Static Value-Flow Analysis
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
SVF::ConstraintGraph Class Reference

#include <ConsG.h>

Inheritance diagram for SVF::ConstraintGraph:
SVF::GenericGraph< ConstraintNode, ConstraintEdge >

Public Types

typedef OrderedMap< NodeID, ConstraintNode * > ConstraintNodeIDToNodeMapTy
 
typedef ConstraintEdge::ConstraintEdgeSetTy::iterator ConstraintNodeIter
 
typedef Map< NodeID, NodeIDNodeToRepMap
 
typedef Map< NodeID, NodeBSNodeToSubsMap
 
typedef FIFOWorkList< NodeIDWorkList
 
- Public Types inherited from SVF::GenericGraph< ConstraintNode, ConstraintEdge >
typedef ConstraintNode NodeType
 
typedef ConstraintEdge 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

 ConstraintGraph (SVFIR *p)
 Constructor. More...
 
virtual ~ConstraintGraph ()
 Destructor. More...
 
ConstraintNodegetConstraintNode (NodeID id) const
 Get/add/remove constraint node. More...
 
void addConstraintNode (ConstraintNode *node, NodeID id)
 
bool hasConstraintNode (NodeID id) const
 
void removeConstraintNode (ConstraintNode *node)
 
bool hasEdge (ConstraintNode *src, ConstraintNode *dst, ConstraintEdge::ConstraintEdgeK kind)
 
ConstraintEdgegetEdge (ConstraintNode *src, ConstraintNode *dst, ConstraintEdge::ConstraintEdgeK kind)
 Get an edge via its src and dst nodes and kind. More...
 
AddrCGEdgeaddAddrCGEdge (NodeID src, NodeID dst)
 Add a SVFIR edge into Edge map. More...
 
CopyCGEdgeaddCopyCGEdge (NodeID src, NodeID dst)
 Add Copy edge. More...
 
NormalGepCGEdgeaddNormalGepCGEdge (NodeID src, NodeID dst, const AccessPath &ap)
 Add Gep edge. More...
 
VariantGepCGEdgeaddVariantGepCGEdge (NodeID src, NodeID dst)
 
LoadCGEdgeaddLoadCGEdge (NodeID src, NodeID dst)
 Add Load edge. More...
 
StoreCGEdgeaddStoreCGEdge (NodeID src, NodeID dst)
 Add Store edge. More...
 
ConstraintEdge::ConstraintEdgeSetTygetAddrCGEdges ()
 Get SVFIR edge. More...
 
ConstraintEdge::ConstraintEdgeSetTygetDirectCGEdges ()
 Get Copy/call/ret/gep edges. More...
 
ConstraintEdge::ConstraintEdgeSetTygetLoadCGEdges ()
 Get Load edges. More...
 
ConstraintEdge::ConstraintEdgeSetTygetStoreCGEdges ()
 Get Store edges. More...
 
void reTargetDstOfEdge (ConstraintEdge *edge, ConstraintNode *newDstNode)
 Used for cycle elimination. More...
 
void reTargetSrcOfEdge (ConstraintEdge *edge, ConstraintNode *newSrcNode)
 Remove edge from old src target, change edge dst id and add modified edge into new src. More...
 
void removeAddrEdge (AddrCGEdge *edge)
 Remove addr edge from their src and dst edge sets. More...
 
void removeDirectEdge (ConstraintEdge *edge)
 Remove direct edge from their src and dst edge sets. More...
 
void removeLoadEdge (LoadCGEdge *edge)
 Remove load edge from their src and dst edge sets. More...
 
void removeStoreEdge (StoreCGEdge *edge)
 Remove store edge from their src and dst edge sets. More...
 
NodeID sccRepNode (NodeID id) const
 SCC rep/sub nodes methods. More...
 
NodeBSsccSubNodes (NodeID id)
 
void setRep (NodeID node, NodeID rep)
 
void setSubs (NodeID node, NodeBS &subs)
 
void resetSubs (NodeID node)
 
NodeBSgetSubs (NodeID node)
 
NodeID getRep (NodeID node)
 
void resetRep (NodeID node)
 
bool moveInEdgesToRepNode (ConstraintNode *node, ConstraintNode *rep)
 
bool moveOutEdgesToRepNode (ConstraintNode *node, ConstraintNode *rep)
 
bool moveEdgesToRepNode (ConstraintNode *node, ConstraintNode *rep)
 
bool isZeroOffsettedGepCGEdge (ConstraintEdge *edge) const
 Check if a given edge is a NormalGepCGEdge with 0 offset. More...
 
const SVFIR::CallSiteToFunPtrMapgetIndirectCallsites () const
 Wrappers for invoking SVFIR methods. More...
 
NodeID getBlackHoleNode ()
 
bool isBlkObjOrConstantObj (NodeID id)
 
NodeBSgetAllFieldsObjVars (NodeID id)
 
NodeID getBaseObjVar (NodeID id)
 
bool isSingleFieldObj (NodeID id) const
 
NodeID getGepObjVar (NodeID id, const APOffset &apOffset)
 Get a field of a memory object. More...
 
NodeID getFIObjVar (NodeID id)
 Get a field-insensitive node of a memory object. More...
 
bool isPWCNode (NodeID nodeId)
 Check/Set PWC (positive weight cycle) flag. More...
 
void setPWCNode (NodeID nodeId)
 
bool hasNodesToBeCollapsed () const
 Add/get nodes to be collapsed. More...
 
void addNodeToBeCollapsed (NodeID id)
 
NodeID getNextCollapseNode ()
 
void dump (std::string name)
 Dump graph into dot file. More...
 
void print ()
 Print CG into terminal. More...
 
void view ()
 View graph from the debugger. More...
 
- Public Member Functions inherited from SVF::GenericGraph< ConstraintNode, ConstraintEdge >
 GenericGraph ()
 Constructor. More...
 
virtual ~GenericGraph ()
 Destructor. More...
 
void destroy ()
 Release memory. More...
 
iterator begin ()
 Iterators. More...
 
const_iterator begin () const
 
iterator end ()
 
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 ()
 

Protected Member Functions

void buildCG ()
 
void destroy ()
 
void clearSolitaries ()
 
SVFStmt::SVFStmtSetTygetPAGEdgeSet (SVFStmt::PEDGEK kind)
 
NodeID getValueNode (const SVFValue *value) const
 Wrappers used internally, not expose to Andersen Pass. More...
 
NodeID getReturnNode (const SVFFunction *value) const
 
NodeID getVarargNode (const SVFFunction *value) const
 

Protected Attributes

SVFIRpag
 
NodeToRepMap nodeToRepMap
 
NodeToSubsMap nodeToSubsMap
 
WorkList nodesToBeCollapsed
 
EdgeID edgeIndex
 
ConstraintEdge::ConstraintEdgeSetTy AddrCGEdgeSet
 
ConstraintEdge::ConstraintEdgeSetTy directEdgeSet
 
ConstraintEdge::ConstraintEdgeSetTy LoadCGEdgeSet
 
ConstraintEdge::ConstraintEdgeSetTy StoreCGEdgeSet
 
- Protected Attributes inherited from SVF::GenericGraph< ConstraintNode, ConstraintEdge >
IDToNodeMapTy IDToNodeMap
 node map More...
 

Additional Inherited Members

- Public Attributes inherited from SVF::GenericGraph< ConstraintNode, ConstraintEdge >
u32_t edgeNum
 total num of node More...
 
u32_t nodeNum
 total num of edge More...
 

Detailed Description

Constraint graph for Andersen's analysis ConstraintNodes are same as PAGNodes ConstraintEdges are self-defined edges (initialized with ConstraintEdges)

Definition at line 44 of file ConsG.h.

Member Typedef Documentation

◆ ConstraintNodeIDToNodeMapTy

Definition at line 48 of file ConsG.h.

◆ ConstraintNodeIter

typedef ConstraintEdge::ConstraintEdgeSetTy::iterator SVF::ConstraintGraph::ConstraintNodeIter

Definition at line 49 of file ConsG.h.

◆ NodeToRepMap

Definition at line 50 of file ConsG.h.

◆ NodeToSubsMap

Definition at line 51 of file ConsG.h.

◆ WorkList

Definition at line 52 of file ConsG.h.

Constructor & Destructor Documentation

◆ ConstraintGraph()

SVF::ConstraintGraph::ConstraintGraph ( SVFIR p)
inline

Constructor.

Definition at line 97 of file ConsG.h.

97  : pag(p), edgeIndex(0)
98  {
99  buildCG();
100  }
cJSON * p
Definition: cJSON.cpp:2559
EdgeID edgeIndex
Definition: ConsG.h:59

◆ ~ConstraintGraph()

virtual SVF::ConstraintGraph::~ConstraintGraph ( )
inlinevirtual

Destructor.

Definition at line 102 of file ConsG.h.

103  {
104  destroy();
105  }

Member Function Documentation

◆ addAddrCGEdge()

AddrCGEdge * ConstraintGraph::addAddrCGEdge ( NodeID  src,
NodeID  dst 
)

Add a SVFIR edge into Edge map.

Add Address edge

Add an address edge

Definition at line 202 of file ConsG.cpp.

203 {
204  ConstraintNode* srcNode = getConstraintNode(src);
205  ConstraintNode* dstNode = getConstraintNode(dst);
206  if (hasEdge(srcNode, dstNode, ConstraintEdge::Addr))
207  return nullptr;
208  AddrCGEdge* edge = new AddrCGEdge(srcNode, dstNode, edgeIndex++);
209 
210  bool inserted = AddrCGEdgeSet.insert(edge).second;
211  (void)inserted; // Suppress warning of unused variable under release build
212  assert(inserted && "new AddrCGEdge not added??");
213 
214  srcNode->addOutgoingAddrEdge(edge);
215  dstNode->addIncomingAddrEdge(edge);
216  return edge;
217 }
ConstraintNode * getConstraintNode(NodeID id) const
Get/add/remove constraint node.
Definition: ConsG.h:109
ConstraintEdge::ConstraintEdgeSetTy AddrCGEdgeSet
Definition: ConsG.h:61
bool hasEdge(ConstraintNode *src, ConstraintNode *dst, ConstraintEdge::ConstraintEdgeK kind)
Definition: ConsG.h:130
void addIncomingAddrEdge(AddrCGEdge *inEdge)
Definition: ConsGNode.h:247
void addOutgoingAddrEdge(AddrCGEdge *outEdge)
Definition: ConsGNode.h:271

◆ addConstraintNode()

void SVF::ConstraintGraph::addConstraintNode ( ConstraintNode node,
NodeID  id 
)
inline

Definition at line 114 of file ConsG.h.

115  {
116  addGNode(id,node);
117  }
void addGNode(NodeID id, NodeType *node)
Add a Node.
Definition: GenericGraph.h:646

◆ addCopyCGEdge()

CopyCGEdge * ConstraintGraph::addCopyCGEdge ( NodeID  src,
NodeID  dst 
)

Add Copy edge.

Add Copy edge

Definition at line 222 of file ConsG.cpp.

223 {
224 
225  ConstraintNode* srcNode = getConstraintNode(src);
226  ConstraintNode* dstNode = getConstraintNode(dst);
227  if (hasEdge(srcNode, dstNode, ConstraintEdge::Copy) || srcNode == dstNode)
228  return nullptr;
229 
230  CopyCGEdge* edge = new CopyCGEdge(srcNode, dstNode, edgeIndex++);
231 
232  bool inserted = directEdgeSet.insert(edge).second;
233  (void)inserted; // Suppress warning of unused variable under release build
234  assert(inserted && "new CopyCGEdge not added??");
235 
236  srcNode->addOutgoingCopyEdge(edge);
237  dstNode->addIncomingCopyEdge(edge);
238  return edge;
239 }
ConstraintEdge::ConstraintEdgeSetTy directEdgeSet
Definition: ConsG.h:62
void addOutgoingCopyEdge(CopyCGEdge *outEdge)
Definition: ConsGNode.h:237
void addIncomingCopyEdge(CopyCGEdge *inEdge)
Add constraint graph edges.
Definition: ConsGNode.h:227

◆ addLoadCGEdge()

LoadCGEdge * ConstraintGraph::addLoadCGEdge ( NodeID  src,
NodeID  dst 
)

Add Load edge.

Add Load edge

Definition at line 288 of file ConsG.cpp.

289 {
290  ConstraintNode* srcNode = getConstraintNode(src);
291  ConstraintNode* dstNode = getConstraintNode(dst);
292  if (hasEdge(srcNode, dstNode, ConstraintEdge::Load))
293  return nullptr;
294 
295  LoadCGEdge* edge = new LoadCGEdge(srcNode, dstNode, edgeIndex++);
296 
297  bool inserted = LoadCGEdgeSet.insert(edge).second;
298  (void)inserted; // Suppress warning of unused variable under release build
299  assert(inserted && "new LoadCGEdge not added??");
300 
301  srcNode->addOutgoingLoadEdge(edge);
302  dstNode->addIncomingLoadEdge(edge);
303  return edge;
304 }
ConstraintEdge::ConstraintEdgeSetTy LoadCGEdgeSet
Definition: ConsG.h:63
void addIncomingLoadEdge(LoadCGEdge *inEdge)
Definition: ConsGNode.h:252
bool addOutgoingLoadEdge(LoadCGEdge *outEdge)
Definition: ConsGNode.h:276

◆ addNodeToBeCollapsed()

void SVF::ConstraintGraph::addNodeToBeCollapsed ( NodeID  id)
inline

Definition at line 366 of file ConsG.h.

367  {
369  }
WorkList nodesToBeCollapsed
Definition: ConsG.h:58
bool push(const Data &data)
Definition: WorkList.h:165

◆ addNormalGepCGEdge()

NormalGepCGEdge * ConstraintGraph::addNormalGepCGEdge ( NodeID  src,
NodeID  dst,
const AccessPath ap 
)

Add Gep edge.

Add Gep edge

Definition at line 245 of file ConsG.cpp.

246 {
247  ConstraintNode* srcNode = getConstraintNode(src);
248  ConstraintNode* dstNode = getConstraintNode(dst);
249  if (hasEdge(srcNode, dstNode, ConstraintEdge::NormalGep))
250  return nullptr;
251 
252  NormalGepCGEdge* edge =
253  new NormalGepCGEdge(srcNode, dstNode, ap, edgeIndex++);
254 
255  bool inserted = directEdgeSet.insert(edge).second;
256  (void)inserted; // Suppress warning of unused variable under release build
257  assert(inserted && "new NormalGepCGEdge not added??");
258 
259  srcNode->addOutgoingGepEdge(edge);
260  dstNode->addIncomingGepEdge(edge);
261  return edge;
262 }
void addIncomingGepEdge(GepCGEdge *inEdge)
Definition: ConsGNode.h:232
void addOutgoingGepEdge(GepCGEdge *outEdge)
Definition: ConsGNode.h:242

◆ addStoreCGEdge()

StoreCGEdge * ConstraintGraph::addStoreCGEdge ( NodeID  src,
NodeID  dst 
)

Add Store edge.

Add Store edge

Definition at line 309 of file ConsG.cpp.

310 {
311  ConstraintNode* srcNode = getConstraintNode(src);
312  ConstraintNode* dstNode = getConstraintNode(dst);
313  if (hasEdge(srcNode, dstNode, ConstraintEdge::Store))
314  return nullptr;
315 
316  StoreCGEdge* edge = new StoreCGEdge(srcNode, dstNode, edgeIndex++);
317 
318  bool inserted = StoreCGEdgeSet.insert(edge).second;
319  (void)inserted; // Suppress warning of unused variable under release build
320  assert(inserted && "new StoreCGEdge not added??");
321 
322  srcNode->addOutgoingStoreEdge(edge);
323  dstNode->addIncomingStoreEdge(edge);
324  return edge;
325 }
ConstraintEdge::ConstraintEdgeSetTy StoreCGEdgeSet
Definition: ConsG.h:64
bool addOutgoingStoreEdge(StoreCGEdge *outEdge)
Definition: ConsGNode.h:284
void addIncomingStoreEdge(StoreCGEdge *inEdge)
Definition: ConsGNode.h:257

◆ addVariantGepCGEdge()

VariantGepCGEdge * ConstraintGraph::addVariantGepCGEdge ( NodeID  src,
NodeID  dst 
)

Add variant gep edge

Definition at line 267 of file ConsG.cpp.

268 {
269  ConstraintNode* srcNode = getConstraintNode(src);
270  ConstraintNode* dstNode = getConstraintNode(dst);
271  if (hasEdge(srcNode, dstNode, ConstraintEdge::VariantGep))
272  return nullptr;
273 
274  VariantGepCGEdge* edge = new VariantGepCGEdge(srcNode, dstNode, edgeIndex++);
275 
276  bool inserted = directEdgeSet.insert(edge).second;
277  (void)inserted; // Suppress warning of unused variable under release build
278  assert(inserted && "new VariantGepCGEdge not added??");
279 
280  srcNode->addOutgoingGepEdge(edge);
281  dstNode->addIncomingGepEdge(edge);
282  return edge;
283 }

◆ buildCG()

void ConstraintGraph::buildCG ( )
protected

Start building constraint graph

Definition at line 40 of file ConsG.cpp.

41 {
42 
43  // initialize nodes
44  for(SVFIR::iterator it = pag->begin(), eit = pag->end(); it!=eit; ++it)
45  {
46  addConstraintNode(new ConstraintNode(it->first), it->first);
47  }
48 
49  // initialize edges
51  for (SVFStmt::SVFStmtSetTy::iterator iter = addrs.begin(), eiter =
52  addrs.end(); iter != eiter; ++iter)
53  {
54  const AddrStmt* edge = SVFUtil::cast<AddrStmt>(*iter);
55  addAddrCGEdge(edge->getRHSVarID(),edge->getLHSVarID());
56  }
57 
59  for (SVFStmt::SVFStmtSetTy::iterator iter = copys.begin(), eiter =
60  copys.end(); iter != eiter; ++iter)
61  {
62  const CopyStmt* edge = SVFUtil::cast<CopyStmt>(*iter);
63  if(edge->isBitCast() || edge->isValueCopy())
64  addCopyCGEdge(edge->getRHSVarID(),edge->getLHSVarID());
65  }
66 
68  for (SVFStmt::SVFStmtSetTy::iterator iter = phis.begin(), eiter =
69  phis.end(); iter != eiter; ++iter)
70  {
71  const PhiStmt* edge = SVFUtil::cast<PhiStmt>(*iter);
72  for(const auto opVar : edge->getOpndVars())
73  addCopyCGEdge(opVar->getId(),edge->getResID());
74  }
75 
77  for (SVFStmt::SVFStmtSetTy::iterator iter = selects.begin(), eiter =
78  selects.end(); iter != eiter; ++iter)
79  {
80  const SelectStmt* edge = SVFUtil::cast<SelectStmt>(*iter);
81  for(const auto opVar : edge->getOpndVars())
82  addCopyCGEdge(opVar->getId(),edge->getResID());
83  }
84 
86  for (SVFStmt::SVFStmtSetTy::iterator iter = calls.begin(), eiter =
87  calls.end(); iter != eiter; ++iter)
88  {
89  const CallPE* edge = SVFUtil::cast<CallPE>(*iter);
90  addCopyCGEdge(edge->getRHSVarID(),edge->getLHSVarID());
91  }
92 
94  for (SVFStmt::SVFStmtSetTy::iterator iter = rets.begin(), eiter =
95  rets.end(); iter != eiter; ++iter)
96  {
97  const RetPE* edge = SVFUtil::cast<RetPE>(*iter);
98  addCopyCGEdge(edge->getRHSVarID(),edge->getLHSVarID());
99  }
100 
102  for (SVFStmt::SVFStmtSetTy::iterator iter = tdfks.begin(), eiter =
103  tdfks.end(); iter != eiter; ++iter)
104  {
105  const TDForkPE* edge = SVFUtil::cast<TDForkPE>(*iter);
106  addCopyCGEdge(edge->getRHSVarID(),edge->getLHSVarID());
107  }
108 
110  for (SVFStmt::SVFStmtSetTy::iterator iter = tdjns.begin(), eiter =
111  tdjns.end(); iter != eiter; ++iter)
112  {
113  const TDJoinPE* edge = SVFUtil::cast<TDJoinPE>(*iter);
114  addCopyCGEdge(edge->getRHSVarID(),edge->getLHSVarID());
115  }
116 
118  for (SVFStmt::SVFStmtSetTy::iterator iter = ngeps.begin(), eiter =
119  ngeps.end(); iter != eiter; ++iter)
120  {
121  GepStmt* edge = SVFUtil::cast<GepStmt>(*iter);
122  if(edge->isVariantFieldGep())
124  else
125  addNormalGepCGEdge(edge->getRHSVarID(),edge->getLHSVarID(),edge->getAccessPath());
126  }
127 
129  for (SVFStmt::SVFStmtSetTy::iterator iter = loads.begin(), eiter =
130  loads.end(); iter != eiter; ++iter)
131  {
132  LoadStmt* edge = SVFUtil::cast<LoadStmt>(*iter);
133  addLoadCGEdge(edge->getRHSVarID(),edge->getLHSVarID());
134  }
135 
137  for (SVFStmt::SVFStmtSetTy::iterator iter = stores.begin(), eiter =
138  stores.end(); iter != eiter; ++iter)
139  {
140  StoreStmt* edge = SVFUtil::cast<StoreStmt>(*iter);
141  addStoreCGEdge(edge->getRHSVarID(),edge->getLHSVarID());
142  }
143 
144  clearSolitaries();
145 }
NodeID getRHSVarID() const
NodeID getLHSVarID() const
LoadCGEdge * addLoadCGEdge(NodeID src, NodeID dst)
Add Load edge.
Definition: ConsG.cpp:288
SVFStmt::SVFStmtSetTy & getPAGEdgeSet(SVFStmt::PEDGEK kind)
Definition: ConsG.h:72
AddrCGEdge * addAddrCGEdge(NodeID src, NodeID dst)
Add a SVFIR edge into Edge map.
Definition: ConsG.cpp:202
void addConstraintNode(ConstraintNode *node, NodeID id)
Definition: ConsG.h:114
CopyCGEdge * addCopyCGEdge(NodeID src, NodeID dst)
Add Copy edge.
Definition: ConsG.cpp:222
StoreCGEdge * addStoreCGEdge(NodeID src, NodeID dst)
Add Store edge.
Definition: ConsG.cpp:309
void clearSolitaries()
Definition: ConsG.cpp:150
VariantGepCGEdge * addVariantGepCGEdge(NodeID src, NodeID dst)
Definition: ConsG.cpp:267
NormalGepCGEdge * addNormalGepCGEdge(NodeID src, NodeID dst, const AccessPath &ap)
Add Gep edge.
Definition: ConsG.cpp:245
bool isBitCast() const
bool isValueCopy() const
iterator begin()
Iterators.
Definition: GenericGraph.h:627
IDToNodeMapTy::iterator iterator
Node Iterators.
Definition: GenericGraph.h:606
bool isVariantFieldGep() const
Gep statement with a variant field index (pointer arithmetic) for struct field access.
const AccessPath & getAccessPath() const
const OPVars & getOpndVars() const
NodeID getResID() const
GenericNode< SVFVar, SVFStmt >::GEdgeSetTy SVFStmtSetTy

◆ clearSolitaries()

void ConstraintGraph::clearSolitaries ( )
protected

Remove nodes that are neither pointers nor connected with any edge

We don't remove return SVFVar from an indirect callsite

Definition at line 150 of file ConsG.cpp.

151 {
153  NodeSet retFromIndCalls;
154  for(auto cs_pair : pag->getIndirectCallsites())
155  {
156  const RetICFGNode* retBlockNode = cs_pair.first->getRetICFGNode();
157  if(pag->callsiteHasRet(retBlockNode))
158  retFromIndCalls.insert(pag->getCallSiteRet(retBlockNode)->getId());
159  }
160 
161  Set<ConstraintNode*> nodesToRemove;
162  for (auto it = this->begin(); it != this->end(); ++it)
163  {
164  if (it->second->hasIncomingEdge() || it->second->hasOutgoingEdge())
165  continue;
166  if (pag->getGNode(it->first)->isPointer())
167  continue;
168  if (retFromIndCalls.find(it->first)!=retFromIndCalls.end())
169  continue;
170  nodesToRemove.insert(it->second);
171  }
172 
173  for (auto node : nodesToRemove)
174  removeConstraintNode(node);
175 }
void removeConstraintNode(ConstraintNode *node)
Definition: ConsG.h:123
NodeType * getGNode(NodeID id) const
Get a node.
Definition: GenericGraph.h:653
NodeID getId() const
Get ID.
Definition: GenericGraph.h:260
const CallSiteToFunPtrMap & getIndirectCallsites() const
Add/get indirect callsites.
Definition: SVFIR.h:350
const SVFVar * getCallSiteRet(const RetICFGNode *cs) const
Get callsite return.
Definition: SVFIR.h:304
bool callsiteHasRet(const RetICFGNode *cs) const
Definition: SVFIR.h:310
Set< NodeID > NodeSet
Definition: GeneralType.h:113
std::unordered_set< Key, Hash, KeyEqual, Allocator > Set
Definition: GeneralType.h:96

◆ destroy()

void ConstraintGraph::destroy ( )
protected

Memory has been cleaned up at GenericGraph

Definition at line 180 of file ConsG.cpp.

181 {
182 }

◆ dump()

void ConstraintGraph::dump ( std::string  name)

Dump graph into dot file.

Dump constraint graph

Definition at line 591 of file ConsG.cpp.

592 {
594 }
const char *const name
Definition: cJSON.h:264
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

◆ getAddrCGEdges()

ConstraintEdge::ConstraintEdgeSetTy& SVF::ConstraintGraph::getAddrCGEdges ( )
inline

Get SVFIR edge.

Get Address edges

Definition at line 196 of file ConsG.h.

197  {
198  return AddrCGEdgeSet;
199  }

◆ getAllFieldsObjVars()

NodeBS& SVF::ConstraintGraph::getAllFieldsObjVars ( NodeID  id)
inline

Definition at line 316 of file ConsG.h.

317  {
318  return pag->getAllFieldsObjVars(id);
319  }
NodeBS & getAllFieldsObjVars(const MemObj *obj)
Get all fields of an object.
Definition: SVFIR.cpp:477

◆ getBaseObjVar()

NodeID SVF::ConstraintGraph::getBaseObjVar ( NodeID  id)
inline

Definition at line 320 of file ConsG.h.

321  {
322  return pag->getBaseObjVar(id);
323  }
NodeID getBaseObjVar(NodeID id) const
Base and Offset methods for Value and Object node.
Definition: SVFIR.h:455

◆ getBlackHoleNode()

NodeID SVF::ConstraintGraph::getBlackHoleNode ( )
inline

Definition at line 308 of file ConsG.h.

309  {
310  return pag->getBlackHoleNode();
311  }
NodeID getBlackHoleNode() const
Definition: IRGraph.h:161

◆ getConstraintNode()

ConstraintNode* SVF::ConstraintGraph::getConstraintNode ( NodeID  id) const
inline

Get/add/remove constraint node.

Definition at line 109 of file ConsG.h.

110  {
111  id = sccRepNode(id);
112  return getGNode(id);
113  }
NodeID sccRepNode(NodeID id) const
SCC rep/sub nodes methods.
Definition: ConsG.h:235

◆ getDirectCGEdges()

ConstraintEdge::ConstraintEdgeSetTy& SVF::ConstraintGraph::getDirectCGEdges ( )
inline

Get Copy/call/ret/gep edges.

Definition at line 201 of file ConsG.h.

202  {
203  return directEdgeSet;
204  }

◆ getEdge()

ConstraintEdge* SVF::ConstraintGraph::getEdge ( ConstraintNode src,
ConstraintNode dst,
ConstraintEdge::ConstraintEdgeK  kind 
)
inline

Get an edge via its src and dst nodes and kind.

Definition at line 148 of file ConsG.h.

149  {
150  ConstraintEdge edge(src,dst,kind);
152  {
153  auto eit = directEdgeSet.find(&edge);
154  return *eit;
155  }
156  else if(kind == ConstraintEdge::Addr)
157  {
158  auto eit = AddrCGEdgeSet.find(&edge);
159  return *eit;
160  }
161  else if(kind == ConstraintEdge::Store)
162  {
163  auto eit = StoreCGEdgeSet.find(&edge);
164  return *eit;
165  }
166  else if(kind == ConstraintEdge::Load)
167  {
168  auto eit = LoadCGEdgeSet.find(&edge);
169  return *eit;
170  }
171  else
172  {
173  assert(false && "no other kind!");
174  return nullptr;
175  }
176  }

◆ getFIObjVar()

NodeID SVF::ConstraintGraph::getFIObjVar ( NodeID  id)
inline

Get a field-insensitive node of a memory object.

The fi obj in PAG must be either an existing node or merged to another rep node in ConsG

Definition at line 339 of file ConsG.h.

340  {
341  NodeID fi = pag->getFIObjVar(id);
343  assert((hasConstraintNode(fi) || sccRepNode(fi) != fi) && "non-existing fi obj??");
344  return fi;
345  }
bool hasConstraintNode(NodeID id) const
Definition: ConsG.h:118
NodeID getFIObjVar(const MemObj *obj) const
Get a field-insensitive obj SVFIR node according to a mem obj.
Definition: SVFIR.h:415
u32_t NodeID
Definition: GeneralType.h:55

◆ getGepObjVar()

NodeID SVF::ConstraintGraph::getGepObjVar ( NodeID  id,
const APOffset apOffset 
)
inline

Get a field of a memory object.

Create a node when it is (1) not exist on graph and (2) not merged

Definition at line 330 of file ConsG.h.

331  {
332  NodeID gep = pag->getGepObjVar(id, apOffset);
334  if(sccRepNode(gep)==gep && hasConstraintNode(gep)==false)
335  addConstraintNode(new ConstraintNode(gep),gep);
336  return gep;
337  }
NodeID getGepObjVar(const MemObj *obj, const APOffset &ap)
Get a field SVFIR Object node according to base mem obj and offset.
Definition: SVFIR.cpp:422

◆ getIndirectCallsites()

const SVFIR::CallSiteToFunPtrMap& SVF::ConstraintGraph::getIndirectCallsites ( ) const
inline

Wrappers for invoking SVFIR methods.

Definition at line 304 of file ConsG.h.

305  {
306  return pag->getIndirectCallsites();
307  }

◆ getLoadCGEdges()

ConstraintEdge::ConstraintEdgeSetTy& SVF::ConstraintGraph::getLoadCGEdges ( )
inline

Get Load edges.

Definition at line 206 of file ConsG.h.

207  {
208  return LoadCGEdgeSet;
209  }

◆ getNextCollapseNode()

NodeID SVF::ConstraintGraph::getNextCollapseNode ( )
inline

Definition at line 370 of file ConsG.h.

371  {
372  return nodesToBeCollapsed.pop();
373  }

◆ getPAGEdgeSet()

SVFStmt::SVFStmtSetTy& SVF::ConstraintGraph::getPAGEdgeSet ( SVFStmt::PEDGEK  kind)
inlineprotected

Definition at line 72 of file ConsG.h.

73  {
74  return pag->getPTASVFStmtSet(kind);
75  }
SVFStmt::SVFStmtSetTy & getPTASVFStmtSet(SVFStmt::PEDGEK kind)
Get PTA edges set according to its kind.
Definition: SVFIR.h:206

◆ getRep()

NodeID SVF::ConstraintGraph::getRep ( NodeID  node)
inline

Definition at line 264 of file ConsG.h.

265  {
266  return nodeToRepMap[node];
267  }
NodeToRepMap nodeToRepMap
Definition: ConsG.h:56

◆ getReturnNode()

NodeID SVF::ConstraintGraph::getReturnNode ( const SVFFunction value) const
inlineprotected

Definition at line 84 of file ConsG.h.

85  {
86  return pag->getReturnNode(value);
87  }
NodeID getReturnNode(const SVFFunction *func) const
GetReturnNode - Return the unique node representing the return value of a function.
Definition: IRGraph.h:152

◆ getStoreCGEdges()

ConstraintEdge::ConstraintEdgeSetTy& SVF::ConstraintGraph::getStoreCGEdges ( )
inline

Get Store edges.

Definition at line 211 of file ConsG.h.

212  {
213  return StoreCGEdgeSet;
214  }

◆ getSubs()

NodeBS& SVF::ConstraintGraph::getSubs ( NodeID  node)
inline

Definition at line 260 of file ConsG.h.

261  {
262  return nodeToSubsMap[node];
263  }
NodeToSubsMap nodeToSubsMap
Definition: ConsG.h:57

◆ getValueNode()

NodeID SVF::ConstraintGraph::getValueNode ( const SVFValue value) const
inlineprotected

Wrappers used internally, not expose to Andersen Pass.

Definition at line 79 of file ConsG.h.

80  {
81  return sccRepNode(pag->getValueNode(value));
82  }
NodeID getValueNode(const SVFValue *V)
Definition: IRGraph.h:137

◆ getVarargNode()

NodeID SVF::ConstraintGraph::getVarargNode ( const SVFFunction value) const
inlineprotected

Definition at line 89 of file ConsG.h.

90  {
91  return pag->getVarargNode(value);
92  }
NodeID getVarargNode(const SVFFunction *func) const
getVarargNode - Return the unique node representing the variadic argument of a variadic function.
Definition: IRGraph.h:157

◆ hasConstraintNode()

bool SVF::ConstraintGraph::hasConstraintNode ( NodeID  id) const
inline

Definition at line 118 of file ConsG.h.

119  {
120  id = sccRepNode(id);
121  return hasGNode(id);
122  }
bool hasGNode(NodeID id) const
Has a node.
Definition: GenericGraph.h:661

◆ hasEdge()

bool SVF::ConstraintGraph::hasEdge ( ConstraintNode src,
ConstraintNode dst,
ConstraintEdge::ConstraintEdgeK  kind 
)
inline

Definition at line 130 of file ConsG.h.

131  {
132  ConstraintEdge edge(src,dst,kind);
133  if(kind == ConstraintEdge::Copy ||
135  return directEdgeSet.find(&edge) != directEdgeSet.end();
136  else if(kind == ConstraintEdge::Addr)
137  return AddrCGEdgeSet.find(&edge) != AddrCGEdgeSet.end();
138  else if(kind == ConstraintEdge::Store)
139  return StoreCGEdgeSet.find(&edge) != StoreCGEdgeSet.end();
140  else if(kind == ConstraintEdge::Load)
141  return LoadCGEdgeSet.find(&edge) != LoadCGEdgeSet.end();
142  else
143  assert(false && "no other kind!");
144  return false;
145  }

◆ hasNodesToBeCollapsed()

bool SVF::ConstraintGraph::hasNodesToBeCollapsed ( ) const
inline

Add/get nodes to be collapsed.

Definition at line 362 of file ConsG.h.

363  {
364  return (!nodesToBeCollapsed.empty());
365  }
bool empty() const
Definition: WorkList.h:146

◆ isBlkObjOrConstantObj()

bool SVF::ConstraintGraph::isBlkObjOrConstantObj ( NodeID  id)
inline

Definition at line 312 of file ConsG.h.

313  {
314  return pag->isBlkObjOrConstantObj(id);
315  }
bool isBlkObjOrConstantObj(NodeID id) const
Definition: SVFIR.h:435

◆ isPWCNode()

bool SVF::ConstraintGraph::isPWCNode ( NodeID  nodeId)
inline

Check/Set PWC (positive weight cycle) flag.

Definition at line 350 of file ConsG.h.

351  {
352  return getConstraintNode(nodeId)->isPWCNode();
353  }
bool isPWCNode() const
Whether a node involves in PWC, if so, all its points-to elements should become field-insensitive.
Definition: ConsGNode.h:81

◆ isSingleFieldObj()

bool SVF::ConstraintGraph::isSingleFieldObj ( NodeID  id) const
inline

Definition at line 324 of file ConsG.h.

325  {
326  const MemObj* mem = pag->getBaseObj(id);
327  return (mem->getMaxFieldOffsetLimit() == 1);
328  }
const MemObj * getBaseObj(NodeID id) const
Definition: SVFIR.h:459

◆ isZeroOffsettedGepCGEdge()

bool SVF::ConstraintGraph::isZeroOffsettedGepCGEdge ( ConstraintEdge edge) const
inline

Check if a given edge is a NormalGepCGEdge with 0 offset.

Definition at line 294 of file ConsG.h.

295  {
296  if (NormalGepCGEdge *normalGepCGEdge = SVFUtil::dyn_cast<NormalGepCGEdge>(edge))
297  if (0 == normalGepCGEdge->getConstantFieldIdx())
298  return true;
299  return false;
300  }

◆ moveEdgesToRepNode()

bool SVF::ConstraintGraph::moveEdgesToRepNode ( ConstraintNode node,
ConstraintNode rep 
)
inline

Move incoming/outgoing direct edges of a sub node to its rep node Return TRUE if there's a gep edge inside this SCC (PWC).

Definition at line 286 of file ConsG.h.

287  {
288  bool gepIn = moveInEdgesToRepNode(node, rep);
289  bool gepOut = moveOutEdgesToRepNode(node, rep);
290  return (gepIn || gepOut);
291  }
bool moveInEdgesToRepNode(ConstraintNode *node, ConstraintNode *rep)
Definition: ConsG.cpp:474
bool moveOutEdgesToRepNode(ConstraintNode *node, ConstraintNode *rep)
Definition: ConsG.cpp:532

◆ moveInEdgesToRepNode()

bool ConstraintGraph::moveInEdgesToRepNode ( ConstraintNode node,
ConstraintNode rep 
)

Move incoming direct edges of a sub node which is outside the SCC to its rep node Remove incoming direct edges of a sub node which is inside the SCC from its rep node Return TRUE if there's a gep edge inside this SCC (PWC).

Move incoming direct edges of a sub node which is outside SCC to its rep node Remove incoming direct edges of a sub node which is inside SCC from its rep node

only copy and gep edge can be removed

Definition at line 474 of file ConsG.cpp.

475 {
476  std::vector<ConstraintEdge*> sccEdges;
477  std::vector<ConstraintEdge*> nonSccEdges;
478  for (ConstraintNode::const_iterator it = node->InEdgeBegin(), eit = node->InEdgeEnd(); it != eit;
479  ++it)
480  {
481  ConstraintEdge* subInEdge = *it;
482  if(sccRepNode(subInEdge->getSrcID()) != rep->getId())
483  nonSccEdges.push_back(subInEdge);
484  else
485  {
486  sccEdges.push_back(subInEdge);
487  }
488  }
489  // if this edge is outside scc, then re-target edge dst to rep
490  while(!nonSccEdges.empty())
491  {
492  ConstraintEdge* edge = nonSccEdges.back();
493  nonSccEdges.pop_back();
494  reTargetDstOfEdge(edge,rep);
495  }
496 
497  bool criticalGepInsideSCC = false;
498  // if this edge is inside scc, then remove this edge and two end nodes
499  while(!sccEdges.empty())
500  {
501  ConstraintEdge* edge = sccEdges.back();
502  sccEdges.pop_back();
504  if(SVFUtil::isa<CopyCGEdge>(edge))
505  removeDirectEdge(edge);
506  else if (SVFUtil::isa<GepCGEdge>(edge))
507  {
508  // If the GEP is critical (i.e. may have a non-zero offset),
509  // then it brings impact on field-sensitivity.
510  if (!isZeroOffsettedGepCGEdge(edge))
511  {
512  criticalGepInsideSCC = true;
513  }
514  removeDirectEdge(edge);
515  }
516  else if(SVFUtil::isa<LoadCGEdge, StoreCGEdge>(edge))
517  reTargetDstOfEdge(edge,rep);
518  else if(AddrCGEdge* addr = SVFUtil::dyn_cast<AddrCGEdge>(edge))
519  {
520  removeAddrEdge(addr);
521  }
522  else
523  assert(false && "no such edge");
524  }
525  return criticalGepInsideSCC;
526 }
void reTargetDstOfEdge(ConstraintEdge *edge, ConstraintNode *newDstNode)
Used for cycle elimination.
Definition: ConsG.cpp:335
void removeDirectEdge(ConstraintEdge *edge)
Remove direct edge from their src and dst edge sets.
Definition: ConsG.cpp:459
void removeAddrEdge(AddrCGEdge *edge)
Remove addr edge from their src and dst edge sets.
Definition: ConsG.cpp:420
bool isZeroOffsettedGepCGEdge(ConstraintEdge *edge) const
Check if a given edge is a NormalGepCGEdge with 0 offset.
Definition: ConsG.h:294
ConstraintEdge::ConstraintEdgeSetTy::const_iterator const_iterator
Definition: ConsGNode.h:45
NodeID getSrcID() const
get methods of the components
Definition: GenericGraph.h:81
iterator InEdgeBegin()
Definition: GenericGraph.h:462
iterator InEdgeEnd()
Definition: GenericGraph.h:466

◆ moveOutEdgesToRepNode()

bool ConstraintGraph::moveOutEdgesToRepNode ( ConstraintNode node,
ConstraintNode rep 
)

Move outgoing direct edges of a sub node which is outside the SCC to its rep node Remove outgoing direct edges of sub node which is inside the SCC from its rep node Return TRUE if there's a gep edge inside this SCC (PWC).

Move outgoing direct edges of a sub node which is outside SCC to its rep node Remove outgoing direct edges of a sub node which is inside SCC from its rep node

only copy and gep edge can be removed

Definition at line 532 of file ConsG.cpp.

533 {
534 
535  std::vector<ConstraintEdge*> sccEdges;
536  std::vector<ConstraintEdge*> nonSccEdges;
537 
538  for (ConstraintNode::const_iterator it = node->OutEdgeBegin(), eit = node->OutEdgeEnd(); it != eit;
539  ++it)
540  {
541  ConstraintEdge* subOutEdge = *it;
542  if(sccRepNode(subOutEdge->getDstID()) != rep->getId())
543  nonSccEdges.push_back(subOutEdge);
544  else
545  {
546  sccEdges.push_back(subOutEdge);
547  }
548  }
549  // if this edge is outside scc, then re-target edge src to rep
550  while(!nonSccEdges.empty())
551  {
552  ConstraintEdge* edge = nonSccEdges.back();
553  nonSccEdges.pop_back();
554  reTargetSrcOfEdge(edge,rep);
555  }
556  bool criticalGepInsideSCC = false;
557  // if this edge is inside scc, then remove this edge and two end nodes
558  while(!sccEdges.empty())
559  {
560  ConstraintEdge* edge = sccEdges.back();
561  sccEdges.pop_back();
563  if(SVFUtil::isa<CopyCGEdge>(edge))
564  removeDirectEdge(edge);
565  else if (SVFUtil::isa<GepCGEdge>(edge))
566  {
567  // If the GEP is critical (i.e. may have a non-zero offset),
568  // then it brings impact on field-sensitivity.
569  if (!isZeroOffsettedGepCGEdge(edge))
570  {
571  criticalGepInsideSCC = true;
572  }
573  removeDirectEdge(edge);
574  }
575  else if(SVFUtil::isa<LoadCGEdge, StoreCGEdge>(edge))
576  reTargetSrcOfEdge(edge,rep);
577  else if(AddrCGEdge* addr = SVFUtil::dyn_cast<AddrCGEdge>(edge))
578  {
579  removeAddrEdge(addr);
580  }
581  else
582  assert(false && "no such edge");
583  }
584  return criticalGepInsideSCC;
585 }
void reTargetSrcOfEdge(ConstraintEdge *edge, ConstraintNode *newSrcNode)
Remove edge from old src target, change edge dst id and add modified edge into new src.
Definition: ConsG.cpp:379
NodeID getDstID() const
Definition: GenericGraph.h:85
iterator OutEdgeEnd()
Definition: GenericGraph.h:458
iterator OutEdgeBegin()
iterators
Definition: GenericGraph.h:454

◆ print()

void ConstraintGraph::print ( void  )

Print CG into terminal.

Print this constraint graph including its nodes and edges

Definition at line 599 of file ConsG.cpp.

600 {
601 
602  outs() << "-----------------ConstraintGraph--------------------------------------\n";
603 
605  for (ConstraintEdge::ConstraintEdgeSetTy::iterator iter = addrs.begin(),
606  eiter = addrs.end(); iter != eiter; ++iter)
607  {
608  outs() << (*iter)->getSrcID() << " -- Addr --> " << (*iter)->getDstID()
609  << "\n";
610  }
611 
613  for (ConstraintEdge::ConstraintEdgeSetTy::iterator iter = directs.begin(),
614  eiter = directs.end(); iter != eiter; ++iter)
615  {
616  if (CopyCGEdge* copy = SVFUtil::dyn_cast<CopyCGEdge>(*iter))
617  {
618  outs() << copy->getSrcID() << " -- Copy --> " << copy->getDstID()
619  << "\n";
620  }
621  else if (NormalGepCGEdge* ngep = SVFUtil::dyn_cast<NormalGepCGEdge>(*iter))
622  {
623  outs() << ngep->getSrcID() << " -- NormalGep (" << ngep->getConstantFieldIdx()
624  << ") --> " << ngep->getDstID() << "\n";
625  }
626  else if (VariantGepCGEdge* vgep = SVFUtil::dyn_cast<VariantGepCGEdge>(*iter))
627  {
628  outs() << vgep->getSrcID() << " -- VarintGep --> "
629  << vgep->getDstID() << "\n";
630  }
631  else
632  assert(false && "wrong constraint edge kind!");
633  }
634 
636  for (ConstraintEdge::ConstraintEdgeSetTy::iterator iter = loads.begin(),
637  eiter = loads.end(); iter != eiter; ++iter)
638  {
639  outs() << (*iter)->getSrcID() << " -- Load --> " << (*iter)->getDstID()
640  << "\n";
641  }
642 
644  for (ConstraintEdge::ConstraintEdgeSetTy::iterator iter = stores.begin(),
645  eiter = stores.end(); iter != eiter; ++iter)
646  {
647  outs() << (*iter)->getSrcID() << " -- Store --> " << (*iter)->getDstID()
648  << "\n";
649  }
650 
651  outs()
652  << "--------------------------------------------------------------\n";
653 
654 }
copy vgep
Definition: PAGGrammar.txt:9
copy
Definition: cJSON.cpp:414
GenericNode< ConstraintNode, ConstraintEdge >::GEdgeSetTy ConstraintEdgeSetTy
Constraint edge type.
Definition: ConsGEdge.h:85
ConstraintEdge::ConstraintEdgeSetTy & getStoreCGEdges()
Get Store edges.
Definition: ConsG.h:211
ConstraintEdge::ConstraintEdgeSetTy & getDirectCGEdges()
Get Copy/call/ret/gep edges.
Definition: ConsG.h:201
ConstraintEdge::ConstraintEdgeSetTy & getAddrCGEdges()
Get SVFIR edge.
Definition: ConsG.h:196
ConstraintEdge::ConstraintEdgeSetTy & getLoadCGEdges()
Get Load edges.
Definition: ConsG.h:206

◆ removeAddrEdge()

void ConstraintGraph::removeAddrEdge ( AddrCGEdge edge)

Remove addr edge from their src and dst edge sets.

Remove addr edge from their src and dst edge sets

Definition at line 420 of file ConsG.cpp.

421 {
424  u32_t num = AddrCGEdgeSet.erase(edge);
425  (void)num; // Suppress warning of unused variable under release build
426  assert(num && "edge not in the set, can not remove!!!");
427  delete edge;
428 }
unsigned u32_t
Definition: CommandLine.h:18
bool removeIncomingAddrEdge(AddrCGEdge *inEdge)
Definition: ConsGNode.h:314
bool removeOutgoingAddrEdge(AddrCGEdge *outEdge)
Remove constraint graph edges.
Definition: ConsGNode.h:305

◆ removeConstraintNode()

void SVF::ConstraintGraph::removeConstraintNode ( ConstraintNode node)
inline

Definition at line 123 of file ConsG.h.

124  {
125  removeGNode(node);
126  }
void removeGNode(NodeType *node)
Delete a node.
Definition: GenericGraph.h:668

◆ removeDirectEdge()

void ConstraintGraph::removeDirectEdge ( ConstraintEdge edge)

Remove direct edge from their src and dst edge sets.

Remove edges from their src and dst edge sets

Definition at line 459 of file ConsG.cpp.

460 {
461 
464  u32_t num = directEdgeSet.erase(edge);
465  (void)num; // Suppress warning of unused variable under release build
466  assert(num && "edge not in the set, can not remove!!!");
467  delete edge;
468 }
bool removeOutgoingDirectEdge(ConstraintEdge *outEdge)
Definition: ConsGNode.h:323
bool removeIncomingDirectEdge(ConstraintEdge *inEdge)
Definition: ConsGNode.h:336

◆ removeLoadEdge()

void ConstraintGraph::removeLoadEdge ( LoadCGEdge edge)

Remove load edge from their src and dst edge sets.

Remove load edge from their src and dst edge sets

Definition at line 433 of file ConsG.cpp.

434 {
437  u32_t num = LoadCGEdgeSet.erase(edge);
438  (void)num; // Suppress warning of unused variable under release build
439  assert(num && "edge not in the set, can not remove!!!");
440  delete edge;
441 }
bool removeOutgoingLoadEdge(LoadCGEdge *outEdge)
Definition: ConsGNode.h:349
bool removeIncomingLoadEdge(LoadCGEdge *inEdge)
Definition: ConsGNode.h:358

◆ removeStoreEdge()

void ConstraintGraph::removeStoreEdge ( StoreCGEdge edge)

Remove store edge from their src and dst edge sets.

Remove store edge from their src and dst edge sets

Definition at line 446 of file ConsG.cpp.

447 {
450  u32_t num = StoreCGEdgeSet.erase(edge);
451  (void)num; // Suppress warning of unused variable under release build
452  assert(num && "edge not in the set, can not remove!!!");
453  delete edge;
454 }
bool removeOutgoingStoreEdge(StoreCGEdge *outEdge)
Definition: ConsGNode.h:367
bool removeIncomingStoreEdge(StoreCGEdge *inEdge)
Definition: ConsGNode.h:376

◆ resetRep()

void SVF::ConstraintGraph::resetRep ( NodeID  node)
inline

Definition at line 268 of file ConsG.h.

269  {
270  nodeToRepMap.erase(node);
271  }

◆ resetSubs()

void SVF::ConstraintGraph::resetSubs ( NodeID  node)
inline

Definition at line 256 of file ConsG.h.

257  {
258  nodeToSubsMap.erase(node);
259  }

◆ reTargetDstOfEdge()

void ConstraintGraph::reTargetDstOfEdge ( ConstraintEdge edge,
ConstraintNode newDstNode 
)

Used for cycle elimination.

Remove edge from old dst target, change edge dst id and add modified edge into new dst

Re-target dst node of an edge

(1) Remove edge from old dst target, (2) Change edge dst id and (3) Add modified edge into new dst

Definition at line 335 of file ConsG.cpp.

336 {
337  NodeID newDstNodeID = newDstNode->getId();
338  NodeID srcId = edge->getSrcID();
339  if(LoadCGEdge* load = SVFUtil::dyn_cast<LoadCGEdge>(edge))
340  {
341  removeLoadEdge(load);
342  addLoadCGEdge(srcId,newDstNodeID);
343  }
344  else if(StoreCGEdge* store = SVFUtil::dyn_cast<StoreCGEdge>(edge))
345  {
346  removeStoreEdge(store);
347  addStoreCGEdge(srcId,newDstNodeID);
348  }
349  else if(CopyCGEdge* copy = SVFUtil::dyn_cast<CopyCGEdge>(edge))
350  {
352  addCopyCGEdge(srcId,newDstNodeID);
353  }
354  else if(NormalGepCGEdge* gep = SVFUtil::dyn_cast<NormalGepCGEdge>(edge))
355  {
356  const AccessPath ap = gep->getAccessPath();
357  removeDirectEdge(gep);
358  addNormalGepCGEdge(srcId,newDstNodeID, ap);
359  }
360  else if(VariantGepCGEdge* gep = SVFUtil::dyn_cast<VariantGepCGEdge>(edge))
361  {
362  removeDirectEdge(gep);
363  addVariantGepCGEdge(srcId,newDstNodeID);
364  }
365  else if(AddrCGEdge* addr = SVFUtil::dyn_cast<AddrCGEdge>(edge))
366  {
367  removeAddrEdge(addr);
368  }
369  else
370  assert(false && "no other edge type!!");
371 }
void removeLoadEdge(LoadCGEdge *edge)
Remove load edge from their src and dst edge sets.
Definition: ConsG.cpp:433
void removeStoreEdge(StoreCGEdge *edge)
Remove store edge from their src and dst edge sets.
Definition: ConsG.cpp:446

◆ reTargetSrcOfEdge()

void ConstraintGraph::reTargetSrcOfEdge ( ConstraintEdge edge,
ConstraintNode newSrcNode 
)

Remove edge from old src target, change edge dst id and add modified edge into new src.

Re-target src node of an edge (1) Remove edge from old src target, (2) Change edge src id and (3) Add modified edge into new src

Definition at line 379 of file ConsG.cpp.

380 {
381  NodeID newSrcNodeID = newSrcNode->getId();
382  NodeID dstId = edge->getDstID();
383  if(LoadCGEdge* load = SVFUtil::dyn_cast<LoadCGEdge>(edge))
384  {
385  removeLoadEdge(load);
386  addLoadCGEdge(newSrcNodeID,dstId);
387  }
388  else if(StoreCGEdge* store = SVFUtil::dyn_cast<StoreCGEdge>(edge))
389  {
390  removeStoreEdge(store);
391  addStoreCGEdge(newSrcNodeID,dstId);
392  }
393  else if(CopyCGEdge* copy = SVFUtil::dyn_cast<CopyCGEdge>(edge))
394  {
396  addCopyCGEdge(newSrcNodeID,dstId);
397  }
398  else if(NormalGepCGEdge* gep = SVFUtil::dyn_cast<NormalGepCGEdge>(edge))
399  {
400  const AccessPath ap = gep->getAccessPath();
401  removeDirectEdge(gep);
402  addNormalGepCGEdge(newSrcNodeID, dstId, ap);
403  }
404  else if(VariantGepCGEdge* gep = SVFUtil::dyn_cast<VariantGepCGEdge>(edge))
405  {
406  removeDirectEdge(gep);
407  addVariantGepCGEdge(newSrcNodeID,dstId);
408  }
409  else if(AddrCGEdge* addr = SVFUtil::dyn_cast<AddrCGEdge>(edge))
410  {
411  removeAddrEdge(addr);
412  }
413  else
414  assert(false && "no other edge type!!");
415 }

◆ sccRepNode()

NodeID SVF::ConstraintGraph::sccRepNode ( NodeID  id) const
inline

SCC rep/sub nodes methods.

Definition at line 235 of file ConsG.h.

236  {
237  NodeToRepMap::const_iterator it = nodeToRepMap.find(id);
238  if(it==nodeToRepMap.end())
239  return id;
240  else
241  return it->second;
242  }

◆ sccSubNodes()

NodeBS& SVF::ConstraintGraph::sccSubNodes ( NodeID  id)
inline

Definition at line 243 of file ConsG.h.

244  {
245  nodeToSubsMap[id].set(id);
246  return nodeToSubsMap[id];
247  }

◆ setPWCNode()

void SVF::ConstraintGraph::setPWCNode ( NodeID  nodeId)
inline

Definition at line 354 of file ConsG.h.

355  {
356  getConstraintNode(nodeId)->setPWCNode();
357  }

◆ setRep()

void SVF::ConstraintGraph::setRep ( NodeID  node,
NodeID  rep 
)
inline

Definition at line 248 of file ConsG.h.

249  {
250  nodeToRepMap[node] = rep;
251  }

◆ setSubs()

void SVF::ConstraintGraph::setSubs ( NodeID  node,
NodeBS subs 
)
inline

Definition at line 252 of file ConsG.h.

253  {
254  nodeToSubsMap[node] |= subs;
255  }

◆ view()

void ConstraintGraph::view ( )

View graph from the debugger.

View dot graph of Constraint graph from debugger.

Definition at line 659 of file ConsG.cpp.

660 {
661  SVF::ViewGraph(this, "Constraint Graph");
662 }
void ViewGraph(const GraphType &G, const std::string &name, bool ShortNames=false, GraphProgram::Name Program=GraphProgram::DOT)
Definition: GraphWriter.h:371

Member Data Documentation

◆ AddrCGEdgeSet

ConstraintEdge::ConstraintEdgeSetTy SVF::ConstraintGraph::AddrCGEdgeSet
protected

Definition at line 61 of file ConsG.h.

◆ directEdgeSet

ConstraintEdge::ConstraintEdgeSetTy SVF::ConstraintGraph::directEdgeSet
protected

Definition at line 62 of file ConsG.h.

◆ edgeIndex

EdgeID SVF::ConstraintGraph::edgeIndex
protected

Definition at line 59 of file ConsG.h.

◆ LoadCGEdgeSet

ConstraintEdge::ConstraintEdgeSetTy SVF::ConstraintGraph::LoadCGEdgeSet
protected

Definition at line 63 of file ConsG.h.

◆ nodesToBeCollapsed

WorkList SVF::ConstraintGraph::nodesToBeCollapsed
protected

Definition at line 58 of file ConsG.h.

◆ nodeToRepMap

NodeToRepMap SVF::ConstraintGraph::nodeToRepMap
protected

Definition at line 56 of file ConsG.h.

◆ nodeToSubsMap

NodeToSubsMap SVF::ConstraintGraph::nodeToSubsMap
protected

Definition at line 57 of file ConsG.h.

◆ pag

SVFIR* SVF::ConstraintGraph::pag
protected

Definition at line 55 of file ConsG.h.

◆ StoreCGEdgeSet

ConstraintEdge::ConstraintEdgeSetTy SVF::ConstraintGraph::StoreCGEdgeSet
protected

Definition at line 64 of file ConsG.h.


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