Static Value-Flow Analysis
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
SVF::SlicedThreadCallGraphView Class Reference

#include <SlicedGraphs.h>

Public Member Functions

 SlicedThreadCallGraphView (ThreadCallGraph *tcg, const OrderedSet< const FunObjVar * > &keptFunctions, const OrderedSet< const ICFGNode * > &extendedKeptNodes)
 
void getOutEdgesOf (const CallGraphNode *node, std::vector< const CallGraphEdge * > &out) const
 Get out edges of a node (only returns kept edges and target nodes)
 
void getInEdgesOf (const CallGraphNode *node, std::vector< const CallGraphEdge * > &out) const
 Get in edges of a node (only returns kept edges and source nodes)
 
void getDirectCallsOf (const CallGraphEdge *edge, std::vector< const CallICFGNode * > &out) const
 Retained callsites carried by an aggregated call-graph edge.
 
void getIndirectCallsOf (const CallGraphEdge *edge, std::vector< const CallICFGNode * > &out) const
 
bool containsCallSite (const CallGraphEdge *edge, const CallICFGNode *callSite) const
 Whether this precise callsite-to-callee relation is retained.
 
void getCalleesOf (const CallICFGNode *callSite, CallGraph::FunctionSet &callees) const
 Retained callees of a callsite.
 
void getForkEdgesOf (const CallICFGNode *callSite, std::vector< const CallGraphEdge * > &out) const
 
void getJoinEdgesOf (const CallICFGNode *callSite, std::vector< const CallGraphEdge * > &out) const
 
bool isKeptNode (const CallGraphNode *node) const
 Check if a node is in the sliced view.
 
const OrderedSet< const CallGraphNode * > & getKeptNodes () const
 Get all kept nodes.
 
const Set< const FunObjVar * > & getKeptFunctions () const
 
bool isKeptEdge (const CallGraphEdge *e) const
 
const Set< const CallICFGNode * > & getIndirectSitesWithEmptyTargets () const
 Indirect call sites that lost all targets after filtering.
 
void dump (const std::string &filename) const
 Dump sliced ThreadCallGraph to dot file.
 
CallGraphgetBackingCallGraph () const
 

Private Member Functions

void buildKeptNodes ()
 
void buildCallGraphSets ()
 

Private Attributes

ThreadCallGraphtcg
 
OrderedSet< const CallGraphNode * > keptNodes
 
Set< const CallGraphEdge * > keptEdges
 
Map< const CallGraphEdge *, CallGraphEdge::CallInstSetkeptDirectCalls
 
Map< const CallGraphEdge *, CallGraphEdge::CallInstSetkeptIndirectCalls
 
Set< const FunObjVar * > keptFunctionsSet
 
Set< const CallICFGNode * > indirectSitesWithEmptyTargets
 
OrderedSet< const ICFGNode * > extendedKeptNodes
 

Detailed Description

Definition at line 176 of file SlicedGraphs.h.

Constructor & Destructor Documentation

◆ SlicedThreadCallGraphView()

SVF::SlicedThreadCallGraphView::SlicedThreadCallGraphView ( ThreadCallGraph tcg,
const OrderedSet< const FunObjVar * > &  keptFunctions,
const OrderedSet< const ICFGNode * > &  extendedKeptNodes 
)

Definition at line 591 of file SlicedGraphs.cpp.

594 : tcg(tcg)
595{
596 for (const FunObjVar* fun : keptFunctions)
597 {
598 keptFunctionsSet.insert(fun);
599 }
602 // The input already contains the slicing targets and control-flow anchors;
603 // buildCallGraphSets filters edges whose callsites were pruned.
605}
Set< const FunObjVar * > keptFunctionsSet
OrderedSet< const ICFGNode * > extendedKeptNodes
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:76

Member Function Documentation

◆ buildCallGraphSets()

void SVF::SlicedThreadCallGraphView::buildCallGraphSets ( )
private

Definition at line 741 of file SlicedGraphs.cpp.

742{
743 // rebuild kept edges, accounting for whether the call site is kept
744 keptEdges.clear();
745 keptDirectCalls.clear();
746 keptIndirectCalls.clear();
748
749 // CallGraph edge: src/dst both in kept functions and the call site still in the kept ICFG node set
750 for (const CallGraphNode* srcNode : keptNodes)
751 {
752 for (const CallGraphEdge* edge : srcNode->getOutEdges())
753 {
754 const CallGraphNode* dstNode = edge ? edge->getDstNode() : nullptr;
755 if (dstNode == nullptr || !keptNodes.count(dstNode))
756 {
757 continue;
758 }
759
761 for (const CallICFGNode* callSite : edge->getDirectCalls())
763 retainedDirect.insert(callSite);
764
766 for (const CallICFGNode* callSite : edge->getIndirectCalls())
769
770 const bool hasOriginalCallSites =
771 !edge->getDirectCalls().empty() || !edge->getIndirectCalls().empty();
772 if (hasOriginalCallSites && retainedDirect.empty() && retainedIndirect.empty())
773 {
774 keptDirectCalls.erase(edge);
775 keptIndirectCalls.erase(edge);
776 continue;
777 }
778
779 keptEdges.insert(edge);
780 }
781 }
782
783 // An indirect callsite is empty only when none of its original targets is
784 // represented by a retained callsite-to-callee relation.
785 for (const ICFGNode* node : extendedKeptNodes)
786 {
787 const CallICFGNode* callSite = SVFUtil::dyn_cast<CallICFGNode>(node);
788 if (callSite == nullptr || !tcg->hasIndCSCallees(callSite))
789 continue;
792 if (callees.empty())
794 }
795}
if(prebuffer< 0)
Definition cJSON.cpp:1269
int count
Definition cJSON.h:216
Set< const CallICFGNode * > CallInstSet
Definition CallGraph.h:55
bool hasIndCSCallees(const CallICFGNode *cs) const
Definition CallGraph.h:335
Set< const FunObjVar * > FunctionSet
Definition CallGraph.h:247
void getCalleesOf(const CallICFGNode *callSite, CallGraph::FunctionSet &callees) const
Retained callees of a callsite.
OrderedSet< const CallGraphNode * > keptNodes
Set< const CallGraphEdge * > keptEdges
Map< const CallGraphEdge *, CallGraphEdge::CallInstSet > keptDirectCalls
Set< const CallICFGNode * > indirectSitesWithEmptyTargets
Map< const CallGraphEdge *, CallGraphEdge::CallInstSet > keptIndirectCalls

◆ buildKeptNodes()

void SVF::SlicedThreadCallGraphView::buildKeptNodes ( )
private

Definition at line 607 of file SlicedGraphs.cpp.

608{
609 for (CallGraph::iterator it = tcg->begin(), eit = tcg->end();
610 it != eit; ++it)
611 {
612 const CallGraphNode* node = it->second;
613 if (node != nullptr && node->getFunction() != nullptr &&
614 keptFunctionsSet.count(node->getFunction()))
615 {
616 keptNodes.insert(node);
617 }
618 }
619}
const FunObjVar * getFunction() const
Get function of this call node.
Definition CallGraph.h:191
iterator begin()
Iterators.
IDToNodeMapTy::iterator iterator
Node Iterators.

◆ containsCallSite()

bool SVF::SlicedThreadCallGraphView::containsCallSite ( const CallGraphEdge edge,
const CallICFGNode callSite 
) const

Whether this precise callsite-to-callee relation is retained.

Definition at line 668 of file SlicedGraphs.cpp.

670{
671 const auto direct = keptDirectCalls.find(edge);
672 if (direct != keptDirectCalls.end() && direct->second.count(callSite))
673 return true;
674 const auto indirect = keptIndirectCalls.find(edge);
675 return indirect != keptIndirectCalls.end() &&
676 indirect->second.count(callSite);
677}

◆ dump()

void SVF::SlicedThreadCallGraphView::dump ( const std::string &  filename) const

Dump sliced ThreadCallGraph to dot file.

Definition at line 797 of file SlicedGraphs.cpp.

798{
799 // Kept nodes + canonical kept edges via GenericGraphTraits; join edges are
800 // not in the normal adjacency, so they are not drawn here.
802}
static void WriteGraphToFile(SVF::OutStream &O, const std::string &GraphName, const GraphType &GT, bool simple=false)
std::ostream & outs()
Overwrite llvm::outs()
Definition SVFUtil.h:52

◆ getBackingCallGraph()

CallGraph * SVF::SlicedThreadCallGraphView::getBackingCallGraph ( ) const
inline

Backing graph access for the graph-traits implementation only. Analysis traversal must use this view's filtered methods above.

Definition at line 242 of file SlicedGraphs.h.

243 {
244 return tcg;
245 }

◆ getCalleesOf()

void SVF::SlicedThreadCallGraphView::getCalleesOf ( const CallICFGNode callSite,
CallGraph::FunctionSet callees 
) const

Retained callees of a callsite.

Definition at line 679 of file SlicedGraphs.cpp.

681{
682 callees.clear();
683 const CallGraphNode* caller = tcg->getCallGraphNode(callSite->getFun());
684 if (!isKeptNode(caller))
685 {
686 return;
687 }
688 std::vector<const CallGraphEdge*> outEdges;
690 for (const CallGraphEdge* edge : outEdges)
691 {
693 {
694 callees.insert(edge->getDstNode()->getFunction());
695 }
696 }
697}
const CallGraphNode * getCallGraphNode(const std::string &name) const
Get call graph node.
bool isKeptNode(const CallGraphNode *node) const
Check if a node is in the sliced view.
bool containsCallSite(const CallGraphEdge *edge, const CallICFGNode *callSite) const
Whether this precise callsite-to-callee relation is retained.
void getOutEdgesOf(const CallGraphNode *node, std::vector< const CallGraphEdge * > &out) const
Get out edges of a node (only returns kept edges and target nodes)

◆ getDirectCallsOf()

void SVF::SlicedThreadCallGraphView::getDirectCallsOf ( const CallGraphEdge edge,
std::vector< const CallICFGNode * > &  out 
) const

Retained callsites carried by an aggregated call-graph edge.

Definition at line 650 of file SlicedGraphs.cpp.

652{
653 out.clear();
654 const auto found = keptDirectCalls.find(edge);
655 if (found != keptDirectCalls.end())
656 out.insert(out.end(), found->second.begin(), found->second.end());
657}

◆ getForkEdgesOf()

void SVF::SlicedThreadCallGraphView::getForkEdgesOf ( const CallICFGNode callSite,
std::vector< const CallGraphEdge * > &  out 
) const

Retained thread relations indexed by their fork/join callsite. Join relations are deliberately separate from normal CallGraph adjacency.

Definition at line 699 of file SlicedGraphs.cpp.

702{
703 out.clear();
704 if (!extendedKeptNodes.count(callSite) ||
706 return;
707 for (auto it = tcg->getForkEdgeBegin(callSite),
708 end = tcg->getForkEdgeEnd(callSite); it != end; ++it)
709 {
710 const CallGraphEdge* edge = *it;
711 if (isKeptNode(edge->getSrcNode()) &&
712 isKeptNode(edge->getDstNode()) &&
714 out.push_back(edge);
715 }
716}
ForkEdgeSet::const_iterator getForkEdgeEnd(const CallICFGNode *cs) const
ForkEdgeSet::const_iterator getForkEdgeBegin(const CallICFGNode *cs) const
bool hasThreadForkEdge(const CallICFGNode *cs) const
Get call graph edge via call instruction.

◆ getIndirectCallsOf()

void SVF::SlicedThreadCallGraphView::getIndirectCallsOf ( const CallGraphEdge edge,
std::vector< const CallICFGNode * > &  out 
) const

Definition at line 659 of file SlicedGraphs.cpp.

661{
662 out.clear();
663 const auto found = keptIndirectCalls.find(edge);
664 if (found != keptIndirectCalls.end())
665 out.insert(out.end(), found->second.begin(), found->second.end());
666}

◆ getIndirectSitesWithEmptyTargets()

const Set< const CallICFGNode * > & SVF::SlicedThreadCallGraphView::getIndirectSitesWithEmptyTargets ( ) const
inline

Indirect call sites that lost all targets after filtering.

Definition at line 232 of file SlicedGraphs.h.

233 {
235 }

◆ getInEdgesOf()

void SVF::SlicedThreadCallGraphView::getInEdgesOf ( const CallGraphNode node,
std::vector< const CallGraphEdge * > &  out 
) const

Get in edges of a node (only returns kept edges and source nodes)

Definition at line 636 of file SlicedGraphs.cpp.

638{
639 out.clear();
640 if (!isKeptNode(node))
641 {
642 return;
643 }
645 const SlicedCallGraphNodeRef n{this, node};
646 for (auto it = GT::child_edge_begin(n), e = GT::child_edge_end(n); it != e; ++it)
647 out.push_back((*it).underlying);
648}
cJSON * n
Definition cJSON.cpp:2558

◆ getJoinEdgesOf()

void SVF::SlicedThreadCallGraphView::getJoinEdgesOf ( const CallICFGNode callSite,
std::vector< const CallGraphEdge * > &  out 
) const

Definition at line 718 of file SlicedGraphs.cpp.

721{
722 out.clear();
723 if (!extendedKeptNodes.count(callSite) ||
725 return;
726 for (auto it = tcg->getJoinEdgeBegin(callSite),
727 end = tcg->getJoinEdgeEnd(callSite); it != end; ++it)
728 {
729 const CallGraphEdge* edge = *it;
730 if (isKeptNode(edge->getSrcNode()) &&
731 isKeptNode(edge->getDstNode()))
732 out.push_back(edge);
733 }
734}
bool hasThreadJoinEdge(const CallICFGNode *cs) const
Get call graph edge via call instruction.
JoinEdgeSet::const_iterator getJoinEdgeEnd(const CallICFGNode *cs) const
JoinEdgeSet::const_iterator getJoinEdgeBegin(const CallICFGNode *cs) const

◆ getKeptFunctions()

const Set< const FunObjVar * > & SVF::SlicedThreadCallGraphView::getKeptFunctions ( ) const
inline

Definition at line 219 of file SlicedGraphs.h.

220 {
221 return keptFunctionsSet;
222 }

◆ getKeptNodes()

const OrderedSet< const CallGraphNode * > & SVF::SlicedThreadCallGraphView::getKeptNodes ( ) const
inline

Get all kept nodes.

Definition at line 214 of file SlicedGraphs.h.

215 {
216 return keptNodes;
217 }

◆ getOutEdgesOf()

void SVF::SlicedThreadCallGraphView::getOutEdgesOf ( const CallGraphNode node,
std::vector< const CallGraphEdge * > &  out 
) const

Get out edges of a node (only returns kept edges and target nodes)

Definition at line 621 of file SlicedGraphs.cpp.

623{
624 out.clear();
625 if (!isKeptNode(node))
626 {
627 return;
628 }
629
631 const SlicedCallGraphNodeRef n{this, node};
632 for (auto it = GT::child_edge_begin(n), e = GT::child_edge_end(n); it != e; ++it)
633 out.push_back((*it).underlying);
634}

◆ isKeptEdge()

bool SVF::SlicedThreadCallGraphView::isKeptEdge ( const CallGraphEdge e) const
inline

Canonical edge membership: keptEdges excludes edges whose call site was pruned, so endpoint checks alone are not enough (queries/traits use this).

Definition at line 226 of file SlicedGraphs.h.

227 {
228 return keptEdges.find(e) != keptEdges.end();
229 }

◆ isKeptNode()

bool SVF::SlicedThreadCallGraphView::isKeptNode ( const CallGraphNode node) const

Check if a node is in the sliced view.

Definition at line 736 of file SlicedGraphs.cpp.

737{
738 return keptNodes.count(node) > 0;
739}

Member Data Documentation

◆ extendedKeptNodes

OrderedSet<const ICFGNode*> SVF::SlicedThreadCallGraphView::extendedKeptNodes
private

Definition at line 255 of file SlicedGraphs.h.

◆ indirectSitesWithEmptyTargets

Set<const CallICFGNode*> SVF::SlicedThreadCallGraphView::indirectSitesWithEmptyTargets
private

Definition at line 254 of file SlicedGraphs.h.

◆ keptDirectCalls

Map<const CallGraphEdge*, CallGraphEdge::CallInstSet> SVF::SlicedThreadCallGraphView::keptDirectCalls
private

Definition at line 251 of file SlicedGraphs.h.

◆ keptEdges

Set<const CallGraphEdge*> SVF::SlicedThreadCallGraphView::keptEdges
private

Definition at line 250 of file SlicedGraphs.h.

◆ keptFunctionsSet

Set<const FunObjVar*> SVF::SlicedThreadCallGraphView::keptFunctionsSet
private

Definition at line 253 of file SlicedGraphs.h.

◆ keptIndirectCalls

Map<const CallGraphEdge*, CallGraphEdge::CallInstSet> SVF::SlicedThreadCallGraphView::keptIndirectCalls
private

Definition at line 252 of file SlicedGraphs.h.

◆ keptNodes

OrderedSet<const CallGraphNode*> SVF::SlicedThreadCallGraphView::keptNodes
private

Definition at line 249 of file SlicedGraphs.h.

◆ tcg

ThreadCallGraph* SVF::SlicedThreadCallGraphView::tcg
private

Definition at line 248 of file SlicedGraphs.h.


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