Modified LiveVariables to perform all of its base initialization in the ctor,
and now we require a FunctionDecl* object so that we can also keep track of
all of the ParmDecls.
Modified clients of LiveVariables to conform to the new interface.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46490 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Analysis/DeadStores.cpp b/Analysis/DeadStores.cpp
index 926109e..4475d49 100644
--- a/Analysis/DeadStores.cpp
+++ b/Analysis/DeadStores.cpp
@@ -76,8 +76,10 @@
namespace clang {
-void CheckDeadStores(CFG& cfg, ASTContext &Ctx, Diagnostic &Diags) {
- LiveVariables L(cfg);
+void CheckDeadStores(CFG& cfg, FunctionDecl& FD, ASTContext &Ctx,
+ Diagnostic &Diags) {
+
+ LiveVariables L(cfg, FD);
L.runOnCFG(cfg);
DeadStoreObs A(Ctx, Diags);
L.runOnAllBlocks(cfg,&A);
diff --git a/Analysis/GRConstants.cpp b/Analysis/GRConstants.cpp
index a0a58db..103e6a0 100644
--- a/Analysis/GRConstants.cpp
+++ b/Analysis/GRConstants.cpp
@@ -577,7 +577,7 @@
/// Liveness - live-variables information the ValueDecl* and block-level
/// Expr* in the CFG. Used to prune out dead state.
- LiveVariables* Liveness;
+ LiveVariables Liveness;
/// Builder - The current GRNodeBuilder which is used when building the nodes
/// for a given statement.
@@ -600,17 +600,14 @@
ASTContext& getContext() const { return G.getContext(); }
public:
- GRConstants(GraphTy& g) : G(g), Liveness(NULL), Builder(NULL),
- ValMgr(G.getContext()), StmtEntryNode(NULL), CurrentStmt(NULL) {
+ GRConstants(GraphTy& g) : G(g), Liveness(G.getCFG(), G.getFunctionDecl()),
+ Builder(NULL), ValMgr(G.getContext()), StmtEntryNode(NULL),
+ CurrentStmt(NULL) {
// Compute liveness information.
- CFG& c = G.getCFG();
- Liveness = new LiveVariables(c);
- Liveness->runOnCFG(c);
- Liveness->runOnAllBlocks(c, NULL, true);
+ Liveness.runOnCFG(G.getCFG());
+ Liveness.runOnAllBlocks(G.getCFG(), NULL, true);
}
-
- ~GRConstants() { delete Liveness; }
/// getCFG - Returns the CFG associated with this analysis.
CFG& getCFG() { return G.getCFG(); }
@@ -843,14 +840,14 @@
// 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<Stmt>(I.getKey())))
+ if (I.getKey().isSubExpr() || !Liveness.isLive(Loc,cast<Stmt>(I.getKey())))
M = StateMgr.Remove(M, I.getKey());
}
// Remove bindings for "dead" decls.
for (; I!=E && I.getKey().isDecl(); ++I)
if (VarDecl* V = dyn_cast<VarDecl>(cast<ValueDecl>(I.getKey())))
- if (!Liveness->isLive(Loc, V))
+ if (!Liveness.isLive(Loc, V))
M = StateMgr.Remove(M, I.getKey());
return M;
diff --git a/Analysis/LiveVariables.cpp b/Analysis/LiveVariables.cpp
index b96f7fc..c14b463 100644
--- a/Analysis/LiveVariables.cpp
+++ b/Analysis/LiveVariables.cpp
@@ -42,7 +42,15 @@
};
} // end anonymous namespace
-void LiveVariables::InitializeValues(const CFG& cfg) {
+
+LiveVariables::LiveVariables(CFG& cfg, FunctionDecl& FD) {
+ getAnalysisData().setCFG(&cfg);
+
+ for (FunctionDecl::param_iterator I=FD.param_begin(), E=FD.param_end();
+ I !=E; ++I)
+ getAnalysisData().Register(*I);
+
+ // Now register all the other VarDecls;
RegisterDecls R(getAnalysisData());
cfg.VisitBlockStmts(R);
}