diff options
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp | 9 | ||||
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h | 6 | ||||
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp | 6 | ||||
-rw-r--r-- | llvm/test/DebugInfo/Generic/inlined-strings.ll | 45 |
4 files changed, 66 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index 3681254ae08..dfb36fa1d43 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -115,6 +115,14 @@ DwarfAccelTables("dwarf-accel-tables", cl::Hidden, clEnumVal(Disable, "Disabled")), cl::init(Default)); +static cl::opt<DefaultOnOff> +DwarfInlinedStrings("dwarf-inlined-strings", cl::Hidden, + cl::desc("Use inlined strings rather than string section."), + cl::values(clEnumVal(Default, "Default for platform"), + clEnumVal(Enable, "Enabled"), + clEnumVal(Disable, "Disabled")), + cl::init(Default)); + enum LinkageNameOption { DefaultLinkageNames, AllLinkageNames, @@ -284,6 +292,7 @@ DwarfDebug::DwarfDebug(AsmPrinter *A, Module *M) else HasDwarfAccelTables = DwarfAccelTables == Enable; + UseInlineStrings = DwarfInlinedStrings == Enable; HasAppleExtensionAttributes = tuneForLLDB(); // Handle split DWARF. diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h index 380c868076b..f858c96d0d2 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h @@ -255,6 +255,9 @@ class DwarfDebug : public DebugHandlerBase { /// Whether to emit all linkage names, or just abstract subprograms. bool UseAllLinkageNames; + /// Use inlined strings. + bool UseInlineStrings = false; + /// DWARF5 Experimental Options /// @{ bool HasDwarfAccelTables; @@ -491,6 +494,9 @@ public: /// DWARF4 format. bool useDWARF2Bitfields() const { return UseDWARF2Bitfields; } + /// Returns whether to use inline strings. + bool useInlineStrings() const { return UseInlineStrings; } + // Experimental DWARF5 features. /// Returns whether or not to emit tables that dwarf consumers can diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp index 76e1228cafc..d7d5298d673 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp @@ -241,6 +241,12 @@ void DwarfUnit::addSInt(DIELoc &Die, Optional<dwarf::Form> Form, void DwarfUnit::addString(DIE &Die, dwarf::Attribute Attribute, StringRef String) { + if (DD->useInlineStrings()) { + Die.addValue(DIEValueAllocator, Attribute, dwarf::DW_FORM_string, + new (DIEValueAllocator) + DIEInlineString(String, DIEValueAllocator)); + return; + } auto StringPoolEntry = DU->getStringPool().getEntry(*Asm, String); dwarf::Form IxForm = isDwoUnit() ? dwarf::DW_FORM_GNU_str_index : dwarf::DW_FORM_strp; diff --git a/llvm/test/DebugInfo/Generic/inlined-strings.ll b/llvm/test/DebugInfo/Generic/inlined-strings.ll new file mode 100644 index 00000000000..18c15b2500c --- /dev/null +++ b/llvm/test/DebugInfo/Generic/inlined-strings.ll @@ -0,0 +1,45 @@ +; REQUIRES: object-emission + +; RUN: %llc_dwarf -O0 -filetype=obj < %s -dwarf-inlined-strings=Enable -o - | llvm-dwarfdump -show-form - | FileCheck %s + +; Also test that the null streamer doesn't crash with debug info. +; RUN: %llc_dwarf -O0 -filetype=null < %s -dwarf-inlined-strings=Enable + +; generated from the following source compiled to bitcode with clang -g -O1 +; static int i; +; int main() { +; (void)&i; +; } + +; CHECK-NOT: DW_FORM_str{{(p|x)}} +; CHECK: DW_FORM_string +; CHECK-NOT: DW_FORM_str{{(p|x)}} + + +source_filename = "test/DebugInfo/Generic/global.ll" + +; Function Attrs: nounwind readnone uwtable +define i32 @main() #0 !dbg !9 { +entry: + ret i32 0, !dbg !12 +} + +attributes #0 = { nounwind readnone uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "unsafe-fp-math"="false" "use-soft-float"="false" } + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!7, !8} + +!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 3.4 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !2, globals: !3, imports: !2) +!1 = !DIFile(filename: "global.cpp", directory: "/tmp") +!2 = !{} +!3 = !{!4} +!4 = !DIGlobalVariableExpression(var: !5, expr: !DIExpression()) +!5 = !DIGlobalVariable(name: "i", linkageName: "_ZL1i", scope: null, file: !1, line: 1, type: !6, isLocal: true, isDefinition: true) +!6 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) +!7 = !{i32 2, !"Dwarf Version", i32 3} +!8 = !{i32 1, !"Debug Info Version", i32 3} +!9 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 2, type: !10, isLocal: false, isDefinition: true, scopeLine: 2, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, unit: !0, variables: !2) +!10 = !DISubroutineType(types: !11) +!11 = !{!6} +!12 = !DILocation(line: 4, scope: !9) + |