Static Value-Flow Analysis
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 
37 using namespace SVF;
38 using namespace SVFUtil;
39 
40 
42 {
43  if(Options::OPTSVFG())
44  return build(pta, VFG::PTRONLYSVFG_OPT);
45  else
46  return build(pta, VFG::PTRONLYSVFG);
47 }
48 
50 {
51  return build(pta, VFG::FULLSVFG);
52 }
53 
54 
59 {
60  svfg->buildSVFG();
61 }
62 
65 {
66 
67  auto mssa = buildMSSA(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 
77  if(Options::SVFGWithIndirectCall() || SVFGWithIndCall)
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 
97 std::unique_ptr<MemSSA> SVFGBuilder::buildMSSA(BVDataPTAImpl* pta, bool ptrOnlyMSSA)
98 {
99 
100  DBOUT(DGENERAL, outs() << pasMsg("Build Memory SSA \n"));
101 
102  auto mssa = std::make_unique<MemSSA>(pta, ptrOnlyMSSA);
103 
104  PTACallGraph* svfirCallGraph = PAG::getPAG()->getCallGraph();
105  for (const auto& item: *svfirCallGraph)
106  {
107 
108  const SVFFunction *fun = item.second->getFunction();
109  if (isExtCall(fun))
110  continue;
111 
112  mssa->buildMemSSA(*fun);
113  }
114 
115  mssa->performStat();
116  if (Options::DumpMSSA())
117  {
118  mssa->dumpMSSA();
119  }
120 
121  return mssa;
122 }
123 
124 
#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.
Definition: SVFGBuilder.cpp:97
SVFG * build(BVDataPTAImpl *pta, VFG::VFGK kind)
Create a DDA SVFG. By default actualOut and FormalIN are removed, unless withAOFI is set true.
Definition: SVFGBuilder.cpp:64
SVFG * buildFullSVFG(BVDataPTAImpl *pta)
Definition: SVFGBuilder.cpp:49
virtual void releaseMemory()
Release global SVFG.
Definition: SVFGBuilder.cpp:92
SVFG * buildPTROnlySVFG(BVDataPTAImpl *pta)
Definition: SVFGBuilder.cpp:41
virtual void buildSVFG()
Can be rewritten by subclasses.
Definition: SVFGBuilder.cpp:58
Definition: SVFG.h:66
PTACallGraph * getCallGraph()
Definition: SVFIR.h:192
static SVFIR * getPAG(bool buildFromFile=false)
Singleton design here to make sure we only have one instance during any analysis.
Definition: SVFIR.h:115
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:99
constexpr std::remove_reference< T >::type && move(T &&t) noexcept
Definition: SVFUtil.h:447
std::ostream & outs()
Overwrite llvm::outs()
Definition: SVFUtil.h:50
for isBitcode
Definition: BasicTypes.h:68