Static Value-Flow Analysis
Loading...
Searching...
No Matches
PreAnalysis.cpp
Go to the documentation of this file.
1//===- PreAnalysis.cpp -- Pre-Analysis for Abstract Interpretation---------//
2//
3// SVF: Static Value-Flow Analysis
4//
5// Copyright (C) <2013-> <Yulei Sui>
6//
7
8// This program is free software: you can redistribute it and/or modify
9// it under the terms of the GNU Affero General Public License as published by
10// the Free Software Foundation, either version 3 of the License, or
11// (at your option) any later version.
12
13// This program is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU Affero General Public License for more details.
17
18// You should have received a copy of the GNU Affero General Public License
19// along with this program. If not, see <http://www.gnu.org/licenses/>.
20//
21//===----------------------------------------------------------------------===//
22
23/*
24 * PreAnalysis.cpp
25 *
26 * Created on: Feb 25, 2026
27 * Author: Jiawei Wang
28 */
29
31#include "Graphs/SVFG.h"
32#include "MSSA/SVFGBuilder.h"
33#include "Util/Options.h"
34
35using namespace SVF;
36
38 : svfir(pag), icfg(icfg), svfg(nullptr), pta(nullptr), callGraph(nullptr), callGraphSCC(nullptr)
39{
44 {
45 SVFGBuilder memSSA(true);
46 svfg = memSSA.buildFullSVFG(pta);
47 }
48}
49
51{
52 for (auto& [func, wto] : funcToWTO)
53 delete wto;
54}
55
57{
59 {
60 assert(svfg && "SVFG is not built for sparse AE");
61 return svfg->getUseSitesOfObjVar(obj, node);
62 }
63 // Non-sparse mode: return ICFG successor nodes
65 for (const auto* edge : node->getOutEdges())
66 succs.insert(edge->getDstNode());
67 return succs;
68}
69
71{
73 {
74 assert(svfg && "SVFG is not built for sparse AE");
76 }
77 // Non-sparse mode: return ICFG successor nodes of the ValVar's ICFGNode
79 if (const ICFGNode* node = var->getICFGNode())
80 {
81 for (const auto* edge : node->getOutEdges())
82 succs.insert(edge->getDstNode());
83 }
84 return succs;
85}
86
88{
90 {
91 assert(svfg && "SVFG is not built for sparse AE");
93 }
94 // Non-sparse mode: return the ValVar's associated ICFGNode
95 return var->getICFGNode();
96}
97
99{
100 if (Options::SparseAE())
101 {
102 assert(svfg && "SVFG is not built for sparse AE");
103 return svfg->getDefSiteOfObjVar(obj, node);
104 }
105 // Non-sparse mode: return ICFG predecessor node
106 for (const auto* edge : node->getInEdges())
107 return edge->getSrcNode();
108 return nullptr;
109}
110
112{
113 callGraphSCC->find();
114
115 for (auto it = callGraph->begin(); it != callGraph->end(); it++)
116 {
117 const FunObjVar *fun = it->second->getFunction();
118 if (fun->isDeclaration())
119 continue;
120
121 NodeID repNodeId = callGraphSCC->repNode(it->second->getId());
122 auto cgSCCNodes = callGraphSCC->subNodes(repNodeId);
123
124 bool isEntry = false;
125 if (it->second->getInEdges().empty())
126 isEntry = true;
127 for (auto inEdge: it->second->getInEdges())
128 {
129 NodeID srcNodeId = inEdge->getSrcID();
130 if (!cgSCCNodes.test(srcNodeId))
131 isEntry = true;
132 }
133
134 if (isEntry)
135 {
137 for (const auto& node: cgSCCNodes)
138 {
139 funcScc.insert(callGraph->getGNode(node)->getFunction());
140 }
142 iwto->init();
143 funcToWTO[it->second->getFunction()] = iwto;
144 }
145 }
146
147}
static AndersenWaveDiff * createAndersenWaveDiff(SVFIR *_pag)
Create an singleton instance directly instead of invoking llvm pass manager.
Definition Andersen.h:407
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.
const GEdgeSetTy & getOutEdges() const
const GEdgeSetTy & getInEdges() const
FunEntryICFGNode * getFunEntryICFGNode(const FunObjVar *fun)
Add a function entry node.
Definition ICFG.cpp:242
static const Option< bool > SparseAE
Definition Options.h:243
CallGraph * getCallGraph() const
Return call graph.
CallGraphSCC * getCallGraphSCC() const
Return call graph SCC.
const ICFGNode * getDefSiteOfObjVar(const ObjVar *obj, const ICFGNode *node) const
const Set< const ICFGNode * > getUseSitesOfValVar(const ValVar *var) const
Map< const FunObjVar *, const ICFGWTO * > funcToWTO
const ICFGNode * getDefSiteOfValVar(const ValVar *var) const
const Set< const ICFGNode * > getUseSitesOfObjVar(const ObjVar *obj, const ICFGNode *node) const
Given an ObjVar and its def-site ICFGNode, find all use-site ICFGNodes.
CallGraphSCC * callGraphSCC
AndersenWaveDiff * pta
virtual ~PreAnalysis()
CallGraph * callGraph
void initWTO()
Build WTO for each function using call graph SCC.
PreAnalysis(SVFIR *pag, ICFG *icfg)
SVFG * buildFullSVFG(BVDataPTAImpl *pta)
const ICFGNode * getDefSiteOfValVar(const ValVar *var) const
Definition SVFG.cpp:765
const Set< const ICFGNode * > getUseSitesOfValVar(const ValVar *var) const
Definition SVFG.cpp:795
const ICFGNode * getDefSiteOfObjVar(const ObjVar *obj, const ICFGNode *node) const
Definition SVFG.cpp:772
const Set< const ICFGNode * > getUseSitesOfObjVar(const ObjVar *obj, const ICFGNode *node) const
Definition SVFG.cpp:815
for isBitcode
Definition BasicTypes.h:68
u32_t NodeID
Definition GeneralType.h:56
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:74