[Mlir-commits] [mlir] [MLIR] Adding 'no_inline' and 'always_inline' attributes on LLMV::CallOp (PR #133726)
Jean-Didier PAILLEUX
llvmlistbot at llvm.org
Mon Mar 31 13:30:41 PDT 2025
https://github.com/JDPailleux updated https://github.com/llvm/llvm-project/pull/133726
>From 2a34371893f1f1d39e8d6719a03b8073d737d5b6 Mon Sep 17 00:00:00 2001
From: Jean-Didier Pailleux <jean-didier.pailleux at sipearl.com>
Date: Mon, 31 Mar 2025 15:55:16 +0200
Subject: [PATCH] [mlir] Adding 'no_inline' and 'always_inline' attributes on
mlir::LLMV::CallOp
---
mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td | 34 +++++++++----------
mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp | 12 ++++---
.../LLVMIR/LLVMToLLVMIRTranslation.cpp | 4 +++
mlir/lib/Target/LLVMIR/ModuleImport.cpp | 3 ++
.../Target/LLVMIR/Import/call-attributes.ll | 29 ++++++++++++++++
mlir/test/Target/LLVMIR/llvmir.mlir | 29 ++++++++++++++++
6 files changed, 90 insertions(+), 21 deletions(-)
create mode 100644 mlir/test/Target/LLVMIR/Import/call-attributes.ll
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
index 90cc851c0a3b2..7d94e04f3d1b4 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
@@ -771,23 +771,23 @@ def LLVM_CallOp : LLVM_MemAccessOpBase<"call",
}];
dag args = (ins OptionalAttr<TypeAttrOf<LLVM_FunctionType>>:$var_callee_type,
- OptionalAttr<FlatSymbolRefAttr>:$callee,
- Variadic<LLVM_Type>:$callee_operands,
- DefaultValuedAttr<LLVM_FastmathFlagsAttr,
- "{}">:$fastmathFlags,
- OptionalAttr<DenseI32ArrayAttr>:$branch_weights,
- DefaultValuedAttr<CConv, "CConv::C">:$CConv,
- DefaultValuedAttr<TailCallKind, "TailCallKind::None">:$TailCallKind,
- OptionalAttr<LLVM_MemoryEffectsAttr>:$memory_effects,
- OptionalAttr<UnitAttr>:$convergent,
- OptionalAttr<UnitAttr>:$no_unwind,
- OptionalAttr<UnitAttr>:$will_return,
- VariadicOfVariadic<LLVM_Type,
- "op_bundle_sizes">:$op_bundle_operands,
- DenseI32ArrayAttr:$op_bundle_sizes,
- OptionalAttr<ArrayAttr>:$op_bundle_tags,
- OptionalAttr<DictArrayAttr>:$arg_attrs,
- OptionalAttr<DictArrayAttr>:$res_attrs);
+ OptionalAttr<FlatSymbolRefAttr>:$callee,
+ Variadic<LLVM_Type>:$callee_operands,
+ DefaultValuedAttr<LLVM_FastmathFlagsAttr, "{}">:$fastmathFlags,
+ OptionalAttr<DenseI32ArrayAttr>:$branch_weights,
+ DefaultValuedAttr<CConv, "CConv::C">:$CConv,
+ DefaultValuedAttr<TailCallKind, "TailCallKind::None">:$TailCallKind,
+ OptionalAttr<LLVM_MemoryEffectsAttr>:$memory_effects,
+ OptionalAttr<UnitAttr>:$convergent,
+ OptionalAttr<UnitAttr>:$no_unwind,
+ OptionalAttr<UnitAttr>:$will_return,
+ VariadicOfVariadic<LLVM_Type, "op_bundle_sizes">:$op_bundle_operands,
+ DenseI32ArrayAttr:$op_bundle_sizes,
+ OptionalAttr<ArrayAttr>:$op_bundle_tags,
+ OptionalAttr<DictArrayAttr>:$arg_attrs,
+ OptionalAttr<DictArrayAttr>:$res_attrs,
+ OptionalAttr<UnitAttr>:$no_inline,
+ OptionalAttr<UnitAttr>:$always_inline);
// Append the aliasing related attributes defined in LLVM_MemAccessOpBase.
let arguments = !con(args, aliasAttrs);
let results = (outs Optional<LLVM_Type>:$result);
diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
index 5370de501a85c..b1fa054d00a59 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
@@ -1036,7 +1036,8 @@ void CallOp::build(OpBuilder &builder, OperationState &state, TypeRange results,
/*op_bundle_operands=*/{}, /*op_bundle_tags=*/{},
/*arg_attrs=*/nullptr, /*res_attrs=*/nullptr,
/*access_groups=*/nullptr, /*alias_scopes=*/nullptr,
- /*noalias_scopes=*/nullptr, /*tbaa=*/nullptr);
+ /*noalias_scopes=*/nullptr, /*tbaa=*/nullptr,
+ /*no_inline=*/ nullptr, /*always_inline=*/ nullptr);
}
void CallOp::build(OpBuilder &builder, OperationState &state,
@@ -1064,7 +1065,8 @@ void CallOp::build(OpBuilder &builder, OperationState &state,
/*op_bundle_operands=*/{}, /*op_bundle_tags=*/{},
/*arg_attrs=*/nullptr, /*res_attrs=*/nullptr,
/*access_groups=*/nullptr,
- /*alias_scopes=*/nullptr, /*noalias_scopes=*/nullptr, /*tbaa=*/nullptr);
+ /*alias_scopes=*/nullptr, /*noalias_scopes=*/nullptr, /*tbaa=*/nullptr,
+ /*no_inline=*/ nullptr, /*always_inline=*/ nullptr);
}
void CallOp::build(OpBuilder &builder, OperationState &state,
@@ -1078,7 +1080,8 @@ void CallOp::build(OpBuilder &builder, OperationState &state,
/*op_bundle_operands=*/{}, /*op_bundle_tags=*/{},
/*arg_attrs=*/nullptr, /*res_attrs=*/nullptr,
/*access_groups=*/nullptr, /*alias_scopes=*/nullptr,
- /*noalias_scopes=*/nullptr, /*tbaa=*/nullptr);
+ /*noalias_scopes=*/nullptr, /*tbaa=*/nullptr,
+ /*no_inline=*/ nullptr, /*always_inline=*/ nullptr);
}
void CallOp::build(OpBuilder &builder, OperationState &state, LLVMFuncOp func,
@@ -1092,7 +1095,8 @@ void CallOp::build(OpBuilder &builder, OperationState &state, LLVMFuncOp func,
/*op_bundle_operands=*/{}, /*op_bundle_tags=*/{},
/*access_groups=*/nullptr, /*alias_scopes=*/nullptr,
/*arg_attrs=*/nullptr, /*res_attrs=*/nullptr,
- /*noalias_scopes=*/nullptr, /*tbaa=*/nullptr);
+ /*noalias_scopes=*/nullptr, /*tbaa=*/nullptr,
+ /*no_inline=*/ nullptr, /*always_inline=*/ nullptr);
}
CallInterfaceCallable CallOp::getCallableForCallee() {
diff --git a/mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp b/mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp
index 833b19c1bece2..57a0511914515 100644
--- a/mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp
@@ -319,6 +319,10 @@ convertOperationImpl(Operation &opInst, llvm::IRBuilderBase &builder,
call->addFnAttr(llvm::Attribute::NoUnwind);
if (callOp.getWillReturnAttr())
call->addFnAttr(llvm::Attribute::WillReturn);
+ if (callOp.getNoInlineAttr())
+ call->addFnAttr(llvm::Attribute::NoInline);
+ if (callOp.getAlwaysInlineAttr())
+ call->addFnAttr(llvm::Attribute::AlwaysInline);
if (failed(convertParameterAndResultAttrs(callOp, call, moduleTranslation)))
return failure();
diff --git a/mlir/lib/Target/LLVMIR/ModuleImport.cpp b/mlir/lib/Target/LLVMIR/ModuleImport.cpp
index 76460b541fe0e..2d34b04753dfc 100644
--- a/mlir/lib/Target/LLVMIR/ModuleImport.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleImport.cpp
@@ -2303,6 +2303,9 @@ LogicalResult ModuleImport::convertCallAttributes(llvm::CallInst *inst,
op.setConvergent(callAttrs.getFnAttr(llvm::Attribute::Convergent).isValid());
op.setNoUnwind(callAttrs.getFnAttr(llvm::Attribute::NoUnwind).isValid());
op.setWillReturn(callAttrs.getFnAttr(llvm::Attribute::WillReturn).isValid());
+ op.setNoInline(callAttrs.getFnAttr(llvm::Attribute::NoInline).isValid());
+ op.setAlwaysInline(
+ callAttrs.getFnAttr(llvm::Attribute::AlwaysInline).isValid());
llvm::MemoryEffects memEffects = inst->getMemoryEffects();
ModRefInfo othermem = convertModRefInfoFromLLVM(
diff --git a/mlir/test/Target/LLVMIR/Import/call-attributes.ll b/mlir/test/Target/LLVMIR/Import/call-attributes.ll
new file mode 100644
index 0000000000000..72e0368e25808
--- /dev/null
+++ b/mlir/test/Target/LLVMIR/Import/call-attributes.ll
@@ -0,0 +1,29 @@
+; RUN: mlir-translate -import-llvm -split-input-file %s | FileCheck %s
+
+; CHECK-LABEL: @test_call_noinline
+; CHECK: llvm.call @f() {no_inline} : () -> ()
+define void @test_call_noinline() {
+ call void @f() #0
+ ret void
+}
+
+define void @f() {
+ ret void
+}
+
+attributes #0 = { noinline }
+
+// -----
+
+; CHECK-LABEL: @test_call_alwaysinline
+; CHECK: llvm.call @f() {always_inline} : () -> ()
+define void @test_call_alwaysinline() {
+ call void @f() #0
+ ret void
+}
+
+define void @f() {
+ ret void
+}
+
+attributes #0 = { alwaysinline }
diff --git a/mlir/test/Target/LLVMIR/llvmir.mlir b/mlir/test/Target/LLVMIR/llvmir.mlir
index 5a1f43ba1d018..7c8fbdfa26ffc 100644
--- a/mlir/test/Target/LLVMIR/llvmir.mlir
+++ b/mlir/test/Target/LLVMIR/llvmir.mlir
@@ -2621,6 +2621,35 @@ llvm.func @willreturn_call() {
// CHECK: #[[ATTRS]]
// CHECK-SAME: willreturn
+// -----
+
+llvm.func @f()
+
+// CHECK-LABEL: @no_inline_call
+// CHECK: call void @f() #[[ATTRS:[0-9]+]]
+llvm.func @no_inline_call() {
+ llvm.call @f() {no_inline} : () -> ()
+ llvm.return
+}
+
+// CHECK: #[[ATTRS]]
+// CHECK-SAME: noinline
+
+// -----
+
+llvm.func @f()
+
+// CHECK-LABEL: @always_inline_call
+// CHECK: call void @f() #[[ATTRS:[0-9]+]]
+llvm.func @always_inline_call() {
+ llvm.call @f() {always_inline} : () -> ()
+ llvm.return
+}
+
+// CHECK: #[[ATTRS]]
+// CHECK-SAME: alwaysinline
+
+
// -----
llvm.func @fa()
More information about the Mlir-commits
mailing list