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 "MemoryModel/PTATY.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<= PTATY::Default_PTA; i++)
72 {
73 PTATY iPtaTy = static_cast<PTATY>(i);
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;
106 case PTATY::VFS_WPA:
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 FunObjVar* fun1 = node1->getFunction();
146 const FunObjVar* 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->getName()
150 << "@" << (fun1==nullptr?"":fun1->getName()) << "] --"
151 << " var" << node2->getId() << "[" << node2->getName()
152 << "@" << (fun2==nullptr?"":fun2->getName()) << "]\n";
153 }
154 }
155}
156
157
159{
160 assert(_pta && "initialize a pointer analysis first");
161 return _pta->getPts(var);
162}
163
168{
169 assert(Options::PASelected(PTATY::AndersenWaveDiff_WPA) && Options::AnderSVFG() && "mod-ref query is only support with -ander and -svfg turned on");
170 return _svfg->getMSSA()->getMRGenerator()->getModRefInfo(callInst);
171}
172
173
178{
179 assert(Options::PASelected(PTATY::AndersenWaveDiff_WPA) && Options::AnderSVFG() && "mod-ref query is only support with -ander and -svfg turned on");
181}
virtual const FunObjVar * getFunction() const
Get containing function, or null for globals/constants.
iterator begin()
Iterators.
IDToNodeMapTy::iterator iterator
Node Iterators.
ModRefInfo getModRefInfo(const CallICFGNode *cs)
MRGenerator * getMRGenerator()
Return MRGenerator.
Definition MemSSA.h:313
static OptionMultiple< PTATY > PASelected
Definition Options.h:217
static const Option< bool > PrintAliases
Definition Options.h:216
static const Option< bool > AnderSVFG
Definition Options.h:214
virtual const PointsTo & getPts(NodeID ptr)=0
Get points-to targets of a pointer. It needs to be implemented in child class.
SVFIR * getPAG() const
virtual AliasResult alias(const SVFVar *V1, const SVFVar *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:113
static char ID
Pass ID.
Definition WPAPass.h:63
PTAVector ptaVector
all pointer analysis to be executed.
Definition WPAPass.h:112
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:167
virtual const PointsTo & getPts(NodeID var)
Retrieve points-to set information.
Definition WPAPass.cpp:158
virtual void PrintAliasPairs(PointerAnalysis *pta)
Print all alias pairs.
Definition WPAPass.cpp:133
SVFG * _svfg
svfg generated through -ander pointer analysis
Definition WPAPass.h:114
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:52
for isBitcode
Definition BasicTypes.h:70
PTATY
Pointer analysis type list.
Definition PTATY.h:9
@ VFS_WPA
Versioned sparse flow-sensitive WPA.
Definition PTATY.h:21
@ Andersen_WPA
Andersen PTA.
Definition PTATY.h:12
@ Default_PTA
default pta without any analysis
Definition PTATY.h:35
@ FSSPARSE_WPA
Sparse flow sensitive WPA.
Definition PTATY.h:20
@ AndersenSFR_WPA
Stride-based field representation.
Definition PTATY.h:14
@ AndersenWaveDiff_WPA
Diff wave propagation andersen-style WPA.
Definition PTATY.h:15
@ TypeCPP_WPA
Type-based analysis for C++.
Definition PTATY.h:26
@ Steensgaard_WPA
Steensgaard PTA.
Definition PTATY.h:16
@ AndersenSCD_WPA
Selective cycle detection andersen-style WPA.
Definition PTATY.h:13
ModRefInfo
Definition SVFType.h:611
u32_t NodeID
Definition GeneralType.h:76
AliasResult
Definition SVFType.h:619
@ NoAlias
Definition SVFType.h:620
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:76
unsigned u32_t
Definition GeneralType.h:67