[llvm-commits] [llvm] r61694 - in /llvm/trunk: docs/ProgrammersManual.html include/llvm/Use.h lib/VMCore/Use.cpp
Gabor Greif
ggreif at gmail.com
Mon Jan 5 08:05:36 PST 2009
Author: ggreif
Date: Mon Jan 5 10:05:32 2009
New Revision: 61694
URL: http://llvm.org/viewvc/llvm-project?rev=61694&view=rev
Log:
Get rid of the tagging functions and use PointerIntPair.
This means that we have to include an additional header.
This patch should be functionally equivalent. I cannot outrule any performance
degradation, though I do not expect any.
Modified:
llvm/trunk/docs/ProgrammersManual.html
llvm/trunk/include/llvm/Use.h
llvm/trunk/lib/VMCore/Use.cpp
Modified: llvm/trunk/docs/ProgrammersManual.html
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/ProgrammersManual.html?rev=61694&r1=61693&r2=61694&view=diff
==============================================================================
--- llvm/trunk/docs/ProgrammersManual.html (original)
+++ llvm/trunk/docs/ProgrammersManual.html Mon Jan 5 10:05:32 2009
@@ -2234,7 +2234,7 @@
<div class="doc_text">
<p>The <tt><a href="http://llvm.org/doxygen/classllvm_1_1User.html">
-User</a></tt> class provides a base for expressing the ownership of <tt>User</tt>
+User</a></tt> class provides a basis for expressing the ownership of <tt>User</tt>
towards other <tt><a href="http://llvm.org/doxygen/classllvm_1_1Value.html">
Value</a></tt>s. The <tt><a href="http://llvm.org/doxygen/classllvm_1_1Use.html">
Use</a></tt> helper class is employed to do the bookkeeping and to facilitate <i>O(1)</i>
@@ -2242,7 +2242,7 @@
<!-- ______________________________________________________________________ -->
<div class="doc_subsubsection">
- <a name="PATypeHolder">Interaction and relationship between <tt>User</tt> and <tt>Use</tt> objects</a>
+ <a name="Use2User">Interaction and relationship between <tt>User</tt> and <tt>Use</tt> objects</a>
</div>
<div class="doc_text">
@@ -2303,7 +2303,7 @@
<!-- ______________________________________________________________________ -->
<div class="doc_subsubsection">
- <a name="PATypeHolder">The waymarking algorithm</a>
+ <a name="Waymarking">The waymarking algorithm</a>
</div>
<div class="doc_text">
@@ -2344,7 +2344,7 @@
<!-- ______________________________________________________________________ -->
<div class="doc_subsubsection">
- <a name="PATypeHolder">Reference implementation</a>
+ <a name="ReferenceImpl">Reference implementation</a>
</div>
<div class="doc_text">
@@ -2434,7 +2434,7 @@
<!-- ______________________________________________________________________ -->
<div class="doc_subsubsection">
- <a name="PATypeHolder">Tagging considerations</a>
+ <a name="Tagging">Tagging considerations</a>
</div>
<p>
@@ -2446,7 +2446,8 @@
For layout b) instead of the <tt>User</tt> we find a pointer (<tt>User*</tt> with LSBit set).
Following this pointer brings us to the <tt>User</tt>. A portable trick ensures
that the first bytes of <tt>User</tt> (if interpreted as a pointer) never has
-the LSBit set.</p>
+the LSBit set. (Portability is relying on the fact that all known compilers place the
+<tt>vptr</tt> in the first word of the instances.)</p>
</div>
@@ -2491,7 +2492,7 @@
<!-- _______________________________________________________________________ -->
<div class="doc_subsubsection">
- <a name="m_Value">Important Public Methods</a>
+ <a name="m_Type">Important Public Methods</a>
</div>
<div class="doc_text">
@@ -2513,7 +2514,7 @@
<!-- _______________________________________________________________________ -->
<div class="doc_subsubsection">
- <a name="m_Value">Important Derived Types</a>
+ <a name="derivedtypes">Important Derived Types</a>
</div>
<div class="doc_text">
<dl>
Modified: llvm/trunk/include/llvm/Use.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Use.h?rev=61694&r1=61693&r2=61694&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Use.h (original)
+++ llvm/trunk/include/llvm/Use.h Mon Jan 5 10:05:32 2009
@@ -18,6 +18,7 @@
#include "llvm/Support/Casting.h"
#include "llvm/ADT/iterator.h"
+#include "llvm/ADT/PointerIntPair.h"
namespace llvm {
@@ -25,46 +26,9 @@
class User;
-//===----------------------------------------------------------------------===//
-// Generic Tagging Functions
-//===----------------------------------------------------------------------===//
-
-// We adhere to the following convention: The type of a tagged pointer
-// to T is T volatile*. This means that functions that superpose a tag
-// on a pointer will be supplied a T* (or T const*) and will return a
-// tagged one: T volatile*. Untagging functions do it the other way
-// 'round. While this scheme does not prevent dereferencing of tagged
-// pointers, proper type annotations do catch most inappropriate uses.
-
/// 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 volatile 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 volatile 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 volatile 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 volatile T *transferTag(const volatile T *From, const T *To) {
- return reinterpret_cast<T*>((ptrdiff_t(From) & MASK) | ptrdiff_t(To));
-}
-
//===----------------------------------------------------------------------===//
// Use Class
@@ -133,10 +97,11 @@
static Use *initTags(Use *Start, Use *Stop, ptrdiff_t Done = 0);
Value *Val;
- Use *Next, *volatile*Prev;
+ Use *Next;
+ PointerIntPair<Use**, 2, PrevPtrTag> Prev;
void setPrev(Use **NewPrev) {
- Prev = transferTag<fullStopTag>(Prev, NewPrev);
+ Prev.setPointer(NewPrev);
}
void addToList(Use **List) {
Next = *List;
@@ -145,7 +110,7 @@
*List = this;
}
void removeFromList() {
- Use **StrippedPrev = stripTag<fullStopTag>(Prev);
+ Use **StrippedPrev = Prev.getPointer();
*StrippedPrev = Next;
if (Next) Next->setPrev(StrippedPrev);
}
Modified: llvm/trunk/lib/VMCore/Use.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Use.cpp?rev=61694&r1=61693&r2=61694&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Use.cpp (original)
+++ llvm/trunk/lib/VMCore/Use.cpp Mon Jan 5 10:05:32 2009
@@ -52,7 +52,7 @@
const Use *Current = this;
while (true) {
- unsigned Tag = extractTag<PrevPtrTag, fullStopTag>((Current++)->Prev);
+ unsigned Tag = (Current++)->Prev.getInt();
switch (Tag) {
case zeroDigitTag:
case oneDigitTag:
@@ -62,7 +62,7 @@
++Current;
ptrdiff_t Offset = 1;
while (true) {
- unsigned Tag = extractTag<PrevPtrTag, fullStopTag>(Current->Prev);
+ unsigned Tag = Current->Prev.getInt();
switch (Tag) {
case zeroDigitTag:
case oneDigitTag:
@@ -91,11 +91,11 @@
--Stop;
Stop->Val = 0;
if (!Count) {
- Stop->Prev = reinterpret_cast<Use**>(Done == 0 ? fullStopTag : stopTag);
+ Stop->Prev.setFromOpaqueValue(reinterpret_cast<Use**>(Done == 0 ? fullStopTag : stopTag));
++Done;
Count = Done;
} else {
- Stop->Prev = reinterpret_cast<Use**>(Count & 1);
+ Stop->Prev.setFromOpaqueValue(reinterpret_cast<Use**>(Count & 1));
Count >>= 1;
++Done;
}
@@ -127,7 +127,7 @@
//===----------------------------------------------------------------------===//
struct AugmentedUse : Use {
- volatile User *ref;
+ PointerIntPair<User*, 1, Tag> ref;
AugmentedUse(); // not implemented
};
@@ -138,10 +138,11 @@
User *Use::getUser() const {
const Use *End = getImpliedUser();
- volatile User *She = static_cast<const AugmentedUse*>(End - 1)->ref;
- return extractTag<Tag, tagOne>(She)
- ? llvm::stripTag<tagOne>(She)
- : reinterpret_cast<User*>(const_cast<Use*>(End));
+ PointerIntPair<User*, 1, Tag>& ref(static_cast<const AugmentedUse*>(End - 1)->ref);
+ User *She = ref.getPointer();
+ return ref.getInt()
+ ? She
+ : (User*)End;
}
//===----------------------------------------------------------------------===//
@@ -153,7 +154,9 @@
+ sizeof(AugmentedUse)
- sizeof(Use)));
Use *End = Begin + N;
- static_cast<AugmentedUse&>(End[-1]).ref = addTag(this, tagOne);
+ PointerIntPair<User*, 1, Tag>& ref(static_cast<AugmentedUse&>(End[-1]).ref);
+ ref.setPointer(const_cast<User*>(this));
+ ref.setInt(tagOne);
return Use::initTags(Begin, End);
}
More information about the llvm-commits
mailing list