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 "Util/Options.h"
30#include "SVFIR/SVFModule.h"
31#include "Util/SVFUtil.h"
32#include "MSSA/MemSSA.h"
33#include "Graphs/SVFG.h"
34#include "MSSA/SVFGBuilder.h"
35#include "WPA/Andersen.h"
36#include "Graphs/CallGraph.h"
37
38
39using namespace SVF;
40using namespace SVFUtil;
41
42
44{
46 return build(pta, VFG::PTRONLYSVFG_OPT);
47 else
48 return build(pta, VFG::PTRONLYSVFG);
49}
50
55
56
61{
62 svfg->buildSVFG();
63}
64
67{
68
69 auto mssa = buildMSSA(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
86 svfg->dump("svfg_final");
87
88 return svfg.get();
89}
90
95{
96 svfg->clearMSSA();
97}
98
99std::unique_ptr<MemSSA> SVFGBuilder::buildMSSA(BVDataPTAImpl* pta, bool ptrOnlyMSSA)
100{
101
102 DBOUT(DGENERAL, outs() << pasMsg("Build Memory SSA \n"));
103
104 auto mssa = std::make_unique<MemSSA>(pta, ptrOnlyMSSA);
105
107 for (const auto& item: *svfirCallGraph)
108 {
109
110 const SVFFunction *fun = item.second->getFunction();
111 if (isExtCall(fun))
112 continue;
113
114 mssa->buildMemSSA(*fun);
115 }
116
117 mssa->performStat();
118 if (Options::DumpMSSA())
119 {
120 mssa->dumpMSSA();
121 }
122
123 return mssa;
124}
125
126
#define DBOUT(TYPE, X)
LLVM debug macros, define type of your DBUG model of each pass.
Definition SVFType.h:484
#define DGENERAL
Definition SVFType.h:490
cJSON * item
Definition cJSON.h:222
static const Option< bool > SVFGWithIndirectCall
Definition Options.h:148
static const Option< bool > DumpMSSA
Definition Options.h:142
static Option< bool > OPTSVFG
Definition Options.h:149
static const Option< bool > DumpVFG
Definition Options.h:111
virtual std::unique_ptr< MemSSA > buildMSSA(BVDataPTAImpl *pta, bool ptrOnlyMSSA)
Build Memory SSA.
SVFG * build(BVDataPTAImpl *pta, VFG::VFGK kind)
Create a DDA SVFG. By default actualOut and FormalIN are removed, unless withAOFI is set true.
SVFG * buildFullSVFG(BVDataPTAImpl *pta)
virtual void releaseMemory()
Release global SVFG.
bool SVFGWithIndCall
SVFG with precomputed indirect call edges.
Definition SVFGBuilder.h:93
SVFG * buildPTROnlySVFG(BVDataPTAImpl *pta)
virtual void buildSVFG()
Can be rewritten by subclasses.
std::unique_ptr< SVFG > svfg
Definition SVFGBuilder.h:91
CallGraph * getCallGraph()
Definition SVFIR.h:193
static SVFIR * getPAG(bool buildFromFile=false)
Singleton design here to make sure we only have one instance during any analysis.
Definition SVFIR.h:116
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
bool isExtCall(const SVFFunction *fun)
Definition SVFUtil.h:278
std::string pasMsg(const std::string &msg)
Print each pass/phase message by converting a string into blue string output.
Definition SVFUtil.cpp:100
std::ostream & outs()
Overwrite llvm::outs()
Definition SVFUtil.h:50
for isBitcode
Definition BasicTypes.h:68
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:74