13 #include "llvm/ADT/SetVector.h"
14 #include "llvm/Support/Debug.h"
16 using namespace circt;
17 using namespace debug;
21 struct DebugAnalysisBuilder {
22 DebugAnalysisBuilder(Operation *rootOp) : rootOp(rootOp) {}
24 void addDebugOp(Operation *op);
25 void addDebugValue(Value value);
26 void addDebugOperand(OpOperand *operand);
27 void maybeDebugOp(Operation *op);
30 SetVector<Operation *> worklist;
32 DenseSet<Operation *> debugOps;
33 DenseSet<Value> debugValues;
34 DenseSet<OpOperand *> debugOperands;
41 rootOp->walk([&](Operation *op) {
42 if (isa<debug::DebugDialect>(op->getDialect())) {
46 for (
auto ®ion : op->getRegions())
47 for (
auto &block : region)
48 for (
auto arg : block.getArguments())
49 if (isa<debug::DebugDialect>(arg.getType().getDialect()))
51 for (
auto result : op->getResults())
52 if (isa<debug::DebugDialect>(result.getType().getDialect()))
53 addDebugValue(result);
58 while (!worklist.empty()) {
59 auto *op = worklist.pop_back_val();
60 if (debugOps.contains(op))
67 if (!isa<hw::HWDialect, comb::CombDialect>(op->getDialect()))
69 if (op->hasAttr(
"name"))
72 if (op->getNumResults() > 0) {
73 auto allUsesDebug = llvm::all_of(op->getUses(), [&](
auto &use) {
74 return debugOperands.contains(&use);
82 if (op->getNumOperands() > 0) {
83 auto allOperandsDebug =
84 llvm::all_of(op->getOperands(), [&](
auto operand) {
85 return debugValues.contains(operand);
87 if (allOperandsDebug) {
95 void DebugAnalysisBuilder::addDebugOp(Operation *op) {
96 if (debugOps.insert(op).second) {
97 for (
auto &operand : op->getOpOperands())
98 addDebugOperand(&operand);
99 for (
auto result : op->getResults())
100 addDebugValue(result);
104 void DebugAnalysisBuilder::addDebugValue(Value value) {
105 if (debugValues.insert(value).second) {
106 for (
auto *user : value.getUsers())
111 void DebugAnalysisBuilder::addDebugOperand(OpOperand *operand) {
112 if (debugOperands.insert(operand).second)
113 maybeDebugOp(operand->get().getDefiningOp());
116 void DebugAnalysisBuilder::maybeDebugOp(Operation *op) {
117 if (!op || debugOps.contains(op))
123 DebugAnalysisBuilder builder(op);
125 debugOps = std::move(builder.debugOps);
126 debugValues = std::move(builder.debugValues);
127 debugOperands = std::move(builder.debugOperands);
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
int run(Type[Generator] generator=CppGenerator, cmdline_args=sys.argv)
DebugAnalysis(Operation *op)