blob: 5a42fe8eca8d88421f3a030f17ba7d0938992dac [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 Bataev62b63b12015-03-10 07:28:44 +000017#include "clang/AST/Type.h"
Alexander Musmanc6388682014-12-15 07:07:06 +000018#include "clang/Basic/OpenMPKinds.h"
Chandler Carruth0d9593d2015-01-14 11:29:14 +000019#include "clang/Basic/SourceLocation.h"
Alexey Bataev9959db52014-05-06 10:08:46 +000020#include "llvm/ADT/DenseMap.h"
Benjamin Kramer8fdba912016-02-02 14:24:21 +000021#include "llvm/ADT/SmallPtrSet.h"
Alexey Bataev3a3bf0b2014-09-22 10:01:53 +000022#include "llvm/ADT/StringMap.h"
Benjamin Kramer8fdba912016-02-02 14:24:21 +000023#include "llvm/IR/Function.h"
Alexey Bataev97720002014-11-11 04:05:39 +000024#include "llvm/IR/ValueHandle.h"
Alexey Bataev18095712014-10-10 12:19:54 +000025
26namespace llvm {
27class ArrayType;
28class Constant;
Alexey Bataev18095712014-10-10 12:19:54 +000029class FunctionType;
Alexey Bataev97720002014-11-11 04:05:39 +000030class GlobalVariable;
Alexey Bataev18095712014-10-10 12:19:54 +000031class StructType;
32class Type;
33class Value;
34} // namespace llvm
Alexey Bataev9959db52014-05-06 10:08:46 +000035
Alexey Bataev9959db52014-05-06 10:08:46 +000036namespace clang {
Alexey Bataevcc37cc12014-11-20 04:34:54 +000037class Expr;
Samuel Antaoee8fb302016-01-06 13:42:12 +000038class GlobalDecl;
Alexey Bataev18095712014-10-10 12:19:54 +000039class OMPExecutableDirective;
40class VarDecl;
41
Alexey Bataev9959db52014-05-06 10:08:46 +000042namespace CodeGen {
John McCall7f416cc2015-09-08 08:05:57 +000043class Address;
Alexey Bataev18095712014-10-10 12:19:54 +000044class CodeGenFunction;
45class CodeGenModule;
Alexey Bataev9959db52014-05-06 10:08:46 +000046
Alexey Bataev6f1ffc02015-04-10 04:50:10 +000047typedef llvm::function_ref<void(CodeGenFunction &)> RegionCodeGenTy;
48
Alexey Bataev9959db52014-05-06 10:08:46 +000049class CGOpenMPRuntime {
Alexey Bataev9959db52014-05-06 10:08:46 +000050 CodeGenModule &CGM;
51 /// \brief Default const ident_t object used for initialization of all other
52 /// ident_t objects.
53 llvm::Constant *DefaultOpenMPPSource;
Alexey Bataev18095712014-10-10 12:19:54 +000054 /// \brief Map of flags and corresponding default locations.
Alexey Bataev15007ba2014-05-07 06:18:01 +000055 typedef llvm::DenseMap<unsigned, llvm::Value *> OpenMPDefaultLocMapTy;
56 OpenMPDefaultLocMapTy OpenMPDefaultLocMap;
Alexey Bataev50b3c952016-02-19 10:38:26 +000057 Address getOrCreateDefaultLocation(unsigned Flags);
John McCall7f416cc2015-09-08 08:05:57 +000058
Alexey Bataev9959db52014-05-06 10:08:46 +000059 llvm::StructType *IdentTy;
Alexey Bataev18095712014-10-10 12:19:54 +000060 /// \brief Map for SourceLocation and OpenMP runtime library debug locations.
Alexey Bataevf002aca2014-05-30 05:48:40 +000061 typedef llvm::DenseMap<unsigned, llvm::Value *> OpenMPDebugLocMapTy;
62 OpenMPDebugLocMapTy OpenMPDebugLocMap;
Alexey Bataev9959db52014-05-06 10:08:46 +000063 /// \brief The type for a microtask which gets passed to __kmpc_fork_call().
64 /// Original representation is:
65 /// typedef void (kmpc_micro)(kmp_int32 global_tid, kmp_int32 bound_tid,...);
66 llvm::FunctionType *Kmpc_MicroTy;
Alexey Bataev18095712014-10-10 12:19:54 +000067 /// \brief Stores debug location and ThreadID for the function.
68 struct DebugLocThreadIdTy {
69 llvm::Value *DebugLoc;
70 llvm::Value *ThreadID;
71 };
72 /// \brief Map of local debug location, ThreadId and functions.
73 typedef llvm::DenseMap<llvm::Function *, DebugLocThreadIdTy>
74 OpenMPLocThreadIDMapTy;
75 OpenMPLocThreadIDMapTy OpenMPLocThreadIDMap;
Alexey Bataev3a3bf0b2014-09-22 10:01:53 +000076 /// \brief Type kmp_critical_name, originally defined as typedef kmp_int32
77 /// kmp_critical_name[8];
78 llvm::ArrayType *KmpCriticalNameTy;
Alexey Bataev97720002014-11-11 04:05:39 +000079 /// \brief An ordered map of auto-generated variables to their unique names.
80 /// It stores variables with the following names: 1) ".gomp_critical_user_" +
81 /// <critical_section_name> + ".var" for "omp critical" directives; 2)
82 /// <mangled_name_for_global_var> + ".cache." for cache for threadprivate
83 /// variables.
84 llvm::StringMap<llvm::AssertingVH<llvm::Constant>, llvm::BumpPtrAllocator>
85 InternalVars;
Alexey Bataev62b63b12015-03-10 07:28:44 +000086 /// \brief Type typedef kmp_int32 (* kmp_routine_entry_t)(kmp_int32, void *);
87 llvm::Type *KmpRoutineEntryPtrTy;
88 QualType KmpRoutineEntryPtrQTy;
Alexey Bataev8fc69dc2015-05-18 07:54:53 +000089 /// \brief Type typedef struct kmp_task {
90 /// void * shareds; /**< pointer to block of pointers to
91 /// shared vars */
92 /// kmp_routine_entry_t routine; /**< pointer to routine to call for
93 /// executing task */
94 /// kmp_int32 part_id; /**< part id for the task */
95 /// kmp_routine_entry_t destructors; /* pointer to function to invoke
96 /// deconstructors of firstprivate C++ objects */
97 /// } kmp_task_t;
98 QualType KmpTaskTQTy;
Alexey Bataev1d2353d2015-06-24 11:01:36 +000099 /// \brief Type typedef struct kmp_depend_info {
100 /// kmp_intptr_t base_addr;
101 /// size_t len;
102 /// struct {
103 /// bool in:1;
104 /// bool out:1;
105 /// } flags;
106 /// } kmp_depend_info_t;
107 QualType KmpDependInfoTy;
Samuel Antaoee8fb302016-01-06 13:42:12 +0000108 /// \brief Type struct __tgt_offload_entry{
109 /// void *addr; // Pointer to the offload entry info.
110 /// // (function or global)
111 /// char *name; // Name of the function or global.
112 /// size_t size; // Size of the entry info (0 if it a function).
113 /// };
114 QualType TgtOffloadEntryQTy;
115 /// struct __tgt_device_image{
116 /// void *ImageStart; // Pointer to the target code start.
117 /// void *ImageEnd; // Pointer to the target code end.
118 /// // We also add the host entries to the device image, as it may be useful
119 /// // for the target runtime to have access to that information.
120 /// __tgt_offload_entry *EntriesBegin; // Begin of the table with all
121 /// // the entries.
122 /// __tgt_offload_entry *EntriesEnd; // End of the table with all the
123 /// // entries (non inclusive).
124 /// };
125 QualType TgtDeviceImageQTy;
126 /// struct __tgt_bin_desc{
127 /// int32_t NumDevices; // Number of devices supported.
128 /// __tgt_device_image *DeviceImages; // Arrays of device images
129 /// // (one per device).
130 /// __tgt_offload_entry *EntriesBegin; // Begin of the table with all the
131 /// // entries.
132 /// __tgt_offload_entry *EntriesEnd; // End of the table with all the
133 /// // entries (non inclusive).
134 /// };
135 QualType TgtBinaryDescriptorQTy;
136 /// \brief Entity that registers the offloading constants that were emitted so
137 /// far.
138 class OffloadEntriesInfoManagerTy {
139 CodeGenModule &CGM;
Alexey Bataev1d2353d2015-06-24 11:01:36 +0000140
Samuel Antaoee8fb302016-01-06 13:42:12 +0000141 /// \brief Number of entries registered so far.
142 unsigned OffloadingEntriesNum;
143
144 public:
145 /// \brief Base class of the entries info.
146 class OffloadEntryInfo {
147 public:
148 /// \brief Kind of a given entry. Currently, only target regions are
149 /// supported.
Reid Klecknerdc78f952016-01-11 20:55:16 +0000150 enum OffloadingEntryInfoKinds : unsigned {
Samuel Antaoee8fb302016-01-06 13:42:12 +0000151 // Entry is a target region.
152 OFFLOAD_ENTRY_INFO_TARGET_REGION = 0,
153 // Invalid entry info.
154 OFFLOAD_ENTRY_INFO_INVALID = ~0u
155 };
156
157 OffloadEntryInfo() : Order(~0u), Kind(OFFLOAD_ENTRY_INFO_INVALID) {}
158 explicit OffloadEntryInfo(OffloadingEntryInfoKinds Kind, unsigned Order)
159 : Order(Order), Kind(Kind) {}
160
161 bool isValid() const { return Order != ~0u; }
162 unsigned getOrder() const { return Order; }
163 OffloadingEntryInfoKinds getKind() const { return Kind; }
164 static bool classof(const OffloadEntryInfo *Info) { return true; }
165
166 protected:
167 // \brief Order this entry was emitted.
168 unsigned Order;
169
170 OffloadingEntryInfoKinds Kind;
171 };
172
173 /// \brief Return true if a there are no entries defined.
174 bool empty() const;
175 /// \brief Return number of entries defined so far.
176 unsigned size() const { return OffloadingEntriesNum; }
177 OffloadEntriesInfoManagerTy(CodeGenModule &CGM)
178 : CGM(CGM), OffloadingEntriesNum(0) {}
179
180 ///
181 /// Target region entries related.
182 ///
183 /// \brief Target region entries info.
184 class OffloadEntryInfoTargetRegion : public OffloadEntryInfo {
185 // \brief Address of the entity that has to be mapped for offloading.
186 llvm::Constant *Addr;
187 // \brief Address that can be used as the ID of the entry.
188 llvm::Constant *ID;
189
190 public:
191 OffloadEntryInfoTargetRegion()
192 : OffloadEntryInfo(OFFLOAD_ENTRY_INFO_TARGET_REGION, ~0u),
193 Addr(nullptr), ID(nullptr) {}
194 explicit OffloadEntryInfoTargetRegion(unsigned Order,
195 llvm::Constant *Addr,
196 llvm::Constant *ID)
197 : OffloadEntryInfo(OFFLOAD_ENTRY_INFO_TARGET_REGION, Order),
198 Addr(Addr), ID(ID) {}
199
200 llvm::Constant *getAddress() const { return Addr; }
201 llvm::Constant *getID() const { return ID; }
202 void setAddress(llvm::Constant *V) {
203 assert(!Addr && "Address as been set before!");
204 Addr = V;
205 }
206 void setID(llvm::Constant *V) {
207 assert(!ID && "ID as been set before!");
208 ID = V;
209 }
210 static bool classof(const OffloadEntryInfo *Info) {
211 return Info->getKind() == OFFLOAD_ENTRY_INFO_TARGET_REGION;
212 }
213 };
214 /// \brief Initialize target region entry.
215 void initializeTargetRegionEntryInfo(unsigned DeviceID, unsigned FileID,
216 StringRef ParentName, unsigned LineNum,
Samuel Antao2de62b02016-02-13 23:35:10 +0000217 unsigned Order);
Samuel Antaoee8fb302016-01-06 13:42:12 +0000218 /// \brief Register target region entry.
219 void registerTargetRegionEntryInfo(unsigned DeviceID, unsigned FileID,
220 StringRef ParentName, unsigned LineNum,
Samuel Antao2de62b02016-02-13 23:35:10 +0000221 llvm::Constant *Addr,
Samuel Antaoee8fb302016-01-06 13:42:12 +0000222 llvm::Constant *ID);
223 /// \brief Return true if a target region entry with the provided
224 /// information exists.
225 bool hasTargetRegionEntryInfo(unsigned DeviceID, unsigned FileID,
Samuel Antao2de62b02016-02-13 23:35:10 +0000226 StringRef ParentName, unsigned LineNum) const;
Samuel Antaoee8fb302016-01-06 13:42:12 +0000227 /// brief Applies action \a Action on all registered entries.
228 typedef llvm::function_ref<void(unsigned, unsigned, StringRef, unsigned,
Samuel Antao2de62b02016-02-13 23:35:10 +0000229 OffloadEntryInfoTargetRegion &)>
Samuel Antaoee8fb302016-01-06 13:42:12 +0000230 OffloadTargetRegionEntryInfoActTy;
231 void actOnTargetRegionEntriesInfo(
232 const OffloadTargetRegionEntryInfoActTy &Action);
233
234 private:
235 // Storage for target region entries kind. The storage is to be indexed by
Samuel Antao2de62b02016-02-13 23:35:10 +0000236 // file ID, device ID, parent function name and line number.
Samuel Antaoee8fb302016-01-06 13:42:12 +0000237 typedef llvm::DenseMap<unsigned, OffloadEntryInfoTargetRegion>
Samuel Antaoee8fb302016-01-06 13:42:12 +0000238 OffloadEntriesTargetRegionPerLine;
239 typedef llvm::StringMap<OffloadEntriesTargetRegionPerLine>
240 OffloadEntriesTargetRegionPerParentName;
241 typedef llvm::DenseMap<unsigned, OffloadEntriesTargetRegionPerParentName>
242 OffloadEntriesTargetRegionPerFile;
243 typedef llvm::DenseMap<unsigned, OffloadEntriesTargetRegionPerFile>
244 OffloadEntriesTargetRegionPerDevice;
245 typedef OffloadEntriesTargetRegionPerDevice OffloadEntriesTargetRegionTy;
246 OffloadEntriesTargetRegionTy OffloadEntriesTargetRegion;
247 };
248 OffloadEntriesInfoManagerTy OffloadEntriesInfoManager;
249
250 /// \brief Creates and registers offloading binary descriptor for the current
251 /// compilation unit. The function that does the registration is returned.
252 llvm::Function *createOffloadingBinaryDescriptorRegistration();
253
Samuel Antao2de62b02016-02-13 23:35:10 +0000254 /// \brief Creates offloading entry for the provided entry ID \a ID,
255 /// address \a Addr and size \a Size.
256 void createOffloadEntry(llvm::Constant *ID, llvm::Constant *Addr,
257 uint64_t Size);
Samuel Antaoee8fb302016-01-06 13:42:12 +0000258
259 /// \brief Creates all the offload entries in the current compilation unit
260 /// along with the associated metadata.
261 void createOffloadEntriesAndInfoMetadata();
262
263 /// \brief Loads all the offload entries information from the host IR
264 /// metadata.
265 void loadOffloadInfoMetadata();
266
267 /// \brief Returns __tgt_offload_entry type.
268 QualType getTgtOffloadEntryQTy();
269
270 /// \brief Returns __tgt_device_image type.
271 QualType getTgtDeviceImageQTy();
272
273 /// \brief Returns __tgt_bin_desc type.
274 QualType getTgtBinaryDescriptorQTy();
275
276 /// \brief Start scanning from statement \a S and and emit all target regions
277 /// found along the way.
278 /// \param S Starting statement.
279 /// \param ParentName Name of the function declaration that is being scanned.
280 void scanForTargetRegionsFunctions(const Stmt *S, StringRef ParentName);
Alexey Bataev62b63b12015-03-10 07:28:44 +0000281
282 /// \brief Build type kmp_routine_entry_t (if not built yet).
283 void emitKmpRoutineEntryT(QualType KmpInt32Ty);
Alexey Bataev9959db52014-05-06 10:08:46 +0000284
Alexey Bataev9959db52014-05-06 10:08:46 +0000285 /// \brief Emits object of ident_t type with info for source location.
Alexey Bataev9959db52014-05-06 10:08:46 +0000286 /// \param Flags Flags for OpenMP location.
287 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000288 llvm::Value *emitUpdateLocation(CodeGenFunction &CGF, SourceLocation Loc,
Alexey Bataev50b3c952016-02-19 10:38:26 +0000289 unsigned Flags = 0);
Alexey Bataev9959db52014-05-06 10:08:46 +0000290
Alexey Bataevd74d0602014-10-13 06:02:40 +0000291 /// \brief Returns pointer to ident_t type.
Alexey Bataev9959db52014-05-06 10:08:46 +0000292 llvm::Type *getIdentTyPointerTy();
293
Alexey Bataevd74d0602014-10-13 06:02:40 +0000294 /// \brief Returns pointer to kmpc_micro type.
Alexey Bataev9959db52014-05-06 10:08:46 +0000295 llvm::Type *getKmpc_MicroPointerTy();
296
297 /// \brief Returns specified OpenMP runtime function.
298 /// \param Function OpenMP runtime function.
299 /// \return Specified function.
Alexey Bataev50b3c952016-02-19 10:38:26 +0000300 llvm::Constant *createRuntimeFunction(unsigned Function);
Alexey Bataev3a3bf0b2014-09-22 10:01:53 +0000301
Alexander Musman21212e42015-03-13 10:38:23 +0000302 /// \brief Returns __kmpc_for_static_init_* runtime function for the specified
303 /// size \a IVSize and sign \a IVSigned.
304 llvm::Constant *createForStaticInitFunction(unsigned IVSize, bool IVSigned);
305
Alexander Musman92bdaab2015-03-12 13:37:50 +0000306 /// \brief Returns __kmpc_dispatch_init_* runtime function for the specified
307 /// size \a IVSize and sign \a IVSigned.
308 llvm::Constant *createDispatchInitFunction(unsigned IVSize, bool IVSigned);
309
310 /// \brief Returns __kmpc_dispatch_next_* runtime function for the specified
311 /// size \a IVSize and sign \a IVSigned.
312 llvm::Constant *createDispatchNextFunction(unsigned IVSize, bool IVSigned);
313
Alexey Bataev98eb6e32015-04-22 11:15:40 +0000314 /// \brief Returns __kmpc_dispatch_fini_* runtime function for the specified
315 /// size \a IVSize and sign \a IVSigned.
316 llvm::Constant *createDispatchFiniFunction(unsigned IVSize, bool IVSigned);
317
Alexey Bataev97720002014-11-11 04:05:39 +0000318 /// \brief If the specified mangled name is not in the module, create and
319 /// return threadprivate cache object. This object is a pointer's worth of
320 /// storage that's reserved for use by the OpenMP runtime.
NAKAMURA Takumicdcbfba2014-11-11 07:58:06 +0000321 /// \param VD Threadprivate variable.
Alexey Bataev97720002014-11-11 04:05:39 +0000322 /// \return Cache variable for the specified threadprivate.
323 llvm::Constant *getOrCreateThreadPrivateCache(const VarDecl *VD);
324
Alexey Bataevd74d0602014-10-13 06:02:40 +0000325 /// \brief Emits address of the word in a memory where current thread id is
326 /// stored.
John McCall7f416cc2015-09-08 08:05:57 +0000327 virtual Address emitThreadIDAddress(CodeGenFunction &CGF, SourceLocation Loc);
Alexey Bataevd74d0602014-10-13 06:02:40 +0000328
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000329 /// \brief Gets thread id value for the current thread.
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000330 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000331 llvm::Value *getThreadID(CodeGenFunction &CGF, SourceLocation Loc);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000332
Alexey Bataev97720002014-11-11 04:05:39 +0000333 /// \brief Gets (if variable with the given name already exist) or creates
334 /// internal global variable with the specified Name. The created variable has
335 /// linkage CommonLinkage by default and is initialized by null value.
336 /// \param Ty Type of the global variable. If it is exist already the type
337 /// must be the same.
338 /// \param Name Name of the variable.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000339 llvm::Constant *getOrCreateInternalVariable(llvm::Type *Ty,
Alexey Bataev97720002014-11-11 04:05:39 +0000340 const llvm::Twine &Name);
341
342 /// \brief Set of threadprivate variables with the generated initializer.
Benjamin Kramer8fdba912016-02-02 14:24:21 +0000343 llvm::SmallPtrSet<const VarDecl *, 4> ThreadPrivateWithDefinition;
Alexey Bataev97720002014-11-11 04:05:39 +0000344
345 /// \brief Emits initialization code for the threadprivate variables.
346 /// \param VDAddr Address of the global variable \a VD.
347 /// \param Ctor Pointer to a global init function for \a VD.
348 /// \param CopyCtor Pointer to a global copy function for \a VD.
349 /// \param Dtor Pointer to a global destructor function for \a VD.
350 /// \param Loc Location of threadprivate declaration.
John McCall7f416cc2015-09-08 08:05:57 +0000351 void emitThreadPrivateVarInit(CodeGenFunction &CGF, Address VDAddr,
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000352 llvm::Value *Ctor, llvm::Value *CopyCtor,
353 llvm::Value *Dtor, SourceLocation Loc);
Alexey Bataev97720002014-11-11 04:05:39 +0000354
Alexey Bataev75ddfab2014-12-01 11:32:38 +0000355 /// \brief Returns corresponding lock object for the specified critical region
356 /// name. If the lock object does not exist it is created, otherwise the
357 /// reference to the existing copy is returned.
358 /// \param CriticalName Name of the critical region.
359 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000360 llvm::Value *getCriticalRegionLock(StringRef CriticalName);
Alexey Bataev75ddfab2014-12-01 11:32:38 +0000361
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000362public:
363 explicit CGOpenMPRuntime(CodeGenModule &CGM);
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +0000364 virtual ~CGOpenMPRuntime() {}
Alexey Bataev91797552015-03-18 04:13:55 +0000365 virtual void clear();
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000366
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000367 /// \brief Emits outlined function for the specified OpenMP parallel directive
368 /// \a D. This outlined function has type void(*)(kmp_int32 *ThreadID,
369 /// kmp_int32 BoundID, struct context_vars*).
Alexey Bataev18095712014-10-10 12:19:54 +0000370 /// \param D OpenMP directive.
371 /// \param ThreadIDVar Variable for thread id in the current OpenMP region.
Alexey Bataev81c7ea02015-07-03 09:56:58 +0000372 /// \param InnermostKind Kind of innermost directive (for simple directives it
373 /// is a directive itself, for combined - its innermost directive).
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000374 /// \param CodeGen Code generation sequence for the \a D directive.
Alexey Bataev81c7ea02015-07-03 09:56:58 +0000375 virtual llvm::Value *emitParallelOutlinedFunction(
376 const OMPExecutableDirective &D, const VarDecl *ThreadIDVar,
377 OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen);
Alexey Bataev18095712014-10-10 12:19:54 +0000378
Alexey Bataev62b63b12015-03-10 07:28:44 +0000379 /// \brief Emits outlined function for the OpenMP task directive \a D. This
380 /// outlined function has type void(*)(kmp_int32 ThreadID, kmp_int32
381 /// PartID, struct context_vars*).
382 /// \param D OpenMP directive.
383 /// \param ThreadIDVar Variable for thread id in the current OpenMP region.
Alexey Bataev81c7ea02015-07-03 09:56:58 +0000384 /// \param InnermostKind Kind of innermost directive (for simple directives it
385 /// is a directive itself, for combined - its innermost directive).
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000386 /// \param CodeGen Code generation sequence for the \a D directive.
Alexey Bataev62b63b12015-03-10 07:28:44 +0000387 ///
Alexey Bataev81c7ea02015-07-03 09:56:58 +0000388 virtual llvm::Value *emitTaskOutlinedFunction(
389 const OMPExecutableDirective &D, const VarDecl *ThreadIDVar,
390 OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen);
Alexey Bataev62b63b12015-03-10 07:28:44 +0000391
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000392 /// \brief Cleans up references to the objects in finished function.
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000393 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000394 void functionFinished(CodeGenFunction &CGF);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000395
Alexey Bataev1d677132015-04-22 13:57:31 +0000396 /// \brief Emits code for parallel or serial call of the \a OutlinedFn with
397 /// variables captured in a record which address is stored in \a
398 /// CapturedStruct.
Alexey Bataev18095712014-10-10 12:19:54 +0000399 /// \param OutlinedFn Outlined function to be run in parallel threads. Type of
Alexey Bataev62b63b12015-03-10 07:28:44 +0000400 /// this function is void(*)(kmp_int32 *, kmp_int32, struct context_vars*).
NAKAMURA Takumi62f0eb52015-09-11 08:13:32 +0000401 /// \param CapturedVars A pointer to the record with the references to
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000402 /// variables used in \a OutlinedFn function.
Alexey Bataev1d677132015-04-22 13:57:31 +0000403 /// \param IfCond Condition in the associated 'if' clause, if it was
404 /// specified, nullptr otherwise.
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000405 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000406 virtual void emitParallelCall(CodeGenFunction &CGF, SourceLocation Loc,
407 llvm::Value *OutlinedFn,
Alexey Bataev2377fe92015-09-10 08:12:02 +0000408 ArrayRef<llvm::Value *> CapturedVars,
409 const Expr *IfCond);
Alexey Bataevd74d0602014-10-13 06:02:40 +0000410
Alexey Bataev75ddfab2014-12-01 11:32:38 +0000411 /// \brief Emits a critical region.
Alexey Bataev18095712014-10-10 12:19:54 +0000412 /// \param CriticalName Name of the critical region.
Alexey Bataev75ddfab2014-12-01 11:32:38 +0000413 /// \param CriticalOpGen Generator for the statement associated with the given
414 /// critical region.
Alexey Bataevfc57d162015-12-15 10:55:09 +0000415 /// \param Hint Value of the 'hint' clause (optional).
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000416 virtual void emitCriticalRegion(CodeGenFunction &CGF, StringRef CriticalName,
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000417 const RegionCodeGenTy &CriticalOpGen,
Alexey Bataevfc57d162015-12-15 10:55:09 +0000418 SourceLocation Loc,
419 const Expr *Hint = nullptr);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000420
Alexey Bataev8d690652014-12-04 07:23:53 +0000421 /// \brief Emits a master region.
422 /// \param MasterOpGen Generator for the statement associated with the given
423 /// master region.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000424 virtual void emitMasterRegion(CodeGenFunction &CGF,
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000425 const RegionCodeGenTy &MasterOpGen,
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000426 SourceLocation Loc);
Alexey Bataev8d690652014-12-04 07:23:53 +0000427
Alexey Bataev9f797f32015-02-05 05:57:51 +0000428 /// \brief Emits code for a taskyield directive.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000429 virtual void emitTaskyieldCall(CodeGenFunction &CGF, SourceLocation Loc);
Alexey Bataev9f797f32015-02-05 05:57:51 +0000430
Alexey Bataevc30dd2d2015-06-18 12:14:09 +0000431 /// \brief Emit a taskgroup region.
432 /// \param TaskgroupOpGen Generator for the statement associated with the
433 /// given taskgroup region.
434 virtual void emitTaskgroupRegion(CodeGenFunction &CGF,
435 const RegionCodeGenTy &TaskgroupOpGen,
436 SourceLocation Loc);
437
Alexey Bataev6956e2e2015-02-05 06:35:41 +0000438 /// \brief Emits a single region.
439 /// \param SingleOpGen Generator for the statement associated with the given
440 /// single region.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000441 virtual void emitSingleRegion(CodeGenFunction &CGF,
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000442 const RegionCodeGenTy &SingleOpGen,
Alexey Bataeva63048e2015-03-23 06:18:07 +0000443 SourceLocation Loc,
444 ArrayRef<const Expr *> CopyprivateVars,
Alexey Bataev420d45b2015-04-14 05:11:24 +0000445 ArrayRef<const Expr *> DestExprs,
Alexey Bataeva63048e2015-03-23 06:18:07 +0000446 ArrayRef<const Expr *> SrcExprs,
Alexey Bataeva63048e2015-03-23 06:18:07 +0000447 ArrayRef<const Expr *> AssignmentOps);
Alexey Bataev6956e2e2015-02-05 06:35:41 +0000448
Alexey Bataev98eb6e32015-04-22 11:15:40 +0000449 /// \brief Emit an ordered region.
450 /// \param OrderedOpGen Generator for the statement associated with the given
Alexey Bataevc30dd2d2015-06-18 12:14:09 +0000451 /// ordered region.
Alexey Bataev98eb6e32015-04-22 11:15:40 +0000452 virtual void emitOrderedRegion(CodeGenFunction &CGF,
453 const RegionCodeGenTy &OrderedOpGen,
Alexey Bataev5f600d62015-09-29 03:48:57 +0000454 SourceLocation Loc, bool IsThreads);
Alexey Bataev98eb6e32015-04-22 11:15:40 +0000455
Alexey Bataevf2685682015-03-30 04:30:22 +0000456 /// \brief Emit an implicit/explicit barrier for OpenMP threads.
457 /// \param Kind Directive for which this implicit barrier call must be
458 /// generated. Must be OMPD_barrier for explicit barrier generation.
Alexey Bataev25e5b442015-09-15 12:52:43 +0000459 /// \param EmitChecks true if need to emit checks for cancellation barriers.
460 /// \param ForceSimpleCall true simple barrier call must be emitted, false if
461 /// runtime class decides which one to emit (simple or with cancellation
462 /// checks).
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000463 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000464 virtual void emitBarrierCall(CodeGenFunction &CGF, SourceLocation Loc,
Alexey Bataev81c7ea02015-07-03 09:56:58 +0000465 OpenMPDirectiveKind Kind,
Alexey Bataev25e5b442015-09-15 12:52:43 +0000466 bool EmitChecks = true,
467 bool ForceSimpleCall = false);
Alexey Bataevb2059782014-10-13 08:23:51 +0000468
Alexander Musmanc6388682014-12-15 07:07:06 +0000469 /// \brief Check if the specified \a ScheduleKind is static non-chunked.
470 /// This kind of worksharing directive is emitted without outer loop.
471 /// \param ScheduleKind Schedule kind specified in the 'schedule' clause.
472 /// \param Chunked True if chunk is specified in the clause.
473 ///
474 virtual bool isStaticNonchunked(OpenMPScheduleClauseKind ScheduleKind,
475 bool Chunked) const;
476
Alexander Musmandf7a8e22015-01-22 08:49:35 +0000477 /// \brief Check if the specified \a ScheduleKind is dynamic.
478 /// This kind of worksharing directive is emitted without outer loop.
479 /// \param ScheduleKind Schedule Kind specified in the 'schedule' clause.
480 ///
481 virtual bool isDynamic(OpenMPScheduleClauseKind ScheduleKind) const;
482
NAKAMURA Takumiff7a9252015-09-08 09:42:41 +0000483 virtual void emitForDispatchInit(CodeGenFunction &CGF, SourceLocation Loc,
484 OpenMPScheduleClauseKind SchedKind,
485 unsigned IVSize, bool IVSigned,
486 bool Ordered, llvm::Value *UB,
487 llvm::Value *Chunk = nullptr);
488
Alexander Musmanc6388682014-12-15 07:07:06 +0000489 /// \brief Call the appropriate runtime routine to initialize it before start
490 /// of loop.
491 ///
492 /// Depending on the loop schedule, it is nesessary to call some runtime
493 /// routine before start of the OpenMP loop to get the loop upper / lower
494 /// bounds \a LB and \a UB and stride \a ST.
495 ///
496 /// \param CGF Reference to current CodeGenFunction.
497 /// \param Loc Clang source location.
NAKAMURA Takumieca08382014-12-17 14:47:06 +0000498 /// \param SchedKind Schedule kind, specified by the 'schedule' clause.
Alexander Musmanc6388682014-12-15 07:07:06 +0000499 /// \param IVSize Size of the iteration variable in bits.
500 /// \param IVSigned Sign of the interation variable.
Alexey Bataevd7589ffe2015-05-20 13:12:48 +0000501 /// \param Ordered true if loop is ordered, false otherwise.
Alexander Musmanc6388682014-12-15 07:07:06 +0000502 /// \param IL Address of the output variable in which the flag of the
503 /// last iteration is returned.
504 /// \param LB Address of the output variable in which the lower iteration
505 /// number is returned.
506 /// \param UB Address of the output variable in which the upper iteration
507 /// number is returned.
508 /// \param ST Address of the output variable in which the stride value is
509 /// returned nesessary to generated the static_chunked scheduled loop.
510 /// \param Chunk Value of the chunk for the static_chunked scheduled loop.
511 /// For the default (nullptr) value, the chunk 1 will be used.
512 ///
John McCall7f416cc2015-09-08 08:05:57 +0000513 virtual void emitForStaticInit(CodeGenFunction &CGF, SourceLocation Loc,
514 OpenMPScheduleClauseKind SchedKind,
515 unsigned IVSize, bool IVSigned, bool Ordered,
516 Address IL, Address LB,
517 Address UB, Address ST,
518 llvm::Value *Chunk = nullptr);
Alexander Musmanc6388682014-12-15 07:07:06 +0000519
520 /// \brief Call the appropriate runtime routine to notify that we finished
Alexey Bataev98eb6e32015-04-22 11:15:40 +0000521 /// iteration of the ordered loop with the dynamic scheduling.
522 ///
523 /// \param CGF Reference to current CodeGenFunction.
524 /// \param Loc Clang source location.
525 /// \param IVSize Size of the iteration variable in bits.
526 /// \param IVSigned Sign of the interation variable.
527 ///
Alexey Bataevd7589ffe2015-05-20 13:12:48 +0000528 virtual void emitForOrderedIterationEnd(CodeGenFunction &CGF,
529 SourceLocation Loc, unsigned IVSize,
530 bool IVSigned);
Alexey Bataev98eb6e32015-04-22 11:15:40 +0000531
532 /// \brief Call the appropriate runtime routine to notify that we finished
Alexander Musmanc6388682014-12-15 07:07:06 +0000533 /// all the work with current loop.
534 ///
535 /// \param CGF Reference to current CodeGenFunction.
536 /// \param Loc Clang source location.
Alexander Musmanc6388682014-12-15 07:07:06 +0000537 ///
Alexey Bataev98eb6e32015-04-22 11:15:40 +0000538 virtual void emitForStaticFinish(CodeGenFunction &CGF, SourceLocation Loc);
Alexander Musmanc6388682014-12-15 07:07:06 +0000539
Alexander Musman92bdaab2015-03-12 13:37:50 +0000540 /// Call __kmpc_dispatch_next(
541 /// ident_t *loc, kmp_int32 tid, kmp_int32 *p_lastiter,
542 /// kmp_int[32|64] *p_lower, kmp_int[32|64] *p_upper,
543 /// kmp_int[32|64] *p_stride);
544 /// \param IVSize Size of the iteration variable in bits.
545 /// \param IVSigned Sign of the interation variable.
546 /// \param IL Address of the output variable in which the flag of the
547 /// last iteration is returned.
548 /// \param LB Address of the output variable in which the lower iteration
549 /// number is returned.
550 /// \param UB Address of the output variable in which the upper iteration
551 /// number is returned.
552 /// \param ST Address of the output variable in which the stride value is
553 /// returned.
554 virtual llvm::Value *emitForNext(CodeGenFunction &CGF, SourceLocation Loc,
555 unsigned IVSize, bool IVSigned,
John McCall7f416cc2015-09-08 08:05:57 +0000556 Address IL, Address LB,
557 Address UB, Address ST);
Alexander Musman92bdaab2015-03-12 13:37:50 +0000558
Alexey Bataevb2059782014-10-13 08:23:51 +0000559 /// \brief Emits call to void __kmpc_push_num_threads(ident_t *loc, kmp_int32
560 /// global_tid, kmp_int32 num_threads) to generate code for 'num_threads'
561 /// clause.
562 /// \param NumThreads An integer value of threads.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000563 virtual void emitNumThreadsClause(CodeGenFunction &CGF,
564 llvm::Value *NumThreads,
565 SourceLocation Loc);
Alexey Bataev97720002014-11-11 04:05:39 +0000566
Alexey Bataev7f210c62015-06-18 13:40:03 +0000567 /// \brief Emit call to void __kmpc_push_proc_bind(ident_t *loc, kmp_int32
568 /// global_tid, int proc_bind) to generate code for 'proc_bind' clause.
569 virtual void emitProcBindClause(CodeGenFunction &CGF,
570 OpenMPProcBindClauseKind ProcBind,
571 SourceLocation Loc);
572
Alexey Bataev97720002014-11-11 04:05:39 +0000573 /// \brief Returns address of the threadprivate variable for the current
574 /// thread.
NAKAMURA Takumicdcbfba2014-11-11 07:58:06 +0000575 /// \param VD Threadprivate variable.
Alexey Bataev97720002014-11-11 04:05:39 +0000576 /// \param VDAddr Address of the global variable \a VD.
577 /// \param Loc Location of the reference to threadprivate var.
578 /// \return Address of the threadprivate variable for the current thread.
John McCall7f416cc2015-09-08 08:05:57 +0000579 virtual Address getAddrOfThreadPrivate(CodeGenFunction &CGF,
580 const VarDecl *VD,
581 Address VDAddr,
582 SourceLocation Loc);
Alexey Bataev97720002014-11-11 04:05:39 +0000583
584 /// \brief Emit a code for initialization of threadprivate variable. It emits
585 /// a call to runtime library which adds initial value to the newly created
586 /// threadprivate variable (if it is not constant) and registers destructor
587 /// for the variable (if any).
588 /// \param VD Threadprivate variable.
589 /// \param VDAddr Address of the global variable \a VD.
590 /// \param Loc Location of threadprivate declaration.
591 /// \param PerformInit true if initialization expression is not constant.
592 virtual llvm::Function *
John McCall7f416cc2015-09-08 08:05:57 +0000593 emitThreadPrivateVarDefinition(const VarDecl *VD, Address VDAddr,
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000594 SourceLocation Loc, bool PerformInit,
595 CodeGenFunction *CGF = nullptr);
Alexey Bataevcc37cc12014-11-20 04:34:54 +0000596
597 /// \brief Emit flush of the variables specified in 'omp flush' directive.
598 /// \param Vars List of variables to flush.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000599 virtual void emitFlush(CodeGenFunction &CGF, ArrayRef<const Expr *> Vars,
600 SourceLocation Loc);
Alexey Bataev62b63b12015-03-10 07:28:44 +0000601
602 /// \brief Emit task region for the task directive. The task region is
Nico Weber20b0ce32015-04-28 18:19:18 +0000603 /// emitted in several steps:
Alexey Bataev62b63b12015-03-10 07:28:44 +0000604 /// 1. Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32
605 /// gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds,
606 /// kmp_routine_entry_t *task_entry). Here task_entry is a pointer to the
607 /// function:
608 /// kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) {
609 /// TaskFunction(gtid, tt->part_id, tt->shareds);
610 /// return 0;
611 /// }
612 /// 2. Copy a list of shared variables to field shareds of the resulting
613 /// structure kmp_task_t returned by the previous call (if any).
614 /// 3. Copy a pointer to destructions function to field destructions of the
615 /// resulting structure kmp_task_t.
616 /// 4. Emit a call to kmp_int32 __kmpc_omp_task(ident_t *, kmp_int32 gtid,
617 /// kmp_task_t *new_task), where new_task is a resulting structure from
618 /// previous items.
Alexey Bataev36c1eb92015-04-30 06:51:57 +0000619 /// \param D Current task directive.
Alexey Bataev62b63b12015-03-10 07:28:44 +0000620 /// \param Tied true if the task is tied (the task is tied to the thread that
621 /// can suspend its task region), false - untied (the task is not tied to any
622 /// thread).
623 /// \param Final Contains either constant bool value, or llvm::Value * of i1
624 /// type for final clause. If the value is true, the task forces all of its
625 /// child tasks to become final and included tasks.
626 /// \param TaskFunction An LLVM function with type void (*)(i32 /*gtid*/, i32
627 /// /*part_id*/, captured_struct */*__context*/);
628 /// \param SharedsTy A type which contains references the shared variables.
Alexey Bataev1d2353d2015-06-24 11:01:36 +0000629 /// \param Shareds Context with the list of shared variables from the \p
Alexey Bataev62b63b12015-03-10 07:28:44 +0000630 /// TaskFunction.
Alexey Bataev1d677132015-04-22 13:57:31 +0000631 /// \param IfCond Not a nullptr if 'if' clause was specified, nullptr
632 /// otherwise.
Alexey Bataev36c1eb92015-04-30 06:51:57 +0000633 /// \param PrivateVars List of references to private variables for the task
634 /// directive.
635 /// \param PrivateCopies List of private copies for each private variable in
Alexey Bataev9e034042015-05-05 04:05:12 +0000636 /// \p PrivateVars.
637 /// \param FirstprivateVars List of references to private variables for the
638 /// task directive.
639 /// \param FirstprivateCopies List of private copies for each private variable
640 /// in \p FirstprivateVars.
641 /// \param FirstprivateInits List of references to auto generated variables
642 /// used for initialization of a single array element. Used if firstprivate
643 /// variable is of array type.
Alexey Bataev1d2353d2015-06-24 11:01:36 +0000644 /// \param Dependences List of dependences for the 'task' construct, including
645 /// original expression and dependency type.
646 virtual void emitTaskCall(
647 CodeGenFunction &CGF, SourceLocation Loc, const OMPExecutableDirective &D,
648 bool Tied, llvm::PointerIntPair<llvm::Value *, 1, bool> Final,
John McCall7f416cc2015-09-08 08:05:57 +0000649 llvm::Value *TaskFunction, QualType SharedsTy, Address Shareds,
Alexey Bataev1d2353d2015-06-24 11:01:36 +0000650 const Expr *IfCond, ArrayRef<const Expr *> PrivateVars,
651 ArrayRef<const Expr *> PrivateCopies,
652 ArrayRef<const Expr *> FirstprivateVars,
653 ArrayRef<const Expr *> FirstprivateCopies,
654 ArrayRef<const Expr *> FirstprivateInits,
655 ArrayRef<std::pair<OpenMPDependClauseKind, const Expr *>> Dependences);
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000656
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000657 /// \brief Emit code for the directive that does not require outlining.
658 ///
Alexey Bataev81c7ea02015-07-03 09:56:58 +0000659 /// \param InnermostKind Kind of innermost directive (for simple directives it
660 /// is a directive itself, for combined - its innermost directive).
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000661 /// \param CodeGen Code generation sequence for the \a D directive.
Alexey Bataev25e5b442015-09-15 12:52:43 +0000662 /// \param HasCancel true if region has inner cancel directive, false
663 /// otherwise.
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000664 virtual void emitInlinedDirective(CodeGenFunction &CGF,
Alexey Bataev81c7ea02015-07-03 09:56:58 +0000665 OpenMPDirectiveKind InnermostKind,
Alexey Bataev25e5b442015-09-15 12:52:43 +0000666 const RegionCodeGenTy &CodeGen,
667 bool HasCancel = false);
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000668 /// \brief Emit a code for reduction clause. Next code should be emitted for
669 /// reduction:
670 /// \code
671 ///
672 /// static kmp_critical_name lock = { 0 };
673 ///
674 /// void reduce_func(void *lhs[<n>], void *rhs[<n>]) {
675 /// ...
676 /// *(Type<i>*)lhs[i] = RedOp<i>(*(Type<i>*)lhs[i], *(Type<i>*)rhs[i]);
677 /// ...
678 /// }
679 ///
680 /// ...
681 /// void *RedList[<n>] = {&<RHSExprs>[0], ..., &<RHSExprs>[<n>-1]};
682 /// switch (__kmpc_reduce{_nowait}(<loc>, <gtid>, <n>, sizeof(RedList),
683 /// RedList, reduce_func, &<lock>)) {
684 /// case 1:
685 /// ...
686 /// <LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]);
687 /// ...
688 /// __kmpc_end_reduce{_nowait}(<loc>, <gtid>, &<lock>);
689 /// break;
690 /// case 2:
691 /// ...
692 /// Atomic(<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]));
693 /// ...
694 /// break;
695 /// default:;
696 /// }
697 /// \endcode
698 ///
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000699 /// \param Privates List of private copies for original reduction arguments.
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000700 /// \param LHSExprs List of LHS in \a ReductionOps reduction operations.
701 /// \param RHSExprs List of RHS in \a ReductionOps reduction operations.
702 /// \param ReductionOps List of reduction operations in form 'LHS binop RHS'
703 /// or 'operator binop(LHS, RHS)'.
704 /// \param WithNowait true if parent directive has also nowait clause, false
705 /// otherwise.
706 virtual void emitReduction(CodeGenFunction &CGF, SourceLocation Loc,
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000707 ArrayRef<const Expr *> Privates,
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000708 ArrayRef<const Expr *> LHSExprs,
709 ArrayRef<const Expr *> RHSExprs,
710 ArrayRef<const Expr *> ReductionOps,
Alexey Bataev89e7e8e2015-06-17 06:21:39 +0000711 bool WithNowait, bool SimpleReduction);
Alexey Bataev8b8e2022015-04-27 05:22:09 +0000712
713 /// \brief Emit code for 'taskwait' directive.
714 virtual void emitTaskwaitCall(CodeGenFunction &CGF, SourceLocation Loc);
Alexey Bataev0f34da12015-07-02 04:17:07 +0000715
716 /// \brief Emit code for 'cancellation point' construct.
717 /// \param CancelRegion Region kind for which the cancellation point must be
718 /// emitted.
719 ///
720 virtual void emitCancellationPointCall(CodeGenFunction &CGF,
721 SourceLocation Loc,
722 OpenMPDirectiveKind CancelRegion);
Alexey Bataev7d5d33e2015-07-06 05:50:32 +0000723
724 /// \brief Emit code for 'cancel' construct.
Alexey Bataev87933c72015-09-18 08:07:34 +0000725 /// \param IfCond Condition in the associated 'if' clause, if it was
726 /// specified, nullptr otherwise.
Alexey Bataev7d5d33e2015-07-06 05:50:32 +0000727 /// \param CancelRegion Region kind for which the cancel must be emitted.
728 ///
729 virtual void emitCancelCall(CodeGenFunction &CGF, SourceLocation Loc,
Alexey Bataev87933c72015-09-18 08:07:34 +0000730 const Expr *IfCond,
Alexey Bataev7d5d33e2015-07-06 05:50:32 +0000731 OpenMPDirectiveKind CancelRegion);
Samuel Antaobed3c462015-10-02 16:14:20 +0000732
733 /// \brief Emit outilined function for 'target' directive.
734 /// \param D Directive to emit.
Samuel Antaoee8fb302016-01-06 13:42:12 +0000735 /// \param ParentName Name of the function that encloses the target region.
736 /// \param OutlinedFn Outlined function value to be defined by this call.
737 /// \param OutlinedFnID Outlined function ID value to be defined by this call.
738 /// \param IsOffloadEntry True if the outlined function is an offload entry.
739 /// An oulined function may not be an entry if, e.g. the if clause always
740 /// evaluates to false.
741 virtual void emitTargetOutlinedFunction(const OMPExecutableDirective &D,
742 StringRef ParentName,
743 llvm::Function *&OutlinedFn,
744 llvm::Constant *&OutlinedFnID,
745 bool IsOffloadEntry);
Samuel Antaobed3c462015-10-02 16:14:20 +0000746
747 /// \brief Emit the target offloading code associated with \a D. The emitted
748 /// code attempts offloading the execution to the device, an the event of
749 /// a failure it executes the host version outlined in \a OutlinedFn.
750 /// \param D Directive to emit.
751 /// \param OutlinedFn Host version of the code to be offloaded.
Samuel Antaoee8fb302016-01-06 13:42:12 +0000752 /// \param OutlinedFnID ID of host version of the code to be offloaded.
Samuel Antaobed3c462015-10-02 16:14:20 +0000753 /// \param IfCond Expression evaluated in if clause associated with the target
754 /// directive, or null if no if clause is used.
755 /// \param Device Expression evaluated in device clause associated with the
756 /// target directive, or null if no device clause is used.
757 /// \param CapturedVars Values captured in the current region.
758 virtual void emitTargetCall(CodeGenFunction &CGF,
759 const OMPExecutableDirective &D,
Samuel Antaoee8fb302016-01-06 13:42:12 +0000760 llvm::Value *OutlinedFn,
761 llvm::Value *OutlinedFnID, const Expr *IfCond,
Samuel Antaobed3c462015-10-02 16:14:20 +0000762 const Expr *Device,
763 ArrayRef<llvm::Value *> CapturedVars);
Samuel Antaoee8fb302016-01-06 13:42:12 +0000764
765 /// \brief Emit the target regions enclosed in \a GD function definition or
766 /// the function itself in case it is a valid device function. Returns true if
767 /// \a GD was dealt with successfully.
Nico Webera2abe8c2016-01-06 19:13:49 +0000768 /// \param GD Function to scan.
Samuel Antaoee8fb302016-01-06 13:42:12 +0000769 virtual bool emitTargetFunctions(GlobalDecl GD);
770
771 /// \brief Emit the global variable if it is a valid device global variable.
772 /// Returns true if \a GD was dealt with successfully.
773 /// \param GD Variable declaration to emit.
774 virtual bool emitTargetGlobalVariable(GlobalDecl GD);
775
776 /// \brief Emit the global \a GD if it is meaningful for the target. Returns
777 /// if it was emitted succesfully.
778 /// \param GD Global to scan.
779 virtual bool emitTargetGlobal(GlobalDecl GD);
780
781 /// \brief Creates the offloading descriptor in the event any target region
782 /// was emitted in the current module and return the function that registers
783 /// it.
784 virtual llvm::Function *emitRegistrationFunction();
Alexey Bataev9959db52014-05-06 10:08:46 +0000785};
Alexey Bataev8cbe0a62015-02-26 10:27:34 +0000786
Alexey Bataev23b69422014-06-18 07:08:49 +0000787} // namespace CodeGen
788} // namespace clang
Alexey Bataev9959db52014-05-06 10:08:46 +0000789
790#endif