Skip to content

[MLIR] fix func.func to llvm.func lowering where no_inline attribute is not propagated over #142088

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Kuree
Copy link
Contributor

@Kuree Kuree commented May 30, 2025

See https://godbolt.org/z/43c84TEGh

func.func no_inline attribute is not propagated to llvm.func even though both of them supports no inline attribute.

I had to put the fix in inside the rewrite function instead of mlir::convertFuncOpToLLVMFuncOp because it takes FunctionOpInterface, which does not have a named method to get no inline information without using get attributes. I'm happy to switch to the latter method.

@llvmbot llvmbot added the mlir label May 30, 2025
@llvmbot
Copy link
Member

llvmbot commented May 30, 2025

@llvm/pr-subscribers-mlir

Author: Keyi Zhang (Kuree)

Changes

See https://godbolt.org/z/43c84TEGh

func.func no_inline attribute is not propagated to llvm.func even though both of them supports no inline attribute.

I had to put the fix in inside the rewrite function instead of mlir::convertFuncOpToLLVMFuncOp because it takes FunctionOpInterface, which does not have a named method to get no inline information without using get attributes. I'm happy to switch to the latter method.


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

2 Files Affected:

  • (modified) mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp (+3)
  • (modified) mlir/test/Conversion/FuncToLLVM/func-to-llvm.mlir (+5)
diff --git a/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp b/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp
index 328c605add65c..bf8e231fde2f4 100644
--- a/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp
+++ b/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp
@@ -490,6 +490,9 @@ struct FuncOpConversion : public ConvertOpToLLVMPattern<func::FuncOp> {
     if (failed(newFuncOp))
       return rewriter.notifyMatchFailure(funcOp, "Could not convert funcop");
 
+    // Propagate noinline attribute
+    newFuncOp->setNoInline(funcOp.getNoInline());
+
     rewriter.eraseOp(funcOp);
     return success();
   }
diff --git a/mlir/test/Conversion/FuncToLLVM/func-to-llvm.mlir b/mlir/test/Conversion/FuncToLLVM/func-to-llvm.mlir
index 2113557fbbb15..4a664ec7aa0fa 100644
--- a/mlir/test/Conversion/FuncToLLVM/func-to-llvm.mlir
+++ b/mlir/test/Conversion/FuncToLLVM/func-to-llvm.mlir
@@ -563,6 +563,11 @@ func.func @non_convertible_arg_type(%arg: vector<1xtf32>) {
   return
 }
 
+// CHECK: llvm.func @no_inline() attributes {no_inline}
+func.func @no_inline() attributes {no_inline} {
+  return
+}
+
 module attributes {transform.with_named_sequence} {
   transform.named_sequence @__transform_main(%toplevel_module: !transform.any_op {transform.readonly}) {
     %func = transform.structured.match ops{["func.func"]} in %toplevel_module

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

Successfully merging this pull request may close these issues.

2 participants