clang  8.0.0svn
CGOpenMPRuntime.h
Go to the documentation of this file.
1 //===----- CGOpenMPRuntime.h - Interface to OpenMP Runtimes -----*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This provides a class for OpenMP runtime code generation.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CLANG_LIB_CODEGEN_CGOPENMPRUNTIME_H
15 #define LLVM_CLANG_LIB_CODEGEN_CGOPENMPRUNTIME_H
16 
17 #include "CGValue.h"
18 #include "clang/AST/Type.h"
21 #include "llvm/ADT/DenseMap.h"
22 #include "llvm/ADT/StringMap.h"
23 #include "llvm/ADT/StringSet.h"
24 #include "llvm/IR/Function.h"
25 #include "llvm/IR/ValueHandle.h"
26 
27 namespace llvm {
28 class ArrayType;
29 class Constant;
30 class FunctionType;
31 class GlobalVariable;
32 class StructType;
33 class Type;
34 class Value;
35 } // namespace llvm
36 
37 namespace clang {
38 class Expr;
39 class GlobalDecl;
40 class OMPDependClause;
41 class OMPExecutableDirective;
42 class OMPLoopDirective;
43 class VarDecl;
44 class OMPDeclareReductionDecl;
45 class IdentifierInfo;
46 
47 namespace CodeGen {
48 class Address;
49 class CodeGenFunction;
50 class CodeGenModule;
51 
52 /// A basic class for pre|post-action for advanced codegen sequence for OpenMP
53 /// region.
55 public:
56  explicit PrePostActionTy() {}
57  virtual void Enter(CodeGenFunction &CGF) {}
58  virtual void Exit(CodeGenFunction &CGF) {}
59  virtual ~PrePostActionTy() {}
60 };
61 
62 /// Class provides a way to call simple version of codegen for OpenMP region, or
63 /// an advanced with possible pre|post-actions in codegen.
64 class RegionCodeGenTy final {
65  intptr_t CodeGen;
66  typedef void (*CodeGenTy)(intptr_t, CodeGenFunction &, PrePostActionTy &);
67  CodeGenTy Callback;
68  mutable PrePostActionTy *PrePostAction;
69  RegionCodeGenTy() = delete;
70  RegionCodeGenTy &operator=(const RegionCodeGenTy &) = delete;
71  template <typename Callable>
72  static void CallbackFn(intptr_t CodeGen, CodeGenFunction &CGF,
73  PrePostActionTy &Action) {
74  return (*reinterpret_cast<Callable *>(CodeGen))(CGF, Action);
75  }
76 
77 public:
78  template <typename Callable>
80  Callable &&CodeGen,
81  typename std::enable_if<
82  !std::is_same<typename std::remove_reference<Callable>::type,
83  RegionCodeGenTy>::value>::type * = nullptr)
84  : CodeGen(reinterpret_cast<intptr_t>(&CodeGen)),
85  Callback(CallbackFn<typename std::remove_reference<Callable>::type>),
86  PrePostAction(nullptr) {}
87  void setAction(PrePostActionTy &Action) const { PrePostAction = &Action; }
88  void operator()(CodeGenFunction &CGF) const;
89 };
90 
91 struct OMPTaskDataTy final {
103  llvm::PointerIntPair<llvm::Value *, 1, bool> Final;
104  llvm::PointerIntPair<llvm::Value *, 1, bool> Schedule;
105  llvm::PointerIntPair<llvm::Value *, 1, bool> Priority;
106  llvm::Value *Reductions = nullptr;
107  unsigned NumberOfParts = 0;
108  bool Tied = true;
109  bool Nogroup = false;
110 };
111 
112 /// Class intended to support codegen of all kind of the reduction clauses.
114 private:
115  /// Data required for codegen of reduction clauses.
116  struct ReductionData {
117  /// Reference to the original shared item.
118  const Expr *Ref = nullptr;
119  /// Helper expression for generation of private copy.
120  const Expr *Private = nullptr;
121  /// Helper expression for generation reduction operation.
122  const Expr *ReductionOp = nullptr;
123  ReductionData(const Expr *Ref, const Expr *Private, const Expr *ReductionOp)
124  : Ref(Ref), Private(Private), ReductionOp(ReductionOp) {}
125  };
126  /// List of reduction-based clauses.
127  SmallVector<ReductionData, 4> ClausesData;
128 
129  /// List of addresses of original shared variables/expressions.
130  SmallVector<std::pair<LValue, LValue>, 4> SharedAddresses;
131  /// Sizes of the reduction items in chars.
133  /// Base declarations for the reduction items.
135 
136  /// Emits lvalue for shared expression.
137  LValue emitSharedLValue(CodeGenFunction &CGF, const Expr *E);
138  /// Emits upper bound for shared expression (if array section).
139  LValue emitSharedLValueUB(CodeGenFunction &CGF, const Expr *E);
140  /// Performs aggregate initialization.
141  /// \param N Number of reduction item in the common list.
142  /// \param PrivateAddr Address of the corresponding private item.
143  /// \param SharedLVal Address of the original shared variable.
144  /// \param DRD Declare reduction construct used for reduction item.
145  void emitAggregateInitialization(CodeGenFunction &CGF, unsigned N,
146  Address PrivateAddr, LValue SharedLVal,
147  const OMPDeclareReductionDecl *DRD);
148 
149 public:
152  ArrayRef<const Expr *> ReductionOps);
153  /// Emits lvalue for a reduction item.
154  /// \param N Number of the reduction item.
155  void emitSharedLValue(CodeGenFunction &CGF, unsigned N);
156  /// Emits the code for the variable-modified type, if required.
157  /// \param N Number of the reduction item.
158  void emitAggregateType(CodeGenFunction &CGF, unsigned N);
159  /// Emits the code for the variable-modified type, if required.
160  /// \param N Number of the reduction item.
161  /// \param Size Size of the type in chars.
162  void emitAggregateType(CodeGenFunction &CGF, unsigned N, llvm::Value *Size);
163  /// Performs initialization of the private copy for the reduction item.
164  /// \param N Number of the reduction item.
165  /// \param PrivateAddr Address of the corresponding private item.
166  /// \param DefaultInit Default initialization sequence that should be
167  /// performed if no reduction specific initialization is found.
168  /// \param SharedLVal Address of the original shared variable.
169  void
170  emitInitialization(CodeGenFunction &CGF, unsigned N, Address PrivateAddr,
171  LValue SharedLVal,
172  llvm::function_ref<bool(CodeGenFunction &)> DefaultInit);
173  /// Returns true if the private copy requires cleanups.
174  bool needCleanups(unsigned N);
175  /// Emits cleanup code for the reduction item.
176  /// \param N Number of the reduction item.
177  /// \param PrivateAddr Address of the corresponding private item.
178  void emitCleanups(CodeGenFunction &CGF, unsigned N, Address PrivateAddr);
179  /// Adjusts \p PrivatedAddr for using instead of the original variable
180  /// address in normal operations.
181  /// \param N Number of the reduction item.
182  /// \param PrivateAddr Address of the corresponding private item.
183  Address adjustPrivateAddress(CodeGenFunction &CGF, unsigned N,
184  Address PrivateAddr);
185  /// Returns LValue for the reduction item.
186  LValue getSharedLValue(unsigned N) const { return SharedAddresses[N].first; }
187  /// Returns the size of the reduction item (in chars and total number of
188  /// elements in the item), or nullptr, if the size is a constant.
189  std::pair<llvm::Value *, llvm::Value *> getSizes(unsigned N) const {
190  return Sizes[N];
191  }
192  /// Returns the base declaration of the reduction item.
193  const VarDecl *getBaseDecl(unsigned N) const { return BaseDecls[N]; }
194  /// Returns the base declaration of the reduction item.
195  const Expr *getRefExpr(unsigned N) const { return ClausesData[N].Ref; }
196  /// Returns true if the initialization of the reduction item uses initializer
197  /// from declare reduction construct.
198  bool usesReductionInitializer(unsigned N) const;
199 };
200 
202 public:
203  /// Allows to disable automatic handling of functions used in target regions
204  /// as those marked as `omp declare target`.
206  CodeGenModule &CGM;
207  bool SavedShouldMarkAsGlobal;
208 
209  public:
212  };
213 
214 protected:
216  StringRef FirstSeparator, Separator;
217 
218  /// Constructor allowing to redefine the name separator for the variables.
219  explicit CGOpenMPRuntime(CodeGenModule &CGM, StringRef FirstSeparator,
220  StringRef Separator);
221 
222  /// Creates offloading entry for the provided entry ID \a ID,
223  /// address \a Addr, size \a Size, and flags \a Flags.
224  virtual void createOffloadEntry(llvm::Constant *ID, llvm::Constant *Addr,
225  uint64_t Size, int32_t Flags,
226  llvm::GlobalValue::LinkageTypes Linkage);
227 
228  /// Helper to emit outlined function for 'target' directive.
229  /// \param D Directive to emit.
230  /// \param ParentName Name of the function that encloses the target region.
231  /// \param OutlinedFn Outlined function value to be defined by this call.
232  /// \param OutlinedFnID Outlined function ID value to be defined by this call.
233  /// \param IsOffloadEntry True if the outlined function is an offload entry.
234  /// \param CodeGen Lambda codegen specific to an accelerator device.
235  /// An outlined function may not be an entry if, e.g. the if clause always
236  /// evaluates to false.
237  virtual void emitTargetOutlinedFunctionHelper(const OMPExecutableDirective &D,
238  StringRef ParentName,
239  llvm::Function *&OutlinedFn,
240  llvm::Constant *&OutlinedFnID,
241  bool IsOffloadEntry,
242  const RegionCodeGenTy &CodeGen);
243 
244  /// Emits code for OpenMP 'if' clause using specified \a CodeGen
245  /// function. Here is the logic:
246  /// if (Cond) {
247  /// ThenGen();
248  /// } else {
249  /// ElseGen();
250  /// }
251  void emitOMPIfClause(CodeGenFunction &CGF, const Expr *Cond,
252  const RegionCodeGenTy &ThenGen,
253  const RegionCodeGenTy &ElseGen);
254 
255  /// Emits object of ident_t type with info for source location.
256  /// \param Flags Flags for OpenMP location.
257  ///
258  llvm::Value *emitUpdateLocation(CodeGenFunction &CGF, SourceLocation Loc,
259  unsigned Flags = 0);
260 
261  /// Returns pointer to ident_t type.
262  llvm::Type *getIdentTyPointerTy();
263 
264  /// Gets thread id value for the current thread.
265  ///
266  llvm::Value *getThreadID(CodeGenFunction &CGF, SourceLocation Loc);
267 
268  /// Get the function name of an outlined region.
269  // The name can be customized depending on the target.
270  //
271  virtual StringRef getOutlinedHelperName() const { return ".omp_outlined."; }
272 
273  /// Emits \p Callee function call with arguments \p Args with location \p Loc.
274  void emitCall(CodeGenFunction &CGF, SourceLocation Loc, llvm::Value *Callee,
275  ArrayRef<llvm::Value *> Args = llvm::None) const;
276 
277  /// Emits address of the word in a memory where current thread id is
278  /// stored.
279  virtual Address emitThreadIDAddress(CodeGenFunction &CGF, SourceLocation Loc);
280 
281  void setLocThreadIdInsertPt(CodeGenFunction &CGF,
282  bool AtCurrentPoint = false);
283  void clearLocThreadIdInsertPt(CodeGenFunction &CGF);
284 
285 private:
286  /// Default const ident_t object used for initialization of all other
287  /// ident_t objects.
288  llvm::Constant *DefaultOpenMPPSource = nullptr;
289  /// Map of flags and corresponding default locations.
290  typedef llvm::DenseMap<unsigned, llvm::Value *> OpenMPDefaultLocMapTy;
291  OpenMPDefaultLocMapTy OpenMPDefaultLocMap;
292  Address getOrCreateDefaultLocation(unsigned Flags);
293 
294  QualType IdentQTy;
295  llvm::StructType *IdentTy = nullptr;
296  /// Map for SourceLocation and OpenMP runtime library debug locations.
297  typedef llvm::DenseMap<unsigned, llvm::Value *> OpenMPDebugLocMapTy;
298  OpenMPDebugLocMapTy OpenMPDebugLocMap;
299  /// The type for a microtask which gets passed to __kmpc_fork_call().
300  /// Original representation is:
301  /// typedef void (kmpc_micro)(kmp_int32 global_tid, kmp_int32 bound_tid,...);
302  llvm::FunctionType *Kmpc_MicroTy = nullptr;
303  /// Stores debug location and ThreadID for the function.
304  struct DebugLocThreadIdTy {
305  llvm::Value *DebugLoc;
306  llvm::Value *ThreadID;
307  /// Insert point for the service instructions.
308  llvm::AssertingVH<llvm::Instruction> ServiceInsertPt = nullptr;
309  };
310  /// Map of local debug location, ThreadId and functions.
311  typedef llvm::DenseMap<llvm::Function *, DebugLocThreadIdTy>
312  OpenMPLocThreadIDMapTy;
313  OpenMPLocThreadIDMapTy OpenMPLocThreadIDMap;
314  /// Map of UDRs and corresponding combiner/initializer.
315  typedef llvm::DenseMap<const OMPDeclareReductionDecl *,
316  std::pair<llvm::Function *, llvm::Function *>>
317  UDRMapTy;
318  UDRMapTy UDRMap;
319  /// Map of functions and locally defined UDRs.
320  typedef llvm::DenseMap<llvm::Function *,
322  FunctionUDRMapTy;
323  FunctionUDRMapTy FunctionUDRMap;
324  /// Type kmp_critical_name, originally defined as typedef kmp_int32
325  /// kmp_critical_name[8];
326  llvm::ArrayType *KmpCriticalNameTy;
327  /// An ordered map of auto-generated variables to their unique names.
328  /// It stores variables with the following names: 1) ".gomp_critical_user_" +
329  /// <critical_section_name> + ".var" for "omp critical" directives; 2)
330  /// <mangled_name_for_global_var> + ".cache." for cache for threadprivate
331  /// variables.
332  llvm::StringMap<llvm::AssertingVH<llvm::Constant>, llvm::BumpPtrAllocator>
333  InternalVars;
334  /// Type typedef kmp_int32 (* kmp_routine_entry_t)(kmp_int32, void *);
335  llvm::Type *KmpRoutineEntryPtrTy = nullptr;
336  QualType KmpRoutineEntryPtrQTy;
337  /// Type typedef struct kmp_task {
338  /// void * shareds; /**< pointer to block of pointers to
339  /// shared vars */
340  /// kmp_routine_entry_t routine; /**< pointer to routine to call for
341  /// executing task */
342  /// kmp_int32 part_id; /**< part id for the task */
343  /// kmp_routine_entry_t destructors; /* pointer to function to invoke
344  /// deconstructors of firstprivate C++ objects */
345  /// } kmp_task_t;
347  /// Saved kmp_task_t for task directive.
349  /// Saved kmp_task_t for taskloop-based directive.
351  /// Type typedef struct kmp_depend_info {
352  /// kmp_intptr_t base_addr;
353  /// size_t len;
354  /// struct {
355  /// bool in:1;
356  /// bool out:1;
357  /// } flags;
358  /// } kmp_depend_info_t;
360  /// struct kmp_dim { // loop bounds info casted to kmp_int64
361  /// kmp_int64 lo; // lower
362  /// kmp_int64 up; // upper
363  /// kmp_int64 st; // stride
364  /// };
366  /// Type struct __tgt_offload_entry{
367  /// void *addr; // Pointer to the offload entry info.
368  /// // (function or global)
369  /// char *name; // Name of the function or global.
370  /// size_t size; // Size of the entry info (0 if it a function).
371  /// };
373  /// struct __tgt_device_image{
374  /// void *ImageStart; // Pointer to the target code start.
375  /// void *ImageEnd; // Pointer to the target code end.
376  /// // We also add the host entries to the device image, as it may be useful
377  /// // for the target runtime to have access to that information.
378  /// __tgt_offload_entry *EntriesBegin; // Begin of the table with all
379  /// // the entries.
380  /// __tgt_offload_entry *EntriesEnd; // End of the table with all the
381  /// // entries (non inclusive).
382  /// };
384  /// struct __tgt_bin_desc{
385  /// int32_t NumDevices; // Number of devices supported.
386  /// __tgt_device_image *DeviceImages; // Arrays of device images
387  /// // (one per device).
388  /// __tgt_offload_entry *EntriesBegin; // Begin of the table with all the
389  /// // entries.
390  /// __tgt_offload_entry *EntriesEnd; // End of the table with all the
391  /// // entries (non inclusive).
392  /// };
394  /// Entity that registers the offloading constants that were emitted so
395  /// far.
397  CodeGenModule &CGM;
398 
399  /// Number of entries registered so far.
400  unsigned OffloadingEntriesNum = 0;
401 
402  public:
403  /// Base class of the entries info.
405  public:
406  /// Kind of a given entry.
407  enum OffloadingEntryInfoKinds : unsigned {
408  /// Entry is a target region.
409  OffloadingEntryInfoTargetRegion = 0,
410  /// Entry is a declare target variable.
411  OffloadingEntryInfoDeviceGlobalVar = 1,
412  /// Invalid entry info.
413  OffloadingEntryInfoInvalid = ~0u
414  };
415 
416  protected:
417  OffloadEntryInfo() = delete;
420  uint32_t Flags)
421  : Flags(Flags), Order(Order), Kind(Kind) {}
422  ~OffloadEntryInfo() = default;
423 
424  public:
425  bool isValid() const { return Order != ~0u; }
426  unsigned getOrder() const { return Order; }
428  uint32_t getFlags() const { return Flags; }
429  void setFlags(uint32_t NewFlags) { Flags = NewFlags; }
430  llvm::Constant *getAddress() const {
431  return cast_or_null<llvm::Constant>(Addr);
432  }
433  void setAddress(llvm::Constant *V) {
434  assert(!Addr.pointsToAliveValue() && "Address has been set before!");
435  Addr = V;
436  }
437  static bool classof(const OffloadEntryInfo *Info) { return true; }
438 
439  private:
440  /// Address of the entity that has to be mapped for offloading.
441  llvm::WeakTrackingVH Addr;
442 
443  /// Flags associated with the device global.
444  uint32_t Flags = 0u;
445 
446  /// Order this entry was emitted.
447  unsigned Order = ~0u;
448 
449  OffloadingEntryInfoKinds Kind = OffloadingEntryInfoInvalid;
450  };
451 
452  /// Return true if a there are no entries defined.
453  bool empty() const;
454  /// Return number of entries defined so far.
455  unsigned size() const { return OffloadingEntriesNum; }
457 
458  //
459  // Target region entries related.
460  //
461 
462  /// Kind of the target registry entry.
463  enum OMPTargetRegionEntryKind : uint32_t {
464  /// Mark the entry as target region.
465  OMPTargetRegionEntryTargetRegion = 0x0,
466  /// Mark the entry as a global constructor.
467  OMPTargetRegionEntryCtor = 0x02,
468  /// Mark the entry as a global destructor.
469  OMPTargetRegionEntryDtor = 0x04,
470  };
471 
472  /// Target region entries info.
474  /// Address that can be used as the ID of the entry.
475  llvm::Constant *ID = nullptr;
476 
477  public:
479  : OffloadEntryInfo(OffloadingEntryInfoTargetRegion) {}
480  explicit OffloadEntryInfoTargetRegion(unsigned Order,
481  llvm::Constant *Addr,
482  llvm::Constant *ID,
484  : OffloadEntryInfo(OffloadingEntryInfoTargetRegion, Order, Flags),
485  ID(ID) {
486  setAddress(Addr);
487  }
488 
489  llvm::Constant *getID() const { return ID; }
490  void setID(llvm::Constant *V) {
491  assert(!ID && "ID has been set before!");
492  ID = V;
493  }
494  static bool classof(const OffloadEntryInfo *Info) {
495  return Info->getKind() == OffloadingEntryInfoTargetRegion;
496  }
497  };
498 
499  /// Initialize target region entry.
500  void initializeTargetRegionEntryInfo(unsigned DeviceID, unsigned FileID,
501  StringRef ParentName, unsigned LineNum,
502  unsigned Order);
503  /// Register target region entry.
504  void registerTargetRegionEntryInfo(unsigned DeviceID, unsigned FileID,
505  StringRef ParentName, unsigned LineNum,
506  llvm::Constant *Addr, llvm::Constant *ID,
508  /// Return true if a target region entry with the provided information
509  /// exists.
510  bool hasTargetRegionEntryInfo(unsigned DeviceID, unsigned FileID,
511  StringRef ParentName, unsigned LineNum) const;
512  /// brief Applies action \a Action on all registered entries.
513  typedef llvm::function_ref<void(unsigned, unsigned, StringRef, unsigned,
516  void actOnTargetRegionEntriesInfo(
517  const OffloadTargetRegionEntryInfoActTy &Action);
518 
519  //
520  // Device global variable entries related.
521  //
522 
523  /// Kind of the global variable entry..
524  enum OMPTargetGlobalVarEntryKind : uint32_t {
525  /// Mark the entry as a to declare target.
526  OMPTargetGlobalVarEntryTo = 0x0,
527  /// Mark the entry as a to declare target link.
528  OMPTargetGlobalVarEntryLink = 0x1,
529  };
530 
531  /// Device global variable entries info.
533  /// Type of the global variable.
534  CharUnits VarSize;
535  llvm::GlobalValue::LinkageTypes Linkage;
536 
537  public:
539  : OffloadEntryInfo(OffloadingEntryInfoDeviceGlobalVar) {}
540  explicit OffloadEntryInfoDeviceGlobalVar(unsigned Order,
542  : OffloadEntryInfo(OffloadingEntryInfoDeviceGlobalVar, Order, Flags) {}
544  unsigned Order, llvm::Constant *Addr, CharUnits VarSize,
546  llvm::GlobalValue::LinkageTypes Linkage)
547  : OffloadEntryInfo(OffloadingEntryInfoDeviceGlobalVar, Order, Flags),
548  VarSize(VarSize), Linkage(Linkage) {
549  setAddress(Addr);
550  }
551 
552  CharUnits getVarSize() const { return VarSize; }
553  void setVarSize(CharUnits Size) { VarSize = Size; }
554  llvm::GlobalValue::LinkageTypes getLinkage() const { return Linkage; }
555  void setLinkage(llvm::GlobalValue::LinkageTypes LT) { Linkage = LT; }
556  static bool classof(const OffloadEntryInfo *Info) {
557  return Info->getKind() == OffloadingEntryInfoDeviceGlobalVar;
558  }
559  };
560 
561  /// Initialize device global variable entry.
562  void initializeDeviceGlobalVarEntryInfo(StringRef Name,
564  unsigned Order);
565 
566  /// Register device global variable entry.
567  void
568  registerDeviceGlobalVarEntryInfo(StringRef VarName, llvm::Constant *Addr,
569  CharUnits VarSize,
571  llvm::GlobalValue::LinkageTypes Linkage);
572  /// Checks if the variable with the given name has been registered already.
573  bool hasDeviceGlobalVarEntryInfo(StringRef VarName) const {
574  return OffloadEntriesDeviceGlobalVar.count(VarName) > 0;
575  }
576  /// Applies action \a Action on all registered entries.
577  typedef llvm::function_ref<void(StringRef,
580  void actOnDeviceGlobalVarEntriesInfo(
582 
583  private:
584  // Storage for target region entries kind. The storage is to be indexed by
585  // file ID, device ID, parent function name and line number.
586  typedef llvm::DenseMap<unsigned, OffloadEntryInfoTargetRegion>
587  OffloadEntriesTargetRegionPerLine;
588  typedef llvm::StringMap<OffloadEntriesTargetRegionPerLine>
589  OffloadEntriesTargetRegionPerParentName;
590  typedef llvm::DenseMap<unsigned, OffloadEntriesTargetRegionPerParentName>
591  OffloadEntriesTargetRegionPerFile;
592  typedef llvm::DenseMap<unsigned, OffloadEntriesTargetRegionPerFile>
593  OffloadEntriesTargetRegionPerDevice;
594  typedef OffloadEntriesTargetRegionPerDevice OffloadEntriesTargetRegionTy;
595  OffloadEntriesTargetRegionTy OffloadEntriesTargetRegion;
596  /// Storage for device global variable entries kind. The storage is to be
597  /// indexed by mangled name.
598  typedef llvm::StringMap<OffloadEntryInfoDeviceGlobalVar>
599  OffloadEntriesDeviceGlobalVarTy;
600  OffloadEntriesDeviceGlobalVarTy OffloadEntriesDeviceGlobalVar;
601  };
603 
604  bool ShouldMarkAsGlobal = true;
605  /// List of the emitted functions.
606  llvm::StringSet<> AlreadyEmittedTargetFunctions;
607  /// List of the global variables with their addresses that should not be
608  /// emitted for the target.
609  llvm::StringMap<llvm::WeakTrackingVH> EmittedNonTargetVariables;
610 
611  /// List of variables that can become declare target implicitly and, thus,
612  /// must be emitted.
613  llvm::SmallDenseSet<const VarDecl *> DeferredGlobalVariables;
614 
615  /// Creates and registers offloading binary descriptor for the current
616  /// compilation unit. The function that does the registration is returned.
618 
619  /// Creates all the offload entries in the current compilation unit
620  /// along with the associated metadata.
622 
623  /// Loads all the offload entries information from the host IR
624  /// metadata.
626 
627  /// Returns __tgt_offload_entry type.
629 
630  /// Returns __tgt_device_image type.
632 
633  /// Returns __tgt_bin_desc type.
635 
636  /// Start scanning from statement \a S and and emit all target regions
637  /// found along the way.
638  /// \param S Starting statement.
639  /// \param ParentName Name of the function declaration that is being scanned.
640  void scanForTargetRegionsFunctions(const Stmt *S, StringRef ParentName);
641 
642  /// Build type kmp_routine_entry_t (if not built yet).
643  void emitKmpRoutineEntryT(QualType KmpInt32Ty);
644 
645  /// Returns pointer to kmpc_micro type.
646  llvm::Type *getKmpc_MicroPointerTy();
647 
648  /// Returns specified OpenMP runtime function.
649  /// \param Function OpenMP runtime function.
650  /// \return Specified function.
651  llvm::Constant *createRuntimeFunction(unsigned Function);
652 
653  /// Returns __kmpc_for_static_init_* runtime function for the specified
654  /// size \a IVSize and sign \a IVSigned.
655  llvm::Constant *createForStaticInitFunction(unsigned IVSize, bool IVSigned);
656 
657  /// Returns __kmpc_dispatch_init_* runtime function for the specified
658  /// size \a IVSize and sign \a IVSigned.
659  llvm::Constant *createDispatchInitFunction(unsigned IVSize, bool IVSigned);
660 
661  /// Returns __kmpc_dispatch_next_* runtime function for the specified
662  /// size \a IVSize and sign \a IVSigned.
663  llvm::Constant *createDispatchNextFunction(unsigned IVSize, bool IVSigned);
664 
665  /// Returns __kmpc_dispatch_fini_* runtime function for the specified
666  /// size \a IVSize and sign \a IVSigned.
667  llvm::Constant *createDispatchFiniFunction(unsigned IVSize, bool IVSigned);
668 
669  /// If the specified mangled name is not in the module, create and
670  /// return threadprivate cache object. This object is a pointer's worth of
671  /// storage that's reserved for use by the OpenMP runtime.
672  /// \param VD Threadprivate variable.
673  /// \return Cache variable for the specified threadprivate.
674  llvm::Constant *getOrCreateThreadPrivateCache(const VarDecl *VD);
675 
676  /// Gets (if variable with the given name already exist) or creates
677  /// internal global variable with the specified Name. The created variable has
678  /// linkage CommonLinkage by default and is initialized by null value.
679  /// \param Ty Type of the global variable. If it is exist already the type
680  /// must be the same.
681  /// \param Name Name of the variable.
682  llvm::Constant *getOrCreateInternalVariable(llvm::Type *Ty,
683  const llvm::Twine &Name);
684 
685  /// Set of threadprivate variables with the generated initializer.
686  llvm::StringSet<> ThreadPrivateWithDefinition;
687 
688  /// Set of declare target variables with the generated initializer.
689  llvm::StringSet<> DeclareTargetWithDefinition;
690 
691  /// Emits initialization code for the threadprivate variables.
692  /// \param VDAddr Address of the global variable \a VD.
693  /// \param Ctor Pointer to a global init function for \a VD.
694  /// \param CopyCtor Pointer to a global copy function for \a VD.
695  /// \param Dtor Pointer to a global destructor function for \a VD.
696  /// \param Loc Location of threadprivate declaration.
698  llvm::Value *Ctor, llvm::Value *CopyCtor,
699  llvm::Value *Dtor, SourceLocation Loc);
700 
701  /// Returns corresponding lock object for the specified critical region
702  /// name. If the lock object does not exist it is created, otherwise the
703  /// reference to the existing copy is returned.
704  /// \param CriticalName Name of the critical region.
705  ///
706  llvm::Value *getCriticalRegionLock(StringRef CriticalName);
707 
708  struct TaskResultTy {
709  llvm::Value *NewTask = nullptr;
710  llvm::Value *TaskEntry = nullptr;
711  llvm::Value *NewTaskNewTaskTTy = nullptr;
713  const RecordDecl *KmpTaskTQTyRD = nullptr;
714  llvm::Value *TaskDupFn = nullptr;
715  };
716  /// Emit task region for the task directive. The task region is emitted in
717  /// several steps:
718  /// 1. Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32
719  /// gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds,
720  /// kmp_routine_entry_t *task_entry). Here task_entry is a pointer to the
721  /// function:
722  /// kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) {
723  /// TaskFunction(gtid, tt->part_id, tt->shareds);
724  /// return 0;
725  /// }
726  /// 2. Copy a list of shared variables to field shareds of the resulting
727  /// structure kmp_task_t returned by the previous call (if any).
728  /// 3. Copy a pointer to destructions function to field destructions of the
729  /// resulting structure kmp_task_t.
730  /// \param D Current task directive.
731  /// \param TaskFunction An LLVM function with type void (*)(i32 /*gtid*/, i32
732  /// /*part_id*/, captured_struct */*__context*/);
733  /// \param SharedsTy A type which contains references the shared variables.
734  /// \param Shareds Context with the list of shared variables from the \p
735  /// TaskFunction.
736  /// \param Data Additional data for task generation like tiednsee, final
737  /// state, list of privates etc.
739  const OMPExecutableDirective &D,
740  llvm::Value *TaskFunction, QualType SharedsTy,
741  Address Shareds, const OMPTaskDataTy &Data);
742 
743 public:
745  : CGOpenMPRuntime(CGM, ".", ".") {}
746  virtual ~CGOpenMPRuntime() {}
747  virtual void clear();
748 
749  /// Get the platform-specific name separator.
750  std::string getName(ArrayRef<StringRef> Parts) const;
751 
752  /// Emit code for the specified user defined reduction construct.
753  virtual void emitUserDefinedReduction(CodeGenFunction *CGF,
754  const OMPDeclareReductionDecl *D);
755  /// Get combiner/initializer for the specified user-defined reduction, if any.
756  virtual std::pair<llvm::Function *, llvm::Function *>
757  getUserDefinedReduction(const OMPDeclareReductionDecl *D);
758 
759  /// Emits outlined function for the specified OpenMP parallel directive
760  /// \a D. This outlined function has type void(*)(kmp_int32 *ThreadID,
761  /// kmp_int32 BoundID, struct context_vars*).
762  /// \param D OpenMP directive.
763  /// \param ThreadIDVar Variable for thread id in the current OpenMP region.
764  /// \param InnermostKind Kind of innermost directive (for simple directives it
765  /// is a directive itself, for combined - its innermost directive).
766  /// \param CodeGen Code generation sequence for the \a D directive.
768  const OMPExecutableDirective &D, const VarDecl *ThreadIDVar,
769  OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen);
770 
771  /// Emits outlined function for the specified OpenMP teams directive
772  /// \a D. This outlined function has type void(*)(kmp_int32 *ThreadID,
773  /// kmp_int32 BoundID, struct context_vars*).
774  /// \param D OpenMP directive.
775  /// \param ThreadIDVar Variable for thread id in the current OpenMP region.
776  /// \param InnermostKind Kind of innermost directive (for simple directives it
777  /// is a directive itself, for combined - its innermost directive).
778  /// \param CodeGen Code generation sequence for the \a D directive.
780  const OMPExecutableDirective &D, const VarDecl *ThreadIDVar,
781  OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen);
782 
783  /// Emits outlined function for the OpenMP task directive \a D. This
784  /// outlined function has type void(*)(kmp_int32 ThreadID, struct task_t*
785  /// TaskT).
786  /// \param D OpenMP directive.
787  /// \param ThreadIDVar Variable for thread id in the current OpenMP region.
788  /// \param PartIDVar Variable for partition id in the current OpenMP untied
789  /// task region.
790  /// \param TaskTVar Variable for task_t argument.
791  /// \param InnermostKind Kind of innermost directive (for simple directives it
792  /// is a directive itself, for combined - its innermost directive).
793  /// \param CodeGen Code generation sequence for the \a D directive.
794  /// \param Tied true if task is generated for tied task, false otherwise.
795  /// \param NumberOfParts Number of parts in untied task. Ignored for tied
796  /// tasks.
797  ///
799  const OMPExecutableDirective &D, const VarDecl *ThreadIDVar,
800  const VarDecl *PartIDVar, const VarDecl *TaskTVar,
801  OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen,
802  bool Tied, unsigned &NumberOfParts);
803 
804  /// Cleans up references to the objects in finished function.
805  ///
806  virtual void functionFinished(CodeGenFunction &CGF);
807 
808  /// Emits code for parallel or serial call of the \a OutlinedFn with
809  /// variables captured in a record which address is stored in \a
810  /// CapturedStruct.
811  /// \param OutlinedFn Outlined function to be run in parallel threads. Type of
812  /// this function is void(*)(kmp_int32 *, kmp_int32, struct context_vars*).
813  /// \param CapturedVars A pointer to the record with the references to
814  /// variables used in \a OutlinedFn function.
815  /// \param IfCond Condition in the associated 'if' clause, if it was
816  /// specified, nullptr otherwise.
817  ///
818  virtual void emitParallelCall(CodeGenFunction &CGF, SourceLocation Loc,
819  llvm::Value *OutlinedFn,
820  ArrayRef<llvm::Value *> CapturedVars,
821  const Expr *IfCond);
822 
823  /// Emits a critical region.
824  /// \param CriticalName Name of the critical region.
825  /// \param CriticalOpGen Generator for the statement associated with the given
826  /// critical region.
827  /// \param Hint Value of the 'hint' clause (optional).
828  virtual void emitCriticalRegion(CodeGenFunction &CGF, StringRef CriticalName,
829  const RegionCodeGenTy &CriticalOpGen,
830  SourceLocation Loc,
831  const Expr *Hint = nullptr);
832 
833  /// Emits a master region.
834  /// \param MasterOpGen Generator for the statement associated with the given
835  /// master region.
836  virtual void emitMasterRegion(CodeGenFunction &CGF,
837  const RegionCodeGenTy &MasterOpGen,
838  SourceLocation Loc);
839 
840  /// Emits code for a taskyield directive.
841  virtual void emitTaskyieldCall(CodeGenFunction &CGF, SourceLocation Loc);
842 
843  /// Emit a taskgroup region.
844  /// \param TaskgroupOpGen Generator for the statement associated with the
845  /// given taskgroup region.
846  virtual void emitTaskgroupRegion(CodeGenFunction &CGF,
847  const RegionCodeGenTy &TaskgroupOpGen,
848  SourceLocation Loc);
849 
850  /// Emits a single region.
851  /// \param SingleOpGen Generator for the statement associated with the given
852  /// single region.
853  virtual void emitSingleRegion(CodeGenFunction &CGF,
854  const RegionCodeGenTy &SingleOpGen,
855  SourceLocation Loc,
856  ArrayRef<const Expr *> CopyprivateVars,
857  ArrayRef<const Expr *> DestExprs,
858  ArrayRef<const Expr *> SrcExprs,
859  ArrayRef<const Expr *> AssignmentOps);
860 
861  /// Emit an ordered region.
862  /// \param OrderedOpGen Generator for the statement associated with the given
863  /// ordered region.
864  virtual void emitOrderedRegion(CodeGenFunction &CGF,
865  const RegionCodeGenTy &OrderedOpGen,
866  SourceLocation Loc, bool IsThreads);
867 
868  /// Emit an implicit/explicit barrier for OpenMP threads.
869  /// \param Kind Directive for which this implicit barrier call must be
870  /// generated. Must be OMPD_barrier for explicit barrier generation.
871  /// \param EmitChecks true if need to emit checks for cancellation barriers.
872  /// \param ForceSimpleCall true simple barrier call must be emitted, false if
873  /// runtime class decides which one to emit (simple or with cancellation
874  /// checks).
875  ///
876  virtual void emitBarrierCall(CodeGenFunction &CGF, SourceLocation Loc,
878  bool EmitChecks = true,
879  bool ForceSimpleCall = false);
880 
881  /// Check if the specified \a ScheduleKind is static non-chunked.
882  /// This kind of worksharing directive is emitted without outer loop.
883  /// \param ScheduleKind Schedule kind specified in the 'schedule' clause.
884  /// \param Chunked True if chunk is specified in the clause.
885  ///
886  virtual bool isStaticNonchunked(OpenMPScheduleClauseKind ScheduleKind,
887  bool Chunked) const;
888 
889  /// Check if the specified \a ScheduleKind is static non-chunked.
890  /// This kind of distribute directive is emitted without outer loop.
891  /// \param ScheduleKind Schedule kind specified in the 'dist_schedule' clause.
892  /// \param Chunked True if chunk is specified in the clause.
893  ///
894  virtual bool isStaticNonchunked(OpenMPDistScheduleClauseKind ScheduleKind,
895  bool Chunked) const;
896 
897  /// Check if the specified \a ScheduleKind is static chunked.
898  /// \param ScheduleKind Schedule kind specified in the 'schedule' clause.
899  /// \param Chunked True if chunk is specified in the clause.
900  ///
901  virtual bool isStaticChunked(OpenMPScheduleClauseKind ScheduleKind,
902  bool Chunked) const;
903 
904  /// Check if the specified \a ScheduleKind is static non-chunked.
905  /// \param ScheduleKind Schedule kind specified in the 'dist_schedule' clause.
906  /// \param Chunked True if chunk is specified in the clause.
907  ///
908  virtual bool isStaticChunked(OpenMPDistScheduleClauseKind ScheduleKind,
909  bool Chunked) const;
910 
911  /// Check if the specified \a ScheduleKind is dynamic.
912  /// This kind of worksharing directive is emitted without outer loop.
913  /// \param ScheduleKind Schedule Kind specified in the 'schedule' clause.
914  ///
915  virtual bool isDynamic(OpenMPScheduleClauseKind ScheduleKind) const;
916 
917  /// struct with the values to be passed to the dispatch runtime function
919  /// Loop lower bound
920  llvm::Value *LB = nullptr;
921  /// Loop upper bound
922  llvm::Value *UB = nullptr;
923  /// Chunk size specified using 'schedule' clause (nullptr if chunk
924  /// was not specified)
925  llvm::Value *Chunk = nullptr;
926  DispatchRTInput() = default;
928  : LB(LB), UB(UB), Chunk(Chunk) {}
929  };
930 
931  /// Call the appropriate runtime routine to initialize it before start
932  /// of loop.
933 
934  /// This is used for non static scheduled types and when the ordered
935  /// clause is present on the loop construct.
936  /// Depending on the loop schedule, it is necessary to call some runtime
937  /// routine before start of the OpenMP loop to get the loop upper / lower
938  /// bounds \a LB and \a UB and stride \a ST.
939  ///
940  /// \param CGF Reference to current CodeGenFunction.
941  /// \param Loc Clang source location.
942  /// \param ScheduleKind Schedule kind, specified by the 'schedule' clause.
943  /// \param IVSize Size of the iteration variable in bits.
944  /// \param IVSigned Sign of the iteration variable.
945  /// \param Ordered true if loop is ordered, false otherwise.
946  /// \param DispatchValues struct containing llvm values for lower bound, upper
947  /// bound, and chunk expression.
948  /// For the default (nullptr) value, the chunk 1 will be used.
949  ///
950  virtual void emitForDispatchInit(CodeGenFunction &CGF, SourceLocation Loc,
951  const OpenMPScheduleTy &ScheduleKind,
952  unsigned IVSize, bool IVSigned, bool Ordered,
953  const DispatchRTInput &DispatchValues);
954 
955  /// Struct with the values to be passed to the static runtime function
956  struct StaticRTInput {
957  /// Size of the iteration variable in bits.
958  unsigned IVSize = 0;
959  /// Sign of the iteration variable.
960  bool IVSigned = false;
961  /// true if loop is ordered, false otherwise.
962  bool Ordered = false;
963  /// Address of the output variable in which the flag of the last iteration
964  /// is returned.
965  Address IL = Address::invalid();
966  /// Address of the output variable in which the lower iteration number is
967  /// returned.
968  Address LB = Address::invalid();
969  /// Address of the output variable in which the upper iteration number is
970  /// returned.
971  Address UB = Address::invalid();
972  /// Address of the output variable in which the stride value is returned
973  /// necessary to generated the static_chunked scheduled loop.
974  Address ST = Address::invalid();
975  /// Value of the chunk for the static_chunked scheduled loop. For the
976  /// default (nullptr) value, the chunk 1 will be used.
977  llvm::Value *Chunk = nullptr;
978  StaticRTInput(unsigned IVSize, bool IVSigned, bool Ordered, Address IL,
979  Address LB, Address UB, Address ST,
980  llvm::Value *Chunk = nullptr)
981  : IVSize(IVSize), IVSigned(IVSigned), Ordered(Ordered), IL(IL), LB(LB),
982  UB(UB), ST(ST), Chunk(Chunk) {}
983  };
984  /// Call the appropriate runtime routine to initialize it before start
985  /// of loop.
986  ///
987  /// This is used only in case of static schedule, when the user did not
988  /// specify a ordered clause on the loop construct.
989  /// Depending on the loop schedule, it is necessary to call some runtime
990  /// routine before start of the OpenMP loop to get the loop upper / lower
991  /// bounds LB and UB and stride ST.
992  ///
993  /// \param CGF Reference to current CodeGenFunction.
994  /// \param Loc Clang source location.
995  /// \param DKind Kind of the directive.
996  /// \param ScheduleKind Schedule kind, specified by the 'schedule' clause.
997  /// \param Values Input arguments for the construct.
998  ///
999  virtual void emitForStaticInit(CodeGenFunction &CGF, SourceLocation Loc,
1000  OpenMPDirectiveKind DKind,
1001  const OpenMPScheduleTy &ScheduleKind,
1002  const StaticRTInput &Values);
1003 
1004  ///
1005  /// \param CGF Reference to current CodeGenFunction.
1006  /// \param Loc Clang source location.
1007  /// \param SchedKind Schedule kind, specified by the 'dist_schedule' clause.
1008  /// \param Values Input arguments for the construct.
1009  ///
1010  virtual void emitDistributeStaticInit(CodeGenFunction &CGF,
1011  SourceLocation Loc,
1012  OpenMPDistScheduleClauseKind SchedKind,
1013  const StaticRTInput &Values);
1014 
1015  /// Call the appropriate runtime routine to notify that we finished
1016  /// iteration of the ordered loop with the dynamic scheduling.
1017  ///
1018  /// \param CGF Reference to current CodeGenFunction.
1019  /// \param Loc Clang source location.
1020  /// \param IVSize Size of the iteration variable in bits.
1021  /// \param IVSigned Sign of the iteration variable.
1022  ///
1023  virtual void emitForOrderedIterationEnd(CodeGenFunction &CGF,
1024  SourceLocation Loc, unsigned IVSize,
1025  bool IVSigned);
1026 
1027  /// Call the appropriate runtime routine to notify that we finished
1028  /// all the work with current loop.
1029  ///
1030  /// \param CGF Reference to current CodeGenFunction.
1031  /// \param Loc Clang source location.
1032  /// \param DKind Kind of the directive for which the static finish is emitted.
1033  ///
1034  virtual void emitForStaticFinish(CodeGenFunction &CGF, SourceLocation Loc,
1035  OpenMPDirectiveKind DKind);
1036 
1037  /// Call __kmpc_dispatch_next(
1038  /// ident_t *loc, kmp_int32 tid, kmp_int32 *p_lastiter,
1039  /// kmp_int[32|64] *p_lower, kmp_int[32|64] *p_upper,
1040  /// kmp_int[32|64] *p_stride);
1041  /// \param IVSize Size of the iteration variable in bits.
1042  /// \param IVSigned Sign of the iteration variable.
1043  /// \param IL Address of the output variable in which the flag of the
1044  /// last iteration is returned.
1045  /// \param LB Address of the output variable in which the lower iteration
1046  /// number is returned.
1047  /// \param UB Address of the output variable in which the upper iteration
1048  /// number is returned.
1049  /// \param ST Address of the output variable in which the stride value is
1050  /// returned.
1052  unsigned IVSize, bool IVSigned,
1053  Address IL, Address LB,
1054  Address UB, Address ST);
1055 
1056  /// Emits call to void __kmpc_push_num_threads(ident_t *loc, kmp_int32
1057  /// global_tid, kmp_int32 num_threads) to generate code for 'num_threads'
1058  /// clause.
1059  /// \param NumThreads An integer value of threads.
1060  virtual void emitNumThreadsClause(CodeGenFunction &CGF,
1061  llvm::Value *NumThreads,
1062  SourceLocation Loc);
1063 
1064  /// Emit call to void __kmpc_push_proc_bind(ident_t *loc, kmp_int32
1065  /// global_tid, int proc_bind) to generate code for 'proc_bind' clause.
1066  virtual void emitProcBindClause(CodeGenFunction &CGF,
1067  OpenMPProcBindClauseKind ProcBind,
1068  SourceLocation Loc);
1069 
1070  /// Returns address of the threadprivate variable for the current
1071  /// thread.
1072  /// \param VD Threadprivate variable.
1073  /// \param VDAddr Address of the global variable \a VD.
1074  /// \param Loc Location of the reference to threadprivate var.
1075  /// \return Address of the threadprivate variable for the current thread.
1077  const VarDecl *VD,
1078  Address VDAddr,
1079  SourceLocation Loc);
1080 
1081  /// Returns the address of the variable marked as declare target with link
1082  /// clause.
1083  virtual Address getAddrOfDeclareTargetLink(const VarDecl *VD);
1084 
1085  /// Emit a code for initialization of threadprivate variable. It emits
1086  /// a call to runtime library which adds initial value to the newly created
1087  /// threadprivate variable (if it is not constant) and registers destructor
1088  /// for the variable (if any).
1089  /// \param VD Threadprivate variable.
1090  /// \param VDAddr Address of the global variable \a VD.
1091  /// \param Loc Location of threadprivate declaration.
1092  /// \param PerformInit true if initialization expression is not constant.
1093  virtual llvm::Function *
1095  SourceLocation Loc, bool PerformInit,
1096  CodeGenFunction *CGF = nullptr);
1097 
1098  /// Emit a code for initialization of declare target variable.
1099  /// \param VD Declare target variable.
1100  /// \param Addr Address of the global variable \a VD.
1101  /// \param PerformInit true if initialization expression is not constant.
1102  virtual bool emitDeclareTargetVarDefinition(const VarDecl *VD,
1103  llvm::GlobalVariable *Addr,
1104  bool PerformInit);
1105 
1106  /// Creates artificial threadprivate variable with name \p Name and type \p
1107  /// VarType.
1108  /// \param VarType Type of the artificial threadprivate variable.
1109  /// \param Name Name of the artificial threadprivate variable.
1111  QualType VarType,
1112  StringRef Name);
1113 
1114  /// Emit flush of the variables specified in 'omp flush' directive.
1115  /// \param Vars List of variables to flush.
1116  virtual void emitFlush(CodeGenFunction &CGF, ArrayRef<const Expr *> Vars,
1117  SourceLocation Loc);
1118 
1119  /// Emit task region for the task directive. The task region is
1120  /// emitted in several steps:
1121  /// 1. Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32
1122  /// gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds,
1123  /// kmp_routine_entry_t *task_entry). Here task_entry is a pointer to the
1124  /// function:
1125  /// kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) {
1126  /// TaskFunction(gtid, tt->part_id, tt->shareds);
1127  /// return 0;
1128  /// }
1129  /// 2. Copy a list of shared variables to field shareds of the resulting
1130  /// structure kmp_task_t returned by the previous call (if any).
1131  /// 3. Copy a pointer to destructions function to field destructions of the
1132  /// resulting structure kmp_task_t.
1133  /// 4. Emit a call to kmp_int32 __kmpc_omp_task(ident_t *, kmp_int32 gtid,
1134  /// kmp_task_t *new_task), where new_task is a resulting structure from
1135  /// previous items.
1136  /// \param D Current task directive.
1137  /// \param TaskFunction An LLVM function with type void (*)(i32 /*gtid*/, i32
1138  /// /*part_id*/, captured_struct */*__context*/);
1139  /// \param SharedsTy A type which contains references the shared variables.
1140  /// \param Shareds Context with the list of shared variables from the \p
1141  /// TaskFunction.
1142  /// \param IfCond Not a nullptr if 'if' clause was specified, nullptr
1143  /// otherwise.
1144  /// \param Data Additional data for task generation like tiednsee, final
1145  /// state, list of privates etc.
1146  virtual void emitTaskCall(CodeGenFunction &CGF, SourceLocation Loc,
1147  const OMPExecutableDirective &D,
1148  llvm::Value *TaskFunction, QualType SharedsTy,
1149  Address Shareds, const Expr *IfCond,
1150  const OMPTaskDataTy &Data);
1151 
1152  /// Emit task region for the taskloop directive. The taskloop region is
1153  /// emitted in several steps:
1154  /// 1. Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32
1155  /// gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds,
1156  /// kmp_routine_entry_t *task_entry). Here task_entry is a pointer to the
1157  /// function:
1158  /// kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) {
1159  /// TaskFunction(gtid, tt->part_id, tt->shareds);
1160  /// return 0;
1161  /// }
1162  /// 2. Copy a list of shared variables to field shareds of the resulting
1163  /// structure kmp_task_t returned by the previous call (if any).
1164  /// 3. Copy a pointer to destructions function to field destructions of the
1165  /// resulting structure kmp_task_t.
1166  /// 4. Emit a call to void __kmpc_taskloop(ident_t *loc, int gtid, kmp_task_t
1167  /// *task, int if_val, kmp_uint64 *lb, kmp_uint64 *ub, kmp_int64 st, int
1168  /// nogroup, int sched, kmp_uint64 grainsize, void *task_dup ), where new_task
1169  /// is a resulting structure from
1170  /// previous items.
1171  /// \param D Current task directive.
1172  /// \param TaskFunction An LLVM function with type void (*)(i32 /*gtid*/, i32
1173  /// /*part_id*/, captured_struct */*__context*/);
1174  /// \param SharedsTy A type which contains references the shared variables.
1175  /// \param Shareds Context with the list of shared variables from the \p
1176  /// TaskFunction.
1177  /// \param IfCond Not a nullptr if 'if' clause was specified, nullptr
1178  /// otherwise.
1179  /// \param Data Additional data for task generation like tiednsee, final
1180  /// state, list of privates etc.
1181  virtual void emitTaskLoopCall(
1182  CodeGenFunction &CGF, SourceLocation Loc, const OMPLoopDirective &D,
1183  llvm::Value *TaskFunction, QualType SharedsTy, Address Shareds,
1184  const Expr *IfCond, const OMPTaskDataTy &Data);
1185 
1186  /// Emit code for the directive that does not require outlining.
1187  ///
1188  /// \param InnermostKind Kind of innermost directive (for simple directives it
1189  /// is a directive itself, for combined - its innermost directive).
1190  /// \param CodeGen Code generation sequence for the \a D directive.
1191  /// \param HasCancel true if region has inner cancel directive, false
1192  /// otherwise.
1193  virtual void emitInlinedDirective(CodeGenFunction &CGF,
1194  OpenMPDirectiveKind InnermostKind,
1195  const RegionCodeGenTy &CodeGen,
1196  bool HasCancel = false);
1197 
1198  /// Emits reduction function.
1199  /// \param ArgsType Array type containing pointers to reduction variables.
1200  /// \param Privates List of private copies for original reduction arguments.
1201  /// \param LHSExprs List of LHS in \a ReductionOps reduction operations.
1202  /// \param RHSExprs List of RHS in \a ReductionOps reduction operations.
1203  /// \param ReductionOps List of reduction operations in form 'LHS binop RHS'
1204  /// or 'operator binop(LHS, RHS)'.
1206  llvm::Type *ArgsType,
1208  ArrayRef<const Expr *> LHSExprs,
1209  ArrayRef<const Expr *> RHSExprs,
1210  ArrayRef<const Expr *> ReductionOps);
1211 
1212  /// Emits single reduction combiner
1214  const Expr *ReductionOp,
1215  const Expr *PrivateRef,
1216  const DeclRefExpr *LHS,
1217  const DeclRefExpr *RHS);
1218 
1223  };
1224  /// Emit a code for reduction clause. Next code should be emitted for
1225  /// reduction:
1226  /// \code
1227  ///
1228  /// static kmp_critical_name lock = { 0 };
1229  ///
1230  /// void reduce_func(void *lhs[<n>], void *rhs[<n>]) {
1231  /// ...
1232  /// *(Type<i>*)lhs[i] = RedOp<i>(*(Type<i>*)lhs[i], *(Type<i>*)rhs[i]);
1233  /// ...
1234  /// }
1235  ///
1236  /// ...
1237  /// void *RedList[<n>] = {&<RHSExprs>[0], ..., &<RHSExprs>[<n>-1]};
1238  /// switch (__kmpc_reduce{_nowait}(<loc>, <gtid>, <n>, sizeof(RedList),
1239  /// RedList, reduce_func, &<lock>)) {
1240  /// case 1:
1241  /// ...
1242  /// <LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]);
1243  /// ...
1244  /// __kmpc_end_reduce{_nowait}(<loc>, <gtid>, &<lock>);
1245  /// break;
1246  /// case 2:
1247  /// ...
1248  /// Atomic(<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]));
1249  /// ...
1250  /// break;
1251  /// default:;
1252  /// }
1253  /// \endcode
1254  ///
1255  /// \param Privates List of private copies for original reduction arguments.
1256  /// \param LHSExprs List of LHS in \a ReductionOps reduction operations.
1257  /// \param RHSExprs List of RHS in \a ReductionOps reduction operations.
1258  /// \param ReductionOps List of reduction operations in form 'LHS binop RHS'
1259  /// or 'operator binop(LHS, RHS)'.
1260  /// \param Options List of options for reduction codegen:
1261  /// WithNowait true if parent directive has also nowait clause, false
1262  /// otherwise.
1263  /// SimpleReduction Emit reduction operation only. Used for omp simd
1264  /// directive on the host.
1265  /// ReductionKind The kind of reduction to perform.
1266  virtual void emitReduction(CodeGenFunction &CGF, SourceLocation Loc,
1268  ArrayRef<const Expr *> LHSExprs,
1269  ArrayRef<const Expr *> RHSExprs,
1270  ArrayRef<const Expr *> ReductionOps,
1271  ReductionOptionsTy Options);
1272 
1273  /// Emit a code for initialization of task reduction clause. Next code
1274  /// should be emitted for reduction:
1275  /// \code
1276  ///
1277  /// _task_red_item_t red_data[n];
1278  /// ...
1279  /// red_data[i].shar = &origs[i];
1280  /// red_data[i].size = sizeof(origs[i]);
1281  /// red_data[i].f_init = (void*)RedInit<i>;
1282  /// red_data[i].f_fini = (void*)RedDest<i>;
1283  /// red_data[i].f_comb = (void*)RedOp<i>;
1284  /// red_data[i].flags = <Flag_i>;
1285  /// ...
1286  /// void* tg1 = __kmpc_task_reduction_init(gtid, n, red_data);
1287  /// \endcode
1288  ///
1289  /// \param LHSExprs List of LHS in \a Data.ReductionOps reduction operations.
1290  /// \param RHSExprs List of RHS in \a Data.ReductionOps reduction operations.
1291  /// \param Data Additional data for task generation like tiedness, final
1292  /// state, list of privates, reductions etc.
1294  SourceLocation Loc,
1295  ArrayRef<const Expr *> LHSExprs,
1296  ArrayRef<const Expr *> RHSExprs,
1297  const OMPTaskDataTy &Data);
1298 
1299  /// Required to resolve existing problems in the runtime. Emits threadprivate
1300  /// variables to store the size of the VLAs/array sections for
1301  /// initializer/combiner/finalizer functions + emits threadprivate variable to
1302  /// store the pointer to the original reduction item for the custom
1303  /// initializer defined by declare reduction construct.
1304  /// \param RCG Allows to reuse an existing data for the reductions.
1305  /// \param N Reduction item for which fixups must be emitted.
1307  ReductionCodeGen &RCG, unsigned N);
1308 
1309  /// Get the address of `void *` type of the privatue copy of the reduction
1310  /// item specified by the \p SharedLVal.
1311  /// \param ReductionsPtr Pointer to the reduction data returned by the
1312  /// emitTaskReductionInit function.
1313  /// \param SharedLVal Address of the original reduction item.
1315  llvm::Value *ReductionsPtr,
1316  LValue SharedLVal);
1317 
1318  /// Emit code for 'taskwait' directive.
1319  virtual void emitTaskwaitCall(CodeGenFunction &CGF, SourceLocation Loc);
1320 
1321  /// Emit code for 'cancellation point' construct.
1322  /// \param CancelRegion Region kind for which the cancellation point must be
1323  /// emitted.
1324  ///
1325  virtual void emitCancellationPointCall(CodeGenFunction &CGF,
1326  SourceLocation Loc,
1327  OpenMPDirectiveKind CancelRegion);
1328 
1329  /// Emit code for 'cancel' construct.
1330  /// \param IfCond Condition in the associated 'if' clause, if it was
1331  /// specified, nullptr otherwise.
1332  /// \param CancelRegion Region kind for which the cancel must be emitted.
1333  ///
1334  virtual void emitCancelCall(CodeGenFunction &CGF, SourceLocation Loc,
1335  const Expr *IfCond,
1336  OpenMPDirectiveKind CancelRegion);
1337 
1338  /// Emit outilined function for 'target' directive.
1339  /// \param D Directive to emit.
1340  /// \param ParentName Name of the function that encloses the target region.
1341  /// \param OutlinedFn Outlined function value to be defined by this call.
1342  /// \param OutlinedFnID Outlined function ID value to be defined by this call.
1343  /// \param IsOffloadEntry True if the outlined function is an offload entry.
1344  /// \param CodeGen Code generation sequence for the \a D directive.
1345  /// An outlined function may not be an entry if, e.g. the if clause always
1346  /// evaluates to false.
1347  virtual void emitTargetOutlinedFunction(const OMPExecutableDirective &D,
1348  StringRef ParentName,
1349  llvm::Function *&OutlinedFn,
1350  llvm::Constant *&OutlinedFnID,
1351  bool IsOffloadEntry,
1352  const RegionCodeGenTy &CodeGen);
1353 
1354  /// Emit the target offloading code associated with \a D. The emitted
1355  /// code attempts offloading the execution to the device, an the event of
1356  /// a failure it executes the host version outlined in \a OutlinedFn.
1357  /// \param D Directive to emit.
1358  /// \param OutlinedFn Host version of the code to be offloaded.
1359  /// \param OutlinedFnID ID of host version of the code to be offloaded.
1360  /// \param IfCond Expression evaluated in if clause associated with the target
1361  /// directive, or null if no if clause is used.
1362  /// \param Device Expression evaluated in device clause associated with the
1363  /// target directive, or null if no device clause is used.
1364  virtual void emitTargetCall(CodeGenFunction &CGF,
1365  const OMPExecutableDirective &D,
1366  llvm::Value *OutlinedFn,
1367  llvm::Value *OutlinedFnID, const Expr *IfCond,
1368  const Expr *Device);
1369 
1370  /// Emit the target regions enclosed in \a GD function definition or
1371  /// the function itself in case it is a valid device function. Returns true if
1372  /// \a GD was dealt with successfully.
1373  /// \param GD Function to scan.
1374  virtual bool emitTargetFunctions(GlobalDecl GD);
1375 
1376  /// Emit the global variable if it is a valid device global variable.
1377  /// Returns true if \a GD was dealt with successfully.
1378  /// \param GD Variable declaration to emit.
1379  virtual bool emitTargetGlobalVariable(GlobalDecl GD);
1380 
1381  /// Checks if the provided global decl \a GD is a declare target variable and
1382  /// registers it when emitting code for the host.
1383  virtual void registerTargetGlobalVariable(const VarDecl *VD,
1384  llvm::Constant *Addr);
1385 
1386  /// Emit the global \a GD if it is meaningful for the target. Returns
1387  /// if it was emitted successfully.
1388  /// \param GD Global to scan.
1389  virtual bool emitTargetGlobal(GlobalDecl GD);
1390 
1391  /// Creates the offloading descriptor in the event any target region
1392  /// was emitted in the current module and return the function that registers
1393  /// it.
1394  virtual llvm::Function *emitRegistrationFunction();
1395 
1396  /// Emits code for teams call of the \a OutlinedFn with
1397  /// variables captured in a record which address is stored in \a
1398  /// CapturedStruct.
1399  /// \param OutlinedFn Outlined function to be run by team masters. Type of
1400  /// this function is void(*)(kmp_int32 *, kmp_int32, struct context_vars*).
1401  /// \param CapturedVars A pointer to the record with the references to
1402  /// variables used in \a OutlinedFn function.
1403  ///
1404  virtual void emitTeamsCall(CodeGenFunction &CGF,
1405  const OMPExecutableDirective &D,
1406  SourceLocation Loc, llvm::Value *OutlinedFn,
1407  ArrayRef<llvm::Value *> CapturedVars);
1408 
1409  /// Emits call to void __kmpc_push_num_teams(ident_t *loc, kmp_int32
1410  /// global_tid, kmp_int32 num_teams, kmp_int32 thread_limit) to generate code
1411  /// for num_teams clause.
1412  /// \param NumTeams An integer expression of teams.
1413  /// \param ThreadLimit An integer expression of threads.
1414  virtual void emitNumTeamsClause(CodeGenFunction &CGF, const Expr *NumTeams,
1415  const Expr *ThreadLimit, SourceLocation Loc);
1416 
1417  /// Struct that keeps all the relevant information that should be kept
1418  /// throughout a 'target data' region.
1420  /// Set to true if device pointer information have to be obtained.
1421  bool RequiresDevicePointerInfo = false;
1422 
1423  public:
1424  /// The array of base pointer passed to the runtime library.
1425  llvm::Value *BasePointersArray = nullptr;
1426  /// The array of section pointers passed to the runtime library.
1427  llvm::Value *PointersArray = nullptr;
1428  /// The array of sizes passed to the runtime library.
1429  llvm::Value *SizesArray = nullptr;
1430  /// The array of map types passed to the runtime library.
1431  llvm::Value *MapTypesArray = nullptr;
1432  /// The total number of pointers passed to the runtime library.
1433  unsigned NumberOfPtrs = 0u;
1434  /// Map between the a declaration of a capture and the corresponding base
1435  /// pointer address where the runtime returns the device pointers.
1436  llvm::DenseMap<const ValueDecl *, Address> CaptureDeviceAddrMap;
1437 
1438  explicit TargetDataInfo() {}
1439  explicit TargetDataInfo(bool RequiresDevicePointerInfo)
1440  : RequiresDevicePointerInfo(RequiresDevicePointerInfo) {}
1441  /// Clear information about the data arrays.
1443  BasePointersArray = nullptr;
1444  PointersArray = nullptr;
1445  SizesArray = nullptr;
1446  MapTypesArray = nullptr;
1447  NumberOfPtrs = 0u;
1448  }
1449  /// Return true if the current target data information has valid arrays.
1450  bool isValid() {
1451  return BasePointersArray && PointersArray && SizesArray &&
1452  MapTypesArray && NumberOfPtrs;
1453  }
1454  bool requiresDevicePointerInfo() { return RequiresDevicePointerInfo; }
1455  };
1456 
1457  /// Emit the target data mapping code associated with \a D.
1458  /// \param D Directive to emit.
1459  /// \param IfCond Expression evaluated in if clause associated with the
1460  /// target directive, or null if no device clause is used.
1461  /// \param Device Expression evaluated in device clause associated with the
1462  /// target directive, or null if no device clause is used.
1463  /// \param Info A record used to store information that needs to be preserved
1464  /// until the region is closed.
1465  virtual void emitTargetDataCalls(CodeGenFunction &CGF,
1466  const OMPExecutableDirective &D,
1467  const Expr *IfCond, const Expr *Device,
1468  const RegionCodeGenTy &CodeGen,
1469  TargetDataInfo &Info);
1470 
1471  /// Emit the data mapping/movement code associated with the directive
1472  /// \a D that should be of the form 'target [{enter|exit} data | update]'.
1473  /// \param D Directive to emit.
1474  /// \param IfCond Expression evaluated in if clause associated with the target
1475  /// directive, or null if no if clause is used.
1476  /// \param Device Expression evaluated in device clause associated with the
1477  /// target directive, or null if no device clause is used.
1479  const OMPExecutableDirective &D,
1480  const Expr *IfCond,
1481  const Expr *Device);
1482 
1483  /// Marks function \a Fn with properly mangled versions of vector functions.
1484  /// \param FD Function marked as 'declare simd'.
1485  /// \param Fn LLVM function that must be marked with 'declare simd'
1486  /// attributes.
1487  virtual void emitDeclareSimdFunction(const FunctionDecl *FD,
1488  llvm::Function *Fn);
1489 
1490  /// Emit initialization for doacross loop nesting support.
1491  /// \param D Loop-based construct used in doacross nesting construct.
1492  virtual void emitDoacrossInit(CodeGenFunction &CGF, const OMPLoopDirective &D,
1493  ArrayRef<Expr *> NumIterations);
1494 
1495  /// Emit code for doacross ordered directive with 'depend' clause.
1496  /// \param C 'depend' clause with 'sink|source' dependency kind.
1497  virtual void emitDoacrossOrdered(CodeGenFunction &CGF,
1498  const OMPDependClause *C);
1499 
1500  /// Translates the native parameter of outlined function if this is required
1501  /// for target.
1502  /// \param FD Field decl from captured record for the parameter.
1503  /// \param NativeParam Parameter itself.
1504  virtual const VarDecl *translateParameter(const FieldDecl *FD,
1505  const VarDecl *NativeParam) const {
1506  return NativeParam;
1507  }
1508 
1509  /// Gets the address of the native argument basing on the address of the
1510  /// target-specific parameter.
1511  /// \param NativeParam Parameter itself.
1512  /// \param TargetParam Corresponding target-specific parameter.
1514  const VarDecl *NativeParam,
1515  const VarDecl *TargetParam) const;
1516 
1517  /// Choose default schedule type and chunk value for the
1518  /// dist_schedule clause.
1520  const OMPLoopDirective &S, OpenMPDistScheduleClauseKind &ScheduleKind,
1521  llvm::Value *&Chunk) const {}
1522 
1523  /// Choose default schedule type and chunk value for the
1524  /// schedule clause.
1526  const OMPLoopDirective &S, OpenMPScheduleClauseKind &ScheduleKind,
1527  const Expr *&ChunkExpr) const {}
1528 
1529  /// Emits call of the outlined function with the provided arguments,
1530  /// translating these arguments to correct target-specific arguments.
1531  virtual void
1533  llvm::Value *OutlinedFn,
1534  ArrayRef<llvm::Value *> Args = llvm::None) const;
1535 
1536  /// Emits OpenMP-specific function prolog.
1537  /// Required for device constructs.
1538  virtual void emitFunctionProlog(CodeGenFunction &CGF, const Decl *D) {}
1539 
1540  /// Gets the OpenMP-specific address of the local variable.
1542  const VarDecl *VD);
1543 
1544  /// Marks the declaration as alread emitted for the device code and returns
1545  /// true, if it was marked already, and false, otherwise.
1546  bool markAsGlobalTarget(GlobalDecl GD);
1547 
1548  /// Emit deferred declare target variables marked for deferred emission.
1549  void emitDeferredTargetDecls() const;
1550 
1551  /// Adjust some parameters for the target-based directives, like addresses of
1552  /// the variables captured by reference in lambdas.
1553  virtual void
1555  const OMPExecutableDirective &D) const;
1556 };
1557 
1558 /// Class supports emissionof SIMD-only code.
1559 class CGOpenMPSIMDRuntime final : public CGOpenMPRuntime {
1560 public:
1561  explicit CGOpenMPSIMDRuntime(CodeGenModule &CGM) : CGOpenMPRuntime(CGM) {}
1562  ~CGOpenMPSIMDRuntime() override {}
1563 
1564  /// Emits outlined function for the specified OpenMP parallel directive
1565  /// \a D. This outlined function has type void(*)(kmp_int32 *ThreadID,
1566  /// kmp_int32 BoundID, struct context_vars*).
1567  /// \param D OpenMP directive.
1568  /// \param ThreadIDVar Variable for thread id in the current OpenMP region.
1569  /// \param InnermostKind Kind of innermost directive (for simple directives it
1570  /// is a directive itself, for combined - its innermost directive).
1571  /// \param CodeGen Code generation sequence for the \a D directive.
1572  llvm::Value *
1574  const VarDecl *ThreadIDVar,
1575  OpenMPDirectiveKind InnermostKind,
1576  const RegionCodeGenTy &CodeGen) override;
1577 
1578  /// Emits outlined function for the specified OpenMP teams directive
1579  /// \a D. This outlined function has type void(*)(kmp_int32 *ThreadID,
1580  /// kmp_int32 BoundID, struct context_vars*).
1581  /// \param D OpenMP directive.
1582  /// \param ThreadIDVar Variable for thread id in the current OpenMP region.
1583  /// \param InnermostKind Kind of innermost directive (for simple directives it
1584  /// is a directive itself, for combined - its innermost directive).
1585  /// \param CodeGen Code generation sequence for the \a D directive.
1586  llvm::Value *
1588  const VarDecl *ThreadIDVar,
1589  OpenMPDirectiveKind InnermostKind,
1590  const RegionCodeGenTy &CodeGen) override;
1591 
1592  /// Emits outlined function for the OpenMP task directive \a D. This
1593  /// outlined function has type void(*)(kmp_int32 ThreadID, struct task_t*
1594  /// TaskT).
1595  /// \param D OpenMP directive.
1596  /// \param ThreadIDVar Variable for thread id in the current OpenMP region.
1597  /// \param PartIDVar Variable for partition id in the current OpenMP untied
1598  /// task region.
1599  /// \param TaskTVar Variable for task_t argument.
1600  /// \param InnermostKind Kind of innermost directive (for simple directives it
1601  /// is a directive itself, for combined - its innermost directive).
1602  /// \param CodeGen Code generation sequence for the \a D directive.
1603  /// \param Tied true if task is generated for tied task, false otherwise.
1604  /// \param NumberOfParts Number of parts in untied task. Ignored for tied
1605  /// tasks.
1606  ///
1608  const OMPExecutableDirective &D, const VarDecl *ThreadIDVar,
1609  const VarDecl *PartIDVar, const VarDecl *TaskTVar,
1610  OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen,
1611  bool Tied, unsigned &NumberOfParts) override;
1612 
1613  /// Emits code for parallel or serial call of the \a OutlinedFn with
1614  /// variables captured in a record which address is stored in \a
1615  /// CapturedStruct.
1616  /// \param OutlinedFn Outlined function to be run in parallel threads. Type of
1617  /// this function is void(*)(kmp_int32 *, kmp_int32, struct context_vars*).
1618  /// \param CapturedVars A pointer to the record with the references to
1619  /// variables used in \a OutlinedFn function.
1620  /// \param IfCond Condition in the associated 'if' clause, if it was
1621  /// specified, nullptr otherwise.
1622  ///
1623  void emitParallelCall(CodeGenFunction &CGF, SourceLocation Loc,
1624  llvm::Value *OutlinedFn,
1625  ArrayRef<llvm::Value *> CapturedVars,
1626  const Expr *IfCond) override;
1627 
1628  /// Emits a critical region.
1629  /// \param CriticalName Name of the critical region.
1630  /// \param CriticalOpGen Generator for the statement associated with the given
1631  /// critical region.
1632  /// \param Hint Value of the 'hint' clause (optional).
1633  void emitCriticalRegion(CodeGenFunction &CGF, StringRef CriticalName,
1634  const RegionCodeGenTy &CriticalOpGen,
1635  SourceLocation Loc,
1636  const Expr *Hint = nullptr) override;
1637 
1638  /// Emits a master region.
1639  /// \param MasterOpGen Generator for the statement associated with the given
1640  /// master region.
1641  void emitMasterRegion(CodeGenFunction &CGF,
1642  const RegionCodeGenTy &MasterOpGen,
1643  SourceLocation Loc) override;
1644 
1645  /// Emits code for a taskyield directive.
1646  void emitTaskyieldCall(CodeGenFunction &CGF, SourceLocation Loc) override;
1647 
1648  /// Emit a taskgroup region.
1649  /// \param TaskgroupOpGen Generator for the statement associated with the
1650  /// given taskgroup region.
1651  void emitTaskgroupRegion(CodeGenFunction &CGF,
1652  const RegionCodeGenTy &TaskgroupOpGen,
1653  SourceLocation Loc) override;
1654 
1655  /// Emits a single region.
1656  /// \param SingleOpGen Generator for the statement associated with the given
1657  /// single region.
1658  void emitSingleRegion(CodeGenFunction &CGF,
1659  const RegionCodeGenTy &SingleOpGen, SourceLocation Loc,
1660  ArrayRef<const Expr *> CopyprivateVars,
1661  ArrayRef<const Expr *> DestExprs,
1662  ArrayRef<const Expr *> SrcExprs,
1663  ArrayRef<const Expr *> AssignmentOps) override;
1664 
1665  /// Emit an ordered region.
1666  /// \param OrderedOpGen Generator for the statement associated with the given
1667  /// ordered region.
1668  void emitOrderedRegion(CodeGenFunction &CGF,
1669  const RegionCodeGenTy &OrderedOpGen,
1670  SourceLocation Loc, bool IsThreads) override;
1671 
1672  /// Emit an implicit/explicit barrier for OpenMP threads.
1673  /// \param Kind Directive for which this implicit barrier call must be
1674  /// generated. Must be OMPD_barrier for explicit barrier generation.
1675  /// \param EmitChecks true if need to emit checks for cancellation barriers.
1676  /// \param ForceSimpleCall true simple barrier call must be emitted, false if
1677  /// runtime class decides which one to emit (simple or with cancellation
1678  /// checks).
1679  ///
1680  void emitBarrierCall(CodeGenFunction &CGF, SourceLocation Loc,
1681  OpenMPDirectiveKind Kind, bool EmitChecks = true,
1682  bool ForceSimpleCall = false) override;
1683 
1684  /// This is used for non static scheduled types and when the ordered
1685  /// clause is present on the loop construct.
1686  /// Depending on the loop schedule, it is necessary to call some runtime
1687  /// routine before start of the OpenMP loop to get the loop upper / lower
1688  /// bounds \a LB and \a UB and stride \a ST.
1689  ///
1690  /// \param CGF Reference to current CodeGenFunction.
1691  /// \param Loc Clang source location.
1692  /// \param ScheduleKind Schedule kind, specified by the 'schedule' clause.
1693  /// \param IVSize Size of the iteration variable in bits.
1694  /// \param IVSigned Sign of the iteration variable.
1695  /// \param Ordered true if loop is ordered, false otherwise.
1696  /// \param DispatchValues struct containing llvm values for lower bound, upper
1697  /// bound, and chunk expression.
1698  /// For the default (nullptr) value, the chunk 1 will be used.
1699  ///
1700  void emitForDispatchInit(CodeGenFunction &CGF, SourceLocation Loc,
1701  const OpenMPScheduleTy &ScheduleKind,
1702  unsigned IVSize, bool IVSigned, bool Ordered,
1703  const DispatchRTInput &DispatchValues) override;
1704 
1705  /// Call the appropriate runtime routine to initialize it before start
1706  /// of loop.
1707  ///
1708  /// This is used only in case of static schedule, when the user did not
1709  /// specify a ordered clause on the loop construct.
1710  /// Depending on the loop schedule, it is necessary to call some runtime
1711  /// routine before start of the OpenMP loop to get the loop upper / lower
1712  /// bounds LB and UB and stride ST.
1713  ///
1714  /// \param CGF Reference to current CodeGenFunction.
1715  /// \param Loc Clang source location.
1716  /// \param DKind Kind of the directive.
1717  /// \param ScheduleKind Schedule kind, specified by the 'schedule' clause.
1718  /// \param Values Input arguments for the construct.
1719  ///
1720  void emitForStaticInit(CodeGenFunction &CGF, SourceLocation Loc,
1721  OpenMPDirectiveKind DKind,
1722  const OpenMPScheduleTy &ScheduleKind,
1723  const StaticRTInput &Values) override;
1724 
1725  ///
1726  /// \param CGF Reference to current CodeGenFunction.
1727  /// \param Loc Clang source location.
1728  /// \param SchedKind Schedule kind, specified by the 'dist_schedule' clause.
1729  /// \param Values Input arguments for the construct.
1730  ///
1731  void emitDistributeStaticInit(CodeGenFunction &CGF, SourceLocation Loc,
1732  OpenMPDistScheduleClauseKind SchedKind,
1733  const StaticRTInput &Values) override;
1734 
1735  /// Call the appropriate runtime routine to notify that we finished
1736  /// iteration of the ordered loop with the dynamic scheduling.
1737  ///
1738  /// \param CGF Reference to current CodeGenFunction.
1739  /// \param Loc Clang source location.
1740  /// \param IVSize Size of the iteration variable in bits.
1741  /// \param IVSigned Sign of the iteration variable.
1742  ///
1743  void emitForOrderedIterationEnd(CodeGenFunction &CGF, SourceLocation Loc,
1744  unsigned IVSize, bool IVSigned) override;
1745 
1746  /// Call the appropriate runtime routine to notify that we finished
1747  /// all the work with current loop.
1748  ///
1749  /// \param CGF Reference to current CodeGenFunction.
1750  /// \param Loc Clang source location.
1751  /// \param DKind Kind of the directive for which the static finish is emitted.
1752  ///
1753  void emitForStaticFinish(CodeGenFunction &CGF, SourceLocation Loc,
1754  OpenMPDirectiveKind DKind) override;
1755 
1756  /// Call __kmpc_dispatch_next(
1757  /// ident_t *loc, kmp_int32 tid, kmp_int32 *p_lastiter,
1758  /// kmp_int[32|64] *p_lower, kmp_int[32|64] *p_upper,
1759  /// kmp_int[32|64] *p_stride);
1760  /// \param IVSize Size of the iteration variable in bits.
1761  /// \param IVSigned Sign of the iteration variable.
1762  /// \param IL Address of the output variable in which the flag of the
1763  /// last iteration is returned.
1764  /// \param LB Address of the output variable in which the lower iteration
1765  /// number is returned.
1766  /// \param UB Address of the output variable in which the upper iteration
1767  /// number is returned.
1768  /// \param ST Address of the output variable in which the stride value is
1769  /// returned.
1770  llvm::Value *emitForNext(CodeGenFunction &CGF, SourceLocation Loc,
1771  unsigned IVSize, bool IVSigned, Address IL,
1772  Address LB, Address UB, Address ST) override;
1773 
1774  /// Emits call to void __kmpc_push_num_threads(ident_t *loc, kmp_int32
1775  /// global_tid, kmp_int32 num_threads) to generate code for 'num_threads'
1776  /// clause.
1777  /// \param NumThreads An integer value of threads.
1778  void emitNumThreadsClause(CodeGenFunction &CGF, llvm::Value *NumThreads,
1779  SourceLocation Loc) override;
1780 
1781  /// Emit call to void __kmpc_push_proc_bind(ident_t *loc, kmp_int32
1782  /// global_tid, int proc_bind) to generate code for 'proc_bind' clause.
1783  void emitProcBindClause(CodeGenFunction &CGF,
1784  OpenMPProcBindClauseKind ProcBind,
1785  SourceLocation Loc) override;
1786 
1787  /// Returns address of the threadprivate variable for the current
1788  /// thread.
1789  /// \param VD Threadprivate variable.
1790  /// \param VDAddr Address of the global variable \a VD.
1791  /// \param Loc Location of the reference to threadprivate var.
1792  /// \return Address of the threadprivate variable for the current thread.
1793  Address getAddrOfThreadPrivate(CodeGenFunction &CGF, const VarDecl *VD,
1794  Address VDAddr, SourceLocation Loc) override;
1795 
1796  /// Emit a code for initialization of threadprivate variable. It emits
1797  /// a call to runtime library which adds initial value to the newly created
1798  /// threadprivate variable (if it is not constant) and registers destructor
1799  /// for the variable (if any).
1800  /// \param VD Threadprivate variable.
1801  /// \param VDAddr Address of the global variable \a VD.
1802  /// \param Loc Location of threadprivate declaration.
1803  /// \param PerformInit true if initialization expression is not constant.
1804  llvm::Function *
1805  emitThreadPrivateVarDefinition(const VarDecl *VD, Address VDAddr,
1806  SourceLocation Loc, bool PerformInit,
1807  CodeGenFunction *CGF = nullptr) override;
1808 
1809  /// Creates artificial threadprivate variable with name \p Name and type \p
1810  /// VarType.
1811  /// \param VarType Type of the artificial threadprivate variable.
1812  /// \param Name Name of the artificial threadprivate variable.
1813  Address getAddrOfArtificialThreadPrivate(CodeGenFunction &CGF,
1814  QualType VarType,
1815  StringRef Name) override;
1816 
1817  /// Emit flush of the variables specified in 'omp flush' directive.
1818  /// \param Vars List of variables to flush.
1819  void emitFlush(CodeGenFunction &CGF, ArrayRef<const Expr *> Vars,
1820  SourceLocation Loc) override;
1821 
1822  /// Emit task region for the task directive. The task region is
1823  /// emitted in several steps:
1824  /// 1. Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32
1825  /// gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds,
1826  /// kmp_routine_entry_t *task_entry). Here task_entry is a pointer to the
1827  /// function:
1828  /// kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) {
1829  /// TaskFunction(gtid, tt->part_id, tt->shareds);
1830  /// return 0;
1831  /// }
1832  /// 2. Copy a list of shared variables to field shareds of the resulting
1833  /// structure kmp_task_t returned by the previous call (if any).
1834  /// 3. Copy a pointer to destructions function to field destructions of the
1835  /// resulting structure kmp_task_t.
1836  /// 4. Emit a call to kmp_int32 __kmpc_omp_task(ident_t *, kmp_int32 gtid,
1837  /// kmp_task_t *new_task), where new_task is a resulting structure from
1838  /// previous items.
1839  /// \param D Current task directive.
1840  /// \param TaskFunction An LLVM function with type void (*)(i32 /*gtid*/, i32
1841  /// /*part_id*/, captured_struct */*__context*/);
1842  /// \param SharedsTy A type which contains references the shared variables.
1843  /// \param Shareds Context with the list of shared variables from the \p
1844  /// TaskFunction.
1845  /// \param IfCond Not a nullptr if 'if' clause was specified, nullptr
1846  /// otherwise.
1847  /// \param Data Additional data for task generation like tiednsee, final
1848  /// state, list of privates etc.
1849  void emitTaskCall(CodeGenFunction &CGF, SourceLocation Loc,
1850  const OMPExecutableDirective &D, llvm::Value *TaskFunction,
1851  QualType SharedsTy, Address Shareds, const Expr *IfCond,
1852  const OMPTaskDataTy &Data) override;
1853 
1854  /// Emit task region for the taskloop directive. The taskloop region is
1855  /// emitted in several steps:
1856  /// 1. Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32
1857  /// gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds,
1858  /// kmp_routine_entry_t *task_entry). Here task_entry is a pointer to the
1859  /// function:
1860  /// kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) {
1861  /// TaskFunction(gtid, tt->part_id, tt->shareds);
1862  /// return 0;
1863  /// }
1864  /// 2. Copy a list of shared variables to field shareds of the resulting
1865  /// structure kmp_task_t returned by the previous call (if any).
1866  /// 3. Copy a pointer to destructions function to field destructions of the
1867  /// resulting structure kmp_task_t.
1868  /// 4. Emit a call to void __kmpc_taskloop(ident_t *loc, int gtid, kmp_task_t
1869  /// *task, int if_val, kmp_uint64 *lb, kmp_uint64 *ub, kmp_int64 st, int
1870  /// nogroup, int sched, kmp_uint64 grainsize, void *task_dup ), where new_task
1871  /// is a resulting structure from
1872  /// previous items.
1873  /// \param D Current task directive.
1874  /// \param TaskFunction An LLVM function with type void (*)(i32 /*gtid*/, i32
1875  /// /*part_id*/, captured_struct */*__context*/);
1876  /// \param SharedsTy A type which contains references the shared variables.
1877  /// \param Shareds Context with the list of shared variables from the \p
1878  /// TaskFunction.
1879  /// \param IfCond Not a nullptr if 'if' clause was specified, nullptr
1880  /// otherwise.
1881  /// \param Data Additional data for task generation like tiednsee, final
1882  /// state, list of privates etc.
1883  void emitTaskLoopCall(CodeGenFunction &CGF, SourceLocation Loc,
1884  const OMPLoopDirective &D, llvm::Value *TaskFunction,
1885  QualType SharedsTy, Address Shareds, const Expr *IfCond,
1886  const OMPTaskDataTy &Data) override;
1887 
1888  /// Emit a code for reduction clause. Next code should be emitted for
1889  /// reduction:
1890  /// \code
1891  ///
1892  /// static kmp_critical_name lock = { 0 };
1893  ///
1894  /// void reduce_func(void *lhs[<n>], void *rhs[<n>]) {
1895  /// ...
1896  /// *(Type<i>*)lhs[i] = RedOp<i>(*(Type<i>*)lhs[i], *(Type<i>*)rhs[i]);
1897  /// ...
1898  /// }
1899  ///
1900  /// ...
1901  /// void *RedList[<n>] = {&<RHSExprs>[0], ..., &<RHSExprs>[<n>-1]};
1902  /// switch (__kmpc_reduce{_nowait}(<loc>, <gtid>, <n>, sizeof(RedList),
1903  /// RedList, reduce_func, &<lock>)) {
1904  /// case 1:
1905  /// ...
1906  /// <LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]);
1907  /// ...
1908  /// __kmpc_end_reduce{_nowait}(<loc>, <gtid>, &<lock>);
1909  /// break;
1910  /// case 2:
1911  /// ...
1912  /// Atomic(<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]));
1913  /// ...
1914  /// break;
1915  /// default:;
1916  /// }
1917  /// \endcode
1918  ///
1919  /// \param Privates List of private copies for original reduction arguments.
1920  /// \param LHSExprs List of LHS in \a ReductionOps reduction operations.
1921  /// \param RHSExprs List of RHS in \a ReductionOps reduction operations.
1922  /// \param ReductionOps List of reduction operations in form 'LHS binop RHS'
1923  /// or 'operator binop(LHS, RHS)'.
1924  /// \param Options List of options for reduction codegen:
1925  /// WithNowait true if parent directive has also nowait clause, false
1926  /// otherwise.
1927  /// SimpleReduction Emit reduction operation only. Used for omp simd
1928  /// directive on the host.
1929  /// ReductionKind The kind of reduction to perform.
1930  void emitReduction(CodeGenFunction &CGF, SourceLocation Loc,
1932  ArrayRef<const Expr *> LHSExprs,
1933  ArrayRef<const Expr *> RHSExprs,
1934  ArrayRef<const Expr *> ReductionOps,
1935  ReductionOptionsTy Options) override;
1936 
1937  /// Emit a code for initialization of task reduction clause. Next code
1938  /// should be emitted for reduction:
1939  /// \code
1940  ///
1941  /// _task_red_item_t red_data[n];
1942  /// ...
1943  /// red_data[i].shar = &origs[i];
1944  /// red_data[i].size = sizeof(origs[i]);
1945  /// red_data[i].f_init = (void*)RedInit<i>;
1946  /// red_data[i].f_fini = (void*)RedDest<i>;
1947  /// red_data[i].f_comb = (void*)RedOp<i>;
1948  /// red_data[i].flags = <Flag_i>;
1949  /// ...
1950  /// void* tg1 = __kmpc_task_reduction_init(gtid, n, red_data);
1951  /// \endcode
1952  ///
1953  /// \param LHSExprs List of LHS in \a Data.ReductionOps reduction operations.
1954  /// \param RHSExprs List of RHS in \a Data.ReductionOps reduction operations.
1955  /// \param Data Additional data for task generation like tiedness, final
1956  /// state, list of privates, reductions etc.
1957  llvm::Value *emitTaskReductionInit(CodeGenFunction &CGF, SourceLocation Loc,
1958  ArrayRef<const Expr *> LHSExprs,
1959  ArrayRef<const Expr *> RHSExprs,
1960  const OMPTaskDataTy &Data) override;
1961 
1962  /// Required to resolve existing problems in the runtime. Emits threadprivate
1963  /// variables to store the size of the VLAs/array sections for
1964  /// initializer/combiner/finalizer functions + emits threadprivate variable to
1965  /// store the pointer to the original reduction item for the custom
1966  /// initializer defined by declare reduction construct.
1967  /// \param RCG Allows to reuse an existing data for the reductions.
1968  /// \param N Reduction item for which fixups must be emitted.
1969  void emitTaskReductionFixups(CodeGenFunction &CGF, SourceLocation Loc,
1970  ReductionCodeGen &RCG, unsigned N) override;
1971 
1972  /// Get the address of `void *` type of the privatue copy of the reduction
1973  /// item specified by the \p SharedLVal.
1974  /// \param ReductionsPtr Pointer to the reduction data returned by the
1975  /// emitTaskReductionInit function.
1976  /// \param SharedLVal Address of the original reduction item.
1977  Address getTaskReductionItem(CodeGenFunction &CGF, SourceLocation Loc,
1978  llvm::Value *ReductionsPtr,
1979  LValue SharedLVal) override;
1980 
1981  /// Emit code for 'taskwait' directive.
1982  void emitTaskwaitCall(CodeGenFunction &CGF, SourceLocation Loc) override;
1983 
1984  /// Emit code for 'cancellation point' construct.
1985  /// \param CancelRegion Region kind for which the cancellation point must be
1986  /// emitted.
1987  ///
1988  void emitCancellationPointCall(CodeGenFunction &CGF, SourceLocation Loc,
1989  OpenMPDirectiveKind CancelRegion) override;
1990 
1991  /// Emit code for 'cancel' construct.
1992  /// \param IfCond Condition in the associated 'if' clause, if it was
1993  /// specified, nullptr otherwise.
1994  /// \param CancelRegion Region kind for which the cancel must be emitted.
1995  ///
1996  void emitCancelCall(CodeGenFunction &CGF, SourceLocation Loc,
1997  const Expr *IfCond,
1998  OpenMPDirectiveKind CancelRegion) override;
1999 
2000  /// Emit outilined function for 'target' directive.
2001  /// \param D Directive to emit.
2002  /// \param ParentName Name of the function that encloses the target region.
2003  /// \param OutlinedFn Outlined function value to be defined by this call.
2004  /// \param OutlinedFnID Outlined function ID value to be defined by this call.
2005  /// \param IsOffloadEntry True if the outlined function is an offload entry.
2006  /// \param CodeGen Code generation sequence for the \a D directive.
2007  /// An outlined function may not be an entry if, e.g. the if clause always
2008  /// evaluates to false.
2010  StringRef ParentName,
2011  llvm::Function *&OutlinedFn,
2012  llvm::Constant *&OutlinedFnID,
2013  bool IsOffloadEntry,
2014  const RegionCodeGenTy &CodeGen) override;
2015 
2016  /// Emit the target offloading code associated with \a D. The emitted
2017  /// code attempts offloading the execution to the device, an the event of
2018  /// a failure it executes the host version outlined in \a OutlinedFn.
2019  /// \param D Directive to emit.
2020  /// \param OutlinedFn Host version of the code to be offloaded.
2021  /// \param OutlinedFnID ID of host version of the code to be offloaded.
2022  /// \param IfCond Expression evaluated in if clause associated with the target
2023  /// directive, or null if no if clause is used.
2024  /// \param Device Expression evaluated in device clause associated with the
2025  /// target directive, or null if no device clause is used.
2026  void emitTargetCall(CodeGenFunction &CGF, const OMPExecutableDirective &D,
2027  llvm::Value *OutlinedFn, llvm::Value *OutlinedFnID,
2028  const Expr *IfCond, const Expr *Device) override;
2029 
2030  /// Emit the target regions enclosed in \a GD function definition or
2031  /// the function itself in case it is a valid device function. Returns true if
2032  /// \a GD was dealt with successfully.
2033  /// \param GD Function to scan.
2034  bool emitTargetFunctions(GlobalDecl GD) override;
2035 
2036  /// Emit the global variable if it is a valid device global variable.
2037  /// Returns true if \a GD was dealt with successfully.
2038  /// \param GD Variable declaration to emit.
2039  bool emitTargetGlobalVariable(GlobalDecl GD) override;
2040 
2041  /// Emit the global \a GD if it is meaningful for the target. Returns
2042  /// if it was emitted successfully.
2043  /// \param GD Global to scan.
2044  bool emitTargetGlobal(GlobalDecl GD) override;
2045 
2046  /// Creates the offloading descriptor in the event any target region
2047  /// was emitted in the current module and return the function that registers
2048  /// it.
2049  llvm::Function *emitRegistrationFunction() override;
2050 
2051  /// Emits code for teams call of the \a OutlinedFn with
2052  /// variables captured in a record which address is stored in \a
2053  /// CapturedStruct.
2054  /// \param OutlinedFn Outlined function to be run by team masters. Type of
2055  /// this function is void(*)(kmp_int32 *, kmp_int32, struct context_vars*).
2056  /// \param CapturedVars A pointer to the record with the references to
2057  /// variables used in \a OutlinedFn function.
2058  ///
2059  void emitTeamsCall(CodeGenFunction &CGF, const OMPExecutableDirective &D,
2060  SourceLocation Loc, llvm::Value *OutlinedFn,
2061  ArrayRef<llvm::Value *> CapturedVars) override;
2062 
2063  /// Emits call to void __kmpc_push_num_teams(ident_t *loc, kmp_int32
2064  /// global_tid, kmp_int32 num_teams, kmp_int32 thread_limit) to generate code
2065  /// for num_teams clause.
2066  /// \param NumTeams An integer expression of teams.
2067  /// \param ThreadLimit An integer expression of threads.
2068  void emitNumTeamsClause(CodeGenFunction &CGF, const Expr *NumTeams,
2069  const Expr *ThreadLimit, SourceLocation Loc) override;
2070 
2071  /// Emit the target data mapping code associated with \a D.
2072  /// \param D Directive to emit.
2073  /// \param IfCond Expression evaluated in if clause associated with the
2074  /// target directive, or null if no device clause is used.
2075  /// \param Device Expression evaluated in device clause associated with the
2076  /// target directive, or null if no device clause is used.
2077  /// \param Info A record used to store information that needs to be preserved
2078  /// until the region is closed.
2079  void emitTargetDataCalls(CodeGenFunction &CGF,
2080  const OMPExecutableDirective &D, const Expr *IfCond,
2081  const Expr *Device, const RegionCodeGenTy &CodeGen,
2082  TargetDataInfo &Info) override;
2083 
2084  /// Emit the data mapping/movement code associated with the directive
2085  /// \a D that should be of the form 'target [{enter|exit} data | update]'.
2086  /// \param D Directive to emit.
2087  /// \param IfCond Expression evaluated in if clause associated with the target
2088  /// directive, or null if no if clause is used.
2089  /// \param Device Expression evaluated in device clause associated with the
2090  /// target directive, or null if no device clause is used.
2091  void emitTargetDataStandAloneCall(CodeGenFunction &CGF,
2092  const OMPExecutableDirective &D,
2093  const Expr *IfCond,
2094  const Expr *Device) override;
2095 
2096  /// Emit initialization for doacross loop nesting support.
2097  /// \param D Loop-based construct used in doacross nesting construct.
2098  void emitDoacrossInit(CodeGenFunction &CGF, const OMPLoopDirective &D,
2099  ArrayRef<Expr *> NumIterations) override;
2100 
2101  /// Emit code for doacross ordered directive with 'depend' clause.
2102  /// \param C 'depend' clause with 'sink|source' dependency kind.
2103  void emitDoacrossOrdered(CodeGenFunction &CGF,
2104  const OMPDependClause *C) override;
2105 
2106  /// Translates the native parameter of outlined function if this is required
2107  /// for target.
2108  /// \param FD Field decl from captured record for the parameter.
2109  /// \param NativeParam Parameter itself.
2110  const VarDecl *translateParameter(const FieldDecl *FD,
2111  const VarDecl *NativeParam) const override;
2112 
2113  /// Gets the address of the native argument basing on the address of the
2114  /// target-specific parameter.
2115  /// \param NativeParam Parameter itself.
2116  /// \param TargetParam Corresponding target-specific parameter.
2117  Address getParameterAddress(CodeGenFunction &CGF, const VarDecl *NativeParam,
2118  const VarDecl *TargetParam) const override;
2119 };
2120 
2121 } // namespace CodeGen
2122 } // namespace clang
2123 
2124 #endif
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
llvm::function_ref< void(unsigned, unsigned, StringRef, unsigned, const OffloadEntryInfoTargetRegion &)> OffloadTargetRegionEntryInfoActTy
brief Applies action Action on all registered entries.
Represents a function declaration or definition.
Definition: Decl.h:1732
OMPTargetRegionEntryKind
Kind of the target registry entry.
virtual Address getAddressOfLocalVariable(CodeGenFunction &CGF, const VarDecl *VD)
Gets the OpenMP-specific address of the local variable.
QualType TgtDeviceImageQTy
struct __tgt_device_image{ void *ImageStart; // Pointer to the target code start. ...
Scheduling data for loop-based OpenMP directives.
Definition: OpenMPKinds.h:132
A (possibly-)qualified type.
Definition: Type.h:642
Allows to disable automatic handling of functions used in target regions as those marked as omp decla...
void emitSingleReductionCombiner(CodeGenFunction &CGF, const Expr *ReductionOp, const Expr *PrivateRef, const DeclRefExpr *LHS, const DeclRefExpr *RHS)
Emits single reduction combiner.
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
Definition: Dominators.h:30
Stmt - This represents one statement.
Definition: Stmt.h:66
virtual void emitUserDefinedReduction(CodeGenFunction *CGF, const OMPDeclareReductionDecl *D)
Emit code for the specified user defined reduction construct.
C Language Family Type Representation.
QualType getTgtBinaryDescriptorQTy()
Returns __tgt_bin_desc type.
SmallVector< std::pair< OpenMPDependClauseKind, const Expr * >, 4 > Dependences
SmallVector< const Expr *, 4 > LastprivateCopies
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:87
llvm::Constant * getOrCreateInternalVariable(llvm::Type *Ty, const llvm::Twine &Name)
Gets (if variable with the given name already exist) or creates internal global variable with the spe...
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::SmallDenseSet< const VarDecl * > DeferredGlobalVariables
List of variables that can become declare target implicitly and, thus, must be emitted.
virtual Address getAddrOfArtificialThreadPrivate(CodeGenFunction &CGF, QualType VarType, StringRef Name)
Creates artificial threadprivate variable with name Name and type VarType.
virtual void clear()
bool markAsGlobalTarget(GlobalDecl GD)
Marks the declaration as alread emitted for the device code and returns true, if it was marked alread...
struct with the values to be passed to the dispatch runtime function
OffloadEntryInfoDeviceGlobalVar(unsigned Order, OMPTargetGlobalVarEntryKind Flags)
void scanForTargetRegionsFunctions(const Stmt *S, StringRef ParentName)
Start scanning from statement S and and emit all target regions found along the way.
llvm::Value * getCriticalRegionLock(StringRef CriticalName)
Returns corresponding lock object for the specified critical region name.
SmallVector< const Expr *, 4 > ReductionCopies
DispatchRTInput(llvm::Value *LB, llvm::Value *UB, llvm::Value *Chunk)
Represents a variable declaration or definition.
Definition: Decl.h:812
virtual void emitOutlinedFunctionCall(CodeGenFunction &CGF, SourceLocation Loc, llvm::Value *OutlinedFn, ArrayRef< llvm::Value *> Args=llvm::None) const
Emits call of the outlined function with the provided arguments, translating these arguments to corre...
bool isValid()
Return true if the current target data information has valid arrays.
llvm::DenseMap< const ValueDecl *, Address > CaptureDeviceAddrMap
Map between the a declaration of a capture and the corresponding base pointer address where the runti...
Class supports emissionof SIMD-only code.
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...
virtual void Exit(CodeGenFunction &CGF)
Linkage
Describes the different kinds of linkage (C++ [basic.link], C99 6.2.2) that an entity may have...
Definition: Linkage.h:24
void createOffloadEntriesAndInfoMetadata()
Creates all the offload entries in the current compilation unit along with the associated metadata...
std::string getName(ArrayRef< StringRef > Parts) const
Get the platform-specific name separator.
Struct that keeps all the relevant information that should be kept throughout a &#39;target data&#39; region...
QualType getTgtOffloadEntryQTy()
Returns __tgt_offload_entry type.
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 &#39;targe...
SmallVector< const Expr *, 4 > PrivateVars
Represents a struct/union/class.
Definition: Decl.h:3589
llvm::StringMap< llvm::WeakTrackingVH > EmittedNonTargetVariables
List of the global variables with their addresses that should not be emitted for the target...
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
virtual void emitMasterRegion(CodeGenFunction &CGF, const RegionCodeGenTy &MasterOpGen, SourceLocation Loc)
Emits a master 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...
SmallVector< const Expr *, 4 > LastprivateVars
virtual void emitDoacrossOrdered(CodeGenFunction &CGF, const OMPDependClause *C)
Emit code for doacross ordered directive with &#39;depend&#39; clause.
Represents a member of a struct/union/class.
Definition: Decl.h:2575
Definition: Format.h:2072
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)...
OMPTargetGlobalVarEntryKind
Kind of the global variable entry..
virtual bool isDynamic(OpenMPScheduleClauseKind ScheduleKind) const
Check if the specified ScheduleKind is dynamic.
Defines some OpenMP-specific enums and functions.
llvm::Type * getKmpc_MicroPointerTy()
Returns pointer to kmpc_micro type.
This is a common base class for loop directives (&#39;omp simd&#39;, &#39;omp for&#39;, &#39;omp for simd&#39; etc...
Definition: StmtOpenMP.h:338
static bool classof(const OffloadEntryInfo *Info)
virtual bool emitTargetFunctions(GlobalDecl GD)
Emit the target regions enclosed in GD function definition or the function itself in case it is a val...
OpenMPDistScheduleClauseKind
OpenMP attributes for &#39;dist_schedule&#39; clause.
Definition: OpenMPKinds.h:100
virtual void emitDoacrossInit(CodeGenFunction &CGF, const OMPLoopDirective &D, ArrayRef< Expr *> NumIterations)
Emit initialization for doacross loop nesting support.
virtual void emitTargetCall(CodeGenFunction &CGF, const OMPExecutableDirective &D, llvm::Value *OutlinedFn, llvm::Value *OutlinedFnID, const Expr *IfCond, const Expr *Device)
Emit the target offloading code associated with D.
QualType TgtOffloadEntryQTy
Type struct __tgt_offload_entry{ void *addr; // Pointer to the offload entry info.
CharUnits - This is an opaque type for sizes expressed in character units.
Definition: CharUnits.h:38
virtual void emitTargetDataCalls(CodeGenFunction &CGF, const OMPExecutableDirective &D, const Expr *IfCond, const Expr *Device, const RegionCodeGenTy &CodeGen, TargetDataInfo &Info)
Emit the target data mapping code associated with D.
i32 captured_struct **param SharedsTy A type which contains references the shared variables *param Shareds Context with the list of shared variables from the p *TaskFunction *param IfCond Not a nullptr if if clause was nullptr *otherwise *param Data Additional data for task generation like final list of privates etc *virtual void emitTaskCall(CodeGenFunction &CGF, SourceLocation Loc, const OMPExecutableDirective &D, llvm::Value *TaskFunction, QualType SharedsTy, Address Shareds, const Expr *IfCond, const OMPTaskDataTy &Data)
llvm::StringSet ThreadPrivateWithDefinition
Set of threadprivate variables with the generated initializer.
virtual std::pair< llvm::Function *, llvm::Function * > getUserDefinedReduction(const OMPDeclareReductionDecl *D)
Get combiner/initializer for the specified user-defined reduction, if any.
SmallVector< const Expr *, 4 > PrivateCopies
llvm::StringSet AlreadyEmittedTargetFunctions
List of the emitted functions.
virtual void emitDeclareSimdFunction(const FunctionDecl *FD, llvm::Function *Fn)
Marks function Fn with properly mangled versions of vector functions.
virtual void emitTeamsCall(CodeGenFunction &CGF, const OMPExecutableDirective &D, SourceLocation Loc, llvm::Value *OutlinedFn, ArrayRef< llvm::Value *> CapturedVars)
Emits code for teams call of the OutlinedFn with variables captured in a record which address is stor...
SmallVector< const Expr *, 4 > FirstprivateCopies
llvm::Value * emitReductionFunction(CodeGenModule &CGM, SourceLocation Loc, llvm::Type *ArgsType, ArrayRef< const Expr *> Privates, ArrayRef< const Expr *> LHSExprs, ArrayRef< const Expr *> RHSExprs, ArrayRef< const Expr *> ReductionOps)
Emits reduction function.
virtual void emitFunctionProlog(CodeGenFunction &CGF, const Decl *D)
Emits OpenMP-specific function prolog.
const VarDecl * getBaseDecl(unsigned N) const
Returns the base declaration of the reduction item.
__INTPTR_TYPE__ intptr_t
A signed integer type with the property that any valid pointer to void can be converted to this type...
Definition: opencl-c.h:83
virtual llvm::Value * emitTeamsOutlinedFunction(const OMPExecutableDirective &D, const VarDecl *ThreadIDVar, OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen)
Emits outlined function for the specified OpenMP teams directive D.
SmallVector< const Expr *, 4 > ReductionOps
SmallVector< const Expr *, 4 > ReductionVars
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 Address getAddrOfDeclareTargetLink(const VarDecl *VD)
Returns the address of the variable marked as declare target with link clause.
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...
llvm::Constant * createForStaticInitFunction(unsigned IVSize, bool IVSigned)
Returns __kmpc_for_static_init_* runtime function for the specified size IVSize and sign IVSigned...
TargetDataInfo(bool RequiresDevicePointerInfo)
Class intended to support codegen of all kind of the reduction clauses.
llvm::Constant * createDispatchFiniFunction(unsigned IVSize, bool IVSigned)
Returns __kmpc_dispatch_fini_* runtime function for the specified size IVSize and sign IVSigned...
QualType getTgtDeviceImageQTy()
Returns __tgt_device_image type.
This represents implicit clause &#39;depend&#39; for the &#39;#pragma omp task&#39; directive.
void emitDeferredTargetDecls() const
Emit deferred declare target variables marked for deferred emission.
virtual void emitTaskReductionFixups(CodeGenFunction &CGF, SourceLocation Loc, ReductionCodeGen &RCG, unsigned N)
Required to resolve existing problems in the runtime.
virtual void emitFlush(CodeGenFunction &CGF, ArrayRef< const Expr *> Vars, SourceLocation Loc)
Emit flush of the variables specified in &#39;omp flush&#39; directive.
OffloadEntryInfo(OffloadingEntryInfoKinds Kind, unsigned Order, uint32_t Flags)
RegionCodeGenTy(Callable &&CodeGen, typename std::enable_if< !std::is_same< typename std::remove_reference< Callable >::type, RegionCodeGenTy >::value >::type *=nullptr)
This represents one expression.
Definition: Expr.h:106
virtual llvm::Value * emitParallelOutlinedFunction(const OMPExecutableDirective &D, const VarDecl *ThreadIDVar, OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen)
Emits outlined function for the specified OpenMP parallel directive D.
void loadOffloadInfoMetadata()
Loads all the offload entries information from the host IR metadata.
void emitKmpRoutineEntryT(QualType KmpInt32Ty)
Build type kmp_routine_entry_t (if not built yet).
virtual const VarDecl * translateParameter(const FieldDecl *FD, const VarDecl *NativeParam) const
Translates the native parameter of outlined function if this is required for target.
QualType SavedKmpTaskloopTQTy
Saved kmp_task_t for taskloop-based directive.
virtual ~CGOpenMPRuntime()
virtual bool isStaticNonchunked(OpenMPDistScheduleClauseKind ScheduleKind, bool Chunked) const
Check if the specified ScheduleKind is static non-chunked.
CGOpenMPRuntime(CodeGenModule &CGM)
void clearArrayInfo()
Clear information about the data arrays.
SmallVector< const Expr *, 4 > FirstprivateVars
virtual Address getAddrOfThreadPrivate(CodeGenFunction &CGF, const VarDecl *VD, Address VDAddr, SourceLocation Loc)
Returns address of the threadprivate variable for the current thread.
virtual bool isStaticChunked(OpenMPDistScheduleClauseKind ScheduleKind, bool Chunked) const
Check if the specified ScheduleKind is static non-chunked.
*QualType KmpTaskTQTy
OpenMPProcBindClauseKind
OpenMP attributes for &#39;proc_bind&#39; clause.
Definition: OpenMPKinds.h:51
llvm::Constant * createDispatchInitFunction(unsigned IVSize, bool IVSigned)
Returns __kmpc_dispatch_init_* runtime function for the specified size IVSize and sign IVSigned...
virtual void emitCriticalRegion(CodeGenFunction &CGF, StringRef CriticalName, const RegionCodeGenTy &CriticalOpGen, SourceLocation Loc, const Expr *Hint=nullptr)
Emits a critical region.
GlobalDecl - represents a global declaration.
Definition: GlobalDecl.h:35
virtual bool emitTargetGlobalVariable(GlobalDecl GD)
Emit the global variable if it is a valid device global variable.
QualType KmpDependInfoTy
Type typedef struct kmp_depend_info { kmp_intptr_t base_addr; size_t len; struct { bool in:1; bool ou...
QualType TgtBinaryDescriptorQTy
struct __tgt_bin_desc{ int32_t NumDevices; // Number of devices supported.
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...
Kind
Encodes a location in the source.
This represents &#39;#pragma omp declare reduction ...&#39; directive.
Definition: DeclOpenMP.h:103
llvm::PointerIntPair< llvm::Value *, 1, bool > Final
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 void emitNumTeamsClause(CodeGenFunction &CGF, const Expr *NumTeams, const Expr *ThreadLimit, SourceLocation Loc)
Emits call to void __kmpc_push_num_teams(ident_t *loc, kmp_int32 global_tid, kmp_int32 num_teams...
This is a basic class for representing single OpenMP executable directive.
Definition: StmtOpenMP.h:33
virtual void emitCancellationPointCall(CodeGenFunction &CGF, SourceLocation Loc, OpenMPDirectiveKind CancelRegion)
Emit code for &#39;cancellation point&#39; construct.
OpenMPDirectiveKind
OpenMP directives.
Definition: OpenMPKinds.h:23
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 llvm::Value * 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.
unsigned size() const
Return number of entries defined so far.
virtual void Enter(CodeGenFunction &CGF)
An aligned address.
Definition: Address.h:25
virtual void emitParallelCall(CodeGenFunction &CGF, SourceLocation Loc, llvm::Value *OutlinedFn, ArrayRef< llvm::Value *> CapturedVars, const Expr *IfCond)
Emits code for parallel or serial call of the OutlinedFn with variables captured in a record which ad...
bool hasDeviceGlobalVarEntryInfo(StringRef VarName) const
Checks if the variable with the given name has been registered already.
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 emitProcBindClause(CodeGenFunction &CGF, OpenMPProcBindClauseKind ProcBind, SourceLocation Loc)
Emit call to void __kmpc_push_proc_bind(ident_t *loc, kmp_int32 global_tid, int proc_bind) to generat...
virtual void emitTaskyieldCall(CodeGenFunction &CGF, SourceLocation Loc)
Emits code for a taskyield directive.
OffloadEntryInfoDeviceGlobalVar(unsigned Order, llvm::Constant *Addr, CharUnits VarSize, OMPTargetGlobalVarEntryKind Flags, llvm::GlobalValue::LinkageTypes Linkage)
virtual void functionFinished(CodeGenFunction &CGF)
Cleans up references to the objects in finished function.
const Expr * getRefExpr(unsigned N) const
Returns the base declaration of the reduction item.
Struct with the values to be passed to the static runtime function.
i32 captured_struct **param SharedsTy A type which contains references the shared variables *param Shareds Context with the list of shared variables from the p *TaskFunction *param Data Additional data for task generation like final list of privates etc *TaskResultTy emitTaskInit(CodeGenFunction &CGF, SourceLocation Loc, const OMPExecutableDirective &D, llvm::Value *TaskFunction, QualType SharedsTy, Address Shareds, const OMPTaskDataTy &Data)
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
void setAction(PrePostActionTy &Action) const
This class organizes the cross-function state that is used while generating LLVM code.
Optional< types::ID > Type
Dataflow Directional Tag Classes.
Class provides a way to call simple version of codegen for OpenMP region, or an advanced with possibl...
OffloadEntryInfoTargetRegion(unsigned Order, llvm::Constant *Addr, llvm::Constant *ID, OMPTargetRegionEntryKind Flags)
virtual bool emitTargetGlobal(GlobalDecl GD)
Emit the global GD if it is meaningful for the target.
virtual void emitCancelCall(CodeGenFunction &CGF, SourceLocation Loc, const Expr *IfCond, OpenMPDirectiveKind CancelRegion)
Emit code for &#39;cancel&#39; construct.
A basic class for pre|post-action for advanced codegen sequence for OpenMP region.
LValue getSharedLValue(unsigned N) const
Returns LValue for the reduction item.
i32 captured_struct **param SharedsTy A type which contains references the shared variables *param Shareds Context with the list of shared variables from the p *TaskFunction *param IfCond Not a nullptr if if clause was nullptr *otherwise *param Data Additional data for task generation like final list of privates etc *virtual void emitTaskLoopCall(CodeGenFunction &CGF, SourceLocation Loc, const OMPLoopDirective &D, llvm::Value *TaskFunction, QualType SharedsTy, Address Shareds, const Expr *IfCond, const OMPTaskDataTy &Data)
llvm::Function * createOffloadingBinaryDescriptorRegistration()
Creates and registers offloading binary descriptor for the current compilation unit.
llvm::PointerIntPair< llvm::Value *, 1, bool > Priority
virtual void emitTargetOutlinedFunction(const OMPExecutableDirective &D, StringRef ParentName, llvm::Function *&OutlinedFn, llvm::Constant *&OutlinedFnID, bool IsOffloadEntry, const RegionCodeGenTy &CodeGen)
Emit outilined function for &#39;target&#39; directive.
OffloadEntriesInfoManagerTy OffloadEntriesInfoManager
CGOpenMPSIMDRuntime(CodeGenModule &CGM)
virtual bool emitDeclareTargetVarDefinition(const VarDecl *VD, llvm::GlobalVariable *Addr, bool PerformInit)
Emit a code for initialization of declare target variable.
virtual void emitDistributeStaticInit(CodeGenFunction &CGF, SourceLocation Loc, OpenMPDistScheduleClauseKind SchedKind, const StaticRTInput &Values)
virtual StringRef getOutlinedHelperName() const
Get the function name of an outlined region.
virtual void emitOrderedRegion(CodeGenFunction &CGF, const RegionCodeGenTy &OrderedOpGen, SourceLocation Loc, bool IsThreads)
Emit an ordered region.
StaticRTInput(unsigned IVSize, bool IVSigned, bool Ordered, Address IL, Address LB, Address UB, Address ST, llvm::Value *Chunk=nullptr)
virtual void emitInlinedDirective(CodeGenFunction &CGF, OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen, bool HasCancel=false)
Emit code for the directive that does not require outlining.
OpenMPScheduleClauseKind
OpenMP attributes for &#39;schedule&#39; clause.
Definition: OpenMPKinds.h:59
Entity that registers the offloading constants that were emitted so far.
llvm::function_ref< void(StringRef, const OffloadEntryInfoDeviceGlobalVar &)> OffloadDeviceGlobalVarEntryInfoActTy
Applies action Action on all registered entries.
llvm::Constant * createDispatchNextFunction(unsigned IVSize, bool IVSigned)
Returns __kmpc_dispatch_next_* runtime function for the specified size IVSize and sign IVSigned...
virtual void emitTaskgroupRegion(CodeGenFunction &CGF, const RegionCodeGenTy &TaskgroupOpGen, SourceLocation Loc)
Emit a taskgroup region.
virtual llvm::Function * emitRegistrationFunction()
Creates the offloading descriptor in the event any target region was emitted in the current module an...
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 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.
Defines the clang::SourceLocation class and associated facilities.
llvm::PointerIntPair< llvm::Value *, 1, bool > Schedule
Privates[]
Gets the list of initial values for linear variables.
Definition: OpenMPClause.h:151
virtual void emitBarrierCall(CodeGenFunction &CGF, SourceLocation Loc, OpenMPDirectiveKind Kind, bool EmitChecks=true, bool ForceSimpleCall=false)
Emit an implicit/explicit barrier for OpenMP threads.
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.
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:1036
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.
QualType KmpDimTy
struct kmp_dim { // loop bounds info casted to kmp_int64 kmp_int64 lo; // lower kmp_int64 up; // uppe...
LValue - This represents an lvalue references.
Definition: CGValue.h:167
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.
QualType SavedKmpTaskTQTy
Saved kmp_task_t for task directive.
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 getDefaultScheduleAndChunk(CodeGenFunction &CGF, const OMPLoopDirective &S, OpenMPScheduleClauseKind &ScheduleKind, const Expr *&ChunkExpr) const
Choose default schedule type and chunk value for the schedule clause.
llvm::Constant * createRuntimeFunction(unsigned Function)
Returns specified OpenMP runtime function.
llvm::StringSet DeclareTargetWithDefinition
Set of declare target variables with the generated initializer.
virtual void emitNumThreadsClause(CodeGenFunction &CGF, llvm::Value *NumThreads, SourceLocation Loc)
Emits call to void __kmpc_push_num_threads(ident_t *loc, kmp_int32 global_tid, kmp_int32 num_threads)...
SmallVector< const Expr *, 4 > FirstprivateInits
llvm::Constant * getOrCreateThreadPrivateCache(const VarDecl *VD)
If the specified mangled name is not in the module, create and return threadprivate cache object...
virtual void emitTaskwaitCall(CodeGenFunction &CGF, SourceLocation Loc)
Emit code for &#39;taskwait&#39; directive.