Skip to content

Commit 5526c8a

Browse files
authored
[MLIR] Model llvm.inline_asm side_effects (#91507)
Allow more cleanups on inline_asm ops modeling side effects based on the side_effect attributed.
1 parent 9047331 commit 5526c8a

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1795,7 +1795,7 @@ def LLVM_FenceOp : LLVM_Op<"fence">, LLVM_MemOpPatterns {
17951795
let hasVerifier = 1;
17961796
}
17971797

1798-
def LLVM_InlineAsmOp : LLVM_Op<"inline_asm", []> {
1798+
def LLVM_InlineAsmOp : LLVM_Op<"inline_asm", [DeclareOpInterfaceMethods<MemoryEffectsOpInterface>]> {
17991799
let description = [{
18001800
The InlineAsmOp mirrors the underlying LLVM semantics with a notable
18011801
exception: the embedded `asm_string` is not allowed to define or reference

mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3034,6 +3034,19 @@ LogicalResult LinkerOptionsOp::verify() {
30343034
return success();
30353035
}
30363036

3037+
//===----------------------------------------------------------------------===//
3038+
// InlineAsmOp
3039+
//===----------------------------------------------------------------------===//
3040+
3041+
void InlineAsmOp::getEffects(
3042+
SmallVectorImpl<SideEffects::EffectInstance<MemoryEffects::Effect>>
3043+
&effects) {
3044+
if (getHasSideEffects()) {
3045+
effects.emplace_back(MemoryEffects::Write::get());
3046+
effects.emplace_back(MemoryEffects::Read::get());
3047+
}
3048+
}
3049+
30373050
//===----------------------------------------------------------------------===//
30383051
// LLVMDialect initialization, type parsing, and registration.
30393052
//===----------------------------------------------------------------------===//

mlir/test/Dialect/LLVMIR/canonicalize.mlir

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,3 +248,14 @@ llvm.func @volatile_load(%x : !llvm.ptr) {
248248
%3 = llvm.load %x atomic unordered { alignment = 1 } : !llvm.ptr -> i8
249249
llvm.return
250250
}
251+
252+
// -----
253+
254+
// CHECK-LABEL: func @inline_asm_side_effects
255+
llvm.func @inline_asm_side_effects(%x : i32) {
256+
// CHECK-NOT: llvm.inline_asm "pure inline asm"
257+
llvm.inline_asm "pure inline asm", "r" %x : (i32) -> ()
258+
// CHECK: llvm.inline_asm has_side_effects "inline asm with side effects"
259+
llvm.inline_asm has_side_effects "inline asm with side effects", "r" %x : (i32) -> ()
260+
llvm.return
261+
}

0 commit comments

Comments
 (0)