[PATCH] D77525: [mlir][AsmPrinter] Change value numbering for local scope to be the next isolated operation.

River Riddle via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 5 23:57:44 PDT 2020


rriddle created this revision.
rriddle added reviewers: bondhugula, mehdi_amini.
Herald added subscribers: llvm-commits, grosul1, Joonsoo, liufengdb, lucyrfox, mgester, arpith-jacob, nicolasvasilache, antiagainst, shauheen, burmako, jpienaar.
Herald added a project: LLVM.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D77525

Files:
  mlir/include/mlir/IR/Operation.h
  mlir/lib/IR/AsmPrinter.cpp


Index: mlir/lib/IR/AsmPrinter.cpp
===================================================================
--- mlir/lib/IR/AsmPrinter.cpp
+++ mlir/lib/IR/AsmPrinter.cpp
@@ -2339,23 +2339,22 @@
 }
 
 void Operation::print(raw_ostream &os, OpPrintingFlags flags) {
-  // Handle top-level operations or local printing.
-  if (!getParent() || flags.shouldUseLocalScope()) {
-    AsmState state(this);
-    OperationPrinter(os, flags, state.getImpl()).print(this);
-    return;
-  }
+  // Find the operation to number from based upon the provided flags.
+  Operation *printedOp = this;
+  do {
+    // If we are printing local scope, stop at the first operation that is
+    // isolated from above.
+    if (flags.shouldUseLocalScope() && printedOp->isKnownIsolatedFromAbove())
+      break;
 
-  Operation *parentOp = getParentOp();
-  if (!parentOp) {
-    os << "<<UNLINKED OPERATION>>\n";
-    return;
-  }
-  // Get the top-level op.
-  while (auto *nextOp = parentOp->getParentOp())
-    parentOp = nextOp;
+    // Otherwise, traverse up to the next parent.
+    Operation *parentOp = printedOp->getParentOp();
+    if (!parentOp)
+      break;
+    printedOp = parentOp;
+  } while (true);
 
-  AsmState state(parentOp);
+  AsmState state(printedOp);
   print(os, state, flags);
 }
 void Operation::print(raw_ostream &os, AsmState &state, OpPrintingFlags flags) {
Index: mlir/include/mlir/IR/Operation.h
===================================================================
--- mlir/include/mlir/IR/Operation.h
+++ mlir/include/mlir/IR/Operation.h
@@ -605,7 +605,7 @@
 };
 
 inline raw_ostream &operator<<(raw_ostream &os, Operation &op) {
-  op.print(os);
+  op.print(os, OpPrintingFlags().useLocalScope());
   return os;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77525.255228.patch
Type: text/x-patch
Size: 1723 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200406/753d8127/attachment.bin>


More information about the llvm-commits mailing list