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"
32#include "Graphs/SVFG.h"
33#include "MSSA/MemPartition.h"
34#include "Graphs/SVFGOPT.h"
35#include "MSSA/MemSSA.h"
36#include "SVFIR/SVFIR.h"
37#include "Util/Options.h"
38#include "Util/SVFUtil.h"
39#include "WPA/Andersen.h"
40
41using namespace SVF;
42using namespace SVFUtil;
43
49
55
60{
61 svfg->buildSVFG();
62}
63
66{
67
68 auto mssa = buildMSSA(
69 pta, (VFG::PTRONLYSVFG == kind || VFG::PTRONLYSVFG_OPT == kind));
70
71 DBOUT(DGENERAL, outs() << pasMsg("Build Sparse Value-Flow Graph \n"));
72 if (kind == VFG::FULLSVFG_OPT || kind == VFG::PTRONLYSVFG_OPT)
73 svfg = std::make_unique<SVFGOPT>(std::move(mssa), kind);
74 else
75 svfg = std::unique_ptr<SVFG>(new SVFG(std::move(mssa), kind));
76 buildSVFG();
77
80 svfg->updateCallGraph(pta);
81
82 if (svfg->getMSSA()->getPTA()->printStat())
83 svfg->performStat();
84
85 if (Options::DumpVFG())
86 svfg->dump("svfg_final");
87
88 if ((kind == VFG::FULLSVFG || kind == VFG::FULLSVFG_OPT) &&
90 {
91 SVFIR* svfir = pta->getPAG();
92 SparseObjGraph routes(*svfg, *svfir->getICFG(), *pta, *svfir);
93 routes.dump("sparse_obj_graph");
94 }
95
96 return svfg.get();
97}
98
103{
104 svfg->clearMSSA();
105}
106
111std::unique_ptr<MRGenerator> SVFGBuilder::createMRGenerator(BVDataPTAImpl* pta, bool ptrOnlyMSSA)
112{
113 switch (Options::MemPar())
114 {
116 return std::make_unique<DistinctMRG>(pta, ptrOnlyMSSA);
118 return std::make_unique<IntraDisjointMRG>(pta, ptrOnlyMSSA);
120 return std::make_unique<InterDisjointMRG>(pta, ptrOnlyMSSA);
121 default:
122 assert(false && "unrecognised memory partition strategy");
123 return nullptr;
124 }
125}
126
127std::unique_ptr<MemSSA> SVFGBuilder::buildMSSA(BVDataPTAImpl* pta,
128 bool ptrOnlyMSSA)
129{
130
131 DBOUT(DGENERAL, outs() << pasMsg("Build Memory SSA \n"));
132
133 auto mssa = std::make_unique<MemSSA>(pta, createMRGenerator(pta, ptrOnlyMSSA));
134
135 const CallGraph* svfirCallGraph = PAG::getPAG()->getCallGraph();
136 for (const auto& item : *svfirCallGraph)
137 {
138
139 const FunObjVar* fun = item.second->getFunction();
140 if (isExtCall(fun))
141 continue;
142
143 mssa->buildMemSSA(*fun);
144 }
145
146 mssa->performStat();
147 if (Options::DumpMSSA())
148 {
149 mssa->dumpMSSA();
150 }
151
152 return mssa;
153}
#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:140
static const OptionMap< u32_t > MemPar
Definition Options.h:143
static const Option< bool > DumpSparseObjGraph
Definition Options.h:109
static const Option< bool > DumpVFG
Definition Options.h:108
SVFIR * getPAG() const
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:249
ICFG * getICFG() const
Definition SVFIR.h:232
static SVFIR * getPAG(bool buildFromFile=false)
Singleton design here to make sure we only have one instance during any analysis.
Definition SVFIR.h:121
void dump(const std::string &file)
Write a DOT graph to <file>.dot through GraphPrinter.
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:121
bool isExtCall(const FunObjVar *fun)
Definition SVFUtil.cpp:526
std::ostream & outs()
Overwrite llvm::outs().
Definition SVFUtil.h:58
for isBitcode
Definition BasicTypes.h:70