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); Use(const Use &U);
/// Destructor - Only for zap() /// Destructor - Only for zap()
inline ~Use() { ~Use() {
if (Val) removeFromList(); 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 enum PrevPtrTag { zeroDigitTag = noTag
, oneDigitTag = tagOne , oneDigitTag = tagOne
, stopTag = tagTwo , stopTag = tagTwo
, fullStopTag = tagThree }; , fullStopTag = tagThree };
/// Constructor
Use(PrevPtrTag tag) : Val(0) {
Prev.setInt(tag);
}
public: public:
/// Normally Use will just implicitly convert to a Value* that it holds. /// Normally Use will just implicitly convert to a Value* that it holds.
operator Value*() const { return Val; } operator Value*() const { return Val; }
@ -114,7 +116,7 @@ public:
private: private:
const Use* getImpliedUser() const; const Use* getImpliedUser() const;
static Use *initTags(Use *Start, Use *Stop, ptrdiff_t Done = 0); static Use *initTags(Use *Start, Use *Stop);
Value *Val; Value *Val;
Use *Next; Use *Next;

View File

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

View File

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

View File

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