llvm.org GIT mirror llvm / 9af1887
Don't have APInt.cpp depend upon DerivedTypes.h. This helps with splitting the Support libraries separately into their own module. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44852 91177308-0d34-0410-b5e6-96231b3b80d8 Reid Spencer 12 years ago
1 changed file(s) with 23 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
1313
1414 #define DEBUG_TYPE "apint"
1515 #include "llvm/ADT/APInt.h"
16 #include "llvm/DerivedTypes.h"
1716 #include "llvm/Support/Debug.h"
1817 #include "llvm/Support/MathExtras.h"
1918 #include
2423
2524 using namespace llvm;
2625
26
27 /// This enumeration just provides for internal constants used in this
28 /// translation unit.
29 enum {
30 MIN_INT_BITS = 1, ///< Minimum number of bits that can be specified
31 ///< Note that this must remain synchronized with IntegerType::MIN_INT_BITS
32 MAX_INT_BITS = (1<<23)-1 ///< Maximum number of bits that can be specified
33 ///< Note that this must remain synchronized with IntegerType::MAX_INT_BITS
34 };
35
2736 /// A utility function for allocating memory, checking for allocation failures,
2837 /// and ensuring the contents are zeroed.
2938 inline static uint64_t* getClearedMemory(uint32_t numWords) {
4352
4453 APInt::APInt(uint32_t numBits, uint64_t val, bool isSigned)
4554 : BitWidth(numBits), VAL(0) {
46 assert(BitWidth >= IntegerType::MIN_INT_BITS && "bitwidth too small");
47 assert(BitWidth <= IntegerType::MAX_INT_BITS && "bitwidth too large");
55 assert(BitWidth >= MIN_INT_BITS && "bitwidth too small");
56 assert(BitWidth <= MAX_INT_BITS && "bitwidth too large");
4857 if (isSingleWord())
4958 VAL = val;
5059 else {
5968
6069 APInt::APInt(uint32_t numBits, uint32_t numWords, const uint64_t bigVal[])
6170 : BitWidth(numBits), VAL(0) {
62 assert(BitWidth >= IntegerType::MIN_INT_BITS && "bitwidth too small");
63 assert(BitWidth <= IntegerType::MAX_INT_BITS && "bitwidth too large");
71 assert(BitWidth >= MIN_INT_BITS && "bitwidth too small");
72 assert(BitWidth <= MAX_INT_BITS && "bitwidth too large");
6473 assert(bigVal && "Null pointer detected!");
6574 if (isSingleWord())
6675 VAL = bigVal[0];
7988 APInt::APInt(uint32_t numbits, const char StrStart[], uint32_t slen,
8089 uint8_t radix)
8190 : BitWidth(numbits), VAL(0) {
82 assert(BitWidth >= IntegerType::MIN_INT_BITS && "bitwidth too small");
83 assert(BitWidth <= IntegerType::MAX_INT_BITS && "bitwidth too large");
91 assert(BitWidth >= MIN_INT_BITS && "bitwidth too small");
92 assert(BitWidth <= MAX_INT_BITS && "bitwidth too large");
8493 fromString(numbits, StrStart, slen, radix);
8594 }
8695
8796 APInt::APInt(uint32_t numbits, const std::string& Val, uint8_t radix)
8897 : BitWidth(numbits), VAL(0) {
89 assert(BitWidth >= IntegerType::MIN_INT_BITS && "bitwidth too small");
90 assert(BitWidth <= IntegerType::MAX_INT_BITS && "bitwidth too large");
98 assert(BitWidth >= MIN_INT_BITS && "bitwidth too small");
99 assert(BitWidth <= MAX_INT_BITS && "bitwidth too large");
91100 assert(!Val.empty() && "String empty?");
92101 fromString(numbits, Val.c_str(), Val.size(), radix);
93102 }
94103
95104 APInt::APInt(const APInt& that)
96105 : BitWidth(that.BitWidth), VAL(0) {
97 assert(BitWidth >= IntegerType::MIN_INT_BITS && "bitwidth too small");
98 assert(BitWidth <= IntegerType::MAX_INT_BITS && "bitwidth too large");
106 assert(BitWidth >= MIN_INT_BITS && "bitwidth too small");
107 assert(BitWidth <= MAX_INT_BITS && "bitwidth too large");
99108 if (isSingleWord())
100109 VAL = that.VAL;
101110 else {
942951 // Truncate to new width.
943952 APInt &APInt::trunc(uint32_t width) {
944953 assert(width < BitWidth && "Invalid APInt Truncate request");
945 assert(width >= IntegerType::MIN_INT_BITS && "Can't truncate to 0 bits");
954 assert(width >= MIN_INT_BITS && "Can't truncate to 0 bits");
946955 uint32_t wordsBefore = getNumWords();
947956 BitWidth = width;
948957 uint32_t wordsAfter = getNumWords();
965974 // Sign extend to a new width.
966975 APInt &APInt::sext(uint32_t width) {
967976 assert(width > BitWidth && "Invalid APInt SignExtend request");
968 assert(width <= IntegerType::MAX_INT_BITS && "Too many bits");
977 assert(width <= MAX_INT_BITS && "Too many bits");
969978 // If the sign bit isn't set, this is the same as zext.
970979 if (!isNegative()) {
971980 zext(width);
10131022 // Zero extend to a new width.
10141023 APInt &APInt::zext(uint32_t width) {
10151024 assert(width > BitWidth && "Invalid APInt ZeroExtend request");
1016 assert(width <= IntegerType::MAX_INT_BITS && "Too many bits");
1025 assert(width <= MAX_INT_BITS && "Too many bits");
10171026 uint32_t wordsBefore = getNumWords();
10181027 BitWidth = width;
10191028 uint32_t wordsAfter = getNumWords();