Chromium Code Reviews

Unified Diff: src/IceGlobalContext.h

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.
Jump to:
View side-by-side diff with in-line comments
« no previous file with comments | « src/IceELFObjectWriter.cpp ('k') | src/IceGlobalContext.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/IceGlobalContext.h
diff --git a/src/IceGlobalContext.h b/src/IceGlobalContext.h
index c8d86af669b4c725751609dc121b60138b0813d0..61eb3e1f6c7a4083f81679db2b82b87565110220 100644
--- a/src/IceGlobalContext.h
+++ b/src/IceGlobalContext.h
@@ -57,6 +57,7 @@ public:
~LockedPtr() { Lock->unlock(); }
T *operator->() const { return Value; }
T &operator*() const { return *Value; }
+ T *get() { return Value; }
private:
T *Value;
@@ -435,6 +436,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 +458,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 +517,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 +546,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 +560,7 @@ private:
HasSeenCode = true;
}
- void addBlockInfoPtrs(VariableDeclaration *ProfileBlockInfo);
+ void saveBlockInfoPtrs();
llvm::SmallVector<ThreadContext *, 128> AllThreadContexts;
llvm::SmallVector<std::thread, 128> TranslationThreads;
« no previous file with comments | « src/IceELFObjectWriter.cpp ('k') | src/IceGlobalContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine