diff options
author | Alexey Bataev <a.bataev@hotmail.com> | 2018-03-15 15:47:20 +0000 |
---|---|---|
committer | Alexey Bataev <a.bataev@hotmail.com> | 2018-03-15 15:47:20 +0000 |
commit | 4f4bf7c3482598c02bea7fbe9bbcca56ac720313 (patch) | |
tree | 9d22d71fca84678cbb814b489d172fb2d714b35d /clang/lib/CodeGen/CGOpenMPRuntime.cpp | |
parent | 1110c4d33675f4351c080e621dbf8ee298ef13ae (diff) | |
download | bcm5719-llvm-4f4bf7c3482598c02bea7fbe9bbcca56ac720313.tar.gz bcm5719-llvm-4f4bf7c3482598c02bea7fbe9bbcca56ac720313.zip |
[OPENMP] Codegen for `omp declare target` construct.
Added initial codegen for device side of declarations inside `omp
declare target` construct + codegen for implicit `declare target`
functions, which are used in the target regions.
llvm-svn: 327636
Diffstat (limited to 'clang/lib/CodeGen/CGOpenMPRuntime.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGOpenMPRuntime.cpp | 54 |
1 files changed, 49 insertions, 5 deletions
diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp index 8c25d206f49..6bbe639f908 100644 --- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -7405,9 +7405,14 @@ bool CGOpenMPRuntime::emitTargetFunctions(GlobalDecl GD) { // Try to detect target regions in the function. scanForTargetRegionsFunctions(FD.getBody(), CGM.getMangledName(GD)); - // We should not emit any function other that the ones created during the - // scanning. Therefore, we signal that this function is completely dealt - // with. + // Do not to emit function if it is not marked as declare target. + if (!GD.getDecl()->hasAttrs()) + return true; + + for (const auto *D = FD.getMostRecentDecl(); D; D = D->getPreviousDecl()) + if (D->hasAttr<OMPDeclareTargetDeclAttr>()) + return false; + return true; } @@ -7433,8 +7438,15 @@ bool CGOpenMPRuntime::emitTargetGlobalVariable(GlobalDecl GD) { } } - // If we are in target mode, we do not emit any global (declare target is not - // implemented yet). Therefore we signal that GD was processed in this case. + // Do not to emit variable if it is not marked as declare target. + if (!GD.getDecl()->hasAttrs()) + return true; + + for (const Decl *D = GD.getDecl()->getMostRecentDecl(); D; + D = D->getPreviousDecl()) + if (D->hasAttr<OMPDeclareTargetDeclAttr>()) + return false; + return true; } @@ -7446,6 +7458,38 @@ bool CGOpenMPRuntime::emitTargetGlobal(GlobalDecl GD) { return emitTargetGlobalVariable(GD); } +CGOpenMPRuntime::DisableAutoDeclareTargetRAII::DisableAutoDeclareTargetRAII( + CodeGenModule &CGM) + : CGM(CGM) { + if (CGM.getLangOpts().OpenMPIsDevice) { + SavedShouldMarkAsGlobal = CGM.getOpenMPRuntime().ShouldMarkAsGlobal; + CGM.getOpenMPRuntime().ShouldMarkAsGlobal = false; + } +} + +CGOpenMPRuntime::DisableAutoDeclareTargetRAII::~DisableAutoDeclareTargetRAII() { + if (CGM.getLangOpts().OpenMPIsDevice) + CGM.getOpenMPRuntime().ShouldMarkAsGlobal = SavedShouldMarkAsGlobal; +} + +bool CGOpenMPRuntime::markAsGlobalTarget(const FunctionDecl *D) { + if (!CGM.getLangOpts().OpenMPIsDevice || !ShouldMarkAsGlobal) + return true; + // Do not to emit function if it is marked as declare target as it was already + // emitted. + for (const auto *FD = D->getMostRecentDecl(); FD; FD = FD->getPreviousDecl()) + if (FD->hasAttr<OMPDeclareTargetDeclAttr>()) + return true; + + const FunctionDecl *FD = D->getCanonicalDecl(); + // Do not mark member functions except for static. + if (const auto *Method = dyn_cast<CXXMethodDecl>(FD)) + if (!Method->isStatic()) + return true; + + return !AlreadyEmittedTargetFunctions.insert(FD).second; +} + llvm::Function *CGOpenMPRuntime::emitRegistrationFunction() { // If we have offloading in the current module, we need to emit the entries // now and register the offloading descriptor. |