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