-
Notifications
You must be signed in to change notification settings - Fork 11.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[MLIR] Add the convergent attribute to LLVM Dialect #97709
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write If you have received no comments on your PR for a week, you can request a review If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-mlir @llvm/pr-subscribers-mlir-llvm Author: Finlay (FMarno) ChangesIn 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:
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
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have a test in mlir/test/Dialect/LLVMIR/func.mlir
? Also, modifying the operation assembly format in mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
(FuncOp::parse/print
) would be better than the current syntax IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There current syntax is in line with other attributes like llvm-project/mlir/test/Target/LLVMIR/Import/function-attributes.ll Lines 349 to 357 in a4ea8a4
|
Seems fair. Thanks! We'd only be missing an export to LLVM IR test then |
added MLIR to LLVMIR test
Thank you for the suggestion, that's been added now |
@FMarno Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested Please check whether problems have been caused by your change specifically, as How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
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
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