[MLIR] Make printing Value to a stream thread-safe (#185762)
Adjust `mlir::Value`'s `operator<<` and `dump()` function so that it can be safely used with multithreading enabled. Similar to `mlir::Operation` which uses `OpPrintingFlags` with `localScope` enabled in printing methods. Using `Value::print(raw_ostream &os)` creates default `OpPrintingFlags` and with these flags print method is called on `getDefiningOp()`. With `localScope` disabled by default, `findParent()` could go all the way up to the `ModuleOp` which can be outside of the pass scope. We had an instance of it in our project when multiple OperationPasses were ran concurrently. Trying to print or dump `mlir::Value` in one of the passes resulted in crash due to failed verifiers that got triggered on parent op before the print.
This commit is contained in:
parent
fd225e296f
commit
0c4eaba2f9
@ -243,10 +243,7 @@ protected:
|
||||
detail::ValueImpl *impl;
|
||||
};
|
||||
|
||||
inline raw_ostream &operator<<(raw_ostream &os, Value value) {
|
||||
value.print(os);
|
||||
return os;
|
||||
}
|
||||
raw_ostream &operator<<(raw_ostream &os, Value value);
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// OpOperand
|
||||
|
||||
@ -4142,8 +4142,13 @@ void Value::print(raw_ostream &os, AsmState &state) const {
|
||||
<< "' at index: " << arg.getArgNumber();
|
||||
}
|
||||
|
||||
raw_ostream &mlir::operator<<(raw_ostream &os, Value value) {
|
||||
value.print(os, OpPrintingFlags().useLocalScope());
|
||||
return os;
|
||||
}
|
||||
|
||||
void Value::dump() const {
|
||||
print(llvm::errs());
|
||||
print(llvm::errs(), OpPrintingFlags().useLocalScope());
|
||||
llvm::errs() << "\n";
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user