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 | |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 17 | #include "clang/AST/Type.h" |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 18 | #include "clang/Basic/OpenMPKinds.h" |
Chandler Carruth | 0d9593d | 2015-01-14 11:29:14 +0000 | [diff] [blame] | 19 | #include "clang/Basic/SourceLocation.h" |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/DenseMap.h" |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/DenseSet.h" |
Alexey Bataev | 3a3bf0b | 2014-09-22 10:01:53 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/StringMap.h" |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 23 | #include "llvm/IR/ValueHandle.h" |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 24 | |
| 25 | namespace llvm { |
| 26 | class ArrayType; |
| 27 | class Constant; |
| 28 | class Function; |
| 29 | class FunctionType; |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 30 | class GlobalVariable; |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 31 | class StructType; |
| 32 | class Type; |
| 33 | class Value; |
| 34 | } // namespace llvm |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 35 | |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 36 | namespace clang { |
Alexey Bataev | cc37cc1 | 2014-11-20 04:34:54 +0000 | [diff] [blame] | 37 | class Expr; |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 38 | class OMPExecutableDirective; |
| 39 | class VarDecl; |
| 40 | |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 41 | namespace CodeGen { |
| 42 | |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 43 | class CodeGenFunction; |
| 44 | class CodeGenModule; |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 45 | |
Alexey Bataev | 6f1ffc0 | 2015-04-10 04:50:10 +0000 | [diff] [blame] | 46 | typedef llvm::function_ref<void(CodeGenFunction &)> RegionCodeGenTy; |
| 47 | |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 48 | class CGOpenMPRuntime { |
Alexey Bataev | 6f1ffc0 | 2015-04-10 04:50:10 +0000 | [diff] [blame] | 49 | private: |
Alexey Bataev | 8f7c1b0 | 2014-12-05 04:09:23 +0000 | [diff] [blame] | 50 | enum OpenMPRTLFunction { |
| 51 | /// \brief Call to void __kmpc_fork_call(ident_t *loc, kmp_int32 argc, |
| 52 | /// kmpc_micro microtask, ...); |
| 53 | OMPRTL__kmpc_fork_call, |
| 54 | /// \brief Call to void *__kmpc_threadprivate_cached(ident_t *loc, |
| 55 | /// kmp_int32 global_tid, void *data, size_t size, void ***cache); |
| 56 | OMPRTL__kmpc_threadprivate_cached, |
| 57 | /// \brief Call to void __kmpc_threadprivate_register( ident_t *, |
| 58 | /// void *data, kmpc_ctor ctor, kmpc_cctor cctor, kmpc_dtor dtor); |
| 59 | OMPRTL__kmpc_threadprivate_register, |
| 60 | // Call to __kmpc_int32 kmpc_global_thread_num(ident_t *loc); |
| 61 | OMPRTL__kmpc_global_thread_num, |
| 62 | // Call to void __kmpc_critical(ident_t *loc, kmp_int32 global_tid, |
| 63 | // kmp_critical_name *crit); |
| 64 | OMPRTL__kmpc_critical, |
| 65 | // Call to void __kmpc_end_critical(ident_t *loc, kmp_int32 global_tid, |
| 66 | // kmp_critical_name *crit); |
| 67 | OMPRTL__kmpc_end_critical, |
| 68 | // Call to kmp_int32 __kmpc_cancel_barrier(ident_t *loc, kmp_int32 |
| 69 | // global_tid); |
| 70 | OMPRTL__kmpc_cancel_barrier, |
Alexander Musman | 21212e4 | 2015-03-13 10:38:23 +0000 | [diff] [blame] | 71 | // Call to void __kmpc_for_static_fini(ident_t *loc, kmp_int32 global_tid); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 72 | OMPRTL__kmpc_for_static_fini, |
Alexey Bataev | 8f7c1b0 | 2014-12-05 04:09:23 +0000 | [diff] [blame] | 73 | // Call to void __kmpc_serialized_parallel(ident_t *loc, kmp_int32 |
| 74 | // global_tid); |
| 75 | OMPRTL__kmpc_serialized_parallel, |
| 76 | // Call to void __kmpc_end_serialized_parallel(ident_t *loc, kmp_int32 |
| 77 | // global_tid); |
| 78 | OMPRTL__kmpc_end_serialized_parallel, |
| 79 | // Call to void __kmpc_push_num_threads(ident_t *loc, kmp_int32 global_tid, |
| 80 | // kmp_int32 num_threads); |
| 81 | OMPRTL__kmpc_push_num_threads, |
Alexey Bataev | d76df6d | 2015-02-24 12:55:09 +0000 | [diff] [blame] | 82 | // Call to void __kmpc_flush(ident_t *loc); |
Alexey Bataev | 8f7c1b0 | 2014-12-05 04:09:23 +0000 | [diff] [blame] | 83 | OMPRTL__kmpc_flush, |
| 84 | // Call to kmp_int32 __kmpc_master(ident_t *, kmp_int32 global_tid); |
| 85 | OMPRTL__kmpc_master, |
| 86 | // Call to void __kmpc_end_master(ident_t *, kmp_int32 global_tid); |
| 87 | OMPRTL__kmpc_end_master, |
Alexey Bataev | 9f797f3 | 2015-02-05 05:57:51 +0000 | [diff] [blame] | 88 | // Call to kmp_int32 __kmpc_omp_taskyield(ident_t *, kmp_int32 global_tid, |
| 89 | // int end_part); |
| 90 | OMPRTL__kmpc_omp_taskyield, |
Alexey Bataev | 6956e2e | 2015-02-05 06:35:41 +0000 | [diff] [blame] | 91 | // Call to kmp_int32 __kmpc_single(ident_t *, kmp_int32 global_tid); |
| 92 | OMPRTL__kmpc_single, |
| 93 | // Call to void __kmpc_end_single(ident_t *, kmp_int32 global_tid); |
| 94 | OMPRTL__kmpc_end_single, |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 95 | // Call to kmp_task_t * __kmpc_omp_task_alloc(ident_t *, kmp_int32 gtid, |
| 96 | // kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds, |
| 97 | // kmp_routine_entry_t *task_entry); |
| 98 | OMPRTL__kmpc_omp_task_alloc, |
| 99 | // Call to kmp_int32 __kmpc_omp_task(ident_t *, kmp_int32 gtid, kmp_task_t * |
| 100 | // new_task); |
| 101 | OMPRTL__kmpc_omp_task, |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 102 | // Call to void __kmpc_copyprivate(ident_t *loc, kmp_int32 global_tid, |
Alexey Bataev | 66beaa9 | 2015-04-30 03:47:32 +0000 | [diff] [blame] | 103 | // size_t cpy_size, void *cpy_data, void(*cpy_func)(void *, void *), |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 104 | // kmp_int32 didit); |
| 105 | OMPRTL__kmpc_copyprivate, |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 106 | // Call to kmp_int32 __kmpc_reduce(ident_t *loc, kmp_int32 global_tid, |
| 107 | // kmp_int32 num_vars, size_t reduce_size, void *reduce_data, void |
| 108 | // (*reduce_func)(void *lhs_data, void *rhs_data), kmp_critical_name *lck); |
| 109 | OMPRTL__kmpc_reduce, |
| 110 | // Call to kmp_int32 __kmpc_reduce_nowait(ident_t *loc, kmp_int32 |
| 111 | // global_tid, kmp_int32 num_vars, size_t reduce_size, void *reduce_data, |
| 112 | // void (*reduce_func)(void *lhs_data, void *rhs_data), kmp_critical_name |
| 113 | // *lck); |
| 114 | OMPRTL__kmpc_reduce_nowait, |
| 115 | // Call to void __kmpc_end_reduce(ident_t *loc, kmp_int32 global_tid, |
| 116 | // kmp_critical_name *lck); |
| 117 | OMPRTL__kmpc_end_reduce, |
| 118 | // Call to void __kmpc_end_reduce_nowait(ident_t *loc, kmp_int32 global_tid, |
| 119 | // kmp_critical_name *lck); |
| 120 | OMPRTL__kmpc_end_reduce_nowait, |
Alexey Bataev | 1d67713 | 2015-04-22 13:57:31 +0000 | [diff] [blame] | 121 | // Call to void __kmpc_omp_task_begin_if0(ident_t *, kmp_int32 gtid, |
| 122 | // kmp_task_t * new_task); |
| 123 | OMPRTL__kmpc_omp_task_begin_if0, |
| 124 | // Call to void __kmpc_omp_task_complete_if0(ident_t *, kmp_int32 gtid, |
| 125 | // kmp_task_t * new_task); |
| 126 | OMPRTL__kmpc_omp_task_complete_if0, |
Alexey Bataev | 98eb6e3 | 2015-04-22 11:15:40 +0000 | [diff] [blame] | 127 | // Call to void __kmpc_ordered(ident_t *loc, kmp_int32 global_tid); |
| 128 | OMPRTL__kmpc_ordered, |
| 129 | // Call to void __kmpc_end_ordered(ident_t *loc, kmp_int32 global_tid); |
| 130 | OMPRTL__kmpc_end_ordered, |
Alexey Bataev | 8b8e202 | 2015-04-27 05:22:09 +0000 | [diff] [blame] | 131 | // Call to kmp_int32 __kmpc_omp_taskwait(ident_t *loc, kmp_int32 |
| 132 | // global_tid); |
| 133 | OMPRTL__kmpc_omp_taskwait, |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 134 | // Call to void __kmpc_taskgroup(ident_t *loc, kmp_int32 global_tid); |
| 135 | OMPRTL__kmpc_taskgroup, |
| 136 | // Call to void __kmpc_end_taskgroup(ident_t *loc, kmp_int32 global_tid); |
| 137 | OMPRTL__kmpc_end_taskgroup, |
Alexey Bataev | 8f7c1b0 | 2014-12-05 04:09:23 +0000 | [diff] [blame] | 138 | }; |
| 139 | |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 140 | /// \brief Values for bit flags used in the ident_t to describe the fields. |
| 141 | /// All enumeric elements are named and described in accordance with the code |
| 142 | /// from http://llvm.org/svn/llvm-project/openmp/trunk/runtime/src/kmp.h |
| 143 | enum OpenMPLocationFlags { |
| 144 | /// \brief Use trampoline for internal microtask. |
| 145 | OMP_IDENT_IMD = 0x01, |
| 146 | /// \brief Use c-style ident structure. |
| 147 | OMP_IDENT_KMPC = 0x02, |
| 148 | /// \brief Atomic reduction option for kmpc_reduce. |
| 149 | OMP_ATOMIC_REDUCE = 0x10, |
| 150 | /// \brief Explicit 'barrier' directive. |
| 151 | OMP_IDENT_BARRIER_EXPL = 0x20, |
| 152 | /// \brief Implicit barrier in code. |
| 153 | OMP_IDENT_BARRIER_IMPL = 0x40, |
| 154 | /// \brief Implicit barrier in 'for' directive. |
| 155 | OMP_IDENT_BARRIER_IMPL_FOR = 0x40, |
| 156 | /// \brief Implicit barrier in 'sections' directive. |
| 157 | OMP_IDENT_BARRIER_IMPL_SECTIONS = 0xC0, |
| 158 | /// \brief Implicit barrier in 'single' directive. |
| 159 | OMP_IDENT_BARRIER_IMPL_SINGLE = 0x140 |
| 160 | }; |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 161 | CodeGenModule &CGM; |
| 162 | /// \brief Default const ident_t object used for initialization of all other |
| 163 | /// ident_t objects. |
| 164 | llvm::Constant *DefaultOpenMPPSource; |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 165 | /// \brief Map of flags and corresponding default locations. |
Alexey Bataev | 15007ba | 2014-05-07 06:18:01 +0000 | [diff] [blame] | 166 | typedef llvm::DenseMap<unsigned, llvm::Value *> OpenMPDefaultLocMapTy; |
| 167 | OpenMPDefaultLocMapTy OpenMPDefaultLocMap; |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 168 | llvm::Value *getOrCreateDefaultLocation(OpenMPLocationFlags Flags); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 169 | /// \brief Describes ident structure that describes a source location. |
| 170 | /// All descriptions are taken from |
| 171 | /// http://llvm.org/svn/llvm-project/openmp/trunk/runtime/src/kmp.h |
| 172 | /// Original structure: |
| 173 | /// typedef struct ident { |
| 174 | /// kmp_int32 reserved_1; /**< might be used in Fortran; |
| 175 | /// see above */ |
| 176 | /// kmp_int32 flags; /**< also f.flags; KMP_IDENT_xxx flags; |
| 177 | /// KMP_IDENT_KMPC identifies this union |
| 178 | /// member */ |
| 179 | /// kmp_int32 reserved_2; /**< not really used in Fortran any more; |
| 180 | /// see above */ |
| 181 | ///#if USE_ITT_BUILD |
| 182 | /// /* but currently used for storing |
| 183 | /// region-specific ITT */ |
| 184 | /// /* contextual information. */ |
| 185 | ///#endif /* USE_ITT_BUILD */ |
| 186 | /// kmp_int32 reserved_3; /**< source[4] in Fortran, do not use for |
| 187 | /// C++ */ |
| 188 | /// char const *psource; /**< String describing the source location. |
| 189 | /// The string is composed of semi-colon separated |
| 190 | // fields which describe the source file, |
| 191 | /// the function and a pair of line numbers that |
| 192 | /// delimit the construct. |
| 193 | /// */ |
| 194 | /// } ident_t; |
| 195 | enum IdentFieldIndex { |
| 196 | /// \brief might be used in Fortran |
| 197 | IdentField_Reserved_1, |
| 198 | /// \brief OMP_IDENT_xxx flags; OMP_IDENT_KMPC identifies this union member. |
| 199 | IdentField_Flags, |
| 200 | /// \brief Not really used in Fortran any more |
| 201 | IdentField_Reserved_2, |
| 202 | /// \brief Source[4] in Fortran, do not use for C++ |
| 203 | IdentField_Reserved_3, |
| 204 | /// \brief String describing the source location. The string is composed of |
| 205 | /// semi-colon separated fields which describe the source file, the function |
| 206 | /// and a pair of line numbers that delimit the construct. |
| 207 | IdentField_PSource |
| 208 | }; |
| 209 | llvm::StructType *IdentTy; |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 210 | /// \brief Map for SourceLocation and OpenMP runtime library debug locations. |
Alexey Bataev | f002aca | 2014-05-30 05:48:40 +0000 | [diff] [blame] | 211 | typedef llvm::DenseMap<unsigned, llvm::Value *> OpenMPDebugLocMapTy; |
| 212 | OpenMPDebugLocMapTy OpenMPDebugLocMap; |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 213 | /// \brief The type for a microtask which gets passed to __kmpc_fork_call(). |
| 214 | /// Original representation is: |
| 215 | /// typedef void (kmpc_micro)(kmp_int32 global_tid, kmp_int32 bound_tid,...); |
| 216 | llvm::FunctionType *Kmpc_MicroTy; |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 217 | /// \brief Stores debug location and ThreadID for the function. |
| 218 | struct DebugLocThreadIdTy { |
| 219 | llvm::Value *DebugLoc; |
| 220 | llvm::Value *ThreadID; |
| 221 | }; |
| 222 | /// \brief Map of local debug location, ThreadId and functions. |
| 223 | typedef llvm::DenseMap<llvm::Function *, DebugLocThreadIdTy> |
| 224 | OpenMPLocThreadIDMapTy; |
| 225 | OpenMPLocThreadIDMapTy OpenMPLocThreadIDMap; |
Alexey Bataev | 3a3bf0b | 2014-09-22 10:01:53 +0000 | [diff] [blame] | 226 | /// \brief Type kmp_critical_name, originally defined as typedef kmp_int32 |
| 227 | /// kmp_critical_name[8]; |
| 228 | llvm::ArrayType *KmpCriticalNameTy; |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 229 | /// \brief An ordered map of auto-generated variables to their unique names. |
| 230 | /// It stores variables with the following names: 1) ".gomp_critical_user_" + |
| 231 | /// <critical_section_name> + ".var" for "omp critical" directives; 2) |
| 232 | /// <mangled_name_for_global_var> + ".cache." for cache for threadprivate |
| 233 | /// variables. |
| 234 | llvm::StringMap<llvm::AssertingVH<llvm::Constant>, llvm::BumpPtrAllocator> |
| 235 | InternalVars; |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 236 | /// \brief Type typedef kmp_int32 (* kmp_routine_entry_t)(kmp_int32, void *); |
| 237 | llvm::Type *KmpRoutineEntryPtrTy; |
| 238 | QualType KmpRoutineEntryPtrQTy; |
Alexey Bataev | 8fc69dc | 2015-05-18 07:54:53 +0000 | [diff] [blame] | 239 | /// \brief Type typedef struct kmp_task { |
| 240 | /// void * shareds; /**< pointer to block of pointers to |
| 241 | /// shared vars */ |
| 242 | /// kmp_routine_entry_t routine; /**< pointer to routine to call for |
| 243 | /// executing task */ |
| 244 | /// kmp_int32 part_id; /**< part id for the task */ |
| 245 | /// kmp_routine_entry_t destructors; /* pointer to function to invoke |
| 246 | /// deconstructors of firstprivate C++ objects */ |
| 247 | /// } kmp_task_t; |
| 248 | QualType KmpTaskTQTy; |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 249 | |
| 250 | /// \brief Build type kmp_routine_entry_t (if not built yet). |
| 251 | void emitKmpRoutineEntryT(QualType KmpInt32Ty); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 252 | |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 253 | /// \brief Emits object of ident_t type with info for source location. |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 254 | /// \param Flags Flags for OpenMP location. |
| 255 | /// |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 256 | llvm::Value *emitUpdateLocation(CodeGenFunction &CGF, SourceLocation Loc, |
| 257 | OpenMPLocationFlags Flags = OMP_IDENT_KMPC); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 258 | |
Alexey Bataev | d74d060 | 2014-10-13 06:02:40 +0000 | [diff] [blame] | 259 | /// \brief Returns pointer to ident_t type. |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 260 | llvm::Type *getIdentTyPointerTy(); |
| 261 | |
Alexey Bataev | d74d060 | 2014-10-13 06:02:40 +0000 | [diff] [blame] | 262 | /// \brief Returns pointer to kmpc_micro type. |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 263 | llvm::Type *getKmpc_MicroPointerTy(); |
| 264 | |
| 265 | /// \brief Returns specified OpenMP runtime function. |
| 266 | /// \param Function OpenMP runtime function. |
| 267 | /// \return Specified function. |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 268 | llvm::Constant *createRuntimeFunction(OpenMPRTLFunction Function); |
Alexey Bataev | 3a3bf0b | 2014-09-22 10:01:53 +0000 | [diff] [blame] | 269 | |
Alexander Musman | 21212e4 | 2015-03-13 10:38:23 +0000 | [diff] [blame] | 270 | /// \brief Returns __kmpc_for_static_init_* runtime function for the specified |
| 271 | /// size \a IVSize and sign \a IVSigned. |
| 272 | llvm::Constant *createForStaticInitFunction(unsigned IVSize, bool IVSigned); |
| 273 | |
Alexander Musman | 92bdaab | 2015-03-12 13:37:50 +0000 | [diff] [blame] | 274 | /// \brief Returns __kmpc_dispatch_init_* runtime function for the specified |
| 275 | /// size \a IVSize and sign \a IVSigned. |
| 276 | llvm::Constant *createDispatchInitFunction(unsigned IVSize, bool IVSigned); |
| 277 | |
| 278 | /// \brief Returns __kmpc_dispatch_next_* runtime function for the specified |
| 279 | /// size \a IVSize and sign \a IVSigned. |
| 280 | llvm::Constant *createDispatchNextFunction(unsigned IVSize, bool IVSigned); |
| 281 | |
Alexey Bataev | 98eb6e3 | 2015-04-22 11:15:40 +0000 | [diff] [blame] | 282 | /// \brief Returns __kmpc_dispatch_fini_* runtime function for the specified |
| 283 | /// size \a IVSize and sign \a IVSigned. |
| 284 | llvm::Constant *createDispatchFiniFunction(unsigned IVSize, bool IVSigned); |
| 285 | |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 286 | /// \brief If the specified mangled name is not in the module, create and |
| 287 | /// return threadprivate cache object. This object is a pointer's worth of |
| 288 | /// storage that's reserved for use by the OpenMP runtime. |
NAKAMURA Takumi | cdcbfba | 2014-11-11 07:58:06 +0000 | [diff] [blame] | 289 | /// \param VD Threadprivate variable. |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 290 | /// \return Cache variable for the specified threadprivate. |
| 291 | llvm::Constant *getOrCreateThreadPrivateCache(const VarDecl *VD); |
| 292 | |
Alexey Bataev | d74d060 | 2014-10-13 06:02:40 +0000 | [diff] [blame] | 293 | /// \brief Emits address of the word in a memory where current thread id is |
| 294 | /// stored. |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 295 | virtual llvm::Value *emitThreadIDAddress(CodeGenFunction &CGF, |
Alexey Bataev | d74d060 | 2014-10-13 06:02:40 +0000 | [diff] [blame] | 296 | SourceLocation Loc); |
| 297 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 298 | /// \brief Gets thread id value for the current thread. |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 299 | /// |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 300 | llvm::Value *getThreadID(CodeGenFunction &CGF, SourceLocation Loc); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 301 | |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 302 | /// \brief Gets (if variable with the given name already exist) or creates |
| 303 | /// internal global variable with the specified Name. The created variable has |
| 304 | /// linkage CommonLinkage by default and is initialized by null value. |
| 305 | /// \param Ty Type of the global variable. If it is exist already the type |
| 306 | /// must be the same. |
| 307 | /// \param Name Name of the variable. |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 308 | llvm::Constant *getOrCreateInternalVariable(llvm::Type *Ty, |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 309 | const llvm::Twine &Name); |
| 310 | |
| 311 | /// \brief Set of threadprivate variables with the generated initializer. |
| 312 | llvm::DenseSet<const VarDecl *> ThreadPrivateWithDefinition; |
| 313 | |
| 314 | /// \brief Emits initialization code for the threadprivate variables. |
| 315 | /// \param VDAddr Address of the global variable \a VD. |
| 316 | /// \param Ctor Pointer to a global init function for \a VD. |
| 317 | /// \param CopyCtor Pointer to a global copy function for \a VD. |
| 318 | /// \param Dtor Pointer to a global destructor function for \a VD. |
| 319 | /// \param Loc Location of threadprivate declaration. |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 320 | void emitThreadPrivateVarInit(CodeGenFunction &CGF, llvm::Value *VDAddr, |
| 321 | llvm::Value *Ctor, llvm::Value *CopyCtor, |
| 322 | llvm::Value *Dtor, SourceLocation Loc); |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 323 | |
Alexey Bataev | 75ddfab | 2014-12-01 11:32:38 +0000 | [diff] [blame] | 324 | /// \brief Returns corresponding lock object for the specified critical region |
| 325 | /// name. If the lock object does not exist it is created, otherwise the |
| 326 | /// reference to the existing copy is returned. |
| 327 | /// \param CriticalName Name of the critical region. |
| 328 | /// |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 329 | llvm::Value *getCriticalRegionLock(StringRef CriticalName); |
Alexey Bataev | 75ddfab | 2014-12-01 11:32:38 +0000 | [diff] [blame] | 330 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 331 | public: |
| 332 | explicit CGOpenMPRuntime(CodeGenModule &CGM); |
| 333 | virtual ~CGOpenMPRuntime() {} |
Alexey Bataev | 9179755 | 2015-03-18 04:13:55 +0000 | [diff] [blame] | 334 | virtual void clear(); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 335 | |
Alexey Bataev | 6f1ffc0 | 2015-04-10 04:50:10 +0000 | [diff] [blame] | 336 | /// \brief Emits outlined function for the specified OpenMP parallel directive |
| 337 | /// \a D. This outlined function has type void(*)(kmp_int32 *ThreadID, |
| 338 | /// kmp_int32 BoundID, struct context_vars*). |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 339 | /// \param D OpenMP directive. |
| 340 | /// \param ThreadIDVar Variable for thread id in the current OpenMP region. |
Alexey Bataev | 6f1ffc0 | 2015-04-10 04:50:10 +0000 | [diff] [blame] | 341 | /// \param CodeGen Code generation sequence for the \a D directive. |
| 342 | virtual llvm::Value * |
| 343 | emitParallelOutlinedFunction(const OMPExecutableDirective &D, |
| 344 | const VarDecl *ThreadIDVar, |
| 345 | const RegionCodeGenTy &CodeGen); |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 346 | |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 347 | /// \brief Emits outlined function for the OpenMP task directive \a D. This |
| 348 | /// outlined function has type void(*)(kmp_int32 ThreadID, kmp_int32 |
| 349 | /// PartID, struct context_vars*). |
| 350 | /// \param D OpenMP directive. |
| 351 | /// \param ThreadIDVar Variable for thread id in the current OpenMP region. |
Alexey Bataev | 6f1ffc0 | 2015-04-10 04:50:10 +0000 | [diff] [blame] | 352 | /// \param CodeGen Code generation sequence for the \a D directive. |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 353 | /// |
| 354 | virtual llvm::Value *emitTaskOutlinedFunction(const OMPExecutableDirective &D, |
| 355 | const VarDecl *ThreadIDVar, |
Alexey Bataev | 6f1ffc0 | 2015-04-10 04:50:10 +0000 | [diff] [blame] | 356 | const RegionCodeGenTy &CodeGen); |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 357 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 358 | /// \brief Cleans up references to the objects in finished function. |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 359 | /// |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 360 | void functionFinished(CodeGenFunction &CGF); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 361 | |
Alexey Bataev | 1d67713 | 2015-04-22 13:57:31 +0000 | [diff] [blame] | 362 | /// \brief Emits code for parallel or serial call of the \a OutlinedFn with |
| 363 | /// variables captured in a record which address is stored in \a |
| 364 | /// CapturedStruct. |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 365 | /// \param OutlinedFn Outlined function to be run in parallel threads. Type of |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 366 | /// this function is void(*)(kmp_int32 *, kmp_int32, struct context_vars*). |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 367 | /// \param CapturedStruct A pointer to the record with the references to |
| 368 | /// variables used in \a OutlinedFn function. |
Alexey Bataev | 1d67713 | 2015-04-22 13:57:31 +0000 | [diff] [blame] | 369 | /// \param IfCond Condition in the associated 'if' clause, if it was |
| 370 | /// specified, nullptr otherwise. |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 371 | /// |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 372 | virtual void emitParallelCall(CodeGenFunction &CGF, SourceLocation Loc, |
| 373 | llvm::Value *OutlinedFn, |
Alexey Bataev | 1d67713 | 2015-04-22 13:57:31 +0000 | [diff] [blame] | 374 | llvm::Value *CapturedStruct, |
| 375 | const Expr *IfCond); |
Alexey Bataev | d74d060 | 2014-10-13 06:02:40 +0000 | [diff] [blame] | 376 | |
Alexey Bataev | 75ddfab | 2014-12-01 11:32:38 +0000 | [diff] [blame] | 377 | /// \brief Emits a critical region. |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 378 | /// \param CriticalName Name of the critical region. |
Alexey Bataev | 75ddfab | 2014-12-01 11:32:38 +0000 | [diff] [blame] | 379 | /// \param CriticalOpGen Generator for the statement associated with the given |
| 380 | /// critical region. |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 381 | virtual void emitCriticalRegion(CodeGenFunction &CGF, StringRef CriticalName, |
Alexey Bataev | 6f1ffc0 | 2015-04-10 04:50:10 +0000 | [diff] [blame] | 382 | const RegionCodeGenTy &CriticalOpGen, |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 383 | SourceLocation Loc); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 384 | |
Alexey Bataev | 8d69065 | 2014-12-04 07:23:53 +0000 | [diff] [blame] | 385 | /// \brief Emits a master region. |
| 386 | /// \param MasterOpGen Generator for the statement associated with the given |
| 387 | /// master region. |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 388 | virtual void emitMasterRegion(CodeGenFunction &CGF, |
Alexey Bataev | 6f1ffc0 | 2015-04-10 04:50:10 +0000 | [diff] [blame] | 389 | const RegionCodeGenTy &MasterOpGen, |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 390 | SourceLocation Loc); |
Alexey Bataev | 8d69065 | 2014-12-04 07:23:53 +0000 | [diff] [blame] | 391 | |
Alexey Bataev | 9f797f3 | 2015-02-05 05:57:51 +0000 | [diff] [blame] | 392 | /// \brief Emits code for a taskyield directive. |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 393 | virtual void emitTaskyieldCall(CodeGenFunction &CGF, SourceLocation Loc); |
Alexey Bataev | 9f797f3 | 2015-02-05 05:57:51 +0000 | [diff] [blame] | 394 | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 395 | /// \brief Emit a taskgroup region. |
| 396 | /// \param TaskgroupOpGen Generator for the statement associated with the |
| 397 | /// given taskgroup region. |
| 398 | virtual void emitTaskgroupRegion(CodeGenFunction &CGF, |
| 399 | const RegionCodeGenTy &TaskgroupOpGen, |
| 400 | SourceLocation Loc); |
| 401 | |
Alexey Bataev | 6956e2e | 2015-02-05 06:35:41 +0000 | [diff] [blame] | 402 | /// \brief Emits a single region. |
| 403 | /// \param SingleOpGen Generator for the statement associated with the given |
| 404 | /// single region. |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 405 | virtual void emitSingleRegion(CodeGenFunction &CGF, |
Alexey Bataev | 6f1ffc0 | 2015-04-10 04:50:10 +0000 | [diff] [blame] | 406 | const RegionCodeGenTy &SingleOpGen, |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 407 | SourceLocation Loc, |
| 408 | ArrayRef<const Expr *> CopyprivateVars, |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 409 | ArrayRef<const Expr *> DestExprs, |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 410 | ArrayRef<const Expr *> SrcExprs, |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 411 | ArrayRef<const Expr *> AssignmentOps); |
Alexey Bataev | 6956e2e | 2015-02-05 06:35:41 +0000 | [diff] [blame] | 412 | |
Alexey Bataev | 98eb6e3 | 2015-04-22 11:15:40 +0000 | [diff] [blame] | 413 | /// \brief Emit an ordered region. |
| 414 | /// \param OrderedOpGen Generator for the statement associated with the given |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 415 | /// ordered region. |
Alexey Bataev | 98eb6e3 | 2015-04-22 11:15:40 +0000 | [diff] [blame] | 416 | virtual void emitOrderedRegion(CodeGenFunction &CGF, |
| 417 | const RegionCodeGenTy &OrderedOpGen, |
| 418 | SourceLocation Loc); |
| 419 | |
Alexey Bataev | f268568 | 2015-03-30 04:30:22 +0000 | [diff] [blame] | 420 | /// \brief Emit an implicit/explicit barrier for OpenMP threads. |
| 421 | /// \param Kind Directive for which this implicit barrier call must be |
| 422 | /// generated. Must be OMPD_barrier for explicit barrier generation. |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 423 | /// |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 424 | virtual void emitBarrierCall(CodeGenFunction &CGF, SourceLocation Loc, |
Alexey Bataev | f268568 | 2015-03-30 04:30:22 +0000 | [diff] [blame] | 425 | OpenMPDirectiveKind Kind); |
Alexey Bataev | b205978 | 2014-10-13 08:23:51 +0000 | [diff] [blame] | 426 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 427 | /// \brief Check if the specified \a ScheduleKind is static non-chunked. |
| 428 | /// This kind of worksharing directive is emitted without outer loop. |
| 429 | /// \param ScheduleKind Schedule kind specified in the 'schedule' clause. |
| 430 | /// \param Chunked True if chunk is specified in the clause. |
| 431 | /// |
| 432 | virtual bool isStaticNonchunked(OpenMPScheduleClauseKind ScheduleKind, |
| 433 | bool Chunked) const; |
| 434 | |
Alexander Musman | df7a8e2 | 2015-01-22 08:49:35 +0000 | [diff] [blame] | 435 | /// \brief Check if the specified \a ScheduleKind is dynamic. |
| 436 | /// This kind of worksharing directive is emitted without outer loop. |
| 437 | /// \param ScheduleKind Schedule Kind specified in the 'schedule' clause. |
| 438 | /// |
| 439 | virtual bool isDynamic(OpenMPScheduleClauseKind ScheduleKind) const; |
| 440 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 441 | /// \brief Call the appropriate runtime routine to initialize it before start |
| 442 | /// of loop. |
| 443 | /// |
| 444 | /// Depending on the loop schedule, it is nesessary to call some runtime |
| 445 | /// routine before start of the OpenMP loop to get the loop upper / lower |
| 446 | /// bounds \a LB and \a UB and stride \a ST. |
| 447 | /// |
| 448 | /// \param CGF Reference to current CodeGenFunction. |
| 449 | /// \param Loc Clang source location. |
NAKAMURA Takumi | eca0838 | 2014-12-17 14:47:06 +0000 | [diff] [blame] | 450 | /// \param SchedKind Schedule kind, specified by the 'schedule' clause. |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 451 | /// \param IVSize Size of the iteration variable in bits. |
| 452 | /// \param IVSigned Sign of the interation variable. |
Alexey Bataev | d7589ffe | 2015-05-20 13:12:48 +0000 | [diff] [blame] | 453 | /// \param Ordered true if loop is ordered, false otherwise. |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 454 | /// \param IL Address of the output variable in which the flag of the |
| 455 | /// last iteration is returned. |
| 456 | /// \param LB Address of the output variable in which the lower iteration |
| 457 | /// number is returned. |
| 458 | /// \param UB Address of the output variable in which the upper iteration |
| 459 | /// number is returned. |
| 460 | /// \param ST Address of the output variable in which the stride value is |
| 461 | /// returned nesessary to generated the static_chunked scheduled loop. |
| 462 | /// \param Chunk Value of the chunk for the static_chunked scheduled loop. |
| 463 | /// For the default (nullptr) value, the chunk 1 will be used. |
| 464 | /// |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 465 | virtual void emitForInit(CodeGenFunction &CGF, SourceLocation Loc, |
| 466 | OpenMPScheduleClauseKind SchedKind, unsigned IVSize, |
Alexey Bataev | d7589ffe | 2015-05-20 13:12:48 +0000 | [diff] [blame] | 467 | bool IVSigned, bool Ordered, llvm::Value *IL, |
| 468 | llvm::Value *LB, llvm::Value *UB, llvm::Value *ST, |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 469 | llvm::Value *Chunk = nullptr); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 470 | |
| 471 | /// \brief Call the appropriate runtime routine to notify that we finished |
Alexey Bataev | 98eb6e3 | 2015-04-22 11:15:40 +0000 | [diff] [blame] | 472 | /// iteration of the ordered loop with the dynamic scheduling. |
| 473 | /// |
| 474 | /// \param CGF Reference to current CodeGenFunction. |
| 475 | /// \param Loc Clang source location. |
| 476 | /// \param IVSize Size of the iteration variable in bits. |
| 477 | /// \param IVSigned Sign of the interation variable. |
| 478 | /// |
Alexey Bataev | d7589ffe | 2015-05-20 13:12:48 +0000 | [diff] [blame] | 479 | virtual void emitForOrderedIterationEnd(CodeGenFunction &CGF, |
| 480 | SourceLocation Loc, unsigned IVSize, |
| 481 | bool IVSigned); |
Alexey Bataev | 98eb6e3 | 2015-04-22 11:15:40 +0000 | [diff] [blame] | 482 | |
| 483 | /// \brief Call the appropriate runtime routine to notify that we finished |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 484 | /// all the work with current loop. |
| 485 | /// |
| 486 | /// \param CGF Reference to current CodeGenFunction. |
| 487 | /// \param Loc Clang source location. |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 488 | /// |
Alexey Bataev | 98eb6e3 | 2015-04-22 11:15:40 +0000 | [diff] [blame] | 489 | virtual void emitForStaticFinish(CodeGenFunction &CGF, SourceLocation Loc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 490 | |
Alexander Musman | 92bdaab | 2015-03-12 13:37:50 +0000 | [diff] [blame] | 491 | /// Call __kmpc_dispatch_next( |
| 492 | /// ident_t *loc, kmp_int32 tid, kmp_int32 *p_lastiter, |
| 493 | /// kmp_int[32|64] *p_lower, kmp_int[32|64] *p_upper, |
| 494 | /// kmp_int[32|64] *p_stride); |
| 495 | /// \param IVSize Size of the iteration variable in bits. |
| 496 | /// \param IVSigned Sign of the interation variable. |
| 497 | /// \param IL Address of the output variable in which the flag of the |
| 498 | /// last iteration is returned. |
| 499 | /// \param LB Address of the output variable in which the lower iteration |
| 500 | /// number is returned. |
| 501 | /// \param UB Address of the output variable in which the upper iteration |
| 502 | /// number is returned. |
| 503 | /// \param ST Address of the output variable in which the stride value is |
| 504 | /// returned. |
| 505 | virtual llvm::Value *emitForNext(CodeGenFunction &CGF, SourceLocation Loc, |
| 506 | unsigned IVSize, bool IVSigned, |
| 507 | llvm::Value *IL, llvm::Value *LB, |
| 508 | llvm::Value *UB, llvm::Value *ST); |
| 509 | |
Alexey Bataev | b205978 | 2014-10-13 08:23:51 +0000 | [diff] [blame] | 510 | /// \brief Emits call to void __kmpc_push_num_threads(ident_t *loc, kmp_int32 |
| 511 | /// global_tid, kmp_int32 num_threads) to generate code for 'num_threads' |
| 512 | /// clause. |
| 513 | /// \param NumThreads An integer value of threads. |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 514 | virtual void emitNumThreadsClause(CodeGenFunction &CGF, |
| 515 | llvm::Value *NumThreads, |
| 516 | SourceLocation Loc); |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 517 | |
| 518 | /// \brief Returns address of the threadprivate variable for the current |
| 519 | /// thread. |
NAKAMURA Takumi | cdcbfba | 2014-11-11 07:58:06 +0000 | [diff] [blame] | 520 | /// \param VD Threadprivate variable. |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 521 | /// \param VDAddr Address of the global variable \a VD. |
| 522 | /// \param Loc Location of the reference to threadprivate var. |
| 523 | /// \return Address of the threadprivate variable for the current thread. |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 524 | virtual llvm::Value *getAddrOfThreadPrivate(CodeGenFunction &CGF, |
| 525 | const VarDecl *VD, |
| 526 | llvm::Value *VDAddr, |
| 527 | SourceLocation Loc); |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 528 | |
| 529 | /// \brief Emit a code for initialization of threadprivate variable. It emits |
| 530 | /// a call to runtime library which adds initial value to the newly created |
| 531 | /// threadprivate variable (if it is not constant) and registers destructor |
| 532 | /// for the variable (if any). |
| 533 | /// \param VD Threadprivate variable. |
| 534 | /// \param VDAddr Address of the global variable \a VD. |
| 535 | /// \param Loc Location of threadprivate declaration. |
| 536 | /// \param PerformInit true if initialization expression is not constant. |
| 537 | virtual llvm::Function * |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 538 | emitThreadPrivateVarDefinition(const VarDecl *VD, llvm::Value *VDAddr, |
| 539 | SourceLocation Loc, bool PerformInit, |
| 540 | CodeGenFunction *CGF = nullptr); |
Alexey Bataev | cc37cc1 | 2014-11-20 04:34:54 +0000 | [diff] [blame] | 541 | |
| 542 | /// \brief Emit flush of the variables specified in 'omp flush' directive. |
| 543 | /// \param Vars List of variables to flush. |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 544 | virtual void emitFlush(CodeGenFunction &CGF, ArrayRef<const Expr *> Vars, |
| 545 | SourceLocation Loc); |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 546 | |
| 547 | /// \brief Emit task region for the task directive. The task region is |
Nico Weber | 20b0ce3 | 2015-04-28 18:19:18 +0000 | [diff] [blame] | 548 | /// emitted in several steps: |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 549 | /// 1. Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32 |
| 550 | /// gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds, |
| 551 | /// kmp_routine_entry_t *task_entry). Here task_entry is a pointer to the |
| 552 | /// function: |
| 553 | /// kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) { |
| 554 | /// TaskFunction(gtid, tt->part_id, tt->shareds); |
| 555 | /// return 0; |
| 556 | /// } |
| 557 | /// 2. Copy a list of shared variables to field shareds of the resulting |
| 558 | /// structure kmp_task_t returned by the previous call (if any). |
| 559 | /// 3. Copy a pointer to destructions function to field destructions of the |
| 560 | /// resulting structure kmp_task_t. |
| 561 | /// 4. Emit a call to kmp_int32 __kmpc_omp_task(ident_t *, kmp_int32 gtid, |
| 562 | /// kmp_task_t *new_task), where new_task is a resulting structure from |
| 563 | /// previous items. |
Alexey Bataev | 36c1eb9 | 2015-04-30 06:51:57 +0000 | [diff] [blame] | 564 | /// \param D Current task directive. |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 565 | /// \param Tied true if the task is tied (the task is tied to the thread that |
| 566 | /// can suspend its task region), false - untied (the task is not tied to any |
| 567 | /// thread). |
| 568 | /// \param Final Contains either constant bool value, or llvm::Value * of i1 |
| 569 | /// type for final clause. If the value is true, the task forces all of its |
| 570 | /// child tasks to become final and included tasks. |
| 571 | /// \param TaskFunction An LLVM function with type void (*)(i32 /*gtid*/, i32 |
| 572 | /// /*part_id*/, captured_struct */*__context*/); |
| 573 | /// \param SharedsTy A type which contains references the shared variables. |
| 574 | /// \param Shareds Context with the list of shared variables from the \a |
| 575 | /// TaskFunction. |
Alexey Bataev | 1d67713 | 2015-04-22 13:57:31 +0000 | [diff] [blame] | 576 | /// \param IfCond Not a nullptr if 'if' clause was specified, nullptr |
| 577 | /// otherwise. |
Alexey Bataev | 36c1eb9 | 2015-04-30 06:51:57 +0000 | [diff] [blame] | 578 | /// \param PrivateVars List of references to private variables for the task |
| 579 | /// directive. |
| 580 | /// \param PrivateCopies List of private copies for each private variable in |
Alexey Bataev | 9e03404 | 2015-05-05 04:05:12 +0000 | [diff] [blame] | 581 | /// \p PrivateVars. |
| 582 | /// \param FirstprivateVars List of references to private variables for the |
| 583 | /// task directive. |
| 584 | /// \param FirstprivateCopies List of private copies for each private variable |
| 585 | /// in \p FirstprivateVars. |
| 586 | /// \param FirstprivateInits List of references to auto generated variables |
| 587 | /// used for initialization of a single array element. Used if firstprivate |
| 588 | /// variable is of array type. |
Alexey Bataev | 36c1eb9 | 2015-04-30 06:51:57 +0000 | [diff] [blame] | 589 | virtual void emitTaskCall(CodeGenFunction &CGF, SourceLocation Loc, |
| 590 | const OMPExecutableDirective &D, bool Tied, |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 591 | llvm::PointerIntPair<llvm::Value *, 1, bool> Final, |
| 592 | llvm::Value *TaskFunction, QualType SharedsTy, |
Alexey Bataev | 36c1eb9 | 2015-04-30 06:51:57 +0000 | [diff] [blame] | 593 | llvm::Value *Shareds, const Expr *IfCond, |
| 594 | const ArrayRef<const Expr *> PrivateVars, |
Alexey Bataev | 9e03404 | 2015-05-05 04:05:12 +0000 | [diff] [blame] | 595 | const ArrayRef<const Expr *> PrivateCopies, |
| 596 | const ArrayRef<const Expr *> FirstprivateVars, |
| 597 | const ArrayRef<const Expr *> FirstprivateCopies, |
| 598 | const ArrayRef<const Expr *> FirstprivateInits); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 599 | |
Alexey Bataev | 6f1ffc0 | 2015-04-10 04:50:10 +0000 | [diff] [blame] | 600 | /// \brief Emit code for the directive that does not require outlining. |
| 601 | /// |
| 602 | /// \param CodeGen Code generation sequence for the \a D directive. |
| 603 | virtual void emitInlinedDirective(CodeGenFunction &CGF, |
| 604 | const RegionCodeGenTy &CodeGen); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 605 | /// \brief Emit a code for reduction clause. Next code should be emitted for |
| 606 | /// reduction: |
| 607 | /// \code |
| 608 | /// |
| 609 | /// static kmp_critical_name lock = { 0 }; |
| 610 | /// |
| 611 | /// void reduce_func(void *lhs[<n>], void *rhs[<n>]) { |
| 612 | /// ... |
| 613 | /// *(Type<i>*)lhs[i] = RedOp<i>(*(Type<i>*)lhs[i], *(Type<i>*)rhs[i]); |
| 614 | /// ... |
| 615 | /// } |
| 616 | /// |
| 617 | /// ... |
| 618 | /// void *RedList[<n>] = {&<RHSExprs>[0], ..., &<RHSExprs>[<n>-1]}; |
| 619 | /// switch (__kmpc_reduce{_nowait}(<loc>, <gtid>, <n>, sizeof(RedList), |
| 620 | /// RedList, reduce_func, &<lock>)) { |
| 621 | /// case 1: |
| 622 | /// ... |
| 623 | /// <LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]); |
| 624 | /// ... |
| 625 | /// __kmpc_end_reduce{_nowait}(<loc>, <gtid>, &<lock>); |
| 626 | /// break; |
| 627 | /// case 2: |
| 628 | /// ... |
| 629 | /// Atomic(<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i])); |
| 630 | /// ... |
| 631 | /// break; |
| 632 | /// default:; |
| 633 | /// } |
| 634 | /// \endcode |
| 635 | /// |
| 636 | /// \param LHSExprs List of LHS in \a ReductionOps reduction operations. |
| 637 | /// \param RHSExprs List of RHS in \a ReductionOps reduction operations. |
| 638 | /// \param ReductionOps List of reduction operations in form 'LHS binop RHS' |
| 639 | /// or 'operator binop(LHS, RHS)'. |
| 640 | /// \param WithNowait true if parent directive has also nowait clause, false |
| 641 | /// otherwise. |
| 642 | virtual void emitReduction(CodeGenFunction &CGF, SourceLocation Loc, |
| 643 | ArrayRef<const Expr *> LHSExprs, |
| 644 | ArrayRef<const Expr *> RHSExprs, |
| 645 | ArrayRef<const Expr *> ReductionOps, |
Alexey Bataev | 89e7e8e | 2015-06-17 06:21:39 +0000 | [diff] [blame] | 646 | bool WithNowait, bool SimpleReduction); |
Alexey Bataev | 8b8e202 | 2015-04-27 05:22:09 +0000 | [diff] [blame] | 647 | |
| 648 | /// \brief Emit code for 'taskwait' directive. |
| 649 | virtual void emitTaskwaitCall(CodeGenFunction &CGF, SourceLocation Loc); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 650 | }; |
Alexey Bataev | 8cbe0a6 | 2015-02-26 10:27:34 +0000 | [diff] [blame] | 651 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 652 | } // namespace CodeGen |
| 653 | } // namespace clang |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 654 | |
| 655 | #endif |