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

#include <PreAnalysis.h>

Public Types

typedef SCCDetection< CallGraph * > CallGraphSCC
 

Public Member Functions

 PreAnalysis (SVFIR *pag, ICFG *icfg)
 
virtual ~PreAnalysis ()
 
AndersenWaveDiffgetPointerAnalysis () const
 Accessors for Andersen's results.
 
CallGraphgetCallGraph () const
 
CallGraphSCCgetCallGraphSCC () const
 
void initWTO ()
 Build WTO for each function using call graph SCC.
 
const Map< const FunObjVar *, const ICFGWTO * > & getFuncToWTO () const
 Accessors for WTO data.
 
void initCycleValVars ()
 
const Set< const ValVar * > getCycleValVars (const ICFGCycleWTO *cycle) const
 

Private Attributes

SVFIRsvfir
 
ICFGicfg
 
AndersenWaveDiffpta
 
CallGraphcallGraph
 
CallGraphSCCcallGraphSCC
 
Map< const FunObjVar *, const ICFGWTO * > funcToWTO
 
Map< const ICFGCycleWTO *, Set< const ValVar * > > cycleToValVars
 

Detailed Description

Definition at line 47 of file PreAnalysis.h.

Member Typedef Documentation

◆ CallGraphSCC

Definition at line 50 of file PreAnalysis.h.

Constructor & Destructor Documentation

◆ PreAnalysis()

PreAnalysis::PreAnalysis ( SVFIR pag,
ICFG icfg 
)

Definition at line 37 of file PreAnalysis.cpp.

38 : svfir(pag), icfg(icfg), pta(nullptr), callGraph(nullptr), callGraphSCC(nullptr)
39{
43}
static AndersenWaveDiff * createAndersenWaveDiff(SVFIR *_pag)
Create an singleton instance directly instead of invoking llvm pass manager.
Definition Andersen.h:407
CallGraph * getCallGraph() const
Return call graph.
CallGraphSCC * getCallGraphSCC() const
Return call graph SCC.
CallGraphSCC * callGraphSCC
Definition PreAnalysis.h:94
AndersenWaveDiff * pta
Definition PreAnalysis.h:92
CallGraph * callGraph
Definition PreAnalysis.h:93

◆ ~PreAnalysis()

PreAnalysis::~PreAnalysis ( )
virtual

Definition at line 45 of file PreAnalysis.cpp.

46{
47 for (auto& [func, wto] : funcToWTO)
48 delete wto;
49}
Map< const FunObjVar *, const ICFGWTO * > funcToWTO
Definition PreAnalysis.h:96
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:76

Member Function Documentation

◆ getCallGraph()

CallGraph * SVF::PreAnalysis::getCallGraph ( ) const
inline

Definition at line 60 of file PreAnalysis.h.

61 {
62 return callGraph;
63 }

◆ getCallGraphSCC()

CallGraphSCC * SVF::PreAnalysis::getCallGraphSCC ( ) const
inline

Definition at line 64 of file PreAnalysis.h.

65 {
66 return callGraphSCC;
67 }

◆ getCycleValVars()

const Set< const ValVar * > SVF::PreAnalysis::getCycleValVars ( const ICFGCycleWTO cycle) const
inline

Look up the ValVar id set of a WTO cycle. Returns nullptr if the cycle is unknown (e.g. dense mode, where the map is never built).

Definition at line 83 of file PreAnalysis.h.

84 {
85 auto it = cycleToValVars.find(cycle);
86 return it == cycleToValVars.end() ? Set<const ValVar*>() : it->second;
87 }
Map< const ICFGCycleWTO *, Set< const ValVar * > > cycleToValVars

◆ getFuncToWTO()

const Map< const FunObjVar *, const ICFGWTO * > & SVF::PreAnalysis::getFuncToWTO ( ) const
inline

Accessors for WTO data.

Definition at line 72 of file PreAnalysis.h.

73 {
74 return funcToWTO;
75 }

◆ getPointerAnalysis()

AndersenWaveDiff * SVF::PreAnalysis::getPointerAnalysis ( ) const
inline

Accessors for Andersen's results.

Definition at line 56 of file PreAnalysis.h.

57 {
58 return pta;
59 }

◆ initCycleValVars()

void PreAnalysis::initCycleValVars ( )

Walk every function's WTO and populate cycleToValVars bottom-up. Called once right after initWTO(). No-op in dense mode.

Definition at line 98 of file PreAnalysis.cpp.

99{
101 return;
102
103 // Step 1: Collect all cycles in top-down order using a stack-based DFS,
104 // then reverse to get bottom-up order (inner cycles before outer ones).
105 std::vector<const ICFGCycleWTO*> cycles;
106 {
107 std::vector<const ICFGWTOComp*> stack;
108 for (const auto& kv : funcToWTO)
109 {
110 if (!kv.second) continue;
111 for (const ICFGWTOComp* comp : kv.second->getWTOComponents())
113 }
114 while (!stack.empty())
115 {
116 const ICFGWTOComp* comp = stack.back();
117 stack.pop_back();
118 if (const ICFGCycleWTO* cycle = SVFUtil::dyn_cast<ICFGCycleWTO>(comp))
119 {
120 for (const ICFGWTOComp* sub : cycle->getWTOComponents())
122 cycles.push_back(cycle);
123 }
124 }
125 std::reverse(cycles.begin(), cycles.end());
126 }
127
128 // Step 2: Build ValVar sets bottom-up. Inner cycles are already in the
129 // map when we reach their enclosing cycle.
130 for (const ICFGCycleWTO* cycle : cycles)
131 {
133
134 // Gather every ICFG node in this cycle (head + body singletons).
135 // For nested sub-cycles, merge their already-computed sets instead.
136 std::vector<const ICFGNode*> nodes;
137 nodes.push_back(cycle->head()->getICFGNode());
138 for (const ICFGWTOComp* comp : cycle->getWTOComponents())
139 {
140 if (const ICFGSingletonWTO* s = SVFUtil::dyn_cast<ICFGSingletonWTO>(comp))
141 nodes.push_back(s->getICFGNode());
142 else if (const ICFGCycleWTO* sub = SVFUtil::dyn_cast<ICFGCycleWTO>(comp))
143 out.insert(cycleToValVars[sub].begin(), cycleToValVars[sub].end());
144 }
145
146 // For each node, collect LHS ValVar IDs from its statements.
147 for (const ICFGNode* node : nodes)
148 {
149 for (const SVFStmt* stmt : node->getSVFStmts())
150 {
151 const ValVar* lhs = nullptr;
152 if (const AssignStmt* a = SVFUtil::dyn_cast<AssignStmt>(stmt))
153 lhs = SVFUtil::dyn_cast<ValVar>(a->getLHSVar());
154 else if (const MultiOpndStmt* m = SVFUtil::dyn_cast<MultiOpndStmt>(stmt))
155 lhs = m->getRes();
156 if (lhs)
157 out.insert(lhs);
158 }
159 // FunEntryICFGNode owns ArgValVars (formal parameters) that have
160 // no defining stmt at the entry — the CallPE lives on the caller
161 // side. For recursive cycles whose head is a FunEntry, we need
162 // these IDs so widening/narrowing observes them across iterations.
163 if (const FunEntryICFGNode* fe = SVFUtil::dyn_cast<FunEntryICFGNode>(node))
164 {
165 for (const SVFVar* fp : fe->getFormalParms())
166 if (const ValVar* v = SVFUtil::dyn_cast<ValVar>(fp))
167 out.insert(v);
168 }
169 }
170 }
171}
if(prebuffer< 0)
Definition cJSON.cpp:1269
cJSON * a
Definition cJSON.cpp:2560
static const OptionMap< u32_t > AESparsity
Definition Options.h:243
LLVM_NODISCARD std::enable_if_t<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type > dyn_cast(const Y &Val)
Definition Casting.h:405
WTONode< ICFG > ICFGSingletonWTO
Definition ICFGWTO.h:45
iter_range< typename GenericGraphTraits< GraphType >::nodes_iterator > nodes(const GraphType &G)
WTOComponent< ICFG > ICFGWTOComp
Definition ICFGWTO.h:44

◆ initWTO()

void PreAnalysis::initWTO ( )

Build WTO for each function using call graph SCC.

Definition at line 51 of file PreAnalysis.cpp.

52{
53 callGraphSCC->find();
54
55 for (auto it = callGraph->begin(); it != callGraph->end(); it++)
56 {
57 const FunObjVar *fun = it->second->getFunction();
58 if (fun->isDeclaration())
59 continue;
60
61 NodeID repNodeId = callGraphSCC->repNode(it->second->getId());
62 auto cgSCCNodes = callGraphSCC->subNodes(repNodeId);
63
64 bool isEntry = false;
65 if (it->second->getInEdges().empty())
66 isEntry = true;
67 for (auto inEdge: it->second->getInEdges())
68 {
69 NodeID srcNodeId = inEdge->getSrcID();
70 if (!cgSCCNodes.test(srcNodeId))
71 isEntry = true;
72 }
73
74 if (isEntry)
75 {
77 for (const auto& node: cgSCCNodes)
78 {
79 funcScc.insert(callGraph->getGNode(node)->getFunction());
80 }
82 iwto->init();
83 funcToWTO[it->second->getFunction()] = iwto;
84 }
85 }
86
87}
virtual const FunObjVar * getFunction() const
Get containing function, or null for globals/constants.
bool isDeclaration() const
iterator begin()
Iterators.
NodeType * getGNode(NodeID id) const
Get a node.
FunEntryICFGNode * getFunEntryICFGNode(const FunObjVar *fun)
Add a function entry node.
Definition ICFG.cpp:242
u32_t NodeID
Definition GeneralType.h:56

Member Data Documentation

◆ callGraph

CallGraph* SVF::PreAnalysis::callGraph
private

Definition at line 93 of file PreAnalysis.h.

◆ callGraphSCC

CallGraphSCC* SVF::PreAnalysis::callGraphSCC
private

Definition at line 94 of file PreAnalysis.h.

◆ cycleToValVars

Map<const ICFGCycleWTO*, Set<const ValVar*> > SVF::PreAnalysis::cycleToValVars
private

Pre-computed (semi-sparse only) map from a WTO cycle to the IDs of every ValVar whose def-site is inside that cycle, including all nested sub-cycles. Empty in dense mode.

Definition at line 101 of file PreAnalysis.h.

◆ funcToWTO

Map<const FunObjVar*, const ICFGWTO*> SVF::PreAnalysis::funcToWTO
private

Definition at line 96 of file PreAnalysis.h.

◆ icfg

ICFG* SVF::PreAnalysis::icfg
private

Definition at line 91 of file PreAnalysis.h.

◆ pta

AndersenWaveDiff* SVF::PreAnalysis::pta
private

Definition at line 92 of file PreAnalysis.h.

◆ svfir

SVFIR* SVF::PreAnalysis::svfir
private

Definition at line 90 of file PreAnalysis.h.


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