summaryrefslogtreecommitdiff
path: root/klee/lib/Expr
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-06-16 03:33:57 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-06-16 03:33:57 +0000
commit1fb0c97cbdeb68f0be3e73c4629d045813a3c6ae (patch)
treebfd8f8373d4f5542c927ee78ebae705a8154983c /klee/lib/Expr
parentb09e3206eefe11ba13020bae47706a2f69c96d14 (diff)
Add (very) basic constant folding for And,Or,Xor.
- Lots more important goodness can be done here.
Diffstat (limited to 'klee/lib/Expr')
-rw-r--r--klee/lib/Expr/ExprBuilder.cpp65
1 files changed, 63 insertions, 2 deletions
diff --git a/klee/lib/Expr/ExprBuilder.cpp b/klee/lib/Expr/ExprBuilder.cpp
index bb6f28ec6da..aaddb3e3372 100644
--- a/klee/lib/Expr/ExprBuilder.cpp
+++ b/klee/lib/Expr/ExprBuilder.cpp
@@ -856,8 +856,8 @@ namespace {
return LHS;
if (LHS->isOne())
return RHS;
- // FIXME: Unbalance muls, fold constants through {sub,add}-with-constant,
- // etc.
+ // FIXME: Unbalance nested muls, fold constants through
+ // {sub,add}-with-constant, etc.
return Base->Mul(LHS, RHS);
}
@@ -870,6 +870,67 @@ namespace {
const ref<NonConstantExpr> &RHS) {
return Base->Mul(LHS, RHS);
}
+
+ ref<Expr> And(const ref<ConstantExpr> &LHS,
+ const ref<NonConstantExpr> &RHS) {
+ if (LHS->isZero())
+ return LHS;
+ if (LHS->isAllOnes())
+ return RHS;
+ // FIXME: Unbalance nested ands, fold constants through
+ // {and,or}-with-constant, etc.
+ return Base->And(LHS, RHS);
+ }
+
+ ref<Expr> And(const ref<NonConstantExpr> &LHS,
+ const ref<ConstantExpr> &RHS) {
+ return And(RHS, LHS);
+ }
+
+ ref<Expr> And(const ref<NonConstantExpr> &LHS,
+ const ref<NonConstantExpr> &RHS) {
+ return Base->And(LHS, RHS);
+ }
+
+ ref<Expr> Or(const ref<ConstantExpr> &LHS,
+ const ref<NonConstantExpr> &RHS) {
+ if (LHS->isZero())
+ return RHS;
+ if (LHS->isAllOnes())
+ return LHS;
+ // FIXME: Unbalance nested ors, fold constants through
+ // {and,or}-with-constant, etc.
+ return Base->Or(LHS, RHS);
+ }
+
+ ref<Expr> Or(const ref<NonConstantExpr> &LHS,
+ const ref<ConstantExpr> &RHS) {
+ return Or(RHS, LHS);
+ }
+
+ ref<Expr> Or(const ref<NonConstantExpr> &LHS,
+ const ref<NonConstantExpr> &RHS) {
+ return Base->Or(LHS, RHS);
+ }
+
+ ref<Expr> Xor(const ref<ConstantExpr> &LHS,
+ const ref<NonConstantExpr> &RHS) {
+ if (LHS->isZero())
+ return RHS;
+ // FIXME: Unbalance nested ors, fold constants through
+ // {and,or}-with-constant, etc.
+ return Base->Xor(LHS, RHS);
+ }
+
+ ref<Expr> Xor(const ref<NonConstantExpr> &LHS,
+ const ref<ConstantExpr> &RHS) {
+ return Xor(RHS, LHS);
+ }
+
+ ref<Expr> Xor(const ref<NonConstantExpr> &LHS,
+ const ref<NonConstantExpr> &RHS) {
+ return Base->Xor(LHS, RHS);
+ }
};
typedef ConstantSpecializedExprBuilder<ConstantFoldingBuilder>