[llvm] r301518 - Use accessors for ValueHandleBase::V; NFC
Sanjoy Das via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 26 23:02:18 PDT 2017
Author: sanjoy
Date: Thu Apr 27 01:02:18 2017
New Revision: 301518
URL: http://llvm.org/viewvc/llvm-project?rev=301518&view=rev
Log:
Use accessors for ValueHandleBase::V; NFC
This changes code that touches ValueHandleBase::V to go through
getValPtr and (newly added) setValPtr. This functionality will be
used later, but also seemed like a generally good cleanup.
I also renamed the field to Val, but that's just to make it obvious
that I fixed all the uses.
Modified:
llvm/trunk/include/llvm/IR/ValueHandle.h
llvm/trunk/lib/IR/Value.cpp
Modified: llvm/trunk/include/llvm/IR/ValueHandle.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/ValueHandle.h?rev=301518&r1=301517&r2=301518&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/ValueHandle.h (original)
+++ llvm/trunk/include/llvm/IR/ValueHandle.h Thu Apr 27 01:02:18 2017
@@ -45,8 +45,8 @@ protected:
: ValueHandleBase(RHS.PrevPair.getInt(), RHS) {}
ValueHandleBase(HandleBaseKind Kind, const ValueHandleBase &RHS)
- : PrevPair(nullptr, Kind), Next(nullptr), V(RHS.V) {
- if (isValid(V))
+ : PrevPair(nullptr, Kind), Next(nullptr), Val(RHS.getValPtr()) {
+ if (isValid(getValPtr()))
AddToExistingUseList(RHS.getPrevPtr());
}
@@ -54,43 +54,51 @@ private:
PointerIntPair<ValueHandleBase**, 2, HandleBaseKind> PrevPair;
ValueHandleBase *Next;
- Value* V;
+ Value *Val;
+
+ void setValPtr(Value *V) { Val = V; }
public:
explicit ValueHandleBase(HandleBaseKind Kind)
- : PrevPair(nullptr, Kind), Next(nullptr), V(nullptr) {}
+ : PrevPair(nullptr, Kind), Next(nullptr), Val(nullptr) {}
ValueHandleBase(HandleBaseKind Kind, Value *V)
- : PrevPair(nullptr, Kind), Next(nullptr), V(V) {
- if (isValid(V))
+ : PrevPair(nullptr, Kind), Next(nullptr), Val(V) {
+ if (isValid(getValPtr()))
AddToUseList();
}
~ValueHandleBase() {
- if (isValid(V))
+ if (isValid(getValPtr()))
RemoveFromUseList();
}
Value *operator=(Value *RHS) {
- if (V == RHS) return RHS;
- if (isValid(V)) RemoveFromUseList();
- V = RHS;
- if (isValid(V)) AddToUseList();
+ if (getValPtr() == RHS)
+ return RHS;
+ if (isValid(getValPtr()))
+ RemoveFromUseList();
+ setValPtr(RHS);
+ if (isValid(getValPtr()))
+ AddToUseList();
return RHS;
}
Value *operator=(const ValueHandleBase &RHS) {
- if (V == RHS.V) return RHS.V;
- if (isValid(V)) RemoveFromUseList();
- V = RHS.V;
- if (isValid(V)) AddToExistingUseList(RHS.getPrevPtr());
- return V;
+ if (getValPtr() == RHS.getValPtr())
+ return RHS.getValPtr();
+ if (isValid(getValPtr()))
+ RemoveFromUseList();
+ setValPtr(RHS.getValPtr());
+ if (isValid(getValPtr()))
+ AddToExistingUseList(RHS.getPrevPtr());
+ return getValPtr();
}
- Value *operator->() const { return V; }
- Value &operator*() const { return *V; }
+ Value *operator->() const { return getValPtr(); }
+ Value &operator*() const { return *getValPtr(); }
protected:
- Value *getValPtr() const { return V; }
+ Value *getValPtr() const { return Val; }
static bool isValid(Value *V) {
return V &&
@@ -105,7 +113,7 @@ protected:
///
/// This should only be used if a derived class has manually removed the
/// handle from the use list.
- void clearValPtr() { V = nullptr; }
+ void clearValPtr() { setValPtr(nullptr); }
public:
// Callbacks made from Value.
Modified: llvm/trunk/lib/IR/Value.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Value.cpp?rev=301518&r1=301517&r2=301518&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Value.cpp (original)
+++ llvm/trunk/lib/IR/Value.cpp Thu Apr 27 01:02:18 2017
@@ -711,7 +711,7 @@ void ValueHandleBase::AddToExistingUseLi
setPrevPtr(List);
if (Next) {
Next->setPrevPtr(&Next);
- assert(V == Next->V && "Added to wrong list?");
+ assert(getValPtr() == Next->getValPtr() && "Added to wrong list?");
}
}
@@ -726,14 +726,14 @@ void ValueHandleBase::AddToExistingUseLi
}
void ValueHandleBase::AddToUseList() {
- assert(V && "Null pointer doesn't have a use list!");
+ assert(getValPtr() && "Null pointer doesn't have a use list!");
- LLVMContextImpl *pImpl = V->getContext().pImpl;
+ LLVMContextImpl *pImpl = getValPtr()->getContext().pImpl;
- if (V->HasValueHandle) {
+ if (getValPtr()->HasValueHandle) {
// If this value already has a ValueHandle, then it must be in the
// ValueHandles map already.
- ValueHandleBase *&Entry = pImpl->ValueHandles[V];
+ ValueHandleBase *&Entry = pImpl->ValueHandles[getValPtr()];
assert(Entry && "Value doesn't have any handles?");
AddToExistingUseList(&Entry);
return;
@@ -747,10 +747,10 @@ void ValueHandleBase::AddToUseList() {
DenseMap<Value*, ValueHandleBase*> &Handles = pImpl->ValueHandles;
const void *OldBucketPtr = Handles.getPointerIntoBucketsArray();
- ValueHandleBase *&Entry = Handles[V];
+ ValueHandleBase *&Entry = Handles[getValPtr()];
assert(!Entry && "Value really did already have handles?");
AddToExistingUseList(&Entry);
- V->HasValueHandle = true;
+ getValPtr()->HasValueHandle = true;
// If reallocation didn't happen or if this was the first insertion, don't
// walk the table.
@@ -762,14 +762,14 @@ void ValueHandleBase::AddToUseList() {
// Okay, reallocation did happen. Fix the Prev Pointers.
for (DenseMap<Value*, ValueHandleBase*>::iterator I = Handles.begin(),
E = Handles.end(); I != E; ++I) {
- assert(I->second && I->first == I->second->V &&
+ assert(I->second && I->first == I->second->getValPtr() &&
"List invariant broken!");
I->second->setPrevPtr(&I->second);
}
}
void ValueHandleBase::RemoveFromUseList() {
- assert(V && V->HasValueHandle &&
+ assert(getValPtr() && getValPtr()->HasValueHandle &&
"Pointer doesn't have a use list!");
// Unlink this from its use list.
@@ -786,11 +786,11 @@ void ValueHandleBase::RemoveFromUseList(
// If the Next pointer was null, then it is possible that this was the last
// ValueHandle watching VP. If so, delete its entry from the ValueHandles
// map.
- LLVMContextImpl *pImpl = V->getContext().pImpl;
+ LLVMContextImpl *pImpl = getValPtr()->getContext().pImpl;
DenseMap<Value*, ValueHandleBase*> &Handles = pImpl->ValueHandles;
if (Handles.isPointerIntoBucketsArray(PrevPtr)) {
- Handles.erase(V);
- V->HasValueHandle = false;
+ Handles.erase(getValPtr());
+ getValPtr()->HasValueHandle = false;
}
}
More information about the llvm-commits
mailing list