clang 24.0.0git
MPIFunctionClassifier.cpp
Go to the documentation of this file.
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
15#include "llvm/ADT/STLExtras.h"
16
17namespace clang {
18namespace ento {
19namespace mpi {
20
21void MPIFunctionClassifier::identifierInit(ASTContext &ASTCtx) {
22 // Initialize function identifiers.
23 initPointToPointIdentifiers(ASTCtx);
24 initCollectiveIdentifiers(ASTCtx);
25 initAdditionalIdentifiers(ASTCtx);
26}
27
28void MPIFunctionClassifier::initPointToPointIdentifiers(ASTContext &ASTCtx) {
29 // Copy identifiers into the correct classification containers.
30 IdentInfo_MPI_Send = &ASTCtx.Idents.get("MPI_Send");
31 MPIPointToPointTypes.push_back(IdentInfo_MPI_Send);
32 MPIType.push_back(IdentInfo_MPI_Send);
33 assert(IdentInfo_MPI_Send);
34
35 IdentInfo_MPI_Isend = &ASTCtx.Idents.get("MPI_Isend");
36 MPIPointToPointTypes.push_back(IdentInfo_MPI_Isend);
37 MPINonBlockingTypes.push_back(IdentInfo_MPI_Isend);
38 MPIType.push_back(IdentInfo_MPI_Isend);
39 assert(IdentInfo_MPI_Isend);
40
41 IdentInfo_MPI_Ssend = &ASTCtx.Idents.get("MPI_Ssend");
42 MPIPointToPointTypes.push_back(IdentInfo_MPI_Ssend);
43 MPIType.push_back(IdentInfo_MPI_Ssend);
44 assert(IdentInfo_MPI_Ssend);
45
46 IdentInfo_MPI_Issend = &ASTCtx.Idents.get("MPI_Issend");
47 MPIPointToPointTypes.push_back(IdentInfo_MPI_Issend);
48 MPINonBlockingTypes.push_back(IdentInfo_MPI_Issend);
49 MPIType.push_back(IdentInfo_MPI_Issend);
50 assert(IdentInfo_MPI_Issend);
51
52 IdentInfo_MPI_Bsend = &ASTCtx.Idents.get("MPI_Bsend");
53 MPIPointToPointTypes.push_back(IdentInfo_MPI_Bsend);
54 MPIType.push_back(IdentInfo_MPI_Bsend);
55 assert(IdentInfo_MPI_Bsend);
56
57 IdentInfo_MPI_Ibsend = &ASTCtx.Idents.get("MPI_Ibsend");
58 MPIPointToPointTypes.push_back(IdentInfo_MPI_Ibsend);
59 MPINonBlockingTypes.push_back(IdentInfo_MPI_Ibsend);
60 MPIType.push_back(IdentInfo_MPI_Ibsend);
61 assert(IdentInfo_MPI_Ibsend);
62
63 IdentInfo_MPI_Rsend = &ASTCtx.Idents.get("MPI_Rsend");
64 MPIPointToPointTypes.push_back(IdentInfo_MPI_Rsend);
65 MPIType.push_back(IdentInfo_MPI_Rsend);
66 assert(IdentInfo_MPI_Rsend);
67
68 IdentInfo_MPI_Irsend = &ASTCtx.Idents.get("MPI_Irsend");
69 MPIPointToPointTypes.push_back(IdentInfo_MPI_Irsend);
70 MPIType.push_back(IdentInfo_MPI_Irsend);
71 assert(IdentInfo_MPI_Irsend);
72
73 IdentInfo_MPI_Recv = &ASTCtx.Idents.get("MPI_Recv");
74 MPIPointToPointTypes.push_back(IdentInfo_MPI_Recv);
75 MPIType.push_back(IdentInfo_MPI_Recv);
76 assert(IdentInfo_MPI_Recv);
77
78 IdentInfo_MPI_Irecv = &ASTCtx.Idents.get("MPI_Irecv");
79 MPIPointToPointTypes.push_back(IdentInfo_MPI_Irecv);
80 MPINonBlockingTypes.push_back(IdentInfo_MPI_Irecv);
81 MPIType.push_back(IdentInfo_MPI_Irecv);
82 assert(IdentInfo_MPI_Irecv);
83}
84
85void MPIFunctionClassifier::initCollectiveIdentifiers(ASTContext &ASTCtx) {
86 // Copy identifiers into the correct classification containers.
87 IdentInfo_MPI_Scatter = &ASTCtx.Idents.get("MPI_Scatter");
88 MPICollectiveTypes.push_back(IdentInfo_MPI_Scatter);
89 MPIPointToCollTypes.push_back(IdentInfo_MPI_Scatter);
90 MPIType.push_back(IdentInfo_MPI_Scatter);
91 assert(IdentInfo_MPI_Scatter);
92
93 IdentInfo_MPI_Iscatter = &ASTCtx.Idents.get("MPI_Iscatter");
94 MPICollectiveTypes.push_back(IdentInfo_MPI_Iscatter);
95 MPIPointToCollTypes.push_back(IdentInfo_MPI_Iscatter);
96 MPINonBlockingTypes.push_back(IdentInfo_MPI_Iscatter);
97 MPIType.push_back(IdentInfo_MPI_Iscatter);
98 assert(IdentInfo_MPI_Iscatter);
99
100 IdentInfo_MPI_Gather = &ASTCtx.Idents.get("MPI_Gather");
101 MPICollectiveTypes.push_back(IdentInfo_MPI_Gather);
102 MPICollToPointTypes.push_back(IdentInfo_MPI_Gather);
103 MPIType.push_back(IdentInfo_MPI_Gather);
104 assert(IdentInfo_MPI_Gather);
105
106 IdentInfo_MPI_Igather = &ASTCtx.Idents.get("MPI_Igather");
107 MPICollectiveTypes.push_back(IdentInfo_MPI_Igather);
108 MPICollToPointTypes.push_back(IdentInfo_MPI_Igather);
109 MPINonBlockingTypes.push_back(IdentInfo_MPI_Igather);
110 MPIType.push_back(IdentInfo_MPI_Igather);
111 assert(IdentInfo_MPI_Igather);
112
113 IdentInfo_MPI_Allgather = &ASTCtx.Idents.get("MPI_Allgather");
114 MPICollectiveTypes.push_back(IdentInfo_MPI_Allgather);
115 MPICollToCollTypes.push_back(IdentInfo_MPI_Allgather);
116 MPIType.push_back(IdentInfo_MPI_Allgather);
117 assert(IdentInfo_MPI_Allgather);
118
119 IdentInfo_MPI_Iallgather = &ASTCtx.Idents.get("MPI_Iallgather");
120 MPICollectiveTypes.push_back(IdentInfo_MPI_Iallgather);
121 MPICollToCollTypes.push_back(IdentInfo_MPI_Iallgather);
122 MPINonBlockingTypes.push_back(IdentInfo_MPI_Iallgather);
123 MPIType.push_back(IdentInfo_MPI_Iallgather);
124 assert(IdentInfo_MPI_Iallgather);
125
126 IdentInfo_MPI_Bcast = &ASTCtx.Idents.get("MPI_Bcast");
127 MPICollectiveTypes.push_back(IdentInfo_MPI_Bcast);
128 MPIPointToCollTypes.push_back(IdentInfo_MPI_Bcast);
129 MPIType.push_back(IdentInfo_MPI_Bcast);
130 assert(IdentInfo_MPI_Bcast);
131
132 IdentInfo_MPI_Ibcast = &ASTCtx.Idents.get("MPI_Ibcast");
133 MPICollectiveTypes.push_back(IdentInfo_MPI_Ibcast);
134 MPIPointToCollTypes.push_back(IdentInfo_MPI_Ibcast);
135 MPINonBlockingTypes.push_back(IdentInfo_MPI_Ibcast);
136 MPIType.push_back(IdentInfo_MPI_Ibcast);
137 assert(IdentInfo_MPI_Ibcast);
138
139 IdentInfo_MPI_Reduce = &ASTCtx.Idents.get("MPI_Reduce");
140 MPICollectiveTypes.push_back(IdentInfo_MPI_Reduce);
141 MPICollToPointTypes.push_back(IdentInfo_MPI_Reduce);
142 MPIType.push_back(IdentInfo_MPI_Reduce);
143 assert(IdentInfo_MPI_Reduce);
144
145 IdentInfo_MPI_Ireduce = &ASTCtx.Idents.get("MPI_Ireduce");
146 MPICollectiveTypes.push_back(IdentInfo_MPI_Ireduce);
147 MPICollToPointTypes.push_back(IdentInfo_MPI_Ireduce);
148 MPINonBlockingTypes.push_back(IdentInfo_MPI_Ireduce);
149 MPIType.push_back(IdentInfo_MPI_Ireduce);
150 assert(IdentInfo_MPI_Ireduce);
151
152 IdentInfo_MPI_Allreduce = &ASTCtx.Idents.get("MPI_Allreduce");
153 MPICollectiveTypes.push_back(IdentInfo_MPI_Allreduce);
154 MPICollToCollTypes.push_back(IdentInfo_MPI_Allreduce);
155 MPIType.push_back(IdentInfo_MPI_Allreduce);
156 assert(IdentInfo_MPI_Allreduce);
157
158 IdentInfo_MPI_Iallreduce = &ASTCtx.Idents.get("MPI_Iallreduce");
159 MPICollectiveTypes.push_back(IdentInfo_MPI_Iallreduce);
160 MPICollToCollTypes.push_back(IdentInfo_MPI_Iallreduce);
161 MPINonBlockingTypes.push_back(IdentInfo_MPI_Iallreduce);
162 MPIType.push_back(IdentInfo_MPI_Iallreduce);
163 assert(IdentInfo_MPI_Iallreduce);
164
165 IdentInfo_MPI_Alltoall = &ASTCtx.Idents.get("MPI_Alltoall");
166 MPICollectiveTypes.push_back(IdentInfo_MPI_Alltoall);
167 MPICollToCollTypes.push_back(IdentInfo_MPI_Alltoall);
168 MPIType.push_back(IdentInfo_MPI_Alltoall);
169 assert(IdentInfo_MPI_Alltoall);
170
171 IdentInfo_MPI_Ialltoall = &ASTCtx.Idents.get("MPI_Ialltoall");
172 MPICollectiveTypes.push_back(IdentInfo_MPI_Ialltoall);
173 MPICollToCollTypes.push_back(IdentInfo_MPI_Ialltoall);
174 MPINonBlockingTypes.push_back(IdentInfo_MPI_Ialltoall);
175 MPIType.push_back(IdentInfo_MPI_Ialltoall);
176 assert(IdentInfo_MPI_Ialltoall);
177
178 auto AddCollective = [&](StringRef Name) {
179 IdentifierInfo *II = &ASTCtx.Idents.get(Name);
180 MPICollectiveTypes.push_back(II);
181 MPIType.push_back(II);
182 return II;
183 };
184 auto AddNonBlockingCollective = [&](StringRef Name) {
185 MPINonBlockingTypes.push_back(AddCollective(Name));
186 };
187
188 // Vector ("v"/"w") variants of the collectives above.
189 AddCollective("MPI_Scatterv");
190 AddNonBlockingCollective("MPI_Iscatterv");
191 AddCollective("MPI_Gatherv");
192 AddNonBlockingCollective("MPI_Igatherv");
193 AddCollective("MPI_Allgatherv");
194 AddNonBlockingCollective("MPI_Iallgatherv");
195 AddCollective("MPI_Alltoallv");
196 AddNonBlockingCollective("MPI_Ialltoallv");
197 AddCollective("MPI_Alltoallw");
198 AddNonBlockingCollective("MPI_Ialltoallw");
199
200 // Nonblocking barrier.
201 AddNonBlockingCollective("MPI_Ibarrier");
202
203 // Prefix reductions (scans).
204 AddCollective("MPI_Scan");
205 AddNonBlockingCollective("MPI_Iscan");
206 AddCollective("MPI_Exscan");
207 AddNonBlockingCollective("MPI_Iexscan");
208
209 // Reduce-scatter family.
210 AddCollective("MPI_Reduce_scatter");
211 AddNonBlockingCollective("MPI_Ireduce_scatter");
212 AddCollective("MPI_Reduce_scatter_block");
213 AddNonBlockingCollective("MPI_Ireduce_scatter_block");
214}
215
216void MPIFunctionClassifier::initAdditionalIdentifiers(ASTContext &ASTCtx) {
217 IdentInfo_MPI_Comm_rank = &ASTCtx.Idents.get("MPI_Comm_rank");
218 MPIType.push_back(IdentInfo_MPI_Comm_rank);
219 assert(IdentInfo_MPI_Comm_rank);
220
221 IdentInfo_MPI_Comm_size = &ASTCtx.Idents.get("MPI_Comm_size");
222 MPIType.push_back(IdentInfo_MPI_Comm_size);
223 assert(IdentInfo_MPI_Comm_size);
224
225 IdentInfo_MPI_Wait = &ASTCtx.Idents.get("MPI_Wait");
226 MPIType.push_back(IdentInfo_MPI_Wait);
227 assert(IdentInfo_MPI_Wait);
228
229 IdentInfo_MPI_Waitall = &ASTCtx.Idents.get("MPI_Waitall");
230 MPIType.push_back(IdentInfo_MPI_Waitall);
231 assert(IdentInfo_MPI_Waitall);
232
233 IdentInfo_MPI_Barrier = &ASTCtx.Idents.get("MPI_Barrier");
234 MPICollectiveTypes.push_back(IdentInfo_MPI_Barrier);
235 MPIType.push_back(IdentInfo_MPI_Barrier);
236 assert(IdentInfo_MPI_Barrier);
237}
238
239// general identifiers
241 return llvm::is_contained(MPIType, IdentInfo);
242}
243
245 const IdentifierInfo *IdentInfo) const {
246 return llvm::is_contained(MPINonBlockingTypes, IdentInfo);
247}
248
249// point-to-point identifiers
251 const IdentifierInfo *IdentInfo) const {
252 return llvm::is_contained(MPIPointToPointTypes, IdentInfo);
253}
254
255// collective identifiers
257 const IdentifierInfo *IdentInfo) const {
258 return llvm::is_contained(MPICollectiveTypes, IdentInfo);
259}
260
262 const IdentifierInfo *IdentInfo) const {
263 return llvm::is_contained(MPICollToCollTypes, IdentInfo);
264}
265
267 const IdentifierInfo *IdentInfo) const {
268 return IdentInfo == IdentInfo_MPI_Scatter ||
269 IdentInfo == IdentInfo_MPI_Iscatter;
270}
271
273 const IdentifierInfo *IdentInfo) const {
274 return IdentInfo == IdentInfo_MPI_Gather ||
275 IdentInfo == IdentInfo_MPI_Igather ||
276 IdentInfo == IdentInfo_MPI_Allgather ||
277 IdentInfo == IdentInfo_MPI_Iallgather;
278}
279
281 const IdentifierInfo *IdentInfo) const {
282 return IdentInfo == IdentInfo_MPI_Allgather ||
283 IdentInfo == IdentInfo_MPI_Iallgather;
284}
285
287 const IdentifierInfo *IdentInfo) const {
288 return IdentInfo == IdentInfo_MPI_Alltoall ||
289 IdentInfo == IdentInfo_MPI_Ialltoall;
290}
291
293 return IdentInfo == IdentInfo_MPI_Bcast || IdentInfo == IdentInfo_MPI_Ibcast;
294}
295
297 const IdentifierInfo *IdentInfo) const {
298 return IdentInfo == IdentInfo_MPI_Reduce ||
299 IdentInfo == IdentInfo_MPI_Ireduce ||
300 IdentInfo == IdentInfo_MPI_Allreduce ||
301 IdentInfo == IdentInfo_MPI_Iallreduce;
302}
303
304// additional identifiers
306 return IdentInfo == IdentInfo_MPI_Wait;
307}
308
310 const IdentifierInfo *IdentInfo) const {
311 return IdentInfo == IdentInfo_MPI_Waitall;
312}
313
315 return IdentInfo == IdentInfo_MPI_Wait || IdentInfo == IdentInfo_MPI_Waitall;
316}
317
318} // end of namespace: mpi
319} // end of namespace: ento
320} // end of namespace: clang
This file defines functionality to identify and classify MPI functions.
IdentifierTable & Idents
Definition ASTContext.h:808
One of these records is kept for each identifier that is lexed.
bool isAlltoallType(const IdentifierInfo *const IdentInfo) const
bool isNonBlockingType(const IdentifierInfo *const IdentInfo) const
bool isReduceType(const IdentifierInfo *const IdentInfo) const
bool isAllgatherType(const IdentifierInfo *const IdentInfo) const
bool isBcastType(const IdentifierInfo *const IdentInfo) const
bool isWaitType(const IdentifierInfo *const IdentInfo) const
bool isGatherType(const IdentifierInfo *const IdentInfo) const
bool isMPIType(const IdentifierInfo *const IdentInfo) const
bool isScatterType(const IdentifierInfo *const IdentInfo) const
bool isCollToColl(const IdentifierInfo *const IdentInfo) const
bool isMPI_Waitall(const IdentifierInfo *const IdentInfo) const
bool isPointToPointType(const IdentifierInfo *const IdentInfo) const
bool isMPI_Wait(const IdentifierInfo *const IdentInfo) const
bool isCollectiveType(const IdentifierInfo *const IdentInfo) const
The JSON file list parser is used to communicate input to InstallAPI.