diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-06-16 03:33:57 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-06-16 03:33:57 +0000 |
commit | 2a05f46ae3bc3a0fb9fc0df78bb8b55a09e6e9a3 (patch) | |
tree | 9262906b88e709f5930895b712ea11ca70479ca1 /lib/Expr | |
parent | ae5eb7c65d8770795f33cbb27de1380b885b53d6 (diff) | |
download | klee-2a05f46ae3bc3a0fb9fc0df78bb8b55a09e6e9a3.tar.gz |
Add (very) basic constant folding for And,Or,Xor.
- Lots more important goodness can be done here. git-svn-id: https://llvm.org/svn/llvm-project/klee/trunk@73461 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Expr')
-rw-r--r-- | lib/Expr/ExprBuilder.cpp | 65 |
1 files changed, 63 insertions, 2 deletions
diff --git a/lib/Expr/ExprBuilder.cpp b/lib/Expr/ExprBuilder.cpp index bb6f28ec..aaddb3e3 100644 --- a/lib/Expr/ExprBuilder.cpp +++ b/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> |