Skip to content

Commit 7cfe620

Browse files
committed
[MLIR][LLVM] Add inline_hint as a first class function attribute
We have `noinline` and `alwaysinline` present as first class function attributes. Add `inline_hint` to the list of function attributes as well. Update the module import and translation to support the new attribute. The verifier does not need to be changed as `inlinehint` does not conflict with `noinline` or `alwaysinline`. `inline_hint` is needed to support the `inline` C/C++ keyword in CIR.
1 parent 0b462f6 commit 7cfe620

File tree

5 files changed

+26
-0
lines changed

5 files changed

+26
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1985,6 +1985,7 @@ def LLVM_LLVMFuncOp : LLVM_Op<"func", [
19851985
OptionalAttr<StrAttr>:$instrument_function_exit,
19861986
OptionalAttr<UnitAttr>:$no_inline,
19871987
OptionalAttr<UnitAttr>:$always_inline,
1988+
OptionalAttr<UnitAttr>:$inline_hint,
19881989
OptionalAttr<UnitAttr>:$no_unwind,
19891990
OptionalAttr<UnitAttr>:$will_return,
19901991
OptionalAttr<UnitAttr>:$optimize_none,
@@ -2037,6 +2038,9 @@ def LLVM_LLVMFuncOp : LLVM_Op<"func", [
20372038
/// Returns true if the `always_inline` attribute is set, false otherwise.
20382039
bool isAlwaysInline() { return bool(getAlwaysInlineAttr()); }
20392040

2041+
/// Returns true if the `inline_hint` attribute is set, false otherwise.
2042+
bool isInlineHint() { return bool(getInlineHintAttr()); }
2043+
20402044
/// Returns true if the `optimize_none` attribute is set, false otherwise.
20412045
bool isOptimizeNone() { return bool(getOptimizeNoneAttr()); }
20422046
}];

mlir/lib/Target/LLVMIR/ModuleImport.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2604,6 +2604,7 @@ static constexpr std::array kExplicitLLVMFuncOpAttributes{
26042604
StringLiteral("denormal-fp-math-f32"),
26052605
StringLiteral("fp-contract"),
26062606
StringLiteral("frame-pointer"),
2607+
StringLiteral("inlinehint"),
26072608
StringLiteral("instrument-function-entry"),
26082609
StringLiteral("instrument-function-exit"),
26092610
StringLiteral("memory"),
@@ -2643,6 +2644,8 @@ void ModuleImport::processFunctionAttributes(llvm::Function *func,
26432644
funcOp.setNoInline(true);
26442645
if (func->hasFnAttribute(llvm::Attribute::AlwaysInline))
26452646
funcOp.setAlwaysInline(true);
2647+
if (func->hasFnAttribute(llvm::Attribute::InlineHint))
2648+
funcOp.setInlineHint(true);
26462649
if (func->hasFnAttribute(llvm::Attribute::OptimizeNone))
26472650
funcOp.setOptimizeNone(true);
26482651
if (func->hasFnAttribute(llvm::Attribute::Convergent))

mlir/lib/Target/LLVMIR/ModuleTranslation.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1653,6 +1653,8 @@ static void convertFunctionAttributes(LLVMFuncOp func,
16531653
llvmFunc->addFnAttr(llvm::Attribute::NoInline);
16541654
if (func.getAlwaysInlineAttr())
16551655
llvmFunc->addFnAttr(llvm::Attribute::AlwaysInline);
1656+
if (func.getInlineHintAttr())
1657+
llvmFunc->addFnAttr(llvm::Attribute::InlineHint);
16561658
if (func.getOptimizeNoneAttr())
16571659
llvmFunc->addFnAttr(llvm::Attribute::OptimizeNone);
16581660
if (func.getConvergentAttr())

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,12 @@ declare void @alwaysinline_attribute() alwaysinline
393393

394394
// -----
395395

396+
; CHECK-LABEL: @inlinehint_attribute
397+
; CHECK-SAME: attributes {inline_hint}
398+
declare void @inlinehint_attribute() inlinehint
399+
400+
// -----
401+
396402
; CHECK-LABEL: @optnone_attribute
397403
; CHECK-SAME: attributes {no_inline, optimize_none}
398404
declare void @optnone_attribute() noinline optnone

mlir/test/Target/LLVMIR/llvmir.mlir

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2555,6 +2555,17 @@ llvm.func @always_inline() attributes { always_inline } {
25552555

25562556
// -----
25572557

2558+
// CHECK-LABEL: @inline_hint
2559+
// CHECK-SAME: #[[ATTRS:[0-9]+]]
2560+
llvm.func @inline_hint() attributes { inline_hint } {
2561+
llvm.return
2562+
}
2563+
2564+
// CHECK: #[[ATTRS]]
2565+
// CHECK-SAME: inlinehint
2566+
2567+
// -----
2568+
25582569
// CHECK-LABEL: @optimize_none
25592570
// CHECK-SAME: #[[ATTRS:[0-9]+]]
25602571
llvm.func @optimize_none() attributes { no_inline, optimize_none } {

0 commit comments

Comments
 (0)