1 //===----- CGOpenMPRuntime.h - Interface to OpenMP Runtimes -----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This provides a class for OpenMP runtime code generation.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_LIB_CODEGEN_CGOPENMPRUNTIME_H
15 #define LLVM_CLANG_LIB_CODEGEN_CGOPENMPRUNTIME_H
17 #include "clang/AST/Type.h"
18 #include "clang/Basic/OpenMPKinds.h"
19 #include "clang/Basic/SourceLocation.h"
20 #include "llvm/ADT/DenseMap.h"
21 #include "llvm/ADT/DenseSet.h"
22 #include "llvm/ADT/StringMap.h"
23 #include "llvm/IR/ValueHandle.h"
38 class OMPExecutableDirective;
43 class CodeGenFunction;
46 typedef llvm::function_ref<void(CodeGenFunction &)> RegionCodeGenTy;
48 class CGOpenMPRuntime {
50 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
70 OMPRTL__kmpc_cancel_barrier,
71 // Call to void __kmpc_barrier(ident_t *loc, kmp_int32 global_tid);
73 // Call to void __kmpc_for_static_fini(ident_t *loc, kmp_int32 global_tid);
74 OMPRTL__kmpc_for_static_fini,
75 // Call to void __kmpc_serialized_parallel(ident_t *loc, kmp_int32
77 OMPRTL__kmpc_serialized_parallel,
78 // Call to void __kmpc_end_serialized_parallel(ident_t *loc, kmp_int32
80 OMPRTL__kmpc_end_serialized_parallel,
81 // Call to void __kmpc_push_num_threads(ident_t *loc, kmp_int32 global_tid,
82 // kmp_int32 num_threads);
83 OMPRTL__kmpc_push_num_threads,
84 // Call to void __kmpc_flush(ident_t *loc);
86 // Call to kmp_int32 __kmpc_master(ident_t *, kmp_int32 global_tid);
88 // Call to void __kmpc_end_master(ident_t *, kmp_int32 global_tid);
89 OMPRTL__kmpc_end_master,
90 // Call to kmp_int32 __kmpc_omp_taskyield(ident_t *, kmp_int32 global_tid,
92 OMPRTL__kmpc_omp_taskyield,
93 // Call to kmp_int32 __kmpc_single(ident_t *, kmp_int32 global_tid);
95 // Call to void __kmpc_end_single(ident_t *, kmp_int32 global_tid);
96 OMPRTL__kmpc_end_single,
97 // Call to kmp_task_t * __kmpc_omp_task_alloc(ident_t *, kmp_int32 gtid,
98 // kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds,
99 // kmp_routine_entry_t *task_entry);
100 OMPRTL__kmpc_omp_task_alloc,
101 // Call to kmp_int32 __kmpc_omp_task(ident_t *, kmp_int32 gtid, kmp_task_t *
103 OMPRTL__kmpc_omp_task,
104 // Call to void __kmpc_copyprivate(ident_t *loc, kmp_int32 global_tid,
105 // size_t cpy_size, void *cpy_data, void(*cpy_func)(void *, void *),
107 OMPRTL__kmpc_copyprivate,
108 // Call to kmp_int32 __kmpc_reduce(ident_t *loc, kmp_int32 global_tid,
109 // kmp_int32 num_vars, size_t reduce_size, void *reduce_data, void
110 // (*reduce_func)(void *lhs_data, void *rhs_data), kmp_critical_name *lck);
112 // Call to kmp_int32 __kmpc_reduce_nowait(ident_t *loc, kmp_int32
113 // global_tid, kmp_int32 num_vars, size_t reduce_size, void *reduce_data,
114 // void (*reduce_func)(void *lhs_data, void *rhs_data), kmp_critical_name
116 OMPRTL__kmpc_reduce_nowait,
117 // Call to void __kmpc_end_reduce(ident_t *loc, kmp_int32 global_tid,
118 // kmp_critical_name *lck);
119 OMPRTL__kmpc_end_reduce,
120 // Call to void __kmpc_end_reduce_nowait(ident_t *loc, kmp_int32 global_tid,
121 // kmp_critical_name *lck);
122 OMPRTL__kmpc_end_reduce_nowait,
123 // Call to void __kmpc_omp_task_begin_if0(ident_t *, kmp_int32 gtid,
124 // kmp_task_t * new_task);
125 OMPRTL__kmpc_omp_task_begin_if0,
126 // Call to void __kmpc_omp_task_complete_if0(ident_t *, kmp_int32 gtid,
127 // kmp_task_t * new_task);
128 OMPRTL__kmpc_omp_task_complete_if0,
129 // Call to void __kmpc_ordered(ident_t *loc, kmp_int32 global_tid);
130 OMPRTL__kmpc_ordered,
131 // Call to void __kmpc_end_ordered(ident_t *loc, kmp_int32 global_tid);
132 OMPRTL__kmpc_end_ordered,
133 // Call to kmp_int32 __kmpc_omp_taskwait(ident_t *loc, kmp_int32
135 OMPRTL__kmpc_omp_taskwait,
136 // Call to void __kmpc_taskgroup(ident_t *loc, kmp_int32 global_tid);
137 OMPRTL__kmpc_taskgroup,
138 // Call to void __kmpc_end_taskgroup(ident_t *loc, kmp_int32 global_tid);
139 OMPRTL__kmpc_end_taskgroup,
140 // Call to void __kmpc_push_proc_bind(ident_t *loc, kmp_int32 global_tid,
142 OMPRTL__kmpc_push_proc_bind,
143 // Call to kmp_int32 __kmpc_omp_task_with_deps(ident_t *loc_ref, kmp_int32
144 // gtid, kmp_task_t * new_task, kmp_int32 ndeps, kmp_depend_info_t
145 // *dep_list, kmp_int32 ndeps_noalias, kmp_depend_info_t *noalias_dep_list);
146 OMPRTL__kmpc_omp_task_with_deps,
147 // Call to void __kmpc_omp_wait_deps(ident_t *loc_ref, kmp_int32
148 // gtid, kmp_int32 ndeps, kmp_depend_info_t *dep_list, kmp_int32
149 // ndeps_noalias, kmp_depend_info_t *noalias_dep_list);
150 OMPRTL__kmpc_omp_wait_deps,
151 // Call to kmp_int32 __kmpc_cancellationpoint(ident_t *loc, kmp_int32
152 // global_tid, kmp_int32 cncl_kind);
153 OMPRTL__kmpc_cancellationpoint,
154 // Call to kmp_int32 __kmpc_cancel(ident_t *loc, kmp_int32 global_tid,
155 // kmp_int32 cncl_kind);
159 /// \brief Values for bit flags used in the ident_t to describe the fields.
160 /// All enumeric elements are named and described in accordance with the code
161 /// from http://llvm.org/svn/llvm-project/openmp/trunk/runtime/src/kmp.h
162 enum OpenMPLocationFlags {
163 /// \brief Use trampoline for internal microtask.
164 OMP_IDENT_IMD = 0x01,
165 /// \brief Use c-style ident structure.
166 OMP_IDENT_KMPC = 0x02,
167 /// \brief Atomic reduction option for kmpc_reduce.
168 OMP_ATOMIC_REDUCE = 0x10,
169 /// \brief Explicit 'barrier' directive.
170 OMP_IDENT_BARRIER_EXPL = 0x20,
171 /// \brief Implicit barrier in code.
172 OMP_IDENT_BARRIER_IMPL = 0x40,
173 /// \brief Implicit barrier in 'for' directive.
174 OMP_IDENT_BARRIER_IMPL_FOR = 0x40,
175 /// \brief Implicit barrier in 'sections' directive.
176 OMP_IDENT_BARRIER_IMPL_SECTIONS = 0xC0,
177 /// \brief Implicit barrier in 'single' directive.
178 OMP_IDENT_BARRIER_IMPL_SINGLE = 0x140
181 /// \brief Default const ident_t object used for initialization of all other
183 llvm::Constant *DefaultOpenMPPSource;
184 /// \brief Map of flags and corresponding default locations.
185 typedef llvm::DenseMap<unsigned, llvm::Value *> OpenMPDefaultLocMapTy;
186 OpenMPDefaultLocMapTy OpenMPDefaultLocMap;
187 llvm::Value *getOrCreateDefaultLocation(OpenMPLocationFlags Flags);
188 /// \brief Describes ident structure that describes a source location.
189 /// All descriptions are taken from
190 /// http://llvm.org/svn/llvm-project/openmp/trunk/runtime/src/kmp.h
191 /// Original structure:
192 /// typedef struct ident {
193 /// kmp_int32 reserved_1; /**< might be used in Fortran;
195 /// kmp_int32 flags; /**< also f.flags; KMP_IDENT_xxx flags;
196 /// KMP_IDENT_KMPC identifies this union
198 /// kmp_int32 reserved_2; /**< not really used in Fortran any more;
201 /// /* but currently used for storing
202 /// region-specific ITT */
203 /// /* contextual information. */
204 ///#endif /* USE_ITT_BUILD */
205 /// kmp_int32 reserved_3; /**< source[4] in Fortran, do not use for
207 /// char const *psource; /**< String describing the source location.
208 /// The string is composed of semi-colon separated
209 // fields which describe the source file,
210 /// the function and a pair of line numbers that
211 /// delimit the construct.
214 enum IdentFieldIndex {
215 /// \brief might be used in Fortran
216 IdentField_Reserved_1,
217 /// \brief OMP_IDENT_xxx flags; OMP_IDENT_KMPC identifies this union member.
219 /// \brief Not really used in Fortran any more
220 IdentField_Reserved_2,
221 /// \brief Source[4] in Fortran, do not use for C++
222 IdentField_Reserved_3,
223 /// \brief String describing the source location. The string is composed of
224 /// semi-colon separated fields which describe the source file, the function
225 /// and a pair of line numbers that delimit the construct.
228 llvm::StructType *IdentTy;
229 /// \brief Map for SourceLocation and OpenMP runtime library debug locations.
230 typedef llvm::DenseMap<unsigned, llvm::Value *> OpenMPDebugLocMapTy;
231 OpenMPDebugLocMapTy OpenMPDebugLocMap;
232 /// \brief The type for a microtask which gets passed to __kmpc_fork_call().
233 /// Original representation is:
234 /// typedef void (kmpc_micro)(kmp_int32 global_tid, kmp_int32 bound_tid,...);
235 llvm::FunctionType *Kmpc_MicroTy;
236 /// \brief Stores debug location and ThreadID for the function.
237 struct DebugLocThreadIdTy {
238 llvm::Value *DebugLoc;
239 llvm::Value *ThreadID;
241 /// \brief Map of local debug location, ThreadId and functions.
242 typedef llvm::DenseMap<llvm::Function *, DebugLocThreadIdTy>
243 OpenMPLocThreadIDMapTy;
244 OpenMPLocThreadIDMapTy OpenMPLocThreadIDMap;
245 /// \brief Type kmp_critical_name, originally defined as typedef kmp_int32
246 /// kmp_critical_name[8];
247 llvm::ArrayType *KmpCriticalNameTy;
248 /// \brief An ordered map of auto-generated variables to their unique names.
249 /// It stores variables with the following names: 1) ".gomp_critical_user_" +
250 /// <critical_section_name> + ".var" for "omp critical" directives; 2)
251 /// <mangled_name_for_global_var> + ".cache." for cache for threadprivate
253 llvm::StringMap<llvm::AssertingVH<llvm::Constant>, llvm::BumpPtrAllocator>
255 /// \brief Type typedef kmp_int32 (* kmp_routine_entry_t)(kmp_int32, void *);
256 llvm::Type *KmpRoutineEntryPtrTy;
257 QualType KmpRoutineEntryPtrQTy;
258 /// \brief Type typedef struct kmp_task {
259 /// void * shareds; /**< pointer to block of pointers to
261 /// kmp_routine_entry_t routine; /**< pointer to routine to call for
262 /// executing task */
263 /// kmp_int32 part_id; /**< part id for the task */
264 /// kmp_routine_entry_t destructors; /* pointer to function to invoke
265 /// deconstructors of firstprivate C++ objects */
267 QualType KmpTaskTQTy;
268 /// \brief Type typedef struct kmp_depend_info {
269 /// kmp_intptr_t base_addr;
275 /// } kmp_depend_info_t;
276 QualType KmpDependInfoTy;
279 /// \brief Build type kmp_routine_entry_t (if not built yet).
280 void emitKmpRoutineEntryT(QualType KmpInt32Ty);
282 /// \brief Emits object of ident_t type with info for source location.
283 /// \param Flags Flags for OpenMP location.
285 llvm::Value *emitUpdateLocation(CodeGenFunction &CGF, SourceLocation Loc,
286 OpenMPLocationFlags Flags = OMP_IDENT_KMPC);
288 /// \brief Returns pointer to ident_t type.
289 llvm::Type *getIdentTyPointerTy();
291 /// \brief Returns pointer to kmpc_micro type.
292 llvm::Type *getKmpc_MicroPointerTy();
294 /// \brief Returns specified OpenMP runtime function.
295 /// \param Function OpenMP runtime function.
296 /// \return Specified function.
297 llvm::Constant *createRuntimeFunction(OpenMPRTLFunction Function);
299 /// \brief Returns __kmpc_for_static_init_* runtime function for the specified
300 /// size \a IVSize and sign \a IVSigned.
301 llvm::Constant *createForStaticInitFunction(unsigned IVSize, bool IVSigned);
303 /// \brief Returns __kmpc_dispatch_init_* runtime function for the specified
304 /// size \a IVSize and sign \a IVSigned.
305 llvm::Constant *createDispatchInitFunction(unsigned IVSize, bool IVSigned);
307 /// \brief Returns __kmpc_dispatch_next_* runtime function for the specified
308 /// size \a IVSize and sign \a IVSigned.
309 llvm::Constant *createDispatchNextFunction(unsigned IVSize, bool IVSigned);
311 /// \brief Returns __kmpc_dispatch_fini_* runtime function for the specified
312 /// size \a IVSize and sign \a IVSigned.
313 llvm::Constant *createDispatchFiniFunction(unsigned IVSize, bool IVSigned);
315 /// \brief If the specified mangled name is not in the module, create and
316 /// return threadprivate cache object. This object is a pointer's worth of
317 /// storage that's reserved for use by the OpenMP runtime.
318 /// \param VD Threadprivate variable.
319 /// \return Cache variable for the specified threadprivate.
320 llvm::Constant *getOrCreateThreadPrivateCache(const VarDecl *VD);
322 /// \brief Emits address of the word in a memory where current thread id is
324 virtual llvm::Value *emitThreadIDAddress(CodeGenFunction &CGF,
327 /// \brief Gets thread id value for the current thread.
329 llvm::Value *getThreadID(CodeGenFunction &CGF, SourceLocation Loc);
331 /// \brief Gets (if variable with the given name already exist) or creates
332 /// internal global variable with the specified Name. The created variable has
333 /// linkage CommonLinkage by default and is initialized by null value.
334 /// \param Ty Type of the global variable. If it is exist already the type
335 /// must be the same.
336 /// \param Name Name of the variable.
337 llvm::Constant *getOrCreateInternalVariable(llvm::Type *Ty,
338 const llvm::Twine &Name);
340 /// \brief Set of threadprivate variables with the generated initializer.
341 llvm::DenseSet<const VarDecl *> ThreadPrivateWithDefinition;
343 /// \brief Emits initialization code for the threadprivate variables.
344 /// \param VDAddr Address of the global variable \a VD.
345 /// \param Ctor Pointer to a global init function for \a VD.
346 /// \param CopyCtor Pointer to a global copy function for \a VD.
347 /// \param Dtor Pointer to a global destructor function for \a VD.
348 /// \param Loc Location of threadprivate declaration.
349 void emitThreadPrivateVarInit(CodeGenFunction &CGF, llvm::Value *VDAddr,
350 llvm::Value *Ctor, llvm::Value *CopyCtor,
351 llvm::Value *Dtor, SourceLocation Loc);
353 /// \brief Returns corresponding lock object for the specified critical region
354 /// name. If the lock object does not exist it is created, otherwise the
355 /// reference to the existing copy is returned.
356 /// \param CriticalName Name of the critical region.
358 llvm::Value *getCriticalRegionLock(StringRef CriticalName);
361 explicit CGOpenMPRuntime(CodeGenModule &CGM);
362 virtual ~CGOpenMPRuntime() {}
363 virtual void clear();
365 /// \brief Emits outlined function for the specified OpenMP parallel directive
366 /// \a D. This outlined function has type void(*)(kmp_int32 *ThreadID,
367 /// kmp_int32 BoundID, struct context_vars*).
368 /// \param D OpenMP directive.
369 /// \param ThreadIDVar Variable for thread id in the current OpenMP region.
370 /// \param InnermostKind Kind of innermost directive (for simple directives it
371 /// is a directive itself, for combined - its innermost directive).
372 /// \param CodeGen Code generation sequence for the \a D directive.
373 virtual llvm::Value *emitParallelOutlinedFunction(
374 const OMPExecutableDirective &D, const VarDecl *ThreadIDVar,
375 OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen);
377 /// \brief Emits outlined function for the OpenMP task directive \a D. This
378 /// outlined function has type void(*)(kmp_int32 ThreadID, kmp_int32
379 /// PartID, struct context_vars*).
380 /// \param D OpenMP directive.
381 /// \param ThreadIDVar Variable for thread id in the current OpenMP region.
382 /// \param InnermostKind Kind of innermost directive (for simple directives it
383 /// is a directive itself, for combined - its innermost directive).
384 /// \param CodeGen Code generation sequence for the \a D directive.
386 virtual llvm::Value *emitTaskOutlinedFunction(
387 const OMPExecutableDirective &D, const VarDecl *ThreadIDVar,
388 OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen);
390 /// \brief Cleans up references to the objects in finished function.
392 void functionFinished(CodeGenFunction &CGF);
394 /// \brief Emits code for parallel or serial call of the \a OutlinedFn with
395 /// variables captured in a record which address is stored in \a
397 /// \param OutlinedFn Outlined function to be run in parallel threads. Type of
398 /// this function is void(*)(kmp_int32 *, kmp_int32, struct context_vars*).
399 /// \param CapturedStruct A pointer to the record with the references to
400 /// variables used in \a OutlinedFn function.
401 /// \param IfCond Condition in the associated 'if' clause, if it was
402 /// specified, nullptr otherwise.
404 virtual void emitParallelCall(CodeGenFunction &CGF, SourceLocation Loc,
405 llvm::Value *OutlinedFn,
406 llvm::Value *CapturedStruct,
409 /// \brief Emits a critical region.
410 /// \param CriticalName Name of the critical region.
411 /// \param CriticalOpGen Generator for the statement associated with the given
413 virtual void emitCriticalRegion(CodeGenFunction &CGF, StringRef CriticalName,
414 const RegionCodeGenTy &CriticalOpGen,
417 /// \brief Emits a master region.
418 /// \param MasterOpGen Generator for the statement associated with the given
420 virtual void emitMasterRegion(CodeGenFunction &CGF,
421 const RegionCodeGenTy &MasterOpGen,
424 /// \brief Emits code for a taskyield directive.
425 virtual void emitTaskyieldCall(CodeGenFunction &CGF, SourceLocation Loc);
427 /// \brief Emit a taskgroup region.
428 /// \param TaskgroupOpGen Generator for the statement associated with the
429 /// given taskgroup region.
430 virtual void emitTaskgroupRegion(CodeGenFunction &CGF,
431 const RegionCodeGenTy &TaskgroupOpGen,
434 /// \brief Emits a single region.
435 /// \param SingleOpGen Generator for the statement associated with the given
437 virtual void emitSingleRegion(CodeGenFunction &CGF,
438 const RegionCodeGenTy &SingleOpGen,
440 ArrayRef<const Expr *> CopyprivateVars,
441 ArrayRef<const Expr *> DestExprs,
442 ArrayRef<const Expr *> SrcExprs,
443 ArrayRef<const Expr *> AssignmentOps);
445 /// \brief Emit an ordered region.
446 /// \param OrderedOpGen Generator for the statement associated with the given
448 virtual void emitOrderedRegion(CodeGenFunction &CGF,
449 const RegionCodeGenTy &OrderedOpGen,
452 /// \brief Emit an implicit/explicit barrier for OpenMP threads.
453 /// \param Kind Directive for which this implicit barrier call must be
454 /// generated. Must be OMPD_barrier for explicit barrier generation.
455 /// \param CheckForCancel true if check for possible cancellation must be
456 /// performed, false otherwise.
458 virtual void emitBarrierCall(CodeGenFunction &CGF, SourceLocation Loc,
459 OpenMPDirectiveKind Kind,
460 bool CheckForCancel = true);
462 /// \brief Check if the specified \a ScheduleKind is static non-chunked.
463 /// This kind of worksharing directive is emitted without outer loop.
464 /// \param ScheduleKind Schedule kind specified in the 'schedule' clause.
465 /// \param Chunked True if chunk is specified in the clause.
467 virtual bool isStaticNonchunked(OpenMPScheduleClauseKind ScheduleKind,
470 /// \brief Check if the specified \a ScheduleKind is dynamic.
471 /// This kind of worksharing directive is emitted without outer loop.
472 /// \param ScheduleKind Schedule Kind specified in the 'schedule' clause.
474 virtual bool isDynamic(OpenMPScheduleClauseKind ScheduleKind) const;
476 /// \brief Call the appropriate runtime routine to initialize it before start
479 /// Depending on the loop schedule, it is nesessary to call some runtime
480 /// routine before start of the OpenMP loop to get the loop upper / lower
481 /// bounds \a LB and \a UB and stride \a ST.
483 /// \param CGF Reference to current CodeGenFunction.
484 /// \param Loc Clang source location.
485 /// \param SchedKind Schedule kind, specified by the 'schedule' clause.
486 /// \param IVSize Size of the iteration variable in bits.
487 /// \param IVSigned Sign of the interation variable.
488 /// \param Ordered true if loop is ordered, false otherwise.
489 /// \param IL Address of the output variable in which the flag of the
490 /// last iteration is returned.
491 /// \param LB Address of the output variable in which the lower iteration
492 /// number is returned.
493 /// \param UB Address of the output variable in which the upper iteration
494 /// number is returned.
495 /// \param ST Address of the output variable in which the stride value is
496 /// returned nesessary to generated the static_chunked scheduled loop.
497 /// \param Chunk Value of the chunk for the static_chunked scheduled loop.
498 /// For the default (nullptr) value, the chunk 1 will be used.
500 virtual void emitForInit(CodeGenFunction &CGF, SourceLocation Loc,
501 OpenMPScheduleClauseKind SchedKind, unsigned IVSize,
502 bool IVSigned, bool Ordered, llvm::Value *IL,
503 llvm::Value *LB, llvm::Value *UB, llvm::Value *ST,
504 llvm::Value *Chunk = nullptr);
506 /// \brief Call the appropriate runtime routine to notify that we finished
507 /// iteration of the ordered loop with the dynamic scheduling.
509 /// \param CGF Reference to current CodeGenFunction.
510 /// \param Loc Clang source location.
511 /// \param IVSize Size of the iteration variable in bits.
512 /// \param IVSigned Sign of the interation variable.
514 virtual void emitForOrderedIterationEnd(CodeGenFunction &CGF,
515 SourceLocation Loc, unsigned IVSize,
518 /// \brief Call the appropriate runtime routine to notify that we finished
519 /// all the work with current loop.
521 /// \param CGF Reference to current CodeGenFunction.
522 /// \param Loc Clang source location.
524 virtual void emitForStaticFinish(CodeGenFunction &CGF, SourceLocation Loc);
526 /// Call __kmpc_dispatch_next(
527 /// ident_t *loc, kmp_int32 tid, kmp_int32 *p_lastiter,
528 /// kmp_int[32|64] *p_lower, kmp_int[32|64] *p_upper,
529 /// kmp_int[32|64] *p_stride);
530 /// \param IVSize Size of the iteration variable in bits.
531 /// \param IVSigned Sign of the interation variable.
532 /// \param IL Address of the output variable in which the flag of the
533 /// last iteration is returned.
534 /// \param LB Address of the output variable in which the lower iteration
535 /// number is returned.
536 /// \param UB Address of the output variable in which the upper iteration
537 /// number is returned.
538 /// \param ST Address of the output variable in which the stride value is
540 virtual llvm::Value *emitForNext(CodeGenFunction &CGF, SourceLocation Loc,
541 unsigned IVSize, bool IVSigned,
542 llvm::Value *IL, llvm::Value *LB,
543 llvm::Value *UB, llvm::Value *ST);
545 /// \brief Emits call to void __kmpc_push_num_threads(ident_t *loc, kmp_int32
546 /// global_tid, kmp_int32 num_threads) to generate code for 'num_threads'
548 /// \param NumThreads An integer value of threads.
549 virtual void emitNumThreadsClause(CodeGenFunction &CGF,
550 llvm::Value *NumThreads,
553 /// \brief Emit call to void __kmpc_push_proc_bind(ident_t *loc, kmp_int32
554 /// global_tid, int proc_bind) to generate code for 'proc_bind' clause.
555 virtual void emitProcBindClause(CodeGenFunction &CGF,
556 OpenMPProcBindClauseKind ProcBind,
559 /// \brief Returns address of the threadprivate variable for the current
561 /// \param VD Threadprivate variable.
562 /// \param VDAddr Address of the global variable \a VD.
563 /// \param Loc Location of the reference to threadprivate var.
564 /// \return Address of the threadprivate variable for the current thread.
565 virtual llvm::Value *getAddrOfThreadPrivate(CodeGenFunction &CGF,
570 /// \brief Emit a code for initialization of threadprivate variable. It emits
571 /// a call to runtime library which adds initial value to the newly created
572 /// threadprivate variable (if it is not constant) and registers destructor
573 /// for the variable (if any).
574 /// \param VD Threadprivate variable.
575 /// \param VDAddr Address of the global variable \a VD.
576 /// \param Loc Location of threadprivate declaration.
577 /// \param PerformInit true if initialization expression is not constant.
578 virtual llvm::Function *
579 emitThreadPrivateVarDefinition(const VarDecl *VD, llvm::Value *VDAddr,
580 SourceLocation Loc, bool PerformInit,
581 CodeGenFunction *CGF = nullptr);
583 /// \brief Emit flush of the variables specified in 'omp flush' directive.
584 /// \param Vars List of variables to flush.
585 virtual void emitFlush(CodeGenFunction &CGF, ArrayRef<const Expr *> Vars,
588 /// \brief Emit task region for the task directive. The task region is
589 /// emitted in several steps:
590 /// 1. Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32
591 /// gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds,
592 /// kmp_routine_entry_t *task_entry). Here task_entry is a pointer to the
594 /// kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) {
595 /// TaskFunction(gtid, tt->part_id, tt->shareds);
598 /// 2. Copy a list of shared variables to field shareds of the resulting
599 /// structure kmp_task_t returned by the previous call (if any).
600 /// 3. Copy a pointer to destructions function to field destructions of the
601 /// resulting structure kmp_task_t.
602 /// 4. Emit a call to kmp_int32 __kmpc_omp_task(ident_t *, kmp_int32 gtid,
603 /// kmp_task_t *new_task), where new_task is a resulting structure from
605 /// \param D Current task directive.
606 /// \param Tied true if the task is tied (the task is tied to the thread that
607 /// can suspend its task region), false - untied (the task is not tied to any
609 /// \param Final Contains either constant bool value, or llvm::Value * of i1
610 /// type for final clause. If the value is true, the task forces all of its
611 /// child tasks to become final and included tasks.
612 /// \param TaskFunction An LLVM function with type void (*)(i32 /*gtid*/, i32
613 /// /*part_id*/, captured_struct */*__context*/);
614 /// \param SharedsTy A type which contains references the shared variables.
615 /// \param Shareds Context with the list of shared variables from the \p
617 /// \param IfCond Not a nullptr if 'if' clause was specified, nullptr
619 /// \param PrivateVars List of references to private variables for the task
621 /// \param PrivateCopies List of private copies for each private variable in
623 /// \param FirstprivateVars List of references to private variables for the
625 /// \param FirstprivateCopies List of private copies for each private variable
626 /// in \p FirstprivateVars.
627 /// \param FirstprivateInits List of references to auto generated variables
628 /// used for initialization of a single array element. Used if firstprivate
629 /// variable is of array type.
630 /// \param Dependences List of dependences for the 'task' construct, including
631 /// original expression and dependency type.
632 virtual void emitTaskCall(
633 CodeGenFunction &CGF, SourceLocation Loc, const OMPExecutableDirective &D,
634 bool Tied, llvm::PointerIntPair<llvm::Value *, 1, bool> Final,
635 llvm::Value *TaskFunction, QualType SharedsTy, llvm::Value *Shareds,
636 const Expr *IfCond, ArrayRef<const Expr *> PrivateVars,
637 ArrayRef<const Expr *> PrivateCopies,
638 ArrayRef<const Expr *> FirstprivateVars,
639 ArrayRef<const Expr *> FirstprivateCopies,
640 ArrayRef<const Expr *> FirstprivateInits,
641 ArrayRef<std::pair<OpenMPDependClauseKind, const Expr *>> Dependences);
643 /// \brief Emit code for the directive that does not require outlining.
645 /// \param InnermostKind Kind of innermost directive (for simple directives it
646 /// is a directive itself, for combined - its innermost directive).
647 /// \param CodeGen Code generation sequence for the \a D directive.
648 virtual void emitInlinedDirective(CodeGenFunction &CGF,
649 OpenMPDirectiveKind InnermostKind,
650 const RegionCodeGenTy &CodeGen);
651 /// \brief Emit a code for reduction clause. Next code should be emitted for
655 /// static kmp_critical_name lock = { 0 };
657 /// void reduce_func(void *lhs[<n>], void *rhs[<n>]) {
659 /// *(Type<i>*)lhs[i] = RedOp<i>(*(Type<i>*)lhs[i], *(Type<i>*)rhs[i]);
664 /// void *RedList[<n>] = {&<RHSExprs>[0], ..., &<RHSExprs>[<n>-1]};
665 /// switch (__kmpc_reduce{_nowait}(<loc>, <gtid>, <n>, sizeof(RedList),
666 /// RedList, reduce_func, &<lock>)) {
669 /// <LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]);
671 /// __kmpc_end_reduce{_nowait}(<loc>, <gtid>, &<lock>);
675 /// Atomic(<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]));
682 /// \param LHSExprs List of LHS in \a ReductionOps reduction operations.
683 /// \param RHSExprs List of RHS in \a ReductionOps reduction operations.
684 /// \param ReductionOps List of reduction operations in form 'LHS binop RHS'
685 /// or 'operator binop(LHS, RHS)'.
686 /// \param WithNowait true if parent directive has also nowait clause, false
688 virtual void emitReduction(CodeGenFunction &CGF, SourceLocation Loc,
689 ArrayRef<const Expr *> LHSExprs,
690 ArrayRef<const Expr *> RHSExprs,
691 ArrayRef<const Expr *> ReductionOps,
692 bool WithNowait, bool SimpleReduction);
694 /// \brief Emit code for 'taskwait' directive.
695 virtual void emitTaskwaitCall(CodeGenFunction &CGF, SourceLocation Loc);
697 /// \brief Emit code for 'cancellation point' construct.
698 /// \param CancelRegion Region kind for which the cancellation point must be
701 virtual void emitCancellationPointCall(CodeGenFunction &CGF,
703 OpenMPDirectiveKind CancelRegion);
705 /// \brief Emit code for 'cancel' construct.
706 /// \param CancelRegion Region kind for which the cancel must be emitted.
708 virtual void emitCancelCall(CodeGenFunction &CGF, SourceLocation Loc,
709 OpenMPDirectiveKind CancelRegion);
712 } // namespace CodeGen