10#define DEBUG_TYPE "independent-solver"
17#include "klee/Support/Debug.h"
20#include "llvm/Support/raw_ostream.h"
42 for (; start<
end; start++)
48 bool modified =
false;
49 for (
typename set_ty::const_iterator it = b.
s.begin(), ie = b.
s.end();
51 if (modified || !
s.count(*it)) {
60 for (
typename set_ty::iterator it =
s.begin(), ie =
s.end();
67 std::set<unsigned>::iterator
begin(){
71 std::set<unsigned>::iterator
end(){
75 void print(llvm::raw_ostream &os)
const {
78 for (
typename set_ty::iterator it =
s.begin(), ie =
s.end();
92inline llvm::raw_ostream &
operator<<(llvm::raw_ostream &os,
93 const ::DenseSet<T> &dis) {
100 typedef std::map<const Array*, ::DenseSet<unsigned> >
elements_ty;
116 std::vector< ref<ReadExpr> > reads;
118 for (
unsigned i = 0; i != reads.size(); ++i) {
131 dis.
add((
unsigned) CE->getZExtValue(32));
133 elements_ty::iterator it2 =
elements.find(array);
153 void print(llvm::raw_ostream &os)
const {
156 for (std::set<const Array*>::iterator it =
wholeObjects.begin(),
158 const Array *array = *it;
166 os <<
"MO" << array->
name;
168 for (elements_ty::const_iterator it =
elements.begin(), ie =
elements.end();
170 const Array *array = it->first;
171 const ::DenseSet<unsigned> &dis = it->second;
179 os <<
"MO" << array->
name <<
" : " << dis;
187 for (std::set<const Array*>::iterator it =
wholeObjects.begin(),
189 const Array *array = *it;
196 const Array *array = it->first;
200 elements_ty::const_iterator it2 = b.
elements.find(array);
203 if (it->second.intersects(it2->second))
212 for(
unsigned i = 0; i < b.
exprs.size(); i ++){
214 exprs.push_back(expr);
217 bool modified =
false;
218 for (std::set<const Array*>::const_iterator it = b.
wholeObjects.begin(),
220 const Array *array = *it;
221 elements_ty::iterator it2 =
elements.find(array);
233 for (elements_ty::const_iterator it = b.
elements.begin(),
234 ie = b.
elements.end(); it != ie; ++it) {
235 const Array *array = it->first;
237 elements_ty::iterator it2 =
elements.find(array);
243 if (it2->second.add(it->second))
262static std::list<IndependentElementSet>*
264 std::list<IndependentElementSet> *factors =
new std::list<IndependentElementSet>();
267 assert(CE && CE->
isFalse() &&
"the expr should always be false and "
268 "therefore not included in factors");
283 bool doneLoop =
false;
286 std::list<IndependentElementSet> *done =
287 new std::list<IndependentElementSet>;
288 while (factors->size() > 0) {
290 factors->pop_front();
294 std::list<IndependentElementSet> *keep =
295 new std::list<IndependentElementSet>;
296 while (factors->size() > 0) {
298 factors->pop_front();
300 if (current.
add(compare)) {
306 keep->push_back(compare);
309 done->push_back(current);
336 it = worklist.begin(), ie = worklist.end(); it != ie; ++it) {
337 if (it->second.intersects(eltsClosure)) {
338 if (eltsClosure.
add(it->second))
340 result.push_back(it->first);
344 newWorklist.push_back(*it);
347 worklist.swap(newWorklist);
351 std::set<
ref<Expr> > reqset(result.begin(), result.end());
353 errs() <<
"Q: " << query.
expr <<
"\n";
357 errs() <<
"C" << i++ <<
": " << constraint;
358 errs() <<
" " << (reqset.count(constraint) ?
"(required)" :
"(independent)") <<
"\n";
361 errs() <<
"elts closure: " << eltsClosure <<
"\n";
373 std::vector<const Array *> &returnVector){
374 std::set<const Array*> thisSeen;
377 thisSeen.insert(it->first);
379 for(std::set<const Array *>::iterator it = ie.
wholeObjects.begin();
381 thisSeen.insert(*it);
383 for(std::set<const Array *>::iterator it = thisSeen.begin(); it != thisSeen.end();
385 returnVector.push_back(*it);
402 const std::vector<const Array*> &objects,
403 std::vector< std::vector<unsigned char> > &values,
412 std::vector< ref<Expr> > required;
421 std::vector< ref<Expr> > required;
430 std::vector< ref<Expr> > required;
441 const Query &query,
const std::vector<const Array *> &objects,
442 std::vector<std::vector<unsigned char>> &values,
443 std::map<
const Array *, std::vector<unsigned char>> &retMap) {
453 if (retMap.size() > 0)
454 assign.
bindings.insert(retMap.begin(), retMap.end());
459 assert(isa<ConstantExpr>(ret) &&
460 "assignment evaluation did not result in constant");
462 if (evaluatedConstraint->isFalse()) {
468 assert(isa<ConstantExpr>(q) &&
469 "assignment evaluation did not result in constant");
470 return cast<ConstantExpr>(q)->isTrue();
474 const std::vector<const Array*> &objects,
475 std::vector< std::vector<unsigned char> > &values,
486 std::map<const Array*, std::vector<unsigned char> > retMap;
487 for (std::list<IndependentElementSet>::iterator it = factors->begin();
488 it != factors->end(); ++it) {
489 std::vector<const Array*> arraysInFactor;
492 assert(it->exprs.size() >= 1 &&
"No null/empty factors");
493 if (arraysInFactor.size() == 0){
497 std::vector<std::vector<unsigned char> > tempValues;
499 arraysInFactor, tempValues, hasSolution)){
503 }
else if (!hasSolution){
508 assert(tempValues.size() == arraysInFactor.size() &&
509 "Should be equal number arrays and answers");
510 for (
unsigned i = 0; i < tempValues.size(); i++){
511 if (retMap.count(arraysInFactor[i])){
515 std::vector<unsigned char> * tempPtr = &retMap[arraysInFactor[i]];
516 assert(tempPtr->size() == tempValues[i].size() &&
517 "we're talking about the same array here");
519 for (std::set<unsigned>::iterator it2 = ds->
begin(); it2 != ds->
end(); it2++){
520 unsigned index = * it2;
521 (* tempPtr)[index] = tempValues[i][index];
525 retMap[arraysInFactor[i]] = tempValues[i];
530 for (std::vector<const Array *>::const_iterator it = objects.begin();
531 it != objects.end(); it++){
532 const Array * arr = * it;
533 if (!retMap.count(arr)){
537 std::vector<unsigned char> ret(arr->
size);
538 values.push_back(ret);
540 values.push_back(retMap[arr]);
static IndependentElementSet getIndependentConstraints(const Query &query, std::vector< ref< Expr > > &result)
bool assertCreatedPointEvaluatesToTrue(const Query &query, const std::vector< const Array * > &objects, std::vector< std::vector< unsigned char > > &values, std::map< const Array *, std::vector< unsigned char > > &retMap)
llvm::raw_ostream & operator<<(llvm::raw_ostream &os, const ::DenseSet< T > &dis)
static void calculateArrayReferences(const IndependentElementSet &ie, std::vector< const Array * > &returnVector)
static std::list< IndependentElementSet > * getAllIndependentConstraintsSets(const Query &query)
void print(llvm::raw_ostream &os) const
std::set< unsigned >::iterator begin()
bool intersects(const DenseSet &b)
std::set< unsigned >::iterator end()
bool add(const DenseSet &b)
IndependentElementSet(ref< Expr > e)
std::set< const Array * > wholeObjects
bool intersects(const IndependentElementSet &b)
IndependentElementSet & operator=(const IndependentElementSet &ies)
IndependentElementSet(const IndependentElementSet &ies)
std::map< const Array *, ::DenseSet< unsigned > > elements_ty
std::vector< ref< Expr > > exprs
bool add(const IndependentElementSet &b)
void print(llvm::raw_ostream &os) const
bool computeValidity(const Query &, Solver::Validity &result)
void setCoreSolverTimeout(time::Span timeout)
bool computeValue(const Query &, ref< Expr > &result)
SolverRunStatus getOperationStatusCode()
getOperationStatusCode - get the status of the last solver operation
bool computeInitialValues(const Query &query, const std::vector< const Array * > &objects, std::vector< std::vector< unsigned char > > &values, bool &hasSolution)
bool computeTruth(const Query &, bool &isValid)
char * getConstraintLog(const Query &)
IndependentSolver(Solver *_solver)
bool isConstantArray() const
ref< Expr > evaluate(const Array *mo, unsigned index) const
bool isFalse() const
isFalse - Is this the false expression.
Class representing a one byte read from an array.
SolverImpl - Abstract base clase for solver implementations.
virtual void setCoreSolverTimeout(time::Span timeout)
virtual bool computeTruth(const Query &query, bool &isValid)=0
virtual bool computeInitialValues(const Query &query, const std::vector< const Array * > &objects, std::vector< std::vector< unsigned char > > &values, bool &hasSolution)=0
virtual bool computeValue(const Query &query, ref< Expr > &result)=0
virtual char * getConstraintLog(const Query &query)
virtual bool computeValidity(const Query &query, Solver::Validity &result)
virtual SolverRunStatus getOperationStatusCode()=0
getOperationStatusCode - get the status of the last solver operation
ref< UpdateNode > head
pointer to the most recent update node
void findReads(ref< Expr > e, bool visitUpdates, std::vector< ref< ReadExpr > > &result)
Solver * createIndependentSolver(Solver *s)
const ConstraintSet & constraints