blob: 97aa5b875b7ebdb4a35246ae4769332da927feeb [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 {
Alexey Bataev8f7c1b02014-12-05 04:09:23 +000046 enum OpenMPRTLFunction {
47 /// \brief Call to void __kmpc_fork_call(ident_t *loc, kmp_int32 argc,
48 /// kmpc_micro microtask, ...);
49 OMPRTL__kmpc_fork_call,
50 /// \brief Call to void *__kmpc_threadprivate_cached(ident_t *loc,
51 /// kmp_int32 global_tid, void *data, size_t size, void ***cache);
52 OMPRTL__kmpc_threadprivate_cached,
53 /// \brief Call to void __kmpc_threadprivate_register( ident_t *,
54 /// void *data, kmpc_ctor ctor, kmpc_cctor cctor, kmpc_dtor dtor);
55 OMPRTL__kmpc_threadprivate_register,
56 // Call to __kmpc_int32 kmpc_global_thread_num(ident_t *loc);
57 OMPRTL__kmpc_global_thread_num,
58 // Call to void __kmpc_critical(ident_t *loc, kmp_int32 global_tid,
59 // kmp_critical_name *crit);
60 OMPRTL__kmpc_critical,
61 // Call to void __kmpc_end_critical(ident_t *loc, kmp_int32 global_tid,
62 // kmp_critical_name *crit);
63 OMPRTL__kmpc_end_critical,
64 // Call to kmp_int32 __kmpc_cancel_barrier(ident_t *loc, kmp_int32
65 // global_tid);
66 OMPRTL__kmpc_cancel_barrier,
Alexander Musmanc6388682014-12-15 07:07:06 +000067 // Calls for static scheduling 'omp for' loops.
68 OMPRTL__kmpc_for_static_init_4,
69 OMPRTL__kmpc_for_static_init_4u,
70 OMPRTL__kmpc_for_static_init_8,
71 OMPRTL__kmpc_for_static_init_8u,
72 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 Bataev8f7c1b02014-12-05 04:09:23 +000095 };
96
Alexey Bataev9959db52014-05-06 10:08:46 +000097 /// \brief Values for bit flags used in the ident_t to describe the fields.
98 /// All enumeric elements are named and described in accordance with the code
99 /// from http://llvm.org/svn/llvm-project/openmp/trunk/runtime/src/kmp.h
100 enum OpenMPLocationFlags {
101 /// \brief Use trampoline for internal microtask.
102 OMP_IDENT_IMD = 0x01,
103 /// \brief Use c-style ident structure.
104 OMP_IDENT_KMPC = 0x02,
105 /// \brief Atomic reduction option for kmpc_reduce.
106 OMP_ATOMIC_REDUCE = 0x10,
107 /// \brief Explicit 'barrier' directive.
108 OMP_IDENT_BARRIER_EXPL = 0x20,
109 /// \brief Implicit barrier in code.
110 OMP_IDENT_BARRIER_IMPL = 0x40,
111 /// \brief Implicit barrier in 'for' directive.
112 OMP_IDENT_BARRIER_IMPL_FOR = 0x40,
113 /// \brief Implicit barrier in 'sections' directive.
114 OMP_IDENT_BARRIER_IMPL_SECTIONS = 0xC0,
115 /// \brief Implicit barrier in 'single' directive.
116 OMP_IDENT_BARRIER_IMPL_SINGLE = 0x140
117 };
Alexey Bataev9959db52014-05-06 10:08:46 +0000118 CodeGenModule &CGM;
119 /// \brief Default const ident_t object used for initialization of all other
120 /// ident_t objects.
121 llvm::Constant *DefaultOpenMPPSource;
Alexey Bataev18095712014-10-10 12:19:54 +0000122 /// \brief Map of flags and corresponding default locations.
Alexey Bataev15007ba2014-05-07 06:18:01 +0000123 typedef llvm::DenseMap<unsigned, llvm::Value *> OpenMPDefaultLocMapTy;
124 OpenMPDefaultLocMapTy OpenMPDefaultLocMap;
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000125 llvm::Value *getOrCreateDefaultLocation(OpenMPLocationFlags Flags);
Alexey Bataev9959db52014-05-06 10:08:46 +0000126 /// \brief Describes ident structure that describes a source location.
127 /// All descriptions are taken from
128 /// http://llvm.org/svn/llvm-project/openmp/trunk/runtime/src/kmp.h
129 /// Original structure:
130 /// typedef struct ident {
131 /// kmp_int32 reserved_1; /**< might be used in Fortran;
132 /// see above */
133 /// kmp_int32 flags; /**< also f.flags; KMP_IDENT_xxx flags;
134 /// KMP_IDENT_KMPC identifies this union
135 /// member */
136 /// kmp_int32 reserved_2; /**< not really used in Fortran any more;
137 /// see above */
138 ///#if USE_ITT_BUILD
139 /// /* but currently used for storing
140 /// region-specific ITT */
141 /// /* contextual information. */
142 ///#endif /* USE_ITT_BUILD */
143 /// kmp_int32 reserved_3; /**< source[4] in Fortran, do not use for
144 /// C++ */
145 /// char const *psource; /**< String describing the source location.
146 /// The string is composed of semi-colon separated
147 // fields which describe the source file,
148 /// the function and a pair of line numbers that
149 /// delimit the construct.
150 /// */
151 /// } ident_t;
152 enum IdentFieldIndex {
153 /// \brief might be used in Fortran
154 IdentField_Reserved_1,
155 /// \brief OMP_IDENT_xxx flags; OMP_IDENT_KMPC identifies this union member.
156 IdentField_Flags,
157 /// \brief Not really used in Fortran any more
158 IdentField_Reserved_2,
159 /// \brief Source[4] in Fortran, do not use for C++
160 IdentField_Reserved_3,
161 /// \brief String describing the source location. The string is composed of
162 /// semi-colon separated fields which describe the source file, the function
163 /// and a pair of line numbers that delimit the construct.
164 IdentField_PSource
165 };
166 llvm::StructType *IdentTy;
Alexey Bataev18095712014-10-10 12:19:54 +0000167 /// \brief Map for SourceLocation and OpenMP runtime library debug locations.
Alexey Bataevf002aca2014-05-30 05:48:40 +0000168 typedef llvm::DenseMap<unsigned, llvm::Value *> OpenMPDebugLocMapTy;
169 OpenMPDebugLocMapTy OpenMPDebugLocMap;
Alexey Bataev9959db52014-05-06 10:08:46 +0000170 /// \brief The type for a microtask which gets passed to __kmpc_fork_call().
171 /// Original representation is:
172 /// typedef void (kmpc_micro)(kmp_int32 global_tid, kmp_int32 bound_tid,...);
173 llvm::FunctionType *Kmpc_MicroTy;
Alexey Bataev18095712014-10-10 12:19:54 +0000174 /// \brief Stores debug location and ThreadID for the function.
175 struct DebugLocThreadIdTy {
176 llvm::Value *DebugLoc;
177 llvm::Value *ThreadID;
178 };
179 /// \brief Map of local debug location, ThreadId and functions.
180 typedef llvm::DenseMap<llvm::Function *, DebugLocThreadIdTy>
181 OpenMPLocThreadIDMapTy;
182 OpenMPLocThreadIDMapTy OpenMPLocThreadIDMap;
Alexey Bataev3a3bf0b2014-09-22 10:01:53 +0000183 /// \brief Type kmp_critical_name, originally defined as typedef kmp_int32
184 /// kmp_critical_name[8];
185 llvm::ArrayType *KmpCriticalNameTy;
Alexey Bataev97720002014-11-11 04:05:39 +0000186 /// \brief An ordered map of auto-generated variables to their unique names.
187 /// It stores variables with the following names: 1) ".gomp_critical_user_" +
188 /// <critical_section_name> + ".var" for "omp critical" directives; 2)
189 /// <mangled_name_for_global_var> + ".cache." for cache for threadprivate
190 /// variables.
191 llvm::StringMap<llvm::AssertingVH<llvm::Constant>, llvm::BumpPtrAllocator>
192 InternalVars;
Alexey Bataev9959db52014-05-06 10:08:46 +0000193
Alexey Bataev9959db52014-05-06 10:08:46 +0000194 /// \brief Emits object of ident_t type with info for source location.
Alexey Bataev9959db52014-05-06 10:08:46 +0000195 /// \param Flags Flags for OpenMP location.
196 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000197 llvm::Value *emitUpdateLocation(CodeGenFunction &CGF, SourceLocation Loc,
198 OpenMPLocationFlags Flags = OMP_IDENT_KMPC);
Alexey Bataev9959db52014-05-06 10:08:46 +0000199
Alexey Bataevd74d0602014-10-13 06:02:40 +0000200 /// \brief Returns pointer to ident_t type.
Alexey Bataev9959db52014-05-06 10:08:46 +0000201 llvm::Type *getIdentTyPointerTy();
202
Alexey Bataevd74d0602014-10-13 06:02:40 +0000203 /// \brief Returns pointer to kmpc_micro type.
Alexey Bataev9959db52014-05-06 10:08:46 +0000204 llvm::Type *getKmpc_MicroPointerTy();
205
206 /// \brief Returns specified OpenMP runtime function.
207 /// \param Function OpenMP runtime function.
208 /// \return Specified function.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000209 llvm::Constant *createRuntimeFunction(OpenMPRTLFunction Function);
Alexey Bataev3a3bf0b2014-09-22 10:01:53 +0000210
Alexey Bataev97720002014-11-11 04:05:39 +0000211 /// \brief If the specified mangled name is not in the module, create and
212 /// return threadprivate cache object. This object is a pointer's worth of
213 /// storage that's reserved for use by the OpenMP runtime.
NAKAMURA Takumicdcbfba2014-11-11 07:58:06 +0000214 /// \param VD Threadprivate variable.
Alexey Bataev97720002014-11-11 04:05:39 +0000215 /// \return Cache variable for the specified threadprivate.
216 llvm::Constant *getOrCreateThreadPrivateCache(const VarDecl *VD);
217
Alexey Bataevd74d0602014-10-13 06:02:40 +0000218 /// \brief Emits address of the word in a memory where current thread id is
219 /// stored.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000220 virtual llvm::Value *emitThreadIDAddress(CodeGenFunction &CGF,
Alexey Bataevd74d0602014-10-13 06:02:40 +0000221 SourceLocation Loc);
222
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000223 /// \brief Gets thread id value for the current thread.
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000224 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000225 llvm::Value *getThreadID(CodeGenFunction &CGF, SourceLocation Loc);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000226
Alexey Bataev97720002014-11-11 04:05:39 +0000227 /// \brief Gets (if variable with the given name already exist) or creates
228 /// internal global variable with the specified Name. The created variable has
229 /// linkage CommonLinkage by default and is initialized by null value.
230 /// \param Ty Type of the global variable. If it is exist already the type
231 /// must be the same.
232 /// \param Name Name of the variable.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000233 llvm::Constant *getOrCreateInternalVariable(llvm::Type *Ty,
Alexey Bataev97720002014-11-11 04:05:39 +0000234 const llvm::Twine &Name);
235
236 /// \brief Set of threadprivate variables with the generated initializer.
237 llvm::DenseSet<const VarDecl *> ThreadPrivateWithDefinition;
238
239 /// \brief Emits initialization code for the threadprivate variables.
240 /// \param VDAddr Address of the global variable \a VD.
241 /// \param Ctor Pointer to a global init function for \a VD.
242 /// \param CopyCtor Pointer to a global copy function for \a VD.
243 /// \param Dtor Pointer to a global destructor function for \a VD.
244 /// \param Loc Location of threadprivate declaration.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000245 void emitThreadPrivateVarInit(CodeGenFunction &CGF, llvm::Value *VDAddr,
246 llvm::Value *Ctor, llvm::Value *CopyCtor,
247 llvm::Value *Dtor, SourceLocation Loc);
Alexey Bataev97720002014-11-11 04:05:39 +0000248
Alexey Bataev75ddfab2014-12-01 11:32:38 +0000249 /// \brief Returns corresponding lock object for the specified critical region
250 /// name. If the lock object does not exist it is created, otherwise the
251 /// reference to the existing copy is returned.
252 /// \param CriticalName Name of the critical region.
253 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000254 llvm::Value *getCriticalRegionLock(StringRef CriticalName);
Alexey Bataev75ddfab2014-12-01 11:32:38 +0000255
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000256public:
257 explicit CGOpenMPRuntime(CodeGenModule &CGM);
258 virtual ~CGOpenMPRuntime() {}
259
Alexey Bataev18095712014-10-10 12:19:54 +0000260 /// \brief Emits outlined function for the specified OpenMP directive \a D
261 /// (required for parallel and task directives). This outlined function has
262 /// type void(*)(kmp_int32 /*ThreadID*/, kmp_int32 /*BoundID*/, struct
263 /// context_vars*).
264 /// \param D OpenMP directive.
265 /// \param ThreadIDVar Variable for thread id in the current OpenMP region.
266 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000267 virtual llvm::Value *emitOutlinedFunction(const OMPExecutableDirective &D,
268 const VarDecl *ThreadIDVar);
Alexey Bataev18095712014-10-10 12:19:54 +0000269
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000270 /// \brief Cleans up references to the objects in finished function.
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000271 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000272 void functionFinished(CodeGenFunction &CGF);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000273
274 /// \brief Emits code for parallel call of the \a OutlinedFn with variables
275 /// captured in a record which address is stored in \a CapturedStruct.
Alexey Bataev18095712014-10-10 12:19:54 +0000276 /// \param OutlinedFn Outlined function to be run in parallel threads. Type of
277 /// this function is void(*)(kmp_int32, kmp_int32, struct context_vars*).
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000278 /// \param CapturedStruct A pointer to the record with the references to
279 /// variables used in \a OutlinedFn function.
280 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000281 virtual void emitParallelCall(CodeGenFunction &CGF, SourceLocation Loc,
282 llvm::Value *OutlinedFn,
283 llvm::Value *CapturedStruct);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000284
Alexey Bataevd74d0602014-10-13 06:02:40 +0000285 /// \brief Emits code for serial call of the \a OutlinedFn with variables
286 /// captured in a record which address is stored in \a CapturedStruct.
287 /// \param OutlinedFn Outlined function to be run in serial mode.
288 /// \param CapturedStruct A pointer to the record with the references to
289 /// variables used in \a OutlinedFn function.
290 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000291 virtual void emitSerialCall(CodeGenFunction &CGF, SourceLocation Loc,
292 llvm::Value *OutlinedFn,
293 llvm::Value *CapturedStruct);
Alexey Bataevd74d0602014-10-13 06:02:40 +0000294
Alexey Bataev75ddfab2014-12-01 11:32:38 +0000295 /// \brief Emits a critical region.
Alexey Bataev18095712014-10-10 12:19:54 +0000296 /// \param CriticalName Name of the critical region.
Alexey Bataev75ddfab2014-12-01 11:32:38 +0000297 /// \param CriticalOpGen Generator for the statement associated with the given
298 /// critical region.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000299 virtual void emitCriticalRegion(CodeGenFunction &CGF, StringRef CriticalName,
300 const std::function<void()> &CriticalOpGen,
301 SourceLocation Loc);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000302
Alexey Bataev8d690652014-12-04 07:23:53 +0000303 /// \brief Emits a master region.
304 /// \param MasterOpGen Generator for the statement associated with the given
305 /// master region.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000306 virtual void emitMasterRegion(CodeGenFunction &CGF,
307 const std::function<void()> &MasterOpGen,
308 SourceLocation Loc);
Alexey Bataev8d690652014-12-04 07:23:53 +0000309
Alexey Bataev9f797f32015-02-05 05:57:51 +0000310 /// \brief Emits code for a taskyield directive.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000311 virtual void emitTaskyieldCall(CodeGenFunction &CGF, SourceLocation Loc);
Alexey Bataev9f797f32015-02-05 05:57:51 +0000312
Alexey Bataev6956e2e2015-02-05 06:35:41 +0000313 /// \brief Emits a single region.
314 /// \param SingleOpGen Generator for the statement associated with the given
315 /// single region.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000316 virtual void emitSingleRegion(CodeGenFunction &CGF,
317 const std::function<void()> &SingleOpGen,
318 SourceLocation Loc);
Alexey Bataev6956e2e2015-02-05 06:35:41 +0000319
Alexey Bataev8f7c1b02014-12-05 04:09:23 +0000320 /// \brief Emits explicit barrier for OpenMP threads.
321 /// \param IsExplicit true, if it is explicitly specified barrier.
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000322 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000323 virtual void emitBarrierCall(CodeGenFunction &CGF, SourceLocation Loc,
324 bool IsExplicit = true);
Alexey Bataevb2059782014-10-13 08:23:51 +0000325
Alexander Musmanc6388682014-12-15 07:07:06 +0000326 /// \brief Check if the specified \a ScheduleKind is static non-chunked.
327 /// This kind of worksharing directive is emitted without outer loop.
328 /// \param ScheduleKind Schedule kind specified in the 'schedule' clause.
329 /// \param Chunked True if chunk is specified in the clause.
330 ///
331 virtual bool isStaticNonchunked(OpenMPScheduleClauseKind ScheduleKind,
332 bool Chunked) const;
333
Alexander Musmandf7a8e22015-01-22 08:49:35 +0000334 /// \brief Check if the specified \a ScheduleKind is dynamic.
335 /// This kind of worksharing directive is emitted without outer loop.
336 /// \param ScheduleKind Schedule Kind specified in the 'schedule' clause.
337 ///
338 virtual bool isDynamic(OpenMPScheduleClauseKind ScheduleKind) const;
339
Alexander Musmanc6388682014-12-15 07:07:06 +0000340 /// \brief Call the appropriate runtime routine to initialize it before start
341 /// of loop.
342 ///
343 /// Depending on the loop schedule, it is nesessary to call some runtime
344 /// routine before start of the OpenMP loop to get the loop upper / lower
345 /// bounds \a LB and \a UB and stride \a ST.
346 ///
347 /// \param CGF Reference to current CodeGenFunction.
348 /// \param Loc Clang source location.
NAKAMURA Takumieca08382014-12-17 14:47:06 +0000349 /// \param SchedKind Schedule kind, specified by the 'schedule' clause.
Alexander Musmanc6388682014-12-15 07:07:06 +0000350 /// \param IVSize Size of the iteration variable in bits.
351 /// \param IVSigned Sign of the interation variable.
352 /// \param IL Address of the output variable in which the flag of the
353 /// last iteration is returned.
354 /// \param LB Address of the output variable in which the lower iteration
355 /// number is returned.
356 /// \param UB Address of the output variable in which the upper iteration
357 /// number is returned.
358 /// \param ST Address of the output variable in which the stride value is
359 /// returned nesessary to generated the static_chunked scheduled loop.
360 /// \param Chunk Value of the chunk for the static_chunked scheduled loop.
361 /// For the default (nullptr) value, the chunk 1 will be used.
362 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000363 virtual void emitForInit(CodeGenFunction &CGF, SourceLocation Loc,
364 OpenMPScheduleClauseKind SchedKind, unsigned IVSize,
365 bool IVSigned, llvm::Value *IL, llvm::Value *LB,
366 llvm::Value *UB, llvm::Value *ST,
367 llvm::Value *Chunk = nullptr);
Alexander Musmanc6388682014-12-15 07:07:06 +0000368
369 /// \brief Call the appropriate runtime routine to notify that we finished
370 /// all the work with current loop.
371 ///
372 /// \param CGF Reference to current CodeGenFunction.
373 /// \param Loc Clang source location.
374 /// \param ScheduleKind Schedule kind, specified by the 'schedule' clause.
375 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000376 virtual void emitForFinish(CodeGenFunction &CGF, SourceLocation Loc,
377 OpenMPScheduleClauseKind ScheduleKind);
Alexander Musmanc6388682014-12-15 07:07:06 +0000378
Alexey Bataevb2059782014-10-13 08:23:51 +0000379 /// \brief Emits call to void __kmpc_push_num_threads(ident_t *loc, kmp_int32
380 /// global_tid, kmp_int32 num_threads) to generate code for 'num_threads'
381 /// clause.
382 /// \param NumThreads An integer value of threads.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000383 virtual void emitNumThreadsClause(CodeGenFunction &CGF,
384 llvm::Value *NumThreads,
385 SourceLocation Loc);
Alexey Bataev97720002014-11-11 04:05:39 +0000386
387 /// \brief Returns address of the threadprivate variable for the current
388 /// thread.
NAKAMURA Takumicdcbfba2014-11-11 07:58:06 +0000389 /// \param VD Threadprivate variable.
Alexey Bataev97720002014-11-11 04:05:39 +0000390 /// \param VDAddr Address of the global variable \a VD.
391 /// \param Loc Location of the reference to threadprivate var.
392 /// \return Address of the threadprivate variable for the current thread.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000393 virtual llvm::Value *getAddrOfThreadPrivate(CodeGenFunction &CGF,
394 const VarDecl *VD,
395 llvm::Value *VDAddr,
396 SourceLocation Loc);
Alexey Bataev97720002014-11-11 04:05:39 +0000397
398 /// \brief Emit a code for initialization of threadprivate variable. It emits
399 /// a call to runtime library which adds initial value to the newly created
400 /// threadprivate variable (if it is not constant) and registers destructor
401 /// for the variable (if any).
402 /// \param VD Threadprivate variable.
403 /// \param VDAddr Address of the global variable \a VD.
404 /// \param Loc Location of threadprivate declaration.
405 /// \param PerformInit true if initialization expression is not constant.
406 virtual llvm::Function *
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000407 emitThreadPrivateVarDefinition(const VarDecl *VD, llvm::Value *VDAddr,
408 SourceLocation Loc, bool PerformInit,
409 CodeGenFunction *CGF = nullptr);
Alexey Bataevcc37cc12014-11-20 04:34:54 +0000410
411 /// \brief Emit flush of the variables specified in 'omp flush' directive.
412 /// \param Vars List of variables to flush.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000413 virtual void emitFlush(CodeGenFunction &CGF, ArrayRef<const Expr *> Vars,
414 SourceLocation Loc);
Alexey Bataev9959db52014-05-06 10:08:46 +0000415};
Alexey Bataev8cbe0a62015-02-26 10:27:34 +0000416
417/// \brief RAII for emitting code of CapturedStmt without function outlining.
418class InlinedOpenMPRegionRAII {
419 CodeGenFunction &CGF;
420
421public:
422 InlinedOpenMPRegionRAII(CodeGenFunction &CGF,
423 const OMPExecutableDirective &D);
424 ~InlinedOpenMPRegionRAII();
425};
Alexey Bataev23b69422014-06-18 07:08:49 +0000426} // namespace CodeGen
427} // namespace clang
Alexey Bataev9959db52014-05-06 10:08:46 +0000428
429#endif