Skip to content

Commit b1943f4

Browse files
authored
[BranchFolding] Remove getBranchDebugLoc() (llvm#114613)
1 parent 511dc26 commit b1943f4

File tree

1 file changed

+17
-25
lines changed

1 file changed

+17
-25
lines changed

llvm/lib/CodeGen/BranchFolding.cpp

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,15 +1268,6 @@ static bool IsBetterFallthrough(MachineBasicBlock *MBB1,
12681268
return MBB2I->isCall() && !MBB1I->isCall();
12691269
}
12701270

1271-
/// getBranchDebugLoc - Find and return, if any, the DebugLoc of the branch
1272-
/// instructions on the block.
1273-
static DebugLoc getBranchDebugLoc(MachineBasicBlock &MBB) {
1274-
MachineBasicBlock::iterator I = MBB.getLastNonDebugInstr();
1275-
if (I != MBB.end() && I->isBranch())
1276-
return I->getDebugLoc();
1277-
return DebugLoc();
1278-
}
1279-
12801271
static void copyDebugInfoToPredecessor(const TargetInstrInfo *TII,
12811272
MachineBasicBlock &MBB,
12821273
MachineBasicBlock &PredMBB) {
@@ -1403,11 +1394,11 @@ bool BranchFolder::OptimizeBlock(MachineBasicBlock *MBB) {
14031394
// destination, remove the branch, replacing it with an unconditional one or
14041395
// a fall-through.
14051396
if (PriorTBB && PriorTBB == PriorFBB) {
1406-
DebugLoc dl = getBranchDebugLoc(PrevBB);
1397+
DebugLoc Dl = PrevBB.findBranchDebugLoc();
14071398
TII->removeBranch(PrevBB);
14081399
PriorCond.clear();
14091400
if (PriorTBB != MBB)
1410-
TII->insertBranch(PrevBB, PriorTBB, nullptr, PriorCond, dl);
1401+
TII->insertBranch(PrevBB, PriorTBB, nullptr, PriorCond, Dl);
14111402
MadeChange = true;
14121403
++NumBranchOpts;
14131404
goto ReoptimizeBlock;
@@ -1461,9 +1452,9 @@ bool BranchFolder::OptimizeBlock(MachineBasicBlock *MBB) {
14611452
// If the prior block branches somewhere else on the condition and here if
14621453
// the condition is false, remove the uncond second branch.
14631454
if (PriorFBB == MBB) {
1464-
DebugLoc dl = getBranchDebugLoc(PrevBB);
1455+
DebugLoc Dl = PrevBB.findBranchDebugLoc();
14651456
TII->removeBranch(PrevBB);
1466-
TII->insertBranch(PrevBB, PriorTBB, nullptr, PriorCond, dl);
1457+
TII->insertBranch(PrevBB, PriorTBB, nullptr, PriorCond, Dl);
14671458
MadeChange = true;
14681459
++NumBranchOpts;
14691460
goto ReoptimizeBlock;
@@ -1475,9 +1466,9 @@ bool BranchFolder::OptimizeBlock(MachineBasicBlock *MBB) {
14751466
if (PriorTBB == MBB) {
14761467
SmallVector<MachineOperand, 4> NewPriorCond(PriorCond);
14771468
if (!TII->reverseBranchCondition(NewPriorCond)) {
1478-
DebugLoc dl = getBranchDebugLoc(PrevBB);
1469+
DebugLoc Dl = PrevBB.findBranchDebugLoc();
14791470
TII->removeBranch(PrevBB);
1480-
TII->insertBranch(PrevBB, PriorFBB, nullptr, NewPriorCond, dl);
1471+
TII->insertBranch(PrevBB, PriorFBB, nullptr, NewPriorCond, Dl);
14811472
MadeChange = true;
14821473
++NumBranchOpts;
14831474
goto ReoptimizeBlock;
@@ -1513,9 +1504,9 @@ bool BranchFolder::OptimizeBlock(MachineBasicBlock *MBB) {
15131504
LLVM_DEBUG(dbgs() << "\nMoving MBB: " << *MBB
15141505
<< "To make fallthrough to: " << *PriorTBB << "\n");
15151506

1516-
DebugLoc dl = getBranchDebugLoc(PrevBB);
1507+
DebugLoc Dl = PrevBB.findBranchDebugLoc();
15171508
TII->removeBranch(PrevBB);
1518-
TII->insertBranch(PrevBB, MBB, nullptr, NewPriorCond, dl);
1509+
TII->insertBranch(PrevBB, MBB, nullptr, NewPriorCond, Dl);
15191510

15201511
// Move this block to the end of the function.
15211512
MBB->moveAfter(&MF.back());
@@ -1576,9 +1567,9 @@ bool BranchFolder::OptimizeBlock(MachineBasicBlock *MBB) {
15761567
if (CurTBB && CurFBB && CurFBB == MBB && CurTBB != MBB) {
15771568
SmallVector<MachineOperand, 4> NewCond(CurCond);
15781569
if (!TII->reverseBranchCondition(NewCond)) {
1579-
DebugLoc dl = getBranchDebugLoc(*MBB);
1570+
DebugLoc Dl = MBB->findBranchDebugLoc();
15801571
TII->removeBranch(*MBB);
1581-
TII->insertBranch(*MBB, CurFBB, CurTBB, NewCond, dl);
1572+
TII->insertBranch(*MBB, CurFBB, CurTBB, NewCond, Dl);
15821573
MadeChange = true;
15831574
++NumBranchOpts;
15841575
goto ReoptimizeBlock;
@@ -1590,7 +1581,7 @@ bool BranchFolder::OptimizeBlock(MachineBasicBlock *MBB) {
15901581
if (CurTBB && CurCond.empty() && !CurFBB &&
15911582
IsBranchOnlyBlock(MBB) && CurTBB != MBB &&
15921583
!MBB->hasAddressTaken() && !MBB->isEHPad()) {
1593-
DebugLoc dl = getBranchDebugLoc(*MBB);
1584+
DebugLoc Dl = MBB->findBranchDebugLoc();
15941585
// This block may contain just an unconditional branch. Because there can
15951586
// be 'non-branch terminators' in the block, try removing the branch and
15961587
// then seeing if the block is empty.
@@ -1624,9 +1615,9 @@ bool BranchFolder::OptimizeBlock(MachineBasicBlock *MBB) {
16241615
assert(!PriorFBB && "Machine CFG out of date!");
16251616
PriorFBB = MBB;
16261617
}
1627-
DebugLoc pdl = getBranchDebugLoc(PrevBB);
1618+
DebugLoc PrevDl = PrevBB.findBranchDebugLoc();
16281619
TII->removeBranch(PrevBB);
1629-
TII->insertBranch(PrevBB, PriorTBB, PriorFBB, PriorCond, pdl);
1620+
TII->insertBranch(PrevBB, PriorTBB, PriorFBB, PriorCond, PrevDl);
16301621
}
16311622

16321623
// Iterate through all the predecessors, revectoring each in-turn.
@@ -1659,10 +1650,11 @@ bool BranchFolder::OptimizeBlock(MachineBasicBlock *MBB) {
16591650
bool NewCurUnAnalyzable = TII->analyzeBranch(
16601651
*PMBB, NewCurTBB, NewCurFBB, NewCurCond, true);
16611652
if (!NewCurUnAnalyzable && NewCurTBB && NewCurTBB == NewCurFBB) {
1662-
DebugLoc pdl = getBranchDebugLoc(*PMBB);
1653+
DebugLoc PrevDl = PMBB->findBranchDebugLoc();
16631654
TII->removeBranch(*PMBB);
16641655
NewCurCond.clear();
1665-
TII->insertBranch(*PMBB, NewCurTBB, nullptr, NewCurCond, pdl);
1656+
TII->insertBranch(*PMBB, NewCurTBB, nullptr, NewCurCond,
1657+
PrevDl);
16661658
MadeChange = true;
16671659
++NumBranchOpts;
16681660
}
@@ -1681,7 +1673,7 @@ bool BranchFolder::OptimizeBlock(MachineBasicBlock *MBB) {
16811673
}
16821674

16831675
// Add the branch back if the block is more than just an uncond branch.
1684-
TII->insertBranch(*MBB, CurTBB, nullptr, CurCond, dl);
1676+
TII->insertBranch(*MBB, CurTBB, nullptr, CurCond, Dl);
16851677
}
16861678
}
16871679

0 commit comments

Comments
 (0)