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

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

Powered by Google App Engine
This is Rietveld 408576698