diff options
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r-- | clang/lib/CodeGen/CGOpenMPRuntime.cpp | 19 | ||||
-rw-r--r-- | clang/lib/CodeGen/CGOpenMPRuntime.h | 6 | ||||
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 4 |
3 files changed, 28 insertions, 1 deletions
diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp index 4d9f495c16e..168504ccaf7 100644 --- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -8106,7 +8106,12 @@ bool CGOpenMPRuntime::emitTargetGlobalVariable(GlobalDecl GD) { // Do not to emit variable if it is not marked as declare target. llvm::Optional<OMPDeclareTargetDeclAttr::MapTypeTy> Res = isDeclareTargetDeclaration(cast<VarDecl>(GD.getDecl())); - return !Res || *Res == OMPDeclareTargetDeclAttr::MT_Link; + if (!Res || *Res == OMPDeclareTargetDeclAttr::MT_Link) { + if (CGM.getContext().DeclMustBeEmitted(GD.getDecl())) + DeferredGlobalVariables.insert(cast<VarDecl>(GD.getDecl())); + return true; + } + return false; } void CGOpenMPRuntime::registerTargetGlobalVariable(const VarDecl *VD, @@ -8163,6 +8168,18 @@ bool CGOpenMPRuntime::emitTargetGlobal(GlobalDecl GD) { return emitTargetGlobalVariable(GD); } +void CGOpenMPRuntime::emitDeferredTargetDecls() const { + for (const VarDecl *VD : DeferredGlobalVariables) { + llvm::Optional<OMPDeclareTargetDeclAttr::MapTypeTy> Res = + isDeclareTargetDeclaration(VD); + if (Res) { + assert(*Res != OMPDeclareTargetDeclAttr::MT_Link && + "Implicit declare target variables must be only to()."); + CGM.EmitGlobal(VD); + } + } +} + CGOpenMPRuntime::DisableAutoDeclareTargetRAII::DisableAutoDeclareTargetRAII( CodeGenModule &CGM) : CGM(CGM) { diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.h b/clang/lib/CodeGen/CGOpenMPRuntime.h index 01ff0c20fd6..ed2b56b5448 100644 --- a/clang/lib/CodeGen/CGOpenMPRuntime.h +++ b/clang/lib/CodeGen/CGOpenMPRuntime.h @@ -602,6 +602,10 @@ private: bool ShouldMarkAsGlobal = true; llvm::SmallDenseSet<const FunctionDecl *> AlreadyEmittedTargetFunctions; + /// List of variables that can become declare target implicitly and, thus, + /// must be emitted. + llvm::SmallDenseSet<const VarDecl *> DeferredGlobalVariables; + /// Creates and registers offloading binary descriptor for the current /// compilation unit. The function that does the registration is returned. llvm::Function *createOffloadingBinaryDescriptorRegistration(); @@ -1509,6 +1513,8 @@ public: /// true, if it was marked already, and false, otherwise. bool markAsGlobalTarget(GlobalDecl GD); + /// Emit deferred declare target variables marked for deferred emission. + void emitDeferredTargetDecls() const; }; /// Class supports emissionof SIMD-only code. diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 8c5e0df0969..dedd57efbd9 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -1747,6 +1747,10 @@ void CodeGenModule::EmitModuleLinkOptions() { } void CodeGenModule::EmitDeferred() { + // Emit deferred declare target declarations. + if (getLangOpts().OpenMP && !getLangOpts().OpenMPSimd) + getOpenMPRuntime().emitDeferredTargetDecls(); + // Emit code for any potentially referenced deferred decls. Since a // previously unused static decl may become used during the generation of code // for a static function, iterate until no changes are made. |