diff options
Diffstat (limited to 'clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.h')
-rw-r--r-- | clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.h | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.h b/clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.h index 60bb9acbc7e..b52bae04e0e 100644 --- a/clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.h +++ b/clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.h @@ -16,11 +16,121 @@ #define LLVM_CLANG_LIB_CODEGEN_CGOPENMPRUNTIMENVPTX_H #include "CGOpenMPRuntime.h" +#include "CodeGenFunction.h" +#include "clang/AST/StmtOpenMP.h" +#include "llvm/IR/CallSite.h" namespace clang { namespace CodeGen { class CGOpenMPRuntimeNVPTX : public CGOpenMPRuntime { + // + // NVPTX calls. + // + + /// \brief Get the GPU warp size. + llvm::Value *getNVPTXWarpSize(CodeGenFunction &CGF); + + /// \brief Get the id of the current thread on the GPU. + llvm::Value *getNVPTXThreadID(CodeGenFunction &CGF); + + // \brief Get the maximum number of threads in a block of the GPU. + llvm::Value *getNVPTXNumThreads(CodeGenFunction &CGF); + + /// \brief Get barrier to synchronize all threads in a block. + void getNVPTXCTABarrier(CodeGenFunction &CGF); + + // \brief Synchronize all GPU threads in a block. + void syncCTAThreads(CodeGenFunction &CGF); + + // + // OMP calls. + // + + /// \brief Get the thread id of the OMP master thread. + /// The master thread id is the first thread (lane) of the last warp in the + /// GPU block. Warp size is assumed to be some power of 2. + /// Thread id is 0 indexed. + /// E.g: If NumThreads is 33, master id is 32. + /// If NumThreads is 64, master id is 32. + /// If NumThreads is 1024, master id is 992. + llvm::Value *getMasterThreadID(CodeGenFunction &CGF); + + // + // Private state and methods. + // + + // Master-worker control state. + // Number of requested OMP threads in parallel region. + llvm::GlobalVariable *ActiveWorkers; + // Outlined function for the workers to execute. + llvm::GlobalVariable *WorkID; + + class EntryFunctionState { + public: + llvm::BasicBlock *ExitBB; + + EntryFunctionState() : ExitBB(nullptr){}; + }; + + class WorkerFunctionState { + public: + llvm::Function *WorkerFn; + const CGFunctionInfo *CGFI; + + WorkerFunctionState(CodeGenModule &CGM); + + private: + void createWorkerFunction(CodeGenModule &CGM); + }; + + /// \brief Initialize master-worker control state. + void initializeEnvironment(); + + /// \brief Emit the worker function for the current target region. + void emitWorkerFunction(WorkerFunctionState &WST); + + /// \brief Helper for worker function. Emit body of worker loop. + void emitWorkerLoop(CodeGenFunction &CGF, WorkerFunctionState &WST); + + /// \brief Helper for target entry function. Guide the master and worker + /// threads to their respective locations. + void emitEntryHeader(CodeGenFunction &CGF, EntryFunctionState &EST, + WorkerFunctionState &WST); + + /// \brief Signal termination of OMP execution. + void emitEntryFooter(CodeGenFunction &CGF, EntryFunctionState &EST); + + /// \brief 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); + + // + // Base class overrides. + // + + /// \brief Creates offloading entry for the provided entry ID \a ID, + /// address \a Addr and size \a Size. + void createOffloadEntry(llvm::Constant *ID, llvm::Constant *Addr, + uint64_t Size) override; + + /// \brief Emit outlined function for 'target' directive 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. + void emitTargetOutlinedFunction(const OMPExecutableDirective &D, + StringRef ParentName, + llvm::Function *&OutlinedFn, + llvm::Constant *&OutlinedFnID, + bool IsOffloadEntry) override; + public: explicit CGOpenMPRuntimeNVPTX(CodeGenModule &CGM); }; |