blob: 992f9a8805e28cc4e439135230232a3677fede48 [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,
Alexey Bataevfc57d162015-12-15 10:55:09 +000065 // Call to void __kmpc_critical_with_hint(ident_t *loc, kmp_int32
66 // global_tid, kmp_critical_name *crit, uintptr_t hint);
67 OMPRTL__kmpc_critical_with_hint,
Alexey Bataev8f7c1b02014-12-05 04:09:23 +000068 // Call to void __kmpc_end_critical(ident_t *loc, kmp_int32 global_tid,
69 // kmp_critical_name *crit);
70 OMPRTL__kmpc_end_critical,
71 // Call to kmp_int32 __kmpc_cancel_barrier(ident_t *loc, kmp_int32
72 // global_tid);
73 OMPRTL__kmpc_cancel_barrier,
Alexey Bataev81c7ea02015-07-03 09:56:58 +000074 // Call to void __kmpc_barrier(ident_t *loc, kmp_int32 global_tid);
75 OMPRTL__kmpc_barrier,
Alexander Musman21212e42015-03-13 10:38:23 +000076 // Call to void __kmpc_for_static_fini(ident_t *loc, kmp_int32 global_tid);
Alexander Musmanc6388682014-12-15 07:07:06 +000077 OMPRTL__kmpc_for_static_fini,
Alexey Bataev8f7c1b02014-12-05 04:09:23 +000078 // Call to void __kmpc_serialized_parallel(ident_t *loc, kmp_int32
79 // global_tid);
80 OMPRTL__kmpc_serialized_parallel,
81 // Call to void __kmpc_end_serialized_parallel(ident_t *loc, kmp_int32
82 // global_tid);
83 OMPRTL__kmpc_end_serialized_parallel,
84 // Call to void __kmpc_push_num_threads(ident_t *loc, kmp_int32 global_tid,
85 // kmp_int32 num_threads);
86 OMPRTL__kmpc_push_num_threads,
Alexey Bataevd76df6d2015-02-24 12:55:09 +000087 // Call to void __kmpc_flush(ident_t *loc);
Alexey Bataev8f7c1b02014-12-05 04:09:23 +000088 OMPRTL__kmpc_flush,
89 // Call to kmp_int32 __kmpc_master(ident_t *, kmp_int32 global_tid);
90 OMPRTL__kmpc_master,
91 // Call to void __kmpc_end_master(ident_t *, kmp_int32 global_tid);
92 OMPRTL__kmpc_end_master,
Alexey Bataev9f797f32015-02-05 05:57:51 +000093 // Call to kmp_int32 __kmpc_omp_taskyield(ident_t *, kmp_int32 global_tid,
94 // int end_part);
95 OMPRTL__kmpc_omp_taskyield,
Alexey Bataev6956e2e2015-02-05 06:35:41 +000096 // Call to kmp_int32 __kmpc_single(ident_t *, kmp_int32 global_tid);
97 OMPRTL__kmpc_single,
98 // Call to void __kmpc_end_single(ident_t *, kmp_int32 global_tid);
99 OMPRTL__kmpc_end_single,
Alexey Bataev62b63b12015-03-10 07:28:44 +0000100 // Call to kmp_task_t * __kmpc_omp_task_alloc(ident_t *, kmp_int32 gtid,
101 // kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds,
102 // kmp_routine_entry_t *task_entry);
103 OMPRTL__kmpc_omp_task_alloc,
104 // Call to kmp_int32 __kmpc_omp_task(ident_t *, kmp_int32 gtid, kmp_task_t *
105 // new_task);
106 OMPRTL__kmpc_omp_task,
Alexey Bataeva63048e2015-03-23 06:18:07 +0000107 // Call to void __kmpc_copyprivate(ident_t *loc, kmp_int32 global_tid,
Alexey Bataev66beaa92015-04-30 03:47:32 +0000108 // size_t cpy_size, void *cpy_data, void(*cpy_func)(void *, void *),
Alexey Bataeva63048e2015-03-23 06:18:07 +0000109 // kmp_int32 didit);
110 OMPRTL__kmpc_copyprivate,
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000111 // Call to kmp_int32 __kmpc_reduce(ident_t *loc, kmp_int32 global_tid,
112 // kmp_int32 num_vars, size_t reduce_size, void *reduce_data, void
113 // (*reduce_func)(void *lhs_data, void *rhs_data), kmp_critical_name *lck);
114 OMPRTL__kmpc_reduce,
115 // Call to kmp_int32 __kmpc_reduce_nowait(ident_t *loc, kmp_int32
116 // global_tid, kmp_int32 num_vars, size_t reduce_size, void *reduce_data,
117 // void (*reduce_func)(void *lhs_data, void *rhs_data), kmp_critical_name
118 // *lck);
119 OMPRTL__kmpc_reduce_nowait,
120 // Call to void __kmpc_end_reduce(ident_t *loc, kmp_int32 global_tid,
121 // kmp_critical_name *lck);
122 OMPRTL__kmpc_end_reduce,
123 // Call to void __kmpc_end_reduce_nowait(ident_t *loc, kmp_int32 global_tid,
124 // kmp_critical_name *lck);
125 OMPRTL__kmpc_end_reduce_nowait,
Alexey Bataev1d677132015-04-22 13:57:31 +0000126 // Call to void __kmpc_omp_task_begin_if0(ident_t *, kmp_int32 gtid,
127 // kmp_task_t * new_task);
128 OMPRTL__kmpc_omp_task_begin_if0,
129 // Call to void __kmpc_omp_task_complete_if0(ident_t *, kmp_int32 gtid,
130 // kmp_task_t * new_task);
131 OMPRTL__kmpc_omp_task_complete_if0,
Alexey Bataev98eb6e32015-04-22 11:15:40 +0000132 // Call to void __kmpc_ordered(ident_t *loc, kmp_int32 global_tid);
133 OMPRTL__kmpc_ordered,
134 // Call to void __kmpc_end_ordered(ident_t *loc, kmp_int32 global_tid);
135 OMPRTL__kmpc_end_ordered,
Alexey Bataev8b8e2022015-04-27 05:22:09 +0000136 // Call to kmp_int32 __kmpc_omp_taskwait(ident_t *loc, kmp_int32
137 // global_tid);
138 OMPRTL__kmpc_omp_taskwait,
Alexey Bataevc30dd2d2015-06-18 12:14:09 +0000139 // Call to void __kmpc_taskgroup(ident_t *loc, kmp_int32 global_tid);
140 OMPRTL__kmpc_taskgroup,
141 // Call to void __kmpc_end_taskgroup(ident_t *loc, kmp_int32 global_tid);
142 OMPRTL__kmpc_end_taskgroup,
Alexey Bataev7f210c62015-06-18 13:40:03 +0000143 // Call to void __kmpc_push_proc_bind(ident_t *loc, kmp_int32 global_tid,
144 // int proc_bind);
145 OMPRTL__kmpc_push_proc_bind,
Alexey Bataev1d2353d2015-06-24 11:01:36 +0000146 // Call to kmp_int32 __kmpc_omp_task_with_deps(ident_t *loc_ref, kmp_int32
147 // gtid, kmp_task_t * new_task, kmp_int32 ndeps, kmp_depend_info_t
148 // *dep_list, kmp_int32 ndeps_noalias, kmp_depend_info_t *noalias_dep_list);
149 OMPRTL__kmpc_omp_task_with_deps,
150 // Call to void __kmpc_omp_wait_deps(ident_t *loc_ref, kmp_int32
151 // gtid, kmp_int32 ndeps, kmp_depend_info_t *dep_list, kmp_int32
152 // ndeps_noalias, kmp_depend_info_t *noalias_dep_list);
153 OMPRTL__kmpc_omp_wait_deps,
Alexey Bataev0f34da12015-07-02 04:17:07 +0000154 // Call to kmp_int32 __kmpc_cancellationpoint(ident_t *loc, kmp_int32
155 // global_tid, kmp_int32 cncl_kind);
156 OMPRTL__kmpc_cancellationpoint,
Alexey Bataev7d5d33e2015-07-06 05:50:32 +0000157 // Call to kmp_int32 __kmpc_cancel(ident_t *loc, kmp_int32 global_tid,
158 // kmp_int32 cncl_kind);
159 OMPRTL__kmpc_cancel,
Samuel Antaobed3c462015-10-02 16:14:20 +0000160
161 //
162 // Offloading related calls
163 //
164 // Call to int32_t __tgt_target(int32_t device_id, void *host_ptr, int32_t
165 // arg_num, void** args_base, void **args, size_t *arg_sizes, int32_t
166 // *arg_types);
167 OMPRTL__tgt_target,
Alexey Bataev8f7c1b02014-12-05 04:09:23 +0000168 };
169
Alexey Bataev9959db52014-05-06 10:08:46 +0000170 /// \brief Values for bit flags used in the ident_t to describe the fields.
171 /// All enumeric elements are named and described in accordance with the code
172 /// from http://llvm.org/svn/llvm-project/openmp/trunk/runtime/src/kmp.h
173 enum OpenMPLocationFlags {
174 /// \brief Use trampoline for internal microtask.
175 OMP_IDENT_IMD = 0x01,
176 /// \brief Use c-style ident structure.
177 OMP_IDENT_KMPC = 0x02,
178 /// \brief Atomic reduction option for kmpc_reduce.
179 OMP_ATOMIC_REDUCE = 0x10,
180 /// \brief Explicit 'barrier' directive.
181 OMP_IDENT_BARRIER_EXPL = 0x20,
182 /// \brief Implicit barrier in code.
183 OMP_IDENT_BARRIER_IMPL = 0x40,
184 /// \brief Implicit barrier in 'for' directive.
185 OMP_IDENT_BARRIER_IMPL_FOR = 0x40,
186 /// \brief Implicit barrier in 'sections' directive.
187 OMP_IDENT_BARRIER_IMPL_SECTIONS = 0xC0,
188 /// \brief Implicit barrier in 'single' directive.
189 OMP_IDENT_BARRIER_IMPL_SINGLE = 0x140
190 };
Alexey Bataev9959db52014-05-06 10:08:46 +0000191 CodeGenModule &CGM;
192 /// \brief Default const ident_t object used for initialization of all other
193 /// ident_t objects.
194 llvm::Constant *DefaultOpenMPPSource;
Alexey Bataev18095712014-10-10 12:19:54 +0000195 /// \brief Map of flags and corresponding default locations.
Alexey Bataev15007ba2014-05-07 06:18:01 +0000196 typedef llvm::DenseMap<unsigned, llvm::Value *> OpenMPDefaultLocMapTy;
197 OpenMPDefaultLocMapTy OpenMPDefaultLocMap;
John McCall7f416cc2015-09-08 08:05:57 +0000198 Address getOrCreateDefaultLocation(OpenMPLocationFlags Flags);
199
200public:
Alexey Bataev9959db52014-05-06 10:08:46 +0000201 /// \brief Describes ident structure that describes a source location.
202 /// All descriptions are taken from
203 /// http://llvm.org/svn/llvm-project/openmp/trunk/runtime/src/kmp.h
204 /// Original structure:
205 /// typedef struct ident {
206 /// kmp_int32 reserved_1; /**< might be used in Fortran;
207 /// see above */
208 /// kmp_int32 flags; /**< also f.flags; KMP_IDENT_xxx flags;
209 /// KMP_IDENT_KMPC identifies this union
210 /// member */
211 /// kmp_int32 reserved_2; /**< not really used in Fortran any more;
212 /// see above */
213 ///#if USE_ITT_BUILD
214 /// /* but currently used for storing
215 /// region-specific ITT */
216 /// /* contextual information. */
217 ///#endif /* USE_ITT_BUILD */
218 /// kmp_int32 reserved_3; /**< source[4] in Fortran, do not use for
219 /// C++ */
220 /// char const *psource; /**< String describing the source location.
221 /// The string is composed of semi-colon separated
222 // fields which describe the source file,
223 /// the function and a pair of line numbers that
224 /// delimit the construct.
225 /// */
226 /// } ident_t;
227 enum IdentFieldIndex {
228 /// \brief might be used in Fortran
229 IdentField_Reserved_1,
230 /// \brief OMP_IDENT_xxx flags; OMP_IDENT_KMPC identifies this union member.
231 IdentField_Flags,
232 /// \brief Not really used in Fortran any more
233 IdentField_Reserved_2,
234 /// \brief Source[4] in Fortran, do not use for C++
235 IdentField_Reserved_3,
236 /// \brief String describing the source location. The string is composed of
237 /// semi-colon separated fields which describe the source file, the function
238 /// and a pair of line numbers that delimit the construct.
239 IdentField_PSource
240 };
John McCall7f416cc2015-09-08 08:05:57 +0000241private:
Alexey Bataev9959db52014-05-06 10:08:46 +0000242 llvm::StructType *IdentTy;
Alexey Bataev18095712014-10-10 12:19:54 +0000243 /// \brief Map for SourceLocation and OpenMP runtime library debug locations.
Alexey Bataevf002aca2014-05-30 05:48:40 +0000244 typedef llvm::DenseMap<unsigned, llvm::Value *> OpenMPDebugLocMapTy;
245 OpenMPDebugLocMapTy OpenMPDebugLocMap;
Alexey Bataev9959db52014-05-06 10:08:46 +0000246 /// \brief The type for a microtask which gets passed to __kmpc_fork_call().
247 /// Original representation is:
248 /// typedef void (kmpc_micro)(kmp_int32 global_tid, kmp_int32 bound_tid,...);
249 llvm::FunctionType *Kmpc_MicroTy;
Alexey Bataev18095712014-10-10 12:19:54 +0000250 /// \brief Stores debug location and ThreadID for the function.
251 struct DebugLocThreadIdTy {
252 llvm::Value *DebugLoc;
253 llvm::Value *ThreadID;
254 };
255 /// \brief Map of local debug location, ThreadId and functions.
256 typedef llvm::DenseMap<llvm::Function *, DebugLocThreadIdTy>
257 OpenMPLocThreadIDMapTy;
258 OpenMPLocThreadIDMapTy OpenMPLocThreadIDMap;
Alexey Bataev3a3bf0b2014-09-22 10:01:53 +0000259 /// \brief Type kmp_critical_name, originally defined as typedef kmp_int32
260 /// kmp_critical_name[8];
261 llvm::ArrayType *KmpCriticalNameTy;
Alexey Bataev97720002014-11-11 04:05:39 +0000262 /// \brief An ordered map of auto-generated variables to their unique names.
263 /// It stores variables with the following names: 1) ".gomp_critical_user_" +
264 /// <critical_section_name> + ".var" for "omp critical" directives; 2)
265 /// <mangled_name_for_global_var> + ".cache." for cache for threadprivate
266 /// variables.
267 llvm::StringMap<llvm::AssertingVH<llvm::Constant>, llvm::BumpPtrAllocator>
268 InternalVars;
Alexey Bataev62b63b12015-03-10 07:28:44 +0000269 /// \brief Type typedef kmp_int32 (* kmp_routine_entry_t)(kmp_int32, void *);
270 llvm::Type *KmpRoutineEntryPtrTy;
271 QualType KmpRoutineEntryPtrQTy;
Alexey Bataev8fc69dc2015-05-18 07:54:53 +0000272 /// \brief Type typedef struct kmp_task {
273 /// void * shareds; /**< pointer to block of pointers to
274 /// shared vars */
275 /// kmp_routine_entry_t routine; /**< pointer to routine to call for
276 /// executing task */
277 /// kmp_int32 part_id; /**< part id for the task */
278 /// kmp_routine_entry_t destructors; /* pointer to function to invoke
279 /// deconstructors of firstprivate C++ objects */
280 /// } kmp_task_t;
281 QualType KmpTaskTQTy;
Alexey Bataev1d2353d2015-06-24 11:01:36 +0000282 /// \brief Type typedef struct kmp_depend_info {
283 /// kmp_intptr_t base_addr;
284 /// size_t len;
285 /// struct {
286 /// bool in:1;
287 /// bool out:1;
288 /// } flags;
289 /// } kmp_depend_info_t;
290 QualType KmpDependInfoTy;
291
Alexey Bataev62b63b12015-03-10 07:28:44 +0000292
293 /// \brief Build type kmp_routine_entry_t (if not built yet).
294 void emitKmpRoutineEntryT(QualType KmpInt32Ty);
Alexey Bataev9959db52014-05-06 10:08:46 +0000295
Alexey Bataev9959db52014-05-06 10:08:46 +0000296 /// \brief Emits object of ident_t type with info for source location.
Alexey Bataev9959db52014-05-06 10:08:46 +0000297 /// \param Flags Flags for OpenMP location.
298 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000299 llvm::Value *emitUpdateLocation(CodeGenFunction &CGF, SourceLocation Loc,
300 OpenMPLocationFlags Flags = OMP_IDENT_KMPC);
Alexey Bataev9959db52014-05-06 10:08:46 +0000301
Alexey Bataevd74d0602014-10-13 06:02:40 +0000302 /// \brief Returns pointer to ident_t type.
Alexey Bataev9959db52014-05-06 10:08:46 +0000303 llvm::Type *getIdentTyPointerTy();
304
Alexey Bataevd74d0602014-10-13 06:02:40 +0000305 /// \brief Returns pointer to kmpc_micro type.
Alexey Bataev9959db52014-05-06 10:08:46 +0000306 llvm::Type *getKmpc_MicroPointerTy();
307
308 /// \brief Returns specified OpenMP runtime function.
309 /// \param Function OpenMP runtime function.
310 /// \return Specified function.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000311 llvm::Constant *createRuntimeFunction(OpenMPRTLFunction Function);
Alexey Bataev3a3bf0b2014-09-22 10:01:53 +0000312
Alexander Musman21212e42015-03-13 10:38:23 +0000313 /// \brief Returns __kmpc_for_static_init_* runtime function for the specified
314 /// size \a IVSize and sign \a IVSigned.
315 llvm::Constant *createForStaticInitFunction(unsigned IVSize, bool IVSigned);
316
Alexander Musman92bdaab2015-03-12 13:37:50 +0000317 /// \brief Returns __kmpc_dispatch_init_* runtime function for the specified
318 /// size \a IVSize and sign \a IVSigned.
319 llvm::Constant *createDispatchInitFunction(unsigned IVSize, bool IVSigned);
320
321 /// \brief Returns __kmpc_dispatch_next_* runtime function for the specified
322 /// size \a IVSize and sign \a IVSigned.
323 llvm::Constant *createDispatchNextFunction(unsigned IVSize, bool IVSigned);
324
Alexey Bataev98eb6e32015-04-22 11:15:40 +0000325 /// \brief Returns __kmpc_dispatch_fini_* runtime function for the specified
326 /// size \a IVSize and sign \a IVSigned.
327 llvm::Constant *createDispatchFiniFunction(unsigned IVSize, bool IVSigned);
328
Alexey Bataev97720002014-11-11 04:05:39 +0000329 /// \brief If the specified mangled name is not in the module, create and
330 /// return threadprivate cache object. This object is a pointer's worth of
331 /// storage that's reserved for use by the OpenMP runtime.
NAKAMURA Takumicdcbfba2014-11-11 07:58:06 +0000332 /// \param VD Threadprivate variable.
Alexey Bataev97720002014-11-11 04:05:39 +0000333 /// \return Cache variable for the specified threadprivate.
334 llvm::Constant *getOrCreateThreadPrivateCache(const VarDecl *VD);
335
Alexey Bataevd74d0602014-10-13 06:02:40 +0000336 /// \brief Emits address of the word in a memory where current thread id is
337 /// stored.
John McCall7f416cc2015-09-08 08:05:57 +0000338 virtual Address emitThreadIDAddress(CodeGenFunction &CGF, SourceLocation Loc);
Alexey Bataevd74d0602014-10-13 06:02:40 +0000339
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000340 /// \brief Gets thread id value for the current thread.
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000341 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000342 llvm::Value *getThreadID(CodeGenFunction &CGF, SourceLocation Loc);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000343
Alexey Bataev97720002014-11-11 04:05:39 +0000344 /// \brief Gets (if variable with the given name already exist) or creates
345 /// internal global variable with the specified Name. The created variable has
346 /// linkage CommonLinkage by default and is initialized by null value.
347 /// \param Ty Type of the global variable. If it is exist already the type
348 /// must be the same.
349 /// \param Name Name of the variable.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000350 llvm::Constant *getOrCreateInternalVariable(llvm::Type *Ty,
Alexey Bataev97720002014-11-11 04:05:39 +0000351 const llvm::Twine &Name);
352
353 /// \brief Set of threadprivate variables with the generated initializer.
354 llvm::DenseSet<const VarDecl *> ThreadPrivateWithDefinition;
355
356 /// \brief Emits initialization code for the threadprivate variables.
357 /// \param VDAddr Address of the global variable \a VD.
358 /// \param Ctor Pointer to a global init function for \a VD.
359 /// \param CopyCtor Pointer to a global copy function for \a VD.
360 /// \param Dtor Pointer to a global destructor function for \a VD.
361 /// \param Loc Location of threadprivate declaration.
John McCall7f416cc2015-09-08 08:05:57 +0000362 void emitThreadPrivateVarInit(CodeGenFunction &CGF, Address VDAddr,
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000363 llvm::Value *Ctor, llvm::Value *CopyCtor,
364 llvm::Value *Dtor, SourceLocation Loc);
Alexey Bataev97720002014-11-11 04:05:39 +0000365
Alexey Bataev75ddfab2014-12-01 11:32:38 +0000366 /// \brief Returns corresponding lock object for the specified critical region
367 /// name. If the lock object does not exist it is created, otherwise the
368 /// reference to the existing copy is returned.
369 /// \param CriticalName Name of the critical region.
370 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000371 llvm::Value *getCriticalRegionLock(StringRef CriticalName);
Alexey Bataev75ddfab2014-12-01 11:32:38 +0000372
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000373public:
374 explicit CGOpenMPRuntime(CodeGenModule &CGM);
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +0000375 virtual ~CGOpenMPRuntime() {}
Alexey Bataev91797552015-03-18 04:13:55 +0000376 virtual void clear();
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000377
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000378 /// \brief Emits outlined function for the specified OpenMP parallel directive
379 /// \a D. This outlined function has type void(*)(kmp_int32 *ThreadID,
380 /// kmp_int32 BoundID, struct context_vars*).
Alexey Bataev18095712014-10-10 12:19:54 +0000381 /// \param D OpenMP directive.
382 /// \param ThreadIDVar Variable for thread id in the current OpenMP region.
Alexey Bataev81c7ea02015-07-03 09:56:58 +0000383 /// \param InnermostKind Kind of innermost directive (for simple directives it
384 /// is a directive itself, for combined - its innermost directive).
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000385 /// \param CodeGen Code generation sequence for the \a D directive.
Alexey Bataev81c7ea02015-07-03 09:56:58 +0000386 virtual llvm::Value *emitParallelOutlinedFunction(
387 const OMPExecutableDirective &D, const VarDecl *ThreadIDVar,
388 OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen);
Alexey Bataev18095712014-10-10 12:19:54 +0000389
Alexey Bataev62b63b12015-03-10 07:28:44 +0000390 /// \brief Emits outlined function for the OpenMP task directive \a D. This
391 /// outlined function has type void(*)(kmp_int32 ThreadID, kmp_int32
392 /// PartID, struct context_vars*).
393 /// \param D OpenMP directive.
394 /// \param ThreadIDVar Variable for thread id in the current OpenMP region.
Alexey Bataev81c7ea02015-07-03 09:56:58 +0000395 /// \param InnermostKind Kind of innermost directive (for simple directives it
396 /// is a directive itself, for combined - its innermost directive).
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000397 /// \param CodeGen Code generation sequence for the \a D directive.
Alexey Bataev62b63b12015-03-10 07:28:44 +0000398 ///
Alexey Bataev81c7ea02015-07-03 09:56:58 +0000399 virtual llvm::Value *emitTaskOutlinedFunction(
400 const OMPExecutableDirective &D, const VarDecl *ThreadIDVar,
401 OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen);
Alexey Bataev62b63b12015-03-10 07:28:44 +0000402
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000403 /// \brief Cleans up references to the objects in finished function.
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000404 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000405 void functionFinished(CodeGenFunction &CGF);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000406
Alexey Bataev1d677132015-04-22 13:57:31 +0000407 /// \brief Emits code for parallel or serial call of the \a OutlinedFn with
408 /// variables captured in a record which address is stored in \a
409 /// CapturedStruct.
Alexey Bataev18095712014-10-10 12:19:54 +0000410 /// \param OutlinedFn Outlined function to be run in parallel threads. Type of
Alexey Bataev62b63b12015-03-10 07:28:44 +0000411 /// this function is void(*)(kmp_int32 *, kmp_int32, struct context_vars*).
NAKAMURA Takumi62f0eb52015-09-11 08:13:32 +0000412 /// \param CapturedVars A pointer to the record with the references to
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000413 /// variables used in \a OutlinedFn function.
Alexey Bataev1d677132015-04-22 13:57:31 +0000414 /// \param IfCond Condition in the associated 'if' clause, if it was
415 /// specified, nullptr otherwise.
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000416 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000417 virtual void emitParallelCall(CodeGenFunction &CGF, SourceLocation Loc,
418 llvm::Value *OutlinedFn,
Alexey Bataev2377fe92015-09-10 08:12:02 +0000419 ArrayRef<llvm::Value *> CapturedVars,
420 const Expr *IfCond);
Alexey Bataevd74d0602014-10-13 06:02:40 +0000421
Alexey Bataev75ddfab2014-12-01 11:32:38 +0000422 /// \brief Emits a critical region.
Alexey Bataev18095712014-10-10 12:19:54 +0000423 /// \param CriticalName Name of the critical region.
Alexey Bataev75ddfab2014-12-01 11:32:38 +0000424 /// \param CriticalOpGen Generator for the statement associated with the given
425 /// critical region.
Alexey Bataevfc57d162015-12-15 10:55:09 +0000426 /// \param Hint Value of the 'hint' clause (optional).
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000427 virtual void emitCriticalRegion(CodeGenFunction &CGF, StringRef CriticalName,
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000428 const RegionCodeGenTy &CriticalOpGen,
Alexey Bataevfc57d162015-12-15 10:55:09 +0000429 SourceLocation Loc,
430 const Expr *Hint = nullptr);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000431
Alexey Bataev8d690652014-12-04 07:23:53 +0000432 /// \brief Emits a master region.
433 /// \param MasterOpGen Generator for the statement associated with the given
434 /// master region.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000435 virtual void emitMasterRegion(CodeGenFunction &CGF,
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000436 const RegionCodeGenTy &MasterOpGen,
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000437 SourceLocation Loc);
Alexey Bataev8d690652014-12-04 07:23:53 +0000438
Alexey Bataev9f797f32015-02-05 05:57:51 +0000439 /// \brief Emits code for a taskyield directive.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000440 virtual void emitTaskyieldCall(CodeGenFunction &CGF, SourceLocation Loc);
Alexey Bataev9f797f32015-02-05 05:57:51 +0000441
Alexey Bataevc30dd2d2015-06-18 12:14:09 +0000442 /// \brief Emit a taskgroup region.
443 /// \param TaskgroupOpGen Generator for the statement associated with the
444 /// given taskgroup region.
445 virtual void emitTaskgroupRegion(CodeGenFunction &CGF,
446 const RegionCodeGenTy &TaskgroupOpGen,
447 SourceLocation Loc);
448
Alexey Bataev6956e2e2015-02-05 06:35:41 +0000449 /// \brief Emits a single region.
450 /// \param SingleOpGen Generator for the statement associated with the given
451 /// single region.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000452 virtual void emitSingleRegion(CodeGenFunction &CGF,
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000453 const RegionCodeGenTy &SingleOpGen,
Alexey Bataeva63048e2015-03-23 06:18:07 +0000454 SourceLocation Loc,
455 ArrayRef<const Expr *> CopyprivateVars,
Alexey Bataev420d45b2015-04-14 05:11:24 +0000456 ArrayRef<const Expr *> DestExprs,
Alexey Bataeva63048e2015-03-23 06:18:07 +0000457 ArrayRef<const Expr *> SrcExprs,
Alexey Bataeva63048e2015-03-23 06:18:07 +0000458 ArrayRef<const Expr *> AssignmentOps);
Alexey Bataev6956e2e2015-02-05 06:35:41 +0000459
Alexey Bataev98eb6e32015-04-22 11:15:40 +0000460 /// \brief Emit an ordered region.
461 /// \param OrderedOpGen Generator for the statement associated with the given
Alexey Bataevc30dd2d2015-06-18 12:14:09 +0000462 /// ordered region.
Alexey Bataev98eb6e32015-04-22 11:15:40 +0000463 virtual void emitOrderedRegion(CodeGenFunction &CGF,
464 const RegionCodeGenTy &OrderedOpGen,
Alexey Bataev5f600d62015-09-29 03:48:57 +0000465 SourceLocation Loc, bool IsThreads);
Alexey Bataev98eb6e32015-04-22 11:15:40 +0000466
Alexey Bataevf2685682015-03-30 04:30:22 +0000467 /// \brief Emit an implicit/explicit barrier for OpenMP threads.
468 /// \param Kind Directive for which this implicit barrier call must be
469 /// generated. Must be OMPD_barrier for explicit barrier generation.
Alexey Bataev25e5b442015-09-15 12:52:43 +0000470 /// \param EmitChecks true if need to emit checks for cancellation barriers.
471 /// \param ForceSimpleCall true simple barrier call must be emitted, false if
472 /// runtime class decides which one to emit (simple or with cancellation
473 /// checks).
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000474 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000475 virtual void emitBarrierCall(CodeGenFunction &CGF, SourceLocation Loc,
Alexey Bataev81c7ea02015-07-03 09:56:58 +0000476 OpenMPDirectiveKind Kind,
Alexey Bataev25e5b442015-09-15 12:52:43 +0000477 bool EmitChecks = true,
478 bool ForceSimpleCall = false);
Alexey Bataevb2059782014-10-13 08:23:51 +0000479
Alexander Musmanc6388682014-12-15 07:07:06 +0000480 /// \brief Check if the specified \a ScheduleKind is static non-chunked.
481 /// This kind of worksharing directive is emitted without outer loop.
482 /// \param ScheduleKind Schedule kind specified in the 'schedule' clause.
483 /// \param Chunked True if chunk is specified in the clause.
484 ///
485 virtual bool isStaticNonchunked(OpenMPScheduleClauseKind ScheduleKind,
486 bool Chunked) const;
487
Alexander Musmandf7a8e22015-01-22 08:49:35 +0000488 /// \brief Check if the specified \a ScheduleKind is dynamic.
489 /// This kind of worksharing directive is emitted without outer loop.
490 /// \param ScheduleKind Schedule Kind specified in the 'schedule' clause.
491 ///
492 virtual bool isDynamic(OpenMPScheduleClauseKind ScheduleKind) const;
493
NAKAMURA Takumiff7a9252015-09-08 09:42:41 +0000494 virtual void emitForDispatchInit(CodeGenFunction &CGF, SourceLocation Loc,
495 OpenMPScheduleClauseKind SchedKind,
496 unsigned IVSize, bool IVSigned,
497 bool Ordered, llvm::Value *UB,
498 llvm::Value *Chunk = nullptr);
499
Alexander Musmanc6388682014-12-15 07:07:06 +0000500 /// \brief Call the appropriate runtime routine to initialize it before start
501 /// of loop.
502 ///
503 /// Depending on the loop schedule, it is nesessary to call some runtime
504 /// routine before start of the OpenMP loop to get the loop upper / lower
505 /// bounds \a LB and \a UB and stride \a ST.
506 ///
507 /// \param CGF Reference to current CodeGenFunction.
508 /// \param Loc Clang source location.
NAKAMURA Takumieca08382014-12-17 14:47:06 +0000509 /// \param SchedKind Schedule kind, specified by the 'schedule' clause.
Alexander Musmanc6388682014-12-15 07:07:06 +0000510 /// \param IVSize Size of the iteration variable in bits.
511 /// \param IVSigned Sign of the interation variable.
Alexey Bataevd7589ffe2015-05-20 13:12:48 +0000512 /// \param Ordered true if loop is ordered, false otherwise.
Alexander Musmanc6388682014-12-15 07:07:06 +0000513 /// \param IL Address of the output variable in which the flag of the
514 /// last iteration is returned.
515 /// \param LB Address of the output variable in which the lower iteration
516 /// number is returned.
517 /// \param UB Address of the output variable in which the upper iteration
518 /// number is returned.
519 /// \param ST Address of the output variable in which the stride value is
520 /// returned nesessary to generated the static_chunked scheduled loop.
521 /// \param Chunk Value of the chunk for the static_chunked scheduled loop.
522 /// For the default (nullptr) value, the chunk 1 will be used.
523 ///
John McCall7f416cc2015-09-08 08:05:57 +0000524 virtual void emitForStaticInit(CodeGenFunction &CGF, SourceLocation Loc,
525 OpenMPScheduleClauseKind SchedKind,
526 unsigned IVSize, bool IVSigned, bool Ordered,
527 Address IL, Address LB,
528 Address UB, Address ST,
529 llvm::Value *Chunk = nullptr);
Alexander Musmanc6388682014-12-15 07:07:06 +0000530
531 /// \brief Call the appropriate runtime routine to notify that we finished
Alexey Bataev98eb6e32015-04-22 11:15:40 +0000532 /// iteration of the ordered loop with the dynamic scheduling.
533 ///
534 /// \param CGF Reference to current CodeGenFunction.
535 /// \param Loc Clang source location.
536 /// \param IVSize Size of the iteration variable in bits.
537 /// \param IVSigned Sign of the interation variable.
538 ///
Alexey Bataevd7589ffe2015-05-20 13:12:48 +0000539 virtual void emitForOrderedIterationEnd(CodeGenFunction &CGF,
540 SourceLocation Loc, unsigned IVSize,
541 bool IVSigned);
Alexey Bataev98eb6e32015-04-22 11:15:40 +0000542
543 /// \brief Call the appropriate runtime routine to notify that we finished
Alexander Musmanc6388682014-12-15 07:07:06 +0000544 /// all the work with current loop.
545 ///
546 /// \param CGF Reference to current CodeGenFunction.
547 /// \param Loc Clang source location.
Alexander Musmanc6388682014-12-15 07:07:06 +0000548 ///
Alexey Bataev98eb6e32015-04-22 11:15:40 +0000549 virtual void emitForStaticFinish(CodeGenFunction &CGF, SourceLocation Loc);
Alexander Musmanc6388682014-12-15 07:07:06 +0000550
Alexander Musman92bdaab2015-03-12 13:37:50 +0000551 /// Call __kmpc_dispatch_next(
552 /// ident_t *loc, kmp_int32 tid, kmp_int32 *p_lastiter,
553 /// kmp_int[32|64] *p_lower, kmp_int[32|64] *p_upper,
554 /// kmp_int[32|64] *p_stride);
555 /// \param IVSize Size of the iteration variable in bits.
556 /// \param IVSigned Sign of the interation variable.
557 /// \param IL Address of the output variable in which the flag of the
558 /// last iteration is returned.
559 /// \param LB Address of the output variable in which the lower iteration
560 /// number is returned.
561 /// \param UB Address of the output variable in which the upper iteration
562 /// number is returned.
563 /// \param ST Address of the output variable in which the stride value is
564 /// returned.
565 virtual llvm::Value *emitForNext(CodeGenFunction &CGF, SourceLocation Loc,
566 unsigned IVSize, bool IVSigned,
John McCall7f416cc2015-09-08 08:05:57 +0000567 Address IL, Address LB,
568 Address UB, Address ST);
Alexander Musman92bdaab2015-03-12 13:37:50 +0000569
Alexey Bataevb2059782014-10-13 08:23:51 +0000570 /// \brief Emits call to void __kmpc_push_num_threads(ident_t *loc, kmp_int32
571 /// global_tid, kmp_int32 num_threads) to generate code for 'num_threads'
572 /// clause.
573 /// \param NumThreads An integer value of threads.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000574 virtual void emitNumThreadsClause(CodeGenFunction &CGF,
575 llvm::Value *NumThreads,
576 SourceLocation Loc);
Alexey Bataev97720002014-11-11 04:05:39 +0000577
Alexey Bataev7f210c62015-06-18 13:40:03 +0000578 /// \brief Emit call to void __kmpc_push_proc_bind(ident_t *loc, kmp_int32
579 /// global_tid, int proc_bind) to generate code for 'proc_bind' clause.
580 virtual void emitProcBindClause(CodeGenFunction &CGF,
581 OpenMPProcBindClauseKind ProcBind,
582 SourceLocation Loc);
583
Alexey Bataev97720002014-11-11 04:05:39 +0000584 /// \brief Returns address of the threadprivate variable for the current
585 /// thread.
NAKAMURA Takumicdcbfba2014-11-11 07:58:06 +0000586 /// \param VD Threadprivate variable.
Alexey Bataev97720002014-11-11 04:05:39 +0000587 /// \param VDAddr Address of the global variable \a VD.
588 /// \param Loc Location of the reference to threadprivate var.
589 /// \return Address of the threadprivate variable for the current thread.
John McCall7f416cc2015-09-08 08:05:57 +0000590 virtual Address getAddrOfThreadPrivate(CodeGenFunction &CGF,
591 const VarDecl *VD,
592 Address VDAddr,
593 SourceLocation Loc);
Alexey Bataev97720002014-11-11 04:05:39 +0000594
595 /// \brief Emit a code for initialization of threadprivate variable. It emits
596 /// a call to runtime library which adds initial value to the newly created
597 /// threadprivate variable (if it is not constant) and registers destructor
598 /// for the variable (if any).
599 /// \param VD Threadprivate variable.
600 /// \param VDAddr Address of the global variable \a VD.
601 /// \param Loc Location of threadprivate declaration.
602 /// \param PerformInit true if initialization expression is not constant.
603 virtual llvm::Function *
John McCall7f416cc2015-09-08 08:05:57 +0000604 emitThreadPrivateVarDefinition(const VarDecl *VD, Address VDAddr,
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000605 SourceLocation Loc, bool PerformInit,
606 CodeGenFunction *CGF = nullptr);
Alexey Bataevcc37cc12014-11-20 04:34:54 +0000607
608 /// \brief Emit flush of the variables specified in 'omp flush' directive.
609 /// \param Vars List of variables to flush.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000610 virtual void emitFlush(CodeGenFunction &CGF, ArrayRef<const Expr *> Vars,
611 SourceLocation Loc);
Alexey Bataev62b63b12015-03-10 07:28:44 +0000612
613 /// \brief Emit task region for the task directive. The task region is
Nico Weber20b0ce32015-04-28 18:19:18 +0000614 /// emitted in several steps:
Alexey Bataev62b63b12015-03-10 07:28:44 +0000615 /// 1. Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32
616 /// gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds,
617 /// kmp_routine_entry_t *task_entry). Here task_entry is a pointer to the
618 /// function:
619 /// kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) {
620 /// TaskFunction(gtid, tt->part_id, tt->shareds);
621 /// return 0;
622 /// }
623 /// 2. Copy a list of shared variables to field shareds of the resulting
624 /// structure kmp_task_t returned by the previous call (if any).
625 /// 3. Copy a pointer to destructions function to field destructions of the
626 /// resulting structure kmp_task_t.
627 /// 4. Emit a call to kmp_int32 __kmpc_omp_task(ident_t *, kmp_int32 gtid,
628 /// kmp_task_t *new_task), where new_task is a resulting structure from
629 /// previous items.
Alexey Bataev36c1eb92015-04-30 06:51:57 +0000630 /// \param D Current task directive.
Alexey Bataev62b63b12015-03-10 07:28:44 +0000631 /// \param Tied true if the task is tied (the task is tied to the thread that
632 /// can suspend its task region), false - untied (the task is not tied to any
633 /// thread).
634 /// \param Final Contains either constant bool value, or llvm::Value * of i1
635 /// type for final clause. If the value is true, the task forces all of its
636 /// child tasks to become final and included tasks.
637 /// \param TaskFunction An LLVM function with type void (*)(i32 /*gtid*/, i32
638 /// /*part_id*/, captured_struct */*__context*/);
639 /// \param SharedsTy A type which contains references the shared variables.
Alexey Bataev1d2353d2015-06-24 11:01:36 +0000640 /// \param Shareds Context with the list of shared variables from the \p
Alexey Bataev62b63b12015-03-10 07:28:44 +0000641 /// TaskFunction.
Alexey Bataev1d677132015-04-22 13:57:31 +0000642 /// \param IfCond Not a nullptr if 'if' clause was specified, nullptr
643 /// otherwise.
Alexey Bataev36c1eb92015-04-30 06:51:57 +0000644 /// \param PrivateVars List of references to private variables for the task
645 /// directive.
646 /// \param PrivateCopies List of private copies for each private variable in
Alexey Bataev9e034042015-05-05 04:05:12 +0000647 /// \p PrivateVars.
648 /// \param FirstprivateVars List of references to private variables for the
649 /// task directive.
650 /// \param FirstprivateCopies List of private copies for each private variable
651 /// in \p FirstprivateVars.
652 /// \param FirstprivateInits List of references to auto generated variables
653 /// used for initialization of a single array element. Used if firstprivate
654 /// variable is of array type.
Alexey Bataev1d2353d2015-06-24 11:01:36 +0000655 /// \param Dependences List of dependences for the 'task' construct, including
656 /// original expression and dependency type.
657 virtual void emitTaskCall(
658 CodeGenFunction &CGF, SourceLocation Loc, const OMPExecutableDirective &D,
659 bool Tied, llvm::PointerIntPair<llvm::Value *, 1, bool> Final,
John McCall7f416cc2015-09-08 08:05:57 +0000660 llvm::Value *TaskFunction, QualType SharedsTy, Address Shareds,
Alexey Bataev1d2353d2015-06-24 11:01:36 +0000661 const Expr *IfCond, ArrayRef<const Expr *> PrivateVars,
662 ArrayRef<const Expr *> PrivateCopies,
663 ArrayRef<const Expr *> FirstprivateVars,
664 ArrayRef<const Expr *> FirstprivateCopies,
665 ArrayRef<const Expr *> FirstprivateInits,
666 ArrayRef<std::pair<OpenMPDependClauseKind, const Expr *>> Dependences);
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000667
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000668 /// \brief Emit code for the directive that does not require outlining.
669 ///
Alexey Bataev81c7ea02015-07-03 09:56:58 +0000670 /// \param InnermostKind Kind of innermost directive (for simple directives it
671 /// is a directive itself, for combined - its innermost directive).
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000672 /// \param CodeGen Code generation sequence for the \a D directive.
Alexey Bataev25e5b442015-09-15 12:52:43 +0000673 /// \param HasCancel true if region has inner cancel directive, false
674 /// otherwise.
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000675 virtual void emitInlinedDirective(CodeGenFunction &CGF,
Alexey Bataev81c7ea02015-07-03 09:56:58 +0000676 OpenMPDirectiveKind InnermostKind,
Alexey Bataev25e5b442015-09-15 12:52:43 +0000677 const RegionCodeGenTy &CodeGen,
678 bool HasCancel = false);
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000679 /// \brief Emit a code for reduction clause. Next code should be emitted for
680 /// reduction:
681 /// \code
682 ///
683 /// static kmp_critical_name lock = { 0 };
684 ///
685 /// void reduce_func(void *lhs[<n>], void *rhs[<n>]) {
686 /// ...
687 /// *(Type<i>*)lhs[i] = RedOp<i>(*(Type<i>*)lhs[i], *(Type<i>*)rhs[i]);
688 /// ...
689 /// }
690 ///
691 /// ...
692 /// void *RedList[<n>] = {&<RHSExprs>[0], ..., &<RHSExprs>[<n>-1]};
693 /// switch (__kmpc_reduce{_nowait}(<loc>, <gtid>, <n>, sizeof(RedList),
694 /// RedList, reduce_func, &<lock>)) {
695 /// case 1:
696 /// ...
697 /// <LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]);
698 /// ...
699 /// __kmpc_end_reduce{_nowait}(<loc>, <gtid>, &<lock>);
700 /// break;
701 /// case 2:
702 /// ...
703 /// Atomic(<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]));
704 /// ...
705 /// break;
706 /// default:;
707 /// }
708 /// \endcode
709 ///
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000710 /// \param Privates List of private copies for original reduction arguments.
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000711 /// \param LHSExprs List of LHS in \a ReductionOps reduction operations.
712 /// \param RHSExprs List of RHS in \a ReductionOps reduction operations.
713 /// \param ReductionOps List of reduction operations in form 'LHS binop RHS'
714 /// or 'operator binop(LHS, RHS)'.
715 /// \param WithNowait true if parent directive has also nowait clause, false
716 /// otherwise.
717 virtual void emitReduction(CodeGenFunction &CGF, SourceLocation Loc,
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000718 ArrayRef<const Expr *> Privates,
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000719 ArrayRef<const Expr *> LHSExprs,
720 ArrayRef<const Expr *> RHSExprs,
721 ArrayRef<const Expr *> ReductionOps,
Alexey Bataev89e7e8e2015-06-17 06:21:39 +0000722 bool WithNowait, bool SimpleReduction);
Alexey Bataev8b8e2022015-04-27 05:22:09 +0000723
724 /// \brief Emit code for 'taskwait' directive.
725 virtual void emitTaskwaitCall(CodeGenFunction &CGF, SourceLocation Loc);
Alexey Bataev0f34da12015-07-02 04:17:07 +0000726
727 /// \brief Emit code for 'cancellation point' construct.
728 /// \param CancelRegion Region kind for which the cancellation point must be
729 /// emitted.
730 ///
731 virtual void emitCancellationPointCall(CodeGenFunction &CGF,
732 SourceLocation Loc,
733 OpenMPDirectiveKind CancelRegion);
Alexey Bataev7d5d33e2015-07-06 05:50:32 +0000734
735 /// \brief Emit code for 'cancel' construct.
Alexey Bataev87933c72015-09-18 08:07:34 +0000736 /// \param IfCond Condition in the associated 'if' clause, if it was
737 /// specified, nullptr otherwise.
Alexey Bataev7d5d33e2015-07-06 05:50:32 +0000738 /// \param CancelRegion Region kind for which the cancel must be emitted.
739 ///
740 virtual void emitCancelCall(CodeGenFunction &CGF, SourceLocation Loc,
Alexey Bataev87933c72015-09-18 08:07:34 +0000741 const Expr *IfCond,
Alexey Bataev7d5d33e2015-07-06 05:50:32 +0000742 OpenMPDirectiveKind CancelRegion);
Samuel Antaobed3c462015-10-02 16:14:20 +0000743
744 /// \brief Emit outilined function for 'target' directive.
745 /// \param D Directive to emit.
Samuel Antao7d5de9a2016-01-05 19:16:13 +0000746 /// \param CodeGen Code generation sequence for the \a D directive.
747 virtual llvm::Value *
748 emitTargetOutlinedFunction(const OMPExecutableDirective &D,
749 const RegionCodeGenTy &CodeGen);
Samuel Antaobed3c462015-10-02 16:14:20 +0000750
751 /// \brief Emit the target offloading code associated with \a D. The emitted
752 /// code attempts offloading the execution to the device, an the event of
753 /// a failure it executes the host version outlined in \a OutlinedFn.
754 /// \param D Directive to emit.
755 /// \param OutlinedFn Host version of the code to be offloaded.
756 /// \param IfCond Expression evaluated in if clause associated with the target
757 /// directive, or null if no if clause is used.
758 /// \param Device Expression evaluated in device clause associated with the
759 /// target directive, or null if no device clause is used.
760 /// \param CapturedVars Values captured in the current region.
761 virtual void emitTargetCall(CodeGenFunction &CGF,
762 const OMPExecutableDirective &D,
Samuel Antao7d5de9a2016-01-05 19:16:13 +0000763 llvm::Value *OutlinedFn, const Expr *IfCond,
Samuel Antaobed3c462015-10-02 16:14:20 +0000764 const Expr *Device,
765 ArrayRef<llvm::Value *> CapturedVars);
Alexey Bataev9959db52014-05-06 10:08:46 +0000766};
Alexey Bataev8cbe0a62015-02-26 10:27:34 +0000767
Alexey Bataev23b69422014-06-18 07:08:49 +0000768} // namespace CodeGen
769} // namespace clang
Alexey Bataev9959db52014-05-06 10:08:46 +0000770
771#endif