X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FIR%2FUse.cpp;h=cae845d99fe58fe3a943b4d38566f3339c7af805;hb=4474471834be491ad1c6de19da0fa82bf667e70a;hp=1d343e8030944cbc5e5e78f78be773ecf2fd1e62;hpb=914d4a76fe0dd7aafb9f06f5af2dcf09c0b87ee7;p=oota-llvm.git diff --git a/lib/IR/Use.cpp b/lib/IR/Use.cpp index 1d343e80309..cae845d99fe 100644 --- a/lib/IR/Use.cpp +++ b/lib/IR/Use.cpp @@ -6,111 +6,76 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -// -// This file implements the algorithm for finding the User of a Use. -// -//===----------------------------------------------------------------------===// +#include "llvm/IR/Use.h" +#include "llvm/IR/User.h" #include "llvm/IR/Value.h" #include namespace llvm { -//===----------------------------------------------------------------------===// -// Use swap Implementation -//===----------------------------------------------------------------------===// - void Use::swap(Use &RHS) { - Value *V1(Val); - Value *V2(RHS.Val); - if (V1 != V2) { - if (V1) { - removeFromList(); - } - - if (V2) { - RHS.removeFromList(); - Val = V2; - V2->addUse(*this); - } else { - Val = 0; - } + if (Val == RHS.Val) + return; + + if (Val) + removeFromList(); + + Value *OldVal = Val; + if (RHS.Val) { + RHS.removeFromList(); + Val = RHS.Val; + Val->addUse(*this); + } else { + Val = nullptr; + } - if (V1) { - RHS.Val = V1; - V1->addUse(RHS); - } else { - RHS.Val = 0; - } + if (OldVal) { + RHS.Val = OldVal; + RHS.Val->addUse(RHS); + } else { + RHS.Val = nullptr; } } -//===----------------------------------------------------------------------===// -// Use getImpliedUser Implementation -//===----------------------------------------------------------------------===// - -const Use *Use::getImpliedUser() const { - const Use *Current = this; - - while (true) { - unsigned Tag = (Current++)->Prev.getInt(); - switch (Tag) { - case zeroDigitTag: - case oneDigitTag: - continue; - - case stopTag: { - ++Current; - ptrdiff_t Offset = 1; - while (true) { - unsigned Tag = Current->Prev.getInt(); - switch (Tag) { - case zeroDigitTag: - case oneDigitTag: - ++Current; - Offset = (Offset << 1) + Tag; - continue; - default: - return Current + Offset; - } - } - } - - case fullStopTag: - return Current; - } - } +User *Use::getUser() const { + const Use *End = getImpliedUser(); + const UserRef *ref = reinterpret_cast(End); + return ref->getInt() ? ref->getPointer() + : reinterpret_cast(const_cast(End)); } -//===----------------------------------------------------------------------===// -// Use initTags Implementation -//===----------------------------------------------------------------------===// +unsigned Use::getOperandNo() const { + return this - getUser()->op_begin(); +} -Use *Use::initTags(Use * const Start, Use *Stop) { +// Sets up the waymarking algorithm's tags for a series of Uses. See the +// algorithm details here: +// +// http://www.llvm.org/docs/ProgrammersManual.html#the-waymarking-algorithm +// +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++]); + 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; if (!Count) { - new(Stop) Use(stopTag); + new (Stop) Use(stopTag); ++Done; Count = Done; } else { - new(Stop) Use(PrevPtrTag(Count & 1)); + new (Stop) Use(PrevPtrTag(Count & 1)); Count >>= 1; ++Done; } @@ -119,10 +84,6 @@ Use *Use::initTags(Use * const Start, Use *Stop) { return Start; } -//===----------------------------------------------------------------------===// -// Use zap Implementation -//===----------------------------------------------------------------------===// - void Use::zap(Use *Start, const Use *Stop, bool del) { while (Start != Stop) (--Stop)->~Use(); @@ -130,16 +91,37 @@ void Use::zap(Use *Start, const Use *Stop, bool del) { ::operator delete(Start); } -//===----------------------------------------------------------------------===// -// Use getUser Implementation -//===----------------------------------------------------------------------===// +const Use *Use::getImpliedUser() const { + const Use *Current = this; -User *Use::getUser() const { - const Use *End = getImpliedUser(); - const UserRef *ref = reinterpret_cast(End); - return ref->getInt() - ? ref->getPointer() - : reinterpret_cast(const_cast(End)); + while (true) { + unsigned Tag = (Current++)->Prev.getInt(); + switch (Tag) { + case zeroDigitTag: + case oneDigitTag: + continue; + + case stopTag: { + ++Current; + ptrdiff_t Offset = 1; + while (true) { + unsigned Tag = Current->Prev.getInt(); + switch (Tag) { + case zeroDigitTag: + case oneDigitTag: + ++Current; + Offset = (Offset << 1) + Tag; + continue; + default: + return Current + Offset; + } + } + } + + case fullStopTag: + return Current; + } + } } } // End llvm namespace