53 &&
"please specify a pointer analysis");
54 assert(mrGenerator !=
nullptr &&
"builder must supply an MRGenerator");
55 mrGen = std::move(mrGenerator);
60 double mrStart =
stat->getClk(
true);
62 double mrEnd =
stat->getClk(
true);
77 assert(!
isExtCall(&fun) &&
"we do not build memory ssa for external functions");
86 double muchiStart =
stat->getClk(
true);
88 double muchiEnd =
stat->getClk(
true);
92 double phiStart =
stat->getClk(
true);
94 double phiEnd =
stat->getClk(
true);
98 double renameStart =
stat->getClk(
true);
100 double renameEnd =
stat->getClk(
true);
114 outs() <<
"\t creating mu chi for function " << fun.
getName()
134 for (BBList::const_iterator iter = reachableBBs.begin(), eiter = reachableBBs.end();
135 iter != eiter; ++iter)
141 if(
mrGen->hasSVFStmtList(inst))
144 for (SVFStmtList::const_iterator bit = pagEdgeList.begin(),
145 ebit = pagEdgeList.end(); bit != ebit; ++bit)
157 if(
mrGen->hasRefMRSet(cs))
160 if(
mrGen->hasModMRSet(cs))
169 iter != eiter; ++iter)
199 outs() <<
"\t insert phi for function " << fun.
getName() <<
"\n");
207 iter != eiter; ++iter)
219 writeWrnMsg(
"bb not in the dominance frontier map??");
226 if (0 == bb2MRSetMap[pbb].
count(mr))
228 bb2MRSetMap[pbb].insert(mr);
247 outs() <<
"\t ssa rename for function " << fun.
getName() <<
"\n");
278 if(
mrGen->hasSVFStmtList(pNode))
281 for(SVFStmtList::const_iterator bit = pagEdgeList.begin(), ebit= pagEdgeList.end();
296 if(
mrGen->hasRefMRSet(cs))
299 if(
mrGen->hasModMRSet(cs))
322 if (mapIter != dtBBsMap.end())
332 while (!memRegs.empty())
344 &&
"did not find initial version in map? ");
346 &&
"did not find initial stack in map? ");
350 auto mrVer = std::make_unique<MRVer>(mr, version, def);
351 auto mrVerPtr = mrVer.get();
363 for (LoadToMUSetMap::iterator iter =
load2MuSetMap.begin(), eiter =
366 for (MUSet::iterator it = iter->second.begin(), eit =
367 iter->second.end(); it != eit; ++it)
373 for (StoreToChiSetMap::iterator iter =
store2ChiSetMap.begin(), eiter =
376 for (CHISet::iterator it = iter->second.begin(), eit =
377 iter->second.end(); it != eit; ++it)
386 for (MUSet::iterator it = iter->second.begin(), eit =
387 iter->second.end(); it != eit; ++it)
396 for (CHISet::iterator it = iter->second.begin(), eit =
397 iter->second.end(); it != eit; ++it)
406 for (CHISet::iterator it = iter->second.begin(), eit =
407 iter->second.end(); it != eit; ++it)
416 for (MUSet::iterator it = iter->second.begin(), eit =
417 iter->second.end(); it != eit; ++it)
423 for (BBToPhiSetMap::iterator iter =
bb2PhiSetMap.begin(), eiter =
426 for (PHISet::iterator it = iter->second.begin(), eit =
427 iter->second.end(); it != eit; ++it)
456 for (; it != eit; it++)
458 const MUSet & muSet = it->second;
473 for (; it != eit; it++)
475 const CHISet& chiSet = it->second;
476 num += chiSet.size();
490 for (; it != eit; it++)
492 const CHISet& chiSet = it->second;
493 num += chiSet.size();
507 for (; it != eit; it++)
509 const MUSet & muSet = it->second;
524 for (; it != eit; it++)
526 const MUSet & muSet = it->second;
541 for (; it != eit; it++)
543 const CHISet & chiSet = it->second;
556 BBToPhiSetMap::const_iterator it =
bb2PhiSetMap.begin();
558 for (; it != eit; it++)
560 const PHISet & phiSet = it->second;
573 for (
const auto&
item: *svfirCallGraph)
579 Out <<
"==========FUNCTION: " << fun->
getName() <<
"==========\n";
584 for (CHISet::iterator chi_it = entry_chis.begin(); chi_it != entry_chis.end(); chi_it++)
596 for(PHISet::iterator pi = phiSet.begin(), epi = phiSet.end(); pi !=epi; ++pi)
601 bool last_is_chi =
false;
621 Out << inst->toString() <<
"\n";
638 bool dump_preamble =
false;
640 for(SVFStmtList::const_iterator bit = pagEdgeList.begin(), ebit= pagEdgeList.end();
647 for(MUSet::iterator it = muSet.begin(), eit = muSet.end(); it!=eit; ++it)
649 if (!dump_preamble && !last_is_chi)
652 dump_preamble =
true;
659 Out << inst->toString() <<
"\n";
661 bool has_chi =
false;
662 for(SVFStmtList::const_iterator bit = pagEdgeList.begin(), ebit= pagEdgeList.end();
669 for(CHISet::iterator it = chiSet.begin(), eit = chiSet.end(); it!=eit; ++it)
691 for (MUSet::iterator mu_it = return_mus.begin(); mu_it != return_mus.end(); mu_it++)
#define DBOUT(TYPE, X)
LLVM debug macros, define type of your DBUG model of each pass.
BasicBlockGraph::IDToNodeMapTy::const_iterator const_bb_iterator
const Map< const SVFBasicBlock *, BBSet > & getDomFrontierMap() const
const Map< const SVFBasicBlock *, BBSet > & getDomTreeMap() const
const_bb_iterator begin() const
const SVFBasicBlock * getEntryBlock() const
const_bb_iterator end() const
const std::vector< const SVFBasicBlock * > & getReachableBBs() const
void setOpVer(MRVer *v)
Set operand ver.
void setResVer(MRVer *v)
Set result operand ver.
PHISet & getPHISet(const SVFBasicBlock *bb)
MemSSA(BVDataPTAImpl *p, std::unique_ptr< MRGenerator > mrGenerator)
std::vector< const SVFBasicBlock * > BBList
For phi insertion.
void RenamePhiOps(const PHISet &phiSet, u32_t pos, MRVector &)
Rename operands (RHS) of phis.
u32_t getFunEntryChiNum() const
BBToPhiSetMap bb2PhiSetMap
CallSiteToCHISetMap callsiteToChiSetMap
CHISet & getCHISet(const StoreStmt *st)
MemRegToCounterMap mr2CounterMap
void RenameMuSet(const MUSet &muSet)
Rename mus, chis and phis.
virtual void createMUCHI(const FunObjVar &fun)
Create mu chi for candidate regions in a function.
u32_t getCallSiteChiNum() const
static double timeOfGeneratingMemRegions
Statistics.
MRVer * newSSAName(const MemRegion *mr, MSSADEF *def)
Get a new SSA name of a memory region.
void AddStoreCHI(const SVFBasicBlock *bb, const StoreStmt *store, const MRSet &mrSet)
static double timeOfInsertingPHI
Time for inserting phis.
bool hasReturnMu(const FunObjVar *fun) const
void destroy()
Release the memory.
SVFIR * getPAG()
Return SVFIR.
bool hasPHISet(const SVFBasicBlock *bb) const
void AddLoadMU(const SVFBasicBlock *bb, const LoadStmt *load, const MRSet &mrSet)
Add methods for mus/chis/phis.
SVFIR::SVFStmtList SVFStmtList
SVFIR edge list.
static double timeOfCreateMUCHI
Time for generating mu/chi for load/store/calls.
CHISet & getFuncEntryChiSet(const FunObjVar *fun)
FunToEntryChiSetMap funToEntryChiSetMap
virtual void insertPHI(const FunObjVar &fun)
Insert phi for candidate regions in a function.
LoadToMUSetMap load2MuSetMap
void RenameChiSet(const CHISet &chiSet, MRVector &memRegs)
Rename chi set.
void RenamePhiRes(const PHISet &phiSet, MRVector &memRegs)
Rename result (LHS) of phis.
u32_t getFunRetMuNum() const
EntryCHI< Condition > ENTRYCHI
std::vector< std::unique_ptr< MRVer > > usedMRVers
StoreToChiSetMap store2ChiSetMap
void dumpMSSA(OutStream &Out=SVFUtil::outs())
Print Memory SSA.
std::vector< const MemRegion * > MRVector
void performStat()
Perform statistics.
virtual void buildMemSSA(const FunObjVar &fun)
We start from here.
void AddCallSiteMU(const CallICFGNode *cs, const MRSet &mrSet)
bool hasFuncEntryChi(const FunObjVar *fun) const
Has function entry chi or return mu.
static double timeOfSSARenaming
Time for SSA rename.
u32_t getBBPhiNum() const
u32_t getCallSiteMuNum() const
u32_t getStoreChiNum() const
u32_t getLoadMuNum() const
Stat methods.
std::unique_ptr< MRGenerator > mrGen
CallSiteToMUSetMap callsiteToMuSetMap
FunToReturnMuSetMap funToReturnMuSetMap
bool hasCHI(const PAGEdge *inst) const
virtual void SSARename(const FunObjVar &fun)
SSA rename for a function.
MRSet usedRegs
The following three set are used for prune SSA phi insertion.
Map< const SVFBasicBlock *, MRSet > BBToMRSetMap
MUSet & getMUSet(const LoadStmt *ld)
Get methods of mu/chi/phi.
void AddCallSiteCHI(const CallICFGNode *cs, const MRSet &mrSet)
MUSet & getReturnMuSet(const FunObjVar *fun)
MemRegToBBsMap reg2BBMap
Maps memory region to its basic block.
void AddMSSAPHI(const SVFBasicBlock *bb, const MRSet &mrSet)
MemRegToVerStackMap mr2VerStackMap
MRSet varKills
Collect memory regions whose definition killed.
virtual void SSARenameBB(const SVFBasicBlock &bb)
SSA rename for a basic block.
bool hasMU(const PAGEdge *inst) const
Has mu/chi methods.
static const Option< std::string > MSSAFun
const FunObjVar * getParent() const
const std::vector< const ICFGNode * > & getICFGNodeList() const
u32_t getBBPredecessorPos(const SVFBasicBlock *succbb)
const ICFGNode * back() const
std::vector< const SVFBasicBlock * > getSuccessors() const
const CallGraph * getCallGraph()
Get CG.
static SVFIR * getPAG(bool buildFromFile=false)
Singleton design here to make sure we only have one instance during any analysis.
virtual const std::string & getName() const
std::enable_if_t<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type > cast(const Y &Val)
bool isHeapAllocExtCall(const ICFGNode *cs)
bool isNonInstricCallSite(const ICFGNode *inst)
Whether an instruction is a callsite in the application code, excluding llvm intrinsic calls.
bool isExtCall(const FunObjVar *fun)
void writeWrnMsg(const std::string &msg)
Writes a message run through wrnMsg.
bool isRetInstNode(const ICFGNode *node)
std::ostream & outs()
Overwrite llvm::outs().
LLVM_NODISCARD std::enable_if_t<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type > dyn_cast(const Y &Val)
@ Default_PTA
default pta without any analysis
std::unordered_set< Key, Hash, KeyEqual, Allocator > Set
std::unordered_map< Key, Value, Hash, KeyEqual, Allocator > Map