aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib
diff options
context:
space:
mode:
authorVitaly Buka <vitalybuka@google.com>2025-06-03 09:14:04 -0700
committerGitHub <noreply@github.com>2025-06-03 09:14:04 -0700
commitb9dec5aa793fbdb3b5db6b240f28bd18f13dbc9e (patch)
tree2c1ebd221566d58a48ef9773229302054aadde37 /llvm/lib
parentb40e4ceaa61c5f14ca261e2952e7f85a066403e2 (diff)
downloadllvm-b9dec5aa793fbdb3b5db6b240f28bd18f13dbc9e.zip
llvm-b9dec5aa793fbdb3b5db6b240f28bd18f13dbc9e.tar.gz
llvm-b9dec5aa793fbdb3b5db6b240f28bd18f13dbc9e.tar.bz2
[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
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp22
1 files changed, 11 insertions, 11 deletions
diff --git a/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp b/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
index 6ba6496..d84b07b 100644
--- a/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
+++ b/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
@@ -424,8 +424,8 @@ private:
const SmallPtrSetImpl<BasicBlock *> &DefBlocks,
SmallPtrSetImpl<BasicBlock *> &LiveInBlocks);
void RenamePass(BasicBlock *BB, BasicBlock *Pred,
- RenamePassData::ValVector &IncVals,
- RenamePassData::LocationVector &IncLocs,
+ RenamePassData::ValVector IncVals,
+ RenamePassData::LocationVector IncLocs,
std::vector<RenamePassData> &Worklist);
bool QueuePhiNode(BasicBlock *BB, unsigned AllocaIdx, unsigned &Version);
@@ -869,7 +869,8 @@ void PromoteMem2Reg::run() {
RenamePassData RPD = std::move(RenamePassWorkList.back());
RenamePassWorkList.pop_back();
// RenamePass may add new worklist entries.
- RenamePass(RPD.BB, RPD.Pred, RPD.Values, RPD.Locations, RenamePassWorkList);
+ RenamePass(RPD.BB, RPD.Pred, std::move(RPD.Values),
+ std::move(RPD.Locations), RenamePassWorkList);
} while (!RenamePassWorkList.empty());
// Remove the allocas themselves from the function.
@@ -1096,10 +1097,9 @@ static void updateForIncomingValueLocation(PHINode *PN, DebugLoc DL,
/// IncomingVals indicates what value each Alloca contains on exit from the
/// predecessor block Pred.
void PromoteMem2Reg::RenamePass(BasicBlock *BB, BasicBlock *Pred,
- RenamePassData::ValVector &IncomingVals,
- RenamePassData::LocationVector &IncomingLocs,
+ RenamePassData::ValVector IncomingVals,
+ RenamePassData::LocationVector IncomingLocs,
std::vector<RenamePassData> &Worklist) {
-NextIteration:
// If we are inserting any phi nodes into this BB, they will already be in the
// block.
if (PHINode *APN = dyn_cast<PHINode>(BB->begin())) {
@@ -1222,17 +1222,17 @@ NextIteration:
// Keep track of the successors so we don't visit the same successor twice
SmallPtrSet<BasicBlock *, 8> VisitedSuccs;
- // Handle the first successor without using the worklist.
+ // Handle the first successor after the rest, to mimic legacy behaviour.
+ // FIXME: Handle them in regular order.
VisitedSuccs.insert(*I);
- Pred = BB;
- BB = *I;
++I;
for (; I != E; ++I)
if (VisitedSuccs.insert(*I).second)
- Worklist.emplace_back(*I, Pred, IncomingVals, IncomingLocs);
+ Worklist.emplace_back(*I, BB, IncomingVals, IncomingLocs);
- goto NextIteration;
+ Worklist.emplace_back(*succ_begin(BB), BB, std::move(IncomingVals),
+ std::move(IncomingLocs));
}
void llvm::PromoteMemToReg(ArrayRef<AllocaInst *> Allocas, DominatorTree &DT,