| 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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 Str << MemUsed; | 122 Str << MemUsed; |
| 123 else | 123 else |
| 124 Str << "(requires '-track-memory')"; | 124 Str << "(requires '-track-memory')"; |
| 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 : ConstPool(new ConstantPool()), ErrorStatus(), StrDump(OsDump), |
| 133 ConstPool(new ConstantPool()), Arch(Arch), Opt(Opt), | 133 StrEmit(OsEmit), VMask(Mask), Arch(Arch), Opt(Opt), |
| 134 TestPrefix(TestPrefix), Flags(Flags), RNG(""), ObjectWriter() { | 134 TestPrefix(TestPrefix), Flags(Flags), RNG(""), ObjectWriter(), |
| 135 CfgQ(/*MaxSize=*/Flags.NumTranslationThreads, |
| 136 /*Sequential=*/(Flags.NumTranslationThreads == 0)) { |
| 135 // Make sure thread_local fields are properly initialized before any | 137 // Make sure thread_local fields are properly initialized before any |
| 136 // accesses are made. Do this here instead of at the start of | 138 // 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 | 139 // main() so that all clients (e.g. unit tests) can benefit for |
| 138 // free. | 140 // free. |
| 139 GlobalContext::TlsInit(); | 141 GlobalContext::TlsInit(); |
| 140 Cfg::TlsInit(); | 142 Cfg::TlsInit(); |
| 141 | |
| 142 // Create a new ThreadContext for the current thread. No need to | 143 // Create a new ThreadContext for the current thread. No need to |
| 143 // lock AllThreadContexts at this point since no other threads have | 144 // lock AllThreadContexts at this point since no other threads have |
| 144 // access yet to this GlobalContext object. | 145 // access yet to this GlobalContext object. |
| 145 AllThreadContexts.push_back(new ThreadContext()); | 146 AllThreadContexts.push_back(new ThreadContext()); |
| 146 ICE_TLS_SET_FIELD(TLS, AllThreadContexts.back()); | 147 ICE_TLS_SET_FIELD(TLS, AllThreadContexts.back()); |
| 147 // Pre-register built-in stack names. | 148 // Pre-register built-in stack names. |
| 148 if (ALLOW_DUMP) { | 149 if (ALLOW_DUMP) { |
| 149 // TODO(stichnot): There needs to be a strong relationship between | 150 // TODO(stichnot): There needs to be a strong relationship between |
| 150 // the newTimerStackID() return values and TSK_Default/TSK_Funcs. | 151 // the newTimerStackID() return values and TSK_Default/TSK_Funcs. |
| 151 newTimerStackID("Total across all functions"); | 152 newTimerStackID("Total across all functions"); |
| 152 newTimerStackID("Per-function summary"); | 153 newTimerStackID("Per-function summary"); |
| 153 } | 154 } |
| 154 if (Flags.UseELFWriter) { | 155 if (Flags.UseELFWriter) { |
| 155 ObjectWriter.reset(new ELFObjectWriter(*this, *ELFStr)); | 156 ObjectWriter.reset(new ELFObjectWriter(*this, *ELFStr)); |
| 156 } | 157 } |
| 157 } | 158 } |
| 158 | 159 |
| 160 void GlobalContext::translateFunctions() { |
| 161 while (Cfg *Func = cfgQueueBlockingPop()) { |
| 162 // Reset per-function stats being accumulated in TLS. |
| 163 resetStats(); |
| 164 // Install Func in TLS for Cfg-specific container allocators. |
| 165 Func->updateTLS(); |
| 166 // Set verbose level to none if the current function does NOT |
| 167 // match the -verbose-focus command-line option. |
| 168 if (!matchSymbolName(Func->getFunctionName(), getFlags().VerboseFocusOn)) |
| 169 Func->setVerbose(IceV_None); |
| 170 // Disable translation if -notranslate is specified, or if the |
| 171 // current function matches the -translate-only option. If |
| 172 // translation is disabled, just dump the high-level IR and |
| 173 // continue. |
| 174 if (getFlags().DisableTranslation || |
| 175 !matchSymbolName(Func->getFunctionName(), getFlags().TranslateOnly)) { |
| 176 Func->dump(); |
| 177 } else { |
| 178 Func->translate(); |
| 179 if (Func->hasError()) { |
| 180 getErrorStatus()->assign(EC_Translation); |
| 181 OstreamLocker L(this); |
| 182 getStrDump() << "ICE translation error: " << Func->getError() << "\n"; |
| 183 } else { |
| 184 if (getFlags().UseIntegratedAssembler) |
| 185 Func->emitIAS(); |
| 186 else |
| 187 Func->emit(); |
| 188 // TODO(stichnot): actually add to emit queue |
| 189 } |
| 190 // TODO(stichnot): fix multithreaded stats dumping. |
| 191 dumpStats(Func->getFunctionName()); |
| 192 } |
| 193 delete Func; |
| 194 } |
| 195 } |
| 196 |
| 159 // Scan a string for S[0-9A-Z]*_ patterns and replace them with | 197 // Scan a string for S[0-9A-Z]*_ patterns and replace them with |
| 160 // S<num>_ where <num> is the next base-36 value. If a type name | 198 // S<num>_ where <num> is the next base-36 value. If a type name |
| 161 // legitimately contains that pattern, then the substitution will be | 199 // legitimately contains that pattern, then the substitution will be |
| 162 // made in error and most likely the link will fail. In this case, | 200 // made in error and most likely the link will fail. In this case, |
| 163 // the test classes can be rewritten not to use that pattern, which is | 201 // the test classes can be rewritten not to use that pattern, which is |
| 164 // much simpler and more reliable than implementing a full demangling | 202 // much simpler and more reliable than implementing a full demangling |
| 165 // parser. Another substitution-in-error may occur if a type | 203 // parser. Another substitution-in-error may occur if a type |
| 166 // identifier ends with the pattern S[0-9A-Z]*, because an immediately | 204 // identifier ends with the pattern S[0-9A-Z]*, because an immediately |
| 167 // following substitution string like "S1_" or "PS1_" may be combined | 205 // following substitution string like "S1_" or "PS1_" may be combined |
| 168 // with the previous type. | 206 // with the previous type. |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 } | 502 } |
| 465 | 503 |
| 466 TimerIdT GlobalContext::getTimerID(TimerStackIdT StackID, | 504 TimerIdT GlobalContext::getTimerID(TimerStackIdT StackID, |
| 467 const IceString &Name) { | 505 const IceString &Name) { |
| 468 auto Timers = getTimers(); | 506 auto Timers = getTimers(); |
| 469 assert(StackID < Timers->size()); | 507 assert(StackID < Timers->size()); |
| 470 return Timers->at(StackID).getTimerID(Name); | 508 return Timers->at(StackID).getTimerID(Name); |
| 471 } | 509 } |
| 472 | 510 |
| 473 void GlobalContext::pushTimer(TimerIdT ID, TimerStackIdT StackID) { | 511 void GlobalContext::pushTimer(TimerIdT ID, TimerStackIdT StackID) { |
| 512 // TODO(stichnot): Timers are completely broken for multithreading; fix. |
| 513 if (getFlags().NumTranslationThreads) |
| 514 llvm::report_fatal_error("Timers and multithreading are currently broken"); |
| 474 auto Timers = getTimers(); | 515 auto Timers = getTimers(); |
| 475 assert(StackID < Timers->size()); | 516 assert(StackID < Timers->size()); |
| 476 Timers->at(StackID).push(ID); | 517 Timers->at(StackID).push(ID); |
| 477 } | 518 } |
| 478 | 519 |
| 479 void GlobalContext::popTimer(TimerIdT ID, TimerStackIdT StackID) { | 520 void GlobalContext::popTimer(TimerIdT ID, TimerStackIdT StackID) { |
| 521 // TODO(stichnot): Timers are completely broken for multithreading; fix. |
| 522 if (getFlags().NumTranslationThreads) |
| 523 llvm::report_fatal_error("Timers and multithreading are currently broken"); |
| 480 auto Timers = getTimers(); | 524 auto Timers = getTimers(); |
| 481 assert(StackID < Timers->size()); | 525 assert(StackID < Timers->size()); |
| 482 Timers->at(StackID).pop(ID); | 526 Timers->at(StackID).pop(ID); |
| 483 } | 527 } |
| 484 | 528 |
| 485 void GlobalContext::resetTimer(TimerStackIdT StackID) { | 529 void GlobalContext::resetTimer(TimerStackIdT StackID) { |
| 486 auto Timers = getTimers(); | 530 auto Timers = getTimers(); |
| 487 assert(StackID < Timers->size()); | 531 assert(StackID < Timers->size()); |
| 488 Timers->at(StackID).reset(); | 532 Timers->at(StackID).reset(); |
| 489 } | 533 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 if (ALLOW_DUMP) { | 565 if (ALLOW_DUMP) { |
| 522 Active = Func->getFocusedTiming() || Ctx->getFlags().SubzeroTimingEnabled; | 566 Active = Func->getFocusedTiming() || Ctx->getFlags().SubzeroTimingEnabled; |
| 523 if (Active) | 567 if (Active) |
| 524 Ctx->pushTimer(ID); | 568 Ctx->pushTimer(ID); |
| 525 } | 569 } |
| 526 } | 570 } |
| 527 | 571 |
| 528 ICE_TLS_DEFINE_FIELD(GlobalContext::ThreadContext *, GlobalContext, TLS); | 572 ICE_TLS_DEFINE_FIELD(GlobalContext::ThreadContext *, GlobalContext, TLS); |
| 529 | 573 |
| 530 } // end of namespace Ice | 574 } // end of namespace Ice |
| OLD | NEW |