forked from OSchip/llvm-project
[Attributor] Add support for compound assignment for ChangeStatus
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. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D106109
This commit is contained in:
parent
16b5e9d6a2
commit
c23da666b5
|
@ -177,7 +177,9 @@ enum class ChangeStatus {
|
|||
};
|
||||
|
||||
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.
|
||||
|
|
|
@ -161,9 +161,17 @@ static cl::opt<bool>
|
|||
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) {
|
||||
|
|
|
@ -3505,7 +3505,7 @@ struct AAFoldRuntimeCallCallSiteReturned : AAFoldRuntimeCall {
|
|||
|
||||
switch (RFKind) {
|
||||
case OMPRTL___kmpc_is_spmd_exec_mode:
|
||||
Changed = Changed | foldIsSPMDExecMode(A);
|
||||
Changed |= foldIsSPMDExecMode(A);
|
||||
break;
|
||||
default:
|
||||
llvm_unreachable("Unhandled OpenMP runtime function!");
|
||||
|
|
Loading…
Reference in New Issue