1 //===-- MPIFunctionClassifier.cpp - classifies MPI functions ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// This file defines functionality to identify and classify MPI functions.
13 //===----------------------------------------------------------------------===//
15 #include "MPIFunctionClassifier.h"
16 #include "llvm/ADT/STLExtras.h"
22 void MPIFunctionClassifier::identifierInit(ASTContext &ASTCtx) {
23 // Initialize function identifiers.
24 initPointToPointIdentifiers(ASTCtx);
25 initCollectiveIdentifiers(ASTCtx);
26 initAdditionalIdentifiers(ASTCtx);
29 void MPIFunctionClassifier::initPointToPointIdentifiers(ASTContext &ASTCtx) {
30 // Copy identifiers into the correct classification containers.
31 IdentInfo_MPI_Send = &ASTCtx.Idents.get("MPI_Send");
32 MPIPointToPointTypes.push_back(IdentInfo_MPI_Send);
33 MPIType.push_back(IdentInfo_MPI_Send);
34 assert(IdentInfo_MPI_Send);
36 IdentInfo_MPI_Isend = &ASTCtx.Idents.get("MPI_Isend");
37 MPIPointToPointTypes.push_back(IdentInfo_MPI_Isend);
38 MPINonBlockingTypes.push_back(IdentInfo_MPI_Isend);
39 MPIType.push_back(IdentInfo_MPI_Isend);
40 assert(IdentInfo_MPI_Isend);
42 IdentInfo_MPI_Ssend = &ASTCtx.Idents.get("MPI_Ssend");
43 MPIPointToPointTypes.push_back(IdentInfo_MPI_Ssend);
44 MPIType.push_back(IdentInfo_MPI_Ssend);
45 assert(IdentInfo_MPI_Ssend);
47 IdentInfo_MPI_Issend = &ASTCtx.Idents.get("MPI_Issend");
48 MPIPointToPointTypes.push_back(IdentInfo_MPI_Issend);
49 MPINonBlockingTypes.push_back(IdentInfo_MPI_Issend);
50 MPIType.push_back(IdentInfo_MPI_Issend);
51 assert(IdentInfo_MPI_Issend);
53 IdentInfo_MPI_Bsend = &ASTCtx.Idents.get("MPI_Bsend");
54 MPIPointToPointTypes.push_back(IdentInfo_MPI_Bsend);
55 MPIType.push_back(IdentInfo_MPI_Bsend);
56 assert(IdentInfo_MPI_Bsend);
58 IdentInfo_MPI_Ibsend = &ASTCtx.Idents.get("MPI_Ibsend");
59 MPIPointToPointTypes.push_back(IdentInfo_MPI_Ibsend);
60 MPINonBlockingTypes.push_back(IdentInfo_MPI_Ibsend);
61 MPIType.push_back(IdentInfo_MPI_Ibsend);
62 assert(IdentInfo_MPI_Ibsend);
64 IdentInfo_MPI_Rsend = &ASTCtx.Idents.get("MPI_Rsend");
65 MPIPointToPointTypes.push_back(IdentInfo_MPI_Rsend);
66 MPIType.push_back(IdentInfo_MPI_Rsend);
67 assert(IdentInfo_MPI_Rsend);
69 IdentInfo_MPI_Irsend = &ASTCtx.Idents.get("MPI_Irsend");
70 MPIPointToPointTypes.push_back(IdentInfo_MPI_Irsend);
71 MPIType.push_back(IdentInfo_MPI_Irsend);
72 assert(IdentInfo_MPI_Irsend);
74 IdentInfo_MPI_Recv = &ASTCtx.Idents.get("MPI_Recv");
75 MPIPointToPointTypes.push_back(IdentInfo_MPI_Recv);
76 MPIType.push_back(IdentInfo_MPI_Recv);
77 assert(IdentInfo_MPI_Recv);
79 IdentInfo_MPI_Irecv = &ASTCtx.Idents.get("MPI_Irecv");
80 MPIPointToPointTypes.push_back(IdentInfo_MPI_Irecv);
81 MPINonBlockingTypes.push_back(IdentInfo_MPI_Irecv);
82 MPIType.push_back(IdentInfo_MPI_Irecv);
83 assert(IdentInfo_MPI_Irecv);
86 void MPIFunctionClassifier::initCollectiveIdentifiers(ASTContext &ASTCtx) {
87 // Copy identifiers into the correct classification containers.
88 IdentInfo_MPI_Scatter = &ASTCtx.Idents.get("MPI_Scatter");
89 MPICollectiveTypes.push_back(IdentInfo_MPI_Scatter);
90 MPIPointToCollTypes.push_back(IdentInfo_MPI_Scatter);
91 MPIType.push_back(IdentInfo_MPI_Scatter);
92 assert(IdentInfo_MPI_Scatter);
94 IdentInfo_MPI_Iscatter = &ASTCtx.Idents.get("MPI_Iscatter");
95 MPICollectiveTypes.push_back(IdentInfo_MPI_Iscatter);
96 MPIPointToCollTypes.push_back(IdentInfo_MPI_Iscatter);
97 MPINonBlockingTypes.push_back(IdentInfo_MPI_Iscatter);
98 MPIType.push_back(IdentInfo_MPI_Iscatter);
99 assert(IdentInfo_MPI_Iscatter);
101 IdentInfo_MPI_Gather = &ASTCtx.Idents.get("MPI_Gather");
102 MPICollectiveTypes.push_back(IdentInfo_MPI_Gather);
103 MPICollToPointTypes.push_back(IdentInfo_MPI_Gather);
104 MPIType.push_back(IdentInfo_MPI_Gather);
105 assert(IdentInfo_MPI_Gather);
107 IdentInfo_MPI_Igather = &ASTCtx.Idents.get("MPI_Igather");
108 MPICollectiveTypes.push_back(IdentInfo_MPI_Igather);
109 MPICollToPointTypes.push_back(IdentInfo_MPI_Igather);
110 MPINonBlockingTypes.push_back(IdentInfo_MPI_Igather);
111 MPIType.push_back(IdentInfo_MPI_Igather);
112 assert(IdentInfo_MPI_Igather);
114 IdentInfo_MPI_Allgather = &ASTCtx.Idents.get("MPI_Allgather");
115 MPICollectiveTypes.push_back(IdentInfo_MPI_Allgather);
116 MPICollToCollTypes.push_back(IdentInfo_MPI_Allgather);
117 MPIType.push_back(IdentInfo_MPI_Allgather);
118 assert(IdentInfo_MPI_Allgather);
120 IdentInfo_MPI_Iallgather = &ASTCtx.Idents.get("MPI_Iallgather");
121 MPICollectiveTypes.push_back(IdentInfo_MPI_Iallgather);
122 MPICollToCollTypes.push_back(IdentInfo_MPI_Iallgather);
123 MPINonBlockingTypes.push_back(IdentInfo_MPI_Iallgather);
124 MPIType.push_back(IdentInfo_MPI_Iallgather);
125 assert(IdentInfo_MPI_Iallgather);
127 IdentInfo_MPI_Bcast = &ASTCtx.Idents.get("MPI_Bcast");
128 MPICollectiveTypes.push_back(IdentInfo_MPI_Bcast);
129 MPIPointToCollTypes.push_back(IdentInfo_MPI_Bcast);
130 MPIType.push_back(IdentInfo_MPI_Bcast);
131 assert(IdentInfo_MPI_Bcast);
133 IdentInfo_MPI_Ibcast = &ASTCtx.Idents.get("MPI_Ibcast");
134 MPICollectiveTypes.push_back(IdentInfo_MPI_Ibcast);
135 MPIPointToCollTypes.push_back(IdentInfo_MPI_Ibcast);
136 MPINonBlockingTypes.push_back(IdentInfo_MPI_Ibcast);
137 MPIType.push_back(IdentInfo_MPI_Ibcast);
138 assert(IdentInfo_MPI_Ibcast);
140 IdentInfo_MPI_Reduce = &ASTCtx.Idents.get("MPI_Reduce");
141 MPICollectiveTypes.push_back(IdentInfo_MPI_Reduce);
142 MPICollToPointTypes.push_back(IdentInfo_MPI_Reduce);
143 MPIType.push_back(IdentInfo_MPI_Reduce);
144 assert(IdentInfo_MPI_Reduce);
146 IdentInfo_MPI_Ireduce = &ASTCtx.Idents.get("MPI_Ireduce");
147 MPICollectiveTypes.push_back(IdentInfo_MPI_Ireduce);
148 MPICollToPointTypes.push_back(IdentInfo_MPI_Ireduce);
149 MPINonBlockingTypes.push_back(IdentInfo_MPI_Ireduce);
150 MPIType.push_back(IdentInfo_MPI_Ireduce);
151 assert(IdentInfo_MPI_Ireduce);
153 IdentInfo_MPI_Allreduce = &ASTCtx.Idents.get("MPI_Allreduce");
154 MPICollectiveTypes.push_back(IdentInfo_MPI_Allreduce);
155 MPICollToCollTypes.push_back(IdentInfo_MPI_Allreduce);
156 MPIType.push_back(IdentInfo_MPI_Allreduce);
157 assert(IdentInfo_MPI_Allreduce);
159 IdentInfo_MPI_Iallreduce = &ASTCtx.Idents.get("MPI_Iallreduce");
160 MPICollectiveTypes.push_back(IdentInfo_MPI_Iallreduce);
161 MPICollToCollTypes.push_back(IdentInfo_MPI_Iallreduce);
162 MPINonBlockingTypes.push_back(IdentInfo_MPI_Iallreduce);
163 MPIType.push_back(IdentInfo_MPI_Iallreduce);
164 assert(IdentInfo_MPI_Iallreduce);
166 IdentInfo_MPI_Alltoall = &ASTCtx.Idents.get("MPI_Alltoall");
167 MPICollectiveTypes.push_back(IdentInfo_MPI_Alltoall);
168 MPICollToCollTypes.push_back(IdentInfo_MPI_Alltoall);
169 MPIType.push_back(IdentInfo_MPI_Alltoall);
170 assert(IdentInfo_MPI_Alltoall);
172 IdentInfo_MPI_Ialltoall = &ASTCtx.Idents.get("MPI_Ialltoall");
173 MPICollectiveTypes.push_back(IdentInfo_MPI_Ialltoall);
174 MPICollToCollTypes.push_back(IdentInfo_MPI_Ialltoall);
175 MPINonBlockingTypes.push_back(IdentInfo_MPI_Ialltoall);
176 MPIType.push_back(IdentInfo_MPI_Ialltoall);
177 assert(IdentInfo_MPI_Ialltoall);
180 void MPIFunctionClassifier::initAdditionalIdentifiers(ASTContext &ASTCtx) {
181 IdentInfo_MPI_Comm_rank = &ASTCtx.Idents.get("MPI_Comm_rank");
182 MPIType.push_back(IdentInfo_MPI_Comm_rank);
183 assert(IdentInfo_MPI_Comm_rank);
185 IdentInfo_MPI_Comm_size = &ASTCtx.Idents.get("MPI_Comm_size");
186 MPIType.push_back(IdentInfo_MPI_Comm_size);
187 assert(IdentInfo_MPI_Comm_size);
189 IdentInfo_MPI_Wait = &ASTCtx.Idents.get("MPI_Wait");
190 MPIType.push_back(IdentInfo_MPI_Wait);
191 assert(IdentInfo_MPI_Wait);
193 IdentInfo_MPI_Waitall = &ASTCtx.Idents.get("MPI_Waitall");
194 MPIType.push_back(IdentInfo_MPI_Waitall);
195 assert(IdentInfo_MPI_Waitall);
197 IdentInfo_MPI_Barrier = &ASTCtx.Idents.get("MPI_Barrier");
198 MPICollectiveTypes.push_back(IdentInfo_MPI_Barrier);
199 MPIType.push_back(IdentInfo_MPI_Barrier);
200 assert(IdentInfo_MPI_Barrier);
203 // general identifiers
204 bool MPIFunctionClassifier::isMPIType(const IdentifierInfo *IdentInfo) const {
205 return llvm::is_contained(MPIType, IdentInfo);
208 bool MPIFunctionClassifier::isNonBlockingType(
209 const IdentifierInfo *IdentInfo) const {
210 return llvm::is_contained(MPINonBlockingTypes, IdentInfo);
213 // point-to-point identifiers
214 bool MPIFunctionClassifier::isPointToPointType(
215 const IdentifierInfo *IdentInfo) const {
216 return llvm::is_contained(MPIPointToPointTypes, IdentInfo);
219 // collective identifiers
220 bool MPIFunctionClassifier::isCollectiveType(
221 const IdentifierInfo *IdentInfo) const {
222 return llvm::is_contained(MPICollectiveTypes, IdentInfo);
225 bool MPIFunctionClassifier::isCollToColl(
226 const IdentifierInfo *IdentInfo) const {
227 return llvm::is_contained(MPICollToCollTypes, IdentInfo);
230 bool MPIFunctionClassifier::isScatterType(
231 const IdentifierInfo *IdentInfo) const {
232 return IdentInfo == IdentInfo_MPI_Scatter ||
233 IdentInfo == IdentInfo_MPI_Iscatter;
236 bool MPIFunctionClassifier::isGatherType(
237 const IdentifierInfo *IdentInfo) const {
238 return IdentInfo == IdentInfo_MPI_Gather ||
239 IdentInfo == IdentInfo_MPI_Igather ||
240 IdentInfo == IdentInfo_MPI_Allgather ||
241 IdentInfo == IdentInfo_MPI_Iallgather;
244 bool MPIFunctionClassifier::isAllgatherType(
245 const IdentifierInfo *IdentInfo) const {
246 return IdentInfo == IdentInfo_MPI_Allgather ||
247 IdentInfo == IdentInfo_MPI_Iallgather;
250 bool MPIFunctionClassifier::isAlltoallType(
251 const IdentifierInfo *IdentInfo) const {
252 return IdentInfo == IdentInfo_MPI_Alltoall ||
253 IdentInfo == IdentInfo_MPI_Ialltoall;
256 bool MPIFunctionClassifier::isBcastType(const IdentifierInfo *IdentInfo) const {
257 return IdentInfo == IdentInfo_MPI_Bcast || IdentInfo == IdentInfo_MPI_Ibcast;
260 bool MPIFunctionClassifier::isReduceType(
261 const IdentifierInfo *IdentInfo) const {
262 return IdentInfo == IdentInfo_MPI_Reduce ||
263 IdentInfo == IdentInfo_MPI_Ireduce ||
264 IdentInfo == IdentInfo_MPI_Allreduce ||
265 IdentInfo == IdentInfo_MPI_Iallreduce;
268 // additional identifiers
269 bool MPIFunctionClassifier::isMPI_Wait(const IdentifierInfo *IdentInfo) const {
270 return IdentInfo == IdentInfo_MPI_Wait;
273 bool MPIFunctionClassifier::isMPI_Waitall(
274 const IdentifierInfo *IdentInfo) const {
275 return IdentInfo == IdentInfo_MPI_Waitall;
278 bool MPIFunctionClassifier::isWaitType(const IdentifierInfo *IdentInfo) const {
279 return IdentInfo == IdentInfo_MPI_Wait || IdentInfo == IdentInfo_MPI_Waitall;
282 } // end of namespace: mpi
283 } // end of namespace: ento
284 } // end of namespace: clang