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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 return ConstPool->Doubles.getOrAdd(this, IceType_f64, ConstantDouble); | 208 return ConstPool->Doubles.getOrAdd(this, IceType_f64, ConstantDouble); |
185 } | 209 } |
186 | 210 |
187 Constant *GlobalContext::getConstantSym(Type Ty, int64_t Offset, | 211 Constant *GlobalContext::getConstantSym(Type Ty, int64_t Offset, |
188 const IceString &Name, | 212 const IceString &Name, |
189 bool SuppressMangling) { | 213 bool SuppressMangling) { |
190 return ConstPool->Relocatables.getOrAdd( | 214 return ConstPool->Relocatables.getOrAdd( |
191 this, Ty, RelocatableTuple(Offset, Name, SuppressMangling)); | 215 this, Ty, RelocatableTuple(Offset, Name, SuppressMangling)); |
192 } | 216 } |
193 | 217 |
| 218 Constant *GlobalContext::getConstantUndef(Type Ty) { |
| 219 return ConstPool->Undefs.getOrAdd(this, Ty); |
| 220 } |
| 221 |
| 222 Constant *GlobalContext::getConstantZero(Type Ty) { |
| 223 switch (Ty) { |
| 224 case IceType_i1: |
| 225 case IceType_i8: |
| 226 case IceType_i16: |
| 227 case IceType_i32: |
| 228 case IceType_i64: |
| 229 return getConstantInt(Ty, 0); |
| 230 case IceType_f32: |
| 231 return getConstantFloat(0); |
| 232 case IceType_f64: |
| 233 return getConstantDouble(0); |
| 234 case IceType_void: |
| 235 case IceType_NUM: |
| 236 break; |
| 237 } |
| 238 llvm_unreachable("Unknown type"); |
| 239 } |
| 240 |
194 ConstantList GlobalContext::getConstantPool(Type Ty) const { | 241 ConstantList GlobalContext::getConstantPool(Type Ty) const { |
195 switch (Ty) { | 242 switch (Ty) { |
196 case IceType_i1: | 243 case IceType_i1: |
197 case IceType_i8: | 244 case IceType_i8: |
198 case IceType_i16: | 245 case IceType_i16: |
199 case IceType_i32: | 246 case IceType_i32: |
200 case IceType_i64: | 247 case IceType_i64: |
201 return ConstPool->Integers.getConstantPool(); | 248 return ConstPool->Integers.getConstantPool(); |
202 case IceType_f32: | 249 case IceType_f32: |
203 return ConstPool->Floats.getConstantPool(); | 250 return ConstPool->Floats.getConstantPool(); |
204 case IceType_f64: | 251 case IceType_f64: |
205 return ConstPool->Doubles.getConstantPool(); | 252 return ConstPool->Doubles.getConstantPool(); |
206 case IceType_void: | 253 case IceType_void: |
207 case IceType_NUM: | 254 case IceType_NUM: |
208 break; | 255 break; |
209 } | 256 } |
210 llvm_unreachable("Unknown type"); | 257 llvm_unreachable("Unknown type"); |
211 } | 258 } |
212 | 259 |
213 void Timer::printElapsedUs(GlobalContext *Ctx, const IceString &Tag) const { | 260 void Timer::printElapsedUs(GlobalContext *Ctx, const IceString &Tag) const { |
214 if (Ctx->isVerbose(IceV_Timing)) { | 261 if (Ctx->isVerbose(IceV_Timing)) { |
215 // Prefixing with '#' allows timing strings to be included | 262 // Prefixing with '#' allows timing strings to be included |
216 // without error in textual assembly output. | 263 // without error in textual assembly output. |
217 Ctx->getStrDump() << "# " << getElapsedUs() << " usec " << Tag << "\n"; | 264 Ctx->getStrDump() << "# " << getElapsedUs() << " usec " << Tag << "\n"; |
218 } | 265 } |
219 } | 266 } |
220 | 267 |
221 } // end of namespace Ice | 268 } // end of namespace Ice |
OLD | NEW |