Static Value-Flow Analysis
Loading...
Searching...
No Matches
Public Types | Static Public Attributes | Protected Member Functions | Protected Attributes | Private Attributes | List of all members
SVF::MemSSA Class Reference

#include <MemSSA.h>

Public Types

enum  MemPartition { Distinct , IntraDisjoint , InterDisjoint }
 
typedef MemRegion::Condition Condition
 define condition here changes needed if we add new type
 
typedef MSSAMU< ConditionMU
 
typedef RetMU< ConditionRETMU
 
typedef LoadMU< ConditionLOADMU
 
typedef CallMU< ConditionCALLMU
 
typedef MSSACHI< ConditionCHI
 
typedef EntryCHI< ConditionENTRYCHI
 
typedef StoreCHI< ConditionSTORECHI
 
typedef CallCHI< ConditionCALLCHI
 
typedef MSSAPHI< ConditionPHI
 
typedef MSSADEF MDEF
 
typedef Set< MU * > MUSet
 
typedef Set< CHI * > CHISet
 
typedef Set< PHI * > PHISet
 
typedef MRGenerator::MRSet MRSet
 Define mem region set.
 
typedef std::vector< const MemRegion * > MRVector
 
typedef Map< const LoadStmt *, MUSetLoadToMUSetMap
 
typedef Map< const StoreStmt *, CHISetStoreToChiSetMap
 
typedef Map< const CallICFGNode *, MUSetCallSiteToMUSetMap
 
typedef Map< const CallICFGNode *, CHISetCallSiteToCHISetMap
 
typedef OrderedMap< const SVFBasicBlock *, PHISetBBToPhiSetMap
 
typedef Map< const FunObjVar *, CHISetFunToEntryChiSetMap
 Map from fun to its entry chi set and return mu set.
 
typedef Map< const FunObjVar *, MUSetFunToReturnMuSetMap
 
typedef std::vector< const SVFBasicBlock * > BBList
 For phi insertion.
 
typedef Map< const SVFBasicBlock *, MRSetBBToMRSetMap
 
typedef Map< const MemRegion *, BBListMemRegToBBsMap
 
typedef Map< const MemRegion *, std::vector< MRVer * > > MemRegToVerStackMap
 For SSA renaming.
 
typedef Map< const MemRegion *, MRVERSIONMemRegToCounterMap
 
typedef SVFIR::SVFStmtList SVFStmtList
 SVFIR edge list.
 

Static Public Attributes

static double timeOfGeneratingMemRegions = 0
 Statistics.
 
static double timeOfCreateMUCHI = 0
 Time for generating mu/chi for load/store/calls.
 
static double timeOfInsertingPHI = 0
 Time for inserting phis.
 
static double timeOfSSARenaming = 0
 Time for SSA rename.
 

Protected Member Functions

virtual void createMUCHI (const FunObjVar &fun)
 Create mu chi for candidate regions in a function.
 
virtual void insertPHI (const FunObjVar &fun)
 Insert phi for candidate regions in a function.
 
virtual void SSARename (const FunObjVar &fun)
 SSA rename for a function.
 
virtual void SSARenameBB (const SVFBasicBlock &bb)
 SSA rename for a basic block.
 

Protected Attributes

BVDataPTAImplpta
 
std::unique_ptr< MRGeneratormrGen
 
MemSSAStatstat
 

Private Attributes

LoadToMUSetMap load2MuSetMap
 
StoreToChiSetMap store2ChiSetMap
 
CallSiteToMUSetMap callsiteToMuSetMap
 
CallSiteToCHISetMap callsiteToChiSetMap
 
BBToPhiSetMap bb2PhiSetMap
 
FunToEntryChiSetMap funToEntryChiSetMap
 
FunToReturnMuSetMap funToReturnMuSetMap
 
MemRegToVerStackMap mr2VerStackMap
 
MemRegToCounterMap mr2CounterMap
 
MRSet usedRegs
 The following three set are used for prune SSA phi insertion.
 
MemRegToBBsMap reg2BBMap
 Maps memory region to its basic block.
 
MRSet varKills
 Collect memory regions whose definition killed.
 
std::vector< std::unique_ptr< MRVer > > usedMRVers
 
void destroy ()
 Release the memory.
 
MRVernewSSAName (const MemRegion *mr, MSSADEF *def)
 Get a new SSA name of a memory region.
 
MRVergetTopStackVer (const MemRegion *mr)
 Get the last version of the SSA ver of memory region.
 
void collectRegUses (const MemRegion *mr)
 Collect region uses and region defs according to mus/chis, in order to insert phis.
 
void collectRegDefs (const SVFBasicBlock *bb, const MemRegion *mr)
 
void AddLoadMU (const SVFBasicBlock *bb, const LoadStmt *load, const MRSet &mrSet)
 Add methods for mus/chis/phis.
 
void AddStoreCHI (const SVFBasicBlock *bb, const StoreStmt *store, const MRSet &mrSet)
 
void AddCallSiteMU (const CallICFGNode *cs, const MRSet &mrSet)
 
void AddCallSiteCHI (const CallICFGNode *cs, const MRSet &mrSet)
 
void AddMSSAPHI (const SVFBasicBlock *bb, const MRSet &mrSet)
 
void AddLoadMU (const SVFBasicBlock *bb, const LoadStmt *load, const MemRegion *mr)
 
void AddStoreCHI (const SVFBasicBlock *bb, const StoreStmt *store, const MemRegion *mr)
 
void AddCallSiteMU (const CallICFGNode *cs, const MemRegion *mr)
 
void AddCallSiteCHI (const CallICFGNode *cs, const MemRegion *mr)
 
void AddMSSAPHI (const SVFBasicBlock *bb, const MemRegion *mr)
 
void RenameMuSet (const MUSet &muSet)
 Rename mus, chis and phis.
 
void RenameChiSet (const CHISet &chiSet, MRVector &memRegs)
 Rename chi set.
 
void RenamePhiRes (const PHISet &phiSet, MRVector &memRegs)
 Rename result (LHS) of phis.
 
void RenamePhiOps (const PHISet &phiSet, u32_t pos, MRVector &)
 Rename operands (RHS) of phis.
 
 MemSSA (BVDataPTAImpl *p, std::unique_ptr< MRGenerator > mrGenerator)
 
SVFIRgetPAG ()
 Return SVFIR.
 
BVDataPTAImplgetPTA () const
 Return PTA.
 
MRGeneratorgetMRGenerator ()
 Return MRGenerator (non-owning; MemSSA retains ownership)
 
virtual void buildMemSSA (const FunObjVar &fun)
 We start from here.
 
void performStat ()
 Perform statistics.
 
bool hasMU (const PAGEdge *inst) const
 Has mu/chi methods.
 
bool hasCHI (const PAGEdge *inst) const
 
bool hasMU (const CallICFGNode *cs) const
 
bool hasCHI (const CallICFGNode *cs) const
 
bool hasFuncEntryChi (const FunObjVar *fun) const
 Has function entry chi or return mu.
 
bool hasReturnMu (const FunObjVar *fun) const
 
CHISetgetFuncEntryChiSet (const FunObjVar *fun)
 
MUSetgetReturnMuSet (const FunObjVar *fun)
 
MUSetgetMUSet (const LoadStmt *ld)
 Get methods of mu/chi/phi.
 
CHISetgetCHISet (const StoreStmt *st)
 
MUSetgetMUSet (const CallICFGNode *cs)
 
CHISetgetCHISet (const CallICFGNode *cs)
 
PHISetgetPHISet (const SVFBasicBlock *bb)
 
bool hasPHISet (const SVFBasicBlock *bb) const
 
LoadToMUSetMapgetLoadToMUSetMap ()
 
StoreToChiSetMapgetStoreToChiSetMap ()
 
FunToReturnMuSetMapgetFunToRetMuSetMap ()
 
FunToEntryChiSetMapgetFunToEntryChiSetMap ()
 
CallSiteToMUSetMapgetCallSiteToMuSetMap ()
 
CallSiteToCHISetMapgetCallSiteToChiSetMap ()
 
BBToPhiSetMapgetBBToPhiSetMap ()
 
u32_t getLoadMuNum () const
 Stat methods.
 
u32_t getStoreChiNum () const
 
u32_t getFunEntryChiNum () const
 
u32_t getFunRetMuNum () const
 
u32_t getCallSiteMuNum () const
 
u32_t getCallSiteChiNum () const
 
u32_t getBBPhiNum () const
 
void dumpMSSA (OutStream &Out=SVFUtil::outs())
 Print Memory SSA.
 

Detailed Description

Definition at line 52 of file MemSSA.h.

Member Typedef Documentation

◆ BBList

For phi insertion.

Definition at line 93 of file MemSSA.h.

◆ BBToMRSetMap

Definition at line 94 of file MemSSA.h.

◆ BBToPhiSetMap

Definition at line 84 of file MemSSA.h.

◆ CALLCHI

Definition at line 66 of file MemSSA.h.

◆ CALLMU

Definition at line 62 of file MemSSA.h.

◆ CallSiteToCHISetMap

Definition at line 83 of file MemSSA.h.

◆ CallSiteToMUSetMap

Definition at line 82 of file MemSSA.h.

◆ CHI

Definition at line 63 of file MemSSA.h.

◆ CHISet

Definition at line 71 of file MemSSA.h.

◆ Condition

define condition here changes needed if we add new type

Definition at line 58 of file MemSSA.h.

◆ ENTRYCHI

Definition at line 64 of file MemSSA.h.

◆ FunToEntryChiSetMap

Map from fun to its entry chi set and return mu set.

Definition at line 88 of file MemSSA.h.

◆ FunToReturnMuSetMap

Definition at line 89 of file MemSSA.h.

◆ LOADMU

Definition at line 61 of file MemSSA.h.

◆ LoadToMUSetMap

Map loads/stores to its mem regions, TODO:visitAtomicCmpXchgInst, visitAtomicRMWInst??

Definition at line 80 of file MemSSA.h.

◆ MDEF

Definition at line 68 of file MemSSA.h.

◆ MemRegToBBsMap

Definition at line 95 of file MemSSA.h.

◆ MemRegToCounterMap

Definition at line 100 of file MemSSA.h.

◆ MemRegToVerStackMap

For SSA renaming.

Definition at line 99 of file MemSSA.h.

◆ MRSet

Define mem region set.

Definition at line 75 of file MemSSA.h.

◆ MRVector

Definition at line 76 of file MemSSA.h.

◆ MU

Definition at line 59 of file MemSSA.h.

◆ MUSet

Definition at line 70 of file MemSSA.h.

◆ PHI

Definition at line 67 of file MemSSA.h.

◆ PHISet

Definition at line 72 of file MemSSA.h.

◆ RETMU

Definition at line 60 of file MemSSA.h.

◆ STORECHI

Definition at line 65 of file MemSSA.h.

◆ StoreToChiSetMap

Definition at line 81 of file MemSSA.h.

◆ SVFStmtList

SVFIR edge list.

Definition at line 103 of file MemSSA.h.

Member Enumeration Documentation

◆ MemPartition

Enumerator
Distinct 
IntraDisjoint 
InterDisjoint 

Definition at line 113 of file MemSSA.h.

114 {
115 Distinct,
118 };
@ InterDisjoint
Definition MemSSA.h:117
@ IntraDisjoint
Definition MemSSA.h:116

Constructor & Destructor Documentation

◆ MemSSA()

MemSSA::MemSSA ( BVDataPTAImpl p,
std::unique_ptr< MRGenerator mrGenerator 
)

Constructor. The builder (SVFGBuilder::createMRGenerator) supplies the MRGenerator and decides the partition strategy / thread-awareness; MemSSA takes ownership of it via unique_ptr. mrGenerator must not be null.

Constructor

Generate whole program memory regions

Definition at line 49 of file MemSSA.cpp.

50{
51 pta = p;
53 && "please specify a pointer analysis");
54 assert(mrGenerator != nullptr && "builder must supply an MRGenerator");
55 mrGen = std::move(mrGenerator);
56
57 stat = new MemSSAStat(this);
58
60 double mrStart = stat->getClk(true);
61 mrGen->generateMRs();
62 double mrEnd = stat->getClk(true);
64}
#define TIMEINTERVAL
Definition SVFType.h:604
cJSON * p
Definition cJSON.cpp:2559
static double timeOfGeneratingMemRegions
Statistics.
Definition MemSSA.h:107
BVDataPTAImpl * pta
Definition MemSSA.h:121
MemSSAStat * stat
Definition MemSSA.h:123
std::unique_ptr< MRGenerator > mrGen
Definition MemSSA.h:122
PTATY getAnalysisTy() const
Type of pointer analysis.
static double getClk(bool mark=false)
Definition SVFStat.cpp:51
@ Default_PTA
default pta without any analysis
Definition PTATY.h:35
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:76

◆ ~MemSSA()

virtual SVF::MemSSA::~MemSSA ( )
inlinevirtual

Destructor.

Definition at line 303 of file MemSSA.h.

304 {
305 destroy();
306 }
void destroy()
Release the memory.
Definition MemSSA.cpp:360

Member Function Documentation

◆ AddCallSiteCHI() [1/2]

void SVF::MemSSA::AddCallSiteCHI ( const CallICFGNode cs,
const MemRegion mr 
)
inlineprivate

Definition at line 233 of file MemSSA.h.

234 {
235 CALLCHI* chi = new CALLCHI(cs, mr);
236 callsiteToChiSetMap[cs].insert(chi);
237 collectRegUses(mr);
238 collectRegDefs(chi->getBasicBlock(),mr);
239 }
CallSiteToCHISetMap callsiteToChiSetMap
Definition MemSSA.h:137
void collectRegDefs(const SVFBasicBlock *bb, const MemRegion *mr)
Definition MemSSA.h:180
CallCHI< Condition > CALLCHI
Definition MemSSA.h:66
void collectRegUses(const MemRegion *mr)
Collect region uses and region defs according to mus/chis, in order to insert phis.
Definition MemSSA.h:175

◆ AddCallSiteCHI() [2/2]

void SVF::MemSSA::AddCallSiteCHI ( const CallICFGNode cs,
const MRSet mrSet 
)
inlineprivate

Definition at line 204 of file MemSSA.h.

205 {
206 for (MRSet::iterator iter = mrSet.begin(), eiter = mrSet.end(); iter != eiter; ++iter)
207 AddCallSiteCHI(cs,*iter);
208 }
void AddCallSiteCHI(const CallICFGNode *cs, const MRSet &mrSet)
Definition MemSSA.h:204

◆ AddCallSiteMU() [1/2]

void SVF::MemSSA::AddCallSiteMU ( const CallICFGNode cs,
const MemRegion mr 
)
inlineprivate

Definition at line 227 of file MemSSA.h.

228 {
229 CALLMU* mu = new CALLMU(cs, mr);
230 callsiteToMuSetMap[cs].insert(mu);
231 collectRegUses(mr);
232 }
CallMU< Condition > CALLMU
Definition MemSSA.h:62
CallSiteToMUSetMap callsiteToMuSetMap
Definition MemSSA.h:136

◆ AddCallSiteMU() [2/2]

void SVF::MemSSA::AddCallSiteMU ( const CallICFGNode cs,
const MRSet mrSet 
)
inlineprivate

Definition at line 199 of file MemSSA.h.

200 {
201 for (MRSet::iterator iter = mrSet.begin(), eiter = mrSet.end(); iter != eiter; ++iter)
202 AddCallSiteMU(cs,*iter);
203 }
void AddCallSiteMU(const CallICFGNode *cs, const MRSet &mrSet)
Definition MemSSA.h:199

◆ AddLoadMU() [1/2]

void SVF::MemSSA::AddLoadMU ( const SVFBasicBlock bb,
const LoadStmt load,
const MemRegion mr 
)
inlineprivate

Definition at line 214 of file MemSSA.h.

215 {
216 LOADMU* mu = new LOADMU(bb,load, mr);
217 load2MuSetMap[load].insert(mu);
218 collectRegUses(mr);
219 }
LoadMU< Condition > LOADMU
Definition MemSSA.h:61
LoadToMUSetMap load2MuSetMap
Definition MemSSA.h:134

◆ AddLoadMU() [2/2]

void SVF::MemSSA::AddLoadMU ( const SVFBasicBlock bb,
const LoadStmt load,
const MRSet mrSet 
)
inlineprivate

Add methods for mus/chis/phis.

Definition at line 189 of file MemSSA.h.

190 {
191 for (MRSet::iterator iter = mrSet.begin(), eiter = mrSet.end(); iter != eiter; ++iter)
192 AddLoadMU(bb,load,*iter);
193 }
void AddLoadMU(const SVFBasicBlock *bb, const LoadStmt *load, const MRSet &mrSet)
Add methods for mus/chis/phis.
Definition MemSSA.h:189

◆ AddMSSAPHI() [1/2]

void SVF::MemSSA::AddMSSAPHI ( const SVFBasicBlock bb,
const MemRegion mr 
)
inlineprivate

Definition at line 240 of file MemSSA.h.

241 {
242 bb2PhiSetMap[bb].insert(new PHI(bb, mr));
243 }
BBToPhiSetMap bb2PhiSetMap
Definition MemSSA.h:138
MSSAPHI< Condition > PHI
Definition MemSSA.h:67

◆ AddMSSAPHI() [2/2]

void SVF::MemSSA::AddMSSAPHI ( const SVFBasicBlock bb,
const MRSet mrSet 
)
inlineprivate

Definition at line 209 of file MemSSA.h.

210 {
211 for (MRSet::iterator iter = mrSet.begin(), eiter = mrSet.end(); iter != eiter; ++iter)
212 AddMSSAPHI(bb,*iter);
213 }
void AddMSSAPHI(const SVFBasicBlock *bb, const MRSet &mrSet)
Definition MemSSA.h:209

◆ AddStoreCHI() [1/2]

void SVF::MemSSA::AddStoreCHI ( const SVFBasicBlock bb,
const StoreStmt store,
const MemRegion mr 
)
inlineprivate

Definition at line 220 of file MemSSA.h.

221 {
222 STORECHI* chi = new STORECHI(bb,store, mr);
223 store2ChiSetMap[store].insert(chi);
224 collectRegUses(mr);
225 collectRegDefs(bb,mr);
226 }
StoreCHI< Condition > STORECHI
Definition MemSSA.h:65
StoreToChiSetMap store2ChiSetMap
Definition MemSSA.h:135

◆ AddStoreCHI() [2/2]

void SVF::MemSSA::AddStoreCHI ( const SVFBasicBlock bb,
const StoreStmt store,
const MRSet mrSet 
)
inlineprivate

Definition at line 194 of file MemSSA.h.

195 {
196 for (MRSet::iterator iter = mrSet.begin(), eiter = mrSet.end(); iter != eiter; ++iter)
197 AddStoreCHI(bb,store,*iter);
198 }
void AddStoreCHI(const SVFBasicBlock *bb, const StoreStmt *store, const MRSet &mrSet)
Definition MemSSA.h:194

◆ buildMemSSA()

void MemSSA::buildMemSSA ( const FunObjVar fun)
virtual

We start from here.

Start building memory SSA

Create mus/chis for loads/stores/calls for memory regions

Insert PHI for memory regions

SSA rename for memory regions

Definition at line 74 of file MemSSA.cpp.

75{
76
77 assert(!isExtCall(&fun) && "we do not build memory ssa for external functions");
78
79 DBOUT(DMSSA, outs() << "Building Memory SSA for function " << fun.getName()
80 << " \n");
81
82 usedRegs.clear();
83 reg2BBMap.clear();
84
86 double muchiStart = stat->getClk(true);
87 createMUCHI(fun);
88 double muchiEnd = stat->getClk(true);
90
92 double phiStart = stat->getClk(true);
93 insertPHI(fun);
94 double phiEnd = stat->getClk(true);
96
98 double renameStart = stat->getClk(true);
99 SSARename(fun);
100 double renameEnd = stat->getClk(true);
102
103}
#define DBOUT(TYPE, X)
LLVM debug macros, define type of your DBUG model of each pass.
Definition SVFType.h:576
#define DMSSA
Definition SVFType.h:593
virtual void createMUCHI(const FunObjVar &fun)
Create mu chi for candidate regions in a function.
Definition MemSSA.cpp:109
static double timeOfInsertingPHI
Time for inserting phis.
Definition MemSSA.h:109
static double timeOfCreateMUCHI
Time for generating mu/chi for load/store/calls.
Definition MemSSA.h:108
virtual void insertPHI(const FunObjVar &fun)
Insert phi for candidate regions in a function.
Definition MemSSA.cpp:195
static double timeOfSSARenaming
Time for SSA rename.
Definition MemSSA.h:110
virtual void SSARename(const FunObjVar &fun)
SSA rename for a function.
Definition MemSSA.cpp:243
MRSet usedRegs
The following three set are used for prune SSA phi insertion.
Definition MemSSA.h:150
MemRegToBBsMap reg2BBMap
Maps memory region to its basic block.
Definition MemSSA.h:152
virtual const std::string & getName() const
Definition SVFValue.h:184
bool isExtCall(const FunObjVar *fun)
Definition SVFUtil.cpp:441
std::ostream & outs()
Overwrite llvm::outs()
Definition SVFUtil.h:52

◆ collectRegDefs()

void SVF::MemSSA::collectRegDefs ( const SVFBasicBlock bb,
const MemRegion mr 
)
inlineprivate

Definition at line 180 of file MemSSA.h.

181 {
182 varKills.insert(mr);
183 reg2BBMap[mr].push_back(bb);
184 }
MRSet varKills
Collect memory regions whose definition killed.
Definition MemSSA.h:154

◆ collectRegUses()

void SVF::MemSSA::collectRegUses ( const MemRegion mr)
inlineprivate

Collect region uses and region defs according to mus/chis, in order to insert phis.

Definition at line 175 of file MemSSA.h.

176 {
177 if (0 == varKills.count(mr))
178 usedRegs.insert(mr);
179 }

◆ createMUCHI()

void MemSSA::createMUCHI ( const FunObjVar fun)
protectedvirtual

Create mu chi for candidate regions in a function.

Create mu/chi according to memory regions collect used mrs in usedRegs and construction map from region to BB for prune SSA phi insertion

get all reachable basic blocks from function entry ignore dead basic blocks

if the function does not have a reachable return instruction from function entry then we won't create return mu for it

Definition at line 109 of file MemSSA.cpp.

110{
111
112
113 DBOUT(DMSSA,
114 outs() << "\t creating mu chi for function " << fun.getName()
115 << "\n");
116 // 1. create mu/chi
117 // insert a set of mus for memory regions at each load
118 // inset a set of chis for memory regions at each store
119
120 // 2. find global names (region name before renaming) of each memory region,
121 // collect used mrs in usedRegs, and collect its def basic block in reg2BBMap
122 // in the form of mu(r) and r = chi (r)
123 // a) mu(r):
124 // if(r \not\in varKills) global = global \cup r
125 // b) r = chi(r):
126 // if(r \not\in varKills) global = global \cup r
127 // varKills = varKills \cup r
128 // block(r) = block(r) \cup bb_{chi}
129
132 BBList reachableBBs = fun.getReachableBBs();
133
134 for (BBList::const_iterator iter = reachableBBs.begin(), eiter = reachableBBs.end();
135 iter != eiter; ++iter)
136 {
137 const SVFBasicBlock* bb = *iter;
138 varKills.clear();
139 for (const auto& inst: bb->getICFGNodeList())
140 {
141 if(mrGen->hasSVFStmtList(inst))
142 {
143 SVFStmtList& pagEdgeList = mrGen->getSVFStmtsFromInst(inst);
144 for (SVFStmtList::const_iterator bit = pagEdgeList.begin(),
145 ebit = pagEdgeList.end(); bit != ebit; ++bit)
146 {
147 const PAGEdge* inst = *bit;
148 if (const LoadStmt* load = SVFUtil::dyn_cast<LoadStmt>(inst))
149 AddLoadMU(bb, load, mrGen->getLoadMRSet(load));
150 else if (const StoreStmt* store = SVFUtil::dyn_cast<StoreStmt>(inst))
151 AddStoreCHI(bb, store, mrGen->getStoreMRSet(store));
152 }
153 }
154 if (isNonInstricCallSite(inst))
155 {
156 const CallICFGNode* cs = cast<CallICFGNode>(inst);
157 if(mrGen->hasRefMRSet(cs))
158 AddCallSiteMU(cs,mrGen->getCallSiteRefMRSet(cs));
159
160 if(mrGen->hasModMRSet(cs))
161 AddCallSiteCHI(cs,mrGen->getCallSiteModMRSet(cs));
162 }
163 }
164 }
165
166 // create entry chi for this function including all memory regions
167 // initialize them with version 0 and 1 r_1 = chi (r_0)
168 for (MRSet::iterator iter = usedRegs.begin(), eiter = usedRegs.end();
169 iter != eiter; ++iter)
170 {
171 const MemRegion* mr = *iter;
172 // initialize mem region version and stack for renaming phase
173 mr2CounterMap[mr] = 0;
174 mr2VerStackMap[mr].clear();
175 ENTRYCHI* chi = new ENTRYCHI(&fun, mr);
176 chi->setOpVer(newSSAName(mr,chi));
177 chi->setResVer(newSSAName(mr,chi));
178 funToEntryChiSetMap[&fun].insert(chi);
179
182 if(fun.hasReturn())
183 {
184 RETMU* mu = new RETMU(&fun, mr);
185 funToReturnMuSetMap[&fun].insert(mu);
186 }
187
188 }
189
190}
const std::vector< const SVFBasicBlock * > & getReachableBBs() const
bool hasReturn() const
Memory Region class.
Definition MemRegion.h:60
std::vector< const SVFBasicBlock * > BBList
For phi insertion.
Definition MemSSA.h:93
MemRegToCounterMap mr2CounterMap
Definition MemSSA.h:144
MRVer * newSSAName(const MemRegion *mr, MSSADEF *def)
Get a new SSA name of a memory region.
Definition MemSSA.cpp:341
SVFIR::SVFStmtList SVFStmtList
SVFIR edge list.
Definition MemSSA.h:103
FunToEntryChiSetMap funToEntryChiSetMap
Definition MemSSA.h:140
EntryCHI< Condition > ENTRYCHI
Definition MemSSA.h:64
RetMU< Condition > RETMU
Definition MemSSA.h:60
FunToReturnMuSetMap funToReturnMuSetMap
Definition MemSSA.h:141
MemRegToVerStackMap mr2VerStackMap
Definition MemSSA.h:143
bool isNonInstricCallSite(const ICFGNode *inst)
Whether an instruction is a callsite in the application code, excluding llvm intrinsic calls.
Definition SVFUtil.h:182

◆ destroy()

void MemSSA::destroy ( )
private

Release the memory.

Clean up memory

Definition at line 360 of file MemSSA.cpp.

361{
362
363 for (LoadToMUSetMap::iterator iter = load2MuSetMap.begin(), eiter =
364 load2MuSetMap.end(); iter != eiter; ++iter)
365 {
366 for (MUSet::iterator it = iter->second.begin(), eit =
367 iter->second.end(); it != eit; ++it)
368 {
369 delete *it;
370 }
371 }
372
373 for (StoreToChiSetMap::iterator iter = store2ChiSetMap.begin(), eiter =
374 store2ChiSetMap.end(); iter != eiter; ++iter)
375 {
376 for (CHISet::iterator it = iter->second.begin(), eit =
377 iter->second.end(); it != eit; ++it)
378 {
379 delete *it;
380 }
381 }
382
383 for (CallSiteToMUSetMap::iterator iter = callsiteToMuSetMap.begin(),
384 eiter = callsiteToMuSetMap.end(); iter != eiter; ++iter)
385 {
386 for (MUSet::iterator it = iter->second.begin(), eit =
387 iter->second.end(); it != eit; ++it)
388 {
389 delete *it;
390 }
391 }
392
393 for (CallSiteToCHISetMap::iterator iter = callsiteToChiSetMap.begin(),
394 eiter = callsiteToChiSetMap.end(); iter != eiter; ++iter)
395 {
396 for (CHISet::iterator it = iter->second.begin(), eit =
397 iter->second.end(); it != eit; ++it)
398 {
399 delete *it;
400 }
401 }
402
403 for (FunToEntryChiSetMap::iterator iter = funToEntryChiSetMap.begin(),
404 eiter = funToEntryChiSetMap.end(); iter != eiter; ++iter)
405 {
406 for (CHISet::iterator it = iter->second.begin(), eit =
407 iter->second.end(); it != eit; ++it)
408 {
409 delete *it;
410 }
411 }
412
413 for (FunToReturnMuSetMap::iterator iter = funToReturnMuSetMap.begin(),
414 eiter = funToReturnMuSetMap.end(); iter != eiter; ++iter)
415 {
416 for (MUSet::iterator it = iter->second.begin(), eit =
417 iter->second.end(); it != eit; ++it)
418 {
419 delete *it;
420 }
421 }
422
423 for (BBToPhiSetMap::iterator iter = bb2PhiSetMap.begin(), eiter =
424 bb2PhiSetMap.end(); iter != eiter; ++iter)
425 {
426 for (PHISet::iterator it = iter->second.begin(), eit =
427 iter->second.end(); it != eit; ++it)
428 {
429 delete *it;
430 }
431 }
432
433 mrGen.reset();
434 delete stat;
435 stat = nullptr;
436 pta = nullptr;
437}

◆ dumpMSSA()

void MemSSA::dumpMSSA ( OutStream Out = SVFUtil::outs())

Print Memory SSA.

Print SSA

Definition at line 569 of file MemSSA.cpp.

570{
571
573 for (const auto& item: *svfirCallGraph)
574 {
575 const FunObjVar* fun = item.second->getFunction();
576 if(Options::MSSAFun()!="" && Options::MSSAFun()!=fun->getName())
577 continue;
578
579 Out << "==========FUNCTION: " << fun->getName() << "==========\n";
580 // dump function entry chi nodes
581 if (hasFuncEntryChi(fun))
582 {
584 for (CHISet::iterator chi_it = entry_chis.begin(); chi_it != entry_chis.end(); chi_it++)
585 {
586 (*chi_it)->dump();
587 }
588 }
589
590 for (FunObjVar::const_bb_iterator bit = fun->begin(), ebit = fun->end();
591 bit != ebit; ++bit)
592 {
593 const SVFBasicBlock* bb = bit->second;
594 Out << bb->getName() << "\n";
595 PHISet& phiSet = getPHISet(bb);
596 for(PHISet::iterator pi = phiSet.begin(), epi = phiSet.end(); pi !=epi; ++pi)
597 {
598 (*pi)->dump();
599 }
600
601 bool last_is_chi = false;
602 for (const auto& inst: bb->getICFGNodeList())
603 {
604 bool isAppCall = isNonInstricCallSite(inst) && !isExtCall(inst);
605 if (isAppCall || isHeapAllocExtCall(inst))
606 {
607 const CallICFGNode* cs = cast<CallICFGNode>(inst);
608 if(hasMU(cs))
609 {
610 if (!last_is_chi)
611 {
612 Out << "\n";
613 }
614 for (MUSet::iterator mit = getMUSet(cs).begin(), emit = getMUSet(cs).end();
615 mit != emit; ++mit)
616 {
617 (*mit)->dump();
618 }
619 }
620
621 Out << inst->toString() << "\n";
622
623 if(hasCHI(cs))
624 {
625 for (CHISet::iterator cit = getCHISet(cs).begin(), ecit = getCHISet(cs).end();
626 cit != ecit; ++cit)
627 {
628 (*cit)->dump();
629 }
630 Out << "\n";
631 last_is_chi = true;
632 }
633 else
634 last_is_chi = false;
635 }
636 else
637 {
638 bool dump_preamble = false;
639 SVFStmtList& pagEdgeList = mrGen->getSVFStmtsFromInst(inst);
640 for(SVFStmtList::const_iterator bit = pagEdgeList.begin(), ebit= pagEdgeList.end();
641 bit!=ebit; ++bit)
642 {
643 const PAGEdge* edge = *bit;
644 if (const LoadStmt* load = SVFUtil::dyn_cast<LoadStmt>(edge))
645 {
646 MUSet& muSet = getMUSet(load);
647 for(MUSet::iterator it = muSet.begin(), eit = muSet.end(); it!=eit; ++it)
648 {
649 if (!dump_preamble && !last_is_chi)
650 {
651 Out << "\n";
652 dump_preamble = true;
653 }
654 (*it)->dump();
655 }
656 }
657 }
658
659 Out << inst->toString() << "\n";
660
661 bool has_chi = false;
662 for(SVFStmtList::const_iterator bit = pagEdgeList.begin(), ebit= pagEdgeList.end();
663 bit!=ebit; ++bit)
664 {
665 const PAGEdge* edge = *bit;
666 if (const StoreStmt* store = SVFUtil::dyn_cast<StoreStmt>(edge))
667 {
668 CHISet& chiSet = getCHISet(store);
669 for(CHISet::iterator it = chiSet.begin(), eit = chiSet.end(); it!=eit; ++it)
670 {
671 has_chi = true;
672 (*it)->dump();
673 }
674 }
675 }
676 if (has_chi)
677 {
678 Out << "\n";
679 last_is_chi = true;
680 }
681 else
682 last_is_chi = false;
683 }
684 }
685 }
686
687 // dump return mu nodes
688 if (hasReturnMu(fun))
689 {
691 for (MUSet::iterator mu_it = return_mus.begin(); mu_it != return_mus.end(); mu_it++)
692 {
693 (*mu_it)->dump();
694 }
695 }
696 }
697}
cJSON * item
Definition cJSON.h:222
BasicBlockGraph::IDToNodeMapTy::const_iterator const_bb_iterator
const_bb_iterator begin() const
const_bb_iterator end() const
PHISet & getPHISet(const SVFBasicBlock *bb)
Definition MemSSA.h:399
CHISet & getCHISet(const StoreStmt *st)
Definition MemSSA.h:387
bool hasReturnMu(const FunObjVar *fun) const
Definition MemSSA.h:366
CHISet & getFuncEntryChiSet(const FunObjVar *fun)
Definition MemSSA.h:371
Set< MU * > MUSet
Definition MemSSA.h:70
Set< PHI * > PHISet
Definition MemSSA.h:72
bool hasFuncEntryChi(const FunObjVar *fun) const
Has function entry chi or return mu.
Definition MemSSA.h:362
bool hasCHI(const PAGEdge *inst) const
Definition MemSSA.h:338
MUSet & getMUSet(const LoadStmt *ld)
Get methods of mu/chi/phi.
Definition MemSSA.h:383
MUSet & getReturnMuSet(const FunObjVar *fun)
Definition MemSSA.h:375
bool hasMU(const PAGEdge *inst) const
Has mu/chi methods.
Definition MemSSA.h:327
Set< CHI * > CHISet
Definition MemSSA.h:71
static const Option< std::string > MSSAFun
Definition Options.h:139
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
bool isHeapAllocExtCall(const ICFGNode *cs)
Definition SVFUtil.cpp:361

◆ getBBPhiNum()

u32_t MemSSA::getBBPhiNum ( ) const

Get PHI numbers

Definition at line 553 of file MemSSA.cpp.

554{
555 u32_t num = 0;
556 BBToPhiSetMap::const_iterator it = bb2PhiSetMap.begin();
557 BBToPhiSetMap::const_iterator eit = bb2PhiSetMap.end();
558 for (; it != eit; it++)
559 {
560 const PHISet & phiSet = it->second;
561 num+= phiSet.size();
562 }
563 return num;
564}
unsigned u32_t
Definition CommandLine.h:18

◆ getBBToPhiSetMap()

BBToPhiSetMap & SVF::MemSSA::getBBToPhiSetMap ( )
inline

Definition at line 431 of file MemSSA.h.

432 {
433 return bb2PhiSetMap;
434 }

◆ getCallSiteChiNum()

u32_t MemSSA::getCallSiteChiNum ( ) const

Get CallCHI numbers

Definition at line 536 of file MemSSA.cpp.

537{
538 u32_t num = 0;
539 CallSiteToCHISetMap::const_iterator it = callsiteToChiSetMap.begin();
540 CallSiteToCHISetMap::const_iterator eit = callsiteToChiSetMap.end();
541 for (; it != eit; it++)
542 {
543 const CHISet & chiSet = it->second;
544 num+= chiSet.size();
545 }
546 return num;
547}

◆ getCallSiteMuNum()

u32_t MemSSA::getCallSiteMuNum ( ) const

Get CallMU numbers

Definition at line 519 of file MemSSA.cpp.

520{
521 u32_t num = 0;
522 CallSiteToMUSetMap::const_iterator it = callsiteToMuSetMap.begin();
523 CallSiteToMUSetMap::const_iterator eit = callsiteToMuSetMap.end();
524 for (; it != eit; it++)
525 {
526 const MUSet & muSet = it->second;
527 num+= muSet.size();
528 }
529 return num;
530}

◆ getCallSiteToChiSetMap()

CallSiteToCHISetMap & SVF::MemSSA::getCallSiteToChiSetMap ( )
inline

Definition at line 427 of file MemSSA.h.

428 {
429 return callsiteToChiSetMap;
430 }

◆ getCallSiteToMuSetMap()

CallSiteToMUSetMap & SVF::MemSSA::getCallSiteToMuSetMap ( )
inline

Definition at line 423 of file MemSSA.h.

424 {
425 return callsiteToMuSetMap;
426 }

◆ getCHISet() [1/2]

CHISet & SVF::MemSSA::getCHISet ( const CallICFGNode cs)
inline

Definition at line 395 of file MemSSA.h.

396 {
397 return callsiteToChiSetMap[cs];
398 }

◆ getCHISet() [2/2]

CHISet & SVF::MemSSA::getCHISet ( const StoreStmt st)
inline

Definition at line 387 of file MemSSA.h.

388 {
389 return store2ChiSetMap[st];
390 }

◆ getFuncEntryChiSet()

CHISet & SVF::MemSSA::getFuncEntryChiSet ( const FunObjVar fun)
inline

Definition at line 371 of file MemSSA.h.

372 {
373 return funToEntryChiSetMap[fun];
374 }

◆ getFunEntryChiNum()

u32_t MemSSA::getFunEntryChiNum ( ) const

Get EntryCHI numbers

Definition at line 485 of file MemSSA.cpp.

486{
487 u32_t num = 0;
488 FunToEntryChiSetMap::const_iterator it = funToEntryChiSetMap.begin();
489 FunToEntryChiSetMap::const_iterator eit = funToEntryChiSetMap.end();
490 for (; it != eit; it++)
491 {
492 const CHISet& chiSet = it->second;
493 num += chiSet.size();
494 }
495 return num;
496}

◆ getFunRetMuNum()

u32_t MemSSA::getFunRetMuNum ( ) const

Get RetMU numbers

Definition at line 502 of file MemSSA.cpp.

503{
504 u32_t num = 0;
505 FunToReturnMuSetMap::const_iterator it = funToReturnMuSetMap.begin();
506 FunToReturnMuSetMap::const_iterator eit = funToReturnMuSetMap.end();
507 for (; it != eit; it++)
508 {
509 const MUSet & muSet = it->second;
510 num+= muSet.size();
511 }
512 return num;
513}

◆ getFunToEntryChiSetMap()

FunToEntryChiSetMap & SVF::MemSSA::getFunToEntryChiSetMap ( )
inline

Definition at line 419 of file MemSSA.h.

420 {
421 return funToEntryChiSetMap;
422 }

◆ getFunToRetMuSetMap()

FunToReturnMuSetMap & SVF::MemSSA::getFunToRetMuSetMap ( )
inline

Definition at line 415 of file MemSSA.h.

416 {
417 return funToReturnMuSetMap;
418 }

◆ getLoadMuNum()

u32_t MemSSA::getLoadMuNum ( ) const

Stat methods.

Get loadMU numbers

Definition at line 451 of file MemSSA.cpp.

452{
453 u32_t num = 0;
454 LoadToMUSetMap::const_iterator it = load2MuSetMap.begin();
455 LoadToMUSetMap::const_iterator eit = load2MuSetMap.end();
456 for (; it != eit; it++)
457 {
458 const MUSet & muSet = it->second;
459 num+= muSet.size();
460 }
461 return num;
462}

◆ getLoadToMUSetMap()

LoadToMUSetMap & SVF::MemSSA::getLoadToMUSetMap ( )
inline

Definition at line 407 of file MemSSA.h.

408 {
409 return load2MuSetMap;
410 }

◆ getMRGenerator()

MRGenerator * SVF::MemSSA::getMRGenerator ( )
inline

Return MRGenerator (non-owning; MemSSA retains ownership)

Definition at line 315 of file MemSSA.h.

316 {
317 return mrGen.get();
318 }

◆ getMUSet() [1/2]

MUSet & SVF::MemSSA::getMUSet ( const CallICFGNode cs)
inline

Definition at line 391 of file MemSSA.h.

392 {
393 return callsiteToMuSetMap[cs];
394 }

◆ getMUSet() [2/2]

MUSet & SVF::MemSSA::getMUSet ( const LoadStmt ld)
inline

Get methods of mu/chi/phi.

Definition at line 383 of file MemSSA.h.

384 {
385 return load2MuSetMap[ld];
386 }

◆ getPAG()

SVFIR * MemSSA::getPAG ( )
inline

Return SVFIR.

Definition at line 66 of file MemSSA.cpp.

67{
68 return pta->getPAG();
69}
SVFIR * getPAG() const

◆ getPHISet()

PHISet & SVF::MemSSA::getPHISet ( const SVFBasicBlock bb)
inline

Definition at line 399 of file MemSSA.h.

400 {
401 return bb2PhiSetMap[bb];
402 }

◆ getPTA()

BVDataPTAImpl * SVF::MemSSA::getPTA ( ) const
inline

Return PTA.

Definition at line 310 of file MemSSA.h.

311 {
312 return pta;
313 }

◆ getReturnMuSet()

MUSet & SVF::MemSSA::getReturnMuSet ( const FunObjVar fun)
inline

Definition at line 375 of file MemSSA.h.

376 {
377 return funToReturnMuSetMap[fun];
378 }

◆ getStoreChiNum()

u32_t MemSSA::getStoreChiNum ( ) const

Get StoreCHI numbers

Definition at line 468 of file MemSSA.cpp.

469{
470 u32_t num = 0;
471 StoreToChiSetMap::const_iterator it = store2ChiSetMap.begin();
472 StoreToChiSetMap::const_iterator eit = store2ChiSetMap.end();
473 for (; it != eit; it++)
474 {
475 const CHISet& chiSet = it->second;
476 num += chiSet.size();
477 }
478 return num;
479}

◆ getStoreToChiSetMap()

StoreToChiSetMap & SVF::MemSSA::getStoreToChiSetMap ( )
inline

Definition at line 411 of file MemSSA.h.

412 {
413 return store2ChiSetMap;
414 }

◆ getTopStackVer()

MRVer * SVF::MemSSA::getTopStackVer ( const MemRegion mr)
inlineprivate

Get the last version of the SSA ver of memory region.

Definition at line 166 of file MemSSA.h.

167 {
168 std::vector<MRVer*> &stack = mr2VerStackMap[mr];
169 assert(!stack.empty() && "stack is empty!!");
170 return stack.back();
171 }

◆ hasCHI() [1/2]

bool SVF::MemSSA::hasCHI ( const CallICFGNode cs) const
inline

Definition at line 354 of file MemSSA.h.

355 {
356 return callsiteToChiSetMap.find(cs)!=callsiteToChiSetMap.end();
357 }

◆ hasCHI() [2/2]

bool SVF::MemSSA::hasCHI ( const PAGEdge inst) const
inline

Definition at line 338 of file MemSSA.h.

339 {
340 if (const StoreStmt* store = SVFUtil::dyn_cast<StoreStmt>(
341 inst))
342 {
343 bool has_store = store2ChiSetMap.count(store) != 0;
344 assert(has_store && "not associated with mem region!");
345 return has_store;
346 }
347 else
348 return false;
349 }

◆ hasFuncEntryChi()

bool SVF::MemSSA::hasFuncEntryChi ( const FunObjVar fun) const
inline

Has function entry chi or return mu.

Definition at line 362 of file MemSSA.h.

363 {
364 return (funToEntryChiSetMap.find(fun) != funToEntryChiSetMap.end());
365 }

◆ hasMU() [1/2]

bool SVF::MemSSA::hasMU ( const CallICFGNode cs) const
inline

Definition at line 350 of file MemSSA.h.

351 {
352 return callsiteToMuSetMap.find(cs)!=callsiteToMuSetMap.end();
353 }

◆ hasMU() [2/2]

bool SVF::MemSSA::hasMU ( const PAGEdge inst) const
inline

Has mu/chi methods.

Definition at line 327 of file MemSSA.h.

328 {
329 if (const LoadStmt* load = SVFUtil::dyn_cast<LoadStmt>(inst))
330 {
331 bool hasMu = load2MuSetMap.count(load) != 0;
332 assert(hasMu && "not associated with mem region!");
333 return hasMu;
334 }
335 else
336 return false;
337 }

◆ hasPHISet()

bool SVF::MemSSA::hasPHISet ( const SVFBasicBlock bb) const
inline

Definition at line 403 of file MemSSA.h.

404 {
405 return bb2PhiSetMap.find(bb)!=bb2PhiSetMap.end();
406 }

◆ hasReturnMu()

bool SVF::MemSSA::hasReturnMu ( const FunObjVar fun) const
inline

Definition at line 366 of file MemSSA.h.

367 {
368 return (funToReturnMuSetMap.find(fun) != funToReturnMuSetMap.end());
369 }

◆ insertPHI()

void MemSSA::insertPHI ( const FunObjVar fun)
protectedvirtual

Insert phi for candidate regions in a function.

Definition at line 195 of file MemSSA.cpp.

196{
197
198 DBOUT(DMSSA,
199 outs() << "\t insert phi for function " << fun.getName() << "\n");
200
202 // record whether a phi of mr has already been inserted into the bb.
204
205 // start inserting phi node
206 for (MRSet::iterator iter = usedRegs.begin(), eiter = usedRegs.end();
207 iter != eiter; ++iter)
208 {
209 const MemRegion* mr = *iter;
210
211 BBList bbs = reg2BBMap[mr];
212 while (!bbs.empty())
213 {
214 const SVFBasicBlock* bb = bbs.back();
215 bbs.pop_back();
216 Map<const SVFBasicBlock*,Set<const SVFBasicBlock*>>::const_iterator it = df.find(bb);
217 if(it == df.end())
218 {
219 writeWrnMsg("bb not in the dominance frontier map??");
220 continue;
221 }
222 const Set<const SVFBasicBlock*>& domSet = it->second;
223 for (const SVFBasicBlock* pbb : domSet)
224 {
225 // if we never insert this phi node before
226 if (0 == bb2MRSetMap[pbb].count(mr))
227 {
228 bb2MRSetMap[pbb].insert(mr);
229 // insert phi node
230 AddMSSAPHI(pbb,mr);
231 // continue to insert phi in its iterative dominate frontiers
232 bbs.push_back(pbb);
233 }
234 }
235 }
236 }
237
238}
int count
Definition cJSON.h:216
const Map< const SVFBasicBlock *, BBSet > & getDomFrontierMap() const
Map< const SVFBasicBlock *, MRSet > BBToMRSetMap
Definition MemSSA.h:94
const ICFGNode * back() const
void writeWrnMsg(const std::string &msg)
Writes a message run through wrnMsg.
Definition SVFUtil.cpp:72

◆ newSSAName()

MRVer * MemSSA::newSSAName ( const MemRegion mr,
MSSADEF def 
)
private

Get a new SSA name of a memory region.

Definition at line 341 of file MemSSA.cpp.

342{
343 assert(0 != mr2CounterMap.count(mr)
344 && "did not find initial version in map? ");
345 assert(0 != mr2VerStackMap.count(mr)
346 && "did not find initial stack in map? ");
347
348 MRVERSION version = mr2CounterMap[mr];
349 mr2CounterMap[mr] = version + 1;
350 auto mrVer = std::make_unique<MRVer>(mr, version, def);
351 auto mrVerPtr = mrVer.get();
352 mr2VerStackMap[mr].push_back(mrVerPtr);
353 usedMRVers.push_back(std::move(mrVer));
354 return mrVerPtr;
355}
std::vector< std::unique_ptr< MRVer > > usedMRVers
Definition MemSSA.h:157
NodeID MRVERSION
Definition MemRegion.h:56

◆ performStat()

void MemSSA::performStat ( )

Perform statistics.

Perform statistics

Definition at line 442 of file MemSSA.cpp.

443{
444 if(pta->printStat())
445 stat->performStat();
446}
virtual void performStat() override
Definition SVFGStat.cpp:74
bool printStat()
Whether print statistics.

◆ RenameChiSet()

void SVF::MemSSA::RenameChiSet ( const CHISet chiSet,
MRVector memRegs 
)
inlineprivate

Rename chi set.

Definition at line 260 of file MemSSA.h.

261 {
262 for (CHISet::const_iterator cit = chiSet.begin(), ecit = chiSet.end();
263 cit != ecit; ++cit)
264 {
265 CHI* chi = (*cit);
266 chi->setOpVer(getTopStackVer(chi->getMR()));
267 chi->setResVer(newSSAName(chi->getMR(),chi));
268 memRegs.push_back(chi->getMR());
269 }
270 }
MSSACHI< Condition > CHI
Definition MemSSA.h:63
MRVer * getTopStackVer(const MemRegion *mr)
Get the last version of the SSA ver of memory region.
Definition MemSSA.h:166

◆ RenameMuSet()

void SVF::MemSSA::RenameMuSet ( const MUSet muSet)
inlineprivate

Rename mus, chis and phis.

Rename mu set

Definition at line 249 of file MemSSA.h.

250 {
251 for (MUSet::const_iterator mit = muSet.begin(), emit = muSet.end();
252 mit != emit; ++mit)
253 {
254 MU* mu = (*mit);
255 mu->setVer(getTopStackVer(mu->getMR()));
256 }
257 }
MSSAMU< Condition > MU
Definition MemSSA.h:59

◆ RenamePhiOps()

void SVF::MemSSA::RenamePhiOps ( const PHISet phiSet,
u32_t  pos,
MRVector  
)
inlineprivate

Rename operands (RHS) of phis.

Definition at line 285 of file MemSSA.h.

286 {
287 for (PHISet::const_iterator iter = phiSet.begin(), eiter = phiSet.end();
288 iter != eiter; ++iter)
289 {
290 PHI* phi = *iter;
291 phi->setOpVer(getTopStackVer(phi->getMR()), pos);
292 }
293 }

◆ RenamePhiRes()

void SVF::MemSSA::RenamePhiRes ( const PHISet phiSet,
MRVector memRegs 
)
inlineprivate

Rename result (LHS) of phis.

Definition at line 273 of file MemSSA.h.

274 {
275 for (PHISet::const_iterator iter = phiSet.begin(), eiter = phiSet.end();
276 iter != eiter; ++iter)
277 {
278 PHI* phi = *iter;
279 phi->setResVer(newSSAName(phi->getMR(),phi));
280 memRegs.push_back(phi->getMR());
281 }
282 }

◆ SSARename()

void MemSSA::SSARename ( const FunObjVar fun)
protectedvirtual

SSA rename for a function.

SSA construction algorithm

Definition at line 243 of file MemSSA.cpp.

244{
245
246 DBOUT(DMSSA,
247 outs() << "\t ssa rename for function " << fun.getName() << "\n");
248
250}
const SVFBasicBlock * getEntryBlock() const
virtual void SSARenameBB(const SVFBasicBlock &bb)
SSA rename for a basic block.
Definition MemSSA.cpp:256

◆ SSARenameBB()

void MemSSA::SSARenameBB ( const SVFBasicBlock bb)
protectedvirtual

SSA rename for a basic block.

Renaming for each memory regions See the renaming algorithm in book Engineering A Compiler (Figure 9.12)

Definition at line 256 of file MemSSA.cpp.

257{
258
259 // record which mem region needs to pop stack
261
262 // rename phi result op
263 // for each r = phi (...)
264 // rewrite r as new name
265 if (hasPHISet(&bb))
267
268
269 // process mu and chi
270 // for each mu(r)
271 // rewrite r with top mrver of stack(r)
272 // for each r = chi(r')
273 // rewrite r' with top mrver of stack(r)
274 // rewrite r with new name
275
276 for (const auto& pNode: bb.getICFGNodeList())
277 {
278 if(mrGen->hasSVFStmtList(pNode))
279 {
280 SVFStmtList& pagEdgeList = mrGen->getSVFStmtsFromInst(pNode);
281 for(SVFStmtList::const_iterator bit = pagEdgeList.begin(), ebit= pagEdgeList.end();
282 bit!=ebit; ++bit)
283 {
284 const PAGEdge* inst = *bit;
285 if (const LoadStmt* load = SVFUtil::dyn_cast<LoadStmt>(inst))
286 RenameMuSet(getMUSet(load));
287
288 else if (const StoreStmt* store = SVFUtil::dyn_cast<StoreStmt>(inst))
290
291 }
292 }
294 {
296 if(mrGen->hasRefMRSet(cs))
298
299 if(mrGen->hasModMRSet(cs))
301 }
302 else if(isRetInstNode(pNode))
303 {
304 const FunObjVar* fun = bb.getParent();
306 }
307 }
308
309
310 // fill phi operands of succ basic blocks
311 for (const SVFBasicBlock* succ : bb.getSuccessors())
312 {
314 if (hasPHISet(succ))
316 }
317
318 // for succ basic block in dominator tree
319 const FunObjVar* fun = bb.getParent();
321 Map<const SVFBasicBlock*,Set<const SVFBasicBlock*>>::const_iterator mapIter = dtBBsMap.find(&bb);
322 if (mapIter != dtBBsMap.end())
323 {
324 const Set<const SVFBasicBlock*>& dtBBs = mapIter->second;
325 for (const SVFBasicBlock* dtbb : dtBBs)
326 {
328 }
329 }
330 // for each r = chi(..), and r = phi(..)
331 // pop ver stack(r)
332 while (!memRegs.empty())
333 {
334 const MemRegion* mr = memRegs.back();
335 memRegs.pop_back();
336 mr2VerStackMap[mr].pop_back();
337 }
338
339}
const Map< const SVFBasicBlock *, BBSet > & getDomTreeMap() const
void RenamePhiOps(const PHISet &phiSet, u32_t pos, MRVector &)
Rename operands (RHS) of phis.
Definition MemSSA.h:285
void RenameMuSet(const MUSet &muSet)
Rename mus, chis and phis.
Definition MemSSA.h:249
bool hasPHISet(const SVFBasicBlock *bb) const
Definition MemSSA.h:403
void RenameChiSet(const CHISet &chiSet, MRVector &memRegs)
Rename chi set.
Definition MemSSA.h:260
void RenamePhiRes(const PHISet &phiSet, MRVector &memRegs)
Rename result (LHS) of phis.
Definition MemSSA.h:273
std::vector< const MemRegion * > MRVector
Definition MemSSA.h:76
const FunObjVar * getParent() const
u32_t getBBPredecessorPos(const SVFBasicBlock *succbb)
bool isRetInstNode(const ICFGNode *node)
Definition SVFUtil.cpp:380

Member Data Documentation

◆ bb2PhiSetMap

BBToPhiSetMap SVF::MemSSA::bb2PhiSetMap
private

Definition at line 138 of file MemSSA.h.

◆ callsiteToChiSetMap

CallSiteToCHISetMap SVF::MemSSA::callsiteToChiSetMap
private

Definition at line 137 of file MemSSA.h.

◆ callsiteToMuSetMap

CallSiteToMUSetMap SVF::MemSSA::callsiteToMuSetMap
private

Definition at line 136 of file MemSSA.h.

◆ funToEntryChiSetMap

FunToEntryChiSetMap SVF::MemSSA::funToEntryChiSetMap
private

Definition at line 140 of file MemSSA.h.

◆ funToReturnMuSetMap

FunToReturnMuSetMap SVF::MemSSA::funToReturnMuSetMap
private

Definition at line 141 of file MemSSA.h.

◆ load2MuSetMap

LoadToMUSetMap SVF::MemSSA::load2MuSetMap
private

Definition at line 134 of file MemSSA.h.

◆ mr2CounterMap

MemRegToCounterMap SVF::MemSSA::mr2CounterMap
private

Definition at line 144 of file MemSSA.h.

◆ mr2VerStackMap

MemRegToVerStackMap SVF::MemSSA::mr2VerStackMap
private

Definition at line 143 of file MemSSA.h.

◆ mrGen

std::unique_ptr<MRGenerator> SVF::MemSSA::mrGen
protected

Definition at line 122 of file MemSSA.h.

◆ pta

BVDataPTAImpl* SVF::MemSSA::pta
protected

Definition at line 121 of file MemSSA.h.

◆ reg2BBMap

MemRegToBBsMap SVF::MemSSA::reg2BBMap
private

Maps memory region to its basic block.

Definition at line 152 of file MemSSA.h.

◆ stat

MemSSAStat* SVF::MemSSA::stat
protected

Definition at line 123 of file MemSSA.h.

◆ store2ChiSetMap

StoreToChiSetMap SVF::MemSSA::store2ChiSetMap
private

Definition at line 135 of file MemSSA.h.

◆ timeOfCreateMUCHI

double MemSSA::timeOfCreateMUCHI = 0
static

Time for generating mu/chi for load/store/calls.

Definition at line 108 of file MemSSA.h.

◆ timeOfGeneratingMemRegions

double MemSSA::timeOfGeneratingMemRegions = 0
static

Statistics.

Time for allocating regions.

Time for allocating regions

Definition at line 107 of file MemSSA.h.

◆ timeOfInsertingPHI

double MemSSA::timeOfInsertingPHI = 0
static

Time for inserting phis.

Definition at line 109 of file MemSSA.h.

◆ timeOfSSARenaming

double MemSSA::timeOfSSARenaming = 0
static

Time for SSA rename.

Definition at line 110 of file MemSSA.h.

◆ usedMRVers

std::vector<std::unique_ptr<MRVer> > SVF::MemSSA::usedMRVers
private

Definition at line 157 of file MemSSA.h.

◆ usedRegs

MRSet SVF::MemSSA::usedRegs
private

The following three set are used for prune SSA phi insertion.

Collects used memory regions

Definition at line 150 of file MemSSA.h.

◆ varKills

MRSet SVF::MemSSA::varKills
private

Collect memory regions whose definition killed.

Definition at line 154 of file MemSSA.h.


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