Skip to content

Commit 08b1d20

Browse files
zyx-billytmsri
authored andcommitted
[MLIR][IR] Fix InProgressAliasInfo init for non-alias (llvm#109013)
When visiting an attr/type that is NoAlias, the created `InProgressAliasInfo` was not getting its `canBeDeferred` and `isType` fields set. Not setting `canBeDeferred` when it should be true breaks the assumption that all nested elements are also false. This will cause problems when at a later point the attr/type needs to be converted by `markAliasNonDeferrable`, as recursion will stop when a `canBeDeferred=false` attr/type is reached, leaving its nested elements not flipped. This causes nested elements to be printed later in the textual IR and cannot be parsed back in.
1 parent dddc84d commit 08b1d20

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

mlir/lib/IR/AsmPrinter.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -584,9 +584,8 @@ class AliasInitializer {
584584
struct InProgressAliasInfo {
585585
InProgressAliasInfo()
586586
: aliasDepth(0), isType(false), canBeDeferred(false) {}
587-
InProgressAliasInfo(StringRef alias, bool isType, bool canBeDeferred)
588-
: alias(alias), aliasDepth(1), isType(isType),
589-
canBeDeferred(canBeDeferred) {}
587+
InProgressAliasInfo(StringRef alias)
588+
: alias(alias), aliasDepth(1), isType(false), canBeDeferred(false) {}
590589

591590
bool operator<(const InProgressAliasInfo &rhs) const {
592591
// Order first by depth, then by attr/type kind, and then by name.
@@ -1096,6 +1095,8 @@ std::pair<size_t, size_t> AliasInitializer::visitImpl(
10961095

10971096
// Try to generate an alias for this value.
10981097
generateAlias(value, it->second, canBeDeferred);
1098+
it->second.isType = std::is_base_of_v<Type, T>;
1099+
it->second.canBeDeferred = canBeDeferred;
10991100

11001101
// Print the value, capturing any nested elements that require aliases.
11011102
SmallVector<size_t> childAliases;
@@ -1153,8 +1154,7 @@ void AliasInitializer::generateAlias(T symbol, InProgressAliasInfo &alias,
11531154
sanitizeIdentifier(nameBuffer, tempBuffer, /*allowedPunctChars=*/"$_-",
11541155
/*allowTrailingDigit=*/false);
11551156
name = name.copy(aliasAllocator);
1156-
alias = InProgressAliasInfo(name, /*isType=*/std::is_base_of_v<Type, T>,
1157-
canBeDeferred);
1157+
alias = InProgressAliasInfo(name);
11581158
}
11591159

11601160
//===----------------------------------------------------------------------===//

mlir/test/IR/print-attr-type-aliases.mlir

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// RUN: mlir-opt %s -split-input-file | FileCheck %s
1+
// RUN: mlir-opt %s -split-input-file -mlir-print-debuginfo | FileCheck %s
22
// Verify printer of type & attr aliases.
3-
// RUN: mlir-opt %s -split-input-file | mlir-opt -split-input-file | FileCheck %s
3+
// RUN: mlir-opt %s -split-input-file -mlir-print-debuginfo | mlir-opt -split-input-file -mlir-print-debuginfo | FileCheck %s
44

55
// CHECK-DAG: #test2Ealias = "alias_test:dot_in_name"
66
"test.op"() {alias_test = "alias_test:dot_in_name"} : () -> ()
@@ -32,16 +32,16 @@
3232
// CHECK-DAG: tensor<32x!test_ui8_>
3333
"test.op"() : () -> tensor<32x!test.int<unsigned, 8>>
3434

35-
// CHECK-DAG: #loc = loc("nested")
36-
// CHECK-DAG: #loc1 = loc("test.mlir":10:8)
37-
// CHECK-DAG: #loc2 = loc(fused<#loc>[#loc1])
35+
// CHECK-DAG: #[[LOC_NESTED:.+]] = loc("nested")
36+
// CHECK-DAG: #[[LOC_RAW:.+]] = loc("test.mlir":10:8)
37+
// CHECK-DAG: = loc(fused<#[[LOC_NESTED]]>[#[[LOC_RAW]]])
3838
"test.op"() {alias_test = loc(fused<loc("nested")>["test.mlir":10:8])} : () -> ()
3939

4040
// -----
4141

4242
// Check proper ordering of intermixed attribute/type aliases.
4343
// CHECK: !tuple = tuple<
44-
// CHECK: #loc1 = loc(fused<!tuple
44+
// CHECK: = loc(fused<!tuple
4545
"test.op"() {alias_test = loc(fused<tuple<i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32>>["test.mlir":10:8])} : () -> ()
4646

4747
// -----
@@ -54,7 +54,7 @@
5454
// -----
5555

5656
// Check that we don't print aliases for things that aren't printed.
57-
// CHECK: #loc1 = loc(fused<memref<1xi32>
57+
// CHECK: = loc(fused<memref<1xi32>
5858
// CHECK-NOT: #map
5959
"test.op"() {alias_test = loc(fused<memref<1xi32, affine_map<(d0) -> (d0)>>>["test.mlir":10:8])} : () -> ()
6060

@@ -71,3 +71,16 @@
7171
"test.op"() {attr = #test.conditional_alias<#unalias_me>} : () -> ()
7272
// CHECK-NEXT: #test.conditional_alias<#test2Ealias>
7373
"test.op"() {attr = #test.conditional_alias<#keep_aliased>} : () -> ()
74+
75+
// -----
76+
77+
// Check that a deferred no_alias attr can be un-deferred.
78+
79+
#keep_aliased = "alias_test:dot_in_name"
80+
#cond_alias = #test.conditional_alias<#keep_aliased>
81+
#no_alias = loc(fused<#cond_alias>["test.mlir":1:1])
82+
83+
// CHECK: #[[TEST_ALIAS:.+]] = "alias_test:dot_in_name"
84+
// CHECK: fused<#test.conditional_alias<#[[TEST_ALIAS]]>
85+
// CHECK: "test.op"
86+
"test.op"() {attr = #no_alias} : () -> () loc(fused<#no_alias>["test.mlir":0:0])

0 commit comments

Comments
 (0)