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