| 1 | //===- OMPConstants.h - OpenMP related constants and helpers ------ C++ -*-===// | 
| 2 | // | 
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | 
| 4 | // See https://llvm.org/LICENSE.txt for license information. | 
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | 
| 6 | // | 
| 7 | //===----------------------------------------------------------------------===// | 
| 8 | /// \file | 
| 9 | /// | 
| 10 | /// This file defines constans and helpers used when dealing with OpenMP. | 
| 11 | /// | 
| 12 | //===----------------------------------------------------------------------===// | 
| 13 |  | 
| 14 | #ifndef LLVM_FRONTEND_OPENMP_OMPCONSTANTS_H | 
| 15 | #define LLVM_FRONTEND_OPENMP_OMPCONSTANTS_H | 
| 16 |  | 
| 17 | #include "llvm/ADT/BitmaskEnum.h" | 
| 18 |  | 
| 19 | #include "llvm/ADT/StringRef.h" | 
| 20 | #include "llvm/Frontend/OpenMP/OMP.h.inc" | 
| 21 |  | 
| 22 | namespace llvm { | 
| 23 | namespace omp { | 
| 24 | LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE(); | 
| 25 |  | 
| 26 | /// IDs for all Internal Control Variables (ICVs). | 
| 27 | enum class InternalControlVar { | 
| 28 | #define ICV_DATA_ENV(Enum, ...) Enum, | 
| 29 | #include "llvm/Frontend/OpenMP/OMPKinds.def" | 
| 30 | }; | 
| 31 |  | 
| 32 | #define ICV_DATA_ENV(Enum, ...)                                                \ | 
| 33 |   constexpr auto Enum = omp::InternalControlVar::Enum; | 
| 34 | #include "llvm/Frontend/OpenMP/OMPKinds.def" | 
| 35 |  | 
| 36 | enum class ICVInitValue { | 
| 37 | #define ICV_INIT_VALUE(Enum, Name) Enum, | 
| 38 | #include "llvm/Frontend/OpenMP/OMPKinds.def" | 
| 39 | }; | 
| 40 |  | 
| 41 | #define ICV_INIT_VALUE(Enum, Name)                                             \ | 
| 42 |   constexpr auto Enum = omp::ICVInitValue::Enum; | 
| 43 | #include "llvm/Frontend/OpenMP/OMPKinds.def" | 
| 44 |  | 
| 45 | /// IDs for all omp runtime library (RTL) functions. | 
| 46 | enum class RuntimeFunction { | 
| 47 | #define OMP_RTL(Enum, ...) Enum, | 
| 48 | #include "llvm/Frontend/OpenMP/OMPKinds.def" | 
| 49 | }; | 
| 50 |  | 
| 51 | #define OMP_RTL(Enum, ...) constexpr auto Enum = omp::RuntimeFunction::Enum; | 
| 52 | #include "llvm/Frontend/OpenMP/OMPKinds.def" | 
| 53 |  | 
| 54 | /// IDs for the different default kinds. | 
| 55 | enum class DefaultKind { | 
| 56 | #define OMP_DEFAULT_KIND(Enum, Str) Enum, | 
| 57 | #include "llvm/Frontend/OpenMP/OMPKinds.def" | 
| 58 | }; | 
| 59 |  | 
| 60 | #define OMP_DEFAULT_KIND(Enum, ...)                                            \ | 
| 61 |   constexpr auto Enum = omp::DefaultKind::Enum; | 
| 62 | #include "llvm/Frontend/OpenMP/OMPKinds.def" | 
| 63 |  | 
| 64 | /// IDs for all omp runtime library ident_t flag encodings (see | 
| 65 | /// their defintion in openmp/runtime/src/kmp.h). | 
| 66 | enum class IdentFlag { | 
| 67 | #define OMP_IDENT_FLAG(Enum, Str, Value) Enum = Value, | 
| 68 | #include "llvm/Frontend/OpenMP/OMPKinds.def" | 
| 69 |   LLVM_MARK_AS_BITMASK_ENUM(0x7FFFFFFF) | 
| 70 | }; | 
| 71 |  | 
| 72 | #define OMP_IDENT_FLAG(Enum, ...) constexpr auto Enum = omp::IdentFlag::Enum; | 
| 73 | #include "llvm/Frontend/OpenMP/OMPKinds.def" | 
| 74 |  | 
| 75 | // Version of the kernel argument format used by the omp runtime. | 
| 76 | #define OMP_KERNEL_ARG_VERSION 2 | 
| 77 |  | 
| 78 | /// \note This needs to be kept in sync with kmp.h enum sched_type. | 
| 79 | /// Todo: Update kmp.h to include this file, and remove the enums in kmp.h | 
| 80 | enum class OMPScheduleType { | 
| 81 |   // For typed comparisons, not a valid schedule | 
| 82 |   None = 0, | 
| 83 |  | 
| 84 |   // Schedule algorithms | 
| 85 |   BaseStaticChunked = 1, | 
| 86 |   BaseStatic = 2, | 
| 87 |   BaseDynamicChunked = 3, | 
| 88 |   BaseGuidedChunked = 4, | 
| 89 |   BaseRuntime = 5, | 
| 90 |   BaseAuto = 6, | 
| 91 |   BaseTrapezoidal = 7, | 
| 92 |   BaseGreedy = 8, | 
| 93 |   BaseBalanced = 9, | 
| 94 |   BaseGuidedIterativeChunked = 10, | 
| 95 |   BaseGuidedAnalyticalChunked = 11, | 
| 96 |   BaseSteal = 12, | 
| 97 |  | 
| 98 |   // with chunk adjustment (e.g., simd) | 
| 99 |   BaseStaticBalancedChunked = 13, | 
| 100 |   BaseGuidedSimd = 14, | 
| 101 |   BaseRuntimeSimd = 15, | 
| 102 |  | 
| 103 |   // static schedules algorithims for distribute | 
| 104 |   BaseDistributeChunked = 27, | 
| 105 |   BaseDistribute = 28, | 
| 106 |  | 
| 107 |   // Modifier flags to be combined with schedule algorithms | 
| 108 |   ModifierUnordered = (1 << 5), | 
| 109 |   ModifierOrdered = (1 << 6), | 
| 110 |   ModifierNomerge = (1 << 7), | 
| 111 |   ModifierMonotonic = (1 << 29), | 
| 112 |   ModifierNonmonotonic = (1 << 30), | 
| 113 |  | 
| 114 |   // Masks combining multiple flags | 
| 115 |   OrderingMask = ModifierUnordered | ModifierOrdered | ModifierNomerge, | 
| 116 |   MonotonicityMask = ModifierMonotonic | ModifierNonmonotonic, | 
| 117 |   ModifierMask = OrderingMask | MonotonicityMask, | 
| 118 |  | 
| 119 |   // valid schedule type values, without monotonicity flags | 
| 120 |   UnorderedStaticChunked = BaseStaticChunked | ModifierUnordered,        //  33 | 
| 121 |   UnorderedStatic = BaseStatic | ModifierUnordered,                      //  34 | 
| 122 |   UnorderedDynamicChunked = BaseDynamicChunked | ModifierUnordered,      //  35 | 
| 123 |   UnorderedGuidedChunked = BaseGuidedChunked | ModifierUnordered,        //  36 | 
| 124 |   UnorderedRuntime = BaseRuntime | ModifierUnordered,                    //  37 | 
| 125 |   UnorderedAuto = BaseAuto | ModifierUnordered,                          //  38 | 
| 126 |   UnorderedTrapezoidal = BaseTrapezoidal | ModifierUnordered,            //  39 | 
| 127 |   UnorderedGreedy = BaseGreedy | ModifierUnordered,                      //  40 | 
| 128 |   UnorderedBalanced = BaseBalanced | ModifierUnordered,                  //  41 | 
| 129 |   UnorderedGuidedIterativeChunked = | 
| 130 |       BaseGuidedIterativeChunked | ModifierUnordered,                    //  42 | 
| 131 |   UnorderedGuidedAnalyticalChunked = | 
| 132 |       BaseGuidedAnalyticalChunked | ModifierUnordered,                   //  43 | 
| 133 |   UnorderedSteal = BaseSteal | ModifierUnordered,                        //  44 | 
| 134 |  | 
| 135 |   UnorderedStaticBalancedChunked = | 
| 136 |       BaseStaticBalancedChunked | ModifierUnordered,                     //  45 | 
| 137 |   UnorderedGuidedSimd = BaseGuidedSimd | ModifierUnordered,              //  46 | 
| 138 |   UnorderedRuntimeSimd = BaseRuntimeSimd | ModifierUnordered,            //  47 | 
| 139 |  | 
| 140 |   OrderedStaticChunked = BaseStaticChunked | ModifierOrdered,            //  65 | 
| 141 |   OrderedStatic = BaseStatic | ModifierOrdered,                          //  66 | 
| 142 |   OrderedDynamicChunked = BaseDynamicChunked | ModifierOrdered,          //  67 | 
| 143 |   OrderedGuidedChunked = BaseGuidedChunked | ModifierOrdered,            //  68 | 
| 144 |   OrderedRuntime = BaseRuntime | ModifierOrdered,                        //  69 | 
| 145 |   OrderedAuto = BaseAuto | ModifierOrdered,                              //  70 | 
| 146 |   OrderdTrapezoidal = BaseTrapezoidal | ModifierOrdered,                 //  71 | 
| 147 |  | 
| 148 |   OrderedDistributeChunked = BaseDistributeChunked | ModifierOrdered,    //  91 | 
| 149 |   OrderedDistribute = BaseDistribute | ModifierOrdered,                  //  92 | 
| 150 |  | 
| 151 |   NomergeUnorderedStaticChunked = | 
| 152 |       BaseStaticChunked | ModifierUnordered | ModifierNomerge,           // 161 | 
| 153 |   NomergeUnorderedStatic = | 
| 154 |       BaseStatic | ModifierUnordered | ModifierNomerge,                  // 162 | 
| 155 |   NomergeUnorderedDynamicChunked = | 
| 156 |       BaseDynamicChunked | ModifierUnordered | ModifierNomerge,          // 163 | 
| 157 |   NomergeUnorderedGuidedChunked = | 
| 158 |       BaseGuidedChunked | ModifierUnordered | ModifierNomerge,           // 164 | 
| 159 |   NomergeUnorderedRuntime = | 
| 160 |       BaseRuntime | ModifierUnordered | ModifierNomerge,                 // 165 | 
| 161 |   NomergeUnorderedAuto = BaseAuto | ModifierUnordered | ModifierNomerge, // 166 | 
| 162 |   NomergeUnorderedTrapezoidal = | 
| 163 |       BaseTrapezoidal | ModifierUnordered | ModifierNomerge,             // 167 | 
| 164 |   NomergeUnorderedGreedy = | 
| 165 |       BaseGreedy | ModifierUnordered | ModifierNomerge,                  // 168 | 
| 166 |   NomergeUnorderedBalanced = | 
| 167 |       BaseBalanced | ModifierUnordered | ModifierNomerge,                // 169 | 
| 168 |   NomergeUnorderedGuidedIterativeChunked = | 
| 169 |       BaseGuidedIterativeChunked | ModifierUnordered | ModifierNomerge,  // 170 | 
| 170 |   NomergeUnorderedGuidedAnalyticalChunked = | 
| 171 |       BaseGuidedAnalyticalChunked | ModifierUnordered | ModifierNomerge, // 171 | 
| 172 |   NomergeUnorderedSteal = | 
| 173 |       BaseSteal | ModifierUnordered | ModifierNomerge,                   // 172 | 
| 174 |  | 
| 175 |   NomergeOrderedStaticChunked = | 
| 176 |       BaseStaticChunked | ModifierOrdered | ModifierNomerge,             // 193 | 
| 177 |   NomergeOrderedStatic = BaseStatic | ModifierOrdered | ModifierNomerge, // 194 | 
| 178 |   NomergeOrderedDynamicChunked = | 
| 179 |       BaseDynamicChunked | ModifierOrdered | ModifierNomerge,            // 195 | 
| 180 |   NomergeOrderedGuidedChunked = | 
| 181 |       BaseGuidedChunked | ModifierOrdered | ModifierNomerge,             // 196 | 
| 182 |   NomergeOrderedRuntime = | 
| 183 |       BaseRuntime | ModifierOrdered | ModifierNomerge,                   // 197 | 
| 184 |   NomergeOrderedAuto = BaseAuto | ModifierOrdered | ModifierNomerge,     // 198 | 
| 185 |   NomergeOrderedTrapezoidal = | 
| 186 |       BaseTrapezoidal | ModifierOrdered | ModifierNomerge,               // 199 | 
| 187 |  | 
| 188 |   LLVM_MARK_AS_BITMASK_ENUM(/* LargestValue */ ModifierMask) | 
| 189 | }; | 
| 190 |  | 
| 191 | /// Values for bit flags used to specify the mapping type for | 
| 192 | /// offloading. | 
| 193 | enum class OpenMPOffloadMappingFlags : uint64_t { | 
| 194 |   /// No flags | 
| 195 |   OMP_MAP_NONE = 0x0, | 
| 196 |   /// Allocate memory on the device and move data from host to device. | 
| 197 |   OMP_MAP_TO = 0x01, | 
| 198 |   /// Allocate memory on the device and move data from device to host. | 
| 199 |   OMP_MAP_FROM = 0x02, | 
| 200 |   /// Always perform the requested mapping action on the element, even | 
| 201 |   /// if it was already mapped before. | 
| 202 |   OMP_MAP_ALWAYS = 0x04, | 
| 203 |   /// Delete the element from the device environment, ignoring the | 
| 204 |   /// current reference count associated with the element. | 
| 205 |   OMP_MAP_DELETE = 0x08, | 
| 206 |   /// The element being mapped is a pointer-pointee pair; both the | 
| 207 |   /// pointer and the pointee should be mapped. | 
| 208 |   OMP_MAP_PTR_AND_OBJ = 0x10, | 
| 209 |   /// This flags signals that the base address of an entry should be | 
| 210 |   /// passed to the target kernel as an argument. | 
| 211 |   OMP_MAP_TARGET_PARAM = 0x20, | 
| 212 |   /// Signal that the runtime library has to return the device pointer | 
| 213 |   /// in the current position for the data being mapped. Used when we have the | 
| 214 |   /// use_device_ptr or use_device_addr clause. | 
| 215 |   OMP_MAP_RETURN_PARAM = 0x40, | 
| 216 |   /// This flag signals that the reference being passed is a pointer to | 
| 217 |   /// private data. | 
| 218 |   OMP_MAP_PRIVATE = 0x80, | 
| 219 |   /// Pass the element to the device by value. | 
| 220 |   OMP_MAP_LITERAL = 0x100, | 
| 221 |   /// Implicit map | 
| 222 |   OMP_MAP_IMPLICIT = 0x200, | 
| 223 |   /// Close is a hint to the runtime to allocate memory close to | 
| 224 |   /// the target device. | 
| 225 |   OMP_MAP_CLOSE = 0x400, | 
| 226 |   /// 0x800 is reserved for compatibility with XLC. | 
| 227 |   /// Produce a runtime error if the data is not already allocated. | 
| 228 |   OMP_MAP_PRESENT = 0x1000, | 
| 229 |   // Increment and decrement a separate reference counter so that the data | 
| 230 |   // cannot be unmapped within the associated region.  Thus, this flag is | 
| 231 |   // intended to be used on 'target' and 'target data' directives because they | 
| 232 |   // are inherently structured.  It is not intended to be used on 'target | 
| 233 |   // enter data' and 'target exit data' directives because they are inherently | 
| 234 |   // dynamic. | 
| 235 |   // This is an OpenMP extension for the sake of OpenACC support. | 
| 236 |   OMP_MAP_OMPX_HOLD = 0x2000, | 
| 237 |   /// Signal that the runtime library should use args as an array of | 
| 238 |   /// descriptor_dim pointers and use args_size as dims. Used when we have | 
| 239 |   /// non-contiguous list items in target update directive | 
| 240 |   OMP_MAP_NON_CONTIG = 0x100000000000, | 
| 241 |   /// The 16 MSBs of the flags indicate whether the entry is member of some | 
| 242 |   /// struct/class. | 
| 243 |   OMP_MAP_MEMBER_OF = 0xffff000000000000, | 
| 244 |   LLVM_MARK_AS_BITMASK_ENUM(/* LargestFlag = */ OMP_MAP_MEMBER_OF) | 
| 245 | }; | 
| 246 |  | 
| 247 | enum OpenMPOffloadingReservedDeviceIDs { | 
| 248 |   /// Device ID if the device was not defined, runtime should get it | 
| 249 |   /// from environment variables in the spec. | 
| 250 |   OMP_DEVICEID_UNDEF = -1 | 
| 251 | }; | 
| 252 |  | 
| 253 | enum class AddressSpace : unsigned { | 
| 254 |   Generic = 0, | 
| 255 |   Global = 1, | 
| 256 |   Shared = 3, | 
| 257 |   Constant = 4, | 
| 258 |   Local = 5, | 
| 259 | }; | 
| 260 |  | 
| 261 | /// \note This needs to be kept in sync with interop.h enum kmp_interop_type_t.: | 
| 262 | enum class OMPInteropType { Unknown, Target, TargetSync }; | 
| 263 |  | 
| 264 | /// Atomic compare operations. Currently OpenMP only supports ==, >, and <. | 
| 265 | enum class OMPAtomicCompareOp : unsigned { EQ, MIN, MAX }; | 
| 266 |  | 
| 267 | /// Fields ids in kmp_depend_info record. | 
| 268 | enum class RTLDependInfoFields { BaseAddr, Len, Flags }; | 
| 269 |  | 
| 270 | /// Dependence kind for RTL. | 
| 271 | enum class RTLDependenceKindTy { | 
| 272 |   DepUnknown = 0x0, | 
| 273 |   DepIn = 0x01, | 
| 274 |   DepInOut = 0x3, | 
| 275 |   DepMutexInOutSet = 0x4, | 
| 276 |   DepInOutSet = 0x8, | 
| 277 |   DepOmpAllMem = 0x80, | 
| 278 | }; | 
| 279 |  | 
| 280 | } // end namespace omp | 
| 281 |  | 
| 282 | } // end namespace llvm | 
| 283 |  | 
| 284 | #include "OMPDeviceConstants.h" | 
| 285 |  | 
| 286 | #endif // LLVM_FRONTEND_OPENMP_OMPCONSTANTS_H | 
| 287 |  |