53 for (SVFStmt::SVFStmtSetTy::iterator iter = addrs.begin(), eiter =
54 addrs.end(); iter != eiter; ++iter)
61 for (SVFStmt::SVFStmtSetTy::iterator iter = copys.begin(), eiter =
62 copys.end(); iter != eiter; ++iter)
70 for (SVFStmt::SVFStmtSetTy::iterator iter = phis.begin(), eiter =
71 phis.end(); iter != eiter; ++iter)
79 for (SVFStmt::SVFStmtSetTy::iterator iter = selects.begin(), eiter =
80 selects.end(); iter != eiter; ++iter)
88 for (SVFStmt::SVFStmtSetTy::iterator iter = calls.begin(), eiter =
89 calls.end(); iter != eiter; ++iter)
97 for (SVFStmt::SVFStmtSetTy::iterator iter = rets.begin(), eiter =
98 rets.end(); iter != eiter; ++iter)
105 for (SVFStmt::SVFStmtSetTy::iterator iter = tdfks.begin(), eiter =
106 tdfks.end(); iter != eiter; ++iter)
114 for (SVFStmt::SVFStmtSetTy::iterator iter = tdjns.begin(), eiter =
115 tdjns.end(); iter != eiter; ++iter)
122 for (SVFStmt::SVFStmtSetTy::iterator iter = ngeps.begin(), eiter =
123 ngeps.end(); iter != eiter; ++iter)
133 for (SVFStmt::SVFStmtSetTy::iterator iter = loads.begin(), eiter =
134 loads.end(); iter != eiter; ++iter)
141 for (SVFStmt::SVFStmtSetTy::iterator iter = stores.begin(), eiter =
142 stores.end(); iter != eiter; ++iter)
158 for(
auto cs_pair :
pag->getIndirectCallsites())
160 const RetICFGNode* retBlockNode = cs_pair.first->getRetICFGNode();
161 if(
pag->callsiteHasRet(retBlockNode))
162 retFromIndCalls.insert(
pag->getCallSiteRet(retBlockNode)->getId());
166 for (
auto it = this->
begin(); it != this->
end(); ++it)
168 if (it->second->hasIncomingEdge() || it->second->hasOutgoingEdge())
170 if (
pag->getSVFVar(it->first)->isPointer())
172 if (retFromIndCalls.find(it->first)!=retFromIndCalls.end())
174 nodesToRemove.insert(it->second);
177 for (
auto node : nodesToRemove)
216 assert(inserted &&
"new AddrCGEdge not added??");
238 assert(inserted &&
"new CopyCGEdge not added??");
261 assert(inserted &&
"new NormalGepCGEdge not added??");
282 assert(inserted &&
"new VariantGepCGEdge not added??");
303 assert(inserted &&
"new LoadCGEdge not added??");
324 assert(inserted &&
"new StoreCGEdge not added??");
374 assert(
false &&
"no other edge type!!");
418 assert(
false &&
"no other edge type!!");
430 assert(num &&
"edge not in the set, can not remove!!!");
443 assert(num &&
"edge not in the set, can not remove!!!");
456 assert(num &&
"edge not in the set, can not remove!!!");
470 assert(num &&
"edge not in the set, can not remove!!!");
480 std::vector<ConstraintEdge*> sccEdges;
481 std::vector<ConstraintEdge*> nonSccEdges;
487 nonSccEdges.push_back(subInEdge);
490 sccEdges.push_back(subInEdge);
494 while(!nonSccEdges.empty())
497 nonSccEdges.pop_back();
501 bool criticalGepInsideSCC =
false;
503 while(!sccEdges.empty())
516 criticalGepInsideSCC =
true;
527 assert(
false &&
"no such edge");
529 return criticalGepInsideSCC;
539 std::vector<ConstraintEdge*> sccEdges;
540 std::vector<ConstraintEdge*> nonSccEdges;
547 nonSccEdges.push_back(subOutEdge);
550 sccEdges.push_back(subOutEdge);
554 while(!nonSccEdges.empty())
557 nonSccEdges.pop_back();
560 bool criticalGepInsideSCC =
false;
562 while(!sccEdges.empty())
575 criticalGepInsideSCC =
true;
586 assert(
false &&
"no such edge");
588 return criticalGepInsideSCC;
606 outs() <<
"-----------------ConstraintGraph--------------------------------------\n";
609 for (ConstraintEdge::ConstraintEdgeSetTy::iterator iter = addrs.begin(),
610 eiter = addrs.end(); iter != eiter; ++iter)
612 outs() << (*iter)->getSrcID() <<
" -- Addr --> " << (*iter)->getDstID()
617 for (ConstraintEdge::ConstraintEdgeSetTy::iterator iter = directs.begin(),
618 eiter = directs.end(); iter != eiter; ++iter)
622 outs() <<
copy->getSrcID() <<
" -- Copy --> " <<
copy->getDstID()
627 outs() << ngep->getSrcID() <<
" -- NormalGep (" << ngep->getConstantFieldIdx()
628 <<
") --> " << ngep->getDstID() <<
"\n";
632 outs() <<
vgep->getSrcID() <<
" -- VarintGep --> "
633 <<
vgep->getDstID() <<
"\n";
636 assert(
false &&
"wrong constraint edge kind!");
640 for (ConstraintEdge::ConstraintEdgeSetTy::iterator iter = loads.begin(),
641 eiter = loads.end(); iter != eiter; ++iter)
643 outs() << (*iter)->getSrcID() <<
" -- Load --> " << (*iter)->getDstID()
648 for (ConstraintEdge::ConstraintEdgeSetTy::iterator iter = stores.begin(),
649 eiter = stores.end(); iter != eiter; ++iter)
651 outs() << (*iter)->getSrcID() <<
" -- Store --> " << (*iter)->getDstID()
656 <<
"--------------------------------------------------------------\n";
758 return "ConstraintG";
764 else return (
n->getInEdges().empty() &&
n->getOutEdges().empty());
773 bool nameDisplay =
true;
775 std::stringstream rawstr(str);
784 rawstr << node->
getId();
787 rawstr << node->
getId();
795 rawstr << node->
getId() <<
":";
808 return "shape=hexagon";
810 return "shape=diamond";
817 return "shape=doubleoctagon";
819 return "shape=box3d";
823 return "shape=component";
827 return "shape=Mrecord";
831 return "shape=octagon";
835 assert(0 &&
"no such kind!!");
840 template<
class EdgeIter>
844 assert(edge &&
"No edge found!!");
847 return "color=green";
851 return "color=black";
856 return "color=\"purple:purple\"";
868 assert(0 &&
"No such kind edge!!");
873 template<
class EdgeIter>
NodeID getRHSVarID() const
NodeID getLHSVarID() const
ConstraintEdge(ConstraintNode *s, ConstraintNode *d, ConstraintEdgeK k, EdgeID id=0)
Constructor.
GenericNode< ConstraintNode, ConstraintEdge >::GEdgeSetTy ConstraintEdgeSetTy
Constraint edge type.
bool moveInEdgesToRepNode(ConstraintNode *node, ConstraintNode *rep)
ConstraintEdge::ConstraintEdgeSetTy StoreCGEdgeSet
ConstraintEdge::ConstraintEdgeSetTy directEdgeSet
ConstraintEdge::ConstraintEdgeSetTy LoadCGEdgeSet
LoadCGEdge * addLoadCGEdge(NodeID src, NodeID dst)
Add Load edge.
void view()
View graph from the debugger.
NodeID sccRepNode(NodeID id) const
SCC rep/sub nodes methods.
ConstraintEdge::ConstraintEdgeSetTy & getStoreCGEdges()
Get Store edges.
ConstraintEdge::ConstraintEdgeSetTy & getDirectCGEdges()
Get Copy/call/ret/gep edges.
void reTargetDstOfEdge(ConstraintEdge *edge, ConstraintNode *newDstNode)
Used for cycle elimination.
AddrCGEdge * addAddrCGEdge(NodeID src, NodeID dst)
Add a SVFIR edge into Edge map.
ConstraintEdge::ConstraintEdgeSetTy AddrCGEdgeSet
void addConstraintNode(ConstraintNode *node, NodeID id)
bool hasEdge(ConstraintNode *src, ConstraintNode *dst, ConstraintEdge::ConstraintEdgeK kind)
ConstraintEdge::ConstraintEdgeSetTy & getLoadCGEdges()
Get Load edges.
CopyCGEdge * addCopyCGEdge(NodeID src, NodeID dst)
Add Copy edge.
StoreCGEdge * addStoreCGEdge(NodeID src, NodeID dst)
Add Store edge.
VariantGepCGEdge * addVariantGepCGEdge(NodeID src, NodeID dst)
SVFStmt::SVFStmtSetTy & getSVFStmtSet(SVFStmt::PEDGEK kind)
void removeConstraintNode(ConstraintNode *node)
void removeDirectEdge(ConstraintEdge *edge)
Remove direct edge from their src and dst edge sets.
bool moveOutEdgesToRepNode(ConstraintNode *node, ConstraintNode *rep)
void removeLoadEdge(LoadCGEdge *edge)
Remove load edge from their src and dst edge sets.
ConstraintNode * getConstraintNode(NodeID id) const
Get/add/remove constraint node.
void print()
Print CG into terminal.
void reTargetSrcOfEdge(ConstraintEdge *edge, ConstraintNode *newSrcNode)
Remove edge from old src target, change edge dst id and add modified edge into new src.
void removeStoreEdge(StoreCGEdge *edge)
Remove store edge from their src and dst edge sets.
NormalGepCGEdge * addNormalGepCGEdge(NodeID src, NodeID dst, const AccessPath &ap)
Add Gep edge.
ConstraintEdge::ConstraintEdgeSetTy & getAddrCGEdges()
Get SVFIR edge.
void removeAddrEdge(AddrCGEdge *edge)
Remove addr edge from their src and dst edge sets.
bool isZeroOffsettedGepCGEdge(ConstraintEdge *edge) const
Check if a given edge is a NormalGepCGEdge with 0 offset.
void dump(std::string name)
Dump graph into dot file.
ConstraintEdge::ConstraintEdgeSetTy copyOutEdges
bool addOutgoingStoreEdge(StoreCGEdge *outEdge)
ConstraintEdge::ConstraintEdgeSetTy::iterator iterator
iterator directInEdgeEnd()
void addIncomingStoreEdge(StoreCGEdge *inEdge)
void addOutgoingCopyEdge(CopyCGEdge *outEdge)
bool removeOutgoingStoreEdge(StoreCGEdge *outEdge)
bool removeIncomingStoreEdge(StoreCGEdge *inEdge)
ConstraintEdge::ConstraintEdgeSetTy copyInEdges
ConstraintEdge::ConstraintEdgeSetTy directInEdges
bool removeIncomingAddrEdge(AddrCGEdge *inEdge)
virtual const std::string toString() const
bool removeOutgoingDirectEdge(ConstraintEdge *outEdge)
bool removeIncomingDirectEdge(ConstraintEdge *inEdge)
bool removeOutgoingLoadEdge(LoadCGEdge *outEdge)
iterator directInEdgeBegin()
void addIncomingLoadEdge(LoadCGEdge *inEdge)
bool removeIncomingLoadEdge(LoadCGEdge *inEdge)
iterator directOutEdgeEnd()
bool addOutgoingLoadEdge(LoadCGEdge *outEdge)
void addIncomingGepEdge(GepCGEdge *inEdge)
ConstraintEdge::ConstraintEdgeSetTy::const_iterator const_iterator
bool removeOutgoingAddrEdge(AddrCGEdge *outEdge)
Remove constraint graph edges.
void addOutgoingGepEdge(GepCGEdge *outEdge)
void addIncomingCopyEdge(CopyCGEdge *inEdge)
Add constraint graph edges.
iterator directOutEdgeBegin()
Iterators.
void addIncomingAddrEdge(AddrCGEdge *inEdge)
void addOutgoingAddrEdge(AddrCGEdge *outEdge)
ConstraintEdge::ConstraintEdgeSetTy directOutEdges
GEdgeKind getEdgeKind() const
NodeID getSrcID() const
get methods of the components
IDToNodeMapTy::iterator iterator
iterator OutEdgeBegin()
iterators
bool isVariantFieldGep() const
Gep statement with a variant field index (pointer arithmetic) for struct field access.
const AccessPath & getAccessPath() const
static void WriteGraphToFile(SVF::OutStream &O, const std::string &GraphName, const GraphType >, bool simple=false)
const OPVars & getOpndVars() const
NodeID getOpVarID(u32_t pos) const
u32_t getOpVarNum() const
static const Option< bool > BriefConsCGDotGraph
static Option< bool > DetectPWC
static const Option< bool > ShowHiddenNode
static bool pagReadFromTXT()
const SVFVar * getSVFVar(NodeID id) const
ObjVar/GepObjVar/BaseObjVar.
static SVFIR * getPAG(bool buildFromFile=false)
Singleton design here to make sure we only have one instance during any analysis.
GenericNode< SVFVar, SVFStmt >::GEdgeSetTy SVFStmtSetTy
NodeID getId() const
Get ID.
virtual const std::string & getName() const
virtual const std::string toString() const
Get string representation.
std::enable_if_t<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type > cast(const Y &Val)
LLVM_NODISCARD bool isa(const Y &Val)
std::ostream & outs()
Overwrite llvm::outs().
LLVM_NODISCARD std::enable_if_t<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type > dyn_cast(const Y &Val)
void ViewGraph(const GraphType &G, const std::string &name, bool ShortNames=false, GraphProgram::Name Program=GraphProgram::DOT)
std::unordered_set< Key, Hash, KeyEqual, Allocator > Set
static std::string getNodeAttributes(NodeType *n, ConstraintGraph *)
static std::string getEdgeSourceLabel(NodeType *, EdgeIter)
static std::string getGraphName(ConstraintGraph *)
Return name of the graph.
static std::string getEdgeAttributes(NodeType *, EdgeIter EI, ConstraintGraph *)
static std::string getNodeLabel(NodeType *n, ConstraintGraph *)
static bool isNodeHidden(NodeType *n, ConstraintGraph *)
DOTGraphTraits(bool isSimple=false)