blob: 1a27db157462a8de0aa5a9555d523771c71e1767 [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"
Alexey Bataev3a3bf0b2014-09-22 10:01:53 +000022#include "llvm/ADT/StringMap.h"
Alexey Bataev2a6f3f52018-11-07 19:11:14 +000023#include "llvm/ADT/StringSet.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
Alexander Kornienko2a8c18d2018-04-06 15:14:32 +0000136 /// Emits lvalue for shared expression.
Alexey Bataev5c40bec2017-07-13 13:36:14 +0000137 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 {
Alexey Bataev4f4bf7c2018-03-15 15:47:20 +0000202public:
203 /// Allows to disable automatic handling of functions used in target regions
204 /// as those marked as `omp declare target`.
205 class DisableAutoDeclareTargetRAII {
206 CodeGenModule &CGM;
207 bool SavedShouldMarkAsGlobal;
208
209 public:
210 DisableAutoDeclareTargetRAII(CodeGenModule &CGM);
211 ~DisableAutoDeclareTargetRAII();
212 };
213
Arpith Chacko Jacob5c309e42016-03-22 01:48:56 +0000214protected:
Alexey Bataev9959db52014-05-06 10:08:46 +0000215 CodeGenModule &CGM;
Alexey Bataev18fa2322018-05-02 14:20:50 +0000216 StringRef FirstSeparator, Separator;
217
218 /// Constructor allowing to redefine the name separator for the variables.
219 explicit CGOpenMPRuntime(CodeGenModule &CGM, StringRef FirstSeparator,
220 StringRef Separator);
Arpith Chacko Jacob5c309e42016-03-22 01:48:56 +0000221
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000222 /// Creates offloading entry for the provided entry ID \a ID,
Samuel Antaof83efdb2017-01-05 16:02:49 +0000223 /// address \a Addr, size \a Size, and flags \a Flags.
Arpith Chacko Jacob5c309e42016-03-22 01:48:56 +0000224 virtual void createOffloadEntry(llvm::Constant *ID, llvm::Constant *Addr,
Alexey Bataev03f270c2018-03-30 18:31:07 +0000225 uint64_t Size, int32_t Flags,
226 llvm::GlobalValue::LinkageTypes Linkage);
Arpith Chacko Jacob5c309e42016-03-22 01:48:56 +0000227
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000228 /// Helper to emit outlined function for 'target' directive.
Arpith Chacko Jacob5c309e42016-03-22 01:48:56 +0000229 /// \param D Directive to emit.
230 /// \param ParentName Name of the function that encloses the target region.
231 /// \param OutlinedFn Outlined function value to be defined by this call.
232 /// \param OutlinedFnID Outlined function ID value to be defined by this call.
233 /// \param IsOffloadEntry True if the outlined function is an offload entry.
234 /// \param CodeGen Lambda codegen specific to an accelerator device.
Simon Pilgrim6c0eeff2017-07-13 17:34:44 +0000235 /// An outlined function may not be an entry if, e.g. the if clause always
Arpith Chacko Jacob5c309e42016-03-22 01:48:56 +0000236 /// evaluates to false.
237 virtual void emitTargetOutlinedFunctionHelper(const OMPExecutableDirective &D,
238 StringRef ParentName,
239 llvm::Function *&OutlinedFn,
240 llvm::Constant *&OutlinedFnID,
241 bool IsOffloadEntry,
242 const RegionCodeGenTy &CodeGen);
243
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000244 /// Emits code for OpenMP 'if' clause using specified \a CodeGen
Arpith Chacko Jacobbb36fe82017-01-10 15:42:51 +0000245 /// function. Here is the logic:
246 /// if (Cond) {
247 /// ThenGen();
248 /// } else {
249 /// ElseGen();
250 /// }
251 void emitOMPIfClause(CodeGenFunction &CGF, const Expr *Cond,
252 const RegionCodeGenTy &ThenGen,
253 const RegionCodeGenTy &ElseGen);
254
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000255 /// Emits object of ident_t type with info for source location.
Arpith Chacko Jacobbb36fe82017-01-10 15:42:51 +0000256 /// \param Flags Flags for OpenMP location.
257 ///
258 llvm::Value *emitUpdateLocation(CodeGenFunction &CGF, SourceLocation Loc,
259 unsigned Flags = 0);
260
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000261 /// Returns pointer to ident_t type.
Arpith Chacko Jacobbb36fe82017-01-10 15:42:51 +0000262 llvm::Type *getIdentTyPointerTy();
263
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000264 /// Gets thread id value for the current thread.
Arpith Chacko Jacobbb36fe82017-01-10 15:42:51 +0000265 ///
266 llvm::Value *getThreadID(CodeGenFunction &CGF, SourceLocation Loc);
267
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000268 /// Get the function name of an outlined region.
Arpith Chacko Jacobbb36fe82017-01-10 15:42:51 +0000269 // The name can be customized depending on the target.
270 //
271 virtual StringRef getOutlinedHelperName() const { return ".omp_outlined."; }
272
Alexey Bataev3c595a62017-08-14 15:01:03 +0000273 /// Emits \p Callee function call with arguments \p Args with location \p Loc.
Alexey Bataev7ef47a62018-02-22 18:33:31 +0000274 void emitCall(CodeGenFunction &CGF, SourceLocation Loc, llvm::Value *Callee,
275 ArrayRef<llvm::Value *> Args = llvm::None) const;
Alexey Bataev3c595a62017-08-14 15:01:03 +0000276
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000277 /// Emits address of the word in a memory where current thread id is
Alexey Bataevb7f3cba2018-03-19 17:04:07 +0000278 /// stored.
279 virtual Address emitThreadIDAddress(CodeGenFunction &CGF, SourceLocation Loc);
280
Alexey Bataevfd006c42018-10-05 15:08:53 +0000281 void setLocThreadIdInsertPt(CodeGenFunction &CGF,
282 bool AtCurrentPoint = false);
283 void clearLocThreadIdInsertPt(CodeGenFunction &CGF);
284
Arpith Chacko Jacob5c309e42016-03-22 01:48:56 +0000285private:
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000286 /// Default const ident_t object used for initialization of all other
Alexey Bataev9959db52014-05-06 10:08:46 +0000287 /// ident_t objects.
Alexey Bataevc5b1d322016-03-04 09:22:22 +0000288 llvm::Constant *DefaultOpenMPPSource = nullptr;
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000289 /// Map of flags and corresponding default locations.
Alexey Bataev15007ba2014-05-07 06:18:01 +0000290 typedef llvm::DenseMap<unsigned, llvm::Value *> OpenMPDefaultLocMapTy;
291 OpenMPDefaultLocMapTy OpenMPDefaultLocMap;
Alexey Bataev50b3c952016-02-19 10:38:26 +0000292 Address getOrCreateDefaultLocation(unsigned Flags);
John McCall7f416cc2015-09-08 08:05:57 +0000293
Alexey Bataeva4fa0b82018-04-16 17:59:34 +0000294 QualType IdentQTy;
Alexey Bataev14fa1c62016-03-29 05:34:15 +0000295 llvm::StructType *IdentTy = nullptr;
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000296 /// Map for SourceLocation and OpenMP runtime library debug locations.
Alexey Bataevf002aca2014-05-30 05:48:40 +0000297 typedef llvm::DenseMap<unsigned, llvm::Value *> OpenMPDebugLocMapTy;
298 OpenMPDebugLocMapTy OpenMPDebugLocMap;
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000299 /// The type for a microtask which gets passed to __kmpc_fork_call().
Alexey Bataev9959db52014-05-06 10:08:46 +0000300 /// Original representation is:
301 /// typedef void (kmpc_micro)(kmp_int32 global_tid, kmp_int32 bound_tid,...);
Alexey Bataev14fa1c62016-03-29 05:34:15 +0000302 llvm::FunctionType *Kmpc_MicroTy = nullptr;
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000303 /// Stores debug location and ThreadID for the function.
Alexey Bataev18095712014-10-10 12:19:54 +0000304 struct DebugLocThreadIdTy {
305 llvm::Value *DebugLoc;
306 llvm::Value *ThreadID;
Alexey Bataevfd006c42018-10-05 15:08:53 +0000307 /// Insert point for the service instructions.
308 llvm::AssertingVH<llvm::Instruction> ServiceInsertPt = nullptr;
Alexey Bataev18095712014-10-10 12:19:54 +0000309 };
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000310 /// Map of local debug location, ThreadId and functions.
Alexey Bataev18095712014-10-10 12:19:54 +0000311 typedef llvm::DenseMap<llvm::Function *, DebugLocThreadIdTy>
312 OpenMPLocThreadIDMapTy;
313 OpenMPLocThreadIDMapTy OpenMPLocThreadIDMap;
Alexey Bataevc5b1d322016-03-04 09:22:22 +0000314 /// Map of UDRs and corresponding combiner/initializer.
315 typedef llvm::DenseMap<const OMPDeclareReductionDecl *,
316 std::pair<llvm::Function *, llvm::Function *>>
317 UDRMapTy;
318 UDRMapTy UDRMap;
319 /// Map of functions and locally defined UDRs.
320 typedef llvm::DenseMap<llvm::Function *,
321 SmallVector<const OMPDeclareReductionDecl *, 4>>
322 FunctionUDRMapTy;
323 FunctionUDRMapTy FunctionUDRMap;
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000324 /// Type kmp_critical_name, originally defined as typedef kmp_int32
Alexey Bataev3a3bf0b2014-09-22 10:01:53 +0000325 /// kmp_critical_name[8];
326 llvm::ArrayType *KmpCriticalNameTy;
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000327 /// An ordered map of auto-generated variables to their unique names.
Alexey Bataev97720002014-11-11 04:05:39 +0000328 /// It stores variables with the following names: 1) ".gomp_critical_user_" +
329 /// <critical_section_name> + ".var" for "omp critical" directives; 2)
330 /// <mangled_name_for_global_var> + ".cache." for cache for threadprivate
331 /// variables.
332 llvm::StringMap<llvm::AssertingVH<llvm::Constant>, llvm::BumpPtrAllocator>
333 InternalVars;
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000334 /// Type typedef kmp_int32 (* kmp_routine_entry_t)(kmp_int32, void *);
Alexey Bataevc5b1d322016-03-04 09:22:22 +0000335 llvm::Type *KmpRoutineEntryPtrTy = nullptr;
Alexey Bataev62b63b12015-03-10 07:28:44 +0000336 QualType KmpRoutineEntryPtrQTy;
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000337 /// Type typedef struct kmp_task {
Alexey Bataev8fc69dc2015-05-18 07:54:53 +0000338 /// void * shareds; /**< pointer to block of pointers to
339 /// shared vars */
340 /// kmp_routine_entry_t routine; /**< pointer to routine to call for
341 /// executing task */
342 /// kmp_int32 part_id; /**< part id for the task */
343 /// kmp_routine_entry_t destructors; /* pointer to function to invoke
344 /// deconstructors of firstprivate C++ objects */
345 /// } kmp_task_t;
346 QualType KmpTaskTQTy;
Alexey Bataeve213f3e2017-10-11 15:29:40 +0000347 /// Saved kmp_task_t for task directive.
348 QualType SavedKmpTaskTQTy;
349 /// Saved kmp_task_t for taskloop-based directive.
350 QualType SavedKmpTaskloopTQTy;
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000351 /// Type typedef struct kmp_depend_info {
Alexey Bataev1d2353d2015-06-24 11:01:36 +0000352 /// kmp_intptr_t base_addr;
353 /// size_t len;
354 /// struct {
355 /// bool in:1;
356 /// bool out:1;
357 /// } flags;
358 /// } kmp_depend_info_t;
359 QualType KmpDependInfoTy;
Alexey Bataev8b427062016-05-25 12:36:08 +0000360 /// struct kmp_dim { // loop bounds info casted to kmp_int64
361 /// kmp_int64 lo; // lower
362 /// kmp_int64 up; // upper
363 /// kmp_int64 st; // stride
364 /// };
365 QualType KmpDimTy;
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000366 /// Type struct __tgt_offload_entry{
Samuel Antaoee8fb302016-01-06 13:42:12 +0000367 /// void *addr; // Pointer to the offload entry info.
368 /// // (function or global)
369 /// char *name; // Name of the function or global.
370 /// size_t size; // Size of the entry info (0 if it a function).
371 /// };
372 QualType TgtOffloadEntryQTy;
373 /// struct __tgt_device_image{
374 /// void *ImageStart; // Pointer to the target code start.
375 /// void *ImageEnd; // Pointer to the target code end.
376 /// // We also add the host entries to the device image, as it may be useful
377 /// // for the target runtime to have access to that information.
378 /// __tgt_offload_entry *EntriesBegin; // Begin of the table with all
379 /// // the entries.
380 /// __tgt_offload_entry *EntriesEnd; // End of the table with all the
381 /// // entries (non inclusive).
382 /// };
383 QualType TgtDeviceImageQTy;
384 /// struct __tgt_bin_desc{
385 /// int32_t NumDevices; // Number of devices supported.
386 /// __tgt_device_image *DeviceImages; // Arrays of device images
387 /// // (one per device).
388 /// __tgt_offload_entry *EntriesBegin; // Begin of the table with all the
389 /// // entries.
390 /// __tgt_offload_entry *EntriesEnd; // End of the table with all the
391 /// // entries (non inclusive).
392 /// };
393 QualType TgtBinaryDescriptorQTy;
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000394 /// Entity that registers the offloading constants that were emitted so
Samuel Antaoee8fb302016-01-06 13:42:12 +0000395 /// far.
396 class OffloadEntriesInfoManagerTy {
397 CodeGenModule &CGM;
Alexey Bataev1d2353d2015-06-24 11:01:36 +0000398
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000399 /// Number of entries registered so far.
Alexey Bataev03f270c2018-03-30 18:31:07 +0000400 unsigned OffloadingEntriesNum = 0;
Samuel Antaoee8fb302016-01-06 13:42:12 +0000401
402 public:
Samuel Antaof83efdb2017-01-05 16:02:49 +0000403 /// Base class of the entries info.
Samuel Antaoee8fb302016-01-06 13:42:12 +0000404 class OffloadEntryInfo {
405 public:
Alexey Bataev34f8a702018-03-28 14:28:54 +0000406 /// Kind of a given entry.
Reid Klecknerdc78f952016-01-11 20:55:16 +0000407 enum OffloadingEntryInfoKinds : unsigned {
Alexey Bataev34f8a702018-03-28 14:28:54 +0000408 /// Entry is a target region.
409 OffloadingEntryInfoTargetRegion = 0,
Alexey Bataev03f270c2018-03-30 18:31:07 +0000410 /// Entry is a declare target variable.
411 OffloadingEntryInfoDeviceGlobalVar = 1,
Alexey Bataev34f8a702018-03-28 14:28:54 +0000412 /// Invalid entry info.
413 OffloadingEntryInfoInvalid = ~0u
Samuel Antaoee8fb302016-01-06 13:42:12 +0000414 };
415
Alexey Bataev03f270c2018-03-30 18:31:07 +0000416 protected:
417 OffloadEntryInfo() = delete;
418 explicit OffloadEntryInfo(OffloadingEntryInfoKinds Kind) : Kind(Kind) {}
Samuel Antaof83efdb2017-01-05 16:02:49 +0000419 explicit OffloadEntryInfo(OffloadingEntryInfoKinds Kind, unsigned Order,
Alexey Bataev03f270c2018-03-30 18:31:07 +0000420 uint32_t Flags)
Samuel Antaof83efdb2017-01-05 16:02:49 +0000421 : Flags(Flags), Order(Order), Kind(Kind) {}
Alexey Bataev03f270c2018-03-30 18:31:07 +0000422 ~OffloadEntryInfo() = default;
Samuel Antaoee8fb302016-01-06 13:42:12 +0000423
Alexey Bataev03f270c2018-03-30 18:31:07 +0000424 public:
Samuel Antaoee8fb302016-01-06 13:42:12 +0000425 bool isValid() const { return Order != ~0u; }
426 unsigned getOrder() const { return Order; }
427 OffloadingEntryInfoKinds getKind() const { return Kind; }
Alexey Bataev03f270c2018-03-30 18:31:07 +0000428 uint32_t getFlags() const { return Flags; }
429 void setFlags(uint32_t NewFlags) { Flags = NewFlags; }
430 llvm::Constant *getAddress() const {
431 return cast_or_null<llvm::Constant>(Addr);
432 }
433 void setAddress(llvm::Constant *V) {
434 assert(!Addr.pointsToAliveValue() && "Address has been set before!");
435 Addr = V;
436 }
Samuel Antaoee8fb302016-01-06 13:42:12 +0000437 static bool classof(const OffloadEntryInfo *Info) { return true; }
438
Samuel Antaof83efdb2017-01-05 16:02:49 +0000439 private:
Alexey Bataev03f270c2018-03-30 18:31:07 +0000440 /// Address of the entity that has to be mapped for offloading.
441 llvm::WeakTrackingVH Addr;
442
Samuel Antaof83efdb2017-01-05 16:02:49 +0000443 /// Flags associated with the device global.
Alexey Bataev03f270c2018-03-30 18:31:07 +0000444 uint32_t Flags = 0u;
Samuel Antaof83efdb2017-01-05 16:02:49 +0000445
446 /// Order this entry was emitted.
Alexey Bataev03f270c2018-03-30 18:31:07 +0000447 unsigned Order = ~0u;
Samuel Antaoee8fb302016-01-06 13:42:12 +0000448
Alexey Bataev03f270c2018-03-30 18:31:07 +0000449 OffloadingEntryInfoKinds Kind = OffloadingEntryInfoInvalid;
Samuel Antaoee8fb302016-01-06 13:42:12 +0000450 };
451
Alexey Bataev03f270c2018-03-30 18:31:07 +0000452 /// Return true if a there are no entries defined.
Samuel Antaoee8fb302016-01-06 13:42:12 +0000453 bool empty() const;
Alexey Bataev03f270c2018-03-30 18:31:07 +0000454 /// Return number of entries defined so far.
Samuel Antaoee8fb302016-01-06 13:42:12 +0000455 unsigned size() const { return OffloadingEntriesNum; }
Alexey Bataev03f270c2018-03-30 18:31:07 +0000456 OffloadEntriesInfoManagerTy(CodeGenModule &CGM) : CGM(CGM) {}
Samuel Antaoee8fb302016-01-06 13:42:12 +0000457
Alexey Bataev03f270c2018-03-30 18:31:07 +0000458 //
459 // Target region entries related.
460 //
461
462 /// Kind of the target registry entry.
463 enum OMPTargetRegionEntryKind : uint32_t {
464 /// Mark the entry as target region.
465 OMPTargetRegionEntryTargetRegion = 0x0,
466 /// Mark the entry as a global constructor.
467 OMPTargetRegionEntryCtor = 0x02,
468 /// Mark the entry as a global destructor.
469 OMPTargetRegionEntryDtor = 0x04,
470 };
471
472 /// Target region entries info.
473 class OffloadEntryInfoTargetRegion final : public OffloadEntryInfo {
474 /// Address that can be used as the ID of the entry.
475 llvm::Constant *ID = nullptr;
Samuel Antaoee8fb302016-01-06 13:42:12 +0000476
477 public:
478 OffloadEntryInfoTargetRegion()
Alexey Bataev03f270c2018-03-30 18:31:07 +0000479 : OffloadEntryInfo(OffloadingEntryInfoTargetRegion) {}
Samuel Antaoee8fb302016-01-06 13:42:12 +0000480 explicit OffloadEntryInfoTargetRegion(unsigned Order,
481 llvm::Constant *Addr,
Alexey Bataev34f8a702018-03-28 14:28:54 +0000482 llvm::Constant *ID,
483 OMPTargetRegionEntryKind Flags)
484 : OffloadEntryInfo(OffloadingEntryInfoTargetRegion, Order, Flags),
Alexey Bataev03f270c2018-03-30 18:31:07 +0000485 ID(ID) {
486 setAddress(Addr);
Samuel Antaoee8fb302016-01-06 13:42:12 +0000487 }
Alexey Bataev03f270c2018-03-30 18:31:07 +0000488
489 llvm::Constant *getID() const { return ID; }
Samuel Antaoee8fb302016-01-06 13:42:12 +0000490 void setID(llvm::Constant *V) {
Alexey Bataev34f8a702018-03-28 14:28:54 +0000491 assert(!ID && "ID has been set before!");
Samuel Antaoee8fb302016-01-06 13:42:12 +0000492 ID = V;
493 }
494 static bool classof(const OffloadEntryInfo *Info) {
Alexey Bataev34f8a702018-03-28 14:28:54 +0000495 return Info->getKind() == OffloadingEntryInfoTargetRegion;
Samuel Antaoee8fb302016-01-06 13:42:12 +0000496 }
497 };
Alexey Bataev03f270c2018-03-30 18:31:07 +0000498
499 /// Initialize target region entry.
Samuel Antaoee8fb302016-01-06 13:42:12 +0000500 void initializeTargetRegionEntryInfo(unsigned DeviceID, unsigned FileID,
501 StringRef ParentName, unsigned LineNum,
Samuel Antao2de62b02016-02-13 23:35:10 +0000502 unsigned Order);
Alexey Bataev03f270c2018-03-30 18:31:07 +0000503 /// Register target region entry.
Samuel Antaoee8fb302016-01-06 13:42:12 +0000504 void registerTargetRegionEntryInfo(unsigned DeviceID, unsigned FileID,
505 StringRef ParentName, unsigned LineNum,
Samuel Antaof83efdb2017-01-05 16:02:49 +0000506 llvm::Constant *Addr, llvm::Constant *ID,
Alexey Bataev34f8a702018-03-28 14:28:54 +0000507 OMPTargetRegionEntryKind Flags);
Alexey Bataev03f270c2018-03-30 18:31:07 +0000508 /// Return true if a target region entry with the provided information
509 /// exists.
Samuel Antaoee8fb302016-01-06 13:42:12 +0000510 bool hasTargetRegionEntryInfo(unsigned DeviceID, unsigned FileID,
Samuel Antao2de62b02016-02-13 23:35:10 +0000511 StringRef ParentName, unsigned LineNum) const;
Samuel Antaoee8fb302016-01-06 13:42:12 +0000512 /// brief Applies action \a Action on all registered entries.
513 typedef llvm::function_ref<void(unsigned, unsigned, StringRef, unsigned,
Alexey Bataev03f270c2018-03-30 18:31:07 +0000514 const OffloadEntryInfoTargetRegion &)>
Samuel Antaoee8fb302016-01-06 13:42:12 +0000515 OffloadTargetRegionEntryInfoActTy;
516 void actOnTargetRegionEntriesInfo(
517 const OffloadTargetRegionEntryInfoActTy &Action);
518
Alexey Bataev03f270c2018-03-30 18:31:07 +0000519 //
520 // Device global variable entries related.
521 //
522
523 /// Kind of the global variable entry..
524 enum OMPTargetGlobalVarEntryKind : uint32_t {
525 /// Mark the entry as a to declare target.
526 OMPTargetGlobalVarEntryTo = 0x0,
Alexey Bataevc52f01d2018-07-16 20:05:25 +0000527 /// Mark the entry as a to declare target link.
528 OMPTargetGlobalVarEntryLink = 0x1,
Alexey Bataev03f270c2018-03-30 18:31:07 +0000529 };
530
531 /// Device global variable entries info.
532 class OffloadEntryInfoDeviceGlobalVar final : public OffloadEntryInfo {
533 /// Type of the global variable.
534 CharUnits VarSize;
535 llvm::GlobalValue::LinkageTypes Linkage;
536
537 public:
538 OffloadEntryInfoDeviceGlobalVar()
539 : OffloadEntryInfo(OffloadingEntryInfoDeviceGlobalVar) {}
540 explicit OffloadEntryInfoDeviceGlobalVar(unsigned Order,
541 OMPTargetGlobalVarEntryKind Flags)
542 : OffloadEntryInfo(OffloadingEntryInfoDeviceGlobalVar, Order, Flags) {}
543 explicit OffloadEntryInfoDeviceGlobalVar(
544 unsigned Order, llvm::Constant *Addr, CharUnits VarSize,
545 OMPTargetGlobalVarEntryKind Flags,
546 llvm::GlobalValue::LinkageTypes Linkage)
547 : OffloadEntryInfo(OffloadingEntryInfoDeviceGlobalVar, Order, Flags),
548 VarSize(VarSize), Linkage(Linkage) {
549 setAddress(Addr);
550 }
551
552 CharUnits getVarSize() const { return VarSize; }
553 void setVarSize(CharUnits Size) { VarSize = Size; }
554 llvm::GlobalValue::LinkageTypes getLinkage() const { return Linkage; }
555 void setLinkage(llvm::GlobalValue::LinkageTypes LT) { Linkage = LT; }
556 static bool classof(const OffloadEntryInfo *Info) {
557 return Info->getKind() == OffloadingEntryInfoDeviceGlobalVar;
558 }
559 };
560
561 /// Initialize device global variable entry.
562 void initializeDeviceGlobalVarEntryInfo(StringRef Name,
563 OMPTargetGlobalVarEntryKind Flags,
564 unsigned Order);
565
566 /// Register device global variable entry.
567 void
568 registerDeviceGlobalVarEntryInfo(StringRef VarName, llvm::Constant *Addr,
569 CharUnits VarSize,
570 OMPTargetGlobalVarEntryKind Flags,
571 llvm::GlobalValue::LinkageTypes Linkage);
572 /// Checks if the variable with the given name has been registered already.
573 bool hasDeviceGlobalVarEntryInfo(StringRef VarName) const {
574 return OffloadEntriesDeviceGlobalVar.count(VarName) > 0;
575 }
576 /// Applies action \a Action on all registered entries.
577 typedef llvm::function_ref<void(StringRef,
578 const OffloadEntryInfoDeviceGlobalVar &)>
579 OffloadDeviceGlobalVarEntryInfoActTy;
580 void actOnDeviceGlobalVarEntriesInfo(
581 const OffloadDeviceGlobalVarEntryInfoActTy &Action);
582
Samuel Antaoee8fb302016-01-06 13:42:12 +0000583 private:
584 // Storage for target region entries kind. The storage is to be indexed by
Samuel Antao2de62b02016-02-13 23:35:10 +0000585 // file ID, device ID, parent function name and line number.
Samuel Antaoee8fb302016-01-06 13:42:12 +0000586 typedef llvm::DenseMap<unsigned, OffloadEntryInfoTargetRegion>
Samuel Antaoee8fb302016-01-06 13:42:12 +0000587 OffloadEntriesTargetRegionPerLine;
588 typedef llvm::StringMap<OffloadEntriesTargetRegionPerLine>
589 OffloadEntriesTargetRegionPerParentName;
590 typedef llvm::DenseMap<unsigned, OffloadEntriesTargetRegionPerParentName>
591 OffloadEntriesTargetRegionPerFile;
592 typedef llvm::DenseMap<unsigned, OffloadEntriesTargetRegionPerFile>
593 OffloadEntriesTargetRegionPerDevice;
594 typedef OffloadEntriesTargetRegionPerDevice OffloadEntriesTargetRegionTy;
595 OffloadEntriesTargetRegionTy OffloadEntriesTargetRegion;
Alexey Bataev03f270c2018-03-30 18:31:07 +0000596 /// Storage for device global variable entries kind. The storage is to be
597 /// indexed by mangled name.
598 typedef llvm::StringMap<OffloadEntryInfoDeviceGlobalVar>
599 OffloadEntriesDeviceGlobalVarTy;
600 OffloadEntriesDeviceGlobalVarTy OffloadEntriesDeviceGlobalVar;
Samuel Antaoee8fb302016-01-06 13:42:12 +0000601 };
602 OffloadEntriesInfoManagerTy OffloadEntriesInfoManager;
603
Alexey Bataev4f4bf7c2018-03-15 15:47:20 +0000604 bool ShouldMarkAsGlobal = true;
Alexey Bataev2a6f3f52018-11-07 19:11:14 +0000605 /// List of the emitted functions.
606 llvm::StringSet<> AlreadyEmittedTargetFunctions;
607 /// List of the global variables with their addresses that should not be
608 /// emitted for the target.
609 llvm::StringMap<llvm::WeakTrackingVH> EmittedNonTargetVariables;
Alexey Bataev4f4bf7c2018-03-15 15:47:20 +0000610
Alexey Bataevbf8fe712018-08-07 16:14:36 +0000611 /// List of variables that can become declare target implicitly and, thus,
612 /// must be emitted.
613 llvm::SmallDenseSet<const VarDecl *> DeferredGlobalVariables;
614
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000615 /// Creates and registers offloading binary descriptor for the current
Samuel Antaoee8fb302016-01-06 13:42:12 +0000616 /// compilation unit. The function that does the registration is returned.
617 llvm::Function *createOffloadingBinaryDescriptorRegistration();
618
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000619 /// Creates all the offload entries in the current compilation unit
Samuel Antaoee8fb302016-01-06 13:42:12 +0000620 /// along with the associated metadata.
621 void createOffloadEntriesAndInfoMetadata();
622
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000623 /// Loads all the offload entries information from the host IR
Samuel Antaoee8fb302016-01-06 13:42:12 +0000624 /// metadata.
625 void loadOffloadInfoMetadata();
626
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000627 /// Returns __tgt_offload_entry type.
Samuel Antaoee8fb302016-01-06 13:42:12 +0000628 QualType getTgtOffloadEntryQTy();
629
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000630 /// Returns __tgt_device_image type.
Samuel Antaoee8fb302016-01-06 13:42:12 +0000631 QualType getTgtDeviceImageQTy();
632
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000633 /// Returns __tgt_bin_desc type.
Samuel Antaoee8fb302016-01-06 13:42:12 +0000634 QualType getTgtBinaryDescriptorQTy();
635
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000636 /// Start scanning from statement \a S and and emit all target regions
Samuel Antaoee8fb302016-01-06 13:42:12 +0000637 /// found along the way.
638 /// \param S Starting statement.
639 /// \param ParentName Name of the function declaration that is being scanned.
640 void scanForTargetRegionsFunctions(const Stmt *S, StringRef ParentName);
Alexey Bataev62b63b12015-03-10 07:28:44 +0000641
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000642 /// Build type kmp_routine_entry_t (if not built yet).
Alexey Bataev62b63b12015-03-10 07:28:44 +0000643 void emitKmpRoutineEntryT(QualType KmpInt32Ty);
Alexey Bataev9959db52014-05-06 10:08:46 +0000644
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000645 /// Returns pointer to kmpc_micro type.
Alexey Bataev9959db52014-05-06 10:08:46 +0000646 llvm::Type *getKmpc_MicroPointerTy();
647
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000648 /// Returns specified OpenMP runtime function.
Alexey Bataev9959db52014-05-06 10:08:46 +0000649 /// \param Function OpenMP runtime function.
650 /// \return Specified function.
Alexey Bataev50b3c952016-02-19 10:38:26 +0000651 llvm::Constant *createRuntimeFunction(unsigned Function);
Alexey Bataev3a3bf0b2014-09-22 10:01:53 +0000652
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000653 /// Returns __kmpc_for_static_init_* runtime function for the specified
Alexander Musman21212e42015-03-13 10:38:23 +0000654 /// size \a IVSize and sign \a IVSigned.
655 llvm::Constant *createForStaticInitFunction(unsigned IVSize, bool IVSigned);
656
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000657 /// Returns __kmpc_dispatch_init_* runtime function for the specified
Alexander Musman92bdaab2015-03-12 13:37:50 +0000658 /// size \a IVSize and sign \a IVSigned.
659 llvm::Constant *createDispatchInitFunction(unsigned IVSize, bool IVSigned);
660
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000661 /// Returns __kmpc_dispatch_next_* runtime function for the specified
Alexander Musman92bdaab2015-03-12 13:37:50 +0000662 /// size \a IVSize and sign \a IVSigned.
663 llvm::Constant *createDispatchNextFunction(unsigned IVSize, bool IVSigned);
664
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000665 /// Returns __kmpc_dispatch_fini_* runtime function for the specified
Alexey Bataev98eb6e32015-04-22 11:15:40 +0000666 /// size \a IVSize and sign \a IVSigned.
667 llvm::Constant *createDispatchFiniFunction(unsigned IVSize, bool IVSigned);
668
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000669 /// If the specified mangled name is not in the module, create and
Alexey Bataev97720002014-11-11 04:05:39 +0000670 /// return threadprivate cache object. This object is a pointer's worth of
671 /// storage that's reserved for use by the OpenMP runtime.
NAKAMURA Takumicdcbfba2014-11-11 07:58:06 +0000672 /// \param VD Threadprivate variable.
Alexey Bataev97720002014-11-11 04:05:39 +0000673 /// \return Cache variable for the specified threadprivate.
674 llvm::Constant *getOrCreateThreadPrivateCache(const VarDecl *VD);
675
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000676 /// Gets (if variable with the given name already exist) or creates
Alexey Bataev97720002014-11-11 04:05:39 +0000677 /// internal global variable with the specified Name. The created variable has
678 /// linkage CommonLinkage by default and is initialized by null value.
679 /// \param Ty Type of the global variable. If it is exist already the type
680 /// must be the same.
681 /// \param Name Name of the variable.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000682 llvm::Constant *getOrCreateInternalVariable(llvm::Type *Ty,
Alexey Bataev97720002014-11-11 04:05:39 +0000683 const llvm::Twine &Name);
684
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000685 /// Set of threadprivate variables with the generated initializer.
Alexey Bataev2a6f3f52018-11-07 19:11:14 +0000686 llvm::StringSet<> ThreadPrivateWithDefinition;
Alexey Bataev97720002014-11-11 04:05:39 +0000687
Alexey Bataev34f8a702018-03-28 14:28:54 +0000688 /// Set of declare target variables with the generated initializer.
Alexey Bataev2a6f3f52018-11-07 19:11:14 +0000689 llvm::StringSet<> DeclareTargetWithDefinition;
Alexey Bataev34f8a702018-03-28 14:28:54 +0000690
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000691 /// Emits initialization code for the threadprivate variables.
Alexey Bataev97720002014-11-11 04:05:39 +0000692 /// \param VDAddr Address of the global variable \a VD.
693 /// \param Ctor Pointer to a global init function for \a VD.
694 /// \param CopyCtor Pointer to a global copy function for \a VD.
695 /// \param Dtor Pointer to a global destructor function for \a VD.
696 /// \param Loc Location of threadprivate declaration.
John McCall7f416cc2015-09-08 08:05:57 +0000697 void emitThreadPrivateVarInit(CodeGenFunction &CGF, Address VDAddr,
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000698 llvm::Value *Ctor, llvm::Value *CopyCtor,
699 llvm::Value *Dtor, SourceLocation Loc);
Alexey Bataev97720002014-11-11 04:05:39 +0000700
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000701 /// Returns corresponding lock object for the specified critical region
Alexey Bataev75ddfab2014-12-01 11:32:38 +0000702 /// name. If the lock object does not exist it is created, otherwise the
703 /// reference to the existing copy is returned.
704 /// \param CriticalName Name of the critical region.
705 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000706 llvm::Value *getCriticalRegionLock(StringRef CriticalName);
Alexey Bataev75ddfab2014-12-01 11:32:38 +0000707
Alexey Bataev24b5bae2016-04-28 09:23:51 +0000708 struct TaskResultTy {
709 llvm::Value *NewTask = nullptr;
710 llvm::Value *TaskEntry = nullptr;
711 llvm::Value *NewTaskNewTaskTTy = nullptr;
Alexey Bataev7292c292016-04-25 12:22:29 +0000712 LValue TDBase;
Alexey Bataeva4fa0b82018-04-16 17:59:34 +0000713 const RecordDecl *KmpTaskTQTyRD = nullptr;
Alexey Bataevf93095a2016-05-05 08:46:22 +0000714 llvm::Value *TaskDupFn = nullptr;
Alexey Bataev7292c292016-04-25 12:22:29 +0000715 };
716 /// Emit task region for the task directive. The task region is emitted in
717 /// several steps:
718 /// 1. Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32
719 /// gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds,
720 /// kmp_routine_entry_t *task_entry). Here task_entry is a pointer to the
721 /// function:
722 /// kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) {
723 /// TaskFunction(gtid, tt->part_id, tt->shareds);
724 /// return 0;
725 /// }
726 /// 2. Copy a list of shared variables to field shareds of the resulting
727 /// structure kmp_task_t returned by the previous call (if any).
728 /// 3. Copy a pointer to destructions function to field destructions of the
729 /// resulting structure kmp_task_t.
730 /// \param D Current task directive.
Alexey Bataev7292c292016-04-25 12:22:29 +0000731 /// \param TaskFunction An LLVM function with type void (*)(i32 /*gtid*/, i32
732 /// /*part_id*/, captured_struct */*__context*/);
733 /// \param SharedsTy A type which contains references the shared variables.
734 /// \param Shareds Context with the list of shared variables from the \p
735 /// TaskFunction.
Alexey Bataev24b5bae2016-04-28 09:23:51 +0000736 /// \param Data Additional data for task generation like tiednsee, final
737 /// state, list of privates etc.
738 TaskResultTy emitTaskInit(CodeGenFunction &CGF, SourceLocation Loc,
739 const OMPExecutableDirective &D,
740 llvm::Value *TaskFunction, QualType SharedsTy,
741 Address Shareds, const OMPTaskDataTy &Data);
Alexey Bataev7292c292016-04-25 12:22:29 +0000742
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000743public:
Alexey Bataev18fa2322018-05-02 14:20:50 +0000744 explicit CGOpenMPRuntime(CodeGenModule &CGM)
745 : CGOpenMPRuntime(CGM, ".", ".") {}
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +0000746 virtual ~CGOpenMPRuntime() {}
Alexey Bataev91797552015-03-18 04:13:55 +0000747 virtual void clear();
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000748
Alexey Bataev18fa2322018-05-02 14:20:50 +0000749 /// Get the platform-specific name separator.
750 std::string getName(ArrayRef<StringRef> Parts) const;
751
Alexey Bataevc5b1d322016-03-04 09:22:22 +0000752 /// Emit code for the specified user defined reduction construct.
753 virtual void emitUserDefinedReduction(CodeGenFunction *CGF,
754 const OMPDeclareReductionDecl *D);
Alexey Bataeva839ddd2016-03-17 10:19:46 +0000755 /// Get combiner/initializer for the specified user-defined reduction, if any.
756 virtual std::pair<llvm::Function *, llvm::Function *>
757 getUserDefinedReduction(const OMPDeclareReductionDecl *D);
Arpith Chacko Jacob19b911c2017-01-18 18:18:53 +0000758
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000759 /// Emits outlined function for the specified OpenMP parallel directive
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000760 /// \a D. This outlined function has type void(*)(kmp_int32 *ThreadID,
761 /// kmp_int32 BoundID, struct context_vars*).
Alexey Bataev18095712014-10-10 12:19:54 +0000762 /// \param D OpenMP directive.
763 /// \param ThreadIDVar Variable for thread id in the current OpenMP region.
Alexey Bataev81c7ea02015-07-03 09:56:58 +0000764 /// \param InnermostKind Kind of innermost directive (for simple directives it
765 /// is a directive itself, for combined - its innermost directive).
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000766 /// \param CodeGen Code generation sequence for the \a D directive.
Arpith Chacko Jacob19b911c2017-01-18 18:18:53 +0000767 virtual llvm::Value *emitParallelOutlinedFunction(
768 const OMPExecutableDirective &D, const VarDecl *ThreadIDVar,
769 OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen);
770
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000771 /// Emits outlined function for the specified OpenMP teams directive
Arpith Chacko Jacob19b911c2017-01-18 18:18:53 +0000772 /// \a D. This outlined function has type void(*)(kmp_int32 *ThreadID,
773 /// kmp_int32 BoundID, struct context_vars*).
774 /// \param D OpenMP directive.
775 /// \param ThreadIDVar Variable for thread id in the current OpenMP region.
776 /// \param InnermostKind Kind of innermost directive (for simple directives it
777 /// is a directive itself, for combined - its innermost directive).
778 /// \param CodeGen Code generation sequence for the \a D directive.
779 virtual llvm::Value *emitTeamsOutlinedFunction(
Alexey Bataev81c7ea02015-07-03 09:56:58 +0000780 const OMPExecutableDirective &D, const VarDecl *ThreadIDVar,
781 OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen);
Alexey Bataev18095712014-10-10 12:19:54 +0000782
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000783 /// Emits outlined function for the OpenMP task directive \a D. This
Alexey Bataev48591dd2016-04-20 04:01:36 +0000784 /// outlined function has type void(*)(kmp_int32 ThreadID, struct task_t*
785 /// TaskT).
Alexey Bataev62b63b12015-03-10 07:28:44 +0000786 /// \param D OpenMP directive.
787 /// \param ThreadIDVar Variable for thread id in the current OpenMP region.
Alexey Bataev48591dd2016-04-20 04:01:36 +0000788 /// \param PartIDVar Variable for partition id in the current OpenMP untied
789 /// task region.
790 /// \param TaskTVar Variable for task_t argument.
Alexey Bataev81c7ea02015-07-03 09:56:58 +0000791 /// \param InnermostKind Kind of innermost directive (for simple directives it
792 /// is a directive itself, for combined - its innermost directive).
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000793 /// \param CodeGen Code generation sequence for the \a D directive.
Alexey Bataev48591dd2016-04-20 04:01:36 +0000794 /// \param Tied true if task is generated for tied task, false otherwise.
795 /// \param NumberOfParts Number of parts in untied task. Ignored for tied
796 /// tasks.
Alexey Bataev62b63b12015-03-10 07:28:44 +0000797 ///
Alexey Bataev81c7ea02015-07-03 09:56:58 +0000798 virtual llvm::Value *emitTaskOutlinedFunction(
799 const OMPExecutableDirective &D, const VarDecl *ThreadIDVar,
Alexey Bataev48591dd2016-04-20 04:01:36 +0000800 const VarDecl *PartIDVar, const VarDecl *TaskTVar,
801 OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen,
802 bool Tied, unsigned &NumberOfParts);
Alexey Bataev62b63b12015-03-10 07:28:44 +0000803
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000804 /// Cleans up references to the objects in finished function.
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000805 ///
Gheorghe-Teodor Bercead3dcf2f2018-03-14 14:17:45 +0000806 virtual void functionFinished(CodeGenFunction &CGF);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000807
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000808 /// Emits code for parallel or serial call of the \a OutlinedFn with
Alexey Bataev1d677132015-04-22 13:57:31 +0000809 /// variables captured in a record which address is stored in \a
810 /// CapturedStruct.
Alexey Bataev18095712014-10-10 12:19:54 +0000811 /// \param OutlinedFn Outlined function to be run in parallel threads. Type of
Alexey Bataev62b63b12015-03-10 07:28:44 +0000812 /// this function is void(*)(kmp_int32 *, kmp_int32, struct context_vars*).
NAKAMURA Takumi62f0eb52015-09-11 08:13:32 +0000813 /// \param CapturedVars A pointer to the record with the references to
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000814 /// variables used in \a OutlinedFn function.
Alexey Bataev1d677132015-04-22 13:57:31 +0000815 /// \param IfCond Condition in the associated 'if' clause, if it was
816 /// specified, nullptr otherwise.
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000817 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000818 virtual void emitParallelCall(CodeGenFunction &CGF, SourceLocation Loc,
819 llvm::Value *OutlinedFn,
Alexey Bataev2377fe92015-09-10 08:12:02 +0000820 ArrayRef<llvm::Value *> CapturedVars,
821 const Expr *IfCond);
Alexey Bataevd74d0602014-10-13 06:02:40 +0000822
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000823 /// Emits a critical region.
Alexey Bataev18095712014-10-10 12:19:54 +0000824 /// \param CriticalName Name of the critical region.
Alexey Bataev75ddfab2014-12-01 11:32:38 +0000825 /// \param CriticalOpGen Generator for the statement associated with the given
826 /// critical region.
Alexey Bataevfc57d162015-12-15 10:55:09 +0000827 /// \param Hint Value of the 'hint' clause (optional).
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000828 virtual void emitCriticalRegion(CodeGenFunction &CGF, StringRef CriticalName,
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000829 const RegionCodeGenTy &CriticalOpGen,
Alexey Bataevfc57d162015-12-15 10:55:09 +0000830 SourceLocation Loc,
831 const Expr *Hint = nullptr);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000832
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000833 /// Emits a master region.
Alexey Bataev8d690652014-12-04 07:23:53 +0000834 /// \param MasterOpGen Generator for the statement associated with the given
835 /// master region.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000836 virtual void emitMasterRegion(CodeGenFunction &CGF,
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000837 const RegionCodeGenTy &MasterOpGen,
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000838 SourceLocation Loc);
Alexey Bataev8d690652014-12-04 07:23:53 +0000839
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000840 /// Emits code for a taskyield directive.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000841 virtual void emitTaskyieldCall(CodeGenFunction &CGF, SourceLocation Loc);
Alexey Bataev9f797f32015-02-05 05:57:51 +0000842
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000843 /// Emit a taskgroup region.
Alexey Bataevc30dd2d2015-06-18 12:14:09 +0000844 /// \param TaskgroupOpGen Generator for the statement associated with the
845 /// given taskgroup region.
846 virtual void emitTaskgroupRegion(CodeGenFunction &CGF,
847 const RegionCodeGenTy &TaskgroupOpGen,
848 SourceLocation Loc);
849
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000850 /// Emits a single region.
Alexey Bataev6956e2e2015-02-05 06:35:41 +0000851 /// \param SingleOpGen Generator for the statement associated with the given
852 /// single region.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000853 virtual void emitSingleRegion(CodeGenFunction &CGF,
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000854 const RegionCodeGenTy &SingleOpGen,
Alexey Bataeva63048e2015-03-23 06:18:07 +0000855 SourceLocation Loc,
856 ArrayRef<const Expr *> CopyprivateVars,
Alexey Bataev420d45b2015-04-14 05:11:24 +0000857 ArrayRef<const Expr *> DestExprs,
Alexey Bataeva63048e2015-03-23 06:18:07 +0000858 ArrayRef<const Expr *> SrcExprs,
Alexey Bataeva63048e2015-03-23 06:18:07 +0000859 ArrayRef<const Expr *> AssignmentOps);
Alexey Bataev6956e2e2015-02-05 06:35:41 +0000860
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000861 /// Emit an ordered region.
Alexey Bataev98eb6e32015-04-22 11:15:40 +0000862 /// \param OrderedOpGen Generator for the statement associated with the given
Alexey Bataevc30dd2d2015-06-18 12:14:09 +0000863 /// ordered region.
Alexey Bataev98eb6e32015-04-22 11:15:40 +0000864 virtual void emitOrderedRegion(CodeGenFunction &CGF,
865 const RegionCodeGenTy &OrderedOpGen,
Alexey Bataev5f600d62015-09-29 03:48:57 +0000866 SourceLocation Loc, bool IsThreads);
Alexey Bataev98eb6e32015-04-22 11:15:40 +0000867
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000868 /// Emit an implicit/explicit barrier for OpenMP threads.
Alexey Bataevf2685682015-03-30 04:30:22 +0000869 /// \param Kind Directive for which this implicit barrier call must be
870 /// generated. Must be OMPD_barrier for explicit barrier generation.
Alexey Bataev25e5b442015-09-15 12:52:43 +0000871 /// \param EmitChecks true if need to emit checks for cancellation barriers.
872 /// \param ForceSimpleCall true simple barrier call must be emitted, false if
873 /// runtime class decides which one to emit (simple or with cancellation
874 /// checks).
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000875 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000876 virtual void emitBarrierCall(CodeGenFunction &CGF, SourceLocation Loc,
Alexey Bataev81c7ea02015-07-03 09:56:58 +0000877 OpenMPDirectiveKind Kind,
Alexey Bataev25e5b442015-09-15 12:52:43 +0000878 bool EmitChecks = true,
879 bool ForceSimpleCall = false);
Alexey Bataevb2059782014-10-13 08:23:51 +0000880
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000881 /// Check if the specified \a ScheduleKind is static non-chunked.
Alexander Musmanc6388682014-12-15 07:07:06 +0000882 /// This kind of worksharing directive is emitted without outer loop.
883 /// \param ScheduleKind Schedule kind specified in the 'schedule' clause.
884 /// \param Chunked True if chunk is specified in the clause.
885 ///
886 virtual bool isStaticNonchunked(OpenMPScheduleClauseKind ScheduleKind,
887 bool Chunked) const;
888
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000889 /// Check if the specified \a ScheduleKind is static non-chunked.
Carlo Bertollifc35ad22016-03-07 16:04:49 +0000890 /// This kind of distribute directive is emitted without outer loop.
891 /// \param ScheduleKind Schedule kind specified in the 'dist_schedule' clause.
892 /// \param Chunked True if chunk is specified in the clause.
893 ///
894 virtual bool isStaticNonchunked(OpenMPDistScheduleClauseKind ScheduleKind,
895 bool Chunked) const;
896
Gheorghe-Teodor Berceae9256762018-10-29 15:45:47 +0000897 /// Check if the specified \a ScheduleKind is static chunked.
898 /// \param ScheduleKind Schedule kind specified in the 'schedule' clause.
899 /// \param Chunked True if chunk is specified in the clause.
900 ///
901 virtual bool isStaticChunked(OpenMPScheduleClauseKind ScheduleKind,
902 bool Chunked) const;
903
904 /// Check if the specified \a ScheduleKind is static non-chunked.
905 /// \param ScheduleKind Schedule kind specified in the 'dist_schedule' clause.
906 /// \param Chunked True if chunk is specified in the clause.
907 ///
908 virtual bool isStaticChunked(OpenMPDistScheduleClauseKind ScheduleKind,
909 bool Chunked) const;
910
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000911 /// Check if the specified \a ScheduleKind is dynamic.
Alexander Musmandf7a8e22015-01-22 08:49:35 +0000912 /// This kind of worksharing directive is emitted without outer loop.
913 /// \param ScheduleKind Schedule Kind specified in the 'schedule' clause.
914 ///
915 virtual bool isDynamic(OpenMPScheduleClauseKind ScheduleKind) const;
916
Carlo Bertollib0ff0a62017-04-25 17:52:12 +0000917 /// struct with the values to be passed to the dispatch runtime function
918 struct DispatchRTInput {
919 /// Loop lower bound
920 llvm::Value *LB = nullptr;
921 /// Loop upper bound
922 llvm::Value *UB = nullptr;
923 /// Chunk size specified using 'schedule' clause (nullptr if chunk
924 /// was not specified)
925 llvm::Value *Chunk = nullptr;
926 DispatchRTInput() = default;
927 DispatchRTInput(llvm::Value *LB, llvm::Value *UB, llvm::Value *Chunk)
928 : LB(LB), UB(UB), Chunk(Chunk) {}
929 };
930
931 /// Call the appropriate runtime routine to initialize it before start
932 /// of loop.
933
934 /// This is used for non static scheduled types and when the ordered
935 /// clause is present on the loop construct.
936 /// Depending on the loop schedule, it is necessary to call some runtime
937 /// routine before start of the OpenMP loop to get the loop upper / lower
938 /// bounds \a LB and \a UB and stride \a ST.
939 ///
940 /// \param CGF Reference to current CodeGenFunction.
941 /// \param Loc Clang source location.
942 /// \param ScheduleKind Schedule kind, specified by the 'schedule' clause.
943 /// \param IVSize Size of the iteration variable in bits.
Simon Pilgrim6c0eeff2017-07-13 17:34:44 +0000944 /// \param IVSigned Sign of the iteration variable.
Carlo Bertollib0ff0a62017-04-25 17:52:12 +0000945 /// \param Ordered true if loop is ordered, false otherwise.
946 /// \param DispatchValues struct containing llvm values for lower bound, upper
947 /// bound, and chunk expression.
948 /// For the default (nullptr) value, the chunk 1 will be used.
949 ///
NAKAMURA Takumiff7a9252015-09-08 09:42:41 +0000950 virtual void emitForDispatchInit(CodeGenFunction &CGF, SourceLocation Loc,
Alexey Bataev9ebd7422016-05-10 09:57:36 +0000951 const OpenMPScheduleTy &ScheduleKind,
952 unsigned IVSize, bool IVSigned, bool Ordered,
Carlo Bertollib0ff0a62017-04-25 17:52:12 +0000953 const DispatchRTInput &DispatchValues);
NAKAMURA Takumiff7a9252015-09-08 09:42:41 +0000954
Alexey Bataev0f87dbe2017-08-14 17:56:13 +0000955 /// Struct with the values to be passed to the static runtime function
956 struct StaticRTInput {
957 /// Size of the iteration variable in bits.
958 unsigned IVSize = 0;
959 /// Sign of the iteration variable.
960 bool IVSigned = false;
961 /// true if loop is ordered, false otherwise.
962 bool Ordered = false;
963 /// Address of the output variable in which the flag of the last iteration
964 /// is returned.
965 Address IL = Address::invalid();
966 /// Address of the output variable in which the lower iteration number is
967 /// returned.
968 Address LB = Address::invalid();
969 /// Address of the output variable in which the upper iteration number is
970 /// returned.
971 Address UB = Address::invalid();
972 /// Address of the output variable in which the stride value is returned
973 /// necessary to generated the static_chunked scheduled loop.
974 Address ST = Address::invalid();
975 /// Value of the chunk for the static_chunked scheduled loop. For the
976 /// default (nullptr) value, the chunk 1 will be used.
977 llvm::Value *Chunk = nullptr;
978 StaticRTInput(unsigned IVSize, bool IVSigned, bool Ordered, Address IL,
979 Address LB, Address UB, Address ST,
980 llvm::Value *Chunk = nullptr)
981 : IVSize(IVSize), IVSigned(IVSigned), Ordered(Ordered), IL(IL), LB(LB),
982 UB(UB), ST(ST), Chunk(Chunk) {}
983 };
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000984 /// Call the appropriate runtime routine to initialize it before start
Alexander Musmanc6388682014-12-15 07:07:06 +0000985 /// of loop.
986 ///
Carlo Bertollib0ff0a62017-04-25 17:52:12 +0000987 /// This is used only in case of static schedule, when the user did not
988 /// specify a ordered clause on the loop construct.
989 /// Depending on the loop schedule, it is necessary to call some runtime
Alexander Musmanc6388682014-12-15 07:07:06 +0000990 /// routine before start of the OpenMP loop to get the loop upper / lower
Alexey Bataev0f87dbe2017-08-14 17:56:13 +0000991 /// bounds LB and UB and stride ST.
Alexander Musmanc6388682014-12-15 07:07:06 +0000992 ///
993 /// \param CGF Reference to current CodeGenFunction.
994 /// \param Loc Clang source location.
Alexey Bataev0f87dbe2017-08-14 17:56:13 +0000995 /// \param DKind Kind of the directive.
Alexey Bataev9ebd7422016-05-10 09:57:36 +0000996 /// \param ScheduleKind Schedule kind, specified by the 'schedule' clause.
Alexey Bataev0f87dbe2017-08-14 17:56:13 +0000997 /// \param Values Input arguments for the construct.
Alexander Musmanc6388682014-12-15 07:07:06 +0000998 ///
John McCall7f416cc2015-09-08 08:05:57 +0000999 virtual void emitForStaticInit(CodeGenFunction &CGF, SourceLocation Loc,
Alexey Bataev0f87dbe2017-08-14 17:56:13 +00001000 OpenMPDirectiveKind DKind,
Alexey Bataev9ebd7422016-05-10 09:57:36 +00001001 const OpenMPScheduleTy &ScheduleKind,
Alexey Bataev0f87dbe2017-08-14 17:56:13 +00001002 const StaticRTInput &Values);
Alexander Musmanc6388682014-12-15 07:07:06 +00001003
Carlo Bertollifc35ad22016-03-07 16:04:49 +00001004 ///
1005 /// \param CGF Reference to current CodeGenFunction.
1006 /// \param Loc Clang source location.
1007 /// \param SchedKind Schedule kind, specified by the 'dist_schedule' clause.
Alexey Bataev0f87dbe2017-08-14 17:56:13 +00001008 /// \param Values Input arguments for the construct.
Carlo Bertollifc35ad22016-03-07 16:04:49 +00001009 ///
Alexey Bataev0f87dbe2017-08-14 17:56:13 +00001010 virtual void emitDistributeStaticInit(CodeGenFunction &CGF,
1011 SourceLocation Loc,
Carlo Bertollifc35ad22016-03-07 16:04:49 +00001012 OpenMPDistScheduleClauseKind SchedKind,
Alexey Bataev0f87dbe2017-08-14 17:56:13 +00001013 const StaticRTInput &Values);
Carlo Bertollifc35ad22016-03-07 16:04:49 +00001014
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001015 /// Call the appropriate runtime routine to notify that we finished
Alexey Bataev98eb6e32015-04-22 11:15:40 +00001016 /// iteration of the ordered loop with the dynamic scheduling.
1017 ///
1018 /// \param CGF Reference to current CodeGenFunction.
1019 /// \param Loc Clang source location.
1020 /// \param IVSize Size of the iteration variable in bits.
Simon Pilgrim6c0eeff2017-07-13 17:34:44 +00001021 /// \param IVSigned Sign of the iteration variable.
Alexey Bataev98eb6e32015-04-22 11:15:40 +00001022 ///
Alexey Bataevd7589ffe2015-05-20 13:12:48 +00001023 virtual void emitForOrderedIterationEnd(CodeGenFunction &CGF,
1024 SourceLocation Loc, unsigned IVSize,
1025 bool IVSigned);
Alexey Bataev98eb6e32015-04-22 11:15:40 +00001026
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001027 /// Call the appropriate runtime routine to notify that we finished
Alexander Musmanc6388682014-12-15 07:07:06 +00001028 /// all the work with current loop.
1029 ///
1030 /// \param CGF Reference to current CodeGenFunction.
1031 /// \param Loc Clang source location.
Alexey Bataevf43f7142017-09-06 16:17:35 +00001032 /// \param DKind Kind of the directive for which the static finish is emitted.
Alexander Musmanc6388682014-12-15 07:07:06 +00001033 ///
Alexey Bataevf43f7142017-09-06 16:17:35 +00001034 virtual void emitForStaticFinish(CodeGenFunction &CGF, SourceLocation Loc,
1035 OpenMPDirectiveKind DKind);
Alexander Musmanc6388682014-12-15 07:07:06 +00001036
Alexander Musman92bdaab2015-03-12 13:37:50 +00001037 /// Call __kmpc_dispatch_next(
1038 /// ident_t *loc, kmp_int32 tid, kmp_int32 *p_lastiter,
1039 /// kmp_int[32|64] *p_lower, kmp_int[32|64] *p_upper,
1040 /// kmp_int[32|64] *p_stride);
1041 /// \param IVSize Size of the iteration variable in bits.
Simon Pilgrim6c0eeff2017-07-13 17:34:44 +00001042 /// \param IVSigned Sign of the iteration variable.
Alexander Musman92bdaab2015-03-12 13:37:50 +00001043 /// \param IL Address of the output variable in which the flag of the
1044 /// last iteration is returned.
1045 /// \param LB Address of the output variable in which the lower iteration
1046 /// number is returned.
1047 /// \param UB Address of the output variable in which the upper iteration
1048 /// number is returned.
1049 /// \param ST Address of the output variable in which the stride value is
1050 /// returned.
1051 virtual llvm::Value *emitForNext(CodeGenFunction &CGF, SourceLocation Loc,
1052 unsigned IVSize, bool IVSigned,
John McCall7f416cc2015-09-08 08:05:57 +00001053 Address IL, Address LB,
1054 Address UB, Address ST);
Alexander Musman92bdaab2015-03-12 13:37:50 +00001055
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001056 /// Emits call to void __kmpc_push_num_threads(ident_t *loc, kmp_int32
Alexey Bataevb2059782014-10-13 08:23:51 +00001057 /// global_tid, kmp_int32 num_threads) to generate code for 'num_threads'
1058 /// clause.
1059 /// \param NumThreads An integer value of threads.
Alexey Bataev3eff5f42015-02-25 08:32:46 +00001060 virtual void emitNumThreadsClause(CodeGenFunction &CGF,
1061 llvm::Value *NumThreads,
1062 SourceLocation Loc);
Alexey Bataev97720002014-11-11 04:05:39 +00001063
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001064 /// Emit call to void __kmpc_push_proc_bind(ident_t *loc, kmp_int32
Alexey Bataev7f210c62015-06-18 13:40:03 +00001065 /// global_tid, int proc_bind) to generate code for 'proc_bind' clause.
1066 virtual void emitProcBindClause(CodeGenFunction &CGF,
1067 OpenMPProcBindClauseKind ProcBind,
1068 SourceLocation Loc);
1069
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001070 /// Returns address of the threadprivate variable for the current
Alexey Bataev97720002014-11-11 04:05:39 +00001071 /// thread.
NAKAMURA Takumicdcbfba2014-11-11 07:58:06 +00001072 /// \param VD Threadprivate variable.
Alexey Bataev97720002014-11-11 04:05:39 +00001073 /// \param VDAddr Address of the global variable \a VD.
1074 /// \param Loc Location of the reference to threadprivate var.
1075 /// \return Address of the threadprivate variable for the current thread.
John McCall7f416cc2015-09-08 08:05:57 +00001076 virtual Address getAddrOfThreadPrivate(CodeGenFunction &CGF,
1077 const VarDecl *VD,
1078 Address VDAddr,
1079 SourceLocation Loc);
Alexey Bataev97720002014-11-11 04:05:39 +00001080
Alexey Bataev92327c52018-03-26 16:40:55 +00001081 /// Returns the address of the variable marked as declare target with link
1082 /// clause.
Alexey Bataev03f270c2018-03-30 18:31:07 +00001083 virtual Address getAddrOfDeclareTargetLink(const VarDecl *VD);
Alexey Bataev92327c52018-03-26 16:40:55 +00001084
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001085 /// Emit a code for initialization of threadprivate variable. It emits
Alexey Bataev97720002014-11-11 04:05:39 +00001086 /// a call to runtime library which adds initial value to the newly created
1087 /// threadprivate variable (if it is not constant) and registers destructor
1088 /// for the variable (if any).
1089 /// \param VD Threadprivate variable.
1090 /// \param VDAddr Address of the global variable \a VD.
1091 /// \param Loc Location of threadprivate declaration.
1092 /// \param PerformInit true if initialization expression is not constant.
1093 virtual llvm::Function *
John McCall7f416cc2015-09-08 08:05:57 +00001094 emitThreadPrivateVarDefinition(const VarDecl *VD, Address VDAddr,
Alexey Bataev3eff5f42015-02-25 08:32:46 +00001095 SourceLocation Loc, bool PerformInit,
1096 CodeGenFunction *CGF = nullptr);
Alexey Bataevcc37cc12014-11-20 04:34:54 +00001097
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001098 /// Emit a code for initialization of declare target variable.
Alexey Bataev34f8a702018-03-28 14:28:54 +00001099 /// \param VD Declare target variable.
1100 /// \param Addr Address of the global variable \a VD.
1101 /// \param PerformInit true if initialization expression is not constant.
1102 virtual bool emitDeclareTargetVarDefinition(const VarDecl *VD,
1103 llvm::GlobalVariable *Addr,
1104 bool PerformInit);
1105
Alexey Bataevbe5a8b42017-07-17 13:30:36 +00001106 /// Creates artificial threadprivate variable with name \p Name and type \p
1107 /// VarType.
1108 /// \param VarType Type of the artificial threadprivate variable.
1109 /// \param Name Name of the artificial threadprivate variable.
1110 virtual Address getAddrOfArtificialThreadPrivate(CodeGenFunction &CGF,
1111 QualType VarType,
1112 StringRef Name);
1113
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001114 /// Emit flush of the variables specified in 'omp flush' directive.
Alexey Bataevcc37cc12014-11-20 04:34:54 +00001115 /// \param Vars List of variables to flush.
Alexey Bataev3eff5f42015-02-25 08:32:46 +00001116 virtual void emitFlush(CodeGenFunction &CGF, ArrayRef<const Expr *> Vars,
1117 SourceLocation Loc);
Alexey Bataev62b63b12015-03-10 07:28:44 +00001118
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001119 /// Emit task region for the task directive. The task region is
Nico Weber20b0ce32015-04-28 18:19:18 +00001120 /// emitted in several steps:
Alexey Bataev62b63b12015-03-10 07:28:44 +00001121 /// 1. Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32
1122 /// gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds,
1123 /// kmp_routine_entry_t *task_entry). Here task_entry is a pointer to the
1124 /// function:
1125 /// kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) {
1126 /// TaskFunction(gtid, tt->part_id, tt->shareds);
1127 /// return 0;
1128 /// }
1129 /// 2. Copy a list of shared variables to field shareds of the resulting
1130 /// structure kmp_task_t returned by the previous call (if any).
1131 /// 3. Copy a pointer to destructions function to field destructions of the
1132 /// resulting structure kmp_task_t.
1133 /// 4. Emit a call to kmp_int32 __kmpc_omp_task(ident_t *, kmp_int32 gtid,
1134 /// kmp_task_t *new_task), where new_task is a resulting structure from
1135 /// previous items.
Alexey Bataev36c1eb92015-04-30 06:51:57 +00001136 /// \param D Current task directive.
Alexey Bataev62b63b12015-03-10 07:28:44 +00001137 /// \param TaskFunction An LLVM function with type void (*)(i32 /*gtid*/, i32
1138 /// /*part_id*/, captured_struct */*__context*/);
1139 /// \param SharedsTy A type which contains references the shared variables.
Alexey Bataev1d2353d2015-06-24 11:01:36 +00001140 /// \param Shareds Context with the list of shared variables from the \p
Alexey Bataev62b63b12015-03-10 07:28:44 +00001141 /// TaskFunction.
Alexey Bataev1d677132015-04-22 13:57:31 +00001142 /// \param IfCond Not a nullptr if 'if' clause was specified, nullptr
1143 /// otherwise.
Alexey Bataev24b5bae2016-04-28 09:23:51 +00001144 /// \param Data Additional data for task generation like tiednsee, final
1145 /// state, list of privates etc.
1146 virtual void emitTaskCall(CodeGenFunction &CGF, SourceLocation Loc,
1147 const OMPExecutableDirective &D,
1148 llvm::Value *TaskFunction, QualType SharedsTy,
1149 Address Shareds, const Expr *IfCond,
1150 const OMPTaskDataTy &Data);
Alexey Bataev794ba0d2015-04-10 10:43:45 +00001151
Alexey Bataev7292c292016-04-25 12:22:29 +00001152 /// Emit task region for the taskloop directive. The taskloop region is
1153 /// emitted in several steps:
1154 /// 1. Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32
1155 /// gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds,
1156 /// kmp_routine_entry_t *task_entry). Here task_entry is a pointer to the
1157 /// function:
1158 /// kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) {
1159 /// TaskFunction(gtid, tt->part_id, tt->shareds);
1160 /// return 0;
1161 /// }
1162 /// 2. Copy a list of shared variables to field shareds of the resulting
1163 /// structure kmp_task_t returned by the previous call (if any).
1164 /// 3. Copy a pointer to destructions function to field destructions of the
1165 /// resulting structure kmp_task_t.
1166 /// 4. Emit a call to void __kmpc_taskloop(ident_t *loc, int gtid, kmp_task_t
1167 /// *task, int if_val, kmp_uint64 *lb, kmp_uint64 *ub, kmp_int64 st, int
1168 /// nogroup, int sched, kmp_uint64 grainsize, void *task_dup ), where new_task
1169 /// is a resulting structure from
1170 /// previous items.
1171 /// \param D Current task directive.
Alexey Bataev7292c292016-04-25 12:22:29 +00001172 /// \param TaskFunction An LLVM function with type void (*)(i32 /*gtid*/, i32
1173 /// /*part_id*/, captured_struct */*__context*/);
1174 /// \param SharedsTy A type which contains references the shared variables.
1175 /// \param Shareds Context with the list of shared variables from the \p
1176 /// TaskFunction.
1177 /// \param IfCond Not a nullptr if 'if' clause was specified, nullptr
1178 /// otherwise.
Alexey Bataev24b5bae2016-04-28 09:23:51 +00001179 /// \param Data Additional data for task generation like tiednsee, final
1180 /// state, list of privates etc.
Alexey Bataev7292c292016-04-25 12:22:29 +00001181 virtual void emitTaskLoopCall(
1182 CodeGenFunction &CGF, SourceLocation Loc, const OMPLoopDirective &D,
Alexey Bataev24b5bae2016-04-28 09:23:51 +00001183 llvm::Value *TaskFunction, QualType SharedsTy, Address Shareds,
1184 const Expr *IfCond, const OMPTaskDataTy &Data);
Alexey Bataev7292c292016-04-25 12:22:29 +00001185
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001186 /// Emit code for the directive that does not require outlining.
Alexey Bataev6f1ffc02015-04-10 04:50:10 +00001187 ///
Alexey Bataev81c7ea02015-07-03 09:56:58 +00001188 /// \param InnermostKind Kind of innermost directive (for simple directives it
1189 /// is a directive itself, for combined - its innermost directive).
Alexey Bataev6f1ffc02015-04-10 04:50:10 +00001190 /// \param CodeGen Code generation sequence for the \a D directive.
Alexey Bataev25e5b442015-09-15 12:52:43 +00001191 /// \param HasCancel true if region has inner cancel directive, false
1192 /// otherwise.
Alexey Bataev6f1ffc02015-04-10 04:50:10 +00001193 virtual void emitInlinedDirective(CodeGenFunction &CGF,
Alexey Bataev81c7ea02015-07-03 09:56:58 +00001194 OpenMPDirectiveKind InnermostKind,
Alexey Bataev25e5b442015-09-15 12:52:43 +00001195 const RegionCodeGenTy &CodeGen,
1196 bool HasCancel = false);
Arpith Chacko Jacob101e8fb2017-02-16 16:20:16 +00001197
1198 /// Emits reduction function.
1199 /// \param ArgsType Array type containing pointers to reduction variables.
1200 /// \param Privates List of private copies for original reduction arguments.
1201 /// \param LHSExprs List of LHS in \a ReductionOps reduction operations.
1202 /// \param RHSExprs List of RHS in \a ReductionOps reduction operations.
1203 /// \param ReductionOps List of reduction operations in form 'LHS binop RHS'
1204 /// or 'operator binop(LHS, RHS)'.
Alexey Bataev7cae94e2018-01-04 19:45:16 +00001205 llvm::Value *emitReductionFunction(CodeGenModule &CGM, SourceLocation Loc,
1206 llvm::Type *ArgsType,
Arpith Chacko Jacob101e8fb2017-02-16 16:20:16 +00001207 ArrayRef<const Expr *> Privates,
1208 ArrayRef<const Expr *> LHSExprs,
1209 ArrayRef<const Expr *> RHSExprs,
1210 ArrayRef<const Expr *> ReductionOps);
1211
1212 /// Emits single reduction combiner
1213 void emitSingleReductionCombiner(CodeGenFunction &CGF,
1214 const Expr *ReductionOp,
1215 const Expr *PrivateRef,
1216 const DeclRefExpr *LHS,
1217 const DeclRefExpr *RHS);
1218
1219 struct ReductionOptionsTy {
1220 bool WithNowait;
1221 bool SimpleReduction;
1222 OpenMPDirectiveKind ReductionKind;
1223 };
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001224 /// Emit a code for reduction clause. Next code should be emitted for
Alexey Bataev794ba0d2015-04-10 10:43:45 +00001225 /// reduction:
1226 /// \code
1227 ///
1228 /// static kmp_critical_name lock = { 0 };
1229 ///
1230 /// void reduce_func(void *lhs[<n>], void *rhs[<n>]) {
1231 /// ...
1232 /// *(Type<i>*)lhs[i] = RedOp<i>(*(Type<i>*)lhs[i], *(Type<i>*)rhs[i]);
1233 /// ...
1234 /// }
1235 ///
1236 /// ...
1237 /// void *RedList[<n>] = {&<RHSExprs>[0], ..., &<RHSExprs>[<n>-1]};
1238 /// switch (__kmpc_reduce{_nowait}(<loc>, <gtid>, <n>, sizeof(RedList),
1239 /// RedList, reduce_func, &<lock>)) {
1240 /// case 1:
1241 /// ...
1242 /// <LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]);
1243 /// ...
1244 /// __kmpc_end_reduce{_nowait}(<loc>, <gtid>, &<lock>);
1245 /// break;
1246 /// case 2:
1247 /// ...
1248 /// Atomic(<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]));
1249 /// ...
1250 /// break;
1251 /// default:;
1252 /// }
1253 /// \endcode
1254 ///
Alexey Bataevf24e7b12015-10-08 09:10:53 +00001255 /// \param Privates List of private copies for original reduction arguments.
Alexey Bataev794ba0d2015-04-10 10:43:45 +00001256 /// \param LHSExprs List of LHS in \a ReductionOps reduction operations.
1257 /// \param RHSExprs List of RHS in \a ReductionOps reduction operations.
1258 /// \param ReductionOps List of reduction operations in form 'LHS binop RHS'
1259 /// or 'operator binop(LHS, RHS)'.
Arpith Chacko Jacob101e8fb2017-02-16 16:20:16 +00001260 /// \param Options List of options for reduction codegen:
1261 /// WithNowait true if parent directive has also nowait clause, false
1262 /// otherwise.
1263 /// SimpleReduction Emit reduction operation only. Used for omp simd
1264 /// directive on the host.
1265 /// ReductionKind The kind of reduction to perform.
Alexey Bataev794ba0d2015-04-10 10:43:45 +00001266 virtual void emitReduction(CodeGenFunction &CGF, SourceLocation Loc,
Alexey Bataevf24e7b12015-10-08 09:10:53 +00001267 ArrayRef<const Expr *> Privates,
Alexey Bataev794ba0d2015-04-10 10:43:45 +00001268 ArrayRef<const Expr *> LHSExprs,
1269 ArrayRef<const Expr *> RHSExprs,
1270 ArrayRef<const Expr *> ReductionOps,
Arpith Chacko Jacob101e8fb2017-02-16 16:20:16 +00001271 ReductionOptionsTy Options);
Alexey Bataev8b8e2022015-04-27 05:22:09 +00001272
Alexey Bataevbe5a8b42017-07-17 13:30:36 +00001273 /// Emit a code for initialization of task reduction clause. Next code
1274 /// should be emitted for reduction:
1275 /// \code
1276 ///
1277 /// _task_red_item_t red_data[n];
1278 /// ...
1279 /// red_data[i].shar = &origs[i];
1280 /// red_data[i].size = sizeof(origs[i]);
1281 /// red_data[i].f_init = (void*)RedInit<i>;
1282 /// red_data[i].f_fini = (void*)RedDest<i>;
1283 /// red_data[i].f_comb = (void*)RedOp<i>;
1284 /// red_data[i].flags = <Flag_i>;
1285 /// ...
1286 /// void* tg1 = __kmpc_task_reduction_init(gtid, n, red_data);
1287 /// \endcode
1288 ///
1289 /// \param LHSExprs List of LHS in \a Data.ReductionOps reduction operations.
1290 /// \param RHSExprs List of RHS in \a Data.ReductionOps reduction operations.
1291 /// \param Data Additional data for task generation like tiedness, final
1292 /// state, list of privates, reductions etc.
1293 virtual llvm::Value *emitTaskReductionInit(CodeGenFunction &CGF,
1294 SourceLocation Loc,
1295 ArrayRef<const Expr *> LHSExprs,
1296 ArrayRef<const Expr *> RHSExprs,
1297 const OMPTaskDataTy &Data);
1298
1299 /// Required to resolve existing problems in the runtime. Emits threadprivate
1300 /// variables to store the size of the VLAs/array sections for
1301 /// initializer/combiner/finalizer functions + emits threadprivate variable to
1302 /// store the pointer to the original reduction item for the custom
1303 /// initializer defined by declare reduction construct.
1304 /// \param RCG Allows to reuse an existing data for the reductions.
1305 /// \param N Reduction item for which fixups must be emitted.
1306 virtual void emitTaskReductionFixups(CodeGenFunction &CGF, SourceLocation Loc,
1307 ReductionCodeGen &RCG, unsigned N);
1308
1309 /// Get the address of `void *` type of the privatue copy of the reduction
1310 /// item specified by the \p SharedLVal.
1311 /// \param ReductionsPtr Pointer to the reduction data returned by the
1312 /// emitTaskReductionInit function.
1313 /// \param SharedLVal Address of the original reduction item.
1314 virtual Address getTaskReductionItem(CodeGenFunction &CGF, SourceLocation Loc,
1315 llvm::Value *ReductionsPtr,
1316 LValue SharedLVal);
1317
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001318 /// Emit code for 'taskwait' directive.
Alexey Bataev8b8e2022015-04-27 05:22:09 +00001319 virtual void emitTaskwaitCall(CodeGenFunction &CGF, SourceLocation Loc);
Alexey Bataev0f34da12015-07-02 04:17:07 +00001320
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001321 /// Emit code for 'cancellation point' construct.
Alexey Bataev0f34da12015-07-02 04:17:07 +00001322 /// \param CancelRegion Region kind for which the cancellation point must be
1323 /// emitted.
1324 ///
1325 virtual void emitCancellationPointCall(CodeGenFunction &CGF,
1326 SourceLocation Loc,
1327 OpenMPDirectiveKind CancelRegion);
Alexey Bataev7d5d33e2015-07-06 05:50:32 +00001328
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001329 /// Emit code for 'cancel' construct.
Alexey Bataev87933c72015-09-18 08:07:34 +00001330 /// \param IfCond Condition in the associated 'if' clause, if it was
1331 /// specified, nullptr otherwise.
Alexey Bataev7d5d33e2015-07-06 05:50:32 +00001332 /// \param CancelRegion Region kind for which the cancel must be emitted.
1333 ///
1334 virtual void emitCancelCall(CodeGenFunction &CGF, SourceLocation Loc,
Alexey Bataev87933c72015-09-18 08:07:34 +00001335 const Expr *IfCond,
Alexey Bataev7d5d33e2015-07-06 05:50:32 +00001336 OpenMPDirectiveKind CancelRegion);
Samuel Antaobed3c462015-10-02 16:14:20 +00001337
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001338 /// Emit outilined function for 'target' directive.
Samuel Antaobed3c462015-10-02 16:14:20 +00001339 /// \param D Directive to emit.
Samuel Antaoee8fb302016-01-06 13:42:12 +00001340 /// \param ParentName Name of the function that encloses the target region.
1341 /// \param OutlinedFn Outlined function value to be defined by this call.
1342 /// \param OutlinedFnID Outlined function ID value to be defined by this call.
1343 /// \param IsOffloadEntry True if the outlined function is an offload entry.
Alexey Bataev14fa1c62016-03-29 05:34:15 +00001344 /// \param CodeGen Code generation sequence for the \a D directive.
Simon Pilgrim6c0eeff2017-07-13 17:34:44 +00001345 /// An outlined function may not be an entry if, e.g. the if clause always
Samuel Antaoee8fb302016-01-06 13:42:12 +00001346 /// evaluates to false.
1347 virtual void emitTargetOutlinedFunction(const OMPExecutableDirective &D,
1348 StringRef ParentName,
1349 llvm::Function *&OutlinedFn,
1350 llvm::Constant *&OutlinedFnID,
Alexey Bataev14fa1c62016-03-29 05:34:15 +00001351 bool IsOffloadEntry,
1352 const RegionCodeGenTy &CodeGen);
Samuel Antaobed3c462015-10-02 16:14:20 +00001353
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001354 /// Emit the target offloading code associated with \a D. The emitted
Samuel Antaobed3c462015-10-02 16:14:20 +00001355 /// code attempts offloading the execution to the device, an the event of
1356 /// a failure it executes the host version outlined in \a OutlinedFn.
1357 /// \param D Directive to emit.
1358 /// \param OutlinedFn Host version of the code to be offloaded.
Samuel Antaoee8fb302016-01-06 13:42:12 +00001359 /// \param OutlinedFnID ID of host version of the code to be offloaded.
Samuel Antaobed3c462015-10-02 16:14:20 +00001360 /// \param IfCond Expression evaluated in if clause associated with the target
1361 /// directive, or null if no if clause is used.
1362 /// \param Device Expression evaluated in device clause associated with the
1363 /// target directive, or null if no device clause is used.
Samuel Antaobed3c462015-10-02 16:14:20 +00001364 virtual void emitTargetCall(CodeGenFunction &CGF,
1365 const OMPExecutableDirective &D,
Samuel Antaoee8fb302016-01-06 13:42:12 +00001366 llvm::Value *OutlinedFn,
1367 llvm::Value *OutlinedFnID, const Expr *IfCond,
Alexey Bataev8451efa2018-01-15 19:06:12 +00001368 const Expr *Device);
Samuel Antaoee8fb302016-01-06 13:42:12 +00001369
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001370 /// Emit the target regions enclosed in \a GD function definition or
Samuel Antaoee8fb302016-01-06 13:42:12 +00001371 /// the function itself in case it is a valid device function. Returns true if
1372 /// \a GD was dealt with successfully.
Nico Webera2abe8c2016-01-06 19:13:49 +00001373 /// \param GD Function to scan.
Samuel Antaoee8fb302016-01-06 13:42:12 +00001374 virtual bool emitTargetFunctions(GlobalDecl GD);
1375
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001376 /// Emit the global variable if it is a valid device global variable.
Samuel Antaoee8fb302016-01-06 13:42:12 +00001377 /// Returns true if \a GD was dealt with successfully.
1378 /// \param GD Variable declaration to emit.
1379 virtual bool emitTargetGlobalVariable(GlobalDecl GD);
1380
Alexey Bataev03f270c2018-03-30 18:31:07 +00001381 /// Checks if the provided global decl \a GD is a declare target variable and
1382 /// registers it when emitting code for the host.
1383 virtual void registerTargetGlobalVariable(const VarDecl *VD,
1384 llvm::Constant *Addr);
1385
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001386 /// Emit the global \a GD if it is meaningful for the target. Returns
Simon Pilgrim2c518802017-03-30 14:13:19 +00001387 /// if it was emitted successfully.
Samuel Antaoee8fb302016-01-06 13:42:12 +00001388 /// \param GD Global to scan.
1389 virtual bool emitTargetGlobal(GlobalDecl GD);
1390
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001391 /// Creates the offloading descriptor in the event any target region
Samuel Antaoee8fb302016-01-06 13:42:12 +00001392 /// was emitted in the current module and return the function that registers
1393 /// it.
1394 virtual llvm::Function *emitRegistrationFunction();
Carlo Bertolli430d8ec2016-03-03 20:34:23 +00001395
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001396 /// Emits code for teams call of the \a OutlinedFn with
Carlo Bertolli430d8ec2016-03-03 20:34:23 +00001397 /// variables captured in a record which address is stored in \a
1398 /// CapturedStruct.
1399 /// \param OutlinedFn Outlined function to be run by team masters. Type of
1400 /// this function is void(*)(kmp_int32 *, kmp_int32, struct context_vars*).
1401 /// \param CapturedVars A pointer to the record with the references to
1402 /// variables used in \a OutlinedFn function.
1403 ///
1404 virtual void emitTeamsCall(CodeGenFunction &CGF,
1405 const OMPExecutableDirective &D,
1406 SourceLocation Loc, llvm::Value *OutlinedFn,
1407 ArrayRef<llvm::Value *> CapturedVars);
1408
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001409 /// Emits call to void __kmpc_push_num_teams(ident_t *loc, kmp_int32
Carlo Bertolli430d8ec2016-03-03 20:34:23 +00001410 /// global_tid, kmp_int32 num_teams, kmp_int32 thread_limit) to generate code
1411 /// for num_teams clause.
Carlo Bertollic6872252016-04-04 15:55:02 +00001412 /// \param NumTeams An integer expression of teams.
1413 /// \param ThreadLimit An integer expression of threads.
1414 virtual void emitNumTeamsClause(CodeGenFunction &CGF, const Expr *NumTeams,
1415 const Expr *ThreadLimit, SourceLocation Loc);
Samuel Antaodf158d52016-04-27 22:58:19 +00001416
Samuel Antaocc10b852016-07-28 14:23:26 +00001417 /// Struct that keeps all the relevant information that should be kept
1418 /// throughout a 'target data' region.
1419 class TargetDataInfo {
1420 /// Set to true if device pointer information have to be obtained.
1421 bool RequiresDevicePointerInfo = false;
1422
1423 public:
1424 /// The array of base pointer passed to the runtime library.
1425 llvm::Value *BasePointersArray = nullptr;
1426 /// The array of section pointers passed to the runtime library.
1427 llvm::Value *PointersArray = nullptr;
1428 /// The array of sizes passed to the runtime library.
1429 llvm::Value *SizesArray = nullptr;
1430 /// The array of map types passed to the runtime library.
1431 llvm::Value *MapTypesArray = nullptr;
1432 /// The total number of pointers passed to the runtime library.
1433 unsigned NumberOfPtrs = 0u;
1434 /// Map between the a declaration of a capture and the corresponding base
1435 /// pointer address where the runtime returns the device pointers.
1436 llvm::DenseMap<const ValueDecl *, Address> CaptureDeviceAddrMap;
1437
1438 explicit TargetDataInfo() {}
1439 explicit TargetDataInfo(bool RequiresDevicePointerInfo)
1440 : RequiresDevicePointerInfo(RequiresDevicePointerInfo) {}
1441 /// Clear information about the data arrays.
1442 void clearArrayInfo() {
1443 BasePointersArray = nullptr;
1444 PointersArray = nullptr;
1445 SizesArray = nullptr;
1446 MapTypesArray = nullptr;
1447 NumberOfPtrs = 0u;
1448 }
1449 /// Return true if the current target data information has valid arrays.
1450 bool isValid() {
1451 return BasePointersArray && PointersArray && SizesArray &&
1452 MapTypesArray && NumberOfPtrs;
1453 }
1454 bool requiresDevicePointerInfo() { return RequiresDevicePointerInfo; }
1455 };
1456
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001457 /// Emit the target data mapping code associated with \a D.
Samuel Antaodf158d52016-04-27 22:58:19 +00001458 /// \param D Directive to emit.
Samuel Antaocc10b852016-07-28 14:23:26 +00001459 /// \param IfCond Expression evaluated in if clause associated with the
1460 /// target directive, or null if no device clause is used.
Samuel Antaodf158d52016-04-27 22:58:19 +00001461 /// \param Device Expression evaluated in device clause associated with the
1462 /// target directive, or null if no device clause is used.
Samuel Antaocc10b852016-07-28 14:23:26 +00001463 /// \param Info A record used to store information that needs to be preserved
1464 /// until the region is closed.
Samuel Antaodf158d52016-04-27 22:58:19 +00001465 virtual void emitTargetDataCalls(CodeGenFunction &CGF,
1466 const OMPExecutableDirective &D,
1467 const Expr *IfCond, const Expr *Device,
Samuel Antaocc10b852016-07-28 14:23:26 +00001468 const RegionCodeGenTy &CodeGen,
1469 TargetDataInfo &Info);
Samuel Antaobd0ae2e2016-04-27 23:07:29 +00001470
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001471 /// Emit the data mapping/movement code associated with the directive
Samuel Antao8d2d7302016-05-26 18:30:22 +00001472 /// \a D that should be of the form 'target [{enter|exit} data | update]'.
Samuel Antaobd0ae2e2016-04-27 23:07:29 +00001473 /// \param D Directive to emit.
1474 /// \param IfCond Expression evaluated in if clause associated with the target
1475 /// directive, or null if no if clause is used.
1476 /// \param Device Expression evaluated in device clause associated with the
1477 /// target directive, or null if no device clause is used.
Samuel Antao8d2d7302016-05-26 18:30:22 +00001478 virtual void emitTargetDataStandAloneCall(CodeGenFunction &CGF,
1479 const OMPExecutableDirective &D,
1480 const Expr *IfCond,
1481 const Expr *Device);
Alexey Bataevc7a82b42016-05-06 09:40:08 +00001482
1483 /// Marks function \a Fn with properly mangled versions of vector functions.
1484 /// \param FD Function marked as 'declare simd'.
1485 /// \param Fn LLVM function that must be marked with 'declare simd'
1486 /// attributes.
1487 virtual void emitDeclareSimdFunction(const FunctionDecl *FD,
1488 llvm::Function *Fn);
Alexey Bataev8b427062016-05-25 12:36:08 +00001489
1490 /// Emit initialization for doacross loop nesting support.
1491 /// \param D Loop-based construct used in doacross nesting construct.
Alexey Bataevf138fda2018-08-13 19:04:24 +00001492 virtual void emitDoacrossInit(CodeGenFunction &CGF, const OMPLoopDirective &D,
1493 ArrayRef<Expr *> NumIterations);
Alexey Bataev8b427062016-05-25 12:36:08 +00001494
1495 /// Emit code for doacross ordered directive with 'depend' clause.
1496 /// \param C 'depend' clause with 'sink|source' dependency kind.
1497 virtual void emitDoacrossOrdered(CodeGenFunction &CGF,
1498 const OMPDependClause *C);
Alexey Bataev2c7eee52017-08-04 19:10:54 +00001499
Alexey Bataev3b8d5582017-08-08 18:04:06 +00001500 /// Translates the native parameter of outlined function if this is required
1501 /// for target.
Alexander Kornienko2a8c18d2018-04-06 15:14:32 +00001502 /// \param FD Field decl from captured record for the parameter.
Alexey Bataev3b8d5582017-08-08 18:04:06 +00001503 /// \param NativeParam Parameter itself.
1504 virtual const VarDecl *translateParameter(const FieldDecl *FD,
1505 const VarDecl *NativeParam) const {
1506 return NativeParam;
1507 }
1508
1509 /// Gets the address of the native argument basing on the address of the
1510 /// target-specific parameter.
1511 /// \param NativeParam Parameter itself.
1512 /// \param TargetParam Corresponding target-specific parameter.
1513 virtual Address getParameterAddress(CodeGenFunction &CGF,
1514 const VarDecl *NativeParam,
1515 const VarDecl *TargetParam) const;
1516
Gheorghe-Teodor Bercea02650d42018-09-27 19:22:56 +00001517 /// Choose default schedule type and chunk value for the
1518 /// dist_schedule clause.
1519 virtual void getDefaultDistScheduleAndChunk(CodeGenFunction &CGF,
1520 const OMPLoopDirective &S, OpenMPDistScheduleClauseKind &ScheduleKind,
1521 llvm::Value *&Chunk) const {}
1522
Gheorghe-Teodor Bercea8233af92018-09-27 20:29:00 +00001523 /// Choose default schedule type and chunk value for the
1524 /// schedule clause.
1525 virtual void getDefaultScheduleAndChunk(CodeGenFunction &CGF,
1526 const OMPLoopDirective &S, OpenMPScheduleClauseKind &ScheduleKind,
Gheorghe-Teodor Berceae9256762018-10-29 15:45:47 +00001527 const Expr *&ChunkExpr) const {}
Gheorghe-Teodor Bercea8233af92018-09-27 20:29:00 +00001528
Alexey Bataev2c7eee52017-08-04 19:10:54 +00001529 /// Emits call of the outlined function with the provided arguments,
1530 /// translating these arguments to correct target-specific arguments.
1531 virtual void
Alexey Bataev3c595a62017-08-14 15:01:03 +00001532 emitOutlinedFunctionCall(CodeGenFunction &CGF, SourceLocation Loc,
1533 llvm::Value *OutlinedFn,
Alexey Bataev2c7eee52017-08-04 19:10:54 +00001534 ArrayRef<llvm::Value *> Args = llvm::None) const;
Gheorghe-Teodor Bercead3dcf2f2018-03-14 14:17:45 +00001535
1536 /// Emits OpenMP-specific function prolog.
1537 /// Required for device constructs.
1538 virtual void emitFunctionProlog(CodeGenFunction &CGF, const Decl *D) {}
1539
1540 /// Gets the OpenMP-specific address of the local variable.
1541 virtual Address getAddressOfLocalVariable(CodeGenFunction &CGF,
1542 const VarDecl *VD);
Alexey Bataev4f4bf7c2018-03-15 15:47:20 +00001543
1544 /// Marks the declaration as alread emitted for the device code and returns
1545 /// true, if it was marked already, and false, otherwise.
Alexey Bataev6d944102018-05-02 15:45:28 +00001546 bool markAsGlobalTarget(GlobalDecl GD);
Alexey Bataev4f4bf7c2018-03-15 15:47:20 +00001547
Alexey Bataevbf8fe712018-08-07 16:14:36 +00001548 /// Emit deferred declare target variables marked for deferred emission.
1549 void emitDeferredTargetDecls() const;
Alexey Bataev60705422018-10-30 15:50:12 +00001550
1551 /// Adjust some parameters for the target-based directives, like addresses of
1552 /// the variables captured by reference in lambdas.
1553 virtual void
1554 adjustTargetSpecificDataForLambdas(CodeGenFunction &CGF,
1555 const OMPExecutableDirective &D) const;
Patrick Lyster8f7f5862018-11-19 15:09:33 +00001556
1557 /// Perform check on requires decl to ensure that target architecture
1558 /// supports unified addressing
1559 virtual void checkArchForUnifiedAddressing(CodeGenModule &CGM,
1560 const OMPRequiresDecl *D) const {}
Alexey Bataev9959db52014-05-06 10:08:46 +00001561};
Alexey Bataev8cbe0a62015-02-26 10:27:34 +00001562
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00001563/// Class supports emissionof SIMD-only code.
1564class CGOpenMPSIMDRuntime final : public CGOpenMPRuntime {
1565public:
1566 explicit CGOpenMPSIMDRuntime(CodeGenModule &CGM) : CGOpenMPRuntime(CGM) {}
1567 ~CGOpenMPSIMDRuntime() override {}
1568
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001569 /// Emits outlined function for the specified OpenMP parallel directive
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00001570 /// \a D. This outlined function has type void(*)(kmp_int32 *ThreadID,
1571 /// kmp_int32 BoundID, struct context_vars*).
1572 /// \param D OpenMP directive.
1573 /// \param ThreadIDVar Variable for thread id in the current OpenMP region.
1574 /// \param InnermostKind Kind of innermost directive (for simple directives it
1575 /// is a directive itself, for combined - its innermost directive).
1576 /// \param CodeGen Code generation sequence for the \a D directive.
1577 llvm::Value *
1578 emitParallelOutlinedFunction(const OMPExecutableDirective &D,
1579 const VarDecl *ThreadIDVar,
1580 OpenMPDirectiveKind InnermostKind,
1581 const RegionCodeGenTy &CodeGen) override;
1582
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001583 /// Emits outlined function for the specified OpenMP teams directive
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00001584 /// \a D. This outlined function has type void(*)(kmp_int32 *ThreadID,
1585 /// kmp_int32 BoundID, struct context_vars*).
1586 /// \param D OpenMP directive.
1587 /// \param ThreadIDVar Variable for thread id in the current OpenMP region.
1588 /// \param InnermostKind Kind of innermost directive (for simple directives it
1589 /// is a directive itself, for combined - its innermost directive).
1590 /// \param CodeGen Code generation sequence for the \a D directive.
1591 llvm::Value *
1592 emitTeamsOutlinedFunction(const OMPExecutableDirective &D,
1593 const VarDecl *ThreadIDVar,
1594 OpenMPDirectiveKind InnermostKind,
1595 const RegionCodeGenTy &CodeGen) override;
1596
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001597 /// Emits outlined function for the OpenMP task directive \a D. This
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00001598 /// outlined function has type void(*)(kmp_int32 ThreadID, struct task_t*
1599 /// TaskT).
1600 /// \param D OpenMP directive.
1601 /// \param ThreadIDVar Variable for thread id in the current OpenMP region.
1602 /// \param PartIDVar Variable for partition id in the current OpenMP untied
1603 /// task region.
1604 /// \param TaskTVar Variable for task_t argument.
1605 /// \param InnermostKind Kind of innermost directive (for simple directives it
1606 /// is a directive itself, for combined - its innermost directive).
1607 /// \param CodeGen Code generation sequence for the \a D directive.
1608 /// \param Tied true if task is generated for tied task, false otherwise.
1609 /// \param NumberOfParts Number of parts in untied task. Ignored for tied
1610 /// tasks.
1611 ///
1612 llvm::Value *emitTaskOutlinedFunction(
1613 const OMPExecutableDirective &D, const VarDecl *ThreadIDVar,
1614 const VarDecl *PartIDVar, const VarDecl *TaskTVar,
1615 OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen,
1616 bool Tied, unsigned &NumberOfParts) override;
1617
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001618 /// Emits code for parallel or serial call of the \a OutlinedFn with
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00001619 /// variables captured in a record which address is stored in \a
1620 /// CapturedStruct.
1621 /// \param OutlinedFn Outlined function to be run in parallel threads. Type of
1622 /// this function is void(*)(kmp_int32 *, kmp_int32, struct context_vars*).
1623 /// \param CapturedVars A pointer to the record with the references to
1624 /// variables used in \a OutlinedFn function.
1625 /// \param IfCond Condition in the associated 'if' clause, if it was
1626 /// specified, nullptr otherwise.
1627 ///
1628 void emitParallelCall(CodeGenFunction &CGF, SourceLocation Loc,
1629 llvm::Value *OutlinedFn,
1630 ArrayRef<llvm::Value *> CapturedVars,
1631 const Expr *IfCond) override;
1632
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001633 /// Emits a critical region.
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00001634 /// \param CriticalName Name of the critical region.
1635 /// \param CriticalOpGen Generator for the statement associated with the given
1636 /// critical region.
1637 /// \param Hint Value of the 'hint' clause (optional).
1638 void emitCriticalRegion(CodeGenFunction &CGF, StringRef CriticalName,
1639 const RegionCodeGenTy &CriticalOpGen,
1640 SourceLocation Loc,
1641 const Expr *Hint = nullptr) override;
1642
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001643 /// Emits a master region.
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00001644 /// \param MasterOpGen Generator for the statement associated with the given
1645 /// master region.
1646 void emitMasterRegion(CodeGenFunction &CGF,
1647 const RegionCodeGenTy &MasterOpGen,
1648 SourceLocation Loc) override;
1649
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001650 /// Emits code for a taskyield directive.
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00001651 void emitTaskyieldCall(CodeGenFunction &CGF, SourceLocation Loc) override;
1652
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001653 /// Emit a taskgroup region.
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00001654 /// \param TaskgroupOpGen Generator for the statement associated with the
1655 /// given taskgroup region.
1656 void emitTaskgroupRegion(CodeGenFunction &CGF,
1657 const RegionCodeGenTy &TaskgroupOpGen,
1658 SourceLocation Loc) override;
1659
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001660 /// Emits a single region.
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00001661 /// \param SingleOpGen Generator for the statement associated with the given
1662 /// single region.
1663 void emitSingleRegion(CodeGenFunction &CGF,
1664 const RegionCodeGenTy &SingleOpGen, SourceLocation Loc,
1665 ArrayRef<const Expr *> CopyprivateVars,
1666 ArrayRef<const Expr *> DestExprs,
1667 ArrayRef<const Expr *> SrcExprs,
1668 ArrayRef<const Expr *> AssignmentOps) override;
1669
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001670 /// Emit an ordered region.
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00001671 /// \param OrderedOpGen Generator for the statement associated with the given
1672 /// ordered region.
1673 void emitOrderedRegion(CodeGenFunction &CGF,
1674 const RegionCodeGenTy &OrderedOpGen,
1675 SourceLocation Loc, bool IsThreads) override;
1676
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001677 /// Emit an implicit/explicit barrier for OpenMP threads.
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00001678 /// \param Kind Directive for which this implicit barrier call must be
1679 /// generated. Must be OMPD_barrier for explicit barrier generation.
1680 /// \param EmitChecks true if need to emit checks for cancellation barriers.
1681 /// \param ForceSimpleCall true simple barrier call must be emitted, false if
1682 /// runtime class decides which one to emit (simple or with cancellation
1683 /// checks).
1684 ///
1685 void emitBarrierCall(CodeGenFunction &CGF, SourceLocation Loc,
1686 OpenMPDirectiveKind Kind, bool EmitChecks = true,
1687 bool ForceSimpleCall = false) override;
1688
1689 /// This is used for non static scheduled types and when the ordered
1690 /// clause is present on the loop construct.
1691 /// Depending on the loop schedule, it is necessary to call some runtime
1692 /// routine before start of the OpenMP loop to get the loop upper / lower
1693 /// bounds \a LB and \a UB and stride \a ST.
1694 ///
1695 /// \param CGF Reference to current CodeGenFunction.
1696 /// \param Loc Clang source location.
1697 /// \param ScheduleKind Schedule kind, specified by the 'schedule' clause.
1698 /// \param IVSize Size of the iteration variable in bits.
1699 /// \param IVSigned Sign of the iteration variable.
1700 /// \param Ordered true if loop is ordered, false otherwise.
1701 /// \param DispatchValues struct containing llvm values for lower bound, upper
1702 /// bound, and chunk expression.
1703 /// For the default (nullptr) value, the chunk 1 will be used.
1704 ///
1705 void emitForDispatchInit(CodeGenFunction &CGF, SourceLocation Loc,
1706 const OpenMPScheduleTy &ScheduleKind,
1707 unsigned IVSize, bool IVSigned, bool Ordered,
1708 const DispatchRTInput &DispatchValues) override;
1709
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001710 /// Call the appropriate runtime routine to initialize it before start
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00001711 /// of loop.
1712 ///
1713 /// This is used only in case of static schedule, when the user did not
1714 /// specify a ordered clause on the loop construct.
1715 /// Depending on the loop schedule, it is necessary to call some runtime
1716 /// routine before start of the OpenMP loop to get the loop upper / lower
1717 /// bounds LB and UB and stride ST.
1718 ///
1719 /// \param CGF Reference to current CodeGenFunction.
1720 /// \param Loc Clang source location.
1721 /// \param DKind Kind of the directive.
1722 /// \param ScheduleKind Schedule kind, specified by the 'schedule' clause.
1723 /// \param Values Input arguments for the construct.
1724 ///
1725 void emitForStaticInit(CodeGenFunction &CGF, SourceLocation Loc,
1726 OpenMPDirectiveKind DKind,
1727 const OpenMPScheduleTy &ScheduleKind,
1728 const StaticRTInput &Values) override;
1729
1730 ///
1731 /// \param CGF Reference to current CodeGenFunction.
1732 /// \param Loc Clang source location.
1733 /// \param SchedKind Schedule kind, specified by the 'dist_schedule' clause.
1734 /// \param Values Input arguments for the construct.
1735 ///
1736 void emitDistributeStaticInit(CodeGenFunction &CGF, SourceLocation Loc,
1737 OpenMPDistScheduleClauseKind SchedKind,
1738 const StaticRTInput &Values) override;
1739
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001740 /// Call the appropriate runtime routine to notify that we finished
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00001741 /// iteration of the ordered loop with the dynamic scheduling.
1742 ///
1743 /// \param CGF Reference to current CodeGenFunction.
1744 /// \param Loc Clang source location.
1745 /// \param IVSize Size of the iteration variable in bits.
1746 /// \param IVSigned Sign of the iteration variable.
1747 ///
1748 void emitForOrderedIterationEnd(CodeGenFunction &CGF, SourceLocation Loc,
1749 unsigned IVSize, bool IVSigned) override;
1750
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001751 /// Call the appropriate runtime routine to notify that we finished
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00001752 /// all the work with current loop.
1753 ///
1754 /// \param CGF Reference to current CodeGenFunction.
1755 /// \param Loc Clang source location.
1756 /// \param DKind Kind of the directive for which the static finish is emitted.
1757 ///
1758 void emitForStaticFinish(CodeGenFunction &CGF, SourceLocation Loc,
1759 OpenMPDirectiveKind DKind) override;
1760
1761 /// Call __kmpc_dispatch_next(
1762 /// ident_t *loc, kmp_int32 tid, kmp_int32 *p_lastiter,
1763 /// kmp_int[32|64] *p_lower, kmp_int[32|64] *p_upper,
1764 /// kmp_int[32|64] *p_stride);
1765 /// \param IVSize Size of the iteration variable in bits.
1766 /// \param IVSigned Sign of the iteration variable.
1767 /// \param IL Address of the output variable in which the flag of the
1768 /// last iteration is returned.
1769 /// \param LB Address of the output variable in which the lower iteration
1770 /// number is returned.
1771 /// \param UB Address of the output variable in which the upper iteration
1772 /// number is returned.
1773 /// \param ST Address of the output variable in which the stride value is
1774 /// returned.
1775 llvm::Value *emitForNext(CodeGenFunction &CGF, SourceLocation Loc,
1776 unsigned IVSize, bool IVSigned, Address IL,
1777 Address LB, Address UB, Address ST) override;
1778
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001779 /// Emits call to void __kmpc_push_num_threads(ident_t *loc, kmp_int32
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00001780 /// global_tid, kmp_int32 num_threads) to generate code for 'num_threads'
1781 /// clause.
1782 /// \param NumThreads An integer value of threads.
1783 void emitNumThreadsClause(CodeGenFunction &CGF, llvm::Value *NumThreads,
1784 SourceLocation Loc) override;
1785
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001786 /// Emit call to void __kmpc_push_proc_bind(ident_t *loc, kmp_int32
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00001787 /// global_tid, int proc_bind) to generate code for 'proc_bind' clause.
1788 void emitProcBindClause(CodeGenFunction &CGF,
1789 OpenMPProcBindClauseKind ProcBind,
1790 SourceLocation Loc) override;
1791
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001792 /// Returns address of the threadprivate variable for the current
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00001793 /// thread.
1794 /// \param VD Threadprivate variable.
1795 /// \param VDAddr Address of the global variable \a VD.
1796 /// \param Loc Location of the reference to threadprivate var.
1797 /// \return Address of the threadprivate variable for the current thread.
1798 Address getAddrOfThreadPrivate(CodeGenFunction &CGF, const VarDecl *VD,
1799 Address VDAddr, SourceLocation Loc) override;
1800
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001801 /// Emit a code for initialization of threadprivate variable. It emits
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00001802 /// a call to runtime library which adds initial value to the newly created
1803 /// threadprivate variable (if it is not constant) and registers destructor
1804 /// for the variable (if any).
1805 /// \param VD Threadprivate variable.
1806 /// \param VDAddr Address of the global variable \a VD.
1807 /// \param Loc Location of threadprivate declaration.
1808 /// \param PerformInit true if initialization expression is not constant.
1809 llvm::Function *
1810 emitThreadPrivateVarDefinition(const VarDecl *VD, Address VDAddr,
1811 SourceLocation Loc, bool PerformInit,
1812 CodeGenFunction *CGF = nullptr) override;
1813
1814 /// Creates artificial threadprivate variable with name \p Name and type \p
1815 /// VarType.
1816 /// \param VarType Type of the artificial threadprivate variable.
1817 /// \param Name Name of the artificial threadprivate variable.
1818 Address getAddrOfArtificialThreadPrivate(CodeGenFunction &CGF,
1819 QualType VarType,
1820 StringRef Name) override;
1821
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001822 /// Emit flush of the variables specified in 'omp flush' directive.
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00001823 /// \param Vars List of variables to flush.
1824 void emitFlush(CodeGenFunction &CGF, ArrayRef<const Expr *> Vars,
1825 SourceLocation Loc) override;
1826
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001827 /// Emit task region for the task directive. The task region is
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00001828 /// emitted in several steps:
1829 /// 1. Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32
1830 /// gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds,
1831 /// kmp_routine_entry_t *task_entry). Here task_entry is a pointer to the
1832 /// function:
1833 /// kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) {
1834 /// TaskFunction(gtid, tt->part_id, tt->shareds);
1835 /// return 0;
1836 /// }
1837 /// 2. Copy a list of shared variables to field shareds of the resulting
1838 /// structure kmp_task_t returned by the previous call (if any).
1839 /// 3. Copy a pointer to destructions function to field destructions of the
1840 /// resulting structure kmp_task_t.
1841 /// 4. Emit a call to kmp_int32 __kmpc_omp_task(ident_t *, kmp_int32 gtid,
1842 /// kmp_task_t *new_task), where new_task is a resulting structure from
1843 /// previous items.
1844 /// \param D Current task directive.
1845 /// \param TaskFunction An LLVM function with type void (*)(i32 /*gtid*/, i32
1846 /// /*part_id*/, captured_struct */*__context*/);
1847 /// \param SharedsTy A type which contains references the shared variables.
1848 /// \param Shareds Context with the list of shared variables from the \p
1849 /// TaskFunction.
1850 /// \param IfCond Not a nullptr if 'if' clause was specified, nullptr
1851 /// otherwise.
1852 /// \param Data Additional data for task generation like tiednsee, final
1853 /// state, list of privates etc.
1854 void emitTaskCall(CodeGenFunction &CGF, SourceLocation Loc,
1855 const OMPExecutableDirective &D, llvm::Value *TaskFunction,
1856 QualType SharedsTy, Address Shareds, const Expr *IfCond,
1857 const OMPTaskDataTy &Data) override;
1858
1859 /// Emit task region for the taskloop directive. The taskloop region is
1860 /// emitted in several steps:
1861 /// 1. Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32
1862 /// gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds,
1863 /// kmp_routine_entry_t *task_entry). Here task_entry is a pointer to the
1864 /// function:
1865 /// kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) {
1866 /// TaskFunction(gtid, tt->part_id, tt->shareds);
1867 /// return 0;
1868 /// }
1869 /// 2. Copy a list of shared variables to field shareds of the resulting
1870 /// structure kmp_task_t returned by the previous call (if any).
1871 /// 3. Copy a pointer to destructions function to field destructions of the
1872 /// resulting structure kmp_task_t.
1873 /// 4. Emit a call to void __kmpc_taskloop(ident_t *loc, int gtid, kmp_task_t
1874 /// *task, int if_val, kmp_uint64 *lb, kmp_uint64 *ub, kmp_int64 st, int
1875 /// nogroup, int sched, kmp_uint64 grainsize, void *task_dup ), where new_task
1876 /// is a resulting structure from
1877 /// previous items.
1878 /// \param D Current task directive.
1879 /// \param TaskFunction An LLVM function with type void (*)(i32 /*gtid*/, i32
1880 /// /*part_id*/, captured_struct */*__context*/);
1881 /// \param SharedsTy A type which contains references the shared variables.
1882 /// \param Shareds Context with the list of shared variables from the \p
1883 /// TaskFunction.
1884 /// \param IfCond Not a nullptr if 'if' clause was specified, nullptr
1885 /// otherwise.
1886 /// \param Data Additional data for task generation like tiednsee, final
1887 /// state, list of privates etc.
1888 void emitTaskLoopCall(CodeGenFunction &CGF, SourceLocation Loc,
1889 const OMPLoopDirective &D, llvm::Value *TaskFunction,
1890 QualType SharedsTy, Address Shareds, const Expr *IfCond,
1891 const OMPTaskDataTy &Data) override;
1892
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001893 /// Emit a code for reduction clause. Next code should be emitted for
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00001894 /// reduction:
1895 /// \code
1896 ///
1897 /// static kmp_critical_name lock = { 0 };
1898 ///
1899 /// void reduce_func(void *lhs[<n>], void *rhs[<n>]) {
1900 /// ...
1901 /// *(Type<i>*)lhs[i] = RedOp<i>(*(Type<i>*)lhs[i], *(Type<i>*)rhs[i]);
1902 /// ...
1903 /// }
1904 ///
1905 /// ...
1906 /// void *RedList[<n>] = {&<RHSExprs>[0], ..., &<RHSExprs>[<n>-1]};
1907 /// switch (__kmpc_reduce{_nowait}(<loc>, <gtid>, <n>, sizeof(RedList),
1908 /// RedList, reduce_func, &<lock>)) {
1909 /// case 1:
1910 /// ...
1911 /// <LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]);
1912 /// ...
1913 /// __kmpc_end_reduce{_nowait}(<loc>, <gtid>, &<lock>);
1914 /// break;
1915 /// case 2:
1916 /// ...
1917 /// Atomic(<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]));
1918 /// ...
1919 /// break;
1920 /// default:;
1921 /// }
1922 /// \endcode
1923 ///
1924 /// \param Privates List of private copies for original reduction arguments.
1925 /// \param LHSExprs List of LHS in \a ReductionOps reduction operations.
1926 /// \param RHSExprs List of RHS in \a ReductionOps reduction operations.
1927 /// \param ReductionOps List of reduction operations in form 'LHS binop RHS'
1928 /// or 'operator binop(LHS, RHS)'.
1929 /// \param Options List of options for reduction codegen:
1930 /// WithNowait true if parent directive has also nowait clause, false
1931 /// otherwise.
1932 /// SimpleReduction Emit reduction operation only. Used for omp simd
1933 /// directive on the host.
1934 /// ReductionKind The kind of reduction to perform.
1935 void emitReduction(CodeGenFunction &CGF, SourceLocation Loc,
1936 ArrayRef<const Expr *> Privates,
1937 ArrayRef<const Expr *> LHSExprs,
1938 ArrayRef<const Expr *> RHSExprs,
1939 ArrayRef<const Expr *> ReductionOps,
1940 ReductionOptionsTy Options) override;
1941
1942 /// Emit a code for initialization of task reduction clause. Next code
1943 /// should be emitted for reduction:
1944 /// \code
1945 ///
1946 /// _task_red_item_t red_data[n];
1947 /// ...
1948 /// red_data[i].shar = &origs[i];
1949 /// red_data[i].size = sizeof(origs[i]);
1950 /// red_data[i].f_init = (void*)RedInit<i>;
1951 /// red_data[i].f_fini = (void*)RedDest<i>;
1952 /// red_data[i].f_comb = (void*)RedOp<i>;
1953 /// red_data[i].flags = <Flag_i>;
1954 /// ...
1955 /// void* tg1 = __kmpc_task_reduction_init(gtid, n, red_data);
1956 /// \endcode
1957 ///
1958 /// \param LHSExprs List of LHS in \a Data.ReductionOps reduction operations.
1959 /// \param RHSExprs List of RHS in \a Data.ReductionOps reduction operations.
1960 /// \param Data Additional data for task generation like tiedness, final
1961 /// state, list of privates, reductions etc.
1962 llvm::Value *emitTaskReductionInit(CodeGenFunction &CGF, SourceLocation Loc,
1963 ArrayRef<const Expr *> LHSExprs,
1964 ArrayRef<const Expr *> RHSExprs,
1965 const OMPTaskDataTy &Data) override;
1966
1967 /// Required to resolve existing problems in the runtime. Emits threadprivate
1968 /// variables to store the size of the VLAs/array sections for
1969 /// initializer/combiner/finalizer functions + emits threadprivate variable to
1970 /// store the pointer to the original reduction item for the custom
1971 /// initializer defined by declare reduction construct.
1972 /// \param RCG Allows to reuse an existing data for the reductions.
1973 /// \param N Reduction item for which fixups must be emitted.
1974 void emitTaskReductionFixups(CodeGenFunction &CGF, SourceLocation Loc,
1975 ReductionCodeGen &RCG, unsigned N) override;
1976
1977 /// Get the address of `void *` type of the privatue copy of the reduction
1978 /// item specified by the \p SharedLVal.
1979 /// \param ReductionsPtr Pointer to the reduction data returned by the
1980 /// emitTaskReductionInit function.
1981 /// \param SharedLVal Address of the original reduction item.
1982 Address getTaskReductionItem(CodeGenFunction &CGF, SourceLocation Loc,
1983 llvm::Value *ReductionsPtr,
1984 LValue SharedLVal) override;
1985
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001986 /// Emit code for 'taskwait' directive.
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00001987 void emitTaskwaitCall(CodeGenFunction &CGF, SourceLocation Loc) override;
1988
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001989 /// Emit code for 'cancellation point' construct.
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00001990 /// \param CancelRegion Region kind for which the cancellation point must be
1991 /// emitted.
1992 ///
1993 void emitCancellationPointCall(CodeGenFunction &CGF, SourceLocation Loc,
1994 OpenMPDirectiveKind CancelRegion) override;
1995
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001996 /// Emit code for 'cancel' construct.
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00001997 /// \param IfCond Condition in the associated 'if' clause, if it was
1998 /// specified, nullptr otherwise.
1999 /// \param CancelRegion Region kind for which the cancel must be emitted.
2000 ///
2001 void emitCancelCall(CodeGenFunction &CGF, SourceLocation Loc,
2002 const Expr *IfCond,
2003 OpenMPDirectiveKind CancelRegion) override;
2004
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002005 /// Emit outilined function for 'target' directive.
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00002006 /// \param D Directive to emit.
2007 /// \param ParentName Name of the function that encloses the target region.
2008 /// \param OutlinedFn Outlined function value to be defined by this call.
2009 /// \param OutlinedFnID Outlined function ID value to be defined by this call.
2010 /// \param IsOffloadEntry True if the outlined function is an offload entry.
2011 /// \param CodeGen Code generation sequence for the \a D directive.
2012 /// An outlined function may not be an entry if, e.g. the if clause always
2013 /// evaluates to false.
2014 void emitTargetOutlinedFunction(const OMPExecutableDirective &D,
2015 StringRef ParentName,
2016 llvm::Function *&OutlinedFn,
2017 llvm::Constant *&OutlinedFnID,
2018 bool IsOffloadEntry,
2019 const RegionCodeGenTy &CodeGen) override;
2020
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002021 /// Emit the target offloading code associated with \a D. The emitted
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00002022 /// code attempts offloading the execution to the device, an the event of
2023 /// a failure it executes the host version outlined in \a OutlinedFn.
2024 /// \param D Directive to emit.
2025 /// \param OutlinedFn Host version of the code to be offloaded.
2026 /// \param OutlinedFnID ID of host version of the code to be offloaded.
2027 /// \param IfCond Expression evaluated in if clause associated with the target
2028 /// directive, or null if no if clause is used.
2029 /// \param Device Expression evaluated in device clause associated with the
2030 /// target directive, or null if no device clause is used.
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00002031 void emitTargetCall(CodeGenFunction &CGF, const OMPExecutableDirective &D,
2032 llvm::Value *OutlinedFn, llvm::Value *OutlinedFnID,
Alexey Bataev8451efa2018-01-15 19:06:12 +00002033 const Expr *IfCond, const Expr *Device) override;
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00002034
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002035 /// Emit the target regions enclosed in \a GD function definition or
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00002036 /// the function itself in case it is a valid device function. Returns true if
2037 /// \a GD was dealt with successfully.
2038 /// \param GD Function to scan.
2039 bool emitTargetFunctions(GlobalDecl GD) override;
2040
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002041 /// Emit the global variable if it is a valid device global variable.
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00002042 /// Returns true if \a GD was dealt with successfully.
2043 /// \param GD Variable declaration to emit.
2044 bool emitTargetGlobalVariable(GlobalDecl GD) override;
2045
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002046 /// Emit the global \a GD if it is meaningful for the target. Returns
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00002047 /// if it was emitted successfully.
2048 /// \param GD Global to scan.
2049 bool emitTargetGlobal(GlobalDecl GD) override;
2050
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002051 /// Creates the offloading descriptor in the event any target region
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00002052 /// was emitted in the current module and return the function that registers
2053 /// it.
2054 llvm::Function *emitRegistrationFunction() override;
2055
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002056 /// Emits code for teams call of the \a OutlinedFn with
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00002057 /// variables captured in a record which address is stored in \a
2058 /// CapturedStruct.
2059 /// \param OutlinedFn Outlined function to be run by team masters. Type of
2060 /// this function is void(*)(kmp_int32 *, kmp_int32, struct context_vars*).
2061 /// \param CapturedVars A pointer to the record with the references to
2062 /// variables used in \a OutlinedFn function.
2063 ///
2064 void emitTeamsCall(CodeGenFunction &CGF, const OMPExecutableDirective &D,
2065 SourceLocation Loc, llvm::Value *OutlinedFn,
2066 ArrayRef<llvm::Value *> CapturedVars) override;
2067
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002068 /// Emits call to void __kmpc_push_num_teams(ident_t *loc, kmp_int32
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00002069 /// global_tid, kmp_int32 num_teams, kmp_int32 thread_limit) to generate code
2070 /// for num_teams clause.
2071 /// \param NumTeams An integer expression of teams.
2072 /// \param ThreadLimit An integer expression of threads.
2073 void emitNumTeamsClause(CodeGenFunction &CGF, const Expr *NumTeams,
2074 const Expr *ThreadLimit, SourceLocation Loc) override;
2075
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002076 /// Emit the target data mapping code associated with \a D.
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00002077 /// \param D Directive to emit.
2078 /// \param IfCond Expression evaluated in if clause associated with the
2079 /// target directive, or null if no device clause is used.
2080 /// \param Device Expression evaluated in device clause associated with the
2081 /// target directive, or null if no device clause is used.
2082 /// \param Info A record used to store information that needs to be preserved
2083 /// until the region is closed.
2084 void emitTargetDataCalls(CodeGenFunction &CGF,
2085 const OMPExecutableDirective &D, const Expr *IfCond,
2086 const Expr *Device, const RegionCodeGenTy &CodeGen,
2087 TargetDataInfo &Info) override;
2088
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002089 /// Emit the data mapping/movement code associated with the directive
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00002090 /// \a D that should be of the form 'target [{enter|exit} data | update]'.
2091 /// \param D Directive to emit.
2092 /// \param IfCond Expression evaluated in if clause associated with the target
2093 /// directive, or null if no if clause is used.
2094 /// \param Device Expression evaluated in device clause associated with the
2095 /// target directive, or null if no device clause is used.
2096 void emitTargetDataStandAloneCall(CodeGenFunction &CGF,
2097 const OMPExecutableDirective &D,
2098 const Expr *IfCond,
2099 const Expr *Device) override;
2100
2101 /// Emit initialization for doacross loop nesting support.
2102 /// \param D Loop-based construct used in doacross nesting construct.
Alexey Bataevf138fda2018-08-13 19:04:24 +00002103 void emitDoacrossInit(CodeGenFunction &CGF, const OMPLoopDirective &D,
2104 ArrayRef<Expr *> NumIterations) override;
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00002105
2106 /// Emit code for doacross ordered directive with 'depend' clause.
2107 /// \param C 'depend' clause with 'sink|source' dependency kind.
2108 void emitDoacrossOrdered(CodeGenFunction &CGF,
2109 const OMPDependClause *C) override;
2110
2111 /// Translates the native parameter of outlined function if this is required
2112 /// for target.
Alexander Kornienko2a8c18d2018-04-06 15:14:32 +00002113 /// \param FD Field decl from captured record for the parameter.
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00002114 /// \param NativeParam Parameter itself.
2115 const VarDecl *translateParameter(const FieldDecl *FD,
2116 const VarDecl *NativeParam) const override;
2117
2118 /// Gets the address of the native argument basing on the address of the
2119 /// target-specific parameter.
2120 /// \param NativeParam Parameter itself.
2121 /// \param TargetParam Corresponding target-specific parameter.
2122 Address getParameterAddress(CodeGenFunction &CGF, const VarDecl *NativeParam,
2123 const VarDecl *TargetParam) const override;
2124};
2125
Alexey Bataev23b69422014-06-18 07:08:49 +00002126} // namespace CodeGen
2127} // namespace clang
Alexey Bataev9959db52014-05-06 10:08:46 +00002128
2129#endif