Static Value-Flow Analysis
Loading...
Searching...
No Matches
SVFGBuilder.cpp
Go to the documentation of this file.
1//===- SVFGBuilder.cpp -- SVFG builder----------------------------------------//
2//
3// SVF: Static Value-Flow Analysis
4//
5// Copyright (C) <2013-2017> <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 * SVFGBuilder.cpp
25 *
26 * Created on: Apr 15, 2014
27 * Author: Yulei Sui
28 */
29#include "MSSA/SVFGBuilder.h"
30#include "Graphs/CallGraph.h"
31#include "Graphs/SVFG.h"
32#include "MSSA/MemPartition.h"
33#include "Graphs/SVFGOPT.h"
34#include "MSSA/MemSSA.h"
35#include "Util/Options.h"
36#include "Util/SVFUtil.h"
37#include "WPA/Andersen.h"
38
39using namespace SVF;
40using namespace SVFUtil;
41
47
53
58{
59 svfg->buildSVFG();
60}
61
64{
65
66 auto mssa = buildMSSA(
67 pta, (VFG::PTRONLYSVFG == kind || VFG::PTRONLYSVFG_OPT == kind));
68
69 DBOUT(DGENERAL, outs() << pasMsg("Build Sparse Value-Flow Graph \n"));
70 if (kind == VFG::FULLSVFG_OPT || kind == VFG::PTRONLYSVFG_OPT)
71 svfg = std::make_unique<SVFGOPT>(std::move(mssa), kind);
72 else
73 svfg = std::unique_ptr<SVFG>(new SVFG(std::move(mssa), kind));
74 buildSVFG();
75
78 svfg->updateCallGraph(pta);
79
80 if (svfg->getMSSA()->getPTA()->printStat())
81 svfg->performStat();
82
83 if (Options::DumpVFG())
84 svfg->dump("svfg_final");
85
86 return svfg.get();
87}
88
93{
94 svfg->clearMSSA();
95}
96
101std::unique_ptr<MRGenerator> SVFGBuilder::createMRGenerator(BVDataPTAImpl* pta, bool ptrOnlyMSSA)
102{
103 switch (Options::MemPar())
104 {
106 return std::make_unique<DistinctMRG>(pta, ptrOnlyMSSA);
108 return std::make_unique<IntraDisjointMRG>(pta, ptrOnlyMSSA);
110 return std::make_unique<InterDisjointMRG>(pta, ptrOnlyMSSA);
111 default:
112 assert(false && "unrecognised memory partition strategy");
113 return nullptr;
114 }
115}
116
117std::unique_ptr<MemSSA> SVFGBuilder::buildMSSA(BVDataPTAImpl* pta,
118 bool ptrOnlyMSSA)
119{
120
121 DBOUT(DGENERAL, outs() << pasMsg("Build Memory SSA \n"));
122
123 auto mssa = std::make_unique<MemSSA>(pta, createMRGenerator(pta, ptrOnlyMSSA));
124
126 for (const auto& item : *svfirCallGraph)
127 {
128
129 const FunObjVar* fun = item.second->getFunction();
130 if (isExtCall(fun))
131 continue;
132
133 mssa->buildMemSSA(*fun);
134 }
135
136 mssa->performStat();
137 if (Options::DumpMSSA())
138 {
139 mssa->dumpMSSA();
140 }
141
142 return mssa;
143}
#define DBOUT(TYPE, X)
LLVM debug macros, define type of your DBUG model of each pass.
Definition SVFType.h:576
#define DGENERAL
Definition SVFType.h:582
cJSON * item
Definition cJSON.h:222
@ InterDisjoint
Definition MemSSA.h:117
@ IntraDisjoint
Definition MemSSA.h:116
static const Option< bool > DumpMSSA
Definition Options.h:138
static const OptionMap< u32_t > MemPar
Definition Options.h:141
static const Option< bool > DumpVFG
Definition Options.h:107
virtual std::unique_ptr< MemSSA > buildMSSA(BVDataPTAImpl *pta, bool ptrOnlyMSSA)
Build Memory SSA.
bool SVFGWithPostOpts
Build optimised version of SVFG.
SVFG * build(BVDataPTAImpl *pta, VFG::VFGK kind)
Create a DDA SVFG. By default actualOut and FormalIN are removed, unless withAOFI is set true.
virtual std::unique_ptr< MRGenerator > createMRGenerator(BVDataPTAImpl *pta, bool ptrOnlyMSSA)
SVFG * buildFullSVFG(BVDataPTAImpl *pta)
virtual void releaseMemory()
Release global SVFG.
bool SVFGWithIndCall
SVFG with precomputed indirect call edges.
SVFG * buildPTROnlySVFG(BVDataPTAImpl *pta)
virtual void buildSVFG()
Can be rewritten by subclasses.
std::unique_ptr< SVFG > svfg
const CallGraph * getCallGraph()
Get CG.
Definition SVFIR.h:248
static SVFIR * getPAG(bool buildFromFile=false)
Singleton design here to make sure we only have one instance during any analysis.
Definition SVFIR.h:120
VFGK
VFG kind.
Definition VFG.h:56
@ FULLSVFG
Definition VFG.h:57
@ PTRONLYSVFG_OPT
Definition VFG.h:57
@ FULLSVFG_OPT
Definition VFG.h:57
@ PTRONLYSVFG
Definition VFG.h:57
std::string pasMsg(const std::string &msg)
Print each pass/phase message by converting a string into blue string output.
Definition SVFUtil.cpp:105
bool isExtCall(const FunObjVar *fun)
Definition SVFUtil.cpp:441
std::ostream & outs()
Overwrite llvm::outs()
Definition SVFUtil.h:52
for isBitcode
Definition BasicTypes.h:70
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:76