blob: b7c92f000b977807bea74ea931350e330a18d229 [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
Alexander Musmanc6388682014-12-15 07:07:06 +000017#include "clang/Basic/OpenMPKinds.h"
Chandler Carruth0d9593d2015-01-14 11:29:14 +000018#include "clang/Basic/SourceLocation.h"
Alexey Bataev9959db52014-05-06 10:08:46 +000019#include "llvm/ADT/DenseMap.h"
Alexey Bataev97720002014-11-11 04:05:39 +000020#include "llvm/ADT/DenseSet.h"
Alexey Bataev3a3bf0b2014-09-22 10:01:53 +000021#include "llvm/ADT/StringMap.h"
Alexey Bataev97720002014-11-11 04:05:39 +000022#include "llvm/IR/ValueHandle.h"
Alexey Bataev18095712014-10-10 12:19:54 +000023
24namespace llvm {
25class ArrayType;
26class Constant;
27class Function;
28class FunctionType;
Alexey Bataev97720002014-11-11 04:05:39 +000029class GlobalVariable;
Alexey Bataev18095712014-10-10 12:19:54 +000030class StructType;
31class Type;
32class Value;
33} // namespace llvm
Alexey Bataev9959db52014-05-06 10:08:46 +000034
Alexey Bataev9959db52014-05-06 10:08:46 +000035namespace clang {
Alexey Bataevcc37cc12014-11-20 04:34:54 +000036class Expr;
Alexey Bataev18095712014-10-10 12:19:54 +000037class OMPExecutableDirective;
38class VarDecl;
39
Alexey Bataev9959db52014-05-06 10:08:46 +000040namespace CodeGen {
41
Alexey Bataev18095712014-10-10 12:19:54 +000042class CodeGenFunction;
43class CodeGenModule;
Alexey Bataev9959db52014-05-06 10:08:46 +000044
45class CGOpenMPRuntime {
46public:
Alexey Bataev8f7c1b02014-12-05 04:09:23 +000047
48private:
49 enum OpenMPRTLFunction {
50 /// \brief Call to void __kmpc_fork_call(ident_t *loc, kmp_int32 argc,
51 /// kmpc_micro microtask, ...);
52 OMPRTL__kmpc_fork_call,
53 /// \brief Call to void *__kmpc_threadprivate_cached(ident_t *loc,
54 /// kmp_int32 global_tid, void *data, size_t size, void ***cache);
55 OMPRTL__kmpc_threadprivate_cached,
56 /// \brief Call to void __kmpc_threadprivate_register( ident_t *,
57 /// void *data, kmpc_ctor ctor, kmpc_cctor cctor, kmpc_dtor dtor);
58 OMPRTL__kmpc_threadprivate_register,
59 // Call to __kmpc_int32 kmpc_global_thread_num(ident_t *loc);
60 OMPRTL__kmpc_global_thread_num,
61 // Call to void __kmpc_critical(ident_t *loc, kmp_int32 global_tid,
62 // kmp_critical_name *crit);
63 OMPRTL__kmpc_critical,
64 // Call to void __kmpc_end_critical(ident_t *loc, kmp_int32 global_tid,
65 // kmp_critical_name *crit);
66 OMPRTL__kmpc_end_critical,
67 // Call to kmp_int32 __kmpc_cancel_barrier(ident_t *loc, kmp_int32
68 // global_tid);
69 OMPRTL__kmpc_cancel_barrier,
Alexander Musmanc6388682014-12-15 07:07:06 +000070 // Calls for static scheduling 'omp for' loops.
71 OMPRTL__kmpc_for_static_init_4,
72 OMPRTL__kmpc_for_static_init_4u,
73 OMPRTL__kmpc_for_static_init_8,
74 OMPRTL__kmpc_for_static_init_8u,
75 OMPRTL__kmpc_for_static_fini,
Alexey Bataev8f7c1b02014-12-05 04:09:23 +000076 // Call to void __kmpc_serialized_parallel(ident_t *loc, kmp_int32
77 // global_tid);
78 OMPRTL__kmpc_serialized_parallel,
79 // Call to void __kmpc_end_serialized_parallel(ident_t *loc, kmp_int32
80 // global_tid);
81 OMPRTL__kmpc_end_serialized_parallel,
82 // Call to void __kmpc_push_num_threads(ident_t *loc, kmp_int32 global_tid,
83 // kmp_int32 num_threads);
84 OMPRTL__kmpc_push_num_threads,
Alexey Bataevd76df6d2015-02-24 12:55:09 +000085 // Call to void __kmpc_flush(ident_t *loc);
Alexey Bataev8f7c1b02014-12-05 04:09:23 +000086 OMPRTL__kmpc_flush,
87 // Call to kmp_int32 __kmpc_master(ident_t *, kmp_int32 global_tid);
88 OMPRTL__kmpc_master,
89 // Call to void __kmpc_end_master(ident_t *, kmp_int32 global_tid);
90 OMPRTL__kmpc_end_master,
Alexey Bataev9f797f32015-02-05 05:57:51 +000091 // Call to kmp_int32 __kmpc_omp_taskyield(ident_t *, kmp_int32 global_tid,
92 // int end_part);
93 OMPRTL__kmpc_omp_taskyield,
Alexey Bataev6956e2e2015-02-05 06:35:41 +000094 // Call to kmp_int32 __kmpc_single(ident_t *, kmp_int32 global_tid);
95 OMPRTL__kmpc_single,
96 // Call to void __kmpc_end_single(ident_t *, kmp_int32 global_tid);
97 OMPRTL__kmpc_end_single,
Alexey Bataev8f7c1b02014-12-05 04:09:23 +000098 };
99
Alexey Bataev9959db52014-05-06 10:08:46 +0000100 /// \brief Values for bit flags used in the ident_t to describe the fields.
101 /// All enumeric elements are named and described in accordance with the code
102 /// from http://llvm.org/svn/llvm-project/openmp/trunk/runtime/src/kmp.h
103 enum OpenMPLocationFlags {
104 /// \brief Use trampoline for internal microtask.
105 OMP_IDENT_IMD = 0x01,
106 /// \brief Use c-style ident structure.
107 OMP_IDENT_KMPC = 0x02,
108 /// \brief Atomic reduction option for kmpc_reduce.
109 OMP_ATOMIC_REDUCE = 0x10,
110 /// \brief Explicit 'barrier' directive.
111 OMP_IDENT_BARRIER_EXPL = 0x20,
112 /// \brief Implicit barrier in code.
113 OMP_IDENT_BARRIER_IMPL = 0x40,
114 /// \brief Implicit barrier in 'for' directive.
115 OMP_IDENT_BARRIER_IMPL_FOR = 0x40,
116 /// \brief Implicit barrier in 'sections' directive.
117 OMP_IDENT_BARRIER_IMPL_SECTIONS = 0xC0,
118 /// \brief Implicit barrier in 'single' directive.
119 OMP_IDENT_BARRIER_IMPL_SINGLE = 0x140
120 };
Alexey Bataev9959db52014-05-06 10:08:46 +0000121 CodeGenModule &CGM;
122 /// \brief Default const ident_t object used for initialization of all other
123 /// ident_t objects.
124 llvm::Constant *DefaultOpenMPPSource;
Alexey Bataev18095712014-10-10 12:19:54 +0000125 /// \brief Map of flags and corresponding default locations.
Alexey Bataev15007ba2014-05-07 06:18:01 +0000126 typedef llvm::DenseMap<unsigned, llvm::Value *> OpenMPDefaultLocMapTy;
127 OpenMPDefaultLocMapTy OpenMPDefaultLocMap;
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000128 llvm::Value *getOrCreateDefaultLocation(OpenMPLocationFlags Flags);
Alexey Bataev9959db52014-05-06 10:08:46 +0000129 /// \brief Describes ident structure that describes a source location.
130 /// All descriptions are taken from
131 /// http://llvm.org/svn/llvm-project/openmp/trunk/runtime/src/kmp.h
132 /// Original structure:
133 /// typedef struct ident {
134 /// kmp_int32 reserved_1; /**< might be used in Fortran;
135 /// see above */
136 /// kmp_int32 flags; /**< also f.flags; KMP_IDENT_xxx flags;
137 /// KMP_IDENT_KMPC identifies this union
138 /// member */
139 /// kmp_int32 reserved_2; /**< not really used in Fortran any more;
140 /// see above */
141 ///#if USE_ITT_BUILD
142 /// /* but currently used for storing
143 /// region-specific ITT */
144 /// /* contextual information. */
145 ///#endif /* USE_ITT_BUILD */
146 /// kmp_int32 reserved_3; /**< source[4] in Fortran, do not use for
147 /// C++ */
148 /// char const *psource; /**< String describing the source location.
149 /// The string is composed of semi-colon separated
150 // fields which describe the source file,
151 /// the function and a pair of line numbers that
152 /// delimit the construct.
153 /// */
154 /// } ident_t;
155 enum IdentFieldIndex {
156 /// \brief might be used in Fortran
157 IdentField_Reserved_1,
158 /// \brief OMP_IDENT_xxx flags; OMP_IDENT_KMPC identifies this union member.
159 IdentField_Flags,
160 /// \brief Not really used in Fortran any more
161 IdentField_Reserved_2,
162 /// \brief Source[4] in Fortran, do not use for C++
163 IdentField_Reserved_3,
164 /// \brief String describing the source location. The string is composed of
165 /// semi-colon separated fields which describe the source file, the function
166 /// and a pair of line numbers that delimit the construct.
167 IdentField_PSource
168 };
169 llvm::StructType *IdentTy;
Alexey Bataev18095712014-10-10 12:19:54 +0000170 /// \brief Map for SourceLocation and OpenMP runtime library debug locations.
Alexey Bataevf002aca2014-05-30 05:48:40 +0000171 typedef llvm::DenseMap<unsigned, llvm::Value *> OpenMPDebugLocMapTy;
172 OpenMPDebugLocMapTy OpenMPDebugLocMap;
Alexey Bataev9959db52014-05-06 10:08:46 +0000173 /// \brief The type for a microtask which gets passed to __kmpc_fork_call().
174 /// Original representation is:
175 /// typedef void (kmpc_micro)(kmp_int32 global_tid, kmp_int32 bound_tid,...);
176 llvm::FunctionType *Kmpc_MicroTy;
Alexey Bataev18095712014-10-10 12:19:54 +0000177 /// \brief Stores debug location and ThreadID for the function.
178 struct DebugLocThreadIdTy {
179 llvm::Value *DebugLoc;
180 llvm::Value *ThreadID;
181 };
182 /// \brief Map of local debug location, ThreadId and functions.
183 typedef llvm::DenseMap<llvm::Function *, DebugLocThreadIdTy>
184 OpenMPLocThreadIDMapTy;
185 OpenMPLocThreadIDMapTy OpenMPLocThreadIDMap;
Alexey Bataev3a3bf0b2014-09-22 10:01:53 +0000186 /// \brief Type kmp_critical_name, originally defined as typedef kmp_int32
187 /// kmp_critical_name[8];
188 llvm::ArrayType *KmpCriticalNameTy;
Alexey Bataev97720002014-11-11 04:05:39 +0000189 /// \brief An ordered map of auto-generated variables to their unique names.
190 /// It stores variables with the following names: 1) ".gomp_critical_user_" +
191 /// <critical_section_name> + ".var" for "omp critical" directives; 2)
192 /// <mangled_name_for_global_var> + ".cache." for cache for threadprivate
193 /// variables.
194 llvm::StringMap<llvm::AssertingVH<llvm::Constant>, llvm::BumpPtrAllocator>
195 InternalVars;
Alexey Bataev9959db52014-05-06 10:08:46 +0000196
Alexey Bataev9959db52014-05-06 10:08:46 +0000197 /// \brief Emits object of ident_t type with info for source location.
Alexey Bataev9959db52014-05-06 10:08:46 +0000198 /// \param Flags Flags for OpenMP location.
199 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000200 llvm::Value *emitUpdateLocation(CodeGenFunction &CGF, SourceLocation Loc,
201 OpenMPLocationFlags Flags = OMP_IDENT_KMPC);
Alexey Bataev9959db52014-05-06 10:08:46 +0000202
Alexey Bataevd74d0602014-10-13 06:02:40 +0000203 /// \brief Returns pointer to ident_t type.
Alexey Bataev9959db52014-05-06 10:08:46 +0000204 llvm::Type *getIdentTyPointerTy();
205
Alexey Bataevd74d0602014-10-13 06:02:40 +0000206 /// \brief Returns pointer to kmpc_micro type.
Alexey Bataev9959db52014-05-06 10:08:46 +0000207 llvm::Type *getKmpc_MicroPointerTy();
208
209 /// \brief Returns specified OpenMP runtime function.
210 /// \param Function OpenMP runtime function.
211 /// \return Specified function.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000212 llvm::Constant *createRuntimeFunction(OpenMPRTLFunction Function);
Alexey Bataev3a3bf0b2014-09-22 10:01:53 +0000213
Alexey Bataev97720002014-11-11 04:05:39 +0000214 /// \brief If the specified mangled name is not in the module, create and
215 /// return threadprivate cache object. This object is a pointer's worth of
216 /// storage that's reserved for use by the OpenMP runtime.
NAKAMURA Takumicdcbfba2014-11-11 07:58:06 +0000217 /// \param VD Threadprivate variable.
Alexey Bataev97720002014-11-11 04:05:39 +0000218 /// \return Cache variable for the specified threadprivate.
219 llvm::Constant *getOrCreateThreadPrivateCache(const VarDecl *VD);
220
Alexey Bataevd74d0602014-10-13 06:02:40 +0000221 /// \brief Emits address of the word in a memory where current thread id is
222 /// stored.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000223 virtual llvm::Value *emitThreadIDAddress(CodeGenFunction &CGF,
Alexey Bataevd74d0602014-10-13 06:02:40 +0000224 SourceLocation Loc);
225
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000226 /// \brief Gets thread id value for the current thread.
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000227 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000228 llvm::Value *getThreadID(CodeGenFunction &CGF, SourceLocation Loc);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000229
Alexey Bataev97720002014-11-11 04:05:39 +0000230 /// \brief Gets (if variable with the given name already exist) or creates
231 /// internal global variable with the specified Name. The created variable has
232 /// linkage CommonLinkage by default and is initialized by null value.
233 /// \param Ty Type of the global variable. If it is exist already the type
234 /// must be the same.
235 /// \param Name Name of the variable.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000236 llvm::Constant *getOrCreateInternalVariable(llvm::Type *Ty,
Alexey Bataev97720002014-11-11 04:05:39 +0000237 const llvm::Twine &Name);
238
239 /// \brief Set of threadprivate variables with the generated initializer.
240 llvm::DenseSet<const VarDecl *> ThreadPrivateWithDefinition;
241
242 /// \brief Emits initialization code for the threadprivate variables.
243 /// \param VDAddr Address of the global variable \a VD.
244 /// \param Ctor Pointer to a global init function for \a VD.
245 /// \param CopyCtor Pointer to a global copy function for \a VD.
246 /// \param Dtor Pointer to a global destructor function for \a VD.
247 /// \param Loc Location of threadprivate declaration.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000248 void emitThreadPrivateVarInit(CodeGenFunction &CGF, llvm::Value *VDAddr,
249 llvm::Value *Ctor, llvm::Value *CopyCtor,
250 llvm::Value *Dtor, SourceLocation Loc);
Alexey Bataev97720002014-11-11 04:05:39 +0000251
Alexey Bataev75ddfab2014-12-01 11:32:38 +0000252 /// \brief Returns corresponding lock object for the specified critical region
253 /// name. If the lock object does not exist it is created, otherwise the
254 /// reference to the existing copy is returned.
255 /// \param CriticalName Name of the critical region.
256 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000257 llvm::Value *getCriticalRegionLock(StringRef CriticalName);
Alexey Bataev75ddfab2014-12-01 11:32:38 +0000258
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000259public:
260 explicit CGOpenMPRuntime(CodeGenModule &CGM);
261 virtual ~CGOpenMPRuntime() {}
262
Alexey Bataev18095712014-10-10 12:19:54 +0000263 /// \brief Emits outlined function for the specified OpenMP directive \a D
264 /// (required for parallel and task directives). This outlined function has
265 /// type void(*)(kmp_int32 /*ThreadID*/, kmp_int32 /*BoundID*/, struct
266 /// context_vars*).
267 /// \param D OpenMP directive.
268 /// \param ThreadIDVar Variable for thread id in the current OpenMP region.
269 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000270 virtual llvm::Value *emitOutlinedFunction(const OMPExecutableDirective &D,
271 const VarDecl *ThreadIDVar);
Alexey Bataev18095712014-10-10 12:19:54 +0000272
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000273 /// \brief Cleans up references to the objects in finished function.
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000274 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000275 void functionFinished(CodeGenFunction &CGF);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000276
277 /// \brief Emits code for parallel call of the \a OutlinedFn with variables
278 /// captured in a record which address is stored in \a CapturedStruct.
Alexey Bataev18095712014-10-10 12:19:54 +0000279 /// \param OutlinedFn Outlined function to be run in parallel threads. Type of
280 /// this function is void(*)(kmp_int32, kmp_int32, struct context_vars*).
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000281 /// \param CapturedStruct A pointer to the record with the references to
282 /// variables used in \a OutlinedFn function.
283 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000284 virtual void emitParallelCall(CodeGenFunction &CGF, SourceLocation Loc,
285 llvm::Value *OutlinedFn,
286 llvm::Value *CapturedStruct);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000287
Alexey Bataevd74d0602014-10-13 06:02:40 +0000288 /// \brief Emits code for serial call of the \a OutlinedFn with variables
289 /// captured in a record which address is stored in \a CapturedStruct.
290 /// \param OutlinedFn Outlined function to be run in serial mode.
291 /// \param CapturedStruct A pointer to the record with the references to
292 /// variables used in \a OutlinedFn function.
293 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000294 virtual void emitSerialCall(CodeGenFunction &CGF, SourceLocation Loc,
295 llvm::Value *OutlinedFn,
296 llvm::Value *CapturedStruct);
Alexey Bataevd74d0602014-10-13 06:02:40 +0000297
Alexey Bataev75ddfab2014-12-01 11:32:38 +0000298 /// \brief Emits a critical region.
Alexey Bataev18095712014-10-10 12:19:54 +0000299 /// \param CriticalName Name of the critical region.
Alexey Bataev75ddfab2014-12-01 11:32:38 +0000300 /// \param CriticalOpGen Generator for the statement associated with the given
301 /// critical region.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000302 virtual void emitCriticalRegion(CodeGenFunction &CGF, StringRef CriticalName,
303 const std::function<void()> &CriticalOpGen,
304 SourceLocation Loc);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000305
Alexey Bataev8d690652014-12-04 07:23:53 +0000306 /// \brief Emits a master region.
307 /// \param MasterOpGen Generator for the statement associated with the given
308 /// master region.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000309 virtual void emitMasterRegion(CodeGenFunction &CGF,
310 const std::function<void()> &MasterOpGen,
311 SourceLocation Loc);
Alexey Bataev8d690652014-12-04 07:23:53 +0000312
Alexey Bataev9f797f32015-02-05 05:57:51 +0000313 /// \brief Emits code for a taskyield directive.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000314 virtual void emitTaskyieldCall(CodeGenFunction &CGF, SourceLocation Loc);
Alexey Bataev9f797f32015-02-05 05:57:51 +0000315
Alexey Bataev6956e2e2015-02-05 06:35:41 +0000316 /// \brief Emits a single region.
317 /// \param SingleOpGen Generator for the statement associated with the given
318 /// single region.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000319 virtual void emitSingleRegion(CodeGenFunction &CGF,
320 const std::function<void()> &SingleOpGen,
321 SourceLocation Loc);
Alexey Bataev6956e2e2015-02-05 06:35:41 +0000322
Alexey Bataev8f7c1b02014-12-05 04:09:23 +0000323 /// \brief Emits explicit barrier for OpenMP threads.
324 /// \param IsExplicit true, if it is explicitly specified barrier.
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000325 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000326 virtual void emitBarrierCall(CodeGenFunction &CGF, SourceLocation Loc,
327 bool IsExplicit = true);
Alexey Bataevb2059782014-10-13 08:23:51 +0000328
Alexander Musmanc6388682014-12-15 07:07:06 +0000329 /// \brief Check if the specified \a ScheduleKind is static non-chunked.
330 /// This kind of worksharing directive is emitted without outer loop.
331 /// \param ScheduleKind Schedule kind specified in the 'schedule' clause.
332 /// \param Chunked True if chunk is specified in the clause.
333 ///
334 virtual bool isStaticNonchunked(OpenMPScheduleClauseKind ScheduleKind,
335 bool Chunked) const;
336
Alexander Musmandf7a8e22015-01-22 08:49:35 +0000337 /// \brief Check if the specified \a ScheduleKind is dynamic.
338 /// This kind of worksharing directive is emitted without outer loop.
339 /// \param ScheduleKind Schedule Kind specified in the 'schedule' clause.
340 ///
341 virtual bool isDynamic(OpenMPScheduleClauseKind ScheduleKind) const;
342
Alexander Musmanc6388682014-12-15 07:07:06 +0000343 /// \brief Call the appropriate runtime routine to initialize it before start
344 /// of loop.
345 ///
346 /// Depending on the loop schedule, it is nesessary to call some runtime
347 /// routine before start of the OpenMP loop to get the loop upper / lower
348 /// bounds \a LB and \a UB and stride \a ST.
349 ///
350 /// \param CGF Reference to current CodeGenFunction.
351 /// \param Loc Clang source location.
NAKAMURA Takumieca08382014-12-17 14:47:06 +0000352 /// \param SchedKind Schedule kind, specified by the 'schedule' clause.
Alexander Musmanc6388682014-12-15 07:07:06 +0000353 /// \param IVSize Size of the iteration variable in bits.
354 /// \param IVSigned Sign of the interation variable.
355 /// \param IL Address of the output variable in which the flag of the
356 /// last iteration is returned.
357 /// \param LB Address of the output variable in which the lower iteration
358 /// number is returned.
359 /// \param UB Address of the output variable in which the upper iteration
360 /// number is returned.
361 /// \param ST Address of the output variable in which the stride value is
362 /// returned nesessary to generated the static_chunked scheduled loop.
363 /// \param Chunk Value of the chunk for the static_chunked scheduled loop.
364 /// For the default (nullptr) value, the chunk 1 will be used.
365 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000366 virtual void emitForInit(CodeGenFunction &CGF, SourceLocation Loc,
367 OpenMPScheduleClauseKind SchedKind, unsigned IVSize,
368 bool IVSigned, llvm::Value *IL, llvm::Value *LB,
369 llvm::Value *UB, llvm::Value *ST,
370 llvm::Value *Chunk = nullptr);
Alexander Musmanc6388682014-12-15 07:07:06 +0000371
372 /// \brief Call the appropriate runtime routine to notify that we finished
373 /// all the work with current loop.
374 ///
375 /// \param CGF Reference to current CodeGenFunction.
376 /// \param Loc Clang source location.
377 /// \param ScheduleKind Schedule kind, specified by the 'schedule' clause.
378 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000379 virtual void emitForFinish(CodeGenFunction &CGF, SourceLocation Loc,
380 OpenMPScheduleClauseKind ScheduleKind);
Alexander Musmanc6388682014-12-15 07:07:06 +0000381
Alexey Bataevb2059782014-10-13 08:23:51 +0000382 /// \brief Emits call to void __kmpc_push_num_threads(ident_t *loc, kmp_int32
383 /// global_tid, kmp_int32 num_threads) to generate code for 'num_threads'
384 /// clause.
385 /// \param NumThreads An integer value of threads.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000386 virtual void emitNumThreadsClause(CodeGenFunction &CGF,
387 llvm::Value *NumThreads,
388 SourceLocation Loc);
Alexey Bataev97720002014-11-11 04:05:39 +0000389
390 /// \brief Returns address of the threadprivate variable for the current
391 /// thread.
NAKAMURA Takumicdcbfba2014-11-11 07:58:06 +0000392 /// \param VD Threadprivate variable.
Alexey Bataev97720002014-11-11 04:05:39 +0000393 /// \param VDAddr Address of the global variable \a VD.
394 /// \param Loc Location of the reference to threadprivate var.
395 /// \return Address of the threadprivate variable for the current thread.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000396 virtual llvm::Value *getAddrOfThreadPrivate(CodeGenFunction &CGF,
397 const VarDecl *VD,
398 llvm::Value *VDAddr,
399 SourceLocation Loc);
Alexey Bataev97720002014-11-11 04:05:39 +0000400
401 /// \brief Emit a code for initialization of threadprivate variable. It emits
402 /// a call to runtime library which adds initial value to the newly created
403 /// threadprivate variable (if it is not constant) and registers destructor
404 /// for the variable (if any).
405 /// \param VD Threadprivate variable.
406 /// \param VDAddr Address of the global variable \a VD.
407 /// \param Loc Location of threadprivate declaration.
408 /// \param PerformInit true if initialization expression is not constant.
409 virtual llvm::Function *
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000410 emitThreadPrivateVarDefinition(const VarDecl *VD, llvm::Value *VDAddr,
411 SourceLocation Loc, bool PerformInit,
412 CodeGenFunction *CGF = nullptr);
Alexey Bataevcc37cc12014-11-20 04:34:54 +0000413
414 /// \brief Emit flush of the variables specified in 'omp flush' directive.
415 /// \param Vars List of variables to flush.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000416 virtual void emitFlush(CodeGenFunction &CGF, ArrayRef<const Expr *> Vars,
417 SourceLocation Loc);
Alexey Bataev9959db52014-05-06 10:08:46 +0000418};
Alexey Bataev23b69422014-06-18 07:08:49 +0000419} // namespace CodeGen
420} // namespace clang
Alexey Bataev9959db52014-05-06 10:08:46 +0000421
422#endif