]> granicus.if.org Git - clang/commitdiff
[OPENMP][NVPTX]Emit service debug variable for NVPTX.
authorAlexey Bataev <a.bataev@hotmail.com>
Mon, 28 Jan 2019 20:03:02 +0000 (20:03 +0000)
committerAlexey Bataev <a.bataev@hotmail.com>
Mon, 28 Jan 2019 20:03:02 +0000 (20:03 +0000)
In case of the empty module, the ptxas tool may emit error message about
empty debug info sections. This patch fixes this bug.

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

lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
test/OpenMP/nvptx_target_firstprivate_codegen.cpp

index c1233044cd60e3df7ee20ffb167c44d392df4c5b..788fa83ea053a48c07fe893d968ecbb859994ba2 100644 (file)
@@ -4494,6 +4494,20 @@ static std::pair<unsigned, unsigned> getSMsBlocksPerSM(CodeGenModule &CGM) {
 }
 
 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;
index 53b0f758852c2420b3119cfd94e5041357aacda4..8ffc08294aa9b31bf7ab417a6eb415b7f3fa96f3 100644 (file)
@@ -16,6 +16,7 @@ struct TT {
 // TCHECK:  [[TT:%.+]] = type { i64, i8 }
 // TCHECK:  [[S1:%.+]] = type { double }
 
+// TCHECK: @{{.*}}_$_{{.*}} = common global i32 0, !dbg !{{[0-9]+}}
 int foo(int n, double *ptr) {
   int a = 0;
   short aa = 0;