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 // This file defines aspects of the compilation that persist across | 10 // This file defines aspects of the compilation that persist across |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 TypePool<IceType_i16, int16_t, ConstantInteger32> Integers16; | 191 TypePool<IceType_i16, int16_t, ConstantInteger32> Integers16; |
192 TypePool<IceType_i32, int32_t, ConstantInteger32> Integers32; | 192 TypePool<IceType_i32, int32_t, ConstantInteger32> Integers32; |
193 TypePool<IceType_i64, int64_t, ConstantInteger64> Integers64; | 193 TypePool<IceType_i64, int64_t, ConstantInteger64> Integers64; |
194 TypePool<IceType_i32, RelocatableTuple, ConstantRelocatable> Relocatables; | 194 TypePool<IceType_i32, RelocatableTuple, ConstantRelocatable> Relocatables; |
195 TypePool<IceType_i32, RelocatableTuple, ConstantRelocatable> | 195 TypePool<IceType_i32, RelocatableTuple, ConstantRelocatable> |
196 ExternRelocatables; | 196 ExternRelocatables; |
197 UndefPool Undefs; | 197 UndefPool Undefs; |
198 }; | 198 }; |
199 | 199 |
200 void GlobalContext::CodeStats::dump(const IceString &Name, Ostream &Str) { | 200 void GlobalContext::CodeStats::dump(const IceString &Name, Ostream &Str) { |
201 if (!ALLOW_DUMP) | 201 if (!buildAllowsDump()) |
202 return; | 202 return; |
203 #define X(str, tag) \ | 203 #define X(str, tag) \ |
204 Str << "|" << Name << "|" str "|" << Stats[CS_##tag] << "\n"; | 204 Str << "|" << Name << "|" str "|" << Stats[CS_##tag] << "\n"; |
205 CODESTATS_TABLE | 205 CODESTATS_TABLE |
206 #undef X | 206 #undef X |
207 Str << "|" << Name << "|Spills+Fills|" | 207 Str << "|" << Name << "|Spills+Fills|" |
208 << Stats[CS_NumSpills] + Stats[CS_NumFills] << "\n"; | 208 << Stats[CS_NumSpills] + Stats[CS_NumFills] << "\n"; |
209 Str << "|" << Name << "|Memory Usage|"; | 209 Str << "|" << Name << "|Memory Usage|"; |
210 if (ssize_t MemUsed = llvm::TimeRecord::getCurrentTime(false).getMemUsed()) | 210 if (ssize_t MemUsed = llvm::TimeRecord::getCurrentTime(false).getMemUsed()) |
211 Str << MemUsed; | 211 Str << MemUsed; |
(...skipping 21 matching lines...) Expand all Loading... |
233 // free. | 233 // free. |
234 GlobalContext::TlsInit(); | 234 GlobalContext::TlsInit(); |
235 Cfg::TlsInit(); | 235 Cfg::TlsInit(); |
236 // Create a new ThreadContext for the current thread. No need to | 236 // Create a new ThreadContext for the current thread. No need to |
237 // lock AllThreadContexts at this point since no other threads have | 237 // lock AllThreadContexts at this point since no other threads have |
238 // access yet to this GlobalContext object. | 238 // access yet to this GlobalContext object. |
239 ThreadContext *MyTLS = new ThreadContext(); | 239 ThreadContext *MyTLS = new ThreadContext(); |
240 AllThreadContexts.push_back(MyTLS); | 240 AllThreadContexts.push_back(MyTLS); |
241 ICE_TLS_SET_FIELD(TLS, MyTLS); | 241 ICE_TLS_SET_FIELD(TLS, MyTLS); |
242 // Pre-register built-in stack names. | 242 // Pre-register built-in stack names. |
243 if (ALLOW_DUMP) { | 243 if (buildAllowsDump()) { |
244 // TODO(stichnot): There needs to be a strong relationship between | 244 // TODO(stichnot): There needs to be a strong relationship between |
245 // the newTimerStackID() return values and TSK_Default/TSK_Funcs. | 245 // the newTimerStackID() return values and TSK_Default/TSK_Funcs. |
246 newTimerStackID("Total across all functions"); | 246 newTimerStackID("Total across all functions"); |
247 newTimerStackID("Per-function summary"); | 247 newTimerStackID("Per-function summary"); |
248 } | 248 } |
249 Timers.initInto(MyTLS->Timers); | 249 Timers.initInto(MyTLS->Timers); |
250 switch (Flags.getOutFileType()) { | 250 switch (Flags.getOutFileType()) { |
251 case FT_Elf: | 251 case FT_Elf: |
252 ObjectWriter.reset(new ELFObjectWriter(*this, *ELFStr)); | 252 ObjectWriter.reset(new ELFObjectWriter(*this, *ELFStr)); |
253 break; | 253 break; |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 Pending.resize(Index + 1); | 362 Pending.resize(Index + 1); |
363 } | 363 } |
364 | 364 |
365 } // end of anonymous namespace | 365 } // end of anonymous namespace |
366 | 366 |
367 void GlobalContext::emitFileHeader() { | 367 void GlobalContext::emitFileHeader() { |
368 TimerMarker T1(Ice::TimerStack::TT_emit, this); | 368 TimerMarker T1(Ice::TimerStack::TT_emit, this); |
369 if (getFlags().getOutFileType() == FT_Elf) { | 369 if (getFlags().getOutFileType() == FT_Elf) { |
370 getObjectWriter()->writeInitialELFHeader(); | 370 getObjectWriter()->writeInitialELFHeader(); |
371 } else { | 371 } else { |
372 if (!ALLOW_DUMP) { | 372 if (!buildAllowsDump()) { |
373 getStrError() << "emitFileHeader for non-ELF"; | 373 getStrError() << "emitFileHeader for non-ELF"; |
374 getErrorStatus()->assign(EC_Translation); | 374 getErrorStatus()->assign(EC_Translation); |
375 } | 375 } |
376 TargetHeaderLowering::createLowering(this)->lower(); | 376 TargetHeaderLowering::createLowering(this)->lower(); |
377 } | 377 } |
378 } | 378 } |
379 | 379 |
380 void GlobalContext::lowerConstants() { DataLowering->lowerConstants(); } | 380 void GlobalContext::lowerConstants() { DataLowering->lowerConstants(); } |
381 | 381 |
382 void GlobalContext::lowerGlobals(const IceString &SectionSuffix) { | 382 void GlobalContext::lowerGlobals(const IceString &SectionSuffix) { |
383 TimerMarker T(TimerStack::TT_emitGlobalInitializers, this); | 383 TimerMarker T(TimerStack::TT_emitGlobalInitializers, this); |
384 const bool DumpGlobalVariables = | 384 const bool DumpGlobalVariables = |
385 ALLOW_DUMP && Flags.getVerbose() && Flags.getVerboseFocusOn().empty(); | 385 buildAllowsDump() && Flags.getVerbose() && Flags.getVerboseFocusOn().empty
(); |
386 if (DumpGlobalVariables) { | 386 if (DumpGlobalVariables) { |
387 OstreamLocker L(this); | 387 OstreamLocker L(this); |
388 Ostream &Stream = getStrDump(); | 388 Ostream &Stream = getStrDump(); |
389 for (const Ice::VariableDeclaration *Global : Globals) { | 389 for (const Ice::VariableDeclaration *Global : Globals) { |
390 Global->dump(this, Stream); | 390 Global->dump(this, Stream); |
391 } | 391 } |
392 } | 392 } |
393 if (Flags.getDisableTranslation()) | 393 if (Flags.getDisableTranslation()) |
394 return; | 394 return; |
395 | 395 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 OstreamLocker L(this); | 466 OstreamLocker L(this); |
467 Cfg::emitTextHeader(MangledName, this, Asm.get()); | 467 Cfg::emitTextHeader(MangledName, this, Asm.get()); |
468 Asm->emitIASBytes(this); | 468 Asm->emitIASBytes(this); |
469 } break; | 469 } break; |
470 case FT_Asm: | 470 case FT_Asm: |
471 llvm::report_fatal_error("Unexpected FT_Asm"); | 471 llvm::report_fatal_error("Unexpected FT_Asm"); |
472 break; | 472 break; |
473 } | 473 } |
474 } break; | 474 } break; |
475 case EmitterWorkItem::WI_Cfg: { | 475 case EmitterWorkItem::WI_Cfg: { |
476 if (!ALLOW_DUMP) | 476 if (!buildAllowsDump()) |
477 llvm::report_fatal_error("WI_Cfg work item created inappropriately"); | 477 llvm::report_fatal_error("WI_Cfg work item created inappropriately"); |
478 lowerGlobalsIfNoCodeHasBeenSeen(); | 478 lowerGlobalsIfNoCodeHasBeenSeen(); |
479 accumulateGlobals(Item->getGlobalInits()); | 479 accumulateGlobals(Item->getGlobalInits()); |
480 | 480 |
481 assert(getFlags().getOutFileType() == FT_Asm); | 481 assert(getFlags().getOutFileType() == FT_Asm); |
482 std::unique_ptr<Cfg> Func = Item->getCfg(); | 482 std::unique_ptr<Cfg> Func = Item->getCfg(); |
483 // Unfortunately, we have to temporarily install the Cfg in TLS | 483 // Unfortunately, we have to temporarily install the Cfg in TLS |
484 // because Variable::asType() uses the allocator to create the | 484 // because Variable::asType() uses the allocator to create the |
485 // differently-typed copy. | 485 // differently-typed copy. |
486 Cfg::setCurrentCfg(Func.get()); | 486 Cfg::setCurrentCfg(Func.get()); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
589 // prefix. | 589 // prefix. |
590 IceString GlobalContext::mangleName(const IceString &Name) const { | 590 IceString GlobalContext::mangleName(const IceString &Name) const { |
591 // An already-nested name like foo::bar() gets pushed down one | 591 // An already-nested name like foo::bar() gets pushed down one |
592 // level, making it equivalent to Prefix::foo::bar(). | 592 // level, making it equivalent to Prefix::foo::bar(). |
593 // _ZN3foo3barExyz ==> _ZN6Prefix3foo3barExyz | 593 // _ZN3foo3barExyz ==> _ZN6Prefix3foo3barExyz |
594 // A non-nested but mangled name like bar() gets nested, making it | 594 // A non-nested but mangled name like bar() gets nested, making it |
595 // equivalent to Prefix::bar(). | 595 // equivalent to Prefix::bar(). |
596 // _Z3barxyz ==> ZN6Prefix3barExyz | 596 // _Z3barxyz ==> ZN6Prefix3barExyz |
597 // An unmangled, extern "C" style name, gets a simple prefix: | 597 // An unmangled, extern "C" style name, gets a simple prefix: |
598 // bar ==> Prefixbar | 598 // bar ==> Prefixbar |
599 if (!ALLOW_DUMP || getFlags().getTestPrefix().empty()) | 599 if (!buildAllowsDump() || getFlags().getTestPrefix().empty()) |
600 return Name; | 600 return Name; |
601 | 601 |
602 const IceString &TestPrefix = getFlags().getTestPrefix(); | 602 const IceString &TestPrefix = getFlags().getTestPrefix(); |
603 unsigned PrefixLength = TestPrefix.length(); | 603 unsigned PrefixLength = TestPrefix.length(); |
604 ManglerVector NameBase(1 + Name.length()); | 604 ManglerVector NameBase(1 + Name.length()); |
605 const size_t BufLen = 30 + Name.length() + PrefixLength; | 605 const size_t BufLen = 30 + Name.length() + PrefixLength; |
606 ManglerVector NewName(BufLen); | 606 ManglerVector NewName(BufLen); |
607 uint32_t BaseLength = 0; // using uint32_t due to sscanf format string | 607 uint32_t BaseLength = 0; // using uint32_t due to sscanf format string |
608 | 608 |
609 int ItemsParsed = sscanf(Name.c_str(), "_ZN%s", NameBase.data()); | 609 int ItemsParsed = sscanf(Name.c_str(), "_ZN%s", NameBase.data()); |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
808 break; | 808 break; |
809 } | 809 } |
810 llvm_unreachable("Unknown type"); | 810 llvm_unreachable("Unknown type"); |
811 } | 811 } |
812 | 812 |
813 ConstantList GlobalContext::getConstantExternSyms() { | 813 ConstantList GlobalContext::getConstantExternSyms() { |
814 return getConstPool()->ExternRelocatables.getConstantPool(); | 814 return getConstPool()->ExternRelocatables.getConstantPool(); |
815 } | 815 } |
816 | 816 |
817 TimerStackIdT GlobalContext::newTimerStackID(const IceString &Name) { | 817 TimerStackIdT GlobalContext::newTimerStackID(const IceString &Name) { |
818 if (!ALLOW_DUMP) | 818 if (!buildAllowsDump()) |
819 return 0; | 819 return 0; |
820 auto Timers = getTimers(); | 820 auto Timers = getTimers(); |
821 TimerStackIdT NewID = Timers->size(); | 821 TimerStackIdT NewID = Timers->size(); |
822 Timers->push_back(TimerStack(Name)); | 822 Timers->push_back(TimerStack(Name)); |
823 return NewID; | 823 return NewID; |
824 } | 824 } |
825 | 825 |
826 TimerIdT GlobalContext::getTimerID(TimerStackIdT StackID, | 826 TimerIdT GlobalContext::getTimerID(TimerStackIdT StackID, |
827 const IceString &Name) { | 827 const IceString &Name) { |
828 auto Timers = &ICE_TLS_GET_FIELD(TLS)->Timers; | 828 auto Timers = &ICE_TLS_GET_FIELD(TLS)->Timers; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
887 return; | 887 return; |
888 OstreamLocker OL(this); | 888 OstreamLocker OL(this); |
889 if (Final) { | 889 if (Final) { |
890 getStatsCumulative()->dump(Name, getStrDump()); | 890 getStatsCumulative()->dump(Name, getStrDump()); |
891 } else { | 891 } else { |
892 ICE_TLS_GET_FIELD(TLS)->StatsFunction.dump(Name, getStrDump()); | 892 ICE_TLS_GET_FIELD(TLS)->StatsFunction.dump(Name, getStrDump()); |
893 } | 893 } |
894 } | 894 } |
895 | 895 |
896 void GlobalContext::dumpTimers(TimerStackIdT StackID, bool DumpCumulative) { | 896 void GlobalContext::dumpTimers(TimerStackIdT StackID, bool DumpCumulative) { |
897 if (!ALLOW_DUMP) | 897 if (!buildAllowsDump()) |
898 return; | 898 return; |
899 auto Timers = getTimers(); | 899 auto Timers = getTimers(); |
900 assert(Timers->size() > StackID); | 900 assert(Timers->size() > StackID); |
901 OstreamLocker L(this); | 901 OstreamLocker L(this); |
902 Timers->at(StackID).dump(getStrDump(), DumpCumulative); | 902 Timers->at(StackID).dump(getStrDump(), DumpCumulative); |
903 } | 903 } |
904 | 904 |
905 void TimerMarker::push() { | 905 void TimerMarker::push() { |
906 switch (StackID) { | 906 switch (StackID) { |
907 case GlobalContext::TSK_Default: | 907 case GlobalContext::TSK_Default: |
(...skipping 13 matching lines...) Expand all Loading... |
921 Ctx = Func->getContext(); | 921 Ctx = Func->getContext(); |
922 Active = | 922 Active = |
923 Func->getFocusedTiming() || Ctx->getFlags().getSubzeroTimingEnabled(); | 923 Func->getFocusedTiming() || Ctx->getFlags().getSubzeroTimingEnabled(); |
924 if (Active) | 924 if (Active) |
925 Ctx->pushTimer(ID, StackID); | 925 Ctx->pushTimer(ID, StackID); |
926 } | 926 } |
927 | 927 |
928 ICE_TLS_DEFINE_FIELD(GlobalContext::ThreadContext *, GlobalContext, TLS); | 928 ICE_TLS_DEFINE_FIELD(GlobalContext::ThreadContext *, GlobalContext, TLS); |
929 | 929 |
930 } // end of namespace Ice | 930 } // end of namespace Ice |
OLD | NEW |