[cfe-commits] r46490 - in /cfe/trunk: Analysis/DeadStores.cpp Analysis/GRConstants.cpp Analysis/LiveVariables.cpp Driver/ASTConsumers.cpp include/clang/Analysis/Analyses/LiveVariables.h include/clang/Analysis/LocalCheckers.h

Ted Kremenek kremenek at apple.com
Mon Jan 28 21:13:24 PST 2008


Author: kremenek
Date: Mon Jan 28 23:13:23 2008
New Revision: 46490

URL: http://llvm.org/viewvc/llvm-project?rev=46490&view=rev
Log:
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.

Modified:
    cfe/trunk/Analysis/DeadStores.cpp
    cfe/trunk/Analysis/GRConstants.cpp
    cfe/trunk/Analysis/LiveVariables.cpp
    cfe/trunk/Driver/ASTConsumers.cpp
    cfe/trunk/include/clang/Analysis/Analyses/LiveVariables.h
    cfe/trunk/include/clang/Analysis/LocalCheckers.h

Modified: cfe/trunk/Analysis/DeadStores.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Analysis/DeadStores.cpp?rev=46490&r1=46489&r2=46490&view=diff

==============================================================================
--- cfe/trunk/Analysis/DeadStores.cpp (original)
+++ cfe/trunk/Analysis/DeadStores.cpp Mon Jan 28 23:13:23 2008
@@ -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);

Modified: cfe/trunk/Analysis/GRConstants.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Analysis/GRConstants.cpp?rev=46490&r1=46489&r2=46490&view=diff

==============================================================================
--- cfe/trunk/Analysis/GRConstants.cpp (original)
+++ cfe/trunk/Analysis/GRConstants.cpp Mon Jan 28 23:13:23 2008
@@ -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;

Modified: cfe/trunk/Analysis/LiveVariables.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Analysis/LiveVariables.cpp?rev=46490&r1=46489&r2=46490&view=diff

==============================================================================
--- cfe/trunk/Analysis/LiveVariables.cpp (original)
+++ cfe/trunk/Analysis/LiveVariables.cpp Mon Jan 28 23:13:23 2008
@@ -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);
 }

Modified: cfe/trunk/Driver/ASTConsumers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/ASTConsumers.cpp?rev=46490&r1=46489&r2=46490&view=diff

==============================================================================
--- cfe/trunk/Driver/ASTConsumers.cpp (original)
+++ cfe/trunk/Driver/ASTConsumers.cpp Mon Jan 28 23:13:23 2008
@@ -449,7 +449,7 @@
 class CFGVisitor : public ASTConsumer {
 public:
   // CFG Visitor interface to be implemented by subclass.
-  virtual void VisitCFG(CFG& C) = 0;
+  virtual void VisitCFG(CFG& C, FunctionDecl& FD) = 0;
   virtual bool printFuncDeclStart() { return true; }
   
   virtual void HandleTopLevelDecl(Decl *D);
@@ -468,7 +468,7 @@
   }
     
   CFG *C = CFG::buildCFG(FD->getBody());
-  VisitCFG(*C);
+  VisitCFG(*C, *FD);
   delete C;
 }
 
@@ -481,7 +481,7 @@
   public:
     CFGDumper(bool use_graphviz) : UseGraphviz(use_graphviz) {}
     
-    virtual void VisitCFG(CFG &C) {
+    virtual void VisitCFG(CFG& C, FunctionDecl&) {
       if (UseGraphviz)
         C.viewCFG();
       else
@@ -505,8 +505,8 @@
       SM = &Context.getSourceManager();
     }
 
-    virtual void VisitCFG(CFG& C) {
-      LiveVariables L(C);
+    virtual void VisitCFG(CFG& C, FunctionDecl& FD) {
+      LiveVariables L(C, FD);
       L.runOnCFG(C);
       L.dumpBlockLiveness(*SM);
     }
@@ -530,7 +530,10 @@
       Ctx = &Context;
     }
     
-    virtual void VisitCFG(CFG& C) { CheckDeadStores(C, *Ctx, Diags); }
+    virtual void VisitCFG(CFG& C, FunctionDecl& FD) {
+      CheckDeadStores(C, FD, *Ctx, Diags);
+    }
+    
     virtual bool printFuncDeclStart() { return false; }
   }; 
 } // end anonymous namespace
@@ -553,7 +556,10 @@
       Ctx = &Context;
     }
     
-    virtual void VisitCFG(CFG& C) { CheckUninitializedValues(C, *Ctx, Diags); }
+    virtual void VisitCFG(CFG& C, FunctionDecl&) { 
+      CheckUninitializedValues(C, *Ctx, Diags);
+    }
+    
     virtual bool printFuncDeclStart() { return false; }
   }; 
 } // end anonymous namespace
@@ -566,12 +572,12 @@
 // GRConstants - Perform intra-procedural, path-sensitive constant propagation.
 
 namespace {
-  class GRConstantsVisitor : public ASTConsumer {
+  class GRConstantsVisitor : public CFGVisitor {
     ASTContext* Ctx;
   public:
     
     virtual void Initialize(ASTContext &Context) { Ctx = &Context; }    
-    virtual void HandleTopLevelDecl(Decl *D);
+    virtual void VisitCFG(CFG& C, FunctionDecl&);
   };
 } // end anonymous namespace
 
@@ -579,18 +585,8 @@
   return new GRConstantsVisitor();
 }
 
-void GRConstantsVisitor::HandleTopLevelDecl(Decl *D) {
-  FunctionDecl *FD = dyn_cast<FunctionDecl>(D);
-
-  if (!FD || !FD->getBody())
-    return;
-
-  DeclPrinter().PrintFunctionDeclStart(FD);
-  llvm::cerr << '\n';
-  
-  CFG *C = CFG::buildCFG(FD->getBody());
-  RunGRConstants(*C, *FD, *Ctx);
-  delete C;
+void GRConstantsVisitor::VisitCFG(CFG& C, FunctionDecl& FD) {
+  RunGRConstants(C, FD, *Ctx);
 }
 
 //===----------------------------------------------------------------------===//

Modified: cfe/trunk/include/clang/Analysis/Analyses/LiveVariables.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/Analyses/LiveVariables.h?rev=46490&r1=46489&r2=46490&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/Analyses/LiveVariables.h (original)
+++ cfe/trunk/include/clang/Analysis/Analyses/LiveVariables.h Mon Jan 28 23:13:23 2008
@@ -64,7 +64,7 @@
 public:
   typedef LiveVariables_ValueTypes::ObserverTy ObserverTy;
     
-  LiveVariables(CFG& cfg) { getAnalysisData().setCFG(&cfg); }
+  LiveVariables(CFG& cfg, FunctionDecl& FD);
   
   /// IsLive - Return true if a variable is live at beginning of a
   /// specified block.
@@ -97,9 +97,10 @@
   ///  analysis.
   unsigned getNumDecls() const { return getAnalysisData().getNumDecls(); }
     
-  /// IntializeValues - Create initial dataflow values and meta data for
-  ///  a given CFG.  This is intended to be called by the dataflow solver.
-  void InitializeValues(const CFG& cfg);
+  /// IntializeValues - This routine can perform extra initialization, but
+  ///  for LiveVariables this does nothing since all that logic is in
+  ///  the constructor.                                              
+  void InitializeValues(const CFG& cfg) {}
   
   void runOnCFG(CFG& cfg);
                                               

Modified: cfe/trunk/include/clang/Analysis/LocalCheckers.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/LocalCheckers.h?rev=46490&r1=46489&r2=46490&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/LocalCheckers.h (original)
+++ cfe/trunk/include/clang/Analysis/LocalCheckers.h Mon Jan 28 23:13:23 2008
@@ -18,10 +18,13 @@
 namespace clang {
 
 class CFG;
+class FunctionDecl;
 class Diagnostic;
 class ASTContext;
 
-void CheckDeadStores(CFG& cfg, ASTContext &Ctx, Diagnostic &Diags);  
+void CheckDeadStores(CFG& cfg, FunctionDecl& FD, ASTContext &Ctx,
+                     Diagnostic &Diags); 
+  
 void CheckUninitializedValues(CFG& cfg, ASTContext& Ctx, Diagnostic& Diags,
                               bool FullUninitTaint=false);
 





More information about the cfe-commits mailing list