@@ -2228,26 +2228,15 @@ void DwarfDebug::beginFunctionImpl(const MachineFunction *MF) {
22282228 PrologEndLoc = emitInitialLocDirective (
22292229 *MF, Asm->OutStreamer ->getContext ().getDwarfCompileUnitID ());
22302230
2231- // Try to determine what line we would be stepped on before entering each MBB.
2232- // This happens in the following ways:
2233- // - If this block has a single predecessor, we determine the last line in
2234- // the pred block and we have stepped from that.
2235- // - If this block has multiple predecessors, we determine the last line in
2236- // each of them; if they all agree then we have stepped from that line,
2237- // otherwise we do not know what line we have stepped from.
2238- // The last line in each MBB is determined as follows:
2239- // - If the block contains at least one DebugLoc, we have stepped from the
2240- // last one.
2241- // - Otherwise, the last line is line 0.
2242- // There is one extra rule however: if a predecessor branches to the current
2243- // basic block, we only count DebugLocs on or before that branch, so if we're
2244- // looking at the MBB %bb.0, which ends with:
2245- // JCC_1 %bb.1, 0, !debug-location !1
2246- // JMP_1 %bb.2, !debug-location !2
2247- // We would consider !1 to be the last loc before %bb.1, and !2 before %bb.2.
2248- // We also don't need to make this calculation for any block that doesn't have
2249- // a non-0 line number on its first instruction, as we will always emit line 0
2250- // without is_stmt for that block regardless.
2231+ // For each MBB we try to determine whether and what source line is *always*
2232+ // the last stepped-on line before entering MBB. Such a line exists if every
2233+ // predecessor has an instruction with source line N, which is the last valid
2234+ // source line to be seen before entering MBB, and if N is the same for all
2235+ // predecessors. If this is true, and the first instruction with a valid
2236+ // source line in MBB also has source line N, then that instruction should
2237+ // *not* use is_stmt. Otherwise, the first instruction with a valid source
2238+ // line in MBB should always use is_stmt, since we may step to it from a
2239+ // different line.
22512240 ForceIsStmtInstrs.clear ();
22522241
22532242 // First, collect the last stepped line for each MBB.
@@ -2266,20 +2255,18 @@ void DwarfDebug::beginFunctionImpl(const MachineFunction *MF) {
22662255 continue ;
22672256 for (auto &MI : MBB) {
22682257 if (MI.getDebugLoc () && MI.getDebugLoc ()->getLine ()) {
2269- for (auto Pred : MBB.predecessors ())
2270- PredMBBsToExamine.insert (&* Pred);
2258+ for (auto * Pred : MBB.predecessors ())
2259+ PredMBBsToExamine.insert (Pred);
22712260 PotentialIsStmtMBBInstrs.insert ({&MBB, &MI});
22722261 break ;
22732262 }
22742263 }
22752264 }
22762265
22772266 // For each predecessor MBB, we examine the last DebugLoc seen before each
2278- // branch or logical fallthrough. We're generous with applying is_stmt; if
2267+ // branch or logical fallthrough. We're generous with applying is_stmt: if
22792268 // there's an edge that TargetInstrInfo::analyzeBranch can't understand, we
2280- // simply assume that is_stmt ought to be applied to the successors, since
2281- // this rule is mainly intended to avoid excessive stepping on lines that
2282- // expand to many lines of code.
2269+ // assume that all successor MBBs use the last DebugLoc seen.
22832270 for (auto *MBB : PredMBBsToExamine) {
22842271 auto CheckMBBEdge = [&](MachineBasicBlock *Succ, unsigned OutgoingLine) {
22852272 auto MBBInstrIt = PotentialIsStmtMBBInstrs.find (Succ);
@@ -2312,7 +2299,6 @@ void DwarfDebug::beginFunctionImpl(const MachineFunction *MF) {
23122299 unsigned FBBLine = MBB->back ().getDebugLoc ()->getLine ();
23132300 assert (MIIt->isBranch () && " Bad result from analyzeBranch?" );
23142301 CheckMBBEdge (FBB, FBBLine);
2315- FBB = nullptr ;
23162302 ++MIIt;
23172303 SuccessorBBs.push_back (TBB);
23182304 } else {
@@ -2344,7 +2330,7 @@ void DwarfDebug::beginFunctionImpl(const MachineFunction *MF) {
23442330 }
23452331 ++MIIt;
23462332 }
2347- for (auto Succ : SuccessorBBs)
2333+ for (auto * Succ : SuccessorBBs)
23482334 CheckMBBEdge (Succ, LastLine);
23492335 }
23502336}
0 commit comments