/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/tools/clang/lib/StaticAnalyzer/Checkers/MPI-Checker/MPIFunctionClassifier.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===-- MPIFunctionClassifier.cpp - classifies MPI functions ----*- C++ -*-===// |
2 | | // |
3 | | // The LLVM Compiler Infrastructure |
4 | | // |
5 | | // This file is distributed under the University of Illinois Open Source |
6 | | // License. See LICENSE.TXT for details. |
7 | | // |
8 | | //===----------------------------------------------------------------------===// |
9 | | /// |
10 | | /// \file |
11 | | /// This file defines functionality to identify and classify MPI functions. |
12 | | /// |
13 | | //===----------------------------------------------------------------------===// |
14 | | |
15 | | #include "clang/StaticAnalyzer/Checkers/MPIFunctionClassifier.h" |
16 | | #include "llvm/ADT/STLExtras.h" |
17 | | |
18 | | namespace clang { |
19 | | namespace ento { |
20 | | namespace mpi { |
21 | | |
22 | 3 | void MPIFunctionClassifier::identifierInit(ASTContext &ASTCtx) { |
23 | 3 | // Initialize function identifiers. |
24 | 3 | initPointToPointIdentifiers(ASTCtx); |
25 | 3 | initCollectiveIdentifiers(ASTCtx); |
26 | 3 | initAdditionalIdentifiers(ASTCtx); |
27 | 3 | } |
28 | | |
29 | 3 | void MPIFunctionClassifier::initPointToPointIdentifiers(ASTContext &ASTCtx) { |
30 | 3 | // Copy identifiers into the correct classification containers. |
31 | 3 | IdentInfo_MPI_Send = &ASTCtx.Idents.get("MPI_Send"); |
32 | 3 | MPIPointToPointTypes.push_back(IdentInfo_MPI_Send); |
33 | 3 | MPIType.push_back(IdentInfo_MPI_Send); |
34 | 3 | assert(IdentInfo_MPI_Send); |
35 | 3 | |
36 | 3 | IdentInfo_MPI_Isend = &ASTCtx.Idents.get("MPI_Isend"); |
37 | 3 | MPIPointToPointTypes.push_back(IdentInfo_MPI_Isend); |
38 | 3 | MPINonBlockingTypes.push_back(IdentInfo_MPI_Isend); |
39 | 3 | MPIType.push_back(IdentInfo_MPI_Isend); |
40 | 3 | assert(IdentInfo_MPI_Isend); |
41 | 3 | |
42 | 3 | IdentInfo_MPI_Ssend = &ASTCtx.Idents.get("MPI_Ssend"); |
43 | 3 | MPIPointToPointTypes.push_back(IdentInfo_MPI_Ssend); |
44 | 3 | MPIType.push_back(IdentInfo_MPI_Ssend); |
45 | 3 | assert(IdentInfo_MPI_Ssend); |
46 | 3 | |
47 | 3 | IdentInfo_MPI_Issend = &ASTCtx.Idents.get("MPI_Issend"); |
48 | 3 | MPIPointToPointTypes.push_back(IdentInfo_MPI_Issend); |
49 | 3 | MPINonBlockingTypes.push_back(IdentInfo_MPI_Issend); |
50 | 3 | MPIType.push_back(IdentInfo_MPI_Issend); |
51 | 3 | assert(IdentInfo_MPI_Issend); |
52 | 3 | |
53 | 3 | IdentInfo_MPI_Bsend = &ASTCtx.Idents.get("MPI_Bsend"); |
54 | 3 | MPIPointToPointTypes.push_back(IdentInfo_MPI_Bsend); |
55 | 3 | MPIType.push_back(IdentInfo_MPI_Bsend); |
56 | 3 | assert(IdentInfo_MPI_Bsend); |
57 | 3 | |
58 | 3 | IdentInfo_MPI_Ibsend = &ASTCtx.Idents.get("MPI_Ibsend"); |
59 | 3 | MPIPointToPointTypes.push_back(IdentInfo_MPI_Ibsend); |
60 | 3 | MPINonBlockingTypes.push_back(IdentInfo_MPI_Ibsend); |
61 | 3 | MPIType.push_back(IdentInfo_MPI_Ibsend); |
62 | 3 | assert(IdentInfo_MPI_Ibsend); |
63 | 3 | |
64 | 3 | IdentInfo_MPI_Rsend = &ASTCtx.Idents.get("MPI_Rsend"); |
65 | 3 | MPIPointToPointTypes.push_back(IdentInfo_MPI_Rsend); |
66 | 3 | MPIType.push_back(IdentInfo_MPI_Rsend); |
67 | 3 | assert(IdentInfo_MPI_Rsend); |
68 | 3 | |
69 | 3 | IdentInfo_MPI_Irsend = &ASTCtx.Idents.get("MPI_Irsend"); |
70 | 3 | MPIPointToPointTypes.push_back(IdentInfo_MPI_Irsend); |
71 | 3 | MPIType.push_back(IdentInfo_MPI_Irsend); |
72 | 3 | assert(IdentInfo_MPI_Irsend); |
73 | 3 | |
74 | 3 | IdentInfo_MPI_Recv = &ASTCtx.Idents.get("MPI_Recv"); |
75 | 3 | MPIPointToPointTypes.push_back(IdentInfo_MPI_Recv); |
76 | 3 | MPIType.push_back(IdentInfo_MPI_Recv); |
77 | 3 | assert(IdentInfo_MPI_Recv); |
78 | 3 | |
79 | 3 | IdentInfo_MPI_Irecv = &ASTCtx.Idents.get("MPI_Irecv"); |
80 | 3 | MPIPointToPointTypes.push_back(IdentInfo_MPI_Irecv); |
81 | 3 | MPINonBlockingTypes.push_back(IdentInfo_MPI_Irecv); |
82 | 3 | MPIType.push_back(IdentInfo_MPI_Irecv); |
83 | 3 | assert(IdentInfo_MPI_Irecv); |
84 | 3 | } |
85 | | |
86 | 3 | void MPIFunctionClassifier::initCollectiveIdentifiers(ASTContext &ASTCtx) { |
87 | 3 | // Copy identifiers into the correct classification containers. |
88 | 3 | IdentInfo_MPI_Scatter = &ASTCtx.Idents.get("MPI_Scatter"); |
89 | 3 | MPICollectiveTypes.push_back(IdentInfo_MPI_Scatter); |
90 | 3 | MPIPointToCollTypes.push_back(IdentInfo_MPI_Scatter); |
91 | 3 | MPIType.push_back(IdentInfo_MPI_Scatter); |
92 | 3 | assert(IdentInfo_MPI_Scatter); |
93 | 3 | |
94 | 3 | IdentInfo_MPI_Iscatter = &ASTCtx.Idents.get("MPI_Iscatter"); |
95 | 3 | MPICollectiveTypes.push_back(IdentInfo_MPI_Iscatter); |
96 | 3 | MPIPointToCollTypes.push_back(IdentInfo_MPI_Iscatter); |
97 | 3 | MPINonBlockingTypes.push_back(IdentInfo_MPI_Iscatter); |
98 | 3 | MPIType.push_back(IdentInfo_MPI_Iscatter); |
99 | 3 | assert(IdentInfo_MPI_Iscatter); |
100 | 3 | |
101 | 3 | IdentInfo_MPI_Gather = &ASTCtx.Idents.get("MPI_Gather"); |
102 | 3 | MPICollectiveTypes.push_back(IdentInfo_MPI_Gather); |
103 | 3 | MPICollToPointTypes.push_back(IdentInfo_MPI_Gather); |
104 | 3 | MPIType.push_back(IdentInfo_MPI_Gather); |
105 | 3 | assert(IdentInfo_MPI_Gather); |
106 | 3 | |
107 | 3 | IdentInfo_MPI_Igather = &ASTCtx.Idents.get("MPI_Igather"); |
108 | 3 | MPICollectiveTypes.push_back(IdentInfo_MPI_Igather); |
109 | 3 | MPICollToPointTypes.push_back(IdentInfo_MPI_Igather); |
110 | 3 | MPINonBlockingTypes.push_back(IdentInfo_MPI_Igather); |
111 | 3 | MPIType.push_back(IdentInfo_MPI_Igather); |
112 | 3 | assert(IdentInfo_MPI_Igather); |
113 | 3 | |
114 | 3 | IdentInfo_MPI_Allgather = &ASTCtx.Idents.get("MPI_Allgather"); |
115 | 3 | MPICollectiveTypes.push_back(IdentInfo_MPI_Allgather); |
116 | 3 | MPICollToCollTypes.push_back(IdentInfo_MPI_Allgather); |
117 | 3 | MPIType.push_back(IdentInfo_MPI_Allgather); |
118 | 3 | assert(IdentInfo_MPI_Allgather); |
119 | 3 | |
120 | 3 | IdentInfo_MPI_Iallgather = &ASTCtx.Idents.get("MPI_Iallgather"); |
121 | 3 | MPICollectiveTypes.push_back(IdentInfo_MPI_Iallgather); |
122 | 3 | MPICollToCollTypes.push_back(IdentInfo_MPI_Iallgather); |
123 | 3 | MPINonBlockingTypes.push_back(IdentInfo_MPI_Iallgather); |
124 | 3 | MPIType.push_back(IdentInfo_MPI_Iallgather); |
125 | 3 | assert(IdentInfo_MPI_Iallgather); |
126 | 3 | |
127 | 3 | IdentInfo_MPI_Bcast = &ASTCtx.Idents.get("MPI_Bcast"); |
128 | 3 | MPICollectiveTypes.push_back(IdentInfo_MPI_Bcast); |
129 | 3 | MPIPointToCollTypes.push_back(IdentInfo_MPI_Bcast); |
130 | 3 | MPIType.push_back(IdentInfo_MPI_Bcast); |
131 | 3 | assert(IdentInfo_MPI_Bcast); |
132 | 3 | |
133 | 3 | IdentInfo_MPI_Ibcast = &ASTCtx.Idents.get("MPI_Ibcast"); |
134 | 3 | MPICollectiveTypes.push_back(IdentInfo_MPI_Ibcast); |
135 | 3 | MPIPointToCollTypes.push_back(IdentInfo_MPI_Ibcast); |
136 | 3 | MPINonBlockingTypes.push_back(IdentInfo_MPI_Ibcast); |
137 | 3 | MPIType.push_back(IdentInfo_MPI_Ibcast); |
138 | 3 | assert(IdentInfo_MPI_Ibcast); |
139 | 3 | |
140 | 3 | IdentInfo_MPI_Reduce = &ASTCtx.Idents.get("MPI_Reduce"); |
141 | 3 | MPICollectiveTypes.push_back(IdentInfo_MPI_Reduce); |
142 | 3 | MPICollToPointTypes.push_back(IdentInfo_MPI_Reduce); |
143 | 3 | MPIType.push_back(IdentInfo_MPI_Reduce); |
144 | 3 | assert(IdentInfo_MPI_Reduce); |
145 | 3 | |
146 | 3 | IdentInfo_MPI_Ireduce = &ASTCtx.Idents.get("MPI_Ireduce"); |
147 | 3 | MPICollectiveTypes.push_back(IdentInfo_MPI_Ireduce); |
148 | 3 | MPICollToPointTypes.push_back(IdentInfo_MPI_Ireduce); |
149 | 3 | MPINonBlockingTypes.push_back(IdentInfo_MPI_Ireduce); |
150 | 3 | MPIType.push_back(IdentInfo_MPI_Ireduce); |
151 | 3 | assert(IdentInfo_MPI_Ireduce); |
152 | 3 | |
153 | 3 | IdentInfo_MPI_Allreduce = &ASTCtx.Idents.get("MPI_Allreduce"); |
154 | 3 | MPICollectiveTypes.push_back(IdentInfo_MPI_Allreduce); |
155 | 3 | MPICollToCollTypes.push_back(IdentInfo_MPI_Allreduce); |
156 | 3 | MPIType.push_back(IdentInfo_MPI_Allreduce); |
157 | 3 | assert(IdentInfo_MPI_Allreduce); |
158 | 3 | |
159 | 3 | IdentInfo_MPI_Iallreduce = &ASTCtx.Idents.get("MPI_Iallreduce"); |
160 | 3 | MPICollectiveTypes.push_back(IdentInfo_MPI_Iallreduce); |
161 | 3 | MPICollToCollTypes.push_back(IdentInfo_MPI_Iallreduce); |
162 | 3 | MPINonBlockingTypes.push_back(IdentInfo_MPI_Iallreduce); |
163 | 3 | MPIType.push_back(IdentInfo_MPI_Iallreduce); |
164 | 3 | assert(IdentInfo_MPI_Iallreduce); |
165 | 3 | |
166 | 3 | IdentInfo_MPI_Alltoall = &ASTCtx.Idents.get("MPI_Alltoall"); |
167 | 3 | MPICollectiveTypes.push_back(IdentInfo_MPI_Alltoall); |
168 | 3 | MPICollToCollTypes.push_back(IdentInfo_MPI_Alltoall); |
169 | 3 | MPIType.push_back(IdentInfo_MPI_Alltoall); |
170 | 3 | assert(IdentInfo_MPI_Alltoall); |
171 | 3 | |
172 | 3 | IdentInfo_MPI_Ialltoall = &ASTCtx.Idents.get("MPI_Ialltoall"); |
173 | 3 | MPICollectiveTypes.push_back(IdentInfo_MPI_Ialltoall); |
174 | 3 | MPICollToCollTypes.push_back(IdentInfo_MPI_Ialltoall); |
175 | 3 | MPINonBlockingTypes.push_back(IdentInfo_MPI_Ialltoall); |
176 | 3 | MPIType.push_back(IdentInfo_MPI_Ialltoall); |
177 | 3 | assert(IdentInfo_MPI_Ialltoall); |
178 | 3 | } |
179 | | |
180 | 3 | void MPIFunctionClassifier::initAdditionalIdentifiers(ASTContext &ASTCtx) { |
181 | 3 | IdentInfo_MPI_Comm_rank = &ASTCtx.Idents.get("MPI_Comm_rank"); |
182 | 3 | MPIType.push_back(IdentInfo_MPI_Comm_rank); |
183 | 3 | assert(IdentInfo_MPI_Comm_rank); |
184 | 3 | |
185 | 3 | IdentInfo_MPI_Comm_size = &ASTCtx.Idents.get("MPI_Comm_size"); |
186 | 3 | MPIType.push_back(IdentInfo_MPI_Comm_size); |
187 | 3 | assert(IdentInfo_MPI_Comm_size); |
188 | 3 | |
189 | 3 | IdentInfo_MPI_Wait = &ASTCtx.Idents.get("MPI_Wait"); |
190 | 3 | MPIType.push_back(IdentInfo_MPI_Wait); |
191 | 3 | assert(IdentInfo_MPI_Wait); |
192 | 3 | |
193 | 3 | IdentInfo_MPI_Waitall = &ASTCtx.Idents.get("MPI_Waitall"); |
194 | 3 | MPIType.push_back(IdentInfo_MPI_Waitall); |
195 | 3 | assert(IdentInfo_MPI_Waitall); |
196 | 3 | |
197 | 3 | IdentInfo_MPI_Barrier = &ASTCtx.Idents.get("MPI_Barrier"); |
198 | 3 | MPICollectiveTypes.push_back(IdentInfo_MPI_Barrier); |
199 | 3 | MPIType.push_back(IdentInfo_MPI_Barrier); |
200 | 3 | assert(IdentInfo_MPI_Barrier); |
201 | 3 | } |
202 | | |
203 | | // general identifiers |
204 | 0 | bool MPIFunctionClassifier::isMPIType(const IdentifierInfo *IdentInfo) const { |
205 | 0 | return llvm::is_contained(MPIType, IdentInfo); |
206 | 0 | } |
207 | | |
208 | | bool MPIFunctionClassifier::isNonBlockingType( |
209 | 131 | const IdentifierInfo *IdentInfo) const { |
210 | 131 | return llvm::is_contained(MPINonBlockingTypes, IdentInfo); |
211 | 131 | } |
212 | | |
213 | | // point-to-point identifiers |
214 | | bool MPIFunctionClassifier::isPointToPointType( |
215 | 0 | const IdentifierInfo *IdentInfo) const { |
216 | 0 | return llvm::is_contained(MPIPointToPointTypes, IdentInfo); |
217 | 0 | } |
218 | | |
219 | | // collective identifiers |
220 | | bool MPIFunctionClassifier::isCollectiveType( |
221 | 0 | const IdentifierInfo *IdentInfo) const { |
222 | 0 | return llvm::is_contained(MPICollectiveTypes, IdentInfo); |
223 | 0 | } |
224 | | |
225 | | bool MPIFunctionClassifier::isCollToColl( |
226 | 0 | const IdentifierInfo *IdentInfo) const { |
227 | 0 | return llvm::is_contained(MPICollToCollTypes, IdentInfo); |
228 | 0 | } |
229 | | |
230 | | bool MPIFunctionClassifier::isScatterType( |
231 | 0 | const IdentifierInfo *IdentInfo) const { |
232 | 0 | return IdentInfo == IdentInfo_MPI_Scatter || |
233 | 0 | IdentInfo == IdentInfo_MPI_Iscatter; |
234 | 0 | } |
235 | | |
236 | | bool MPIFunctionClassifier::isGatherType( |
237 | 0 | const IdentifierInfo *IdentInfo) const { |
238 | 0 | return IdentInfo == IdentInfo_MPI_Gather || |
239 | 0 | IdentInfo == IdentInfo_MPI_Igather || |
240 | 0 | IdentInfo == IdentInfo_MPI_Allgather || |
241 | 0 | IdentInfo == IdentInfo_MPI_Iallgather; |
242 | 0 | } |
243 | | |
244 | | bool MPIFunctionClassifier::isAllgatherType( |
245 | 0 | const IdentifierInfo *IdentInfo) const { |
246 | 0 | return IdentInfo == IdentInfo_MPI_Allgather || |
247 | 0 | IdentInfo == IdentInfo_MPI_Iallgather; |
248 | 0 | } |
249 | | |
250 | | bool MPIFunctionClassifier::isAlltoallType( |
251 | 0 | const IdentifierInfo *IdentInfo) const { |
252 | 0 | return IdentInfo == IdentInfo_MPI_Alltoall || |
253 | 0 | IdentInfo == IdentInfo_MPI_Ialltoall; |
254 | 0 | } |
255 | | |
256 | 0 | bool MPIFunctionClassifier::isBcastType(const IdentifierInfo *IdentInfo) const { |
257 | 0 | return IdentInfo == IdentInfo_MPI_Bcast || IdentInfo == IdentInfo_MPI_Ibcast; |
258 | 0 | } |
259 | | |
260 | | bool MPIFunctionClassifier::isReduceType( |
261 | 0 | const IdentifierInfo *IdentInfo) const { |
262 | 0 | return IdentInfo == IdentInfo_MPI_Reduce || |
263 | 0 | IdentInfo == IdentInfo_MPI_Ireduce || |
264 | 0 | IdentInfo == IdentInfo_MPI_Allreduce || |
265 | 0 | IdentInfo == IdentInfo_MPI_Iallreduce; |
266 | 0 | } |
267 | | |
268 | | // additional identifiers |
269 | 84 | bool MPIFunctionClassifier::isMPI_Wait(const IdentifierInfo *IdentInfo) const { |
270 | 84 | return IdentInfo == IdentInfo_MPI_Wait; |
271 | 84 | } |
272 | | |
273 | | bool MPIFunctionClassifier::isMPI_Waitall( |
274 | 51 | const IdentifierInfo *IdentInfo) const { |
275 | 51 | return IdentInfo == IdentInfo_MPI_Waitall; |
276 | 51 | } |
277 | | |
278 | 131 | bool MPIFunctionClassifier::isWaitType(const IdentifierInfo *IdentInfo) const { |
279 | 92 | return IdentInfo == IdentInfo_MPI_Wait || IdentInfo == IdentInfo_MPI_Waitall; |
280 | 131 | } |
281 | | |
282 | | } // end of namespace: mpi |
283 | | } // end of namespace: ento |
284 | | } // end of namespace: clang |