X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FVMCore%2FUse.cpp;h=2258b8d985ae066ff85471a292b0aec48678a563;hb=6c3541d5597033bdb2f26f5ade811b482c32a39a;hp=b25415a3d14e0e20e55d65c0e72287c665cf3bd9;hpb=ae5a20a9177650525b40ed88c8326a398e6caa8a;p=oota-llvm.git diff --git a/lib/VMCore/Use.cpp b/lib/VMCore/Use.cpp index b25415a3d14..2258b8d985a 100644 --- a/lib/VMCore/Use.cpp +++ b/lib/VMCore/Use.cpp @@ -11,7 +11,7 @@ // //===----------------------------------------------------------------------===// -#include "llvm/User.h" +#include "llvm/Value.h" namespace llvm { @@ -85,19 +85,31 @@ 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; + static const PrevPtrTag tags[20] = { fullStopTag, oneDigitTag, stopTag, + oneDigitTag, oneDigitTag, stopTag, + zeroDigitTag, oneDigitTag, oneDigitTag, + stopTag, zeroDigitTag, oneDigitTag, + zeroDigitTag, oneDigitTag, stopTag, + oneDigitTag, oneDigitTag, oneDigitTag, + oneDigitTag, stopTag + }; + new(Stop) Use(tags[Done++]); + } + ptrdiff_t Count = Done; while (Start != Stop) { --Stop; - Stop->Val = 0; if (!Count) { - Stop->Prev.setFromOpaqueValue(reinterpret_cast(Done == 0 - ? fullStopTag - : stopTag)); + new(Stop) Use(stopTag); ++Done; Count = Done; } else { - Stop->Prev.setFromOpaqueValue(reinterpret_cast(Count & 1)); + new(Stop) Use(PrevPtrTag(Count & 1)); Count >>= 1; ++Done; } @@ -111,123 +123,24 @@ 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); - } } -//===----------------------------------------------------------------------===// -// AugmentedUse layout struct -//===----------------------------------------------------------------------===// - -struct AugmentedUse : Use { - PointerIntPair ref; - AugmentedUse(); // not implemented -}; - - //===----------------------------------------------------------------------===// // Use getUser Implementation //===----------------------------------------------------------------------===// User *Use::getUser() const { const Use *End = getImpliedUser(); - const PointerIntPair& ref( - static_cast(End - 1)->ref); + const PointerIntPair& + ref(static_cast(End - 1)->ref); User *She = ref.getPointer(); return ref.getInt() ? She : (User*)End; } -//===----------------------------------------------------------------------===// -// User allocHungoffUses Implementation -//===----------------------------------------------------------------------===// - -Use *User::allocHungoffUses(unsigned N) const { - Use *Begin = static_cast(::operator new(sizeof(Use) * N - + sizeof(AugmentedUse) - - sizeof(Use))); - Use *End = Begin + N; - PointerIntPair& ref(static_cast(End[-1]).ref); - ref.setPointer(const_cast(this)); - ref.setInt(tagOne); - return Use::initTags(Begin, End); -} - -//===----------------------------------------------------------------------===// -// User operator new Implementations -//===----------------------------------------------------------------------===// - -void *User::operator new(size_t s, unsigned Us) { - void *Storage = ::operator new(s + sizeof(Use) * Us); - Use *Start = static_cast(Storage); - Use *End = Start + Us; - User *Obj = reinterpret_cast(End); - Obj->OperandList = Start; - Obj->NumOperands = Us; - Use::initTags(Start, End); - return Obj; -} - -/// Prefixed allocation - just before the first Use, allocate a NULL pointer. -/// The destructor can detect its presence and readjust the OperandList -/// for deletition. -/// -void *User::operator new(size_t s, unsigned Us, bool Prefix) { - // currently prefixed allocation only admissible for - // unconditional branch instructions - if (!Prefix) - return operator new(s, Us); - - assert(Us == 1 && "Other than one Use allocated?"); - typedef PointerIntPair TaggedPrefix; - void *Raw = ::operator new(s + sizeof(TaggedPrefix) + sizeof(Use) * Us); - TaggedPrefix *Pre = static_cast(Raw); - Pre->setFromOpaqueValue(0); - void *Storage = Pre + 1; // skip over prefix - Use *Start = static_cast(Storage); - Use *End = Start + Us; - User *Obj = reinterpret_cast(End); - Obj->OperandList = Start; - Obj->NumOperands = Us; - Use::initTags(Start, End); - return Obj; -} - -//===----------------------------------------------------------------------===// -// User operator delete Implementation -//===----------------------------------------------------------------------===// - -void User::operator delete(void *Usr) { - User *Start = static_cast(Usr); - Use *Storage = static_cast(Usr) - Start->NumOperands; - // - // look for a variadic User - if (Storage == Start->OperandList) { - ::operator delete(Storage); - return; - } - // - // check for the flag whether the destructor has detected a prefixed - // allocation, in which case we remove the flag and delete starting - // at OperandList - if (reinterpret_cast(Start->OperandList) & 1) { - ::operator delete(reinterpret_cast(Start->OperandList) - 1); - return; - } - // - // in all other cases just delete the nullary User (covers hung-off - // uses also - ::operator delete(Usr); -} - } // End llvm namespace