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

Side by Side Diff: src/IceGlobalContext.cpp

Issue 1848733002: Subzero: Refine the memory usage report with -szstats . (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Bug fix Created 4 years, 8 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 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 } 237 }
238 if (BuildDefs::dump()) { 238 if (BuildDefs::dump()) {
239 // Do a separate loop over AllThreadContexts to avoid holding two locks at 239 // Do a separate loop over AllThreadContexts to avoid holding two locks at
240 // once. 240 // once.
241 auto Stats = getStatsCumulative(); 241 auto Stats = getStatsCumulative();
242 for (ThreadContext *TLS : AllThreadContexts) 242 for (ThreadContext *TLS : AllThreadContexts)
243 Stats->add(TLS->StatsCumulative); 243 Stats->add(TLS->StatsCumulative);
244 } 244 }
245 } 245 }
246 246
247 void GlobalContext::CodeStats::dump(const std::string &Name, 247 void GlobalContext::CodeStats::dump(const Cfg *Func, GlobalContext *Ctx) {
248 GlobalContext *Ctx) {
249 if (!BuildDefs::dump()) 248 if (!BuildDefs::dump())
250 return; 249 return;
251 OstreamLocker _(Ctx); 250 OstreamLocker _(Ctx);
252 Ostream &Str = Ctx->getStrDump(); 251 Ostream &Str = Ctx->getStrDump();
252 const std::string Name =
253 (Func == nullptr ? "_FINAL_" : Func->getFunctionNameAndSize());
253 #define X(str, tag) \ 254 #define X(str, tag) \
254 Str << "|" << Name << "|" str "|" << Stats[CS_##tag] << "\n"; 255 Str << "|" << Name << "|" str "|" << Stats[CS_##tag] << "\n";
255 CODESTATS_TABLE 256 CODESTATS_TABLE
256 #undef X 257 #undef X
257 Str << "|" << Name << "|Spills+Fills|" 258 Str << "|" << Name << "|Spills+Fills|"
258 << Stats[CS_NumSpills] + Stats[CS_NumFills] << "\n"; 259 << Stats[CS_NumSpills] + Stats[CS_NumFills] << "\n";
259 Str << "|" << Name << "|Memory Usage|"; 260 Str << "|" << Name << "|Memory Usage|";
260 if (ssize_t MemUsed = llvm::TimeRecord::getCurrentTime(false).getMemUsed()) 261 if (ssize_t MemUsed = llvm::TimeRecord::getCurrentTime(false).getMemUsed())
261 Str << MemUsed; 262 Str << MemUsed;
262 else 263 else
263 Str << "(requires '-track-memory')"; 264 Str << "(requires '-track-memory')";
264 Str << "\n"; 265 Str << "\n";
265 Str << "|" << Name << "|CPool Sizes "; 266 Str << "|" << Name << "|CPool Sizes ";
266 { 267 {
267 auto Pool = Ctx->getConstPool(); 268 auto Pool = Ctx->getConstPool();
268 Str << "|f32=" << Pool->Floats.size(); 269 Str << "|f32=" << Pool->Floats.size();
269 Str << "|f64=" << Pool->Doubles.size(); 270 Str << "|f64=" << Pool->Doubles.size();
270 Str << "|i1=" << Pool->Integers1.size(); 271 Str << "|i1=" << Pool->Integers1.size();
271 Str << "|i8=" << Pool->Integers8.size(); 272 Str << "|i8=" << Pool->Integers8.size();
272 Str << "|i16=" << Pool->Integers16.size(); 273 Str << "|i16=" << Pool->Integers16.size();
273 Str << "|i32=" << Pool->Integers32.size(); 274 Str << "|i32=" << Pool->Integers32.size();
274 Str << "|i64=" << Pool->Integers64.size(); 275 Str << "|i64=" << Pool->Integers64.size();
275 Str << "|Rel=" << Pool->Relocatables.size(); 276 Str << "|Rel=" << Pool->Relocatables.size();
276 Str << "|ExtRel=" << Pool->ExternRelocatables.size(); 277 Str << "|ExtRel=" << Pool->ExternRelocatables.size();
277 } 278 }
278 Str << "\n"; 279 Str << "\n";
280 if (Func != nullptr) {
281 Str << "|" << Name << "|Cfg Memory |" << Func->getTotalMemoryMB()
282 << " MB\n";
283 }
279 } 284 }
280 285
281 GlobalContext::GlobalContext(Ostream *OsDump, Ostream *OsEmit, Ostream *OsError, 286 GlobalContext::GlobalContext(Ostream *OsDump, Ostream *OsEmit, Ostream *OsError,
282 ELFStreamer *ELFStr) 287 ELFStreamer *ELFStr)
283 : Strings(new StringPool()), ConstPool(new ConstantPool()), ErrorStatus(), 288 : Strings(new StringPool()), ConstPool(new ConstantPool()), ErrorStatus(),
284 StrDump(OsDump), StrEmit(OsEmit), StrError(OsError), IntrinsicsInfo(this), 289 StrDump(OsDump), StrEmit(OsEmit), StrError(OsError), IntrinsicsInfo(this),
285 ObjectWriter(), OptQ(/*Sequential=*/Flags.isSequential(), 290 ObjectWriter(), OptQ(/*Sequential=*/Flags.isSequential(),
286 /*MaxSize=*/ 291 /*MaxSize=*/
287 (Flags.getParseParallel() && Flags.getBuildOnRead()) 292 (Flags.getParseParallel() && Flags.getBuildOnRead())
288 ? MaxOptQSize 293 ? MaxOptQSize
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 } else { 378 } else {
374 Func->getAssembler<>()->setInternal(Func->getInternal()); 379 Func->getAssembler<>()->setInternal(Func->getInternal());
375 switch (getFlags().getOutFileType()) { 380 switch (getFlags().getOutFileType()) {
376 case FT_Elf: 381 case FT_Elf:
377 case FT_Iasm: { 382 case FT_Iasm: {
378 Func->emitIAS(); 383 Func->emitIAS();
379 // The Cfg has already emitted into the assembly buffer, so 384 // The Cfg has already emitted into the assembly buffer, so
380 // stats have been fully collected into this thread's TLS. 385 // stats have been fully collected into this thread's TLS.
381 // Dump them before TLS is reset for the next Cfg. 386 // Dump them before TLS is reset for the next Cfg.
382 if (BuildDefs::dump()) 387 if (BuildDefs::dump())
383 dumpStats(Func->getFunctionNameAndSize()); 388 dumpStats(Func.get());
384 auto Asm = Func->releaseAssembler(); 389 auto Asm = Func->releaseAssembler();
385 // Copy relevant fields into Asm before Func is deleted. 390 // Copy relevant fields into Asm before Func is deleted.
386 Asm->setFunctionName(Func->getFunctionName()); 391 Asm->setFunctionName(Func->getFunctionName());
387 Item = makeUnique<EmitterWorkItem>(Func->getSequenceNumber(), 392 Item = makeUnique<EmitterWorkItem>(Func->getSequenceNumber(),
388 std::move(Asm)); 393 std::move(Asm));
389 Item->setGlobalInits(Func->getGlobalInits()); 394 Item->setGlobalInits(Func->getGlobalInits());
390 } break; 395 } break;
391 case FT_Asm: 396 case FT_Asm:
392 // The Cfg has not been emitted yet, so stats are not ready 397 // The Cfg has not been emitted yet, so stats are not ready
393 // to be dumped. 398 // to be dumped.
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 lowerGlobalsIfNoCodeHasBeenSeen(); 632 lowerGlobalsIfNoCodeHasBeenSeen();
628 accumulateGlobals(Item->getGlobalInits()); 633 accumulateGlobals(Item->getGlobalInits());
629 634
630 assert(getFlags().getOutFileType() == FT_Asm); 635 assert(getFlags().getOutFileType() == FT_Asm);
631 std::unique_ptr<Cfg> Func = Item->getCfg(); 636 std::unique_ptr<Cfg> Func = Item->getCfg();
632 // Unfortunately, we have to temporarily install the Cfg in TLS 637 // Unfortunately, we have to temporarily install the Cfg in TLS
633 // because Variable::asType() uses the allocator to create the 638 // because Variable::asType() uses the allocator to create the
634 // differently-typed copy. 639 // differently-typed copy.
635 CfgLocalAllocatorScope _(Func.get()); 640 CfgLocalAllocatorScope _(Func.get());
636 Func->emit(); 641 Func->emit();
637 dumpStats(Func->getFunctionNameAndSize()); 642 dumpStats(Func.get());
638 } break; 643 } break;
639 } 644 }
640 } 645 }
641 // Update the start index for next shuffling queue 646 // Update the start index for next shuffling queue
642 ShuffleStartIndex = ShuffleEndIndex; 647 ShuffleStartIndex = ShuffleEndIndex;
643 } 648 }
644 649
645 // In case there are no code to be generated, we invoke the conditional 650 // In case there are no code to be generated, we invoke the conditional
646 // lowerGlobals again -- this is a no-op if code has been emitted. 651 // lowerGlobals again -- this is a no-op if code has been emitted.
647 lowerGlobalsIfNoCodeHasBeenSeen(); 652 lowerGlobalsIfNoCodeHasBeenSeen();
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
937 } 942 }
938 if (getFlags().isSequential()) 943 if (getFlags().isSequential())
939 emitItems(); 944 emitItems();
940 } 945 }
941 946
942 std::unique_ptr<EmitterWorkItem> GlobalContext::emitQueueBlockingPop() { 947 std::unique_ptr<EmitterWorkItem> GlobalContext::emitQueueBlockingPop() {
943 TimerMarker _(TimerStack::TT_qEmitPop, this); 948 TimerMarker _(TimerStack::TT_qEmitPop, this);
944 return EmitQ.blockingPop(); 949 return EmitQ.blockingPop();
945 } 950 }
946 951
947 void GlobalContext::dumpStats(const std::string &Name, bool Final) { 952 void GlobalContext::dumpStats(const Cfg *Func) {
948 if (!getFlags().getDumpStats()) 953 if (!getFlags().getDumpStats())
949 return; 954 return;
950 if (Final) { 955 if (Func == nullptr) {
951 getStatsCumulative()->dump(Name, this); 956 getStatsCumulative()->dump(Func, this);
952 } else { 957 } else {
953 ICE_TLS_GET_FIELD(TLS)->StatsFunction.dump(Name, this); 958 ICE_TLS_GET_FIELD(TLS)->StatsFunction.dump(Func, this);
954 } 959 }
955 } 960 }
956 961
957 void GlobalContext::dumpTimers(TimerStackIdT StackID, bool DumpCumulative) { 962 void GlobalContext::dumpTimers(TimerStackIdT StackID, bool DumpCumulative) {
958 if (!BuildDefs::timers()) 963 if (!BuildDefs::timers())
959 return; 964 return;
960 auto Timers = getTimers(); 965 auto Timers = getTimers();
961 assert(Timers->size() > StackID); 966 assert(Timers->size() > StackID);
962 OstreamLocker L(this); 967 OstreamLocker L(this);
963 Timers->at(StackID).dump(getStrDump(), DumpCumulative); 968 Timers->at(StackID).dump(getStrDump(), DumpCumulative);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
998 Ctx = Func->getContext(); 1003 Ctx = Func->getContext();
999 Active = 1004 Active =
1000 Func->getFocusedTiming() || Ctx->getFlags().getSubzeroTimingEnabled(); 1005 Func->getFocusedTiming() || Ctx->getFlags().getSubzeroTimingEnabled();
1001 if (Active) 1006 if (Active)
1002 Ctx->pushTimer(ID, StackID); 1007 Ctx->pushTimer(ID, StackID);
1003 } 1008 }
1004 1009
1005 ICE_TLS_DEFINE_FIELD(GlobalContext::ThreadContext *, GlobalContext, TLS); 1010 ICE_TLS_DEFINE_FIELD(GlobalContext::ThreadContext *, GlobalContext, TLS);
1006 1011
1007 } // end of namespace Ice 1012 } // 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