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/SVFG.h"
18#include "WPA/FlowSensitive.h"
19#include "MemoryModel/PTATY.h"
20
21namespace SVF
22{
23
25
30{
32
33private:
35
36public:
39
40 typedef std::vector<ObjToVersionMap> LocVersionMap;
43
45 static const Version invalidVersion;
46
49
52
54 virtual void initialize() override;
55
57 virtual void finalize() override;
58
60 virtual const std::string PTAName() const override
61 {
62 return "VersionedFlowSensitive";
63 }
64
66
67 static inline bool classof(const VersionedFlowSensitive *)
68 {
69 return true;
70 }
71 static inline bool classof(const PointerAnalysis *pta)
72 {
73 return pta->getAnalysisTy() == PTATY::VFS_WPA;
74 }
75
76
79 {
80 if (vfspta == nullptr)
81 {
83 vfspta->analyze();
84 }
85
86 return vfspta;
87 }
88
90 static void releaseVFSWPA()
91 {
92 if (vfspta) delete vfspta;
93 vfspta = nullptr;
94 }
95
96protected:
97 virtual bool processLoad(const LoadSVFGNode* load) override;
98 virtual bool processStore(const StoreSVFGNode* store) override;
99 virtual void processNode(NodeID n) override;
100 virtual void updateConnectedNodes(const SVFGEdgeSetTy& newEdges) override;
101
103 virtual bool propAlongIndirectEdge(const IndirectSVFGEdge*) override
104 {
105 return false;
106 }
107
109 virtual void cluster(void) override;
110
111public:
113 virtual bool isStore(const NodeID l) const;
114
116 virtual bool isLoad(const NodeID l) const;
117
119 Version getVersion(const NodeID l, const NodeID o, const LocVersionMap &lvm) const;
120
122 Version getConsume(const NodeID l, const NodeID o) const;
123
125 Version getYield(const NodeID l, const NodeID o) const;
126
128 std::vector<Version> &getReliantVersions(const NodeID o, const Version v);
129
131 NodeBS &getStmtReliance(const NodeID o, const Version v);
132
134 void dumpReliances(void) const;
135
137 void dumpLocVersionMaps(void) const;
138
139 void solveAndwritePtsToFile(const std::string& filename) override;
140
141 void writeVersionedAnalysisResultToFile(const std::string& filename);
142
143 void readVersionedAnalysisResultFromFile(std::ifstream& F);
144
145 void readPtsFromFile(const std::string& filename) override;
146
148 static void dumpMeldVersion(MeldVersion &v);
149
150private:
152 void prelabel(void);
154 void meldLabel(void);
156 static bool meld(MeldVersion &mv1, const MeldVersion &mv2);
157
160
165
168 void propagateVersion(const NodeID o, const Version v, const Version vp, bool time=true);
169
171 virtual void buildIsStoreLoadMaps(void);
172
174 virtual void buildDeltaMaps(void);
175
178 virtual bool delta(const NodeID l) const;
179
182 virtual bool deltaSource(const NodeID l) const;
183
185 void setVersion(const NodeID l, const NodeID o, const Version v, LocVersionMap &lvm);
186
188 void setConsume(const NodeID l, const NodeID o, const Version v);
189
191 void setYield(const NodeID l, const NodeID o, const Version v);
192
198
203
207
208 // Maps an object o to o' if o is equivalent to o' with respect to
209 // versioning. Thus, we don't need to store the versions of o and look
210 // up those for o' instead.
212
216
218
221
224 std::vector<bool> deltaMap;
225
229 std::vector<bool> deltaSourceMap;
230
232 std::vector<bool> isStoreMap;
233
235 std::vector<bool> isLoadMap;
236
238
241
246
248
249 class SCC
250 {
251 private:
252 typedef struct NodeData
253 {
254 int index;
258
259 public:
271 static unsigned detectSCCs(VersionedFlowSensitive *vfs,
272 const SVFG *svfg, const NodeID object,
273 const std::vector<const SVFGNode *> &startingNodes,
274 std::vector<int> &partOf,
275 std::vector<const IndirectSVFGEdge *> &footprint);
276
277 private:
279 static void visit(VersionedFlowSensitive *vfs,
280 const NodeID object,
281 std::vector<int> &partOf,
282 std::vector<const IndirectSVFGEdge *> &footprint,
283 std::vector<NodeData> &nodeData,
284 std::stack<const SVFGNode *> &stack,
285 int &index,
286 int &currentSCC,
287 const SVFGNode *v);
288 };
289};
290
291} // End namespace SVF
292
293#endif /* VFS_H_ */
PRIVATE Xlinker stack
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
FlowSensitive(PAG *_pag, PTATY type=PTATY::FSSPARSE_WPA)
Constructor.
SVFG::SVFGEdgeSetTy SVFGEdgeSetTy
Definition PAG.h:46
PTATY getAnalysisTy() const
Type of pointer analysis.
struct SVF::VersionedFlowSensitive::SCC::NodeData NodeData
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 * createVFSWPA(PAG *_pag)
Create single instance of versioned flow-sensitive points-to analysis.
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.
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)
VersionedFlowSensitive(PAG *_pag, PTATY type=PTATY::VFS_WPA)
Constructor.
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
Definition GeneralType.h:99
PTATY
Pointer analysis type list.
Definition PTATY.h:9
@ VFS_WPA
Versioned sparse flow-sensitive WPA.
Definition PTATY.h:21
LoadVFGNode LoadSVFGNode
Definition SVFG.h:54
u32_t NodeID
Definition GeneralType.h:76
std::unordered_set< Key, Hash, KeyEqual, Allocator > Set
Definition GeneralType.h:51
StoreVFGNode StoreSVFGNode
Definition SVFG.h:53
VFGNode SVFGNode
Definition SVFG.h:43
std::unordered_map< Key, Value, Hash, KeyEqual, Allocator > Map
Definition GeneralType.h:56
unsigned Version
Definition GeneralType.h:97
SparseBitVector NodeBS
Definition GeneralType.h:82
unsigned u32_t
Definition GeneralType.h:67