SVF
TypeBasedHeapCloning.h
Go to the documentation of this file.
1 //===- TypeBasedHeapCloning.h -- Type filter/type-based heap cloning base ------------//
2 
3 /*
4  * TypeBasedHeapCloning.h
5  *
6  * Contains data structures and functions to extend a pointer analysis
7  * with type-based heap cloning/type filtering.
8  *
9  * Created on: Feb 08, 2020
10  * Author: Mohamad Barbar
11  */
12 
13 #include "SVF-FE/DCHG.h"
14 #include "Graphs/PAG.h"
16 #include "Util/BasicTypes.h"
17 
18 namespace SVF
19 {
20 
22 {
23 public:
25  static const MDNode *getRawCTirMetadata(const Value *);
26 
27  virtual ~TypeBasedHeapCloning() { };
28 
29 protected:
31  static const DIType *undefType;
32 
34  static const std::string derefFnName;
36  static const std::string mangledDerefFnName;
37 
40 
43  virtual void backPropagate(NodeID clone) = 0;
44 
47  DCHGraph *dchg = nullptr;
48 
50  void setDCHG(DCHGraph *dchg);
52  void setPAG(PAG *pag);
53 
56  bool isBlkObjOrConstantObj(NodeID o) const;
57 
60  bool isBase(const DIType *a, const DIType *b) const;
61 
63  bool isClone(NodeID o) const;
64 
66  void setType(NodeID o, const DIType *t);
68  const DIType *getType(NodeID o) const;
69 
71  void setAllocationSite(NodeID o, NodeID site);
74 
76  const NodeBS getObjsWithClones(void);
78  void addClone(NodeID o, NodeID c);
80  const NodeBS &getClones(NodeID o);
81 
82  // Set o as the original object of clone c.
83  void setOriginalObj(NodeID c, NodeID o);
85  NodeID getOriginalObj(NodeID c) const;
86 
89 
91  void addGepToObj(NodeID gep, NodeID base, unsigned offset);
94  const NodeBS &getGepObjsFromMemObj(const MemObj *memObj, unsigned offset);
97  const NodeBS &getGepObjs(NodeID base);
98 
102  const NodeBS getGepObjClones(NodeID base, unsigned offset);
103 
106  bool init(NodeID loc, NodeID p, const DIType *tildet, bool reuse, bool gep=false);
107 
110  NodeID cloneObject(NodeID o, const DIType *type, bool reuse);
111 
113  inline NodeID addCloneDummyObjNode(const MemObj *mem);
115  inline NodeID addCloneGepObjNode(const MemObj *mem, const LocationSet &l);
117  inline NodeID addCloneFIObjNode(const MemObj *mem);
118 
122  const DIType *getTypeFromCTirMetadata(const Value *);
123 
140  void validateTBHCTests(SVFModule *svfMod);
141 
143  void dumpStats(void);
144 
145 private:
149  PAG *ppag = nullptr;
150 
167 
169  bool isGep(const PAGNode *n) const;
170 
171  // Bunch of stats to keep track of.
172  unsigned numInit = 0;
173  unsigned numTBWU = 0;
174  unsigned numTBSSU = 0;
175  unsigned numTBSU = 0;
176  unsigned numReuse = 0;
177  unsigned numAgg = 0;
178 
179  // Previous stats but only upon stack/global objects.
180  unsigned numSGInit = 0;
181  unsigned numSGTBWU = 0;
182  unsigned numSGTBSSU = 0;
183  unsigned numSGTBSU = 0;
184  unsigned numSGReuse = 0;
185  unsigned numSGAgg = 0;
186 };
187 
188 } // End namespace SVF
void setOriginalObj(NodeID c, NodeID o)
virtual void backPropagate(NodeID clone)=0
static const std::string derefFnName
deref function for TBHC alias tests.
u32_t NodeID
Definition: SVFBasicTypes.h:80
TypeBasedHeapCloning(BVDataPTAImpl *pta)
Constructor. pta is the pointer analysis using this object (i.e. that which is extending).
const NodeBS & getGepObjs(NodeID base)
Map< NodeID, const DIType * > objToType
Object -> its type.
Map< NodeID, PointsTo > locToFilterSet
Maps nodes (a location like a PAG node or SVFG node) to their filter set.
void setType(NodeID o, const DIType *t)
Sets the type (in objToType) of o.
Map< NodeID, NodeBS > objToGeps
Maps objects to the GEP nodes beneath them.
NodeID addCloneFIObjNode(const MemObj *mem)
Add clone FI object node to PAG.
bool isBlkObjOrConstantObj(NodeID o) const
NodeID addCloneGepObjNode(const MemObj *mem, const LocationSet &l)
Add clone GEP object node to PAG.
Definition: PAG.h:47
Dwarf based CHG.
Definition: DCHG.h:208
std::unordered_map< Key, Value, Hash, KeyEqual, Allocator > Map
Definition: SVFBasicTypes.h:98
static const DIType * undefType
The undefined type (•); void.
BVDataPTAImpl * pta
PTA extending this class.
Map< NodeID, NodeID > objToAllocation
PAG * ppag
PAG the PTA uses. Just a shortcut for getPAG().
const NodeBS getObjsWithClones(void)
Returns objects that have clones (any key in objToClones).
void setPAG(PAG *pag)
PAG must be set by extending class once the PAG is available.
static const std::string mangledDerefFnName
deref function (mangled) for TBHC alias tests.
NodeID cloneObject(NodeID o, const DIType *type, bool reuse)
void setDCHG(DCHGraph *dchg)
DCHG must be set by extending class once the DCHG is available.
void dumpStats(void)
Dump some statistics we tracked.
void validateTBHCTests(SVFModule *svfMod)
const NodeBS & getGepObjsFromMemObj(const MemObj *memObj, unsigned offset)
NodeID getAllocationSite(NodeID o) const
Returns the allocation site (from objToAllocation) of o. Asserts existence.
static const MDNode * getRawCTirMetadata(const Value *)
Returns raw ctir metadata of a Value. Returns null if it doesn&#39;t exist.
bool isBase(const DIType *a, const DIType *b) const
const DIType * getType(NodeID o) const
Returns the type (from objToType) of o. Asserts existence.
void setAllocationSite(NodeID o, NodeID site)
Sets the allocation site (in objToAllocation) of o.
llvm::MDNode MDNode
Definition: BasicTypes.h:138
Map< NodeID, NodeID > cloneToOriginalObj
(Clone) object -> original object (opposite of objToclones).
for isBitcode
Definition: ContextDDA.h:15
bool isClone(NodeID o) const
Returns true if o is a clone.
llvm::SparseBitVector NodeBS
Definition: SVFBasicTypes.h:87
const NodeBS & getClones(NodeID o)
Returns all the clones of o.
PointsTo & getFilterSet(NodeID loc)
Returns the filter set of a location. Not const; could create empty PointsTo.
bool isGep(const PAGNode *n) const
Test whether object is a GEP object. For convenience.
NodeID addCloneDummyObjNode(const MemObj *mem)
Add clone dummy object node to PAG.
const DIType * getTypeFromCTirMetadata(const Value *)
Map< NodeID, NodeBS > objToClones
(Original) object -> set of its clones.
const NodeBS getGepObjClones(NodeID base, unsigned offset)
Map< const MemObj *, Map< unsigned, NodeBS > > memObjToGeps
Maps memory objects to their GEP objects. (memobj -> (fieldidx -> geps))
void addClone(NodeID o, NodeID c)
Add a clone c to object o.
bool init(NodeID loc, NodeID p, const DIType *tildet, bool reuse, bool gep=false)
NodeID getOriginalObj(NodeID c) const
Returns the original object c is cloned from. If c is not a clone, returns itself.
llvm::Value Value
Definition: BasicTypes.h:78
NodeBS PointsTo
Definition: SVFBasicTypes.h:88
llvm::DIType DIType
Definition: BasicTypes.h:217
void addGepToObj(NodeID gep, NodeID base, unsigned offset)
Associates gep with base (through objToGeps and memObjToGeps).