Skip to content

Commit 0f35df3

Browse files
authored
[MLIR][LLVM] Add inline_hint as a first class function attribute (llvm#163324)
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 33503d0 commit 0f35df3

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
@@ -1986,6 +1986,7 @@ def LLVM_LLVMFuncOp : LLVM_Op<"func", [
19861986
OptionalAttr<StrAttr>:$instrument_function_exit,
19871987
OptionalAttr<UnitAttr>:$no_inline,
19881988
OptionalAttr<UnitAttr>:$always_inline,
1989+
OptionalAttr<UnitAttr>:$inline_hint,
19891990
OptionalAttr<UnitAttr>:$no_unwind,
19901991
OptionalAttr<UnitAttr>:$will_return,
19911992
OptionalAttr<UnitAttr>:$optimize_none,
@@ -2038,6 +2039,9 @@ def LLVM_LLVMFuncOp : LLVM_Op<"func", [
20382039
/// Returns true if the `always_inline` attribute is set, false otherwise.
20392040
bool isAlwaysInline() { return bool(getAlwaysInlineAttr()); }
20402041

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

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
@@ -1652,6 +1652,8 @@ static void convertFunctionAttributes(LLVMFuncOp func,
16521652
llvmFunc->addFnAttr(llvm::Attribute::NoInline);
16531653
if (func.getAlwaysInlineAttr())
16541654
llvmFunc->addFnAttr(llvm::Attribute::AlwaysInline);
1655+
if (func.getInlineHintAttr())
1656+
llvmFunc->addFnAttr(llvm::Attribute::InlineHint);
16551657
if (func.getOptimizeNoneAttr())
16561658
llvmFunc->addFnAttr(llvm::Attribute::OptimizeNone);
16571659
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)