| Index: src/IceGlobalContext.h
|
| diff --git a/src/IceGlobalContext.h b/src/IceGlobalContext.h
|
| index c8d86af669b4c725751609dc121b60138b0813d0..b53f651bcb0804ad9fd1ec4fbe9be6daaabf0bc1 100644
|
| --- a/src/IceGlobalContext.h
|
| +++ b/src/IceGlobalContext.h
|
| @@ -237,6 +237,20 @@ public:
|
| return Ret;
|
| }
|
|
|
| + template <typename T> T *allocate_initializer(SizeT Count = 1) {
|
| + static_assert(
|
| + std::is_trivially_destructible<T>::value,
|
| + "allocate_initializer can only allocate trivially destructible types.");
|
| + return getInitializerAllocator()->allocate_initializer<T>(Count);
|
| + }
|
| +
|
| + template <typename T> T *allocate_variable_declaration() {
|
| + static_assert(!std::is_trivially_destructible<T>::value,
|
| + "allocate_variable_declaration expects non-trivially "
|
| + "destructible types.");
|
| + return getInitializerAllocator()->allocate_variable_declaration<T>();
|
| + }
|
| +
|
| const Intrinsics &getIntrinsicsInfo() const { return IntrinsicsInfo; }
|
|
|
| ELFObjectWriter *getObjectWriter() const { return ObjectWriter.get(); }
|
| @@ -435,6 +449,18 @@ public:
|
| static ClFlags Flags;
|
| static ClFlagsExtra ExtraFlags;
|
|
|
| + /// DisposeGlobalVariablesAfterLowering controls whether the memory used by
|
| + /// GlobaleVariables can be reclaimed right after they have been lowered.
|
| + /// @{
|
| + bool getDisposeGlobalVariablesAfterLowering() const {
|
| + return DisposeGlobalVariablesAfterLowering;
|
| + }
|
| +
|
| + void setDisposeGlobalVariablesAfterLowering(bool Value) {
|
| + DisposeGlobalVariablesAfterLowering = Value;
|
| + }
|
| + /// @}
|
| +
|
| private:
|
| // Try to ensure mutexes are allocated on separate cache lines.
|
|
|
| @@ -445,6 +471,11 @@ private:
|
| ArenaAllocator Allocator;
|
|
|
| ICE_CACHELINE_BOUNDARY;
|
| + // Managed by getInitializerAllocator()
|
| + GlobalLockType InitAllocLock;
|
| + VariableDeclarationList Globals;
|
| +
|
| + ICE_CACHELINE_BOUNDARY;
|
| // Managed by getDestructors()
|
| using DestructorArray = std::vector<std::function<void()>>;
|
| GlobalLockType DestructorsLock;
|
| @@ -499,13 +530,18 @@ private:
|
| // TODO(jpp): move to EmitterContext.
|
| bool HasSeenCode = false;
|
| // TODO(jpp): move to EmitterContext.
|
| - VariableDeclarationList Globals;
|
| - // TODO(jpp): move to EmitterContext.
|
| - VariableDeclaration *ProfileBlockInfoVarDecl;
|
| + VariableDeclaration *ProfileBlockInfoVarDecl = nullptr;
|
| + std::vector<VariableDeclaration *> ProfileBlockInfos;
|
| + /// Indicates if global variable declarations can be disposed of right after
|
| + /// lowering.
|
| + bool DisposeGlobalVariablesAfterLowering = true;
|
|
|
| LockedPtr<ArenaAllocator> getAllocator() {
|
| return LockedPtr<ArenaAllocator>(&Allocator, &AllocLock);
|
| }
|
| + LockedPtr<VariableDeclarationList> getInitializerAllocator() {
|
| + return LockedPtr<VariableDeclarationList>(&Globals, &InitAllocLock);
|
| + }
|
| LockedPtr<ConstantPool> getConstPool() {
|
| return LockedPtr<ConstantPool>(ConstPool.get(), &ConstPoolLock);
|
| }
|
| @@ -523,8 +559,10 @@ private:
|
| }
|
|
|
| void accumulateGlobals(std::unique_ptr<VariableDeclarationList> Globls) {
|
| - if (Globls != nullptr)
|
| - Globals.insert(Globals.end(), Globls->begin(), Globls->end());
|
| + LockedPtr<VariableDeclarationList> _(&Globals, &InitAllocLock);
|
| + if (Globls != nullptr) {
|
| + Globals.merge(Globls.get());
|
| + }
|
| }
|
|
|
| void lowerGlobalsIfNoCodeHasBeenSeen() {
|
| @@ -535,7 +573,7 @@ private:
|
| HasSeenCode = true;
|
| }
|
|
|
| - void addBlockInfoPtrs(VariableDeclaration *ProfileBlockInfo);
|
| + void saveBlockInfoPtrs();
|
|
|
| llvm::SmallVector<ThreadContext *, 128> AllThreadContexts;
|
| llvm::SmallVector<std::thread, 128> TranslationThreads;
|
|
|