[Lldb-commits] [lldb] 1a3bf29 - [DebugInfo] Switch to using constructor homing (-debug-info-kind=constructor) by default when debug info is enabled

2021-07-26 Thread Amy Huang via lldb-commits

Author: Amy Huang
Date: 2021-07-26T17:24:42-07:00
New Revision: 1a3bf2953a9209fdc4dbb6e99678e02a7fec019d

URL: 
https://github.com/llvm/llvm-project/commit/1a3bf2953a9209fdc4dbb6e99678e02a7fec019d
DIFF: 
https://github.com/llvm/llvm-project/commit/1a3bf2953a9209fdc4dbb6e99678e02a7fec019d.diff

LOG: [DebugInfo] Switch to using constructor homing 
(-debug-info-kind=constructor) by default when debug info is enabled

Constructor homing reduces the amount of class type info that is emitted
by emitting conmplete type info for a class only when a constructor for
that class is emitted.

This will mainly reduce the amount of duplicate debug info in object
files. In Chrome enabling ctor homing decreased total build directory sizes
by about 30%.

It's also expected that some class types (such as unused classes)
will no longer be emitted in the debug info. This is fine, since we wouldn't
expect to need these types when debugging.

In some cases (e.g. libc++, https://reviews.llvm.org/D98750), classes
are used without calling the constructor. Since this is technically
undefined behavior, enabling constructor homing should be fine.
However Clang now has an attribute
`__attribute__((standalone_debug))` that can be used on classes to
ignore ctor homing.

Bug: https://bugs.llvm.org/show_bug.cgi?id=46537

Differential Revision: https://reviews.llvm.org/D106084

Added: 


Modified: 
clang/include/clang/Basic/DebugInfoOptions.h
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/CodeGenCXX/debug-info-template-deduction-guide.cpp
clang/test/Driver/cl-options.c
clang/test/Driver/clang-g-opts.c
clang/test/Driver/cuda-dwarf-2.cu
clang/test/Driver/debug-options-as.c
clang/test/Driver/debug-options.c
clang/test/Driver/integrated-as.s
clang/test/Driver/myriad-toolchain.c
clang/test/Driver/openmp-offload-gpu.c
clang/test/Driver/split-debug.c
lldb/test/Shell/SymbolFile/PDB/Inputs/ClassLayoutTest.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DebugInfoOptions.h 
b/clang/include/clang/Basic/DebugInfoOptions.h
index 7f5669c1760fd..c1259d7797db2 100644
--- a/clang/include/clang/Basic/DebugInfoOptions.h
+++ b/clang/include/clang/Basic/DebugInfoOptions.h
@@ -37,6 +37,7 @@ enum DebugInfoKind {
   /// Limit generated debug info for classes to reduce size. This emits class
   /// type info only where the constructor is emitted, if it is a class that
   /// has a constructor.
+  /// FIXME: Consider combining this with LimitedDebugInfo.
   DebugInfoConstructor,
 
   /// Limit generated debug info to reduce size (-fno-standalone-debug). This

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index fabacd9d49c02..fa45be0f8169f 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -504,7 +504,7 @@ static codegenoptions::DebugInfoKind 
DebugLevelToInfoKind(const Arg &A) {
 return codegenoptions::DebugLineTablesOnly;
   if (A.getOption().matches(options::OPT_gline_directives_only))
 return codegenoptions::DebugDirectivesOnly;
-  return codegenoptions::LimitedDebugInfo;
+  return codegenoptions::DebugInfoConstructor;
 }
 
 static bool mustUseNonLeafFramePointerForTarget(const llvm::Triple &Triple) {
@@ -2545,7 +2545,7 @@ static void CollectArgsForIntegratedAssembler(Compilation 
&C,
   CmdArgs.push_back(Value.data());
 } else {
   RenderDebugEnablingArgs(Args, CmdArgs,
-  codegenoptions::LimitedDebugInfo,
+  codegenoptions::DebugInfoConstructor,
   DwarfVersion, llvm::DebuggerKind::Default);
 }
   } else if (Value.startswith("-mcpu") || Value.startswith("-mfpu") ||
@@ -3914,7 +3914,7 @@ static void renderDebugOptions(const ToolChain &TC, const 
Driver &D,
 }
   }
   if (const Arg *A = Args.getLastArg(options::OPT_g_Group)) {
-DebugInfoKind = codegenoptions::LimitedDebugInfo;
+DebugInfoKind = codegenoptions::DebugInfoConstructor;
 
 // If the last option explicitly specified a debug-info level, use it.
 if (checkDebugInfoOption(A, Args, D, TC) &&
@@ -4036,7 +4036,7 @@ static void renderDebugOptions(const ToolChain &TC, const 
Driver &D,
 if (checkDebugInfoOption(A, Args, D, TC)) {
   if (DebugInfoKind != codegenoptions::DebugLineTablesOnly &&
   DebugInfoKind != codegenoptions::DebugDirectivesOnly) {
-DebugInfoKind = codegenoptions::LimitedDebugInfo;
+DebugInfoKind = codegenoptions::DebugInfoConstructor;
 CmdArgs.push_back("-dwarf-ext-refs");
 CmdArgs.push_back("-fmodule-format=obj");
   }
@@ -4057,7 +4057,8 @@ static void renderDebugOptions(const ToolChain &TC, const 
Driver &D,
   if (const Arg *A = Args.getLastArg(options::OPT_fstandalone_debug))
 (void)checkDebugInfoOption(A, Args, D, TC);
 
-  if (Debug

[Lldb-commits] [lldb] 394db22 - Revert "Switch to using -debug-info-kind=constructor as default (from =limited)"

2020-07-28 Thread Amy Huang via lldb-commits

Author: Amy Huang
Date: 2020-07-28T11:23:59-07:00
New Revision: 394db2259575ef3cac8d3d37836b11eb2373c435

URL: 
https://github.com/llvm/llvm-project/commit/394db2259575ef3cac8d3d37836b11eb2373c435
DIFF: 
https://github.com/llvm/llvm-project/commit/394db2259575ef3cac8d3d37836b11eb2373c435.diff

LOG: Revert "Switch to using -debug-info-kind=constructor as default (from 
=limited)"

This reverts commit 227db86a1b7dd6f96f7df14890fcd071bc4fe1f5.

Causing debug info errors in google3 LTO builds; also causes a
debuginfo-test failure.

Added: 


Modified: 
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/cl-options.c
clang/test/Driver/clang-g-opts.c
clang/test/Driver/cuda-dwarf-2.cu
clang/test/Driver/debug-options-as.c
clang/test/Driver/debug-options.c
clang/test/Driver/integrated-as.s
clang/test/Driver/myriad-toolchain.c
clang/test/Driver/openmp-offload-gpu.c
clang/test/Driver/split-debug.c
lldb/test/Shell/SymbolFile/PDB/Inputs/ClassLayoutTest.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index b0de225f8abf..68e4eb0eedda 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -498,7 +498,7 @@ static codegenoptions::DebugInfoKind 
DebugLevelToInfoKind(const Arg &A) {
 return codegenoptions::DebugLineTablesOnly;
   if (A.getOption().matches(options::OPT_gline_directives_only))
 return codegenoptions::DebugDirectivesOnly;
-  return codegenoptions::DebugInfoConstructor;
+  return codegenoptions::LimitedDebugInfo;
 }
 
 static bool mustUseNonLeafFramePointerForTarget(const llvm::Triple &Triple) {
@@ -2383,7 +2383,7 @@ static void CollectArgsForIntegratedAssembler(Compilation 
&C,
   CmdArgs.push_back(Value.data());
 } else {
   RenderDebugEnablingArgs(Args, CmdArgs,
-  codegenoptions::DebugInfoConstructor,
+  codegenoptions::LimitedDebugInfo,
   DwarfVersion, llvm::DebuggerKind::Default);
 }
   } else if (Value.startswith("-mcpu") || Value.startswith("-mfpu") ||
@@ -3656,7 +3656,7 @@ static void RenderDebugOptions(const ToolChain &TC, const 
Driver &D,
   if (const Arg *A =
   Args.getLastArg(options::OPT_g_Group, options::OPT_gsplit_dwarf,
   options::OPT_gsplit_dwarf_EQ)) {
-DebugInfoKind = codegenoptions::DebugInfoConstructor;
+DebugInfoKind = codegenoptions::LimitedDebugInfo;
 
 // If the last option explicitly specified a debug-info level, use it.
 if (checkDebugInfoOption(A, Args, D, TC) &&
@@ -3761,7 +3761,7 @@ static void RenderDebugOptions(const ToolChain &TC, const 
Driver &D,
 if (checkDebugInfoOption(A, Args, D, TC)) {
   if (DebugInfoKind != codegenoptions::DebugLineTablesOnly &&
   DebugInfoKind != codegenoptions::DebugDirectivesOnly) {
-DebugInfoKind = codegenoptions::DebugInfoConstructor;
+DebugInfoKind = codegenoptions::LimitedDebugInfo;
 CmdArgs.push_back("-dwarf-ext-refs");
 CmdArgs.push_back("-fmodule-format=obj");
   }
@@ -3781,9 +3781,7 @@ static void RenderDebugOptions(const ToolChain &TC, const 
Driver &D,
   TC.GetDefaultStandaloneDebug());
   if (const Arg *A = Args.getLastArg(options::OPT_fstandalone_debug))
 (void)checkDebugInfoOption(A, Args, D, TC);
-  if ((DebugInfoKind == codegenoptions::LimitedDebugInfo ||
-   DebugInfoKind == codegenoptions::DebugInfoConstructor) &&
-  NeedFullDebug)
+  if (DebugInfoKind == codegenoptions::LimitedDebugInfo && NeedFullDebug)
 DebugInfoKind = codegenoptions::FullDebugInfo;
 
   if (Args.hasFlag(options::OPT_gembed_source, options::OPT_gno_embed_source,
@@ -6569,7 +6567,7 @@ void Clang::AddClangCLArgs(const ArgList &Args, types::ID 
InputType,
   options::OPT_gline_tables_only)) {
 *EmitCodeView = true;
 if (DebugInfoArg->getOption().matches(options::OPT__SLASH_Z7))
-  *DebugInfoKind = codegenoptions::DebugInfoConstructor;
+  *DebugInfoKind = codegenoptions::LimitedDebugInfo;
 else
   *DebugInfoKind = codegenoptions::DebugLineTablesOnly;
   } else {
@@ -6866,7 +6864,7 @@ void ClangAs::ConstructJob(Compilation &C, const 
JobAction &JA,
 // the guard for source type, however there is a test which asserts
 // that some assembler invocation receives no -debug-info-kind,
 // and it's not clear whether that test is just overly restrictive.
-DebugInfoKind = (WantDebug ? codegenoptions::DebugInfoConstructor
+DebugInfoKind = (WantDebug ? codegenoptions::LimitedDebugInfo
: codegenoptions::NoDebugInfo);
 // Add the -fdebug-compilation-dir flag if needed.
 addDebugCompDirArg(Args, CmdArgs, C.getDriver().getVFS());

diff  --git a/clang/test/Driver/cl-options.

[Lldb-commits] [lldb] 227db86 - Switch to using -debug-info-kind=constructor as default (from =limited)

2020-07-09 Thread Amy Huang via lldb-commits

Author: Amy Huang
Date: 2020-07-09T15:26:46-07:00
New Revision: 227db86a1b7dd6f96f7df14890fcd071bc4fe1f5

URL: 
https://github.com/llvm/llvm-project/commit/227db86a1b7dd6f96f7df14890fcd071bc4fe1f5
DIFF: 
https://github.com/llvm/llvm-project/commit/227db86a1b7dd6f96f7df14890fcd071bc4fe1f5.diff

LOG: Switch to using -debug-info-kind=constructor as default (from =limited)

Summary:
-debug-info-kind=constructor reduces the amount of class debug info that
is emitted; this patch switches to using this as the default.

Constructor homing emits the complete type info for a class only when the
constructor is emitted, so it is expected that there will be some classes that
are not defined in the debug info anymore because they are never constructed,
and we shouldn't need debug info for these classes.

I compared the PDB files for clang, and there are 273 class types that are 
defined with `=limited`
but not with `=constructor` (out of ~60,000 total class types).
We've looked at a number of the types that are no longer defined with 
=constructor. The vast
majority of cases are something like class A is used as a parameter in a member 
function of
some other class B, which is emitted. But the function that uses class A is 
never called, and class A
is never constructed, and therefore isn't emitted in the debug info.

Bug: https://bugs.llvm.org/show_bug.cgi?id=46537

Subscribers: aprantl, cfe-commits, lldb-commits

Tags: #clang, #lldb

Differential Revision: https://reviews.llvm.org/D79147

Added: 


Modified: 
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/cl-options.c
clang/test/Driver/clang-g-opts.c
clang/test/Driver/cuda-dwarf-2.cu
clang/test/Driver/debug-options-as.c
clang/test/Driver/debug-options.c
clang/test/Driver/integrated-as.s
clang/test/Driver/myriad-toolchain.c
clang/test/Driver/openmp-offload-gpu.c
clang/test/Driver/split-debug.c
lldb/test/Shell/SymbolFile/PDB/Inputs/ClassLayoutTest.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index ed365c608387..9b424beec428 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -498,7 +498,7 @@ static codegenoptions::DebugInfoKind 
DebugLevelToInfoKind(const Arg &A) {
 return codegenoptions::DebugLineTablesOnly;
   if (A.getOption().matches(options::OPT_gline_directives_only))
 return codegenoptions::DebugDirectivesOnly;
-  return codegenoptions::LimitedDebugInfo;
+  return codegenoptions::DebugInfoConstructor;
 }
 
 static bool mustUseNonLeafFramePointerForTarget(const llvm::Triple &Triple) {
@@ -2380,7 +2380,7 @@ static void CollectArgsForIntegratedAssembler(Compilation 
&C,
   CmdArgs.push_back(Value.data());
 } else {
   RenderDebugEnablingArgs(Args, CmdArgs,
-  codegenoptions::LimitedDebugInfo,
+  codegenoptions::DebugInfoConstructor,
   DwarfVersion, llvm::DebuggerKind::Default);
 }
   } else if (Value.startswith("-mcpu") || Value.startswith("-mfpu") ||
@@ -3653,7 +3653,7 @@ static void RenderDebugOptions(const ToolChain &TC, const 
Driver &D,
   if (const Arg *A =
   Args.getLastArg(options::OPT_g_Group, options::OPT_gsplit_dwarf,
   options::OPT_gsplit_dwarf_EQ)) {
-DebugInfoKind = codegenoptions::LimitedDebugInfo;
+DebugInfoKind = codegenoptions::DebugInfoConstructor;
 
 // If the last option explicitly specified a debug-info level, use it.
 if (checkDebugInfoOption(A, Args, D, TC) &&
@@ -3758,7 +3758,7 @@ static void RenderDebugOptions(const ToolChain &TC, const 
Driver &D,
 if (checkDebugInfoOption(A, Args, D, TC)) {
   if (DebugInfoKind != codegenoptions::DebugLineTablesOnly &&
   DebugInfoKind != codegenoptions::DebugDirectivesOnly) {
-DebugInfoKind = codegenoptions::LimitedDebugInfo;
+DebugInfoKind = codegenoptions::DebugInfoConstructor;
 CmdArgs.push_back("-dwarf-ext-refs");
 CmdArgs.push_back("-fmodule-format=obj");
   }
@@ -3778,7 +3778,9 @@ static void RenderDebugOptions(const ToolChain &TC, const 
Driver &D,
   TC.GetDefaultStandaloneDebug());
   if (const Arg *A = Args.getLastArg(options::OPT_fstandalone_debug))
 (void)checkDebugInfoOption(A, Args, D, TC);
-  if (DebugInfoKind == codegenoptions::LimitedDebugInfo && NeedFullDebug)
+  if ((DebugInfoKind == codegenoptions::LimitedDebugInfo ||
+   DebugInfoKind == codegenoptions::DebugInfoConstructor) &&
+  NeedFullDebug)
 DebugInfoKind = codegenoptions::FullDebugInfo;
 
   if (Args.hasFlag(options::OPT_gembed_source, options::OPT_gno_embed_source,
@@ -6552,7 +6554,7 @@ void Clang::AddClangCLArgs(const ArgList &Args, types::ID 
InputType,
   options::OPT_gline_tables_only))