Simplify the construction and destruction of Uses. Simplify

User::dropHungOffUses().

llvm-svn: 123580
This commit is contained in:
Jay Foad 2011-01-16 15:30:52 +00:00
parent ec3b10fc56
commit bbb91f2b22
4 changed files with 26 additions and 35 deletions

View File

@ -67,18 +67,20 @@ private:
Use(const Use &U);
/// Destructor - Only for zap()
inline ~Use() {
~Use() {
if (Val) removeFromList();
}
/// Default ctor - This leaves the Use completely uninitialized. The only
/// thing that is valid to do with this use is to call the "init" method.
inline Use() {}
enum PrevPtrTag { zeroDigitTag = noTag
, oneDigitTag = tagOne
, stopTag = tagTwo
, fullStopTag = tagThree };
/// Constructor
Use(PrevPtrTag tag) : Val(0) {
Prev.setInt(tag);
}
public:
/// Normally Use will just implicitly convert to a Value* that it holds.
operator Value*() const { return Val; }
@ -114,7 +116,7 @@ public:
private:
const Use* getImpliedUser() const;
static Use *initTags(Use *Start, Use *Stop, ptrdiff_t Done = 0);
static Use *initTags(Use *Start, Use *Stop);
Value *Val;
Use *Next;

View File

@ -50,12 +50,10 @@ protected:
User(const Type *ty, unsigned vty, Use *OpList, unsigned NumOps)
: Value(ty, vty), OperandList(OpList), NumOperands(NumOps) {}
Use *allocHungoffUses(unsigned) const;
void dropHungoffUses(Use *U) {
if (OperandList == U) {
OperandList = 0;
NumOperands = 0;
}
Use::zap(U, U->getImpliedUser(), true);
void dropHungoffUses() {
Use::zap(OperandList, OperandList + NumOperands, true);
OperandList = 0;
NumOperands = 0;
}
public:
~User() {

View File

@ -96,8 +96,7 @@ PHINode::PHINode(const PHINode &PN)
}
PHINode::~PHINode() {
if (OperandList)
dropHungoffUses(OperandList);
dropHungoffUses();
}
// removeIncomingValue - Remove an incoming value. This is useful if a
@ -158,7 +157,7 @@ void PHINode::resizeOperands(unsigned NumOps) {
Use *NewOps = allocHungoffUses(NumOps);
std::copy(OldOps, OldOps + e, NewOps);
OperandList = NewOps;
if (OldOps) Use::zap(OldOps, OldOps + e, true);
Use::zap(OldOps, OldOps + e, true);
}
/// hasConstantValue - If the specified PHI node always merges together the same
@ -2982,7 +2981,7 @@ SwitchInst::SwitchInst(const SwitchInst &SI)
}
SwitchInst::~SwitchInst() {
dropHungoffUses(OperandList);
dropHungoffUses();
}
@ -3053,7 +3052,7 @@ void SwitchInst::resizeOperands(unsigned NumOps) {
NewOps[i] = OldOps[i];
}
OperandList = NewOps;
if (OldOps) Use::zap(OldOps, OldOps + e, true);
Use::zap(OldOps, OldOps + e, true);
}
@ -3068,7 +3067,7 @@ void SwitchInst::setSuccessorV(unsigned idx, BasicBlock *B) {
}
//===----------------------------------------------------------------------===//
// SwitchInst Implementation
// IndirectBrInst Implementation
//===----------------------------------------------------------------------===//
void IndirectBrInst::init(Value *Address, unsigned NumDests) {
@ -3108,7 +3107,7 @@ void IndirectBrInst::resizeOperands(unsigned NumOps) {
for (unsigned i = 0; i != e; ++i)
NewOps[i] = OldOps[i];
OperandList = NewOps;
if (OldOps) Use::zap(OldOps, OldOps + e, true);
Use::zap(OldOps, OldOps + e, true);
}
IndirectBrInst::IndirectBrInst(Value *Address, unsigned NumCases,
@ -3136,7 +3135,7 @@ IndirectBrInst::IndirectBrInst(const IndirectBrInst &IBI)
}
IndirectBrInst::~IndirectBrInst() {
dropHungoffUses(OperandList);
dropHungoffUses();
}
/// addDestination - Add a destination.

View File

@ -85,7 +85,8 @@ const Use *Use::getImpliedUser() const {
// Use initTags Implementation
//===----------------------------------------------------------------------===//
Use *Use::initTags(Use * const Start, Use *Stop, ptrdiff_t Done) {
Use *Use::initTags(Use * const Start, Use *Stop) {
ptrdiff_t Done = 0;
while (Done < 20) {
if (Start == Stop--)
return Start;
@ -97,20 +98,18 @@ Use *Use::initTags(Use * const Start, Use *Stop, ptrdiff_t Done) {
oneDigitTag, oneDigitTag, oneDigitTag,
oneDigitTag, stopTag
};
Stop->Prev.setFromOpaqueValue(reinterpret_cast<Use**>(tags[Done++]));
Stop->Val = 0;
new(Stop) Use(tags[Done++]);
}
ptrdiff_t Count = Done;
while (Start != Stop) {
--Stop;
Stop->Val = 0;
if (!Count) {
Stop->Prev.setFromOpaqueValue(reinterpret_cast<Use**>(stopTag));
new(Stop) Use(stopTag);
++Done;
Count = Done;
} else {
Stop->Prev.setFromOpaqueValue(reinterpret_cast<Use**>(Count & 1));
new(Stop) Use(PrevPtrTag(Count & 1));
Count >>= 1;
++Done;
}
@ -124,17 +123,10 @@ Use *Use::initTags(Use * const Start, Use *Stop, ptrdiff_t Done) {
//===----------------------------------------------------------------------===//
void Use::zap(Use *Start, const Use *Stop, bool del) {
if (del) {
while (Start != Stop) {
(--Stop)->~Use();
}
while (Start != Stop)
(--Stop)->~Use();
if (del)
::operator delete(Start);
return;
}
while (Start != Stop) {
(Start++)->set(0);
}
}
//===----------------------------------------------------------------------===//