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