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