[cfe-commits] r42034 - in /cfe/trunk: Analysis/DataflowSolver.h Analysis/UnintializedValues.cpp include/clang/Analysis/CFGStmtVisitor.h include/clang/Analysis/CFGVarDeclVisitor.h include/clang/Analysis/DataflowValues.h include/clang/Analysis/UninitializedValues.h
Ted Kremenek
kremenek at apple.com
Mon Sep 17 10:14:52 PDT 2007
Author: kremenek
Date: Mon Sep 17 12:14:52 2007
New Revision: 42034
URL: http://llvm.org/viewvc/llvm-project?rev=42034&view=rev
Log:
Removed "ObserverTy" from core DataflowValues types. The observer
mechanism can be implemented simply by affixing the Observer to an
analysis meta data, so it doesn't need to be a required type. This
also permits analyses not to implement an Observer if it doesn't make
sense.
Changed "DataflowValues::MetaDataTy" to
"DataflowValues::AnalysisDataTy" to reflect that the type
enscapsulated the data associated with analyzing a given CFG.
Changed CFGStmtVisitor::BlockStmt_VisitImplicitControlFlowStmt(Stmt*)
to ...VisitImplicitControlFlowExpr(Expr*). The type narrowing is more
precise and more useful to clients.
Added CFGStmtVisitor::BlockStmt_VisitExpr to reflect the visitation of
expressions at the block statement level. This captures all implicit
control-flow statements as well as other expressions that are hoisted
to the block level (such as conditions for terminators and function
calls). This is especially useful for dataflow analysis.
Modified:
cfe/trunk/Analysis/DataflowSolver.h
cfe/trunk/Analysis/UnintializedValues.cpp
cfe/trunk/include/clang/Analysis/CFGStmtVisitor.h
cfe/trunk/include/clang/Analysis/CFGVarDeclVisitor.h
cfe/trunk/include/clang/Analysis/DataflowValues.h
cfe/trunk/include/clang/Analysis/UninitializedValues.h
Modified: cfe/trunk/Analysis/DataflowSolver.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Analysis/DataflowSolver.h?rev=42034&r1=42033&r2=42034&view=diff
==============================================================================
--- cfe/trunk/Analysis/DataflowSolver.h (original)
+++ cfe/trunk/Analysis/DataflowSolver.h Mon Sep 17 12:14:52 2007
@@ -62,14 +62,13 @@
typedef typename _DFValuesTy::AnalysisDirTag AnalysisDirTag;
typedef typename _DFValuesTy::ValTy ValTy;
typedef typename _DFValuesTy::BlockDataMapTy BlockDataMapTy;
- typedef typename _DFValuesTy::ObserverTy ObserverTy;
//===--------------------------------------------------------------------===//
// External interface: constructing and running the solver.
//===--------------------------------------------------------------------===//
public:
- DataflowSolver(DFValuesTy& d, ObserverTy* o = NULL) : D(d), O(o) {}
+ DataflowSolver(DFValuesTy& d) : D(d) {}
~DataflowSolver() {}
/// runOnCFG - Computes dataflow values for all blocks in a CFG.
@@ -86,7 +85,7 @@
/// only be used for querying the dataflow values within a block with
/// and Observer object.
void runOnBlock(const CFGBlock* B) {
- TransferFuncsTy TF (D.getMetaData(),O);
+ TransferFuncsTy TF (D.getAnalysisData());
ProcessBlock(B,TF,AnalysisDirTag());
}
@@ -106,7 +105,7 @@
WorkList.enqueue(&cfg.getEntry());
// Create the state for transfer functions.
- TransferFuncsTy TF(D.getMetaData(),O);
+ TransferFuncsTy TF(D.getAnalysisData());
// Process the worklist until it is empty.
while (!WorkList.isEmpty()) {
@@ -131,7 +130,7 @@
WorkList.enqueue(&cfg.getExit());
// Create the state for transfer functions.
- TransferFuncsTy TF(D.getMetaData(),O);
+ TransferFuncsTy TF(D.getAnalysisData());
// Process the worklist until it is empty.
while (!WorkList.isEmpty()) {
@@ -213,7 +212,6 @@
private:
DFValuesTy& D;
- ObserverTy* O;
};
Modified: cfe/trunk/Analysis/UnintializedValues.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Analysis/UnintializedValues.cpp?rev=42034&r1=42033&r2=42034&view=diff
==============================================================================
--- cfe/trunk/Analysis/UnintializedValues.cpp (original)
+++ cfe/trunk/Analysis/UnintializedValues.cpp Mon Sep 17 12:14:52 2007
@@ -24,26 +24,30 @@
namespace {
-class RegisterDecls : public CFGVarDeclVisitor<RegisterDecls> {
- UninitializedValues::MetaDataTy& M;
+class RegisterDeclsAndExprs : public CFGVarDeclVisitor<RegisterDeclsAndExprs> {
+ UninitializedValues::AnalysisDataTy& AD;
public:
- RegisterDecls(const CFG& cfg, UninitializedValues::MetaDataTy& m) :
- CFGVarDeclVisitor<RegisterDecls>(cfg), M(m) {}
+ RegisterDeclsAndExprs(const CFG& cfg, UninitializedValues::AnalysisDataTy& ad)
+ : CFGVarDeclVisitor<RegisterDeclsAndExprs>(cfg), AD(ad)
+ {}
void VisitVarDecl(VarDecl* D) {
- if (M.Map.find(D) == M.Map.end()) {
- M.Map[D] = M.NumDecls++;
- }
- }
+ if (AD.VMap.find(D) == AD.VMap.end())
+ AD.VMap[D] = AD.Counter++;
+ }
+
+ void BlockStmt_VisitExpr(Expr* E) {
+ if (AD.EMap.find(E) == AD.EMap.end())
+ AD.EMap[E] = AD.Counter++;
+ }
};
} // end anonymous namespace
void UninitializedValues::InitializeValues(const CFG& cfg) {
- RegisterDecls R(cfg,this->getMetaData());
- R.VisitAllDecls();
-
- getBlockDataMap()[ &cfg.getEntry() ].resize( getMetaData().NumDecls );
+ RegisterDeclsAndExprs R(cfg,this->getAnalysisData());
+ R.VisitAllDecls();
+ getBlockDataMap()[ &cfg.getEntry() ].resize( getAnalysisData().Counter );
}
//===--------------------------------------------------------------------===//
@@ -53,15 +57,17 @@
namespace {
class TransferFuncs : public CFGStmtVisitor<TransferFuncs,bool> {
UninitializedValues::ValTy V;
- UninitializedValues::MetaDataTy& M;
- UninitializedValues::ObserverTy* O;
+ UninitializedValues::AnalysisDataTy& AD;
public:
- TransferFuncs(UninitializedValues::MetaDataTy& m,
- UninitializedValues::ObserverTy* o) : M(m), O(o) {
- V.resize(M.NumDecls);
+ TransferFuncs(UninitializedValues::AnalysisDataTy& ad) : AD(ad) {
+ V.resize(AD.Counter);
}
UninitializedValues::ValTy& getVal() { return V; }
+
+// bool VisitDeclRefExpr(DeclRefExpr* DR);
+// bool VisitBinaryOperator(BinaryOperator* B);
+// bool VisitUnaryOperator(UnaryOperator* U);
};
} // end anonymous namespace
Modified: cfe/trunk/include/clang/Analysis/CFGStmtVisitor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/CFGStmtVisitor.h?rev=42034&r1=42033&r2=42034&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/CFGStmtVisitor.h (original)
+++ cfe/trunk/include/clang/Analysis/CFGStmtVisitor.h Mon Sep 17 12:14:52 2007
@@ -28,7 +28,8 @@
#define DEFAULT_BLOCKSTMT_VISIT(CLASS) RetTy BlockStmt_Visit ## CLASS(CLASS *S)\
{ return\
- static_cast<ImplClass*>(this)->BlockStmt_VisitImplicitControlFlowStmt(S); }
+ static_cast<ImplClass*>(this)->BlockStmt_VisitImplicitControlFlowExpr(\
+ cast<Expr>(S)); }
template <typename ImplClass, typename RetTy=void>
class CFGStmtVisitor : public StmtVisitor<ImplClass,RetTy> {
@@ -54,7 +55,11 @@
}
default:
- return static_cast<ImplClass*>(this)->BlockStmt_VisitStmt(S);
+ if (isa<Expr>(S))
+ return
+ static_cast<ImplClass*>(this)->BlockStmt_VisitExpr(cast<Expr>(S));
+ else
+ return static_cast<ImplClass*>(this)->BlockStmt_VisitStmt(S);
}
}
@@ -62,8 +67,12 @@
DEFAULT_BLOCKSTMT_VISIT(StmtExpr)
DEFAULT_BLOCKSTMT_VISIT(ConditionalOperator)
- RetTy BlockStmt_VisitImplicitControlFlowStmt(Stmt* S) {
- return static_cast<ImplClass*>(this)->BlockStmt_VisitStmt(S);
+ RetTy BlockStmt_VisitImplicitControlFlowExpr(Expr* E) {
+ return static_cast<ImplClass*>(this)->BlockStmt_VisitExpr(E);
+ }
+
+ RetTy BlockStmt_VisitExpr(Expr* E) {
+ return static_cast<ImplClass*>(this)->BlockStmt_VisitStmt(E);
}
RetTy BlockStmt_VisitStmt(Stmt* S) {
@@ -72,12 +81,12 @@
RetTy BlockStmt_VisitLogicalOp(BinaryOperator* B) {
return
- static_cast<ImplClass*>(this)->BlockStmt_VisitImplicitControlFlowStmt(B);
+ static_cast<ImplClass*>(this)->BlockStmt_VisitImplicitControlFlowExpr(B);
}
RetTy BlockStmt_VisitComma(BinaryOperator* B) {
return
- static_cast<ImplClass*>(this)->BlockStmt_VisitImplicitControlFlowStmt(B);
+ static_cast<ImplClass*>(this)->BlockStmt_VisitImplicitControlFlowExpr(B);
}
//===--------------------------------------------------------------------===//
Modified: cfe/trunk/include/clang/Analysis/CFGVarDeclVisitor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/CFGVarDeclVisitor.h?rev=42034&r1=42033&r2=42034&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/CFGVarDeclVisitor.h (original)
+++ cfe/trunk/include/clang/Analysis/CFGVarDeclVisitor.h Mon Sep 17 12:14:52 2007
@@ -15,7 +15,7 @@
#ifndef LLVM_CLANG_ANALYSIS_CFG_VARDECL_VISITOR_H
#define LLVM_CLANG_ANALYSIS_CFG_VARDECL_VISITOR_H
-#include "clang/AST/StmtVisitor.h"
+#include "clang/Analysis/CFGStmtVisitor.h"
#include "clang/AST/Decl.h"
#include "clang/AST/Stmt.h"
#include "clang/AST/CFG.h"
@@ -23,7 +23,7 @@
namespace clang {
template <typename ImplClass>
-class CFGVarDeclVisitor : public StmtVisitor<ImplClass> {
+class CFGVarDeclVisitor : public CFGStmtVisitor<ImplClass> {
const CFG& cfg;
public:
CFGVarDeclVisitor(const CFG& c) : cfg(c) {}
Modified: cfe/trunk/include/clang/Analysis/DataflowValues.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/DataflowValues.h?rev=42034&r1=42033&r2=42034&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/DataflowValues.h (original)
+++ cfe/trunk/include/clang/Analysis/DataflowValues.h Mon Sep 17 12:14:52 2007
@@ -35,7 +35,7 @@
} // end namespace dataflow
-template <typename TypeClass,
+template <typename ValueTypes,
typename _AnalysisDirTag = dataflow::forward_analysis_tag >
class DataflowValues {
@@ -44,10 +44,8 @@
//===--------------------------------------------------------------------===//
public:
- typedef typename TypeClass::ValTy ValTy;
- typedef typename TypeClass::MetaDataTy MetaDataTy;
- typedef typename TypeClass::ObserverTy ObserverTy;
-
+ typedef typename ValueTypes::ValTy ValTy;
+ typedef typename ValueTypes::AnalysisDataTy AnalysisDataTy;
typedef _AnalysisDirTag AnalysisDirTag;
typedef llvm::DenseMap<const CFGBlock*, ValTy> BlockDataMapTy;
@@ -101,19 +99,20 @@
BlockDataMapTy& getBlockDataMap() { return BlockDataMap; }
const BlockDataMapTy& getBlockDataMap() const { return BlockDataMap; }
- /// getMetaData - Retrieves the meta data associated with a dataflow analysis.
+ /// 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.
- MetaDataTy& getMetaData() { return Meta; }
- const MetaDataTy& getMetaData() const { return Meta; }
+ AnalysisDataTy& getAnalysisData() { return AnalysisData; }
+ const AnalysisDataTy& getAnalysisData() const { return AnalysisData; }
//===--------------------------------------------------------------------===//
// Internal data.
//===--------------------------------------------------------------------===//
protected:
- BlockDataMapTy BlockDataMap;
- MetaDataTy Meta;
+ BlockDataMapTy BlockDataMap;
+ AnalysisDataTy AnalysisData;
};
} // end namespace clang
Modified: cfe/trunk/include/clang/Analysis/UninitializedValues.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/UninitializedValues.h?rev=42034&r1=42033&r2=42034&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/UninitializedValues.h (original)
+++ cfe/trunk/include/clang/Analysis/UninitializedValues.h Mon Sep 17 12:14:52 2007
@@ -21,10 +21,12 @@
namespace clang {
class VarDecl;
+ class Expr;
-/// UninitializedValuesTypes - Utility class to wrap type declarations
-/// used for defining the UninitializedValues class.
-class UninitializedValuesTypes {
+/// UninitializedValues_ValueTypes - Utility class to wrap type declarations
+/// for dataflow values and dataflow analysis state for the
+/// Unitialized Values analysis.
+class UninitializedValues_ValueTypes {
public:
class ValTy {
llvm::BitVector BV;
@@ -41,26 +43,21 @@
void copyValues(ValTy& RHS) { BV = RHS.BV; }
};
- struct MetaDataTy {
- llvm::DenseMap<const VarDecl*, unsigned > Map;
- unsigned NumDecls;
+ struct AnalysisDataTy {
+ llvm::DenseMap<const VarDecl*, unsigned > VMap;
+ llvm::DenseMap<const Expr*, unsigned > EMap;
+ unsigned Counter;
- MetaDataTy() : NumDecls(0) {}
- };
-
- class ObserverTy {
- virtual ~ObserverTy();
- virtual void ObserveStmt(Stmt* S, MetaDataTy& M, ValTy& V) {}
- virtual void ObserveBlockExit(const CFGBlock* B, MetaDataTy& M, ValTy& V) {}
+ AnalysisDataTy() : Counter(0) {}
};
};
-
/// UninitializedValues - Objects of this class encapsulate dataflow analysis
/// information regarding what variable declarations in a function are
/// potentially unintialized.
-class UninitializedValues : public DataflowValues<UninitializedValuesTypes> {
-
+class UninitializedValues :
+ public DataflowValues<UninitializedValues_ValueTypes> {
+
//===--------------------------------------------------------------------===//
// Public interface.
//===--------------------------------------------------------------------===//
More information about the cfe-commits
mailing list