blob: 9dd7744346b4ec07172037fca210698d42fd307d [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;
Alexey Bataevc5b1d322016-03-04 09:22:22 +000041class OMPDeclareReductionDecl;
42class IdentifierInfo;
Alexey Bataev18095712014-10-10 12:19:54 +000043
Alexey Bataev9959db52014-05-06 10:08:46 +000044namespace CodeGen {
John McCall7f416cc2015-09-08 08:05:57 +000045class Address;
Alexey Bataev18095712014-10-10 12:19:54 +000046class CodeGenFunction;
47class CodeGenModule;
Alexey Bataev9959db52014-05-06 10:08:46 +000048
Alexey Bataev6f1ffc02015-04-10 04:50:10 +000049typedef llvm::function_ref<void(CodeGenFunction &)> RegionCodeGenTy;
50
Alexey Bataev9959db52014-05-06 10:08:46 +000051class CGOpenMPRuntime {
Alexey Bataev9959db52014-05-06 10:08:46 +000052 CodeGenModule &CGM;
53 /// \brief Default const ident_t object used for initialization of all other
54 /// ident_t objects.
Alexey Bataevc5b1d322016-03-04 09:22:22 +000055 llvm::Constant *DefaultOpenMPPSource = nullptr;
Alexey Bataev18095712014-10-10 12:19:54 +000056 /// \brief Map of flags and corresponding default locations.
Alexey Bataev15007ba2014-05-07 06:18:01 +000057 typedef llvm::DenseMap<unsigned, llvm::Value *> OpenMPDefaultLocMapTy;
58 OpenMPDefaultLocMapTy OpenMPDefaultLocMap;
Alexey Bataev50b3c952016-02-19 10:38:26 +000059 Address getOrCreateDefaultLocation(unsigned Flags);
John McCall7f416cc2015-09-08 08:05:57 +000060
Alexey Bataev9959db52014-05-06 10:08:46 +000061 llvm::StructType *IdentTy;
Alexey Bataev18095712014-10-10 12:19:54 +000062 /// \brief Map for SourceLocation and OpenMP runtime library debug locations.
Alexey Bataevf002aca2014-05-30 05:48:40 +000063 typedef llvm::DenseMap<unsigned, llvm::Value *> OpenMPDebugLocMapTy;
64 OpenMPDebugLocMapTy OpenMPDebugLocMap;
Alexey Bataev9959db52014-05-06 10:08:46 +000065 /// \brief The type for a microtask which gets passed to __kmpc_fork_call().
66 /// Original representation is:
67 /// typedef void (kmpc_micro)(kmp_int32 global_tid, kmp_int32 bound_tid,...);
68 llvm::FunctionType *Kmpc_MicroTy;
Alexey Bataev18095712014-10-10 12:19:54 +000069 /// \brief Stores debug location and ThreadID for the function.
70 struct DebugLocThreadIdTy {
71 llvm::Value *DebugLoc;
72 llvm::Value *ThreadID;
73 };
74 /// \brief Map of local debug location, ThreadId and functions.
75 typedef llvm::DenseMap<llvm::Function *, DebugLocThreadIdTy>
76 OpenMPLocThreadIDMapTy;
77 OpenMPLocThreadIDMapTy OpenMPLocThreadIDMap;
Alexey Bataevc5b1d322016-03-04 09:22:22 +000078 /// Map of UDRs and corresponding combiner/initializer.
79 typedef llvm::DenseMap<const OMPDeclareReductionDecl *,
80 std::pair<llvm::Function *, llvm::Function *>>
81 UDRMapTy;
82 UDRMapTy UDRMap;
83 /// Map of functions and locally defined UDRs.
84 typedef llvm::DenseMap<llvm::Function *,
85 SmallVector<const OMPDeclareReductionDecl *, 4>>
86 FunctionUDRMapTy;
87 FunctionUDRMapTy FunctionUDRMap;
88 IdentifierInfo *In = nullptr;
89 IdentifierInfo *Out = nullptr;
90 IdentifierInfo *Priv = nullptr;
91 IdentifierInfo *Orig = nullptr;
Alexey Bataev3a3bf0b2014-09-22 10:01:53 +000092 /// \brief Type kmp_critical_name, originally defined as typedef kmp_int32
93 /// kmp_critical_name[8];
94 llvm::ArrayType *KmpCriticalNameTy;
Alexey Bataev97720002014-11-11 04:05:39 +000095 /// \brief An ordered map of auto-generated variables to their unique names.
96 /// It stores variables with the following names: 1) ".gomp_critical_user_" +
97 /// <critical_section_name> + ".var" for "omp critical" directives; 2)
98 /// <mangled_name_for_global_var> + ".cache." for cache for threadprivate
99 /// variables.
100 llvm::StringMap<llvm::AssertingVH<llvm::Constant>, llvm::BumpPtrAllocator>
101 InternalVars;
Alexey Bataev62b63b12015-03-10 07:28:44 +0000102 /// \brief Type typedef kmp_int32 (* kmp_routine_entry_t)(kmp_int32, void *);
Alexey Bataevc5b1d322016-03-04 09:22:22 +0000103 llvm::Type *KmpRoutineEntryPtrTy = nullptr;
Alexey Bataev62b63b12015-03-10 07:28:44 +0000104 QualType KmpRoutineEntryPtrQTy;
Alexey Bataev8fc69dc2015-05-18 07:54:53 +0000105 /// \brief Type typedef struct kmp_task {
106 /// void * shareds; /**< pointer to block of pointers to
107 /// shared vars */
108 /// kmp_routine_entry_t routine; /**< pointer to routine to call for
109 /// executing task */
110 /// kmp_int32 part_id; /**< part id for the task */
111 /// kmp_routine_entry_t destructors; /* pointer to function to invoke
112 /// deconstructors of firstprivate C++ objects */
113 /// } kmp_task_t;
114 QualType KmpTaskTQTy;
Alexey Bataev1d2353d2015-06-24 11:01:36 +0000115 /// \brief Type typedef struct kmp_depend_info {
116 /// kmp_intptr_t base_addr;
117 /// size_t len;
118 /// struct {
119 /// bool in:1;
120 /// bool out:1;
121 /// } flags;
122 /// } kmp_depend_info_t;
123 QualType KmpDependInfoTy;
Samuel Antaoee8fb302016-01-06 13:42:12 +0000124 /// \brief Type struct __tgt_offload_entry{
125 /// void *addr; // Pointer to the offload entry info.
126 /// // (function or global)
127 /// char *name; // Name of the function or global.
128 /// size_t size; // Size of the entry info (0 if it a function).
129 /// };
130 QualType TgtOffloadEntryQTy;
131 /// struct __tgt_device_image{
132 /// void *ImageStart; // Pointer to the target code start.
133 /// void *ImageEnd; // Pointer to the target code end.
134 /// // We also add the host entries to the device image, as it may be useful
135 /// // for the target runtime to have access to that information.
136 /// __tgt_offload_entry *EntriesBegin; // Begin of the table with all
137 /// // the entries.
138 /// __tgt_offload_entry *EntriesEnd; // End of the table with all the
139 /// // entries (non inclusive).
140 /// };
141 QualType TgtDeviceImageQTy;
142 /// struct __tgt_bin_desc{
143 /// int32_t NumDevices; // Number of devices supported.
144 /// __tgt_device_image *DeviceImages; // Arrays of device images
145 /// // (one per device).
146 /// __tgt_offload_entry *EntriesBegin; // Begin of the table with all the
147 /// // entries.
148 /// __tgt_offload_entry *EntriesEnd; // End of the table with all the
149 /// // entries (non inclusive).
150 /// };
151 QualType TgtBinaryDescriptorQTy;
152 /// \brief Entity that registers the offloading constants that were emitted so
153 /// far.
154 class OffloadEntriesInfoManagerTy {
155 CodeGenModule &CGM;
Alexey Bataev1d2353d2015-06-24 11:01:36 +0000156
Samuel Antaoee8fb302016-01-06 13:42:12 +0000157 /// \brief Number of entries registered so far.
158 unsigned OffloadingEntriesNum;
159
160 public:
161 /// \brief Base class of the entries info.
162 class OffloadEntryInfo {
163 public:
164 /// \brief Kind of a given entry. Currently, only target regions are
165 /// supported.
Reid Klecknerdc78f952016-01-11 20:55:16 +0000166 enum OffloadingEntryInfoKinds : unsigned {
Samuel Antaoee8fb302016-01-06 13:42:12 +0000167 // Entry is a target region.
168 OFFLOAD_ENTRY_INFO_TARGET_REGION = 0,
169 // Invalid entry info.
170 OFFLOAD_ENTRY_INFO_INVALID = ~0u
171 };
172
173 OffloadEntryInfo() : Order(~0u), Kind(OFFLOAD_ENTRY_INFO_INVALID) {}
174 explicit OffloadEntryInfo(OffloadingEntryInfoKinds Kind, unsigned Order)
175 : Order(Order), Kind(Kind) {}
176
177 bool isValid() const { return Order != ~0u; }
178 unsigned getOrder() const { return Order; }
179 OffloadingEntryInfoKinds getKind() const { return Kind; }
180 static bool classof(const OffloadEntryInfo *Info) { return true; }
181
182 protected:
183 // \brief Order this entry was emitted.
184 unsigned Order;
185
186 OffloadingEntryInfoKinds Kind;
187 };
188
189 /// \brief Return true if a there are no entries defined.
190 bool empty() const;
191 /// \brief Return number of entries defined so far.
192 unsigned size() const { return OffloadingEntriesNum; }
193 OffloadEntriesInfoManagerTy(CodeGenModule &CGM)
194 : CGM(CGM), OffloadingEntriesNum(0) {}
195
196 ///
197 /// Target region entries related.
198 ///
199 /// \brief Target region entries info.
200 class OffloadEntryInfoTargetRegion : public OffloadEntryInfo {
201 // \brief Address of the entity that has to be mapped for offloading.
202 llvm::Constant *Addr;
203 // \brief Address that can be used as the ID of the entry.
204 llvm::Constant *ID;
205
206 public:
207 OffloadEntryInfoTargetRegion()
208 : OffloadEntryInfo(OFFLOAD_ENTRY_INFO_TARGET_REGION, ~0u),
209 Addr(nullptr), ID(nullptr) {}
210 explicit OffloadEntryInfoTargetRegion(unsigned Order,
211 llvm::Constant *Addr,
212 llvm::Constant *ID)
213 : OffloadEntryInfo(OFFLOAD_ENTRY_INFO_TARGET_REGION, Order),
214 Addr(Addr), ID(ID) {}
215
216 llvm::Constant *getAddress() const { return Addr; }
217 llvm::Constant *getID() const { return ID; }
218 void setAddress(llvm::Constant *V) {
219 assert(!Addr && "Address as been set before!");
220 Addr = V;
221 }
222 void setID(llvm::Constant *V) {
223 assert(!ID && "ID as been set before!");
224 ID = V;
225 }
226 static bool classof(const OffloadEntryInfo *Info) {
227 return Info->getKind() == OFFLOAD_ENTRY_INFO_TARGET_REGION;
228 }
229 };
230 /// \brief Initialize target region entry.
231 void initializeTargetRegionEntryInfo(unsigned DeviceID, unsigned FileID,
232 StringRef ParentName, unsigned LineNum,
Samuel Antao2de62b02016-02-13 23:35:10 +0000233 unsigned Order);
Samuel Antaoee8fb302016-01-06 13:42:12 +0000234 /// \brief Register target region entry.
235 void registerTargetRegionEntryInfo(unsigned DeviceID, unsigned FileID,
236 StringRef ParentName, unsigned LineNum,
Samuel Antao2de62b02016-02-13 23:35:10 +0000237 llvm::Constant *Addr,
Samuel Antaoee8fb302016-01-06 13:42:12 +0000238 llvm::Constant *ID);
239 /// \brief Return true if a target region entry with the provided
240 /// information exists.
241 bool hasTargetRegionEntryInfo(unsigned DeviceID, unsigned FileID,
Samuel Antao2de62b02016-02-13 23:35:10 +0000242 StringRef ParentName, unsigned LineNum) const;
Samuel Antaoee8fb302016-01-06 13:42:12 +0000243 /// brief Applies action \a Action on all registered entries.
244 typedef llvm::function_ref<void(unsigned, unsigned, StringRef, unsigned,
Samuel Antao2de62b02016-02-13 23:35:10 +0000245 OffloadEntryInfoTargetRegion &)>
Samuel Antaoee8fb302016-01-06 13:42:12 +0000246 OffloadTargetRegionEntryInfoActTy;
247 void actOnTargetRegionEntriesInfo(
248 const OffloadTargetRegionEntryInfoActTy &Action);
249
250 private:
251 // Storage for target region entries kind. The storage is to be indexed by
Samuel Antao2de62b02016-02-13 23:35:10 +0000252 // file ID, device ID, parent function name and line number.
Samuel Antaoee8fb302016-01-06 13:42:12 +0000253 typedef llvm::DenseMap<unsigned, OffloadEntryInfoTargetRegion>
Samuel Antaoee8fb302016-01-06 13:42:12 +0000254 OffloadEntriesTargetRegionPerLine;
255 typedef llvm::StringMap<OffloadEntriesTargetRegionPerLine>
256 OffloadEntriesTargetRegionPerParentName;
257 typedef llvm::DenseMap<unsigned, OffloadEntriesTargetRegionPerParentName>
258 OffloadEntriesTargetRegionPerFile;
259 typedef llvm::DenseMap<unsigned, OffloadEntriesTargetRegionPerFile>
260 OffloadEntriesTargetRegionPerDevice;
261 typedef OffloadEntriesTargetRegionPerDevice OffloadEntriesTargetRegionTy;
262 OffloadEntriesTargetRegionTy OffloadEntriesTargetRegion;
263 };
264 OffloadEntriesInfoManagerTy OffloadEntriesInfoManager;
265
266 /// \brief Creates and registers offloading binary descriptor for the current
267 /// compilation unit. The function that does the registration is returned.
268 llvm::Function *createOffloadingBinaryDescriptorRegistration();
269
Samuel Antao2de62b02016-02-13 23:35:10 +0000270 /// \brief Creates offloading entry for the provided entry ID \a ID,
271 /// address \a Addr and size \a Size.
272 void createOffloadEntry(llvm::Constant *ID, llvm::Constant *Addr,
273 uint64_t Size);
Samuel Antaoee8fb302016-01-06 13:42:12 +0000274
275 /// \brief Creates all the offload entries in the current compilation unit
276 /// along with the associated metadata.
277 void createOffloadEntriesAndInfoMetadata();
278
279 /// \brief Loads all the offload entries information from the host IR
280 /// metadata.
281 void loadOffloadInfoMetadata();
282
283 /// \brief Returns __tgt_offload_entry type.
284 QualType getTgtOffloadEntryQTy();
285
286 /// \brief Returns __tgt_device_image type.
287 QualType getTgtDeviceImageQTy();
288
289 /// \brief Returns __tgt_bin_desc type.
290 QualType getTgtBinaryDescriptorQTy();
291
292 /// \brief Start scanning from statement \a S and and emit all target regions
293 /// found along the way.
294 /// \param S Starting statement.
295 /// \param ParentName Name of the function declaration that is being scanned.
296 void scanForTargetRegionsFunctions(const Stmt *S, StringRef ParentName);
Alexey Bataev62b63b12015-03-10 07:28:44 +0000297
298 /// \brief Build type kmp_routine_entry_t (if not built yet).
299 void emitKmpRoutineEntryT(QualType KmpInt32Ty);
Alexey Bataev9959db52014-05-06 10:08:46 +0000300
Alexey Bataev9959db52014-05-06 10:08:46 +0000301 /// \brief Emits object of ident_t type with info for source location.
Alexey Bataev9959db52014-05-06 10:08:46 +0000302 /// \param Flags Flags for OpenMP location.
303 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000304 llvm::Value *emitUpdateLocation(CodeGenFunction &CGF, SourceLocation Loc,
Alexey Bataev50b3c952016-02-19 10:38:26 +0000305 unsigned Flags = 0);
Alexey Bataev9959db52014-05-06 10:08:46 +0000306
Alexey Bataevd74d0602014-10-13 06:02:40 +0000307 /// \brief Returns pointer to ident_t type.
Alexey Bataev9959db52014-05-06 10:08:46 +0000308 llvm::Type *getIdentTyPointerTy();
309
Alexey Bataevd74d0602014-10-13 06:02:40 +0000310 /// \brief Returns pointer to kmpc_micro type.
Alexey Bataev9959db52014-05-06 10:08:46 +0000311 llvm::Type *getKmpc_MicroPointerTy();
312
313 /// \brief Returns specified OpenMP runtime function.
314 /// \param Function OpenMP runtime function.
315 /// \return Specified function.
Alexey Bataev50b3c952016-02-19 10:38:26 +0000316 llvm::Constant *createRuntimeFunction(unsigned Function);
Alexey Bataev3a3bf0b2014-09-22 10:01:53 +0000317
Alexander Musman21212e42015-03-13 10:38:23 +0000318 /// \brief Returns __kmpc_for_static_init_* runtime function for the specified
319 /// size \a IVSize and sign \a IVSigned.
320 llvm::Constant *createForStaticInitFunction(unsigned IVSize, bool IVSigned);
321
Alexander Musman92bdaab2015-03-12 13:37:50 +0000322 /// \brief Returns __kmpc_dispatch_init_* runtime function for the specified
323 /// size \a IVSize and sign \a IVSigned.
324 llvm::Constant *createDispatchInitFunction(unsigned IVSize, bool IVSigned);
325
326 /// \brief Returns __kmpc_dispatch_next_* runtime function for the specified
327 /// size \a IVSize and sign \a IVSigned.
328 llvm::Constant *createDispatchNextFunction(unsigned IVSize, bool IVSigned);
329
Alexey Bataev98eb6e32015-04-22 11:15:40 +0000330 /// \brief Returns __kmpc_dispatch_fini_* runtime function for the specified
331 /// size \a IVSize and sign \a IVSigned.
332 llvm::Constant *createDispatchFiniFunction(unsigned IVSize, bool IVSigned);
333
Alexey Bataev97720002014-11-11 04:05:39 +0000334 /// \brief If the specified mangled name is not in the module, create and
335 /// return threadprivate cache object. This object is a pointer's worth of
336 /// storage that's reserved for use by the OpenMP runtime.
NAKAMURA Takumicdcbfba2014-11-11 07:58:06 +0000337 /// \param VD Threadprivate variable.
Alexey Bataev97720002014-11-11 04:05:39 +0000338 /// \return Cache variable for the specified threadprivate.
339 llvm::Constant *getOrCreateThreadPrivateCache(const VarDecl *VD);
340
Alexey Bataevd74d0602014-10-13 06:02:40 +0000341 /// \brief Emits address of the word in a memory where current thread id is
342 /// stored.
John McCall7f416cc2015-09-08 08:05:57 +0000343 virtual Address emitThreadIDAddress(CodeGenFunction &CGF, SourceLocation Loc);
Alexey Bataevd74d0602014-10-13 06:02:40 +0000344
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000345 /// \brief Gets thread id value for the current thread.
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000346 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000347 llvm::Value *getThreadID(CodeGenFunction &CGF, SourceLocation Loc);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000348
Alexey Bataev97720002014-11-11 04:05:39 +0000349 /// \brief Gets (if variable with the given name already exist) or creates
350 /// internal global variable with the specified Name. The created variable has
351 /// linkage CommonLinkage by default and is initialized by null value.
352 /// \param Ty Type of the global variable. If it is exist already the type
353 /// must be the same.
354 /// \param Name Name of the variable.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000355 llvm::Constant *getOrCreateInternalVariable(llvm::Type *Ty,
Alexey Bataev97720002014-11-11 04:05:39 +0000356 const llvm::Twine &Name);
357
358 /// \brief Set of threadprivate variables with the generated initializer.
Benjamin Kramer8fdba912016-02-02 14:24:21 +0000359 llvm::SmallPtrSet<const VarDecl *, 4> ThreadPrivateWithDefinition;
Alexey Bataev97720002014-11-11 04:05:39 +0000360
361 /// \brief Emits initialization code for the threadprivate variables.
362 /// \param VDAddr Address of the global variable \a VD.
363 /// \param Ctor Pointer to a global init function for \a VD.
364 /// \param CopyCtor Pointer to a global copy function for \a VD.
365 /// \param Dtor Pointer to a global destructor function for \a VD.
366 /// \param Loc Location of threadprivate declaration.
John McCall7f416cc2015-09-08 08:05:57 +0000367 void emitThreadPrivateVarInit(CodeGenFunction &CGF, Address VDAddr,
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000368 llvm::Value *Ctor, llvm::Value *CopyCtor,
369 llvm::Value *Dtor, SourceLocation Loc);
Alexey Bataev97720002014-11-11 04:05:39 +0000370
Alexey Bataev75ddfab2014-12-01 11:32:38 +0000371 /// \brief Returns corresponding lock object for the specified critical region
372 /// name. If the lock object does not exist it is created, otherwise the
373 /// reference to the existing copy is returned.
374 /// \param CriticalName Name of the critical region.
375 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000376 llvm::Value *getCriticalRegionLock(StringRef CriticalName);
Alexey Bataev75ddfab2014-12-01 11:32:38 +0000377
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000378public:
379 explicit CGOpenMPRuntime(CodeGenModule &CGM);
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +0000380 virtual ~CGOpenMPRuntime() {}
Alexey Bataev91797552015-03-18 04:13:55 +0000381 virtual void clear();
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000382
Alexey Bataevc5b1d322016-03-04 09:22:22 +0000383 /// Emit code for the specified user defined reduction construct.
384 virtual void emitUserDefinedReduction(CodeGenFunction *CGF,
385 const OMPDeclareReductionDecl *D);
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000386 /// \brief Emits outlined function for the specified OpenMP parallel directive
387 /// \a D. This outlined function has type void(*)(kmp_int32 *ThreadID,
388 /// kmp_int32 BoundID, struct context_vars*).
Alexey Bataev18095712014-10-10 12:19:54 +0000389 /// \param D OpenMP directive.
390 /// \param ThreadIDVar Variable for thread id in the current OpenMP region.
Alexey Bataev81c7ea02015-07-03 09:56:58 +0000391 /// \param InnermostKind Kind of innermost directive (for simple directives it
392 /// is a directive itself, for combined - its innermost directive).
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000393 /// \param CodeGen Code generation sequence for the \a D directive.
Carlo Bertolli430d8ec2016-03-03 20:34:23 +0000394 virtual llvm::Value *emitParallelOrTeamsOutlinedFunction(
Alexey Bataev81c7ea02015-07-03 09:56:58 +0000395 const OMPExecutableDirective &D, const VarDecl *ThreadIDVar,
396 OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen);
Alexey Bataev18095712014-10-10 12:19:54 +0000397
Alexey Bataev62b63b12015-03-10 07:28:44 +0000398 /// \brief Emits outlined function for the OpenMP task directive \a D. This
399 /// outlined function has type void(*)(kmp_int32 ThreadID, kmp_int32
400 /// PartID, struct context_vars*).
401 /// \param D OpenMP directive.
402 /// \param ThreadIDVar Variable for thread id in the current OpenMP region.
Alexey Bataev81c7ea02015-07-03 09:56:58 +0000403 /// \param InnermostKind Kind of innermost directive (for simple directives it
404 /// is a directive itself, for combined - its innermost directive).
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000405 /// \param CodeGen Code generation sequence for the \a D directive.
Alexey Bataev62b63b12015-03-10 07:28:44 +0000406 ///
Alexey Bataev81c7ea02015-07-03 09:56:58 +0000407 virtual llvm::Value *emitTaskOutlinedFunction(
408 const OMPExecutableDirective &D, const VarDecl *ThreadIDVar,
409 OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen);
Alexey Bataev62b63b12015-03-10 07:28:44 +0000410
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000411 /// \brief Cleans up references to the objects in finished function.
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000412 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000413 void functionFinished(CodeGenFunction &CGF);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000414
Alexey Bataev1d677132015-04-22 13:57:31 +0000415 /// \brief Emits code for parallel or serial call of the \a OutlinedFn with
416 /// variables captured in a record which address is stored in \a
417 /// CapturedStruct.
Alexey Bataev18095712014-10-10 12:19:54 +0000418 /// \param OutlinedFn Outlined function to be run in parallel threads. Type of
Alexey Bataev62b63b12015-03-10 07:28:44 +0000419 /// this function is void(*)(kmp_int32 *, kmp_int32, struct context_vars*).
NAKAMURA Takumi62f0eb52015-09-11 08:13:32 +0000420 /// \param CapturedVars A pointer to the record with the references to
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000421 /// variables used in \a OutlinedFn function.
Alexey Bataev1d677132015-04-22 13:57:31 +0000422 /// \param IfCond Condition in the associated 'if' clause, if it was
423 /// specified, nullptr otherwise.
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000424 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000425 virtual void emitParallelCall(CodeGenFunction &CGF, SourceLocation Loc,
426 llvm::Value *OutlinedFn,
Alexey Bataev2377fe92015-09-10 08:12:02 +0000427 ArrayRef<llvm::Value *> CapturedVars,
428 const Expr *IfCond);
Alexey Bataevd74d0602014-10-13 06:02:40 +0000429
Alexey Bataev75ddfab2014-12-01 11:32:38 +0000430 /// \brief Emits a critical region.
Alexey Bataev18095712014-10-10 12:19:54 +0000431 /// \param CriticalName Name of the critical region.
Alexey Bataev75ddfab2014-12-01 11:32:38 +0000432 /// \param CriticalOpGen Generator for the statement associated with the given
433 /// critical region.
Alexey Bataevfc57d162015-12-15 10:55:09 +0000434 /// \param Hint Value of the 'hint' clause (optional).
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000435 virtual void emitCriticalRegion(CodeGenFunction &CGF, StringRef CriticalName,
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000436 const RegionCodeGenTy &CriticalOpGen,
Alexey Bataevfc57d162015-12-15 10:55:09 +0000437 SourceLocation Loc,
438 const Expr *Hint = nullptr);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000439
Alexey Bataev8d690652014-12-04 07:23:53 +0000440 /// \brief Emits a master region.
441 /// \param MasterOpGen Generator for the statement associated with the given
442 /// master region.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000443 virtual void emitMasterRegion(CodeGenFunction &CGF,
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000444 const RegionCodeGenTy &MasterOpGen,
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000445 SourceLocation Loc);
Alexey Bataev8d690652014-12-04 07:23:53 +0000446
Alexey Bataev9f797f32015-02-05 05:57:51 +0000447 /// \brief Emits code for a taskyield directive.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000448 virtual void emitTaskyieldCall(CodeGenFunction &CGF, SourceLocation Loc);
Alexey Bataev9f797f32015-02-05 05:57:51 +0000449
Alexey Bataevc30dd2d2015-06-18 12:14:09 +0000450 /// \brief Emit a taskgroup region.
451 /// \param TaskgroupOpGen Generator for the statement associated with the
452 /// given taskgroup region.
453 virtual void emitTaskgroupRegion(CodeGenFunction &CGF,
454 const RegionCodeGenTy &TaskgroupOpGen,
455 SourceLocation Loc);
456
Alexey Bataev6956e2e2015-02-05 06:35:41 +0000457 /// \brief Emits a single region.
458 /// \param SingleOpGen Generator for the statement associated with the given
459 /// single region.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000460 virtual void emitSingleRegion(CodeGenFunction &CGF,
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000461 const RegionCodeGenTy &SingleOpGen,
Alexey Bataeva63048e2015-03-23 06:18:07 +0000462 SourceLocation Loc,
463 ArrayRef<const Expr *> CopyprivateVars,
Alexey Bataev420d45b2015-04-14 05:11:24 +0000464 ArrayRef<const Expr *> DestExprs,
Alexey Bataeva63048e2015-03-23 06:18:07 +0000465 ArrayRef<const Expr *> SrcExprs,
Alexey Bataeva63048e2015-03-23 06:18:07 +0000466 ArrayRef<const Expr *> AssignmentOps);
Alexey Bataev6956e2e2015-02-05 06:35:41 +0000467
Alexey Bataev98eb6e32015-04-22 11:15:40 +0000468 /// \brief Emit an ordered region.
469 /// \param OrderedOpGen Generator for the statement associated with the given
Alexey Bataevc30dd2d2015-06-18 12:14:09 +0000470 /// ordered region.
Alexey Bataev98eb6e32015-04-22 11:15:40 +0000471 virtual void emitOrderedRegion(CodeGenFunction &CGF,
472 const RegionCodeGenTy &OrderedOpGen,
Alexey Bataev5f600d62015-09-29 03:48:57 +0000473 SourceLocation Loc, bool IsThreads);
Alexey Bataev98eb6e32015-04-22 11:15:40 +0000474
Alexey Bataevf2685682015-03-30 04:30:22 +0000475 /// \brief Emit an implicit/explicit barrier for OpenMP threads.
476 /// \param Kind Directive for which this implicit barrier call must be
477 /// generated. Must be OMPD_barrier for explicit barrier generation.
Alexey Bataev25e5b442015-09-15 12:52:43 +0000478 /// \param EmitChecks true if need to emit checks for cancellation barriers.
479 /// \param ForceSimpleCall true simple barrier call must be emitted, false if
480 /// runtime class decides which one to emit (simple or with cancellation
481 /// checks).
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000482 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000483 virtual void emitBarrierCall(CodeGenFunction &CGF, SourceLocation Loc,
Alexey Bataev81c7ea02015-07-03 09:56:58 +0000484 OpenMPDirectiveKind Kind,
Alexey Bataev25e5b442015-09-15 12:52:43 +0000485 bool EmitChecks = true,
486 bool ForceSimpleCall = false);
Alexey Bataevb2059782014-10-13 08:23:51 +0000487
Alexander Musmanc6388682014-12-15 07:07:06 +0000488 /// \brief Check if the specified \a ScheduleKind is static non-chunked.
489 /// This kind of worksharing directive is emitted without outer loop.
490 /// \param ScheduleKind Schedule kind specified in the 'schedule' clause.
491 /// \param Chunked True if chunk is specified in the clause.
492 ///
493 virtual bool isStaticNonchunked(OpenMPScheduleClauseKind ScheduleKind,
494 bool Chunked) const;
495
Alexander Musmandf7a8e22015-01-22 08:49:35 +0000496 /// \brief Check if the specified \a ScheduleKind is dynamic.
497 /// This kind of worksharing directive is emitted without outer loop.
498 /// \param ScheduleKind Schedule Kind specified in the 'schedule' clause.
499 ///
500 virtual bool isDynamic(OpenMPScheduleClauseKind ScheduleKind) const;
501
NAKAMURA Takumiff7a9252015-09-08 09:42:41 +0000502 virtual void emitForDispatchInit(CodeGenFunction &CGF, SourceLocation Loc,
503 OpenMPScheduleClauseKind SchedKind,
504 unsigned IVSize, bool IVSigned,
505 bool Ordered, llvm::Value *UB,
506 llvm::Value *Chunk = nullptr);
507
Alexander Musmanc6388682014-12-15 07:07:06 +0000508 /// \brief Call the appropriate runtime routine to initialize it before start
509 /// of loop.
510 ///
511 /// Depending on the loop schedule, it is nesessary to call some runtime
512 /// routine before start of the OpenMP loop to get the loop upper / lower
513 /// bounds \a LB and \a UB and stride \a ST.
514 ///
515 /// \param CGF Reference to current CodeGenFunction.
516 /// \param Loc Clang source location.
NAKAMURA Takumieca08382014-12-17 14:47:06 +0000517 /// \param SchedKind Schedule kind, specified by the 'schedule' clause.
Alexander Musmanc6388682014-12-15 07:07:06 +0000518 /// \param IVSize Size of the iteration variable in bits.
519 /// \param IVSigned Sign of the interation variable.
Alexey Bataevd7589ffe2015-05-20 13:12:48 +0000520 /// \param Ordered true if loop is ordered, false otherwise.
Alexander Musmanc6388682014-12-15 07:07:06 +0000521 /// \param IL Address of the output variable in which the flag of the
522 /// last iteration is returned.
523 /// \param LB Address of the output variable in which the lower iteration
524 /// number is returned.
525 /// \param UB Address of the output variable in which the upper iteration
526 /// number is returned.
527 /// \param ST Address of the output variable in which the stride value is
528 /// returned nesessary to generated the static_chunked scheduled loop.
529 /// \param Chunk Value of the chunk for the static_chunked scheduled loop.
530 /// For the default (nullptr) value, the chunk 1 will be used.
531 ///
John McCall7f416cc2015-09-08 08:05:57 +0000532 virtual void emitForStaticInit(CodeGenFunction &CGF, SourceLocation Loc,
533 OpenMPScheduleClauseKind SchedKind,
534 unsigned IVSize, bool IVSigned, bool Ordered,
535 Address IL, Address LB,
536 Address UB, Address ST,
537 llvm::Value *Chunk = nullptr);
Alexander Musmanc6388682014-12-15 07:07:06 +0000538
539 /// \brief Call the appropriate runtime routine to notify that we finished
Alexey Bataev98eb6e32015-04-22 11:15:40 +0000540 /// iteration of the ordered loop with the dynamic scheduling.
541 ///
542 /// \param CGF Reference to current CodeGenFunction.
543 /// \param Loc Clang source location.
544 /// \param IVSize Size of the iteration variable in bits.
545 /// \param IVSigned Sign of the interation variable.
546 ///
Alexey Bataevd7589ffe2015-05-20 13:12:48 +0000547 virtual void emitForOrderedIterationEnd(CodeGenFunction &CGF,
548 SourceLocation Loc, unsigned IVSize,
549 bool IVSigned);
Alexey Bataev98eb6e32015-04-22 11:15:40 +0000550
551 /// \brief Call the appropriate runtime routine to notify that we finished
Alexander Musmanc6388682014-12-15 07:07:06 +0000552 /// all the work with current loop.
553 ///
554 /// \param CGF Reference to current CodeGenFunction.
555 /// \param Loc Clang source location.
Alexander Musmanc6388682014-12-15 07:07:06 +0000556 ///
Alexey Bataev98eb6e32015-04-22 11:15:40 +0000557 virtual void emitForStaticFinish(CodeGenFunction &CGF, SourceLocation Loc);
Alexander Musmanc6388682014-12-15 07:07:06 +0000558
Alexander Musman92bdaab2015-03-12 13:37:50 +0000559 /// Call __kmpc_dispatch_next(
560 /// ident_t *loc, kmp_int32 tid, kmp_int32 *p_lastiter,
561 /// kmp_int[32|64] *p_lower, kmp_int[32|64] *p_upper,
562 /// kmp_int[32|64] *p_stride);
563 /// \param IVSize Size of the iteration variable in bits.
564 /// \param IVSigned Sign of the interation variable.
565 /// \param IL Address of the output variable in which the flag of the
566 /// last iteration is returned.
567 /// \param LB Address of the output variable in which the lower iteration
568 /// number is returned.
569 /// \param UB Address of the output variable in which the upper iteration
570 /// number is returned.
571 /// \param ST Address of the output variable in which the stride value is
572 /// returned.
573 virtual llvm::Value *emitForNext(CodeGenFunction &CGF, SourceLocation Loc,
574 unsigned IVSize, bool IVSigned,
John McCall7f416cc2015-09-08 08:05:57 +0000575 Address IL, Address LB,
576 Address UB, Address ST);
Alexander Musman92bdaab2015-03-12 13:37:50 +0000577
Alexey Bataevb2059782014-10-13 08:23:51 +0000578 /// \brief Emits call to void __kmpc_push_num_threads(ident_t *loc, kmp_int32
579 /// global_tid, kmp_int32 num_threads) to generate code for 'num_threads'
580 /// clause.
581 /// \param NumThreads An integer value of threads.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000582 virtual void emitNumThreadsClause(CodeGenFunction &CGF,
583 llvm::Value *NumThreads,
584 SourceLocation Loc);
Alexey Bataev97720002014-11-11 04:05:39 +0000585
Alexey Bataev7f210c62015-06-18 13:40:03 +0000586 /// \brief Emit call to void __kmpc_push_proc_bind(ident_t *loc, kmp_int32
587 /// global_tid, int proc_bind) to generate code for 'proc_bind' clause.
588 virtual void emitProcBindClause(CodeGenFunction &CGF,
589 OpenMPProcBindClauseKind ProcBind,
590 SourceLocation Loc);
591
Alexey Bataev97720002014-11-11 04:05:39 +0000592 /// \brief Returns address of the threadprivate variable for the current
593 /// thread.
NAKAMURA Takumicdcbfba2014-11-11 07:58:06 +0000594 /// \param VD Threadprivate variable.
Alexey Bataev97720002014-11-11 04:05:39 +0000595 /// \param VDAddr Address of the global variable \a VD.
596 /// \param Loc Location of the reference to threadprivate var.
597 /// \return Address of the threadprivate variable for the current thread.
John McCall7f416cc2015-09-08 08:05:57 +0000598 virtual Address getAddrOfThreadPrivate(CodeGenFunction &CGF,
599 const VarDecl *VD,
600 Address VDAddr,
601 SourceLocation Loc);
Alexey Bataev97720002014-11-11 04:05:39 +0000602
603 /// \brief Emit a code for initialization of threadprivate variable. It emits
604 /// a call to runtime library which adds initial value to the newly created
605 /// threadprivate variable (if it is not constant) and registers destructor
606 /// for the variable (if any).
607 /// \param VD Threadprivate variable.
608 /// \param VDAddr Address of the global variable \a VD.
609 /// \param Loc Location of threadprivate declaration.
610 /// \param PerformInit true if initialization expression is not constant.
611 virtual llvm::Function *
John McCall7f416cc2015-09-08 08:05:57 +0000612 emitThreadPrivateVarDefinition(const VarDecl *VD, Address VDAddr,
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000613 SourceLocation Loc, bool PerformInit,
614 CodeGenFunction *CGF = nullptr);
Alexey Bataevcc37cc12014-11-20 04:34:54 +0000615
616 /// \brief Emit flush of the variables specified in 'omp flush' directive.
617 /// \param Vars List of variables to flush.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000618 virtual void emitFlush(CodeGenFunction &CGF, ArrayRef<const Expr *> Vars,
619 SourceLocation Loc);
Alexey Bataev62b63b12015-03-10 07:28:44 +0000620
621 /// \brief Emit task region for the task directive. The task region is
Nico Weber20b0ce32015-04-28 18:19:18 +0000622 /// emitted in several steps:
Alexey Bataev62b63b12015-03-10 07:28:44 +0000623 /// 1. Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32
624 /// gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds,
625 /// kmp_routine_entry_t *task_entry). Here task_entry is a pointer to the
626 /// function:
627 /// kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) {
628 /// TaskFunction(gtid, tt->part_id, tt->shareds);
629 /// return 0;
630 /// }
631 /// 2. Copy a list of shared variables to field shareds of the resulting
632 /// structure kmp_task_t returned by the previous call (if any).
633 /// 3. Copy a pointer to destructions function to field destructions of the
634 /// resulting structure kmp_task_t.
635 /// 4. Emit a call to kmp_int32 __kmpc_omp_task(ident_t *, kmp_int32 gtid,
636 /// kmp_task_t *new_task), where new_task is a resulting structure from
637 /// previous items.
Alexey Bataev36c1eb92015-04-30 06:51:57 +0000638 /// \param D Current task directive.
Alexey Bataev62b63b12015-03-10 07:28:44 +0000639 /// \param Tied true if the task is tied (the task is tied to the thread that
640 /// can suspend its task region), false - untied (the task is not tied to any
641 /// thread).
642 /// \param Final Contains either constant bool value, or llvm::Value * of i1
643 /// type for final clause. If the value is true, the task forces all of its
644 /// child tasks to become final and included tasks.
645 /// \param TaskFunction An LLVM function with type void (*)(i32 /*gtid*/, i32
646 /// /*part_id*/, captured_struct */*__context*/);
647 /// \param SharedsTy A type which contains references the shared variables.
Alexey Bataev1d2353d2015-06-24 11:01:36 +0000648 /// \param Shareds Context with the list of shared variables from the \p
Alexey Bataev62b63b12015-03-10 07:28:44 +0000649 /// TaskFunction.
Alexey Bataev1d677132015-04-22 13:57:31 +0000650 /// \param IfCond Not a nullptr if 'if' clause was specified, nullptr
651 /// otherwise.
Alexey Bataev36c1eb92015-04-30 06:51:57 +0000652 /// \param PrivateVars List of references to private variables for the task
653 /// directive.
654 /// \param PrivateCopies List of private copies for each private variable in
Alexey Bataev9e034042015-05-05 04:05:12 +0000655 /// \p PrivateVars.
656 /// \param FirstprivateVars List of references to private variables for the
657 /// task directive.
658 /// \param FirstprivateCopies List of private copies for each private variable
659 /// in \p FirstprivateVars.
660 /// \param FirstprivateInits List of references to auto generated variables
661 /// used for initialization of a single array element. Used if firstprivate
662 /// variable is of array type.
Alexey Bataev1d2353d2015-06-24 11:01:36 +0000663 /// \param Dependences List of dependences for the 'task' construct, including
664 /// original expression and dependency type.
665 virtual void emitTaskCall(
666 CodeGenFunction &CGF, SourceLocation Loc, const OMPExecutableDirective &D,
667 bool Tied, llvm::PointerIntPair<llvm::Value *, 1, bool> Final,
John McCall7f416cc2015-09-08 08:05:57 +0000668 llvm::Value *TaskFunction, QualType SharedsTy, Address Shareds,
Alexey Bataev1d2353d2015-06-24 11:01:36 +0000669 const Expr *IfCond, ArrayRef<const Expr *> PrivateVars,
670 ArrayRef<const Expr *> PrivateCopies,
671 ArrayRef<const Expr *> FirstprivateVars,
672 ArrayRef<const Expr *> FirstprivateCopies,
673 ArrayRef<const Expr *> FirstprivateInits,
674 ArrayRef<std::pair<OpenMPDependClauseKind, const Expr *>> Dependences);
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000675
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000676 /// \brief Emit code for the directive that does not require outlining.
677 ///
Alexey Bataev81c7ea02015-07-03 09:56:58 +0000678 /// \param InnermostKind Kind of innermost directive (for simple directives it
679 /// is a directive itself, for combined - its innermost directive).
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000680 /// \param CodeGen Code generation sequence for the \a D directive.
Alexey Bataev25e5b442015-09-15 12:52:43 +0000681 /// \param HasCancel true if region has inner cancel directive, false
682 /// otherwise.
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000683 virtual void emitInlinedDirective(CodeGenFunction &CGF,
Alexey Bataev81c7ea02015-07-03 09:56:58 +0000684 OpenMPDirectiveKind InnermostKind,
Alexey Bataev25e5b442015-09-15 12:52:43 +0000685 const RegionCodeGenTy &CodeGen,
686 bool HasCancel = false);
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000687 /// \brief Emit a code for reduction clause. Next code should be emitted for
688 /// reduction:
689 /// \code
690 ///
691 /// static kmp_critical_name lock = { 0 };
692 ///
693 /// void reduce_func(void *lhs[<n>], void *rhs[<n>]) {
694 /// ...
695 /// *(Type<i>*)lhs[i] = RedOp<i>(*(Type<i>*)lhs[i], *(Type<i>*)rhs[i]);
696 /// ...
697 /// }
698 ///
699 /// ...
700 /// void *RedList[<n>] = {&<RHSExprs>[0], ..., &<RHSExprs>[<n>-1]};
701 /// switch (__kmpc_reduce{_nowait}(<loc>, <gtid>, <n>, sizeof(RedList),
702 /// RedList, reduce_func, &<lock>)) {
703 /// case 1:
704 /// ...
705 /// <LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]);
706 /// ...
707 /// __kmpc_end_reduce{_nowait}(<loc>, <gtid>, &<lock>);
708 /// break;
709 /// case 2:
710 /// ...
711 /// Atomic(<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]));
712 /// ...
713 /// break;
714 /// default:;
715 /// }
716 /// \endcode
717 ///
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000718 /// \param Privates List of private copies for original reduction arguments.
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000719 /// \param LHSExprs List of LHS in \a ReductionOps reduction operations.
720 /// \param RHSExprs List of RHS in \a ReductionOps reduction operations.
721 /// \param ReductionOps List of reduction operations in form 'LHS binop RHS'
722 /// or 'operator binop(LHS, RHS)'.
723 /// \param WithNowait true if parent directive has also nowait clause, false
724 /// otherwise.
725 virtual void emitReduction(CodeGenFunction &CGF, SourceLocation Loc,
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000726 ArrayRef<const Expr *> Privates,
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000727 ArrayRef<const Expr *> LHSExprs,
728 ArrayRef<const Expr *> RHSExprs,
729 ArrayRef<const Expr *> ReductionOps,
Alexey Bataev89e7e8e2015-06-17 06:21:39 +0000730 bool WithNowait, bool SimpleReduction);
Alexey Bataev8b8e2022015-04-27 05:22:09 +0000731
732 /// \brief Emit code for 'taskwait' directive.
733 virtual void emitTaskwaitCall(CodeGenFunction &CGF, SourceLocation Loc);
Alexey Bataev0f34da12015-07-02 04:17:07 +0000734
735 /// \brief Emit code for 'cancellation point' construct.
736 /// \param CancelRegion Region kind for which the cancellation point must be
737 /// emitted.
738 ///
739 virtual void emitCancellationPointCall(CodeGenFunction &CGF,
740 SourceLocation Loc,
741 OpenMPDirectiveKind CancelRegion);
Alexey Bataev7d5d33e2015-07-06 05:50:32 +0000742
743 /// \brief Emit code for 'cancel' construct.
Alexey Bataev87933c72015-09-18 08:07:34 +0000744 /// \param IfCond Condition in the associated 'if' clause, if it was
745 /// specified, nullptr otherwise.
Alexey Bataev7d5d33e2015-07-06 05:50:32 +0000746 /// \param CancelRegion Region kind for which the cancel must be emitted.
747 ///
748 virtual void emitCancelCall(CodeGenFunction &CGF, SourceLocation Loc,
Alexey Bataev87933c72015-09-18 08:07:34 +0000749 const Expr *IfCond,
Alexey Bataev7d5d33e2015-07-06 05:50:32 +0000750 OpenMPDirectiveKind CancelRegion);
Samuel Antaobed3c462015-10-02 16:14:20 +0000751
752 /// \brief Emit outilined function for 'target' directive.
753 /// \param D Directive to emit.
Samuel Antaoee8fb302016-01-06 13:42:12 +0000754 /// \param ParentName Name of the function that encloses the target region.
755 /// \param OutlinedFn Outlined function value to be defined by this call.
756 /// \param OutlinedFnID Outlined function ID value to be defined by this call.
757 /// \param IsOffloadEntry True if the outlined function is an offload entry.
758 /// An oulined function may not be an entry if, e.g. the if clause always
759 /// evaluates to false.
760 virtual void emitTargetOutlinedFunction(const OMPExecutableDirective &D,
761 StringRef ParentName,
762 llvm::Function *&OutlinedFn,
763 llvm::Constant *&OutlinedFnID,
764 bool IsOffloadEntry);
Samuel Antaobed3c462015-10-02 16:14:20 +0000765
766 /// \brief Emit the target offloading code associated with \a D. The emitted
767 /// code attempts offloading the execution to the device, an the event of
768 /// a failure it executes the host version outlined in \a OutlinedFn.
769 /// \param D Directive to emit.
770 /// \param OutlinedFn Host version of the code to be offloaded.
Samuel Antaoee8fb302016-01-06 13:42:12 +0000771 /// \param OutlinedFnID ID of host version of the code to be offloaded.
Samuel Antaobed3c462015-10-02 16:14:20 +0000772 /// \param IfCond Expression evaluated in if clause associated with the target
773 /// directive, or null if no if clause is used.
774 /// \param Device Expression evaluated in device clause associated with the
775 /// target directive, or null if no device clause is used.
776 /// \param CapturedVars Values captured in the current region.
777 virtual void emitTargetCall(CodeGenFunction &CGF,
778 const OMPExecutableDirective &D,
Samuel Antaoee8fb302016-01-06 13:42:12 +0000779 llvm::Value *OutlinedFn,
780 llvm::Value *OutlinedFnID, const Expr *IfCond,
Samuel Antaobed3c462015-10-02 16:14:20 +0000781 const Expr *Device,
782 ArrayRef<llvm::Value *> CapturedVars);
Samuel Antaoee8fb302016-01-06 13:42:12 +0000783
784 /// \brief Emit the target regions enclosed in \a GD function definition or
785 /// the function itself in case it is a valid device function. Returns true if
786 /// \a GD was dealt with successfully.
Nico Webera2abe8c2016-01-06 19:13:49 +0000787 /// \param GD Function to scan.
Samuel Antaoee8fb302016-01-06 13:42:12 +0000788 virtual bool emitTargetFunctions(GlobalDecl GD);
789
790 /// \brief Emit the global variable if it is a valid device global variable.
791 /// Returns true if \a GD was dealt with successfully.
792 /// \param GD Variable declaration to emit.
793 virtual bool emitTargetGlobalVariable(GlobalDecl GD);
794
795 /// \brief Emit the global \a GD if it is meaningful for the target. Returns
796 /// if it was emitted succesfully.
797 /// \param GD Global to scan.
798 virtual bool emitTargetGlobal(GlobalDecl GD);
799
800 /// \brief Creates the offloading descriptor in the event any target region
801 /// was emitted in the current module and return the function that registers
802 /// it.
803 virtual llvm::Function *emitRegistrationFunction();
Carlo Bertolli430d8ec2016-03-03 20:34:23 +0000804
805 /// \brief Emits code for teams call of the \a OutlinedFn with
806 /// variables captured in a record which address is stored in \a
807 /// CapturedStruct.
808 /// \param OutlinedFn Outlined function to be run by team masters. Type of
809 /// this function is void(*)(kmp_int32 *, kmp_int32, struct context_vars*).
810 /// \param CapturedVars A pointer to the record with the references to
811 /// variables used in \a OutlinedFn function.
812 ///
813 virtual void emitTeamsCall(CodeGenFunction &CGF,
814 const OMPExecutableDirective &D,
815 SourceLocation Loc, llvm::Value *OutlinedFn,
816 ArrayRef<llvm::Value *> CapturedVars);
817
818 /// \brief Emits call to void __kmpc_push_num_teams(ident_t *loc, kmp_int32
819 /// global_tid, kmp_int32 num_teams, kmp_int32 thread_limit) to generate code
820 /// for num_teams clause.
821 /// \param NumTeams An integer value of teams.
Simon Pilgrim1feae0d2016-03-05 22:35:55 +0000822 /// \param ThreadLimit An integer value of threads.
Carlo Bertolli430d8ec2016-03-03 20:34:23 +0000823 virtual void emitNumTeamsClause(CodeGenFunction &CGF, llvm::Value *NumTeams,
824 llvm::Value *ThreadLimit, SourceLocation Loc);
825
Alexey Bataev9959db52014-05-06 10:08:46 +0000826};
Alexey Bataev8cbe0a62015-02-26 10:27:34 +0000827
Alexey Bataev23b69422014-06-18 07:08:49 +0000828} // namespace CodeGen
829} // namespace clang
Alexey Bataev9959db52014-05-06 10:08:46 +0000830
831#endif