NodeLetVarMap1.clear();
PLPrintNodeSet.clear();
AlreadyPrintedSet.clear();
- SimplifyMap.clear();
- SimplifyNegMap.clear();
+ SimplifyMap->clear();
+ SimplifyNegMap->clear();
SolverMap.clear();
AlwaysTrueFormMap.clear();
_arrayread_ite.clear();
_arrayread_symbol.clear();
_introduced_symbols.clear();
TransformMap.clear();
- _letid_expr_map.clear();
+ _letid_expr_map->clear();
CounterExampleMap.clear();
ComputeFormulaMap.clear();
StatInfoSet.clear();
NodeLetVarMap1.clear();
PLPrintNodeSet.clear();
AlreadyPrintedSet.clear();
- SimplifyMap.clear();
- SimplifyNegMap.clear();
+ SimplifyMap->clear();
+ SimplifyNegMap->clear();
SolverMap.clear();
AlwaysTrueFormMap.clear();
_arrayread_ite.clear();
_arrayread_symbol.clear();
_introduced_symbols.clear();
TransformMap.clear();
- _letid_expr_map.clear();
+ _letid_expr_map->clear();
CounterExampleMap.clear();
ComputeFormulaMap.clear();
StatInfoSet.clear();
void CheckSimplifyInvariant(const ASTNode& a, const ASTNode& output);
private:
//memo table for simplifcation
- ASTNodeMap SimplifyMap;
- ASTNodeMap SimplifyNegMap;
+ ASTNodeMap *SimplifyMap;
+ ASTNodeMap *SimplifyNegMap;
ASTNodeMap SolverMap;
ASTNodeSet AlwaysTrueFormMap;
ASTNodeMap MultInverseMap;
// MAP: This map is from bound IDs that occur in LETs to
// expression. The map is useful in checking replacing the IDs
// with the corresponding expressions.
- ASTNodeMap _letid_expr_map;
+ ASTNodeMap *_letid_expr_map;
public:
ASTNode ResolveID(const ASTNode& var);
//functions for checking and updating simplifcation map
bool CheckSimplifyMap(const ASTNode& key, ASTNode& output, bool pushNeg);
void UpdateSimplifyMap(const ASTNode& key, const ASTNode& value, bool pushNeg);
+ void ResetSimplifyMaps();
bool CheckAlwaysTrueFormMap(const ASTNode& key);
void UpdateAlwaysTrueFormMap(const ASTNode& val);
bool CheckMultInverseMap(const ASTNode& key, ASTNode& output);
ASTFalse(CreateNode(FALSE)),
ASTTrue(CreateNode(TRUE)),
ASTUndefined(CreateNode(UNDEFINED)),
- SimplifyMap(INITIAL_SIMPLIFY_MAP_SIZE),
- SimplifyNegMap(INITIAL_SIMPLIFY_MAP_SIZE),
SolverMap(INITIAL_SOLVER_MAP_SIZE),
_arrayread_symbol(INITIAL_ARRAYREAD_SYMBOL_SIZE),
_introduced_symbols(INITIAL_INTRODUCED_SYMBOLS_SIZE),
start_abstracting = false;
Begin_RemoveWrites = false;
SimplifyWrites_InPlace_Flag = false;
+ SimplifyMap = new ASTNodeMap(INITIAL_SIMPLIFY_MAP_SIZE);
+ SimplifyNegMap = new ASTNodeMap(INITIAL_SIMPLIFY_MAP_SIZE);
+ _letid_expr_map = new ASTNodeMap(INITIAL_INTRODUCED_SYMBOLS_SIZE);
};
//destructor
//3. otherwise add the <var,letExpr> pair to the _letid_expr table.
void BeevMgr::LetExprMgr(const ASTNode& var, const ASTNode& letExpr) {
ASTNodeMap::iterator it;
- if(((it = _letid_expr_map.find(var)) != _letid_expr_map.end()) &&
+ if(((it = _letid_expr_map->find(var)) != _letid_expr_map->end()) &&
it->second != ASTUndefined) {
FatalError("LetExprMgr:The LET-var v has already been defined in this LET scope: v =", var);
}
FatalError("LetExprMgr:This var is already declared. cannot redeclare as a letvar: v =", var);
}
- _letid_expr_map[var] = letExpr;
+ (*_letid_expr_map)[var] = letExpr;
}
//this function looksup the "var to letexpr map" and returns the
//corresponding letexpr. if there is no letexpr, then it simply
//returns the var.
ASTNode BeevMgr::ResolveID(const ASTNode& v) {
+ if (_letid_expr_map == NULL)
+ InitializeLetIDMap();
+
if(v.GetKind() != SYMBOL) {
return v;
}
}
ASTNodeMap::iterator it;
- if((it =_letid_expr_map.find(v)) != _letid_expr_map.end()) {
+ if((it =_letid_expr_map->find(v)) != _letid_expr_map->end()) {
if(it->second == ASTUndefined)
FatalError("Unresolved Identifier: ",v);
else
//declared variables also get stored in this map, but there value
//is ASTUndefined. This is really a hack. I don't know how to get
//rid of this hack.
- _letid_expr_map[v] = ASTUndefined;
+ (*_letid_expr_map)[v] = ASTUndefined;
return v;
}
// This function simply cleans up the LetID -> LetExpr Map.
void BeevMgr::CleanupLetIDMap(void) {
- ASTNodeMap::iterator it = _letid_expr_map.begin();
- ASTNodeMap::iterator itend = _letid_expr_map.end();
+
+ // ext/hash_map::clear() is very expensive on big empty lists. shortcut.
+ if (_letid_expr_map->size() ==0)
+ return;
+
+
+ ASTNodeMap::iterator it = _letid_expr_map->begin();
+ ASTNodeMap::iterator itend = _letid_expr_map->end();
for(;it!=itend;it++) {
if(it->second != ASTUndefined) {
it->first.SetValueWidth(0);
it->first.SetIndexWidth(0);
}
}
- _letid_expr_map.clear();
+
+ // May contain lots of buckets, so reset.
+ delete _letid_expr_map;
+ _letid_expr_map = new ASTNodeMap();
+
+ }
+
+ void BeevMgr::InitializeLetIDMap(void)
+ {
+ _letid_expr_map = new ASTNodeMap();
}
};
bool BeevMgr::CheckSimplifyMap(const ASTNode& key,
ASTNode& output, bool pushNeg) {
ASTNodeMap::iterator it, itend;
- it = pushNeg ? SimplifyNegMap.find(key) : SimplifyMap.find(key);
- itend = pushNeg ? SimplifyNegMap.end() : SimplifyMap.end();
+ it = pushNeg ? SimplifyNegMap->find(key) : SimplifyMap->find(key);
+ itend = pushNeg ? SimplifyNegMap->end() : SimplifyMap->end();
if(it != itend) {
output = it->second;
return true;
}
- if(pushNeg && (it = SimplifyMap.find(key)) != SimplifyMap.end()) {
+ if(pushNeg && (it = SimplifyMap->find(key)) != SimplifyMap->end()) {
output =
(ASTFalse == it->second) ?
ASTTrue :
void BeevMgr::UpdateSimplifyMap(const ASTNode& key, const ASTNode& value, bool pushNeg) {
if(pushNeg)
- SimplifyNegMap[key] = value;
+ (*SimplifyNegMap)[key] = value;
else
- SimplifyMap[key] = value;
+ (*SimplifyMap)[key] = value;
}
bool BeevMgr::CheckSubstitutionMap(const ASTNode& key, ASTNode& output) {
}
ASTNode BeevMgr::SimplifyFormula_TopLevel(const ASTNode& b, bool pushNeg) {
- SimplifyMap.clear();
- SimplifyNegMap.clear();
+ ResetSimplifyMaps();
ASTNode out = SimplifyFormula(b,pushNeg);
- SimplifyMap.clear();
- SimplifyNegMap.clear();
+ ResetSimplifyMaps();
return out;
}
} //end of flattenonelevel()
ASTNode BeevMgr::SimplifyTerm_TopLevel(const ASTNode& b) {
- SimplifyMap.clear();
- SimplifyNegMap.clear();
+ ResetSimplifyMaps();
ASTNode out = SimplifyTerm(b);
- SimplifyNegMap.clear();
- SimplifyMap.clear();
+ ResetSimplifyMaps();
return out;
}
TermsAlreadySeenMap[term] = var;
return false;
}
+
+// in ext/hash_map, and tr/unordered_map, there is no provision to shrink down
+// the number of buckets in a hash map. If the hash_map has previously held a
+// lot of data, then it will have a lot of buckets. Slowing down iterators and
+// clears() in particular.
+void BeevMgr::ResetSimplifyMaps()
+{
+ delete SimplifyMap;
+ SimplifyMap = new ASTNodeMap(INITIAL_SIMPLIFY_MAP_SIZE);
+
+ delete SimplifyNegMap;
+ SimplifyNegMap = new ASTNodeMap(INITIAL_SIMPLIFY_MAP_SIZE);
+}
+
+
};//end of namespace