Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(187)

Side by Side Diff: src/IceGlobalContext.cpp

Issue 870653002: Subzero: Initial implementation of multithreaded translation. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Fix getErrorStatus() usage in BitcodeMunger Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 : 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 CfgQ(Flags.NumTranslationThreads, (Flags.NumTranslationThreads == 0)),
JF 2015/01/23 17:22:43 Add /*MaxSize=*/ and /*Sequential=*/ here.
Jim Stichnoth 2015/01/23 21:54:02 Nice, done.
136 ErrorStatus() {
135 // Create a new ThreadContext for the current thread. No need to 137 // Create a new ThreadContext for the current thread. No need to
136 // lock AllThreadContexts at this point since no other threads have 138 // lock AllThreadContexts at this point since no other threads have
137 // access yet to this GlobalContext object. 139 // access yet to this GlobalContext object.
138 AllThreadContexts.push_back(new ThreadContext()); 140 AllThreadContexts.push_back(new ThreadContext());
139 TLS = AllThreadContexts.back(); 141 TLS = AllThreadContexts.back();
140 // Pre-register built-in stack names. 142 // Pre-register built-in stack names.
141 if (ALLOW_DUMP) { 143 if (ALLOW_DUMP) {
142 // TODO(stichnot): There needs to be a strong relationship between 144 // TODO(stichnot): There needs to be a strong relationship between
143 // the newTimerStackID() return values and TSK_Default/TSK_Funcs. 145 // the newTimerStackID() return values and TSK_Default/TSK_Funcs.
144 newTimerStackID("Total across all functions"); 146 newTimerStackID("Total across all functions");
145 newTimerStackID("Per-function summary"); 147 newTimerStackID("Per-function summary");
146 } 148 }
147 if (Flags.UseELFWriter) { 149 if (Flags.UseELFWriter) {
148 ObjectWriter.reset(new ELFObjectWriter(*this, *ELFStr)); 150 ObjectWriter.reset(new ELFObjectWriter(*this, *ELFStr));
149 } 151 }
150 } 152 }
151 153
154 void GlobalContext::translateFunctions() {
155 while (Cfg *Func = cfgQueueGet()) {
156 // Reset per-function stats being accumulated in TLS.
157 resetStats();
158 // Install Func in TLS for Cfg-specific container allocators.
159 Func->updateTLS();
160 // Set verbose level to none if the current function does NOT
161 // match the -verbose-focus command-line option.
162 if (!matchSymbolName(Func->getFunctionName(), getFlags().VerboseFocusOn))
163 Func->setVerbose(IceV_None);
164 // Disable translation if -notranslate is specified, or if the
165 // current function matches the -translate-only option. If
166 // translation is disabled, just dump the high-level IR and
167 // continue.
168 if (getFlags().DisableTranslation ||
169 !matchSymbolName(Func->getFunctionName(), getFlags().TranslateOnly)) {
170 Func->dump();
171 } else {
172 Func->translate();
173 if (Func->hasError()) {
174 OstreamLocker L(this);
175 getStrDump() << "ICE translation error: " << Func->getError() << "\n";
176 ErrorStatus.assign(1, std::generic_category());
177 } else {
178 if (getFlags().UseIntegratedAssembler)
179 Func->emitIAS();
180 else
181 Func->emit();
182 // TODO(stichnot): actually add to emit queue
183 }
184 // TODO(stichnot): fix multithreaded stats dumping.
185 dumpStats(Func->getFunctionName());
186 }
187 delete Func;
188 }
189 }
190
152 // Scan a string for S[0-9A-Z]*_ patterns and replace them with 191 // Scan a string for S[0-9A-Z]*_ patterns and replace them with
153 // S<num>_ where <num> is the next base-36 value. If a type name 192 // S<num>_ where <num> is the next base-36 value. If a type name
154 // legitimately contains that pattern, then the substitution will be 193 // legitimately contains that pattern, then the substitution will be
155 // made in error and most likely the link will fail. In this case, 194 // made in error and most likely the link will fail. In this case,
156 // the test classes can be rewritten not to use that pattern, which is 195 // the test classes can be rewritten not to use that pattern, which is
157 // much simpler and more reliable than implementing a full demangling 196 // much simpler and more reliable than implementing a full demangling
158 // parser. Another substitution-in-error may occur if a type 197 // parser. Another substitution-in-error may occur if a type
159 // identifier ends with the pattern S[0-9A-Z]*, because an immediately 198 // identifier ends with the pattern S[0-9A-Z]*, because an immediately
160 // following substitution string like "S1_" or "PS1_" may be combined 199 // following substitution string like "S1_" or "PS1_" may be combined
161 // with the previous type. 200 // with the previous type.
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 } 496 }
458 497
459 TimerIdT GlobalContext::getTimerID(TimerStackIdT StackID, 498 TimerIdT GlobalContext::getTimerID(TimerStackIdT StackID,
460 const IceString &Name) { 499 const IceString &Name) {
461 auto Timers = getTimers(); 500 auto Timers = getTimers();
462 assert(StackID < Timers->size()); 501 assert(StackID < Timers->size());
463 return Timers->at(StackID).getTimerID(Name); 502 return Timers->at(StackID).getTimerID(Name);
464 } 503 }
465 504
466 void GlobalContext::pushTimer(TimerIdT ID, TimerStackIdT StackID) { 505 void GlobalContext::pushTimer(TimerIdT ID, TimerStackIdT StackID) {
506 // TODO(stichnot): Timers are completely broken for multithreading; fix.
507 if (getFlags().NumTranslationThreads)
508 llvm::report_fatal_error("Timers and multithreading are currently broken");
467 auto Timers = getTimers(); 509 auto Timers = getTimers();
468 assert(StackID < Timers->size()); 510 assert(StackID < Timers->size());
469 Timers->at(StackID).push(ID); 511 Timers->at(StackID).push(ID);
470 } 512 }
471 513
472 void GlobalContext::popTimer(TimerIdT ID, TimerStackIdT StackID) { 514 void GlobalContext::popTimer(TimerIdT ID, TimerStackIdT StackID) {
515 // TODO(stichnot): Timers are completely broken for multithreading; fix.
516 if (getFlags().NumTranslationThreads)
517 llvm::report_fatal_error("Timers and multithreading are currently broken");
473 auto Timers = getTimers(); 518 auto Timers = getTimers();
474 assert(StackID < Timers->size()); 519 assert(StackID < Timers->size());
475 Timers->at(StackID).pop(ID); 520 Timers->at(StackID).pop(ID);
476 } 521 }
477 522
478 void GlobalContext::resetTimer(TimerStackIdT StackID) { 523 void GlobalContext::resetTimer(TimerStackIdT StackID) {
479 auto Timers = getTimers(); 524 auto Timers = getTimers();
480 assert(StackID < Timers->size()); 525 assert(StackID < Timers->size());
481 Timers->at(StackID).reset(); 526 Timers->at(StackID).reset();
482 } 527 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 if (ALLOW_DUMP) { 559 if (ALLOW_DUMP) {
515 Active = Func->getFocusedTiming() || Ctx->getFlags().SubzeroTimingEnabled; 560 Active = Func->getFocusedTiming() || Ctx->getFlags().SubzeroTimingEnabled;
516 if (Active) 561 if (Active)
517 Ctx->pushTimer(ID); 562 Ctx->pushTimer(ID);
518 } 563 }
519 } 564 }
520 565
521 thread_local GlobalContext::ThreadContext *GlobalContext::TLS; 566 thread_local GlobalContext::ThreadContext *GlobalContext::TLS;
522 567
523 } // end of namespace Ice 568 } // end of namespace Ice
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698