Skip to content

Commit aeb06c6

Browse files
authored
[MLIR] Adding 'inline_hint' attribute on LLMV::CallOp (#134582)
Addition of `inlinehint` attributes for CallOps in MLIR in order to be able to say to a function call that the inlining is desirable without having the attribute on the FuncOp.
1 parent 23c9cfc commit aeb06c6

File tree

6 files changed

+48
-9
lines changed

6 files changed

+48
-9
lines changed

mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td

+11-5
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,11 @@ def LLVM_CallOp : LLVM_MemAccessOpBase<"call",
749749
the LLVM function type that uses an explicit void type to model functions
750750
that do not return a value.
751751

752+
If this operatin has the `no_inline` attribute, then this specific function call
753+
will never be inlined. The opposite behavior will occur if the call has `always_inline`
754+
attribute. The `inline_hint` attribute indicates that it is desirable to inline
755+
this function call.
756+
752757
Examples:
753758

754759
```mlir
@@ -778,16 +783,17 @@ def LLVM_CallOp : LLVM_MemAccessOpBase<"call",
778783
DefaultValuedAttr<CConv, "CConv::C">:$CConv,
779784
DefaultValuedAttr<TailCallKind, "TailCallKind::None">:$TailCallKind,
780785
OptionalAttr<LLVM_MemoryEffectsAttr>:$memory_effects,
781-
OptionalAttr<UnitAttr>:$convergent,
782-
OptionalAttr<UnitAttr>:$no_unwind,
783-
OptionalAttr<UnitAttr>:$will_return,
786+
UnitAttr:$convergent,
787+
UnitAttr:$no_unwind,
788+
UnitAttr:$will_return,
784789
VariadicOfVariadic<LLVM_Type, "op_bundle_sizes">:$op_bundle_operands,
785790
DenseI32ArrayAttr:$op_bundle_sizes,
786791
OptionalAttr<ArrayAttr>:$op_bundle_tags,
787792
OptionalAttr<DictArrayAttr>:$arg_attrs,
788793
OptionalAttr<DictArrayAttr>:$res_attrs,
789-
OptionalAttr<UnitAttr>:$no_inline,
790-
OptionalAttr<UnitAttr>:$always_inline);
794+
UnitAttr:$no_inline,
795+
UnitAttr:$always_inline,
796+
UnitAttr:$inline_hint);
791797
// Append the aliasing related attributes defined in LLVM_MemAccessOpBase.
792798
let arguments = !con(args, aliasAttrs);
793799
let results = (outs Optional<LLVM_Type>:$result);

mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,8 @@ void CallOp::build(OpBuilder &builder, OperationState &state, TypeRange results,
10321032
/*arg_attrs=*/nullptr, /*res_attrs=*/nullptr,
10331033
/*access_groups=*/nullptr, /*alias_scopes=*/nullptr,
10341034
/*noalias_scopes=*/nullptr, /*tbaa=*/nullptr,
1035-
/*no_inline=*/nullptr, /*always_inline=*/nullptr);
1035+
/*no_inline=*/nullptr, /*always_inline=*/nullptr,
1036+
/*inline_hint=*/nullptr);
10361037
}
10371038

10381039
void CallOp::build(OpBuilder &builder, OperationState &state,
@@ -1061,7 +1062,8 @@ void CallOp::build(OpBuilder &builder, OperationState &state,
10611062
/*arg_attrs=*/nullptr, /*res_attrs=*/nullptr,
10621063
/*access_groups=*/nullptr,
10631064
/*alias_scopes=*/nullptr, /*noalias_scopes=*/nullptr, /*tbaa=*/nullptr,
1064-
/*no_inline=*/nullptr, /*always_inline=*/nullptr);
1065+
/*no_inline=*/nullptr, /*always_inline=*/nullptr,
1066+
/*inline_hint=*/nullptr);
10651067
}
10661068

10671069
void CallOp::build(OpBuilder &builder, OperationState &state,
@@ -1076,7 +1078,8 @@ void CallOp::build(OpBuilder &builder, OperationState &state,
10761078
/*arg_attrs=*/nullptr, /*res_attrs=*/nullptr,
10771079
/*access_groups=*/nullptr, /*alias_scopes=*/nullptr,
10781080
/*noalias_scopes=*/nullptr, /*tbaa=*/nullptr,
1079-
/*no_inline=*/nullptr, /*always_inline=*/nullptr);
1081+
/*no_inline=*/nullptr, /*always_inline=*/nullptr,
1082+
/*inline_hint=*/nullptr);
10801083
}
10811084

10821085
void CallOp::build(OpBuilder &builder, OperationState &state, LLVMFuncOp func,
@@ -1091,7 +1094,8 @@ void CallOp::build(OpBuilder &builder, OperationState &state, LLVMFuncOp func,
10911094
/*access_groups=*/nullptr, /*alias_scopes=*/nullptr,
10921095
/*arg_attrs=*/nullptr, /*res_attrs=*/nullptr,
10931096
/*noalias_scopes=*/nullptr, /*tbaa=*/nullptr,
1094-
/*no_inline=*/nullptr, /*always_inline=*/nullptr);
1097+
/*no_inline=*/nullptr, /*always_inline=*/nullptr,
1098+
/*inline_hint=*/nullptr);
10951099
}
10961100

10971101
CallInterfaceCallable CallOp::getCallableForCallee() {

mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,8 @@ convertOperationImpl(Operation &opInst, llvm::IRBuilderBase &builder,
323323
call->addFnAttr(llvm::Attribute::NoInline);
324324
if (callOp.getAlwaysInlineAttr())
325325
call->addFnAttr(llvm::Attribute::AlwaysInline);
326+
if (callOp.getInlineHintAttr())
327+
call->addFnAttr(llvm::Attribute::InlineHint);
326328

327329
if (failed(convertParameterAndResultAttrs(callOp, call, moduleTranslation)))
328330
return failure();

mlir/lib/Target/LLVMIR/ModuleImport.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -2362,6 +2362,7 @@ LogicalResult ModuleImport::convertCallAttributes(llvm::CallInst *inst,
23622362
op.setNoInline(callAttrs.getFnAttr(llvm::Attribute::NoInline).isValid());
23632363
op.setAlwaysInline(
23642364
callAttrs.getFnAttr(llvm::Attribute::AlwaysInline).isValid());
2365+
op.setInlineHint(callAttrs.getFnAttr(llvm::Attribute::InlineHint).isValid());
23652366

23662367
llvm::MemoryEffects memEffects = inst->getMemoryEffects();
23672368
ModRefInfo othermem = convertModRefInfoFromLLVM(

mlir/test/Target/LLVMIR/Import/call-attributes.ll

+13
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,16 @@ define void @test_call_alwaysinline() {
2323
}
2424

2525
attributes #0 = { alwaysinline }
26+
27+
// -----
28+
29+
declare void @f()
30+
31+
; CHECK-LABEL: @test_call_inlinehint
32+
; CHECK: llvm.call @f() {inline_hint} : () -> ()
33+
define void @test_call_inlinehint() {
34+
call void @f() #0
35+
ret void
36+
}
37+
38+
attributes #0 = { inlinehint }

mlir/test/Target/LLVMIR/llvmir.mlir

+13
Original file line numberDiff line numberDiff line change
@@ -2649,6 +2649,19 @@ llvm.func @always_inline_call() {
26492649
// CHECK: #[[ATTRS]]
26502650
// CHECK-SAME: alwaysinline
26512651

2652+
// -----
2653+
2654+
llvm.func @f()
2655+
2656+
// CHECK-LABEL: @inline_hint_call
2657+
// CHECK: call void @f() #[[ATTRS:[0-9]+]]
2658+
llvm.func @inline_hint_call() {
2659+
llvm.call @f() {inline_hint} : () -> ()
2660+
llvm.return
2661+
}
2662+
2663+
// CHECK: #[[ATTRS]]
2664+
// CHECK-SAME: inlinehint
26522665

26532666
// -----
26542667

0 commit comments

Comments
 (0)