[Mlir-commits] [mlir] [mlir] Retain original identifier names for debugging v3 (PR #119996)
Maksim Levental
llvmlistbot at llvm.org
Sat Dec 14 20:31:47 PST 2024
https://github.com/makslevental updated https://github.com/llvm/llvm-project/pull/119996
>From afb53cde2d65c2f54725a09d4b51105ce25d7299 Mon Sep 17 00:00:00 2001
From: max <maksim.levental at gmail.com>
Date: Fri, 13 Dec 2024 23:39:19 -0500
Subject: [PATCH 1/2] [mlir] retain identifier names
---
mlir/include/mlir/IR/OperationSupport.h | 7 +
mlir/lib/IR/AsmPrinter.cpp | 45 ++++-
mlir/test/IR/use-nameloc-as-prefix.mlir | 231 ++++++++++++++++++++++++
3 files changed, 280 insertions(+), 3 deletions(-)
create mode 100644 mlir/test/IR/use-nameloc-as-prefix.mlir
diff --git a/mlir/include/mlir/IR/OperationSupport.h b/mlir/include/mlir/IR/OperationSupport.h
index 1b93f3d3d04fe8..c6a603ae518785 100644
--- a/mlir/include/mlir/IR/OperationSupport.h
+++ b/mlir/include/mlir/IR/OperationSupport.h
@@ -1221,6 +1221,10 @@ class OpPrintingFlags {
/// Return if printer should use unique SSA IDs.
bool shouldPrintUniqueSSAIDs() const;
+ /// Returns if the printer should retain identifier names collected using
+ /// parsing.
+ bool shouldUseNameLocAsPrefix() const;
+
private:
/// Elide large elements attributes if the number of elements is larger than
/// the upper limit.
@@ -1254,6 +1258,9 @@ class OpPrintingFlags {
/// Print unique SSA IDs for values, block arguments and naming conflicts
bool printUniqueSSAIDsFlag : 1;
+
+ /// Print the retained original names of identifiers
+ bool useNameLocAsPrefix : 1;
};
//===----------------------------------------------------------------------===//
diff --git a/mlir/lib/IR/AsmPrinter.cpp b/mlir/lib/IR/AsmPrinter.cpp
index 61b90bc9b0a7bb..18db2dc555c766 100644
--- a/mlir/lib/IR/AsmPrinter.cpp
+++ b/mlir/lib/IR/AsmPrinter.cpp
@@ -195,6 +195,10 @@ struct AsmPrinterOptions {
"mlir-print-unique-ssa-ids", llvm::cl::init(false),
llvm::cl::desc("Print unique SSA ID numbers for values, block arguments "
"and naming conflicts across all regions")};
+
+ llvm::cl::opt<bool> useNameLocAsPrefix{
+ "mlir-use-nameloc-as-prefix", llvm::cl::init(false),
+ llvm::cl::desc("TODO")};
};
} // namespace
@@ -212,7 +216,8 @@ OpPrintingFlags::OpPrintingFlags()
: printDebugInfoFlag(false), printDebugInfoPrettyFormFlag(false),
printGenericOpFormFlag(false), skipRegionsFlag(false),
assumeVerifiedFlag(false), printLocalScope(false),
- printValueUsersFlag(false), printUniqueSSAIDsFlag(false) {
+ printValueUsersFlag(false), printUniqueSSAIDsFlag(false),
+ useNameLocAsPrefix(false) {
// Initialize based upon command line options, if they are available.
if (!clOptions.isConstructed())
return;
@@ -231,6 +236,7 @@ OpPrintingFlags::OpPrintingFlags()
skipRegionsFlag = clOptions->skipRegionsOpt;
printValueUsersFlag = clOptions->printValueUsers;
printUniqueSSAIDsFlag = clOptions->printUniqueSSAIDs;
+ useNameLocAsPrefix = clOptions->useNameLocAsPrefix;
}
/// Enable the elision of large elements attributes, by printing a '...'
@@ -362,6 +368,11 @@ bool OpPrintingFlags::shouldPrintUniqueSSAIDs() const {
return printUniqueSSAIDsFlag || shouldPrintGenericOpForm();
}
+/// TODO
+bool OpPrintingFlags::shouldUseNameLocAsPrefix() const {
+ return useNameLocAsPrefix;
+}
+
//===----------------------------------------------------------------------===//
// NewLineCounter
//===----------------------------------------------------------------------===//
@@ -1514,10 +1525,22 @@ void SSANameState::numberValuesInRegion(Region ®ion) {
setValueName(arg, name);
};
+ bool alreadySetNames = false;
if (!printerFlags.shouldPrintGenericOpForm()) {
if (Operation *op = region.getParentOp()) {
- if (auto asmInterface = dyn_cast<OpAsmOpInterface>(op))
+ if (auto asmInterface = dyn_cast<OpAsmOpInterface>(op)) {
asmInterface.getAsmBlockArgumentNames(region, setBlockArgNameFn);
+ alreadySetNames = true;
+ }
+ }
+ }
+
+ if (printerFlags.shouldUseNameLocAsPrefix() && !alreadySetNames) {
+ for (BlockArgument arg : region.getArguments()) {
+ if (isa<NameLoc>(arg.getLoc())) {
+ auto nameLoc = cast<NameLoc>(arg.getLoc());
+ setBlockArgNameFn(arg, nameLoc.getName());
+ }
}
}
@@ -1553,7 +1576,12 @@ void SSANameState::numberValuesInBlock(Block &block) {
specialNameBuffer.resize(strlen("arg"));
specialName << nextArgumentID++;
}
- setValueName(arg, specialName.str());
+ if (printerFlags.shouldUseNameLocAsPrefix() && isa<NameLoc>(arg.getLoc())) {
+ auto nameLoc = cast<NameLoc>(arg.getLoc());
+ setValueName(arg, nameLoc.getName());
+ } else {
+ setValueName(arg, specialName.str());
+ }
}
// Number the operations in this block.
@@ -1589,10 +1617,21 @@ void SSANameState::numberValuesInOp(Operation &op) {
blockNames[block] = {-1, name};
};
+ bool alreadySetNames = false;
if (!printerFlags.shouldPrintGenericOpForm()) {
if (OpAsmOpInterface asmInterface = dyn_cast<OpAsmOpInterface>(&op)) {
asmInterface.getAsmBlockNames(setBlockNameFn);
asmInterface.getAsmResultNames(setResultNameFn);
+ alreadySetNames = true;
+ }
+ }
+
+ if (printerFlags.shouldUseNameLocAsPrefix() && !alreadySetNames) {
+ for (Value opResult : op.getResults()) {
+ if (isa<NameLoc>(opResult.getLoc())) {
+ auto nameLoc = cast<NameLoc>(opResult.getLoc());
+ setResultNameFn(opResult, nameLoc.getName());
+ }
}
}
diff --git a/mlir/test/IR/use-nameloc-as-prefix.mlir b/mlir/test/IR/use-nameloc-as-prefix.mlir
new file mode 100644
index 00000000000000..ba0b888ee5f80d
--- /dev/null
+++ b/mlir/test/IR/use-nameloc-as-prefix.mlir
@@ -0,0 +1,231 @@
+// RUN: mlir-opt -allow-unregistered-dialect %s -mlir-print-debuginfo -mlir-print-local-scope | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect %s -mlir-print-debuginfo | FileCheck %s --check-prefix=CHECK-ALIAS
+// RUN: mlir-opt -allow-unregistered-dialect %s -mlir-print-debuginfo | mlir-opt -allow-unregistered-dialect -mlir-print-debuginfo | FileCheck %s --check-prefix=CHECK-ALIAS
+// This test verifies that debug locations are round-trippable.
+
+#set0 = affine_set<(d0) : (1 == 0)>
+
+// CHECK-LABEL: func @inline_notation
+func.func @inline_notation() -> i32 {
+ // CHECK: -> i32 loc("foo")
+ %1 = "foo"() : () -> i32 loc("foo")
+
+ // CHECK: arith.constant 4 : index loc(callsite("foo" at "mysource.cc":10:8))
+ %2 = arith.constant 4 : index loc(callsite("foo" at "mysource.cc":10:8))
+
+ // CHECK: affine.for %arg0 loc("IVlocation") = 0 to 8 {
+ // CHECK: } loc(fused["foo", "mysource.cc":10:8])
+ affine.for %i0 loc("IVlocation") = 0 to 8 {
+ } loc(fused["foo", "mysource.cc":10:8])
+
+ // CHECK: } loc(fused<"myPass">["foo", "foo2"])
+ affine.if #set0(%2) {
+ } loc(fused<"myPass">["foo", "foo2"])
+
+ // CHECK: } loc(fused<"myPass">["foo"])
+ affine.if #set0(%2) {
+ } loc(fused<"myPass">["foo"])
+
+ // CHECK: return %0 : i32 loc(unknown)
+ return %1 : i32 loc(unknown)
+}
+
+// CHECK-LABEL: func private @loc_attr(i1 {foo.loc_attr = loc(callsite("foo" at "mysource.cc":10:8))})
+func.func private @loc_attr(i1 {foo.loc_attr = loc(callsite("foo" at "mysource.cc":10:8))})
+
+// CHECK-LABEL: func.func private @filelocrange_attr1(i1 {foo.loc_attr = loc("mysource.cc":10:0)})
+func.func private @filelocrange_attr1(i1 {foo.loc_attr = loc("mysource.cc":10)})
+// CHECK-LABEL: func.func private @filelocrange_attr2(i1 {foo.loc_attr = loc("mysource.cc":10:8)})
+func.func private @filelocrange_attr2(i1 {foo.loc_attr = loc("mysource.cc":10:8)})
+// CHECK-LABEL: func.func private @filelocrange_attr3(i1 {foo.loc_attr = loc("mysource.cc":10:8 to :12)})
+func.func private @filelocrange_attr3(i1 {foo.loc_attr = loc("mysource.cc":10:8 to :12)})
+// CHECK-LABEL: func.func private @filelocrange_attr4(i1 {foo.loc_attr = loc("mysource.cc":10:8 to 12:4)})
+func.func private @filelocrange_attr4(i1 {foo.loc_attr = loc("mysource.cc":10:8 to 12:4)})
+
+ // Check that locations get properly escaped.
+// CHECK-LABEL: func @escape_strings()
+func.func @escape_strings() {
+ // CHECK: loc("escaped\0A")
+ "foo"() : () -> () loc("escaped\n")
+
+ // CHECK: loc("escaped\0A")
+ "foo"() : () -> () loc("escaped\0A")
+
+ // CHECK: loc("escaped\0A":0:0)
+ "foo"() : () -> () loc("escaped\n":0:0)
+ return
+}
+
+// CHECK-ALIAS: "foo.op"() : () -> () loc(#[[LOC:.*]])
+"foo.op"() : () -> () loc(#loc)
+
+// CHECK-LABEL: func @argLocs(
+// CHECK-SAME: %arg0: i32 loc({{.*}}locations.mlir":[[# @LINE+1]]:20),
+func.func @argLocs(%x: i32,
+// CHECK-SAME: %arg1: i64 loc("hotdog")
+ %y: i64 loc("hotdog")) {
+ return
+}
+
+// CHECK-LABEL: "foo.unknown_op_with_bbargs"()
+// CHECK-ALIAS: "foo.unknown_op_with_bbargs"()
+"foo.unknown_op_with_bbargs"() ({
+// CHECK-NEXT: ^bb0(%arg0: i32 loc({{.*}}locations.mlir":[[# @LINE+2]]:7),
+// CHECK-ALIAS-NEXT: ^bb0(%arg0: i32 loc({{.*}}locations.mlir":[[# @LINE+1]]:7),
+ ^bb0(%x: i32,
+// CHECK-SAME: %arg1: i32 loc("cheetos"),
+// CHECK-ALIAS-SAME: %arg1: i32 loc("cheetos"),
+ %y: i32 loc("cheetos"),
+// CHECK-SAME: %arg2: i32 loc("out_of_line_location2")):
+// CHECK-ALIAS-SAME: %arg2: i32 loc("out_of_line_location2")):
+ %z: i32 loc("out_of_line_location2")):
+ %1 = arith.addi %x, %y : i32
+ "foo.yield"(%1) : (i32) -> ()
+ }) : () -> ()
+
+// CHECK-LABEL: func @location_name_child_is_name
+func.func @location_name_child_is_name() {
+ // CHECK: "foo"("foo")
+ return loc("foo"("foo"))
+}
+
+// CHECK-ALIAS: #[[LOC]] = loc("out_of_line_location")
+#loc = loc("out_of_line_location")
+
+// CHECK-LABEL: @optional_location_specifier
+// CHECK: test.attr_with_loc("foo" loc("foo_loc"))
+func.func @optional_location_specifier() {
+ test.attr_with_loc("foo" loc("foo_loc"))
+ return
+}
+
+// CHECK-LABEL: @dialect_location
+// CHECK: test.attr_with_loc("dialectLoc" loc(#test.custom_location<"foo.mlir" * 32>))
+func.func @dialect_location() {
+ test.attr_with_loc("dialectLoc" loc(#test.custom_location<"foo.mlir"*32>))
+ return
+}
+
+// RUN: mlir-opt -allow-unregistered-dialect %s -mlir-print-debuginfo -mlir-pretty-debuginfo -mlir-print-local-scope | FileCheck %s
+
+#set0 = affine_set<(d0) : (1 == 0)>
+
+// CHECK-LABEL: func @inline_notation
+func.func @inline_notation() -> i32 {
+ // CHECK: -> i32 "foo"
+ %1 = "foo"() : () -> i32 loc("foo")
+
+ // CHECK: arith.constant 4 : index "foo" at mysource.cc:10:8
+ %2 = arith.constant 4 : index loc(callsite("foo" at "mysource.cc":10:8))
+
+ // CHECK: arith.constant 4 : index "foo"
+ // CHECK-NEXT: at mysource1.cc:10:8
+ // CHECK-NEXT: at mysource2.cc:13:8
+ // CHECK-NEXT: at mysource3.cc:100:10
+ %3 = arith.constant 4 : index loc(callsite("foo" at callsite("mysource1.cc":10:8 at callsite("mysource2.cc":13:8 at "mysource3.cc":100:10))))
+
+ // CHECK: } ["foo", mysource.cc:10:8]
+ affine.for %i0 = 0 to 8 {
+ } loc(fused["foo", "mysource.cc":10:8])
+
+ // CHECK: } <"myPass">["foo", "foo2"]
+ affine.if #set0(%2) {
+ } loc(fused<"myPass">["foo", "foo2"])
+
+ // CHECK: "foo.op"() : () -> () #test.custom_location<"foo.mlir" * 1234>
+ "foo.op"() : () -> () loc(#test.custom_location<"foo.mlir" * 1234>)
+
+ // CHECK: return %0 : i32 [unknown]
+ return %1 : i32 loc(unknown)
+}
+
+// RUN: mlir-opt -allow-unregistered-dialect -split-input-file %s | FileCheck %s --check-prefixes=CHECK-CUSTOM,CHECK
+// RUN: mlir-opt -allow-unregistered-dialect -mlir-print-op-generic -split-input-file %s | FileCheck %s --check-prefixes=CHECK,CHECK-GENERIC
+// RUN: mlir-opt -allow-unregistered-dialect -split-input-file --mlir-print-op-generic --mlir-print-debuginfo -mlir-print-local-scope %s | FileCheck %s --check-prefixes=CHECK-LOCATION
+
+// -----
+
+func.func @pretty_printed_region_op(%arg0 : f32, %arg1 : f32) -> (f32) {
+// CHECK-CUSTOM: test.pretty_printed_region %arg1, %arg0 start test.special.op end : (f32, f32) -> f32
+// CHECK-GENERIC: "test.pretty_printed_region"(%arg1, %arg0)
+// CHECK-GENERIC: ^bb0(%arg[[x:[0-9]+]]: f32, %arg[[y:[0-9]+]]: f32
+// CHECK-GENERIC: %[[RES:.*]] = "test.special.op"(%arg[[x]], %arg[[y]]) : (f32, f32) -> f32
+// CHECK-GENERIC: "test.return"(%[[RES]]) : (f32) -> ()
+// CHECK-GENERIC: : (f32, f32) -> f32
+
+ %res = test.pretty_printed_region %arg1, %arg0 start test.special.op end : (f32, f32) -> (f32) loc("some_NameLoc")
+ return %res : f32
+}
+
+// -----
+
+func.func @pretty_printed_region_op(%arg0 : f32, %arg1 : f32) -> (f32) {
+// CHECK-CUSTOM: test.pretty_printed_region %arg1, %arg0
+// CHECK-GENERIC: "test.pretty_printed_region"(%arg1, %arg0)
+// CHECK: ^bb0(%arg[[x:[0-9]+]]: f32, %arg[[y:[0-9]+]]: f32):
+// CHECK: %[[RES:.*]] = "test.non.special.op"(%arg[[x]], %arg[[y]]) : (f32, f32) -> f32
+// CHECK: "test.return"(%[[RES]]) : (f32) -> ()
+// CHECK: : (f32, f32) -> f32
+
+ %0 = test.pretty_printed_region %arg1, %arg0 ({
+ ^bb0(%arg2: f32, %arg3: f32):
+ %1 = "test.non.special.op"(%arg2, %arg3) : (f32, f32) -> f32
+ "test.return"(%1) : (f32) -> ()
+ }) : (f32, f32) -> f32
+ return %0 : f32
+}
+
+// -----
+
+func.func @pretty_printed_region_op_deferred_loc(%arg0 : f32, %arg1 : f32) -> (f32) {
+// CHECK-LOCATION: "test.pretty_printed_region"(%arg1, %arg0)
+// CHECK-LOCATION: ^bb0(%arg[[x:[0-9]+]]: f32 loc("foo"), %arg[[y:[0-9]+]]: f32 loc("foo")
+// CHECK-LOCATION: %[[RES:.*]] = "test.special.op"(%arg[[x]], %arg[[y]]) : (f32, f32) -> f32
+// CHECK-LOCATION: "test.return"(%[[RES]]) : (f32) -> ()
+// CHECK-LOCATION: : (f32, f32) -> f32
+
+ %res = test.pretty_printed_region %arg1, %arg0 start test.special.op end : (f32, f32) -> (f32) loc("foo")
+ return %res : f32
+}
+
+// -----
+
+// This tests the behavior of custom block names:
+// operations like `test.block_names` can define custom names for blocks in
+// nested regions.
+// CHECK-CUSTOM-LABEL: func @block_names
+func.func @block_names(%bool : i1) {
+ // CHECK: test.block_names
+ test.block_names {
+ // CHECK-CUSTOM: br ^foo1
+ // CHECK-GENERIC: cf.br{{.*}}^bb1
+ cf.br ^foo1
+ // CHECK-CUSTOM: ^foo1:
+ // CHECK-GENERIC: ^bb1:
+ ^foo1:
+ // CHECK-CUSTOM: br ^foo2
+ // CHECK-GENERIC: cf.br{{.*}}^bb2
+ cf.br ^foo2
+ // CHECK-CUSTOM: ^foo2:
+ // CHECK-GENERIC: ^bb2:
+ ^foo2:
+ "test.return"() : () -> ()
+ }
+ return
+}
+
+// RUN: mlir-opt -allow-unregistered-dialect %s | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect -mlir-print-op-generic -mlir-print-debuginfo -mlir-print-local-scope %s | FileCheck %s --check-prefix=CHECK-GENERIC
+
+// CHECK-LABEL: func @wrapping_op
+// CHECK-GENERIC: "func.func"
+// CHECK-GENERIC-SAME: sym_name = "wrapping_op"
+func.func @wrapping_op(%arg0 : i32, %arg1 : f32) -> (i3, i2, i1) {
+// CHECK: %0:3 = test.wrapping_region wraps "some.op"(%arg1, %arg0) {test.attr = "attr"} : (f32, i32) -> (i1, i2, i3)
+// CHECK-GENERIC: "test.wrapping_region"() ({
+// CHECK-GENERIC: %[[NESTED_RES:.*]]:3 = "some.op"(%arg1, %arg0) {test.attr = "attr"} : (f32, i32) -> (i1, i2, i3) loc("some_NameLoc")
+// CHECK-GENERIC: "test.return"(%[[NESTED_RES]]#0, %[[NESTED_RES]]#1, %[[NESTED_RES]]#2) : (i1, i2, i3) -> () loc("some_NameLoc")
+// CHECK-GENERIC: }) : () -> (i1, i2, i3) loc("some_NameLoc")
+ %res:3 = test.wrapping_region wraps "some.op"(%arg1, %arg0) { test.attr = "attr" } : (f32, i32) -> (i1, i2, i3) loc("some_NameLoc")
+ return %res#2, %res#1, %res#0 : i3, i2, i1
+}
>From 9e6c00d6d4919a4e9a4fdf46b2913da1e5990a2d Mon Sep 17 00:00:00 2001
From: Maksim Levental <maksim.levental at gmail.com>
Date: Sat, 14 Dec 2024 23:21:15 -0500
Subject: [PATCH 2/2] add mlir-use-nameloc-as-prefix and set to true and "fix"
tests that break
---
mlir/lib/IR/AsmPrinter.cpp | 6 +-
mlir/test/IR/locations.mlir | 14 +-
mlir/test/IR/pretty-locations.mlir | 2 +-
mlir/test/IR/pretty_printed_region_op.mlir | 12 +-
mlir/test/IR/use-nameloc-as-prefix.mlir | 231 ---------------------
mlir/test/IR/wrapping_op.mlir | 6 +-
mlir/test/mlir-tblgen/pattern.mlir | 2 +-
7 files changed, 21 insertions(+), 252 deletions(-)
delete mode 100644 mlir/test/IR/use-nameloc-as-prefix.mlir
diff --git a/mlir/lib/IR/AsmPrinter.cpp b/mlir/lib/IR/AsmPrinter.cpp
index 18db2dc555c766..2bab5afc2775f2 100644
--- a/mlir/lib/IR/AsmPrinter.cpp
+++ b/mlir/lib/IR/AsmPrinter.cpp
@@ -196,9 +196,9 @@ struct AsmPrinterOptions {
llvm::cl::desc("Print unique SSA ID numbers for values, block arguments "
"and naming conflicts across all regions")};
- llvm::cl::opt<bool> useNameLocAsPrefix{
- "mlir-use-nameloc-as-prefix", llvm::cl::init(false),
- llvm::cl::desc("TODO")};
+ llvm::cl::opt<bool> useNameLocAsPrefix{"mlir-use-nameloc-as-prefix",
+ llvm::cl::init(true),
+ llvm::cl::desc("TODO")};
};
} // namespace
diff --git a/mlir/test/IR/locations.mlir b/mlir/test/IR/locations.mlir
index b725307b420b79..dc39315a765a83 100644
--- a/mlir/test/IR/locations.mlir
+++ b/mlir/test/IR/locations.mlir
@@ -13,7 +13,7 @@ func.func @inline_notation() -> i32 {
// CHECK: arith.constant 4 : index loc(callsite("foo" at "mysource.cc":10:8))
%2 = arith.constant 4 : index loc(callsite("foo" at "mysource.cc":10:8))
- // CHECK: affine.for %arg0 loc("IVlocation") = 0 to 8 {
+ // CHECK: affine.for %IVlocation loc("IVlocation") = 0 to 8 {
// CHECK: } loc(fused["foo", "mysource.cc":10:8])
affine.for %i0 loc("IVlocation") = 0 to 8 {
} loc(fused["foo", "mysource.cc":10:8])
@@ -26,7 +26,7 @@ func.func @inline_notation() -> i32 {
affine.if #set0(%2) {
} loc(fused<"myPass">["foo"])
- // CHECK: return %0 : i32 loc(unknown)
+ // CHECK: return %foo : i32 loc(unknown)
return %1 : i32 loc(unknown)
}
@@ -62,7 +62,7 @@ func.func @escape_strings() {
// CHECK-LABEL: func @argLocs(
// CHECK-SAME: %arg0: i32 loc({{.*}}locations.mlir":[[# @LINE+1]]:20),
func.func @argLocs(%x: i32,
-// CHECK-SAME: %arg1: i64 loc("hotdog")
+// CHECK-SAME: %hotdog: i64 loc("hotdog")
%y: i64 loc("hotdog")) {
return
}
@@ -73,11 +73,11 @@ func.func @argLocs(%x: i32,
// CHECK-NEXT: ^bb0(%arg0: i32 loc({{.*}}locations.mlir":[[# @LINE+2]]:7),
// CHECK-ALIAS-NEXT: ^bb0(%arg0: i32 loc({{.*}}locations.mlir":[[# @LINE+1]]:7),
^bb0(%x: i32,
-// CHECK-SAME: %arg1: i32 loc("cheetos"),
-// CHECK-ALIAS-SAME: %arg1: i32 loc("cheetos"),
+// CHECK-SAME: %cheetos: i32 loc("cheetos"),
+// CHECK-ALIAS-SAME: %cheetos: i32 loc("cheetos"),
%y: i32 loc("cheetos"),
-// CHECK-SAME: %arg2: i32 loc("out_of_line_location2")):
-// CHECK-ALIAS-SAME: %arg2: i32 loc("out_of_line_location2")):
+// CHECK-SAME: %out_of_line_location2: i32 loc("out_of_line_location2")):
+// CHECK-ALIAS-SAME: %out_of_line_location2: i32 loc("out_of_line_location2")):
%z: i32 loc("out_of_line_location2")):
%1 = arith.addi %x, %y : i32
"foo.yield"(%1) : (i32) -> ()
diff --git a/mlir/test/IR/pretty-locations.mlir b/mlir/test/IR/pretty-locations.mlir
index 598bebeb83aebd..30391252cabfbe 100644
--- a/mlir/test/IR/pretty-locations.mlir
+++ b/mlir/test/IR/pretty-locations.mlir
@@ -27,6 +27,6 @@ func.func @inline_notation() -> i32 {
// CHECK: "foo.op"() : () -> () #test.custom_location<"foo.mlir" * 1234>
"foo.op"() : () -> () loc(#test.custom_location<"foo.mlir" * 1234>)
- // CHECK: return %0 : i32 [unknown]
+ // CHECK: return %foo : i32 [unknown]
return %1 : i32 loc(unknown)
}
diff --git a/mlir/test/IR/pretty_printed_region_op.mlir b/mlir/test/IR/pretty_printed_region_op.mlir
index 0a81f9d53a3097..8c6d71d1bf10f2 100644
--- a/mlir/test/IR/pretty_printed_region_op.mlir
+++ b/mlir/test/IR/pretty_printed_region_op.mlir
@@ -6,9 +6,9 @@
func.func @pretty_printed_region_op(%arg0 : f32, %arg1 : f32) -> (f32) {
// CHECK-CUSTOM: test.pretty_printed_region %arg1, %arg0 start test.special.op end : (f32, f32) -> f32
-// CHECK-GENERIC: "test.pretty_printed_region"(%arg1, %arg0)
-// CHECK-GENERIC: ^bb0(%arg[[x:[0-9]+]]: f32, %arg[[y:[0-9]+]]: f32
-// CHECK-GENERIC: %[[RES:.*]] = "test.special.op"(%arg[[x]], %arg[[y]]) : (f32, f32) -> f32
+// CHECK-GENERIC: %some_NameLoc = "test.pretty_printed_region"(%arg1, %arg0)
+// CHECK-GENERIC: ^bb0(%some_NameLoc_[[x:[0-9]+]]: f32, %some_NameLoc_[[y:[0-9]+]]: f32
+// CHECK-GENERIC: %[[RES:.*]] = "test.special.op"(%some_NameLoc_[[x]], %some_NameLoc_[[y]]) : (f32, f32) -> f32
// CHECK-GENERIC: "test.return"(%[[RES]]) : (f32) -> ()
// CHECK-GENERIC: : (f32, f32) -> f32
@@ -37,9 +37,9 @@ func.func @pretty_printed_region_op(%arg0 : f32, %arg1 : f32) -> (f32) {
// -----
func.func @pretty_printed_region_op_deferred_loc(%arg0 : f32, %arg1 : f32) -> (f32) {
-// CHECK-LOCATION: "test.pretty_printed_region"(%arg1, %arg0)
-// CHECK-LOCATION: ^bb0(%arg[[x:[0-9]+]]: f32 loc("foo"), %arg[[y:[0-9]+]]: f32 loc("foo")
-// CHECK-LOCATION: %[[RES:.*]] = "test.special.op"(%arg[[x]], %arg[[y]]) : (f32, f32) -> f32
+// CHECK-LOCATION: %foo = "test.pretty_printed_region"(%arg1, %arg0)
+// CHECK-LOCATION: ^bb0(%foo_[[x:[0-9]+]]: f32 loc("foo"), %foo_[[y:[0-9]+]]: f32 loc("foo")
+// CHECK-LOCATION: %[[RES:.*]] = "test.special.op"(%foo_[[x]], %foo_[[y]]) : (f32, f32) -> f32
// CHECK-LOCATION: "test.return"(%[[RES]]) : (f32) -> ()
// CHECK-LOCATION: : (f32, f32) -> f32
diff --git a/mlir/test/IR/use-nameloc-as-prefix.mlir b/mlir/test/IR/use-nameloc-as-prefix.mlir
deleted file mode 100644
index ba0b888ee5f80d..00000000000000
--- a/mlir/test/IR/use-nameloc-as-prefix.mlir
+++ /dev/null
@@ -1,231 +0,0 @@
-// RUN: mlir-opt -allow-unregistered-dialect %s -mlir-print-debuginfo -mlir-print-local-scope | FileCheck %s
-// RUN: mlir-opt -allow-unregistered-dialect %s -mlir-print-debuginfo | FileCheck %s --check-prefix=CHECK-ALIAS
-// RUN: mlir-opt -allow-unregistered-dialect %s -mlir-print-debuginfo | mlir-opt -allow-unregistered-dialect -mlir-print-debuginfo | FileCheck %s --check-prefix=CHECK-ALIAS
-// This test verifies that debug locations are round-trippable.
-
-#set0 = affine_set<(d0) : (1 == 0)>
-
-// CHECK-LABEL: func @inline_notation
-func.func @inline_notation() -> i32 {
- // CHECK: -> i32 loc("foo")
- %1 = "foo"() : () -> i32 loc("foo")
-
- // CHECK: arith.constant 4 : index loc(callsite("foo" at "mysource.cc":10:8))
- %2 = arith.constant 4 : index loc(callsite("foo" at "mysource.cc":10:8))
-
- // CHECK: affine.for %arg0 loc("IVlocation") = 0 to 8 {
- // CHECK: } loc(fused["foo", "mysource.cc":10:8])
- affine.for %i0 loc("IVlocation") = 0 to 8 {
- } loc(fused["foo", "mysource.cc":10:8])
-
- // CHECK: } loc(fused<"myPass">["foo", "foo2"])
- affine.if #set0(%2) {
- } loc(fused<"myPass">["foo", "foo2"])
-
- // CHECK: } loc(fused<"myPass">["foo"])
- affine.if #set0(%2) {
- } loc(fused<"myPass">["foo"])
-
- // CHECK: return %0 : i32 loc(unknown)
- return %1 : i32 loc(unknown)
-}
-
-// CHECK-LABEL: func private @loc_attr(i1 {foo.loc_attr = loc(callsite("foo" at "mysource.cc":10:8))})
-func.func private @loc_attr(i1 {foo.loc_attr = loc(callsite("foo" at "mysource.cc":10:8))})
-
-// CHECK-LABEL: func.func private @filelocrange_attr1(i1 {foo.loc_attr = loc("mysource.cc":10:0)})
-func.func private @filelocrange_attr1(i1 {foo.loc_attr = loc("mysource.cc":10)})
-// CHECK-LABEL: func.func private @filelocrange_attr2(i1 {foo.loc_attr = loc("mysource.cc":10:8)})
-func.func private @filelocrange_attr2(i1 {foo.loc_attr = loc("mysource.cc":10:8)})
-// CHECK-LABEL: func.func private @filelocrange_attr3(i1 {foo.loc_attr = loc("mysource.cc":10:8 to :12)})
-func.func private @filelocrange_attr3(i1 {foo.loc_attr = loc("mysource.cc":10:8 to :12)})
-// CHECK-LABEL: func.func private @filelocrange_attr4(i1 {foo.loc_attr = loc("mysource.cc":10:8 to 12:4)})
-func.func private @filelocrange_attr4(i1 {foo.loc_attr = loc("mysource.cc":10:8 to 12:4)})
-
- // Check that locations get properly escaped.
-// CHECK-LABEL: func @escape_strings()
-func.func @escape_strings() {
- // CHECK: loc("escaped\0A")
- "foo"() : () -> () loc("escaped\n")
-
- // CHECK: loc("escaped\0A")
- "foo"() : () -> () loc("escaped\0A")
-
- // CHECK: loc("escaped\0A":0:0)
- "foo"() : () -> () loc("escaped\n":0:0)
- return
-}
-
-// CHECK-ALIAS: "foo.op"() : () -> () loc(#[[LOC:.*]])
-"foo.op"() : () -> () loc(#loc)
-
-// CHECK-LABEL: func @argLocs(
-// CHECK-SAME: %arg0: i32 loc({{.*}}locations.mlir":[[# @LINE+1]]:20),
-func.func @argLocs(%x: i32,
-// CHECK-SAME: %arg1: i64 loc("hotdog")
- %y: i64 loc("hotdog")) {
- return
-}
-
-// CHECK-LABEL: "foo.unknown_op_with_bbargs"()
-// CHECK-ALIAS: "foo.unknown_op_with_bbargs"()
-"foo.unknown_op_with_bbargs"() ({
-// CHECK-NEXT: ^bb0(%arg0: i32 loc({{.*}}locations.mlir":[[# @LINE+2]]:7),
-// CHECK-ALIAS-NEXT: ^bb0(%arg0: i32 loc({{.*}}locations.mlir":[[# @LINE+1]]:7),
- ^bb0(%x: i32,
-// CHECK-SAME: %arg1: i32 loc("cheetos"),
-// CHECK-ALIAS-SAME: %arg1: i32 loc("cheetos"),
- %y: i32 loc("cheetos"),
-// CHECK-SAME: %arg2: i32 loc("out_of_line_location2")):
-// CHECK-ALIAS-SAME: %arg2: i32 loc("out_of_line_location2")):
- %z: i32 loc("out_of_line_location2")):
- %1 = arith.addi %x, %y : i32
- "foo.yield"(%1) : (i32) -> ()
- }) : () -> ()
-
-// CHECK-LABEL: func @location_name_child_is_name
-func.func @location_name_child_is_name() {
- // CHECK: "foo"("foo")
- return loc("foo"("foo"))
-}
-
-// CHECK-ALIAS: #[[LOC]] = loc("out_of_line_location")
-#loc = loc("out_of_line_location")
-
-// CHECK-LABEL: @optional_location_specifier
-// CHECK: test.attr_with_loc("foo" loc("foo_loc"))
-func.func @optional_location_specifier() {
- test.attr_with_loc("foo" loc("foo_loc"))
- return
-}
-
-// CHECK-LABEL: @dialect_location
-// CHECK: test.attr_with_loc("dialectLoc" loc(#test.custom_location<"foo.mlir" * 32>))
-func.func @dialect_location() {
- test.attr_with_loc("dialectLoc" loc(#test.custom_location<"foo.mlir"*32>))
- return
-}
-
-// RUN: mlir-opt -allow-unregistered-dialect %s -mlir-print-debuginfo -mlir-pretty-debuginfo -mlir-print-local-scope | FileCheck %s
-
-#set0 = affine_set<(d0) : (1 == 0)>
-
-// CHECK-LABEL: func @inline_notation
-func.func @inline_notation() -> i32 {
- // CHECK: -> i32 "foo"
- %1 = "foo"() : () -> i32 loc("foo")
-
- // CHECK: arith.constant 4 : index "foo" at mysource.cc:10:8
- %2 = arith.constant 4 : index loc(callsite("foo" at "mysource.cc":10:8))
-
- // CHECK: arith.constant 4 : index "foo"
- // CHECK-NEXT: at mysource1.cc:10:8
- // CHECK-NEXT: at mysource2.cc:13:8
- // CHECK-NEXT: at mysource3.cc:100:10
- %3 = arith.constant 4 : index loc(callsite("foo" at callsite("mysource1.cc":10:8 at callsite("mysource2.cc":13:8 at "mysource3.cc":100:10))))
-
- // CHECK: } ["foo", mysource.cc:10:8]
- affine.for %i0 = 0 to 8 {
- } loc(fused["foo", "mysource.cc":10:8])
-
- // CHECK: } <"myPass">["foo", "foo2"]
- affine.if #set0(%2) {
- } loc(fused<"myPass">["foo", "foo2"])
-
- // CHECK: "foo.op"() : () -> () #test.custom_location<"foo.mlir" * 1234>
- "foo.op"() : () -> () loc(#test.custom_location<"foo.mlir" * 1234>)
-
- // CHECK: return %0 : i32 [unknown]
- return %1 : i32 loc(unknown)
-}
-
-// RUN: mlir-opt -allow-unregistered-dialect -split-input-file %s | FileCheck %s --check-prefixes=CHECK-CUSTOM,CHECK
-// RUN: mlir-opt -allow-unregistered-dialect -mlir-print-op-generic -split-input-file %s | FileCheck %s --check-prefixes=CHECK,CHECK-GENERIC
-// RUN: mlir-opt -allow-unregistered-dialect -split-input-file --mlir-print-op-generic --mlir-print-debuginfo -mlir-print-local-scope %s | FileCheck %s --check-prefixes=CHECK-LOCATION
-
-// -----
-
-func.func @pretty_printed_region_op(%arg0 : f32, %arg1 : f32) -> (f32) {
-// CHECK-CUSTOM: test.pretty_printed_region %arg1, %arg0 start test.special.op end : (f32, f32) -> f32
-// CHECK-GENERIC: "test.pretty_printed_region"(%arg1, %arg0)
-// CHECK-GENERIC: ^bb0(%arg[[x:[0-9]+]]: f32, %arg[[y:[0-9]+]]: f32
-// CHECK-GENERIC: %[[RES:.*]] = "test.special.op"(%arg[[x]], %arg[[y]]) : (f32, f32) -> f32
-// CHECK-GENERIC: "test.return"(%[[RES]]) : (f32) -> ()
-// CHECK-GENERIC: : (f32, f32) -> f32
-
- %res = test.pretty_printed_region %arg1, %arg0 start test.special.op end : (f32, f32) -> (f32) loc("some_NameLoc")
- return %res : f32
-}
-
-// -----
-
-func.func @pretty_printed_region_op(%arg0 : f32, %arg1 : f32) -> (f32) {
-// CHECK-CUSTOM: test.pretty_printed_region %arg1, %arg0
-// CHECK-GENERIC: "test.pretty_printed_region"(%arg1, %arg0)
-// CHECK: ^bb0(%arg[[x:[0-9]+]]: f32, %arg[[y:[0-9]+]]: f32):
-// CHECK: %[[RES:.*]] = "test.non.special.op"(%arg[[x]], %arg[[y]]) : (f32, f32) -> f32
-// CHECK: "test.return"(%[[RES]]) : (f32) -> ()
-// CHECK: : (f32, f32) -> f32
-
- %0 = test.pretty_printed_region %arg1, %arg0 ({
- ^bb0(%arg2: f32, %arg3: f32):
- %1 = "test.non.special.op"(%arg2, %arg3) : (f32, f32) -> f32
- "test.return"(%1) : (f32) -> ()
- }) : (f32, f32) -> f32
- return %0 : f32
-}
-
-// -----
-
-func.func @pretty_printed_region_op_deferred_loc(%arg0 : f32, %arg1 : f32) -> (f32) {
-// CHECK-LOCATION: "test.pretty_printed_region"(%arg1, %arg0)
-// CHECK-LOCATION: ^bb0(%arg[[x:[0-9]+]]: f32 loc("foo"), %arg[[y:[0-9]+]]: f32 loc("foo")
-// CHECK-LOCATION: %[[RES:.*]] = "test.special.op"(%arg[[x]], %arg[[y]]) : (f32, f32) -> f32
-// CHECK-LOCATION: "test.return"(%[[RES]]) : (f32) -> ()
-// CHECK-LOCATION: : (f32, f32) -> f32
-
- %res = test.pretty_printed_region %arg1, %arg0 start test.special.op end : (f32, f32) -> (f32) loc("foo")
- return %res : f32
-}
-
-// -----
-
-// This tests the behavior of custom block names:
-// operations like `test.block_names` can define custom names for blocks in
-// nested regions.
-// CHECK-CUSTOM-LABEL: func @block_names
-func.func @block_names(%bool : i1) {
- // CHECK: test.block_names
- test.block_names {
- // CHECK-CUSTOM: br ^foo1
- // CHECK-GENERIC: cf.br{{.*}}^bb1
- cf.br ^foo1
- // CHECK-CUSTOM: ^foo1:
- // CHECK-GENERIC: ^bb1:
- ^foo1:
- // CHECK-CUSTOM: br ^foo2
- // CHECK-GENERIC: cf.br{{.*}}^bb2
- cf.br ^foo2
- // CHECK-CUSTOM: ^foo2:
- // CHECK-GENERIC: ^bb2:
- ^foo2:
- "test.return"() : () -> ()
- }
- return
-}
-
-// RUN: mlir-opt -allow-unregistered-dialect %s | FileCheck %s
-// RUN: mlir-opt -allow-unregistered-dialect -mlir-print-op-generic -mlir-print-debuginfo -mlir-print-local-scope %s | FileCheck %s --check-prefix=CHECK-GENERIC
-
-// CHECK-LABEL: func @wrapping_op
-// CHECK-GENERIC: "func.func"
-// CHECK-GENERIC-SAME: sym_name = "wrapping_op"
-func.func @wrapping_op(%arg0 : i32, %arg1 : f32) -> (i3, i2, i1) {
-// CHECK: %0:3 = test.wrapping_region wraps "some.op"(%arg1, %arg0) {test.attr = "attr"} : (f32, i32) -> (i1, i2, i3)
-// CHECK-GENERIC: "test.wrapping_region"() ({
-// CHECK-GENERIC: %[[NESTED_RES:.*]]:3 = "some.op"(%arg1, %arg0) {test.attr = "attr"} : (f32, i32) -> (i1, i2, i3) loc("some_NameLoc")
-// CHECK-GENERIC: "test.return"(%[[NESTED_RES]]#0, %[[NESTED_RES]]#1, %[[NESTED_RES]]#2) : (i1, i2, i3) -> () loc("some_NameLoc")
-// CHECK-GENERIC: }) : () -> (i1, i2, i3) loc("some_NameLoc")
- %res:3 = test.wrapping_region wraps "some.op"(%arg1, %arg0) { test.attr = "attr" } : (f32, i32) -> (i1, i2, i3) loc("some_NameLoc")
- return %res#2, %res#1, %res#0 : i3, i2, i1
-}
diff --git a/mlir/test/IR/wrapping_op.mlir b/mlir/test/IR/wrapping_op.mlir
index 3f7a350ee654e7..7ddfca3e4bf64b 100644
--- a/mlir/test/IR/wrapping_op.mlir
+++ b/mlir/test/IR/wrapping_op.mlir
@@ -5,10 +5,10 @@
// CHECK-GENERIC: "func.func"
// CHECK-GENERIC-SAME: sym_name = "wrapping_op"
func.func @wrapping_op(%arg0 : i32, %arg1 : f32) -> (i3, i2, i1) {
-// CHECK: %0:3 = test.wrapping_region wraps "some.op"(%arg1, %arg0) {test.attr = "attr"} : (f32, i32) -> (i1, i2, i3)
+// CHECK: %some_NameLoc, %some_NameLoc_0, %some_NameLoc_1 = test.wrapping_region wraps "some.op"(%arg1, %arg0) {test.attr = "attr"} : (f32, i32) -> (i1, i2, i3)
// CHECK-GENERIC: "test.wrapping_region"() ({
-// CHECK-GENERIC: %[[NESTED_RES:.*]]:3 = "some.op"(%arg1, %arg0) {test.attr = "attr"} : (f32, i32) -> (i1, i2, i3) loc("some_NameLoc")
-// CHECK-GENERIC: "test.return"(%[[NESTED_RES]]#0, %[[NESTED_RES]]#1, %[[NESTED_RES]]#2) : (i1, i2, i3) -> () loc("some_NameLoc")
+// CHECK-GENERIC: %some_NameLoc_2, %some_NameLoc_3, %some_NameLoc_4 = "some.op"(%arg1, %arg0) {test.attr = "attr"} : (f32, i32) -> (i1, i2, i3) loc("some_NameLoc")
+// CHECK-GENERIC: "test.return"(%some_NameLoc_2, %some_NameLoc_3, %some_NameLoc_4) : (i1, i2, i3) -> () loc("some_NameLoc")
// CHECK-GENERIC: }) : () -> (i1, i2, i3) loc("some_NameLoc")
%res:3 = test.wrapping_region wraps "some.op"(%arg1, %arg0) { test.attr = "attr" } : (f32, i32) -> (i1, i2, i3) loc("some_NameLoc")
return %res#2, %res#1, %res#0 : i3, i2, i1
diff --git a/mlir/test/mlir-tblgen/pattern.mlir b/mlir/test/mlir-tblgen/pattern.mlir
index 60d46e676d2a33..5594e80420a722 100644
--- a/mlir/test/mlir-tblgen/pattern.mlir
+++ b/mlir/test/mlir-tblgen/pattern.mlir
@@ -678,7 +678,7 @@ func.func @returnTypeAndLocation(%arg0 : i32) -> i1 {
%0 = "test.source_op"(%arg0) {tag = 66 : i32} : (i32) -> i1
// CHECK: "test.op_x"(%arg0) : (i32) -> i32 loc("loc1")
// CHECK: "test.op_x"(%arg0) : (i32) -> i32 loc("loc2")
- // CHECK: "test.two_to_one"(%0, %1) : (i32, i32) -> i1
+ // CHECK: "test.two_to_one"(%loc1, %loc2) : (i32, i32) -> i1
return %0 : i1
}
More information about the Mlir-commits
mailing list