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