Static Value-Flow Analysis
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Attributes | List of all members
SVF::CDG Class Reference

#include <CDG.h>

Inheritance diagram for SVF::CDG:
SVF::GenericGraph< NodeTy, EdgeTy >

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< NodeTy, EdgeTy >
typedef NodeTy NodeType
 
typedef EdgeTy 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.
 
CDGNodegetCDGNode (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.
 
CDGEdgegetCDGEdge (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< NodeTy, EdgeTy >
 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.
 
NodeTypegetGNode (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 CDGgetCDG ()
 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 CDGcontrolDg = nullptr
 

Additional Inherited Members

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

Detailed Description

Definition at line 142 of file CDG.h.

Member Typedef Documentation

◆ CDGEdgeSetTy

Definition at line 148 of file CDG.h.

◆ CDGNodeIDToNodeMapTy

Definition at line 147 of file CDG.h.

◆ const_iterator

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

Definition at line 150 of file CDG.h.

◆ ICFGNodePairVector

Definition at line 152 of file CDG.h.

◆ ICFGNodeVector

Definition at line 151 of file CDG.h.

◆ iterator

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

Definition at line 149 of file CDG.h.

Constructor & Destructor Documentation

◆ CDG()

SVF::CDG::CDG ( )
inlineprivate

Constructor.

Definition at line 157 of file CDG.h.

158 {
159
160 }

◆ ~CDG()

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

Destructor.

Definition at line 184 of file CDG.h.

184{}

Member Function Documentation

◆ addCDGEdge()

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

Add CDG edge.

Definition at line 281 of file CDG.h.

282 {
283 bool added1 = edge->getDstNode()->addIncomingEdge(edge);
284 bool added2 = edge->getSrcNode()->addOutgoingEdge(edge);
285 assert(added1 && added2 && "edge not added??");
286 return added1 && added2;
287 }
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:74

◆ 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);
51 incEdgeNum();
52 }
53 else
54 {
56 getCDGNode(dst->getId()));
57 pEdge->insertBranchCondition(pNode, branchID);
58 }
59}
bool hasCDGEdge(CDGNode *src, CDGNode *dst)
Whether we has a CDG edge.
Definition CDG.h:201
CDGEdge * getCDGEdge(const CDGNode *src, const CDGNode *dst)
Get a control dependence edge according to src and dst.
Definition CDG.h:216
bool hasCDGNode(NodeID id) const
Whether has the CDGNode.
Definition CDG.h:195
bool addCDGEdge(CDGEdge *edge)
Add CDG edge.
Definition CDG.h:281
CDGNode * getCDGNode(NodeID id) const
Get a CDG node.
Definition CDG.h:187
void addGNode(NodeID id, NodeType *node)
Add a Node.
NodeID getId() const
Get ID.

◆ addCDGNode()

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

Add a CDG node.

Definition at line 290 of file CDG.h.

291 {
292 addGNode(node->getId(), node);
293 }

◆ addCDGNodesFromVector()

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

Add CDG nodes from nodeid vector.

Definition at line 296 of file CDG.h.

297 {
298 for (const ICFGNode *icfgNode: nodes)
299 {
300 if (!IDToNodeMap.count(icfgNode->getId()))
301 {
302 addGNode(icfgNode->getId(), new CDGNode(icfgNode));
303 }
304 }
305 }
IDToNodeMapTy IDToNodeMap
node map
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 240 of file CDG.h.

241 {
243 }
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:50

◆ getCDG()

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

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

Definition at line 166 of file CDG.h.

167 {
168 if (controlDg == nullptr)
169 {
170 controlDg = new CDG();
171 }
172 return controlDg;
173 }
CDG()
Constructor.
Definition CDG.h:157
static CDG * controlDg
Definition CDG.h:155

◆ 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 216 of file CDG.h.

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

◆ getCDGNode()

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

Get a CDG node.

Definition at line 187 of file CDG.h.

188 {
189 if (!hasCDGNode(id))
190 return nullptr;
191 return getGNode(id);
192 }
NodeType * getGNode(NodeID id) const
Get a node.

◆ hasCDGEdge()

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

Whether we has a CDG edge.

Definition at line 201 of file CDG.h.

202 {
203 CDGEdge edge(src, dst);
204 CDGEdge *outEdge = src->hasOutgoingEdge(&edge);
205 CDGEdge *inEdge = dst->hasIncomingEdge(&edge);
206 if (outEdge && inEdge)
207 {
208 assert(outEdge == inEdge && "edges not match");
209 return true;
210 }
211 else
212 return false;
213 }

◆ hasCDGNode()

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

Whether has the CDGNode.

Definition at line 195 of file CDG.h.

196 {
197 return hasGNode(id);
198 }
bool hasGNode(NodeID id) const
Has a node.

◆ releaseCDG()

static void SVF::CDG::releaseCDG ( )
inlinestatic

Definition at line 175 of file CDG.h.

176 {
177 if (controlDg)
178 delete controlDg;
179 controlDg = nullptr;
180 }

◆ removeCDGEdge()

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

Remove a control dependence edge.

Definition at line 247 of file CDG.h.

248 {
249 edge->getDstNode()->removeIncomingEdge(edge);
250 edge->getSrcNode()->removeOutgoingEdge(edge);
251 delete edge;
252 }

◆ removeCDGNode() [1/2]

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

Remove a CDGNode.

Definition at line 255 of file CDG.h.

256 {
257 std::set<CDGEdge *> temp;
258 for (CDGEdge *e: node->getInEdges())
259 temp.insert(e);
260 for (CDGEdge *e: node->getOutEdges())
261 temp.insert(e);
262 for (CDGEdge *e: temp)
263 {
264 removeCDGEdge(e);
265 }
266 removeGNode(node);
267 }
void removeCDGEdge(CDGEdge *edge)
Remove a control dependence edge.
Definition CDG.h:247
void removeGNode(NodeType *node)
Delete a node.

◆ removeCDGNode() [2/2]

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

Remove node from nodeID.

Definition at line 270 of file CDG.h.

271 {
272 if (hasCDGNode(id))
273 {
275 return true;
276 }
277 return false;
278 }
void removeCDGNode(CDGNode *node)
Remove a CDGNode.
Definition CDG.h:255

◆ view()

void SVF::CDG::view ( )
inline

View graph from the debugger.

Definition at line 234 of file CDG.h.

235 {
236 SVF::ViewGraph(this, "Control Dependence Graph");
237 }
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 155 of file CDG.h.


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