Skip to content

Commit

Permalink
small chantes
Browse files Browse the repository at this point in the history
  • Loading branch information
hwg committed Oct 29, 2024
1 parent 580802a commit 82cbdf1
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 82 deletions.
76 changes: 29 additions & 47 deletions svf/include/Graphs/CallGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class CallGraphEdge : public GenericCallGraphEdgeTy
typedef Set<const CallICFGNode*> CallInstSet;
enum CEDGEK
{
CallRetEdge,TDForkEdge,TDJoinEdge,HareParForEdge
CallRetEdge
};


Expand All @@ -77,21 +77,11 @@ class CallGraphEdge : public GenericCallGraphEdgeTy
{
return (cs << EdgeKindMaskBits) | k;
}
/// Get direct and indirect calls
//@{
/// Get direct calls
inline CallSiteID getCallSiteID() const
{
return csId;
}
inline CallInstSet& getDirectCalls()
{
return directCalls;
}
inline const CallInstSet& getDirectCalls() const
{
return directCalls;
}
//@}

/// Add direct callsite
//@{
Expand All @@ -118,9 +108,7 @@ class CallGraphEdge : public GenericCallGraphEdgeTy
}
static inline bool classof(const GenericCallGraphEdgeTy *edge)
{
return edge->getEdgeKind() == CallGraphEdge::CallRetEdge ||
edge->getEdgeKind() == CallGraphEdge::TDForkEdge ||
edge->getEdgeKind() == CallGraphEdge::TDJoinEdge;
return edge->getEdgeKind() == CallGraphEdge::CallRetEdge;
}
//@}

Expand Down Expand Up @@ -241,6 +229,30 @@ class CallGraph : public GenericCallGraphTy
/// Clean up memory
void destroy();

/// Add CallSiteID
inline CallSiteID addCallSite(const CallICFGNode* cs, const SVFFunction* callee)
{
std::pair<const CallICFGNode*, const SVFFunction*> newCS(std::make_pair(cs, callee));
CallSiteToIdMap::const_iterator it = csToIdMap.find(newCS);
//assert(it == csToIdMap.end() && "cannot add a callsite twice");
if(it == csToIdMap.end())
{
CallSiteID id = totalCallSiteNum++;
csToIdMap.insert(std::make_pair(newCS, id));
idToCSMap.insert(std::make_pair(id, newCS));
return id;
}
return it->second;
}

/// Add call graph edge
inline void addEdge(CallGraphEdge* edge)
{
edge->getDstNode()->addIncomingEdge(edge);
edge->getSrcNode()->addOutgoingEdge(edge);
}


public:
/// Constructor
CallGraph(CGEK k = NormCallGraph);
Expand Down Expand Up @@ -274,42 +286,12 @@ class CallGraph : public GenericCallGraphTy

//@}

/// Add/Get CallSiteID
//@{
inline CallSiteID addCallSite(const CallICFGNode* cs, const SVFFunction* callee)
{
std::pair<const CallICFGNode*, const SVFFunction*> newCS(std::make_pair(cs, callee));
CallSiteToIdMap::const_iterator it = csToIdMap.find(newCS);
//assert(it == csToIdMap.end() && "cannot add a callsite twice");
if(it == csToIdMap.end())
{
CallSiteID id = totalCallSiteNum++;
csToIdMap.insert(std::make_pair(newCS, id));
idToCSMap.insert(std::make_pair(id, newCS));
return id;
}
return it->second;
}
//@}

/// Whether we have already created this call graph edge
CallGraphEdge* hasGraphEdge(CallGraphNode* src, CallGraphNode* dst,
CallGraphEdge::CEDGEK kind, CallSiteID csId) const;


/// Add call graph edge
inline void addEdge(CallGraphEdge* edge)
{
edge->getDstNode()->addIncomingEdge(edge);
edge->getSrcNode()->addOutgoingEdge(edge);
}
CallGraphEdge::CEDGEK kind, CallSiteID csId) const;

/// Add direct/indirect call edges
//@{
/// Add direct call edges
void addDirectCallGraphEdge(const CallICFGNode* call, const SVFFunction* callerFun, const SVFFunction* calleeFun);
//@}


/// Dump the graph
void dump(const std::string& filename);

Expand Down
47 changes: 26 additions & 21 deletions svf/include/Graphs/PTACallGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,30 @@ class PTACallGraph : public GenericPTACallGraphTy
/// Clean up memory
void destroy();

protected:
/// Add CallSiteID
inline CallSiteID addCallSite(const CallICFGNode* cs, const SVFFunction* callee)
{
std::pair<const CallICFGNode*, const SVFFunction*> newCS(std::make_pair(cs, callee));
CallSiteToIdMap::const_iterator it = csToIdMap.find(newCS);
//assert(it == csToIdMap.end() && "cannot add a callsite twice");
if(it == csToIdMap.end())
{
CallSiteID id = totalCallSiteNum++;
csToIdMap.insert(std::make_pair(newCS, id));
idToCSMap.insert(std::make_pair(id, newCS));
return id;
}
return it->second;
}

/// Add call graph edge
inline void addEdge(PTACallGraphEdge* edge)
{
edge->getDstNode()->addIncomingEdge(edge);
edge->getSrcNode()->addOutgoingEdge(edge);
}

public:
/// Constructor
PTACallGraph(CGEK k = NormCallGraph);
Expand Down Expand Up @@ -348,22 +372,8 @@ class PTACallGraph : public GenericPTACallGraphTy

//@}

/// Add/Get CallSiteID
/// Get CallSiteID
//@{
inline CallSiteID addCallSite(const CallICFGNode* cs, const SVFFunction* callee)
{
std::pair<const CallICFGNode*, const SVFFunction*> newCS(std::make_pair(cs, callee));
CallSiteToIdMap::const_iterator it = csToIdMap.find(newCS);
//assert(it == csToIdMap.end() && "cannot add a callsite twice");
if(it == csToIdMap.end())
{
CallSiteID id = totalCallSiteNum++;
csToIdMap.insert(std::make_pair(newCS, id));
idToCSMap.insert(std::make_pair(id, newCS));
return id;
}
return it->second;
}
inline CallSiteID getCallSiteID(const CallICFGNode* cs, const SVFFunction* callee) const
{
CallSitePair newCS(std::make_pair(cs, callee));
Expand Down Expand Up @@ -438,12 +448,7 @@ class PTACallGraph : public GenericPTACallGraphTy
return it->second.end();
}
//@}
/// Add call graph edge
inline void addEdge(PTACallGraphEdge* edge)
{
edge->getDstNode()->addIncomingEdge(edge);
edge->getSrcNode()->addOutgoingEdge(edge);
}


/// Add indirect call edges
//@{
Expand Down
15 changes: 1 addition & 14 deletions svf/lib/Graphs/CallGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,20 +196,7 @@ struct DOTGraphTraits<CallGraph*> : public DefaultDOTGraphTraits
CallGraphEdge* edge = *(EI.getCurrent());
assert(edge && "No edge found!!");

std::string color;

if (edge->getEdgeKind() == CallGraphEdge::TDJoinEdge)
{
color = "color=green";
}
else if (edge->getEdgeKind() == CallGraphEdge::TDForkEdge)
{
color = "color=blue";
}
else
{
color = "color=black";
}
std::string color = "color=black";
return color;
}

Expand Down

0 comments on commit 82cbdf1

Please sign in to comment.