Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1 | //===----- CGOpenMPRuntime.h - Interface to OpenMP Runtimes -----*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This provides a class for OpenMP runtime code generation. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
Benjamin Kramer | 2f5db8b | 2014-08-13 16:25:19 +0000 | [diff] [blame] | 13 | #ifndef LLVM_CLANG_LIB_CODEGEN_CGOPENMPRUNTIME_H |
| 14 | #define LLVM_CLANG_LIB_CODEGEN_CGOPENMPRUNTIME_H |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 15 | |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 16 | #include "CGValue.h" |
Richard Trieu | f8b8b39 | 2019-01-11 01:32:35 +0000 | [diff] [blame] | 17 | #include "clang/AST/DeclOpenMP.h" |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 18 | #include "clang/AST/Type.h" |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 19 | #include "clang/Basic/OpenMPKinds.h" |
Chandler Carruth | 0d9593d | 2015-01-14 11:29:14 +0000 | [diff] [blame] | 20 | #include "clang/Basic/SourceLocation.h" |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/DenseMap.h" |
Alexey Bataev | 3a3bf0b | 2014-09-22 10:01:53 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/StringMap.h" |
Alexey Bataev | 2a6f3f5 | 2018-11-07 19:11:14 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/StringSet.h" |
Benjamin Kramer | 8fdba91 | 2016-02-02 14:24:21 +0000 | [diff] [blame] | 24 | #include "llvm/IR/Function.h" |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 25 | #include "llvm/IR/ValueHandle.h" |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 26 | |
| 27 | namespace llvm { |
| 28 | class ArrayType; |
| 29 | class Constant; |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 30 | class FunctionType; |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 31 | class GlobalVariable; |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 32 | class StructType; |
| 33 | class Type; |
| 34 | class Value; |
| 35 | } // namespace llvm |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 36 | |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 37 | namespace clang { |
Alexey Bataev | cc37cc1 | 2014-11-20 04:34:54 +0000 | [diff] [blame] | 38 | class Expr; |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 39 | class GlobalDecl; |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 40 | class OMPDependClause; |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 41 | class OMPExecutableDirective; |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 42 | class OMPLoopDirective; |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 43 | class VarDecl; |
Alexey Bataev | c5b1d32 | 2016-03-04 09:22:22 +0000 | [diff] [blame] | 44 | class OMPDeclareReductionDecl; |
| 45 | class IdentifierInfo; |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 46 | |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 47 | namespace CodeGen { |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 48 | class Address; |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 49 | class CodeGenFunction; |
| 50 | class CodeGenModule; |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 51 | |
Alexey Bataev | 14fa1c6 | 2016-03-29 05:34:15 +0000 | [diff] [blame] | 52 | /// A basic class for pre|post-action for advanced codegen sequence for OpenMP |
| 53 | /// region. |
| 54 | class PrePostActionTy { |
| 55 | public: |
| 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. |
| 64 | class 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 | |
| 77 | public: |
| 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 Bataev | 6f1ffc0 | 2015-04-10 04:50:10 +0000 | [diff] [blame] | 90 | |
Alexey Bataev | 24b5bae | 2016-04-28 09:23:51 +0000 | [diff] [blame] | 91 | struct 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 Bataev | f93095a | 2016-05-05 08:46:22 +0000 | [diff] [blame] | 97 | SmallVector<const Expr *, 4> LastprivateVars; |
| 98 | SmallVector<const Expr *, 4> LastprivateCopies; |
Alexey Bataev | be5a8b4 | 2017-07-17 13:30:36 +0000 | [diff] [blame] | 99 | SmallVector<const Expr *, 4> ReductionVars; |
| 100 | SmallVector<const Expr *, 4> ReductionCopies; |
| 101 | SmallVector<const Expr *, 4> ReductionOps; |
Alexey Bataev | 24b5bae | 2016-04-28 09:23:51 +0000 | [diff] [blame] | 102 | 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 Bataev | 1e1e286 | 2016-05-10 12:21:02 +0000 | [diff] [blame] | 105 | llvm::PointerIntPair<llvm::Value *, 1, bool> Priority; |
Alexey Bataev | be5a8b4 | 2017-07-17 13:30:36 +0000 | [diff] [blame] | 106 | llvm::Value *Reductions = nullptr; |
Alexey Bataev | 24b5bae | 2016-04-28 09:23:51 +0000 | [diff] [blame] | 107 | unsigned NumberOfParts = 0; |
| 108 | bool Tied = true; |
| 109 | bool Nogroup = false; |
| 110 | }; |
| 111 | |
Alexey Bataev | 5c40bec | 2017-07-13 13:36:14 +0000 | [diff] [blame] | 112 | /// Class intended to support codegen of all kind of the reduction clauses. |
| 113 | class ReductionCodeGen { |
| 114 | private: |
Simon Pilgrim | 6c0eeff | 2017-07-13 17:34:44 +0000 | [diff] [blame] | 115 | /// Data required for codegen of reduction clauses. |
Alexey Bataev | 5c40bec | 2017-07-13 13:36:14 +0000 | [diff] [blame] | 116 | 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 Bataev | be5a8b4 | 2017-07-17 13:30:36 +0000 | [diff] [blame] | 132 | SmallVector<std::pair<llvm::Value *, llvm::Value *>, 4> Sizes; |
Alexey Bataev | 5c40bec | 2017-07-13 13:36:14 +0000 | [diff] [blame] | 133 | /// Base declarations for the reduction items. |
| 134 | SmallVector<const VarDecl *, 4> BaseDecls; |
Alexey Bataev | be5a8b4 | 2017-07-17 13:30:36 +0000 | [diff] [blame] | 135 | |
Alexander Kornienko | 2a8c18d | 2018-04-06 15:14:32 +0000 | [diff] [blame] | 136 | /// Emits lvalue for shared expression. |
Alexey Bataev | 5c40bec | 2017-07-13 13:36:14 +0000 | [diff] [blame] | 137 | LValue emitSharedLValue(CodeGenFunction &CGF, const Expr *E); |
| 138 | /// Emits upper bound for shared expression (if array section). |
| 139 | LValue emitSharedLValueUB(CodeGenFunction &CGF, const Expr *E); |
| 140 | /// Performs aggregate initialization. |
| 141 | /// \param N Number of reduction item in the common list. |
| 142 | /// \param PrivateAddr Address of the corresponding private item. |
Alexey Bataev | be5a8b4 | 2017-07-17 13:30:36 +0000 | [diff] [blame] | 143 | /// \param SharedLVal Address of the original shared variable. |
| 144 | /// \param DRD Declare reduction construct used for reduction item. |
Alexey Bataev | 5c40bec | 2017-07-13 13:36:14 +0000 | [diff] [blame] | 145 | void emitAggregateInitialization(CodeGenFunction &CGF, unsigned N, |
Alexey Bataev | be5a8b4 | 2017-07-17 13:30:36 +0000 | [diff] [blame] | 146 | Address PrivateAddr, LValue SharedLVal, |
| 147 | const OMPDeclareReductionDecl *DRD); |
Alexey Bataev | 5c40bec | 2017-07-13 13:36:14 +0000 | [diff] [blame] | 148 | |
| 149 | public: |
| 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 Pilgrim | 6c0eeff | 2017-07-13 17:34:44 +0000 | [diff] [blame] | 168 | /// \param SharedLVal Address of the original shared variable. |
Alexey Bataev | 5c40bec | 2017-07-13 13:36:14 +0000 | [diff] [blame] | 169 | void |
| 170 | emitInitialization(CodeGenFunction &CGF, unsigned N, Address PrivateAddr, |
| 171 | LValue SharedLVal, |
| 172 | llvm::function_ref<bool(CodeGenFunction &)> DefaultInit); |
Simon Pilgrim | 6c0eeff | 2017-07-13 17:34:44 +0000 | [diff] [blame] | 173 | /// Returns true if the private copy requires cleanups. |
Alexey Bataev | 5c40bec | 2017-07-13 13:36:14 +0000 | [diff] [blame] | 174 | bool needCleanups(unsigned N); |
Simon Pilgrim | 6c0eeff | 2017-07-13 17:34:44 +0000 | [diff] [blame] | 175 | /// Emits cleanup code for the reduction item. |
Alexey Bataev | 5c40bec | 2017-07-13 13:36:14 +0000 | [diff] [blame] | 176 | /// \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 Pilgrim | 6c0eeff | 2017-07-13 17:34:44 +0000 | [diff] [blame] | 179 | /// Adjusts \p PrivatedAddr for using instead of the original variable |
Alexey Bataev | 5c40bec | 2017-07-13 13:36:14 +0000 | [diff] [blame] | 180 | /// 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 Bataev | be5a8b4 | 2017-07-17 13:30:36 +0000 | [diff] [blame] | 187 | /// 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 Bataev | 5c40bec | 2017-07-13 13:36:14 +0000 | [diff] [blame] | 192 | /// Returns the base declaration of the reduction item. |
| 193 | const VarDecl *getBaseDecl(unsigned N) const { return BaseDecls[N]; } |
Alexey Bataev | 1c44e15 | 2018-03-06 18:59:43 +0000 | [diff] [blame] | 194 | /// Returns the base declaration of the reduction item. |
| 195 | const Expr *getRefExpr(unsigned N) const { return ClausesData[N].Ref; } |
Alexey Bataev | be5a8b4 | 2017-07-17 13:30:36 +0000 | [diff] [blame] | 196 | /// Returns true if the initialization of the reduction item uses initializer |
| 197 | /// from declare reduction construct. |
| 198 | bool usesReductionInitializer(unsigned N) const; |
Alexey Bataev | 5c40bec | 2017-07-13 13:36:14 +0000 | [diff] [blame] | 199 | }; |
| 200 | |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 201 | class CGOpenMPRuntime { |
Alexey Bataev | 4f4bf7c | 2018-03-15 15:47:20 +0000 | [diff] [blame] | 202 | public: |
| 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 Jacob | 5c309e4 | 2016-03-22 01:48:56 +0000 | [diff] [blame] | 214 | protected: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 215 | CodeGenModule &CGM; |
Alexey Bataev | 18fa232 | 2018-05-02 14:20:50 +0000 | [diff] [blame] | 216 | 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 Jacob | 5c309e4 | 2016-03-22 01:48:56 +0000 | [diff] [blame] | 221 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 222 | /// Creates offloading entry for the provided entry ID \a ID, |
Samuel Antao | f83efdb | 2017-01-05 16:02:49 +0000 | [diff] [blame] | 223 | /// address \a Addr, size \a Size, and flags \a Flags. |
Arpith Chacko Jacob | 5c309e4 | 2016-03-22 01:48:56 +0000 | [diff] [blame] | 224 | virtual void createOffloadEntry(llvm::Constant *ID, llvm::Constant *Addr, |
Alexey Bataev | 03f270c | 2018-03-30 18:31:07 +0000 | [diff] [blame] | 225 | uint64_t Size, int32_t Flags, |
| 226 | llvm::GlobalValue::LinkageTypes Linkage); |
Arpith Chacko Jacob | 5c309e4 | 2016-03-22 01:48:56 +0000 | [diff] [blame] | 227 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 228 | /// Helper to emit outlined function for 'target' directive. |
Arpith Chacko Jacob | 5c309e4 | 2016-03-22 01:48:56 +0000 | [diff] [blame] | 229 | /// \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 Pilgrim | 6c0eeff | 2017-07-13 17:34:44 +0000 | [diff] [blame] | 235 | /// An outlined function may not be an entry if, e.g. the if clause always |
Arpith Chacko Jacob | 5c309e4 | 2016-03-22 01:48:56 +0000 | [diff] [blame] | 236 | /// 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 Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 244 | /// Emits code for OpenMP 'if' clause using specified \a CodeGen |
Arpith Chacko Jacob | bb36fe8 | 2017-01-10 15:42:51 +0000 | [diff] [blame] | 245 | /// 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 Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 255 | /// Emits object of ident_t type with info for source location. |
Arpith Chacko Jacob | bb36fe8 | 2017-01-10 15:42:51 +0000 | [diff] [blame] | 256 | /// \param Flags Flags for OpenMP location. |
| 257 | /// |
| 258 | llvm::Value *emitUpdateLocation(CodeGenFunction &CGF, SourceLocation Loc, |
| 259 | unsigned Flags = 0); |
| 260 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 261 | /// Returns pointer to ident_t type. |
Arpith Chacko Jacob | bb36fe8 | 2017-01-10 15:42:51 +0000 | [diff] [blame] | 262 | llvm::Type *getIdentTyPointerTy(); |
| 263 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 264 | /// Gets thread id value for the current thread. |
Arpith Chacko Jacob | bb36fe8 | 2017-01-10 15:42:51 +0000 | [diff] [blame] | 265 | /// |
| 266 | llvm::Value *getThreadID(CodeGenFunction &CGF, SourceLocation Loc); |
| 267 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 268 | /// Get the function name of an outlined region. |
Arpith Chacko Jacob | bb36fe8 | 2017-01-10 15:42:51 +0000 | [diff] [blame] | 269 | // The name can be customized depending on the target. |
| 270 | // |
| 271 | virtual StringRef getOutlinedHelperName() const { return ".omp_outlined."; } |
| 272 | |
Alexey Bataev | 3c595a6 | 2017-08-14 15:01:03 +0000 | [diff] [blame] | 273 | /// Emits \p Callee function call with arguments \p Args with location \p Loc. |
James Y Knight | 9871db0 | 2019-02-05 16:42:33 +0000 | [diff] [blame] | 274 | void emitCall(CodeGenFunction &CGF, SourceLocation Loc, |
| 275 | llvm::FunctionCallee Callee, |
Alexey Bataev | 7ef47a6 | 2018-02-22 18:33:31 +0000 | [diff] [blame] | 276 | ArrayRef<llvm::Value *> Args = llvm::None) const; |
Alexey Bataev | 3c595a6 | 2017-08-14 15:01:03 +0000 | [diff] [blame] | 277 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 278 | /// Emits address of the word in a memory where current thread id is |
Alexey Bataev | b7f3cba | 2018-03-19 17:04:07 +0000 | [diff] [blame] | 279 | /// stored. |
| 280 | virtual Address emitThreadIDAddress(CodeGenFunction &CGF, SourceLocation Loc); |
| 281 | |
Alexey Bataev | fd006c4 | 2018-10-05 15:08:53 +0000 | [diff] [blame] | 282 | void setLocThreadIdInsertPt(CodeGenFunction &CGF, |
| 283 | bool AtCurrentPoint = false); |
| 284 | void clearLocThreadIdInsertPt(CodeGenFunction &CGF); |
| 285 | |
Alexey Bataev | ceeaa48 | 2018-11-21 21:04:34 +0000 | [diff] [blame] | 286 | /// Check if the default location must be constant. |
| 287 | /// Default is false to support OMPT/OMPD. |
| 288 | virtual bool isDefaultLocationConstant() const { return false; } |
| 289 | |
| 290 | /// Returns additional flags that can be stored in reserved_2 field of the |
| 291 | /// default location. |
| 292 | virtual unsigned getDefaultLocationReserved2Flags() const { return 0; } |
| 293 | |
Alexey Bataev | c3028ca | 2018-12-04 15:03:25 +0000 | [diff] [blame] | 294 | /// Returns default flags for the barriers depending on the directive, for |
| 295 | /// which this barier is going to be emitted. |
| 296 | static unsigned getDefaultFlagsForBarriers(OpenMPDirectiveKind Kind); |
| 297 | |
Alexey Bataev | a116602 | 2018-11-27 21:24:54 +0000 | [diff] [blame] | 298 | /// Get the LLVM type for the critical name. |
| 299 | llvm::ArrayType *getKmpCriticalNameTy() const {return KmpCriticalNameTy;} |
| 300 | |
| 301 | /// Returns corresponding lock object for the specified critical region |
| 302 | /// name. If the lock object does not exist it is created, otherwise the |
| 303 | /// reference to the existing copy is returned. |
| 304 | /// \param CriticalName Name of the critical region. |
| 305 | /// |
| 306 | llvm::Value *getCriticalRegionLock(StringRef CriticalName); |
| 307 | |
Arpith Chacko Jacob | 5c309e4 | 2016-03-22 01:48:56 +0000 | [diff] [blame] | 308 | private: |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 309 | /// Default const ident_t object used for initialization of all other |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 310 | /// ident_t objects. |
Alexey Bataev | c5b1d32 | 2016-03-04 09:22:22 +0000 | [diff] [blame] | 311 | llvm::Constant *DefaultOpenMPPSource = nullptr; |
Alexey Bataev | ceeaa48 | 2018-11-21 21:04:34 +0000 | [diff] [blame] | 312 | using FlagsTy = std::pair<unsigned, unsigned>; |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 313 | /// Map of flags and corresponding default locations. |
Alexey Bataev | ceeaa48 | 2018-11-21 21:04:34 +0000 | [diff] [blame] | 314 | using OpenMPDefaultLocMapTy = llvm::DenseMap<FlagsTy, llvm::Value *>; |
Alexey Bataev | 15007ba | 2014-05-07 06:18:01 +0000 | [diff] [blame] | 315 | OpenMPDefaultLocMapTy OpenMPDefaultLocMap; |
Alexey Bataev | 50b3c95 | 2016-02-19 10:38:26 +0000 | [diff] [blame] | 316 | Address getOrCreateDefaultLocation(unsigned Flags); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 317 | |
Alexey Bataev | a4fa0b8 | 2018-04-16 17:59:34 +0000 | [diff] [blame] | 318 | QualType IdentQTy; |
Alexey Bataev | 14fa1c6 | 2016-03-29 05:34:15 +0000 | [diff] [blame] | 319 | llvm::StructType *IdentTy = nullptr; |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 320 | /// Map for SourceLocation and OpenMP runtime library debug locations. |
Alexey Bataev | f002aca | 2014-05-30 05:48:40 +0000 | [diff] [blame] | 321 | typedef llvm::DenseMap<unsigned, llvm::Value *> OpenMPDebugLocMapTy; |
| 322 | OpenMPDebugLocMapTy OpenMPDebugLocMap; |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 323 | /// The type for a microtask which gets passed to __kmpc_fork_call(). |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 324 | /// Original representation is: |
| 325 | /// typedef void (kmpc_micro)(kmp_int32 global_tid, kmp_int32 bound_tid,...); |
Alexey Bataev | 14fa1c6 | 2016-03-29 05:34:15 +0000 | [diff] [blame] | 326 | llvm::FunctionType *Kmpc_MicroTy = nullptr; |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 327 | /// Stores debug location and ThreadID for the function. |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 328 | struct DebugLocThreadIdTy { |
| 329 | llvm::Value *DebugLoc; |
| 330 | llvm::Value *ThreadID; |
Alexey Bataev | fd006c4 | 2018-10-05 15:08:53 +0000 | [diff] [blame] | 331 | /// Insert point for the service instructions. |
| 332 | llvm::AssertingVH<llvm::Instruction> ServiceInsertPt = nullptr; |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 333 | }; |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 334 | /// Map of local debug location, ThreadId and functions. |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 335 | typedef llvm::DenseMap<llvm::Function *, DebugLocThreadIdTy> |
| 336 | OpenMPLocThreadIDMapTy; |
| 337 | OpenMPLocThreadIDMapTy OpenMPLocThreadIDMap; |
Alexey Bataev | c5b1d32 | 2016-03-04 09:22:22 +0000 | [diff] [blame] | 338 | /// Map of UDRs and corresponding combiner/initializer. |
| 339 | typedef llvm::DenseMap<const OMPDeclareReductionDecl *, |
| 340 | std::pair<llvm::Function *, llvm::Function *>> |
| 341 | UDRMapTy; |
| 342 | UDRMapTy UDRMap; |
| 343 | /// Map of functions and locally defined UDRs. |
| 344 | typedef llvm::DenseMap<llvm::Function *, |
| 345 | SmallVector<const OMPDeclareReductionDecl *, 4>> |
| 346 | FunctionUDRMapTy; |
| 347 | FunctionUDRMapTy FunctionUDRMap; |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 348 | /// Type kmp_critical_name, originally defined as typedef kmp_int32 |
Alexey Bataev | 3a3bf0b | 2014-09-22 10:01:53 +0000 | [diff] [blame] | 349 | /// kmp_critical_name[8]; |
| 350 | llvm::ArrayType *KmpCriticalNameTy; |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 351 | /// An ordered map of auto-generated variables to their unique names. |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 352 | /// It stores variables with the following names: 1) ".gomp_critical_user_" + |
| 353 | /// <critical_section_name> + ".var" for "omp critical" directives; 2) |
| 354 | /// <mangled_name_for_global_var> + ".cache." for cache for threadprivate |
| 355 | /// variables. |
| 356 | llvm::StringMap<llvm::AssertingVH<llvm::Constant>, llvm::BumpPtrAllocator> |
| 357 | InternalVars; |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 358 | /// Type typedef kmp_int32 (* kmp_routine_entry_t)(kmp_int32, void *); |
Alexey Bataev | c5b1d32 | 2016-03-04 09:22:22 +0000 | [diff] [blame] | 359 | llvm::Type *KmpRoutineEntryPtrTy = nullptr; |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 360 | QualType KmpRoutineEntryPtrQTy; |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 361 | /// Type typedef struct kmp_task { |
Alexey Bataev | 8fc69dc | 2015-05-18 07:54:53 +0000 | [diff] [blame] | 362 | /// void * shareds; /**< pointer to block of pointers to |
| 363 | /// shared vars */ |
| 364 | /// kmp_routine_entry_t routine; /**< pointer to routine to call for |
| 365 | /// executing task */ |
| 366 | /// kmp_int32 part_id; /**< part id for the task */ |
| 367 | /// kmp_routine_entry_t destructors; /* pointer to function to invoke |
| 368 | /// deconstructors of firstprivate C++ objects */ |
| 369 | /// } kmp_task_t; |
| 370 | QualType KmpTaskTQTy; |
Alexey Bataev | e213f3e | 2017-10-11 15:29:40 +0000 | [diff] [blame] | 371 | /// Saved kmp_task_t for task directive. |
| 372 | QualType SavedKmpTaskTQTy; |
| 373 | /// Saved kmp_task_t for taskloop-based directive. |
| 374 | QualType SavedKmpTaskloopTQTy; |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 375 | /// Type typedef struct kmp_depend_info { |
Alexey Bataev | 1d2353d | 2015-06-24 11:01:36 +0000 | [diff] [blame] | 376 | /// kmp_intptr_t base_addr; |
| 377 | /// size_t len; |
| 378 | /// struct { |
| 379 | /// bool in:1; |
| 380 | /// bool out:1; |
| 381 | /// } flags; |
| 382 | /// } kmp_depend_info_t; |
| 383 | QualType KmpDependInfoTy; |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 384 | /// struct kmp_dim { // loop bounds info casted to kmp_int64 |
| 385 | /// kmp_int64 lo; // lower |
| 386 | /// kmp_int64 up; // upper |
| 387 | /// kmp_int64 st; // stride |
| 388 | /// }; |
| 389 | QualType KmpDimTy; |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 390 | /// Type struct __tgt_offload_entry{ |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 391 | /// void *addr; // Pointer to the offload entry info. |
| 392 | /// // (function or global) |
| 393 | /// char *name; // Name of the function or global. |
| 394 | /// size_t size; // Size of the entry info (0 if it a function). |
| 395 | /// }; |
| 396 | QualType TgtOffloadEntryQTy; |
| 397 | /// struct __tgt_device_image{ |
| 398 | /// void *ImageStart; // Pointer to the target code start. |
| 399 | /// void *ImageEnd; // Pointer to the target code end. |
| 400 | /// // We also add the host entries to the device image, as it may be useful |
| 401 | /// // for the target runtime to have access to that information. |
| 402 | /// __tgt_offload_entry *EntriesBegin; // Begin of the table with all |
| 403 | /// // the entries. |
| 404 | /// __tgt_offload_entry *EntriesEnd; // End of the table with all the |
| 405 | /// // entries (non inclusive). |
| 406 | /// }; |
| 407 | QualType TgtDeviceImageQTy; |
| 408 | /// struct __tgt_bin_desc{ |
| 409 | /// int32_t NumDevices; // Number of devices supported. |
| 410 | /// __tgt_device_image *DeviceImages; // Arrays of device images |
| 411 | /// // (one per device). |
| 412 | /// __tgt_offload_entry *EntriesBegin; // Begin of the table with all the |
| 413 | /// // entries. |
| 414 | /// __tgt_offload_entry *EntriesEnd; // End of the table with all the |
| 415 | /// // entries (non inclusive). |
| 416 | /// }; |
| 417 | QualType TgtBinaryDescriptorQTy; |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 418 | /// Entity that registers the offloading constants that were emitted so |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 419 | /// far. |
| 420 | class OffloadEntriesInfoManagerTy { |
| 421 | CodeGenModule &CGM; |
Alexey Bataev | 1d2353d | 2015-06-24 11:01:36 +0000 | [diff] [blame] | 422 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 423 | /// Number of entries registered so far. |
Alexey Bataev | 03f270c | 2018-03-30 18:31:07 +0000 | [diff] [blame] | 424 | unsigned OffloadingEntriesNum = 0; |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 425 | |
| 426 | public: |
Samuel Antao | f83efdb | 2017-01-05 16:02:49 +0000 | [diff] [blame] | 427 | /// Base class of the entries info. |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 428 | class OffloadEntryInfo { |
| 429 | public: |
Alexey Bataev | 34f8a70 | 2018-03-28 14:28:54 +0000 | [diff] [blame] | 430 | /// Kind of a given entry. |
Reid Kleckner | dc78f95 | 2016-01-11 20:55:16 +0000 | [diff] [blame] | 431 | enum OffloadingEntryInfoKinds : unsigned { |
Alexey Bataev | 34f8a70 | 2018-03-28 14:28:54 +0000 | [diff] [blame] | 432 | /// Entry is a target region. |
| 433 | OffloadingEntryInfoTargetRegion = 0, |
Alexey Bataev | 03f270c | 2018-03-30 18:31:07 +0000 | [diff] [blame] | 434 | /// Entry is a declare target variable. |
| 435 | OffloadingEntryInfoDeviceGlobalVar = 1, |
Alexey Bataev | 34f8a70 | 2018-03-28 14:28:54 +0000 | [diff] [blame] | 436 | /// Invalid entry info. |
| 437 | OffloadingEntryInfoInvalid = ~0u |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 438 | }; |
| 439 | |
Alexey Bataev | 03f270c | 2018-03-30 18:31:07 +0000 | [diff] [blame] | 440 | protected: |
| 441 | OffloadEntryInfo() = delete; |
| 442 | explicit OffloadEntryInfo(OffloadingEntryInfoKinds Kind) : Kind(Kind) {} |
Samuel Antao | f83efdb | 2017-01-05 16:02:49 +0000 | [diff] [blame] | 443 | explicit OffloadEntryInfo(OffloadingEntryInfoKinds Kind, unsigned Order, |
Alexey Bataev | 03f270c | 2018-03-30 18:31:07 +0000 | [diff] [blame] | 444 | uint32_t Flags) |
Samuel Antao | f83efdb | 2017-01-05 16:02:49 +0000 | [diff] [blame] | 445 | : Flags(Flags), Order(Order), Kind(Kind) {} |
Alexey Bataev | 03f270c | 2018-03-30 18:31:07 +0000 | [diff] [blame] | 446 | ~OffloadEntryInfo() = default; |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 447 | |
Alexey Bataev | 03f270c | 2018-03-30 18:31:07 +0000 | [diff] [blame] | 448 | public: |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 449 | bool isValid() const { return Order != ~0u; } |
| 450 | unsigned getOrder() const { return Order; } |
| 451 | OffloadingEntryInfoKinds getKind() const { return Kind; } |
Alexey Bataev | 03f270c | 2018-03-30 18:31:07 +0000 | [diff] [blame] | 452 | uint32_t getFlags() const { return Flags; } |
| 453 | void setFlags(uint32_t NewFlags) { Flags = NewFlags; } |
| 454 | llvm::Constant *getAddress() const { |
| 455 | return cast_or_null<llvm::Constant>(Addr); |
| 456 | } |
| 457 | void setAddress(llvm::Constant *V) { |
| 458 | assert(!Addr.pointsToAliveValue() && "Address has been set before!"); |
| 459 | Addr = V; |
| 460 | } |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 461 | static bool classof(const OffloadEntryInfo *Info) { return true; } |
| 462 | |
Samuel Antao | f83efdb | 2017-01-05 16:02:49 +0000 | [diff] [blame] | 463 | private: |
Alexey Bataev | 03f270c | 2018-03-30 18:31:07 +0000 | [diff] [blame] | 464 | /// Address of the entity that has to be mapped for offloading. |
| 465 | llvm::WeakTrackingVH Addr; |
| 466 | |
Samuel Antao | f83efdb | 2017-01-05 16:02:49 +0000 | [diff] [blame] | 467 | /// Flags associated with the device global. |
Alexey Bataev | 03f270c | 2018-03-30 18:31:07 +0000 | [diff] [blame] | 468 | uint32_t Flags = 0u; |
Samuel Antao | f83efdb | 2017-01-05 16:02:49 +0000 | [diff] [blame] | 469 | |
| 470 | /// Order this entry was emitted. |
Alexey Bataev | 03f270c | 2018-03-30 18:31:07 +0000 | [diff] [blame] | 471 | unsigned Order = ~0u; |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 472 | |
Alexey Bataev | 03f270c | 2018-03-30 18:31:07 +0000 | [diff] [blame] | 473 | OffloadingEntryInfoKinds Kind = OffloadingEntryInfoInvalid; |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 474 | }; |
| 475 | |
Alexey Bataev | 03f270c | 2018-03-30 18:31:07 +0000 | [diff] [blame] | 476 | /// Return true if a there are no entries defined. |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 477 | bool empty() const; |
Alexey Bataev | 03f270c | 2018-03-30 18:31:07 +0000 | [diff] [blame] | 478 | /// Return number of entries defined so far. |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 479 | unsigned size() const { return OffloadingEntriesNum; } |
Alexey Bataev | 03f270c | 2018-03-30 18:31:07 +0000 | [diff] [blame] | 480 | OffloadEntriesInfoManagerTy(CodeGenModule &CGM) : CGM(CGM) {} |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 481 | |
Alexey Bataev | 03f270c | 2018-03-30 18:31:07 +0000 | [diff] [blame] | 482 | // |
| 483 | // Target region entries related. |
| 484 | // |
| 485 | |
| 486 | /// Kind of the target registry entry. |
| 487 | enum OMPTargetRegionEntryKind : uint32_t { |
| 488 | /// Mark the entry as target region. |
| 489 | OMPTargetRegionEntryTargetRegion = 0x0, |
| 490 | /// Mark the entry as a global constructor. |
| 491 | OMPTargetRegionEntryCtor = 0x02, |
| 492 | /// Mark the entry as a global destructor. |
| 493 | OMPTargetRegionEntryDtor = 0x04, |
| 494 | }; |
| 495 | |
| 496 | /// Target region entries info. |
| 497 | class OffloadEntryInfoTargetRegion final : public OffloadEntryInfo { |
| 498 | /// Address that can be used as the ID of the entry. |
| 499 | llvm::Constant *ID = nullptr; |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 500 | |
| 501 | public: |
| 502 | OffloadEntryInfoTargetRegion() |
Alexey Bataev | 03f270c | 2018-03-30 18:31:07 +0000 | [diff] [blame] | 503 | : OffloadEntryInfo(OffloadingEntryInfoTargetRegion) {} |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 504 | explicit OffloadEntryInfoTargetRegion(unsigned Order, |
| 505 | llvm::Constant *Addr, |
Alexey Bataev | 34f8a70 | 2018-03-28 14:28:54 +0000 | [diff] [blame] | 506 | llvm::Constant *ID, |
| 507 | OMPTargetRegionEntryKind Flags) |
| 508 | : OffloadEntryInfo(OffloadingEntryInfoTargetRegion, Order, Flags), |
Alexey Bataev | 03f270c | 2018-03-30 18:31:07 +0000 | [diff] [blame] | 509 | ID(ID) { |
| 510 | setAddress(Addr); |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 511 | } |
Alexey Bataev | 03f270c | 2018-03-30 18:31:07 +0000 | [diff] [blame] | 512 | |
| 513 | llvm::Constant *getID() const { return ID; } |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 514 | void setID(llvm::Constant *V) { |
Alexey Bataev | 34f8a70 | 2018-03-28 14:28:54 +0000 | [diff] [blame] | 515 | assert(!ID && "ID has been set before!"); |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 516 | ID = V; |
| 517 | } |
| 518 | static bool classof(const OffloadEntryInfo *Info) { |
Alexey Bataev | 34f8a70 | 2018-03-28 14:28:54 +0000 | [diff] [blame] | 519 | return Info->getKind() == OffloadingEntryInfoTargetRegion; |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 520 | } |
| 521 | }; |
Alexey Bataev | 03f270c | 2018-03-30 18:31:07 +0000 | [diff] [blame] | 522 | |
| 523 | /// Initialize target region entry. |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 524 | void initializeTargetRegionEntryInfo(unsigned DeviceID, unsigned FileID, |
| 525 | StringRef ParentName, unsigned LineNum, |
Samuel Antao | 2de62b0 | 2016-02-13 23:35:10 +0000 | [diff] [blame] | 526 | unsigned Order); |
Alexey Bataev | 03f270c | 2018-03-30 18:31:07 +0000 | [diff] [blame] | 527 | /// Register target region entry. |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 528 | void registerTargetRegionEntryInfo(unsigned DeviceID, unsigned FileID, |
| 529 | StringRef ParentName, unsigned LineNum, |
Samuel Antao | f83efdb | 2017-01-05 16:02:49 +0000 | [diff] [blame] | 530 | llvm::Constant *Addr, llvm::Constant *ID, |
Alexey Bataev | 34f8a70 | 2018-03-28 14:28:54 +0000 | [diff] [blame] | 531 | OMPTargetRegionEntryKind Flags); |
Alexey Bataev | 03f270c | 2018-03-30 18:31:07 +0000 | [diff] [blame] | 532 | /// Return true if a target region entry with the provided information |
| 533 | /// exists. |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 534 | bool hasTargetRegionEntryInfo(unsigned DeviceID, unsigned FileID, |
Samuel Antao | 2de62b0 | 2016-02-13 23:35:10 +0000 | [diff] [blame] | 535 | StringRef ParentName, unsigned LineNum) const; |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 536 | /// brief Applies action \a Action on all registered entries. |
| 537 | typedef llvm::function_ref<void(unsigned, unsigned, StringRef, unsigned, |
Alexey Bataev | 03f270c | 2018-03-30 18:31:07 +0000 | [diff] [blame] | 538 | const OffloadEntryInfoTargetRegion &)> |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 539 | OffloadTargetRegionEntryInfoActTy; |
| 540 | void actOnTargetRegionEntriesInfo( |
| 541 | const OffloadTargetRegionEntryInfoActTy &Action); |
| 542 | |
Alexey Bataev | 03f270c | 2018-03-30 18:31:07 +0000 | [diff] [blame] | 543 | // |
| 544 | // Device global variable entries related. |
| 545 | // |
| 546 | |
| 547 | /// Kind of the global variable entry.. |
| 548 | enum OMPTargetGlobalVarEntryKind : uint32_t { |
| 549 | /// Mark the entry as a to declare target. |
| 550 | OMPTargetGlobalVarEntryTo = 0x0, |
Alexey Bataev | c52f01d | 2018-07-16 20:05:25 +0000 | [diff] [blame] | 551 | /// Mark the entry as a to declare target link. |
| 552 | OMPTargetGlobalVarEntryLink = 0x1, |
Alexey Bataev | 03f270c | 2018-03-30 18:31:07 +0000 | [diff] [blame] | 553 | }; |
| 554 | |
| 555 | /// Device global variable entries info. |
| 556 | class OffloadEntryInfoDeviceGlobalVar final : public OffloadEntryInfo { |
| 557 | /// Type of the global variable. |
| 558 | CharUnits VarSize; |
| 559 | llvm::GlobalValue::LinkageTypes Linkage; |
| 560 | |
| 561 | public: |
| 562 | OffloadEntryInfoDeviceGlobalVar() |
| 563 | : OffloadEntryInfo(OffloadingEntryInfoDeviceGlobalVar) {} |
| 564 | explicit OffloadEntryInfoDeviceGlobalVar(unsigned Order, |
| 565 | OMPTargetGlobalVarEntryKind Flags) |
| 566 | : OffloadEntryInfo(OffloadingEntryInfoDeviceGlobalVar, Order, Flags) {} |
| 567 | explicit OffloadEntryInfoDeviceGlobalVar( |
| 568 | unsigned Order, llvm::Constant *Addr, CharUnits VarSize, |
| 569 | OMPTargetGlobalVarEntryKind Flags, |
| 570 | llvm::GlobalValue::LinkageTypes Linkage) |
| 571 | : OffloadEntryInfo(OffloadingEntryInfoDeviceGlobalVar, Order, Flags), |
| 572 | VarSize(VarSize), Linkage(Linkage) { |
| 573 | setAddress(Addr); |
| 574 | } |
| 575 | |
| 576 | CharUnits getVarSize() const { return VarSize; } |
| 577 | void setVarSize(CharUnits Size) { VarSize = Size; } |
| 578 | llvm::GlobalValue::LinkageTypes getLinkage() const { return Linkage; } |
| 579 | void setLinkage(llvm::GlobalValue::LinkageTypes LT) { Linkage = LT; } |
| 580 | static bool classof(const OffloadEntryInfo *Info) { |
| 581 | return Info->getKind() == OffloadingEntryInfoDeviceGlobalVar; |
| 582 | } |
| 583 | }; |
| 584 | |
| 585 | /// Initialize device global variable entry. |
| 586 | void initializeDeviceGlobalVarEntryInfo(StringRef Name, |
| 587 | OMPTargetGlobalVarEntryKind Flags, |
| 588 | unsigned Order); |
| 589 | |
| 590 | /// Register device global variable entry. |
| 591 | void |
| 592 | registerDeviceGlobalVarEntryInfo(StringRef VarName, llvm::Constant *Addr, |
| 593 | CharUnits VarSize, |
| 594 | OMPTargetGlobalVarEntryKind Flags, |
| 595 | llvm::GlobalValue::LinkageTypes Linkage); |
| 596 | /// Checks if the variable with the given name has been registered already. |
| 597 | bool hasDeviceGlobalVarEntryInfo(StringRef VarName) const { |
| 598 | return OffloadEntriesDeviceGlobalVar.count(VarName) > 0; |
| 599 | } |
| 600 | /// Applies action \a Action on all registered entries. |
| 601 | typedef llvm::function_ref<void(StringRef, |
| 602 | const OffloadEntryInfoDeviceGlobalVar &)> |
| 603 | OffloadDeviceGlobalVarEntryInfoActTy; |
| 604 | void actOnDeviceGlobalVarEntriesInfo( |
| 605 | const OffloadDeviceGlobalVarEntryInfoActTy &Action); |
| 606 | |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 607 | private: |
| 608 | // Storage for target region entries kind. The storage is to be indexed by |
Samuel Antao | 2de62b0 | 2016-02-13 23:35:10 +0000 | [diff] [blame] | 609 | // file ID, device ID, parent function name and line number. |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 610 | typedef llvm::DenseMap<unsigned, OffloadEntryInfoTargetRegion> |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 611 | OffloadEntriesTargetRegionPerLine; |
| 612 | typedef llvm::StringMap<OffloadEntriesTargetRegionPerLine> |
| 613 | OffloadEntriesTargetRegionPerParentName; |
| 614 | typedef llvm::DenseMap<unsigned, OffloadEntriesTargetRegionPerParentName> |
| 615 | OffloadEntriesTargetRegionPerFile; |
| 616 | typedef llvm::DenseMap<unsigned, OffloadEntriesTargetRegionPerFile> |
| 617 | OffloadEntriesTargetRegionPerDevice; |
| 618 | typedef OffloadEntriesTargetRegionPerDevice OffloadEntriesTargetRegionTy; |
| 619 | OffloadEntriesTargetRegionTy OffloadEntriesTargetRegion; |
Alexey Bataev | 03f270c | 2018-03-30 18:31:07 +0000 | [diff] [blame] | 620 | /// Storage for device global variable entries kind. The storage is to be |
| 621 | /// indexed by mangled name. |
| 622 | typedef llvm::StringMap<OffloadEntryInfoDeviceGlobalVar> |
| 623 | OffloadEntriesDeviceGlobalVarTy; |
| 624 | OffloadEntriesDeviceGlobalVarTy OffloadEntriesDeviceGlobalVar; |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 625 | }; |
| 626 | OffloadEntriesInfoManagerTy OffloadEntriesInfoManager; |
| 627 | |
Alexey Bataev | 4f4bf7c | 2018-03-15 15:47:20 +0000 | [diff] [blame] | 628 | bool ShouldMarkAsGlobal = true; |
Alexey Bataev | 2a6f3f5 | 2018-11-07 19:11:14 +0000 | [diff] [blame] | 629 | /// List of the emitted functions. |
| 630 | llvm::StringSet<> AlreadyEmittedTargetFunctions; |
| 631 | /// List of the global variables with their addresses that should not be |
| 632 | /// emitted for the target. |
| 633 | llvm::StringMap<llvm::WeakTrackingVH> EmittedNonTargetVariables; |
Alexey Bataev | 4f4bf7c | 2018-03-15 15:47:20 +0000 | [diff] [blame] | 634 | |
Alexey Bataev | bf8fe71 | 2018-08-07 16:14:36 +0000 | [diff] [blame] | 635 | /// List of variables that can become declare target implicitly and, thus, |
| 636 | /// must be emitted. |
| 637 | llvm::SmallDenseSet<const VarDecl *> DeferredGlobalVariables; |
| 638 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 639 | /// Creates and registers offloading binary descriptor for the current |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 640 | /// compilation unit. The function that does the registration is returned. |
| 641 | llvm::Function *createOffloadingBinaryDescriptorRegistration(); |
| 642 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 643 | /// Creates all the offload entries in the current compilation unit |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 644 | /// along with the associated metadata. |
| 645 | void createOffloadEntriesAndInfoMetadata(); |
| 646 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 647 | /// Loads all the offload entries information from the host IR |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 648 | /// metadata. |
| 649 | void loadOffloadInfoMetadata(); |
| 650 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 651 | /// Returns __tgt_offload_entry type. |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 652 | QualType getTgtOffloadEntryQTy(); |
| 653 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 654 | /// Returns __tgt_device_image type. |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 655 | QualType getTgtDeviceImageQTy(); |
| 656 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 657 | /// Returns __tgt_bin_desc type. |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 658 | QualType getTgtBinaryDescriptorQTy(); |
| 659 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 660 | /// Start scanning from statement \a S and and emit all target regions |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 661 | /// found along the way. |
| 662 | /// \param S Starting statement. |
| 663 | /// \param ParentName Name of the function declaration that is being scanned. |
| 664 | void scanForTargetRegionsFunctions(const Stmt *S, StringRef ParentName); |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 665 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 666 | /// Build type kmp_routine_entry_t (if not built yet). |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 667 | void emitKmpRoutineEntryT(QualType KmpInt32Ty); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 668 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 669 | /// Returns pointer to kmpc_micro type. |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 670 | llvm::Type *getKmpc_MicroPointerTy(); |
| 671 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 672 | /// Returns specified OpenMP runtime function. |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 673 | /// \param Function OpenMP runtime function. |
| 674 | /// \return Specified function. |
James Y Knight | 9871db0 | 2019-02-05 16:42:33 +0000 | [diff] [blame] | 675 | llvm::FunctionCallee createRuntimeFunction(unsigned Function); |
Alexey Bataev | 3a3bf0b | 2014-09-22 10:01:53 +0000 | [diff] [blame] | 676 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 677 | /// Returns __kmpc_for_static_init_* runtime function for the specified |
Alexander Musman | 21212e4 | 2015-03-13 10:38:23 +0000 | [diff] [blame] | 678 | /// size \a IVSize and sign \a IVSigned. |
James Y Knight | 9871db0 | 2019-02-05 16:42:33 +0000 | [diff] [blame] | 679 | llvm::FunctionCallee createForStaticInitFunction(unsigned IVSize, |
| 680 | bool IVSigned); |
Alexander Musman | 21212e4 | 2015-03-13 10:38:23 +0000 | [diff] [blame] | 681 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 682 | /// Returns __kmpc_dispatch_init_* runtime function for the specified |
Alexander Musman | 92bdaab | 2015-03-12 13:37:50 +0000 | [diff] [blame] | 683 | /// size \a IVSize and sign \a IVSigned. |
James Y Knight | 9871db0 | 2019-02-05 16:42:33 +0000 | [diff] [blame] | 684 | llvm::FunctionCallee createDispatchInitFunction(unsigned IVSize, |
| 685 | bool IVSigned); |
Alexander Musman | 92bdaab | 2015-03-12 13:37:50 +0000 | [diff] [blame] | 686 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 687 | /// Returns __kmpc_dispatch_next_* runtime function for the specified |
Alexander Musman | 92bdaab | 2015-03-12 13:37:50 +0000 | [diff] [blame] | 688 | /// size \a IVSize and sign \a IVSigned. |
James Y Knight | 9871db0 | 2019-02-05 16:42:33 +0000 | [diff] [blame] | 689 | llvm::FunctionCallee createDispatchNextFunction(unsigned IVSize, |
| 690 | bool IVSigned); |
Alexander Musman | 92bdaab | 2015-03-12 13:37:50 +0000 | [diff] [blame] | 691 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 692 | /// Returns __kmpc_dispatch_fini_* runtime function for the specified |
Alexey Bataev | 98eb6e3 | 2015-04-22 11:15:40 +0000 | [diff] [blame] | 693 | /// size \a IVSize and sign \a IVSigned. |
James Y Knight | 9871db0 | 2019-02-05 16:42:33 +0000 | [diff] [blame] | 694 | llvm::FunctionCallee createDispatchFiniFunction(unsigned IVSize, |
| 695 | bool IVSigned); |
Alexey Bataev | 98eb6e3 | 2015-04-22 11:15:40 +0000 | [diff] [blame] | 696 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 697 | /// If the specified mangled name is not in the module, create and |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 698 | /// return threadprivate cache object. This object is a pointer's worth of |
| 699 | /// storage that's reserved for use by the OpenMP runtime. |
NAKAMURA Takumi | cdcbfba | 2014-11-11 07:58:06 +0000 | [diff] [blame] | 700 | /// \param VD Threadprivate variable. |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 701 | /// \return Cache variable for the specified threadprivate. |
| 702 | llvm::Constant *getOrCreateThreadPrivateCache(const VarDecl *VD); |
| 703 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 704 | /// Gets (if variable with the given name already exist) or creates |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 705 | /// internal global variable with the specified Name. The created variable has |
| 706 | /// linkage CommonLinkage by default and is initialized by null value. |
| 707 | /// \param Ty Type of the global variable. If it is exist already the type |
| 708 | /// must be the same. |
| 709 | /// \param Name Name of the variable. |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 710 | llvm::Constant *getOrCreateInternalVariable(llvm::Type *Ty, |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 711 | const llvm::Twine &Name); |
| 712 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 713 | /// Set of threadprivate variables with the generated initializer. |
Alexey Bataev | 2a6f3f5 | 2018-11-07 19:11:14 +0000 | [diff] [blame] | 714 | llvm::StringSet<> ThreadPrivateWithDefinition; |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 715 | |
Alexey Bataev | 34f8a70 | 2018-03-28 14:28:54 +0000 | [diff] [blame] | 716 | /// Set of declare target variables with the generated initializer. |
Alexey Bataev | 2a6f3f5 | 2018-11-07 19:11:14 +0000 | [diff] [blame] | 717 | llvm::StringSet<> DeclareTargetWithDefinition; |
Alexey Bataev | 34f8a70 | 2018-03-28 14:28:54 +0000 | [diff] [blame] | 718 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 719 | /// Emits initialization code for the threadprivate variables. |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 720 | /// \param VDAddr Address of the global variable \a VD. |
| 721 | /// \param Ctor Pointer to a global init function for \a VD. |
| 722 | /// \param CopyCtor Pointer to a global copy function for \a VD. |
| 723 | /// \param Dtor Pointer to a global destructor function for \a VD. |
| 724 | /// \param Loc Location of threadprivate declaration. |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 725 | void emitThreadPrivateVarInit(CodeGenFunction &CGF, Address VDAddr, |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 726 | llvm::Value *Ctor, llvm::Value *CopyCtor, |
| 727 | llvm::Value *Dtor, SourceLocation Loc); |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 728 | |
Alexey Bataev | 24b5bae | 2016-04-28 09:23:51 +0000 | [diff] [blame] | 729 | struct TaskResultTy { |
| 730 | llvm::Value *NewTask = nullptr; |
James Y Knight | 9871db0 | 2019-02-05 16:42:33 +0000 | [diff] [blame] | 731 | llvm::Function *TaskEntry = nullptr; |
Alexey Bataev | 24b5bae | 2016-04-28 09:23:51 +0000 | [diff] [blame] | 732 | llvm::Value *NewTaskNewTaskTTy = nullptr; |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 733 | LValue TDBase; |
Alexey Bataev | a4fa0b8 | 2018-04-16 17:59:34 +0000 | [diff] [blame] | 734 | const RecordDecl *KmpTaskTQTyRD = nullptr; |
Alexey Bataev | f93095a | 2016-05-05 08:46:22 +0000 | [diff] [blame] | 735 | llvm::Value *TaskDupFn = nullptr; |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 736 | }; |
| 737 | /// Emit task region for the task directive. The task region is emitted in |
| 738 | /// several steps: |
| 739 | /// 1. Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32 |
| 740 | /// gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds, |
| 741 | /// kmp_routine_entry_t *task_entry). Here task_entry is a pointer to the |
| 742 | /// function: |
| 743 | /// kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) { |
| 744 | /// TaskFunction(gtid, tt->part_id, tt->shareds); |
| 745 | /// return 0; |
| 746 | /// } |
| 747 | /// 2. Copy a list of shared variables to field shareds of the resulting |
| 748 | /// structure kmp_task_t returned by the previous call (if any). |
| 749 | /// 3. Copy a pointer to destructions function to field destructions of the |
| 750 | /// resulting structure kmp_task_t. |
| 751 | /// \param D Current task directive. |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 752 | /// \param TaskFunction An LLVM function with type void (*)(i32 /*gtid*/, i32 |
| 753 | /// /*part_id*/, captured_struct */*__context*/); |
| 754 | /// \param SharedsTy A type which contains references the shared variables. |
| 755 | /// \param Shareds Context with the list of shared variables from the \p |
| 756 | /// TaskFunction. |
Alexey Bataev | 24b5bae | 2016-04-28 09:23:51 +0000 | [diff] [blame] | 757 | /// \param Data Additional data for task generation like tiednsee, final |
| 758 | /// state, list of privates etc. |
| 759 | TaskResultTy emitTaskInit(CodeGenFunction &CGF, SourceLocation Loc, |
| 760 | const OMPExecutableDirective &D, |
James Y Knight | 9871db0 | 2019-02-05 16:42:33 +0000 | [diff] [blame] | 761 | llvm::Function *TaskFunction, QualType SharedsTy, |
Alexey Bataev | 24b5bae | 2016-04-28 09:23:51 +0000 | [diff] [blame] | 762 | Address Shareds, const OMPTaskDataTy &Data); |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 763 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 764 | public: |
Alexey Bataev | 18fa232 | 2018-05-02 14:20:50 +0000 | [diff] [blame] | 765 | explicit CGOpenMPRuntime(CodeGenModule &CGM) |
| 766 | : CGOpenMPRuntime(CGM, ".", ".") {} |
Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 767 | virtual ~CGOpenMPRuntime() {} |
Alexey Bataev | 9179755 | 2015-03-18 04:13:55 +0000 | [diff] [blame] | 768 | virtual void clear(); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 769 | |
Alexey Bataev | 18fa232 | 2018-05-02 14:20:50 +0000 | [diff] [blame] | 770 | /// Get the platform-specific name separator. |
| 771 | std::string getName(ArrayRef<StringRef> Parts) const; |
| 772 | |
Alexey Bataev | c5b1d32 | 2016-03-04 09:22:22 +0000 | [diff] [blame] | 773 | /// Emit code for the specified user defined reduction construct. |
| 774 | virtual void emitUserDefinedReduction(CodeGenFunction *CGF, |
| 775 | const OMPDeclareReductionDecl *D); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 776 | /// Get combiner/initializer for the specified user-defined reduction, if any. |
| 777 | virtual std::pair<llvm::Function *, llvm::Function *> |
| 778 | getUserDefinedReduction(const OMPDeclareReductionDecl *D); |
Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 779 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 780 | /// Emits outlined function for the specified OpenMP parallel directive |
Alexey Bataev | 6f1ffc0 | 2015-04-10 04:50:10 +0000 | [diff] [blame] | 781 | /// \a D. This outlined function has type void(*)(kmp_int32 *ThreadID, |
| 782 | /// kmp_int32 BoundID, struct context_vars*). |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 783 | /// \param D OpenMP directive. |
| 784 | /// \param ThreadIDVar Variable for thread id in the current OpenMP region. |
Alexey Bataev | 81c7ea0 | 2015-07-03 09:56:58 +0000 | [diff] [blame] | 785 | /// \param InnermostKind Kind of innermost directive (for simple directives it |
| 786 | /// is a directive itself, for combined - its innermost directive). |
Alexey Bataev | 6f1ffc0 | 2015-04-10 04:50:10 +0000 | [diff] [blame] | 787 | /// \param CodeGen Code generation sequence for the \a D directive. |
James Y Knight | 9871db0 | 2019-02-05 16:42:33 +0000 | [diff] [blame] | 788 | virtual llvm::Function *emitParallelOutlinedFunction( |
Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 789 | const OMPExecutableDirective &D, const VarDecl *ThreadIDVar, |
| 790 | OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen); |
| 791 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 792 | /// Emits outlined function for the specified OpenMP teams directive |
Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 793 | /// \a D. This outlined function has type void(*)(kmp_int32 *ThreadID, |
| 794 | /// kmp_int32 BoundID, struct context_vars*). |
| 795 | /// \param D OpenMP directive. |
| 796 | /// \param ThreadIDVar Variable for thread id in the current OpenMP region. |
| 797 | /// \param InnermostKind Kind of innermost directive (for simple directives it |
| 798 | /// is a directive itself, for combined - its innermost directive). |
| 799 | /// \param CodeGen Code generation sequence for the \a D directive. |
James Y Knight | 9871db0 | 2019-02-05 16:42:33 +0000 | [diff] [blame] | 800 | virtual llvm::Function *emitTeamsOutlinedFunction( |
Alexey Bataev | 81c7ea0 | 2015-07-03 09:56:58 +0000 | [diff] [blame] | 801 | const OMPExecutableDirective &D, const VarDecl *ThreadIDVar, |
| 802 | OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen); |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 803 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 804 | /// Emits outlined function for the OpenMP task directive \a D. This |
Alexey Bataev | 48591dd | 2016-04-20 04:01:36 +0000 | [diff] [blame] | 805 | /// outlined function has type void(*)(kmp_int32 ThreadID, struct task_t* |
| 806 | /// TaskT). |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 807 | /// \param D OpenMP directive. |
| 808 | /// \param ThreadIDVar Variable for thread id in the current OpenMP region. |
Alexey Bataev | 48591dd | 2016-04-20 04:01:36 +0000 | [diff] [blame] | 809 | /// \param PartIDVar Variable for partition id in the current OpenMP untied |
| 810 | /// task region. |
| 811 | /// \param TaskTVar Variable for task_t argument. |
Alexey Bataev | 81c7ea0 | 2015-07-03 09:56:58 +0000 | [diff] [blame] | 812 | /// \param InnermostKind Kind of innermost directive (for simple directives it |
| 813 | /// is a directive itself, for combined - its innermost directive). |
Alexey Bataev | 6f1ffc0 | 2015-04-10 04:50:10 +0000 | [diff] [blame] | 814 | /// \param CodeGen Code generation sequence for the \a D directive. |
Alexey Bataev | 48591dd | 2016-04-20 04:01:36 +0000 | [diff] [blame] | 815 | /// \param Tied true if task is generated for tied task, false otherwise. |
| 816 | /// \param NumberOfParts Number of parts in untied task. Ignored for tied |
| 817 | /// tasks. |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 818 | /// |
James Y Knight | 9871db0 | 2019-02-05 16:42:33 +0000 | [diff] [blame] | 819 | virtual llvm::Function *emitTaskOutlinedFunction( |
Alexey Bataev | 81c7ea0 | 2015-07-03 09:56:58 +0000 | [diff] [blame] | 820 | const OMPExecutableDirective &D, const VarDecl *ThreadIDVar, |
Alexey Bataev | 48591dd | 2016-04-20 04:01:36 +0000 | [diff] [blame] | 821 | const VarDecl *PartIDVar, const VarDecl *TaskTVar, |
| 822 | OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen, |
| 823 | bool Tied, unsigned &NumberOfParts); |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 824 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 825 | /// Cleans up references to the objects in finished function. |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 826 | /// |
Gheorghe-Teodor Bercea | d3dcf2f | 2018-03-14 14:17:45 +0000 | [diff] [blame] | 827 | virtual void functionFinished(CodeGenFunction &CGF); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 828 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 829 | /// Emits code for parallel or serial call of the \a OutlinedFn with |
Alexey Bataev | 1d67713 | 2015-04-22 13:57:31 +0000 | [diff] [blame] | 830 | /// variables captured in a record which address is stored in \a |
| 831 | /// CapturedStruct. |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 832 | /// \param OutlinedFn Outlined function to be run in parallel threads. Type of |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 833 | /// this function is void(*)(kmp_int32 *, kmp_int32, struct context_vars*). |
NAKAMURA Takumi | 62f0eb5 | 2015-09-11 08:13:32 +0000 | [diff] [blame] | 834 | /// \param CapturedVars A pointer to the record with the references to |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 835 | /// variables used in \a OutlinedFn function. |
Alexey Bataev | 1d67713 | 2015-04-22 13:57:31 +0000 | [diff] [blame] | 836 | /// \param IfCond Condition in the associated 'if' clause, if it was |
| 837 | /// specified, nullptr otherwise. |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 838 | /// |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 839 | virtual void emitParallelCall(CodeGenFunction &CGF, SourceLocation Loc, |
James Y Knight | 9871db0 | 2019-02-05 16:42:33 +0000 | [diff] [blame] | 840 | llvm::Function *OutlinedFn, |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 841 | ArrayRef<llvm::Value *> CapturedVars, |
| 842 | const Expr *IfCond); |
Alexey Bataev | d74d060 | 2014-10-13 06:02:40 +0000 | [diff] [blame] | 843 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 844 | /// Emits a critical region. |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 845 | /// \param CriticalName Name of the critical region. |
Alexey Bataev | 75ddfab | 2014-12-01 11:32:38 +0000 | [diff] [blame] | 846 | /// \param CriticalOpGen Generator for the statement associated with the given |
| 847 | /// critical region. |
Alexey Bataev | fc57d16 | 2015-12-15 10:55:09 +0000 | [diff] [blame] | 848 | /// \param Hint Value of the 'hint' clause (optional). |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 849 | virtual void emitCriticalRegion(CodeGenFunction &CGF, StringRef CriticalName, |
Alexey Bataev | 6f1ffc0 | 2015-04-10 04:50:10 +0000 | [diff] [blame] | 850 | const RegionCodeGenTy &CriticalOpGen, |
Alexey Bataev | fc57d16 | 2015-12-15 10:55:09 +0000 | [diff] [blame] | 851 | SourceLocation Loc, |
| 852 | const Expr *Hint = nullptr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 853 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 854 | /// Emits a master region. |
Alexey Bataev | 8d69065 | 2014-12-04 07:23:53 +0000 | [diff] [blame] | 855 | /// \param MasterOpGen Generator for the statement associated with the given |
| 856 | /// master region. |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 857 | virtual void emitMasterRegion(CodeGenFunction &CGF, |
Alexey Bataev | 6f1ffc0 | 2015-04-10 04:50:10 +0000 | [diff] [blame] | 858 | const RegionCodeGenTy &MasterOpGen, |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 859 | SourceLocation Loc); |
Alexey Bataev | 8d69065 | 2014-12-04 07:23:53 +0000 | [diff] [blame] | 860 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 861 | /// Emits code for a taskyield directive. |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 862 | virtual void emitTaskyieldCall(CodeGenFunction &CGF, SourceLocation Loc); |
Alexey Bataev | 9f797f3 | 2015-02-05 05:57:51 +0000 | [diff] [blame] | 863 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 864 | /// Emit a taskgroup region. |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 865 | /// \param TaskgroupOpGen Generator for the statement associated with the |
| 866 | /// given taskgroup region. |
| 867 | virtual void emitTaskgroupRegion(CodeGenFunction &CGF, |
| 868 | const RegionCodeGenTy &TaskgroupOpGen, |
| 869 | SourceLocation Loc); |
| 870 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 871 | /// Emits a single region. |
Alexey Bataev | 6956e2e | 2015-02-05 06:35:41 +0000 | [diff] [blame] | 872 | /// \param SingleOpGen Generator for the statement associated with the given |
| 873 | /// single region. |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 874 | virtual void emitSingleRegion(CodeGenFunction &CGF, |
Alexey Bataev | 6f1ffc0 | 2015-04-10 04:50:10 +0000 | [diff] [blame] | 875 | const RegionCodeGenTy &SingleOpGen, |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 876 | SourceLocation Loc, |
| 877 | ArrayRef<const Expr *> CopyprivateVars, |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 878 | ArrayRef<const Expr *> DestExprs, |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 879 | ArrayRef<const Expr *> SrcExprs, |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 880 | ArrayRef<const Expr *> AssignmentOps); |
Alexey Bataev | 6956e2e | 2015-02-05 06:35:41 +0000 | [diff] [blame] | 881 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 882 | /// Emit an ordered region. |
Alexey Bataev | 98eb6e3 | 2015-04-22 11:15:40 +0000 | [diff] [blame] | 883 | /// \param OrderedOpGen Generator for the statement associated with the given |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 884 | /// ordered region. |
Alexey Bataev | 98eb6e3 | 2015-04-22 11:15:40 +0000 | [diff] [blame] | 885 | virtual void emitOrderedRegion(CodeGenFunction &CGF, |
| 886 | const RegionCodeGenTy &OrderedOpGen, |
Alexey Bataev | 5f600d6 | 2015-09-29 03:48:57 +0000 | [diff] [blame] | 887 | SourceLocation Loc, bool IsThreads); |
Alexey Bataev | 98eb6e3 | 2015-04-22 11:15:40 +0000 | [diff] [blame] | 888 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 889 | /// Emit an implicit/explicit barrier for OpenMP threads. |
Alexey Bataev | f268568 | 2015-03-30 04:30:22 +0000 | [diff] [blame] | 890 | /// \param Kind Directive for which this implicit barrier call must be |
| 891 | /// generated. Must be OMPD_barrier for explicit barrier generation. |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 892 | /// \param EmitChecks true if need to emit checks for cancellation barriers. |
| 893 | /// \param ForceSimpleCall true simple barrier call must be emitted, false if |
| 894 | /// runtime class decides which one to emit (simple or with cancellation |
| 895 | /// checks). |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 896 | /// |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 897 | virtual void emitBarrierCall(CodeGenFunction &CGF, SourceLocation Loc, |
Alexey Bataev | 81c7ea0 | 2015-07-03 09:56:58 +0000 | [diff] [blame] | 898 | OpenMPDirectiveKind Kind, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 899 | bool EmitChecks = true, |
| 900 | bool ForceSimpleCall = false); |
Alexey Bataev | b205978 | 2014-10-13 08:23:51 +0000 | [diff] [blame] | 901 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 902 | /// Check if the specified \a ScheduleKind is static non-chunked. |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 903 | /// This kind of worksharing directive is emitted without outer loop. |
| 904 | /// \param ScheduleKind Schedule kind specified in the 'schedule' clause. |
| 905 | /// \param Chunked True if chunk is specified in the clause. |
| 906 | /// |
| 907 | virtual bool isStaticNonchunked(OpenMPScheduleClauseKind ScheduleKind, |
| 908 | bool Chunked) const; |
| 909 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 910 | /// Check if the specified \a ScheduleKind is static non-chunked. |
Carlo Bertolli | fc35ad2 | 2016-03-07 16:04:49 +0000 | [diff] [blame] | 911 | /// This kind of distribute directive is emitted without outer loop. |
| 912 | /// \param ScheduleKind Schedule kind specified in the 'dist_schedule' clause. |
| 913 | /// \param Chunked True if chunk is specified in the clause. |
| 914 | /// |
| 915 | virtual bool isStaticNonchunked(OpenMPDistScheduleClauseKind ScheduleKind, |
| 916 | bool Chunked) const; |
| 917 | |
Gheorghe-Teodor Bercea | e925676 | 2018-10-29 15:45:47 +0000 | [diff] [blame] | 918 | /// Check if the specified \a ScheduleKind is static chunked. |
| 919 | /// \param ScheduleKind Schedule kind specified in the 'schedule' clause. |
| 920 | /// \param Chunked True if chunk is specified in the clause. |
| 921 | /// |
| 922 | virtual bool isStaticChunked(OpenMPScheduleClauseKind ScheduleKind, |
| 923 | bool Chunked) const; |
| 924 | |
| 925 | /// Check if the specified \a ScheduleKind is static non-chunked. |
| 926 | /// \param ScheduleKind Schedule kind specified in the 'dist_schedule' clause. |
| 927 | /// \param Chunked True if chunk is specified in the clause. |
| 928 | /// |
| 929 | virtual bool isStaticChunked(OpenMPDistScheduleClauseKind ScheduleKind, |
| 930 | bool Chunked) const; |
| 931 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 932 | /// Check if the specified \a ScheduleKind is dynamic. |
Alexander Musman | df7a8e2 | 2015-01-22 08:49:35 +0000 | [diff] [blame] | 933 | /// This kind of worksharing directive is emitted without outer loop. |
| 934 | /// \param ScheduleKind Schedule Kind specified in the 'schedule' clause. |
| 935 | /// |
| 936 | virtual bool isDynamic(OpenMPScheduleClauseKind ScheduleKind) const; |
| 937 | |
Carlo Bertolli | b0ff0a6 | 2017-04-25 17:52:12 +0000 | [diff] [blame] | 938 | /// struct with the values to be passed to the dispatch runtime function |
| 939 | struct DispatchRTInput { |
| 940 | /// Loop lower bound |
| 941 | llvm::Value *LB = nullptr; |
| 942 | /// Loop upper bound |
| 943 | llvm::Value *UB = nullptr; |
| 944 | /// Chunk size specified using 'schedule' clause (nullptr if chunk |
| 945 | /// was not specified) |
| 946 | llvm::Value *Chunk = nullptr; |
| 947 | DispatchRTInput() = default; |
| 948 | DispatchRTInput(llvm::Value *LB, llvm::Value *UB, llvm::Value *Chunk) |
| 949 | : LB(LB), UB(UB), Chunk(Chunk) {} |
| 950 | }; |
| 951 | |
| 952 | /// Call the appropriate runtime routine to initialize it before start |
| 953 | /// of loop. |
| 954 | |
| 955 | /// This is used for non static scheduled types and when the ordered |
| 956 | /// clause is present on the loop construct. |
| 957 | /// Depending on the loop schedule, it is necessary to call some runtime |
| 958 | /// routine before start of the OpenMP loop to get the loop upper / lower |
| 959 | /// bounds \a LB and \a UB and stride \a ST. |
| 960 | /// |
| 961 | /// \param CGF Reference to current CodeGenFunction. |
| 962 | /// \param Loc Clang source location. |
| 963 | /// \param ScheduleKind Schedule kind, specified by the 'schedule' clause. |
| 964 | /// \param IVSize Size of the iteration variable in bits. |
Simon Pilgrim | 6c0eeff | 2017-07-13 17:34:44 +0000 | [diff] [blame] | 965 | /// \param IVSigned Sign of the iteration variable. |
Carlo Bertolli | b0ff0a6 | 2017-04-25 17:52:12 +0000 | [diff] [blame] | 966 | /// \param Ordered true if loop is ordered, false otherwise. |
| 967 | /// \param DispatchValues struct containing llvm values for lower bound, upper |
| 968 | /// bound, and chunk expression. |
| 969 | /// For the default (nullptr) value, the chunk 1 will be used. |
| 970 | /// |
NAKAMURA Takumi | ff7a925 | 2015-09-08 09:42:41 +0000 | [diff] [blame] | 971 | virtual void emitForDispatchInit(CodeGenFunction &CGF, SourceLocation Loc, |
Alexey Bataev | 9ebd742 | 2016-05-10 09:57:36 +0000 | [diff] [blame] | 972 | const OpenMPScheduleTy &ScheduleKind, |
| 973 | unsigned IVSize, bool IVSigned, bool Ordered, |
Carlo Bertolli | b0ff0a6 | 2017-04-25 17:52:12 +0000 | [diff] [blame] | 974 | const DispatchRTInput &DispatchValues); |
NAKAMURA Takumi | ff7a925 | 2015-09-08 09:42:41 +0000 | [diff] [blame] | 975 | |
Alexey Bataev | 0f87dbe | 2017-08-14 17:56:13 +0000 | [diff] [blame] | 976 | /// Struct with the values to be passed to the static runtime function |
| 977 | struct StaticRTInput { |
| 978 | /// Size of the iteration variable in bits. |
| 979 | unsigned IVSize = 0; |
| 980 | /// Sign of the iteration variable. |
| 981 | bool IVSigned = false; |
| 982 | /// true if loop is ordered, false otherwise. |
| 983 | bool Ordered = false; |
| 984 | /// Address of the output variable in which the flag of the last iteration |
| 985 | /// is returned. |
| 986 | Address IL = Address::invalid(); |
| 987 | /// Address of the output variable in which the lower iteration number is |
| 988 | /// returned. |
| 989 | Address LB = Address::invalid(); |
| 990 | /// Address of the output variable in which the upper iteration number is |
| 991 | /// returned. |
| 992 | Address UB = Address::invalid(); |
| 993 | /// Address of the output variable in which the stride value is returned |
| 994 | /// necessary to generated the static_chunked scheduled loop. |
| 995 | Address ST = Address::invalid(); |
| 996 | /// Value of the chunk for the static_chunked scheduled loop. For the |
| 997 | /// default (nullptr) value, the chunk 1 will be used. |
| 998 | llvm::Value *Chunk = nullptr; |
| 999 | StaticRTInput(unsigned IVSize, bool IVSigned, bool Ordered, Address IL, |
| 1000 | Address LB, Address UB, Address ST, |
| 1001 | llvm::Value *Chunk = nullptr) |
| 1002 | : IVSize(IVSize), IVSigned(IVSigned), Ordered(Ordered), IL(IL), LB(LB), |
| 1003 | UB(UB), ST(ST), Chunk(Chunk) {} |
| 1004 | }; |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1005 | /// Call the appropriate runtime routine to initialize it before start |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 1006 | /// of loop. |
| 1007 | /// |
Carlo Bertolli | b0ff0a6 | 2017-04-25 17:52:12 +0000 | [diff] [blame] | 1008 | /// This is used only in case of static schedule, when the user did not |
| 1009 | /// specify a ordered clause on the loop construct. |
| 1010 | /// Depending on the loop schedule, it is necessary to call some runtime |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 1011 | /// routine before start of the OpenMP loop to get the loop upper / lower |
Alexey Bataev | 0f87dbe | 2017-08-14 17:56:13 +0000 | [diff] [blame] | 1012 | /// bounds LB and UB and stride ST. |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 1013 | /// |
| 1014 | /// \param CGF Reference to current CodeGenFunction. |
| 1015 | /// \param Loc Clang source location. |
Alexey Bataev | 0f87dbe | 2017-08-14 17:56:13 +0000 | [diff] [blame] | 1016 | /// \param DKind Kind of the directive. |
Alexey Bataev | 9ebd742 | 2016-05-10 09:57:36 +0000 | [diff] [blame] | 1017 | /// \param ScheduleKind Schedule kind, specified by the 'schedule' clause. |
Alexey Bataev | 0f87dbe | 2017-08-14 17:56:13 +0000 | [diff] [blame] | 1018 | /// \param Values Input arguments for the construct. |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 1019 | /// |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1020 | virtual void emitForStaticInit(CodeGenFunction &CGF, SourceLocation Loc, |
Alexey Bataev | 0f87dbe | 2017-08-14 17:56:13 +0000 | [diff] [blame] | 1021 | OpenMPDirectiveKind DKind, |
Alexey Bataev | 9ebd742 | 2016-05-10 09:57:36 +0000 | [diff] [blame] | 1022 | const OpenMPScheduleTy &ScheduleKind, |
Alexey Bataev | 0f87dbe | 2017-08-14 17:56:13 +0000 | [diff] [blame] | 1023 | const StaticRTInput &Values); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 1024 | |
Carlo Bertolli | fc35ad2 | 2016-03-07 16:04:49 +0000 | [diff] [blame] | 1025 | /// |
| 1026 | /// \param CGF Reference to current CodeGenFunction. |
| 1027 | /// \param Loc Clang source location. |
| 1028 | /// \param SchedKind Schedule kind, specified by the 'dist_schedule' clause. |
Alexey Bataev | 0f87dbe | 2017-08-14 17:56:13 +0000 | [diff] [blame] | 1029 | /// \param Values Input arguments for the construct. |
Carlo Bertolli | fc35ad2 | 2016-03-07 16:04:49 +0000 | [diff] [blame] | 1030 | /// |
Alexey Bataev | 0f87dbe | 2017-08-14 17:56:13 +0000 | [diff] [blame] | 1031 | virtual void emitDistributeStaticInit(CodeGenFunction &CGF, |
| 1032 | SourceLocation Loc, |
Carlo Bertolli | fc35ad2 | 2016-03-07 16:04:49 +0000 | [diff] [blame] | 1033 | OpenMPDistScheduleClauseKind SchedKind, |
Alexey Bataev | 0f87dbe | 2017-08-14 17:56:13 +0000 | [diff] [blame] | 1034 | const StaticRTInput &Values); |
Carlo Bertolli | fc35ad2 | 2016-03-07 16:04:49 +0000 | [diff] [blame] | 1035 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1036 | /// Call the appropriate runtime routine to notify that we finished |
Alexey Bataev | 98eb6e3 | 2015-04-22 11:15:40 +0000 | [diff] [blame] | 1037 | /// iteration of the ordered loop with the dynamic scheduling. |
| 1038 | /// |
| 1039 | /// \param CGF Reference to current CodeGenFunction. |
| 1040 | /// \param Loc Clang source location. |
| 1041 | /// \param IVSize Size of the iteration variable in bits. |
Simon Pilgrim | 6c0eeff | 2017-07-13 17:34:44 +0000 | [diff] [blame] | 1042 | /// \param IVSigned Sign of the iteration variable. |
Alexey Bataev | 98eb6e3 | 2015-04-22 11:15:40 +0000 | [diff] [blame] | 1043 | /// |
Alexey Bataev | d7589ffe | 2015-05-20 13:12:48 +0000 | [diff] [blame] | 1044 | virtual void emitForOrderedIterationEnd(CodeGenFunction &CGF, |
| 1045 | SourceLocation Loc, unsigned IVSize, |
| 1046 | bool IVSigned); |
Alexey Bataev | 98eb6e3 | 2015-04-22 11:15:40 +0000 | [diff] [blame] | 1047 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1048 | /// Call the appropriate runtime routine to notify that we finished |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 1049 | /// all the work with current loop. |
| 1050 | /// |
| 1051 | /// \param CGF Reference to current CodeGenFunction. |
| 1052 | /// \param Loc Clang source location. |
Alexey Bataev | f43f714 | 2017-09-06 16:17:35 +0000 | [diff] [blame] | 1053 | /// \param DKind Kind of the directive for which the static finish is emitted. |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 1054 | /// |
Alexey Bataev | f43f714 | 2017-09-06 16:17:35 +0000 | [diff] [blame] | 1055 | virtual void emitForStaticFinish(CodeGenFunction &CGF, SourceLocation Loc, |
| 1056 | OpenMPDirectiveKind DKind); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 1057 | |
Alexander Musman | 92bdaab | 2015-03-12 13:37:50 +0000 | [diff] [blame] | 1058 | /// Call __kmpc_dispatch_next( |
| 1059 | /// ident_t *loc, kmp_int32 tid, kmp_int32 *p_lastiter, |
| 1060 | /// kmp_int[32|64] *p_lower, kmp_int[32|64] *p_upper, |
| 1061 | /// kmp_int[32|64] *p_stride); |
| 1062 | /// \param IVSize Size of the iteration variable in bits. |
Simon Pilgrim | 6c0eeff | 2017-07-13 17:34:44 +0000 | [diff] [blame] | 1063 | /// \param IVSigned Sign of the iteration variable. |
Alexander Musman | 92bdaab | 2015-03-12 13:37:50 +0000 | [diff] [blame] | 1064 | /// \param IL Address of the output variable in which the flag of the |
| 1065 | /// last iteration is returned. |
| 1066 | /// \param LB Address of the output variable in which the lower iteration |
| 1067 | /// number is returned. |
| 1068 | /// \param UB Address of the output variable in which the upper iteration |
| 1069 | /// number is returned. |
| 1070 | /// \param ST Address of the output variable in which the stride value is |
| 1071 | /// returned. |
| 1072 | virtual llvm::Value *emitForNext(CodeGenFunction &CGF, SourceLocation Loc, |
| 1073 | unsigned IVSize, bool IVSigned, |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1074 | Address IL, Address LB, |
| 1075 | Address UB, Address ST); |
Alexander Musman | 92bdaab | 2015-03-12 13:37:50 +0000 | [diff] [blame] | 1076 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1077 | /// Emits call to void __kmpc_push_num_threads(ident_t *loc, kmp_int32 |
Alexey Bataev | b205978 | 2014-10-13 08:23:51 +0000 | [diff] [blame] | 1078 | /// global_tid, kmp_int32 num_threads) to generate code for 'num_threads' |
| 1079 | /// clause. |
| 1080 | /// \param NumThreads An integer value of threads. |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 1081 | virtual void emitNumThreadsClause(CodeGenFunction &CGF, |
| 1082 | llvm::Value *NumThreads, |
| 1083 | SourceLocation Loc); |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 1084 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1085 | /// Emit call to void __kmpc_push_proc_bind(ident_t *loc, kmp_int32 |
Alexey Bataev | 7f210c6 | 2015-06-18 13:40:03 +0000 | [diff] [blame] | 1086 | /// global_tid, int proc_bind) to generate code for 'proc_bind' clause. |
| 1087 | virtual void emitProcBindClause(CodeGenFunction &CGF, |
| 1088 | OpenMPProcBindClauseKind ProcBind, |
| 1089 | SourceLocation Loc); |
| 1090 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1091 | /// Returns address of the threadprivate variable for the current |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 1092 | /// thread. |
NAKAMURA Takumi | cdcbfba | 2014-11-11 07:58:06 +0000 | [diff] [blame] | 1093 | /// \param VD Threadprivate variable. |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 1094 | /// \param VDAddr Address of the global variable \a VD. |
| 1095 | /// \param Loc Location of the reference to threadprivate var. |
| 1096 | /// \return Address of the threadprivate variable for the current thread. |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1097 | virtual Address getAddrOfThreadPrivate(CodeGenFunction &CGF, |
| 1098 | const VarDecl *VD, |
| 1099 | Address VDAddr, |
| 1100 | SourceLocation Loc); |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 1101 | |
Alexey Bataev | 92327c5 | 2018-03-26 16:40:55 +0000 | [diff] [blame] | 1102 | /// Returns the address of the variable marked as declare target with link |
| 1103 | /// clause. |
Alexey Bataev | 03f270c | 2018-03-30 18:31:07 +0000 | [diff] [blame] | 1104 | virtual Address getAddrOfDeclareTargetLink(const VarDecl *VD); |
Alexey Bataev | 92327c5 | 2018-03-26 16:40:55 +0000 | [diff] [blame] | 1105 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1106 | /// Emit a code for initialization of threadprivate variable. It emits |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 1107 | /// a call to runtime library which adds initial value to the newly created |
| 1108 | /// threadprivate variable (if it is not constant) and registers destructor |
| 1109 | /// for the variable (if any). |
| 1110 | /// \param VD Threadprivate variable. |
| 1111 | /// \param VDAddr Address of the global variable \a VD. |
| 1112 | /// \param Loc Location of threadprivate declaration. |
| 1113 | /// \param PerformInit true if initialization expression is not constant. |
| 1114 | virtual llvm::Function * |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1115 | emitThreadPrivateVarDefinition(const VarDecl *VD, Address VDAddr, |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 1116 | SourceLocation Loc, bool PerformInit, |
| 1117 | CodeGenFunction *CGF = nullptr); |
Alexey Bataev | cc37cc1 | 2014-11-20 04:34:54 +0000 | [diff] [blame] | 1118 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1119 | /// Emit a code for initialization of declare target variable. |
Alexey Bataev | 34f8a70 | 2018-03-28 14:28:54 +0000 | [diff] [blame] | 1120 | /// \param VD Declare target variable. |
| 1121 | /// \param Addr Address of the global variable \a VD. |
| 1122 | /// \param PerformInit true if initialization expression is not constant. |
| 1123 | virtual bool emitDeclareTargetVarDefinition(const VarDecl *VD, |
| 1124 | llvm::GlobalVariable *Addr, |
| 1125 | bool PerformInit); |
| 1126 | |
Alexey Bataev | be5a8b4 | 2017-07-17 13:30:36 +0000 | [diff] [blame] | 1127 | /// Creates artificial threadprivate variable with name \p Name and type \p |
| 1128 | /// VarType. |
| 1129 | /// \param VarType Type of the artificial threadprivate variable. |
| 1130 | /// \param Name Name of the artificial threadprivate variable. |
| 1131 | virtual Address getAddrOfArtificialThreadPrivate(CodeGenFunction &CGF, |
| 1132 | QualType VarType, |
| 1133 | StringRef Name); |
| 1134 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1135 | /// Emit flush of the variables specified in 'omp flush' directive. |
Alexey Bataev | cc37cc1 | 2014-11-20 04:34:54 +0000 | [diff] [blame] | 1136 | /// \param Vars List of variables to flush. |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 1137 | virtual void emitFlush(CodeGenFunction &CGF, ArrayRef<const Expr *> Vars, |
| 1138 | SourceLocation Loc); |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1139 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1140 | /// Emit task region for the task directive. The task region is |
Nico Weber | 20b0ce3 | 2015-04-28 18:19:18 +0000 | [diff] [blame] | 1141 | /// emitted in several steps: |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1142 | /// 1. Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32 |
| 1143 | /// gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds, |
| 1144 | /// kmp_routine_entry_t *task_entry). Here task_entry is a pointer to the |
| 1145 | /// function: |
| 1146 | /// kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) { |
| 1147 | /// TaskFunction(gtid, tt->part_id, tt->shareds); |
| 1148 | /// return 0; |
| 1149 | /// } |
| 1150 | /// 2. Copy a list of shared variables to field shareds of the resulting |
| 1151 | /// structure kmp_task_t returned by the previous call (if any). |
| 1152 | /// 3. Copy a pointer to destructions function to field destructions of the |
| 1153 | /// resulting structure kmp_task_t. |
| 1154 | /// 4. Emit a call to kmp_int32 __kmpc_omp_task(ident_t *, kmp_int32 gtid, |
| 1155 | /// kmp_task_t *new_task), where new_task is a resulting structure from |
| 1156 | /// previous items. |
Alexey Bataev | 36c1eb9 | 2015-04-30 06:51:57 +0000 | [diff] [blame] | 1157 | /// \param D Current task directive. |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1158 | /// \param TaskFunction An LLVM function with type void (*)(i32 /*gtid*/, i32 |
| 1159 | /// /*part_id*/, captured_struct */*__context*/); |
| 1160 | /// \param SharedsTy A type which contains references the shared variables. |
Alexey Bataev | 1d2353d | 2015-06-24 11:01:36 +0000 | [diff] [blame] | 1161 | /// \param Shareds Context with the list of shared variables from the \p |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1162 | /// TaskFunction. |
Alexey Bataev | 1d67713 | 2015-04-22 13:57:31 +0000 | [diff] [blame] | 1163 | /// \param IfCond Not a nullptr if 'if' clause was specified, nullptr |
| 1164 | /// otherwise. |
Alexey Bataev | 24b5bae | 2016-04-28 09:23:51 +0000 | [diff] [blame] | 1165 | /// \param Data Additional data for task generation like tiednsee, final |
| 1166 | /// state, list of privates etc. |
| 1167 | virtual void emitTaskCall(CodeGenFunction &CGF, SourceLocation Loc, |
| 1168 | const OMPExecutableDirective &D, |
James Y Knight | 9871db0 | 2019-02-05 16:42:33 +0000 | [diff] [blame] | 1169 | llvm::Function *TaskFunction, QualType SharedsTy, |
Alexey Bataev | 24b5bae | 2016-04-28 09:23:51 +0000 | [diff] [blame] | 1170 | Address Shareds, const Expr *IfCond, |
| 1171 | const OMPTaskDataTy &Data); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 1172 | |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 1173 | /// Emit task region for the taskloop directive. The taskloop region is |
| 1174 | /// emitted in several steps: |
| 1175 | /// 1. Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32 |
| 1176 | /// gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds, |
| 1177 | /// kmp_routine_entry_t *task_entry). Here task_entry is a pointer to the |
| 1178 | /// function: |
| 1179 | /// kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) { |
| 1180 | /// TaskFunction(gtid, tt->part_id, tt->shareds); |
| 1181 | /// return 0; |
| 1182 | /// } |
| 1183 | /// 2. Copy a list of shared variables to field shareds of the resulting |
| 1184 | /// structure kmp_task_t returned by the previous call (if any). |
| 1185 | /// 3. Copy a pointer to destructions function to field destructions of the |
| 1186 | /// resulting structure kmp_task_t. |
| 1187 | /// 4. Emit a call to void __kmpc_taskloop(ident_t *loc, int gtid, kmp_task_t |
| 1188 | /// *task, int if_val, kmp_uint64 *lb, kmp_uint64 *ub, kmp_int64 st, int |
| 1189 | /// nogroup, int sched, kmp_uint64 grainsize, void *task_dup ), where new_task |
| 1190 | /// is a resulting structure from |
| 1191 | /// previous items. |
| 1192 | /// \param D Current task directive. |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 1193 | /// \param TaskFunction An LLVM function with type void (*)(i32 /*gtid*/, i32 |
| 1194 | /// /*part_id*/, captured_struct */*__context*/); |
| 1195 | /// \param SharedsTy A type which contains references the shared variables. |
| 1196 | /// \param Shareds Context with the list of shared variables from the \p |
| 1197 | /// TaskFunction. |
| 1198 | /// \param IfCond Not a nullptr if 'if' clause was specified, nullptr |
| 1199 | /// otherwise. |
Alexey Bataev | 24b5bae | 2016-04-28 09:23:51 +0000 | [diff] [blame] | 1200 | /// \param Data Additional data for task generation like tiednsee, final |
| 1201 | /// state, list of privates etc. |
James Y Knight | 9871db0 | 2019-02-05 16:42:33 +0000 | [diff] [blame] | 1202 | virtual void emitTaskLoopCall(CodeGenFunction &CGF, SourceLocation Loc, |
| 1203 | const OMPLoopDirective &D, |
| 1204 | llvm::Function *TaskFunction, |
| 1205 | QualType SharedsTy, Address Shareds, |
| 1206 | const Expr *IfCond, const OMPTaskDataTy &Data); |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 1207 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1208 | /// Emit code for the directive that does not require outlining. |
Alexey Bataev | 6f1ffc0 | 2015-04-10 04:50:10 +0000 | [diff] [blame] | 1209 | /// |
Alexey Bataev | 81c7ea0 | 2015-07-03 09:56:58 +0000 | [diff] [blame] | 1210 | /// \param InnermostKind Kind of innermost directive (for simple directives it |
| 1211 | /// is a directive itself, for combined - its innermost directive). |
Alexey Bataev | 6f1ffc0 | 2015-04-10 04:50:10 +0000 | [diff] [blame] | 1212 | /// \param CodeGen Code generation sequence for the \a D directive. |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 1213 | /// \param HasCancel true if region has inner cancel directive, false |
| 1214 | /// otherwise. |
Alexey Bataev | 6f1ffc0 | 2015-04-10 04:50:10 +0000 | [diff] [blame] | 1215 | virtual void emitInlinedDirective(CodeGenFunction &CGF, |
Alexey Bataev | 81c7ea0 | 2015-07-03 09:56:58 +0000 | [diff] [blame] | 1216 | OpenMPDirectiveKind InnermostKind, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 1217 | const RegionCodeGenTy &CodeGen, |
| 1218 | bool HasCancel = false); |
Arpith Chacko Jacob | 101e8fb | 2017-02-16 16:20:16 +0000 | [diff] [blame] | 1219 | |
| 1220 | /// Emits reduction function. |
| 1221 | /// \param ArgsType Array type containing pointers to reduction variables. |
| 1222 | /// \param Privates List of private copies for original reduction arguments. |
| 1223 | /// \param LHSExprs List of LHS in \a ReductionOps reduction operations. |
| 1224 | /// \param RHSExprs List of RHS in \a ReductionOps reduction operations. |
| 1225 | /// \param ReductionOps List of reduction operations in form 'LHS binop RHS' |
| 1226 | /// or 'operator binop(LHS, RHS)'. |
James Y Knight | 9871db0 | 2019-02-05 16:42:33 +0000 | [diff] [blame] | 1227 | llvm::Function *emitReductionFunction(CodeGenModule &CGM, SourceLocation Loc, |
| 1228 | llvm::Type *ArgsType, |
| 1229 | ArrayRef<const Expr *> Privates, |
| 1230 | ArrayRef<const Expr *> LHSExprs, |
| 1231 | ArrayRef<const Expr *> RHSExprs, |
| 1232 | ArrayRef<const Expr *> ReductionOps); |
Arpith Chacko Jacob | 101e8fb | 2017-02-16 16:20:16 +0000 | [diff] [blame] | 1233 | |
| 1234 | /// Emits single reduction combiner |
| 1235 | void emitSingleReductionCombiner(CodeGenFunction &CGF, |
| 1236 | const Expr *ReductionOp, |
| 1237 | const Expr *PrivateRef, |
| 1238 | const DeclRefExpr *LHS, |
| 1239 | const DeclRefExpr *RHS); |
| 1240 | |
| 1241 | struct ReductionOptionsTy { |
| 1242 | bool WithNowait; |
| 1243 | bool SimpleReduction; |
| 1244 | OpenMPDirectiveKind ReductionKind; |
| 1245 | }; |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1246 | /// Emit a code for reduction clause. Next code should be emitted for |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 1247 | /// reduction: |
| 1248 | /// \code |
| 1249 | /// |
| 1250 | /// static kmp_critical_name lock = { 0 }; |
| 1251 | /// |
| 1252 | /// void reduce_func(void *lhs[<n>], void *rhs[<n>]) { |
| 1253 | /// ... |
| 1254 | /// *(Type<i>*)lhs[i] = RedOp<i>(*(Type<i>*)lhs[i], *(Type<i>*)rhs[i]); |
| 1255 | /// ... |
| 1256 | /// } |
| 1257 | /// |
| 1258 | /// ... |
| 1259 | /// void *RedList[<n>] = {&<RHSExprs>[0], ..., &<RHSExprs>[<n>-1]}; |
| 1260 | /// switch (__kmpc_reduce{_nowait}(<loc>, <gtid>, <n>, sizeof(RedList), |
| 1261 | /// RedList, reduce_func, &<lock>)) { |
| 1262 | /// case 1: |
| 1263 | /// ... |
| 1264 | /// <LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]); |
| 1265 | /// ... |
| 1266 | /// __kmpc_end_reduce{_nowait}(<loc>, <gtid>, &<lock>); |
| 1267 | /// break; |
| 1268 | /// case 2: |
| 1269 | /// ... |
| 1270 | /// Atomic(<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i])); |
| 1271 | /// ... |
| 1272 | /// break; |
| 1273 | /// default:; |
| 1274 | /// } |
| 1275 | /// \endcode |
| 1276 | /// |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 1277 | /// \param Privates List of private copies for original reduction arguments. |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 1278 | /// \param LHSExprs List of LHS in \a ReductionOps reduction operations. |
| 1279 | /// \param RHSExprs List of RHS in \a ReductionOps reduction operations. |
| 1280 | /// \param ReductionOps List of reduction operations in form 'LHS binop RHS' |
| 1281 | /// or 'operator binop(LHS, RHS)'. |
Arpith Chacko Jacob | 101e8fb | 2017-02-16 16:20:16 +0000 | [diff] [blame] | 1282 | /// \param Options List of options for reduction codegen: |
| 1283 | /// WithNowait true if parent directive has also nowait clause, false |
| 1284 | /// otherwise. |
| 1285 | /// SimpleReduction Emit reduction operation only. Used for omp simd |
| 1286 | /// directive on the host. |
| 1287 | /// ReductionKind The kind of reduction to perform. |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 1288 | virtual void emitReduction(CodeGenFunction &CGF, SourceLocation Loc, |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 1289 | ArrayRef<const Expr *> Privates, |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 1290 | ArrayRef<const Expr *> LHSExprs, |
| 1291 | ArrayRef<const Expr *> RHSExprs, |
| 1292 | ArrayRef<const Expr *> ReductionOps, |
Arpith Chacko Jacob | 101e8fb | 2017-02-16 16:20:16 +0000 | [diff] [blame] | 1293 | ReductionOptionsTy Options); |
Alexey Bataev | 8b8e202 | 2015-04-27 05:22:09 +0000 | [diff] [blame] | 1294 | |
Alexey Bataev | be5a8b4 | 2017-07-17 13:30:36 +0000 | [diff] [blame] | 1295 | /// Emit a code for initialization of task reduction clause. Next code |
| 1296 | /// should be emitted for reduction: |
| 1297 | /// \code |
| 1298 | /// |
| 1299 | /// _task_red_item_t red_data[n]; |
| 1300 | /// ... |
| 1301 | /// red_data[i].shar = &origs[i]; |
| 1302 | /// red_data[i].size = sizeof(origs[i]); |
| 1303 | /// red_data[i].f_init = (void*)RedInit<i>; |
| 1304 | /// red_data[i].f_fini = (void*)RedDest<i>; |
| 1305 | /// red_data[i].f_comb = (void*)RedOp<i>; |
| 1306 | /// red_data[i].flags = <Flag_i>; |
| 1307 | /// ... |
| 1308 | /// void* tg1 = __kmpc_task_reduction_init(gtid, n, red_data); |
| 1309 | /// \endcode |
| 1310 | /// |
| 1311 | /// \param LHSExprs List of LHS in \a Data.ReductionOps reduction operations. |
| 1312 | /// \param RHSExprs List of RHS in \a Data.ReductionOps reduction operations. |
| 1313 | /// \param Data Additional data for task generation like tiedness, final |
| 1314 | /// state, list of privates, reductions etc. |
| 1315 | virtual llvm::Value *emitTaskReductionInit(CodeGenFunction &CGF, |
| 1316 | SourceLocation Loc, |
| 1317 | ArrayRef<const Expr *> LHSExprs, |
| 1318 | ArrayRef<const Expr *> RHSExprs, |
| 1319 | const OMPTaskDataTy &Data); |
| 1320 | |
| 1321 | /// Required to resolve existing problems in the runtime. Emits threadprivate |
| 1322 | /// variables to store the size of the VLAs/array sections for |
| 1323 | /// initializer/combiner/finalizer functions + emits threadprivate variable to |
| 1324 | /// store the pointer to the original reduction item for the custom |
| 1325 | /// initializer defined by declare reduction construct. |
| 1326 | /// \param RCG Allows to reuse an existing data for the reductions. |
| 1327 | /// \param N Reduction item for which fixups must be emitted. |
| 1328 | virtual void emitTaskReductionFixups(CodeGenFunction &CGF, SourceLocation Loc, |
| 1329 | ReductionCodeGen &RCG, unsigned N); |
| 1330 | |
| 1331 | /// Get the address of `void *` type of the privatue copy of the reduction |
| 1332 | /// item specified by the \p SharedLVal. |
| 1333 | /// \param ReductionsPtr Pointer to the reduction data returned by the |
| 1334 | /// emitTaskReductionInit function. |
| 1335 | /// \param SharedLVal Address of the original reduction item. |
| 1336 | virtual Address getTaskReductionItem(CodeGenFunction &CGF, SourceLocation Loc, |
| 1337 | llvm::Value *ReductionsPtr, |
| 1338 | LValue SharedLVal); |
| 1339 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1340 | /// Emit code for 'taskwait' directive. |
Alexey Bataev | 8b8e202 | 2015-04-27 05:22:09 +0000 | [diff] [blame] | 1341 | virtual void emitTaskwaitCall(CodeGenFunction &CGF, SourceLocation Loc); |
Alexey Bataev | 0f34da1 | 2015-07-02 04:17:07 +0000 | [diff] [blame] | 1342 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1343 | /// Emit code for 'cancellation point' construct. |
Alexey Bataev | 0f34da1 | 2015-07-02 04:17:07 +0000 | [diff] [blame] | 1344 | /// \param CancelRegion Region kind for which the cancellation point must be |
| 1345 | /// emitted. |
| 1346 | /// |
| 1347 | virtual void emitCancellationPointCall(CodeGenFunction &CGF, |
| 1348 | SourceLocation Loc, |
| 1349 | OpenMPDirectiveKind CancelRegion); |
Alexey Bataev | 7d5d33e | 2015-07-06 05:50:32 +0000 | [diff] [blame] | 1350 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1351 | /// Emit code for 'cancel' construct. |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 1352 | /// \param IfCond Condition in the associated 'if' clause, if it was |
| 1353 | /// specified, nullptr otherwise. |
Alexey Bataev | 7d5d33e | 2015-07-06 05:50:32 +0000 | [diff] [blame] | 1354 | /// \param CancelRegion Region kind for which the cancel must be emitted. |
| 1355 | /// |
| 1356 | virtual void emitCancelCall(CodeGenFunction &CGF, SourceLocation Loc, |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 1357 | const Expr *IfCond, |
Alexey Bataev | 7d5d33e | 2015-07-06 05:50:32 +0000 | [diff] [blame] | 1358 | OpenMPDirectiveKind CancelRegion); |
Samuel Antao | bed3c46 | 2015-10-02 16:14:20 +0000 | [diff] [blame] | 1359 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1360 | /// Emit outilined function for 'target' directive. |
Samuel Antao | bed3c46 | 2015-10-02 16:14:20 +0000 | [diff] [blame] | 1361 | /// \param D Directive to emit. |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 1362 | /// \param ParentName Name of the function that encloses the target region. |
| 1363 | /// \param OutlinedFn Outlined function value to be defined by this call. |
| 1364 | /// \param OutlinedFnID Outlined function ID value to be defined by this call. |
| 1365 | /// \param IsOffloadEntry True if the outlined function is an offload entry. |
Alexey Bataev | 14fa1c6 | 2016-03-29 05:34:15 +0000 | [diff] [blame] | 1366 | /// \param CodeGen Code generation sequence for the \a D directive. |
Simon Pilgrim | 6c0eeff | 2017-07-13 17:34:44 +0000 | [diff] [blame] | 1367 | /// An outlined function may not be an entry if, e.g. the if clause always |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 1368 | /// evaluates to false. |
| 1369 | virtual void emitTargetOutlinedFunction(const OMPExecutableDirective &D, |
| 1370 | StringRef ParentName, |
| 1371 | llvm::Function *&OutlinedFn, |
| 1372 | llvm::Constant *&OutlinedFnID, |
Alexey Bataev | 14fa1c6 | 2016-03-29 05:34:15 +0000 | [diff] [blame] | 1373 | bool IsOffloadEntry, |
| 1374 | const RegionCodeGenTy &CodeGen); |
Samuel Antao | bed3c46 | 2015-10-02 16:14:20 +0000 | [diff] [blame] | 1375 | |
Alexey Bataev | 7bb3353 | 2019-01-07 21:30:43 +0000 | [diff] [blame] | 1376 | /// Emit code that pushes the trip count of loops associated with constructs |
| 1377 | /// 'target teams distribute' and 'teams distribute parallel for'. |
| 1378 | /// \param SizeEmitter Emits the int64 value for the number of iterations of |
| 1379 | /// the associated loop. |
| 1380 | virtual void emitTargetNumIterationsCall( |
| 1381 | CodeGenFunction &CGF, const OMPExecutableDirective &D, const Expr *Device, |
| 1382 | const llvm::function_ref<llvm::Value *( |
| 1383 | CodeGenFunction &CGF, const OMPLoopDirective &D)> &SizeEmitter); |
| 1384 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1385 | /// Emit the target offloading code associated with \a D. The emitted |
Samuel Antao | bed3c46 | 2015-10-02 16:14:20 +0000 | [diff] [blame] | 1386 | /// code attempts offloading the execution to the device, an the event of |
| 1387 | /// a failure it executes the host version outlined in \a OutlinedFn. |
| 1388 | /// \param D Directive to emit. |
| 1389 | /// \param OutlinedFn Host version of the code to be offloaded. |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 1390 | /// \param OutlinedFnID ID of host version of the code to be offloaded. |
Samuel Antao | bed3c46 | 2015-10-02 16:14:20 +0000 | [diff] [blame] | 1391 | /// \param IfCond Expression evaluated in if clause associated with the target |
| 1392 | /// directive, or null if no if clause is used. |
| 1393 | /// \param Device Expression evaluated in device clause associated with the |
| 1394 | /// target directive, or null if no device clause is used. |
Samuel Antao | bed3c46 | 2015-10-02 16:14:20 +0000 | [diff] [blame] | 1395 | virtual void emitTargetCall(CodeGenFunction &CGF, |
| 1396 | const OMPExecutableDirective &D, |
James Y Knight | 9871db0 | 2019-02-05 16:42:33 +0000 | [diff] [blame] | 1397 | llvm::Function *OutlinedFn, |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 1398 | llvm::Value *OutlinedFnID, const Expr *IfCond, |
Alexey Bataev | 8451efa | 2018-01-15 19:06:12 +0000 | [diff] [blame] | 1399 | const Expr *Device); |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 1400 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1401 | /// Emit the target regions enclosed in \a GD function definition or |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 1402 | /// the function itself in case it is a valid device function. Returns true if |
| 1403 | /// \a GD was dealt with successfully. |
Nico Weber | a2abe8c | 2016-01-06 19:13:49 +0000 | [diff] [blame] | 1404 | /// \param GD Function to scan. |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 1405 | virtual bool emitTargetFunctions(GlobalDecl GD); |
| 1406 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1407 | /// Emit the global variable if it is a valid device global variable. |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 1408 | /// Returns true if \a GD was dealt with successfully. |
| 1409 | /// \param GD Variable declaration to emit. |
| 1410 | virtual bool emitTargetGlobalVariable(GlobalDecl GD); |
| 1411 | |
Alexey Bataev | 03f270c | 2018-03-30 18:31:07 +0000 | [diff] [blame] | 1412 | /// Checks if the provided global decl \a GD is a declare target variable and |
| 1413 | /// registers it when emitting code for the host. |
| 1414 | virtual void registerTargetGlobalVariable(const VarDecl *VD, |
| 1415 | llvm::Constant *Addr); |
| 1416 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1417 | /// Emit the global \a GD if it is meaningful for the target. Returns |
Simon Pilgrim | 2c51880 | 2017-03-30 14:13:19 +0000 | [diff] [blame] | 1418 | /// if it was emitted successfully. |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 1419 | /// \param GD Global to scan. |
| 1420 | virtual bool emitTargetGlobal(GlobalDecl GD); |
| 1421 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1422 | /// Creates the offloading descriptor in the event any target region |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 1423 | /// was emitted in the current module and return the function that registers |
| 1424 | /// it. |
| 1425 | virtual llvm::Function *emitRegistrationFunction(); |
Carlo Bertolli | 430d8ec | 2016-03-03 20:34:23 +0000 | [diff] [blame] | 1426 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1427 | /// Emits code for teams call of the \a OutlinedFn with |
Carlo Bertolli | 430d8ec | 2016-03-03 20:34:23 +0000 | [diff] [blame] | 1428 | /// variables captured in a record which address is stored in \a |
| 1429 | /// CapturedStruct. |
| 1430 | /// \param OutlinedFn Outlined function to be run by team masters. Type of |
| 1431 | /// this function is void(*)(kmp_int32 *, kmp_int32, struct context_vars*). |
| 1432 | /// \param CapturedVars A pointer to the record with the references to |
| 1433 | /// variables used in \a OutlinedFn function. |
| 1434 | /// |
| 1435 | virtual void emitTeamsCall(CodeGenFunction &CGF, |
| 1436 | const OMPExecutableDirective &D, |
James Y Knight | 9871db0 | 2019-02-05 16:42:33 +0000 | [diff] [blame] | 1437 | SourceLocation Loc, llvm::Function *OutlinedFn, |
Carlo Bertolli | 430d8ec | 2016-03-03 20:34:23 +0000 | [diff] [blame] | 1438 | ArrayRef<llvm::Value *> CapturedVars); |
| 1439 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1440 | /// Emits call to void __kmpc_push_num_teams(ident_t *loc, kmp_int32 |
Carlo Bertolli | 430d8ec | 2016-03-03 20:34:23 +0000 | [diff] [blame] | 1441 | /// global_tid, kmp_int32 num_teams, kmp_int32 thread_limit) to generate code |
| 1442 | /// for num_teams clause. |
Carlo Bertolli | c687225 | 2016-04-04 15:55:02 +0000 | [diff] [blame] | 1443 | /// \param NumTeams An integer expression of teams. |
| 1444 | /// \param ThreadLimit An integer expression of threads. |
| 1445 | virtual void emitNumTeamsClause(CodeGenFunction &CGF, const Expr *NumTeams, |
| 1446 | const Expr *ThreadLimit, SourceLocation Loc); |
Samuel Antao | df158d5 | 2016-04-27 22:58:19 +0000 | [diff] [blame] | 1447 | |
Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 1448 | /// Struct that keeps all the relevant information that should be kept |
| 1449 | /// throughout a 'target data' region. |
| 1450 | class TargetDataInfo { |
| 1451 | /// Set to true if device pointer information have to be obtained. |
| 1452 | bool RequiresDevicePointerInfo = false; |
| 1453 | |
| 1454 | public: |
| 1455 | /// The array of base pointer passed to the runtime library. |
| 1456 | llvm::Value *BasePointersArray = nullptr; |
| 1457 | /// The array of section pointers passed to the runtime library. |
| 1458 | llvm::Value *PointersArray = nullptr; |
| 1459 | /// The array of sizes passed to the runtime library. |
| 1460 | llvm::Value *SizesArray = nullptr; |
| 1461 | /// The array of map types passed to the runtime library. |
| 1462 | llvm::Value *MapTypesArray = nullptr; |
| 1463 | /// The total number of pointers passed to the runtime library. |
| 1464 | unsigned NumberOfPtrs = 0u; |
| 1465 | /// Map between the a declaration of a capture and the corresponding base |
| 1466 | /// pointer address where the runtime returns the device pointers. |
| 1467 | llvm::DenseMap<const ValueDecl *, Address> CaptureDeviceAddrMap; |
| 1468 | |
| 1469 | explicit TargetDataInfo() {} |
| 1470 | explicit TargetDataInfo(bool RequiresDevicePointerInfo) |
| 1471 | : RequiresDevicePointerInfo(RequiresDevicePointerInfo) {} |
| 1472 | /// Clear information about the data arrays. |
| 1473 | void clearArrayInfo() { |
| 1474 | BasePointersArray = nullptr; |
| 1475 | PointersArray = nullptr; |
| 1476 | SizesArray = nullptr; |
| 1477 | MapTypesArray = nullptr; |
| 1478 | NumberOfPtrs = 0u; |
| 1479 | } |
| 1480 | /// Return true if the current target data information has valid arrays. |
| 1481 | bool isValid() { |
| 1482 | return BasePointersArray && PointersArray && SizesArray && |
| 1483 | MapTypesArray && NumberOfPtrs; |
| 1484 | } |
| 1485 | bool requiresDevicePointerInfo() { return RequiresDevicePointerInfo; } |
| 1486 | }; |
| 1487 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1488 | /// Emit the target data mapping code associated with \a D. |
Samuel Antao | df158d5 | 2016-04-27 22:58:19 +0000 | [diff] [blame] | 1489 | /// \param D Directive to emit. |
Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 1490 | /// \param IfCond Expression evaluated in if clause associated with the |
| 1491 | /// target directive, or null if no device clause is used. |
Samuel Antao | df158d5 | 2016-04-27 22:58:19 +0000 | [diff] [blame] | 1492 | /// \param Device Expression evaluated in device clause associated with the |
| 1493 | /// target directive, or null if no device clause is used. |
Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 1494 | /// \param Info A record used to store information that needs to be preserved |
| 1495 | /// until the region is closed. |
Samuel Antao | df158d5 | 2016-04-27 22:58:19 +0000 | [diff] [blame] | 1496 | virtual void emitTargetDataCalls(CodeGenFunction &CGF, |
| 1497 | const OMPExecutableDirective &D, |
| 1498 | const Expr *IfCond, const Expr *Device, |
Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 1499 | const RegionCodeGenTy &CodeGen, |
| 1500 | TargetDataInfo &Info); |
Samuel Antao | bd0ae2e | 2016-04-27 23:07:29 +0000 | [diff] [blame] | 1501 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1502 | /// Emit the data mapping/movement code associated with the directive |
Samuel Antao | 8d2d730 | 2016-05-26 18:30:22 +0000 | [diff] [blame] | 1503 | /// \a D that should be of the form 'target [{enter|exit} data | update]'. |
Samuel Antao | bd0ae2e | 2016-04-27 23:07:29 +0000 | [diff] [blame] | 1504 | /// \param D Directive to emit. |
| 1505 | /// \param IfCond Expression evaluated in if clause associated with the target |
| 1506 | /// directive, or null if no if clause is used. |
| 1507 | /// \param Device Expression evaluated in device clause associated with the |
| 1508 | /// target directive, or null if no device clause is used. |
Samuel Antao | 8d2d730 | 2016-05-26 18:30:22 +0000 | [diff] [blame] | 1509 | virtual void emitTargetDataStandAloneCall(CodeGenFunction &CGF, |
| 1510 | const OMPExecutableDirective &D, |
| 1511 | const Expr *IfCond, |
| 1512 | const Expr *Device); |
Alexey Bataev | c7a82b4 | 2016-05-06 09:40:08 +0000 | [diff] [blame] | 1513 | |
| 1514 | /// Marks function \a Fn with properly mangled versions of vector functions. |
| 1515 | /// \param FD Function marked as 'declare simd'. |
| 1516 | /// \param Fn LLVM function that must be marked with 'declare simd' |
| 1517 | /// attributes. |
| 1518 | virtual void emitDeclareSimdFunction(const FunctionDecl *FD, |
| 1519 | llvm::Function *Fn); |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 1520 | |
| 1521 | /// Emit initialization for doacross loop nesting support. |
| 1522 | /// \param D Loop-based construct used in doacross nesting construct. |
Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 1523 | virtual void emitDoacrossInit(CodeGenFunction &CGF, const OMPLoopDirective &D, |
| 1524 | ArrayRef<Expr *> NumIterations); |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 1525 | |
| 1526 | /// Emit code for doacross ordered directive with 'depend' clause. |
| 1527 | /// \param C 'depend' clause with 'sink|source' dependency kind. |
| 1528 | virtual void emitDoacrossOrdered(CodeGenFunction &CGF, |
| 1529 | const OMPDependClause *C); |
Alexey Bataev | 2c7eee5 | 2017-08-04 19:10:54 +0000 | [diff] [blame] | 1530 | |
Alexey Bataev | 3b8d558 | 2017-08-08 18:04:06 +0000 | [diff] [blame] | 1531 | /// Translates the native parameter of outlined function if this is required |
| 1532 | /// for target. |
Alexander Kornienko | 2a8c18d | 2018-04-06 15:14:32 +0000 | [diff] [blame] | 1533 | /// \param FD Field decl from captured record for the parameter. |
Alexey Bataev | 3b8d558 | 2017-08-08 18:04:06 +0000 | [diff] [blame] | 1534 | /// \param NativeParam Parameter itself. |
| 1535 | virtual const VarDecl *translateParameter(const FieldDecl *FD, |
| 1536 | const VarDecl *NativeParam) const { |
| 1537 | return NativeParam; |
| 1538 | } |
| 1539 | |
| 1540 | /// Gets the address of the native argument basing on the address of the |
| 1541 | /// target-specific parameter. |
| 1542 | /// \param NativeParam Parameter itself. |
| 1543 | /// \param TargetParam Corresponding target-specific parameter. |
| 1544 | virtual Address getParameterAddress(CodeGenFunction &CGF, |
| 1545 | const VarDecl *NativeParam, |
| 1546 | const VarDecl *TargetParam) const; |
| 1547 | |
Gheorghe-Teodor Bercea | 02650d4 | 2018-09-27 19:22:56 +0000 | [diff] [blame] | 1548 | /// Choose default schedule type and chunk value for the |
| 1549 | /// dist_schedule clause. |
| 1550 | virtual void getDefaultDistScheduleAndChunk(CodeGenFunction &CGF, |
| 1551 | const OMPLoopDirective &S, OpenMPDistScheduleClauseKind &ScheduleKind, |
| 1552 | llvm::Value *&Chunk) const {} |
| 1553 | |
Gheorghe-Teodor Bercea | 8233af9 | 2018-09-27 20:29:00 +0000 | [diff] [blame] | 1554 | /// Choose default schedule type and chunk value for the |
| 1555 | /// schedule clause. |
| 1556 | virtual void getDefaultScheduleAndChunk(CodeGenFunction &CGF, |
| 1557 | const OMPLoopDirective &S, OpenMPScheduleClauseKind &ScheduleKind, |
Gheorghe-Teodor Bercea | e925676 | 2018-10-29 15:45:47 +0000 | [diff] [blame] | 1558 | const Expr *&ChunkExpr) const {} |
Gheorghe-Teodor Bercea | 8233af9 | 2018-09-27 20:29:00 +0000 | [diff] [blame] | 1559 | |
Alexey Bataev | 2c7eee5 | 2017-08-04 19:10:54 +0000 | [diff] [blame] | 1560 | /// Emits call of the outlined function with the provided arguments, |
| 1561 | /// translating these arguments to correct target-specific arguments. |
| 1562 | virtual void |
Alexey Bataev | 3c595a6 | 2017-08-14 15:01:03 +0000 | [diff] [blame] | 1563 | emitOutlinedFunctionCall(CodeGenFunction &CGF, SourceLocation Loc, |
James Y Knight | 9871db0 | 2019-02-05 16:42:33 +0000 | [diff] [blame] | 1564 | llvm::FunctionCallee OutlinedFn, |
Alexey Bataev | 2c7eee5 | 2017-08-04 19:10:54 +0000 | [diff] [blame] | 1565 | ArrayRef<llvm::Value *> Args = llvm::None) const; |
Gheorghe-Teodor Bercea | d3dcf2f | 2018-03-14 14:17:45 +0000 | [diff] [blame] | 1566 | |
| 1567 | /// Emits OpenMP-specific function prolog. |
| 1568 | /// Required for device constructs. |
| 1569 | virtual void emitFunctionProlog(CodeGenFunction &CGF, const Decl *D) {} |
| 1570 | |
| 1571 | /// Gets the OpenMP-specific address of the local variable. |
| 1572 | virtual Address getAddressOfLocalVariable(CodeGenFunction &CGF, |
| 1573 | const VarDecl *VD); |
Alexey Bataev | 4f4bf7c | 2018-03-15 15:47:20 +0000 | [diff] [blame] | 1574 | |
Raphael Isemann | b23ccec | 2018-12-10 12:37:46 +0000 | [diff] [blame] | 1575 | /// Marks the declaration as already emitted for the device code and returns |
Alexey Bataev | 4f4bf7c | 2018-03-15 15:47:20 +0000 | [diff] [blame] | 1576 | /// true, if it was marked already, and false, otherwise. |
Alexey Bataev | 6d94410 | 2018-05-02 15:45:28 +0000 | [diff] [blame] | 1577 | bool markAsGlobalTarget(GlobalDecl GD); |
Alexey Bataev | 4f4bf7c | 2018-03-15 15:47:20 +0000 | [diff] [blame] | 1578 | |
Alexey Bataev | bf8fe71 | 2018-08-07 16:14:36 +0000 | [diff] [blame] | 1579 | /// Emit deferred declare target variables marked for deferred emission. |
| 1580 | void emitDeferredTargetDecls() const; |
Alexey Bataev | 6070542 | 2018-10-30 15:50:12 +0000 | [diff] [blame] | 1581 | |
| 1582 | /// Adjust some parameters for the target-based directives, like addresses of |
| 1583 | /// the variables captured by reference in lambdas. |
| 1584 | virtual void |
| 1585 | adjustTargetSpecificDataForLambdas(CodeGenFunction &CGF, |
| 1586 | const OMPExecutableDirective &D) const; |
Patrick Lyster | 8f7f586 | 2018-11-19 15:09:33 +0000 | [diff] [blame] | 1587 | |
| 1588 | /// Perform check on requires decl to ensure that target architecture |
| 1589 | /// supports unified addressing |
| 1590 | virtual void checkArchForUnifiedAddressing(CodeGenModule &CGM, |
| 1591 | const OMPRequiresDecl *D) const {} |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1592 | }; |
Alexey Bataev | 8cbe0a6 | 2015-02-26 10:27:34 +0000 | [diff] [blame] | 1593 | |
Alexey Bataev | a8a9153a | 2017-12-29 18:07:07 +0000 | [diff] [blame] | 1594 | /// Class supports emissionof SIMD-only code. |
| 1595 | class CGOpenMPSIMDRuntime final : public CGOpenMPRuntime { |
| 1596 | public: |
| 1597 | explicit CGOpenMPSIMDRuntime(CodeGenModule &CGM) : CGOpenMPRuntime(CGM) {} |
| 1598 | ~CGOpenMPSIMDRuntime() override {} |
| 1599 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1600 | /// Emits outlined function for the specified OpenMP parallel directive |
Alexey Bataev | a8a9153a | 2017-12-29 18:07:07 +0000 | [diff] [blame] | 1601 | /// \a D. This outlined function has type void(*)(kmp_int32 *ThreadID, |
| 1602 | /// kmp_int32 BoundID, struct context_vars*). |
| 1603 | /// \param D OpenMP directive. |
| 1604 | /// \param ThreadIDVar Variable for thread id in the current OpenMP region. |
| 1605 | /// \param InnermostKind Kind of innermost directive (for simple directives it |
| 1606 | /// is a directive itself, for combined - its innermost directive). |
| 1607 | /// \param CodeGen Code generation sequence for the \a D directive. |
James Y Knight | 9871db0 | 2019-02-05 16:42:33 +0000 | [diff] [blame] | 1608 | llvm::Function * |
Alexey Bataev | a8a9153a | 2017-12-29 18:07:07 +0000 | [diff] [blame] | 1609 | emitParallelOutlinedFunction(const OMPExecutableDirective &D, |
| 1610 | const VarDecl *ThreadIDVar, |
| 1611 | OpenMPDirectiveKind InnermostKind, |
| 1612 | const RegionCodeGenTy &CodeGen) override; |
| 1613 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1614 | /// Emits outlined function for the specified OpenMP teams directive |
Alexey Bataev | a8a9153a | 2017-12-29 18:07:07 +0000 | [diff] [blame] | 1615 | /// \a D. This outlined function has type void(*)(kmp_int32 *ThreadID, |
| 1616 | /// kmp_int32 BoundID, struct context_vars*). |
| 1617 | /// \param D OpenMP directive. |
| 1618 | /// \param ThreadIDVar Variable for thread id in the current OpenMP region. |
| 1619 | /// \param InnermostKind Kind of innermost directive (for simple directives it |
| 1620 | /// is a directive itself, for combined - its innermost directive). |
| 1621 | /// \param CodeGen Code generation sequence for the \a D directive. |
James Y Knight | 9871db0 | 2019-02-05 16:42:33 +0000 | [diff] [blame] | 1622 | llvm::Function * |
Alexey Bataev | a8a9153a | 2017-12-29 18:07:07 +0000 | [diff] [blame] | 1623 | emitTeamsOutlinedFunction(const OMPExecutableDirective &D, |
| 1624 | const VarDecl *ThreadIDVar, |
| 1625 | OpenMPDirectiveKind InnermostKind, |
| 1626 | const RegionCodeGenTy &CodeGen) override; |
| 1627 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1628 | /// Emits outlined function for the OpenMP task directive \a D. This |
Alexey Bataev | a8a9153a | 2017-12-29 18:07:07 +0000 | [diff] [blame] | 1629 | /// outlined function has type void(*)(kmp_int32 ThreadID, struct task_t* |
| 1630 | /// TaskT). |
| 1631 | /// \param D OpenMP directive. |
| 1632 | /// \param ThreadIDVar Variable for thread id in the current OpenMP region. |
| 1633 | /// \param PartIDVar Variable for partition id in the current OpenMP untied |
| 1634 | /// task region. |
| 1635 | /// \param TaskTVar Variable for task_t argument. |
| 1636 | /// \param InnermostKind Kind of innermost directive (for simple directives it |
| 1637 | /// is a directive itself, for combined - its innermost directive). |
| 1638 | /// \param CodeGen Code generation sequence for the \a D directive. |
| 1639 | /// \param Tied true if task is generated for tied task, false otherwise. |
| 1640 | /// \param NumberOfParts Number of parts in untied task. Ignored for tied |
| 1641 | /// tasks. |
| 1642 | /// |
James Y Knight | 9871db0 | 2019-02-05 16:42:33 +0000 | [diff] [blame] | 1643 | llvm::Function *emitTaskOutlinedFunction( |
Alexey Bataev | a8a9153a | 2017-12-29 18:07:07 +0000 | [diff] [blame] | 1644 | const OMPExecutableDirective &D, const VarDecl *ThreadIDVar, |
| 1645 | const VarDecl *PartIDVar, const VarDecl *TaskTVar, |
| 1646 | OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen, |
| 1647 | bool Tied, unsigned &NumberOfParts) override; |
| 1648 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1649 | /// Emits code for parallel or serial call of the \a OutlinedFn with |
Alexey Bataev | a8a9153a | 2017-12-29 18:07:07 +0000 | [diff] [blame] | 1650 | /// variables captured in a record which address is stored in \a |
| 1651 | /// CapturedStruct. |
| 1652 | /// \param OutlinedFn Outlined function to be run in parallel threads. Type of |
| 1653 | /// this function is void(*)(kmp_int32 *, kmp_int32, struct context_vars*). |
| 1654 | /// \param CapturedVars A pointer to the record with the references to |
| 1655 | /// variables used in \a OutlinedFn function. |
| 1656 | /// \param IfCond Condition in the associated 'if' clause, if it was |
| 1657 | /// specified, nullptr otherwise. |
| 1658 | /// |
| 1659 | void emitParallelCall(CodeGenFunction &CGF, SourceLocation Loc, |
James Y Knight | 9871db0 | 2019-02-05 16:42:33 +0000 | [diff] [blame] | 1660 | llvm::Function *OutlinedFn, |
Alexey Bataev | a8a9153a | 2017-12-29 18:07:07 +0000 | [diff] [blame] | 1661 | ArrayRef<llvm::Value *> CapturedVars, |
| 1662 | const Expr *IfCond) override; |
| 1663 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1664 | /// Emits a critical region. |
Alexey Bataev | a8a9153a | 2017-12-29 18:07:07 +0000 | [diff] [blame] | 1665 | /// \param CriticalName Name of the critical region. |
| 1666 | /// \param CriticalOpGen Generator for the statement associated with the given |
| 1667 | /// critical region. |
| 1668 | /// \param Hint Value of the 'hint' clause (optional). |
| 1669 | void emitCriticalRegion(CodeGenFunction &CGF, StringRef CriticalName, |
| 1670 | const RegionCodeGenTy &CriticalOpGen, |
| 1671 | SourceLocation Loc, |
| 1672 | const Expr *Hint = nullptr) override; |
| 1673 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1674 | /// Emits a master region. |
Alexey Bataev | a8a9153a | 2017-12-29 18:07:07 +0000 | [diff] [blame] | 1675 | /// \param MasterOpGen Generator for the statement associated with the given |
| 1676 | /// master region. |
| 1677 | void emitMasterRegion(CodeGenFunction &CGF, |
| 1678 | const RegionCodeGenTy &MasterOpGen, |
| 1679 | SourceLocation Loc) override; |
| 1680 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1681 | /// Emits code for a taskyield directive. |
Alexey Bataev | a8a9153a | 2017-12-29 18:07:07 +0000 | [diff] [blame] | 1682 | void emitTaskyieldCall(CodeGenFunction &CGF, SourceLocation Loc) override; |
| 1683 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1684 | /// Emit a taskgroup region. |
Alexey Bataev | a8a9153a | 2017-12-29 18:07:07 +0000 | [diff] [blame] | 1685 | /// \param TaskgroupOpGen Generator for the statement associated with the |
| 1686 | /// given taskgroup region. |
| 1687 | void emitTaskgroupRegion(CodeGenFunction &CGF, |
| 1688 | const RegionCodeGenTy &TaskgroupOpGen, |
| 1689 | SourceLocation Loc) override; |
| 1690 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1691 | /// Emits a single region. |
Alexey Bataev | a8a9153a | 2017-12-29 18:07:07 +0000 | [diff] [blame] | 1692 | /// \param SingleOpGen Generator for the statement associated with the given |
| 1693 | /// single region. |
| 1694 | void emitSingleRegion(CodeGenFunction &CGF, |
| 1695 | const RegionCodeGenTy &SingleOpGen, SourceLocation Loc, |
| 1696 | ArrayRef<const Expr *> CopyprivateVars, |
| 1697 | ArrayRef<const Expr *> DestExprs, |
| 1698 | ArrayRef<const Expr *> SrcExprs, |
| 1699 | ArrayRef<const Expr *> AssignmentOps) override; |
| 1700 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1701 | /// Emit an ordered region. |
Alexey Bataev | a8a9153a | 2017-12-29 18:07:07 +0000 | [diff] [blame] | 1702 | /// \param OrderedOpGen Generator for the statement associated with the given |
| 1703 | /// ordered region. |
| 1704 | void emitOrderedRegion(CodeGenFunction &CGF, |
| 1705 | const RegionCodeGenTy &OrderedOpGen, |
| 1706 | SourceLocation Loc, bool IsThreads) override; |
| 1707 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1708 | /// Emit an implicit/explicit barrier for OpenMP threads. |
Alexey Bataev | a8a9153a | 2017-12-29 18:07:07 +0000 | [diff] [blame] | 1709 | /// \param Kind Directive for which this implicit barrier call must be |
| 1710 | /// generated. Must be OMPD_barrier for explicit barrier generation. |
| 1711 | /// \param EmitChecks true if need to emit checks for cancellation barriers. |
| 1712 | /// \param ForceSimpleCall true simple barrier call must be emitted, false if |
| 1713 | /// runtime class decides which one to emit (simple or with cancellation |
| 1714 | /// checks). |
| 1715 | /// |
| 1716 | void emitBarrierCall(CodeGenFunction &CGF, SourceLocation Loc, |
| 1717 | OpenMPDirectiveKind Kind, bool EmitChecks = true, |
| 1718 | bool ForceSimpleCall = false) override; |
| 1719 | |
| 1720 | /// This is used for non static scheduled types and when the ordered |
| 1721 | /// clause is present on the loop construct. |
| 1722 | /// Depending on the loop schedule, it is necessary to call some runtime |
| 1723 | /// routine before start of the OpenMP loop to get the loop upper / lower |
| 1724 | /// bounds \a LB and \a UB and stride \a ST. |
| 1725 | /// |
| 1726 | /// \param CGF Reference to current CodeGenFunction. |
| 1727 | /// \param Loc Clang source location. |
| 1728 | /// \param ScheduleKind Schedule kind, specified by the 'schedule' clause. |
| 1729 | /// \param IVSize Size of the iteration variable in bits. |
| 1730 | /// \param IVSigned Sign of the iteration variable. |
| 1731 | /// \param Ordered true if loop is ordered, false otherwise. |
| 1732 | /// \param DispatchValues struct containing llvm values for lower bound, upper |
| 1733 | /// bound, and chunk expression. |
| 1734 | /// For the default (nullptr) value, the chunk 1 will be used. |
| 1735 | /// |
| 1736 | void emitForDispatchInit(CodeGenFunction &CGF, SourceLocation Loc, |
| 1737 | const OpenMPScheduleTy &ScheduleKind, |
| 1738 | unsigned IVSize, bool IVSigned, bool Ordered, |
| 1739 | const DispatchRTInput &DispatchValues) override; |
| 1740 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1741 | /// Call the appropriate runtime routine to initialize it before start |
Alexey Bataev | a8a9153a | 2017-12-29 18:07:07 +0000 | [diff] [blame] | 1742 | /// of loop. |
| 1743 | /// |
| 1744 | /// This is used only in case of static schedule, when the user did not |
| 1745 | /// specify a ordered clause on the loop construct. |
| 1746 | /// Depending on the loop schedule, it is necessary to call some runtime |
| 1747 | /// routine before start of the OpenMP loop to get the loop upper / lower |
| 1748 | /// bounds LB and UB and stride ST. |
| 1749 | /// |
| 1750 | /// \param CGF Reference to current CodeGenFunction. |
| 1751 | /// \param Loc Clang source location. |
| 1752 | /// \param DKind Kind of the directive. |
| 1753 | /// \param ScheduleKind Schedule kind, specified by the 'schedule' clause. |
| 1754 | /// \param Values Input arguments for the construct. |
| 1755 | /// |
| 1756 | void emitForStaticInit(CodeGenFunction &CGF, SourceLocation Loc, |
| 1757 | OpenMPDirectiveKind DKind, |
| 1758 | const OpenMPScheduleTy &ScheduleKind, |
| 1759 | const StaticRTInput &Values) override; |
| 1760 | |
| 1761 | /// |
| 1762 | /// \param CGF Reference to current CodeGenFunction. |
| 1763 | /// \param Loc Clang source location. |
| 1764 | /// \param SchedKind Schedule kind, specified by the 'dist_schedule' clause. |
| 1765 | /// \param Values Input arguments for the construct. |
| 1766 | /// |
| 1767 | void emitDistributeStaticInit(CodeGenFunction &CGF, SourceLocation Loc, |
| 1768 | OpenMPDistScheduleClauseKind SchedKind, |
| 1769 | const StaticRTInput &Values) override; |
| 1770 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1771 | /// Call the appropriate runtime routine to notify that we finished |
Alexey Bataev | a8a9153a | 2017-12-29 18:07:07 +0000 | [diff] [blame] | 1772 | /// iteration of the ordered loop with the dynamic scheduling. |
| 1773 | /// |
| 1774 | /// \param CGF Reference to current CodeGenFunction. |
| 1775 | /// \param Loc Clang source location. |
| 1776 | /// \param IVSize Size of the iteration variable in bits. |
| 1777 | /// \param IVSigned Sign of the iteration variable. |
| 1778 | /// |
| 1779 | void emitForOrderedIterationEnd(CodeGenFunction &CGF, SourceLocation Loc, |
| 1780 | unsigned IVSize, bool IVSigned) override; |
| 1781 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1782 | /// Call the appropriate runtime routine to notify that we finished |
Alexey Bataev | a8a9153a | 2017-12-29 18:07:07 +0000 | [diff] [blame] | 1783 | /// all the work with current loop. |
| 1784 | /// |
| 1785 | /// \param CGF Reference to current CodeGenFunction. |
| 1786 | /// \param Loc Clang source location. |
| 1787 | /// \param DKind Kind of the directive for which the static finish is emitted. |
| 1788 | /// |
| 1789 | void emitForStaticFinish(CodeGenFunction &CGF, SourceLocation Loc, |
| 1790 | OpenMPDirectiveKind DKind) override; |
| 1791 | |
| 1792 | /// Call __kmpc_dispatch_next( |
| 1793 | /// ident_t *loc, kmp_int32 tid, kmp_int32 *p_lastiter, |
| 1794 | /// kmp_int[32|64] *p_lower, kmp_int[32|64] *p_upper, |
| 1795 | /// kmp_int[32|64] *p_stride); |
| 1796 | /// \param IVSize Size of the iteration variable in bits. |
| 1797 | /// \param IVSigned Sign of the iteration variable. |
| 1798 | /// \param IL Address of the output variable in which the flag of the |
| 1799 | /// last iteration is returned. |
| 1800 | /// \param LB Address of the output variable in which the lower iteration |
| 1801 | /// number is returned. |
| 1802 | /// \param UB Address of the output variable in which the upper iteration |
| 1803 | /// number is returned. |
| 1804 | /// \param ST Address of the output variable in which the stride value is |
| 1805 | /// returned. |
| 1806 | llvm::Value *emitForNext(CodeGenFunction &CGF, SourceLocation Loc, |
| 1807 | unsigned IVSize, bool IVSigned, Address IL, |
| 1808 | Address LB, Address UB, Address ST) override; |
| 1809 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1810 | /// Emits call to void __kmpc_push_num_threads(ident_t *loc, kmp_int32 |
Alexey Bataev | a8a9153a | 2017-12-29 18:07:07 +0000 | [diff] [blame] | 1811 | /// global_tid, kmp_int32 num_threads) to generate code for 'num_threads' |
| 1812 | /// clause. |
| 1813 | /// \param NumThreads An integer value of threads. |
| 1814 | void emitNumThreadsClause(CodeGenFunction &CGF, llvm::Value *NumThreads, |
| 1815 | SourceLocation Loc) override; |
| 1816 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1817 | /// Emit call to void __kmpc_push_proc_bind(ident_t *loc, kmp_int32 |
Alexey Bataev | a8a9153a | 2017-12-29 18:07:07 +0000 | [diff] [blame] | 1818 | /// global_tid, int proc_bind) to generate code for 'proc_bind' clause. |
| 1819 | void emitProcBindClause(CodeGenFunction &CGF, |
| 1820 | OpenMPProcBindClauseKind ProcBind, |
| 1821 | SourceLocation Loc) override; |
| 1822 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1823 | /// Returns address of the threadprivate variable for the current |
Alexey Bataev | a8a9153a | 2017-12-29 18:07:07 +0000 | [diff] [blame] | 1824 | /// thread. |
| 1825 | /// \param VD Threadprivate variable. |
| 1826 | /// \param VDAddr Address of the global variable \a VD. |
| 1827 | /// \param Loc Location of the reference to threadprivate var. |
| 1828 | /// \return Address of the threadprivate variable for the current thread. |
| 1829 | Address getAddrOfThreadPrivate(CodeGenFunction &CGF, const VarDecl *VD, |
| 1830 | Address VDAddr, SourceLocation Loc) override; |
| 1831 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1832 | /// Emit a code for initialization of threadprivate variable. It emits |
Alexey Bataev | a8a9153a | 2017-12-29 18:07:07 +0000 | [diff] [blame] | 1833 | /// a call to runtime library which adds initial value to the newly created |
| 1834 | /// threadprivate variable (if it is not constant) and registers destructor |
| 1835 | /// for the variable (if any). |
| 1836 | /// \param VD Threadprivate variable. |
| 1837 | /// \param VDAddr Address of the global variable \a VD. |
| 1838 | /// \param Loc Location of threadprivate declaration. |
| 1839 | /// \param PerformInit true if initialization expression is not constant. |
| 1840 | llvm::Function * |
| 1841 | emitThreadPrivateVarDefinition(const VarDecl *VD, Address VDAddr, |
| 1842 | SourceLocation Loc, bool PerformInit, |
| 1843 | CodeGenFunction *CGF = nullptr) override; |
| 1844 | |
| 1845 | /// Creates artificial threadprivate variable with name \p Name and type \p |
| 1846 | /// VarType. |
| 1847 | /// \param VarType Type of the artificial threadprivate variable. |
| 1848 | /// \param Name Name of the artificial threadprivate variable. |
| 1849 | Address getAddrOfArtificialThreadPrivate(CodeGenFunction &CGF, |
| 1850 | QualType VarType, |
| 1851 | StringRef Name) override; |
| 1852 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1853 | /// Emit flush of the variables specified in 'omp flush' directive. |
Alexey Bataev | a8a9153a | 2017-12-29 18:07:07 +0000 | [diff] [blame] | 1854 | /// \param Vars List of variables to flush. |
| 1855 | void emitFlush(CodeGenFunction &CGF, ArrayRef<const Expr *> Vars, |
| 1856 | SourceLocation Loc) override; |
| 1857 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1858 | /// Emit task region for the task directive. The task region is |
Alexey Bataev | a8a9153a | 2017-12-29 18:07:07 +0000 | [diff] [blame] | 1859 | /// emitted in several steps: |
| 1860 | /// 1. Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32 |
| 1861 | /// gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds, |
| 1862 | /// kmp_routine_entry_t *task_entry). Here task_entry is a pointer to the |
| 1863 | /// function: |
| 1864 | /// kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) { |
| 1865 | /// TaskFunction(gtid, tt->part_id, tt->shareds); |
| 1866 | /// return 0; |
| 1867 | /// } |
| 1868 | /// 2. Copy a list of shared variables to field shareds of the resulting |
| 1869 | /// structure kmp_task_t returned by the previous call (if any). |
| 1870 | /// 3. Copy a pointer to destructions function to field destructions of the |
| 1871 | /// resulting structure kmp_task_t. |
| 1872 | /// 4. Emit a call to kmp_int32 __kmpc_omp_task(ident_t *, kmp_int32 gtid, |
| 1873 | /// kmp_task_t *new_task), where new_task is a resulting structure from |
| 1874 | /// previous items. |
| 1875 | /// \param D Current task directive. |
| 1876 | /// \param TaskFunction An LLVM function with type void (*)(i32 /*gtid*/, i32 |
| 1877 | /// /*part_id*/, captured_struct */*__context*/); |
| 1878 | /// \param SharedsTy A type which contains references the shared variables. |
| 1879 | /// \param Shareds Context with the list of shared variables from the \p |
| 1880 | /// TaskFunction. |
| 1881 | /// \param IfCond Not a nullptr if 'if' clause was specified, nullptr |
| 1882 | /// otherwise. |
| 1883 | /// \param Data Additional data for task generation like tiednsee, final |
| 1884 | /// state, list of privates etc. |
| 1885 | void emitTaskCall(CodeGenFunction &CGF, SourceLocation Loc, |
James Y Knight | 9871db0 | 2019-02-05 16:42:33 +0000 | [diff] [blame] | 1886 | const OMPExecutableDirective &D, |
| 1887 | llvm::Function *TaskFunction, QualType SharedsTy, |
| 1888 | Address Shareds, const Expr *IfCond, |
Alexey Bataev | a8a9153a | 2017-12-29 18:07:07 +0000 | [diff] [blame] | 1889 | const OMPTaskDataTy &Data) override; |
| 1890 | |
| 1891 | /// Emit task region for the taskloop directive. The taskloop region is |
| 1892 | /// emitted in several steps: |
| 1893 | /// 1. Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32 |
| 1894 | /// gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds, |
| 1895 | /// kmp_routine_entry_t *task_entry). Here task_entry is a pointer to the |
| 1896 | /// function: |
| 1897 | /// kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) { |
| 1898 | /// TaskFunction(gtid, tt->part_id, tt->shareds); |
| 1899 | /// return 0; |
| 1900 | /// } |
| 1901 | /// 2. Copy a list of shared variables to field shareds of the resulting |
| 1902 | /// structure kmp_task_t returned by the previous call (if any). |
| 1903 | /// 3. Copy a pointer to destructions function to field destructions of the |
| 1904 | /// resulting structure kmp_task_t. |
| 1905 | /// 4. Emit a call to void __kmpc_taskloop(ident_t *loc, int gtid, kmp_task_t |
| 1906 | /// *task, int if_val, kmp_uint64 *lb, kmp_uint64 *ub, kmp_int64 st, int |
| 1907 | /// nogroup, int sched, kmp_uint64 grainsize, void *task_dup ), where new_task |
| 1908 | /// is a resulting structure from |
| 1909 | /// previous items. |
| 1910 | /// \param D Current task directive. |
| 1911 | /// \param TaskFunction An LLVM function with type void (*)(i32 /*gtid*/, i32 |
| 1912 | /// /*part_id*/, captured_struct */*__context*/); |
| 1913 | /// \param SharedsTy A type which contains references the shared variables. |
| 1914 | /// \param Shareds Context with the list of shared variables from the \p |
| 1915 | /// TaskFunction. |
| 1916 | /// \param IfCond Not a nullptr if 'if' clause was specified, nullptr |
| 1917 | /// otherwise. |
| 1918 | /// \param Data Additional data for task generation like tiednsee, final |
| 1919 | /// state, list of privates etc. |
| 1920 | void emitTaskLoopCall(CodeGenFunction &CGF, SourceLocation Loc, |
James Y Knight | 9871db0 | 2019-02-05 16:42:33 +0000 | [diff] [blame] | 1921 | const OMPLoopDirective &D, llvm::Function *TaskFunction, |
Alexey Bataev | a8a9153a | 2017-12-29 18:07:07 +0000 | [diff] [blame] | 1922 | QualType SharedsTy, Address Shareds, const Expr *IfCond, |
| 1923 | const OMPTaskDataTy &Data) override; |
| 1924 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1925 | /// Emit a code for reduction clause. Next code should be emitted for |
Alexey Bataev | a8a9153a | 2017-12-29 18:07:07 +0000 | [diff] [blame] | 1926 | /// reduction: |
| 1927 | /// \code |
| 1928 | /// |
| 1929 | /// static kmp_critical_name lock = { 0 }; |
| 1930 | /// |
| 1931 | /// void reduce_func(void *lhs[<n>], void *rhs[<n>]) { |
| 1932 | /// ... |
| 1933 | /// *(Type<i>*)lhs[i] = RedOp<i>(*(Type<i>*)lhs[i], *(Type<i>*)rhs[i]); |
| 1934 | /// ... |
| 1935 | /// } |
| 1936 | /// |
| 1937 | /// ... |
| 1938 | /// void *RedList[<n>] = {&<RHSExprs>[0], ..., &<RHSExprs>[<n>-1]}; |
| 1939 | /// switch (__kmpc_reduce{_nowait}(<loc>, <gtid>, <n>, sizeof(RedList), |
| 1940 | /// RedList, reduce_func, &<lock>)) { |
| 1941 | /// case 1: |
| 1942 | /// ... |
| 1943 | /// <LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]); |
| 1944 | /// ... |
| 1945 | /// __kmpc_end_reduce{_nowait}(<loc>, <gtid>, &<lock>); |
| 1946 | /// break; |
| 1947 | /// case 2: |
| 1948 | /// ... |
| 1949 | /// Atomic(<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i])); |
| 1950 | /// ... |
| 1951 | /// break; |
| 1952 | /// default:; |
| 1953 | /// } |
| 1954 | /// \endcode |
| 1955 | /// |
| 1956 | /// \param Privates List of private copies for original reduction arguments. |
| 1957 | /// \param LHSExprs List of LHS in \a ReductionOps reduction operations. |
| 1958 | /// \param RHSExprs List of RHS in \a ReductionOps reduction operations. |
| 1959 | /// \param ReductionOps List of reduction operations in form 'LHS binop RHS' |
| 1960 | /// or 'operator binop(LHS, RHS)'. |
| 1961 | /// \param Options List of options for reduction codegen: |
| 1962 | /// WithNowait true if parent directive has also nowait clause, false |
| 1963 | /// otherwise. |
| 1964 | /// SimpleReduction Emit reduction operation only. Used for omp simd |
| 1965 | /// directive on the host. |
| 1966 | /// ReductionKind The kind of reduction to perform. |
| 1967 | void emitReduction(CodeGenFunction &CGF, SourceLocation Loc, |
| 1968 | ArrayRef<const Expr *> Privates, |
| 1969 | ArrayRef<const Expr *> LHSExprs, |
| 1970 | ArrayRef<const Expr *> RHSExprs, |
| 1971 | ArrayRef<const Expr *> ReductionOps, |
| 1972 | ReductionOptionsTy Options) override; |
| 1973 | |
| 1974 | /// Emit a code for initialization of task reduction clause. Next code |
| 1975 | /// should be emitted for reduction: |
| 1976 | /// \code |
| 1977 | /// |
| 1978 | /// _task_red_item_t red_data[n]; |
| 1979 | /// ... |
| 1980 | /// red_data[i].shar = &origs[i]; |
| 1981 | /// red_data[i].size = sizeof(origs[i]); |
| 1982 | /// red_data[i].f_init = (void*)RedInit<i>; |
| 1983 | /// red_data[i].f_fini = (void*)RedDest<i>; |
| 1984 | /// red_data[i].f_comb = (void*)RedOp<i>; |
| 1985 | /// red_data[i].flags = <Flag_i>; |
| 1986 | /// ... |
| 1987 | /// void* tg1 = __kmpc_task_reduction_init(gtid, n, red_data); |
| 1988 | /// \endcode |
| 1989 | /// |
| 1990 | /// \param LHSExprs List of LHS in \a Data.ReductionOps reduction operations. |
| 1991 | /// \param RHSExprs List of RHS in \a Data.ReductionOps reduction operations. |
| 1992 | /// \param Data Additional data for task generation like tiedness, final |
| 1993 | /// state, list of privates, reductions etc. |
| 1994 | llvm::Value *emitTaskReductionInit(CodeGenFunction &CGF, SourceLocation Loc, |
| 1995 | ArrayRef<const Expr *> LHSExprs, |
| 1996 | ArrayRef<const Expr *> RHSExprs, |
| 1997 | const OMPTaskDataTy &Data) override; |
| 1998 | |
| 1999 | /// Required to resolve existing problems in the runtime. Emits threadprivate |
| 2000 | /// variables to store the size of the VLAs/array sections for |
| 2001 | /// initializer/combiner/finalizer functions + emits threadprivate variable to |
| 2002 | /// store the pointer to the original reduction item for the custom |
| 2003 | /// initializer defined by declare reduction construct. |
| 2004 | /// \param RCG Allows to reuse an existing data for the reductions. |
| 2005 | /// \param N Reduction item for which fixups must be emitted. |
| 2006 | void emitTaskReductionFixups(CodeGenFunction &CGF, SourceLocation Loc, |
| 2007 | ReductionCodeGen &RCG, unsigned N) override; |
| 2008 | |
| 2009 | /// Get the address of `void *` type of the privatue copy of the reduction |
| 2010 | /// item specified by the \p SharedLVal. |
| 2011 | /// \param ReductionsPtr Pointer to the reduction data returned by the |
| 2012 | /// emitTaskReductionInit function. |
| 2013 | /// \param SharedLVal Address of the original reduction item. |
| 2014 | Address getTaskReductionItem(CodeGenFunction &CGF, SourceLocation Loc, |
| 2015 | llvm::Value *ReductionsPtr, |
| 2016 | LValue SharedLVal) override; |
| 2017 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2018 | /// Emit code for 'taskwait' directive. |
Alexey Bataev | a8a9153a | 2017-12-29 18:07:07 +0000 | [diff] [blame] | 2019 | void emitTaskwaitCall(CodeGenFunction &CGF, SourceLocation Loc) override; |
| 2020 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2021 | /// Emit code for 'cancellation point' construct. |
Alexey Bataev | a8a9153a | 2017-12-29 18:07:07 +0000 | [diff] [blame] | 2022 | /// \param CancelRegion Region kind for which the cancellation point must be |
| 2023 | /// emitted. |
| 2024 | /// |
| 2025 | void emitCancellationPointCall(CodeGenFunction &CGF, SourceLocation Loc, |
| 2026 | OpenMPDirectiveKind CancelRegion) override; |
| 2027 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2028 | /// Emit code for 'cancel' construct. |
Alexey Bataev | a8a9153a | 2017-12-29 18:07:07 +0000 | [diff] [blame] | 2029 | /// \param IfCond Condition in the associated 'if' clause, if it was |
| 2030 | /// specified, nullptr otherwise. |
| 2031 | /// \param CancelRegion Region kind for which the cancel must be emitted. |
| 2032 | /// |
| 2033 | void emitCancelCall(CodeGenFunction &CGF, SourceLocation Loc, |
| 2034 | const Expr *IfCond, |
| 2035 | OpenMPDirectiveKind CancelRegion) override; |
| 2036 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2037 | /// Emit outilined function for 'target' directive. |
Alexey Bataev | a8a9153a | 2017-12-29 18:07:07 +0000 | [diff] [blame] | 2038 | /// \param D Directive to emit. |
| 2039 | /// \param ParentName Name of the function that encloses the target region. |
| 2040 | /// \param OutlinedFn Outlined function value to be defined by this call. |
| 2041 | /// \param OutlinedFnID Outlined function ID value to be defined by this call. |
| 2042 | /// \param IsOffloadEntry True if the outlined function is an offload entry. |
| 2043 | /// \param CodeGen Code generation sequence for the \a D directive. |
| 2044 | /// An outlined function may not be an entry if, e.g. the if clause always |
| 2045 | /// evaluates to false. |
| 2046 | void emitTargetOutlinedFunction(const OMPExecutableDirective &D, |
| 2047 | StringRef ParentName, |
| 2048 | llvm::Function *&OutlinedFn, |
| 2049 | llvm::Constant *&OutlinedFnID, |
| 2050 | bool IsOffloadEntry, |
| 2051 | const RegionCodeGenTy &CodeGen) override; |
| 2052 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2053 | /// Emit the target offloading code associated with \a D. The emitted |
Alexey Bataev | a8a9153a | 2017-12-29 18:07:07 +0000 | [diff] [blame] | 2054 | /// code attempts offloading the execution to the device, an the event of |
| 2055 | /// a failure it executes the host version outlined in \a OutlinedFn. |
| 2056 | /// \param D Directive to emit. |
| 2057 | /// \param OutlinedFn Host version of the code to be offloaded. |
| 2058 | /// \param OutlinedFnID ID of host version of the code to be offloaded. |
| 2059 | /// \param IfCond Expression evaluated in if clause associated with the target |
| 2060 | /// directive, or null if no if clause is used. |
| 2061 | /// \param Device Expression evaluated in device clause associated with the |
| 2062 | /// target directive, or null if no device clause is used. |
Alexey Bataev | a8a9153a | 2017-12-29 18:07:07 +0000 | [diff] [blame] | 2063 | void emitTargetCall(CodeGenFunction &CGF, const OMPExecutableDirective &D, |
James Y Knight | 9871db0 | 2019-02-05 16:42:33 +0000 | [diff] [blame] | 2064 | llvm::Function *OutlinedFn, llvm::Value *OutlinedFnID, |
Alexey Bataev | 8451efa | 2018-01-15 19:06:12 +0000 | [diff] [blame] | 2065 | const Expr *IfCond, const Expr *Device) override; |
Alexey Bataev | a8a9153a | 2017-12-29 18:07:07 +0000 | [diff] [blame] | 2066 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2067 | /// Emit the target regions enclosed in \a GD function definition or |
Alexey Bataev | a8a9153a | 2017-12-29 18:07:07 +0000 | [diff] [blame] | 2068 | /// the function itself in case it is a valid device function. Returns true if |
| 2069 | /// \a GD was dealt with successfully. |
| 2070 | /// \param GD Function to scan. |
| 2071 | bool emitTargetFunctions(GlobalDecl GD) override; |
| 2072 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2073 | /// Emit the global variable if it is a valid device global variable. |
Alexey Bataev | a8a9153a | 2017-12-29 18:07:07 +0000 | [diff] [blame] | 2074 | /// Returns true if \a GD was dealt with successfully. |
| 2075 | /// \param GD Variable declaration to emit. |
| 2076 | bool emitTargetGlobalVariable(GlobalDecl GD) override; |
| 2077 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2078 | /// Emit the global \a GD if it is meaningful for the target. Returns |
Alexey Bataev | a8a9153a | 2017-12-29 18:07:07 +0000 | [diff] [blame] | 2079 | /// if it was emitted successfully. |
| 2080 | /// \param GD Global to scan. |
| 2081 | bool emitTargetGlobal(GlobalDecl GD) override; |
| 2082 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2083 | /// Creates the offloading descriptor in the event any target region |
Alexey Bataev | a8a9153a | 2017-12-29 18:07:07 +0000 | [diff] [blame] | 2084 | /// was emitted in the current module and return the function that registers |
| 2085 | /// it. |
| 2086 | llvm::Function *emitRegistrationFunction() override; |
| 2087 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2088 | /// Emits code for teams call of the \a OutlinedFn with |
Alexey Bataev | a8a9153a | 2017-12-29 18:07:07 +0000 | [diff] [blame] | 2089 | /// variables captured in a record which address is stored in \a |
| 2090 | /// CapturedStruct. |
| 2091 | /// \param OutlinedFn Outlined function to be run by team masters. Type of |
| 2092 | /// this function is void(*)(kmp_int32 *, kmp_int32, struct context_vars*). |
| 2093 | /// \param CapturedVars A pointer to the record with the references to |
| 2094 | /// variables used in \a OutlinedFn function. |
| 2095 | /// |
| 2096 | void emitTeamsCall(CodeGenFunction &CGF, const OMPExecutableDirective &D, |
James Y Knight | 9871db0 | 2019-02-05 16:42:33 +0000 | [diff] [blame] | 2097 | SourceLocation Loc, llvm::Function *OutlinedFn, |
Alexey Bataev | a8a9153a | 2017-12-29 18:07:07 +0000 | [diff] [blame] | 2098 | ArrayRef<llvm::Value *> CapturedVars) override; |
| 2099 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2100 | /// Emits call to void __kmpc_push_num_teams(ident_t *loc, kmp_int32 |
Alexey Bataev | a8a9153a | 2017-12-29 18:07:07 +0000 | [diff] [blame] | 2101 | /// global_tid, kmp_int32 num_teams, kmp_int32 thread_limit) to generate code |
| 2102 | /// for num_teams clause. |
| 2103 | /// \param NumTeams An integer expression of teams. |
| 2104 | /// \param ThreadLimit An integer expression of threads. |
| 2105 | void emitNumTeamsClause(CodeGenFunction &CGF, const Expr *NumTeams, |
| 2106 | const Expr *ThreadLimit, SourceLocation Loc) override; |
| 2107 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2108 | /// Emit the target data mapping code associated with \a D. |
Alexey Bataev | a8a9153a | 2017-12-29 18:07:07 +0000 | [diff] [blame] | 2109 | /// \param D Directive to emit. |
| 2110 | /// \param IfCond Expression evaluated in if clause associated with the |
| 2111 | /// target directive, or null if no device clause is used. |
| 2112 | /// \param Device Expression evaluated in device clause associated with the |
| 2113 | /// target directive, or null if no device clause is used. |
| 2114 | /// \param Info A record used to store information that needs to be preserved |
| 2115 | /// until the region is closed. |
| 2116 | void emitTargetDataCalls(CodeGenFunction &CGF, |
| 2117 | const OMPExecutableDirective &D, const Expr *IfCond, |
| 2118 | const Expr *Device, const RegionCodeGenTy &CodeGen, |
| 2119 | TargetDataInfo &Info) override; |
| 2120 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2121 | /// Emit the data mapping/movement code associated with the directive |
Alexey Bataev | a8a9153a | 2017-12-29 18:07:07 +0000 | [diff] [blame] | 2122 | /// \a D that should be of the form 'target [{enter|exit} data | update]'. |
| 2123 | /// \param D Directive to emit. |
| 2124 | /// \param IfCond Expression evaluated in if clause associated with the target |
| 2125 | /// directive, or null if no if clause is used. |
| 2126 | /// \param Device Expression evaluated in device clause associated with the |
| 2127 | /// target directive, or null if no device clause is used. |
| 2128 | void emitTargetDataStandAloneCall(CodeGenFunction &CGF, |
| 2129 | const OMPExecutableDirective &D, |
| 2130 | const Expr *IfCond, |
| 2131 | const Expr *Device) override; |
| 2132 | |
| 2133 | /// Emit initialization for doacross loop nesting support. |
| 2134 | /// \param D Loop-based construct used in doacross nesting construct. |
Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 2135 | void emitDoacrossInit(CodeGenFunction &CGF, const OMPLoopDirective &D, |
| 2136 | ArrayRef<Expr *> NumIterations) override; |
Alexey Bataev | a8a9153a | 2017-12-29 18:07:07 +0000 | [diff] [blame] | 2137 | |
| 2138 | /// Emit code for doacross ordered directive with 'depend' clause. |
| 2139 | /// \param C 'depend' clause with 'sink|source' dependency kind. |
| 2140 | void emitDoacrossOrdered(CodeGenFunction &CGF, |
| 2141 | const OMPDependClause *C) override; |
| 2142 | |
| 2143 | /// Translates the native parameter of outlined function if this is required |
| 2144 | /// for target. |
Alexander Kornienko | 2a8c18d | 2018-04-06 15:14:32 +0000 | [diff] [blame] | 2145 | /// \param FD Field decl from captured record for the parameter. |
Alexey Bataev | a8a9153a | 2017-12-29 18:07:07 +0000 | [diff] [blame] | 2146 | /// \param NativeParam Parameter itself. |
| 2147 | const VarDecl *translateParameter(const FieldDecl *FD, |
| 2148 | const VarDecl *NativeParam) const override; |
| 2149 | |
| 2150 | /// Gets the address of the native argument basing on the address of the |
| 2151 | /// target-specific parameter. |
| 2152 | /// \param NativeParam Parameter itself. |
| 2153 | /// \param TargetParam Corresponding target-specific parameter. |
| 2154 | Address getParameterAddress(CodeGenFunction &CGF, const VarDecl *NativeParam, |
| 2155 | const VarDecl *TargetParam) const override; |
| 2156 | }; |
| 2157 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 2158 | } // namespace CodeGen |
| 2159 | } // namespace clang |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 2160 | |
| 2161 | #endif |