CIRCT  20.0.0git
DumpDebugInfo.cpp
Go to the documentation of this file.
1 //===- DumpDebugInfo.cpp - Human-readable debug info dump -----------------===//
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 
10 #include "circt/Target/DebugInfo.h"
11 #include "mlir/Support/IndentedOstream.h"
12 
13 using namespace mlir;
14 using namespace circt;
15 
16 static void dump(DIModule &module, raw_indented_ostream &os);
17 
18 static void dump(DIVariable &variable, raw_indented_ostream &os) {
19  os << "Variable " << variable.name;
20  if (variable.loc)
21  os << " at " << variable.loc;
22  os << "\n";
23  os.indent();
24  if (variable.value) {
25  if (auto blockArg = dyn_cast_or_null<BlockArgument>(variable.value)) {
26  os << "Arg " << blockArg.getArgNumber() << " of "
27  << blockArg.getOwner()->getParentOp()->getName();
28  } else if (auto result = dyn_cast_or_null<OpResult>(variable.value)) {
29  os << "Result " << result.getResultNumber() << " of "
30  << result.getDefiningOp()->getName();
31  }
32  os << " of type " << variable.value.getType() << " at "
33  << variable.value.getLoc() << "\n";
34  }
35  os.unindent();
36 }
37 
38 static void dump(DIInstance &instance, raw_indented_ostream &os) {
39  os << "Instance " << instance.name << " of " << instance.module->name;
40  if (instance.op)
41  os << " for " << instance.op->getName() << " at " << instance.op->getLoc();
42  os << "\n";
43  if (instance.module->isInline) {
44  os.indent();
45  dump(*instance.module, os);
46  os.unindent();
47  }
48 }
49 
50 static void dump(DIModule &module, raw_indented_ostream &os) {
51  os << "Module " << module.name;
52  if (module.op)
53  os << " for " << module.op->getName() << " at " << module.op->getLoc();
54  os << "\n";
55  os.indent();
56  for (auto *variable : module.variables)
57  dump(*variable, os);
58  for (auto *instance : module.instances)
59  dump(*instance, os);
60  os.unindent();
61 }
62 
63 static void dump(DebugInfo &di, raw_indented_ostream &os) {
64  os << "DebugInfo for " << di.operation->getName() << " at "
65  << di.operation->getLoc() << "\n";
66  os.indent();
67  for (auto nameAndModule : di.moduleNodes)
68  dump(*nameAndModule.second, os);
69  os.unindent();
70 }
71 
72 LogicalResult debug::dumpDebugInfo(Operation *module, llvm::raw_ostream &os) {
73  DebugInfo di(module);
74  raw_indented_ostream indentedOs(os);
75  dump(di, indentedOs);
76  return success();
77 }
static void dump(DIModule &module, raw_indented_ostream &os)
LogicalResult dumpDebugInfo(Operation *module, llvm::raw_ostream &os)
Dump the debug information in the given module in a human-readable format.
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
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
Operation * operation
The operation that was passed to the constructor.
Definition: DebugInfo.h:68
llvm::MapVector< StringAttr, DIModule * > moduleNodes
A mapping from module name to module debug info.
Definition: DebugInfo.h:70