OLD | NEW |
1 //===- subzero/src/IceGlobalContext.h - Global context defs -----*- C++ -*-===// | 1 //===- subzero/src/IceGlobalContext.h - Global context defs -----*- C++ -*-===// |
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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 LockedPtr(T *Value, GlobalLockType *Lock) : Value(Value), Lock(Lock) { | 50 LockedPtr(T *Value, GlobalLockType *Lock) : Value(Value), Lock(Lock) { |
51 Lock->lock(); | 51 Lock->lock(); |
52 } | 52 } |
53 LockedPtr(LockedPtr &&Other) : Value(Other.Value), Lock(Other.Lock) { | 53 LockedPtr(LockedPtr &&Other) : Value(Other.Value), Lock(Other.Lock) { |
54 Other.Value = nullptr; | 54 Other.Value = nullptr; |
55 Other.Lock = nullptr; | 55 Other.Lock = nullptr; |
56 } | 56 } |
57 ~LockedPtr() { Lock->unlock(); } | 57 ~LockedPtr() { Lock->unlock(); } |
58 T *operator->() const { return Value; } | 58 T *operator->() const { return Value; } |
59 T &operator*() const { return *Value; } | 59 T &operator*() const { return *Value; } |
| 60 T *get() { return Value; } |
60 | 61 |
61 private: | 62 private: |
62 T *Value; | 63 T *Value; |
63 GlobalLockType *Lock; | 64 GlobalLockType *Lock; |
64 }; | 65 }; |
65 | 66 |
66 class GlobalContext { | 67 class GlobalContext { |
67 GlobalContext() = delete; | 68 GlobalContext() = delete; |
68 GlobalContext(const GlobalContext &) = delete; | 69 GlobalContext(const GlobalContext &) = delete; |
69 GlobalContext &operator=(const GlobalContext &) = delete; | 70 GlobalContext &operator=(const GlobalContext &) = delete; |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 /// verbose level for a particular function. An empty Match argument means | 429 /// verbose level for a particular function. An empty Match argument means |
429 /// match everything. Returns true if there is a match. | 430 /// match everything. Returns true if there is a match. |
430 static bool matchSymbolName(const IceString &SymbolName, | 431 static bool matchSymbolName(const IceString &SymbolName, |
431 const IceString &Match) { | 432 const IceString &Match) { |
432 return Match.empty() || Match == SymbolName; | 433 return Match.empty() || Match == SymbolName; |
433 } | 434 } |
434 | 435 |
435 static ClFlags Flags; | 436 static ClFlags Flags; |
436 static ClFlagsExtra ExtraFlags; | 437 static ClFlagsExtra ExtraFlags; |
437 | 438 |
| 439 /// DisposeGlobalVariablesAfterLowering controls whether the memory used by |
| 440 /// GlobaleVariables can be reclaimed right after they have been lowered. |
| 441 /// @{ |
| 442 bool getDisposeGlobalVariablesAfterLowering() const { |
| 443 return DisposeGlobalVariablesAfterLowering; |
| 444 } |
| 445 |
| 446 void setDisposeGlobalVariablesAfterLowering(bool Value) { |
| 447 DisposeGlobalVariablesAfterLowering = Value; |
| 448 } |
| 449 /// @} |
| 450 |
438 private: | 451 private: |
439 // Try to ensure mutexes are allocated on separate cache lines. | 452 // Try to ensure mutexes are allocated on separate cache lines. |
440 | 453 |
441 // Destructors collaborate with Allocator | 454 // Destructors collaborate with Allocator |
442 ICE_CACHELINE_BOUNDARY; | 455 ICE_CACHELINE_BOUNDARY; |
443 // Managed by getAllocator() | 456 // Managed by getAllocator() |
444 GlobalLockType AllocLock; | 457 GlobalLockType AllocLock; |
445 ArenaAllocator Allocator; | 458 ArenaAllocator Allocator; |
446 | 459 |
447 ICE_CACHELINE_BOUNDARY; | 460 ICE_CACHELINE_BOUNDARY; |
| 461 // Managed by getInitializerAllocator() |
| 462 GlobalLockType InitAllocLock; |
| 463 VariableDeclarationList Globals; |
| 464 |
| 465 ICE_CACHELINE_BOUNDARY; |
448 // Managed by getDestructors() | 466 // Managed by getDestructors() |
449 using DestructorArray = std::vector<std::function<void()>>; | 467 using DestructorArray = std::vector<std::function<void()>>; |
450 GlobalLockType DestructorsLock; | 468 GlobalLockType DestructorsLock; |
451 DestructorArray Destructors; | 469 DestructorArray Destructors; |
452 | 470 |
453 ICE_CACHELINE_BOUNDARY; | 471 ICE_CACHELINE_BOUNDARY; |
454 // Managed by getConstantPool() | 472 // Managed by getConstantPool() |
455 GlobalLockType ConstPoolLock; | 473 GlobalLockType ConstPoolLock; |
456 std::unique_ptr<ConstantPool> ConstPool; | 474 std::unique_ptr<ConstantPool> ConstPool; |
457 | 475 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 BoundedProducerConsumerQueue<EmitterWorkItem> EmitQ; | 510 BoundedProducerConsumerQueue<EmitterWorkItem> EmitQ; |
493 // DataLowering is only ever used by a single thread at a time (either in | 511 // DataLowering is only ever used by a single thread at a time (either in |
494 // emitItems(), or in IceCompiler::run before the compilation is over.) | 512 // emitItems(), or in IceCompiler::run before the compilation is over.) |
495 // TODO(jpp): move to EmitterContext. | 513 // TODO(jpp): move to EmitterContext. |
496 std::unique_ptr<TargetDataLowering> DataLowering; | 514 std::unique_ptr<TargetDataLowering> DataLowering; |
497 /// If !HasEmittedCode, SubZero will accumulate all Globals (which are "true" | 515 /// If !HasEmittedCode, SubZero will accumulate all Globals (which are "true" |
498 /// program global variables) until the first code WorkItem is seen. | 516 /// program global variables) until the first code WorkItem is seen. |
499 // TODO(jpp): move to EmitterContext. | 517 // TODO(jpp): move to EmitterContext. |
500 bool HasSeenCode = false; | 518 bool HasSeenCode = false; |
501 // TODO(jpp): move to EmitterContext. | 519 // TODO(jpp): move to EmitterContext. |
502 VariableDeclarationList Globals; | 520 VariableDeclaration *ProfileBlockInfoVarDecl = nullptr; |
503 // TODO(jpp): move to EmitterContext. | 521 std::vector<VariableDeclaration *> ProfileBlockInfos; |
504 VariableDeclaration *ProfileBlockInfoVarDecl; | 522 /// Indicates if global variable declarations can be disposed of right after |
| 523 /// lowering. |
| 524 bool DisposeGlobalVariablesAfterLowering = true; |
505 | 525 |
506 LockedPtr<ArenaAllocator> getAllocator() { | 526 LockedPtr<ArenaAllocator> getAllocator() { |
507 return LockedPtr<ArenaAllocator>(&Allocator, &AllocLock); | 527 return LockedPtr<ArenaAllocator>(&Allocator, &AllocLock); |
508 } | 528 } |
| 529 LockedPtr<VariableDeclarationList> getInitializerAllocator() { |
| 530 return LockedPtr<VariableDeclarationList>(&Globals, &InitAllocLock); |
| 531 } |
509 LockedPtr<ConstantPool> getConstPool() { | 532 LockedPtr<ConstantPool> getConstPool() { |
510 return LockedPtr<ConstantPool>(ConstPool.get(), &ConstPoolLock); | 533 return LockedPtr<ConstantPool>(ConstPool.get(), &ConstPoolLock); |
511 } | 534 } |
512 LockedPtr<JumpTableDataList> getJumpTableList() { | 535 LockedPtr<JumpTableDataList> getJumpTableList() { |
513 return LockedPtr<JumpTableDataList>(&JumpTableList, &JumpTablesLock); | 536 return LockedPtr<JumpTableDataList>(&JumpTableList, &JumpTablesLock); |
514 } | 537 } |
515 LockedPtr<CodeStats> getStatsCumulative() { | 538 LockedPtr<CodeStats> getStatsCumulative() { |
516 return LockedPtr<CodeStats>(&StatsCumulative, &StatsLock); | 539 return LockedPtr<CodeStats>(&StatsCumulative, &StatsLock); |
517 } | 540 } |
518 LockedPtr<TimerList> getTimers() { | 541 LockedPtr<TimerList> getTimers() { |
519 return LockedPtr<TimerList>(&Timers, &TimerLock); | 542 return LockedPtr<TimerList>(&Timers, &TimerLock); |
520 } | 543 } |
521 LockedPtr<DestructorArray> getDestructors() { | 544 LockedPtr<DestructorArray> getDestructors() { |
522 return LockedPtr<DestructorArray>(&Destructors, &DestructorsLock); | 545 return LockedPtr<DestructorArray>(&Destructors, &DestructorsLock); |
523 } | 546 } |
524 | 547 |
525 void accumulateGlobals(std::unique_ptr<VariableDeclarationList> Globls) { | 548 void accumulateGlobals(std::unique_ptr<VariableDeclarationList> Globls) { |
526 if (Globls != nullptr) | 549 LockedPtr<VariableDeclarationList> _(&Globals, &InitAllocLock); |
527 Globals.insert(Globals.end(), Globls->begin(), Globls->end()); | 550 if (Globls != nullptr) { |
| 551 Globals.merge(Globls.get()); |
| 552 } |
528 } | 553 } |
529 | 554 |
530 void lowerGlobalsIfNoCodeHasBeenSeen() { | 555 void lowerGlobalsIfNoCodeHasBeenSeen() { |
531 if (HasSeenCode) | 556 if (HasSeenCode) |
532 return; | 557 return; |
533 constexpr char NoSuffix[] = ""; | 558 constexpr char NoSuffix[] = ""; |
534 lowerGlobals(NoSuffix); | 559 lowerGlobals(NoSuffix); |
535 HasSeenCode = true; | 560 HasSeenCode = true; |
536 } | 561 } |
537 | 562 |
538 void addBlockInfoPtrs(VariableDeclaration *ProfileBlockInfo); | 563 void saveBlockInfoPtrs(); |
539 | 564 |
540 llvm::SmallVector<ThreadContext *, 128> AllThreadContexts; | 565 llvm::SmallVector<ThreadContext *, 128> AllThreadContexts; |
541 llvm::SmallVector<std::thread, 128> TranslationThreads; | 566 llvm::SmallVector<std::thread, 128> TranslationThreads; |
542 llvm::SmallVector<std::thread, 128> EmitterThreads; | 567 llvm::SmallVector<std::thread, 128> EmitterThreads; |
543 // Each thread has its own TLS pointer which is also held in | 568 // Each thread has its own TLS pointer which is also held in |
544 // AllThreadContexts. | 569 // AllThreadContexts. |
545 ICE_TLS_DECLARE_FIELD(ThreadContext *, TLS); | 570 ICE_TLS_DECLARE_FIELD(ThreadContext *, TLS); |
546 | 571 |
547 public: | 572 public: |
548 static void TlsInit() { ICE_TLS_INIT_FIELD(TLS); } | 573 static void TlsInit() { ICE_TLS_INIT_FIELD(TLS); } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
596 explicit OstreamLocker(GlobalContext *Ctx) : Ctx(Ctx) { Ctx->lockStr(); } | 621 explicit OstreamLocker(GlobalContext *Ctx) : Ctx(Ctx) { Ctx->lockStr(); } |
597 ~OstreamLocker() { Ctx->unlockStr(); } | 622 ~OstreamLocker() { Ctx->unlockStr(); } |
598 | 623 |
599 private: | 624 private: |
600 GlobalContext *const Ctx; | 625 GlobalContext *const Ctx; |
601 }; | 626 }; |
602 | 627 |
603 } // end of namespace Ice | 628 } // end of namespace Ice |
604 | 629 |
605 #endif // SUBZERO_SRC_ICEGLOBALCONTEXT_H | 630 #endif // SUBZERO_SRC_ICEGLOBALCONTEXT_H |
OLD | NEW |