mirror of
https://github.com/zama-ai/concrete.git
synced 2026-02-16 23:51:36 -05:00
feat(compiler): Add functions for type inference debugging to TypeInferenceUtils
The main debugging function is `TypeInferenceUtils::dumpAllState(mlir::Operation* op)` which dumps the entire state of type inference for the function containing `op`.
This commit is contained in:
@@ -916,6 +916,63 @@ protected:
|
||||
}
|
||||
}
|
||||
|
||||
// Prints an indentation composed of `indent` times `" "`.
|
||||
void printIndent(int indent) {
|
||||
for (int i = 0; i < indent; i++)
|
||||
llvm::dbgs() << " ";
|
||||
}
|
||||
|
||||
// Dumps the state of type inference for the operation `op` with an
|
||||
// indentation level of `indent` as the name of the operation,
|
||||
// followed by the types inferred for each operand, followed by
|
||||
// `->`, followed by a dump of the state for any operation nested in
|
||||
// any region of `op`.
|
||||
void dumpStateForOp(mlir::Operation *op, int indent) {
|
||||
const LocalInferenceState state = getCurrentInferredTypes(op);
|
||||
|
||||
printIndent(indent);
|
||||
llvm::dbgs() << op->getName() << " {";
|
||||
|
||||
llvm::interleaveComma(
|
||||
op->getAttrs(), llvm::dbgs(), [&](const mlir::NamedAttribute &attr) {
|
||||
llvm::dbgs() << attr.getName() << " = " << attr.getValue();
|
||||
});
|
||||
|
||||
llvm::dbgs() << "} : (";
|
||||
|
||||
llvm::interleaveComma(op->getOperands(), llvm::dbgs(), [&](mlir::Value v) {
|
||||
llvm::dbgs() << state.find(v);
|
||||
});
|
||||
|
||||
llvm::dbgs() << ") -> (";
|
||||
|
||||
llvm::interleaveComma(op->getResults(), llvm::dbgs(), [&](mlir::Value v) {
|
||||
llvm::dbgs() << state.find(v);
|
||||
});
|
||||
|
||||
llvm::dbgs() << ")\n";
|
||||
|
||||
for (mlir::Region &r : op->getRegions())
|
||||
for (mlir::Block &b : r.getBlocks())
|
||||
for (mlir::Operation &childOp : b.getOperations())
|
||||
dumpStateForOp(&childOp, indent + 1);
|
||||
}
|
||||
|
||||
// Dumps the entire state of type inference for the function
|
||||
// containing the operation `op`. For each operation, this prints
|
||||
// the name of the operation, followed by the types inferred for
|
||||
// each operand, followed by `->`, followed by the types inferred
|
||||
// for the results.
|
||||
void dumpAllState(mlir::Operation *op) {
|
||||
mlir::Operation *funcOp = op;
|
||||
while (funcOp && !llvm::isa<mlir::func::FuncOp>(funcOp))
|
||||
funcOp = funcOp->getParentOp();
|
||||
|
||||
assert(funcOp);
|
||||
|
||||
dumpStateForOp(funcOp, 0);
|
||||
}
|
||||
|
||||
TypeResolver &resolver;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user