Static Value-Flow Analysis
PCG.h
Go to the documentation of this file.
1 //===- PCG.h -- Procedure creation graph-------------//
2 //
3 // SVF: Static Value-Flow Analysis
4 //
5 // Copyright (C) <2013-> <Yulei Sui>
6 //
7 
8 // This program is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU Affero General Public License as published by
10 // the Free Software Foundation, either version 3 of the License, or
11 // (at your option) any later version.
12 
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU Affero General Public License for more details.
17 
18 // You should have received a copy of the GNU Affero General Public License
19 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 //
21 //===----------------------------------------------------------------------===//
22 
23 /*
24  * MHP.h
25  *
26  * Created on: Jan 21, 2014
27  * Author: Yulei Sui, Peng Di
28  */
29 
30 #ifndef PCG_H_
31 #define PCG_H_
32 
33 #include "Util/ThreadAPI.h"
34 #include "Graphs/PTACallGraph.h"
35 #include "Util/WorkList.h"
36 #include "WPA/Andersen.h"
37 #include <set>
38 #include <vector>
39 
40 #include "MHP.h"
41 
42 namespace SVF
43 {
44 
50 class PCG
51 {
52 
53 public:
55  typedef std::vector<const SVFFunction*> FunVec;
59 
60 private:
69 
72 
74 
75  inline bool isSpawnerFun(const SVFFunction* fun) const
76  {
77  return spawners.find(fun) != spawners.end();
78  }
79  inline bool isSpawneeFun(const SVFFunction* fun) const
80  {
81  return spawnees.find(fun) != spawnees.end();
82  }
83  inline bool isFollowerFun(const SVFFunction* fun) const
84  {
85  return followers.find(fun) != followers.end();
86  }
87  inline bool addSpawnerFun(const SVFFunction* fun)
88  {
89  if (fun->isDeclaration())
90  return false;
91  return spawners.insert(fun).second;
92  }
93  inline bool addSpawneeFun(const SVFFunction* fun)
94  {
95  if (fun->isDeclaration())
96  return false;
97  return spawnees.insert(fun).second;
98  }
99  inline bool addFollowerFun(const SVFFunction* fun)
100  {
101  if (fun->isDeclaration())
102  return false;
103  return followers.insert(fun).second;
104  }
106 
108 
109  inline bool addSpawnsite(const SVFInstruction* callInst)
110  {
111  return spawnCallSites.insert(callInst).second;
112  }
113  inline bool isSpawnsite(const SVFInstruction* callInst)
114  {
115  return spawnCallSites.find(callInst) != spawnCallSites.end();
116  }
118 
120  inline CallInstSet::const_iterator spawnSitesBegin() const
121  {
122  return spawnCallSites.begin();
123  }
124  inline CallInstSet::const_iterator spawnSitesEnd() const
125  {
126  return spawnCallSites.end();
127  }
129 
130 public:
131 
134  {
135  mod = pta->getModule();
138  }
139 
141  virtual bool analyze();
142 
144  virtual ~PCG()
145  {
146  }
147 
149  {
150  return pta->getICFG()->getCallICFGNode(inst);
151  }
153  virtual bool mayHappenInParallel(const SVFInstruction* i1, const SVFInstruction* i2) const;
154  bool mayHappenInParallelBetweenFunctions(const SVFFunction* fun1, const SVFFunction* fun2) const;
155  inline const FunSet& getMHPFunctions() const
156  {
157  return mhpfuns;
158  }
159 
161  void initFromThreadAPI(SVFModule* module);
162 
164 
165  void inferFromCallGraph();
166  void collectSpawners();
167  void collectSpawnees();
168  void collectFollowers();
169  void identifyFollowers();
171 
173 
174  inline const FunSet& getSpawners() const
175  {
176  return spawners;
177  }
178  inline const FunSet& getSpawnees() const
179  {
180  return spawnees;
181  }
182  inline const FunSet& getFollowers() const
183  {
184  return followers;
185  }
187 
189 
190  inline FunSet::const_iterator spawnersBegin(const SVFFunction* fun) const
191  {
192  return spawners.begin();
193  }
194  inline FunSet::const_iterator spawnersEnd(const SVFFunction* fun) const
195  {
196  return spawners.end();
197  }
198  inline FunSet::const_iterator spawneesBegin(const SVFFunction* fun) const
199  {
200  return spawnees.begin();
201  }
202  inline FunSet::const_iterator spawneesEnd(const SVFFunction* fun) const
203  {
204  return spawnees.end();
205  }
206  inline FunSet::const_iterator followersBegin(const SVFFunction* fun) const
207  {
208  return followers.begin();
209  }
210  inline FunSet::const_iterator followersEnd(const SVFFunction* fun) const
211  {
212  return followers.end();
213  }
215 
217  void interferenceAnalysis();
218 
220  void printResults();
224  void printTDFuns();
225 };
226 
227 } // End namespace SVF
228 
229 #endif /* PCG_H_ */
CallICFGNode * getCallICFGNode(const SVFInstruction *inst)
Definition: ICFG.cpp:241
Definition: PCG.h:51
void interferenceAnalysis()
Thread interferenceAnalysis.
Definition: PCG.cpp:302
void collectFollowers()
Definition: PCG.cpp:265
virtual bool mayHappenInParallel(const SVFInstruction *i1, const SVFInstruction *i2) const
Interface to query whether two function may happen-in-parallel.
Definition: PCG.cpp:83
bool addSpawneeFun(const SVFFunction *fun)
Definition: PCG.h:93
const FunSet & getFollowers() const
Definition: PCG.h:182
std::vector< const SVFFunction * > FunVec
Definition: PCG.h:55
void initFromThreadAPI(SVFModule *module)
Initialize spawner and spawnee sets with threadAPI.
Definition: PCG.cpp:96
CallInstSet::const_iterator spawnSitesBegin() const
Spawn sites iterators.
Definition: PCG.h:120
FunSet::const_iterator spawnersEnd(const SVFFunction *fun) const
Definition: PCG.h:194
const FunSet & getMHPFunctions() const
Definition: PCG.h:155
virtual ~PCG()
Destructor.
Definition: PCG.h:144
FunSet spawners
Definition: PCG.h:61
FunSet::const_iterator spawnersBegin(const SVFFunction *fun) const
Iterators for thread properties of a procedure.
Definition: PCG.h:190
FunSet::const_iterator spawneesBegin(const SVFFunction *fun) const
Definition: PCG.h:198
PCG(PointerAnalysis *an)
Constructor.
Definition: PCG.h:133
bool addFollowerFun(const SVFFunction *fun)
Definition: PCG.h:99
bool isSpawnerFun(const SVFFunction *fun) const
Add/Get methods for thread properties of a procedure.
Definition: PCG.h:75
const FunSet & getSpawnees() const
Definition: PCG.h:178
FIFOWorkList< const SVFBasicBlock * > BBWorkList
Definition: PCG.h:58
virtual bool analyze()
We start the pass here.
Definition: PCG.cpp:49
bool addSpawnerFun(const SVFFunction *fun)
Definition: PCG.h:87
bool addSpawnsite(const SVFInstruction *callInst)
Add/search spawn sites which directly or indirectly create a thread.
Definition: PCG.h:109
const FunSet & getSpawners() const
Get spawners/spawnees/followers.
Definition: PCG.h:174
FunSet spawnees
Definition: PCG.h:62
bool isFollowerFun(const SVFFunction *fun) const
Definition: PCG.h:83
FunSet::const_iterator followersBegin(const SVFFunction *fun) const
Definition: PCG.h:206
bool isSpawnsite(const SVFInstruction *callInst)
Definition: PCG.h:113
ThreadAPI * tdAPI
Definition: PCG.h:68
CallInstSet spawnCallSites
Callsites direct or Indirect call a function which spawn a thread.
Definition: PCG.h:71
void collectSpawnees()
Definition: PCG.cpp:187
CallInstSet::const_iterator spawnSitesEnd() const
Definition: PCG.h:124
CallICFGNode * getCallICFGNode(const SVFInstruction *inst)
Definition: PCG.h:148
FunSet mhpfuns
Definition: PCG.h:64
SVFModule * mod
Definition: PCG.h:66
FIFOWorkList< const SVFFunction * > FunWorkList
Definition: PCG.h:57
bool isSpawneeFun(const SVFFunction *fun) const
Definition: PCG.h:79
Set< const SVFFunction * > FunSet
Definition: PCG.h:54
FunSet followers
Definition: PCG.h:63
FunSet::const_iterator spawneesEnd(const SVFFunction *fun) const
Definition: PCG.h:202
void printResults()
Print analysis results.
Definition: PCG.cpp:341
Set< const SVFInstruction * > CallInstSet
Definition: PCG.h:56
FunSet::const_iterator followersEnd(const SVFFunction *fun) const
Definition: PCG.h:210
PointerAnalysis * pta
Definition: PCG.h:67
void inferFromCallGraph()
Infer spawner spawnee and followers sets by traversing on callGraph.
Definition: PCG.cpp:133
void identifyFollowers()
Definition: PCG.cpp:217
PTACallGraph * callgraph
Definition: PCG.h:65
void collectSpawners()
Definition: PCG.cpp:146
bool mayHappenInParallelBetweenFunctions(const SVFFunction *fun1, const SVFFunction *fun2) const
Definition: PCG.cpp:69
void printTDFuns()
Definition: PCG.cpp:350
PTACallGraph * getPTACallGraph() const
Return call graph.
SVFModule * getModule() const
Module.
ICFG * getICFG() const
Get ICFG.
bool isDeclaration() const
Definition: SVFValue.h:367
static ThreadAPI * getThreadAPI()
Return a static reference.
Definition: ThreadAPI.h:102
for isBitcode
Definition: BasicTypes.h:68
std::unordered_set< Key, Hash, KeyEqual, Allocator > Set
Definition: GeneralType.h:96