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 /// \file | 10 /// \file |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 if (Func != nullptr) { | 280 if (Func != nullptr) { |
281 Str << "|" << Name << "|Cfg Memory |" << Func->getTotalMemoryMB() | 281 Str << "|" << Name << "|Cfg Memory |" << Func->getTotalMemoryMB() |
282 << " MB\n"; | 282 << " MB\n"; |
283 } | 283 } |
284 } | 284 } |
285 | 285 |
286 GlobalContext::GlobalContext(Ostream *OsDump, Ostream *OsEmit, Ostream *OsError, | 286 GlobalContext::GlobalContext(Ostream *OsDump, Ostream *OsEmit, Ostream *OsError, |
287 ELFStreamer *ELFStr) | 287 ELFStreamer *ELFStr) |
288 : Strings(new StringPool()), ConstPool(new ConstantPool()), ErrorStatus(), | 288 : Strings(new StringPool()), ConstPool(new ConstantPool()), ErrorStatus(), |
289 StrDump(OsDump), StrEmit(OsEmit), StrError(OsError), IntrinsicsInfo(this), | 289 StrDump(OsDump), StrEmit(OsEmit), StrError(OsError), IntrinsicsInfo(this), |
290 ObjectWriter(), | 290 ObjectWriter(), OptQ(/*Sequential=*/getFlags().isSequential(), |
291 OptQ(/*Sequential=*/Flags.isSequential(), | 291 /*MaxSize=*/ |
292 /*MaxSize=*/ | 292 getFlags().isParseParallel() |
293 Flags.isParseParallel() ? MaxOptQSize | 293 ? MaxOptQSize |
294 : Flags.getNumTranslationThreads()), | 294 : getFlags().getNumTranslationThreads()), |
295 // EmitQ is allowed unlimited size. | 295 // EmitQ is allowed unlimited size. |
296 EmitQ(/*Sequential=*/Flags.isSequential()), | 296 EmitQ(/*Sequential=*/getFlags().isSequential()), |
297 DataLowering(TargetDataLowering::createLowering(this)) { | 297 DataLowering(TargetDataLowering::createLowering(this)) { |
298 assert(OsDump && "OsDump is not defined for GlobalContext"); | 298 assert(OsDump && "OsDump is not defined for GlobalContext"); |
299 assert(OsEmit && "OsEmit is not defined for GlobalContext"); | 299 assert(OsEmit && "OsEmit is not defined for GlobalContext"); |
300 assert(OsError && "OsError is not defined for GlobalContext"); | 300 assert(OsError && "OsError is not defined for GlobalContext"); |
301 // Make sure thread_local fields are properly initialized before any | 301 // Make sure thread_local fields are properly initialized before any |
302 // accesses are made. Do this here instead of at the start of | 302 // accesses are made. Do this here instead of at the start of |
303 // main() so that all clients (e.g. unit tests) can benefit for | 303 // main() so that all clients (e.g. unit tests) can benefit for |
304 // free. | 304 // free. |
305 GlobalContext::TlsInit(); | 305 GlobalContext::TlsInit(); |
306 Cfg::TlsInit(); | 306 Cfg::TlsInit(); |
307 // Create a new ThreadContext for the current thread. No need to | 307 // Create a new ThreadContext for the current thread. No need to |
308 // lock AllThreadContexts at this point since no other threads have | 308 // lock AllThreadContexts at this point since no other threads have |
309 // access yet to this GlobalContext object. | 309 // access yet to this GlobalContext object. |
310 ThreadContext *MyTLS = new ThreadContext(); | 310 ThreadContext *MyTLS = new ThreadContext(); |
311 AllThreadContexts.push_back(MyTLS); | 311 AllThreadContexts.push_back(MyTLS); |
312 ICE_TLS_SET_FIELD(TLS, MyTLS); | 312 ICE_TLS_SET_FIELD(TLS, MyTLS); |
313 // Pre-register built-in stack names. | 313 // Pre-register built-in stack names. |
314 if (BuildDefs::timers()) { | 314 if (BuildDefs::timers()) { |
315 // TODO(stichnot): There needs to be a strong relationship between | 315 // TODO(stichnot): There needs to be a strong relationship between |
316 // the newTimerStackID() return values and TSK_Default/TSK_Funcs. | 316 // the newTimerStackID() return values and TSK_Default/TSK_Funcs. |
317 newTimerStackID("Total across all functions"); | 317 newTimerStackID("Total across all functions"); |
318 newTimerStackID("Per-function summary"); | 318 newTimerStackID("Per-function summary"); |
319 } | 319 } |
320 Timers.initInto(MyTLS->Timers); | 320 Timers.initInto(MyTLS->Timers); |
321 switch (Flags.getOutFileType()) { | 321 switch (getFlags().getOutFileType()) { |
322 case FT_Elf: | 322 case FT_Elf: |
323 ObjectWriter.reset(new ELFObjectWriter(*this, *ELFStr)); | 323 ObjectWriter.reset(new ELFObjectWriter(*this, *ELFStr)); |
324 break; | 324 break; |
325 case FT_Asm: | 325 case FT_Asm: |
326 case FT_Iasm: | 326 case FT_Iasm: |
327 break; | 327 break; |
328 } | 328 } |
329 // Cache up front common constants. | 329 // Cache up front common constants. |
330 #define X(tag, sizeLog2, align, elts, elty, str, rcstr) \ | 330 #define X(tag, sizeLog2, align, elts, elty, str, rcstr) \ |
331 ConstZeroForType[IceType_##tag] = getConstantZeroInternal(IceType_##tag); | 331 ConstZeroForType[IceType_##tag] = getConstantZeroInternal(IceType_##tag); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 void GlobalContext::saveBlockInfoPtrs() { | 441 void GlobalContext::saveBlockInfoPtrs() { |
442 for (VariableDeclaration *Global : Globals) { | 442 for (VariableDeclaration *Global : Globals) { |
443 if (Cfg::isProfileGlobal(*Global)) { | 443 if (Cfg::isProfileGlobal(*Global)) { |
444 ProfileBlockInfos.push_back(Global); | 444 ProfileBlockInfos.push_back(Global); |
445 } | 445 } |
446 } | 446 } |
447 } | 447 } |
448 | 448 |
449 void GlobalContext::lowerGlobals(const std::string &SectionSuffix) { | 449 void GlobalContext::lowerGlobals(const std::string &SectionSuffix) { |
450 TimerMarker T(TimerStack::TT_emitGlobalInitializers, this); | 450 TimerMarker T(TimerStack::TT_emitGlobalInitializers, this); |
451 const bool DumpGlobalVariables = BuildDefs::dump() && | 451 const bool DumpGlobalVariables = |
452 (Flags.getVerbose() & IceV_GlobalInit) && | 452 BuildDefs::dump() && (getFlags().getVerbose() & IceV_GlobalInit) && |
453 Flags.getVerboseFocusOn().empty(); | 453 getFlags().getVerboseFocusOn().empty(); |
454 if (DumpGlobalVariables) { | 454 if (DumpGlobalVariables) { |
455 OstreamLocker L(this); | 455 OstreamLocker L(this); |
456 Ostream &Stream = getStrDump(); | 456 Ostream &Stream = getStrDump(); |
457 for (const Ice::VariableDeclaration *Global : Globals) { | 457 for (const Ice::VariableDeclaration *Global : Globals) { |
458 Global->dump(Stream); | 458 Global->dump(Stream); |
459 } | 459 } |
460 } | 460 } |
461 if (Flags.getDisableTranslation()) | 461 if (getFlags().getDisableTranslation()) |
462 return; | 462 return; |
463 | 463 |
464 saveBlockInfoPtrs(); | 464 saveBlockInfoPtrs(); |
465 // If we need to shuffle the layout of global variables, shuffle them now. | 465 // If we need to shuffle the layout of global variables, shuffle them now. |
466 if (getFlags().getReorderGlobalVariables()) { | 466 if (getFlags().getReorderGlobalVariables()) { |
467 // Create a random number generator for global variable reordering. | 467 // Create a random number generator for global variable reordering. |
468 RandomNumberGenerator RNG(getFlags().getRandomSeed(), | 468 RandomNumberGenerator RNG(getFlags().getRandomSeed(), |
469 RPE_GlobalVariableReordering); | 469 RPE_GlobalVariableReordering); |
470 RandomShuffle(Globals.begin(), Globals.end(), | 470 RandomShuffle(Globals.begin(), Globals.end(), |
471 [&RNG](int N) { return (uint32_t)RNG.next(N); }); | 471 [&RNG](int N) { return (uint32_t)RNG.next(N); }); |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
665 return; | 665 return; |
666 OstreamLocker _(this); | 666 OstreamLocker _(this); |
667 Ostream &Str = getStrDump(); | 667 Ostream &Str = getStrDump(); |
668 Str << "GlobalContext strings:\n"; | 668 Str << "GlobalContext strings:\n"; |
669 getStrings()->dump(Str); | 669 getStrings()->dump(Str); |
670 } | 670 } |
671 | 671 |
672 void GlobalContext::dumpConstantLookupCounts() { | 672 void GlobalContext::dumpConstantLookupCounts() { |
673 if (!BuildDefs::dump()) | 673 if (!BuildDefs::dump()) |
674 return; | 674 return; |
675 const bool DumpCounts = (Flags.getVerbose() & IceV_ConstPoolStats) && | 675 const bool DumpCounts = (getFlags().getVerbose() & IceV_ConstPoolStats) && |
676 Flags.getVerboseFocusOn().empty(); | 676 getFlags().getVerboseFocusOn().empty(); |
677 if (!DumpCounts) | 677 if (!DumpCounts) |
678 return; | 678 return; |
679 | 679 |
680 OstreamLocker _(this); | 680 OstreamLocker _(this); |
681 Ostream &Str = getStrDump(); | 681 Ostream &Str = getStrDump(); |
682 Str << "Constant pool use stats: count+value+type\n"; | 682 Str << "Constant pool use stats: count+value+type\n"; |
683 #define X(WhichPool) \ | 683 #define X(WhichPool) \ |
684 for (auto *C : getConstPool()->WhichPool.getConstantPool()) { \ | 684 for (auto *C : getConstPool()->WhichPool.getConstantPool()) { \ |
685 Str << C->getLookupCount() << " "; \ | 685 Str << C->getLookupCount() << " "; \ |
686 C->dump(Str); \ | 686 C->dump(Str); \ |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
966 assert(Timers->size() > StackID); | 966 assert(Timers->size() > StackID); |
967 OstreamLocker L(this); | 967 OstreamLocker L(this); |
968 Timers->at(StackID).dump(getStrDump(), DumpCumulative); | 968 Timers->at(StackID).dump(getStrDump(), DumpCumulative); |
969 } | 969 } |
970 | 970 |
971 LockedPtr<StringPool> | 971 LockedPtr<StringPool> |
972 GlobalStringPoolTraits::getStrings(const GlobalContext *PoolOwner) { | 972 GlobalStringPoolTraits::getStrings(const GlobalContext *PoolOwner) { |
973 return PoolOwner->getStrings(); | 973 return PoolOwner->getStrings(); |
974 } | 974 } |
975 | 975 |
976 ClFlags GlobalContext::Flags; | |
977 | |
978 TimerIdT TimerMarker::getTimerIdFromFuncName(GlobalContext *Ctx, | 976 TimerIdT TimerMarker::getTimerIdFromFuncName(GlobalContext *Ctx, |
979 const std::string &FuncName) { | 977 const std::string &FuncName) { |
980 if (!BuildDefs::timers()) | 978 if (!BuildDefs::timers()) |
981 return 0; | 979 return 0; |
982 if (!Ctx->getFlags().getTimeEachFunction()) | 980 if (!getFlags().getTimeEachFunction()) |
983 return 0; | 981 return 0; |
984 return Ctx->getTimerID(GlobalContext::TSK_Funcs, FuncName); | 982 return Ctx->getTimerID(GlobalContext::TSK_Funcs, FuncName); |
985 } | 983 } |
986 | 984 |
987 void TimerMarker::push() { | 985 void TimerMarker::push() { |
988 switch (StackID) { | 986 switch (StackID) { |
989 case GlobalContext::TSK_Default: | 987 case GlobalContext::TSK_Default: |
990 Active = Ctx->getFlags().getSubzeroTimingEnabled(); | 988 Active = getFlags().getSubzeroTimingEnabled(); |
991 break; | 989 break; |
992 case GlobalContext::TSK_Funcs: | 990 case GlobalContext::TSK_Funcs: |
993 Active = Ctx->getFlags().getTimeEachFunction(); | 991 Active = getFlags().getTimeEachFunction(); |
994 break; | 992 break; |
995 default: | 993 default: |
996 break; | 994 break; |
997 } | 995 } |
998 if (Active) | 996 if (Active) |
999 Ctx->pushTimer(ID, StackID); | 997 Ctx->pushTimer(ID, StackID); |
1000 } | 998 } |
1001 | 999 |
1002 void TimerMarker::pushCfg(const Cfg *Func) { | 1000 void TimerMarker::pushCfg(const Cfg *Func) { |
1003 Ctx = Func->getContext(); | 1001 Ctx = Func->getContext(); |
1004 Active = | 1002 Active = Func->getFocusedTiming() || getFlags().getSubzeroTimingEnabled(); |
1005 Func->getFocusedTiming() || Ctx->getFlags().getSubzeroTimingEnabled(); | |
1006 if (Active) | 1003 if (Active) |
1007 Ctx->pushTimer(ID, StackID); | 1004 Ctx->pushTimer(ID, StackID); |
1008 } | 1005 } |
1009 | 1006 |
1010 ICE_TLS_DEFINE_FIELD(GlobalContext::ThreadContext *, GlobalContext, TLS); | 1007 ICE_TLS_DEFINE_FIELD(GlobalContext::ThreadContext *, GlobalContext, TLS); |
1011 | 1008 |
1012 } // end of namespace Ice | 1009 } // end of namespace Ice |
OLD | NEW |