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

Side by Side Diff: src/IceGlobalContext.cpp

Issue 1776473007: Subzero. Allocate global initializers from a dedicated arena. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Removes global variable (and initializer) allocation methods from GlobalContext. 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/IceGlobalInits.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 /// \file 10 /// \file
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
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;
290 case FT_Asm: 290 case FT_Asm:
291 case FT_Iasm: 291 case FT_Iasm:
292 break; 292 break;
293 } 293 }
294 294
295 // ProfileBlockInfoVarDecl is initialized here because it takes this as a
296 // parameter -- we want to
297 // ensure that at least this' member variables are initialized.
298 ProfileBlockInfoVarDecl = VariableDeclaration::createExternal(this);
299 ProfileBlockInfoVarDecl->setAlignment(typeWidthInBytes(IceType_i64));
300 ProfileBlockInfoVarDecl->setIsConstant(true);
301
302 // Note: if you change this symbol, make sure to update
303 // runtime/szrt_profiler.c as well.
304 ProfileBlockInfoVarDecl->setName("__Sz_block_profile_info");
305
306 TargetLowering::staticInit(this); 295 TargetLowering::staticInit(this);
307 } 296 }
308 297
309 void GlobalContext::translateFunctions() { 298 void GlobalContext::translateFunctions() {
310 TimerMarker Timer(TimerStack::TT_translateFunctions, this); 299 TimerMarker Timer(TimerStack::TT_translateFunctions, this);
311 while (std::unique_ptr<Cfg> Func = optQueueBlockingPop()) { 300 while (std::unique_ptr<Cfg> Func = optQueueBlockingPop()) {
312 // Install Func in TLS for Cfg-specific container allocators. 301 // Install Func in TLS for Cfg-specific container allocators.
313 CfgLocalAllocatorScope _(Func.get()); 302 CfgLocalAllocatorScope _(Func.get());
314 // Reset per-function stats being accumulated in TLS. 303 // Reset per-function stats being accumulated in TLS.
315 resetStats(); 304 resetStats();
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 getErrorStatus()->assign(EC_Translation); 379 getErrorStatus()->assign(EC_Translation);
391 } 380 }
392 TargetHeaderLowering::createLowering(this)->lower(); 381 TargetHeaderLowering::createLowering(this)->lower();
393 } 382 }
394 } 383 }
395 384
396 void GlobalContext::lowerConstants() { DataLowering->lowerConstants(); } 385 void GlobalContext::lowerConstants() { DataLowering->lowerConstants(); }
397 386
398 void GlobalContext::lowerJumpTables() { DataLowering->lowerJumpTables(); } 387 void GlobalContext::lowerJumpTables() { DataLowering->lowerJumpTables(); }
399 388
400 void GlobalContext::addBlockInfoPtrs(VariableDeclaration *ProfileBlockInfo) { 389 void GlobalContext::saveBlockInfoPtrs() {
401 for (const VariableDeclaration *Global : Globals) { 390 for (VariableDeclaration *Global : Globals) {
402 if (Cfg::isProfileGlobal(*Global)) { 391 if (Cfg::isProfileGlobal(*Global)) {
403 constexpr RelocOffsetT BlockExecutionCounterOffset = 0; 392 ProfileBlockInfos.push_back(Global);
404 ProfileBlockInfo->addInitializer(
405 VariableDeclaration::RelocInitializer::create(
406 Global,
407 {RelocOffset::create(this, BlockExecutionCounterOffset)}));
408 } 393 }
409 } 394 }
410 } 395 }
411 396
412 void GlobalContext::lowerGlobals(const IceString &SectionSuffix) { 397 void GlobalContext::lowerGlobals(const IceString &SectionSuffix) {
413 TimerMarker T(TimerStack::TT_emitGlobalInitializers, this); 398 TimerMarker T(TimerStack::TT_emitGlobalInitializers, this);
414 const bool DumpGlobalVariables = BuildDefs::dump() && 399 const bool DumpGlobalVariables = BuildDefs::dump() &&
415 (Flags.getVerbose() & IceV_GlobalInit) && 400 (Flags.getVerbose() & IceV_GlobalInit) &&
416 Flags.getVerboseFocusOn().empty(); 401 Flags.getVerboseFocusOn().empty();
417 if (DumpGlobalVariables) { 402 if (DumpGlobalVariables) {
418 OstreamLocker L(this); 403 OstreamLocker L(this);
419 Ostream &Stream = getStrDump(); 404 Ostream &Stream = getStrDump();
420 for (const Ice::VariableDeclaration *Global : Globals) { 405 for (const Ice::VariableDeclaration *Global : Globals) {
421 Global->dump(Stream); 406 Global->dump(Stream);
422 } 407 }
423 } 408 }
424 if (Flags.getDisableTranslation()) 409 if (Flags.getDisableTranslation())
425 return; 410 return;
426 411
427 addBlockInfoPtrs(ProfileBlockInfoVarDecl); 412 saveBlockInfoPtrs();
428 // If we need to shuffle the layout of global variables, shuffle them now. 413 // If we need to shuffle the layout of global variables, shuffle them now.
429 if (getFlags().shouldReorderGlobalVariables()) { 414 if (getFlags().shouldReorderGlobalVariables()) {
430 // Create a random number generator for global variable reordering. 415 // Create a random number generator for global variable reordering.
431 RandomNumberGenerator RNG(getFlags().getRandomSeed(), 416 RandomNumberGenerator RNG(getFlags().getRandomSeed(),
432 RPE_GlobalVariableReordering); 417 RPE_GlobalVariableReordering);
433 RandomShuffle(Globals.begin(), Globals.end(), 418 RandomShuffle(Globals.begin(), Globals.end(),
434 [&RNG](int N) { return (uint32_t)RNG.next(N); }); 419 [&RNG](int N) { return (uint32_t)RNG.next(N); });
435 } 420 }
436 DataLowering->lowerGlobals(Globals, SectionSuffix); 421 DataLowering->lowerGlobals(Globals, SectionSuffix);
437 for (VariableDeclaration *Var : Globals) { 422 if (ProfileBlockInfos.empty() && DisposeGlobalVariablesAfterLowering) {
438 Var->discardInitializers(); 423 Globals.clearAndPurge();
424 } else {
425 Globals.clear();
439 } 426 }
440 Globals.clear();
441 } 427 }
442 428
443 void GlobalContext::lowerProfileData() { 429 void GlobalContext::lowerProfileData() {
444 // ProfileBlockInfoVarDecl is initialized in the constructor, and will only 430 // ProfileBlockInfoVarDecl is initialized in the constructor, and will only
445 // ever be nullptr after this method completes. This assertion is a convoluted 431 // ever be nullptr after this method completes. This assertion is a convoluted
446 // way of ensuring lowerProfileData is invoked a single time. 432 // way of ensuring lowerProfileData is invoked a single time.
447 assert(ProfileBlockInfoVarDecl != nullptr); 433 assert(ProfileBlockInfoVarDecl == nullptr);
434
435 auto GlobalVariablePool = getInitializerAllocator();
436 ProfileBlockInfoVarDecl =
437 VariableDeclaration::createExternal(GlobalVariablePool.get());
438 ProfileBlockInfoVarDecl->setAlignment(typeWidthInBytes(IceType_i64));
439 ProfileBlockInfoVarDecl->setIsConstant(true);
440
441 // Note: if you change this symbol, make sure to update
442 // runtime/szrt_profiler.c as well.
443 ProfileBlockInfoVarDecl->setName("__Sz_block_profile_info");
444
445 for (const VariableDeclaration *PBI : ProfileBlockInfos) {
446 if (Cfg::isProfileGlobal(*PBI)) {
447 constexpr RelocOffsetT BlockExecutionCounterOffset = 0;
448 ProfileBlockInfoVarDecl->addInitializer(
449 VariableDeclaration::RelocInitializer::create(
450 GlobalVariablePool.get(), PBI,
451 {RelocOffset::create(this, BlockExecutionCounterOffset)}));
452 }
453 }
454
448 // This adds a 64-bit sentinel entry to the end of our array. For 32-bit 455 // This adds a 64-bit sentinel entry to the end of our array. For 32-bit
449 // architectures this will waste 4 bytes. 456 // architectures this will waste 4 bytes.
450 const SizeT Sizeof64BitNullPtr = typeWidthInBytes(IceType_i64); 457 const SizeT Sizeof64BitNullPtr = typeWidthInBytes(IceType_i64);
451 ProfileBlockInfoVarDecl->addInitializer( 458 ProfileBlockInfoVarDecl->addInitializer(
452 VariableDeclaration::ZeroInitializer::create(Sizeof64BitNullPtr)); 459 VariableDeclaration::ZeroInitializer::create(GlobalVariablePool.get(),
460 Sizeof64BitNullPtr));
453 Globals.push_back(ProfileBlockInfoVarDecl); 461 Globals.push_back(ProfileBlockInfoVarDecl);
454 constexpr char ProfileDataSection[] = "$sz_profiler$"; 462 constexpr char ProfileDataSection[] = "$sz_profiler$";
455 lowerGlobals(ProfileDataSection); 463 lowerGlobals(ProfileDataSection);
456 ProfileBlockInfoVarDecl = nullptr;
457 } 464 }
458 465
459 void GlobalContext::emitItems() { 466 void GlobalContext::emitItems() {
460 const bool Threaded = !getFlags().isSequential(); 467 const bool Threaded = !getFlags().isSequential();
461 // Pending is a vector containing the reassembled, ordered list of 468 // Pending is a vector containing the reassembled, ordered list of
462 // work items. When we're ready for the next item, we first check 469 // work items. When we're ready for the next item, we first check
463 // whether it's in the Pending list. If not, we take an item from 470 // whether it's in the Pending list. If not, we take an item from
464 // the work queue, and if it's not the item we're waiting for, we 471 // the work queue, and if it's not the item we're waiting for, we
465 // insert it into Pending and repeat. The work item is deleted 472 // insert it into Pending and repeat. The work item is deleted
466 // after it is processed. 473 // after it is processed.
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
914 Ctx = Func->getContext(); 921 Ctx = Func->getContext();
915 Active = 922 Active =
916 Func->getFocusedTiming() || Ctx->getFlags().getSubzeroTimingEnabled(); 923 Func->getFocusedTiming() || Ctx->getFlags().getSubzeroTimingEnabled();
917 if (Active) 924 if (Active)
918 Ctx->pushTimer(ID, StackID); 925 Ctx->pushTimer(ID, StackID);
919 } 926 }
920 927
921 ICE_TLS_DEFINE_FIELD(GlobalContext::ThreadContext *, GlobalContext, TLS); 928 ICE_TLS_DEFINE_FIELD(GlobalContext::ThreadContext *, GlobalContext, TLS);
922 929
923 } // end of namespace Ice 930 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/IceGlobalContext.h ('k') | src/IceGlobalInits.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698