[llvm-commits] [PATCH 14/20] [AVX] Make BinOpInit Unique
David Greene
dag at cray.com
Tue Jul 19 13:11:49 PDT 2011
Make sure BinOpInits are unique and created only once. This will be
important for AVX/SIMD as many operators will be used to generate
patterns and other relevant data.
---
utils/TableGen/Record.cpp | 22 +++++++++++++++++++++-
1 files changed, 21 insertions(+), 1 deletions(-)
diff --git oldutils/TableGen/Record.cpp newutils/TableGen/Record.cpp
index 7adee3b..d2ae02a 100644
--- oldutils/TableGen/Record.cpp
+++ newutils/TableGen/Record.cpp
@@ -851,7 +851,27 @@ std::string UnOpInit::getAsString() const {
const BinOpInit *BinOpInit::get(BinaryOp opc, const Init *lhs,
const Init *rhs, RecTy *Type) {
- return new BinOpInit(opc, lhs, rhs, Type);
+ typedef std::pair<
+ std::pair<std::pair<unsigned, const Init *>, const Init *>,
+ RecTy *
+ > Key;
+
+ typedef DenseMap<Key, BinOpInit *> Pool;
+ static Pool ThePool;
+
+ Key TheKey(std::make_pair(std::make_pair(std::make_pair(opc, lhs), rhs),
+ Type));
+
+ Pool::iterator Result = ThePool.find(TheKey);
+
+ if (Result == ThePool.end()) {
+ BinOpInit *New = new BinOpInit(opc, lhs, rhs, Type);
+ 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 *BinOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const {
--
1.7.6
More information about the llvm-commits
mailing list