 Chromium Code Reviews
 Chromium Code Reviews Issue 1775253003:
  Cache common constants before lowering.  (Closed) 
  Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
    
  
    Issue 1775253003:
  Cache common constants before lowering.  (Closed) 
  Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master| 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] = installConstantZero(IceType_##tag); | |
| 298 ICETYPE_TABLE; | |
| 299 #undef X | |
| 300 ConstantTrue = installConstantInt1(1); | |
| 301 // Define runtime helper functions. | |
| 302 { | |
| 
Jim Stichnoth
2016/03/17 00:14:52
Is this set of braces necessary?
 
Karl
2016/03/17 16:40:53
Removed.
 | |
| 303 #define X(Tag, Name) RuntimeHelperFunc[H_##Tag] = getConstantExternSym(Name); | |
| 304 RUNTIME_HELPER_FUNCTIONS_TABLE | |
| 305 #undef X | |
| 306 } | |
| 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::installConstantInt1(int8_t ConstantInt1) { | 
| 
Jim Stichnoth
2016/03/17 00:14:52
Bikeshed time.  I kinda don't like the "install" p
 
Karl
2016/03/17 16:40:53
Done.
 | |
| 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::installConstantInt8(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::installConstantInt16(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::installConstantInt32(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::installConstantInt64(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 16 matching lines...) Expand all Loading... | |
| 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 | 
| 713 // All locking is done by the getConstant*() target function. | 726 // All locking is done by the getConstant*() target function. | 
| 714 Constant *GlobalContext::getConstantZero(Type Ty) { | 727 Constant *GlobalContext::installConstantZero(Type Ty) { | 
| 715 switch (Ty) { | 728 switch (Ty) { | 
| 716 case IceType_i1: | 729 case IceType_i1: | 
| 717 return getConstantInt1(0); | 730 return installConstantInt1(0); | 
| 731 break; | |
| 
Jim Stichnoth
2016/03/17 00:14:52
You don't need all these "break" statements after
 
Karl
2016/03/17 16:40:53
Done.
 | |
| 718 case IceType_i8: | 732 case IceType_i8: | 
| 719 return getConstantInt8(0); | 733 return installConstantInt8(0); | 
| 734 break; | |
| 720 case IceType_i16: | 735 case IceType_i16: | 
| 721 return getConstantInt16(0); | 736 return installConstantInt16(0); | 
| 737 break; | |
| 722 case IceType_i32: | 738 case IceType_i32: | 
| 723 return getConstantInt32(0); | 739 return installConstantInt32(0); | 
| 740 break; | |
| 724 case IceType_i64: | 741 case IceType_i64: | 
| 725 return getConstantInt64(0); | 742 return installConstantInt64(0); | 
| 743 break; | |
| 726 case IceType_f32: | 744 case IceType_f32: | 
| 727 return getConstantFloat(0); | 745 return getConstantFloat(0); | 
| 746 break; | |
| 728 case IceType_f64: | 747 case IceType_f64: | 
| 729 return getConstantDouble(0); | 748 return getConstantDouble(0); | 
| 730 case IceType_v4i1: | |
| 731 case IceType_v8i1: | |
| 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; | 749 break; | 
| 750 default: | |
| 751 return nullptr; | |
| 
Jim Stichnoth
2016/03/17 00:14:52
I kind of like the previous behavior where it give
 
John
2016/03/17 14:31:33
I also like the previous behavior better, but I am
 
Karl
2016/03/17 16:40:53
Followed John's advice.
 | |
| 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 |