CIRCT  20.0.0git
DebugInfo.h
Go to the documentation of this file.
1 //===- DebugInfo.h - Debug info analysis ------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef CIRCT_ANALYSIS_DEBUGINFO_H
10 #define CIRCT_ANALYSIS_DEBUGINFO_H
11 
12 #include "circt/Support/LLVM.h"
13 #include "mlir/IR/BuiltinAttributes.h"
14 #include "mlir/IR/Operation.h"
15 #include "llvm/ADT/MapVector.h"
16 
17 namespace circt {
18 
19 struct DIInstance;
20 struct DIVariable;
21 
22 namespace detail {
23 struct DebugInfoBuilder;
24 } // namespace detail
25 
26 struct DIModule {
27  /// The operation that generated this level of hierarchy.
28  Operation *op = nullptr;
29  /// The name of this level of hierarchy.
30  StringAttr name;
31  /// Levels of hierarchy nested under this module.
32  SmallVector<DIInstance *, 0> instances;
33  /// Variables declared within this module.
34  SmallVector<DIVariable *, 0> variables;
35  /// If this is an extern declaration.
36  bool isExtern = false;
37  /// If this is an inline scope created by a `dbg.scope` operation.
38  bool isInline = false;
39 };
40 
41 struct DIInstance {
42  /// The operation that generated this instance.
43  Operation *op = nullptr;
44  /// The name of this instance.
45  StringAttr name;
46  /// The instantiated module.
48 };
49 
50 struct DIVariable {
51  /// The name of this variable.
52  StringAttr name;
53  /// The location of the variable's declaration.
54  LocationAttr loc;
55  /// The SSA value representing the value of this variable.
56  Value value = nullptr;
57 };
58 
59 /// Debug information attached to an operation and the operations nested within.
60 ///
61 /// This is an analysis that gathers debug information for a piece of IR, either
62 /// from attributes attached to operations or the general structure of the IR.
63 struct DebugInfo {
64  /// Collect the debug information nested under the given operation.
65  DebugInfo(Operation *op);
66 
67  /// The operation that was passed to the constructor.
68  Operation *operation;
69  /// A mapping from module name to module debug info.
70  llvm::MapVector<StringAttr, DIModule *> moduleNodes;
71 
72 protected:
73  friend struct detail::DebugInfoBuilder;
74  llvm::SpecificBumpPtrAllocator<DIModule> moduleAllocator;
75  llvm::SpecificBumpPtrAllocator<DIInstance> instanceAllocator;
76  llvm::SpecificBumpPtrAllocator<DIVariable> variableAllocator;
77 };
78 
79 } // namespace circt
80 
81 #endif // CIRCT_ANALYSIS_DEBUGINFO_H
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition: DebugAnalysis.h:21
Operation * op
The operation that generated this instance.
Definition: DebugInfo.h:43
StringAttr name
The name of this instance.
Definition: DebugInfo.h:45
DIModule * module
The instantiated module.
Definition: DebugInfo.h:47
bool isInline
If this is an inline scope created by a dbg.scope operation.
Definition: DebugInfo.h:38
Operation * op
The operation that generated this level of hierarchy.
Definition: DebugInfo.h:28
SmallVector< DIInstance *, 0 > instances
Levels of hierarchy nested under this module.
Definition: DebugInfo.h:32
SmallVector< DIVariable *, 0 > variables
Variables declared within this module.
Definition: DebugInfo.h:34
bool isExtern
If this is an extern declaration.
Definition: DebugInfo.h:36
StringAttr name
The name of this level of hierarchy.
Definition: DebugInfo.h:30
Value value
The SSA value representing the value of this variable.
Definition: DebugInfo.h:56
StringAttr name
The name of this variable.
Definition: DebugInfo.h:52
LocationAttr loc
The location of the variable's declaration.
Definition: DebugInfo.h:54
Debug information attached to an operation and the operations nested within.
Definition: DebugInfo.h:63
llvm::SpecificBumpPtrAllocator< DIInstance > instanceAllocator
Definition: DebugInfo.h:75
Operation * operation
The operation that was passed to the constructor.
Definition: DebugInfo.h:68
llvm::SpecificBumpPtrAllocator< DIModule > moduleAllocator
Definition: DebugInfo.h:74
llvm::SpecificBumpPtrAllocator< DIVariable > variableAllocator
Definition: DebugInfo.h:76
llvm::MapVector< StringAttr, DIModule * > moduleNodes
A mapping from module name to module debug info.
Definition: DebugInfo.h:70
DebugInfo(Operation *op)
Collect the debug information nested under the given operation.
Definition: DebugInfo.cpp:188
Helper to populate a DebugInfo with nodes.
Definition: DebugInfo.cpp:24