[llvm-commits] [llvm] r46188 - in /llvm/trunk: include/llvm/ADT/APInt.h lib/Support/APInt.cpp

Ted Kremenek kremenek at apple.com
Fri Jan 18 20:23:34 PST 2008


Author: kremenek
Date: Fri Jan 18 22:23:33 2008
New Revision: 46188

URL: http://llvm.org/viewvc/llvm-project?rev=46188&view=rev
Log:
Added FoldingSet style 'profiling' support for APInt.

Modified:
    llvm/trunk/include/llvm/ADT/APInt.h
    llvm/trunk/lib/Support/APInt.cpp

Modified: llvm/trunk/include/llvm/ADT/APInt.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/APInt.h?rev=46188&r1=46187&r2=46188&view=diff

==============================================================================
--- llvm/trunk/include/llvm/ADT/APInt.h (original)
+++ llvm/trunk/include/llvm/ADT/APInt.h Fri Jan 18 22:23:33 2008
@@ -24,6 +24,7 @@
 namespace llvm {
   class Serializer;
   class Deserializer;
+  class FoldingSetNodeID;
   
   /* An unsigned host type used as a single part of a multi-part
      bignum.  */
@@ -210,6 +211,10 @@
   ///  for object deserialization (pair this with the static method Read).
   explicit APInt() : BitWidth(1) {}
   
+  /// Profile - Used to insert APInt objects, or objects that contain APInt 
+  ///  objects, into FoldingSets.
+  void Profile(FoldingSetNodeID& ID) const;
+  
   /// @brief Used by the Bitcode serializer to emit APInts to Bitcode.
   void Emit(Serializer& S) const;
   

Modified: llvm/trunk/lib/Support/APInt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/APInt.cpp?rev=46188&r1=46187&r2=46188&view=diff

==============================================================================
--- llvm/trunk/lib/Support/APInt.cpp (original)
+++ llvm/trunk/lib/Support/APInt.cpp Fri Jan 18 22:23:33 2008
@@ -14,6 +14,7 @@
 
 #define DEBUG_TYPE "apint"
 #include "llvm/ADT/APInt.h"
+#include "llvm/ADT/FoldingSet.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/MathExtras.h"
 #include <math.h>
@@ -24,7 +25,6 @@
 
 using namespace llvm;
 
-
 /// This enumeration just provides for internal constants used in this
 /// translation unit. 
 enum {
@@ -165,6 +165,18 @@
   return clearUnusedBits();
 }
 
+/// Profile - This method 'profiles' an APInt for use with FoldingSet.
+void APInt::Profile(FoldingSetNodeID& ID) const {
+  if (isSingleWord()) {
+    ID.AddInteger(VAL);
+    return;
+  }
+
+  uint32_t NumWords = getNumWords();
+  for (unsigned i = 0; i < NumWords; ++i)
+    ID.AddInteger(pVal[i]);
+}
+
 /// add_1 - This function adds a single "digit" integer, y, to the multiple 
 /// "digit" integer array,  x[]. x[] is modified to reflect the addition and
 /// 1 is returned if there is a carry out, otherwise 0 is returned.





More information about the llvm-commits mailing list