Static Value-Flow Analysis
Loading...
Searching...
No Matches
WPAPass.cpp
Go to the documentation of this file.
1//===- WPAPass.cpp -- Whole program analysis pass------------------------------//
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 * @file: WPA.cpp
25 * @author: yesen
26 * @date: 10/06/2014
27 * @version: 1.0
28 *
29 * @section LICENSE
30 *
31 * @section DESCRIPTION
32 *
33 */
34
35
36#include "Util/Options.h"
37#include "SVFIR/SVFModule.h"
39#include "WPA/WPAPass.h"
40#include "WPA/Andersen.h"
41#include "WPA/AndersenPWC.h"
42#include "WPA/FlowSensitive.h"
44#include "WPA/TypeAnalysis.h"
45#include "WPA/Steensgaard.h"
46
47using namespace SVF;
48
49char WPAPass::ID = 0;
50
55{
56 PTAVector::const_iterator it = ptaVector.begin();
57 PTAVector::const_iterator eit = ptaVector.end();
58 for (; it != eit; ++it)
59 {
60 PointerAnalysis* pta = *it;
61 delete pta;
62 }
63 ptaVector.clear();
64}
65
70{
71 for (u32_t i = 0; i<= PointerAnalysis::Default_PTA; i++)
72 {
76 }
77 assert(!ptaVector.empty() && "No pointer analysis is specified.\n");
78}
79
84{
86 switch (kind)
87 {
89 _pta = new Andersen(pag);
90 break;
92 _pta = new AndersenSCD(pag);
93 break;
95 _pta = new AndersenSFR(pag);
96 break;
98 _pta = new AndersenWaveDiff(pag);
99 break;
101 _pta = new Steensgaard(pag);
102 break;
104 _pta = new FlowSensitive(pag);
105 break;
107 _pta = new VersionedFlowSensitive(pag);
108 break;
110 _pta = new TypeAnalysis(pag);
111 break;
112 default:
113 assert(false && "This pointer analysis has not been implemented yet.\n");
114 return;
115 }
116
117 ptaVector.push_back(_pta);
118 _pta->analyze();
119 if (Options::AnderSVFG())
120 {
121 SVFGBuilder memSSA(true);
122 assert(SVFUtil::isa<AndersenBase>(_pta) && "supports only andersen/steensgaard for pre-computed SVFG");
123 SVFG *svfg = memSSA.buildFullSVFG((BVDataPTAImpl*)_pta);
126 _svfg = svfg;
127 }
128
131}
132
134{
135 SVFIR* pag = pta->getPAG();
136 for (SVFIR::iterator lit = pag->begin(), elit = pag->end(); lit != elit; ++lit)
137 {
138 PAGNode* node1 = lit->second;
140 for (SVFIR::iterator rit = lit, erit = pag->end(); rit != erit; ++rit)
141 {
142 node2 = rit->second;
143 if(node1==node2)
144 continue;
145 const SVFFunction* fun1 = node1->getFunction();
146 const SVFFunction* fun2 = node2->getFunction();
147 AliasResult result = pta->alias(node1->getId(), node2->getId());
148 SVFUtil::outs() << (result == AliasResult::NoAlias ? "NoAlias" : "MayAlias")
149 << " var" << node1->getId() << "[" << node1->getValueName()
150 << "@" << (fun1==nullptr?"":fun1->getName()) << "] --"
151 << " var" << node2->getId() << "[" << node2->getValueName()
152 << "@" << (fun2==nullptr?"":fun2->getName()) << "]\n";
153 }
154 }
155}
156
158{
159 assert(_pta && "initialize a pointer analysis first");
160 SVFIR* pag = _pta->getPAG();
161 return getPts(pag->getValueNode(value));
162}
163
165{
166 assert(_pta && "initialize a pointer analysis first");
167 return _pta->getPts(var);
168}
169
175{
176
178
179 SVFIR* pag = _pta->getPAG();
180
186 if (pag->hasValueNode(V1) && pag->hasValueNode(V2))
187 {
189 if (Options::AliasRule.nothingSet() || Options::AliasRule(Veto))
190 {
193
194 for (PTAVector::const_iterator it = ptaVector.begin(), eit = ptaVector.end();
195 it != eit; ++it)
196 {
197 if ((*it)->alias(V1, V2) == AliasResult::NoAlias)
199 }
200 }
202 {
205
206 for (PTAVector::const_iterator it = ptaVector.begin(), eit = ptaVector.end();
207 it != eit; ++it)
208 {
209 if ((*it)->alias(V1, V2) == AliasResult::MayAlias)
211 }
212 }
213 }
214
215 return result;
216}
217
222{
223 assert(Options::PASelected(PointerAnalysis::AndersenWaveDiff_WPA) && Options::AnderSVFG() && "mod-ref query is only support with -ander and -svfg turned on");
224 return _svfg->getMSSA()->getMRGenerator()->getModRefInfo(callInst);
225}
226
231{
232 assert(Options::PASelected(PointerAnalysis::AndersenWaveDiff_WPA) && Options::AnderSVFG() && "mod-ref query is only support with -ander and -svfg turned on");
233 return _svfg->getMSSA()->getMRGenerator()->getModRefInfo(callInst, V);
234}
235
iterator begin()
Iterators.
IDToNodeMapTy::iterator iterator
Node Iterators.
bool hasValueNode(const SVFValue *V)
Definition IRGraph.h:141
NodeID getValueNode(const SVFValue *V)
Definition IRGraph.h:137
ModRefInfo getModRefInfo(const CallICFGNode *cs)
MRGenerator * getMRGenerator()
Return MRGenerator.
Definition MemSSA.h:313
static OptionMultiple< WPAPass::AliasCheckRule > AliasRule
Definition Options.h:225
static OptionMultiple< PointerAnalysis::PTATY > PASelected
Definition Options.h:224
static const Option< bool > PrintAliases
Definition Options.h:223
static const Option< bool > AnderSVFG
Definition Options.h:221
virtual const PointsTo & getPts(NodeID ptr)=0
Get points-to targets of a pointer. It needs to be implemented in child class.
PTATY
Pointer analysis type list.
@ VFS_WPA
Versioned sparse flow-sensitive WPA.
@ AndersenSCD_WPA
Selective cycle detection andersen-style WPA.
@ Andersen_WPA
Andersen PTA.
@ AndersenWaveDiff_WPA
Diff wave propagation andersen-style WPA.
@ TypeCPP_WPA
Type-based analysis for C++.
@ AndersenSFR_WPA
Stride-based field representation.
@ Steensgaard_WPA
Steensgaard PTA.
@ FSSPARSE_WPA
Sparse flow sensitive WPA.
@ Default_PTA
default pta without any analysis
SVFIR * getPAG() const
virtual AliasResult alias(const SVFValue *V1, const SVFValue *V2)=0
Interface exposed to users of our pointer analysis, given Value infos.
virtual void analyze()=0
Start Analysis here (main part of pointer analysis). It needs to be implemented in child class.
SVFG * buildFullSVFG(BVDataPTAImpl *pta)
MemSSA * getMSSA() const
Get SVFG memory SSA.
Definition SVFG.h:138
PointerAnalysis * _pta
pointer analysis to be executed.
Definition WPAPass.h:117
static char ID
Pass ID.
Definition WPAPass.h:60
@ Conservative
return MayAlias if any pta says alias
Definition WPAPass.h:64
@ Veto
return NoAlias if any pta says no alias
Definition WPAPass.h:65
virtual const PointsTo & getPts(const SVFValue *value)
Retrieve points-to set information.
Definition WPAPass.cpp:157
PTAVector ptaVector
all pointer analysis to be executed.
Definition WPAPass.h:116
virtual ~WPAPass()
Destructor.
Definition WPAPass.cpp:54
virtual ModRefInfo getModRefInfo(const CallICFGNode *callInst)
Interface of mod-ref analysis to determine whether a CallSite instruction can mod or ref any memory l...
Definition WPAPass.cpp:221
virtual AliasResult alias(const SVFValue *V1, const SVFValue *V2)
Interface expose to users of our pointer analysis, given Value infos.
Definition WPAPass.cpp:174
virtual void PrintAliasPairs(PointerAnalysis *pta)
Print all alias pairs.
Definition WPAPass.cpp:133
SVFG * _svfg
svfg generated through -ander pointer analysis
Definition WPAPass.h:118
void runPointerAnalysis(SVFIR *pag, u32_t kind)
Create pointer analysis according to specified kind and analyze the module.
Definition WPAPass.cpp:83
virtual void runOnModule(SVFIR *svfModule)
Run pointer analysis on SVFModule.
Definition WPAPass.cpp:69
std::ostream & outs()
Overwrite llvm::outs()
Definition SVFUtil.h:50
for isBitcode
Definition BasicTypes.h:68
ModRefInfo
Definition SVFType.h:519
u32_t NodeID
Definition GeneralType.h:55
AliasResult
Definition SVFType.h:527
@ MayAlias
Definition SVFType.h:529
@ NoAlias
Definition SVFType.h:528
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:74
unsigned u32_t
Definition GeneralType.h:46