]> granicus.if.org Git - clang/commitdiff
[OPENMP] Fix PR38710: static functions are not emitted as implicitly
authorAlexey Bataev <a.bataev@hotmail.com>
Thu, 30 Aug 2018 18:56:11 +0000 (18:56 +0000)
committerAlexey Bataev <a.bataev@hotmail.com>
Thu, 30 Aug 2018 18:56:11 +0000 (18:56 +0000)
'declare target'.

All the functions, referenced in implicit|explicit target regions must
be emitted during code emission for the device.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@341093 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
lib/CodeGen/CGOpenMPRuntimeNVPTX.h
lib/CodeGen/CodeGenModule.cpp
test/OpenMP/declare_target_codegen.cpp

index 9dce947e17a01234b1ce132018a5238dd281c1fc..068ba56ab869e2c12947b38124af1a5c95e2075f 100644 (file)
@@ -1832,7 +1832,8 @@ llvm::Value *CGOpenMPRuntimeNVPTX::emitTeamsOutlinedFunction(
 }
 
 void CGOpenMPRuntimeNVPTX::emitGenericVarsProlog(CodeGenFunction &CGF,
-                                                 SourceLocation Loc) {
+                                                 SourceLocation Loc,
+                                                 bool WithSPMDCheck) {
   if (getDataSharingMode(CGM) != CGOpenMPRuntimeNVPTX::Generic)
     return;
 
@@ -1855,7 +1856,8 @@ void CGOpenMPRuntimeNVPTX::emitGenericVarsProlog(CodeGenFunction &CGF,
     GlobalRecordSize = llvm::alignTo(GlobalRecordSize, Alignment);
 
     llvm::Value *GlobalRecCastAddr;
-    if (getExecutionMode() == CGOpenMPRuntimeNVPTX::EM_Unknown) {
+    if (WithSPMDCheck ||
+        getExecutionMode() == CGOpenMPRuntimeNVPTX::EM_Unknown) {
       llvm::BasicBlock *ExitBB = CGF.createBasicBlock(".exit");
       llvm::BasicBlock *SPMDBB = CGF.createBasicBlock(".spmd");
       llvm::BasicBlock *NonSPMDBB = CGF.createBasicBlock(".non-spmd");
@@ -1963,7 +1965,8 @@ void CGOpenMPRuntimeNVPTX::emitGenericVarsProlog(CodeGenFunction &CGF,
   I->getSecond().MappedParams->apply(CGF);
 }
 
-void CGOpenMPRuntimeNVPTX::emitGenericVarsEpilog(CodeGenFunction &CGF) {
+void CGOpenMPRuntimeNVPTX::emitGenericVarsEpilog(CodeGenFunction &CGF,
+                                                 bool WithSPMDCheck) {
   if (getDataSharingMode(CGM) != CGOpenMPRuntimeNVPTX::Generic)
     return;
 
@@ -1979,7 +1982,8 @@ void CGOpenMPRuntimeNVPTX::emitGenericVarsEpilog(CodeGenFunction &CGF) {
           Addr);
     }
     if (I->getSecond().GlobalRecordAddr) {
-      if (getExecutionMode() == CGOpenMPRuntimeNVPTX::EM_Unknown) {
+      if (WithSPMDCheck ||
+          getExecutionMode() == CGOpenMPRuntimeNVPTX::EM_Unknown) {
         CGBuilderTy &Bld = CGF.Builder;
         llvm::BasicBlock *ExitBB = CGF.createBasicBlock(".exit");
         llvm::BasicBlock *NonSPMDBB = CGF.createBasicBlock(".non-spmd");
@@ -3972,13 +3976,13 @@ void CGOpenMPRuntimeNVPTX::emitFunctionProlog(CodeGenFunction &CGF,
     Data.insert(std::make_pair(VD, std::make_pair(FD, Address::invalid())));
   }
   if (!NeedToDelayGlobalization) {
-    emitGenericVarsProlog(CGF, D->getBeginLoc());
+    emitGenericVarsProlog(CGF, D->getBeginLoc(), /*WithSPMDCheck=*/true);
     struct GlobalizationScope final : EHScopeStack::Cleanup {
       GlobalizationScope() = default;
 
       void Emit(CodeGenFunction &CGF, Flags flags) override {
         static_cast<CGOpenMPRuntimeNVPTX &>(CGF.CGM.getOpenMPRuntime())
-            .emitGenericVarsEpilog(CGF);
+            .emitGenericVarsEpilog(CGF, /*WithSPMDCheck=*/true);
       }
     };
     CGF.EHStack.pushCleanup<GlobalizationScope>(NormalAndEHCleanup);
index 0975eb064187b28c8267f2bae59328793a077eaa..85ed838d473d4af3744fd21fff3847670448c904 100644 (file)
@@ -72,10 +72,11 @@ private:
   void emitNonSPMDEntryFooter(CodeGenFunction &CGF, EntryFunctionState &EST);
 
   /// Helper for generic variables globalization prolog.
-  void emitGenericVarsProlog(CodeGenFunction &CGF, SourceLocation Loc);
+  void emitGenericVarsProlog(CodeGenFunction &CGF, SourceLocation Loc,
+                             bool WithSPMDCheck = false);
 
   /// Helper for generic variables globalization epilog.
-  void emitGenericVarsEpilog(CodeGenFunction &CGF);
+  void emitGenericVarsEpilog(CodeGenFunction &CGF, bool WithSPMDCheck = false);
 
   /// Helper for SPMD mode target directive's entry function.
   void emitSPMDEntryHeader(CodeGenFunction &CGF, EntryFunctionState &EST,
index c5cac6a3982f1734b99928fe470f249cd3590800..51869ef7cbe2d57fa76597c3b2be382666ed1d39 100644 (file)
@@ -2579,17 +2579,16 @@ llvm::Constant *CodeGenModule::GetOrCreateLLVMFunction(
     if (getLangOpts().OpenMPIsDevice && OpenMPRuntime &&
         !OpenMPRuntime->markAsGlobalTarget(GD) && FD->isDefined() &&
         !DontDefer && !IsForDefinition) {
-      if (const FunctionDecl *FDDef = FD->getDefinition())
-        if (getContext().DeclMustBeEmitted(FDDef)) {
-          GlobalDecl GDDef;
-          if (const auto *CD = dyn_cast<CXXConstructorDecl>(FDDef))
-            GDDef = GlobalDecl(CD, GD.getCtorType());
-          else if (const auto *DD = dyn_cast<CXXDestructorDecl>(FDDef))
-            GDDef = GlobalDecl(DD, GD.getDtorType());
-          else
-            GDDef = GlobalDecl(FDDef);
-          addDeferredDeclToEmit(GDDef);
-        }
+      if (const FunctionDecl *FDDef = FD->getDefinition()) {
+        GlobalDecl GDDef;
+        if (const auto *CD = dyn_cast<CXXConstructorDecl>(FDDef))
+          GDDef = GlobalDecl(CD, GD.getCtorType());
+        else if (const auto *DD = dyn_cast<CXXDestructorDecl>(FDDef))
+          GDDef = GlobalDecl(DD, GD.getDtorType());
+        else
+          GDDef = GlobalDecl(FDDef);
+        EmitGlobal(GDDef);
+      }
     }
 
     if (FD->isMultiVersion()) {
index b8f03f7e205f475d8ed9f1fb14c0cf0b45ed7461..1694ec6072ca17a5b56009ce3933a746228f145f 100644 (file)
@@ -78,7 +78,7 @@ public:
 
 int foo();
 
-int baz1();
+static int baz1() { return 0; }
 
 int baz2();