Skip to content

Commit

Permalink
[OpenMP 5.0] Codegen support for user-defined mappers.
Browse files Browse the repository at this point in the history
This patch implements the code generation for OpenMP 5.0 declare mapper
(user-defined mapper) constructs. For each declare mapper, a mapper
function is generated. These mapper functions will be called by the
runtime and/or other mapper functions to achieve user defined mapping.

The design slides can be found at
https://github.com/lingda-li/public-sharing/blob/master/mapper_runtime_design.pptx

Re-commit after revert in r367773 because r367755 changed the LLVM-IR
output such that a CHECK line failed.

Patch by Lingda Li <[email protected]>

Differential Revision: https://reviews.llvm.org/D59474

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@367905 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
Meinersbur committed Aug 5, 2019
1 parent 63c73ab commit 4c0e634
Show file tree
Hide file tree
Showing 7 changed files with 887 additions and 87 deletions.
1 change: 1 addition & 0 deletions include/clang/AST/GlobalDecl.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class GlobalDecl {
GlobalDecl(const CapturedDecl *D) { Init(D); }
GlobalDecl(const ObjCMethodDecl *D) { Init(D); }
GlobalDecl(const OMPDeclareReductionDecl *D) { Init(D); }
GlobalDecl(const OMPDeclareMapperDecl *D) { Init(D); }
GlobalDecl(const CXXConstructorDecl *D, CXXCtorType Type) : Value(D, Type) {}
GlobalDecl(const CXXDestructorDecl *D, CXXDtorType Type) : Value(D, Type) {}
GlobalDecl(const VarDecl *D, DynamicInitKind StubKind)
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9860,7 +9860,7 @@ bool ASTContext::DeclMustBeEmitted(const Decl *D) {
return !D->getDeclContext()->isDependentContext();
else if (isa<OMPAllocateDecl>(D))
return !D->getDeclContext()->isDependentContext();
else if (isa<OMPDeclareReductionDecl>(D))
else if (isa<OMPDeclareReductionDecl>(D) || isa<OMPDeclareMapperDecl>(D))
return !D->getDeclContext()->isDependentContext();
else if (isa<ImportDecl>(D))
return true;
Expand Down
7 changes: 4 additions & 3 deletions lib/CodeGen/CGDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2530,10 +2530,11 @@ void CodeGenModule::EmitOMPDeclareReduction(const OMPDeclareReductionDecl *D,
}

void CodeGenModule::EmitOMPDeclareMapper(const OMPDeclareMapperDecl *D,
CodeGenFunction *CGF) {
if (!LangOpts.OpenMP || (!LangOpts.EmitAllDecls && !D->isUsed()))
CodeGenFunction *CGF) {
if (!LangOpts.OpenMP || LangOpts.OpenMPSimd ||
(!LangOpts.EmitAllDecls && !D->isUsed()))
return;
// FIXME: need to implement mapper code generation
getOpenMPRuntime().emitUserDefinedMapper(D, CGF);
}

void CodeGenModule::EmitOMPRequiresDecl(const OMPRequiresDecl *D) {
Expand Down
499 changes: 476 additions & 23 deletions lib/CodeGen/CGOpenMPRuntime.cpp

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions lib/CodeGen/CGOpenMPRuntime.h
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,14 @@ class CGOpenMPRuntime {
SmallVector<const OMPDeclareReductionDecl *, 4>>
FunctionUDRMapTy;
FunctionUDRMapTy FunctionUDRMap;
/// Map from the user-defined mapper declaration to its corresponding
/// functions.
llvm::DenseMap<const OMPDeclareMapperDecl *, llvm::Function *> UDMMap;
/// Map of functions and their local user-defined mappers.
using FunctionUDMMapTy =
llvm::DenseMap<llvm::Function *,
SmallVector<const OMPDeclareMapperDecl *, 4>>;
FunctionUDMMapTy FunctionUDMMap;
/// Type kmp_critical_name, originally defined as typedef kmp_int32
/// kmp_critical_name[8];
llvm::ArrayType *KmpCriticalNameTy;
Expand Down Expand Up @@ -738,6 +746,14 @@ class CGOpenMPRuntime {
llvm::Value *Ctor, llvm::Value *CopyCtor,
llvm::Value *Dtor, SourceLocation Loc);

/// Emit the array initialization or deletion portion for user-defined mapper
/// code generation.
void emitUDMapperArrayInitOrDel(CodeGenFunction &MapperCGF,
llvm::Value *Handle, llvm::Value *BasePtr,
llvm::Value *Ptr, llvm::Value *Size,
llvm::Value *MapType, CharUnits ElementSize,
llvm::BasicBlock *ExitBB, bool IsInit);

struct TaskResultTy {
llvm::Value *NewTask = nullptr;
llvm::Function *TaskEntry = nullptr;
Expand Down Expand Up @@ -798,6 +814,10 @@ class CGOpenMPRuntime {
virtual std::pair<llvm::Function *, llvm::Function *>
getUserDefinedReduction(const OMPDeclareReductionDecl *D);

/// Emit the function for the user defined mapper construct.
void emitUserDefinedMapper(const OMPDeclareMapperDecl *D,
CodeGenFunction *CGF = nullptr);

/// Emits outlined function for the specified OpenMP parallel directive
/// \a D. This outlined function has type void(*)(kmp_int32 *ThreadID,
/// kmp_int32 BoundID, struct context_vars*).
Expand Down
3 changes: 3 additions & 0 deletions lib/CodeGen/ModuleBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ namespace {
if (auto *DRD = dyn_cast<OMPDeclareReductionDecl>(Member)) {
if (Ctx->DeclMustBeEmitted(DRD))
Builder->EmitGlobal(DRD);
} else if (auto *DMD = dyn_cast<OMPDeclareMapperDecl>(Member)) {
if (Ctx->DeclMustBeEmitted(DMD))
Builder->EmitGlobal(DMD);
}
}
}
Expand Down
Loading

0 comments on commit 4c0e634

Please sign in to comment.