Skip to content

Commit 6b1263b

Browse files
committed
[Driver] Add a -gdwarf-types option and set it up as an alias for -g (NFC-ish)
Background ---------- Now that Swift AST type support in LLDB has matured, we can stop emitting DWARF type information by default to reduce compile time and ibject file size. A future commit will change -g to emit only AST type references. The full set of debug options will be -gnone -gline-tables-only -g // AST types (= everything that LLDB needs) -gdwarf-types // AST types + DWARF types (for legacy debuggers)
1 parent b4d3059 commit 6b1263b

File tree

8 files changed

+44
-28
lines changed

8 files changed

+44
-28
lines changed

include/swift/AST/IRGenOptions.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ enum class IRGenOutputKind : unsigned {
4848
enum class IRGenDebugInfoKind : unsigned {
4949
None, /// No debug info.
5050
LineTables, /// Line tables only.
51-
Normal /// Line tables + DWARF types.
51+
ASTTypes, /// Line tables + AST type references.
52+
DwarfTypes, /// Line tables + AST type references + DWARF types.
53+
Normal = DwarfTypes /// The setting LLDB prefers.
5254
};
5355

5456
enum class IRGenEmbedMode : unsigned {

include/swift/Option/Options.td

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,12 +293,16 @@ def Oplayground : Flag<["-"], "Oplayground">, Group<O_Group>,
293293
def g_Group : OptionGroup<"<debug info options>">;
294294

295295
def g : Flag<["-"], "g">, Group<g_Group>, Flags<[FrontendOption]>,
296-
HelpText<"Emit debug info">;
296+
HelpText<"Emit debug info. "
297+
"This is the preferred setting for debugging with LLDB.">;
297298
def gnone : Flag<["-"], "gnone">, Group<g_Group>, Flags<[FrontendOption]>,
298299
HelpText<"Don't emit debug info">;
299300
def gline_tables_only : Flag<["-"], "gline-tables-only">,
300301
Group<g_Group>, Flags<[FrontendOption]>,
301302
HelpText<"Emit minimal debug info for backtraces only">;
303+
def gdwarf_types : Flag<["-"], "gdwarf-types">,
304+
Group<g_Group>, Flags<[FrontendOption]>,
305+
HelpText<"Emit full DWARF type info.">;
302306

303307
// Assert configuration identifiers.
304308
def AssertConfig : Separate<["-"], "assert-config">,

lib/Driver/Driver.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,8 @@ void Driver::buildOutputInfo(const ToolChain &TC, const DerivedArgList &Args,
975975
OI.DebugInfoKind = IRGenDebugInfoKind::Normal;
976976
else if (A->getOption().matches(options::OPT_gline_tables_only))
977977
OI.DebugInfoKind = IRGenDebugInfoKind::LineTables;
978+
else if (A->getOption().matches(options::OPT_gdwarf_types))
979+
OI.DebugInfoKind = IRGenDebugInfoKind::DwarfTypes;
978980
else
979981
assert(A->getOption().matches(options::OPT_gnone) &&
980982
"unknown -g<kind> option");
@@ -985,7 +987,7 @@ void Driver::buildOutputInfo(const ToolChain &TC, const DerivedArgList &Args,
985987
// top-level output.
986988
OI.ShouldGenerateModule = true;
987989
OI.ShouldTreatModuleAsTopLevelOutput = true;
988-
} else if ((OI.DebugInfoKind == IRGenDebugInfoKind::Normal &&
990+
} else if ((OI.DebugInfoKind > IRGenDebugInfoKind::LineTables &&
989991
OI.shouldLink()) ||
990992
Args.hasArg(options::OPT_emit_objc_header,
991993
options::OPT_emit_objc_header_path)) {

lib/Driver/ToolChains.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,7 @@ toolchains::Darwin::constructInvocation(const LinkJobAction &job,
964964

965965
addInputsOfType(Arguments, context.InputActions, types::TY_Object);
966966

967-
if (context.OI.DebugInfoKind == IRGenDebugInfoKind::Normal) {
967+
if (context.OI.DebugInfoKind > IRGenDebugInfoKind::LineTables) {
968968
size_t argCount = Arguments.size();
969969
if (context.OI.CompilerMode == OutputInfo::Mode::SingleCompile)
970970
addInputsOfType(Arguments, context.Inputs, types::TY_SwiftModuleFile);

lib/Frontend/CompilerInvocation.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1142,11 +1142,13 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
11421142
Opts.DebugInfoKind = IRGenDebugInfoKind::Normal;
11431143
else if (A->getOption().matches(options::OPT_gline_tables_only))
11441144
Opts.DebugInfoKind = IRGenDebugInfoKind::LineTables;
1145+
else if (A->getOption().matches(options::OPT_gdwarf_types))
1146+
Opts.DebugInfoKind = IRGenDebugInfoKind::DwarfTypes;
11451147
else
11461148
assert(A->getOption().matches(options::OPT_gnone) &&
11471149
"unknown -g<kind> option");
11481150

1149-
if (Opts.DebugInfoKind == IRGenDebugInfoKind::Normal) {
1151+
if (Opts.DebugInfoKind > IRGenDebugInfoKind::LineTables) {
11501152
ArgStringList RenderedArgs;
11511153
for (auto A : Args)
11521154
A->render(Args, RenderedArgs);

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ IRGenDebugInfo::IRGenDebugInfo(const IRGenOptions &Opts,
135135
TheCU = DBuilder.createCompileUnit(
136136
Lang, AbsMainFile, Opts.DebugCompilationDir, Producer, IsOptimized,
137137
Flags, MajorRuntimeVersion, SplitName,
138-
Opts.DebugInfoKind == IRGenDebugInfoKind::LineTables
139-
? llvm::DICompileUnit::LineTablesOnly
140-
: llvm::DICompileUnit::FullDebug);
138+
Opts.DebugInfoKind > IRGenDebugInfoKind::LineTables
139+
? llvm::DICompileUnit::FullDebug
140+
: llvm::DICompileUnit::LineTablesOnly);
141141
MainFile = getOrCreateFile(BumpAllocatedString(AbsMainFile).data());
142142

143143
// Because the swift compiler relies on Clang to setup the Module,
@@ -395,7 +395,7 @@ llvm::DIScope *IRGenDebugInfo::getOrCreateScope(const SILDebugScope *DS) {
395395
llvm::DIScope *Parent = getOrCreateScope(ParentScope);
396396
assert(isa<llvm::DILocalScope>(Parent) && "not a local scope");
397397

398-
if (Opts.DebugInfoKind == IRGenDebugInfoKind::LineTables)
398+
if (Opts.DebugInfoKind <= IRGenDebugInfoKind::LineTables)
399399
return Parent;
400400

401401
assert(DS->Parent && "lexical block must have a parent subprogram");
@@ -682,9 +682,9 @@ llvm::DISubprogram *IRGenDebugInfo::emitFunction(
682682
}
683683

684684
CanSILFunctionType FnTy = getFunctionType(SILTy);
685-
auto Params = Opts.DebugInfoKind == IRGenDebugInfoKind::LineTables
686-
? nullptr
687-
: createParameterTypes(SILTy, DeclCtx);
685+
auto Params = Opts.DebugInfoKind > IRGenDebugInfoKind::LineTables
686+
? createParameterTypes(SILTy, DeclCtx)
687+
: nullptr;
688688
llvm::DISubroutineType *DIFnTy = DBuilder.createSubroutineType(Params);
689689
llvm::DITemplateParameterArray TemplateParameters = nullptr;
690690
llvm::DISubprogram *Decl = nullptr;
@@ -740,7 +740,7 @@ llvm::DISubprogram *IRGenDebugInfo::emitFunction(
740740
}
741741

742742
void IRGenDebugInfo::emitImport(ImportDecl *D) {
743-
if (Opts.DebugInfoKind == IRGenDebugInfoKind::LineTables)
743+
if (Opts.DebugInfoKind <= IRGenDebugInfoKind::LineTables)
744744
return;
745745

746746
swift::Module *M = IGM.Context.getModule(D->getModulePath());
@@ -828,7 +828,7 @@ TypeAliasDecl *IRGenDebugInfo::getMetadataType() {
828828
void IRGenDebugInfo::emitTypeMetadata(IRGenFunction &IGF,
829829
llvm::Value *Metadata,
830830
StringRef Name) {
831-
if (Opts.DebugInfoKind == IRGenDebugInfoKind::LineTables)
831+
if (Opts.DebugInfoKind <= IRGenDebugInfoKind::LineTables)
832832
return;
833833

834834
auto TName = BumpAllocatedString(("$swift.type." + Name).str());
@@ -883,7 +883,7 @@ void IRGenDebugInfo::emitVariableDeclaration(
883883
if (!DS)
884884
return;
885885

886-
if (Opts.DebugInfoKind == IRGenDebugInfoKind::LineTables)
886+
if (Opts.DebugInfoKind <= IRGenDebugInfoKind::LineTables)
887887
return;
888888

889889
if (!DbgTy.size)
@@ -1004,7 +1004,7 @@ void IRGenDebugInfo::emitGlobalVariableDeclaration(llvm::Constant *Var,
10041004
DebugTypeInfo DbgTy,
10051005
bool IsLocalToUnit,
10061006
Optional<SILLocation> Loc) {
1007-
if (Opts.DebugInfoKind == IRGenDebugInfoKind::LineTables)
1007+
if (Opts.DebugInfoKind <= IRGenDebugInfoKind::LineTables)
10081008
return;
10091009

10101010
llvm::DIType *Ty = getOrCreateType(DbgTy);

lib/IRGen/IRGenModule.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,13 @@ static clang::CodeGenerator *createClangCodeGenerator(ASTContext &Context,
9292
case IRGenDebugInfoKind::LineTables:
9393
CGO.setDebugInfo(clang::codegenoptions::DebugInfoKind::DebugLineTablesOnly);
9494
break;
95-
case IRGenDebugInfoKind::Normal:
95+
case IRGenDebugInfoKind::ASTTypes:
96+
// TODO: Enable -gmodules for the clang code generator.
97+
case IRGenDebugInfoKind::DwarfTypes:
9698
CGO.setDebugInfo(clang::codegenoptions::DebugInfoKind::FullDebugInfo);
9799
break;
98100
}
99-
if (Opts.DebugInfoKind != IRGenDebugInfoKind::None) {
101+
if (Opts.DebugInfoKind > IRGenDebugInfoKind::None) {
100102
CGO.DebugCompilationDir = Opts.DebugCompilationDir;
101103
CGO.DwarfVersion = Opts.DWARFVersion;
102104
CGO.DwarfDebugFlags = Opts.DWARFDebugFlags;
@@ -383,16 +385,13 @@ IRGenModule::IRGenModule(IRGenerator &irgen,
383385
// Only use the new calling conventions on platforms that support it.
384386
auto Arch = Triple.getArch();
385387
if (SWIFT_RT_USE_RegisterPreservingCC &&
386-
Arch == llvm::Triple::ArchType::aarch64) {
388+
Arch == llvm::Triple::ArchType::aarch64)
387389
RegisterPreservingCC = SWIFT_LLVM_CC(RegisterPreservingCC);
388-
}
389-
else {
390+
else
390391
RegisterPreservingCC = DefaultCC;
391-
}
392392

393-
if (IRGen.Opts.DebugInfoKind != IRGenDebugInfoKind::None) {
393+
if (IRGen.Opts.DebugInfoKind > IRGenDebugInfoKind::None)
394394
DebugInfo = new IRGenDebugInfo(IRGen.Opts, *CI, *this, Module, SF);
395-
}
396395

397396
initClangTypeConverter();
398397
}

test/DebugInfo/basic.swift

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,30 @@
11
// A (no longer) basic test for debug info.
22
// --------------------------------------------------------------------
33
// Verify that we don't emit any debug info by default.
4-
// RUN: %target-swift-frontend %s -emit-ir -o - | FileCheck %s --check-prefix NDEBUG
4+
// RUN: %target-swift-frontend %s -emit-ir -o - \
5+
// RUN: | FileCheck %s --check-prefix NDEBUG
56
// NDEBUG-NOT: !dbg
67
// NDEBUG-NOT: DW_TAG
78
// --------------------------------------------------------------------
89
// Verify that we don't emit any debug info with -gnone.
9-
// RUN: %target-swift-frontend %s -emit-ir -gnone -o - | FileCheck %s --check-prefix NDEBUG
10+
// RUN: %target-swift-frontend %s -emit-ir -gnone -o - \
11+
// RUN: | FileCheck %s --check-prefix NDEBUG
1012
// --------------------------------------------------------------------
1113
// Verify that we don't emit any type info with -gline-tables-only.
12-
// RUN: %target-swift-frontend %s -emit-ir -gline-tables-only -o - | FileCheck %s --check-prefix CHECK-LINETABLES
14+
// RUN: %target-swift-frontend %s -emit-ir -gline-tables-only -o - \
15+
// RUN: | FileCheck %s --check-prefix CHECK-LINETABLES
1316
// CHECK: !dbg
1417
// CHECK-LINETABLES-NOT: DW_TAG_{{.*}}variable
1518
// CHECK-LINETABLES-NOT: DW_TAG_structure_type
1619
// CHECK-LINETABLES-NOT: DW_TAG_basic_type
1720
// --------------------------------------------------------------------
1821
// Now check that we do generate line+scope info with -g.
1922
// RUN: %target-swift-frontend %s -emit-ir -g -o - | FileCheck %s
20-
// RUN: %target-swift-frontend %s -emit-ir -g -o - -disable-sil-linking | FileCheck %s --check-prefix=CHECK-NOSIL
23+
// RUN: %target-swift-frontend %s -emit-ir -g -o - -disable-sil-linking \
24+
// RUN: | FileCheck %s --check-prefix=CHECK-NOSIL
25+
// --------------------------------------------------------------------
26+
// Currently -gdwarf-types should give the same results as -g.
27+
// RUN: %target-swift-frontend %s -emit-ir -gdwarf-types -o - | FileCheck %s
2128
// --------------------------------------------------------------------
2229
//
2330
// CHECK: foo

0 commit comments

Comments
 (0)