Static Value-Flow Analysis
Loading...
Searching...
No Matches
VersionedFlowSensitive.h
Go to the documentation of this file.
1//===- VersionedFlowSensitive.h -- Versioned flow-sensitive pointer analysis --------//
2
3/*
4 * VersionedFlowSensitiveAnalysis.h
5 *
6 * Created on: Jun 26, 2020
7 * Author: Mohamad Barbar
8 *
9 * The implementation is based on
10 * Mohamad Barbar, Yulei Sui and Shiping Chen. "Object Versioning for Flow-Sensitive Pointer Analysis".
11 * International Symposium on Code Generation and Optimization (CGO'21)
12 */
13
14#ifndef VFS_H_
15#define VFS_H_
16
17#include "Graphs/SVFGOPT.h"
18#include "MSSA/SVFGBuilder.h"
19#include "WPA/FlowSensitive.h"
20#include "WPA/WPAFSSolver.h"
21#include "MemoryModel/PTATY.h"
23
24namespace SVF
25{
26
27class AndersenWaveDiff;
28
33{
35
36private:
38
39public:
42
43 typedef std::vector<ObjToVersionMap> LocVersionMap;
46
48 static const Version invalidVersion;
49
52
55
57 virtual void initialize() override;
58
60 virtual void finalize() override;
61
63 virtual const std::string PTAName() const override
64 {
65 return "VersionedFlowSensitive";
66 }
67
69
70 static inline bool classof(const VersionedFlowSensitive *)
71 {
72 return true;
73 }
74 static inline bool classof(const PointerAnalysis *pta)
75 {
76 return pta->getAnalysisTy() == PTATY::VFS_WPA;
77 }
79
82 {
83 if (vfspta == nullptr)
84 {
86 vfspta->analyze();
87 }
88
89 return vfspta;
90 }
91
93 static void releaseVFSWPA()
94 {
95 if (vfspta) delete vfspta;
96 vfspta = nullptr;
97 }
98
99protected:
100 virtual bool processLoad(const LoadSVFGNode* load) override;
101 virtual bool processStore(const StoreSVFGNode* store) override;
102 virtual void processNode(NodeID n) override;
103 virtual void updateConnectedNodes(const SVFGEdgeSetTy& newEdges) override;
104
106 virtual bool propAlongIndirectEdge(const IndirectSVFGEdge*) override
107 {
108 return false;
109 }
110
112 virtual void cluster(void) override;
113
114public:
116 virtual bool isStore(const NodeID l) const;
117
119 virtual bool isLoad(const NodeID l) const;
120
122 Version getVersion(const NodeID l, const NodeID o, const LocVersionMap &lvm) const;
123
125 Version getConsume(const NodeID l, const NodeID o) const;
126
128 Version getYield(const NodeID l, const NodeID o) const;
129
131 std::vector<Version> &getReliantVersions(const NodeID o, const Version v);
132
134 NodeBS &getStmtReliance(const NodeID o, const Version v);
135
137 void dumpReliances(void) const;
138
140 void dumpLocVersionMaps(void) const;
141
142 void solveAndwritePtsToFile(const std::string& filename) override;
143
144 void writeVersionedAnalysisResultToFile(const std::string& filename);
145
146 void readVersionedAnalysisResultFromFile(std::ifstream& F);
147
148 void readPtsFromFile(const std::string& filename) override;
149
151 static void dumpMeldVersion(MeldVersion &v);
152
153private:
155 void prelabel(void);
157 void meldLabel(void);
159 static bool meld(MeldVersion &mv1, const MeldVersion &mv2);
160
163
168
171 void propagateVersion(const NodeID o, const Version v, const Version vp, bool time=true);
172
174 virtual void buildIsStoreLoadMaps(void);
175
177 virtual void buildDeltaMaps(void);
178
181 virtual bool delta(const NodeID l) const;
182
185 virtual bool deltaSource(const NodeID l) const;
186
188 void setVersion(const NodeID l, const NodeID o, const Version v, LocVersionMap &lvm);
189
191 void setConsume(const NodeID l, const NodeID o, const Version v);
192
194 void setYield(const NodeID l, const NodeID o, const Version v);
195
201
206
210
211 // Maps an object o to o' if o is equivalent to o' with respect to
212 // versioning. Thus, we don't need to store the versions of o and look
213 // up those for o' instead.
215
219
221
224
227 std::vector<bool> deltaMap;
228
232 std::vector<bool> deltaSourceMap;
233
235 std::vector<bool> isStoreMap;
236
238 std::vector<bool> isLoadMap;
239
241
244
249
251
252 class SCC
253 {
254 private:
255 typedef struct NodeData
256 {
257 int index;
260 } NodeData;
261
262 public:
274 static unsigned detectSCCs(VersionedFlowSensitive *vfs,
275 const SVFG *svfg, const NodeID object,
276 const std::vector<const SVFGNode *> &startingNodes,
277 std::vector<int> &partOf,
278 std::vector<const IndirectSVFGEdge *> &footprint);
279
280 private:
282 static void visit(VersionedFlowSensitive *vfs,
283 const NodeID object,
284 std::vector<int> &partOf,
285 std::vector<const IndirectSVFGEdge *> &footprint,
286 std::vector<NodeData> &nodeData,
287 std::stack<const SVFGNode *> &stack,
288 int &index,
289 int &currentSCC,
290 const SVFGNode *v);
291 };
292};
293
294} // End namespace SVF
295
296#endif /* VFS_H_ */
newitem type
Definition cJSON.cpp:2739
cJSON * n
Definition cJSON.cpp:2558
int index
Definition cJSON.h:170
VersionedPTData< NodeID, NodeSet, NodeID, PointsTo, VersionedVar, Set< VersionedVar > > VersionedPTDataTy
SVFG::SVFGEdgeSetTy SVFGEdgeSetTy
void analyze() override
Flow sensitive analysis.
PTATY getAnalysisTy() const
Type of pointer analysis.
static void visit(VersionedFlowSensitive *vfs, const NodeID object, std::vector< int > &partOf, std::vector< const IndirectSVFGEdge * > &footprint, std::vector< NodeData > &nodeData, std::stack< const SVFGNode * > &stack, int &index, int &currentSCC, const SVFGNode *v)
Called by detectSCCs then called recursively.
static unsigned detectSCCs(VersionedFlowSensitive *vfs, const SVFG *svfg, const NodeID object, const std::vector< const SVFGNode * > &startingNodes, std::vector< int > &partOf, std::vector< const IndirectSVFGEdge * > &footprint)
Version getYield(const NodeID l, const NodeID o) const
Returns the yielded version of o at l. If no such version exists, returns invalidVersion.
void dumpLocVersionMaps(void) const
Dumps maps consume and yield.
BVDataPTAImpl::VersionedPTDataTy * vPtD
Points-to DS for working with versions.
LocVersionMap yield
Actual yield map. Yield analogue to consume.
std::vector< bool > isStoreMap
isStoreMap[l] means SVFG node l is a store node.
virtual void updateConnectedNodes(const SVFGEdgeSetTy &newEdges) override
Update nodes connected during updating call graph.
virtual bool processLoad(const LoadSVFGNode *load) override
static bool meld(MeldVersion &mv1, const MeldVersion &mv2)
Melds v2 into v1 (in place), returns whether a change occurred.
VersionRelianceMap versionReliance
o -> (version -> versions which rely on it).
u32_t numPrelabelVersions
Number of versions created during prelabeling.
void removeAllIndirectSVFGEdges(void)
Removes all indirect edges in the SVFG.
Map< NodeID, NodeID > equivalentObject
void readVersionedAnalysisResultFromFile(std::ifstream &F)
virtual void buildDeltaMaps(void)
Fills in deltaMap and deltaSourceMap for the SVFG.
NodeBS & getStmtReliance(const NodeID o, const Version v)
Returns the statements which rely on o:v.
static const Version invalidVersion
If this version appears, there has been an error.
virtual bool deltaSource(const NodeID l) const
double meldLabelingTime
Time to meld label SVFG.
static VersionedFlowSensitive * vfspta
static VersionedVar atKey(NodeID, Version)
Return key into vPtD for address-taken var of a specific version.
Version getVersion(const NodeID l, const NodeID o, const LocVersionMap &lvm) const
Shared code for getConsume and getYield. They wrap this function.
std::vector< bool > isLoadMap
isLoadMap[l] means SVFG node l is a load node.
virtual const std::string PTAName() const override
Get PTA name.
static void releaseVFSWPA()
Release flow-sensitive pointer analysis.
static void dumpMeldVersion(MeldVersion &v)
Dumps a MeldVersion to stdout.
double prelabelingTime
Time to prelabel SVFG.
void propagateVersion(NodeID o, Version v)
void prelabel(void)
Prelabel the SVFG: set y(o) for stores and c(o) for delta nodes to a new version.
virtual void initialize() override
Initialize analysis.
virtual void processNode(NodeID n) override
Handle various constraints.
virtual void buildIsStoreLoadMaps(void)
Fills in isStoreMap and isLoadMap.
static VersionedFlowSensitive * createVFSWPA(SVFIR *_pag)
Create single instance of versioned flow-sensitive points-to analysis.
virtual bool isLoad(const NodeID l) const
Returns true if l is a load node.
void dumpReliances(void) const
Dumps versionReliance and stmtReliance.
Map< VersionedVar, const DummyVersionPropSVFGNode * > VarToPropNodeMap
virtual bool delta(const NodeID l) const
std::vector< ObjToVersionMap > LocVersionMap
virtual bool processStore(const StoreSVFGNode *store) override
void setConsume(const NodeID l, const NodeID o, const Version v)
Sets the consumed version of o at l to v.
virtual bool isStore(const NodeID l) const
Returns true if l is a store node.
void meldLabel(void)
Meld label the prelabeled SVFG.
void writeVersionedAnalysisResultToFile(const std::string &filename)
static bool classof(const PointerAnalysis *pta)
void setYield(const NodeID l, const NodeID o, const Version v)
Sets the yielded version of o at l to v.
void solveAndwritePtsToFile(const std::string &filename) override
virtual bool propAlongIndirectEdge(const IndirectSVFGEdge *) override
Override to do nothing. Instead, we will use propagateVersion when necessary.
Map< NodeID, Map< Version, std::vector< Version > > > VersionRelianceMap
(o -> (v -> versions with rely on o:v).
virtual void finalize() override
Finalize analysis.
void setVersion(const NodeID l, const NodeID o, const Version v, LocVersionMap &lvm)
Shared code for setConsume and setYield. They wrap this function.
std::vector< Version > & getReliantVersions(const NodeID o, const Version v)
Returns the versions of o which rely on o:v.
void readPtsFromFile(const std::string &filename) override
virtual void cluster(void) override
Override since we want to assign different weights based on versioning.
Map< NodeID, Map< Version, NodeBS > > stmtReliance
o x version -> statement nodes which rely on that o/version.
double versionPropTime
Time to propagate versions to versions which rely on them.
Version getConsume(const NodeID l, const NodeID o) const
Returns the consumed version of o at l. If no such version exists, returns invalidVersion.
Map< NodeID, Version > ObjToVersionMap
static bool classof(const VersionedFlowSensitive *)
Methods to support type inquiry through isa, cast, and dyn_cast.
u32_t numPrelabeledNodes
Additional statistics.
for isBitcode
Definition BasicTypes.h:70
std::pair< NodeID, Version > VersionedVar
PTATY
Pointer analysis type list.
Definition PTATY.h:9
@ VFS_WPA
Versioned sparse flow-sensitive WPA.
Definition PTATY.h:21
u32_t NodeID
Definition GeneralType.h:56
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:76
unsigned Version
unsigned u32_t
Definition GeneralType.h:47