2008-05-15 12:04:30 +02:00
|
|
|
//===-- Use.cpp - Implement the Use class ---------------------------------===//
|
2008-05-10 10:32:32 +02:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the algorithm for finding the User of a Use.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-01-16 09:10:57 +01:00
|
|
|
#include "llvm/Value.h"
|
2008-05-10 10:32:32 +02:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2008-05-14 00:51:52 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Use swap Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
void Use::swap(Use &RHS) {
|
2008-09-19 17:13:20 +02:00
|
|
|
Value *V1(Val);
|
|
|
|
Value *V2(RHS.Val);
|
2008-05-14 00:51:52 +02:00
|
|
|
if (V1 != V2) {
|
|
|
|
if (V1) {
|
|
|
|
removeFromList();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (V2) {
|
|
|
|
RHS.removeFromList();
|
2008-09-19 17:13:20 +02:00
|
|
|
Val = V2;
|
2008-05-14 00:51:52 +02:00
|
|
|
V2->addUse(*this);
|
|
|
|
} else {
|
2008-09-19 17:13:20 +02:00
|
|
|
Val = 0;
|
2008-05-14 00:51:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (V1) {
|
2008-09-19 17:13:20 +02:00
|
|
|
RHS.Val = V1;
|
2008-05-14 00:51:52 +02:00
|
|
|
V1->addUse(RHS);
|
|
|
|
} else {
|
2008-09-19 17:13:20 +02:00
|
|
|
RHS.Val = 0;
|
2008-05-14 00:51:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-10 10:32:32 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Use getImpliedUser Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
const Use *Use::getImpliedUser() const {
|
|
|
|
const Use *Current = this;
|
|
|
|
|
|
|
|
while (true) {
|
2009-01-05 17:05:32 +01:00
|
|
|
unsigned Tag = (Current++)->Prev.getInt();
|
2008-05-10 10:32:32 +02:00
|
|
|
switch (Tag) {
|
|
|
|
case zeroDigitTag:
|
|
|
|
case oneDigitTag:
|
|
|
|
continue;
|
|
|
|
|
|
|
|
case stopTag: {
|
|
|
|
++Current;
|
|
|
|
ptrdiff_t Offset = 1;
|
|
|
|
while (true) {
|
2009-01-05 17:05:32 +01:00
|
|
|
unsigned Tag = Current->Prev.getInt();
|
2008-05-10 10:32:32 +02:00
|
|
|
switch (Tag) {
|
|
|
|
case zeroDigitTag:
|
|
|
|
case oneDigitTag:
|
|
|
|
++Current;
|
|
|
|
Offset = (Offset << 1) + Tag;
|
|
|
|
continue;
|
|
|
|
default:
|
|
|
|
return Current + Offset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
case fullStopTag:
|
|
|
|
return Current;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Use initTags Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-01-16 16:30:52 +01:00
|
|
|
Use *Use::initTags(Use * const Start, Use *Stop) {
|
|
|
|
ptrdiff_t Done = 0;
|
2010-07-19 16:48:15 +02:00
|
|
|
while (Done < 20) {
|
2010-07-16 22:35:19 +02:00
|
|
|
if (Start == Stop--)
|
|
|
|
return Start;
|
2010-07-19 16:48:15 +02:00
|
|
|
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
|
|
|
|
};
|
2011-01-16 16:30:52 +01:00
|
|
|
new(Stop) Use(tags[Done++]);
|
2010-07-16 22:35:19 +02:00
|
|
|
}
|
|
|
|
|
2008-05-10 10:32:32 +02:00
|
|
|
ptrdiff_t Count = Done;
|
|
|
|
while (Start != Stop) {
|
|
|
|
--Stop;
|
|
|
|
if (!Count) {
|
2011-01-16 16:30:52 +01:00
|
|
|
new(Stop) Use(stopTag);
|
2008-05-10 10:32:32 +02:00
|
|
|
++Done;
|
|
|
|
Count = Done;
|
|
|
|
} else {
|
2011-01-16 16:30:52 +01:00
|
|
|
new(Stop) Use(PrevPtrTag(Count & 1));
|
2008-05-10 10:32:32 +02:00
|
|
|
Count >>= 1;
|
|
|
|
++Done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Start;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Use zap Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
void Use::zap(Use *Start, const Use *Stop, bool del) {
|
2011-01-16 16:30:52 +01:00
|
|
|
while (Start != Stop)
|
|
|
|
(--Stop)->~Use();
|
|
|
|
if (del)
|
2008-05-10 10:32:32 +02:00
|
|
|
::operator delete(Start);
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Use getUser Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
User *Use::getUser() const {
|
|
|
|
const Use *End = getImpliedUser();
|
2011-01-17 16:18:06 +01:00
|
|
|
const PointerIntPair<User*, 1, unsigned>&
|
|
|
|
ref(static_cast<const AugmentedUse*>(End - 1)->ref);
|
2009-01-05 17:05:32 +01:00
|
|
|
User *She = ref.getPointer();
|
|
|
|
return ref.getInt()
|
2009-01-05 17:28:14 +01:00
|
|
|
? She
|
|
|
|
: (User*)End;
|
2008-05-10 10:32:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // End llvm namespace
|