blob: ec128de4e93ef02550a4592847a60331f1d1151a [file] [log] [blame]
Alexey Bataev9959db52014-05-06 10:08:46 +00001//===----- 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 Kramer2f5db8b2014-08-13 16:25:19 +000014#ifndef LLVM_CLANG_LIB_CODEGEN_CGOPENMPRUNTIME_H
15#define LLVM_CLANG_LIB_CODEGEN_CGOPENMPRUNTIME_H
Alexey Bataev9959db52014-05-06 10:08:46 +000016
Alexey Bataev62b63b12015-03-10 07:28:44 +000017#include "clang/AST/Type.h"
Alexander Musmanc6388682014-12-15 07:07:06 +000018#include "clang/Basic/OpenMPKinds.h"
Chandler Carruth0d9593d2015-01-14 11:29:14 +000019#include "clang/Basic/SourceLocation.h"
Alexey Bataev9959db52014-05-06 10:08:46 +000020#include "llvm/ADT/DenseMap.h"
Alexey Bataev97720002014-11-11 04:05:39 +000021#include "llvm/ADT/DenseSet.h"
Alexey Bataev3a3bf0b2014-09-22 10:01:53 +000022#include "llvm/ADT/StringMap.h"
Alexey Bataev97720002014-11-11 04:05:39 +000023#include "llvm/IR/ValueHandle.h"
Alexey Bataev18095712014-10-10 12:19:54 +000024
25namespace llvm {
26class ArrayType;
27class Constant;
28class Function;
29class FunctionType;
Alexey Bataev97720002014-11-11 04:05:39 +000030class GlobalVariable;
Alexey Bataev18095712014-10-10 12:19:54 +000031class StructType;
32class Type;
33class Value;
34} // namespace llvm
Alexey Bataev9959db52014-05-06 10:08:46 +000035
Alexey Bataev9959db52014-05-06 10:08:46 +000036namespace clang {
Alexey Bataevcc37cc12014-11-20 04:34:54 +000037class Expr;
Alexey Bataev18095712014-10-10 12:19:54 +000038class OMPExecutableDirective;
39class VarDecl;
40
Alexey Bataev9959db52014-05-06 10:08:46 +000041namespace CodeGen {
John McCall7f416cc2015-09-08 08:05:57 +000042class Address;
Alexey Bataev18095712014-10-10 12:19:54 +000043class CodeGenFunction;
44class CodeGenModule;
Alexey Bataev9959db52014-05-06 10:08:46 +000045
Alexey Bataev6f1ffc02015-04-10 04:50:10 +000046typedef llvm::function_ref<void(CodeGenFunction &)> RegionCodeGenTy;
47
Alexey Bataev9959db52014-05-06 10:08:46 +000048class CGOpenMPRuntime {
Alexey Bataev6f1ffc02015-04-10 04:50:10 +000049private:
Alexey Bataev8f7c1b02014-12-05 04:09:23 +000050 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 Bataev81c7ea02015-07-03 09:56:58 +000071 // Call to void __kmpc_barrier(ident_t *loc, kmp_int32 global_tid);
72 OMPRTL__kmpc_barrier,
Alexander Musman21212e42015-03-13 10:38:23 +000073 // Call to void __kmpc_for_static_fini(ident_t *loc, kmp_int32 global_tid);
Alexander Musmanc6388682014-12-15 07:07:06 +000074 OMPRTL__kmpc_for_static_fini,
Alexey Bataev8f7c1b02014-12-05 04:09:23 +000075 // 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 Bataevd76df6d2015-02-24 12:55:09 +000084 // Call to void __kmpc_flush(ident_t *loc);
Alexey Bataev8f7c1b02014-12-05 04:09:23 +000085 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 Bataev9f797f32015-02-05 05:57:51 +000090 // Call to kmp_int32 __kmpc_omp_taskyield(ident_t *, kmp_int32 global_tid,
91 // int end_part);
92 OMPRTL__kmpc_omp_taskyield,
Alexey Bataev6956e2e2015-02-05 06:35:41 +000093 // 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 Bataev62b63b12015-03-10 07:28:44 +000097 // 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 Bataeva63048e2015-03-23 06:18:07 +0000104 // Call to void __kmpc_copyprivate(ident_t *loc, kmp_int32 global_tid,
Alexey Bataev66beaa92015-04-30 03:47:32 +0000105 // size_t cpy_size, void *cpy_data, void(*cpy_func)(void *, void *),
Alexey Bataeva63048e2015-03-23 06:18:07 +0000106 // kmp_int32 didit);
107 OMPRTL__kmpc_copyprivate,
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000108 // 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 Bataev1d677132015-04-22 13:57:31 +0000123 // 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 Bataev98eb6e32015-04-22 11:15:40 +0000129 // 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 Bataev8b8e2022015-04-27 05:22:09 +0000133 // Call to kmp_int32 __kmpc_omp_taskwait(ident_t *loc, kmp_int32
134 // global_tid);
135 OMPRTL__kmpc_omp_taskwait,
Alexey Bataevc30dd2d2015-06-18 12:14:09 +0000136 // 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 Bataev7f210c62015-06-18 13:40:03 +0000140 // 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 Bataev1d2353d2015-06-24 11:01:36 +0000143 // 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 Bataev0f34da12015-07-02 04:17:07 +0000151 // Call to kmp_int32 __kmpc_cancellationpoint(ident_t *loc, kmp_int32
152 // global_tid, kmp_int32 cncl_kind);
153 OMPRTL__kmpc_cancellationpoint,
Alexey Bataev7d5d33e2015-07-06 05:50:32 +0000154 // Call to kmp_int32 __kmpc_cancel(ident_t *loc, kmp_int32 global_tid,
155 // kmp_int32 cncl_kind);
156 OMPRTL__kmpc_cancel,
Samuel Antaobed3c462015-10-02 16:14:20 +0000157
158 //
159 // Offloading related calls
160 //
161 // Call to int32_t __tgt_target(int32_t device_id, void *host_ptr, int32_t
162 // arg_num, void** args_base, void **args, size_t *arg_sizes, int32_t
163 // *arg_types);
164 OMPRTL__tgt_target,
Alexey Bataev8f7c1b02014-12-05 04:09:23 +0000165 };
166
Alexey Bataev9959db52014-05-06 10:08:46 +0000167 /// \brief Values for bit flags used in the ident_t to describe the fields.
168 /// All enumeric elements are named and described in accordance with the code
169 /// from http://llvm.org/svn/llvm-project/openmp/trunk/runtime/src/kmp.h
170 enum OpenMPLocationFlags {
171 /// \brief Use trampoline for internal microtask.
172 OMP_IDENT_IMD = 0x01,
173 /// \brief Use c-style ident structure.
174 OMP_IDENT_KMPC = 0x02,
175 /// \brief Atomic reduction option for kmpc_reduce.
176 OMP_ATOMIC_REDUCE = 0x10,
177 /// \brief Explicit 'barrier' directive.
178 OMP_IDENT_BARRIER_EXPL = 0x20,
179 /// \brief Implicit barrier in code.
180 OMP_IDENT_BARRIER_IMPL = 0x40,
181 /// \brief Implicit barrier in 'for' directive.
182 OMP_IDENT_BARRIER_IMPL_FOR = 0x40,
183 /// \brief Implicit barrier in 'sections' directive.
184 OMP_IDENT_BARRIER_IMPL_SECTIONS = 0xC0,
185 /// \brief Implicit barrier in 'single' directive.
186 OMP_IDENT_BARRIER_IMPL_SINGLE = 0x140
187 };
Alexey Bataev9959db52014-05-06 10:08:46 +0000188 CodeGenModule &CGM;
189 /// \brief Default const ident_t object used for initialization of all other
190 /// ident_t objects.
191 llvm::Constant *DefaultOpenMPPSource;
Alexey Bataev18095712014-10-10 12:19:54 +0000192 /// \brief Map of flags and corresponding default locations.
Alexey Bataev15007ba2014-05-07 06:18:01 +0000193 typedef llvm::DenseMap<unsigned, llvm::Value *> OpenMPDefaultLocMapTy;
194 OpenMPDefaultLocMapTy OpenMPDefaultLocMap;
John McCall7f416cc2015-09-08 08:05:57 +0000195 Address getOrCreateDefaultLocation(OpenMPLocationFlags Flags);
196
197public:
Alexey Bataev9959db52014-05-06 10:08:46 +0000198 /// \brief Describes ident structure that describes a source location.
199 /// All descriptions are taken from
200 /// http://llvm.org/svn/llvm-project/openmp/trunk/runtime/src/kmp.h
201 /// Original structure:
202 /// typedef struct ident {
203 /// kmp_int32 reserved_1; /**< might be used in Fortran;
204 /// see above */
205 /// kmp_int32 flags; /**< also f.flags; KMP_IDENT_xxx flags;
206 /// KMP_IDENT_KMPC identifies this union
207 /// member */
208 /// kmp_int32 reserved_2; /**< not really used in Fortran any more;
209 /// see above */
210 ///#if USE_ITT_BUILD
211 /// /* but currently used for storing
212 /// region-specific ITT */
213 /// /* contextual information. */
214 ///#endif /* USE_ITT_BUILD */
215 /// kmp_int32 reserved_3; /**< source[4] in Fortran, do not use for
216 /// C++ */
217 /// char const *psource; /**< String describing the source location.
218 /// The string is composed of semi-colon separated
219 // fields which describe the source file,
220 /// the function and a pair of line numbers that
221 /// delimit the construct.
222 /// */
223 /// } ident_t;
224 enum IdentFieldIndex {
225 /// \brief might be used in Fortran
226 IdentField_Reserved_1,
227 /// \brief OMP_IDENT_xxx flags; OMP_IDENT_KMPC identifies this union member.
228 IdentField_Flags,
229 /// \brief Not really used in Fortran any more
230 IdentField_Reserved_2,
231 /// \brief Source[4] in Fortran, do not use for C++
232 IdentField_Reserved_3,
233 /// \brief String describing the source location. The string is composed of
234 /// semi-colon separated fields which describe the source file, the function
235 /// and a pair of line numbers that delimit the construct.
236 IdentField_PSource
237 };
John McCall7f416cc2015-09-08 08:05:57 +0000238private:
Alexey Bataev9959db52014-05-06 10:08:46 +0000239 llvm::StructType *IdentTy;
Alexey Bataev18095712014-10-10 12:19:54 +0000240 /// \brief Map for SourceLocation and OpenMP runtime library debug locations.
Alexey Bataevf002aca2014-05-30 05:48:40 +0000241 typedef llvm::DenseMap<unsigned, llvm::Value *> OpenMPDebugLocMapTy;
242 OpenMPDebugLocMapTy OpenMPDebugLocMap;
Alexey Bataev9959db52014-05-06 10:08:46 +0000243 /// \brief The type for a microtask which gets passed to __kmpc_fork_call().
244 /// Original representation is:
245 /// typedef void (kmpc_micro)(kmp_int32 global_tid, kmp_int32 bound_tid,...);
246 llvm::FunctionType *Kmpc_MicroTy;
Alexey Bataev18095712014-10-10 12:19:54 +0000247 /// \brief Stores debug location and ThreadID for the function.
248 struct DebugLocThreadIdTy {
249 llvm::Value *DebugLoc;
250 llvm::Value *ThreadID;
251 };
252 /// \brief Map of local debug location, ThreadId and functions.
253 typedef llvm::DenseMap<llvm::Function *, DebugLocThreadIdTy>
254 OpenMPLocThreadIDMapTy;
255 OpenMPLocThreadIDMapTy OpenMPLocThreadIDMap;
Alexey Bataev3a3bf0b2014-09-22 10:01:53 +0000256 /// \brief Type kmp_critical_name, originally defined as typedef kmp_int32
257 /// kmp_critical_name[8];
258 llvm::ArrayType *KmpCriticalNameTy;
Alexey Bataev97720002014-11-11 04:05:39 +0000259 /// \brief An ordered map of auto-generated variables to their unique names.
260 /// It stores variables with the following names: 1) ".gomp_critical_user_" +
261 /// <critical_section_name> + ".var" for "omp critical" directives; 2)
262 /// <mangled_name_for_global_var> + ".cache." for cache for threadprivate
263 /// variables.
264 llvm::StringMap<llvm::AssertingVH<llvm::Constant>, llvm::BumpPtrAllocator>
265 InternalVars;
Alexey Bataev62b63b12015-03-10 07:28:44 +0000266 /// \brief Type typedef kmp_int32 (* kmp_routine_entry_t)(kmp_int32, void *);
267 llvm::Type *KmpRoutineEntryPtrTy;
268 QualType KmpRoutineEntryPtrQTy;
Alexey Bataev8fc69dc2015-05-18 07:54:53 +0000269 /// \brief Type typedef struct kmp_task {
270 /// void * shareds; /**< pointer to block of pointers to
271 /// shared vars */
272 /// kmp_routine_entry_t routine; /**< pointer to routine to call for
273 /// executing task */
274 /// kmp_int32 part_id; /**< part id for the task */
275 /// kmp_routine_entry_t destructors; /* pointer to function to invoke
276 /// deconstructors of firstprivate C++ objects */
277 /// } kmp_task_t;
278 QualType KmpTaskTQTy;
Alexey Bataev1d2353d2015-06-24 11:01:36 +0000279 /// \brief Type typedef struct kmp_depend_info {
280 /// kmp_intptr_t base_addr;
281 /// size_t len;
282 /// struct {
283 /// bool in:1;
284 /// bool out:1;
285 /// } flags;
286 /// } kmp_depend_info_t;
287 QualType KmpDependInfoTy;
288
Alexey Bataev62b63b12015-03-10 07:28:44 +0000289
290 /// \brief Build type kmp_routine_entry_t (if not built yet).
291 void emitKmpRoutineEntryT(QualType KmpInt32Ty);
Alexey Bataev9959db52014-05-06 10:08:46 +0000292
Alexey Bataev9959db52014-05-06 10:08:46 +0000293 /// \brief Emits object of ident_t type with info for source location.
Alexey Bataev9959db52014-05-06 10:08:46 +0000294 /// \param Flags Flags for OpenMP location.
295 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000296 llvm::Value *emitUpdateLocation(CodeGenFunction &CGF, SourceLocation Loc,
297 OpenMPLocationFlags Flags = OMP_IDENT_KMPC);
Alexey Bataev9959db52014-05-06 10:08:46 +0000298
Alexey Bataevd74d0602014-10-13 06:02:40 +0000299 /// \brief Returns pointer to ident_t type.
Alexey Bataev9959db52014-05-06 10:08:46 +0000300 llvm::Type *getIdentTyPointerTy();
301
Alexey Bataevd74d0602014-10-13 06:02:40 +0000302 /// \brief Returns pointer to kmpc_micro type.
Alexey Bataev9959db52014-05-06 10:08:46 +0000303 llvm::Type *getKmpc_MicroPointerTy();
304
305 /// \brief Returns specified OpenMP runtime function.
306 /// \param Function OpenMP runtime function.
307 /// \return Specified function.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000308 llvm::Constant *createRuntimeFunction(OpenMPRTLFunction Function);
Alexey Bataev3a3bf0b2014-09-22 10:01:53 +0000309
Alexander Musman21212e42015-03-13 10:38:23 +0000310 /// \brief Returns __kmpc_for_static_init_* runtime function for the specified
311 /// size \a IVSize and sign \a IVSigned.
312 llvm::Constant *createForStaticInitFunction(unsigned IVSize, bool IVSigned);
313
Alexander Musman92bdaab2015-03-12 13:37:50 +0000314 /// \brief Returns __kmpc_dispatch_init_* runtime function for the specified
315 /// size \a IVSize and sign \a IVSigned.
316 llvm::Constant *createDispatchInitFunction(unsigned IVSize, bool IVSigned);
317
318 /// \brief Returns __kmpc_dispatch_next_* runtime function for the specified
319 /// size \a IVSize and sign \a IVSigned.
320 llvm::Constant *createDispatchNextFunction(unsigned IVSize, bool IVSigned);
321
Alexey Bataev98eb6e32015-04-22 11:15:40 +0000322 /// \brief Returns __kmpc_dispatch_fini_* runtime function for the specified
323 /// size \a IVSize and sign \a IVSigned.
324 llvm::Constant *createDispatchFiniFunction(unsigned IVSize, bool IVSigned);
325
Alexey Bataev97720002014-11-11 04:05:39 +0000326 /// \brief If the specified mangled name is not in the module, create and
327 /// return threadprivate cache object. This object is a pointer's worth of
328 /// storage that's reserved for use by the OpenMP runtime.
NAKAMURA Takumicdcbfba2014-11-11 07:58:06 +0000329 /// \param VD Threadprivate variable.
Alexey Bataev97720002014-11-11 04:05:39 +0000330 /// \return Cache variable for the specified threadprivate.
331 llvm::Constant *getOrCreateThreadPrivateCache(const VarDecl *VD);
332
Alexey Bataevd74d0602014-10-13 06:02:40 +0000333 /// \brief Emits address of the word in a memory where current thread id is
334 /// stored.
John McCall7f416cc2015-09-08 08:05:57 +0000335 virtual Address emitThreadIDAddress(CodeGenFunction &CGF, SourceLocation Loc);
Alexey Bataevd74d0602014-10-13 06:02:40 +0000336
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000337 /// \brief Gets thread id value for the current thread.
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000338 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000339 llvm::Value *getThreadID(CodeGenFunction &CGF, SourceLocation Loc);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000340
Alexey Bataev97720002014-11-11 04:05:39 +0000341 /// \brief Gets (if variable with the given name already exist) or creates
342 /// internal global variable with the specified Name. The created variable has
343 /// linkage CommonLinkage by default and is initialized by null value.
344 /// \param Ty Type of the global variable. If it is exist already the type
345 /// must be the same.
346 /// \param Name Name of the variable.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000347 llvm::Constant *getOrCreateInternalVariable(llvm::Type *Ty,
Alexey Bataev97720002014-11-11 04:05:39 +0000348 const llvm::Twine &Name);
349
350 /// \brief Set of threadprivate variables with the generated initializer.
351 llvm::DenseSet<const VarDecl *> ThreadPrivateWithDefinition;
352
353 /// \brief Emits initialization code for the threadprivate variables.
354 /// \param VDAddr Address of the global variable \a VD.
355 /// \param Ctor Pointer to a global init function for \a VD.
356 /// \param CopyCtor Pointer to a global copy function for \a VD.
357 /// \param Dtor Pointer to a global destructor function for \a VD.
358 /// \param Loc Location of threadprivate declaration.
John McCall7f416cc2015-09-08 08:05:57 +0000359 void emitThreadPrivateVarInit(CodeGenFunction &CGF, Address VDAddr,
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000360 llvm::Value *Ctor, llvm::Value *CopyCtor,
361 llvm::Value *Dtor, SourceLocation Loc);
Alexey Bataev97720002014-11-11 04:05:39 +0000362
Alexey Bataev75ddfab2014-12-01 11:32:38 +0000363 /// \brief Returns corresponding lock object for the specified critical region
364 /// name. If the lock object does not exist it is created, otherwise the
365 /// reference to the existing copy is returned.
366 /// \param CriticalName Name of the critical region.
367 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000368 llvm::Value *getCriticalRegionLock(StringRef CriticalName);
Alexey Bataev75ddfab2014-12-01 11:32:38 +0000369
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000370public:
371 explicit CGOpenMPRuntime(CodeGenModule &CGM);
372 virtual ~CGOpenMPRuntime() {}
Alexey Bataev91797552015-03-18 04:13:55 +0000373 virtual void clear();
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000374
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000375 /// \brief Emits outlined function for the specified OpenMP parallel directive
376 /// \a D. This outlined function has type void(*)(kmp_int32 *ThreadID,
377 /// kmp_int32 BoundID, struct context_vars*).
Alexey Bataev18095712014-10-10 12:19:54 +0000378 /// \param D OpenMP directive.
379 /// \param ThreadIDVar Variable for thread id in the current OpenMP region.
Alexey Bataev81c7ea02015-07-03 09:56:58 +0000380 /// \param InnermostKind Kind of innermost directive (for simple directives it
381 /// is a directive itself, for combined - its innermost directive).
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000382 /// \param CodeGen Code generation sequence for the \a D directive.
Alexey Bataev81c7ea02015-07-03 09:56:58 +0000383 virtual llvm::Value *emitParallelOutlinedFunction(
384 const OMPExecutableDirective &D, const VarDecl *ThreadIDVar,
385 OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen);
Alexey Bataev18095712014-10-10 12:19:54 +0000386
Alexey Bataev62b63b12015-03-10 07:28:44 +0000387 /// \brief Emits outlined function for the OpenMP task directive \a D. This
388 /// outlined function has type void(*)(kmp_int32 ThreadID, kmp_int32
389 /// PartID, struct context_vars*).
390 /// \param D OpenMP directive.
391 /// \param ThreadIDVar Variable for thread id in the current OpenMP region.
Alexey Bataev81c7ea02015-07-03 09:56:58 +0000392 /// \param InnermostKind Kind of innermost directive (for simple directives it
393 /// is a directive itself, for combined - its innermost directive).
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000394 /// \param CodeGen Code generation sequence for the \a D directive.
Alexey Bataev62b63b12015-03-10 07:28:44 +0000395 ///
Alexey Bataev81c7ea02015-07-03 09:56:58 +0000396 virtual llvm::Value *emitTaskOutlinedFunction(
397 const OMPExecutableDirective &D, const VarDecl *ThreadIDVar,
398 OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen);
Alexey Bataev62b63b12015-03-10 07:28:44 +0000399
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000400 /// \brief Cleans up references to the objects in finished function.
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000401 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000402 void functionFinished(CodeGenFunction &CGF);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000403
Alexey Bataev1d677132015-04-22 13:57:31 +0000404 /// \brief Emits code for parallel or serial call of the \a OutlinedFn with
405 /// variables captured in a record which address is stored in \a
406 /// CapturedStruct.
Alexey Bataev18095712014-10-10 12:19:54 +0000407 /// \param OutlinedFn Outlined function to be run in parallel threads. Type of
Alexey Bataev62b63b12015-03-10 07:28:44 +0000408 /// this function is void(*)(kmp_int32 *, kmp_int32, struct context_vars*).
NAKAMURA Takumi62f0eb52015-09-11 08:13:32 +0000409 /// \param CapturedVars A pointer to the record with the references to
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000410 /// variables used in \a OutlinedFn function.
Alexey Bataev1d677132015-04-22 13:57:31 +0000411 /// \param IfCond Condition in the associated 'if' clause, if it was
412 /// specified, nullptr otherwise.
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000413 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000414 virtual void emitParallelCall(CodeGenFunction &CGF, SourceLocation Loc,
415 llvm::Value *OutlinedFn,
Alexey Bataev2377fe92015-09-10 08:12:02 +0000416 ArrayRef<llvm::Value *> CapturedVars,
417 const Expr *IfCond);
Alexey Bataevd74d0602014-10-13 06:02:40 +0000418
Alexey Bataev75ddfab2014-12-01 11:32:38 +0000419 /// \brief Emits a critical region.
Alexey Bataev18095712014-10-10 12:19:54 +0000420 /// \param CriticalName Name of the critical region.
Alexey Bataev75ddfab2014-12-01 11:32:38 +0000421 /// \param CriticalOpGen Generator for the statement associated with the given
422 /// critical region.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000423 virtual void emitCriticalRegion(CodeGenFunction &CGF, StringRef CriticalName,
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000424 const RegionCodeGenTy &CriticalOpGen,
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000425 SourceLocation Loc);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000426
Alexey Bataev8d690652014-12-04 07:23:53 +0000427 /// \brief Emits a master region.
428 /// \param MasterOpGen Generator for the statement associated with the given
429 /// master region.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000430 virtual void emitMasterRegion(CodeGenFunction &CGF,
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000431 const RegionCodeGenTy &MasterOpGen,
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000432 SourceLocation Loc);
Alexey Bataev8d690652014-12-04 07:23:53 +0000433
Alexey Bataev9f797f32015-02-05 05:57:51 +0000434 /// \brief Emits code for a taskyield directive.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000435 virtual void emitTaskyieldCall(CodeGenFunction &CGF, SourceLocation Loc);
Alexey Bataev9f797f32015-02-05 05:57:51 +0000436
Alexey Bataevc30dd2d2015-06-18 12:14:09 +0000437 /// \brief Emit a taskgroup region.
438 /// \param TaskgroupOpGen Generator for the statement associated with the
439 /// given taskgroup region.
440 virtual void emitTaskgroupRegion(CodeGenFunction &CGF,
441 const RegionCodeGenTy &TaskgroupOpGen,
442 SourceLocation Loc);
443
Alexey Bataev6956e2e2015-02-05 06:35:41 +0000444 /// \brief Emits a single region.
445 /// \param SingleOpGen Generator for the statement associated with the given
446 /// single region.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000447 virtual void emitSingleRegion(CodeGenFunction &CGF,
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000448 const RegionCodeGenTy &SingleOpGen,
Alexey Bataeva63048e2015-03-23 06:18:07 +0000449 SourceLocation Loc,
450 ArrayRef<const Expr *> CopyprivateVars,
Alexey Bataev420d45b2015-04-14 05:11:24 +0000451 ArrayRef<const Expr *> DestExprs,
Alexey Bataeva63048e2015-03-23 06:18:07 +0000452 ArrayRef<const Expr *> SrcExprs,
Alexey Bataeva63048e2015-03-23 06:18:07 +0000453 ArrayRef<const Expr *> AssignmentOps);
Alexey Bataev6956e2e2015-02-05 06:35:41 +0000454
Alexey Bataev98eb6e32015-04-22 11:15:40 +0000455 /// \brief Emit an ordered region.
456 /// \param OrderedOpGen Generator for the statement associated with the given
Alexey Bataevc30dd2d2015-06-18 12:14:09 +0000457 /// ordered region.
Alexey Bataev98eb6e32015-04-22 11:15:40 +0000458 virtual void emitOrderedRegion(CodeGenFunction &CGF,
459 const RegionCodeGenTy &OrderedOpGen,
Alexey Bataev5f600d62015-09-29 03:48:57 +0000460 SourceLocation Loc, bool IsThreads);
Alexey Bataev98eb6e32015-04-22 11:15:40 +0000461
Alexey Bataevf2685682015-03-30 04:30:22 +0000462 /// \brief Emit an implicit/explicit barrier for OpenMP threads.
463 /// \param Kind Directive for which this implicit barrier call must be
464 /// generated. Must be OMPD_barrier for explicit barrier generation.
Alexey Bataev25e5b442015-09-15 12:52:43 +0000465 /// \param EmitChecks true if need to emit checks for cancellation barriers.
466 /// \param ForceSimpleCall true simple barrier call must be emitted, false if
467 /// runtime class decides which one to emit (simple or with cancellation
468 /// checks).
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000469 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000470 virtual void emitBarrierCall(CodeGenFunction &CGF, SourceLocation Loc,
Alexey Bataev81c7ea02015-07-03 09:56:58 +0000471 OpenMPDirectiveKind Kind,
Alexey Bataev25e5b442015-09-15 12:52:43 +0000472 bool EmitChecks = true,
473 bool ForceSimpleCall = false);
Alexey Bataevb2059782014-10-13 08:23:51 +0000474
Alexander Musmanc6388682014-12-15 07:07:06 +0000475 /// \brief Check if the specified \a ScheduleKind is static non-chunked.
476 /// This kind of worksharing directive is emitted without outer loop.
477 /// \param ScheduleKind Schedule kind specified in the 'schedule' clause.
478 /// \param Chunked True if chunk is specified in the clause.
479 ///
480 virtual bool isStaticNonchunked(OpenMPScheduleClauseKind ScheduleKind,
481 bool Chunked) const;
482
Alexander Musmandf7a8e22015-01-22 08:49:35 +0000483 /// \brief Check if the specified \a ScheduleKind is dynamic.
484 /// This kind of worksharing directive is emitted without outer loop.
485 /// \param ScheduleKind Schedule Kind specified in the 'schedule' clause.
486 ///
487 virtual bool isDynamic(OpenMPScheduleClauseKind ScheduleKind) const;
488
NAKAMURA Takumiff7a9252015-09-08 09:42:41 +0000489 virtual void emitForDispatchInit(CodeGenFunction &CGF, SourceLocation Loc,
490 OpenMPScheduleClauseKind SchedKind,
491 unsigned IVSize, bool IVSigned,
492 bool Ordered, llvm::Value *UB,
493 llvm::Value *Chunk = nullptr);
494
Alexander Musmanc6388682014-12-15 07:07:06 +0000495 /// \brief Call the appropriate runtime routine to initialize it before start
496 /// of loop.
497 ///
498 /// Depending on the loop schedule, it is nesessary to call some runtime
499 /// routine before start of the OpenMP loop to get the loop upper / lower
500 /// bounds \a LB and \a UB and stride \a ST.
501 ///
502 /// \param CGF Reference to current CodeGenFunction.
503 /// \param Loc Clang source location.
NAKAMURA Takumieca08382014-12-17 14:47:06 +0000504 /// \param SchedKind Schedule kind, specified by the 'schedule' clause.
Alexander Musmanc6388682014-12-15 07:07:06 +0000505 /// \param IVSize Size of the iteration variable in bits.
506 /// \param IVSigned Sign of the interation variable.
Alexey Bataevd7589ffe2015-05-20 13:12:48 +0000507 /// \param Ordered true if loop is ordered, false otherwise.
Alexander Musmanc6388682014-12-15 07:07:06 +0000508 /// \param IL Address of the output variable in which the flag of the
509 /// last iteration is returned.
510 /// \param LB Address of the output variable in which the lower iteration
511 /// number is returned.
512 /// \param UB Address of the output variable in which the upper iteration
513 /// number is returned.
514 /// \param ST Address of the output variable in which the stride value is
515 /// returned nesessary to generated the static_chunked scheduled loop.
516 /// \param Chunk Value of the chunk for the static_chunked scheduled loop.
517 /// For the default (nullptr) value, the chunk 1 will be used.
518 ///
John McCall7f416cc2015-09-08 08:05:57 +0000519 virtual void emitForStaticInit(CodeGenFunction &CGF, SourceLocation Loc,
520 OpenMPScheduleClauseKind SchedKind,
521 unsigned IVSize, bool IVSigned, bool Ordered,
522 Address IL, Address LB,
523 Address UB, Address ST,
524 llvm::Value *Chunk = nullptr);
Alexander Musmanc6388682014-12-15 07:07:06 +0000525
526 /// \brief Call the appropriate runtime routine to notify that we finished
Alexey Bataev98eb6e32015-04-22 11:15:40 +0000527 /// iteration of the ordered loop with the dynamic scheduling.
528 ///
529 /// \param CGF Reference to current CodeGenFunction.
530 /// \param Loc Clang source location.
531 /// \param IVSize Size of the iteration variable in bits.
532 /// \param IVSigned Sign of the interation variable.
533 ///
Alexey Bataevd7589ffe2015-05-20 13:12:48 +0000534 virtual void emitForOrderedIterationEnd(CodeGenFunction &CGF,
535 SourceLocation Loc, unsigned IVSize,
536 bool IVSigned);
Alexey Bataev98eb6e32015-04-22 11:15:40 +0000537
538 /// \brief Call the appropriate runtime routine to notify that we finished
Alexander Musmanc6388682014-12-15 07:07:06 +0000539 /// all the work with current loop.
540 ///
541 /// \param CGF Reference to current CodeGenFunction.
542 /// \param Loc Clang source location.
Alexander Musmanc6388682014-12-15 07:07:06 +0000543 ///
Alexey Bataev98eb6e32015-04-22 11:15:40 +0000544 virtual void emitForStaticFinish(CodeGenFunction &CGF, SourceLocation Loc);
Alexander Musmanc6388682014-12-15 07:07:06 +0000545
Alexander Musman92bdaab2015-03-12 13:37:50 +0000546 /// Call __kmpc_dispatch_next(
547 /// ident_t *loc, kmp_int32 tid, kmp_int32 *p_lastiter,
548 /// kmp_int[32|64] *p_lower, kmp_int[32|64] *p_upper,
549 /// kmp_int[32|64] *p_stride);
550 /// \param IVSize Size of the iteration variable in bits.
551 /// \param IVSigned Sign of the interation variable.
552 /// \param IL Address of the output variable in which the flag of the
553 /// last iteration is returned.
554 /// \param LB Address of the output variable in which the lower iteration
555 /// number is returned.
556 /// \param UB Address of the output variable in which the upper iteration
557 /// number is returned.
558 /// \param ST Address of the output variable in which the stride value is
559 /// returned.
560 virtual llvm::Value *emitForNext(CodeGenFunction &CGF, SourceLocation Loc,
561 unsigned IVSize, bool IVSigned,
John McCall7f416cc2015-09-08 08:05:57 +0000562 Address IL, Address LB,
563 Address UB, Address ST);
Alexander Musman92bdaab2015-03-12 13:37:50 +0000564
Alexey Bataevb2059782014-10-13 08:23:51 +0000565 /// \brief Emits call to void __kmpc_push_num_threads(ident_t *loc, kmp_int32
566 /// global_tid, kmp_int32 num_threads) to generate code for 'num_threads'
567 /// clause.
568 /// \param NumThreads An integer value of threads.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000569 virtual void emitNumThreadsClause(CodeGenFunction &CGF,
570 llvm::Value *NumThreads,
571 SourceLocation Loc);
Alexey Bataev97720002014-11-11 04:05:39 +0000572
Alexey Bataev7f210c62015-06-18 13:40:03 +0000573 /// \brief Emit call to void __kmpc_push_proc_bind(ident_t *loc, kmp_int32
574 /// global_tid, int proc_bind) to generate code for 'proc_bind' clause.
575 virtual void emitProcBindClause(CodeGenFunction &CGF,
576 OpenMPProcBindClauseKind ProcBind,
577 SourceLocation Loc);
578
Alexey Bataev97720002014-11-11 04:05:39 +0000579 /// \brief Returns address of the threadprivate variable for the current
580 /// thread.
NAKAMURA Takumicdcbfba2014-11-11 07:58:06 +0000581 /// \param VD Threadprivate variable.
Alexey Bataev97720002014-11-11 04:05:39 +0000582 /// \param VDAddr Address of the global variable \a VD.
583 /// \param Loc Location of the reference to threadprivate var.
584 /// \return Address of the threadprivate variable for the current thread.
John McCall7f416cc2015-09-08 08:05:57 +0000585 virtual Address getAddrOfThreadPrivate(CodeGenFunction &CGF,
586 const VarDecl *VD,
587 Address VDAddr,
588 SourceLocation Loc);
Alexey Bataev97720002014-11-11 04:05:39 +0000589
590 /// \brief Emit a code for initialization of threadprivate variable. It emits
591 /// a call to runtime library which adds initial value to the newly created
592 /// threadprivate variable (if it is not constant) and registers destructor
593 /// for the variable (if any).
594 /// \param VD Threadprivate variable.
595 /// \param VDAddr Address of the global variable \a VD.
596 /// \param Loc Location of threadprivate declaration.
597 /// \param PerformInit true if initialization expression is not constant.
598 virtual llvm::Function *
John McCall7f416cc2015-09-08 08:05:57 +0000599 emitThreadPrivateVarDefinition(const VarDecl *VD, Address VDAddr,
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000600 SourceLocation Loc, bool PerformInit,
601 CodeGenFunction *CGF = nullptr);
Alexey Bataevcc37cc12014-11-20 04:34:54 +0000602
603 /// \brief Emit flush of the variables specified in 'omp flush' directive.
604 /// \param Vars List of variables to flush.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000605 virtual void emitFlush(CodeGenFunction &CGF, ArrayRef<const Expr *> Vars,
606 SourceLocation Loc);
Alexey Bataev62b63b12015-03-10 07:28:44 +0000607
608 /// \brief Emit task region for the task directive. The task region is
Nico Weber20b0ce32015-04-28 18:19:18 +0000609 /// emitted in several steps:
Alexey Bataev62b63b12015-03-10 07:28:44 +0000610 /// 1. Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32
611 /// gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds,
612 /// kmp_routine_entry_t *task_entry). Here task_entry is a pointer to the
613 /// function:
614 /// kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) {
615 /// TaskFunction(gtid, tt->part_id, tt->shareds);
616 /// return 0;
617 /// }
618 /// 2. Copy a list of shared variables to field shareds of the resulting
619 /// structure kmp_task_t returned by the previous call (if any).
620 /// 3. Copy a pointer to destructions function to field destructions of the
621 /// resulting structure kmp_task_t.
622 /// 4. Emit a call to kmp_int32 __kmpc_omp_task(ident_t *, kmp_int32 gtid,
623 /// kmp_task_t *new_task), where new_task is a resulting structure from
624 /// previous items.
Alexey Bataev36c1eb92015-04-30 06:51:57 +0000625 /// \param D Current task directive.
Alexey Bataev62b63b12015-03-10 07:28:44 +0000626 /// \param Tied true if the task is tied (the task is tied to the thread that
627 /// can suspend its task region), false - untied (the task is not tied to any
628 /// thread).
629 /// \param Final Contains either constant bool value, or llvm::Value * of i1
630 /// type for final clause. If the value is true, the task forces all of its
631 /// child tasks to become final and included tasks.
632 /// \param TaskFunction An LLVM function with type void (*)(i32 /*gtid*/, i32
633 /// /*part_id*/, captured_struct */*__context*/);
634 /// \param SharedsTy A type which contains references the shared variables.
Alexey Bataev1d2353d2015-06-24 11:01:36 +0000635 /// \param Shareds Context with the list of shared variables from the \p
Alexey Bataev62b63b12015-03-10 07:28:44 +0000636 /// TaskFunction.
Alexey Bataev1d677132015-04-22 13:57:31 +0000637 /// \param IfCond Not a nullptr if 'if' clause was specified, nullptr
638 /// otherwise.
Alexey Bataev36c1eb92015-04-30 06:51:57 +0000639 /// \param PrivateVars List of references to private variables for the task
640 /// directive.
641 /// \param PrivateCopies List of private copies for each private variable in
Alexey Bataev9e034042015-05-05 04:05:12 +0000642 /// \p PrivateVars.
643 /// \param FirstprivateVars List of references to private variables for the
644 /// task directive.
645 /// \param FirstprivateCopies List of private copies for each private variable
646 /// in \p FirstprivateVars.
647 /// \param FirstprivateInits List of references to auto generated variables
648 /// used for initialization of a single array element. Used if firstprivate
649 /// variable is of array type.
Alexey Bataev1d2353d2015-06-24 11:01:36 +0000650 /// \param Dependences List of dependences for the 'task' construct, including
651 /// original expression and dependency type.
652 virtual void emitTaskCall(
653 CodeGenFunction &CGF, SourceLocation Loc, const OMPExecutableDirective &D,
654 bool Tied, llvm::PointerIntPair<llvm::Value *, 1, bool> Final,
John McCall7f416cc2015-09-08 08:05:57 +0000655 llvm::Value *TaskFunction, QualType SharedsTy, Address Shareds,
Alexey Bataev1d2353d2015-06-24 11:01:36 +0000656 const Expr *IfCond, ArrayRef<const Expr *> PrivateVars,
657 ArrayRef<const Expr *> PrivateCopies,
658 ArrayRef<const Expr *> FirstprivateVars,
659 ArrayRef<const Expr *> FirstprivateCopies,
660 ArrayRef<const Expr *> FirstprivateInits,
661 ArrayRef<std::pair<OpenMPDependClauseKind, const Expr *>> Dependences);
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000662
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000663 /// \brief Emit code for the directive that does not require outlining.
664 ///
Alexey Bataev81c7ea02015-07-03 09:56:58 +0000665 /// \param InnermostKind Kind of innermost directive (for simple directives it
666 /// is a directive itself, for combined - its innermost directive).
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000667 /// \param CodeGen Code generation sequence for the \a D directive.
Alexey Bataev25e5b442015-09-15 12:52:43 +0000668 /// \param HasCancel true if region has inner cancel directive, false
669 /// otherwise.
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000670 virtual void emitInlinedDirective(CodeGenFunction &CGF,
Alexey Bataev81c7ea02015-07-03 09:56:58 +0000671 OpenMPDirectiveKind InnermostKind,
Alexey Bataev25e5b442015-09-15 12:52:43 +0000672 const RegionCodeGenTy &CodeGen,
673 bool HasCancel = false);
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000674 /// \brief Emit a code for reduction clause. Next code should be emitted for
675 /// reduction:
676 /// \code
677 ///
678 /// static kmp_critical_name lock = { 0 };
679 ///
680 /// void reduce_func(void *lhs[<n>], void *rhs[<n>]) {
681 /// ...
682 /// *(Type<i>*)lhs[i] = RedOp<i>(*(Type<i>*)lhs[i], *(Type<i>*)rhs[i]);
683 /// ...
684 /// }
685 ///
686 /// ...
687 /// void *RedList[<n>] = {&<RHSExprs>[0], ..., &<RHSExprs>[<n>-1]};
688 /// switch (__kmpc_reduce{_nowait}(<loc>, <gtid>, <n>, sizeof(RedList),
689 /// RedList, reduce_func, &<lock>)) {
690 /// case 1:
691 /// ...
692 /// <LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]);
693 /// ...
694 /// __kmpc_end_reduce{_nowait}(<loc>, <gtid>, &<lock>);
695 /// break;
696 /// case 2:
697 /// ...
698 /// Atomic(<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]));
699 /// ...
700 /// break;
701 /// default:;
702 /// }
703 /// \endcode
704 ///
705 /// \param LHSExprs List of LHS in \a ReductionOps reduction operations.
706 /// \param RHSExprs List of RHS in \a ReductionOps reduction operations.
707 /// \param ReductionOps List of reduction operations in form 'LHS binop RHS'
708 /// or 'operator binop(LHS, RHS)'.
709 /// \param WithNowait true if parent directive has also nowait clause, false
710 /// otherwise.
711 virtual void emitReduction(CodeGenFunction &CGF, SourceLocation Loc,
712 ArrayRef<const Expr *> LHSExprs,
713 ArrayRef<const Expr *> RHSExprs,
714 ArrayRef<const Expr *> ReductionOps,
Alexey Bataev89e7e8e2015-06-17 06:21:39 +0000715 bool WithNowait, bool SimpleReduction);
Alexey Bataev8b8e2022015-04-27 05:22:09 +0000716
717 /// \brief Emit code for 'taskwait' directive.
718 virtual void emitTaskwaitCall(CodeGenFunction &CGF, SourceLocation Loc);
Alexey Bataev0f34da12015-07-02 04:17:07 +0000719
720 /// \brief Emit code for 'cancellation point' construct.
721 /// \param CancelRegion Region kind for which the cancellation point must be
722 /// emitted.
723 ///
724 virtual void emitCancellationPointCall(CodeGenFunction &CGF,
725 SourceLocation Loc,
726 OpenMPDirectiveKind CancelRegion);
Alexey Bataev7d5d33e2015-07-06 05:50:32 +0000727
728 /// \brief Emit code for 'cancel' construct.
Alexey Bataev87933c72015-09-18 08:07:34 +0000729 /// \param IfCond Condition in the associated 'if' clause, if it was
730 /// specified, nullptr otherwise.
Alexey Bataev7d5d33e2015-07-06 05:50:32 +0000731 /// \param CancelRegion Region kind for which the cancel must be emitted.
732 ///
733 virtual void emitCancelCall(CodeGenFunction &CGF, SourceLocation Loc,
Alexey Bataev87933c72015-09-18 08:07:34 +0000734 const Expr *IfCond,
Alexey Bataev7d5d33e2015-07-06 05:50:32 +0000735 OpenMPDirectiveKind CancelRegion);
Samuel Antaobed3c462015-10-02 16:14:20 +0000736
737 /// \brief Emit outilined function for 'target' directive.
738 /// \param D Directive to emit.
739 /// \param CodeGen Code generation sequence for the \a D directive.
740 virtual llvm::Value *
741 emitTargetOutlinedFunction(const OMPExecutableDirective &D,
742 const RegionCodeGenTy &CodeGen);
743
744 /// \brief Emit the target offloading code associated with \a D. The emitted
745 /// code attempts offloading the execution to the device, an the event of
746 /// a failure it executes the host version outlined in \a OutlinedFn.
747 /// \param D Directive to emit.
748 /// \param OutlinedFn Host version of the code to be offloaded.
749 /// \param IfCond Expression evaluated in if clause associated with the target
750 /// directive, or null if no if clause is used.
751 /// \param Device Expression evaluated in device clause associated with the
752 /// target directive, or null if no device clause is used.
753 /// \param CapturedVars Values captured in the current region.
754 virtual void emitTargetCall(CodeGenFunction &CGF,
755 const OMPExecutableDirective &D,
756 llvm::Value *OutlinedFn, const Expr *IfCond,
757 const Expr *Device,
758 ArrayRef<llvm::Value *> CapturedVars);
Alexey Bataev9959db52014-05-06 10:08:46 +0000759};
Alexey Bataev8cbe0a62015-02-26 10:27:34 +0000760
Alexey Bataev23b69422014-06-18 07:08:49 +0000761} // namespace CodeGen
762} // namespace clang
Alexey Bataev9959db52014-05-06 10:08:46 +0000763
764#endif