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