2016-02-08 23:59:20 +08:00
|
|
|
//===----- CGOpenMPRuntimeNVPTX.h - Interface to OpenMP NVPTX Runtimes ----===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This provides a class for OpenMP runtime code generation specialized to NVPTX
|
|
|
|
// targets.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CLANG_LIB_CODEGEN_CGOPENMPRUNTIMENVPTX_H
|
|
|
|
#define LLVM_CLANG_LIB_CODEGEN_CGOPENMPRUNTIMENVPTX_H
|
|
|
|
|
|
|
|
#include "CGOpenMPRuntime.h"
|
2016-03-22 09:48:56 +08:00
|
|
|
#include "CodeGenFunction.h"
|
|
|
|
#include "clang/AST/StmtOpenMP.h"
|
|
|
|
#include "llvm/IR/CallSite.h"
|
2016-02-08 23:59:20 +08:00
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace CodeGen {
|
|
|
|
|
|
|
|
class CGOpenMPRuntimeNVPTX : public CGOpenMPRuntime {
|
2018-05-11 02:32:08 +08:00
|
|
|
public:
|
|
|
|
/// Defines the execution mode.
|
|
|
|
enum ExecutionMode {
|
|
|
|
/// SPMD execution mode (all threads are worker threads).
|
|
|
|
EM_SPMD,
|
|
|
|
/// Non-SPMD execution mode (1 master thread, others are workers).
|
|
|
|
EM_NonSPMD,
|
|
|
|
/// Unknown execution mode (orphaned directive).
|
|
|
|
EM_Unknown,
|
|
|
|
};
|
2017-01-05 23:24:05 +08:00
|
|
|
private:
|
2018-05-07 22:50:05 +08:00
|
|
|
/// Parallel outlined function work for workers to execute.
|
2017-01-10 23:42:51 +08:00
|
|
|
llvm::SmallVector<llvm::Function *, 16> Work;
|
|
|
|
|
2016-12-23 03:44:05 +08:00
|
|
|
struct EntryFunctionState {
|
|
|
|
llvm::BasicBlock *ExitBB = nullptr;
|
2016-03-29 13:34:15 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class WorkerFunctionState {
|
|
|
|
public:
|
|
|
|
llvm::Function *WorkerFn;
|
2018-04-17 04:16:21 +08:00
|
|
|
const CGFunctionInfo &CGFI;
|
2018-01-05 03:45:16 +08:00
|
|
|
SourceLocation Loc;
|
2016-03-29 13:34:15 +08:00
|
|
|
|
2018-01-05 03:45:16 +08:00
|
|
|
WorkerFunctionState(CodeGenModule &CGM, SourceLocation Loc);
|
2016-03-29 13:34:15 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
void createWorkerFunction(CodeGenModule &CGM);
|
|
|
|
};
|
|
|
|
|
2018-05-11 02:32:08 +08:00
|
|
|
ExecutionMode getExecutionMode() const;
|
2017-01-19 03:35:00 +08:00
|
|
|
|
2018-11-27 02:37:09 +08:00
|
|
|
bool requiresFullRuntime() const { return RequiresFullRuntime; }
|
|
|
|
|
2019-01-04 00:25:35 +08:00
|
|
|
/// Get barrier to synchronize all threads in a block.
|
|
|
|
void syncCTAThreads(CodeGenFunction &CGF);
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Emit the worker function for the current target region.
|
2016-03-22 09:48:56 +08:00
|
|
|
void emitWorkerFunction(WorkerFunctionState &WST);
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Helper for worker function. Emit body of worker loop.
|
2016-03-22 09:48:56 +08:00
|
|
|
void emitWorkerLoop(CodeGenFunction &CGF, WorkerFunctionState &WST);
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Helper for non-SPMD target entry function. Guide the master and
|
2017-01-05 23:24:05 +08:00
|
|
|
/// worker threads to their respective locations.
|
2018-05-07 22:50:05 +08:00
|
|
|
void emitNonSPMDEntryHeader(CodeGenFunction &CGF, EntryFunctionState &EST,
|
2017-01-05 23:24:05 +08:00
|
|
|
WorkerFunctionState &WST);
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Signal termination of OMP execution for non-SPMD target entry
|
2017-01-05 23:24:05 +08:00
|
|
|
/// function.
|
2018-05-07 22:50:05 +08:00
|
|
|
void emitNonSPMDEntryFooter(CodeGenFunction &CGF, EntryFunctionState &EST);
|
2017-01-05 23:24:05 +08:00
|
|
|
|
2018-03-16 02:10:54 +08:00
|
|
|
/// Helper for generic variables globalization prolog.
|
2018-08-31 02:56:11 +08:00
|
|
|
void emitGenericVarsProlog(CodeGenFunction &CGF, SourceLocation Loc,
|
|
|
|
bool WithSPMDCheck = false);
|
2018-03-16 02:10:54 +08:00
|
|
|
|
|
|
|
/// Helper for generic variables globalization epilog.
|
2018-08-31 02:56:11 +08:00
|
|
|
void emitGenericVarsEpilog(CodeGenFunction &CGF, bool WithSPMDCheck = false);
|
2018-03-16 02:10:54 +08:00
|
|
|
|
2018-06-22 04:26:33 +08:00
|
|
|
/// Helper for SPMD mode target directive's entry function.
|
|
|
|
void emitSPMDEntryHeader(CodeGenFunction &CGF, EntryFunctionState &EST,
|
2017-01-19 03:35:00 +08:00
|
|
|
const OMPExecutableDirective &D);
|
|
|
|
|
2018-06-22 04:26:33 +08:00
|
|
|
/// Signal termination of SPMD mode execution.
|
|
|
|
void emitSPMDEntryFooter(CodeGenFunction &CGF, EntryFunctionState &EST);
|
2017-01-19 03:35:00 +08:00
|
|
|
|
2016-03-22 09:48:56 +08:00
|
|
|
//
|
|
|
|
// Base class overrides.
|
|
|
|
//
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Creates offloading entry for the provided entry ID \a ID,
|
[OpenMP] Add fields for flags in the offload entry descriptor.
Summary:
This patch adds two fields to the offload entry descriptor. One field is meant to signal Ctors/Dtors and `link` global variables, and the other is reserved for runtime library use.
Currently, these fields are only filled with zeros in the current code generation, but that will change when `declare target` is added.
The reason, we are adding these fields now is to make the code generation consistent with the runtime library proposal under review in https://reviews.llvm.org/D14031.
Reviewers: ABataev, hfinkel, carlo.bertolli, kkwli0, arpith-jacob, Hahnfeld
Subscribers: cfe-commits, caomhin, jholewinski
Differential Revision: https://reviews.llvm.org/D28298
llvm-svn: 291124
2017-01-06 00:02:49 +08:00
|
|
|
/// address \a Addr, size \a Size, and flags \a Flags.
|
2016-03-22 09:48:56 +08:00
|
|
|
void createOffloadEntry(llvm::Constant *ID, llvm::Constant *Addr,
|
2018-03-31 02:31:07 +08:00
|
|
|
uint64_t Size, int32_t Flags,
|
|
|
|
llvm::GlobalValue::LinkageTypes Linkage) override;
|
2016-03-22 09:48:56 +08:00
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Emit outlined function specialized for the Fork-Join
|
2017-01-05 23:24:05 +08:00
|
|
|
/// programming model for applicable target directives on the NVPTX device.
|
|
|
|
/// \param D Directive to emit.
|
|
|
|
/// \param ParentName Name of the function that encloses the target region.
|
|
|
|
/// \param OutlinedFn Outlined function value to be defined by this call.
|
|
|
|
/// \param OutlinedFnID Outlined function ID value to be defined by this call.
|
|
|
|
/// \param IsOffloadEntry True if the outlined function is an offload entry.
|
|
|
|
/// An outlined function may not be an entry if, e.g. the if clause always
|
|
|
|
/// evaluates to false.
|
2018-05-07 22:50:05 +08:00
|
|
|
void emitNonSPMDKernel(const OMPExecutableDirective &D, StringRef ParentName,
|
2017-01-05 23:24:05 +08:00
|
|
|
llvm::Function *&OutlinedFn,
|
|
|
|
llvm::Constant *&OutlinedFnID, bool IsOffloadEntry,
|
|
|
|
const RegionCodeGenTy &CodeGen);
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Emit outlined function specialized for the Single Program
|
2017-01-19 03:35:00 +08:00
|
|
|
/// Multiple Data programming model for applicable target directives on the
|
|
|
|
/// NVPTX device.
|
|
|
|
/// \param D Directive to emit.
|
|
|
|
/// \param ParentName Name of the function that encloses the target region.
|
|
|
|
/// \param OutlinedFn Outlined function value to be defined by this call.
|
|
|
|
/// \param OutlinedFnID Outlined function ID value to be defined by this call.
|
|
|
|
/// \param IsOffloadEntry True if the outlined function is an offload entry.
|
|
|
|
/// \param CodeGen Object containing the target statements.
|
|
|
|
/// An outlined function may not be an entry if, e.g. the if clause always
|
|
|
|
/// evaluates to false.
|
2018-06-22 04:26:33 +08:00
|
|
|
void emitSPMDKernel(const OMPExecutableDirective &D, StringRef ParentName,
|
2017-01-19 03:35:00 +08:00
|
|
|
llvm::Function *&OutlinedFn,
|
|
|
|
llvm::Constant *&OutlinedFnID, bool IsOffloadEntry,
|
|
|
|
const RegionCodeGenTy &CodeGen);
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Emit outlined function for 'target' directive on the NVPTX
|
2016-03-22 09:48:56 +08:00
|
|
|
/// device.
|
|
|
|
/// \param D Directive to emit.
|
|
|
|
/// \param ParentName Name of the function that encloses the target region.
|
|
|
|
/// \param OutlinedFn Outlined function value to be defined by this call.
|
|
|
|
/// \param OutlinedFnID Outlined function ID value to be defined by this call.
|
|
|
|
/// \param IsOffloadEntry True if the outlined function is an offload entry.
|
|
|
|
/// An outlined function may not be an entry if, e.g. the if clause always
|
|
|
|
/// evaluates to false.
|
|
|
|
void emitTargetOutlinedFunction(const OMPExecutableDirective &D,
|
|
|
|
StringRef ParentName,
|
|
|
|
llvm::Function *&OutlinedFn,
|
|
|
|
llvm::Constant *&OutlinedFnID,
|
2016-03-29 13:34:15 +08:00
|
|
|
bool IsOffloadEntry,
|
|
|
|
const RegionCodeGenTy &CodeGen) override;
|
2016-03-22 09:48:56 +08:00
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Emits code for parallel or serial call of the \a OutlinedFn with
|
2017-01-10 23:42:51 +08:00
|
|
|
/// variables captured in a record which address is stored in \a
|
|
|
|
/// CapturedStruct.
|
2018-05-07 22:50:05 +08:00
|
|
|
/// This call is for the Non-SPMD Execution Mode.
|
2017-01-10 23:42:51 +08:00
|
|
|
/// \param OutlinedFn Outlined function to be run in parallel threads. Type of
|
|
|
|
/// this function is void(*)(kmp_int32 *, kmp_int32, struct context_vars*).
|
|
|
|
/// \param CapturedVars A pointer to the record with the references to
|
|
|
|
/// variables used in \a OutlinedFn function.
|
|
|
|
/// \param IfCond Condition in the associated 'if' clause, if it was
|
|
|
|
/// specified, nullptr otherwise.
|
2018-05-07 22:50:05 +08:00
|
|
|
void emitNonSPMDParallelCall(CodeGenFunction &CGF, SourceLocation Loc,
|
2017-01-10 23:42:51 +08:00
|
|
|
llvm::Value *OutlinedFn,
|
|
|
|
ArrayRef<llvm::Value *> CapturedVars,
|
|
|
|
const Expr *IfCond);
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Emits code for parallel or serial call of the \a OutlinedFn with
|
2017-01-19 03:35:00 +08:00
|
|
|
/// variables captured in a record which address is stored in \a
|
|
|
|
/// CapturedStruct.
|
|
|
|
/// This call is for a parallel directive within an SPMD target directive.
|
|
|
|
/// \param OutlinedFn Outlined function to be run in parallel threads. Type of
|
|
|
|
/// this function is void(*)(kmp_int32 *, kmp_int32, struct context_vars*).
|
|
|
|
/// \param CapturedVars A pointer to the record with the references to
|
|
|
|
/// variables used in \a OutlinedFn function.
|
|
|
|
/// \param IfCond Condition in the associated 'if' clause, if it was
|
|
|
|
/// specified, nullptr otherwise.
|
|
|
|
///
|
2018-06-22 04:26:33 +08:00
|
|
|
void emitSPMDParallelCall(CodeGenFunction &CGF, SourceLocation Loc,
|
2017-01-19 03:35:00 +08:00
|
|
|
llvm::Value *OutlinedFn,
|
|
|
|
ArrayRef<llvm::Value *> CapturedVars,
|
|
|
|
const Expr *IfCond);
|
|
|
|
|
2017-01-10 23:42:51 +08:00
|
|
|
protected:
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Get the function name of an outlined region.
|
2017-01-10 23:42:51 +08:00
|
|
|
// The name can be customized depending on the target.
|
|
|
|
//
|
|
|
|
StringRef getOutlinedHelperName() const override {
|
|
|
|
return "__omp_outlined__";
|
|
|
|
}
|
|
|
|
|
2018-11-22 05:04:34 +08:00
|
|
|
/// Check if the default location must be constant.
|
|
|
|
/// Constant for NVPTX for better optimization.
|
|
|
|
bool isDefaultLocationConstant() const override { return true; }
|
|
|
|
|
|
|
|
/// Returns additional flags that can be stored in reserved_2 field of the
|
|
|
|
/// default location.
|
|
|
|
/// For NVPTX target contains data about SPMD/Non-SPMD execution mode +
|
|
|
|
/// Full/Lightweight runtime mode. Used for better optimization.
|
|
|
|
unsigned getDefaultLocationReserved2Flags() const override;
|
|
|
|
|
2016-02-08 23:59:20 +08:00
|
|
|
public:
|
|
|
|
explicit CGOpenMPRuntimeNVPTX(CodeGenModule &CGM);
|
2018-11-02 22:54:07 +08:00
|
|
|
void clear() override;
|
2016-04-04 23:55:02 +08:00
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Emit call to void __kmpc_push_proc_bind(ident_t *loc, kmp_int32
|
2017-01-26 00:55:10 +08:00
|
|
|
/// global_tid, int proc_bind) to generate code for 'proc_bind' clause.
|
|
|
|
virtual void emitProcBindClause(CodeGenFunction &CGF,
|
|
|
|
OpenMPProcBindClauseKind ProcBind,
|
|
|
|
SourceLocation Loc) override;
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Emits call to void __kmpc_push_num_threads(ident_t *loc, kmp_int32
|
2017-01-25 09:18:34 +08:00
|
|
|
/// global_tid, kmp_int32 num_threads) to generate code for 'num_threads'
|
|
|
|
/// clause.
|
|
|
|
/// \param NumThreads An integer value of threads.
|
|
|
|
virtual void emitNumThreadsClause(CodeGenFunction &CGF,
|
|
|
|
llvm::Value *NumThreads,
|
|
|
|
SourceLocation Loc) override;
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// This function ought to emit, in the general case, a call to
|
2016-04-04 23:55:02 +08:00
|
|
|
// the openmp runtime kmpc_push_num_teams. In NVPTX backend it is not needed
|
|
|
|
// as these numbers are obtained through the PTX grid and block configuration.
|
|
|
|
/// \param NumTeams An integer expression of teams.
|
|
|
|
/// \param ThreadLimit An integer expression of threads.
|
|
|
|
void emitNumTeamsClause(CodeGenFunction &CGF, const Expr *NumTeams,
|
|
|
|
const Expr *ThreadLimit, SourceLocation Loc) override;
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Emits inlined function for the specified OpenMP parallel
|
2017-01-19 02:18:53 +08:00
|
|
|
// directive.
|
2016-04-04 23:55:02 +08:00
|
|
|
/// \a D. This outlined function has type void(*)(kmp_int32 *ThreadID,
|
|
|
|
/// kmp_int32 BoundID, struct context_vars*).
|
|
|
|
/// \param D OpenMP directive.
|
|
|
|
/// \param ThreadIDVar Variable for thread id in the current OpenMP region.
|
|
|
|
/// \param InnermostKind Kind of innermost directive (for simple directives it
|
|
|
|
/// is a directive itself, for combined - its innermost directive).
|
|
|
|
/// \param CodeGen Code generation sequence for the \a D directive.
|
|
|
|
llvm::Value *
|
2017-01-19 02:18:53 +08:00
|
|
|
emitParallelOutlinedFunction(const OMPExecutableDirective &D,
|
|
|
|
const VarDecl *ThreadIDVar,
|
|
|
|
OpenMPDirectiveKind InnermostKind,
|
|
|
|
const RegionCodeGenTy &CodeGen) override;
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Emits inlined function for the specified OpenMP teams
|
2017-01-19 02:18:53 +08:00
|
|
|
// directive.
|
|
|
|
/// \a D. This outlined function has type void(*)(kmp_int32 *ThreadID,
|
|
|
|
/// kmp_int32 BoundID, struct context_vars*).
|
|
|
|
/// \param D OpenMP directive.
|
|
|
|
/// \param ThreadIDVar Variable for thread id in the current OpenMP region.
|
|
|
|
/// \param InnermostKind Kind of innermost directive (for simple directives it
|
|
|
|
/// is a directive itself, for combined - its innermost directive).
|
|
|
|
/// \param CodeGen Code generation sequence for the \a D directive.
|
|
|
|
llvm::Value *
|
|
|
|
emitTeamsOutlinedFunction(const OMPExecutableDirective &D,
|
|
|
|
const VarDecl *ThreadIDVar,
|
|
|
|
OpenMPDirectiveKind InnermostKind,
|
|
|
|
const RegionCodeGenTy &CodeGen) override;
|
2016-04-04 23:55:02 +08:00
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Emits code for teams call of the \a OutlinedFn with
|
2016-04-04 23:55:02 +08:00
|
|
|
/// variables captured in a record which address is stored in \a
|
|
|
|
/// CapturedStruct.
|
|
|
|
/// \param OutlinedFn Outlined function to be run by team masters. Type of
|
|
|
|
/// this function is void(*)(kmp_int32 *, kmp_int32, struct context_vars*).
|
|
|
|
/// \param CapturedVars A pointer to the record with the references to
|
|
|
|
/// variables used in \a OutlinedFn function.
|
|
|
|
///
|
|
|
|
void emitTeamsCall(CodeGenFunction &CGF, const OMPExecutableDirective &D,
|
|
|
|
SourceLocation Loc, llvm::Value *OutlinedFn,
|
|
|
|
ArrayRef<llvm::Value *> CapturedVars) override;
|
2017-01-10 23:42:51 +08:00
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Emits code for parallel or serial call of the \a OutlinedFn with
|
2017-01-10 23:42:51 +08:00
|
|
|
/// variables captured in a record which address is stored in \a
|
|
|
|
/// CapturedStruct.
|
|
|
|
/// \param OutlinedFn Outlined function to be run in parallel threads. Type of
|
|
|
|
/// this function is void(*)(kmp_int32 *, kmp_int32, struct context_vars*).
|
|
|
|
/// \param CapturedVars A pointer to the record with the references to
|
|
|
|
/// variables used in \a OutlinedFn function.
|
|
|
|
/// \param IfCond Condition in the associated 'if' clause, if it was
|
|
|
|
/// specified, nullptr otherwise.
|
|
|
|
void emitParallelCall(CodeGenFunction &CGF, SourceLocation Loc,
|
|
|
|
llvm::Value *OutlinedFn,
|
|
|
|
ArrayRef<llvm::Value *> CapturedVars,
|
|
|
|
const Expr *IfCond) override;
|
2017-01-19 03:35:00 +08:00
|
|
|
|
2018-12-04 23:03:25 +08:00
|
|
|
/// Emit an implicit/explicit barrier for OpenMP threads.
|
|
|
|
/// \param Kind Directive for which this implicit barrier call must be
|
|
|
|
/// generated. Must be OMPD_barrier for explicit barrier generation.
|
|
|
|
/// \param EmitChecks true if need to emit checks for cancellation barriers.
|
|
|
|
/// \param ForceSimpleCall true simple barrier call must be emitted, false if
|
|
|
|
/// runtime class decides which one to emit (simple or with cancellation
|
|
|
|
/// checks).
|
|
|
|
///
|
|
|
|
void emitBarrierCall(CodeGenFunction &CGF, SourceLocation Loc,
|
|
|
|
OpenMPDirectiveKind Kind, bool EmitChecks = true,
|
|
|
|
bool ForceSimpleCall = false) override;
|
|
|
|
|
2018-05-08 01:23:05 +08:00
|
|
|
/// Emits a critical region.
|
|
|
|
/// \param CriticalName Name of the critical region.
|
|
|
|
/// \param CriticalOpGen Generator for the statement associated with the given
|
|
|
|
/// critical region.
|
|
|
|
/// \param Hint Value of the 'hint' clause (optional).
|
|
|
|
void emitCriticalRegion(CodeGenFunction &CGF, StringRef CriticalName,
|
|
|
|
const RegionCodeGenTy &CriticalOpGen,
|
|
|
|
SourceLocation Loc,
|
|
|
|
const Expr *Hint = nullptr) override;
|
|
|
|
|
2017-02-17 00:20:16 +08:00
|
|
|
/// Emit a code for reduction clause.
|
|
|
|
///
|
|
|
|
/// \param Privates List of private copies for original reduction arguments.
|
|
|
|
/// \param LHSExprs List of LHS in \a ReductionOps reduction operations.
|
|
|
|
/// \param RHSExprs List of RHS in \a ReductionOps reduction operations.
|
|
|
|
/// \param ReductionOps List of reduction operations in form 'LHS binop RHS'
|
|
|
|
/// or 'operator binop(LHS, RHS)'.
|
|
|
|
/// \param Options List of options for reduction codegen:
|
|
|
|
/// WithNowait true if parent directive has also nowait clause, false
|
|
|
|
/// otherwise.
|
|
|
|
/// SimpleReduction Emit reduction operation only. Used for omp simd
|
|
|
|
/// directive on the host.
|
|
|
|
/// ReductionKind The kind of reduction to perform.
|
|
|
|
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;
|
|
|
|
|
|
|
|
/// Returns specified OpenMP runtime function for the current OpenMP
|
|
|
|
/// implementation. Specialized for the NVPTX device.
|
|
|
|
/// \param Function OpenMP runtime function.
|
|
|
|
/// \return Specified function.
|
|
|
|
llvm::Constant *createNVPTXRuntimeFunction(unsigned Function);
|
|
|
|
|
2017-08-09 02:04:06 +08:00
|
|
|
/// Translates the native parameter of outlined function if this is required
|
|
|
|
/// for target.
|
2018-04-06 23:14:32 +08:00
|
|
|
/// \param FD Field decl from captured record for the parameter.
|
2017-08-09 02:04:06 +08:00
|
|
|
/// \param NativeParam Parameter itself.
|
|
|
|
const VarDecl *translateParameter(const FieldDecl *FD,
|
|
|
|
const VarDecl *NativeParam) const override;
|
|
|
|
|
|
|
|
/// Gets the address of the native argument basing on the address of the
|
|
|
|
/// target-specific parameter.
|
|
|
|
/// \param NativeParam Parameter itself.
|
|
|
|
/// \param TargetParam Corresponding target-specific parameter.
|
|
|
|
Address getParameterAddress(CodeGenFunction &CGF, const VarDecl *NativeParam,
|
|
|
|
const VarDecl *TargetParam) const override;
|
|
|
|
|
|
|
|
/// Emits call of the outlined function with the provided arguments,
|
|
|
|
/// translating these arguments to correct target-specific arguments.
|
|
|
|
void emitOutlinedFunctionCall(
|
2017-08-14 23:01:03 +08:00
|
|
|
CodeGenFunction &CGF, SourceLocation Loc, llvm::Value *OutlinedFn,
|
2017-08-09 02:04:06 +08:00
|
|
|
ArrayRef<llvm::Value *> Args = llvm::None) const override;
|
|
|
|
|
2018-03-14 22:17:45 +08:00
|
|
|
/// Emits OpenMP-specific function prolog.
|
|
|
|
/// Required for device constructs.
|
|
|
|
void emitFunctionProlog(CodeGenFunction &CGF, const Decl *D) override;
|
|
|
|
|
|
|
|
/// Gets the OpenMP-specific address of the local variable.
|
|
|
|
Address getAddressOfLocalVariable(CodeGenFunction &CGF,
|
|
|
|
const VarDecl *VD) override;
|
|
|
|
|
2018-05-07 22:50:05 +08:00
|
|
|
/// Target codegen is specialized based on two data-sharing modes: CUDA, in
|
|
|
|
/// which the local variables are actually global threadlocal, and Generic, in
|
|
|
|
/// which the local variables are placed in global memory if they may escape
|
|
|
|
/// their declaration context.
|
|
|
|
enum DataSharingMode {
|
|
|
|
/// CUDA data sharing mode.
|
|
|
|
CUDA,
|
|
|
|
/// Generic data-sharing mode.
|
2017-01-19 03:35:00 +08:00
|
|
|
Generic,
|
|
|
|
};
|
|
|
|
|
2018-03-14 22:17:45 +08:00
|
|
|
/// Cleans up references to the objects in finished function.
|
|
|
|
///
|
|
|
|
void functionFinished(CodeGenFunction &CGF) override;
|
|
|
|
|
2018-09-28 04:29:00 +08:00
|
|
|
/// Choose a default value for the dist_schedule clause.
|
2018-09-28 03:22:56 +08:00
|
|
|
void getDefaultDistScheduleAndChunk(CodeGenFunction &CGF,
|
|
|
|
const OMPLoopDirective &S, OpenMPDistScheduleClauseKind &ScheduleKind,
|
|
|
|
llvm::Value *&Chunk) const override;
|
|
|
|
|
2018-09-28 04:29:00 +08:00
|
|
|
/// Choose a default value for the schedule clause.
|
|
|
|
void getDefaultScheduleAndChunk(CodeGenFunction &CGF,
|
|
|
|
const OMPLoopDirective &S, OpenMPScheduleClauseKind &ScheduleKind,
|
2018-10-29 23:45:47 +08:00
|
|
|
const Expr *&ChunkExpr) const override;
|
2018-09-28 04:29:00 +08:00
|
|
|
|
2018-10-30 23:50:12 +08:00
|
|
|
/// Adjust some parameters for the target-based directives, like addresses of
|
|
|
|
/// the variables captured by reference in lambdas.
|
|
|
|
void adjustTargetSpecificDataForLambdas(
|
|
|
|
CodeGenFunction &CGF, const OMPExecutableDirective &D) const override;
|
|
|
|
|
2018-11-19 23:09:33 +08:00
|
|
|
/// Perform check on requires decl to ensure that target architecture
|
|
|
|
/// supports unified addressing
|
|
|
|
void checkArchForUnifiedAddressing(CodeGenModule &CGM,
|
|
|
|
const OMPRequiresDecl *D) const override;
|
|
|
|
|
2017-01-19 03:35:00 +08:00
|
|
|
private:
|
2018-05-07 22:50:05 +08:00
|
|
|
/// Track the execution mode when codegening directives within a target
|
|
|
|
/// region. The appropriate mode (SPMD/NON-SPMD) is set on entry to the
|
|
|
|
/// target region and used by containing directives such as 'parallel'
|
|
|
|
/// to emit optimized code.
|
2018-05-11 02:32:08 +08:00
|
|
|
ExecutionMode CurrentExecutionMode = EM_Unknown;
|
2018-05-07 22:50:05 +08:00
|
|
|
|
2018-11-27 02:37:09 +08:00
|
|
|
/// Check if the full runtime is required (default - yes).
|
|
|
|
bool RequiresFullRuntime = true;
|
|
|
|
|
2018-05-07 22:50:05 +08:00
|
|
|
/// true if we're emitting the code for the target region and next parallel
|
|
|
|
/// region is L0 for sure.
|
|
|
|
bool IsInTargetMasterThreadRegion = false;
|
2018-10-13 04:19:59 +08:00
|
|
|
/// true if currently emitting code for target/teams/distribute region, false
|
|
|
|
/// - otherwise.
|
|
|
|
bool IsInTTDRegion = false;
|
2018-05-07 22:50:05 +08:00
|
|
|
/// true if we're definitely in the parallel region.
|
|
|
|
bool IsInParallelRegion = false;
|
2018-03-14 22:17:45 +08:00
|
|
|
|
|
|
|
/// Map between an outlined function and its wrapper.
|
|
|
|
llvm::DenseMap<llvm::Function *, llvm::Function *> WrapperFunctionsMap;
|
|
|
|
|
|
|
|
/// Emit function which wraps the outline parallel region
|
|
|
|
/// and controls the parameters which are passed to this function.
|
|
|
|
/// The wrapper ensures that the outlined function is called
|
|
|
|
/// with the correct arguments when data is shared.
|
|
|
|
llvm::Function *createParallelDataSharingWrapper(
|
|
|
|
llvm::Function *OutlinedParallelFn, const OMPExecutableDirective &D);
|
|
|
|
|
2018-10-09 22:49:00 +08:00
|
|
|
/// The data for the single globalized variable.
|
|
|
|
struct MappedVarData {
|
|
|
|
/// Corresponding field in the global record.
|
2018-10-13 00:04:20 +08:00
|
|
|
const FieldDecl *FD = nullptr;
|
2018-10-09 22:49:00 +08:00
|
|
|
/// Corresponding address.
|
|
|
|
Address PrivateAddr = Address::invalid();
|
|
|
|
/// true, if only one element is required (for latprivates in SPMD mode),
|
|
|
|
/// false, if need to create based on the warp-size.
|
|
|
|
bool IsOnePerTeam = false;
|
|
|
|
MappedVarData() = delete;
|
|
|
|
MappedVarData(const FieldDecl *FD, bool IsOnePerTeam = false)
|
|
|
|
: FD(FD), IsOnePerTeam(IsOnePerTeam) {}
|
|
|
|
};
|
2018-03-14 22:17:45 +08:00
|
|
|
/// The map of local variables to their addresses in the global memory.
|
2018-10-09 22:49:00 +08:00
|
|
|
using DeclToAddrMapTy = llvm::MapVector<const Decl *, MappedVarData>;
|
2018-03-16 02:10:54 +08:00
|
|
|
/// Set of the parameters passed by value escaping OpenMP context.
|
|
|
|
using EscapedParamsTy = llvm::SmallPtrSet<const Decl *, 4>;
|
|
|
|
struct FunctionData {
|
|
|
|
DeclToAddrMapTy LocalVarData;
|
2018-10-13 00:04:20 +08:00
|
|
|
llvm::Optional<DeclToAddrMapTy> SecondaryLocalVarData = llvm::None;
|
2018-03-20 22:45:59 +08:00
|
|
|
EscapedParamsTy EscapedParameters;
|
|
|
|
llvm::SmallVector<const ValueDecl*, 4> EscapedVariableLengthDecls;
|
|
|
|
llvm::SmallVector<llvm::Value *, 4> EscapedVariableLengthDeclsAddrs;
|
2018-03-16 02:10:54 +08:00
|
|
|
const RecordDecl *GlobalRecord = nullptr;
|
2018-10-13 00:04:20 +08:00
|
|
|
llvm::Optional<const RecordDecl *> SecondaryGlobalRecord = llvm::None;
|
2018-03-16 02:10:54 +08:00
|
|
|
llvm::Value *GlobalRecordAddr = nullptr;
|
2018-08-30 02:32:21 +08:00
|
|
|
llvm::Value *IsInSPMDModeFlag = nullptr;
|
2018-03-16 02:10:54 +08:00
|
|
|
std::unique_ptr<CodeGenFunction::OMPMapVars> MappedParams;
|
|
|
|
};
|
2018-03-14 22:17:45 +08:00
|
|
|
/// Maps the function to the list of the globalized variables with their
|
|
|
|
/// addresses.
|
2018-03-16 02:10:54 +08:00
|
|
|
llvm::SmallDenseMap<llvm::Function *, FunctionData> FunctionGlobalizedDecls;
|
2018-11-02 22:54:07 +08:00
|
|
|
/// List of records for the globalized variables in target/teams/distribute
|
|
|
|
/// contexts. Inner records are going to be joined into the single record,
|
|
|
|
/// while those resulting records are going to be joined into the single
|
|
|
|
/// union. This resulting union (one per CU) is the entry point for the static
|
|
|
|
/// memory management runtime functions.
|
|
|
|
struct GlobalPtrSizeRecsTy {
|
2018-11-10 00:18:04 +08:00
|
|
|
llvm::GlobalVariable *UseSharedMemory = nullptr;
|
2018-11-02 22:54:07 +08:00
|
|
|
llvm::GlobalVariable *RecSize = nullptr;
|
2018-11-10 00:18:04 +08:00
|
|
|
llvm::GlobalVariable *Buffer = nullptr;
|
|
|
|
SourceLocation Loc;
|
2018-11-02 22:54:07 +08:00
|
|
|
llvm::SmallVector<const RecordDecl *, 2> Records;
|
|
|
|
unsigned RegionCounter = 0;
|
|
|
|
};
|
|
|
|
llvm::SmallVector<GlobalPtrSizeRecsTy, 8> GlobalizedRecords;
|
|
|
|
/// Shared pointer for the global memory in the global memory buffer used for
|
|
|
|
/// the given kernel.
|
|
|
|
llvm::GlobalVariable *KernelStaticGlobalized = nullptr;
|
2018-11-17 03:38:21 +08:00
|
|
|
/// Pair of the Non-SPMD team and all reductions variables in this team
|
|
|
|
/// region.
|
|
|
|
std::pair<const Decl *, llvm::SmallVector<const ValueDecl *, 4>>
|
|
|
|
TeamAndReductions;
|
2016-02-08 23:59:20 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // CodeGen namespace.
|
|
|
|
} // clang namespace.
|
|
|
|
|
|
|
|
#endif // LLVM_CLANG_LIB_CODEGEN_CGOPENMPRUNTIMENVPTX_H
|