1 //===----- CGOpenMPRuntime.h - Interface to OpenMP Runtimes -----*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This provides a class for OpenMP runtime code generation. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #ifndef LLVM_CLANG_LIB_CODEGEN_CGOPENMPRUNTIME_H 14 #define LLVM_CLANG_LIB_CODEGEN_CGOPENMPRUNTIME_H 15 16 #include "CGValue.h" 17 #include "clang/AST/DeclOpenMP.h" 18 #include "clang/AST/GlobalDecl.h" 19 #include "clang/AST/Type.h" 20 #include "clang/Basic/OpenMPKinds.h" 21 #include "clang/Basic/SourceLocation.h" 22 #include "llvm/ADT/DenseMap.h" 23 #include "llvm/ADT/PointerIntPair.h" 24 #include "llvm/ADT/SmallPtrSet.h" 25 #include "llvm/ADT/StringMap.h" 26 #include "llvm/ADT/StringSet.h" 27 #include "llvm/Frontend/OpenMP/OMPConstants.h" 28 #include "llvm/Frontend/OpenMP/OMPIRBuilder.h" 29 #include "llvm/IR/Function.h" 30 #include "llvm/IR/ValueHandle.h" 31 #include "llvm/Support/AtomicOrdering.h" 32 33 namespace llvm { 34 class ArrayType; 35 class Constant; 36 class FunctionType; 37 class GlobalVariable; 38 class StructType; 39 class Type; 40 class Value; 41 class OpenMPIRBuilder; 42 } // namespace llvm 43 44 namespace clang { 45 class Expr; 46 class OMPDependClause; 47 class OMPExecutableDirective; 48 class OMPLoopDirective; 49 class VarDecl; 50 class OMPDeclareReductionDecl; 51 class IdentifierInfo; 52 53 namespace CodeGen { 54 class Address; 55 class CodeGenFunction; 56 class CodeGenModule; 57 58 /// A basic class for pre|post-action for advanced codegen sequence for OpenMP 59 /// region. 60 class PrePostActionTy { 61 public: 62 explicit PrePostActionTy() {} 63 virtual void Enter(CodeGenFunction &CGF) {} 64 virtual void Exit(CodeGenFunction &CGF) {} 65 virtual ~PrePostActionTy() {} 66 }; 67 68 /// Class provides a way to call simple version of codegen for OpenMP region, or 69 /// an advanced with possible pre|post-actions in codegen. 70 class RegionCodeGenTy final { 71 intptr_t CodeGen; 72 typedef void (*CodeGenTy)(intptr_t, CodeGenFunction &, PrePostActionTy &); 73 CodeGenTy Callback; 74 mutable PrePostActionTy *PrePostAction; 75 RegionCodeGenTy() = delete; 76 template <typename Callable> 77 static void CallbackFn(intptr_t CodeGen, CodeGenFunction &CGF, 78 PrePostActionTy &Action) { 79 return (*reinterpret_cast<Callable *>(CodeGen))(CGF, Action); 80 } 81 82 public: 83 template <typename Callable> 84 RegionCodeGenTy( 85 Callable &&CodeGen, 86 std::enable_if_t<!std::is_same<std::remove_reference_t<Callable>, 87 RegionCodeGenTy>::value> * = nullptr) 88 : CodeGen(reinterpret_cast<intptr_t>(&CodeGen)), 89 Callback(CallbackFn<std::remove_reference_t<Callable>>), 90 PrePostAction(nullptr) {} 91 void setAction(PrePostActionTy &Action) const { PrePostAction = &Action; } 92 void operator()(CodeGenFunction &CGF) const; 93 }; 94 95 struct OMPTaskDataTy final { 96 SmallVector<const Expr *, 4> PrivateVars; 97 SmallVector<const Expr *, 4> PrivateCopies; 98 SmallVector<const Expr *, 4> FirstprivateVars; 99 SmallVector<const Expr *, 4> FirstprivateCopies; 100 SmallVector<const Expr *, 4> FirstprivateInits; 101 SmallVector<const Expr *, 4> LastprivateVars; 102 SmallVector<const Expr *, 4> LastprivateCopies; 103 SmallVector<const Expr *, 4> ReductionVars; 104 SmallVector<const Expr *, 4> ReductionOrigs; 105 SmallVector<const Expr *, 4> ReductionCopies; 106 SmallVector<const Expr *, 4> ReductionOps; 107 SmallVector<CanonicalDeclPtr<const VarDecl>, 4> PrivateLocals; 108 struct DependData { 109 OpenMPDependClauseKind DepKind = OMPC_DEPEND_unknown; 110 const Expr *IteratorExpr = nullptr; 111 SmallVector<const Expr *, 4> DepExprs; 112 explicit DependData() = default; 113 DependData(OpenMPDependClauseKind DepKind, const Expr *IteratorExpr) 114 : DepKind(DepKind), IteratorExpr(IteratorExpr) {} 115 }; 116 SmallVector<DependData, 4> Dependences; 117 llvm::PointerIntPair<llvm::Value *, 1, bool> Final; 118 llvm::PointerIntPair<llvm::Value *, 1, bool> Schedule; 119 llvm::PointerIntPair<llvm::Value *, 1, bool> Priority; 120 llvm::Value *Reductions = nullptr; 121 unsigned NumberOfParts = 0; 122 bool Tied = true; 123 bool Nogroup = false; 124 bool IsReductionWithTaskMod = false; 125 bool IsWorksharingReduction = false; 126 }; 127 128 /// Class intended to support codegen of all kind of the reduction clauses. 129 class ReductionCodeGen { 130 private: 131 /// Data required for codegen of reduction clauses. 132 struct ReductionData { 133 /// Reference to the item shared between tasks to reduce into. 134 const Expr *Shared = nullptr; 135 /// Reference to the original item. 136 const Expr *Ref = nullptr; 137 /// Helper expression for generation of private copy. 138 const Expr *Private = nullptr; 139 /// Helper expression for generation reduction operation. 140 const Expr *ReductionOp = nullptr; 141 ReductionData(const Expr *Shared, const Expr *Ref, const Expr *Private, 142 const Expr *ReductionOp) 143 : Shared(Shared), Ref(Ref), Private(Private), ReductionOp(ReductionOp) { 144 } 145 }; 146 /// List of reduction-based clauses. 147 SmallVector<ReductionData, 4> ClausesData; 148 149 /// List of addresses of shared variables/expressions. 150 SmallVector<std::pair<LValue, LValue>, 4> SharedAddresses; 151 /// List of addresses of original variables/expressions. 152 SmallVector<std::pair<LValue, LValue>, 4> OrigAddresses; 153 /// Sizes of the reduction items in chars. 154 SmallVector<std::pair<llvm::Value *, llvm::Value *>, 4> Sizes; 155 /// Base declarations for the reduction items. 156 SmallVector<const VarDecl *, 4> BaseDecls; 157 158 /// Emits lvalue for shared expression. 159 LValue emitSharedLValue(CodeGenFunction &CGF, const Expr *E); 160 /// Emits upper bound for shared expression (if array section). 161 LValue emitSharedLValueUB(CodeGenFunction &CGF, const Expr *E); 162 /// Performs aggregate initialization. 163 /// \param N Number of reduction item in the common list. 164 /// \param PrivateAddr Address of the corresponding private item. 165 /// \param SharedLVal Address of the original shared variable. 166 /// \param DRD Declare reduction construct used for reduction item. 167 void emitAggregateInitialization(CodeGenFunction &CGF, unsigned N, 168 Address PrivateAddr, LValue SharedLVal, 169 const OMPDeclareReductionDecl *DRD); 170 171 public: 172 ReductionCodeGen(ArrayRef<const Expr *> Shareds, ArrayRef<const Expr *> Origs, 173 ArrayRef<const Expr *> Privates, 174 ArrayRef<const Expr *> ReductionOps); 175 /// Emits lvalue for the shared and original reduction item. 176 /// \param N Number of the reduction item. 177 void emitSharedOrigLValue(CodeGenFunction &CGF, unsigned N); 178 /// Emits the code for the variable-modified type, if required. 179 /// \param N Number of the reduction item. 180 void emitAggregateType(CodeGenFunction &CGF, unsigned N); 181 /// Emits the code for the variable-modified type, if required. 182 /// \param N Number of the reduction item. 183 /// \param Size Size of the type in chars. 184 void emitAggregateType(CodeGenFunction &CGF, unsigned N, llvm::Value *Size); 185 /// Performs initialization of the private copy for the reduction item. 186 /// \param N Number of the reduction item. 187 /// \param PrivateAddr Address of the corresponding private item. 188 /// \param DefaultInit Default initialization sequence that should be 189 /// performed if no reduction specific initialization is found. 190 /// \param SharedLVal Address of the original shared variable. 191 void 192 emitInitialization(CodeGenFunction &CGF, unsigned N, Address PrivateAddr, 193 LValue SharedLVal, 194 llvm::function_ref<bool(CodeGenFunction &)> DefaultInit); 195 /// Returns true if the private copy requires cleanups. 196 bool needCleanups(unsigned N); 197 /// Emits cleanup code for the reduction item. 198 /// \param N Number of the reduction item. 199 /// \param PrivateAddr Address of the corresponding private item. 200 void emitCleanups(CodeGenFunction &CGF, unsigned N, Address PrivateAddr); 201 /// Adjusts \p PrivatedAddr for using instead of the original variable 202 /// address in normal operations. 203 /// \param N Number of the reduction item. 204 /// \param PrivateAddr Address of the corresponding private item. 205 Address adjustPrivateAddress(CodeGenFunction &CGF, unsigned N, 206 Address PrivateAddr); 207 /// Returns LValue for the reduction item. 208 LValue getSharedLValue(unsigned N) const { return SharedAddresses[N].first; } 209 /// Returns LValue for the original reduction item. 210 LValue getOrigLValue(unsigned N) const { return OrigAddresses[N].first; } 211 /// Returns the size of the reduction item (in chars and total number of 212 /// elements in the item), or nullptr, if the size is a constant. 213 std::pair<llvm::Value *, llvm::Value *> getSizes(unsigned N) const { 214 return Sizes[N]; 215 } 216 /// Returns the base declaration of the reduction item. 217 const VarDecl *getBaseDecl(unsigned N) const { return BaseDecls[N]; } 218 /// Returns the base declaration of the reduction item. 219 const Expr *getRefExpr(unsigned N) const { return ClausesData[N].Ref; } 220 /// Returns true if the initialization of the reduction item uses initializer 221 /// from declare reduction construct. 222 bool usesReductionInitializer(unsigned N) const; 223 }; 224 225 class CGOpenMPRuntime { 226 public: 227 /// Allows to disable automatic handling of functions used in target regions 228 /// as those marked as `omp declare target`. 229 class DisableAutoDeclareTargetRAII { 230 CodeGenModule &CGM; 231 bool SavedShouldMarkAsGlobal; 232 233 public: 234 DisableAutoDeclareTargetRAII(CodeGenModule &CGM); 235 ~DisableAutoDeclareTargetRAII(); 236 }; 237 238 /// Manages list of nontemporal decls for the specified directive. 239 class NontemporalDeclsRAII { 240 CodeGenModule &CGM; 241 const bool NeedToPush; 242 243 public: 244 NontemporalDeclsRAII(CodeGenModule &CGM, const OMPLoopDirective &S); 245 ~NontemporalDeclsRAII(); 246 }; 247 248 /// Manages list of nontemporal decls for the specified directive. 249 class UntiedTaskLocalDeclsRAII { 250 CodeGenModule &CGM; 251 const bool NeedToPush; 252 253 public: 254 UntiedTaskLocalDeclsRAII( 255 CodeGenFunction &CGF, 256 const llvm::MapVector<CanonicalDeclPtr<const VarDecl>, 257 std::pair<Address, Address>> &LocalVars); 258 ~UntiedTaskLocalDeclsRAII(); 259 }; 260 261 /// Maps the expression for the lastprivate variable to the global copy used 262 /// to store new value because original variables are not mapped in inner 263 /// parallel regions. Only private copies are captured but we need also to 264 /// store private copy in shared address. 265 /// Also, stores the expression for the private loop counter and it 266 /// threaprivate name. 267 struct LastprivateConditionalData { 268 llvm::MapVector<CanonicalDeclPtr<const Decl>, SmallString<16>> 269 DeclToUniqueName; 270 LValue IVLVal; 271 llvm::Function *Fn = nullptr; 272 bool Disabled = false; 273 }; 274 /// Manages list of lastprivate conditional decls for the specified directive. 275 class LastprivateConditionalRAII { 276 enum class ActionToDo { 277 DoNotPush, 278 PushAsLastprivateConditional, 279 DisableLastprivateConditional, 280 }; 281 CodeGenModule &CGM; 282 ActionToDo Action = ActionToDo::DoNotPush; 283 284 /// Check and try to disable analysis of inner regions for changes in 285 /// lastprivate conditional. 286 void tryToDisableInnerAnalysis(const OMPExecutableDirective &S, 287 llvm::DenseSet<CanonicalDeclPtr<const Decl>> 288 &NeedToAddForLPCsAsDisabled) const; 289 290 LastprivateConditionalRAII(CodeGenFunction &CGF, 291 const OMPExecutableDirective &S); 292 293 public: 294 explicit LastprivateConditionalRAII(CodeGenFunction &CGF, 295 const OMPExecutableDirective &S, 296 LValue IVLVal); 297 static LastprivateConditionalRAII disable(CodeGenFunction &CGF, 298 const OMPExecutableDirective &S); 299 ~LastprivateConditionalRAII(); 300 }; 301 302 llvm::OpenMPIRBuilder &getOMPBuilder() { return OMPBuilder; } 303 304 protected: 305 CodeGenModule &CGM; 306 StringRef FirstSeparator, Separator; 307 308 /// An OpenMP-IR-Builder instance. 309 llvm::OpenMPIRBuilder OMPBuilder; 310 311 /// Constructor allowing to redefine the name separator for the variables. 312 explicit CGOpenMPRuntime(CodeGenModule &CGM, StringRef FirstSeparator, 313 StringRef Separator); 314 315 /// Creates offloading entry for the provided entry ID \a ID, 316 /// address \a Addr, size \a Size, and flags \a Flags. 317 virtual void createOffloadEntry(llvm::Constant *ID, llvm::Constant *Addr, 318 uint64_t Size, int32_t Flags, 319 llvm::GlobalValue::LinkageTypes Linkage); 320 321 /// Helper to emit outlined function for 'target' directive. 322 /// \param D Directive to emit. 323 /// \param ParentName Name of the function that encloses the target region. 324 /// \param OutlinedFn Outlined function value to be defined by this call. 325 /// \param OutlinedFnID Outlined function ID value to be defined by this call. 326 /// \param IsOffloadEntry True if the outlined function is an offload entry. 327 /// \param CodeGen Lambda codegen specific to an accelerator device. 328 /// An outlined function may not be an entry if, e.g. the if clause always 329 /// evaluates to false. 330 virtual void emitTargetOutlinedFunctionHelper(const OMPExecutableDirective &D, 331 StringRef ParentName, 332 llvm::Function *&OutlinedFn, 333 llvm::Constant *&OutlinedFnID, 334 bool IsOffloadEntry, 335 const RegionCodeGenTy &CodeGen); 336 337 /// Emits object of ident_t type with info for source location. 338 /// \param Flags Flags for OpenMP location. 339 /// 340 llvm::Value *emitUpdateLocation(CodeGenFunction &CGF, SourceLocation Loc, 341 unsigned Flags = 0); 342 343 /// Emit the number of teams for a target directive. Inspect the num_teams 344 /// clause associated with a teams construct combined or closely nested 345 /// with the target directive. 346 /// 347 /// Emit a team of size one for directives such as 'target parallel' that 348 /// have no associated teams construct. 349 /// 350 /// Otherwise, return nullptr. 351 const Expr *getNumTeamsExprForTargetDirective(CodeGenFunction &CGF, 352 const OMPExecutableDirective &D, 353 int32_t &DefaultVal); 354 llvm::Value *emitNumTeamsForTargetDirective(CodeGenFunction &CGF, 355 const OMPExecutableDirective &D); 356 /// Emit the number of threads for a target directive. Inspect the 357 /// thread_limit clause associated with a teams construct combined or closely 358 /// nested with the target directive. 359 /// 360 /// Emit the num_threads clause for directives such as 'target parallel' that 361 /// have no associated teams construct. 362 /// 363 /// Otherwise, return nullptr. 364 const Expr * 365 getNumThreadsExprForTargetDirective(CodeGenFunction &CGF, 366 const OMPExecutableDirective &D, 367 int32_t &DefaultVal); 368 llvm::Value * 369 emitNumThreadsForTargetDirective(CodeGenFunction &CGF, 370 const OMPExecutableDirective &D); 371 372 /// Returns pointer to ident_t type. 373 llvm::Type *getIdentTyPointerTy(); 374 375 /// Gets thread id value for the current thread. 376 /// 377 llvm::Value *getThreadID(CodeGenFunction &CGF, SourceLocation Loc); 378 379 /// Get the function name of an outlined region. 380 // The name can be customized depending on the target. 381 // 382 virtual StringRef getOutlinedHelperName() const { return ".omp_outlined."; } 383 384 /// Emits \p Callee function call with arguments \p Args with location \p Loc. 385 void emitCall(CodeGenFunction &CGF, SourceLocation Loc, 386 llvm::FunctionCallee Callee, 387 ArrayRef<llvm::Value *> Args = llvm::None) const; 388 389 /// Emits address of the word in a memory where current thread id is 390 /// stored. 391 virtual Address emitThreadIDAddress(CodeGenFunction &CGF, SourceLocation Loc); 392 393 void setLocThreadIdInsertPt(CodeGenFunction &CGF, 394 bool AtCurrentPoint = false); 395 void clearLocThreadIdInsertPt(CodeGenFunction &CGF); 396 397 /// Check if the default location must be constant. 398 /// Default is false to support OMPT/OMPD. 399 virtual bool isDefaultLocationConstant() const { return false; } 400 401 /// Returns additional flags that can be stored in reserved_2 field of the 402 /// default location. 403 virtual unsigned getDefaultLocationReserved2Flags() const { return 0; } 404 405 /// Returns default flags for the barriers depending on the directive, for 406 /// which this barier is going to be emitted. 407 static unsigned getDefaultFlagsForBarriers(OpenMPDirectiveKind Kind); 408 409 /// Get the LLVM type for the critical name. 410 llvm::ArrayType *getKmpCriticalNameTy() const {return KmpCriticalNameTy;} 411 412 /// Returns corresponding lock object for the specified critical region 413 /// name. If the lock object does not exist it is created, otherwise the 414 /// reference to the existing copy is returned. 415 /// \param CriticalName Name of the critical region. 416 /// 417 llvm::Value *getCriticalRegionLock(StringRef CriticalName); 418 419 private: 420 421 /// Map for SourceLocation and OpenMP runtime library debug locations. 422 typedef llvm::DenseMap<SourceLocation, llvm::Value *> OpenMPDebugLocMapTy; 423 OpenMPDebugLocMapTy OpenMPDebugLocMap; 424 /// The type for a microtask which gets passed to __kmpc_fork_call(). 425 /// Original representation is: 426 /// typedef void (kmpc_micro)(kmp_int32 global_tid, kmp_int32 bound_tid,...); 427 llvm::FunctionType *Kmpc_MicroTy = nullptr; 428 /// Stores debug location and ThreadID for the function. 429 struct DebugLocThreadIdTy { 430 llvm::Value *DebugLoc; 431 llvm::Value *ThreadID; 432 /// Insert point for the service instructions. 433 llvm::AssertingVH<llvm::Instruction> ServiceInsertPt = nullptr; 434 }; 435 /// Map of local debug location, ThreadId and functions. 436 typedef llvm::DenseMap<llvm::Function *, DebugLocThreadIdTy> 437 OpenMPLocThreadIDMapTy; 438 OpenMPLocThreadIDMapTy OpenMPLocThreadIDMap; 439 /// Map of UDRs and corresponding combiner/initializer. 440 typedef llvm::DenseMap<const OMPDeclareReductionDecl *, 441 std::pair<llvm::Function *, llvm::Function *>> 442 UDRMapTy; 443 UDRMapTy UDRMap; 444 /// Map of functions and locally defined UDRs. 445 typedef llvm::DenseMap<llvm::Function *, 446 SmallVector<const OMPDeclareReductionDecl *, 4>> 447 FunctionUDRMapTy; 448 FunctionUDRMapTy FunctionUDRMap; 449 /// Map from the user-defined mapper declaration to its corresponding 450 /// functions. 451 llvm::DenseMap<const OMPDeclareMapperDecl *, llvm::Function *> UDMMap; 452 /// Map of functions and their local user-defined mappers. 453 using FunctionUDMMapTy = 454 llvm::DenseMap<llvm::Function *, 455 SmallVector<const OMPDeclareMapperDecl *, 4>>; 456 FunctionUDMMapTy FunctionUDMMap; 457 /// Maps local variables marked as lastprivate conditional to their internal 458 /// types. 459 llvm::DenseMap<llvm::Function *, 460 llvm::DenseMap<CanonicalDeclPtr<const Decl>, 461 std::tuple<QualType, const FieldDecl *, 462 const FieldDecl *, LValue>>> 463 LastprivateConditionalToTypes; 464 /// Maps function to the position of the untied task locals stack. 465 llvm::DenseMap<llvm::Function *, unsigned> FunctionToUntiedTaskStackMap; 466 /// Type kmp_critical_name, originally defined as typedef kmp_int32 467 /// kmp_critical_name[8]; 468 llvm::ArrayType *KmpCriticalNameTy; 469 /// An ordered map of auto-generated variables to their unique names. 470 /// It stores variables with the following names: 1) ".gomp_critical_user_" + 471 /// <critical_section_name> + ".var" for "omp critical" directives; 2) 472 /// <mangled_name_for_global_var> + ".cache." for cache for threadprivate 473 /// variables. 474 llvm::StringMap<llvm::AssertingVH<llvm::Constant>, llvm::BumpPtrAllocator> 475 InternalVars; 476 /// Type typedef kmp_int32 (* kmp_routine_entry_t)(kmp_int32, void *); 477 llvm::Type *KmpRoutineEntryPtrTy = nullptr; 478 QualType KmpRoutineEntryPtrQTy; 479 /// Type typedef struct kmp_task { 480 /// void * shareds; /**< pointer to block of pointers to 481 /// shared vars */ 482 /// kmp_routine_entry_t routine; /**< pointer to routine to call for 483 /// executing task */ 484 /// kmp_int32 part_id; /**< part id for the task */ 485 /// kmp_routine_entry_t destructors; /* pointer to function to invoke 486 /// deconstructors of firstprivate C++ objects */ 487 /// } kmp_task_t; 488 QualType KmpTaskTQTy; 489 /// Saved kmp_task_t for task directive. 490 QualType SavedKmpTaskTQTy; 491 /// Saved kmp_task_t for taskloop-based directive. 492 QualType SavedKmpTaskloopTQTy; 493 /// Type typedef struct kmp_depend_info { 494 /// kmp_intptr_t base_addr; 495 /// size_t len; 496 /// struct { 497 /// bool in:1; 498 /// bool out:1; 499 /// } flags; 500 /// } kmp_depend_info_t; 501 QualType KmpDependInfoTy; 502 /// Type typedef struct kmp_task_affinity_info { 503 /// kmp_intptr_t base_addr; 504 /// size_t len; 505 /// struct { 506 /// bool flag1 : 1; 507 /// bool flag2 : 1; 508 /// kmp_int32 reserved : 30; 509 /// } flags; 510 /// } kmp_task_affinity_info_t; 511 QualType KmpTaskAffinityInfoTy; 512 /// struct kmp_dim { // loop bounds info casted to kmp_int64 513 /// kmp_int64 lo; // lower 514 /// kmp_int64 up; // upper 515 /// kmp_int64 st; // stride 516 /// }; 517 QualType KmpDimTy; 518 /// Type struct __tgt_offload_entry{ 519 /// void *addr; // Pointer to the offload entry info. 520 /// // (function or global) 521 /// char *name; // Name of the function or global. 522 /// size_t size; // Size of the entry info (0 if it a function). 523 /// int32_t flags; 524 /// int32_t reserved; 525 /// }; 526 QualType TgtOffloadEntryQTy; 527 /// Entity that registers the offloading constants that were emitted so 528 /// far. 529 class OffloadEntriesInfoManagerTy { 530 CodeGenModule &CGM; 531 532 /// Number of entries registered so far. 533 unsigned OffloadingEntriesNum = 0; 534 535 public: 536 /// Base class of the entries info. 537 class OffloadEntryInfo { 538 public: 539 /// Kind of a given entry. 540 enum OffloadingEntryInfoKinds : unsigned { 541 /// Entry is a target region. 542 OffloadingEntryInfoTargetRegion = 0, 543 /// Entry is a declare target variable. 544 OffloadingEntryInfoDeviceGlobalVar = 1, 545 /// Invalid entry info. 546 OffloadingEntryInfoInvalid = ~0u 547 }; 548 549 protected: 550 OffloadEntryInfo() = delete; 551 explicit OffloadEntryInfo(OffloadingEntryInfoKinds Kind) : Kind(Kind) {} 552 explicit OffloadEntryInfo(OffloadingEntryInfoKinds Kind, unsigned Order, 553 uint32_t Flags) 554 : Flags(Flags), Order(Order), Kind(Kind) {} 555 ~OffloadEntryInfo() = default; 556 557 public: 558 bool isValid() const { return Order != ~0u; } 559 unsigned getOrder() const { return Order; } 560 OffloadingEntryInfoKinds getKind() const { return Kind; } 561 uint32_t getFlags() const { return Flags; } 562 void setFlags(uint32_t NewFlags) { Flags = NewFlags; } 563 llvm::Constant *getAddress() const { 564 return cast_or_null<llvm::Constant>(Addr); 565 } 566 void setAddress(llvm::Constant *V) { 567 assert(!Addr.pointsToAliveValue() && "Address has been set before!"); 568 Addr = V; 569 } 570 static bool classof(const OffloadEntryInfo *Info) { return true; } 571 572 private: 573 /// Address of the entity that has to be mapped for offloading. 574 llvm::WeakTrackingVH Addr; 575 576 /// Flags associated with the device global. 577 uint32_t Flags = 0u; 578 579 /// Order this entry was emitted. 580 unsigned Order = ~0u; 581 582 OffloadingEntryInfoKinds Kind = OffloadingEntryInfoInvalid; 583 }; 584 585 /// Return true if a there are no entries defined. 586 bool empty() const; 587 /// Return number of entries defined so far. 588 unsigned size() const { return OffloadingEntriesNum; } 589 OffloadEntriesInfoManagerTy(CodeGenModule &CGM) : CGM(CGM) {} 590 591 // 592 // Target region entries related. 593 // 594 595 /// Kind of the target registry entry. 596 enum OMPTargetRegionEntryKind : uint32_t { 597 /// Mark the entry as target region. 598 OMPTargetRegionEntryTargetRegion = 0x0, 599 /// Mark the entry as a global constructor. 600 OMPTargetRegionEntryCtor = 0x02, 601 /// Mark the entry as a global destructor. 602 OMPTargetRegionEntryDtor = 0x04, 603 }; 604 605 /// Target region entries info. 606 class OffloadEntryInfoTargetRegion final : public OffloadEntryInfo { 607 /// Address that can be used as the ID of the entry. 608 llvm::Constant *ID = nullptr; 609 610 public: 611 OffloadEntryInfoTargetRegion() 612 : OffloadEntryInfo(OffloadingEntryInfoTargetRegion) {} 613 explicit OffloadEntryInfoTargetRegion(unsigned Order, 614 llvm::Constant *Addr, 615 llvm::Constant *ID, 616 OMPTargetRegionEntryKind Flags) 617 : OffloadEntryInfo(OffloadingEntryInfoTargetRegion, Order, Flags), 618 ID(ID) { 619 setAddress(Addr); 620 } 621 622 llvm::Constant *getID() const { return ID; } 623 void setID(llvm::Constant *V) { 624 assert(!ID && "ID has been set before!"); 625 ID = V; 626 } 627 static bool classof(const OffloadEntryInfo *Info) { 628 return Info->getKind() == OffloadingEntryInfoTargetRegion; 629 } 630 }; 631 632 /// Initialize target region entry. 633 void initializeTargetRegionEntryInfo(unsigned DeviceID, unsigned FileID, 634 StringRef ParentName, unsigned LineNum, 635 unsigned Order); 636 /// Register target region entry. 637 void registerTargetRegionEntryInfo(unsigned DeviceID, unsigned FileID, 638 StringRef ParentName, unsigned LineNum, 639 llvm::Constant *Addr, llvm::Constant *ID, 640 OMPTargetRegionEntryKind Flags); 641 /// Return true if a target region entry with the provided information 642 /// exists. 643 bool hasTargetRegionEntryInfo(unsigned DeviceID, unsigned FileID, 644 StringRef ParentName, unsigned LineNum, 645 bool IgnoreAddressId = false) const; 646 /// brief Applies action \a Action on all registered entries. 647 typedef llvm::function_ref<void(unsigned, unsigned, StringRef, unsigned, 648 const OffloadEntryInfoTargetRegion &)> 649 OffloadTargetRegionEntryInfoActTy; 650 void actOnTargetRegionEntriesInfo( 651 const OffloadTargetRegionEntryInfoActTy &Action); 652 653 // 654 // Device global variable entries related. 655 // 656 657 /// Kind of the global variable entry.. 658 enum OMPTargetGlobalVarEntryKind : uint32_t { 659 /// Mark the entry as a to declare target. 660 OMPTargetGlobalVarEntryTo = 0x0, 661 /// Mark the entry as a to declare target link. 662 OMPTargetGlobalVarEntryLink = 0x1, 663 }; 664 665 /// Device global variable entries info. 666 class OffloadEntryInfoDeviceGlobalVar final : public OffloadEntryInfo { 667 /// Type of the global variable. 668 CharUnits VarSize; 669 llvm::GlobalValue::LinkageTypes Linkage; 670 671 public: 672 OffloadEntryInfoDeviceGlobalVar() 673 : OffloadEntryInfo(OffloadingEntryInfoDeviceGlobalVar) {} 674 explicit OffloadEntryInfoDeviceGlobalVar(unsigned Order, 675 OMPTargetGlobalVarEntryKind Flags) 676 : OffloadEntryInfo(OffloadingEntryInfoDeviceGlobalVar, Order, Flags) {} 677 explicit OffloadEntryInfoDeviceGlobalVar( 678 unsigned Order, llvm::Constant *Addr, CharUnits VarSize, 679 OMPTargetGlobalVarEntryKind Flags, 680 llvm::GlobalValue::LinkageTypes Linkage) 681 : OffloadEntryInfo(OffloadingEntryInfoDeviceGlobalVar, Order, Flags), 682 VarSize(VarSize), Linkage(Linkage) { 683 setAddress(Addr); 684 } 685 686 CharUnits getVarSize() const { return VarSize; } 687 void setVarSize(CharUnits Size) { VarSize = Size; } 688 llvm::GlobalValue::LinkageTypes getLinkage() const { return Linkage; } 689 void setLinkage(llvm::GlobalValue::LinkageTypes LT) { Linkage = LT; } 690 static bool classof(const OffloadEntryInfo *Info) { 691 return Info->getKind() == OffloadingEntryInfoDeviceGlobalVar; 692 } 693 }; 694 695 /// Initialize device global variable entry. 696 void initializeDeviceGlobalVarEntryInfo(StringRef Name, 697 OMPTargetGlobalVarEntryKind Flags, 698 unsigned Order); 699 700 /// Register device global variable entry. 701 void 702 registerDeviceGlobalVarEntryInfo(StringRef VarName, llvm::Constant *Addr, 703 CharUnits VarSize, 704 OMPTargetGlobalVarEntryKind Flags, 705 llvm::GlobalValue::LinkageTypes Linkage); 706 /// Checks if the variable with the given name has been registered already. 707 bool hasDeviceGlobalVarEntryInfo(StringRef VarName) const { 708 return OffloadEntriesDeviceGlobalVar.count(VarName) > 0; 709 } 710 /// Applies action \a Action on all registered entries. 711 typedef llvm::function_ref<void(StringRef, 712 const OffloadEntryInfoDeviceGlobalVar &)> 713 OffloadDeviceGlobalVarEntryInfoActTy; 714 void actOnDeviceGlobalVarEntriesInfo( 715 const OffloadDeviceGlobalVarEntryInfoActTy &Action); 716 717 private: 718 // Storage for target region entries kind. The storage is to be indexed by 719 // file ID, device ID, parent function name and line number. 720 typedef llvm::DenseMap<unsigned, OffloadEntryInfoTargetRegion> 721 OffloadEntriesTargetRegionPerLine; 722 typedef llvm::StringMap<OffloadEntriesTargetRegionPerLine> 723 OffloadEntriesTargetRegionPerParentName; 724 typedef llvm::DenseMap<unsigned, OffloadEntriesTargetRegionPerParentName> 725 OffloadEntriesTargetRegionPerFile; 726 typedef llvm::DenseMap<unsigned, OffloadEntriesTargetRegionPerFile> 727 OffloadEntriesTargetRegionPerDevice; 728 typedef OffloadEntriesTargetRegionPerDevice OffloadEntriesTargetRegionTy; 729 OffloadEntriesTargetRegionTy OffloadEntriesTargetRegion; 730 /// Storage for device global variable entries kind. The storage is to be 731 /// indexed by mangled name. 732 typedef llvm::StringMap<OffloadEntryInfoDeviceGlobalVar> 733 OffloadEntriesDeviceGlobalVarTy; 734 OffloadEntriesDeviceGlobalVarTy OffloadEntriesDeviceGlobalVar; 735 }; 736 OffloadEntriesInfoManagerTy OffloadEntriesInfoManager; 737 738 bool ShouldMarkAsGlobal = true; 739 /// List of the emitted declarations. 740 llvm::DenseSet<CanonicalDeclPtr<const Decl>> AlreadyEmittedTargetDecls; 741 /// List of the global variables with their addresses that should not be 742 /// emitted for the target. 743 llvm::StringMap<llvm::WeakTrackingVH> EmittedNonTargetVariables; 744 745 /// List of variables that can become declare target implicitly and, thus, 746 /// must be emitted. 747 llvm::SmallDenseSet<const VarDecl *> DeferredGlobalVariables; 748 749 using NontemporalDeclsSet = llvm::SmallDenseSet<CanonicalDeclPtr<const Decl>>; 750 /// Stack for list of declarations in current context marked as nontemporal. 751 /// The set is the union of all current stack elements. 752 llvm::SmallVector<NontemporalDeclsSet, 4> NontemporalDeclsStack; 753 754 using UntiedLocalVarsAddressesMap = 755 llvm::MapVector<CanonicalDeclPtr<const VarDecl>, 756 std::pair<Address, Address>>; 757 llvm::SmallVector<UntiedLocalVarsAddressesMap, 4> UntiedLocalVarsStack; 758 759 /// Stack for list of addresses of declarations in current context marked as 760 /// lastprivate conditional. The set is the union of all current stack 761 /// elements. 762 llvm::SmallVector<LastprivateConditionalData, 4> LastprivateConditionalStack; 763 764 /// Flag for keeping track of weather a requires unified_shared_memory 765 /// directive is present. 766 bool HasRequiresUnifiedSharedMemory = false; 767 768 /// Atomic ordering from the omp requires directive. 769 llvm::AtomicOrdering RequiresAtomicOrdering = llvm::AtomicOrdering::Monotonic; 770 771 /// Flag for keeping track of weather a target region has been emitted. 772 bool HasEmittedTargetRegion = false; 773 774 /// Flag for keeping track of weather a device routine has been emitted. 775 /// Device routines are specific to the 776 bool HasEmittedDeclareTargetRegion = false; 777 778 /// Loads all the offload entries information from the host IR 779 /// metadata. 780 void loadOffloadInfoMetadata(); 781 782 /// Returns __tgt_offload_entry type. 783 QualType getTgtOffloadEntryQTy(); 784 785 /// Start scanning from statement \a S and and emit all target regions 786 /// found along the way. 787 /// \param S Starting statement. 788 /// \param ParentName Name of the function declaration that is being scanned. 789 void scanForTargetRegionsFunctions(const Stmt *S, StringRef ParentName); 790 791 /// Build type kmp_routine_entry_t (if not built yet). 792 void emitKmpRoutineEntryT(QualType KmpInt32Ty); 793 794 /// Returns pointer to kmpc_micro type. 795 llvm::Type *getKmpc_MicroPointerTy(); 796 797 /// Returns __kmpc_for_static_init_* runtime function for the specified 798 /// size \a IVSize and sign \a IVSigned. 799 llvm::FunctionCallee createForStaticInitFunction(unsigned IVSize, 800 bool IVSigned); 801 802 /// Returns __kmpc_dispatch_init_* runtime function for the specified 803 /// size \a IVSize and sign \a IVSigned. 804 llvm::FunctionCallee createDispatchInitFunction(unsigned IVSize, 805 bool IVSigned); 806 807 /// Returns __kmpc_dispatch_next_* runtime function for the specified 808 /// size \a IVSize and sign \a IVSigned. 809 llvm::FunctionCallee createDispatchNextFunction(unsigned IVSize, 810 bool IVSigned); 811 812 /// Returns __kmpc_dispatch_fini_* runtime function for the specified 813 /// size \a IVSize and sign \a IVSigned. 814 llvm::FunctionCallee createDispatchFiniFunction(unsigned IVSize, 815 bool IVSigned); 816 817 /// If the specified mangled name is not in the module, create and 818 /// return threadprivate cache object. This object is a pointer's worth of 819 /// storage that's reserved for use by the OpenMP runtime. 820 /// \param VD Threadprivate variable. 821 /// \return Cache variable for the specified threadprivate. 822 llvm::Constant *getOrCreateThreadPrivateCache(const VarDecl *VD); 823 824 /// Gets (if variable with the given name already exist) or creates 825 /// internal global variable with the specified Name. The created variable has 826 /// linkage CommonLinkage by default and is initialized by null value. 827 /// \param Ty Type of the global variable. If it is exist already the type 828 /// must be the same. 829 /// \param Name Name of the variable. 830 llvm::Constant *getOrCreateInternalVariable(llvm::Type *Ty, 831 const llvm::Twine &Name, 832 unsigned AddressSpace = 0); 833 834 /// Set of threadprivate variables with the generated initializer. 835 llvm::StringSet<> ThreadPrivateWithDefinition; 836 837 /// Set of declare target variables with the generated initializer. 838 llvm::StringSet<> DeclareTargetWithDefinition; 839 840 /// Emits initialization code for the threadprivate variables. 841 /// \param VDAddr Address of the global variable \a VD. 842 /// \param Ctor Pointer to a global init function for \a VD. 843 /// \param CopyCtor Pointer to a global copy function for \a VD. 844 /// \param Dtor Pointer to a global destructor function for \a VD. 845 /// \param Loc Location of threadprivate declaration. 846 void emitThreadPrivateVarInit(CodeGenFunction &CGF, Address VDAddr, 847 llvm::Value *Ctor, llvm::Value *CopyCtor, 848 llvm::Value *Dtor, SourceLocation Loc); 849 850 /// Emit the array initialization or deletion portion for user-defined mapper 851 /// code generation. 852 void emitUDMapperArrayInitOrDel(CodeGenFunction &MapperCGF, 853 llvm::Value *Handle, llvm::Value *BasePtr, 854 llvm::Value *Ptr, llvm::Value *Size, 855 llvm::Value *MapType, llvm::Value *MapName, 856 CharUnits ElementSize, 857 llvm::BasicBlock *ExitBB, bool IsInit); 858 859 struct TaskResultTy { 860 llvm::Value *NewTask = nullptr; 861 llvm::Function *TaskEntry = nullptr; 862 llvm::Value *NewTaskNewTaskTTy = nullptr; 863 LValue TDBase; 864 const RecordDecl *KmpTaskTQTyRD = nullptr; 865 llvm::Value *TaskDupFn = nullptr; 866 }; 867 /// Emit task region for the task directive. The task region is emitted in 868 /// several steps: 869 /// 1. Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32 870 /// gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds, 871 /// kmp_routine_entry_t *task_entry). Here task_entry is a pointer to the 872 /// function: 873 /// kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) { 874 /// TaskFunction(gtid, tt->part_id, tt->shareds); 875 /// return 0; 876 /// } 877 /// 2. Copy a list of shared variables to field shareds of the resulting 878 /// structure kmp_task_t returned by the previous call (if any). 879 /// 3. Copy a pointer to destructions function to field destructions of the 880 /// resulting structure kmp_task_t. 881 /// \param D Current task directive. 882 /// \param TaskFunction An LLVM function with type void (*)(i32 /*gtid*/, i32 883 /// /*part_id*/, captured_struct */*__context*/); 884 /// \param SharedsTy A type which contains references the shared variables. 885 /// \param Shareds Context with the list of shared variables from the \p 886 /// TaskFunction. 887 /// \param Data Additional data for task generation like tiednsee, final 888 /// state, list of privates etc. 889 TaskResultTy emitTaskInit(CodeGenFunction &CGF, SourceLocation Loc, 890 const OMPExecutableDirective &D, 891 llvm::Function *TaskFunction, QualType SharedsTy, 892 Address Shareds, const OMPTaskDataTy &Data); 893 894 /// Emit code that pushes the trip count of loops associated with constructs 895 /// 'target teams distribute' and 'teams distribute parallel for'. 896 /// \param SizeEmitter Emits the int64 value for the number of iterations of 897 /// the associated loop. 898 void emitTargetNumIterationsCall( 899 CodeGenFunction &CGF, const OMPExecutableDirective &D, 900 llvm::Value *DeviceID, 901 llvm::function_ref<llvm::Value *(CodeGenFunction &CGF, 902 const OMPLoopDirective &D)> 903 SizeEmitter); 904 905 /// Emit update for lastprivate conditional data. 906 void emitLastprivateConditionalUpdate(CodeGenFunction &CGF, LValue IVLVal, 907 StringRef UniqueDeclName, LValue LVal, 908 SourceLocation Loc); 909 910 /// Returns the number of the elements and the address of the depobj 911 /// dependency array. 912 /// \return Number of elements in depobj array and the pointer to the array of 913 /// dependencies. 914 std::pair<llvm::Value *, LValue> getDepobjElements(CodeGenFunction &CGF, 915 LValue DepobjLVal, 916 SourceLocation Loc); 917 918 public: 919 explicit CGOpenMPRuntime(CodeGenModule &CGM) 920 : CGOpenMPRuntime(CGM, ".", ".") {} 921 virtual ~CGOpenMPRuntime() {} 922 virtual void clear(); 923 924 /// Emits code for OpenMP 'if' clause using specified \a CodeGen 925 /// function. Here is the logic: 926 /// if (Cond) { 927 /// ThenGen(); 928 /// } else { 929 /// ElseGen(); 930 /// } 931 void emitIfClause(CodeGenFunction &CGF, const Expr *Cond, 932 const RegionCodeGenTy &ThenGen, 933 const RegionCodeGenTy &ElseGen); 934 935 /// Checks if the \p Body is the \a CompoundStmt and returns its child 936 /// statement iff there is only one that is not evaluatable at the compile 937 /// time. 938 static const Stmt *getSingleCompoundChild(ASTContext &Ctx, const Stmt *Body); 939 940 /// Get the platform-specific name separator. 941 std::string getName(ArrayRef<StringRef> Parts) const; 942 943 /// Emit code for the specified user defined reduction construct. 944 virtual void emitUserDefinedReduction(CodeGenFunction *CGF, 945 const OMPDeclareReductionDecl *D); 946 /// Get combiner/initializer for the specified user-defined reduction, if any. 947 virtual std::pair<llvm::Function *, llvm::Function *> 948 getUserDefinedReduction(const OMPDeclareReductionDecl *D); 949 950 /// Emit the function for the user defined mapper construct. 951 void emitUserDefinedMapper(const OMPDeclareMapperDecl *D, 952 CodeGenFunction *CGF = nullptr); 953 /// Get the function for the specified user-defined mapper. If it does not 954 /// exist, create one. 955 llvm::Function * 956 getOrCreateUserDefinedMapperFunc(const OMPDeclareMapperDecl *D); 957 958 /// Emits outlined function for the specified OpenMP parallel directive 959 /// \a D. This outlined function has type void(*)(kmp_int32 *ThreadID, 960 /// kmp_int32 BoundID, struct context_vars*). 961 /// \param D OpenMP directive. 962 /// \param ThreadIDVar Variable for thread id in the current OpenMP region. 963 /// \param InnermostKind Kind of innermost directive (for simple directives it 964 /// is a directive itself, for combined - its innermost directive). 965 /// \param CodeGen Code generation sequence for the \a D directive. 966 virtual llvm::Function *emitParallelOutlinedFunction( 967 const OMPExecutableDirective &D, const VarDecl *ThreadIDVar, 968 OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen); 969 970 /// Emits outlined function for the specified OpenMP teams directive 971 /// \a D. This outlined function has type void(*)(kmp_int32 *ThreadID, 972 /// kmp_int32 BoundID, struct context_vars*). 973 /// \param D OpenMP directive. 974 /// \param ThreadIDVar Variable for thread id in the current OpenMP region. 975 /// \param InnermostKind Kind of innermost directive (for simple directives it 976 /// is a directive itself, for combined - its innermost directive). 977 /// \param CodeGen Code generation sequence for the \a D directive. 978 virtual llvm::Function *emitTeamsOutlinedFunction( 979 const OMPExecutableDirective &D, const VarDecl *ThreadIDVar, 980 OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen); 981 982 /// Emits outlined function for the OpenMP task directive \a D. This 983 /// outlined function has type void(*)(kmp_int32 ThreadID, struct task_t* 984 /// TaskT). 985 /// \param D OpenMP directive. 986 /// \param ThreadIDVar Variable for thread id in the current OpenMP region. 987 /// \param PartIDVar Variable for partition id in the current OpenMP untied 988 /// task region. 989 /// \param TaskTVar Variable for task_t argument. 990 /// \param InnermostKind Kind of innermost directive (for simple directives it 991 /// is a directive itself, for combined - its innermost directive). 992 /// \param CodeGen Code generation sequence for the \a D directive. 993 /// \param Tied true if task is generated for tied task, false otherwise. 994 /// \param NumberOfParts Number of parts in untied task. Ignored for tied 995 /// tasks. 996 /// 997 virtual llvm::Function *emitTaskOutlinedFunction( 998 const OMPExecutableDirective &D, const VarDecl *ThreadIDVar, 999 const VarDecl *PartIDVar, const VarDecl *TaskTVar, 1000 OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen, 1001 bool Tied, unsigned &NumberOfParts); 1002 1003 /// Cleans up references to the objects in finished function. 1004 /// 1005 virtual void functionFinished(CodeGenFunction &CGF); 1006 1007 /// Emits code for parallel or serial call of the \a OutlinedFn with 1008 /// variables captured in a record which address is stored in \a 1009 /// CapturedStruct. 1010 /// \param OutlinedFn Outlined function to be run in parallel threads. Type of 1011 /// this function is void(*)(kmp_int32 *, kmp_int32, struct context_vars*). 1012 /// \param CapturedVars A pointer to the record with the references to 1013 /// variables used in \a OutlinedFn function. 1014 /// \param IfCond Condition in the associated 'if' clause, if it was 1015 /// specified, nullptr otherwise. 1016 /// 1017 virtual void emitParallelCall(CodeGenFunction &CGF, SourceLocation Loc, 1018 llvm::Function *OutlinedFn, 1019 ArrayRef<llvm::Value *> CapturedVars, 1020 const Expr *IfCond); 1021 1022 /// Emits a critical region. 1023 /// \param CriticalName Name of the critical region. 1024 /// \param CriticalOpGen Generator for the statement associated with the given 1025 /// critical region. 1026 /// \param Hint Value of the 'hint' clause (optional). 1027 virtual void emitCriticalRegion(CodeGenFunction &CGF, StringRef CriticalName, 1028 const RegionCodeGenTy &CriticalOpGen, 1029 SourceLocation Loc, 1030 const Expr *Hint = nullptr); 1031 1032 /// Emits a master region. 1033 /// \param MasterOpGen Generator for the statement associated with the given 1034 /// master region. 1035 virtual void emitMasterRegion(CodeGenFunction &CGF, 1036 const RegionCodeGenTy &MasterOpGen, 1037 SourceLocation Loc); 1038 1039 /// Emits a masked region. 1040 /// \param MaskedOpGen Generator for the statement associated with the given 1041 /// masked region. 1042 virtual void emitMaskedRegion(CodeGenFunction &CGF, 1043 const RegionCodeGenTy &MaskedOpGen, 1044 SourceLocation Loc, 1045 const Expr *Filter = nullptr); 1046 1047 /// Emits code for a taskyield directive. 1048 virtual void emitTaskyieldCall(CodeGenFunction &CGF, SourceLocation Loc); 1049 1050 /// Emit a taskgroup region. 1051 /// \param TaskgroupOpGen Generator for the statement associated with the 1052 /// given taskgroup region. 1053 virtual void emitTaskgroupRegion(CodeGenFunction &CGF, 1054 const RegionCodeGenTy &TaskgroupOpGen, 1055 SourceLocation Loc); 1056 1057 /// Emits a single region. 1058 /// \param SingleOpGen Generator for the statement associated with the given 1059 /// single region. 1060 virtual void emitSingleRegion(CodeGenFunction &CGF, 1061 const RegionCodeGenTy &SingleOpGen, 1062 SourceLocation Loc, 1063 ArrayRef<const Expr *> CopyprivateVars, 1064 ArrayRef<const Expr *> DestExprs, 1065 ArrayRef<const Expr *> SrcExprs, 1066 ArrayRef<const Expr *> AssignmentOps); 1067 1068 /// Emit an ordered region. 1069 /// \param OrderedOpGen Generator for the statement associated with the given 1070 /// ordered region. 1071 virtual void emitOrderedRegion(CodeGenFunction &CGF, 1072 const RegionCodeGenTy &OrderedOpGen, 1073 SourceLocation Loc, bool IsThreads); 1074 1075 /// Emit an implicit/explicit barrier for OpenMP threads. 1076 /// \param Kind Directive for which this implicit barrier call must be 1077 /// generated. Must be OMPD_barrier for explicit barrier generation. 1078 /// \param EmitChecks true if need to emit checks for cancellation barriers. 1079 /// \param ForceSimpleCall true simple barrier call must be emitted, false if 1080 /// runtime class decides which one to emit (simple or with cancellation 1081 /// checks). 1082 /// 1083 virtual void emitBarrierCall(CodeGenFunction &CGF, SourceLocation Loc, 1084 OpenMPDirectiveKind Kind, 1085 bool EmitChecks = true, 1086 bool ForceSimpleCall = false); 1087 1088 /// Check if the specified \a ScheduleKind is static non-chunked. 1089 /// This kind of worksharing directive is emitted without outer loop. 1090 /// \param ScheduleKind Schedule kind specified in the 'schedule' clause. 1091 /// \param Chunked True if chunk is specified in the clause. 1092 /// 1093 virtual bool isStaticNonchunked(OpenMPScheduleClauseKind ScheduleKind, 1094 bool Chunked) const; 1095 1096 /// Check if the specified \a ScheduleKind is static non-chunked. 1097 /// This kind of distribute directive is emitted without outer loop. 1098 /// \param ScheduleKind Schedule kind specified in the 'dist_schedule' clause. 1099 /// \param Chunked True if chunk is specified in the clause. 1100 /// 1101 virtual bool isStaticNonchunked(OpenMPDistScheduleClauseKind ScheduleKind, 1102 bool Chunked) const; 1103 1104 /// Check if the specified \a ScheduleKind is static chunked. 1105 /// \param ScheduleKind Schedule kind specified in the 'schedule' clause. 1106 /// \param Chunked True if chunk is specified in the clause. 1107 /// 1108 virtual bool isStaticChunked(OpenMPScheduleClauseKind ScheduleKind, 1109 bool Chunked) const; 1110 1111 /// Check if the specified \a ScheduleKind is static non-chunked. 1112 /// \param ScheduleKind Schedule kind specified in the 'dist_schedule' clause. 1113 /// \param Chunked True if chunk is specified in the clause. 1114 /// 1115 virtual bool isStaticChunked(OpenMPDistScheduleClauseKind ScheduleKind, 1116 bool Chunked) const; 1117 1118 /// Check if the specified \a ScheduleKind is dynamic. 1119 /// This kind of worksharing directive is emitted without outer loop. 1120 /// \param ScheduleKind Schedule Kind specified in the 'schedule' clause. 1121 /// 1122 virtual bool isDynamic(OpenMPScheduleClauseKind ScheduleKind) const; 1123 1124 /// struct with the values to be passed to the dispatch runtime function 1125 struct DispatchRTInput { 1126 /// Loop lower bound 1127 llvm::Value *LB = nullptr; 1128 /// Loop upper bound 1129 llvm::Value *UB = nullptr; 1130 /// Chunk size specified using 'schedule' clause (nullptr if chunk 1131 /// was not specified) 1132 llvm::Value *Chunk = nullptr; 1133 DispatchRTInput() = default; 1134 DispatchRTInput(llvm::Value *LB, llvm::Value *UB, llvm::Value *Chunk) 1135 : LB(LB), UB(UB), Chunk(Chunk) {} 1136 }; 1137 1138 /// Call the appropriate runtime routine to initialize it before start 1139 /// of loop. 1140 1141 /// This is used for non static scheduled types and when the ordered 1142 /// clause is present on the loop construct. 1143 /// Depending on the loop schedule, it is necessary to call some runtime 1144 /// routine before start of the OpenMP loop to get the loop upper / lower 1145 /// bounds \a LB and \a UB and stride \a ST. 1146 /// 1147 /// \param CGF Reference to current CodeGenFunction. 1148 /// \param Loc Clang source location. 1149 /// \param ScheduleKind Schedule kind, specified by the 'schedule' clause. 1150 /// \param IVSize Size of the iteration variable in bits. 1151 /// \param IVSigned Sign of the iteration variable. 1152 /// \param Ordered true if loop is ordered, false otherwise. 1153 /// \param DispatchValues struct containing llvm values for lower bound, upper 1154 /// bound, and chunk expression. 1155 /// For the default (nullptr) value, the chunk 1 will be used. 1156 /// 1157 virtual void emitForDispatchInit(CodeGenFunction &CGF, SourceLocation Loc, 1158 const OpenMPScheduleTy &ScheduleKind, 1159 unsigned IVSize, bool IVSigned, bool Ordered, 1160 const DispatchRTInput &DispatchValues); 1161 1162 /// Struct with the values to be passed to the static runtime function 1163 struct StaticRTInput { 1164 /// Size of the iteration variable in bits. 1165 unsigned IVSize = 0; 1166 /// Sign of the iteration variable. 1167 bool IVSigned = false; 1168 /// true if loop is ordered, false otherwise. 1169 bool Ordered = false; 1170 /// Address of the output variable in which the flag of the last iteration 1171 /// is returned. 1172 Address IL = Address::invalid(); 1173 /// Address of the output variable in which the lower iteration number is 1174 /// returned. 1175 Address LB = Address::invalid(); 1176 /// Address of the output variable in which the upper iteration number is 1177 /// returned. 1178 Address UB = Address::invalid(); 1179 /// Address of the output variable in which the stride value is returned 1180 /// necessary to generated the static_chunked scheduled loop. 1181 Address ST = Address::invalid(); 1182 /// Value of the chunk for the static_chunked scheduled loop. For the 1183 /// default (nullptr) value, the chunk 1 will be used. 1184 llvm::Value *Chunk = nullptr; 1185 StaticRTInput(unsigned IVSize, bool IVSigned, bool Ordered, Address IL, 1186 Address LB, Address UB, Address ST, 1187 llvm::Value *Chunk = nullptr) 1188 : IVSize(IVSize), IVSigned(IVSigned), Ordered(Ordered), IL(IL), LB(LB), 1189 UB(UB), ST(ST), Chunk(Chunk) {} 1190 }; 1191 /// Call the appropriate runtime routine to initialize it before start 1192 /// of loop. 1193 /// 1194 /// This is used only in case of static schedule, when the user did not 1195 /// specify a ordered clause on the loop construct. 1196 /// Depending on the loop schedule, it is necessary to call some runtime 1197 /// routine before start of the OpenMP loop to get the loop upper / lower 1198 /// bounds LB and UB and stride ST. 1199 /// 1200 /// \param CGF Reference to current CodeGenFunction. 1201 /// \param Loc Clang source location. 1202 /// \param DKind Kind of the directive. 1203 /// \param ScheduleKind Schedule kind, specified by the 'schedule' clause. 1204 /// \param Values Input arguments for the construct. 1205 /// 1206 virtual void emitForStaticInit(CodeGenFunction &CGF, SourceLocation Loc, 1207 OpenMPDirectiveKind DKind, 1208 const OpenMPScheduleTy &ScheduleKind, 1209 const StaticRTInput &Values); 1210 1211 /// 1212 /// \param CGF Reference to current CodeGenFunction. 1213 /// \param Loc Clang source location. 1214 /// \param SchedKind Schedule kind, specified by the 'dist_schedule' clause. 1215 /// \param Values Input arguments for the construct. 1216 /// 1217 virtual void emitDistributeStaticInit(CodeGenFunction &CGF, 1218 SourceLocation Loc, 1219 OpenMPDistScheduleClauseKind SchedKind, 1220 const StaticRTInput &Values); 1221 1222 /// Call the appropriate runtime routine to notify that we finished 1223 /// iteration of the ordered loop with the dynamic scheduling. 1224 /// 1225 /// \param CGF Reference to current CodeGenFunction. 1226 /// \param Loc Clang source location. 1227 /// \param IVSize Size of the iteration variable in bits. 1228 /// \param IVSigned Sign of the iteration variable. 1229 /// 1230 virtual void emitForOrderedIterationEnd(CodeGenFunction &CGF, 1231 SourceLocation Loc, unsigned IVSize, 1232 bool IVSigned); 1233 1234 /// Call the appropriate runtime routine to notify that we finished 1235 /// all the work with current loop. 1236 /// 1237 /// \param CGF Reference to current CodeGenFunction. 1238 /// \param Loc Clang source location. 1239 /// \param DKind Kind of the directive for which the static finish is emitted. 1240 /// 1241 virtual void emitForStaticFinish(CodeGenFunction &CGF, SourceLocation Loc, 1242 OpenMPDirectiveKind DKind); 1243 1244 /// Call __kmpc_dispatch_next( 1245 /// ident_t *loc, kmp_int32 tid, kmp_int32 *p_lastiter, 1246 /// kmp_int[32|64] *p_lower, kmp_int[32|64] *p_upper, 1247 /// kmp_int[32|64] *p_stride); 1248 /// \param IVSize Size of the iteration variable in bits. 1249 /// \param IVSigned Sign of the iteration variable. 1250 /// \param IL Address of the output variable in which the flag of the 1251 /// last iteration is returned. 1252 /// \param LB Address of the output variable in which the lower iteration 1253 /// number is returned. 1254 /// \param UB Address of the output variable in which the upper iteration 1255 /// number is returned. 1256 /// \param ST Address of the output variable in which the stride value is 1257 /// returned. 1258 virtual llvm::Value *emitForNext(CodeGenFunction &CGF, SourceLocation Loc, 1259 unsigned IVSize, bool IVSigned, 1260 Address IL, Address LB, 1261 Address UB, Address ST); 1262 1263 /// Emits call to void __kmpc_push_num_threads(ident_t *loc, kmp_int32 1264 /// global_tid, kmp_int32 num_threads) to generate code for 'num_threads' 1265 /// clause. 1266 /// \param NumThreads An integer value of threads. 1267 virtual void emitNumThreadsClause(CodeGenFunction &CGF, 1268 llvm::Value *NumThreads, 1269 SourceLocation Loc); 1270 1271 /// Emit call to void __kmpc_push_proc_bind(ident_t *loc, kmp_int32 1272 /// global_tid, int proc_bind) to generate code for 'proc_bind' clause. 1273 virtual void emitProcBindClause(CodeGenFunction &CGF, 1274 llvm::omp::ProcBindKind ProcBind, 1275 SourceLocation Loc); 1276 1277 /// Returns address of the threadprivate variable for the current 1278 /// thread. 1279 /// \param VD Threadprivate variable. 1280 /// \param VDAddr Address of the global variable \a VD. 1281 /// \param Loc Location of the reference to threadprivate var. 1282 /// \return Address of the threadprivate variable for the current thread. 1283 virtual Address getAddrOfThreadPrivate(CodeGenFunction &CGF, 1284 const VarDecl *VD, 1285 Address VDAddr, 1286 SourceLocation Loc); 1287 1288 /// Returns the address of the variable marked as declare target with link 1289 /// clause OR as declare target with to clause and unified memory. 1290 virtual Address getAddrOfDeclareTargetVar(const VarDecl *VD); 1291 1292 /// Emit a code for initialization of threadprivate variable. It emits 1293 /// a call to runtime library which adds initial value to the newly created 1294 /// threadprivate variable (if it is not constant) and registers destructor 1295 /// for the variable (if any). 1296 /// \param VD Threadprivate variable. 1297 /// \param VDAddr Address of the global variable \a VD. 1298 /// \param Loc Location of threadprivate declaration. 1299 /// \param PerformInit true if initialization expression is not constant. 1300 virtual llvm::Function * 1301 emitThreadPrivateVarDefinition(const VarDecl *VD, Address VDAddr, 1302 SourceLocation Loc, bool PerformInit, 1303 CodeGenFunction *CGF = nullptr); 1304 1305 /// Emit a code for initialization of declare target variable. 1306 /// \param VD Declare target variable. 1307 /// \param Addr Address of the global variable \a VD. 1308 /// \param PerformInit true if initialization expression is not constant. 1309 virtual bool emitDeclareTargetVarDefinition(const VarDecl *VD, 1310 llvm::GlobalVariable *Addr, 1311 bool PerformInit); 1312 1313 /// Creates artificial threadprivate variable with name \p Name and type \p 1314 /// VarType. 1315 /// \param VarType Type of the artificial threadprivate variable. 1316 /// \param Name Name of the artificial threadprivate variable. 1317 virtual Address getAddrOfArtificialThreadPrivate(CodeGenFunction &CGF, 1318 QualType VarType, 1319 StringRef Name); 1320 1321 /// Emit flush of the variables specified in 'omp flush' directive. 1322 /// \param Vars List of variables to flush. 1323 virtual void emitFlush(CodeGenFunction &CGF, ArrayRef<const Expr *> Vars, 1324 SourceLocation Loc, llvm::AtomicOrdering AO); 1325 1326 /// Emit task region for the task directive. The task region is 1327 /// emitted in several steps: 1328 /// 1. Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32 1329 /// gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds, 1330 /// kmp_routine_entry_t *task_entry). Here task_entry is a pointer to the 1331 /// function: 1332 /// kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) { 1333 /// TaskFunction(gtid, tt->part_id, tt->shareds); 1334 /// return 0; 1335 /// } 1336 /// 2. Copy a list of shared variables to field shareds of the resulting 1337 /// structure kmp_task_t returned by the previous call (if any). 1338 /// 3. Copy a pointer to destructions function to field destructions of the 1339 /// resulting structure kmp_task_t. 1340 /// 4. Emit a call to kmp_int32 __kmpc_omp_task(ident_t *, kmp_int32 gtid, 1341 /// kmp_task_t *new_task), where new_task is a resulting structure from 1342 /// previous items. 1343 /// \param D Current task directive. 1344 /// \param TaskFunction An LLVM function with type void (*)(i32 /*gtid*/, i32 1345 /// /*part_id*/, captured_struct */*__context*/); 1346 /// \param SharedsTy A type which contains references the shared variables. 1347 /// \param Shareds Context with the list of shared variables from the \p 1348 /// TaskFunction. 1349 /// \param IfCond Not a nullptr if 'if' clause was specified, nullptr 1350 /// otherwise. 1351 /// \param Data Additional data for task generation like tiednsee, final 1352 /// state, list of privates etc. 1353 virtual void emitTaskCall(CodeGenFunction &CGF, SourceLocation Loc, 1354 const OMPExecutableDirective &D, 1355 llvm::Function *TaskFunction, QualType SharedsTy, 1356 Address Shareds, const Expr *IfCond, 1357 const OMPTaskDataTy &Data); 1358 1359 /// Emit task region for the taskloop directive. The taskloop region is 1360 /// emitted in several steps: 1361 /// 1. Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32 1362 /// gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds, 1363 /// kmp_routine_entry_t *task_entry). Here task_entry is a pointer to the 1364 /// function: 1365 /// kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) { 1366 /// TaskFunction(gtid, tt->part_id, tt->shareds); 1367 /// return 0; 1368 /// } 1369 /// 2. Copy a list of shared variables to field shareds of the resulting 1370 /// structure kmp_task_t returned by the previous call (if any). 1371 /// 3. Copy a pointer to destructions function to field destructions of the 1372 /// resulting structure kmp_task_t. 1373 /// 4. Emit a call to void __kmpc_taskloop(ident_t *loc, int gtid, kmp_task_t 1374 /// *task, int if_val, kmp_uint64 *lb, kmp_uint64 *ub, kmp_int64 st, int 1375 /// nogroup, int sched, kmp_uint64 grainsize, void *task_dup ), where new_task 1376 /// is a resulting structure from 1377 /// previous items. 1378 /// \param D Current task directive. 1379 /// \param TaskFunction An LLVM function with type void (*)(i32 /*gtid*/, i32 1380 /// /*part_id*/, captured_struct */*__context*/); 1381 /// \param SharedsTy A type which contains references the shared variables. 1382 /// \param Shareds Context with the list of shared variables from the \p 1383 /// TaskFunction. 1384 /// \param IfCond Not a nullptr if 'if' clause was specified, nullptr 1385 /// otherwise. 1386 /// \param Data Additional data for task generation like tiednsee, final 1387 /// state, list of privates etc. 1388 virtual void emitTaskLoopCall(CodeGenFunction &CGF, SourceLocation Loc, 1389 const OMPLoopDirective &D, 1390 llvm::Function *TaskFunction, 1391 QualType SharedsTy, Address Shareds, 1392 const Expr *IfCond, const OMPTaskDataTy &Data); 1393 1394 /// Emit code for the directive that does not require outlining. 1395 /// 1396 /// \param InnermostKind Kind of innermost directive (for simple directives it 1397 /// is a directive itself, for combined - its innermost directive). 1398 /// \param CodeGen Code generation sequence for the \a D directive. 1399 /// \param HasCancel true if region has inner cancel directive, false 1400 /// otherwise. 1401 virtual void emitInlinedDirective(CodeGenFunction &CGF, 1402 OpenMPDirectiveKind InnermostKind, 1403 const RegionCodeGenTy &CodeGen, 1404 bool HasCancel = false); 1405 1406 /// Emits reduction function. 1407 /// \param ArgsType Array type containing pointers to reduction variables. 1408 /// \param Privates List of private copies for original reduction arguments. 1409 /// \param LHSExprs List of LHS in \a ReductionOps reduction operations. 1410 /// \param RHSExprs List of RHS in \a ReductionOps reduction operations. 1411 /// \param ReductionOps List of reduction operations in form 'LHS binop RHS' 1412 /// or 'operator binop(LHS, RHS)'. 1413 llvm::Function *emitReductionFunction(SourceLocation Loc, 1414 llvm::Type *ArgsType, 1415 ArrayRef<const Expr *> Privates, 1416 ArrayRef<const Expr *> LHSExprs, 1417 ArrayRef<const Expr *> RHSExprs, 1418 ArrayRef<const Expr *> ReductionOps); 1419 1420 /// Emits single reduction combiner 1421 void emitSingleReductionCombiner(CodeGenFunction &CGF, 1422 const Expr *ReductionOp, 1423 const Expr *PrivateRef, 1424 const DeclRefExpr *LHS, 1425 const DeclRefExpr *RHS); 1426 1427 struct ReductionOptionsTy { 1428 bool WithNowait; 1429 bool SimpleReduction; 1430 OpenMPDirectiveKind ReductionKind; 1431 }; 1432 /// Emit a code for reduction clause. Next code should be emitted for 1433 /// reduction: 1434 /// \code 1435 /// 1436 /// static kmp_critical_name lock = { 0 }; 1437 /// 1438 /// void reduce_func(void *lhs[<n>], void *rhs[<n>]) { 1439 /// ... 1440 /// *(Type<i>*)lhs[i] = RedOp<i>(*(Type<i>*)lhs[i], *(Type<i>*)rhs[i]); 1441 /// ... 1442 /// } 1443 /// 1444 /// ... 1445 /// void *RedList[<n>] = {&<RHSExprs>[0], ..., &<RHSExprs>[<n>-1]}; 1446 /// switch (__kmpc_reduce{_nowait}(<loc>, <gtid>, <n>, sizeof(RedList), 1447 /// RedList, reduce_func, &<lock>)) { 1448 /// case 1: 1449 /// ... 1450 /// <LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]); 1451 /// ... 1452 /// __kmpc_end_reduce{_nowait}(<loc>, <gtid>, &<lock>); 1453 /// break; 1454 /// case 2: 1455 /// ... 1456 /// Atomic(<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i])); 1457 /// ... 1458 /// break; 1459 /// default:; 1460 /// } 1461 /// \endcode 1462 /// 1463 /// \param Privates List of private copies for original reduction arguments. 1464 /// \param LHSExprs List of LHS in \a ReductionOps reduction operations. 1465 /// \param RHSExprs List of RHS in \a ReductionOps reduction operations. 1466 /// \param ReductionOps List of reduction operations in form 'LHS binop RHS' 1467 /// or 'operator binop(LHS, RHS)'. 1468 /// \param Options List of options for reduction codegen: 1469 /// WithNowait true if parent directive has also nowait clause, false 1470 /// otherwise. 1471 /// SimpleReduction Emit reduction operation only. Used for omp simd 1472 /// directive on the host. 1473 /// ReductionKind The kind of reduction to perform. 1474 virtual void emitReduction(CodeGenFunction &CGF, SourceLocation Loc, 1475 ArrayRef<const Expr *> Privates, 1476 ArrayRef<const Expr *> LHSExprs, 1477 ArrayRef<const Expr *> RHSExprs, 1478 ArrayRef<const Expr *> ReductionOps, 1479 ReductionOptionsTy Options); 1480 1481 /// Emit a code for initialization of task reduction clause. Next code 1482 /// should be emitted for reduction: 1483 /// \code 1484 /// 1485 /// _taskred_item_t red_data[n]; 1486 /// ... 1487 /// red_data[i].shar = &shareds[i]; 1488 /// red_data[i].orig = &origs[i]; 1489 /// red_data[i].size = sizeof(origs[i]); 1490 /// red_data[i].f_init = (void*)RedInit<i>; 1491 /// red_data[i].f_fini = (void*)RedDest<i>; 1492 /// red_data[i].f_comb = (void*)RedOp<i>; 1493 /// red_data[i].flags = <Flag_i>; 1494 /// ... 1495 /// void* tg1 = __kmpc_taskred_init(gtid, n, red_data); 1496 /// \endcode 1497 /// For reduction clause with task modifier it emits the next call: 1498 /// \code 1499 /// 1500 /// _taskred_item_t red_data[n]; 1501 /// ... 1502 /// red_data[i].shar = &shareds[i]; 1503 /// red_data[i].orig = &origs[i]; 1504 /// red_data[i].size = sizeof(origs[i]); 1505 /// red_data[i].f_init = (void*)RedInit<i>; 1506 /// red_data[i].f_fini = (void*)RedDest<i>; 1507 /// red_data[i].f_comb = (void*)RedOp<i>; 1508 /// red_data[i].flags = <Flag_i>; 1509 /// ... 1510 /// void* tg1 = __kmpc_taskred_modifier_init(loc, gtid, is_worksharing, n, 1511 /// red_data); 1512 /// \endcode 1513 /// \param LHSExprs List of LHS in \a Data.ReductionOps reduction operations. 1514 /// \param RHSExprs List of RHS in \a Data.ReductionOps reduction operations. 1515 /// \param Data Additional data for task generation like tiedness, final 1516 /// state, list of privates, reductions etc. 1517 virtual llvm::Value *emitTaskReductionInit(CodeGenFunction &CGF, 1518 SourceLocation Loc, 1519 ArrayRef<const Expr *> LHSExprs, 1520 ArrayRef<const Expr *> RHSExprs, 1521 const OMPTaskDataTy &Data); 1522 1523 /// Emits the following code for reduction clause with task modifier: 1524 /// \code 1525 /// __kmpc_task_reduction_modifier_fini(loc, gtid, is_worksharing); 1526 /// \endcode 1527 virtual void emitTaskReductionFini(CodeGenFunction &CGF, SourceLocation Loc, 1528 bool IsWorksharingReduction); 1529 1530 /// Required to resolve existing problems in the runtime. Emits threadprivate 1531 /// variables to store the size of the VLAs/array sections for 1532 /// initializer/combiner/finalizer functions. 1533 /// \param RCG Allows to reuse an existing data for the reductions. 1534 /// \param N Reduction item for which fixups must be emitted. 1535 virtual void emitTaskReductionFixups(CodeGenFunction &CGF, SourceLocation Loc, 1536 ReductionCodeGen &RCG, unsigned N); 1537 1538 /// Get the address of `void *` type of the privatue copy of the reduction 1539 /// item specified by the \p SharedLVal. 1540 /// \param ReductionsPtr Pointer to the reduction data returned by the 1541 /// emitTaskReductionInit function. 1542 /// \param SharedLVal Address of the original reduction item. 1543 virtual Address getTaskReductionItem(CodeGenFunction &CGF, SourceLocation Loc, 1544 llvm::Value *ReductionsPtr, 1545 LValue SharedLVal); 1546 1547 /// Emit code for 'taskwait' directive. 1548 virtual void emitTaskwaitCall(CodeGenFunction &CGF, SourceLocation Loc); 1549 1550 /// Emit code for 'cancellation point' construct. 1551 /// \param CancelRegion Region kind for which the cancellation point must be 1552 /// emitted. 1553 /// 1554 virtual void emitCancellationPointCall(CodeGenFunction &CGF, 1555 SourceLocation Loc, 1556 OpenMPDirectiveKind CancelRegion); 1557 1558 /// Emit code for 'cancel' construct. 1559 /// \param IfCond Condition in the associated 'if' clause, if it was 1560 /// specified, nullptr otherwise. 1561 /// \param CancelRegion Region kind for which the cancel must be emitted. 1562 /// 1563 virtual void emitCancelCall(CodeGenFunction &CGF, SourceLocation Loc, 1564 const Expr *IfCond, 1565 OpenMPDirectiveKind CancelRegion); 1566 1567 /// Emit outilined function for 'target' directive. 1568 /// \param D Directive to emit. 1569 /// \param ParentName Name of the function that encloses the target region. 1570 /// \param OutlinedFn Outlined function value to be defined by this call. 1571 /// \param OutlinedFnID Outlined function ID value to be defined by this call. 1572 /// \param IsOffloadEntry True if the outlined function is an offload entry. 1573 /// \param CodeGen Code generation sequence for the \a D directive. 1574 /// An outlined function may not be an entry if, e.g. the if clause always 1575 /// evaluates to false. 1576 virtual void emitTargetOutlinedFunction(const OMPExecutableDirective &D, 1577 StringRef ParentName, 1578 llvm::Function *&OutlinedFn, 1579 llvm::Constant *&OutlinedFnID, 1580 bool IsOffloadEntry, 1581 const RegionCodeGenTy &CodeGen); 1582 1583 /// Emit the target offloading code associated with \a D. The emitted 1584 /// code attempts offloading the execution to the device, an the event of 1585 /// a failure it executes the host version outlined in \a OutlinedFn. 1586 /// \param D Directive to emit. 1587 /// \param OutlinedFn Host version of the code to be offloaded. 1588 /// \param OutlinedFnID ID of host version of the code to be offloaded. 1589 /// \param IfCond Expression evaluated in if clause associated with the target 1590 /// directive, or null if no if clause is used. 1591 /// \param Device Expression evaluated in device clause associated with the 1592 /// target directive, or null if no device clause is used and device modifier. 1593 /// \param SizeEmitter Callback to emit number of iterations for loop-based 1594 /// directives. 1595 virtual void emitTargetCall( 1596 CodeGenFunction &CGF, const OMPExecutableDirective &D, 1597 llvm::Function *OutlinedFn, llvm::Value *OutlinedFnID, const Expr *IfCond, 1598 llvm::PointerIntPair<const Expr *, 2, OpenMPDeviceClauseModifier> Device, 1599 llvm::function_ref<llvm::Value *(CodeGenFunction &CGF, 1600 const OMPLoopDirective &D)> 1601 SizeEmitter); 1602 1603 /// Emit the target regions enclosed in \a GD function definition or 1604 /// the function itself in case it is a valid device function. Returns true if 1605 /// \a GD was dealt with successfully. 1606 /// \param GD Function to scan. 1607 virtual bool emitTargetFunctions(GlobalDecl GD); 1608 1609 /// Emit the global variable if it is a valid device global variable. 1610 /// Returns true if \a GD was dealt with successfully. 1611 /// \param GD Variable declaration to emit. 1612 virtual bool emitTargetGlobalVariable(GlobalDecl GD); 1613 1614 /// Checks if the provided global decl \a GD is a declare target variable and 1615 /// registers it when emitting code for the host. 1616 virtual void registerTargetGlobalVariable(const VarDecl *VD, 1617 llvm::Constant *Addr); 1618 1619 /// Emit the global \a GD if it is meaningful for the target. Returns 1620 /// if it was emitted successfully. 1621 /// \param GD Global to scan. 1622 virtual bool emitTargetGlobal(GlobalDecl GD); 1623 1624 /// Creates and returns a registration function for when at least one 1625 /// requires directives was used in the current module. 1626 llvm::Function *emitRequiresDirectiveRegFun(); 1627 1628 /// Creates all the offload entries in the current compilation unit 1629 /// along with the associated metadata. 1630 void createOffloadEntriesAndInfoMetadata(); 1631 1632 /// Emits code for teams call of the \a OutlinedFn with 1633 /// variables captured in a record which address is stored in \a 1634 /// CapturedStruct. 1635 /// \param OutlinedFn Outlined function to be run by team masters. Type of 1636 /// this function is void(*)(kmp_int32 *, kmp_int32, struct context_vars*). 1637 /// \param CapturedVars A pointer to the record with the references to 1638 /// variables used in \a OutlinedFn function. 1639 /// 1640 virtual void emitTeamsCall(CodeGenFunction &CGF, 1641 const OMPExecutableDirective &D, 1642 SourceLocation Loc, llvm::Function *OutlinedFn, 1643 ArrayRef<llvm::Value *> CapturedVars); 1644 1645 /// Emits call to void __kmpc_push_num_teams(ident_t *loc, kmp_int32 1646 /// global_tid, kmp_int32 num_teams, kmp_int32 thread_limit) to generate code 1647 /// for num_teams clause. 1648 /// \param NumTeams An integer expression of teams. 1649 /// \param ThreadLimit An integer expression of threads. 1650 virtual void emitNumTeamsClause(CodeGenFunction &CGF, const Expr *NumTeams, 1651 const Expr *ThreadLimit, SourceLocation Loc); 1652 1653 /// Struct that keeps all the relevant information that should be kept 1654 /// throughout a 'target data' region. 1655 class TargetDataInfo { 1656 /// Set to true if device pointer information have to be obtained. 1657 bool RequiresDevicePointerInfo = false; 1658 /// Set to true if Clang emits separate runtime calls for the beginning and 1659 /// end of the region. These calls might have separate map type arrays. 1660 bool SeparateBeginEndCalls = false; 1661 1662 public: 1663 /// The array of base pointer passed to the runtime library. 1664 llvm::Value *BasePointersArray = nullptr; 1665 /// The array of section pointers passed to the runtime library. 1666 llvm::Value *PointersArray = nullptr; 1667 /// The array of sizes passed to the runtime library. 1668 llvm::Value *SizesArray = nullptr; 1669 /// The array of map types passed to the runtime library for the beginning 1670 /// of the region or for the entire region if there are no separate map 1671 /// types for the region end. 1672 llvm::Value *MapTypesArray = nullptr; 1673 /// The array of map types passed to the runtime library for the end of the 1674 /// region, or nullptr if there are no separate map types for the region 1675 /// end. 1676 llvm::Value *MapTypesArrayEnd = nullptr; 1677 /// The array of user-defined mappers passed to the runtime library. 1678 llvm::Value *MappersArray = nullptr; 1679 /// The array of original declaration names of mapped pointers sent to the 1680 /// runtime library for debugging 1681 llvm::Value *MapNamesArray = nullptr; 1682 /// Indicate whether any user-defined mapper exists. 1683 bool HasMapper = false; 1684 /// The total number of pointers passed to the runtime library. 1685 unsigned NumberOfPtrs = 0u; 1686 /// Map between the a declaration of a capture and the corresponding base 1687 /// pointer address where the runtime returns the device pointers. 1688 llvm::DenseMap<const ValueDecl *, Address> CaptureDeviceAddrMap; 1689 1690 explicit TargetDataInfo() {} 1691 explicit TargetDataInfo(bool RequiresDevicePointerInfo, 1692 bool SeparateBeginEndCalls) 1693 : RequiresDevicePointerInfo(RequiresDevicePointerInfo), 1694 SeparateBeginEndCalls(SeparateBeginEndCalls) {} 1695 /// Clear information about the data arrays. 1696 void clearArrayInfo() { 1697 BasePointersArray = nullptr; 1698 PointersArray = nullptr; 1699 SizesArray = nullptr; 1700 MapTypesArray = nullptr; 1701 MapTypesArrayEnd = nullptr; 1702 MapNamesArray = nullptr; 1703 MappersArray = nullptr; 1704 HasMapper = false; 1705 NumberOfPtrs = 0u; 1706 } 1707 /// Return true if the current target data information has valid arrays. 1708 bool isValid() { 1709 return BasePointersArray && PointersArray && SizesArray && 1710 MapTypesArray && (!HasMapper || MappersArray) && NumberOfPtrs; 1711 } 1712 bool requiresDevicePointerInfo() { return RequiresDevicePointerInfo; } 1713 bool separateBeginEndCalls() { return SeparateBeginEndCalls; } 1714 }; 1715 1716 /// Emit the target data mapping code associated with \a D. 1717 /// \param D Directive to emit. 1718 /// \param IfCond Expression evaluated in if clause associated with the 1719 /// target directive, or null if no device clause is used. 1720 /// \param Device Expression evaluated in device clause associated with the 1721 /// target directive, or null if no device clause is used. 1722 /// \param Info A record used to store information that needs to be preserved 1723 /// until the region is closed. 1724 virtual void emitTargetDataCalls(CodeGenFunction &CGF, 1725 const OMPExecutableDirective &D, 1726 const Expr *IfCond, const Expr *Device, 1727 const RegionCodeGenTy &CodeGen, 1728 TargetDataInfo &Info); 1729 1730 /// Emit the data mapping/movement code associated with the directive 1731 /// \a D that should be of the form 'target [{enter|exit} data | update]'. 1732 /// \param D Directive to emit. 1733 /// \param IfCond Expression evaluated in if clause associated with the target 1734 /// directive, or null if no if clause is used. 1735 /// \param Device Expression evaluated in device clause associated with the 1736 /// target directive, or null if no device clause is used. 1737 virtual void emitTargetDataStandAloneCall(CodeGenFunction &CGF, 1738 const OMPExecutableDirective &D, 1739 const Expr *IfCond, 1740 const Expr *Device); 1741 1742 /// Marks function \a Fn with properly mangled versions of vector functions. 1743 /// \param FD Function marked as 'declare simd'. 1744 /// \param Fn LLVM function that must be marked with 'declare simd' 1745 /// attributes. 1746 virtual void emitDeclareSimdFunction(const FunctionDecl *FD, 1747 llvm::Function *Fn); 1748 1749 /// Emit initialization for doacross loop nesting support. 1750 /// \param D Loop-based construct used in doacross nesting construct. 1751 virtual void emitDoacrossInit(CodeGenFunction &CGF, const OMPLoopDirective &D, 1752 ArrayRef<Expr *> NumIterations); 1753 1754 /// Emit code for doacross ordered directive with 'depend' clause. 1755 /// \param C 'depend' clause with 'sink|source' dependency kind. 1756 virtual void emitDoacrossOrdered(CodeGenFunction &CGF, 1757 const OMPDependClause *C); 1758 1759 /// Translates the native parameter of outlined function if this is required 1760 /// for target. 1761 /// \param FD Field decl from captured record for the parameter. 1762 /// \param NativeParam Parameter itself. 1763 virtual const VarDecl *translateParameter(const FieldDecl *FD, 1764 const VarDecl *NativeParam) const { 1765 return NativeParam; 1766 } 1767 1768 /// Gets the address of the native argument basing on the address of the 1769 /// target-specific parameter. 1770 /// \param NativeParam Parameter itself. 1771 /// \param TargetParam Corresponding target-specific parameter. 1772 virtual Address getParameterAddress(CodeGenFunction &CGF, 1773 const VarDecl *NativeParam, 1774 const VarDecl *TargetParam) const; 1775 1776 /// Choose default schedule type and chunk value for the 1777 /// dist_schedule clause. 1778 virtual void getDefaultDistScheduleAndChunk(CodeGenFunction &CGF, 1779 const OMPLoopDirective &S, OpenMPDistScheduleClauseKind &ScheduleKind, 1780 llvm::Value *&Chunk) const {} 1781 1782 /// Choose default schedule type and chunk value for the 1783 /// schedule clause. 1784 virtual void getDefaultScheduleAndChunk(CodeGenFunction &CGF, 1785 const OMPLoopDirective &S, OpenMPScheduleClauseKind &ScheduleKind, 1786 const Expr *&ChunkExpr) const; 1787 1788 /// Emits call of the outlined function with the provided arguments, 1789 /// translating these arguments to correct target-specific arguments. 1790 virtual void 1791 emitOutlinedFunctionCall(CodeGenFunction &CGF, SourceLocation Loc, 1792 llvm::FunctionCallee OutlinedFn, 1793 ArrayRef<llvm::Value *> Args = llvm::None) const; 1794 1795 /// Emits OpenMP-specific function prolog. 1796 /// Required for device constructs. 1797 virtual void emitFunctionProlog(CodeGenFunction &CGF, const Decl *D); 1798 1799 /// Gets the OpenMP-specific address of the local variable. 1800 virtual Address getAddressOfLocalVariable(CodeGenFunction &CGF, 1801 const VarDecl *VD); 1802 1803 /// Marks the declaration as already emitted for the device code and returns 1804 /// true, if it was marked already, and false, otherwise. 1805 bool markAsGlobalTarget(GlobalDecl GD); 1806 1807 /// Emit deferred declare target variables marked for deferred emission. 1808 void emitDeferredTargetDecls() const; 1809 1810 /// Adjust some parameters for the target-based directives, like addresses of 1811 /// the variables captured by reference in lambdas. 1812 virtual void 1813 adjustTargetSpecificDataForLambdas(CodeGenFunction &CGF, 1814 const OMPExecutableDirective &D) const; 1815 1816 /// Perform check on requires decl to ensure that target architecture 1817 /// supports unified addressing 1818 virtual void processRequiresDirective(const OMPRequiresDecl *D); 1819 1820 /// Gets default memory ordering as specified in requires directive. 1821 llvm::AtomicOrdering getDefaultMemoryOrdering() const; 1822 1823 /// Checks if the variable has associated OMPAllocateDeclAttr attribute with 1824 /// the predefined allocator and translates it into the corresponding address 1825 /// space. 1826 virtual bool hasAllocateAttributeForGlobalVar(const VarDecl *VD, LangAS &AS); 1827 1828 /// Return whether the unified_shared_memory has been specified. 1829 bool hasRequiresUnifiedSharedMemory() const; 1830 1831 /// Checks if the \p VD variable is marked as nontemporal declaration in 1832 /// current context. 1833 bool isNontemporalDecl(const ValueDecl *VD) const; 1834 1835 /// Create specialized alloca to handle lastprivate conditionals. 1836 Address emitLastprivateConditionalInit(CodeGenFunction &CGF, 1837 const VarDecl *VD); 1838 1839 /// Checks if the provided \p LVal is lastprivate conditional and emits the 1840 /// code to update the value of the original variable. 1841 /// \code 1842 /// lastprivate(conditional: a) 1843 /// ... 1844 /// <type> a; 1845 /// lp_a = ...; 1846 /// #pragma omp critical(a) 1847 /// if (last_iv_a <= iv) { 1848 /// last_iv_a = iv; 1849 /// global_a = lp_a; 1850 /// } 1851 /// \endcode 1852 virtual void checkAndEmitLastprivateConditional(CodeGenFunction &CGF, 1853 const Expr *LHS); 1854 1855 /// Checks if the lastprivate conditional was updated in inner region and 1856 /// writes the value. 1857 /// \code 1858 /// lastprivate(conditional: a) 1859 /// ... 1860 /// <type> a;bool Fired = false; 1861 /// #pragma omp ... shared(a) 1862 /// { 1863 /// lp_a = ...; 1864 /// Fired = true; 1865 /// } 1866 /// if (Fired) { 1867 /// #pragma omp critical(a) 1868 /// if (last_iv_a <= iv) { 1869 /// last_iv_a = iv; 1870 /// global_a = lp_a; 1871 /// } 1872 /// Fired = false; 1873 /// } 1874 /// \endcode 1875 virtual void checkAndEmitSharedLastprivateConditional( 1876 CodeGenFunction &CGF, const OMPExecutableDirective &D, 1877 const llvm::DenseSet<CanonicalDeclPtr<const VarDecl>> &IgnoredDecls); 1878 1879 /// Gets the address of the global copy used for lastprivate conditional 1880 /// update, if any. 1881 /// \param PrivLVal LValue for the private copy. 1882 /// \param VD Original lastprivate declaration. 1883 virtual void emitLastprivateConditionalFinalUpdate(CodeGenFunction &CGF, 1884 LValue PrivLVal, 1885 const VarDecl *VD, 1886 SourceLocation Loc); 1887 1888 /// Emits list of dependecies based on the provided data (array of 1889 /// dependence/expression pairs). 1890 /// \returns Pointer to the first element of the array casted to VoidPtr type. 1891 std::pair<llvm::Value *, Address> 1892 emitDependClause(CodeGenFunction &CGF, 1893 ArrayRef<OMPTaskDataTy::DependData> Dependencies, 1894 SourceLocation Loc); 1895 1896 /// Emits list of dependecies based on the provided data (array of 1897 /// dependence/expression pairs) for depobj construct. In this case, the 1898 /// variable is allocated in dynamically. \returns Pointer to the first 1899 /// element of the array casted to VoidPtr type. 1900 Address emitDepobjDependClause(CodeGenFunction &CGF, 1901 const OMPTaskDataTy::DependData &Dependencies, 1902 SourceLocation Loc); 1903 1904 /// Emits the code to destroy the dependency object provided in depobj 1905 /// directive. 1906 void emitDestroyClause(CodeGenFunction &CGF, LValue DepobjLVal, 1907 SourceLocation Loc); 1908 1909 /// Updates the dependency kind in the specified depobj object. 1910 /// \param DepobjLVal LValue for the main depobj object. 1911 /// \param NewDepKind New dependency kind. 1912 void emitUpdateClause(CodeGenFunction &CGF, LValue DepobjLVal, 1913 OpenMPDependClauseKind NewDepKind, SourceLocation Loc); 1914 1915 /// Initializes user defined allocators specified in the uses_allocators 1916 /// clauses. 1917 void emitUsesAllocatorsInit(CodeGenFunction &CGF, const Expr *Allocator, 1918 const Expr *AllocatorTraits); 1919 1920 /// Destroys user defined allocators specified in the uses_allocators clause. 1921 void emitUsesAllocatorsFini(CodeGenFunction &CGF, const Expr *Allocator); 1922 1923 /// Returns true if the variable is a local variable in untied task. 1924 bool isLocalVarInUntiedTask(CodeGenFunction &CGF, const VarDecl *VD) const; 1925 }; 1926 1927 /// Class supports emissionof SIMD-only code. 1928 class CGOpenMPSIMDRuntime final : public CGOpenMPRuntime { 1929 public: 1930 explicit CGOpenMPSIMDRuntime(CodeGenModule &CGM) : CGOpenMPRuntime(CGM) {} 1931 ~CGOpenMPSIMDRuntime() override {} 1932 1933 /// Emits outlined function for the specified OpenMP parallel directive 1934 /// \a D. This outlined function has type void(*)(kmp_int32 *ThreadID, 1935 /// kmp_int32 BoundID, struct context_vars*). 1936 /// \param D OpenMP directive. 1937 /// \param ThreadIDVar Variable for thread id in the current OpenMP region. 1938 /// \param InnermostKind Kind of innermost directive (for simple directives it 1939 /// is a directive itself, for combined - its innermost directive). 1940 /// \param CodeGen Code generation sequence for the \a D directive. 1941 llvm::Function * 1942 emitParallelOutlinedFunction(const OMPExecutableDirective &D, 1943 const VarDecl *ThreadIDVar, 1944 OpenMPDirectiveKind InnermostKind, 1945 const RegionCodeGenTy &CodeGen) override; 1946 1947 /// Emits outlined function for the specified OpenMP teams directive 1948 /// \a D. This outlined function has type void(*)(kmp_int32 *ThreadID, 1949 /// kmp_int32 BoundID, struct context_vars*). 1950 /// \param D OpenMP directive. 1951 /// \param ThreadIDVar Variable for thread id in the current OpenMP region. 1952 /// \param InnermostKind Kind of innermost directive (for simple directives it 1953 /// is a directive itself, for combined - its innermost directive). 1954 /// \param CodeGen Code generation sequence for the \a D directive. 1955 llvm::Function * 1956 emitTeamsOutlinedFunction(const OMPExecutableDirective &D, 1957 const VarDecl *ThreadIDVar, 1958 OpenMPDirectiveKind InnermostKind, 1959 const RegionCodeGenTy &CodeGen) override; 1960 1961 /// Emits outlined function for the OpenMP task directive \a D. This 1962 /// outlined function has type void(*)(kmp_int32 ThreadID, struct task_t* 1963 /// TaskT). 1964 /// \param D OpenMP directive. 1965 /// \param ThreadIDVar Variable for thread id in the current OpenMP region. 1966 /// \param PartIDVar Variable for partition id in the current OpenMP untied 1967 /// task region. 1968 /// \param TaskTVar Variable for task_t argument. 1969 /// \param InnermostKind Kind of innermost directive (for simple directives it 1970 /// is a directive itself, for combined - its innermost directive). 1971 /// \param CodeGen Code generation sequence for the \a D directive. 1972 /// \param Tied true if task is generated for tied task, false otherwise. 1973 /// \param NumberOfParts Number of parts in untied task. Ignored for tied 1974 /// tasks. 1975 /// 1976 llvm::Function *emitTaskOutlinedFunction( 1977 const OMPExecutableDirective &D, const VarDecl *ThreadIDVar, 1978 const VarDecl *PartIDVar, const VarDecl *TaskTVar, 1979 OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen, 1980 bool Tied, unsigned &NumberOfParts) override; 1981 1982 /// Emits code for parallel or serial call of the \a OutlinedFn with 1983 /// variables captured in a record which address is stored in \a 1984 /// CapturedStruct. 1985 /// \param OutlinedFn Outlined function to be run in parallel threads. Type of 1986 /// this function is void(*)(kmp_int32 *, kmp_int32, struct context_vars*). 1987 /// \param CapturedVars A pointer to the record with the references to 1988 /// variables used in \a OutlinedFn function. 1989 /// \param IfCond Condition in the associated 'if' clause, if it was 1990 /// specified, nullptr otherwise. 1991 /// 1992 void emitParallelCall(CodeGenFunction &CGF, SourceLocation Loc, 1993 llvm::Function *OutlinedFn, 1994 ArrayRef<llvm::Value *> CapturedVars, 1995 const Expr *IfCond) override; 1996 1997 /// Emits a critical region. 1998 /// \param CriticalName Name of the critical region. 1999 /// \param CriticalOpGen Generator for the statement associated with the given 2000 /// critical region. 2001 /// \param Hint Value of the 'hint' clause (optional). 2002 void emitCriticalRegion(CodeGenFunction &CGF, StringRef CriticalName, 2003 const RegionCodeGenTy &CriticalOpGen, 2004 SourceLocation Loc, 2005 const Expr *Hint = nullptr) override; 2006 2007 /// Emits a master region. 2008 /// \param MasterOpGen Generator for the statement associated with the given 2009 /// master region. 2010 void emitMasterRegion(CodeGenFunction &CGF, 2011 const RegionCodeGenTy &MasterOpGen, 2012 SourceLocation Loc) override; 2013 2014 /// Emits a masked region. 2015 /// \param MaskedOpGen Generator for the statement associated with the given 2016 /// masked region. 2017 void emitMaskedRegion(CodeGenFunction &CGF, 2018 const RegionCodeGenTy &MaskedOpGen, SourceLocation Loc, 2019 const Expr *Filter = nullptr) override; 2020 2021 /// Emits a masked region. 2022 /// \param MaskedOpGen Generator for the statement associated with the given 2023 /// masked region. 2024 2025 /// Emits code for a taskyield directive. 2026 void emitTaskyieldCall(CodeGenFunction &CGF, SourceLocation Loc) override; 2027 2028 /// Emit a taskgroup region. 2029 /// \param TaskgroupOpGen Generator for the statement associated with the 2030 /// given taskgroup region. 2031 void emitTaskgroupRegion(CodeGenFunction &CGF, 2032 const RegionCodeGenTy &TaskgroupOpGen, 2033 SourceLocation Loc) override; 2034 2035 /// Emits a single region. 2036 /// \param SingleOpGen Generator for the statement associated with the given 2037 /// single region. 2038 void emitSingleRegion(CodeGenFunction &CGF, 2039 const RegionCodeGenTy &SingleOpGen, SourceLocation Loc, 2040 ArrayRef<const Expr *> CopyprivateVars, 2041 ArrayRef<const Expr *> DestExprs, 2042 ArrayRef<const Expr *> SrcExprs, 2043 ArrayRef<const Expr *> AssignmentOps) override; 2044 2045 /// Emit an ordered region. 2046 /// \param OrderedOpGen Generator for the statement associated with the given 2047 /// ordered region. 2048 void emitOrderedRegion(CodeGenFunction &CGF, 2049 const RegionCodeGenTy &OrderedOpGen, 2050 SourceLocation Loc, bool IsThreads) override; 2051 2052 /// Emit an implicit/explicit barrier for OpenMP threads. 2053 /// \param Kind Directive for which this implicit barrier call must be 2054 /// generated. Must be OMPD_barrier for explicit barrier generation. 2055 /// \param EmitChecks true if need to emit checks for cancellation barriers. 2056 /// \param ForceSimpleCall true simple barrier call must be emitted, false if 2057 /// runtime class decides which one to emit (simple or with cancellation 2058 /// checks). 2059 /// 2060 void emitBarrierCall(CodeGenFunction &CGF, SourceLocation Loc, 2061 OpenMPDirectiveKind Kind, bool EmitChecks = true, 2062 bool ForceSimpleCall = false) override; 2063 2064 /// This is used for non static scheduled types and when the ordered 2065 /// clause is present on the loop construct. 2066 /// Depending on the loop schedule, it is necessary to call some runtime 2067 /// routine before start of the OpenMP loop to get the loop upper / lower 2068 /// bounds \a LB and \a UB and stride \a ST. 2069 /// 2070 /// \param CGF Reference to current CodeGenFunction. 2071 /// \param Loc Clang source location. 2072 /// \param ScheduleKind Schedule kind, specified by the 'schedule' clause. 2073 /// \param IVSize Size of the iteration variable in bits. 2074 /// \param IVSigned Sign of the iteration variable. 2075 /// \param Ordered true if loop is ordered, false otherwise. 2076 /// \param DispatchValues struct containing llvm values for lower bound, upper 2077 /// bound, and chunk expression. 2078 /// For the default (nullptr) value, the chunk 1 will be used. 2079 /// 2080 void emitForDispatchInit(CodeGenFunction &CGF, SourceLocation Loc, 2081 const OpenMPScheduleTy &ScheduleKind, 2082 unsigned IVSize, bool IVSigned, bool Ordered, 2083 const DispatchRTInput &DispatchValues) override; 2084 2085 /// Call the appropriate runtime routine to initialize it before start 2086 /// of loop. 2087 /// 2088 /// This is used only in case of static schedule, when the user did not 2089 /// specify a ordered clause on the loop construct. 2090 /// Depending on the loop schedule, it is necessary to call some runtime 2091 /// routine before start of the OpenMP loop to get the loop upper / lower 2092 /// bounds LB and UB and stride ST. 2093 /// 2094 /// \param CGF Reference to current CodeGenFunction. 2095 /// \param Loc Clang source location. 2096 /// \param DKind Kind of the directive. 2097 /// \param ScheduleKind Schedule kind, specified by the 'schedule' clause. 2098 /// \param Values Input arguments for the construct. 2099 /// 2100 void emitForStaticInit(CodeGenFunction &CGF, SourceLocation Loc, 2101 OpenMPDirectiveKind DKind, 2102 const OpenMPScheduleTy &ScheduleKind, 2103 const StaticRTInput &Values) override; 2104 2105 /// 2106 /// \param CGF Reference to current CodeGenFunction. 2107 /// \param Loc Clang source location. 2108 /// \param SchedKind Schedule kind, specified by the 'dist_schedule' clause. 2109 /// \param Values Input arguments for the construct. 2110 /// 2111 void emitDistributeStaticInit(CodeGenFunction &CGF, SourceLocation Loc, 2112 OpenMPDistScheduleClauseKind SchedKind, 2113 const StaticRTInput &Values) override; 2114 2115 /// Call the appropriate runtime routine to notify that we finished 2116 /// iteration of the ordered loop with the dynamic scheduling. 2117 /// 2118 /// \param CGF Reference to current CodeGenFunction. 2119 /// \param Loc Clang source location. 2120 /// \param IVSize Size of the iteration variable in bits. 2121 /// \param IVSigned Sign of the iteration variable. 2122 /// 2123 void emitForOrderedIterationEnd(CodeGenFunction &CGF, SourceLocation Loc, 2124 unsigned IVSize, bool IVSigned) override; 2125 2126 /// Call the appropriate runtime routine to notify that we finished 2127 /// all the work with current loop. 2128 /// 2129 /// \param CGF Reference to current CodeGenFunction. 2130 /// \param Loc Clang source location. 2131 /// \param DKind Kind of the directive for which the static finish is emitted. 2132 /// 2133 void emitForStaticFinish(CodeGenFunction &CGF, SourceLocation Loc, 2134 OpenMPDirectiveKind DKind) override; 2135 2136 /// Call __kmpc_dispatch_next( 2137 /// ident_t *loc, kmp_int32 tid, kmp_int32 *p_lastiter, 2138 /// kmp_int[32|64] *p_lower, kmp_int[32|64] *p_upper, 2139 /// kmp_int[32|64] *p_stride); 2140 /// \param IVSize Size of the iteration variable in bits. 2141 /// \param IVSigned Sign of the iteration variable. 2142 /// \param IL Address of the output variable in which the flag of the 2143 /// last iteration is returned. 2144 /// \param LB Address of the output variable in which the lower iteration 2145 /// number is returned. 2146 /// \param UB Address of the output variable in which the upper iteration 2147 /// number is returned. 2148 /// \param ST Address of the output variable in which the stride value is 2149 /// returned. 2150 llvm::Value *emitForNext(CodeGenFunction &CGF, SourceLocation Loc, 2151 unsigned IVSize, bool IVSigned, Address IL, 2152 Address LB, Address UB, Address ST) override; 2153 2154 /// Emits call to void __kmpc_push_num_threads(ident_t *loc, kmp_int32 2155 /// global_tid, kmp_int32 num_threads) to generate code for 'num_threads' 2156 /// clause. 2157 /// \param NumThreads An integer value of threads. 2158 void emitNumThreadsClause(CodeGenFunction &CGF, llvm::Value *NumThreads, 2159 SourceLocation Loc) override; 2160 2161 /// Emit call to void __kmpc_push_proc_bind(ident_t *loc, kmp_int32 2162 /// global_tid, int proc_bind) to generate code for 'proc_bind' clause. 2163 void emitProcBindClause(CodeGenFunction &CGF, 2164 llvm::omp::ProcBindKind ProcBind, 2165 SourceLocation Loc) override; 2166 2167 /// Returns address of the threadprivate variable for the current 2168 /// thread. 2169 /// \param VD Threadprivate variable. 2170 /// \param VDAddr Address of the global variable \a VD. 2171 /// \param Loc Location of the reference to threadprivate var. 2172 /// \return Address of the threadprivate variable for the current thread. 2173 Address getAddrOfThreadPrivate(CodeGenFunction &CGF, const VarDecl *VD, 2174 Address VDAddr, SourceLocation Loc) override; 2175 2176 /// Emit a code for initialization of threadprivate variable. It emits 2177 /// a call to runtime library which adds initial value to the newly created 2178 /// threadprivate variable (if it is not constant) and registers destructor 2179 /// for the variable (if any). 2180 /// \param VD Threadprivate variable. 2181 /// \param VDAddr Address of the global variable \a VD. 2182 /// \param Loc Location of threadprivate declaration. 2183 /// \param PerformInit true if initialization expression is not constant. 2184 llvm::Function * 2185 emitThreadPrivateVarDefinition(const VarDecl *VD, Address VDAddr, 2186 SourceLocation Loc, bool PerformInit, 2187 CodeGenFunction *CGF = nullptr) override; 2188 2189 /// Creates artificial threadprivate variable with name \p Name and type \p 2190 /// VarType. 2191 /// \param VarType Type of the artificial threadprivate variable. 2192 /// \param Name Name of the artificial threadprivate variable. 2193 Address getAddrOfArtificialThreadPrivate(CodeGenFunction &CGF, 2194 QualType VarType, 2195 StringRef Name) override; 2196 2197 /// Emit flush of the variables specified in 'omp flush' directive. 2198 /// \param Vars List of variables to flush. 2199 void emitFlush(CodeGenFunction &CGF, ArrayRef<const Expr *> Vars, 2200 SourceLocation Loc, llvm::AtomicOrdering AO) override; 2201 2202 /// Emit task region for the task directive. The task region is 2203 /// emitted in several steps: 2204 /// 1. Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32 2205 /// gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds, 2206 /// kmp_routine_entry_t *task_entry). Here task_entry is a pointer to the 2207 /// function: 2208 /// kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) { 2209 /// TaskFunction(gtid, tt->part_id, tt->shareds); 2210 /// return 0; 2211 /// } 2212 /// 2. Copy a list of shared variables to field shareds of the resulting 2213 /// structure kmp_task_t returned by the previous call (if any). 2214 /// 3. Copy a pointer to destructions function to field destructions of the 2215 /// resulting structure kmp_task_t. 2216 /// 4. Emit a call to kmp_int32 __kmpc_omp_task(ident_t *, kmp_int32 gtid, 2217 /// kmp_task_t *new_task), where new_task is a resulting structure from 2218 /// previous items. 2219 /// \param D Current task directive. 2220 /// \param TaskFunction An LLVM function with type void (*)(i32 /*gtid*/, i32 2221 /// /*part_id*/, captured_struct */*__context*/); 2222 /// \param SharedsTy A type which contains references the shared variables. 2223 /// \param Shareds Context with the list of shared variables from the \p 2224 /// TaskFunction. 2225 /// \param IfCond Not a nullptr if 'if' clause was specified, nullptr 2226 /// otherwise. 2227 /// \param Data Additional data for task generation like tiednsee, final 2228 /// state, list of privates etc. 2229 void emitTaskCall(CodeGenFunction &CGF, SourceLocation Loc, 2230 const OMPExecutableDirective &D, 2231 llvm::Function *TaskFunction, QualType SharedsTy, 2232 Address Shareds, const Expr *IfCond, 2233 const OMPTaskDataTy &Data) override; 2234 2235 /// Emit task region for the taskloop directive. The taskloop region is 2236 /// emitted in several steps: 2237 /// 1. Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32 2238 /// gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds, 2239 /// kmp_routine_entry_t *task_entry). Here task_entry is a pointer to the 2240 /// function: 2241 /// kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) { 2242 /// TaskFunction(gtid, tt->part_id, tt->shareds); 2243 /// return 0; 2244 /// } 2245 /// 2. Copy a list of shared variables to field shareds of the resulting 2246 /// structure kmp_task_t returned by the previous call (if any). 2247 /// 3. Copy a pointer to destructions function to field destructions of the 2248 /// resulting structure kmp_task_t. 2249 /// 4. Emit a call to void __kmpc_taskloop(ident_t *loc, int gtid, kmp_task_t 2250 /// *task, int if_val, kmp_uint64 *lb, kmp_uint64 *ub, kmp_int64 st, int 2251 /// nogroup, int sched, kmp_uint64 grainsize, void *task_dup ), where new_task 2252 /// is a resulting structure from 2253 /// previous items. 2254 /// \param D Current task directive. 2255 /// \param TaskFunction An LLVM function with type void (*)(i32 /*gtid*/, i32 2256 /// /*part_id*/, captured_struct */*__context*/); 2257 /// \param SharedsTy A type which contains references the shared variables. 2258 /// \param Shareds Context with the list of shared variables from the \p 2259 /// TaskFunction. 2260 /// \param IfCond Not a nullptr if 'if' clause was specified, nullptr 2261 /// otherwise. 2262 /// \param Data Additional data for task generation like tiednsee, final 2263 /// state, list of privates etc. 2264 void emitTaskLoopCall(CodeGenFunction &CGF, SourceLocation Loc, 2265 const OMPLoopDirective &D, llvm::Function *TaskFunction, 2266 QualType SharedsTy, Address Shareds, const Expr *IfCond, 2267 const OMPTaskDataTy &Data) override; 2268 2269 /// Emit a code for reduction clause. Next code should be emitted for 2270 /// reduction: 2271 /// \code 2272 /// 2273 /// static kmp_critical_name lock = { 0 }; 2274 /// 2275 /// void reduce_func(void *lhs[<n>], void *rhs[<n>]) { 2276 /// ... 2277 /// *(Type<i>*)lhs[i] = RedOp<i>(*(Type<i>*)lhs[i], *(Type<i>*)rhs[i]); 2278 /// ... 2279 /// } 2280 /// 2281 /// ... 2282 /// void *RedList[<n>] = {&<RHSExprs>[0], ..., &<RHSExprs>[<n>-1]}; 2283 /// switch (__kmpc_reduce{_nowait}(<loc>, <gtid>, <n>, sizeof(RedList), 2284 /// RedList, reduce_func, &<lock>)) { 2285 /// case 1: 2286 /// ... 2287 /// <LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]); 2288 /// ... 2289 /// __kmpc_end_reduce{_nowait}(<loc>, <gtid>, &<lock>); 2290 /// break; 2291 /// case 2: 2292 /// ... 2293 /// Atomic(<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i])); 2294 /// ... 2295 /// break; 2296 /// default:; 2297 /// } 2298 /// \endcode 2299 /// 2300 /// \param Privates List of private copies for original reduction arguments. 2301 /// \param LHSExprs List of LHS in \a ReductionOps reduction operations. 2302 /// \param RHSExprs List of RHS in \a ReductionOps reduction operations. 2303 /// \param ReductionOps List of reduction operations in form 'LHS binop RHS' 2304 /// or 'operator binop(LHS, RHS)'. 2305 /// \param Options List of options for reduction codegen: 2306 /// WithNowait true if parent directive has also nowait clause, false 2307 /// otherwise. 2308 /// SimpleReduction Emit reduction operation only. Used for omp simd 2309 /// directive on the host. 2310 /// ReductionKind The kind of reduction to perform. 2311 void emitReduction(CodeGenFunction &CGF, SourceLocation Loc, 2312 ArrayRef<const Expr *> Privates, 2313 ArrayRef<const Expr *> LHSExprs, 2314 ArrayRef<const Expr *> RHSExprs, 2315 ArrayRef<const Expr *> ReductionOps, 2316 ReductionOptionsTy Options) override; 2317 2318 /// Emit a code for initialization of task reduction clause. Next code 2319 /// should be emitted for reduction: 2320 /// \code 2321 /// 2322 /// _taskred_item_t red_data[n]; 2323 /// ... 2324 /// red_data[i].shar = &shareds[i]; 2325 /// red_data[i].orig = &origs[i]; 2326 /// red_data[i].size = sizeof(origs[i]); 2327 /// red_data[i].f_init = (void*)RedInit<i>; 2328 /// red_data[i].f_fini = (void*)RedDest<i>; 2329 /// red_data[i].f_comb = (void*)RedOp<i>; 2330 /// red_data[i].flags = <Flag_i>; 2331 /// ... 2332 /// void* tg1 = __kmpc_taskred_init(gtid, n, red_data); 2333 /// \endcode 2334 /// For reduction clause with task modifier it emits the next call: 2335 /// \code 2336 /// 2337 /// _taskred_item_t red_data[n]; 2338 /// ... 2339 /// red_data[i].shar = &shareds[i]; 2340 /// red_data[i].orig = &origs[i]; 2341 /// red_data[i].size = sizeof(origs[i]); 2342 /// red_data[i].f_init = (void*)RedInit<i>; 2343 /// red_data[i].f_fini = (void*)RedDest<i>; 2344 /// red_data[i].f_comb = (void*)RedOp<i>; 2345 /// red_data[i].flags = <Flag_i>; 2346 /// ... 2347 /// void* tg1 = __kmpc_taskred_modifier_init(loc, gtid, is_worksharing, n, 2348 /// red_data); 2349 /// \endcode 2350 /// \param LHSExprs List of LHS in \a Data.ReductionOps reduction operations. 2351 /// \param RHSExprs List of RHS in \a Data.ReductionOps reduction operations. 2352 /// \param Data Additional data for task generation like tiedness, final 2353 /// state, list of privates, reductions etc. 2354 llvm::Value *emitTaskReductionInit(CodeGenFunction &CGF, SourceLocation Loc, 2355 ArrayRef<const Expr *> LHSExprs, 2356 ArrayRef<const Expr *> RHSExprs, 2357 const OMPTaskDataTy &Data) override; 2358 2359 /// Emits the following code for reduction clause with task modifier: 2360 /// \code 2361 /// __kmpc_task_reduction_modifier_fini(loc, gtid, is_worksharing); 2362 /// \endcode 2363 void emitTaskReductionFini(CodeGenFunction &CGF, SourceLocation Loc, 2364 bool IsWorksharingReduction) override; 2365 2366 /// Required to resolve existing problems in the runtime. Emits threadprivate 2367 /// variables to store the size of the VLAs/array sections for 2368 /// initializer/combiner/finalizer functions + emits threadprivate variable to 2369 /// store the pointer to the original reduction item for the custom 2370 /// initializer defined by declare reduction construct. 2371 /// \param RCG Allows to reuse an existing data for the reductions. 2372 /// \param N Reduction item for which fixups must be emitted. 2373 void emitTaskReductionFixups(CodeGenFunction &CGF, SourceLocation Loc, 2374 ReductionCodeGen &RCG, unsigned N) override; 2375 2376 /// Get the address of `void *` type of the privatue copy of the reduction 2377 /// item specified by the \p SharedLVal. 2378 /// \param ReductionsPtr Pointer to the reduction data returned by the 2379 /// emitTaskReductionInit function. 2380 /// \param SharedLVal Address of the original reduction item. 2381 Address getTaskReductionItem(CodeGenFunction &CGF, SourceLocation Loc, 2382 llvm::Value *ReductionsPtr, 2383 LValue SharedLVal) override; 2384 2385 /// Emit code for 'taskwait' directive. 2386 void emitTaskwaitCall(CodeGenFunction &CGF, SourceLocation Loc) override; 2387 2388 /// Emit code for 'cancellation point' construct. 2389 /// \param CancelRegion Region kind for which the cancellation point must be 2390 /// emitted. 2391 /// 2392 void emitCancellationPointCall(CodeGenFunction &CGF, SourceLocation Loc, 2393 OpenMPDirectiveKind CancelRegion) override; 2394 2395 /// Emit code for 'cancel' construct. 2396 /// \param IfCond Condition in the associated 'if' clause, if it was 2397 /// specified, nullptr otherwise. 2398 /// \param CancelRegion Region kind for which the cancel must be emitted. 2399 /// 2400 void emitCancelCall(CodeGenFunction &CGF, SourceLocation Loc, 2401 const Expr *IfCond, 2402 OpenMPDirectiveKind CancelRegion) override; 2403 2404 /// Emit outilined function for 'target' directive. 2405 /// \param D Directive to emit. 2406 /// \param ParentName Name of the function that encloses the target region. 2407 /// \param OutlinedFn Outlined function value to be defined by this call. 2408 /// \param OutlinedFnID Outlined function ID value to be defined by this call. 2409 /// \param IsOffloadEntry True if the outlined function is an offload entry. 2410 /// \param CodeGen Code generation sequence for the \a D directive. 2411 /// An outlined function may not be an entry if, e.g. the if clause always 2412 /// evaluates to false. 2413 void emitTargetOutlinedFunction(const OMPExecutableDirective &D, 2414 StringRef ParentName, 2415 llvm::Function *&OutlinedFn, 2416 llvm::Constant *&OutlinedFnID, 2417 bool IsOffloadEntry, 2418 const RegionCodeGenTy &CodeGen) override; 2419 2420 /// Emit the target offloading code associated with \a D. The emitted 2421 /// code attempts offloading the execution to the device, an the event of 2422 /// a failure it executes the host version outlined in \a OutlinedFn. 2423 /// \param D Directive to emit. 2424 /// \param OutlinedFn Host version of the code to be offloaded. 2425 /// \param OutlinedFnID ID of host version of the code to be offloaded. 2426 /// \param IfCond Expression evaluated in if clause associated with the target 2427 /// directive, or null if no if clause is used. 2428 /// \param Device Expression evaluated in device clause associated with the 2429 /// target directive, or null if no device clause is used and device modifier. 2430 void emitTargetCall( 2431 CodeGenFunction &CGF, const OMPExecutableDirective &D, 2432 llvm::Function *OutlinedFn, llvm::Value *OutlinedFnID, const Expr *IfCond, 2433 llvm::PointerIntPair<const Expr *, 2, OpenMPDeviceClauseModifier> Device, 2434 llvm::function_ref<llvm::Value *(CodeGenFunction &CGF, 2435 const OMPLoopDirective &D)> 2436 SizeEmitter) override; 2437 2438 /// Emit the target regions enclosed in \a GD function definition or 2439 /// the function itself in case it is a valid device function. Returns true if 2440 /// \a GD was dealt with successfully. 2441 /// \param GD Function to scan. 2442 bool emitTargetFunctions(GlobalDecl GD) override; 2443 2444 /// Emit the global variable if it is a valid device global variable. 2445 /// Returns true if \a GD was dealt with successfully. 2446 /// \param GD Variable declaration to emit. 2447 bool emitTargetGlobalVariable(GlobalDecl GD) override; 2448 2449 /// Emit the global \a GD if it is meaningful for the target. Returns 2450 /// if it was emitted successfully. 2451 /// \param GD Global to scan. 2452 bool emitTargetGlobal(GlobalDecl GD) override; 2453 2454 /// Emits code for teams call of the \a OutlinedFn with 2455 /// variables captured in a record which address is stored in \a 2456 /// CapturedStruct. 2457 /// \param OutlinedFn Outlined function to be run by team masters. Type of 2458 /// this function is void(*)(kmp_int32 *, kmp_int32, struct context_vars*). 2459 /// \param CapturedVars A pointer to the record with the references to 2460 /// variables used in \a OutlinedFn function. 2461 /// 2462 void emitTeamsCall(CodeGenFunction &CGF, const OMPExecutableDirective &D, 2463 SourceLocation Loc, llvm::Function *OutlinedFn, 2464 ArrayRef<llvm::Value *> CapturedVars) override; 2465 2466 /// Emits call to void __kmpc_push_num_teams(ident_t *loc, kmp_int32 2467 /// global_tid, kmp_int32 num_teams, kmp_int32 thread_limit) to generate code 2468 /// for num_teams clause. 2469 /// \param NumTeams An integer expression of teams. 2470 /// \param ThreadLimit An integer expression of threads. 2471 void emitNumTeamsClause(CodeGenFunction &CGF, const Expr *NumTeams, 2472 const Expr *ThreadLimit, SourceLocation Loc) override; 2473 2474 /// Emit the target data mapping code associated with \a D. 2475 /// \param D Directive to emit. 2476 /// \param IfCond Expression evaluated in if clause associated with the 2477 /// target directive, or null if no device clause is used. 2478 /// \param Device Expression evaluated in device clause associated with the 2479 /// target directive, or null if no device clause is used. 2480 /// \param Info A record used to store information that needs to be preserved 2481 /// until the region is closed. 2482 void emitTargetDataCalls(CodeGenFunction &CGF, 2483 const OMPExecutableDirective &D, const Expr *IfCond, 2484 const Expr *Device, const RegionCodeGenTy &CodeGen, 2485 TargetDataInfo &Info) override; 2486 2487 /// Emit the data mapping/movement code associated with the directive 2488 /// \a D that should be of the form 'target [{enter|exit} data | update]'. 2489 /// \param D Directive to emit. 2490 /// \param IfCond Expression evaluated in if clause associated with the target 2491 /// directive, or null if no if clause is used. 2492 /// \param Device Expression evaluated in device clause associated with the 2493 /// target directive, or null if no device clause is used. 2494 void emitTargetDataStandAloneCall(CodeGenFunction &CGF, 2495 const OMPExecutableDirective &D, 2496 const Expr *IfCond, 2497 const Expr *Device) override; 2498 2499 /// Emit initialization for doacross loop nesting support. 2500 /// \param D Loop-based construct used in doacross nesting construct. 2501 void emitDoacrossInit(CodeGenFunction &CGF, const OMPLoopDirective &D, 2502 ArrayRef<Expr *> NumIterations) override; 2503 2504 /// Emit code for doacross ordered directive with 'depend' clause. 2505 /// \param C 'depend' clause with 'sink|source' dependency kind. 2506 void emitDoacrossOrdered(CodeGenFunction &CGF, 2507 const OMPDependClause *C) override; 2508 2509 /// Translates the native parameter of outlined function if this is required 2510 /// for target. 2511 /// \param FD Field decl from captured record for the parameter. 2512 /// \param NativeParam Parameter itself. 2513 const VarDecl *translateParameter(const FieldDecl *FD, 2514 const VarDecl *NativeParam) const override; 2515 2516 /// Gets the address of the native argument basing on the address of the 2517 /// target-specific parameter. 2518 /// \param NativeParam Parameter itself. 2519 /// \param TargetParam Corresponding target-specific parameter. 2520 Address getParameterAddress(CodeGenFunction &CGF, const VarDecl *NativeParam, 2521 const VarDecl *TargetParam) const override; 2522 2523 /// Gets the OpenMP-specific address of the local variable. 2524 Address getAddressOfLocalVariable(CodeGenFunction &CGF, 2525 const VarDecl *VD) override { 2526 return Address::invalid(); 2527 } 2528 }; 2529 2530 } // namespace CodeGen 2531 } // namespace clang 2532 2533 #endif 2534