[cfe-commits] r42498 - in /cfe/trunk: AST/CFG.cpp Analysis/DeadStores.cpp Analysis/LiveVariables.cpp Analysis/UninitializedValues.cpp Driver/ASTStreamers.cpp include/clang/Analysis/ExprDeclBitVector.h include/clang/Analysis/LiveVariables.h include/clang/Analysis/UninitializedValues.h
Ted Kremenek
kremenek at apple.com
Mon Oct 1 13:33:52 PDT 2007
Author: kremenek
Date: Mon Oct 1 15:33:52 2007
New Revision: 42498
URL: http://llvm.org/viewvc/llvm-project?rev=42498&view=rev
Log:
Migrated LiveVariables and UninitializedVariables to now use the
tracked BlkExpr information now maintained by the CFG class.
Modified:
cfe/trunk/AST/CFG.cpp
cfe/trunk/Analysis/DeadStores.cpp
cfe/trunk/Analysis/LiveVariables.cpp
cfe/trunk/Analysis/UninitializedValues.cpp
cfe/trunk/Driver/ASTStreamers.cpp
cfe/trunk/include/clang/Analysis/ExprDeclBitVector.h
cfe/trunk/include/clang/Analysis/LiveVariables.h
cfe/trunk/include/clang/Analysis/UninitializedValues.h
Modified: cfe/trunk/AST/CFG.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/CFG.cpp?rev=42498&r1=42497&r2=42498&view=diff
==============================================================================
--- cfe/trunk/AST/CFG.cpp (original)
+++ cfe/trunk/AST/CFG.cpp Mon Oct 1 15:33:52 2007
@@ -949,11 +949,13 @@
}
bool CFG::isBlkExpr(const Stmt* S) {
+ assert (S != NULL);
if (const Expr* E = dyn_cast<Expr>(S)) return getBlkExprNum(E);
else return true; // Statements are by default "block-level expressions."
}
CFG::BlkExprNumTy CFG::getBlkExprNum(const Expr* E) {
+ assert(E != NULL);
if (!BlkExprMap) { BlkExprMap = (void*) PopulateBlkExprMap(*this); }
BlkExprMapTy* M = reinterpret_cast<BlkExprMapTy*>(BlkExprMap);
Modified: cfe/trunk/Analysis/DeadStores.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Analysis/DeadStores.cpp?rev=42498&r1=42497&r2=42498&view=diff
==============================================================================
--- cfe/trunk/Analysis/DeadStores.cpp (original)
+++ cfe/trunk/Analysis/DeadStores.cpp Mon Oct 1 15:33:52 2007
@@ -76,7 +76,7 @@
namespace clang {
void CheckDeadStores(CFG& cfg, ASTContext &Ctx, Diagnostic &Diags) {
- LiveVariables L;
+ LiveVariables L(cfg);
L.runOnCFG(cfg);
DeadStoreObs A(Ctx, Diags);
L.runOnAllBlocks(cfg,A);
Modified: cfe/trunk/Analysis/LiveVariables.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Analysis/LiveVariables.cpp?rev=42498&r1=42497&r2=42498&view=diff
==============================================================================
--- cfe/trunk/Analysis/LiveVariables.cpp (original)
+++ cfe/trunk/Analysis/LiveVariables.cpp Mon Oct 1 15:33:52 2007
@@ -31,18 +31,16 @@
//===----------------------------------------------------------------------===//
namespace {
-class RegisterDeclsExprs : public CFGRecStmtDeclVisitor<RegisterDeclsExprs> {
+class RegisterDecls : public CFGRecStmtDeclVisitor<RegisterDecls> {
LiveVariables::AnalysisDataTy& AD;
public:
- RegisterDeclsExprs(LiveVariables::AnalysisDataTy& ad) : AD(ad) {}
-
+ RegisterDecls(LiveVariables::AnalysisDataTy& ad) : AD(ad) {}
void VisitVarDecl(VarDecl* VD) { AD.Register(VD); }
- void BlockStmt_VisitExpr(Expr* E) { AD.Register(E); }
-};
+};
} // end anonymous namespace
void LiveVariables::InitializeValues(const CFG& cfg) {
- RegisterDeclsExprs R(getAnalysisData());
+ RegisterDecls R(getAnalysisData());
cfg.VisitBlockStmts(R);
}
@@ -58,10 +56,8 @@
class TransferFuncs : public CFGStmtVisitor<TransferFuncs> {
LiveVariables::AnalysisDataTy& AD;
LiveVariables::ValTy LiveState;
- bool ExprLiveness;
public:
- TransferFuncs(LiveVariables::AnalysisDataTy& ad) : AD(ad),
- ExprLiveness(Dead) {}
+ TransferFuncs(LiveVariables::AnalysisDataTy& ad) : AD(ad) {}
LiveVariables::ValTy& getVal() { return LiveState; }
@@ -71,16 +67,26 @@
void VisitDeclStmt(DeclStmt* DS);
void VisitUnaryOperator(UnaryOperator* U);
void VisitStmt(Stmt* S);
- void BlockStmt_VisitExpr(Expr *E);
+ void VisitExpr(Expr* E);
+ void BlockStmt_VisitExpr(Expr *E);
+ void Visit(Stmt *S);
DeclRefExpr* FindDeclRef(Stmt *S);
-
- void Visit(Stmt *S) {
- if (AD.Observer) AD.Observer->ObserveStmt(S,AD,LiveState);
- static_cast<CFGStmtVisitor<TransferFuncs>*>(this)->Visit(S);
- }
};
+
+void TransferFuncs::VisitExpr(Expr * E) {
+ if (AD.getCFG().isBlkExpr(E)) return;
+ else VisitStmt(E);
+}
+
+void TransferFuncs::VisitStmt(Stmt* S) { VisitChildren(S); }
+
+void TransferFuncs::Visit(Stmt *S) {
+ if (AD.Observer)
+ AD.Observer->ObserveStmt(S,AD,LiveState);
+ static_cast<CFGStmtVisitor<TransferFuncs>*>(this)->Visit(S);
+}
void TransferFuncs::VisitDeclRefExpr(DeclRefExpr* DR) {
if (VarDecl* V = dyn_cast<VarDecl>(DR->getDecl()))
@@ -151,17 +157,12 @@
void TransferFuncs::VisitDeclStmt(DeclStmt* DS) {
// Declarations effectively "kill" a variable since they cannot
// possibly be live before they are declared.
- for (ScopedDecl* D = DS->getDecl(); D != NULL ; D = D->getNextDeclarator())
+ for (ScopedDecl* D = DS->getDecl(); D != NULL; D = D->getNextDeclarator())
LiveState(D,AD) = Dead;
}
-void TransferFuncs::VisitStmt(Stmt* S) {
- if (AD.isTracked(static_cast<Expr*>(S))) return;
- else VisitChildren(S);
-}
-
void TransferFuncs::BlockStmt_VisitExpr(Expr* E) {
- assert (AD.isTracked(E));
+ assert (AD.getCFG().isBlkExpr(E));
static_cast<CFGStmtVisitor<TransferFuncs>*>(this)->Visit(E);
}
Modified: cfe/trunk/Analysis/UninitializedValues.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Analysis/UninitializedValues.cpp?rev=42498&r1=42497&r2=42498&view=diff
==============================================================================
--- cfe/trunk/Analysis/UninitializedValues.cpp (original)
+++ cfe/trunk/Analysis/UninitializedValues.cpp Mon Oct 1 15:33:52 2007
@@ -28,19 +28,18 @@
namespace {
-class RegisterDeclsExprs : public CFGRecStmtDeclVisitor<RegisterDeclsExprs> {
+class RegisterDecls : public CFGRecStmtDeclVisitor<RegisterDecls> {
UninitializedValues::AnalysisDataTy& AD;
public:
- RegisterDeclsExprs(UninitializedValues::AnalysisDataTy& ad) : AD(ad) {}
+ RegisterDecls(UninitializedValues::AnalysisDataTy& ad) : AD(ad) {}
void VisitBlockVarDecl(BlockVarDecl* VD) { AD.Register(VD); }
- void BlockStmt_VisitExpr(Expr* E) { AD.Register(E); }
};
} // end anonymous namespace
void UninitializedValues::InitializeValues(const CFG& cfg) {
- RegisterDeclsExprs R(this->getAnalysisData());
+ RegisterDecls R(getAnalysisData());
cfg.VisitBlockStmts(R);
}
@@ -77,7 +76,6 @@
static const bool Initialized = true;
static const bool Uninitialized = false;
-
bool TransferFuncs::VisitDeclRefExpr(DeclRefExpr* DR) {
if (BlockVarDecl* VD = dyn_cast<BlockVarDecl>(DR->getDecl())) {
if (AD.Observer) AD.Observer->ObserveDeclRefExpr(V,AD,DR,VD);
@@ -230,7 +228,7 @@
bool FullUninitTaint) {
// Compute the unitialized values information.
- UninitializedValues U;
+ UninitializedValues U(cfg);
U.getAnalysisData().FullUninitTaint = FullUninitTaint;
Solver S(U);
S.runOnCFG(cfg);
Modified: cfe/trunk/Driver/ASTStreamers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/ASTStreamers.cpp?rev=42498&r1=42497&r2=42498&view=diff
==============================================================================
--- cfe/trunk/Driver/ASTStreamers.cpp (original)
+++ cfe/trunk/Driver/ASTStreamers.cpp Mon Oct 1 15:33:52 2007
@@ -222,7 +222,7 @@
}
virtual void VisitCFG(CFG& C) {
- LiveVariables L;
+ LiveVariables L(C);
L.runOnCFG(C);
L.dumpBlockLiveness(*SM);
}
Modified: cfe/trunk/include/clang/Analysis/ExprDeclBitVector.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/ExprDeclBitVector.h?rev=42498&r1=42497&r2=42498&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/ExprDeclBitVector.h (original)
+++ cfe/trunk/include/clang/Analysis/ExprDeclBitVector.h Mon Oct 1 15:33:52 2007
@@ -17,6 +17,7 @@
#ifndef LLVM_CLANG_EXPRDECLBVDVAL_H
#define LLVM_CLANG_EXPRDECLBVDVAL_H
+#include "clang/AST/CFG.h"
#include "llvm/ADT/BitVector.h"
#include "llvm/ADT/DenseMap.h"
@@ -130,36 +131,25 @@
//===--------------------------------------------------------------------===//
class AnalysisDataTy : public DeclBitVector_Types::AnalysisDataTy {
+ CFG* cfg;
public:
- typedef llvm::DenseMap<const Expr*, unsigned > EMapTy;
- typedef EMapTy::const_iterator expr_iterator;
-
- protected:
- EMapTy EMap;
- unsigned NExprs;
-
- public:
-
- AnalysisDataTy() : NExprs(0) {}
+ AnalysisDataTy() {}
virtual ~AnalysisDataTy() {}
+
+ void setCFG(CFG* c) { cfg = c; }
+ CFG& getCFG() { assert(cfg && "CFG should not be NULL."); return *cfg; }
- bool isTracked(const Expr* E) { return EMap.find(E) != EMap.end(); }
+ bool isTracked(const Expr* E) { return cfg->isBlkExpr(E); }
using DeclBitVector_Types::AnalysisDataTy::isTracked;
unsigned getIdx(const Expr* E) const {
- EMapTy::const_iterator I = EMap.find(E);
- assert (I != EMap.end());
- return I->second;
- }
+ CFG::BlkExprNumTy I = cfg->getBlkExprNum(E);
+ assert(I && "expression not tracked for bitvector.");
+ return I;
+ }
using DeclBitVector_Types::AnalysisDataTy::getIdx;
- unsigned getNumExprs() const { return NExprs; }
-
- void Register(const Expr* E) { if (!isTracked(E)) EMap[E] = NExprs++; }
- using DeclBitVector_Types::AnalysisDataTy::Register;
-
- expr_iterator begin_expr() const { return EMap.begin(); }
- expr_iterator end_expr() const { return EMap.end(); }
+ unsigned getNumExprs() const { return cfg->getNumBlkExprs(); }
};
//===--------------------------------------------------------------------===//
Modified: cfe/trunk/include/clang/Analysis/LiveVariables.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/LiveVariables.h?rev=42498&r1=42497&r2=42498&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/LiveVariables.h (original)
+++ cfe/trunk/include/clang/Analysis/LiveVariables.h Mon Oct 1 15:33:52 2007
@@ -65,7 +65,7 @@
public:
typedef LiveVariables_ValueTypes::ObserverTy ObserverTy;
- LiveVariables() {}
+ LiveVariables(CFG& cfg) { getAnalysisData().setCFG(&cfg); }
/// IsLive - Return true if a variable is live at beginning of a
/// specified block.
Modified: cfe/trunk/include/clang/Analysis/UninitializedValues.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/UninitializedValues.h?rev=42498&r1=42497&r2=42498&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/UninitializedValues.h (original)
+++ cfe/trunk/include/clang/Analysis/UninitializedValues.h Mon Oct 1 15:33:52 2007
@@ -63,7 +63,7 @@
public:
typedef UninitializedValues_ValueTypes::ObserverTy ObserverTy;
- UninitializedValues() {}
+ UninitializedValues(CFG &cfg) { getAnalysisData().setCFG(&cfg); }
/// IntializeValues - Create initial dataflow values and meta data for
/// a given CFG. This is intended to be called by the dataflow solver.
More information about the cfe-commits
mailing list