[Mlir-commits] [mlir] [MLIR] Add the convergent attribute to LLVM Dialect (PR #97709)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Jul 4 03:26:30 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-llvm
Author: Finlay (FMarno)
<details>
<summary>Changes</summary>
In order to use the convergent attribute in the GPUToLLVMSPV pass, I've added the attribute to the LLVM dialect.
---
Full diff: https://github.com/llvm/llvm-project/pull/97709.diff
5 Files Affected:
- (modified) mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td (+1)
- (modified) mlir/lib/Target/LLVMIR/ModuleImport.cpp (+3)
- (modified) mlir/lib/Target/LLVMIR/ModuleTranslation.cpp (+2)
- (modified) mlir/test/Dialect/LLVMIR/func.mlir (+6)
- (modified) mlir/test/Target/LLVMIR/Import/function-attributes.ll (+6)
``````````diff
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
index fb3b8e77c492e..3774bda05eb2b 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
@@ -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,
diff --git a/mlir/lib/Target/LLVMIR/ModuleImport.cpp b/mlir/lib/Target/LLVMIR/ModuleImport.cpp
index cfcf33436a899..9b917db5e7dfe 100644
--- a/mlir/lib/Target/LLVMIR/ModuleImport.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleImport.cpp
@@ -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"),
@@ -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);
diff --git a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
index e0b1816e2dcfb..40196a5c760f9 100644
--- a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
@@ -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);
}
diff --git a/mlir/test/Dialect/LLVMIR/func.mlir b/mlir/test/Dialect/LLVMIR/func.mlir
index 006f2f64a2727..d417942861940 100644
--- a/mlir/test/Dialect/LLVMIR/func.mlir
+++ b/mlir/test/Dialect/LLVMIR/func.mlir
@@ -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
+ }
}
// -----
diff --git a/mlir/test/Target/LLVMIR/Import/function-attributes.ll b/mlir/test/Target/LLVMIR/Import/function-attributes.ll
index d9851e99fe33b..322ce6eadab4e 100644
--- a/mlir/test/Target/LLVMIR/Import/function-attributes.ll
+++ b/mlir/test/Target/LLVMIR/Import/function-attributes.ll
@@ -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
``````````
</details>
https://github.com/llvm/llvm-project/pull/97709
More information about the Mlir-commits
mailing list