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