Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit ab57bf1

Browse files
committed
DebugInfo: Consider a CU containing only local imported entities to be 'empty'
This can come up in ThinLTO & wastes space & makes degenerate IR. As per the added FIXME, ultimately, local imported entities should hang off the function and that way the imported entity list on the CU can be tested for emptiness like all the other CU lists. (function-attached local imported entities are probably also the best path forward for fixing how imported entities are handled both in cross-module use (currently, while ThinLTO preserves the imported entities, they would not get used at the imported inlined location - only in the abstract origin that appears in the partial CU created by the import (which isn't emitted under Fission due to cross-CU limitations there)) and to reduce the number of points where imported entities are emitted (they're currently emitted into every inlined instance, concrete instance, and abstract origin - they should only go in teh abstract origin if there is one, otherwise in the concrete instance - but this requires lots of delayed handling and wiring up, same as abstract variables & subprograms)) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@309354 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 7313cf8 commit ab57bf1

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

include/llvm/IR/Metadata.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1188,7 +1188,8 @@ void TempMDNodeDeleter::operator()(MDNode *Node) const {
11881188
/// particular Metadata subclass.
11891189
template <class T>
11901190
class TypedMDOperandIterator
1191-
: std::iterator<std::input_iterator_tag, T *, std::ptrdiff_t, void, T *> {
1191+
: public std::iterator<std::input_iterator_tag, T *, std::ptrdiff_t, void,
1192+
T *> {
11921193
MDNode::op_iterator I = nullptr;
11931194

11941195
public:

lib/CodeGen/AsmPrinter/DwarfDebug.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,9 @@ DwarfDebug::getOrCreateDwarfCompileUnit(const DICompileUnit *DIUnit) {
428428
Asm->TM.Options.MCOptions.SplitDwarfFile);
429429
}
430430

431+
for (auto *IE : DIUnit->getImportedEntities())
432+
NewCU.addImportedEntity(IE);
433+
431434
// LTO with assembly output shares a single line table amongst multiple CUs.
432435
// To avoid the compilation directory being ambiguous, let the line table
433436
// explicitly describe the directory of all files, never relying on the
@@ -522,14 +525,6 @@ sortGlobalExprs(SmallVectorImpl<DwarfCompileUnit::GlobalExpr> &GVEs) {
522525
return GVEs;
523526
}
524527

525-
static bool isEmptyCU(DICompileUnit *CUNode) {
526-
return CUNode->getEnumTypes().empty() &&
527-
CUNode->getRetainedTypes().empty() &&
528-
CUNode->getGlobalVariables().empty() &&
529-
CUNode->getImportedEntities().empty() &&
530-
CUNode->getMacros().empty();
531-
}
532-
533528
// Emit all Dwarf sections that should come prior to the content. Create
534529
// global DIEs and emit initial debug info sections. This is invoked by
535530
// the target AsmPrinter.
@@ -556,12 +551,20 @@ void DwarfDebug::beginModule() {
556551
}
557552

558553
for (DICompileUnit *CUNode : M->debug_compile_units()) {
559-
if (isEmptyCU(CUNode))
554+
// FIXME: Move local imported entities into a list attached to the
555+
// subprogram, then this search won't be needed and a
556+
// getImportedEntities().empty() test should go below with the rest.
557+
bool HasNonLocalImportedEntities = llvm::any_of(
558+
CUNode->getImportedEntities(), [](const DIImportedEntity *IE) {
559+
return !isa<DILocalScope>(IE->getScope());
560+
});
561+
562+
if (!HasNonLocalImportedEntities && CUNode->getEnumTypes().empty() &&
563+
CUNode->getRetainedTypes().empty() &&
564+
CUNode->getGlobalVariables().empty() && CUNode->getMacros().empty())
560565
continue;
561566

562567
DwarfCompileUnit &CU = getOrCreateDwarfCompileUnit(CUNode);
563-
for (auto *IE : CUNode->getImportedEntities())
564-
CU.addImportedEntity(IE);
565568

566569
// Global Variables.
567570
for (auto *GVE : CUNode->getGlobalVariables())

test/DebugInfo/omit-empty.ll

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,18 @@
33

44
; CHECK-NOT: .debug_
55

6-
!llvm.dbg.cu = !{!0}
6+
!llvm.dbg.cu = !{!0, !5}
77
!llvm.module.flags = !{!3, !4}
88

99
!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "LLVM", isOptimized: false, runtimeVersion: 2, emissionKind: FullDebug, enums: !2, retainedTypes: !2, globals: !2, imports: !2)
1010
!1 = !DIFile(filename: "<stdin>", directory: "/")
1111
!2 = !{}
1212
!3 = !{i32 2, !"Dwarf Version", i32 4}
1313
!4 = !{i32 2, !"Debug Info Version", i32 3}
14+
!5 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "LLVM", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, imports: !6)
15+
!6 = !{!7}
16+
!7 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !8, entity: !8, file: !1, line: 3)
17+
!8 = distinct !DISubprogram(name: "f2", linkageName: "_Z2f2v", scope: !1, file: !1, line: 2, type: !9, isLocal: false, isDefinition: true, scopeLine: 2, flags: DIFlagPrototyped, isOptimized: false, unit: !5, variables: !2)
18+
!9 = !DISubroutineType(types: !10)
19+
!10 = !{null}
20+
!11 = !DINamespace(name: "ns", scope: null)

0 commit comments

Comments
 (0)