| Index: src/IceGlobalContext.cpp
|
| diff --git a/src/IceGlobalContext.cpp b/src/IceGlobalContext.cpp
|
| index 413278fe1e35aeccbf1c6901e9bf9885c23aa2f7..40b74e886372cabbecd071fae4f274a5dba9b852 100644
|
| --- a/src/IceGlobalContext.cpp
|
| +++ b/src/IceGlobalContext.cpp
|
| @@ -143,8 +143,9 @@ GlobalContext::GlobalContext(Ostream *OsDump, Ostream *OsEmit,
|
| // Create a new ThreadContext for the current thread. No need to
|
| // lock AllThreadContexts at this point since no other threads have
|
| // access yet to this GlobalContext object.
|
| - AllThreadContexts.push_back(new ThreadContext());
|
| - ICE_TLS_SET_FIELD(TLS, AllThreadContexts.back());
|
| + ThreadContext *MyTLS = new ThreadContext();
|
| + AllThreadContexts.push_back(MyTLS);
|
| + ICE_TLS_SET_FIELD(TLS, MyTLS);
|
| // Pre-register built-in stack names.
|
| if (ALLOW_DUMP) {
|
| // TODO(stichnot): There needs to be a strong relationship between
|
| @@ -152,6 +153,7 @@ GlobalContext::GlobalContext(Ostream *OsDump, Ostream *OsEmit,
|
| newTimerStackID("Total across all functions");
|
| newTimerStackID("Per-function summary");
|
| }
|
| + Timers.initInto(MyTLS->Timers);
|
| if (Flags.UseELFWriter) {
|
| ObjectWriter.reset(new ELFObjectWriter(*this, *ELFStr));
|
| }
|
| @@ -503,38 +505,32 @@ TimerStackIdT GlobalContext::newTimerStackID(const IceString &Name) {
|
|
|
| TimerIdT GlobalContext::getTimerID(TimerStackIdT StackID,
|
| const IceString &Name) {
|
| - auto Timers = getTimers();
|
| + auto Timers = &ICE_TLS_GET_FIELD(TLS)->Timers;
|
| assert(StackID < Timers->size());
|
| return Timers->at(StackID).getTimerID(Name);
|
| }
|
|
|
| void GlobalContext::pushTimer(TimerIdT ID, TimerStackIdT StackID) {
|
| - // TODO(stichnot): Timers are completely broken for multithreading; fix.
|
| - if (getFlags().NumTranslationThreads)
|
| - llvm::report_fatal_error("Timers and multithreading are currently broken");
|
| - auto Timers = getTimers();
|
| + auto Timers = &ICE_TLS_GET_FIELD(TLS)->Timers;
|
| assert(StackID < Timers->size());
|
| Timers->at(StackID).push(ID);
|
| }
|
|
|
| void GlobalContext::popTimer(TimerIdT ID, TimerStackIdT StackID) {
|
| - // TODO(stichnot): Timers are completely broken for multithreading; fix.
|
| - if (getFlags().NumTranslationThreads)
|
| - llvm::report_fatal_error("Timers and multithreading are currently broken");
|
| - auto Timers = getTimers();
|
| + auto Timers = &ICE_TLS_GET_FIELD(TLS)->Timers;
|
| assert(StackID < Timers->size());
|
| Timers->at(StackID).pop(ID);
|
| }
|
|
|
| void GlobalContext::resetTimer(TimerStackIdT StackID) {
|
| - auto Timers = getTimers();
|
| + auto Timers = &ICE_TLS_GET_FIELD(TLS)->Timers;
|
| assert(StackID < Timers->size());
|
| Timers->at(StackID).reset();
|
| }
|
|
|
| void GlobalContext::setTimerName(TimerStackIdT StackID,
|
| const IceString &NewName) {
|
| - auto Timers = getTimers();
|
| + auto Timers = &ICE_TLS_GET_FIELD(TLS)->Timers;
|
| assert(StackID < Timers->size());
|
| Timers->at(StackID).setName(NewName);
|
| }
|
| @@ -560,8 +556,8 @@ void GlobalContext::dumpTimers(TimerStackIdT StackID, bool DumpCumulative) {
|
| Timers->at(StackID).dump(getStrDump(), DumpCumulative);
|
| }
|
|
|
| -TimerMarker::TimerMarker(TimerIdT ID, const Cfg *Func)
|
| - : ID(ID), Ctx(Func->getContext()), Active(false) {
|
| +TimerMarker::TimerMarker(TimerIdT ID, const Cfg *Func, TimerStackIdT StackID)
|
| + : ID(ID), Ctx(Func->getContext()), StackID(StackID), Active(false) {
|
| if (ALLOW_DUMP) {
|
| Active = Func->getFocusedTiming() || Ctx->getFlags().SubzeroTimingEnabled;
|
| if (Active)
|
|
|