[cfe-commits] r42534 - in /cfe/trunk/include/clang: AST/CFG.h Analysis/FlowSensitive/DataflowSolver.h Analysis/FlowSensitive/DataflowValues.h Analysis/PathSensitive/ProgramEdge.h Analysis/ProgramEdge.h

Ted Kremenek kremenek at apple.com
Tue Oct 2 10:12:02 PDT 2007


Author: kremenek
Date: Tue Oct  2 12:12:02 2007
New Revision: 42534

URL: http://llvm.org/viewvc/llvm-project?rev=42534&view=rev
Log:
Moved ProgramEdge out out include/.../Analysis/PathSensitive to include/.../Analysis, as it is now used by the FlowSensitive subsystem as well.

Removed "Edge" nested class by CFG, as it is now subsumed by ProgramEdge.

Adjusted DataflowSolver and DataflowValues to use ProgramEdges instead
of CFG::Edge.

Added:
    cfe/trunk/include/clang/Analysis/ProgramEdge.h
      - copied, changed from r42530, cfe/trunk/include/clang/Analysis/PathSensitive/ProgramEdge.h
Removed:
    cfe/trunk/include/clang/Analysis/PathSensitive/ProgramEdge.h
Modified:
    cfe/trunk/include/clang/AST/CFG.h
    cfe/trunk/include/clang/Analysis/FlowSensitive/DataflowSolver.h
    cfe/trunk/include/clang/Analysis/FlowSensitive/DataflowValues.h

Modified: cfe/trunk/include/clang/AST/CFG.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/CFG.h?rev=42534&r1=42533&r2=42534&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/CFG.h (original)
+++ cfe/trunk/include/clang/AST/CFG.h Tue Oct  2 12:12:02 2007
@@ -231,26 +231,6 @@
   const CFGBlock*  getIndirectGotoBlock() const { return IndirectGotoBlock; }
   
   //===--------------------------------------------------------------------===//
-  // CFG Edges (Source Block, Destination Block)
-  //===--------------------------------------------------------------------===//
-
-  class Edge {
-    const CFGBlock* S;
-    const CFGBlock* D;
-  public:
-    Edge(const CFGBlock* src, const CFGBlock* dst) : S(src), D(dst) {}
-    Edge(const Edge& RHS) : S(RHS.S), D(RHS.D) {}
-    
-    Edge& operator=(const Edge& RHS) { S = RHS.S; D = RHS.D; return *this; }
-    
-    const CFGBlock* getSrc() const { return S; }
-    const CFGBlock* getDst() const { return D; }
-        
-    bool operator==(const Edge& RHS) const { return S == RHS.S && D == RHS.D; }    
-    bool operator!=(const Edge& RHS) const { return !(*this == RHS); }
-  };
-  
-  //===--------------------------------------------------------------------===//
   // Member templates useful for various batch operations over CFGs.
   //===--------------------------------------------------------------------===//
   

Modified: cfe/trunk/include/clang/Analysis/FlowSensitive/DataflowSolver.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/FlowSensitive/DataflowSolver.h?rev=42534&r1=42533&r2=42534&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/FlowSensitive/DataflowSolver.h (original)
+++ cfe/trunk/include/clang/Analysis/FlowSensitive/DataflowSolver.h Tue Oct  2 12:12:02 2007
@@ -15,6 +15,7 @@
 #define LLVM_CLANG_ANALYSES_DATAFLOW_SOLVER
 
 #include "clang/AST/CFG.h"
+#include "clang/Analysis/ProgramEdge.h"
 #include "llvm/ADT/SmallPtrSet.h"
 #include "functional" // STL
 
@@ -68,12 +69,12 @@
   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 BlkBlkEdge PrevEdge(const CFGBlock* B, const CFGBlock* PrevBlk) {
+    return BlkBlkEdge(PrevBlk,B);
   }
   
-  static CFG::Edge NextEdge(const CFGBlock* B, const CFGBlock* NextBlk) {
-    return CFG::Edge(B,NextBlk);
+  static BlkBlkEdge NextEdge(const CFGBlock* B, const CFGBlock* NextBlk) {
+    return BlkBlkEdge(B,NextBlk);
   }
 };
 
@@ -91,12 +92,12 @@
   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 BlkBlkEdge PrevEdge(const CFGBlock* B, const CFGBlock* PrevBlk) {
+    return BlkBlkEdge(B,PrevBlk);
   }
   
-  static CFG::Edge NextEdge(const CFGBlock* B, const CFGBlock* NextBlk) {
-    return CFG::Edge(NextBlk,B);
+  static BlkBlkEdge NextEdge(const CFGBlock* B, const CFGBlock* NextBlk) {
+    return BlkBlkEdge(NextBlk,B);
   }
 };
 } // end namespace dataflow
@@ -241,7 +242,7 @@
   }
     
   /// UpdateEdgeValue - Update the value associated with a given edge.
-  void UpdateEdgeValue(CFG::Edge E, ValTy& V, const CFGBlock* TargetBlock) {
+  void UpdateEdgeValue(BlkBlkEdge E, ValTy& V, const CFGBlock* TargetBlock) {
   
     EdgeDataMapTy& M = D.getEdgeDataMap();
     typename EdgeDataMapTy::iterator I = M.find(E);

Modified: cfe/trunk/include/clang/Analysis/FlowSensitive/DataflowValues.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/FlowSensitive/DataflowValues.h?rev=42534&r1=42533&r2=42534&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/FlowSensitive/DataflowValues.h (original)
+++ cfe/trunk/include/clang/Analysis/FlowSensitive/DataflowValues.h Tue Oct  2 12:12:02 2007
@@ -17,43 +17,10 @@
 #define LLVM_CLANG_ANALYSES_DATAFLOW_VALUES
 
 #include "clang/AST/CFG.h"
+#include "clang/Analysis/ProgramEdge.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.
@@ -81,7 +48,7 @@
   typedef typename ValueTypes::ValTy               ValTy;
   typedef typename ValueTypes::AnalysisDataTy      AnalysisDataTy;  
   typedef _AnalysisDirTag                          AnalysisDirTag;
-  typedef llvm::DenseMap<CFG::Edge, ValTy>         EdgeDataMapTy;
+  typedef llvm::DenseMap<ProgramEdge, ValTy>       EdgeDataMapTy;
   typedef llvm::DenseMap<const CFGBlock*, ValTy>   BlockDataMapTy;
 
   //===--------------------------------------------------------------------===//
@@ -113,13 +80,13 @@
 
   /// getEdgeData - Retrieves the dataflow values associated with a
   ///  CFG edge.
-  ValTy& getEdgeData(const CFG::Edge& E) {
+  ValTy& getEdgeData(const BlkBlkEdge& 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 {
+  const ValTy& getEdgeData(const BlkBlkEdge& E) const {
     return reinterpret_cast<DataflowValues*>(this)->getEdgeData(E);
   }  
 

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

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/ProgramEdge.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/ProgramEdge.h (removed)
@@ -1,130 +0,0 @@
-//==- ProgramEdge.h - Program Points for Path-Sensitive Analysis --*- 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 the interface ProgramEdge, which identifies a distinct
-//  location in a function based on edges within its CFG.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_CLANG_ANALYSIS_PATHSENS_PROGRAM_POINT
-#define LLVM_CLANG_ANALYSIS_PATHSENS_PROGRAM_POINT
-
-#include "llvm/Support/DataTypes.h"
-#include "llvm/ADT/DenseMap.h"
-#include <cassert>
-
-namespace clang {
-  
-  class CFGBlock;
-  class Stmt;
-  
-class ProgramEdge {
-  uintptr_t Src, Dst;
-public:
-  enum EdgeKind { StmtBlk=0, BlkStmt=1, StmtStmt=2, BlkBlk=3 };
-  static bool classof(const ProgramEdge*) { return true; }
-  
-  unsigned getKind() const { return (unsigned) Src & 0x3; }
-  void* RawSrc() const { return reinterpret_cast<void*>(Src & ~0x3); }
-  void* RawDst() const { return reinterpret_cast<void*>(Dst); }
-
-  bool operator==(const ProgramEdge & RHS) const {
-    // comparing pointer values canoncalizes "NULL" edges where both pointers 
-    // are NULL without having to worry about edgekind.  We can otherwise
-    // ignore edgekind because no CFGBlock* or Stmt* will have the same value.
-    return RawSrc() == RHS.RawSrc() && RawDst() == RHS.RawDst();    
-  }
-  
-  unsigned getHashValue() const {
-    uintptr_t v1 = reinterpret_cast<uintptr_t>(RawSrc());
-    uintptr_t v2 = reinterpret_cast<uintptr_t>(RawDst());
-    return static_cast<unsigned>( (v1 >> 4) ^ (v1 >> 9) ^ 
-                                  (v2 >> 5) ^ (v2 >> 10) );
-  }
-  
-protected:
-  
-  ProgramEdge(const void* src, const void* dst, EdgeKind k) {
-    assert (k >= StmtBlk && k <= BlkBlk);
-    Src = reinterpret_cast<uintptr_t>(const_cast<void*>(src)) | k;
-    Dst = reinterpret_cast<uintptr_t>(const_cast<void*>(dst));
-  }
-};
-
-class StmtBlkEdge : public ProgramEdge {
-public:
-  StmtBlkEdge(const Stmt* S,const CFGBlock* B)
-  : ProgramEdge(S,B,StmtBlk) {}
-  
-  const Stmt*     Src() const { return reinterpret_cast<Stmt*>(RawSrc()); }
-  const CFGBlock* Dst() const { return reinterpret_cast<CFGBlock*>(RawDst()); }  
-  
-  static bool classof(const ProgramEdge* E) { return E->getKind() == StmtBlk; }
-};
-
-class BlkStmtEdge : public ProgramEdge {
-public:
-  BlkStmtEdge(const CFGBlock* B, const Stmt* S)
-  : ProgramEdge(B,S,BlkStmt) {}
-  
-  const CFGBlock* Src() const { return reinterpret_cast<CFGBlock*>(RawSrc()); }  
-  const Stmt*     Dst() const { return reinterpret_cast<Stmt*>(RawDst()); }
-
-  static bool classof(const ProgramEdge* E) { return E->getKind() == StmtBlk; }
-};
-  
-class StmtStmtEdge : public ProgramEdge {
-public:
-  StmtStmtEdge(const Stmt* S1, const Stmt* S2)
-  : ProgramEdge(S1,S2,StmtStmt) {}
-  
-  const Stmt*     Src() const { return reinterpret_cast<Stmt*>(RawSrc()); }  
-  const Stmt*     Dst() const { return reinterpret_cast<Stmt*>(RawDst()); }
-  
-  static bool classof(const ProgramEdge* E) { return E->getKind() == StmtStmt; }
-};
-
-
-class BlkBlkEdge : public ProgramEdge {
-public:
-  BlkBlkEdge(const CFGBlock* B1, const CFGBlock* B2)
-  : ProgramEdge(B1,B2,BlkBlk) {}
-  
-  const CFGBlock* Src() const { return reinterpret_cast<CFGBlock*>(RawSrc()); }  
-  const CFGBlock* Dst() const { return reinterpret_cast<CFGBlock*>(RawDst()); }
-  
-  static bool classof(const ProgramEdge* E) { return E->getKind() == BlkBlk; }
-};
-
-} // end namespace clang
-
-
-namespace llvm { // Traits specialization for DenseMap 
-  
-template <> struct DenseMapInfo<clang::ProgramEdge> {
-
-  static inline clang::ProgramEdge getEmptyKey() {
-    return clang::BlkBlkEdge(NULL,NULL);
-  }
-  
-  static inline clang::ProgramEdge getTombstoneKey() {
-    return clang::BlkBlkEdge(reinterpret_cast<clang::CFGBlock*>(-1),
-                             reinterpret_cast<clang::CFGBlock*>(-1));
-  }
-  
-  static bool isEqual(const clang::ProgramEdge& LHS,
-                       const clang::ProgramEdge& RHS) {
-    return LHS == RHS;
-  }
-  
-  static bool isPod() { return true; }
-};
-} // end namespace llvm
-
-#endif

Copied: cfe/trunk/include/clang/Analysis/ProgramEdge.h (from r42530, cfe/trunk/include/clang/Analysis/PathSensitive/ProgramEdge.h)
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/ProgramEdge.h?p2=cfe/trunk/include/clang/Analysis/ProgramEdge.h&p1=cfe/trunk/include/clang/Analysis/PathSensitive/ProgramEdge.h&r1=42530&r2=42534&rev=42534&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/ProgramEdge.h (original)
+++ cfe/trunk/include/clang/Analysis/ProgramEdge.h Tue Oct  2 12:12:02 2007
@@ -41,6 +41,10 @@
     return RawSrc() == RHS.RawSrc() && RawDst() == RHS.RawDst();    
   }
   
+  bool operator!=(const ProgramEdge& RHS) const {
+    return RawSrc() != RHS.RawSrc() || RawDst() != RHS.RawDst();
+  }
+  
   unsigned getHashValue() const {
     uintptr_t v1 = reinterpret_cast<uintptr_t>(RawSrc());
     uintptr_t v2 = reinterpret_cast<uintptr_t>(RawDst());
@@ -118,6 +122,10 @@
                              reinterpret_cast<clang::CFGBlock*>(-1));
   }
   
+  static unsigned getHashValue(const clang::ProgramEdge& E) {
+    return E.getHashValue();
+  }
+  
   static bool isEqual(const clang::ProgramEdge& LHS,
                        const clang::ProgramEdge& RHS) {
     return LHS == RHS;





More information about the cfe-commits mailing list