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

Unified Diff: src/IceDefs.h

Issue 802183004: Subzero: Use CFG-local arena allocation for relevant containers. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Typo fix Created 6 years 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
« no previous file with comments | « src/IceConverter.cpp ('k') | src/IceGlobalContext.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/IceDefs.h
diff --git a/src/IceDefs.h b/src/IceDefs.h
index 6434077caa1c1fe6b5a5c4401ced131d3279004c..867a2dd2fcab98921fdd6aadbe665d45bc8c162b 100644
--- a/src/IceDefs.h
+++ b/src/IceDefs.h
@@ -32,6 +32,7 @@
#include "llvm/ADT/SmallBitVector.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/STLExtras.h"
+#include "llvm/Support/Allocator.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/ELF.h"
#include "llvm/Support/raw_ostream.h"
@@ -56,16 +57,40 @@ class Variable;
class VariableDeclaration;
class VariablesMetadata;
-// TODO: Switch over to LLVM's ADT container classes.
-// http://llvm.org/docs/ProgrammersManual.html#picking-the-right-data-structure-for-a-task
+typedef llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 1024 * 1024>
+ArenaAllocator;
+
+ArenaAllocator *getCurrentCfgAllocator();
+
+template <typename T> struct CfgLocalAllocator {
+ using value_type = T;
+ CfgLocalAllocator() = default;
+ template <class U> CfgLocalAllocator(const CfgLocalAllocator<U> &) {}
+ T *allocate(std::size_t Num) {
+ return getCurrentCfgAllocator()->Allocate<T>(Num);
+ }
+ void deallocate(T *, std::size_t) {}
+};
+template <typename T, typename U>
+inline bool operator==(const CfgLocalAllocator<T> &,
+ const CfgLocalAllocator<U> &) {
+ return true;
+}
+template <typename T, typename U>
+inline bool operator!=(const CfgLocalAllocator<T> &,
+ const CfgLocalAllocator<U> &) {
+ return false;
+}
+
typedef std::string IceString;
typedef llvm::ilist<Inst> InstList;
// Ideally PhiList would be llvm::ilist<InstPhi>, and similar for
// AssignList, but this runs into issues with SFINAE.
typedef InstList PhiList;
typedef InstList AssignList;
-typedef std::vector<Variable *> VarList;
-typedef std::vector<CfgNode *> NodeList;
+// VarList and NodeList are arena-allocated from the Cfg's allocator.
+typedef std::vector<Variable *, CfgLocalAllocator<Variable *>> VarList;
+typedef std::vector<CfgNode *, CfgLocalAllocator<CfgNode *>> NodeList;
typedef std::vector<Constant *> ConstantList;
// SizeT is for holding small-ish limits like number of source
« no previous file with comments | « src/IceConverter.cpp ('k') | src/IceGlobalContext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698