clang  6.0.0svn
MPIFunctionClassifier.cpp
Go to the documentation of this file.
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 
16 #include "llvm/ADT/STLExtras.h"
17 
18 namespace clang {
19 namespace ento {
20 namespace mpi {
21 
22 void MPIFunctionClassifier::identifierInit(ASTContext &ASTCtx) {
23  // Initialize function identifiers.
24  initPointToPointIdentifiers(ASTCtx);
25  initCollectiveIdentifiers(ASTCtx);
26  initAdditionalIdentifiers(ASTCtx);
27 }
28 
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);
35 
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);
41 
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);
46 
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);
52 
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);
57 
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);
63 
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);
68 
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);
73 
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);
78 
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);
84 }
85 
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);
93 
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);
100 
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);
106 
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);
113 
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);
119 
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);
126 
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);
132 
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);
139 
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);
145 
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);
152 
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);
158 
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);
165 
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);
171 
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);
178 }
179 
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);
184 
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);
188 
189  IdentInfo_MPI_Wait = &ASTCtx.Idents.get("MPI_Wait");
190  MPIType.push_back(IdentInfo_MPI_Wait);
191  assert(IdentInfo_MPI_Wait);
192 
193  IdentInfo_MPI_Waitall = &ASTCtx.Idents.get("MPI_Waitall");
194  MPIType.push_back(IdentInfo_MPI_Waitall);
195  assert(IdentInfo_MPI_Waitall);
196 
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);
201 }
202 
203 // general identifiers
204 bool MPIFunctionClassifier::isMPIType(const IdentifierInfo *IdentInfo) const {
205  return llvm::is_contained(MPIType, IdentInfo);
206 }
207 
209  const IdentifierInfo *IdentInfo) const {
210  return llvm::is_contained(MPINonBlockingTypes, IdentInfo);
211 }
212 
213 // point-to-point identifiers
215  const IdentifierInfo *IdentInfo) const {
216  return llvm::is_contained(MPIPointToPointTypes, IdentInfo);
217 }
218 
219 // collective identifiers
221  const IdentifierInfo *IdentInfo) const {
222  return llvm::is_contained(MPICollectiveTypes, IdentInfo);
223 }
224 
226  const IdentifierInfo *IdentInfo) const {
227  return llvm::is_contained(MPICollToCollTypes, IdentInfo);
228 }
229 
231  const IdentifierInfo *IdentInfo) const {
232  return IdentInfo == IdentInfo_MPI_Scatter ||
233  IdentInfo == IdentInfo_MPI_Iscatter;
234 }
235 
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;
242 }
243 
245  const IdentifierInfo *IdentInfo) const {
246  return IdentInfo == IdentInfo_MPI_Allgather ||
247  IdentInfo == IdentInfo_MPI_Iallgather;
248 }
249 
251  const IdentifierInfo *IdentInfo) const {
252  return IdentInfo == IdentInfo_MPI_Alltoall ||
253  IdentInfo == IdentInfo_MPI_Ialltoall;
254 }
255 
257  return IdentInfo == IdentInfo_MPI_Bcast || IdentInfo == IdentInfo_MPI_Ibcast;
258 }
259 
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;
266 }
267 
268 // additional identifiers
269 bool MPIFunctionClassifier::isMPI_Wait(const IdentifierInfo *IdentInfo) const {
270  return IdentInfo == IdentInfo_MPI_Wait;
271 }
272 
274  const IdentifierInfo *IdentInfo) const {
275  return IdentInfo == IdentInfo_MPI_Waitall;
276 }
277 
278 bool MPIFunctionClassifier::isWaitType(const IdentifierInfo *IdentInfo) const {
279  return IdentInfo == IdentInfo_MPI_Wait || IdentInfo == IdentInfo_MPI_Waitall;
280 }
281 
282 } // end of namespace: mpi
283 } // end of namespace: ento
284 } // end of namespace: clang
bool isCollectiveType(const IdentifierInfo *const IdentInfo) const
bool isAlltoallType(const IdentifierInfo *const IdentInfo) const
One of these records is kept for each identifier that is lexed.
bool isAllgatherType(const IdentifierInfo *const IdentInfo) const
bool isNonBlockingType(const IdentifierInfo *const IdentInfo) const
bool isBcastType(const IdentifierInfo *const IdentInfo) const
bool isMPI_Waitall(const IdentifierInfo *const IdentInfo) const
This file defines functionality to identify and classify MPI functions.
bool isMPI_Wait(const IdentifierInfo *const IdentInfo) const
bool isScatterType(const IdentifierInfo *const IdentInfo) const
bool isReduceType(const IdentifierInfo *const IdentInfo) const
bool isWaitType(const IdentifierInfo *const IdentInfo) const
Dataflow Directional Tag Classes.
bool isPointToPointType(const IdentifierInfo *const IdentInfo) const
bool isGatherType(const IdentifierInfo *const IdentInfo) const
bool isCollToColl(const IdentifierInfo *const IdentInfo) const
bool isMPIType(const IdentifierInfo *const IdentInfo) const