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

Side by Side Diff: src/IceGlobalContext.cpp

Issue 1784243006: Subzero: Improve the use of timers. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Code review changes Created 4 years, 9 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') | src/IceTargetLowering.cpp » ('j') | 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 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 // free. 269 // free.
270 GlobalContext::TlsInit(); 270 GlobalContext::TlsInit();
271 Cfg::TlsInit(); 271 Cfg::TlsInit();
272 // Create a new ThreadContext for the current thread. No need to 272 // Create a new ThreadContext for the current thread. No need to
273 // lock AllThreadContexts at this point since no other threads have 273 // lock AllThreadContexts at this point since no other threads have
274 // access yet to this GlobalContext object. 274 // access yet to this GlobalContext object.
275 ThreadContext *MyTLS = new ThreadContext(); 275 ThreadContext *MyTLS = new ThreadContext();
276 AllThreadContexts.push_back(MyTLS); 276 AllThreadContexts.push_back(MyTLS);
277 ICE_TLS_SET_FIELD(TLS, MyTLS); 277 ICE_TLS_SET_FIELD(TLS, MyTLS);
278 // Pre-register built-in stack names. 278 // Pre-register built-in stack names.
279 if (BuildDefs::dump()) { 279 if (BuildDefs::timers()) {
280 // TODO(stichnot): There needs to be a strong relationship between 280 // TODO(stichnot): There needs to be a strong relationship between
281 // the newTimerStackID() return values and TSK_Default/TSK_Funcs. 281 // the newTimerStackID() return values and TSK_Default/TSK_Funcs.
282 newTimerStackID("Total across all functions"); 282 newTimerStackID("Total across all functions");
283 newTimerStackID("Per-function summary"); 283 newTimerStackID("Per-function summary");
284 } 284 }
285 Timers.initInto(MyTLS->Timers); 285 Timers.initInto(MyTLS->Timers);
286 switch (Flags.getOutFileType()) { 286 switch (Flags.getOutFileType()) {
287 case FT_Elf: 287 case FT_Elf:
288 ObjectWriter.reset(new ELFObjectWriter(*this, *ELFStr)); 288 ObjectWriter.reset(new ELFObjectWriter(*this, *ELFStr));
289 break; 289 break;
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 800
801 JumpTableData & 801 JumpTableData &
802 GlobalContext::addJumpTable(const IceString &FuncName, SizeT Id, 802 GlobalContext::addJumpTable(const IceString &FuncName, SizeT Id,
803 const JumpTableData::TargetList &TargetList) { 803 const JumpTableData::TargetList &TargetList) {
804 auto JumpTableList = getJumpTableList(); 804 auto JumpTableList = getJumpTableList();
805 JumpTableList->emplace_back(FuncName, Id, TargetList); 805 JumpTableList->emplace_back(FuncName, Id, TargetList);
806 return JumpTableList->back(); 806 return JumpTableList->back();
807 } 807 }
808 808
809 TimerStackIdT GlobalContext::newTimerStackID(const IceString &Name) { 809 TimerStackIdT GlobalContext::newTimerStackID(const IceString &Name) {
810 if (!BuildDefs::dump()) 810 if (!BuildDefs::timers())
811 return 0; 811 return 0;
812 auto Timers = getTimers(); 812 auto Timers = getTimers();
813 TimerStackIdT NewID = Timers->size(); 813 TimerStackIdT NewID = Timers->size();
814 Timers->push_back(TimerStack(Name)); 814 Timers->push_back(TimerStack(Name));
815 return NewID; 815 return NewID;
816 } 816 }
817 817
818 TimerIdT GlobalContext::getTimerID(TimerStackIdT StackID, 818 TimerIdT GlobalContext::getTimerID(TimerStackIdT StackID,
819 const IceString &Name) { 819 const IceString &Name) {
820 auto Timers = &ICE_TLS_GET_FIELD(TLS)->Timers; 820 auto Timers = &ICE_TLS_GET_FIELD(TLS)->Timers;
(...skipping 25 matching lines...) Expand all
846 assert(StackID < Timers->size()); 846 assert(StackID < Timers->size());
847 Timers->at(StackID).setName(NewName); 847 Timers->at(StackID).setName(NewName);
848 } 848 }
849 849
850 // Note: optQueueBlockingPush and optQueueBlockingPop use unique_ptr at the 850 // Note: optQueueBlockingPush and optQueueBlockingPop use unique_ptr at the
851 // interface to take and transfer ownership, but they internally store the raw 851 // interface to take and transfer ownership, but they internally store the raw
852 // Cfg pointer in the work queue. This allows e.g. future queue optimizations 852 // Cfg pointer in the work queue. This allows e.g. future queue optimizations
853 // such as the use of atomics to modify queue elements. 853 // such as the use of atomics to modify queue elements.
854 void GlobalContext::optQueueBlockingPush(std::unique_ptr<Cfg> Func) { 854 void GlobalContext::optQueueBlockingPush(std::unique_ptr<Cfg> Func) {
855 assert(Func); 855 assert(Func);
856 OptQ.blockingPush(Func.release()); 856 {
857 TimerMarker _(TimerStack::TT_qTransPush, this);
858 OptQ.blockingPush(Func.release());
859 }
857 if (getFlags().isSequential()) 860 if (getFlags().isSequential())
858 translateFunctions(); 861 translateFunctions();
859 } 862 }
860 863
861 std::unique_ptr<Cfg> GlobalContext::optQueueBlockingPop() { 864 std::unique_ptr<Cfg> GlobalContext::optQueueBlockingPop() {
865 TimerMarker _(TimerStack::TT_qTransPop, this);
862 return std::unique_ptr<Cfg>(OptQ.blockingPop()); 866 return std::unique_ptr<Cfg>(OptQ.blockingPop());
863 } 867 }
864 868
865 void GlobalContext::emitQueueBlockingPush(EmitterWorkItem *Item) { 869 void GlobalContext::emitQueueBlockingPush(EmitterWorkItem *Item) {
866 assert(Item); 870 assert(Item);
867 EmitQ.blockingPush(Item); 871 {
872 TimerMarker _(TimerStack::TT_qEmitPush, this);
873 EmitQ.blockingPush(Item);
874 }
868 if (getFlags().isSequential()) 875 if (getFlags().isSequential())
869 emitItems(); 876 emitItems();
870 } 877 }
871 878
872 EmitterWorkItem *GlobalContext::emitQueueBlockingPop() { 879 EmitterWorkItem *GlobalContext::emitQueueBlockingPop() {
880 TimerMarker _(TimerStack::TT_qEmitPop, this);
873 return EmitQ.blockingPop(); 881 return EmitQ.blockingPop();
874 } 882 }
875 883
876 void GlobalContext::dumpStats(const IceString &Name, bool Final) { 884 void GlobalContext::dumpStats(const IceString &Name, bool Final) {
877 if (!getFlags().getDumpStats()) 885 if (!getFlags().getDumpStats())
878 return; 886 return;
879 if (Final) { 887 if (Final) {
880 getStatsCumulative()->dump(Name, this); 888 getStatsCumulative()->dump(Name, this);
881 } else { 889 } else {
882 ICE_TLS_GET_FIELD(TLS)->StatsFunction.dump(Name, this); 890 ICE_TLS_GET_FIELD(TLS)->StatsFunction.dump(Name, this);
883 } 891 }
884 } 892 }
885 893
886 void GlobalContext::dumpTimers(TimerStackIdT StackID, bool DumpCumulative) { 894 void GlobalContext::dumpTimers(TimerStackIdT StackID, bool DumpCumulative) {
887 if (!BuildDefs::dump()) 895 if (!BuildDefs::timers())
888 return; 896 return;
889 auto Timers = getTimers(); 897 auto Timers = getTimers();
890 assert(Timers->size() > StackID); 898 assert(Timers->size() > StackID);
891 OstreamLocker L(this); 899 OstreamLocker L(this);
892 Timers->at(StackID).dump(getStrDump(), DumpCumulative); 900 Timers->at(StackID).dump(getStrDump(), DumpCumulative);
893 } 901 }
894 902
895 ClFlags GlobalContext::Flags; 903 ClFlags GlobalContext::Flags;
896 ClFlagsExtra GlobalContext::ExtraFlags; 904 ClFlagsExtra GlobalContext::ExtraFlags;
897 905
906 TimerIdT TimerMarker::getTimerIdFromFuncName(GlobalContext *Ctx,
907 const IceString &FuncName) {
908 if (!BuildDefs::timers())
909 return 0;
910 if (!Ctx->getFlags().getTimeEachFunction())
911 return 0;
912 return Ctx->getTimerID(GlobalContext::TSK_Funcs, FuncName);
913 }
914
898 void TimerMarker::push() { 915 void TimerMarker::push() {
899 switch (StackID) { 916 switch (StackID) {
900 case GlobalContext::TSK_Default: 917 case GlobalContext::TSK_Default:
901 Active = Ctx->getFlags().getSubzeroTimingEnabled(); 918 Active = Ctx->getFlags().getSubzeroTimingEnabled();
902 break; 919 break;
903 case GlobalContext::TSK_Funcs: 920 case GlobalContext::TSK_Funcs:
904 Active = Ctx->getFlags().getTimeEachFunction(); 921 Active = Ctx->getFlags().getTimeEachFunction();
905 break; 922 break;
906 default: 923 default:
907 break; 924 break;
908 } 925 }
909 if (Active) 926 if (Active)
910 Ctx->pushTimer(ID, StackID); 927 Ctx->pushTimer(ID, StackID);
911 } 928 }
912 929
913 void TimerMarker::pushCfg(const Cfg *Func) { 930 void TimerMarker::pushCfg(const Cfg *Func) {
914 Ctx = Func->getContext(); 931 Ctx = Func->getContext();
915 Active = 932 Active =
916 Func->getFocusedTiming() || Ctx->getFlags().getSubzeroTimingEnabled(); 933 Func->getFocusedTiming() || Ctx->getFlags().getSubzeroTimingEnabled();
917 if (Active) 934 if (Active)
918 Ctx->pushTimer(ID, StackID); 935 Ctx->pushTimer(ID, StackID);
919 } 936 }
920 937
921 ICE_TLS_DEFINE_FIELD(GlobalContext::ThreadContext *, GlobalContext, TLS); 938 ICE_TLS_DEFINE_FIELD(GlobalContext::ThreadContext *, GlobalContext, TLS);
922 939
923 } // end of namespace Ice 940 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/IceGlobalContext.h ('k') | src/IceTargetLowering.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698