From: Ted Kremenek Date: Thu, 24 Jan 2008 19:43:37 +0000 (+0000) Subject: Adjusted storage of values for Stmt* so that we need only query if X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5c1b996e25bce27f170e3723118c396ddd2d33cd;p=clang Adjusted storage of values for Stmt* so that we need only query if a Stmt* is a block-level expression when we INSERT a value into the map, and not also when we QUERY a value. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46321 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Analysis/GRConstants.cpp b/Analysis/GRConstants.cpp index 9db8e7f196..ad072d2e8c 100644 --- a/Analysis/GRConstants.cpp +++ b/Analysis/GRConstants.cpp @@ -49,14 +49,14 @@ namespace { class VISIBILITY_HIDDEN ValueKey { uintptr_t Raw; public: - enum Kind { IsSubExp=0x0, IsDecl=0x1, IsBlkExpr=0x2, Flags=0x3 }; + enum Kind { IsSubExp=0x0, IsBlkExpr=0x1, IsDecl=0x2, Flags=0x3 }; inline void* getPtr() const { return reinterpret_cast(Raw & ~Flags); } inline Kind getKind() const { return (Kind) (Raw & Flags); } ValueKey(const ValueDecl* VD) : Raw(reinterpret_cast(VD) | IsDecl) {} - ValueKey(Stmt* S, bool isBlkExpr) + ValueKey(Stmt* S, bool isBlkExpr = false) : Raw(reinterpret_cast(S) | (isBlkExpr ? IsBlkExpr : IsSubExp)){} bool isSubExpr() const { return getKind() == IsSubExp; } @@ -68,7 +68,7 @@ public: } inline bool operator==(const ValueKey& X) const { - return Raw == X.Raw; + return getPtr() == X.getPtr(); } inline bool operator!=(const ValueKey& X) const { @@ -77,9 +77,17 @@ public: inline bool operator<(const ValueKey& X) const { Kind k = getKind(), Xk = X.getKind(); + + if (k == IsDecl) { + if (Xk != IsDecl) + return false; + } + else { + if (Xk == IsDecl) + return true; + } - return k == Xk ? getPtr() < X.getPtr() - : ((unsigned) k) < ((unsigned) Xk); + return getPtr() < X.getPtr(); } }; } // end anonymous namespace @@ -709,7 +717,7 @@ ExprValue GRConstants::GetValue(const StateTy& St, Stmt* S) { break; } - StateTy::TreeTy* T = St.SlimFind(ValueKey(S, getCFG().isBlkExpr(S))); + StateTy::TreeTy* T = St.SlimFind(S); return T ? T->getValue().second : InvalidValue(); } @@ -764,20 +772,20 @@ GRConstants::StateTy GRConstants::RemoveDeadBindings(Stmt* Loc, StateTy M) { // iterators are iterating over the tree of the *original* map. StateTy::iterator I = M.begin(), E = M.end(); - // Remove old bindings for subexpressions. - for (; I!=E && I.getKey().getKind() == ValueKey::IsSubExp; ++I) - M = StateMgr.Remove(M, I.getKey()); + // Remove old bindings for subexpressions and "dead" block-level expressions. + for (; I!=E && !I.getKey().isDecl(); ++I) { + if (I.getKey().isSubExpr() || !Liveness->isLive(Loc,cast(I.getKey()))) + M = StateMgr.Remove(M, I.getKey()); + } // Remove bindings for "dead" decls. - for (; I!=E && I.getKey().getKind() == ValueKey::IsDecl; ++I) + for (; I!=E ; ++I) { + assert (I.getKey().isDecl()); + if (VarDecl* V = dyn_cast(cast(I.getKey()))) if (!Liveness->isLive(Loc, V)) M = StateMgr.Remove(M, I.getKey()); - - // Remove bindings for "dead" block-level expressions. - for (; I!=E; ++I) - if (!Liveness->isLive(Loc, cast(I.getKey()))) - M = StateMgr.Remove(M, I.getKey()); + } return M; }