CGOpenMPRuntimeNVPTX.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. //===----- CGOpenMPRuntimeNVPTX.h - Interface to OpenMP NVPTX Runtimes ----===//
  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 specialized to NVPTX
  10. // targets.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_CLANG_LIB_CODEGEN_CGOPENMPRUNTIMENVPTX_H
  14. #define LLVM_CLANG_LIB_CODEGEN_CGOPENMPRUNTIMENVPTX_H
  15. #include "CGOpenMPRuntime.h"
  16. #include "CodeGenFunction.h"
  17. #include "clang/AST/StmtOpenMP.h"
  18. namespace clang {
  19. namespace CodeGen {
  20. class CGOpenMPRuntimeNVPTX : public CGOpenMPRuntime {
  21. public:
  22. /// Defines the execution mode.
  23. enum ExecutionMode {
  24. /// SPMD execution mode (all threads are worker threads).
  25. EM_SPMD,
  26. /// Non-SPMD execution mode (1 master thread, others are workers).
  27. EM_NonSPMD,
  28. /// Unknown execution mode (orphaned directive).
  29. EM_Unknown,
  30. };
  31. private:
  32. /// Parallel outlined function work for workers to execute.
  33. llvm::SmallVector<llvm::Function *, 16> Work;
  34. struct EntryFunctionState {
  35. llvm::BasicBlock *ExitBB = nullptr;
  36. };
  37. class WorkerFunctionState {
  38. public:
  39. llvm::Function *WorkerFn;
  40. const CGFunctionInfo &CGFI;
  41. SourceLocation Loc;
  42. WorkerFunctionState(CodeGenModule &CGM, SourceLocation Loc);
  43. private:
  44. void createWorkerFunction(CodeGenModule &CGM);
  45. };
  46. ExecutionMode getExecutionMode() const;
  47. bool requiresFullRuntime() const { return RequiresFullRuntime; }
  48. /// Get barrier to synchronize all threads in a block.
  49. void syncCTAThreads(CodeGenFunction &CGF);
  50. /// Emit the worker function for the current target region.
  51. void emitWorkerFunction(WorkerFunctionState &WST);
  52. /// Helper for worker function. Emit body of worker loop.
  53. void emitWorkerLoop(CodeGenFunction &CGF, WorkerFunctionState &WST);
  54. /// Helper for non-SPMD target entry function. Guide the master and
  55. /// worker threads to their respective locations.
  56. void emitNonSPMDEntryHeader(CodeGenFunction &CGF, EntryFunctionState &EST,
  57. WorkerFunctionState &WST);
  58. /// Signal termination of OMP execution for non-SPMD target entry
  59. /// function.
  60. void emitNonSPMDEntryFooter(CodeGenFunction &CGF, EntryFunctionState &EST);
  61. /// Helper for generic variables globalization prolog.
  62. void emitGenericVarsProlog(CodeGenFunction &CGF, SourceLocation Loc,
  63. bool WithSPMDCheck = false);
  64. /// Helper for generic variables globalization epilog.
  65. void emitGenericVarsEpilog(CodeGenFunction &CGF, bool WithSPMDCheck = false);
  66. /// Helper for SPMD mode target directive's entry function.
  67. void emitSPMDEntryHeader(CodeGenFunction &CGF, EntryFunctionState &EST,
  68. const OMPExecutableDirective &D);
  69. /// Signal termination of SPMD mode execution.
  70. void emitSPMDEntryFooter(CodeGenFunction &CGF, EntryFunctionState &EST);
  71. //
  72. // Base class overrides.
  73. //
  74. /// Creates offloading entry for the provided entry ID \a ID,
  75. /// address \a Addr, size \a Size, and flags \a Flags.
  76. void createOffloadEntry(llvm::Constant *ID, llvm::Constant *Addr,
  77. uint64_t Size, int32_t Flags,
  78. llvm::GlobalValue::LinkageTypes Linkage) override;
  79. /// Emit outlined function specialized for the Fork-Join
  80. /// programming model for applicable target directives on the NVPTX device.
  81. /// \param D Directive to emit.
  82. /// \param ParentName Name of the function that encloses the target region.
  83. /// \param OutlinedFn Outlined function value to be defined by this call.
  84. /// \param OutlinedFnID Outlined function ID value to be defined by this call.
  85. /// \param IsOffloadEntry True if the outlined function is an offload entry.
  86. /// An outlined function may not be an entry if, e.g. the if clause always
  87. /// evaluates to false.
  88. void emitNonSPMDKernel(const OMPExecutableDirective &D, StringRef ParentName,
  89. llvm::Function *&OutlinedFn,
  90. llvm::Constant *&OutlinedFnID, bool IsOffloadEntry,
  91. const RegionCodeGenTy &CodeGen);
  92. /// Emit outlined function specialized for the Single Program
  93. /// Multiple Data programming model for applicable target directives on the
  94. /// NVPTX device.
  95. /// \param D Directive to emit.
  96. /// \param ParentName Name of the function that encloses the target region.
  97. /// \param OutlinedFn Outlined function value to be defined by this call.
  98. /// \param OutlinedFnID Outlined function ID value to be defined by this call.
  99. /// \param IsOffloadEntry True if the outlined function is an offload entry.
  100. /// \param CodeGen Object containing the target statements.
  101. /// An outlined function may not be an entry if, e.g. the if clause always
  102. /// evaluates to false.
  103. void emitSPMDKernel(const OMPExecutableDirective &D, StringRef ParentName,
  104. llvm::Function *&OutlinedFn,
  105. llvm::Constant *&OutlinedFnID, bool IsOffloadEntry,
  106. const RegionCodeGenTy &CodeGen);
  107. /// Emit outlined function for 'target' directive on the NVPTX
  108. /// device.
  109. /// \param D Directive to emit.
  110. /// \param ParentName Name of the function that encloses the target region.
  111. /// \param OutlinedFn Outlined function value to be defined by this call.
  112. /// \param OutlinedFnID Outlined function ID value to be defined by this call.
  113. /// \param IsOffloadEntry True if the outlined function is an offload entry.
  114. /// An outlined function may not be an entry if, e.g. the if clause always
  115. /// evaluates to false.
  116. void emitTargetOutlinedFunction(const OMPExecutableDirective &D,
  117. StringRef ParentName,
  118. llvm::Function *&OutlinedFn,
  119. llvm::Constant *&OutlinedFnID,
  120. bool IsOffloadEntry,
  121. const RegionCodeGenTy &CodeGen) override;
  122. /// Emits code for parallel or serial call of the \a OutlinedFn with
  123. /// variables captured in a record which address is stored in \a
  124. /// CapturedStruct.
  125. /// This call is for the Non-SPMD Execution Mode.
  126. /// \param OutlinedFn Outlined function to be run in parallel threads. Type of
  127. /// this function is void(*)(kmp_int32 *, kmp_int32, struct context_vars*).
  128. /// \param CapturedVars A pointer to the record with the references to
  129. /// variables used in \a OutlinedFn function.
  130. /// \param IfCond Condition in the associated 'if' clause, if it was
  131. /// specified, nullptr otherwise.
  132. void emitNonSPMDParallelCall(CodeGenFunction &CGF, SourceLocation Loc,
  133. llvm::Value *OutlinedFn,
  134. ArrayRef<llvm::Value *> CapturedVars,
  135. const Expr *IfCond);
  136. /// Emits code for parallel or serial call of the \a OutlinedFn with
  137. /// variables captured in a record which address is stored in \a
  138. /// CapturedStruct.
  139. /// This call is for a parallel directive within an SPMD target directive.
  140. /// \param OutlinedFn Outlined function to be run in parallel threads. Type of
  141. /// this function is void(*)(kmp_int32 *, kmp_int32, struct context_vars*).
  142. /// \param CapturedVars A pointer to the record with the references to
  143. /// variables used in \a OutlinedFn function.
  144. /// \param IfCond Condition in the associated 'if' clause, if it was
  145. /// specified, nullptr otherwise.
  146. ///
  147. void emitSPMDParallelCall(CodeGenFunction &CGF, SourceLocation Loc,
  148. llvm::Function *OutlinedFn,
  149. ArrayRef<llvm::Value *> CapturedVars,
  150. const Expr *IfCond);
  151. protected:
  152. /// Get the function name of an outlined region.
  153. // The name can be customized depending on the target.
  154. //
  155. StringRef getOutlinedHelperName() const override {
  156. return "__omp_outlined__";
  157. }
  158. /// Check if the default location must be constant.
  159. /// Constant for NVPTX for better optimization.
  160. bool isDefaultLocationConstant() const override { return true; }
  161. /// Returns additional flags that can be stored in reserved_2 field of the
  162. /// default location.
  163. /// For NVPTX target contains data about SPMD/Non-SPMD execution mode +
  164. /// Full/Lightweight runtime mode. Used for better optimization.
  165. unsigned getDefaultLocationReserved2Flags() const override;
  166. /// Tries to emit declare variant function for \p OldGD from \p NewGD.
  167. /// \param OrigAddr LLVM IR value for \p OldGD.
  168. /// \param IsForDefinition true, if requested emission for the definition of
  169. /// \p OldGD.
  170. /// \returns true, was able to emit a definition function for \p OldGD, which
  171. /// points to \p NewGD.
  172. /// NVPTX backend does not support global aliases, so just use the function,
  173. /// emitted for \p NewGD instead of \p OldGD.
  174. bool tryEmitDeclareVariant(const GlobalDecl &NewGD, const GlobalDecl &OldGD,
  175. llvm::GlobalValue *OrigAddr,
  176. bool IsForDefinition) override;
  177. public:
  178. explicit CGOpenMPRuntimeNVPTX(CodeGenModule &CGM);
  179. void clear() override;
  180. /// Emit call to void __kmpc_push_proc_bind(ident_t *loc, kmp_int32
  181. /// global_tid, int proc_bind) to generate code for 'proc_bind' clause.
  182. virtual void emitProcBindClause(CodeGenFunction &CGF,
  183. OpenMPProcBindClauseKind ProcBind,
  184. SourceLocation Loc) override;
  185. /// Emits call to void __kmpc_push_num_threads(ident_t *loc, kmp_int32
  186. /// global_tid, kmp_int32 num_threads) to generate code for 'num_threads'
  187. /// clause.
  188. /// \param NumThreads An integer value of threads.
  189. virtual void emitNumThreadsClause(CodeGenFunction &CGF,
  190. llvm::Value *NumThreads,
  191. SourceLocation Loc) override;
  192. /// This function ought to emit, in the general case, a call to
  193. // the openmp runtime kmpc_push_num_teams. In NVPTX backend it is not needed
  194. // as these numbers are obtained through the PTX grid and block configuration.
  195. /// \param NumTeams An integer expression of teams.
  196. /// \param ThreadLimit An integer expression of threads.
  197. void emitNumTeamsClause(CodeGenFunction &CGF, const Expr *NumTeams,
  198. const Expr *ThreadLimit, SourceLocation Loc) override;
  199. /// Emits inlined function for the specified OpenMP parallel
  200. // directive.
  201. /// \a D. This outlined function has type void(*)(kmp_int32 *ThreadID,
  202. /// kmp_int32 BoundID, struct context_vars*).
  203. /// \param D OpenMP directive.
  204. /// \param ThreadIDVar Variable for thread id in the current OpenMP region.
  205. /// \param InnermostKind Kind of innermost directive (for simple directives it
  206. /// is a directive itself, for combined - its innermost directive).
  207. /// \param CodeGen Code generation sequence for the \a D directive.
  208. llvm::Function *
  209. emitParallelOutlinedFunction(const OMPExecutableDirective &D,
  210. const VarDecl *ThreadIDVar,
  211. OpenMPDirectiveKind InnermostKind,
  212. const RegionCodeGenTy &CodeGen) override;
  213. /// Emits inlined function for the specified OpenMP teams
  214. // directive.
  215. /// \a D. This outlined function has type void(*)(kmp_int32 *ThreadID,
  216. /// kmp_int32 BoundID, struct context_vars*).
  217. /// \param D OpenMP directive.
  218. /// \param ThreadIDVar Variable for thread id in the current OpenMP region.
  219. /// \param InnermostKind Kind of innermost directive (for simple directives it
  220. /// is a directive itself, for combined - its innermost directive).
  221. /// \param CodeGen Code generation sequence for the \a D directive.
  222. llvm::Function *
  223. emitTeamsOutlinedFunction(const OMPExecutableDirective &D,
  224. const VarDecl *ThreadIDVar,
  225. OpenMPDirectiveKind InnermostKind,
  226. const RegionCodeGenTy &CodeGen) override;
  227. /// Emits code for teams call of the \a OutlinedFn with
  228. /// variables captured in a record which address is stored in \a
  229. /// CapturedStruct.
  230. /// \param OutlinedFn Outlined function to be run by team masters. Type of
  231. /// this function is void(*)(kmp_int32 *, kmp_int32, struct context_vars*).
  232. /// \param CapturedVars A pointer to the record with the references to
  233. /// variables used in \a OutlinedFn function.
  234. ///
  235. void emitTeamsCall(CodeGenFunction &CGF, const OMPExecutableDirective &D,
  236. SourceLocation Loc, llvm::Function *OutlinedFn,
  237. ArrayRef<llvm::Value *> CapturedVars) override;
  238. /// Emits code for parallel or serial call of the \a OutlinedFn with
  239. /// variables captured in a record which address is stored in \a
  240. /// CapturedStruct.
  241. /// \param OutlinedFn Outlined function to be run in parallel threads. Type of
  242. /// this function is void(*)(kmp_int32 *, kmp_int32, struct context_vars*).
  243. /// \param CapturedVars A pointer to the record with the references to
  244. /// variables used in \a OutlinedFn function.
  245. /// \param IfCond Condition in the associated 'if' clause, if it was
  246. /// specified, nullptr otherwise.
  247. void emitParallelCall(CodeGenFunction &CGF, SourceLocation Loc,
  248. llvm::Function *OutlinedFn,
  249. ArrayRef<llvm::Value *> CapturedVars,
  250. const Expr *IfCond) override;
  251. /// Emit an implicit/explicit barrier for OpenMP threads.
  252. /// \param Kind Directive for which this implicit barrier call must be
  253. /// generated. Must be OMPD_barrier for explicit barrier generation.
  254. /// \param EmitChecks true if need to emit checks for cancellation barriers.
  255. /// \param ForceSimpleCall true simple barrier call must be emitted, false if
  256. /// runtime class decides which one to emit (simple or with cancellation
  257. /// checks).
  258. ///
  259. void emitBarrierCall(CodeGenFunction &CGF, SourceLocation Loc,
  260. OpenMPDirectiveKind Kind, bool EmitChecks = true,
  261. bool ForceSimpleCall = false) override;
  262. /// Emits a critical region.
  263. /// \param CriticalName Name of the critical region.
  264. /// \param CriticalOpGen Generator for the statement associated with the given
  265. /// critical region.
  266. /// \param Hint Value of the 'hint' clause (optional).
  267. void emitCriticalRegion(CodeGenFunction &CGF, StringRef CriticalName,
  268. const RegionCodeGenTy &CriticalOpGen,
  269. SourceLocation Loc,
  270. const Expr *Hint = nullptr) override;
  271. /// Emit a code for reduction clause.
  272. ///
  273. /// \param Privates List of private copies for original reduction arguments.
  274. /// \param LHSExprs List of LHS in \a ReductionOps reduction operations.
  275. /// \param RHSExprs List of RHS in \a ReductionOps reduction operations.
  276. /// \param ReductionOps List of reduction operations in form 'LHS binop RHS'
  277. /// or 'operator binop(LHS, RHS)'.
  278. /// \param Options List of options for reduction codegen:
  279. /// WithNowait true if parent directive has also nowait clause, false
  280. /// otherwise.
  281. /// SimpleReduction Emit reduction operation only. Used for omp simd
  282. /// directive on the host.
  283. /// ReductionKind The kind of reduction to perform.
  284. virtual void emitReduction(CodeGenFunction &CGF, SourceLocation Loc,
  285. ArrayRef<const Expr *> Privates,
  286. ArrayRef<const Expr *> LHSExprs,
  287. ArrayRef<const Expr *> RHSExprs,
  288. ArrayRef<const Expr *> ReductionOps,
  289. ReductionOptionsTy Options) override;
  290. /// Returns specified OpenMP runtime function for the current OpenMP
  291. /// implementation. Specialized for the NVPTX device.
  292. /// \param Function OpenMP runtime function.
  293. /// \return Specified function.
  294. llvm::FunctionCallee createNVPTXRuntimeFunction(unsigned Function);
  295. /// Translates the native parameter of outlined function if this is required
  296. /// for target.
  297. /// \param FD Field decl from captured record for the parameter.
  298. /// \param NativeParam Parameter itself.
  299. const VarDecl *translateParameter(const FieldDecl *FD,
  300. const VarDecl *NativeParam) const override;
  301. /// Gets the address of the native argument basing on the address of the
  302. /// target-specific parameter.
  303. /// \param NativeParam Parameter itself.
  304. /// \param TargetParam Corresponding target-specific parameter.
  305. Address getParameterAddress(CodeGenFunction &CGF, const VarDecl *NativeParam,
  306. const VarDecl *TargetParam) const override;
  307. /// Emits call of the outlined function with the provided arguments,
  308. /// translating these arguments to correct target-specific arguments.
  309. void emitOutlinedFunctionCall(
  310. CodeGenFunction &CGF, SourceLocation Loc, llvm::FunctionCallee OutlinedFn,
  311. ArrayRef<llvm::Value *> Args = llvm::None) const override;
  312. /// Emits OpenMP-specific function prolog.
  313. /// Required for device constructs.
  314. void emitFunctionProlog(CodeGenFunction &CGF, const Decl *D) override;
  315. /// Gets the OpenMP-specific address of the local variable.
  316. Address getAddressOfLocalVariable(CodeGenFunction &CGF,
  317. const VarDecl *VD) override;
  318. /// Target codegen is specialized based on two data-sharing modes: CUDA, in
  319. /// which the local variables are actually global threadlocal, and Generic, in
  320. /// which the local variables are placed in global memory if they may escape
  321. /// their declaration context.
  322. enum DataSharingMode {
  323. /// CUDA data sharing mode.
  324. CUDA,
  325. /// Generic data-sharing mode.
  326. Generic,
  327. };
  328. /// Cleans up references to the objects in finished function.
  329. ///
  330. void functionFinished(CodeGenFunction &CGF) override;
  331. /// Choose a default value for the dist_schedule clause.
  332. void getDefaultDistScheduleAndChunk(CodeGenFunction &CGF,
  333. const OMPLoopDirective &S, OpenMPDistScheduleClauseKind &ScheduleKind,
  334. llvm::Value *&Chunk) const override;
  335. /// Choose a default value for the schedule clause.
  336. void getDefaultScheduleAndChunk(CodeGenFunction &CGF,
  337. const OMPLoopDirective &S, OpenMPScheduleClauseKind &ScheduleKind,
  338. const Expr *&ChunkExpr) const override;
  339. /// Adjust some parameters for the target-based directives, like addresses of
  340. /// the variables captured by reference in lambdas.
  341. void adjustTargetSpecificDataForLambdas(
  342. CodeGenFunction &CGF, const OMPExecutableDirective &D) const override;
  343. /// Perform check on requires decl to ensure that target architecture
  344. /// supports unified addressing
  345. void checkArchForUnifiedAddressing(const OMPRequiresDecl *D) override;
  346. /// Returns default address space for the constant firstprivates, __constant__
  347. /// address space by default.
  348. unsigned getDefaultFirstprivateAddressSpace() const override;
  349. /// Checks if the variable has associated OMPAllocateDeclAttr attribute with
  350. /// the predefined allocator and translates it into the corresponding address
  351. /// space.
  352. bool hasAllocateAttributeForGlobalVar(const VarDecl *VD, LangAS &AS) override;
  353. private:
  354. /// Track the execution mode when codegening directives within a target
  355. /// region. The appropriate mode (SPMD/NON-SPMD) is set on entry to the
  356. /// target region and used by containing directives such as 'parallel'
  357. /// to emit optimized code.
  358. ExecutionMode CurrentExecutionMode = EM_Unknown;
  359. /// Check if the full runtime is required (default - yes).
  360. bool RequiresFullRuntime = true;
  361. /// true if we're emitting the code for the target region and next parallel
  362. /// region is L0 for sure.
  363. bool IsInTargetMasterThreadRegion = false;
  364. /// true if currently emitting code for target/teams/distribute region, false
  365. /// - otherwise.
  366. bool IsInTTDRegion = false;
  367. /// true if we're definitely in the parallel region.
  368. bool IsInParallelRegion = false;
  369. /// Map between an outlined function and its wrapper.
  370. llvm::DenseMap<llvm::Function *, llvm::Function *> WrapperFunctionsMap;
  371. /// Emit function which wraps the outline parallel region
  372. /// and controls the parameters which are passed to this function.
  373. /// The wrapper ensures that the outlined function is called
  374. /// with the correct arguments when data is shared.
  375. llvm::Function *createParallelDataSharingWrapper(
  376. llvm::Function *OutlinedParallelFn, const OMPExecutableDirective &D);
  377. /// The data for the single globalized variable.
  378. struct MappedVarData {
  379. /// Corresponding field in the global record.
  380. const FieldDecl *FD = nullptr;
  381. /// Corresponding address.
  382. Address PrivateAddr = Address::invalid();
  383. /// true, if only one element is required (for latprivates in SPMD mode),
  384. /// false, if need to create based on the warp-size.
  385. bool IsOnePerTeam = false;
  386. MappedVarData() = delete;
  387. MappedVarData(const FieldDecl *FD, bool IsOnePerTeam = false)
  388. : FD(FD), IsOnePerTeam(IsOnePerTeam) {}
  389. };
  390. /// The map of local variables to their addresses in the global memory.
  391. using DeclToAddrMapTy = llvm::MapVector<const Decl *, MappedVarData>;
  392. /// Set of the parameters passed by value escaping OpenMP context.
  393. using EscapedParamsTy = llvm::SmallPtrSet<const Decl *, 4>;
  394. struct FunctionData {
  395. DeclToAddrMapTy LocalVarData;
  396. llvm::Optional<DeclToAddrMapTy> SecondaryLocalVarData = llvm::None;
  397. EscapedParamsTy EscapedParameters;
  398. llvm::SmallVector<const ValueDecl*, 4> EscapedVariableLengthDecls;
  399. llvm::SmallVector<llvm::Value *, 4> EscapedVariableLengthDeclsAddrs;
  400. const RecordDecl *GlobalRecord = nullptr;
  401. llvm::Optional<const RecordDecl *> SecondaryGlobalRecord = llvm::None;
  402. llvm::Value *GlobalRecordAddr = nullptr;
  403. llvm::Value *IsInSPMDModeFlag = nullptr;
  404. std::unique_ptr<CodeGenFunction::OMPMapVars> MappedParams;
  405. };
  406. /// Maps the function to the list of the globalized variables with their
  407. /// addresses.
  408. llvm::SmallDenseMap<llvm::Function *, FunctionData> FunctionGlobalizedDecls;
  409. /// List of records for the globalized variables in target/teams/distribute
  410. /// contexts. Inner records are going to be joined into the single record,
  411. /// while those resulting records are going to be joined into the single
  412. /// union. This resulting union (one per CU) is the entry point for the static
  413. /// memory management runtime functions.
  414. struct GlobalPtrSizeRecsTy {
  415. llvm::GlobalVariable *UseSharedMemory = nullptr;
  416. llvm::GlobalVariable *RecSize = nullptr;
  417. llvm::GlobalVariable *Buffer = nullptr;
  418. SourceLocation Loc;
  419. llvm::SmallVector<const RecordDecl *, 2> Records;
  420. unsigned RegionCounter = 0;
  421. };
  422. llvm::SmallVector<GlobalPtrSizeRecsTy, 8> GlobalizedRecords;
  423. llvm::GlobalVariable *KernelTeamsReductionPtr = nullptr;
  424. /// List of the records with the list of fields for the reductions across the
  425. /// teams. Used to build the intermediate buffer for the fast teams
  426. /// reductions.
  427. /// All the records are gathered into a union `union.type` is created.
  428. llvm::SmallVector<const RecordDecl *, 4> TeamsReductions;
  429. /// Shared pointer for the global memory in the global memory buffer used for
  430. /// the given kernel.
  431. llvm::GlobalVariable *KernelStaticGlobalized = nullptr;
  432. /// Pair of the Non-SPMD team and all reductions variables in this team
  433. /// region.
  434. std::pair<const Decl *, llvm::SmallVector<const ValueDecl *, 4>>
  435. TeamAndReductions;
  436. };
  437. } // CodeGen namespace.
  438. } // clang namespace.
  439. #endif // LLVM_CLANG_LIB_CODEGEN_CGOPENMPRUNTIMENVPTX_H