Static Value-Flow Analysis
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. More...
 
typedef IDToNodeMapTy::iterator iterator
 Node Iterators. More...
 
typedef IDToNodeMapTy::const_iterator const_iterator
 

Public Member Functions

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

Static Public Member Functions

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

Private Member Functions

 CDG ()
 Constructor. More...
 

Static Private Attributes

static CDGcontrolDg = nullptr
 

Additional Inherited Members

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

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

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

Definition at line 152 of file CDG.h.

◆ ICFGNodeVector

typedef std::vector<const ICFGNode *> SVF::CDG::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  }

◆ 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:76
bool hasCDGEdge(CDGNode *src, CDGNode *dst)
Whether we has a CDG edge.
Definition: CDG.h:201
CDGNode * getCDGNode(NodeID id) const
Get a CDG node.
Definition: CDG.h:187
bool hasCDGNode(NodeID id) const
Whether has the CDGNode.
Definition: CDG.h:195
bool addCDGEdge(CDGEdge *edge)
Add CDG edge.
Definition: CDG.h:281
CDGEdge * getCDGEdge(const CDGNode *src, const CDGNode *dst)
Get a control dependence edge according to src and dst.
Definition: CDG.h:216
void addGNode(NodeID id, NodeType *node)
Add a Node.
Definition: GenericGraph.h:646
NodeID getId() const
Get ID.
Definition: GenericGraph.h:260

◆ 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
Definition: GenericGraph.h:699
iter_range< typename GenericGraphTraits< GraphType >::nodes_iterator > nodes(const GraphType &G)
Definition: GraphTraits.h:111

◆ 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)
Definition: GraphPrinter.h:56
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.
Definition: GenericGraph.h:653

◆ 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.
Definition: GenericGraph.h:661

◆ 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.
Definition: GenericGraph.h:668

◆ 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)
Definition: GraphWriter.h:371

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: