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