SVF
Public Types | Private Member Functions | Private Attributes | List of all members
SVF::TypeSystem Class Reference

#include <PTAType.h>

Public Types

typedef Map< NodeID, TypeSet * > VarToTypeSetMapTy
 
typedef OrderedMap< PTAType, NodeBSTypeToVarsMapTy
 
typedef VarToTypeSetMapTy::iterator iterator
 
typedef VarToTypeSetMapTy::const_iterator const_iterator
 

Public Member Functions

iterator begin ()
 Iterators. More...
 
iterator end ()
 
const_iterator begin () const
 
const_iterator end () const
 
 TypeSystem (const PAG *pag)
 Constructor. More...
 
bool hasTypeSet (NodeID var) const
 Has typeset or not. More...
 
const TypeSetgetTypeSet (NodeID var) const
 Get a var's typeset. More...
 
bool addTypeForVar (NodeID var, const PTAType &type)
 
bool addTypeForVar (NodeID var, const Type *type)
 
void addVarForType (NodeID var, const PTAType &type)
 
void addVarForType (NodeID var, const Type *type)
 
bool hasVarsForType (const PTAType &type) const
 
NodeBSgetVarsForType (const PTAType &type)
 
void printTypeSystem () const
 Print each var's id and all its types. More...
 

Private Member Functions

void translateLLVMTypeToPTAType (const PAG *pag)
 

Private Attributes

VarToTypeSetMapTy VarToTypeSetMap
 
OrderedSet< PTATypeallPTATypes
 
TypeToVarsMapTy typeToVarsMap
 

Detailed Description

Definition at line 189 of file PTAType.h.

Member Typedef Documentation

◆ const_iterator

typedef VarToTypeSetMapTy::const_iterator SVF::TypeSystem::const_iterator

Definition at line 198 of file PTAType.h.

◆ iterator

typedef VarToTypeSetMapTy::iterator SVF::TypeSystem::iterator

Definition at line 197 of file PTAType.h.

◆ TypeToVarsMapTy

Definition at line 195 of file PTAType.h.

◆ VarToTypeSetMapTy

Definition at line 193 of file PTAType.h.

Constructor & Destructor Documentation

◆ TypeSystem()

SVF::TypeSystem::TypeSystem ( const PAG pag)
inline

Constructor.

Definition at line 221 of file PTAType.h.

222  {
224  }
void translateLLVMTypeToPTAType(const PAG *pag)
Definition: PTAType.h:330

Member Function Documentation

◆ addTypeForVar() [1/2]

bool SVF::TypeSystem::addTypeForVar ( NodeID  var,
const PTAType type 
)
inline

Add a ptatype for a var Return true if the ptatype is new for this var

Definition at line 243 of file PTAType.h.

244  {
245  iterator it = VarToTypeSetMap.find(var);
246  if (it != VarToTypeSetMap.end())
247  {
248  TypeSet *typeSet = it->second;
249  return typeSet->addType(type);
250  }
251  else
252  {
253  TypeSet *typeSet = new TypeSet;
254  typeSet->addType(type);
255  VarToTypeSetMap[var] = typeSet;
256  return true;
257  }
258  }
VarToTypeSetMapTy::iterator iterator
Definition: PTAType.h:197
VarToTypeSetMapTy VarToTypeSetMap
Definition: PTAType.h:361

◆ addTypeForVar() [2/2]

bool SVF::TypeSystem::addTypeForVar ( NodeID  var,
const Type type 
)
inline

Add a ptatype for a var Return true if the ptatype is new for this var

Definition at line 262 of file PTAType.h.

263  {
264  PTAType ptaTy(type);
265  return addTypeForVar(var, ptaTy);
266  }
bool addTypeForVar(NodeID var, const PTAType &type)
Definition: PTAType.h:243

◆ addVarForType() [1/2]

void SVF::TypeSystem::addVarForType ( NodeID  var,
const PTAType type 
)
inline

Definition at line 268 of file PTAType.h.

269  {
270  TypeToVarsMapTy::iterator it = typeToVarsMap.find(type);
271  if (it == typeToVarsMap.end())
272  {
273  NodeBS nodes;
274  nodes.set(var);
275  typeToVarsMap[type] = nodes;
276  }
277  else
278  {
279  NodeBS &nodes = it->second;
280  nodes.set(var);
281  }
282  }
TypeToVarsMapTy typeToVarsMap
Definition: PTAType.h:363
llvm::SparseBitVector NodeBS
Definition: SVFBasicTypes.h:87

◆ addVarForType() [2/2]

void SVF::TypeSystem::addVarForType ( NodeID  var,
const Type type 
)
inline

Definition at line 284 of file PTAType.h.

285  {
286  PTAType ptaTy(type);
287  return addVarForType(var, ptaTy);
288  }
void addVarForType(NodeID var, const PTAType &type)
Definition: PTAType.h:268

◆ begin() [1/2]

iterator SVF::TypeSystem::begin ( )
inline

Iterators.

Definition at line 202 of file PTAType.h.

203  {
204  return VarToTypeSetMap.begin();
205  }
VarToTypeSetMapTy VarToTypeSetMap
Definition: PTAType.h:361

◆ begin() [2/2]

const_iterator SVF::TypeSystem::begin ( ) const
inline

Definition at line 210 of file PTAType.h.

211  {
212  return VarToTypeSetMap.begin();
213  }
VarToTypeSetMapTy VarToTypeSetMap
Definition: PTAType.h:361

◆ end() [1/2]

iterator SVF::TypeSystem::end ( )
inline

Definition at line 206 of file PTAType.h.

207  {
208  return VarToTypeSetMap.end();
209  }
VarToTypeSetMapTy VarToTypeSetMap
Definition: PTAType.h:361

◆ end() [2/2]

const_iterator SVF::TypeSystem::end ( ) const
inline

Definition at line 214 of file PTAType.h.

215  {
216  return VarToTypeSetMap.end();
217  }
VarToTypeSetMapTy VarToTypeSetMap
Definition: PTAType.h:361

◆ getTypeSet()

const TypeSet* SVF::TypeSystem::getTypeSet ( NodeID  var) const
inline

Get a var's typeset.

Definition at line 234 of file PTAType.h.

235  {
236  const_iterator it = VarToTypeSetMap.find(var);
237  assert(it != VarToTypeSetMap.end() && "Can not find typeset for var");
238  return it->second;
239  }
VarToTypeSetMapTy::const_iterator const_iterator
Definition: PTAType.h:198
#define assert(ex)
Definition: util.h:141
VarToTypeSetMapTy VarToTypeSetMap
Definition: PTAType.h:361

◆ getVarsForType()

NodeBS& SVF::TypeSystem::getVarsForType ( const PTAType type)
inline

Definition at line 296 of file PTAType.h.

297  {
298  TypeToVarsMapTy::iterator it = typeToVarsMap.find(type);
299  assert(it != typeToVarsMap.end() && "Can not find vars for type");
300  return it->second;
301  }
TypeToVarsMapTy typeToVarsMap
Definition: PTAType.h:363
#define assert(ex)
Definition: util.h:141

◆ hasTypeSet()

bool SVF::TypeSystem::hasTypeSet ( NodeID  var) const
inline

Has typeset or not.

Definition at line 227 of file PTAType.h.

228  {
229  const_iterator it = VarToTypeSetMap.find(var);
230  return it != VarToTypeSetMap.end();
231  }
VarToTypeSetMapTy::const_iterator const_iterator
Definition: PTAType.h:198
VarToTypeSetMapTy VarToTypeSetMap
Definition: PTAType.h:361

◆ hasVarsForType()

bool SVF::TypeSystem::hasVarsForType ( const PTAType type) const
inline

Definition at line 290 of file PTAType.h.

291  {
292  TypeToVarsMapTy::const_iterator it = typeToVarsMap.find(type);
293  return it != typeToVarsMap.end();
294  }
TypeToVarsMapTy typeToVarsMap
Definition: PTAType.h:363

◆ printTypeSystem()

void SVF::TypeSystem::printTypeSystem ( ) const
inline

Print each var's id and all its types.

Definition at line 306 of file PTAType.h.

307  {
308  for (const_iterator it = VarToTypeSetMap.begin(),
309  eit = VarToTypeSetMap.end(); it != eit; ++it)
310  {
311  SVFUtil::errs() << "Var: " << it->first << '\n';
312  SVFUtil::errs() << "types:\n";
313  const TypeSet *typeSet = it->second;
314  typeSet->dumpTypes();
315  SVFUtil::errs() << '\n';
316  }
317  }
VarToTypeSetMapTy::const_iterator const_iterator
Definition: PTAType.h:198
raw_ostream & errs()
Overwrite llvm::errs()
Definition: SVFUtil.h:53
VarToTypeSetMapTy VarToTypeSetMap
Definition: PTAType.h:361

◆ translateLLVMTypeToPTAType()

void SVF::TypeSystem::translateLLVMTypeToPTAType ( const PAG pag)
inlineprivate

Definition at line 330 of file PTAType.h.

331  {
332  for (PAG::const_iterator it = pag->begin(); it != pag->end(); ++it)
333  {
334  const PAGNode *pagNode = it->second;
335  if (pagNode->hasValue() == false)
336  continue;
337 
338  const Value *value = pagNode->getValue();
339  const Type *valType = value->getType();
340 
341  const Type *nodeType = valType;
342 
343  if (const GepValPN *gepvalnode = SVFUtil::dyn_cast<GepValPN>(pagNode))
344  {
345  nodeType = gepvalnode->getType();
346  }
347  else if (SVFUtil::isa<RetPN>(pagNode))
348  {
349  const llvm::PointerType *ptrTy = SVFUtil::dyn_cast<llvm::PointerType>(valType);
350  const llvm::FunctionType *funTy = SVFUtil::dyn_cast<llvm::FunctionType>(ptrTy->getElementType());
351  nodeType = funTy->getReturnType();
352  }
353 
354  PTAType ptaType(nodeType);
355  if (addTypeForVar(pagNode->getId(), ptaType))
356  addVarForType(pagNode->getId(), ptaType);
357  }
358  }
bool addTypeForVar(NodeID var, const PTAType &type)
Definition: PTAType.h:243
llvm::FunctionType FunctionType
Definition: BasicTypes.h:109
llvm::Type Type
Definition: BasicTypes.h:75
llvm::PointerType PointerType
Definition: BasicTypes.h:108
IDToNodeMapTy::const_iterator const_iterator
Definition: GenericGraph.h:338
void addVarForType(NodeID var, const PTAType &type)
Definition: PTAType.h:268
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:343
llvm::Value Value
Definition: BasicTypes.h:78

Member Data Documentation

◆ allPTATypes

OrderedSet<PTAType> SVF::TypeSystem::allPTATypes
private

Definition at line 362 of file PTAType.h.

◆ typeToVarsMap

TypeToVarsMapTy SVF::TypeSystem::typeToVarsMap
private

Definition at line 363 of file PTAType.h.

◆ VarToTypeSetMap

VarToTypeSetMapTy SVF::TypeSystem::VarToTypeSetMap
private

Definition at line 361 of file PTAType.h.


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