| OLD | NEW |
| 1 //===- subzero/src/IceGlobalContext.cpp - Global context defs -------------===// | 1 //===- subzero/src/IceGlobalContext.cpp - Global context defs -------------===// |
| 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 /// \file | 10 /// \file |
| 11 /// \brief Defines aspects of the compilation that persist across multiple | 11 /// \brief Defines aspects of the compilation that persist across multiple |
| 12 /// functions. | 12 /// functions. |
| 13 /// | 13 /// |
| 14 //===----------------------------------------------------------------------===// | 14 //===----------------------------------------------------------------------===// |
| 15 | 15 |
| 16 #include "IceGlobalContext.h" | 16 #include "IceGlobalContext.h" |
| 17 | 17 |
| 18 #include "IceCfg.h" | 18 #include "IceCfg.h" |
| 19 #include "IceCfgNode.h" | 19 #include "IceCfgNode.h" |
| 20 #include "IceClFlags.h" | 20 #include "IceClFlags.h" |
| 21 #include "IceClFlagsExtra.h" | 21 #include "IceClFlagsExtra.h" |
| 22 #include "IceDefs.h" | 22 #include "IceDefs.h" |
| 23 #include "IceELFObjectWriter.h" | 23 #include "IceELFObjectWriter.h" |
| 24 #include "IceGlobalInits.h" | 24 #include "IceGlobalInits.h" |
| 25 #include "IceOperand.h" | 25 #include "IceOperand.h" |
| 26 #include "IceTargetLowering.h" | 26 #include "IceTargetLowering.h" |
| 27 #include "IceTimerTree.h" | 27 #include "IceTimerTree.h" |
| 28 #include "IceTypes.def" |
| 28 #include "IceTypes.h" | 29 #include "IceTypes.h" |
| 29 | 30 |
| 30 #ifdef __clang__ | 31 #ifdef __clang__ |
| 31 #pragma clang diagnostic push | 32 #pragma clang diagnostic push |
| 32 #pragma clang diagnostic ignored "-Wunused-parameter" | 33 #pragma clang diagnostic ignored "-Wunused-parameter" |
| 33 #endif // __clang__ | 34 #endif // __clang__ |
| 34 | 35 |
| 35 #include "llvm/Support/Timer.h" | 36 #include "llvm/Support/Timer.h" |
| 36 | 37 |
| 37 #ifdef __clang__ | 38 #ifdef __clang__ |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 } | 285 } |
| 285 Timers.initInto(MyTLS->Timers); | 286 Timers.initInto(MyTLS->Timers); |
| 286 switch (Flags.getOutFileType()) { | 287 switch (Flags.getOutFileType()) { |
| 287 case FT_Elf: | 288 case FT_Elf: |
| 288 ObjectWriter.reset(new ELFObjectWriter(*this, *ELFStr)); | 289 ObjectWriter.reset(new ELFObjectWriter(*this, *ELFStr)); |
| 289 break; | 290 break; |
| 290 case FT_Asm: | 291 case FT_Asm: |
| 291 case FT_Iasm: | 292 case FT_Iasm: |
| 292 break; | 293 break; |
| 293 } | 294 } |
| 295 // Cache up front common constants. |
| 296 #define X(tag, sizeLog2, align, elts, elty, str, rcstr) \ |
| 297 ConstZeroForType[IceType_##tag] = getConstantZeroInternal(IceType_##tag); |
| 298 ICETYPE_TABLE; |
| 299 #undef X |
| 300 ConstantTrue = getConstantInt1Internal(1); |
| 301 // Define runtime helper functions. |
| 302 #define X(Tag, Name) \ |
| 303 RuntimeHelperFunc[static_cast<size_t>(RuntimeHelper::H_##Tag)] = \ |
| 304 getConstantExternSym(Name); |
| 305 RUNTIME_HELPER_FUNCTIONS_TABLE |
| 306 #undef X |
| 294 | 307 |
| 295 TargetLowering::staticInit(this); | 308 TargetLowering::staticInit(this); |
| 296 } | 309 } |
| 297 | 310 |
| 298 void GlobalContext::translateFunctions() { | 311 void GlobalContext::translateFunctions() { |
| 299 TimerMarker Timer(TimerStack::TT_translateFunctions, this); | 312 TimerMarker Timer(TimerStack::TT_translateFunctions, this); |
| 300 while (std::unique_ptr<Cfg> Func = optQueueBlockingPop()) { | 313 while (std::unique_ptr<Cfg> Func = optQueueBlockingPop()) { |
| 301 // Install Func in TLS for Cfg-specific container allocators. | 314 // Install Func in TLS for Cfg-specific container allocators. |
| 302 CfgLocalAllocatorScope _(Func.get()); | 315 CfgLocalAllocatorScope _(Func.get()); |
| 303 // Reset per-function stats being accumulated in TLS. | 316 // Reset per-function stats being accumulated in TLS. |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 case IceType_i32: | 663 case IceType_i32: |
| 651 return getConstantInt32(Value); | 664 return getConstantInt32(Value); |
| 652 case IceType_i64: | 665 case IceType_i64: |
| 653 return getConstantInt64(Value); | 666 return getConstantInt64(Value); |
| 654 default: | 667 default: |
| 655 llvm_unreachable("Bad integer type for getConstant"); | 668 llvm_unreachable("Bad integer type for getConstant"); |
| 656 } | 669 } |
| 657 return nullptr; | 670 return nullptr; |
| 658 } | 671 } |
| 659 | 672 |
| 660 Constant *GlobalContext::getConstantInt1(int8_t ConstantInt1) { | 673 Constant *GlobalContext::getConstantInt1Internal(int8_t ConstantInt1) { |
| 661 ConstantInt1 &= INT8_C(1); | 674 ConstantInt1 &= INT8_C(1); |
| 662 return getConstPool()->Integers1.getOrAdd(this, ConstantInt1); | 675 return getConstPool()->Integers1.getOrAdd(this, ConstantInt1); |
| 663 } | 676 } |
| 664 | 677 |
| 665 Constant *GlobalContext::getConstantInt8(int8_t ConstantInt8) { | 678 Constant *GlobalContext::getConstantInt8Internal(int8_t ConstantInt8) { |
| 666 return getConstPool()->Integers8.getOrAdd(this, ConstantInt8); | 679 return getConstPool()->Integers8.getOrAdd(this, ConstantInt8); |
| 667 } | 680 } |
| 668 | 681 |
| 669 Constant *GlobalContext::getConstantInt16(int16_t ConstantInt16) { | 682 Constant *GlobalContext::getConstantInt16Internal(int16_t ConstantInt16) { |
| 670 return getConstPool()->Integers16.getOrAdd(this, ConstantInt16); | 683 return getConstPool()->Integers16.getOrAdd(this, ConstantInt16); |
| 671 } | 684 } |
| 672 | 685 |
| 673 Constant *GlobalContext::getConstantInt32(int32_t ConstantInt32) { | 686 Constant *GlobalContext::getConstantInt32Internal(int32_t ConstantInt32) { |
| 674 return getConstPool()->Integers32.getOrAdd(this, ConstantInt32); | 687 return getConstPool()->Integers32.getOrAdd(this, ConstantInt32); |
| 675 } | 688 } |
| 676 | 689 |
| 677 Constant *GlobalContext::getConstantInt64(int64_t ConstantInt64) { | 690 Constant *GlobalContext::getConstantInt64Internal(int64_t ConstantInt64) { |
| 678 return getConstPool()->Integers64.getOrAdd(this, ConstantInt64); | 691 return getConstPool()->Integers64.getOrAdd(this, ConstantInt64); |
| 679 } | 692 } |
| 680 | 693 |
| 681 Constant *GlobalContext::getConstantFloat(float ConstantFloat) { | 694 Constant *GlobalContext::getConstantFloat(float ConstantFloat) { |
| 682 return getConstPool()->Floats.getOrAdd(this, ConstantFloat); | 695 return getConstPool()->Floats.getOrAdd(this, ConstantFloat); |
| 683 } | 696 } |
| 684 | 697 |
| 685 Constant *GlobalContext::getConstantDouble(double ConstantDouble) { | 698 Constant *GlobalContext::getConstantDouble(double ConstantDouble) { |
| 686 return getConstPool()->Doubles.getOrAdd(this, ConstantDouble); | 699 return getConstPool()->Doubles.getOrAdd(this, ConstantDouble); |
| 687 } | 700 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 703 Constant *GlobalContext::getConstantExternSym(const IceString &Name) { | 716 Constant *GlobalContext::getConstantExternSym(const IceString &Name) { |
| 704 constexpr RelocOffsetT Offset = 0; | 717 constexpr RelocOffsetT Offset = 0; |
| 705 return getConstPool()->ExternRelocatables.getOrAdd( | 718 return getConstPool()->ExternRelocatables.getOrAdd( |
| 706 this, RelocatableTuple(Offset, {}, Name)); | 719 this, RelocatableTuple(Offset, {}, Name)); |
| 707 } | 720 } |
| 708 | 721 |
| 709 Constant *GlobalContext::getConstantUndef(Type Ty) { | 722 Constant *GlobalContext::getConstantUndef(Type Ty) { |
| 710 return getConstPool()->Undefs.getOrAdd(this, Ty); | 723 return getConstPool()->Undefs.getOrAdd(this, Ty); |
| 711 } | 724 } |
| 712 | 725 |
| 726 Constant *GlobalContext::getConstantZero(Type Ty) { |
| 727 Constant *Zero = ConstZeroForType[Ty]; |
| 728 if (Zero == nullptr) |
| 729 llvm::report_fatal_error("Unsupported constant type: " + typeIceString(Ty)); |
| 730 return Zero; |
| 731 } |
| 732 |
| 713 // All locking is done by the getConstant*() target function. | 733 // All locking is done by the getConstant*() target function. |
| 714 Constant *GlobalContext::getConstantZero(Type Ty) { | 734 Constant *GlobalContext::getConstantZeroInternal(Type Ty) { |
| 715 switch (Ty) { | 735 switch (Ty) { |
| 716 case IceType_i1: | 736 case IceType_i1: |
| 717 return getConstantInt1(0); | 737 return getConstantInt1Internal(0); |
| 718 case IceType_i8: | 738 case IceType_i8: |
| 719 return getConstantInt8(0); | 739 return getConstantInt8Internal(0); |
| 720 case IceType_i16: | 740 case IceType_i16: |
| 721 return getConstantInt16(0); | 741 return getConstantInt16Internal(0); |
| 722 case IceType_i32: | 742 case IceType_i32: |
| 723 return getConstantInt32(0); | 743 return getConstantInt32Internal(0); |
| 724 case IceType_i64: | 744 case IceType_i64: |
| 725 return getConstantInt64(0); | 745 return getConstantInt64Internal(0); |
| 726 case IceType_f32: | 746 case IceType_f32: |
| 727 return getConstantFloat(0); | 747 return getConstantFloat(0); |
| 728 case IceType_f64: | 748 case IceType_f64: |
| 729 return getConstantDouble(0); | 749 return getConstantDouble(0); |
| 730 case IceType_v4i1: | 750 default: |
| 731 case IceType_v8i1: | 751 return nullptr; |
| 732 case IceType_v16i1: | |
| 733 case IceType_v16i8: | |
| 734 case IceType_v8i16: | |
| 735 case IceType_v4i32: | |
| 736 case IceType_v4f32: { | |
| 737 IceString Str; | |
| 738 llvm::raw_string_ostream BaseOS(Str); | |
| 739 BaseOS << "Unsupported constant type: " << Ty; | |
| 740 llvm_unreachable(BaseOS.str().c_str()); | |
| 741 } break; | |
| 742 case IceType_void: | |
| 743 case IceType_NUM: | |
| 744 break; | |
| 745 } | 752 } |
| 746 llvm_unreachable("Unknown type"); | |
| 747 } | 753 } |
| 748 | 754 |
| 749 ConstantList GlobalContext::getConstantPool(Type Ty) { | 755 ConstantList GlobalContext::getConstantPool(Type Ty) { |
| 750 switch (Ty) { | 756 switch (Ty) { |
| 751 case IceType_i1: | 757 case IceType_i1: |
| 752 case IceType_i8: | 758 case IceType_i8: |
| 753 return getConstPool()->Integers8.getConstantPool(); | 759 return getConstPool()->Integers8.getConstantPool(); |
| 754 case IceType_i16: | 760 case IceType_i16: |
| 755 return getConstPool()->Integers16.getConstantPool(); | 761 return getConstPool()->Integers16.getConstantPool(); |
| 756 case IceType_i32: | 762 case IceType_i32: |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 943 Ctx = Func->getContext(); | 949 Ctx = Func->getContext(); |
| 944 Active = | 950 Active = |
| 945 Func->getFocusedTiming() || Ctx->getFlags().getSubzeroTimingEnabled(); | 951 Func->getFocusedTiming() || Ctx->getFlags().getSubzeroTimingEnabled(); |
| 946 if (Active) | 952 if (Active) |
| 947 Ctx->pushTimer(ID, StackID); | 953 Ctx->pushTimer(ID, StackID); |
| 948 } | 954 } |
| 949 | 955 |
| 950 ICE_TLS_DEFINE_FIELD(GlobalContext::ThreadContext *, GlobalContext, TLS); | 956 ICE_TLS_DEFINE_FIELD(GlobalContext::ThreadContext *, GlobalContext, TLS); |
| 951 | 957 |
| 952 } // end of namespace Ice | 958 } // end of namespace Ice |
| OLD | NEW |