-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[MLIR][TBLGen] Added compound assignment operator for any BitEnum #160840
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][TBLGen] Added compound assignment operator for any BitEnum #160840
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 notified. 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 permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. 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: Alexandra Sidorova (a-sidorova) ChangesDetails:
Tickets:@amd-eochoalo Full diff: https://github.com/llvm/llvm-project/pull/160840.diff 5 Files Affected:
diff --git a/mlir/docs/DefiningDialects/Operations.md b/mlir/docs/DefiningDialects/Operations.md
index f988bebea1223..7c1be84727476 100644
--- a/mlir/docs/DefiningDialects/Operations.md
+++ b/mlir/docs/DefiningDialects/Operations.md
@@ -1649,6 +1649,15 @@ inline constexpr MyBitEnum operator&(MyBitEnum a, MyBitEnum b) {
inline constexpr MyBitEnum operator^(MyBitEnum a, MyBitEnum b) {
return static_cast<MyBitEnum>(static_cast<uint32_t>(a) ^ static_cast<uint32_t>(b));
}
+inline constexpr MyBitEnum &operator|=(MyBitEnum &a, MyBitEnum b) {
+ return a = a | b;
+}
+inline constexpr MyBitEnum &operator&=(MyBitEnum &a, MyBitEnum b) {
+ return a = a & b;
+}
+inline constexpr MyBitEnum &operator^=(MyBitEnum &a, MyBitEnum b) {
+ return a = a ^ b;
+}
inline constexpr MyBitEnum operator~(MyBitEnum bits) {
// Ensure only bits that can be present in the enum are set
return static_cast<MyBitEnum>(~static_cast<uint32_t>(bits) & static_cast<uint32_t>(15u));
diff --git a/mlir/lib/Conversion/MemRefToSPIRV/MemRefToSPIRV.cpp b/mlir/lib/Conversion/MemRefToSPIRV/MemRefToSPIRV.cpp
index 49d06497dbeea..f44552c4556c2 100644
--- a/mlir/lib/Conversion/MemRefToSPIRV/MemRefToSPIRV.cpp
+++ b/mlir/lib/Conversion/MemRefToSPIRV/MemRefToSPIRV.cpp
@@ -512,7 +512,7 @@ calculateMemoryRequirements(Value accessedPtr, bool isNontemporal,
if (!sizeInBytes.has_value())
return failure();
- memoryAccess = memoryAccess | spirv::MemoryAccess::Aligned;
+ memoryAccess |= spirv::MemoryAccess::Aligned;
auto memAccessAttr = spirv::MemoryAccessAttr::get(ctx, memoryAccess);
auto alignmentValue = preferredAlignment ? preferredAlignment : *sizeInBytes;
auto alignment = IntegerAttr::get(IntegerType::get(ctx, 32), alignmentValue);
diff --git a/mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRV.cpp b/mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRV.cpp
index 04f56b9691fd1..5061a4454a7fd 100644
--- a/mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRV.cpp
+++ b/mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRV.cpp
@@ -753,7 +753,7 @@ struct VectorLoadOpConverter final
spirv::MemoryAccessAttr memoryAccessAttr;
IntegerAttr alignmentAttr;
if (alignment.has_value()) {
- memoryAccess = memoryAccess | spirv::MemoryAccess::Aligned;
+ memoryAccess |= spirv::MemoryAccess::Aligned;
memoryAccessAttr =
spirv::MemoryAccessAttr::get(rewriter.getContext(), memoryAccess);
alignmentAttr = rewriter.getI32IntegerAttr(alignment.value());
@@ -822,7 +822,7 @@ struct VectorStoreOpConverter final
spirv::MemoryAccessAttr memoryAccessAttr;
IntegerAttr alignmentAttr;
if (alignment.has_value()) {
- memoryAccess = memoryAccess | spirv::MemoryAccess::Aligned;
+ memoryAccess |= spirv::MemoryAccess::Aligned;
memoryAccessAttr =
spirv::MemoryAccessAttr::get(rewriter.getContext(), memoryAccess);
alignmentAttr = rewriter.getI32IntegerAttr(alignment.value());
diff --git a/mlir/lib/Dialect/LLVMIR/Transforms/DIScopeForLLVMFuncOp.cpp b/mlir/lib/Dialect/LLVMIR/Transforms/DIScopeForLLVMFuncOp.cpp
index 5ceae9b16af20..67573c4ee6061 100644
--- a/mlir/lib/Dialect/LLVMIR/Transforms/DIScopeForLLVMFuncOp.cpp
+++ b/mlir/lib/Dialect/LLVMIR/Transforms/DIScopeForLLVMFuncOp.cpp
@@ -77,7 +77,7 @@ static void addScopeToFunction(LLVM::LLVMFuncOp llvmFunc,
auto subprogramFlags = LLVM::DISubprogramFlags::Optimized;
if (!llvmFunc.isExternal()) {
id = DistinctAttr::create(UnitAttr::get(context));
- subprogramFlags = subprogramFlags | LLVM::DISubprogramFlags::Definition;
+ subprogramFlags |= LLVM::DISubprogramFlags::Definition;
} else {
compileUnitAttr = {};
}
diff --git a/mlir/tools/mlir-tblgen/EnumsGen.cpp b/mlir/tools/mlir-tblgen/EnumsGen.cpp
index d152763f7382e..d4d32f5885971 100644
--- a/mlir/tools/mlir-tblgen/EnumsGen.cpp
+++ b/mlir/tools/mlir-tblgen/EnumsGen.cpp
@@ -364,6 +364,9 @@ getAllBitsUnsetCase(llvm::ArrayRef<EnumCase> cases) {
// inline constexpr <enum-type> operator|(<enum-type> a, <enum-type> b);
// inline constexpr <enum-type> operator&(<enum-type> a, <enum-type> b);
// inline constexpr <enum-type> operator^(<enum-type> a, <enum-type> b);
+// inline constexpr <enum-type> &operator|=(<enum-type> &a, <enum-type> b);
+// inline constexpr <enum-type> &operator&=(<enum-type> &a, <enum-type> b);
+// inline constexpr <enum-type> &operator^=(<enum-type> &a, <enum-type> b);
// inline constexpr <enum-type> operator~(<enum-type> bits);
// inline constexpr bool bitEnumContainsAll(<enum-type> bits, <enum-type> bit);
// inline constexpr bool bitEnumContainsAny(<enum-type> bits, <enum-type> bit);
@@ -385,6 +388,15 @@ inline constexpr {0} operator&({0} a, {0} b) {{
inline constexpr {0} operator^({0} a, {0} b) {{
return static_cast<{0}>(static_cast<{1}>(a) ^ static_cast<{1}>(b));
}
+inline constexpr {0} &operator|=({0} &a, {0} b) {{
+ return a = a | b;
+}
+inline constexpr {0} &operator&=({0} &a, {0} b) {{
+ return a = a & b;
+}
+inline constexpr {0} &operator^=({0} &a, {0} b) {{
+ return a = a ^ b;
+}
inline constexpr {0} operator~({0} bits) {{
// Ensure only bits that can be present in the enum are set
return static_cast<{0}>(~static_cast<{1}>(bits) & static_cast<{1}>({2}u));
|
|
@llvm/pr-subscribers-mlir-spirv Author: Alexandra Sidorova (a-sidorova) ChangesDetails:
Tickets:@amd-eochoalo Full diff: https://github.com/llvm/llvm-project/pull/160840.diff 5 Files Affected:
diff --git a/mlir/docs/DefiningDialects/Operations.md b/mlir/docs/DefiningDialects/Operations.md
index f988bebea1223..7c1be84727476 100644
--- a/mlir/docs/DefiningDialects/Operations.md
+++ b/mlir/docs/DefiningDialects/Operations.md
@@ -1649,6 +1649,15 @@ inline constexpr MyBitEnum operator&(MyBitEnum a, MyBitEnum b) {
inline constexpr MyBitEnum operator^(MyBitEnum a, MyBitEnum b) {
return static_cast<MyBitEnum>(static_cast<uint32_t>(a) ^ static_cast<uint32_t>(b));
}
+inline constexpr MyBitEnum &operator|=(MyBitEnum &a, MyBitEnum b) {
+ return a = a | b;
+}
+inline constexpr MyBitEnum &operator&=(MyBitEnum &a, MyBitEnum b) {
+ return a = a & b;
+}
+inline constexpr MyBitEnum &operator^=(MyBitEnum &a, MyBitEnum b) {
+ return a = a ^ b;
+}
inline constexpr MyBitEnum operator~(MyBitEnum bits) {
// Ensure only bits that can be present in the enum are set
return static_cast<MyBitEnum>(~static_cast<uint32_t>(bits) & static_cast<uint32_t>(15u));
diff --git a/mlir/lib/Conversion/MemRefToSPIRV/MemRefToSPIRV.cpp b/mlir/lib/Conversion/MemRefToSPIRV/MemRefToSPIRV.cpp
index 49d06497dbeea..f44552c4556c2 100644
--- a/mlir/lib/Conversion/MemRefToSPIRV/MemRefToSPIRV.cpp
+++ b/mlir/lib/Conversion/MemRefToSPIRV/MemRefToSPIRV.cpp
@@ -512,7 +512,7 @@ calculateMemoryRequirements(Value accessedPtr, bool isNontemporal,
if (!sizeInBytes.has_value())
return failure();
- memoryAccess = memoryAccess | spirv::MemoryAccess::Aligned;
+ memoryAccess |= spirv::MemoryAccess::Aligned;
auto memAccessAttr = spirv::MemoryAccessAttr::get(ctx, memoryAccess);
auto alignmentValue = preferredAlignment ? preferredAlignment : *sizeInBytes;
auto alignment = IntegerAttr::get(IntegerType::get(ctx, 32), alignmentValue);
diff --git a/mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRV.cpp b/mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRV.cpp
index 04f56b9691fd1..5061a4454a7fd 100644
--- a/mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRV.cpp
+++ b/mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRV.cpp
@@ -753,7 +753,7 @@ struct VectorLoadOpConverter final
spirv::MemoryAccessAttr memoryAccessAttr;
IntegerAttr alignmentAttr;
if (alignment.has_value()) {
- memoryAccess = memoryAccess | spirv::MemoryAccess::Aligned;
+ memoryAccess |= spirv::MemoryAccess::Aligned;
memoryAccessAttr =
spirv::MemoryAccessAttr::get(rewriter.getContext(), memoryAccess);
alignmentAttr = rewriter.getI32IntegerAttr(alignment.value());
@@ -822,7 +822,7 @@ struct VectorStoreOpConverter final
spirv::MemoryAccessAttr memoryAccessAttr;
IntegerAttr alignmentAttr;
if (alignment.has_value()) {
- memoryAccess = memoryAccess | spirv::MemoryAccess::Aligned;
+ memoryAccess |= spirv::MemoryAccess::Aligned;
memoryAccessAttr =
spirv::MemoryAccessAttr::get(rewriter.getContext(), memoryAccess);
alignmentAttr = rewriter.getI32IntegerAttr(alignment.value());
diff --git a/mlir/lib/Dialect/LLVMIR/Transforms/DIScopeForLLVMFuncOp.cpp b/mlir/lib/Dialect/LLVMIR/Transforms/DIScopeForLLVMFuncOp.cpp
index 5ceae9b16af20..67573c4ee6061 100644
--- a/mlir/lib/Dialect/LLVMIR/Transforms/DIScopeForLLVMFuncOp.cpp
+++ b/mlir/lib/Dialect/LLVMIR/Transforms/DIScopeForLLVMFuncOp.cpp
@@ -77,7 +77,7 @@ static void addScopeToFunction(LLVM::LLVMFuncOp llvmFunc,
auto subprogramFlags = LLVM::DISubprogramFlags::Optimized;
if (!llvmFunc.isExternal()) {
id = DistinctAttr::create(UnitAttr::get(context));
- subprogramFlags = subprogramFlags | LLVM::DISubprogramFlags::Definition;
+ subprogramFlags |= LLVM::DISubprogramFlags::Definition;
} else {
compileUnitAttr = {};
}
diff --git a/mlir/tools/mlir-tblgen/EnumsGen.cpp b/mlir/tools/mlir-tblgen/EnumsGen.cpp
index d152763f7382e..d4d32f5885971 100644
--- a/mlir/tools/mlir-tblgen/EnumsGen.cpp
+++ b/mlir/tools/mlir-tblgen/EnumsGen.cpp
@@ -364,6 +364,9 @@ getAllBitsUnsetCase(llvm::ArrayRef<EnumCase> cases) {
// inline constexpr <enum-type> operator|(<enum-type> a, <enum-type> b);
// inline constexpr <enum-type> operator&(<enum-type> a, <enum-type> b);
// inline constexpr <enum-type> operator^(<enum-type> a, <enum-type> b);
+// inline constexpr <enum-type> &operator|=(<enum-type> &a, <enum-type> b);
+// inline constexpr <enum-type> &operator&=(<enum-type> &a, <enum-type> b);
+// inline constexpr <enum-type> &operator^=(<enum-type> &a, <enum-type> b);
// inline constexpr <enum-type> operator~(<enum-type> bits);
// inline constexpr bool bitEnumContainsAll(<enum-type> bits, <enum-type> bit);
// inline constexpr bool bitEnumContainsAny(<enum-type> bits, <enum-type> bit);
@@ -385,6 +388,15 @@ inline constexpr {0} operator&({0} a, {0} b) {{
inline constexpr {0} operator^({0} a, {0} b) {{
return static_cast<{0}>(static_cast<{1}>(a) ^ static_cast<{1}>(b));
}
+inline constexpr {0} &operator|=({0} &a, {0} b) {{
+ return a = a | b;
+}
+inline constexpr {0} &operator&=({0} &a, {0} b) {{
+ return a = a & b;
+}
+inline constexpr {0} &operator^=({0} &a, {0} b) {{
+ return a = a ^ b;
+}
inline constexpr {0} operator~({0} bits) {{
// Ensure only bits that can be present in the enum are set
return static_cast<{0}>(~static_cast<{1}>(bits) & static_cast<{1}>({2}u));
|
|
@llvm/pr-subscribers-mlir-core Author: Alexandra Sidorova (a-sidorova) ChangesDetails:
Tickets:@amd-eochoalo Full diff: https://github.com/llvm/llvm-project/pull/160840.diff 5 Files Affected:
diff --git a/mlir/docs/DefiningDialects/Operations.md b/mlir/docs/DefiningDialects/Operations.md
index f988bebea1223..7c1be84727476 100644
--- a/mlir/docs/DefiningDialects/Operations.md
+++ b/mlir/docs/DefiningDialects/Operations.md
@@ -1649,6 +1649,15 @@ inline constexpr MyBitEnum operator&(MyBitEnum a, MyBitEnum b) {
inline constexpr MyBitEnum operator^(MyBitEnum a, MyBitEnum b) {
return static_cast<MyBitEnum>(static_cast<uint32_t>(a) ^ static_cast<uint32_t>(b));
}
+inline constexpr MyBitEnum &operator|=(MyBitEnum &a, MyBitEnum b) {
+ return a = a | b;
+}
+inline constexpr MyBitEnum &operator&=(MyBitEnum &a, MyBitEnum b) {
+ return a = a & b;
+}
+inline constexpr MyBitEnum &operator^=(MyBitEnum &a, MyBitEnum b) {
+ return a = a ^ b;
+}
inline constexpr MyBitEnum operator~(MyBitEnum bits) {
// Ensure only bits that can be present in the enum are set
return static_cast<MyBitEnum>(~static_cast<uint32_t>(bits) & static_cast<uint32_t>(15u));
diff --git a/mlir/lib/Conversion/MemRefToSPIRV/MemRefToSPIRV.cpp b/mlir/lib/Conversion/MemRefToSPIRV/MemRefToSPIRV.cpp
index 49d06497dbeea..f44552c4556c2 100644
--- a/mlir/lib/Conversion/MemRefToSPIRV/MemRefToSPIRV.cpp
+++ b/mlir/lib/Conversion/MemRefToSPIRV/MemRefToSPIRV.cpp
@@ -512,7 +512,7 @@ calculateMemoryRequirements(Value accessedPtr, bool isNontemporal,
if (!sizeInBytes.has_value())
return failure();
- memoryAccess = memoryAccess | spirv::MemoryAccess::Aligned;
+ memoryAccess |= spirv::MemoryAccess::Aligned;
auto memAccessAttr = spirv::MemoryAccessAttr::get(ctx, memoryAccess);
auto alignmentValue = preferredAlignment ? preferredAlignment : *sizeInBytes;
auto alignment = IntegerAttr::get(IntegerType::get(ctx, 32), alignmentValue);
diff --git a/mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRV.cpp b/mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRV.cpp
index 04f56b9691fd1..5061a4454a7fd 100644
--- a/mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRV.cpp
+++ b/mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRV.cpp
@@ -753,7 +753,7 @@ struct VectorLoadOpConverter final
spirv::MemoryAccessAttr memoryAccessAttr;
IntegerAttr alignmentAttr;
if (alignment.has_value()) {
- memoryAccess = memoryAccess | spirv::MemoryAccess::Aligned;
+ memoryAccess |= spirv::MemoryAccess::Aligned;
memoryAccessAttr =
spirv::MemoryAccessAttr::get(rewriter.getContext(), memoryAccess);
alignmentAttr = rewriter.getI32IntegerAttr(alignment.value());
@@ -822,7 +822,7 @@ struct VectorStoreOpConverter final
spirv::MemoryAccessAttr memoryAccessAttr;
IntegerAttr alignmentAttr;
if (alignment.has_value()) {
- memoryAccess = memoryAccess | spirv::MemoryAccess::Aligned;
+ memoryAccess |= spirv::MemoryAccess::Aligned;
memoryAccessAttr =
spirv::MemoryAccessAttr::get(rewriter.getContext(), memoryAccess);
alignmentAttr = rewriter.getI32IntegerAttr(alignment.value());
diff --git a/mlir/lib/Dialect/LLVMIR/Transforms/DIScopeForLLVMFuncOp.cpp b/mlir/lib/Dialect/LLVMIR/Transforms/DIScopeForLLVMFuncOp.cpp
index 5ceae9b16af20..67573c4ee6061 100644
--- a/mlir/lib/Dialect/LLVMIR/Transforms/DIScopeForLLVMFuncOp.cpp
+++ b/mlir/lib/Dialect/LLVMIR/Transforms/DIScopeForLLVMFuncOp.cpp
@@ -77,7 +77,7 @@ static void addScopeToFunction(LLVM::LLVMFuncOp llvmFunc,
auto subprogramFlags = LLVM::DISubprogramFlags::Optimized;
if (!llvmFunc.isExternal()) {
id = DistinctAttr::create(UnitAttr::get(context));
- subprogramFlags = subprogramFlags | LLVM::DISubprogramFlags::Definition;
+ subprogramFlags |= LLVM::DISubprogramFlags::Definition;
} else {
compileUnitAttr = {};
}
diff --git a/mlir/tools/mlir-tblgen/EnumsGen.cpp b/mlir/tools/mlir-tblgen/EnumsGen.cpp
index d152763f7382e..d4d32f5885971 100644
--- a/mlir/tools/mlir-tblgen/EnumsGen.cpp
+++ b/mlir/tools/mlir-tblgen/EnumsGen.cpp
@@ -364,6 +364,9 @@ getAllBitsUnsetCase(llvm::ArrayRef<EnumCase> cases) {
// inline constexpr <enum-type> operator|(<enum-type> a, <enum-type> b);
// inline constexpr <enum-type> operator&(<enum-type> a, <enum-type> b);
// inline constexpr <enum-type> operator^(<enum-type> a, <enum-type> b);
+// inline constexpr <enum-type> &operator|=(<enum-type> &a, <enum-type> b);
+// inline constexpr <enum-type> &operator&=(<enum-type> &a, <enum-type> b);
+// inline constexpr <enum-type> &operator^=(<enum-type> &a, <enum-type> b);
// inline constexpr <enum-type> operator~(<enum-type> bits);
// inline constexpr bool bitEnumContainsAll(<enum-type> bits, <enum-type> bit);
// inline constexpr bool bitEnumContainsAny(<enum-type> bits, <enum-type> bit);
@@ -385,6 +388,15 @@ inline constexpr {0} operator&({0} a, {0} b) {{
inline constexpr {0} operator^({0} a, {0} b) {{
return static_cast<{0}>(static_cast<{1}>(a) ^ static_cast<{1}>(b));
}
+inline constexpr {0} &operator|=({0} &a, {0} b) {{
+ return a = a | b;
+}
+inline constexpr {0} &operator&=({0} &a, {0} b) {{
+ return a = a & b;
+}
+inline constexpr {0} &operator^=({0} &a, {0} b) {{
+ return a = a ^ b;
+}
inline constexpr {0} operator~({0} bits) {{
// Ensure only bits that can be present in the enum are set
return static_cast<{0}>(~static_cast<{1}>(bits) & static_cast<{1}>({2}u));
|
amd-eochoalo
left a comment
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.
This looks great @a-sidorova !
Just one note, can you not reference github users on the PR description? See here for reference.
Before committing, also remove my name from the commit message as it is not useful in the commit message. (The PR description will become the commit message.)
|
I've let the checks run. Please merge only after the tests are done. |
Sounds fair, I'll try to spare you unnecessary notifications. Waiting for CI status |
|
@a-sidorova 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 by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. 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. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/116/builds/18921 Here is the relevant piece of the build log for the reference |
|
Seems unrelated. |
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/129/builds/30359 Here is the relevant piece of the build log for the reference |
…vm#160840) ## Details: - Added missing compound assignment operators `|=`, `&=`, `^=` to `mlir-tblgen` - Replaced the arithmetic operators with added assignment operators for `BitEnum` in the transformations - Updated related documentation ## Tickets: - Closes llvm#158098
Details:
|=,&=,^=tomlir-tblgenBitEnumin the transformationsTickets: