[PATCH] D106109: [Attributor] Add support for compound assignment for ChangeStatus
Shilei Tian via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 15 16:28:53 PDT 2021
tianshilei1992 created this revision.
Herald added subscribers: ormris, okura, kuter, uenoku, hiraditya.
Herald added a reviewer: uenoku.
Herald added a reviewer: homerdin.
tianshilei1992 requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added a reviewer: sstefan1.
Herald added a reviewer: baziotis.
Herald added subscribers: llvm-commits, bbn.
Herald added a project: LLVM.
A common use of `ChangeStatus` is as follows:
ChangeStatus Changed = ChangeStatus::UNCHANGED;
Changed |= foo();
where `foo` returns `ChangeStatus` as well. Currently `ChangeStatus` doesn't
support compound assignment, we have to write as
Changed = Changed | foo();
which is not that convenient.
This patch add the support for compound assignment for `ChangeStatus`. Compound
assignment is usually implemented as a member function, and binary arithmetic
operator is therefore implemented using compound assignment. However, unlike
regular C++ class, enum class doesn't support member functions. As a result, they
can only be implemented in the way shown in the patch.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D106109
Files:
llvm/include/llvm/Transforms/IPO/Attributor.h
llvm/lib/Transforms/IPO/Attributor.cpp
llvm/lib/Transforms/IPO/OpenMPOpt.cpp
Index: llvm/lib/Transforms/IPO/OpenMPOpt.cpp
===================================================================
--- llvm/lib/Transforms/IPO/OpenMPOpt.cpp
+++ llvm/lib/Transforms/IPO/OpenMPOpt.cpp
@@ -3505,7 +3505,7 @@
switch (RFKind) {
case OMPRTL___kmpc_is_spmd_exec_mode:
- Changed = Changed | foldIsSPMDExecMode(A);
+ Changed |= foldIsSPMDExecMode(A);
break;
default:
llvm_unreachable("Unhandled OpenMP runtime function!");
Index: llvm/lib/Transforms/IPO/Attributor.cpp
===================================================================
--- llvm/lib/Transforms/IPO/Attributor.cpp
+++ llvm/lib/Transforms/IPO/Attributor.cpp
@@ -161,9 +161,17 @@
ChangeStatus llvm::operator|(ChangeStatus L, ChangeStatus R) {
return L == ChangeStatus::CHANGED ? L : R;
}
+ChangeStatus &llvm::operator|=(ChangeStatus &L, ChangeStatus R) {
+ L = L | R;
+ return L;
+}
ChangeStatus llvm::operator&(ChangeStatus L, ChangeStatus R) {
return L == ChangeStatus::UNCHANGED ? L : R;
}
+ChangeStatus &llvm::operator&=(ChangeStatus &L, ChangeStatus R) {
+ L = L & R;
+ return L;
+}
///}
bool AA::isValidInScope(const Value &V, const Function *Scope) {
Index: llvm/include/llvm/Transforms/IPO/Attributor.h
===================================================================
--- llvm/include/llvm/Transforms/IPO/Attributor.h
+++ llvm/include/llvm/Transforms/IPO/Attributor.h
@@ -177,7 +177,9 @@
};
ChangeStatus operator|(ChangeStatus l, ChangeStatus r);
+ChangeStatus &operator|=(ChangeStatus &l, ChangeStatus r);
ChangeStatus operator&(ChangeStatus l, ChangeStatus r);
+ChangeStatus &operator&=(ChangeStatus &l, ChangeStatus r);
enum class DepClassTy {
REQUIRED, ///< The target cannot be valid if the source is not.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D106109.359161.patch
Type: text/x-patch
Size: 1761 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210715/7a550387/attachment.bin>
More information about the llvm-commits
mailing list