blob: dc62f2b6d554f7e49ca53e5ec69ff6e38e31f343 [file] [log] [blame]
Alexey Bataev9959db52014-05-06 10:08:46 +00001//===----- 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
Benjamin Kramer2f5db8b2014-08-13 16:25:19 +000014#ifndef LLVM_CLANG_LIB_CODEGEN_CGOPENMPRUNTIME_H
15#define LLVM_CLANG_LIB_CODEGEN_CGOPENMPRUNTIME_H
Alexey Bataev9959db52014-05-06 10:08:46 +000016
Alexey Bataev7292c292016-04-25 12:22:29 +000017#include "CGValue.h"
Alexey Bataev62b63b12015-03-10 07:28:44 +000018#include "clang/AST/Type.h"
Alexander Musmanc6388682014-12-15 07:07:06 +000019#include "clang/Basic/OpenMPKinds.h"
Chandler Carruth0d9593d2015-01-14 11:29:14 +000020#include "clang/Basic/SourceLocation.h"
Alexey Bataev9959db52014-05-06 10:08:46 +000021#include "llvm/ADT/DenseMap.h"
Benjamin Kramer8fdba912016-02-02 14:24:21 +000022#include "llvm/ADT/SmallPtrSet.h"
Alexey Bataev3a3bf0b2014-09-22 10:01:53 +000023#include "llvm/ADT/StringMap.h"
Benjamin Kramer8fdba912016-02-02 14:24:21 +000024#include "llvm/IR/Function.h"
Alexey Bataev97720002014-11-11 04:05:39 +000025#include "llvm/IR/ValueHandle.h"
Alexey Bataev18095712014-10-10 12:19:54 +000026
27namespace llvm {
28class ArrayType;
29class Constant;
Alexey Bataev18095712014-10-10 12:19:54 +000030class FunctionType;
Alexey Bataev97720002014-11-11 04:05:39 +000031class GlobalVariable;
Alexey Bataev18095712014-10-10 12:19:54 +000032class StructType;
33class Type;
34class Value;
35} // namespace llvm
Alexey Bataev9959db52014-05-06 10:08:46 +000036
Alexey Bataev9959db52014-05-06 10:08:46 +000037namespace clang {
Alexey Bataevcc37cc12014-11-20 04:34:54 +000038class Expr;
Samuel Antaoee8fb302016-01-06 13:42:12 +000039class GlobalDecl;
Alexey Bataev8b427062016-05-25 12:36:08 +000040class OMPDependClause;
Alexey Bataev18095712014-10-10 12:19:54 +000041class OMPExecutableDirective;
Alexey Bataev7292c292016-04-25 12:22:29 +000042class OMPLoopDirective;
Alexey Bataev18095712014-10-10 12:19:54 +000043class VarDecl;
Alexey Bataevc5b1d322016-03-04 09:22:22 +000044class OMPDeclareReductionDecl;
45class IdentifierInfo;
Alexey Bataev18095712014-10-10 12:19:54 +000046
Alexey Bataev9959db52014-05-06 10:08:46 +000047namespace CodeGen {
John McCall7f416cc2015-09-08 08:05:57 +000048class Address;
Alexey Bataev18095712014-10-10 12:19:54 +000049class CodeGenFunction;
50class CodeGenModule;
Alexey Bataev9959db52014-05-06 10:08:46 +000051
Alexey Bataev14fa1c62016-03-29 05:34:15 +000052/// A basic class for pre|post-action for advanced codegen sequence for OpenMP
53/// region.
54class PrePostActionTy {
55public:
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.
64class 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
77public:
78 template <typename Callable>
79 RegionCodeGenTy(
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};
Alexey Bataev6f1ffc02015-04-10 04:50:10 +000090
Alexey Bataev24b5bae2016-04-28 09:23:51 +000091struct OMPTaskDataTy final {
92 SmallVector<const Expr *, 4> PrivateVars;
93 SmallVector<const Expr *, 4> PrivateCopies;
94 SmallVector<const Expr *, 4> FirstprivateVars;
95 SmallVector<const Expr *, 4> FirstprivateCopies;
96 SmallVector<const Expr *, 4> FirstprivateInits;
Alexey Bataevf93095a2016-05-05 08:46:22 +000097 SmallVector<const Expr *, 4> LastprivateVars;
98 SmallVector<const Expr *, 4> LastprivateCopies;
Alexey Bataev24b5bae2016-04-28 09:23:51 +000099 SmallVector<std::pair<OpenMPDependClauseKind, const Expr *>, 4> Dependences;
100 llvm::PointerIntPair<llvm::Value *, 1, bool> Final;
101 llvm::PointerIntPair<llvm::Value *, 1, bool> Schedule;
Alexey Bataev1e1e2862016-05-10 12:21:02 +0000102 llvm::PointerIntPair<llvm::Value *, 1, bool> Priority;
Alexey Bataev24b5bae2016-04-28 09:23:51 +0000103 unsigned NumberOfParts = 0;
104 bool Tied = true;
105 bool Nogroup = false;
106};
107
Alexey Bataev9959db52014-05-06 10:08:46 +0000108class CGOpenMPRuntime {
Arpith Chacko Jacob5c309e42016-03-22 01:48:56 +0000109protected:
Alexey Bataev9959db52014-05-06 10:08:46 +0000110 CodeGenModule &CGM;
Arpith Chacko Jacob5c309e42016-03-22 01:48:56 +0000111
112 /// \brief Creates offloading entry for the provided entry ID \a ID,
Samuel Antaof83efdb2017-01-05 16:02:49 +0000113 /// address \a Addr, size \a Size, and flags \a Flags.
Arpith Chacko Jacob5c309e42016-03-22 01:48:56 +0000114 virtual void createOffloadEntry(llvm::Constant *ID, llvm::Constant *Addr,
Samuel Antaof83efdb2017-01-05 16:02:49 +0000115 uint64_t Size, int32_t Flags = 0);
Arpith Chacko Jacob5c309e42016-03-22 01:48:56 +0000116
117 /// \brief Helper to emit outlined function for 'target' directive.
118 /// \param D Directive to emit.
119 /// \param ParentName Name of the function that encloses the target region.
120 /// \param OutlinedFn Outlined function value to be defined by this call.
121 /// \param OutlinedFnID Outlined function ID value to be defined by this call.
122 /// \param IsOffloadEntry True if the outlined function is an offload entry.
123 /// \param CodeGen Lambda codegen specific to an accelerator device.
124 /// An oulined function may not be an entry if, e.g. the if clause always
125 /// evaluates to false.
126 virtual void emitTargetOutlinedFunctionHelper(const OMPExecutableDirective &D,
127 StringRef ParentName,
128 llvm::Function *&OutlinedFn,
129 llvm::Constant *&OutlinedFnID,
130 bool IsOffloadEntry,
131 const RegionCodeGenTy &CodeGen);
132
Arpith Chacko Jacobbb36fe82017-01-10 15:42:51 +0000133 /// \brief Emits code for OpenMP 'if' clause using specified \a CodeGen
134 /// function. Here is the logic:
135 /// if (Cond) {
136 /// ThenGen();
137 /// } else {
138 /// ElseGen();
139 /// }
140 void emitOMPIfClause(CodeGenFunction &CGF, const Expr *Cond,
141 const RegionCodeGenTy &ThenGen,
142 const RegionCodeGenTy &ElseGen);
143
144 /// \brief Emits object of ident_t type with info for source location.
145 /// \param Flags Flags for OpenMP location.
146 ///
147 llvm::Value *emitUpdateLocation(CodeGenFunction &CGF, SourceLocation Loc,
148 unsigned Flags = 0);
149
150 /// \brief Returns pointer to ident_t type.
151 llvm::Type *getIdentTyPointerTy();
152
153 /// \brief Gets thread id value for the current thread.
154 ///
155 llvm::Value *getThreadID(CodeGenFunction &CGF, SourceLocation Loc);
156
157 /// \brief Get the function name of an outlined region.
158 // The name can be customized depending on the target.
159 //
160 virtual StringRef getOutlinedHelperName() const { return ".omp_outlined."; }
161
Arpith Chacko Jacob5c309e42016-03-22 01:48:56 +0000162private:
Alexey Bataev9959db52014-05-06 10:08:46 +0000163 /// \brief Default const ident_t object used for initialization of all other
164 /// ident_t objects.
Alexey Bataevc5b1d322016-03-04 09:22:22 +0000165 llvm::Constant *DefaultOpenMPPSource = nullptr;
Alexey Bataev18095712014-10-10 12:19:54 +0000166 /// \brief Map of flags and corresponding default locations.
Alexey Bataev15007ba2014-05-07 06:18:01 +0000167 typedef llvm::DenseMap<unsigned, llvm::Value *> OpenMPDefaultLocMapTy;
168 OpenMPDefaultLocMapTy OpenMPDefaultLocMap;
Alexey Bataev50b3c952016-02-19 10:38:26 +0000169 Address getOrCreateDefaultLocation(unsigned Flags);
John McCall7f416cc2015-09-08 08:05:57 +0000170
Alexey Bataev14fa1c62016-03-29 05:34:15 +0000171 llvm::StructType *IdentTy = nullptr;
Alexey Bataev18095712014-10-10 12:19:54 +0000172 /// \brief Map for SourceLocation and OpenMP runtime library debug locations.
Alexey Bataevf002aca2014-05-30 05:48:40 +0000173 typedef llvm::DenseMap<unsigned, llvm::Value *> OpenMPDebugLocMapTy;
174 OpenMPDebugLocMapTy OpenMPDebugLocMap;
Alexey Bataev9959db52014-05-06 10:08:46 +0000175 /// \brief The type for a microtask which gets passed to __kmpc_fork_call().
176 /// Original representation is:
177 /// typedef void (kmpc_micro)(kmp_int32 global_tid, kmp_int32 bound_tid,...);
Alexey Bataev14fa1c62016-03-29 05:34:15 +0000178 llvm::FunctionType *Kmpc_MicroTy = nullptr;
Alexey Bataev18095712014-10-10 12:19:54 +0000179 /// \brief Stores debug location and ThreadID for the function.
180 struct DebugLocThreadIdTy {
181 llvm::Value *DebugLoc;
182 llvm::Value *ThreadID;
183 };
184 /// \brief Map of local debug location, ThreadId and functions.
185 typedef llvm::DenseMap<llvm::Function *, DebugLocThreadIdTy>
186 OpenMPLocThreadIDMapTy;
187 OpenMPLocThreadIDMapTy OpenMPLocThreadIDMap;
Alexey Bataevc5b1d322016-03-04 09:22:22 +0000188 /// Map of UDRs and corresponding combiner/initializer.
189 typedef llvm::DenseMap<const OMPDeclareReductionDecl *,
190 std::pair<llvm::Function *, llvm::Function *>>
191 UDRMapTy;
192 UDRMapTy UDRMap;
193 /// Map of functions and locally defined UDRs.
194 typedef llvm::DenseMap<llvm::Function *,
195 SmallVector<const OMPDeclareReductionDecl *, 4>>
196 FunctionUDRMapTy;
197 FunctionUDRMapTy FunctionUDRMap;
198 IdentifierInfo *In = nullptr;
199 IdentifierInfo *Out = nullptr;
200 IdentifierInfo *Priv = nullptr;
201 IdentifierInfo *Orig = nullptr;
Alexey Bataev3a3bf0b2014-09-22 10:01:53 +0000202 /// \brief Type kmp_critical_name, originally defined as typedef kmp_int32
203 /// kmp_critical_name[8];
204 llvm::ArrayType *KmpCriticalNameTy;
Alexey Bataev97720002014-11-11 04:05:39 +0000205 /// \brief An ordered map of auto-generated variables to their unique names.
206 /// It stores variables with the following names: 1) ".gomp_critical_user_" +
207 /// <critical_section_name> + ".var" for "omp critical" directives; 2)
208 /// <mangled_name_for_global_var> + ".cache." for cache for threadprivate
209 /// variables.
210 llvm::StringMap<llvm::AssertingVH<llvm::Constant>, llvm::BumpPtrAllocator>
211 InternalVars;
Alexey Bataev62b63b12015-03-10 07:28:44 +0000212 /// \brief Type typedef kmp_int32 (* kmp_routine_entry_t)(kmp_int32, void *);
Alexey Bataevc5b1d322016-03-04 09:22:22 +0000213 llvm::Type *KmpRoutineEntryPtrTy = nullptr;
Alexey Bataev62b63b12015-03-10 07:28:44 +0000214 QualType KmpRoutineEntryPtrQTy;
Alexey Bataev8fc69dc2015-05-18 07:54:53 +0000215 /// \brief Type typedef struct kmp_task {
216 /// void * shareds; /**< pointer to block of pointers to
217 /// shared vars */
218 /// kmp_routine_entry_t routine; /**< pointer to routine to call for
219 /// executing task */
220 /// kmp_int32 part_id; /**< part id for the task */
221 /// kmp_routine_entry_t destructors; /* pointer to function to invoke
222 /// deconstructors of firstprivate C++ objects */
223 /// } kmp_task_t;
224 QualType KmpTaskTQTy;
Alexey Bataev1d2353d2015-06-24 11:01:36 +0000225 /// \brief Type typedef struct kmp_depend_info {
226 /// kmp_intptr_t base_addr;
227 /// size_t len;
228 /// struct {
229 /// bool in:1;
230 /// bool out:1;
231 /// } flags;
232 /// } kmp_depend_info_t;
233 QualType KmpDependInfoTy;
Alexey Bataev8b427062016-05-25 12:36:08 +0000234 /// struct kmp_dim { // loop bounds info casted to kmp_int64
235 /// kmp_int64 lo; // lower
236 /// kmp_int64 up; // upper
237 /// kmp_int64 st; // stride
238 /// };
239 QualType KmpDimTy;
Samuel Antaoee8fb302016-01-06 13:42:12 +0000240 /// \brief Type struct __tgt_offload_entry{
241 /// void *addr; // Pointer to the offload entry info.
242 /// // (function or global)
243 /// char *name; // Name of the function or global.
244 /// size_t size; // Size of the entry info (0 if it a function).
245 /// };
246 QualType TgtOffloadEntryQTy;
247 /// struct __tgt_device_image{
248 /// void *ImageStart; // Pointer to the target code start.
249 /// void *ImageEnd; // Pointer to the target code end.
250 /// // We also add the host entries to the device image, as it may be useful
251 /// // for the target runtime to have access to that information.
252 /// __tgt_offload_entry *EntriesBegin; // Begin of the table with all
253 /// // the entries.
254 /// __tgt_offload_entry *EntriesEnd; // End of the table with all the
255 /// // entries (non inclusive).
256 /// };
257 QualType TgtDeviceImageQTy;
258 /// struct __tgt_bin_desc{
259 /// int32_t NumDevices; // Number of devices supported.
260 /// __tgt_device_image *DeviceImages; // Arrays of device images
261 /// // (one per device).
262 /// __tgt_offload_entry *EntriesBegin; // Begin of the table with all the
263 /// // entries.
264 /// __tgt_offload_entry *EntriesEnd; // End of the table with all the
265 /// // entries (non inclusive).
266 /// };
267 QualType TgtBinaryDescriptorQTy;
268 /// \brief Entity that registers the offloading constants that were emitted so
269 /// far.
270 class OffloadEntriesInfoManagerTy {
271 CodeGenModule &CGM;
Alexey Bataev1d2353d2015-06-24 11:01:36 +0000272
Samuel Antaoee8fb302016-01-06 13:42:12 +0000273 /// \brief Number of entries registered so far.
274 unsigned OffloadingEntriesNum;
275
276 public:
Samuel Antaof83efdb2017-01-05 16:02:49 +0000277 /// Base class of the entries info.
Samuel Antaoee8fb302016-01-06 13:42:12 +0000278 class OffloadEntryInfo {
279 public:
Samuel Antaof83efdb2017-01-05 16:02:49 +0000280 /// Kind of a given entry. Currently, only target regions are
Samuel Antaoee8fb302016-01-06 13:42:12 +0000281 /// supported.
Reid Klecknerdc78f952016-01-11 20:55:16 +0000282 enum OffloadingEntryInfoKinds : unsigned {
Samuel Antaoee8fb302016-01-06 13:42:12 +0000283 // Entry is a target region.
284 OFFLOAD_ENTRY_INFO_TARGET_REGION = 0,
285 // Invalid entry info.
286 OFFLOAD_ENTRY_INFO_INVALID = ~0u
287 };
288
Samuel Antaof83efdb2017-01-05 16:02:49 +0000289 OffloadEntryInfo()
290 : Flags(0), Order(~0u), Kind(OFFLOAD_ENTRY_INFO_INVALID) {}
291 explicit OffloadEntryInfo(OffloadingEntryInfoKinds Kind, unsigned Order,
292 int32_t Flags)
293 : Flags(Flags), Order(Order), Kind(Kind) {}
Samuel Antaoee8fb302016-01-06 13:42:12 +0000294
295 bool isValid() const { return Order != ~0u; }
296 unsigned getOrder() const { return Order; }
297 OffloadingEntryInfoKinds getKind() const { return Kind; }
Samuel Antaof83efdb2017-01-05 16:02:49 +0000298 int32_t getFlags() const { return Flags; }
299 void setFlags(int32_t NewFlags) { Flags = NewFlags; }
Samuel Antaoee8fb302016-01-06 13:42:12 +0000300 static bool classof(const OffloadEntryInfo *Info) { return true; }
301
Samuel Antaof83efdb2017-01-05 16:02:49 +0000302 private:
303 /// Flags associated with the device global.
304 int32_t Flags;
305
306 /// Order this entry was emitted.
Samuel Antaoee8fb302016-01-06 13:42:12 +0000307 unsigned Order;
308
309 OffloadingEntryInfoKinds Kind;
310 };
311
312 /// \brief Return true if a there are no entries defined.
313 bool empty() const;
314 /// \brief Return number of entries defined so far.
315 unsigned size() const { return OffloadingEntriesNum; }
316 OffloadEntriesInfoManagerTy(CodeGenModule &CGM)
317 : CGM(CGM), OffloadingEntriesNum(0) {}
318
319 ///
320 /// Target region entries related.
321 ///
322 /// \brief Target region entries info.
323 class OffloadEntryInfoTargetRegion : public OffloadEntryInfo {
324 // \brief Address of the entity that has to be mapped for offloading.
325 llvm::Constant *Addr;
326 // \brief Address that can be used as the ID of the entry.
327 llvm::Constant *ID;
328
329 public:
330 OffloadEntryInfoTargetRegion()
Samuel Antaof83efdb2017-01-05 16:02:49 +0000331 : OffloadEntryInfo(OFFLOAD_ENTRY_INFO_TARGET_REGION, ~0u,
332 /*Flags=*/0),
Samuel Antaoee8fb302016-01-06 13:42:12 +0000333 Addr(nullptr), ID(nullptr) {}
334 explicit OffloadEntryInfoTargetRegion(unsigned Order,
335 llvm::Constant *Addr,
Samuel Antaof83efdb2017-01-05 16:02:49 +0000336 llvm::Constant *ID, int32_t Flags)
337 : OffloadEntryInfo(OFFLOAD_ENTRY_INFO_TARGET_REGION, Order, Flags),
Samuel Antaoee8fb302016-01-06 13:42:12 +0000338 Addr(Addr), ID(ID) {}
339
340 llvm::Constant *getAddress() const { return Addr; }
341 llvm::Constant *getID() const { return ID; }
342 void setAddress(llvm::Constant *V) {
343 assert(!Addr && "Address as been set before!");
344 Addr = V;
345 }
346 void setID(llvm::Constant *V) {
347 assert(!ID && "ID as been set before!");
348 ID = V;
349 }
350 static bool classof(const OffloadEntryInfo *Info) {
351 return Info->getKind() == OFFLOAD_ENTRY_INFO_TARGET_REGION;
352 }
353 };
354 /// \brief Initialize target region entry.
355 void initializeTargetRegionEntryInfo(unsigned DeviceID, unsigned FileID,
356 StringRef ParentName, unsigned LineNum,
Samuel Antao2de62b02016-02-13 23:35:10 +0000357 unsigned Order);
Samuel Antaoee8fb302016-01-06 13:42:12 +0000358 /// \brief Register target region entry.
359 void registerTargetRegionEntryInfo(unsigned DeviceID, unsigned FileID,
360 StringRef ParentName, unsigned LineNum,
Samuel Antaof83efdb2017-01-05 16:02:49 +0000361 llvm::Constant *Addr, llvm::Constant *ID,
362 int32_t Flags);
Samuel Antaoee8fb302016-01-06 13:42:12 +0000363 /// \brief Return true if a target region entry with the provided
364 /// information exists.
365 bool hasTargetRegionEntryInfo(unsigned DeviceID, unsigned FileID,
Samuel Antao2de62b02016-02-13 23:35:10 +0000366 StringRef ParentName, unsigned LineNum) const;
Samuel Antaoee8fb302016-01-06 13:42:12 +0000367 /// brief Applies action \a Action on all registered entries.
368 typedef llvm::function_ref<void(unsigned, unsigned, StringRef, unsigned,
Samuel Antao2de62b02016-02-13 23:35:10 +0000369 OffloadEntryInfoTargetRegion &)>
Samuel Antaoee8fb302016-01-06 13:42:12 +0000370 OffloadTargetRegionEntryInfoActTy;
371 void actOnTargetRegionEntriesInfo(
372 const OffloadTargetRegionEntryInfoActTy &Action);
373
374 private:
375 // Storage for target region entries kind. The storage is to be indexed by
Samuel Antao2de62b02016-02-13 23:35:10 +0000376 // file ID, device ID, parent function name and line number.
Samuel Antaoee8fb302016-01-06 13:42:12 +0000377 typedef llvm::DenseMap<unsigned, OffloadEntryInfoTargetRegion>
Samuel Antaoee8fb302016-01-06 13:42:12 +0000378 OffloadEntriesTargetRegionPerLine;
379 typedef llvm::StringMap<OffloadEntriesTargetRegionPerLine>
380 OffloadEntriesTargetRegionPerParentName;
381 typedef llvm::DenseMap<unsigned, OffloadEntriesTargetRegionPerParentName>
382 OffloadEntriesTargetRegionPerFile;
383 typedef llvm::DenseMap<unsigned, OffloadEntriesTargetRegionPerFile>
384 OffloadEntriesTargetRegionPerDevice;
385 typedef OffloadEntriesTargetRegionPerDevice OffloadEntriesTargetRegionTy;
386 OffloadEntriesTargetRegionTy OffloadEntriesTargetRegion;
387 };
388 OffloadEntriesInfoManagerTy OffloadEntriesInfoManager;
389
390 /// \brief Creates and registers offloading binary descriptor for the current
391 /// compilation unit. The function that does the registration is returned.
392 llvm::Function *createOffloadingBinaryDescriptorRegistration();
393
Samuel Antaoee8fb302016-01-06 13:42:12 +0000394 /// \brief Creates all the offload entries in the current compilation unit
395 /// along with the associated metadata.
396 void createOffloadEntriesAndInfoMetadata();
397
398 /// \brief Loads all the offload entries information from the host IR
399 /// metadata.
400 void loadOffloadInfoMetadata();
401
402 /// \brief Returns __tgt_offload_entry type.
403 QualType getTgtOffloadEntryQTy();
404
405 /// \brief Returns __tgt_device_image type.
406 QualType getTgtDeviceImageQTy();
407
408 /// \brief Returns __tgt_bin_desc type.
409 QualType getTgtBinaryDescriptorQTy();
410
411 /// \brief Start scanning from statement \a S and and emit all target regions
412 /// found along the way.
413 /// \param S Starting statement.
414 /// \param ParentName Name of the function declaration that is being scanned.
415 void scanForTargetRegionsFunctions(const Stmt *S, StringRef ParentName);
Alexey Bataev62b63b12015-03-10 07:28:44 +0000416
417 /// \brief Build type kmp_routine_entry_t (if not built yet).
418 void emitKmpRoutineEntryT(QualType KmpInt32Ty);
Alexey Bataev9959db52014-05-06 10:08:46 +0000419
Alexey Bataevd74d0602014-10-13 06:02:40 +0000420 /// \brief Returns pointer to kmpc_micro type.
Alexey Bataev9959db52014-05-06 10:08:46 +0000421 llvm::Type *getKmpc_MicroPointerTy();
422
423 /// \brief Returns specified OpenMP runtime function.
424 /// \param Function OpenMP runtime function.
425 /// \return Specified function.
Alexey Bataev50b3c952016-02-19 10:38:26 +0000426 llvm::Constant *createRuntimeFunction(unsigned Function);
Alexey Bataev3a3bf0b2014-09-22 10:01:53 +0000427
Alexander Musman21212e42015-03-13 10:38:23 +0000428 /// \brief Returns __kmpc_for_static_init_* runtime function for the specified
429 /// size \a IVSize and sign \a IVSigned.
430 llvm::Constant *createForStaticInitFunction(unsigned IVSize, bool IVSigned);
431
Alexander Musman92bdaab2015-03-12 13:37:50 +0000432 /// \brief Returns __kmpc_dispatch_init_* runtime function for the specified
433 /// size \a IVSize and sign \a IVSigned.
434 llvm::Constant *createDispatchInitFunction(unsigned IVSize, bool IVSigned);
435
436 /// \brief Returns __kmpc_dispatch_next_* runtime function for the specified
437 /// size \a IVSize and sign \a IVSigned.
438 llvm::Constant *createDispatchNextFunction(unsigned IVSize, bool IVSigned);
439
Alexey Bataev98eb6e32015-04-22 11:15:40 +0000440 /// \brief Returns __kmpc_dispatch_fini_* runtime function for the specified
441 /// size \a IVSize and sign \a IVSigned.
442 llvm::Constant *createDispatchFiniFunction(unsigned IVSize, bool IVSigned);
443
Alexey Bataev97720002014-11-11 04:05:39 +0000444 /// \brief If the specified mangled name is not in the module, create and
445 /// return threadprivate cache object. This object is a pointer's worth of
446 /// storage that's reserved for use by the OpenMP runtime.
NAKAMURA Takumicdcbfba2014-11-11 07:58:06 +0000447 /// \param VD Threadprivate variable.
Alexey Bataev97720002014-11-11 04:05:39 +0000448 /// \return Cache variable for the specified threadprivate.
449 llvm::Constant *getOrCreateThreadPrivateCache(const VarDecl *VD);
450
Alexey Bataevd74d0602014-10-13 06:02:40 +0000451 /// \brief Emits address of the word in a memory where current thread id is
452 /// stored.
John McCall7f416cc2015-09-08 08:05:57 +0000453 virtual Address emitThreadIDAddress(CodeGenFunction &CGF, SourceLocation Loc);
Alexey Bataevd74d0602014-10-13 06:02:40 +0000454
Alexey Bataev97720002014-11-11 04:05:39 +0000455 /// \brief Gets (if variable with the given name already exist) or creates
456 /// internal global variable with the specified Name. The created variable has
457 /// linkage CommonLinkage by default and is initialized by null value.
458 /// \param Ty Type of the global variable. If it is exist already the type
459 /// must be the same.
460 /// \param Name Name of the variable.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000461 llvm::Constant *getOrCreateInternalVariable(llvm::Type *Ty,
Alexey Bataev97720002014-11-11 04:05:39 +0000462 const llvm::Twine &Name);
463
464 /// \brief Set of threadprivate variables with the generated initializer.
Benjamin Kramer8fdba912016-02-02 14:24:21 +0000465 llvm::SmallPtrSet<const VarDecl *, 4> ThreadPrivateWithDefinition;
Alexey Bataev97720002014-11-11 04:05:39 +0000466
467 /// \brief Emits initialization code for the threadprivate variables.
468 /// \param VDAddr Address of the global variable \a VD.
469 /// \param Ctor Pointer to a global init function for \a VD.
470 /// \param CopyCtor Pointer to a global copy function for \a VD.
471 /// \param Dtor Pointer to a global destructor function for \a VD.
472 /// \param Loc Location of threadprivate declaration.
John McCall7f416cc2015-09-08 08:05:57 +0000473 void emitThreadPrivateVarInit(CodeGenFunction &CGF, Address VDAddr,
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000474 llvm::Value *Ctor, llvm::Value *CopyCtor,
475 llvm::Value *Dtor, SourceLocation Loc);
Alexey Bataev97720002014-11-11 04:05:39 +0000476
Alexey Bataev75ddfab2014-12-01 11:32:38 +0000477 /// \brief Returns corresponding lock object for the specified critical region
478 /// name. If the lock object does not exist it is created, otherwise the
479 /// reference to the existing copy is returned.
480 /// \param CriticalName Name of the critical region.
481 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000482 llvm::Value *getCriticalRegionLock(StringRef CriticalName);
Alexey Bataev75ddfab2014-12-01 11:32:38 +0000483
Alexey Bataev24b5bae2016-04-28 09:23:51 +0000484 struct TaskResultTy {
485 llvm::Value *NewTask = nullptr;
486 llvm::Value *TaskEntry = nullptr;
487 llvm::Value *NewTaskNewTaskTTy = nullptr;
Alexey Bataev7292c292016-04-25 12:22:29 +0000488 LValue TDBase;
Alexey Bataev24b5bae2016-04-28 09:23:51 +0000489 RecordDecl *KmpTaskTQTyRD = nullptr;
Alexey Bataevf93095a2016-05-05 08:46:22 +0000490 llvm::Value *TaskDupFn = nullptr;
Alexey Bataev7292c292016-04-25 12:22:29 +0000491 };
492 /// Emit task region for the task directive. The task region is emitted in
493 /// several steps:
494 /// 1. Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32
495 /// gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds,
496 /// kmp_routine_entry_t *task_entry). Here task_entry is a pointer to the
497 /// function:
498 /// kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) {
499 /// TaskFunction(gtid, tt->part_id, tt->shareds);
500 /// return 0;
501 /// }
502 /// 2. Copy a list of shared variables to field shareds of the resulting
503 /// structure kmp_task_t returned by the previous call (if any).
504 /// 3. Copy a pointer to destructions function to field destructions of the
505 /// resulting structure kmp_task_t.
506 /// \param D Current task directive.
Alexey Bataev7292c292016-04-25 12:22:29 +0000507 /// \param TaskFunction An LLVM function with type void (*)(i32 /*gtid*/, i32
508 /// /*part_id*/, captured_struct */*__context*/);
509 /// \param SharedsTy A type which contains references the shared variables.
510 /// \param Shareds Context with the list of shared variables from the \p
511 /// TaskFunction.
Alexey Bataev24b5bae2016-04-28 09:23:51 +0000512 /// \param Data Additional data for task generation like tiednsee, final
513 /// state, list of privates etc.
514 TaskResultTy emitTaskInit(CodeGenFunction &CGF, SourceLocation Loc,
515 const OMPExecutableDirective &D,
516 llvm::Value *TaskFunction, QualType SharedsTy,
517 Address Shareds, const OMPTaskDataTy &Data);
Alexey Bataev7292c292016-04-25 12:22:29 +0000518
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000519public:
520 explicit CGOpenMPRuntime(CodeGenModule &CGM);
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +0000521 virtual ~CGOpenMPRuntime() {}
Alexey Bataev91797552015-03-18 04:13:55 +0000522 virtual void clear();
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000523
Alexey Bataevc5b1d322016-03-04 09:22:22 +0000524 /// Emit code for the specified user defined reduction construct.
525 virtual void emitUserDefinedReduction(CodeGenFunction *CGF,
526 const OMPDeclareReductionDecl *D);
Alexey Bataeva839ddd2016-03-17 10:19:46 +0000527 /// Get combiner/initializer for the specified user-defined reduction, if any.
528 virtual std::pair<llvm::Function *, llvm::Function *>
529 getUserDefinedReduction(const OMPDeclareReductionDecl *D);
Arpith Chacko Jacob19b911c2017-01-18 18:18:53 +0000530
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000531 /// \brief Emits outlined function for the specified OpenMP parallel directive
532 /// \a D. This outlined function has type void(*)(kmp_int32 *ThreadID,
533 /// kmp_int32 BoundID, struct context_vars*).
Alexey Bataev18095712014-10-10 12:19:54 +0000534 /// \param D OpenMP directive.
535 /// \param ThreadIDVar Variable for thread id in the current OpenMP region.
Alexey Bataev81c7ea02015-07-03 09:56:58 +0000536 /// \param InnermostKind Kind of innermost directive (for simple directives it
537 /// is a directive itself, for combined - its innermost directive).
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000538 /// \param CodeGen Code generation sequence for the \a D directive.
Arpith Chacko Jacob19b911c2017-01-18 18:18:53 +0000539 virtual llvm::Value *emitParallelOutlinedFunction(
540 const OMPExecutableDirective &D, const VarDecl *ThreadIDVar,
541 OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen);
542
543 /// \brief Emits outlined function for the specified OpenMP teams directive
544 /// \a D. This outlined function has type void(*)(kmp_int32 *ThreadID,
545 /// kmp_int32 BoundID, struct context_vars*).
546 /// \param D OpenMP directive.
547 /// \param ThreadIDVar Variable for thread id in the current OpenMP region.
548 /// \param InnermostKind Kind of innermost directive (for simple directives it
549 /// is a directive itself, for combined - its innermost directive).
550 /// \param CodeGen Code generation sequence for the \a D directive.
551 virtual llvm::Value *emitTeamsOutlinedFunction(
Alexey Bataev81c7ea02015-07-03 09:56:58 +0000552 const OMPExecutableDirective &D, const VarDecl *ThreadIDVar,
553 OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen);
Alexey Bataev18095712014-10-10 12:19:54 +0000554
Alexey Bataev62b63b12015-03-10 07:28:44 +0000555 /// \brief Emits outlined function for the OpenMP task directive \a D. This
Alexey Bataev48591dd2016-04-20 04:01:36 +0000556 /// outlined function has type void(*)(kmp_int32 ThreadID, struct task_t*
557 /// TaskT).
Alexey Bataev62b63b12015-03-10 07:28:44 +0000558 /// \param D OpenMP directive.
559 /// \param ThreadIDVar Variable for thread id in the current OpenMP region.
Alexey Bataev48591dd2016-04-20 04:01:36 +0000560 /// \param PartIDVar Variable for partition id in the current OpenMP untied
561 /// task region.
562 /// \param TaskTVar Variable for task_t argument.
Alexey Bataev81c7ea02015-07-03 09:56:58 +0000563 /// \param InnermostKind Kind of innermost directive (for simple directives it
564 /// is a directive itself, for combined - its innermost directive).
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000565 /// \param CodeGen Code generation sequence for the \a D directive.
Alexey Bataev48591dd2016-04-20 04:01:36 +0000566 /// \param Tied true if task is generated for tied task, false otherwise.
567 /// \param NumberOfParts Number of parts in untied task. Ignored for tied
568 /// tasks.
Alexey Bataev62b63b12015-03-10 07:28:44 +0000569 ///
Alexey Bataev81c7ea02015-07-03 09:56:58 +0000570 virtual llvm::Value *emitTaskOutlinedFunction(
571 const OMPExecutableDirective &D, const VarDecl *ThreadIDVar,
Alexey Bataev48591dd2016-04-20 04:01:36 +0000572 const VarDecl *PartIDVar, const VarDecl *TaskTVar,
573 OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen,
574 bool Tied, unsigned &NumberOfParts);
Alexey Bataev62b63b12015-03-10 07:28:44 +0000575
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000576 /// \brief Cleans up references to the objects in finished function.
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000577 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000578 void functionFinished(CodeGenFunction &CGF);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000579
Alexey Bataev1d677132015-04-22 13:57:31 +0000580 /// \brief Emits code for parallel or serial call of the \a OutlinedFn with
581 /// variables captured in a record which address is stored in \a
582 /// CapturedStruct.
Alexey Bataev18095712014-10-10 12:19:54 +0000583 /// \param OutlinedFn Outlined function to be run in parallel threads. Type of
Alexey Bataev62b63b12015-03-10 07:28:44 +0000584 /// this function is void(*)(kmp_int32 *, kmp_int32, struct context_vars*).
NAKAMURA Takumi62f0eb52015-09-11 08:13:32 +0000585 /// \param CapturedVars A pointer to the record with the references to
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000586 /// variables used in \a OutlinedFn function.
Alexey Bataev1d677132015-04-22 13:57:31 +0000587 /// \param IfCond Condition in the associated 'if' clause, if it was
588 /// specified, nullptr otherwise.
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000589 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000590 virtual void emitParallelCall(CodeGenFunction &CGF, SourceLocation Loc,
591 llvm::Value *OutlinedFn,
Alexey Bataev2377fe92015-09-10 08:12:02 +0000592 ArrayRef<llvm::Value *> CapturedVars,
593 const Expr *IfCond);
Alexey Bataevd74d0602014-10-13 06:02:40 +0000594
Alexey Bataev75ddfab2014-12-01 11:32:38 +0000595 /// \brief Emits a critical region.
Alexey Bataev18095712014-10-10 12:19:54 +0000596 /// \param CriticalName Name of the critical region.
Alexey Bataev75ddfab2014-12-01 11:32:38 +0000597 /// \param CriticalOpGen Generator for the statement associated with the given
598 /// critical region.
Alexey Bataevfc57d162015-12-15 10:55:09 +0000599 /// \param Hint Value of the 'hint' clause (optional).
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000600 virtual void emitCriticalRegion(CodeGenFunction &CGF, StringRef CriticalName,
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000601 const RegionCodeGenTy &CriticalOpGen,
Alexey Bataevfc57d162015-12-15 10:55:09 +0000602 SourceLocation Loc,
603 const Expr *Hint = nullptr);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000604
Alexey Bataev8d690652014-12-04 07:23:53 +0000605 /// \brief Emits a master region.
606 /// \param MasterOpGen Generator for the statement associated with the given
607 /// master region.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000608 virtual void emitMasterRegion(CodeGenFunction &CGF,
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000609 const RegionCodeGenTy &MasterOpGen,
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000610 SourceLocation Loc);
Alexey Bataev8d690652014-12-04 07:23:53 +0000611
Alexey Bataev9f797f32015-02-05 05:57:51 +0000612 /// \brief Emits code for a taskyield directive.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000613 virtual void emitTaskyieldCall(CodeGenFunction &CGF, SourceLocation Loc);
Alexey Bataev9f797f32015-02-05 05:57:51 +0000614
Alexey Bataevc30dd2d2015-06-18 12:14:09 +0000615 /// \brief Emit a taskgroup region.
616 /// \param TaskgroupOpGen Generator for the statement associated with the
617 /// given taskgroup region.
618 virtual void emitTaskgroupRegion(CodeGenFunction &CGF,
619 const RegionCodeGenTy &TaskgroupOpGen,
620 SourceLocation Loc);
621
Alexey Bataev6956e2e2015-02-05 06:35:41 +0000622 /// \brief Emits a single region.
623 /// \param SingleOpGen Generator for the statement associated with the given
624 /// single region.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000625 virtual void emitSingleRegion(CodeGenFunction &CGF,
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000626 const RegionCodeGenTy &SingleOpGen,
Alexey Bataeva63048e2015-03-23 06:18:07 +0000627 SourceLocation Loc,
628 ArrayRef<const Expr *> CopyprivateVars,
Alexey Bataev420d45b2015-04-14 05:11:24 +0000629 ArrayRef<const Expr *> DestExprs,
Alexey Bataeva63048e2015-03-23 06:18:07 +0000630 ArrayRef<const Expr *> SrcExprs,
Alexey Bataeva63048e2015-03-23 06:18:07 +0000631 ArrayRef<const Expr *> AssignmentOps);
Alexey Bataev6956e2e2015-02-05 06:35:41 +0000632
Alexey Bataev98eb6e32015-04-22 11:15:40 +0000633 /// \brief Emit an ordered region.
634 /// \param OrderedOpGen Generator for the statement associated with the given
Alexey Bataevc30dd2d2015-06-18 12:14:09 +0000635 /// ordered region.
Alexey Bataev98eb6e32015-04-22 11:15:40 +0000636 virtual void emitOrderedRegion(CodeGenFunction &CGF,
637 const RegionCodeGenTy &OrderedOpGen,
Alexey Bataev5f600d62015-09-29 03:48:57 +0000638 SourceLocation Loc, bool IsThreads);
Alexey Bataev98eb6e32015-04-22 11:15:40 +0000639
Alexey Bataevf2685682015-03-30 04:30:22 +0000640 /// \brief Emit an implicit/explicit barrier for OpenMP threads.
641 /// \param Kind Directive for which this implicit barrier call must be
642 /// generated. Must be OMPD_barrier for explicit barrier generation.
Alexey Bataev25e5b442015-09-15 12:52:43 +0000643 /// \param EmitChecks true if need to emit checks for cancellation barriers.
644 /// \param ForceSimpleCall true simple barrier call must be emitted, false if
645 /// runtime class decides which one to emit (simple or with cancellation
646 /// checks).
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000647 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000648 virtual void emitBarrierCall(CodeGenFunction &CGF, SourceLocation Loc,
Alexey Bataev81c7ea02015-07-03 09:56:58 +0000649 OpenMPDirectiveKind Kind,
Alexey Bataev25e5b442015-09-15 12:52:43 +0000650 bool EmitChecks = true,
651 bool ForceSimpleCall = false);
Alexey Bataevb2059782014-10-13 08:23:51 +0000652
Alexander Musmanc6388682014-12-15 07:07:06 +0000653 /// \brief Check if the specified \a ScheduleKind is static non-chunked.
654 /// This kind of worksharing directive is emitted without outer loop.
655 /// \param ScheduleKind Schedule kind specified in the 'schedule' clause.
656 /// \param Chunked True if chunk is specified in the clause.
657 ///
658 virtual bool isStaticNonchunked(OpenMPScheduleClauseKind ScheduleKind,
659 bool Chunked) const;
660
Carlo Bertollifc35ad22016-03-07 16:04:49 +0000661 /// \brief Check if the specified \a ScheduleKind is static non-chunked.
662 /// This kind of distribute directive is emitted without outer loop.
663 /// \param ScheduleKind Schedule kind specified in the 'dist_schedule' clause.
664 /// \param Chunked True if chunk is specified in the clause.
665 ///
666 virtual bool isStaticNonchunked(OpenMPDistScheduleClauseKind ScheduleKind,
667 bool Chunked) const;
668
Alexander Musmandf7a8e22015-01-22 08:49:35 +0000669 /// \brief Check if the specified \a ScheduleKind is dynamic.
670 /// This kind of worksharing directive is emitted without outer loop.
671 /// \param ScheduleKind Schedule Kind specified in the 'schedule' clause.
672 ///
673 virtual bool isDynamic(OpenMPScheduleClauseKind ScheduleKind) const;
674
NAKAMURA Takumiff7a9252015-09-08 09:42:41 +0000675 virtual void emitForDispatchInit(CodeGenFunction &CGF, SourceLocation Loc,
Alexey Bataev9ebd7422016-05-10 09:57:36 +0000676 const OpenMPScheduleTy &ScheduleKind,
677 unsigned IVSize, bool IVSigned, bool Ordered,
678 llvm::Value *UB,
NAKAMURA Takumiff7a9252015-09-08 09:42:41 +0000679 llvm::Value *Chunk = nullptr);
680
Alexander Musmanc6388682014-12-15 07:07:06 +0000681 /// \brief Call the appropriate runtime routine to initialize it before start
682 /// of loop.
683 ///
684 /// Depending on the loop schedule, it is nesessary to call some runtime
685 /// routine before start of the OpenMP loop to get the loop upper / lower
686 /// bounds \a LB and \a UB and stride \a ST.
687 ///
688 /// \param CGF Reference to current CodeGenFunction.
689 /// \param Loc Clang source location.
Alexey Bataev9ebd7422016-05-10 09:57:36 +0000690 /// \param ScheduleKind Schedule kind, specified by the 'schedule' clause.
Alexander Musmanc6388682014-12-15 07:07:06 +0000691 /// \param IVSize Size of the iteration variable in bits.
692 /// \param IVSigned Sign of the interation variable.
Alexey Bataevd7589ffe2015-05-20 13:12:48 +0000693 /// \param Ordered true if loop is ordered, false otherwise.
Alexander Musmanc6388682014-12-15 07:07:06 +0000694 /// \param IL Address of the output variable in which the flag of the
695 /// last iteration is returned.
696 /// \param LB Address of the output variable in which the lower iteration
697 /// number is returned.
698 /// \param UB Address of the output variable in which the upper iteration
699 /// number is returned.
700 /// \param ST Address of the output variable in which the stride value is
701 /// returned nesessary to generated the static_chunked scheduled loop.
702 /// \param Chunk Value of the chunk for the static_chunked scheduled loop.
703 /// For the default (nullptr) value, the chunk 1 will be used.
704 ///
John McCall7f416cc2015-09-08 08:05:57 +0000705 virtual void emitForStaticInit(CodeGenFunction &CGF, SourceLocation Loc,
Alexey Bataev9ebd7422016-05-10 09:57:36 +0000706 const OpenMPScheduleTy &ScheduleKind,
John McCall7f416cc2015-09-08 08:05:57 +0000707 unsigned IVSize, bool IVSigned, bool Ordered,
Alexey Bataev9ebd7422016-05-10 09:57:36 +0000708 Address IL, Address LB, Address UB, Address ST,
John McCall7f416cc2015-09-08 08:05:57 +0000709 llvm::Value *Chunk = nullptr);
Alexander Musmanc6388682014-12-15 07:07:06 +0000710
Carlo Bertollifc35ad22016-03-07 16:04:49 +0000711 ///
712 /// \param CGF Reference to current CodeGenFunction.
713 /// \param Loc Clang source location.
714 /// \param SchedKind Schedule kind, specified by the 'dist_schedule' clause.
715 /// \param IVSize Size of the iteration variable in bits.
716 /// \param IVSigned Sign of the interation variable.
717 /// \param Ordered true if loop is ordered, false otherwise.
718 /// \param IL Address of the output variable in which the flag of the
719 /// last iteration is returned.
720 /// \param LB Address of the output variable in which the lower iteration
721 /// number is returned.
722 /// \param UB Address of the output variable in which the upper iteration
723 /// number is returned.
724 /// \param ST Address of the output variable in which the stride value is
725 /// returned nesessary to generated the static_chunked scheduled loop.
726 /// \param Chunk Value of the chunk for the static_chunked scheduled loop.
727 /// For the default (nullptr) value, the chunk 1 will be used.
728 ///
729 virtual void emitDistributeStaticInit(CodeGenFunction &CGF, SourceLocation Loc,
730 OpenMPDistScheduleClauseKind SchedKind,
731 unsigned IVSize, bool IVSigned,
732 bool Ordered, Address IL, Address LB,
733 Address UB, Address ST,
734 llvm::Value *Chunk = nullptr);
735
Alexander Musmanc6388682014-12-15 07:07:06 +0000736 /// \brief Call the appropriate runtime routine to notify that we finished
Alexey Bataev98eb6e32015-04-22 11:15:40 +0000737 /// iteration of the ordered loop with the dynamic scheduling.
738 ///
739 /// \param CGF Reference to current CodeGenFunction.
740 /// \param Loc Clang source location.
741 /// \param IVSize Size of the iteration variable in bits.
742 /// \param IVSigned Sign of the interation variable.
743 ///
Alexey Bataevd7589ffe2015-05-20 13:12:48 +0000744 virtual void emitForOrderedIterationEnd(CodeGenFunction &CGF,
745 SourceLocation Loc, unsigned IVSize,
746 bool IVSigned);
Alexey Bataev98eb6e32015-04-22 11:15:40 +0000747
748 /// \brief Call the appropriate runtime routine to notify that we finished
Alexander Musmanc6388682014-12-15 07:07:06 +0000749 /// all the work with current loop.
750 ///
751 /// \param CGF Reference to current CodeGenFunction.
752 /// \param Loc Clang source location.
Alexander Musmanc6388682014-12-15 07:07:06 +0000753 ///
Alexey Bataev98eb6e32015-04-22 11:15:40 +0000754 virtual void emitForStaticFinish(CodeGenFunction &CGF, SourceLocation Loc);
Alexander Musmanc6388682014-12-15 07:07:06 +0000755
Alexander Musman92bdaab2015-03-12 13:37:50 +0000756 /// Call __kmpc_dispatch_next(
757 /// ident_t *loc, kmp_int32 tid, kmp_int32 *p_lastiter,
758 /// kmp_int[32|64] *p_lower, kmp_int[32|64] *p_upper,
759 /// kmp_int[32|64] *p_stride);
760 /// \param IVSize Size of the iteration variable in bits.
761 /// \param IVSigned Sign of the interation variable.
762 /// \param IL Address of the output variable in which the flag of the
763 /// last iteration is returned.
764 /// \param LB Address of the output variable in which the lower iteration
765 /// number is returned.
766 /// \param UB Address of the output variable in which the upper iteration
767 /// number is returned.
768 /// \param ST Address of the output variable in which the stride value is
769 /// returned.
770 virtual llvm::Value *emitForNext(CodeGenFunction &CGF, SourceLocation Loc,
771 unsigned IVSize, bool IVSigned,
John McCall7f416cc2015-09-08 08:05:57 +0000772 Address IL, Address LB,
773 Address UB, Address ST);
Alexander Musman92bdaab2015-03-12 13:37:50 +0000774
Alexey Bataevb2059782014-10-13 08:23:51 +0000775 /// \brief Emits call to void __kmpc_push_num_threads(ident_t *loc, kmp_int32
776 /// global_tid, kmp_int32 num_threads) to generate code for 'num_threads'
777 /// clause.
778 /// \param NumThreads An integer value of threads.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000779 virtual void emitNumThreadsClause(CodeGenFunction &CGF,
780 llvm::Value *NumThreads,
781 SourceLocation Loc);
Alexey Bataev97720002014-11-11 04:05:39 +0000782
Alexey Bataev7f210c62015-06-18 13:40:03 +0000783 /// \brief Emit call to void __kmpc_push_proc_bind(ident_t *loc, kmp_int32
784 /// global_tid, int proc_bind) to generate code for 'proc_bind' clause.
785 virtual void emitProcBindClause(CodeGenFunction &CGF,
786 OpenMPProcBindClauseKind ProcBind,
787 SourceLocation Loc);
788
Alexey Bataev97720002014-11-11 04:05:39 +0000789 /// \brief Returns address of the threadprivate variable for the current
790 /// thread.
NAKAMURA Takumicdcbfba2014-11-11 07:58:06 +0000791 /// \param VD Threadprivate variable.
Alexey Bataev97720002014-11-11 04:05:39 +0000792 /// \param VDAddr Address of the global variable \a VD.
793 /// \param Loc Location of the reference to threadprivate var.
794 /// \return Address of the threadprivate variable for the current thread.
John McCall7f416cc2015-09-08 08:05:57 +0000795 virtual Address getAddrOfThreadPrivate(CodeGenFunction &CGF,
796 const VarDecl *VD,
797 Address VDAddr,
798 SourceLocation Loc);
Alexey Bataev97720002014-11-11 04:05:39 +0000799
800 /// \brief Emit a code for initialization of threadprivate variable. It emits
801 /// a call to runtime library which adds initial value to the newly created
802 /// threadprivate variable (if it is not constant) and registers destructor
803 /// for the variable (if any).
804 /// \param VD Threadprivate variable.
805 /// \param VDAddr Address of the global variable \a VD.
806 /// \param Loc Location of threadprivate declaration.
807 /// \param PerformInit true if initialization expression is not constant.
808 virtual llvm::Function *
John McCall7f416cc2015-09-08 08:05:57 +0000809 emitThreadPrivateVarDefinition(const VarDecl *VD, Address VDAddr,
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000810 SourceLocation Loc, bool PerformInit,
811 CodeGenFunction *CGF = nullptr);
Alexey Bataevcc37cc12014-11-20 04:34:54 +0000812
813 /// \brief Emit flush of the variables specified in 'omp flush' directive.
814 /// \param Vars List of variables to flush.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000815 virtual void emitFlush(CodeGenFunction &CGF, ArrayRef<const Expr *> Vars,
816 SourceLocation Loc);
Alexey Bataev62b63b12015-03-10 07:28:44 +0000817
818 /// \brief Emit task region for the task directive. The task region is
Nico Weber20b0ce32015-04-28 18:19:18 +0000819 /// emitted in several steps:
Alexey Bataev62b63b12015-03-10 07:28:44 +0000820 /// 1. Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32
821 /// gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds,
822 /// kmp_routine_entry_t *task_entry). Here task_entry is a pointer to the
823 /// function:
824 /// kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) {
825 /// TaskFunction(gtid, tt->part_id, tt->shareds);
826 /// return 0;
827 /// }
828 /// 2. Copy a list of shared variables to field shareds of the resulting
829 /// structure kmp_task_t returned by the previous call (if any).
830 /// 3. Copy a pointer to destructions function to field destructions of the
831 /// resulting structure kmp_task_t.
832 /// 4. Emit a call to kmp_int32 __kmpc_omp_task(ident_t *, kmp_int32 gtid,
833 /// kmp_task_t *new_task), where new_task is a resulting structure from
834 /// previous items.
Alexey Bataev36c1eb92015-04-30 06:51:57 +0000835 /// \param D Current task directive.
Alexey Bataev62b63b12015-03-10 07:28:44 +0000836 /// \param TaskFunction An LLVM function with type void (*)(i32 /*gtid*/, i32
837 /// /*part_id*/, captured_struct */*__context*/);
838 /// \param SharedsTy A type which contains references the shared variables.
Alexey Bataev1d2353d2015-06-24 11:01:36 +0000839 /// \param Shareds Context with the list of shared variables from the \p
Alexey Bataev62b63b12015-03-10 07:28:44 +0000840 /// TaskFunction.
Alexey Bataev1d677132015-04-22 13:57:31 +0000841 /// \param IfCond Not a nullptr if 'if' clause was specified, nullptr
842 /// otherwise.
Alexey Bataev24b5bae2016-04-28 09:23:51 +0000843 /// \param Data Additional data for task generation like tiednsee, final
844 /// state, list of privates etc.
845 virtual void emitTaskCall(CodeGenFunction &CGF, SourceLocation Loc,
846 const OMPExecutableDirective &D,
847 llvm::Value *TaskFunction, QualType SharedsTy,
848 Address Shareds, const Expr *IfCond,
849 const OMPTaskDataTy &Data);
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000850
Alexey Bataev7292c292016-04-25 12:22:29 +0000851 /// Emit task region for the taskloop directive. The taskloop region is
852 /// emitted in several steps:
853 /// 1. Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32
854 /// gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds,
855 /// kmp_routine_entry_t *task_entry). Here task_entry is a pointer to the
856 /// function:
857 /// kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) {
858 /// TaskFunction(gtid, tt->part_id, tt->shareds);
859 /// return 0;
860 /// }
861 /// 2. Copy a list of shared variables to field shareds of the resulting
862 /// structure kmp_task_t returned by the previous call (if any).
863 /// 3. Copy a pointer to destructions function to field destructions of the
864 /// resulting structure kmp_task_t.
865 /// 4. Emit a call to void __kmpc_taskloop(ident_t *loc, int gtid, kmp_task_t
866 /// *task, int if_val, kmp_uint64 *lb, kmp_uint64 *ub, kmp_int64 st, int
867 /// nogroup, int sched, kmp_uint64 grainsize, void *task_dup ), where new_task
868 /// is a resulting structure from
869 /// previous items.
870 /// \param D Current task directive.
Alexey Bataev7292c292016-04-25 12:22:29 +0000871 /// \param TaskFunction An LLVM function with type void (*)(i32 /*gtid*/, i32
872 /// /*part_id*/, captured_struct */*__context*/);
873 /// \param SharedsTy A type which contains references the shared variables.
874 /// \param Shareds Context with the list of shared variables from the \p
875 /// TaskFunction.
876 /// \param IfCond Not a nullptr if 'if' clause was specified, nullptr
877 /// otherwise.
Alexey Bataev24b5bae2016-04-28 09:23:51 +0000878 /// \param Data Additional data for task generation like tiednsee, final
879 /// state, list of privates etc.
Alexey Bataev7292c292016-04-25 12:22:29 +0000880 virtual void emitTaskLoopCall(
881 CodeGenFunction &CGF, SourceLocation Loc, const OMPLoopDirective &D,
Alexey Bataev24b5bae2016-04-28 09:23:51 +0000882 llvm::Value *TaskFunction, QualType SharedsTy, Address Shareds,
883 const Expr *IfCond, const OMPTaskDataTy &Data);
Alexey Bataev7292c292016-04-25 12:22:29 +0000884
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000885 /// \brief Emit code for the directive that does not require outlining.
886 ///
Alexey Bataev81c7ea02015-07-03 09:56:58 +0000887 /// \param InnermostKind Kind of innermost directive (for simple directives it
888 /// is a directive itself, for combined - its innermost directive).
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000889 /// \param CodeGen Code generation sequence for the \a D directive.
Alexey Bataev25e5b442015-09-15 12:52:43 +0000890 /// \param HasCancel true if region has inner cancel directive, false
891 /// otherwise.
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000892 virtual void emitInlinedDirective(CodeGenFunction &CGF,
Alexey Bataev81c7ea02015-07-03 09:56:58 +0000893 OpenMPDirectiveKind InnermostKind,
Alexey Bataev25e5b442015-09-15 12:52:43 +0000894 const RegionCodeGenTy &CodeGen,
895 bool HasCancel = false);
Arpith Chacko Jacob101e8fb2017-02-16 16:20:16 +0000896
897 /// Emits reduction function.
898 /// \param ArgsType Array type containing pointers to reduction variables.
899 /// \param Privates List of private copies for original reduction arguments.
900 /// \param LHSExprs List of LHS in \a ReductionOps reduction operations.
901 /// \param RHSExprs List of RHS in \a ReductionOps reduction operations.
902 /// \param ReductionOps List of reduction operations in form 'LHS binop RHS'
903 /// or 'operator binop(LHS, RHS)'.
904 llvm::Value *emitReductionFunction(CodeGenModule &CGM, llvm::Type *ArgsType,
905 ArrayRef<const Expr *> Privates,
906 ArrayRef<const Expr *> LHSExprs,
907 ArrayRef<const Expr *> RHSExprs,
908 ArrayRef<const Expr *> ReductionOps);
909
910 /// Emits single reduction combiner
911 void emitSingleReductionCombiner(CodeGenFunction &CGF,
912 const Expr *ReductionOp,
913 const Expr *PrivateRef,
914 const DeclRefExpr *LHS,
915 const DeclRefExpr *RHS);
916
917 struct ReductionOptionsTy {
918 bool WithNowait;
919 bool SimpleReduction;
920 OpenMPDirectiveKind ReductionKind;
921 };
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000922 /// \brief Emit a code for reduction clause. Next code should be emitted for
923 /// reduction:
924 /// \code
925 ///
926 /// static kmp_critical_name lock = { 0 };
927 ///
928 /// void reduce_func(void *lhs[<n>], void *rhs[<n>]) {
929 /// ...
930 /// *(Type<i>*)lhs[i] = RedOp<i>(*(Type<i>*)lhs[i], *(Type<i>*)rhs[i]);
931 /// ...
932 /// }
933 ///
934 /// ...
935 /// void *RedList[<n>] = {&<RHSExprs>[0], ..., &<RHSExprs>[<n>-1]};
936 /// switch (__kmpc_reduce{_nowait}(<loc>, <gtid>, <n>, sizeof(RedList),
937 /// RedList, reduce_func, &<lock>)) {
938 /// case 1:
939 /// ...
940 /// <LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]);
941 /// ...
942 /// __kmpc_end_reduce{_nowait}(<loc>, <gtid>, &<lock>);
943 /// break;
944 /// case 2:
945 /// ...
946 /// Atomic(<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]));
947 /// ...
948 /// break;
949 /// default:;
950 /// }
951 /// \endcode
952 ///
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000953 /// \param Privates List of private copies for original reduction arguments.
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000954 /// \param LHSExprs List of LHS in \a ReductionOps reduction operations.
955 /// \param RHSExprs List of RHS in \a ReductionOps reduction operations.
956 /// \param ReductionOps List of reduction operations in form 'LHS binop RHS'
957 /// or 'operator binop(LHS, RHS)'.
Arpith Chacko Jacob101e8fb2017-02-16 16:20:16 +0000958 /// \param Options List of options for reduction codegen:
959 /// WithNowait true if parent directive has also nowait clause, false
960 /// otherwise.
961 /// SimpleReduction Emit reduction operation only. Used for omp simd
962 /// directive on the host.
963 /// ReductionKind The kind of reduction to perform.
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000964 virtual void emitReduction(CodeGenFunction &CGF, SourceLocation Loc,
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000965 ArrayRef<const Expr *> Privates,
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000966 ArrayRef<const Expr *> LHSExprs,
967 ArrayRef<const Expr *> RHSExprs,
968 ArrayRef<const Expr *> ReductionOps,
Arpith Chacko Jacob101e8fb2017-02-16 16:20:16 +0000969 ReductionOptionsTy Options);
Alexey Bataev8b8e2022015-04-27 05:22:09 +0000970
971 /// \brief Emit code for 'taskwait' directive.
972 virtual void emitTaskwaitCall(CodeGenFunction &CGF, SourceLocation Loc);
Alexey Bataev0f34da12015-07-02 04:17:07 +0000973
974 /// \brief Emit code for 'cancellation point' construct.
975 /// \param CancelRegion Region kind for which the cancellation point must be
976 /// emitted.
977 ///
978 virtual void emitCancellationPointCall(CodeGenFunction &CGF,
979 SourceLocation Loc,
980 OpenMPDirectiveKind CancelRegion);
Alexey Bataev7d5d33e2015-07-06 05:50:32 +0000981
982 /// \brief Emit code for 'cancel' construct.
Alexey Bataev87933c72015-09-18 08:07:34 +0000983 /// \param IfCond Condition in the associated 'if' clause, if it was
984 /// specified, nullptr otherwise.
Alexey Bataev7d5d33e2015-07-06 05:50:32 +0000985 /// \param CancelRegion Region kind for which the cancel must be emitted.
986 ///
987 virtual void emitCancelCall(CodeGenFunction &CGF, SourceLocation Loc,
Alexey Bataev87933c72015-09-18 08:07:34 +0000988 const Expr *IfCond,
Alexey Bataev7d5d33e2015-07-06 05:50:32 +0000989 OpenMPDirectiveKind CancelRegion);
Samuel Antaobed3c462015-10-02 16:14:20 +0000990
991 /// \brief Emit outilined function for 'target' directive.
992 /// \param D Directive to emit.
Samuel Antaoee8fb302016-01-06 13:42:12 +0000993 /// \param ParentName Name of the function that encloses the target region.
994 /// \param OutlinedFn Outlined function value to be defined by this call.
995 /// \param OutlinedFnID Outlined function ID value to be defined by this call.
996 /// \param IsOffloadEntry True if the outlined function is an offload entry.
Alexey Bataev14fa1c62016-03-29 05:34:15 +0000997 /// \param CodeGen Code generation sequence for the \a D directive.
Samuel Antaoee8fb302016-01-06 13:42:12 +0000998 /// An oulined function may not be an entry if, e.g. the if clause always
999 /// evaluates to false.
1000 virtual void emitTargetOutlinedFunction(const OMPExecutableDirective &D,
1001 StringRef ParentName,
1002 llvm::Function *&OutlinedFn,
1003 llvm::Constant *&OutlinedFnID,
Alexey Bataev14fa1c62016-03-29 05:34:15 +00001004 bool IsOffloadEntry,
1005 const RegionCodeGenTy &CodeGen);
Samuel Antaobed3c462015-10-02 16:14:20 +00001006
1007 /// \brief Emit the target offloading code associated with \a D. The emitted
1008 /// code attempts offloading the execution to the device, an the event of
1009 /// a failure it executes the host version outlined in \a OutlinedFn.
1010 /// \param D Directive to emit.
1011 /// \param OutlinedFn Host version of the code to be offloaded.
Samuel Antaoee8fb302016-01-06 13:42:12 +00001012 /// \param OutlinedFnID ID of host version of the code to be offloaded.
Samuel Antaobed3c462015-10-02 16:14:20 +00001013 /// \param IfCond Expression evaluated in if clause associated with the target
1014 /// directive, or null if no if clause is used.
1015 /// \param Device Expression evaluated in device clause associated with the
1016 /// target directive, or null if no device clause is used.
1017 /// \param CapturedVars Values captured in the current region.
1018 virtual void emitTargetCall(CodeGenFunction &CGF,
1019 const OMPExecutableDirective &D,
Samuel Antaoee8fb302016-01-06 13:42:12 +00001020 llvm::Value *OutlinedFn,
1021 llvm::Value *OutlinedFnID, const Expr *IfCond,
Samuel Antaobed3c462015-10-02 16:14:20 +00001022 const Expr *Device,
1023 ArrayRef<llvm::Value *> CapturedVars);
Samuel Antaoee8fb302016-01-06 13:42:12 +00001024
1025 /// \brief Emit the target regions enclosed in \a GD function definition or
1026 /// the function itself in case it is a valid device function. Returns true if
1027 /// \a GD was dealt with successfully.
Nico Webera2abe8c2016-01-06 19:13:49 +00001028 /// \param GD Function to scan.
Samuel Antaoee8fb302016-01-06 13:42:12 +00001029 virtual bool emitTargetFunctions(GlobalDecl GD);
1030
1031 /// \brief Emit the global variable if it is a valid device global variable.
1032 /// Returns true if \a GD was dealt with successfully.
1033 /// \param GD Variable declaration to emit.
1034 virtual bool emitTargetGlobalVariable(GlobalDecl GD);
1035
1036 /// \brief Emit the global \a GD if it is meaningful for the target. Returns
1037 /// if it was emitted succesfully.
1038 /// \param GD Global to scan.
1039 virtual bool emitTargetGlobal(GlobalDecl GD);
1040
1041 /// \brief Creates the offloading descriptor in the event any target region
1042 /// was emitted in the current module and return the function that registers
1043 /// it.
1044 virtual llvm::Function *emitRegistrationFunction();
Carlo Bertolli430d8ec2016-03-03 20:34:23 +00001045
1046 /// \brief Emits code for teams call of the \a OutlinedFn with
1047 /// variables captured in a record which address is stored in \a
1048 /// CapturedStruct.
1049 /// \param OutlinedFn Outlined function to be run by team masters. Type of
1050 /// this function is void(*)(kmp_int32 *, kmp_int32, struct context_vars*).
1051 /// \param CapturedVars A pointer to the record with the references to
1052 /// variables used in \a OutlinedFn function.
1053 ///
1054 virtual void emitTeamsCall(CodeGenFunction &CGF,
1055 const OMPExecutableDirective &D,
1056 SourceLocation Loc, llvm::Value *OutlinedFn,
1057 ArrayRef<llvm::Value *> CapturedVars);
1058
1059 /// \brief Emits call to void __kmpc_push_num_teams(ident_t *loc, kmp_int32
1060 /// global_tid, kmp_int32 num_teams, kmp_int32 thread_limit) to generate code
1061 /// for num_teams clause.
Carlo Bertollic6872252016-04-04 15:55:02 +00001062 /// \param NumTeams An integer expression of teams.
1063 /// \param ThreadLimit An integer expression of threads.
1064 virtual void emitNumTeamsClause(CodeGenFunction &CGF, const Expr *NumTeams,
1065 const Expr *ThreadLimit, SourceLocation Loc);
Samuel Antaodf158d52016-04-27 22:58:19 +00001066
Samuel Antaocc10b852016-07-28 14:23:26 +00001067 /// Struct that keeps all the relevant information that should be kept
1068 /// throughout a 'target data' region.
1069 class TargetDataInfo {
1070 /// Set to true if device pointer information have to be obtained.
1071 bool RequiresDevicePointerInfo = false;
1072
1073 public:
1074 /// The array of base pointer passed to the runtime library.
1075 llvm::Value *BasePointersArray = nullptr;
1076 /// The array of section pointers passed to the runtime library.
1077 llvm::Value *PointersArray = nullptr;
1078 /// The array of sizes passed to the runtime library.
1079 llvm::Value *SizesArray = nullptr;
1080 /// The array of map types passed to the runtime library.
1081 llvm::Value *MapTypesArray = nullptr;
1082 /// The total number of pointers passed to the runtime library.
1083 unsigned NumberOfPtrs = 0u;
1084 /// Map between the a declaration of a capture and the corresponding base
1085 /// pointer address where the runtime returns the device pointers.
1086 llvm::DenseMap<const ValueDecl *, Address> CaptureDeviceAddrMap;
1087
1088 explicit TargetDataInfo() {}
1089 explicit TargetDataInfo(bool RequiresDevicePointerInfo)
1090 : RequiresDevicePointerInfo(RequiresDevicePointerInfo) {}
1091 /// Clear information about the data arrays.
1092 void clearArrayInfo() {
1093 BasePointersArray = nullptr;
1094 PointersArray = nullptr;
1095 SizesArray = nullptr;
1096 MapTypesArray = nullptr;
1097 NumberOfPtrs = 0u;
1098 }
1099 /// Return true if the current target data information has valid arrays.
1100 bool isValid() {
1101 return BasePointersArray && PointersArray && SizesArray &&
1102 MapTypesArray && NumberOfPtrs;
1103 }
1104 bool requiresDevicePointerInfo() { return RequiresDevicePointerInfo; }
1105 };
1106
Samuel Antaodf158d52016-04-27 22:58:19 +00001107 /// \brief Emit the target data mapping code associated with \a D.
1108 /// \param D Directive to emit.
Samuel Antaocc10b852016-07-28 14:23:26 +00001109 /// \param IfCond Expression evaluated in if clause associated with the
1110 /// target directive, or null if no device clause is used.
Samuel Antaodf158d52016-04-27 22:58:19 +00001111 /// \param Device Expression evaluated in device clause associated with the
1112 /// target directive, or null if no device clause is used.
Samuel Antaocc10b852016-07-28 14:23:26 +00001113 /// \param Info A record used to store information that needs to be preserved
1114 /// until the region is closed.
Samuel Antaodf158d52016-04-27 22:58:19 +00001115 virtual void emitTargetDataCalls(CodeGenFunction &CGF,
1116 const OMPExecutableDirective &D,
1117 const Expr *IfCond, const Expr *Device,
Samuel Antaocc10b852016-07-28 14:23:26 +00001118 const RegionCodeGenTy &CodeGen,
1119 TargetDataInfo &Info);
Samuel Antaobd0ae2e2016-04-27 23:07:29 +00001120
Samuel Antao8d2d7302016-05-26 18:30:22 +00001121 /// \brief Emit the data mapping/movement code associated with the directive
1122 /// \a D that should be of the form 'target [{enter|exit} data | update]'.
Samuel Antaobd0ae2e2016-04-27 23:07:29 +00001123 /// \param D Directive to emit.
1124 /// \param IfCond Expression evaluated in if clause associated with the target
1125 /// directive, or null if no if clause is used.
1126 /// \param Device Expression evaluated in device clause associated with the
1127 /// target directive, or null if no device clause is used.
Samuel Antao8d2d7302016-05-26 18:30:22 +00001128 virtual void emitTargetDataStandAloneCall(CodeGenFunction &CGF,
1129 const OMPExecutableDirective &D,
1130 const Expr *IfCond,
1131 const Expr *Device);
Alexey Bataevc7a82b42016-05-06 09:40:08 +00001132
1133 /// Marks function \a Fn with properly mangled versions of vector functions.
1134 /// \param FD Function marked as 'declare simd'.
1135 /// \param Fn LLVM function that must be marked with 'declare simd'
1136 /// attributes.
1137 virtual void emitDeclareSimdFunction(const FunctionDecl *FD,
1138 llvm::Function *Fn);
Alexey Bataev8b427062016-05-25 12:36:08 +00001139
1140 /// Emit initialization for doacross loop nesting support.
1141 /// \param D Loop-based construct used in doacross nesting construct.
1142 virtual void emitDoacrossInit(CodeGenFunction &CGF,
1143 const OMPLoopDirective &D);
1144
1145 /// Emit code for doacross ordered directive with 'depend' clause.
1146 /// \param C 'depend' clause with 'sink|source' dependency kind.
1147 virtual void emitDoacrossOrdered(CodeGenFunction &CGF,
1148 const OMPDependClause *C);
Alexey Bataev9959db52014-05-06 10:08:46 +00001149};
Alexey Bataev8cbe0a62015-02-26 10:27:34 +00001150
Alexey Bataev23b69422014-06-18 07:08:49 +00001151} // namespace CodeGen
1152} // namespace clang
Alexey Bataev9959db52014-05-06 10:08:46 +00001153
1154#endif