| 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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 Str << "\n"; | 127 Str << "\n"; |
| 128 } | 128 } |
| 129 | 129 |
| 130 GlobalContext::GlobalContext(Ostream *OsDump, Ostream *OsEmit, | 130 GlobalContext::GlobalContext(Ostream *OsDump, Ostream *OsEmit, |
| 131 ELFStreamer *ELFStr, VerboseMask Mask, | 131 ELFStreamer *ELFStr, VerboseMask Mask, |
| 132 TargetArch Arch, OptLevel Opt, | 132 TargetArch Arch, OptLevel Opt, |
| 133 IceString TestPrefix, const ClFlags &Flags) | 133 IceString TestPrefix, const ClFlags &Flags) |
| 134 : ConstPool(new ConstantPool()), ErrorStatus(), StrDump(OsDump), | 134 : ConstPool(new ConstantPool()), ErrorStatus(), StrDump(OsDump), |
| 135 StrEmit(OsEmit), VMask(Mask), Arch(Arch), Opt(Opt), | 135 StrEmit(OsEmit), VMask(Mask), Arch(Arch), Opt(Opt), |
| 136 TestPrefix(TestPrefix), Flags(Flags), RNG(""), ObjectWriter(), | 136 TestPrefix(TestPrefix), Flags(Flags), RNG(""), ObjectWriter(), |
| 137 CfgQ(/*MaxSize=*/Flags.NumTranslationThreads, | 137 CfgQ(/*MaxSize=*/Flags.getNumTranslationThreads(), |
| 138 /*Sequential=*/(Flags.NumTranslationThreads == 0)) { | 138 /*Sequential=*/(Flags.getNumTranslationThreads() == 0)) { |
| 139 // Make sure thread_local fields are properly initialized before any | 139 // Make sure thread_local fields are properly initialized before any |
| 140 // accesses are made. Do this here instead of at the start of | 140 // accesses are made. Do this here instead of at the start of |
| 141 // main() so that all clients (e.g. unit tests) can benefit for | 141 // main() so that all clients (e.g. unit tests) can benefit for |
| 142 // free. | 142 // free. |
| 143 GlobalContext::TlsInit(); | 143 GlobalContext::TlsInit(); |
| 144 Cfg::TlsInit(); | 144 Cfg::TlsInit(); |
| 145 // Create a new ThreadContext for the current thread. No need to | 145 // Create a new ThreadContext for the current thread. No need to |
| 146 // lock AllThreadContexts at this point since no other threads have | 146 // lock AllThreadContexts at this point since no other threads have |
| 147 // access yet to this GlobalContext object. | 147 // access yet to this GlobalContext object. |
| 148 ThreadContext *MyTLS = new ThreadContext(); | 148 ThreadContext *MyTLS = new ThreadContext(); |
| 149 AllThreadContexts.push_back(MyTLS); | 149 AllThreadContexts.push_back(MyTLS); |
| 150 ICE_TLS_SET_FIELD(TLS, MyTLS); | 150 ICE_TLS_SET_FIELD(TLS, MyTLS); |
| 151 // Pre-register built-in stack names. | 151 // Pre-register built-in stack names. |
| 152 if (ALLOW_DUMP) { | 152 if (ALLOW_DUMP) { |
| 153 // TODO(stichnot): There needs to be a strong relationship between | 153 // TODO(stichnot): There needs to be a strong relationship between |
| 154 // the newTimerStackID() return values and TSK_Default/TSK_Funcs. | 154 // the newTimerStackID() return values and TSK_Default/TSK_Funcs. |
| 155 newTimerStackID("Total across all functions"); | 155 newTimerStackID("Total across all functions"); |
| 156 newTimerStackID("Per-function summary"); | 156 newTimerStackID("Per-function summary"); |
| 157 } | 157 } |
| 158 Timers.initInto(MyTLS->Timers); | 158 Timers.initInto(MyTLS->Timers); |
| 159 if (Flags.UseELFWriter) { | 159 if (Flags.getUseELFWriter()) { |
| 160 ObjectWriter.reset(new ELFObjectWriter(*this, *ELFStr)); | 160 ObjectWriter.reset(new ELFObjectWriter(*this, *ELFStr)); |
| 161 } | 161 } |
| 162 } | 162 } |
| 163 | 163 |
| 164 void GlobalContext::translateFunctions() { | 164 void GlobalContext::translateFunctions() { |
| 165 while (std::unique_ptr<Cfg> Func = cfgQueueBlockingPop()) { | 165 while (std::unique_ptr<Cfg> Func = cfgQueueBlockingPop()) { |
| 166 // Install Func in TLS for Cfg-specific container allocators. | 166 // Install Func in TLS for Cfg-specific container allocators. |
| 167 Cfg::setCurrentCfg(Func.get()); | 167 Cfg::setCurrentCfg(Func.get()); |
| 168 // Reset per-function stats being accumulated in TLS. | 168 // Reset per-function stats being accumulated in TLS. |
| 169 resetStats(); | 169 resetStats(); |
| 170 // Set verbose level to none if the current function does NOT | 170 // Set verbose level to none if the current function does NOT |
| 171 // match the -verbose-focus command-line option. | 171 // match the -verbose-focus command-line option. |
| 172 if (!matchSymbolName(Func->getFunctionName(), getFlags().VerboseFocusOn)) | 172 if (!matchSymbolName(Func->getFunctionName(), |
| 173 getFlags().getVerboseFocusOn())) |
| 173 Func->setVerbose(IceV_None); | 174 Func->setVerbose(IceV_None); |
| 174 // Disable translation if -notranslate is specified, or if the | 175 // Disable translation if -notranslate is specified, or if the |
| 175 // current function matches the -translate-only option. If | 176 // current function matches the -translate-only option. If |
| 176 // translation is disabled, just dump the high-level IR and | 177 // translation is disabled, just dump the high-level IR and |
| 177 // continue. | 178 // continue. |
| 178 if (getFlags().DisableTranslation || | 179 if (getFlags().getDisableTranslation() || |
| 179 !matchSymbolName(Func->getFunctionName(), getFlags().TranslateOnly)) { | 180 !matchSymbolName(Func->getFunctionName(), |
| 181 getFlags().getTranslateOnly())) { |
| 180 Func->dump(); | 182 Func->dump(); |
| 181 } else { | 183 } else { |
| 182 Func->translate(); | 184 Func->translate(); |
| 183 if (Func->hasError()) { | 185 if (Func->hasError()) { |
| 184 getErrorStatus()->assign(EC_Translation); | 186 getErrorStatus()->assign(EC_Translation); |
| 185 OstreamLocker L(this); | 187 OstreamLocker L(this); |
| 186 getStrDump() << "ICE translation error: " << Func->getError() << "\n"; | 188 getStrDump() << "ICE translation error: " << Func->getError() << "\n"; |
| 187 } else { | 189 } else { |
| 188 if (getFlags().UseIntegratedAssembler) | 190 if (getFlags().getUseIntegratedAssembler()) |
| 189 Func->emitIAS(); | 191 Func->emitIAS(); |
| 190 else | 192 else |
| 191 Func->emit(); | 193 Func->emit(); |
| 192 // TODO(stichnot): actually add to emit queue | 194 // TODO(stichnot): actually add to emit queue |
| 193 } | 195 } |
| 194 dumpStats(Func->getFunctionName()); | 196 dumpStats(Func->getFunctionName()); |
| 195 } | 197 } |
| 196 Cfg::setCurrentCfg(nullptr); | 198 Cfg::setCurrentCfg(nullptr); |
| 197 // The Cfg now gets deleted as Func goes out of scope. | 199 // The Cfg now gets deleted as Func goes out of scope. |
| 198 } | 200 } |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 // to modify queue elements. | 557 // to modify queue elements. |
| 556 void GlobalContext::cfgQueueBlockingPush(std::unique_ptr<Cfg> Func) { | 558 void GlobalContext::cfgQueueBlockingPush(std::unique_ptr<Cfg> Func) { |
| 557 CfgQ.blockingPush(Func.release()); | 559 CfgQ.blockingPush(Func.release()); |
| 558 } | 560 } |
| 559 | 561 |
| 560 std::unique_ptr<Cfg> GlobalContext::cfgQueueBlockingPop() { | 562 std::unique_ptr<Cfg> GlobalContext::cfgQueueBlockingPop() { |
| 561 return std::unique_ptr<Cfg>(CfgQ.blockingPop()); | 563 return std::unique_ptr<Cfg>(CfgQ.blockingPop()); |
| 562 } | 564 } |
| 563 | 565 |
| 564 void GlobalContext::dumpStats(const IceString &Name, bool Final) { | 566 void GlobalContext::dumpStats(const IceString &Name, bool Final) { |
| 565 if (!ALLOW_DUMP || !getFlags().DumpStats) | 567 if (!getFlags().getDumpStats()) |
| 566 return; | 568 return; |
| 567 OstreamLocker OL(this); | 569 OstreamLocker OL(this); |
| 568 if (Final) { | 570 if (Final) { |
| 569 getStatsCumulative()->dump(Name, getStrDump()); | 571 getStatsCumulative()->dump(Name, getStrDump()); |
| 570 } else { | 572 } else { |
| 571 ICE_TLS_GET_FIELD(TLS)->StatsFunction.dump(Name, getStrDump()); | 573 ICE_TLS_GET_FIELD(TLS)->StatsFunction.dump(Name, getStrDump()); |
| 572 } | 574 } |
| 573 } | 575 } |
| 574 | 576 |
| 575 void GlobalContext::dumpTimers(TimerStackIdT StackID, bool DumpCumulative) { | 577 void GlobalContext::dumpTimers(TimerStackIdT StackID, bool DumpCumulative) { |
| 576 if (!ALLOW_DUMP) | 578 if (!ALLOW_DUMP) |
| 577 return; | 579 return; |
| 578 auto Timers = getTimers(); | 580 auto Timers = getTimers(); |
| 579 assert(Timers->size() > StackID); | 581 assert(Timers->size() > StackID); |
| 580 OstreamLocker L(this); | 582 OstreamLocker L(this); |
| 581 Timers->at(StackID).dump(getStrDump(), DumpCumulative); | 583 Timers->at(StackID).dump(getStrDump(), DumpCumulative); |
| 582 } | 584 } |
| 583 | 585 |
| 584 void TimerMarker::push() { | 586 void TimerMarker::push() { |
| 585 switch (StackID) { | 587 switch (StackID) { |
| 586 case GlobalContext::TSK_Default: | 588 case GlobalContext::TSK_Default: |
| 587 Active = Ctx->getFlags().SubzeroTimingEnabled; | 589 Active = Ctx->getFlags().getSubzeroTimingEnabled(); |
| 588 break; | 590 break; |
| 589 case GlobalContext::TSK_Funcs: | 591 case GlobalContext::TSK_Funcs: |
| 590 Active = Ctx->getFlags().TimeEachFunction; | 592 Active = Ctx->getFlags().getTimeEachFunction(); |
| 591 break; | 593 break; |
| 592 default: | 594 default: |
| 593 break; | 595 break; |
| 594 } | 596 } |
| 595 if (Active) | 597 if (Active) |
| 596 Ctx->pushTimer(ID, StackID); | 598 Ctx->pushTimer(ID, StackID); |
| 597 } | 599 } |
| 598 | 600 |
| 599 void TimerMarker::pushCfg(const Cfg *Func) { | 601 void TimerMarker::pushCfg(const Cfg *Func) { |
| 600 Ctx = Func->getContext(); | 602 Ctx = Func->getContext(); |
| 601 Active = Func->getFocusedTiming() || Ctx->getFlags().SubzeroTimingEnabled; | 603 Active = |
| 604 Func->getFocusedTiming() || Ctx->getFlags().getSubzeroTimingEnabled(); |
| 602 if (Active) | 605 if (Active) |
| 603 Ctx->pushTimer(ID, StackID); | 606 Ctx->pushTimer(ID, StackID); |
| 604 } | 607 } |
| 605 | 608 |
| 606 ICE_TLS_DEFINE_FIELD(GlobalContext::ThreadContext *, GlobalContext, TLS); | 609 ICE_TLS_DEFINE_FIELD(GlobalContext::ThreadContext *, GlobalContext, TLS); |
| 607 | 610 |
| 608 } // end of namespace Ice | 611 } // end of namespace Ice |
| OLD | NEW |