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

Side by Side Diff: src/IceGlobalContext.cpp

Issue 2896133003: Do not inline GlobalContext TLS methods. (Closed)
Patch Set: Created 3 years, 7 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
« no previous file with comments | « src/IceGlobalContext.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 auto *Revision = VariableDeclaration::create(&Globals, true); 365 auto *Revision = VariableDeclaration::create(&Globals, true);
366 Revision->setName(this, "__Sz_revision"); 366 Revision->setName(this, "__Sz_revision");
367 Revision->setIsConstant(true); 367 Revision->setIsConstant(true);
368 const char *RevisionString = getSubzeroRevision(); 368 const char *RevisionString = getSubzeroRevision();
369 Revision->addInitializer(VariableDeclaration::DataInitializer::create( 369 Revision->addInitializer(VariableDeclaration::DataInitializer::create(
370 &Globals, RevisionString, 1 + strlen(RevisionString))); 370 &Globals, RevisionString, 1 + strlen(RevisionString)));
371 Globals.push_back(Revision); 371 Globals.push_back(Revision);
372 } 372 }
373 } 373 }
374 374
375 void GlobalContext::translateFunctionsWrapper(ThreadContext *MyTLS) {
376 ICE_TLS_SET_FIELD(TLS, MyTLS);
377 translateFunctions();
378 }
379
375 void GlobalContext::translateFunctions() { 380 void GlobalContext::translateFunctions() {
376 TimerMarker Timer(TimerStack::TT_translateFunctions, this); 381 TimerMarker Timer(TimerStack::TT_translateFunctions, this);
377 while (std::unique_ptr<OptWorkItem> OptItem = optQueueBlockingPop()) { 382 while (std::unique_ptr<OptWorkItem> OptItem = optQueueBlockingPop()) {
378 std::unique_ptr<EmitterWorkItem> Item; 383 std::unique_ptr<EmitterWorkItem> Item;
379 auto Func = OptItem->getParsedCfg(); 384 auto Func = OptItem->getParsedCfg();
380 // Install Func in TLS for Cfg-specific container allocators. 385 // Install Func in TLS for Cfg-specific container allocators.
381 CfgLocalAllocatorScope _(Func.get()); 386 CfgLocalAllocatorScope _(Func.get());
382 // Reset per-function stats being accumulated in TLS. 387 // Reset per-function stats being accumulated in TLS.
383 resetStats(); 388 resetStats();
384 // Set verbose level to none if the current function does NOT match the 389 // Set verbose level to none if the current function does NOT match the
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 452
448 // Ensure Pending is large enough that Pending[Index] is valid. 453 // Ensure Pending is large enough that Pending[Index] is valid.
449 void resizePending(std::vector<std::unique_ptr<EmitterWorkItem>> *Pending, 454 void resizePending(std::vector<std::unique_ptr<EmitterWorkItem>> *Pending,
450 uint32_t Index) { 455 uint32_t Index) {
451 if (Index >= Pending->size()) 456 if (Index >= Pending->size())
452 Utils::reserveAndResize(*Pending, Index + 1); 457 Utils::reserveAndResize(*Pending, Index + 1);
453 } 458 }
454 459
455 } // end of anonymous namespace 460 } // end of anonymous namespace
456 461
462 // static
463 void GlobalContext::TlsInit() {
464 ICE_TLS_INIT_FIELD(TLS);
465 }
466
457 void GlobalContext::emitFileHeader() { 467 void GlobalContext::emitFileHeader() {
458 TimerMarker T1(Ice::TimerStack::TT_emitAsm, this); 468 TimerMarker T1(Ice::TimerStack::TT_emitAsm, this);
459 if (getFlags().getOutFileType() == FT_Elf) { 469 if (getFlags().getOutFileType() == FT_Elf) {
460 getObjectWriter()->writeInitialELFHeader(); 470 getObjectWriter()->writeInitialELFHeader();
461 } else { 471 } else {
462 if (!BuildDefs::dump()) { 472 if (!BuildDefs::dump()) {
463 getStrError() << "emitFileHeader for non-ELF"; 473 getStrError() << "emitFileHeader for non-ELF";
464 getErrorStatus()->assign(EC_Translation); 474 getErrorStatus()->assign(EC_Translation);
465 } 475 }
466 TargetHeaderLowering::createLowering(this)->lower(); 476 TargetHeaderLowering::createLowering(this)->lower();
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 // architectures this will waste 4 bytes. 559 // architectures this will waste 4 bytes.
550 const SizeT Sizeof64BitNullPtr = typeWidthInBytes(IceType_i64); 560 const SizeT Sizeof64BitNullPtr = typeWidthInBytes(IceType_i64);
551 ProfileBlockInfoVarDecl->addInitializer( 561 ProfileBlockInfoVarDecl->addInitializer(
552 VariableDeclaration::ZeroInitializer::create(GlobalVariablePool.get(), 562 VariableDeclaration::ZeroInitializer::create(GlobalVariablePool.get(),
553 Sizeof64BitNullPtr)); 563 Sizeof64BitNullPtr));
554 Globals.push_back(ProfileBlockInfoVarDecl); 564 Globals.push_back(ProfileBlockInfoVarDecl);
555 constexpr char ProfileDataSection[] = "$sz_profiler$"; 565 constexpr char ProfileDataSection[] = "$sz_profiler$";
556 lowerGlobals(ProfileDataSection); 566 lowerGlobals(ProfileDataSection);
557 } 567 }
558 568
569 void GlobalContext::emitterWrapper(ThreadContext *MyTLS) {
570 ICE_TLS_SET_FIELD(TLS, MyTLS);
571 emitItems();
572 }
573
559 void GlobalContext::emitItems() { 574 void GlobalContext::emitItems() {
560 const bool Threaded = !getFlags().isSequential(); 575 const bool Threaded = !getFlags().isSequential();
561 // Pending is a vector containing the reassembled, ordered list of 576 // Pending is a vector containing the reassembled, ordered list of
562 // work items. When we're ready for the next item, we first check 577 // work items. When we're ready for the next item, we first check
563 // whether it's in the Pending list. If not, we take an item from 578 // whether it's in the Pending list. If not, we take an item from
564 // the work queue, and if it's not the item we're waiting for, we 579 // the work queue, and if it's not the item we're waiting for, we
565 // insert it into Pending and repeat. The work item is deleted 580 // insert it into Pending and repeat. The work item is deleted
566 // after it is processed. 581 // after it is processed.
567 std::vector<std::unique_ptr<EmitterWorkItem>> Pending; 582 std::vector<std::unique_ptr<EmitterWorkItem>> Pending;
568 uint32_t DesiredSequenceNumber = getFirstSequenceNumber(); 583 uint32_t DesiredSequenceNumber = getFirstSequenceNumber();
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
980 } 995 }
981 if (getFlags().isSequential()) 996 if (getFlags().isSequential())
982 emitItems(); 997 emitItems();
983 } 998 }
984 999
985 std::unique_ptr<EmitterWorkItem> GlobalContext::emitQueueBlockingPop() { 1000 std::unique_ptr<EmitterWorkItem> GlobalContext::emitQueueBlockingPop() {
986 TimerMarker _(TimerStack::TT_qEmitPop, this); 1001 TimerMarker _(TimerStack::TT_qEmitPop, this);
987 return EmitQ.blockingPop(); 1002 return EmitQ.blockingPop();
988 } 1003 }
989 1004
1005 void GlobalContext::initParserThread() {
1006 ThreadContext *Tls = new ThreadContext();
1007 auto Timers = getTimers();
1008 Timers->initInto(Tls->Timers);
1009 AllThreadContexts.push_back(Tls);
1010 ICE_TLS_SET_FIELD(TLS, Tls);
1011 }
1012
1013 void GlobalContext::startWorkerThreads() {
1014 size_t NumWorkers = getFlags().getNumTranslationThreads();
1015 auto Timers = getTimers();
1016 for (size_t i = 0; i < NumWorkers; ++i) {
1017 ThreadContext *WorkerTLS = new ThreadContext();
1018 Timers->initInto(WorkerTLS->Timers);
1019 AllThreadContexts.push_back(WorkerTLS);
1020 TranslationThreads.push_back(std::thread(
1021 &GlobalContext::translateFunctionsWrapper, this, WorkerTLS));
1022 }
1023 if (NumWorkers) {
1024 ThreadContext *WorkerTLS = new ThreadContext();
1025 Timers->initInto(WorkerTLS->Timers);
1026 AllThreadContexts.push_back(WorkerTLS);
1027 EmitterThreads.push_back(
1028 std::thread(&GlobalContext::emitterWrapper, this, WorkerTLS));
1029 }
1030 }
1031
1032 void GlobalContext::resetStats() {
1033 if (BuildDefs::dump())
1034 ICE_TLS_GET_FIELD(TLS)->StatsFunction.reset();
1035 }
1036
990 void GlobalContext::dumpStats(const Cfg *Func) { 1037 void GlobalContext::dumpStats(const Cfg *Func) {
991 if (!getFlags().getDumpStats()) 1038 if (!getFlags().getDumpStats())
992 return; 1039 return;
993 if (Func == nullptr) { 1040 if (Func == nullptr) {
994 getStatsCumulative()->dump(Func, this); 1041 getStatsCumulative()->dump(Func, this);
995 } else { 1042 } else {
996 ICE_TLS_GET_FIELD(TLS)->StatsFunction.dump(Func, this); 1043 ICE_TLS_GET_FIELD(TLS)->StatsFunction.dump(Func, this);
997 } 1044 }
998 } 1045 }
999 1046
1047 void GlobalContext::statsUpdateEmitted(uint32_t InstCount) {
1048 if (!getFlags().getDumpStats())
1049 return;
1050 ThreadContext *Tls = ICE_TLS_GET_FIELD(TLS);
1051 Tls->StatsFunction.update(CodeStats::CS_InstCount, InstCount);
1052 Tls->StatsCumulative.update(CodeStats::CS_InstCount, InstCount);
1053 }
1054
1055 void GlobalContext::statsUpdateRegistersSaved(uint32_t Num) {
1056 if (!getFlags().getDumpStats())
1057 return;
1058 ThreadContext *Tls = ICE_TLS_GET_FIELD(TLS);
1059 Tls->StatsFunction.update(CodeStats::CS_RegsSaved, Num);
1060 Tls->StatsCumulative.update(CodeStats::CS_RegsSaved, Num);
1061 }
1062
1063 void GlobalContext::statsUpdateFrameBytes(uint32_t Bytes) {
1064 if (!getFlags().getDumpStats())
1065 return;
1066 ThreadContext *Tls = ICE_TLS_GET_FIELD(TLS);
1067 Tls->StatsFunction.update(CodeStats::CS_FrameByte, Bytes);
1068 Tls->StatsCumulative.update(CodeStats::CS_FrameByte, Bytes);
1069 }
1070
1071 void GlobalContext::statsUpdateSpills() {
1072 if (!getFlags().getDumpStats())
1073 return;
1074 ThreadContext *Tls = ICE_TLS_GET_FIELD(TLS);
1075 Tls->StatsFunction.update(CodeStats::CS_NumSpills);
1076 Tls->StatsCumulative.update(CodeStats::CS_NumSpills);
1077 }
1078
1079 void GlobalContext::statsUpdateFills() {
1080 if (!getFlags().getDumpStats())
1081 return;
1082 ThreadContext *Tls = ICE_TLS_GET_FIELD(TLS);
1083 Tls->StatsFunction.update(CodeStats::CS_NumFills);
1084 Tls->StatsCumulative.update(CodeStats::CS_NumFills);
1085 }
1086
1087 void GlobalContext::statsUpdateRPImms() {
1088 if (!getFlags().getDumpStats())
1089 return;
1090 ThreadContext *Tls = ICE_TLS_GET_FIELD(TLS);
1091 Tls->StatsFunction.update(CodeStats::CS_NumRPImms);
1092 Tls->StatsCumulative.update(CodeStats::CS_NumRPImms);
1093 }
1094
1000 void GlobalContext::dumpTimers(TimerStackIdT StackID, bool DumpCumulative) { 1095 void GlobalContext::dumpTimers(TimerStackIdT StackID, bool DumpCumulative) {
1001 if (!BuildDefs::timers()) 1096 if (!BuildDefs::timers())
1002 return; 1097 return;
1003 auto Timers = getTimers(); 1098 auto Timers = getTimers();
1004 assert(Timers->size() > StackID); 1099 assert(Timers->size() > StackID);
1005 OstreamLocker L(this); 1100 OstreamLocker L(this);
1006 Timers->at(StackID).dump(getStrDump(), DumpCumulative); 1101 Timers->at(StackID).dump(getStrDump(), DumpCumulative);
1007 } 1102 }
1008 1103
1009 void GlobalContext::dumpLocalTimers(const std::string &TimerNameOverride, 1104 void GlobalContext::dumpLocalTimers(const std::string &TimerNameOverride,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1058 void TimerMarker::pushCfg(const Cfg *Func) { 1153 void TimerMarker::pushCfg(const Cfg *Func) {
1059 Ctx = Func->getContext(); 1154 Ctx = Func->getContext();
1060 Active = Func->getFocusedTiming() || getFlags().getSubzeroTimingEnabled(); 1155 Active = Func->getFocusedTiming() || getFlags().getSubzeroTimingEnabled();
1061 if (Active) 1156 if (Active)
1062 Ctx->pushTimer(ID, StackID); 1157 Ctx->pushTimer(ID, StackID);
1063 } 1158 }
1064 1159
1065 ICE_TLS_DEFINE_FIELD(GlobalContext::ThreadContext *, GlobalContext, TLS); 1160 ICE_TLS_DEFINE_FIELD(GlobalContext::ThreadContext *, GlobalContext, TLS);
1066 1161
1067 } // end of namespace Ice 1162 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/IceGlobalContext.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698