Static Value-Flow Analysis
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 More...
 
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. More...
 
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 SVFFunction *, CHISetFunToEntryChiSetMap
 Map from fun to its entry chi set and return mu set. More...
 
typedef Map< const SVFFunction *, MUSetFunToReturnMuSetMap
 
typedef std::vector< const SVFBasicBlock * > BBList
 For phi insertion. More...
 
typedef Map< const SVFBasicBlock *, MRSetBBToMRSetMap
 
typedef Map< const MemRegion *, BBListMemRegToBBsMap
 
typedef Map< const MemRegion *, std::vector< MRVer * > > MemRegToVerStackMap
 For SSA renaming. More...
 
typedef Map< const MemRegion *, MRVERSIONMemRegToCounterMap
 
typedef SVFIR::SVFStmtList SVFStmtList
 SVFIR edge list. More...
 

Static Public Attributes

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

Protected Member Functions

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

Protected Attributes

BVDataPTAImplpta
 
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. More...
 
MemRegToBBsMap reg2BBMap
 Maps memory region to its basic block. More...
 
MRSet varKills
 Collect memory regions whose definition killed. More...
 
std::vector< std::unique_ptr< MRVer > > usedMRVers
 
void destroy ()
 Release the memory. More...
 
MRVernewSSAName (const MemRegion *mr, MSSADEF *def)
 Get a new SSA name of a memory region. More...
 
MRVergetTopStackVer (const MemRegion *mr)
 Get the last version of the SSA ver of memory region. More...
 
void collectRegUses (const MemRegion *mr)
 Collect region uses and region defs according to mus/chis, in order to insert phis. More...
 
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. More...
 
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. More...
 
void RenameChiSet (const CHISet &chiSet, MRVector &memRegs)
 Rename chi set. More...
 
void RenamePhiRes (const PHISet &phiSet, MRVector &memRegs)
 Rename result (LHS) of phis. More...
 
void RenamePhiOps (const PHISet &phiSet, u32_t pos, MRVector &)
 Rename operands (RHS) of phis. More...
 
 MemSSA (BVDataPTAImpl *p, bool ptrOnlyMSSA)
 Constructor. More...
 
virtual ~MemSSA ()
 Destructor. More...
 
SVFIRgetPAG ()
 Return SVFIR. More...
 
BVDataPTAImplgetPTA () const
 Return PTA. More...
 
MRGeneratorgetMRGenerator ()
 Return MRGenerator. More...
 
virtual void buildMemSSA (const SVFFunction &fun)
 We start from here. More...
 
void performStat ()
 Perform statistics. More...
 
bool hasMU (const PAGEdge *inst) const
 Has mu/chi methods. More...
 
bool hasCHI (const PAGEdge *inst) const
 
bool hasMU (const CallICFGNode *cs) const
 
bool hasCHI (const CallICFGNode *cs) const
 
bool hasFuncEntryChi (const SVFFunction *fun) const
 Has function entry chi or return mu. More...
 
bool hasReturnMu (const SVFFunction *fun) const
 
CHISetgetFuncEntryChiSet (const SVFFunction *fun)
 
MUSetgetReturnMuSet (const SVFFunction *fun)
 
MUSetgetMUSet (const LoadStmt *ld)
 Get methods of mu/chi/phi. More...
 
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. More...
 
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. More...
 

Detailed Description

Definition at line 52 of file MemSSA.h.

Member Typedef Documentation

◆ BBList

typedef std::vector<const SVFBasicBlock*> SVF::MemSSA::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

typedef Map<const MemRegion*, std::vector<MRVer*> > SVF::MemSSA::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

typedef std::vector<const MemRegion*> SVF::MemSSA::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
@ Distinct
Definition: MemSSA.h:115
@ IntraDisjoint
Definition: MemSSA.h:116

Constructor & Destructor Documentation

◆ MemSSA()

MemSSA::MemSSA ( BVDataPTAImpl p,
bool  ptrOnlyMSSA 
)

Constructor.

Constructor

Generate whole program memory regions

Definition at line 46 of file MemSSA.cpp.

47 {
48  pta = p;
50  && "please specify a pointer analysis");
51 
52  if (Options::MemPar() == MemPartition::Distinct)
53  mrGen = new DistinctMRG(pta, ptrOnlyMSSA);
54  else if (Options::MemPar() == MemPartition::IntraDisjoint)
55  mrGen = new IntraDisjointMRG(pta, ptrOnlyMSSA);
56  else if (Options::MemPar() == MemPartition::InterDisjoint)
57  mrGen = new InterDisjointMRG(pta, ptrOnlyMSSA);
58  else
59  assert(false && "unrecognised memory partition strategy");
60 
61 
62  stat = new MemSSAStat(this);
63 
65  double mrStart = stat->getClk(true);
66  mrGen->generateMRs();
67  double mrEnd = stat->getClk(true);
68  timeOfGeneratingMemRegions = (mrEnd - mrStart)/TIMEINTERVAL;
69 }
#define TIMEINTERVAL
Definition: SVFType.h:512
cJSON * p
Definition: cJSON.cpp:2559
virtual void generateMRs()
Start generating memory regions.
Definition: MemRegion.cpp:124
MRGenerator * mrGen
Definition: MemSSA.h:122
static double timeOfGeneratingMemRegions
Statistics.
Definition: MemSSA.h:107
BVDataPTAImpl * pta
Definition: MemSSA.h:121
MemSSAStat * stat
Definition: MemSSA.h:123
static const OptionMap< MemSSA::MemPartition > MemPar
Definition: Options.h:145
@ Default_PTA
default pta without any analysis
PTATY getAnalysisTy() const
Type of pointer analysis.
static double getClk(bool mark=false)
Definition: SVFStat.cpp:47

◆ ~MemSSA()

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

Destructor.

Definition at line 301 of file MemSSA.h.

302  {
303  destroy();
304  }
void destroy()
Release the memory.
Definition: MemSSA.cpp:365

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 SVFFunction 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 79 of file MemSSA.cpp.

80 {
81 
82  assert(!isExtCall(&fun) && "we do not build memory ssa for external functions");
83 
84  DBOUT(DMSSA, outs() << "Building Memory SSA for function " << fun.getName()
85  << " \n");
86 
87  usedRegs.clear();
88  reg2BBMap.clear();
89 
91  double muchiStart = stat->getClk(true);
92  createMUCHI(fun);
93  double muchiEnd = stat->getClk(true);
94  timeOfCreateMUCHI += (muchiEnd - muchiStart)/TIMEINTERVAL;
95 
97  double phiStart = stat->getClk(true);
98  insertPHI(fun);
99  double phiEnd = stat->getClk(true);
100  timeOfInsertingPHI += (phiEnd - phiStart)/TIMEINTERVAL;
101 
103  double renameStart = stat->getClk(true);
104  SSARename(fun);
105  double renameEnd = stat->getClk(true);
106  timeOfSSARenaming += (renameEnd - renameStart)/TIMEINTERVAL;
107 
108 }
#define DBOUT(TYPE, X)
LLVM debug macros, define type of your DBUG model of each pass.
Definition: SVFType.h:484
#define DMSSA
Definition: SVFType.h:501
virtual void SSARename(const SVFFunction &fun)
SSA rename for a function.
Definition: MemSSA.cpp:248
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 createMUCHI(const SVFFunction &fun)
Create mu chi for candidate regions in a function.
Definition: MemSSA.cpp:114
static double timeOfSSARenaming
Time for SSA rename.
Definition: MemSSA.h:110
virtual void insertPHI(const SVFFunction &fun)
Insert phi for candidate regions in a function.
Definition: MemSSA.cpp:200
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
const std::string & getName() const
Definition: SVFValue.h:243
bool isExtCall(const SVFFunction *fun)
Definition: SVFUtil.h:278
std::ostream & outs()
Overwrite llvm::outs()
Definition: SVFUtil.h:50

◆ 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 SVFFunction 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 114 of file MemSSA.cpp.

115 {
116 
117 
118  DBOUT(DMSSA,
119  outs() << "\t creating mu chi for function " << fun.getName()
120  << "\n");
121  // 1. create mu/chi
122  // insert a set of mus for memory regions at each load
123  // inset a set of chis for memory regions at each store
124 
125  // 2. find global names (region name before renaming) of each memory region,
126  // collect used mrs in usedRegs, and collect its def basic block in reg2BBMap
127  // in the form of mu(r) and r = chi (r)
128  // a) mu(r):
129  // if(r \not\in varKills) global = global \cup r
130  // b) r = chi(r):
131  // if(r \not\in varKills) global = global \cup r
132  // varKills = varKills \cup r
133  // block(r) = block(r) \cup bb_{chi}
134 
137  BBList reachableBBs = fun.getReachableBBs();
138 
139  for (BBList::const_iterator iter = reachableBBs.begin(), eiter = reachableBBs.end();
140  iter != eiter; ++iter)
141  {
142  const SVFBasicBlock* bb = *iter;
143  varKills.clear();
144  for (const auto& inst: bb->getICFGNodeList())
145  {
146  if(mrGen->hasSVFStmtList(inst))
147  {
148  SVFStmtList& pagEdgeList = mrGen->getPAGEdgesFromInst(inst);
149  for (SVFStmtList::const_iterator bit = pagEdgeList.begin(),
150  ebit = pagEdgeList.end(); bit != ebit; ++bit)
151  {
152  const PAGEdge* inst = *bit;
153  if (const LoadStmt* load = SVFUtil::dyn_cast<LoadStmt>(inst))
154  AddLoadMU(bb, load, mrGen->getLoadMRSet(load));
155  else if (const StoreStmt* store = SVFUtil::dyn_cast<StoreStmt>(inst))
156  AddStoreCHI(bb, store, mrGen->getStoreMRSet(store));
157  }
158  }
159  if (isNonInstricCallSite(inst))
160  {
161  const CallICFGNode* cs = cast<CallICFGNode>(inst);
162  if(mrGen->hasRefMRSet(cs))
164 
165  if(mrGen->hasModMRSet(cs))
167  }
168  }
169  }
170 
171  // create entry chi for this function including all memory regions
172  // initialize them with version 0 and 1 r_1 = chi (r_0)
173  for (MRSet::iterator iter = usedRegs.begin(), eiter = usedRegs.end();
174  iter != eiter; ++iter)
175  {
176  const MemRegion* mr = *iter;
177  // initialize mem region version and stack for renaming phase
178  mr2CounterMap[mr] = 0;
179  mr2VerStackMap[mr].clear();
180  ENTRYCHI* chi = new ENTRYCHI(&fun, mr);
181  chi->setOpVer(newSSAName(mr,chi));
182  chi->setResVer(newSSAName(mr,chi));
183  funToEntryChiSetMap[&fun].insert(chi);
184 
187  if(fun.hasReturn())
188  {
189  RETMU* mu = new RETMU(&fun, mr);
190  funToReturnMuSetMap[&fun].insert(mu);
191  }
192 
193  }
194 
195 }
MRSet & getLoadMRSet(const LoadStmt *load)
Definition: MemRegion.h:447
SVFStmtList & getPAGEdgesFromInst(const ICFGNode *node)
Given an instruction, get all its the PAGEdge (statement) in sequence.
Definition: MemRegion.cpp:160
MRSet & getStoreMRSet(const StoreStmt *store)
Definition: MemRegion.h:451
MRSet & getCallSiteModMRSet(const CallICFGNode *cs)
Definition: MemRegion.h:467
bool hasModMRSet(const CallICFGNode *cs)
Definition: MemRegion.h:459
bool hasSVFStmtList(const ICFGNode *icfgNode)
Whether this instruction has SVFIR Edge.
Definition: MemRegion.cpp:150
MRSet & getCallSiteRefMRSet(const CallICFGNode *cs)
Definition: MemRegion.h:463
bool hasRefMRSet(const CallICFGNode *cs)
Definition: MemRegion.h:455
Memory Region class.
Definition: MemRegion.h:56
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:346
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
const std::vector< const ICFGNode * > & getICFGNodeList() const
Definition: SVFValue.h:569
bool hasReturn() const
Definition: SVFValue.h:460
const std::vector< const SVFBasicBlock * > & getReachableBBs() const
Definition: SVFValue.h:450
bool isNonInstricCallSite(const Instruction *inst)
Whether an instruction is a callsite in the application code, excluding llvm intrinsic calls.
Definition: LLVMUtil.cpp:649

◆ destroy()

void MemSSA::destroy ( )
private

Release the memory.

Clean up memory

Definition at line 365 of file MemSSA.cpp.

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

◆ dumpMSSA()

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

Print Memory SSA.

Print SSA

Definition at line 575 of file MemSSA.cpp.

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

◆ getBBPhiNum()

u32_t MemSSA::getBBPhiNum ( ) const

Get PHI numbers

Definition at line 559 of file MemSSA.cpp.

560 {
561  u32_t num = 0;
562  BBToPhiSetMap::const_iterator it = bb2PhiSetMap.begin();
563  BBToPhiSetMap::const_iterator eit = bb2PhiSetMap.end();
564  for (; it != eit; it++)
565  {
566  const PHISet & phiSet = it->second;
567  num+= phiSet.size();
568  }
569  return num;
570 }
unsigned u32_t
Definition: CommandLine.h:18

◆ getBBToPhiSetMap()

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

Definition at line 429 of file MemSSA.h.

430  {
431  return bb2PhiSetMap;
432  }

◆ getCallSiteChiNum()

u32_t MemSSA::getCallSiteChiNum ( ) const

Get CallCHI numbers

Definition at line 542 of file MemSSA.cpp.

543 {
544  u32_t num = 0;
545  CallSiteToCHISetMap::const_iterator it = callsiteToChiSetMap.begin();
546  CallSiteToCHISetMap::const_iterator eit = callsiteToChiSetMap.end();
547  for (; it != eit; it++)
548  {
549  const CHISet & chiSet = it->second;
550  num+= chiSet.size();
551  }
552  return num;
553 }

◆ getCallSiteMuNum()

u32_t MemSSA::getCallSiteMuNum ( ) const

Get CallMU numbers

Definition at line 525 of file MemSSA.cpp.

526 {
527  u32_t num = 0;
528  CallSiteToMUSetMap::const_iterator it = callsiteToMuSetMap.begin();
529  CallSiteToMUSetMap::const_iterator eit = callsiteToMuSetMap.end();
530  for (; it != eit; it++)
531  {
532  const MUSet & muSet = it->second;
533  num+= muSet.size();
534  }
535  return num;
536 }

◆ getCallSiteToChiSetMap()

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

Definition at line 425 of file MemSSA.h.

426  {
427  return callsiteToChiSetMap;
428  }

◆ getCallSiteToMuSetMap()

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

Definition at line 421 of file MemSSA.h.

422  {
423  return callsiteToMuSetMap;
424  }

◆ getCHISet() [1/2]

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

Definition at line 393 of file MemSSA.h.

394  {
395  return callsiteToChiSetMap[cs];
396  }

◆ getCHISet() [2/2]

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

Definition at line 385 of file MemSSA.h.

386  {
387  return store2ChiSetMap[st];
388  }

◆ getFuncEntryChiSet()

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

Definition at line 369 of file MemSSA.h.

370  {
371  return funToEntryChiSetMap[fun];
372  }

◆ getFunEntryChiNum()

u32_t MemSSA::getFunEntryChiNum ( ) const

Get EntryCHI numbers

Definition at line 491 of file MemSSA.cpp.

492 {
493  u32_t num = 0;
494  FunToEntryChiSetMap::const_iterator it = funToEntryChiSetMap.begin();
495  FunToEntryChiSetMap::const_iterator eit = funToEntryChiSetMap.end();
496  for (; it != eit; it++)
497  {
498  const CHISet& chiSet = it->second;
499  num += chiSet.size();
500  }
501  return num;
502 }

◆ getFunRetMuNum()

u32_t MemSSA::getFunRetMuNum ( ) const

Get RetMU numbers

Definition at line 508 of file MemSSA.cpp.

509 {
510  u32_t num = 0;
511  FunToReturnMuSetMap::const_iterator it = funToReturnMuSetMap.begin();
512  FunToReturnMuSetMap::const_iterator eit = funToReturnMuSetMap.end();
513  for (; it != eit; it++)
514  {
515  const MUSet & muSet = it->second;
516  num+= muSet.size();
517  }
518  return num;
519 }

◆ getFunToEntryChiSetMap()

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

Definition at line 417 of file MemSSA.h.

418  {
419  return funToEntryChiSetMap;
420  }

◆ getFunToRetMuSetMap()

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

Definition at line 413 of file MemSSA.h.

414  {
415  return funToReturnMuSetMap;
416  }

◆ getLoadMuNum()

u32_t MemSSA::getLoadMuNum ( ) const

Stat methods.

Get loadMU numbers

Definition at line 457 of file MemSSA.cpp.

458 {
459  u32_t num = 0;
460  LoadToMUSetMap::const_iterator it = load2MuSetMap.begin();
461  LoadToMUSetMap::const_iterator eit = load2MuSetMap.end();
462  for (; it != eit; it++)
463  {
464  const MUSet & muSet = it->second;
465  num+= muSet.size();
466  }
467  return num;
468 }

◆ getLoadToMUSetMap()

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

Definition at line 405 of file MemSSA.h.

406  {
407  return load2MuSetMap;
408  }

◆ getMRGenerator()

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

Return MRGenerator.

Definition at line 313 of file MemSSA.h.

314  {
315  return mrGen;
316  }

◆ getMUSet() [1/2]

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

Definition at line 389 of file MemSSA.h.

390  {
391  return callsiteToMuSetMap[cs];
392  }

◆ getMUSet() [2/2]

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

Get methods of mu/chi/phi.

Definition at line 381 of file MemSSA.h.

382  {
383  return load2MuSetMap[ld];
384  }

◆ getPAG()

SVFIR * MemSSA::getPAG ( )
inline

Return SVFIR.

Definition at line 71 of file MemSSA.cpp.

72 {
73  return pta->getPAG();
74 }
SVFIR * getPAG() const

◆ getPHISet()

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

Definition at line 397 of file MemSSA.h.

398  {
399  return bb2PhiSetMap[bb];
400  }

◆ getPTA()

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

Return PTA.

Definition at line 308 of file MemSSA.h.

309  {
310  return pta;
311  }

◆ getReturnMuSet()

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

Definition at line 373 of file MemSSA.h.

374  {
375  return funToReturnMuSetMap[fun];
376  }

◆ getStoreChiNum()

u32_t MemSSA::getStoreChiNum ( ) const

Get StoreCHI numbers

Definition at line 474 of file MemSSA.cpp.

475 {
476  u32_t num = 0;
477  StoreToChiSetMap::const_iterator it = store2ChiSetMap.begin();
478  StoreToChiSetMap::const_iterator eit = store2ChiSetMap.end();
479  for (; it != eit; it++)
480  {
481  const CHISet& chiSet = it->second;
482  num += chiSet.size();
483  }
484  return num;
485 }

◆ getStoreToChiSetMap()

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

Definition at line 409 of file MemSSA.h.

410  {
411  return store2ChiSetMap;
412  }

◆ 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 352 of file MemSSA.h.

353  {
354  return callsiteToChiSetMap.find(cs)!=callsiteToChiSetMap.end();
355  }

◆ hasCHI() [2/2]

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

Definition at line 336 of file MemSSA.h.

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

◆ hasFuncEntryChi()

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

Has function entry chi or return mu.

Definition at line 360 of file MemSSA.h.

361  {
362  return (funToEntryChiSetMap.find(fun) != funToEntryChiSetMap.end());
363  }

◆ hasMU() [1/2]

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

Definition at line 348 of file MemSSA.h.

349  {
350  return callsiteToMuSetMap.find(cs)!=callsiteToMuSetMap.end();
351  }

◆ hasMU() [2/2]

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

Has mu/chi methods.

Definition at line 325 of file MemSSA.h.

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

◆ hasPHISet()

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

Definition at line 401 of file MemSSA.h.

402  {
403  return bb2PhiSetMap.find(bb)!=bb2PhiSetMap.end();
404  }

◆ hasReturnMu()

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

Definition at line 364 of file MemSSA.h.

365  {
366  return (funToReturnMuSetMap.find(fun) != funToReturnMuSetMap.end());
367  }

◆ insertPHI()

void MemSSA::insertPHI ( const SVFFunction fun)
protectedvirtual

Insert phi for candidate regions in a function.

Definition at line 200 of file MemSSA.cpp.

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

◆ newSSAName()

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

Get a new SSA name of a memory region.

Definition at line 346 of file MemSSA.cpp.

347 {
348  assert(0 != mr2CounterMap.count(mr)
349  && "did not find initial version in map? ");
350  assert(0 != mr2VerStackMap.count(mr)
351  && "did not find initial stack in map? ");
352 
353  MRVERSION version = mr2CounterMap[mr];
354  mr2CounterMap[mr] = version + 1;
355  auto mrVer = std::make_unique<MRVer>(mr, version, def);
356  auto mrVerPtr = mrVer.get();
357  mr2VerStackMap[mr].push_back(mrVerPtr);
358  usedMRVers.push_back(std::move(mrVer));
359  return mrVerPtr;
360 }
std::vector< std::unique_ptr< MRVer > > usedMRVers
Definition: MemSSA.h:157
constexpr std::remove_reference< T >::type && move(T &&t) noexcept
Definition: SVFUtil.h:447
NodeID MRVERSION
Definition: MemRegion.h:52

◆ performStat()

void MemSSA::performStat ( )

Perform statistics.

Perform statistics

Definition at line 448 of file MemSSA.cpp.

449 {
450  if(pta->printStat())
451  stat->performStat();
452 }
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 SVFFunction fun)
protectedvirtual

SSA rename for a function.

SSA construction algorithm

Definition at line 248 of file MemSSA.cpp.

249 {
250 
251  DBOUT(DMSSA,
252  outs() << "\t ssa rename for function " << fun.getName() << "\n");
253 
254  SSARenameBB(*fun.getEntryBlock());
255 }
virtual void SSARenameBB(const SVFBasicBlock &bb)
SSA rename for a basic block.
Definition: MemSSA.cpp:261
const SVFBasicBlock * getEntryBlock() const
Definition: SVFValue.h:409

◆ 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 261 of file MemSSA.cpp.

262 {
263 
264  // record which mem region needs to pop stack
265  MRVector memRegs;
266 
267  // rename phi result op
268  // for each r = phi (...)
269  // rewrite r as new name
270  if (hasPHISet(&bb))
271  RenamePhiRes(getPHISet(&bb),memRegs);
272 
273 
274  // process mu and chi
275  // for each mu(r)
276  // rewrite r with top mrver of stack(r)
277  // for each r = chi(r')
278  // rewrite r' with top mrver of stack(r)
279  // rewrite r with new name
280 
281  for (const auto& pNode: bb.getICFGNodeList())
282  {
283  if(mrGen->hasSVFStmtList(pNode))
284  {
285  SVFStmtList& pagEdgeList = mrGen->getPAGEdgesFromInst(pNode);
286  for(SVFStmtList::const_iterator bit = pagEdgeList.begin(), ebit= pagEdgeList.end();
287  bit!=ebit; ++bit)
288  {
289  const PAGEdge* inst = *bit;
290  if (const LoadStmt* load = SVFUtil::dyn_cast<LoadStmt>(inst))
291  RenameMuSet(getMUSet(load));
292 
293  else if (const StoreStmt* store = SVFUtil::dyn_cast<StoreStmt>(inst))
294  RenameChiSet(getCHISet(store),memRegs);
295 
296  }
297  }
298  if (isNonInstricCallSite(pNode))
299  {
300  const CallICFGNode* cs = cast<CallICFGNode>(pNode);
301  if(mrGen->hasRefMRSet(cs))
302  RenameMuSet(getMUSet(cs));
303 
304  if(mrGen->hasModMRSet(cs))
305  RenameChiSet(getCHISet(cs),memRegs);
306  }
307  else if(isRetInstNode(pNode))
308  {
309  const SVFFunction* fun = bb.getParent();
311  }
312  }
313 
314 
315  // fill phi operands of succ basic blocks
316  for (const SVFBasicBlock* succ : bb.getSuccessors())
317  {
318  u32_t pos = bb.getBBPredecessorPos(succ);
319  if (hasPHISet(succ))
320  RenamePhiOps(getPHISet(succ),pos,memRegs);
321  }
322 
323  // for succ basic block in dominator tree
324  const SVFFunction* fun = bb.getParent();
326  Map<const SVFBasicBlock*,Set<const SVFBasicBlock*>>::const_iterator mapIter = dtBBsMap.find(&bb);
327  if (mapIter != dtBBsMap.end())
328  {
329  const Set<const SVFBasicBlock*>& dtBBs = mapIter->second;
330  for (const SVFBasicBlock* dtbb : dtBBs)
331  {
332  SSARenameBB(*dtbb);
333  }
334  }
335  // for each r = chi(..), and r = phi(..)
336  // pop ver stack(r)
337  while (!memRegs.empty())
338  {
339  const MemRegion* mr = memRegs.back();
340  memRegs.pop_back();
341  mr2VerStackMap[mr].pop_back();
342  }
343 
344 }
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:401
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
u32_t getBBPredecessorPos(const SVFBasicBlock *succbb)
Definition: SVFValue.cpp:241
const std::vector< const SVFBasicBlock * > & getSuccessors() const
Definition: SVFValue.h:606
const SVFFunction * getParent() const
Definition: SVFValue.h:584
const Map< const SVFBasicBlock *, BBSet > & getDomTreeMap() const
Definition: SVFValue.h:490
bool isRetInstNode(const ICFGNode *node)
Definition: SVFUtil.cpp:388

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

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: