[Mlir-commits] [mlir] d6df018 - [MLIR] Add the convergent attribute to LLVM Dialect (#97709)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri Jul 5 00:33:59 PDT 2024
Author: Finlay
Date: 2024-07-05T09:33:56+02:00
New Revision: d6df01870a24cc707c724849b346111959413363
URL: https://github.com/llvm/llvm-project/commit/d6df01870a24cc707c724849b346111959413363
DIFF: https://github.com/llvm/llvm-project/commit/d6df01870a24cc707c724849b346111959413363.diff
LOG: [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
Added:
Modified:
mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
mlir/lib/Target/LLVMIR/ModuleImport.cpp
mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
mlir/test/Dialect/LLVMIR/func.mlir
mlir/test/Target/LLVMIR/Import/function-attributes.ll
mlir/test/Target/LLVMIR/llvmir.mlir
Removed:
################################################################################
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
index fb3b8e77c492e3..3774bda05eb2be 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 cfcf33436a899c..9b917db5e7dfe3 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 e0b1816e2dcfbe..40196a5c760f96 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 006f2f64a27277..d417942861940b 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 d9851e99fe33b9..322ce6eadab4e4 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
diff --git a/mlir/test/Target/LLVMIR/llvmir.mlir b/mlir/test/Target/LLVMIR/llvmir.mlir
index 7116f3b64d7f50..29fdb55c1b3018 100644
--- a/mlir/test/Target/LLVMIR/llvmir.mlir
+++ b/mlir/test/Target/LLVMIR/llvmir.mlir
@@ -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
More information about the Mlir-commits
mailing list