Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 1 | //===- subzero/src/IceGlobalContext.cpp - Global context defs ---*- C++ -*-===// |
| 2 | // |
| 3 | // The Subzero Code Generator |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines aspects of the compilation that persist across |
| 11 | // multiple functions. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Jim Stichnoth | 217dc08 | 2014-07-11 14:06:55 -0700 | [diff] [blame] | 15 | #include <ctype.h> // isdigit(), isupper() |
Jan Voung | 839c4ce | 2014-07-28 15:19:43 -0700 | [diff] [blame] | 16 | #include <locale> // locale |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 17 | |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 18 | #include "IceDefs.h" |
| 19 | #include "IceTypes.h" |
| 20 | #include "IceCfg.h" |
Jim Stichnoth | 989a703 | 2014-08-08 10:13:44 -0700 | [diff] [blame] | 21 | #include "IceClFlags.h" |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 22 | #include "IceGlobalContext.h" |
| 23 | #include "IceOperand.h" |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 24 | #include "IceTargetLowering.h" |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 25 | |
| 26 | namespace Ice { |
| 27 | |
| 28 | // TypePool maps constants of type KeyType (e.g. float) to pointers to |
| 29 | // type ValueType (e.g. ConstantFloat). KeyType values are compared |
| 30 | // using memcmp() because of potential NaN values in KeyType values. |
| 31 | // KeyTypeHasFP indicates whether KeyType is a floating-point type |
| 32 | // whose values need to be compared using memcmp() for NaN |
| 33 | // correctness. TODO: use std::is_floating_point<KeyType> instead of |
| 34 | // KeyTypeHasFP with C++11. |
| 35 | template <typename KeyType, typename ValueType, bool KeyTypeHasFP = false> |
| 36 | class TypePool { |
| 37 | TypePool(const TypePool &) LLVM_DELETED_FUNCTION; |
| 38 | TypePool &operator=(const TypePool &) LLVM_DELETED_FUNCTION; |
| 39 | |
| 40 | public: |
Jim Stichnoth | f61d5b2 | 2014-05-23 13:31:24 -0700 | [diff] [blame] | 41 | TypePool() : NextPoolID(0) {} |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 42 | ValueType *getOrAdd(GlobalContext *Ctx, Type Ty, KeyType Key) { |
| 43 | TupleType TupleKey = std::make_pair(Ty, Key); |
| 44 | typename ContainerType::const_iterator Iter = Pool.find(TupleKey); |
| 45 | if (Iter != Pool.end()) |
| 46 | return Iter->second; |
Jim Stichnoth | f61d5b2 | 2014-05-23 13:31:24 -0700 | [diff] [blame] | 47 | ValueType *Result = ValueType::create(Ctx, Ty, Key, NextPoolID++); |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 48 | Pool[TupleKey] = Result; |
| 49 | return Result; |
| 50 | } |
Jim Stichnoth | f61d5b2 | 2014-05-23 13:31:24 -0700 | [diff] [blame] | 51 | ConstantList getConstantPool() const { |
| 52 | ConstantList Constants; |
| 53 | Constants.reserve(Pool.size()); |
| 54 | // TODO: replace the loop with std::transform + lambdas. |
| 55 | for (typename ContainerType::const_iterator I = Pool.begin(), |
| 56 | E = Pool.end(); |
| 57 | I != E; ++I) { |
| 58 | Constants.push_back(I->second); |
| 59 | } |
| 60 | return Constants; |
| 61 | } |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 62 | |
| 63 | private: |
| 64 | typedef std::pair<Type, KeyType> TupleType; |
| 65 | struct TupleCompare { |
Jan Voung | 839c4ce | 2014-07-28 15:19:43 -0700 | [diff] [blame] | 66 | bool operator()(const TupleType &A, const TupleType &B) const { |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 67 | if (A.first != B.first) |
| 68 | return A.first < B.first; |
| 69 | if (KeyTypeHasFP) |
| 70 | return memcmp(&A.second, &B.second, sizeof(KeyType)) < 0; |
| 71 | return A.second < B.second; |
| 72 | } |
| 73 | }; |
| 74 | typedef std::map<const TupleType, ValueType *, TupleCompare> ContainerType; |
| 75 | ContainerType Pool; |
Jim Stichnoth | f61d5b2 | 2014-05-23 13:31:24 -0700 | [diff] [blame] | 76 | uint32_t NextPoolID; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 77 | }; |
| 78 | |
Matt Wala | d8f4a7d | 2014-06-18 09:55:03 -0700 | [diff] [blame] | 79 | // UndefPool maps ICE types to the corresponding ConstantUndef values. |
| 80 | class UndefPool { |
| 81 | UndefPool(const UndefPool &) LLVM_DELETED_FUNCTION; |
| 82 | UndefPool &operator=(const UndefPool &) LLVM_DELETED_FUNCTION; |
| 83 | |
| 84 | public: |
| 85 | UndefPool() : NextPoolID(0) {} |
| 86 | |
| 87 | ConstantUndef *getOrAdd(GlobalContext *Ctx, Type Ty) { |
| 88 | ContainerType::iterator I = Pool.find(Ty); |
| 89 | if (I != Pool.end()) |
| 90 | return I->second; |
| 91 | ConstantUndef *Undef = ConstantUndef::create(Ctx, Ty, NextPoolID++); |
| 92 | Pool[Ty] = Undef; |
| 93 | return Undef; |
| 94 | } |
| 95 | |
| 96 | private: |
| 97 | uint32_t NextPoolID; |
| 98 | typedef std::map<Type, ConstantUndef *> ContainerType; |
| 99 | ContainerType Pool; |
| 100 | }; |
| 101 | |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 102 | // The global constant pool bundles individual pools of each type of |
| 103 | // interest. |
| 104 | class ConstantPool { |
| 105 | ConstantPool(const ConstantPool &) LLVM_DELETED_FUNCTION; |
| 106 | ConstantPool &operator=(const ConstantPool &) LLVM_DELETED_FUNCTION; |
| 107 | |
| 108 | public: |
| 109 | ConstantPool() {} |
| 110 | TypePool<float, ConstantFloat, true> Floats; |
| 111 | TypePool<double, ConstantDouble, true> Doubles; |
Jan Voung | bc00463 | 2014-09-16 15:09:10 -0700 | [diff] [blame^] | 112 | TypePool<uint32_t, ConstantInteger32> Integers32; |
| 113 | TypePool<uint64_t, ConstantInteger64> Integers64; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 114 | TypePool<RelocatableTuple, ConstantRelocatable> Relocatables; |
Matt Wala | d8f4a7d | 2014-06-18 09:55:03 -0700 | [diff] [blame] | 115 | UndefPool Undefs; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 116 | }; |
| 117 | |
| 118 | GlobalContext::GlobalContext(llvm::raw_ostream *OsDump, |
| 119 | llvm::raw_ostream *OsEmit, VerboseMask Mask, |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 120 | TargetArch Arch, OptLevel Opt, |
Jim Stichnoth | 989a703 | 2014-08-08 10:13:44 -0700 | [diff] [blame] | 121 | IceString TestPrefix, const ClFlags &Flags) |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 122 | : StrDump(OsDump), StrEmit(OsEmit), VMask(Mask), |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 123 | ConstPool(new ConstantPool()), Arch(Arch), Opt(Opt), |
Matt Wala | 1bd2fce | 2014-08-08 14:02:09 -0700 | [diff] [blame] | 124 | TestPrefix(TestPrefix), Flags(Flags), HasEmittedFirstMethod(false), |
| 125 | RNG("") {} |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 126 | |
Jim Stichnoth | 217dc08 | 2014-07-11 14:06:55 -0700 | [diff] [blame] | 127 | // Scan a string for S[0-9A-Z]*_ patterns and replace them with |
| 128 | // S<num>_ where <num> is the next base-36 value. If a type name |
| 129 | // legitimately contains that pattern, then the substitution will be |
| 130 | // made in error and most likely the link will fail. In this case, |
| 131 | // the test classes can be rewritten not to use that pattern, which is |
| 132 | // much simpler and more reliable than implementing a full demangling |
| 133 | // parser. Another substitution-in-error may occur if a type |
| 134 | // identifier ends with the pattern S[0-9A-Z]*, because an immediately |
| 135 | // following substitution string like "S1_" or "PS1_" may be combined |
| 136 | // with the previous type. |
| 137 | void GlobalContext::incrementSubstitutions(ManglerVector &OldName) const { |
| 138 | const std::locale CLocale("C"); |
| 139 | // Provide extra space in case the length of <num> increases. |
| 140 | ManglerVector NewName(OldName.size() * 2); |
| 141 | size_t OldPos = 0; |
| 142 | size_t NewPos = 0; |
| 143 | size_t OldLen = OldName.size(); |
| 144 | for (; OldPos < OldLen; ++OldPos, ++NewPos) { |
| 145 | if (OldName[OldPos] == '\0') |
| 146 | break; |
| 147 | if (OldName[OldPos] == 'S') { |
| 148 | // Search forward until we find _ or invalid character (including \0). |
| 149 | bool AllZs = true; |
| 150 | bool Found = false; |
| 151 | size_t Last; |
| 152 | for (Last = OldPos + 1; Last < OldLen; ++Last) { |
| 153 | char Ch = OldName[Last]; |
| 154 | if (Ch == '_') { |
| 155 | Found = true; |
| 156 | break; |
| 157 | } else if (std::isdigit(Ch) || std::isupper(Ch, CLocale)) { |
| 158 | if (Ch != 'Z') |
| 159 | AllZs = false; |
| 160 | } else { |
| 161 | // Invalid character, stop searching. |
| 162 | break; |
| 163 | } |
| 164 | } |
| 165 | if (Found) { |
| 166 | NewName[NewPos++] = OldName[OldPos++]; // 'S' |
| 167 | size_t Length = Last - OldPos; |
| 168 | // NewPos and OldPos point just past the 'S'. |
| 169 | assert(NewName[NewPos - 1] == 'S'); |
| 170 | assert(OldName[OldPos - 1] == 'S'); |
| 171 | assert(OldName[OldPos + Length] == '_'); |
| 172 | if (AllZs) { |
Jim Stichnoth | 78b4c0b | 2014-07-11 15:29:23 -0700 | [diff] [blame] | 173 | // Replace N 'Z' characters with a '0' (if N=0) or '1' (if |
| 174 | // N>0) followed by N '0' characters. |
| 175 | NewName[NewPos++] = (Length ? '1' : '0'); |
| 176 | for (size_t i = 0; i < Length; ++i) { |
Jim Stichnoth | 217dc08 | 2014-07-11 14:06:55 -0700 | [diff] [blame] | 177 | NewName[NewPos++] = '0'; |
| 178 | } |
| 179 | } else { |
| 180 | // Iterate right-to-left and increment the base-36 number. |
| 181 | bool Carry = true; |
| 182 | for (size_t i = 0; i < Length; ++i) { |
| 183 | size_t Offset = Length - 1 - i; |
| 184 | char Ch = OldName[OldPos + Offset]; |
| 185 | if (Carry) { |
| 186 | Carry = false; |
| 187 | switch (Ch) { |
| 188 | case '9': |
| 189 | Ch = 'A'; |
| 190 | break; |
| 191 | case 'Z': |
| 192 | Ch = '0'; |
| 193 | Carry = true; |
| 194 | break; |
| 195 | default: |
| 196 | ++Ch; |
| 197 | break; |
| 198 | } |
| 199 | } |
| 200 | NewName[NewPos + Offset] = Ch; |
| 201 | } |
| 202 | NewPos += Length; |
| 203 | } |
| 204 | OldPos = Last; |
| 205 | // Fall through and let the '_' be copied across. |
| 206 | } |
| 207 | } |
| 208 | NewName[NewPos] = OldName[OldPos]; |
| 209 | } |
| 210 | assert(NewName[NewPos] == '\0'); |
| 211 | OldName = NewName; |
| 212 | } |
| 213 | |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 214 | // In this context, name mangling means to rewrite a symbol using a |
| 215 | // given prefix. For a C++ symbol, nest the original symbol inside |
| 216 | // the "prefix" namespace. For other symbols, just prepend the |
| 217 | // prefix. |
| 218 | IceString GlobalContext::mangleName(const IceString &Name) const { |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 219 | // An already-nested name like foo::bar() gets pushed down one |
| 220 | // level, making it equivalent to Prefix::foo::bar(). |
| 221 | // _ZN3foo3barExyz ==> _ZN6Prefix3foo3barExyz |
| 222 | // A non-nested but mangled name like bar() gets nested, making it |
| 223 | // equivalent to Prefix::bar(). |
| 224 | // _Z3barxyz ==> ZN6Prefix3barExyz |
| 225 | // An unmangled, extern "C" style name, gets a simple prefix: |
| 226 | // bar ==> Prefixbar |
| 227 | if (getTestPrefix().empty()) |
| 228 | return Name; |
| 229 | |
| 230 | unsigned PrefixLength = getTestPrefix().length(); |
Jim Stichnoth | 217dc08 | 2014-07-11 14:06:55 -0700 | [diff] [blame] | 231 | ManglerVector NameBase(1 + Name.length()); |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 232 | const size_t BufLen = 30 + Name.length() + PrefixLength; |
Jim Stichnoth | 217dc08 | 2014-07-11 14:06:55 -0700 | [diff] [blame] | 233 | ManglerVector NewName(BufLen); |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 234 | uint32_t BaseLength = 0; // using uint32_t due to sscanf format string |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 235 | |
Derek Schuff | 44712d1 | 2014-06-17 14:34:34 -0700 | [diff] [blame] | 236 | int ItemsParsed = sscanf(Name.c_str(), "_ZN%s", NameBase.data()); |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 237 | if (ItemsParsed == 1) { |
| 238 | // Transform _ZN3foo3barExyz ==> _ZN6Prefix3foo3barExyz |
| 239 | // (splice in "6Prefix") ^^^^^^^ |
Derek Schuff | 44712d1 | 2014-06-17 14:34:34 -0700 | [diff] [blame] | 240 | snprintf(NewName.data(), BufLen, "_ZN%u%s%s", PrefixLength, |
| 241 | getTestPrefix().c_str(), NameBase.data()); |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 242 | // We ignore the snprintf return value (here and below). If we |
| 243 | // somehow miscalculated the output buffer length, the output will |
| 244 | // be truncated, but it will be truncated consistently for all |
| 245 | // mangleName() calls on the same input string. |
Jim Stichnoth | 217dc08 | 2014-07-11 14:06:55 -0700 | [diff] [blame] | 246 | incrementSubstitutions(NewName); |
Derek Schuff | 44712d1 | 2014-06-17 14:34:34 -0700 | [diff] [blame] | 247 | return NewName.data(); |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 248 | } |
| 249 | |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 250 | // Artificially limit BaseLength to 9 digits (less than 1 billion) |
| 251 | // because sscanf behavior is undefined on integer overflow. If |
| 252 | // there are more than 9 digits (which we test by looking at the |
| 253 | // beginning of NameBase), then we consider this a failure to parse |
| 254 | // a namespace mangling, and fall back to the simple prefixing. |
Derek Schuff | 44712d1 | 2014-06-17 14:34:34 -0700 | [diff] [blame] | 255 | ItemsParsed = sscanf(Name.c_str(), "_Z%9u%s", &BaseLength, NameBase.data()); |
| 256 | if (ItemsParsed == 2 && BaseLength <= strlen(NameBase.data()) && |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 257 | !isdigit(NameBase[0])) { |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 258 | // Transform _Z3barxyz ==> _ZN6Prefix3barExyz |
| 259 | // ^^^^^^^^ ^ |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 260 | // (splice in "N6Prefix", and insert "E" after "3bar") |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 261 | // But an "I" after the identifier indicates a template argument |
| 262 | // list terminated with "E"; insert the new "E" before/after the |
| 263 | // old "E". E.g.: |
| 264 | // Transform _Z3barIabcExyz ==> _ZN6Prefix3barIabcEExyz |
| 265 | // ^^^^^^^^ ^ |
| 266 | // (splice in "N6Prefix", and insert "E" after "3barIabcE") |
Jim Stichnoth | 217dc08 | 2014-07-11 14:06:55 -0700 | [diff] [blame] | 267 | ManglerVector OrigName(Name.length()); |
| 268 | ManglerVector OrigSuffix(Name.length()); |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 269 | uint32_t ActualBaseLength = BaseLength; |
| 270 | if (NameBase[ActualBaseLength] == 'I') { |
| 271 | ++ActualBaseLength; |
| 272 | while (NameBase[ActualBaseLength] != 'E' && |
| 273 | NameBase[ActualBaseLength] != '\0') |
| 274 | ++ActualBaseLength; |
| 275 | } |
Derek Schuff | 44712d1 | 2014-06-17 14:34:34 -0700 | [diff] [blame] | 276 | strncpy(OrigName.data(), NameBase.data(), ActualBaseLength); |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 277 | OrigName[ActualBaseLength] = '\0'; |
Derek Schuff | 44712d1 | 2014-06-17 14:34:34 -0700 | [diff] [blame] | 278 | strcpy(OrigSuffix.data(), NameBase.data() + ActualBaseLength); |
| 279 | snprintf(NewName.data(), BufLen, "_ZN%u%s%u%sE%s", PrefixLength, |
| 280 | getTestPrefix().c_str(), BaseLength, OrigName.data(), |
| 281 | OrigSuffix.data()); |
Jim Stichnoth | 217dc08 | 2014-07-11 14:06:55 -0700 | [diff] [blame] | 282 | incrementSubstitutions(NewName); |
Derek Schuff | 44712d1 | 2014-06-17 14:34:34 -0700 | [diff] [blame] | 283 | return NewName.data(); |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | // Transform bar ==> Prefixbar |
| 287 | // ^^^^^^ |
| 288 | return getTestPrefix() + Name; |
| 289 | } |
| 290 | |
| 291 | GlobalContext::~GlobalContext() {} |
| 292 | |
Jan Voung | bc00463 | 2014-09-16 15:09:10 -0700 | [diff] [blame^] | 293 | Constant *GlobalContext::getConstantInt64(Type Ty, uint64_t ConstantInt64) { |
| 294 | assert(Ty == IceType_i64); |
| 295 | return ConstPool->Integers64.getOrAdd(this, Ty, ConstantInt64); |
| 296 | } |
| 297 | |
| 298 | Constant *GlobalContext::getConstantInt32(Type Ty, uint32_t ConstantInt32) { |
Jim Stichnoth | 3ef786f | 2014-09-08 11:19:21 -0700 | [diff] [blame] | 299 | if (Ty == IceType_i1) |
Jan Voung | bc00463 | 2014-09-16 15:09:10 -0700 | [diff] [blame^] | 300 | ConstantInt32 &= UINT32_C(1); |
| 301 | return ConstPool->Integers32.getOrAdd(this, Ty, ConstantInt32); |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | Constant *GlobalContext::getConstantFloat(float ConstantFloat) { |
| 305 | return ConstPool->Floats.getOrAdd(this, IceType_f32, ConstantFloat); |
| 306 | } |
| 307 | |
| 308 | Constant *GlobalContext::getConstantDouble(double ConstantDouble) { |
| 309 | return ConstPool->Doubles.getOrAdd(this, IceType_f64, ConstantDouble); |
| 310 | } |
| 311 | |
| 312 | Constant *GlobalContext::getConstantSym(Type Ty, int64_t Offset, |
| 313 | const IceString &Name, |
| 314 | bool SuppressMangling) { |
| 315 | return ConstPool->Relocatables.getOrAdd( |
| 316 | this, Ty, RelocatableTuple(Offset, Name, SuppressMangling)); |
| 317 | } |
| 318 | |
Matt Wala | d8f4a7d | 2014-06-18 09:55:03 -0700 | [diff] [blame] | 319 | Constant *GlobalContext::getConstantUndef(Type Ty) { |
| 320 | return ConstPool->Undefs.getOrAdd(this, Ty); |
| 321 | } |
| 322 | |
| 323 | Constant *GlobalContext::getConstantZero(Type Ty) { |
| 324 | switch (Ty) { |
| 325 | case IceType_i1: |
| 326 | case IceType_i8: |
| 327 | case IceType_i16: |
| 328 | case IceType_i32: |
Jan Voung | bc00463 | 2014-09-16 15:09:10 -0700 | [diff] [blame^] | 329 | return getConstantInt32(Ty, 0); |
Matt Wala | d8f4a7d | 2014-06-18 09:55:03 -0700 | [diff] [blame] | 330 | case IceType_i64: |
Jan Voung | bc00463 | 2014-09-16 15:09:10 -0700 | [diff] [blame^] | 331 | return getConstantInt64(Ty, 0); |
Matt Wala | d8f4a7d | 2014-06-18 09:55:03 -0700 | [diff] [blame] | 332 | case IceType_f32: |
| 333 | return getConstantFloat(0); |
| 334 | case IceType_f64: |
| 335 | return getConstantDouble(0); |
Matt Wala | 928f129 | 2014-07-07 16:50:46 -0700 | [diff] [blame] | 336 | case IceType_v4i1: |
| 337 | case IceType_v8i1: |
| 338 | case IceType_v16i1: |
| 339 | case IceType_v16i8: |
| 340 | case IceType_v8i16: |
| 341 | case IceType_v4i32: |
| 342 | case IceType_v4f32: { |
| 343 | IceString Str; |
| 344 | llvm::raw_string_ostream BaseOS(Str); |
Jim Stichnoth | 78282f6 | 2014-07-27 23:14:00 -0700 | [diff] [blame] | 345 | BaseOS << "Unsupported constant type: " << Ty; |
Matt Wala | 928f129 | 2014-07-07 16:50:46 -0700 | [diff] [blame] | 346 | llvm_unreachable(BaseOS.str().c_str()); |
| 347 | } break; |
Matt Wala | d8f4a7d | 2014-06-18 09:55:03 -0700 | [diff] [blame] | 348 | case IceType_void: |
| 349 | case IceType_NUM: |
| 350 | break; |
| 351 | } |
| 352 | llvm_unreachable("Unknown type"); |
| 353 | } |
| 354 | |
Jim Stichnoth | f61d5b2 | 2014-05-23 13:31:24 -0700 | [diff] [blame] | 355 | ConstantList GlobalContext::getConstantPool(Type Ty) const { |
| 356 | switch (Ty) { |
| 357 | case IceType_i1: |
| 358 | case IceType_i8: |
| 359 | case IceType_i16: |
| 360 | case IceType_i32: |
Jan Voung | bc00463 | 2014-09-16 15:09:10 -0700 | [diff] [blame^] | 361 | return ConstPool->Integers32.getConstantPool(); |
Jim Stichnoth | f61d5b2 | 2014-05-23 13:31:24 -0700 | [diff] [blame] | 362 | case IceType_i64: |
Jan Voung | bc00463 | 2014-09-16 15:09:10 -0700 | [diff] [blame^] | 363 | return ConstPool->Integers64.getConstantPool(); |
Jim Stichnoth | f61d5b2 | 2014-05-23 13:31:24 -0700 | [diff] [blame] | 364 | case IceType_f32: |
| 365 | return ConstPool->Floats.getConstantPool(); |
| 366 | case IceType_f64: |
| 367 | return ConstPool->Doubles.getConstantPool(); |
Matt Wala | 928f129 | 2014-07-07 16:50:46 -0700 | [diff] [blame] | 368 | case IceType_v4i1: |
| 369 | case IceType_v8i1: |
| 370 | case IceType_v16i1: |
| 371 | case IceType_v16i8: |
| 372 | case IceType_v8i16: |
| 373 | case IceType_v4i32: |
| 374 | case IceType_v4f32: { |
| 375 | IceString Str; |
| 376 | llvm::raw_string_ostream BaseOS(Str); |
Jim Stichnoth | 78282f6 | 2014-07-27 23:14:00 -0700 | [diff] [blame] | 377 | BaseOS << "Unsupported constant type: " << Ty; |
Matt Wala | 928f129 | 2014-07-07 16:50:46 -0700 | [diff] [blame] | 378 | llvm_unreachable(BaseOS.str().c_str()); |
| 379 | } break; |
Jim Stichnoth | f61d5b2 | 2014-05-23 13:31:24 -0700 | [diff] [blame] | 380 | case IceType_void: |
| 381 | case IceType_NUM: |
| 382 | break; |
| 383 | } |
| 384 | llvm_unreachable("Unknown type"); |
| 385 | } |
| 386 | |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 387 | void Timer::printElapsedUs(GlobalContext *Ctx, const IceString &Tag) const { |
| 388 | if (Ctx->isVerbose(IceV_Timing)) { |
| 389 | // Prefixing with '#' allows timing strings to be included |
| 390 | // without error in textual assembly output. |
| 391 | Ctx->getStrDump() << "# " << getElapsedUs() << " usec " << Tag << "\n"; |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | } // end of namespace Ice |