[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h

2007-02-20 Thread Reid Spencer


Changes in directory llvm/include/llvm/ADT:

APInt.h updated: 1.14 -> 1.15
---
Log message:

Add an internal convenience method for division that urem and udiv use.


---
Diffs of the changes:  (+5 -0)

 APInt.h |5 +
 1 files changed, 5 insertions(+)


Index: llvm/include/llvm/ADT/APInt.h
diff -u llvm/include/llvm/ADT/APInt.h:1.14 llvm/include/llvm/ADT/APInt.h:1.15
--- llvm/include/llvm/ADT/APInt.h:1.14  Sun Feb 18 21:18:22 2007
+++ llvm/include/llvm/ADT/APInt.h   Tue Feb 20 02:43:42 2007
@@ -128,6 +128,11 @@
   void fromString(uint32_t numBits, const char *StrStart, uint32_t slen, 
   uint8_t radix);
 
+  /// @brief An internal division function for dividing APInts.
+  static void divide(const APInt LHS, uint32_t lhsWords, 
+ const APInt &RHS, uint32_t rhsWords,
+ APInt *Quotient, APInt *Remainder);
+
 public:
   /// @brief Create a new APInt of numBits bit-width, and initialized as val.
   APInt(uint32_t numBits, uint64_t val);



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Support/APInt.cpp

2007-02-20 Thread Reid Spencer


Changes in directory llvm/lib/Support:

APInt.cpp updated: 1.21 -> 1.22
---
Log message:

First version that can process arith.cpp test case up to 1024 bits:
1. Ensure pVal is set to 0 in each constructor.
2. Fix roundToDouble to make correct calculations and not read beyond the
   end of allocated memory.
3. Implement Knuth's "classical algorithm" for division from scratch and
   eliminate buffer overflows and uninitialized mememory reads. Document
   it properly too.
4. Implement a wrapper function for KnuthDiv which handles the 64-bit to
   32-bit conversion and back. It also implement short division for the
   n == 1 case that Knuth's algorithm can't handle.
5. Simplify the logic of udiv and urem a little, make them exit early, and
   have them use the "divide" wrapper function to perform the division 
   or remainder operation.
6. Move the toString function to the end of the file, closer to where
   the division functions are located.

Note: division is still broken for some > 64 bit values, but at least it
  doesn't crash any more.


---
Diffs of the changes:  (+424 -172)

 APInt.cpp |  596 --
 1 files changed, 424 insertions(+), 172 deletions(-)


Index: llvm/lib/Support/APInt.cpp
diff -u llvm/lib/Support/APInt.cpp:1.21 llvm/lib/Support/APInt.cpp:1.22
--- llvm/lib/Support/APInt.cpp:1.21 Sun Feb 18 16:29:05 2007
+++ llvm/lib/Support/APInt.cpp  Tue Feb 20 02:51:03 2007
@@ -36,7 +36,7 @@
 }
 
 APInt::APInt(uint32_t numBits, uint64_t val)
-  : BitWidth(numBits) {
+  : BitWidth(numBits), pVal(0) {
   assert(BitWidth >= IntegerType::MIN_INT_BITS && "bitwidth too small");
   assert(BitWidth <= IntegerType::MAX_INT_BITS && "bitwidth too large");
   if (isSingleWord()) 
@@ -48,7 +48,7 @@
 }
 
 APInt::APInt(uint32_t numBits, uint32_t numWords, uint64_t bigVal[])
-  : BitWidth(numBits) {
+  : BitWidth(numBits), pVal(0)  {
   assert(BitWidth >= IntegerType::MIN_INT_BITS && "bitwidth too small");
   assert(BitWidth <= IntegerType::MAX_INT_BITS && "bitwidth too large");
   assert(bigVal && "Null pointer detected!");
@@ -71,20 +71,22 @@
 /// @brief Create a new APInt by translating the char array represented
 /// integer value.
 APInt::APInt(uint32_t numbits, const char StrStart[], uint32_t slen, 
- uint8_t radix) {
+ uint8_t radix) 
+  : BitWidth(numbits), pVal(0) {
   fromString(numbits, StrStart, slen, radix);
 }
 
 /// @brief Create a new APInt by translating the string represented
 /// integer value.
-APInt::APInt(uint32_t numbits, const std::string& Val, uint8_t radix) {
+APInt::APInt(uint32_t numbits, const std::string& Val, uint8_t radix)
+  : BitWidth(numbits), pVal(0) {
   assert(!Val.empty() && "String empty?");
   fromString(numbits, Val.c_str(), Val.size(), radix);
 }
 
 /// @brief Copy constructor
 APInt::APInt(const APInt& APIVal)
-  : BitWidth(APIVal.BitWidth) {
+  : BitWidth(APIVal.BitWidth), pVal(0) {
   if (isSingleWord()) 
 VAL = APIVal.VAL;
   else {
@@ -94,7 +96,8 @@
 }
 
 APInt::~APInt() {
-  if (!isSingleWord() && pVal) delete[] pVal;
+  if (!isSingleWord() && pVal) 
+delete[] pVal;
 }
 
 /// @brief Copy assignment operator. Create a new object from the given
@@ -641,80 +644,6 @@
   return *this;
 }
 
-/// to_string - This function translates the APInt into a string.
-std::string APInt::toString(uint8_t radix, bool wantSigned) const {
-  assert((radix == 10 || radix == 8 || radix == 16 || radix == 2) &&
- "Radix should be 2, 8, 10, or 16!");
-  static const char *digits[] = { 
-"0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F" 
-  };
-  std::string result;
-  uint32_t bits_used = getActiveBits();
-  if (isSingleWord()) {
-char buf[65];
-const char *format = (radix == 10 ? (wantSigned ? "%lld" : "%llu") :
-   (radix == 16 ? "%llX" : (radix == 8 ? "%llo" : 0)));
-if (format) {
-  if (wantSigned) {
-int64_t sextVal = (int64_t(VAL) << (APINT_BITS_PER_WORD-BitWidth)) >> 
-   (APINT_BITS_PER_WORD-BitWidth);
-sprintf(buf, format, sextVal);
-  } else 
-sprintf(buf, format, VAL);
-} else {
-  memset(buf, 0, 65);
-  uint64_t v = VAL;
-  while (bits_used) {
-uint32_t bit = v & 1;
-bits_used--;
-buf[bits_used] = digits[bit][0];
-v >>=1;
-  }
-}
-result = buf;
-return result;
-  }
-
-  if (radix != 10) {
-uint64_t mask = radix - 1;
-uint32_t shift = (radix == 16 ? 4 : radix  == 8 ? 3 : 1);
-uint32_t nibbles = APINT_BITS_PER_WORD / shift;
-for (uint32_t i = 0; i < getNumWords(); ++i) {
-  uint64_t value = pVal[i];
-  for (uint32_t j = 0; j < nibbles; ++j) {
-result.insert(0, digits[ value & mask ]);
-value >>= shift;
-  }
-}
-return result;
-  }
-
-  APInt tmp(*this);
-  APInt divisor(tmp.getBitWidth(), 10);
-  APInt zero(tmp.getBitWidth(), 0);
-  size_t insert_at = 0;
-  if (wantSigned && tmp[

[llvm-commits] [see] CVS: llvm/lib/Target/X86/X86TargetAsmInfo.cpp

2007-02-20 Thread Andrew Lenharth


Changes in directory llvm/lib/Target/X86:

X86TargetAsmInfo.cpp updated: 1.7 -> 1.7.4.1
---
Log message:

Backport fix to [see]

---
Diffs of the changes:  (+1 -1)

 X86TargetAsmInfo.cpp |2 +-
 1 files changed, 1 insertion(+), 1 deletion(-)


Index: llvm/lib/Target/X86/X86TargetAsmInfo.cpp
diff -u llvm/lib/Target/X86/X86TargetAsmInfo.cpp:1.7 
llvm/lib/Target/X86/X86TargetAsmInfo.cpp:1.7.4.1
--- llvm/lib/Target/X86/X86TargetAsmInfo.cpp:1.7Tue Oct 31 02:31:24 2006
+++ llvm/lib/Target/X86/X86TargetAsmInfo.cppTue Feb 20 12:19:58 2007
@@ -69,7 +69,7 @@
 // bool HasDotLoc; // Defaults to false.
 // HasDotFile - True if target asm supports .file directives.
 // bool HasDotFile; // Defaults to false.
-PrivateGlobalPrefix = ".";  // Prefix for private global symbols
+PrivateGlobalPrefix = ".L";  // Prefix for private global symbols
 DwarfRequiresFrameSection = false;
 DwarfAbbrevSection =  "\t.section\t.debug_abbrev,\"\",@progbits";
 DwarfInfoSection ="\t.section\t.debug_info,\"\",@progbits";



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] [see] CVS: llvm/lib/Target/CBackend/Writer.cpp

2007-02-20 Thread Andrew Lenharth


Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.280 -> 1.280.4.1
---
Log message:

section support for CBE, may want to port this to head

---
Diffs of the changes:  (+2 -0)

 Writer.cpp |2 ++
 1 files changed, 2 insertions(+)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.280 
llvm/lib/Target/CBackend/Writer.cpp:1.280.4.1
--- llvm/lib/Target/CBackend/Writer.cpp:1.280   Sun Nov  5 13:26:37 2006
+++ llvm/lib/Target/CBackend/Writer.cpp Tue Feb 20 12:21:25 2007
@@ -1273,6 +1273,8 @@
   Out << " __attribute__((common))";
 else if (I->hasWeakLinkage())
   Out << " __ATTRIBUTE_WEAK__";
+if (I->hasSection())
+  Out << " __attribute__ ((__section__ (\"" << I->getSection() << 
"\")))";
 Out << ";\n";
   }
   }



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Support/APInt.cpp

2007-02-20 Thread Reid Spencer


Changes in directory llvm/lib/Support:

APInt.cpp updated: 1.22 -> 1.23
---
Log message:

Use INFINITY macro from math.h instead of constructing hex floating point
constants (avoids warnings).


---
Diffs of the changes:  (+3 -2)

 APInt.cpp |5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)


Index: llvm/lib/Support/APInt.cpp
diff -u llvm/lib/Support/APInt.cpp:1.22 llvm/lib/Support/APInt.cpp:1.23
--- llvm/lib/Support/APInt.cpp:1.22 Tue Feb 20 02:51:03 2007
+++ llvm/lib/Support/APInt.cpp  Tue Feb 20 12:29:12 2007
@@ -17,6 +17,7 @@
 #include "llvm/Support/MathExtras.h"
 #include 
 #include 
+#include 
 using namespace llvm;
 
 // A utility function for allocating memory, checking for allocation failures,
@@ -837,9 +838,9 @@
   // Return infinity for exponent overflow
   if (exp > 1023) {
 if (!isSigned || !isNeg)
-  return double(0x0.0p2047L); // positive infinity
+  return double(INFINITY); // positive infinity
 else 
-  return double(-0x0.0p2047L); // negative infinity
+  return double(-INFINITY); // negative infinity
   }
   exp += 1023; // Increment for 1023 bias
 



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


Re: [llvm-commits] CVS: llvm/lib/Support/APInt.cpp

2007-02-20 Thread Evan Cheng
Hi Reid,

This breaks the build for me.

$ make ENABLE_OPTIMIZED=1 -j2
make[1]: Nothing to be done for `all'.
llvm[1]: Compiling Annotation.cpp for Release build
llvm[1]: Compiling APInt.cpp for Release build
APInt.cpp:841: error: floating constant exceeds range of 'float'
APInt.cpp:843: error: floating constant exceeds range of 'float'

Evan

On Feb 20, 2007, at 10:29 AM, Reid Spencer wrote:

>
>
> Changes in directory llvm/lib/Support:
>
> APInt.cpp updated: 1.22 -> 1.23
> ---
> Log message:
>
> Use INFINITY macro from math.h instead of constructing hex floating  
> point
> constants (avoids warnings).
>
>
> ---
> Diffs of the changes:  (+3 -2)
>
>  APInt.cpp |5 +++--
>  1 files changed, 3 insertions(+), 2 deletions(-)
>
>
> Index: llvm/lib/Support/APInt.cpp
> diff -u llvm/lib/Support/APInt.cpp:1.22 llvm/lib/Support/APInt.cpp: 
> 1.23
> --- llvm/lib/Support/APInt.cpp:1.22   Tue Feb 20 02:51:03 2007
> +++ llvm/lib/Support/APInt.cppTue Feb 20 12:29:12 2007
> @@ -17,6 +17,7 @@
>  #include "llvm/Support/MathExtras.h"
>  #include 
>  #include 
> +#include 
>  using namespace llvm;
>
>  // A utility function for allocating memory, checking for  
> allocation failures,
> @@ -837,9 +838,9 @@
>// Return infinity for exponent overflow
>if (exp > 1023) {
>  if (!isSigned || !isNeg)
> -  return double(0x0.0p2047L); // positive infinity
> +  return double(INFINITY); // positive infinity
>  else
> -  return double(-0x0.0p2047L); // negative infinity
> +  return double(-INFINITY); // negative infinity
>}
>exp += 1023; // Increment for 1023 bias
>
>
>
>
> ___
> llvm-commits mailing list
> llvm-commits@cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits

___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


Re: [llvm-commits] CVS: llvm/lib/Support/APInt.cpp

2007-02-20 Thread Chris Lattner
On Feb 20, 2007, at 11:13 AM, Evan Cheng wrote:
> Hi Reid,
> This breaks the build for me.
>
> $ make ENABLE_OPTIMIZED=1 -j2
> make[1]: Nothing to be done for `all'.
> llvm[1]: Compiling Annotation.cpp for Release build
> llvm[1]: Compiling APInt.cpp for Release build
> APInt.cpp:841: error: floating constant exceeds range of 'float'
> APInt.cpp:843: error: floating constant exceeds range of 'float'

Okay, how about just using something like (1e300 * 1e300), which will  
constant fold to inf?

-Chris

> Evan
>
> On Feb 20, 2007, at 10:29 AM, Reid Spencer wrote:
>
>>
>>
>> Changes in directory llvm/lib/Support:
>>
>> APInt.cpp updated: 1.22 -> 1.23
>> ---
>> Log message:
>>
>> Use INFINITY macro from math.h instead of constructing hex floating
>> point
>> constants (avoids warnings).
>>
>>
>> ---
>> Diffs of the changes:  (+3 -2)
>>
>>  APInt.cpp |5 +++--
>>  1 files changed, 3 insertions(+), 2 deletions(-)
>>
>>
>> Index: llvm/lib/Support/APInt.cpp
>> diff -u llvm/lib/Support/APInt.cpp:1.22 llvm/lib/Support/APInt.cpp:
>> 1.23
>> --- llvm/lib/Support/APInt.cpp:1.22  Tue Feb 20 02:51:03 2007
>> +++ llvm/lib/Support/APInt.cpp   Tue Feb 20 12:29:12 2007
>> @@ -17,6 +17,7 @@
>>  #include "llvm/Support/MathExtras.h"
>>  #include 
>>  #include 
>> +#include 
>>  using namespace llvm;
>>
>>  // A utility function for allocating memory, checking for
>> allocation failures,
>> @@ -837,9 +838,9 @@
>>// Return infinity for exponent overflow
>>if (exp > 1023) {
>>  if (!isSigned || !isNeg)
>> -  return double(0x0.0p2047L); // positive infinity
>> +  return double(INFINITY); // positive infinity
>>  else
>> -  return double(-0x0.0p2047L); // negative infinity
>> +  return double(-INFINITY); // negative infinity
>>}
>>exp += 1023; // Increment for 1023 bias
>>
>>
>>
>>
>> ___
>> llvm-commits mailing list
>> llvm-commits@cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
> ___
> llvm-commits mailing list
> llvm-commits@cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits

___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm-test/SingleSource/UnitTests/Integer/APInt/arith.cpp

2007-02-20 Thread Reid Spencer


Changes in directory llvm-test/SingleSource/UnitTests/Integer/APInt:

arith.cpp updated: 1.10 -> 1.11
---
Log message:

Consolidate code, expand testing to more values.


---
Diffs of the changes:  (+55 -18)

 arith.cpp |   73 ++
 1 files changed, 55 insertions(+), 18 deletions(-)


Index: llvm-test/SingleSource/UnitTests/Integer/APInt/arith.cpp
diff -u llvm-test/SingleSource/UnitTests/Integer/APInt/arith.cpp:1.10 
llvm-test/SingleSource/UnitTests/Integer/APInt/arith.cpp:1.11
--- llvm-test/SingleSource/UnitTests/Integer/APInt/arith.cpp:1.10   Sun Feb 
18 16:29:58 2007
+++ llvm-test/SingleSource/UnitTests/Integer/APInt/arith.cppTue Feb 20 
14:39:34 2007
@@ -26,6 +26,16 @@
 printf("\n");
 }
 
+APInt randomAPInt(unsigned bits) {
+  APInt val(bits, 0u);
+  for (unsigned i = 0; i < bits; ++i) {
+unsigned bit = rand() % 2;
+val = val.shl(1);
+val |= APInt(bits, bit);
+  }
+  return val;
+}
+
 void test_interface(const APInt &val) {
   printf("INTERFACE TEST: val = "); print(val);
   unsigned bitwidth = val.getBitWidth();
@@ -104,8 +114,8 @@
 }
 
 void test_binops(const APInt &v1, const APInt &v2) {
-  printf("BINARY OPERATORS TEST: vl = "); print(v1,false,false);
-  printf(", v2 = "); print(v2);
+  printf("BINARY OPERATORS TEST: \n  vl: "); print(v1,false,false);
+  printf("\n  v2: "); print(v2);
   APInt result(v1);
   result &= v2;
   printf("v1 &= v2: "); print(result);
@@ -157,7 +167,7 @@
 printf("lshr(v1,%d) = ", shiftAmt); print(result);
 result = shl(v1,shiftAmt);
 printf("shl(v1,%d) = ", shiftAmt); print(result);
-if (v2 == 0)
+if (v2 == APInt(v2.getBitWidth(), 0))
   printf("sdiv/udiv/srem/urem not tested, v2 == 0\n");
 else {
   result = sdiv(v1,v2);
@@ -174,28 +184,55 @@
 
 void test_multiple() {
   srand(0);
-  for (unsigned bits = 1; bits <= 1024; ++bits) {
-APInt v1(bits, 0u);
-APInt v2(bits, 0u);
-for (unsigned i = 0; i < bits; ++i) {
-  unsigned bit = rand() % 2;
-  v1 = v1.shl(1);
-  v1 |= APInt(bits, bit);
+  for (unsigned bits = 1; bits <= 256; ++bits) {
+printf("\nTEST CASE: %d BITS\n\n", bits);
+APInt zero(bits,0);
+APInt one(bits,1);
+if (bits == 1) {
+  test_interface(zero);
+  test_interface(one);
+  test_unops(zero);
+  test_unops(one);
+  test_binops(zero,one);
+  test_binops(one,zero);
+  continue;
+}
+APInt two(bits,1);
+APInt three(bits,1);
+APInt min = APInt::getMinValue(bits, true);
+APInt max = APInt::getMaxValue(bits, true);
+APInt mid = APIntOps::lshr(max, bits/2);
+APInt r1 = randomAPInt(bits);
+APInt r2 = randomAPInt(bits);
+APInt *list[9];
+list[0] = &zero;
+list[1] = &one;
+list[2] = &two;
+list[3] = &three;
+list[4] = &min;
+list[5] = &r1;
+list[6] = ∣
+list[7] = &r2;
+list[8] = &max;
+for (unsigned i = 0; i < 9; ++i) {
+  test_interface(*(list[i]));
+  test_unops(*(list[i]));
 }
-for (unsigned i = 0; i < bits; ++i) {
-  unsigned bit = rand() % 2;
-  v2 = v2.shl(1);
-  v2 |= APInt(bits, bit);
+for (unsigned i = 0; i < 9; ++i) {
+  for (unsigned j = 0; j < 9; ++j) {
+test_binops(*(list[i]), *(list[j]));
+  }
 }
-printf("\nTEST CASE: %d bits\n\n", bits);
-test_interface(v1);
-test_unops(v2);
-test_binops(v1,v2);
   }
 }
 
 int main()
 {
+  APInt X(48, 100);
+  APInt Y(48, 10);
+  APInt Q(1,0);
+  APInt R(1,0);
+  APInt::divide(X, 1, Y, 1, &Q, &R);
   test_multiple();
   return 0;
 }



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Support/APInt.cpp

2007-02-20 Thread Reid Spencer


Changes in directory llvm/lib/Support:

APInt.cpp updated: 1.23 -> 1.24
---
Log message:

Clean up variable names in operator*.
Attempt #3 for getting a portable INFINITY value.


---
Diffs of the changes:  (+8 -8)

 APInt.cpp |   16 
 1 files changed, 8 insertions(+), 8 deletions(-)


Index: llvm/lib/Support/APInt.cpp
diff -u llvm/lib/Support/APInt.cpp:1.23 llvm/lib/Support/APInt.cpp:1.24
--- llvm/lib/Support/APInt.cpp:1.23 Tue Feb 20 12:29:12 2007
+++ llvm/lib/Support/APInt.cpp  Tue Feb 20 14:42:10 2007
@@ -17,7 +17,6 @@
 #include "llvm/Support/MathExtras.h"
 #include 
 #include 
-#include 
 using namespace llvm;
 
 // A utility function for allocating memory, checking for allocation failures,
@@ -331,7 +330,8 @@
 /// given APInt& RHS and assigns the result to this APInt.
 APInt& APInt::operator*=(const APInt& RHS) {
   assert(BitWidth == RHS.BitWidth && "Bit widths must be the same");
-  if (isSingleWord()) VAL *= RHS.isSingleWord() ? RHS.VAL : RHS.pVal[0];
+  if (isSingleWord()) 
+VAL *= RHS.VAL;
   else {
 // one-based first non-zero bit position.
 uint32_t first = getActiveBits();
@@ -456,10 +456,10 @@
 /// RHS.
 APInt APInt::operator*(const APInt& RHS) const {
   assert(BitWidth == RHS.BitWidth && "Bit widths must be the same");
-  APInt API(RHS);
-  API *= *this;
-  API.clearUnusedBits();
-  return API;
+  APInt Result(*this);
+  Result *= RHS;
+  Result.clearUnusedBits();
+  return Result;
 }
 
 /// @brief Addition operator. Adds this APInt by the given APInt& RHS.
@@ -838,9 +838,9 @@
   // Return infinity for exponent overflow
   if (exp > 1023) {
 if (!isSigned || !isNeg)
-  return double(INFINITY); // positive infinity
+  return double(1.0E300 * 1.0E300); // positive infinity
 else 
-  return double(-INFINITY); // negative infinity
+  return double(-1.0E300 * 1.0E300); // negative infinity
   }
   exp += 1023; // Increment for 1023 bias
 



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm-test/SingleSource/UnitTests/Integer/APInt/gptest.cpp

2007-02-20 Thread Reid Spencer


Changes in directory llvm-test/SingleSource/UnitTests/Integer/APInt:

gptest.cpp added (r1.1)
---
Log message:

A test program to test APInt against the results produced by pari/gp. If
there's no output other than the bit size banners, everything is fine. If
outputs vary from pari/gp, they are printed. Program requires "gp" to be
in the user's path.


---
Diffs of the changes:  (+380 -0)

 gptest.cpp |  380 +
 1 files changed, 380 insertions(+)


Index: llvm-test/SingleSource/UnitTests/Integer/APInt/gptest.cpp
diff -c /dev/null llvm-test/SingleSource/UnitTests/Integer/APInt/gptest.cpp:1.1
*** /dev/null   Tue Feb 20 14:44:11 2007
--- llvm-test/SingleSource/UnitTests/Integer/APInt/gptest.cpp   Tue Feb 20 
14:44:00 2007
***
*** 0 
--- 1,380 
+ //===--- gptest.cpp --- Test Cases for Bit Accurate Types 
-===//
+ //
+ // This file was developed by Guoling Han and is distributed under the 
+ // University of Illinois Open Source License. See LICENSE.TXT for details.
+ //
+ 
//===--===//
+ //
+ // This is a validating test for arithmetic operations that uses the gp (pari)
+ // calculator to validate APInt's computations.
+ //
+ 
//===--===//
+ 
+ #include "llvm/ADT/APInt.h"
+ #include 
+ #include 
+ #include 
+ #include 
+ #include "llvm/System/Signals.h"
+ 
+ using namespace llvm;
+ 
+ APInt x(21, 0x1f);
+ APInt y(21, 0x0f);
+ 
+ void print(const APInt& X, bool wantSigned = false, bool withNL = true) {
+   std::string decstr = X.toString(10,wantSigned);
+   printf("%s", decstr.c_str());
+   if (withNL)
+ printf("\n");
+ }
+ 
+ APInt randomAPInt(unsigned bits) {
+   APInt val(bits, 0u);
+   for (unsigned i = 0; i < bits; ++i) {
+ unsigned bit = rand() % 2;
+ val = val.shl(1);
+ val |= APInt(bits, bit);
+   }
+   return val;
+ }
+ 
+ void test_interface(const APInt &val) {
+   printf("INTERFACE TEST: val = "); print(val);
+   unsigned bitwidth = val.getBitWidth();
+   unsigned pos = rand() % bitwidth;
+   printf("val[%u] = %d\n", pos, val[pos]);
+   APInt smax(APInt::getMaxValue(bitwidth, true));
+   APInt umax(APInt::getMaxValue(bitwidth, false));
+   APInt smin(APInt::getMinValue(bitwidth, true));
+   APInt umin(APInt::getMinValue(bitwidth, false));
+   printf("APInt::getMinValue(%d, true)  = ", bitwidth); print(smin,true);
+   printf("APInt::getMaxValue(%d, true)  = ", bitwidth); print(smax,true);
+   printf("APInt::getMinValue(%d, false) = ", bitwidth); print(umin);
+   printf("APInt::getMaxValue(%d, false) = ", bitwidth); print(umax);
+   APInt null = APInt::getNullValue(bitwidth);
+   APInt allone = APInt::getAllOnesValue(bitwidth);
+   printf("APInt::getNullValue(%d) = ", bitwidth); print(null);
+   printf("APInt::getAllOnesValue(%d) = ", bitwidth); print(allone);
+   APInt x(val);
+   x.set(pos);
+   printf("val.set(%d) = ", pos);  print(x);
+   x.set();
+   printf("val.set() = "); print(x);
+   x = val;
+   x.clear(pos);
+   printf("val.clear(%d) = ", pos);  print(x);
+   x.clear();
+   printf("val.clear() = "); print(x);
+   x = val;
+   x.flip(pos);
+   printf("val.flip(%d) = ", pos); print(x);
+   x = val;
+   x.flip();
+   printf("val.flip() = "); print(x);
+   unsigned bitsize = bitwidth / 2;
+   printf("val.getHiBits(%d) = ", bitsize); print(val.getHiBits(bitsize));
+   printf("val.getLoBits(%d) = ", bitsize); print(val.getLoBits(bitsize));
+   printf("val.isIntN(%d) = %d\n", bitwidth, val.isIntN(bitwidth));
+ }
+ 
+ void test_unops(const APInt &val) {
+   printf("UNARY OPERATORS TEST: val = "); print(val);
+   APInt x(val);
+   x++;
+   printf("val++ = "); print(x);
+   x = val;
+   ++x;
+   printf("++val = "); print(x);
+   x = val;
+   x--;
+   printf("val-- = "); print(x);
+   x = val;
+   --x;
+   printf("--val = "); print(x);
+   x = -val;
+   printf("-val = "); print(x);
+   x = ~val;
+   printf("~val = "); print(x);
+   printf("!val = %d\n", !val);
+   printf("val.isPowerOf2() = %d\n", val.isPowerOf2());
+   printf("val.logBase2() = %d\n", val.logBase2());
+   printf("val.countLeadingZeros() = %d\n", val.countLeadingZeros());
+   printf("val.countTrailingZeros() = %d\n", val.countTrailingZeros());
+   printf("val.countPopulation() = %d\n", val.countPopulation());
+   printf("val.getBitWidth() = %d\n", val.getBitWidth());
+   if (val.getBitWidth() >= 16 && val.getBitWidth() % 16 == 0) {
+ x = val.byteSwap();
+ printf("val.byteSwap() = "); print(x);
+   }
+   printf("val.roundToDouble(false) = %f\n", val.roundToDouble(false));
+   printf("val.roundToDouble(true)  = %f\n", val.roundToDouble(true));
+   printf("val.getValue() = ");
+   if (val.getBitWidth() > 64)
+ printf("too wide\n");
+   else
+ printf("%lu\n", val.getValue());
+ }
+ 
+ void old_test_binops(const APInt &v1, const APInt &v2) {
+   printf("BINARY OPERATORS TEST

[llvm-commits] CVS: llvm/lib/Transforms/Utils/InlineFunction.cpp

2007-02-20 Thread Dan Gohman


Changes in directory llvm/lib/Transforms/Utils:

InlineFunction.cpp updated: 1.53 -> 1.54
---
Log message:

Fix typos in comments.


---
Diffs of the changes:  (+1 -1)

 InlineFunction.cpp |2 +-
 1 files changed, 1 insertion(+), 1 deletion(-)


Index: llvm/lib/Transforms/Utils/InlineFunction.cpp
diff -u llvm/lib/Transforms/Utils/InlineFunction.cpp:1.53 
llvm/lib/Transforms/Utils/InlineFunction.cpp:1.54
--- llvm/lib/Transforms/Utils/InlineFunction.cpp:1.53   Mon Feb 12 20:10:56 2007
+++ llvm/lib/Transforms/Utils/InlineFunction.cppTue Feb 20 14:52:03 2007
@@ -263,7 +263,7 @@
 ++I;
 
   // Transfer all of the allocas over in a block.  Using splice means
-  // that they instructions aren't removed from the symbol table, then
+  // that the instructions aren't removed from the symbol table, then
   // reinserted.
   Caller->front().getInstList().splice(InsertPoint,
FirstNewBlock->getInstList(),



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Target/Target.td

2007-02-20 Thread Dan Gohman


Changes in directory llvm/lib/Target:

Target.td updated: 1.92 -> 1.93
---
Log message:

Fix typos in comments.


---
Diffs of the changes:  (+1 -1)

 Target.td |2 +-
 1 files changed, 1 insertion(+), 1 deletion(-)


Index: llvm/lib/Target/Target.td
diff -u llvm/lib/Target/Target.td:1.92 llvm/lib/Target/Target.td:1.93
--- llvm/lib/Target/Target.td:1.92  Fri Jan 26 08:34:51 2007
+++ llvm/lib/Target/Target.td   Tue Feb 20 14:52:03 2007
@@ -39,7 +39,7 @@
   int SpillAlignment = 0;
 
   // Aliases - A list of registers that this register overlaps with.  A read or
-  // modification of this register can potentially read or modifie the aliased
+  // modification of this register can potentially read or modify the aliased
   // registers.
   //
   list Aliases = [];



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/VMCore/Constants.cpp

2007-02-20 Thread Evan Cheng


Changes in directory llvm/lib/VMCore:

Constants.cpp updated: 1.219 -> 1.220
---
Log message:

This cast broke lots of tests.

---
Diffs of the changes:  (+1 -1)

 Constants.cpp |2 +-
 1 files changed, 1 insertion(+), 1 deletion(-)


Index: llvm/lib/VMCore/Constants.cpp
diff -u llvm/lib/VMCore/Constants.cpp:1.219 llvm/lib/VMCore/Constants.cpp:1.220
--- llvm/lib/VMCore/Constants.cpp:1.219 Tue Feb 20 01:17:17 2007
+++ llvm/lib/VMCore/Constants.cpp   Tue Feb 20 15:30:56 2007
@@ -248,7 +248,7 @@
 uint64_t IntVal = DoubleToBits(V);
 ConstantFP *&Slot = (*DoubleConstants)[std::make_pair(IntVal, Ty)];
 if (Slot) return Slot;
-return Slot = new ConstantFP(Ty, (float)V);
+return Slot = new ConstantFP(Ty, V);
   }
 }
 



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Support/APInt.cpp

2007-02-20 Thread Reid Spencer


Changes in directory llvm/lib/Support:

APInt.cpp updated: 1.24 -> 1.25
---
Log message:

Make long addition and subtraction work. Speed things up by using internal
functions more.


---
Diffs of the changes:  (+69 -72)

 APInt.cpp |  141 ++
 1 files changed, 69 insertions(+), 72 deletions(-)


Index: llvm/lib/Support/APInt.cpp
diff -u llvm/lib/Support/APInt.cpp:1.24 llvm/lib/Support/APInt.cpp:1.25
--- llvm/lib/Support/APInt.cpp:1.24 Tue Feb 20 14:42:10 2007
+++ llvm/lib/Support/APInt.cpp  Tue Feb 20 17:40:25 2007
@@ -85,13 +85,13 @@
 }
 
 /// @brief Copy constructor
-APInt::APInt(const APInt& APIVal)
-  : BitWidth(APIVal.BitWidth), pVal(0) {
+APInt::APInt(const APInt& that)
+  : BitWidth(that.BitWidth), pVal(0) {
   if (isSingleWord()) 
-VAL = APIVal.VAL;
+VAL = that.VAL;
   else {
 pVal = getMemory(getNumWords());
-memcpy(pVal, APIVal.pVal, getNumWords() * APINT_WORD_SIZE);
+memcpy(pVal, that.pVal, getNumWords() * APINT_WORD_SIZE);
   }
 }
 
@@ -186,11 +186,11 @@
 /// y[] and returns the carry.
 static uint64_t add(uint64_t dest[], uint64_t x[], 
uint64_t y[], uint32_t len) {
-  uint32_t carry = 0;
+  uint64_t carry = 0;
   for (uint32_t i = 0; i< len; ++i) {
-carry += x[i];
-dest[i] = carry + y[i];
-carry = carry < x[i] ? 1 : (dest[i] < carry ? 1 : 0);
+uint64_t save = x[i];
+dest[i] = x[i] + y[i] + carry;
+carry = dest[i] < save ? 1 : 0;
   }
   return carry;
 }
@@ -199,18 +199,10 @@
 /// RHS and assigns the result to this APInt.
 APInt& APInt::operator+=(const APInt& RHS) {
   assert(BitWidth == RHS.BitWidth && "Bit widths must be the same");
-  if (isSingleWord()) VAL += RHS.isSingleWord() ? RHS.VAL : RHS.pVal[0];
+  if (isSingleWord()) 
+VAL += RHS.VAL;
   else {
-if (RHS.isSingleWord()) add_1(pVal, pVal, getNumWords(), RHS.VAL);
-else {
-  if (getNumWords() <= RHS.getNumWords()) 
-add(pVal, pVal, RHS.pVal, getNumWords());
-  else {
-uint64_t carry = add(pVal, pVal, RHS.pVal, RHS.getNumWords());
-add_1(pVal + RHS.getNumWords(), pVal + RHS.getNumWords(), 
-  getNumWords() - RHS.getNumWords(), carry);
-  }
-}
+add(pVal, pVal, RHS.pVal, getNumWords());
   }
   clearUnusedBits();
   return *this;
@@ -220,19 +212,13 @@
 /// integer array y[], and returns the borrow-out carry.
 static uint64_t sub(uint64_t dest[], uint64_t x[], 
uint64_t y[], uint32_t len) {
-  // Carry indicator.
-  uint64_t cy = 0;
-  
+  uint64_t borrow = 0;
   for (uint32_t i = 0; i < len; ++i) {
-uint64_t Y = y[i], X = x[i];
-Y += cy;
-
-cy = Y < cy ? 1 : 0;
-Y = X - Y;
-cy += Y > X ? 1 : 0;
-dest[i] = Y;
+uint64_t save = x[i];
+dest[i] = x[i] - borrow - y[i];
+borrow = save < dest[i] ? 1 : 0;
   }
-  return cy;
+  return borrow;
 }
 
 /// @brief Subtraction assignment operator. Subtracts this APInt by the given
@@ -240,20 +226,9 @@
 APInt& APInt::operator-=(const APInt& RHS) {
   assert(BitWidth == RHS.BitWidth && "Bit widths must be the same");
   if (isSingleWord()) 
-VAL -= RHS.isSingleWord() ? RHS.VAL : RHS.pVal[0];
-  else {
-if (RHS.isSingleWord())
-  sub_1(pVal, getNumWords(), RHS.VAL);
-else {
-  if (RHS.getNumWords() < getNumWords()) { 
-uint64_t carry = sub(pVal, pVal, RHS.pVal, RHS.getNumWords());
-sub_1(pVal + RHS.getNumWords(), getNumWords() - RHS.getNumWords(), 
-  carry); 
-  }
-  else
-sub(pVal, pVal, RHS.pVal, getNumWords());
-}
-  }
+VAL -= RHS.VAL;
+  else
+sub(pVal, pVal, RHS.pVal, getNumWords());
   clearUnusedBits();
   return *this;
 }
@@ -330,7 +305,7 @@
 /// given APInt& RHS and assigns the result to this APInt.
 APInt& APInt::operator*=(const APInt& RHS) {
   assert(BitWidth == RHS.BitWidth && "Bit widths must be the same");
-  if (isSingleWord()) 
+  if (isSingleWord())
 VAL *= RHS.VAL;
   else {
 // one-based first non-zero bit position.
@@ -338,8 +313,6 @@
 uint32_t xlen = !first ? 0 : whichWord(first - 1) + 1;
 if (!xlen) 
   return *this;
-else if (RHS.isSingleWord()) 
-  mul_1(pVal, pVal, xlen, RHS.VAL);
 else {
   first = RHS.getActiveBits();
   uint32_t ylen = !first ? 0 : whichWord(first - 1) + 1;
@@ -392,11 +365,13 @@
   assert(BitWidth == RHS.BitWidth && "Bit widths must be the same");
   if (isSingleWord()) {
 VAL ^= RHS.VAL;
+this->clearUnusedBits();
 return *this;
   } 
   uint32_t numWords = getNumWords();
   for (uint32_t i = 0; i < numWords; ++i)
 pVal[i] ^= RHS.pVal[i];
+  this->clearUnusedBits();
   return *this;
 }
 
@@ -420,6 +395,7 @@
   assert(BitWidth == RHS.BitWidth && "Bit widths must be the same");
   if (isSingleWord())
 return APInt(getBitWidth(), VAL | RHS.VAL);
+
   APInt Result(*this);
   uint32_t numWords = getNumWords();
   for (uint32_t i = 0; i < numWords; ++i)
@@ -431,8 +4

[llvm-commits] CVS: llvm/lib/Support/APInt.cpp

2007-02-20 Thread Reid Spencer


Changes in directory llvm/lib/Support:

APInt.cpp updated: 1.25 -> 1.26
---
Log message:

Fix countLeadingZeros to actually return the correct number.
Fix toString to correctly return "0" for zero valued APInts over 128 bits.


---
Diffs of the changes:  (+13 -11)

 APInt.cpp |   24 +---
 1 files changed, 13 insertions(+), 11 deletions(-)


Index: llvm/lib/Support/APInt.cpp
diff -u llvm/lib/Support/APInt.cpp:1.25 llvm/lib/Support/APInt.cpp:1.26
--- llvm/lib/Support/APInt.cpp:1.25 Tue Feb 20 17:40:25 2007
+++ llvm/lib/Support/APInt.cpp  Tue Feb 20 18:29:48 2007
@@ -696,18 +696,20 @@
 /// the number of zeros from the most significant bit to the first one bit.
 /// @returns numWord() * 64 if the value is zero.
 uint32_t APInt::countLeadingZeros() const {
-  if (isSingleWord())
-return CountLeadingZeros_64(VAL) - (APINT_BITS_PER_WORD - BitWidth);
   uint32_t Count = 0;
-  for (uint32_t i = getNumWords(); i > 0u; --i) {
-uint32_t tmp = CountLeadingZeros_64(pVal[i-1]);
-Count += tmp;
-if (tmp != APINT_BITS_PER_WORD)
-  if (i == getNumWords())
-Count -= (APINT_BITS_PER_WORD - whichBit(BitWidth));
-  break;
+  if (isSingleWord())
+Count = CountLeadingZeros_64(VAL);
+  else {
+for (uint32_t i = getNumWords(); i > 0u; --i) {
+  if (pVal[i-1] == 0)
+Count += APINT_BITS_PER_WORD;
+  else {
+Count += CountLeadingZeros_64(pVal[i-1]);
+break;
+  }
+}
   }
-  return Count;
+  return Count - (APINT_BITS_PER_WORD - (BitWidth % APINT_BITS_PER_WORD));
 }
 
 /// countTrailingZeros - This function is a APInt version corresponding to
@@ -1513,7 +1515,7 @@
 result = "-";
 insert_at = 1;
   }
-  if (tmp == 0)
+  if (tmp == APInt(tmp.getBitWidth(), 0))
 result = "0";
   else while (tmp.ne(zero)) {
 APInt APdigit(1,0);



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] [124123] Converts "getOrInsertFunction" calls to "Intrinsic::getDeclaration " calls for

2007-02-20 Thread bwendlin
Revision: 124123
Author:   bwendlin
Date: 2007-02-20 16:45:58 -0800 (Tue, 20 Feb 2007)

Log Message:
---
Converts "getOrInsertFunction" calls to "Intrinsic::getDeclaration" calls for
PR1189. It also gets rid of the function caching mechanism, so that it's
multi-module safe.

Modified Paths:
--
apple-local/branches/llvm/gcc/llvm-convert.cpp
apple-local/branches/llvm/gcc/llvm-internal.h

Modified: apple-local/branches/llvm/gcc/llvm-convert.cpp
===
--- apple-local/branches/llvm/gcc/llvm-convert.cpp  2007-02-20 21:42:10 UTC 
(rev 124122)
+++ apple-local/branches/llvm/gcc/llvm-convert.cpp  2007-02-21 00:45:58 UTC 
(rev 124123)
@@ -33,7 +33,6 @@
 #include "llvm/DerivedTypes.h"
 #include "llvm/InlineAsm.h"
 #include "llvm/Instructions.h"
-#include "llvm/Intrinsics.h"
 #include "llvm/Module.h"
 #include "llvm/Target/TargetAsmInfo.h"
 #include "llvm/Target/TargetData.h"
@@ -1118,63 +1117,55 @@
 void TreeToLLVM::EmitMemCpy(Value *DestPtr, Value *SrcPtr, Value *Size, 
 unsigned Align) {
   const Type *SBP = PointerType::get(Type::Int8Ty);
-  static Constant *MemCpy = 0;
   const Type *IntPtr = TD.getIntPtrType();
-  if (!MemCpy) {
-const char *Name = IntPtr == Type::Int32Ty ?
-   "llvm.memcpy.i32" : "llvm.memcpy.i64";
-MemCpy = TheModule->getOrInsertFunction(Name, Type::VoidTy, SBP, 
-SBP, IntPtr, Type::Int32Ty,
-NULL);
-  }
   Value *Ops[4] = {
 CastToType(Instruction::BitCast, DestPtr, SBP),
 CastToType(Instruction::BitCast, SrcPtr, SBP),
 CastToSIntType(Size, IntPtr),
 ConstantInt::get(Type::Int32Ty, Align)
   };
-  new CallInst(MemCpy, Ops, 4, "", CurBB);
+
+  new CallInst(Intrinsic::getDeclaration(TheModule, 
+ (IntPtr == Type::Int32Ty) ?
+ Intrinsic::memcpy_i32 :
+ Intrinsic::memcpy_i64),
+   Ops, 4, "", CurBB);
 }
 
 void TreeToLLVM::EmitMemMove(Value *DestPtr, Value *SrcPtr, Value *Size, 
  unsigned Align) {
   const Type *SBP = PointerType::get(Type::Int8Ty);
-  static Constant *MemMove = 0;
   const Type *IntPtr = TD.getIntPtrType();
-  if (!MemMove) {
-const char *Name = IntPtr == Type::Int32Ty ?
-   "llvm.memmove.i32" : "llvm.memmove.i64";
-MemMove = TheModule->getOrInsertFunction(Name, Type::VoidTy, SBP, SBP,
- IntPtr, Type::Int32Ty, NULL);
-  }
   Value *Ops[4] = {
 CastToType(Instruction::BitCast, DestPtr, SBP),
 CastToType(Instruction::BitCast, SrcPtr, SBP),
 CastToSIntType(Size, IntPtr),
 ConstantInt::get(Type::Int32Ty, Align)
   };
-  new CallInst(MemMove, Ops, 4, "", CurBB);
+
+  new CallInst(Intrinsic::getDeclaration(TheModule,
+ (IntPtr == Type::Int32Ty) ?
+ Intrinsic::memmove_i32 :
+ Intrinsic::memmove_i64),
+   Ops, 4, "", CurBB);
 }
 
 void TreeToLLVM::EmitMemSet(Value *DestPtr, Value *SrcVal, Value *Size, 
 unsigned Align) {
   const Type *SBP = PointerType::get(Type::Int8Ty);
-  static Constant *MemSet = 0;
   const Type *IntPtr = TD.getIntPtrType();
-  if (!MemSet) {
-const char *Name = IntPtr == Type::Int32Ty ?
-   "llvm.memset.i32" : "llvm.memset.i64";
-MemSet = TheModule->getOrInsertFunction(Name, Type::VoidTy, SBP, 
-Type::Int8Ty, IntPtr,
-Type::Int32Ty, NULL);
-  }
   Value *Ops[4] = {
 CastToType(Instruction::BitCast, DestPtr, SBP),
 CastToSIntType(SrcVal, Type::Int8Ty),
 CastToSIntType(Size, IntPtr),
 ConstantInt::get(Type::Int32Ty, Align)
   };
-  new CallInst(MemSet, Ops, 4, "", CurBB);
+
+  new CallInst(Intrinsic::getDeclaration(TheModule,
+ (IntPtr == Type::Int32Ty) ?
+ Intrinsic::memset_i32 :
+ Intrinsic::memset_i64),
+   Ops, 4, "", CurBB);
 }
 
 
@@ -2561,8 +2552,7 @@
 return new SelectInst(Cmp, Op, OpN, "abs", CurBB);
   } else {
 // Turn FP abs into fabs/fabsf.
-static Function *fabsf_cache = 0, *fabs_cache = 0;
-return EmitBuiltinUnaryFPOp(Op, "fabsf", fabsf_cache, "fabs", fabs_cache);
+return EmitBuiltinUnaryFPOp(Op, "fabsf", "fabs");
   }
 }
 
@@ -3504,17 +3494,8 @@
   }
   
   // Finally, map the intrinsic ID back to a name.
-  static const char * const IntrinsicNames[] = {
-#define GET_INTRINSIC_NAME_TABLE
-#include "llvm/Intrinsics.gen"
-#undef GET_INTRINSIC_NAME_TABLE
-0
-  };
-  const char *Intrins

[llvm-commits] CVS: llvm/lib/CodeGen/VirtRegMap.cpp

2007-02-20 Thread Evan Cheng


Changes in directory llvm/lib/CodeGen:

VirtRegMap.cpp updated: 1.96 -> 1.97
---
Log message:

Use BitVector instead. No functionality change.

---
Diffs of the changes:  (+5 -8)

 VirtRegMap.cpp |   13 +
 1 files changed, 5 insertions(+), 8 deletions(-)


Index: llvm/lib/CodeGen/VirtRegMap.cpp
diff -u llvm/lib/CodeGen/VirtRegMap.cpp:1.96 
llvm/lib/CodeGen/VirtRegMap.cpp:1.97
--- llvm/lib/CodeGen/VirtRegMap.cpp:1.96Mon Feb 19 19:29:10 2007
+++ llvm/lib/CodeGen/VirtRegMap.cpp Tue Feb 20 20:22:03 2007
@@ -27,6 +27,7 @@
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/Compiler.h"
+#include "llvm/ADT/BitVector.h"
 #include "llvm/ADT/Statistic.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallSet.h"
@@ -423,14 +424,10 @@
   class VISIBILITY_HIDDEN ReuseInfo {
 MachineInstr &MI;
 std::vector Reuses;
-bool *PhysRegsClobbered;
+BitVector PhysRegsClobbered;
   public:
 ReuseInfo(MachineInstr &mi, const MRegisterInfo *mri) : MI(mi) {
-  PhysRegsClobbered = new bool[mri->getNumRegs()];
-  std::fill(PhysRegsClobbered, PhysRegsClobbered+mri->getNumRegs(), false);
-}
-~ReuseInfo() {
-  delete[] PhysRegsClobbered;
+  PhysRegsClobbered.resize(mri->getNumRegs());
 }
 
 bool hasReuses() const {
@@ -452,11 +449,11 @@
 }
 
 void markClobbered(unsigned PhysReg) {
-  PhysRegsClobbered[PhysReg] = true;
+  PhysRegsClobbered.set(PhysReg);
 }
 
 bool isClobbered(unsigned PhysReg) const {
-  return PhysRegsClobbered[PhysReg];
+  return PhysRegsClobbered.test(PhysReg);
 }
 
 /// GetRegForReload - We are about to emit a reload into PhysReg.  If there



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/CodeGen/LiveIntervalAnalysis.cpp

2007-02-20 Thread Evan Cheng


Changes in directory llvm/lib/CodeGen:

LiveIntervalAnalysis.cpp updated: 1.209 -> 1.210
---
Log message:

Out of bound reference.

---
Diffs of the changes:  (+2 -2)

 LiveIntervalAnalysis.cpp |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)


Index: llvm/lib/CodeGen/LiveIntervalAnalysis.cpp
diff -u llvm/lib/CodeGen/LiveIntervalAnalysis.cpp:1.209 
llvm/lib/CodeGen/LiveIntervalAnalysis.cpp:1.210
--- llvm/lib/CodeGen/LiveIntervalAnalysis.cpp:1.209 Mon Feb 19 15:49:53 2007
+++ llvm/lib/CodeGen/LiveIntervalAnalysis.cpp   Tue Feb 20 20:27:39 2007
@@ -1451,10 +1451,10 @@
 /// reg between indexes Start and End.
 bool
 LiveIntervals::hasRegisterUse(unsigned Reg, unsigned Start, unsigned End) {
-  for (unsigned Index = Start+InstrSlots::NUM; Index != End;
+  for (unsigned Index = Start+InstrSlots::NUM; Index < End;
Index += InstrSlots::NUM) {
 // Skip deleted instructions
-while (Index != End && !getInstructionFromIndex(Index))
+while (Index < End && !getInstructionFromIndex(Index))
   Index += InstrSlots::NUM;
 if (Index >= End) break;
 



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/include/llvm/Analysis/ET-Forest.h

2007-02-20 Thread Devang Patel


Changes in directory llvm/include/llvm/Analysis:

ET-Forest.h updated: 1.7 -> 1.8
---
Log message:

Fix memory leak (PR 775: http://llvm.org/PR775 ).


---
Diffs of the changes:  (+2 -0)

 ET-Forest.h |2 ++
 1 files changed, 2 insertions(+)


Index: llvm/include/llvm/Analysis/ET-Forest.h
diff -u llvm/include/llvm/Analysis/ET-Forest.h:1.7 
llvm/include/llvm/Analysis/ET-Forest.h:1.8
--- llvm/include/llvm/Analysis/ET-Forest.h:1.7  Thu Sep 21 20:05:33 2006
+++ llvm/include/llvm/Analysis/ET-Forest.h  Tue Feb 20 20:36:31 2007
@@ -141,6 +141,8 @@
   // removeFromForest()
   ~ETNode() {
 delete RightmostOcc;
+if (ParentOcc)
+  delete ParentOcc;
   }
 
   void removeFromForest() {



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Support/APInt.cpp

2007-02-20 Thread Reid Spencer


Changes in directory llvm/lib/Support:

APInt.cpp updated: 1.26 -> 1.27
---
Log message:

1. Add a dump() method for faster debugging.
2. Change 0 initialization of union to larger component so all is zeroed.
3. Fix the borrow logic in subtraction so it works for > 128 bits.
4. Rewrite fromString to use a simpler but correct algorithm and also to
   not set the bit width contrary to the user's request.
5. Optimize toString a bit by making it only do one Knuth divide per
   iteration instead of two.

With these changes, all arithmetic passes (verified by pari/GP) up to 
1024 bits except for certain division cases.


---
Diffs of the changes:  (+80 -81)

 APInt.cpp |  161 ++
 1 files changed, 80 insertions(+), 81 deletions(-)


Index: llvm/lib/Support/APInt.cpp
diff -u llvm/lib/Support/APInt.cpp:1.26 llvm/lib/Support/APInt.cpp:1.27
--- llvm/lib/Support/APInt.cpp:1.26 Tue Feb 20 18:29:48 2007
+++ llvm/lib/Support/APInt.cpp  Tue Feb 20 21:55:44 2007
@@ -17,6 +17,11 @@
 #include "llvm/Support/MathExtras.h"
 #include 
 #include 
+#ifndef NDEBUG
+#include 
+#include 
+#endif
+
 using namespace llvm;
 
 // A utility function for allocating memory, checking for allocation failures,
@@ -36,7 +41,7 @@
 }
 
 APInt::APInt(uint32_t numBits, uint64_t val)
-  : BitWidth(numBits), pVal(0) {
+  : BitWidth(numBits), VAL(0) {
   assert(BitWidth >= IntegerType::MIN_INT_BITS && "bitwidth too small");
   assert(BitWidth <= IntegerType::MAX_INT_BITS && "bitwidth too large");
   if (isSingleWord()) 
@@ -48,7 +53,7 @@
 }
 
 APInt::APInt(uint32_t numBits, uint32_t numWords, uint64_t bigVal[])
-  : BitWidth(numBits), pVal(0)  {
+  : BitWidth(numBits), VAL(0)  {
   assert(BitWidth >= IntegerType::MIN_INT_BITS && "bitwidth too small");
   assert(BitWidth <= IntegerType::MAX_INT_BITS && "bitwidth too large");
   assert(bigVal && "Null pointer detected!");
@@ -72,21 +77,21 @@
 /// integer value.
 APInt::APInt(uint32_t numbits, const char StrStart[], uint32_t slen, 
  uint8_t radix) 
-  : BitWidth(numbits), pVal(0) {
+  : BitWidth(numbits), VAL(0) {
   fromString(numbits, StrStart, slen, radix);
 }
 
 /// @brief Create a new APInt by translating the string represented
 /// integer value.
 APInt::APInt(uint32_t numbits, const std::string& Val, uint8_t radix)
-  : BitWidth(numbits), pVal(0) {
+  : BitWidth(numbits), VAL(0) {
   assert(!Val.empty() && "String empty?");
   fromString(numbits, Val.c_str(), Val.size(), radix);
 }
 
 /// @brief Copy constructor
 APInt::APInt(const APInt& that)
-  : BitWidth(that.BitWidth), pVal(0) {
+  : BitWidth(that.BitWidth), VAL(0) {
   if (isSingleWord()) 
 VAL = that.VAL;
   else {
@@ -184,11 +189,10 @@
 
 /// add - This function adds the integer array x[] by integer array
 /// y[] and returns the carry.
-static uint64_t add(uint64_t dest[], uint64_t x[], 
-   uint64_t y[], uint32_t len) {
+static uint64_t add(uint64_t dest[], uint64_t x[], uint64_t y[], uint32_t len) 
{
   uint64_t carry = 0;
   for (uint32_t i = 0; i< len; ++i) {
-uint64_t save = x[i];
+uint64_t save = std::max(x[i],y[i]);
 dest[i] = x[i] + y[i] + carry;
 carry = dest[i] < save ? 1 : 0;
   }
@@ -210,13 +214,13 @@
 
 /// sub - This function subtracts the integer array x[] by
 /// integer array y[], and returns the borrow-out carry.
-static uint64_t sub(uint64_t dest[], uint64_t x[], 
-   uint64_t y[], uint32_t len) {
-  uint64_t borrow = 0;
+static uint64_t sub(uint64_t *dest, const uint64_t *x, const uint64_t *y, 
+uint32_t len) {
+  bool borrow = false;
   for (uint32_t i = 0; i < len; ++i) {
-uint64_t save = x[i];
-dest[i] = x[i] - borrow - y[i];
-borrow = save < dest[i] ? 1 : 0;
+uint64_t x_tmp = borrow ? x[i] - 1 : x[i];
+borrow = y[i] > x_tmp || (borrow && x[i] == 0);
+dest[i] = x_tmp - y[i];
   }
   return borrow;
 }
@@ -1385,72 +1389,55 @@
 }
 
 /// @brief Converts a char array into an integer.
-void APInt::fromString(uint32_t numbits, const char *StrStart, uint32_t slen, 
+void APInt::fromString(uint32_t numbits, const char *str, uint32_t slen, 
uint8_t radix) {
+  // Check our assumptions here
   assert((radix == 10 || radix == 8 || radix == 16 || radix == 2) &&
  "Radix should be 2, 8, 10, or 16!");
-  assert(StrStart && "String is null?");
-  uint32_t size = 0;
-  // If the radix is a power of 2, read the input
-  // from most significant to least significant.
-  if ((radix & (radix - 1)) == 0) {
-uint32_t nextBitPos = 0; 
-uint32_t bits_per_digit = radix / 8 + 2;
-uint64_t resDigit = 0;
-BitWidth = slen * bits_per_digit;
-if (getNumWords() > 1)
-  pVal = getMemory(getNumWords());
-for (int i = slen - 1; i >= 0; --i) {
-  uint64_t digit = StrStart[i] - '0';
-  resDigit |= digit << nextBitPos;
-  nextBitPos += bits_per_digit;
-  if (nextBitPos >= APINT_BITS_PER_WORD)

[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h

2007-02-20 Thread Reid Spencer


Changes in directory llvm/include/llvm/ADT:

APInt.h updated: 1.15 -> 1.16
---
Log message:

Add a dump() method for debugging.


---
Diffs of the changes:  (+7 -2)

 APInt.h |9 +++--
 1 files changed, 7 insertions(+), 2 deletions(-)


Index: llvm/include/llvm/ADT/APInt.h
diff -u llvm/include/llvm/ADT/APInt.h:1.15 llvm/include/llvm/ADT/APInt.h:1.16
--- llvm/include/llvm/ADT/APInt.h:1.15  Tue Feb 20 02:43:42 2007
+++ llvm/include/llvm/ADT/APInt.h   Tue Feb 20 21:56:12 2007
@@ -128,12 +128,17 @@
   void fromString(uint32_t numBits, const char *StrStart, uint32_t slen, 
   uint8_t radix);
 
+#ifndef NDEBUG
+  /// @brief debug method
+  void dump() const;
+#endif
+
+public:
   /// @brief An internal division function for dividing APInts.
   static void divide(const APInt LHS, uint32_t lhsWords, 
  const APInt &RHS, uint32_t rhsWords,
  APInt *Quotient, APInt *Remainder);
 
-public:
   /// @brief Create a new APInt of numBits bit-width, and initialized as val.
   APInt(uint32_t numBits, uint64_t val);
 
@@ -412,7 +417,7 @@
   /// computations to see how "wide" the value is.
   /// @brief Compute the number of active bits in the value
   inline uint32_t getActiveBits() const {
-return getNumWords() * APINT_BITS_PER_WORD - countLeadingZeros();
+return BitWidth - countLeadingZeros();
   }
 
   /// @returns a uint64_t value from this APInt. If this APInt contains a 
single



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Support/APInt.cpp

2007-02-20 Thread Reid Spencer


Changes in directory llvm/lib/Support:

APInt.cpp updated: 1.27 -> 1.28
---
Log message:

Fix the carry in addition.


---
Diffs of the changes:  (+2 -2)

 APInt.cpp |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)


Index: llvm/lib/Support/APInt.cpp
diff -u llvm/lib/Support/APInt.cpp:1.27 llvm/lib/Support/APInt.cpp:1.28
--- llvm/lib/Support/APInt.cpp:1.27 Tue Feb 20 21:55:44 2007
+++ llvm/lib/Support/APInt.cpp  Tue Feb 20 23:44:56 2007
@@ -192,9 +192,9 @@
 static uint64_t add(uint64_t dest[], uint64_t x[], uint64_t y[], uint32_t len) 
{
   uint64_t carry = 0;
   for (uint32_t i = 0; i< len; ++i) {
-uint64_t save = std::max(x[i],y[i]);
 dest[i] = x[i] + y[i] + carry;
-carry = dest[i] < save ? 1 : 0;
+uint64_t limit = std::min(x[i],y[i]);
+carry = dest[i] < limit || (carry && dest[i] == limit);
   }
   return carry;
 }



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/Makefile

2007-02-20 Thread Chris Lattner


Changes in directory llvm:

Makefile updated: 1.69 -> 1.70
---
Log message:

revert r1.68.  This breaks 'make install' without doing 'make' first, but
fixes PR1208: http://llvm.org/PR1208 .


---
Diffs of the changes:  (+7 -0)

 Makefile |7 +++
 1 files changed, 7 insertions(+)


Index: llvm/Makefile
diff -u llvm/Makefile:1.69 llvm/Makefile:1.70
--- llvm/Makefile:1.69  Mon Feb  5 17:18:58 2007
+++ llvm/Makefile   Wed Feb 21 00:23:20 2007
@@ -40,6 +40,13 @@
   OPTIONAL_DIRS :=
 endif
 
+# Don't install utils, examples, or projects they are only used to 
+# build LLVM.
+ifeq ($(MAKECMDGOALS),install)
+  DIRS := $(filter-out utils, $(DIRS))
+  OPTIONAL_DIRS :=
+endif
+
 # Include the main makefile machinery.
 include $(LLVM_SRC_ROOT)/Makefile.rules
 



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


Re: [llvm-commits] CVS: llvm/Makefile

2007-02-20 Thread Reid Spencer
On Wed, 2007-02-21 at 00:23 -0600, Chris Lattner wrote:
> 
> Changes in directory llvm:
> 
> Makefile updated: 1.69 -> 1.70
> ---
> Log message:
> 
> revert r1.68.  This breaks 'make install' without doing 'make' first, but
> fixes PR1208: http://llvm.org/PR1208 .

This isn't correct. I implemented the NO_INSTALL keyword specifically to
prevent installation of a directory's build products. This is what
utils/TableGen does. 

Please revert this patch (1.70) and edit the examples directory's
makefiles to include:

NO_INSTALL := 1

That will prevent installation of the examples while still fixing the PR
for allowing "make install" to build everything and install only that
which is installable.

>From the makefile guide:

> NO_INSTALL
> Specifies that the build products of the directory should not
> be installed but should be built even if the install target is
> given. This is handy for directories that build libraries or
> tools that are only used as part of the build process, such as
> code generators (e.g. tblgen).

Thanks,

Reid.

> 
> 
> ---
> Diffs of the changes:  (+7 -0)
> 
>  Makefile |7 +++
>  1 files changed, 7 insertions(+)
> 
> 
> Index: llvm/Makefile
> diff -u llvm/Makefile:1.69 llvm/Makefile:1.70
> --- llvm/Makefile:1.69Mon Feb  5 17:18:58 2007
> +++ llvm/Makefile Wed Feb 21 00:23:20 2007
> @@ -40,6 +40,13 @@
>OPTIONAL_DIRS :=
>  endif
>  
> +# Don't install utils, examples, or projects they are only used to 
> +# build LLVM.
> +ifeq ($(MAKECMDGOALS),install)
> +  DIRS := $(filter-out utils, $(DIRS))
> +  OPTIONAL_DIRS :=
> +endif
> +
>  # Include the main makefile machinery.
>  include $(LLVM_SRC_ROOT)/Makefile.rules
>  
> 
> 
> 
> ___
> llvm-commits mailing list
> llvm-commits@cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits

___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


Re: [llvm-commits] CVS: llvm/Makefile

2007-02-20 Thread Chris Lattner
>> revert r1.68.  This breaks 'make install' without doing 'make'  
>> first, but
>> fixes PR1208: http://llvm.org/PR1208 .
>
> This isn't correct.

I'm aware of that, which is why I mentioned that in the commit  
message.  I'm just repairing the regression by reverting the  
offending patch: if you'd like to refix "make install without doing a  
make first" (without reintroducing the regression) go for it!

-Chris


___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


Re: [llvm-commits] CVS: llvm/Makefile

2007-02-20 Thread Reid Spencer
On Tue, 2007-02-20 at 23:23 -0800, Chris Lattner wrote:
> >> revert r1.68.  This breaks 'make install' without doing 'make'  
> >> first, but
> >> fixes PR1208: http://llvm.org/PR1208 .
> >
> > This isn't correct.
> 
> I'm aware of that, which is why I mentioned that in the commit  
> message.  I'm just repairing the regression by reverting the  
> offending patch: if you'd like to refix "make install without doing a  
> make first" (without reintroducing the regression) go for it!

I just explained exactly how.

> 
> -Chris
> 
> 

___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits