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