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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 // The global constant pool bundles individual pools of each type of | 102 // The global constant pool bundles individual pools of each type of |
103 // interest. | 103 // interest. |
104 class ConstantPool { | 104 class ConstantPool { |
105 ConstantPool(const ConstantPool &) LLVM_DELETED_FUNCTION; | 105 ConstantPool(const ConstantPool &) LLVM_DELETED_FUNCTION; |
106 ConstantPool &operator=(const ConstantPool &) LLVM_DELETED_FUNCTION; | 106 ConstantPool &operator=(const ConstantPool &) LLVM_DELETED_FUNCTION; |
107 | 107 |
108 public: | 108 public: |
109 ConstantPool() {} | 109 ConstantPool() {} |
110 TypePool<float, ConstantFloat, true> Floats; | 110 TypePool<float, ConstantFloat, true> Floats; |
111 TypePool<double, ConstantDouble, true> Doubles; | 111 TypePool<double, ConstantDouble, true> Doubles; |
112 TypePool<uint64_t, ConstantInteger> Integers; | 112 TypePool<uint32_t, ConstantInteger32> Integers32; |
| 113 TypePool<uint64_t, ConstantInteger64> Integers64; |
113 TypePool<RelocatableTuple, ConstantRelocatable> Relocatables; | 114 TypePool<RelocatableTuple, ConstantRelocatable> Relocatables; |
114 UndefPool Undefs; | 115 UndefPool Undefs; |
115 }; | 116 }; |
116 | 117 |
117 GlobalContext::GlobalContext(llvm::raw_ostream *OsDump, | 118 GlobalContext::GlobalContext(llvm::raw_ostream *OsDump, |
118 llvm::raw_ostream *OsEmit, VerboseMask Mask, | 119 llvm::raw_ostream *OsEmit, VerboseMask Mask, |
119 TargetArch Arch, OptLevel Opt, | 120 TargetArch Arch, OptLevel Opt, |
120 IceString TestPrefix, const ClFlags &Flags) | 121 IceString TestPrefix, const ClFlags &Flags) |
121 : StrDump(OsDump), StrEmit(OsEmit), VMask(Mask), | 122 : StrDump(OsDump), StrEmit(OsEmit), VMask(Mask), |
122 ConstPool(new ConstantPool()), Arch(Arch), Opt(Opt), | 123 ConstPool(new ConstantPool()), Arch(Arch), Opt(Opt), |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 return NewName.data(); | 283 return NewName.data(); |
283 } | 284 } |
284 | 285 |
285 // Transform bar ==> Prefixbar | 286 // Transform bar ==> Prefixbar |
286 // ^^^^^^ | 287 // ^^^^^^ |
287 return getTestPrefix() + Name; | 288 return getTestPrefix() + Name; |
288 } | 289 } |
289 | 290 |
290 GlobalContext::~GlobalContext() {} | 291 GlobalContext::~GlobalContext() {} |
291 | 292 |
292 Constant *GlobalContext::getConstantInt(Type Ty, uint64_t ConstantInt64) { | 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) { |
293 if (Ty == IceType_i1) | 299 if (Ty == IceType_i1) |
294 ConstantInt64 &= UINT64_C(1); | 300 ConstantInt32 &= UINT32_C(1); |
295 return ConstPool->Integers.getOrAdd(this, Ty, ConstantInt64); | 301 return ConstPool->Integers32.getOrAdd(this, Ty, ConstantInt32); |
296 } | 302 } |
297 | 303 |
298 Constant *GlobalContext::getConstantFloat(float ConstantFloat) { | 304 Constant *GlobalContext::getConstantFloat(float ConstantFloat) { |
299 return ConstPool->Floats.getOrAdd(this, IceType_f32, ConstantFloat); | 305 return ConstPool->Floats.getOrAdd(this, IceType_f32, ConstantFloat); |
300 } | 306 } |
301 | 307 |
302 Constant *GlobalContext::getConstantDouble(double ConstantDouble) { | 308 Constant *GlobalContext::getConstantDouble(double ConstantDouble) { |
303 return ConstPool->Doubles.getOrAdd(this, IceType_f64, ConstantDouble); | 309 return ConstPool->Doubles.getOrAdd(this, IceType_f64, ConstantDouble); |
304 } | 310 } |
305 | 311 |
306 Constant *GlobalContext::getConstantSym(Type Ty, int64_t Offset, | 312 Constant *GlobalContext::getConstantSym(Type Ty, int64_t Offset, |
307 const IceString &Name, | 313 const IceString &Name, |
308 bool SuppressMangling) { | 314 bool SuppressMangling) { |
309 return ConstPool->Relocatables.getOrAdd( | 315 return ConstPool->Relocatables.getOrAdd( |
310 this, Ty, RelocatableTuple(Offset, Name, SuppressMangling)); | 316 this, Ty, RelocatableTuple(Offset, Name, SuppressMangling)); |
311 } | 317 } |
312 | 318 |
313 Constant *GlobalContext::getConstantUndef(Type Ty) { | 319 Constant *GlobalContext::getConstantUndef(Type Ty) { |
314 return ConstPool->Undefs.getOrAdd(this, Ty); | 320 return ConstPool->Undefs.getOrAdd(this, Ty); |
315 } | 321 } |
316 | 322 |
317 Constant *GlobalContext::getConstantZero(Type Ty) { | 323 Constant *GlobalContext::getConstantZero(Type Ty) { |
318 switch (Ty) { | 324 switch (Ty) { |
319 case IceType_i1: | 325 case IceType_i1: |
320 case IceType_i8: | 326 case IceType_i8: |
321 case IceType_i16: | 327 case IceType_i16: |
322 case IceType_i32: | 328 case IceType_i32: |
| 329 return getConstantInt32(Ty, 0); |
323 case IceType_i64: | 330 case IceType_i64: |
324 return getConstantInt(Ty, 0); | 331 return getConstantInt64(Ty, 0); |
325 case IceType_f32: | 332 case IceType_f32: |
326 return getConstantFloat(0); | 333 return getConstantFloat(0); |
327 case IceType_f64: | 334 case IceType_f64: |
328 return getConstantDouble(0); | 335 return getConstantDouble(0); |
329 case IceType_v4i1: | 336 case IceType_v4i1: |
330 case IceType_v8i1: | 337 case IceType_v8i1: |
331 case IceType_v16i1: | 338 case IceType_v16i1: |
332 case IceType_v16i8: | 339 case IceType_v16i8: |
333 case IceType_v8i16: | 340 case IceType_v8i16: |
334 case IceType_v4i32: | 341 case IceType_v4i32: |
335 case IceType_v4f32: { | 342 case IceType_v4f32: { |
336 IceString Str; | 343 IceString Str; |
337 llvm::raw_string_ostream BaseOS(Str); | 344 llvm::raw_string_ostream BaseOS(Str); |
338 BaseOS << "Unsupported constant type: " << Ty; | 345 BaseOS << "Unsupported constant type: " << Ty; |
339 llvm_unreachable(BaseOS.str().c_str()); | 346 llvm_unreachable(BaseOS.str().c_str()); |
340 } break; | 347 } break; |
341 case IceType_void: | 348 case IceType_void: |
342 case IceType_NUM: | 349 case IceType_NUM: |
343 break; | 350 break; |
344 } | 351 } |
345 llvm_unreachable("Unknown type"); | 352 llvm_unreachable("Unknown type"); |
346 } | 353 } |
347 | 354 |
348 ConstantList GlobalContext::getConstantPool(Type Ty) const { | 355 ConstantList GlobalContext::getConstantPool(Type Ty) const { |
349 switch (Ty) { | 356 switch (Ty) { |
350 case IceType_i1: | 357 case IceType_i1: |
351 case IceType_i8: | 358 case IceType_i8: |
352 case IceType_i16: | 359 case IceType_i16: |
353 case IceType_i32: | 360 case IceType_i32: |
| 361 return ConstPool->Integers32.getConstantPool(); |
354 case IceType_i64: | 362 case IceType_i64: |
355 return ConstPool->Integers.getConstantPool(); | 363 return ConstPool->Integers64.getConstantPool(); |
356 case IceType_f32: | 364 case IceType_f32: |
357 return ConstPool->Floats.getConstantPool(); | 365 return ConstPool->Floats.getConstantPool(); |
358 case IceType_f64: | 366 case IceType_f64: |
359 return ConstPool->Doubles.getConstantPool(); | 367 return ConstPool->Doubles.getConstantPool(); |
360 case IceType_v4i1: | 368 case IceType_v4i1: |
361 case IceType_v8i1: | 369 case IceType_v8i1: |
362 case IceType_v16i1: | 370 case IceType_v16i1: |
363 case IceType_v16i8: | 371 case IceType_v16i8: |
364 case IceType_v8i16: | 372 case IceType_v8i16: |
365 case IceType_v4i32: | 373 case IceType_v4i32: |
(...skipping 12 matching lines...) Expand all Loading... |
378 | 386 |
379 void Timer::printElapsedUs(GlobalContext *Ctx, const IceString &Tag) const { | 387 void Timer::printElapsedUs(GlobalContext *Ctx, const IceString &Tag) const { |
380 if (Ctx->isVerbose(IceV_Timing)) { | 388 if (Ctx->isVerbose(IceV_Timing)) { |
381 // Prefixing with '#' allows timing strings to be included | 389 // Prefixing with '#' allows timing strings to be included |
382 // without error in textual assembly output. | 390 // without error in textual assembly output. |
383 Ctx->getStrDump() << "# " << getElapsedUs() << " usec " << Tag << "\n"; | 391 Ctx->getStrDump() << "# " << getElapsedUs() << " usec " << Tag << "\n"; |
384 } | 392 } |
385 } | 393 } |
386 | 394 |
387 } // end of namespace Ice | 395 } // end of namespace Ice |
OLD | NEW |