================ @@ -2333,6 +2352,170 @@ DwarfDebug::emitInitialLocDirective(const MachineFunction &MF, unsigned CUID) { return PrologEndLoc; } +void DwarfDebug::findKeyInstructions(const MachineFunction *MF) { + // New function - reset KeyInstructions. + KeyInstructions.clear(); + + // The current candidate is_stmt instructions for each source atom. + // Map {(InlinedAt, Group): (Rank, Instructions)}. + DenseMap<std::pair<DILocation *, uint32_t>, + std::pair<uint16_t, SmallVector<const MachineInstr *>>> + GroupCandidates; + + // 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. + // * If this instr rank is equal, add this instruction to KeyInstructions. + // Remove existing instructions from KeyInstructions if they have the + // same parent. + // * If this instr rank is higher (lower precedence), ignore it. + // * If this instr rank is lower (higher precedence), erase existing + // instructions from KeyInstructions. Add this instr to KeyInstructions. + + for (auto &MBB : *MF) { + // Rather than apply is_stmt directly to Key Instructions, we "float" + // is_stmt up to the 1st instruction with the same line number in a + // contiguous block. That instruction is called the "buoy". The + // buoy gets reset if we encouner an instruction with an atom + // group. + const MachineInstr *Buoy = nullptr; + // The atom group number associated with Buoy which may be 0 if we haven't + // encountered an atom group yet in this blob of instructions with the same + // line number. + uint64_t BuoyAtom = 0; + + for (auto &MI : MBB) { + if (MI.isMetaInstruction()) + continue; + + if (!MI.getDebugLoc() || !MI.getDebugLoc().getLine()) + continue; + + // Reset the Buoy to this instruciton if it has a different line number. ---------------- jmorse wrote:
```suggestion // Reset the Buoy to this instruction if it has a different line number. ``` https://github.com/llvm/llvm-project/pull/133495 _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits