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