blob: 54dd71c1a3d1d12b6c0d7af34f72335552932800 [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 {
42
Alexey Bataev18095712014-10-10 12:19:54 +000043class CodeGenFunction;
44class CodeGenModule;
Alexey Bataev9959db52014-05-06 10:08:46 +000045
46class CGOpenMPRuntime {
Alexey Bataev8f7c1b02014-12-05 04:09:23 +000047 enum OpenMPRTLFunction {
48 /// \brief Call to void __kmpc_fork_call(ident_t *loc, kmp_int32 argc,
49 /// kmpc_micro microtask, ...);
50 OMPRTL__kmpc_fork_call,
51 /// \brief Call to void *__kmpc_threadprivate_cached(ident_t *loc,
52 /// kmp_int32 global_tid, void *data, size_t size, void ***cache);
53 OMPRTL__kmpc_threadprivate_cached,
54 /// \brief Call to void __kmpc_threadprivate_register( ident_t *,
55 /// void *data, kmpc_ctor ctor, kmpc_cctor cctor, kmpc_dtor dtor);
56 OMPRTL__kmpc_threadprivate_register,
57 // Call to __kmpc_int32 kmpc_global_thread_num(ident_t *loc);
58 OMPRTL__kmpc_global_thread_num,
59 // Call to void __kmpc_critical(ident_t *loc, kmp_int32 global_tid,
60 // kmp_critical_name *crit);
61 OMPRTL__kmpc_critical,
62 // Call to void __kmpc_end_critical(ident_t *loc, kmp_int32 global_tid,
63 // kmp_critical_name *crit);
64 OMPRTL__kmpc_end_critical,
65 // Call to kmp_int32 __kmpc_cancel_barrier(ident_t *loc, kmp_int32
66 // global_tid);
67 OMPRTL__kmpc_cancel_barrier,
Alexander Musmanc6388682014-12-15 07:07:06 +000068 // Calls for static scheduling 'omp for' loops.
69 OMPRTL__kmpc_for_static_init_4,
70 OMPRTL__kmpc_for_static_init_4u,
71 OMPRTL__kmpc_for_static_init_8,
72 OMPRTL__kmpc_for_static_init_8u,
73 OMPRTL__kmpc_for_static_fini,
Alexey Bataev8f7c1b02014-12-05 04:09:23 +000074 // Call to void __kmpc_serialized_parallel(ident_t *loc, kmp_int32
75 // global_tid);
76 OMPRTL__kmpc_serialized_parallel,
77 // Call to void __kmpc_end_serialized_parallel(ident_t *loc, kmp_int32
78 // global_tid);
79 OMPRTL__kmpc_end_serialized_parallel,
80 // Call to void __kmpc_push_num_threads(ident_t *loc, kmp_int32 global_tid,
81 // kmp_int32 num_threads);
82 OMPRTL__kmpc_push_num_threads,
Alexey Bataevd76df6d2015-02-24 12:55:09 +000083 // Call to void __kmpc_flush(ident_t *loc);
Alexey Bataev8f7c1b02014-12-05 04:09:23 +000084 OMPRTL__kmpc_flush,
85 // Call to kmp_int32 __kmpc_master(ident_t *, kmp_int32 global_tid);
86 OMPRTL__kmpc_master,
87 // Call to void __kmpc_end_master(ident_t *, kmp_int32 global_tid);
88 OMPRTL__kmpc_end_master,
Alexey Bataev9f797f32015-02-05 05:57:51 +000089 // Call to kmp_int32 __kmpc_omp_taskyield(ident_t *, kmp_int32 global_tid,
90 // int end_part);
91 OMPRTL__kmpc_omp_taskyield,
Alexey Bataev6956e2e2015-02-05 06:35:41 +000092 // Call to kmp_int32 __kmpc_single(ident_t *, kmp_int32 global_tid);
93 OMPRTL__kmpc_single,
94 // Call to void __kmpc_end_single(ident_t *, kmp_int32 global_tid);
95 OMPRTL__kmpc_end_single,
Alexey Bataev62b63b12015-03-10 07:28:44 +000096 // Call to kmp_task_t * __kmpc_omp_task_alloc(ident_t *, kmp_int32 gtid,
97 // kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds,
98 // kmp_routine_entry_t *task_entry);
99 OMPRTL__kmpc_omp_task_alloc,
100 // Call to kmp_int32 __kmpc_omp_task(ident_t *, kmp_int32 gtid, kmp_task_t *
101 // new_task);
102 OMPRTL__kmpc_omp_task,
Alexey Bataev8f7c1b02014-12-05 04:09:23 +0000103 };
104
Alexey Bataev9959db52014-05-06 10:08:46 +0000105 /// \brief Values for bit flags used in the ident_t to describe the fields.
106 /// All enumeric elements are named and described in accordance with the code
107 /// from http://llvm.org/svn/llvm-project/openmp/trunk/runtime/src/kmp.h
108 enum OpenMPLocationFlags {
109 /// \brief Use trampoline for internal microtask.
110 OMP_IDENT_IMD = 0x01,
111 /// \brief Use c-style ident structure.
112 OMP_IDENT_KMPC = 0x02,
113 /// \brief Atomic reduction option for kmpc_reduce.
114 OMP_ATOMIC_REDUCE = 0x10,
115 /// \brief Explicit 'barrier' directive.
116 OMP_IDENT_BARRIER_EXPL = 0x20,
117 /// \brief Implicit barrier in code.
118 OMP_IDENT_BARRIER_IMPL = 0x40,
119 /// \brief Implicit barrier in 'for' directive.
120 OMP_IDENT_BARRIER_IMPL_FOR = 0x40,
121 /// \brief Implicit barrier in 'sections' directive.
122 OMP_IDENT_BARRIER_IMPL_SECTIONS = 0xC0,
123 /// \brief Implicit barrier in 'single' directive.
124 OMP_IDENT_BARRIER_IMPL_SINGLE = 0x140
125 };
Alexey Bataev9959db52014-05-06 10:08:46 +0000126 CodeGenModule &CGM;
127 /// \brief Default const ident_t object used for initialization of all other
128 /// ident_t objects.
129 llvm::Constant *DefaultOpenMPPSource;
Alexey Bataev18095712014-10-10 12:19:54 +0000130 /// \brief Map of flags and corresponding default locations.
Alexey Bataev15007ba2014-05-07 06:18:01 +0000131 typedef llvm::DenseMap<unsigned, llvm::Value *> OpenMPDefaultLocMapTy;
132 OpenMPDefaultLocMapTy OpenMPDefaultLocMap;
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000133 llvm::Value *getOrCreateDefaultLocation(OpenMPLocationFlags Flags);
Alexey Bataev9959db52014-05-06 10:08:46 +0000134 /// \brief Describes ident structure that describes a source location.
135 /// All descriptions are taken from
136 /// http://llvm.org/svn/llvm-project/openmp/trunk/runtime/src/kmp.h
137 /// Original structure:
138 /// typedef struct ident {
139 /// kmp_int32 reserved_1; /**< might be used in Fortran;
140 /// see above */
141 /// kmp_int32 flags; /**< also f.flags; KMP_IDENT_xxx flags;
142 /// KMP_IDENT_KMPC identifies this union
143 /// member */
144 /// kmp_int32 reserved_2; /**< not really used in Fortran any more;
145 /// see above */
146 ///#if USE_ITT_BUILD
147 /// /* but currently used for storing
148 /// region-specific ITT */
149 /// /* contextual information. */
150 ///#endif /* USE_ITT_BUILD */
151 /// kmp_int32 reserved_3; /**< source[4] in Fortran, do not use for
152 /// C++ */
153 /// char const *psource; /**< String describing the source location.
154 /// The string is composed of semi-colon separated
155 // fields which describe the source file,
156 /// the function and a pair of line numbers that
157 /// delimit the construct.
158 /// */
159 /// } ident_t;
160 enum IdentFieldIndex {
161 /// \brief might be used in Fortran
162 IdentField_Reserved_1,
163 /// \brief OMP_IDENT_xxx flags; OMP_IDENT_KMPC identifies this union member.
164 IdentField_Flags,
165 /// \brief Not really used in Fortran any more
166 IdentField_Reserved_2,
167 /// \brief Source[4] in Fortran, do not use for C++
168 IdentField_Reserved_3,
169 /// \brief String describing the source location. The string is composed of
170 /// semi-colon separated fields which describe the source file, the function
171 /// and a pair of line numbers that delimit the construct.
172 IdentField_PSource
173 };
174 llvm::StructType *IdentTy;
Alexey Bataev18095712014-10-10 12:19:54 +0000175 /// \brief Map for SourceLocation and OpenMP runtime library debug locations.
Alexey Bataevf002aca2014-05-30 05:48:40 +0000176 typedef llvm::DenseMap<unsigned, llvm::Value *> OpenMPDebugLocMapTy;
177 OpenMPDebugLocMapTy OpenMPDebugLocMap;
Alexey Bataev9959db52014-05-06 10:08:46 +0000178 /// \brief The type for a microtask which gets passed to __kmpc_fork_call().
179 /// Original representation is:
180 /// typedef void (kmpc_micro)(kmp_int32 global_tid, kmp_int32 bound_tid,...);
181 llvm::FunctionType *Kmpc_MicroTy;
Alexey Bataev18095712014-10-10 12:19:54 +0000182 /// \brief Stores debug location and ThreadID for the function.
183 struct DebugLocThreadIdTy {
184 llvm::Value *DebugLoc;
185 llvm::Value *ThreadID;
186 };
187 /// \brief Map of local debug location, ThreadId and functions.
188 typedef llvm::DenseMap<llvm::Function *, DebugLocThreadIdTy>
189 OpenMPLocThreadIDMapTy;
190 OpenMPLocThreadIDMapTy OpenMPLocThreadIDMap;
Alexey Bataev3a3bf0b2014-09-22 10:01:53 +0000191 /// \brief Type kmp_critical_name, originally defined as typedef kmp_int32
192 /// kmp_critical_name[8];
193 llvm::ArrayType *KmpCriticalNameTy;
Alexey Bataev97720002014-11-11 04:05:39 +0000194 /// \brief An ordered map of auto-generated variables to their unique names.
195 /// It stores variables with the following names: 1) ".gomp_critical_user_" +
196 /// <critical_section_name> + ".var" for "omp critical" directives; 2)
197 /// <mangled_name_for_global_var> + ".cache." for cache for threadprivate
198 /// variables.
199 llvm::StringMap<llvm::AssertingVH<llvm::Constant>, llvm::BumpPtrAllocator>
200 InternalVars;
Alexey Bataev62b63b12015-03-10 07:28:44 +0000201 /// \brief Type typedef kmp_int32 (* kmp_routine_entry_t)(kmp_int32, void *);
202 llvm::Type *KmpRoutineEntryPtrTy;
203 QualType KmpRoutineEntryPtrQTy;
204
205 /// \brief Build type kmp_routine_entry_t (if not built yet).
206 void emitKmpRoutineEntryT(QualType KmpInt32Ty);
Alexey Bataev9959db52014-05-06 10:08:46 +0000207
Alexey Bataev9959db52014-05-06 10:08:46 +0000208 /// \brief Emits object of ident_t type with info for source location.
Alexey Bataev9959db52014-05-06 10:08:46 +0000209 /// \param Flags Flags for OpenMP location.
210 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000211 llvm::Value *emitUpdateLocation(CodeGenFunction &CGF, SourceLocation Loc,
212 OpenMPLocationFlags Flags = OMP_IDENT_KMPC);
Alexey Bataev9959db52014-05-06 10:08:46 +0000213
Alexey Bataevd74d0602014-10-13 06:02:40 +0000214 /// \brief Returns pointer to ident_t type.
Alexey Bataev9959db52014-05-06 10:08:46 +0000215 llvm::Type *getIdentTyPointerTy();
216
Alexey Bataevd74d0602014-10-13 06:02:40 +0000217 /// \brief Returns pointer to kmpc_micro type.
Alexey Bataev9959db52014-05-06 10:08:46 +0000218 llvm::Type *getKmpc_MicroPointerTy();
219
220 /// \brief Returns specified OpenMP runtime function.
221 /// \param Function OpenMP runtime function.
222 /// \return Specified function.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000223 llvm::Constant *createRuntimeFunction(OpenMPRTLFunction Function);
Alexey Bataev3a3bf0b2014-09-22 10:01:53 +0000224
Alexey Bataev97720002014-11-11 04:05:39 +0000225 /// \brief If the specified mangled name is not in the module, create and
226 /// return threadprivate cache object. This object is a pointer's worth of
227 /// storage that's reserved for use by the OpenMP runtime.
NAKAMURA Takumicdcbfba2014-11-11 07:58:06 +0000228 /// \param VD Threadprivate variable.
Alexey Bataev97720002014-11-11 04:05:39 +0000229 /// \return Cache variable for the specified threadprivate.
230 llvm::Constant *getOrCreateThreadPrivateCache(const VarDecl *VD);
231
Alexey Bataevd74d0602014-10-13 06:02:40 +0000232 /// \brief Emits address of the word in a memory where current thread id is
233 /// stored.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000234 virtual llvm::Value *emitThreadIDAddress(CodeGenFunction &CGF,
Alexey Bataevd74d0602014-10-13 06:02:40 +0000235 SourceLocation Loc);
236
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000237 /// \brief Gets thread id value for the current thread.
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000238 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000239 llvm::Value *getThreadID(CodeGenFunction &CGF, SourceLocation Loc);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000240
Alexey Bataev97720002014-11-11 04:05:39 +0000241 /// \brief Gets (if variable with the given name already exist) or creates
242 /// internal global variable with the specified Name. The created variable has
243 /// linkage CommonLinkage by default and is initialized by null value.
244 /// \param Ty Type of the global variable. If it is exist already the type
245 /// must be the same.
246 /// \param Name Name of the variable.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000247 llvm::Constant *getOrCreateInternalVariable(llvm::Type *Ty,
Alexey Bataev97720002014-11-11 04:05:39 +0000248 const llvm::Twine &Name);
249
250 /// \brief Set of threadprivate variables with the generated initializer.
251 llvm::DenseSet<const VarDecl *> ThreadPrivateWithDefinition;
252
253 /// \brief Emits initialization code for the threadprivate variables.
254 /// \param VDAddr Address of the global variable \a VD.
255 /// \param Ctor Pointer to a global init function for \a VD.
256 /// \param CopyCtor Pointer to a global copy function for \a VD.
257 /// \param Dtor Pointer to a global destructor function for \a VD.
258 /// \param Loc Location of threadprivate declaration.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000259 void emitThreadPrivateVarInit(CodeGenFunction &CGF, llvm::Value *VDAddr,
260 llvm::Value *Ctor, llvm::Value *CopyCtor,
261 llvm::Value *Dtor, SourceLocation Loc);
Alexey Bataev97720002014-11-11 04:05:39 +0000262
Alexey Bataev75ddfab2014-12-01 11:32:38 +0000263 /// \brief Returns corresponding lock object for the specified critical region
264 /// name. If the lock object does not exist it is created, otherwise the
265 /// reference to the existing copy is returned.
266 /// \param CriticalName Name of the critical region.
267 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000268 llvm::Value *getCriticalRegionLock(StringRef CriticalName);
Alexey Bataev75ddfab2014-12-01 11:32:38 +0000269
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000270public:
271 explicit CGOpenMPRuntime(CodeGenModule &CGM);
272 virtual ~CGOpenMPRuntime() {}
273
Alexey Bataev62b63b12015-03-10 07:28:44 +0000274 /// \brief Emits outlined function for the specified OpenMP directive \a D.
275 /// This outlined function has type void(*)(kmp_int32 *ThreadID, kmp_int32
276 /// BoundID, struct context_vars*).
Alexey Bataev18095712014-10-10 12:19:54 +0000277 /// \param D OpenMP directive.
278 /// \param ThreadIDVar Variable for thread id in the current OpenMP region.
279 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000280 virtual llvm::Value *emitOutlinedFunction(const OMPExecutableDirective &D,
281 const VarDecl *ThreadIDVar);
Alexey Bataev18095712014-10-10 12:19:54 +0000282
Alexey Bataev62b63b12015-03-10 07:28:44 +0000283 /// \brief Emits outlined function for the OpenMP task directive \a D. This
284 /// outlined function has type void(*)(kmp_int32 ThreadID, kmp_int32
285 /// PartID, struct context_vars*).
286 /// \param D OpenMP directive.
287 /// \param ThreadIDVar Variable for thread id in the current OpenMP region.
288 /// \param PartID If not nullptr - variable used for part id in tasks.
289 ///
290 virtual llvm::Value *emitTaskOutlinedFunction(const OMPExecutableDirective &D,
291 const VarDecl *ThreadIDVar,
292 const VarDecl *PartIDVar);
293
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000294 /// \brief Cleans up references to the objects in finished function.
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000295 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000296 void functionFinished(CodeGenFunction &CGF);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000297
298 /// \brief Emits code for parallel call of the \a OutlinedFn with variables
299 /// captured in a record which address is stored in \a CapturedStruct.
Alexey Bataev18095712014-10-10 12:19:54 +0000300 /// \param OutlinedFn Outlined function to be run in parallel threads. Type of
Alexey Bataev62b63b12015-03-10 07:28:44 +0000301 /// this function is void(*)(kmp_int32 *, kmp_int32, struct context_vars*).
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000302 /// \param CapturedStruct A pointer to the record with the references to
303 /// variables used in \a OutlinedFn function.
304 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000305 virtual void emitParallelCall(CodeGenFunction &CGF, SourceLocation Loc,
306 llvm::Value *OutlinedFn,
307 llvm::Value *CapturedStruct);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000308
Alexey Bataevd74d0602014-10-13 06:02:40 +0000309 /// \brief Emits code for serial call of the \a OutlinedFn with variables
310 /// captured in a record which address is stored in \a CapturedStruct.
311 /// \param OutlinedFn Outlined function to be run in serial mode.
312 /// \param CapturedStruct A pointer to the record with the references to
313 /// variables used in \a OutlinedFn function.
314 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000315 virtual void emitSerialCall(CodeGenFunction &CGF, SourceLocation Loc,
316 llvm::Value *OutlinedFn,
317 llvm::Value *CapturedStruct);
Alexey Bataevd74d0602014-10-13 06:02:40 +0000318
Alexey Bataev75ddfab2014-12-01 11:32:38 +0000319 /// \brief Emits a critical region.
Alexey Bataev18095712014-10-10 12:19:54 +0000320 /// \param CriticalName Name of the critical region.
Alexey Bataev75ddfab2014-12-01 11:32:38 +0000321 /// \param CriticalOpGen Generator for the statement associated with the given
322 /// critical region.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000323 virtual void emitCriticalRegion(CodeGenFunction &CGF, StringRef CriticalName,
324 const std::function<void()> &CriticalOpGen,
325 SourceLocation Loc);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000326
Alexey Bataev8d690652014-12-04 07:23:53 +0000327 /// \brief Emits a master region.
328 /// \param MasterOpGen Generator for the statement associated with the given
329 /// master region.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000330 virtual void emitMasterRegion(CodeGenFunction &CGF,
331 const std::function<void()> &MasterOpGen,
332 SourceLocation Loc);
Alexey Bataev8d690652014-12-04 07:23:53 +0000333
Alexey Bataev9f797f32015-02-05 05:57:51 +0000334 /// \brief Emits code for a taskyield directive.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000335 virtual void emitTaskyieldCall(CodeGenFunction &CGF, SourceLocation Loc);
Alexey Bataev9f797f32015-02-05 05:57:51 +0000336
Alexey Bataev6956e2e2015-02-05 06:35:41 +0000337 /// \brief Emits a single region.
338 /// \param SingleOpGen Generator for the statement associated with the given
339 /// single region.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000340 virtual void emitSingleRegion(CodeGenFunction &CGF,
341 const std::function<void()> &SingleOpGen,
342 SourceLocation Loc);
Alexey Bataev6956e2e2015-02-05 06:35:41 +0000343
Alexey Bataev8f7c1b02014-12-05 04:09:23 +0000344 /// \brief Emits explicit barrier for OpenMP threads.
345 /// \param IsExplicit true, if it is explicitly specified barrier.
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000346 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000347 virtual void emitBarrierCall(CodeGenFunction &CGF, SourceLocation Loc,
348 bool IsExplicit = true);
Alexey Bataevb2059782014-10-13 08:23:51 +0000349
Alexander Musmanc6388682014-12-15 07:07:06 +0000350 /// \brief Check if the specified \a ScheduleKind is static non-chunked.
351 /// This kind of worksharing directive is emitted without outer loop.
352 /// \param ScheduleKind Schedule kind specified in the 'schedule' clause.
353 /// \param Chunked True if chunk is specified in the clause.
354 ///
355 virtual bool isStaticNonchunked(OpenMPScheduleClauseKind ScheduleKind,
356 bool Chunked) const;
357
Alexander Musmandf7a8e22015-01-22 08:49:35 +0000358 /// \brief Check if the specified \a ScheduleKind is dynamic.
359 /// This kind of worksharing directive is emitted without outer loop.
360 /// \param ScheduleKind Schedule Kind specified in the 'schedule' clause.
361 ///
362 virtual bool isDynamic(OpenMPScheduleClauseKind ScheduleKind) const;
363
Alexander Musmanc6388682014-12-15 07:07:06 +0000364 /// \brief Call the appropriate runtime routine to initialize it before start
365 /// of loop.
366 ///
367 /// Depending on the loop schedule, it is nesessary to call some runtime
368 /// routine before start of the OpenMP loop to get the loop upper / lower
369 /// bounds \a LB and \a UB and stride \a ST.
370 ///
371 /// \param CGF Reference to current CodeGenFunction.
372 /// \param Loc Clang source location.
NAKAMURA Takumieca08382014-12-17 14:47:06 +0000373 /// \param SchedKind Schedule kind, specified by the 'schedule' clause.
Alexander Musmanc6388682014-12-15 07:07:06 +0000374 /// \param IVSize Size of the iteration variable in bits.
375 /// \param IVSigned Sign of the interation variable.
376 /// \param IL Address of the output variable in which the flag of the
377 /// last iteration is returned.
378 /// \param LB Address of the output variable in which the lower iteration
379 /// number is returned.
380 /// \param UB Address of the output variable in which the upper iteration
381 /// number is returned.
382 /// \param ST Address of the output variable in which the stride value is
383 /// returned nesessary to generated the static_chunked scheduled loop.
384 /// \param Chunk Value of the chunk for the static_chunked scheduled loop.
385 /// For the default (nullptr) value, the chunk 1 will be used.
386 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000387 virtual void emitForInit(CodeGenFunction &CGF, SourceLocation Loc,
388 OpenMPScheduleClauseKind SchedKind, unsigned IVSize,
389 bool IVSigned, llvm::Value *IL, llvm::Value *LB,
390 llvm::Value *UB, llvm::Value *ST,
391 llvm::Value *Chunk = nullptr);
Alexander Musmanc6388682014-12-15 07:07:06 +0000392
393 /// \brief Call the appropriate runtime routine to notify that we finished
394 /// all the work with current loop.
395 ///
396 /// \param CGF Reference to current CodeGenFunction.
397 /// \param Loc Clang source location.
398 /// \param ScheduleKind Schedule kind, specified by the 'schedule' clause.
399 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000400 virtual void emitForFinish(CodeGenFunction &CGF, SourceLocation Loc,
401 OpenMPScheduleClauseKind ScheduleKind);
Alexander Musmanc6388682014-12-15 07:07:06 +0000402
Alexey Bataevb2059782014-10-13 08:23:51 +0000403 /// \brief Emits call to void __kmpc_push_num_threads(ident_t *loc, kmp_int32
404 /// global_tid, kmp_int32 num_threads) to generate code for 'num_threads'
405 /// clause.
406 /// \param NumThreads An integer value of threads.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000407 virtual void emitNumThreadsClause(CodeGenFunction &CGF,
408 llvm::Value *NumThreads,
409 SourceLocation Loc);
Alexey Bataev97720002014-11-11 04:05:39 +0000410
411 /// \brief Returns address of the threadprivate variable for the current
412 /// thread.
NAKAMURA Takumicdcbfba2014-11-11 07:58:06 +0000413 /// \param VD Threadprivate variable.
Alexey Bataev97720002014-11-11 04:05:39 +0000414 /// \param VDAddr Address of the global variable \a VD.
415 /// \param Loc Location of the reference to threadprivate var.
416 /// \return Address of the threadprivate variable for the current thread.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000417 virtual llvm::Value *getAddrOfThreadPrivate(CodeGenFunction &CGF,
418 const VarDecl *VD,
419 llvm::Value *VDAddr,
420 SourceLocation Loc);
Alexey Bataev97720002014-11-11 04:05:39 +0000421
422 /// \brief Emit a code for initialization of threadprivate variable. It emits
423 /// a call to runtime library which adds initial value to the newly created
424 /// threadprivate variable (if it is not constant) and registers destructor
425 /// for the variable (if any).
426 /// \param VD Threadprivate variable.
427 /// \param VDAddr Address of the global variable \a VD.
428 /// \param Loc Location of threadprivate declaration.
429 /// \param PerformInit true if initialization expression is not constant.
430 virtual llvm::Function *
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000431 emitThreadPrivateVarDefinition(const VarDecl *VD, llvm::Value *VDAddr,
432 SourceLocation Loc, bool PerformInit,
433 CodeGenFunction *CGF = nullptr);
Alexey Bataevcc37cc12014-11-20 04:34:54 +0000434
435 /// \brief Emit flush of the variables specified in 'omp flush' directive.
436 /// \param Vars List of variables to flush.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000437 virtual void emitFlush(CodeGenFunction &CGF, ArrayRef<const Expr *> Vars,
438 SourceLocation Loc);
Alexey Bataev62b63b12015-03-10 07:28:44 +0000439
440 /// \brief Emit task region for the task directive. The task region is
441 /// emmitted in several steps:
442 /// 1. Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32
443 /// gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds,
444 /// kmp_routine_entry_t *task_entry). Here task_entry is a pointer to the
445 /// function:
446 /// kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) {
447 /// TaskFunction(gtid, tt->part_id, tt->shareds);
448 /// return 0;
449 /// }
450 /// 2. Copy a list of shared variables to field shareds of the resulting
451 /// structure kmp_task_t returned by the previous call (if any).
452 /// 3. Copy a pointer to destructions function to field destructions of the
453 /// resulting structure kmp_task_t.
454 /// 4. Emit a call to kmp_int32 __kmpc_omp_task(ident_t *, kmp_int32 gtid,
455 /// kmp_task_t *new_task), where new_task is a resulting structure from
456 /// previous items.
457 /// \param Tied true if the task is tied (the task is tied to the thread that
458 /// can suspend its task region), false - untied (the task is not tied to any
459 /// thread).
460 /// \param Final Contains either constant bool value, or llvm::Value * of i1
461 /// type for final clause. If the value is true, the task forces all of its
462 /// child tasks to become final and included tasks.
463 /// \param TaskFunction An LLVM function with type void (*)(i32 /*gtid*/, i32
464 /// /*part_id*/, captured_struct */*__context*/);
465 /// \param SharedsTy A type which contains references the shared variables.
466 /// \param Shareds Context with the list of shared variables from the \a
467 /// TaskFunction.
468 virtual void emitTaskCall(CodeGenFunction &CGF, SourceLocation Loc, bool Tied,
469 llvm::PointerIntPair<llvm::Value *, 1, bool> Final,
470 llvm::Value *TaskFunction, QualType SharedsTy,
471 llvm::Value *Shareds);
Alexey Bataev9959db52014-05-06 10:08:46 +0000472};
Alexey Bataev8cbe0a62015-02-26 10:27:34 +0000473
474/// \brief RAII for emitting code of CapturedStmt without function outlining.
475class InlinedOpenMPRegionRAII {
476 CodeGenFunction &CGF;
477
478public:
479 InlinedOpenMPRegionRAII(CodeGenFunction &CGF,
480 const OMPExecutableDirective &D);
481 ~InlinedOpenMPRegionRAII();
482};
Alexey Bataev23b69422014-06-18 07:08:49 +0000483} // namespace CodeGen
484} // namespace clang
Alexey Bataev9959db52014-05-06 10:08:46 +0000485
486#endif