[llvm-branch-commits] [llvm-branch] r202038 - make template args boolean for getImpliedUser/initTags; enable algorithm selection

Gabor Greif ggreif at gmail.com
Mon Feb 24 06:59:11 PST 2014


Author: ggreif
Date: Mon Feb 24 08:59:11 2014
New Revision: 202038

URL: http://llvm.org/viewvc/llvm-project?rev=202038&view=rev
Log:
make template args boolean for getImpliedUser/initTags; enable algorithm selection

Modified:
    llvm/branches/ggreif/waymark-64-new/include/llvm/IR/Use.h
    llvm/branches/ggreif/waymark-64-new/lib/IR/Use.cpp

Modified: llvm/branches/ggreif/waymark-64-new/include/llvm/IR/Use.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/ggreif/waymark-64-new/include/llvm/IR/Use.h?rev=202038&r1=202037&r2=202038&view=diff
==============================================================================
--- llvm/branches/ggreif/waymark-64-new/include/llvm/IR/Use.h (original)
+++ llvm/branches/ggreif/waymark-64-new/include/llvm/IR/Use.h Mon Feb 24 08:59:11 2014
@@ -59,19 +59,21 @@ template <> struct PrevPointerIntPair<fa
                   , oneDigitTag
                   , stopTag
                   , fullStopTag };
+  enum { threeBitTags = false };
   typedef PrevPtrTag Tag_t;
   typedef PointerIntPair<Use**, 2, PrevPtrTag> Pair;
 };
 
 template <> struct PrevPointerIntPair<true> {
-  enum PrevPtrTag3 { fullStopTag3,
-		     stopTag3,
-		     skipStopTag3,
-		     skip2StopTag3,
-		     zeroZeroDigitTag3,
-		     zeroOneDigitTag3,
-		     oneZeroDigitTag3,
-		     oneOneDigitTag3 };
+  enum PrevPtrTag3 { fullStopTag3
+                   , stopTag3
+                   , skipStopTag3
+                   , skip2StopTag3
+                   , zeroZeroDigitTag3
+                   , zeroOneDigitTag3
+                   , oneZeroDigitTag3
+                   , oneOneDigitTag3 };
+  enum { threeBitTags = true };
   typedef PrevPtrTag3 Tag_t;
   typedef PointerIntPair<Use**, 3, PrevPtrTag3> Pair;
 };
@@ -105,6 +107,8 @@ private:
     Prev.setInt(tag);
   }
 
+  Use(PrevPointerIntPair<!threeBitTags>::Tag_t) {}
+
 public:
   /// Normally Use will just implicitly convert to a Value* that it holds.
   operator Value*() const { return Val; }
@@ -144,9 +148,9 @@ public:
 
 private:
   inline const Use *getImpliedUser() const;
-  template <size_t>
+  template <bool>
   const Use *getImpliedUser() const;
-  template <size_t>
+  template <bool>
   static Use *initTags(Use * const Start, Use *Stop);
 
   Value *Val;
@@ -174,17 +178,21 @@ private:
 
 // Out-of-class specializations/definitions.
 template<>
-Use *Use::initTags<8>(Use * const Start, Use *Stop);
+Use *Use::initTags<false>(Use * const Start, Use *Stop);
+template<>
+Use *Use::initTags<true>(Use * const Start, Use *Stop);
 
 inline Use * Use::initTags(Use *Start, Use *Stop) {
-  return initTags<sizeof(Use**)>(Start, Stop);
+  return initTags<threeBitTags>(Start, Stop);
 }
 
 template<>
-const Use *Use::getImpliedUser<8>() const;
+const Use *Use::getImpliedUser<false>() const;
+template<>
+const Use *Use::getImpliedUser<true>() const;
 
 inline const Use *Use::getImpliedUser() const {
-  return getImpliedUser<sizeof(Use**)>();
+  return getImpliedUser<threeBitTags>();
 }
 
 

Modified: llvm/branches/ggreif/waymark-64-new/lib/IR/Use.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/ggreif/waymark-64-new/lib/IR/Use.cpp?rev=202038&r1=202037&r2=202038&view=diff
==============================================================================
--- llvm/branches/ggreif/waymark-64-new/lib/IR/Use.cpp (original)
+++ llvm/branches/ggreif/waymark-64-new/lib/IR/Use.cpp Mon Feb 24 08:59:11 2014
@@ -49,24 +49,24 @@ void Use::swap(Use &RHS) {
 //                         Use getImpliedUser Implementation
 //===----------------------------------------------------------------------===//
 
-/* NEED SFINAE tricks: http://stackoverflow.com/questions/14603163/how-to-use-sfinae-for-selecting-constructors
 template<>
-const Use *Use::getImpliedUser<4>() const {
+const Use *Use::getImpliedUser<false>() const {
+  typedef PrevPointerIntPair<false> T;
   const Use *Current = this;
 
   while (true) {
-    switch (unsigned Tag = (Current++)->Prev.getInt()) {
-      case zeroDigitTag:
-      case oneDigitTag:
+    switch ((Current++)->Prev.getInt()) {
+      case T::zeroDigitTag:
+      case T::oneDigitTag:
         continue;
 
-      case stopTag: {
+      case T::stopTag: {
         ++Current;
         ptrdiff_t Offset = 1;
         while (true) {
           switch (unsigned Tag = Current->Prev.getInt()) {
-            case zeroDigitTag:
-            case oneDigitTag:
+            case T::zeroDigitTag:
+            case T::oneDigitTag:
               ++Current;
               Offset = (Offset << 1) + Tag;
               continue;
@@ -76,15 +76,17 @@ const Use *Use::getImpliedUser<4>() cons
         }
       }
 
-      case fullStopTag:
+      case T::fullStopTag:
         return Current;
+
+      default:; // absorb Tag3 values to suppress warnings
     }
   }
 }
-*/
+
 
 template<>
-const Use *Use::getImpliedUser<8>() const {
+const Use *Use::getImpliedUser<true>() const {
   const Use *Current = this;
 
   while (true) {
@@ -119,14 +121,14 @@ const Use *Use::getImpliedUser<8>() cons
 //                         Use initTags Implementation
 //===----------------------------------------------------------------------===//
 
-/*
+
 template<>
-Use *Use::initTags<4>(Use * const Start, Use *Stop) {
+Use *Use::initTags<false>(Use * const Start, Use *Stop) {
   ptrdiff_t Done = 0;
   while (Done < 32) {
     if (Start == Stop--)
       return Start;
-#   define TAG_AT(N, TAG) (uintptr_t(TAG ## Tag) << ((N) * 2))
+#   define TAG_AT(N, TAG) (uintptr_t(PrevPointerIntPair<false>::TAG ## Tag) << ((N) * 2))
     static const uintptr_t tags =
       TAG_AT(0, fullStop) | TAG_AT(1, oneDigit) | TAG_AT(2, stop) |
       TAG_AT(3, oneDigit) | TAG_AT(4, oneDigit) | TAG_AT(5, stop) |
@@ -140,18 +142,18 @@ Use *Use::initTags<4>(Use * const Start,
       TAG_AT(26, zeroDigit) | TAG_AT(27, oneDigit) | TAG_AT(28, zeroDigit) |
       TAG_AT(29, oneDigit) | TAG_AT(30, oneDigit) | TAG_AT(31, stop);
 #   undef TAG_AT
-    new(Stop) Use(PrevPtrTag((tags >> Done++ * 2) & 0x3));
+    new(Stop) Use(PrevPointerIntPair<false>::Tag_t((tags >> Done++ * 2) & 0x3));
   }
 
   ptrdiff_t Count = Done;
   while (Start != Stop) {
     --Stop;
     if (!Count) {
-      new(Stop) Use(stopTag);
+      new(Stop) Use(PrevPointerIntPair<false>::stopTag);
       ++Done;
       Count = Done;
     } else {
-      new(Stop) Use(PrevPtrTag(Count & 1));
+      new(Stop) Use(PrevPointerIntPair<false>::PrevPtrTag(Count & 1));
       Count >>= 1;
       ++Done;
     }
@@ -159,10 +161,10 @@ Use *Use::initTags<4>(Use * const Start,
 
   return Start;
 }
-*/
+
 
 template<>
-Use *Use::initTags<8>(Use * const Start, Use *Stop) {
+Use *Use::initTags<true>(Use * const Start, Use *Stop) {
   ptrdiff_t Done = 0;
   while (Done < 17) {
     if (Start == Stop--)





More information about the llvm-branch-commits mailing list