// to do. Flatten the XOR.
ASTNode BVSolver::solveForXOR(const ASTNode& xorNode)
{
- assert(_bm->UserFlags.solve_for_XORS_flag);
+ assert(_bm->UserFlags.isSet("xor-solve","1"));
if (xorNode.GetKind() != XOR)
{
ASTNode
BVSolver::solveForAndOfXOR(const ASTNode& n)
{
- assert(_bm->UserFlags.solve_for_XORS_flag);
+ assert(_bm->UserFlags.isSet("xor-solve","1"));
if (n.GetKind() != AND)
return n;
}
Kind k = input.GetKind();
- if (XOR ==k && _bm->UserFlags.solve_for_XORS_flag)
+ if (XOR ==k && _bm->UserFlags.isSet("xor-solve","1"))
{
ASTNode output = solveForXOR(_input);
UpdateAlreadySolvedMap(_input, output);
if (evens != ASTTrue)
output = _bm->CreateNode(AND, output, evens);
- if (_bm->UserFlags.solve_for_XORS_flag)
+ if (_bm->UserFlags.isSet("xor-solve","1"))
output = solveForAndOfXOR(output);
// Imagine in the last conjunct A is replaced by B. But there could
const set<ASTNode> empty;
+ public:
// All the nodes that depend on the value of a particular node.
void
build(const ASTNode & current, const ASTNode & prior)
}
}
+ void replaceFresh(const ASTNode& old, const ASTNode& newN, set<ASTNode> *newNDepends,
+ ASTVec& variables)
+ {
+ NodeToDependentNodeMap::const_iterator it = dependents.find(old);
+ if (it == dependents.end())
+ return;
+
+ it->second->erase(old);
+ dependents.insert(make_pair(newN,newNDepends));
+ variables.push_back(newN);
+ }
+
// The "toRemove" node is being removed. Used by unconstrained elimination.
void removeNode(const ASTNode& toRemove, ASTVec& variables)
{
return s->count(higher) > 0;
}
+ bool isUnconstrained(const ASTNode& n)
+ {
+ if (n.GetKind() != SYMBOL)
+ return false;
+
+ NodeToDependentNodeMap::const_iterator it = dependents.find(n);
+ assert(it != dependents.end());
+ return it->second->size() ==1;
+ }
+
+#if 0
void
getAllVariables(ASTVec& v)
{
v.push_back(it->first);
}
}
+#endif
};
{
return substitutionMap.CheckSubstitutionMap(key);
}
+ bool Simplifier::UpdateSubstitutionMapFewChecks(const ASTNode& e0, const ASTNode& e1)
+ {
+ return substitutionMap.UpdateSubstitutionMapFewChecks(e0,e1);
+ }
bool Simplifier::UpdateSubstitutionMap(const ASTNode& e0, const ASTNode& e1)
{
const unsigned len = left.GetValueWidth();
+ if(_bm->UserFlags.isSet("inequality-simplifications","1"))
+ {
+
const int constStart = std::min(mostSignificantConstants(left),mostSignificantConstants(right));
int comparator =0;
return pushNeg ? nf->CreateNode(NOT, status) : status;
}
- if (comparator!=0 && (k == BVSGT || k == BVSGE))
- {
- // one is bigger than the other.
- int sign_a = getConstantBit(left, 0);
- int sign_b = getConstantBit(right, 0);
- if (sign_a < sign_b)
- {
- comparator =1; // a > b.
- }
- if (sign_a > sign_b)
- comparator =-1;
+ if (comparator != 0 && (k == BVSGT || k == BVSGE))
+ {
+ // one is bigger than the other.
+ int sign_a = getConstantBit(left, 0);
+ int sign_b = getConstantBit(right, 0);
+ if (sign_a < sign_b)
+ {
+ comparator = 1; // a > b.
+ }
+ if (sign_a > sign_b)
+ comparator = -1;
- ASTNode status = (comparator ==1)? ASTTrue: ASTFalse;
- return pushNeg ? nf->CreateNode(NOT, status) : status;
- }
+ ASTNode status = (comparator == 1) ? ASTTrue : ASTFalse;
+ return pushNeg ? nf->CreateNode(NOT, status) : status;
+ }
- {
- ASTNodeSet visited0, visited1;
- vector<ASTNode> l0,l1;
+ {
+ ASTNodeSet visited0, visited1;
+ vector<ASTNode> l0, l1;
- // Sound overapproximation. Doesn't consider the equalities.
- if (getPossibleValues(left, visited0, l0) && getPossibleValues(right,visited1, l1))
- {
- {
- bool (*comp)(const ASTNode&, const ASTNode&);
- if (k == BVSGT || k == BVSGE)
- comp = signedGreaterThan;
- else
- comp = unsignedGreaterThan;
- {
- ASTNode minLHS = *max_element(l0.begin(), l0.end(),
- comp);
- ASTNode maxRHS = *min_element(l1.begin(), l1.end(),
- comp);
-
- if (comp(minLHS, maxRHS))
- return pushNeg ? ASTFalse : ASTTrue;
- }
- {
- ASTNode maxLHS = *min_element(l0.begin(), l0.end(),
- comp);
- ASTNode minRHS = *max_element(l1.begin(), l1.end(),
- comp);
-
- if (comp(minRHS, maxLHS))
- return pushNeg ? ASTTrue : ASTFalse;
- }
- }
- }
- }
+ // Sound overapproximation. Doesn't consider the equalities.
+ if (getPossibleValues(left, visited0, l0) && getPossibleValues(right, visited1, l1))
+ {
+ {
+ bool
+ (*comp)(const ASTNode&, const ASTNode&);
+ if (k == BVSGT || k == BVSGE)
+ comp = signedGreaterThan;
+ else
+ comp = unsignedGreaterThan;
+ {
+ ASTNode minLHS = *max_element(l0.begin(), l0.end(), comp);
+ ASTNode maxRHS = *min_element(l1.begin(), l1.end(), comp);
+
+ if (comp(minLHS, maxRHS))
+ return pushNeg ? ASTFalse : ASTTrue;
+ }
+ {
+ ASTNode maxLHS = *min_element(l0.begin(), l0.end(), comp);
+ ASTNode minRHS = *max_element(l1.begin(), l1.end(), comp);
+
+ if (comp(minRHS, maxLHS))
+ return pushNeg ? ASTTrue : ASTFalse;
+ }
+ }
+ }
+ }
+ }
const ASTNode unsigned_min = _bm->CreateZeroConst(len);
const ASTNode one = _bm->CreateOneConst(len);
{
output = zero;
}
- else if (BVMULT == k
- && 1 == nonconstkids.size()
+ else if (BVMULT == k
+ && 1 == nonconstkids.size()
&& constoutput == max)
{
//useful special case opt: when input is BVMULT(max_const,t),
//then output = BVUMINUS(t). this is easier on the bitblaster
- output =
+ output =
nf->CreateTerm(BVUMINUS, inputValueWidth, nonconstkids);
- }
+ }
else
{
if (0 < nonconstkids.size())