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

Side by Side Diff: src/IceGlobalContext.cpp

Issue 1024203002: Move some flag-like props from GlobalContext and TargetLowering to ClFlags. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: review / clean up formatting Created 5 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/IceRNG.h » ('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 // This file defines aspects of the compilation that persist across 10 // This file defines aspects of the compilation that persist across
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 << Stats[CS_NumSpills] + Stats[CS_NumFills] << "\n"; 155 << Stats[CS_NumSpills] + Stats[CS_NumFills] << "\n";
156 Str << "|" << Name << "|Memory Usage|"; 156 Str << "|" << Name << "|Memory Usage|";
157 if (ssize_t MemUsed = llvm::TimeRecord::getCurrentTime(false).getMemUsed()) 157 if (ssize_t MemUsed = llvm::TimeRecord::getCurrentTime(false).getMemUsed())
158 Str << MemUsed; 158 Str << MemUsed;
159 else 159 else
160 Str << "(requires '-track-memory')"; 160 Str << "(requires '-track-memory')";
161 Str << "\n"; 161 Str << "\n";
162 } 162 }
163 163
164 GlobalContext::GlobalContext(Ostream *OsDump, Ostream *OsEmit, 164 GlobalContext::GlobalContext(Ostream *OsDump, Ostream *OsEmit,
165 ELFStreamer *ELFStr, VerboseMask Mask, 165 ELFStreamer *ELFStr, const ClFlags &Flags)
166 TargetArch Arch, OptLevel Opt,
167 IceString TestPrefix, const ClFlags &Flags)
168 : ConstPool(new ConstantPool()), ErrorStatus(), StrDump(OsDump), 166 : ConstPool(new ConstantPool()), ErrorStatus(), StrDump(OsDump),
169 StrEmit(OsEmit), VMask(Mask), Arch(Arch), Opt(Opt), 167 StrEmit(OsEmit), Flags(Flags), RNG(Flags.getRandomSeed()), ObjectWriter(),
170 TestPrefix(TestPrefix), Flags(Flags), RNG(""), ObjectWriter(),
171 OptQ(/*Sequential=*/Flags.isSequential(), 168 OptQ(/*Sequential=*/Flags.isSequential(),
172 /*MaxSize=*/Flags.getNumTranslationThreads()), 169 /*MaxSize=*/Flags.getNumTranslationThreads()),
173 // EmitQ is allowed unlimited size. 170 // EmitQ is allowed unlimited size.
174 EmitQ(/*Sequential=*/Flags.isSequential()) { 171 EmitQ(/*Sequential=*/Flags.isSequential()) {
175 // Make sure thread_local fields are properly initialized before any 172 // Make sure thread_local fields are properly initialized before any
176 // accesses are made. Do this here instead of at the start of 173 // accesses are made. Do this here instead of at the start of
177 // main() so that all clients (e.g. unit tests) can benefit for 174 // main() so that all clients (e.g. unit tests) can benefit for
178 // free. 175 // free.
179 GlobalContext::TlsInit(); 176 GlobalContext::TlsInit();
180 Cfg::TlsInit(); 177 Cfg::TlsInit();
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 // The Cfg now gets deleted as Func goes out of scope. 257 // The Cfg now gets deleted as Func goes out of scope.
261 } 258 }
262 } 259 }
263 260
264 namespace { 261 namespace {
265 262
266 void lowerGlobals(GlobalContext *Ctx, 263 void lowerGlobals(GlobalContext *Ctx,
267 std::unique_ptr<VariableDeclarationList> VariableDeclarations, 264 std::unique_ptr<VariableDeclarationList> VariableDeclarations,
268 TargetDataLowering *DataLowering) { 265 TargetDataLowering *DataLowering) {
269 TimerMarker T(TimerStack::TT_emitGlobalInitializers, Ctx); 266 TimerMarker T(TimerStack::TT_emitGlobalInitializers, Ctx);
270 const bool DumpGlobalVariables = ALLOW_DUMP && Ctx->getVerbose() && 267 const bool DumpGlobalVariables = ALLOW_DUMP && Ctx->getFlags().getVerbose() &&
271 Ctx->getFlags().getVerboseFocusOn().empty(); 268 Ctx->getFlags().getVerboseFocusOn().empty();
272 if (DumpGlobalVariables) { 269 if (DumpGlobalVariables) {
273 OstreamLocker L(Ctx); 270 OstreamLocker L(Ctx);
274 Ostream &Stream = Ctx->getStrDump(); 271 Ostream &Stream = Ctx->getStrDump();
275 for (const Ice::VariableDeclaration *Global : *VariableDeclarations) { 272 for (const Ice::VariableDeclaration *Global : *VariableDeclarations) {
276 Global->dump(Ctx, Stream); 273 Global->dump(Ctx, Stream);
277 } 274 }
278 } 275 }
279 if (Ctx->getFlags().getDisableTranslation()) 276 if (Ctx->getFlags().getDisableTranslation())
280 return; 277 return;
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 // prefix. 449 // prefix.
453 IceString GlobalContext::mangleName(const IceString &Name) const { 450 IceString GlobalContext::mangleName(const IceString &Name) const {
454 // An already-nested name like foo::bar() gets pushed down one 451 // An already-nested name like foo::bar() gets pushed down one
455 // level, making it equivalent to Prefix::foo::bar(). 452 // level, making it equivalent to Prefix::foo::bar().
456 // _ZN3foo3barExyz ==> _ZN6Prefix3foo3barExyz 453 // _ZN3foo3barExyz ==> _ZN6Prefix3foo3barExyz
457 // A non-nested but mangled name like bar() gets nested, making it 454 // A non-nested but mangled name like bar() gets nested, making it
458 // equivalent to Prefix::bar(). 455 // equivalent to Prefix::bar().
459 // _Z3barxyz ==> ZN6Prefix3barExyz 456 // _Z3barxyz ==> ZN6Prefix3barExyz
460 // An unmangled, extern "C" style name, gets a simple prefix: 457 // An unmangled, extern "C" style name, gets a simple prefix:
461 // bar ==> Prefixbar 458 // bar ==> Prefixbar
462 if (!ALLOW_DUMP || getTestPrefix().empty()) 459 if (!ALLOW_DUMP || getFlags().getTestPrefix().empty())
463 return Name; 460 return Name;
464 461
465 unsigned PrefixLength = getTestPrefix().length(); 462 const IceString &TestPrefix = getFlags().getTestPrefix();
463 unsigned PrefixLength = TestPrefix.length();
466 ManglerVector NameBase(1 + Name.length()); 464 ManglerVector NameBase(1 + Name.length());
467 const size_t BufLen = 30 + Name.length() + PrefixLength; 465 const size_t BufLen = 30 + Name.length() + PrefixLength;
468 ManglerVector NewName(BufLen); 466 ManglerVector NewName(BufLen);
469 uint32_t BaseLength = 0; // using uint32_t due to sscanf format string 467 uint32_t BaseLength = 0; // using uint32_t due to sscanf format string
470 468
471 int ItemsParsed = sscanf(Name.c_str(), "_ZN%s", NameBase.data()); 469 int ItemsParsed = sscanf(Name.c_str(), "_ZN%s", NameBase.data());
472 if (ItemsParsed == 1) { 470 if (ItemsParsed == 1) {
473 // Transform _ZN3foo3barExyz ==> _ZN6Prefix3foo3barExyz 471 // Transform _ZN3foo3barExyz ==> _ZN6Prefix3foo3barExyz
474 // (splice in "6Prefix") ^^^^^^^ 472 // (splice in "6Prefix") ^^^^^^^
475 snprintf(NewName.data(), BufLen, "_ZN%u%s%s", PrefixLength, 473 snprintf(NewName.data(), BufLen, "_ZN%u%s%s", PrefixLength,
476 getTestPrefix().c_str(), NameBase.data()); 474 TestPrefix.c_str(), NameBase.data());
477 // We ignore the snprintf return value (here and below). If we 475 // We ignore the snprintf return value (here and below). If we
478 // somehow miscalculated the output buffer length, the output will 476 // somehow miscalculated the output buffer length, the output will
479 // be truncated, but it will be truncated consistently for all 477 // be truncated, but it will be truncated consistently for all
480 // mangleName() calls on the same input string. 478 // mangleName() calls on the same input string.
481 incrementSubstitutions(NewName); 479 incrementSubstitutions(NewName);
482 return NewName.data(); 480 return NewName.data();
483 } 481 }
484 482
485 // Artificially limit BaseLength to 9 digits (less than 1 billion) 483 // Artificially limit BaseLength to 9 digits (less than 1 billion)
486 // because sscanf behavior is undefined on integer overflow. If 484 // because sscanf behavior is undefined on integer overflow. If
(...skipping 18 matching lines...) Expand all
505 if (NameBase[ActualBaseLength] == 'I') { 503 if (NameBase[ActualBaseLength] == 'I') {
506 ++ActualBaseLength; 504 ++ActualBaseLength;
507 while (NameBase[ActualBaseLength] != 'E' && 505 while (NameBase[ActualBaseLength] != 'E' &&
508 NameBase[ActualBaseLength] != '\0') 506 NameBase[ActualBaseLength] != '\0')
509 ++ActualBaseLength; 507 ++ActualBaseLength;
510 } 508 }
511 strncpy(OrigName.data(), NameBase.data(), ActualBaseLength); 509 strncpy(OrigName.data(), NameBase.data(), ActualBaseLength);
512 OrigName[ActualBaseLength] = '\0'; 510 OrigName[ActualBaseLength] = '\0';
513 strcpy(OrigSuffix.data(), NameBase.data() + ActualBaseLength); 511 strcpy(OrigSuffix.data(), NameBase.data() + ActualBaseLength);
514 snprintf(NewName.data(), BufLen, "_ZN%u%s%u%sE%s", PrefixLength, 512 snprintf(NewName.data(), BufLen, "_ZN%u%s%u%sE%s", PrefixLength,
515 getTestPrefix().c_str(), BaseLength, OrigName.data(), 513 TestPrefix.c_str(), BaseLength, OrigName.data(),
516 OrigSuffix.data()); 514 OrigSuffix.data());
517 incrementSubstitutions(NewName); 515 incrementSubstitutions(NewName);
518 return NewName.data(); 516 return NewName.data();
519 } 517 }
520 518
521 // Transform bar ==> Prefixbar 519 // Transform bar ==> Prefixbar
522 // ^^^^^^ 520 // ^^^^^^
523 return getTestPrefix() + Name; 521 return TestPrefix + Name;
524 } 522 }
525 523
526 GlobalContext::~GlobalContext() { 524 GlobalContext::~GlobalContext() {
527 llvm::DeleteContainerPointers(AllThreadContexts); 525 llvm::DeleteContainerPointers(AllThreadContexts);
528 } 526 }
529 527
530 // TODO(stichnot): Consider adding thread-local caches of constant 528 // TODO(stichnot): Consider adding thread-local caches of constant
531 // pool entries to reduce contention. 529 // pool entries to reduce contention.
532 530
533 // All locking is done by the getConstantInt[0-9]+() target function. 531 // All locking is done by the getConstantInt[0-9]+() target function.
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 Ctx = Func->getContext(); 773 Ctx = Func->getContext();
776 Active = 774 Active =
777 Func->getFocusedTiming() || Ctx->getFlags().getSubzeroTimingEnabled(); 775 Func->getFocusedTiming() || Ctx->getFlags().getSubzeroTimingEnabled();
778 if (Active) 776 if (Active)
779 Ctx->pushTimer(ID, StackID); 777 Ctx->pushTimer(ID, StackID);
780 } 778 }
781 779
782 ICE_TLS_DEFINE_FIELD(GlobalContext::ThreadContext *, GlobalContext, TLS); 780 ICE_TLS_DEFINE_FIELD(GlobalContext::ThreadContext *, GlobalContext, TLS);
783 781
784 } // end of namespace Ice 782 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/IceGlobalContext.h ('k') | src/IceRNG.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698