From 4aea9d3d47e7e47630704fdf6628221fa45f6151 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Tue, 2 Jun 2009 17:01:00 +0000 Subject: Use ConstantExpr::alloc instead of ref directly - The "constant optimization" embedded inside ref is going away. - No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/klee/trunk@72730 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Expr/Constraints.cpp | 4 +-- lib/Expr/Expr.cpp | 44 ++++++++++++++++----------------- lib/Expr/ExprEvaluator.cpp | 2 +- lib/Expr/ExprPPrinter.cpp | 7 +++--- lib/Expr/Parser.cpp | 61 +++++++++++++++++++++++----------------------- 5 files changed, 60 insertions(+), 58 deletions(-) (limited to 'lib/Expr') diff --git a/lib/Expr/Constraints.cpp b/lib/Expr/Constraints.cpp index e9c376f4..4c18a3b3 100644 --- a/lib/Expr/Constraints.cpp +++ b/lib/Expr/Constraints.cpp @@ -100,11 +100,11 @@ ref ConstraintManager::simplifyExpr(ref e) const { ee->left)); } else { equalities.insert(std::make_pair(*it, - ref(1,Expr::Bool))); + ConstantExpr::alloc(1, Expr::Bool))); } } else { equalities.insert(std::make_pair(*it, - ref(1,Expr::Bool))); + ConstantExpr::alloc(1, Expr::Bool))); } } diff --git a/lib/Expr/Expr.cpp b/lib/Expr/Expr.cpp index 55b9a0a4..7f20e3fc 100644 --- a/lib/Expr/Expr.cpp +++ b/lib/Expr/Expr.cpp @@ -43,42 +43,42 @@ ref Expr::createTempRead(const Array *array, Expr::Width w) { switch (w) { case Expr::Bool: return ZExtExpr::create(ReadExpr::create(ul, - ref(0,kMachinePointerType)), + ConstantExpr::alloc(0,kMachinePointerType)), Expr::Bool); case Expr::Int8: return ReadExpr::create(ul, - ref(0,kMachinePointerType)); + ConstantExpr::alloc(0,kMachinePointerType)); case Expr::Int16: return ConcatExpr::create(ReadExpr::create(ul, - ref(1,kMachinePointerType)), + ConstantExpr::alloc(1,kMachinePointerType)), ReadExpr::create(ul, - ref(0,kMachinePointerType))); + ConstantExpr::alloc(0,kMachinePointerType))); case Expr::Int32: return ConcatExpr::create4(ReadExpr::create(ul, - ref(3,kMachinePointerType)), + ConstantExpr::alloc(3,kMachinePointerType)), ReadExpr::create(ul, - ref(2,kMachinePointerType)), + ConstantExpr::alloc(2,kMachinePointerType)), ReadExpr::create(ul, - ref(1,kMachinePointerType)), + ConstantExpr::alloc(1,kMachinePointerType)), ReadExpr::create(ul, - ref(0,kMachinePointerType))); + ConstantExpr::alloc(0,kMachinePointerType))); case Expr::Int64: return ConcatExpr::create8(ReadExpr::create(ul, - ref(7,kMachinePointerType)), + ConstantExpr::alloc(7,kMachinePointerType)), ReadExpr::create(ul, - ref(6,kMachinePointerType)), + ConstantExpr::alloc(6,kMachinePointerType)), ReadExpr::create(ul, - ref(5,kMachinePointerType)), + ConstantExpr::alloc(5,kMachinePointerType)), ReadExpr::create(ul, - ref(4,kMachinePointerType)), + ConstantExpr::alloc(4,kMachinePointerType)), ReadExpr::create(ul, - ref(3,kMachinePointerType)), + ConstantExpr::alloc(3,kMachinePointerType)), ReadExpr::create(ul, - ref(2,kMachinePointerType)), + ConstantExpr::alloc(2,kMachinePointerType)), ReadExpr::create(ul, - ref(1,kMachinePointerType)), + ConstantExpr::alloc(1,kMachinePointerType)), ReadExpr::create(ul, - ref(0,kMachinePointerType))); + ConstantExpr::alloc(0,kMachinePointerType))); default: assert(0 && "invalid width"); } } @@ -639,7 +639,7 @@ static ref SubExpr_create(Expr *l, Expr *r) { if (type == Expr::Bool) { return XorExpr_create(l, r); } else if (*l==*r) { - return ref(0, type); + return ConstantExpr::alloc(0, type); } else { Expr::Kind lk = l->getKind(), rk = r->getKind(); if (lk==Expr::Add && l->getKid(0).isConstant()) { // (k+a)-b = k+(a-b) @@ -891,7 +891,7 @@ ref _e_op ::create(const ref &l, const ref &r) { \ static ref EqExpr_create(const ref &l, const ref &r) { if (l == r) { - return ref(1, Expr::Bool); + return ConstantExpr::alloc(1, Expr::Bool); } else { return EqExpr::alloc(l, r); } @@ -952,7 +952,7 @@ static ref TryConstArrayOpt(const ref &cl, //llvm::cerr << "\n\n=== Applying const array optimization ===\n\n"; if (matches == 0) - return ref(0, Expr::Bool); + return ConstantExpr::alloc(0, Expr::Bool); ref res = EqExpr::create(first_idx_match, rd->index); if (matches == 1) @@ -1079,11 +1079,11 @@ static ref UltExpr_create(const ref &l, const ref &r) { if (r.isConstant()) { uint64_t value = r.getConstantValue(); if (value <= 8) { - ref res(0,Expr::Bool); + ref res = ConstantExpr::alloc(0, Expr::Bool); for (unsigned i=0; i(i,t)), res); + res = OrExpr::create(EqExpr::create(l, + ConstantExpr::alloc(i, t)), res); } - // llvm::cerr << l << "<" << r << " <=> " << res << "\n"; return res; } } diff --git a/lib/Expr/ExprEvaluator.cpp b/lib/Expr/ExprEvaluator.cpp index 102387e1..cf901f0e 100644 --- a/lib/Expr/ExprEvaluator.cpp +++ b/lib/Expr/ExprEvaluator.cpp @@ -26,7 +26,7 @@ ExprVisitor::Action ExprEvaluator::evalRead(const UpdateList &ul, UpdateList fwd(ul.root, un, 0); return Action::changeTo(ReadExpr::create(fwd, - ref(index,Expr::Int32))); + ConstantExpr::alloc(index, Expr::Int32))); } } diff --git a/lib/Expr/ExprPPrinter.cpp b/lib/Expr/ExprPPrinter.cpp index dc7f4f64..fd367f23 100644 --- a/lib/Expr/ExprPPrinter.cpp +++ b/lib/Expr/ExprPPrinter.cpp @@ -240,7 +240,8 @@ class PPrinter : public ExprPPrinter { // Get stride expr in proper index width. Expr::Width idxWidth = base->index.getWidth(); - ref strideExpr(stride, idxWidth), offset(0, idxWidth); + ref strideExpr = ConstantExpr::alloc(stride, idxWidth); + ref offset = ConstantExpr::alloc(0, idxWidth); for (unsigned i=1; igetNumKids(); ++i) { const ReadExpr *re = dyn_ref_cast(ep->getKid(i)); if (!re) @@ -357,7 +358,7 @@ public: // Detect Not. // FIXME: This should be in common code. if (const EqExpr *ee = dyn_ref_cast(e)) { - if (ee->left == ref(false, Expr::Bool)) { + if (ee->left == ConstantExpr::alloc(false, Expr::Bool)) { PC << "(Not"; printWidth(PC, e); PC << ' '; @@ -443,7 +444,7 @@ void ExprPPrinter::printOne(std::ostream &os, void ExprPPrinter::printConstraints(std::ostream &os, const ConstraintManager &constraints) { - printQuery(os, constraints, ref(false, Expr::Bool)); + printQuery(os, constraints, ConstantExpr::alloc(false, Expr::Bool)); } void ExprPPrinter::printQuery(std::ostream &os, diff --git a/lib/Expr/Parser.cpp b/lib/Expr/Parser.cpp index dba089a5..a8ea0a6b 100644 --- a/lib/Expr/Parser.cpp +++ b/lib/Expr/Parser.cpp @@ -398,7 +398,7 @@ DeclResult ParserImpl::ParseQueryCommand() { if (Tok.kind == Token::EndOfFile) { Error("unexpected end of file."); return new QueryCommand(Constraints.begin(), Constraints.end(), - ref(false, Expr::Bool)); + ConstantExpr::alloc(false, Expr::Bool)); } ExprResult Res = ParseExpr(TypeResult(Expr::Bool)); @@ -410,7 +410,7 @@ DeclResult ParserImpl::ParseQueryCommand() { ExprResult Res = ParseExpr(TypeResult()); if (!Res.isValid()) // Error emitted by ParseExpr. - Res = ExprResult(ref(0, Expr::Bool)); + Res = ExprResult(ConstantExpr::alloc(0, Expr::Bool)); ExpectRParen("unexpected argument to 'query'."); return new QueryCommand(Constraints.begin(), Constraints.end(), @@ -447,7 +447,7 @@ ExprResult ParserImpl::ParseExpr(TypeResult ExpectedType) { if (Tok.kind == Token::KWFalse || Tok.kind == Token::KWTrue) { bool Value = Tok.kind == Token::KWTrue; ConsumeToken(); - return ExprResult(ref(Value, Expr::Bool)); + return ExprResult(ConstantExpr::alloc(Value, Expr::Bool)); } if (Tok.kind == Token::Number) { @@ -491,9 +491,10 @@ ExprResult ParserImpl::ParseExpr(TypeResult ExpectedType) { // use-of-undef errors. // FIXME: Maybe we should let the symbol table map to invalid // entries? - if (Label && ExpectedType.isValid()) - ExprSymTab.insert(std::make_pair(Label, - ref(0, ExpectedType.get()))); + if (Label && ExpectedType.isValid()) { + ref Value = ConstantExpr::alloc(0, ExpectedType.get()); + ExprSymTab.insert(std::make_pair(Label, Value)); + } return Res; } else if (ExpectedType.isValid()) { // Type check result. @@ -716,7 +717,7 @@ ExprResult ParserImpl::ParseParenExpr(TypeResult FIXME_UNUSED) { default: Error("internal error, unimplemented special form.", Name); SkipUntilRParen(); - return ExprResult(ref(0, ResTy)); + return ExprResult(ConstantExpr::alloc(0, ResTy)); } } @@ -740,20 +741,20 @@ ExprResult ParserImpl::ParseUnaryParenExpr(const Token &Name, if (Tok.kind == Token::RParen) { Error("unexpected end of arguments.", Name); ConsumeRParen(); - return ref(0, ResTy); + return ConstantExpr::alloc(0, ResTy); } ExprResult Arg = ParseExpr(IsFixed ? ResTy : TypeResult()); if (!Arg.isValid()) - Arg = ref(0, ResTy); + Arg = ConstantExpr::alloc(0, ResTy); ExpectRParen("unexpected argument in unary expression."); ExprHandle E = Arg.get(); switch (Kind) { case eMacroKind_Not: - return EqExpr::alloc(ref(0, E.getWidth()), E); + return EqExpr::alloc(ConstantExpr::alloc(0, E.getWidth()), E); case eMacroKind_Neg: - return SubExpr::alloc(ref(0, E.getWidth()), E); + return SubExpr::alloc(ConstantExpr::alloc(0, E.getWidth()), E); case Expr::SExt: // FIXME: Type check arguments. return SExtExpr::alloc(E, ResTy); @@ -762,7 +763,7 @@ ExprResult ParserImpl::ParseUnaryParenExpr(const Token &Name, return ZExtExpr::alloc(E, ResTy); default: Error("internal error, unhandled kind.", Name); - return ref(0, ResTy); + return ConstantExpr::alloc(0, ResTy); } } @@ -831,7 +832,7 @@ ExprResult ParserImpl::ParseBinaryParenExpr(const Token &Name, ParseMatchedBinaryArgs(Name, IsFixed ? TypeResult(ResTy) : TypeResult(), LHS, RHS); if (!LHS.isValid() || !RHS.isValid()) - return ref(0, ResTy); + return ConstantExpr::alloc(0, ResTy); ref LHS_E = LHS.get(), RHS_E = RHS.get(); assert(LHS_E.getWidth() == RHS_E.getWidth() && "Mismatched types!"); @@ -865,7 +866,7 @@ ExprResult ParserImpl::ParseBinaryParenExpr(const Token &Name, case Expr::Sge: return SgeExpr::alloc(LHS_E, RHS_E); default: Error("FIXME: unhandled kind.", Name); - return ref(0, ResTy); + return ConstantExpr::alloc(0, ResTy); } } @@ -875,14 +876,14 @@ ExprResult ParserImpl::ParseSelectParenExpr(const Token &Name, if (Tok.kind == Token::RParen) { Error("unexpected end of arguments.", Name); ConsumeRParen(); - return ref(0, ResTy); + return ConstantExpr::alloc(0, ResTy); } ExprResult Cond = ParseExpr(Expr::Bool); ExprResult LHS, RHS; ParseMatchedBinaryArgs(Name, ResTy, LHS, RHS); if (!Cond.isValid() || !LHS.isValid() || !RHS.isValid()) - return ref(0, ResTy); + return ConstantExpr::alloc(0, ResTy); return SelectExpr::alloc(Cond.get(), LHS.get(), RHS.get()); } @@ -900,7 +901,7 @@ ExprResult ParserImpl::ParseConcatParenExpr(const Token &Name, // Skip to end of expr on error. if (!E.isValid()) { SkipUntilRParen(); - return ref(0, ResTy); + return ConstantExpr::alloc(0, ResTy); } Kids.push_back(E.get()); @@ -911,7 +912,7 @@ ExprResult ParserImpl::ParseConcatParenExpr(const Token &Name, if (Width != ResTy) { Error("concat does not match expected result size."); - return ref(0, ResTy); + return ConstantExpr::alloc(0, ResTy); } return ConcatExpr::createN(Kids.size(), &Kids[0]); @@ -926,14 +927,14 @@ ExprResult ParserImpl::ParseExtractParenExpr(const Token &Name, ExpectRParen("unexpected argument to expression."); if (!OffsetExpr.isValid() || !Child.isValid()) - return ref(0, ResTy); + return ConstantExpr::alloc(0, ResTy); assert(OffsetExpr.get().isConstant() && "ParseNumber returned non-constant."); unsigned Offset = (unsigned) OffsetExpr.get().getConstantValue(); if (Offset + ResTy > Child.get().getWidth()) { Error("extract out-of-range of child expression.", Name); - return ref(0, ResTy); + return ConstantExpr::alloc(0, ResTy); } return ExtractExpr::alloc(Child.get(), Offset, ResTy); @@ -947,7 +948,7 @@ ExprResult ParserImpl::ParseAnyReadParenExpr(const Token &Name, ExpectRParen("unexpected argument in read expression."); if (!Array.isValid()) - return ref(0, ResTy); + return ConstantExpr::alloc(0, ResTy); // FIXME: Need generic way to get array width. Needs to work with // anonymous arrays. @@ -962,10 +963,10 @@ ExprResult ParserImpl::ParseAnyReadParenExpr(const Token &Name, IndexExpr = Index.getExpr(); if (!IndexExpr.isValid()) - return ref(0, ResTy); + return ConstantExpr::alloc(0, ResTy); else if (IndexExpr.get().getWidth() != ArrayDomainType) { Error("index width does not match array domain."); - return ref(0, ResTy); + return ConstantExpr::alloc(0, ResTy); } // FIXME: Check range width. @@ -973,13 +974,13 @@ ExprResult ParserImpl::ParseAnyReadParenExpr(const Token &Name, switch (Kind) { default: assert(0 && "Invalid kind."); - return ref(0, ResTy); + return ConstantExpr::alloc(0, ResTy); case eMacroKind_ReadLSB: case eMacroKind_ReadMSB: { unsigned NumReads = ResTy / ArrayRangeType; if (ResTy != NumReads*ArrayRangeType) { Error("invalid ordered read (not multiple of range type).", Name); - return ref(0, ResTy); + return ConstantExpr::alloc(0, ResTy); } std::vector Kids; Kids.reserve(NumReads); @@ -987,7 +988,7 @@ ExprResult ParserImpl::ParseAnyReadParenExpr(const Token &Name, for (unsigned i=0; i(i, ArrayDomainType)); + ConstantExpr::alloc(i, ArrayDomainType)); Kids.push_back(ReadExpr::alloc(Array.get(), OffsetIndex)); } if (Kind == eMacroKind_ReadLSB) @@ -1185,7 +1186,7 @@ ExprResult ParserImpl::ParseNumberToken(Expr::Width Type, const Token &Tok) { // Diagnose 0[box] with no trailing digits. if (!N) { Error("invalid numeric token (no digits).", Tok); - return ref(0, Type); + return ConstantExpr::alloc(0, Type); } } @@ -1207,12 +1208,12 @@ ExprResult ParserImpl::ParseNumberToken(Expr::Width Type, const Token &Tok) { Digit = Char - 'A' + 10; else { Error("invalid character in numeric token.", Tok); - return ref(0, Type); + return ConstantExpr::alloc(0, Type); } if (Digit >= Radix) { Error("invalid character in numeric token (out of range).", Tok); - return ref(0, Type); + return ConstantExpr::alloc(0, Type); } DigitVal = Digit; @@ -1223,7 +1224,7 @@ ExprResult ParserImpl::ParseNumberToken(Expr::Width Type, const Token &Tok) { if (HasMinus) Val = -Val; - return ExprResult(ref(Val.trunc(Type).getZExtValue(), Type)); + return ExprResult(ConstantExpr::alloc(Val.trunc(Type).getZExtValue(), Type)); } /// ParseTypeSpecifier - Parse a type specifier. -- cgit 1.4.1