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