SVF
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
SVF::OfflineConsG Class Reference

#include <OfflineConsG.h>

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

Public Types

typedef SCCDetection< OfflineConsG * > OSCC
 
typedef Set< LoadCGEdge * > LoadEdges
 
typedef Set< StoreCGEdge * > StoreEdges
 
- Public Types inherited from SVF::ConstraintGraph
typedef Map< NodeID, ConstraintNode * > ConstraintNodeIDToNodeMapTy
 
typedef ConstraintEdge::ConstraintEdgeSetTy::iterator ConstraintNodeIter
 
typedef Map< NodeID, NodeID > NodeToRepMap
 
typedef Map< NodeID, NodeBS > NodeToSubsMap
 
typedef FIFOWorkList< NodeID > WorkList
 
- Public Types inherited from SVF::GenericGraph< ConstraintNode, ConstraintEdge >
typedef ConstraintNode NodeType
 
typedef ConstraintEdge EdgeType
 
typedef Map< NodeID, NodeType *> IDToNodeMapTy
 NodeID to GenericNode map. More...
 
typedef IDToNodeMapTy::iterator iterator
 Node Iterators. More...
 
typedef IDToNodeMapTy::const_iterator const_iterator
 

Public Member Functions

 OfflineConsG (PAG *p)
 
bool hasOCGRep (NodeID node) const
 
NodeID getOCGRep (NodeID node) const
 
const NodeToRepMap & getOCGRepMap () const
 
bool isaRef (NodeID node) const
 
bool hasRef (NodeID node) const
 
NodeID getRef (NodeID node) const
 
void solveOfflineSCC (OSCC *oscc)
 
void buildOfflineMap (OSCC *oscc)
 
void dump (std::string name)
 
- Public Member Functions inherited from SVF::ConstraintGraph
 ConstraintGraph (PAG *p)
 Constructor. More...
 
virtual ~ConstraintGraph ()
 Destructor. More...
 
bool hasEdge (ConstraintNode *src, ConstraintNode *dst, ConstraintEdge::ConstraintEdgeK kind)
 
ConstraintEdge * getEdge (ConstraintNode *src, ConstraintNode *dst, ConstraintEdge::ConstraintEdgeK kind)
 Get an edge via its src and dst nodes and kind. More...
 
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...
 
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...
 
ConstraintNode * getConstraintNode (NodeID id) const
 Get/add/remove constraint node. More...
 
void addConstraintNode (ConstraintNode *node, NodeID id)
 
bool hasConstraintNode (NodeID id) const
 
void removeConstraintNode (ConstraintNode *node)
 
AddrCGEdge * addAddrCGEdge (NodeID src, NodeID dst)
 Add a PAG edge into Edge map. More...
 
CopyCGEdge * addCopyCGEdge (NodeID src, NodeID dst)
 Add Copy edge. More...
 
NormalGepCGEdge * addNormalGepCGEdge (NodeID src, NodeID dst, const LocationSet &ls)
 Add Gep edge. More...
 
VariantGepCGEdge * addVariantGepCGEdge (NodeID src, NodeID dst)
 
LoadCGEdge * addLoadCGEdge (NodeID src, NodeID dst)
 Add Load edge. More...
 
StoreCGEdge * addStoreCGEdge (NodeID src, NodeID dst)
 Add Store edge. More...
 
ConstraintEdge::ConstraintEdgeSetTy & getAddrCGEdges ()
 Get PAG edge. More...
 
ConstraintEdge::ConstraintEdgeSetTy & getDirectCGEdges ()
 Get Copy/call/ret/gep edges. More...
 
ConstraintEdge::ConstraintEdgeSetTy & getLoadCGEdges ()
 Get Load edges. More...
 
ConstraintEdge::ConstraintEdgeSetTy & getStoreCGEdges ()
 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 modifed 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...
 
NodeBS & sccSubNodes (NodeID id)
 
void setRep (NodeID node, NodeID rep)
 
void setSubs (NodeID node, NodeBS &subs)
 
void resetSubs (NodeID node)
 
NodeBS & getSubs (NodeID node)
 
NodeID getRep (NodeID node)
 
void resetRep (NodeID node)
 
const PAG::CallSiteToFunPtrMap & getIndirectCallsites () const
 Wrappers for invoking PAG methods. More...
 
NodeID getBlackHoleNode ()
 
bool isBlkObjOrConstantObj (NodeID id)
 
NodeBS & getAllFieldsObjNode (NodeID id)
 
NodeID getBaseObjNode (NodeID id)
 
bool isSingleFieldObj (NodeID id) const
 
NodeID getGepObjNode (NodeID id, const LocationSet &ls)
 Get a field of a memory object. More...
 
NodeID getFIObjNode (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 ()
 
- 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...
 
NodeType * getGNode (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

bool hasNorRep (NodeID nor) const
 
void setNorRep (NodeID nor, NodeID rep)
 
NodeID getNorRep (NodeID nor) const
 
NodeID solveRep (OSCC *oscc, NodeID rep)
 
void buildOfflineCG ()
 
bool addRefLoadEdge (NodeID src, NodeID dst)
 
bool addRefStoreEdge (NodeID src, NodeID dst)
 
bool createRefNode (NodeID nodeId)
 
- Protected Member Functions inherited from SVF::ConstraintGraph
void buildCG ()
 
void destroy ()
 
PAGEdge::PAGEdgeSetTy & getPAGEdgeSet (PAGEdge::PEDGEK kind)
 
NodeID getValueNode (const Value *value) const
 Wappers used internally, not expose to Andernsen Pass. More...
 
NodeID getReturnNode (const SVFFunction *value) const
 
NodeID getVarargNode (const SVFFunction *value) const
 

Protected Attributes

NodeSet refNodes
 
NodeToRepMap nodeToRefMap
 
NodeToRepMap norToRepMap
 
- Protected Attributes inherited from SVF::ConstraintGraph
PAG * pag
 
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

Offline constraint graph for Andersen's analysis. In OCG, a 'ref' node is used to represent the point-to set of a constraint node. 'Nor' means a constraint node of its corresponding ref node.

Definition at line 44 of file OfflineConsG.h.

Member Typedef Documentation

◆ LoadEdges

Definition at line 49 of file OfflineConsG.h.

◆ OSCC

Definition at line 48 of file OfflineConsG.h.

◆ StoreEdges

Definition at line 50 of file OfflineConsG.h.

Constructor & Destructor Documentation

◆ OfflineConsG()

SVF::OfflineConsG::OfflineConsG ( PAG *  p)
inline

Definition at line 58 of file OfflineConsG.h.

58  : ConstraintGraph(p),
59  nodeToRefMap( {}), norToRepMap({})
60  {
62  }
NodeToRepMap nodeToRefMap
Definition: OfflineConsG.h:54
ConstraintGraph(PAG *p)
Constructor.
Definition: ConsG.h:95
NodeToRepMap norToRepMap
Definition: OfflineConsG.h:55

Member Function Documentation

◆ addRefLoadEdge()

bool OfflineConsG::addRefLoadEdge ( NodeID  src,
NodeID  dst 
)
protected

Add a copy edge between the ref node of src node and dst node, while meeting a LOAD constraint.

Definition at line 86 of file OfflineConsG.cpp.

87 {
88  createRefNode(src);
89  NodeID ref = nodeToRefMap[src];
90  return addCopyCGEdge(ref, dst);
91 }
u32_t NodeID
Definition: SVFBasicTypes.h:80
NodeToRepMap nodeToRefMap
Definition: OfflineConsG.h:54
CopyCGEdge * addCopyCGEdge(NodeID src, NodeID dst)
Add Copy edge.
Definition: ConsG.cpp:173
bool createRefNode(NodeID nodeId)

◆ addRefStoreEdge()

bool OfflineConsG::addRefStoreEdge ( NodeID  src,
NodeID  dst 
)
protected

Add a copy edge between src node and the ref node of dst node, while meeting a STORE constraint.

Definition at line 97 of file OfflineConsG.cpp.

98 {
99  createRefNode(dst);
100  NodeID ref = nodeToRefMap[dst];
101  return addCopyCGEdge(src, ref);
102 }
u32_t NodeID
Definition: SVFBasicTypes.h:80
NodeToRepMap nodeToRefMap
Definition: OfflineConsG.h:54
CopyCGEdge * addCopyCGEdge(NodeID src, NodeID dst)
Add Copy edge.
Definition: ConsG.cpp:173
bool createRefNode(NodeID nodeId)

◆ buildOfflineCG()

void OfflineConsG::buildOfflineCG ( )
protected

Builder of offline constraint graph

Definition at line 39 of file OfflineConsG.cpp.

40 {
41  LoadEdges loads;
42  StoreEdges stores;
43 
44  // Add a copy edge between the ref node of src node and dst node
45  for (ConstraintEdge::ConstraintEdgeSetTy::iterator it = LoadCGEdgeSet.begin(), eit =
46  LoadCGEdgeSet.end(); it != eit; ++it)
47  {
49  loads.insert(load);
50  NodeID src = load->getSrcID();
51  NodeID dst = load->getDstID();
52  addRefLoadEdge(src, dst);
53  }
54  // Add a copy edge between src node and the ref node of dst node
55  for (ConstraintEdge::ConstraintEdgeSetTy::iterator it = StoreCGEdgeSet.begin(), eit =
56  StoreCGEdgeSet.end(); it != eit; ++it)
57  {
59  stores.insert(store);
60  NodeID src = store->getSrcID();
61  NodeID dst = store->getDstID();
62  addRefStoreEdge(src, dst);
63  }
64 
65  // Dump offline graph with all edges
66  dump("oCG_initial");
67 
68  // Remove load and store edges in offline constraint graph
69  for (LoadEdges::iterator it = loads.begin(), eit = loads.end(); it != eit; ++it)
70  {
71  removeLoadEdge(*it);
72  }
73  for (StoreEdges::iterator it = stores.begin(), eit = stores.end(); it != eit; ++it)
74  {
75  removeStoreEdge(*it);
76  }
77 
78  // Dump offline graph with removed load and store edges
79  dump("oCG_final");
80 }
NodeID getDstID() const
Definition: GenericGraph.h:77
u32_t NodeID
Definition: SVFBasicTypes.h:80
void removeStoreEdge(StoreCGEdge *edge)
Remove store edge from their src and dst edge sets.
Definition: ConsG.cpp:380
bool addRefLoadEdge(NodeID src, NodeID dst)
NodeID getSrcID() const
get methods of the components
Definition: GenericGraph.h:73
Set< StoreCGEdge * > StoreEdges
Definition: OfflineConsG.h:50
bool addRefStoreEdge(NodeID src, NodeID dst)
Set< LoadCGEdge * > LoadEdges
Definition: OfflineConsG.h:49
void dump(std::string name)
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:343
void removeLoadEdge(LoadCGEdge *edge)
Remove load edge from their src and dst edge sets.
Definition: ConsG.cpp:368
ConstraintEdge::ConstraintEdgeSetTy StoreCGEdgeSet
Definition: ConsG.h:64
ConstraintEdge::ConstraintEdgeSetTy LoadCGEdgeSet
Definition: ConsG.h:63

◆ buildOfflineMap()

void OfflineConsG::buildOfflineMap ( OSCC *  oscc)

Build offline node to rep map, which only collect nodes having a ref node

Definition at line 133 of file OfflineConsG.cpp.

134 {
135  for (NodeToRepMap::const_iterator it = nodeToRefMap.begin(); it != nodeToRefMap.end(); ++it)
136  {
137  NodeID node = it->first;
138  NodeID ref = getRef(node);
139  NodeID rep = solveRep(oscc,oscc->repNode(ref));
140  if (!isaRef(rep) && !isaRef(node))
141  setNorRep(node, rep);
142  }
143 }
u32_t NodeID
Definition: SVFBasicTypes.h:80
void setNorRep(NodeID nor, NodeID rep)
Definition: OfflineConsG.h:116
NodeToRepMap nodeToRefMap
Definition: OfflineConsG.h:54
bool isaRef(NodeID node) const
Definition: OfflineConsG.h:81
NodeID solveRep(OSCC *oscc, NodeID rep)
NodeID getRef(NodeID node) const
Definition: OfflineConsG.h:93

◆ createRefNode()

bool OfflineConsG::createRefNode ( NodeID  nodeId)
protected

Create a ref node for a constraint node if it does not have one

Definition at line 107 of file OfflineConsG.cpp.

108 {
109  if (hasRef(nodeId))
110  return false;
111 
112  NodeID refId = pag->addDummyValNode();
113  ConstraintNode* node = new ConstraintNode(refId);
114  addConstraintNode(node, refId);
115  refNodes.insert(refId);
116  nodeToRefMap[nodeId] = refId;
117  return true;
118 }
u32_t NodeID
Definition: SVFBasicTypes.h:80
NodeID addDummyValNode()
Add a dummy value/object node according to node ID (llvm value is null)
Definition: PAG.h:736
bool hasRef(NodeID node) const
Definition: OfflineConsG.h:87
void addConstraintNode(ConstraintNode *node, NodeID id)
Definition: ConsG.h:112
NodeToRepMap nodeToRefMap
Definition: OfflineConsG.h:54

◆ dump()

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

Dump offline constraint graph

Definition at line 169 of file OfflineConsG.cpp.

170 {
172  GraphPrinter::WriteGraphToFile(outs(), name, this);
173 }
static const llvm::cl::opt< bool > OCGDotGraph
Definition: Options.h:63
raw_ostream & outs()
Overwrite llvm::outs()
Definition: SVFUtil.h:47
static void WriteGraphToFile(llvm::raw_ostream &O, const std::string &GraphName, const GraphType &GT, bool simple=false)
Definition: GraphPrinter.h:56

◆ getNorRep()

NodeID SVF::OfflineConsG::getNorRep ( NodeID  nor) const
inlineprotected

Definition at line 121 of file OfflineConsG.h.

122  {
123  NodeToRepMap::const_iterator it = norToRepMap.find(nor);
124  assert(it != norToRepMap.end() && "No such rep node in nor to rep map!");
125  return it->second;
126  };
#define assert(ex)
Definition: util.h:141
NodeToRepMap norToRepMap
Definition: OfflineConsG.h:55

◆ getOCGRep()

NodeID SVF::OfflineConsG::getOCGRep ( NodeID  node) const
inline

Definition at line 70 of file OfflineConsG.h.

71  {
72  return getNorRep(node);
73  }
NodeID getNorRep(NodeID nor) const
Definition: OfflineConsG.h:121

◆ getOCGRepMap()

const NodeToRepMap& SVF::OfflineConsG::getOCGRepMap ( ) const
inline

Definition at line 75 of file OfflineConsG.h.

76  {
77  return norToRepMap;
78  }
NodeToRepMap norToRepMap
Definition: OfflineConsG.h:55

◆ getRef()

NodeID SVF::OfflineConsG::getRef ( NodeID  node) const
inline

Definition at line 93 of file OfflineConsG.h.

94  {
95  NodeToRepMap::const_iterator it = nodeToRefMap.find(node);
96  assert(it != nodeToRefMap.end() && "No such ref node in ref to node map!");
97  return it->second;
98  }
#define assert(ex)
Definition: util.h:141
NodeToRepMap nodeToRefMap
Definition: OfflineConsG.h:54

◆ hasNorRep()

bool SVF::OfflineConsG::hasNorRep ( NodeID  nor) const
inlineprotected

Definition at line 110 of file OfflineConsG.h.

111  {
112  NodeToRepMap::const_iterator it = norToRepMap.find(nor);
113  return it != norToRepMap.end();
114  };
NodeToRepMap norToRepMap
Definition: OfflineConsG.h:55

◆ hasOCGRep()

bool SVF::OfflineConsG::hasOCGRep ( NodeID  node) const
inline

Definition at line 65 of file OfflineConsG.h.

66  {
67  return hasNorRep(node);
68  }
bool hasNorRep(NodeID nor) const
Definition: OfflineConsG.h:110

◆ hasRef()

bool SVF::OfflineConsG::hasRef ( NodeID  node) const
inline

Definition at line 87 of file OfflineConsG.h.

88  {
89  NodeToRepMap::const_iterator it = nodeToRefMap.find(node);
90  return it != nodeToRefMap.end();
91  };
NodeToRepMap nodeToRefMap
Definition: OfflineConsG.h:54

◆ isaRef()

bool SVF::OfflineConsG::isaRef ( NodeID  node) const
inline

Definition at line 81 of file OfflineConsG.h.

82  {
83  NodeSet::const_iterator it = refNodes.find(node);
84  return it != refNodes.end();
85  };

◆ setNorRep()

void SVF::OfflineConsG::setNorRep ( NodeID  nor,
NodeID  rep 
)
inlineprotected

Definition at line 116 of file OfflineConsG.h.

117  {
118  norToRepMap.insert(std::pair<NodeID, NodeID>(nor, rep));
119  };
NodeToRepMap norToRepMap
Definition: OfflineConsG.h:55

◆ solveOfflineSCC()

void OfflineConsG::solveOfflineSCC ( OSCC *  oscc)

Use a offline SCC detector to solve node relations in OCG. Generally, the 'oscc' should be solved first.

Definition at line 124 of file OfflineConsG.cpp.

125 {
126  // Build offline nodeToRepMap
127  buildOfflineMap(oscc);
128 }
void buildOfflineMap(OSCC *oscc)

◆ solveRep()

NodeID OfflineConsG::solveRep ( OSCC *  oscc,
NodeID  rep 
)
protected

The rep nodes of offline constraint graph are possible to be 'ref' nodes. These nodes should be replaced by one of its sub nodes which is not a ref node.

Definition at line 149 of file OfflineConsG.cpp.

150 {
151  if (isaRef(rep))
152  {
153  NodeBS subNodes = oscc->subNodes(rep);
154  for (NodeBS::iterator subIt = subNodes.begin(), subEit = subNodes.end(); subIt != subEit; ++subIt)
155  {
156  if (isaRef(*subIt))
157  {
158  rep = *subIt;
159  break;
160  }
161  }
162  }
163  return rep;
164 }
bool isaRef(NodeID node) const
Definition: OfflineConsG.h:81
llvm::SparseBitVector NodeBS
Definition: SVFBasicTypes.h:87

Member Data Documentation

◆ nodeToRefMap

NodeToRepMap SVF::OfflineConsG::nodeToRefMap
protected

Definition at line 54 of file OfflineConsG.h.

◆ norToRepMap

NodeToRepMap SVF::OfflineConsG::norToRepMap
protected

Definition at line 55 of file OfflineConsG.h.

◆ refNodes

NodeSet SVF::OfflineConsG::refNodes
protected

Definition at line 53 of file OfflineConsG.h.


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