blob: 0f18d13296f5dc911e1840b7a1e03b23076ba357 [file] [log] [blame]
Alexey Bataev9959db52014-05-06 10:08:46 +00001//===----- CGOpenMPRuntime.h - Interface to OpenMP Runtimes -----*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This provides a class for OpenMP runtime code generation.
11//
12//===----------------------------------------------------------------------===//
13
Benjamin Kramer2f5db8b2014-08-13 16:25:19 +000014#ifndef LLVM_CLANG_LIB_CODEGEN_CGOPENMPRUNTIME_H
15#define LLVM_CLANG_LIB_CODEGEN_CGOPENMPRUNTIME_H
Alexey Bataev9959db52014-05-06 10:08:46 +000016
Alexey Bataev7292c292016-04-25 12:22:29 +000017#include "CGValue.h"
Alexey Bataev62b63b12015-03-10 07:28:44 +000018#include "clang/AST/Type.h"
Alexander Musmanc6388682014-12-15 07:07:06 +000019#include "clang/Basic/OpenMPKinds.h"
Chandler Carruth0d9593d2015-01-14 11:29:14 +000020#include "clang/Basic/SourceLocation.h"
Alexey Bataev9959db52014-05-06 10:08:46 +000021#include "llvm/ADT/DenseMap.h"
Benjamin Kramer8fdba912016-02-02 14:24:21 +000022#include "llvm/ADT/SmallPtrSet.h"
Alexey Bataev3a3bf0b2014-09-22 10:01:53 +000023#include "llvm/ADT/StringMap.h"
Benjamin Kramer8fdba912016-02-02 14:24:21 +000024#include "llvm/IR/Function.h"
Alexey Bataev97720002014-11-11 04:05:39 +000025#include "llvm/IR/ValueHandle.h"
Alexey Bataev18095712014-10-10 12:19:54 +000026
27namespace llvm {
28class ArrayType;
29class Constant;
Alexey Bataev18095712014-10-10 12:19:54 +000030class FunctionType;
Alexey Bataev97720002014-11-11 04:05:39 +000031class GlobalVariable;
Alexey Bataev18095712014-10-10 12:19:54 +000032class StructType;
33class Type;
34class Value;
35} // namespace llvm
Alexey Bataev9959db52014-05-06 10:08:46 +000036
Alexey Bataev9959db52014-05-06 10:08:46 +000037namespace clang {
Alexey Bataevcc37cc12014-11-20 04:34:54 +000038class Expr;
Samuel Antaoee8fb302016-01-06 13:42:12 +000039class GlobalDecl;
Alexey Bataev8b427062016-05-25 12:36:08 +000040class OMPDependClause;
Alexey Bataev18095712014-10-10 12:19:54 +000041class OMPExecutableDirective;
Alexey Bataev7292c292016-04-25 12:22:29 +000042class OMPLoopDirective;
Alexey Bataev18095712014-10-10 12:19:54 +000043class VarDecl;
Alexey Bataevc5b1d322016-03-04 09:22:22 +000044class OMPDeclareReductionDecl;
45class IdentifierInfo;
Alexey Bataev18095712014-10-10 12:19:54 +000046
Alexey Bataev9959db52014-05-06 10:08:46 +000047namespace CodeGen {
John McCall7f416cc2015-09-08 08:05:57 +000048class Address;
Alexey Bataev18095712014-10-10 12:19:54 +000049class CodeGenFunction;
50class CodeGenModule;
Alexey Bataev9959db52014-05-06 10:08:46 +000051
Alexey Bataev14fa1c62016-03-29 05:34:15 +000052/// A basic class for pre|post-action for advanced codegen sequence for OpenMP
53/// region.
54class PrePostActionTy {
55public:
56 explicit PrePostActionTy() {}
57 virtual void Enter(CodeGenFunction &CGF) {}
58 virtual void Exit(CodeGenFunction &CGF) {}
59 virtual ~PrePostActionTy() {}
60};
61
62/// Class provides a way to call simple version of codegen for OpenMP region, or
63/// an advanced with possible pre|post-actions in codegen.
64class RegionCodeGenTy final {
65 intptr_t CodeGen;
66 typedef void (*CodeGenTy)(intptr_t, CodeGenFunction &, PrePostActionTy &);
67 CodeGenTy Callback;
68 mutable PrePostActionTy *PrePostAction;
69 RegionCodeGenTy() = delete;
70 RegionCodeGenTy &operator=(const RegionCodeGenTy &) = delete;
71 template <typename Callable>
72 static void CallbackFn(intptr_t CodeGen, CodeGenFunction &CGF,
73 PrePostActionTy &Action) {
74 return (*reinterpret_cast<Callable *>(CodeGen))(CGF, Action);
75 }
76
77public:
78 template <typename Callable>
79 RegionCodeGenTy(
80 Callable &&CodeGen,
81 typename std::enable_if<
82 !std::is_same<typename std::remove_reference<Callable>::type,
83 RegionCodeGenTy>::value>::type * = nullptr)
84 : CodeGen(reinterpret_cast<intptr_t>(&CodeGen)),
85 Callback(CallbackFn<typename std::remove_reference<Callable>::type>),
86 PrePostAction(nullptr) {}
87 void setAction(PrePostActionTy &Action) const { PrePostAction = &Action; }
88 void operator()(CodeGenFunction &CGF) const;
89};
Alexey Bataev6f1ffc02015-04-10 04:50:10 +000090
Alexey Bataev24b5bae2016-04-28 09:23:51 +000091struct OMPTaskDataTy final {
92 SmallVector<const Expr *, 4> PrivateVars;
93 SmallVector<const Expr *, 4> PrivateCopies;
94 SmallVector<const Expr *, 4> FirstprivateVars;
95 SmallVector<const Expr *, 4> FirstprivateCopies;
96 SmallVector<const Expr *, 4> FirstprivateInits;
Alexey Bataevf93095a2016-05-05 08:46:22 +000097 SmallVector<const Expr *, 4> LastprivateVars;
98 SmallVector<const Expr *, 4> LastprivateCopies;
Alexey Bataevbe5a8b42017-07-17 13:30:36 +000099 SmallVector<const Expr *, 4> ReductionVars;
100 SmallVector<const Expr *, 4> ReductionCopies;
101 SmallVector<const Expr *, 4> ReductionOps;
Alexey Bataev24b5bae2016-04-28 09:23:51 +0000102 SmallVector<std::pair<OpenMPDependClauseKind, const Expr *>, 4> Dependences;
103 llvm::PointerIntPair<llvm::Value *, 1, bool> Final;
104 llvm::PointerIntPair<llvm::Value *, 1, bool> Schedule;
Alexey Bataev1e1e2862016-05-10 12:21:02 +0000105 llvm::PointerIntPair<llvm::Value *, 1, bool> Priority;
Alexey Bataevbe5a8b42017-07-17 13:30:36 +0000106 llvm::Value *Reductions = nullptr;
Alexey Bataev24b5bae2016-04-28 09:23:51 +0000107 unsigned NumberOfParts = 0;
108 bool Tied = true;
109 bool Nogroup = false;
110};
111
Alexey Bataev5c40bec2017-07-13 13:36:14 +0000112/// Class intended to support codegen of all kind of the reduction clauses.
113class ReductionCodeGen {
114private:
Simon Pilgrim6c0eeff2017-07-13 17:34:44 +0000115 /// Data required for codegen of reduction clauses.
Alexey Bataev5c40bec2017-07-13 13:36:14 +0000116 struct ReductionData {
117 /// Reference to the original shared item.
118 const Expr *Ref = nullptr;
119 /// Helper expression for generation of private copy.
120 const Expr *Private = nullptr;
121 /// Helper expression for generation reduction operation.
122 const Expr *ReductionOp = nullptr;
123 ReductionData(const Expr *Ref, const Expr *Private, const Expr *ReductionOp)
124 : Ref(Ref), Private(Private), ReductionOp(ReductionOp) {}
125 };
126 /// List of reduction-based clauses.
127 SmallVector<ReductionData, 4> ClausesData;
128
129 /// List of addresses of original shared variables/expressions.
130 SmallVector<std::pair<LValue, LValue>, 4> SharedAddresses;
131 /// Sizes of the reduction items in chars.
Alexey Bataevbe5a8b42017-07-17 13:30:36 +0000132 SmallVector<std::pair<llvm::Value *, llvm::Value *>, 4> Sizes;
Alexey Bataev5c40bec2017-07-13 13:36:14 +0000133 /// Base declarations for the reduction items.
134 SmallVector<const VarDecl *, 4> BaseDecls;
Alexey Bataevbe5a8b42017-07-17 13:30:36 +0000135
Alexey Bataev5c40bec2017-07-13 13:36:14 +0000136 /// Emits lvalue for shared expresion.
137 LValue emitSharedLValue(CodeGenFunction &CGF, const Expr *E);
138 /// Emits upper bound for shared expression (if array section).
139 LValue emitSharedLValueUB(CodeGenFunction &CGF, const Expr *E);
140 /// Performs aggregate initialization.
141 /// \param N Number of reduction item in the common list.
142 /// \param PrivateAddr Address of the corresponding private item.
Alexey Bataevbe5a8b42017-07-17 13:30:36 +0000143 /// \param SharedLVal Address of the original shared variable.
144 /// \param DRD Declare reduction construct used for reduction item.
Alexey Bataev5c40bec2017-07-13 13:36:14 +0000145 void emitAggregateInitialization(CodeGenFunction &CGF, unsigned N,
Alexey Bataevbe5a8b42017-07-17 13:30:36 +0000146 Address PrivateAddr, LValue SharedLVal,
147 const OMPDeclareReductionDecl *DRD);
Alexey Bataev5c40bec2017-07-13 13:36:14 +0000148
149public:
150 ReductionCodeGen(ArrayRef<const Expr *> Shareds,
151 ArrayRef<const Expr *> Privates,
152 ArrayRef<const Expr *> ReductionOps);
153 /// Emits lvalue for a reduction item.
154 /// \param N Number of the reduction item.
155 void emitSharedLValue(CodeGenFunction &CGF, unsigned N);
156 /// Emits the code for the variable-modified type, if required.
157 /// \param N Number of the reduction item.
158 void emitAggregateType(CodeGenFunction &CGF, unsigned N);
159 /// Emits the code for the variable-modified type, if required.
160 /// \param N Number of the reduction item.
161 /// \param Size Size of the type in chars.
162 void emitAggregateType(CodeGenFunction &CGF, unsigned N, llvm::Value *Size);
163 /// Performs initialization of the private copy for the reduction item.
164 /// \param N Number of the reduction item.
165 /// \param PrivateAddr Address of the corresponding private item.
166 /// \param DefaultInit Default initialization sequence that should be
167 /// performed if no reduction specific initialization is found.
Simon Pilgrim6c0eeff2017-07-13 17:34:44 +0000168 /// \param SharedLVal Address of the original shared variable.
Alexey Bataev5c40bec2017-07-13 13:36:14 +0000169 void
170 emitInitialization(CodeGenFunction &CGF, unsigned N, Address PrivateAddr,
171 LValue SharedLVal,
172 llvm::function_ref<bool(CodeGenFunction &)> DefaultInit);
Simon Pilgrim6c0eeff2017-07-13 17:34:44 +0000173 /// Returns true if the private copy requires cleanups.
Alexey Bataev5c40bec2017-07-13 13:36:14 +0000174 bool needCleanups(unsigned N);
Simon Pilgrim6c0eeff2017-07-13 17:34:44 +0000175 /// Emits cleanup code for the reduction item.
Alexey Bataev5c40bec2017-07-13 13:36:14 +0000176 /// \param N Number of the reduction item.
177 /// \param PrivateAddr Address of the corresponding private item.
178 void emitCleanups(CodeGenFunction &CGF, unsigned N, Address PrivateAddr);
Simon Pilgrim6c0eeff2017-07-13 17:34:44 +0000179 /// Adjusts \p PrivatedAddr for using instead of the original variable
Alexey Bataev5c40bec2017-07-13 13:36:14 +0000180 /// address in normal operations.
181 /// \param N Number of the reduction item.
182 /// \param PrivateAddr Address of the corresponding private item.
183 Address adjustPrivateAddress(CodeGenFunction &CGF, unsigned N,
184 Address PrivateAddr);
185 /// Returns LValue for the reduction item.
186 LValue getSharedLValue(unsigned N) const { return SharedAddresses[N].first; }
Alexey Bataevbe5a8b42017-07-17 13:30:36 +0000187 /// Returns the size of the reduction item (in chars and total number of
188 /// elements in the item), or nullptr, if the size is a constant.
189 std::pair<llvm::Value *, llvm::Value *> getSizes(unsigned N) const {
190 return Sizes[N];
191 }
Alexey Bataev5c40bec2017-07-13 13:36:14 +0000192 /// Returns the base declaration of the reduction item.
193 const VarDecl *getBaseDecl(unsigned N) const { return BaseDecls[N]; }
Alexey Bataev1c44e152018-03-06 18:59:43 +0000194 /// Returns the base declaration of the reduction item.
195 const Expr *getRefExpr(unsigned N) const { return ClausesData[N].Ref; }
Alexey Bataevbe5a8b42017-07-17 13:30:36 +0000196 /// Returns true if the initialization of the reduction item uses initializer
197 /// from declare reduction construct.
198 bool usesReductionInitializer(unsigned N) const;
Alexey Bataev5c40bec2017-07-13 13:36:14 +0000199};
200
Alexey Bataev9959db52014-05-06 10:08:46 +0000201class CGOpenMPRuntime {
Arpith Chacko Jacob5c309e42016-03-22 01:48:56 +0000202protected:
Alexey Bataev9959db52014-05-06 10:08:46 +0000203 CodeGenModule &CGM;
Arpith Chacko Jacob5c309e42016-03-22 01:48:56 +0000204
205 /// \brief Creates offloading entry for the provided entry ID \a ID,
Samuel Antaof83efdb2017-01-05 16:02:49 +0000206 /// address \a Addr, size \a Size, and flags \a Flags.
Arpith Chacko Jacob5c309e42016-03-22 01:48:56 +0000207 virtual void createOffloadEntry(llvm::Constant *ID, llvm::Constant *Addr,
Samuel Antaof83efdb2017-01-05 16:02:49 +0000208 uint64_t Size, int32_t Flags = 0);
Arpith Chacko Jacob5c309e42016-03-22 01:48:56 +0000209
210 /// \brief Helper to emit outlined function for 'target' directive.
211 /// \param D Directive to emit.
212 /// \param ParentName Name of the function that encloses the target region.
213 /// \param OutlinedFn Outlined function value to be defined by this call.
214 /// \param OutlinedFnID Outlined function ID value to be defined by this call.
215 /// \param IsOffloadEntry True if the outlined function is an offload entry.
216 /// \param CodeGen Lambda codegen specific to an accelerator device.
Simon Pilgrim6c0eeff2017-07-13 17:34:44 +0000217 /// An outlined function may not be an entry if, e.g. the if clause always
Arpith Chacko Jacob5c309e42016-03-22 01:48:56 +0000218 /// evaluates to false.
219 virtual void emitTargetOutlinedFunctionHelper(const OMPExecutableDirective &D,
220 StringRef ParentName,
221 llvm::Function *&OutlinedFn,
222 llvm::Constant *&OutlinedFnID,
223 bool IsOffloadEntry,
224 const RegionCodeGenTy &CodeGen);
225
Arpith Chacko Jacobbb36fe82017-01-10 15:42:51 +0000226 /// \brief Emits code for OpenMP 'if' clause using specified \a CodeGen
227 /// function. Here is the logic:
228 /// if (Cond) {
229 /// ThenGen();
230 /// } else {
231 /// ElseGen();
232 /// }
233 void emitOMPIfClause(CodeGenFunction &CGF, const Expr *Cond,
234 const RegionCodeGenTy &ThenGen,
235 const RegionCodeGenTy &ElseGen);
236
237 /// \brief Emits object of ident_t type with info for source location.
238 /// \param Flags Flags for OpenMP location.
239 ///
240 llvm::Value *emitUpdateLocation(CodeGenFunction &CGF, SourceLocation Loc,
241 unsigned Flags = 0);
242
243 /// \brief Returns pointer to ident_t type.
244 llvm::Type *getIdentTyPointerTy();
245
246 /// \brief Gets thread id value for the current thread.
247 ///
248 llvm::Value *getThreadID(CodeGenFunction &CGF, SourceLocation Loc);
249
250 /// \brief Get the function name of an outlined region.
251 // The name can be customized depending on the target.
252 //
253 virtual StringRef getOutlinedHelperName() const { return ".omp_outlined."; }
254
Alexey Bataev3c595a62017-08-14 15:01:03 +0000255 /// Emits \p Callee function call with arguments \p Args with location \p Loc.
Alexey Bataev7ef47a62018-02-22 18:33:31 +0000256 void emitCall(CodeGenFunction &CGF, SourceLocation Loc, llvm::Value *Callee,
257 ArrayRef<llvm::Value *> Args = llvm::None) const;
Alexey Bataev3c595a62017-08-14 15:01:03 +0000258
Arpith Chacko Jacob5c309e42016-03-22 01:48:56 +0000259private:
Alexey Bataev9959db52014-05-06 10:08:46 +0000260 /// \brief Default const ident_t object used for initialization of all other
261 /// ident_t objects.
Alexey Bataevc5b1d322016-03-04 09:22:22 +0000262 llvm::Constant *DefaultOpenMPPSource = nullptr;
Alexey Bataev18095712014-10-10 12:19:54 +0000263 /// \brief Map of flags and corresponding default locations.
Alexey Bataev15007ba2014-05-07 06:18:01 +0000264 typedef llvm::DenseMap<unsigned, llvm::Value *> OpenMPDefaultLocMapTy;
265 OpenMPDefaultLocMapTy OpenMPDefaultLocMap;
Alexey Bataev50b3c952016-02-19 10:38:26 +0000266 Address getOrCreateDefaultLocation(unsigned Flags);
John McCall7f416cc2015-09-08 08:05:57 +0000267
Alexey Bataev14fa1c62016-03-29 05:34:15 +0000268 llvm::StructType *IdentTy = nullptr;
Alexey Bataev18095712014-10-10 12:19:54 +0000269 /// \brief Map for SourceLocation and OpenMP runtime library debug locations.
Alexey Bataevf002aca2014-05-30 05:48:40 +0000270 typedef llvm::DenseMap<unsigned, llvm::Value *> OpenMPDebugLocMapTy;
271 OpenMPDebugLocMapTy OpenMPDebugLocMap;
Alexey Bataev9959db52014-05-06 10:08:46 +0000272 /// \brief The type for a microtask which gets passed to __kmpc_fork_call().
273 /// Original representation is:
274 /// typedef void (kmpc_micro)(kmp_int32 global_tid, kmp_int32 bound_tid,...);
Alexey Bataev14fa1c62016-03-29 05:34:15 +0000275 llvm::FunctionType *Kmpc_MicroTy = nullptr;
Alexey Bataev18095712014-10-10 12:19:54 +0000276 /// \brief Stores debug location and ThreadID for the function.
277 struct DebugLocThreadIdTy {
278 llvm::Value *DebugLoc;
279 llvm::Value *ThreadID;
280 };
281 /// \brief Map of local debug location, ThreadId and functions.
282 typedef llvm::DenseMap<llvm::Function *, DebugLocThreadIdTy>
283 OpenMPLocThreadIDMapTy;
284 OpenMPLocThreadIDMapTy OpenMPLocThreadIDMap;
Alexey Bataevc5b1d322016-03-04 09:22:22 +0000285 /// Map of UDRs and corresponding combiner/initializer.
286 typedef llvm::DenseMap<const OMPDeclareReductionDecl *,
287 std::pair<llvm::Function *, llvm::Function *>>
288 UDRMapTy;
289 UDRMapTy UDRMap;
290 /// Map of functions and locally defined UDRs.
291 typedef llvm::DenseMap<llvm::Function *,
292 SmallVector<const OMPDeclareReductionDecl *, 4>>
293 FunctionUDRMapTy;
294 FunctionUDRMapTy FunctionUDRMap;
295 IdentifierInfo *In = nullptr;
296 IdentifierInfo *Out = nullptr;
297 IdentifierInfo *Priv = nullptr;
298 IdentifierInfo *Orig = nullptr;
Alexey Bataev3a3bf0b2014-09-22 10:01:53 +0000299 /// \brief Type kmp_critical_name, originally defined as typedef kmp_int32
300 /// kmp_critical_name[8];
301 llvm::ArrayType *KmpCriticalNameTy;
Alexey Bataev97720002014-11-11 04:05:39 +0000302 /// \brief An ordered map of auto-generated variables to their unique names.
303 /// It stores variables with the following names: 1) ".gomp_critical_user_" +
304 /// <critical_section_name> + ".var" for "omp critical" directives; 2)
305 /// <mangled_name_for_global_var> + ".cache." for cache for threadprivate
306 /// variables.
307 llvm::StringMap<llvm::AssertingVH<llvm::Constant>, llvm::BumpPtrAllocator>
308 InternalVars;
Alexey Bataev62b63b12015-03-10 07:28:44 +0000309 /// \brief Type typedef kmp_int32 (* kmp_routine_entry_t)(kmp_int32, void *);
Alexey Bataevc5b1d322016-03-04 09:22:22 +0000310 llvm::Type *KmpRoutineEntryPtrTy = nullptr;
Alexey Bataev62b63b12015-03-10 07:28:44 +0000311 QualType KmpRoutineEntryPtrQTy;
Alexey Bataev8fc69dc2015-05-18 07:54:53 +0000312 /// \brief Type typedef struct kmp_task {
313 /// void * shareds; /**< pointer to block of pointers to
314 /// shared vars */
315 /// kmp_routine_entry_t routine; /**< pointer to routine to call for
316 /// executing task */
317 /// kmp_int32 part_id; /**< part id for the task */
318 /// kmp_routine_entry_t destructors; /* pointer to function to invoke
319 /// deconstructors of firstprivate C++ objects */
320 /// } kmp_task_t;
321 QualType KmpTaskTQTy;
Alexey Bataeve213f3e2017-10-11 15:29:40 +0000322 /// Saved kmp_task_t for task directive.
323 QualType SavedKmpTaskTQTy;
324 /// Saved kmp_task_t for taskloop-based directive.
325 QualType SavedKmpTaskloopTQTy;
Alexey Bataev1d2353d2015-06-24 11:01:36 +0000326 /// \brief Type typedef struct kmp_depend_info {
327 /// kmp_intptr_t base_addr;
328 /// size_t len;
329 /// struct {
330 /// bool in:1;
331 /// bool out:1;
332 /// } flags;
333 /// } kmp_depend_info_t;
334 QualType KmpDependInfoTy;
Alexey Bataev8b427062016-05-25 12:36:08 +0000335 /// struct kmp_dim { // loop bounds info casted to kmp_int64
336 /// kmp_int64 lo; // lower
337 /// kmp_int64 up; // upper
338 /// kmp_int64 st; // stride
339 /// };
340 QualType KmpDimTy;
Samuel Antaoee8fb302016-01-06 13:42:12 +0000341 /// \brief Type struct __tgt_offload_entry{
342 /// void *addr; // Pointer to the offload entry info.
343 /// // (function or global)
344 /// char *name; // Name of the function or global.
345 /// size_t size; // Size of the entry info (0 if it a function).
346 /// };
347 QualType TgtOffloadEntryQTy;
348 /// struct __tgt_device_image{
349 /// void *ImageStart; // Pointer to the target code start.
350 /// void *ImageEnd; // Pointer to the target code end.
351 /// // We also add the host entries to the device image, as it may be useful
352 /// // for the target runtime to have access to that information.
353 /// __tgt_offload_entry *EntriesBegin; // Begin of the table with all
354 /// // the entries.
355 /// __tgt_offload_entry *EntriesEnd; // End of the table with all the
356 /// // entries (non inclusive).
357 /// };
358 QualType TgtDeviceImageQTy;
359 /// struct __tgt_bin_desc{
360 /// int32_t NumDevices; // Number of devices supported.
361 /// __tgt_device_image *DeviceImages; // Arrays of device images
362 /// // (one per device).
363 /// __tgt_offload_entry *EntriesBegin; // Begin of the table with all the
364 /// // entries.
365 /// __tgt_offload_entry *EntriesEnd; // End of the table with all the
366 /// // entries (non inclusive).
367 /// };
368 QualType TgtBinaryDescriptorQTy;
369 /// \brief Entity that registers the offloading constants that were emitted so
370 /// far.
371 class OffloadEntriesInfoManagerTy {
372 CodeGenModule &CGM;
Alexey Bataev1d2353d2015-06-24 11:01:36 +0000373
Samuel Antaoee8fb302016-01-06 13:42:12 +0000374 /// \brief Number of entries registered so far.
375 unsigned OffloadingEntriesNum;
376
377 public:
Samuel Antaof83efdb2017-01-05 16:02:49 +0000378 /// Base class of the entries info.
Samuel Antaoee8fb302016-01-06 13:42:12 +0000379 class OffloadEntryInfo {
380 public:
Samuel Antaof83efdb2017-01-05 16:02:49 +0000381 /// Kind of a given entry. Currently, only target regions are
Samuel Antaoee8fb302016-01-06 13:42:12 +0000382 /// supported.
Reid Klecknerdc78f952016-01-11 20:55:16 +0000383 enum OffloadingEntryInfoKinds : unsigned {
Samuel Antaoee8fb302016-01-06 13:42:12 +0000384 // Entry is a target region.
385 OFFLOAD_ENTRY_INFO_TARGET_REGION = 0,
386 // Invalid entry info.
387 OFFLOAD_ENTRY_INFO_INVALID = ~0u
388 };
389
Samuel Antaof83efdb2017-01-05 16:02:49 +0000390 OffloadEntryInfo()
391 : Flags(0), Order(~0u), Kind(OFFLOAD_ENTRY_INFO_INVALID) {}
392 explicit OffloadEntryInfo(OffloadingEntryInfoKinds Kind, unsigned Order,
393 int32_t Flags)
394 : Flags(Flags), Order(Order), Kind(Kind) {}
Samuel Antaoee8fb302016-01-06 13:42:12 +0000395
396 bool isValid() const { return Order != ~0u; }
397 unsigned getOrder() const { return Order; }
398 OffloadingEntryInfoKinds getKind() const { return Kind; }
Samuel Antaof83efdb2017-01-05 16:02:49 +0000399 int32_t getFlags() const { return Flags; }
400 void setFlags(int32_t NewFlags) { Flags = NewFlags; }
Samuel Antaoee8fb302016-01-06 13:42:12 +0000401 static bool classof(const OffloadEntryInfo *Info) { return true; }
402
Samuel Antaof83efdb2017-01-05 16:02:49 +0000403 private:
404 /// Flags associated with the device global.
405 int32_t Flags;
406
407 /// Order this entry was emitted.
Samuel Antaoee8fb302016-01-06 13:42:12 +0000408 unsigned Order;
409
410 OffloadingEntryInfoKinds Kind;
411 };
412
413 /// \brief Return true if a there are no entries defined.
414 bool empty() const;
415 /// \brief Return number of entries defined so far.
416 unsigned size() const { return OffloadingEntriesNum; }
417 OffloadEntriesInfoManagerTy(CodeGenModule &CGM)
418 : CGM(CGM), OffloadingEntriesNum(0) {}
419
420 ///
421 /// Target region entries related.
422 ///
423 /// \brief Target region entries info.
424 class OffloadEntryInfoTargetRegion : public OffloadEntryInfo {
425 // \brief Address of the entity that has to be mapped for offloading.
426 llvm::Constant *Addr;
427 // \brief Address that can be used as the ID of the entry.
428 llvm::Constant *ID;
429
430 public:
431 OffloadEntryInfoTargetRegion()
Samuel Antaof83efdb2017-01-05 16:02:49 +0000432 : OffloadEntryInfo(OFFLOAD_ENTRY_INFO_TARGET_REGION, ~0u,
433 /*Flags=*/0),
Samuel Antaoee8fb302016-01-06 13:42:12 +0000434 Addr(nullptr), ID(nullptr) {}
435 explicit OffloadEntryInfoTargetRegion(unsigned Order,
436 llvm::Constant *Addr,
Samuel Antaof83efdb2017-01-05 16:02:49 +0000437 llvm::Constant *ID, int32_t Flags)
438 : OffloadEntryInfo(OFFLOAD_ENTRY_INFO_TARGET_REGION, Order, Flags),
Samuel Antaoee8fb302016-01-06 13:42:12 +0000439 Addr(Addr), ID(ID) {}
440
441 llvm::Constant *getAddress() const { return Addr; }
442 llvm::Constant *getID() const { return ID; }
443 void setAddress(llvm::Constant *V) {
444 assert(!Addr && "Address as been set before!");
445 Addr = V;
446 }
447 void setID(llvm::Constant *V) {
448 assert(!ID && "ID as been set before!");
449 ID = V;
450 }
451 static bool classof(const OffloadEntryInfo *Info) {
452 return Info->getKind() == OFFLOAD_ENTRY_INFO_TARGET_REGION;
453 }
454 };
455 /// \brief Initialize target region entry.
456 void initializeTargetRegionEntryInfo(unsigned DeviceID, unsigned FileID,
457 StringRef ParentName, unsigned LineNum,
Samuel Antao2de62b02016-02-13 23:35:10 +0000458 unsigned Order);
Samuel Antaoee8fb302016-01-06 13:42:12 +0000459 /// \brief Register target region entry.
460 void registerTargetRegionEntryInfo(unsigned DeviceID, unsigned FileID,
461 StringRef ParentName, unsigned LineNum,
Samuel Antaof83efdb2017-01-05 16:02:49 +0000462 llvm::Constant *Addr, llvm::Constant *ID,
463 int32_t Flags);
Samuel Antaoee8fb302016-01-06 13:42:12 +0000464 /// \brief Return true if a target region entry with the provided
465 /// information exists.
466 bool hasTargetRegionEntryInfo(unsigned DeviceID, unsigned FileID,
Samuel Antao2de62b02016-02-13 23:35:10 +0000467 StringRef ParentName, unsigned LineNum) const;
Samuel Antaoee8fb302016-01-06 13:42:12 +0000468 /// brief Applies action \a Action on all registered entries.
469 typedef llvm::function_ref<void(unsigned, unsigned, StringRef, unsigned,
Samuel Antao2de62b02016-02-13 23:35:10 +0000470 OffloadEntryInfoTargetRegion &)>
Samuel Antaoee8fb302016-01-06 13:42:12 +0000471 OffloadTargetRegionEntryInfoActTy;
472 void actOnTargetRegionEntriesInfo(
473 const OffloadTargetRegionEntryInfoActTy &Action);
474
475 private:
476 // Storage for target region entries kind. The storage is to be indexed by
Samuel Antao2de62b02016-02-13 23:35:10 +0000477 // file ID, device ID, parent function name and line number.
Samuel Antaoee8fb302016-01-06 13:42:12 +0000478 typedef llvm::DenseMap<unsigned, OffloadEntryInfoTargetRegion>
Samuel Antaoee8fb302016-01-06 13:42:12 +0000479 OffloadEntriesTargetRegionPerLine;
480 typedef llvm::StringMap<OffloadEntriesTargetRegionPerLine>
481 OffloadEntriesTargetRegionPerParentName;
482 typedef llvm::DenseMap<unsigned, OffloadEntriesTargetRegionPerParentName>
483 OffloadEntriesTargetRegionPerFile;
484 typedef llvm::DenseMap<unsigned, OffloadEntriesTargetRegionPerFile>
485 OffloadEntriesTargetRegionPerDevice;
486 typedef OffloadEntriesTargetRegionPerDevice OffloadEntriesTargetRegionTy;
487 OffloadEntriesTargetRegionTy OffloadEntriesTargetRegion;
488 };
489 OffloadEntriesInfoManagerTy OffloadEntriesInfoManager;
490
491 /// \brief Creates and registers offloading binary descriptor for the current
492 /// compilation unit. The function that does the registration is returned.
493 llvm::Function *createOffloadingBinaryDescriptorRegistration();
494
Samuel Antaoee8fb302016-01-06 13:42:12 +0000495 /// \brief Creates all the offload entries in the current compilation unit
496 /// along with the associated metadata.
497 void createOffloadEntriesAndInfoMetadata();
498
499 /// \brief Loads all the offload entries information from the host IR
500 /// metadata.
501 void loadOffloadInfoMetadata();
502
503 /// \brief Returns __tgt_offload_entry type.
504 QualType getTgtOffloadEntryQTy();
505
506 /// \brief Returns __tgt_device_image type.
507 QualType getTgtDeviceImageQTy();
508
509 /// \brief Returns __tgt_bin_desc type.
510 QualType getTgtBinaryDescriptorQTy();
511
512 /// \brief Start scanning from statement \a S and and emit all target regions
513 /// found along the way.
514 /// \param S Starting statement.
515 /// \param ParentName Name of the function declaration that is being scanned.
516 void scanForTargetRegionsFunctions(const Stmt *S, StringRef ParentName);
Alexey Bataev62b63b12015-03-10 07:28:44 +0000517
518 /// \brief Build type kmp_routine_entry_t (if not built yet).
519 void emitKmpRoutineEntryT(QualType KmpInt32Ty);
Alexey Bataev9959db52014-05-06 10:08:46 +0000520
Alexey Bataevd74d0602014-10-13 06:02:40 +0000521 /// \brief Returns pointer to kmpc_micro type.
Alexey Bataev9959db52014-05-06 10:08:46 +0000522 llvm::Type *getKmpc_MicroPointerTy();
523
524 /// \brief Returns specified OpenMP runtime function.
525 /// \param Function OpenMP runtime function.
526 /// \return Specified function.
Alexey Bataev50b3c952016-02-19 10:38:26 +0000527 llvm::Constant *createRuntimeFunction(unsigned Function);
Alexey Bataev3a3bf0b2014-09-22 10:01:53 +0000528
Alexander Musman21212e42015-03-13 10:38:23 +0000529 /// \brief Returns __kmpc_for_static_init_* runtime function for the specified
530 /// size \a IVSize and sign \a IVSigned.
531 llvm::Constant *createForStaticInitFunction(unsigned IVSize, bool IVSigned);
532
Alexander Musman92bdaab2015-03-12 13:37:50 +0000533 /// \brief Returns __kmpc_dispatch_init_* runtime function for the specified
534 /// size \a IVSize and sign \a IVSigned.
535 llvm::Constant *createDispatchInitFunction(unsigned IVSize, bool IVSigned);
536
537 /// \brief Returns __kmpc_dispatch_next_* runtime function for the specified
538 /// size \a IVSize and sign \a IVSigned.
539 llvm::Constant *createDispatchNextFunction(unsigned IVSize, bool IVSigned);
540
Alexey Bataev98eb6e32015-04-22 11:15:40 +0000541 /// \brief Returns __kmpc_dispatch_fini_* runtime function for the specified
542 /// size \a IVSize and sign \a IVSigned.
543 llvm::Constant *createDispatchFiniFunction(unsigned IVSize, bool IVSigned);
544
Alexey Bataev97720002014-11-11 04:05:39 +0000545 /// \brief If the specified mangled name is not in the module, create and
546 /// return threadprivate cache object. This object is a pointer's worth of
547 /// storage that's reserved for use by the OpenMP runtime.
NAKAMURA Takumicdcbfba2014-11-11 07:58:06 +0000548 /// \param VD Threadprivate variable.
Alexey Bataev97720002014-11-11 04:05:39 +0000549 /// \return Cache variable for the specified threadprivate.
550 llvm::Constant *getOrCreateThreadPrivateCache(const VarDecl *VD);
551
Alexey Bataevd74d0602014-10-13 06:02:40 +0000552 /// \brief Emits address of the word in a memory where current thread id is
553 /// stored.
John McCall7f416cc2015-09-08 08:05:57 +0000554 virtual Address emitThreadIDAddress(CodeGenFunction &CGF, SourceLocation Loc);
Alexey Bataevd74d0602014-10-13 06:02:40 +0000555
Alexey Bataev97720002014-11-11 04:05:39 +0000556 /// \brief Gets (if variable with the given name already exist) or creates
557 /// internal global variable with the specified Name. The created variable has
558 /// linkage CommonLinkage by default and is initialized by null value.
559 /// \param Ty Type of the global variable. If it is exist already the type
560 /// must be the same.
561 /// \param Name Name of the variable.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000562 llvm::Constant *getOrCreateInternalVariable(llvm::Type *Ty,
Alexey Bataev97720002014-11-11 04:05:39 +0000563 const llvm::Twine &Name);
564
565 /// \brief Set of threadprivate variables with the generated initializer.
Benjamin Kramer8fdba912016-02-02 14:24:21 +0000566 llvm::SmallPtrSet<const VarDecl *, 4> ThreadPrivateWithDefinition;
Alexey Bataev97720002014-11-11 04:05:39 +0000567
568 /// \brief Emits initialization code for the threadprivate variables.
569 /// \param VDAddr Address of the global variable \a VD.
570 /// \param Ctor Pointer to a global init function for \a VD.
571 /// \param CopyCtor Pointer to a global copy function for \a VD.
572 /// \param Dtor Pointer to a global destructor function for \a VD.
573 /// \param Loc Location of threadprivate declaration.
John McCall7f416cc2015-09-08 08:05:57 +0000574 void emitThreadPrivateVarInit(CodeGenFunction &CGF, Address VDAddr,
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000575 llvm::Value *Ctor, llvm::Value *CopyCtor,
576 llvm::Value *Dtor, SourceLocation Loc);
Alexey Bataev97720002014-11-11 04:05:39 +0000577
Alexey Bataev75ddfab2014-12-01 11:32:38 +0000578 /// \brief Returns corresponding lock object for the specified critical region
579 /// name. If the lock object does not exist it is created, otherwise the
580 /// reference to the existing copy is returned.
581 /// \param CriticalName Name of the critical region.
582 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000583 llvm::Value *getCriticalRegionLock(StringRef CriticalName);
Alexey Bataev75ddfab2014-12-01 11:32:38 +0000584
Alexey Bataev24b5bae2016-04-28 09:23:51 +0000585 struct TaskResultTy {
586 llvm::Value *NewTask = nullptr;
587 llvm::Value *TaskEntry = nullptr;
588 llvm::Value *NewTaskNewTaskTTy = nullptr;
Alexey Bataev7292c292016-04-25 12:22:29 +0000589 LValue TDBase;
Alexey Bataev24b5bae2016-04-28 09:23:51 +0000590 RecordDecl *KmpTaskTQTyRD = nullptr;
Alexey Bataevf93095a2016-05-05 08:46:22 +0000591 llvm::Value *TaskDupFn = nullptr;
Alexey Bataev7292c292016-04-25 12:22:29 +0000592 };
593 /// Emit task region for the task directive. The task region is emitted in
594 /// several steps:
595 /// 1. Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32
596 /// gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds,
597 /// kmp_routine_entry_t *task_entry). Here task_entry is a pointer to the
598 /// function:
599 /// kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) {
600 /// TaskFunction(gtid, tt->part_id, tt->shareds);
601 /// return 0;
602 /// }
603 /// 2. Copy a list of shared variables to field shareds of the resulting
604 /// structure kmp_task_t returned by the previous call (if any).
605 /// 3. Copy a pointer to destructions function to field destructions of the
606 /// resulting structure kmp_task_t.
607 /// \param D Current task directive.
Alexey Bataev7292c292016-04-25 12:22:29 +0000608 /// \param TaskFunction An LLVM function with type void (*)(i32 /*gtid*/, i32
609 /// /*part_id*/, captured_struct */*__context*/);
610 /// \param SharedsTy A type which contains references the shared variables.
611 /// \param Shareds Context with the list of shared variables from the \p
612 /// TaskFunction.
Alexey Bataev24b5bae2016-04-28 09:23:51 +0000613 /// \param Data Additional data for task generation like tiednsee, final
614 /// state, list of privates etc.
615 TaskResultTy emitTaskInit(CodeGenFunction &CGF, SourceLocation Loc,
616 const OMPExecutableDirective &D,
617 llvm::Value *TaskFunction, QualType SharedsTy,
618 Address Shareds, const OMPTaskDataTy &Data);
Alexey Bataev7292c292016-04-25 12:22:29 +0000619
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000620public:
621 explicit CGOpenMPRuntime(CodeGenModule &CGM);
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +0000622 virtual ~CGOpenMPRuntime() {}
Alexey Bataev91797552015-03-18 04:13:55 +0000623 virtual void clear();
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000624
Alexey Bataevc5b1d322016-03-04 09:22:22 +0000625 /// Emit code for the specified user defined reduction construct.
626 virtual void emitUserDefinedReduction(CodeGenFunction *CGF,
627 const OMPDeclareReductionDecl *D);
Alexey Bataeva839ddd2016-03-17 10:19:46 +0000628 /// Get combiner/initializer for the specified user-defined reduction, if any.
629 virtual std::pair<llvm::Function *, llvm::Function *>
630 getUserDefinedReduction(const OMPDeclareReductionDecl *D);
Arpith Chacko Jacob19b911c2017-01-18 18:18:53 +0000631
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000632 /// \brief Emits outlined function for the specified OpenMP parallel directive
633 /// \a D. This outlined function has type void(*)(kmp_int32 *ThreadID,
634 /// kmp_int32 BoundID, struct context_vars*).
Alexey Bataev18095712014-10-10 12:19:54 +0000635 /// \param D OpenMP directive.
636 /// \param ThreadIDVar Variable for thread id in the current OpenMP region.
Alexey Bataev81c7ea02015-07-03 09:56:58 +0000637 /// \param InnermostKind Kind of innermost directive (for simple directives it
638 /// is a directive itself, for combined - its innermost directive).
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000639 /// \param CodeGen Code generation sequence for the \a D directive.
Arpith Chacko Jacob19b911c2017-01-18 18:18:53 +0000640 virtual llvm::Value *emitParallelOutlinedFunction(
641 const OMPExecutableDirective &D, const VarDecl *ThreadIDVar,
642 OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen);
643
644 /// \brief Emits outlined function for the specified OpenMP teams directive
645 /// \a D. This outlined function has type void(*)(kmp_int32 *ThreadID,
646 /// kmp_int32 BoundID, struct context_vars*).
647 /// \param D OpenMP directive.
648 /// \param ThreadIDVar Variable for thread id in the current OpenMP region.
649 /// \param InnermostKind Kind of innermost directive (for simple directives it
650 /// is a directive itself, for combined - its innermost directive).
651 /// \param CodeGen Code generation sequence for the \a D directive.
652 virtual llvm::Value *emitTeamsOutlinedFunction(
Alexey Bataev81c7ea02015-07-03 09:56:58 +0000653 const OMPExecutableDirective &D, const VarDecl *ThreadIDVar,
654 OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen);
Alexey Bataev18095712014-10-10 12:19:54 +0000655
Alexey Bataev62b63b12015-03-10 07:28:44 +0000656 /// \brief Emits outlined function for the OpenMP task directive \a D. This
Alexey Bataev48591dd2016-04-20 04:01:36 +0000657 /// outlined function has type void(*)(kmp_int32 ThreadID, struct task_t*
658 /// TaskT).
Alexey Bataev62b63b12015-03-10 07:28:44 +0000659 /// \param D OpenMP directive.
660 /// \param ThreadIDVar Variable for thread id in the current OpenMP region.
Alexey Bataev48591dd2016-04-20 04:01:36 +0000661 /// \param PartIDVar Variable for partition id in the current OpenMP untied
662 /// task region.
663 /// \param TaskTVar Variable for task_t argument.
Alexey Bataev81c7ea02015-07-03 09:56:58 +0000664 /// \param InnermostKind Kind of innermost directive (for simple directives it
665 /// is a directive itself, for combined - its innermost directive).
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000666 /// \param CodeGen Code generation sequence for the \a D directive.
Alexey Bataev48591dd2016-04-20 04:01:36 +0000667 /// \param Tied true if task is generated for tied task, false otherwise.
668 /// \param NumberOfParts Number of parts in untied task. Ignored for tied
669 /// tasks.
Alexey Bataev62b63b12015-03-10 07:28:44 +0000670 ///
Alexey Bataev81c7ea02015-07-03 09:56:58 +0000671 virtual llvm::Value *emitTaskOutlinedFunction(
672 const OMPExecutableDirective &D, const VarDecl *ThreadIDVar,
Alexey Bataev48591dd2016-04-20 04:01:36 +0000673 const VarDecl *PartIDVar, const VarDecl *TaskTVar,
674 OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen,
675 bool Tied, unsigned &NumberOfParts);
Alexey Bataev62b63b12015-03-10 07:28:44 +0000676
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000677 /// \brief Cleans up references to the objects in finished function.
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000678 ///
Gheorghe-Teodor Bercead3dcf2f2018-03-14 14:17:45 +0000679 virtual void functionFinished(CodeGenFunction &CGF);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000680
Alexey Bataev1d677132015-04-22 13:57:31 +0000681 /// \brief Emits code for parallel or serial call of the \a OutlinedFn with
682 /// variables captured in a record which address is stored in \a
683 /// CapturedStruct.
Alexey Bataev18095712014-10-10 12:19:54 +0000684 /// \param OutlinedFn Outlined function to be run in parallel threads. Type of
Alexey Bataev62b63b12015-03-10 07:28:44 +0000685 /// this function is void(*)(kmp_int32 *, kmp_int32, struct context_vars*).
NAKAMURA Takumi62f0eb52015-09-11 08:13:32 +0000686 /// \param CapturedVars A pointer to the record with the references to
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000687 /// variables used in \a OutlinedFn function.
Alexey Bataev1d677132015-04-22 13:57:31 +0000688 /// \param IfCond Condition in the associated 'if' clause, if it was
689 /// specified, nullptr otherwise.
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000690 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000691 virtual void emitParallelCall(CodeGenFunction &CGF, SourceLocation Loc,
692 llvm::Value *OutlinedFn,
Alexey Bataev2377fe92015-09-10 08:12:02 +0000693 ArrayRef<llvm::Value *> CapturedVars,
694 const Expr *IfCond);
Alexey Bataevd74d0602014-10-13 06:02:40 +0000695
Alexey Bataev75ddfab2014-12-01 11:32:38 +0000696 /// \brief Emits a critical region.
Alexey Bataev18095712014-10-10 12:19:54 +0000697 /// \param CriticalName Name of the critical region.
Alexey Bataev75ddfab2014-12-01 11:32:38 +0000698 /// \param CriticalOpGen Generator for the statement associated with the given
699 /// critical region.
Alexey Bataevfc57d162015-12-15 10:55:09 +0000700 /// \param Hint Value of the 'hint' clause (optional).
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000701 virtual void emitCriticalRegion(CodeGenFunction &CGF, StringRef CriticalName,
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000702 const RegionCodeGenTy &CriticalOpGen,
Alexey Bataevfc57d162015-12-15 10:55:09 +0000703 SourceLocation Loc,
704 const Expr *Hint = nullptr);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000705
Alexey Bataev8d690652014-12-04 07:23:53 +0000706 /// \brief Emits a master region.
707 /// \param MasterOpGen Generator for the statement associated with the given
708 /// master region.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000709 virtual void emitMasterRegion(CodeGenFunction &CGF,
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000710 const RegionCodeGenTy &MasterOpGen,
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000711 SourceLocation Loc);
Alexey Bataev8d690652014-12-04 07:23:53 +0000712
Alexey Bataev9f797f32015-02-05 05:57:51 +0000713 /// \brief Emits code for a taskyield directive.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000714 virtual void emitTaskyieldCall(CodeGenFunction &CGF, SourceLocation Loc);
Alexey Bataev9f797f32015-02-05 05:57:51 +0000715
Alexey Bataevc30dd2d2015-06-18 12:14:09 +0000716 /// \brief Emit a taskgroup region.
717 /// \param TaskgroupOpGen Generator for the statement associated with the
718 /// given taskgroup region.
719 virtual void emitTaskgroupRegion(CodeGenFunction &CGF,
720 const RegionCodeGenTy &TaskgroupOpGen,
721 SourceLocation Loc);
722
Alexey Bataev6956e2e2015-02-05 06:35:41 +0000723 /// \brief Emits a single region.
724 /// \param SingleOpGen Generator for the statement associated with the given
725 /// single region.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000726 virtual void emitSingleRegion(CodeGenFunction &CGF,
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000727 const RegionCodeGenTy &SingleOpGen,
Alexey Bataeva63048e2015-03-23 06:18:07 +0000728 SourceLocation Loc,
729 ArrayRef<const Expr *> CopyprivateVars,
Alexey Bataev420d45b2015-04-14 05:11:24 +0000730 ArrayRef<const Expr *> DestExprs,
Alexey Bataeva63048e2015-03-23 06:18:07 +0000731 ArrayRef<const Expr *> SrcExprs,
Alexey Bataeva63048e2015-03-23 06:18:07 +0000732 ArrayRef<const Expr *> AssignmentOps);
Alexey Bataev6956e2e2015-02-05 06:35:41 +0000733
Alexey Bataev98eb6e32015-04-22 11:15:40 +0000734 /// \brief Emit an ordered region.
735 /// \param OrderedOpGen Generator for the statement associated with the given
Alexey Bataevc30dd2d2015-06-18 12:14:09 +0000736 /// ordered region.
Alexey Bataev98eb6e32015-04-22 11:15:40 +0000737 virtual void emitOrderedRegion(CodeGenFunction &CGF,
738 const RegionCodeGenTy &OrderedOpGen,
Alexey Bataev5f600d62015-09-29 03:48:57 +0000739 SourceLocation Loc, bool IsThreads);
Alexey Bataev98eb6e32015-04-22 11:15:40 +0000740
Alexey Bataevf2685682015-03-30 04:30:22 +0000741 /// \brief Emit an implicit/explicit barrier for OpenMP threads.
742 /// \param Kind Directive for which this implicit barrier call must be
743 /// generated. Must be OMPD_barrier for explicit barrier generation.
Alexey Bataev25e5b442015-09-15 12:52:43 +0000744 /// \param EmitChecks true if need to emit checks for cancellation barriers.
745 /// \param ForceSimpleCall true simple barrier call must be emitted, false if
746 /// runtime class decides which one to emit (simple or with cancellation
747 /// checks).
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000748 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000749 virtual void emitBarrierCall(CodeGenFunction &CGF, SourceLocation Loc,
Alexey Bataev81c7ea02015-07-03 09:56:58 +0000750 OpenMPDirectiveKind Kind,
Alexey Bataev25e5b442015-09-15 12:52:43 +0000751 bool EmitChecks = true,
752 bool ForceSimpleCall = false);
Alexey Bataevb2059782014-10-13 08:23:51 +0000753
Alexander Musmanc6388682014-12-15 07:07:06 +0000754 /// \brief Check if the specified \a ScheduleKind is static non-chunked.
755 /// This kind of worksharing directive is emitted without outer loop.
756 /// \param ScheduleKind Schedule kind specified in the 'schedule' clause.
757 /// \param Chunked True if chunk is specified in the clause.
758 ///
759 virtual bool isStaticNonchunked(OpenMPScheduleClauseKind ScheduleKind,
760 bool Chunked) const;
761
Carlo Bertollifc35ad22016-03-07 16:04:49 +0000762 /// \brief Check if the specified \a ScheduleKind is static non-chunked.
763 /// This kind of distribute directive is emitted without outer loop.
764 /// \param ScheduleKind Schedule kind specified in the 'dist_schedule' clause.
765 /// \param Chunked True if chunk is specified in the clause.
766 ///
767 virtual bool isStaticNonchunked(OpenMPDistScheduleClauseKind ScheduleKind,
768 bool Chunked) const;
769
Alexander Musmandf7a8e22015-01-22 08:49:35 +0000770 /// \brief Check if the specified \a ScheduleKind is dynamic.
771 /// This kind of worksharing directive is emitted without outer loop.
772 /// \param ScheduleKind Schedule Kind specified in the 'schedule' clause.
773 ///
774 virtual bool isDynamic(OpenMPScheduleClauseKind ScheduleKind) const;
775
Carlo Bertollib0ff0a62017-04-25 17:52:12 +0000776 /// struct with the values to be passed to the dispatch runtime function
777 struct DispatchRTInput {
778 /// Loop lower bound
779 llvm::Value *LB = nullptr;
780 /// Loop upper bound
781 llvm::Value *UB = nullptr;
782 /// Chunk size specified using 'schedule' clause (nullptr if chunk
783 /// was not specified)
784 llvm::Value *Chunk = nullptr;
785 DispatchRTInput() = default;
786 DispatchRTInput(llvm::Value *LB, llvm::Value *UB, llvm::Value *Chunk)
787 : LB(LB), UB(UB), Chunk(Chunk) {}
788 };
789
790 /// Call the appropriate runtime routine to initialize it before start
791 /// of loop.
792
793 /// This is used for non static scheduled types and when the ordered
794 /// clause is present on the loop construct.
795 /// Depending on the loop schedule, it is necessary to call some runtime
796 /// routine before start of the OpenMP loop to get the loop upper / lower
797 /// bounds \a LB and \a UB and stride \a ST.
798 ///
799 /// \param CGF Reference to current CodeGenFunction.
800 /// \param Loc Clang source location.
801 /// \param ScheduleKind Schedule kind, specified by the 'schedule' clause.
802 /// \param IVSize Size of the iteration variable in bits.
Simon Pilgrim6c0eeff2017-07-13 17:34:44 +0000803 /// \param IVSigned Sign of the iteration variable.
Carlo Bertollib0ff0a62017-04-25 17:52:12 +0000804 /// \param Ordered true if loop is ordered, false otherwise.
805 /// \param DispatchValues struct containing llvm values for lower bound, upper
806 /// bound, and chunk expression.
807 /// For the default (nullptr) value, the chunk 1 will be used.
808 ///
NAKAMURA Takumiff7a9252015-09-08 09:42:41 +0000809 virtual void emitForDispatchInit(CodeGenFunction &CGF, SourceLocation Loc,
Alexey Bataev9ebd7422016-05-10 09:57:36 +0000810 const OpenMPScheduleTy &ScheduleKind,
811 unsigned IVSize, bool IVSigned, bool Ordered,
Carlo Bertollib0ff0a62017-04-25 17:52:12 +0000812 const DispatchRTInput &DispatchValues);
NAKAMURA Takumiff7a9252015-09-08 09:42:41 +0000813
Alexey Bataev0f87dbe2017-08-14 17:56:13 +0000814 /// Struct with the values to be passed to the static runtime function
815 struct StaticRTInput {
816 /// Size of the iteration variable in bits.
817 unsigned IVSize = 0;
818 /// Sign of the iteration variable.
819 bool IVSigned = false;
820 /// true if loop is ordered, false otherwise.
821 bool Ordered = false;
822 /// Address of the output variable in which the flag of the last iteration
823 /// is returned.
824 Address IL = Address::invalid();
825 /// Address of the output variable in which the lower iteration number is
826 /// returned.
827 Address LB = Address::invalid();
828 /// Address of the output variable in which the upper iteration number is
829 /// returned.
830 Address UB = Address::invalid();
831 /// Address of the output variable in which the stride value is returned
832 /// necessary to generated the static_chunked scheduled loop.
833 Address ST = Address::invalid();
834 /// Value of the chunk for the static_chunked scheduled loop. For the
835 /// default (nullptr) value, the chunk 1 will be used.
836 llvm::Value *Chunk = nullptr;
837 StaticRTInput(unsigned IVSize, bool IVSigned, bool Ordered, Address IL,
838 Address LB, Address UB, Address ST,
839 llvm::Value *Chunk = nullptr)
840 : IVSize(IVSize), IVSigned(IVSigned), Ordered(Ordered), IL(IL), LB(LB),
841 UB(UB), ST(ST), Chunk(Chunk) {}
842 };
Alexander Musmanc6388682014-12-15 07:07:06 +0000843 /// \brief Call the appropriate runtime routine to initialize it before start
844 /// of loop.
845 ///
Carlo Bertollib0ff0a62017-04-25 17:52:12 +0000846 /// This is used only in case of static schedule, when the user did not
847 /// specify a ordered clause on the loop construct.
848 /// Depending on the loop schedule, it is necessary to call some runtime
Alexander Musmanc6388682014-12-15 07:07:06 +0000849 /// routine before start of the OpenMP loop to get the loop upper / lower
Alexey Bataev0f87dbe2017-08-14 17:56:13 +0000850 /// bounds LB and UB and stride ST.
Alexander Musmanc6388682014-12-15 07:07:06 +0000851 ///
852 /// \param CGF Reference to current CodeGenFunction.
853 /// \param Loc Clang source location.
Alexey Bataev0f87dbe2017-08-14 17:56:13 +0000854 /// \param DKind Kind of the directive.
Alexey Bataev9ebd7422016-05-10 09:57:36 +0000855 /// \param ScheduleKind Schedule kind, specified by the 'schedule' clause.
Alexey Bataev0f87dbe2017-08-14 17:56:13 +0000856 /// \param Values Input arguments for the construct.
Alexander Musmanc6388682014-12-15 07:07:06 +0000857 ///
John McCall7f416cc2015-09-08 08:05:57 +0000858 virtual void emitForStaticInit(CodeGenFunction &CGF, SourceLocation Loc,
Alexey Bataev0f87dbe2017-08-14 17:56:13 +0000859 OpenMPDirectiveKind DKind,
Alexey Bataev9ebd7422016-05-10 09:57:36 +0000860 const OpenMPScheduleTy &ScheduleKind,
Alexey Bataev0f87dbe2017-08-14 17:56:13 +0000861 const StaticRTInput &Values);
Alexander Musmanc6388682014-12-15 07:07:06 +0000862
Carlo Bertollifc35ad22016-03-07 16:04:49 +0000863 ///
864 /// \param CGF Reference to current CodeGenFunction.
865 /// \param Loc Clang source location.
866 /// \param SchedKind Schedule kind, specified by the 'dist_schedule' clause.
Alexey Bataev0f87dbe2017-08-14 17:56:13 +0000867 /// \param Values Input arguments for the construct.
Carlo Bertollifc35ad22016-03-07 16:04:49 +0000868 ///
Alexey Bataev0f87dbe2017-08-14 17:56:13 +0000869 virtual void emitDistributeStaticInit(CodeGenFunction &CGF,
870 SourceLocation Loc,
Carlo Bertollifc35ad22016-03-07 16:04:49 +0000871 OpenMPDistScheduleClauseKind SchedKind,
Alexey Bataev0f87dbe2017-08-14 17:56:13 +0000872 const StaticRTInput &Values);
Carlo Bertollifc35ad22016-03-07 16:04:49 +0000873
Alexander Musmanc6388682014-12-15 07:07:06 +0000874 /// \brief Call the appropriate runtime routine to notify that we finished
Alexey Bataev98eb6e32015-04-22 11:15:40 +0000875 /// iteration of the ordered loop with the dynamic scheduling.
876 ///
877 /// \param CGF Reference to current CodeGenFunction.
878 /// \param Loc Clang source location.
879 /// \param IVSize Size of the iteration variable in bits.
Simon Pilgrim6c0eeff2017-07-13 17:34:44 +0000880 /// \param IVSigned Sign of the iteration variable.
Alexey Bataev98eb6e32015-04-22 11:15:40 +0000881 ///
Alexey Bataevd7589ffe2015-05-20 13:12:48 +0000882 virtual void emitForOrderedIterationEnd(CodeGenFunction &CGF,
883 SourceLocation Loc, unsigned IVSize,
884 bool IVSigned);
Alexey Bataev98eb6e32015-04-22 11:15:40 +0000885
886 /// \brief Call the appropriate runtime routine to notify that we finished
Alexander Musmanc6388682014-12-15 07:07:06 +0000887 /// all the work with current loop.
888 ///
889 /// \param CGF Reference to current CodeGenFunction.
890 /// \param Loc Clang source location.
Alexey Bataevf43f7142017-09-06 16:17:35 +0000891 /// \param DKind Kind of the directive for which the static finish is emitted.
Alexander Musmanc6388682014-12-15 07:07:06 +0000892 ///
Alexey Bataevf43f7142017-09-06 16:17:35 +0000893 virtual void emitForStaticFinish(CodeGenFunction &CGF, SourceLocation Loc,
894 OpenMPDirectiveKind DKind);
Alexander Musmanc6388682014-12-15 07:07:06 +0000895
Alexander Musman92bdaab2015-03-12 13:37:50 +0000896 /// Call __kmpc_dispatch_next(
897 /// ident_t *loc, kmp_int32 tid, kmp_int32 *p_lastiter,
898 /// kmp_int[32|64] *p_lower, kmp_int[32|64] *p_upper,
899 /// kmp_int[32|64] *p_stride);
900 /// \param IVSize Size of the iteration variable in bits.
Simon Pilgrim6c0eeff2017-07-13 17:34:44 +0000901 /// \param IVSigned Sign of the iteration variable.
Alexander Musman92bdaab2015-03-12 13:37:50 +0000902 /// \param IL Address of the output variable in which the flag of the
903 /// last iteration is returned.
904 /// \param LB Address of the output variable in which the lower iteration
905 /// number is returned.
906 /// \param UB Address of the output variable in which the upper iteration
907 /// number is returned.
908 /// \param ST Address of the output variable in which the stride value is
909 /// returned.
910 virtual llvm::Value *emitForNext(CodeGenFunction &CGF, SourceLocation Loc,
911 unsigned IVSize, bool IVSigned,
John McCall7f416cc2015-09-08 08:05:57 +0000912 Address IL, Address LB,
913 Address UB, Address ST);
Alexander Musman92bdaab2015-03-12 13:37:50 +0000914
Alexey Bataevb2059782014-10-13 08:23:51 +0000915 /// \brief Emits call to void __kmpc_push_num_threads(ident_t *loc, kmp_int32
916 /// global_tid, kmp_int32 num_threads) to generate code for 'num_threads'
917 /// clause.
918 /// \param NumThreads An integer value of threads.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000919 virtual void emitNumThreadsClause(CodeGenFunction &CGF,
920 llvm::Value *NumThreads,
921 SourceLocation Loc);
Alexey Bataev97720002014-11-11 04:05:39 +0000922
Alexey Bataev7f210c62015-06-18 13:40:03 +0000923 /// \brief Emit call to void __kmpc_push_proc_bind(ident_t *loc, kmp_int32
924 /// global_tid, int proc_bind) to generate code for 'proc_bind' clause.
925 virtual void emitProcBindClause(CodeGenFunction &CGF,
926 OpenMPProcBindClauseKind ProcBind,
927 SourceLocation Loc);
928
Alexey Bataev97720002014-11-11 04:05:39 +0000929 /// \brief Returns address of the threadprivate variable for the current
930 /// thread.
NAKAMURA Takumicdcbfba2014-11-11 07:58:06 +0000931 /// \param VD Threadprivate variable.
Alexey Bataev97720002014-11-11 04:05:39 +0000932 /// \param VDAddr Address of the global variable \a VD.
933 /// \param Loc Location of the reference to threadprivate var.
934 /// \return Address of the threadprivate variable for the current thread.
John McCall7f416cc2015-09-08 08:05:57 +0000935 virtual Address getAddrOfThreadPrivate(CodeGenFunction &CGF,
936 const VarDecl *VD,
937 Address VDAddr,
938 SourceLocation Loc);
Alexey Bataev97720002014-11-11 04:05:39 +0000939
940 /// \brief Emit a code for initialization of threadprivate variable. It emits
941 /// a call to runtime library which adds initial value to the newly created
942 /// threadprivate variable (if it is not constant) and registers destructor
943 /// for the variable (if any).
944 /// \param VD Threadprivate variable.
945 /// \param VDAddr Address of the global variable \a VD.
946 /// \param Loc Location of threadprivate declaration.
947 /// \param PerformInit true if initialization expression is not constant.
948 virtual llvm::Function *
John McCall7f416cc2015-09-08 08:05:57 +0000949 emitThreadPrivateVarDefinition(const VarDecl *VD, Address VDAddr,
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000950 SourceLocation Loc, bool PerformInit,
951 CodeGenFunction *CGF = nullptr);
Alexey Bataevcc37cc12014-11-20 04:34:54 +0000952
Alexey Bataevbe5a8b42017-07-17 13:30:36 +0000953 /// Creates artificial threadprivate variable with name \p Name and type \p
954 /// VarType.
955 /// \param VarType Type of the artificial threadprivate variable.
956 /// \param Name Name of the artificial threadprivate variable.
957 virtual Address getAddrOfArtificialThreadPrivate(CodeGenFunction &CGF,
958 QualType VarType,
959 StringRef Name);
960
Alexey Bataevcc37cc12014-11-20 04:34:54 +0000961 /// \brief Emit flush of the variables specified in 'omp flush' directive.
962 /// \param Vars List of variables to flush.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000963 virtual void emitFlush(CodeGenFunction &CGF, ArrayRef<const Expr *> Vars,
964 SourceLocation Loc);
Alexey Bataev62b63b12015-03-10 07:28:44 +0000965
966 /// \brief Emit task region for the task directive. The task region is
Nico Weber20b0ce32015-04-28 18:19:18 +0000967 /// emitted in several steps:
Alexey Bataev62b63b12015-03-10 07:28:44 +0000968 /// 1. Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32
969 /// gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds,
970 /// kmp_routine_entry_t *task_entry). Here task_entry is a pointer to the
971 /// function:
972 /// kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) {
973 /// TaskFunction(gtid, tt->part_id, tt->shareds);
974 /// return 0;
975 /// }
976 /// 2. Copy a list of shared variables to field shareds of the resulting
977 /// structure kmp_task_t returned by the previous call (if any).
978 /// 3. Copy a pointer to destructions function to field destructions of the
979 /// resulting structure kmp_task_t.
980 /// 4. Emit a call to kmp_int32 __kmpc_omp_task(ident_t *, kmp_int32 gtid,
981 /// kmp_task_t *new_task), where new_task is a resulting structure from
982 /// previous items.
Alexey Bataev36c1eb92015-04-30 06:51:57 +0000983 /// \param D Current task directive.
Alexey Bataev62b63b12015-03-10 07:28:44 +0000984 /// \param TaskFunction An LLVM function with type void (*)(i32 /*gtid*/, i32
985 /// /*part_id*/, captured_struct */*__context*/);
986 /// \param SharedsTy A type which contains references the shared variables.
Alexey Bataev1d2353d2015-06-24 11:01:36 +0000987 /// \param Shareds Context with the list of shared variables from the \p
Alexey Bataev62b63b12015-03-10 07:28:44 +0000988 /// TaskFunction.
Alexey Bataev1d677132015-04-22 13:57:31 +0000989 /// \param IfCond Not a nullptr if 'if' clause was specified, nullptr
990 /// otherwise.
Alexey Bataev24b5bae2016-04-28 09:23:51 +0000991 /// \param Data Additional data for task generation like tiednsee, final
992 /// state, list of privates etc.
993 virtual void emitTaskCall(CodeGenFunction &CGF, SourceLocation Loc,
994 const OMPExecutableDirective &D,
995 llvm::Value *TaskFunction, QualType SharedsTy,
996 Address Shareds, const Expr *IfCond,
997 const OMPTaskDataTy &Data);
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000998
Alexey Bataev7292c292016-04-25 12:22:29 +0000999 /// Emit task region for the taskloop directive. The taskloop region is
1000 /// emitted in several steps:
1001 /// 1. Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32
1002 /// gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds,
1003 /// kmp_routine_entry_t *task_entry). Here task_entry is a pointer to the
1004 /// function:
1005 /// kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) {
1006 /// TaskFunction(gtid, tt->part_id, tt->shareds);
1007 /// return 0;
1008 /// }
1009 /// 2. Copy a list of shared variables to field shareds of the resulting
1010 /// structure kmp_task_t returned by the previous call (if any).
1011 /// 3. Copy a pointer to destructions function to field destructions of the
1012 /// resulting structure kmp_task_t.
1013 /// 4. Emit a call to void __kmpc_taskloop(ident_t *loc, int gtid, kmp_task_t
1014 /// *task, int if_val, kmp_uint64 *lb, kmp_uint64 *ub, kmp_int64 st, int
1015 /// nogroup, int sched, kmp_uint64 grainsize, void *task_dup ), where new_task
1016 /// is a resulting structure from
1017 /// previous items.
1018 /// \param D Current task directive.
Alexey Bataev7292c292016-04-25 12:22:29 +00001019 /// \param TaskFunction An LLVM function with type void (*)(i32 /*gtid*/, i32
1020 /// /*part_id*/, captured_struct */*__context*/);
1021 /// \param SharedsTy A type which contains references the shared variables.
1022 /// \param Shareds Context with the list of shared variables from the \p
1023 /// TaskFunction.
1024 /// \param IfCond Not a nullptr if 'if' clause was specified, nullptr
1025 /// otherwise.
Alexey Bataev24b5bae2016-04-28 09:23:51 +00001026 /// \param Data Additional data for task generation like tiednsee, final
1027 /// state, list of privates etc.
Alexey Bataev7292c292016-04-25 12:22:29 +00001028 virtual void emitTaskLoopCall(
1029 CodeGenFunction &CGF, SourceLocation Loc, const OMPLoopDirective &D,
Alexey Bataev24b5bae2016-04-28 09:23:51 +00001030 llvm::Value *TaskFunction, QualType SharedsTy, Address Shareds,
1031 const Expr *IfCond, const OMPTaskDataTy &Data);
Alexey Bataev7292c292016-04-25 12:22:29 +00001032
Alexey Bataev6f1ffc02015-04-10 04:50:10 +00001033 /// \brief Emit code for the directive that does not require outlining.
1034 ///
Alexey Bataev81c7ea02015-07-03 09:56:58 +00001035 /// \param InnermostKind Kind of innermost directive (for simple directives it
1036 /// is a directive itself, for combined - its innermost directive).
Alexey Bataev6f1ffc02015-04-10 04:50:10 +00001037 /// \param CodeGen Code generation sequence for the \a D directive.
Alexey Bataev25e5b442015-09-15 12:52:43 +00001038 /// \param HasCancel true if region has inner cancel directive, false
1039 /// otherwise.
Alexey Bataev6f1ffc02015-04-10 04:50:10 +00001040 virtual void emitInlinedDirective(CodeGenFunction &CGF,
Alexey Bataev81c7ea02015-07-03 09:56:58 +00001041 OpenMPDirectiveKind InnermostKind,
Alexey Bataev25e5b442015-09-15 12:52:43 +00001042 const RegionCodeGenTy &CodeGen,
1043 bool HasCancel = false);
Arpith Chacko Jacob101e8fb2017-02-16 16:20:16 +00001044
1045 /// Emits reduction function.
1046 /// \param ArgsType Array type containing pointers to reduction variables.
1047 /// \param Privates List of private copies for original reduction arguments.
1048 /// \param LHSExprs List of LHS in \a ReductionOps reduction operations.
1049 /// \param RHSExprs List of RHS in \a ReductionOps reduction operations.
1050 /// \param ReductionOps List of reduction operations in form 'LHS binop RHS'
1051 /// or 'operator binop(LHS, RHS)'.
Alexey Bataev7cae94e2018-01-04 19:45:16 +00001052 llvm::Value *emitReductionFunction(CodeGenModule &CGM, SourceLocation Loc,
1053 llvm::Type *ArgsType,
Arpith Chacko Jacob101e8fb2017-02-16 16:20:16 +00001054 ArrayRef<const Expr *> Privates,
1055 ArrayRef<const Expr *> LHSExprs,
1056 ArrayRef<const Expr *> RHSExprs,
1057 ArrayRef<const Expr *> ReductionOps);
1058
1059 /// Emits single reduction combiner
1060 void emitSingleReductionCombiner(CodeGenFunction &CGF,
1061 const Expr *ReductionOp,
1062 const Expr *PrivateRef,
1063 const DeclRefExpr *LHS,
1064 const DeclRefExpr *RHS);
1065
1066 struct ReductionOptionsTy {
1067 bool WithNowait;
1068 bool SimpleReduction;
1069 OpenMPDirectiveKind ReductionKind;
1070 };
Alexey Bataev794ba0d2015-04-10 10:43:45 +00001071 /// \brief Emit a code for reduction clause. Next code should be emitted for
1072 /// reduction:
1073 /// \code
1074 ///
1075 /// static kmp_critical_name lock = { 0 };
1076 ///
1077 /// void reduce_func(void *lhs[<n>], void *rhs[<n>]) {
1078 /// ...
1079 /// *(Type<i>*)lhs[i] = RedOp<i>(*(Type<i>*)lhs[i], *(Type<i>*)rhs[i]);
1080 /// ...
1081 /// }
1082 ///
1083 /// ...
1084 /// void *RedList[<n>] = {&<RHSExprs>[0], ..., &<RHSExprs>[<n>-1]};
1085 /// switch (__kmpc_reduce{_nowait}(<loc>, <gtid>, <n>, sizeof(RedList),
1086 /// RedList, reduce_func, &<lock>)) {
1087 /// case 1:
1088 /// ...
1089 /// <LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]);
1090 /// ...
1091 /// __kmpc_end_reduce{_nowait}(<loc>, <gtid>, &<lock>);
1092 /// break;
1093 /// case 2:
1094 /// ...
1095 /// Atomic(<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]));
1096 /// ...
1097 /// break;
1098 /// default:;
1099 /// }
1100 /// \endcode
1101 ///
Alexey Bataevf24e7b12015-10-08 09:10:53 +00001102 /// \param Privates List of private copies for original reduction arguments.
Alexey Bataev794ba0d2015-04-10 10:43:45 +00001103 /// \param LHSExprs List of LHS in \a ReductionOps reduction operations.
1104 /// \param RHSExprs List of RHS in \a ReductionOps reduction operations.
1105 /// \param ReductionOps List of reduction operations in form 'LHS binop RHS'
1106 /// or 'operator binop(LHS, RHS)'.
Arpith Chacko Jacob101e8fb2017-02-16 16:20:16 +00001107 /// \param Options List of options for reduction codegen:
1108 /// WithNowait true if parent directive has also nowait clause, false
1109 /// otherwise.
1110 /// SimpleReduction Emit reduction operation only. Used for omp simd
1111 /// directive on the host.
1112 /// ReductionKind The kind of reduction to perform.
Alexey Bataev794ba0d2015-04-10 10:43:45 +00001113 virtual void emitReduction(CodeGenFunction &CGF, SourceLocation Loc,
Alexey Bataevf24e7b12015-10-08 09:10:53 +00001114 ArrayRef<const Expr *> Privates,
Alexey Bataev794ba0d2015-04-10 10:43:45 +00001115 ArrayRef<const Expr *> LHSExprs,
1116 ArrayRef<const Expr *> RHSExprs,
1117 ArrayRef<const Expr *> ReductionOps,
Arpith Chacko Jacob101e8fb2017-02-16 16:20:16 +00001118 ReductionOptionsTy Options);
Alexey Bataev8b8e2022015-04-27 05:22:09 +00001119
Alexey Bataevbe5a8b42017-07-17 13:30:36 +00001120 /// Emit a code for initialization of task reduction clause. Next code
1121 /// should be emitted for reduction:
1122 /// \code
1123 ///
1124 /// _task_red_item_t red_data[n];
1125 /// ...
1126 /// red_data[i].shar = &origs[i];
1127 /// red_data[i].size = sizeof(origs[i]);
1128 /// red_data[i].f_init = (void*)RedInit<i>;
1129 /// red_data[i].f_fini = (void*)RedDest<i>;
1130 /// red_data[i].f_comb = (void*)RedOp<i>;
1131 /// red_data[i].flags = <Flag_i>;
1132 /// ...
1133 /// void* tg1 = __kmpc_task_reduction_init(gtid, n, red_data);
1134 /// \endcode
1135 ///
1136 /// \param LHSExprs List of LHS in \a Data.ReductionOps reduction operations.
1137 /// \param RHSExprs List of RHS in \a Data.ReductionOps reduction operations.
1138 /// \param Data Additional data for task generation like tiedness, final
1139 /// state, list of privates, reductions etc.
1140 virtual llvm::Value *emitTaskReductionInit(CodeGenFunction &CGF,
1141 SourceLocation Loc,
1142 ArrayRef<const Expr *> LHSExprs,
1143 ArrayRef<const Expr *> RHSExprs,
1144 const OMPTaskDataTy &Data);
1145
1146 /// Required to resolve existing problems in the runtime. Emits threadprivate
1147 /// variables to store the size of the VLAs/array sections for
1148 /// initializer/combiner/finalizer functions + emits threadprivate variable to
1149 /// store the pointer to the original reduction item for the custom
1150 /// initializer defined by declare reduction construct.
1151 /// \param RCG Allows to reuse an existing data for the reductions.
1152 /// \param N Reduction item for which fixups must be emitted.
1153 virtual void emitTaskReductionFixups(CodeGenFunction &CGF, SourceLocation Loc,
1154 ReductionCodeGen &RCG, unsigned N);
1155
1156 /// Get the address of `void *` type of the privatue copy of the reduction
1157 /// item specified by the \p SharedLVal.
1158 /// \param ReductionsPtr Pointer to the reduction data returned by the
1159 /// emitTaskReductionInit function.
1160 /// \param SharedLVal Address of the original reduction item.
1161 virtual Address getTaskReductionItem(CodeGenFunction &CGF, SourceLocation Loc,
1162 llvm::Value *ReductionsPtr,
1163 LValue SharedLVal);
1164
Alexey Bataev8b8e2022015-04-27 05:22:09 +00001165 /// \brief Emit code for 'taskwait' directive.
1166 virtual void emitTaskwaitCall(CodeGenFunction &CGF, SourceLocation Loc);
Alexey Bataev0f34da12015-07-02 04:17:07 +00001167
1168 /// \brief Emit code for 'cancellation point' construct.
1169 /// \param CancelRegion Region kind for which the cancellation point must be
1170 /// emitted.
1171 ///
1172 virtual void emitCancellationPointCall(CodeGenFunction &CGF,
1173 SourceLocation Loc,
1174 OpenMPDirectiveKind CancelRegion);
Alexey Bataev7d5d33e2015-07-06 05:50:32 +00001175
1176 /// \brief Emit code for 'cancel' construct.
Alexey Bataev87933c72015-09-18 08:07:34 +00001177 /// \param IfCond Condition in the associated 'if' clause, if it was
1178 /// specified, nullptr otherwise.
Alexey Bataev7d5d33e2015-07-06 05:50:32 +00001179 /// \param CancelRegion Region kind for which the cancel must be emitted.
1180 ///
1181 virtual void emitCancelCall(CodeGenFunction &CGF, SourceLocation Loc,
Alexey Bataev87933c72015-09-18 08:07:34 +00001182 const Expr *IfCond,
Alexey Bataev7d5d33e2015-07-06 05:50:32 +00001183 OpenMPDirectiveKind CancelRegion);
Samuel Antaobed3c462015-10-02 16:14:20 +00001184
1185 /// \brief Emit outilined function for 'target' directive.
1186 /// \param D Directive to emit.
Samuel Antaoee8fb302016-01-06 13:42:12 +00001187 /// \param ParentName Name of the function that encloses the target region.
1188 /// \param OutlinedFn Outlined function value to be defined by this call.
1189 /// \param OutlinedFnID Outlined function ID value to be defined by this call.
1190 /// \param IsOffloadEntry True if the outlined function is an offload entry.
Alexey Bataev14fa1c62016-03-29 05:34:15 +00001191 /// \param CodeGen Code generation sequence for the \a D directive.
Simon Pilgrim6c0eeff2017-07-13 17:34:44 +00001192 /// An outlined function may not be an entry if, e.g. the if clause always
Samuel Antaoee8fb302016-01-06 13:42:12 +00001193 /// evaluates to false.
1194 virtual void emitTargetOutlinedFunction(const OMPExecutableDirective &D,
1195 StringRef ParentName,
1196 llvm::Function *&OutlinedFn,
1197 llvm::Constant *&OutlinedFnID,
Alexey Bataev14fa1c62016-03-29 05:34:15 +00001198 bool IsOffloadEntry,
1199 const RegionCodeGenTy &CodeGen);
Samuel Antaobed3c462015-10-02 16:14:20 +00001200
1201 /// \brief Emit the target offloading code associated with \a D. The emitted
1202 /// code attempts offloading the execution to the device, an the event of
1203 /// a failure it executes the host version outlined in \a OutlinedFn.
1204 /// \param D Directive to emit.
1205 /// \param OutlinedFn Host version of the code to be offloaded.
Samuel Antaoee8fb302016-01-06 13:42:12 +00001206 /// \param OutlinedFnID ID of host version of the code to be offloaded.
Samuel Antaobed3c462015-10-02 16:14:20 +00001207 /// \param IfCond Expression evaluated in if clause associated with the target
1208 /// directive, or null if no if clause is used.
1209 /// \param Device Expression evaluated in device clause associated with the
1210 /// target directive, or null if no device clause is used.
Samuel Antaobed3c462015-10-02 16:14:20 +00001211 virtual void emitTargetCall(CodeGenFunction &CGF,
1212 const OMPExecutableDirective &D,
Samuel Antaoee8fb302016-01-06 13:42:12 +00001213 llvm::Value *OutlinedFn,
1214 llvm::Value *OutlinedFnID, const Expr *IfCond,
Alexey Bataev8451efa2018-01-15 19:06:12 +00001215 const Expr *Device);
Samuel Antaoee8fb302016-01-06 13:42:12 +00001216
1217 /// \brief Emit the target regions enclosed in \a GD function definition or
1218 /// the function itself in case it is a valid device function. Returns true if
1219 /// \a GD was dealt with successfully.
Nico Webera2abe8c2016-01-06 19:13:49 +00001220 /// \param GD Function to scan.
Samuel Antaoee8fb302016-01-06 13:42:12 +00001221 virtual bool emitTargetFunctions(GlobalDecl GD);
1222
1223 /// \brief Emit the global variable if it is a valid device global variable.
1224 /// Returns true if \a GD was dealt with successfully.
1225 /// \param GD Variable declaration to emit.
1226 virtual bool emitTargetGlobalVariable(GlobalDecl GD);
1227
1228 /// \brief Emit the global \a GD if it is meaningful for the target. Returns
Simon Pilgrim2c518802017-03-30 14:13:19 +00001229 /// if it was emitted successfully.
Samuel Antaoee8fb302016-01-06 13:42:12 +00001230 /// \param GD Global to scan.
1231 virtual bool emitTargetGlobal(GlobalDecl GD);
1232
1233 /// \brief Creates the offloading descriptor in the event any target region
1234 /// was emitted in the current module and return the function that registers
1235 /// it.
1236 virtual llvm::Function *emitRegistrationFunction();
Carlo Bertolli430d8ec2016-03-03 20:34:23 +00001237
1238 /// \brief Emits code for teams call of the \a OutlinedFn with
1239 /// variables captured in a record which address is stored in \a
1240 /// CapturedStruct.
1241 /// \param OutlinedFn Outlined function to be run by team masters. Type of
1242 /// this function is void(*)(kmp_int32 *, kmp_int32, struct context_vars*).
1243 /// \param CapturedVars A pointer to the record with the references to
1244 /// variables used in \a OutlinedFn function.
1245 ///
1246 virtual void emitTeamsCall(CodeGenFunction &CGF,
1247 const OMPExecutableDirective &D,
1248 SourceLocation Loc, llvm::Value *OutlinedFn,
1249 ArrayRef<llvm::Value *> CapturedVars);
1250
1251 /// \brief Emits call to void __kmpc_push_num_teams(ident_t *loc, kmp_int32
1252 /// global_tid, kmp_int32 num_teams, kmp_int32 thread_limit) to generate code
1253 /// for num_teams clause.
Carlo Bertollic6872252016-04-04 15:55:02 +00001254 /// \param NumTeams An integer expression of teams.
1255 /// \param ThreadLimit An integer expression of threads.
1256 virtual void emitNumTeamsClause(CodeGenFunction &CGF, const Expr *NumTeams,
1257 const Expr *ThreadLimit, SourceLocation Loc);
Samuel Antaodf158d52016-04-27 22:58:19 +00001258
Samuel Antaocc10b852016-07-28 14:23:26 +00001259 /// Struct that keeps all the relevant information that should be kept
1260 /// throughout a 'target data' region.
1261 class TargetDataInfo {
1262 /// Set to true if device pointer information have to be obtained.
1263 bool RequiresDevicePointerInfo = false;
1264
1265 public:
1266 /// The array of base pointer passed to the runtime library.
1267 llvm::Value *BasePointersArray = nullptr;
1268 /// The array of section pointers passed to the runtime library.
1269 llvm::Value *PointersArray = nullptr;
1270 /// The array of sizes passed to the runtime library.
1271 llvm::Value *SizesArray = nullptr;
1272 /// The array of map types passed to the runtime library.
1273 llvm::Value *MapTypesArray = nullptr;
1274 /// The total number of pointers passed to the runtime library.
1275 unsigned NumberOfPtrs = 0u;
1276 /// Map between the a declaration of a capture and the corresponding base
1277 /// pointer address where the runtime returns the device pointers.
1278 llvm::DenseMap<const ValueDecl *, Address> CaptureDeviceAddrMap;
1279
1280 explicit TargetDataInfo() {}
1281 explicit TargetDataInfo(bool RequiresDevicePointerInfo)
1282 : RequiresDevicePointerInfo(RequiresDevicePointerInfo) {}
1283 /// Clear information about the data arrays.
1284 void clearArrayInfo() {
1285 BasePointersArray = nullptr;
1286 PointersArray = nullptr;
1287 SizesArray = nullptr;
1288 MapTypesArray = nullptr;
1289 NumberOfPtrs = 0u;
1290 }
1291 /// Return true if the current target data information has valid arrays.
1292 bool isValid() {
1293 return BasePointersArray && PointersArray && SizesArray &&
1294 MapTypesArray && NumberOfPtrs;
1295 }
1296 bool requiresDevicePointerInfo() { return RequiresDevicePointerInfo; }
1297 };
1298
Samuel Antaodf158d52016-04-27 22:58:19 +00001299 /// \brief Emit the target data mapping code associated with \a D.
1300 /// \param D Directive to emit.
Samuel Antaocc10b852016-07-28 14:23:26 +00001301 /// \param IfCond Expression evaluated in if clause associated with the
1302 /// target directive, or null if no device clause is used.
Samuel Antaodf158d52016-04-27 22:58:19 +00001303 /// \param Device Expression evaluated in device clause associated with the
1304 /// target directive, or null if no device clause is used.
Samuel Antaocc10b852016-07-28 14:23:26 +00001305 /// \param Info A record used to store information that needs to be preserved
1306 /// until the region is closed.
Samuel Antaodf158d52016-04-27 22:58:19 +00001307 virtual void emitTargetDataCalls(CodeGenFunction &CGF,
1308 const OMPExecutableDirective &D,
1309 const Expr *IfCond, const Expr *Device,
Samuel Antaocc10b852016-07-28 14:23:26 +00001310 const RegionCodeGenTy &CodeGen,
1311 TargetDataInfo &Info);
Samuel Antaobd0ae2e2016-04-27 23:07:29 +00001312
Samuel Antao8d2d7302016-05-26 18:30:22 +00001313 /// \brief Emit the data mapping/movement code associated with the directive
1314 /// \a D that should be of the form 'target [{enter|exit} data | update]'.
Samuel Antaobd0ae2e2016-04-27 23:07:29 +00001315 /// \param D Directive to emit.
1316 /// \param IfCond Expression evaluated in if clause associated with the target
1317 /// directive, or null if no if clause is used.
1318 /// \param Device Expression evaluated in device clause associated with the
1319 /// target directive, or null if no device clause is used.
Samuel Antao8d2d7302016-05-26 18:30:22 +00001320 virtual void emitTargetDataStandAloneCall(CodeGenFunction &CGF,
1321 const OMPExecutableDirective &D,
1322 const Expr *IfCond,
1323 const Expr *Device);
Alexey Bataevc7a82b42016-05-06 09:40:08 +00001324
1325 /// Marks function \a Fn with properly mangled versions of vector functions.
1326 /// \param FD Function marked as 'declare simd'.
1327 /// \param Fn LLVM function that must be marked with 'declare simd'
1328 /// attributes.
1329 virtual void emitDeclareSimdFunction(const FunctionDecl *FD,
1330 llvm::Function *Fn);
Alexey Bataev8b427062016-05-25 12:36:08 +00001331
1332 /// Emit initialization for doacross loop nesting support.
1333 /// \param D Loop-based construct used in doacross nesting construct.
1334 virtual void emitDoacrossInit(CodeGenFunction &CGF,
1335 const OMPLoopDirective &D);
1336
1337 /// Emit code for doacross ordered directive with 'depend' clause.
1338 /// \param C 'depend' clause with 'sink|source' dependency kind.
1339 virtual void emitDoacrossOrdered(CodeGenFunction &CGF,
1340 const OMPDependClause *C);
Alexey Bataev2c7eee52017-08-04 19:10:54 +00001341
Alexey Bataev3b8d5582017-08-08 18:04:06 +00001342 /// Translates the native parameter of outlined function if this is required
1343 /// for target.
1344 /// \param FD Field decl from captured record for the paramater.
1345 /// \param NativeParam Parameter itself.
1346 virtual const VarDecl *translateParameter(const FieldDecl *FD,
1347 const VarDecl *NativeParam) const {
1348 return NativeParam;
1349 }
1350
1351 /// Gets the address of the native argument basing on the address of the
1352 /// target-specific parameter.
1353 /// \param NativeParam Parameter itself.
1354 /// \param TargetParam Corresponding target-specific parameter.
1355 virtual Address getParameterAddress(CodeGenFunction &CGF,
1356 const VarDecl *NativeParam,
1357 const VarDecl *TargetParam) const;
1358
Alexey Bataev2c7eee52017-08-04 19:10:54 +00001359 /// Emits call of the outlined function with the provided arguments,
1360 /// translating these arguments to correct target-specific arguments.
1361 virtual void
Alexey Bataev3c595a62017-08-14 15:01:03 +00001362 emitOutlinedFunctionCall(CodeGenFunction &CGF, SourceLocation Loc,
1363 llvm::Value *OutlinedFn,
Alexey Bataev2c7eee52017-08-04 19:10:54 +00001364 ArrayRef<llvm::Value *> Args = llvm::None) const;
Gheorghe-Teodor Bercead3dcf2f2018-03-14 14:17:45 +00001365
1366 /// Emits OpenMP-specific function prolog.
1367 /// Required for device constructs.
1368 virtual void emitFunctionProlog(CodeGenFunction &CGF, const Decl *D) {}
1369
1370 /// Gets the OpenMP-specific address of the local variable.
1371 virtual Address getAddressOfLocalVariable(CodeGenFunction &CGF,
1372 const VarDecl *VD);
Alexey Bataev9959db52014-05-06 10:08:46 +00001373};
Alexey Bataev8cbe0a62015-02-26 10:27:34 +00001374
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00001375/// Class supports emissionof SIMD-only code.
1376class CGOpenMPSIMDRuntime final : public CGOpenMPRuntime {
1377public:
1378 explicit CGOpenMPSIMDRuntime(CodeGenModule &CGM) : CGOpenMPRuntime(CGM) {}
1379 ~CGOpenMPSIMDRuntime() override {}
1380
1381 /// \brief Emits outlined function for the specified OpenMP parallel directive
1382 /// \a D. This outlined function has type void(*)(kmp_int32 *ThreadID,
1383 /// kmp_int32 BoundID, struct context_vars*).
1384 /// \param D OpenMP directive.
1385 /// \param ThreadIDVar Variable for thread id in the current OpenMP region.
1386 /// \param InnermostKind Kind of innermost directive (for simple directives it
1387 /// is a directive itself, for combined - its innermost directive).
1388 /// \param CodeGen Code generation sequence for the \a D directive.
1389 llvm::Value *
1390 emitParallelOutlinedFunction(const OMPExecutableDirective &D,
1391 const VarDecl *ThreadIDVar,
1392 OpenMPDirectiveKind InnermostKind,
1393 const RegionCodeGenTy &CodeGen) override;
1394
1395 /// \brief Emits outlined function for the specified OpenMP teams directive
1396 /// \a D. This outlined function has type void(*)(kmp_int32 *ThreadID,
1397 /// kmp_int32 BoundID, struct context_vars*).
1398 /// \param D OpenMP directive.
1399 /// \param ThreadIDVar Variable for thread id in the current OpenMP region.
1400 /// \param InnermostKind Kind of innermost directive (for simple directives it
1401 /// is a directive itself, for combined - its innermost directive).
1402 /// \param CodeGen Code generation sequence for the \a D directive.
1403 llvm::Value *
1404 emitTeamsOutlinedFunction(const OMPExecutableDirective &D,
1405 const VarDecl *ThreadIDVar,
1406 OpenMPDirectiveKind InnermostKind,
1407 const RegionCodeGenTy &CodeGen) override;
1408
1409 /// \brief Emits outlined function for the OpenMP task directive \a D. This
1410 /// outlined function has type void(*)(kmp_int32 ThreadID, struct task_t*
1411 /// TaskT).
1412 /// \param D OpenMP directive.
1413 /// \param ThreadIDVar Variable for thread id in the current OpenMP region.
1414 /// \param PartIDVar Variable for partition id in the current OpenMP untied
1415 /// task region.
1416 /// \param TaskTVar Variable for task_t argument.
1417 /// \param InnermostKind Kind of innermost directive (for simple directives it
1418 /// is a directive itself, for combined - its innermost directive).
1419 /// \param CodeGen Code generation sequence for the \a D directive.
1420 /// \param Tied true if task is generated for tied task, false otherwise.
1421 /// \param NumberOfParts Number of parts in untied task. Ignored for tied
1422 /// tasks.
1423 ///
1424 llvm::Value *emitTaskOutlinedFunction(
1425 const OMPExecutableDirective &D, const VarDecl *ThreadIDVar,
1426 const VarDecl *PartIDVar, const VarDecl *TaskTVar,
1427 OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen,
1428 bool Tied, unsigned &NumberOfParts) override;
1429
1430 /// \brief Emits code for parallel or serial call of the \a OutlinedFn with
1431 /// variables captured in a record which address is stored in \a
1432 /// CapturedStruct.
1433 /// \param OutlinedFn Outlined function to be run in parallel threads. Type of
1434 /// this function is void(*)(kmp_int32 *, kmp_int32, struct context_vars*).
1435 /// \param CapturedVars A pointer to the record with the references to
1436 /// variables used in \a OutlinedFn function.
1437 /// \param IfCond Condition in the associated 'if' clause, if it was
1438 /// specified, nullptr otherwise.
1439 ///
1440 void emitParallelCall(CodeGenFunction &CGF, SourceLocation Loc,
1441 llvm::Value *OutlinedFn,
1442 ArrayRef<llvm::Value *> CapturedVars,
1443 const Expr *IfCond) override;
1444
1445 /// \brief Emits a critical region.
1446 /// \param CriticalName Name of the critical region.
1447 /// \param CriticalOpGen Generator for the statement associated with the given
1448 /// critical region.
1449 /// \param Hint Value of the 'hint' clause (optional).
1450 void emitCriticalRegion(CodeGenFunction &CGF, StringRef CriticalName,
1451 const RegionCodeGenTy &CriticalOpGen,
1452 SourceLocation Loc,
1453 const Expr *Hint = nullptr) override;
1454
1455 /// \brief Emits a master region.
1456 /// \param MasterOpGen Generator for the statement associated with the given
1457 /// master region.
1458 void emitMasterRegion(CodeGenFunction &CGF,
1459 const RegionCodeGenTy &MasterOpGen,
1460 SourceLocation Loc) override;
1461
1462 /// \brief Emits code for a taskyield directive.
1463 void emitTaskyieldCall(CodeGenFunction &CGF, SourceLocation Loc) override;
1464
1465 /// \brief Emit a taskgroup region.
1466 /// \param TaskgroupOpGen Generator for the statement associated with the
1467 /// given taskgroup region.
1468 void emitTaskgroupRegion(CodeGenFunction &CGF,
1469 const RegionCodeGenTy &TaskgroupOpGen,
1470 SourceLocation Loc) override;
1471
1472 /// \brief Emits a single region.
1473 /// \param SingleOpGen Generator for the statement associated with the given
1474 /// single region.
1475 void emitSingleRegion(CodeGenFunction &CGF,
1476 const RegionCodeGenTy &SingleOpGen, SourceLocation Loc,
1477 ArrayRef<const Expr *> CopyprivateVars,
1478 ArrayRef<const Expr *> DestExprs,
1479 ArrayRef<const Expr *> SrcExprs,
1480 ArrayRef<const Expr *> AssignmentOps) override;
1481
1482 /// \brief Emit an ordered region.
1483 /// \param OrderedOpGen Generator for the statement associated with the given
1484 /// ordered region.
1485 void emitOrderedRegion(CodeGenFunction &CGF,
1486 const RegionCodeGenTy &OrderedOpGen,
1487 SourceLocation Loc, bool IsThreads) override;
1488
1489 /// \brief Emit an implicit/explicit barrier for OpenMP threads.
1490 /// \param Kind Directive for which this implicit barrier call must be
1491 /// generated. Must be OMPD_barrier for explicit barrier generation.
1492 /// \param EmitChecks true if need to emit checks for cancellation barriers.
1493 /// \param ForceSimpleCall true simple barrier call must be emitted, false if
1494 /// runtime class decides which one to emit (simple or with cancellation
1495 /// checks).
1496 ///
1497 void emitBarrierCall(CodeGenFunction &CGF, SourceLocation Loc,
1498 OpenMPDirectiveKind Kind, bool EmitChecks = true,
1499 bool ForceSimpleCall = false) override;
1500
1501 /// This is used for non static scheduled types and when the ordered
1502 /// clause is present on the loop construct.
1503 /// Depending on the loop schedule, it is necessary to call some runtime
1504 /// routine before start of the OpenMP loop to get the loop upper / lower
1505 /// bounds \a LB and \a UB and stride \a ST.
1506 ///
1507 /// \param CGF Reference to current CodeGenFunction.
1508 /// \param Loc Clang source location.
1509 /// \param ScheduleKind Schedule kind, specified by the 'schedule' clause.
1510 /// \param IVSize Size of the iteration variable in bits.
1511 /// \param IVSigned Sign of the iteration variable.
1512 /// \param Ordered true if loop is ordered, false otherwise.
1513 /// \param DispatchValues struct containing llvm values for lower bound, upper
1514 /// bound, and chunk expression.
1515 /// For the default (nullptr) value, the chunk 1 will be used.
1516 ///
1517 void emitForDispatchInit(CodeGenFunction &CGF, SourceLocation Loc,
1518 const OpenMPScheduleTy &ScheduleKind,
1519 unsigned IVSize, bool IVSigned, bool Ordered,
1520 const DispatchRTInput &DispatchValues) override;
1521
1522 /// \brief Call the appropriate runtime routine to initialize it before start
1523 /// of loop.
1524 ///
1525 /// This is used only in case of static schedule, when the user did not
1526 /// specify a ordered clause on the loop construct.
1527 /// Depending on the loop schedule, it is necessary to call some runtime
1528 /// routine before start of the OpenMP loop to get the loop upper / lower
1529 /// bounds LB and UB and stride ST.
1530 ///
1531 /// \param CGF Reference to current CodeGenFunction.
1532 /// \param Loc Clang source location.
1533 /// \param DKind Kind of the directive.
1534 /// \param ScheduleKind Schedule kind, specified by the 'schedule' clause.
1535 /// \param Values Input arguments for the construct.
1536 ///
1537 void emitForStaticInit(CodeGenFunction &CGF, SourceLocation Loc,
1538 OpenMPDirectiveKind DKind,
1539 const OpenMPScheduleTy &ScheduleKind,
1540 const StaticRTInput &Values) override;
1541
1542 ///
1543 /// \param CGF Reference to current CodeGenFunction.
1544 /// \param Loc Clang source location.
1545 /// \param SchedKind Schedule kind, specified by the 'dist_schedule' clause.
1546 /// \param Values Input arguments for the construct.
1547 ///
1548 void emitDistributeStaticInit(CodeGenFunction &CGF, SourceLocation Loc,
1549 OpenMPDistScheduleClauseKind SchedKind,
1550 const StaticRTInput &Values) override;
1551
1552 /// \brief Call the appropriate runtime routine to notify that we finished
1553 /// iteration of the ordered loop with the dynamic scheduling.
1554 ///
1555 /// \param CGF Reference to current CodeGenFunction.
1556 /// \param Loc Clang source location.
1557 /// \param IVSize Size of the iteration variable in bits.
1558 /// \param IVSigned Sign of the iteration variable.
1559 ///
1560 void emitForOrderedIterationEnd(CodeGenFunction &CGF, SourceLocation Loc,
1561 unsigned IVSize, bool IVSigned) override;
1562
1563 /// \brief Call the appropriate runtime routine to notify that we finished
1564 /// all the work with current loop.
1565 ///
1566 /// \param CGF Reference to current CodeGenFunction.
1567 /// \param Loc Clang source location.
1568 /// \param DKind Kind of the directive for which the static finish is emitted.
1569 ///
1570 void emitForStaticFinish(CodeGenFunction &CGF, SourceLocation Loc,
1571 OpenMPDirectiveKind DKind) override;
1572
1573 /// Call __kmpc_dispatch_next(
1574 /// ident_t *loc, kmp_int32 tid, kmp_int32 *p_lastiter,
1575 /// kmp_int[32|64] *p_lower, kmp_int[32|64] *p_upper,
1576 /// kmp_int[32|64] *p_stride);
1577 /// \param IVSize Size of the iteration variable in bits.
1578 /// \param IVSigned Sign of the iteration variable.
1579 /// \param IL Address of the output variable in which the flag of the
1580 /// last iteration is returned.
1581 /// \param LB Address of the output variable in which the lower iteration
1582 /// number is returned.
1583 /// \param UB Address of the output variable in which the upper iteration
1584 /// number is returned.
1585 /// \param ST Address of the output variable in which the stride value is
1586 /// returned.
1587 llvm::Value *emitForNext(CodeGenFunction &CGF, SourceLocation Loc,
1588 unsigned IVSize, bool IVSigned, Address IL,
1589 Address LB, Address UB, Address ST) override;
1590
1591 /// \brief Emits call to void __kmpc_push_num_threads(ident_t *loc, kmp_int32
1592 /// global_tid, kmp_int32 num_threads) to generate code for 'num_threads'
1593 /// clause.
1594 /// \param NumThreads An integer value of threads.
1595 void emitNumThreadsClause(CodeGenFunction &CGF, llvm::Value *NumThreads,
1596 SourceLocation Loc) override;
1597
1598 /// \brief Emit call to void __kmpc_push_proc_bind(ident_t *loc, kmp_int32
1599 /// global_tid, int proc_bind) to generate code for 'proc_bind' clause.
1600 void emitProcBindClause(CodeGenFunction &CGF,
1601 OpenMPProcBindClauseKind ProcBind,
1602 SourceLocation Loc) override;
1603
1604 /// \brief Returns address of the threadprivate variable for the current
1605 /// thread.
1606 /// \param VD Threadprivate variable.
1607 /// \param VDAddr Address of the global variable \a VD.
1608 /// \param Loc Location of the reference to threadprivate var.
1609 /// \return Address of the threadprivate variable for the current thread.
1610 Address getAddrOfThreadPrivate(CodeGenFunction &CGF, const VarDecl *VD,
1611 Address VDAddr, SourceLocation Loc) override;
1612
1613 /// \brief Emit a code for initialization of threadprivate variable. It emits
1614 /// a call to runtime library which adds initial value to the newly created
1615 /// threadprivate variable (if it is not constant) and registers destructor
1616 /// for the variable (if any).
1617 /// \param VD Threadprivate variable.
1618 /// \param VDAddr Address of the global variable \a VD.
1619 /// \param Loc Location of threadprivate declaration.
1620 /// \param PerformInit true if initialization expression is not constant.
1621 llvm::Function *
1622 emitThreadPrivateVarDefinition(const VarDecl *VD, Address VDAddr,
1623 SourceLocation Loc, bool PerformInit,
1624 CodeGenFunction *CGF = nullptr) override;
1625
1626 /// Creates artificial threadprivate variable with name \p Name and type \p
1627 /// VarType.
1628 /// \param VarType Type of the artificial threadprivate variable.
1629 /// \param Name Name of the artificial threadprivate variable.
1630 Address getAddrOfArtificialThreadPrivate(CodeGenFunction &CGF,
1631 QualType VarType,
1632 StringRef Name) override;
1633
1634 /// \brief Emit flush of the variables specified in 'omp flush' directive.
1635 /// \param Vars List of variables to flush.
1636 void emitFlush(CodeGenFunction &CGF, ArrayRef<const Expr *> Vars,
1637 SourceLocation Loc) override;
1638
1639 /// \brief Emit task region for the task directive. The task region is
1640 /// emitted in several steps:
1641 /// 1. Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32
1642 /// gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds,
1643 /// kmp_routine_entry_t *task_entry). Here task_entry is a pointer to the
1644 /// function:
1645 /// kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) {
1646 /// TaskFunction(gtid, tt->part_id, tt->shareds);
1647 /// return 0;
1648 /// }
1649 /// 2. Copy a list of shared variables to field shareds of the resulting
1650 /// structure kmp_task_t returned by the previous call (if any).
1651 /// 3. Copy a pointer to destructions function to field destructions of the
1652 /// resulting structure kmp_task_t.
1653 /// 4. Emit a call to kmp_int32 __kmpc_omp_task(ident_t *, kmp_int32 gtid,
1654 /// kmp_task_t *new_task), where new_task is a resulting structure from
1655 /// previous items.
1656 /// \param D Current task directive.
1657 /// \param TaskFunction An LLVM function with type void (*)(i32 /*gtid*/, i32
1658 /// /*part_id*/, captured_struct */*__context*/);
1659 /// \param SharedsTy A type which contains references the shared variables.
1660 /// \param Shareds Context with the list of shared variables from the \p
1661 /// TaskFunction.
1662 /// \param IfCond Not a nullptr if 'if' clause was specified, nullptr
1663 /// otherwise.
1664 /// \param Data Additional data for task generation like tiednsee, final
1665 /// state, list of privates etc.
1666 void emitTaskCall(CodeGenFunction &CGF, SourceLocation Loc,
1667 const OMPExecutableDirective &D, llvm::Value *TaskFunction,
1668 QualType SharedsTy, Address Shareds, const Expr *IfCond,
1669 const OMPTaskDataTy &Data) override;
1670
1671 /// Emit task region for the taskloop directive. The taskloop region is
1672 /// emitted in several steps:
1673 /// 1. Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32
1674 /// gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds,
1675 /// kmp_routine_entry_t *task_entry). Here task_entry is a pointer to the
1676 /// function:
1677 /// kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) {
1678 /// TaskFunction(gtid, tt->part_id, tt->shareds);
1679 /// return 0;
1680 /// }
1681 /// 2. Copy a list of shared variables to field shareds of the resulting
1682 /// structure kmp_task_t returned by the previous call (if any).
1683 /// 3. Copy a pointer to destructions function to field destructions of the
1684 /// resulting structure kmp_task_t.
1685 /// 4. Emit a call to void __kmpc_taskloop(ident_t *loc, int gtid, kmp_task_t
1686 /// *task, int if_val, kmp_uint64 *lb, kmp_uint64 *ub, kmp_int64 st, int
1687 /// nogroup, int sched, kmp_uint64 grainsize, void *task_dup ), where new_task
1688 /// is a resulting structure from
1689 /// previous items.
1690 /// \param D Current task directive.
1691 /// \param TaskFunction An LLVM function with type void (*)(i32 /*gtid*/, i32
1692 /// /*part_id*/, captured_struct */*__context*/);
1693 /// \param SharedsTy A type which contains references the shared variables.
1694 /// \param Shareds Context with the list of shared variables from the \p
1695 /// TaskFunction.
1696 /// \param IfCond Not a nullptr if 'if' clause was specified, nullptr
1697 /// otherwise.
1698 /// \param Data Additional data for task generation like tiednsee, final
1699 /// state, list of privates etc.
1700 void emitTaskLoopCall(CodeGenFunction &CGF, SourceLocation Loc,
1701 const OMPLoopDirective &D, llvm::Value *TaskFunction,
1702 QualType SharedsTy, Address Shareds, const Expr *IfCond,
1703 const OMPTaskDataTy &Data) override;
1704
1705 /// \brief Emit a code for reduction clause. Next code should be emitted for
1706 /// reduction:
1707 /// \code
1708 ///
1709 /// static kmp_critical_name lock = { 0 };
1710 ///
1711 /// void reduce_func(void *lhs[<n>], void *rhs[<n>]) {
1712 /// ...
1713 /// *(Type<i>*)lhs[i] = RedOp<i>(*(Type<i>*)lhs[i], *(Type<i>*)rhs[i]);
1714 /// ...
1715 /// }
1716 ///
1717 /// ...
1718 /// void *RedList[<n>] = {&<RHSExprs>[0], ..., &<RHSExprs>[<n>-1]};
1719 /// switch (__kmpc_reduce{_nowait}(<loc>, <gtid>, <n>, sizeof(RedList),
1720 /// RedList, reduce_func, &<lock>)) {
1721 /// case 1:
1722 /// ...
1723 /// <LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]);
1724 /// ...
1725 /// __kmpc_end_reduce{_nowait}(<loc>, <gtid>, &<lock>);
1726 /// break;
1727 /// case 2:
1728 /// ...
1729 /// Atomic(<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]));
1730 /// ...
1731 /// break;
1732 /// default:;
1733 /// }
1734 /// \endcode
1735 ///
1736 /// \param Privates List of private copies for original reduction arguments.
1737 /// \param LHSExprs List of LHS in \a ReductionOps reduction operations.
1738 /// \param RHSExprs List of RHS in \a ReductionOps reduction operations.
1739 /// \param ReductionOps List of reduction operations in form 'LHS binop RHS'
1740 /// or 'operator binop(LHS, RHS)'.
1741 /// \param Options List of options for reduction codegen:
1742 /// WithNowait true if parent directive has also nowait clause, false
1743 /// otherwise.
1744 /// SimpleReduction Emit reduction operation only. Used for omp simd
1745 /// directive on the host.
1746 /// ReductionKind The kind of reduction to perform.
1747 void emitReduction(CodeGenFunction &CGF, SourceLocation Loc,
1748 ArrayRef<const Expr *> Privates,
1749 ArrayRef<const Expr *> LHSExprs,
1750 ArrayRef<const Expr *> RHSExprs,
1751 ArrayRef<const Expr *> ReductionOps,
1752 ReductionOptionsTy Options) override;
1753
1754 /// Emit a code for initialization of task reduction clause. Next code
1755 /// should be emitted for reduction:
1756 /// \code
1757 ///
1758 /// _task_red_item_t red_data[n];
1759 /// ...
1760 /// red_data[i].shar = &origs[i];
1761 /// red_data[i].size = sizeof(origs[i]);
1762 /// red_data[i].f_init = (void*)RedInit<i>;
1763 /// red_data[i].f_fini = (void*)RedDest<i>;
1764 /// red_data[i].f_comb = (void*)RedOp<i>;
1765 /// red_data[i].flags = <Flag_i>;
1766 /// ...
1767 /// void* tg1 = __kmpc_task_reduction_init(gtid, n, red_data);
1768 /// \endcode
1769 ///
1770 /// \param LHSExprs List of LHS in \a Data.ReductionOps reduction operations.
1771 /// \param RHSExprs List of RHS in \a Data.ReductionOps reduction operations.
1772 /// \param Data Additional data for task generation like tiedness, final
1773 /// state, list of privates, reductions etc.
1774 llvm::Value *emitTaskReductionInit(CodeGenFunction &CGF, SourceLocation Loc,
1775 ArrayRef<const Expr *> LHSExprs,
1776 ArrayRef<const Expr *> RHSExprs,
1777 const OMPTaskDataTy &Data) override;
1778
1779 /// Required to resolve existing problems in the runtime. Emits threadprivate
1780 /// variables to store the size of the VLAs/array sections for
1781 /// initializer/combiner/finalizer functions + emits threadprivate variable to
1782 /// store the pointer to the original reduction item for the custom
1783 /// initializer defined by declare reduction construct.
1784 /// \param RCG Allows to reuse an existing data for the reductions.
1785 /// \param N Reduction item for which fixups must be emitted.
1786 void emitTaskReductionFixups(CodeGenFunction &CGF, SourceLocation Loc,
1787 ReductionCodeGen &RCG, unsigned N) override;
1788
1789 /// Get the address of `void *` type of the privatue copy of the reduction
1790 /// item specified by the \p SharedLVal.
1791 /// \param ReductionsPtr Pointer to the reduction data returned by the
1792 /// emitTaskReductionInit function.
1793 /// \param SharedLVal Address of the original reduction item.
1794 Address getTaskReductionItem(CodeGenFunction &CGF, SourceLocation Loc,
1795 llvm::Value *ReductionsPtr,
1796 LValue SharedLVal) override;
1797
1798 /// \brief Emit code for 'taskwait' directive.
1799 void emitTaskwaitCall(CodeGenFunction &CGF, SourceLocation Loc) override;
1800
1801 /// \brief Emit code for 'cancellation point' construct.
1802 /// \param CancelRegion Region kind for which the cancellation point must be
1803 /// emitted.
1804 ///
1805 void emitCancellationPointCall(CodeGenFunction &CGF, SourceLocation Loc,
1806 OpenMPDirectiveKind CancelRegion) override;
1807
1808 /// \brief Emit code for 'cancel' construct.
1809 /// \param IfCond Condition in the associated 'if' clause, if it was
1810 /// specified, nullptr otherwise.
1811 /// \param CancelRegion Region kind for which the cancel must be emitted.
1812 ///
1813 void emitCancelCall(CodeGenFunction &CGF, SourceLocation Loc,
1814 const Expr *IfCond,
1815 OpenMPDirectiveKind CancelRegion) override;
1816
1817 /// \brief Emit outilined function for 'target' directive.
1818 /// \param D Directive to emit.
1819 /// \param ParentName Name of the function that encloses the target region.
1820 /// \param OutlinedFn Outlined function value to be defined by this call.
1821 /// \param OutlinedFnID Outlined function ID value to be defined by this call.
1822 /// \param IsOffloadEntry True if the outlined function is an offload entry.
1823 /// \param CodeGen Code generation sequence for the \a D directive.
1824 /// An outlined function may not be an entry if, e.g. the if clause always
1825 /// evaluates to false.
1826 void emitTargetOutlinedFunction(const OMPExecutableDirective &D,
1827 StringRef ParentName,
1828 llvm::Function *&OutlinedFn,
1829 llvm::Constant *&OutlinedFnID,
1830 bool IsOffloadEntry,
1831 const RegionCodeGenTy &CodeGen) override;
1832
1833 /// \brief Emit the target offloading code associated with \a D. The emitted
1834 /// code attempts offloading the execution to the device, an the event of
1835 /// a failure it executes the host version outlined in \a OutlinedFn.
1836 /// \param D Directive to emit.
1837 /// \param OutlinedFn Host version of the code to be offloaded.
1838 /// \param OutlinedFnID ID of host version of the code to be offloaded.
1839 /// \param IfCond Expression evaluated in if clause associated with the target
1840 /// directive, or null if no if clause is used.
1841 /// \param Device Expression evaluated in device clause associated with the
1842 /// target directive, or null if no device clause is used.
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00001843 void emitTargetCall(CodeGenFunction &CGF, const OMPExecutableDirective &D,
1844 llvm::Value *OutlinedFn, llvm::Value *OutlinedFnID,
Alexey Bataev8451efa2018-01-15 19:06:12 +00001845 const Expr *IfCond, const Expr *Device) override;
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00001846
1847 /// \brief Emit the target regions enclosed in \a GD function definition or
1848 /// the function itself in case it is a valid device function. Returns true if
1849 /// \a GD was dealt with successfully.
1850 /// \param GD Function to scan.
1851 bool emitTargetFunctions(GlobalDecl GD) override;
1852
1853 /// \brief Emit the global variable if it is a valid device global variable.
1854 /// Returns true if \a GD was dealt with successfully.
1855 /// \param GD Variable declaration to emit.
1856 bool emitTargetGlobalVariable(GlobalDecl GD) override;
1857
1858 /// \brief Emit the global \a GD if it is meaningful for the target. Returns
1859 /// if it was emitted successfully.
1860 /// \param GD Global to scan.
1861 bool emitTargetGlobal(GlobalDecl GD) override;
1862
1863 /// \brief Creates the offloading descriptor in the event any target region
1864 /// was emitted in the current module and return the function that registers
1865 /// it.
1866 llvm::Function *emitRegistrationFunction() override;
1867
1868 /// \brief Emits code for teams call of the \a OutlinedFn with
1869 /// variables captured in a record which address is stored in \a
1870 /// CapturedStruct.
1871 /// \param OutlinedFn Outlined function to be run by team masters. Type of
1872 /// this function is void(*)(kmp_int32 *, kmp_int32, struct context_vars*).
1873 /// \param CapturedVars A pointer to the record with the references to
1874 /// variables used in \a OutlinedFn function.
1875 ///
1876 void emitTeamsCall(CodeGenFunction &CGF, const OMPExecutableDirective &D,
1877 SourceLocation Loc, llvm::Value *OutlinedFn,
1878 ArrayRef<llvm::Value *> CapturedVars) override;
1879
1880 /// \brief Emits call to void __kmpc_push_num_teams(ident_t *loc, kmp_int32
1881 /// global_tid, kmp_int32 num_teams, kmp_int32 thread_limit) to generate code
1882 /// for num_teams clause.
1883 /// \param NumTeams An integer expression of teams.
1884 /// \param ThreadLimit An integer expression of threads.
1885 void emitNumTeamsClause(CodeGenFunction &CGF, const Expr *NumTeams,
1886 const Expr *ThreadLimit, SourceLocation Loc) override;
1887
1888 /// \brief Emit the target data mapping code associated with \a D.
1889 /// \param D Directive to emit.
1890 /// \param IfCond Expression evaluated in if clause associated with the
1891 /// target directive, or null if no device clause is used.
1892 /// \param Device Expression evaluated in device clause associated with the
1893 /// target directive, or null if no device clause is used.
1894 /// \param Info A record used to store information that needs to be preserved
1895 /// until the region is closed.
1896 void emitTargetDataCalls(CodeGenFunction &CGF,
1897 const OMPExecutableDirective &D, const Expr *IfCond,
1898 const Expr *Device, const RegionCodeGenTy &CodeGen,
1899 TargetDataInfo &Info) override;
1900
1901 /// \brief Emit the data mapping/movement code associated with the directive
1902 /// \a D that should be of the form 'target [{enter|exit} data | update]'.
1903 /// \param D Directive to emit.
1904 /// \param IfCond Expression evaluated in if clause associated with the target
1905 /// directive, or null if no if clause is used.
1906 /// \param Device Expression evaluated in device clause associated with the
1907 /// target directive, or null if no device clause is used.
1908 void emitTargetDataStandAloneCall(CodeGenFunction &CGF,
1909 const OMPExecutableDirective &D,
1910 const Expr *IfCond,
1911 const Expr *Device) override;
1912
1913 /// Emit initialization for doacross loop nesting support.
1914 /// \param D Loop-based construct used in doacross nesting construct.
1915 void emitDoacrossInit(CodeGenFunction &CGF,
1916 const OMPLoopDirective &D) override;
1917
1918 /// Emit code for doacross ordered directive with 'depend' clause.
1919 /// \param C 'depend' clause with 'sink|source' dependency kind.
1920 void emitDoacrossOrdered(CodeGenFunction &CGF,
1921 const OMPDependClause *C) override;
1922
1923 /// Translates the native parameter of outlined function if this is required
1924 /// for target.
1925 /// \param FD Field decl from captured record for the paramater.
1926 /// \param NativeParam Parameter itself.
1927 const VarDecl *translateParameter(const FieldDecl *FD,
1928 const VarDecl *NativeParam) const override;
1929
1930 /// Gets the address of the native argument basing on the address of the
1931 /// target-specific parameter.
1932 /// \param NativeParam Parameter itself.
1933 /// \param TargetParam Corresponding target-specific parameter.
1934 Address getParameterAddress(CodeGenFunction &CGF, const VarDecl *NativeParam,
1935 const VarDecl *TargetParam) const override;
1936};
1937
Alexey Bataev23b69422014-06-18 07:08:49 +00001938} // namespace CodeGen
1939} // namespace clang
Alexey Bataev9959db52014-05-06 10:08:46 +00001940
1941#endif