[llvm-commits] [PATCH 09/20] [AVX] Make IntInit Unique
David Greene
dag at cray.com
Tue Jul 19 13:11:44 PDT 2011
Use a DenseMap to make sure only one IntInit of any value exists.
---
utils/TableGen/Record.cpp | 14 +++++++++++++-
1 files changed, 13 insertions(+), 1 deletions(-)
diff --git oldutils/TableGen/Record.cpp newutils/TableGen/Record.cpp
index 4c019d3..dda0b71 100644
--- oldutils/TableGen/Record.cpp
+++ newutils/TableGen/Record.cpp
@@ -491,7 +491,19 @@ const Init *BitsInit::resolveReferences(Record &R, const RecordVal *RV) const {
}
const IntInit *IntInit::get(int64_t V) {
- return new IntInit(V);
+ typedef DenseMap<int64_t, IntInit *> Pool;
+ static Pool ThePool;
+
+ Pool::iterator Result = ThePool.find(V);
+
+ if (Result == ThePool.end()) {
+ IntInit *New = new IntInit(V);
+ bool Inserted = false;
+ tie(Result, Inserted) = ThePool.insert(std::make_pair(V, New));
+ assert(Inserted && "Did not insert new Init into pool!");
+ }
+
+ return Result->second;
}
std::string IntInit::getAsString() const {
--
1.7.6
More information about the llvm-commits
mailing list