NotOr, // not sure why this would help (not done)
NotXor, // not sure why this would help (not done)
FlattenAssocCommut,
+ FlattenAssocCommutNoDuplicates,
PlusCombineLikeTerms,
MultSimplify,
MultDistribConst,
case SignExtendEliminate : out << "SignExtendEliminate"; return out;
case NotIdemp : out << "NotIdemp"; return out;
case UleSelf: out << "UleSelf"; return out;
- case FlattenAssocCommut: out << "FlattenAssocCommut"; return out;
+ case FlattenAssocCommut: out << "FlattenAssocCommut"; return out;
+ case FlattenAssocCommutNoDuplicates: out << "FlattenAssocCommutNoDuplicates"; return out;
case PlusCombineLikeTerms: out << "PlusCombineLikeTerms"; return out;
case MultSimplify: out << "MultSimplify"; return out;
case MultDistribConst: out << "MultDistribConst"; return out;
RewriteRule<SubEliminate> rule82;
RewriteRule<XorOne> rule83;
RewriteRule<XorZero> rule84;
- RewriteRule<MultPow2> rule87;
RewriteRule<MultSlice> rule85;
+ RewriteRule<FlattenAssocCommutNoDuplicates> rule86;
+ RewriteRule<MultPow2> rule87;
RewriteRule<ExtractMultLeadingBit> rule88;
RewriteRule<NegIdemp> rule91;
RewriteRule<UdivPow2> rule92;
return utils::mkSortedNode(kind::BITVECTOR_AND, children);
}
+template<> inline
+bool RewriteRule<FlattenAssocCommutNoDuplicates>::applies(TNode node) {
+ Kind kind = node.getKind();
+ if (kind != kind::BITVECTOR_OR &&
+ kind != kind::BITVECTOR_AND)
+ return false;
+ TNode::iterator child_it = node.begin();
+ for(; child_it != node.end(); ++child_it) {
+ if ((*child_it).getKind() == kind) {
+ return true;
+ }
+ }
+ return false;
+}
+
+template<> inline
+Node RewriteRule<FlattenAssocCommutNoDuplicates>::apply(TNode node) {
+ Debug("bv-rewrite") << "RewriteRule<FlattenAssocCommut>(" << node << ")" << std::endl;
+ std::vector<Node> processingStack;
+ processingStack.push_back(node);
+ __gnu_cxx::hash_set<TNode, TNodeHashFunction> processed;
+ std::vector<Node> children;
+ Kind kind = node.getKind();
+
+ while (! processingStack.empty()) {
+ TNode current = processingStack.back();
+ processingStack.pop_back();
+ if (processed.count(current))
+ continue;
+
+ processed.insert(current);
+
+ // flatten expression
+ if (current.getKind() == kind) {
+ for (unsigned i = 0; i < current.getNumChildren(); ++i) {
+ processingStack.push_back(current[i]);
+ }
+ } else {
+ children.push_back(current);
+ }
+ }
+ return utils::mkSortedNode(kind, children);
+}
+
+
template<> inline
bool RewriteRule<OrSimplify>::applies(TNode node) {
return (node.getKind() == kind::BITVECTOR_OR);
RewriteResponse TheoryBVRewriter::RewriteAnd(TNode node, bool prerewrite) {
Node resultNode = node;
resultNode = LinearRewriteStrategy
- < RewriteRule<FlattenAssocCommut>,
+ < RewriteRule<FlattenAssocCommutNoDuplicates>,
RewriteRule<AndSimplify>
>::apply(node);
RewriteResponse TheoryBVRewriter::RewriteOr(TNode node, bool prerewrite){
Node resultNode = node;
resultNode = LinearRewriteStrategy
- < RewriteRule<FlattenAssocCommut>,
+ < RewriteRule<FlattenAssocCommutNoDuplicates>,
RewriteRule<OrSimplify>
>::apply(node);