@@ -2062,7 +2062,6 @@ void DwarfDebug::beginInstruction(const MachineInstr *MI) {
2062
2062
unsigned LastAsmLine =
2063
2063
Asm->OutStreamer ->getContext ().getCurrentDwarfLoc ().getLine ();
2064
2064
2065
- <<<<<<< HEAD
2066
2065
if (!DL && MI == PrologEndLoc) {
2067
2066
// In rare situations, we might want to place the end of the prologue
2068
2067
// somewhere that doesn't have a source location already. It should be in
@@ -2073,11 +2072,9 @@ void DwarfDebug::beginInstruction(const MachineInstr *MI) {
2073
2072
return ;
2074
2073
}
2075
2074
2076
- =======
2077
2075
bool PrevInstInSameSection =
2078
2076
(!PrevInstBB ||
2079
2077
PrevInstBB->getSectionID () == MI->getParent ()->getSectionID ());
2080
- >>>>>>> ac5931e8f979 (Re-add unnecessarily removed code)
2081
2078
bool ForceIsStmt = ForceIsStmtInstrs.contains (MI);
2082
2079
if (DL == PrevInstLoc && PrevInstInSameSection && !ForceIsStmt) {
2083
2080
// If we have an ongoing unspecified location, nothing to do here.
@@ -2319,26 +2316,40 @@ DwarfDebug::emitInitialLocDirective(const MachineFunction &MF, unsigned CUID) {
2319
2316
void DwarfDebug::findForceIsStmtInstrs (const MachineFunction *MF) {
2320
2317
ForceIsStmtInstrs.clear ();
2321
2318
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
2324
- // predecessor has an instruction with source line N, which is the last valid
2325
- // source line to be seen before entering MBB, and if N is the same for all
2326
- // predecessors. If this is true, and the first instruction with a valid
2327
- // source line in MBB also has source line N, then that instruction should
2328
- // *not* use is_stmt. Otherwise, the first instruction with a valid source
2329
- // line in MBB should always use is_stmt, since we may step to it from a
2330
- // different line.
2331
- // First, collect the last stepped line for each MBB.
2332
- SmallDenseMap<std::pair<const MachineBasicBlock *, const MachineBasicBlock *>,
2333
- unsigned >
2334
- MBBExitLines;
2319
+ // For this function, we try to find MBBs where the last source line in every
2320
+ // block predecessor matches the first line seen in the block itself; for
2321
+ // every such MBB, we set is_stmt=false on the first line in the block, and
2322
+ // for every other block we set is_stmt=true on the first line.
2323
+ // For example, if we have the block %bb.3, which has 2 predecesors %bb.1 and
2324
+ // %bb.2:
2325
+ // bb.1:
2326
+ // $r3 = MOV64ri 12, debug-location !DILocation(line: 4)
2327
+ // JMP %bb.3, debug-location !DILocation(line: 5)
2328
+ // bb.2:
2329
+ // $r3 = MOV64ri 24, debug-location !DILocation(line: 5)
2330
+ // JMP %bb.3
2331
+ // bb.3:
2332
+ // $r2 = MOV64ri 1
2333
+ // $r1 = ADD $r2, $r3, debug-location !DILocation(line: 5)
2334
+ // When we examine %bb.3, we first check to see if it contains any
2335
+ // instructions with debug locations, and select the first such instruction;
2336
+ // in this case, the ADD, with line=5. We then examine both of its
2337
+ // predecessors to see what the last debug-location in them is. For each
2338
+ // predecessor, if they do not contain any debug-locations, or if the last
2339
+ // debug-location before jumping to %bb.3 does not have line=5, then the ADD
2340
+ // in %bb.3 must use IsStmt. In this case, all predecessors have a
2341
+ // debug-location with line=5 as the last debug-location before jumping to
2342
+ // %bb.3, so we do not set is_stmt for the ADD instruction - we know that
2343
+ // whichever MBB we have arrived from, the line has not changed.
2344
+
2335
2345
const auto *TII = MF->getSubtarget ().getInstrInfo ();
2336
2346
2337
- // We only need to examine MBBs that could have is_stmt set by this logic.
2347
+ // We only need to the predecessors of MBBs that could have is_stmt set by
2348
+ // this logic.
2349
+ SmallDenseSet<MachineBasicBlock *, 4 > PredMBBsToExamine;
2350
+ SmallDenseMap<MachineBasicBlock *, MachineInstr *> PotentialIsStmtMBBInstrs;
2338
2351
// We use const_cast even though we won't actually modify MF, because some
2339
2352
// methods we need take a non-const MBB.
2340
- SmallSetVector<MachineBasicBlock *, 4 > PredMBBsToExamine;
2341
- SmallDenseMap<MachineBasicBlock *, MachineInstr *> PotentialIsStmtMBBInstrs;
2342
2353
for (auto &MBB : *const_cast <MachineFunction *>(MF)) {
2343
2354
if (MBB.empty () || MBB.pred_empty ())
2344
2355
continue ;
@@ -2352,10 +2363,11 @@ void DwarfDebug::findForceIsStmtInstrs(const MachineFunction *MF) {
2352
2363
}
2353
2364
}
2354
2365
2355
- // For each predecessor MBB, we examine the last DebugLoc seen before each
2356
- // branch or logical fallthrough. We're generous with applying is_stmt: if
2357
- // there's an edge that TargetInstrInfo::analyzeBranch can't understand, we
2358
- // assume that all successor MBBs use the last DebugLoc seen.
2366
+ // For each predecessor MBB, we examine the last line seen before each branch
2367
+ // or logical fallthrough. We use analyzeBranch to handle cases where
2368
+ // different branches have different outgoing lines (i.e. if there are
2369
+ // multiple branches that each have their own source location); otherwise we
2370
+ // just use the last line in the block.
2359
2371
for (auto *MBB : PredMBBsToExamine) {
2360
2372
auto CheckMBBEdge = [&](MachineBasicBlock *Succ, unsigned OutgoingLine) {
2361
2373
auto MBBInstrIt = PotentialIsStmtMBBInstrs.find (Succ);
@@ -2440,8 +2452,7 @@ void DwarfDebug::beginFunctionImpl(const MachineFunction *MF) {
2440
2452
CurFn = MF;
2441
2453
2442
2454
auto *SP = MF->getFunction ().getSubprogram ();
2443
- assert (LScopes.empty () ||
2444
- SP == LScopes.getCurrentFunctionScope ()->getScopeNode ());
2455
+ assert (LScopes.empty () || SP == LScopes.getCurrentFunctionScope ()->getScopeNode ());
2445
2456
if (SP->getUnit ()->getEmissionKind () == DICompileUnit::NoDebug)
2446
2457
return ;
2447
2458
0 commit comments