Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1 | //===----- CGOpenMPRuntime.h - Interface to OpenMP Runtimes -----*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This provides a class for OpenMP runtime code generation. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Benjamin Kramer | 2f5db8b | 2014-08-13 16:25:19 +0000 | [diff] [blame] | 14 | #ifndef LLVM_CLANG_LIB_CODEGEN_CGOPENMPRUNTIME_H |
| 15 | #define LLVM_CLANG_LIB_CODEGEN_CGOPENMPRUNTIME_H |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 16 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 17 | #include "clang/Basic/OpenMPKinds.h" |
Chandler Carruth | 0d9593d | 2015-01-14 11:29:14 +0000 | [diff] [blame] | 18 | #include "clang/Basic/SourceLocation.h" |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/DenseMap.h" |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/DenseSet.h" |
Alexey Bataev | 3a3bf0b | 2014-09-22 10:01:53 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/StringMap.h" |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 22 | #include "llvm/IR/ValueHandle.h" |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 23 | |
| 24 | namespace llvm { |
| 25 | class ArrayType; |
| 26 | class Constant; |
| 27 | class Function; |
| 28 | class FunctionType; |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 29 | class GlobalVariable; |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 30 | class StructType; |
| 31 | class Type; |
| 32 | class Value; |
| 33 | } // namespace llvm |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 34 | |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 35 | namespace clang { |
Alexey Bataev | cc37cc1 | 2014-11-20 04:34:54 +0000 | [diff] [blame] | 36 | class Expr; |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 37 | class OMPExecutableDirective; |
| 38 | class VarDecl; |
| 39 | |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 40 | namespace CodeGen { |
| 41 | |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 42 | class CodeGenFunction; |
| 43 | class CodeGenModule; |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 44 | |
| 45 | class CGOpenMPRuntime { |
| 46 | public: |
Alexey Bataev | 8f7c1b0 | 2014-12-05 04:09:23 +0000 | [diff] [blame] | 47 | |
| 48 | private: |
| 49 | enum OpenMPRTLFunction { |
| 50 | /// \brief Call to void __kmpc_fork_call(ident_t *loc, kmp_int32 argc, |
| 51 | /// kmpc_micro microtask, ...); |
| 52 | OMPRTL__kmpc_fork_call, |
| 53 | /// \brief Call to void *__kmpc_threadprivate_cached(ident_t *loc, |
| 54 | /// kmp_int32 global_tid, void *data, size_t size, void ***cache); |
| 55 | OMPRTL__kmpc_threadprivate_cached, |
| 56 | /// \brief Call to void __kmpc_threadprivate_register( ident_t *, |
| 57 | /// void *data, kmpc_ctor ctor, kmpc_cctor cctor, kmpc_dtor dtor); |
| 58 | OMPRTL__kmpc_threadprivate_register, |
| 59 | // Call to __kmpc_int32 kmpc_global_thread_num(ident_t *loc); |
| 60 | OMPRTL__kmpc_global_thread_num, |
| 61 | // Call to void __kmpc_critical(ident_t *loc, kmp_int32 global_tid, |
| 62 | // kmp_critical_name *crit); |
| 63 | OMPRTL__kmpc_critical, |
| 64 | // Call to void __kmpc_end_critical(ident_t *loc, kmp_int32 global_tid, |
| 65 | // kmp_critical_name *crit); |
| 66 | OMPRTL__kmpc_end_critical, |
| 67 | // Call to kmp_int32 __kmpc_cancel_barrier(ident_t *loc, kmp_int32 |
| 68 | // global_tid); |
| 69 | OMPRTL__kmpc_cancel_barrier, |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 70 | // Calls for static scheduling 'omp for' loops. |
| 71 | OMPRTL__kmpc_for_static_init_4, |
| 72 | OMPRTL__kmpc_for_static_init_4u, |
| 73 | OMPRTL__kmpc_for_static_init_8, |
| 74 | OMPRTL__kmpc_for_static_init_8u, |
| 75 | OMPRTL__kmpc_for_static_fini, |
Alexey Bataev | 8f7c1b0 | 2014-12-05 04:09:23 +0000 | [diff] [blame] | 76 | // Call to void __kmpc_serialized_parallel(ident_t *loc, kmp_int32 |
| 77 | // global_tid); |
| 78 | OMPRTL__kmpc_serialized_parallel, |
| 79 | // Call to void __kmpc_end_serialized_parallel(ident_t *loc, kmp_int32 |
| 80 | // global_tid); |
| 81 | OMPRTL__kmpc_end_serialized_parallel, |
| 82 | // Call to void __kmpc_push_num_threads(ident_t *loc, kmp_int32 global_tid, |
| 83 | // kmp_int32 num_threads); |
| 84 | OMPRTL__kmpc_push_num_threads, |
Alexey Bataev | d76df6d | 2015-02-24 12:55:09 +0000 | [diff] [blame] | 85 | // Call to void __kmpc_flush(ident_t *loc); |
Alexey Bataev | 8f7c1b0 | 2014-12-05 04:09:23 +0000 | [diff] [blame] | 86 | OMPRTL__kmpc_flush, |
| 87 | // Call to kmp_int32 __kmpc_master(ident_t *, kmp_int32 global_tid); |
| 88 | OMPRTL__kmpc_master, |
| 89 | // Call to void __kmpc_end_master(ident_t *, kmp_int32 global_tid); |
| 90 | OMPRTL__kmpc_end_master, |
Alexey Bataev | 9f797f3 | 2015-02-05 05:57:51 +0000 | [diff] [blame] | 91 | // Call to kmp_int32 __kmpc_omp_taskyield(ident_t *, kmp_int32 global_tid, |
| 92 | // int end_part); |
| 93 | OMPRTL__kmpc_omp_taskyield, |
Alexey Bataev | 6956e2e | 2015-02-05 06:35:41 +0000 | [diff] [blame] | 94 | // Call to kmp_int32 __kmpc_single(ident_t *, kmp_int32 global_tid); |
| 95 | OMPRTL__kmpc_single, |
| 96 | // Call to void __kmpc_end_single(ident_t *, kmp_int32 global_tid); |
| 97 | OMPRTL__kmpc_end_single, |
Alexey Bataev | 8f7c1b0 | 2014-12-05 04:09:23 +0000 | [diff] [blame] | 98 | }; |
| 99 | |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 100 | /// \brief Values for bit flags used in the ident_t to describe the fields. |
| 101 | /// All enumeric elements are named and described in accordance with the code |
| 102 | /// from http://llvm.org/svn/llvm-project/openmp/trunk/runtime/src/kmp.h |
| 103 | enum OpenMPLocationFlags { |
| 104 | /// \brief Use trampoline for internal microtask. |
| 105 | OMP_IDENT_IMD = 0x01, |
| 106 | /// \brief Use c-style ident structure. |
| 107 | OMP_IDENT_KMPC = 0x02, |
| 108 | /// \brief Atomic reduction option for kmpc_reduce. |
| 109 | OMP_ATOMIC_REDUCE = 0x10, |
| 110 | /// \brief Explicit 'barrier' directive. |
| 111 | OMP_IDENT_BARRIER_EXPL = 0x20, |
| 112 | /// \brief Implicit barrier in code. |
| 113 | OMP_IDENT_BARRIER_IMPL = 0x40, |
| 114 | /// \brief Implicit barrier in 'for' directive. |
| 115 | OMP_IDENT_BARRIER_IMPL_FOR = 0x40, |
| 116 | /// \brief Implicit barrier in 'sections' directive. |
| 117 | OMP_IDENT_BARRIER_IMPL_SECTIONS = 0xC0, |
| 118 | /// \brief Implicit barrier in 'single' directive. |
| 119 | OMP_IDENT_BARRIER_IMPL_SINGLE = 0x140 |
| 120 | }; |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 121 | CodeGenModule &CGM; |
| 122 | /// \brief Default const ident_t object used for initialization of all other |
| 123 | /// ident_t objects. |
| 124 | llvm::Constant *DefaultOpenMPPSource; |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 125 | /// \brief Map of flags and corresponding default locations. |
Alexey Bataev | 15007ba | 2014-05-07 06:18:01 +0000 | [diff] [blame] | 126 | typedef llvm::DenseMap<unsigned, llvm::Value *> OpenMPDefaultLocMapTy; |
| 127 | OpenMPDefaultLocMapTy OpenMPDefaultLocMap; |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 128 | llvm::Value *GetOrCreateDefaultOpenMPLocation(OpenMPLocationFlags Flags); |
| 129 | /// \brief Describes ident structure that describes a source location. |
| 130 | /// All descriptions are taken from |
| 131 | /// http://llvm.org/svn/llvm-project/openmp/trunk/runtime/src/kmp.h |
| 132 | /// Original structure: |
| 133 | /// typedef struct ident { |
| 134 | /// kmp_int32 reserved_1; /**< might be used in Fortran; |
| 135 | /// see above */ |
| 136 | /// kmp_int32 flags; /**< also f.flags; KMP_IDENT_xxx flags; |
| 137 | /// KMP_IDENT_KMPC identifies this union |
| 138 | /// member */ |
| 139 | /// kmp_int32 reserved_2; /**< not really used in Fortran any more; |
| 140 | /// see above */ |
| 141 | ///#if USE_ITT_BUILD |
| 142 | /// /* but currently used for storing |
| 143 | /// region-specific ITT */ |
| 144 | /// /* contextual information. */ |
| 145 | ///#endif /* USE_ITT_BUILD */ |
| 146 | /// kmp_int32 reserved_3; /**< source[4] in Fortran, do not use for |
| 147 | /// C++ */ |
| 148 | /// char const *psource; /**< String describing the source location. |
| 149 | /// The string is composed of semi-colon separated |
| 150 | // fields which describe the source file, |
| 151 | /// the function and a pair of line numbers that |
| 152 | /// delimit the construct. |
| 153 | /// */ |
| 154 | /// } ident_t; |
| 155 | enum IdentFieldIndex { |
| 156 | /// \brief might be used in Fortran |
| 157 | IdentField_Reserved_1, |
| 158 | /// \brief OMP_IDENT_xxx flags; OMP_IDENT_KMPC identifies this union member. |
| 159 | IdentField_Flags, |
| 160 | /// \brief Not really used in Fortran any more |
| 161 | IdentField_Reserved_2, |
| 162 | /// \brief Source[4] in Fortran, do not use for C++ |
| 163 | IdentField_Reserved_3, |
| 164 | /// \brief String describing the source location. The string is composed of |
| 165 | /// semi-colon separated fields which describe the source file, the function |
| 166 | /// and a pair of line numbers that delimit the construct. |
| 167 | IdentField_PSource |
| 168 | }; |
| 169 | llvm::StructType *IdentTy; |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 170 | /// \brief Map for SourceLocation and OpenMP runtime library debug locations. |
Alexey Bataev | f002aca | 2014-05-30 05:48:40 +0000 | [diff] [blame] | 171 | typedef llvm::DenseMap<unsigned, llvm::Value *> OpenMPDebugLocMapTy; |
| 172 | OpenMPDebugLocMapTy OpenMPDebugLocMap; |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 173 | /// \brief The type for a microtask which gets passed to __kmpc_fork_call(). |
| 174 | /// Original representation is: |
| 175 | /// typedef void (kmpc_micro)(kmp_int32 global_tid, kmp_int32 bound_tid,...); |
| 176 | llvm::FunctionType *Kmpc_MicroTy; |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 177 | /// \brief Stores debug location and ThreadID for the function. |
| 178 | struct DebugLocThreadIdTy { |
| 179 | llvm::Value *DebugLoc; |
| 180 | llvm::Value *ThreadID; |
| 181 | }; |
| 182 | /// \brief Map of local debug location, ThreadId and functions. |
| 183 | typedef llvm::DenseMap<llvm::Function *, DebugLocThreadIdTy> |
| 184 | OpenMPLocThreadIDMapTy; |
| 185 | OpenMPLocThreadIDMapTy OpenMPLocThreadIDMap; |
Alexey Bataev | 3a3bf0b | 2014-09-22 10:01:53 +0000 | [diff] [blame] | 186 | /// \brief Type kmp_critical_name, originally defined as typedef kmp_int32 |
| 187 | /// kmp_critical_name[8]; |
| 188 | llvm::ArrayType *KmpCriticalNameTy; |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 189 | /// \brief An ordered map of auto-generated variables to their unique names. |
| 190 | /// It stores variables with the following names: 1) ".gomp_critical_user_" + |
| 191 | /// <critical_section_name> + ".var" for "omp critical" directives; 2) |
| 192 | /// <mangled_name_for_global_var> + ".cache." for cache for threadprivate |
| 193 | /// variables. |
| 194 | llvm::StringMap<llvm::AssertingVH<llvm::Constant>, llvm::BumpPtrAllocator> |
| 195 | InternalVars; |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 196 | |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 197 | /// \brief Emits object of ident_t type with info for source location. |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 198 | /// \param Flags Flags for OpenMP location. |
| 199 | /// |
| 200 | llvm::Value * |
| 201 | EmitOpenMPUpdateLocation(CodeGenFunction &CGF, SourceLocation Loc, |
| 202 | OpenMPLocationFlags Flags = OMP_IDENT_KMPC); |
| 203 | |
Alexey Bataev | d74d060 | 2014-10-13 06:02:40 +0000 | [diff] [blame] | 204 | /// \brief Returns pointer to ident_t type. |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 205 | llvm::Type *getIdentTyPointerTy(); |
| 206 | |
Alexey Bataev | d74d060 | 2014-10-13 06:02:40 +0000 | [diff] [blame] | 207 | /// \brief Returns pointer to kmpc_micro type. |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 208 | llvm::Type *getKmpc_MicroPointerTy(); |
| 209 | |
| 210 | /// \brief Returns specified OpenMP runtime function. |
| 211 | /// \param Function OpenMP runtime function. |
| 212 | /// \return Specified function. |
| 213 | llvm::Constant *CreateRuntimeFunction(OpenMPRTLFunction Function); |
Alexey Bataev | 3a3bf0b | 2014-09-22 10:01:53 +0000 | [diff] [blame] | 214 | |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 215 | /// \brief If the specified mangled name is not in the module, create and |
| 216 | /// return threadprivate cache object. This object is a pointer's worth of |
| 217 | /// storage that's reserved for use by the OpenMP runtime. |
NAKAMURA Takumi | cdcbfba | 2014-11-11 07:58:06 +0000 | [diff] [blame] | 218 | /// \param VD Threadprivate variable. |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 219 | /// \return Cache variable for the specified threadprivate. |
| 220 | llvm::Constant *getOrCreateThreadPrivateCache(const VarDecl *VD); |
| 221 | |
Alexey Bataev | d74d060 | 2014-10-13 06:02:40 +0000 | [diff] [blame] | 222 | /// \brief Emits address of the word in a memory where current thread id is |
| 223 | /// stored. |
| 224 | virtual llvm::Value *EmitThreadIDAddress(CodeGenFunction &CGF, |
| 225 | SourceLocation Loc); |
| 226 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 227 | /// \brief Gets thread id value for the current thread. |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 228 | /// |
| 229 | llvm::Value *GetOpenMPThreadID(CodeGenFunction &CGF, SourceLocation Loc); |
| 230 | |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 231 | /// \brief Gets (if variable with the given name already exist) or creates |
| 232 | /// internal global variable with the specified Name. The created variable has |
| 233 | /// linkage CommonLinkage by default and is initialized by null value. |
| 234 | /// \param Ty Type of the global variable. If it is exist already the type |
| 235 | /// must be the same. |
| 236 | /// \param Name Name of the variable. |
| 237 | llvm::Constant *GetOrCreateInternalVariable(llvm::Type *Ty, |
| 238 | const llvm::Twine &Name); |
| 239 | |
| 240 | /// \brief Set of threadprivate variables with the generated initializer. |
| 241 | llvm::DenseSet<const VarDecl *> ThreadPrivateWithDefinition; |
| 242 | |
| 243 | /// \brief Emits initialization code for the threadprivate variables. |
| 244 | /// \param VDAddr Address of the global variable \a VD. |
| 245 | /// \param Ctor Pointer to a global init function for \a VD. |
| 246 | /// \param CopyCtor Pointer to a global copy function for \a VD. |
| 247 | /// \param Dtor Pointer to a global destructor function for \a VD. |
| 248 | /// \param Loc Location of threadprivate declaration. |
| 249 | void EmitOMPThreadPrivateVarInit(CodeGenFunction &CGF, llvm::Value *VDAddr, |
| 250 | llvm::Value *Ctor, llvm::Value *CopyCtor, |
| 251 | llvm::Value *Dtor, SourceLocation Loc); |
| 252 | |
Alexey Bataev | 75ddfab | 2014-12-01 11:32:38 +0000 | [diff] [blame] | 253 | /// \brief Returns corresponding lock object for the specified critical region |
| 254 | /// name. If the lock object does not exist it is created, otherwise the |
| 255 | /// reference to the existing copy is returned. |
| 256 | /// \param CriticalName Name of the critical region. |
| 257 | /// |
| 258 | llvm::Value *GetCriticalRegionLock(StringRef CriticalName); |
| 259 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 260 | public: |
| 261 | explicit CGOpenMPRuntime(CodeGenModule &CGM); |
| 262 | virtual ~CGOpenMPRuntime() {} |
| 263 | |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 264 | /// \brief Emits outlined function for the specified OpenMP directive \a D |
| 265 | /// (required for parallel and task directives). This outlined function has |
| 266 | /// type void(*)(kmp_int32 /*ThreadID*/, kmp_int32 /*BoundID*/, struct |
| 267 | /// context_vars*). |
| 268 | /// \param D OpenMP directive. |
| 269 | /// \param ThreadIDVar Variable for thread id in the current OpenMP region. |
| 270 | /// |
| 271 | virtual llvm::Value * |
| 272 | EmitOpenMPOutlinedFunction(const OMPExecutableDirective &D, |
| 273 | const VarDecl *ThreadIDVar); |
| 274 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 275 | /// \brief Cleans up references to the objects in finished function. |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 276 | /// |
| 277 | void FunctionFinished(CodeGenFunction &CGF); |
| 278 | |
| 279 | /// \brief Emits code for parallel call of the \a OutlinedFn with variables |
| 280 | /// captured in a record which address is stored in \a CapturedStruct. |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 281 | /// \param OutlinedFn Outlined function to be run in parallel threads. Type of |
| 282 | /// this function is void(*)(kmp_int32, kmp_int32, struct context_vars*). |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 283 | /// \param CapturedStruct A pointer to the record with the references to |
| 284 | /// variables used in \a OutlinedFn function. |
| 285 | /// |
| 286 | virtual void EmitOMPParallelCall(CodeGenFunction &CGF, SourceLocation Loc, |
| 287 | llvm::Value *OutlinedFn, |
| 288 | llvm::Value *CapturedStruct); |
| 289 | |
Alexey Bataev | d74d060 | 2014-10-13 06:02:40 +0000 | [diff] [blame] | 290 | /// \brief Emits code for serial call of the \a OutlinedFn with variables |
| 291 | /// captured in a record which address is stored in \a CapturedStruct. |
| 292 | /// \param OutlinedFn Outlined function to be run in serial mode. |
| 293 | /// \param CapturedStruct A pointer to the record with the references to |
| 294 | /// variables used in \a OutlinedFn function. |
| 295 | /// |
| 296 | virtual void EmitOMPSerialCall(CodeGenFunction &CGF, SourceLocation Loc, |
| 297 | llvm::Value *OutlinedFn, |
| 298 | llvm::Value *CapturedStruct); |
| 299 | |
Alexey Bataev | 75ddfab | 2014-12-01 11:32:38 +0000 | [diff] [blame] | 300 | /// \brief Emits a critical region. |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 301 | /// \param CriticalName Name of the critical region. |
Alexey Bataev | 75ddfab | 2014-12-01 11:32:38 +0000 | [diff] [blame] | 302 | /// \param CriticalOpGen Generator for the statement associated with the given |
| 303 | /// critical region. |
| 304 | virtual void EmitOMPCriticalRegion(CodeGenFunction &CGF, |
| 305 | StringRef CriticalName, |
| 306 | const std::function<void()> &CriticalOpGen, |
| 307 | SourceLocation Loc); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 308 | |
Alexey Bataev | 8d69065 | 2014-12-04 07:23:53 +0000 | [diff] [blame] | 309 | /// \brief Emits a master region. |
| 310 | /// \param MasterOpGen Generator for the statement associated with the given |
| 311 | /// master region. |
| 312 | virtual void EmitOMPMasterRegion(CodeGenFunction &CGF, |
| 313 | const std::function<void()> &MasterOpGen, |
| 314 | SourceLocation Loc); |
| 315 | |
Alexey Bataev | 9f797f3 | 2015-02-05 05:57:51 +0000 | [diff] [blame] | 316 | /// \brief Emits code for a taskyield directive. |
| 317 | virtual void EmitOMPTaskyieldCall(CodeGenFunction &CGF, SourceLocation Loc); |
| 318 | |
Alexey Bataev | 6956e2e | 2015-02-05 06:35:41 +0000 | [diff] [blame] | 319 | /// \brief Emits a single region. |
| 320 | /// \param SingleOpGen Generator for the statement associated with the given |
| 321 | /// single region. |
| 322 | virtual void EmitOMPSingleRegion(CodeGenFunction &CGF, |
| 323 | const std::function<void()> &SingleOpGen, |
| 324 | SourceLocation Loc); |
| 325 | |
Alexey Bataev | 8f7c1b0 | 2014-12-05 04:09:23 +0000 | [diff] [blame] | 326 | /// \brief Emits explicit barrier for OpenMP threads. |
| 327 | /// \param IsExplicit true, if it is explicitly specified barrier. |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 328 | /// |
| 329 | virtual void EmitOMPBarrierCall(CodeGenFunction &CGF, SourceLocation Loc, |
Alexey Bataev | 8f7c1b0 | 2014-12-05 04:09:23 +0000 | [diff] [blame] | 330 | bool IsExplicit = true); |
Alexey Bataev | b205978 | 2014-10-13 08:23:51 +0000 | [diff] [blame] | 331 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 332 | /// \brief Check if the specified \a ScheduleKind is static non-chunked. |
| 333 | /// This kind of worksharing directive is emitted without outer loop. |
| 334 | /// \param ScheduleKind Schedule kind specified in the 'schedule' clause. |
| 335 | /// \param Chunked True if chunk is specified in the clause. |
| 336 | /// |
| 337 | virtual bool isStaticNonchunked(OpenMPScheduleClauseKind ScheduleKind, |
| 338 | bool Chunked) const; |
| 339 | |
Alexander Musman | df7a8e2 | 2015-01-22 08:49:35 +0000 | [diff] [blame] | 340 | /// \brief Check if the specified \a ScheduleKind is dynamic. |
| 341 | /// This kind of worksharing directive is emitted without outer loop. |
| 342 | /// \param ScheduleKind Schedule Kind specified in the 'schedule' clause. |
| 343 | /// |
| 344 | virtual bool isDynamic(OpenMPScheduleClauseKind ScheduleKind) const; |
| 345 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 346 | /// \brief Call the appropriate runtime routine to initialize it before start |
| 347 | /// of loop. |
| 348 | /// |
| 349 | /// Depending on the loop schedule, it is nesessary to call some runtime |
| 350 | /// routine before start of the OpenMP loop to get the loop upper / lower |
| 351 | /// bounds \a LB and \a UB and stride \a ST. |
| 352 | /// |
| 353 | /// \param CGF Reference to current CodeGenFunction. |
| 354 | /// \param Loc Clang source location. |
NAKAMURA Takumi | eca0838 | 2014-12-17 14:47:06 +0000 | [diff] [blame] | 355 | /// \param SchedKind Schedule kind, specified by the 'schedule' clause. |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 356 | /// \param IVSize Size of the iteration variable in bits. |
| 357 | /// \param IVSigned Sign of the interation variable. |
| 358 | /// \param IL Address of the output variable in which the flag of the |
| 359 | /// last iteration is returned. |
| 360 | /// \param LB Address of the output variable in which the lower iteration |
| 361 | /// number is returned. |
| 362 | /// \param UB Address of the output variable in which the upper iteration |
| 363 | /// number is returned. |
| 364 | /// \param ST Address of the output variable in which the stride value is |
| 365 | /// returned nesessary to generated the static_chunked scheduled loop. |
| 366 | /// \param Chunk Value of the chunk for the static_chunked scheduled loop. |
| 367 | /// For the default (nullptr) value, the chunk 1 will be used. |
| 368 | /// |
| 369 | virtual void EmitOMPForInit(CodeGenFunction &CGF, SourceLocation Loc, |
| 370 | OpenMPScheduleClauseKind SchedKind, |
| 371 | unsigned IVSize, bool IVSigned, llvm::Value *IL, |
| 372 | llvm::Value *LB, llvm::Value *UB, llvm::Value *ST, |
| 373 | llvm::Value *Chunk = nullptr); |
| 374 | |
| 375 | /// \brief Call the appropriate runtime routine to notify that we finished |
| 376 | /// all the work with current loop. |
| 377 | /// |
| 378 | /// \param CGF Reference to current CodeGenFunction. |
| 379 | /// \param Loc Clang source location. |
| 380 | /// \param ScheduleKind Schedule kind, specified by the 'schedule' clause. |
| 381 | /// |
| 382 | virtual void EmitOMPForFinish(CodeGenFunction &CGF, SourceLocation Loc, |
| 383 | OpenMPScheduleClauseKind ScheduleKind); |
| 384 | |
Alexey Bataev | b205978 | 2014-10-13 08:23:51 +0000 | [diff] [blame] | 385 | /// \brief Emits call to void __kmpc_push_num_threads(ident_t *loc, kmp_int32 |
| 386 | /// global_tid, kmp_int32 num_threads) to generate code for 'num_threads' |
| 387 | /// clause. |
| 388 | /// \param NumThreads An integer value of threads. |
| 389 | virtual void EmitOMPNumThreadsClause(CodeGenFunction &CGF, |
| 390 | llvm::Value *NumThreads, |
| 391 | SourceLocation Loc); |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 392 | |
| 393 | /// \brief Returns address of the threadprivate variable for the current |
| 394 | /// thread. |
NAKAMURA Takumi | cdcbfba | 2014-11-11 07:58:06 +0000 | [diff] [blame] | 395 | /// \param VD Threadprivate variable. |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 396 | /// \param VDAddr Address of the global variable \a VD. |
| 397 | /// \param Loc Location of the reference to threadprivate var. |
| 398 | /// \return Address of the threadprivate variable for the current thread. |
| 399 | virtual llvm::Value *getOMPAddrOfThreadPrivate(CodeGenFunction &CGF, |
| 400 | const VarDecl *VD, |
| 401 | llvm::Value *VDAddr, |
| 402 | SourceLocation Loc); |
| 403 | |
| 404 | /// \brief Emit a code for initialization of threadprivate variable. It emits |
| 405 | /// a call to runtime library which adds initial value to the newly created |
| 406 | /// threadprivate variable (if it is not constant) and registers destructor |
| 407 | /// for the variable (if any). |
| 408 | /// \param VD Threadprivate variable. |
| 409 | /// \param VDAddr Address of the global variable \a VD. |
| 410 | /// \param Loc Location of threadprivate declaration. |
| 411 | /// \param PerformInit true if initialization expression is not constant. |
| 412 | virtual llvm::Function * |
| 413 | EmitOMPThreadPrivateVarDefinition(const VarDecl *VD, llvm::Value *VDAddr, |
| 414 | SourceLocation Loc, bool PerformInit, |
| 415 | CodeGenFunction *CGF = nullptr); |
Alexey Bataev | cc37cc1 | 2014-11-20 04:34:54 +0000 | [diff] [blame] | 416 | |
| 417 | /// \brief Emit flush of the variables specified in 'omp flush' directive. |
| 418 | /// \param Vars List of variables to flush. |
| 419 | virtual void EmitOMPFlush(CodeGenFunction &CGF, ArrayRef<const Expr *> Vars, |
| 420 | SourceLocation Loc); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 421 | }; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 422 | } // namespace CodeGen |
| 423 | } // namespace clang |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 424 | |
| 425 | #endif |