Static Value-Flow Analysis
Loading...
Searching...
No Matches
ThreadAPI.h
Go to the documentation of this file.
1//===- ThreadAPI.h -- API for threads-----------------------------------------//
2//
3// SVF: Static Value-Flow Analysis
4//
5// Copyright (C) <2013-2017> <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 * ThreadAPI.h
25 *
26 * Created on: Jan 21, 2014
27 * Author: Yulei Sui, dye
28 */
29
30#ifndef THREADAPI_H_
31#define THREADAPI_H_
32
33#include "Util/GeneralType.h"
34
35namespace SVF
36{
37
38class ICFGNode;
39class CallICFGNode;
40class SVFVar;
41class ValVar;
42class ObjVar;
43class FunObjVar;
44class PointerAnalysis;
45
46/*
47 * ThreadAPI class contains interfaces for pthread programs
48 */
50{
51
52public:
75
77
78private:
81
84 {
85 init();
86 }
87
89 void init();
90
93
95 TD_TYPE getType(const FunObjVar* F) const;
96
97public:
100 {
101 if(tdAPI == nullptr)
102 {
103 tdAPI = new ThreadAPI();
104 }
105 return tdAPI;
106 }
107
108 static void destroy()
109 {
110 if(tdAPI != nullptr)
111 {
112 delete tdAPI;
113 tdAPI = nullptr;
114 }
115 }
116
118
119
121 const ValVar* getForkedThread(const CallICFGNode *inst) const;
124 const ValVar* getForkedFun(const CallICFGNode *inst) const;
125
128 const ValVar* getActualParmAtForkSite(const CallICFGNode *inst) const;
129
131 const SVFVar* getFormalParmOfForkedFun(const FunObjVar* F) const;
133
134
135
137
138 bool isTDFork(const CallICFGNode *inst) const;
140
142
143 bool isTDJoin(const CallICFGNode *inst) const;
145
147
148
150 const SVFVar* getJoinedThread(const CallICFGNode *inst) const;
153 const SVFVar* getRetParmAtJoinedSite(const CallICFGNode *inst) const;
155
161
163 const SVFVar* joinArg) const;
165 const SVFVar* joinArg, ForkJoinAliasCache& cache) const;
166
167
169
170 bool isTDExit(const CallICFGNode *inst) const;
172
174
175 bool isTDAcquire(const CallICFGNode* inst) const;
177
179
180 bool isTDRelease(const CallICFGNode *inst) const;
182
184
185
186 const SVFVar* getLockVal(const ICFGNode *inst) const;
188
190
191 bool isTDBarWait(const CallICFGNode *inst) const;
193
194 void performAPIStat();
196};
197
198} // End namespace SVF
199
200#endif /* THREADAPI_H_ */
const ValVar * getForkedFun(const CallICFGNode *inst) const
bool isTDFork(const CallICFGNode *inst) const
Return true if this call create a new thread.
static ThreadAPI * tdAPI
Static reference.
Definition ThreadAPI.h:92
@ TD_COND_SIGNAL
wait a condition
Definition ThreadAPI.h:65
@ TD_DETACH
wait for a thread to join
Definition ThreadAPI.h:58
@ TD_CONDVAR_INI
initial a mutex variable
Definition ThreadAPI.h:69
@ HARE_PAR_FOR
Barrier wait.
Definition ThreadAPI.h:73
@ TD_BAR_INIT
initial a mutex variable
Definition ThreadAPI.h:71
@ TD_ACQUIRE
detach a thread directly instead wait for it to join
Definition ThreadAPI.h:59
@ TD_MUTEX_DESTROY
initial a mutex variable
Definition ThreadAPI.h:68
@ TD_FORK
dummy type
Definition ThreadAPI.h:56
@ TD_CONDVAR_DESTROY
initial a mutex variable
Definition ThreadAPI.h:70
@ TD_JOIN
create a new thread
Definition ThreadAPI.h:57
@ TD_BAR_WAIT
Barrier init.
Definition ThreadAPI.h:72
@ TD_COND_BROADCAST
signal a condition
Definition ThreadAPI.h:66
@ TD_COND_WAIT
cancel a thread by another
Definition ThreadAPI.h:64
@ TD_TRY_ACQUIRE
acquire a lock
Definition ThreadAPI.h:60
@ TD_MUTEX_INI
broadcast a condition
Definition ThreadAPI.h:67
@ TD_RELEASE
try to acquire a lock
Definition ThreadAPI.h:61
@ TD_EXIT
release a lock
Definition ThreadAPI.h:62
@ TD_CANCEL
exit/kill a thread
Definition ThreadAPI.h:63
const ValVar * getForkedThread(const CallICFGNode *inst) const
Return arguments/attributes of pthread_create / hare_parallel_for.
TDAPIMap tdAPIMap
API map, from a string to threadAPI type.
Definition ThreadAPI.h:80
bool isTDJoin(const CallICFGNode *inst) const
Return true if this call wait for a worker thread.
void init()
Initialize the map.
bool isTDRelease(const CallICFGNode *inst) const
Return true if this call release a lock.
const SVFVar * getFormalParmOfForkedFun(const FunObjVar *F) const
Return the formal parm of forked function (the first arg in pthread)
const SVFVar * getLockVal(const ICFGNode *inst) const
Return lock value.
bool isTDExit(const CallICFGNode *inst) const
Return true if this call exits/terminate a thread.
const SVFVar * getRetParmAtJoinedSite(const CallICFGNode *inst) const
void statInit(Map< std::string, u32_t > &tdAPIStatMap)
const SVFVar * getJoinedThread(const CallICFGNode *inst) const
Return arguments/attributes of pthread_join.
ThreadAPI()
Constructor.
Definition ThreadAPI.h:83
void performAPIStat()
bool isAliasedForkJoin(PointerAnalysis *pta, const SVFVar *forkArg, const SVFVar *joinArg) const
Map< std::string, TD_TYPE > TDAPIMap
Definition ThreadAPI.h:76
const ValVar * getActualParmAtForkSite(const CallICFGNode *inst) const
static ThreadAPI * getThreadAPI()
Return a static reference.
Definition ThreadAPI.h:99
bool isTDBarWait(const CallICFGNode *inst) const
Return true if this call waits for a barrier.
bool isTDAcquire(const CallICFGNode *inst) const
Return true if this call acquire a lock.
TD_TYPE getType(const FunObjVar *F) const
Get the function type if it is a threadAPI function.
static void destroy()
Definition ThreadAPI.h:108
for isBitcode
Definition BasicTypes.h:70
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:76
If fork join the same thread.
Definition ThreadAPI.h:158
Map< const SVFVar *, NodeBS > joinedThreadObjects
Definition ThreadAPI.h:159