Chromium Code Reviews

Side by Side Diff: src/IceGlobalContext.cpp

Issue 1834473002: Allow Subzero to parse function blocks in parallel. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Clean up code. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
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 /// \file 10 /// \file
(...skipping 238 matching lines...)
249 Str << "|ExtRel=" << Pool->ExternRelocatables.size(); 249 Str << "|ExtRel=" << Pool->ExternRelocatables.size();
250 } 250 }
251 Str << "\n"; 251 Str << "\n";
252 } 252 }
253 253
254 GlobalContext::GlobalContext(Ostream *OsDump, Ostream *OsEmit, Ostream *OsError, 254 GlobalContext::GlobalContext(Ostream *OsDump, Ostream *OsEmit, Ostream *OsError,
255 ELFStreamer *ELFStr) 255 ELFStreamer *ELFStr)
256 : ConstPool(new ConstantPool()), ErrorStatus(), StrDump(OsDump), 256 : ConstPool(new ConstantPool()), ErrorStatus(), StrDump(OsDump),
257 StrEmit(OsEmit), StrError(OsError), ObjectWriter(), 257 StrEmit(OsEmit), StrError(OsError), ObjectWriter(),
258 OptQ(/*Sequential=*/Flags.isSequential(), 258 OptQ(/*Sequential=*/Flags.isSequential(),
259 /*MaxSize=*/Flags.getNumTranslationThreads()), 259 /*MaxSize=*/
260 (Flags.getParseParallel() && Flags.getBuildOnRead())
261 ? MaxOptQSize
262 : Flags.getNumTranslationThreads()),
260 // EmitQ is allowed unlimited size. 263 // EmitQ is allowed unlimited size.
261 EmitQ(/*Sequential=*/Flags.isSequential()), 264 EmitQ(/*Sequential=*/Flags.isSequential()),
262 DataLowering(TargetDataLowering::createLowering(this)) { 265 DataLowering(TargetDataLowering::createLowering(this)) {
263 assert(OsDump && "OsDump is not defined for GlobalContext"); 266 assert(OsDump && "OsDump is not defined for GlobalContext");
264 assert(OsEmit && "OsEmit is not defined for GlobalContext"); 267 assert(OsEmit && "OsEmit is not defined for GlobalContext");
265 assert(OsError && "OsError is not defined for GlobalContext"); 268 assert(OsError && "OsError is not defined for GlobalContext");
266 // Make sure thread_local fields are properly initialized before any 269 // Make sure thread_local fields are properly initialized before any
267 // accesses are made. Do this here instead of at the start of 270 // accesses are made. Do this here instead of at the start of
268 // main() so that all clients (e.g. unit tests) can benefit for 271 // main() so that all clients (e.g. unit tests) can benefit for
269 // free. 272 // free.
(...skipping 32 matching lines...)
302 RuntimeHelperFunc[static_cast<size_t>(RuntimeHelper::H_##Tag)] = \ 305 RuntimeHelperFunc[static_cast<size_t>(RuntimeHelper::H_##Tag)] = \
303 getConstantExternSym(Name); 306 getConstantExternSym(Name);
304 RUNTIME_HELPER_FUNCTIONS_TABLE 307 RUNTIME_HELPER_FUNCTIONS_TABLE
305 #undef X 308 #undef X
306 309
307 TargetLowering::staticInit(this); 310 TargetLowering::staticInit(this);
308 } 311 }
309 312
310 void GlobalContext::translateFunctions() { 313 void GlobalContext::translateFunctions() {
311 TimerMarker Timer(TimerStack::TT_translateFunctions, this); 314 TimerMarker Timer(TimerStack::TT_translateFunctions, this);
312 while (std::unique_ptr<Cfg> Func = optQueueBlockingPop()) { 315 while (std::unique_ptr<OptWorkItem> OptItem = optQueueBlockingPop()) {
316 std::unique_ptr<Cfg> Func = OptItem->getParsedCfg();
313 // Install Func in TLS for Cfg-specific container allocators. 317 // Install Func in TLS for Cfg-specific container allocators.
314 CfgLocalAllocatorScope _(Func.get()); 318 CfgLocalAllocatorScope _(Func.get());
315 // Reset per-function stats being accumulated in TLS. 319 // Reset per-function stats being accumulated in TLS.
316 resetStats(); 320 resetStats();
317 // Set verbose level to none if the current function does NOT 321 // Set verbose level to none if the current function does NOT
318 // match the -verbose-focus command-line option. 322 // match the -verbose-focus command-line option.
319 if (!matchSymbolName(Func->getFunctionName(), 323 if (!matchSymbolName(Func->getFunctionName(),
320 getFlags().getVerboseFocusOn())) 324 getFlags().getVerboseFocusOn()))
321 Func->setVerbose(IceV_None); 325 Func->setVerbose(IceV_None);
322 // Disable translation if -notranslate is specified, or if the 326 // Disable translation if -notranslate is specified, or if the
(...skipping 537 matching lines...)
860 const IceString &NewName) { 864 const IceString &NewName) {
861 auto Timers = &ICE_TLS_GET_FIELD(TLS)->Timers; 865 auto Timers = &ICE_TLS_GET_FIELD(TLS)->Timers;
862 assert(StackID < Timers->size()); 866 assert(StackID < Timers->size());
863 Timers->at(StackID).setName(NewName); 867 Timers->at(StackID).setName(NewName);
864 } 868 }
865 869
866 // Note: optQueueBlockingPush and optQueueBlockingPop use unique_ptr at the 870 // Note: optQueueBlockingPush and optQueueBlockingPop use unique_ptr at the
867 // interface to take and transfer ownership, but they internally store the raw 871 // interface to take and transfer ownership, but they internally store the raw
868 // Cfg pointer in the work queue. This allows e.g. future queue optimizations 872 // Cfg pointer in the work queue. This allows e.g. future queue optimizations
869 // such as the use of atomics to modify queue elements. 873 // such as the use of atomics to modify queue elements.
870 void GlobalContext::optQueueBlockingPush(std::unique_ptr<Cfg> Func) { 874 void GlobalContext::optQueueBlockingPush(std::unique_ptr<OptWorkItem> Item) {
871 assert(Func); 875 assert(Item);
872 { 876 {
873 TimerMarker _(TimerStack::TT_qTransPush, this); 877 TimerMarker _(TimerStack::TT_qTransPush, this);
874 OptQ.blockingPush(std::move(Func)); 878 OptQ.blockingPush(std::move(Item));
875 } 879 }
876 if (getFlags().isSequential()) 880 if (getFlags().isSequential())
877 translateFunctions(); 881 translateFunctions();
878 } 882 }
879 883
880 std::unique_ptr<Cfg> GlobalContext::optQueueBlockingPop() { 884 std::unique_ptr<OptWorkItem> GlobalContext::optQueueBlockingPop() {
881 TimerMarker _(TimerStack::TT_qTransPop, this); 885 TimerMarker _(TimerStack::TT_qTransPop, this);
882 return std::unique_ptr<Cfg>(OptQ.blockingPop()); 886 return std::unique_ptr<OptWorkItem>(OptQ.blockingPop());
883 } 887 }
884 888
885 void GlobalContext::emitQueueBlockingPush( 889 void GlobalContext::emitQueueBlockingPush(
886 std::unique_ptr<EmitterWorkItem> Item) { 890 std::unique_ptr<EmitterWorkItem> Item) {
887 assert(Item); 891 assert(Item);
888 { 892 {
889 TimerMarker _(TimerStack::TT_qEmitPush, this); 893 TimerMarker _(TimerStack::TT_qEmitPush, this);
890 EmitQ.blockingPush(std::move(Item)); 894 EmitQ.blockingPush(std::move(Item));
891 } 895 }
892 if (getFlags().isSequential()) 896 if (getFlags().isSequential())
(...skipping 54 matching lines...)
947 Ctx = Func->getContext(); 951 Ctx = Func->getContext();
948 Active = 952 Active =
949 Func->getFocusedTiming() || Ctx->getFlags().getSubzeroTimingEnabled(); 953 Func->getFocusedTiming() || Ctx->getFlags().getSubzeroTimingEnabled();
950 if (Active) 954 if (Active)
951 Ctx->pushTimer(ID, StackID); 955 Ctx->pushTimer(ID, StackID);
952 } 956 }
953 957
954 ICE_TLS_DEFINE_FIELD(GlobalContext::ThreadContext *, GlobalContext, TLS); 958 ICE_TLS_DEFINE_FIELD(GlobalContext::ThreadContext *, GlobalContext, TLS);
955 959
956 } // end of namespace Ice 960 } // end of namespace Ice
OLDNEW

Powered by Google App Engine