[Mlir-commits] [mlir] [MLIR] Model llvm.inline_asm side_effects (PR #91507)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Wed May 8 10:27:13 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
Author: Thomas Raoux (ThomasRaoux)
<details>
<summary>Changes</summary>
Allow more cleanups on inline_asm ops modeling side effects based on the side_effect attributed.
---
Full diff: https://github.com/llvm/llvm-project/pull/91507.diff
3 Files Affected:
- (modified) mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td (+1-1)
- (modified) mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp (+13)
- (modified) mlir/test/Dialect/LLVMIR/canonicalize.mlir (+11)
``````````diff
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
index 6655ce6f123e1..4b91708ea1aa7 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
@@ -1795,7 +1795,7 @@ def LLVM_FenceOp : LLVM_Op<"fence">, LLVM_MemOpPatterns {
let hasVerifier = 1;
}
-def LLVM_InlineAsmOp : LLVM_Op<"inline_asm", []> {
+def LLVM_InlineAsmOp : LLVM_Op<"inline_asm", [DeclareOpInterfaceMethods<MemoryEffectsOpInterface>]> {
let description = [{
The InlineAsmOp mirrors the underlying LLVM semantics with a notable
exception: the embedded `asm_string` is not allowed to define or reference
diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
index 7be493d5992c4..7d33d05feb650 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
@@ -3034,6 +3034,19 @@ LogicalResult LinkerOptionsOp::verify() {
return success();
}
+//===----------------------------------------------------------------------===//
+// InlineAsmOp
+//===----------------------------------------------------------------------===//
+
+void InlineAsmOp::getEffects(
+ SmallVectorImpl<SideEffects::EffectInstance<MemoryEffects::Effect>>
+ &effects) {
+ if (getHasSideEffects()) {
+ effects.emplace_back(MemoryEffects::Write::get());
+ effects.emplace_back(MemoryEffects::Read::get());
+ }
+}
+
//===----------------------------------------------------------------------===//
// LLVMDialect initialization, type parsing, and registration.
//===----------------------------------------------------------------------===//
diff --git a/mlir/test/Dialect/LLVMIR/canonicalize.mlir b/mlir/test/Dialect/LLVMIR/canonicalize.mlir
index 6b265bbbdbfb2..15f960167cb5f 100644
--- a/mlir/test/Dialect/LLVMIR/canonicalize.mlir
+++ b/mlir/test/Dialect/LLVMIR/canonicalize.mlir
@@ -248,3 +248,14 @@ llvm.func @volatile_load(%x : !llvm.ptr) {
%3 = llvm.load %x atomic unordered { alignment = 1 } : !llvm.ptr -> i8
llvm.return
}
+
+// -----
+
+// CHECK-LABEL: func @inline_asm_side_effects
+llvm.func @inline_asm_side_effects(%x : i32) {
+ // CHECK-NOT: llvm.inline_asm "pure inline asm"
+ llvm.inline_asm "pure inline asm", "r" %x : (i32) -> ()
+ // CHECK: llvm.inline_asm has_side_effects "inline asm with side effects"
+ llvm.inline_asm has_side_effects "inline asm with side effects", "r" %x : (i32) -> ()
+ llvm.return
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/91507
More information about the Mlir-commits
mailing list