Static Value-Flow Analysis
Loading...
Searching...
No Matches
WPASolver.h
Go to the documentation of this file.
1//===- WPASolver.h -- Generic WPA solver--------------------------------------//
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/*
25 * WPASolver.h
26 *
27 * Created on: Oct 25, 2013
28 * Author: Yulei Sui
29 */
30
31#ifndef GRAPHSOLVER_H_
32#define GRAPHSOLVER_H_
33
34#include "Util/WorkList.h"
35#include "Util/GeneralType.h"
36
37namespace SVF
38{
39
40/*
41 * Generic graph solver for whole program pointer analysis
42 */
43template<class GraphType>
45{
46
47public:
50 typedef typename GTraits::NodeRef GNODE;
51 typedef typename GTraits::EdgeType GEDGE;
52 typedef typename GTraits::ChildIteratorType child_iterator;
53
55
57
58protected:
59
65 virtual ~WPASolver() = default;
66
68 inline SCC* getSCCDetector() const
69 {
70 return scc.get();
71 }
72
74
75 const inline GraphType graph()
76 {
77 return _graph;
78 }
79 inline void setGraph(GraphType g)
80 {
81 _graph = g;
82 scc = std::make_unique<SCC>(_graph);
83 }
85
87 virtual inline NodeStack& SCCDetect()
88 {
89 getSCCDetector()->find();
90 return getSCCDetector()->topoNodeStack();
91 }
92 virtual inline NodeStack& SCCDetect(NodeSet& candidates)
93 {
94 getSCCDetector()->find(candidates);
95 return getSCCDetector()->topoNodeStack();
96 }
97
98 virtual inline void initWorklist()
99 {
100 NodeStack& nodeStack = SCCDetect();
101 while (!nodeStack.empty())
102 {
103 NodeID nodeId = nodeStack.top();
104 nodeStack.pop();
106 }
107 }
108
109 virtual inline void solveWorklist()
110 {
111 while (!isWorklistEmpty())
112 {
114 // Keep solving until workList is empty.
117 }
118 }
119
121
122
123 virtual inline void processNode(NodeID) {}
125 virtual void collapseFields() {}
128 virtual void propagate(GNODE* v)
129 {
130 child_iterator EI = GTraits::direct_child_begin(*v);
131 child_iterator EE = GTraits::direct_child_end(*v);
132 for (; EI != EE; ++EI)
133 {
134 if (propFromSrcToDst(*(EI.getCurrent())))
136 }
137 }
139 virtual bool propFromSrcToDst(GEDGE*)
140 {
141 return false;
142 }
144
145 virtual NodeID sccRepNode(NodeID id) const
146 {
147 return getSCCDetector()->repNode(id);
148 }
149
151
153 {
154 return sccRepNode(worklist.pop());
155 }
156
157 virtual inline void pushIntoWorklist(NodeID id)
158 {
160 }
161 inline bool isWorklistEmpty()
162 {
163 return worklist.empty();
164 }
165 inline bool isInWorklist(NodeID id)
166 {
167 return worklist.find(id);
168 }
170
175
176
178 inline GNODE* Node(NodeID id)
179 {
180 return GTraits::getNode(_graph, id);
181 }
182
185 {
186 return GTraits::getNodeID(node);
187 }
188
189protected:
192
194 std::unique_ptr<SCC> scc;
195
198
199public:
202};
203
204} // End namespace SVF
205
206#endif /* GRAPHSOLVER_H_ */
#define false
Definition cJSON.cpp:70
bool push(const Data &data)
Definition WorkList.h:180
bool empty() const
Definition WorkList.h:161
bool find(const Data &data) const
Definition WorkList.h:172
NodeID Node_Index(GNODE node)
Get node ID.
Definition WPASolver.h:184
bool isInWorklist(NodeID id)
Definition WPASolver.h:165
WPASolver()
Constructor.
Definition WPASolver.h:61
SCCDetection< GraphType > SCC
Definition WPASolver.h:54
WorkList worklist
Worklist for resolution.
Definition WPASolver.h:197
std::unique_ptr< SCC > scc
SCC.
Definition WPASolver.h:194
NodeID popFromWorklist()
Worklist operations.
Definition WPASolver.h:152
GNODE * Node(NodeID id)
Get node on the graph.
Definition WPASolver.h:178
GTraits::NodeRef GNODE
Definition WPASolver.h:50
SCC * getSCCDetector() const
Get SCC detector.
Definition WPASolver.h:68
virtual NodeID sccRepNode(NodeID id) const
Definition WPASolver.h:145
virtual void pushIntoWorklist(NodeID id)
Definition WPASolver.h:157
GTraits::ChildIteratorType child_iterator
Definition WPASolver.h:52
virtual void propagate(GNODE *v)
Definition WPASolver.h:128
FIFOWorkList< NodeID > WorkList
Definition WPASolver.h:56
SVF::GenericGraphTraits< GraphType > GTraits
Define the GTraits and node iterator for printing.
Definition WPASolver.h:49
virtual NodeStack & SCCDetect(NodeSet &candidates)
Definition WPASolver.h:92
virtual void initWorklist()
Definition WPASolver.h:98
virtual void collapseFields()
collapse positive weight cycles of a graph
Definition WPASolver.h:125
GraphType _graph
Graph.
Definition WPASolver.h:191
virtual bool propFromSrcToDst(GEDGE *)
Propagate information from source to destination node, to be implemented in the child class.
Definition WPASolver.h:139
bool isWorklistEmpty()
Definition WPASolver.h:161
virtual ~WPASolver()=default
Destructor.
void setGraph(GraphType g)
Definition WPASolver.h:79
virtual NodeStack & SCCDetect()
SCC detection.
Definition WPASolver.h:87
u32_t iterationForPrintStat
print out statistics for i-th iteration
Definition WPASolver.h:174
u32_t numOfIteration
num of iterations during constraint solving
Definition WPASolver.h:201
GTraits::EdgeType GEDGE
Definition WPASolver.h:51
virtual void processNode(NodeID)
Following methods are to be implemented in child class, in order to achieve a fully worked PTA.
Definition WPASolver.h:123
const GraphType graph()
Get/Set graph methods.
Definition WPASolver.h:75
bool reanalyze
Reanalyze if any constraint value changed.
Definition WPASolver.h:172
virtual void solveWorklist()
Definition WPASolver.h:109
for isBitcode
Definition BasicTypes.h:70
std::stack< NodeID > NodeStack
Definition GeneralType.h:92
Set< NodeID > NodeSet
Definition GeneralType.h:87
u32_t NodeID
Definition GeneralType.h:76
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:76
unsigned u32_t
Definition GeneralType.h:67
typename GraphType::UnknownGraphTypeError NodeRef
Definition GraphTraits.h:80