SVF
AndersenWaveDiffWithType.cpp
Go to the documentation of this file.
1 #include "WPA/Andersen.h"
2 #include "MemoryModel/PTAType.h"
3 
4 using namespace SVF;
5 using namespace SVFUtil;
6 
8 
9 
12 {
13  NodeID srcId = edge->getSrcID();
14  NodeID dstId = edge->getDstID();
15  if (pag->hasNonlabeledEdge(pag->getPAGNode(srcId), pag->getPAGNode(dstId), PAGEdge::Copy))
16  {
17  const Value *val = pag->getIntraPAGEdge(srcId, dstId, PAGEdge::Copy)->getValue();
18  if (val)
19  {
20  if (const CastInst *castInst = SVFUtil::dyn_cast<CastInst>(val))
21  {
22  updateObjType(castInst->getType(), getPts(edge->getSrcID()));
23  }
24  else if (const ConstantExpr *ce = SVFUtil::dyn_cast<ConstantExpr>(val))
25  {
26  if (ce->getOpcode() == Instruction::BitCast)
27  {
28  updateObjType(ce->getType(), getPts(edge->getSrcID()));
29  }
30  }
31  }
32  }
33 }
34 
37 {
38  for (PointsTo::iterator it = objs.begin(), eit = objs.end(); it != eit; ++it)
39  {
40  if (typeSystem->addTypeForVar(*it, type))
41  {
42  typeSystem->addVarForType(*it, type);
43  processTypeMismatchedGep(*it, type);
44  }
45  }
46 }
47 
50 {
51  TypeMismatchedObjToEdgeTy::iterator it = typeMismatchedObjToEdges.find(obj);
52  if (it == typeMismatchedObjToEdges.end())
53  return;
54  Set<const GepCGEdge*> &edges = it->second;
55  Set<const GepCGEdge*> processed;
56 
57  PTAType ptaTy(type);
58  NodeBS &nodesOfType = typeSystem->getVarsForType(ptaTy);
59 
60  for (Set<const GepCGEdge*>::iterator nit = edges.begin(), neit = edges.end(); nit != neit; ++nit)
61  {
62  if (const NormalGepCGEdge *normalGepEdge = SVFUtil::dyn_cast<NormalGepCGEdge>(*nit))
63  {
64  if (!nodesOfType.test(normalGepEdge->getSrcID()))
65  continue;
66  PointsTo tmpPts;
67  tmpPts.set(obj);
68  Andersen::processGepPts(tmpPts, normalGepEdge);
69  processed.insert(normalGepEdge);
70  }
71  }
72 
73  for (Set<const GepCGEdge*>::iterator nit = processed.begin(), neit = processed.end(); nit != neit; ++nit)
74  edges.erase(*nit);
75 }
76 
78 bool AndersenWaveDiffWithType::matchType(NodeID ptrid, NodeID objid, const NormalGepCGEdge *normalGepEdge)
79 {
80  if (!typeSystem->hasTypeSet(ptrid) || !typeSystem->hasTypeSet(objid))
81  return true;
82  const TypeSet *ptrTypeSet = typeSystem->getTypeSet(ptrid);
83  const TypeSet *objTypeSet = typeSystem->getTypeSet(objid);
84  if (ptrTypeSet->intersect(objTypeSet))
85  {
86  return true;
87  }
88  else
89  {
90  recordTypeMismatchedGep(objid, normalGepEdge);
91  return false;
92  }
93 }
94 
97 {
98  NodeID srcId = normalGepEdge->getSrcID();
99  NodeID dstId = normalGepEdge->getDstID();
100  if (pag->hasNonlabeledEdge(pag->getPAGNode(srcId), pag->getPAGNode(dstId), PAGEdge::NormalGep))
101  {
102  const Value *val = pag->getIntraPAGEdge(srcId, dstId, PAGEdge::NormalGep)->getValue();
103  if (val)
104  {
105  PTAType ptaTy(val->getType());
106  if(typeSystem->addTypeForVar(id, ptaTy))
107  typeSystem->addVarForType(id, ptaTy);
108  }
109  }
110 }
111 
113 {
115 
117  const NodeBS &repNodes = getSCCDetector()->getRepNodes();
118  for (NodeBS::iterator it = repNodes.begin(), eit = repNodes.end(); it != eit; ++it)
119  {
120  NodeBS subNodes = getSCCDetector()->subNodes(*it);
121  mergeTypeOfNodes(subNodes);
122  }
123 
124  return getSCCDetector()->topoNodeStack();
125 }
126 
129 {
130 
132  OrderedSet<PTAType> typesInSCC;
133  for (NodeBS::iterator it = nodes.begin(), eit = nodes.end(); it != eit; ++it)
134  {
135  if (typeSystem->hasTypeSet(*it))
136  {
137  const TypeSet *typeSet = typeSystem->getTypeSet(*it);
138  for (TypeSet::const_iterator tyit = typeSet->begin(), tyeit = typeSet->end(); tyit != tyeit; ++tyit)
139  {
140  const PTAType &ptaTy = *tyit;
141  typesInSCC.insert(ptaTy);
142  }
143  }
144  }
145 
147  for (NodeBS::iterator it = nodes.begin(), eit = nodes.end(); it != eit; ++it)
148  {
149  for (OrderedSet<PTAType>::iterator tyit = typesInSCC.begin(), tyeit = typesInSCC.end(); tyit != tyeit; ++tyit)
150  {
151  const PTAType &ptaTy = *tyit;
152  if (typeSystem->addTypeForVar(*it, ptaTy))
153  typeSystem->addVarForType(*it, ptaTy);
154  }
155  }
156 
157 }
std::set< Key, Compare, Allocator > OrderedSet
llvm::CastInst CastInst
Definition: BasicTypes.h:150
NodeID getDstID() const
Definition: GenericGraph.h:77
u32_t NodeID
Definition: SVFBasicTypes.h:80
llvm::Type Type
Definition: BasicTypes.h:75
std::stack< NodeID > NodeStack
NodeID getSrcID() const
get methods of the components
Definition: GenericGraph.h:73
bool intersect(const TypeSet *typeset) const
Intersect with another typeset or not.
Definition: PTAType.h:140
std::unordered_set< Key, Hash, KeyEqual, Allocator > Set
Definition: SVFBasicTypes.h:93
iterator begin()
Definition: PTAType.h:99
TypeSetTy::const_iterator const_iterator
Definition: PTAType.h:95
virtual NodeStack & SCCDetect()
SCC detection.
virtual void addTypeForGepObjNode(NodeID id, const NormalGepCGEdge *normalGepEdge)
add type for newly created GepObjNode
iterator end()
Definition: PTAType.h:103
virtual bool processGepPts(const PointsTo &pts, const GepCGEdge *edge)
Definition: Andersen.cpp:358
for isBitcode
Definition: ContextDDA.h:15
void updateObjType(const Type *type, const PointsTo &objs)
update type of objects when process "bitcast" CopyCGEdge
llvm::SparseBitVector NodeBS
Definition: SVFBasicTypes.h:87
virtual NodeStack & SCCDetect()
SCC detection.
Definition: Andersen.cpp:571
llvm::ConstantExpr ConstantExpr
Definition: BasicTypes.h:125
virtual void processCast(const ConstraintEdge *edge)
process "bitcast" CopyCGEdge
static AndersenWaveDiffWithType * diffWaveWithType
Definition: Andersen.h:494
virtual bool matchType(NodeID ptrid, NodeID objid, const NormalGepCGEdge *normalGepEdge)
match types for Gep Edges
void mergeTypeOfNodes(const NodeBS &nodes)
merge types of nodes in a cycle
llvm::Value Value
Definition: BasicTypes.h:78
NodeBS PointsTo
Definition: SVFBasicTypes.h:88
void processTypeMismatchedGep(NodeID obj, const Type *type)
process mismatched gep edges