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