Static Value-Flow Analysis
Loading...
Searching...
No Matches
GraphReachSolver.h
Go to the documentation of this file.
1//===- GraphReachSolver.h -- Generic graph reachability 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 * GraphReachSolver.h
25 *
26 * Created on: Apr 1, 2014
27 * Author: Yulei Sui
28 */
29
30#ifndef CFLSOLVER_H_
31#define CFLSOLVER_H_
32
33#include "Util/WorkList.h"
34#include "Util/DPItem.h"
35
36namespace SVF
37{
38
39/*
40 * Generic Graph Reachability solver for demand-driven analysis based on different graphs (e.g. SVFIR, VFG, ThreadVFG)
41 * Extend this class for sophisticated CFL-reachability resolution (e.g. field, flow, path)
42 */
43template<class GraphType, class DPIm = DPItem>
45{
46
47public:
50 typedef typename GTraits::NodeType GNODE;
51 typedef typename GTraits::EdgeType GEDGE;
52 typedef typename GTraits::nodes_iterator node_iterator;
53 typedef typename GTraits::ChildIteratorType child_iterator;
54
57 typedef typename InvGTraits::ChildIteratorType inv_child_iterator;
58
61
62protected:
63
70 {
71 }
73
74 const inline GraphType graph() const
75 {
76 return _graph;
77 }
78 inline void setGraph(GraphType g)
79 {
80 _graph = g;
81 }
83
84 inline GNODE* getNode(NodeID id) const
85 {
86 return _graph->getGNode(id);
87 }
88 virtual inline NodeID getNodeIDFromItem(const DPIm& item) const
89 {
90 return item.getCurNodeID();
91 }
93 virtual void forwardTraverse(DPIm& it)
94 {
96
97 while (!isWorklistEmpty())
98 {
99 DPIm item = popFromWorklist();
101
103 child_iterator EI = GTraits::child_begin(v);
104 child_iterator EE = GTraits::child_end(v);
105 for (; EI != EE; ++EI)
106 {
107 FWProcessOutgoingEdge(item,*(EI.getCurrent()) );
108 }
109 }
110 }
112 virtual void backwardTraverse(DPIm& it)
113 {
115
116 while (!isWorklistEmpty())
117 {
118 DPIm item = popFromWorklist();
120
122 inv_child_iterator EI = InvGTraits::child_begin(v);
123 inv_child_iterator EE = InvGTraits::child_end(v);
124 for (; EI != EE; ++EI)
125 {
126 BWProcessIncomingEdge(item,*(EI.getCurrent()) );
127 }
128 }
129 }
131
132 virtual void FWProcessCurNode(const DPIm&)
133 {
134 }
135 virtual void BWProcessCurNode(const DPIm&)
136 {
137 }
139
141 virtual void FWProcessOutgoingEdge(const DPIm& item, GEDGE* edge)
142 {
143 DPIm newItem(item);
144 newItem.setCurNodeID(edge->getDstID());
146 }
147 virtual void BWProcessIncomingEdge(const DPIm& item, GEDGE* edge)
148 {
149 DPIm newItem(item);
150 newItem.setCurNodeID(edge->getSrcID());
152 }
154
156 inline DPIm popFromWorklist()
157 {
158 return worklist.pop();
159 }
160 inline bool pushIntoWorklist(DPIm& item)
161 {
162 return worklist.push(item);
163 }
164 inline bool isWorklistEmpty()
165 {
166 return worklist.empty();
167 }
168 inline bool isInWorklist(DPIm& item)
169 {
170 return worklist.find(item);
171 }
173
174private:
175
177 GraphType _graph;
178
181
182};
183
184} // End namespace SVF
185
186#endif /* CFLSOLVER_H_ */
cJSON * item
Definition cJSON.h:222
void setGraph(GraphType g)
DPIm popFromWorklist()
Worklist operations.
virtual ~GraphReachSolver()
Destructor.
virtual void FWProcessOutgoingEdge(const DPIm &item, GEDGE *edge)
Propagation for the solving, to be implemented in the child class.
InvGTraits::ChildIteratorType inv_child_iterator
bool isInWorklist(DPIm &item)
FIFOWorkList< DPIm > WorkList
Define worklist.
GTraits::nodes_iterator node_iterator
WorkList worklist
Worklist for resolution.
bool pushIntoWorklist(DPIm &item)
virtual void BWProcessCurNode(const DPIm &)
virtual void FWProcessCurNode(const DPIm &)
Process the DP item.
SVF::GenericGraphTraits< GraphType > GTraits
Define the GTraits and node iterator.
GraphReachSolver()
Constructor.
virtual NodeID getNodeIDFromItem(const DPIm &item) const
virtual void backwardTraverse(DPIm &it)
CFL forward traverse solve.
const GraphType graph() const
Get/Set graph methods.
GTraits::EdgeType GEDGE
virtual void BWProcessIncomingEdge(const DPIm &item, GEDGE *edge)
GNODE * getNode(NodeID id) const
virtual void forwardTraverse(DPIm &it)
CFL forward traverse solve.
GTraits::ChildIteratorType child_iterator
GTraits::NodeType GNODE
SVF::GenericGraphTraits< SVF::Inverse< GNODE * > > InvGTraits
Define inverse GTraits and note iterator.
for isBitcode
Definition BasicTypes.h:68
u32_t NodeID
Definition GeneralType.h:55
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:74