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

#include <IRGraph.h>

Inheritance diagram for SVF::IRGraph:
SVF::GenericGraph< SVFVar, SVFStmt > SVF::SVFIR

Public Types

typedef Set< const SVFStmt * > SVFStmtSet
 
typedef Map< const SVFValue *, SVFStmtSetValueToEdgeMap
 
- Public Types inherited from SVF::GenericGraph< SVFVar, SVFStmt >
typedef SVFVar NodeType
 
typedef SVFStmt 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

 IRGraph (bool buildFromFile)
 
virtual ~IRGraph ()
 
SymbolTableInfogetSymbolInfo () const
 
bool isBuiltFromFile ()
 Whether this SVFIR built from a txt file. More...
 
const SVFStmtSetgetValueEdges (const SVFValue *V)
 Get all SVFIR Edges that corresponds to an LLVM value. More...
 
NodeID getValueNode (const SVFValue *V)
 
bool hasValueNode (const SVFValue *V)
 
NodeID getObjectNode (const SVFValue *V)
 
NodeID getReturnNode (const SVFFunction *func) const
 GetReturnNode - Return the unique node representing the return value of a function. More...
 
NodeID getVarargNode (const SVFFunction *func) const
 getVarargNode - Return the unique node representing the variadic argument of a variadic function. More...
 
NodeID getBlackHoleNode () const
 
NodeID getConstantNode () const
 
NodeID getBlkPtr () const
 
NodeID getNullPtr () const
 
const MemObjgetBlackHoleObj () const
 
const MemObjgetConstantObj () const
 
u32_t getValueNodeNum () const
 
u32_t getObjectNodeNum () const
 
u32_t getNodeNumAfterPAGBuild () const
 
void setNodeNumAfterPAGBuild (u32_t num)
 
u32_t getPAGNodeNum () const
 
u32_t getPAGEdgeNum () const
 
u32_t getPTAPAGEdgeNum () const
 
std::string getGraphName () const
 Return graph name. More...
 
void dump (std::string name)
 Dump SVFIR. More...
 
void view ()
 View graph from the debugger. More...
 
- Public Member Functions inherited from SVF::GenericGraph< SVFVar, SVFStmt >
 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

NodeID addNode (SVFVar *node, NodeID i)
 Add a node into the graph. More...
 
bool addEdge (SVFVar *src, SVFVar *dst, SVFStmt *edge)
 Add an edge into the graph. More...
 
SVFStmthasNonlabeledEdge (SVFVar *src, SVFVar *dst, SVFStmt::PEDGEK kind)
 
SVFStmthasLabeledEdge (SVFVar *src, SVFVar *dst, SVFStmt::PEDGEK kind, const ICFGNode *cs)
 
SVFStmthasLabeledEdge (SVFVar *src, SVFVar *op1, SVFStmt::PEDGEK kind, const SVFVar *op2)
 
void mapValueToEdge (const SVFValue *V, SVFStmt *edge)
 Map a value to a set of edges. More...
 
const MemObjgetMemObj (const SVFValue *val) const
 get MemObj according to LLVM value More...
 

Protected Attributes

SVFStmt::KindToSVFStmtMapTy KindToSVFStmtSetMap
 SVFIR edge map containing all PAGEdges. More...
 
SVFStmt::KindToSVFStmtMapTy KindToPTASVFStmtSetMap
 SVFIR edge map containing only pointer-related edges, i.e., both LHS and RHS are of pointer type. More...
 
bool fromFile
 Whether the SVFIR is built according to user specified data from a txt file. More...
 
NodeID nodeNumAfterPAGBuild
 initial node number after building SVFIR, excluding later added nodes, e.g., gepobj nodes More...
 
u32_t totalPTAPAGEdge
 
ValueToEdgeMap valueToEdgeMap
 Map SVFValues (e.g., ICFGNodes) to all corresponding PAGEdges. More...
 
SymbolTableInfosymInfo
 
- Protected Attributes inherited from SVF::GenericGraph< SVFVar, SVFStmt >
IDToNodeMapTy IDToNodeMap
 node map More...
 

Friends

class SVFIRWriter
 
class SVFIRReader
 

Additional Inherited Members

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

Detailed Description

Definition at line 49 of file IRGraph.h.

Member Typedef Documentation

◆ SVFStmtSet

Definition at line 55 of file IRGraph.h.

◆ ValueToEdgeMap

Definition at line 56 of file IRGraph.h.

Constructor & Destructor Documentation

◆ IRGraph()

SVF::IRGraph::IRGraph ( bool  buildFromFile)
inline

Definition at line 104 of file IRGraph.h.

105  : fromFile(buildFromFile), nodeNumAfterPAGBuild(0), totalPTAPAGEdge(0)
106  {
108  // insert dummy value if a correct value cannot be found
109  valueToEdgeMap[nullptr] = SVFStmtSet();
110  }
ValueToEdgeMap valueToEdgeMap
Map SVFValues (e.g., ICFGNodes) to all corresponding PAGEdges.
Definition: IRGraph.h:64
Set< const SVFStmt * > SVFStmtSet
Definition: IRGraph.h:55
SymbolTableInfo * symInfo
Definition: IRGraph.h:65
bool fromFile
Whether the SVFIR is built according to user specified data from a txt file.
Definition: IRGraph.h:61
NodeID nodeNumAfterPAGBuild
initial node number after building SVFIR, excluding later added nodes, e.g., gepobj nodes
Definition: IRGraph.h:62
u32_t totalPTAPAGEdge
Definition: IRGraph.h:63
static SymbolTableInfo * SymbolInfo()
Singleton design here to make sure we only have one instance during any analysis.

◆ ~IRGraph()

IRGraph::~IRGraph ( )
virtual

Definition at line 36 of file IRGraph.cpp.

37 {
39  symInfo = nullptr;
40 }
static void releaseSymbolInfo()

Member Function Documentation

◆ addEdge()

bool IRGraph::addEdge ( SVFVar src,
SVFVar dst,
SVFStmt edge 
)
protected

Add an edge into the graph.

Add a SVFIR edge into edge map

Definition at line 45 of file IRGraph.cpp.

46 {
47 
49  outs() << "add edge from " << src->getId() << " kind :"
50  << src->getNodeKind() << " to " << dst->getId()
51  << " kind :" << dst->getNodeKind() << "\n");
52  src->addOutEdge(edge);
53  dst->addInEdge(edge);
54  return true;
55 }
#define DBOUT(TYPE, X)
LLVM debug macros, define type of your DBUG model of each pass.
Definition: SVFType.h:484
#define DPAGBuild
Definition: SVFType.h:492
GNodeK getNodeKind() const
Get node kind.
Definition: GenericGraph.h:266
NodeID getId() const
Get ID.
Definition: GenericGraph.h:260
void addOutEdge(SVFStmt *outEdge)
Definition: SVFVariables.h:223
void addInEdge(SVFStmt *inEdge)
add methods of the components
Definition: SVFVariables.h:216
std::ostream & outs()
Overwrite llvm::outs()
Definition: SVFUtil.h:50

◆ addNode()

NodeID SVF::IRGraph::addNode ( SVFVar node,
NodeID  i 
)
inlineprotected

Add a node into the graph.

Definition at line 68 of file IRGraph.h.

69  {
70  addGNode(i,node);
71  return i;
72  }
void addGNode(NodeID id, NodeType *node)
Add a Node.
Definition: GenericGraph.h:646

◆ dump()

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

Dump SVFIR.

Dump this IRGraph

Definition at line 102 of file IRGraph.cpp.

103 {
105 }
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

◆ getBlackHoleNode()

NodeID SVF::IRGraph::getBlackHoleNode ( ) const
inline

Definition at line 161 of file IRGraph.h.

162  {
163  return symInfo->blackholeSymID();
164  }
SymID blackholeSymID() const

◆ getBlackHoleObj()

const MemObj* SVF::IRGraph::getBlackHoleObj ( ) const
inline

Definition at line 177 of file IRGraph.h.

178  {
179  return symInfo->getBlkObj();
180  }
MemObj * getBlkObj() const

◆ getBlkPtr()

NodeID SVF::IRGraph::getBlkPtr ( ) const
inline

Definition at line 169 of file IRGraph.h.

170  {
171  return symInfo->blkPtrSymID();
172  }
SymID blkPtrSymID() const

◆ getConstantNode()

NodeID SVF::IRGraph::getConstantNode ( ) const
inline

Definition at line 165 of file IRGraph.h.

166  {
167  return symInfo->constantSymID();
168  }
SymID constantSymID() const

◆ getConstantObj()

const MemObj* SVF::IRGraph::getConstantObj ( ) const
inline

Definition at line 181 of file IRGraph.h.

182  {
183  return symInfo->getConstantObj();
184  }
MemObj * getConstantObj() const

◆ getGraphName()

std::string SVF::IRGraph::getGraphName ( ) const
inline

Return graph name.

Definition at line 216 of file IRGraph.h.

217  {
218  return "SVFIR";
219  }

◆ getMemObj()

const MemObj* SVF::IRGraph::getMemObj ( const SVFValue val) const
inlineprotected

get MemObj according to LLVM value

Definition at line 98 of file IRGraph.h.

99  {
100  return symInfo->getObj(symInfo->getObjSym(val));
101  }
MemObj * getObj(SymID id) const
SymID getObjSym(const SVFValue *val) const

◆ getNodeNumAfterPAGBuild()

u32_t SVF::IRGraph::getNodeNumAfterPAGBuild ( ) const
inline

Definition at line 194 of file IRGraph.h.

195  {
196  return nodeNumAfterPAGBuild;
197  }

◆ getNullPtr()

NodeID SVF::IRGraph::getNullPtr ( ) const
inline

Definition at line 173 of file IRGraph.h.

174  {
175  return symInfo->nullPtrSymID();
176  }
SymID nullPtrSymID() const

◆ getObjectNode()

NodeID SVF::IRGraph::getObjectNode ( const SVFValue V)
inline

getObject - Return the obj node id refer to the memory object for the specified global, heap or alloca instruction according to llvm value.

Definition at line 147 of file IRGraph.h.

148  {
149  return symInfo->getObjSym(V);
150  }

◆ getObjectNodeNum()

u32_t SVF::IRGraph::getObjectNodeNum ( ) const
inline

Definition at line 190 of file IRGraph.h.

191  {
192  return symInfo->idToObjMap().size();
193  }
IDToMemMapTy & idToObjMap()

◆ getPAGEdgeNum()

u32_t SVF::IRGraph::getPAGEdgeNum ( ) const
inline

Definition at line 207 of file IRGraph.h.

208  {
209  return edgeNum;
210  }
u32_t edgeNum
total num of node
Definition: GenericGraph.h:702

◆ getPAGNodeNum()

u32_t SVF::IRGraph::getPAGNodeNum ( ) const
inline

Definition at line 203 of file IRGraph.h.

204  {
205  return nodeNum;
206  }
u32_t nodeNum
total num of edge
Definition: GenericGraph.h:703

◆ getPTAPAGEdgeNum()

u32_t SVF::IRGraph::getPTAPAGEdgeNum ( ) const
inline

Definition at line 211 of file IRGraph.h.

212  {
213  return totalPTAPAGEdge;
214  }

◆ getReturnNode()

NodeID SVF::IRGraph::getReturnNode ( const SVFFunction func) const
inline

GetReturnNode - Return the unique node representing the return value of a function.

Definition at line 152 of file IRGraph.h.

153  {
154  return symInfo->getRetSym(func);
155  }
SymID getRetSym(const SVFFunction *val) const

◆ getSymbolInfo()

SymbolTableInfo* SVF::IRGraph::getSymbolInfo ( ) const
inline

Definition at line 114 of file IRGraph.h.

115  {
116  return symInfo;
117  }

◆ getValueEdges()

const SVFStmtSet& SVF::IRGraph::getValueEdges ( const SVFValue V)
inline

Get all SVFIR Edges that corresponds to an LLVM value.

Definition at line 124 of file IRGraph.h.

125  {
126  auto it = valueToEdgeMap.find(V);
127  if (it == valueToEdgeMap.end())
128  {
129  //special empty set
130  return valueToEdgeMap.at(nullptr);
131  }
132  return it->second;
133  }

◆ getValueNode()

NodeID SVF::IRGraph::getValueNode ( const SVFValue V)
inline

Get SVFIR Node according to LLVM value getNode - Return the node corresponding to the specified pointer.

Definition at line 137 of file IRGraph.h.

138  {
139  return symInfo->getValSym(V);
140  }
SymID getValSym(const SVFValue *val)
Get different kinds of syms.

◆ getValueNodeNum()

u32_t SVF::IRGraph::getValueNodeNum ( ) const
inline

Definition at line 186 of file IRGraph.h.

187  {
188  return symInfo->valSyms().size();
189  }
ValueToIDMapTy & valSyms()
Get different kinds of syms maps.

◆ getVarargNode()

NodeID SVF::IRGraph::getVarargNode ( const SVFFunction func) const
inline

getVarargNode - Return the unique node representing the variadic argument of a variadic function.

Definition at line 157 of file IRGraph.h.

158  {
159  return symInfo->getVarargSym(func);
160  }
SymID getVarargSym(const SVFFunction *val) const

◆ hasLabeledEdge() [1/2]

SVFStmt * IRGraph::hasLabeledEdge ( SVFVar src,
SVFVar dst,
SVFStmt::PEDGEK  kind,
const ICFGNode callInst 
)
protected

Return true if this labeled edge exits, including store, call and load two store edge can have same dst and src but located in different basic blocks, thus flags are needed to distinguish them

Return an inter-procedural edge if found

Definition at line 88 of file IRGraph.cpp.

89 {
90  SVFStmt edge(src,dst,SVFStmt::makeEdgeFlagWithCallInst(kind,callInst), false);
91  SVFStmt::SVFStmtSetTy::iterator it = KindToSVFStmtSetMap[kind].find(&edge);
92  if (it != KindToSVFStmtSetMap[kind].end())
93  {
94  return *it;
95  }
96  return nullptr;
97 }
SVFStmt::KindToSVFStmtMapTy KindToSVFStmtSetMap
SVFIR edge map containing all PAGEdges.
Definition: IRGraph.h:59
static GEdgeFlag makeEdgeFlagWithCallInst(GEdgeKind k, const ICFGNode *cs)

◆ hasLabeledEdge() [2/2]

SVFStmt * IRGraph::hasLabeledEdge ( SVFVar src,
SVFVar op1,
SVFStmt::PEDGEK  kind,
const SVFVar op2 
)
protected

Return MultiOpndStmt since it has more than one operands (we use operand 2 here to make the flag)

Return an MultiOpndStmt if found

Definition at line 74 of file IRGraph.cpp.

75 {
76  SVFStmt edge(src,op1,SVFStmt::makeEdgeFlagWithAddionalOpnd(kind,op2), false);
77  SVFStmt::SVFStmtSetTy::iterator it = KindToSVFStmtSetMap[kind].find(&edge);
78  if (it != KindToSVFStmtSetMap[kind].end())
79  {
80  return *it;
81  }
82  return nullptr;
83 }
static GEdgeFlag makeEdgeFlagWithAddionalOpnd(GEdgeKind k, const SVFVar *var)

◆ hasNonlabeledEdge()

SVFStmt * IRGraph::hasNonlabeledEdge ( SVFVar src,
SVFVar dst,
SVFStmt::PEDGEK  kind 
)
protected

Return true if it is an intra-procedural edge

Definition at line 60 of file IRGraph.cpp.

61 {
62  SVFStmt edge(src,dst,kind, false);
63  SVFStmt::SVFStmtSetTy::iterator it = KindToSVFStmtSetMap[kind].find(&edge);
64  if (it != KindToSVFStmtSetMap[kind].end())
65  {
66  return *it;
67  }
68  return nullptr;
69 }

◆ hasValueNode()

bool SVF::IRGraph::hasValueNode ( const SVFValue V)
inline

Definition at line 141 of file IRGraph.h.

142  {
143  return symInfo->hasValSym(V);
144  }
bool hasValSym(const SVFValue *val)

◆ isBuiltFromFile()

bool SVF::IRGraph::isBuiltFromFile ( )
inline

Whether this SVFIR built from a txt file.

Definition at line 119 of file IRGraph.h.

120  {
121  return fromFile;
122  }

◆ mapValueToEdge()

void SVF::IRGraph::mapValueToEdge ( const SVFValue V,
SVFStmt edge 
)
inlineprotected

Map a value to a set of edges.

Definition at line 89 of file IRGraph.h.

90  {
91  auto inserted = valueToEdgeMap.emplace(V, SVFStmtSet{edge});
92  if (!inserted.second)
93  {
94  inserted.first->second.emplace(edge);
95  }
96  }

◆ setNodeNumAfterPAGBuild()

void SVF::IRGraph::setNodeNumAfterPAGBuild ( u32_t  num)
inline

Definition at line 198 of file IRGraph.h.

199  {
200  nodeNumAfterPAGBuild = num;
201  }

◆ view()

void IRGraph::view ( )

View graph from the debugger.

View IRGraph

Definition at line 110 of file IRGraph.cpp.

111 {
112  SVF::ViewGraph(this, "ProgramAssignmentGraph");
113 }
void ViewGraph(const GraphType &G, const std::string &name, bool ShortNames=false, GraphProgram::Name Program=GraphProgram::DOT)
Definition: GraphWriter.h:371

Friends And Related Function Documentation

◆ SVFIRReader

friend class SVFIRReader
friend

Definition at line 52 of file IRGraph.h.

◆ SVFIRWriter

friend class SVFIRWriter
friend

Definition at line 51 of file IRGraph.h.

Member Data Documentation

◆ fromFile

bool SVF::IRGraph::fromFile
protected

Whether the SVFIR is built according to user specified data from a txt file.

Definition at line 61 of file IRGraph.h.

◆ KindToPTASVFStmtSetMap

SVFStmt::KindToSVFStmtMapTy SVF::IRGraph::KindToPTASVFStmtSetMap
protected

SVFIR edge map containing only pointer-related edges, i.e., both LHS and RHS are of pointer type.

Definition at line 60 of file IRGraph.h.

◆ KindToSVFStmtSetMap

SVFStmt::KindToSVFStmtMapTy SVF::IRGraph::KindToSVFStmtSetMap
protected

SVFIR edge map containing all PAGEdges.

Definition at line 59 of file IRGraph.h.

◆ nodeNumAfterPAGBuild

NodeID SVF::IRGraph::nodeNumAfterPAGBuild
protected

initial node number after building SVFIR, excluding later added nodes, e.g., gepobj nodes

Definition at line 62 of file IRGraph.h.

◆ symInfo

SymbolTableInfo* SVF::IRGraph::symInfo
protected

Definition at line 65 of file IRGraph.h.

◆ totalPTAPAGEdge

u32_t SVF::IRGraph::totalPTAPAGEdge
protected

Definition at line 63 of file IRGraph.h.

◆ valueToEdgeMap

ValueToEdgeMap SVF::IRGraph::valueToEdgeMap
protected

Map SVFValues (e.g., ICFGNodes) to all corresponding PAGEdges.

Definition at line 64 of file IRGraph.h.


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