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