Skip to content

[mlir][llvm] Respect call noinline attr in inliner #134493

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 7, 2025

Conversation

gysit
Copy link
Contributor

@gysit gysit commented Apr 5, 2025

This commit extends the LLVM dialect inliner interface to respect the call op's noinline attribute. This is a follow-up to #133726
which added the noinline attribute to the LLVM dialect call op.

This commit extends the LLVM dialect inliner interface to respect the
call op's noinline attribute. This is a follow-up to
llvm#133726
which added the noinline attribute to the LLVM dialect call op.
@llvmbot
Copy link
Member

llvmbot commented Apr 5, 2025

@llvm/pr-subscribers-mlir-llvm

@llvm/pr-subscribers-mlir

Author: Tobias Gysi (gysit)

Changes

This commit extends the LLVM dialect inliner interface to respect the call op's noinline attribute. This is a follow-up to #133726
which added the noinline attribute to the LLVM dialect call op.


Full diff: https://github.com/llvm/llvm-project/pull/134493.diff

2 Files Affected:

  • (modified) mlir/lib/Dialect/LLVMIR/Transforms/InlinerInterfaceImpl.cpp (+6-1)
  • (modified) mlir/test/Dialect/LLVMIR/inlining.mlir (+2-2)
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

Copy link
Collaborator

@joker-eph joker-eph left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG, thanks!

@gysit gysit merged commit d9ccfd7 into llvm:main Apr 7, 2025
12 of 14 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Apr 7, 2025

LLVM Buildbot has detected a new failure on builder clang-aarch64-sve2-vla-2stage running on linaro-g4-02 while building mlir at step 12 "ninja check 2".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/199/builds/2636

Here is the relevant piece of the build log for the reference
Step 12 (ninja check 2) failure: stage 2 checked (failure)
...
PASS: Flang :: Driver/print-resource-dir.F90 (24781 of 96621)
PASS: Flang :: Driver/linker-flags.f90 (24782 of 96621)
PASS: Flang :: Driver/print-effective-triple.f90 (24783 of 96621)
PASS: Flang :: Driver/predefined-macros-compiler-version.F90 (24784 of 96621)
PASS: Flang :: Driver/macro-def-undef.F90 (24785 of 96621)
PASS: Flang :: Driver/parse-error.ll (24786 of 96621)
PASS: Flang :: Driver/override-triple.ll (24787 of 96621)
PASS: Flang :: Driver/phases.f90 (24788 of 96621)
PASS: Flang :: Driver/parse-fir-error.ll (24789 of 96621)
UNRESOLVED: Flang :: Driver/slp-vectorize.ll (24790 of 96621)
******************** TEST 'Flang :: Driver/slp-vectorize.ll' FAILED ********************
Test has no 'RUN:' line
********************
PASS: Flang :: Driver/print-pipeline-passes.f90 (24791 of 96621)
PASS: Flang :: Driver/print-target-triple.f90 (24792 of 96621)
PASS: Flang :: Driver/fixed-line-length.f90 (24793 of 96621)
PASS: Flang :: Driver/mlir-pass-pipeline.f90 (24794 of 96621)
PASS: Flang :: Driver/parse-ir-error.f95 (24795 of 96621)
PASS: Flang :: Driver/mlink-builtin-bc.f90 (24796 of 96621)
PASS: Flang :: Driver/missing-arg.f90 (24797 of 96621)
PASS: Clangd Unit Tests :: ./ClangdTests/73/81 (24798 of 96621)
PASS: Flang :: Driver/lto-bc.f90 (24799 of 96621)
PASS: Flang :: Driver/pthread.f90 (24800 of 96621)
PASS: Flang :: Driver/pp-fixed-form.f90 (24801 of 96621)
PASS: Flang :: Driver/std2018-wrong.f90 (24802 of 96621)
PASS: Flang :: Driver/scanning-error.f95 (24803 of 96621)
PASS: Flang :: Driver/pass-plugin-not-found.f90 (24804 of 96621)
PASS: Flang :: Driver/supported-suffices/f03-suffix.f03 (24805 of 96621)
PASS: Flang :: Driver/tco-code-gen-llvm.fir (24806 of 96621)
PASS: Flang :: Driver/target-gpu-features.f90 (24807 of 96621)
PASS: Flang :: Driver/target.f90 (24808 of 96621)
PASS: Flang :: Driver/supported-suffices/f08-suffix.f08 (24809 of 96621)
PASS: Flang :: Driver/q-unused-arguments.f90 (24810 of 96621)
PASS: Flang :: Driver/mllvm.f90 (24811 of 96621)
PASS: Flang :: Driver/fsave-optimization-record.f90 (24812 of 96621)
PASS: Flang :: Driver/multiple-input-files.f90 (24813 of 96621)
PASS: Flang :: Driver/unsupported-vscale-max-min.f90 (24814 of 96621)
PASS: Flang :: Driver/input-from-stdin/input-from-stdin.f90 (24815 of 96621)
PASS: Flang :: Driver/target-machine-error.f90 (24816 of 96621)
PASS: Flang :: Driver/unparse-with-modules.f90 (24817 of 96621)
PASS: Flang :: Driver/prescanner-diag.f90 (24818 of 96621)
PASS: Flang :: Driver/lto-flags.f90 (24819 of 96621)
PASS: Flang :: Driver/optimization-remark-invalid.f90 (24820 of 96621)
PASS: Flang :: Driver/no-duplicate-main.f90 (24821 of 96621)
PASS: Flang :: Driver/unparse-use-analyzed.f95 (24822 of 96621)
PASS: Flang :: Driver/save-temps.f90 (24823 of 96621)
PASS: Flang :: Driver/std2018.f90 (24824 of 96621)
PASS: Flang :: Driver/w-arg-unsupported.f90 (24825 of 96621)
PASS: Flang :: Driver/optimization-remark-backend.f90 (24826 of 96621)

@llvm-ci
Copy link
Collaborator

llvm-ci commented Apr 7, 2025

LLVM Buildbot has detected a new failure on builder clang-aarch64-sve-vla-2stage running on linaro-g3-01 while building mlir at step 12 "ninja check 2".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/41/builds/5983

Here is the relevant piece of the build log for the reference
Step 12 (ninja check 2) failure: stage 2 checked (failure)
...
PASS: Flang :: Driver/fd-lines-as.f90 (25216 of 97666)
PASS: Flang :: Driver/fveclib-codegen.f90 (25217 of 97666)
PASS: Flang :: Driver/lto-bc.f90 (25218 of 97666)
PASS: Flang :: Driver/override-triple.ll (25219 of 97666)
PASS: Flang :: Driver/parse-error.ll (25220 of 97666)
PASS: Flang :: Driver/frepack-arrays-contiguity.f90 (25221 of 97666)
PASS: Flang :: Driver/print-pipeline-passes.f90 (25222 of 97666)
PASS: Flang :: Driver/print-resource-dir.F90 (25223 of 97666)
PASS: Flang :: Driver/print-target-triple.f90 (25224 of 97666)
UNRESOLVED: Flang :: Driver/slp-vectorize.ll (25225 of 97666)
******************** TEST 'Flang :: Driver/slp-vectorize.ll' FAILED ********************
Test has no 'RUN:' line
********************
PASS: Flang :: Driver/parse-ir-error.f95 (25226 of 97666)
PASS: Flang :: Driver/include-header.f90 (25227 of 97666)
PASS: Flang :: Driver/print-effective-triple.f90 (25228 of 97666)
PASS: Flang :: Driver/config-file.f90 (25229 of 97666)
PASS: Flang :: Driver/phases.f90 (25230 of 97666)
PASS: Flang :: Driver/supported-suffices/f03-suffix.f03 (25231 of 97666)
PASS: Flang :: Driver/bbc-openmp-version-macro.f90 (25232 of 97666)
PASS: Flang :: Driver/missing-arg.f90 (25233 of 97666)
PASS: Flang :: Driver/pthread.f90 (25234 of 97666)
PASS: Flang :: Driver/mlir-pass-pipeline.f90 (25235 of 97666)
PASS: Flang :: Driver/scanning-error.f95 (25236 of 97666)
PASS: Flang :: Driver/parse-fir-error.ll (25237 of 97666)
PASS: Flang :: Driver/std2018-wrong.f90 (25238 of 97666)
PASS: Flang :: Driver/supported-suffices/f08-suffix.f08 (25239 of 97666)
PASS: Flang :: Driver/target-gpu-features.f90 (25240 of 97666)
PASS: Flang :: Driver/tco-code-gen-llvm.fir (25241 of 97666)
PASS: Flang :: Driver/mllvm.f90 (25242 of 97666)
PASS: Flang :: Driver/unsupported-vscale-max-min.f90 (25243 of 97666)
PASS: Flang :: Driver/target.f90 (25244 of 97666)
PASS: Flang :: Driver/input-from-stdin/input-from-stdin.f90 (25245 of 97666)
PASS: Flang :: Driver/optimization-remark-backend.f90 (25246 of 97666)
PASS: Flang :: Driver/q-unused-arguments.f90 (25247 of 97666)
PASS: Flang :: Driver/no-duplicate-main.f90 (25248 of 97666)
PASS: Flang :: Driver/unparse-with-modules.f90 (25249 of 97666)
PASS: Flang :: Driver/fixed-line-length.f90 (25250 of 97666)
PASS: Flang :: Driver/pp-fixed-form.f90 (25251 of 97666)
PASS: Flang :: Driver/pass-plugin-not-found.f90 (25252 of 97666)
PASS: Flang :: Driver/linker-flags.f90 (25253 of 97666)
PASS: Flang :: Driver/lto-flags.f90 (25254 of 97666)
PASS: Clangd Unit Tests :: ./ClangdTests/80/81 (25255 of 97666)
PASS: Flang :: Driver/std2018.f90 (25256 of 97666)
PASS: Flang :: Driver/target-machine-error.f90 (25257 of 97666)
PASS: Flang :: Driver/fsave-optimization-record.f90 (25258 of 97666)
PASS: Flang :: Driver/multiple-input-files.f90 (25259 of 97666)
PASS: Flang :: Driver/prescanner-diag.f90 (25260 of 97666)
PASS: Flang :: Driver/unparse-use-analyzed.f95 (25261 of 97666)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants