Skip to content

Commit

Permalink
[OpenMP] Base support for target directive codegen on NVPTX device.
Browse files Browse the repository at this point in the history
Summary:
This patch adds base support for codegen of the target directive on the NVPTX device.

Reviewers: ABataev

Differential Revision: http://reviews.llvm.org/D17877

Reworked test case after buildbot failure on windows.
Updated patch to integrate r263837 and test case nvptx_target_firstprivate_codegen.cpp.

llvm-svn: 264018
  • Loading branch information
arpith-jacob committed Mar 22, 2016
1 parent f2be78c commit 5c309e4
Show file tree
Hide file tree
Showing 5 changed files with 1,052 additions and 6 deletions.
10 changes: 10 additions & 0 deletions clang/lib/CodeGen/CGOpenMPRuntime.cpp
Expand Up @@ -4182,6 +4182,14 @@ void CGOpenMPRuntime::emitTargetOutlinedFunction(
CGF.EmitStmt(CS.getCapturedStmt());
};

emitTargetOutlinedFunctionHelper(D, ParentName, OutlinedFn, OutlinedFnID,
IsOffloadEntry, CodeGen);
}

void CGOpenMPRuntime::emitTargetOutlinedFunctionHelper(
const OMPExecutableDirective &D, StringRef ParentName,
llvm::Function *&OutlinedFn, llvm::Constant *&OutlinedFnID,
bool IsOffloadEntry, const RegionCodeGenTy &CodeGen) {
// Create a unique name for the entry function using the source location
// information of the current target region. The name will be something like:
//
Expand All @@ -4203,6 +4211,8 @@ void CGOpenMPRuntime::emitTargetOutlinedFunction(
<< llvm::format("_%x_", FileID) << ParentName << "_l" << Line;
}

const CapturedStmt &CS = *cast<CapturedStmt>(D.getAssociatedStmt());

CodeGenFunction CGF(CGM, true);
CGOpenMPTargetRegionInfo CGInfo(CS, CodeGen, EntryFnName);
CodeGenFunction::CGCapturedStmtRAII CapInfoRAII(CGF, &CGInfo);
Expand Down
29 changes: 24 additions & 5 deletions clang/lib/CodeGen/CGOpenMPRuntime.h
Expand Up @@ -49,7 +49,31 @@ class CodeGenModule;
typedef llvm::function_ref<void(CodeGenFunction &)> RegionCodeGenTy;

class CGOpenMPRuntime {
protected:
CodeGenModule &CGM;

/// \brief Creates offloading entry for the provided entry ID \a ID,
/// address \a Addr and size \a Size.
virtual void createOffloadEntry(llvm::Constant *ID, llvm::Constant *Addr,
uint64_t Size);

/// \brief Helper to emit outlined function for 'target' directive.
/// \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 Lambda codegen specific to an accelerator device.
/// An oulined function may not be an entry if, e.g. the if clause always
/// evaluates to false.
virtual void emitTargetOutlinedFunctionHelper(const OMPExecutableDirective &D,
StringRef ParentName,
llvm::Function *&OutlinedFn,
llvm::Constant *&OutlinedFnID,
bool IsOffloadEntry,
const RegionCodeGenTy &CodeGen);

private:
/// \brief Default const ident_t object used for initialization of all other
/// ident_t objects.
llvm::Constant *DefaultOpenMPPSource = nullptr;
Expand Down Expand Up @@ -267,11 +291,6 @@ class CGOpenMPRuntime {
/// compilation unit. The function that does the registration is returned.
llvm::Function *createOffloadingBinaryDescriptorRegistration();

/// \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);

/// \brief Creates all the offload entries in the current compilation unit
/// along with the associated metadata.
void createOffloadEntriesAndInfoMetadata();
Expand Down

0 comments on commit 5c309e4

Please sign in to comment.