-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
[MLIR] Adding 'no_inline' and 'always_inline' attributes on LLMV::CallOp #133726
[MLIR] Adding 'no_inline' and 'always_inline' attributes on LLMV::CallOp #133726
Conversation
@llvm/pr-subscribers-mlir Author: Jean-Didier PAILLEUX (JDPailleux) ChangesAddition of Full diff: https://github.com/llvm/llvm-project/pull/133726.diff 4 Files Affected:
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
index 90cc851c0a3b2..36a76232578bb 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
@@ -771,23 +771,21 @@ 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..9db7b7be1e6fc 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/test/Target/LLVMIR/llvmir.mlir b/mlir/test/Target/LLVMIR/llvmir.mlir
index 5a1f43ba1d018..b9b0e761f49d2 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-SAME: #[[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-SAME: #[[ATTRS:[0-9]+]]
+llvm.func @always_inline_call() {
+ llvm.call @f() {always_inline} : () -> ()
+ llvm.return
+}
+
+// CHECK: #[[ATTRS]]
+// CHECK-SAME: alwaysinline
+
+
// -----
llvm.func @fa()
|
@llvm/pr-subscribers-mlir-llvm Author: Jean-Didier PAILLEUX (JDPailleux) ChangesAddition of Full diff: https://github.com/llvm/llvm-project/pull/133726.diff 4 Files Affected:
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
index 90cc851c0a3b2..36a76232578bb 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
@@ -771,23 +771,21 @@ 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..9db7b7be1e6fc 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/test/Target/LLVMIR/llvmir.mlir b/mlir/test/Target/LLVMIR/llvmir.mlir
index 5a1f43ba1d018..b9b0e761f49d2 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-SAME: #[[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-SAME: #[[ATTRS:[0-9]+]]
+llvm.func @always_inline_call() {
+ llvm.call @f() {always_inline} : () -> ()
+ llvm.return
+}
+
+// CHECK: #[[ATTRS]]
+// CHECK-SAME: alwaysinline
+
+
// -----
llvm.func @fa()
|
Can you add the relevant import tests also in https://github.com/llvm/llvm-project/tree/main/mlir/test/Target/LLVMIR/Import? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the extension. As already stated before, this also needs import logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Added a nit comment in addition to the other review comments.
2c2f6a3
to
2a34371
Compare
✅ With the latest revision this PR passed the C/C++ code formatter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM % additional nits. Make sure that clang-format is happy as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM modulo @Dinistro 's comments
2a34371
to
773bf98
Compare
Test added |
Thanks for you feedbacks and sorry for the clang-format issues. |
773bf98
to
6059c0d
Compare
If we're adding first-class support for these attributes, we should likely handle this in the MLIR inliner as well, can you update |
…lOp (llvm#133726) Addition of `no_inline` and `always_inline` attributes for CallOps in MLIR in order to be able to inline or not directly the call of a function without having the attribute on the `FuncOp`. The addition of these attributes will be used in a future PR in Flang (`[NO]INLINE` directive).
@JDPailleux : ping on my comment above? |
Addition of
no_inline
andalways_inline
attributes for CallOps in MLIR in order to be able to inline or not directly the call of a function without having the attribute on theFuncOp
.The addition of these attributes will be used in a future PR in Flang (
[NO]INLINE
directive).