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

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: Disable asType() in the minimal build 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
Index: src/IceDefs.h
diff --git a/src/IceDefs.h b/src/IceDefs.h
index 4160fec4abdec0f496696c9544b4c7a4ef84ae3c..875d8152145528912170a63a462a3707cac00e12 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>
JF 2014/12/18 06:36:53 Why 1024? The default LLVM provides is 4x that.
Jim Stichnoth 2014/12/18 23:39:55 The LLVM default is 4K, I increased it to 1M in a
+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;
JF 2014/12/18 06:36:53 Closing braces don't need the space.
Jim Stichnoth 2014/12/18 23:39:55 Done. Nice job C++, I knew you could do it!
typedef std::vector<Constant *> ConstantList;
// SizeT is for holding small-ish limits like number of source

Powered by Google App Engine
This is Rietveld 408576698