Commit b516ca06 authored by Vedant Kumar's avatar Vedant Kumar Committed by Hans Wennborg
Browse files

Revert "Reland: [DWARF] Allow cross-CU references of subprogram definitions"

... as well as:
Revert "[DWARF] Defer creating declaration DIEs until we prepare call site info"

This reverts commit fa4701e1.

This reverts commit 79daafc9.

There have been reports of this assert getting hit:

CalleeDIE && "Could not find DIE for call site entry origin

(cherry picked from commit 802bec89)
parent b28b38a5
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -968,8 +968,8 @@ DIE &DwarfCompileUnit::constructCallSiteEntryDIE(
    addAddress(CallSiteDIE, getDwarf5OrGNUAttr(dwarf::DW_AT_call_target),
               MachineLocation(CallReg));
  } else {
    DIE *CalleeDIE = getDIE(CalleeSP);
    assert(CalleeDIE && "Could not find DIE for call site entry origin");
    DIE *CalleeDIE = getOrCreateSubprogramDIE(CalleeSP);
    assert(CalleeDIE && "Could not create DIE for call site entry origin");
    addDIEEntry(CallSiteDIE, getDwarf5OrGNUAttr(dwarf::DW_AT_call_origin),
                *CalleeDIE);
  }
+5 −19
Original line number Diff line number Diff line
@@ -540,14 +540,6 @@ void DwarfDebug::constructAbstractSubprogramScopeDIE(DwarfCompileUnit &SrcCU,
  }
}

DIE &DwarfDebug::constructSubprogramDefinitionDIE(const DISubprogram *SP) {
  DICompileUnit *Unit = SP->getUnit();
  assert(SP->isDefinition() && "Subprogram not a definition");
  assert(Unit && "Subprogram definition without parent unit");
  auto &CU = getOrCreateDwarfCompileUnit(Unit);
  return *CU.getOrCreateSubprogramDIE(SP);
}

/// Try to interpret values loaded into registers that forward parameters
/// for \p CallMI. Store parameters with interpreted value into \p Params.
static void collectCallSiteParameters(const MachineInstr *CallMI,
@@ -758,17 +750,6 @@ void DwarfDebug::constructCallSiteEntryDIEs(const DISubprogram &SP,
        if (!CalleeDecl || !CalleeDecl->getSubprogram())
          continue;
        CalleeSP = CalleeDecl->getSubprogram();

        if (CalleeSP->isDefinition()) {
          // Ensure that a subprogram DIE for the callee is available in the
          // appropriate CU.
          constructSubprogramDefinitionDIE(CalleeSP);
        } else {
          // Create the declaration DIE if it is missing. This is required to
          // support compilation of old bitcode with an incomplete list of
          // retained metadata.
          CU.getOrCreateSubprogramDIE(CalleeSP);
        }
      }

      // TODO: Omit call site entries for runtime calls (objc_msgSend, etc).
@@ -924,6 +905,11 @@ DwarfDebug::getOrCreateDwarfCompileUnit(const DICompileUnit *DIUnit) {
    NewCU.setSection(Asm->getObjFileLowering().getDwarfInfoSection());
  }

  // Create DIEs for function declarations used for call site debug info.
  for (auto Scope : DIUnit->getRetainedTypes())
    if (auto *SP = dyn_cast_or_null<DISubprogram>(Scope))
      NewCU.getOrCreateSubprogramDIE(SP);

  CUMap.insert({DIUnit, &NewCU});
  CUDieMap.insert({&NewCU.getUnitDie(), &NewCU});
  return NewCU;
+0 −3
Original line number Diff line number Diff line
@@ -442,9 +442,6 @@ class DwarfDebug : public DebugHandlerBase {
  /// Construct a DIE for this abstract scope.
  void constructAbstractSubprogramScopeDIE(DwarfCompileUnit &SrcCU, LexicalScope *Scope);

  /// Construct a DIE for the subprogram definition \p SP and return it.
  DIE &constructSubprogramDefinitionDIE(const DISubprogram *SP);

  /// Construct DIEs for call site entries describing the calls in \p MF.
  void constructCallSiteEntryDIEs(const DISubprogram &SP, DwarfCompileUnit &CU,
                                  DIE &ScopeDIE, const MachineFunction &MF);
+5 −4
Original line number Diff line number Diff line
@@ -188,9 +188,8 @@ int64_t DwarfUnit::getDefaultLowerBound() const {

/// Check whether the DIE for this MDNode can be shared across CUs.
bool DwarfUnit::isShareableAcrossCUs(const DINode *D) const {
  // When the MDNode can be part of the type system (this includes subprogram
  // declarations *and* subprogram definitions, even local definitions), the
  // DIE must be shared across CUs.
  // When the MDNode can be part of the type system, the DIE can be shared
  // across CUs.
  // Combining type units and cross-CU DIE sharing is lower value (since
  // cross-CU DIE sharing is used in LTO and removes type redundancy at that
  // level already) but may be implementable for some value in projects
@@ -198,7 +197,9 @@ bool DwarfUnit::isShareableAcrossCUs(const DINode *D) const {
  // together.
  if (isDwoUnit() && !DD->shareAcrossDWOCUs())
    return false;
  return (isa<DIType>(D) || isa<DISubprogram>(D)) && !DD->generateTypeUnits();
  return (isa<DIType>(D) ||
          (isa<DISubprogram>(D) && !cast<DISubprogram>(D)->isDefinition())) &&
         !DD->generateTypeUnits();
}

DIE *DwarfUnit::getDIE(const DINode *D) const {
+0 −44
Original line number Diff line number Diff line
; RUN: llc -mtriple=arm64-apple-ios -filetype=obj < %s -o %t.o
; RUN: llvm-dwarfdump %t.o | FileCheck %s -implicit-check-not=DW_TAG_subprogram

; The declaration subprogram for "function" is not in the CU's list of
; retained types. Test that a DWARF call site entry can still be constructed.

; CHECK: DW_TAG_subprogram
; CHECK:   DW_AT_name {{.*}}__hidden#3_
; CHECK:   DW_TAG_call_site
; CHECK:     DW_AT_call_origin (0x{{0+}}[[FUNCTION_DIE:.*]])

; CHECK: 0x{{0+}}[[FUNCTION_DIE]]: DW_TAG_subprogram
; CHECK:   DW_AT_name {{.*}}function

target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
target triple = "arm64-apple-ios9.0.0"

define i32 @main() local_unnamed_addr !dbg !8 {
  %1 = tail call [2 x i64] @function([2 x i64] zeroinitializer), !dbg !11
  %2 = extractvalue [2 x i64] %1, 0, !dbg !11
  %3 = trunc i64 %2 to i32, !dbg !11
  ret i32 %3, !dbg !12
}

declare !dbg !13 [2 x i64] @function([2 x i64]) local_unnamed_addr

!llvm.module.flags = !{!0, !1, !2, !3, !4}
!llvm.dbg.cu = !{!5}
!llvm.ident = !{!7}

!0 = !{i32 2, !"SDK Version", [2 x i32] [i32 13, i32 4]}
!1 = !{i32 7, !"Dwarf Version", i32 4}
!2 = !{i32 2, !"Debug Info Version", i32 3}
!3 = !{i32 1, !"wchar_size", i32 4}
!4 = !{i32 7, !"PIC Level", i32 2}
!5 = distinct !DICompileUnit(language: DW_LANG_C99, file: !6, producer: "__hidden#0_", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, nameTableKind: None)
!6 = !DIFile(filename: "__hidden#1_", directory: "__hidden#2_")
!7 = !{!"Apple clang version 11.0.0 (llvm-project fa407d93fd5e618d76378c1ce4e4f517e0563278) (+internal-os)"}
!8 = distinct !DISubprogram(name: "__hidden#3_", scope: !6, file: !6, line: 9, type: !9, scopeLine: 9, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !5)
!9 = !DISubroutineType(types: !10)
!10 = !{}
!11 = !DILocation(line: 12, column: 10, scope: !8)
!12 = !DILocation(line: 13, column: 3, scope: !8)
!13 = !DISubprogram(name: "function", scope: !6, file: !6, line: 7, type: !9, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)
Loading