[llvm-commits] [llvm] r56348 - in /llvm/trunk: include/llvm/Use.h include/llvm/Value.h lib/VMCore/Use.cpp lib/VMCore/Value.cpp lib/VMCore/getValue.cpp

Gabor Greif ggreif at gmail.com
Fri Sep 19 08:03:58 PDT 2008


Author: ggreif
Date: Fri Sep 19 10:03:57 2008
New Revision: 56348

URL: http://llvm.org/viewvc/llvm-project?rev=56348&view=rev
Log:
first shot at removing Use::Val
untested, Use::swap() is definitely not done yet

Added:
    llvm/trunk/lib/VMCore/getValue.cpp
      - copied unchanged from r56283, llvm/branches/ggreif/use-diet/lib/VMCore/getValue.cpp
Modified:
    llvm/trunk/include/llvm/Use.h
    llvm/trunk/include/llvm/Value.h
    llvm/trunk/lib/VMCore/Use.cpp
    llvm/trunk/lib/VMCore/Value.cpp

Modified: llvm/trunk/include/llvm/Use.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Use.h?rev=56348&r1=56347&r2=56348&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Use.h (original)
+++ llvm/trunk/include/llvm/Use.h Fri Sep 19 10:03:57 2008
@@ -66,11 +66,22 @@
 // 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 @@
 
   /// 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 @@
   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 @@
     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 @@
   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 @@
   }
 
   /// 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 @@
     _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 @@
   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;

Modified: llvm/trunk/include/llvm/Value.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Value.h?rev=56348&r1=56347&r2=56348&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Value.h (original)
+++ llvm/trunk/include/llvm/Value.h Fri Sep 19 10:03:57 2008
@@ -138,7 +138,7 @@
   typedef value_use_iterator<User>       use_iterator;
   typedef value_use_iterator<const User> use_const_iterator;
 
-  bool               use_empty() const { return UseList == 0; }
+  bool               use_empty() const { return Use::isNil(UseList); }
   use_iterator       use_begin()       { return use_iterator(UseList); }
   use_const_iterator use_begin() const { return use_const_iterator(UseList); }
   use_iterator       use_end()         { return use_iterator(0);   }
@@ -245,14 +245,16 @@
 }
   
 void Use::init(Value *V, User *) {
-  Val = V;
+  Val1 = V;
   if (V) V->addUse(*this);
+  else Next = nilUse(0);
 }
 
 void Use::set(Value *V) {
-  if (Val) removeFromList();
-  Val = V;
+  if (Val1) removeFromList();
+  Val1 = V;
   if (V) V->addUse(*this);
+  else Next = nilUse(0);
 }
 
 

Modified: llvm/trunk/lib/VMCore/Use.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Use.cpp?rev=56348&r1=56347&r2=56348&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/Use.cpp (original)
+++ llvm/trunk/lib/VMCore/Use.cpp Fri Sep 19 10:03:57 2008
@@ -20,8 +20,31 @@
 //===----------------------------------------------------------------------===//
 
 void Use::swap(Use &RHS) {
-  Value *V1(Val);
-  Value *V2(RHS.Val);
+  ptrdiff_t dist((char*)&RHS - (char*)this);
+
+  if (dist) {
+    Use *valid1(stripTag<tagMaskN>(Next));
+    Use *valid2(stripTag<tagMaskN>(RHS.Next));
+    if (valid1 && valid2) {
+      bool real1(fullStopTagN != extractTag<NextPtrTag, tagMaskN>(Next));
+      bool real2(fullStopTagN != extractTag<NextPtrTag, tagMaskN>(RHS.Next));
+      (char*&)*stripTag<tagMask>(Prev) += dist;
+      (char*&)*stripTag<tagMask>(RHS.Prev) -= dist;
+      if (real1)
+	(char*&)valid1->Next += dist;
+      if (real2)
+        (char*&)valid2->Next -= dist;
+
+    }
+
+    // swap the members
+    std::swap(Next, RHS.Next);
+    Use** Prev1 = transferTag<tagMask>(Prev, stripTag<tagMask>(RHS.Prev));
+    RHS.Prev = transferTag<tagMask>(RHS.Prev, stripTag<tagMask>(Prev));
+    Prev = Prev1;
+  }
+  /*  Value *V1(Val1);
+  Value *V2(RHS.Val1);
   if (V1 != V2) {
     if (V1) {
       removeFromList();
@@ -29,19 +52,20 @@
 
     if (V2) {
       RHS.removeFromList();
-      Val = V2;
+      Val1 = V2;
       V2->addUse(*this);
     } else {
-      Val = 0;
+      Val1 = 0;
     }
 
     if (V1) {
-      RHS.Val = V1;
+      RHS.Val1 = V1;
       V1->addUse(RHS);
     } else {
-      RHS.Val = 0;
+      RHS.Val1 = 0;
     }
   }
+  */
 }
 
 //===----------------------------------------------------------------------===//
@@ -52,7 +76,7 @@
   const Use *Current = this;
 
   while (true) {
-    unsigned Tag = extractTag<PrevPtrTag, fullStopTag>((Current++)->Prev);
+    unsigned Tag = extractTag<PrevPtrTag, tagMask>((Current++)->Prev);
     switch (Tag) {
       case zeroDigitTag:
       case oneDigitTag:
@@ -62,7 +86,7 @@
         ++Current;
         ptrdiff_t Offset = 1;
         while (true) {
-          unsigned Tag = extractTag<PrevPtrTag, fullStopTag>(Current->Prev);
+          unsigned Tag = extractTag<PrevPtrTag, tagMask>(Current->Prev);
           switch (Tag) {
             case zeroDigitTag:
             case oneDigitTag:
@@ -89,7 +113,8 @@
   ptrdiff_t Count = Done;
   while (Start != Stop) {
     --Stop;
-    Stop->Val = 0;
+    Stop->Val1 = 0;
+    Stop->Next = nilUse(0);
     if (!Count) {
       Stop->Prev = reinterpret_cast<Use**>(Done == 0 ? fullStopTag : stopTag);
       ++Done;

Modified: llvm/trunk/lib/VMCore/Value.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Value.cpp?rev=56348&r1=56347&r2=56348&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/Value.cpp (original)
+++ llvm/trunk/lib/VMCore/Value.cpp Fri Sep 19 10:03:57 2008
@@ -34,7 +34,7 @@
 
 Value::Value(const Type *ty, unsigned scid)
   : SubclassID(scid), SubclassData(0), VTy(checkType(ty)),
-    UseList(0), Name(0) {
+    UseList(Use::nilUse(this)), Name(0) {
   if (isa<CallInst>(this) || isa<InvokeInst>(this))
     assert((VTy->isFirstClassType() || VTy == Type::VoidTy ||
             isa<OpaqueType>(ty) || VTy->getTypeID() == Type::StructTyID) &&
@@ -298,7 +298,7 @@
 //
 void Value::uncheckedReplaceAllUsesWith(Value *New) {
   while (!use_empty()) {
-    Use &U = *UseList;
+    Use &U = *use_begin().U;
     // Must handle Constants specially, we cannot call replaceUsesOfWith on a
     // constant because they are uniqued.
     if (Constant *C = dyn_cast<Constant>(U.getUser())) {





More information about the llvm-commits mailing list