Skip to content

Commit 7813158

Browse files
committed
Address review comments
1 parent 05ec291 commit 7813158

File tree

2 files changed

+47
-26
lines changed

2 files changed

+47
-26
lines changed

llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp

Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2312,36 +2312,22 @@ DwarfDebug::emitInitialLocDirective(const MachineFunction &MF, unsigned CUID) {
23122312
return PrologEndLoc;
23132313
}
23142314

2315-
// Gather pre-function debug information. Assumes being called immediately
2316-
// after the function entry point has been emitted.
2317-
void DwarfDebug::beginFunctionImpl(const MachineFunction *MF) {
2318-
CurFn = MF;
2319-
2320-
auto *SP = MF->getFunction().getSubprogram();
2321-
assert(LScopes.empty() || SP == LScopes.getCurrentFunctionScope()->getScopeNode());
2322-
if (SP->getUnit()->getEmissionKind() == DICompileUnit::NoDebug)
2323-
return;
2324-
2325-
DwarfCompileUnit &CU = getOrCreateDwarfCompileUnit(SP->getUnit());
2326-
2327-
Asm->OutStreamer->getContext().setDwarfCompileUnitID(
2328-
getDwarfCompileUnitIDForLineTable(CU));
2329-
2330-
// Record beginning of function.
2331-
PrologEndLoc = emitInitialLocDirective(
2332-
*MF, Asm->OutStreamer->getContext().getDwarfCompileUnitID());
2315+
/// For the function \p MF, finds the set of instructions which may represent a
2316+
/// change in line number from one or more of the preceding MBBs. Stores the
2317+
/// resulting set of instructions, which should have is_stmt set, in
2318+
/// ForceIsStmtInstrs.
2319+
void DwarfDebug::findForceIsStmtInstrs(const MachineFunction *MF) {
2320+
ForceIsStmtInstrs.clear();
23332321

2334-
// For each MBB we try to determine whether and what source line is *always*
2335-
// the last stepped-on line before entering MBB. Such a line exists if every
2322+
// Here we try to find MBBs where the last line stepped on before entering
2323+
// it is always the same, and which line that is. Such a line exists if every
23362324
// predecessor has an instruction with source line N, which is the last valid
23372325
// source line to be seen before entering MBB, and if N is the same for all
23382326
// predecessors. If this is true, and the first instruction with a valid
23392327
// source line in MBB also has source line N, then that instruction should
23402328
// *not* use is_stmt. Otherwise, the first instruction with a valid source
23412329
// line in MBB should always use is_stmt, since we may step to it from a
23422330
// different line.
2343-
ForceIsStmtInstrs.clear();
2344-
23452331
// First, collect the last stepped line for each MBB.
23462332
SmallDenseMap<std::pair<const MachineBasicBlock *, const MachineBasicBlock *>,
23472333
unsigned>
@@ -2351,7 +2337,7 @@ void DwarfDebug::beginFunctionImpl(const MachineFunction *MF) {
23512337
// We only need to examine MBBs that could have is_stmt set by this logic.
23522338
// We use const_cast even though we won't actually modify MF, because some
23532339
// methods we need take a non-const MBB.
2354-
SetVector<MachineBasicBlock *> PredMBBsToExamine;
2340+
SmallSetVector<MachineBasicBlock *, 4> PredMBBsToExamine;
23552341
SmallDenseMap<MachineBasicBlock *, MachineInstr *> PotentialIsStmtMBBInstrs;
23562342
for (auto &MBB : *const_cast<MachineFunction *>(MF)) {
23572343
if (MBB.empty() || MBB.pred_empty())
@@ -2381,9 +2367,19 @@ void DwarfDebug::beginFunctionImpl(const MachineFunction *MF) {
23812367
PotentialIsStmtMBBInstrs.erase(MBBInstrIt);
23822368
ForceIsStmtInstrs.insert(MI);
23832369
};
2384-
// If this block is empty, it technically has a fall through but we should
2385-
// assume it is irrelevant for the purposes of calculating is_stmt.
2386-
if (MBB->empty())
2370+
// If this block is empty, we conservatively assume that its fallthrough
2371+
// successor needs is_stmt; we could check MBB's predecessors to see if it
2372+
// has a consistent entry line, but this seems unlikely to be worthwhile.
2373+
if (MBB->empty()) {
2374+
for (auto *Succ : MBB->successors())
2375+
CheckMBBEdge(Succ, 0);
2376+
continue;
2377+
}
2378+
// If MBB has no successors that are in the "potential" set, due to one or
2379+
// more of them having confirmed is_stmt, we can skip this check early.
2380+
if (none_of(MBB->successors(), [&](auto *SuccMBB) {
2381+
return PotentialIsStmtMBBInstrs.contains(SuccMBB);
2382+
}))
23872383
continue;
23882384
// If we can't determine what DLs this branch's successors use, just treat
23892385
// all the successors as coming from the last DebugLoc.
@@ -2438,6 +2434,29 @@ void DwarfDebug::beginFunctionImpl(const MachineFunction *MF) {
24382434
}
24392435
}
24402436

2437+
// Gather pre-function debug information. Assumes being called immediately
2438+
// after the function entry point has been emitted.
2439+
void DwarfDebug::beginFunctionImpl(const MachineFunction *MF) {
2440+
CurFn = MF;
2441+
2442+
auto *SP = MF->getFunction().getSubprogram();
2443+
assert(LScopes.empty() ||
2444+
SP == LScopes.getCurrentFunctionScope()->getScopeNode());
2445+
if (SP->getUnit()->getEmissionKind() == DICompileUnit::NoDebug)
2446+
return;
2447+
2448+
DwarfCompileUnit &CU = getOrCreateDwarfCompileUnit(SP->getUnit());
2449+
2450+
Asm->OutStreamer->getContext().setDwarfCompileUnitID(
2451+
getDwarfCompileUnitIDForLineTable(CU));
2452+
2453+
// Record beginning of function.
2454+
PrologEndLoc = emitInitialLocDirective(
2455+
*MF, Asm->OutStreamer->getContext().getDwarfCompileUnitID());
2456+
2457+
findForceIsStmtInstrs(MF);
2458+
}
2459+
24412460
unsigned
24422461
DwarfDebug::getDwarfCompileUnitIDForLineTable(const DwarfCompileUnit &CU) {
24432462
// Set DwarfDwarfCompileUnitID in MCContext to the Compile Unit this function

llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,8 @@ class DwarfDebug : public DebugHandlerBase {
696696
/// Emit the reference to the section.
697697
void emitSectionReference(const DwarfCompileUnit &CU);
698698

699+
void findForceIsStmtInstrs(const MachineFunction *MF);
700+
699701
protected:
700702
/// Gather pre-function debug information.
701703
void beginFunctionImpl(const MachineFunction *MF) override;

0 commit comments

Comments
 (0)