Skip to content

[MLIR][IR] Fix InProgressAliasInfo init for non-alias #109013

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions mlir/lib/IR/AsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -584,9 +584,8 @@ class AliasInitializer {
struct InProgressAliasInfo {
InProgressAliasInfo()
: aliasDepth(0), isType(false), canBeDeferred(false) {}
InProgressAliasInfo(StringRef alias, bool isType, bool canBeDeferred)
: alias(alias), aliasDepth(1), isType(isType),
canBeDeferred(canBeDeferred) {}
InProgressAliasInfo(StringRef alias)
: alias(alias), aliasDepth(1), isType(false), canBeDeferred(false) {}

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

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

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

//===----------------------------------------------------------------------===//
Expand Down
27 changes: 20 additions & 7 deletions mlir/test/IR/print-attr-type-aliases.mlir
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// RUN: mlir-opt %s -split-input-file | FileCheck %s
// RUN: mlir-opt %s -split-input-file -mlir-print-debuginfo | FileCheck %s
// Verify printer of type & attr aliases.
// RUN: mlir-opt %s -split-input-file | mlir-opt -split-input-file | FileCheck %s
// RUN: mlir-opt %s -split-input-file -mlir-print-debuginfo | mlir-opt -split-input-file -mlir-print-debuginfo | FileCheck %s

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

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

// -----

// Check proper ordering of intermixed attribute/type aliases.
// CHECK: !tuple = tuple<
// CHECK: #loc1 = loc(fused<!tuple
// CHECK: = loc(fused<!tuple
"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])} : () -> ()

// -----
Expand All @@ -54,7 +54,7 @@
// -----

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

Expand All @@ -71,3 +71,16 @@
"test.op"() {attr = #test.conditional_alias<#unalias_me>} : () -> ()
// CHECK-NEXT: #test.conditional_alias<#test2Ealias>
"test.op"() {attr = #test.conditional_alias<#keep_aliased>} : () -> ()

// -----

// Check that a deferred no_alias attr can be un-deferred.

#keep_aliased = "alias_test:dot_in_name"
#cond_alias = #test.conditional_alias<#keep_aliased>
#no_alias = loc(fused<#cond_alias>["test.mlir":1:1])

// CHECK: #[[TEST_ALIAS:.+]] = "alias_test:dot_in_name"
// CHECK: fused<#test.conditional_alias<#[[TEST_ALIAS]]>
// CHECK: "test.op"
"test.op"() {attr = #no_alias} : () -> () loc(fused<#no_alias>["test.mlir":0:0])
Loading