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 "SVFIR/SVFValue.h"
34
35namespace SVF
36{
37
38class SVFModule;
39class ICFGNode;
40class CallICFGNode;
41class SVFVar;
42class ValVar;
43class ObjVar;
44
45/*
46 * ThreadAPI class contains interfaces for pthread programs
47 */
49{
50
51public:
74
76
77private:
80
83 {
84 init();
85 }
86
88 void init();
89
92
94 inline TD_TYPE getType(const SVFFunction* F) const
95 {
96 if(F)
97 {
98 TDAPIMap::const_iterator it= tdAPIMap.find(F->getName());
99 if(it != tdAPIMap.end())
100 return it->second;
101 }
102 return TD_DUMMY;
103 }
104
105public:
108 {
109 if(tdAPI == nullptr)
110 {
111 tdAPI = new ThreadAPI();
112 }
113 return tdAPI;
114 }
115
116 static void destroy()
117 {
118 if(tdAPI != nullptr)
119 {
120 delete tdAPI;
121 tdAPI = nullptr;
122 }
123 }
124
126
127
129 const ValVar* getForkedThread(const CallICFGNode *inst) const;
132 const ValVar* getForkedFun(const CallICFGNode *inst) const;
133
136 const ValVar* getActualParmAtForkSite(const CallICFGNode *inst) const;
137
139 const SVFVar* getFormalParmOfForkedFun(const SVFFunction* F) const;
141
142
143
145
146 bool isTDFork(const CallICFGNode *inst) const;
148
150
151 bool isTDJoin(const CallICFGNode *inst) const;
153
155
156
158 const SVFVar* getJoinedThread(const CallICFGNode *inst) const;
161 const SVFVar* getRetParmAtJoinedSite(const CallICFGNode *inst) const;
163
164
166
167 bool isTDExit(const CallICFGNode *inst) const;
169
171
172 bool isTDAcquire(const CallICFGNode* inst) const;
174
176
177 bool isTDRelease(const CallICFGNode *inst) const;
179
181
182
183 const SVFVar* getLockVal(const ICFGNode *inst) const;
185
187
188 bool isTDBarWait(const CallICFGNode *inst) const;
190
193};
194
195} // End namespace SVF
196
197#endif /* THREADAPI_H_ */
#define F(f)
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:91
@ TD_COND_SIGNAL
wait a condition
Definition ThreadAPI.h:64
@ TD_DETACH
wait for a thread to join
Definition ThreadAPI.h:57
@ TD_CONDVAR_INI
initial a mutex variable
Definition ThreadAPI.h:68
@ HARE_PAR_FOR
Barrier wait.
Definition ThreadAPI.h:72
@ TD_BAR_INIT
initial a mutex variable
Definition ThreadAPI.h:70
@ TD_ACQUIRE
detach a thread directly instead wait for it to join
Definition ThreadAPI.h:58
@ TD_MUTEX_DESTROY
initial a mutex variable
Definition ThreadAPI.h:67
@ TD_FORK
dummy type
Definition ThreadAPI.h:55
@ TD_CONDVAR_DESTROY
initial a mutex variable
Definition ThreadAPI.h:69
@ TD_JOIN
create a new thread
Definition ThreadAPI.h:56
@ TD_BAR_WAIT
Barrier init.
Definition ThreadAPI.h:71
@ TD_COND_BROADCAST
signal a condition
Definition ThreadAPI.h:65
@ TD_COND_WAIT
cancel a thread by another
Definition ThreadAPI.h:63
@ TD_TRY_ACQUIRE
acquire a lock
Definition ThreadAPI.h:59
@ TD_MUTEX_INI
broadcast a condition
Definition ThreadAPI.h:66
@ TD_RELEASE
try to acquire a lock
Definition ThreadAPI.h:60
@ TD_EXIT
release a lock
Definition ThreadAPI.h:61
@ TD_CANCEL
exit/kill a thread
Definition ThreadAPI.h:62
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:79
bool isTDJoin(const CallICFGNode *inst) const
Return true if this call wait for a worker thread.
void init()
Initialize the map.
const SVFVar * getFormalParmOfForkedFun(const SVFFunction *F) const
Return the formal parm of forked function (the first arg in pthread)
bool isTDRelease(const CallICFGNode *inst) const
Return true if this call release a lock.
void performAPIStat(SVFModule *m)
const SVFVar * getLockVal(const ICFGNode *inst) const
Return lock value.
TD_TYPE getType(const SVFFunction *F) const
Get the function type if it is a threadAPI function.
Definition ThreadAPI.h:94
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:82
Map< std::string, TD_TYPE > TDAPIMap
Definition ThreadAPI.h:75
const ValVar * getActualParmAtForkSite(const CallICFGNode *inst) const
static ThreadAPI * getThreadAPI()
Return a static reference.
Definition ThreadAPI.h:107
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.
static void destroy()
Definition ThreadAPI.h:116
for isBitcode
Definition BasicTypes.h:68
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:74