Static Value-Flow Analysis
Loading...
Searching...
No Matches
FlowSensitive.h
Go to the documentation of this file.
1//===- FlowSensitive.h -- Flow-sensitive pointer analysis---------------------//
2//
3// SVF: Static Value-Flow Analysis
4//
5// Copyright (C) <2013-2017> <Yulei Sui>
6//
7
8// This program is free software: you can redistribute it and/or modify
9// it under the terms of the GNU Affero General Public License as published by
10// the Free Software Foundation, either version 3 of the License, or
11// (at your option) any later version.
12
13// This program is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU Affero General Public License for more details.
17
18// You should have received a copy of the GNU Affero General Public License
19// along with this program. If not, see <http://www.gnu.org/licenses/>.
20//
21//===----------------------------------------------------------------------===//
22
23/*
24 * FlowSensitiveAnalysis.h
25 *
26 * Created on: Oct 28, 2013
27 * Author: Yulei Sui
28 */
29
30#ifndef FLOWSENSITIVEANALYSIS_H_
31#define FLOWSENSITIVEANALYSIS_H_
32
33#include "Graphs/SVFG.h"
35#include "MSSA/SVFGBuilder.h"
36#include "WPA/WPAFSSolver.h"
37
38namespace SVF
39{
40
41class AndersenWaveDiff;
42
48{
49 friend class FlowSensitiveStat;
50protected:
52
53public:
57
72
74 ~FlowSensitive() override = default;
75
78 {
79 if (fspta == nullptr)
80 {
81 fspta = std::unique_ptr<FlowSensitive>(new FlowSensitive(_pag));
82 fspta->analyze();
83 }
84 return fspta.get();
85 }
86
88 static void releaseFSWPA()
89 {
90 fspta = nullptr;
91 }
92
94 virtual bool runOnModule()
95 {
96 return false;
97 }
98
100 void analyze() override;
101
102 virtual void solveAndwritePtsToFile(const std::string& filename);
103
104 virtual void readPtsFromFile(const std::string& filename);
105
106 virtual void solveConstraints();
107
109 void initialize() override;
110
112 void finalize() override;
113
115 const std::string PTAName() const override
116 {
117 return "FlowSensitive";
118 }
119
121
122 static inline bool classof(const FlowSensitive *)
123 {
124 return true;
125 }
126 static inline bool classof(const PointerAnalysis *pta)
127 {
128 return pta->getAnalysisTy() == PTATY::FSSPARSE_WPA;
129 }
131
133 inline SVFG* getSVFG() const
134 {
135 return svfg;
136 }
137
138protected:
140 NodeStack& SCCDetect() override;
141
143
144
145 bool propFromSrcToDst(SVFGEdge* edge) override;
147 virtual bool propAlongDirectEdge(const DirectSVFGEdge* edge);
149 virtual bool propAlongIndirectEdge(const IndirectSVFGEdge* edge);
151 virtual bool propVarPtsFromSrcToDst(NodeID var, const SVFGNode* src, const SVFGNode* dst);
154 virtual bool propagateFromAPToFP(const ActualParmSVFGNode* ap, const SVFGNode* dst);
157 virtual bool propagateFromFRToAR(const FormalRetSVFGNode* fr, const SVFGNode* dst);
159 virtual bool weakUpdateOutFromIn(const SVFGNode* node)
160 {
161 return getDFPTDataTy()->updateAllDFOutFromIn(node->getId(),0,false);
162 }
165 {
166 return getDFPTDataTy()->updateAllDFOutFromIn(node->getId(),singleton,true);
167 }
169
172
173 bool propVarPtsAfterCGUpdated(NodeID var, const SVFGNode* src, const SVFGNode* dst);
174
176 {
177 return getDFPTDataTy()->updateAllDFInFromOut(srcStmt->getId(), srcVar, dstStmt->getId(),dstVar);
178 }
179 virtual inline bool propDFInToIn(const SVFGNode* srcStmt, NodeID srcVar, const SVFGNode* dstStmt, NodeID dstVar)
180 {
181 return getDFPTDataTy()->updateAllDFInFromIn(srcStmt->getId(), srcVar, dstStmt->getId(),dstVar);
182 }
184
186
188 {
189 return getDFPTDataTy()->updateDFOutFromIn(srcStmt->getId(),srcVar, dstStmt->getId(),dstVar);
190 }
192 {
193 return getDFPTDataTy()->updateDFInFromIn(srcStmt->getId(),srcVar, dstStmt->getId(),dstVar);
194 }
196 {
197 return getDFPTDataTy()->updateDFInFromOut(srcStmt->getId(),srcVar, dstStmt->getId(),dstVar);
198 }
199
200 virtual inline bool unionPtsFromIn(const SVFGNode* stmt, NodeID srcVar, NodeID dstVar)
201 {
202 return getDFPTDataTy()->updateTLVPts(stmt->getId(),srcVar,dstVar);
203 }
204 virtual inline bool unionPtsFromTop(const SVFGNode* stmt, NodeID srcVar, NodeID dstVar)
205 {
206 return getDFPTDataTy()->updateATVPts(srcVar,stmt->getId(),dstVar);
207 }
208
209 inline void clearAllDFOutVarFlag(const SVFGNode* stmt)
210 {
211 getDFPTDataTy()->clearAllDFOutUpdatedVar(stmt->getId());
212 }
214
216
217 void processNode(NodeID nodeId) override;
218 bool processSVFGNode(SVFGNode* node);
219 virtual bool processAddr(const AddrSVFGNode* addr);
220 virtual bool processCopy(const CopySVFGNode* copy);
221 virtual bool processPhi(const PHISVFGNode* phi);
222 virtual bool processGep(const GepSVFGNode* edge);
223 virtual bool processLoad(const LoadSVFGNode* load);
224 virtual bool processStore(const StoreSVFGNode* store);
226
228
229
230 bool updateCallGraph(const CallSiteToFunPtrMap& callsites) override;
234 virtual void updateConnectedNodes(const SVFGEdgeSetTy& edges);
236
238 bool isStrongUpdate(const SVFGNode* node, NodeID& singleton);
239
241 virtual void countAliases(Set<std::pair<NodeID, NodeID>> cmp, unsigned *mayAliases, unsigned *noAliases);
242
245
246 inline const PointsTo& getDFInPtsSet(const SVFGNode* stmt, const NodeID node)
247 {
248 return getDFPTDataTy()->getDFInPtsSet(stmt->getId(),node);
249 }
250 inline const PointsTo& getDFOutPtsSet(const SVFGNode* stmt, const NodeID node)
251 {
252 return getDFPTDataTy()->getDFOutPtsSet(stmt->getId(),node);
253 }
255
259 inline const DFInOutMap& getDFInputMap() const
260 {
261 return getMutDFPTDataTy()->getDFIn();
262 }
263 inline const DFInOutMap& getDFOutputMap() const
264 {
265 return getMutDFPTDataTy()->getDFOut();
266 }
268
271 virtual void cluster(void);
273 virtual void plainMap(void) const;
274
275 static std::unique_ptr<FlowSensitive> fspta;
278
280 std::vector<std::pair<hclust_fast_methods, std::vector<NodeID>>> candidateMappings;
281
283
293
297
298 double solveTime;
299 double sccTime;
300 double processTime;
304 double updateTime;
305 double addrTime;
306 double copyTime;
307 double gepTime;
308 double loadTime;
309 double storeTime;
310 double phiTime;
312
315
316 void svfgStat();
317};
318
319} // End namespace SVF
320
321#endif /* FLOWSENSITIVEANALYSIS_H_ */
newitem type
Definition cJSON.cpp:2739
copy
Definition cJSON.cpp:414
MutDFPTDataTy * getMutDFPTDataTy() const
DFPTDataTy * getDFPTDataTy() const
BVDataPTAImpl::MutDFPTDataTy MutDFPTDataTy
bool updateOutFromIn(const SVFGNode *srcStmt, NodeID srcVar, const SVFGNode *dstStmt, NodeID dstVar)
Update data-flow points-to data.
~FlowSensitive() override=default
Destructor.
void processNode(NodeID nodeId) override
Handle various constraints.
u32_t numOfProcessedLoad
Number of processed Phi node.
static bool classof(const PointerAnalysis *pta)
const PointsTo & getDFInPtsSet(const SVFGNode *stmt, const NodeID node)
Get points-to set for a node from data flow IN/OUT set at a statement.
virtual void solveConstraints()
virtual bool unionPtsFromIn(const SVFGNode *stmt, NodeID srcVar, NodeID dstVar)
virtual void updateConnectedNodes(const SVFGEdgeSetTy &edges)
Update nodes connected during updating call graph.
u32_t numOfProcessedCopy
Number of processed Addr node.
virtual void countAliases(Set< std::pair< NodeID, NodeID > > cmp, unsigned *mayAliases, unsigned *noAliases)
Fills may/noAliases for the location/pointer pairs in cmp.
double gepTime
time of handling gep edges
static std::unique_ptr< FlowSensitive > fspta
double indirectPropaTime
time of points-to propagation of top-level pointers
virtual bool propagateFromAPToFP(const ActualParmSVFGNode *ap, const SVFGNode *dst)
double addrTime
time of handling address edges
virtual bool propagateFromFRToAR(const FormalRetSVFGNode *fr, const SVFGNode *dst)
virtual bool propDFInToIn(const SVFGNode *srcStmt, NodeID srcVar, const SVFGNode *dstStmt, NodeID dstVar)
const DFInOutMap & getDFOutputMap() const
NodeStack & SCCDetect() override
SCC detection.
double solveTime
time of solve.
bool isStrongUpdate(const SVFGNode *node, NodeID &singleton)
Return TRUE if this is a strong update STORE statement.
virtual void readPtsFromFile(const std::string &filename)
virtual bool unionPtsFromTop(const SVFGNode *stmt, NodeID srcVar, NodeID dstVar)
const DFInOutMap & getDFInputMap() const
virtual bool runOnModule()
We start from here.
virtual void plainMap(void) const
Sets the global best mapping as a plain mapping, i.e. n -> n.
AndersenWaveDiff * ander
virtual bool propDFOutToIn(const SVFGNode *srcStmt, NodeID srcVar, const SVFGNode *dstStmt, NodeID dstVar)
u32_t numOfProcessedStore
Number of processed Load node.
SVFG::SVFGEdgeSetTy SVFGEdgeSetTy
const PointsTo & getDFOutPtsSet(const SVFGNode *stmt, const NodeID node)
void analyze() override
Flow sensitive analysis.
BVDataPTAImpl::MutDFPTDataTy::PtsMap PtsMap
double storeTime
time of store edges
SVFG * getSVFG() const
Return SVFG.
virtual bool updateInFromIn(const SVFGNode *srcStmt, NodeID srcVar, const SVFGNode *dstStmt, NodeID dstVar)
double copyTime
time of handling copy edges
bool propFromSrcToDst(SVFGEdge *edge) override
Propagation.
u32_t numOfProcessedGep
Number of processed Copy node.
virtual void cluster(void)
virtual bool strongUpdateOutFromIn(const SVFGNode *node, NodeID singleton)
Handle strong updates.
void finalize() override
Finalize analysis.
void clearAllDFOutVarFlag(const SVFGNode *stmt)
bool processSVFGNode(SVFGNode *node)
virtual bool processLoad(const LoadSVFGNode *load)
bool propVarPtsAfterCGUpdated(NodeID var, const SVFGNode *src, const SVFGNode *dst)
virtual bool processPhi(const PHISVFGNode *phi)
virtual bool processStore(const StoreSVFGNode *store)
u32_t maxSCCSize
Number of processed mssa node.
virtual bool processCopy(const CopySVFGNode *copy)
double loadTime
time of load edges
bool updateCallGraph(const CallSiteToFunPtrMap &callsites) override
Update call graph.
virtual bool weakUpdateOutFromIn(const SVFGNode *node)
Handle weak updates.
virtual bool processAddr(const AddrSVFGNode *addr)
u32_t numOfProcessedActualParam
Number of processed Store node.
u32_t numOfProcessedPhi
Number of processed Gep node.
double propagationTime
time of points-to propagation.
const std::string PTAName() const override
Get PTA name.
static bool classof(const FlowSensitive *)
Methods for support type inquiry through isa, cast, and dyn_cast.
virtual bool propAlongDirectEdge(const DirectSVFGEdge *edge)
Propagate points-to information along a DIRECT SVFG edge.
void initialize() override
Initialize analysis.
void connectCallerAndCallee(const CallEdgeMap &newEdges, SVFGEdgeSetTy &edges)
Connect nodes in SVFG.
std::vector< std::pair< hclust_fast_methods, std::vector< NodeID > > > candidateMappings
Save candidate mappings for evaluation's sake.
virtual bool processGep(const GepSVFGNode *edge)
u32_t numOfProcessedFormalRet
Number of processed actual param node.
double directPropaTime
time of points-to propagation of address-taken objects
double processTime
time of processNode.
u32_t numOfProcessedAddr
Statistics.
virtual bool propVarPtsFromSrcToDst(NodeID var, const SVFGNode *src, const SVFGNode *dst)
Propagate points-to information of a certain variable from src to dst.
static void releaseFSWPA()
Release flow-sensitive pointer analysis.
FlowSensitive(SVFIR *_pag, PTATY type=PTATY::FSSPARSE_WPA)
Constructor.
virtual bool propAlongIndirectEdge(const IndirectSVFGEdge *edge)
Propagate points-to information along an INDIRECT SVFG edge.
double phiTime
time of phi nodes.
static FlowSensitive * createFSWPA(SVFIR *_pag)
Create single instance of flow-sensitive pointer analysis.
double sccTime
time of SCC detection.
double updateTime
time of strong/weak updates.
virtual bool updateInFromOut(const SVFGNode *srcStmt, NodeID srcVar, const SVFGNode *dstStmt, NodeID dstVar)
u32_t numOfProcessedMSSANode
Number of processed formal ret node.
BVDataPTAImpl::MutDFPTDataTy::DFPtsMap DFInOutMap
virtual void solveAndwritePtsToFile(const std::string &filename)
double updateCallGraphTime
time of updating call graph
Map< LocID, PtsMap > DFPtsMap
Data-flow point-to map.
const DFPtsMap & getDFIn()
const DFPtsMap & getDFOut()
BaseMutPTData::PtsMap PtsMap
OrderedMap< const CallICFGNode *, FunctionSet > CallEdgeMap
PTATY getAnalysisTy() const
Type of pointer analysis.
SVFIR::CallSiteToFunPtrMap CallSiteToFunPtrMap
u32_t OnTheFlyIterBudgetForStat
Flag for iteration budget for on-the-fly statistics.
NodeID getId() const
Get ID.
Definition SVFValue.h:158
VFGEdge::SVFGEdgeSetTy SVFGEdgeSetTy
Definition VFG.h:78
u32_t iterationForPrintStat
print out statistics for i-th iteration
Definition WPASolver.h:174
for isBitcode
Definition BasicTypes.h:70
std::stack< NodeID > NodeStack
Definition GeneralType.h:92
WPAFSSolver< SVFG * > WPASVFGFSSolver
PTATY
Pointer analysis type list.
Definition PTATY.h:9
@ FSSPARSE_WPA
Sparse flow sensitive WPA.
Definition PTATY.h:20
u32_t NodeID
Definition GeneralType.h:76
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:76
unsigned u32_t
Definition GeneralType.h:67
std::unordered_set< Key, Hash, KeyEqual, Allocator > Set
Definition GeneralType.h:51