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" |
Benjamin Kramer | 8fdba91 | 2016-02-02 14:24:21 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/SmallPtrSet.h" |
Alexey Bataev | 3a3bf0b | 2014-09-22 10:01:53 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/StringMap.h" |
Benjamin Kramer | 8fdba91 | 2016-02-02 14:24:21 +0000 | [diff] [blame] | 23 | #include "llvm/IR/Function.h" |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 24 | #include "llvm/IR/ValueHandle.h" |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 25 | |
| 26 | namespace llvm { |
| 27 | class ArrayType; |
| 28 | class Constant; |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 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; |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 38 | class GlobalDecl; |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 39 | class OMPExecutableDirective; |
| 40 | class VarDecl; |
| 41 | |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 42 | namespace CodeGen { |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 43 | class Address; |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 44 | class CodeGenFunction; |
| 45 | class CodeGenModule; |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 46 | |
Alexey Bataev | 6f1ffc0 | 2015-04-10 04:50:10 +0000 | [diff] [blame] | 47 | typedef llvm::function_ref<void(CodeGenFunction &)> RegionCodeGenTy; |
| 48 | |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 49 | class CGOpenMPRuntime { |
Alexey Bataev | 6f1ffc0 | 2015-04-10 04:50:10 +0000 | [diff] [blame] | 50 | private: |
Alexey Bataev | 8f7c1b0 | 2014-12-05 04:09:23 +0000 | [diff] [blame] | 51 | enum OpenMPRTLFunction { |
| 52 | /// \brief Call to void __kmpc_fork_call(ident_t *loc, kmp_int32 argc, |
| 53 | /// kmpc_micro microtask, ...); |
| 54 | OMPRTL__kmpc_fork_call, |
| 55 | /// \brief Call to void *__kmpc_threadprivate_cached(ident_t *loc, |
| 56 | /// kmp_int32 global_tid, void *data, size_t size, void ***cache); |
| 57 | OMPRTL__kmpc_threadprivate_cached, |
| 58 | /// \brief Call to void __kmpc_threadprivate_register( ident_t *, |
| 59 | /// void *data, kmpc_ctor ctor, kmpc_cctor cctor, kmpc_dtor dtor); |
| 60 | OMPRTL__kmpc_threadprivate_register, |
| 61 | // Call to __kmpc_int32 kmpc_global_thread_num(ident_t *loc); |
| 62 | OMPRTL__kmpc_global_thread_num, |
| 63 | // Call to void __kmpc_critical(ident_t *loc, kmp_int32 global_tid, |
| 64 | // kmp_critical_name *crit); |
| 65 | OMPRTL__kmpc_critical, |
Alexey Bataev | fc57d16 | 2015-12-15 10:55:09 +0000 | [diff] [blame] | 66 | // Call to void __kmpc_critical_with_hint(ident_t *loc, kmp_int32 |
| 67 | // global_tid, kmp_critical_name *crit, uintptr_t hint); |
| 68 | OMPRTL__kmpc_critical_with_hint, |
Alexey Bataev | 8f7c1b0 | 2014-12-05 04:09:23 +0000 | [diff] [blame] | 69 | // Call to void __kmpc_end_critical(ident_t *loc, kmp_int32 global_tid, |
| 70 | // kmp_critical_name *crit); |
| 71 | OMPRTL__kmpc_end_critical, |
| 72 | // Call to kmp_int32 __kmpc_cancel_barrier(ident_t *loc, kmp_int32 |
| 73 | // global_tid); |
| 74 | OMPRTL__kmpc_cancel_barrier, |
Alexey Bataev | 81c7ea0 | 2015-07-03 09:56:58 +0000 | [diff] [blame] | 75 | // Call to void __kmpc_barrier(ident_t *loc, kmp_int32 global_tid); |
| 76 | OMPRTL__kmpc_barrier, |
Alexander Musman | 21212e4 | 2015-03-13 10:38:23 +0000 | [diff] [blame] | 77 | // 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] | 78 | OMPRTL__kmpc_for_static_fini, |
Alexey Bataev | 8f7c1b0 | 2014-12-05 04:09:23 +0000 | [diff] [blame] | 79 | // Call to void __kmpc_serialized_parallel(ident_t *loc, kmp_int32 |
| 80 | // global_tid); |
| 81 | OMPRTL__kmpc_serialized_parallel, |
| 82 | // Call to void __kmpc_end_serialized_parallel(ident_t *loc, kmp_int32 |
| 83 | // global_tid); |
| 84 | OMPRTL__kmpc_end_serialized_parallel, |
| 85 | // Call to void __kmpc_push_num_threads(ident_t *loc, kmp_int32 global_tid, |
| 86 | // kmp_int32 num_threads); |
| 87 | OMPRTL__kmpc_push_num_threads, |
Alexey Bataev | d76df6d | 2015-02-24 12:55:09 +0000 | [diff] [blame] | 88 | // Call to void __kmpc_flush(ident_t *loc); |
Alexey Bataev | 8f7c1b0 | 2014-12-05 04:09:23 +0000 | [diff] [blame] | 89 | OMPRTL__kmpc_flush, |
| 90 | // Call to kmp_int32 __kmpc_master(ident_t *, kmp_int32 global_tid); |
| 91 | OMPRTL__kmpc_master, |
| 92 | // Call to void __kmpc_end_master(ident_t *, kmp_int32 global_tid); |
| 93 | OMPRTL__kmpc_end_master, |
Alexey Bataev | 9f797f3 | 2015-02-05 05:57:51 +0000 | [diff] [blame] | 94 | // Call to kmp_int32 __kmpc_omp_taskyield(ident_t *, kmp_int32 global_tid, |
| 95 | // int end_part); |
| 96 | OMPRTL__kmpc_omp_taskyield, |
Alexey Bataev | 6956e2e | 2015-02-05 06:35:41 +0000 | [diff] [blame] | 97 | // Call to kmp_int32 __kmpc_single(ident_t *, kmp_int32 global_tid); |
| 98 | OMPRTL__kmpc_single, |
| 99 | // Call to void __kmpc_end_single(ident_t *, kmp_int32 global_tid); |
| 100 | OMPRTL__kmpc_end_single, |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 101 | // Call to kmp_task_t * __kmpc_omp_task_alloc(ident_t *, kmp_int32 gtid, |
| 102 | // kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds, |
| 103 | // kmp_routine_entry_t *task_entry); |
| 104 | OMPRTL__kmpc_omp_task_alloc, |
| 105 | // Call to kmp_int32 __kmpc_omp_task(ident_t *, kmp_int32 gtid, kmp_task_t * |
| 106 | // new_task); |
| 107 | OMPRTL__kmpc_omp_task, |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 108 | // Call to void __kmpc_copyprivate(ident_t *loc, kmp_int32 global_tid, |
Alexey Bataev | 66beaa9 | 2015-04-30 03:47:32 +0000 | [diff] [blame] | 109 | // size_t cpy_size, void *cpy_data, void(*cpy_func)(void *, void *), |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 110 | // kmp_int32 didit); |
| 111 | OMPRTL__kmpc_copyprivate, |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 112 | // Call to kmp_int32 __kmpc_reduce(ident_t *loc, kmp_int32 global_tid, |
| 113 | // kmp_int32 num_vars, size_t reduce_size, void *reduce_data, void |
| 114 | // (*reduce_func)(void *lhs_data, void *rhs_data), kmp_critical_name *lck); |
| 115 | OMPRTL__kmpc_reduce, |
| 116 | // Call to kmp_int32 __kmpc_reduce_nowait(ident_t *loc, kmp_int32 |
| 117 | // global_tid, kmp_int32 num_vars, size_t reduce_size, void *reduce_data, |
| 118 | // void (*reduce_func)(void *lhs_data, void *rhs_data), kmp_critical_name |
| 119 | // *lck); |
| 120 | OMPRTL__kmpc_reduce_nowait, |
| 121 | // Call to void __kmpc_end_reduce(ident_t *loc, kmp_int32 global_tid, |
| 122 | // kmp_critical_name *lck); |
| 123 | OMPRTL__kmpc_end_reduce, |
| 124 | // Call to void __kmpc_end_reduce_nowait(ident_t *loc, kmp_int32 global_tid, |
| 125 | // kmp_critical_name *lck); |
| 126 | OMPRTL__kmpc_end_reduce_nowait, |
Alexey Bataev | 1d67713 | 2015-04-22 13:57:31 +0000 | [diff] [blame] | 127 | // Call to void __kmpc_omp_task_begin_if0(ident_t *, kmp_int32 gtid, |
| 128 | // kmp_task_t * new_task); |
| 129 | OMPRTL__kmpc_omp_task_begin_if0, |
| 130 | // Call to void __kmpc_omp_task_complete_if0(ident_t *, kmp_int32 gtid, |
| 131 | // kmp_task_t * new_task); |
| 132 | OMPRTL__kmpc_omp_task_complete_if0, |
Alexey Bataev | 98eb6e3 | 2015-04-22 11:15:40 +0000 | [diff] [blame] | 133 | // Call to void __kmpc_ordered(ident_t *loc, kmp_int32 global_tid); |
| 134 | OMPRTL__kmpc_ordered, |
| 135 | // Call to void __kmpc_end_ordered(ident_t *loc, kmp_int32 global_tid); |
| 136 | OMPRTL__kmpc_end_ordered, |
Alexey Bataev | 8b8e202 | 2015-04-27 05:22:09 +0000 | [diff] [blame] | 137 | // Call to kmp_int32 __kmpc_omp_taskwait(ident_t *loc, kmp_int32 |
| 138 | // global_tid); |
| 139 | OMPRTL__kmpc_omp_taskwait, |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 140 | // Call to void __kmpc_taskgroup(ident_t *loc, kmp_int32 global_tid); |
| 141 | OMPRTL__kmpc_taskgroup, |
| 142 | // Call to void __kmpc_end_taskgroup(ident_t *loc, kmp_int32 global_tid); |
| 143 | OMPRTL__kmpc_end_taskgroup, |
Alexey Bataev | 7f210c6 | 2015-06-18 13:40:03 +0000 | [diff] [blame] | 144 | // Call to void __kmpc_push_proc_bind(ident_t *loc, kmp_int32 global_tid, |
| 145 | // int proc_bind); |
| 146 | OMPRTL__kmpc_push_proc_bind, |
Alexey Bataev | 1d2353d | 2015-06-24 11:01:36 +0000 | [diff] [blame] | 147 | // Call to kmp_int32 __kmpc_omp_task_with_deps(ident_t *loc_ref, kmp_int32 |
| 148 | // gtid, kmp_task_t * new_task, kmp_int32 ndeps, kmp_depend_info_t |
| 149 | // *dep_list, kmp_int32 ndeps_noalias, kmp_depend_info_t *noalias_dep_list); |
| 150 | OMPRTL__kmpc_omp_task_with_deps, |
| 151 | // Call to void __kmpc_omp_wait_deps(ident_t *loc_ref, kmp_int32 |
| 152 | // gtid, kmp_int32 ndeps, kmp_depend_info_t *dep_list, kmp_int32 |
| 153 | // ndeps_noalias, kmp_depend_info_t *noalias_dep_list); |
| 154 | OMPRTL__kmpc_omp_wait_deps, |
Alexey Bataev | 0f34da1 | 2015-07-02 04:17:07 +0000 | [diff] [blame] | 155 | // Call to kmp_int32 __kmpc_cancellationpoint(ident_t *loc, kmp_int32 |
| 156 | // global_tid, kmp_int32 cncl_kind); |
| 157 | OMPRTL__kmpc_cancellationpoint, |
Alexey Bataev | 7d5d33e | 2015-07-06 05:50:32 +0000 | [diff] [blame] | 158 | // Call to kmp_int32 __kmpc_cancel(ident_t *loc, kmp_int32 global_tid, |
| 159 | // kmp_int32 cncl_kind); |
| 160 | OMPRTL__kmpc_cancel, |
Samuel Antao | bed3c46 | 2015-10-02 16:14:20 +0000 | [diff] [blame] | 161 | |
| 162 | // |
| 163 | // Offloading related calls |
| 164 | // |
| 165 | // Call to int32_t __tgt_target(int32_t device_id, void *host_ptr, int32_t |
| 166 | // arg_num, void** args_base, void **args, size_t *arg_sizes, int32_t |
| 167 | // *arg_types); |
| 168 | OMPRTL__tgt_target, |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 169 | // Call to void __tgt_register_lib(__tgt_bin_desc *desc); |
| 170 | OMPRTL__tgt_register_lib, |
| 171 | // Call to void __tgt_unregister_lib(__tgt_bin_desc *desc); |
| 172 | OMPRTL__tgt_unregister_lib, |
Alexey Bataev | 8f7c1b0 | 2014-12-05 04:09:23 +0000 | [diff] [blame] | 173 | }; |
| 174 | |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 175 | /// \brief Values for bit flags used in the ident_t to describe the fields. |
| 176 | /// All enumeric elements are named and described in accordance with the code |
| 177 | /// from http://llvm.org/svn/llvm-project/openmp/trunk/runtime/src/kmp.h |
| 178 | enum OpenMPLocationFlags { |
| 179 | /// \brief Use trampoline for internal microtask. |
| 180 | OMP_IDENT_IMD = 0x01, |
| 181 | /// \brief Use c-style ident structure. |
| 182 | OMP_IDENT_KMPC = 0x02, |
| 183 | /// \brief Atomic reduction option for kmpc_reduce. |
| 184 | OMP_ATOMIC_REDUCE = 0x10, |
| 185 | /// \brief Explicit 'barrier' directive. |
| 186 | OMP_IDENT_BARRIER_EXPL = 0x20, |
| 187 | /// \brief Implicit barrier in code. |
| 188 | OMP_IDENT_BARRIER_IMPL = 0x40, |
| 189 | /// \brief Implicit barrier in 'for' directive. |
| 190 | OMP_IDENT_BARRIER_IMPL_FOR = 0x40, |
| 191 | /// \brief Implicit barrier in 'sections' directive. |
| 192 | OMP_IDENT_BARRIER_IMPL_SECTIONS = 0xC0, |
| 193 | /// \brief Implicit barrier in 'single' directive. |
| 194 | OMP_IDENT_BARRIER_IMPL_SINGLE = 0x140 |
| 195 | }; |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 196 | CodeGenModule &CGM; |
| 197 | /// \brief Default const ident_t object used for initialization of all other |
| 198 | /// ident_t objects. |
| 199 | llvm::Constant *DefaultOpenMPPSource; |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 200 | /// \brief Map of flags and corresponding default locations. |
Alexey Bataev | 15007ba | 2014-05-07 06:18:01 +0000 | [diff] [blame] | 201 | typedef llvm::DenseMap<unsigned, llvm::Value *> OpenMPDefaultLocMapTy; |
| 202 | OpenMPDefaultLocMapTy OpenMPDefaultLocMap; |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 203 | Address getOrCreateDefaultLocation(OpenMPLocationFlags Flags); |
| 204 | |
| 205 | public: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 206 | /// \brief Describes ident structure that describes a source location. |
| 207 | /// All descriptions are taken from |
| 208 | /// http://llvm.org/svn/llvm-project/openmp/trunk/runtime/src/kmp.h |
| 209 | /// Original structure: |
| 210 | /// typedef struct ident { |
| 211 | /// kmp_int32 reserved_1; /**< might be used in Fortran; |
| 212 | /// see above */ |
| 213 | /// kmp_int32 flags; /**< also f.flags; KMP_IDENT_xxx flags; |
| 214 | /// KMP_IDENT_KMPC identifies this union |
| 215 | /// member */ |
| 216 | /// kmp_int32 reserved_2; /**< not really used in Fortran any more; |
| 217 | /// see above */ |
| 218 | ///#if USE_ITT_BUILD |
| 219 | /// /* but currently used for storing |
| 220 | /// region-specific ITT */ |
| 221 | /// /* contextual information. */ |
| 222 | ///#endif /* USE_ITT_BUILD */ |
| 223 | /// kmp_int32 reserved_3; /**< source[4] in Fortran, do not use for |
| 224 | /// C++ */ |
| 225 | /// char const *psource; /**< String describing the source location. |
| 226 | /// The string is composed of semi-colon separated |
| 227 | // fields which describe the source file, |
| 228 | /// the function and a pair of line numbers that |
| 229 | /// delimit the construct. |
| 230 | /// */ |
| 231 | /// } ident_t; |
| 232 | enum IdentFieldIndex { |
| 233 | /// \brief might be used in Fortran |
| 234 | IdentField_Reserved_1, |
| 235 | /// \brief OMP_IDENT_xxx flags; OMP_IDENT_KMPC identifies this union member. |
| 236 | IdentField_Flags, |
| 237 | /// \brief Not really used in Fortran any more |
| 238 | IdentField_Reserved_2, |
| 239 | /// \brief Source[4] in Fortran, do not use for C++ |
| 240 | IdentField_Reserved_3, |
| 241 | /// \brief String describing the source location. The string is composed of |
| 242 | /// semi-colon separated fields which describe the source file, the function |
| 243 | /// and a pair of line numbers that delimit the construct. |
| 244 | IdentField_PSource |
| 245 | }; |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 246 | private: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 247 | llvm::StructType *IdentTy; |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 248 | /// \brief Map for SourceLocation and OpenMP runtime library debug locations. |
Alexey Bataev | f002aca | 2014-05-30 05:48:40 +0000 | [diff] [blame] | 249 | typedef llvm::DenseMap<unsigned, llvm::Value *> OpenMPDebugLocMapTy; |
| 250 | OpenMPDebugLocMapTy OpenMPDebugLocMap; |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 251 | /// \brief The type for a microtask which gets passed to __kmpc_fork_call(). |
| 252 | /// Original representation is: |
| 253 | /// typedef void (kmpc_micro)(kmp_int32 global_tid, kmp_int32 bound_tid,...); |
| 254 | llvm::FunctionType *Kmpc_MicroTy; |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 255 | /// \brief Stores debug location and ThreadID for the function. |
| 256 | struct DebugLocThreadIdTy { |
| 257 | llvm::Value *DebugLoc; |
| 258 | llvm::Value *ThreadID; |
| 259 | }; |
| 260 | /// \brief Map of local debug location, ThreadId and functions. |
| 261 | typedef llvm::DenseMap<llvm::Function *, DebugLocThreadIdTy> |
| 262 | OpenMPLocThreadIDMapTy; |
| 263 | OpenMPLocThreadIDMapTy OpenMPLocThreadIDMap; |
Alexey Bataev | 3a3bf0b | 2014-09-22 10:01:53 +0000 | [diff] [blame] | 264 | /// \brief Type kmp_critical_name, originally defined as typedef kmp_int32 |
| 265 | /// kmp_critical_name[8]; |
| 266 | llvm::ArrayType *KmpCriticalNameTy; |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 267 | /// \brief An ordered map of auto-generated variables to their unique names. |
| 268 | /// It stores variables with the following names: 1) ".gomp_critical_user_" + |
| 269 | /// <critical_section_name> + ".var" for "omp critical" directives; 2) |
| 270 | /// <mangled_name_for_global_var> + ".cache." for cache for threadprivate |
| 271 | /// variables. |
| 272 | llvm::StringMap<llvm::AssertingVH<llvm::Constant>, llvm::BumpPtrAllocator> |
| 273 | InternalVars; |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 274 | /// \brief Type typedef kmp_int32 (* kmp_routine_entry_t)(kmp_int32, void *); |
| 275 | llvm::Type *KmpRoutineEntryPtrTy; |
| 276 | QualType KmpRoutineEntryPtrQTy; |
Alexey Bataev | 8fc69dc | 2015-05-18 07:54:53 +0000 | [diff] [blame] | 277 | /// \brief Type typedef struct kmp_task { |
| 278 | /// void * shareds; /**< pointer to block of pointers to |
| 279 | /// shared vars */ |
| 280 | /// kmp_routine_entry_t routine; /**< pointer to routine to call for |
| 281 | /// executing task */ |
| 282 | /// kmp_int32 part_id; /**< part id for the task */ |
| 283 | /// kmp_routine_entry_t destructors; /* pointer to function to invoke |
| 284 | /// deconstructors of firstprivate C++ objects */ |
| 285 | /// } kmp_task_t; |
| 286 | QualType KmpTaskTQTy; |
Alexey Bataev | 1d2353d | 2015-06-24 11:01:36 +0000 | [diff] [blame] | 287 | /// \brief Type typedef struct kmp_depend_info { |
| 288 | /// kmp_intptr_t base_addr; |
| 289 | /// size_t len; |
| 290 | /// struct { |
| 291 | /// bool in:1; |
| 292 | /// bool out:1; |
| 293 | /// } flags; |
| 294 | /// } kmp_depend_info_t; |
| 295 | QualType KmpDependInfoTy; |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 296 | /// \brief Type struct __tgt_offload_entry{ |
| 297 | /// void *addr; // Pointer to the offload entry info. |
| 298 | /// // (function or global) |
| 299 | /// char *name; // Name of the function or global. |
| 300 | /// size_t size; // Size of the entry info (0 if it a function). |
| 301 | /// }; |
| 302 | QualType TgtOffloadEntryQTy; |
| 303 | /// struct __tgt_device_image{ |
| 304 | /// void *ImageStart; // Pointer to the target code start. |
| 305 | /// void *ImageEnd; // Pointer to the target code end. |
| 306 | /// // We also add the host entries to the device image, as it may be useful |
| 307 | /// // for the target runtime to have access to that information. |
| 308 | /// __tgt_offload_entry *EntriesBegin; // Begin of the table with all |
| 309 | /// // the entries. |
| 310 | /// __tgt_offload_entry *EntriesEnd; // End of the table with all the |
| 311 | /// // entries (non inclusive). |
| 312 | /// }; |
| 313 | QualType TgtDeviceImageQTy; |
| 314 | /// struct __tgt_bin_desc{ |
| 315 | /// int32_t NumDevices; // Number of devices supported. |
| 316 | /// __tgt_device_image *DeviceImages; // Arrays of device images |
| 317 | /// // (one per device). |
| 318 | /// __tgt_offload_entry *EntriesBegin; // Begin of the table with all the |
| 319 | /// // entries. |
| 320 | /// __tgt_offload_entry *EntriesEnd; // End of the table with all the |
| 321 | /// // entries (non inclusive). |
| 322 | /// }; |
| 323 | QualType TgtBinaryDescriptorQTy; |
| 324 | /// \brief Entity that registers the offloading constants that were emitted so |
| 325 | /// far. |
| 326 | class OffloadEntriesInfoManagerTy { |
| 327 | CodeGenModule &CGM; |
Alexey Bataev | 1d2353d | 2015-06-24 11:01:36 +0000 | [diff] [blame] | 328 | |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 329 | /// \brief Number of entries registered so far. |
| 330 | unsigned OffloadingEntriesNum; |
| 331 | |
| 332 | public: |
| 333 | /// \brief Base class of the entries info. |
| 334 | class OffloadEntryInfo { |
| 335 | public: |
| 336 | /// \brief Kind of a given entry. Currently, only target regions are |
| 337 | /// supported. |
Reid Kleckner | dc78f95 | 2016-01-11 20:55:16 +0000 | [diff] [blame] | 338 | enum OffloadingEntryInfoKinds : unsigned { |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 339 | // Entry is a target region. |
| 340 | OFFLOAD_ENTRY_INFO_TARGET_REGION = 0, |
| 341 | // Invalid entry info. |
| 342 | OFFLOAD_ENTRY_INFO_INVALID = ~0u |
| 343 | }; |
| 344 | |
| 345 | OffloadEntryInfo() : Order(~0u), Kind(OFFLOAD_ENTRY_INFO_INVALID) {} |
| 346 | explicit OffloadEntryInfo(OffloadingEntryInfoKinds Kind, unsigned Order) |
| 347 | : Order(Order), Kind(Kind) {} |
| 348 | |
| 349 | bool isValid() const { return Order != ~0u; } |
| 350 | unsigned getOrder() const { return Order; } |
| 351 | OffloadingEntryInfoKinds getKind() const { return Kind; } |
| 352 | static bool classof(const OffloadEntryInfo *Info) { return true; } |
| 353 | |
| 354 | protected: |
| 355 | // \brief Order this entry was emitted. |
| 356 | unsigned Order; |
| 357 | |
| 358 | OffloadingEntryInfoKinds Kind; |
| 359 | }; |
| 360 | |
| 361 | /// \brief Return true if a there are no entries defined. |
| 362 | bool empty() const; |
| 363 | /// \brief Return number of entries defined so far. |
| 364 | unsigned size() const { return OffloadingEntriesNum; } |
| 365 | OffloadEntriesInfoManagerTy(CodeGenModule &CGM) |
| 366 | : CGM(CGM), OffloadingEntriesNum(0) {} |
| 367 | |
| 368 | /// |
| 369 | /// Target region entries related. |
| 370 | /// |
| 371 | /// \brief Target region entries info. |
| 372 | class OffloadEntryInfoTargetRegion : public OffloadEntryInfo { |
| 373 | // \brief Address of the entity that has to be mapped for offloading. |
| 374 | llvm::Constant *Addr; |
| 375 | // \brief Address that can be used as the ID of the entry. |
| 376 | llvm::Constant *ID; |
| 377 | |
| 378 | public: |
| 379 | OffloadEntryInfoTargetRegion() |
| 380 | : OffloadEntryInfo(OFFLOAD_ENTRY_INFO_TARGET_REGION, ~0u), |
| 381 | Addr(nullptr), ID(nullptr) {} |
| 382 | explicit OffloadEntryInfoTargetRegion(unsigned Order, |
| 383 | llvm::Constant *Addr, |
| 384 | llvm::Constant *ID) |
| 385 | : OffloadEntryInfo(OFFLOAD_ENTRY_INFO_TARGET_REGION, Order), |
| 386 | Addr(Addr), ID(ID) {} |
| 387 | |
| 388 | llvm::Constant *getAddress() const { return Addr; } |
| 389 | llvm::Constant *getID() const { return ID; } |
| 390 | void setAddress(llvm::Constant *V) { |
| 391 | assert(!Addr && "Address as been set before!"); |
| 392 | Addr = V; |
| 393 | } |
| 394 | void setID(llvm::Constant *V) { |
| 395 | assert(!ID && "ID as been set before!"); |
| 396 | ID = V; |
| 397 | } |
| 398 | static bool classof(const OffloadEntryInfo *Info) { |
| 399 | return Info->getKind() == OFFLOAD_ENTRY_INFO_TARGET_REGION; |
| 400 | } |
| 401 | }; |
| 402 | /// \brief Initialize target region entry. |
| 403 | void initializeTargetRegionEntryInfo(unsigned DeviceID, unsigned FileID, |
| 404 | StringRef ParentName, unsigned LineNum, |
Samuel Antao | 2de62b0 | 2016-02-13 23:35:10 +0000 | [diff] [blame] | 405 | unsigned Order); |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 406 | /// \brief Register target region entry. |
| 407 | void registerTargetRegionEntryInfo(unsigned DeviceID, unsigned FileID, |
| 408 | StringRef ParentName, unsigned LineNum, |
Samuel Antao | 2de62b0 | 2016-02-13 23:35:10 +0000 | [diff] [blame] | 409 | llvm::Constant *Addr, |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 410 | llvm::Constant *ID); |
| 411 | /// \brief Return true if a target region entry with the provided |
| 412 | /// information exists. |
| 413 | bool hasTargetRegionEntryInfo(unsigned DeviceID, unsigned FileID, |
Samuel Antao | 2de62b0 | 2016-02-13 23:35:10 +0000 | [diff] [blame] | 414 | StringRef ParentName, unsigned LineNum) const; |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 415 | /// brief Applies action \a Action on all registered entries. |
| 416 | typedef llvm::function_ref<void(unsigned, unsigned, StringRef, unsigned, |
Samuel Antao | 2de62b0 | 2016-02-13 23:35:10 +0000 | [diff] [blame] | 417 | OffloadEntryInfoTargetRegion &)> |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 418 | OffloadTargetRegionEntryInfoActTy; |
| 419 | void actOnTargetRegionEntriesInfo( |
| 420 | const OffloadTargetRegionEntryInfoActTy &Action); |
| 421 | |
| 422 | private: |
| 423 | // Storage for target region entries kind. The storage is to be indexed by |
Samuel Antao | 2de62b0 | 2016-02-13 23:35:10 +0000 | [diff] [blame] | 424 | // file ID, device ID, parent function name and line number. |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 425 | typedef llvm::DenseMap<unsigned, OffloadEntryInfoTargetRegion> |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 426 | OffloadEntriesTargetRegionPerLine; |
| 427 | typedef llvm::StringMap<OffloadEntriesTargetRegionPerLine> |
| 428 | OffloadEntriesTargetRegionPerParentName; |
| 429 | typedef llvm::DenseMap<unsigned, OffloadEntriesTargetRegionPerParentName> |
| 430 | OffloadEntriesTargetRegionPerFile; |
| 431 | typedef llvm::DenseMap<unsigned, OffloadEntriesTargetRegionPerFile> |
| 432 | OffloadEntriesTargetRegionPerDevice; |
| 433 | typedef OffloadEntriesTargetRegionPerDevice OffloadEntriesTargetRegionTy; |
| 434 | OffloadEntriesTargetRegionTy OffloadEntriesTargetRegion; |
| 435 | }; |
| 436 | OffloadEntriesInfoManagerTy OffloadEntriesInfoManager; |
| 437 | |
| 438 | /// \brief Creates and registers offloading binary descriptor for the current |
| 439 | /// compilation unit. The function that does the registration is returned. |
| 440 | llvm::Function *createOffloadingBinaryDescriptorRegistration(); |
| 441 | |
Samuel Antao | 2de62b0 | 2016-02-13 23:35:10 +0000 | [diff] [blame] | 442 | /// \brief Creates offloading entry for the provided entry ID \a ID, |
| 443 | /// address \a Addr and size \a Size. |
| 444 | void createOffloadEntry(llvm::Constant *ID, llvm::Constant *Addr, |
| 445 | uint64_t Size); |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 446 | |
| 447 | /// \brief Creates all the offload entries in the current compilation unit |
| 448 | /// along with the associated metadata. |
| 449 | void createOffloadEntriesAndInfoMetadata(); |
| 450 | |
| 451 | /// \brief Loads all the offload entries information from the host IR |
| 452 | /// metadata. |
| 453 | void loadOffloadInfoMetadata(); |
| 454 | |
| 455 | /// \brief Returns __tgt_offload_entry type. |
| 456 | QualType getTgtOffloadEntryQTy(); |
| 457 | |
| 458 | /// \brief Returns __tgt_device_image type. |
| 459 | QualType getTgtDeviceImageQTy(); |
| 460 | |
| 461 | /// \brief Returns __tgt_bin_desc type. |
| 462 | QualType getTgtBinaryDescriptorQTy(); |
| 463 | |
| 464 | /// \brief Start scanning from statement \a S and and emit all target regions |
| 465 | /// found along the way. |
| 466 | /// \param S Starting statement. |
| 467 | /// \param ParentName Name of the function declaration that is being scanned. |
| 468 | void scanForTargetRegionsFunctions(const Stmt *S, StringRef ParentName); |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 469 | |
| 470 | /// \brief Build type kmp_routine_entry_t (if not built yet). |
| 471 | void emitKmpRoutineEntryT(QualType KmpInt32Ty); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 472 | |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 473 | /// \brief Emits object of ident_t type with info for source location. |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 474 | /// \param Flags Flags for OpenMP location. |
| 475 | /// |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 476 | llvm::Value *emitUpdateLocation(CodeGenFunction &CGF, SourceLocation Loc, |
| 477 | OpenMPLocationFlags Flags = OMP_IDENT_KMPC); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 478 | |
Alexey Bataev | d74d060 | 2014-10-13 06:02:40 +0000 | [diff] [blame] | 479 | /// \brief Returns pointer to ident_t type. |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 480 | llvm::Type *getIdentTyPointerTy(); |
| 481 | |
Alexey Bataev | d74d060 | 2014-10-13 06:02:40 +0000 | [diff] [blame] | 482 | /// \brief Returns pointer to kmpc_micro type. |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 483 | llvm::Type *getKmpc_MicroPointerTy(); |
| 484 | |
| 485 | /// \brief Returns specified OpenMP runtime function. |
| 486 | /// \param Function OpenMP runtime function. |
| 487 | /// \return Specified function. |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 488 | llvm::Constant *createRuntimeFunction(OpenMPRTLFunction Function); |
Alexey Bataev | 3a3bf0b | 2014-09-22 10:01:53 +0000 | [diff] [blame] | 489 | |
Alexander Musman | 21212e4 | 2015-03-13 10:38:23 +0000 | [diff] [blame] | 490 | /// \brief Returns __kmpc_for_static_init_* runtime function for the specified |
| 491 | /// size \a IVSize and sign \a IVSigned. |
| 492 | llvm::Constant *createForStaticInitFunction(unsigned IVSize, bool IVSigned); |
| 493 | |
Alexander Musman | 92bdaab | 2015-03-12 13:37:50 +0000 | [diff] [blame] | 494 | /// \brief Returns __kmpc_dispatch_init_* runtime function for the specified |
| 495 | /// size \a IVSize and sign \a IVSigned. |
| 496 | llvm::Constant *createDispatchInitFunction(unsigned IVSize, bool IVSigned); |
| 497 | |
| 498 | /// \brief Returns __kmpc_dispatch_next_* runtime function for the specified |
| 499 | /// size \a IVSize and sign \a IVSigned. |
| 500 | llvm::Constant *createDispatchNextFunction(unsigned IVSize, bool IVSigned); |
| 501 | |
Alexey Bataev | 98eb6e3 | 2015-04-22 11:15:40 +0000 | [diff] [blame] | 502 | /// \brief Returns __kmpc_dispatch_fini_* runtime function for the specified |
| 503 | /// size \a IVSize and sign \a IVSigned. |
| 504 | llvm::Constant *createDispatchFiniFunction(unsigned IVSize, bool IVSigned); |
| 505 | |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 506 | /// \brief If the specified mangled name is not in the module, create and |
| 507 | /// return threadprivate cache object. This object is a pointer's worth of |
| 508 | /// storage that's reserved for use by the OpenMP runtime. |
NAKAMURA Takumi | cdcbfba | 2014-11-11 07:58:06 +0000 | [diff] [blame] | 509 | /// \param VD Threadprivate variable. |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 510 | /// \return Cache variable for the specified threadprivate. |
| 511 | llvm::Constant *getOrCreateThreadPrivateCache(const VarDecl *VD); |
| 512 | |
Alexey Bataev | d74d060 | 2014-10-13 06:02:40 +0000 | [diff] [blame] | 513 | /// \brief Emits address of the word in a memory where current thread id is |
| 514 | /// stored. |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 515 | virtual Address emitThreadIDAddress(CodeGenFunction &CGF, SourceLocation Loc); |
Alexey Bataev | d74d060 | 2014-10-13 06:02:40 +0000 | [diff] [blame] | 516 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 517 | /// \brief Gets thread id value for the current thread. |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 518 | /// |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 519 | llvm::Value *getThreadID(CodeGenFunction &CGF, SourceLocation Loc); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 520 | |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 521 | /// \brief Gets (if variable with the given name already exist) or creates |
| 522 | /// internal global variable with the specified Name. The created variable has |
| 523 | /// linkage CommonLinkage by default and is initialized by null value. |
| 524 | /// \param Ty Type of the global variable. If it is exist already the type |
| 525 | /// must be the same. |
| 526 | /// \param Name Name of the variable. |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 527 | llvm::Constant *getOrCreateInternalVariable(llvm::Type *Ty, |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 528 | const llvm::Twine &Name); |
| 529 | |
| 530 | /// \brief Set of threadprivate variables with the generated initializer. |
Benjamin Kramer | 8fdba91 | 2016-02-02 14:24:21 +0000 | [diff] [blame] | 531 | llvm::SmallPtrSet<const VarDecl *, 4> ThreadPrivateWithDefinition; |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 532 | |
| 533 | /// \brief Emits initialization code for the threadprivate variables. |
| 534 | /// \param VDAddr Address of the global variable \a VD. |
| 535 | /// \param Ctor Pointer to a global init function for \a VD. |
| 536 | /// \param CopyCtor Pointer to a global copy function for \a VD. |
| 537 | /// \param Dtor Pointer to a global destructor function for \a VD. |
| 538 | /// \param Loc Location of threadprivate declaration. |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 539 | void emitThreadPrivateVarInit(CodeGenFunction &CGF, Address VDAddr, |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 540 | llvm::Value *Ctor, llvm::Value *CopyCtor, |
| 541 | llvm::Value *Dtor, SourceLocation Loc); |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 542 | |
Alexey Bataev | 75ddfab | 2014-12-01 11:32:38 +0000 | [diff] [blame] | 543 | /// \brief Returns corresponding lock object for the specified critical region |
| 544 | /// name. If the lock object does not exist it is created, otherwise the |
| 545 | /// reference to the existing copy is returned. |
| 546 | /// \param CriticalName Name of the critical region. |
| 547 | /// |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 548 | llvm::Value *getCriticalRegionLock(StringRef CriticalName); |
Alexey Bataev | 75ddfab | 2014-12-01 11:32:38 +0000 | [diff] [blame] | 549 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 550 | public: |
| 551 | explicit CGOpenMPRuntime(CodeGenModule &CGM); |
Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 552 | virtual ~CGOpenMPRuntime() {} |
Alexey Bataev | 9179755 | 2015-03-18 04:13:55 +0000 | [diff] [blame] | 553 | virtual void clear(); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 554 | |
Alexey Bataev | 6f1ffc0 | 2015-04-10 04:50:10 +0000 | [diff] [blame] | 555 | /// \brief Emits outlined function for the specified OpenMP parallel directive |
| 556 | /// \a D. This outlined function has type void(*)(kmp_int32 *ThreadID, |
| 557 | /// kmp_int32 BoundID, struct context_vars*). |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 558 | /// \param D OpenMP directive. |
| 559 | /// \param ThreadIDVar Variable for thread id in the current OpenMP region. |
Alexey Bataev | 81c7ea0 | 2015-07-03 09:56:58 +0000 | [diff] [blame] | 560 | /// \param InnermostKind Kind of innermost directive (for simple directives it |
| 561 | /// is a directive itself, for combined - its innermost directive). |
Alexey Bataev | 6f1ffc0 | 2015-04-10 04:50:10 +0000 | [diff] [blame] | 562 | /// \param CodeGen Code generation sequence for the \a D directive. |
Alexey Bataev | 81c7ea0 | 2015-07-03 09:56:58 +0000 | [diff] [blame] | 563 | virtual llvm::Value *emitParallelOutlinedFunction( |
| 564 | const OMPExecutableDirective &D, const VarDecl *ThreadIDVar, |
| 565 | OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen); |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 566 | |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 567 | /// \brief Emits outlined function for the OpenMP task directive \a D. This |
| 568 | /// outlined function has type void(*)(kmp_int32 ThreadID, kmp_int32 |
| 569 | /// PartID, struct context_vars*). |
| 570 | /// \param D OpenMP directive. |
| 571 | /// \param ThreadIDVar Variable for thread id in the current OpenMP region. |
Alexey Bataev | 81c7ea0 | 2015-07-03 09:56:58 +0000 | [diff] [blame] | 572 | /// \param InnermostKind Kind of innermost directive (for simple directives it |
| 573 | /// is a directive itself, for combined - its innermost directive). |
Alexey Bataev | 6f1ffc0 | 2015-04-10 04:50:10 +0000 | [diff] [blame] | 574 | /// \param CodeGen Code generation sequence for the \a D directive. |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 575 | /// |
Alexey Bataev | 81c7ea0 | 2015-07-03 09:56:58 +0000 | [diff] [blame] | 576 | virtual llvm::Value *emitTaskOutlinedFunction( |
| 577 | const OMPExecutableDirective &D, const VarDecl *ThreadIDVar, |
| 578 | OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen); |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 579 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 580 | /// \brief Cleans up references to the objects in finished function. |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 581 | /// |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 582 | void functionFinished(CodeGenFunction &CGF); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 583 | |
Alexey Bataev | 1d67713 | 2015-04-22 13:57:31 +0000 | [diff] [blame] | 584 | /// \brief Emits code for parallel or serial call of the \a OutlinedFn with |
| 585 | /// variables captured in a record which address is stored in \a |
| 586 | /// CapturedStruct. |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 587 | /// \param OutlinedFn Outlined function to be run in parallel threads. Type of |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 588 | /// this function is void(*)(kmp_int32 *, kmp_int32, struct context_vars*). |
NAKAMURA Takumi | 62f0eb5 | 2015-09-11 08:13:32 +0000 | [diff] [blame] | 589 | /// \param CapturedVars A pointer to the record with the references to |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 590 | /// variables used in \a OutlinedFn function. |
Alexey Bataev | 1d67713 | 2015-04-22 13:57:31 +0000 | [diff] [blame] | 591 | /// \param IfCond Condition in the associated 'if' clause, if it was |
| 592 | /// specified, nullptr otherwise. |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 593 | /// |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 594 | virtual void emitParallelCall(CodeGenFunction &CGF, SourceLocation Loc, |
| 595 | llvm::Value *OutlinedFn, |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 596 | ArrayRef<llvm::Value *> CapturedVars, |
| 597 | const Expr *IfCond); |
Alexey Bataev | d74d060 | 2014-10-13 06:02:40 +0000 | [diff] [blame] | 598 | |
Alexey Bataev | 75ddfab | 2014-12-01 11:32:38 +0000 | [diff] [blame] | 599 | /// \brief Emits a critical region. |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 600 | /// \param CriticalName Name of the critical region. |
Alexey Bataev | 75ddfab | 2014-12-01 11:32:38 +0000 | [diff] [blame] | 601 | /// \param CriticalOpGen Generator for the statement associated with the given |
| 602 | /// critical region. |
Alexey Bataev | fc57d16 | 2015-12-15 10:55:09 +0000 | [diff] [blame] | 603 | /// \param Hint Value of the 'hint' clause (optional). |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 604 | virtual void emitCriticalRegion(CodeGenFunction &CGF, StringRef CriticalName, |
Alexey Bataev | 6f1ffc0 | 2015-04-10 04:50:10 +0000 | [diff] [blame] | 605 | const RegionCodeGenTy &CriticalOpGen, |
Alexey Bataev | fc57d16 | 2015-12-15 10:55:09 +0000 | [diff] [blame] | 606 | SourceLocation Loc, |
| 607 | const Expr *Hint = nullptr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 608 | |
Alexey Bataev | 8d69065 | 2014-12-04 07:23:53 +0000 | [diff] [blame] | 609 | /// \brief Emits a master region. |
| 610 | /// \param MasterOpGen Generator for the statement associated with the given |
| 611 | /// master region. |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 612 | virtual void emitMasterRegion(CodeGenFunction &CGF, |
Alexey Bataev | 6f1ffc0 | 2015-04-10 04:50:10 +0000 | [diff] [blame] | 613 | const RegionCodeGenTy &MasterOpGen, |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 614 | SourceLocation Loc); |
Alexey Bataev | 8d69065 | 2014-12-04 07:23:53 +0000 | [diff] [blame] | 615 | |
Alexey Bataev | 9f797f3 | 2015-02-05 05:57:51 +0000 | [diff] [blame] | 616 | /// \brief Emits code for a taskyield directive. |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 617 | virtual void emitTaskyieldCall(CodeGenFunction &CGF, SourceLocation Loc); |
Alexey Bataev | 9f797f3 | 2015-02-05 05:57:51 +0000 | [diff] [blame] | 618 | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 619 | /// \brief Emit a taskgroup region. |
| 620 | /// \param TaskgroupOpGen Generator for the statement associated with the |
| 621 | /// given taskgroup region. |
| 622 | virtual void emitTaskgroupRegion(CodeGenFunction &CGF, |
| 623 | const RegionCodeGenTy &TaskgroupOpGen, |
| 624 | SourceLocation Loc); |
| 625 | |
Alexey Bataev | 6956e2e | 2015-02-05 06:35:41 +0000 | [diff] [blame] | 626 | /// \brief Emits a single region. |
| 627 | /// \param SingleOpGen Generator for the statement associated with the given |
| 628 | /// single region. |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 629 | virtual void emitSingleRegion(CodeGenFunction &CGF, |
Alexey Bataev | 6f1ffc0 | 2015-04-10 04:50:10 +0000 | [diff] [blame] | 630 | const RegionCodeGenTy &SingleOpGen, |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 631 | SourceLocation Loc, |
| 632 | ArrayRef<const Expr *> CopyprivateVars, |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 633 | ArrayRef<const Expr *> DestExprs, |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 634 | ArrayRef<const Expr *> SrcExprs, |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 635 | ArrayRef<const Expr *> AssignmentOps); |
Alexey Bataev | 6956e2e | 2015-02-05 06:35:41 +0000 | [diff] [blame] | 636 | |
Alexey Bataev | 98eb6e3 | 2015-04-22 11:15:40 +0000 | [diff] [blame] | 637 | /// \brief Emit an ordered region. |
| 638 | /// \param OrderedOpGen Generator for the statement associated with the given |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 639 | /// ordered region. |
Alexey Bataev | 98eb6e3 | 2015-04-22 11:15:40 +0000 | [diff] [blame] | 640 | virtual void emitOrderedRegion(CodeGenFunction &CGF, |
| 641 | const RegionCodeGenTy &OrderedOpGen, |
Alexey Bataev | 5f600d6 | 2015-09-29 03:48:57 +0000 | [diff] [blame] | 642 | SourceLocation Loc, bool IsThreads); |
Alexey Bataev | 98eb6e3 | 2015-04-22 11:15:40 +0000 | [diff] [blame] | 643 | |
Alexey Bataev | f268568 | 2015-03-30 04:30:22 +0000 | [diff] [blame] | 644 | /// \brief Emit an implicit/explicit barrier for OpenMP threads. |
| 645 | /// \param Kind Directive for which this implicit barrier call must be |
| 646 | /// generated. Must be OMPD_barrier for explicit barrier generation. |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 647 | /// \param EmitChecks true if need to emit checks for cancellation barriers. |
| 648 | /// \param ForceSimpleCall true simple barrier call must be emitted, false if |
| 649 | /// runtime class decides which one to emit (simple or with cancellation |
| 650 | /// checks). |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 651 | /// |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 652 | virtual void emitBarrierCall(CodeGenFunction &CGF, SourceLocation Loc, |
Alexey Bataev | 81c7ea0 | 2015-07-03 09:56:58 +0000 | [diff] [blame] | 653 | OpenMPDirectiveKind Kind, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 654 | bool EmitChecks = true, |
| 655 | bool ForceSimpleCall = false); |
Alexey Bataev | b205978 | 2014-10-13 08:23:51 +0000 | [diff] [blame] | 656 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 657 | /// \brief Check if the specified \a ScheduleKind is static non-chunked. |
| 658 | /// This kind of worksharing directive is emitted without outer loop. |
| 659 | /// \param ScheduleKind Schedule kind specified in the 'schedule' clause. |
| 660 | /// \param Chunked True if chunk is specified in the clause. |
| 661 | /// |
| 662 | virtual bool isStaticNonchunked(OpenMPScheduleClauseKind ScheduleKind, |
| 663 | bool Chunked) const; |
| 664 | |
Alexander Musman | df7a8e2 | 2015-01-22 08:49:35 +0000 | [diff] [blame] | 665 | /// \brief Check if the specified \a ScheduleKind is dynamic. |
| 666 | /// This kind of worksharing directive is emitted without outer loop. |
| 667 | /// \param ScheduleKind Schedule Kind specified in the 'schedule' clause. |
| 668 | /// |
| 669 | virtual bool isDynamic(OpenMPScheduleClauseKind ScheduleKind) const; |
| 670 | |
NAKAMURA Takumi | ff7a925 | 2015-09-08 09:42:41 +0000 | [diff] [blame] | 671 | virtual void emitForDispatchInit(CodeGenFunction &CGF, SourceLocation Loc, |
| 672 | OpenMPScheduleClauseKind SchedKind, |
| 673 | unsigned IVSize, bool IVSigned, |
| 674 | bool Ordered, llvm::Value *UB, |
| 675 | llvm::Value *Chunk = nullptr); |
| 676 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 677 | /// \brief Call the appropriate runtime routine to initialize it before start |
| 678 | /// of loop. |
| 679 | /// |
| 680 | /// Depending on the loop schedule, it is nesessary to call some runtime |
| 681 | /// routine before start of the OpenMP loop to get the loop upper / lower |
| 682 | /// bounds \a LB and \a UB and stride \a ST. |
| 683 | /// |
| 684 | /// \param CGF Reference to current CodeGenFunction. |
| 685 | /// \param Loc Clang source location. |
NAKAMURA Takumi | eca0838 | 2014-12-17 14:47:06 +0000 | [diff] [blame] | 686 | /// \param SchedKind Schedule kind, specified by the 'schedule' clause. |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 687 | /// \param IVSize Size of the iteration variable in bits. |
| 688 | /// \param IVSigned Sign of the interation variable. |
Alexey Bataev | d7589ffe | 2015-05-20 13:12:48 +0000 | [diff] [blame] | 689 | /// \param Ordered true if loop is ordered, false otherwise. |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 690 | /// \param IL Address of the output variable in which the flag of the |
| 691 | /// last iteration is returned. |
| 692 | /// \param LB Address of the output variable in which the lower iteration |
| 693 | /// number is returned. |
| 694 | /// \param UB Address of the output variable in which the upper iteration |
| 695 | /// number is returned. |
| 696 | /// \param ST Address of the output variable in which the stride value is |
| 697 | /// returned nesessary to generated the static_chunked scheduled loop. |
| 698 | /// \param Chunk Value of the chunk for the static_chunked scheduled loop. |
| 699 | /// For the default (nullptr) value, the chunk 1 will be used. |
| 700 | /// |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 701 | virtual void emitForStaticInit(CodeGenFunction &CGF, SourceLocation Loc, |
| 702 | OpenMPScheduleClauseKind SchedKind, |
| 703 | unsigned IVSize, bool IVSigned, bool Ordered, |
| 704 | Address IL, Address LB, |
| 705 | Address UB, Address ST, |
| 706 | llvm::Value *Chunk = nullptr); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 707 | |
| 708 | /// \brief Call the appropriate runtime routine to notify that we finished |
Alexey Bataev | 98eb6e3 | 2015-04-22 11:15:40 +0000 | [diff] [blame] | 709 | /// iteration of the ordered loop with the dynamic scheduling. |
| 710 | /// |
| 711 | /// \param CGF Reference to current CodeGenFunction. |
| 712 | /// \param Loc Clang source location. |
| 713 | /// \param IVSize Size of the iteration variable in bits. |
| 714 | /// \param IVSigned Sign of the interation variable. |
| 715 | /// |
Alexey Bataev | d7589ffe | 2015-05-20 13:12:48 +0000 | [diff] [blame] | 716 | virtual void emitForOrderedIterationEnd(CodeGenFunction &CGF, |
| 717 | SourceLocation Loc, unsigned IVSize, |
| 718 | bool IVSigned); |
Alexey Bataev | 98eb6e3 | 2015-04-22 11:15:40 +0000 | [diff] [blame] | 719 | |
| 720 | /// \brief Call the appropriate runtime routine to notify that we finished |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 721 | /// all the work with current loop. |
| 722 | /// |
| 723 | /// \param CGF Reference to current CodeGenFunction. |
| 724 | /// \param Loc Clang source location. |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 725 | /// |
Alexey Bataev | 98eb6e3 | 2015-04-22 11:15:40 +0000 | [diff] [blame] | 726 | virtual void emitForStaticFinish(CodeGenFunction &CGF, SourceLocation Loc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 727 | |
Alexander Musman | 92bdaab | 2015-03-12 13:37:50 +0000 | [diff] [blame] | 728 | /// Call __kmpc_dispatch_next( |
| 729 | /// ident_t *loc, kmp_int32 tid, kmp_int32 *p_lastiter, |
| 730 | /// kmp_int[32|64] *p_lower, kmp_int[32|64] *p_upper, |
| 731 | /// kmp_int[32|64] *p_stride); |
| 732 | /// \param IVSize Size of the iteration variable in bits. |
| 733 | /// \param IVSigned Sign of the interation variable. |
| 734 | /// \param IL Address of the output variable in which the flag of the |
| 735 | /// last iteration is returned. |
| 736 | /// \param LB Address of the output variable in which the lower iteration |
| 737 | /// number is returned. |
| 738 | /// \param UB Address of the output variable in which the upper iteration |
| 739 | /// number is returned. |
| 740 | /// \param ST Address of the output variable in which the stride value is |
| 741 | /// returned. |
| 742 | virtual llvm::Value *emitForNext(CodeGenFunction &CGF, SourceLocation Loc, |
| 743 | unsigned IVSize, bool IVSigned, |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 744 | Address IL, Address LB, |
| 745 | Address UB, Address ST); |
Alexander Musman | 92bdaab | 2015-03-12 13:37:50 +0000 | [diff] [blame] | 746 | |
Alexey Bataev | b205978 | 2014-10-13 08:23:51 +0000 | [diff] [blame] | 747 | /// \brief Emits call to void __kmpc_push_num_threads(ident_t *loc, kmp_int32 |
| 748 | /// global_tid, kmp_int32 num_threads) to generate code for 'num_threads' |
| 749 | /// clause. |
| 750 | /// \param NumThreads An integer value of threads. |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 751 | virtual void emitNumThreadsClause(CodeGenFunction &CGF, |
| 752 | llvm::Value *NumThreads, |
| 753 | SourceLocation Loc); |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 754 | |
Alexey Bataev | 7f210c6 | 2015-06-18 13:40:03 +0000 | [diff] [blame] | 755 | /// \brief Emit call to void __kmpc_push_proc_bind(ident_t *loc, kmp_int32 |
| 756 | /// global_tid, int proc_bind) to generate code for 'proc_bind' clause. |
| 757 | virtual void emitProcBindClause(CodeGenFunction &CGF, |
| 758 | OpenMPProcBindClauseKind ProcBind, |
| 759 | SourceLocation Loc); |
| 760 | |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 761 | /// \brief Returns address of the threadprivate variable for the current |
| 762 | /// thread. |
NAKAMURA Takumi | cdcbfba | 2014-11-11 07:58:06 +0000 | [diff] [blame] | 763 | /// \param VD Threadprivate variable. |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 764 | /// \param VDAddr Address of the global variable \a VD. |
| 765 | /// \param Loc Location of the reference to threadprivate var. |
| 766 | /// \return Address of the threadprivate variable for the current thread. |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 767 | virtual Address getAddrOfThreadPrivate(CodeGenFunction &CGF, |
| 768 | const VarDecl *VD, |
| 769 | Address VDAddr, |
| 770 | SourceLocation Loc); |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 771 | |
| 772 | /// \brief Emit a code for initialization of threadprivate variable. It emits |
| 773 | /// a call to runtime library which adds initial value to the newly created |
| 774 | /// threadprivate variable (if it is not constant) and registers destructor |
| 775 | /// for the variable (if any). |
| 776 | /// \param VD Threadprivate variable. |
| 777 | /// \param VDAddr Address of the global variable \a VD. |
| 778 | /// \param Loc Location of threadprivate declaration. |
| 779 | /// \param PerformInit true if initialization expression is not constant. |
| 780 | virtual llvm::Function * |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 781 | emitThreadPrivateVarDefinition(const VarDecl *VD, Address VDAddr, |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 782 | SourceLocation Loc, bool PerformInit, |
| 783 | CodeGenFunction *CGF = nullptr); |
Alexey Bataev | cc37cc1 | 2014-11-20 04:34:54 +0000 | [diff] [blame] | 784 | |
| 785 | /// \brief Emit flush of the variables specified in 'omp flush' directive. |
| 786 | /// \param Vars List of variables to flush. |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 787 | virtual void emitFlush(CodeGenFunction &CGF, ArrayRef<const Expr *> Vars, |
| 788 | SourceLocation Loc); |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 789 | |
| 790 | /// \brief Emit task region for the task directive. The task region is |
Nico Weber | 20b0ce3 | 2015-04-28 18:19:18 +0000 | [diff] [blame] | 791 | /// emitted in several steps: |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 792 | /// 1. Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32 |
| 793 | /// gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds, |
| 794 | /// kmp_routine_entry_t *task_entry). Here task_entry is a pointer to the |
| 795 | /// function: |
| 796 | /// kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) { |
| 797 | /// TaskFunction(gtid, tt->part_id, tt->shareds); |
| 798 | /// return 0; |
| 799 | /// } |
| 800 | /// 2. Copy a list of shared variables to field shareds of the resulting |
| 801 | /// structure kmp_task_t returned by the previous call (if any). |
| 802 | /// 3. Copy a pointer to destructions function to field destructions of the |
| 803 | /// resulting structure kmp_task_t. |
| 804 | /// 4. Emit a call to kmp_int32 __kmpc_omp_task(ident_t *, kmp_int32 gtid, |
| 805 | /// kmp_task_t *new_task), where new_task is a resulting structure from |
| 806 | /// previous items. |
Alexey Bataev | 36c1eb9 | 2015-04-30 06:51:57 +0000 | [diff] [blame] | 807 | /// \param D Current task directive. |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 808 | /// \param Tied true if the task is tied (the task is tied to the thread that |
| 809 | /// can suspend its task region), false - untied (the task is not tied to any |
| 810 | /// thread). |
| 811 | /// \param Final Contains either constant bool value, or llvm::Value * of i1 |
| 812 | /// type for final clause. If the value is true, the task forces all of its |
| 813 | /// child tasks to become final and included tasks. |
| 814 | /// \param TaskFunction An LLVM function with type void (*)(i32 /*gtid*/, i32 |
| 815 | /// /*part_id*/, captured_struct */*__context*/); |
| 816 | /// \param SharedsTy A type which contains references the shared variables. |
Alexey Bataev | 1d2353d | 2015-06-24 11:01:36 +0000 | [diff] [blame] | 817 | /// \param Shareds Context with the list of shared variables from the \p |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 818 | /// TaskFunction. |
Alexey Bataev | 1d67713 | 2015-04-22 13:57:31 +0000 | [diff] [blame] | 819 | /// \param IfCond Not a nullptr if 'if' clause was specified, nullptr |
| 820 | /// otherwise. |
Alexey Bataev | 36c1eb9 | 2015-04-30 06:51:57 +0000 | [diff] [blame] | 821 | /// \param PrivateVars List of references to private variables for the task |
| 822 | /// directive. |
| 823 | /// \param PrivateCopies List of private copies for each private variable in |
Alexey Bataev | 9e03404 | 2015-05-05 04:05:12 +0000 | [diff] [blame] | 824 | /// \p PrivateVars. |
| 825 | /// \param FirstprivateVars List of references to private variables for the |
| 826 | /// task directive. |
| 827 | /// \param FirstprivateCopies List of private copies for each private variable |
| 828 | /// in \p FirstprivateVars. |
| 829 | /// \param FirstprivateInits List of references to auto generated variables |
| 830 | /// used for initialization of a single array element. Used if firstprivate |
| 831 | /// variable is of array type. |
Alexey Bataev | 1d2353d | 2015-06-24 11:01:36 +0000 | [diff] [blame] | 832 | /// \param Dependences List of dependences for the 'task' construct, including |
| 833 | /// original expression and dependency type. |
| 834 | virtual void emitTaskCall( |
| 835 | CodeGenFunction &CGF, SourceLocation Loc, const OMPExecutableDirective &D, |
| 836 | bool Tied, llvm::PointerIntPair<llvm::Value *, 1, bool> Final, |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 837 | llvm::Value *TaskFunction, QualType SharedsTy, Address Shareds, |
Alexey Bataev | 1d2353d | 2015-06-24 11:01:36 +0000 | [diff] [blame] | 838 | const Expr *IfCond, ArrayRef<const Expr *> PrivateVars, |
| 839 | ArrayRef<const Expr *> PrivateCopies, |
| 840 | ArrayRef<const Expr *> FirstprivateVars, |
| 841 | ArrayRef<const Expr *> FirstprivateCopies, |
| 842 | ArrayRef<const Expr *> FirstprivateInits, |
| 843 | ArrayRef<std::pair<OpenMPDependClauseKind, const Expr *>> Dependences); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 844 | |
Alexey Bataev | 6f1ffc0 | 2015-04-10 04:50:10 +0000 | [diff] [blame] | 845 | /// \brief Emit code for the directive that does not require outlining. |
| 846 | /// |
Alexey Bataev | 81c7ea0 | 2015-07-03 09:56:58 +0000 | [diff] [blame] | 847 | /// \param InnermostKind Kind of innermost directive (for simple directives it |
| 848 | /// is a directive itself, for combined - its innermost directive). |
Alexey Bataev | 6f1ffc0 | 2015-04-10 04:50:10 +0000 | [diff] [blame] | 849 | /// \param CodeGen Code generation sequence for the \a D directive. |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 850 | /// \param HasCancel true if region has inner cancel directive, false |
| 851 | /// otherwise. |
Alexey Bataev | 6f1ffc0 | 2015-04-10 04:50:10 +0000 | [diff] [blame] | 852 | virtual void emitInlinedDirective(CodeGenFunction &CGF, |
Alexey Bataev | 81c7ea0 | 2015-07-03 09:56:58 +0000 | [diff] [blame] | 853 | OpenMPDirectiveKind InnermostKind, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 854 | const RegionCodeGenTy &CodeGen, |
| 855 | bool HasCancel = false); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 856 | /// \brief Emit a code for reduction clause. Next code should be emitted for |
| 857 | /// reduction: |
| 858 | /// \code |
| 859 | /// |
| 860 | /// static kmp_critical_name lock = { 0 }; |
| 861 | /// |
| 862 | /// void reduce_func(void *lhs[<n>], void *rhs[<n>]) { |
| 863 | /// ... |
| 864 | /// *(Type<i>*)lhs[i] = RedOp<i>(*(Type<i>*)lhs[i], *(Type<i>*)rhs[i]); |
| 865 | /// ... |
| 866 | /// } |
| 867 | /// |
| 868 | /// ... |
| 869 | /// void *RedList[<n>] = {&<RHSExprs>[0], ..., &<RHSExprs>[<n>-1]}; |
| 870 | /// switch (__kmpc_reduce{_nowait}(<loc>, <gtid>, <n>, sizeof(RedList), |
| 871 | /// RedList, reduce_func, &<lock>)) { |
| 872 | /// case 1: |
| 873 | /// ... |
| 874 | /// <LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]); |
| 875 | /// ... |
| 876 | /// __kmpc_end_reduce{_nowait}(<loc>, <gtid>, &<lock>); |
| 877 | /// break; |
| 878 | /// case 2: |
| 879 | /// ... |
| 880 | /// Atomic(<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i])); |
| 881 | /// ... |
| 882 | /// break; |
| 883 | /// default:; |
| 884 | /// } |
| 885 | /// \endcode |
| 886 | /// |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 887 | /// \param Privates List of private copies for original reduction arguments. |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 888 | /// \param LHSExprs List of LHS in \a ReductionOps reduction operations. |
| 889 | /// \param RHSExprs List of RHS in \a ReductionOps reduction operations. |
| 890 | /// \param ReductionOps List of reduction operations in form 'LHS binop RHS' |
| 891 | /// or 'operator binop(LHS, RHS)'. |
| 892 | /// \param WithNowait true if parent directive has also nowait clause, false |
| 893 | /// otherwise. |
| 894 | virtual void emitReduction(CodeGenFunction &CGF, SourceLocation Loc, |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 895 | ArrayRef<const Expr *> Privates, |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 896 | ArrayRef<const Expr *> LHSExprs, |
| 897 | ArrayRef<const Expr *> RHSExprs, |
| 898 | ArrayRef<const Expr *> ReductionOps, |
Alexey Bataev | 89e7e8e | 2015-06-17 06:21:39 +0000 | [diff] [blame] | 899 | bool WithNowait, bool SimpleReduction); |
Alexey Bataev | 8b8e202 | 2015-04-27 05:22:09 +0000 | [diff] [blame] | 900 | |
| 901 | /// \brief Emit code for 'taskwait' directive. |
| 902 | virtual void emitTaskwaitCall(CodeGenFunction &CGF, SourceLocation Loc); |
Alexey Bataev | 0f34da1 | 2015-07-02 04:17:07 +0000 | [diff] [blame] | 903 | |
| 904 | /// \brief Emit code for 'cancellation point' construct. |
| 905 | /// \param CancelRegion Region kind for which the cancellation point must be |
| 906 | /// emitted. |
| 907 | /// |
| 908 | virtual void emitCancellationPointCall(CodeGenFunction &CGF, |
| 909 | SourceLocation Loc, |
| 910 | OpenMPDirectiveKind CancelRegion); |
Alexey Bataev | 7d5d33e | 2015-07-06 05:50:32 +0000 | [diff] [blame] | 911 | |
| 912 | /// \brief Emit code for 'cancel' construct. |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 913 | /// \param IfCond Condition in the associated 'if' clause, if it was |
| 914 | /// specified, nullptr otherwise. |
Alexey Bataev | 7d5d33e | 2015-07-06 05:50:32 +0000 | [diff] [blame] | 915 | /// \param CancelRegion Region kind for which the cancel must be emitted. |
| 916 | /// |
| 917 | virtual void emitCancelCall(CodeGenFunction &CGF, SourceLocation Loc, |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 918 | const Expr *IfCond, |
Alexey Bataev | 7d5d33e | 2015-07-06 05:50:32 +0000 | [diff] [blame] | 919 | OpenMPDirectiveKind CancelRegion); |
Samuel Antao | bed3c46 | 2015-10-02 16:14:20 +0000 | [diff] [blame] | 920 | |
| 921 | /// \brief Emit outilined function for 'target' directive. |
| 922 | /// \param D Directive to emit. |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 923 | /// \param ParentName Name of the function that encloses the target region. |
| 924 | /// \param OutlinedFn Outlined function value to be defined by this call. |
| 925 | /// \param OutlinedFnID Outlined function ID value to be defined by this call. |
| 926 | /// \param IsOffloadEntry True if the outlined function is an offload entry. |
| 927 | /// An oulined function may not be an entry if, e.g. the if clause always |
| 928 | /// evaluates to false. |
| 929 | virtual void emitTargetOutlinedFunction(const OMPExecutableDirective &D, |
| 930 | StringRef ParentName, |
| 931 | llvm::Function *&OutlinedFn, |
| 932 | llvm::Constant *&OutlinedFnID, |
| 933 | bool IsOffloadEntry); |
Samuel Antao | bed3c46 | 2015-10-02 16:14:20 +0000 | [diff] [blame] | 934 | |
| 935 | /// \brief Emit the target offloading code associated with \a D. The emitted |
| 936 | /// code attempts offloading the execution to the device, an the event of |
| 937 | /// a failure it executes the host version outlined in \a OutlinedFn. |
| 938 | /// \param D Directive to emit. |
| 939 | /// \param OutlinedFn Host version of the code to be offloaded. |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 940 | /// \param OutlinedFnID ID of host version of the code to be offloaded. |
Samuel Antao | bed3c46 | 2015-10-02 16:14:20 +0000 | [diff] [blame] | 941 | /// \param IfCond Expression evaluated in if clause associated with the target |
| 942 | /// directive, or null if no if clause is used. |
| 943 | /// \param Device Expression evaluated in device clause associated with the |
| 944 | /// target directive, or null if no device clause is used. |
| 945 | /// \param CapturedVars Values captured in the current region. |
| 946 | virtual void emitTargetCall(CodeGenFunction &CGF, |
| 947 | const OMPExecutableDirective &D, |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 948 | llvm::Value *OutlinedFn, |
| 949 | llvm::Value *OutlinedFnID, const Expr *IfCond, |
Samuel Antao | bed3c46 | 2015-10-02 16:14:20 +0000 | [diff] [blame] | 950 | const Expr *Device, |
| 951 | ArrayRef<llvm::Value *> CapturedVars); |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 952 | |
| 953 | /// \brief Emit the target regions enclosed in \a GD function definition or |
| 954 | /// the function itself in case it is a valid device function. Returns true if |
| 955 | /// \a GD was dealt with successfully. |
Nico Weber | a2abe8c | 2016-01-06 19:13:49 +0000 | [diff] [blame] | 956 | /// \param GD Function to scan. |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 957 | virtual bool emitTargetFunctions(GlobalDecl GD); |
| 958 | |
| 959 | /// \brief Emit the global variable if it is a valid device global variable. |
| 960 | /// Returns true if \a GD was dealt with successfully. |
| 961 | /// \param GD Variable declaration to emit. |
| 962 | virtual bool emitTargetGlobalVariable(GlobalDecl GD); |
| 963 | |
| 964 | /// \brief Emit the global \a GD if it is meaningful for the target. Returns |
| 965 | /// if it was emitted succesfully. |
| 966 | /// \param GD Global to scan. |
| 967 | virtual bool emitTargetGlobal(GlobalDecl GD); |
| 968 | |
| 969 | /// \brief Creates the offloading descriptor in the event any target region |
| 970 | /// was emitted in the current module and return the function that registers |
| 971 | /// it. |
| 972 | virtual llvm::Function *emitRegistrationFunction(); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 973 | }; |
Alexey Bataev | 8cbe0a6 | 2015-02-26 10:27:34 +0000 | [diff] [blame] | 974 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 975 | } // namespace CodeGen |
| 976 | } // namespace clang |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 977 | |
| 978 | #endif |