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

#include <MemRegion.h>

Inheritance diagram for SVF::MRGenerator:
SVF::DistinctMRG SVF::IntraDisjointMRG SVF::InterDisjointMRG

Public Types

typedef FIFOWorkList< NodeIDWorkList
 
typedef OrderedSet< const MemRegion *, MemRegion::equalMemRegionMRSet
 Get typedef from Pointer Analysis.
 
typedef Map< const PAGEdge *, const FunObjVar * > PAGEdgeToFunMap
 
typedef OrderedSet< NodeBS, SVFUtil::equalNodeBSPointsToList
 
typedef Map< const FunObjVar *, NodeBSFunToPointsToMap
 
typedef Map< const FunObjVar *, PointsToListFunToPointsTosMap
 
typedef OrderedMap< NodeBS, NodeBS, SVFUtil::equalNodeBSPtsToRepPtsSetMap
 
typedef Map< const FunObjVar *, MRSetFunToMRsMap
 Map a function to its region set.
 
typedef Map< const LoadStmt *, MRSetLoadsToMRsMap
 
typedef Map< const StoreStmt *, MRSetStoresToMRsMap
 
typedef Map< const CallICFGNode *, MRSetCallSiteToMRsMap
 
typedef Map< const LoadStmt *, NodeBSLoadsToPointsToMap
 Map loads/stores/callsites to their cpts set.
 
typedef Map< const StoreStmt *, NodeBSStoresToPointsToMap
 
typedef Map< const CallICFGNode *, NodeBSCallSiteToPointsToMap
 
typedef Map< const FunObjVar *, NodeBSFunToNodeBSMap
 Maps Mod-Ref analysis.
 
typedef Map< const CallICFGNode *, NodeBSCallSiteToNodeBSMap
 Map a callsite to its indirect refs/mods of memory objects.
 
typedef Map< NodeID, NodeBSNodeToPTSSMap
 
typedef SVFIR::SVFStmtList SVFStmtList
 SVFIR edge list.
 
typedef SCCDetection< CallGraph * > SCC
 Call Graph SCC.
 

Public Member Functions

MRSetgetMRSet ()
 
const NodeBSgetRepPointsTo (const NodeBS &cpts) const
 Get superset cpts set.
 
const MemRegiongetMR (const NodeBS &cpts) const
 Get a memory region according to cpts.
 
u32_t getMRNum () const
 
virtual ~MRGenerator ()
 Destructor.
 
virtual void generateMRs ()
 Start generating memory regions.
 
const FunObjVargetFunction (const PAGEdge *pagEdge) const
 Get the function which SVFIR Edge located.
 
MRSetgetFunMRSet (const FunObjVar *fun)
 Get Memory Region set.
 
MRSetgetLoadMRSet (const LoadStmt *load)
 
MRSetgetStoreMRSet (const StoreStmt *store)
 
bool hasRefMRSet (const CallICFGNode *cs)
 
bool hasModMRSet (const CallICFGNode *cs)
 
MRSetgetCallSiteRefMRSet (const CallICFGNode *cs)
 
MRSetgetCallSiteModMRSet (const CallICFGNode *cs)
 
bool hasSVFStmtList (const ICFGNode *icfgNode)
 Whether this instruction has SVFIR Edge.
 
SVFStmtListgetSVFStmtsFromInst (const ICFGNode *node)
 Given an instruction, get all its the PAGEdge (statement) in sequence.
 
NodeBS getModInfoForCall (const CallICFGNode *cs)
 getModRefInfo APIs
 
NodeBS getRefInfoForCall (const CallICFGNode *cs)
 
ModRefInfo getModRefInfo (const CallICFGNode *cs)
 
ModRefInfo getModRefInfo (const CallICFGNode *cs, const SVFVar *V)
 
ModRefInfo getModRefInfo (const CallICFGNode *cs1, const CallICFGNode *cs2)
 

Protected Member Functions

 MRGenerator (BVDataPTAImpl *p, bool ptrOnly)
 
void createMR (const FunObjVar *fun, const NodeBS &cpts)
 Generate a memory region and put in into functions which use it.
 
void collectGlobals ()
 Collect all global variables for later escape analysis.
 
virtual void collectModRefForLoadStore ()
 Generate regions for loads/stores.
 
virtual void collectModRefForCall ()
 Generate regions for calls/rets.
 
virtual void partitionMRs ()
 Partition regions.
 
virtual void updateAliasMRs ()
 Update aliased regions for loads/stores/callsites.
 
virtual void sortPointsTo (const NodeBS &cpts)
 Given a condition pts, insert into cptsToRepCPtsMap for region generation.
 
virtual bool isAliasedMR (const NodeBS &cpts, const MemRegion *mr)
 Whether a region is aliased with a conditional points-to.
 
virtual void getAliasMemRegions (MRSet &aliasMRs, const NodeBS &cpts, const FunObjVar *fun)
 Get all aliased mem regions from function fun according to cpts.
 
virtual void getMRsForLoad (MRSet &aliasMRs, const NodeBS &cpts, const FunObjVar *)
 Get memory regions for a load statement according to cpts.
 
virtual void getMRsForCallSiteRef (MRSet &aliasMRs, const NodeBS &cpts, const FunObjVar *)
 Get memory regions for call site ref according to cpts.
 
virtual void modRefAnalysis (CallGraphNode *callGraphNode, WorkList &worklist)
 Mod-Ref analysis for callsite invoking this callGraphNode.
 
virtual bool handleCallsiteModRef (NodeBS &mod, NodeBS &ref, const CallICFGNode *cs, const FunObjVar *fun)
 Get Mod-Ref of a callee function.
 
void addCPtsToStore (NodeBS &cpts, const StoreStmt *st, const FunObjVar *fun)
 Add cpts to store/load.
 
void addCPtsToLoad (NodeBS &cpts, const LoadStmt *ld, const FunObjVar *fun)
 
void addCPtsToCallSiteRefs (NodeBS &cpts, const CallICFGNode *cs)
 
void addCPtsToCallSiteMods (NodeBS &cpts, const CallICFGNode *cs)
 
bool hasCPtsList (const FunObjVar *fun) const
 
PointsToListgetPointsToList (const FunObjVar *fun)
 
FunToPointsTosMapgetFunToPointsToList ()
 
void addRefSideEffectOfFunction (const FunObjVar *fun, const NodeBS &refs)
 Add/Get methods for side-effect of functions and callsites.
 
void addModSideEffectOfFunction (const FunObjVar *fun, const NodeBS &mods)
 Add indirect def an memory object in the function.
 
bool addRefSideEffectOfCallSite (const CallICFGNode *cs, const NodeBS &refs)
 Add indirect uses an memory object in the function.
 
bool addModSideEffectOfCallSite (const CallICFGNode *cs, const NodeBS &mods)
 Add indirect def an memory object in the function.
 
const NodeBSgetRefSideEffectOfFunction (const FunObjVar *fun)
 Get indirect refs of a function.
 
const NodeBSgetModSideEffectOfFunction (const FunObjVar *fun)
 Get indirect mods of a function.
 
const NodeBSgetRefSideEffectOfCallSite (const CallICFGNode *cs)
 Get indirect refs of a callsite.
 
const NodeBSgetModSideEffectOfCallSite (const CallICFGNode *cs)
 Get indirect mods of a callsite.
 
bool hasRefSideEffectOfCallSite (const CallICFGNode *cs)
 Has indirect refs of a callsite.
 
bool hasModSideEffectOfCallSite (const CallICFGNode *cs)
 Has indirect mods of a callsite.
 

Protected Attributes

MRSet memRegSet
 A set of All memory regions.
 
PtsToRepPtsSetMap cptsToRepCPtsMap
 Map a condition pts to its rep conditional pts (super set points-to)
 

Private Member Functions

void destroy ()
 Clean up memory.
 
void collectCallSitePts (const CallICFGNode *cs)
 
NodeBSCollectPtsChain (NodeID id)
 
NodeBSgetCallSiteArgsPts (const CallICFGNode *cs)
 Return the pts chain of all callsite arguments.
 
NodeBSgetCallSiteRetPts (const CallICFGNode *cs)
 Return the pts chain of the return parameter of the callsite.
 
bool isNonLocalObject (NodeID id, const FunObjVar *curFun) const
 
void getEscapObjviaGlobals (NodeBS &globs, const NodeBS &pts)
 Get all the objects in callee's modref escaped via global objects (the chain pts of globals)
 

Private Attributes

BVDataPTAImplpta
 
SCCcallGraphSCC
 
CallGraphcallGraph
 
bool ptrOnlyMSSA
 
FunToMRsMap funToMRsMap
 Map a function to all its memory regions.
 
LoadsToMRsMap loadsToMRsMap
 Map a load SVFIR Edge to its memory regions sets in order for inserting mus in Memory SSA.
 
StoresToMRsMap storesToMRsMap
 Map a store SVFIR Edge to its memory regions sets in order for inserting chis in Memory SSA.
 
CallSiteToMRsMap callsiteToRefMRsMap
 Map a callsite to its refs regions.
 
CallSiteToMRsMap callsiteToModMRsMap
 Map a callsite to its mods regions.
 
LoadsToPointsToMap loadsToPointsToMap
 Map a load SVFIR Edge to its CPts set map.
 
StoresToPointsToMap storesToPointsToMap
 Map a store SVFIR Edge to its CPts set map.
 
CallSiteToPointsToMap callsiteToRefPointsToMap
 Map a callsite to it refs cpts set.
 
CallSiteToPointsToMap callsiteToModPointsToMap
 Map a callsite to it mods cpts set.
 
FunToPointsTosMap funToPointsToMap
 Map a function to all of its conditional points-to sets.
 
PAGEdgeToFunMap pagEdgeToFunMap
 Map a PAGEdge to its fun.
 
FunToPointsToMap funToRefsMap
 Map a function to its indirect uses of memory objects.
 
FunToPointsToMap funToModsMap
 Map a function to its indirect defs of memory objects.
 
CallSiteToPointsToMap csToRefsMap
 Map a callsite to its indirect uses of memory objects.
 
CallSiteToPointsToMap csToModsMap
 Map a callsite to its indirect defs of memory objects.
 
CallSiteToPointsToMap csToCallSiteArgsPtsMap
 Map a callsite to all its object might pass into its callees.
 
CallSiteToPointsToMap csToCallSiteRetPtsMap
 Map a callsite to all its object might return from its callees.
 
NodeToPTSSMap cachedPtsChainMap
 Map a pointer to its cached points-to chain;.
 
NodeBS allGlobals
 All global variable SVFIR node ids.
 

Detailed Description

Memory Region Partitioning

Definition at line 135 of file MemRegion.h.

Member Typedef Documentation

◆ CallSiteToMRsMap

Definition at line 159 of file MemRegion.h.

◆ CallSiteToNodeBSMap

Map a callsite to its indirect refs/mods of memory objects.

Definition at line 174 of file MemRegion.h.

◆ CallSiteToPointsToMap

Definition at line 166 of file MemRegion.h.

◆ FunToMRsMap

Map a function to its region set.

Definition at line 153 of file MemRegion.h.

◆ FunToNodeBSMap

Maps Mod-Ref analysis.

Map a function to its indirect refs/mods of memory objects

Definition at line 172 of file MemRegion.h.

◆ FunToPointsToMap

Definition at line 148 of file MemRegion.h.

◆ FunToPointsTosMap

Definition at line 149 of file MemRegion.h.

◆ LoadsToMRsMap

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

Definition at line 157 of file MemRegion.h.

◆ LoadsToPointsToMap

Map loads/stores/callsites to their cpts set.

Definition at line 164 of file MemRegion.h.

◆ MRSet

Get typedef from Pointer Analysis.

Define mem region set

Definition at line 145 of file MemRegion.h.

◆ NodeToPTSSMap

Definition at line 177 of file MemRegion.h.

◆ PAGEdgeToFunMap

Definition at line 146 of file MemRegion.h.

◆ PointsToList

Definition at line 147 of file MemRegion.h.

◆ PtsToRepPtsSetMap

Definition at line 150 of file MemRegion.h.

◆ SCC

Call Graph SCC.

Definition at line 182 of file MemRegion.h.

◆ StoresToMRsMap

Definition at line 158 of file MemRegion.h.

◆ StoresToPointsToMap

Definition at line 165 of file MemRegion.h.

◆ SVFStmtList

SVFIR edge list.

Definition at line 180 of file MemRegion.h.

◆ WorkList

Definition at line 139 of file MemRegion.h.

Constructor & Destructor Documentation

◆ MRGenerator()

MRGenerator::MRGenerator ( BVDataPTAImpl p,
bool  ptrOnly 
)
protected

Definition at line 42 of file MemRegion.cpp.

42 :
44{
47}
cJSON * p
Definition cJSON.cpp:2559
CallGraph * callGraph
Definition MemRegion.h:203
SCCDetection< CallGraph * > SCC
Call Graph SCC.
Definition MemRegion.h:182
BVDataPTAImpl * pta
Definition MemRegion.h:201
CallGraph * getCallGraph() const
Return call graph.
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:76

◆ ~MRGenerator()

virtual SVF::MRGenerator::~MRGenerator ( )
inlinevirtual

Destructor.

Definition at line 428 of file MemRegion.h.

429 {
430 destroy();
431 }
void destroy()
Clean up memory.
Definition MemRegion.cpp:52

Member Function Documentation

◆ addCPtsToCallSiteMods()

void SVF::MRGenerator::addCPtsToCallSiteMods ( NodeBS cpts,
const CallICFGNode cs 
)
inlineprotected

Definition at line 360 of file MemRegion.h.

361 {
362 callsiteToModPointsToMap[cs] |= cpts;
363 funToPointsToMap[cs->getCaller()].insert(cpts);
364 }
FunToPointsTosMap funToPointsToMap
Map a function to all of its conditional points-to sets.
Definition MemRegion.h:226
CallSiteToPointsToMap callsiteToModPointsToMap
Map a callsite to it mods cpts set.
Definition MemRegion.h:223

◆ addCPtsToCallSiteRefs()

void SVF::MRGenerator::addCPtsToCallSiteRefs ( NodeBS cpts,
const CallICFGNode cs 
)
inlineprotected

Definition at line 355 of file MemRegion.h.

356 {
357 callsiteToRefPointsToMap[cs] |= cpts;
358 funToPointsToMap[cs->getCaller()].insert(cpts);
359 }
CallSiteToPointsToMap callsiteToRefPointsToMap
Map a callsite to it refs cpts set.
Definition MemRegion.h:221

◆ addCPtsToLoad()

void SVF::MRGenerator::addCPtsToLoad ( NodeBS cpts,
const LoadStmt ld,
const FunObjVar fun 
)
inlineprotected

Definition at line 349 of file MemRegion.h.

350 {
351 loadsToPointsToMap[ld] = cpts;
352 funToPointsToMap[fun].insert(cpts);
354 }
void addRefSideEffectOfFunction(const FunObjVar *fun, const NodeBS &refs)
Add/Get methods for side-effect of functions and callsites.
LoadsToPointsToMap loadsToPointsToMap
Map a load SVFIR Edge to its CPts set map.
Definition MemRegion.h:217

◆ addCPtsToStore()

void SVF::MRGenerator::addCPtsToStore ( NodeBS cpts,
const StoreStmt st,
const FunObjVar fun 
)
inlineprotected

Add cpts to store/load.

Definition at line 343 of file MemRegion.h.

344 {
345 storesToPointsToMap[st] = cpts;
346 funToPointsToMap[fun].insert(cpts);
348 }
void addModSideEffectOfFunction(const FunObjVar *fun, const NodeBS &mods)
Add indirect def an memory object in the function.
StoresToPointsToMap storesToPointsToMap
Map a store SVFIR Edge to its CPts set map.
Definition MemRegion.h:219

◆ addModSideEffectOfCallSite()

bool MRGenerator::addModSideEffectOfCallSite ( const CallICFGNode cs,
const NodeBS mods 
)
protected

Add indirect def an memory object in the function.

Add indirect def an memory object in the function

Definition at line 445 of file MemRegion.cpp.

446{
447 if(!mods.empty())
448 {
453 return csToModsMap[cs] |= modset;
454 }
455 return false;
456}
const FunObjVar * getCaller() const
Return callsite.
Definition ICFGNode.h:453
CallSiteToPointsToMap csToModsMap
Map a callsite to its indirect defs of memory objects.
Definition MemRegion.h:237
NodeBS & getCallSiteArgsPts(const CallICFGNode *cs)
Return the pts chain of all callsite arguments.
Definition MemRegion.h:259
void getEscapObjviaGlobals(NodeBS &globs, const NodeBS &pts)
Get all the objects in callee's modref escaped via global objects (the chain pts of globals)
NodeBS & getCallSiteRetPts(const CallICFGNode *cs)
Return the pts chain of the return parameter of the callsite.
Definition MemRegion.h:264

◆ addModSideEffectOfFunction()

void MRGenerator::addModSideEffectOfFunction ( const FunObjVar fun,
const NodeBS mods 
)
protected

Add indirect def an memory object in the function.

Add indirect def an memory object in the function

Definition at line 417 of file MemRegion.cpp.

418{
419 for(NodeBS::iterator it = mods.begin(), eit = mods.end(); it!=eit; ++it)
420 {
421 if(isNonLocalObject(*it,fun))
422 funToModsMap[fun].set(*it);
423 }
424}
FunToPointsToMap funToModsMap
Map a function to its indirect defs of memory objects.
Definition MemRegion.h:233
bool isNonLocalObject(NodeID id, const FunObjVar *curFun) const

◆ addRefSideEffectOfCallSite()

bool MRGenerator::addRefSideEffectOfCallSite ( const CallICFGNode cs,
const NodeBS refs 
)
protected

Add indirect uses an memory object in the function.

Add indirect uses an memory object in the function

Definition at line 429 of file MemRegion.cpp.

430{
431 if(!refs.empty())
432 {
437 return csToRefsMap[cs] |= refset;
438 }
439 return false;
440}
CallSiteToPointsToMap csToRefsMap
Map a callsite to its indirect uses of memory objects.
Definition MemRegion.h:235

◆ addRefSideEffectOfFunction()

void MRGenerator::addRefSideEffectOfFunction ( const FunObjVar fun,
const NodeBS refs 
)
protected

Add/Get methods for side-effect of functions and callsites.

Add indirect uses an memory object in the function

Definition at line 405 of file MemRegion.cpp.

406{
407 for(NodeBS::iterator it = refs.begin(), eit = refs.end(); it!=eit; ++it)
408 {
409 if(isNonLocalObject(*it,fun))
410 funToRefsMap[fun].set(*it);
411 }
412}
FunToPointsToMap funToRefsMap
Map a function to its indirect uses of memory objects.
Definition MemRegion.h:231

◆ collectCallSitePts()

void MRGenerator::collectCallSitePts ( const CallICFGNode cs)
private

Get all objects might pass into and pass out of callee(s) from a callsite

collect the pts chain of the callsite arguments

collect the pts chain of the return argument

Definition at line 462 of file MemRegion.cpp.

463{
466 SVFIR* pag = pta->getPAG();
467 CallICFGNode* callBlockNode = const_cast<CallICFGNode*>(cs);
469
470 WorkList worklist;
471 if (pag->hasCallSiteArgsMap(callBlockNode))
472 {
473 const SVFIR::ValVarList& args = pta->getPAG()->getCallSiteArgsList(callBlockNode);
474 for(SVFIR::ValVarList::const_iterator itA = args.begin(), ieA = args.end(); itA!=ieA; ++itA)
475 {
476 const PAGNode* node = *itA;
477 if(node->isPointer())
478 worklist.push(node->getId());
479 }
480 }
481
482 while(!worklist.empty())
483 {
484 NodeID nodeId = worklist.pop();
485 const NodeBS& tmp = pta->getPts(nodeId).toNodeBS();
486 for(NodeBS::iterator it = tmp.begin(), eit = tmp.end(); it!=eit; ++it)
488 }
489
492
494 {
495 const PAGNode* node = pta->getPAG()->getCallSiteRet(retBlockNode);
496 if(node->isPointer())
497 {
498 const NodeBS& tmp = pta->getPts(node->getId()).toNodeBS();
499 for(NodeBS::iterator it = tmp.begin(), eit = tmp.end(); it!=eit; ++it)
501 }
502 }
503
504}
const PointsTo & getPts(NodeID id) override
const RetICFGNode * getRetICFGNode() const
Return callsite.
Definition ICFGNode.h:440
CallSiteToPointsToMap csToCallSiteRetPtsMap
Map a callsite to all its object might return from its callees.
Definition MemRegion.h:241
FIFOWorkList< NodeID > WorkList
Definition MemRegion.h:139
NodeBS & CollectPtsChain(NodeID id)
CallSiteToPointsToMap csToCallSiteArgsPtsMap
Map a callsite to all its object might pass into its callees.
Definition MemRegion.h:239
SVFIR * getPAG() const
NodeBS toNodeBS() const
Returns this points-to set as a NodeBS.
Definition PointsTo.cpp:313
const ValVar * getCallSiteRet(const RetICFGNode *cs) const
Get callsite return.
Definition SVFIR.h:407
std::vector< const ValVar * > ValVarList
Definition SVFIR.h:60
bool hasCallSiteArgsMap(const CallICFGNode *cs) const
Callsite has argument list.
Definition SVFIR.h:385
bool callsiteHasRet(const RetICFGNode *cs) const
Definition SVFIR.h:413
const ValVarList & getCallSiteArgsList(const CallICFGNode *cs) const
Get callsite argument list.
Definition SVFIR.h:395
NodeID getId() const
Get ID.
Definition SVFValue.h:160
virtual bool isPointer() const
Check if this variable represents a pointer.
u32_t NodeID
Definition GeneralType.h:76

◆ collectGlobals()

void MRGenerator::collectGlobals ( )
protected

Collect all global variables for later escape analysis.

Collect globals for escape analysis

Definition at line 105 of file MemRegion.cpp.

106{
107 SVFIR* pag = pta->getPAG();
108 for (SVFIR::iterator nIter = pag->begin(); nIter != pag->end(); ++nIter)
109 {
110 if(ObjVar* obj = SVFUtil::dyn_cast<ObjVar>(nIter->second))
111 {
112 if (pag->getBaseObject(obj->getId())->isGlobalObj())
113 {
114 allGlobals.set(nIter->first);
116 }
117 }
118 }
119}
bool isGlobalObj() const
iterator begin()
Iterators.
IDToNodeMapTy::iterator iterator
Node Iterators.
NodeBS allGlobals
All global variable SVFIR node ids.
Definition MemRegion.h:247
const BaseObjVar * getBaseObject(NodeID id) const
Definition SVFIR.h:498
void set(unsigned Idx)

◆ collectModRefForCall()

void MRGenerator::collectModRefForCall ( )
protectedvirtual

Generate regions for calls/rets.

Generate memory regions for calls

collect points-to information for callsites

handle all sub scc nodes of this rep node

Get mod-ref of all callsites calling callGraphNode

mods are treated as both def and use of memory objects

Definition at line 227 of file MemRegion.cpp.

228{
229
230 DBOUT(DGENERAL, outs() << pasMsg("\t\tCollect Callsite PointsTo \n"));
231
233 for(SVFIR::CallSiteSet::const_iterator it = pta->getPAG()->getCallSiteSet().begin(),
234 eit = pta->getPAG()->getCallSiteSet().end(); it!=eit; ++it)
235 {
237 }
238
239 DBOUT(DGENERAL, outs() << pasMsg("\t\tPerform Callsite Mod-Ref \n"));
240
241 WorkList worklist = callGraphSCC->revTopoNodeStack();
242
243 while(!worklist.empty())
244 {
245 NodeID callGraphNodeID = worklist.front();
246 worklist.pop();
248 const NodeBS& subNodes = callGraphSCC->subNodes(callGraphNodeID);
249 for(NodeBS::iterator it = subNodes.begin(), eit = subNodes.end(); it!=eit; ++it)
250 {
254 }
255 }
256
257 DBOUT(DGENERAL, outs() << pasMsg("\t\tAdd PointsTo to Callsites \n"));
258
259 for (const CallICFGNode* callBlockNode : pta->getPAG()->getCallSiteSet())
260 {
261 if(hasRefSideEffectOfCallSite(callBlockNode))
262 {
263 NodeBS refs = getRefSideEffectOfCallSite(callBlockNode);
264 addCPtsToCallSiteRefs(refs,callBlockNode);
265 }
266 if(hasModSideEffectOfCallSite(callBlockNode))
267 {
268 NodeBS mods = getModSideEffectOfCallSite(callBlockNode);
270 addCPtsToCallSiteMods(mods,callBlockNode);
271 addCPtsToCallSiteRefs(mods,callBlockNode);
272 }
273 }
274}
#define DBOUT(TYPE, X)
LLVM debug macros, define type of your DBUG model of each pass.
Definition SVFType.h:576
#define DGENERAL
Definition SVFType.h:582
const CallGraphNode * getCallGraphNode(const std::string &name) const
Get call graph node.
bool hasModSideEffectOfCallSite(const CallICFGNode *cs)
Has indirect mods of a callsite.
Definition MemRegion.h:415
void addCPtsToCallSiteRefs(NodeBS &cpts, const CallICFGNode *cs)
Definition MemRegion.h:355
bool hasRefSideEffectOfCallSite(const CallICFGNode *cs)
Has indirect refs of a callsite.
Definition MemRegion.h:410
void collectCallSitePts(const CallICFGNode *cs)
void addCPtsToCallSiteMods(NodeBS &cpts, const CallICFGNode *cs)
Definition MemRegion.h:360
const NodeBS & getRefSideEffectOfCallSite(const CallICFGNode *cs)
Get indirect refs of a callsite.
Definition MemRegion.h:400
const NodeBS & getModSideEffectOfCallSite(const CallICFGNode *cs)
Get indirect mods of a callsite.
Definition MemRegion.h:405
virtual void modRefAnalysis(CallGraphNode *callGraphNode, WorkList &worklist)
Mod-Ref analysis for callsite invoking this callGraphNode.
const CallSiteSet & getCallSiteSet() const
Get all callsites.
Definition SVFIR.h:351
iterator begin() const
std::string pasMsg(const std::string &msg)
Print each pass/phase message by converting a string into blue string output.
Definition SVFUtil.cpp:105
std::ostream & outs()
Overwrite llvm::outs()
Definition SVFUtil.h:52

◆ collectModRefForLoadStore()

void MRGenerator::collectModRefForLoadStore ( )
protectedvirtual

Generate regions for loads/stores.

Generate memory regions for loads/stores

if this function does not have any caller, then we do not care its MSSA

Definition at line 174 of file MemRegion.cpp.

175{
176
178 for (const auto& item: *svfirCallGraph)
179 {
180 const FunObjVar& fun = *item.second->getFunction();
181
184 continue;
185
186 for (FunObjVar::const_bb_iterator iter = fun.begin(), eiter = fun.end();
187 iter != eiter; ++iter)
188 {
189 const SVFBasicBlock* bb = iter->second;
190 for (const auto& inst: bb->getICFGNodeList())
191 {
193 for (SVFStmtList::iterator bit = pagEdgeList.begin(), ebit =
194 pagEdgeList.end(); bit != ebit; ++bit)
195 {
196 const PAGEdge* inst = *bit;
197 pagEdgeToFunMap[inst] = &fun;
198 if (const StoreStmt *st = SVFUtil::dyn_cast<StoreStmt>(inst))
199 {
200 NodeBS cpts(pta->getPts(st->getLHSVarID()).toNodeBS());
201 // TODO: change this assertion check later when we have conditional points-to set
202 if (cpts.empty())
203 continue;
204 assert(!cpts.empty() && "null pointer!!");
205 addCPtsToStore(cpts, st, &fun);
206 }
207
208 else if (const LoadStmt *ld = SVFUtil::dyn_cast<LoadStmt>(inst))
209 {
210 NodeBS cpts(pta->getPts(ld->getRHSVarID()).toNodeBS());
211 // TODO: change this assertion check later when we have conditional points-to set
212 if (cpts.empty())
213 continue;
214 assert(!cpts.empty() && "null pointer!!");
215 addCPtsToLoad(cpts, ld, &fun);
216 }
217 }
218 }
219 }
220 }
221}
cJSON * item
Definition cJSON.h:222
BasicBlockGraph::IDToNodeMapTy::const_iterator const_bb_iterator
const_bb_iterator begin() const
bool isUncalledFunction() const
const_bb_iterator end() const
void addCPtsToLoad(NodeBS &cpts, const LoadStmt *ld, const FunObjVar *fun)
Definition MemRegion.h:349
void addCPtsToStore(NodeBS &cpts, const StoreStmt *st, const FunObjVar *fun)
Add cpts to store/load.
Definition MemRegion.h:343
SVFIR::SVFStmtList SVFStmtList
SVFIR edge list.
Definition MemRegion.h:180
PAGEdgeToFunMap pagEdgeToFunMap
Map a PAGEdge to its fun.
Definition MemRegion.h:228
SVFStmtList & getSVFStmtsFromInst(const ICFGNode *node)
Given an instruction, get all its the PAGEdge (statement) in sequence.
static const Option< bool > IgnoreDeadFun
Definition Options.h:135
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

◆ CollectPtsChain()

NodeBS & MRGenerator::CollectPtsChain ( NodeID  id)
private

Recursively collect all points-to of the whole struct fields

Definition at line 510 of file MemRegion.cpp.

511{
513 NodeToPTSSMap::iterator it = cachedPtsChainMap.find(baseId);
514 if(it!=cachedPtsChainMap.end())
515 return it->second;
516 else
517 {
520
521 WorkList worklist;
522 for(NodeBS::iterator it = pts.begin(), eit = pts.end(); it!=eit; ++it)
523 worklist.push(*it);
524
525 while(!worklist.empty())
526 {
527 NodeID nodeId = worklist.pop();
528 const NodeBS& tmp = pta->getPts(nodeId).toNodeBS();
529 for(NodeBS::iterator it = tmp.begin(), eit = tmp.end(); it!=eit; ++it)
530 {
532 }
533 }
534 return pts;
535 }
536
537}
bool push(const Data &data)
Definition WorkList.h:180
NodeToPTSSMap cachedPtsChainMap
Map a pointer to its cached points-to chain;.
Definition MemRegion.h:244
NodeID getBaseObjVarID(NodeID id) const
Base and Offset methods for Value and Object node.
Definition SVFIR.h:554
NodeBS getFieldsAfterCollapse(NodeID id)
Definition SVFIR.cpp:595

◆ createMR()

void MRGenerator::createMR ( const FunObjVar fun,
const NodeBS cpts 
)
protected

Generate a memory region and put in into functions which use it.

Generate a memory region and put in into functions which use it

Definition at line 70 of file MemRegion.cpp.

71{
72 const NodeBS& repCPts = getRepPointsTo(cpts);
74 MRSet::const_iterator mit = memRegSet.find(&mr);
75 if(mit!=memRegSet.end())
76 {
77 const MemRegion* mr = *mit;
78 MRSet& mrs = funToMRsMap[fun];
79 if(mrs.find(mr)==mrs.end())
80 mrs.insert(mr);
81 }
82 else
83 {
85 memRegSet.insert(m);
86 funToMRsMap[fun].insert(m);
87 }
88}
FunToMRsMap funToMRsMap
Map a function to all its memory regions.
Definition MemRegion.h:207
OrderedSet< const MemRegion *, MemRegion::equalMemRegion > MRSet
Get typedef from Pointer Analysis.
Definition MemRegion.h:145
const NodeBS & getRepPointsTo(const NodeBS &cpts) const
Get superset cpts set.
Definition MemRegion.h:190
MRSet memRegSet
A set of All memory regions.
Definition MemRegion.h:280
Memory Region class.
Definition MemRegion.h:60

◆ destroy()

void MRGenerator::destroy ( )
private

Clean up memory.

Clean up memory

Definition at line 52 of file MemRegion.cpp.

53{
54
55 for (MRSet::iterator it = memRegSet.begin(), eit = memRegSet.end();
56 it != eit; ++it)
57 {
58 delete *it;
59 }
60
61 delete callGraphSCC;
62 callGraphSCC = nullptr;
63 callGraph = nullptr;
64 pta = nullptr;
65}

◆ generateMRs()

void MRGenerator::generateMRs ( )
virtual

Start generating memory regions.

Generate memory regions according to pointer analysis results Attach regions on loads/stores

collect mod-ref for loads/stores

collect mod-ref for calls

Partition memory regions

attach memory regions for loads/stores/calls

Definition at line 125 of file MemRegion.cpp.

126{
127
128 DBOUT(DGENERAL, outs() << pasMsg("Generate Memory Regions \n"));
129
131
132 callGraphSCC->find();
133
134 DBOUT(DGENERAL, outs() << pasMsg("\tCollect ModRef For Load/Store \n"));
135
138
139 DBOUT(DGENERAL, outs() << pasMsg("\tCollect ModRef For const CallICFGNode*\n"));
140
143
144 DBOUT(DGENERAL, outs() << pasMsg("\tPartition Memory Regions \n"));
146 partitionMRs();
149}
virtual void collectModRefForLoadStore()
Generate regions for loads/stores.
virtual void collectModRefForCall()
Generate regions for calls/rets.
virtual void updateAliasMRs()
Update aliased regions for loads/stores/callsites.
virtual void partitionMRs()
Partition regions.
void collectGlobals()
Collect all global variables for later escape analysis.

◆ getAliasMemRegions()

virtual void SVF::MRGenerator::getAliasMemRegions ( MRSet aliasMRs,
const NodeBS cpts,
const FunObjVar fun 
)
inlineprotectedvirtual

Get all aliased mem regions from function fun according to cpts.

Definition at line 311 of file MemRegion.h.

312 {
313 for(MRSet::const_iterator it = funToMRsMap[fun].begin(), eit = funToMRsMap[fun].end(); it!=eit; ++it)
314 {
315 if(isAliasedMR(cpts,*it))
316 aliasMRs.insert(*it);
317 }
318 }
virtual bool isAliasedMR(const NodeBS &cpts, const MemRegion *mr)
Whether a region is aliased with a conditional points-to.
Definition MemRegion.h:306

◆ getCallSiteArgsPts()

NodeBS & SVF::MRGenerator::getCallSiteArgsPts ( const CallICFGNode cs)
inlineprivate

Return the pts chain of all callsite arguments.

Definition at line 259 of file MemRegion.h.

260 {
261 return csToCallSiteArgsPtsMap[cs];
262 }

◆ getCallSiteModMRSet()

MRSet & SVF::MRGenerator::getCallSiteModMRSet ( const CallICFGNode cs)
inline

Definition at line 469 of file MemRegion.h.

470 {
471 return callsiteToModMRsMap[cs];
472 }
CallSiteToMRsMap callsiteToModMRsMap
Map a callsite to its mods regions.
Definition MemRegion.h:215

◆ getCallSiteRefMRSet()

MRSet & SVF::MRGenerator::getCallSiteRefMRSet ( const CallICFGNode cs)
inline

Definition at line 465 of file MemRegion.h.

466 {
467 return callsiteToRefMRsMap[cs];
468 }
CallSiteToMRsMap callsiteToRefMRsMap
Map a callsite to its refs regions.
Definition MemRegion.h:213

◆ getCallSiteRetPts()

NodeBS & SVF::MRGenerator::getCallSiteRetPts ( const CallICFGNode cs)
inlineprivate

Return the pts chain of the return parameter of the callsite.

Definition at line 264 of file MemRegion.h.

265 {
266 return csToCallSiteRetPtsMap[cs];
267 }

◆ getEscapObjviaGlobals()

void MRGenerator::getEscapObjviaGlobals ( NodeBS globs,
const NodeBS calleeModRef 
)
private

Get all the objects in callee's modref escaped via global objects (the chain pts of globals)

Get all the objects in callee's modref escaped via global objects (the chain pts of globals) Otherwise, the object in callee's modref would not escape through globals

Definition at line 544 of file MemRegion.cpp.

545{
546 for(NodeBS::iterator it = calleeModRef.begin(), eit = calleeModRef.end(); it!=eit; ++it)
547 {
548 const BaseObjVar* pVar = pta->getPAG()->getBaseObject(*it);
549 (void)pVar;
550 //(void)obj; // Suppress warning of unused variable under release build
551 assert(pVar && "object not found!!");
552 if(allGlobals.test(*it))
553 globs.set(*it);
554 }
555}
bool test(unsigned Idx) const

◆ getFunction()

const FunObjVar * SVF::MRGenerator::getFunction ( const PAGEdge pagEdge) const
inline

Get the function which SVFIR Edge located.

Definition at line 437 of file MemRegion.h.

438 {
439 PAGEdgeToFunMap::const_iterator it = pagEdgeToFunMap.find(pagEdge);
440 assert(it!=pagEdgeToFunMap.end() && "can not find its function, it is a global SVFIR edge");
441 return it->second;
442 }

◆ getFunMRSet()

MRSet & SVF::MRGenerator::getFunMRSet ( const FunObjVar fun)
inline

Get Memory Region set.

Definition at line 445 of file MemRegion.h.

446 {
447 return funToMRsMap[fun];
448 }

◆ getFunToPointsToList()

FunToPointsTosMap & SVF::MRGenerator::getFunToPointsToList ( )
inlineprotected

Definition at line 373 of file MemRegion.h.

374 {
375 return funToPointsToMap;
376 }

◆ getLoadMRSet()

MRSet & SVF::MRGenerator::getLoadMRSet ( const LoadStmt load)
inline

Definition at line 449 of file MemRegion.h.

450 {
451 return loadsToMRsMap[load];
452 }
LoadsToMRsMap loadsToMRsMap
Map a load SVFIR Edge to its memory regions sets in order for inserting mus in Memory SSA.
Definition MemRegion.h:209

◆ getModInfoForCall()

NodeBS MRGenerator::getModInfoForCall ( const CallICFGNode cs)

getModRefInfo APIs

Collect mod ref for external callsite other than heap alloc external call

Obtain the mod sets for a call, used for external ModRefInfo queries

Definition at line 657 of file MemRegion.cpp.

658{
659 if (isExtCall(cs) && !isHeapAllocExtCall(cs))
660 {
662 NodeBS mods;
663 for (SVFStmtList::const_iterator bit = pagEdgeList.begin(), ebit =
664 pagEdgeList.end(); bit != ebit; ++bit)
665 {
666 const PAGEdge* edge = *bit;
667 if (const StoreStmt* st = SVFUtil::dyn_cast<StoreStmt>(edge))
668 mods |= pta->getPts(st->getLHSVarID()).toNodeBS();
669 }
670 return mods;
671 }
672 else
673 {
675 }
676}
bool isHeapAllocExtCall(const ICFGNode *cs)
Definition SVFUtil.cpp:361
bool isExtCall(const FunObjVar *fun)
Definition SVFUtil.cpp:441

◆ getModRefInfo() [1/3]

ModRefInfo MRGenerator::getModRefInfo ( const CallICFGNode cs)

Determine whether a CallSite instruction can mod or ref any memory location

Definition at line 706 of file MemRegion.cpp.

707{
708 bool ref = !getRefInfoForCall(cs).empty();
709 bool mod = !getModInfoForCall(cs).empty();
710
711 if (mod && ref)
712 return ModRefInfo::ModRef;
713 else if (ref)
714 return ModRefInfo::Ref;
715 else if (mod)
716 return ModRefInfo::Mod;
717 else
719}
NodeBS getRefInfoForCall(const CallICFGNode *cs)
NodeBS getModInfoForCall(const CallICFGNode *cs)
getModRefInfo APIs
@ Ref
Definition SVFType.h:613
@ NoModRef
Definition SVFType.h:615
@ ModRef
Definition SVFType.h:612
@ Mod
Definition SVFType.h:614

◆ getModRefInfo() [2/3]

ModRefInfo MRGenerator::getModRefInfo ( const CallICFGNode cs,
const SVFVar V 
)

Determine whether a const CallICFGNode* instruction can mod or ref a specific memory location pointed by V

Definition at line 725 of file MemRegion.cpp.

726{
727 bool ref = false;
728 bool mod = false;
729
730 const NodeBS pts(pta->getPts(V->getId()).toNodeBS());
731 const NodeBS csRef = getRefInfoForCall(cs);
732 const NodeBS csMod = getModInfoForCall(cs);
737
738 if (csRefExpanded.intersects(ptsExpanded))
739 ref = true;
740 if (csModExpanded.intersects(ptsExpanded))
741 mod = true;
742
743 if (mod && ref)
744 return ModRefInfo::ModRef;
745 else if (ref)
746 return ModRefInfo::Ref;
747 else if (mod)
748 return ModRefInfo::Mod;
749 else
751}
virtual void expandFIObjs(const PointsTo &pts, PointsTo &expandedPts)
Expand FI objects.

◆ getModRefInfo() [3/3]

ModRefInfo MRGenerator::getModRefInfo ( const CallICFGNode cs1,
const CallICFGNode cs2 
)

Determine mod-ref relations between two const CallICFGNode* instructions

return NoModRef neither two callsites ref or mod any memory

Ref: cs1 ref memory mod by cs2

Mod: cs1 mod memory ref or mod by cs2

ModRef: cs1 ref and mod memory mod by cs2

Definition at line 756 of file MemRegion.cpp.

757{
758 bool ref = false;
759 bool mod = false;
760
764
774
776 if (cs1RefExpanded.intersects(cs2ModExpanded))
777 ref = true;
779 if (cs1ModExpanded.intersects(cs2RefExpanded) || cs1ModExpanded.intersects(cs2ModExpanded))
780 mod = true;
782 if (cs1RefExpanded.intersects(cs2ModExpanded) && cs1ModExpanded.intersects(cs2ModExpanded))
783 ref = mod = true;
784
785 if (ref && mod)
786 return ModRefInfo::ModRef;
787 else if (ref)
788 return ModRefInfo::Ref;
789 else if (mod)
790 return ModRefInfo::Mod;
791 else
793}
ModRefInfo getModRefInfo(const CallICFGNode *cs)

◆ getModSideEffectOfCallSite()

const NodeBS & SVF::MRGenerator::getModSideEffectOfCallSite ( const CallICFGNode cs)
inlineprotected

Get indirect mods of a callsite.

Definition at line 405 of file MemRegion.h.

406 {
407 return csToModsMap[cs];
408 }

◆ getModSideEffectOfFunction()

const NodeBS & SVF::MRGenerator::getModSideEffectOfFunction ( const FunObjVar fun)
inlineprotected

Get indirect mods of a function.

Definition at line 395 of file MemRegion.h.

396 {
397 return funToModsMap[fun];
398 }

◆ getMR()

const MemRegion * MRGenerator::getMR ( const NodeBS cpts) const

Get a memory region according to cpts.

Generate a memory region and put in into functions which use it

Definition at line 93 of file MemRegion.cpp.

94{
95 MemRegion mr(getRepPointsTo(cpts));
96 MRSet::iterator mit = memRegSet.find(&mr);
97 assert(mit!=memRegSet.end() && "memory region not found!!");
98 return *mit;
99}

◆ getMRNum()

u32_t SVF::MRGenerator::getMRNum ( ) const
inline

Definition at line 422 of file MemRegion.h.

423 {
424 return memRegSet.size();
425 }

◆ getMRSet()

MRSet & SVF::MRGenerator::getMRSet ( )
inline

Definition at line 184 of file MemRegion.h.

185 {
186 return memRegSet;
187 }

◆ getMRsForCallSiteRef()

virtual void SVF::MRGenerator::getMRsForCallSiteRef ( MRSet aliasMRs,
const NodeBS cpts,
const FunObjVar  
)
inlineprotectedvirtual

Get memory regions for call site ref according to cpts.

Reimplemented in SVF::DistinctMRG, and SVF::IntraDisjointMRG.

Definition at line 328 of file MemRegion.h.

329 {
330 const MemRegion* mr = getMR(cpts);
331 aliasMRs.insert(mr);
332 }
const MemRegion * getMR(const NodeBS &cpts) const
Get a memory region according to cpts.
Definition MemRegion.cpp:93

◆ getMRsForLoad()

virtual void SVF::MRGenerator::getMRsForLoad ( MRSet aliasMRs,
const NodeBS cpts,
const FunObjVar  
)
inlineprotectedvirtual

Get memory regions for a load statement according to cpts.

Reimplemented in SVF::InterDisjointMRG, SVF::DistinctMRG, and SVF::IntraDisjointMRG.

Definition at line 321 of file MemRegion.h.

322 {
323 const MemRegion* mr = getMR(cpts);
324 aliasMRs.insert(mr);
325 }

◆ getPointsToList()

PointsToList & SVF::MRGenerator::getPointsToList ( const FunObjVar fun)
inlineprotected

Definition at line 369 of file MemRegion.h.

370 {
371 return funToPointsToMap[fun];
372 }

◆ getRefInfoForCall()

NodeBS MRGenerator::getRefInfoForCall ( const CallICFGNode cs)

Obtain the ref sets for a call, used for external ModRefInfo queries

Definition at line 681 of file MemRegion.cpp.

682{
683 if (isExtCall(cs) && !isHeapAllocExtCall(cs))
684 {
686 NodeBS refs;
687 for (SVFStmtList::const_iterator bit = pagEdgeList.begin(), ebit =
688 pagEdgeList.end(); bit != ebit; ++bit)
689 {
690 const PAGEdge* edge = *bit;
691 if (const LoadStmt* ld = SVFUtil::dyn_cast<LoadStmt>(edge))
692 refs |= pta->getPts(ld->getRHSVarID()).toNodeBS();
693 }
694 return refs;
695 }
696 else
697 {
699 }
700}

◆ getRefSideEffectOfCallSite()

const NodeBS & SVF::MRGenerator::getRefSideEffectOfCallSite ( const CallICFGNode cs)
inlineprotected

Get indirect refs of a callsite.

Definition at line 400 of file MemRegion.h.

401 {
402 return csToRefsMap[cs];
403 }

◆ getRefSideEffectOfFunction()

const NodeBS & SVF::MRGenerator::getRefSideEffectOfFunction ( const FunObjVar fun)
inlineprotected

Get indirect refs of a function.

Definition at line 390 of file MemRegion.h.

391 {
392 return funToRefsMap[fun];
393 }

◆ getRepPointsTo()

const NodeBS & SVF::MRGenerator::getRepPointsTo ( const NodeBS cpts) const
inline

Get superset cpts set.

Definition at line 190 of file MemRegion.h.

191 {
192 PtsToRepPtsSetMap::const_iterator it = cptsToRepCPtsMap.find(cpts);
193 assert(it!=cptsToRepCPtsMap.end() && "can not find superset of cpts??");
194 return it->second;
195 }
PtsToRepPtsSetMap cptsToRepCPtsMap
Map a condition pts to its rep conditional pts (super set points-to)
Definition MemRegion.h:282

◆ getStoreMRSet()

MRSet & SVF::MRGenerator::getStoreMRSet ( const StoreStmt store)
inline

Definition at line 453 of file MemRegion.h.

454 {
455 return storesToMRsMap[store];
456 }
StoresToMRsMap storesToMRsMap
Map a store SVFIR Edge to its memory regions sets in order for inserting chis in Memory SSA.
Definition MemRegion.h:211

◆ getSVFStmtsFromInst()

SVFIR::SVFStmtList & MRGenerator::getSVFStmtsFromInst ( const ICFGNode node)

Given an instruction, get all its the PAGEdge (statement) in sequence.

Definition at line 161 of file MemRegion.cpp.

162{
163 SVFIR* pag = pta->getPAG();
164 if (ptrOnlyMSSA)
165 return pag->getPTASVFStmtList(node);
166 else
167 return pag->getSVFStmtList(node);
168}
SVFStmtList & getSVFStmtList(const ICFGNode *inst)
Given an instruction, get all its PAGEdges.
Definition SVFIR.h:318
SVFStmtList & getPTASVFStmtList(const ICFGNode *inst)
Given an instruction, get all its PTA PAGEdges.
Definition SVFIR.h:323

◆ handleCallsiteModRef()

bool MRGenerator::handleCallsiteModRef ( NodeBS mod,
NodeBS ref,
const CallICFGNode cs,
const FunObjVar callee 
)
protectedvirtual

Get Mod-Ref of a callee function.

Get Mod-Ref of a callee function

if a callee is a heap allocator function, then its mod set of this callsite is the heap object.

otherwise, we find the mod/ref sets from the callee function, who has definition and been processed

Definition at line 590 of file MemRegion.cpp.

591{
593 if(isHeapAllocExtCall(cs))
594 {
596 for (SVFStmtList::const_iterator bit = pagEdgeList.begin(),
597 ebit = pagEdgeList.end(); bit != ebit; ++bit)
598 {
599 const PAGEdge* edge = *bit;
600 if (const AddrStmt* addr = SVFUtil::dyn_cast<AddrStmt>(edge))
601 mod.set(addr->getRHSVarID());
602 }
603 }
605 else
606 {
609 }
610 // add ref set
612 // add mod set
614
615 return refchanged || modchanged;
616}
const NodeBS & getModSideEffectOfFunction(const FunObjVar *fun)
Get indirect mods of a function.
Definition MemRegion.h:395
const NodeBS & getRefSideEffectOfFunction(const FunObjVar *fun)
Get indirect refs of a function.
Definition MemRegion.h:390
bool addRefSideEffectOfCallSite(const CallICFGNode *cs, const NodeBS &refs)
Add indirect uses an memory object in the function.
bool addModSideEffectOfCallSite(const CallICFGNode *cs, const NodeBS &mods)
Add indirect def an memory object in the function.

◆ hasCPtsList()

bool SVF::MRGenerator::hasCPtsList ( const FunObjVar fun) const
inlineprotected

Definition at line 365 of file MemRegion.h.

366 {
367 return funToPointsToMap.find(fun)!=funToPointsToMap.end();
368 }

◆ hasModMRSet()

bool SVF::MRGenerator::hasModMRSet ( const CallICFGNode cs)
inline

Definition at line 461 of file MemRegion.h.

462 {
463 return callsiteToModMRsMap.find(cs)!=callsiteToModMRsMap.end();
464 }

◆ hasModSideEffectOfCallSite()

bool SVF::MRGenerator::hasModSideEffectOfCallSite ( const CallICFGNode cs)
inlineprotected

Has indirect mods of a callsite.

Definition at line 415 of file MemRegion.h.

416 {
417 return csToModsMap.find(cs) != csToModsMap.end();
418 }

◆ hasRefMRSet()

bool SVF::MRGenerator::hasRefMRSet ( const CallICFGNode cs)
inline

Definition at line 457 of file MemRegion.h.

458 {
459 return callsiteToRefMRsMap.find(cs)!=callsiteToRefMRsMap.end();
460 }

◆ hasRefSideEffectOfCallSite()

bool SVF::MRGenerator::hasRefSideEffectOfCallSite ( const CallICFGNode cs)
inlineprotected

Has indirect refs of a callsite.

Definition at line 410 of file MemRegion.h.

411 {
412 return csToRefsMap.find(cs) != csToRefsMap.end();
413 }

◆ hasSVFStmtList()

bool MRGenerator::hasSVFStmtList ( const ICFGNode icfgNode)

Whether this instruction has SVFIR Edge.

Definition at line 151 of file MemRegion.cpp.

152{
153 SVFIR* pag = pta->getPAG();
154 if (ptrOnlyMSSA)
155 return pag->hasPTASVFStmtList(node);
156 else
157 return pag->hasSVFStmtList(node);
158}
bool hasPTASVFStmtList(const ICFGNode *inst) const
Definition SVFIR.h:312
bool hasSVFStmtList(const ICFGNode *inst) const
Whether this instruction has SVFIR Edge.
Definition SVFIR.h:308

◆ isAliasedMR()

virtual bool SVF::MRGenerator::isAliasedMR ( const NodeBS cpts,
const MemRegion mr 
)
inlineprotectedvirtual

Whether a region is aliased with a conditional points-to.

Definition at line 306 of file MemRegion.h.

307 {
308 return mr->getPointsTo().intersects(cpts);
309 }

◆ isNonLocalObject()

bool MRGenerator::isNonLocalObject ( NodeID  id,
const FunObjVar curFun 
) const
private

Whether the object node is a non-local object including global, heap, and stack variable in recursions

if the object is heap or global

or if the local variable of its callers or a local variable is in function recursion cycles

Definition at line 561 of file MemRegion.cpp.

562{
563 //ABTest
564 const BaseObjVar* obj = pta->getPAG()->getBaseObject(id);
565 assert(obj && "object not found!!");
567 const BaseObjVar* pVar = pta->getPAG()->getBaseObject(id);
568 assert(pVar && "object not found!");
569 if(obj->isGlobalObj() || SVFUtil::isa<HeapObjVar, DummyObjVar>(pVar))
570 return true;
573 else if(SVFUtil::isa<StackObjVar>(pVar))
574 {
575 if(const FunObjVar* svffun = pVar->getFunction())
576 {
577 if(svffun!=curFun)
578 return true;
579 else
580 return callGraphSCC->isInCycle(callGraph->getCallGraphNode(svffun)->getId());
581 }
582 }
583
584 return false;
585}
virtual const FunObjVar * getFunction() const
Get containing function, or null for globals/constants.

◆ modRefAnalysis()

void MRGenerator::modRefAnalysis ( CallGraphNode callGraphNode,
WorkList worklist 
)
protectedvirtual

Mod-Ref analysis for callsite invoking this callGraphNode.

Call site mod-ref analysis Compute mod-ref of all callsites invoking this call graph node

add ref/mod set of callee to its invocation callsites at caller

handle direct callsites

handle indirect callsites

Definition at line 622 of file MemRegion.cpp.

623{
624
626 for(CallGraphNode::iterator it = callGraphNode->InEdgeBegin(), eit = callGraphNode->InEdgeEnd();
627 it!=eit; ++it)
628 {
630
632 for(CallGraphEdge::CallInstSet::iterator cit = edge->getDirectCalls().begin(),
633 ecit = edge->getDirectCalls().end(); cit!=ecit; ++cit)
634 {
635 NodeBS mod, ref;
636 const CallICFGNode* cs = (*cit);
637 bool modrefchanged = handleCallsiteModRef(mod, ref, cs, callGraphNode->getFunction());
638 if(modrefchanged)
639 worklist.push(edge->getSrcID());
640 }
642 for(CallGraphEdge::CallInstSet::iterator cit = edge->getIndirectCalls().begin(),
643 ecit = edge->getIndirectCalls().end(); cit!=ecit; ++cit)
644 {
645 NodeBS mod, ref;
646 const CallICFGNode* cs = (*cit);
647 bool modrefchanged = handleCallsiteModRef(mod, ref, cs, callGraphNode->getFunction());
648 if(modrefchanged)
649 worklist.push(edge->getSrcID());
650 }
651 }
652}
const FunObjVar * getFunction() const
Get function of this call node.
Definition CallGraph.h:191
GEdgeSetTy::iterator iterator
iterator InEdgeBegin()
iterator InEdgeEnd()
virtual bool handleCallsiteModRef(NodeBS &mod, NodeBS &ref, const CallICFGNode *cs, const FunObjVar *fun)
Get Mod-Ref of a callee function.

◆ partitionMRs()

void MRGenerator::partitionMRs ( )
protectedvirtual

Partition regions.

Partition memory regions

Compute all superset of all condition points-to sets TODO: we may need some refined region partitioning algorithm here For now, we just collapse all refs/mods objects at callsites into one region Consider modularly partition memory regions to speed up analysis (only partition regions within function scope)

Generate memory regions according to condition pts after computing superset

Reimplemented in SVF::DistinctMRG, SVF::IntraDisjointMRG, and SVF::InterDisjointMRG.

Definition at line 315 of file MemRegion.cpp.

316{
317
322 for(FunToPointsTosMap::iterator it = getFunToPointsToList().begin(), eit = getFunToPointsToList().end();
323 it!=eit; ++it)
324 {
325 for(PointsToList::iterator cit = it->second.begin(), ecit = it->second.end(); cit!=ecit; ++cit)
326 {
328 }
329 }
331 for(FunToPointsTosMap::iterator it = getFunToPointsToList().begin(), eit = getFunToPointsToList().end();
332 it!=eit; ++it)
333 {
334 const FunObjVar* fun = it->first;
335 for(PointsToList::iterator cit = it->second.begin(), ecit = it->second.end(); cit!=ecit; ++cit)
336 {
337 createMR(fun,*cit);
338 }
339 }
340
341}
void createMR(const FunObjVar *fun, const NodeBS &cpts)
Generate a memory region and put in into functions which use it.
Definition MemRegion.cpp:70
FunToPointsTosMap & getFunToPointsToList()
Definition MemRegion.h:373
virtual void sortPointsTo(const NodeBS &cpts)
Given a condition pts, insert into cptsToRepCPtsMap for region generation.

◆ sortPointsTo()

void MRGenerator::sortPointsTo ( const NodeBS cpts)
protectedvirtual

Given a condition pts, insert into cptsToRepCPtsMap for region generation.

Given a condition pts, insert into cptsToRepCPtsMap Always map it to its superset(rep) cpts according to existing items 1) map cpts to its superset(rep) which exists in the map, otherwise its superset is itself 2) adjust existing items in the map if their supersets are cpts

Definition at line 282 of file MemRegion.cpp.

283{
284
285 if(cptsToRepCPtsMap.find(cpts)!=cptsToRepCPtsMap.end())
286 return;
287
289 NodeBS repCPts = cpts;
290 for(PtsToRepPtsSetMap::iterator it = cptsToRepCPtsMap.begin(),
291 eit = cptsToRepCPtsMap.end(); it!=eit; ++it)
292 {
293 NodeBS& existCPts = it->second;
294 if(cpts.contains(existCPts))
295 {
296 subSetList.insert(it->first);
297 }
298 else if(existCPts.contains(cpts))
299 {
301 }
302 }
303
304 for(PointsToList::iterator it = subSetList.begin(), eit = subSetList.end(); it!=eit; ++it)
305 {
306 cptsToRepCPtsMap[*it] = cpts;
307 }
308
310}
bool contains(const SparseBitVector< ElementSize > &RHS) const
OrderedSet< PointsTo, equalPointsTo > PointsToList
Definition SVFUtil.h:168

◆ updateAliasMRs()

void MRGenerator::updateAliasMRs ( )
protectedvirtual

Update aliased regions for loads/stores/callsites.

Update aliased regions for loads/stores/callsites

update stores with its aliased regions

update callsites with its aliased regions

Definition at line 346 of file MemRegion.cpp.

347{
348
350 for(StoresToPointsToMap::const_iterator it = storesToPointsToMap.begin(), eit = storesToPointsToMap.end(); it!=eit; ++it)
351 {
353 const FunObjVar* fun = getFunction(it->first);
354 const NodeBS& storeCPts = it->second;
356 for(MRSet::iterator ait = aliasMRs.begin(), eait = aliasMRs.end(); ait!=eait; ++ait)
357 {
358 storesToMRsMap[it->first].insert(*ait);
359 }
360 }
361
362 for(LoadsToPointsToMap::const_iterator it = loadsToPointsToMap.begin(), eit = loadsToPointsToMap.end(); it!=eit; ++it)
363 {
365 const FunObjVar* fun = getFunction(it->first);
366 const NodeBS& loadCPts = it->second;
368 for(MRSet::iterator ait = aliasMRs.begin(), eait = aliasMRs.end(); ait!=eait; ++ait)
369 {
370 loadsToMRsMap[it->first].insert(*ait);
371 }
372 }
373
375 for(CallSiteToPointsToMap::const_iterator it = callsiteToModPointsToMap.begin(),
376 eit = callsiteToModPointsToMap.end(); it!=eit; ++it)
377 {
378 const FunObjVar* fun = it->first->getCaller();
380 const NodeBS& callsiteModCPts = it->second;
382 for(MRSet::iterator ait = aliasMRs.begin(), eait = aliasMRs.end(); ait!=eait; ++ait)
383 {
384 callsiteToModMRsMap[it->first].insert(*ait);
385 }
386 }
387 for(CallSiteToPointsToMap::const_iterator it = callsiteToRefPointsToMap.begin(),
388 eit = callsiteToRefPointsToMap.end(); it!=eit; ++it)
389 {
390 const FunObjVar* fun = it->first->getCaller();
392 const NodeBS& callsiteRefCPts = it->second;
394 for(MRSet::iterator ait = aliasMRs.begin(), eait = aliasMRs.end(); ait!=eait; ++ait)
395 {
396 callsiteToRefMRsMap[it->first].insert(*ait);
397 }
398 }
399}
virtual void getAliasMemRegions(MRSet &aliasMRs, const NodeBS &cpts, const FunObjVar *fun)
Get all aliased mem regions from function fun according to cpts.
Definition MemRegion.h:311
const FunObjVar * getFunction(const PAGEdge *pagEdge) const
Get the function which SVFIR Edge located.
Definition MemRegion.h:437
virtual void getMRsForCallSiteRef(MRSet &aliasMRs, const NodeBS &cpts, const FunObjVar *)
Get memory regions for call site ref according to cpts.
Definition MemRegion.h:328
virtual void getMRsForLoad(MRSet &aliasMRs, const NodeBS &cpts, const FunObjVar *)
Get memory regions for a load statement according to cpts.
Definition MemRegion.h:321

Member Data Documentation

◆ allGlobals

NodeBS SVF::MRGenerator::allGlobals
private

All global variable SVFIR node ids.

Definition at line 247 of file MemRegion.h.

◆ cachedPtsChainMap

NodeToPTSSMap SVF::MRGenerator::cachedPtsChainMap
private

Map a pointer to its cached points-to chain;.

Definition at line 244 of file MemRegion.h.

◆ callGraph

CallGraph* SVF::MRGenerator::callGraph
private

Definition at line 203 of file MemRegion.h.

◆ callGraphSCC

SCC* SVF::MRGenerator::callGraphSCC
private

Definition at line 202 of file MemRegion.h.

◆ callsiteToModMRsMap

CallSiteToMRsMap SVF::MRGenerator::callsiteToModMRsMap
private

Map a callsite to its mods regions.

Definition at line 215 of file MemRegion.h.

◆ callsiteToModPointsToMap

CallSiteToPointsToMap SVF::MRGenerator::callsiteToModPointsToMap
private

Map a callsite to it mods cpts set.

Definition at line 223 of file MemRegion.h.

◆ callsiteToRefMRsMap

CallSiteToMRsMap SVF::MRGenerator::callsiteToRefMRsMap
private

Map a callsite to its refs regions.

Definition at line 213 of file MemRegion.h.

◆ callsiteToRefPointsToMap

CallSiteToPointsToMap SVF::MRGenerator::callsiteToRefPointsToMap
private

Map a callsite to it refs cpts set.

Definition at line 221 of file MemRegion.h.

◆ cptsToRepCPtsMap

PtsToRepPtsSetMap SVF::MRGenerator::cptsToRepCPtsMap
protected

Map a condition pts to its rep conditional pts (super set points-to)

Definition at line 282 of file MemRegion.h.

◆ csToCallSiteArgsPtsMap

CallSiteToPointsToMap SVF::MRGenerator::csToCallSiteArgsPtsMap
private

Map a callsite to all its object might pass into its callees.

Definition at line 239 of file MemRegion.h.

◆ csToCallSiteRetPtsMap

CallSiteToPointsToMap SVF::MRGenerator::csToCallSiteRetPtsMap
private

Map a callsite to all its object might return from its callees.

Definition at line 241 of file MemRegion.h.

◆ csToModsMap

CallSiteToPointsToMap SVF::MRGenerator::csToModsMap
private

Map a callsite to its indirect defs of memory objects.

Definition at line 237 of file MemRegion.h.

◆ csToRefsMap

CallSiteToPointsToMap SVF::MRGenerator::csToRefsMap
private

Map a callsite to its indirect uses of memory objects.

Definition at line 235 of file MemRegion.h.

◆ funToModsMap

FunToPointsToMap SVF::MRGenerator::funToModsMap
private

Map a function to its indirect defs of memory objects.

Definition at line 233 of file MemRegion.h.

◆ funToMRsMap

FunToMRsMap SVF::MRGenerator::funToMRsMap
private

Map a function to all its memory regions.

Definition at line 207 of file MemRegion.h.

◆ funToPointsToMap

FunToPointsTosMap SVF::MRGenerator::funToPointsToMap
private

Map a function to all of its conditional points-to sets.

Definition at line 226 of file MemRegion.h.

◆ funToRefsMap

FunToPointsToMap SVF::MRGenerator::funToRefsMap
private

Map a function to its indirect uses of memory objects.

Definition at line 231 of file MemRegion.h.

◆ loadsToMRsMap

LoadsToMRsMap SVF::MRGenerator::loadsToMRsMap
private

Map a load SVFIR Edge to its memory regions sets in order for inserting mus in Memory SSA.

Definition at line 209 of file MemRegion.h.

◆ loadsToPointsToMap

LoadsToPointsToMap SVF::MRGenerator::loadsToPointsToMap
private

Map a load SVFIR Edge to its CPts set map.

Definition at line 217 of file MemRegion.h.

◆ memRegSet

MRSet SVF::MRGenerator::memRegSet
protected

A set of All memory regions.

Definition at line 280 of file MemRegion.h.

◆ pagEdgeToFunMap

PAGEdgeToFunMap SVF::MRGenerator::pagEdgeToFunMap
private

Map a PAGEdge to its fun.

Definition at line 228 of file MemRegion.h.

◆ pta

BVDataPTAImpl* SVF::MRGenerator::pta
private

Definition at line 201 of file MemRegion.h.

◆ ptrOnlyMSSA

bool SVF::MRGenerator::ptrOnlyMSSA
private

Definition at line 204 of file MemRegion.h.

◆ storesToMRsMap

StoresToMRsMap SVF::MRGenerator::storesToMRsMap
private

Map a store SVFIR Edge to its memory regions sets in order for inserting chis in Memory SSA.

Definition at line 211 of file MemRegion.h.

◆ storesToPointsToMap

StoresToPointsToMap SVF::MRGenerator::storesToPointsToMap
private

Map a store SVFIR Edge to its CPts set map.

Definition at line 219 of file MemRegion.h.


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