Skip to content

Commit b6d6893

Browse files
FMarnovictor-eds
authored andcommitted
[MLIR] Add attributes no_unwind and will_return to the LLVMIR dialect (#98921)
And testing. These are being added to be used in the GPU to LLVM SPV pass. --------- Co-authored-by: Victor Perez <victor.perez@codeplay.com>
1 parent 95d919c commit b6d6893

File tree

6 files changed

+59
-0
lines changed

6 files changed

+59
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,6 +1461,8 @@ def LLVM_LLVMFuncOp : LLVM_Op<"func", [
14611461
OptionalAttr<StrAttr>:$fp_contract,
14621462
OptionalAttr<UnitAttr>:$no_inline,
14631463
OptionalAttr<UnitAttr>:$always_inline,
1464+
OptionalAttr<UnitAttr>:$no_unwind,
1465+
OptionalAttr<UnitAttr>:$will_return,
14641466
OptionalAttr<UnitAttr>:$optimize_none
14651467
);
14661468

mlir/lib/Target/LLVMIR/ModuleImport.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1686,11 +1686,13 @@ static constexpr std::array kExplicitAttributes{
16861686
StringLiteral("no-nans-fp-math"),
16871687
StringLiteral("no-signed-zeros-fp-math"),
16881688
StringLiteral("noinline"),
1689+
StringLiteral("nounwind"),
16891690
StringLiteral("optnone"),
16901691
StringLiteral("target-features"),
16911692
StringLiteral("tune-cpu"),
16921693
StringLiteral("unsafe-fp-math"),
16931694
StringLiteral("vscale_range"),
1695+
StringLiteral("willreturn"),
16941696
};
16951697

16961698
static void processPassthroughAttrs(llvm::Function *func, LLVMFuncOp funcOp) {
@@ -1763,6 +1765,10 @@ void ModuleImport::processFunctionAttributes(llvm::Function *func,
17631765
funcOp.setOptimizeNone(true);
17641766
if (func->hasFnAttribute(llvm::Attribute::Convergent))
17651767
funcOp.setConvergent(true);
1768+
if (func->hasFnAttribute(llvm::Attribute::NoUnwind))
1769+
funcOp.setNoUnwind(true);
1770+
if (func->hasFnAttribute(llvm::Attribute::WillReturn))
1771+
funcOp.setWillReturn(true);
17661772

17671773
if (func->hasFnAttribute("aarch64_pstate_sm_enabled"))
17681774
funcOp.setArmStreaming(true);

mlir/lib/Target/LLVMIR/ModuleTranslation.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,6 +1441,10 @@ static void convertFunctionAttributes(LLVMFuncOp func,
14411441
llvmFunc->addFnAttr(llvm::Attribute::OptimizeNone);
14421442
if (func.getConvergentAttr())
14431443
llvmFunc->addFnAttr(llvm::Attribute::Convergent);
1444+
if (func.getNoUnwindAttr())
1445+
llvmFunc->addFnAttr(llvm::Attribute::NoUnwind);
1446+
if (func.getWillReturnAttr())
1447+
llvmFunc->addFnAttr(llvm::Attribute::WillReturn);
14441448
convertFunctionMemoryAttributes(func, llvmFunc);
14451449
}
14461450

mlir/test/Dialect/LLVMIR/func.mlir

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,19 @@ module {
312312
llvm.return
313313
}
314314

315+
llvm.func @nounwind_function() attributes {no_unwind} {
316+
// CHECK: @nounwind_function
317+
// CHECK-SAME: attributes {no_unwind}
318+
llvm.return
319+
}
320+
321+
llvm.func @willreturn_function() attributes {will_return} {
322+
// CHECK: @willreturn_function
323+
// CHECK-SAME: attributes {will_return}
324+
llvm.return
325+
}
326+
327+
315328
}
316329

317330
// -----

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,3 +385,15 @@ declare void @optnone_attribute() noinline optnone
385385
; CHECK-LABEL: @convergent_attribute
386386
; CHECK-SAME: attributes {convergent}
387387
declare void @convergent_attribute() convergent
388+
389+
// -----
390+
391+
; CHECK-LABEL: @nounwind_attribute
392+
; CHECK-SAME: attributes {no_unwind}
393+
declare void @nounwind_attribute() nounwind
394+
395+
// -----
396+
397+
; CHECK-LABEL: @willreturn_attribute
398+
; CHECK-SAME: attributes {will_return}
399+
declare void @willreturn_attribute() willreturn

mlir/test/Target/LLVMIR/llvmir.mlir

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2452,3 +2452,25 @@ llvm.func @convergent() attributes { convergent } {
24522452

24532453
// CHECK: #[[ATTRS]]
24542454
// CHECK-SAME: convergent
2455+
2456+
// -----
2457+
2458+
// CHECK-LABEL: @nounwind
2459+
// CHECK-SAME: #[[ATTRS:[0-9]+]]
2460+
llvm.func @nounwind() attributes { no_unwind } {
2461+
llvm.return
2462+
}
2463+
2464+
// CHECK: #[[ATTRS]]
2465+
// CHECK-SAME: nounwind
2466+
2467+
// -----
2468+
2469+
// CHECK-LABEL: @willreturn
2470+
// CHECK-SAME: #[[ATTRS:[0-9]+]]
2471+
llvm.func @willreturn() attributes { will_return } {
2472+
llvm.return
2473+
}
2474+
2475+
// CHECK: #[[ATTRS]]
2476+
// CHECK-SAME: willreturn

0 commit comments

Comments
 (0)