OLD | NEW |
1 //===- subzero/src/IceGlobalContext.cpp - Global context defs ---*- C++ -*-===// | 1 //===- subzero/src/IceGlobalContext.cpp - Global context defs ---*- C++ -*-===// |
2 // | 2 // |
3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
4 // | 4 // |
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 // | 9 // |
10 // This file defines aspects of the compilation that persist across | 10 // This file defines aspects of the compilation that persist across |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 if (KeyTypeHasFP) | 67 if (KeyTypeHasFP) |
68 return memcmp(&A.second, &B.second, sizeof(KeyType)) < 0; | 68 return memcmp(&A.second, &B.second, sizeof(KeyType)) < 0; |
69 return A.second < B.second; | 69 return A.second < B.second; |
70 } | 70 } |
71 }; | 71 }; |
72 typedef std::map<const TupleType, ValueType *, TupleCompare> ContainerType; | 72 typedef std::map<const TupleType, ValueType *, TupleCompare> ContainerType; |
73 ContainerType Pool; | 73 ContainerType Pool; |
74 uint32_t NextPoolID; | 74 uint32_t NextPoolID; |
75 }; | 75 }; |
76 | 76 |
| 77 // UndefPool maps ICE types to the corresponding ConstantUndef values. |
| 78 class UndefPool { |
| 79 UndefPool(const UndefPool &) LLVM_DELETED_FUNCTION; |
| 80 UndefPool &operator=(const UndefPool &) LLVM_DELETED_FUNCTION; |
| 81 |
| 82 public: |
| 83 UndefPool() : NextPoolID(0) {} |
| 84 |
| 85 ConstantUndef *getOrAdd(GlobalContext *Ctx, Type Ty) { |
| 86 ContainerType::iterator I = Pool.find(Ty); |
| 87 if (I != Pool.end()) |
| 88 return I->second; |
| 89 ConstantUndef *Undef = ConstantUndef::create(Ctx, Ty, NextPoolID++); |
| 90 Pool[Ty] = Undef; |
| 91 return Undef; |
| 92 } |
| 93 |
| 94 private: |
| 95 uint32_t NextPoolID; |
| 96 typedef std::map<Type, ConstantUndef *> ContainerType; |
| 97 ContainerType Pool; |
| 98 }; |
| 99 |
77 // The global constant pool bundles individual pools of each type of | 100 // The global constant pool bundles individual pools of each type of |
78 // interest. | 101 // interest. |
79 class ConstantPool { | 102 class ConstantPool { |
80 ConstantPool(const ConstantPool &) LLVM_DELETED_FUNCTION; | 103 ConstantPool(const ConstantPool &) LLVM_DELETED_FUNCTION; |
81 ConstantPool &operator=(const ConstantPool &) LLVM_DELETED_FUNCTION; | 104 ConstantPool &operator=(const ConstantPool &) LLVM_DELETED_FUNCTION; |
82 | 105 |
83 public: | 106 public: |
84 ConstantPool() {} | 107 ConstantPool() {} |
85 TypePool<float, ConstantFloat, true> Floats; | 108 TypePool<float, ConstantFloat, true> Floats; |
86 TypePool<double, ConstantDouble, true> Doubles; | 109 TypePool<double, ConstantDouble, true> Doubles; |
87 TypePool<uint64_t, ConstantInteger> Integers; | 110 TypePool<uint64_t, ConstantInteger> Integers; |
88 TypePool<RelocatableTuple, ConstantRelocatable> Relocatables; | 111 TypePool<RelocatableTuple, ConstantRelocatable> Relocatables; |
| 112 UndefPool Undefs; |
89 }; | 113 }; |
90 | 114 |
91 GlobalContext::GlobalContext(llvm::raw_ostream *OsDump, | 115 GlobalContext::GlobalContext(llvm::raw_ostream *OsDump, |
92 llvm::raw_ostream *OsEmit, VerboseMask Mask, | 116 llvm::raw_ostream *OsEmit, VerboseMask Mask, |
93 TargetArch Arch, OptLevel Opt, | 117 TargetArch Arch, OptLevel Opt, |
94 IceString TestPrefix) | 118 IceString TestPrefix) |
95 : StrDump(OsDump), StrEmit(OsEmit), VMask(Mask), | 119 : StrDump(OsDump), StrEmit(OsEmit), VMask(Mask), |
96 ConstPool(new ConstantPool()), Arch(Arch), Opt(Opt), | 120 ConstPool(new ConstantPool()), Arch(Arch), Opt(Opt), |
97 TestPrefix(TestPrefix), HasEmittedFirstMethod(false) {} | 121 TestPrefix(TestPrefix), HasEmittedFirstMethod(false) {} |
98 | 122 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 return ConstPool->Doubles.getOrAdd(this, IceType_f64, ConstantDouble); | 209 return ConstPool->Doubles.getOrAdd(this, IceType_f64, ConstantDouble); |
186 } | 210 } |
187 | 211 |
188 Constant *GlobalContext::getConstantSym(Type Ty, int64_t Offset, | 212 Constant *GlobalContext::getConstantSym(Type Ty, int64_t Offset, |
189 const IceString &Name, | 213 const IceString &Name, |
190 bool SuppressMangling) { | 214 bool SuppressMangling) { |
191 return ConstPool->Relocatables.getOrAdd( | 215 return ConstPool->Relocatables.getOrAdd( |
192 this, Ty, RelocatableTuple(Offset, Name, SuppressMangling)); | 216 this, Ty, RelocatableTuple(Offset, Name, SuppressMangling)); |
193 } | 217 } |
194 | 218 |
| 219 Constant *GlobalContext::getConstantUndef(Type Ty) { |
| 220 return ConstPool->Undefs.getOrAdd(this, Ty); |
| 221 } |
| 222 |
| 223 Constant *GlobalContext::getConstantZero(Type Ty) { |
| 224 switch (Ty) { |
| 225 case IceType_i1: |
| 226 case IceType_i8: |
| 227 case IceType_i16: |
| 228 case IceType_i32: |
| 229 case IceType_i64: |
| 230 return getConstantInt(Ty, 0); |
| 231 case IceType_f32: |
| 232 return getConstantFloat(0); |
| 233 case IceType_f64: |
| 234 return getConstantDouble(0); |
| 235 case IceType_void: |
| 236 case IceType_NUM: |
| 237 break; |
| 238 } |
| 239 llvm_unreachable("Unknown type"); |
| 240 } |
| 241 |
195 ConstantList GlobalContext::getConstantPool(Type Ty) const { | 242 ConstantList GlobalContext::getConstantPool(Type Ty) const { |
196 switch (Ty) { | 243 switch (Ty) { |
197 case IceType_i1: | 244 case IceType_i1: |
198 case IceType_i8: | 245 case IceType_i8: |
199 case IceType_i16: | 246 case IceType_i16: |
200 case IceType_i32: | 247 case IceType_i32: |
201 case IceType_i64: | 248 case IceType_i64: |
202 return ConstPool->Integers.getConstantPool(); | 249 return ConstPool->Integers.getConstantPool(); |
203 case IceType_f32: | 250 case IceType_f32: |
204 return ConstPool->Floats.getConstantPool(); | 251 return ConstPool->Floats.getConstantPool(); |
205 case IceType_f64: | 252 case IceType_f64: |
206 return ConstPool->Doubles.getConstantPool(); | 253 return ConstPool->Doubles.getConstantPool(); |
207 case IceType_void: | 254 case IceType_void: |
208 case IceType_NUM: | 255 case IceType_NUM: |
209 break; | 256 break; |
210 } | 257 } |
211 llvm_unreachable("Unknown type"); | 258 llvm_unreachable("Unknown type"); |
212 } | 259 } |
213 | 260 |
214 void Timer::printElapsedUs(GlobalContext *Ctx, const IceString &Tag) const { | 261 void Timer::printElapsedUs(GlobalContext *Ctx, const IceString &Tag) const { |
215 if (Ctx->isVerbose(IceV_Timing)) { | 262 if (Ctx->isVerbose(IceV_Timing)) { |
216 // Prefixing with '#' allows timing strings to be included | 263 // Prefixing with '#' allows timing strings to be included |
217 // without error in textual assembly output. | 264 // without error in textual assembly output. |
218 Ctx->getStrDump() << "# " << getElapsedUs() << " usec " << Tag << "\n"; | 265 Ctx->getStrDump() << "# " << getElapsedUs() << " usec " << Tag << "\n"; |
219 } | 266 } |
220 } | 267 } |
221 | 268 |
222 } // end of namespace Ice | 269 } // end of namespace Ice |
OLD | NEW |