[Mlir-commits] [mlir] a33018d - [MLIR][LLVM] Allowlist more side-effecting operations in LLVM inliner.

Johannes de Fine Licht llvmlistbot at llvm.org
Thu Mar 30 04:45:18 PDT 2023


Author: Johannes de Fine Licht
Date: 2023-03-30T11:41:51Z
New Revision: a33018d01bd6a0a8dd50c5d26f03e9b827e51126

URL: https://github.com/llvm/llvm-project/commit/a33018d01bd6a0a8dd50c5d26f03e9b827e51126
DIFF: https://github.com/llvm/llvm-project/commit/a33018d01bd6a0a8dd50c5d26f03e9b827e51126.diff

LOG: [MLIR][LLVM] Allowlist more side-effecting operations in LLVM inliner.

These operations do not on their own require special handling to be
inlined, and can just be inlined as is.

Reviewed By: gysit

Differential Revision: https://reviews.llvm.org/D147148

Added: 
    

Modified: 
    mlir/lib/Dialect/LLVMIR/IR/LLVMInlining.cpp
    mlir/test/Dialect/LLVMIR/inlining.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMInlining.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMInlining.cpp
index bd1a14476f991..b1a3fb7ac55f9 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMInlining.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMInlining.cpp
@@ -289,14 +289,25 @@ struct LLVMInlinerInterface : public DialectInlinerInterface {
         return false;
       }
     }
-    if (!isa<LLVM::CallOp, LLVM::AllocaOp, LLVM::LifetimeStartOp,
-             LLVM::LifetimeEndOp, LLVM::LoadOp, LLVM::StoreOp>(op)) {
-      LLVM_DEBUG(llvm::dbgs()
-                 << "Cannot inline: unhandled side effecting operation \""
-                 << op->getName() << "\"\n");
-      return false;
-    }
-    return true;
+    // clang-format off
+    if (isa<LLVM::AllocaOp,
+            LLVM::CallOp,
+            LLVM::DbgDeclareOp,
+            LLVM::DbgValueOp,
+            LLVM::LifetimeEndOp,
+            LLVM::LifetimeStartOp,
+            LLVM::LoadOp,
+            LLVM::MemcpyOp,
+            LLVM::MemmoveOp,
+            LLVM::MemsetOp,
+            LLVM::StoreOp,
+            LLVM::UnreachableOp>(op))
+      return true;
+    // clang-format on
+    LLVM_DEBUG(llvm::dbgs()
+               << "Cannot inline: unhandled side effecting operation \""
+               << op->getName() << "\"\n");
+    return false;
   }
 
   /// Handle the given inlined return by replacing it with a branch. This

diff  --git a/mlir/test/Dialect/LLVMIR/inlining.mlir b/mlir/test/Dialect/LLVMIR/inlining.mlir
index e059ab3be6d1c..afaa776c2d013 100644
--- a/mlir/test/Dialect/LLVMIR/inlining.mlir
+++ b/mlir/test/Dialect/LLVMIR/inlining.mlir
@@ -1,18 +1,38 @@
 // RUN: mlir-opt %s -inline -split-input-file | FileCheck %s
 
+#file = #llvm.di_file<"foo.mlir" in "/foo/">
+#variable = #llvm.di_local_variable<scope = #file>
+#variableAddr = #llvm.di_local_variable<scope = #file>
+
 func.func @inner_func_inlinable(%ptr : !llvm.ptr) -> i32 {
   %0 = llvm.mlir.constant(42 : i32) : i32
   llvm.store %0, %ptr { alignment = 8 } : i32, !llvm.ptr
   %1 = llvm.load %ptr { alignment = 8 } : !llvm.ptr -> i32
+  llvm.intr.dbg.value #variable = %0 : i32
+  llvm.intr.dbg.declare #variableAddr = %ptr : !llvm.ptr
+  %byte = llvm.mlir.constant(43 : i8) : i8
+  %volatile = llvm.mlir.constant(1 : i1) : i1
+  "llvm.intr.memset"(%ptr, %byte, %0, %volatile) : (!llvm.ptr, i8, i32, i1) -> ()
+  "llvm.intr.memmove"(%ptr, %ptr, %0, %volatile) : (!llvm.ptr, !llvm.ptr, i32, i1) -> ()
+  "llvm.intr.memcpy"(%ptr, %ptr, %0, %volatile) : (!llvm.ptr, !llvm.ptr, i32, i1) -> ()
+  llvm.cond_br %volatile, ^bb1, ^bb2
+^bb1:
+  llvm.unreachable
+^bb2:
   return %1 : i32
 }
 
 // CHECK-LABEL: func.func @test_inline(
 // CHECK-SAME: %[[PTR:[a-zA-Z0-9_]+]]
-// CHECK-NEXT: %[[CST:.*]] = llvm.mlir.constant(42 : i32) : i32
-// CHECK-NEXT: llvm.store %[[CST]], %[[PTR]]
-// CHECK-NEXT: %[[RES:.+]] = llvm.load %[[PTR]]
-// CHECK-NEXT: return %[[RES]] : i32
+// CHECK: %[[CST:.*]] = llvm.mlir.constant(42
+// CHECK: llvm.store %[[CST]], %[[PTR]]
+// CHECK: %[[RES:.+]] = llvm.load %[[PTR]]
+// CHECK: llvm.intr.dbg.value #{{.+}} = %[[CST]]
+// CHECK: llvm.intr.dbg.declare #{{.+}} = %[[PTR]]
+// CHECK: "llvm.intr.memset"(%[[PTR]]
+// CHECK: "llvm.intr.memmove"(%[[PTR]], %[[PTR]]
+// CHECK: "llvm.intr.memcpy"(%[[PTR]], %[[PTR]]
+// CHECK: llvm.unreachable
 func.func @test_inline(%ptr : !llvm.ptr) -> i32 {
   %0 = call @inner_func_inlinable(%ptr) : (!llvm.ptr) -> i32
   return %0 : i32


        


More information about the Mlir-commits mailing list