[cfe-commits] r42320 - in /cfe/trunk: Analysis/DataflowSolver.h Analysis/LiveVariables.cpp Analysis/UninitializedValues.cpp include/clang/Analysis/DataflowValues.h include/clang/Analysis/FlowSensitive/ include/clang/Analysis/FlowSensitive/DataflowSolver.h include/clang/Analysis/FlowSensitive/DataflowValues.h include/clang/Analysis/LiveVariables.h include/clang/Analysis/UninitializedValues.h

Ted Kremenek kremenek at apple.com
Tue Sep 25 14:00:24 PDT 2007


Author: kremenek
Date: Tue Sep 25 16:00:24 2007
New Revision: 42320

URL: http://llvm.org/viewvc/llvm-project?rev=42320&view=rev
Log:
Moved "DataflowSolver.h" to the "include/" subtree.  Adjusted client
code that uses the solver to reflect the new location.

Created "FlowSensitive" subdirectory in include/clang/Analysis to hold
header files relating to flow-sensitive analyses.  Moved
"DataflowValues.h" into this subdirectory.

Added:
    cfe/trunk/include/clang/Analysis/FlowSensitive/
    cfe/trunk/include/clang/Analysis/FlowSensitive/DataflowSolver.h
      - copied unchanged from r42317, cfe/trunk/Analysis/DataflowSolver.h
    cfe/trunk/include/clang/Analysis/FlowSensitive/DataflowValues.h
      - copied unchanged from r42317, cfe/trunk/include/clang/Analysis/DataflowValues.h
Removed:
    cfe/trunk/Analysis/DataflowSolver.h
    cfe/trunk/include/clang/Analysis/DataflowValues.h
Modified:
    cfe/trunk/Analysis/LiveVariables.cpp
    cfe/trunk/Analysis/UninitializedValues.cpp
    cfe/trunk/include/clang/Analysis/LiveVariables.h
    cfe/trunk/include/clang/Analysis/UninitializedValues.h

Removed: cfe/trunk/Analysis/DataflowSolver.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Analysis/DataflowSolver.h?rev=42319&view=auto

==============================================================================
--- cfe/trunk/Analysis/DataflowSolver.h (original)
+++ cfe/trunk/Analysis/DataflowSolver.h (removed)
@@ -1,267 +0,0 @@
-//===--- DataflowSolver.h - Skeleton Dataflow Analysis Code -----*- C++ -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file was developed by Ted Kremenek and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file defines skeleton code for implementing dataflow analyses.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_CLANG_ANALYSES_DATAFLOW_SOLVER
-#define LLVM_CLANG_ANALYSES_DATAFLOW_SOLVER
-
-#include "clang/AST/CFG.h"
-#include "llvm/ADT/SmallPtrSet.h"
-#include "functional" // STL
-
-namespace clang {
-
-//===----------------------------------------------------------------------===//
-/// DataflowWorkListTy - Data structure representing the worklist used for
-///  dataflow algorithms.
-//===----------------------------------------------------------------------===//  
-
-class DataflowWorkListTy {
-  typedef llvm::SmallPtrSet<const CFGBlock*,20> BlockSet;
-  BlockSet wlist;
-public:
-  /// enqueue - Add a block to the worklist.  Blocks already on the
-  ///  worklist are not added a second time.
-  void enqueue(const CFGBlock* B) { wlist.insert(B); }
-  
-  /// dequeue - Remove a block from the worklist.
-  const CFGBlock* dequeue() {
-    assert (!wlist.empty());
-    const CFGBlock* B = *wlist.begin();
-    wlist.erase(B);
-    return B;          
-  }
-  
-  /// isEmpty - Return true if the worklist is empty.
-  bool isEmpty() const { return wlist.empty(); }
-};
-
-//===----------------------------------------------------------------------===//
-// BlockItrTraits - Traits classes that allow transparent iteration
-//  over successors/predecessors of a block depending on the direction
-//  of our dataflow analysis.
-//===----------------------------------------------------------------------===//
-
-namespace dataflow {
-template<typename Tag> struct ItrTraits {};
-
-template <> struct ItrTraits<forward_analysis_tag> {
-  typedef CFGBlock::const_pred_iterator PrevBItr;
-  typedef CFGBlock::const_succ_iterator NextBItr;
-  typedef CFGBlock::const_iterator      StmtItr;
-  
-  static PrevBItr PrevBegin(const CFGBlock* B) { return B->pred_begin(); }
-  static PrevBItr PrevEnd(const CFGBlock* B) { return B->pred_end(); }
-  
-  static NextBItr NextBegin(const CFGBlock* B) { return B->succ_begin(); }    
-  static NextBItr NextEnd(const CFGBlock* B) { return B->succ_end(); }
-  
-  static StmtItr StmtBegin(const CFGBlock* B) { return B->begin(); }
-  static StmtItr StmtEnd(const CFGBlock* B) { return B->end(); }
-  
-  static CFG::Edge PrevEdge(const CFGBlock* B, const CFGBlock* PrevBlk) {
-    return CFG::Edge(PrevBlk,B);
-  }
-  
-  static CFG::Edge NextEdge(const CFGBlock* B, const CFGBlock* NextBlk) {
-    return CFG::Edge(B,NextBlk);
-  }
-};
-
-template <> struct ItrTraits<backward_analysis_tag> {
-  typedef CFGBlock::const_succ_iterator    PrevBItr;
-  typedef CFGBlock::const_pred_iterator    NextBItr;
-  typedef CFGBlock::const_reverse_iterator StmtItr;
-  
-  static PrevBItr PrevBegin(const CFGBlock* B) { return B->succ_begin(); }    
-  static PrevBItr PrevEnd(const CFGBlock* B) { return B->succ_end(); }
-  
-  static NextBItr NextBegin(const CFGBlock* B) { return B->pred_begin(); }    
-  static NextBItr NextEnd(const CFGBlock* B) { return B->pred_end(); }
-  
-  static StmtItr StmtBegin(const CFGBlock* B) { return B->rbegin(); }
-  static StmtItr StmtEnd(const CFGBlock* B) { return B->rend(); }    
-  
-  static CFG::Edge PrevEdge(const CFGBlock* B, const CFGBlock* PrevBlk) {
-    return CFG::Edge(B,PrevBlk);
-  }
-  
-  static CFG::Edge NextEdge(const CFGBlock* B, const CFGBlock* NextBlk) {
-    return CFG::Edge(NextBlk,B);
-  }
-};
-} // end namespace dataflow
-
-//===----------------------------------------------------------------------===//
-/// DataflowSolverTy - Generic dataflow solver.
-//===----------------------------------------------------------------------===//
-  
-template <typename _DFValuesTy,      // Usually a subclass of DataflowValues
-          typename _TransferFuncsTy,
-          typename _MergeOperatorTy,
-          typename _Equal = std::equal_to<typename _DFValuesTy::ValTy> >
-class DataflowSolver {
-
-  //===----------------------------------------------------===//
-  // Type declarations.
-  //===----------------------------------------------------===//
-
-public:
-  typedef _DFValuesTy                              DFValuesTy;
-  typedef _TransferFuncsTy                         TransferFuncsTy;
-  typedef _MergeOperatorTy                         MergeOperatorTy;
-  
-  typedef typename _DFValuesTy::AnalysisDirTag     AnalysisDirTag;
-  typedef typename _DFValuesTy::ValTy              ValTy;
-  typedef typename _DFValuesTy::EdgeDataMapTy      EdgeDataMapTy;
-  typedef typename _DFValuesTy::BlockDataMapTy     BlockDataMapTy;
-
-  typedef dataflow::ItrTraits<AnalysisDirTag>      ItrTraits;
-  typedef typename ItrTraits::NextBItr             NextBItr;
-  typedef typename ItrTraits::PrevBItr             PrevBItr;
-  typedef typename ItrTraits::StmtItr              StmtItr;
-  
-  //===----------------------------------------------------===//
-  // External interface: constructing and running the solver.
-  //===----------------------------------------------------===//
-  
-public:
-  DataflowSolver(DFValuesTy& d) : D(d), TF(d.getAnalysisData()) {}
-  ~DataflowSolver() {}  
-  
-  /// runOnCFG - Computes dataflow values for all blocks in a CFG.
-  void runOnCFG(const CFG& cfg) {
-    // Set initial dataflow values and boundary conditions.
-    D.InitializeValues(cfg);     
-    // Solve the dataflow equations.  This will populate D.EdgeDataMap
-    // with dataflow values.
-    SolveDataflowEquations(cfg);    
-  }
-  
-  /// runOnBlock - Computes dataflow values for a given block.  This
-  ///  should usually be invoked only after previously computing
-  ///  dataflow values using runOnCFG, as runOnBlock is intended to
-  ///  only be used for querying the dataflow values within a block
-  ///  with and Observer object.
-  void runOnBlock(const CFGBlock* B) {
-    BlockDataMapTy& M = D.getBlockDataMap();
-    typename BlockDataMapTy::iterator I = M.find(B);
-
-    if (I != M.end()) {
-      TF.getVal().copyValues(I->second);
-      ProcessBlock(B);
-    }
-  }
-  
-  void runOnBlock(const CFGBlock& B) { runOnBlock(&B); }
-  void runOnBlock(CFG::iterator& I) { runOnBlock(*I); }
-  void runOnBlock(CFG::const_iterator& I) { runOnBlock(*I); }
-
-  void runOnAllBlocks(const CFG& cfg) {
-    for (CFG::const_iterator I=cfg.begin(), E=cfg.end(); I!=E; ++I)
-      runOnBlock(I);
-  }
-  
-  //===----------------------------------------------------===//
-  // Internal solver logic.
-  //===----------------------------------------------------===//
-  
-private:
- 
-  /// SolveDataflowEquations - Perform the actual worklist algorithm
-  ///  to compute dataflow values.
-  void SolveDataflowEquations(const CFG& cfg) {
-    EnqueueFirstBlock(cfg,AnalysisDirTag());
-    
-    while (!WorkList.isEmpty()) {
-      const CFGBlock* B = WorkList.dequeue();
-      ProcessMerge(B);
-      ProcessBlock(B);
-      UpdateEdges(B,TF.getVal());
-    }
-  }
-  
-  void EnqueueFirstBlock(const CFG& cfg, dataflow::forward_analysis_tag) {
-    WorkList.enqueue(&cfg.getEntry());
-  }
-  
-  void EnqueueFirstBlock(const CFG& cfg, dataflow::backward_analysis_tag) {
-    WorkList.enqueue(&cfg.getExit());
-  }  
-
-  void ProcessMerge(const CFGBlock* B) {
-    // Merge dataflow values from all predecessors of this block.
-    ValTy& V = TF.getVal();
-    V.resetValues(D.getAnalysisData());
-    MergeOperatorTy Merge;
-    
-    EdgeDataMapTy& M = D.getEdgeDataMap();
-    bool firstMerge = true;
-    
-    for (PrevBItr I=ItrTraits::PrevBegin(B),E=ItrTraits::PrevEnd(B); I!=E; ++I){
-
-      typename EdgeDataMapTy::iterator EI = M.find(ItrTraits::PrevEdge(B,*I));
-
-      if (EI != M.end()) {
-        if (firstMerge) {
-          firstMerge = false;
-          V.copyValues(EI->second);
-        }
-        else Merge(V,EI->second);
-      }
-    }
-    
-    // Set the data for the block.
-    D.getBlockDataMap()[B].copyValues(V);
-  }
-  
-
-  /// ProcessBlock - Process the transfer functions for a given block.
-  void ProcessBlock(const CFGBlock* B) {
-    for (StmtItr I=ItrTraits::StmtBegin(B), E=ItrTraits::StmtEnd(B); I!=E; ++I)
-      TF.BlockStmt_Visit(const_cast<Stmt*>(*I));
-  }
-
-  /// UpdateEdges - After processing the transfer functions for a
-  ///   block, update the dataflow value associated with the block's
-  ///   outgoing/incoming edges (depending on whether we do a
-  //    forward/backward analysis respectively)
-  void UpdateEdges(const CFGBlock* B, ValTy& V) {
-    for (NextBItr I=ItrTraits::NextBegin(B), E=ItrTraits::NextEnd(B); I!=E; ++I)
-      UpdateEdgeValue(ItrTraits::NextEdge(B,*I),V,*I);
-  }
-    
-  /// UpdateEdgeValue - Update the value associated with a given edge.
-  void UpdateEdgeValue(CFG::Edge E, ValTy& V, const CFGBlock* TargetBlock) {
-  
-    EdgeDataMapTy& M = D.getEdgeDataMap();
-    typename EdgeDataMapTy::iterator I = M.find(E);
-      
-    if (I == M.end()) {  // First computed value for this edge?
-      M[E].copyValues(V);
-      WorkList.enqueue(TargetBlock);
-    }
-    else if (!_Equal()(V,I->second)) {
-      I->second.copyValues(V);
-      WorkList.enqueue(TargetBlock);
-    }
-  }
-    
-private:
-  DFValuesTy& D;
-  DataflowWorkListTy WorkList;
-  TransferFuncsTy TF;
-};  
-  
-
-} // end namespace clang
-#endif

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

==============================================================================
--- cfe/trunk/Analysis/LiveVariables.cpp (original)
+++ cfe/trunk/Analysis/LiveVariables.cpp Tue Sep 25 16:00:24 2007
@@ -17,7 +17,7 @@
 #include "clang/AST/Expr.h"
 #include "clang/AST/CFG.h"
 #include "clang/Analysis/Visitors/CFGRecStmtDeclVisitor.h"
-#include "DataflowSolver.h"
+#include "clang/Analysis/FlowSensitive/DataflowSolver.h"
 #include "clang/Lex/IdentifierTable.h"
 #include "llvm/ADT/SmallPtrSet.h"
 

Modified: cfe/trunk/Analysis/UninitializedValues.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Analysis/UninitializedValues.cpp?rev=42320&r1=42319&r2=42320&view=diff

==============================================================================
--- cfe/trunk/Analysis/UninitializedValues.cpp (original)
+++ cfe/trunk/Analysis/UninitializedValues.cpp Tue Sep 25 16:00:24 2007
@@ -16,7 +16,7 @@
 #include "clang/Analysis/LocalCheckers.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/AST/ASTContext.h"
-#include "DataflowSolver.h"
+#include "clang/Analysis/FlowSensitive/DataflowSolver.h"
 
 #include "llvm/ADT/SmallPtrSet.h"
 

Removed: cfe/trunk/include/clang/Analysis/DataflowValues.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/DataflowValues.h?rev=42319&view=auto

==============================================================================
--- cfe/trunk/include/clang/Analysis/DataflowValues.h (original)
+++ cfe/trunk/include/clang/Analysis/DataflowValues.h (removed)
@@ -1,172 +0,0 @@
-//===--- DataflowValues.h - Data structure for dataflow values --*- C++ -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file was developed by Ted Kremenek and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file defines a skeleton data structure for encapsulating the dataflow
-// values for a CFG.  Typically this is subclassed to provide methods for
-// computing these values from a CFG.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_CLANG_ANALYSES_DATAFLOW_VALUES
-#define LLVM_CLANG_ANALYSES_DATAFLOW_VALUES
-
-#include "clang/AST/CFG.h"
-#include "llvm/ADT/DenseMap.h"
-
-//===----------------------------------------------------------------------===//
-// DenseMapInfo for CFG::Edge for use with DenseMap
-//===----------------------------------------------------------------------===//
-
-namespace llvm {
-  
-  template <> struct DenseMapInfo<clang::CFG::Edge> {
-    static inline clang::CFG::Edge getEmptyKey() { 
-      return clang::CFG::Edge(NULL,NULL); 
-    }
-    
-    static inline clang::CFG::Edge getTombstoneKey() {
-      return clang::CFG::Edge(NULL,reinterpret_cast<clang::CFGBlock*>(-1));      
-    }
-    
-    static unsigned getHashValue(const clang::CFG::Edge& E) {
-      const clang::CFGBlock* P1 = E.getSrc();
-      const clang::CFGBlock* P2 = E.getDst();  
-      return static_cast<unsigned>((reinterpret_cast<uintptr_t>(P1) >> 4) ^
-                                   (reinterpret_cast<uintptr_t>(P1) >> 9) ^
-                                   (reinterpret_cast<uintptr_t>(P2) >> 5) ^
-                                   (reinterpret_cast<uintptr_t>(P2) >> 10));
-    }
-    
-    static bool isEqual(const clang::CFG::Edge& LHS,
-                        const clang::CFG::Edge& RHS) {                        
-      return LHS == RHS;
-    }
-    
-    static bool isPod() { return true; }
-  };
-  
-} // end namespace llvm
-
-//===----------------------------------------------------------------------===//
-/// Dataflow Directional Tag Classes.  These are used for tag dispatching
-///  within the dataflow solver/transfer functions to determine what direction
-///  a dataflow analysis flows.
-//===----------------------------------------------------------------------===//   
-
-namespace clang {
-namespace dataflow {
-  struct forward_analysis_tag {};
-  struct backward_analysis_tag {};
-} // end namespace dataflow
-
-//===----------------------------------------------------------------------===//
-/// DataflowValues.  Container class to store dataflow values for a CFG.
-//===----------------------------------------------------------------------===//   
-  
-template <typename ValueTypes,
-          typename _AnalysisDirTag = dataflow::forward_analysis_tag >
-class DataflowValues {
-
-  //===--------------------------------------------------------------------===//
-  // Type declarations.
-  //===--------------------------------------------------------------------===//    
-
-public:
-  typedef typename ValueTypes::ValTy               ValTy;
-  typedef typename ValueTypes::AnalysisDataTy      AnalysisDataTy;  
-  typedef _AnalysisDirTag                          AnalysisDirTag;
-  typedef llvm::DenseMap<CFG::Edge, ValTy>         EdgeDataMapTy;
-  typedef llvm::DenseMap<const CFGBlock*, ValTy>   BlockDataMapTy;
-
-  //===--------------------------------------------------------------------===//
-  // Predicates.
-  //===--------------------------------------------------------------------===//
-
-public:
-  /// isForwardAnalysis - Returns true if the dataflow values are computed
-  ///  from a forward analysis.
-  bool isForwardAnalysis() { return isForwardAnalysis(AnalysisDirTag()); }
-  
-  /// isBackwardAnalysis - Returns true if the dataflow values are computed
-  ///  from a backward analysis.
-  bool isBackwardAnalysis() { return !isForwardAnalysis(); }
-  
-private:
-  bool isForwardAnalysis(dataflow::forward_analysis_tag)  { return true; }
-  bool isForwardAnalysis(dataflow::backward_analysis_tag) { return false; }  
-  
-  //===--------------------------------------------------------------------===//
-  // Initialization and accessors methods.
-  //===--------------------------------------------------------------------===//
-
-public:
-  /// InitializeValues - Invoked by the solver to initialize state needed for
-  ///  dataflow analysis.  This method is usually specialized by subclasses.
-  void InitializeValues(const CFG& cfg) {};  
-
-
-  /// getEdgeData - Retrieves the dataflow values associated with a
-  ///  CFG edge.
-  ValTy& getEdgeData(const CFG::Edge& E) {
-    typename EdgeDataMapTy::iterator I = EdgeDataMap.find(E);
-    assert (I != EdgeDataMap.end() && "No data associated with Edge.");
-    return I->second;
-  }
-  
-  const ValTy& getEdgeData(const CFG::Edge& E) const {
-    return reinterpret_cast<DataflowValues*>(this)->getEdgeData(E);
-  }  
-
-  /// getBlockData - Retrieves the dataflow values associated with a 
-  ///  specified CFGBlock.  If the dataflow analysis is a forward analysis,
-  ///  this data is associated with the END of the block.  If the analysis
-  ///  is a backwards analysis, it is associated with the ENTRY of the block.  
-  ValTy& getBlockData(const CFGBlock* B) {
-    typename BlockDataMapTy::iterator I = BlockDataMap.find(B);
-    assert (I != BlockDataMap.end() && "No data associated with block.");
-    return I->second;
-  }
-  
-  const ValTy& getBlockData(const CFGBlock* B) const {
-    return const_cast<DataflowValues*>(this)->getBlockData(B);
-  }  
-  
-  /// getEdgeDataMap - Retrieves the internal map between CFG edges and
-  ///  dataflow values.  Usually used by a dataflow solver to compute
-  ///  values for blocks.
-  EdgeDataMapTy& getEdgeDataMap() { return EdgeDataMap; }
-  const EdgeDataMapTy& getEdgeDataMap() const { return EdgeDataMap; }
-
-  /// getBlockDataMap - Retrieves the internal map between CFGBlocks and
-  /// dataflow values.  If the dataflow analysis operates in the forward
-  /// direction, the values correspond to the dataflow values at the start
-  /// of the block.  Otherwise, for a backward analysis, the values correpsond
-  /// to the dataflow values at the end of the block.
-  BlockDataMapTy& getBlockDataMap() { return BlockDataMap; }
-  const BlockDataMapTy& getBlockDataMap() const { return BlockDataMap; }
-
-  /// getAnalysisData - Retrieves the meta data associated with a 
-  ///  dataflow analysis for analyzing a particular CFG.  
-  ///  This is typically consumed by transfer function code (via the solver).
-  ///  This can also be used by subclasses to interpret the dataflow values.
-  AnalysisDataTy& getAnalysisData() { return AnalysisData; }
-  const AnalysisDataTy& getAnalysisData() const { return AnalysisData; }
-  
-  //===--------------------------------------------------------------------===//
-  // Internal data.
-  //===--------------------------------------------------------------------===//
-  
-protected:
-  EdgeDataMapTy      EdgeDataMap;
-  BlockDataMapTy     BlockDataMap;
-  AnalysisDataTy     AnalysisData;
-};          
-
-} // end namespace clang
-#endif

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

==============================================================================
--- cfe/trunk/include/clang/Analysis/LiveVariables.h (original)
+++ cfe/trunk/include/clang/Analysis/LiveVariables.h Tue Sep 25 16:00:24 2007
@@ -15,7 +15,7 @@
 #define LLVM_CLANG_LIVEVARIABLES_H
 
 #include "clang/AST/Decl.h"
-#include "clang/Analysis/DataflowValues.h"
+#include "clang/Analysis/FlowSensitive/DataflowValues.h"
 #include "llvm/ADT/BitVector.h"
 #include "llvm/ADT/DenseMap.h"
 

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

==============================================================================
--- cfe/trunk/include/clang/Analysis/UninitializedValues.h (original)
+++ cfe/trunk/include/clang/Analysis/UninitializedValues.h Tue Sep 25 16:00:24 2007
@@ -16,7 +16,7 @@
 #define LLVM_CLANG_UNITVALS_H
 
 #include "llvm/ADT/BitVector.h"
-#include "clang/Analysis/DataflowValues.h"
+#include "clang/Analysis/FlowSensitive/DataflowValues.h"
 
 namespace clang {
 





More information about the cfe-commits mailing list