forked from OSchip/llvm-project
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
9aa7e8e9ff
commit
f4ea3d3d9c
|
@ -56,55 +56,48 @@ private:
|
||||||
PointerIntPair<ValueHandleBase**, 2, HandleBaseKind> PrevPair;
|
PointerIntPair<ValueHandleBase**, 2, HandleBaseKind> PrevPair;
|
||||||
ValueHandleBase *Next;
|
ValueHandleBase *Next;
|
||||||
|
|
||||||
// A subclass may want to store some information along with the value
|
Value* V;
|
||||||
// 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;
|
|
||||||
|
|
||||||
ValueHandleBase(const ValueHandleBase&) LLVM_DELETED_FUNCTION;
|
ValueHandleBase(const ValueHandleBase&) LLVM_DELETED_FUNCTION;
|
||||||
public:
|
public:
|
||||||
explicit ValueHandleBase(HandleBaseKind Kind)
|
explicit ValueHandleBase(HandleBaseKind Kind)
|
||||||
: PrevPair(nullptr, Kind), Next(nullptr), VP(nullptr, 0) {}
|
: PrevPair(nullptr, Kind), Next(nullptr), V(nullptr) {}
|
||||||
ValueHandleBase(HandleBaseKind Kind, Value *V)
|
ValueHandleBase(HandleBaseKind Kind, Value *V)
|
||||||
: PrevPair(nullptr, Kind), Next(nullptr), VP(V, 0) {
|
: PrevPair(nullptr, Kind), Next(nullptr), V(V) {
|
||||||
if (isValid(VP.getPointer()))
|
if (isValid(V))
|
||||||
AddToUseList();
|
AddToUseList();
|
||||||
}
|
}
|
||||||
ValueHandleBase(HandleBaseKind Kind, const ValueHandleBase &RHS)
|
ValueHandleBase(HandleBaseKind Kind, const ValueHandleBase &RHS)
|
||||||
: PrevPair(nullptr, Kind), Next(nullptr), VP(RHS.VP) {
|
: PrevPair(nullptr, Kind), Next(nullptr), V(RHS.V) {
|
||||||
if (isValid(VP.getPointer()))
|
if (isValid(V))
|
||||||
AddToExistingUseList(RHS.getPrevPtr());
|
AddToExistingUseList(RHS.getPrevPtr());
|
||||||
}
|
}
|
||||||
~ValueHandleBase() {
|
~ValueHandleBase() {
|
||||||
if (isValid(VP.getPointer()))
|
if (isValid(V))
|
||||||
RemoveFromUseList();
|
RemoveFromUseList();
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *operator=(Value *RHS) {
|
Value *operator=(Value *RHS) {
|
||||||
if (VP.getPointer() == RHS) return RHS;
|
if (V == RHS) return RHS;
|
||||||
if (isValid(VP.getPointer())) RemoveFromUseList();
|
if (isValid(V)) RemoveFromUseList();
|
||||||
VP.setPointer(RHS);
|
V = RHS;
|
||||||
if (isValid(VP.getPointer())) AddToUseList();
|
if (isValid(V)) AddToUseList();
|
||||||
return RHS;
|
return RHS;
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *operator=(const ValueHandleBase &RHS) {
|
Value *operator=(const ValueHandleBase &RHS) {
|
||||||
if (VP.getPointer() == RHS.VP.getPointer()) return RHS.VP.getPointer();
|
if (V == RHS.V) return RHS.V;
|
||||||
if (isValid(VP.getPointer())) RemoveFromUseList();
|
if (isValid(V)) RemoveFromUseList();
|
||||||
VP.setPointer(RHS.VP.getPointer());
|
V = RHS.V;
|
||||||
if (isValid(VP.getPointer())) AddToExistingUseList(RHS.getPrevPtr());
|
if (isValid(V)) AddToExistingUseList(RHS.getPrevPtr());
|
||||||
return VP.getPointer();
|
return V;
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *operator->() const { return getValPtr(); }
|
Value *operator->() const { return V; }
|
||||||
Value &operator*() const { return *getValPtr(); }
|
Value &operator*() const { return *V; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Value *getValPtr() const { return VP.getPointer(); }
|
Value *getValPtr() const { return V; }
|
||||||
|
|
||||||
void setValPtrInt(unsigned K) { VP.setInt(K); }
|
|
||||||
unsigned getValPtrInt() const { return VP.getInt(); }
|
|
||||||
|
|
||||||
static bool isValid(Value *V) {
|
static bool isValid(Value *V) {
|
||||||
return V &&
|
return V &&
|
||||||
|
@ -123,7 +116,7 @@ private:
|
||||||
HandleBaseKind getKind() const { return PrevPair.getInt(); }
|
HandleBaseKind getKind() const { return PrevPair.getInt(); }
|
||||||
void setPrevPtr(ValueHandleBase **Ptr) { PrevPair.setPointer(Ptr); }
|
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
|
/// List is the address of either the head of the list or a Next node within
|
||||||
/// the existing use list.
|
/// the existing use list.
|
||||||
|
@ -132,7 +125,7 @@ private:
|
||||||
/// \brief Add this ValueHandle to the use list after Node.
|
/// \brief Add this ValueHandle to the use list after Node.
|
||||||
void AddToExistingUseListAfter(ValueHandleBase *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();
|
void AddToUseList();
|
||||||
/// \brief Remove this ValueHandle from its current use list.
|
/// \brief Remove this ValueHandle from its current use list.
|
||||||
void RemoveFromUseList();
|
void RemoveFromUseList();
|
||||||
|
|
|
@ -645,7 +645,7 @@ void ValueHandleBase::AddToExistingUseList(ValueHandleBase **List) {
|
||||||
setPrevPtr(List);
|
setPrevPtr(List);
|
||||||
if (Next) {
|
if (Next) {
|
||||||
Next->setPrevPtr(&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() {
|
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
|
// If this value already has a ValueHandle, then it must be in the
|
||||||
// ValueHandles map already.
|
// ValueHandles map already.
|
||||||
ValueHandleBase *&Entry = pImpl->ValueHandles[VP.getPointer()];
|
ValueHandleBase *&Entry = pImpl->ValueHandles[V];
|
||||||
assert(Entry && "Value doesn't have any handles?");
|
assert(Entry && "Value doesn't have any handles?");
|
||||||
AddToExistingUseList(&Entry);
|
AddToExistingUseList(&Entry);
|
||||||
return;
|
return;
|
||||||
|
@ -681,10 +681,10 @@ void ValueHandleBase::AddToUseList() {
|
||||||
DenseMap<Value*, ValueHandleBase*> &Handles = pImpl->ValueHandles;
|
DenseMap<Value*, ValueHandleBase*> &Handles = pImpl->ValueHandles;
|
||||||
const void *OldBucketPtr = Handles.getPointerIntoBucketsArray();
|
const void *OldBucketPtr = Handles.getPointerIntoBucketsArray();
|
||||||
|
|
||||||
ValueHandleBase *&Entry = Handles[VP.getPointer()];
|
ValueHandleBase *&Entry = Handles[V];
|
||||||
assert(!Entry && "Value really did already have handles?");
|
assert(!Entry && "Value really did already have handles?");
|
||||||
AddToExistingUseList(&Entry);
|
AddToExistingUseList(&Entry);
|
||||||
VP.getPointer()->HasValueHandle = true;
|
V->HasValueHandle = true;
|
||||||
|
|
||||||
// If reallocation didn't happen or if this was the first insertion, don't
|
// If reallocation didn't happen or if this was the first insertion, don't
|
||||||
// walk the table.
|
// walk the table.
|
||||||
|
@ -696,14 +696,14 @@ void ValueHandleBase::AddToUseList() {
|
||||||
// Okay, reallocation did happen. Fix the Prev Pointers.
|
// Okay, reallocation did happen. Fix the Prev Pointers.
|
||||||
for (DenseMap<Value*, ValueHandleBase*>::iterator I = Handles.begin(),
|
for (DenseMap<Value*, ValueHandleBase*>::iterator I = Handles.begin(),
|
||||||
E = Handles.end(); I != E; ++I) {
|
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!");
|
"List invariant broken!");
|
||||||
I->second->setPrevPtr(&I->second);
|
I->second->setPrevPtr(&I->second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ValueHandleBase::RemoveFromUseList() {
|
void ValueHandleBase::RemoveFromUseList() {
|
||||||
assert(VP.getPointer() && VP.getPointer()->HasValueHandle &&
|
assert(V && V->HasValueHandle &&
|
||||||
"Pointer doesn't have a use list!");
|
"Pointer doesn't have a use list!");
|
||||||
|
|
||||||
// Unlink this from its 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
|
// 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
|
// ValueHandle watching VP. If so, delete its entry from the ValueHandles
|
||||||
// map.
|
// map.
|
||||||
LLVMContextImpl *pImpl = VP.getPointer()->getContext().pImpl;
|
LLVMContextImpl *pImpl = V->getContext().pImpl;
|
||||||
DenseMap<Value*, ValueHandleBase*> &Handles = pImpl->ValueHandles;
|
DenseMap<Value*, ValueHandleBase*> &Handles = pImpl->ValueHandles;
|
||||||
if (Handles.isPointerIntoBucketsArray(PrevPtr)) {
|
if (Handles.isPointerIntoBucketsArray(PrevPtr)) {
|
||||||
Handles.erase(VP.getPointer());
|
Handles.erase(V);
|
||||||
VP.getPointer()->HasValueHandle = false;
|
V->HasValueHandle = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue