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