| 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 // This file defines aspects of the compilation that persist across | 10 // This file defines aspects of the compilation that persist across |
| 11 // multiple functions. | 11 // multiple functions. |
| 12 // | 12 // |
| 13 //===----------------------------------------------------------------------===// | 13 //===----------------------------------------------------------------------===// |
| 14 | 14 |
| 15 #include "IceGlobalContext.h" | 15 #include "IceGlobalContext.h" |
| 16 | 16 |
| 17 #include "IceCfg.h" | 17 #include "IceCfg.h" |
| 18 #include "IceCfgNode.h" | 18 #include "IceCfgNode.h" |
| 19 #include "IceClFlags.h" | 19 #include "IceClFlags.h" |
| 20 #include "IceDefs.h" | 20 #include "IceDefs.h" |
| 21 #include "IceELFObjectWriter.h" | 21 #include "IceELFObjectWriter.h" |
| 22 #include "IceGlobalInits.h" | 22 #include "IceGlobalInits.h" |
| 23 #include "IceOperand.h" | 23 #include "IceOperand.h" |
| 24 #include "IceTargetLowering.h" | 24 #include "IceTargetLowering.h" |
| 25 #include "IceTimerTree.h" | 25 #include "IceTimerTree.h" |
| 26 #include "IceTypes.h" | 26 #include "IceTypes.h" |
| 27 | 27 |
| 28 #pragma clang diagnostic push | 28 #pragma clang diagnostic push |
| 29 #pragma clang diagnostic ignored "-Wunused-parameter" | 29 #pragma clang diagnostic ignored "-Wunused-parameter" |
| 30 #pragma clang diagnostic ignored "-Wshadow" |
| 30 #include "llvm/Support/Timer.h" | 31 #include "llvm/Support/Timer.h" |
| 31 #pragma clang diagnostic pop | 32 #pragma clang diagnostic pop |
| 32 | 33 |
| 33 #include <algorithm> // max() | 34 #include <algorithm> // max() |
| 34 #include <cctype> // isdigit(), isupper() | 35 #include <cctype> // isdigit(), isupper() |
| 35 #include <locale> // locale | 36 #include <locale> // locale |
| 36 #include <unordered_map> | 37 #include <unordered_map> |
| 37 | 38 |
| 38 namespace std { | 39 namespace std { |
| 39 template <> struct hash<Ice::RelocatableTuple> { | 40 template <> struct hash<Ice::RelocatableTuple> { |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 << Stats[CS_NumSpills] + Stats[CS_NumFills] << "\n"; | 214 << Stats[CS_NumSpills] + Stats[CS_NumFills] << "\n"; |
| 214 Str << "|" << Name << "|Memory Usage|"; | 215 Str << "|" << Name << "|Memory Usage|"; |
| 215 if (ssize_t MemUsed = llvm::TimeRecord::getCurrentTime(false).getMemUsed()) | 216 if (ssize_t MemUsed = llvm::TimeRecord::getCurrentTime(false).getMemUsed()) |
| 216 Str << MemUsed; | 217 Str << MemUsed; |
| 217 else | 218 else |
| 218 Str << "(requires '-track-memory')"; | 219 Str << "(requires '-track-memory')"; |
| 219 Str << "\n"; | 220 Str << "\n"; |
| 220 } | 221 } |
| 221 | 222 |
| 222 GlobalContext::GlobalContext(Ostream *OsDump, Ostream *OsEmit, Ostream *OsError, | 223 GlobalContext::GlobalContext(Ostream *OsDump, Ostream *OsEmit, Ostream *OsError, |
| 223 ELFStreamer *ELFStr, const ClFlags &Flags) | 224 ELFStreamer *ELFStr, const ClFlags &MyFlags) |
| 224 : ConstPool(new ConstantPool()), ErrorStatus(), StrDump(OsDump), | 225 : ConstPool(new ConstantPool()), ErrorStatus(), StrDump(OsDump), |
| 225 StrEmit(OsEmit), StrError(OsError), Flags(Flags), | 226 StrEmit(OsEmit), StrError(OsError), Flags(MyFlags), |
| 226 RNG(Flags.getRandomSeed()), ObjectWriter(), | 227 RNG(Flags.getRandomSeed()), ObjectWriter(), |
| 227 OptQ(/*Sequential=*/Flags.isSequential(), | 228 OptQ(/*Sequential=*/Flags.isSequential(), |
| 228 /*MaxSize=*/Flags.getNumTranslationThreads()), | 229 /*MaxSize=*/Flags.getNumTranslationThreads()), |
| 229 // EmitQ is allowed unlimited size. | 230 // EmitQ is allowed unlimited size. |
| 230 EmitQ(/*Sequential=*/Flags.isSequential()), | 231 EmitQ(/*Sequential=*/Flags.isSequential()), |
| 231 DataLowering(TargetDataLowering::createLowering(this)) { | 232 DataLowering(TargetDataLowering::createLowering(this)) { |
| 232 assert(OsDump && "OsDump is not defined for GlobalContext"); | 233 assert(OsDump && "OsDump is not defined for GlobalContext"); |
| 233 assert(OsEmit && "OsEmit is not defined for GlobalContext"); | 234 assert(OsEmit && "OsEmit is not defined for GlobalContext"); |
| 234 assert(OsError && "OsError is not defined for GlobalContext"); | 235 assert(OsError && "OsError is not defined for GlobalContext"); |
| 235 // Make sure thread_local fields are properly initialized before any | 236 // Make sure thread_local fields are properly initialized before any |
| (...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 871 llvm_unreachable("Unknown type"); | 872 llvm_unreachable("Unknown type"); |
| 872 } | 873 } |
| 873 | 874 |
| 874 ConstantList GlobalContext::getConstantExternSyms() { | 875 ConstantList GlobalContext::getConstantExternSyms() { |
| 875 return getConstPool()->ExternRelocatables.getConstantPool(); | 876 return getConstPool()->ExternRelocatables.getConstantPool(); |
| 876 } | 877 } |
| 877 | 878 |
| 878 TimerStackIdT GlobalContext::newTimerStackID(const IceString &Name) { | 879 TimerStackIdT GlobalContext::newTimerStackID(const IceString &Name) { |
| 879 if (!BuildDefs::dump()) | 880 if (!BuildDefs::dump()) |
| 880 return 0; | 881 return 0; |
| 881 auto Timers = getTimers(); | 882 auto MyTimers = getTimers(); |
| 882 TimerStackIdT NewID = Timers->size(); | 883 TimerStackIdT NewID = MyTimers->size(); |
| 883 Timers->push_back(TimerStack(Name)); | 884 MyTimers->push_back(TimerStack(Name)); |
| 884 return NewID; | 885 return NewID; |
| 885 } | 886 } |
| 886 | 887 |
| 887 TimerIdT GlobalContext::getTimerID(TimerStackIdT StackID, | 888 TimerIdT GlobalContext::getTimerID(TimerStackIdT StackID, |
| 888 const IceString &Name) { | 889 const IceString &Name) { |
| 889 auto Timers = &ICE_TLS_GET_FIELD(TLS)->Timers; | 890 auto MyTimers = &ICE_TLS_GET_FIELD(TLS)->Timers; |
| 890 assert(StackID < Timers->size()); | 891 assert(StackID < MyTimers->size()); |
| 891 return Timers->at(StackID).getTimerID(Name); | 892 return MyTimers->at(StackID).getTimerID(Name); |
| 892 } | 893 } |
| 893 | 894 |
| 894 void GlobalContext::pushTimer(TimerIdT ID, TimerStackIdT StackID) { | 895 void GlobalContext::pushTimer(TimerIdT ID, TimerStackIdT StackID) { |
| 895 auto Timers = &ICE_TLS_GET_FIELD(TLS)->Timers; | 896 auto MyTimers = &ICE_TLS_GET_FIELD(TLS)->Timers; |
| 896 assert(StackID < Timers->size()); | 897 assert(StackID < MyTimers->size()); |
| 897 Timers->at(StackID).push(ID); | 898 MyTimers->at(StackID).push(ID); |
| 898 } | 899 } |
| 899 | 900 |
| 900 void GlobalContext::popTimer(TimerIdT ID, TimerStackIdT StackID) { | 901 void GlobalContext::popTimer(TimerIdT ID, TimerStackIdT StackID) { |
| 901 auto Timers = &ICE_TLS_GET_FIELD(TLS)->Timers; | 902 auto MyTimers = &ICE_TLS_GET_FIELD(TLS)->Timers; |
| 902 assert(StackID < Timers->size()); | 903 assert(StackID < MyTimers->size()); |
| 903 Timers->at(StackID).pop(ID); | 904 MyTimers->at(StackID).pop(ID); |
| 904 } | 905 } |
| 905 | 906 |
| 906 void GlobalContext::resetTimer(TimerStackIdT StackID) { | 907 void GlobalContext::resetTimer(TimerStackIdT StackID) { |
| 907 auto Timers = &ICE_TLS_GET_FIELD(TLS)->Timers; | 908 auto MyTimers = &ICE_TLS_GET_FIELD(TLS)->Timers; |
| 908 assert(StackID < Timers->size()); | 909 assert(StackID < MyTimers->size()); |
| 909 Timers->at(StackID).reset(); | 910 MyTimers->at(StackID).reset(); |
| 910 } | 911 } |
| 911 | 912 |
| 912 void GlobalContext::setTimerName(TimerStackIdT StackID, | 913 void GlobalContext::setTimerName(TimerStackIdT StackID, |
| 913 const IceString &NewName) { | 914 const IceString &NewName) { |
| 914 auto Timers = &ICE_TLS_GET_FIELD(TLS)->Timers; | 915 auto MyTimers = &ICE_TLS_GET_FIELD(TLS)->Timers; |
| 915 assert(StackID < Timers->size()); | 916 assert(StackID < MyTimers->size()); |
| 916 Timers->at(StackID).setName(NewName); | 917 MyTimers->at(StackID).setName(NewName); |
| 917 } | 918 } |
| 918 | 919 |
| 919 // Note: optQueueBlockingPush and optQueueBlockingPop use unique_ptr | 920 // Note: optQueueBlockingPush and optQueueBlockingPop use unique_ptr |
| 920 // at the interface to take and transfer ownership, but they | 921 // at the interface to take and transfer ownership, but they |
| 921 // internally store the raw Cfg pointer in the work queue. This | 922 // internally store the raw Cfg pointer in the work queue. This |
| 922 // allows e.g. future queue optimizations such as the use of atomics | 923 // allows e.g. future queue optimizations such as the use of atomics |
| 923 // to modify queue elements. | 924 // to modify queue elements. |
| 924 void GlobalContext::optQueueBlockingPush(std::unique_ptr<Cfg> Func) { | 925 void GlobalContext::optQueueBlockingPush(std::unique_ptr<Cfg> Func) { |
| 925 assert(Func); | 926 assert(Func); |
| 926 OptQ.blockingPush(Func.release()); | 927 OptQ.blockingPush(Func.release()); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 950 if (Final) { | 951 if (Final) { |
| 951 getStatsCumulative()->dump(Name, getStrDump()); | 952 getStatsCumulative()->dump(Name, getStrDump()); |
| 952 } else { | 953 } else { |
| 953 ICE_TLS_GET_FIELD(TLS)->StatsFunction.dump(Name, getStrDump()); | 954 ICE_TLS_GET_FIELD(TLS)->StatsFunction.dump(Name, getStrDump()); |
| 954 } | 955 } |
| 955 } | 956 } |
| 956 | 957 |
| 957 void GlobalContext::dumpTimers(TimerStackIdT StackID, bool DumpCumulative) { | 958 void GlobalContext::dumpTimers(TimerStackIdT StackID, bool DumpCumulative) { |
| 958 if (!BuildDefs::dump()) | 959 if (!BuildDefs::dump()) |
| 959 return; | 960 return; |
| 960 auto Timers = getTimers(); | 961 auto MyTimers = getTimers(); |
| 961 assert(Timers->size() > StackID); | 962 assert(MyTimers->size() > StackID); |
| 962 OstreamLocker L(this); | 963 OstreamLocker L(this); |
| 963 Timers->at(StackID).dump(getStrDump(), DumpCumulative); | 964 MyTimers->at(StackID).dump(getStrDump(), DumpCumulative); |
| 964 } | 965 } |
| 965 | 966 |
| 966 void TimerMarker::push() { | 967 void TimerMarker::push() { |
| 967 switch (StackID) { | 968 switch (StackID) { |
| 968 case GlobalContext::TSK_Default: | 969 case GlobalContext::TSK_Default: |
| 969 Active = Ctx->getFlags().getSubzeroTimingEnabled(); | 970 Active = Ctx->getFlags().getSubzeroTimingEnabled(); |
| 970 break; | 971 break; |
| 971 case GlobalContext::TSK_Funcs: | 972 case GlobalContext::TSK_Funcs: |
| 972 Active = Ctx->getFlags().getTimeEachFunction(); | 973 Active = Ctx->getFlags().getTimeEachFunction(); |
| 973 break; | 974 break; |
| 974 default: | 975 default: |
| 975 break; | 976 break; |
| 976 } | 977 } |
| 977 if (Active) | 978 if (Active) |
| 978 Ctx->pushTimer(ID, StackID); | 979 Ctx->pushTimer(ID, StackID); |
| 979 } | 980 } |
| 980 | 981 |
| 981 void TimerMarker::pushCfg(const Cfg *Func) { | 982 void TimerMarker::pushCfg(const Cfg *Func) { |
| 982 Ctx = Func->getContext(); | 983 Ctx = Func->getContext(); |
| 983 Active = | 984 Active = |
| 984 Func->getFocusedTiming() || Ctx->getFlags().getSubzeroTimingEnabled(); | 985 Func->getFocusedTiming() || Ctx->getFlags().getSubzeroTimingEnabled(); |
| 985 if (Active) | 986 if (Active) |
| 986 Ctx->pushTimer(ID, StackID); | 987 Ctx->pushTimer(ID, StackID); |
| 987 } | 988 } |
| 988 | 989 |
| 989 ICE_TLS_DEFINE_FIELD(GlobalContext::ThreadContext *, GlobalContext, TLS); | 990 ICE_TLS_DEFINE_FIELD(GlobalContext::ThreadContext *, GlobalContext, TLS); |
| 990 | 991 |
| 991 } // end of namespace Ice | 992 } // end of namespace Ice |
| OLD | NEW |