| 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 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 Str << "\n"; | 125 Str << "\n"; |
| 126 } | 126 } |
| 127 | 127 |
| 128 GlobalContext::GlobalContext(Ostream *OsDump, Ostream *OsEmit, | 128 GlobalContext::GlobalContext(Ostream *OsDump, Ostream *OsEmit, |
| 129 ELFStreamer *ELFStr, VerboseMask Mask, | 129 ELFStreamer *ELFStr, VerboseMask Mask, |
| 130 TargetArch Arch, OptLevel Opt, | 130 TargetArch Arch, OptLevel Opt, |
| 131 IceString TestPrefix, const ClFlags &Flags) | 131 IceString TestPrefix, const ClFlags &Flags) |
| 132 : StrDump(OsDump), StrEmit(OsEmit), VMask(Mask), | 132 : StrDump(OsDump), StrEmit(OsEmit), VMask(Mask), |
| 133 ConstPool(new ConstantPool()), Arch(Arch), Opt(Opt), | 133 ConstPool(new ConstantPool()), Arch(Arch), Opt(Opt), |
| 134 TestPrefix(TestPrefix), Flags(Flags), RNG(""), ObjectWriter() { | 134 TestPrefix(TestPrefix), Flags(Flags), RNG(""), ObjectWriter() { |
| 135 // Make sure thread_local fields are properly initialized before any |
| 136 // accesses are made. Do this here instead of at the start of |
| 137 // main() so that all clients (e.g. unit tests) can benefit for |
| 138 // free. |
| 139 GlobalContext::TlsInit(); |
| 140 Cfg::TlsInit(); |
| 141 |
| 135 // Create a new ThreadContext for the current thread. No need to | 142 // Create a new ThreadContext for the current thread. No need to |
| 136 // lock AllThreadContexts at this point since no other threads have | 143 // lock AllThreadContexts at this point since no other threads have |
| 137 // access yet to this GlobalContext object. | 144 // access yet to this GlobalContext object. |
| 138 AllThreadContexts.push_back(new ThreadContext()); | 145 AllThreadContexts.push_back(new ThreadContext()); |
| 139 TLS = AllThreadContexts.back(); | 146 ICE_TLS_SET_FIELD(TLS, AllThreadContexts.back()); |
| 140 // Pre-register built-in stack names. | 147 // Pre-register built-in stack names. |
| 141 if (ALLOW_DUMP) { | 148 if (ALLOW_DUMP) { |
| 142 // TODO(stichnot): There needs to be a strong relationship between | 149 // TODO(stichnot): There needs to be a strong relationship between |
| 143 // the newTimerStackID() return values and TSK_Default/TSK_Funcs. | 150 // the newTimerStackID() return values and TSK_Default/TSK_Funcs. |
| 144 newTimerStackID("Total across all functions"); | 151 newTimerStackID("Total across all functions"); |
| 145 newTimerStackID("Per-function summary"); | 152 newTimerStackID("Per-function summary"); |
| 146 } | 153 } |
| 147 if (Flags.UseELFWriter) { | 154 if (Flags.UseELFWriter) { |
| 148 ObjectWriter.reset(new ELFObjectWriter(*this, *ELFStr)); | 155 ObjectWriter.reset(new ELFObjectWriter(*this, *ELFStr)); |
| 149 } | 156 } |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 Timers->at(StackID).setName(NewName); | 495 Timers->at(StackID).setName(NewName); |
| 489 } | 496 } |
| 490 | 497 |
| 491 void GlobalContext::dumpStats(const IceString &Name, bool Final) { | 498 void GlobalContext::dumpStats(const IceString &Name, bool Final) { |
| 492 if (!ALLOW_DUMP || !getFlags().DumpStats) | 499 if (!ALLOW_DUMP || !getFlags().DumpStats) |
| 493 return; | 500 return; |
| 494 OstreamLocker OL(this); | 501 OstreamLocker OL(this); |
| 495 if (Final) { | 502 if (Final) { |
| 496 getStatsCumulative()->dump(Name, getStrDump()); | 503 getStatsCumulative()->dump(Name, getStrDump()); |
| 497 } else { | 504 } else { |
| 498 TLS->StatsFunction.dump(Name, getStrDump()); | 505 ICE_TLS_GET_FIELD(TLS)->StatsFunction.dump(Name, getStrDump()); |
| 499 getStatsCumulative()->dump("_TOTAL_", getStrDump()); | 506 getStatsCumulative()->dump("_TOTAL_", getStrDump()); |
| 500 } | 507 } |
| 501 } | 508 } |
| 502 | 509 |
| 503 void GlobalContext::dumpTimers(TimerStackIdT StackID, bool DumpCumulative) { | 510 void GlobalContext::dumpTimers(TimerStackIdT StackID, bool DumpCumulative) { |
| 504 if (!ALLOW_DUMP) | 511 if (!ALLOW_DUMP) |
| 505 return; | 512 return; |
| 506 auto Timers = getTimers(); | 513 auto Timers = getTimers(); |
| 507 assert(Timers->size() > StackID); | 514 assert(Timers->size() > StackID); |
| 508 OstreamLocker L(this); | 515 OstreamLocker L(this); |
| 509 Timers->at(StackID).dump(getStrDump(), DumpCumulative); | 516 Timers->at(StackID).dump(getStrDump(), DumpCumulative); |
| 510 } | 517 } |
| 511 | 518 |
| 512 TimerMarker::TimerMarker(TimerIdT ID, const Cfg *Func) | 519 TimerMarker::TimerMarker(TimerIdT ID, const Cfg *Func) |
| 513 : ID(ID), Ctx(Func->getContext()), Active(false) { | 520 : ID(ID), Ctx(Func->getContext()), Active(false) { |
| 514 if (ALLOW_DUMP) { | 521 if (ALLOW_DUMP) { |
| 515 Active = Func->getFocusedTiming() || Ctx->getFlags().SubzeroTimingEnabled; | 522 Active = Func->getFocusedTiming() || Ctx->getFlags().SubzeroTimingEnabled; |
| 516 if (Active) | 523 if (Active) |
| 517 Ctx->pushTimer(ID); | 524 Ctx->pushTimer(ID); |
| 518 } | 525 } |
| 519 } | 526 } |
| 520 | 527 |
| 521 ICE_ATTRIBUTE_TLS GlobalContext::ThreadContext *GlobalContext::TLS; | 528 ICE_TLS_DEFINE_FIELD(GlobalContext::ThreadContext *, GlobalContext, TLS); |
| 522 | 529 |
| 523 } // end of namespace Ice | 530 } // end of namespace Ice |
| OLD | NEW |