[llvm] ac4893d - [NFC][PromoteMem2Reg] Move IncomingVals, IncomingLocs, Worklist into class (#142468)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 3 14:47:48 PDT 2025
Author: Vitaly Buka
Date: 2025-06-03T14:47:45-07:00
New Revision: ac4893dd77eeb67be830b0dac70ad28c4b4f0caf
URL: https://github.com/llvm/llvm-project/commit/ac4893dd77eeb67be830b0dac70ad28c4b4f0caf
DIFF: https://github.com/llvm/llvm-project/commit/ac4893dd77eeb67be830b0dac70ad28c4b4f0caf.diff
LOG: [NFC][PromoteMem2Reg] Move IncomingVals, IncomingLocs, Worklist into class (#142468)
They are all DFS state related, as `Visited`. But `Visited` is already a
class member, so we make things more consistent and less
parameters to pass around.
By itself, the patch has little value, but it simplifies stuff in the
#142474.
For #142461
Added:
Modified:
llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp b/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
index d420aa7a931a0..16a3d20bfd481 100644
--- a/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
+++ b/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
@@ -392,6 +392,15 @@ struct PromoteMem2Reg {
/// number.
SmallVector<unsigned> BBNumPreds;
+ /// The state of incoming values for the current DFS step.
+ RenamePassData::ValVector IncomingVals;
+
+ /// The state of incoming locations for the current DFS step.
+ RenamePassData::LocationVector IncomingLocs;
+
+ // DFS work stack.
+ SmallVector<RenamePassData, 8> Worklist;
+
/// Whether the function has the no-signed-zeros-fp-math attribute set.
bool NoSignedZeros = false;
@@ -423,10 +432,7 @@ struct PromoteMem2Reg {
void ComputeLiveInBlocks(AllocaInst *AI, AllocaInfo &Info,
const SmallPtrSetImpl<BasicBlock *> &DefBlocks,
SmallPtrSetImpl<BasicBlock *> &LiveInBlocks);
- void RenamePass(BasicBlock *BB, BasicBlock *Pred,
- RenamePassData::ValVector IncVals,
- RenamePassData::LocationVector IncLocs,
- std::vector<RenamePassData> &Worklist);
+ void RenamePass(BasicBlock *BB, BasicBlock *Pred);
bool QueuePhiNode(BasicBlock *BB, unsigned AllocaIdx, unsigned &Version);
/// Delete dbg.assigns that have been demoted to dbg.values.
@@ -438,6 +444,20 @@ struct PromoteMem2Reg {
DVR->eraseFromParent();
DVRAssignsToDelete.clear();
}
+
+ void pushToWorklist(BasicBlock *BB, BasicBlock *Pred,
+ RenamePassData::ValVector IncVals,
+ RenamePassData::LocationVector IncLocs) {
+ Worklist.emplace_back(BB, Pred, std::move(IncVals), std::move(IncLocs));
+ }
+
+ RenamePassData popFromWorklist() {
+ RenamePassData R = std::move(Worklist.back());
+ Worklist.pop_back();
+ IncomingVals = std::move(R.Values);
+ IncomingLocs = std::move(R.Locations);
+ return R;
+ }
};
} // end anonymous namespace
@@ -849,29 +869,26 @@ void PromoteMem2Reg::run() {
// Set the incoming values for the basic block to be null values for all of
// the alloca's. We do this in case there is a load of a value that has not
// been stored yet. In this case, it will get this null value.
- RenamePassData::ValVector Values(Allocas.size());
+ IncomingVals.resize(Allocas.size());
for (unsigned i = 0, e = Allocas.size(); i != e; ++i)
- Values[i] = UndefValue::get(Allocas[i]->getAllocatedType());
+ IncomingVals[i] = UndefValue::get(Allocas[i]->getAllocatedType());
// When handling debug info, treat all incoming values as if they have unknown
// locations until proven otherwise.
- RenamePassData::LocationVector Locations(Allocas.size());
+ IncomingLocs.resize(Allocas.size());
// The renamer uses the Visited set to avoid infinite loops.
Visited.resize(F.getMaxBlockNumber());
// Walks all basic blocks in the function performing the SSA rename algorithm
// and inserting the phi nodes we marked as necessary
- std::vector<RenamePassData> RenamePassWorkList;
- RenamePassWorkList.emplace_back(&F.front(), nullptr, std::move(Values),
- std::move(Locations));
+ pushToWorklist(&F.front(), nullptr, std::move(IncomingVals),
+ std::move(IncomingLocs));
do {
- RenamePassData RPD = std::move(RenamePassWorkList.back());
- RenamePassWorkList.pop_back();
+ RenamePassData RPD = popFromWorklist();
// RenamePass may add new worklist entries.
- RenamePass(RPD.BB, RPD.Pred, std::move(RPD.Values),
- std::move(RPD.Locations), RenamePassWorkList);
- } while (!RenamePassWorkList.empty());
+ RenamePass(RPD.BB, RPD.Pred);
+ } while (!Worklist.empty());
// Remove the allocas themselves from the function.
for (Instruction *A : Allocas) {
@@ -1096,10 +1113,7 @@ 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,
- std::vector<RenamePassData> &Worklist) {
+void PromoteMem2Reg::RenamePass(BasicBlock *BB, BasicBlock *Pred) {
// 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())) {
@@ -1226,8 +1240,7 @@ void PromoteMem2Reg::RenamePass(BasicBlock *BB, BasicBlock *Pred,
IncomingVals = Worklist.back().Values;
IncomingLocs = Worklist.back().Locations;
}
- Worklist.emplace_back(S, BB, std::move(IncomingVals),
- std::move(IncomingLocs));
+ pushToWorklist(S, BB, std::move(IncomingVals), std::move(IncomingLocs));
}
}
More information about the llvm-commits
mailing list