Skip to content

Commit d6df018

Browse files
authored
[MLIR] Add the convergent attribute to LLVM Dialect (#97709)
In order to use the convergent attribute in the GPUToLLVMSPV pass, I've added the attribute to the LLVM dialect. Some details on the convergent attribute https://llvm.org/docs/ConvergentOperations.html#convergent-operations
1 parent 8101cbf commit d6df018

File tree

6 files changed

+29
-0
lines changed

6 files changed

+29
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,6 +1425,7 @@ def LLVM_LLVMFuncOp : LLVM_Op<"func", [
14251425
UnitAttr:$dso_local,
14261426
DefaultValuedAttr<CConv, "CConv::C">:$CConv,
14271427
OptionalAttr<SymbolRefAttr>:$comdat,
1428+
OptionalAttr<UnitAttr>:$convergent,
14281429
OptionalAttr<FlatSymbolRefAttr>:$personality,
14291430
OptionalAttr<StrAttr>:$garbageCollector,
14301431
OptionalAttr<ArrayAttr>:$passthrough,

mlir/lib/Target/LLVMIR/ModuleImport.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1675,6 +1675,7 @@ static constexpr std::array kExplicitAttributes{
16751675
StringLiteral("aarch64_pstate_sm_enabled"),
16761676
StringLiteral("alwaysinline"),
16771677
StringLiteral("approx-func-fp-math"),
1678+
StringLiteral("convergent"),
16781679
StringLiteral("frame-pointer"),
16791680
StringLiteral("no-infs-fp-math"),
16801681
StringLiteral("no-nans-fp-math"),
@@ -1754,6 +1755,8 @@ void ModuleImport::processFunctionAttributes(llvm::Function *func,
17541755
funcOp.setAlwaysInline(true);
17551756
if (func->hasFnAttribute(llvm::Attribute::OptimizeNone))
17561757
funcOp.setOptimizeNone(true);
1758+
if (func->hasFnAttribute(llvm::Attribute::Convergent))
1759+
funcOp.setConvergent(true);
17571760

17581761
if (func->hasFnAttribute("aarch64_pstate_sm_enabled"))
17591762
funcOp.setArmStreaming(true);

mlir/lib/Target/LLVMIR/ModuleTranslation.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,6 +1422,8 @@ static void convertFunctionAttributes(LLVMFuncOp func,
14221422
llvmFunc->addFnAttr(llvm::Attribute::AlwaysInline);
14231423
if (func.getOptimizeNoneAttr())
14241424
llvmFunc->addFnAttr(llvm::Attribute::OptimizeNone);
1425+
if (func.getConvergentAttr())
1426+
llvmFunc->addFnAttr(llvm::Attribute::Convergent);
14251427
convertFunctionMemoryAttributes(func, llvmFunc);
14261428
}
14271429

mlir/test/Dialect/LLVMIR/func.mlir

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,12 @@ module {
287287
// CHECK-SAME: attributes {no_signed_zeros_fp_math = true}
288288
llvm.return
289289
}
290+
291+
llvm.func @convergent_function() attributes {convergent} {
292+
// CHECK: @convergent_function
293+
// CHECK-SAME: attributes {convergent}
294+
llvm.return
295+
}
290296
}
291297

292298
// -----

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,3 +361,9 @@ declare void @alwaysinline_attribute() alwaysinline
361361
; CHECK-LABEL: @optnone_attribute
362362
; CHECK-SAME: attributes {no_inline, optimize_none}
363363
declare void @optnone_attribute() noinline optnone
364+
365+
// -----
366+
367+
; CHECK-LABEL: @convergent_attribute
368+
; CHECK-SAME: attributes {convergent}
369+
declare void @convergent_attribute() convergent

mlir/test/Target/LLVMIR/llvmir.mlir

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2441,3 +2441,14 @@ llvm.func @optimize_none() attributes { no_inline, optimize_none } {
24412441

24422442
// CHECK: #[[ATTRS]]
24432443
// CHECK-SAME: optnone
2444+
2445+
// -----
2446+
2447+
// CHECK-LABEL: @convergent
2448+
// CHECK-SAME: #[[ATTRS:[0-9]+]]
2449+
llvm.func @convergent() attributes { convergent } {
2450+
llvm.return
2451+
}
2452+
2453+
// CHECK: #[[ATTRS]]
2454+
// CHECK-SAME: convergent

0 commit comments

Comments
 (0)