blob: 1b91d02e3b17f360f1877ad53c44b62c5c6d37f6 [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
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,
Alexander Musman21212e42015-03-13 10:38:23 +000071 // Call to void __kmpc_for_static_fini(ident_t *loc, kmp_int32 global_tid);
Alexander Musmanc6388682014-12-15 07:07:06 +000072 OMPRTL__kmpc_for_static_fini,
Alexey Bataev8f7c1b02014-12-05 04:09:23 +000073 // Call to void __kmpc_serialized_parallel(ident_t *loc, kmp_int32
74 // global_tid);
75 OMPRTL__kmpc_serialized_parallel,
76 // Call to void __kmpc_end_serialized_parallel(ident_t *loc, kmp_int32
77 // global_tid);
78 OMPRTL__kmpc_end_serialized_parallel,
79 // Call to void __kmpc_push_num_threads(ident_t *loc, kmp_int32 global_tid,
80 // kmp_int32 num_threads);
81 OMPRTL__kmpc_push_num_threads,
Alexey Bataevd76df6d2015-02-24 12:55:09 +000082 // Call to void __kmpc_flush(ident_t *loc);
Alexey Bataev8f7c1b02014-12-05 04:09:23 +000083 OMPRTL__kmpc_flush,
84 // Call to kmp_int32 __kmpc_master(ident_t *, kmp_int32 global_tid);
85 OMPRTL__kmpc_master,
86 // Call to void __kmpc_end_master(ident_t *, kmp_int32 global_tid);
87 OMPRTL__kmpc_end_master,
Alexey Bataev9f797f32015-02-05 05:57:51 +000088 // Call to kmp_int32 __kmpc_omp_taskyield(ident_t *, kmp_int32 global_tid,
89 // int end_part);
90 OMPRTL__kmpc_omp_taskyield,
Alexey Bataev6956e2e2015-02-05 06:35:41 +000091 // Call to kmp_int32 __kmpc_single(ident_t *, kmp_int32 global_tid);
92 OMPRTL__kmpc_single,
93 // Call to void __kmpc_end_single(ident_t *, kmp_int32 global_tid);
94 OMPRTL__kmpc_end_single,
Alexey Bataev62b63b12015-03-10 07:28:44 +000095 // Call to kmp_task_t * __kmpc_omp_task_alloc(ident_t *, kmp_int32 gtid,
96 // kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds,
97 // kmp_routine_entry_t *task_entry);
98 OMPRTL__kmpc_omp_task_alloc,
99 // Call to kmp_int32 __kmpc_omp_task(ident_t *, kmp_int32 gtid, kmp_task_t *
100 // new_task);
101 OMPRTL__kmpc_omp_task,
Alexey Bataeva63048e2015-03-23 06:18:07 +0000102 // Call to void __kmpc_copyprivate(ident_t *loc, kmp_int32 global_tid,
103 // kmp_int32 cpy_size, void *cpy_data, void(*cpy_func)(void *, void *),
104 // kmp_int32 didit);
105 OMPRTL__kmpc_copyprivate,
Alexey Bataev8f7c1b02014-12-05 04:09:23 +0000106 };
107
Alexey Bataev9959db52014-05-06 10:08:46 +0000108 /// \brief Values for bit flags used in the ident_t to describe the fields.
109 /// All enumeric elements are named and described in accordance with the code
110 /// from http://llvm.org/svn/llvm-project/openmp/trunk/runtime/src/kmp.h
111 enum OpenMPLocationFlags {
112 /// \brief Use trampoline for internal microtask.
113 OMP_IDENT_IMD = 0x01,
114 /// \brief Use c-style ident structure.
115 OMP_IDENT_KMPC = 0x02,
116 /// \brief Atomic reduction option for kmpc_reduce.
117 OMP_ATOMIC_REDUCE = 0x10,
118 /// \brief Explicit 'barrier' directive.
119 OMP_IDENT_BARRIER_EXPL = 0x20,
120 /// \brief Implicit barrier in code.
121 OMP_IDENT_BARRIER_IMPL = 0x40,
122 /// \brief Implicit barrier in 'for' directive.
123 OMP_IDENT_BARRIER_IMPL_FOR = 0x40,
124 /// \brief Implicit barrier in 'sections' directive.
125 OMP_IDENT_BARRIER_IMPL_SECTIONS = 0xC0,
126 /// \brief Implicit barrier in 'single' directive.
127 OMP_IDENT_BARRIER_IMPL_SINGLE = 0x140
128 };
Alexey Bataev9959db52014-05-06 10:08:46 +0000129 CodeGenModule &CGM;
130 /// \brief Default const ident_t object used for initialization of all other
131 /// ident_t objects.
132 llvm::Constant *DefaultOpenMPPSource;
Alexey Bataev18095712014-10-10 12:19:54 +0000133 /// \brief Map of flags and corresponding default locations.
Alexey Bataev15007ba2014-05-07 06:18:01 +0000134 typedef llvm::DenseMap<unsigned, llvm::Value *> OpenMPDefaultLocMapTy;
135 OpenMPDefaultLocMapTy OpenMPDefaultLocMap;
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000136 llvm::Value *getOrCreateDefaultLocation(OpenMPLocationFlags Flags);
Alexey Bataev9959db52014-05-06 10:08:46 +0000137 /// \brief Describes ident structure that describes a source location.
138 /// All descriptions are taken from
139 /// http://llvm.org/svn/llvm-project/openmp/trunk/runtime/src/kmp.h
140 /// Original structure:
141 /// typedef struct ident {
142 /// kmp_int32 reserved_1; /**< might be used in Fortran;
143 /// see above */
144 /// kmp_int32 flags; /**< also f.flags; KMP_IDENT_xxx flags;
145 /// KMP_IDENT_KMPC identifies this union
146 /// member */
147 /// kmp_int32 reserved_2; /**< not really used in Fortran any more;
148 /// see above */
149 ///#if USE_ITT_BUILD
150 /// /* but currently used for storing
151 /// region-specific ITT */
152 /// /* contextual information. */
153 ///#endif /* USE_ITT_BUILD */
154 /// kmp_int32 reserved_3; /**< source[4] in Fortran, do not use for
155 /// C++ */
156 /// char const *psource; /**< String describing the source location.
157 /// The string is composed of semi-colon separated
158 // fields which describe the source file,
159 /// the function and a pair of line numbers that
160 /// delimit the construct.
161 /// */
162 /// } ident_t;
163 enum IdentFieldIndex {
164 /// \brief might be used in Fortran
165 IdentField_Reserved_1,
166 /// \brief OMP_IDENT_xxx flags; OMP_IDENT_KMPC identifies this union member.
167 IdentField_Flags,
168 /// \brief Not really used in Fortran any more
169 IdentField_Reserved_2,
170 /// \brief Source[4] in Fortran, do not use for C++
171 IdentField_Reserved_3,
172 /// \brief String describing the source location. The string is composed of
173 /// semi-colon separated fields which describe the source file, the function
174 /// and a pair of line numbers that delimit the construct.
175 IdentField_PSource
176 };
177 llvm::StructType *IdentTy;
Alexey Bataev18095712014-10-10 12:19:54 +0000178 /// \brief Map for SourceLocation and OpenMP runtime library debug locations.
Alexey Bataevf002aca2014-05-30 05:48:40 +0000179 typedef llvm::DenseMap<unsigned, llvm::Value *> OpenMPDebugLocMapTy;
180 OpenMPDebugLocMapTy OpenMPDebugLocMap;
Alexey Bataev9959db52014-05-06 10:08:46 +0000181 /// \brief The type for a microtask which gets passed to __kmpc_fork_call().
182 /// Original representation is:
183 /// typedef void (kmpc_micro)(kmp_int32 global_tid, kmp_int32 bound_tid,...);
184 llvm::FunctionType *Kmpc_MicroTy;
Alexey Bataev18095712014-10-10 12:19:54 +0000185 /// \brief Stores debug location and ThreadID for the function.
186 struct DebugLocThreadIdTy {
187 llvm::Value *DebugLoc;
188 llvm::Value *ThreadID;
189 };
190 /// \brief Map of local debug location, ThreadId and functions.
191 typedef llvm::DenseMap<llvm::Function *, DebugLocThreadIdTy>
192 OpenMPLocThreadIDMapTy;
193 OpenMPLocThreadIDMapTy OpenMPLocThreadIDMap;
Alexey Bataev3a3bf0b2014-09-22 10:01:53 +0000194 /// \brief Type kmp_critical_name, originally defined as typedef kmp_int32
195 /// kmp_critical_name[8];
196 llvm::ArrayType *KmpCriticalNameTy;
Alexey Bataev97720002014-11-11 04:05:39 +0000197 /// \brief An ordered map of auto-generated variables to their unique names.
198 /// It stores variables with the following names: 1) ".gomp_critical_user_" +
199 /// <critical_section_name> + ".var" for "omp critical" directives; 2)
200 /// <mangled_name_for_global_var> + ".cache." for cache for threadprivate
201 /// variables.
202 llvm::StringMap<llvm::AssertingVH<llvm::Constant>, llvm::BumpPtrAllocator>
203 InternalVars;
Alexey Bataev62b63b12015-03-10 07:28:44 +0000204 /// \brief Type typedef kmp_int32 (* kmp_routine_entry_t)(kmp_int32, void *);
205 llvm::Type *KmpRoutineEntryPtrTy;
206 QualType KmpRoutineEntryPtrQTy;
207
208 /// \brief Build type kmp_routine_entry_t (if not built yet).
209 void emitKmpRoutineEntryT(QualType KmpInt32Ty);
Alexey Bataev9959db52014-05-06 10:08:46 +0000210
Alexey Bataev9959db52014-05-06 10:08:46 +0000211 /// \brief Emits object of ident_t type with info for source location.
Alexey Bataev9959db52014-05-06 10:08:46 +0000212 /// \param Flags Flags for OpenMP location.
213 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000214 llvm::Value *emitUpdateLocation(CodeGenFunction &CGF, SourceLocation Loc,
215 OpenMPLocationFlags Flags = OMP_IDENT_KMPC);
Alexey Bataev9959db52014-05-06 10:08:46 +0000216
Alexey Bataevd74d0602014-10-13 06:02:40 +0000217 /// \brief Returns pointer to ident_t type.
Alexey Bataev9959db52014-05-06 10:08:46 +0000218 llvm::Type *getIdentTyPointerTy();
219
Alexey Bataevd74d0602014-10-13 06:02:40 +0000220 /// \brief Returns pointer to kmpc_micro type.
Alexey Bataev9959db52014-05-06 10:08:46 +0000221 llvm::Type *getKmpc_MicroPointerTy();
222
223 /// \brief Returns specified OpenMP runtime function.
224 /// \param Function OpenMP runtime function.
225 /// \return Specified function.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000226 llvm::Constant *createRuntimeFunction(OpenMPRTLFunction Function);
Alexey Bataev3a3bf0b2014-09-22 10:01:53 +0000227
Alexander Musman21212e42015-03-13 10:38:23 +0000228 /// \brief Returns __kmpc_for_static_init_* runtime function for the specified
229 /// size \a IVSize and sign \a IVSigned.
230 llvm::Constant *createForStaticInitFunction(unsigned IVSize, bool IVSigned);
231
Alexander Musman92bdaab2015-03-12 13:37:50 +0000232 /// \brief Returns __kmpc_dispatch_init_* runtime function for the specified
233 /// size \a IVSize and sign \a IVSigned.
234 llvm::Constant *createDispatchInitFunction(unsigned IVSize, bool IVSigned);
235
236 /// \brief Returns __kmpc_dispatch_next_* runtime function for the specified
237 /// size \a IVSize and sign \a IVSigned.
238 llvm::Constant *createDispatchNextFunction(unsigned IVSize, bool IVSigned);
239
Alexey Bataev97720002014-11-11 04:05:39 +0000240 /// \brief If the specified mangled name is not in the module, create and
241 /// return threadprivate cache object. This object is a pointer's worth of
242 /// storage that's reserved for use by the OpenMP runtime.
NAKAMURA Takumicdcbfba2014-11-11 07:58:06 +0000243 /// \param VD Threadprivate variable.
Alexey Bataev97720002014-11-11 04:05:39 +0000244 /// \return Cache variable for the specified threadprivate.
245 llvm::Constant *getOrCreateThreadPrivateCache(const VarDecl *VD);
246
Alexey Bataevd74d0602014-10-13 06:02:40 +0000247 /// \brief Emits address of the word in a memory where current thread id is
248 /// stored.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000249 virtual llvm::Value *emitThreadIDAddress(CodeGenFunction &CGF,
Alexey Bataevd74d0602014-10-13 06:02:40 +0000250 SourceLocation Loc);
251
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000252 /// \brief Gets thread id value for the current thread.
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000253 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000254 llvm::Value *getThreadID(CodeGenFunction &CGF, SourceLocation Loc);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000255
Alexey Bataev97720002014-11-11 04:05:39 +0000256 /// \brief Gets (if variable with the given name already exist) or creates
257 /// internal global variable with the specified Name. The created variable has
258 /// linkage CommonLinkage by default and is initialized by null value.
259 /// \param Ty Type of the global variable. If it is exist already the type
260 /// must be the same.
261 /// \param Name Name of the variable.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000262 llvm::Constant *getOrCreateInternalVariable(llvm::Type *Ty,
Alexey Bataev97720002014-11-11 04:05:39 +0000263 const llvm::Twine &Name);
264
265 /// \brief Set of threadprivate variables with the generated initializer.
266 llvm::DenseSet<const VarDecl *> ThreadPrivateWithDefinition;
267
268 /// \brief Emits initialization code for the threadprivate variables.
269 /// \param VDAddr Address of the global variable \a VD.
270 /// \param Ctor Pointer to a global init function for \a VD.
271 /// \param CopyCtor Pointer to a global copy function for \a VD.
272 /// \param Dtor Pointer to a global destructor function for \a VD.
273 /// \param Loc Location of threadprivate declaration.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000274 void emitThreadPrivateVarInit(CodeGenFunction &CGF, llvm::Value *VDAddr,
275 llvm::Value *Ctor, llvm::Value *CopyCtor,
276 llvm::Value *Dtor, SourceLocation Loc);
Alexey Bataev97720002014-11-11 04:05:39 +0000277
Alexey Bataev75ddfab2014-12-01 11:32:38 +0000278 /// \brief Returns corresponding lock object for the specified critical region
279 /// name. If the lock object does not exist it is created, otherwise the
280 /// reference to the existing copy is returned.
281 /// \param CriticalName Name of the critical region.
282 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000283 llvm::Value *getCriticalRegionLock(StringRef CriticalName);
Alexey Bataev75ddfab2014-12-01 11:32:38 +0000284
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000285public:
286 explicit CGOpenMPRuntime(CodeGenModule &CGM);
287 virtual ~CGOpenMPRuntime() {}
Alexey Bataev91797552015-03-18 04:13:55 +0000288 virtual void clear();
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000289
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000290 /// \brief Emits outlined function for the specified OpenMP parallel directive
291 /// \a D. This outlined function has type void(*)(kmp_int32 *ThreadID,
292 /// kmp_int32 BoundID, struct context_vars*).
Alexey Bataev18095712014-10-10 12:19:54 +0000293 /// \param D OpenMP directive.
294 /// \param ThreadIDVar Variable for thread id in the current OpenMP region.
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000295 /// \param CodeGen Code generation sequence for the \a D directive.
296 virtual llvm::Value *
297 emitParallelOutlinedFunction(const OMPExecutableDirective &D,
298 const VarDecl *ThreadIDVar,
299 const RegionCodeGenTy &CodeGen);
Alexey Bataev18095712014-10-10 12:19:54 +0000300
Alexey Bataev62b63b12015-03-10 07:28:44 +0000301 /// \brief Emits outlined function for the OpenMP task directive \a D. This
302 /// outlined function has type void(*)(kmp_int32 ThreadID, kmp_int32
303 /// PartID, struct context_vars*).
304 /// \param D OpenMP directive.
305 /// \param ThreadIDVar Variable for thread id in the current OpenMP region.
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000306 /// \param CodeGen Code generation sequence for the \a D directive.
Alexey Bataev62b63b12015-03-10 07:28:44 +0000307 ///
308 virtual llvm::Value *emitTaskOutlinedFunction(const OMPExecutableDirective &D,
309 const VarDecl *ThreadIDVar,
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000310 const RegionCodeGenTy &CodeGen);
Alexey Bataev62b63b12015-03-10 07:28:44 +0000311
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000312 /// \brief Cleans up references to the objects in finished function.
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000313 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000314 void functionFinished(CodeGenFunction &CGF);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000315
316 /// \brief Emits code for parallel call of the \a OutlinedFn with variables
317 /// captured in a record which address is stored in \a CapturedStruct.
Alexey Bataev18095712014-10-10 12:19:54 +0000318 /// \param OutlinedFn Outlined function to be run in parallel threads. Type of
Alexey Bataev62b63b12015-03-10 07:28:44 +0000319 /// this function is void(*)(kmp_int32 *, kmp_int32, struct context_vars*).
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000320 /// \param CapturedStruct A pointer to the record with the references to
321 /// variables used in \a OutlinedFn function.
322 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000323 virtual void emitParallelCall(CodeGenFunction &CGF, SourceLocation Loc,
324 llvm::Value *OutlinedFn,
325 llvm::Value *CapturedStruct);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000326
Alexey Bataevd74d0602014-10-13 06:02:40 +0000327 /// \brief Emits code for serial call of the \a OutlinedFn with variables
328 /// captured in a record which address is stored in \a CapturedStruct.
329 /// \param OutlinedFn Outlined function to be run in serial mode.
330 /// \param CapturedStruct A pointer to the record with the references to
331 /// variables used in \a OutlinedFn function.
332 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000333 virtual void emitSerialCall(CodeGenFunction &CGF, SourceLocation Loc,
334 llvm::Value *OutlinedFn,
335 llvm::Value *CapturedStruct);
Alexey Bataevd74d0602014-10-13 06:02:40 +0000336
Alexey Bataev75ddfab2014-12-01 11:32:38 +0000337 /// \brief Emits a critical region.
Alexey Bataev18095712014-10-10 12:19:54 +0000338 /// \param CriticalName Name of the critical region.
Alexey Bataev75ddfab2014-12-01 11:32:38 +0000339 /// \param CriticalOpGen Generator for the statement associated with the given
340 /// critical region.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000341 virtual void emitCriticalRegion(CodeGenFunction &CGF, StringRef CriticalName,
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000342 const RegionCodeGenTy &CriticalOpGen,
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000343 SourceLocation Loc);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000344
Alexey Bataev8d690652014-12-04 07:23:53 +0000345 /// \brief Emits a master region.
346 /// \param MasterOpGen Generator for the statement associated with the given
347 /// master region.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000348 virtual void emitMasterRegion(CodeGenFunction &CGF,
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000349 const RegionCodeGenTy &MasterOpGen,
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000350 SourceLocation Loc);
Alexey Bataev8d690652014-12-04 07:23:53 +0000351
Alexey Bataev9f797f32015-02-05 05:57:51 +0000352 /// \brief Emits code for a taskyield directive.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000353 virtual void emitTaskyieldCall(CodeGenFunction &CGF, SourceLocation Loc);
Alexey Bataev9f797f32015-02-05 05:57:51 +0000354
Alexey Bataev6956e2e2015-02-05 06:35:41 +0000355 /// \brief Emits a single region.
356 /// \param SingleOpGen Generator for the statement associated with the given
357 /// single region.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000358 virtual void emitSingleRegion(CodeGenFunction &CGF,
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000359 const RegionCodeGenTy &SingleOpGen,
Alexey Bataeva63048e2015-03-23 06:18:07 +0000360 SourceLocation Loc,
361 ArrayRef<const Expr *> CopyprivateVars,
362 ArrayRef<const Expr *> SrcExprs,
363 ArrayRef<const Expr *> DstExprs,
364 ArrayRef<const Expr *> AssignmentOps);
Alexey Bataev6956e2e2015-02-05 06:35:41 +0000365
Alexey Bataevf2685682015-03-30 04:30:22 +0000366 /// \brief Emit an implicit/explicit barrier for OpenMP threads.
367 /// \param Kind Directive for which this implicit barrier call must be
368 /// generated. Must be OMPD_barrier for explicit barrier generation.
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000369 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000370 virtual void emitBarrierCall(CodeGenFunction &CGF, SourceLocation Loc,
Alexey Bataevf2685682015-03-30 04:30:22 +0000371 OpenMPDirectiveKind Kind);
Alexey Bataevb2059782014-10-13 08:23:51 +0000372
Alexander Musmanc6388682014-12-15 07:07:06 +0000373 /// \brief Check if the specified \a ScheduleKind is static non-chunked.
374 /// This kind of worksharing directive is emitted without outer loop.
375 /// \param ScheduleKind Schedule kind specified in the 'schedule' clause.
376 /// \param Chunked True if chunk is specified in the clause.
377 ///
378 virtual bool isStaticNonchunked(OpenMPScheduleClauseKind ScheduleKind,
379 bool Chunked) const;
380
Alexander Musmandf7a8e22015-01-22 08:49:35 +0000381 /// \brief Check if the specified \a ScheduleKind is dynamic.
382 /// This kind of worksharing directive is emitted without outer loop.
383 /// \param ScheduleKind Schedule Kind specified in the 'schedule' clause.
384 ///
385 virtual bool isDynamic(OpenMPScheduleClauseKind ScheduleKind) const;
386
Alexander Musmanc6388682014-12-15 07:07:06 +0000387 /// \brief Call the appropriate runtime routine to initialize it before start
388 /// of loop.
389 ///
390 /// Depending on the loop schedule, it is nesessary to call some runtime
391 /// routine before start of the OpenMP loop to get the loop upper / lower
392 /// bounds \a LB and \a UB and stride \a ST.
393 ///
394 /// \param CGF Reference to current CodeGenFunction.
395 /// \param Loc Clang source location.
NAKAMURA Takumieca08382014-12-17 14:47:06 +0000396 /// \param SchedKind Schedule kind, specified by the 'schedule' clause.
Alexander Musmanc6388682014-12-15 07:07:06 +0000397 /// \param IVSize Size of the iteration variable in bits.
398 /// \param IVSigned Sign of the interation variable.
399 /// \param IL Address of the output variable in which the flag of the
400 /// last iteration is returned.
401 /// \param LB Address of the output variable in which the lower iteration
402 /// number is returned.
403 /// \param UB Address of the output variable in which the upper iteration
404 /// number is returned.
405 /// \param ST Address of the output variable in which the stride value is
406 /// returned nesessary to generated the static_chunked scheduled loop.
407 /// \param Chunk Value of the chunk for the static_chunked scheduled loop.
408 /// For the default (nullptr) value, the chunk 1 will be used.
409 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000410 virtual void emitForInit(CodeGenFunction &CGF, SourceLocation Loc,
411 OpenMPScheduleClauseKind SchedKind, unsigned IVSize,
412 bool IVSigned, llvm::Value *IL, llvm::Value *LB,
413 llvm::Value *UB, llvm::Value *ST,
414 llvm::Value *Chunk = nullptr);
Alexander Musmanc6388682014-12-15 07:07:06 +0000415
416 /// \brief Call the appropriate runtime routine to notify that we finished
417 /// all the work with current loop.
418 ///
419 /// \param CGF Reference to current CodeGenFunction.
420 /// \param Loc Clang source location.
421 /// \param ScheduleKind Schedule kind, specified by the 'schedule' clause.
422 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000423 virtual void emitForFinish(CodeGenFunction &CGF, SourceLocation Loc,
424 OpenMPScheduleClauseKind ScheduleKind);
Alexander Musmanc6388682014-12-15 07:07:06 +0000425
Alexander Musman92bdaab2015-03-12 13:37:50 +0000426 /// Call __kmpc_dispatch_next(
427 /// ident_t *loc, kmp_int32 tid, kmp_int32 *p_lastiter,
428 /// kmp_int[32|64] *p_lower, kmp_int[32|64] *p_upper,
429 /// kmp_int[32|64] *p_stride);
430 /// \param IVSize Size of the iteration variable in bits.
431 /// \param IVSigned Sign of the interation variable.
432 /// \param IL Address of the output variable in which the flag of the
433 /// last iteration is returned.
434 /// \param LB Address of the output variable in which the lower iteration
435 /// number is returned.
436 /// \param UB Address of the output variable in which the upper iteration
437 /// number is returned.
438 /// \param ST Address of the output variable in which the stride value is
439 /// returned.
440 virtual llvm::Value *emitForNext(CodeGenFunction &CGF, SourceLocation Loc,
441 unsigned IVSize, bool IVSigned,
442 llvm::Value *IL, llvm::Value *LB,
443 llvm::Value *UB, llvm::Value *ST);
444
Alexey Bataevb2059782014-10-13 08:23:51 +0000445 /// \brief Emits call to void __kmpc_push_num_threads(ident_t *loc, kmp_int32
446 /// global_tid, kmp_int32 num_threads) to generate code for 'num_threads'
447 /// clause.
448 /// \param NumThreads An integer value of threads.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000449 virtual void emitNumThreadsClause(CodeGenFunction &CGF,
450 llvm::Value *NumThreads,
451 SourceLocation Loc);
Alexey Bataev97720002014-11-11 04:05:39 +0000452
453 /// \brief Returns address of the threadprivate variable for the current
454 /// thread.
NAKAMURA Takumicdcbfba2014-11-11 07:58:06 +0000455 /// \param VD Threadprivate variable.
Alexey Bataev97720002014-11-11 04:05:39 +0000456 /// \param VDAddr Address of the global variable \a VD.
457 /// \param Loc Location of the reference to threadprivate var.
458 /// \return Address of the threadprivate variable for the current thread.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000459 virtual llvm::Value *getAddrOfThreadPrivate(CodeGenFunction &CGF,
460 const VarDecl *VD,
461 llvm::Value *VDAddr,
462 SourceLocation Loc);
Alexey Bataev97720002014-11-11 04:05:39 +0000463
464 /// \brief Emit a code for initialization of threadprivate variable. It emits
465 /// a call to runtime library which adds initial value to the newly created
466 /// threadprivate variable (if it is not constant) and registers destructor
467 /// for the variable (if any).
468 /// \param VD Threadprivate variable.
469 /// \param VDAddr Address of the global variable \a VD.
470 /// \param Loc Location of threadprivate declaration.
471 /// \param PerformInit true if initialization expression is not constant.
472 virtual llvm::Function *
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000473 emitThreadPrivateVarDefinition(const VarDecl *VD, llvm::Value *VDAddr,
474 SourceLocation Loc, bool PerformInit,
475 CodeGenFunction *CGF = nullptr);
Alexey Bataevcc37cc12014-11-20 04:34:54 +0000476
477 /// \brief Emit flush of the variables specified in 'omp flush' directive.
478 /// \param Vars List of variables to flush.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000479 virtual void emitFlush(CodeGenFunction &CGF, ArrayRef<const Expr *> Vars,
480 SourceLocation Loc);
Alexey Bataev62b63b12015-03-10 07:28:44 +0000481
482 /// \brief Emit task region for the task directive. The task region is
483 /// emmitted in several steps:
484 /// 1. Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32
485 /// gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds,
486 /// kmp_routine_entry_t *task_entry). Here task_entry is a pointer to the
487 /// function:
488 /// kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) {
489 /// TaskFunction(gtid, tt->part_id, tt->shareds);
490 /// return 0;
491 /// }
492 /// 2. Copy a list of shared variables to field shareds of the resulting
493 /// structure kmp_task_t returned by the previous call (if any).
494 /// 3. Copy a pointer to destructions function to field destructions of the
495 /// resulting structure kmp_task_t.
496 /// 4. Emit a call to kmp_int32 __kmpc_omp_task(ident_t *, kmp_int32 gtid,
497 /// kmp_task_t *new_task), where new_task is a resulting structure from
498 /// previous items.
499 /// \param Tied true if the task is tied (the task is tied to the thread that
500 /// can suspend its task region), false - untied (the task is not tied to any
501 /// thread).
502 /// \param Final Contains either constant bool value, or llvm::Value * of i1
503 /// type for final clause. If the value is true, the task forces all of its
504 /// child tasks to become final and included tasks.
505 /// \param TaskFunction An LLVM function with type void (*)(i32 /*gtid*/, i32
506 /// /*part_id*/, captured_struct */*__context*/);
507 /// \param SharedsTy A type which contains references the shared variables.
508 /// \param Shareds Context with the list of shared variables from the \a
509 /// TaskFunction.
510 virtual void emitTaskCall(CodeGenFunction &CGF, SourceLocation Loc, bool Tied,
511 llvm::PointerIntPair<llvm::Value *, 1, bool> Final,
512 llvm::Value *TaskFunction, QualType SharedsTy,
513 llvm::Value *Shareds);
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000514 /// \brief Emit code for the directive that does not require outlining.
515 ///
516 /// \param CodeGen Code generation sequence for the \a D directive.
517 virtual void emitInlinedDirective(CodeGenFunction &CGF,
518 const RegionCodeGenTy &CodeGen);
Alexey Bataev9959db52014-05-06 10:08:46 +0000519};
Alexey Bataev8cbe0a62015-02-26 10:27:34 +0000520
Alexey Bataev23b69422014-06-18 07:08:49 +0000521} // namespace CodeGen
522} // namespace clang
Alexey Bataev9959db52014-05-06 10:08:46 +0000523
524#endif