[Mlir-commits] [mlir] [mlir][llvm] Respect call noinline attr in inliner (PR #134493)
Tobias Gysi
llvmlistbot at llvm.org
Sat Apr 5 04:16:42 PDT 2025
https://github.com/gysit created https://github.com/llvm/llvm-project/pull/134493
This commit extends the LLVM dialect inliner interface to respect the call op's noinline attribute. This is a follow-up to https://github.com/llvm/llvm-project/pull/133726
which added the noinline attribute to the LLVM dialect call op.
>From 326e2880a35d838ef655d1cefef3c8d45ee9b432 Mon Sep 17 00:00:00 2001
From: Tobias Gysi <tobias.gysi at nextsilicon.com>
Date: Sat, 5 Apr 2025 11:55:37 +0200
Subject: [PATCH] [mlir][llvm] Respect call noinline attr in inliner
This commit extends the LLVM dialect inliner interface to respect the
call op's noinline attribute. This is a follow-up to
https://github.com/llvm/llvm-project/pull/133726
which added the noinline attribute to the LLVM dialect call op.
---
.../lib/Dialect/LLVMIR/Transforms/InlinerInterfaceImpl.cpp | 7 ++++++-
mlir/test/Dialect/LLVMIR/inlining.mlir | 4 ++--
2 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/mlir/lib/Dialect/LLVMIR/Transforms/InlinerInterfaceImpl.cpp b/mlir/lib/Dialect/LLVMIR/Transforms/InlinerInterfaceImpl.cpp
index aab8d037cd8d2..1edf7fd070b27 100644
--- a/mlir/lib/Dialect/LLVMIR/Transforms/InlinerInterfaceImpl.cpp
+++ b/mlir/lib/Dialect/LLVMIR/Transforms/InlinerInterfaceImpl.cpp
@@ -664,11 +664,16 @@ struct LLVMInlinerInterface : public DialectInlinerInterface {
bool isLegalToInline(Operation *call, Operation *callable,
bool wouldBeCloned) const final {
- if (!isa<LLVM::CallOp>(call)) {
+ auto callOp = dyn_cast<LLVM::CallOp>(call);
+ if (!callOp) {
LLVM_DEBUG(llvm::dbgs() << "Cannot inline: call is not an '"
<< LLVM::CallOp::getOperationName() << "' op\n");
return false;
}
+ if (callOp.getNoInline()) {
+ LLVM_DEBUG(llvm::dbgs() << "Cannot inline: call is marked no_inline\n");
+ return false;
+ }
auto funcOp = dyn_cast<LLVM::LLVMFuncOp>(callable);
if (!funcOp) {
LLVM_DEBUG(llvm::dbgs()
diff --git a/mlir/test/Dialect/LLVMIR/inlining.mlir b/mlir/test/Dialect/LLVMIR/inlining.mlir
index eb249a4771753..136d0f85d509a 100644
--- a/mlir/test/Dialect/LLVMIR/inlining.mlir
+++ b/mlir/test/Dialect/LLVMIR/inlining.mlir
@@ -95,7 +95,7 @@ llvm.func @foo() -> (i32) attributes { no_inline } {
llvm.return %0 : i32
}
-llvm.func @bar() -> (i32) attributes { no_inline } {
+llvm.func @bar() -> (i32) {
%0 = llvm.mlir.constant(1 : i32) : i32
llvm.return %0 : i32
}
@@ -106,7 +106,7 @@ llvm.func @callee_with_multiple_blocks(%cond: i1) -> (i32) {
%0 = llvm.call @foo() : () -> (i32)
llvm.br ^bb3(%0: i32)
^bb2:
- %1 = llvm.call @bar() : () -> (i32)
+ %1 = llvm.call @bar() { no_inline } : () -> (i32)
llvm.br ^bb3(%1: i32)
^bb3(%arg: i32):
llvm.return %arg : i32
More information about the Mlir-commits
mailing list