[OPENMP][NVPTX]Emit service debug variable for NVPTX.

In case of the empty module, the ptxas tool may emit error message about
empty debug info sections. This patch fixes this bug.

llvm-svn: 352421
diff --git a/clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp b/clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
index c123304..788fa83 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
@@ -4494,6 +4494,20 @@
 }
 
 void CGOpenMPRuntimeNVPTX::clear() {
+  if (CGDebugInfo *DI = CGM.getModuleDebugInfo())
+    if (CGM.getCodeGenOpts().getDebugInfo() >=
+        codegenoptions::LimitedDebugInfo) {
+      ASTContext &C = CGM.getContext();
+      auto *VD = VarDecl::Create(
+          C, C.getTranslationUnitDecl(), SourceLocation(), SourceLocation(),
+          &C.Idents.get("_$_"), C.IntTy, /*TInfo=*/nullptr, SC_Static);
+      auto *Var = cast<llvm::GlobalVariable>(
+          CGM.CreateRuntimeVariable(CGM.IntTy, "_$_"));
+      Var->setInitializer(llvm::ConstantInt::getNullValue(CGM.IntTy));
+      Var->setLinkage(llvm::GlobalVariable::CommonLinkage);
+      CGM.addCompilerUsedGlobal(Var);
+      DI->EmitGlobalVariable(Var, VD);
+    }
   if (!GlobalizedRecords.empty()) {
     ASTContext &C = CGM.getContext();
     llvm::SmallVector<const GlobalPtrSizeRecsTy *, 4> GlobalRecs;