Index: lib/CodeGen/AsmPrinter/DebugHandlerBase.h =================================================================== --- lib/CodeGen/AsmPrinter/DebugHandlerBase.h +++ lib/CodeGen/AsmPrinter/DebugHandlerBase.h @@ -49,6 +49,10 @@ extractFromMachineInstruction(const MachineInstr &Instruction); }; +typedef std::pair LabelInfo; +typedef std::pair InlinedLabel; +typedef SmallVector DbgLabelList; + /// Base class for debug information backends. Common functionality related to /// tracking which variables and scopes are alive at a given PC live here. class DebugHandlerBase : public AsmPrinterHandler { @@ -82,6 +86,9 @@ /// variable. Variables are listed in order of appearance. DbgValueHistoryMap DbgValues; + /// Labels are listed in order of appearance. + DbgLabelList DbgLabels; + /// Maps instruction with label emitted before instruction. /// FIXME: Make this private from DwarfDebug, we have the necessary accessors /// for it. @@ -104,6 +111,8 @@ LabelsAfterInsn.insert(std::make_pair(MI, nullptr)); } + void collectDbgLabel(const MachineFunction *MF, DbgLabelList &Result); + virtual void beginFunctionImpl(const MachineFunction *MF) = 0; virtual void endFunctionImpl(const MachineFunction *MF) = 0; virtual void skippedNonDebugFunction() {} Index: lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp =================================================================== --- lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp +++ lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp @@ -167,6 +167,24 @@ return true; } +void DebugHandlerBase::collectDbgLabel(const MachineFunction *MF, + DbgLabelList &Result) { + for (const auto &MBB : *MF) { + for (const auto &MI : MBB) { + if (MI.isDebugLabel()) { + assert(MI.getNumOperands() == 1 && "Invalid DBG_LABEL instruction!"); + const DILabel *RawLabel = MI.getDebugLabel(); + assert(RawLabel->isValidLocationForIntrinsic(MI.getDebugLoc()) && + "Expected inlined-at fields to agree"); + requestLabelBeforeInsn(&MI); + Result.push_back(std::make_pair(RawLabel, + std::make_pair(MI.getDebugLoc()->getInlinedAt(), + &MI))); + } + } + } +} + void DebugHandlerBase::beginFunction(const MachineFunction *MF) { PrevInstBB = nullptr; @@ -191,6 +209,9 @@ calculateDbgValueHistory(MF, Asm->MF->getSubtarget().getRegisterInfo(), DbgValues); + // Collect local labels. + collectDbgLabel(MF, DbgLabels); + // Request labels for the full history. for (const auto &I : DbgValues) { const auto &Ranges = I.second;