TimingSolver.cpp

Go to the documentation of this file.
00001 //===-- TimingSolver.cpp --------------------------------------------------===//
00002 //
00003 //                     The KLEE Symbolic Virtual Machine
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 
00010 #include "TimingSolver.h"
00011 
00012 #include "klee/ExecutionState.h"
00013 #include "klee/Solver.h"
00014 #include "klee/Statistics.h"
00015 
00016 #include "CoreStats.h"
00017 
00018 #include "llvm/System/Process.h"
00019 
00020 using namespace klee;
00021 using namespace llvm;
00022 
00023 /***/
00024 
00025 bool TimingSolver::evaluate(const ExecutionState& state, ref<Expr> expr,
00026                             Solver::Validity &result) {
00027   // Fast path, to avoid timer and OS overhead.
00028   if (ConstantExpr *CE = dyn_cast<ConstantExpr>(expr)) {
00029     result = CE->getConstantValue() ? Solver::True : Solver::False;
00030     return true;
00031   }
00032 
00033   sys::TimeValue now(0,0),user(0,0),delta(0,0),sys(0,0);
00034   sys::Process::GetTimeUsage(now,user,sys);
00035 
00036   if (simplifyExprs)
00037     expr = state.constraints.simplifyExpr(expr);
00038 
00039   bool success = solver->evaluate(Query(state.constraints, expr), result);
00040 
00041   sys::Process::GetTimeUsage(delta,user,sys);
00042   delta -= now;
00043   stats::solverTime += delta.usec();
00044   state.queryCost += delta.usec()/1000000.;
00045 
00046   return success;
00047 }
00048 
00049 bool TimingSolver::mustBeTrue(const ExecutionState& state, ref<Expr> expr, 
00050                               bool &result) {
00051   // Fast path, to avoid timer and OS overhead.
00052   if (ConstantExpr *CE = dyn_cast<ConstantExpr>(expr)) {
00053     result = CE->getConstantValue() ? true : false;
00054     return true;
00055   }
00056 
00057   sys::TimeValue now(0,0),user(0,0),delta(0,0),sys(0,0);
00058   sys::Process::GetTimeUsage(now,user,sys);
00059 
00060   if (simplifyExprs)
00061     expr = state.constraints.simplifyExpr(expr);
00062 
00063   bool success = solver->mustBeTrue(Query(state.constraints, expr), result);
00064 
00065   sys::Process::GetTimeUsage(delta,user,sys);
00066   delta -= now;
00067   stats::solverTime += delta.usec();
00068   state.queryCost += delta.usec()/1000000.;
00069 
00070   return success;
00071 }
00072 
00073 bool TimingSolver::mustBeFalse(const ExecutionState& state, ref<Expr> expr,
00074                                bool &result) {
00075   return mustBeTrue(state, Expr::createNot(expr), result);
00076 }
00077 
00078 bool TimingSolver::mayBeTrue(const ExecutionState& state, ref<Expr> expr, 
00079                              bool &result) {
00080   bool res;
00081   if (!mustBeFalse(state, expr, res))
00082     return false;
00083   result = !res;
00084   return true;
00085 }
00086 
00087 bool TimingSolver::mayBeFalse(const ExecutionState& state, ref<Expr> expr, 
00088                               bool &result) {
00089   bool res;
00090   if (!mustBeTrue(state, expr, res))
00091     return false;
00092   result = !res;
00093   return true;
00094 }
00095 
00096 bool TimingSolver::getValue(const ExecutionState& state, ref<Expr> expr, 
00097                             ref<ConstantExpr> &result) {
00098   // Fast path, to avoid timer and OS overhead.
00099   if (ConstantExpr *CE = dyn_cast<ConstantExpr>(expr)) {
00100     result = CE;
00101     return true;
00102   }
00103   
00104   sys::TimeValue now(0,0),user(0,0),delta(0,0),sys(0,0);
00105   sys::Process::GetTimeUsage(now,user,sys);
00106 
00107   if (simplifyExprs)
00108     expr = state.constraints.simplifyExpr(expr);
00109 
00110   bool success = solver->getValue(Query(state.constraints, expr), result);
00111 
00112   sys::Process::GetTimeUsage(delta,user,sys);
00113   delta -= now;
00114   stats::solverTime += delta.usec();
00115   state.queryCost += delta.usec()/1000000.;
00116 
00117   return success;
00118 }
00119 
00120 bool 
00121 TimingSolver::getInitialValues(const ExecutionState& state, 
00122                                const std::vector<const Array*>
00123                                  &objects,
00124                                std::vector< std::vector<unsigned char> >
00125                                  &result) {
00126   if (objects.empty())
00127     return true;
00128 
00129   sys::TimeValue now(0,0),user(0,0),delta(0,0),sys(0,0);
00130   sys::Process::GetTimeUsage(now,user,sys);
00131 
00132   bool success = solver->getInitialValues(Query(state.constraints,
00133                                                 ConstantExpr::alloc(0, Expr::Bool)), 
00134                                           objects, result);
00135   
00136   sys::Process::GetTimeUsage(delta,user,sys);
00137   delta -= now;
00138   stats::solverTime += delta.usec();
00139   state.queryCost += delta.usec()/1000000.;
00140   
00141   return success;
00142 }
00143 
00144 std::pair< ref<Expr>, ref<Expr> >
00145 TimingSolver::getRange(const ExecutionState& state, ref<Expr> expr) {
00146   return solver->getRange(Query(state.constraints, expr));
00147 }

Generated on Fri Jun 5 03:31:32 2009 for klee by  doxygen 1.5.8