1*06f32e7eSjoerg //===-- MPITypes.h - Functionality to model MPI concepts --------*- C++ -*-===//
2*06f32e7eSjoerg //
3*06f32e7eSjoerg // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*06f32e7eSjoerg // See https://llvm.org/LICENSE.txt for license information.
5*06f32e7eSjoerg // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*06f32e7eSjoerg //
7*06f32e7eSjoerg //===----------------------------------------------------------------------===//
8*06f32e7eSjoerg ///
9*06f32e7eSjoerg /// \file
10*06f32e7eSjoerg /// This file provides definitions to model concepts of MPI. The mpi::Request
11*06f32e7eSjoerg /// class defines a wrapper class, in order to make MPI requests trackable for
12*06f32e7eSjoerg /// path-sensitive analysis.
13*06f32e7eSjoerg ///
14*06f32e7eSjoerg //===----------------------------------------------------------------------===//
15*06f32e7eSjoerg 
16*06f32e7eSjoerg #ifndef LLVM_CLANG_LIB_STATICANALYZER_CHECKERS_MPICHECKER_MPITYPES_H
17*06f32e7eSjoerg #define LLVM_CLANG_LIB_STATICANALYZER_CHECKERS_MPICHECKER_MPITYPES_H
18*06f32e7eSjoerg 
19*06f32e7eSjoerg #include "clang/StaticAnalyzer/Checkers/MPIFunctionClassifier.h"
20*06f32e7eSjoerg #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
21*06f32e7eSjoerg #include "llvm/ADT/SmallSet.h"
22*06f32e7eSjoerg 
23*06f32e7eSjoerg namespace clang {
24*06f32e7eSjoerg namespace ento {
25*06f32e7eSjoerg namespace mpi {
26*06f32e7eSjoerg 
27*06f32e7eSjoerg class Request {
28*06f32e7eSjoerg public:
29*06f32e7eSjoerg   enum State : unsigned char { Nonblocking, Wait };
30*06f32e7eSjoerg 
Request(State S)31*06f32e7eSjoerg   Request(State S) : CurrentState{S} {}
32*06f32e7eSjoerg 
Profile(llvm::FoldingSetNodeID & Id)33*06f32e7eSjoerg   void Profile(llvm::FoldingSetNodeID &Id) const {
34*06f32e7eSjoerg     Id.AddInteger(CurrentState);
35*06f32e7eSjoerg   }
36*06f32e7eSjoerg 
37*06f32e7eSjoerg   bool operator==(const Request &ToCompare) const {
38*06f32e7eSjoerg     return CurrentState == ToCompare.CurrentState;
39*06f32e7eSjoerg   }
40*06f32e7eSjoerg 
41*06f32e7eSjoerg   const State CurrentState;
42*06f32e7eSjoerg };
43*06f32e7eSjoerg 
44*06f32e7eSjoerg // The RequestMap stores MPI requests which are identified by their memory
45*06f32e7eSjoerg // region. Requests are used in MPI to complete nonblocking operations with wait
46*06f32e7eSjoerg // operations. A custom map implementation is used, in order to make it
47*06f32e7eSjoerg // available in an arbitrary amount of translation units.
48*06f32e7eSjoerg struct RequestMap {};
49*06f32e7eSjoerg typedef llvm::ImmutableMap<const clang::ento::MemRegion *,
50*06f32e7eSjoerg                            clang::ento::mpi::Request>
51*06f32e7eSjoerg     RequestMapImpl;
52*06f32e7eSjoerg 
53*06f32e7eSjoerg } // end of namespace: mpi
54*06f32e7eSjoerg 
55*06f32e7eSjoerg template <>
56*06f32e7eSjoerg struct ProgramStateTrait<mpi::RequestMap>
57*06f32e7eSjoerg     : public ProgramStatePartialTrait<mpi::RequestMapImpl> {
58*06f32e7eSjoerg   static void *GDMIndex() {
59*06f32e7eSjoerg     static int index = 0;
60*06f32e7eSjoerg     return &index;
61*06f32e7eSjoerg   }
62*06f32e7eSjoerg };
63*06f32e7eSjoerg 
64*06f32e7eSjoerg } // end of namespace: ento
65*06f32e7eSjoerg } // end of namespace: clang
66*06f32e7eSjoerg #endif
67