Skip to content

Commit b9dec5a

Browse files
authored
[NFC] Remove goto in PromoteMem2Reg::RenamePass (#142454)
'goto' is essentially a shortcut for push/pop for worklist. It can be expensive if we copy vectors, but if we move them, it should not be an issue. Without 'goto' it's easier to reason about the code, when `PromoteMem2Reg::RenamePass` processes exactly one edge at a time. There is out of order processing of the first successor, I keep it just to make this patch pure NFC. I'll remove this in follow up patches. For #142461
1 parent b40e4ce commit b9dec5a

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -424,8 +424,8 @@ struct PromoteMem2Reg {
424424
const SmallPtrSetImpl<BasicBlock *> &DefBlocks,
425425
SmallPtrSetImpl<BasicBlock *> &LiveInBlocks);
426426
void RenamePass(BasicBlock *BB, BasicBlock *Pred,
427-
RenamePassData::ValVector &IncVals,
428-
RenamePassData::LocationVector &IncLocs,
427+
RenamePassData::ValVector IncVals,
428+
RenamePassData::LocationVector IncLocs,
429429
std::vector<RenamePassData> &Worklist);
430430
bool QueuePhiNode(BasicBlock *BB, unsigned AllocaIdx, unsigned &Version);
431431

@@ -869,7 +869,8 @@ void PromoteMem2Reg::run() {
869869
RenamePassData RPD = std::move(RenamePassWorkList.back());
870870
RenamePassWorkList.pop_back();
871871
// RenamePass may add new worklist entries.
872-
RenamePass(RPD.BB, RPD.Pred, RPD.Values, RPD.Locations, RenamePassWorkList);
872+
RenamePass(RPD.BB, RPD.Pred, std::move(RPD.Values),
873+
std::move(RPD.Locations), RenamePassWorkList);
873874
} while (!RenamePassWorkList.empty());
874875

875876
// Remove the allocas themselves from the function.
@@ -1096,10 +1097,9 @@ static void updateForIncomingValueLocation(PHINode *PN, DebugLoc DL,
10961097
/// IncomingVals indicates what value each Alloca contains on exit from the
10971098
/// predecessor block Pred.
10981099
void PromoteMem2Reg::RenamePass(BasicBlock *BB, BasicBlock *Pred,
1099-
RenamePassData::ValVector &IncomingVals,
1100-
RenamePassData::LocationVector &IncomingLocs,
1100+
RenamePassData::ValVector IncomingVals,
1101+
RenamePassData::LocationVector IncomingLocs,
11011102
std::vector<RenamePassData> &Worklist) {
1102-
NextIteration:
11031103
// If we are inserting any phi nodes into this BB, they will already be in the
11041104
// block.
11051105
if (PHINode *APN = dyn_cast<PHINode>(BB->begin())) {
@@ -1222,17 +1222,17 @@ void PromoteMem2Reg::RenamePass(BasicBlock *BB, BasicBlock *Pred,
12221222
// Keep track of the successors so we don't visit the same successor twice
12231223
SmallPtrSet<BasicBlock *, 8> VisitedSuccs;
12241224

1225-
// Handle the first successor without using the worklist.
1225+
// Handle the first successor after the rest, to mimic legacy behaviour.
1226+
// FIXME: Handle them in regular order.
12261227
VisitedSuccs.insert(*I);
1227-
Pred = BB;
1228-
BB = *I;
12291228
++I;
12301229

12311230
for (; I != E; ++I)
12321231
if (VisitedSuccs.insert(*I).second)
1233-
Worklist.emplace_back(*I, Pred, IncomingVals, IncomingLocs);
1232+
Worklist.emplace_back(*I, BB, IncomingVals, IncomingLocs);
12341233

1235-
goto NextIteration;
1234+
Worklist.emplace_back(*succ_begin(BB), BB, std::move(IncomingVals),
1235+
std::move(IncomingLocs));
12361236
}
12371237

12381238
void llvm::PromoteMemToReg(ArrayRef<AllocaInst *> Allocas, DominatorTree &DT,

0 commit comments

Comments
 (0)