Static Value-Flow Analysis
Loading...
Searching...
No Matches
SVF::CDG Class Reference

#include <CDG.h>

Inheritance diagram for SVF::CDG:
SVF::GenericGraph< CDGNode, CDGEdge >

Public Types

typedef Map< NodeID, CDGNode * > CDGNodeIDToNodeMapTy
typedef CDGEdge::CDGEdgeSetTy CDGEdgeSetTy
typedef CDGNodeIDToNodeMapTy::iterator iterator
typedef CDGNodeIDToNodeMapTy::const_iterator const_iterator
typedef std::vector< const ICFGNode * > ICFGNodeVector
typedef std::vector< std::pair< const ICFGNode *, const ICFGNode * > > ICFGNodePairVector
Public Types inherited from SVF::GenericGraph< CDGNode, CDGEdge >
typedef CDGNode NodeType
typedef CDGEdge EdgeType
typedef OrderedMap< NodeID, NodeType * > IDToNodeMapTy
 NodeID to GenericNode map.
typedef IDToNodeMapTy::iterator iterator
 Node Iterators.
typedef IDToNodeMapTy::const_iterator const_iterator

Public Member Functions

virtual ~CDG ()
 Destructor.
CDGNode * getCDGNode (NodeID id) const
 Get a CDG node.
bool hasCDGNode (NodeID id) const
 Whether has the CDGNode.
bool hasCDGEdge (CDGNode *src, CDGNode *dst)
 Whether we has a CDG edge.
CDGEdge * getCDGEdge (const CDGNode *src, const CDGNode *dst)
 Get a control dependence edge according to src and dst.
void view ()
 View graph from the debugger.
void dump (const std::string &filename)
 Dump graph into dot file.
void removeCDGEdge (CDGEdge *edge)
 Remove a control dependence edge.
void removeCDGNode (CDGNode *node)
 Remove a CDGNode.
bool removeCDGNode (NodeID id)
 Remove node from nodeID.
bool addCDGEdge (CDGEdge *edge)
 Add CDG edge.
virtual void addCDGNode (CDGNode *node)
 Add a CDG node.
void addCDGNodesFromVector (ICFGNodeVector nodes)
 Add CDG nodes from nodeid vector.
void addCDGEdgeFromSrcDst (const ICFGNode *src, const ICFGNode *dst, const SVFVar *pNode, s32_t branchID)
 Add CDG edges from nodeid pair.
Public Member Functions inherited from SVF::GenericGraph< CDGNode, CDGEdge >
 GenericGraph ()
 Constructor.
virtual ~GenericGraph ()
 Destructor.
void destroy ()
 Release memory.
iterator begin ()
 Iterators.
iterator end ()
const_iterator begin () const
const_iterator end () const
void addGNode (NodeID id, NodeType *node)
 Add a Node.
NodeType * getGNode (NodeID id) const
 Get a node.
bool hasGNode (NodeID id) const
 Has a node.
void removeGNode (NodeType *node)
 Delete a node.
u32_t getTotalNodeNum () const
 Get total number of node/edge.
u32_t getTotalEdgeNum () const
void incNodeNum ()
 Increase number of node/edge.
void incEdgeNum ()

Static Public Member Functions

static CDG * getCDG ()
 Singleton design here to make sure we only have one instance during any analysis.
static void releaseCDG ()

Private Member Functions

 CDG ()
 Constructor.

Static Private Attributes

static CDG * controlDg = nullptr

Additional Inherited Members

Public Attributes inherited from SVF::GenericGraph< CDGNode, CDGEdge >
u32_t edgeNum
 total num of node
u32_t nodeNum
 total num of edge
Protected Attributes inherited from SVF::GenericGraph< CDGNode, CDGEdge >
IDToNodeMapTy IDToNodeMap
 node map

Detailed Description

Definition at line 148 of file CDG.h.

Member Typedef Documentation

◆ CDGEdgeSetTy

Definition at line 154 of file CDG.h.

◆ CDGNodeIDToNodeMapTy

Definition at line 153 of file CDG.h.

◆ const_iterator

typedef CDGNodeIDToNodeMapTy::const_iterator SVF::CDG::const_iterator

Definition at line 156 of file CDG.h.

◆ ICFGNodePairVector

typedef std::vector<std::pair<const ICFGNode *, const ICFGNode *> > SVF::CDG::ICFGNodePairVector

Definition at line 158 of file CDG.h.

◆ ICFGNodeVector

typedef std::vector<const ICFGNode *> SVF::CDG::ICFGNodeVector

Definition at line 157 of file CDG.h.

◆ iterator

typedef CDGNodeIDToNodeMapTy::iterator SVF::CDG::iterator

Definition at line 155 of file CDG.h.

Constructor & Destructor Documentation

◆ CDG()

SVF::CDG::CDG ( )
inlineprivate

Constructor.

Definition at line 163 of file CDG.h.

164 {
165
166 }

◆ ~CDG()

virtual SVF::CDG::~CDG ( )
inlinevirtual

Destructor.

Definition at line 190 of file CDG.h.

190{}

Member Function Documentation

◆ addCDGEdge()

bool SVF::CDG::addCDGEdge ( CDGEdge * edge)
inline

Add CDG edge.

Definition at line 287 of file CDG.h.

288 {
289 bool added1 = edge->getDstNode()->addIncomingEdge(edge);
290 bool added2 = edge->getSrcNode()->addOutgoingEdge(edge);
291 assert(added1 && added2 && "edge not added??");
292 return added1 && added2;
293 }

◆ addCDGEdgeFromSrcDst()

void CDG::addCDGEdgeFromSrcDst ( const ICFGNode * src,
const ICFGNode * dst,
const SVFVar * pNode,
s32_t branchID )

Add CDG edges from nodeid pair.

Definition at line 35 of file CDG.cpp.

36{
37 if (!hasCDGNode(src->getId()))
38 {
39 addGNode(src->getId(), new CDGNode(src));
40 }
41 if (!hasCDGNode(dst->getId()))
42 {
43 addGNode(dst->getId(), new CDGNode(dst));
44 }
45 if (!hasCDGEdge(getCDGNode(src->getId()), getCDGNode(dst->getId())))
46 {
47 CDGEdge *pEdge = new CDGEdge(getCDGNode(src->getId()),
48 getCDGNode(dst->getId()));
49 pEdge->insertBranchCondition(pNode, branchID);
50 addCDGEdge(pEdge);
51 incEdgeNum();
52 }
53 else
54 {
55 CDGEdge *pEdge = getCDGEdge(getCDGNode(src->getId()),
56 getCDGNode(dst->getId()));
57 pEdge->insertBranchCondition(pNode, branchID);
58 }
59}
void insertBranchCondition(const SVFVar *pNode, s32_t branchID)
Definition CDG.h:82
bool hasCDGEdge(CDGNode *src, CDGNode *dst)
Whether we has a CDG edge.
Definition CDG.h:207
CDGEdge * getCDGEdge(const CDGNode *src, const CDGNode *dst)
Get a control dependence edge according to src and dst.
Definition CDG.h:222
bool hasCDGNode(NodeID id) const
Whether has the CDGNode.
Definition CDG.h:201
bool addCDGEdge(CDGEdge *edge)
Add CDG edge.
Definition CDG.h:287
CDGNode * getCDGNode(NodeID id) const
Get a CDG node.
Definition CDG.h:193
void addGNode(NodeID id, NodeType *node)
NodeID getId() const
Get ID.
Definition SVFValue.h:158

◆ addCDGNode()

virtual void SVF::CDG::addCDGNode ( CDGNode * node)
inlinevirtual

Add a CDG node.

Definition at line 296 of file CDG.h.

297 {
298 addGNode(node->getId(), node);
299 }

◆ addCDGNodesFromVector()

void SVF::CDG::addCDGNodesFromVector ( ICFGNodeVector nodes)
inline

Add CDG nodes from nodeid vector.

Definition at line 302 of file CDG.h.

303 {
304 for (const ICFGNode *icfgNode: nodes)
305 {
306 if (!IDToNodeMap.count(icfgNode->getId()))
307 {
308 addGNode(icfgNode->getId(), new CDGNode(icfgNode));
309 }
310 }
311 }
iter_range< typename GenericGraphTraits< GraphType >::nodes_iterator > nodes(const GraphType &G)

◆ dump()

void SVF::CDG::dump ( const std::string & filename)
inline

Dump graph into dot file.

Definition at line 246 of file CDG.h.

247 {
249 }
static void WriteGraphToFile(SVF::OutStream &O, const std::string &GraphName, const GraphType &GT, bool simple=false)
std::ostream & outs()
Overwrite llvm::outs().
Definition SVFUtil.h:58

◆ getCDG()

CDG * SVF::CDG::getCDG ( )
inlinestatic

Singleton design here to make sure we only have one instance during any analysis.

Definition at line 172 of file CDG.h.

173 {
174 if (controlDg == nullptr)
175 {
176 controlDg = new CDG();
177 }
178 return controlDg;
179 }
CDG()
Constructor.
Definition CDG.h:163
static CDG * controlDg
Definition CDG.h:161

◆ getCDGEdge()

CDGEdge * SVF::CDG::getCDGEdge ( const CDGNode * src,
const CDGNode * dst )
inline

Get a control dependence edge according to src and dst.

Definition at line 222 of file CDG.h.

223 {
224 CDGEdge *edge = nullptr;
225 size_t counter = 0;
226 for (CDGEdge::CDGEdgeSetTy::iterator iter = src->OutEdgeBegin();
227 iter != src->OutEdgeEnd(); ++iter)
228 {
229 if ((*iter)->getDstID() == dst->getId())
230 {
231 counter++;
232 edge = (*iter);
233 }
234 }
235 assert(counter <= 1 && "there's more than one edge between two CDG nodes");
236 return edge;
237 }

◆ getCDGNode()

CDGNode * SVF::CDG::getCDGNode ( NodeID id) const
inline

Get a CDG node.

Definition at line 193 of file CDG.h.

194 {
195 if (!hasCDGNode(id))
196 return nullptr;
197 return getGNode(id);
198 }
NodeType * getGNode(NodeID id) const

◆ hasCDGEdge()

bool SVF::CDG::hasCDGEdge ( CDGNode * src,
CDGNode * dst )
inline

Whether we has a CDG edge.

Definition at line 207 of file CDG.h.

208 {
209 CDGEdge edge(src, dst);
210 CDGEdge *outEdge = src->hasOutgoingEdge(&edge);
211 CDGEdge *inEdge = dst->hasIncomingEdge(&edge);
212 if (outEdge && inEdge)
213 {
214 assert(outEdge == inEdge && "edges not match");
215 return true;
216 }
217 else
218 return false;
219 }

◆ hasCDGNode()

bool SVF::CDG::hasCDGNode ( NodeID id) const
inline

Whether has the CDGNode.

Definition at line 201 of file CDG.h.

202 {
203 return hasGNode(id);
204 }

◆ releaseCDG()

void SVF::CDG::releaseCDG ( )
inlinestatic

Definition at line 181 of file CDG.h.

182 {
183 if (controlDg)
184 delete controlDg;
185 controlDg = nullptr;
186 }

◆ removeCDGEdge()

void SVF::CDG::removeCDGEdge ( CDGEdge * edge)
inline

Remove a control dependence edge.

Definition at line 253 of file CDG.h.

254 {
255 edge->getDstNode()->removeIncomingEdge(edge);
256 edge->getSrcNode()->removeOutgoingEdge(edge);
257 delete edge;
258 }

◆ removeCDGNode() [1/2]

void SVF::CDG::removeCDGNode ( CDGNode * node)
inline

Remove a CDGNode.

Definition at line 261 of file CDG.h.

262 {
263 std::set<CDGEdge *> temp;
264 for (CDGEdge *e: node->getInEdges())
265 temp.insert(e);
266 for (CDGEdge *e: node->getOutEdges())
267 temp.insert(e);
268 for (CDGEdge *e: temp)
269 {
270 removeCDGEdge(e);
271 }
272 removeGNode(node);
273 }
void removeCDGEdge(CDGEdge *edge)
Remove a control dependence edge.
Definition CDG.h:253

◆ removeCDGNode() [2/2]

bool SVF::CDG::removeCDGNode ( NodeID id)
inline

Remove node from nodeID.

Definition at line 276 of file CDG.h.

277 {
278 if (hasCDGNode(id))
279 {
281 return true;
282 }
283 return false;
284 }
void removeCDGNode(CDGNode *node)
Remove a CDGNode.
Definition CDG.h:261

◆ view()

void SVF::CDG::view ( )
inline

View graph from the debugger.

Definition at line 240 of file CDG.h.

241 {
242 SVF::ViewGraph(this, "Control Dependence Graph");
243 }
void ViewGraph(const GraphType &G, const std::string &name, bool ShortNames=false, GraphProgram::Name Program=GraphProgram::DOT)

Member Data Documentation

◆ controlDg

CDG * CDG::controlDg = nullptr
staticprivate

Singleton pattern here

Definition at line 161 of file CDG.h.


The documentation for this class was generated from the following files: