@@ -2312,36 +2312,22 @@ DwarfDebug::emitInitialLocDirective(const MachineFunction &MF, unsigned CUID) {
2312
2312
return PrologEndLoc;
2313
2313
}
2314
2314
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 ();
2333
2321
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
2336
2324
// predecessor has an instruction with source line N, which is the last valid
2337
2325
// source line to be seen before entering MBB, and if N is the same for all
2338
2326
// predecessors. If this is true, and the first instruction with a valid
2339
2327
// source line in MBB also has source line N, then that instruction should
2340
2328
// *not* use is_stmt. Otherwise, the first instruction with a valid source
2341
2329
// line in MBB should always use is_stmt, since we may step to it from a
2342
2330
// different line.
2343
- ForceIsStmtInstrs.clear ();
2344
-
2345
2331
// First, collect the last stepped line for each MBB.
2346
2332
SmallDenseMap<std::pair<const MachineBasicBlock *, const MachineBasicBlock *>,
2347
2333
unsigned >
@@ -2351,7 +2337,7 @@ void DwarfDebug::beginFunctionImpl(const MachineFunction *MF) {
2351
2337
// We only need to examine MBBs that could have is_stmt set by this logic.
2352
2338
// We use const_cast even though we won't actually modify MF, because some
2353
2339
// methods we need take a non-const MBB.
2354
- SetVector <MachineBasicBlock *> PredMBBsToExamine;
2340
+ SmallSetVector <MachineBasicBlock *, 4 > PredMBBsToExamine;
2355
2341
SmallDenseMap<MachineBasicBlock *, MachineInstr *> PotentialIsStmtMBBInstrs;
2356
2342
for (auto &MBB : *const_cast <MachineFunction *>(MF)) {
2357
2343
if (MBB.empty () || MBB.pred_empty ())
@@ -2381,9 +2367,19 @@ void DwarfDebug::beginFunctionImpl(const MachineFunction *MF) {
2381
2367
PotentialIsStmtMBBInstrs.erase (MBBInstrIt);
2382
2368
ForceIsStmtInstrs.insert (MI);
2383
2369
};
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
+ }))
2387
2383
continue ;
2388
2384
// If we can't determine what DLs this branch's successors use, just treat
2389
2385
// all the successors as coming from the last DebugLoc.
@@ -2438,6 +2434,29 @@ void DwarfDebug::beginFunctionImpl(const MachineFunction *MF) {
2438
2434
}
2439
2435
}
2440
2436
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
+
2441
2460
unsigned
2442
2461
DwarfDebug::getDwarfCompileUnitIDForLineTable (const DwarfCompileUnit &CU) {
2443
2462
// Set DwarfDwarfCompileUnitID in MCContext to the Compile Unit this function
0 commit comments