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