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