Static Value-Flow Analysis
Loading...
Searching...
No Matches
SVF::SVFGBuilder Class Reference

#include <SVFGBuilder.h>

Inheritance diagram for SVF::SVFGBuilder:
SVF::MTASVFGBuilder SVF::SaberSVFGBuilder SVF::CFLSVFGBuilder

Public Types

typedef PointerAnalysis::CallSiteSet CallSiteSet
typedef PointerAnalysis::CallEdgeMap CallEdgeMap
typedef PointerAnalysis::FunctionSet FunctionSet
typedef SVFG::SVFGEdgeSetTy SVFGEdgeSet

Public Member Functions

 SVFGBuilder (bool _SVFGWithIndCall=Options::SVFGWithIndirectCall(), bool _SVFGWithPostOpts=Options::OPTSVFG())
 Constructor.
virtual ~SVFGBuilder ()=default
 Destructor.
SVFG * buildPTROnlySVFG (BVDataPTAImpl *pta)
SVFG * buildFullSVFG (BVDataPTAImpl *pta)
SVFG * getSVFG () const
 Get SVFG instance.
void markValidVFEdge (SVFGEdgeSet &edges)
 Mark feasible VF edge by removing it from set vfEdgesAtIndCallSite.
bool isSpuriousVFEdgeAtIndCallSite (const SVFGEdge *edge)
 Return true if this is an VF Edge pre-connected by Andersen's analysis.
virtual std::unique_ptr< MemSSA > buildMSSA (BVDataPTAImpl *pta, bool ptrOnlyMSSA)
 Build Memory SSA.

Protected Member Functions

virtual std::unique_ptr< MRGenerator > createMRGenerator (BVDataPTAImpl *pta, bool ptrOnlyMSSA)
SVFG * build (BVDataPTAImpl *pta, VFG::VFGK kind)
 Create a DDA SVFG. By default actualOut and FormalIN are removed, unless withAOFI is set true.
virtual void buildSVFG ()
 Can be rewritten by subclasses.
virtual void releaseMemory ()
 Release global SVFG.

Protected Attributes

SVFGEdgeSet vfEdgesAtIndCallSite
 SVFG Edges connected at indirect call/ret sites.
std::unique_ptr< SVFG > svfg
bool SVFGWithIndCall
 SVFG with precomputed indirect call edges.
bool SVFGWithPostOpts
 Build optimised version of SVFG.

Detailed Description

SVFG Builder

Definition at line 43 of file SVFGBuilder.h.

Member Typedef Documentation

◆ CallEdgeMap

◆ CallSiteSet

◆ FunctionSet

◆ SVFGEdgeSet

Constructor & Destructor Documentation

◆ SVFGBuilder()

SVF::SVFGBuilder::SVFGBuilder ( bool _SVFGWithIndCall = Options::SVFGWithIndirectCall(),
bool _SVFGWithPostOpts = Options::OPTSVFG() )
inlineexplicit

Constructor.

Definition at line 53 of file SVFGBuilder.h.

54 : svfg(nullptr), SVFGWithIndCall(_SVFGWithIndCall), SVFGWithPostOpts(_SVFGWithPostOpts)
55 {
56 }
bool SVFGWithPostOpts
Build optimised version of SVFG.
bool SVFGWithIndCall
SVFG with precomputed indirect call edges.
std::unique_ptr< SVFG > svfg

◆ ~SVFGBuilder()

virtual SVF::SVFGBuilder::~SVFGBuilder ( )
virtualdefault

Destructor.

Member Function Documentation

◆ build()

SVFG * SVFGBuilder::build ( BVDataPTAImpl * pta,
VFG::VFGK kind )
protected

Create a DDA SVFG. By default actualOut and FormalIN are removed, unless withAOFI is set true.

Create DDA SVFG.

Update call graph using pre-analysis results

Definition at line 65 of file SVFGBuilder.cpp.

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}
#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
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.
virtual void buildSVFG()
Can be rewritten by subclasses.
ICFG * getICFG() const
Definition SVFIR.h:232
@ 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
std::ostream & outs()
Overwrite llvm::outs().
Definition SVFUtil.h:58

◆ buildFullSVFG()

SVFG * SVFGBuilder::buildFullSVFG ( BVDataPTAImpl * pta)

Definition at line 50 of file SVFGBuilder.cpp.

51{
52 return this->SVFGWithPostOpts ? build(pta, VFG::FULLSVFG_OPT)
53 : build(pta, VFG::FULLSVFG);
54}
SVFG * build(BVDataPTAImpl *pta, VFG::VFGK kind)
Create a DDA SVFG. By default actualOut and FormalIN are removed, unless withAOFI is set true.

◆ buildMSSA()

std::unique_ptr< MemSSA > SVFGBuilder::buildMSSA ( BVDataPTAImpl * pta,
bool ptrOnlyMSSA )
virtual

Build Memory SSA.

Definition at line 127 of file SVFGBuilder.cpp.

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}
cJSON * item
Definition cJSON.h:222
static const Option< bool > DumpMSSA
Definition Options.h:140
virtual std::unique_ptr< MRGenerator > createMRGenerator(BVDataPTAImpl *pta, bool ptrOnlyMSSA)
const CallGraph * getCallGraph()
Get CG.
Definition SVFIR.h:249
static SVFIR * getPAG(bool buildFromFile=false)
Singleton design here to make sure we only have one instance during any analysis.
Definition SVFIR.h:121
bool isExtCall(const FunObjVar *fun)
Definition SVFUtil.cpp:526

◆ buildPTROnlySVFG()

SVFG * SVFGBuilder::buildPTROnlySVFG ( BVDataPTAImpl * pta)

Definition at line 44 of file SVFGBuilder.cpp.

45{
47 : build(pta, VFG::PTRONLYSVFG);
48}

◆ buildSVFG()

void SVFGBuilder::buildSVFG ( )
protectedvirtual

Can be rewritten by subclasses.

Create SVFG

Reimplemented in SVF::CFLSVFGBuilder, SVF::MTASVFGBuilder, and SVF::SaberSVFGBuilder.

Definition at line 59 of file SVFGBuilder.cpp.

60{
61 svfg->buildSVFG();
62}

◆ createMRGenerator()

std::unique_ptr< MRGenerator > SVFGBuilder::createMRGenerator ( BVDataPTAImpl * pta,
bool ptrOnlyMSSA )
protectedvirtual

Hook supplying the MRGenerator for the MemSSA built above. The default builds the stock generator selected by Options::MemPar(); MTASVFGBuilder overrides this to inject a thread-aware (ThreadMRG) generator. Ownership transfers to the MemSSA constructed in buildMSSA.

Build the stock MRGenerator selected by Options::MemPar(). MTASVFGBuilder overrides this hook to inject a thread-aware (ThreadMRG) generator instead.

Reimplemented in SVF::MTASVFGBuilder.

Definition at line 111 of file SVFGBuilder.cpp.

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}
@ InterDisjoint
Definition MemSSA.h:117
@ IntraDisjoint
Definition MemSSA.h:116
static const OptionMap< u32_t > MemPar
Definition Options.h:143

◆ getSVFG()

SVFG * SVF::SVFGBuilder::getSVFG ( ) const
inline

Get SVFG instance.

Definition at line 65 of file SVFGBuilder.h.

66 {
67 return svfg.get();
68 }

◆ isSpuriousVFEdgeAtIndCallSite()

bool SVF::SVFGBuilder::isSpuriousVFEdgeAtIndCallSite ( const SVFGEdge * edge)
inline

Return true if this is an VF Edge pre-connected by Andersen's analysis.

Definition at line 77 of file SVFGBuilder.h.

78 {
79 return vfEdgesAtIndCallSite.find(const_cast<SVFGEdge*>(edge))!=vfEdgesAtIndCallSite.end();
80 }
SVFGEdgeSet vfEdgesAtIndCallSite
SVFG Edges connected at indirect call/ret sites.
VFGEdge SVFGEdge
Definition SVFG.h:42

◆ markValidVFEdge()

void SVF::SVFGBuilder::markValidVFEdge ( SVFGEdgeSet & edges)
inline

Mark feasible VF edge by removing it from set vfEdgesAtIndCallSite.

Definition at line 71 of file SVFGBuilder.h.

72 {
73 for(SVFGEdgeSet::iterator it = edges.begin(), eit = edges.end(); it!=eit; ++it)
74 vfEdgesAtIndCallSite.erase(*it);
75 }

◆ releaseMemory()

void SVFGBuilder::releaseMemory ( )
protectedvirtual

Release global SVFG.

Release memory

Definition at line 102 of file SVFGBuilder.cpp.

103{
104 svfg->clearMSSA();
105}

Member Data Documentation

◆ svfg

std::unique_ptr<SVFG> SVF::SVFGBuilder::svfg
protected

Definition at line 101 of file SVFGBuilder.h.

◆ SVFGWithIndCall

bool SVF::SVFGBuilder::SVFGWithIndCall
protected

SVFG with precomputed indirect call edges.

Definition at line 103 of file SVFGBuilder.h.

◆ SVFGWithPostOpts

bool SVF::SVFGBuilder::SVFGWithPostOpts
protected

Build optimised version of SVFG.

Definition at line 105 of file SVFGBuilder.h.

◆ vfEdgesAtIndCallSite

SVFGEdgeSet SVF::SVFGBuilder::vfEdgesAtIndCallSite
protected

SVFG Edges connected at indirect call/ret sites.

Definition at line 100 of file SVFGBuilder.h.


The documentation for this class was generated from the following files: