Skip to content

[MLIR] Adding 'inline_hint' attribute on LLMV::CallOp #134582

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 11, 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
16 changes: 11 additions & 5 deletions mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,11 @@ def LLVM_CallOp : LLVM_MemAccessOpBase<"call",
the LLVM function type that uses an explicit void type to model functions
that do not return a value.

If this operatin has the `no_inline` attribute, then this specific function call
will never be inlined. The opposite behavior will occur if the call has `always_inline`
attribute. The `inline_hint` attribute indicates that it is desirable to inline
this function call.

Examples:

```mlir
Expand Down Expand Up @@ -778,16 +783,17 @@ def LLVM_CallOp : LLVM_MemAccessOpBase<"call",
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,
UnitAttr:$convergent,
UnitAttr:$no_unwind,
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);
UnitAttr:$no_inline,
UnitAttr:$always_inline,
UnitAttr:$inline_hint);
// 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 @@ -1038,7 +1038,8 @@ void CallOp::build(OpBuilder &builder, OperationState &state, TypeRange results,
/*arg_attrs=*/nullptr, /*res_attrs=*/nullptr,
/*access_groups=*/nullptr, /*alias_scopes=*/nullptr,
/*noalias_scopes=*/nullptr, /*tbaa=*/nullptr,
/*no_inline=*/nullptr, /*always_inline=*/nullptr);
/*no_inline=*/nullptr, /*always_inline=*/nullptr,
/*inline_hint=*/nullptr);
}

void CallOp::build(OpBuilder &builder, OperationState &state,
Expand Down Expand Up @@ -1067,7 +1068,8 @@ void CallOp::build(OpBuilder &builder, OperationState &state,
/*arg_attrs=*/nullptr, /*res_attrs=*/nullptr,
/*access_groups=*/nullptr,
/*alias_scopes=*/nullptr, /*noalias_scopes=*/nullptr, /*tbaa=*/nullptr,
/*no_inline=*/nullptr, /*always_inline=*/nullptr);
/*no_inline=*/nullptr, /*always_inline=*/nullptr,
/*inline_hint=*/nullptr);
}

void CallOp::build(OpBuilder &builder, OperationState &state,
Expand All @@ -1082,7 +1084,8 @@ void CallOp::build(OpBuilder &builder, OperationState &state,
/*arg_attrs=*/nullptr, /*res_attrs=*/nullptr,
/*access_groups=*/nullptr, /*alias_scopes=*/nullptr,
/*noalias_scopes=*/nullptr, /*tbaa=*/nullptr,
/*no_inline=*/nullptr, /*always_inline=*/nullptr);
/*no_inline=*/nullptr, /*always_inline=*/nullptr,
/*inline_hint=*/nullptr);
}

void CallOp::build(OpBuilder &builder, OperationState &state, LLVMFuncOp func,
Expand All @@ -1097,7 +1100,8 @@ void CallOp::build(OpBuilder &builder, OperationState &state, LLVMFuncOp func,
/*access_groups=*/nullptr, /*alias_scopes=*/nullptr,
/*arg_attrs=*/nullptr, /*res_attrs=*/nullptr,
/*noalias_scopes=*/nullptr, /*tbaa=*/nullptr,
/*no_inline=*/nullptr, /*always_inline=*/nullptr);
/*no_inline=*/nullptr, /*always_inline=*/nullptr,
/*inline_hint=*/nullptr);
}

CallInterfaceCallable CallOp::getCallableForCallee() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,8 @@ convertOperationImpl(Operation &opInst, llvm::IRBuilderBase &builder,
call->addFnAttr(llvm::Attribute::NoInline);
if (callOp.getAlwaysInlineAttr())
call->addFnAttr(llvm::Attribute::AlwaysInline);
if (callOp.getInlineHintAttr())
call->addFnAttr(llvm::Attribute::InlineHint);

if (failed(convertParameterAndResultAttrs(callOp, call, moduleTranslation)))
return failure();
Expand Down
1 change: 1 addition & 0 deletions mlir/lib/Target/LLVMIR/ModuleImport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2334,6 +2334,7 @@ LogicalResult ModuleImport::convertCallAttributes(llvm::CallInst *inst,
op.setNoInline(callAttrs.getFnAttr(llvm::Attribute::NoInline).isValid());
op.setAlwaysInline(
callAttrs.getFnAttr(llvm::Attribute::AlwaysInline).isValid());
op.setInlineHint(callAttrs.getFnAttr(llvm::Attribute::InlineHint).isValid());

llvm::MemoryEffects memEffects = inst->getMemoryEffects();
ModRefInfo othermem = convertModRefInfoFromLLVM(
Expand Down
13 changes: 13 additions & 0 deletions mlir/test/Target/LLVMIR/Import/call-attributes.ll
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,16 @@ define void @test_call_alwaysinline() {
}

attributes #0 = { alwaysinline }

// -----

declare void @f()

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

attributes #0 = { inlinehint }
13 changes: 13 additions & 0 deletions mlir/test/Target/LLVMIR/llvmir.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -2649,6 +2649,19 @@ llvm.func @always_inline_call() {
// CHECK: #[[ATTRS]]
// CHECK-SAME: alwaysinline

// -----

llvm.func @f()

// CHECK-LABEL: @inline_hint_call
// CHECK: call void @f() #[[ATTRS:[0-9]+]]
llvm.func @inline_hint_call() {
llvm.call @f() {inline_hint} : () -> ()
llvm.return
}

// CHECK: #[[ATTRS]]
// CHECK-SAME: inlinehint

// -----

Expand Down