Use CHAR_BIT instead of hard-coding 8 in several places where it
authorDan Gohman <gohman@apple.com>
Wed, 1 Apr 2009 18:45:54 +0000 (18:45 +0000)
committerDan Gohman <gohman@apple.com>
Wed, 1 Apr 2009 18:45:54 +0000 (18:45 +0000)
is appropriate. This helps visually differentiate host-oriented
calculations from target-oriented calculations.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@68227 91177308-0d34-0410-b5e6-96231b3b80d8

13 files changed:
include/llvm/ADT/APInt.h
include/llvm/ADT/BitVector.h
include/llvm/ADT/SparseBitVector.h
include/llvm/Bitcode/BitstreamReader.h
include/llvm/CodeGen/LiveInterval.h
include/llvm/CodeGen/MachineConstantPool.h
include/llvm/CodeGen/SelectionDAGNodes.h
include/llvm/Support/CommandLine.h
lib/ExecutionEngine/Interpreter/Execution.cpp
lib/ExecutionEngine/JIT/JITMemoryManager.cpp
lib/Support/APInt.cpp
lib/Target/CellSPU/SPUISelLowering.cpp
tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp

index a309d7f99548f88697c5b269051728de94d19649..388316d20994c82692148e44f6b3fcdaab8b8e82 100644 (file)
@@ -18,6 +18,7 @@
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/MathExtras.h"
 #include <cassert>
+#include <climits>
 #include <cstring>
 #include <string>
 
@@ -81,7 +82,8 @@ class APInt {
   /// This enum is used to hold the constants we needed for APInt.
   enum {
     /// Bits in a word
-    APINT_BITS_PER_WORD = static_cast<unsigned int>(sizeof(uint64_t)) * 8,
+    APINT_BITS_PER_WORD = static_cast<unsigned int>(sizeof(uint64_t)) *
+                          CHAR_BIT,
     /// Byte size of a word
     APINT_WORD_SIZE = static_cast<unsigned int>(sizeof(uint64_t))
   };
index 23fde26e142ddfc1f88bcb0d26df2dc09a689435..9c046efaaddd9cf7bfec7d6d70b37e23f848417e 100644 (file)
@@ -17,6 +17,7 @@
 #include "llvm/Support/MathExtras.h"
 #include <algorithm>
 #include <cassert>
+#include <climits>
 #include <cstring>
 
 namespace llvm {
@@ -24,7 +25,7 @@ namespace llvm {
 class BitVector {
   typedef unsigned long BitWord;
 
-  enum { BITWORD_SIZE = (unsigned)sizeof(BitWord) * 8 };
+  enum { BITWORD_SIZE = (unsigned)sizeof(BitWord) * CHAR_BIT };
 
   BitWord  *Bits;        // Actual bits.
   unsigned Size;         // Size of bitvector in bits.
index dabcb028e99868660285aff61415b7c9bee004ff..70cb7f4f90cee521adcb3329191a8d0a3b87dfbd 100644 (file)
@@ -16,6 +16,7 @@
 #define LLVM_ADT_SPARSEBITVECTOR_H
 
 #include <cassert>
+#include <climits>
 #include <cstring>
 #include "llvm/Support/DataTypes.h"
 #include "llvm/ADT/STLExtras.h"
@@ -44,7 +45,7 @@ struct SparseBitVectorElement
 public:
   typedef unsigned long BitWord;
   enum {
-    BITWORD_SIZE = sizeof(BitWord) * 8,
+    BITWORD_SIZE = sizeof(BitWord) * CHAR_BIT,
     BITWORDS_PER_ELEMENT = (ElementSize + BITWORD_SIZE - 1) / BITWORD_SIZE,
     BITS_PER_ELEMENT = ElementSize
   };
index 7cbd10f532c63301846b64e9158312660bf1c4ca..48eaa36b524c7ea974b2c734d15ea2e182aa22df 100644 (file)
@@ -16,6 +16,7 @@
 #define BITSTREAM_READER_H
 
 #include "llvm/Bitcode/BitCodes.h"
+#include <climits>
 #include <vector>
 
 namespace llvm {
@@ -114,7 +115,7 @@ public:
 
   /// GetCurrentBitNo - Return the bit # of the bit we are reading.
   uint64_t GetCurrentBitNo() const {
-    return (NextChar-FirstChar)*8 + ((32-BitsInCurWord) & 31);
+    return (NextChar-FirstChar)*CHAR_BIT + ((32-BitsInCurWord) & 31);
   }
 
   /// JumpToBit - Reset the stream to the specified bit number.
index 8e99ee7e29f2e822ae6bcf616cc5921337ba40e3..c75d5947b962904ceac6bb49d8abf9d634af8d84 100644 (file)
@@ -25,6 +25,7 @@
 #include "llvm/Support/Allocator.h"
 #include <iosfwd>
 #include <cassert>
+#include <climits>
 
 namespace llvm {
   class MachineInstr;
@@ -115,7 +116,7 @@ namespace llvm {
     LiveInterval(unsigned Reg, float Weight, bool IsSS = false)
       : reg(Reg), weight(Weight), preference(0)  {
       if (IsSS)
-        reg = reg | (1U << (sizeof(unsigned)*8-1));
+        reg = reg | (1U << (sizeof(unsigned)*CHAR_BIT-1));
     }
 
     typedef Ranges::iterator iterator;
@@ -159,14 +160,14 @@ namespace llvm {
     /// isStackSlot - Return true if this is a stack slot interval.
     ///
     bool isStackSlot() const {
-      return reg & (1U << (sizeof(unsigned)*8-1));
+      return reg & (1U << (sizeof(unsigned)*CHAR_BIT-1));
     }
 
     /// getStackSlotIndex - Return stack slot index if this is a stack slot
     /// interval.
     int getStackSlotIndex() const {
       assert(isStackSlot() && "Interval is not a stack slot interval!");
-      return reg & ~(1U << (sizeof(unsigned)*8-1));
+      return reg & ~(1U << (sizeof(unsigned)*CHAR_BIT-1));
     }
 
     bool hasAtLeastOneValue() const { return !valnos.empty(); }
index d5bd25c47b73eebd72d51494c1d627b249acc711..99996cf28fb1e21df2daa28f26524842f89e96d3 100644 (file)
@@ -17,6 +17,7 @@
 #define LLVM_CODEGEN_MACHINECONSTANTPOOL_H
 
 #include <cassert>
+#include <climits>
 #include <vector>
 
 namespace llvm {
@@ -81,7 +82,7 @@ public:
   MachineConstantPoolEntry(MachineConstantPoolValue *V, unsigned A)
     : Alignment(A) {
     Val.MachineCPVal = V; 
-    Alignment |= 1 << (sizeof(unsigned)*8-1);
+    Alignment |= 1 << (sizeof(unsigned)*CHAR_BIT-1);
   }
 
   bool isMachineConstantPoolEntry() const {
@@ -89,7 +90,7 @@ public:
   }
 
   int getAlignment() const { 
-    return Alignment & ~(1 << (sizeof(unsigned)*8-1));
+    return Alignment & ~(1 << (sizeof(unsigned)*CHAR_BIT-1));
   }
 
   const Type *getType() const;
index 047e61274a641fb3dfc132dc6b87b97b971701a0..6cea5d6d7af067f8bd5f0043a06849631ac28159 100644 (file)
@@ -32,6 +32,7 @@
 #include "llvm/Support/DataTypes.h"
 #include "llvm/CodeGen/DebugLoc.h"
 #include <cassert>
+#include <climits>
 
 namespace llvm {
 
@@ -1864,7 +1865,7 @@ protected:
              getSDVTList(VT)), Offset(o), Alignment(0) {
     assert((int)Offset >= 0 && "Offset is too large");
     Val.MachineCPVal = v;
-    Offset |= 1 << (sizeof(unsigned)*8-1);
+    Offset |= 1 << (sizeof(unsigned)*CHAR_BIT-1);
   }
   ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
                      MVT VT, int o, unsigned Align)
@@ -1873,7 +1874,7 @@ protected:
              getSDVTList(VT)), Offset(o), Alignment(Align) {
     assert((int)Offset >= 0 && "Offset is too large");
     Val.MachineCPVal = v;
-    Offset |= 1 << (sizeof(unsigned)*8-1);
+    Offset |= 1 << (sizeof(unsigned)*CHAR_BIT-1);
   }
 public:
 
@@ -1892,7 +1893,7 @@ public:
   }
 
   int getOffset() const {
-    return Offset & ~(1 << (sizeof(unsigned)*8-1));
+    return Offset & ~(1 << (sizeof(unsigned)*CHAR_BIT-1));
   }
 
   // Return the alignment of this constant pool object, which is either 0 (for
index e45ab217a42e7455e3e334b809f54702924aa8c5..6b05e602eff1ab85bdd4405953979a700d27e251 100644 (file)
@@ -25,6 +25,7 @@
 #include "llvm/Support/Compiler.h"
 #include "llvm/ADT/SmallVector.h"
 #include <cassert>
+#include <climits>
 #include <cstdarg>
 #include <string>
 #include <utility>
@@ -1109,7 +1110,7 @@ class bits_storage {
   template<class T>
   static unsigned Bit(const T &V) {
     unsigned BitPos = reinterpret_cast<unsigned>(V);
-    assert(BitPos < sizeof(unsigned) * 8 &&
+    assert(BitPos < sizeof(unsigned) * CHAR_BIT &&
           "enum exceeds width of bit vector!");
     return 1 << BitPos;
   }
@@ -1150,7 +1151,7 @@ class bits_storage<DataType, bool> {
   template<class T>
   static unsigned Bit(const T &V) {
     unsigned BitPos = reinterpret_cast<unsigned>(V);
-    assert(BitPos < sizeof(unsigned) * 8 &&
+    assert(BitPos < sizeof(unsigned) * CHAR_BIT &&
           "enum exceeds width of bit vector!");
     return 1 << BitPos;
   }
index f10360903f4e90e3dd697d4b860140f29bb1b6cb..a79bcc2803129c41529ed56a71bf2326d9c7e0ab 100644 (file)
@@ -1092,10 +1092,10 @@ GenericValue Interpreter::executeBitCastInst(Value *SrcVal, const Type *DstTy,
     Dest.PointerVal = Src.PointerVal;
   } else if (DstTy->isInteger()) {
     if (SrcTy == Type::FloatTy) {
-      Dest.IntVal.zext(sizeof(Src.FloatVal) * 8);
+      Dest.IntVal.zext(sizeof(Src.FloatVal) * CHAR_BIT);
       Dest.IntVal.floatToBits(Src.FloatVal);
     } else if (SrcTy == Type::DoubleTy) {
-      Dest.IntVal.zext(sizeof(Src.DoubleVal) * 8);
+      Dest.IntVal.zext(sizeof(Src.DoubleVal) * CHAR_BIT);
       Dest.IntVal.doubleToBits(Src.DoubleVal);
     } else if (SrcTy->isInteger()) {
       Dest.IntVal = Src.IntVal;
index b2bf8529d45667b6ffbed5a513b6f55ecc4ffd01..2819b6d4653bea7c17a7ffb2e249f6f80f465a0f 100644 (file)
@@ -18,6 +18,7 @@
 #include <map>
 #include <vector>
 #include <cassert>
+#include <climits>
 #include <cstdio>
 #include <cstdlib>
 #include <cstring>
@@ -48,7 +49,7 @@ namespace {
     
     /// BlockSize - This is the size in bytes of this memory block,
     /// including this header.
-    uintptr_t BlockSize : (sizeof(intptr_t)*8 - 2);
+    uintptr_t BlockSize : (sizeof(intptr_t)*CHAR_BIT - 2);
     
 
     /// getBlockAfter - Return the memory block immediately after this one.
index ae9b066684cfb93335a69b6c07264ce64a780053..1cabe0f03e7136044646f70fad34637a7a00dc7a 100644 (file)
@@ -1631,7 +1631,7 @@ void APInt::divide(const APInt LHS, unsigned lhsWords,
   // can't use 64-bit operands here because we don't have native results of 
   // 128-bits. Furthermore, casting the 64-bit values to 32-bit values won't 
   // work on large-endian machines.
-  uint64_t mask = ~0ull >> (sizeof(unsigned)*8);
+  uint64_t mask = ~0ull >> (sizeof(unsigned)*CHAR_BIT);
   unsigned n = rhsWords * 2;
   unsigned m = (lhsWords * 2) - n;
 
@@ -1661,7 +1661,7 @@ void APInt::divide(const APInt LHS, unsigned lhsWords,
   for (unsigned i = 0; i < lhsWords; ++i) {
     uint64_t tmp = (LHS.getNumWords() == 1 ? LHS.VAL : LHS.pVal[i]);
     U[i * 2] = (unsigned)(tmp & mask);
-    U[i * 2 + 1] = (unsigned)(tmp >> (sizeof(unsigned)*8));
+    U[i * 2 + 1] = (unsigned)(tmp >> (sizeof(unsigned)*CHAR_BIT));
   }
   U[m+n] = 0; // this extra word is for "spill" in the Knuth algorithm.
 
@@ -1670,7 +1670,7 @@ void APInt::divide(const APInt LHS, unsigned lhsWords,
   for (unsigned i = 0; i < rhsWords; ++i) {
     uint64_t tmp = (RHS.getNumWords() == 1 ? RHS.VAL : RHS.pVal[i]);
     V[i * 2] = (unsigned)(tmp & mask);
-    V[i * 2 + 1] = (unsigned)(tmp >> (sizeof(unsigned)*8));
+    V[i * 2 + 1] = (unsigned)(tmp >> (sizeof(unsigned)*CHAR_BIT));
   }
 
   // initialize the quotient and remainder
index c306298f31c0f61ba23198933ced9ddbc75424b1..c07e6d5645cc0360c04c59c7afe72cb475c7c436 100644 (file)
@@ -2909,7 +2909,7 @@ SPUTargetLowering::computeMaskedBitsForTargetNode(const SDValue Op,
                                                   const SelectionDAG &DAG,
                                                   unsigned Depth ) const {
 #if 0
-  const uint64_t uint64_sizebits = sizeof(uint64_t) * 8;
+  const uint64_t uint64_sizebits = sizeof(uint64_t) * CHAR_BIT;
 
   switch (Op.getOpcode()) {
   default:
index 623bcaeae7b525f407ec42cd10e2b5e6848dcdc2..52a198ae790f8fe81d0dee1f522d6c56dc1a014a 100644 (file)
@@ -425,7 +425,7 @@ static int AnalyzeBitcode() {
   
   if (Dump) std::cerr << "\n\n";
   
-  uint64_t BufferSizeBits = Buffer->getBufferSize()*8;
+  uint64_t BufferSizeBits = Buffer->getBufferSize()*CHAR_BIT;
   // Print a summary of the read file.
   std::cerr << "Summary of " << InputFilename << ":\n";
   std::cerr << "         Total size: ";