forked from OSchip/llvm-project
Teach ValueHandleBase to treat DenseMap's special Empty and Tombstone
values the same way it treats null pointers. This is needed to allow CallbackVH to be used as a key in a DenseMap. llvm-svn: 77695
This commit is contained in:
parent
9d7de2a155
commit
0542060b8a
|
@ -14,6 +14,7 @@
|
||||||
#ifndef LLVM_SUPPORT_VALUEHANDLE_H
|
#ifndef LLVM_SUPPORT_VALUEHANDLE_H
|
||||||
#define LLVM_SUPPORT_VALUEHANDLE_H
|
#define LLVM_SUPPORT_VALUEHANDLE_H
|
||||||
|
|
||||||
|
#include "llvm/ADT/DenseMapInfo.h"
|
||||||
#include "llvm/ADT/PointerIntPair.h"
|
#include "llvm/ADT/PointerIntPair.h"
|
||||||
#include "llvm/Value.h"
|
#include "llvm/Value.h"
|
||||||
|
|
||||||
|
@ -57,32 +58,32 @@ public:
|
||||||
: PrevPair(0, Kind), Next(0), VP(0) {}
|
: PrevPair(0, Kind), Next(0), VP(0) {}
|
||||||
ValueHandleBase(HandleBaseKind Kind, Value *V)
|
ValueHandleBase(HandleBaseKind Kind, Value *V)
|
||||||
: PrevPair(0, Kind), Next(0), VP(V) {
|
: PrevPair(0, Kind), Next(0), VP(V) {
|
||||||
if (V)
|
if (isValid(VP))
|
||||||
AddToUseList();
|
AddToUseList();
|
||||||
}
|
}
|
||||||
ValueHandleBase(HandleBaseKind Kind, const ValueHandleBase &RHS)
|
ValueHandleBase(HandleBaseKind Kind, const ValueHandleBase &RHS)
|
||||||
: PrevPair(0, Kind), Next(0), VP(RHS.VP) {
|
: PrevPair(0, Kind), Next(0), VP(RHS.VP) {
|
||||||
if (VP)
|
if (isValid(VP))
|
||||||
AddToExistingUseList(RHS.getPrevPtr());
|
AddToExistingUseList(RHS.getPrevPtr());
|
||||||
}
|
}
|
||||||
~ValueHandleBase() {
|
~ValueHandleBase() {
|
||||||
if (VP)
|
if (isValid(VP))
|
||||||
RemoveFromUseList();
|
RemoveFromUseList();
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *operator=(Value *RHS) {
|
Value *operator=(Value *RHS) {
|
||||||
if (VP == RHS) return RHS;
|
if (VP == RHS) return RHS;
|
||||||
if (VP) RemoveFromUseList();
|
if (isValid(VP)) RemoveFromUseList();
|
||||||
VP = RHS;
|
VP = RHS;
|
||||||
if (VP) AddToUseList();
|
if (isValid(VP)) AddToUseList();
|
||||||
return RHS;
|
return RHS;
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *operator=(const ValueHandleBase &RHS) {
|
Value *operator=(const ValueHandleBase &RHS) {
|
||||||
if (VP == RHS.VP) return RHS.VP;
|
if (VP == RHS.VP) return RHS.VP;
|
||||||
if (VP) RemoveFromUseList();
|
if (isValid(VP)) RemoveFromUseList();
|
||||||
VP = RHS.VP;
|
VP = RHS.VP;
|
||||||
if (VP) AddToExistingUseList(RHS.getPrevPtr());
|
if (isValid(VP)) AddToExistingUseList(RHS.getPrevPtr());
|
||||||
return VP;
|
return VP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,6 +93,12 @@ public:
|
||||||
protected:
|
protected:
|
||||||
Value *getValPtr() const { return VP; }
|
Value *getValPtr() const { return VP; }
|
||||||
private:
|
private:
|
||||||
|
static bool isValid(Value *V) {
|
||||||
|
return V &&
|
||||||
|
V != DenseMapInfo<Value *>::getEmptyKey() &&
|
||||||
|
V != DenseMapInfo<Value *>::getTombstoneKey();
|
||||||
|
}
|
||||||
|
|
||||||
// Callbacks made from Value.
|
// Callbacks made from Value.
|
||||||
static void ValueIsDeleted(Value *V);
|
static void ValueIsDeleted(Value *V);
|
||||||
static void ValueIsRAUWd(Value *Old, Value *New);
|
static void ValueIsRAUWd(Value *Old, Value *New);
|
||||||
|
|
Loading…
Reference in New Issue