Go to the documentation of this file.
14 #ifndef LLVM_CLANG_LIB_CODEGEN_CGOPENMPRUNTIMEGPU_H
15 #define LLVM_CLANG_LIB_CODEGEN_CGOPENMPRUNTIMEGPU_H
39 struct EntryFunctionState {
45 bool requiresFullRuntime()
const {
return RequiresFullRuntime; }
48 void syncCTAThreads(CodeGenFunction &CGF);
51 void emitKernelInit(CodeGenFunction &CGF, EntryFunctionState &EST,
55 void emitKernelDeinit(CodeGenFunction &CGF, EntryFunctionState &EST,
59 void emitGenericVarsProlog(CodeGenFunction &CGF, SourceLocation Loc,
60 bool WithSPMDCheck =
false);
63 void emitGenericVarsEpilog(CodeGenFunction &CGF,
bool WithSPMDCheck =
false);
71 void createOffloadEntry(llvm::Constant *
ID, llvm::Constant *Addr,
73 llvm::GlobalValue::LinkageTypes
Linkage)
override;
84 void emitNonSPMDKernel(
const OMPExecutableDirective &D, StringRef ParentName,
85 llvm::Function *&OutlinedFn,
86 llvm::Constant *&OutlinedFnID,
bool IsOffloadEntry,
87 const RegionCodeGenTy &CodeGen);
100 void emitSPMDKernel(
const OMPExecutableDirective &D, StringRef ParentName,
101 llvm::Function *&OutlinedFn,
102 llvm::Constant *&OutlinedFnID,
bool IsOffloadEntry,
103 const RegionCodeGenTy &CodeGen);
114 void emitTargetOutlinedFunction(
const OMPExecutableDirective &D,
115 StringRef ParentName,
116 llvm::Function *&OutlinedFn,
117 llvm::Constant *&OutlinedFnID,
119 const RegionCodeGenTy &CodeGen)
override;
131 void emitNonSPMDParallelCall(CodeGenFunction &CGF, SourceLocation Loc,
132 llvm::Value *OutlinedFn,
133 ArrayRef<llvm::Value *> CapturedVars,
147 void emitSPMDParallelCall(CodeGenFunction &CGF, SourceLocation Loc,
148 llvm::Function *OutlinedFn,
149 ArrayRef<llvm::Value *> CapturedVars,
157 return "__omp_outlined__";
172 void clear()
override;
190 llvm::omp::ProcBindKind ProcBind,
198 llvm::Value *NumThreads,
264 llvm::Function *OutlinedFn,
266 const Expr *IfCond, llvm::Value *NumThreads)
override;
278 bool ForceSimpleCall =
false)
override;
288 const Expr *Hint =
nullptr)
override;
308 ReductionOptionsTy Options)
override;
321 const VarDecl *NativeParam)
const override;
328 const VarDecl *TargetParam)
const override;
362 llvm::Value *&Chunk)
const override;
367 const Expr *&ChunkExpr)
const override;
391 bool RequiresFullRuntime =
true;
395 bool IsInTargetMasterThreadRegion =
false;
398 bool IsInTTDRegion =
false;
400 bool IsInParallelRegion =
false;
403 llvm::DenseMap<llvm::Function *, llvm::Function *> WrapperFunctionsMap;
409 llvm::Function *createParallelDataSharingWrapper(
413 struct MappedVarData {
415 llvm::Value *GlobalizedVal =
nullptr;
420 using DeclToAddrMapTy = llvm::MapVector<const Decl *, MappedVarData>;
423 struct FunctionData {
424 DeclToAddrMapTy LocalVarData;
426 EscapedParamsTy EscapedParameters;
429 EscapedVariableLengthDeclsAddrs;
430 llvm::Value *IsInSPMDModeFlag =
nullptr;
431 std::unique_ptr<CodeGenFunction::OMPMapVars> MappedParams;
435 llvm::SmallDenseMap<llvm::Function *, FunctionData> FunctionGlobalizedDecls;
436 llvm::GlobalVariable *KernelTeamsReductionPtr =
nullptr;
444 llvm::GlobalVariable *KernelStaticGlobalized =
nullptr;
447 std::pair<const Decl *, llvm::SmallVector<const ValueDecl *, 4>>
454 #endif // LLVM_CLANG_LIB_CODEGEN_CGOPENMPRUNTIMEGPU_H
CGOpenMPRuntimeGPU(CodeGenModule &CGM)
void emitOutlinedFunctionCall(CodeGenFunction &CGF, SourceLocation Loc, llvm::FunctionCallee OutlinedFn, ArrayRef< llvm::Value * > Args=llvm::None) const override
Emits call of the outlined function with the provided arguments, translating these arguments to corre...
@ EM_SPMD
SPMD execution mode (all threads are worker threads).
void emitBarrierCall(CodeGenFunction &CGF, SourceLocation Loc, OpenMPDirectiveKind Kind, bool EmitChecks=true, bool ForceSimpleCall=false) override
Emit an implicit/explicit barrier for OpenMP threads.
Encodes a location in the source.
llvm::Value * getGPUWarpSize(CodeGenFunction &CGF)
Declare generalized virtual functions which need to be defined by all specializations of OpenMPGPURun...
void emitParallelCall(CodeGenFunction &CGF, SourceLocation Loc, llvm::Function *OutlinedFn, ArrayRef< llvm::Value * > CapturedVars, const Expr *IfCond, llvm::Value *NumThreads) override
Emits code for parallel or serial call of the OutlinedFn with variables captured in a record which ad...
Represents a member of a struct/union/class.
void adjustTargetSpecificDataForLambdas(CodeGenFunction &CGF, const OMPExecutableDirective &D) const override
Adjust some parameters for the target-based directives, like addresses of the variables captured by r...
@ Generic
Generic data-sharing mode.
void functionFinished(CodeGenFunction &CGF) override
Cleans up references to the objects in finished function.
llvm::FunctionCallee createNVPTXRuntimeFunction(unsigned Function)
Returns specified OpenMP runtime function for the current OpenMP implementation.
bool hasAllocateAttributeForGlobalVar(const VarDecl *VD, LangAS &AS) override
Checks if the variable has associated OMPAllocateDeclAttr attribute with the predefined allocator and...
llvm::Function * emitParallelOutlinedFunction(const OMPExecutableDirective &D, const VarDecl *ThreadIDVar, OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen) override
Emits inlined function for the specified OpenMP parallel.
@ CUDA
CUDA data sharing mode.
StringRef getOutlinedHelperName() const override
Get the function name of an outlined region.
virtual void emitNumThreadsClause(CodeGenFunction &CGF, llvm::Value *NumThreads, SourceLocation Loc) override
Emits call to void __kmpc_push_num_threads(ident_t *loc, kmp_int32 global_tid, kmp_int32 num_threads)...
llvm::Value * getGPUNumThreads(CodeGenFunction &CGF)
Get the maximum number of threads in a block of the GPU.
void getDefaultScheduleAndChunk(CodeGenFunction &CGF, const OMPLoopDirective &S, OpenMPScheduleClauseKind &ScheduleKind, const Expr *&ChunkExpr) const override
Choose a default value for the schedule clause.
DataSharingMode
Target codegen is specialized based on two data-sharing modes: CUDA, in which the local variables are...
Linkage
Describes the different kinds of linkage (C++ [basic.link], C99 6.2.2) that an entity may have.
virtual void emitReduction(CodeGenFunction &CGF, SourceLocation Loc, ArrayRef< const Expr * > Privates, ArrayRef< const Expr * > LHSExprs, ArrayRef< const Expr * > RHSExprs, ArrayRef< const Expr * > ReductionOps, ReductionOptionsTy Options) override
Emit a code for reduction clause.
This is a common base class for loop directives ('omp simd', 'omp for', 'omp for simd' etc....
void emitNumTeamsClause(CodeGenFunction &CGF, const Expr *NumTeams, const Expr *ThreadLimit, SourceLocation Loc) override
This function ought to emit, in the general case, a call to.
ExecutionMode
Defines the execution mode.
Represents a variable declaration or definition.
bool isDefaultLocationConstant() const override
Check if the default location must be constant.
const VarDecl * translateParameter(const FieldDecl *FD, const VarDecl *NativeParam) const override
Translates the native parameter of outlined function if this is required for target.
LangAS
Defines the address space values used by the address space qualifier of QualType.
Class provides a way to call simple version of codegen for OpenMP region, or an advanced with possibl...
void processRequiresDirective(const OMPRequiresDecl *D) override
Perform check on requires decl to ensure that target architecture supports unified addressing.
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
This class organizes the cross-function state that is used while generating LLVM code.
Decl - This represents one declaration (or definition), e.g.
void getDefaultDistScheduleAndChunk(CodeGenFunction &CGF, const OMPLoopDirective &S, OpenMPDistScheduleClauseKind &ScheduleKind, llvm::Value *&Chunk) const override
Choose a default value for the dist_schedule clause.
llvm::Value * getGPUThreadID(CodeGenFunction &CGF)
Get the id of the current thread on the GPU.
@ EM_NonSPMD
Non-SPMD execution mode (1 master thread, others are workers).
This is a basic class for representing single OpenMP executable directive.
Address getParameterAddress(CodeGenFunction &CGF, const VarDecl *NativeParam, const VarDecl *TargetParam) const override
Gets the address of the native argument basing on the address of the target-specific parameter.
OpenMPDistScheduleClauseKind
OpenMP attributes for 'dist_schedule' clause.
void emitCriticalRegion(CodeGenFunction &CGF, StringRef CriticalName, const RegionCodeGenTy &CriticalOpGen, SourceLocation Loc, const Expr *Hint=nullptr) override
Emits a critical region.
virtual void emitProcBindClause(CodeGenFunction &CGF, llvm::omp::ProcBindKind ProcBind, SourceLocation Loc) override
Emit call to void __kmpc_push_proc_bind(ident_t *loc, kmp_int32 global_tid, int proc_bind) to generat...
llvm::Function * emitTeamsOutlinedFunction(const OMPExecutableDirective &D, const VarDecl *ThreadIDVar, OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen) override
Emits inlined function for the specified OpenMP teams.
This represents '#pragma omp requires...' directive.
llvm::omp::Directive OpenMPDirectiveKind
OpenMP directives.
void emitFunctionProlog(CodeGenFunction &CGF, const Decl *D) override
Emits OpenMP-specific function prolog.
This represents one expression.
OpenMPScheduleClauseKind
OpenMP attributes for 'schedule' clause.
void emitTeamsCall(CodeGenFunction &CGF, const OMPExecutableDirective &D, SourceLocation Loc, llvm::Function *OutlinedFn, ArrayRef< llvm::Value * > CapturedVars) override
Emits code for teams call of the OutlinedFn with variables captured in a record which address is stor...
@ EM_Unknown
Unknown execution mode (orphaned directive).
unsigned getDefaultLocationReserved2Flags() const override
Returns additional flags that can be stored in reserved_2 field of the default location.
Address getAddressOfLocalVariable(CodeGenFunction &CGF, const VarDecl *VD) override
Gets the OpenMP-specific address of the local variable.