clang  10.0.0svn
CGOpenMPRuntime.h
Go to the documentation of this file.
1 //===----- CGOpenMPRuntime.h - Interface to OpenMP Runtimes -----*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This provides a class for OpenMP runtime code generation.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_CLANG_LIB_CODEGEN_CGOPENMPRUNTIME_H
14 #define LLVM_CLANG_LIB_CODEGEN_CGOPENMPRUNTIME_H
15 
16 #include "CGValue.h"
17 #include "clang/AST/DeclOpenMP.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,
275  llvm::FunctionCallee Callee,
276  ArrayRef<llvm::Value *> Args = llvm::None) const;
277 
278  /// Emits address of the word in a memory where current thread id is
279  /// stored.
280  virtual Address emitThreadIDAddress(CodeGenFunction &CGF, SourceLocation Loc);
281 
282  void setLocThreadIdInsertPt(CodeGenFunction &CGF,
283  bool AtCurrentPoint = false);
284  void clearLocThreadIdInsertPt(CodeGenFunction &CGF);
285 
286  /// Check if the default location must be constant.
287  /// Default is false to support OMPT/OMPD.
288  virtual bool isDefaultLocationConstant() const { return false; }
289 
290  /// Returns additional flags that can be stored in reserved_2 field of the
291  /// default location.
292  virtual unsigned getDefaultLocationReserved2Flags() const { return 0; }
293 
294  /// Returns default flags for the barriers depending on the directive, for
295  /// which this barier is going to be emitted.
296  static unsigned getDefaultFlagsForBarriers(OpenMPDirectiveKind Kind);
297 
298  /// Get the LLVM type for the critical name.
299  llvm::ArrayType *getKmpCriticalNameTy() const {return KmpCriticalNameTy;}
300 
301  /// Returns corresponding lock object for the specified critical region
302  /// name. If the lock object does not exist it is created, otherwise the
303  /// reference to the existing copy is returned.
304  /// \param CriticalName Name of the critical region.
305  ///
306  llvm::Value *getCriticalRegionLock(StringRef CriticalName);
307 
308 private:
309  /// Default const ident_t object used for initialization of all other
310  /// ident_t objects.
311  llvm::Constant *DefaultOpenMPPSource = nullptr;
312  using FlagsTy = std::pair<unsigned, unsigned>;
313  /// Map of flags and corresponding default locations.
314  using OpenMPDefaultLocMapTy = llvm::DenseMap<FlagsTy, llvm::Value *>;
315  OpenMPDefaultLocMapTy OpenMPDefaultLocMap;
316  Address getOrCreateDefaultLocation(unsigned Flags);
317 
318  QualType IdentQTy;
319  llvm::StructType *IdentTy = nullptr;
320  /// Map for SourceLocation and OpenMP runtime library debug locations.
321  typedef llvm::DenseMap<unsigned, llvm::Value *> OpenMPDebugLocMapTy;
322  OpenMPDebugLocMapTy OpenMPDebugLocMap;
323  /// The type for a microtask which gets passed to __kmpc_fork_call().
324  /// Original representation is:
325  /// typedef void (kmpc_micro)(kmp_int32 global_tid, kmp_int32 bound_tid,...);
326  llvm::FunctionType *Kmpc_MicroTy = nullptr;
327  /// Stores debug location and ThreadID for the function.
328  struct DebugLocThreadIdTy {
329  llvm::Value *DebugLoc;
330  llvm::Value *ThreadID;
331  /// Insert point for the service instructions.
332  llvm::AssertingVH<llvm::Instruction> ServiceInsertPt = nullptr;
333  };
334  /// Map of local debug location, ThreadId and functions.
335  typedef llvm::DenseMap<llvm::Function *, DebugLocThreadIdTy>
336  OpenMPLocThreadIDMapTy;
337  OpenMPLocThreadIDMapTy OpenMPLocThreadIDMap;
338  /// Map of UDRs and corresponding combiner/initializer.
339  typedef llvm::DenseMap<const OMPDeclareReductionDecl *,
340  std::pair<llvm::Function *, llvm::Function *>>
341  UDRMapTy;
342  UDRMapTy UDRMap;
343  /// Map of functions and locally defined UDRs.
344  typedef llvm::DenseMap<llvm::Function *,
346  FunctionUDRMapTy;
347  FunctionUDRMapTy FunctionUDRMap;
348  /// Map from the user-defined mapper declaration to its corresponding
349  /// functions.
350  llvm::DenseMap<const OMPDeclareMapperDecl *, llvm::Function *> UDMMap;
351  /// Map of functions and their local user-defined mappers.
352  using FunctionUDMMapTy =
353  llvm::DenseMap<llvm::Function *,
355  FunctionUDMMapTy FunctionUDMMap;
356  /// Type kmp_critical_name, originally defined as typedef kmp_int32
357  /// kmp_critical_name[8];
358  llvm::ArrayType *KmpCriticalNameTy;
359  /// An ordered map of auto-generated variables to their unique names.
360  /// It stores variables with the following names: 1) ".gomp_critical_user_" +
361  /// <critical_section_name> + ".var" for "omp critical" directives; 2)
362  /// <mangled_name_for_global_var> + ".cache." for cache for threadprivate
363  /// variables.
364  llvm::StringMap<llvm::AssertingVH<llvm::Constant>, llvm::BumpPtrAllocator>
365  InternalVars;
366  /// Type typedef kmp_int32 (* kmp_routine_entry_t)(kmp_int32, void *);
367  llvm::Type *KmpRoutineEntryPtrTy = nullptr;
368  QualType KmpRoutineEntryPtrQTy;
369  /// Type typedef struct kmp_task {
370  /// void * shareds; /**< pointer to block of pointers to
371  /// shared vars */
372  /// kmp_routine_entry_t routine; /**< pointer to routine to call for
373  /// executing task */
374  /// kmp_int32 part_id; /**< part id for the task */
375  /// kmp_routine_entry_t destructors; /* pointer to function to invoke
376  /// deconstructors of firstprivate C++ objects */
377  /// } kmp_task_t;
379  /// Saved kmp_task_t for task directive.
381  /// Saved kmp_task_t for taskloop-based directive.
383  /// Type typedef struct kmp_depend_info {
384  /// kmp_intptr_t base_addr;
385  /// size_t len;
386  /// struct {
387  /// bool in:1;
388  /// bool out:1;
389  /// } flags;
390  /// } kmp_depend_info_t;
392  /// struct kmp_dim { // loop bounds info casted to kmp_int64
393  /// kmp_int64 lo; // lower
394  /// kmp_int64 up; // upper
395  /// kmp_int64 st; // stride
396  /// };
398  /// Type struct __tgt_offload_entry{
399  /// void *addr; // Pointer to the offload entry info.
400  /// // (function or global)
401  /// char *name; // Name of the function or global.
402  /// size_t size; // Size of the entry info (0 if it a function).
403  /// };
405  /// struct __tgt_device_image{
406  /// void *ImageStart; // Pointer to the target code start.
407  /// void *ImageEnd; // Pointer to the target code end.
408  /// // We also add the host entries to the device image, as it may be useful
409  /// // for the target runtime to have access to that information.
410  /// __tgt_offload_entry *EntriesBegin; // Begin of the table with all
411  /// // the entries.
412  /// __tgt_offload_entry *EntriesEnd; // End of the table with all the
413  /// // entries (non inclusive).
414  /// };
416  /// struct __tgt_bin_desc{
417  /// int32_t NumDevices; // Number of devices supported.
418  /// __tgt_device_image *DeviceImages; // Arrays of device images
419  /// // (one per device).
420  /// __tgt_offload_entry *EntriesBegin; // Begin of the table with all the
421  /// // entries.
422  /// __tgt_offload_entry *EntriesEnd; // End of the table with all the
423  /// // entries (non inclusive).
424  /// };
426  /// Entity that registers the offloading constants that were emitted so
427  /// far.
429  CodeGenModule &CGM;
430 
431  /// Number of entries registered so far.
432  unsigned OffloadingEntriesNum = 0;
433 
434  public:
435  /// Base class of the entries info.
437  public:
438  /// Kind of a given entry.
439  enum OffloadingEntryInfoKinds : unsigned {
440  /// Entry is a target region.
441  OffloadingEntryInfoTargetRegion = 0,
442  /// Entry is a declare target variable.
443  OffloadingEntryInfoDeviceGlobalVar = 1,
444  /// Invalid entry info.
445  OffloadingEntryInfoInvalid = ~0u
446  };
447 
448  protected:
449  OffloadEntryInfo() = delete;
450  explicit OffloadEntryInfo(OffloadingEntryInfoKinds Kind) : Kind(Kind) {}
451  explicit OffloadEntryInfo(OffloadingEntryInfoKinds Kind, unsigned Order,
452  uint32_t Flags)
453  : Flags(Flags), Order(Order), Kind(Kind) {}
454  ~OffloadEntryInfo() = default;
455 
456  public:
457  bool isValid() const { return Order != ~0u; }
458  unsigned getOrder() const { return Order; }
460  uint32_t getFlags() const { return Flags; }
461  void setFlags(uint32_t NewFlags) { Flags = NewFlags; }
462  llvm::Constant *getAddress() const {
463  return cast_or_null<llvm::Constant>(Addr);
464  }
465  void setAddress(llvm::Constant *V) {
466  assert(!Addr.pointsToAliveValue() && "Address has been set before!");
467  Addr = V;
468  }
469  static bool classof(const OffloadEntryInfo *Info) { return true; }
470 
471  private:
472  /// Address of the entity that has to be mapped for offloading.
473  llvm::WeakTrackingVH Addr;
474 
475  /// Flags associated with the device global.
476  uint32_t Flags = 0u;
477 
478  /// Order this entry was emitted.
479  unsigned Order = ~0u;
480 
481  OffloadingEntryInfoKinds Kind = OffloadingEntryInfoInvalid;
482  };
483 
484  /// Return true if a there are no entries defined.
485  bool empty() const;
486  /// Return number of entries defined so far.
487  unsigned size() const { return OffloadingEntriesNum; }
489 
490  //
491  // Target region entries related.
492  //
493 
494  /// Kind of the target registry entry.
495  enum OMPTargetRegionEntryKind : uint32_t {
496  /// Mark the entry as target region.
497  OMPTargetRegionEntryTargetRegion = 0x0,
498  /// Mark the entry as a global constructor.
499  OMPTargetRegionEntryCtor = 0x02,
500  /// Mark the entry as a global destructor.
501  OMPTargetRegionEntryDtor = 0x04,
502  };
503 
504  /// Target region entries info.
506  /// Address that can be used as the ID of the entry.
507  llvm::Constant *ID = nullptr;
508 
509  public:
511  : OffloadEntryInfo(OffloadingEntryInfoTargetRegion) {}
512  explicit OffloadEntryInfoTargetRegion(unsigned Order,
513  llvm::Constant *Addr,
514  llvm::Constant *ID,
516  : OffloadEntryInfo(OffloadingEntryInfoTargetRegion, Order, Flags),
517  ID(ID) {
518  setAddress(Addr);
519  }
520 
521  llvm::Constant *getID() const { return ID; }
522  void setID(llvm::Constant *V) {
523  assert(!ID && "ID has been set before!");
524  ID = V;
525  }
526  static bool classof(const OffloadEntryInfo *Info) {
527  return Info->getKind() == OffloadingEntryInfoTargetRegion;
528  }
529  };
530 
531  /// Initialize target region entry.
532  void initializeTargetRegionEntryInfo(unsigned DeviceID, unsigned FileID,
533  StringRef ParentName, unsigned LineNum,
534  unsigned Order);
535  /// Register target region entry.
536  void registerTargetRegionEntryInfo(unsigned DeviceID, unsigned FileID,
537  StringRef ParentName, unsigned LineNum,
538  llvm::Constant *Addr, llvm::Constant *ID,
540  /// Return true if a target region entry with the provided information
541  /// exists.
542  bool hasTargetRegionEntryInfo(unsigned DeviceID, unsigned FileID,
543  StringRef ParentName, unsigned LineNum) const;
544  /// brief Applies action \a Action on all registered entries.
545  typedef llvm::function_ref<void(unsigned, unsigned, StringRef, unsigned,
548  void actOnTargetRegionEntriesInfo(
549  const OffloadTargetRegionEntryInfoActTy &Action);
550 
551  //
552  // Device global variable entries related.
553  //
554 
555  /// Kind of the global variable entry..
556  enum OMPTargetGlobalVarEntryKind : uint32_t {
557  /// Mark the entry as a to declare target.
558  OMPTargetGlobalVarEntryTo = 0x0,
559  /// Mark the entry as a to declare target link.
560  OMPTargetGlobalVarEntryLink = 0x1,
561  };
562 
563  /// Device global variable entries info.
565  /// Type of the global variable.
566  CharUnits VarSize;
567  llvm::GlobalValue::LinkageTypes Linkage;
568 
569  public:
571  : OffloadEntryInfo(OffloadingEntryInfoDeviceGlobalVar) {}
572  explicit OffloadEntryInfoDeviceGlobalVar(unsigned Order,
574  : OffloadEntryInfo(OffloadingEntryInfoDeviceGlobalVar, Order, Flags) {}
576  unsigned Order, llvm::Constant *Addr, CharUnits VarSize,
578  llvm::GlobalValue::LinkageTypes Linkage)
579  : OffloadEntryInfo(OffloadingEntryInfoDeviceGlobalVar, Order, Flags),
580  VarSize(VarSize), Linkage(Linkage) {
581  setAddress(Addr);
582  }
583 
584  CharUnits getVarSize() const { return VarSize; }
585  void setVarSize(CharUnits Size) { VarSize = Size; }
586  llvm::GlobalValue::LinkageTypes getLinkage() const { return Linkage; }
587  void setLinkage(llvm::GlobalValue::LinkageTypes LT) { Linkage = LT; }
588  static bool classof(const OffloadEntryInfo *Info) {
589  return Info->getKind() == OffloadingEntryInfoDeviceGlobalVar;
590  }
591  };
592 
593  /// Initialize device global variable entry.
594  void initializeDeviceGlobalVarEntryInfo(StringRef Name,
596  unsigned Order);
597 
598  /// Register device global variable entry.
599  void
600  registerDeviceGlobalVarEntryInfo(StringRef VarName, llvm::Constant *Addr,
601  CharUnits VarSize,
603  llvm::GlobalValue::LinkageTypes Linkage);
604  /// Checks if the variable with the given name has been registered already.
605  bool hasDeviceGlobalVarEntryInfo(StringRef VarName) const {
606  return OffloadEntriesDeviceGlobalVar.count(VarName) > 0;
607  }
608  /// Applies action \a Action on all registered entries.
609  typedef llvm::function_ref<void(StringRef,
612  void actOnDeviceGlobalVarEntriesInfo(
614 
615  private:
616  // Storage for target region entries kind. The storage is to be indexed by
617  // file ID, device ID, parent function name and line number.
618  typedef llvm::DenseMap<unsigned, OffloadEntryInfoTargetRegion>
619  OffloadEntriesTargetRegionPerLine;
620  typedef llvm::StringMap<OffloadEntriesTargetRegionPerLine>
621  OffloadEntriesTargetRegionPerParentName;
622  typedef llvm::DenseMap<unsigned, OffloadEntriesTargetRegionPerParentName>
623  OffloadEntriesTargetRegionPerFile;
624  typedef llvm::DenseMap<unsigned, OffloadEntriesTargetRegionPerFile>
625  OffloadEntriesTargetRegionPerDevice;
626  typedef OffloadEntriesTargetRegionPerDevice OffloadEntriesTargetRegionTy;
627  OffloadEntriesTargetRegionTy OffloadEntriesTargetRegion;
628  /// Storage for device global variable entries kind. The storage is to be
629  /// indexed by mangled name.
630  typedef llvm::StringMap<OffloadEntryInfoDeviceGlobalVar>
631  OffloadEntriesDeviceGlobalVarTy;
632  OffloadEntriesDeviceGlobalVarTy OffloadEntriesDeviceGlobalVar;
633  };
635 
636  bool ShouldMarkAsGlobal = true;
637  /// List of the emitted functions.
638  llvm::StringSet<> AlreadyEmittedTargetFunctions;
639  /// List of the global variables with their addresses that should not be
640  /// emitted for the target.
641  llvm::StringMap<llvm::WeakTrackingVH> EmittedNonTargetVariables;
642 
643  /// List of variables that can become declare target implicitly and, thus,
644  /// must be emitted.
645  llvm::SmallDenseSet<const VarDecl *> DeferredGlobalVariables;
646 
647  /// Flag for keeping track of weather a requires unified_shared_memory
648  /// directive is present.
650 
651  /// Flag for keeping track of weather a target region has been emitted.
653 
654  /// Flag for keeping track of weather a device routine has been emitted.
655  /// Device routines are specific to the
657 
658  /// Creates and registers offloading binary descriptor for the current
659  /// compilation unit. The function that does the registration is returned.
661 
662  /// Creates all the offload entries in the current compilation unit
663  /// along with the associated metadata.
665 
666  /// Loads all the offload entries information from the host IR
667  /// metadata.
669 
670  /// Returns __tgt_offload_entry type.
672 
673  /// Returns __tgt_device_image type.
675 
676  /// Returns __tgt_bin_desc type.
678 
679  /// Start scanning from statement \a S and and emit all target regions
680  /// found along the way.
681  /// \param S Starting statement.
682  /// \param ParentName Name of the function declaration that is being scanned.
683  void scanForTargetRegionsFunctions(const Stmt *S, StringRef ParentName);
684 
685  /// Build type kmp_routine_entry_t (if not built yet).
686  void emitKmpRoutineEntryT(QualType KmpInt32Ty);
687 
688  /// Returns pointer to kmpc_micro type.
689  llvm::Type *getKmpc_MicroPointerTy();
690 
691  /// Returns specified OpenMP runtime function.
692  /// \param Function OpenMP runtime function.
693  /// \return Specified function.
694  llvm::FunctionCallee createRuntimeFunction(unsigned Function);
695 
696  /// Returns __kmpc_for_static_init_* runtime function for the specified
697  /// size \a IVSize and sign \a IVSigned.
698  llvm::FunctionCallee createForStaticInitFunction(unsigned IVSize,
699  bool IVSigned);
700 
701  /// Returns __kmpc_dispatch_init_* runtime function for the specified
702  /// size \a IVSize and sign \a IVSigned.
703  llvm::FunctionCallee createDispatchInitFunction(unsigned IVSize,
704  bool IVSigned);
705 
706  /// Returns __kmpc_dispatch_next_* runtime function for the specified
707  /// size \a IVSize and sign \a IVSigned.
708  llvm::FunctionCallee createDispatchNextFunction(unsigned IVSize,
709  bool IVSigned);
710 
711  /// Returns __kmpc_dispatch_fini_* runtime function for the specified
712  /// size \a IVSize and sign \a IVSigned.
713  llvm::FunctionCallee createDispatchFiniFunction(unsigned IVSize,
714  bool IVSigned);
715 
716  /// If the specified mangled name is not in the module, create and
717  /// return threadprivate cache object. This object is a pointer's worth of
718  /// storage that's reserved for use by the OpenMP runtime.
719  /// \param VD Threadprivate variable.
720  /// \return Cache variable for the specified threadprivate.
721  llvm::Constant *getOrCreateThreadPrivateCache(const VarDecl *VD);
722 
723  /// Gets (if variable with the given name already exist) or creates
724  /// internal global variable with the specified Name. The created variable has
725  /// linkage CommonLinkage by default and is initialized by null value.
726  /// \param Ty Type of the global variable. If it is exist already the type
727  /// must be the same.
728  /// \param Name Name of the variable.
729  llvm::Constant *getOrCreateInternalVariable(llvm::Type *Ty,
730  const llvm::Twine &Name,
731  unsigned AddressSpace = 0);
732 
733  /// Set of threadprivate variables with the generated initializer.
734  llvm::StringSet<> ThreadPrivateWithDefinition;
735 
736  /// Set of declare target variables with the generated initializer.
737  llvm::StringSet<> DeclareTargetWithDefinition;
738 
739  /// Emits initialization code for the threadprivate variables.
740  /// \param VDAddr Address of the global variable \a VD.
741  /// \param Ctor Pointer to a global init function for \a VD.
742  /// \param CopyCtor Pointer to a global copy function for \a VD.
743  /// \param Dtor Pointer to a global destructor function for \a VD.
744  /// \param Loc Location of threadprivate declaration.
746  llvm::Value *Ctor, llvm::Value *CopyCtor,
747  llvm::Value *Dtor, SourceLocation Loc);
748 
749  /// Emit the array initialization or deletion portion for user-defined mapper
750  /// code generation.
752  llvm::Value *Handle, llvm::Value *BasePtr,
753  llvm::Value *Ptr, llvm::Value *Size,
754  llvm::Value *MapType, CharUnits ElementSize,
755  llvm::BasicBlock *ExitBB, bool IsInit);
756 
757  struct TaskResultTy {
758  llvm::Value *NewTask = nullptr;
759  llvm::Function *TaskEntry = nullptr;
760  llvm::Value *NewTaskNewTaskTTy = nullptr;
762  const RecordDecl *KmpTaskTQTyRD = nullptr;
763  llvm::Value *TaskDupFn = nullptr;
764  };
765  /// Emit task region for the task directive. The task region is emitted in
766  /// several steps:
767  /// 1. Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32
768  /// gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds,
769  /// kmp_routine_entry_t *task_entry). Here task_entry is a pointer to the
770  /// function:
771  /// kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) {
772  /// TaskFunction(gtid, tt->part_id, tt->shareds);
773  /// return 0;
774  /// }
775  /// 2. Copy a list of shared variables to field shareds of the resulting
776  /// structure kmp_task_t returned by the previous call (if any).
777  /// 3. Copy a pointer to destructions function to field destructions of the
778  /// resulting structure kmp_task_t.
779  /// \param D Current task directive.
780  /// \param TaskFunction An LLVM function with type void (*)(i32 /*gtid*/, i32
781  /// /*part_id*/, captured_struct */*__context*/);
782  /// \param SharedsTy A type which contains references the shared variables.
783  /// \param Shareds Context with the list of shared variables from the \p
784  /// TaskFunction.
785  /// \param Data Additional data for task generation like tiednsee, final
786  /// state, list of privates etc.
788  const OMPExecutableDirective &D,
789  llvm::Function *TaskFunction, QualType SharedsTy,
790  Address Shareds, const OMPTaskDataTy &Data);
791 
792  /// Returns default address space for the constant firstprivates, 0 by
793  /// default.
794  virtual unsigned getDefaultFirstprivateAddressSpace() const { return 0; }
795 
796 public:
798  : CGOpenMPRuntime(CGM, ".", ".") {}
799  virtual ~CGOpenMPRuntime() {}
800  virtual void clear();
801 
802  /// Checks if the \p Body is the \a CompoundStmt and returns its child
803  /// statement iff there is only one that is not evaluatable at the compile
804  /// time.
805  static const Stmt *getSingleCompoundChild(ASTContext &Ctx, const Stmt *Body);
806 
807  /// Get the platform-specific name separator.
808  std::string getName(ArrayRef<StringRef> Parts) const;
809 
810  /// Emit code for the specified user defined reduction construct.
811  virtual void emitUserDefinedReduction(CodeGenFunction *CGF,
812  const OMPDeclareReductionDecl *D);
813  /// Get combiner/initializer for the specified user-defined reduction, if any.
814  virtual std::pair<llvm::Function *, llvm::Function *>
815  getUserDefinedReduction(const OMPDeclareReductionDecl *D);
816 
817  /// Emit the function for the user defined mapper construct.
819  CodeGenFunction *CGF = nullptr);
820 
821  /// Emits outlined function for the specified OpenMP parallel directive
822  /// \a D. This outlined function has type void(*)(kmp_int32 *ThreadID,
823  /// kmp_int32 BoundID, struct context_vars*).
824  /// \param D OpenMP directive.
825  /// \param ThreadIDVar Variable for thread id in the current OpenMP region.
826  /// \param InnermostKind Kind of innermost directive (for simple directives it
827  /// is a directive itself, for combined - its innermost directive).
828  /// \param CodeGen Code generation sequence for the \a D directive.
829  virtual llvm::Function *emitParallelOutlinedFunction(
830  const OMPExecutableDirective &D, const VarDecl *ThreadIDVar,
831  OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen);
832 
833  /// Emits outlined function for the specified OpenMP teams directive
834  /// \a D. This outlined function has type void(*)(kmp_int32 *ThreadID,
835  /// kmp_int32 BoundID, struct context_vars*).
836  /// \param D OpenMP directive.
837  /// \param ThreadIDVar Variable for thread id in the current OpenMP region.
838  /// \param InnermostKind Kind of innermost directive (for simple directives it
839  /// is a directive itself, for combined - its innermost directive).
840  /// \param CodeGen Code generation sequence for the \a D directive.
841  virtual llvm::Function *emitTeamsOutlinedFunction(
842  const OMPExecutableDirective &D, const VarDecl *ThreadIDVar,
843  OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen);
844 
845  /// Emits outlined function for the OpenMP task directive \a D. This
846  /// outlined function has type void(*)(kmp_int32 ThreadID, struct task_t*
847  /// TaskT).
848  /// \param D OpenMP directive.
849  /// \param ThreadIDVar Variable for thread id in the current OpenMP region.
850  /// \param PartIDVar Variable for partition id in the current OpenMP untied
851  /// task region.
852  /// \param TaskTVar Variable for task_t argument.
853  /// \param InnermostKind Kind of innermost directive (for simple directives it
854  /// is a directive itself, for combined - its innermost directive).
855  /// \param CodeGen Code generation sequence for the \a D directive.
856  /// \param Tied true if task is generated for tied task, false otherwise.
857  /// \param NumberOfParts Number of parts in untied task. Ignored for tied
858  /// tasks.
859  ///
860  virtual llvm::Function *emitTaskOutlinedFunction(
861  const OMPExecutableDirective &D, const VarDecl *ThreadIDVar,
862  const VarDecl *PartIDVar, const VarDecl *TaskTVar,
863  OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen,
864  bool Tied, unsigned &NumberOfParts);
865 
866  /// Cleans up references to the objects in finished function.
867  ///
868  virtual void functionFinished(CodeGenFunction &CGF);
869 
870  /// Emits code for parallel or serial call of the \a OutlinedFn with
871  /// variables captured in a record which address is stored in \a
872  /// CapturedStruct.
873  /// \param OutlinedFn Outlined function to be run in parallel threads. Type of
874  /// this function is void(*)(kmp_int32 *, kmp_int32, struct context_vars*).
875  /// \param CapturedVars A pointer to the record with the references to
876  /// variables used in \a OutlinedFn function.
877  /// \param IfCond Condition in the associated 'if' clause, if it was
878  /// specified, nullptr otherwise.
879  ///
880  virtual void emitParallelCall(CodeGenFunction &CGF, SourceLocation Loc,
881  llvm::Function *OutlinedFn,
882  ArrayRef<llvm::Value *> CapturedVars,
883  const Expr *IfCond);
884 
885  /// Emits a critical region.
886  /// \param CriticalName Name of the critical region.
887  /// \param CriticalOpGen Generator for the statement associated with the given
888  /// critical region.
889  /// \param Hint Value of the 'hint' clause (optional).
890  virtual void emitCriticalRegion(CodeGenFunction &CGF, StringRef CriticalName,
891  const RegionCodeGenTy &CriticalOpGen,
892  SourceLocation Loc,
893  const Expr *Hint = nullptr);
894 
895  /// Emits a master region.
896  /// \param MasterOpGen Generator for the statement associated with the given
897  /// master region.
898  virtual void emitMasterRegion(CodeGenFunction &CGF,
899  const RegionCodeGenTy &MasterOpGen,
900  SourceLocation Loc);
901 
902  /// Emits code for a taskyield directive.
903  virtual void emitTaskyieldCall(CodeGenFunction &CGF, SourceLocation Loc);
904 
905  /// Emit a taskgroup region.
906  /// \param TaskgroupOpGen Generator for the statement associated with the
907  /// given taskgroup region.
908  virtual void emitTaskgroupRegion(CodeGenFunction &CGF,
909  const RegionCodeGenTy &TaskgroupOpGen,
910  SourceLocation Loc);
911 
912  /// Emits a single region.
913  /// \param SingleOpGen Generator for the statement associated with the given
914  /// single region.
915  virtual void emitSingleRegion(CodeGenFunction &CGF,
916  const RegionCodeGenTy &SingleOpGen,
917  SourceLocation Loc,
918  ArrayRef<const Expr *> CopyprivateVars,
919  ArrayRef<const Expr *> DestExprs,
920  ArrayRef<const Expr *> SrcExprs,
921  ArrayRef<const Expr *> AssignmentOps);
922 
923  /// Emit an ordered region.
924  /// \param OrderedOpGen Generator for the statement associated with the given
925  /// ordered region.
926  virtual void emitOrderedRegion(CodeGenFunction &CGF,
927  const RegionCodeGenTy &OrderedOpGen,
928  SourceLocation Loc, bool IsThreads);
929 
930  /// Emit an implicit/explicit barrier for OpenMP threads.
931  /// \param Kind Directive for which this implicit barrier call must be
932  /// generated. Must be OMPD_barrier for explicit barrier generation.
933  /// \param EmitChecks true if need to emit checks for cancellation barriers.
934  /// \param ForceSimpleCall true simple barrier call must be emitted, false if
935  /// runtime class decides which one to emit (simple or with cancellation
936  /// checks).
937  ///
938  virtual void emitBarrierCall(CodeGenFunction &CGF, SourceLocation Loc,
939  OpenMPDirectiveKind Kind,
940  bool EmitChecks = true,
941  bool ForceSimpleCall = false);
942 
943  /// Check if the specified \a ScheduleKind is static non-chunked.
944  /// This kind of worksharing directive is emitted without outer loop.
945  /// \param ScheduleKind Schedule kind specified in the 'schedule' clause.
946  /// \param Chunked True if chunk is specified in the clause.
947  ///
948  virtual bool isStaticNonchunked(OpenMPScheduleClauseKind ScheduleKind,
949  bool Chunked) const;
950 
951  /// Check if the specified \a ScheduleKind is static non-chunked.
952  /// This kind of distribute directive is emitted without outer loop.
953  /// \param ScheduleKind Schedule kind specified in the 'dist_schedule' clause.
954  /// \param Chunked True if chunk is specified in the clause.
955  ///
956  virtual bool isStaticNonchunked(OpenMPDistScheduleClauseKind ScheduleKind,
957  bool Chunked) const;
958 
959  /// Check if the specified \a ScheduleKind is static chunked.
960  /// \param ScheduleKind Schedule kind specified in the 'schedule' clause.
961  /// \param Chunked True if chunk is specified in the clause.
962  ///
963  virtual bool isStaticChunked(OpenMPScheduleClauseKind ScheduleKind,
964  bool Chunked) const;
965 
966  /// Check if the specified \a ScheduleKind is static non-chunked.
967  /// \param ScheduleKind Schedule kind specified in the 'dist_schedule' clause.
968  /// \param Chunked True if chunk is specified in the clause.
969  ///
970  virtual bool isStaticChunked(OpenMPDistScheduleClauseKind ScheduleKind,
971  bool Chunked) const;
972 
973  /// Check if the specified \a ScheduleKind is dynamic.
974  /// This kind of worksharing directive is emitted without outer loop.
975  /// \param ScheduleKind Schedule Kind specified in the 'schedule' clause.
976  ///
977  virtual bool isDynamic(OpenMPScheduleClauseKind ScheduleKind) const;
978 
979  /// struct with the values to be passed to the dispatch runtime function
981  /// Loop lower bound
982  llvm::Value *LB = nullptr;
983  /// Loop upper bound
984  llvm::Value *UB = nullptr;
985  /// Chunk size specified using 'schedule' clause (nullptr if chunk
986  /// was not specified)
987  llvm::Value *Chunk = nullptr;
988  DispatchRTInput() = default;
990  : LB(LB), UB(UB), Chunk(Chunk) {}
991  };
992 
993  /// Call the appropriate runtime routine to initialize it before start
994  /// of loop.
995 
996  /// This is used for non static scheduled types and when the ordered
997  /// clause is present on the loop construct.
998  /// Depending on the loop schedule, it is necessary to call some runtime
999  /// routine before start of the OpenMP loop to get the loop upper / lower
1000  /// bounds \a LB and \a UB and stride \a ST.
1001  ///
1002  /// \param CGF Reference to current CodeGenFunction.
1003  /// \param Loc Clang source location.
1004  /// \param ScheduleKind Schedule kind, specified by the 'schedule' clause.
1005  /// \param IVSize Size of the iteration variable in bits.
1006  /// \param IVSigned Sign of the iteration variable.
1007  /// \param Ordered true if loop is ordered, false otherwise.
1008  /// \param DispatchValues struct containing llvm values for lower bound, upper
1009  /// bound, and chunk expression.
1010  /// For the default (nullptr) value, the chunk 1 will be used.
1011  ///
1012  virtual void emitForDispatchInit(CodeGenFunction &CGF, SourceLocation Loc,
1013  const OpenMPScheduleTy &ScheduleKind,
1014  unsigned IVSize, bool IVSigned, bool Ordered,
1015  const DispatchRTInput &DispatchValues);
1016 
1017  /// Struct with the values to be passed to the static runtime function
1018  struct StaticRTInput {
1019  /// Size of the iteration variable in bits.
1020  unsigned IVSize = 0;
1021  /// Sign of the iteration variable.
1022  bool IVSigned = false;
1023  /// true if loop is ordered, false otherwise.
1024  bool Ordered = false;
1025  /// Address of the output variable in which the flag of the last iteration
1026  /// is returned.
1027  Address IL = Address::invalid();
1028  /// Address of the output variable in which the lower iteration number is
1029  /// returned.
1030  Address LB = Address::invalid();
1031  /// Address of the output variable in which the upper iteration number is
1032  /// returned.
1033  Address UB = Address::invalid();
1034  /// Address of the output variable in which the stride value is returned
1035  /// necessary to generated the static_chunked scheduled loop.
1036  Address ST = Address::invalid();
1037  /// Value of the chunk for the static_chunked scheduled loop. For the
1038  /// default (nullptr) value, the chunk 1 will be used.
1039  llvm::Value *Chunk = nullptr;
1040  StaticRTInput(unsigned IVSize, bool IVSigned, bool Ordered, Address IL,
1041  Address LB, Address UB, Address ST,
1042  llvm::Value *Chunk = nullptr)
1043  : IVSize(IVSize), IVSigned(IVSigned), Ordered(Ordered), IL(IL), LB(LB),
1044  UB(UB), ST(ST), Chunk(Chunk) {}
1045  };
1046  /// Call the appropriate runtime routine to initialize it before start
1047  /// of loop.
1048  ///
1049  /// This is used only in case of static schedule, when the user did not
1050  /// specify a ordered clause on the loop construct.
1051  /// Depending on the loop schedule, it is necessary to call some runtime
1052  /// routine before start of the OpenMP loop to get the loop upper / lower
1053  /// bounds LB and UB and stride ST.
1054  ///
1055  /// \param CGF Reference to current CodeGenFunction.
1056  /// \param Loc Clang source location.
1057  /// \param DKind Kind of the directive.
1058  /// \param ScheduleKind Schedule kind, specified by the 'schedule' clause.
1059  /// \param Values Input arguments for the construct.
1060  ///
1061  virtual void emitForStaticInit(CodeGenFunction &CGF, SourceLocation Loc,
1062  OpenMPDirectiveKind DKind,
1063  const OpenMPScheduleTy &ScheduleKind,
1064  const StaticRTInput &Values);
1065 
1066  ///
1067  /// \param CGF Reference to current CodeGenFunction.
1068  /// \param Loc Clang source location.
1069  /// \param SchedKind Schedule kind, specified by the 'dist_schedule' clause.
1070  /// \param Values Input arguments for the construct.
1071  ///
1072  virtual void emitDistributeStaticInit(CodeGenFunction &CGF,
1073  SourceLocation Loc,
1074  OpenMPDistScheduleClauseKind SchedKind,
1075  const StaticRTInput &Values);
1076 
1077  /// Call the appropriate runtime routine to notify that we finished
1078  /// iteration of the ordered loop with the dynamic scheduling.
1079  ///
1080  /// \param CGF Reference to current CodeGenFunction.
1081  /// \param Loc Clang source location.
1082  /// \param IVSize Size of the iteration variable in bits.
1083  /// \param IVSigned Sign of the iteration variable.
1084  ///
1085  virtual void emitForOrderedIterationEnd(CodeGenFunction &CGF,
1086  SourceLocation Loc, unsigned IVSize,
1087  bool IVSigned);
1088 
1089  /// Call the appropriate runtime routine to notify that we finished
1090  /// all the work with current loop.
1091  ///
1092  /// \param CGF Reference to current CodeGenFunction.
1093  /// \param Loc Clang source location.
1094  /// \param DKind Kind of the directive for which the static finish is emitted.
1095  ///
1096  virtual void emitForStaticFinish(CodeGenFunction &CGF, SourceLocation Loc,
1097  OpenMPDirectiveKind DKind);
1098 
1099  /// Call __kmpc_dispatch_next(
1100  /// ident_t *loc, kmp_int32 tid, kmp_int32 *p_lastiter,
1101  /// kmp_int[32|64] *p_lower, kmp_int[32|64] *p_upper,
1102  /// kmp_int[32|64] *p_stride);
1103  /// \param IVSize Size of the iteration variable in bits.
1104  /// \param IVSigned Sign of the iteration variable.
1105  /// \param IL Address of the output variable in which the flag of the
1106  /// last iteration is returned.
1107  /// \param LB Address of the output variable in which the lower iteration
1108  /// number is returned.
1109  /// \param UB Address of the output variable in which the upper iteration
1110  /// number is returned.
1111  /// \param ST Address of the output variable in which the stride value is
1112  /// returned.
1114  unsigned IVSize, bool IVSigned,
1115  Address IL, Address LB,
1116  Address UB, Address ST);
1117 
1118  /// Emits call to void __kmpc_push_num_threads(ident_t *loc, kmp_int32
1119  /// global_tid, kmp_int32 num_threads) to generate code for 'num_threads'
1120  /// clause.
1121  /// \param NumThreads An integer value of threads.
1122  virtual void emitNumThreadsClause(CodeGenFunction &CGF,
1123  llvm::Value *NumThreads,
1124  SourceLocation Loc);
1125 
1126  /// Emit call to void __kmpc_push_proc_bind(ident_t *loc, kmp_int32
1127  /// global_tid, int proc_bind) to generate code for 'proc_bind' clause.
1128  virtual void emitProcBindClause(CodeGenFunction &CGF,
1129  OpenMPProcBindClauseKind ProcBind,
1130  SourceLocation Loc);
1131 
1132  /// Returns address of the threadprivate variable for the current
1133  /// thread.
1134  /// \param VD Threadprivate variable.
1135  /// \param VDAddr Address of the global variable \a VD.
1136  /// \param Loc Location of the reference to threadprivate var.
1137  /// \return Address of the threadprivate variable for the current thread.
1139  const VarDecl *VD,
1140  Address VDAddr,
1141  SourceLocation Loc);
1142 
1143  /// Returns the address of the variable marked as declare target with link
1144  /// clause OR as declare target with to clause and unified memory.
1145  virtual Address getAddrOfDeclareTargetVar(const VarDecl *VD);
1146 
1147  /// Emit a code for initialization of threadprivate variable. It emits
1148  /// a call to runtime library which adds initial value to the newly created
1149  /// threadprivate variable (if it is not constant) and registers destructor
1150  /// for the variable (if any).
1151  /// \param VD Threadprivate variable.
1152  /// \param VDAddr Address of the global variable \a VD.
1153  /// \param Loc Location of threadprivate declaration.
1154  /// \param PerformInit true if initialization expression is not constant.
1155  virtual llvm::Function *
1157  SourceLocation Loc, bool PerformInit,
1158  CodeGenFunction *CGF = nullptr);
1159 
1160  /// Emit a code for initialization of declare target variable.
1161  /// \param VD Declare target variable.
1162  /// \param Addr Address of the global variable \a VD.
1163  /// \param PerformInit true if initialization expression is not constant.
1164  virtual bool emitDeclareTargetVarDefinition(const VarDecl *VD,
1165  llvm::GlobalVariable *Addr,
1166  bool PerformInit);
1167 
1168  /// Creates artificial threadprivate variable with name \p Name and type \p
1169  /// VarType.
1170  /// \param VarType Type of the artificial threadprivate variable.
1171  /// \param Name Name of the artificial threadprivate variable.
1173  QualType VarType,
1174  StringRef Name);
1175 
1176  /// Emit flush of the variables specified in 'omp flush' directive.
1177  /// \param Vars List of variables to flush.
1178  virtual void emitFlush(CodeGenFunction &CGF, ArrayRef<const Expr *> Vars,
1179  SourceLocation Loc);
1180 
1181  /// Emit task region for the task directive. The task region is
1182  /// emitted in several steps:
1183  /// 1. Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32
1184  /// gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds,
1185  /// kmp_routine_entry_t *task_entry). Here task_entry is a pointer to the
1186  /// function:
1187  /// kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) {
1188  /// TaskFunction(gtid, tt->part_id, tt->shareds);
1189  /// return 0;
1190  /// }
1191  /// 2. Copy a list of shared variables to field shareds of the resulting
1192  /// structure kmp_task_t returned by the previous call (if any).
1193  /// 3. Copy a pointer to destructions function to field destructions of the
1194  /// resulting structure kmp_task_t.
1195  /// 4. Emit a call to kmp_int32 __kmpc_omp_task(ident_t *, kmp_int32 gtid,
1196  /// kmp_task_t *new_task), where new_task is a resulting structure from
1197  /// previous items.
1198  /// \param D Current task directive.
1199  /// \param TaskFunction An LLVM function with type void (*)(i32 /*gtid*/, i32
1200  /// /*part_id*/, captured_struct */*__context*/);
1201  /// \param SharedsTy A type which contains references the shared variables.
1202  /// \param Shareds Context with the list of shared variables from the \p
1203  /// TaskFunction.
1204  /// \param IfCond Not a nullptr if 'if' clause was specified, nullptr
1205  /// otherwise.
1206  /// \param Data Additional data for task generation like tiednsee, final
1207  /// state, list of privates etc.
1208  virtual void emitTaskCall(CodeGenFunction &CGF, SourceLocation Loc,
1209  const OMPExecutableDirective &D,
1210  llvm::Function *TaskFunction, QualType SharedsTy,
1211  Address Shareds, const Expr *IfCond,
1212  const OMPTaskDataTy &Data);
1213 
1214  /// Emit task region for the taskloop directive. The taskloop region is
1215  /// emitted in several steps:
1216  /// 1. Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32
1217  /// gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds,
1218  /// kmp_routine_entry_t *task_entry). Here task_entry is a pointer to the
1219  /// function:
1220  /// kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) {
1221  /// TaskFunction(gtid, tt->part_id, tt->shareds);
1222  /// return 0;
1223  /// }
1224  /// 2. Copy a list of shared variables to field shareds of the resulting
1225  /// structure kmp_task_t returned by the previous call (if any).
1226  /// 3. Copy a pointer to destructions function to field destructions of the
1227  /// resulting structure kmp_task_t.
1228  /// 4. Emit a call to void __kmpc_taskloop(ident_t *loc, int gtid, kmp_task_t
1229  /// *task, int if_val, kmp_uint64 *lb, kmp_uint64 *ub, kmp_int64 st, int
1230  /// nogroup, int sched, kmp_uint64 grainsize, void *task_dup ), where new_task
1231  /// is a resulting structure from
1232  /// previous items.
1233  /// \param D Current task directive.
1234  /// \param TaskFunction An LLVM function with type void (*)(i32 /*gtid*/, i32
1235  /// /*part_id*/, captured_struct */*__context*/);
1236  /// \param SharedsTy A type which contains references the shared variables.
1237  /// \param Shareds Context with the list of shared variables from the \p
1238  /// TaskFunction.
1239  /// \param IfCond Not a nullptr if 'if' clause was specified, nullptr
1240  /// otherwise.
1241  /// \param Data Additional data for task generation like tiednsee, final
1242  /// state, list of privates etc.
1243  virtual void emitTaskLoopCall(CodeGenFunction &CGF, SourceLocation Loc,
1244  const OMPLoopDirective &D,
1245  llvm::Function *TaskFunction,
1246  QualType SharedsTy, Address Shareds,
1247  const Expr *IfCond, const OMPTaskDataTy &Data);
1248 
1249  /// Emit code for the directive that does not require outlining.
1250  ///
1251  /// \param InnermostKind Kind of innermost directive (for simple directives it
1252  /// is a directive itself, for combined - its innermost directive).
1253  /// \param CodeGen Code generation sequence for the \a D directive.
1254  /// \param HasCancel true if region has inner cancel directive, false
1255  /// otherwise.
1256  virtual void emitInlinedDirective(CodeGenFunction &CGF,
1257  OpenMPDirectiveKind InnermostKind,
1258  const RegionCodeGenTy &CodeGen,
1259  bool HasCancel = false);
1260 
1261  /// Emits reduction function.
1262  /// \param ArgsType Array type containing pointers to reduction variables.
1263  /// \param Privates List of private copies for original reduction arguments.
1264  /// \param LHSExprs List of LHS in \a ReductionOps reduction operations.
1265  /// \param RHSExprs List of RHS in \a ReductionOps reduction operations.
1266  /// \param ReductionOps List of reduction operations in form 'LHS binop RHS'
1267  /// or 'operator binop(LHS, RHS)'.
1268  llvm::Function *emitReductionFunction(SourceLocation Loc,
1269  llvm::Type *ArgsType,
1271  ArrayRef<const Expr *> LHSExprs,
1272  ArrayRef<const Expr *> RHSExprs,
1273  ArrayRef<const Expr *> ReductionOps);
1274 
1275  /// Emits single reduction combiner
1277  const Expr *ReductionOp,
1278  const Expr *PrivateRef,
1279  const DeclRefExpr *LHS,
1280  const DeclRefExpr *RHS);
1281 
1286  };
1287  /// Emit a code for reduction clause. Next code should be emitted for
1288  /// reduction:
1289  /// \code
1290  ///
1291  /// static kmp_critical_name lock = { 0 };
1292  ///
1293  /// void reduce_func(void *lhs[<n>], void *rhs[<n>]) {
1294  /// ...
1295  /// *(Type<i>*)lhs[i] = RedOp<i>(*(Type<i>*)lhs[i], *(Type<i>*)rhs[i]);
1296  /// ...
1297  /// }
1298  ///
1299  /// ...
1300  /// void *RedList[<n>] = {&<RHSExprs>[0], ..., &<RHSExprs>[<n>-1]};
1301  /// switch (__kmpc_reduce{_nowait}(<loc>, <gtid>, <n>, sizeof(RedList),
1302  /// RedList, reduce_func, &<lock>)) {
1303  /// case 1:
1304  /// ...
1305  /// <LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]);
1306  /// ...
1307  /// __kmpc_end_reduce{_nowait}(<loc>, <gtid>, &<lock>);
1308  /// break;
1309  /// case 2:
1310  /// ...
1311  /// Atomic(<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]));
1312  /// ...
1313  /// break;
1314  /// default:;
1315  /// }
1316  /// \endcode
1317  ///
1318  /// \param Privates List of private copies for original reduction arguments.
1319  /// \param LHSExprs List of LHS in \a ReductionOps reduction operations.
1320  /// \param RHSExprs List of RHS in \a ReductionOps reduction operations.
1321  /// \param ReductionOps List of reduction operations in form 'LHS binop RHS'
1322  /// or 'operator binop(LHS, RHS)'.
1323  /// \param Options List of options for reduction codegen:
1324  /// WithNowait true if parent directive has also nowait clause, false
1325  /// otherwise.
1326  /// SimpleReduction Emit reduction operation only. Used for omp simd
1327  /// directive on the host.
1328  /// ReductionKind The kind of reduction to perform.
1329  virtual void emitReduction(CodeGenFunction &CGF, SourceLocation Loc,
1331  ArrayRef<const Expr *> LHSExprs,
1332  ArrayRef<const Expr *> RHSExprs,
1333  ArrayRef<const Expr *> ReductionOps,
1334  ReductionOptionsTy Options);
1335 
1336  /// Emit a code for initialization of task reduction clause. Next code
1337  /// should be emitted for reduction:
1338  /// \code
1339  ///
1340  /// _task_red_item_t red_data[n];
1341  /// ...
1342  /// red_data[i].shar = &origs[i];
1343  /// red_data[i].size = sizeof(origs[i]);
1344  /// red_data[i].f_init = (void*)RedInit<i>;
1345  /// red_data[i].f_fini = (void*)RedDest<i>;
1346  /// red_data[i].f_comb = (void*)RedOp<i>;
1347  /// red_data[i].flags = <Flag_i>;
1348  /// ...
1349  /// void* tg1 = __kmpc_task_reduction_init(gtid, n, red_data);
1350  /// \endcode
1351  ///
1352  /// \param LHSExprs List of LHS in \a Data.ReductionOps reduction operations.
1353  /// \param RHSExprs List of RHS in \a Data.ReductionOps reduction operations.
1354  /// \param Data Additional data for task generation like tiedness, final
1355  /// state, list of privates, reductions etc.
1357  SourceLocation Loc,
1358  ArrayRef<const Expr *> LHSExprs,
1359  ArrayRef<const Expr *> RHSExprs,
1360  const OMPTaskDataTy &Data);
1361 
1362  /// Required to resolve existing problems in the runtime. Emits threadprivate
1363  /// variables to store the size of the VLAs/array sections for
1364  /// initializer/combiner/finalizer functions + emits threadprivate variable to
1365  /// store the pointer to the original reduction item for the custom
1366  /// initializer defined by declare reduction construct.
1367  /// \param RCG Allows to reuse an existing data for the reductions.
1368  /// \param N Reduction item for which fixups must be emitted.
1370  ReductionCodeGen &RCG, unsigned N);
1371 
1372  /// Get the address of `void *` type of the privatue copy of the reduction
1373  /// item specified by the \p SharedLVal.
1374  /// \param ReductionsPtr Pointer to the reduction data returned by the
1375  /// emitTaskReductionInit function.
1376  /// \param SharedLVal Address of the original reduction item.
1378  llvm::Value *ReductionsPtr,
1379  LValue SharedLVal);
1380 
1381  /// Emit code for 'taskwait' directive.
1382  virtual void emitTaskwaitCall(CodeGenFunction &CGF, SourceLocation Loc);
1383 
1384  /// Emit code for 'cancellation point' construct.
1385  /// \param CancelRegion Region kind for which the cancellation point must be
1386  /// emitted.
1387  ///
1388  virtual void emitCancellationPointCall(CodeGenFunction &CGF,
1389  SourceLocation Loc,
1390  OpenMPDirectiveKind CancelRegion);
1391 
1392  /// Emit code for 'cancel' construct.
1393  /// \param IfCond Condition in the associated 'if' clause, if it was
1394  /// specified, nullptr otherwise.
1395  /// \param CancelRegion Region kind for which the cancel must be emitted.
1396  ///
1397  virtual void emitCancelCall(CodeGenFunction &CGF, SourceLocation Loc,
1398  const Expr *IfCond,
1399  OpenMPDirectiveKind CancelRegion);
1400 
1401  /// Emit outilined function for 'target' directive.
1402  /// \param D Directive to emit.
1403  /// \param ParentName Name of the function that encloses the target region.
1404  /// \param OutlinedFn Outlined function value to be defined by this call.
1405  /// \param OutlinedFnID Outlined function ID value to be defined by this call.
1406  /// \param IsOffloadEntry True if the outlined function is an offload entry.
1407  /// \param CodeGen Code generation sequence for the \a D directive.
1408  /// An outlined function may not be an entry if, e.g. the if clause always
1409  /// evaluates to false.
1410  virtual void emitTargetOutlinedFunction(const OMPExecutableDirective &D,
1411  StringRef ParentName,
1412  llvm::Function *&OutlinedFn,
1413  llvm::Constant *&OutlinedFnID,
1414  bool IsOffloadEntry,
1415  const RegionCodeGenTy &CodeGen);
1416 
1417  /// Emit code that pushes the trip count of loops associated with constructs
1418  /// 'target teams distribute' and 'teams distribute parallel for'.
1419  /// \param SizeEmitter Emits the int64 value for the number of iterations of
1420  /// the associated loop.
1421  virtual void emitTargetNumIterationsCall(
1422  CodeGenFunction &CGF, const OMPExecutableDirective &D, const Expr *Device,
1423  const llvm::function_ref<llvm::Value *(
1424  CodeGenFunction &CGF, const OMPLoopDirective &D)> &SizeEmitter);
1425 
1426  /// Emit the target offloading code associated with \a D. The emitted
1427  /// code attempts offloading the execution to the device, an the event of
1428  /// a failure it executes the host version outlined in \a OutlinedFn.
1429  /// \param D Directive to emit.
1430  /// \param OutlinedFn Host version of the code to be offloaded.
1431  /// \param OutlinedFnID ID of host version of the code to be offloaded.
1432  /// \param IfCond Expression evaluated in if clause associated with the target
1433  /// directive, or null if no if clause is used.
1434  /// \param Device Expression evaluated in device clause associated with the
1435  /// target directive, or null if no device clause is used.
1436  virtual void emitTargetCall(CodeGenFunction &CGF,
1437  const OMPExecutableDirective &D,
1438  llvm::Function *OutlinedFn,
1439  llvm::Value *OutlinedFnID, const Expr *IfCond,
1440  const Expr *Device);
1441 
1442  /// Emit the target regions enclosed in \a GD function definition or
1443  /// the function itself in case it is a valid device function. Returns true if
1444  /// \a GD was dealt with successfully.
1445  /// \param GD Function to scan.
1446  virtual bool emitTargetFunctions(GlobalDecl GD);
1447 
1448  /// Emit the global variable if it is a valid device global variable.
1449  /// Returns true if \a GD was dealt with successfully.
1450  /// \param GD Variable declaration to emit.
1451  virtual bool emitTargetGlobalVariable(GlobalDecl GD);
1452 
1453  /// Checks if the provided global decl \a GD is a declare target variable and
1454  /// registers it when emitting code for the host.
1455  virtual void registerTargetGlobalVariable(const VarDecl *VD,
1456  llvm::Constant *Addr);
1457 
1458  /// Registers provided target firstprivate variable as global on the
1459  /// target.
1460  llvm::Constant *registerTargetFirstprivateCopy(CodeGenFunction &CGF,
1461  const VarDecl *VD);
1462 
1463  /// Emit the global \a GD if it is meaningful for the target. Returns
1464  /// if it was emitted successfully.
1465  /// \param GD Global to scan.
1466  virtual bool emitTargetGlobal(GlobalDecl GD);
1467 
1468  /// Creates and returns a registration function for when at least one
1469  /// requires directives was used in the current module.
1470  llvm::Function *emitRequiresDirectiveRegFun();
1471 
1472  /// Creates the offloading descriptor in the event any target region
1473  /// was emitted in the current module and return the function that registers
1474  /// it.
1475  virtual llvm::Function *emitRegistrationFunction();
1476 
1477  /// Emits code for teams call of the \a OutlinedFn with
1478  /// variables captured in a record which address is stored in \a
1479  /// CapturedStruct.
1480  /// \param OutlinedFn Outlined function to be run by team masters. Type of
1481  /// this function is void(*)(kmp_int32 *, kmp_int32, struct context_vars*).
1482  /// \param CapturedVars A pointer to the record with the references to
1483  /// variables used in \a OutlinedFn function.
1484  ///
1485  virtual void emitTeamsCall(CodeGenFunction &CGF,
1486  const OMPExecutableDirective &D,
1487  SourceLocation Loc, llvm::Function *OutlinedFn,
1488  ArrayRef<llvm::Value *> CapturedVars);
1489 
1490  /// Emits call to void __kmpc_push_num_teams(ident_t *loc, kmp_int32
1491  /// global_tid, kmp_int32 num_teams, kmp_int32 thread_limit) to generate code
1492  /// for num_teams clause.
1493  /// \param NumTeams An integer expression of teams.
1494  /// \param ThreadLimit An integer expression of threads.
1495  virtual void emitNumTeamsClause(CodeGenFunction &CGF, const Expr *NumTeams,
1496  const Expr *ThreadLimit, SourceLocation Loc);
1497 
1498  /// Struct that keeps all the relevant information that should be kept
1499  /// throughout a 'target data' region.
1501  /// Set to true if device pointer information have to be obtained.
1502  bool RequiresDevicePointerInfo = false;
1503 
1504  public:
1505  /// The array of base pointer passed to the runtime library.
1506  llvm::Value *BasePointersArray = nullptr;
1507  /// The array of section pointers passed to the runtime library.
1508  llvm::Value *PointersArray = nullptr;
1509  /// The array of sizes passed to the runtime library.
1510  llvm::Value *SizesArray = nullptr;
1511  /// The array of map types passed to the runtime library.
1512  llvm::Value *MapTypesArray = nullptr;
1513  /// The total number of pointers passed to the runtime library.
1514  unsigned NumberOfPtrs = 0u;
1515  /// Map between the a declaration of a capture and the corresponding base
1516  /// pointer address where the runtime returns the device pointers.
1517  llvm::DenseMap<const ValueDecl *, Address> CaptureDeviceAddrMap;
1518 
1519  explicit TargetDataInfo() {}
1520  explicit TargetDataInfo(bool RequiresDevicePointerInfo)
1521  : RequiresDevicePointerInfo(RequiresDevicePointerInfo) {}
1522  /// Clear information about the data arrays.
1524  BasePointersArray = nullptr;
1525  PointersArray = nullptr;
1526  SizesArray = nullptr;
1527  MapTypesArray = nullptr;
1528  NumberOfPtrs = 0u;
1529  }
1530  /// Return true if the current target data information has valid arrays.
1531  bool isValid() {
1532  return BasePointersArray && PointersArray && SizesArray &&
1533  MapTypesArray && NumberOfPtrs;
1534  }
1535  bool requiresDevicePointerInfo() { return RequiresDevicePointerInfo; }
1536  };
1537 
1538  /// Emit the target data mapping code associated with \a D.
1539  /// \param D Directive to emit.
1540  /// \param IfCond Expression evaluated in if clause associated with the
1541  /// target directive, or null if no device clause is used.
1542  /// \param Device Expression evaluated in device clause associated with the
1543  /// target directive, or null if no device clause is used.
1544  /// \param Info A record used to store information that needs to be preserved
1545  /// until the region is closed.
1546  virtual void emitTargetDataCalls(CodeGenFunction &CGF,
1547  const OMPExecutableDirective &D,
1548  const Expr *IfCond, const Expr *Device,
1549  const RegionCodeGenTy &CodeGen,
1550  TargetDataInfo &Info);
1551 
1552  /// Emit the data mapping/movement code associated with the directive
1553  /// \a D that should be of the form 'target [{enter|exit} data | update]'.
1554  /// \param D Directive to emit.
1555  /// \param IfCond Expression evaluated in if clause associated with the target
1556  /// directive, or null if no if clause is used.
1557  /// \param Device Expression evaluated in device clause associated with the
1558  /// target directive, or null if no device clause is used.
1560  const OMPExecutableDirective &D,
1561  const Expr *IfCond,
1562  const Expr *Device);
1563 
1564  /// Marks function \a Fn with properly mangled versions of vector functions.
1565  /// \param FD Function marked as 'declare simd'.
1566  /// \param Fn LLVM function that must be marked with 'declare simd'
1567  /// attributes.
1568  virtual void emitDeclareSimdFunction(const FunctionDecl *FD,
1569  llvm::Function *Fn);
1570 
1571  /// Emit initialization for doacross loop nesting support.
1572  /// \param D Loop-based construct used in doacross nesting construct.
1573  virtual void emitDoacrossInit(CodeGenFunction &CGF, const OMPLoopDirective &D,
1574  ArrayRef<Expr *> NumIterations);
1575 
1576  /// Emit code for doacross ordered directive with 'depend' clause.
1577  /// \param C 'depend' clause with 'sink|source' dependency kind.
1578  virtual void emitDoacrossOrdered(CodeGenFunction &CGF,
1579  const OMPDependClause *C);
1580 
1581  /// Translates the native parameter of outlined function if this is required
1582  /// for target.
1583  /// \param FD Field decl from captured record for the parameter.
1584  /// \param NativeParam Parameter itself.
1585  virtual const VarDecl *translateParameter(const FieldDecl *FD,
1586  const VarDecl *NativeParam) const {
1587  return NativeParam;
1588  }
1589 
1590  /// Gets the address of the native argument basing on the address of the
1591  /// target-specific parameter.
1592  /// \param NativeParam Parameter itself.
1593  /// \param TargetParam Corresponding target-specific parameter.
1595  const VarDecl *NativeParam,
1596  const VarDecl *TargetParam) const;
1597 
1598  /// Choose default schedule type and chunk value for the
1599  /// dist_schedule clause.
1601  const OMPLoopDirective &S, OpenMPDistScheduleClauseKind &ScheduleKind,
1602  llvm::Value *&Chunk) const {}
1603 
1604  /// Choose default schedule type and chunk value for the
1605  /// schedule clause.
1606  virtual void getDefaultScheduleAndChunk(CodeGenFunction &CGF,
1607  const OMPLoopDirective &S, OpenMPScheduleClauseKind &ScheduleKind,
1608  const Expr *&ChunkExpr) const;
1609 
1610  /// Emits call of the outlined function with the provided arguments,
1611  /// translating these arguments to correct target-specific arguments.
1612  virtual void
1614  llvm::FunctionCallee OutlinedFn,
1615  ArrayRef<llvm::Value *> Args = llvm::None) const;
1616 
1617  /// Emits OpenMP-specific function prolog.
1618  /// Required for device constructs.
1619  virtual void emitFunctionProlog(CodeGenFunction &CGF, const Decl *D);
1620 
1621  /// Gets the OpenMP-specific address of the local variable.
1623  const VarDecl *VD);
1624 
1625  /// Marks the declaration as already emitted for the device code and returns
1626  /// true, if it was marked already, and false, otherwise.
1627  bool markAsGlobalTarget(GlobalDecl GD);
1628 
1629  /// Emit deferred declare target variables marked for deferred emission.
1630  void emitDeferredTargetDecls() const;
1631 
1632  /// Adjust some parameters for the target-based directives, like addresses of
1633  /// the variables captured by reference in lambdas.
1634  virtual void
1636  const OMPExecutableDirective &D) const;
1637 
1638  /// Perform check on requires decl to ensure that target architecture
1639  /// supports unified addressing
1640  virtual void checkArchForUnifiedAddressing(const OMPRequiresDecl *D);
1641 
1642  /// Checks if the variable has associated OMPAllocateDeclAttr attribute with
1643  /// the predefined allocator and translates it into the corresponding address
1644  /// space.
1645  virtual bool hasAllocateAttributeForGlobalVar(const VarDecl *VD, LangAS &AS);
1646 
1647  /// Return whether the unified_shared_memory has been specified.
1648  bool hasRequiresUnifiedSharedMemory() const;
1649 };
1650 
1651 /// Class supports emissionof SIMD-only code.
1652 class CGOpenMPSIMDRuntime final : public CGOpenMPRuntime {
1653 public:
1654  explicit CGOpenMPSIMDRuntime(CodeGenModule &CGM) : CGOpenMPRuntime(CGM) {}
1655  ~CGOpenMPSIMDRuntime() override {}
1656 
1657  /// Emits outlined function for the specified OpenMP parallel directive
1658  /// \a D. This outlined function has type void(*)(kmp_int32 *ThreadID,
1659  /// kmp_int32 BoundID, struct context_vars*).
1660  /// \param D OpenMP directive.
1661  /// \param ThreadIDVar Variable for thread id in the current OpenMP region.
1662  /// \param InnermostKind Kind of innermost directive (for simple directives it
1663  /// is a directive itself, for combined - its innermost directive).
1664  /// \param CodeGen Code generation sequence for the \a D directive.
1665  llvm::Function *
1667  const VarDecl *ThreadIDVar,
1668  OpenMPDirectiveKind InnermostKind,
1669  const RegionCodeGenTy &CodeGen) override;
1670 
1671  /// Emits outlined function for the specified OpenMP teams directive
1672  /// \a D. This outlined function has type void(*)(kmp_int32 *ThreadID,
1673  /// kmp_int32 BoundID, struct context_vars*).
1674  /// \param D OpenMP directive.
1675  /// \param ThreadIDVar Variable for thread id in the current OpenMP region.
1676  /// \param InnermostKind Kind of innermost directive (for simple directives it
1677  /// is a directive itself, for combined - its innermost directive).
1678  /// \param CodeGen Code generation sequence for the \a D directive.
1679  llvm::Function *
1681  const VarDecl *ThreadIDVar,
1682  OpenMPDirectiveKind InnermostKind,
1683  const RegionCodeGenTy &CodeGen) override;
1684 
1685  /// Emits outlined function for the OpenMP task directive \a D. This
1686  /// outlined function has type void(*)(kmp_int32 ThreadID, struct task_t*
1687  /// TaskT).
1688  /// \param D OpenMP directive.
1689  /// \param ThreadIDVar Variable for thread id in the current OpenMP region.
1690  /// \param PartIDVar Variable for partition id in the current OpenMP untied
1691  /// task region.
1692  /// \param TaskTVar Variable for task_t argument.
1693  /// \param InnermostKind Kind of innermost directive (for simple directives it
1694  /// is a directive itself, for combined - its innermost directive).
1695  /// \param CodeGen Code generation sequence for the \a D directive.
1696  /// \param Tied true if task is generated for tied task, false otherwise.
1697  /// \param NumberOfParts Number of parts in untied task. Ignored for tied
1698  /// tasks.
1699  ///
1700  llvm::Function *emitTaskOutlinedFunction(
1701  const OMPExecutableDirective &D, const VarDecl *ThreadIDVar,
1702  const VarDecl *PartIDVar, const VarDecl *TaskTVar,
1703  OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen,
1704  bool Tied, unsigned &NumberOfParts) override;
1705 
1706  /// Emits code for parallel or serial call of the \a OutlinedFn with
1707  /// variables captured in a record which address is stored in \a
1708  /// CapturedStruct.
1709  /// \param OutlinedFn Outlined function to be run in parallel threads. Type of
1710  /// this function is void(*)(kmp_int32 *, kmp_int32, struct context_vars*).
1711  /// \param CapturedVars A pointer to the record with the references to
1712  /// variables used in \a OutlinedFn function.
1713  /// \param IfCond Condition in the associated 'if' clause, if it was
1714  /// specified, nullptr otherwise.
1715  ///
1716  void emitParallelCall(CodeGenFunction &CGF, SourceLocation Loc,
1717  llvm::Function *OutlinedFn,
1718  ArrayRef<llvm::Value *> CapturedVars,
1719  const Expr *IfCond) override;
1720 
1721  /// Emits a critical region.
1722  /// \param CriticalName Name of the critical region.
1723  /// \param CriticalOpGen Generator for the statement associated with the given
1724  /// critical region.
1725  /// \param Hint Value of the 'hint' clause (optional).
1726  void emitCriticalRegion(CodeGenFunction &CGF, StringRef CriticalName,
1727  const RegionCodeGenTy &CriticalOpGen,
1728  SourceLocation Loc,
1729  const Expr *Hint = nullptr) override;
1730 
1731  /// Emits a master region.
1732  /// \param MasterOpGen Generator for the statement associated with the given
1733  /// master region.
1734  void emitMasterRegion(CodeGenFunction &CGF,
1735  const RegionCodeGenTy &MasterOpGen,
1736  SourceLocation Loc) override;
1737 
1738  /// Emits code for a taskyield directive.
1739  void emitTaskyieldCall(CodeGenFunction &CGF, SourceLocation Loc) override;
1740 
1741  /// Emit a taskgroup region.
1742  /// \param TaskgroupOpGen Generator for the statement associated with the
1743  /// given taskgroup region.
1744  void emitTaskgroupRegion(CodeGenFunction &CGF,
1745  const RegionCodeGenTy &TaskgroupOpGen,
1746  SourceLocation Loc) override;
1747 
1748  /// Emits a single region.
1749  /// \param SingleOpGen Generator for the statement associated with the given
1750  /// single region.
1751  void emitSingleRegion(CodeGenFunction &CGF,
1752  const RegionCodeGenTy &SingleOpGen, SourceLocation Loc,
1753  ArrayRef<const Expr *> CopyprivateVars,
1754  ArrayRef<const Expr *> DestExprs,
1755  ArrayRef<const Expr *> SrcExprs,
1756  ArrayRef<const Expr *> AssignmentOps) override;
1757 
1758  /// Emit an ordered region.
1759  /// \param OrderedOpGen Generator for the statement associated with the given
1760  /// ordered region.
1761  void emitOrderedRegion(CodeGenFunction &CGF,
1762  const RegionCodeGenTy &OrderedOpGen,
1763  SourceLocation Loc, bool IsThreads) override;
1764 
1765  /// Emit an implicit/explicit barrier for OpenMP threads.
1766  /// \param Kind Directive for which this implicit barrier call must be
1767  /// generated. Must be OMPD_barrier for explicit barrier generation.
1768  /// \param EmitChecks true if need to emit checks for cancellation barriers.
1769  /// \param ForceSimpleCall true simple barrier call must be emitted, false if
1770  /// runtime class decides which one to emit (simple or with cancellation
1771  /// checks).
1772  ///
1773  void emitBarrierCall(CodeGenFunction &CGF, SourceLocation Loc,
1774  OpenMPDirectiveKind Kind, bool EmitChecks = true,
1775  bool ForceSimpleCall = false) override;
1776 
1777  /// This is used for non static scheduled types and when the ordered
1778  /// clause is present on the loop construct.
1779  /// Depending on the loop schedule, it is necessary to call some runtime
1780  /// routine before start of the OpenMP loop to get the loop upper / lower
1781  /// bounds \a LB and \a UB and stride \a ST.
1782  ///
1783  /// \param CGF Reference to current CodeGenFunction.
1784  /// \param Loc Clang source location.
1785  /// \param ScheduleKind Schedule kind, specified by the 'schedule' clause.
1786  /// \param IVSize Size of the iteration variable in bits.
1787  /// \param IVSigned Sign of the iteration variable.
1788  /// \param Ordered true if loop is ordered, false otherwise.
1789  /// \param DispatchValues struct containing llvm values for lower bound, upper
1790  /// bound, and chunk expression.
1791  /// For the default (nullptr) value, the chunk 1 will be used.
1792  ///
1793  void emitForDispatchInit(CodeGenFunction &CGF, SourceLocation Loc,
1794  const OpenMPScheduleTy &ScheduleKind,
1795  unsigned IVSize, bool IVSigned, bool Ordered,
1796  const DispatchRTInput &DispatchValues) override;
1797 
1798  /// Call the appropriate runtime routine to initialize it before start
1799  /// of loop.
1800  ///
1801  /// This is used only in case of static schedule, when the user did not
1802  /// specify a ordered clause on the loop construct.
1803  /// Depending on the loop schedule, it is necessary to call some runtime
1804  /// routine before start of the OpenMP loop to get the loop upper / lower
1805  /// bounds LB and UB and stride ST.
1806  ///
1807  /// \param CGF Reference to current CodeGenFunction.
1808  /// \param Loc Clang source location.
1809  /// \param DKind Kind of the directive.
1810  /// \param ScheduleKind Schedule kind, specified by the 'schedule' clause.
1811  /// \param Values Input arguments for the construct.
1812  ///
1813  void emitForStaticInit(CodeGenFunction &CGF, SourceLocation Loc,
1814  OpenMPDirectiveKind DKind,
1815  const OpenMPScheduleTy &ScheduleKind,
1816  const StaticRTInput &Values) override;
1817 
1818  ///
1819  /// \param CGF Reference to current CodeGenFunction.
1820  /// \param Loc Clang source location.
1821  /// \param SchedKind Schedule kind, specified by the 'dist_schedule' clause.
1822  /// \param Values Input arguments for the construct.
1823  ///
1824  void emitDistributeStaticInit(CodeGenFunction &CGF, SourceLocation Loc,
1825  OpenMPDistScheduleClauseKind SchedKind,
1826  const StaticRTInput &Values) override;
1827 
1828  /// Call the appropriate runtime routine to notify that we finished
1829  /// iteration of the ordered loop with the dynamic scheduling.
1830  ///
1831  /// \param CGF Reference to current CodeGenFunction.
1832  /// \param Loc Clang source location.
1833  /// \param IVSize Size of the iteration variable in bits.
1834  /// \param IVSigned Sign of the iteration variable.
1835  ///
1836  void emitForOrderedIterationEnd(CodeGenFunction &CGF, SourceLocation Loc,
1837  unsigned IVSize, bool IVSigned) override;
1838 
1839  /// Call the appropriate runtime routine to notify that we finished
1840  /// all the work with current loop.
1841  ///
1842  /// \param CGF Reference to current CodeGenFunction.
1843  /// \param Loc Clang source location.
1844  /// \param DKind Kind of the directive for which the static finish is emitted.
1845  ///
1846  void emitForStaticFinish(CodeGenFunction &CGF, SourceLocation Loc,
1847  OpenMPDirectiveKind DKind) override;
1848 
1849  /// Call __kmpc_dispatch_next(
1850  /// ident_t *loc, kmp_int32 tid, kmp_int32 *p_lastiter,
1851  /// kmp_int[32|64] *p_lower, kmp_int[32|64] *p_upper,
1852  /// kmp_int[32|64] *p_stride);
1853  /// \param IVSize Size of the iteration variable in bits.
1854  /// \param IVSigned Sign of the iteration variable.
1855  /// \param IL Address of the output variable in which the flag of the
1856  /// last iteration is returned.
1857  /// \param LB Address of the output variable in which the lower iteration
1858  /// number is returned.
1859  /// \param UB Address of the output variable in which the upper iteration
1860  /// number is returned.
1861  /// \param ST Address of the output variable in which the stride value is
1862  /// returned.
1863  llvm::Value *emitForNext(CodeGenFunction &CGF, SourceLocation Loc,
1864  unsigned IVSize, bool IVSigned, Address IL,
1865  Address LB, Address UB, Address ST) override;
1866 
1867  /// Emits call to void __kmpc_push_num_threads(ident_t *loc, kmp_int32
1868  /// global_tid, kmp_int32 num_threads) to generate code for 'num_threads'
1869  /// clause.
1870  /// \param NumThreads An integer value of threads.
1871  void emitNumThreadsClause(CodeGenFunction &CGF, llvm::Value *NumThreads,
1872  SourceLocation Loc) override;
1873 
1874  /// Emit call to void __kmpc_push_proc_bind(ident_t *loc, kmp_int32
1875  /// global_tid, int proc_bind) to generate code for 'proc_bind' clause.
1876  void emitProcBindClause(CodeGenFunction &CGF,
1877  OpenMPProcBindClauseKind ProcBind,
1878  SourceLocation Loc) override;
1879 
1880  /// Returns address of the threadprivate variable for the current
1881  /// thread.
1882  /// \param VD Threadprivate variable.
1883  /// \param VDAddr Address of the global variable \a VD.
1884  /// \param Loc Location of the reference to threadprivate var.
1885  /// \return Address of the threadprivate variable for the current thread.
1886  Address getAddrOfThreadPrivate(CodeGenFunction &CGF, const VarDecl *VD,
1887  Address VDAddr, SourceLocation Loc) override;
1888 
1889  /// Emit a code for initialization of threadprivate variable. It emits
1890  /// a call to runtime library which adds initial value to the newly created
1891  /// threadprivate variable (if it is not constant) and registers destructor
1892  /// for the variable (if any).
1893  /// \param VD Threadprivate variable.
1894  /// \param VDAddr Address of the global variable \a VD.
1895  /// \param Loc Location of threadprivate declaration.
1896  /// \param PerformInit true if initialization expression is not constant.
1897  llvm::Function *
1898  emitThreadPrivateVarDefinition(const VarDecl *VD, Address VDAddr,
1899  SourceLocation Loc, bool PerformInit,
1900  CodeGenFunction *CGF = nullptr) override;
1901 
1902  /// Creates artificial threadprivate variable with name \p Name and type \p
1903  /// VarType.
1904  /// \param VarType Type of the artificial threadprivate variable.
1905  /// \param Name Name of the artificial threadprivate variable.
1906  Address getAddrOfArtificialThreadPrivate(CodeGenFunction &CGF,
1907  QualType VarType,
1908  StringRef Name) override;
1909 
1910  /// Emit flush of the variables specified in 'omp flush' directive.
1911  /// \param Vars List of variables to flush.
1912  void emitFlush(CodeGenFunction &CGF, ArrayRef<const Expr *> Vars,
1913  SourceLocation Loc) override;
1914 
1915  /// Emit task region for the task directive. The task region is
1916  /// emitted in several steps:
1917  /// 1. Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32
1918  /// gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds,
1919  /// kmp_routine_entry_t *task_entry). Here task_entry is a pointer to the
1920  /// function:
1921  /// kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) {
1922  /// TaskFunction(gtid, tt->part_id, tt->shareds);
1923  /// return 0;
1924  /// }
1925  /// 2. Copy a list of shared variables to field shareds of the resulting
1926  /// structure kmp_task_t returned by the previous call (if any).
1927  /// 3. Copy a pointer to destructions function to field destructions of the
1928  /// resulting structure kmp_task_t.
1929  /// 4. Emit a call to kmp_int32 __kmpc_omp_task(ident_t *, kmp_int32 gtid,
1930  /// kmp_task_t *new_task), where new_task is a resulting structure from
1931  /// previous items.
1932  /// \param D Current task directive.
1933  /// \param TaskFunction An LLVM function with type void (*)(i32 /*gtid*/, i32
1934  /// /*part_id*/, captured_struct */*__context*/);
1935  /// \param SharedsTy A type which contains references the shared variables.
1936  /// \param Shareds Context with the list of shared variables from the \p
1937  /// TaskFunction.
1938  /// \param IfCond Not a nullptr if 'if' clause was specified, nullptr
1939  /// otherwise.
1940  /// \param Data Additional data for task generation like tiednsee, final
1941  /// state, list of privates etc.
1942  void emitTaskCall(CodeGenFunction &CGF, SourceLocation Loc,
1943  const OMPExecutableDirective &D,
1944  llvm::Function *TaskFunction, QualType SharedsTy,
1945  Address Shareds, const Expr *IfCond,
1946  const OMPTaskDataTy &Data) override;
1947 
1948  /// Emit task region for the taskloop directive. The taskloop region is
1949  /// emitted in several steps:
1950  /// 1. Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32
1951  /// gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds,
1952  /// kmp_routine_entry_t *task_entry). Here task_entry is a pointer to the
1953  /// function:
1954  /// kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) {
1955  /// TaskFunction(gtid, tt->part_id, tt->shareds);
1956  /// return 0;
1957  /// }
1958  /// 2. Copy a list of shared variables to field shareds of the resulting
1959  /// structure kmp_task_t returned by the previous call (if any).
1960  /// 3. Copy a pointer to destructions function to field destructions of the
1961  /// resulting structure kmp_task_t.
1962  /// 4. Emit a call to void __kmpc_taskloop(ident_t *loc, int gtid, kmp_task_t
1963  /// *task, int if_val, kmp_uint64 *lb, kmp_uint64 *ub, kmp_int64 st, int
1964  /// nogroup, int sched, kmp_uint64 grainsize, void *task_dup ), where new_task
1965  /// is a resulting structure from
1966  /// previous items.
1967  /// \param D Current task directive.
1968  /// \param TaskFunction An LLVM function with type void (*)(i32 /*gtid*/, i32
1969  /// /*part_id*/, captured_struct */*__context*/);
1970  /// \param SharedsTy A type which contains references the shared variables.
1971  /// \param Shareds Context with the list of shared variables from the \p
1972  /// TaskFunction.
1973  /// \param IfCond Not a nullptr if 'if' clause was specified, nullptr
1974  /// otherwise.
1975  /// \param Data Additional data for task generation like tiednsee, final
1976  /// state, list of privates etc.
1977  void emitTaskLoopCall(CodeGenFunction &CGF, SourceLocation Loc,
1978  const OMPLoopDirective &D, llvm::Function *TaskFunction,
1979  QualType SharedsTy, Address Shareds, const Expr *IfCond,
1980  const OMPTaskDataTy &Data) override;
1981 
1982  /// Emit a code for reduction clause. Next code should be emitted for
1983  /// reduction:
1984  /// \code
1985  ///
1986  /// static kmp_critical_name lock = { 0 };
1987  ///
1988  /// void reduce_func(void *lhs[<n>], void *rhs[<n>]) {
1989  /// ...
1990  /// *(Type<i>*)lhs[i] = RedOp<i>(*(Type<i>*)lhs[i], *(Type<i>*)rhs[i]);
1991  /// ...
1992  /// }
1993  ///
1994  /// ...
1995  /// void *RedList[<n>] = {&<RHSExprs>[0], ..., &<RHSExprs>[<n>-1]};
1996  /// switch (__kmpc_reduce{_nowait}(<loc>, <gtid>, <n>, sizeof(RedList),
1997  /// RedList, reduce_func, &<lock>)) {
1998  /// case 1:
1999  /// ...
2000  /// <LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]);
2001  /// ...
2002  /// __kmpc_end_reduce{_nowait}(<loc>, <gtid>, &<lock>);
2003  /// break;
2004  /// case 2:
2005  /// ...
2006  /// Atomic(<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]));
2007  /// ...
2008  /// break;
2009  /// default:;
2010  /// }
2011  /// \endcode
2012  ///
2013  /// \param Privates List of private copies for original reduction arguments.
2014  /// \param LHSExprs List of LHS in \a ReductionOps reduction operations.
2015  /// \param RHSExprs List of RHS in \a ReductionOps reduction operations.
2016  /// \param ReductionOps List of reduction operations in form 'LHS binop RHS'
2017  /// or 'operator binop(LHS, RHS)'.
2018  /// \param Options List of options for reduction codegen:
2019  /// WithNowait true if parent directive has also nowait clause, false
2020  /// otherwise.
2021  /// SimpleReduction Emit reduction operation only. Used for omp simd
2022  /// directive on the host.
2023  /// ReductionKind The kind of reduction to perform.
2024  void emitReduction(CodeGenFunction &CGF, SourceLocation Loc,
2026  ArrayRef<const Expr *> LHSExprs,
2027  ArrayRef<const Expr *> RHSExprs,
2028  ArrayRef<const Expr *> ReductionOps,
2029  ReductionOptionsTy Options) override;
2030 
2031  /// Emit a code for initialization of task reduction clause. Next code
2032  /// should be emitted for reduction:
2033  /// \code
2034  ///
2035  /// _task_red_item_t red_data[n];
2036  /// ...
2037  /// red_data[i].shar = &origs[i];
2038  /// red_data[i].size = sizeof(origs[i]);
2039  /// red_data[i].f_init = (void*)RedInit<i>;
2040  /// red_data[i].f_fini = (void*)RedDest<i>;
2041  /// red_data[i].f_comb = (void*)RedOp<i>;
2042  /// red_data[i].flags = <Flag_i>;
2043  /// ...
2044  /// void* tg1 = __kmpc_task_reduction_init(gtid, n, red_data);
2045  /// \endcode
2046  ///
2047  /// \param LHSExprs List of LHS in \a Data.ReductionOps reduction operations.
2048  /// \param RHSExprs List of RHS in \a Data.ReductionOps reduction operations.
2049  /// \param Data Additional data for task generation like tiedness, final
2050  /// state, list of privates, reductions etc.
2051  llvm::Value *emitTaskReductionInit(CodeGenFunction &CGF, SourceLocation Loc,
2052  ArrayRef<const Expr *> LHSExprs,
2053  ArrayRef<const Expr *> RHSExprs,
2054  const OMPTaskDataTy &Data) override;
2055 
2056  /// Required to resolve existing problems in the runtime. Emits threadprivate
2057  /// variables to store the size of the VLAs/array sections for
2058  /// initializer/combiner/finalizer functions + emits threadprivate variable to
2059  /// store the pointer to the original reduction item for the custom
2060  /// initializer defined by declare reduction construct.
2061  /// \param RCG Allows to reuse an existing data for the reductions.
2062  /// \param N Reduction item for which fixups must be emitted.
2063  void emitTaskReductionFixups(CodeGenFunction &CGF, SourceLocation Loc,
2064  ReductionCodeGen &RCG, unsigned N) override;
2065 
2066  /// Get the address of `void *` type of the privatue copy of the reduction
2067  /// item specified by the \p SharedLVal.
2068  /// \param ReductionsPtr Pointer to the reduction data returned by the
2069  /// emitTaskReductionInit function.
2070  /// \param SharedLVal Address of the original reduction item.
2071  Address getTaskReductionItem(CodeGenFunction &CGF, SourceLocation Loc,
2072  llvm::Value *ReductionsPtr,
2073  LValue SharedLVal) override;
2074 
2075  /// Emit code for 'taskwait' directive.
2076  void emitTaskwaitCall(CodeGenFunction &CGF, SourceLocation Loc) override;
2077 
2078  /// Emit code for 'cancellation point' construct.
2079  /// \param CancelRegion Region kind for which the cancellation point must be
2080  /// emitted.
2081  ///
2082  void emitCancellationPointCall(CodeGenFunction &CGF, SourceLocation Loc,
2083  OpenMPDirectiveKind CancelRegion) override;
2084 
2085  /// Emit code for 'cancel' construct.
2086  /// \param IfCond Condition in the associated 'if' clause, if it was
2087  /// specified, nullptr otherwise.
2088  /// \param CancelRegion Region kind for which the cancel must be emitted.
2089  ///
2090  void emitCancelCall(CodeGenFunction &CGF, SourceLocation Loc,
2091  const Expr *IfCond,
2092  OpenMPDirectiveKind CancelRegion) override;
2093 
2094  /// Emit outilined function for 'target' directive.
2095  /// \param D Directive to emit.
2096  /// \param ParentName Name of the function that encloses the target region.
2097  /// \param OutlinedFn Outlined function value to be defined by this call.
2098  /// \param OutlinedFnID Outlined function ID value to be defined by this call.
2099  /// \param IsOffloadEntry True if the outlined function is an offload entry.
2100  /// \param CodeGen Code generation sequence for the \a D directive.
2101  /// An outlined function may not be an entry if, e.g. the if clause always
2102  /// evaluates to false.
2104  StringRef ParentName,
2105  llvm::Function *&OutlinedFn,
2106  llvm::Constant *&OutlinedFnID,
2107  bool IsOffloadEntry,
2108  const RegionCodeGenTy &CodeGen) override;
2109 
2110  /// Emit the target offloading code associated with \a D. The emitted
2111  /// code attempts offloading the execution to the device, an the event of
2112  /// a failure it executes the host version outlined in \a OutlinedFn.
2113  /// \param D Directive to emit.
2114  /// \param OutlinedFn Host version of the code to be offloaded.
2115  /// \param OutlinedFnID ID of host version of the code to be offloaded.
2116  /// \param IfCond Expression evaluated in if clause associated with the target
2117  /// directive, or null if no if clause is used.
2118  /// \param Device Expression evaluated in device clause associated with the
2119  /// target directive, or null if no device clause is used.
2120  void emitTargetCall(CodeGenFunction &CGF, const OMPExecutableDirective &D,
2121  llvm::Function *OutlinedFn, llvm::Value *OutlinedFnID,
2122  const Expr *IfCond, const Expr *Device) override;
2123 
2124  /// Emit the target regions enclosed in \a GD function definition or
2125  /// the function itself in case it is a valid device function. Returns true if
2126  /// \a GD was dealt with successfully.
2127  /// \param GD Function to scan.
2128  bool emitTargetFunctions(GlobalDecl GD) override;
2129 
2130  /// Emit the global variable if it is a valid device global variable.
2131  /// Returns true if \a GD was dealt with successfully.
2132  /// \param GD Variable declaration to emit.
2133  bool emitTargetGlobalVariable(GlobalDecl GD) override;
2134 
2135  /// Emit the global \a GD if it is meaningful for the target. Returns
2136  /// if it was emitted successfully.
2137  /// \param GD Global to scan.
2138  bool emitTargetGlobal(GlobalDecl GD) override;
2139 
2140  /// Creates the offloading descriptor in the event any target region
2141  /// was emitted in the current module and return the function that registers
2142  /// it.
2143  llvm::Function *emitRegistrationFunction() override;
2144 
2145  /// Emits code for teams call of the \a OutlinedFn with
2146  /// variables captured in a record which address is stored in \a
2147  /// CapturedStruct.
2148  /// \param OutlinedFn Outlined function to be run by team masters. Type of
2149  /// this function is void(*)(kmp_int32 *, kmp_int32, struct context_vars*).
2150  /// \param CapturedVars A pointer to the record with the references to
2151  /// variables used in \a OutlinedFn function.
2152  ///
2153  void emitTeamsCall(CodeGenFunction &CGF, const OMPExecutableDirective &D,
2154  SourceLocation Loc, llvm::Function *OutlinedFn,
2155  ArrayRef<llvm::Value *> CapturedVars) override;
2156 
2157  /// Emits call to void __kmpc_push_num_teams(ident_t *loc, kmp_int32
2158  /// global_tid, kmp_int32 num_teams, kmp_int32 thread_limit) to generate code
2159  /// for num_teams clause.
2160  /// \param NumTeams An integer expression of teams.
2161  /// \param ThreadLimit An integer expression of threads.
2162  void emitNumTeamsClause(CodeGenFunction &CGF, const Expr *NumTeams,
2163  const Expr *ThreadLimit, SourceLocation Loc) override;
2164 
2165  /// Emit the target data mapping code associated with \a D.
2166  /// \param D Directive to emit.
2167  /// \param IfCond Expression evaluated in if clause associated with the
2168  /// target directive, or null if no device clause is used.
2169  /// \param Device Expression evaluated in device clause associated with the
2170  /// target directive, or null if no device clause is used.
2171  /// \param Info A record used to store information that needs to be preserved
2172  /// until the region is closed.
2173  void emitTargetDataCalls(CodeGenFunction &CGF,
2174  const OMPExecutableDirective &D, const Expr *IfCond,
2175  const Expr *Device, const RegionCodeGenTy &CodeGen,
2176  TargetDataInfo &Info) override;
2177 
2178  /// Emit the data mapping/movement code associated with the directive
2179  /// \a D that should be of the form 'target [{enter|exit} data | update]'.
2180  /// \param D Directive to emit.
2181  /// \param IfCond Expression evaluated in if clause associated with the target
2182  /// directive, or null if no if clause is used.
2183  /// \param Device Expression evaluated in device clause associated with the
2184  /// target directive, or null if no device clause is used.
2185  void emitTargetDataStandAloneCall(CodeGenFunction &CGF,
2186  const OMPExecutableDirective &D,
2187  const Expr *IfCond,
2188  const Expr *Device) override;
2189 
2190  /// Emit initialization for doacross loop nesting support.
2191  /// \param D Loop-based construct used in doacross nesting construct.
2192  void emitDoacrossInit(CodeGenFunction &CGF, const OMPLoopDirective &D,
2193  ArrayRef<Expr *> NumIterations) override;
2194 
2195  /// Emit code for doacross ordered directive with 'depend' clause.
2196  /// \param C 'depend' clause with 'sink|source' dependency kind.
2197  void emitDoacrossOrdered(CodeGenFunction &CGF,
2198  const OMPDependClause *C) override;
2199 
2200  /// Translates the native parameter of outlined function if this is required
2201  /// for target.
2202  /// \param FD Field decl from captured record for the parameter.
2203  /// \param NativeParam Parameter itself.
2204  const VarDecl *translateParameter(const FieldDecl *FD,
2205  const VarDecl *NativeParam) const override;
2206 
2207  /// Gets the address of the native argument basing on the address of the
2208  /// target-specific parameter.
2209  /// \param NativeParam Parameter itself.
2210  /// \param TargetParam Corresponding target-specific parameter.
2211  Address getParameterAddress(CodeGenFunction &CGF, const VarDecl *NativeParam,
2212  const VarDecl *TargetParam) const override;
2213 
2214  /// Gets the OpenMP-specific address of the local variable.
2215  Address getAddressOfLocalVariable(CodeGenFunction &CGF,
2216  const VarDecl *VD) override {
2217  return Address::invalid();
2218  }
2219 };
2220 
2221 } // namespace CodeGen
2222 } // namespace clang
2223 
2224 #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:1756
OMPTargetRegionEntryKind
Kind of the target registry entry.
bool hasRequiresUnifiedSharedMemory() const
Return whether the unified_shared_memory has been specified.
virtual Address getAddressOfLocalVariable(CodeGenFunction &CGF, const VarDecl *VD)
Gets the OpenMP-specific address of the local variable.
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::Function *TaskFunction, QualType SharedsTy, Address Shareds, const OMPTaskDataTy &Data)
QualType TgtDeviceImageQTy
struct __tgt_device_image{ void *ImageStart; // Pointer to the target code start. ...
Scheduling data for loop-based OpenMP directives.
Definition: OpenMPKinds.h:165
A (possibly-)qualified type.
Definition: Type.h:643
Allows to disable automatic handling of functions used in target regions as those marked as omp decla...
llvm::Function * emitReductionFunction(SourceLocation Loc, llvm::Type *ArgsType, ArrayRef< const Expr *> Privates, ArrayRef< const Expr *> LHSExprs, ArrayRef< const Expr *> RHSExprs, ArrayRef< const Expr *> ReductionOps)
Emits reduction function.
void emitSingleReductionCombiner(CodeGenFunction &CGF, const Expr *ReductionOp, const Expr *PrivateRef, const DeclRefExpr *LHS, const DeclRefExpr *RHS)
Emits single reduction combiner.
Specialize PointerLikeTypeTraits to allow LazyGenerationalUpdatePtr to be placed into a PointerUnion...
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:88
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 already emitted for the device code and returns true, if it was marked alrea...
struct with the values to be passed to the dispatch runtime function
OffloadEntryInfoDeviceGlobalVar(unsigned Order, OMPTargetGlobalVarEntryKind Flags)
virtual void checkArchForUnifiedAddressing(const OMPRequiresDecl *D)
Perform check on requires decl to ensure that target architecture supports unified addressing...
void scanForTargetRegionsFunctions(const Stmt *S, StringRef ParentName)
Start scanning from statement S and and emit all target regions found along the way.
SmallVector< const Expr *, 4 > ReductionCopies
static const Stmt * getSingleCompoundChild(ASTContext &Ctx, const Stmt *Body)
Checks if the Body is the CompoundStmt and returns its child statement iff there is only one that is ...
DispatchRTInput(llvm::Value *LB, llvm::Value *UB, llvm::Value *Chunk)
Represents a variable declaration or definition.
Definition: Decl.h:812
bool isValid()
Return true if the current target data information has valid arrays.
virtual void emitTargetCall(CodeGenFunction &CGF, const OMPExecutableDirective &D, llvm::Function *OutlinedFn, llvm::Value *OutlinedFnID, const Expr *IfCond, const Expr *Device)
Emit the target offloading code associated with D.
llvm::DenseMap< const ValueDecl *, Address > CaptureDeviceAddrMap
Map between the a declaration of a capture and the corresponding base pointer address where the runti...
LangAS
Defines the address space values used by the address space qualifier of QualType. ...
Definition: AddressSpaces.h:25
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:23
void createOffloadEntriesAndInfoMetadata()
Creates all the offload entries in the current compilation unit along with the associated metadata...
llvm::FunctionCallee createForStaticInitFunction(unsigned IVSize, bool IVSigned)
Returns __kmpc_for_static_init_* runtime function for the specified size IVSize and sign IVSigned...
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:3634
llvm::StringMap< llvm::WeakTrackingVH > EmittedNonTargetVariables
List of the global variables with their addresses that should not be emitted for the target...
bool HasEmittedTargetRegion
Flag for keeping track of weather a target region has been emitted.
virtual llvm::Function * emitParallelOutlinedFunction(const OMPExecutableDirective &D, const VarDecl *ThreadIDVar, OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen)
Emits outlined function for the specified OpenMP parallel directive 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 emitTaskLoopCall(CodeGenFunction &CGF, SourceLocation Loc, const OMPLoopDirective &D, llvm::Function *TaskFunction, QualType SharedsTy, Address Shareds, const Expr *IfCond, const OMPTaskDataTy &Data)
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.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:160
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:2615
Definition: Format.h:2327
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:418
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:125
virtual void emitDoacrossInit(CodeGenFunction &CGF, const OMPLoopDirective &D, ArrayRef< Expr *> NumIterations)
Emit initialization for doacross loop nesting support.
void emitUserDefinedMapper(const OMPDeclareMapperDecl *D, CodeGenFunction *CGF=nullptr)
Emit the function for the user defined mapper construct.
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:37
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.
llvm::ArrayType * getKmpCriticalNameTy() const
Get the LLVM type for the critical name.
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.
SmallVector< const Expr *, 4 > FirstprivateCopies
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.
SmallVector< const Expr *, 4 > ReductionOps
SmallVector< const Expr *, 4 > ReductionVars
virtual bool hasAllocateAttributeForGlobalVar(const VarDecl *VD, LangAS &AS)
Checks if the variable has associated OMPAllocateDeclAttr attribute with the predefined allocator and...
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 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...
TargetDataInfo(bool RequiresDevicePointerInfo)
Class intended to support codegen of all kind of the reduction clauses.
llvm::FunctionCallee createRuntimeFunction(unsigned Function)
Returns specified OpenMP runtime function.
This represents &#39;#pragma omp requires...&#39; directive.
Definition: DeclOpenMP.h:345
QualType getTgtDeviceImageQTy()
Returns __tgt_device_image type.
This represents implicit clause &#39;depend&#39; for the &#39;#pragma omp task&#39; directive.
virtual unsigned getDefaultFirstprivateAddressSpace() const
Returns default address space for the constant firstprivates, 0 by default.
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:108
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).
#define V(N, I)
Definition: ASTContext.h:2913
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.
llvm::FunctionCallee createDispatchNextFunction(unsigned IVSize, bool IVSigned)
Returns __kmpc_dispatch_next_* runtime function for the specified size IVSize and sign IVSigned...
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
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:40
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 Address getAddrOfDeclareTargetVar(const VarDecl *VD)
Returns the address of the variable marked as declare target with link clause OR as declare target wi...
Address getAddressOfLocalVariable(CodeGenFunction &CGF, const VarDecl *VD) override
Gets the OpenMP-specific address of the local variable.
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...
__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-base.h:55
Kind
llvm::Function * emitRequiresDirectiveRegFun()
Creates and returns a registration function for when at least one requires directives was used in the...
Encodes a location in the source.
llvm::FunctionCallee createDispatchFiniFunction(unsigned IVSize, bool IVSigned)
Returns __kmpc_dispatch_fini_* runtime function for the specified size IVSize and sign IVSigned...
This represents &#39;#pragma omp declare reduction ...&#39; directive.
Definition: DeclOpenMP.h:102
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:32
virtual void emitCancellationPointCall(CodeGenFunction &CGF, SourceLocation Loc, OpenMPDirectiveKind CancelRegion)
Emit code for &#39;cancellation point&#39; construct.
OpenMPDirectiveKind
OpenMP directives.
Definition: OpenMPKinds.h:22
virtual llvm::Function * emitThreadPrivateVarDefinition(const VarDecl *VD, Address VDAddr, SourceLocation Loc, bool PerformInit, CodeGenFunction *CGF=nullptr)
Emit a code for initialization of threadprivate variable.
This file defines OpenMP nodes for declarative directives.
virtual void emitParallelCall(CodeGenFunction &CGF, SourceLocation Loc, llvm::Function *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...
unsigned size() const
Return number of entries defined so far.
virtual void Enter(CodeGenFunction &CGF)
An aligned address.
Definition: Address.h:24
llvm::FunctionCallee createDispatchInitFunction(unsigned IVSize, bool IVSigned)
Returns __kmpc_dispatch_init_* runtime function for the specified size IVSize and sign IVSigned...
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.
virtual void emitOutlinedFunctionCall(CodeGenFunction &CGF, SourceLocation Loc, llvm::FunctionCallee OutlinedFn, ArrayRef< llvm::Value *> Args=llvm::None) const
Emits call of the outlined function with the provided arguments, translating these arguments to corre...
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.
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...
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::Function *TaskFunction, QualType SharedsTy, Address Shareds, const Expr *IfCond, const OMPTaskDataTy &Data)
static std::string getName(const CallEvent &Call)
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.
llvm::Function * createOffloadingBinaryDescriptorRegistration()
Creates and registers offloading binary descriptor for the current compilation unit.
llvm::PointerIntPair< llvm::Value *, 1, bool > Priority
void emitUDMapperArrayInitOrDel(CodeGenFunction &MapperCGF, llvm::Value *Handle, llvm::Value *BasePtr, llvm::Value *Ptr, llvm::Value *Size, llvm::Value *MapType, CharUnits ElementSize, llvm::BasicBlock *ExitBB, bool IsInit)
Emit the array initialization or deletion portion for user-defined mapper code generation.
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.
virtual bool isDefaultLocationConstant() const
Check if the default location must be constant.
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 emitTeamsCall(CodeGenFunction &CGF, const OMPExecutableDirective &D, SourceLocation Loc, llvm::Function *OutlinedFn, ArrayRef< llvm::Value *> CapturedVars)
Emits code for teams call of the OutlinedFn with variables captured in a record which address is stor...
virtual void emitDistributeStaticInit(CodeGenFunction &CGF, SourceLocation Loc, OpenMPDistScheduleClauseKind SchedKind, const StaticRTInput &Values)
virtual StringRef getOutlinedHelperName() const
Get the function name of an outlined region.
bool HasEmittedDeclareTargetRegion
Flag for keeping track of weather a device routine has been emitted.
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::Constant * getOrCreateInternalVariable(llvm::Type *Ty, const llvm::Twine &Name, unsigned AddressSpace=0)
Gets (if variable with the given name already exist) or creates internal global variable with the spe...
llvm::function_ref< void(StringRef, const OffloadEntryInfoDeviceGlobalVar &)> OffloadDeviceGlobalVarEntryInfoActTy
Applies action Action on all registered entries.
llvm::Constant * registerTargetFirstprivateCopy(CodeGenFunction &CGF, const VarDecl *VD)
Registers provided target firstprivate variable as global on the target.
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:150
virtual llvm::Function * emitTeamsOutlinedFunction(const OMPExecutableDirective &D, const VarDecl *ThreadIDVar, OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen)
Emits outlined function for the specified OpenMP teams directive D.
ASTImporterLookupTable & LT
This represents &#39;#pragma omp declare mapper ...&#39; directive.
Definition: DeclOpenMP.h:217
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:1141
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.
bool HasRequiresUnifiedSharedMemory
Flag for keeping track of weather a requires unified_shared_memory directive is present.
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:166
virtual unsigned getDefaultLocationReserved2Flags() const
Returns additional flags that can be stored in reserved_2 field of the default location.
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::StringSet DeclareTargetWithDefinition
Set of declare target variables with the generated initializer.
virtual llvm::Function * emitTaskOutlinedFunction(const OMPExecutableDirective &D, const VarDecl *ThreadIDVar, const VarDecl *PartIDVar, const VarDecl *TaskTVar, OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen, bool Tied, unsigned &NumberOfParts)
Emits outlined function for the OpenMP task directive D.
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 emitTargetNumIterationsCall(CodeGenFunction &CGF, const OMPExecutableDirective &D, const Expr *Device, const llvm::function_ref< llvm::Value *(CodeGenFunction &CGF, const OMPLoopDirective &D)> &SizeEmitter)
Emit code that pushes the trip count of loops associated with constructs &#39;target teams distribute&#39; an...
virtual void emitTaskwaitCall(CodeGenFunction &CGF, SourceLocation Loc)
Emit code for &#39;taskwait&#39; directive.