diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index 47c44efa8e73c..11b85763a3fb1 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -2383,6 +2383,8 @@ void DwarfDebug::computeKeyInstructions(const MachineFunction *MF) { std::pair>> GroupCandidates; + const auto &TII = *MF->getSubtarget().getInstrInfo(); + // For each instruction: // * Skip insts without DebugLoc, AtomGroup or AtomRank, and line zeros. // * Check if insts in this group have been seen already in GroupCandidates. @@ -2411,24 +2413,20 @@ void DwarfDebug::computeKeyInstructions(const MachineFunction *MF) { if (MI.isMetaInstruction()) continue; - if (!MI.getDebugLoc() || !MI.getDebugLoc().getLine()) + const DILocation *Loc = MI.getDebugLoc().get(); + if (!Loc || !Loc->getLine()) continue; // Reset the Buoy to this instruction if it has a different line number. - if (!Buoy || - Buoy->getDebugLoc().getLine() != MI.getDebugLoc().getLine()) { + if (!Buoy || Buoy->getDebugLoc().getLine() != Loc->getLine()) { Buoy = &MI; BuoyAtom = 0; // Set later when we know which atom the buoy is used by. } // Call instructions are handled specially - we always mark them as key // regardless of atom info. - const auto &TII = - *MI.getParent()->getParent()->getSubtarget().getInstrInfo(); bool IsCallLike = MI.isCall() || TII.isTailCall(MI); if (IsCallLike) { - assert(MI.getDebugLoc() && "Unexpectedly missing DL"); - // Calls are always key. Put the buoy (may not be the call) into // KeyInstructions directly rather than the candidate map to avoid it // being erased (and we may not have a group number for the call). @@ -2438,14 +2436,13 @@ void DwarfDebug::computeKeyInstructions(const MachineFunction *MF) { Buoy = nullptr; BuoyAtom = 0; - if (!MI.getDebugLoc()->getAtomGroup() || - !MI.getDebugLoc()->getAtomRank()) + if (!Loc->getAtomGroup() || !Loc->getAtomRank()) continue; } - auto *InlinedAt = MI.getDebugLoc()->getInlinedAt(); - uint64_t Group = MI.getDebugLoc()->getAtomGroup(); - uint8_t Rank = MI.getDebugLoc()->getAtomRank(); + auto *InlinedAt = Loc->getInlinedAt(); + uint64_t Group = Loc->getAtomGroup(); + uint8_t Rank = Loc->getAtomRank(); if (!Group || !Rank) continue; @@ -2487,8 +2484,8 @@ void DwarfDebug::computeKeyInstructions(const MachineFunction *MF) { CandidateInsts.push_back(Buoy); CandidateRank = Rank; - assert(!BuoyAtom || BuoyAtom == MI.getDebugLoc()->getAtomGroup()); - BuoyAtom = MI.getDebugLoc()->getAtomGroup(); + assert(!BuoyAtom || BuoyAtom == Loc->getAtomGroup()); + BuoyAtom = Loc->getAtomGroup(); } else { // Don't add calls, because they've been dealt with already. This means // CandidateInsts might now be empty - handle that.