From 03eca4ba3255665bd4b2e246b92f63cc2b06a1bf Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Tue, 16 Jun 2009 02:26:40 +0000 Subject: Start SimplifyingExprBuilder - Normalize Ne, Ugt, Uge, Slt, Sge git-svn-id: https://llvm.org/svn/llvm-project/klee/trunk@73458 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Expr/ExprBuilder.cpp | 145 +++++++---------------------------------------- 1 file changed, 21 insertions(+), 124 deletions(-) (limited to 'lib') diff --git a/lib/Expr/ExprBuilder.cpp b/lib/Expr/ExprBuilder.cpp index 0c8ce06e..098da6ea 100644 --- a/lib/Expr/ExprBuilder.cpp +++ b/lib/Expr/ExprBuilder.cpp @@ -854,142 +854,39 @@ namespace { typedef ConstantSpecializedExprBuilder ConstantFoldingExprBuilder; - class SimplifyingExprBuilder : public ExprBuilder { - ExprBuilder *Base; - + class SimplifyingBuilder : public ChainedBuilder { public: - SimplifyingExprBuilder(ExprBuilder *_Base) : Base(_Base) {} - ~SimplifyingExprBuilder() { - delete Base; - } - - virtual ref Constant(uint64_t Value, Expr::Width W) { - return Base->Constant(Value, W); - } - - virtual ref NotOptimized(const ref &Index) { - return Base->NotOptimized(Index); - } - - virtual ref Read(const UpdateList &Updates, - const ref &Index) { - return Base->Read(Updates, Index); - } - - virtual ref Select(const ref &Cond, - const ref &LHS, const ref &RHS) { - return Base->Select(Cond, LHS, RHS); - } - - virtual ref Concat(const ref &LHS, const ref &RHS) { - return Base->Concat(LHS, RHS); - } - - virtual ref Extract(const ref &LHS, - unsigned Offset, Expr::Width W) { - return Base->Extract(LHS, Offset, W); - } - - virtual ref ZExt(const ref &LHS, Expr::Width W) { - return Base->ZExt(LHS, W); - } - - virtual ref SExt(const ref &LHS, Expr::Width W) { - return Base->SExt(LHS, W); - } - - virtual ref Add(const ref &LHS, const ref &RHS) { - return Base->Add(LHS, RHS); - } - - virtual ref Sub(const ref &LHS, const ref &RHS) { - return Base->Sub(LHS, RHS); - } - - virtual ref Mul(const ref &LHS, const ref &RHS) { - return Base->Mul(LHS, RHS); - } - - virtual ref UDiv(const ref &LHS, const ref &RHS) { - return Base->UDiv(LHS, RHS); - } - - virtual ref SDiv(const ref &LHS, const ref &RHS) { - return Base->SDiv(LHS, RHS); - } - - virtual ref URem(const ref &LHS, const ref &RHS) { - return Base->URem(LHS, RHS); - } - - virtual ref SRem(const ref &LHS, const ref &RHS) { - return Base->SRem(LHS, RHS); - } - - virtual ref And(const ref &LHS, const ref &RHS) { - return Base->And(LHS, RHS); - } - - virtual ref Or(const ref &LHS, const ref &RHS) { - return Base->Or(LHS, RHS); - } - - virtual ref Xor(const ref &LHS, const ref &RHS) { - return Base->Xor(LHS, RHS); - } - - virtual ref Shl(const ref &LHS, const ref &RHS) { - return Base->Shl(LHS, RHS); - } - - virtual ref LShr(const ref &LHS, const ref &RHS) { - return Base->LShr(LHS, RHS); - } - - virtual ref AShr(const ref &LHS, const ref &RHS) { - return Base->AShr(LHS, RHS); - } - - virtual ref Eq(const ref &LHS, const ref &RHS) { - return Base->Eq(LHS, RHS); - } - - virtual ref Ne(const ref &LHS, const ref &RHS) { - return Base->Ne(LHS, RHS); - } - - virtual ref Ult(const ref &LHS, const ref &RHS) { - return Base->Ult(LHS, RHS); - } - - virtual ref Ule(const ref &LHS, const ref &RHS) { - return Base->Ule(LHS, RHS); - } - - virtual ref Ugt(const ref &LHS, const ref &RHS) { - return Base->Ugt(LHS, RHS); - } + SimplifyingBuilder(ExprBuilder *Builder, ExprBuilder *Base) + : ChainedBuilder(Builder, Base) {} - virtual ref Uge(const ref &LHS, const ref &RHS) { - return Base->Uge(LHS, RHS); + ref Ne(const ref &LHS, const ref &RHS) { + // X != Y ==> !(X == Y) + return Builder->Not(Builder->Eq(LHS, RHS)); } - virtual ref Slt(const ref &LHS, const ref &RHS) { - return Base->Slt(LHS, RHS); + ref Ugt(const ref &LHS, const ref &RHS) { + // X u> Y ==> Y u< X + return Builder->Ult(RHS, LHS); } - virtual ref Sle(const ref &LHS, const ref &RHS) { - return Base->Sle(LHS, RHS); + ref Uge(const ref &LHS, const ref &RHS) { + // X u>= Y ==> Y u<= X + return Builder->Ule(RHS, LHS); } - virtual ref Sgt(const ref &LHS, const ref &RHS) { - return Base->Sgt(LHS, RHS); + ref Sgt(const ref &LHS, const ref &RHS) { + // X s> Y ==> Y s< X + return Builder->Slt(RHS, LHS); } - virtual ref Sge(const ref &LHS, const ref &RHS) { - return Base->Sge(LHS, RHS); + ref Sge(const ref &LHS, const ref &RHS) { + // X s>= Y ==> Y s<= X + return Builder->Sle(RHS, LHS); } }; + + typedef ConstantSpecializedExprBuilder + SimplifyingExprBuilder; } ExprBuilder *klee::createDefaultExprBuilder() { -- cgit 1.4.1