blob: 489ecdf15e1aa55367f50dc88b2057c76286e091 [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
Alexey Bataevceeaa482018-11-21 21:04:34 +0000285 /// Check if the default location must be constant.
286 /// Default is false to support OMPT/OMPD.
287 virtual bool isDefaultLocationConstant() const { return false; }
288
289 /// Returns additional flags that can be stored in reserved_2 field of the
290 /// default location.
291 virtual unsigned getDefaultLocationReserved2Flags() const { return 0; }
292
Arpith Chacko Jacob5c309e42016-03-22 01:48:56 +0000293private:
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000294 /// Default const ident_t object used for initialization of all other
Alexey Bataev9959db52014-05-06 10:08:46 +0000295 /// ident_t objects.
Alexey Bataevc5b1d322016-03-04 09:22:22 +0000296 llvm::Constant *DefaultOpenMPPSource = nullptr;
Alexey Bataevceeaa482018-11-21 21:04:34 +0000297 using FlagsTy = std::pair<unsigned, unsigned>;
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000298 /// Map of flags and corresponding default locations.
Alexey Bataevceeaa482018-11-21 21:04:34 +0000299 using OpenMPDefaultLocMapTy = llvm::DenseMap<FlagsTy, llvm::Value *>;
Alexey Bataev15007ba2014-05-07 06:18:01 +0000300 OpenMPDefaultLocMapTy OpenMPDefaultLocMap;
Alexey Bataev50b3c952016-02-19 10:38:26 +0000301 Address getOrCreateDefaultLocation(unsigned Flags);
John McCall7f416cc2015-09-08 08:05:57 +0000302
Alexey Bataeva4fa0b82018-04-16 17:59:34 +0000303 QualType IdentQTy;
Alexey Bataev14fa1c62016-03-29 05:34:15 +0000304 llvm::StructType *IdentTy = nullptr;
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000305 /// Map for SourceLocation and OpenMP runtime library debug locations.
Alexey Bataevf002aca2014-05-30 05:48:40 +0000306 typedef llvm::DenseMap<unsigned, llvm::Value *> OpenMPDebugLocMapTy;
307 OpenMPDebugLocMapTy OpenMPDebugLocMap;
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000308 /// The type for a microtask which gets passed to __kmpc_fork_call().
Alexey Bataev9959db52014-05-06 10:08:46 +0000309 /// Original representation is:
310 /// typedef void (kmpc_micro)(kmp_int32 global_tid, kmp_int32 bound_tid,...);
Alexey Bataev14fa1c62016-03-29 05:34:15 +0000311 llvm::FunctionType *Kmpc_MicroTy = nullptr;
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000312 /// Stores debug location and ThreadID for the function.
Alexey Bataev18095712014-10-10 12:19:54 +0000313 struct DebugLocThreadIdTy {
314 llvm::Value *DebugLoc;
315 llvm::Value *ThreadID;
Alexey Bataevfd006c42018-10-05 15:08:53 +0000316 /// Insert point for the service instructions.
317 llvm::AssertingVH<llvm::Instruction> ServiceInsertPt = nullptr;
Alexey Bataev18095712014-10-10 12:19:54 +0000318 };
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000319 /// Map of local debug location, ThreadId and functions.
Alexey Bataev18095712014-10-10 12:19:54 +0000320 typedef llvm::DenseMap<llvm::Function *, DebugLocThreadIdTy>
321 OpenMPLocThreadIDMapTy;
322 OpenMPLocThreadIDMapTy OpenMPLocThreadIDMap;
Alexey Bataevc5b1d322016-03-04 09:22:22 +0000323 /// Map of UDRs and corresponding combiner/initializer.
324 typedef llvm::DenseMap<const OMPDeclareReductionDecl *,
325 std::pair<llvm::Function *, llvm::Function *>>
326 UDRMapTy;
327 UDRMapTy UDRMap;
328 /// Map of functions and locally defined UDRs.
329 typedef llvm::DenseMap<llvm::Function *,
330 SmallVector<const OMPDeclareReductionDecl *, 4>>
331 FunctionUDRMapTy;
332 FunctionUDRMapTy FunctionUDRMap;
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000333 /// Type kmp_critical_name, originally defined as typedef kmp_int32
Alexey Bataev3a3bf0b2014-09-22 10:01:53 +0000334 /// kmp_critical_name[8];
335 llvm::ArrayType *KmpCriticalNameTy;
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000336 /// An ordered map of auto-generated variables to their unique names.
Alexey Bataev97720002014-11-11 04:05:39 +0000337 /// It stores variables with the following names: 1) ".gomp_critical_user_" +
338 /// <critical_section_name> + ".var" for "omp critical" directives; 2)
339 /// <mangled_name_for_global_var> + ".cache." for cache for threadprivate
340 /// variables.
341 llvm::StringMap<llvm::AssertingVH<llvm::Constant>, llvm::BumpPtrAllocator>
342 InternalVars;
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000343 /// Type typedef kmp_int32 (* kmp_routine_entry_t)(kmp_int32, void *);
Alexey Bataevc5b1d322016-03-04 09:22:22 +0000344 llvm::Type *KmpRoutineEntryPtrTy = nullptr;
Alexey Bataev62b63b12015-03-10 07:28:44 +0000345 QualType KmpRoutineEntryPtrQTy;
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000346 /// Type typedef struct kmp_task {
Alexey Bataev8fc69dc2015-05-18 07:54:53 +0000347 /// void * shareds; /**< pointer to block of pointers to
348 /// shared vars */
349 /// kmp_routine_entry_t routine; /**< pointer to routine to call for
350 /// executing task */
351 /// kmp_int32 part_id; /**< part id for the task */
352 /// kmp_routine_entry_t destructors; /* pointer to function to invoke
353 /// deconstructors of firstprivate C++ objects */
354 /// } kmp_task_t;
355 QualType KmpTaskTQTy;
Alexey Bataeve213f3e2017-10-11 15:29:40 +0000356 /// Saved kmp_task_t for task directive.
357 QualType SavedKmpTaskTQTy;
358 /// Saved kmp_task_t for taskloop-based directive.
359 QualType SavedKmpTaskloopTQTy;
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000360 /// Type typedef struct kmp_depend_info {
Alexey Bataev1d2353d2015-06-24 11:01:36 +0000361 /// kmp_intptr_t base_addr;
362 /// size_t len;
363 /// struct {
364 /// bool in:1;
365 /// bool out:1;
366 /// } flags;
367 /// } kmp_depend_info_t;
368 QualType KmpDependInfoTy;
Alexey Bataev8b427062016-05-25 12:36:08 +0000369 /// struct kmp_dim { // loop bounds info casted to kmp_int64
370 /// kmp_int64 lo; // lower
371 /// kmp_int64 up; // upper
372 /// kmp_int64 st; // stride
373 /// };
374 QualType KmpDimTy;
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000375 /// Type struct __tgt_offload_entry{
Samuel Antaoee8fb302016-01-06 13:42:12 +0000376 /// void *addr; // Pointer to the offload entry info.
377 /// // (function or global)
378 /// char *name; // Name of the function or global.
379 /// size_t size; // Size of the entry info (0 if it a function).
380 /// };
381 QualType TgtOffloadEntryQTy;
382 /// struct __tgt_device_image{
383 /// void *ImageStart; // Pointer to the target code start.
384 /// void *ImageEnd; // Pointer to the target code end.
385 /// // We also add the host entries to the device image, as it may be useful
386 /// // for the target runtime to have access to that information.
387 /// __tgt_offload_entry *EntriesBegin; // Begin of the table with all
388 /// // the entries.
389 /// __tgt_offload_entry *EntriesEnd; // End of the table with all the
390 /// // entries (non inclusive).
391 /// };
392 QualType TgtDeviceImageQTy;
393 /// struct __tgt_bin_desc{
394 /// int32_t NumDevices; // Number of devices supported.
395 /// __tgt_device_image *DeviceImages; // Arrays of device images
396 /// // (one per device).
397 /// __tgt_offload_entry *EntriesBegin; // Begin of the table with all the
398 /// // entries.
399 /// __tgt_offload_entry *EntriesEnd; // End of the table with all the
400 /// // entries (non inclusive).
401 /// };
402 QualType TgtBinaryDescriptorQTy;
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000403 /// Entity that registers the offloading constants that were emitted so
Samuel Antaoee8fb302016-01-06 13:42:12 +0000404 /// far.
405 class OffloadEntriesInfoManagerTy {
406 CodeGenModule &CGM;
Alexey Bataev1d2353d2015-06-24 11:01:36 +0000407
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000408 /// Number of entries registered so far.
Alexey Bataev03f270c2018-03-30 18:31:07 +0000409 unsigned OffloadingEntriesNum = 0;
Samuel Antaoee8fb302016-01-06 13:42:12 +0000410
411 public:
Samuel Antaof83efdb2017-01-05 16:02:49 +0000412 /// Base class of the entries info.
Samuel Antaoee8fb302016-01-06 13:42:12 +0000413 class OffloadEntryInfo {
414 public:
Alexey Bataev34f8a702018-03-28 14:28:54 +0000415 /// Kind of a given entry.
Reid Klecknerdc78f952016-01-11 20:55:16 +0000416 enum OffloadingEntryInfoKinds : unsigned {
Alexey Bataev34f8a702018-03-28 14:28:54 +0000417 /// Entry is a target region.
418 OffloadingEntryInfoTargetRegion = 0,
Alexey Bataev03f270c2018-03-30 18:31:07 +0000419 /// Entry is a declare target variable.
420 OffloadingEntryInfoDeviceGlobalVar = 1,
Alexey Bataev34f8a702018-03-28 14:28:54 +0000421 /// Invalid entry info.
422 OffloadingEntryInfoInvalid = ~0u
Samuel Antaoee8fb302016-01-06 13:42:12 +0000423 };
424
Alexey Bataev03f270c2018-03-30 18:31:07 +0000425 protected:
426 OffloadEntryInfo() = delete;
427 explicit OffloadEntryInfo(OffloadingEntryInfoKinds Kind) : Kind(Kind) {}
Samuel Antaof83efdb2017-01-05 16:02:49 +0000428 explicit OffloadEntryInfo(OffloadingEntryInfoKinds Kind, unsigned Order,
Alexey Bataev03f270c2018-03-30 18:31:07 +0000429 uint32_t Flags)
Samuel Antaof83efdb2017-01-05 16:02:49 +0000430 : Flags(Flags), Order(Order), Kind(Kind) {}
Alexey Bataev03f270c2018-03-30 18:31:07 +0000431 ~OffloadEntryInfo() = default;
Samuel Antaoee8fb302016-01-06 13:42:12 +0000432
Alexey Bataev03f270c2018-03-30 18:31:07 +0000433 public:
Samuel Antaoee8fb302016-01-06 13:42:12 +0000434 bool isValid() const { return Order != ~0u; }
435 unsigned getOrder() const { return Order; }
436 OffloadingEntryInfoKinds getKind() const { return Kind; }
Alexey Bataev03f270c2018-03-30 18:31:07 +0000437 uint32_t getFlags() const { return Flags; }
438 void setFlags(uint32_t NewFlags) { Flags = NewFlags; }
439 llvm::Constant *getAddress() const {
440 return cast_or_null<llvm::Constant>(Addr);
441 }
442 void setAddress(llvm::Constant *V) {
443 assert(!Addr.pointsToAliveValue() && "Address has been set before!");
444 Addr = V;
445 }
Samuel Antaoee8fb302016-01-06 13:42:12 +0000446 static bool classof(const OffloadEntryInfo *Info) { return true; }
447
Samuel Antaof83efdb2017-01-05 16:02:49 +0000448 private:
Alexey Bataev03f270c2018-03-30 18:31:07 +0000449 /// Address of the entity that has to be mapped for offloading.
450 llvm::WeakTrackingVH Addr;
451
Samuel Antaof83efdb2017-01-05 16:02:49 +0000452 /// Flags associated with the device global.
Alexey Bataev03f270c2018-03-30 18:31:07 +0000453 uint32_t Flags = 0u;
Samuel Antaof83efdb2017-01-05 16:02:49 +0000454
455 /// Order this entry was emitted.
Alexey Bataev03f270c2018-03-30 18:31:07 +0000456 unsigned Order = ~0u;
Samuel Antaoee8fb302016-01-06 13:42:12 +0000457
Alexey Bataev03f270c2018-03-30 18:31:07 +0000458 OffloadingEntryInfoKinds Kind = OffloadingEntryInfoInvalid;
Samuel Antaoee8fb302016-01-06 13:42:12 +0000459 };
460
Alexey Bataev03f270c2018-03-30 18:31:07 +0000461 /// Return true if a there are no entries defined.
Samuel Antaoee8fb302016-01-06 13:42:12 +0000462 bool empty() const;
Alexey Bataev03f270c2018-03-30 18:31:07 +0000463 /// Return number of entries defined so far.
Samuel Antaoee8fb302016-01-06 13:42:12 +0000464 unsigned size() const { return OffloadingEntriesNum; }
Alexey Bataev03f270c2018-03-30 18:31:07 +0000465 OffloadEntriesInfoManagerTy(CodeGenModule &CGM) : CGM(CGM) {}
Samuel Antaoee8fb302016-01-06 13:42:12 +0000466
Alexey Bataev03f270c2018-03-30 18:31:07 +0000467 //
468 // Target region entries related.
469 //
470
471 /// Kind of the target registry entry.
472 enum OMPTargetRegionEntryKind : uint32_t {
473 /// Mark the entry as target region.
474 OMPTargetRegionEntryTargetRegion = 0x0,
475 /// Mark the entry as a global constructor.
476 OMPTargetRegionEntryCtor = 0x02,
477 /// Mark the entry as a global destructor.
478 OMPTargetRegionEntryDtor = 0x04,
479 };
480
481 /// Target region entries info.
482 class OffloadEntryInfoTargetRegion final : public OffloadEntryInfo {
483 /// Address that can be used as the ID of the entry.
484 llvm::Constant *ID = nullptr;
Samuel Antaoee8fb302016-01-06 13:42:12 +0000485
486 public:
487 OffloadEntryInfoTargetRegion()
Alexey Bataev03f270c2018-03-30 18:31:07 +0000488 : OffloadEntryInfo(OffloadingEntryInfoTargetRegion) {}
Samuel Antaoee8fb302016-01-06 13:42:12 +0000489 explicit OffloadEntryInfoTargetRegion(unsigned Order,
490 llvm::Constant *Addr,
Alexey Bataev34f8a702018-03-28 14:28:54 +0000491 llvm::Constant *ID,
492 OMPTargetRegionEntryKind Flags)
493 : OffloadEntryInfo(OffloadingEntryInfoTargetRegion, Order, Flags),
Alexey Bataev03f270c2018-03-30 18:31:07 +0000494 ID(ID) {
495 setAddress(Addr);
Samuel Antaoee8fb302016-01-06 13:42:12 +0000496 }
Alexey Bataev03f270c2018-03-30 18:31:07 +0000497
498 llvm::Constant *getID() const { return ID; }
Samuel Antaoee8fb302016-01-06 13:42:12 +0000499 void setID(llvm::Constant *V) {
Alexey Bataev34f8a702018-03-28 14:28:54 +0000500 assert(!ID && "ID has been set before!");
Samuel Antaoee8fb302016-01-06 13:42:12 +0000501 ID = V;
502 }
503 static bool classof(const OffloadEntryInfo *Info) {
Alexey Bataev34f8a702018-03-28 14:28:54 +0000504 return Info->getKind() == OffloadingEntryInfoTargetRegion;
Samuel Antaoee8fb302016-01-06 13:42:12 +0000505 }
506 };
Alexey Bataev03f270c2018-03-30 18:31:07 +0000507
508 /// Initialize target region entry.
Samuel Antaoee8fb302016-01-06 13:42:12 +0000509 void initializeTargetRegionEntryInfo(unsigned DeviceID, unsigned FileID,
510 StringRef ParentName, unsigned LineNum,
Samuel Antao2de62b02016-02-13 23:35:10 +0000511 unsigned Order);
Alexey Bataev03f270c2018-03-30 18:31:07 +0000512 /// Register target region entry.
Samuel Antaoee8fb302016-01-06 13:42:12 +0000513 void registerTargetRegionEntryInfo(unsigned DeviceID, unsigned FileID,
514 StringRef ParentName, unsigned LineNum,
Samuel Antaof83efdb2017-01-05 16:02:49 +0000515 llvm::Constant *Addr, llvm::Constant *ID,
Alexey Bataev34f8a702018-03-28 14:28:54 +0000516 OMPTargetRegionEntryKind Flags);
Alexey Bataev03f270c2018-03-30 18:31:07 +0000517 /// Return true if a target region entry with the provided information
518 /// exists.
Samuel Antaoee8fb302016-01-06 13:42:12 +0000519 bool hasTargetRegionEntryInfo(unsigned DeviceID, unsigned FileID,
Samuel Antao2de62b02016-02-13 23:35:10 +0000520 StringRef ParentName, unsigned LineNum) const;
Samuel Antaoee8fb302016-01-06 13:42:12 +0000521 /// brief Applies action \a Action on all registered entries.
522 typedef llvm::function_ref<void(unsigned, unsigned, StringRef, unsigned,
Alexey Bataev03f270c2018-03-30 18:31:07 +0000523 const OffloadEntryInfoTargetRegion &)>
Samuel Antaoee8fb302016-01-06 13:42:12 +0000524 OffloadTargetRegionEntryInfoActTy;
525 void actOnTargetRegionEntriesInfo(
526 const OffloadTargetRegionEntryInfoActTy &Action);
527
Alexey Bataev03f270c2018-03-30 18:31:07 +0000528 //
529 // Device global variable entries related.
530 //
531
532 /// Kind of the global variable entry..
533 enum OMPTargetGlobalVarEntryKind : uint32_t {
534 /// Mark the entry as a to declare target.
535 OMPTargetGlobalVarEntryTo = 0x0,
Alexey Bataevc52f01d2018-07-16 20:05:25 +0000536 /// Mark the entry as a to declare target link.
537 OMPTargetGlobalVarEntryLink = 0x1,
Alexey Bataev03f270c2018-03-30 18:31:07 +0000538 };
539
540 /// Device global variable entries info.
541 class OffloadEntryInfoDeviceGlobalVar final : public OffloadEntryInfo {
542 /// Type of the global variable.
543 CharUnits VarSize;
544 llvm::GlobalValue::LinkageTypes Linkage;
545
546 public:
547 OffloadEntryInfoDeviceGlobalVar()
548 : OffloadEntryInfo(OffloadingEntryInfoDeviceGlobalVar) {}
549 explicit OffloadEntryInfoDeviceGlobalVar(unsigned Order,
550 OMPTargetGlobalVarEntryKind Flags)
551 : OffloadEntryInfo(OffloadingEntryInfoDeviceGlobalVar, Order, Flags) {}
552 explicit OffloadEntryInfoDeviceGlobalVar(
553 unsigned Order, llvm::Constant *Addr, CharUnits VarSize,
554 OMPTargetGlobalVarEntryKind Flags,
555 llvm::GlobalValue::LinkageTypes Linkage)
556 : OffloadEntryInfo(OffloadingEntryInfoDeviceGlobalVar, Order, Flags),
557 VarSize(VarSize), Linkage(Linkage) {
558 setAddress(Addr);
559 }
560
561 CharUnits getVarSize() const { return VarSize; }
562 void setVarSize(CharUnits Size) { VarSize = Size; }
563 llvm::GlobalValue::LinkageTypes getLinkage() const { return Linkage; }
564 void setLinkage(llvm::GlobalValue::LinkageTypes LT) { Linkage = LT; }
565 static bool classof(const OffloadEntryInfo *Info) {
566 return Info->getKind() == OffloadingEntryInfoDeviceGlobalVar;
567 }
568 };
569
570 /// Initialize device global variable entry.
571 void initializeDeviceGlobalVarEntryInfo(StringRef Name,
572 OMPTargetGlobalVarEntryKind Flags,
573 unsigned Order);
574
575 /// Register device global variable entry.
576 void
577 registerDeviceGlobalVarEntryInfo(StringRef VarName, llvm::Constant *Addr,
578 CharUnits VarSize,
579 OMPTargetGlobalVarEntryKind Flags,
580 llvm::GlobalValue::LinkageTypes Linkage);
581 /// Checks if the variable with the given name has been registered already.
582 bool hasDeviceGlobalVarEntryInfo(StringRef VarName) const {
583 return OffloadEntriesDeviceGlobalVar.count(VarName) > 0;
584 }
585 /// Applies action \a Action on all registered entries.
586 typedef llvm::function_ref<void(StringRef,
587 const OffloadEntryInfoDeviceGlobalVar &)>
588 OffloadDeviceGlobalVarEntryInfoActTy;
589 void actOnDeviceGlobalVarEntriesInfo(
590 const OffloadDeviceGlobalVarEntryInfoActTy &Action);
591
Samuel Antaoee8fb302016-01-06 13:42:12 +0000592 private:
593 // Storage for target region entries kind. The storage is to be indexed by
Samuel Antao2de62b02016-02-13 23:35:10 +0000594 // file ID, device ID, parent function name and line number.
Samuel Antaoee8fb302016-01-06 13:42:12 +0000595 typedef llvm::DenseMap<unsigned, OffloadEntryInfoTargetRegion>
Samuel Antaoee8fb302016-01-06 13:42:12 +0000596 OffloadEntriesTargetRegionPerLine;
597 typedef llvm::StringMap<OffloadEntriesTargetRegionPerLine>
598 OffloadEntriesTargetRegionPerParentName;
599 typedef llvm::DenseMap<unsigned, OffloadEntriesTargetRegionPerParentName>
600 OffloadEntriesTargetRegionPerFile;
601 typedef llvm::DenseMap<unsigned, OffloadEntriesTargetRegionPerFile>
602 OffloadEntriesTargetRegionPerDevice;
603 typedef OffloadEntriesTargetRegionPerDevice OffloadEntriesTargetRegionTy;
604 OffloadEntriesTargetRegionTy OffloadEntriesTargetRegion;
Alexey Bataev03f270c2018-03-30 18:31:07 +0000605 /// Storage for device global variable entries kind. The storage is to be
606 /// indexed by mangled name.
607 typedef llvm::StringMap<OffloadEntryInfoDeviceGlobalVar>
608 OffloadEntriesDeviceGlobalVarTy;
609 OffloadEntriesDeviceGlobalVarTy OffloadEntriesDeviceGlobalVar;
Samuel Antaoee8fb302016-01-06 13:42:12 +0000610 };
611 OffloadEntriesInfoManagerTy OffloadEntriesInfoManager;
612
Alexey Bataev4f4bf7c2018-03-15 15:47:20 +0000613 bool ShouldMarkAsGlobal = true;
Alexey Bataev2a6f3f52018-11-07 19:11:14 +0000614 /// List of the emitted functions.
615 llvm::StringSet<> AlreadyEmittedTargetFunctions;
616 /// List of the global variables with their addresses that should not be
617 /// emitted for the target.
618 llvm::StringMap<llvm::WeakTrackingVH> EmittedNonTargetVariables;
Alexey Bataev4f4bf7c2018-03-15 15:47:20 +0000619
Alexey Bataevbf8fe712018-08-07 16:14:36 +0000620 /// List of variables that can become declare target implicitly and, thus,
621 /// must be emitted.
622 llvm::SmallDenseSet<const VarDecl *> DeferredGlobalVariables;
623
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000624 /// Creates and registers offloading binary descriptor for the current
Samuel Antaoee8fb302016-01-06 13:42:12 +0000625 /// compilation unit. The function that does the registration is returned.
626 llvm::Function *createOffloadingBinaryDescriptorRegistration();
627
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000628 /// Creates all the offload entries in the current compilation unit
Samuel Antaoee8fb302016-01-06 13:42:12 +0000629 /// along with the associated metadata.
630 void createOffloadEntriesAndInfoMetadata();
631
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000632 /// Loads all the offload entries information from the host IR
Samuel Antaoee8fb302016-01-06 13:42:12 +0000633 /// metadata.
634 void loadOffloadInfoMetadata();
635
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000636 /// Returns __tgt_offload_entry type.
Samuel Antaoee8fb302016-01-06 13:42:12 +0000637 QualType getTgtOffloadEntryQTy();
638
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000639 /// Returns __tgt_device_image type.
Samuel Antaoee8fb302016-01-06 13:42:12 +0000640 QualType getTgtDeviceImageQTy();
641
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000642 /// Returns __tgt_bin_desc type.
Samuel Antaoee8fb302016-01-06 13:42:12 +0000643 QualType getTgtBinaryDescriptorQTy();
644
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000645 /// Start scanning from statement \a S and and emit all target regions
Samuel Antaoee8fb302016-01-06 13:42:12 +0000646 /// found along the way.
647 /// \param S Starting statement.
648 /// \param ParentName Name of the function declaration that is being scanned.
649 void scanForTargetRegionsFunctions(const Stmt *S, StringRef ParentName);
Alexey Bataev62b63b12015-03-10 07:28:44 +0000650
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000651 /// Build type kmp_routine_entry_t (if not built yet).
Alexey Bataev62b63b12015-03-10 07:28:44 +0000652 void emitKmpRoutineEntryT(QualType KmpInt32Ty);
Alexey Bataev9959db52014-05-06 10:08:46 +0000653
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000654 /// Returns pointer to kmpc_micro type.
Alexey Bataev9959db52014-05-06 10:08:46 +0000655 llvm::Type *getKmpc_MicroPointerTy();
656
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000657 /// Returns specified OpenMP runtime function.
Alexey Bataev9959db52014-05-06 10:08:46 +0000658 /// \param Function OpenMP runtime function.
659 /// \return Specified function.
Alexey Bataev50b3c952016-02-19 10:38:26 +0000660 llvm::Constant *createRuntimeFunction(unsigned Function);
Alexey Bataev3a3bf0b2014-09-22 10:01:53 +0000661
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000662 /// Returns __kmpc_for_static_init_* runtime function for the specified
Alexander Musman21212e42015-03-13 10:38:23 +0000663 /// size \a IVSize and sign \a IVSigned.
664 llvm::Constant *createForStaticInitFunction(unsigned IVSize, bool IVSigned);
665
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000666 /// Returns __kmpc_dispatch_init_* runtime function for the specified
Alexander Musman92bdaab2015-03-12 13:37:50 +0000667 /// size \a IVSize and sign \a IVSigned.
668 llvm::Constant *createDispatchInitFunction(unsigned IVSize, bool IVSigned);
669
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000670 /// Returns __kmpc_dispatch_next_* runtime function for the specified
Alexander Musman92bdaab2015-03-12 13:37:50 +0000671 /// size \a IVSize and sign \a IVSigned.
672 llvm::Constant *createDispatchNextFunction(unsigned IVSize, bool IVSigned);
673
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000674 /// Returns __kmpc_dispatch_fini_* runtime function for the specified
Alexey Bataev98eb6e32015-04-22 11:15:40 +0000675 /// size \a IVSize and sign \a IVSigned.
676 llvm::Constant *createDispatchFiniFunction(unsigned IVSize, bool IVSigned);
677
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000678 /// If the specified mangled name is not in the module, create and
Alexey Bataev97720002014-11-11 04:05:39 +0000679 /// return threadprivate cache object. This object is a pointer's worth of
680 /// storage that's reserved for use by the OpenMP runtime.
NAKAMURA Takumicdcbfba2014-11-11 07:58:06 +0000681 /// \param VD Threadprivate variable.
Alexey Bataev97720002014-11-11 04:05:39 +0000682 /// \return Cache variable for the specified threadprivate.
683 llvm::Constant *getOrCreateThreadPrivateCache(const VarDecl *VD);
684
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000685 /// Gets (if variable with the given name already exist) or creates
Alexey Bataev97720002014-11-11 04:05:39 +0000686 /// internal global variable with the specified Name. The created variable has
687 /// linkage CommonLinkage by default and is initialized by null value.
688 /// \param Ty Type of the global variable. If it is exist already the type
689 /// must be the same.
690 /// \param Name Name of the variable.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000691 llvm::Constant *getOrCreateInternalVariable(llvm::Type *Ty,
Alexey Bataev97720002014-11-11 04:05:39 +0000692 const llvm::Twine &Name);
693
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000694 /// Set of threadprivate variables with the generated initializer.
Alexey Bataev2a6f3f52018-11-07 19:11:14 +0000695 llvm::StringSet<> ThreadPrivateWithDefinition;
Alexey Bataev97720002014-11-11 04:05:39 +0000696
Alexey Bataev34f8a702018-03-28 14:28:54 +0000697 /// Set of declare target variables with the generated initializer.
Alexey Bataev2a6f3f52018-11-07 19:11:14 +0000698 llvm::StringSet<> DeclareTargetWithDefinition;
Alexey Bataev34f8a702018-03-28 14:28:54 +0000699
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000700 /// Emits initialization code for the threadprivate variables.
Alexey Bataev97720002014-11-11 04:05:39 +0000701 /// \param VDAddr Address of the global variable \a VD.
702 /// \param Ctor Pointer to a global init function for \a VD.
703 /// \param CopyCtor Pointer to a global copy function for \a VD.
704 /// \param Dtor Pointer to a global destructor function for \a VD.
705 /// \param Loc Location of threadprivate declaration.
John McCall7f416cc2015-09-08 08:05:57 +0000706 void emitThreadPrivateVarInit(CodeGenFunction &CGF, Address VDAddr,
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000707 llvm::Value *Ctor, llvm::Value *CopyCtor,
708 llvm::Value *Dtor, SourceLocation Loc);
Alexey Bataev97720002014-11-11 04:05:39 +0000709
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000710 /// Returns corresponding lock object for the specified critical region
Alexey Bataev75ddfab2014-12-01 11:32:38 +0000711 /// name. If the lock object does not exist it is created, otherwise the
712 /// reference to the existing copy is returned.
713 /// \param CriticalName Name of the critical region.
714 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000715 llvm::Value *getCriticalRegionLock(StringRef CriticalName);
Alexey Bataev75ddfab2014-12-01 11:32:38 +0000716
Alexey Bataev24b5bae2016-04-28 09:23:51 +0000717 struct TaskResultTy {
718 llvm::Value *NewTask = nullptr;
719 llvm::Value *TaskEntry = nullptr;
720 llvm::Value *NewTaskNewTaskTTy = nullptr;
Alexey Bataev7292c292016-04-25 12:22:29 +0000721 LValue TDBase;
Alexey Bataeva4fa0b82018-04-16 17:59:34 +0000722 const RecordDecl *KmpTaskTQTyRD = nullptr;
Alexey Bataevf93095a2016-05-05 08:46:22 +0000723 llvm::Value *TaskDupFn = nullptr;
Alexey Bataev7292c292016-04-25 12:22:29 +0000724 };
725 /// Emit task region for the task directive. The task region is emitted in
726 /// several steps:
727 /// 1. Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32
728 /// gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds,
729 /// kmp_routine_entry_t *task_entry). Here task_entry is a pointer to the
730 /// function:
731 /// kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) {
732 /// TaskFunction(gtid, tt->part_id, tt->shareds);
733 /// return 0;
734 /// }
735 /// 2. Copy a list of shared variables to field shareds of the resulting
736 /// structure kmp_task_t returned by the previous call (if any).
737 /// 3. Copy a pointer to destructions function to field destructions of the
738 /// resulting structure kmp_task_t.
739 /// \param D Current task directive.
Alexey Bataev7292c292016-04-25 12:22:29 +0000740 /// \param TaskFunction An LLVM function with type void (*)(i32 /*gtid*/, i32
741 /// /*part_id*/, captured_struct */*__context*/);
742 /// \param SharedsTy A type which contains references the shared variables.
743 /// \param Shareds Context with the list of shared variables from the \p
744 /// TaskFunction.
Alexey Bataev24b5bae2016-04-28 09:23:51 +0000745 /// \param Data Additional data for task generation like tiednsee, final
746 /// state, list of privates etc.
747 TaskResultTy emitTaskInit(CodeGenFunction &CGF, SourceLocation Loc,
748 const OMPExecutableDirective &D,
749 llvm::Value *TaskFunction, QualType SharedsTy,
750 Address Shareds, const OMPTaskDataTy &Data);
Alexey Bataev7292c292016-04-25 12:22:29 +0000751
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000752public:
Alexey Bataev18fa2322018-05-02 14:20:50 +0000753 explicit CGOpenMPRuntime(CodeGenModule &CGM)
754 : CGOpenMPRuntime(CGM, ".", ".") {}
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +0000755 virtual ~CGOpenMPRuntime() {}
Alexey Bataev91797552015-03-18 04:13:55 +0000756 virtual void clear();
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000757
Alexey Bataev18fa2322018-05-02 14:20:50 +0000758 /// Get the platform-specific name separator.
759 std::string getName(ArrayRef<StringRef> Parts) const;
760
Alexey Bataevc5b1d322016-03-04 09:22:22 +0000761 /// Emit code for the specified user defined reduction construct.
762 virtual void emitUserDefinedReduction(CodeGenFunction *CGF,
763 const OMPDeclareReductionDecl *D);
Alexey Bataeva839ddd2016-03-17 10:19:46 +0000764 /// Get combiner/initializer for the specified user-defined reduction, if any.
765 virtual std::pair<llvm::Function *, llvm::Function *>
766 getUserDefinedReduction(const OMPDeclareReductionDecl *D);
Arpith Chacko Jacob19b911c2017-01-18 18:18:53 +0000767
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000768 /// Emits outlined function for the specified OpenMP parallel directive
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000769 /// \a D. This outlined function has type void(*)(kmp_int32 *ThreadID,
770 /// kmp_int32 BoundID, struct context_vars*).
Alexey Bataev18095712014-10-10 12:19:54 +0000771 /// \param D OpenMP directive.
772 /// \param ThreadIDVar Variable for thread id in the current OpenMP region.
Alexey Bataev81c7ea02015-07-03 09:56:58 +0000773 /// \param InnermostKind Kind of innermost directive (for simple directives it
774 /// is a directive itself, for combined - its innermost directive).
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000775 /// \param CodeGen Code generation sequence for the \a D directive.
Arpith Chacko Jacob19b911c2017-01-18 18:18:53 +0000776 virtual llvm::Value *emitParallelOutlinedFunction(
777 const OMPExecutableDirective &D, const VarDecl *ThreadIDVar,
778 OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen);
779
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000780 /// Emits outlined function for the specified OpenMP teams directive
Arpith Chacko Jacob19b911c2017-01-18 18:18:53 +0000781 /// \a D. This outlined function has type void(*)(kmp_int32 *ThreadID,
782 /// kmp_int32 BoundID, struct context_vars*).
783 /// \param D OpenMP directive.
784 /// \param ThreadIDVar Variable for thread id in the current OpenMP region.
785 /// \param InnermostKind Kind of innermost directive (for simple directives it
786 /// is a directive itself, for combined - its innermost directive).
787 /// \param CodeGen Code generation sequence for the \a D directive.
788 virtual llvm::Value *emitTeamsOutlinedFunction(
Alexey Bataev81c7ea02015-07-03 09:56:58 +0000789 const OMPExecutableDirective &D, const VarDecl *ThreadIDVar,
790 OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen);
Alexey Bataev18095712014-10-10 12:19:54 +0000791
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000792 /// Emits outlined function for the OpenMP task directive \a D. This
Alexey Bataev48591dd2016-04-20 04:01:36 +0000793 /// outlined function has type void(*)(kmp_int32 ThreadID, struct task_t*
794 /// TaskT).
Alexey Bataev62b63b12015-03-10 07:28:44 +0000795 /// \param D OpenMP directive.
796 /// \param ThreadIDVar Variable for thread id in the current OpenMP region.
Alexey Bataev48591dd2016-04-20 04:01:36 +0000797 /// \param PartIDVar Variable for partition id in the current OpenMP untied
798 /// task region.
799 /// \param TaskTVar Variable for task_t argument.
Alexey Bataev81c7ea02015-07-03 09:56:58 +0000800 /// \param InnermostKind Kind of innermost directive (for simple directives it
801 /// is a directive itself, for combined - its innermost directive).
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000802 /// \param CodeGen Code generation sequence for the \a D directive.
Alexey Bataev48591dd2016-04-20 04:01:36 +0000803 /// \param Tied true if task is generated for tied task, false otherwise.
804 /// \param NumberOfParts Number of parts in untied task. Ignored for tied
805 /// tasks.
Alexey Bataev62b63b12015-03-10 07:28:44 +0000806 ///
Alexey Bataev81c7ea02015-07-03 09:56:58 +0000807 virtual llvm::Value *emitTaskOutlinedFunction(
808 const OMPExecutableDirective &D, const VarDecl *ThreadIDVar,
Alexey Bataev48591dd2016-04-20 04:01:36 +0000809 const VarDecl *PartIDVar, const VarDecl *TaskTVar,
810 OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen,
811 bool Tied, unsigned &NumberOfParts);
Alexey Bataev62b63b12015-03-10 07:28:44 +0000812
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000813 /// Cleans up references to the objects in finished function.
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000814 ///
Gheorghe-Teodor Bercead3dcf2f2018-03-14 14:17:45 +0000815 virtual void functionFinished(CodeGenFunction &CGF);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000816
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000817 /// Emits code for parallel or serial call of the \a OutlinedFn with
Alexey Bataev1d677132015-04-22 13:57:31 +0000818 /// variables captured in a record which address is stored in \a
819 /// CapturedStruct.
Alexey Bataev18095712014-10-10 12:19:54 +0000820 /// \param OutlinedFn Outlined function to be run in parallel threads. Type of
Alexey Bataev62b63b12015-03-10 07:28:44 +0000821 /// this function is void(*)(kmp_int32 *, kmp_int32, struct context_vars*).
NAKAMURA Takumi62f0eb52015-09-11 08:13:32 +0000822 /// \param CapturedVars A pointer to the record with the references to
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000823 /// variables used in \a OutlinedFn function.
Alexey Bataev1d677132015-04-22 13:57:31 +0000824 /// \param IfCond Condition in the associated 'if' clause, if it was
825 /// specified, nullptr otherwise.
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000826 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000827 virtual void emitParallelCall(CodeGenFunction &CGF, SourceLocation Loc,
828 llvm::Value *OutlinedFn,
Alexey Bataev2377fe92015-09-10 08:12:02 +0000829 ArrayRef<llvm::Value *> CapturedVars,
830 const Expr *IfCond);
Alexey Bataevd74d0602014-10-13 06:02:40 +0000831
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000832 /// Emits a critical region.
Alexey Bataev18095712014-10-10 12:19:54 +0000833 /// \param CriticalName Name of the critical region.
Alexey Bataev75ddfab2014-12-01 11:32:38 +0000834 /// \param CriticalOpGen Generator for the statement associated with the given
835 /// critical region.
Alexey Bataevfc57d162015-12-15 10:55:09 +0000836 /// \param Hint Value of the 'hint' clause (optional).
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000837 virtual void emitCriticalRegion(CodeGenFunction &CGF, StringRef CriticalName,
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000838 const RegionCodeGenTy &CriticalOpGen,
Alexey Bataevfc57d162015-12-15 10:55:09 +0000839 SourceLocation Loc,
840 const Expr *Hint = nullptr);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000841
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000842 /// Emits a master region.
Alexey Bataev8d690652014-12-04 07:23:53 +0000843 /// \param MasterOpGen Generator for the statement associated with the given
844 /// master region.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000845 virtual void emitMasterRegion(CodeGenFunction &CGF,
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000846 const RegionCodeGenTy &MasterOpGen,
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000847 SourceLocation Loc);
Alexey Bataev8d690652014-12-04 07:23:53 +0000848
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000849 /// Emits code for a taskyield directive.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000850 virtual void emitTaskyieldCall(CodeGenFunction &CGF, SourceLocation Loc);
Alexey Bataev9f797f32015-02-05 05:57:51 +0000851
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000852 /// Emit a taskgroup region.
Alexey Bataevc30dd2d2015-06-18 12:14:09 +0000853 /// \param TaskgroupOpGen Generator for the statement associated with the
854 /// given taskgroup region.
855 virtual void emitTaskgroupRegion(CodeGenFunction &CGF,
856 const RegionCodeGenTy &TaskgroupOpGen,
857 SourceLocation Loc);
858
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000859 /// Emits a single region.
Alexey Bataev6956e2e2015-02-05 06:35:41 +0000860 /// \param SingleOpGen Generator for the statement associated with the given
861 /// single region.
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000862 virtual void emitSingleRegion(CodeGenFunction &CGF,
Alexey Bataev6f1ffc02015-04-10 04:50:10 +0000863 const RegionCodeGenTy &SingleOpGen,
Alexey Bataeva63048e2015-03-23 06:18:07 +0000864 SourceLocation Loc,
865 ArrayRef<const Expr *> CopyprivateVars,
Alexey Bataev420d45b2015-04-14 05:11:24 +0000866 ArrayRef<const Expr *> DestExprs,
Alexey Bataeva63048e2015-03-23 06:18:07 +0000867 ArrayRef<const Expr *> SrcExprs,
Alexey Bataeva63048e2015-03-23 06:18:07 +0000868 ArrayRef<const Expr *> AssignmentOps);
Alexey Bataev6956e2e2015-02-05 06:35:41 +0000869
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000870 /// Emit an ordered region.
Alexey Bataev98eb6e32015-04-22 11:15:40 +0000871 /// \param OrderedOpGen Generator for the statement associated with the given
Alexey Bataevc30dd2d2015-06-18 12:14:09 +0000872 /// ordered region.
Alexey Bataev98eb6e32015-04-22 11:15:40 +0000873 virtual void emitOrderedRegion(CodeGenFunction &CGF,
874 const RegionCodeGenTy &OrderedOpGen,
Alexey Bataev5f600d62015-09-29 03:48:57 +0000875 SourceLocation Loc, bool IsThreads);
Alexey Bataev98eb6e32015-04-22 11:15:40 +0000876
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000877 /// Emit an implicit/explicit barrier for OpenMP threads.
Alexey Bataevf2685682015-03-30 04:30:22 +0000878 /// \param Kind Directive for which this implicit barrier call must be
879 /// generated. Must be OMPD_barrier for explicit barrier generation.
Alexey Bataev25e5b442015-09-15 12:52:43 +0000880 /// \param EmitChecks true if need to emit checks for cancellation barriers.
881 /// \param ForceSimpleCall true simple barrier call must be emitted, false if
882 /// runtime class decides which one to emit (simple or with cancellation
883 /// checks).
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000884 ///
Alexey Bataev3eff5f42015-02-25 08:32:46 +0000885 virtual void emitBarrierCall(CodeGenFunction &CGF, SourceLocation Loc,
Alexey Bataev81c7ea02015-07-03 09:56:58 +0000886 OpenMPDirectiveKind Kind,
Alexey Bataev25e5b442015-09-15 12:52:43 +0000887 bool EmitChecks = true,
888 bool ForceSimpleCall = false);
Alexey Bataevb2059782014-10-13 08:23:51 +0000889
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000890 /// Check if the specified \a ScheduleKind is static non-chunked.
Alexander Musmanc6388682014-12-15 07:07:06 +0000891 /// This kind of worksharing directive is emitted without outer loop.
892 /// \param ScheduleKind Schedule kind specified in the 'schedule' clause.
893 /// \param Chunked True if chunk is specified in the clause.
894 ///
895 virtual bool isStaticNonchunked(OpenMPScheduleClauseKind ScheduleKind,
896 bool Chunked) const;
897
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000898 /// Check if the specified \a ScheduleKind is static non-chunked.
Carlo Bertollifc35ad22016-03-07 16:04:49 +0000899 /// This kind of distribute directive is emitted without outer loop.
900 /// \param ScheduleKind Schedule kind specified in the 'dist_schedule' clause.
901 /// \param Chunked True if chunk is specified in the clause.
902 ///
903 virtual bool isStaticNonchunked(OpenMPDistScheduleClauseKind ScheduleKind,
904 bool Chunked) const;
905
Gheorghe-Teodor Berceae9256762018-10-29 15:45:47 +0000906 /// Check if the specified \a ScheduleKind is static chunked.
907 /// \param ScheduleKind Schedule kind specified in the 'schedule' clause.
908 /// \param Chunked True if chunk is specified in the clause.
909 ///
910 virtual bool isStaticChunked(OpenMPScheduleClauseKind ScheduleKind,
911 bool Chunked) const;
912
913 /// Check if the specified \a ScheduleKind is static non-chunked.
914 /// \param ScheduleKind Schedule kind specified in the 'dist_schedule' clause.
915 /// \param Chunked True if chunk is specified in the clause.
916 ///
917 virtual bool isStaticChunked(OpenMPDistScheduleClauseKind ScheduleKind,
918 bool Chunked) const;
919
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000920 /// Check if the specified \a ScheduleKind is dynamic.
Alexander Musmandf7a8e22015-01-22 08:49:35 +0000921 /// This kind of worksharing directive is emitted without outer loop.
922 /// \param ScheduleKind Schedule Kind specified in the 'schedule' clause.
923 ///
924 virtual bool isDynamic(OpenMPScheduleClauseKind ScheduleKind) const;
925
Carlo Bertollib0ff0a62017-04-25 17:52:12 +0000926 /// struct with the values to be passed to the dispatch runtime function
927 struct DispatchRTInput {
928 /// Loop lower bound
929 llvm::Value *LB = nullptr;
930 /// Loop upper bound
931 llvm::Value *UB = nullptr;
932 /// Chunk size specified using 'schedule' clause (nullptr if chunk
933 /// was not specified)
934 llvm::Value *Chunk = nullptr;
935 DispatchRTInput() = default;
936 DispatchRTInput(llvm::Value *LB, llvm::Value *UB, llvm::Value *Chunk)
937 : LB(LB), UB(UB), Chunk(Chunk) {}
938 };
939
940 /// Call the appropriate runtime routine to initialize it before start
941 /// of loop.
942
943 /// This is used for non static scheduled types and when the ordered
944 /// clause is present on the loop construct.
945 /// Depending on the loop schedule, it is necessary to call some runtime
946 /// routine before start of the OpenMP loop to get the loop upper / lower
947 /// bounds \a LB and \a UB and stride \a ST.
948 ///
949 /// \param CGF Reference to current CodeGenFunction.
950 /// \param Loc Clang source location.
951 /// \param ScheduleKind Schedule kind, specified by the 'schedule' clause.
952 /// \param IVSize Size of the iteration variable in bits.
Simon Pilgrim6c0eeff2017-07-13 17:34:44 +0000953 /// \param IVSigned Sign of the iteration variable.
Carlo Bertollib0ff0a62017-04-25 17:52:12 +0000954 /// \param Ordered true if loop is ordered, false otherwise.
955 /// \param DispatchValues struct containing llvm values for lower bound, upper
956 /// bound, and chunk expression.
957 /// For the default (nullptr) value, the chunk 1 will be used.
958 ///
NAKAMURA Takumiff7a9252015-09-08 09:42:41 +0000959 virtual void emitForDispatchInit(CodeGenFunction &CGF, SourceLocation Loc,
Alexey Bataev9ebd7422016-05-10 09:57:36 +0000960 const OpenMPScheduleTy &ScheduleKind,
961 unsigned IVSize, bool IVSigned, bool Ordered,
Carlo Bertollib0ff0a62017-04-25 17:52:12 +0000962 const DispatchRTInput &DispatchValues);
NAKAMURA Takumiff7a9252015-09-08 09:42:41 +0000963
Alexey Bataev0f87dbe2017-08-14 17:56:13 +0000964 /// Struct with the values to be passed to the static runtime function
965 struct StaticRTInput {
966 /// Size of the iteration variable in bits.
967 unsigned IVSize = 0;
968 /// Sign of the iteration variable.
969 bool IVSigned = false;
970 /// true if loop is ordered, false otherwise.
971 bool Ordered = false;
972 /// Address of the output variable in which the flag of the last iteration
973 /// is returned.
974 Address IL = Address::invalid();
975 /// Address of the output variable in which the lower iteration number is
976 /// returned.
977 Address LB = Address::invalid();
978 /// Address of the output variable in which the upper iteration number is
979 /// returned.
980 Address UB = Address::invalid();
981 /// Address of the output variable in which the stride value is returned
982 /// necessary to generated the static_chunked scheduled loop.
983 Address ST = Address::invalid();
984 /// Value of the chunk for the static_chunked scheduled loop. For the
985 /// default (nullptr) value, the chunk 1 will be used.
986 llvm::Value *Chunk = nullptr;
987 StaticRTInput(unsigned IVSize, bool IVSigned, bool Ordered, Address IL,
988 Address LB, Address UB, Address ST,
989 llvm::Value *Chunk = nullptr)
990 : IVSize(IVSize), IVSigned(IVSigned), Ordered(Ordered), IL(IL), LB(LB),
991 UB(UB), ST(ST), Chunk(Chunk) {}
992 };
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000993 /// Call the appropriate runtime routine to initialize it before start
Alexander Musmanc6388682014-12-15 07:07:06 +0000994 /// of loop.
995 ///
Carlo Bertollib0ff0a62017-04-25 17:52:12 +0000996 /// This is used only in case of static schedule, when the user did not
997 /// specify a ordered clause on the loop construct.
998 /// Depending on the loop schedule, it is necessary to call some runtime
Alexander Musmanc6388682014-12-15 07:07:06 +0000999 /// routine before start of the OpenMP loop to get the loop upper / lower
Alexey Bataev0f87dbe2017-08-14 17:56:13 +00001000 /// bounds LB and UB and stride ST.
Alexander Musmanc6388682014-12-15 07:07:06 +00001001 ///
1002 /// \param CGF Reference to current CodeGenFunction.
1003 /// \param Loc Clang source location.
Alexey Bataev0f87dbe2017-08-14 17:56:13 +00001004 /// \param DKind Kind of the directive.
Alexey Bataev9ebd7422016-05-10 09:57:36 +00001005 /// \param ScheduleKind Schedule kind, specified by the 'schedule' clause.
Alexey Bataev0f87dbe2017-08-14 17:56:13 +00001006 /// \param Values Input arguments for the construct.
Alexander Musmanc6388682014-12-15 07:07:06 +00001007 ///
John McCall7f416cc2015-09-08 08:05:57 +00001008 virtual void emitForStaticInit(CodeGenFunction &CGF, SourceLocation Loc,
Alexey Bataev0f87dbe2017-08-14 17:56:13 +00001009 OpenMPDirectiveKind DKind,
Alexey Bataev9ebd7422016-05-10 09:57:36 +00001010 const OpenMPScheduleTy &ScheduleKind,
Alexey Bataev0f87dbe2017-08-14 17:56:13 +00001011 const StaticRTInput &Values);
Alexander Musmanc6388682014-12-15 07:07:06 +00001012
Carlo Bertollifc35ad22016-03-07 16:04:49 +00001013 ///
1014 /// \param CGF Reference to current CodeGenFunction.
1015 /// \param Loc Clang source location.
1016 /// \param SchedKind Schedule kind, specified by the 'dist_schedule' clause.
Alexey Bataev0f87dbe2017-08-14 17:56:13 +00001017 /// \param Values Input arguments for the construct.
Carlo Bertollifc35ad22016-03-07 16:04:49 +00001018 ///
Alexey Bataev0f87dbe2017-08-14 17:56:13 +00001019 virtual void emitDistributeStaticInit(CodeGenFunction &CGF,
1020 SourceLocation Loc,
Carlo Bertollifc35ad22016-03-07 16:04:49 +00001021 OpenMPDistScheduleClauseKind SchedKind,
Alexey Bataev0f87dbe2017-08-14 17:56:13 +00001022 const StaticRTInput &Values);
Carlo Bertollifc35ad22016-03-07 16:04:49 +00001023
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001024 /// Call the appropriate runtime routine to notify that we finished
Alexey Bataev98eb6e32015-04-22 11:15:40 +00001025 /// iteration of the ordered loop with the dynamic scheduling.
1026 ///
1027 /// \param CGF Reference to current CodeGenFunction.
1028 /// \param Loc Clang source location.
1029 /// \param IVSize Size of the iteration variable in bits.
Simon Pilgrim6c0eeff2017-07-13 17:34:44 +00001030 /// \param IVSigned Sign of the iteration variable.
Alexey Bataev98eb6e32015-04-22 11:15:40 +00001031 ///
Alexey Bataevd7589ffe2015-05-20 13:12:48 +00001032 virtual void emitForOrderedIterationEnd(CodeGenFunction &CGF,
1033 SourceLocation Loc, unsigned IVSize,
1034 bool IVSigned);
Alexey Bataev98eb6e32015-04-22 11:15:40 +00001035
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001036 /// Call the appropriate runtime routine to notify that we finished
Alexander Musmanc6388682014-12-15 07:07:06 +00001037 /// all the work with current loop.
1038 ///
1039 /// \param CGF Reference to current CodeGenFunction.
1040 /// \param Loc Clang source location.
Alexey Bataevf43f7142017-09-06 16:17:35 +00001041 /// \param DKind Kind of the directive for which the static finish is emitted.
Alexander Musmanc6388682014-12-15 07:07:06 +00001042 ///
Alexey Bataevf43f7142017-09-06 16:17:35 +00001043 virtual void emitForStaticFinish(CodeGenFunction &CGF, SourceLocation Loc,
1044 OpenMPDirectiveKind DKind);
Alexander Musmanc6388682014-12-15 07:07:06 +00001045
Alexander Musman92bdaab2015-03-12 13:37:50 +00001046 /// Call __kmpc_dispatch_next(
1047 /// ident_t *loc, kmp_int32 tid, kmp_int32 *p_lastiter,
1048 /// kmp_int[32|64] *p_lower, kmp_int[32|64] *p_upper,
1049 /// kmp_int[32|64] *p_stride);
1050 /// \param IVSize Size of the iteration variable in bits.
Simon Pilgrim6c0eeff2017-07-13 17:34:44 +00001051 /// \param IVSigned Sign of the iteration variable.
Alexander Musman92bdaab2015-03-12 13:37:50 +00001052 /// \param IL Address of the output variable in which the flag of the
1053 /// last iteration is returned.
1054 /// \param LB Address of the output variable in which the lower iteration
1055 /// number is returned.
1056 /// \param UB Address of the output variable in which the upper iteration
1057 /// number is returned.
1058 /// \param ST Address of the output variable in which the stride value is
1059 /// returned.
1060 virtual llvm::Value *emitForNext(CodeGenFunction &CGF, SourceLocation Loc,
1061 unsigned IVSize, bool IVSigned,
John McCall7f416cc2015-09-08 08:05:57 +00001062 Address IL, Address LB,
1063 Address UB, Address ST);
Alexander Musman92bdaab2015-03-12 13:37:50 +00001064
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001065 /// Emits call to void __kmpc_push_num_threads(ident_t *loc, kmp_int32
Alexey Bataevb2059782014-10-13 08:23:51 +00001066 /// global_tid, kmp_int32 num_threads) to generate code for 'num_threads'
1067 /// clause.
1068 /// \param NumThreads An integer value of threads.
Alexey Bataev3eff5f42015-02-25 08:32:46 +00001069 virtual void emitNumThreadsClause(CodeGenFunction &CGF,
1070 llvm::Value *NumThreads,
1071 SourceLocation Loc);
Alexey Bataev97720002014-11-11 04:05:39 +00001072
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001073 /// Emit call to void __kmpc_push_proc_bind(ident_t *loc, kmp_int32
Alexey Bataev7f210c62015-06-18 13:40:03 +00001074 /// global_tid, int proc_bind) to generate code for 'proc_bind' clause.
1075 virtual void emitProcBindClause(CodeGenFunction &CGF,
1076 OpenMPProcBindClauseKind ProcBind,
1077 SourceLocation Loc);
1078
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001079 /// Returns address of the threadprivate variable for the current
Alexey Bataev97720002014-11-11 04:05:39 +00001080 /// thread.
NAKAMURA Takumicdcbfba2014-11-11 07:58:06 +00001081 /// \param VD Threadprivate variable.
Alexey Bataev97720002014-11-11 04:05:39 +00001082 /// \param VDAddr Address of the global variable \a VD.
1083 /// \param Loc Location of the reference to threadprivate var.
1084 /// \return Address of the threadprivate variable for the current thread.
John McCall7f416cc2015-09-08 08:05:57 +00001085 virtual Address getAddrOfThreadPrivate(CodeGenFunction &CGF,
1086 const VarDecl *VD,
1087 Address VDAddr,
1088 SourceLocation Loc);
Alexey Bataev97720002014-11-11 04:05:39 +00001089
Alexey Bataev92327c52018-03-26 16:40:55 +00001090 /// Returns the address of the variable marked as declare target with link
1091 /// clause.
Alexey Bataev03f270c2018-03-30 18:31:07 +00001092 virtual Address getAddrOfDeclareTargetLink(const VarDecl *VD);
Alexey Bataev92327c52018-03-26 16:40:55 +00001093
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001094 /// Emit a code for initialization of threadprivate variable. It emits
Alexey Bataev97720002014-11-11 04:05:39 +00001095 /// a call to runtime library which adds initial value to the newly created
1096 /// threadprivate variable (if it is not constant) and registers destructor
1097 /// for the variable (if any).
1098 /// \param VD Threadprivate variable.
1099 /// \param VDAddr Address of the global variable \a VD.
1100 /// \param Loc Location of threadprivate declaration.
1101 /// \param PerformInit true if initialization expression is not constant.
1102 virtual llvm::Function *
John McCall7f416cc2015-09-08 08:05:57 +00001103 emitThreadPrivateVarDefinition(const VarDecl *VD, Address VDAddr,
Alexey Bataev3eff5f42015-02-25 08:32:46 +00001104 SourceLocation Loc, bool PerformInit,
1105 CodeGenFunction *CGF = nullptr);
Alexey Bataevcc37cc12014-11-20 04:34:54 +00001106
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001107 /// Emit a code for initialization of declare target variable.
Alexey Bataev34f8a702018-03-28 14:28:54 +00001108 /// \param VD Declare target variable.
1109 /// \param Addr Address of the global variable \a VD.
1110 /// \param PerformInit true if initialization expression is not constant.
1111 virtual bool emitDeclareTargetVarDefinition(const VarDecl *VD,
1112 llvm::GlobalVariable *Addr,
1113 bool PerformInit);
1114
Alexey Bataevbe5a8b42017-07-17 13:30:36 +00001115 /// Creates artificial threadprivate variable with name \p Name and type \p
1116 /// VarType.
1117 /// \param VarType Type of the artificial threadprivate variable.
1118 /// \param Name Name of the artificial threadprivate variable.
1119 virtual Address getAddrOfArtificialThreadPrivate(CodeGenFunction &CGF,
1120 QualType VarType,
1121 StringRef Name);
1122
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001123 /// Emit flush of the variables specified in 'omp flush' directive.
Alexey Bataevcc37cc12014-11-20 04:34:54 +00001124 /// \param Vars List of variables to flush.
Alexey Bataev3eff5f42015-02-25 08:32:46 +00001125 virtual void emitFlush(CodeGenFunction &CGF, ArrayRef<const Expr *> Vars,
1126 SourceLocation Loc);
Alexey Bataev62b63b12015-03-10 07:28:44 +00001127
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001128 /// Emit task region for the task directive. The task region is
Nico Weber20b0ce32015-04-28 18:19:18 +00001129 /// emitted in several steps:
Alexey Bataev62b63b12015-03-10 07:28:44 +00001130 /// 1. Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32
1131 /// gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds,
1132 /// kmp_routine_entry_t *task_entry). Here task_entry is a pointer to the
1133 /// function:
1134 /// kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) {
1135 /// TaskFunction(gtid, tt->part_id, tt->shareds);
1136 /// return 0;
1137 /// }
1138 /// 2. Copy a list of shared variables to field shareds of the resulting
1139 /// structure kmp_task_t returned by the previous call (if any).
1140 /// 3. Copy a pointer to destructions function to field destructions of the
1141 /// resulting structure kmp_task_t.
1142 /// 4. Emit a call to kmp_int32 __kmpc_omp_task(ident_t *, kmp_int32 gtid,
1143 /// kmp_task_t *new_task), where new_task is a resulting structure from
1144 /// previous items.
Alexey Bataev36c1eb92015-04-30 06:51:57 +00001145 /// \param D Current task directive.
Alexey Bataev62b63b12015-03-10 07:28:44 +00001146 /// \param TaskFunction An LLVM function with type void (*)(i32 /*gtid*/, i32
1147 /// /*part_id*/, captured_struct */*__context*/);
1148 /// \param SharedsTy A type which contains references the shared variables.
Alexey Bataev1d2353d2015-06-24 11:01:36 +00001149 /// \param Shareds Context with the list of shared variables from the \p
Alexey Bataev62b63b12015-03-10 07:28:44 +00001150 /// TaskFunction.
Alexey Bataev1d677132015-04-22 13:57:31 +00001151 /// \param IfCond Not a nullptr if 'if' clause was specified, nullptr
1152 /// otherwise.
Alexey Bataev24b5bae2016-04-28 09:23:51 +00001153 /// \param Data Additional data for task generation like tiednsee, final
1154 /// state, list of privates etc.
1155 virtual void emitTaskCall(CodeGenFunction &CGF, SourceLocation Loc,
1156 const OMPExecutableDirective &D,
1157 llvm::Value *TaskFunction, QualType SharedsTy,
1158 Address Shareds, const Expr *IfCond,
1159 const OMPTaskDataTy &Data);
Alexey Bataev794ba0d2015-04-10 10:43:45 +00001160
Alexey Bataev7292c292016-04-25 12:22:29 +00001161 /// Emit task region for the taskloop directive. The taskloop region is
1162 /// emitted in several steps:
1163 /// 1. Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32
1164 /// gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds,
1165 /// kmp_routine_entry_t *task_entry). Here task_entry is a pointer to the
1166 /// function:
1167 /// kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) {
1168 /// TaskFunction(gtid, tt->part_id, tt->shareds);
1169 /// return 0;
1170 /// }
1171 /// 2. Copy a list of shared variables to field shareds of the resulting
1172 /// structure kmp_task_t returned by the previous call (if any).
1173 /// 3. Copy a pointer to destructions function to field destructions of the
1174 /// resulting structure kmp_task_t.
1175 /// 4. Emit a call to void __kmpc_taskloop(ident_t *loc, int gtid, kmp_task_t
1176 /// *task, int if_val, kmp_uint64 *lb, kmp_uint64 *ub, kmp_int64 st, int
1177 /// nogroup, int sched, kmp_uint64 grainsize, void *task_dup ), where new_task
1178 /// is a resulting structure from
1179 /// previous items.
1180 /// \param D Current task directive.
Alexey Bataev7292c292016-04-25 12:22:29 +00001181 /// \param TaskFunction An LLVM function with type void (*)(i32 /*gtid*/, i32
1182 /// /*part_id*/, captured_struct */*__context*/);
1183 /// \param SharedsTy A type which contains references the shared variables.
1184 /// \param Shareds Context with the list of shared variables from the \p
1185 /// TaskFunction.
1186 /// \param IfCond Not a nullptr if 'if' clause was specified, nullptr
1187 /// otherwise.
Alexey Bataev24b5bae2016-04-28 09:23:51 +00001188 /// \param Data Additional data for task generation like tiednsee, final
1189 /// state, list of privates etc.
Alexey Bataev7292c292016-04-25 12:22:29 +00001190 virtual void emitTaskLoopCall(
1191 CodeGenFunction &CGF, SourceLocation Loc, const OMPLoopDirective &D,
Alexey Bataev24b5bae2016-04-28 09:23:51 +00001192 llvm::Value *TaskFunction, QualType SharedsTy, Address Shareds,
1193 const Expr *IfCond, const OMPTaskDataTy &Data);
Alexey Bataev7292c292016-04-25 12:22:29 +00001194
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001195 /// Emit code for the directive that does not require outlining.
Alexey Bataev6f1ffc02015-04-10 04:50:10 +00001196 ///
Alexey Bataev81c7ea02015-07-03 09:56:58 +00001197 /// \param InnermostKind Kind of innermost directive (for simple directives it
1198 /// is a directive itself, for combined - its innermost directive).
Alexey Bataev6f1ffc02015-04-10 04:50:10 +00001199 /// \param CodeGen Code generation sequence for the \a D directive.
Alexey Bataev25e5b442015-09-15 12:52:43 +00001200 /// \param HasCancel true if region has inner cancel directive, false
1201 /// otherwise.
Alexey Bataev6f1ffc02015-04-10 04:50:10 +00001202 virtual void emitInlinedDirective(CodeGenFunction &CGF,
Alexey Bataev81c7ea02015-07-03 09:56:58 +00001203 OpenMPDirectiveKind InnermostKind,
Alexey Bataev25e5b442015-09-15 12:52:43 +00001204 const RegionCodeGenTy &CodeGen,
1205 bool HasCancel = false);
Arpith Chacko Jacob101e8fb2017-02-16 16:20:16 +00001206
1207 /// Emits reduction function.
1208 /// \param ArgsType Array type containing pointers to reduction variables.
1209 /// \param Privates List of private copies for original reduction arguments.
1210 /// \param LHSExprs List of LHS in \a ReductionOps reduction operations.
1211 /// \param RHSExprs List of RHS in \a ReductionOps reduction operations.
1212 /// \param ReductionOps List of reduction operations in form 'LHS binop RHS'
1213 /// or 'operator binop(LHS, RHS)'.
Alexey Bataev7cae94e2018-01-04 19:45:16 +00001214 llvm::Value *emitReductionFunction(CodeGenModule &CGM, SourceLocation Loc,
1215 llvm::Type *ArgsType,
Arpith Chacko Jacob101e8fb2017-02-16 16:20:16 +00001216 ArrayRef<const Expr *> Privates,
1217 ArrayRef<const Expr *> LHSExprs,
1218 ArrayRef<const Expr *> RHSExprs,
1219 ArrayRef<const Expr *> ReductionOps);
1220
1221 /// Emits single reduction combiner
1222 void emitSingleReductionCombiner(CodeGenFunction &CGF,
1223 const Expr *ReductionOp,
1224 const Expr *PrivateRef,
1225 const DeclRefExpr *LHS,
1226 const DeclRefExpr *RHS);
1227
1228 struct ReductionOptionsTy {
1229 bool WithNowait;
1230 bool SimpleReduction;
1231 OpenMPDirectiveKind ReductionKind;
1232 };
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001233 /// Emit a code for reduction clause. Next code should be emitted for
Alexey Bataev794ba0d2015-04-10 10:43:45 +00001234 /// reduction:
1235 /// \code
1236 ///
1237 /// static kmp_critical_name lock = { 0 };
1238 ///
1239 /// void reduce_func(void *lhs[<n>], void *rhs[<n>]) {
1240 /// ...
1241 /// *(Type<i>*)lhs[i] = RedOp<i>(*(Type<i>*)lhs[i], *(Type<i>*)rhs[i]);
1242 /// ...
1243 /// }
1244 ///
1245 /// ...
1246 /// void *RedList[<n>] = {&<RHSExprs>[0], ..., &<RHSExprs>[<n>-1]};
1247 /// switch (__kmpc_reduce{_nowait}(<loc>, <gtid>, <n>, sizeof(RedList),
1248 /// RedList, reduce_func, &<lock>)) {
1249 /// case 1:
1250 /// ...
1251 /// <LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]);
1252 /// ...
1253 /// __kmpc_end_reduce{_nowait}(<loc>, <gtid>, &<lock>);
1254 /// break;
1255 /// case 2:
1256 /// ...
1257 /// Atomic(<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]));
1258 /// ...
1259 /// break;
1260 /// default:;
1261 /// }
1262 /// \endcode
1263 ///
Alexey Bataevf24e7b12015-10-08 09:10:53 +00001264 /// \param Privates List of private copies for original reduction arguments.
Alexey Bataev794ba0d2015-04-10 10:43:45 +00001265 /// \param LHSExprs List of LHS in \a ReductionOps reduction operations.
1266 /// \param RHSExprs List of RHS in \a ReductionOps reduction operations.
1267 /// \param ReductionOps List of reduction operations in form 'LHS binop RHS'
1268 /// or 'operator binop(LHS, RHS)'.
Arpith Chacko Jacob101e8fb2017-02-16 16:20:16 +00001269 /// \param Options List of options for reduction codegen:
1270 /// WithNowait true if parent directive has also nowait clause, false
1271 /// otherwise.
1272 /// SimpleReduction Emit reduction operation only. Used for omp simd
1273 /// directive on the host.
1274 /// ReductionKind The kind of reduction to perform.
Alexey Bataev794ba0d2015-04-10 10:43:45 +00001275 virtual void emitReduction(CodeGenFunction &CGF, SourceLocation Loc,
Alexey Bataevf24e7b12015-10-08 09:10:53 +00001276 ArrayRef<const Expr *> Privates,
Alexey Bataev794ba0d2015-04-10 10:43:45 +00001277 ArrayRef<const Expr *> LHSExprs,
1278 ArrayRef<const Expr *> RHSExprs,
1279 ArrayRef<const Expr *> ReductionOps,
Arpith Chacko Jacob101e8fb2017-02-16 16:20:16 +00001280 ReductionOptionsTy Options);
Alexey Bataev8b8e2022015-04-27 05:22:09 +00001281
Alexey Bataevbe5a8b42017-07-17 13:30:36 +00001282 /// Emit a code for initialization of task reduction clause. Next code
1283 /// should be emitted for reduction:
1284 /// \code
1285 ///
1286 /// _task_red_item_t red_data[n];
1287 /// ...
1288 /// red_data[i].shar = &origs[i];
1289 /// red_data[i].size = sizeof(origs[i]);
1290 /// red_data[i].f_init = (void*)RedInit<i>;
1291 /// red_data[i].f_fini = (void*)RedDest<i>;
1292 /// red_data[i].f_comb = (void*)RedOp<i>;
1293 /// red_data[i].flags = <Flag_i>;
1294 /// ...
1295 /// void* tg1 = __kmpc_task_reduction_init(gtid, n, red_data);
1296 /// \endcode
1297 ///
1298 /// \param LHSExprs List of LHS in \a Data.ReductionOps reduction operations.
1299 /// \param RHSExprs List of RHS in \a Data.ReductionOps reduction operations.
1300 /// \param Data Additional data for task generation like tiedness, final
1301 /// state, list of privates, reductions etc.
1302 virtual llvm::Value *emitTaskReductionInit(CodeGenFunction &CGF,
1303 SourceLocation Loc,
1304 ArrayRef<const Expr *> LHSExprs,
1305 ArrayRef<const Expr *> RHSExprs,
1306 const OMPTaskDataTy &Data);
1307
1308 /// Required to resolve existing problems in the runtime. Emits threadprivate
1309 /// variables to store the size of the VLAs/array sections for
1310 /// initializer/combiner/finalizer functions + emits threadprivate variable to
1311 /// store the pointer to the original reduction item for the custom
1312 /// initializer defined by declare reduction construct.
1313 /// \param RCG Allows to reuse an existing data for the reductions.
1314 /// \param N Reduction item for which fixups must be emitted.
1315 virtual void emitTaskReductionFixups(CodeGenFunction &CGF, SourceLocation Loc,
1316 ReductionCodeGen &RCG, unsigned N);
1317
1318 /// Get the address of `void *` type of the privatue copy of the reduction
1319 /// item specified by the \p SharedLVal.
1320 /// \param ReductionsPtr Pointer to the reduction data returned by the
1321 /// emitTaskReductionInit function.
1322 /// \param SharedLVal Address of the original reduction item.
1323 virtual Address getTaskReductionItem(CodeGenFunction &CGF, SourceLocation Loc,
1324 llvm::Value *ReductionsPtr,
1325 LValue SharedLVal);
1326
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001327 /// Emit code for 'taskwait' directive.
Alexey Bataev8b8e2022015-04-27 05:22:09 +00001328 virtual void emitTaskwaitCall(CodeGenFunction &CGF, SourceLocation Loc);
Alexey Bataev0f34da12015-07-02 04:17:07 +00001329
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001330 /// Emit code for 'cancellation point' construct.
Alexey Bataev0f34da12015-07-02 04:17:07 +00001331 /// \param CancelRegion Region kind for which the cancellation point must be
1332 /// emitted.
1333 ///
1334 virtual void emitCancellationPointCall(CodeGenFunction &CGF,
1335 SourceLocation Loc,
1336 OpenMPDirectiveKind CancelRegion);
Alexey Bataev7d5d33e2015-07-06 05:50:32 +00001337
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001338 /// Emit code for 'cancel' construct.
Alexey Bataev87933c72015-09-18 08:07:34 +00001339 /// \param IfCond Condition in the associated 'if' clause, if it was
1340 /// specified, nullptr otherwise.
Alexey Bataev7d5d33e2015-07-06 05:50:32 +00001341 /// \param CancelRegion Region kind for which the cancel must be emitted.
1342 ///
1343 virtual void emitCancelCall(CodeGenFunction &CGF, SourceLocation Loc,
Alexey Bataev87933c72015-09-18 08:07:34 +00001344 const Expr *IfCond,
Alexey Bataev7d5d33e2015-07-06 05:50:32 +00001345 OpenMPDirectiveKind CancelRegion);
Samuel Antaobed3c462015-10-02 16:14:20 +00001346
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001347 /// Emit outilined function for 'target' directive.
Samuel Antaobed3c462015-10-02 16:14:20 +00001348 /// \param D Directive to emit.
Samuel Antaoee8fb302016-01-06 13:42:12 +00001349 /// \param ParentName Name of the function that encloses the target region.
1350 /// \param OutlinedFn Outlined function value to be defined by this call.
1351 /// \param OutlinedFnID Outlined function ID value to be defined by this call.
1352 /// \param IsOffloadEntry True if the outlined function is an offload entry.
Alexey Bataev14fa1c62016-03-29 05:34:15 +00001353 /// \param CodeGen Code generation sequence for the \a D directive.
Simon Pilgrim6c0eeff2017-07-13 17:34:44 +00001354 /// An outlined function may not be an entry if, e.g. the if clause always
Samuel Antaoee8fb302016-01-06 13:42:12 +00001355 /// evaluates to false.
1356 virtual void emitTargetOutlinedFunction(const OMPExecutableDirective &D,
1357 StringRef ParentName,
1358 llvm::Function *&OutlinedFn,
1359 llvm::Constant *&OutlinedFnID,
Alexey Bataev14fa1c62016-03-29 05:34:15 +00001360 bool IsOffloadEntry,
1361 const RegionCodeGenTy &CodeGen);
Samuel Antaobed3c462015-10-02 16:14:20 +00001362
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001363 /// Emit the target offloading code associated with \a D. The emitted
Samuel Antaobed3c462015-10-02 16:14:20 +00001364 /// code attempts offloading the execution to the device, an the event of
1365 /// a failure it executes the host version outlined in \a OutlinedFn.
1366 /// \param D Directive to emit.
1367 /// \param OutlinedFn Host version of the code to be offloaded.
Samuel Antaoee8fb302016-01-06 13:42:12 +00001368 /// \param OutlinedFnID ID of host version of the code to be offloaded.
Samuel Antaobed3c462015-10-02 16:14:20 +00001369 /// \param IfCond Expression evaluated in if clause associated with the target
1370 /// directive, or null if no if clause is used.
1371 /// \param Device Expression evaluated in device clause associated with the
1372 /// target directive, or null if no device clause is used.
Samuel Antaobed3c462015-10-02 16:14:20 +00001373 virtual void emitTargetCall(CodeGenFunction &CGF,
1374 const OMPExecutableDirective &D,
Samuel Antaoee8fb302016-01-06 13:42:12 +00001375 llvm::Value *OutlinedFn,
1376 llvm::Value *OutlinedFnID, const Expr *IfCond,
Alexey Bataev8451efa2018-01-15 19:06:12 +00001377 const Expr *Device);
Samuel Antaoee8fb302016-01-06 13:42:12 +00001378
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001379 /// Emit the target regions enclosed in \a GD function definition or
Samuel Antaoee8fb302016-01-06 13:42:12 +00001380 /// the function itself in case it is a valid device function. Returns true if
1381 /// \a GD was dealt with successfully.
Nico Webera2abe8c2016-01-06 19:13:49 +00001382 /// \param GD Function to scan.
Samuel Antaoee8fb302016-01-06 13:42:12 +00001383 virtual bool emitTargetFunctions(GlobalDecl GD);
1384
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001385 /// Emit the global variable if it is a valid device global variable.
Samuel Antaoee8fb302016-01-06 13:42:12 +00001386 /// Returns true if \a GD was dealt with successfully.
1387 /// \param GD Variable declaration to emit.
1388 virtual bool emitTargetGlobalVariable(GlobalDecl GD);
1389
Alexey Bataev03f270c2018-03-30 18:31:07 +00001390 /// Checks if the provided global decl \a GD is a declare target variable and
1391 /// registers it when emitting code for the host.
1392 virtual void registerTargetGlobalVariable(const VarDecl *VD,
1393 llvm::Constant *Addr);
1394
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001395 /// Emit the global \a GD if it is meaningful for the target. Returns
Simon Pilgrim2c518802017-03-30 14:13:19 +00001396 /// if it was emitted successfully.
Samuel Antaoee8fb302016-01-06 13:42:12 +00001397 /// \param GD Global to scan.
1398 virtual bool emitTargetGlobal(GlobalDecl GD);
1399
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001400 /// Creates the offloading descriptor in the event any target region
Samuel Antaoee8fb302016-01-06 13:42:12 +00001401 /// was emitted in the current module and return the function that registers
1402 /// it.
1403 virtual llvm::Function *emitRegistrationFunction();
Carlo Bertolli430d8ec2016-03-03 20:34:23 +00001404
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001405 /// Emits code for teams call of the \a OutlinedFn with
Carlo Bertolli430d8ec2016-03-03 20:34:23 +00001406 /// variables captured in a record which address is stored in \a
1407 /// CapturedStruct.
1408 /// \param OutlinedFn Outlined function to be run by team masters. Type of
1409 /// this function is void(*)(kmp_int32 *, kmp_int32, struct context_vars*).
1410 /// \param CapturedVars A pointer to the record with the references to
1411 /// variables used in \a OutlinedFn function.
1412 ///
1413 virtual void emitTeamsCall(CodeGenFunction &CGF,
1414 const OMPExecutableDirective &D,
1415 SourceLocation Loc, llvm::Value *OutlinedFn,
1416 ArrayRef<llvm::Value *> CapturedVars);
1417
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001418 /// Emits call to void __kmpc_push_num_teams(ident_t *loc, kmp_int32
Carlo Bertolli430d8ec2016-03-03 20:34:23 +00001419 /// global_tid, kmp_int32 num_teams, kmp_int32 thread_limit) to generate code
1420 /// for num_teams clause.
Carlo Bertollic6872252016-04-04 15:55:02 +00001421 /// \param NumTeams An integer expression of teams.
1422 /// \param ThreadLimit An integer expression of threads.
1423 virtual void emitNumTeamsClause(CodeGenFunction &CGF, const Expr *NumTeams,
1424 const Expr *ThreadLimit, SourceLocation Loc);
Samuel Antaodf158d52016-04-27 22:58:19 +00001425
Samuel Antaocc10b852016-07-28 14:23:26 +00001426 /// Struct that keeps all the relevant information that should be kept
1427 /// throughout a 'target data' region.
1428 class TargetDataInfo {
1429 /// Set to true if device pointer information have to be obtained.
1430 bool RequiresDevicePointerInfo = false;
1431
1432 public:
1433 /// The array of base pointer passed to the runtime library.
1434 llvm::Value *BasePointersArray = nullptr;
1435 /// The array of section pointers passed to the runtime library.
1436 llvm::Value *PointersArray = nullptr;
1437 /// The array of sizes passed to the runtime library.
1438 llvm::Value *SizesArray = nullptr;
1439 /// The array of map types passed to the runtime library.
1440 llvm::Value *MapTypesArray = nullptr;
1441 /// The total number of pointers passed to the runtime library.
1442 unsigned NumberOfPtrs = 0u;
1443 /// Map between the a declaration of a capture and the corresponding base
1444 /// pointer address where the runtime returns the device pointers.
1445 llvm::DenseMap<const ValueDecl *, Address> CaptureDeviceAddrMap;
1446
1447 explicit TargetDataInfo() {}
1448 explicit TargetDataInfo(bool RequiresDevicePointerInfo)
1449 : RequiresDevicePointerInfo(RequiresDevicePointerInfo) {}
1450 /// Clear information about the data arrays.
1451 void clearArrayInfo() {
1452 BasePointersArray = nullptr;
1453 PointersArray = nullptr;
1454 SizesArray = nullptr;
1455 MapTypesArray = nullptr;
1456 NumberOfPtrs = 0u;
1457 }
1458 /// Return true if the current target data information has valid arrays.
1459 bool isValid() {
1460 return BasePointersArray && PointersArray && SizesArray &&
1461 MapTypesArray && NumberOfPtrs;
1462 }
1463 bool requiresDevicePointerInfo() { return RequiresDevicePointerInfo; }
1464 };
1465
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001466 /// Emit the target data mapping code associated with \a D.
Samuel Antaodf158d52016-04-27 22:58:19 +00001467 /// \param D Directive to emit.
Samuel Antaocc10b852016-07-28 14:23:26 +00001468 /// \param IfCond Expression evaluated in if clause associated with the
1469 /// target directive, or null if no device clause is used.
Samuel Antaodf158d52016-04-27 22:58:19 +00001470 /// \param Device Expression evaluated in device clause associated with the
1471 /// target directive, or null if no device clause is used.
Samuel Antaocc10b852016-07-28 14:23:26 +00001472 /// \param Info A record used to store information that needs to be preserved
1473 /// until the region is closed.
Samuel Antaodf158d52016-04-27 22:58:19 +00001474 virtual void emitTargetDataCalls(CodeGenFunction &CGF,
1475 const OMPExecutableDirective &D,
1476 const Expr *IfCond, const Expr *Device,
Samuel Antaocc10b852016-07-28 14:23:26 +00001477 const RegionCodeGenTy &CodeGen,
1478 TargetDataInfo &Info);
Samuel Antaobd0ae2e2016-04-27 23:07:29 +00001479
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001480 /// Emit the data mapping/movement code associated with the directive
Samuel Antao8d2d7302016-05-26 18:30:22 +00001481 /// \a D that should be of the form 'target [{enter|exit} data | update]'.
Samuel Antaobd0ae2e2016-04-27 23:07:29 +00001482 /// \param D Directive to emit.
1483 /// \param IfCond Expression evaluated in if clause associated with the target
1484 /// directive, or null if no if clause is used.
1485 /// \param Device Expression evaluated in device clause associated with the
1486 /// target directive, or null if no device clause is used.
Samuel Antao8d2d7302016-05-26 18:30:22 +00001487 virtual void emitTargetDataStandAloneCall(CodeGenFunction &CGF,
1488 const OMPExecutableDirective &D,
1489 const Expr *IfCond,
1490 const Expr *Device);
Alexey Bataevc7a82b42016-05-06 09:40:08 +00001491
1492 /// Marks function \a Fn with properly mangled versions of vector functions.
1493 /// \param FD Function marked as 'declare simd'.
1494 /// \param Fn LLVM function that must be marked with 'declare simd'
1495 /// attributes.
1496 virtual void emitDeclareSimdFunction(const FunctionDecl *FD,
1497 llvm::Function *Fn);
Alexey Bataev8b427062016-05-25 12:36:08 +00001498
1499 /// Emit initialization for doacross loop nesting support.
1500 /// \param D Loop-based construct used in doacross nesting construct.
Alexey Bataevf138fda2018-08-13 19:04:24 +00001501 virtual void emitDoacrossInit(CodeGenFunction &CGF, const OMPLoopDirective &D,
1502 ArrayRef<Expr *> NumIterations);
Alexey Bataev8b427062016-05-25 12:36:08 +00001503
1504 /// Emit code for doacross ordered directive with 'depend' clause.
1505 /// \param C 'depend' clause with 'sink|source' dependency kind.
1506 virtual void emitDoacrossOrdered(CodeGenFunction &CGF,
1507 const OMPDependClause *C);
Alexey Bataev2c7eee52017-08-04 19:10:54 +00001508
Alexey Bataev3b8d5582017-08-08 18:04:06 +00001509 /// Translates the native parameter of outlined function if this is required
1510 /// for target.
Alexander Kornienko2a8c18d2018-04-06 15:14:32 +00001511 /// \param FD Field decl from captured record for the parameter.
Alexey Bataev3b8d5582017-08-08 18:04:06 +00001512 /// \param NativeParam Parameter itself.
1513 virtual const VarDecl *translateParameter(const FieldDecl *FD,
1514 const VarDecl *NativeParam) const {
1515 return NativeParam;
1516 }
1517
1518 /// Gets the address of the native argument basing on the address of the
1519 /// target-specific parameter.
1520 /// \param NativeParam Parameter itself.
1521 /// \param TargetParam Corresponding target-specific parameter.
1522 virtual Address getParameterAddress(CodeGenFunction &CGF,
1523 const VarDecl *NativeParam,
1524 const VarDecl *TargetParam) const;
1525
Gheorghe-Teodor Bercea02650d42018-09-27 19:22:56 +00001526 /// Choose default schedule type and chunk value for the
1527 /// dist_schedule clause.
1528 virtual void getDefaultDistScheduleAndChunk(CodeGenFunction &CGF,
1529 const OMPLoopDirective &S, OpenMPDistScheduleClauseKind &ScheduleKind,
1530 llvm::Value *&Chunk) const {}
1531
Gheorghe-Teodor Bercea8233af92018-09-27 20:29:00 +00001532 /// Choose default schedule type and chunk value for the
1533 /// schedule clause.
1534 virtual void getDefaultScheduleAndChunk(CodeGenFunction &CGF,
1535 const OMPLoopDirective &S, OpenMPScheduleClauseKind &ScheduleKind,
Gheorghe-Teodor Berceae9256762018-10-29 15:45:47 +00001536 const Expr *&ChunkExpr) const {}
Gheorghe-Teodor Bercea8233af92018-09-27 20:29:00 +00001537
Alexey Bataev2c7eee52017-08-04 19:10:54 +00001538 /// Emits call of the outlined function with the provided arguments,
1539 /// translating these arguments to correct target-specific arguments.
1540 virtual void
Alexey Bataev3c595a62017-08-14 15:01:03 +00001541 emitOutlinedFunctionCall(CodeGenFunction &CGF, SourceLocation Loc,
1542 llvm::Value *OutlinedFn,
Alexey Bataev2c7eee52017-08-04 19:10:54 +00001543 ArrayRef<llvm::Value *> Args = llvm::None) const;
Gheorghe-Teodor Bercead3dcf2f2018-03-14 14:17:45 +00001544
1545 /// Emits OpenMP-specific function prolog.
1546 /// Required for device constructs.
1547 virtual void emitFunctionProlog(CodeGenFunction &CGF, const Decl *D) {}
1548
1549 /// Gets the OpenMP-specific address of the local variable.
1550 virtual Address getAddressOfLocalVariable(CodeGenFunction &CGF,
1551 const VarDecl *VD);
Alexey Bataev4f4bf7c2018-03-15 15:47:20 +00001552
1553 /// Marks the declaration as alread emitted for the device code and returns
1554 /// true, if it was marked already, and false, otherwise.
Alexey Bataev6d944102018-05-02 15:45:28 +00001555 bool markAsGlobalTarget(GlobalDecl GD);
Alexey Bataev4f4bf7c2018-03-15 15:47:20 +00001556
Alexey Bataevbf8fe712018-08-07 16:14:36 +00001557 /// Emit deferred declare target variables marked for deferred emission.
1558 void emitDeferredTargetDecls() const;
Alexey Bataev60705422018-10-30 15:50:12 +00001559
1560 /// Adjust some parameters for the target-based directives, like addresses of
1561 /// the variables captured by reference in lambdas.
1562 virtual void
1563 adjustTargetSpecificDataForLambdas(CodeGenFunction &CGF,
1564 const OMPExecutableDirective &D) const;
Patrick Lyster8f7f5862018-11-19 15:09:33 +00001565
1566 /// Perform check on requires decl to ensure that target architecture
1567 /// supports unified addressing
1568 virtual void checkArchForUnifiedAddressing(CodeGenModule &CGM,
1569 const OMPRequiresDecl *D) const {}
Alexey Bataev9959db52014-05-06 10:08:46 +00001570};
Alexey Bataev8cbe0a62015-02-26 10:27:34 +00001571
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00001572/// Class supports emissionof SIMD-only code.
1573class CGOpenMPSIMDRuntime final : public CGOpenMPRuntime {
1574public:
1575 explicit CGOpenMPSIMDRuntime(CodeGenModule &CGM) : CGOpenMPRuntime(CGM) {}
1576 ~CGOpenMPSIMDRuntime() override {}
1577
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001578 /// Emits outlined function for the specified OpenMP parallel directive
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00001579 /// \a D. This outlined function has type void(*)(kmp_int32 *ThreadID,
1580 /// kmp_int32 BoundID, struct context_vars*).
1581 /// \param D OpenMP directive.
1582 /// \param ThreadIDVar Variable for thread id in the current OpenMP region.
1583 /// \param InnermostKind Kind of innermost directive (for simple directives it
1584 /// is a directive itself, for combined - its innermost directive).
1585 /// \param CodeGen Code generation sequence for the \a D directive.
1586 llvm::Value *
1587 emitParallelOutlinedFunction(const OMPExecutableDirective &D,
1588 const VarDecl *ThreadIDVar,
1589 OpenMPDirectiveKind InnermostKind,
1590 const RegionCodeGenTy &CodeGen) override;
1591
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001592 /// Emits outlined function for the specified OpenMP teams directive
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00001593 /// \a D. This outlined function has type void(*)(kmp_int32 *ThreadID,
1594 /// kmp_int32 BoundID, struct context_vars*).
1595 /// \param D OpenMP directive.
1596 /// \param ThreadIDVar Variable for thread id in the current OpenMP region.
1597 /// \param InnermostKind Kind of innermost directive (for simple directives it
1598 /// is a directive itself, for combined - its innermost directive).
1599 /// \param CodeGen Code generation sequence for the \a D directive.
1600 llvm::Value *
1601 emitTeamsOutlinedFunction(const OMPExecutableDirective &D,
1602 const VarDecl *ThreadIDVar,
1603 OpenMPDirectiveKind InnermostKind,
1604 const RegionCodeGenTy &CodeGen) override;
1605
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001606 /// Emits outlined function for the OpenMP task directive \a D. This
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00001607 /// outlined function has type void(*)(kmp_int32 ThreadID, struct task_t*
1608 /// TaskT).
1609 /// \param D OpenMP directive.
1610 /// \param ThreadIDVar Variable for thread id in the current OpenMP region.
1611 /// \param PartIDVar Variable for partition id in the current OpenMP untied
1612 /// task region.
1613 /// \param TaskTVar Variable for task_t argument.
1614 /// \param InnermostKind Kind of innermost directive (for simple directives it
1615 /// is a directive itself, for combined - its innermost directive).
1616 /// \param CodeGen Code generation sequence for the \a D directive.
1617 /// \param Tied true if task is generated for tied task, false otherwise.
1618 /// \param NumberOfParts Number of parts in untied task. Ignored for tied
1619 /// tasks.
1620 ///
1621 llvm::Value *emitTaskOutlinedFunction(
1622 const OMPExecutableDirective &D, const VarDecl *ThreadIDVar,
1623 const VarDecl *PartIDVar, const VarDecl *TaskTVar,
1624 OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen,
1625 bool Tied, unsigned &NumberOfParts) override;
1626
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001627 /// Emits code for parallel or serial call of the \a OutlinedFn with
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00001628 /// variables captured in a record which address is stored in \a
1629 /// CapturedStruct.
1630 /// \param OutlinedFn Outlined function to be run in parallel threads. Type of
1631 /// this function is void(*)(kmp_int32 *, kmp_int32, struct context_vars*).
1632 /// \param CapturedVars A pointer to the record with the references to
1633 /// variables used in \a OutlinedFn function.
1634 /// \param IfCond Condition in the associated 'if' clause, if it was
1635 /// specified, nullptr otherwise.
1636 ///
1637 void emitParallelCall(CodeGenFunction &CGF, SourceLocation Loc,
1638 llvm::Value *OutlinedFn,
1639 ArrayRef<llvm::Value *> CapturedVars,
1640 const Expr *IfCond) override;
1641
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001642 /// Emits a critical region.
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00001643 /// \param CriticalName Name of the critical region.
1644 /// \param CriticalOpGen Generator for the statement associated with the given
1645 /// critical region.
1646 /// \param Hint Value of the 'hint' clause (optional).
1647 void emitCriticalRegion(CodeGenFunction &CGF, StringRef CriticalName,
1648 const RegionCodeGenTy &CriticalOpGen,
1649 SourceLocation Loc,
1650 const Expr *Hint = nullptr) override;
1651
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001652 /// Emits a master region.
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00001653 /// \param MasterOpGen Generator for the statement associated with the given
1654 /// master region.
1655 void emitMasterRegion(CodeGenFunction &CGF,
1656 const RegionCodeGenTy &MasterOpGen,
1657 SourceLocation Loc) override;
1658
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001659 /// Emits code for a taskyield directive.
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00001660 void emitTaskyieldCall(CodeGenFunction &CGF, SourceLocation Loc) override;
1661
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001662 /// Emit a taskgroup region.
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00001663 /// \param TaskgroupOpGen Generator for the statement associated with the
1664 /// given taskgroup region.
1665 void emitTaskgroupRegion(CodeGenFunction &CGF,
1666 const RegionCodeGenTy &TaskgroupOpGen,
1667 SourceLocation Loc) override;
1668
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001669 /// Emits a single region.
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00001670 /// \param SingleOpGen Generator for the statement associated with the given
1671 /// single region.
1672 void emitSingleRegion(CodeGenFunction &CGF,
1673 const RegionCodeGenTy &SingleOpGen, SourceLocation Loc,
1674 ArrayRef<const Expr *> CopyprivateVars,
1675 ArrayRef<const Expr *> DestExprs,
1676 ArrayRef<const Expr *> SrcExprs,
1677 ArrayRef<const Expr *> AssignmentOps) override;
1678
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001679 /// Emit an ordered region.
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00001680 /// \param OrderedOpGen Generator for the statement associated with the given
1681 /// ordered region.
1682 void emitOrderedRegion(CodeGenFunction &CGF,
1683 const RegionCodeGenTy &OrderedOpGen,
1684 SourceLocation Loc, bool IsThreads) override;
1685
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001686 /// Emit an implicit/explicit barrier for OpenMP threads.
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00001687 /// \param Kind Directive for which this implicit barrier call must be
1688 /// generated. Must be OMPD_barrier for explicit barrier generation.
1689 /// \param EmitChecks true if need to emit checks for cancellation barriers.
1690 /// \param ForceSimpleCall true simple barrier call must be emitted, false if
1691 /// runtime class decides which one to emit (simple or with cancellation
1692 /// checks).
1693 ///
1694 void emitBarrierCall(CodeGenFunction &CGF, SourceLocation Loc,
1695 OpenMPDirectiveKind Kind, bool EmitChecks = true,
1696 bool ForceSimpleCall = false) override;
1697
1698 /// This is used for non static scheduled types and when the ordered
1699 /// clause is present on the loop construct.
1700 /// Depending on the loop schedule, it is necessary to call some runtime
1701 /// routine before start of the OpenMP loop to get the loop upper / lower
1702 /// bounds \a LB and \a UB and stride \a ST.
1703 ///
1704 /// \param CGF Reference to current CodeGenFunction.
1705 /// \param Loc Clang source location.
1706 /// \param ScheduleKind Schedule kind, specified by the 'schedule' clause.
1707 /// \param IVSize Size of the iteration variable in bits.
1708 /// \param IVSigned Sign of the iteration variable.
1709 /// \param Ordered true if loop is ordered, false otherwise.
1710 /// \param DispatchValues struct containing llvm values for lower bound, upper
1711 /// bound, and chunk expression.
1712 /// For the default (nullptr) value, the chunk 1 will be used.
1713 ///
1714 void emitForDispatchInit(CodeGenFunction &CGF, SourceLocation Loc,
1715 const OpenMPScheduleTy &ScheduleKind,
1716 unsigned IVSize, bool IVSigned, bool Ordered,
1717 const DispatchRTInput &DispatchValues) override;
1718
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001719 /// Call the appropriate runtime routine to initialize it before start
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00001720 /// of loop.
1721 ///
1722 /// This is used only in case of static schedule, when the user did not
1723 /// specify a ordered clause on the loop construct.
1724 /// Depending on the loop schedule, it is necessary to call some runtime
1725 /// routine before start of the OpenMP loop to get the loop upper / lower
1726 /// bounds LB and UB and stride ST.
1727 ///
1728 /// \param CGF Reference to current CodeGenFunction.
1729 /// \param Loc Clang source location.
1730 /// \param DKind Kind of the directive.
1731 /// \param ScheduleKind Schedule kind, specified by the 'schedule' clause.
1732 /// \param Values Input arguments for the construct.
1733 ///
1734 void emitForStaticInit(CodeGenFunction &CGF, SourceLocation Loc,
1735 OpenMPDirectiveKind DKind,
1736 const OpenMPScheduleTy &ScheduleKind,
1737 const StaticRTInput &Values) override;
1738
1739 ///
1740 /// \param CGF Reference to current CodeGenFunction.
1741 /// \param Loc Clang source location.
1742 /// \param SchedKind Schedule kind, specified by the 'dist_schedule' clause.
1743 /// \param Values Input arguments for the construct.
1744 ///
1745 void emitDistributeStaticInit(CodeGenFunction &CGF, SourceLocation Loc,
1746 OpenMPDistScheduleClauseKind SchedKind,
1747 const StaticRTInput &Values) override;
1748
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001749 /// Call the appropriate runtime routine to notify that we finished
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00001750 /// iteration of the ordered loop with the dynamic scheduling.
1751 ///
1752 /// \param CGF Reference to current CodeGenFunction.
1753 /// \param Loc Clang source location.
1754 /// \param IVSize Size of the iteration variable in bits.
1755 /// \param IVSigned Sign of the iteration variable.
1756 ///
1757 void emitForOrderedIterationEnd(CodeGenFunction &CGF, SourceLocation Loc,
1758 unsigned IVSize, bool IVSigned) override;
1759
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001760 /// Call the appropriate runtime routine to notify that we finished
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00001761 /// all the work with current loop.
1762 ///
1763 /// \param CGF Reference to current CodeGenFunction.
1764 /// \param Loc Clang source location.
1765 /// \param DKind Kind of the directive for which the static finish is emitted.
1766 ///
1767 void emitForStaticFinish(CodeGenFunction &CGF, SourceLocation Loc,
1768 OpenMPDirectiveKind DKind) override;
1769
1770 /// Call __kmpc_dispatch_next(
1771 /// ident_t *loc, kmp_int32 tid, kmp_int32 *p_lastiter,
1772 /// kmp_int[32|64] *p_lower, kmp_int[32|64] *p_upper,
1773 /// kmp_int[32|64] *p_stride);
1774 /// \param IVSize Size of the iteration variable in bits.
1775 /// \param IVSigned Sign of the iteration variable.
1776 /// \param IL Address of the output variable in which the flag of the
1777 /// last iteration is returned.
1778 /// \param LB Address of the output variable in which the lower iteration
1779 /// number is returned.
1780 /// \param UB Address of the output variable in which the upper iteration
1781 /// number is returned.
1782 /// \param ST Address of the output variable in which the stride value is
1783 /// returned.
1784 llvm::Value *emitForNext(CodeGenFunction &CGF, SourceLocation Loc,
1785 unsigned IVSize, bool IVSigned, Address IL,
1786 Address LB, Address UB, Address ST) override;
1787
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001788 /// Emits call to void __kmpc_push_num_threads(ident_t *loc, kmp_int32
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00001789 /// global_tid, kmp_int32 num_threads) to generate code for 'num_threads'
1790 /// clause.
1791 /// \param NumThreads An integer value of threads.
1792 void emitNumThreadsClause(CodeGenFunction &CGF, llvm::Value *NumThreads,
1793 SourceLocation Loc) override;
1794
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001795 /// Emit call to void __kmpc_push_proc_bind(ident_t *loc, kmp_int32
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00001796 /// global_tid, int proc_bind) to generate code for 'proc_bind' clause.
1797 void emitProcBindClause(CodeGenFunction &CGF,
1798 OpenMPProcBindClauseKind ProcBind,
1799 SourceLocation Loc) override;
1800
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001801 /// Returns address of the threadprivate variable for the current
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00001802 /// thread.
1803 /// \param VD Threadprivate variable.
1804 /// \param VDAddr Address of the global variable \a VD.
1805 /// \param Loc Location of the reference to threadprivate var.
1806 /// \return Address of the threadprivate variable for the current thread.
1807 Address getAddrOfThreadPrivate(CodeGenFunction &CGF, const VarDecl *VD,
1808 Address VDAddr, SourceLocation Loc) override;
1809
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001810 /// Emit a code for initialization of threadprivate variable. It emits
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00001811 /// a call to runtime library which adds initial value to the newly created
1812 /// threadprivate variable (if it is not constant) and registers destructor
1813 /// for the variable (if any).
1814 /// \param VD Threadprivate variable.
1815 /// \param VDAddr Address of the global variable \a VD.
1816 /// \param Loc Location of threadprivate declaration.
1817 /// \param PerformInit true if initialization expression is not constant.
1818 llvm::Function *
1819 emitThreadPrivateVarDefinition(const VarDecl *VD, Address VDAddr,
1820 SourceLocation Loc, bool PerformInit,
1821 CodeGenFunction *CGF = nullptr) override;
1822
1823 /// Creates artificial threadprivate variable with name \p Name and type \p
1824 /// VarType.
1825 /// \param VarType Type of the artificial threadprivate variable.
1826 /// \param Name Name of the artificial threadprivate variable.
1827 Address getAddrOfArtificialThreadPrivate(CodeGenFunction &CGF,
1828 QualType VarType,
1829 StringRef Name) override;
1830
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001831 /// Emit flush of the variables specified in 'omp flush' directive.
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00001832 /// \param Vars List of variables to flush.
1833 void emitFlush(CodeGenFunction &CGF, ArrayRef<const Expr *> Vars,
1834 SourceLocation Loc) override;
1835
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001836 /// Emit task region for the task directive. The task region is
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00001837 /// emitted in several steps:
1838 /// 1. Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32
1839 /// gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds,
1840 /// kmp_routine_entry_t *task_entry). Here task_entry is a pointer to the
1841 /// function:
1842 /// kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) {
1843 /// TaskFunction(gtid, tt->part_id, tt->shareds);
1844 /// return 0;
1845 /// }
1846 /// 2. Copy a list of shared variables to field shareds of the resulting
1847 /// structure kmp_task_t returned by the previous call (if any).
1848 /// 3. Copy a pointer to destructions function to field destructions of the
1849 /// resulting structure kmp_task_t.
1850 /// 4. Emit a call to kmp_int32 __kmpc_omp_task(ident_t *, kmp_int32 gtid,
1851 /// kmp_task_t *new_task), where new_task is a resulting structure from
1852 /// previous items.
1853 /// \param D Current task directive.
1854 /// \param TaskFunction An LLVM function with type void (*)(i32 /*gtid*/, i32
1855 /// /*part_id*/, captured_struct */*__context*/);
1856 /// \param SharedsTy A type which contains references the shared variables.
1857 /// \param Shareds Context with the list of shared variables from the \p
1858 /// TaskFunction.
1859 /// \param IfCond Not a nullptr if 'if' clause was specified, nullptr
1860 /// otherwise.
1861 /// \param Data Additional data for task generation like tiednsee, final
1862 /// state, list of privates etc.
1863 void emitTaskCall(CodeGenFunction &CGF, SourceLocation Loc,
1864 const OMPExecutableDirective &D, llvm::Value *TaskFunction,
1865 QualType SharedsTy, Address Shareds, const Expr *IfCond,
1866 const OMPTaskDataTy &Data) override;
1867
1868 /// Emit task region for the taskloop directive. The taskloop region is
1869 /// emitted in several steps:
1870 /// 1. Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32
1871 /// gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds,
1872 /// kmp_routine_entry_t *task_entry). Here task_entry is a pointer to the
1873 /// function:
1874 /// kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) {
1875 /// TaskFunction(gtid, tt->part_id, tt->shareds);
1876 /// return 0;
1877 /// }
1878 /// 2. Copy a list of shared variables to field shareds of the resulting
1879 /// structure kmp_task_t returned by the previous call (if any).
1880 /// 3. Copy a pointer to destructions function to field destructions of the
1881 /// resulting structure kmp_task_t.
1882 /// 4. Emit a call to void __kmpc_taskloop(ident_t *loc, int gtid, kmp_task_t
1883 /// *task, int if_val, kmp_uint64 *lb, kmp_uint64 *ub, kmp_int64 st, int
1884 /// nogroup, int sched, kmp_uint64 grainsize, void *task_dup ), where new_task
1885 /// is a resulting structure from
1886 /// previous items.
1887 /// \param D Current task directive.
1888 /// \param TaskFunction An LLVM function with type void (*)(i32 /*gtid*/, i32
1889 /// /*part_id*/, captured_struct */*__context*/);
1890 /// \param SharedsTy A type which contains references the shared variables.
1891 /// \param Shareds Context with the list of shared variables from the \p
1892 /// TaskFunction.
1893 /// \param IfCond Not a nullptr if 'if' clause was specified, nullptr
1894 /// otherwise.
1895 /// \param Data Additional data for task generation like tiednsee, final
1896 /// state, list of privates etc.
1897 void emitTaskLoopCall(CodeGenFunction &CGF, SourceLocation Loc,
1898 const OMPLoopDirective &D, llvm::Value *TaskFunction,
1899 QualType SharedsTy, Address Shareds, const Expr *IfCond,
1900 const OMPTaskDataTy &Data) override;
1901
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001902 /// Emit a code for reduction clause. Next code should be emitted for
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00001903 /// reduction:
1904 /// \code
1905 ///
1906 /// static kmp_critical_name lock = { 0 };
1907 ///
1908 /// void reduce_func(void *lhs[<n>], void *rhs[<n>]) {
1909 /// ...
1910 /// *(Type<i>*)lhs[i] = RedOp<i>(*(Type<i>*)lhs[i], *(Type<i>*)rhs[i]);
1911 /// ...
1912 /// }
1913 ///
1914 /// ...
1915 /// void *RedList[<n>] = {&<RHSExprs>[0], ..., &<RHSExprs>[<n>-1]};
1916 /// switch (__kmpc_reduce{_nowait}(<loc>, <gtid>, <n>, sizeof(RedList),
1917 /// RedList, reduce_func, &<lock>)) {
1918 /// case 1:
1919 /// ...
1920 /// <LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]);
1921 /// ...
1922 /// __kmpc_end_reduce{_nowait}(<loc>, <gtid>, &<lock>);
1923 /// break;
1924 /// case 2:
1925 /// ...
1926 /// Atomic(<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]));
1927 /// ...
1928 /// break;
1929 /// default:;
1930 /// }
1931 /// \endcode
1932 ///
1933 /// \param Privates List of private copies for original reduction arguments.
1934 /// \param LHSExprs List of LHS in \a ReductionOps reduction operations.
1935 /// \param RHSExprs List of RHS in \a ReductionOps reduction operations.
1936 /// \param ReductionOps List of reduction operations in form 'LHS binop RHS'
1937 /// or 'operator binop(LHS, RHS)'.
1938 /// \param Options List of options for reduction codegen:
1939 /// WithNowait true if parent directive has also nowait clause, false
1940 /// otherwise.
1941 /// SimpleReduction Emit reduction operation only. Used for omp simd
1942 /// directive on the host.
1943 /// ReductionKind The kind of reduction to perform.
1944 void emitReduction(CodeGenFunction &CGF, SourceLocation Loc,
1945 ArrayRef<const Expr *> Privates,
1946 ArrayRef<const Expr *> LHSExprs,
1947 ArrayRef<const Expr *> RHSExprs,
1948 ArrayRef<const Expr *> ReductionOps,
1949 ReductionOptionsTy Options) override;
1950
1951 /// Emit a code for initialization of task reduction clause. Next code
1952 /// should be emitted for reduction:
1953 /// \code
1954 ///
1955 /// _task_red_item_t red_data[n];
1956 /// ...
1957 /// red_data[i].shar = &origs[i];
1958 /// red_data[i].size = sizeof(origs[i]);
1959 /// red_data[i].f_init = (void*)RedInit<i>;
1960 /// red_data[i].f_fini = (void*)RedDest<i>;
1961 /// red_data[i].f_comb = (void*)RedOp<i>;
1962 /// red_data[i].flags = <Flag_i>;
1963 /// ...
1964 /// void* tg1 = __kmpc_task_reduction_init(gtid, n, red_data);
1965 /// \endcode
1966 ///
1967 /// \param LHSExprs List of LHS in \a Data.ReductionOps reduction operations.
1968 /// \param RHSExprs List of RHS in \a Data.ReductionOps reduction operations.
1969 /// \param Data Additional data for task generation like tiedness, final
1970 /// state, list of privates, reductions etc.
1971 llvm::Value *emitTaskReductionInit(CodeGenFunction &CGF, SourceLocation Loc,
1972 ArrayRef<const Expr *> LHSExprs,
1973 ArrayRef<const Expr *> RHSExprs,
1974 const OMPTaskDataTy &Data) override;
1975
1976 /// Required to resolve existing problems in the runtime. Emits threadprivate
1977 /// variables to store the size of the VLAs/array sections for
1978 /// initializer/combiner/finalizer functions + emits threadprivate variable to
1979 /// store the pointer to the original reduction item for the custom
1980 /// initializer defined by declare reduction construct.
1981 /// \param RCG Allows to reuse an existing data for the reductions.
1982 /// \param N Reduction item for which fixups must be emitted.
1983 void emitTaskReductionFixups(CodeGenFunction &CGF, SourceLocation Loc,
1984 ReductionCodeGen &RCG, unsigned N) override;
1985
1986 /// Get the address of `void *` type of the privatue copy of the reduction
1987 /// item specified by the \p SharedLVal.
1988 /// \param ReductionsPtr Pointer to the reduction data returned by the
1989 /// emitTaskReductionInit function.
1990 /// \param SharedLVal Address of the original reduction item.
1991 Address getTaskReductionItem(CodeGenFunction &CGF, SourceLocation Loc,
1992 llvm::Value *ReductionsPtr,
1993 LValue SharedLVal) override;
1994
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001995 /// Emit code for 'taskwait' directive.
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00001996 void emitTaskwaitCall(CodeGenFunction &CGF, SourceLocation Loc) override;
1997
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001998 /// Emit code for 'cancellation point' construct.
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00001999 /// \param CancelRegion Region kind for which the cancellation point must be
2000 /// emitted.
2001 ///
2002 void emitCancellationPointCall(CodeGenFunction &CGF, SourceLocation Loc,
2003 OpenMPDirectiveKind CancelRegion) override;
2004
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002005 /// Emit code for 'cancel' construct.
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00002006 /// \param IfCond Condition in the associated 'if' clause, if it was
2007 /// specified, nullptr otherwise.
2008 /// \param CancelRegion Region kind for which the cancel must be emitted.
2009 ///
2010 void emitCancelCall(CodeGenFunction &CGF, SourceLocation Loc,
2011 const Expr *IfCond,
2012 OpenMPDirectiveKind CancelRegion) override;
2013
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002014 /// Emit outilined function for 'target' directive.
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00002015 /// \param D Directive to emit.
2016 /// \param ParentName Name of the function that encloses the target region.
2017 /// \param OutlinedFn Outlined function value to be defined by this call.
2018 /// \param OutlinedFnID Outlined function ID value to be defined by this call.
2019 /// \param IsOffloadEntry True if the outlined function is an offload entry.
2020 /// \param CodeGen Code generation sequence for the \a D directive.
2021 /// An outlined function may not be an entry if, e.g. the if clause always
2022 /// evaluates to false.
2023 void emitTargetOutlinedFunction(const OMPExecutableDirective &D,
2024 StringRef ParentName,
2025 llvm::Function *&OutlinedFn,
2026 llvm::Constant *&OutlinedFnID,
2027 bool IsOffloadEntry,
2028 const RegionCodeGenTy &CodeGen) override;
2029
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002030 /// Emit the target offloading code associated with \a D. The emitted
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00002031 /// code attempts offloading the execution to the device, an the event of
2032 /// a failure it executes the host version outlined in \a OutlinedFn.
2033 /// \param D Directive to emit.
2034 /// \param OutlinedFn Host version of the code to be offloaded.
2035 /// \param OutlinedFnID ID of host version of the code to be offloaded.
2036 /// \param IfCond Expression evaluated in if clause associated with the target
2037 /// directive, or null if no if clause is used.
2038 /// \param Device Expression evaluated in device clause associated with the
2039 /// target directive, or null if no device clause is used.
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00002040 void emitTargetCall(CodeGenFunction &CGF, const OMPExecutableDirective &D,
2041 llvm::Value *OutlinedFn, llvm::Value *OutlinedFnID,
Alexey Bataev8451efa2018-01-15 19:06:12 +00002042 const Expr *IfCond, const Expr *Device) override;
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00002043
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002044 /// Emit the target regions enclosed in \a GD function definition or
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00002045 /// the function itself in case it is a valid device function. Returns true if
2046 /// \a GD was dealt with successfully.
2047 /// \param GD Function to scan.
2048 bool emitTargetFunctions(GlobalDecl GD) override;
2049
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002050 /// Emit the global variable if it is a valid device global variable.
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00002051 /// Returns true if \a GD was dealt with successfully.
2052 /// \param GD Variable declaration to emit.
2053 bool emitTargetGlobalVariable(GlobalDecl GD) override;
2054
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002055 /// Emit the global \a GD if it is meaningful for the target. Returns
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00002056 /// if it was emitted successfully.
2057 /// \param GD Global to scan.
2058 bool emitTargetGlobal(GlobalDecl GD) override;
2059
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002060 /// Creates the offloading descriptor in the event any target region
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00002061 /// was emitted in the current module and return the function that registers
2062 /// it.
2063 llvm::Function *emitRegistrationFunction() override;
2064
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002065 /// Emits code for teams call of the \a OutlinedFn with
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00002066 /// variables captured in a record which address is stored in \a
2067 /// CapturedStruct.
2068 /// \param OutlinedFn Outlined function to be run by team masters. Type of
2069 /// this function is void(*)(kmp_int32 *, kmp_int32, struct context_vars*).
2070 /// \param CapturedVars A pointer to the record with the references to
2071 /// variables used in \a OutlinedFn function.
2072 ///
2073 void emitTeamsCall(CodeGenFunction &CGF, const OMPExecutableDirective &D,
2074 SourceLocation Loc, llvm::Value *OutlinedFn,
2075 ArrayRef<llvm::Value *> CapturedVars) override;
2076
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002077 /// Emits call to void __kmpc_push_num_teams(ident_t *loc, kmp_int32
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00002078 /// global_tid, kmp_int32 num_teams, kmp_int32 thread_limit) to generate code
2079 /// for num_teams clause.
2080 /// \param NumTeams An integer expression of teams.
2081 /// \param ThreadLimit An integer expression of threads.
2082 void emitNumTeamsClause(CodeGenFunction &CGF, const Expr *NumTeams,
2083 const Expr *ThreadLimit, SourceLocation Loc) override;
2084
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002085 /// Emit the target data mapping code associated with \a D.
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00002086 /// \param D Directive to emit.
2087 /// \param IfCond Expression evaluated in if clause associated with the
2088 /// target directive, or null if no device clause is used.
2089 /// \param Device Expression evaluated in device clause associated with the
2090 /// target directive, or null if no device clause is used.
2091 /// \param Info A record used to store information that needs to be preserved
2092 /// until the region is closed.
2093 void emitTargetDataCalls(CodeGenFunction &CGF,
2094 const OMPExecutableDirective &D, const Expr *IfCond,
2095 const Expr *Device, const RegionCodeGenTy &CodeGen,
2096 TargetDataInfo &Info) override;
2097
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002098 /// Emit the data mapping/movement code associated with the directive
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00002099 /// \a D that should be of the form 'target [{enter|exit} data | update]'.
2100 /// \param D Directive to emit.
2101 /// \param IfCond Expression evaluated in if clause associated with the target
2102 /// directive, or null if no if clause is used.
2103 /// \param Device Expression evaluated in device clause associated with the
2104 /// target directive, or null if no device clause is used.
2105 void emitTargetDataStandAloneCall(CodeGenFunction &CGF,
2106 const OMPExecutableDirective &D,
2107 const Expr *IfCond,
2108 const Expr *Device) override;
2109
2110 /// Emit initialization for doacross loop nesting support.
2111 /// \param D Loop-based construct used in doacross nesting construct.
Alexey Bataevf138fda2018-08-13 19:04:24 +00002112 void emitDoacrossInit(CodeGenFunction &CGF, const OMPLoopDirective &D,
2113 ArrayRef<Expr *> NumIterations) override;
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00002114
2115 /// Emit code for doacross ordered directive with 'depend' clause.
2116 /// \param C 'depend' clause with 'sink|source' dependency kind.
2117 void emitDoacrossOrdered(CodeGenFunction &CGF,
2118 const OMPDependClause *C) override;
2119
2120 /// Translates the native parameter of outlined function if this is required
2121 /// for target.
Alexander Kornienko2a8c18d2018-04-06 15:14:32 +00002122 /// \param FD Field decl from captured record for the parameter.
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00002123 /// \param NativeParam Parameter itself.
2124 const VarDecl *translateParameter(const FieldDecl *FD,
2125 const VarDecl *NativeParam) const override;
2126
2127 /// Gets the address of the native argument basing on the address of the
2128 /// target-specific parameter.
2129 /// \param NativeParam Parameter itself.
2130 /// \param TargetParam Corresponding target-specific parameter.
2131 Address getParameterAddress(CodeGenFunction &CGF, const VarDecl *NativeParam,
2132 const VarDecl *TargetParam) const override;
2133};
2134
Alexey Bataev23b69422014-06-18 07:08:49 +00002135} // namespace CodeGen
2136} // namespace clang
Alexey Bataev9959db52014-05-06 10:08:46 +00002137
2138#endif