Skip to content

Commit

Permalink
[MLIR] Add the convergent attribute to LLVM Dialect (llvm#97709)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
FMarno committed Jul 5, 2024
1 parent 8101cbf commit d6df018
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -1425,6 +1425,7 @@ def LLVM_LLVMFuncOp : LLVM_Op<"func", [
UnitAttr:$dso_local,
DefaultValuedAttr<CConv, "CConv::C">:$CConv,
OptionalAttr<SymbolRefAttr>:$comdat,
OptionalAttr<UnitAttr>:$convergent,
OptionalAttr<FlatSymbolRefAttr>:$personality,
OptionalAttr<StrAttr>:$garbageCollector,
OptionalAttr<ArrayAttr>:$passthrough,
Expand Down
3 changes: 3 additions & 0 deletions mlir/lib/Target/LLVMIR/ModuleImport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1675,6 +1675,7 @@ static constexpr std::array kExplicitAttributes{
StringLiteral("aarch64_pstate_sm_enabled"),
StringLiteral("alwaysinline"),
StringLiteral("approx-func-fp-math"),
StringLiteral("convergent"),
StringLiteral("frame-pointer"),
StringLiteral("no-infs-fp-math"),
StringLiteral("no-nans-fp-math"),
Expand Down Expand Up @@ -1754,6 +1755,8 @@ void ModuleImport::processFunctionAttributes(llvm::Function *func,
funcOp.setAlwaysInline(true);
if (func->hasFnAttribute(llvm::Attribute::OptimizeNone))
funcOp.setOptimizeNone(true);
if (func->hasFnAttribute(llvm::Attribute::Convergent))
funcOp.setConvergent(true);

if (func->hasFnAttribute("aarch64_pstate_sm_enabled"))
funcOp.setArmStreaming(true);
Expand Down
2 changes: 2 additions & 0 deletions mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1422,6 +1422,8 @@ static void convertFunctionAttributes(LLVMFuncOp func,
llvmFunc->addFnAttr(llvm::Attribute::AlwaysInline);
if (func.getOptimizeNoneAttr())
llvmFunc->addFnAttr(llvm::Attribute::OptimizeNone);
if (func.getConvergentAttr())
llvmFunc->addFnAttr(llvm::Attribute::Convergent);
convertFunctionMemoryAttributes(func, llvmFunc);
}

Expand Down
6 changes: 6 additions & 0 deletions mlir/test/Dialect/LLVMIR/func.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,12 @@ module {
// CHECK-SAME: attributes {no_signed_zeros_fp_math = true}
llvm.return
}

llvm.func @convergent_function() attributes {convergent} {
// CHECK: @convergent_function
// CHECK-SAME: attributes {convergent}
llvm.return
}
}

// -----
Expand Down
6 changes: 6 additions & 0 deletions mlir/test/Target/LLVMIR/Import/function-attributes.ll
Original file line number Diff line number Diff line change
Expand Up @@ -361,3 +361,9 @@ declare void @alwaysinline_attribute() alwaysinline
; CHECK-LABEL: @optnone_attribute
; CHECK-SAME: attributes {no_inline, optimize_none}
declare void @optnone_attribute() noinline optnone

// -----

; CHECK-LABEL: @convergent_attribute
; CHECK-SAME: attributes {convergent}
declare void @convergent_attribute() convergent
11 changes: 11 additions & 0 deletions mlir/test/Target/LLVMIR/llvmir.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -2441,3 +2441,14 @@ llvm.func @optimize_none() attributes { no_inline, optimize_none } {

// CHECK: #[[ATTRS]]
// CHECK-SAME: optnone

// -----

// CHECK-LABEL: @convergent
// CHECK-SAME: #[[ATTRS:[0-9]+]]
llvm.func @convergent() attributes { convergent } {
llvm.return
}

// CHECK: #[[ATTRS]]
// CHECK-SAME: convergent

0 comments on commit d6df018

Please sign in to comment.