Skip to content

[MLIR] Adding 'no_inline' and 'always_inline' attributes on LLMV::CallOp #133726

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 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 8 additions & 4 deletions mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions mlir/lib/Target/LLVMIR/ModuleImport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
25 changes: 25 additions & 0 deletions mlir/test/Target/LLVMIR/Import/call-attributes.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
; RUN: mlir-translate -import-llvm -split-input-file %s | FileCheck %s

declare void @f()

; CHECK-LABEL: @test_call_noinline
; CHECK: llvm.call @f() {no_inline} : () -> ()
define void @test_call_noinline() {
call void @f() #0
ret void
}

attributes #0 = { noinline }

// -----

declare void @f()

; CHECK-LABEL: @test_call_alwaysinline
; CHECK: llvm.call @f() {always_inline} : () -> ()
define void @test_call_alwaysinline() {
call void @f() #0
ret void
}

attributes #0 = { alwaysinline }
29 changes: 29 additions & 0 deletions mlir/test/Target/LLVMIR/llvmir.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down