[llvm] a73d354 - DWARF: Enable "ranges always" under Split DWARF by default

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 29 14:02:15 PDT 2023


Author: David Blaikie
Date: 2023-03-29T21:01:38Z
New Revision: a73d354024f668b30dc828366a40c50dab8b4159

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

LOG: DWARF: Enable "ranges always" under Split DWARF by default

Given the intent of Split DWARF is to minimize .o file size it seems
like adequate signal that it's worth a minor tradeoff in .dwo size to
significantly reduce .o size (though it doesn't reduce linked executable
size - the cost is mostly in the static relocations resolved by the
linker).

Added: 
    llvm/test/DebugInfo/X86/ranges_always_default.ll

Modified: 
    llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
    llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
    llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
    llvm/test/DebugInfo/X86/debug_addr.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
index f336eae12518f..4c65253bf7a14 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
@@ -637,7 +637,7 @@ void DwarfCompileUnit::attachRangesOrLowHighPC(
   assert(!Ranges.empty());
   if (!DD->useRangesSection() ||
       (Ranges.size() == 1 &&
-       (!DD->alwaysUseRanges() ||
+       (!DD->alwaysUseRanges(*this) ||
         DD->getSectionLabel(&Ranges.front().Begin->getSection()) ==
             Ranges.front().Begin))) {
     const RangeSpan &Front = Ranges.front();

diff  --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
index 82af9e26fdc86..98f24599970da 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -452,14 +452,8 @@ DwarfDebug::DwarfDebug(AsmPrinter *A)
 
   // Split DWARF would benefit object size significantly by trading reductions
   // in address pool usage for slightly increased range list encodings.
-  if (DwarfVersion >= 5) {
+  if (DwarfVersion >= 5)
     MinimizeAddr = MinimizeAddrInV5Option;
-    // FIXME: In the future, enable this by default for Split DWARF where the
-    // tradeoff is more pronounced due to being able to offload the range
-    // lists to the dwo file and shrink object files/reduce relocations there.
-    if (MinimizeAddr == MinimizeAddrInV5::Default)
-      MinimizeAddr = MinimizeAddrInV5::Disabled;
-  }
 
   Asm->OutStreamer->getContext().setDwarfVersion(DwarfVersion);
   Asm->OutStreamer->getContext().setDwarfFormat(Dwarf64 ? dwarf::DWARF64
@@ -3585,3 +3579,13 @@ DwarfDebug::getMD5AsBytes(const DIFile *File) const {
   std::copy(ChecksumString.begin(), ChecksumString.end(), CKMem.data());
   return CKMem;
 }
+
+bool DwarfDebug::alwaysUseRanges(const DwarfCompileUnit &CU) const {
+  if (MinimizeAddr == MinimizeAddrInV5::Ranges)
+    return true;
+  if (MinimizeAddr != MinimizeAddrInV5::Default)
+    return false;
+  if (useSplitDwarf())
+    return true;
+  return false;
+}

diff  --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
index 5d2ef8ee79a7b..0e71c216e9587 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
@@ -696,9 +696,7 @@ class DwarfDebug : public DebugHandlerBase {
 
   /// Returns whether range encodings should be used for single entry range
   /// lists.
-  bool alwaysUseRanges() const {
-    return MinimizeAddr == MinimizeAddrInV5::Ranges;
-  }
+  bool alwaysUseRanges(const DwarfCompileUnit &) const;
 
   // Returns whether novel exprloc addrx+offset encodings should be used to
   // reduce debug_addr size.

diff  --git a/llvm/test/DebugInfo/X86/debug_addr.ll b/llvm/test/DebugInfo/X86/debug_addr.ll
index 6087f452c1c48..a69aa6f8307ef 100644
--- a/llvm/test/DebugInfo/X86/debug_addr.ll
+++ b/llvm/test/DebugInfo/X86/debug_addr.ll
@@ -1,7 +1,7 @@
-; RUN: llc -split-dwarf-file=test.dwo -dwarf-version=4 %s -mtriple=i386-unknown-linux-gnu -filetype=obj -o - | \
+; RUN: llc -split-dwarf-file=test.dwo -dwarf-version=4 %s -mtriple=i386-unknown-linux-gnu -filetype=obj -o - -minimize-addr-in-v5=Disabled | \
 ; RUN: llvm-dwarfdump -v - | FileCheck %s -check-prefix=DWARF4
 
-; RUN: llc -split-dwarf-file=test.dwo -dwarf-version=5 %s -mtriple=i386-unknown-linux-gnu -filetype=obj -o - | \
+; RUN: llc -split-dwarf-file=test.dwo -dwarf-version=5 %s -mtriple=i386-unknown-linux-gnu -filetype=obj -o - -minimize-addr-in-v5=Disabled | \
 ; RUN: llvm-dwarfdump -v - | FileCheck %s -check-prefix=DWARF5
 
 ; Source:

diff  --git a/llvm/test/DebugInfo/X86/ranges_always_default.ll b/llvm/test/DebugInfo/X86/ranges_always_default.ll
new file mode 100644
index 0000000000000..0cb2004a57d9f
--- /dev/null
+++ b/llvm/test/DebugInfo/X86/ranges_always_default.ll
@@ -0,0 +1,59 @@
+; RUN: llc -O0 %s -mtriple=x86_64-unknown-linux-gnu -filetype=obj -o - -minimize-addr-in-v5=Default \
+; RUN:   -split-dwarf-file=test.dwo \
+; RUN:   | llvm-dwarfdump -debug-info -debug-addr -debug-rnglists -v - \
+; RUN:   | FileCheck --check-prefix=RANGE %s
+
+; RUN: llc -O0 %s -mtriple=x86_64-unknown-linux-gnu -filetype=obj -o - -minimize-addr-in-v5=Disabled \
+; RUN:   -split-dwarf-file=test.dwo \
+; RUN:   | llvm-dwarfdump -debug-info -debug-addr -debug-rnglists -v - \
+; RUN:   | FileCheck --check-prefix=NORANGE %s
+
+; A simpler example than used in ranges_always.ll, since this doesn't test all
+; the nuances of where minimizing ranges are useful. This is only testing the
+; defaulting behavior - specifically that the "ranges" version of the
+; functionality is used when Split DWARF emission occurs (so, when split dwarf is
+; enabled and !(gmlt+!split-dwarf-inlining) (because if the latter is true, then
+; split dwarf emission doesn't occur because it'd be redundant/extra verbose)
+
+; CHECK: DW_TAG_inlined_subroutine
+; CHECK-NOT: {{DW_TAG|NULL}}
+; RANGE: DW_AT_ranges
+; CHECK-NOT: {{DW_TAG|NULL}}
+; NORANGE: DW_AT_low_pc
+; CHECK-NOT: {{DW_TAG|NULL}}
+; NORANGE: DW_AT_high_pc
+; CHECK: NULL
+
+
+; Function Attrs: mustprogress noinline optnone uwtable
+define dso_local void @_Z2f3v() !dbg !10 {
+entry:
+  call void @_Z2f1v(), !dbg !13
+  call void @_Z2f1v(), !dbg !14
+  ret void, !dbg !17
+}
+
+declare void @_Z2f1v()
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!2, !3, !4, !5, !6, !7, !8}
+!llvm.ident = !{!9}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 17.0.0 (git at github.com:llvm/llvm-project.git 22afe19ac03f5b5db642cbb8ba7022c2ffc09710)", isOptimized: false, runtimeVersion: 0, emissionKind: LineTablesOnly, splitDebugInlining: false, nameTableKind: None)
+!1 = !DIFile(filename: "test.cpp", directory: "/proc/self/cwd", checksumkind: CSK_MD5, checksum: "77606e6e313660c9c1dac8290849946d")
+!2 = !{i32 7, !"Dwarf Version", i32 5}
+!3 = !{i32 2, !"Debug Info Version", i32 3}
+!4 = !{i32 1, !"wchar_size", i32 4}
+!5 = !{i32 8, !"PIC Level", i32 2}
+!6 = !{i32 7, !"PIE Level", i32 2}
+!7 = !{i32 7, !"uwtable", i32 2}
+!8 = !{i32 7, !"frame-pointer", i32 2}
+!9 = !{!"clang version 17.0.0 (git at github.com:llvm/llvm-project.git 22afe19ac03f5b5db642cbb8ba7022c2ffc09710)"}
+!10 = distinct !DISubprogram(name: "f3", scope: !1, file: !1, line: 5, type: !11, scopeLine: 5, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !12)
+!11 = !DISubroutineType(types: !12)
+!12 = !{}
+!13 = !DILocation(line: 6, column: 3, scope: !10)
+!14 = !DILocation(line: 3, column: 3, scope: !15, inlinedAt: !16)
+!15 = distinct !DISubprogram(name: "f2", scope: !1, file: !1, line: 2, type: !11, scopeLine: 2, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !12)
+!16 = distinct !DILocation(line: 7, column: 3, scope: !10)
+!17 = !DILocation(line: 8, column: 1, scope: !10)


        


More information about the llvm-commits mailing list