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

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: fixes ther llvm2ice converter; fixes the VariableDeclarationList destructor. 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 side-by-side diff with in-line comments
Download patch
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;
« src/IceDefs.h ('K') | « src/IceELFObjectWriter.cpp ('k') | src/IceGlobalContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698