[llvm] d2e15a8 - [RS4GC] Cleanup meetBDVState. NFC.
Serguei Katkov via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 8 21:18:37 PDT 2021
Author: Serguei Katkov
Date: 2021-04-09T10:20:25+07:00
New Revision: d2e15a83a664ba6cdfa9d17e81ecc9115b2c5046
URL: https://github.com/llvm/llvm-project/commit/d2e15a83a664ba6cdfa9d17e81ecc9115b2c5046
DIFF: https://github.com/llvm/llvm-project/commit/d2e15a83a664ba6cdfa9d17e81ecc9115b2c5046.diff
LOG: [RS4GC] Cleanup meetBDVState. NFC.
meetBDVState looks pretty difficult to read and follow.
This is purely NFC but doing several things:
1) Combine meet and meetBDVState
2) Move the function to be a member of BDVState
3) Make BDVState be a mutable object
4) Convert switch to sequence of ifs
5) Adds comments.
Reviewers: reames, dantrushin
Reviewed By: reames
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D99064
Added:
Modified:
llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp b/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
index 91c3de569d2f..78291b354f88 100644
--- a/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
+++ b/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
@@ -706,6 +706,39 @@ class BDVState {
bool isUnknown() const { return getStatus() == Unknown; }
bool isConflict() const { return getStatus() == Conflict; }
+ // Values of type BDVState form a lattice, and this function implements the
+ // meet
+ // operation.
+ void meet(const BDVState &Other) {
+ auto markConflict = [&]() {
+ Status = BDVState::Conflict;
+ BaseValue = nullptr;
+ };
+ // Conflict is a final state.
+ if (isConflict())
+ return;
+ // if we are not known - just take other state.
+ if (isUnknown()) {
+ Status = Other.getStatus();
+ BaseValue = Other.getBaseValue();
+ return;
+ }
+ // We are base.
+ assert(isBase() && "Unknown state");
+ // If other is unknown - just keep our state.
+ if (Other.isUnknown())
+ return;
+ // If other is conflict - it is a final state.
+ if (Other.isConflict())
+ return markConflict();
+ // Other is base as well.
+ assert(Other.isBase() && "Unknown state");
+ // If bases are
diff erent - Conflict.
+ if (getBaseValue() != Other.getBaseValue())
+ return markConflict();
+ // We are identical, do nothing.
+ }
+
bool operator==(const BDVState &Other) const {
return OriginalValue == OriginalValue && BaseValue == Other.BaseValue &&
Status == Other.Status;
@@ -751,43 +784,6 @@ static raw_ostream &operator<<(raw_ostream &OS, const BDVState &State) {
}
#endif
-static BDVState::StatusTy meet(const BDVState::StatusTy &LHS,
- const BDVState::StatusTy &RHS) {
- switch (LHS) {
- case BDVState::Unknown:
- return RHS;
- case BDVState::Base:
- switch (RHS) {
- case BDVState::Unknown:
- case BDVState::Base:
- return BDVState::Base;
- case BDVState::Conflict:
- return BDVState::Conflict;
- };
- llvm_unreachable("covered switch");
- case BDVState::Conflict:
- return BDVState::Conflict;
- }
- llvm_unreachable("covered switch");
-}
-
-// Values of type BDVState form a lattice, and this function implements the meet
-// operation.
-static BDVState meetBDVState(const BDVState &LHS, const BDVState &RHS) {
- auto NewStatus = meet(LHS.getStatus(), RHS.getStatus());
- assert(NewStatus == meet(RHS.getStatus(), LHS.getStatus()));
-
- Value *BaseValue = LHS.getStatus() == BDVState::Base ?
- LHS.getBaseValue() : RHS.getBaseValue();
- if (LHS.getStatus() == BDVState::Base && RHS.getStatus() == BDVState::Base &&
- LHS.getBaseValue() != RHS.getBaseValue()) {
- NewStatus = BDVState::Conflict;
- }
- if (NewStatus == BDVState::Conflict)
- BaseValue = nullptr;
- return BDVState(LHS.getOriginalValue(), NewStatus, BaseValue);
-}
-
/// For a given value or instruction, figure out what base ptr its derived from.
/// For gc objects, this is simply itself. On success, returns a value which is
/// the base pointer. (This is reliable and can be used for relocation.) On
@@ -971,10 +967,10 @@ static Value *findBasePointer(Value *I, DefiningValueMapTy &Cache) {
"why did it get added?");
BDVState NewState(BDV);
- visitBDVOperands(BDV, [&] (Value *Op) {
+ visitBDVOperands(BDV, [&](Value *Op) {
Value *BDV = findBaseOrBDV(Op, Cache);
auto OpState = GetStateForBDV(BDV, Op);
- NewState = meetBDVState(NewState, OpState);
+ NewState.meet(OpState);
});
BDVState OldState = States[BDV];
More information about the llvm-commits
mailing list