[Mlir-commits] [mlir] Allow SymbolUserOpInterface operators to be used in RemoveDeadValues Pass (PR #117405)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri Nov 22 16:10:20 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
Author: M. Zeeshan Siddiqui (codemzs)
<details>
<summary>Changes</summary>
Pursuant to the conversation at https://github.com/llvm/llvm-project/pull/116519 this change removes the restriction on `SymbolUserOpInterface` operators so they can be used with operators that implement `SymbolOpInterface`, example:
`memref.global` implements `SymbolOpInterface` so it can be used with `memref.get_global` which implements `SymbolUserOpInterface`
```
// Define a global constant array
memref.global "private" constant @<!-- -->global_array : memref<10xi32> = dense<[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]> : tensor<10xi32>
// Access this global constant within a function
func @<!-- -->use_global() {
%0 = memref.get_global @<!-- -->global_array : memref<10xi32>
// Use %0 as needed
}
```
---
Full diff: https://github.com/llvm/llvm-project/pull/117405.diff
2 Files Affected:
- (modified) mlir/lib/Transforms/RemoveDeadValues.cpp (+2-4)
- (modified) mlir/test/Transforms/remove-dead-values.mlir (+2-1)
``````````diff
diff --git a/mlir/lib/Transforms/RemoveDeadValues.cpp b/mlir/lib/Transforms/RemoveDeadValues.cpp
index b82280dda8ba73..0aa9dcb36681b3 100644
--- a/mlir/lib/Transforms/RemoveDeadValues.cpp
+++ b/mlir/lib/Transforms/RemoveDeadValues.cpp
@@ -577,10 +577,8 @@ void RemoveDeadValues::runOnOperation() {
WalkResult acceptableIR = module->walk([&](Operation *op) {
if (op == module)
return WalkResult::advance();
- if (isa<BranchOpInterface>(op) ||
- (isa<SymbolUserOpInterface>(op) && !isa<CallOpInterface>(op))) {
- op->emitError() << "cannot optimize an IR with "
- "non-call symbol user ops or branch ops\n";
+ if (isa<BranchOpInterface>(op)) {
+ op->emitError() << "cannot optimize an IR with branch ops\n";
return WalkResult::interrupt();
}
return WalkResult::advance();
diff --git a/mlir/test/Transforms/remove-dead-values.mlir b/mlir/test/Transforms/remove-dead-values.mlir
index 47137fc6430fea..7a8d49681a4b18 100644
--- a/mlir/test/Transforms/remove-dead-values.mlir
+++ b/mlir/test/Transforms/remove-dead-values.mlir
@@ -3,9 +3,10 @@
// The IR is updated regardless of memref.global private constant
//
module {
- memref.global "private" constant @__something_global : memref<i32> = dense<0>
+ memref.global "private" constant @global_buffer : memref<5xi32> = dense<[1, 2, 3, 4, 5]> : tensor<5xi32>
func.func @main(%arg0: i32) -> i32 {
%0 = tensor.empty() : tensor<10xbf16>
+ %1 = memref.get_global @global_buffer : memref<5xi32>
// CHECK-NOT: tensor.empty
return %arg0 : i32
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/117405
More information about the Mlir-commits
mailing list