From 8387021d215b1b4223b3ae5626a9b6f31e3eab6f Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Wed, 22 Oct 2014 19:34:33 +0000 Subject: [PATCH] DebugInfo: Omit scopes in -gmlt to reduce metadata size (on disk and in memory) I haven't done any actual impact analysis of this change as it's a strict improvement, but I'd be curious to know how much it helps. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@220408 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGDebugInfo.cpp | 19 ++++++++++++++----- test/CodeGen/debug-info-scope.c | 12 ++++++++++++ test/CodeGenCXX/debug-info-scope.cpp | 6 +++--- test/CodeGenObjC/catch-lexical-block.m | 2 +- 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index 489a203272..0d662372a1 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -2606,13 +2606,16 @@ void CGDebugInfo::EmitLexicalBlockStart(CGBuilderTy &Builder, // Set our current location. setLocation(Loc); - // Create a new lexical block and push it on the stack. - CreateLexicalBlock(Loc); - // Emit a line table change for the current location inside the new scope. Builder.SetCurrentDebugLocation(llvm::DebugLoc::get(getLineNumber(Loc), getColumnNumber(Loc), LexicalBlockStack.back())); + + if (DebugKind <= CodeGenOptions::DebugLineTablesOnly) + return; + + // Create a new lexical block and push it on the stack. + CreateLexicalBlock(Loc); } /// EmitLexicalBlockEnd - Constructs the debug code for exiting a declarative @@ -2624,6 +2627,9 @@ void CGDebugInfo::EmitLexicalBlockEnd(CGBuilderTy &Builder, // Provide an entry in the line table for the end of the block. EmitLocation(Builder, Loc); + if (DebugKind <= CodeGenOptions::DebugLineTablesOnly) + return; + LexicalBlockStack.pop_back(); } @@ -2634,8 +2640,11 @@ void CGDebugInfo::EmitFunctionEnd(CGBuilderTy &Builder) { assert(RCount <= LexicalBlockStack.size() && "Region stack mismatch"); // Pop all regions for this function. - while (LexicalBlockStack.size() != RCount) - EmitLexicalBlockEnd(Builder, CurLoc); + while (LexicalBlockStack.size() != RCount) { + // Provide an entry in the line table for the end of the block. + EmitLocation(Builder, CurLoc); + LexicalBlockStack.pop_back(); + } FnBeginRegionCount.pop_back(); } diff --git a/test/CodeGen/debug-info-scope.c b/test/CodeGen/debug-info-scope.c index 9decaeafd5..d84fafd018 100644 --- a/test/CodeGen/debug-info-scope.c +++ b/test/CodeGen/debug-info-scope.c @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -g -emit-llvm < %s | FileCheck %s +// RUN: %clang_cc1 -gline-tables-only -emit-llvm < %s | FileCheck --check-prefix=GMLT %s // Two variables with same name in separate scope. // Radar 8330217. int main() { @@ -6,10 +7,21 @@ int main() { int k = 0; // CHECK: DW_TAG_auto_variable ] [i] // CHECK-NEXT: DW_TAG_lexical_block + +// FIXME: Looks like we don't actually need both these lexical blocks (disc 2 +// just refers to disc 1, nothing actually uses disc 2). +// GMLT-NOT: DW_TAG_lexical_block +// GMLT: "0xb\002", {{.*}}} ; [ DW_TAG_lexical_block ] +// GMLT-NOT: DW_TAG_lexical_block +// GMLT: "0xb\001", {{.*}}} ; [ DW_TAG_lexical_block ] +// Make sure we don't have any more lexical blocks because we don't need them in +// -gmlt. +// GMLT-NOT: DW_TAG_lexical_block for (int i = 0; i < 10; i++) j++; // CHECK: DW_TAG_auto_variable ] [i] // CHECK-NEXT: DW_TAG_lexical_block +// GMLT-NOT: DW_TAG_lexical_block for (int i = 0; i < 10; i++) k++; return 0; diff --git a/test/CodeGenCXX/debug-info-scope.cpp b/test/CodeGenCXX/debug-info-scope.cpp index 6fd628cfe4..8957e60d7c 100644 --- a/test/CodeGenCXX/debug-info-scope.cpp +++ b/test/CodeGenCXX/debug-info-scope.cpp @@ -39,9 +39,9 @@ void func() { // FIXME: Do not include scopes that have only other scopes (and no variables // or using declarations) as direct children, they just waste // space/relocations/etc. - // CHECK: [[FOR_BODY:![0-9]+]] = metadata !{metadata !"0xb\00[[@LINE-4]]\00{{.*}}", metadata !{{[0-9]+}}, metadata [[FOR]]} ; [ DW_TAG_lexical_block ] - // CHECK: = metadata !{metadata !"0x100\00{{.*}}", metadata [[FOR_COMPOUND:![0-9]*]], {{.*}} ; [ DW_TAG_auto_variable ] [b] [line [[@LINE+2]]] - // CHECK: [[FOR_COMPOUND]] = metadata !{metadata !"0xb\00[[@LINE-6]]\00{{.*}}", metadata !{{[0-9]+}}, metadata [[FOR_BODY]]} ; [ DW_TAG_lexical_block ] + // CHECK: = metadata !{metadata !"0x100\00{{.*}}", metadata [[FOR_COMPOUND:![0-9]*]], {{.*}} ; [ DW_TAG_auto_variable ] [b] [line [[@LINE+3]]] + // CHECK: [[FOR_COMPOUND]] = metadata !{metadata !"0xb\00[[@LINE-5]]\00{{.*}}", metadata !{{[0-9]+}}, metadata [[FOR_BODY:![0-9]+]]} ; [ DW_TAG_lexical_block ] + // CHECK: [[FOR_BODY]] = metadata !{metadata !"0xb\00[[@LINE-6]]\00{{.*}}", metadata !{{[0-9]+}}, metadata [[FOR]]} ; [ DW_TAG_lexical_block ] bool b = i % 2; } diff --git a/test/CodeGenObjC/catch-lexical-block.m b/test/CodeGenObjC/catch-lexical-block.m index 618d3a2232..d5aeee143b 100644 --- a/test/CodeGenObjC/catch-lexical-block.m +++ b/test/CodeGenObjC/catch-lexical-block.m @@ -10,6 +10,6 @@ void f0() { // We should have 3 lexical blocks here at the moment, including one // for the catch block. // CHECK: lexical_block -// CHECK: lexical_block // CHECK: auto_variable // CHECK: lexical_block +// CHECK: lexical_block -- 2.40.0