Skip to content

Commit ae9edbc

Browse files
committed
[mlir][AsmPrinter] Change value numbering for local scope to be the next isolated operation.
Summary: This revision updates the value numbering when printing to number from the next parent operation that is isolated from above. This is the highest level to number from that still ensures thread-safety. This revision also changes the behavior of Operator::operator<< to use local scope to avoid thread races when numbering operations. Differential Revision: https://reviews.llvm.org/D77525
1 parent 0731132 commit ae9edbc

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

mlir/include/mlir/IR/Operation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ class Operation final
605605
};
606606

607607
inline raw_ostream &operator<<(raw_ostream &os, Operation &op) {
608-
op.print(os);
608+
op.print(os, OpPrintingFlags().useLocalScope());
609609
return os;
610610
}
611611

mlir/lib/IR/AsmPrinter.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2344,23 +2344,23 @@ void Value::printAsOperand(raw_ostream &os, AsmState &state) {
23442344
}
23452345

23462346
void Operation::print(raw_ostream &os, OpPrintingFlags flags) {
2347-
// Handle top-level operations or local printing.
2348-
if (!getParent() || flags.shouldUseLocalScope()) {
2349-
AsmState state(this);
2350-
OperationPrinter(os, flags, state.getImpl()).print(this);
2351-
return;
2352-
}
2347+
// Find the operation to number from based upon the provided flags.
2348+
Operation *printedOp = this;
2349+
bool shouldUseLocalScope = flags.shouldUseLocalScope();
2350+
do {
2351+
// If we are printing local scope, stop at the first operation that is
2352+
// isolated from above.
2353+
if (shouldUseLocalScope && printedOp->isKnownIsolatedFromAbove())
2354+
break;
23532355

2354-
Operation *parentOp = getParentOp();
2355-
if (!parentOp) {
2356-
os << "<<UNLINKED OPERATION>>\n";
2357-
return;
2358-
}
2359-
// Get the top-level op.
2360-
while (auto *nextOp = parentOp->getParentOp())
2361-
parentOp = nextOp;
2356+
// Otherwise, traverse up to the next parent.
2357+
Operation *parentOp = printedOp->getParentOp();
2358+
if (!parentOp)
2359+
break;
2360+
printedOp = parentOp;
2361+
} while (true);
23622362

2363-
AsmState state(parentOp);
2363+
AsmState state(printedOp);
23642364
print(os, state, flags);
23652365
}
23662366
void Operation::print(raw_ostream &os, AsmState &state, OpPrintingFlags flags) {

0 commit comments

Comments
 (0)