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=OrderedSet< const ICFGNode * >())
 
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)
 
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
 
const CallGraph::CallGraphEdgeSetgetKeptEdges () const
 Get all kept edges.
 
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.
 
ThreadCallGraphgetOriginalThreadCallGraph () const
 Get original ThreadCallGraph.
 
CallGraphgetOriginalCallGraph () const
 Get original CallGraph (ThreadCallGraph inherits from CallGraph)
 

Private Member Functions

void buildKeptNodes ()
 
void buildCallGraphSets ()
 

Private Attributes

ThreadCallGraphtcg
 
OrderedSet< const CallGraphNode * > keptNodes
 
CallGraph::CallGraphEdgeSet keptEdges
 
Set< const FunObjVar * > keptFunctionsSet
 
Set< const CallICFGNode * > indirectSitesWithEmptyTargets
 
OrderedSet< const ICFGNode * > extendedKeptNodes
 

Detailed Description

Definition at line 185 of file SlicedGraphs.h.

Constructor & Destructor Documentation

◆ SlicedThreadCallGraphView()

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

Definition at line 597 of file SlicedGraphs.cpp.

600 : tcg(tcg)
601{
602 for (const FunObjVar* fun : keptFunctions)
603 {
604 keptFunctionsSet.insert(fun);
605 }
608 // extendedKeptNodes already includes all necessary nodes from performSpatialSlicing;
609 // buildCallGraphSets builds the kept edges (filtering pruned call sites when it is non-empty).
611}
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 657 of file SlicedGraphs.cpp.

658{
659 // rebuild kept edges, accounting for whether the call site is kept
660 keptEdges.clear();
662
663 // CallGraph edge: src/dst both in kept functions and the call site still in the kept ICFG node set
664 for (const CallGraphNode* srcNode : keptNodes)
665 {
666 for (const CallGraphEdge* edge : srcNode->getOutEdges())
667 {
668 const CallGraphNode* dstNode = edge ? edge->getDstNode() : nullptr;
669 if (!dstNode || !keptNodes.count(dstNode))
670 {
671 continue;
672 }
673
674 const CallGraphEdge::CallInstSet &directCalls = edge->getDirectCalls();
675 const CallGraphEdge::CallInstSet &indirectCalls = edge->getIndirectCalls();
676 const CallICFGNode* callSite = nullptr;
677 if (!directCalls.empty())
678 {
679 callSite = *directCalls.begin();
680 }
681 else if (!indirectCalls.empty())
682 {
683 callSite = *indirectCalls.begin();
684 }
685
686 if (!extendedKeptNodes.empty() && callSite && !extendedKeptNodes.count(callSite))
687 {
688 // call site was pruned, skip this edge
689 continue;
690 }
691
692 // indirect call: record if all targets were filtered out
693 if (callSite && edge->getEdgeKind() == CallGraphEdge::CallRetEdge &&
695 {
697 bool hasKeptTarget = false;
698 for (const FunObjVar* tgt : targets)
699 {
700 if (keptFunctionsSet.count(tgt))
701 {
702 hasKeptTarget = true;
703 break;
704 }
705 }
706 if (!hasKeptTarget)
707 {
709 }
710 }
711
712 keptEdges.insert(const_cast<CallGraphEdge*>(edge));
713 }
714 }
715}
Set< const CallICFGNode * > CallInstSet
Definition CallGraph.h:55
bool hasIndCSCallees(const CallICFGNode *cs) const
Definition CallGraph.h:335
const FunctionSet & getIndCSCallees(const CallICFGNode *cs) const
Definition CallGraph.h:339
Set< const FunObjVar * > FunctionSet
Definition CallGraph.h:247
OrderedSet< const CallGraphNode * > keptNodes
CallGraph::CallGraphEdgeSet keptEdges
Set< const CallICFGNode * > indirectSitesWithEmptyTargets

◆ buildKeptNodes()

void SVF::SlicedThreadCallGraphView::buildKeptNodes ( )
private

Definition at line 613 of file SlicedGraphs.cpp.

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

◆ dump()

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

Dump sliced ThreadCallGraph to dot file.

Definition at line 717 of file SlicedGraphs.cpp.

718{
719 // Kept nodes + canonical kept edges via GenericGraphTraits; join edges are
720 // not in the normal adjacency, so they are not drawn here.
722}
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

◆ getIndirectSitesWithEmptyTargets()

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

Indirect call sites that lost all targets after filtering.

Definition at line 226 of file SlicedGraphs.h.

227 {
229 }

◆ 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 639 of file SlicedGraphs.cpp.

640{
641 out.clear();
642 if (!isKeptNode(node))
643 {
644 return;
645 }
647 const SlicedCallGraphNodeRef n{this, node};
648 for (auto it = GT::child_edge_begin(n), e = GT::child_edge_end(n); it != e; ++it)
649 out.push_back((*it).underlying);
650}
cJSON * n
Definition cJSON.cpp:2558
bool isKeptNode(const CallGraphNode *node) const
Check if a node is in the sliced view.

◆ getKeptEdges()

const CallGraph::CallGraphEdgeSet & SVF::SlicedThreadCallGraphView::getKeptEdges ( ) const
inline

Get all kept edges.

Definition at line 213 of file SlicedGraphs.h.

214 {
215 return keptEdges;
216 }

◆ getKeptFunctions()

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

Definition at line 207 of file SlicedGraphs.h.

208 {
209 return keptFunctionsSet;
210 }

◆ getKeptNodes()

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

Get all kept nodes.

Definition at line 202 of file SlicedGraphs.h.

203 {
204 return keptNodes;
205 }

◆ getOriginalCallGraph()

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

Get original CallGraph (ThreadCallGraph inherits from CallGraph)

Definition at line 241 of file SlicedGraphs.h.

242 {
243 return tcg;
244 }

◆ getOriginalThreadCallGraph()

ThreadCallGraph * SVF::SlicedThreadCallGraphView::getOriginalThreadCallGraph ( ) const
inline

Get original ThreadCallGraph.

Definition at line 235 of file SlicedGraphs.h.

236 {
237 return tcg;
238 }

◆ 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 625 of file SlicedGraphs.cpp.

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

◆ 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 220 of file SlicedGraphs.h.

221 {
222 return keptEdges.find(const_cast<CallGraphEdge*>(e)) != keptEdges.end();
223 }

◆ isKeptNode()

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

Check if a node is in the sliced view.

Definition at line 652 of file SlicedGraphs.cpp.

653{
654 return keptNodes.count(node) > 0;
655}

Member Data Documentation

◆ extendedKeptNodes

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

Definition at line 252 of file SlicedGraphs.h.

◆ indirectSitesWithEmptyTargets

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

Definition at line 251 of file SlicedGraphs.h.

◆ keptEdges

CallGraph::CallGraphEdgeSet SVF::SlicedThreadCallGraphView::keptEdges
private

Definition at line 249 of file SlicedGraphs.h.

◆ keptFunctionsSet

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

Definition at line 250 of file SlicedGraphs.h.

◆ keptNodes

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

Definition at line 248 of file SlicedGraphs.h.

◆ tcg

ThreadCallGraph* SVF::SlicedThreadCallGraphView::tcg
private

Definition at line 247 of file SlicedGraphs.h.


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