[llvm-commits] [llvm] r49726 - in /llvm/branches/ggreif/use-diet: include/llvm/Use.h include/llvm/User.h lib/VMCore/Use.cpp
Gabor Greif
ggreif at gmail.com
Tue Apr 15 06:14:38 PDT 2008
Author: ggreif
Date: Tue Apr 15 08:14:38 2008
New Revision: 49726
URL: http://llvm.org/viewvc/llvm-project?rev=49726&view=rev
Log:
* move tagging functions to Use.h
* add extractTag and transferTag
* un-inline User::allocHungoffUses
* prettify overall
Modified:
llvm/branches/ggreif/use-diet/include/llvm/Use.h
llvm/branches/ggreif/use-diet/include/llvm/User.h
llvm/branches/ggreif/use-diet/lib/VMCore/Use.cpp
Modified: llvm/branches/ggreif/use-diet/include/llvm/Use.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/ggreif/use-diet/include/llvm/Use.h?rev=49726&r1=49725&r2=49726&view=diff
==============================================================================
--- llvm/branches/ggreif/use-diet/include/llvm/Use.h (original)
+++ llvm/branches/ggreif/use-diet/include/llvm/Use.h Tue Apr 15 08:14:38 2008
@@ -26,6 +26,40 @@
//===----------------------------------------------------------------------===//
+// Generic Tagging Functions
+//===----------------------------------------------------------------------===//
+
+/// Tag - generic tag type for (at least 32 bit) pointers
+enum Tag { noTag, tagOne, tagTwo, tagThree };
+
+/// addTag - insert tag bits into an (untagged) pointer
+template <typename T, typename TAG>
+inline T *addTag(const T *P, TAG Tag) {
+ return reinterpret_cast<T*>(ptrdiff_t(P) | Tag);
+}
+
+/// stripTag - remove tag bits from a pointer,
+/// making it dereferencable
+template <ptrdiff_t MASK, typename T>
+inline T *stripTag(const T *P) {
+ return reinterpret_cast<T*>(ptrdiff_t(P) & ~MASK);
+}
+
+/// extractTag - extract tag bits from a pointer
+template <typename TAG, TAG MASK, typename T>
+inline TAG extractTag(const T *P) {
+ return TAG(ptrdiff_t(P) & MASK);
+}
+
+/// transferTag - transfer tag bits from a pointer,
+/// to an untagged pointer
+template <ptrdiff_t MASK, typename T>
+inline T *transferTag(const T *From, const T *To) {
+ return reinterpret_cast<T*>((ptrdiff_t(From) & MASK) | ptrdiff_t(To));
+}
+
+
+//===----------------------------------------------------------------------===//
// Use Class
//===----------------------------------------------------------------------===//
@@ -50,8 +84,12 @@
/// 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.
-private:
inline Use() {}
+ enum ValuePtrTag { zeroDigitTag = noTag
+ , oneDigitTag = tagOne
+ , stopTag = tagTwo
+ , fullStopTag = tagThree };
+
public:
@@ -59,7 +97,7 @@
Value *get() const { return stripTag(Val); }
User *getUser() const;
const Use* getImpliedUser() const;
- static void initTags(Use *Start, Use *Stop, ptrdiff_t Done = 0);
+ static Use *initTags(Use *Start, Use *Stop, ptrdiff_t Done = 0);
static void zap(Use *Start, const Use *Stop, bool del = false);
inline void set(Value *Val);
@@ -83,10 +121,10 @@
Value *Val;
static Value *stripTag(Value *V) {
- return reinterpret_cast<Value*>(reinterpret_cast<ptrdiff_t>(V) & ~3UL);
+ return llvm::stripTag<fullStopTag>(V);
}
Value *transferTag(Value *V) {
- return reinterpret_cast<Value*>(reinterpret_cast<ptrdiff_t>(V) | (reinterpret_cast<ptrdiff_t>(Val) & 3UL));
+ return llvm::transferTag<fullStopTag>(Val, V);
}
void addToList(Use **List) {
Next = *List;
Modified: llvm/branches/ggreif/use-diet/include/llvm/User.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/ggreif/use-diet/include/llvm/User.h?rev=49726&r1=49725&r2=49726&view=diff
==============================================================================
--- llvm/branches/ggreif/use-diet/include/llvm/User.h (original)
+++ llvm/branches/ggreif/use-diet/include/llvm/User.h Tue Apr 15 08:14:38 2008
@@ -196,6 +196,7 @@
class User;
+/// OperandTraits<User> - specialization to User
template <>
struct OperandTraits<User> {
static inline Use *op_begin(User*);
@@ -216,9 +217,9 @@
protected:
/// OperandList - This is a pointer to the array of Users for this operand.
/// For nodes of fixed arity (e.g. a binary operator) this array will live
- /// embedded into the derived class. For nodes of variable arity
- /// (e.g. ConstantArrays, CallInst, PHINodes, ReturnInst etc.), this memory
- /// will be dynamically allocated and should be destroyed by the classes'
+ /// prefixed to the derived class. For nodes of resizable variable arity
+ /// (e.g. PHINodes, SwitchInst etc.), this memory will be dynamically
+ /// allocated and should be destroyed by the classes'
/// virtual dtor.
Use *OperandList;
@@ -256,7 +257,7 @@
template <unsigned Idx> const Use &Op() const {
return OperandTraits<User>::op_begin(const_cast<User*>(this))[Idx];
}
- inline Use *allocHungoffUses(unsigned) const;
+ Use *allocHungoffUses(unsigned) const;
void dropHungoffUses(Use *U) {
Use::zap(U, U->getImpliedUser(), true);
}
@@ -320,30 +321,6 @@
return U->getNumOperands();
}
-enum Tag { noTag, tagOne, tagTwo, tagThree };
-
-template <typename T, typename TAG>
-inline T *addTag(const T *P, TAG Tag) {
- return reinterpret_cast<T*>(ptrdiff_t(P) | Tag);
-}
-
-template <typename T, typename TAG, ptrdiff_t MASK>
-inline T *stripTag(const T *P) {
- return reinterpret_cast<T*>(ptrdiff_t(P) & ~MASK);
-}
-
-Use *User::allocHungoffUses(unsigned N) const {
- struct AugmentedUse : Use {
- User *ref;
- AugmentedUse(); // not implemented
- };
- Use *Begin = static_cast<Use*>(::operator new(sizeof(Use) * N + sizeof(AugmentedUse) - sizeof(Use)));
- Use *End = Begin + N;
- static_cast<AugmentedUse&>(End[-1]).ref = addTag(this, tagOne);
- Use::initTags(Begin, End);
- return Begin;
-}
-
template<> struct simplify_type<User::op_iterator> {
typedef Value* SimpleType;
Modified: llvm/branches/ggreif/use-diet/lib/VMCore/Use.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/ggreif/use-diet/lib/VMCore/Use.cpp?rev=49726&r1=49725&r2=49726&view=diff
==============================================================================
--- llvm/branches/ggreif/use-diet/lib/VMCore/Use.cpp (original)
+++ llvm/branches/ggreif/use-diet/lib/VMCore/Use.cpp Tue Apr 15 08:14:38 2008
@@ -12,6 +12,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/Value.h"
+#include "llvm/User.h"
namespace llvm {
@@ -19,15 +20,13 @@
// Use getImpliedUser Implementation
//===----------------------------------------------------------------------===//
-enum ValuePtrTag { zeroDigitTag = 0, oneDigitTag = 1, stopTag = 0x2, fullStopTag = 0x3 };
-
const Use *Use::getImpliedUser() const {
bool StopEncountered = false;
ptrdiff_t Offset = 1;
const Use *Current = this;
while (true) {
- unsigned Tag = unsigned(Current->Val) & 0x3;
+ unsigned Tag = extractTag<ValuePtrTag, fullStopTag>(Current->Val);
switch (Tag)
{
case zeroDigitTag:
@@ -53,7 +52,7 @@
// Use initTags Implementation
//===----------------------------------------------------------------------===//
-void Use::initTags(Use *Start, Use *Stop, ptrdiff_t Done) {
+Use *Use::initTags(Use * const Start, Use *Stop, ptrdiff_t Done) {
ptrdiff_t Count = 0;
while (Start != Stop)
{
@@ -69,6 +68,8 @@
++Done;
}
}
+
+ return Start;
}
//===----------------------------------------------------------------------===//
@@ -85,19 +86,39 @@
}
//===----------------------------------------------------------------------===//
+// AugmentedUse layout struct
+//===----------------------------------------------------------------------===//
+
+struct AugmentedUse : Use {
+ User *ref;
+ AugmentedUse(); // not implemented
+};
+
+
+//===----------------------------------------------------------------------===//
// Use getUser Implementation
//===----------------------------------------------------------------------===//
User *Use::getUser() const {
const Use* End = getImpliedUser();
- User *She = End->U;
- if (ptrdiff_t(She) & 1UL)
- She = (User*)(ptrdiff_t(She) & ~1UL);
- else
- She = (User*)End;
+ User *She = static_cast<const AugmentedUse*>(End - 1)->ref;
+ She = extractTag<Tag, tagOne>(She)
+ ? llvm::stripTag<tagOne>(She)
+ : reinterpret_cast<User*>(const_cast<Use*>(End));
assert((!U || U == She) && "Implicit User differs?");
return She;
}
+//===----------------------------------------------------------------------===//
+// User allocHungoffUses Implementation
+//===----------------------------------------------------------------------===//
+
+Use *User::allocHungoffUses(unsigned N) const {
+ Use *Begin = static_cast<Use*>(::operator new(sizeof(Use) * N + sizeof(AugmentedUse) - sizeof(Use)));
+ Use *End = Begin + N;
+ static_cast<AugmentedUse&>(End[-1]).ref = addTag(this, tagOne);
+ return Use::initTags(Begin, End);
+}
+
} // End llvm namespace
More information about the llvm-commits
mailing list