[llvm-commits] [PATCH 19/20] [AVX] Make FieldInit Unique
David Greene
dag at cray.com
Tue Jul 19 13:11:54 PDT 2011
Make sure FieldInits are unique and created only once.
---
utils/TableGen/Record.cpp | 16 +++++++++++++++-
1 files changed, 15 insertions(+), 1 deletions(-)
diff --git oldutils/TableGen/Record.cpp newutils/TableGen/Record.cpp
index ef1601e..cf82255 100644
--- oldutils/TableGen/Record.cpp
+++ newutils/TableGen/Record.cpp
@@ -1499,7 +1499,21 @@ std::string DefInit::getAsString() const {
}
const FieldInit *FieldInit::get(const Init *R, const std::string &FN) {
- return new FieldInit(R, FN);
+ typedef std::pair<const Init *, std::string> Key;
+ typedef DenseMap<Key, FieldInit *> Pool;
+ static Pool ThePool;
+
+ Key TheKey(std::make_pair(R, FN));
+ Pool::iterator Result = ThePool.find(TheKey);
+
+ if (Result == ThePool.end()) {
+ FieldInit *New = new FieldInit(R, FN);
+ bool Inserted = false;
+ tie(Result, Inserted) = ThePool.insert(std::make_pair(TheKey, New));
+ assert(Inserted && "Did not insert new Init into pool!");
+ }
+
+ return Result->second;
}
const Init *FieldInit::resolveBitReference(Record &R, const RecordVal *RV,
--
1.7.6
More information about the llvm-commits
mailing list