clang 24.0.0git
CGOpenMPRuntime.h
Go to the documentation of this file.
1//===----- CGOpenMPRuntime.h - Interface to OpenMP Runtimes -----*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This provides a class for OpenMP runtime code generation.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_LIB_CODEGEN_CGOPENMPRUNTIME_H
14#define LLVM_CLANG_LIB_CODEGEN_CGOPENMPRUNTIME_H
15
16#include "CGValue.h"
19#include "clang/AST/Type.h"
22#include "llvm/ADT/DenseMap.h"
23#include "llvm/ADT/PointerIntPair.h"
24#include "llvm/ADT/SmallPtrSet.h"
25#include "llvm/ADT/StringMap.h"
26#include "llvm/ADT/StringSet.h"
27#include "llvm/Frontend/OpenMP/OMPConstants.h"
28#include "llvm/Frontend/OpenMP/OMPIRBuilder.h"
29#include "llvm/IR/Function.h"
30#include "llvm/IR/ValueHandle.h"
31#include "llvm/Support/AtomicOrdering.h"
32
33namespace llvm {
34class ArrayType;
35class Constant;
36class FunctionType;
37class GlobalVariable;
38class Type;
39class Value;
40class OpenMPIRBuilder;
41} // namespace llvm
42
43namespace clang {
44class Expr;
45class OMPDependClause;
46class OMPExecutableDirective;
47class OMPLoopDirective;
48class VarDecl;
50
51namespace CodeGen {
52class Address;
53class CodeGenFunction;
54class CodeGenModule;
55
56/// A basic class for pre|post-action for advanced codegen sequence for OpenMP
57/// region.
59public:
60 explicit PrePostActionTy() {}
61 virtual void Enter(CodeGenFunction &CGF) {}
62 virtual void Exit(CodeGenFunction &CGF) {}
63 virtual ~PrePostActionTy() {}
64};
65
66/// Class provides a way to call simple version of codegen for OpenMP region, or
67/// an advanced with possible pre|post-actions in codegen.
68class RegionCodeGenTy final {
69 intptr_t CodeGen;
70 typedef void (*CodeGenTy)(intptr_t, CodeGenFunction &, PrePostActionTy &);
71 CodeGenTy Callback;
72 mutable PrePostActionTy *PrePostAction;
73 RegionCodeGenTy() = delete;
74 template <typename Callable>
75 static void CallbackFn(intptr_t CodeGen, CodeGenFunction &CGF,
76 PrePostActionTy &Action) {
77 return (*reinterpret_cast<Callable *>(CodeGen))(CGF, Action);
78 }
79
80public:
81 template <typename Callable>
83 Callable &&CodeGen,
84 std::enable_if_t<!std::is_same<std::remove_reference_t<Callable>,
85 RegionCodeGenTy>::value> * = nullptr)
86 : CodeGen(reinterpret_cast<intptr_t>(&CodeGen)),
87 Callback(CallbackFn<std::remove_reference_t<Callable>>),
88 PrePostAction(nullptr) {}
89 void setAction(PrePostActionTy &Action) const { PrePostAction = &Action; }
90 void operator()(CodeGenFunction &CGF) const;
91};
92
127
128/// Class intended to support codegen of all kind of the reduction clauses.
130private:
131 /// Data required for codegen of reduction clauses.
132 struct ReductionData {
133 /// Reference to the item shared between tasks to reduce into.
134 const Expr *Shared = nullptr;
135 /// Reference to the original item.
136 const Expr *Ref = nullptr;
137 /// Helper expression for generation of private copy.
138 const Expr *Private = nullptr;
139 /// Helper expression for generation reduction operation.
140 const Expr *ReductionOp = nullptr;
141 ReductionData(const Expr *Shared, const Expr *Ref, const Expr *Private,
142 const Expr *ReductionOp)
143 : Shared(Shared), Ref(Ref), Private(Private), ReductionOp(ReductionOp) {
144 }
145 };
146 /// List of reduction-based clauses.
148
149 /// List of addresses of shared variables/expressions.
150 SmallVector<std::pair<LValue, LValue>, 4> SharedAddresses;
151 /// List of addresses of original variables/expressions.
153 /// Sizes of the reduction items in chars.
155 /// Base declarations for the reduction items.
157
158 /// Emits lvalue for shared expression.
159 LValue emitSharedLValue(CodeGenFunction &CGF, const Expr *E);
160 /// Emits upper bound for shared expression (if array section).
161 LValue emitSharedLValueUB(CodeGenFunction &CGF, const Expr *E);
162 /// Performs aggregate initialization.
163 /// \param N Number of reduction item in the common list.
164 /// \param PrivateAddr Address of the corresponding private item.
165 /// \param SharedAddr Address of the original shared variable.
166 /// \param DRD Declare reduction construct used for reduction item.
167 void emitAggregateInitialization(CodeGenFunction &CGF, unsigned N,
168 Address PrivateAddr, Address SharedAddr,
169 const OMPDeclareReductionDecl *DRD);
170
171public:
174 ArrayRef<const Expr *> ReductionOps);
175 /// Emits lvalue for the shared and original reduction item.
176 /// \param N Number of the reduction item.
177 void emitSharedOrigLValue(CodeGenFunction &CGF, unsigned N);
178 /// Emits the code for the variable-modified type, if required.
179 /// \param N Number of the reduction item.
180 void emitAggregateType(CodeGenFunction &CGF, unsigned N);
181 /// Emits the code for the variable-modified type, if required.
182 /// \param N Number of the reduction item.
183 /// \param Size Size of the type in chars.
184 void emitAggregateType(CodeGenFunction &CGF, unsigned N, llvm::Value *Size);
185 /// Performs initialization of the private copy for the reduction item.
186 /// \param N Number of the reduction item.
187 /// \param PrivateAddr Address of the corresponding private item.
188 /// \param DefaultInit Default initialization sequence that should be
189 /// performed if no reduction specific initialization is found.
190 /// \param SharedAddr Address of the original shared variable.
191 void
192 emitInitialization(CodeGenFunction &CGF, unsigned N, Address PrivateAddr,
193 Address SharedAddr,
194 llvm::function_ref<bool(CodeGenFunction &)> DefaultInit);
195 /// Returns true if the private copy requires cleanups.
196 bool needCleanups(unsigned N);
197 /// Emits cleanup code for the reduction item.
198 /// \param N Number of the reduction item.
199 /// \param PrivateAddr Address of the corresponding private item.
200 void emitCleanups(CodeGenFunction &CGF, unsigned N, Address PrivateAddr);
201 /// Adjusts \p PrivatedAddr for using instead of the original variable
202 /// address in normal operations.
203 /// \param N Number of the reduction item.
204 /// \param PrivateAddr Address of the corresponding private item.
206 Address PrivateAddr);
207 /// Returns LValue for the reduction item.
208 LValue getSharedLValue(unsigned N) const { return SharedAddresses[N].first; }
209 /// Returns LValue for the original reduction item.
210 LValue getOrigLValue(unsigned N) const { return OrigAddresses[N].first; }
211 /// Returns the size of the reduction item (in chars and total number of
212 /// elements in the item), or nullptr, if the size is a constant.
213 std::pair<llvm::Value *, llvm::Value *> getSizes(unsigned N) const {
214 return Sizes[N];
215 }
216 /// Returns the base declaration of the reduction item.
217 const VarDecl *getBaseDecl(unsigned N) const { return BaseDecls[N]; }
218 /// Returns the base declaration of the reduction item.
219 const Expr *getRefExpr(unsigned N) const { return ClausesData[N].Ref; }
220 /// Returns true if the initialization of the reduction item uses initializer
221 /// from declare reduction construct.
222 bool usesReductionInitializer(unsigned N) const;
223 /// Return the type of the private item.
224 QualType getPrivateType(unsigned N) const {
225 return cast<VarDecl>(cast<DeclRefExpr>(ClausesData[N].Private)->getDecl())
226 ->getType();
227 }
228};
229
231public:
232 /// Allows to disable automatic handling of functions used in target regions
233 /// as those marked as `omp declare target`.
235 CodeGenModule &CGM;
236 bool SavedShouldMarkAsGlobal = false;
237
238 public:
241 };
242
243 /// Manages list of nontemporal decls for the specified directive.
245 CodeGenModule &CGM;
246 const bool NeedToPush;
247
248 public:
251 };
252
253 /// Manages list of nontemporal decls for the specified directive.
255 CodeGenModule &CGM;
256 const bool NeedToPush;
257
258 public:
260 CodeGenFunction &CGF,
261 const llvm::MapVector<CanonicalDeclPtr<const VarDecl>,
262 std::pair<Address, Address>> &LocalVars);
264 };
265
266 /// Maps the expression for the lastprivate variable to the global copy used
267 /// to store new value because original variables are not mapped in inner
268 /// parallel regions. Only private copies are captured but we need also to
269 /// store private copy in shared address.
270 /// Also, stores the expression for the private loop counter and it
271 /// threaprivate name.
273 llvm::MapVector<CanonicalDeclPtr<const Decl>, SmallString<16>>
276 llvm::Function *Fn = nullptr;
277 bool Disabled = false;
278 };
279 /// Manages list of lastprivate conditional decls for the specified directive.
280 class LastprivateConditionalRAII {
281 enum class ActionToDo {
282 DoNotPush,
283 PushAsLastprivateConditional,
284 DisableLastprivateConditional,
285 };
286 CodeGenModule &CGM;
287 ActionToDo Action = ActionToDo::DoNotPush;
288
289 /// Check and try to disable analysis of inner regions for changes in
290 /// lastprivate conditional.
291 void tryToDisableInnerAnalysis(const OMPExecutableDirective &S,
292 llvm::DenseSet<CanonicalDeclPtr<const Decl>>
293 &NeedToAddForLPCsAsDisabled) const;
294
295 LastprivateConditionalRAII(CodeGenFunction &CGF,
296 const OMPExecutableDirective &S);
297
298 public:
299 explicit LastprivateConditionalRAII(CodeGenFunction &CGF,
300 const OMPExecutableDirective &S,
301 LValue IVLVal);
302 static LastprivateConditionalRAII disable(CodeGenFunction &CGF,
303 const OMPExecutableDirective &S);
305 };
306
307 llvm::OpenMPIRBuilder &getOMPBuilder() { return OMPBuilder; }
308
309protected:
311
312 /// An OpenMP-IR-Builder instance.
313 llvm::OpenMPIRBuilder OMPBuilder;
314
315 /// Helper to determine the min/max number of threads/teams for \p D.
318 llvm::OpenMPIRBuilder::TargetKernelDefaultAttrs &Attrs);
319
320 /// Helper to emit outlined function for 'target' directive.
321 /// \param D Directive to emit.
322 /// \param ParentName Name of the function that encloses the target region.
323 /// \param OutlinedFn Outlined function value to be defined by this call.
324 /// \param OutlinedFnID Outlined function ID value to be defined by this call.
325 /// \param IsOffloadEntry True if the outlined function is an offload entry.
326 /// \param CodeGen Lambda codegen specific to an accelerator device.
327 /// An outlined function may not be an entry if, e.g. the if clause always
328 /// evaluates to false.
330 StringRef ParentName,
331 llvm::Function *&OutlinedFn,
332 llvm::Constant *&OutlinedFnID,
333 bool IsOffloadEntry,
334 const RegionCodeGenTy &CodeGen);
335
336 /// Returns pointer to ident_t type.
337 llvm::Type *getIdentTyPointerTy();
338
339 /// Gets thread id value for the current thread.
340 ///
341 llvm::Value *getThreadID(CodeGenFunction &CGF, SourceLocation Loc);
342
343 /// Get the function name of an outlined region.
344 std::string getOutlinedHelperName(StringRef Name) const;
345 std::string getOutlinedHelperName(CodeGenFunction &CGF) const;
346
347 /// Get the function name of a reduction function.
348 std::string getReductionFuncName(StringRef Name) const;
349
350 /// Emits \p Callee function call with arguments \p Args with location \p Loc.
352 llvm::FunctionCallee Callee,
353 ArrayRef<llvm::Value *> Args = {}) const;
354
355 /// Emits address of the word in a memory where current thread id is
356 /// stored.
358
360 bool AtCurrentPoint = false);
362
363 /// Check if the default location must be constant.
364 /// Default is false to support OMPT/OMPD.
365 virtual bool isDefaultLocationConstant() const { return false; }
366
367 /// Returns additional flags that can be stored in reserved_2 field of the
368 /// default location.
369 virtual unsigned getDefaultLocationReserved2Flags() const { return 0; }
370
371 /// Returns default flags for the barriers depending on the directive, for
372 /// which this barier is going to be emitted.
374
375 /// Get the LLVM type for the critical name.
376 llvm::ArrayType *getKmpCriticalNameTy() const {return KmpCriticalNameTy;}
377
378 /// Returns corresponding lock object for the specified critical region
379 /// name. If the lock object does not exist it is created, otherwise the
380 /// reference to the existing copy is returned.
381 /// \param CriticalName Name of the critical region.
382 ///
383 llvm::Value *getCriticalRegionLock(StringRef CriticalName);
384
385protected:
386 /// Map for SourceLocation and OpenMP runtime library debug locations.
387 typedef llvm::DenseMap<SourceLocation, llvm::Value *> OpenMPDebugLocMapTy;
389 /// Stores debug location and ThreadID for the function.
391 llvm::Value *DebugLoc;
392 llvm::Value *ThreadID;
393 /// Insert point for the service instructions.
394 llvm::AssertingVH<llvm::Instruction> ServiceInsertPt = nullptr;
395 };
396 /// Map of local debug location, ThreadId and functions.
397 typedef llvm::DenseMap<llvm::Function *, DebugLocThreadIdTy>
400 /// Map of UDRs and corresponding combiner/initializer.
401 typedef llvm::DenseMap<const OMPDeclareReductionDecl *,
402 std::pair<llvm::Function *, llvm::Function *>>
405 /// Map of functions and locally defined UDRs.
406 typedef llvm::DenseMap<llvm::Function *,
410 /// Map from the user-defined mapper declaration to its corresponding
411 /// functions.
412 llvm::DenseMap<const OMPDeclareMapperDecl *, llvm::Function *> UDMMap;
413 /// Map of functions and their local user-defined mappers.
415 llvm::DenseMap<llvm::Function *,
418 /// Maps local variables marked as lastprivate conditional to their internal
419 /// types.
420 llvm::DenseMap<llvm::Function *,
421 llvm::DenseMap<CanonicalDeclPtr<const Decl>,
422 std::tuple<QualType, const FieldDecl *,
423 const FieldDecl *, LValue>>>
425 /// Maps function to the position of the untied task locals stack.
426 llvm::DenseMap<llvm::Function *, unsigned> FunctionToUntiedTaskStackMap;
427 /// Type kmp_critical_name, originally defined as typedef kmp_int32
428 /// kmp_critical_name[8];
429 llvm::ArrayType *KmpCriticalNameTy;
430 /// An ordered map of auto-generated variables to their unique names.
431 /// It stores variables with the following names: 1) ".gomp_critical_user_" +
432 /// <critical_section_name> + ".var" for "omp critical" directives; 2)
433 /// <mangled_name_for_global_var> + ".cache." for cache for threadprivate
434 /// variables.
435 llvm::StringMap<llvm::AssertingVH<llvm::GlobalVariable>,
436 llvm::BumpPtrAllocator> InternalVars;
437 /// Type typedef kmp_int32 (* kmp_routine_entry_t)(kmp_int32, void *);
438 llvm::Type *KmpRoutineEntryPtrTy = nullptr;
440 /// Type typedef struct kmp_task {
441 /// void * shareds; /**< pointer to block of pointers to
442 /// shared vars */
443 /// kmp_routine_entry_t routine; /**< pointer to routine to call for
444 /// executing task */
445 /// kmp_int32 part_id; /**< part id for the task */
446 /// kmp_routine_entry_t destructors; /* pointer to function to invoke
447 /// deconstructors of firstprivate C++ objects */
448 /// } kmp_task_t;
450 /// Saved kmp_task_t for task directive.
452 /// Saved kmp_task_t for taskloop-based directive.
454 /// Type typedef struct kmp_depend_info {
455 /// kmp_intptr_t base_addr;
456 /// size_t len;
457 /// struct {
458 /// bool in:1;
459 /// bool out:1;
460 /// } flags;
461 /// } kmp_depend_info_t;
463 /// Type typedef struct kmp_task_affinity_info {
464 /// kmp_intptr_t base_addr;
465 /// size_t len;
466 /// struct {
467 /// bool flag1 : 1;
468 /// bool flag2 : 1;
469 /// kmp_int32 reserved : 30;
470 /// } flags;
471 /// } kmp_task_affinity_info_t;
473 /// struct kmp_dim { // loop bounds info casted to kmp_int64
474 /// kmp_int64 lo; // lower
475 /// kmp_int64 up; // upper
476 /// kmp_int64 st; // stride
477 /// };
479
481 /// List of the emitted declarations.
482 llvm::DenseSet<CanonicalDeclPtr<const Decl>> AlreadyEmittedTargetDecls;
483 /// Implicitly-defined constructors already scanned for target regions; only
484 /// lambdas can hold such regions there and they compute their own parent.
486 /// List of the global variables with their addresses that should not be
487 /// emitted for the target.
488 llvm::StringMap<llvm::WeakTrackingVH> EmittedNonTargetVariables;
489
490 /// List of variables that can become declare target implicitly and, thus,
491 /// must be emitted.
492 llvm::SmallDenseSet<const VarDecl *> DeferredGlobalVariables;
493
494 using NontemporalDeclsSet = llvm::SmallDenseSet<CanonicalDeclPtr<const Decl>>;
495 /// Stack for list of declarations in current context marked as nontemporal.
496 /// The set is the union of all current stack elements.
498
500 llvm::MapVector<CanonicalDeclPtr<const VarDecl>,
501 std::pair<Address, Address>>;
503
504 /// Stack for list of addresses of declarations in current context marked as
505 /// lastprivate conditional. The set is the union of all current stack
506 /// elements.
508
509 /// Flag for keeping track of weather a requires unified_shared_memory
510 /// directive is present.
512
513 /// Atomic ordering from the omp requires directive.
514 llvm::AtomicOrdering RequiresAtomicOrdering = llvm::AtomicOrdering::Monotonic;
515
516 /// Flag for keeping track of weather a target region has been emitted.
518
519 /// Flag for keeping track of weather a device routine has been emitted.
520 /// Device routines are specific to the
522
523 /// Start scanning from statement \a S and emit all target regions
524 /// found along the way.
525 /// \param S Starting statement.
526 /// \param ParentName Name of the function declaration that is being scanned.
527 void scanForTargetRegionsFunctions(const Stmt *S, StringRef ParentName);
528
529 /// Scans the mem-initializers and the body of \a Ctor for target regions.
531 StringRef ParentName);
532
533 /// Build type kmp_routine_entry_t (if not built yet).
534 void emitKmpRoutineEntryT(QualType KmpInt32Ty);
535
536 /// If the specified mangled name is not in the module, create and
537 /// return threadprivate cache object. This object is a pointer's worth of
538 /// storage that's reserved for use by the OpenMP runtime.
539 /// \param VD Threadprivate variable.
540 /// \return Cache variable for the specified threadprivate.
541 llvm::Constant *getOrCreateThreadPrivateCache(const VarDecl *VD);
542
543 /// Set of threadprivate variables with the generated initializer.
545
546 /// Set of declare target variables with the generated initializer.
548
549 /// Emits initialization code for the threadprivate variables.
550 /// \param VDAddr Address of the global variable \a VD.
551 /// \param Ctor Pointer to a global init function for \a VD.
552 /// \param CopyCtor Pointer to a global copy function for \a VD.
553 /// \param Dtor Pointer to a global destructor function for \a VD.
554 /// \param Loc Location of threadprivate declaration.
556 llvm::Value *Ctor, llvm::Value *CopyCtor,
557 llvm::Value *Dtor, SourceLocation Loc);
558
560 llvm::Value *NewTask = nullptr;
561 llvm::Function *TaskEntry = nullptr;
562 llvm::Value *NewTaskNewTaskTTy = nullptr;
564 const RecordDecl *KmpTaskTQTyRD = nullptr;
565 llvm::Value *TaskDupFn = nullptr;
566 };
567 /// Emit task region for the task directive. The task region is emitted in
568 /// several steps:
569 /// 1. Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32
570 /// gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds,
571 /// kmp_routine_entry_t *task_entry). Here task_entry is a pointer to the
572 /// function:
573 /// kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) {
574 /// TaskFunction(gtid, tt->part_id, tt->shareds);
575 /// return 0;
576 /// }
577 /// 2. Copy a list of shared variables to field shareds of the resulting
578 /// structure kmp_task_t returned by the previous call (if any).
579 /// 3. Copy a pointer to destructions function to field destructions of the
580 /// resulting structure kmp_task_t.
581 /// \param D Current task directive.
582 /// \param TaskFunction An LLVM function with type void (*)(i32 /*gtid*/, i32
583 /// /*part_id*/, captured_struct */*__context*/);
584 /// \param SharedsTy A type which contains references the shared variables.
585 /// \param Shareds Context with the list of shared variables from the \p
586 /// TaskFunction.
587 /// \param Data Additional data for task generation like tiednsee, final
588 /// state, list of privates etc.
590 const OMPExecutableDirective &D,
591 llvm::Function *TaskFunction, QualType SharedsTy,
592 Address Shareds, const OMPTaskDataTy &Data);
593
594 /// Emit update for lastprivate conditional data.
596 StringRef UniqueDeclName, LValue LVal,
597 SourceLocation Loc);
598
599 /// Returns the number of the elements and the address of the depobj
600 /// dependency array.
601 /// \return Number of elements in depobj array and the pointer to the array of
602 /// dependencies.
603 std::pair<llvm::Value *, LValue> getDepobjElements(CodeGenFunction &CGF,
604 LValue DepobjLVal,
605 SourceLocation Loc);
606
610
612 LValue PosLVal, const OMPTaskDataTy::DependData &Data,
613 Address DependenciesArray);
614
615 /// Keep track of VTable Declarations so we don't register duplicate VTable.
616 llvm::SmallDenseMap<CXXRecordDecl *, const VarDecl *> VTableDeclMap;
617
618public:
620 virtual ~CGOpenMPRuntime() {}
621 virtual void clear();
622
623 /// Emits object of ident_t type with info for source location.
624 /// \param Flags Flags for OpenMP location.
625 /// \param EmitLoc emit source location with debug-info is off.
626 ///
628 unsigned Flags = 0, bool EmitLoc = false);
629
630 /// Emit the number of teams for a target directive. Inspect the num_teams
631 /// clause associated with a teams construct combined or closely nested
632 /// with the target directive.
633 ///
634 /// Emit a team of size one for directives such as 'target parallel' that
635 /// have no associated teams construct.
636 ///
637 /// Otherwise, return nullptr.
639 const OMPExecutableDirective &D,
640 int32_t &MinTeamsVal,
641 int32_t &MaxTeamsVal);
643 const OMPExecutableDirective &D);
644
645 /// Check for a number of threads upper bound constant value (stored in \p
646 /// UpperBound), or expression (returned). If the value is conditional (via an
647 /// if-clause), store the condition in \p CondExpr. Similarly, a potential
648 /// thread limit expression is stored in \p ThreadLimitExpr. If \p
649 /// UpperBoundOnly is true, no expression evaluation is perfomed.
652 int32_t &UpperBound, bool UpperBoundOnly,
653 llvm::Value **CondExpr = nullptr, const Expr **ThreadLimitExpr = nullptr);
654
655 /// Emit an expression that denotes the number of threads a target region
656 /// shall use. Will generate "i32 0" to allow the runtime to choose.
657 llvm::Value *
659 const OMPExecutableDirective &D);
660
661 /// Return the trip count of loops associated with constructs / 'target teams
662 /// distribute' and 'teams distribute parallel for'. \param SizeEmitter Emits
663 /// the int64 value for the number of iterations of the associated loop.
664 llvm::Value *emitTargetNumIterationsCall(
666 llvm::function_ref<llvm::Value *(CodeGenFunction &CGF,
667 const OMPLoopDirective &D)>
668 SizeEmitter);
669
670 /// Returns true if the current target is a GPU.
671 virtual bool isGPU() const { return false; }
672
673 /// Check if the variable length declaration is delayed:
675 const VarDecl *VD) const {
676 return false;
677 };
678
679 /// Check whether \a S is the loop the target kernel being emitted was
680 /// promoted for, to complete the promotion to a "no-loop" SPMD kernel,
681 /// mirroring Flang's MLIR promotion path.
682 virtual bool canPromoteToNoLoop(const OMPLoopDirective &S) const {
683 return false;
684 }
685
686 /// Get call to __kmpc_alloc_shared
687 virtual std::pair<llvm::Value *, llvm::Value *>
689 llvm_unreachable("not implemented");
690 }
691
692 /// Get call to __kmpc_free_shared
693 virtual void getKmpcFreeShared(
694 CodeGenFunction &CGF,
695 const std::pair<llvm::Value *, llvm::Value *> &AddrSizePair) {
696 llvm_unreachable("not implemented");
697 }
698
699 /// Emits code for OpenMP 'if' clause using specified \a CodeGen
700 /// function. Here is the logic:
701 /// if (Cond) {
702 /// ThenGen();
703 /// } else {
704 /// ElseGen();
705 /// }
706 void emitIfClause(CodeGenFunction &CGF, const Expr *Cond,
707 const RegionCodeGenTy &ThenGen,
708 const RegionCodeGenTy &ElseGen);
709
710 /// Checks if the \p Body is the \a CompoundStmt and returns its child
711 /// statement iff there is only one that is not evaluatable at the compile
712 /// time.
713 static const Stmt *getSingleCompoundChild(ASTContext &Ctx, const Stmt *Body);
714
715 /// Get the platform-specific name separator.
716 std::string getName(ArrayRef<StringRef> Parts) const;
717
718 /// Emit code for the specified user defined reduction construct.
720 const OMPDeclareReductionDecl *D);
721 /// Get combiner/initializer for the specified user-defined reduction, if any.
722 virtual std::pair<llvm::Function *, llvm::Function *>
724
725 /// Emit the function for the user defined mapper construct.
727 CodeGenFunction *CGF = nullptr);
728 /// Get the function for the specified user-defined mapper. If it does not
729 /// exist, create one.
730 llvm::Function *
732
733 /// Emits outlined function for the specified OpenMP parallel directive
734 /// \a D. This outlined function has type void(*)(kmp_int32 *ThreadID,
735 /// kmp_int32 BoundID, struct context_vars*).
736 /// \param CGF Reference to current CodeGenFunction.
737 /// \param D OpenMP directive.
738 /// \param ThreadIDVar Variable for thread id in the current OpenMP region.
739 /// \param InnermostKind Kind of innermost directive (for simple directives it
740 /// is a directive itself, for combined - its innermost directive).
741 /// \param CodeGen Code generation sequence for the \a D directive.
742 virtual llvm::Function *emitParallelOutlinedFunction(
744 const VarDecl *ThreadIDVar, OpenMPDirectiveKind InnermostKind,
745 const RegionCodeGenTy &CodeGen);
746
747 /// Emits outlined function for the specified OpenMP teams directive
748 /// \a D. This outlined function has type void(*)(kmp_int32 *ThreadID,
749 /// kmp_int32 BoundID, struct context_vars*).
750 /// \param CGF Reference to current CodeGenFunction.
751 /// \param D OpenMP directive.
752 /// \param ThreadIDVar Variable for thread id in the current OpenMP region.
753 /// \param InnermostKind Kind of innermost directive (for simple directives it
754 /// is a directive itself, for combined - its innermost directive).
755 /// \param CodeGen Code generation sequence for the \a D directive.
756 virtual llvm::Function *emitTeamsOutlinedFunction(
758 const VarDecl *ThreadIDVar, OpenMPDirectiveKind InnermostKind,
759 const RegionCodeGenTy &CodeGen);
760
761 /// Emits outlined function for the OpenMP task directive \a D. This
762 /// outlined function has type void(*)(kmp_int32 ThreadID, struct task_t*
763 /// TaskT).
764 /// \param D OpenMP directive.
765 /// \param ThreadIDVar Variable for thread id in the current OpenMP region.
766 /// \param PartIDVar Variable for partition id in the current OpenMP untied
767 /// task region.
768 /// \param TaskTVar Variable for task_t argument.
769 /// \param InnermostKind Kind of innermost directive (for simple directives it
770 /// is a directive itself, for combined - its innermost directive).
771 /// \param CodeGen Code generation sequence for the \a D directive.
772 /// \param Tied true if task is generated for tied task, false otherwise.
773 /// \param NumberOfParts Number of parts in untied task. Ignored for tied
774 /// tasks.
775 ///
776 virtual llvm::Function *emitTaskOutlinedFunction(
777 const OMPExecutableDirective &D, const VarDecl *ThreadIDVar,
778 const VarDecl *PartIDVar, const VarDecl *TaskTVar,
779 OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen,
780 bool Tied, unsigned &NumberOfParts);
781
782 /// Cleans up references to the objects in finished function.
783 ///
784 virtual void functionFinished(CodeGenFunction &CGF);
785
786 /// Emits code for parallel or serial call of the \a OutlinedFn with
787 /// variables captured in a record which address is stored in \a
788 /// CapturedStruct.
789 /// \param OutlinedFn Outlined function to be run in parallel threads. Type of
790 /// this function is void(*)(kmp_int32 *, kmp_int32, struct context_vars*).
791 /// \param CapturedVars A pointer to the record with the references to
792 /// variables used in \a OutlinedFn function.
793 /// \param IfCond Condition in the associated 'if' clause, if it was
794 /// specified, nullptr otherwise.
795 /// \param NumThreads The value corresponding to the num_threads clause, if
796 /// any, or nullptr.
797 /// \param NumThreadsModifier The modifier of the num_threads clause, if
798 /// any, ignored otherwise.
799 /// \param Severity The severity corresponding to the num_threads clause, if
800 /// any, ignored otherwise.
801 /// \param Message The message string corresponding to the num_threads clause,
802 /// if any, or nullptr.
803 ///
804 virtual void
806 llvm::Function *OutlinedFn,
807 ArrayRef<llvm::Value *> CapturedVars, const Expr *IfCond,
808 llvm::Value *NumThreads,
809 OpenMPNumThreadsClauseModifier NumThreadsModifier =
811 OpenMPSeverityClauseKind Severity = OMPC_SEVERITY_fatal,
812 const Expr *Message = nullptr);
813
814 /// Emits a critical region.
815 /// \param CriticalName Name of the critical region.
816 /// \param CriticalOpGen Generator for the statement associated with the given
817 /// critical region.
818 /// \param Hint Value of the 'hint' clause (optional).
819 virtual void emitCriticalRegion(CodeGenFunction &CGF, StringRef CriticalName,
820 const RegionCodeGenTy &CriticalOpGen,
821 SourceLocation Loc,
822 const Expr *Hint = nullptr);
823
824 /// Emits a master region.
825 /// \param MasterOpGen Generator for the statement associated with the given
826 /// master region.
827 virtual void emitMasterRegion(CodeGenFunction &CGF,
828 const RegionCodeGenTy &MasterOpGen,
829 SourceLocation Loc);
830
831 /// Emits a masked region.
832 /// \param MaskedOpGen Generator for the statement associated with the given
833 /// masked region.
834 virtual void emitMaskedRegion(CodeGenFunction &CGF,
835 const RegionCodeGenTy &MaskedOpGen,
836 SourceLocation Loc,
837 const Expr *Filter = nullptr);
838
839 /// Emits code for a taskyield directive.
840 virtual void emitTaskyieldCall(CodeGenFunction &CGF, SourceLocation Loc);
841
842 /// Emit __kmpc_error call for error directive
843 /// extern void __kmpc_error(ident_t *loc, int severity, const char *message);
844 virtual void emitErrorCall(CodeGenFunction &CGF, SourceLocation Loc, Expr *ME,
845 bool IsFatal);
846
847 /// Emit a taskgroup region.
848 /// \param TaskgroupOpGen Generator for the statement associated with the
849 /// given taskgroup region.
850 virtual void emitTaskgroupRegion(CodeGenFunction &CGF,
851 const RegionCodeGenTy &TaskgroupOpGen,
852 SourceLocation Loc);
853
854 /// Emits a single region.
855 /// \param SingleOpGen Generator for the statement associated with the given
856 /// single region.
857 virtual void emitSingleRegion(CodeGenFunction &CGF,
858 const RegionCodeGenTy &SingleOpGen,
859 SourceLocation Loc,
860 ArrayRef<const Expr *> CopyprivateVars,
861 ArrayRef<const Expr *> DestExprs,
862 ArrayRef<const Expr *> SrcExprs,
863 ArrayRef<const Expr *> AssignmentOps);
864
865 /// Emit an ordered region.
866 /// \param OrderedOpGen Generator for the statement associated with the given
867 /// ordered region.
868 virtual void emitOrderedRegion(CodeGenFunction &CGF,
869 const RegionCodeGenTy &OrderedOpGen,
870 SourceLocation Loc, bool IsThreads);
871
872 /// Emit an implicit/explicit barrier for OpenMP threads.
873 /// \param Kind Directive for which this implicit barrier call must be
874 /// generated. Must be OMPD_barrier for explicit barrier generation.
875 /// \param EmitChecks true if need to emit checks for cancellation barriers.
876 /// \param ForceSimpleCall true simple barrier call must be emitted, false if
877 /// runtime class decides which one to emit (simple or with cancellation
878 /// checks).
879 ///
880 virtual void emitBarrierCall(CodeGenFunction &CGF, SourceLocation Loc,
882 bool EmitChecks = true,
883 bool ForceSimpleCall = false);
884
885 /// Check if the specified \a ScheduleKind is static non-chunked.
886 /// This kind of worksharing directive is emitted without outer loop.
887 /// \param ScheduleKind Schedule kind specified in the 'schedule' clause.
888 /// \param Chunked True if chunk is specified in the clause.
889 ///
890 virtual bool isStaticNonchunked(OpenMPScheduleClauseKind ScheduleKind,
891 bool Chunked) const;
892
893 /// Check if the specified \a ScheduleKind is static non-chunked.
894 /// This kind of distribute directive is emitted without outer loop.
895 /// \param ScheduleKind Schedule kind specified in the 'dist_schedule' clause.
896 /// \param Chunked True if chunk is specified in the clause.
897 ///
898 virtual bool isStaticNonchunked(OpenMPDistScheduleClauseKind ScheduleKind,
899 bool Chunked) const;
900
901 /// Check if the specified \a ScheduleKind is static chunked.
902 /// \param ScheduleKind Schedule kind specified in the 'schedule' clause.
903 /// \param Chunked True if chunk is specified in the clause.
904 ///
905 virtual bool isStaticChunked(OpenMPScheduleClauseKind ScheduleKind,
906 bool Chunked) const;
907
908 /// Check if the specified \a ScheduleKind is static non-chunked.
909 /// \param ScheduleKind Schedule kind specified in the 'dist_schedule' clause.
910 /// \param Chunked True if chunk is specified in the clause.
911 ///
912 virtual bool isStaticChunked(OpenMPDistScheduleClauseKind ScheduleKind,
913 bool Chunked) const;
914
915 /// Check if the specified \a ScheduleKind is dynamic.
916 /// This kind of worksharing directive is emitted without outer loop.
917 /// \param ScheduleKind Schedule Kind specified in the 'schedule' clause.
918 ///
919 virtual bool isDynamic(OpenMPScheduleClauseKind ScheduleKind) const;
920
921 /// struct with the values to be passed to the dispatch runtime function
923 /// Loop lower bound
924 llvm::Value *LB = nullptr;
925 /// Loop upper bound
926 llvm::Value *UB = nullptr;
927 /// Chunk size specified using 'schedule' clause (nullptr if chunk
928 /// was not specified)
929 llvm::Value *Chunk = nullptr;
930 DispatchRTInput() = default;
931 DispatchRTInput(llvm::Value *LB, llvm::Value *UB, llvm::Value *Chunk)
932 : LB(LB), UB(UB), Chunk(Chunk) {}
933 };
934
935 /// Call the appropriate runtime routine to initialize it before start
936 /// of loop.
937
938 /// This is used for non static scheduled types and when the ordered
939 /// clause is present on the loop construct.
940 /// Depending on the loop schedule, it is necessary to call some runtime
941 /// routine before start of the OpenMP loop to get the loop upper / lower
942 /// bounds \a LB and \a UB and stride \a ST.
943 ///
944 /// \param CGF Reference to current CodeGenFunction.
945 /// \param Loc Clang source location.
946 /// \param ScheduleKind Schedule kind, specified by the 'schedule' clause.
947 /// \param IVSize Size of the iteration variable in bits.
948 /// \param IVSigned Sign of the iteration variable.
949 /// \param Ordered true if loop is ordered, false otherwise.
950 /// \param DispatchValues struct containing llvm values for lower bound, upper
951 /// bound, and chunk expression.
952 /// For the default (nullptr) value, the chunk 1 will be used.
953 ///
955 const OpenMPScheduleTy &ScheduleKind,
956 unsigned IVSize, bool IVSigned, bool Ordered,
957 const DispatchRTInput &DispatchValues);
958
959 /// This is used for non static scheduled types and when the ordered
960 /// clause is present on the loop construct.
961 ///
962 /// \param CGF Reference to current CodeGenFunction.
963 /// \param Loc Clang source location.
964 ///
966
967 /// Struct with the values to be passed to the static runtime function
969 /// Size of the iteration variable in bits.
970 unsigned IVSize = 0;
971 /// Sign of the iteration variable.
972 bool IVSigned = false;
973 /// true if loop is ordered, false otherwise.
974 bool Ordered = false;
975 /// Address of the output variable in which the flag of the last iteration
976 /// is returned.
978 /// Address of the output variable in which the lower iteration number is
979 /// returned.
981 /// Address of the output variable in which the upper iteration number is
982 /// returned.
984 /// Address of the output variable in which the stride value is returned
985 /// necessary to generated the static_chunked scheduled loop.
987 /// Value of the chunk for the static_chunked scheduled loop. For the
988 /// default (nullptr) value, the chunk 1 will be used.
989 llvm::Value *Chunk = nullptr;
992 llvm::Value *Chunk = nullptr)
994 UB(UB), ST(ST), Chunk(Chunk) {}
995 };
996 /// Call the appropriate runtime routine to initialize it before start
997 /// of loop.
998 ///
999 /// This is used only in case of static schedule, when the user did not
1000 /// specify a ordered clause on the loop construct.
1001 /// Depending on the loop schedule, it is necessary to call some runtime
1002 /// routine before start of the OpenMP loop to get the loop upper / lower
1003 /// bounds LB and UB and stride ST.
1004 ///
1005 /// \param CGF Reference to current CodeGenFunction.
1006 /// \param Loc Clang source location.
1007 /// \param DKind Kind of the directive.
1008 /// \param ScheduleKind Schedule kind, specified by the 'schedule' clause.
1009 /// \param Values Input arguments for the construct.
1010 ///
1011 virtual void emitForStaticInit(CodeGenFunction &CGF, SourceLocation Loc,
1012 OpenMPDirectiveKind DKind,
1013 const OpenMPScheduleTy &ScheduleKind,
1014 const StaticRTInput &Values);
1015
1016 ///
1017 /// \param CGF Reference to current CodeGenFunction.
1018 /// \param Loc Clang source location.
1019 /// \param SchedKind Schedule kind, specified by the 'dist_schedule' clause.
1020 /// \param Values Input arguments for the construct.
1021 ///
1022 virtual void emitDistributeStaticInit(CodeGenFunction &CGF,
1023 SourceLocation Loc,
1025 const StaticRTInput &Values);
1026
1027 /// Call the appropriate runtime routine to notify that we finished
1028 /// iteration of the ordered loop with the dynamic scheduling.
1029 ///
1030 /// \param CGF Reference to current CodeGenFunction.
1031 /// \param Loc Clang source location.
1032 /// \param IVSize Size of the iteration variable in bits.
1033 /// \param IVSigned Sign of the iteration variable.
1034 ///
1036 SourceLocation Loc, unsigned IVSize,
1037 bool IVSigned);
1038
1039 /// Call the appropriate runtime routine to notify that we finished
1040 /// all the work with current loop.
1041 ///
1042 /// \param CGF Reference to current CodeGenFunction.
1043 /// \param Loc Clang source location.
1044 /// \param DKind Kind of the directive for which the static finish is emitted.
1045 ///
1046 virtual void emitForStaticFinish(CodeGenFunction &CGF, SourceLocation Loc,
1047 OpenMPDirectiveKind DKind);
1048
1049 /// Call __kmpc_dispatch_next(
1050 /// ident_t *loc, kmp_int32 tid, kmp_int32 *p_lastiter,
1051 /// kmp_int[32|64] *p_lower, kmp_int[32|64] *p_upper,
1052 /// kmp_int[32|64] *p_stride);
1053 /// \param IVSize Size of the iteration variable in bits.
1054 /// \param IVSigned Sign of the iteration variable.
1055 /// \param IL Address of the output variable in which the flag of the
1056 /// last iteration is returned.
1057 /// \param LB Address of the output variable in which the lower iteration
1058 /// number is returned.
1059 /// \param UB Address of the output variable in which the upper iteration
1060 /// number is returned.
1061 /// \param ST Address of the output variable in which the stride value is
1062 /// returned.
1063 virtual llvm::Value *emitForNext(CodeGenFunction &CGF, SourceLocation Loc,
1064 unsigned IVSize, bool IVSigned,
1065 Address IL, Address LB,
1066 Address UB, Address ST);
1067
1068 virtual llvm::Value *emitMessageClause(CodeGenFunction &CGF,
1069 const Expr *Message,
1070 SourceLocation Loc);
1071
1072 virtual llvm::Value *emitSeverityClause(OpenMPSeverityClauseKind Severity,
1073 SourceLocation Loc);
1074
1075 /// Emits call to void __kmpc_push_num_threads(ident_t *loc, kmp_int32
1076 /// global_tid, kmp_int32 num_threads) to generate code for 'num_threads'
1077 /// clause.
1078 /// If the modifier 'strict' is given:
1079 /// Emits call to void __kmpc_push_num_threads_strict(ident_t *loc, kmp_int32
1080 /// global_tid, kmp_int32 num_threads, int severity, const char *message) to
1081 /// generate code for 'num_threads' clause with 'strict' modifier.
1082 /// \param NumThreads An integer value of threads.
1083 virtual void emitNumThreadsClause(
1084 CodeGenFunction &CGF, llvm::Value *NumThreads, SourceLocation Loc,
1086 OpenMPSeverityClauseKind Severity = OMPC_SEVERITY_fatal,
1087 SourceLocation SeverityLoc = SourceLocation(),
1088 const Expr *Message = nullptr,
1089 SourceLocation MessageLoc = SourceLocation());
1090
1091 /// Emit call to void __kmpc_push_proc_bind(ident_t *loc, kmp_int32
1092 /// global_tid, int proc_bind) to generate code for 'proc_bind' clause.
1093 virtual void emitProcBindClause(CodeGenFunction &CGF,
1094 llvm::omp::ProcBindKind ProcBind,
1095 SourceLocation Loc);
1096
1097 /// Returns address of the threadprivate variable for the current
1098 /// thread.
1099 /// \param VD Threadprivate variable.
1100 /// \param VDAddr Address of the global variable \a VD.
1101 /// \param Loc Location of the reference to threadprivate var.
1102 /// \return Address of the threadprivate variable for the current thread.
1104 const VarDecl *VD, Address VDAddr,
1105 SourceLocation Loc);
1106
1107 /// Returns the address of the variable marked as declare target with link
1108 /// clause OR as declare target with to clause and unified memory.
1110
1111 /// Emit a code for initialization of threadprivate variable. It emits
1112 /// a call to runtime library which adds initial value to the newly created
1113 /// threadprivate variable (if it is not constant) and registers destructor
1114 /// for the variable (if any).
1115 /// \param VD Threadprivate variable.
1116 /// \param VDAddr Address of the global variable \a VD.
1117 /// \param Loc Location of threadprivate declaration.
1118 /// \param PerformInit true if initialization expression is not constant.
1119 virtual llvm::Function *
1121 SourceLocation Loc, bool PerformInit,
1122 CodeGenFunction *CGF = nullptr);
1123
1124 /// Emit code for handling declare target functions in the runtime.
1125 /// \param FD Declare target function.
1126 /// \param Addr Address of the global \a FD.
1127 /// \param PerformInit true if initialization expression is not constant.
1128 virtual void emitDeclareTargetFunction(const FunctionDecl *FD,
1129 llvm::GlobalValue *GV);
1130
1131 /// Register VTable to OpenMP offload entry.
1132 /// \param VTable VTable of the C++ class.
1133 /// \param RD C++ class decl.
1134 virtual void registerVTableOffloadEntry(llvm::GlobalVariable *VTable,
1135 const VarDecl *VD);
1136 /// Emit code for registering vtable by scanning through map clause
1137 /// in OpenMP target region.
1138 /// \param D OpenMP target directive.
1139 virtual void registerVTable(const OMPExecutableDirective &D);
1140
1141 /// Emit and register VTable for the C++ class in OpenMP offload entry.
1142 /// \param CXXRecord C++ class decl.
1143 /// \param VD Variable decl which holds VTable.
1146 const VarDecl *VD);
1147
1148 /// Creates artificial threadprivate variable with name \p Name and type \p
1149 /// VarType.
1150 /// \param VarType Type of the artificial threadprivate variable.
1151 /// \param Name Name of the artificial threadprivate variable.
1153 QualType VarType,
1154 StringRef Name);
1155
1156 /// Emit flush of the variables specified in 'omp flush' directive.
1157 /// \param Vars List of variables to flush.
1158 /// \param AO Memory ordering of the flush, or NotAtomic for a flush with a
1159 /// list (a strong flush).
1160 virtual void emitFlush(CodeGenFunction &CGF, ArrayRef<const Expr *> Vars,
1161 SourceLocation Loc, llvm::AtomicOrdering AO);
1162
1163 /// Emit task region for the task directive. The task region is
1164 /// emitted in several steps:
1165 /// 1. Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32
1166 /// gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds,
1167 /// kmp_routine_entry_t *task_entry). Here task_entry is a pointer to the
1168 /// function:
1169 /// kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) {
1170 /// TaskFunction(gtid, tt->part_id, tt->shareds);
1171 /// return 0;
1172 /// }
1173 /// 2. Copy a list of shared variables to field shareds of the resulting
1174 /// structure kmp_task_t returned by the previous call (if any).
1175 /// 3. Copy a pointer to destructions function to field destructions of the
1176 /// resulting structure kmp_task_t.
1177 /// 4. Emit a call to kmp_int32 __kmpc_omp_task(ident_t *, kmp_int32 gtid,
1178 /// kmp_task_t *new_task), where new_task is a resulting structure from
1179 /// previous items.
1180 /// \param D Current task directive.
1181 /// \param TaskFunction An LLVM function with type void (*)(i32 /*gtid*/, i32
1182 /// /*part_id*/, captured_struct */*__context*/);
1183 /// \param SharedsTy A type which contains references the shared variables.
1184 /// \param Shareds Context with the list of shared variables from the \p
1185 /// TaskFunction.
1186 /// \param IfCond Not a nullptr if 'if' clause was specified, nullptr
1187 /// otherwise.
1188 /// \param Data Additional data for task generation like tiednsee, final
1189 /// state, list of privates etc.
1190 virtual void emitTaskCall(CodeGenFunction &CGF, SourceLocation Loc,
1191 const OMPExecutableDirective &D,
1192 llvm::Function *TaskFunction, QualType SharedsTy,
1193 Address Shareds, const Expr *IfCond,
1194 const OMPTaskDataTy &Data);
1195
1196 /// Emit task region for the taskloop directive. The taskloop region is
1197 /// emitted in several steps:
1198 /// 1. Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32
1199 /// gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds,
1200 /// kmp_routine_entry_t *task_entry). Here task_entry is a pointer to the
1201 /// function:
1202 /// kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) {
1203 /// TaskFunction(gtid, tt->part_id, tt->shareds);
1204 /// return 0;
1205 /// }
1206 /// 2. Copy a list of shared variables to field shareds of the resulting
1207 /// structure kmp_task_t returned by the previous call (if any).
1208 /// 3. Copy a pointer to destructions function to field destructions of the
1209 /// resulting structure kmp_task_t.
1210 /// 4. Emit a call to void __kmpc_taskloop(ident_t *loc, int gtid, kmp_task_t
1211 /// *task, int if_val, kmp_uint64 *lb, kmp_uint64 *ub, kmp_int64 st, int
1212 /// nogroup, int sched, kmp_uint64 grainsize, void *task_dup ), where new_task
1213 /// is a resulting structure from
1214 /// previous items.
1215 /// \param D Current task directive.
1216 /// \param TaskFunction An LLVM function with type void (*)(i32 /*gtid*/, i32
1217 /// /*part_id*/, captured_struct */*__context*/);
1218 /// \param SharedsTy A type which contains references the shared variables.
1219 /// \param Shareds Context with the list of shared variables from the \p
1220 /// TaskFunction.
1221 /// \param IfCond Not a nullptr if 'if' clause was specified, nullptr
1222 /// otherwise.
1223 /// \param Data Additional data for task generation like tiednsee, final
1224 /// state, list of privates etc.
1225 virtual void emitTaskLoopCall(CodeGenFunction &CGF, SourceLocation Loc,
1226 const OMPLoopDirective &D,
1227 llvm::Function *TaskFunction,
1228 QualType SharedsTy, Address Shareds,
1229 const Expr *IfCond, const OMPTaskDataTy &Data);
1230
1231 /// Emit code for the directive that does not require outlining.
1232 ///
1233 /// \param InnermostKind Kind of innermost directive (for simple directives it
1234 /// is a directive itself, for combined - its innermost directive).
1235 /// \param CodeGen Code generation sequence for the \a D directive.
1236 /// \param HasCancel true if region has inner cancel directive, false
1237 /// otherwise.
1238 virtual void emitInlinedDirective(CodeGenFunction &CGF,
1239 OpenMPDirectiveKind InnermostKind,
1240 const RegionCodeGenTy &CodeGen,
1241 bool HasCancel = false);
1242
1243 /// Emits reduction function.
1244 /// \param ReducerName Name of the function calling the reduction.
1245 /// \param ArgsElemType Array type containing pointers to reduction variables.
1246 /// \param Privates List of private copies for original reduction arguments.
1247 /// \param LHSExprs List of LHS in \a ReductionOps reduction operations.
1248 /// \param RHSExprs List of RHS in \a ReductionOps reduction operations.
1249 /// \param ReductionOps List of reduction operations in form 'LHS binop RHS'
1250 /// or 'operator binop(LHS, RHS)'.
1251 llvm::Function *emitReductionFunction(
1252 StringRef ReducerName, SourceLocation Loc, llvm::Type *ArgsElemType,
1254 ArrayRef<const Expr *> RHSExprs, ArrayRef<const Expr *> ReductionOps);
1255
1256 /// Emits single reduction combiner
1258 const Expr *ReductionOp,
1259 const Expr *PrivateRef,
1260 const DeclRefExpr *LHS,
1261 const DeclRefExpr *RHS);
1262
1269
1270 /// Emits code for private variable reduction
1271 /// \param Privates List of private copies for original reduction arguments.
1272 /// \param LHSExprs List of LHS in \a ReductionOps reduction operations.
1273 /// \param RHSExprs List of RHS in \a ReductionOps reduction operations.
1274 /// \param ReductionOps List of reduction operations in form 'LHS binop RHS'
1275 /// or 'operator binop(LHS, RHS)'.
1277 const Expr *Privates, const Expr *LHSExprs,
1278 const Expr *RHSExprs, const Expr *ReductionOps);
1279
1280 /// Emit a code for reduction clause. Next code should be emitted for
1281 /// reduction:
1282 /// \code
1283 ///
1284 /// static kmp_critical_name lock = { 0 };
1285 ///
1286 /// void reduce_func(void *lhs[<n>], void *rhs[<n>]) {
1287 /// ...
1288 /// *(Type<i>*)lhs[i] = RedOp<i>(*(Type<i>*)lhs[i], *(Type<i>*)rhs[i]);
1289 /// ...
1290 /// }
1291 ///
1292 /// ...
1293 /// void *RedList[<n>] = {&<RHSExprs>[0], ..., &<RHSExprs>[<n>-1]};
1294 /// switch (__kmpc_reduce{_nowait}(<loc>, <gtid>, <n>, sizeof(RedList),
1295 /// RedList, reduce_func, &<lock>)) {
1296 /// case 1:
1297 /// ...
1298 /// <LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]);
1299 /// ...
1300 /// __kmpc_end_reduce{_nowait}(<loc>, <gtid>, &<lock>);
1301 /// break;
1302 /// case 2:
1303 /// ...
1304 /// Atomic(<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]));
1305 /// ...
1306 /// break;
1307 /// default:;
1308 /// }
1309 /// \endcode
1310 ///
1311 /// \param Privates List of private copies for original reduction arguments.
1312 /// \param LHSExprs List of LHS in \a ReductionOps reduction operations.
1313 /// \param RHSExprs List of RHS in \a ReductionOps reduction operations.
1314 /// \param ReductionOps List of reduction operations in form 'LHS binop RHS'
1315 /// or 'operator binop(LHS, RHS)'.
1316 /// \param Options List of options for reduction codegen:
1317 /// WithNowait true if parent directive has also nowait clause, false
1318 /// otherwise.
1319 /// SimpleReduction Emit reduction operation only. Used for omp simd
1320 /// directive on the host.
1321 /// ReductionKind The kind of reduction to perform.
1322 virtual void emitReduction(CodeGenFunction &CGF, SourceLocation Loc,
1324 ArrayRef<const Expr *> LHSExprs,
1325 ArrayRef<const Expr *> RHSExprs,
1326 ArrayRef<const Expr *> ReductionOps,
1327 ReductionOptionsTy Options);
1328
1329 /// Emit a code for initialization of task reduction clause. Next code
1330 /// should be emitted for reduction:
1331 /// \code
1332 ///
1333 /// _taskred_item_t red_data[n];
1334 /// ...
1335 /// red_data[i].shar = &shareds[i];
1336 /// red_data[i].orig = &origs[i];
1337 /// red_data[i].size = sizeof(origs[i]);
1338 /// red_data[i].f_init = (void*)RedInit<i>;
1339 /// red_data[i].f_fini = (void*)RedDest<i>;
1340 /// red_data[i].f_comb = (void*)RedOp<i>;
1341 /// red_data[i].flags = <Flag_i>;
1342 /// ...
1343 /// void* tg1 = __kmpc_taskred_init(gtid, n, red_data);
1344 /// \endcode
1345 /// For reduction clause with task modifier it emits the next call:
1346 /// \code
1347 ///
1348 /// _taskred_item_t red_data[n];
1349 /// ...
1350 /// red_data[i].shar = &shareds[i];
1351 /// red_data[i].orig = &origs[i];
1352 /// red_data[i].size = sizeof(origs[i]);
1353 /// red_data[i].f_init = (void*)RedInit<i>;
1354 /// red_data[i].f_fini = (void*)RedDest<i>;
1355 /// red_data[i].f_comb = (void*)RedOp<i>;
1356 /// red_data[i].flags = <Flag_i>;
1357 /// ...
1358 /// void* tg1 = __kmpc_taskred_modifier_init(loc, gtid, is_worksharing, n,
1359 /// red_data);
1360 /// \endcode
1361 /// \param LHSExprs List of LHS in \a Data.ReductionOps reduction operations.
1362 /// \param RHSExprs List of RHS in \a Data.ReductionOps reduction operations.
1363 /// \param Data Additional data for task generation like tiedness, final
1364 /// state, list of privates, reductions etc.
1365 virtual llvm::Value *emitTaskReductionInit(CodeGenFunction &CGF,
1366 SourceLocation Loc,
1367 ArrayRef<const Expr *> LHSExprs,
1368 ArrayRef<const Expr *> RHSExprs,
1369 const OMPTaskDataTy &Data);
1370
1371 /// Emits the following code for reduction clause with task modifier:
1372 /// \code
1373 /// __kmpc_task_reduction_modifier_fini(loc, gtid, is_worksharing);
1374 /// \endcode
1376 bool IsWorksharingReduction);
1377
1378 /// Required to resolve existing problems in the runtime. Emits threadprivate
1379 /// variables to store the size of the VLAs/array sections for
1380 /// initializer/combiner/finalizer functions.
1381 /// \param RCG Allows to reuse an existing data for the reductions.
1382 /// \param N Reduction item for which fixups must be emitted.
1384 ReductionCodeGen &RCG, unsigned N);
1385
1386 /// Get the address of `void *` type of the privatue copy of the reduction
1387 /// item specified by the \p SharedLVal.
1388 /// \param ReductionsPtr Pointer to the reduction data returned by the
1389 /// emitTaskReductionInit function.
1390 /// \param SharedLVal Address of the original reduction item.
1392 llvm::Value *ReductionsPtr,
1393 LValue SharedLVal);
1394
1395 /// Emit code for 'taskwait' directive.
1396 virtual void emitTaskwaitCall(CodeGenFunction &CGF, SourceLocation Loc,
1397 const OMPTaskDataTy &Data);
1398
1399 /// Emit code for 'cancellation point' construct.
1400 /// \param CancelRegion Region kind for which the cancellation point must be
1401 /// emitted.
1402 ///
1404 SourceLocation Loc,
1405 OpenMPDirectiveKind CancelRegion);
1406
1407 /// Emit code for 'cancel' construct.
1408 /// \param IfCond Condition in the associated 'if' clause, if it was
1409 /// specified, nullptr otherwise.
1410 /// \param CancelRegion Region kind for which the cancel must be emitted.
1411 ///
1412 virtual void emitCancelCall(CodeGenFunction &CGF, SourceLocation Loc,
1413 const Expr *IfCond,
1414 OpenMPDirectiveKind CancelRegion);
1415
1416 /// Emit the '<kernel>_kernel_environment' global for a target region that
1417 /// is compiled for a non-GPU (host-style) offload target, which does not
1418 /// go through the GPU device-side runtime init/deinit sequence.
1420 CodeGenFunction &CGF);
1421
1422 /// Emit outilined function for 'target' directive.
1423 /// \param D Directive to emit.
1424 /// \param ParentName Name of the function that encloses the target region.
1425 /// \param OutlinedFn Outlined function value to be defined by this call.
1426 /// \param OutlinedFnID Outlined function ID value to be defined by this call.
1427 /// \param IsOffloadEntry True if the outlined function is an offload entry.
1428 /// \param CodeGen Code generation sequence for the \a D directive.
1429 /// An outlined function may not be an entry if, e.g. the if clause always
1430 /// evaluates to false.
1432 StringRef ParentName,
1433 llvm::Function *&OutlinedFn,
1434 llvm::Constant *&OutlinedFnID,
1435 bool IsOffloadEntry,
1436 const RegionCodeGenTy &CodeGen);
1437
1438 /// Returns the parent name of the target regions in \a FD: its enclosing
1439 /// non-closure function if \a FD is a closure, otherwise \a FD itself;
1440 /// constructors and destructors use their complete variant.
1441 StringRef getTargetRegionParentName(const FunctionDecl *FD) const;
1442
1443 /// Emit the target offloading code associated with \a D. The emitted
1444 /// code attempts offloading the execution to the device, an the event of
1445 /// a failure it executes the host version outlined in \a OutlinedFn.
1446 /// \param D Directive to emit.
1447 /// \param OutlinedFn Host version of the code to be offloaded.
1448 /// \param OutlinedFnID ID of host version of the code to be offloaded.
1449 /// \param IfCond Expression evaluated in if clause associated with the target
1450 /// directive, or null if no if clause is used.
1451 /// \param Device Expression evaluated in device clause associated with the
1452 /// target directive, or null if no device clause is used and device modifier.
1453 /// \param SizeEmitter Callback to emit number of iterations for loop-based
1454 /// directives.
1455 virtual void emitTargetCall(
1457 llvm::Function *OutlinedFn, llvm::Value *OutlinedFnID, const Expr *IfCond,
1458 llvm::PointerIntPair<const Expr *, 2, OpenMPDeviceClauseModifier> Device,
1459 llvm::function_ref<llvm::Value *(CodeGenFunction &CGF,
1460 const OMPLoopDirective &D)>
1461 SizeEmitter);
1462
1463 /// Emit the target regions enclosed in \a GD function definition or
1464 /// the function itself in case it is a valid device function. Returns true if
1465 /// \a GD was dealt with successfully.
1466 /// \param GD Function to scan.
1467 virtual bool emitTargetFunctions(GlobalDecl GD);
1468
1469 /// Emit the global variable if it is a valid device global variable.
1470 /// Returns true if \a GD was dealt with successfully.
1471 /// \param GD Variable declaration to emit.
1472 virtual bool emitTargetGlobalVariable(GlobalDecl GD);
1473
1474 /// Checks if the provided global decl \a GD is a declare target variable and
1475 /// registers it when emitting code for the host.
1476 virtual void registerTargetGlobalVariable(const VarDecl *VD,
1477 llvm::Constant *Addr);
1478
1479 /// Emit the global \a GD if it is meaningful for the target. Returns
1480 /// if it was emitted successfully.
1481 /// \param GD Global to scan.
1482 virtual bool emitTargetGlobal(GlobalDecl GD);
1483
1484 /// Creates all the offload entries in the current compilation unit
1485 /// along with the associated metadata.
1487
1488 /// Emits code for teams call of the \a OutlinedFn with
1489 /// variables captured in a record which address is stored in \a
1490 /// CapturedStruct.
1491 /// \param OutlinedFn Outlined function to be run by team masters. Type of
1492 /// this function is void(*)(kmp_int32 *, kmp_int32, struct context_vars*).
1493 /// \param CapturedVars A pointer to the record with the references to
1494 /// variables used in \a OutlinedFn function.
1495 ///
1496 virtual void emitTeamsCall(CodeGenFunction &CGF,
1497 const OMPExecutableDirective &D,
1498 SourceLocation Loc, llvm::Function *OutlinedFn,
1499 ArrayRef<llvm::Value *> CapturedVars);
1500
1501 /// Emits call to void __kmpc_push_num_teams(ident_t *loc, kmp_int32
1502 /// global_tid, kmp_int32 num_teams, kmp_int32 thread_limit) to generate code
1503 /// for num_teams clause.
1504 /// \param NumTeams An integer expression of teams.
1505 /// \param ThreadLimit An integer expression of threads.
1506 virtual void emitNumTeamsClause(CodeGenFunction &CGF, const Expr *NumTeams,
1507 const Expr *ThreadLimit, SourceLocation Loc);
1508
1509 /// Emits call to void __kmpc_set_thread_limit(ident_t *loc, kmp_int32
1510 /// global_tid, kmp_int32 thread_limit) to generate code for
1511 /// thread_limit clause on target directive
1512 /// \param ThreadLimit An integer expression of threads.
1513 virtual void emitThreadLimitClause(CodeGenFunction &CGF,
1514 const Expr *ThreadLimit,
1515 SourceLocation Loc);
1516
1517 /// Struct that keeps all the relevant information that should be kept
1518 /// throughout a 'target data' region.
1520 public:
1521 explicit TargetDataInfo() : llvm::OpenMPIRBuilder::TargetDataInfo() {}
1522 explicit TargetDataInfo(bool RequiresDevicePointerInfo,
1523 bool SeparateBeginEndCalls)
1524 : llvm::OpenMPIRBuilder::TargetDataInfo(RequiresDevicePointerInfo,
1525 SeparateBeginEndCalls) {}
1526 /// Map between the a declaration of a capture and the corresponding new
1527 /// llvm address where the runtime returns the device pointers.
1528 llvm::DenseMap<const ValueDecl *, llvm::Value *> CaptureDeviceAddrMap;
1529 };
1530
1531 /// Emit the target data mapping code associated with \a D.
1532 /// \param D Directive to emit.
1533 /// \param IfCond Expression evaluated in if clause associated with the
1534 /// target directive, or null if no device clause is used.
1535 /// \param Device Expression evaluated in device clause associated with the
1536 /// target directive, or null if no device clause is used.
1537 /// \param Info A record used to store information that needs to be preserved
1538 /// until the region is closed.
1539 virtual void emitTargetDataCalls(CodeGenFunction &CGF,
1540 const OMPExecutableDirective &D,
1541 const Expr *IfCond, const Expr *Device,
1542 const RegionCodeGenTy &CodeGen,
1544
1545 /// Emit the data mapping/movement code associated with the directive
1546 /// \a D that should be of the form 'target [{enter|exit} data | update]'.
1547 /// \param D Directive to emit.
1548 /// \param IfCond Expression evaluated in if clause associated with the target
1549 /// directive, or null if no if clause is used.
1550 /// \param Device Expression evaluated in device clause associated with the
1551 /// target directive, or null if no device clause is used.
1553 const OMPExecutableDirective &D,
1554 const Expr *IfCond,
1555 const Expr *Device);
1556
1557 /// Marks function \a Fn with properly mangled versions of vector functions.
1558 /// \param FD Function marked as 'declare simd'.
1559 /// \param Fn LLVM function that must be marked with 'declare simd'
1560 /// attributes.
1561 virtual void emitDeclareSimdFunction(const FunctionDecl *FD,
1562 llvm::Function *Fn);
1563
1564 /// Emit initialization for doacross loop nesting support.
1565 /// \param D Loop-based construct used in doacross nesting construct.
1566 virtual void emitDoacrossInit(CodeGenFunction &CGF, const OMPLoopDirective &D,
1567 ArrayRef<Expr *> NumIterations);
1568
1569 /// Emit code for doacross ordered directive with 'depend' clause.
1570 /// \param C 'depend' clause with 'sink|source' dependency kind.
1571 virtual void emitDoacrossOrdered(CodeGenFunction &CGF,
1572 const OMPDependClause *C);
1573
1574 /// Emit code for doacross ordered directive with 'doacross' clause.
1575 /// \param C 'doacross' clause with 'sink|source' dependence type.
1576 virtual void emitDoacrossOrdered(CodeGenFunction &CGF,
1577 const OMPDoacrossClause *C);
1578
1579 /// Translates the native parameter of outlined function if this is required
1580 /// for target.
1581 /// \param FD Field decl from captured record for the parameter.
1582 /// \param NativeParam Parameter itself.
1583 virtual const VarDecl *translateParameter(const FieldDecl *FD,
1584 const VarDecl *NativeParam) const {
1585 return NativeParam;
1586 }
1587
1588 /// Gets the address of the native argument basing on the address of the
1589 /// target-specific parameter.
1590 /// \param NativeParam Parameter itself.
1591 /// \param TargetParam Corresponding target-specific parameter.
1593 const VarDecl *NativeParam,
1594 const VarDecl *TargetParam) const;
1595
1596 /// Choose default schedule type and chunk value for the
1597 /// dist_schedule clause.
1599 const OMPLoopDirective &S, OpenMPDistScheduleClauseKind &ScheduleKind,
1600 llvm::Value *&Chunk) const {}
1601
1602 /// Choose default schedule type and chunk value for the
1603 /// schedule clause.
1605 const OMPLoopDirective &S, OpenMPScheduleClauseKind &ScheduleKind,
1606 const Expr *&ChunkExpr) const;
1607
1608 /// Emits call of the outlined function with the provided arguments,
1609 /// translating these arguments to correct target-specific arguments.
1610 virtual void
1612 llvm::FunctionCallee OutlinedFn,
1613 ArrayRef<llvm::Value *> Args = {}) const;
1614
1615 /// Emits OpenMP-specific function prolog.
1616 /// Required for device constructs.
1617 virtual void emitFunctionProlog(CodeGenFunction &CGF, const Decl *D);
1618
1619 /// Gets the OpenMP-specific address of the local variable.
1620 virtual Address getAddressOfLocalVariable(CodeGenFunction &CGF,
1621 const VarDecl *VD);
1622
1623 /// Marks the declaration as already emitted for the device code and returns
1624 /// true, if it was marked already, and false, otherwise.
1626
1627 /// Emit deferred declare target variables marked for deferred emission.
1628 void emitDeferredTargetDecls() const;
1629
1630 /// Adjust some parameters for the target-based directives, like addresses of
1631 /// the variables captured by reference in lambdas.
1632 virtual void
1633 adjustTargetSpecificDataForLambdas(CodeGenFunction &CGF,
1634 const OMPExecutableDirective &D) const;
1635
1636 /// Perform check on requires decl to ensure that target architecture
1637 /// supports unified addressing
1638 virtual void processRequiresDirective(const OMPRequiresDecl *D);
1639
1640 /// Gets default memory ordering as specified in requires directive.
1641 llvm::AtomicOrdering getDefaultMemoryOrdering() const;
1642
1643 /// Checks if the variable has associated OMPAllocateDeclAttr attribute with
1644 /// the predefined allocator and translates it into the corresponding address
1645 /// space.
1646 virtual bool hasAllocateAttributeForGlobalVar(const VarDecl *VD, LangAS &AS);
1647
1648 /// Return whether the unified_shared_memory has been specified.
1649 bool hasRequiresUnifiedSharedMemory() const;
1650
1651 /// Checks if the \p VD variable is marked as nontemporal declaration in
1652 /// current context.
1653 bool isNontemporalDecl(const ValueDecl *VD) const;
1654
1655 /// Create specialized alloca to handle lastprivate conditionals.
1656 Address emitLastprivateConditionalInit(CodeGenFunction &CGF,
1657 const VarDecl *VD);
1658
1659 /// Checks if the provided \p LVal is lastprivate conditional and emits the
1660 /// code to update the value of the original variable.
1661 /// \code
1662 /// lastprivate(conditional: a)
1663 /// ...
1664 /// <type> a;
1665 /// lp_a = ...;
1666 /// #pragma omp critical(a)
1667 /// if (last_iv_a <= iv) {
1668 /// last_iv_a = iv;
1669 /// global_a = lp_a;
1670 /// }
1671 /// \endcode
1672 virtual void checkAndEmitLastprivateConditional(CodeGenFunction &CGF,
1673 const Expr *LHS);
1674
1675 /// Checks if the lastprivate conditional was updated in inner region and
1676 /// writes the value.
1677 /// \code
1678 /// lastprivate(conditional: a)
1679 /// ...
1680 /// <type> a;bool Fired = false;
1681 /// #pragma omp ... shared(a)
1682 /// {
1683 /// lp_a = ...;
1684 /// Fired = true;
1685 /// }
1686 /// if (Fired) {
1687 /// #pragma omp critical(a)
1688 /// if (last_iv_a <= iv) {
1689 /// last_iv_a = iv;
1690 /// global_a = lp_a;
1691 /// }
1692 /// Fired = false;
1693 /// }
1694 /// \endcode
1696 CodeGenFunction &CGF, const OMPExecutableDirective &D,
1697 const llvm::DenseSet<CanonicalDeclPtr<const VarDecl>> &IgnoredDecls);
1698
1699 /// Gets the address of the global copy used for lastprivate conditional
1700 /// update, if any.
1701 /// \param PrivLVal LValue for the private copy.
1702 /// \param VD Original lastprivate declaration.
1703 virtual void emitLastprivateConditionalFinalUpdate(CodeGenFunction &CGF,
1704 LValue PrivLVal,
1705 const VarDecl *VD,
1706 SourceLocation Loc);
1707
1708 /// Emits list of dependecies based on the provided data (array of
1709 /// dependence/expression pairs).
1710 /// \returns Pointer to the first element of the array casted to VoidPtr type.
1711 std::pair<llvm::Value *, Address>
1712 emitDependClause(CodeGenFunction &CGF,
1714 SourceLocation Loc);
1715
1716 /// Emits list of dependecies based on the provided data (array of
1717 /// dependence/expression pairs) for depobj construct. In this case, the
1718 /// variable is allocated in dynamically. \returns Pointer to the first
1719 /// element of the array casted to VoidPtr type.
1720 Address emitDepobjDependClause(CodeGenFunction &CGF,
1721 const OMPTaskDataTy::DependData &Dependencies,
1722 SourceLocation Loc);
1723
1724 /// Emits the code to destroy the dependency object provided in depobj
1725 /// directive.
1726 void emitDestroyClause(CodeGenFunction &CGF, LValue DepobjLVal,
1727 SourceLocation Loc);
1728
1729 /// Updates the dependency kind in the specified depobj object.
1730 /// \param DepobjLVal LValue for the main depobj object.
1731 /// \param NewDepKind New dependency kind.
1732 void emitUpdateDependObjectsClause(CodeGenFunction &CGF, LValue DepobjLVal,
1733 OpenMPDependClauseKind NewDepKind,
1734 SourceLocation Loc);
1735
1736 /// Initializes user defined allocators specified in the uses_allocators
1737 /// clauses.
1738 void emitUsesAllocatorsInit(CodeGenFunction &CGF, const Expr *Allocator,
1739 const Expr *AllocatorTraits);
1740
1741 /// Destroys user defined allocators specified in the uses_allocators clause.
1742 void emitUsesAllocatorsFini(CodeGenFunction &CGF, const Expr *Allocator);
1743
1744 /// Returns true if the variable is a local variable in untied task.
1745 bool isLocalVarInUntiedTask(CodeGenFunction &CGF, const VarDecl *VD) const;
1746};
1747
1748/// Class supports emissionof SIMD-only code.
1750public:
1753
1754 /// Emits outlined function for the specified OpenMP parallel directive
1755 /// \a D. This outlined function has type void(*)(kmp_int32 *ThreadID,
1756 /// kmp_int32 BoundID, struct context_vars*).
1757 /// \param CGF Reference to current CodeGenFunction.
1758 /// \param D OpenMP directive.
1759 /// \param ThreadIDVar Variable for thread id in the current OpenMP region.
1760 /// \param InnermostKind Kind of innermost directive (for simple directives it
1761 /// is a directive itself, for combined - its innermost directive).
1762 /// \param CodeGen Code generation sequence for the \a D directive.
1763 llvm::Function *emitParallelOutlinedFunction(
1765 const VarDecl *ThreadIDVar, OpenMPDirectiveKind InnermostKind,
1766 const RegionCodeGenTy &CodeGen) override;
1767
1768 /// Emits outlined function for the specified OpenMP teams directive
1769 /// \a D. This outlined function has type void(*)(kmp_int32 *ThreadID,
1770 /// kmp_int32 BoundID, struct context_vars*).
1771 /// \param CGF Reference to current CodeGenFunction.
1772 /// \param D OpenMP directive.
1773 /// \param ThreadIDVar Variable for thread id in the current OpenMP region.
1774 /// \param InnermostKind Kind of innermost directive (for simple directives it
1775 /// is a directive itself, for combined - its innermost directive).
1776 /// \param CodeGen Code generation sequence for the \a D directive.
1777 llvm::Function *emitTeamsOutlinedFunction(
1779 const VarDecl *ThreadIDVar, OpenMPDirectiveKind InnermostKind,
1780 const RegionCodeGenTy &CodeGen) override;
1781
1782 /// Emits outlined function for the OpenMP task directive \a D. This
1783 /// outlined function has type void(*)(kmp_int32 ThreadID, struct task_t*
1784 /// TaskT).
1785 /// \param D OpenMP directive.
1786 /// \param ThreadIDVar Variable for thread id in the current OpenMP region.
1787 /// \param PartIDVar Variable for partition id in the current OpenMP untied
1788 /// task region.
1789 /// \param TaskTVar Variable for task_t argument.
1790 /// \param InnermostKind Kind of innermost directive (for simple directives it
1791 /// is a directive itself, for combined - its innermost directive).
1792 /// \param CodeGen Code generation sequence for the \a D directive.
1793 /// \param Tied true if task is generated for tied task, false otherwise.
1794 /// \param NumberOfParts Number of parts in untied task. Ignored for tied
1795 /// tasks.
1796 ///
1797 llvm::Function *emitTaskOutlinedFunction(
1798 const OMPExecutableDirective &D, const VarDecl *ThreadIDVar,
1799 const VarDecl *PartIDVar, const VarDecl *TaskTVar,
1800 OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen,
1801 bool Tied, unsigned &NumberOfParts) override;
1802
1803 /// Emits code for parallel or serial call of the \a OutlinedFn with
1804 /// variables captured in a record which address is stored in \a
1805 /// CapturedStruct.
1806 /// \param OutlinedFn Outlined function to be run in parallel threads. Type of
1807 /// this function is void(*)(kmp_int32 *, kmp_int32, struct context_vars*).
1808 /// \param CapturedVars A pointer to the record with the references to
1809 /// variables used in \a OutlinedFn function.
1810 /// \param IfCond Condition in the associated 'if' clause, if it was
1811 /// specified, nullptr otherwise.
1812 /// \param NumThreads The value corresponding to the num_threads clause, if
1813 /// any, or nullptr.
1814 /// \param NumThreadsModifier The modifier of the num_threads clause, if
1815 /// any, ignored otherwise.
1816 /// \param Severity The severity corresponding to the num_threads clause, if
1817 /// any, ignored otherwise.
1818 /// \param Message The message string corresponding to the num_threads clause,
1819 /// if any, or nullptr.
1820 ///
1822 llvm::Function *OutlinedFn,
1823 ArrayRef<llvm::Value *> CapturedVars,
1824 const Expr *IfCond, llvm::Value *NumThreads,
1825 OpenMPNumThreadsClauseModifier NumThreadsModifier =
1827 OpenMPSeverityClauseKind Severity = OMPC_SEVERITY_fatal,
1828 const Expr *Message = nullptr) override;
1829
1830 /// Emits a critical region.
1831 /// \param CriticalName Name of the critical region.
1832 /// \param CriticalOpGen Generator for the statement associated with the given
1833 /// critical region.
1834 /// \param Hint Value of the 'hint' clause (optional).
1835 void emitCriticalRegion(CodeGenFunction &CGF, StringRef CriticalName,
1836 const RegionCodeGenTy &CriticalOpGen,
1837 SourceLocation Loc,
1838 const Expr *Hint = nullptr) override;
1839
1840 /// Emits a master region.
1841 /// \param MasterOpGen Generator for the statement associated with the given
1842 /// master region.
1844 const RegionCodeGenTy &MasterOpGen,
1845 SourceLocation Loc) override;
1846
1847 /// Emits a masked region.
1848 /// \param MaskedOpGen Generator for the statement associated with the given
1849 /// masked region.
1851 const RegionCodeGenTy &MaskedOpGen, SourceLocation Loc,
1852 const Expr *Filter = nullptr) override;
1853
1854 /// Emits a masked region.
1855 /// \param MaskedOpGen Generator for the statement associated with the given
1856 /// masked region.
1857
1858 /// Emits code for a taskyield directive.
1859 void emitTaskyieldCall(CodeGenFunction &CGF, SourceLocation Loc) override;
1860
1861 /// Emit a taskgroup region.
1862 /// \param TaskgroupOpGen Generator for the statement associated with the
1863 /// given taskgroup region.
1865 const RegionCodeGenTy &TaskgroupOpGen,
1866 SourceLocation Loc) override;
1867
1868 /// Emits a single region.
1869 /// \param SingleOpGen Generator for the statement associated with the given
1870 /// single region.
1872 const RegionCodeGenTy &SingleOpGen, SourceLocation Loc,
1873 ArrayRef<const Expr *> CopyprivateVars,
1874 ArrayRef<const Expr *> DestExprs,
1875 ArrayRef<const Expr *> SrcExprs,
1876 ArrayRef<const Expr *> AssignmentOps) override;
1877
1878 /// Emit an ordered region.
1879 /// \param OrderedOpGen Generator for the statement associated with the given
1880 /// ordered region.
1882 const RegionCodeGenTy &OrderedOpGen,
1883 SourceLocation Loc, bool IsThreads) override;
1884
1885 /// Emit an implicit/explicit barrier for OpenMP threads.
1886 /// \param Kind Directive for which this implicit barrier call must be
1887 /// generated. Must be OMPD_barrier for explicit barrier generation.
1888 /// \param EmitChecks true if need to emit checks for cancellation barriers.
1889 /// \param ForceSimpleCall true simple barrier call must be emitted, false if
1890 /// runtime class decides which one to emit (simple or with cancellation
1891 /// checks).
1892 ///
1894 OpenMPDirectiveKind Kind, bool EmitChecks = true,
1895 bool ForceSimpleCall = false) override;
1896
1897 /// This is used for non static scheduled types and when the ordered
1898 /// clause is present on the loop construct.
1899 /// Depending on the loop schedule, it is necessary to call some runtime
1900 /// routine before start of the OpenMP loop to get the loop upper / lower
1901 /// bounds \a LB and \a UB and stride \a ST.
1902 ///
1903 /// \param CGF Reference to current CodeGenFunction.
1904 /// \param Loc Clang source location.
1905 /// \param ScheduleKind Schedule kind, specified by the 'schedule' clause.
1906 /// \param IVSize Size of the iteration variable in bits.
1907 /// \param IVSigned Sign of the iteration variable.
1908 /// \param Ordered true if loop is ordered, false otherwise.
1909 /// \param DispatchValues struct containing llvm values for lower bound, upper
1910 /// bound, and chunk expression.
1911 /// For the default (nullptr) value, the chunk 1 will be used.
1912 ///
1914 const OpenMPScheduleTy &ScheduleKind,
1915 unsigned IVSize, bool IVSigned, bool Ordered,
1916 const DispatchRTInput &DispatchValues) override;
1917
1918 /// This is used for non static scheduled types and when the ordered
1919 /// clause is present on the loop construct.
1920 ///
1921 /// \param CGF Reference to current CodeGenFunction.
1922 /// \param Loc Clang source location.
1923 ///
1924 void emitForDispatchDeinit(CodeGenFunction &CGF, SourceLocation Loc) override;
1925
1926 /// Call the appropriate runtime routine to initialize it before start
1927 /// of loop.
1928 ///
1929 /// This is used only in case of static schedule, when the user did not
1930 /// specify a ordered clause on the loop construct.
1931 /// Depending on the loop schedule, it is necessary to call some runtime
1932 /// routine before start of the OpenMP loop to get the loop upper / lower
1933 /// bounds LB and UB and stride ST.
1934 ///
1935 /// \param CGF Reference to current CodeGenFunction.
1936 /// \param Loc Clang source location.
1937 /// \param DKind Kind of the directive.
1938 /// \param ScheduleKind Schedule kind, specified by the 'schedule' clause.
1939 /// \param Values Input arguments for the construct.
1940 ///
1942 OpenMPDirectiveKind DKind,
1943 const OpenMPScheduleTy &ScheduleKind,
1944 const StaticRTInput &Values) override;
1945
1946 ///
1947 /// \param CGF Reference to current CodeGenFunction.
1948 /// \param Loc Clang source location.
1949 /// \param SchedKind Schedule kind, specified by the 'dist_schedule' clause.
1950 /// \param Values Input arguments for the construct.
1951 ///
1954 const StaticRTInput &Values) override;
1955
1956 /// Call the appropriate runtime routine to notify that we finished
1957 /// iteration of the ordered loop with the dynamic scheduling.
1958 ///
1959 /// \param CGF Reference to current CodeGenFunction.
1960 /// \param Loc Clang source location.
1961 /// \param IVSize Size of the iteration variable in bits.
1962 /// \param IVSigned Sign of the iteration variable.
1963 ///
1965 unsigned IVSize, bool IVSigned) override;
1966
1967 /// Call the appropriate runtime routine to notify that we finished
1968 /// all the work with current loop.
1969 ///
1970 /// \param CGF Reference to current CodeGenFunction.
1971 /// \param Loc Clang source location.
1972 /// \param DKind Kind of the directive for which the static finish is emitted.
1973 ///
1975 OpenMPDirectiveKind DKind) override;
1976
1977 /// Call __kmpc_dispatch_next(
1978 /// ident_t *loc, kmp_int32 tid, kmp_int32 *p_lastiter,
1979 /// kmp_int[32|64] *p_lower, kmp_int[32|64] *p_upper,
1980 /// kmp_int[32|64] *p_stride);
1981 /// \param IVSize Size of the iteration variable in bits.
1982 /// \param IVSigned Sign of the iteration variable.
1983 /// \param IL Address of the output variable in which the flag of the
1984 /// last iteration is returned.
1985 /// \param LB Address of the output variable in which the lower iteration
1986 /// number is returned.
1987 /// \param UB Address of the output variable in which the upper iteration
1988 /// number is returned.
1989 /// \param ST Address of the output variable in which the stride value is
1990 /// returned.
1991 llvm::Value *emitForNext(CodeGenFunction &CGF, SourceLocation Loc,
1992 unsigned IVSize, bool IVSigned, Address IL,
1993 Address LB, Address UB, Address ST) override;
1994
1995 /// Emits call to void __kmpc_push_num_threads(ident_t *loc, kmp_int32
1996 /// global_tid, kmp_int32 num_threads) to generate code for 'num_threads'
1997 /// clause.
1998 /// If the modifier 'strict' is given:
1999 /// Emits call to void __kmpc_push_num_threads_strict(ident_t *loc, kmp_int32
2000 /// global_tid, kmp_int32 num_threads, int severity, const char *message) to
2001 /// generate code for 'num_threads' clause with 'strict' modifier.
2002 /// \param NumThreads An integer value of threads.
2004 CodeGenFunction &CGF, llvm::Value *NumThreads, SourceLocation Loc,
2006 OpenMPSeverityClauseKind Severity = OMPC_SEVERITY_fatal,
2007 SourceLocation SeverityLoc = SourceLocation(),
2008 const Expr *Message = nullptr,
2009 SourceLocation MessageLoc = SourceLocation()) override;
2010
2011 /// Emit call to void __kmpc_push_proc_bind(ident_t *loc, kmp_int32
2012 /// global_tid, int proc_bind) to generate code for 'proc_bind' clause.
2014 llvm::omp::ProcBindKind ProcBind,
2015 SourceLocation Loc) override;
2016
2017 /// Returns address of the threadprivate variable for the current
2018 /// thread.
2019 /// \param VD Threadprivate variable.
2020 /// \param VDAddr Address of the global variable \a VD.
2021 /// \param Loc Location of the reference to threadprivate var.
2022 /// \return Address of the threadprivate variable for the current thread.
2024 Address VDAddr, SourceLocation Loc) override;
2025
2026 /// Emit a code for initialization of threadprivate variable. It emits
2027 /// a call to runtime library which adds initial value to the newly created
2028 /// threadprivate variable (if it is not constant) and registers destructor
2029 /// for the variable (if any).
2030 /// \param VD Threadprivate variable.
2031 /// \param VDAddr Address of the global variable \a VD.
2032 /// \param Loc Location of threadprivate declaration.
2033 /// \param PerformInit true if initialization expression is not constant.
2034 llvm::Function *
2036 SourceLocation Loc, bool PerformInit,
2037 CodeGenFunction *CGF = nullptr) override;
2038
2039 /// Creates artificial threadprivate variable with name \p Name and type \p
2040 /// VarType.
2041 /// \param VarType Type of the artificial threadprivate variable.
2042 /// \param Name Name of the artificial threadprivate variable.
2044 QualType VarType,
2045 StringRef Name) override;
2046
2047 /// Emit flush of the variables specified in 'omp flush' directive.
2048 /// \param Vars List of variables to flush.
2050 SourceLocation Loc, llvm::AtomicOrdering AO) override;
2051
2052 /// Emit task region for the task directive. The task region is
2053 /// emitted in several steps:
2054 /// 1. Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32
2055 /// gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds,
2056 /// kmp_routine_entry_t *task_entry). Here task_entry is a pointer to the
2057 /// function:
2058 /// kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) {
2059 /// TaskFunction(gtid, tt->part_id, tt->shareds);
2060 /// return 0;
2061 /// }
2062 /// 2. Copy a list of shared variables to field shareds of the resulting
2063 /// structure kmp_task_t returned by the previous call (if any).
2064 /// 3. Copy a pointer to destructions function to field destructions of the
2065 /// resulting structure kmp_task_t.
2066 /// 4. Emit a call to kmp_int32 __kmpc_omp_task(ident_t *, kmp_int32 gtid,
2067 /// kmp_task_t *new_task), where new_task is a resulting structure from
2068 /// previous items.
2069 /// \param D Current task directive.
2070 /// \param TaskFunction An LLVM function with type void (*)(i32 /*gtid*/, i32
2071 /// /*part_id*/, captured_struct */*__context*/);
2072 /// \param SharedsTy A type which contains references the shared variables.
2073 /// \param Shareds Context with the list of shared variables from the \p
2074 /// TaskFunction.
2075 /// \param IfCond Not a nullptr if 'if' clause was specified, nullptr
2076 /// otherwise.
2077 /// \param Data Additional data for task generation like tiednsee, final
2078 /// state, list of privates etc.
2080 const OMPExecutableDirective &D,
2081 llvm::Function *TaskFunction, QualType SharedsTy,
2082 Address Shareds, const Expr *IfCond,
2083 const OMPTaskDataTy &Data) override;
2084
2085 /// Emit task region for the taskloop directive. The taskloop region is
2086 /// emitted in several steps:
2087 /// 1. Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32
2088 /// gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds,
2089 /// kmp_routine_entry_t *task_entry). Here task_entry is a pointer to the
2090 /// function:
2091 /// kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) {
2092 /// TaskFunction(gtid, tt->part_id, tt->shareds);
2093 /// return 0;
2094 /// }
2095 /// 2. Copy a list of shared variables to field shareds of the resulting
2096 /// structure kmp_task_t returned by the previous call (if any).
2097 /// 3. Copy a pointer to destructions function to field destructions of the
2098 /// resulting structure kmp_task_t.
2099 /// 4. Emit a call to void __kmpc_taskloop(ident_t *loc, int gtid, kmp_task_t
2100 /// *task, int if_val, kmp_uint64 *lb, kmp_uint64 *ub, kmp_int64 st, int
2101 /// nogroup, int sched, kmp_uint64 grainsize, void *task_dup ), where new_task
2102 /// is a resulting structure from
2103 /// previous items.
2104 /// \param D Current task directive.
2105 /// \param TaskFunction An LLVM function with type void (*)(i32 /*gtid*/, i32
2106 /// /*part_id*/, captured_struct */*__context*/);
2107 /// \param SharedsTy A type which contains references the shared variables.
2108 /// \param Shareds Context with the list of shared variables from the \p
2109 /// TaskFunction.
2110 /// \param IfCond Not a nullptr if 'if' clause was specified, nullptr
2111 /// otherwise.
2112 /// \param Data Additional data for task generation like tiednsee, final
2113 /// state, list of privates etc.
2115 const OMPLoopDirective &D, llvm::Function *TaskFunction,
2116 QualType SharedsTy, Address Shareds, const Expr *IfCond,
2117 const OMPTaskDataTy &Data) override;
2118
2119 /// Emit a code for reduction clause. Next code should be emitted for
2120 /// reduction:
2121 /// \code
2122 ///
2123 /// static kmp_critical_name lock = { 0 };
2124 ///
2125 /// void reduce_func(void *lhs[<n>], void *rhs[<n>]) {
2126 /// ...
2127 /// *(Type<i>*)lhs[i] = RedOp<i>(*(Type<i>*)lhs[i], *(Type<i>*)rhs[i]);
2128 /// ...
2129 /// }
2130 ///
2131 /// ...
2132 /// void *RedList[<n>] = {&<RHSExprs>[0], ..., &<RHSExprs>[<n>-1]};
2133 /// switch (__kmpc_reduce{_nowait}(<loc>, <gtid>, <n>, sizeof(RedList),
2134 /// RedList, reduce_func, &<lock>)) {
2135 /// case 1:
2136 /// ...
2137 /// <LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]);
2138 /// ...
2139 /// __kmpc_end_reduce{_nowait}(<loc>, <gtid>, &<lock>);
2140 /// break;
2141 /// case 2:
2142 /// ...
2143 /// Atomic(<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]));
2144 /// ...
2145 /// break;
2146 /// default:;
2147 /// }
2148 /// \endcode
2149 ///
2150 /// \param Privates List of private copies for original reduction arguments.
2151 /// \param LHSExprs List of LHS in \a ReductionOps reduction operations.
2152 /// \param RHSExprs List of RHS in \a ReductionOps reduction operations.
2153 /// \param ReductionOps List of reduction operations in form 'LHS binop RHS'
2154 /// or 'operator binop(LHS, RHS)'.
2155 /// \param Options List of options for reduction codegen:
2156 /// WithNowait true if parent directive has also nowait clause, false
2157 /// otherwise.
2158 /// SimpleReduction Emit reduction operation only. Used for omp simd
2159 /// directive on the host.
2160 /// ReductionKind The kind of reduction to perform.
2163 ArrayRef<const Expr *> LHSExprs,
2164 ArrayRef<const Expr *> RHSExprs,
2165 ArrayRef<const Expr *> ReductionOps,
2166 ReductionOptionsTy Options) override;
2167
2168 /// Emit a code for initialization of task reduction clause. Next code
2169 /// should be emitted for reduction:
2170 /// \code
2171 ///
2172 /// _taskred_item_t red_data[n];
2173 /// ...
2174 /// red_data[i].shar = &shareds[i];
2175 /// red_data[i].orig = &origs[i];
2176 /// red_data[i].size = sizeof(origs[i]);
2177 /// red_data[i].f_init = (void*)RedInit<i>;
2178 /// red_data[i].f_fini = (void*)RedDest<i>;
2179 /// red_data[i].f_comb = (void*)RedOp<i>;
2180 /// red_data[i].flags = <Flag_i>;
2181 /// ...
2182 /// void* tg1 = __kmpc_taskred_init(gtid, n, red_data);
2183 /// \endcode
2184 /// For reduction clause with task modifier it emits the next call:
2185 /// \code
2186 ///
2187 /// _taskred_item_t red_data[n];
2188 /// ...
2189 /// red_data[i].shar = &shareds[i];
2190 /// red_data[i].orig = &origs[i];
2191 /// red_data[i].size = sizeof(origs[i]);
2192 /// red_data[i].f_init = (void*)RedInit<i>;
2193 /// red_data[i].f_fini = (void*)RedDest<i>;
2194 /// red_data[i].f_comb = (void*)RedOp<i>;
2195 /// red_data[i].flags = <Flag_i>;
2196 /// ...
2197 /// void* tg1 = __kmpc_taskred_modifier_init(loc, gtid, is_worksharing, n,
2198 /// red_data);
2199 /// \endcode
2200 /// \param LHSExprs List of LHS in \a Data.ReductionOps reduction operations.
2201 /// \param RHSExprs List of RHS in \a Data.ReductionOps reduction operations.
2202 /// \param Data Additional data for task generation like tiedness, final
2203 /// state, list of privates, reductions etc.
2205 ArrayRef<const Expr *> LHSExprs,
2206 ArrayRef<const Expr *> RHSExprs,
2207 const OMPTaskDataTy &Data) override;
2208
2209 /// Emits the following code for reduction clause with task modifier:
2210 /// \code
2211 /// __kmpc_task_reduction_modifier_fini(loc, gtid, is_worksharing);
2212 /// \endcode
2214 bool IsWorksharingReduction) override;
2215
2216 /// Required to resolve existing problems in the runtime. Emits threadprivate
2217 /// variables to store the size of the VLAs/array sections for
2218 /// initializer/combiner/finalizer functions + emits threadprivate variable to
2219 /// store the pointer to the original reduction item for the custom
2220 /// initializer defined by declare reduction construct.
2221 /// \param RCG Allows to reuse an existing data for the reductions.
2222 /// \param N Reduction item for which fixups must be emitted.
2224 ReductionCodeGen &RCG, unsigned N) override;
2225
2226 /// Get the address of `void *` type of the privatue copy of the reduction
2227 /// item specified by the \p SharedLVal.
2228 /// \param ReductionsPtr Pointer to the reduction data returned by the
2229 /// emitTaskReductionInit function.
2230 /// \param SharedLVal Address of the original reduction item.
2232 llvm::Value *ReductionsPtr,
2233 LValue SharedLVal) override;
2234
2235 /// Emit code for 'taskwait' directive.
2237 const OMPTaskDataTy &Data) override;
2238
2239 /// Emit code for 'cancellation point' construct.
2240 /// \param CancelRegion Region kind for which the cancellation point must be
2241 /// emitted.
2242 ///
2244 OpenMPDirectiveKind CancelRegion) override;
2245
2246 /// Emit code for 'cancel' construct.
2247 /// \param IfCond Condition in the associated 'if' clause, if it was
2248 /// specified, nullptr otherwise.
2249 /// \param CancelRegion Region kind for which the cancel must be emitted.
2250 ///
2252 const Expr *IfCond,
2253 OpenMPDirectiveKind CancelRegion) override;
2254
2255 /// Emit outilined function for 'target' directive.
2256 /// \param D Directive to emit.
2257 /// \param ParentName Name of the function that encloses the target region.
2258 /// \param OutlinedFn Outlined function value to be defined by this call.
2259 /// \param OutlinedFnID Outlined function ID value to be defined by this call.
2260 /// \param IsOffloadEntry True if the outlined function is an offload entry.
2261 /// \param CodeGen Code generation sequence for the \a D directive.
2262 /// An outlined function may not be an entry if, e.g. the if clause always
2263 /// evaluates to false.
2265 StringRef ParentName,
2266 llvm::Function *&OutlinedFn,
2267 llvm::Constant *&OutlinedFnID,
2268 bool IsOffloadEntry,
2269 const RegionCodeGenTy &CodeGen) override;
2270
2271 /// Emit the target offloading code associated with \a D. The emitted
2272 /// code attempts offloading the execution to the device, an the event of
2273 /// a failure it executes the host version outlined in \a OutlinedFn.
2274 /// \param D Directive to emit.
2275 /// \param OutlinedFn Host version of the code to be offloaded.
2276 /// \param OutlinedFnID ID of host version of the code to be offloaded.
2277 /// \param IfCond Expression evaluated in if clause associated with the target
2278 /// directive, or null if no if clause is used.
2279 /// \param Device Expression evaluated in device clause associated with the
2280 /// target directive, or null if no device clause is used and device modifier.
2281 void emitTargetCall(
2283 llvm::Function *OutlinedFn, llvm::Value *OutlinedFnID, const Expr *IfCond,
2284 llvm::PointerIntPair<const Expr *, 2, OpenMPDeviceClauseModifier> Device,
2285 llvm::function_ref<llvm::Value *(CodeGenFunction &CGF,
2286 const OMPLoopDirective &D)>
2287 SizeEmitter) override;
2288
2289 /// Emit the target regions enclosed in \a GD function definition or
2290 /// the function itself in case it is a valid device function. Returns true if
2291 /// \a GD was dealt with successfully.
2292 /// \param GD Function to scan.
2293 bool emitTargetFunctions(GlobalDecl GD) override;
2294
2295 /// Emit the global variable if it is a valid device global variable.
2296 /// Returns true if \a GD was dealt with successfully.
2297 /// \param GD Variable declaration to emit.
2298 bool emitTargetGlobalVariable(GlobalDecl GD) override;
2299
2300 /// Emit the global \a GD if it is meaningful for the target. Returns
2301 /// if it was emitted successfully.
2302 /// \param GD Global to scan.
2303 bool emitTargetGlobal(GlobalDecl GD) override;
2304
2305 /// Emits code for teams call of the \a OutlinedFn with
2306 /// variables captured in a record which address is stored in \a
2307 /// CapturedStruct.
2308 /// \param OutlinedFn Outlined function to be run by team masters. Type of
2309 /// this function is void(*)(kmp_int32 *, kmp_int32, struct context_vars*).
2310 /// \param CapturedVars A pointer to the record with the references to
2311 /// variables used in \a OutlinedFn function.
2312 ///
2314 SourceLocation Loc, llvm::Function *OutlinedFn,
2315 ArrayRef<llvm::Value *> CapturedVars) override;
2316
2317 /// Emits call to void __kmpc_push_num_teams(ident_t *loc, kmp_int32
2318 /// global_tid, kmp_int32 num_teams, kmp_int32 thread_limit) to generate code
2319 /// for num_teams clause.
2320 /// \param NumTeams An integer expression of teams.
2321 /// \param ThreadLimit An integer expression of threads.
2322 void emitNumTeamsClause(CodeGenFunction &CGF, const Expr *NumTeams,
2323 const Expr *ThreadLimit, SourceLocation Loc) override;
2324
2325 /// Emit the target data mapping code associated with \a D.
2326 /// \param D Directive to emit.
2327 /// \param IfCond Expression evaluated in if clause associated with the
2328 /// target directive, or null if no device clause is used.
2329 /// \param Device Expression evaluated in device clause associated with the
2330 /// target directive, or null if no device clause is used.
2331 /// \param Info A record used to store information that needs to be preserved
2332 /// until the region is closed.
2334 const OMPExecutableDirective &D, const Expr *IfCond,
2335 const Expr *Device, const RegionCodeGenTy &CodeGen,
2336 CGOpenMPRuntime::TargetDataInfo &Info) override;
2337
2338 /// Emit the data mapping/movement code associated with the directive
2339 /// \a D that should be of the form 'target [{enter|exit} data | update]'.
2340 /// \param D Directive to emit.
2341 /// \param IfCond Expression evaluated in if clause associated with the target
2342 /// directive, or null if no if clause is used.
2343 /// \param Device Expression evaluated in device clause associated with the
2344 /// target directive, or null if no device clause is used.
2346 const OMPExecutableDirective &D,
2347 const Expr *IfCond,
2348 const Expr *Device) override;
2349
2350 /// Emit initialization for doacross loop nesting support.
2351 /// \param D Loop-based construct used in doacross nesting construct.
2353 ArrayRef<Expr *> NumIterations) override;
2354
2355 /// Emit code for doacross ordered directive with 'depend' clause.
2356 /// \param C 'depend' clause with 'sink|source' dependency kind.
2358 const OMPDependClause *C) override;
2359
2360 /// Emit code for doacross ordered directive with 'doacross' clause.
2361 /// \param C 'doacross' clause with 'sink|source' dependence type.
2363 const OMPDoacrossClause *C) override;
2364
2365 /// Translates the native parameter of outlined function if this is required
2366 /// for target.
2367 /// \param FD Field decl from captured record for the parameter.
2368 /// \param NativeParam Parameter itself.
2369 const VarDecl *translateParameter(const FieldDecl *FD,
2370 const VarDecl *NativeParam) const override;
2371
2372 /// Gets the address of the native argument basing on the address of the
2373 /// target-specific parameter.
2374 /// \param NativeParam Parameter itself.
2375 /// \param TargetParam Corresponding target-specific parameter.
2376 Address getParameterAddress(CodeGenFunction &CGF, const VarDecl *NativeParam,
2377 const VarDecl *TargetParam) const override;
2378
2379 /// Gets the OpenMP-specific address of the local variable.
2381 const VarDecl *VD) override {
2382 return Address::invalid();
2383 }
2384};
2385
2386} // namespace CodeGen
2387// Utility for openmp doacross clause kind
2388namespace {
2389template <typename T> class OMPDoacrossKind {
2390public:
2391 bool isSink(const T *) { return false; }
2392 bool isSource(const T *) { return false; }
2393};
2394template <> class OMPDoacrossKind<OMPDependClause> {
2395public:
2396 bool isSink(const OMPDependClause *C) {
2397 return C->getDependencyKind() == OMPC_DEPEND_sink;
2398 }
2399 bool isSource(const OMPDependClause *C) {
2400 return C->getDependencyKind() == OMPC_DEPEND_source;
2401 }
2402};
2403template <> class OMPDoacrossKind<OMPDoacrossClause> {
2404public:
2405 bool isSource(const OMPDoacrossClause *C) {
2406 return C->getDependenceType() == OMPC_DOACROSS_source ||
2407 C->getDependenceType() == OMPC_DOACROSS_source_omp_cur_iteration;
2408 }
2409 bool isSink(const OMPDoacrossClause *C) {
2410 return C->getDependenceType() == OMPC_DOACROSS_sink ||
2411 C->getDependenceType() == OMPC_DOACROSS_sink_omp_cur_iteration;
2412 }
2413};
2414} // namespace
2415} // namespace clang
2416
2417#endif
This file defines OpenMP nodes for declarative directives.
Defines some OpenMP-specific enums and functions.
Defines the clang::SourceLocation class and associated facilities.
C Language Family Type Representation.
This represents implicit clause 'depend' for the 'pragma omp task' directive.
This represents the 'doacross' clause for the 'pragma omp ordered' directive.
This is a common base class for loop directives ('omp simd', 'omp for', 'omp for simd' etc....
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:246
Represents a C++ constructor within a class.
Definition DeclCXX.h:2645
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
A wrapper class around a pointer that always points to its canonical declaration.
Like RawAddress, an abstract representation of an aligned address, but the pointer contained in this ...
Definition Address.h:128
static Address invalid()
Definition Address.h:176
static LastprivateConditionalRAII disable(CodeGenFunction &CGF, const OMPExecutableDirective &S)
NontemporalDeclsRAII(CodeGenModule &CGM, const OMPLoopDirective &S)
Struct that keeps all the relevant information that should be kept throughout a 'target data' region.
llvm::DenseMap< const ValueDecl *, llvm::Value * > CaptureDeviceAddrMap
Map between the a declaration of a capture and the corresponding new llvm address where the runtime r...
TargetDataInfo(bool RequiresDevicePointerInfo, bool SeparateBeginEndCalls)
UntiedTaskLocalDeclsRAII(CodeGenFunction &CGF, const llvm::MapVector< CanonicalDeclPtr< const VarDecl >, std::pair< Address, Address > > &LocalVars)
virtual Address emitThreadIDAddress(CodeGenFunction &CGF, SourceLocation Loc)
Emits address of the word in a memory where current thread id is stored.
virtual bool canPromoteToNoLoop(const OMPLoopDirective &S) const
Check whether S is the loop the target kernel being emitted was promoted for, to complete the promoti...
llvm::StringSet ThreadPrivateWithDefinition
Set of threadprivate variables with the generated initializer.
void emitUpdateDependObjectsClause(CodeGenFunction &CGF, LValue DepobjLVal, OpenMPDependClauseKind NewDepKind, SourceLocation Loc)
Updates the dependency kind in the specified depobj object.
virtual void getKmpcFreeShared(CodeGenFunction &CGF, const std::pair< llvm::Value *, llvm::Value * > &AddrSizePair)
Get call to __kmpc_free_shared.
virtual void emitTaskCall(CodeGenFunction &CGF, SourceLocation Loc, const OMPExecutableDirective &D, llvm::Function *TaskFunction, QualType SharedsTy, Address Shareds, const Expr *IfCond, const OMPTaskDataTy &Data)
Emit task region for the task directive.
void createOffloadEntriesAndInfoMetadata()
Creates all the offload entries in the current compilation unit along with the associated metadata.
const Expr * getNumTeamsExprForTargetDirective(CodeGenFunction &CGF, const OMPExecutableDirective &D, int32_t &MinTeamsVal, int32_t &MaxTeamsVal)
Emit the number of teams for a target directive.
virtual Address getAddrOfThreadPrivate(CodeGenFunction &CGF, const VarDecl *VD, Address VDAddr, SourceLocation Loc)
Returns address of the threadprivate variable for the current thread.
void emitDeferredTargetDecls() const
Emit deferred declare target variables marked for deferred emission.
virtual llvm::Value * emitForNext(CodeGenFunction &CGF, SourceLocation Loc, unsigned IVSize, bool IVSigned, Address IL, Address LB, Address UB, Address ST)
Call __kmpc_dispatch_next( ident_t *loc, kmp_int32 tid, kmp_int32 *p_lastiter, kmp_int[32|64] *p_lowe...
bool markAsGlobalTarget(GlobalDecl GD)
Marks the declaration as already emitted for the device code and returns true, if it was marked alrea...
virtual void emitParallelCall(CodeGenFunction &CGF, SourceLocation Loc, llvm::Function *OutlinedFn, ArrayRef< llvm::Value * > CapturedVars, const Expr *IfCond, llvm::Value *NumThreads, OpenMPNumThreadsClauseModifier NumThreadsModifier=OMPC_NUMTHREADS_unknown, OpenMPSeverityClauseKind Severity=OMPC_SEVERITY_fatal, const Expr *Message=nullptr)
Emits code for parallel or serial call of the OutlinedFn with variables captured in a record which ad...
llvm::SmallDenseSet< CanonicalDeclPtr< const Decl > > NontemporalDeclsSet
virtual void emitTargetDataStandAloneCall(CodeGenFunction &CGF, const OMPExecutableDirective &D, const Expr *IfCond, const Expr *Device)
Emit the data mapping/movement code associated with the directive D that should be of the form 'targe...
virtual void emitNumThreadsClause(CodeGenFunction &CGF, llvm::Value *NumThreads, SourceLocation Loc, OpenMPNumThreadsClauseModifier Modifier=OMPC_NUMTHREADS_unknown, OpenMPSeverityClauseKind Severity=OMPC_SEVERITY_fatal, SourceLocation SeverityLoc=SourceLocation(), const Expr *Message=nullptr, SourceLocation MessageLoc=SourceLocation())
Emits call to void __kmpc_push_num_threads(ident_t *loc, kmp_int32global_tid, kmp_int32 num_threads) ...
QualType SavedKmpTaskloopTQTy
Saved kmp_task_t for taskloop-based directive.
virtual void emitSingleRegion(CodeGenFunction &CGF, const RegionCodeGenTy &SingleOpGen, SourceLocation Loc, ArrayRef< const Expr * > CopyprivateVars, ArrayRef< const Expr * > DestExprs, ArrayRef< const Expr * > SrcExprs, ArrayRef< const Expr * > AssignmentOps)
Emits a single region.
virtual bool emitTargetGlobal(GlobalDecl GD)
Emit the global GD if it is meaningful for the target.
void setLocThreadIdInsertPt(CodeGenFunction &CGF, bool AtCurrentPoint=false)
std::string getOutlinedHelperName(StringRef Name) const
Get the function name of an outlined region.
StringRef getTargetRegionParentName(const FunctionDecl *FD) const
Returns the parent name of the target regions in FD: its enclosing non-closure function if FD is a cl...
bool HasEmittedDeclareTargetRegion
Flag for keeping track of weather a device routine has been emitted.
llvm::Constant * getOrCreateThreadPrivateCache(const VarDecl *VD)
If the specified mangled name is not in the module, create and return threadprivate cache object.
virtual Address getTaskReductionItem(CodeGenFunction &CGF, SourceLocation Loc, llvm::Value *ReductionsPtr, LValue SharedLVal)
Get the address of void * type of the privatue copy of the reduction item specified by the SharedLVal...
virtual void emitForDispatchDeinit(CodeGenFunction &CGF, SourceLocation Loc)
This is used for non static scheduled types and when the ordered clause is present on the loop constr...
void emitCall(CodeGenFunction &CGF, SourceLocation Loc, llvm::FunctionCallee Callee, ArrayRef< llvm::Value * > Args={}) const
Emits Callee function call with arguments Args with location Loc.
virtual void getDefaultScheduleAndChunk(CodeGenFunction &CGF, const OMPLoopDirective &S, OpenMPScheduleClauseKind &ScheduleKind, const Expr *&ChunkExpr) const
Choose default schedule type and chunk value for the schedule clause.
virtual std::pair< llvm::Function *, llvm::Function * > getUserDefinedReduction(const OMPDeclareReductionDecl *D)
Get combiner/initializer for the specified user-defined reduction, if any.
virtual bool isGPU() const
Returns true if the current target is a GPU.
static const Stmt * getSingleCompoundChild(ASTContext &Ctx, const Stmt *Body)
Checks if the Body is the CompoundStmt and returns its child statement iff there is only one that is ...
virtual void emitDeclareTargetFunction(const FunctionDecl *FD, llvm::GlobalValue *GV)
Emit code for handling declare target functions in the runtime.
bool HasRequiresUnifiedSharedMemory
Flag for keeping track of weather a requires unified_shared_memory directive is present.
llvm::Value * emitUpdateLocation(CodeGenFunction &CGF, SourceLocation Loc, unsigned Flags=0, bool EmitLoc=false)
Emits object of ident_t type with info for source location.
bool isLocalVarInUntiedTask(CodeGenFunction &CGF, const VarDecl *VD) const
Returns true if the variable is a local variable in untied task.
virtual void emitTeamsCall(CodeGenFunction &CGF, const OMPExecutableDirective &D, SourceLocation Loc, llvm::Function *OutlinedFn, ArrayRef< llvm::Value * > CapturedVars)
Emits code for teams call of the OutlinedFn with variables captured in a record which address is stor...
virtual void emitCancellationPointCall(CodeGenFunction &CGF, SourceLocation Loc, OpenMPDirectiveKind CancelRegion)
Emit code for 'cancellation point' construct.
llvm::DenseMap< llvm::Function *, SmallVector< const OMPDeclareMapperDecl *, 4 > > FunctionUDMMapTy
Map of functions and their local user-defined mappers.
virtual const VarDecl * translateParameter(const FieldDecl *FD, const VarDecl *NativeParam) const
Translates the native parameter of outlined function if this is required for target.
llvm::DenseMap< llvm::Function *, SmallVector< const OMPDeclareReductionDecl *, 4 > > FunctionUDRMapTy
Map of functions and locally defined UDRs.
virtual llvm::Function * emitThreadPrivateVarDefinition(const VarDecl *VD, Address VDAddr, SourceLocation Loc, bool PerformInit, CodeGenFunction *CGF=nullptr)
Emit a code for initialization of threadprivate variable.
virtual bool isDefaultLocationConstant() const
Check if the default location must be constant.
virtual ConstantAddress getAddrOfDeclareTargetVar(const VarDecl *VD)
Returns the address of the variable marked as declare target with link clause OR as declare target wi...
llvm::Function * getOrCreateUserDefinedMapperFunc(const OMPDeclareMapperDecl *D)
Get the function for the specified user-defined mapper.
OpenMPLocThreadIDMapTy OpenMPLocThreadIDMap
virtual void functionFinished(CodeGenFunction &CGF)
Cleans up references to the objects in finished function.
virtual llvm::Function * emitTeamsOutlinedFunction(CodeGenFunction &CGF, const OMPExecutableDirective &D, const VarDecl *ThreadIDVar, OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen)
Emits outlined function for the specified OpenMP teams directive D.
llvm::DenseMap< llvm::Function *, DebugLocThreadIdTy > OpenMPLocThreadIDMapTy
Map of local debug location, ThreadId and functions.
QualType KmpTaskTQTy
Type typedef struct kmp_task { void * shareds; /‍**< pointer to block of pointers to shared vars ‍/ k...
llvm::OpenMPIRBuilder OMPBuilder
An OpenMP-IR-Builder instance.
virtual void emitDoacrossInit(CodeGenFunction &CGF, const OMPLoopDirective &D, ArrayRef< Expr * > NumIterations)
Emit initialization for doacross loop nesting support.
virtual void adjustTargetSpecificDataForLambdas(CodeGenFunction &CGF, const OMPExecutableDirective &D) const
Adjust some parameters for the target-based directives, like addresses of the variables captured by r...
virtual void emitTargetDataCalls(CodeGenFunction &CGF, const OMPExecutableDirective &D, const Expr *IfCond, const Expr *Device, const RegionCodeGenTy &CodeGen, CGOpenMPRuntime::TargetDataInfo &Info)
Emit the target data mapping code associated with D.
virtual unsigned getDefaultLocationReserved2Flags() const
Returns additional flags that can be stored in reserved_2 field of the default location.
virtual Address getParameterAddress(CodeGenFunction &CGF, const VarDecl *NativeParam, const VarDecl *TargetParam) const
Gets the address of the native argument basing on the address of the target-specific parameter.
void emitUsesAllocatorsFini(CodeGenFunction &CGF, const Expr *Allocator)
Destroys user defined allocators specified in the uses_allocators clause.
QualType KmpTaskAffinityInfoTy
Type typedef struct kmp_task_affinity_info { kmp_intptr_t base_addr; size_t len; struct { bool flag1 ...
llvm::SmallVector< NontemporalDeclsSet, 4 > NontemporalDeclsStack
Stack for list of declarations in current context marked as nontemporal.
void emitPrivateReduction(CodeGenFunction &CGF, SourceLocation Loc, const Expr *Privates, const Expr *LHSExprs, const Expr *RHSExprs, const Expr *ReductionOps)
Emits code for private variable reduction.
llvm::Value * emitNumTeamsForTargetDirective(CodeGenFunction &CGF, const OMPExecutableDirective &D)
virtual void emitTargetOutlinedFunctionHelper(const OMPExecutableDirective &D, StringRef ParentName, llvm::Function *&OutlinedFn, llvm::Constant *&OutlinedFnID, bool IsOffloadEntry, const RegionCodeGenTy &CodeGen)
Helper to emit outlined function for 'target' directive.
void scanForTargetRegionsFunctions(const Stmt *S, StringRef ParentName)
Start scanning from statement S and emit all target regions found along the way.
SmallVector< llvm::Value *, 4 > emitDepobjElementsSizes(CodeGenFunction &CGF, QualType &KmpDependInfoTy, const OMPTaskDataTy::DependData &Data)
virtual llvm::Value * emitMessageClause(CodeGenFunction &CGF, const Expr *Message, SourceLocation Loc)
virtual void emitTaskgroupRegion(CodeGenFunction &CGF, const RegionCodeGenTy &TaskgroupOpGen, SourceLocation Loc)
Emit a taskgroup region.
llvm::DenseMap< llvm::Function *, llvm::DenseMap< CanonicalDeclPtr< const Decl >, std::tuple< QualType, const FieldDecl *, const FieldDecl *, LValue > > > LastprivateConditionalToTypes
Maps local variables marked as lastprivate conditional to their internal types.
virtual bool emitTargetGlobalVariable(GlobalDecl GD)
Emit the global variable if it is a valid device global variable.
virtual void emitNumTeamsClause(CodeGenFunction &CGF, const Expr *NumTeams, const Expr *ThreadLimit, SourceLocation Loc)
Emits call to void __kmpc_push_num_teams(ident_t *loc, kmp_int32global_tid, kmp_int32 num_teams,...
bool hasRequiresUnifiedSharedMemory() const
Return whether the unified_shared_memory has been specified.
virtual Address getAddrOfArtificialThreadPrivate(CodeGenFunction &CGF, QualType VarType, StringRef Name)
Creates artificial threadprivate variable with name Name and type VarType.
void emitUserDefinedMapper(const OMPDeclareMapperDecl *D, CodeGenFunction *CGF=nullptr)
Emit the function for the user defined mapper construct.
llvm::DenseMap< SourceLocation, llvm::Value * > OpenMPDebugLocMapTy
Map for SourceLocation and OpenMP runtime library debug locations.
bool HasEmittedTargetRegion
Flag for keeping track of weather a target region has been emitted.
void emitDepobjElements(CodeGenFunction &CGF, QualType &KmpDependInfoTy, LValue PosLVal, const OMPTaskDataTy::DependData &Data, Address DependenciesArray)
std::string getReductionFuncName(StringRef Name) const
Get the function name of a reduction function.
virtual void processRequiresDirective(const OMPRequiresDecl *D)
Perform check on requires decl to ensure that target architecture supports unified addressing.
llvm::DenseSet< CanonicalDeclPtr< const Decl > > AlreadyEmittedTargetDecls
List of the emitted declarations.
virtual llvm::Value * emitTaskReductionInit(CodeGenFunction &CGF, SourceLocation Loc, ArrayRef< const Expr * > LHSExprs, ArrayRef< const Expr * > RHSExprs, const OMPTaskDataTy &Data)
Emit a code for initialization of task reduction clause.
llvm::Value * getThreadID(CodeGenFunction &CGF, SourceLocation Loc)
Gets thread id value for the current thread.
virtual void emitLastprivateConditionalFinalUpdate(CodeGenFunction &CGF, LValue PrivLVal, const VarDecl *VD, SourceLocation Loc)
Gets the address of the global copy used for lastprivate conditional update, if any.
llvm::MapVector< CanonicalDeclPtr< const VarDecl >, std::pair< Address, Address > > UntiedLocalVarsAddressesMap
virtual void emitErrorCall(CodeGenFunction &CGF, SourceLocation Loc, Expr *ME, bool IsFatal)
Emit __kmpc_error call for error directive extern void __kmpc_error(ident_t *loc, int severity,...
void clearLocThreadIdInsertPt(CodeGenFunction &CGF)
virtual void emitTaskyieldCall(CodeGenFunction &CGF, SourceLocation Loc)
Emits code for a taskyield directive.
virtual std::pair< llvm::Value *, llvm::Value * > getKmpcAllocShared(CodeGenFunction &CGF, const VarDecl *VD)
Get call to __kmpc_alloc_shared.
std::string getName(ArrayRef< StringRef > Parts) const
Get the platform-specific name separator.
void computeMinAndMaxThreadsAndTeams(const OMPExecutableDirective &D, CodeGenFunction &CGF, llvm::OpenMPIRBuilder::TargetKernelDefaultAttrs &Attrs)
Helper to determine the min/max number of threads/teams for D.
virtual void emitFlush(CodeGenFunction &CGF, ArrayRef< const Expr * > Vars, SourceLocation Loc, llvm::AtomicOrdering AO)
Emit flush of the variables specified in 'omp flush' directive.
virtual void emitTaskwaitCall(CodeGenFunction &CGF, SourceLocation Loc, const OMPTaskDataTy &Data)
Emit code for 'taskwait' directive.
virtual void emitProcBindClause(CodeGenFunction &CGF, llvm::omp::ProcBindKind ProcBind, SourceLocation Loc)
Emit call to void __kmpc_push_proc_bind(ident_t *loc, kmp_int32global_tid, int proc_bind) to generate...
void emitLastprivateConditionalUpdate(CodeGenFunction &CGF, LValue IVLVal, StringRef UniqueDeclName, LValue LVal, SourceLocation Loc)
Emit update for lastprivate conditional data.
virtual void emitTaskLoopCall(CodeGenFunction &CGF, SourceLocation Loc, const OMPLoopDirective &D, llvm::Function *TaskFunction, QualType SharedsTy, Address Shareds, const Expr *IfCond, const OMPTaskDataTy &Data)
Emit task region for the taskloop directive.
virtual void emitBarrierCall(CodeGenFunction &CGF, SourceLocation Loc, OpenMPDirectiveKind Kind, bool EmitChecks=true, bool ForceSimpleCall=false)
Emit an implicit/explicit barrier for OpenMP threads.
static unsigned getDefaultFlagsForBarriers(OpenMPDirectiveKind Kind)
Returns default flags for the barriers depending on the directive, for which this barier is going to ...
virtual bool isDelayedVariableLengthDecl(CodeGenFunction &CGF, const VarDecl *VD) const
Check if the variable length declaration is delayed:
virtual bool emitTargetFunctions(GlobalDecl GD)
Emit the target regions enclosed in GD function definition or the function itself in case it is a val...
TaskResultTy emitTaskInit(CodeGenFunction &CGF, SourceLocation Loc, const OMPExecutableDirective &D, llvm::Function *TaskFunction, QualType SharedsTy, Address Shareds, const OMPTaskDataTy &Data)
Emit task region for the task directive.
llvm::Value * emitTargetNumIterationsCall(CodeGenFunction &CGF, const OMPExecutableDirective &D, llvm::function_ref< llvm::Value *(CodeGenFunction &CGF, const OMPLoopDirective &D)> SizeEmitter)
Return the trip count of loops associated with constructs / 'target teams distribute' and 'teams dist...
llvm::StringMap< llvm::AssertingVH< llvm::GlobalVariable >, llvm::BumpPtrAllocator > InternalVars
An ordered map of auto-generated variables to their unique names.
virtual void emitDistributeStaticInit(CodeGenFunction &CGF, SourceLocation Loc, OpenMPDistScheduleClauseKind SchedKind, const StaticRTInput &Values)
llvm::SmallVector< UntiedLocalVarsAddressesMap, 4 > UntiedLocalVarsStack
virtual void emitForStaticFinish(CodeGenFunction &CGF, SourceLocation Loc, OpenMPDirectiveKind DKind)
Call the appropriate runtime routine to notify that we finished all the work with current loop.
virtual void emitThreadLimitClause(CodeGenFunction &CGF, const Expr *ThreadLimit, SourceLocation Loc)
Emits call to void __kmpc_set_thread_limit(ident_t *loc, kmp_int32global_tid, kmp_int32 thread_limit)...
void emitIfClause(CodeGenFunction &CGF, const Expr *Cond, const RegionCodeGenTy &ThenGen, const RegionCodeGenTy &ElseGen)
Emits code for OpenMP 'if' clause using specified CodeGen function.
Address emitDepobjDependClause(CodeGenFunction &CGF, const OMPTaskDataTy::DependData &Dependencies, SourceLocation Loc)
Emits list of dependecies based on the provided data (array of dependence/expression pairs) for depob...
bool isNontemporalDecl(const ValueDecl *VD) const
Checks if the VD variable is marked as nontemporal declaration in current context.
virtual llvm::Function * emitParallelOutlinedFunction(CodeGenFunction &CGF, const OMPExecutableDirective &D, const VarDecl *ThreadIDVar, OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen)
Emits outlined function for the specified OpenMP parallel directive D.
const Expr * getNumThreadsExprForTargetDirective(CodeGenFunction &CGF, const OMPExecutableDirective &D, int32_t &UpperBound, bool UpperBoundOnly, llvm::Value **CondExpr=nullptr, const Expr **ThreadLimitExpr=nullptr)
Check for a number of threads upper bound constant value (stored in UpperBound), or expression (retur...
virtual void registerVTableOffloadEntry(llvm::GlobalVariable *VTable, const VarDecl *VD)
Register VTable to OpenMP offload entry.
virtual llvm::Value * emitSeverityClause(OpenMPSeverityClauseKind Severity, SourceLocation Loc)
llvm::SmallVector< LastprivateConditionalData, 4 > LastprivateConditionalStack
Stack for list of addresses of declarations in current context marked as lastprivate conditional.
virtual void emitForStaticInit(CodeGenFunction &CGF, SourceLocation Loc, OpenMPDirectiveKind DKind, const OpenMPScheduleTy &ScheduleKind, const StaticRTInput &Values)
Call the appropriate runtime routine to initialize it before start of loop.
virtual void emitDeclareSimdFunction(const FunctionDecl *FD, llvm::Function *Fn)
Marks function Fn with properly mangled versions of vector functions.
llvm::AtomicOrdering getDefaultMemoryOrdering() const
Gets default memory ordering as specified in requires directive.
llvm::StringSet DeclareTargetWithDefinition
Set of declare target variables with the generated initializer.
virtual bool isStaticNonchunked(OpenMPScheduleClauseKind ScheduleKind, bool Chunked) const
Check if the specified ScheduleKind is static non-chunked.
virtual void emitAndRegisterVTable(CodeGenModule &CGM, CXXRecordDecl *CXXRecord, const VarDecl *VD)
Emit and register VTable for the C++ class in OpenMP offload entry.
void scanConstructorForTargetRegions(const CXXConstructorDecl *Ctor, StringRef ParentName)
Scans the mem-initializers and the body of Ctor for target regions.
llvm::Value * getCriticalRegionLock(StringRef CriticalName)
Returns corresponding lock object for the specified critical region name.
virtual void emitCancelCall(CodeGenFunction &CGF, SourceLocation Loc, const Expr *IfCond, OpenMPDirectiveKind CancelRegion)
Emit code for 'cancel' construct.
QualType SavedKmpTaskTQTy
Saved kmp_task_t for task directive.
virtual void emitMasterRegion(CodeGenFunction &CGF, const RegionCodeGenTy &MasterOpGen, SourceLocation Loc)
Emits a master region.
virtual llvm::Function * emitTaskOutlinedFunction(const OMPExecutableDirective &D, const VarDecl *ThreadIDVar, const VarDecl *PartIDVar, const VarDecl *TaskTVar, OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen, bool Tied, unsigned &NumberOfParts)
Emits outlined function for the OpenMP task directive D.
OpenMPDebugLocMapTy OpenMPDebugLocMap
llvm::DenseMap< llvm::Function *, unsigned > FunctionToUntiedTaskStackMap
Maps function to the position of the untied task locals stack.
void emitHostKernelEnvironment(const OMPExecutableDirective &D, CodeGenFunction &CGF)
Emit the '<kernel>_kernel_environment' global for a target region that is compiled for a non-GPU (hos...
void emitDestroyClause(CodeGenFunction &CGF, LValue DepobjLVal, SourceLocation Loc)
Emits the code to destroy the dependency object provided in depobj directive.
virtual void emitTaskReductionFixups(CodeGenFunction &CGF, SourceLocation Loc, ReductionCodeGen &RCG, unsigned N)
Required to resolve existing problems in the runtime.
llvm::ArrayType * KmpCriticalNameTy
Type kmp_critical_name, originally defined as typedef kmp_int32 kmp_critical_name[8];.
virtual void emitDoacrossOrdered(CodeGenFunction &CGF, const OMPDependClause *C)
Emit code for doacross ordered directive with 'depend' clause.
llvm::DenseMap< const OMPDeclareMapperDecl *, llvm::Function * > UDMMap
Map from the user-defined mapper declaration to its corresponding functions.
virtual void checkAndEmitLastprivateConditional(CodeGenFunction &CGF, const Expr *LHS)
Checks if the provided LVal is lastprivate conditional and emits the code to update the value of the ...
std::pair< llvm::Value *, LValue > getDepobjElements(CodeGenFunction &CGF, LValue DepobjLVal, SourceLocation Loc)
Returns the number of the elements and the address of the depobj dependency array.
llvm::SmallDenseSet< const VarDecl * > DeferredGlobalVariables
List of variables that can become declare target implicitly and, thus, must be emitted.
void emitUsesAllocatorsInit(CodeGenFunction &CGF, const Expr *Allocator, const Expr *AllocatorTraits)
Initializes user defined allocators specified in the uses_allocators clauses.
virtual void getDefaultDistScheduleAndChunk(CodeGenFunction &CGF, const OMPLoopDirective &S, OpenMPDistScheduleClauseKind &ScheduleKind, llvm::Value *&Chunk) const
Choose default schedule type and chunk value for the dist_schedule clause.
llvm::DenseMap< const OMPDeclareReductionDecl *, std::pair< llvm::Function *, llvm::Function * > > UDRMapTy
Map of UDRs and corresponding combiner/initializer.
virtual void registerVTable(const OMPExecutableDirective &D)
Emit code for registering vtable by scanning through map clause in OpenMP target region.
llvm::Type * KmpRoutineEntryPtrTy
Type typedef kmp_int32 (* kmp_routine_entry_t)(kmp_int32, void *);.
llvm::Type * getIdentTyPointerTy()
Returns pointer to ident_t type.
void emitSingleReductionCombiner(CodeGenFunction &CGF, const Expr *ReductionOp, const Expr *PrivateRef, const DeclRefExpr *LHS, const DeclRefExpr *RHS)
Emits single reduction combiner.
llvm::OpenMPIRBuilder & getOMPBuilder()
virtual void emitTargetOutlinedFunction(const OMPExecutableDirective &D, StringRef ParentName, llvm::Function *&OutlinedFn, llvm::Constant *&OutlinedFnID, bool IsOffloadEntry, const RegionCodeGenTy &CodeGen)
Emit outilined function for 'target' directive.
virtual void emitCriticalRegion(CodeGenFunction &CGF, StringRef CriticalName, const RegionCodeGenTy &CriticalOpGen, SourceLocation Loc, const Expr *Hint=nullptr)
Emits a critical region.
virtual void emitForOrderedIterationEnd(CodeGenFunction &CGF, SourceLocation Loc, unsigned IVSize, bool IVSigned)
Call the appropriate runtime routine to notify that we finished iteration of the ordered loop with th...
virtual void emitOutlinedFunctionCall(CodeGenFunction &CGF, SourceLocation Loc, llvm::FunctionCallee OutlinedFn, ArrayRef< llvm::Value * > Args={}) const
Emits call of the outlined function with the provided arguments, translating these arguments to corre...
llvm::Value * emitNumThreadsForTargetDirective(CodeGenFunction &CGF, const OMPExecutableDirective &D)
Emit an expression that denotes the number of threads a target region shall use.
void emitThreadPrivateVarInit(CodeGenFunction &CGF, Address VDAddr, llvm::Value *Ctor, llvm::Value *CopyCtor, llvm::Value *Dtor, SourceLocation Loc)
Emits initialization code for the threadprivate variables.
virtual void emitUserDefinedReduction(CodeGenFunction *CGF, const OMPDeclareReductionDecl *D)
Emit code for the specified user defined reduction construct.
virtual void checkAndEmitSharedLastprivateConditional(CodeGenFunction &CGF, const OMPExecutableDirective &D, const llvm::DenseSet< CanonicalDeclPtr< const VarDecl > > &IgnoredDecls)
Checks if the lastprivate conditional was updated in inner region and writes the value.
QualType KmpDimTy
struct kmp_dim { // loop bounds info casted to kmp_int64 kmp_int64 lo; // lower kmp_int64 up; // uppe...
llvm::SmallPtrSet< const CXXConstructorDecl *, 8 > ScannedImplicitCtors
Implicitly-defined constructors already scanned for target regions; only lambdas can hold such region...
virtual void emitInlinedDirective(CodeGenFunction &CGF, OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen, bool HasCancel=false)
Emit code for the directive that does not require outlining.
virtual void registerTargetGlobalVariable(const VarDecl *VD, llvm::Constant *Addr)
Checks if the provided global decl GD is a declare target variable and registers it when emitting cod...
virtual void emitFunctionProlog(CodeGenFunction &CGF, const Decl *D)
Emits OpenMP-specific function prolog.
void emitKmpRoutineEntryT(QualType KmpInt32Ty)
Build type kmp_routine_entry_t (if not built yet).
llvm::SmallDenseMap< CXXRecordDecl *, const VarDecl * > VTableDeclMap
Keep track of VTable Declarations so we don't register duplicate VTable.
virtual bool isStaticChunked(OpenMPScheduleClauseKind ScheduleKind, bool Chunked) const
Check if the specified ScheduleKind is static chunked.
virtual void emitTargetCall(CodeGenFunction &CGF, const OMPExecutableDirective &D, llvm::Function *OutlinedFn, llvm::Value *OutlinedFnID, const Expr *IfCond, llvm::PointerIntPair< const Expr *, 2, OpenMPDeviceClauseModifier > Device, llvm::function_ref< llvm::Value *(CodeGenFunction &CGF, const OMPLoopDirective &D)> SizeEmitter)
Emit the target offloading code associated with D.
virtual bool hasAllocateAttributeForGlobalVar(const VarDecl *VD, LangAS &AS)
Checks if the variable has associated OMPAllocateDeclAttr attribute with the predefined allocator and...
llvm::AtomicOrdering RequiresAtomicOrdering
Atomic ordering from the omp requires directive.
virtual void emitReduction(CodeGenFunction &CGF, SourceLocation Loc, ArrayRef< const Expr * > Privates, ArrayRef< const Expr * > LHSExprs, ArrayRef< const Expr * > RHSExprs, ArrayRef< const Expr * > ReductionOps, ReductionOptionsTy Options)
Emit a code for reduction clause.
std::pair< llvm::Value *, Address > emitDependClause(CodeGenFunction &CGF, ArrayRef< OMPTaskDataTy::DependData > Dependencies, SourceLocation Loc)
Emits list of dependecies based on the provided data (array of dependence/expression pairs).
llvm::StringMap< llvm::WeakTrackingVH > EmittedNonTargetVariables
List of the global variables with their addresses that should not be emitted for the target.
virtual bool isDynamic(OpenMPScheduleClauseKind ScheduleKind) const
Check if the specified ScheduleKind is dynamic.
Address emitLastprivateConditionalInit(CodeGenFunction &CGF, const VarDecl *VD)
Create specialized alloca to handle lastprivate conditionals.
llvm::ArrayType * getKmpCriticalNameTy() const
Get the LLVM type for the critical name.
virtual void emitOrderedRegion(CodeGenFunction &CGF, const RegionCodeGenTy &OrderedOpGen, SourceLocation Loc, bool IsThreads)
Emit an ordered region.
virtual Address getAddressOfLocalVariable(CodeGenFunction &CGF, const VarDecl *VD)
Gets the OpenMP-specific address of the local variable.
virtual void emitTaskReductionFini(CodeGenFunction &CGF, SourceLocation Loc, bool IsWorksharingReduction)
Emits the following code for reduction clause with task modifier:
virtual void emitMaskedRegion(CodeGenFunction &CGF, const RegionCodeGenTy &MaskedOpGen, SourceLocation Loc, const Expr *Filter=nullptr)
Emits a masked region.
QualType KmpDependInfoTy
Type typedef struct kmp_depend_info { kmp_intptr_t base_addr; size_t len; struct { bool in:1; bool ou...
llvm::Function * emitReductionFunction(StringRef ReducerName, SourceLocation Loc, llvm::Type *ArgsElemType, ArrayRef< const Expr * > Privates, ArrayRef< const Expr * > LHSExprs, ArrayRef< const Expr * > RHSExprs, ArrayRef< const Expr * > ReductionOps)
Emits reduction function.
virtual void emitForDispatchInit(CodeGenFunction &CGF, SourceLocation Loc, const OpenMPScheduleTy &ScheduleKind, unsigned IVSize, bool IVSigned, bool Ordered, const DispatchRTInput &DispatchValues)
Call the appropriate runtime routine to initialize it before start of loop.
Address getTaskReductionItem(CodeGenFunction &CGF, SourceLocation Loc, llvm::Value *ReductionsPtr, LValue SharedLVal) override
Get the address of void * type of the privatue copy of the reduction item specified by the SharedLVal...
void emitCriticalRegion(CodeGenFunction &CGF, StringRef CriticalName, const RegionCodeGenTy &CriticalOpGen, SourceLocation Loc, const Expr *Hint=nullptr) override
Emits a critical region.
void emitDistributeStaticInit(CodeGenFunction &CGF, SourceLocation Loc, OpenMPDistScheduleClauseKind SchedKind, const StaticRTInput &Values) override
void emitForStaticInit(CodeGenFunction &CGF, SourceLocation Loc, OpenMPDirectiveKind DKind, const OpenMPScheduleTy &ScheduleKind, const StaticRTInput &Values) override
Call the appropriate runtime routine to initialize it before start of loop.
bool emitTargetGlobalVariable(GlobalDecl GD) override
Emit the global variable if it is a valid device global variable.
llvm::Value * emitForNext(CodeGenFunction &CGF, SourceLocation Loc, unsigned IVSize, bool IVSigned, Address IL, Address LB, Address UB, Address ST) override
Call __kmpc_dispatch_next( ident_t *loc, kmp_int32 tid, kmp_int32 *p_lastiter, kmp_int[32|64] *p_lowe...
llvm::Function * emitThreadPrivateVarDefinition(const VarDecl *VD, Address VDAddr, SourceLocation Loc, bool PerformInit, CodeGenFunction *CGF=nullptr) override
Emit a code for initialization of threadprivate variable.
void emitTargetDataStandAloneCall(CodeGenFunction &CGF, const OMPExecutableDirective &D, const Expr *IfCond, const Expr *Device) override
Emit the data mapping/movement code associated with the directive D that should be of the form 'targe...
llvm::Function * emitTeamsOutlinedFunction(CodeGenFunction &CGF, const OMPExecutableDirective &D, const VarDecl *ThreadIDVar, OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen) override
Emits outlined function for the specified OpenMP teams directive D.
void emitParallelCall(CodeGenFunction &CGF, SourceLocation Loc, llvm::Function *OutlinedFn, ArrayRef< llvm::Value * > CapturedVars, const Expr *IfCond, llvm::Value *NumThreads, OpenMPNumThreadsClauseModifier NumThreadsModifier=OMPC_NUMTHREADS_unknown, OpenMPSeverityClauseKind Severity=OMPC_SEVERITY_fatal, const Expr *Message=nullptr) override
Emits code for parallel or serial call of the OutlinedFn with variables captured in a record which ad...
void emitReduction(CodeGenFunction &CGF, SourceLocation Loc, ArrayRef< const Expr * > Privates, ArrayRef< const Expr * > LHSExprs, ArrayRef< const Expr * > RHSExprs, ArrayRef< const Expr * > ReductionOps, ReductionOptionsTy Options) override
Emit a code for reduction clause.
void emitFlush(CodeGenFunction &CGF, ArrayRef< const Expr * > Vars, SourceLocation Loc, llvm::AtomicOrdering AO) override
Emit flush of the variables specified in 'omp flush' directive.
void emitDoacrossOrdered(CodeGenFunction &CGF, const OMPDependClause *C) override
Emit code for doacross ordered directive with 'depend' clause.
void emitTaskyieldCall(CodeGenFunction &CGF, SourceLocation Loc) override
Emits a masked region.
Address getAddrOfArtificialThreadPrivate(CodeGenFunction &CGF, QualType VarType, StringRef Name) override
Creates artificial threadprivate variable with name Name and type VarType.
Address getAddrOfThreadPrivate(CodeGenFunction &CGF, const VarDecl *VD, Address VDAddr, SourceLocation Loc) override
Returns address of the threadprivate variable for the current thread.
void emitSingleRegion(CodeGenFunction &CGF, const RegionCodeGenTy &SingleOpGen, SourceLocation Loc, ArrayRef< const Expr * > CopyprivateVars, ArrayRef< const Expr * > DestExprs, ArrayRef< const Expr * > SrcExprs, ArrayRef< const Expr * > AssignmentOps) override
Emits a single region.
void emitTaskReductionFixups(CodeGenFunction &CGF, SourceLocation Loc, ReductionCodeGen &RCG, unsigned N) override
Required to resolve existing problems in the runtime.
llvm::Function * emitParallelOutlinedFunction(CodeGenFunction &CGF, const OMPExecutableDirective &D, const VarDecl *ThreadIDVar, OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen) override
Emits outlined function for the specified OpenMP parallel directive D.
void emitCancellationPointCall(CodeGenFunction &CGF, SourceLocation Loc, OpenMPDirectiveKind CancelRegion) override
Emit code for 'cancellation point' construct.
void emitBarrierCall(CodeGenFunction &CGF, SourceLocation Loc, OpenMPDirectiveKind Kind, bool EmitChecks=true, bool ForceSimpleCall=false) override
Emit an implicit/explicit barrier for OpenMP threads.
Address getAddressOfLocalVariable(CodeGenFunction &CGF, const VarDecl *VD) override
Gets the OpenMP-specific address of the local variable.
Address getParameterAddress(CodeGenFunction &CGF, const VarDecl *NativeParam, const VarDecl *TargetParam) const override
Gets the address of the native argument basing on the address of the target-specific parameter.
void emitTeamsCall(CodeGenFunction &CGF, const OMPExecutableDirective &D, SourceLocation Loc, llvm::Function *OutlinedFn, ArrayRef< llvm::Value * > CapturedVars) override
Emits code for teams call of the OutlinedFn with variables captured in a record which address is stor...
void emitForOrderedIterationEnd(CodeGenFunction &CGF, SourceLocation Loc, unsigned IVSize, bool IVSigned) override
Call the appropriate runtime routine to notify that we finished iteration of the ordered loop with th...
bool emitTargetGlobal(GlobalDecl GD) override
Emit the global GD if it is meaningful for the target.
void emitTaskReductionFini(CodeGenFunction &CGF, SourceLocation Loc, bool IsWorksharingReduction) override
Emits the following code for reduction clause with task modifier:
void emitOrderedRegion(CodeGenFunction &CGF, const RegionCodeGenTy &OrderedOpGen, SourceLocation Loc, bool IsThreads) override
Emit an ordered region.
void emitForStaticFinish(CodeGenFunction &CGF, SourceLocation Loc, OpenMPDirectiveKind DKind) override
Call the appropriate runtime routine to notify that we finished all the work with current loop.
llvm::Value * emitTaskReductionInit(CodeGenFunction &CGF, SourceLocation Loc, ArrayRef< const Expr * > LHSExprs, ArrayRef< const Expr * > RHSExprs, const OMPTaskDataTy &Data) override
Emit a code for initialization of task reduction clause.
void emitProcBindClause(CodeGenFunction &CGF, llvm::omp::ProcBindKind ProcBind, SourceLocation Loc) override
Emit call to void __kmpc_push_proc_bind(ident_t *loc, kmp_int32global_tid, int proc_bind) to generate...
void emitTargetOutlinedFunction(const OMPExecutableDirective &D, StringRef ParentName, llvm::Function *&OutlinedFn, llvm::Constant *&OutlinedFnID, bool IsOffloadEntry, const RegionCodeGenTy &CodeGen) override
Emit outilined function for 'target' directive.
void emitMasterRegion(CodeGenFunction &CGF, const RegionCodeGenTy &MasterOpGen, SourceLocation Loc) override
Emits a master region.
void emitNumTeamsClause(CodeGenFunction &CGF, const Expr *NumTeams, const Expr *ThreadLimit, SourceLocation Loc) override
Emits call to void __kmpc_push_num_teams(ident_t *loc, kmp_int32global_tid, kmp_int32 num_teams,...
void emitForDispatchDeinit(CodeGenFunction &CGF, SourceLocation Loc) override
This is used for non static scheduled types and when the ordered clause is present on the loop constr...
const VarDecl * translateParameter(const FieldDecl *FD, const VarDecl *NativeParam) const override
Translates the native parameter of outlined function if this is required for target.
void emitNumThreadsClause(CodeGenFunction &CGF, llvm::Value *NumThreads, SourceLocation Loc, OpenMPNumThreadsClauseModifier Modifier=OMPC_NUMTHREADS_unknown, OpenMPSeverityClauseKind Severity=OMPC_SEVERITY_fatal, SourceLocation SeverityLoc=SourceLocation(), const Expr *Message=nullptr, SourceLocation MessageLoc=SourceLocation()) override
Emits call to void __kmpc_push_num_threads(ident_t *loc, kmp_int32global_tid, kmp_int32 num_threads) ...
void emitMaskedRegion(CodeGenFunction &CGF, const RegionCodeGenTy &MaskedOpGen, SourceLocation Loc, const Expr *Filter=nullptr) override
Emits a masked region.
void emitTaskCall(CodeGenFunction &CGF, SourceLocation Loc, const OMPExecutableDirective &D, llvm::Function *TaskFunction, QualType SharedsTy, Address Shareds, const Expr *IfCond, const OMPTaskDataTy &Data) override
Emit task region for the task directive.
void emitTargetCall(CodeGenFunction &CGF, const OMPExecutableDirective &D, llvm::Function *OutlinedFn, llvm::Value *OutlinedFnID, const Expr *IfCond, llvm::PointerIntPair< const Expr *, 2, OpenMPDeviceClauseModifier > Device, llvm::function_ref< llvm::Value *(CodeGenFunction &CGF, const OMPLoopDirective &D)> SizeEmitter) override
Emit the target offloading code associated with D.
bool emitTargetFunctions(GlobalDecl GD) override
Emit the target regions enclosed in GD function definition or the function itself in case it is a val...
void emitDoacrossInit(CodeGenFunction &CGF, const OMPLoopDirective &D, ArrayRef< Expr * > NumIterations) override
Emit initialization for doacross loop nesting support.
void emitCancelCall(CodeGenFunction &CGF, SourceLocation Loc, const Expr *IfCond, OpenMPDirectiveKind CancelRegion) override
Emit code for 'cancel' construct.
void emitTaskwaitCall(CodeGenFunction &CGF, SourceLocation Loc, const OMPTaskDataTy &Data) override
Emit code for 'taskwait' directive.
void emitTaskgroupRegion(CodeGenFunction &CGF, const RegionCodeGenTy &TaskgroupOpGen, SourceLocation Loc) override
Emit a taskgroup region.
void emitTargetDataCalls(CodeGenFunction &CGF, const OMPExecutableDirective &D, const Expr *IfCond, const Expr *Device, const RegionCodeGenTy &CodeGen, CGOpenMPRuntime::TargetDataInfo &Info) override
Emit the target data mapping code associated with D.
void emitForDispatchInit(CodeGenFunction &CGF, SourceLocation Loc, const OpenMPScheduleTy &ScheduleKind, unsigned IVSize, bool IVSigned, bool Ordered, const DispatchRTInput &DispatchValues) override
This is used for non static scheduled types and when the ordered clause is present on the loop constr...
llvm::Function * emitTaskOutlinedFunction(const OMPExecutableDirective &D, const VarDecl *ThreadIDVar, const VarDecl *PartIDVar, const VarDecl *TaskTVar, OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen, bool Tied, unsigned &NumberOfParts) override
Emits outlined function for the OpenMP task directive D.
void emitTaskLoopCall(CodeGenFunction &CGF, SourceLocation Loc, const OMPLoopDirective &D, llvm::Function *TaskFunction, QualType SharedsTy, Address Shareds, const Expr *IfCond, const OMPTaskDataTy &Data) override
Emit task region for the taskloop directive.
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
This class organizes the cross-function state that is used while generating LLVM code.
A specialization of Address that requires the address to be an LLVM Constant.
Definition Address.h:296
LValue - This represents an lvalue references.
Definition CGValue.h:183
A basic class for pre|post-action for advanced codegen sequence for OpenMP region.
virtual void Exit(CodeGenFunction &CGF)
virtual void Enter(CodeGenFunction &CGF)
Class intended to support codegen of all kind of the reduction clauses.
LValue getSharedLValue(unsigned N) const
Returns LValue for the reduction item.
const Expr * getRefExpr(unsigned N) const
Returns the base declaration of the reduction item.
LValue getOrigLValue(unsigned N) const
Returns LValue for the original reduction item.
bool needCleanups(unsigned N)
Returns true if the private copy requires cleanups.
void emitAggregateType(CodeGenFunction &CGF, unsigned N)
Emits the code for the variable-modified type, if required.
const VarDecl * getBaseDecl(unsigned N) const
Returns the base declaration of the reduction item.
QualType getPrivateType(unsigned N) const
Return the type of the private item.
bool usesReductionInitializer(unsigned N) const
Returns true if the initialization of the reduction item uses initializer from declare reduction cons...
void emitSharedOrigLValue(CodeGenFunction &CGF, unsigned N)
Emits lvalue for the shared and original reduction item.
void emitInitialization(CodeGenFunction &CGF, unsigned N, Address PrivateAddr, Address SharedAddr, llvm::function_ref< bool(CodeGenFunction &)> DefaultInit)
Performs initialization of the private copy for the reduction item.
std::pair< llvm::Value *, llvm::Value * > getSizes(unsigned N) const
Returns the size of the reduction item (in chars and total number of elements in the item),...
ReductionCodeGen(ArrayRef< const Expr * > Shareds, ArrayRef< const Expr * > Origs, ArrayRef< const Expr * > Privates, ArrayRef< const Expr * > ReductionOps)
void emitCleanups(CodeGenFunction &CGF, unsigned N, Address PrivateAddr)
Emits cleanup code for the reduction item.
Address adjustPrivateAddress(CodeGenFunction &CGF, unsigned N, Address PrivateAddr)
Adjusts PrivatedAddr for using instead of the original variable address in normal operations.
Class provides a way to call simple version of codegen for OpenMP region, or an advanced with possibl...
RegionCodeGenTy(Callable &&CodeGen, std::enable_if_t<!std::is_same< std::remove_reference_t< Callable >, RegionCodeGenTy >::value > *=nullptr)
void operator()(CodeGenFunction &CGF) const
void setAction(PrePostActionTy &Action) const
A reference to a declared variable, function, enum, etc.
Definition Expr.h:1315
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
This represents one expression.
Definition Expr.h:114
Represents a member of a struct/union/class.
Definition Decl.h:3346
Represents a function declaration or definition.
Definition Decl.h:2082
GlobalDecl - represents a global declaration.
Definition GlobalDecl.h:60
This represents 'pragma omp declare mapper ...' directive.
Definition DeclOpenMP.h:349
This represents 'pragma omp declare reduction ...' directive.
Definition DeclOpenMP.h:239
This represents 'pragma omp requires...' directive.
Definition DeclOpenMP.h:479
A (possibly-)qualified type.
Definition TypeBase.h:938
Represents a struct/union/class.
Definition Decl.h:4512
Encodes a location in the source.
Stmt - This represents one statement.
Definition Stmt.h:85
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition Decl.h:714
Represents a variable declaration or definition.
Definition Decl.h:934
Top level wrappers for InstallAPI frontend operations.
Privates[]
This class represents the 'transparent' clause in the 'pragma omp task' directive.
@ Private
'private' clause, allowed on 'parallel', 'serial', 'loop', 'parallel loop', and 'serial loop' constru...
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
OpenMPDistScheduleClauseKind
OpenMP attributes for 'dist_schedule' clause.
OpenMPDependClauseKind
OpenMP attributes for 'depend' clause.
Definition OpenMPKinds.h:55
@ OMPC_DEPEND_unknown
Definition OpenMPKinds.h:59
OpenMPSeverityClauseKind
OpenMP attributes for 'severity' clause.
LangAS
Defines the address space values used by the address space qualifier of QualType.
llvm::omp::Directive OpenMPDirectiveKind
OpenMP directives.
Definition OpenMPKinds.h:25
OpenMPNumThreadsClauseModifier
@ OMPC_NUMTHREADS_unknown
U cast(CodeGen::Address addr)
Definition Address.h:327
OpenMPScheduleClauseKind
OpenMP attributes for 'schedule' clause.
Definition OpenMPKinds.h:31
Diagnostic wrappers for TextAPI types for error reporting.
Definition Dominators.h:30
__INTPTR_TYPE__ intptr_t
A signed integer type with the property that any valid pointer to void can be converted to this type,...
__builtin_elementwise_add_sat __builtin_elementwise_sub_sat int32_t
Stores debug location and ThreadID for the function.
llvm::AssertingVH< llvm::Instruction > ServiceInsertPt
Insert point for the service instructions.
llvm::Value * Chunk
Chunk size specified using 'schedule' clause (nullptr if chunk was not specified)
DispatchRTInput(llvm::Value *LB, llvm::Value *UB, llvm::Value *Chunk)
Maps the expression for the lastprivate variable to the global copy used to store new value because o...
llvm::MapVector< CanonicalDeclPtr< const Decl >, SmallString< 16 > > DeclToUniqueName
StaticRTInput(unsigned IVSize, bool IVSigned, bool Ordered, Address IL, Address LB, Address UB, Address ST, llvm::Value *Chunk=nullptr)
bool IVSigned
Sign of the iteration variable.
Address UB
Address of the output variable in which the upper iteration number is returned.
Address IL
Address of the output variable in which the flag of the last iteration is returned.
llvm::Value * Chunk
Value of the chunk for the static_chunked scheduled loop.
unsigned IVSize
Size of the iteration variable in bits.
Address ST
Address of the output variable in which the stride value is returned necessary to generated the stati...
bool Ordered
true if loop is ordered, false otherwise.
Address LB
Address of the output variable in which the lower iteration number is returned.
DependData(OpenMPDependClauseKind DepKind, const Expr *IteratorExpr)
SmallVector< const Expr *, 4 > DepExprs
SmallVector< const Expr *, 4 > FirstprivateVars
SmallVector< CanonicalDeclPtr< const VarDecl >, 4 > PrivateLocals
SmallVector< const Expr *, 4 > LastprivateCopies
SmallVector< const Expr *, 4 > PrivateCopies
SmallVector< const Expr *, 4 > ReductionVars
llvm::PointerIntPair< llvm::Value *, 1, bool > Schedule
SmallVector< const Expr *, 4 > FirstprivateInits
llvm::PointerIntPair< llvm::Value *, 1, bool > Priority
SmallVector< const Expr *, 4 > ReductionOps
SmallVector< DependData, 4 > Dependences
SmallVector< const Expr *, 4 > ReductionCopies
SmallVector< const Expr *, 4 > PrivateVars
llvm::PointerIntPair< llvm::Value *, 1, bool > Final
SmallVector< const Expr *, 4 > FirstprivateCopies
SmallVector< const Expr *, 4 > LastprivateVars
SmallVector< const Expr *, 4 > ReductionOrigs
Scheduling data for loop-based OpenMP directives.