mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-23 19:23:23 +01:00
Cleaup ValueHandle to no longer keep a PointerIntPair for the Value*.
This was used previously for metadata but is no longer needed there. Not doing this simplifies ValueHandle and will make it easier to fix things like AssertingVH's DenseMapInfo. llvm-svn: 225487
This commit is contained in:
parent
87302ccea9
commit
6f0624b9b5
@ -56,55 +56,48 @@ private:
|
||||
PointerIntPair<ValueHandleBase**, 2, HandleBaseKind> PrevPair;
|
||||
ValueHandleBase *Next;
|
||||
|
||||
// A subclass may want to store some information along with the value
|
||||
// pointer. Allow them to do this by making the value pointer a pointer-int
|
||||
// pair. The 'setValPtrInt' and 'getValPtrInt' methods below give them this
|
||||
// access.
|
||||
PointerIntPair<Value*, 2> VP;
|
||||
Value* V;
|
||||
|
||||
ValueHandleBase(const ValueHandleBase&) LLVM_DELETED_FUNCTION;
|
||||
public:
|
||||
explicit ValueHandleBase(HandleBaseKind Kind)
|
||||
: PrevPair(nullptr, Kind), Next(nullptr), VP(nullptr, 0) {}
|
||||
: PrevPair(nullptr, Kind), Next(nullptr), V(nullptr) {}
|
||||
ValueHandleBase(HandleBaseKind Kind, Value *V)
|
||||
: PrevPair(nullptr, Kind), Next(nullptr), VP(V, 0) {
|
||||
if (isValid(VP.getPointer()))
|
||||
: PrevPair(nullptr, Kind), Next(nullptr), V(V) {
|
||||
if (isValid(V))
|
||||
AddToUseList();
|
||||
}
|
||||
ValueHandleBase(HandleBaseKind Kind, const ValueHandleBase &RHS)
|
||||
: PrevPair(nullptr, Kind), Next(nullptr), VP(RHS.VP) {
|
||||
if (isValid(VP.getPointer()))
|
||||
: PrevPair(nullptr, Kind), Next(nullptr), V(RHS.V) {
|
||||
if (isValid(V))
|
||||
AddToExistingUseList(RHS.getPrevPtr());
|
||||
}
|
||||
~ValueHandleBase() {
|
||||
if (isValid(VP.getPointer()))
|
||||
if (isValid(V))
|
||||
RemoveFromUseList();
|
||||
}
|
||||
|
||||
Value *operator=(Value *RHS) {
|
||||
if (VP.getPointer() == RHS) return RHS;
|
||||
if (isValid(VP.getPointer())) RemoveFromUseList();
|
||||
VP.setPointer(RHS);
|
||||
if (isValid(VP.getPointer())) AddToUseList();
|
||||
if (V == RHS) return RHS;
|
||||
if (isValid(V)) RemoveFromUseList();
|
||||
V = RHS;
|
||||
if (isValid(V)) AddToUseList();
|
||||
return RHS;
|
||||
}
|
||||
|
||||
Value *operator=(const ValueHandleBase &RHS) {
|
||||
if (VP.getPointer() == RHS.VP.getPointer()) return RHS.VP.getPointer();
|
||||
if (isValid(VP.getPointer())) RemoveFromUseList();
|
||||
VP.setPointer(RHS.VP.getPointer());
|
||||
if (isValid(VP.getPointer())) AddToExistingUseList(RHS.getPrevPtr());
|
||||
return VP.getPointer();
|
||||
if (V == RHS.V) return RHS.V;
|
||||
if (isValid(V)) RemoveFromUseList();
|
||||
V = RHS.V;
|
||||
if (isValid(V)) AddToExistingUseList(RHS.getPrevPtr());
|
||||
return V;
|
||||
}
|
||||
|
||||
Value *operator->() const { return getValPtr(); }
|
||||
Value &operator*() const { return *getValPtr(); }
|
||||
Value *operator->() const { return V; }
|
||||
Value &operator*() const { return *V; }
|
||||
|
||||
protected:
|
||||
Value *getValPtr() const { return VP.getPointer(); }
|
||||
|
||||
void setValPtrInt(unsigned K) { VP.setInt(K); }
|
||||
unsigned getValPtrInt() const { return VP.getInt(); }
|
||||
Value *getValPtr() const { return V; }
|
||||
|
||||
static bool isValid(Value *V) {
|
||||
return V &&
|
||||
@ -123,7 +116,7 @@ private:
|
||||
HandleBaseKind getKind() const { return PrevPair.getInt(); }
|
||||
void setPrevPtr(ValueHandleBase **Ptr) { PrevPair.setPointer(Ptr); }
|
||||
|
||||
/// \brief Add this ValueHandle to the use list for VP.
|
||||
/// \brief Add this ValueHandle to the use list for V.
|
||||
///
|
||||
/// List is the address of either the head of the list or a Next node within
|
||||
/// the existing use list.
|
||||
@ -132,7 +125,7 @@ private:
|
||||
/// \brief Add this ValueHandle to the use list after Node.
|
||||
void AddToExistingUseListAfter(ValueHandleBase *Node);
|
||||
|
||||
/// \brief Add this ValueHandle to the use list for VP.
|
||||
/// \brief Add this ValueHandle to the use list for V.
|
||||
void AddToUseList();
|
||||
/// \brief Remove this ValueHandle from its current use list.
|
||||
void RemoveFromUseList();
|
||||
|
@ -645,7 +645,7 @@ void ValueHandleBase::AddToExistingUseList(ValueHandleBase **List) {
|
||||
setPrevPtr(List);
|
||||
if (Next) {
|
||||
Next->setPrevPtr(&Next);
|
||||
assert(VP.getPointer() == Next->VP.getPointer() && "Added to wrong list?");
|
||||
assert(V == Next->V && "Added to wrong list?");
|
||||
}
|
||||
}
|
||||
|
||||
@ -660,14 +660,14 @@ void ValueHandleBase::AddToExistingUseListAfter(ValueHandleBase *List) {
|
||||
}
|
||||
|
||||
void ValueHandleBase::AddToUseList() {
|
||||
assert(VP.getPointer() && "Null pointer doesn't have a use list!");
|
||||
assert(V && "Null pointer doesn't have a use list!");
|
||||
|
||||
LLVMContextImpl *pImpl = VP.getPointer()->getContext().pImpl;
|
||||
LLVMContextImpl *pImpl = V->getContext().pImpl;
|
||||
|
||||
if (VP.getPointer()->HasValueHandle) {
|
||||
if (V->HasValueHandle) {
|
||||
// If this value already has a ValueHandle, then it must be in the
|
||||
// ValueHandles map already.
|
||||
ValueHandleBase *&Entry = pImpl->ValueHandles[VP.getPointer()];
|
||||
ValueHandleBase *&Entry = pImpl->ValueHandles[V];
|
||||
assert(Entry && "Value doesn't have any handles?");
|
||||
AddToExistingUseList(&Entry);
|
||||
return;
|
||||
@ -681,10 +681,10 @@ void ValueHandleBase::AddToUseList() {
|
||||
DenseMap<Value*, ValueHandleBase*> &Handles = pImpl->ValueHandles;
|
||||
const void *OldBucketPtr = Handles.getPointerIntoBucketsArray();
|
||||
|
||||
ValueHandleBase *&Entry = Handles[VP.getPointer()];
|
||||
ValueHandleBase *&Entry = Handles[V];
|
||||
assert(!Entry && "Value really did already have handles?");
|
||||
AddToExistingUseList(&Entry);
|
||||
VP.getPointer()->HasValueHandle = true;
|
||||
V->HasValueHandle = true;
|
||||
|
||||
// If reallocation didn't happen or if this was the first insertion, don't
|
||||
// walk the table.
|
||||
@ -696,14 +696,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->VP.getPointer() &&
|
||||
assert(I->second && I->first == I->second->V &&
|
||||
"List invariant broken!");
|
||||
I->second->setPrevPtr(&I->second);
|
||||
}
|
||||
}
|
||||
|
||||
void ValueHandleBase::RemoveFromUseList() {
|
||||
assert(VP.getPointer() && VP.getPointer()->HasValueHandle &&
|
||||
assert(V && V->HasValueHandle &&
|
||||
"Pointer doesn't have a use list!");
|
||||
|
||||
// Unlink this from its use list.
|
||||
@ -720,11 +720,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 = VP.getPointer()->getContext().pImpl;
|
||||
LLVMContextImpl *pImpl = V->getContext().pImpl;
|
||||
DenseMap<Value*, ValueHandleBase*> &Handles = pImpl->ValueHandles;
|
||||
if (Handles.isPointerIntoBucketsArray(PrevPtr)) {
|
||||
Handles.erase(VP.getPointer());
|
||||
VP.getPointer()->HasValueHandle = false;
|
||||
Handles.erase(V);
|
||||
V->HasValueHandle = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user