Static Value-Flow Analysis
Loading...
Searching...
No Matches
CallGraph.h
Go to the documentation of this file.
1//===- CallGraph.h -- Call graph representation----------------------------//
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 * CallGraph.h
25 *
26 * Created on: Nov 7, 2013
27 * Author: Yulei Sui
28 */
29
30#ifndef CALLGRAPH_H_
31#define CALLGRAPH_H_
32
33#include "Graphs/GenericGraph.h"
34#include "SVFIR/SVFValue.h"
35#include "Graphs/ICFG.h"
36#include <set>
37
38namespace SVF
39{
40
41class CallGraphNode;
42class SVFModule;
43
44
45/*
46 * Call Graph edge representing a calling relation between two functions
47 * Multiple calls from function A to B are merged into one call edge
48 * Each call edge has a set of direct callsites and a set of indirect callsites
49 */
52{
53
54public:
56
57private:
59public:
62 GenericCallGraphEdgeTy(s, d, icfgNode->getId())
63 {
64 }
67 {
68 }
69
71
72 void addDirectCallSite(const CallICFGNode* call);
74
76
77 inline CallInstSet::const_iterator directCallsBegin() const
78 {
79 return directCalls.begin();
80 }
81 inline CallInstSet::const_iterator directCallsEnd() const
82 {
83 return directCalls.end();
84 }
86
88
89 static inline bool classof(const CallGraphEdge*)
90 {
91 return true;
92 }
94
96
98 {
99 o << edge.toString();
100 return o;
101 }
103
104 virtual const std::string toString() const;
105
107
108};
109
110/*
111 * Call Graph node representing a function
112 */
115{
116private:
118
119public:
124
125 inline const std::string &getName() const
126 {
127 return fun->getName();
128 }
129
131 inline const SVFFunction* getFunction() const
132 {
133 return fun;
134 }
135
136
138
140 {
141 o << node.toString();
142 return o;
143 }
145
146 virtual const std::string toString() const;
147
149
150 static inline bool classof(const CallGraphNode*)
151 {
152 return true;
153 }
154
155 static inline bool classof(const GenericICFGNodeTy* node)
156 {
157 return node->getNodeKind() == CallNodeKd;
158 }
159
160 static inline bool classof(const SVFBaseNode* node)
161 {
162 return node->getNodeKind() == CallNodeKd;
163 }
165};
166
172{
173 friend class PTACallGraph;
174
175public:
181
182protected:
185
187
189 void destroy();
190
193 {
194 edge->getDstNode()->addIncomingEdge(edge);
195 edge->getSrcNode()->addOutgoingEdge(edge);
196 }
197
198
199public:
201 CallGraph();
202
203 void addCallGraphNode(const SVFFunction* fun);
204
205 const CallGraphNode* getCallGraphNode(const std::string& name);
206
208 virtual ~CallGraph()
209 {
210 destroy();
211 }
212
214
216 {
217 return getGNode(id);
218 }
220 {
221 FunToCallGraphNodeMap::const_iterator it = funToCallGraphNodeMap.find(fun);
222 assert(it!=funToCallGraphNodeMap.end() && "call graph node not found!!");
223 return it->second;
224 }
225
227
230 const CallICFGNode* callIcfgNode) const;
231
235 void dump(const std::string& filename);
236
238 void view();
239};
240
241} // End namespace SVF
242
243namespace SVF
244{
245/* !
246 * GenericGraphTraits specializations for generic graph algorithms.
247 * Provide graph traits for traversing from a constraint node using standard graph traversals.
248 */
249template<> struct GenericGraphTraits<SVF::CallGraphNode*> : public GenericGraphTraits<SVF::GenericNode<SVF::CallGraphNode,SVF::CallGraphEdge>* >
250{
251};
252
254template<>
255struct GenericGraphTraits<Inverse<SVF::CallGraphNode*> > : public GenericGraphTraits<Inverse<SVF::GenericNode<SVF::CallGraphNode,SVF::CallGraphEdge>* > >
256{
257};
258
259template<> struct GenericGraphTraits<SVF::CallGraph*> : public GenericGraphTraits<SVF::GenericGraph<SVF::CallGraphNode,SVF::CallGraphEdge>* >
260{
262};
263
264} // End namespace llvm
265
266#endif /* CALLGRAPH_H_ */
const char *const name
Definition cJSON.h:264
static bool classof(const CallGraphEdge *)
ClassOf.
Definition CallGraph.h:89
CallGraphEdge(CallGraphNode *s, CallGraphNode *d, const CallICFGNode *icfgNode)
Constructor.
Definition CallGraph.h:61
void addDirectCallSite(const CallICFGNode *call)
Add direct callsite.
Definition CallGraph.cpp:43
virtual ~CallGraphEdge()
Destructor.
Definition CallGraph.h:66
GenericNode< CallGraphNode, CallGraphEdge >::GEdgeSetTy CallGraphEdgeSet
Definition CallGraph.h:106
virtual const std::string toString() const
Definition CallGraph.cpp:50
CallInstSet::const_iterator directCallsEnd() const
Definition CallGraph.h:81
friend OutStream & operator<<(OutStream &o, const CallGraphEdge &edge)
Overloading operator << for dumping ICFG node ID.
Definition CallGraph.h:97
Set< const CallICFGNode * > CallInstSet
Definition CallGraph.h:55
CallInstSet directCalls
Definition CallGraph.h:58
CallInstSet::const_iterator directCallsBegin() const
Iterators for direct and indirect callsites.
Definition CallGraph.h:77
static bool classof(const GenericICFGNodeTy *node)
Definition CallGraph.h:155
const SVFFunction * fun
Definition CallGraph.h:117
const std::string & getName() const
Definition CallGraph.h:125
CallGraphNode(NodeID i, const SVFFunction *f)
Constructor.
Definition CallGraph.h:121
virtual const std::string toString() const
Definition CallGraph.cpp:60
static bool classof(const SVFBaseNode *node)
Definition CallGraph.h:160
const SVFFunction * getFunction() const
Get function of this call node.
Definition CallGraph.h:131
friend OutStream & operator<<(OutStream &o, const CallGraphNode &node)
Overloading operator << for dumping ICFG node ID.
Definition CallGraph.h:139
static bool classof(const CallGraphNode *)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition CallGraph.h:150
CallInstToCallGraphEdgesMap callinstToCallGraphEdgesMap
Map a call instruction to its corresponding call edges.
Definition CallGraph.h:184
Map< const CallICFGNode *, CallGraphEdgeSet > CallInstToCallGraphEdgesMap
Definition CallGraph.h:178
CallGraph()
Constructor.
Definition CallGraph.cpp:70
Set< const SVFFunction * > FunctionSet
Definition CallGraph.h:179
void addCallGraphNode(const SVFFunction *fun)
Definition CallGraph.cpp:86
void addEdge(CallGraphEdge *edge)
Add call graph edge.
Definition CallGraph.h:192
CallGraphNode * getCallGraphNode(const SVFFunction *fun) const
Definition CallGraph.h:219
Map< const SVFFunction *, CallGraphNode * > FunToCallGraphNodeMap
Definition CallGraph.h:177
NodeID callGraphNodeNum
Definition CallGraph.h:186
void destroy()
Clean up memory.
Definition CallGraph.cpp:79
FunToCallGraphNodeMap funToCallGraphNodeMap
Call Graph node map.
Definition CallGraph.h:183
OrderedMap< const CallICFGNode *, FunctionSet > CallEdgeMap
Definition CallGraph.h:180
CallGraphEdge::CallGraphEdgeSet CallGraphEdgeSet
Definition CallGraph.h:176
CallGraphNode * getCallGraphNode(NodeID id) const
Get call graph node.
Definition CallGraph.h:215
void view()
View the graph from the debugger.
void dump(const std::string &filename)
Dump the graph.
virtual ~CallGraph()
Destructor.
Definition CallGraph.h:208
CallGraphEdge * hasGraphEdge(CallGraphNode *src, CallGraphNode *dst, const CallICFGNode *callIcfgNode) const
Whether we have already created this call graph edge.
Definition CallGraph.cpp:98
void addDirectCallGraphEdge(const CallICFGNode *call, const SVFFunction *callerFun, const SVFFunction *calleeFun)
Add direct call edges.
const CallGraphNode * getCallGraphNode(const std::string &name)
NodeType * getGNode(NodeID id) const
Get a node.
OrderedSet< EdgeType *, typename EdgeType::equalGEdge > GEdgeSetTy
Edge kind.
GNodeK getNodeKind() const
Get node kind.
const std::string & getName() const
Definition SVFValue.h:243
for isBitcode
Definition BasicTypes.h:68
GenericGraph< CallGraphNode, CallGraphEdge > GenericCallGraphTy
Definition CallGraph.h:170
u32_t NodeID
Definition GeneralType.h:55
std::ostream OutStream
Definition GeneralType.h:45
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:74
GenericNode< CallGraphNode, CallGraphEdge > GenericCallGraphNodeTy
Definition CallGraph.h:113
GenericEdge< CallGraphNode > GenericCallGraphEdgeTy
Definition CallGraph.h:50