klee
|
Class representing symbolic expressions. More...
#include <Expr.h>
Classes | |
struct | CreateArg |
Public Types | |
enum | Kind { InvalidKind = -1 , Constant = 0 , NotOptimized , Read =NotOptimized+2 , Select , Concat , Extract , ZExt , SExt , Not , Add , Sub , Mul , UDiv , SDiv , URem , SRem , And , Or , Xor , Shl , LShr , AShr , Eq , Ne , Ult , Ule , Ugt , Uge , Slt , Sle , Sgt , Sge , LastKind =Sge , CastKindFirst =ZExt , CastKindLast =SExt , BinaryKindFirst =Add , BinaryKindLast =Sge , CmpKindFirst =Eq , CmpKindLast =Sge } |
typedef unsigned | Width |
The type of an expression is simply its width, in bits. More... | |
Public Member Functions | |
Expr () | |
virtual | ~Expr () |
virtual Kind | getKind () const =0 |
virtual Width | getWidth () const =0 |
virtual unsigned | getNumKids () const =0 |
virtual ref< Expr > | getKid (unsigned i) const =0 |
virtual void | print (llvm::raw_ostream &os) const |
void | dump () const |
dump - Print the expression to stderr. More... | |
virtual unsigned | hash () const |
Returns the pre-computed hash of the current expression. More... | |
virtual unsigned | computeHash () |
int | compare (const Expr &b) const |
virtual ref< Expr > | rebuild (ref< Expr > kids[]) const =0 |
bool | isZero () const |
isZero - Is this a constant zero. More... | |
bool | isTrue () const |
isTrue - Is this the true expression. More... | |
bool | isFalse () const |
isFalse - Is this the false expression. More... | |
Static Public Member Functions | |
static void | printKind (llvm::raw_ostream &os, Kind k) |
static void | printWidth (llvm::raw_ostream &os, Expr::Width w) |
static unsigned | getMinBytesForWidth (Width w) |
returns the smallest number of bytes in which the given width fits More... | |
static ref< Expr > | createSExtToPointerWidth (ref< Expr > e) |
static ref< Expr > | createZExtToPointerWidth (ref< Expr > e) |
static ref< Expr > | createImplies (ref< Expr > hyp, ref< Expr > conc) |
static ref< Expr > | createIsZero (ref< Expr > e) |
static ref< Expr > | createTempRead (const Array *array, Expr::Width w) |
static ref< ConstantExpr > | createPointer (uint64_t v) |
static ref< Expr > | createFromKind (Kind k, std::vector< CreateArg > args) |
static bool | isValidKidWidth (unsigned kid, Width w) |
static bool | needsResultType () |
static bool | classof (const Expr *) |
Public Attributes | |
class ReferenceCounter | _refCount |
Required by klee::ref-managed objects. More... | |
Static Public Attributes | |
static unsigned | count = 0 |
static const unsigned | MAGIC_HASH_CONSTANT = 39 |
static const Width | InvalidWidth = 0 |
static const Width | Bool = 1 |
static const Width | Int8 = 8 |
static const Width | Int16 = 16 |
static const Width | Int32 = 32 |
static const Width | Int64 = 64 |
static const Width | Fl80 = 80 |
Protected Member Functions | |
virtual int | compareContents (const Expr &b) const =0 |
Protected Attributes | |
unsigned | hashValue |
Private Types | |
typedef llvm::DenseSet< std::pair< const Expr *, const Expr * > > | ExprEquivSet |
Private Member Functions | |
int | compare (const Expr &b, ExprEquivSet &equivs) const |
Class representing symbolic expressions.
Expression canonicalization: we define certain rules for canonicalization rules for Exprs in order to simplify code that pattern matches Exprs (since the number of forms are reduced), to open up further chances for optimization, and to increase similarity for caching and other purposes.
The general rules are:
No Expr has all constant arguments.
Booleans:
Ne
, Ugt
, Uge
, Sgt
, Sge
are not used Not
And
, Or
, Xor
, Eq
, as well as SExt
, ZExt
, Select
and NotOptimized
. == false
). Linear Formulas:
add(-c, ?)
. Chains are unbalanced to the right
Steps required for adding an expr:
Todo: Shouldn't bool Xor
just be written as not equal?
|
private |
typedef unsigned klee::Expr::Width |
enum klee::Expr::Kind |
|
inlinevirtual |
|
inlinestatic |
int Expr::compare | ( | const Expr & | b | ) | const |
Compares b
to this
Expr for structural equivalence.
This method effectively defines a total order over all Expr.
[in] | b | Expr to compare this to. |
this
is <
b
this
is structurally equivalent to b
this
is >
b
<
and >
are binary relations that express the total order.
Definition at line 95 of file Expr.cpp.
References compare().
Referenced by compare(), klee::operator<(), and klee::operator==().
|
private |
Definition at line 103 of file Expr.cpp.
References compare(), compareContents(), getKid(), getKind(), getNumKids(), and hashValue.
|
protectedpure virtual |
Compares b
to this
Expr and determines how they are ordered (ignoring their kid expressions - i.e. those returned by getKid()
).
Typically this requires comparing internal attributes of the Expr.
Implementations can assume that b
and this
are of the same kind.
This method effectively defines a partial order over Expr of the same kind (partial because kid Expr are not compared).
This method should not be called directly. Instead compare()
should be used.
[in] | b | Expr to compare this to. |
this
is <
b
ignoring kid expressions.this
is >
b
ignoring kid expressions.this
and b
are not ordered.<
and >
are binary relations that express the partial order.
Implemented in klee::NotOptimizedExpr, klee::ReadExpr, klee::SelectExpr, klee::ConcatExpr, klee::ExtractExpr, klee::NotExpr, klee::CastExpr, and klee::ConstantExpr.
Referenced by compare().
|
virtual |
(Re)computes the hash of the current expression. Returns the hash value.
Reimplemented in klee::ReadExpr, klee::ExtractExpr, klee::NotExpr, klee::CastExpr, and klee::ConstantExpr.
Definition at line 182 of file Expr.cpp.
References getKid(), getKind(), getNumKids(), hash(), hashValue, and MAGIC_HASH_CONSTANT.
Referenced by klee::SelectExpr::alloc(), klee::NotExpr::alloc(), klee::ExtractExpr::alloc(), klee::ConcatExpr::alloc(), klee::NotOptimizedExpr::alloc(), and klee::ReadExpr::alloc().
Definition at line 230 of file Expr.cpp.
References Add, And, AShr, BINARY_EXPR_CASE, CAST_EXPR_CASE, Concat, Constant, klee::ConcatExpr::create(), klee::SelectExpr::create(), klee::NotOptimizedExpr::create(), Eq, Extract, LShr, Mul, Ne, NotOptimized, Or, Read, SDiv, Select, SExt, Sge, Sgt, Shl, Sle, Slt, SRem, Sub, UDiv, Uge, Ugt, Ule, Ult, URem, Xor, and ZExt.
Definition at line 318 of file Expr.cpp.
References createIsZero().
Definition at line 322 of file Expr.cpp.
References klee::ConstantExpr::create(), and getWidth().
Referenced by klee::ValidatingSolver::computeInitialValues(), klee::SelectExpr::create(), createImplies(), EqExpr_createPartialR(), klee::Executor::executeFree(), klee::Executor::executeInstruction(), klee::Executor::fork(), klee::Executor::getSymbolicSolution(), LShrExpr_create(), klee::TimingSolver::mustBeFalse(), klee::Query::negateExpr(), klee::ExprSMTLIBPrinter::printHumanReadableQuery(), klee::ExprSMTLIBPrinter::printQueryInSingleAssert(), ShlExpr_create(), SleExpr_create(), SltExpr_create(), UleExpr_create(), and UltExpr_create().
|
static |
Definition at line 46 of file Context.cpp.
References klee::ConstantExpr::create(), and klee::Context::get().
Referenced by klee::Executor::allocateGlobalObjects(), klee::Executor::evalConstant(), klee::Executor::executeFree(), klee::Executor::executeInstruction(), and klee::Executor::runFunctionAsMain().
Definition at line 38 of file Context.cpp.
References klee::Context::get().
Referenced by klee::Executor::executeInstruction().
|
static |
Create a little endian read of the given type at offset 0 of the given object.
Definition at line 49 of file Expr.cpp.
References klee::ConstantExpr::alloc(), Bool, klee::ConcatExpr::create(), klee::ReadExpr::create(), klee::ConcatExpr::create4(), klee::ConcatExpr::create8(), Int16, Int32, Int64, and Int8.
Referenced by klee::Executor::replaceReadWithSymbolic().
Definition at line 42 of file Context.cpp.
References klee::Context::get().
Referenced by klee::Executor::executeInstruction().
void Expr::dump | ( | ) | const |
dump - Print the expression to stderr.
Definition at line 330 of file Expr.cpp.
References print().
Referenced by klee::Query::dump().
Implemented in klee::BinaryExpr, klee::NotOptimizedExpr, klee::ReadExpr, klee::SelectExpr, klee::ConcatExpr, klee::ExtractExpr, klee::NotExpr, klee::CastExpr, and klee::ConstantExpr.
Referenced by AddExpr_create(), AddExpr_createPartialR(), compare(), computeHash(), klee::ExprRangeEvaluator< T >::evaluate(), klee::findReads(), klee::ExprSMTLIBPrinter::getSort(), klee::ArrayExprHelper::hasOrderedReads(), klee::AssignmentGenerator::hasOrderedReads(), PPrinter::hasOrderedReads(), PPrinter::hasSimpleKids(), klee::AssignmentGenerator::helperGenerateAssignment(), PPrinter::isSimple(), PPrinter::printExpr(), klee::ExprSMTLIBPrinter::printFullExpression(), klee::ExprSMTLIBPrinter::printLogicalOrBitVectorExpr(), klee::ExprSMTLIBPrinter::printSortArgsExpr(), CexData::propogateExactValues(), CexData::propogatePossibleValues(), klee::ExprSMTLIBPrinter::scan(), PPrinter::scan1(), klee::ExprSMTLIBPrinter::scanBindingExprDeps(), SubExpr_create(), SubExpr_createPartialR(), klee::ExprVisitor::visitActual(), and klee::ExprEvaluator::visitExpr().
|
pure virtual |
Implemented in klee::NotOptimizedExpr, klee::ReadExpr, klee::SelectExpr, klee::ConcatExpr, klee::ExtractExpr, klee::NotExpr, and klee::ConstantExpr.
Referenced by klee::ConstraintManager::addConstraintInternal(), AddExpr_create(), AddExpr_createPartialR(), klee::NonConstantExpr::classof(), klee::BinaryExpr::classof(), klee::CmpExpr::classof(), klee::NotOptimizedExpr::classof(), klee::ReadExpr::classof(), klee::SelectExpr::classof(), klee::ConcatExpr::classof(), klee::ExtractExpr::classof(), klee::NotExpr::classof(), klee::CastExpr::classof(), klee::ConstantExpr::classof(), compare(), computeHash(), klee::AssignmentGenerator::createExtendExpr(), EqExpr_createPartialR(), klee::ExprRangeEvaluator< T >::evaluate(), klee::ImpliedValue::getImpliedValues(), klee::ExprSMTLIBPrinter::getSMTLIBKeyword(), klee::ExprSMTLIBPrinter::getSort(), klee::ArrayExprHelper::hasOrderedReads(), klee::AssignmentGenerator::hasOrderedReads(), PPrinter::hasOrderedReads(), klee::AssignmentGenerator::helperGenerateAssignment(), PPrinter::print(), klee::ExprSMTLIBPrinter::printFullExpression(), klee::ExprSMTLIBPrinter::printLogicalOrBitVectorExpr(), CexData::propogateExactValues(), CexData::propogatePossibleValues(), SubExpr_create(), SubExpr_createPartialR(), klee::ExprVisitor::visitActual(), and klee::ExprEvaluator::visitExprPost().
|
inlinestatic |
returns the smallest number of bytes in which the given width fits
Definition at line 262 of file Expr.h.
Referenced by klee::Executor::executeCall(), klee::Executor::executeMemoryOperation(), and klee::Executor::replaceReadWithSymbolic().
|
pure virtual |
Implemented in klee::BinaryExpr, klee::NotOptimizedExpr, klee::ReadExpr, klee::SelectExpr, klee::ConcatExpr, klee::ExtractExpr, klee::NotExpr, klee::CastExpr, and klee::ConstantExpr.
Referenced by compare(), computeHash(), klee::ExprRangeEvaluator< T >::evaluate(), klee::findReads(), PPrinter::hasSimpleKids(), PPrinter::isSimple(), PPrinter::printExpr(), klee::ExprSMTLIBPrinter::printLogicalOrBitVectorExpr(), klee::ExprSMTLIBPrinter::printSortArgsExpr(), klee::ExprSMTLIBPrinter::scan(), PPrinter::scan1(), klee::ExprSMTLIBPrinter::scanBindingExprDeps(), klee::ExprVisitor::visitActual(), and klee::ExprEvaluator::visitExpr().
|
pure virtual |
Implemented in klee::CmpExpr, klee::NotOptimizedExpr, klee::ReadExpr, klee::SelectExpr, klee::ConcatExpr, klee::ExtractExpr, klee::NotExpr, klee::CastExpr, and klee::ConstantExpr.
Referenced by AddExpr_create(), AShrExpr_create(), klee::ExprOptimizer::buildConstantSelectExpr(), klee::ExprOptimizer::buildMixedSelectExpr(), klee::ConcatExpr::ConcatExpr(), klee::ConcatExpr::create(), klee::SelectExpr::create(), klee::ExtractExpr::create(), klee::AssignmentGenerator::createExtendExpr(), klee::AssignmentGenerator::createExtractExpr(), createIsZero(), klee::Executor::evalConstant(), klee::Solver::evaluate(), klee::ExprRangeEvaluator< T >::evaluate(), klee::Executor::executeCall(), klee::Executor::executeInstruction(), klee::Executor::executeMemoryOperation(), klee::UpdateList::extend(), klee::AssignmentGenerator::generatePartialAssignment(), klee::ImpliedValue::getImpliedValues(), klee::Solver::getRange(), klee::ExprSMTLIBPrinter::getSort(), klee::NotOptimizedExpr::getWidth(), klee::SelectExpr::getWidth(), klee::NotExpr::getWidth(), klee::ArrayExprHelper::hasOrderedReads(), klee::AssignmentGenerator::hasOrderedReads(), PPrinter::hasOrderedReads(), klee::AssignmentGenerator::helperGenerateAssignment(), isFalse(), isTrue(), LShrExpr_create(), MulExpr_create(), klee::Solver::mustBeTrue(), klee::ExprSMTLIBPrinter::printCastToSort(), PPrinter::printWidth(), CexData::propogateExactValues(), CexData::propogatePossibleValues(), klee::Executor::replaceReadWithSymbolic(), SDivExpr_create(), ShlExpr_create(), PPrinter::shouldPrintWidth(), SleExpr_create(), SltExpr_create(), SRemExpr_create(), SubExpr_create(), TryConstArrayOpt(), UDivExpr_create(), UleExpr_create(), UltExpr_create(), URemExpr_create(), and klee::ObjectState::write().
|
inlinevirtual |
Returns the pre-computed hash of the current expression.
Definition at line 222 of file Expr.h.
References hashValue.
Referenced by computeHash(), klee::UpdateNode::computeHash(), klee::ReadExpr::computeHash(), klee::ExtractExpr::computeHash(), klee::NotExpr::computeHash(), klee::CastExpr::computeHash(), CachingSolver::CacheEntryHash::operator()(), klee::util::ExprHash::operator()(), klee::ConstantArrayExprVisitor::visitConcat(), and klee::ConstantArrayExprVisitor::visitRead().
|
inline |
isFalse - Is this the false expression.
Definition at line 1163 of file Expr.h.
References Bool, and getWidth().
Referenced by klee::ExprPPrinter::printQuery(), and propogateValues().
|
inline |
isTrue - Is this the true expression.
Definition at line 1156 of file Expr.h.
References Bool, and getWidth().
Referenced by klee::ExprOptimizer::computeIndexes(), klee::Executor::executeCall(), propogateValues(), and klee::Assignment::satisfies().
|
inlinestatic |
|
inline |
isZero - Is this a constant zero.
Definition at line 1150 of file Expr.h.
Referenced by klee::Executor::executeInstruction(), and klee::AssignmentGenerator::helperGenerateAssignment().
|
virtual |
Definition at line 326 of file Expr.cpp.
References klee::ExprPPrinter::printSingleExpr().
Referenced by dump(), and klee::operator<<().
|
static |
Definition at line 135 of file Expr.cpp.
References Add, And, AShr, Concat, Constant, Eq, Extract, LShr, Mul, Ne, Not, NotOptimized, Or, Read, SDiv, Select, SExt, Sge, Sgt, Shl, Sle, Slt, SRem, Sub, UDiv, Uge, Ugt, Ule, Ult, URem, X, Xor, and ZExt.
Referenced by klee::AssignmentGenerator::helperGenerateAssignment(), and klee::operator<<().
|
static |
Implemented in klee::NotOptimizedExpr, klee::ReadExpr, klee::SelectExpr, klee::ConcatExpr, klee::ExtractExpr, klee::NotExpr, and klee::ConstantExpr.
Referenced by klee::ExprEvaluator::protectedDivOperation(), klee::ExprVisitor::visitActual(), and klee::ExprEvaluator::visitExpr().
class ReferenceCounter klee::Expr::_refCount |
|
static |
Definition at line 100 of file Expr.h.
Referenced by klee::Executor::addConstraint(), AddExpr_create(), AddExpr_createPartialR(), AShrExpr_create(), klee::SelectExpr::create(), createTempRead(), klee::ConstantExpr::Eq(), EqExpr_create(), EqExpr_createPartialR(), klee::Solver::evaluate(), klee::Executor::executeInstruction(), klee::ExprBuilder::False(), klee::ConstantExpr::fromMemory(), klee::MemoryObject::getBoundsCheckOffset(), klee::Executor::getConstraintLog(), klee::TimingSolver::getInitialValues(), klee::ExprSMTLIBPrinter::getSort(), klee::Executor::getSymbolicSolution(), klee::CmpExpr::getWidth(), isFalse(), klee::ConstantExpr::isFalse(), isTrue(), klee::ConstantExpr::isTrue(), klee::SelectExpr::isValidKidWidth(), LShrExpr_create(), klee::ExecutionState::merge(), MulExpr_create(), MulExpr_createPartialR(), klee::Solver::mustBeTrue(), klee::ConstantExpr::Ne(), klee::ExprOptimizer::optimizeExpr(), klee::ExprSMTLIBPrinter::printCastToSort(), klee::ExprPPrinter::printConstraints(), printWidth(), klee::ObjectState::read(), SDivExpr_create(), klee::ConstantExpr::Sge(), klee::ConstantExpr::Sgt(), ShlExpr_create(), klee::ConstraintManager::simplifyExpr(), klee::ConstantExpr::Sle(), SleExpr_create(), klee::ConstantExpr::Slt(), SltExpr_create(), SRemExpr_create(), SubExpr_create(), SubExpr_createPartialR(), klee::ConstantExpr::toMemory(), klee::ExprBuilder::True(), TryConstArrayOpt(), UDivExpr_create(), klee::ConstantExpr::Uge(), klee::ConstantExpr::Ugt(), klee::ConstantExpr::Ule(), UleExpr_create(), klee::ConstantExpr::Ult(), UltExpr_create(), URemExpr_create(), klee::Query::withFalse(), klee::ObjectState::write(), and XorExpr_createPartialR().
|
static |
|
static |
Definition at line 105 of file Expr.h.
Referenced by klee::Executor::callExternalFunction(), fpWidthToSemantics(), printWidth(), and klee::ConstantExpr::toMemory().
|
protected |
Definition at line 180 of file Expr.h.
Referenced by compare(), computeHash(), klee::ReadExpr::computeHash(), klee::ExtractExpr::computeHash(), klee::NotExpr::computeHash(), klee::CastExpr::computeHash(), klee::ConstantExpr::computeHash(), and hash().
|
static |
Definition at line 102 of file Expr.h.
Referenced by createTempRead(), klee::ConstantExpr::fromMemory(), printWidth(), klee::ConstantExpr::toMemory(), and klee::ObjectState::write().
|
static |
Definition at line 103 of file Expr.h.
Referenced by klee::ExprOptimizer::buildConstantSelectExpr(), klee::ExprRewriter::concatenateOrExpr(), createTempRead(), klee::Executor::executeCall(), klee::Executor::executeInstruction(), klee::ObjectState::flushRangeForRead(), klee::ObjectState::flushRangeForWrite(), fpWidthToSemantics(), klee::ConstantExpr::fromMemory(), klee::Executor::getEhTypeidFor(), klee::SeedInfo::patchSeed(), printWidth(), klee::ObjectState::read(), klee::ObjectState::read8(), klee::Executor::runFunctionAsMain(), klee::ConstantExpr::toMemory(), klee::ObjectState::write(), and klee::ObjectState::write8().
|
static |
Definition at line 104 of file Expr.h.
Referenced by klee::Executor::callExternalFunction(), createTempRead(), klee::Executor::executeCall(), klee::Executor::executeInstruction(), fpWidthToSemantics(), klee::ConstantExpr::fromMemory(), printWidth(), klee::ConstantExpr::toMemory(), and klee::ObjectState::write().
|
static |
Definition at line 101 of file Expr.h.
Referenced by createTempRead(), klee::ObjectState::flushRangeForRead(), klee::ObjectState::flushRangeForWrite(), klee::ConstantExpr::fromMemory(), klee::AssignmentGenerator::getByteValue(), klee::ExprOptimizer::getSelectOptExpr(), klee::ObjectState::getUpdates(), klee::IndexTransformationExprVisitor::getWidth(), klee::ArrayExprHelper::hasOrderedReads(), klee::AssignmentGenerator::hasOrderedReads(), klee::ArrayExprHelper::isReadExprAtOffset(), klee::AssignmentGenerator::isReadExprAtOffset(), klee::SeedInfo::patchSeed(), printWidth(), klee::ObjectState::read8(), klee::ConstantExpr::toMemory(), and klee::ObjectState::write().
|
static |
Definition at line 99 of file Expr.h.
Referenced by klee::IndexTransformationExprVisitor::getWidth(), klee::Expr::CreateArg::isWidth(), and klee::IndexTransformationExprVisitor::visitConcat().
|
static |
Definition at line 94 of file Expr.h.
Referenced by computeHash(), klee::Array::computeHash(), klee::ReadExpr::computeHash(), klee::ExtractExpr::computeHash(), klee::NotExpr::computeHash(), klee::CastExpr::computeHash(), klee::ConstantExpr::computeHash(), and klee::UpdateList::hash().