summaryrefslogtreecommitdiffstats
path: root/include/llvm/Use.h
diff options
context:
space:
mode:
authorGabor Greif <ggreif@gmail.com>2008-09-19 15:03:57 +0000
committerGabor Greif <ggreif@gmail.com>2008-09-19 15:03:57 +0000
commit6c2c95d0acd867add034d93d4b909ddd75d61b14 (patch)
treeb167f6bf294bfe2c01fde421dc8ea5a871c3f78e /include/llvm/Use.h
parent210fada2c6bb31198722000e52059e41f6641c3b (diff)
downloadexternal_llvm-6c2c95d0acd867add034d93d4b909ddd75d61b14.zip
external_llvm-6c2c95d0acd867add034d93d4b909ddd75d61b14.tar.gz
external_llvm-6c2c95d0acd867add034d93d4b909ddd75d61b14.tar.bz2
first shot at removing Use::Val
untested, Use::swap() is definitely not done yet git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@56348 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Use.h')
-rw-r--r--include/llvm/Use.h79
1 files changed, 58 insertions, 21 deletions
diff --git a/include/llvm/Use.h b/include/llvm/Use.h
index 891eaf8..b116e8c 100644
--- a/include/llvm/Use.h
+++ b/include/llvm/Use.h
@@ -66,11 +66,22 @@ inline T *transferTag(const T *From, const T *To) {
// Use is here to make keeping the "use" list of a Value up-to-date really easy.
//
class Use {
-private:
+ class UseWaymark;
+ friend class UseWaymark;
+ Value *getValue() const;
+ /// nilUse - returns a 'token' that marks the end of the def/use chain
+ static Use *nilUse(const Value *V) {
+ return addTag((Use*)V, fullStopTagN);
+ }
+ static bool isNil(Use *U) { return extractTag<NextPtrTag, tagMaskN>(U) == fullStopTagN; }
+ void showWaymarks() const;
+ static bool isStop(Use *U) {
+ return isStopTag(extractTag<NextPtrTag, tagMaskN>(U));
+ }
+public:
/// init - specify Value and User
/// @deprecated in 2.4, will be removed soon
inline void init(Value *V, User *U);
-public:
/// swap - provide a fast substitute to std::swap<Use>
/// that also works with less standard-compliant compilers
void swap(Use &RHS);
@@ -81,7 +92,7 @@ private:
/// Destructor - Only for zap()
inline ~Use() {
- if (Val) removeFromList();
+ if (Val1) removeFromList();
}
/// Default ctor - This leaves the Use completely uninitialized. The only thing
@@ -91,11 +102,22 @@ private:
enum PrevPtrTag { zeroDigitTag = noTag
, oneDigitTag = tagOne
, stopTag = tagTwo
- , fullStopTag = tagThree };
-
+ , fullStopTag = tagThree
+ , tagMask = tagThree };
+
+ enum NextPtrTag { zeroDigitTagN = tagTwo
+ , oneDigitTagN = tagOne
+ , stopTagN = noTag
+ , fullStopTagN = tagThree
+ , tagMaskN = tagThree };
+
+ static bool isStopTag(NextPtrTag T) {
+ bool P[] = { true, false, false, true };
+ return P[T];
+ }
public:
- operator Value*() const { return Val; }
- Value *get() const { return Val; }
+ operator Value*() const { return get(); }
+ inline Value *get() const;
User *getUser() const;
const Use* getImpliedUser() const;
static Use *initTags(Use *Start, Use *Stop, ptrdiff_t Done = 0);
@@ -108,31 +130,38 @@ public:
return RHS;
}
const Use &operator=(const Use &RHS) {
- set(RHS.Val);
+ set(RHS.Val1);
return *this;
}
- Value *operator->() { return Val; }
- const Value *operator->() const { return Val; }
+ Value *operator->() { return get(); }
+ const Value *operator->() const { return get(); }
- Use *getNext() const { return Next; }
+ Use *getNext() const { return extractTag<NextPtrTag, tagMaskN>(Next) == fullStopTagN
+ ? 0
+ : stripTag<tagMaskN>(Next); }
private:
- Value *Val;
+ Value *Val1;
Use *Next, **Prev;
void setPrev(Use **NewPrev) {
- Prev = transferTag<fullStopTag>(Prev, NewPrev);
+ Prev = transferTag<tagMask>(Prev, NewPrev);
}
void addToList(Use **List) {
Next = *List;
- if (Next) Next->setPrev(&Next);
+ Use *StrippedNext(getNext());
+ if (StrippedNext) StrippedNext->setPrev(&Next);
setPrev(List);
*List = this;
}
void removeFromList() {
- Use **StrippedPrev = stripTag<fullStopTag>(Prev);
+ // __builtin_prefetch(Next);
+ Use **StrippedPrev = stripTag<tagMask>(Prev);
+ Use *StrippedNext(getNext());
+ if (isStop(Next))
+ assert((isStop(*StrippedPrev) || (StrippedNext ? isStop(StrippedNext->Next) : true)) && "joining digits?");
*StrippedPrev = Next;
- if (Next) Next->setPrev(StrippedPrev);
+ if (StrippedNext) StrippedNext->setPrev(StrippedPrev);
}
friend class Value;
@@ -161,7 +190,10 @@ class value_use_iterator : public forward_iterator<UserTy*, ptrdiff_t> {
typedef value_use_iterator<UserTy> _Self;
Use *U;
- explicit value_use_iterator(Use *u) : U(u) {}
+ explicit value_use_iterator(Use *u) : U(extractTag<Use::NextPtrTag, Use::tagMaskN>(u)
+ == Use::fullStopTagN
+ ? 0
+ : stripTag<Use::tagMaskN>(u)) {}
friend class Value;
public:
typedef typename super::reference reference;
@@ -178,11 +210,11 @@ public:
}
/// atEnd - return true if this iterator is equal to use_end() on the value.
- bool atEnd() const { return U == 0; }
+ bool atEnd() const { return !U; }
// Iterator traversal: forward iteration only
_Self &operator++() { // Preincrement
- assert(U && "Cannot increment end iterator!");
+ assert(!atEnd() && "Cannot increment end iterator!");
U = U->getNext();
return *this;
}
@@ -190,9 +222,9 @@ public:
_Self tmp = *this; ++*this; return tmp;
}
- // Retrieve a pointer to the current User.
+ // Retrieve a reference to the current User
UserTy *operator*() const {
- assert(U && "Cannot dereference end iterator!");
+ assert(!atEnd() && "Cannot dereference end iterator!");
return U->getUser();
}
@@ -206,6 +238,11 @@ public:
unsigned getOperandNo() const;
};
+Value *Use::get() const {
+ return fullStopTagN == extractTag<NextPtrTag, tagMaskN>(Next)
+ ? reinterpret_cast<Value*>(stripTag<tagMaskN>(Next))
+ : (Val1 == getValue() ? Val1 : 0); // should crash if not equal!
+}
template<> struct simplify_type<value_use_iterator<User> > {
typedef User* SimpleType;