Skip to content

Commit

Permalink
[DwarfDebug] Move emission of imported entities from beginModule() to…
Browse files Browse the repository at this point in the history
… endModule() (2/7)

RFC https://discourse.llvm.org/t/rfc-dwarfdebug-fix-and-improve-handling-imported-entities-types-and-static-local-in-subprogram-and-lexical-block-scopes/68544

!Note! Extracted from the following patch for review purpose only, should
be squashed with the next patch (D144004) before committing.

Currently the back-end emits imported entities in `DwarfDebug::beginModule()`.
However in case an imported declaration is a function, it must point to an
abstract subprogram if it exists (see PR51501). But in `DwarfDebug::beginModule()`
the DWARF generator doesn't have information to identify if an abstract
subprogram needs to be created.

Only by entering `DwarfDebug::endModule()` all subprograms are processed,
so it's clear which subprogram DIE should be referred to. Hence, the patch moves
the emission there.

The patch is need to fix PR51501, but it only does the preliminary
work. Since it changes the order of debug entities in emitted DWARF and
therefore affect many tests it's separated from the fix for the sake of
simplifying review.

Note that there are other issues with handling an imported declaration in
`DwarfDebug::beginModule()`. They are described in more details in D114705.

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

Depends on D143984
  • Loading branch information
chbessonova authored and dzhidzhoev committed Jun 14, 2023
1 parent b8c08f7 commit 40b2eb6
Show file tree
Hide file tree
Showing 6 changed files with 6,402 additions and 6,406 deletions.
15 changes: 9 additions & 6 deletions llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
Expand Up @@ -1258,10 +1258,6 @@ void DwarfDebug::beginModule(Module *M) {
// There is no point in force-emitting a forward declaration.
CU.getOrCreateTypeDIE(RT);
}
// Emit imported_modules last so that the relevant context is already
// available.
for (auto *IE : CUNode->getImportedEntities())
constructAndAddImportedEntityDIE(CU, IE);
}
}

Expand Down Expand Up @@ -1442,8 +1438,15 @@ void DwarfDebug::endModule() {
assert(CurMI == nullptr);

for (const auto &P : CUMap) {
auto &CU = *P.second;
CU.createBaseTypeDIEs();
const auto *CUNode = cast<DICompileUnit>(P.first);
DwarfCompileUnit *CU = &*P.second;

// Emit imported entities.
for (auto *IE : CUNode->getImportedEntities())
constructAndAddImportedEntityDIE(*CU, IE);

// Emit base types.
CU->createBaseTypeDIEs();
}

// If we aren't actually generating debug info (check beginModule -
Expand Down
3 changes: 1 addition & 2 deletions llvm/test/DebugInfo/BPF/extern-void.ll
Expand Up @@ -36,9 +36,8 @@ entry:
; CHECK: .quad bla1
; CHECK-NEXT: DW_TAG_variable
;
; CHECK: .quad bla2
; CHECK: .quad bla2
; CHECK-NEXT: DW_TAG_const_type
; CHECK-NEXT: DW_TAG_subprogram

; Function Attrs: nounwind readnone speculatable willreturn
declare void @llvm.dbg.value(metadata, metadata, metadata) #1
Expand Down
12 changes: 6 additions & 6 deletions llvm/test/DebugInfo/Generic/namespace.ll
Expand Up @@ -57,13 +57,8 @@
; CHECK: NULL

; CHECK: DW_TAG_base_type
; CHECK: DW_TAG_imported_module
; CHECK: DW_AT_decl_file ([[F2:.*]])
; CHECK: DW_AT_decl_line (18)
; CHECK: DW_AT_import ([[NS1]])
; CHECK: DW_TAG_imported_declaration

; CHECK: DW_TAG_subprogram

; CHECK: DW_TAG_subprogram
; CHECK: DW_AT_MIPS_linkage_name
; CHECK: DW_AT_name ("func")
Expand Down Expand Up @@ -127,6 +122,11 @@
; CHECK: NULL

; CHECK: DW_TAG_subprogram
; CHECK: DW_TAG_imported_module
; CHECK: DW_AT_decl_file ([[F2:.*]])
; CHECK: DW_AT_decl_line (18)
; CHECK: DW_AT_import ([[NS1]])
; CHECK: DW_TAG_imported_declaration
; CHECK: DW_TAG_base_type
; CHECK: NULL

Expand Down

0 comments on commit 40b2eb6

Please sign in to comment.