[Mlir-commits] [mlir] 00b7d95 - Stop stripping the `std.` prefix when printing operations in a region with a defined default dialect

Mehdi Amini llvmlistbot at llvm.org
Tue Oct 5 19:36:29 PDT 2021


Author: Mehdi Amini
Date: 2021-10-06T02:36:14Z
New Revision: 00b7d951828cdc56eab1ff7658214ffc4675ee0d

URL: https://github.com/llvm/llvm-project/commit/00b7d951828cdc56eab1ff7658214ffc4675ee0d
DIFF: https://github.com/llvm/llvm-project/commit/00b7d951828cdc56eab1ff7658214ffc4675ee0d.diff

LOG: Stop stripping the `std.` prefix when printing operations in a region with a defined default dialect

This fixes round-trip / ambiguity when an operation in the standard dialect would
have the same name as an operation in the default dialect.

Differential Revision: https://reviews.llvm.org/D111204

Added: 
    

Modified: 
    mlir/lib/IR/Operation.cpp
    mlir/test/IR/parser.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/IR/Operation.cpp b/mlir/lib/IR/Operation.cpp
index 0fa51ea979430..e7cc0642120fd 100644
--- a/mlir/lib/IR/Operation.cpp
+++ b/mlir/lib/IR/Operation.cpp
@@ -646,8 +646,9 @@ void OpState::printOpName(Operation *op, OpAsmPrinter &p,
   StringRef name = op->getName().getStringRef();
   if (name.startswith((defaultDialect + ".").str()))
     name = name.drop_front(defaultDialect.size() + 1);
-  // TODO: remove this special case.
-  else if (name.startswith("std."))
+  // TODO: remove this special case (and update test/IR/parser.mlir)
+  else if ((defaultDialect.empty() || defaultDialect == "builtin") &&
+           name.startswith("std."))
     name = name.drop_front(4);
   p.getStream() << name;
 }

diff  --git a/mlir/test/IR/parser.mlir b/mlir/test/IR/parser.mlir
index 959f1e2af4abd..b087cb226ae1a 100644
--- a/mlir/test/IR/parser.mlir
+++ b/mlir/test/IR/parser.mlir
@@ -1312,7 +1312,7 @@ func @pretty_names() {
 // operations like `test.default_dialect` can define a default dialect
 // used in nested region.
 // CHECK-LABEL: func @default_dialect
-func @default_dialect() {
+func @default_dialect(%bool : i1) {
   test.default_dialect {
     // The test dialect is the default in this region, the following two
     // operations are parsed identically.
@@ -1324,8 +1324,17 @@ func @default_dialect() {
     // example.
     // CHECK:  "test.op_with_attr"() {test.attr = "test.value"} : () -> ()
     "test.op_with_attr"() {test.attr = "test.value"} : () -> ()
+
+    // TODO: remove this after removing the special casing for std in the printer.
+    // Verify that operations in the standard dialect keep the `std.` prefix.
+    // CHECK: std.assert
+    assert %bool, "Assertion"
     "test.terminator"() : ()->()
   }
+  // The same operation outside of the region does not have an std. prefix.
+  // CHECK-NOT: std.assert
+  // CHECK: assert
+  assert %bool, "Assertion"
   return
 }
 


        


More information about the Mlir-commits mailing list