Skip to content

Commit ac4893d

Browse files
authored
[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
1 parent 857138b commit ac4893d

File tree

1 file changed

+34
-21
lines changed

1 file changed

+34
-21
lines changed

llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,15 @@ struct PromoteMem2Reg {
392392
/// number.
393393
SmallVector<unsigned> BBNumPreds;
394394

395+
/// The state of incoming values for the current DFS step.
396+
RenamePassData::ValVector IncomingVals;
397+
398+
/// The state of incoming locations for the current DFS step.
399+
RenamePassData::LocationVector IncomingLocs;
400+
401+
// DFS work stack.
402+
SmallVector<RenamePassData, 8> Worklist;
403+
395404
/// Whether the function has the no-signed-zeros-fp-math attribute set.
396405
bool NoSignedZeros = false;
397406

@@ -423,10 +432,7 @@ struct PromoteMem2Reg {
423432
void ComputeLiveInBlocks(AllocaInst *AI, AllocaInfo &Info,
424433
const SmallPtrSetImpl<BasicBlock *> &DefBlocks,
425434
SmallPtrSetImpl<BasicBlock *> &LiveInBlocks);
426-
void RenamePass(BasicBlock *BB, BasicBlock *Pred,
427-
RenamePassData::ValVector IncVals,
428-
RenamePassData::LocationVector IncLocs,
429-
std::vector<RenamePassData> &Worklist);
435+
void RenamePass(BasicBlock *BB, BasicBlock *Pred);
430436
bool QueuePhiNode(BasicBlock *BB, unsigned AllocaIdx, unsigned &Version);
431437

432438
/// Delete dbg.assigns that have been demoted to dbg.values.
@@ -438,6 +444,20 @@ struct PromoteMem2Reg {
438444
DVR->eraseFromParent();
439445
DVRAssignsToDelete.clear();
440446
}
447+
448+
void pushToWorklist(BasicBlock *BB, BasicBlock *Pred,
449+
RenamePassData::ValVector IncVals,
450+
RenamePassData::LocationVector IncLocs) {
451+
Worklist.emplace_back(BB, Pred, std::move(IncVals), std::move(IncLocs));
452+
}
453+
454+
RenamePassData popFromWorklist() {
455+
RenamePassData R = std::move(Worklist.back());
456+
Worklist.pop_back();
457+
IncomingVals = std::move(R.Values);
458+
IncomingLocs = std::move(R.Locations);
459+
return R;
460+
}
441461
};
442462

443463
} // end anonymous namespace
@@ -849,29 +869,26 @@ void PromoteMem2Reg::run() {
849869
// Set the incoming values for the basic block to be null values for all of
850870
// the alloca's. We do this in case there is a load of a value that has not
851871
// been stored yet. In this case, it will get this null value.
852-
RenamePassData::ValVector Values(Allocas.size());
872+
IncomingVals.resize(Allocas.size());
853873
for (unsigned i = 0, e = Allocas.size(); i != e; ++i)
854-
Values[i] = UndefValue::get(Allocas[i]->getAllocatedType());
874+
IncomingVals[i] = UndefValue::get(Allocas[i]->getAllocatedType());
855875

856876
// When handling debug info, treat all incoming values as if they have unknown
857877
// locations until proven otherwise.
858-
RenamePassData::LocationVector Locations(Allocas.size());
878+
IncomingLocs.resize(Allocas.size());
859879

860880
// The renamer uses the Visited set to avoid infinite loops.
861881
Visited.resize(F.getMaxBlockNumber());
862882

863883
// Walks all basic blocks in the function performing the SSA rename algorithm
864884
// and inserting the phi nodes we marked as necessary
865-
std::vector<RenamePassData> RenamePassWorkList;
866-
RenamePassWorkList.emplace_back(&F.front(), nullptr, std::move(Values),
867-
std::move(Locations));
885+
pushToWorklist(&F.front(), nullptr, std::move(IncomingVals),
886+
std::move(IncomingLocs));
868887
do {
869-
RenamePassData RPD = std::move(RenamePassWorkList.back());
870-
RenamePassWorkList.pop_back();
888+
RenamePassData RPD = popFromWorklist();
871889
// RenamePass may add new worklist entries.
872-
RenamePass(RPD.BB, RPD.Pred, std::move(RPD.Values),
873-
std::move(RPD.Locations), RenamePassWorkList);
874-
} while (!RenamePassWorkList.empty());
890+
RenamePass(RPD.BB, RPD.Pred);
891+
} while (!Worklist.empty());
875892

876893
// Remove the allocas themselves from the function.
877894
for (Instruction *A : Allocas) {
@@ -1096,10 +1113,7 @@ static void updateForIncomingValueLocation(PHINode *PN, DebugLoc DL,
10961113
///
10971114
/// IncomingVals indicates what value each Alloca contains on exit from the
10981115
/// predecessor block Pred.
1099-
void PromoteMem2Reg::RenamePass(BasicBlock *BB, BasicBlock *Pred,
1100-
RenamePassData::ValVector IncomingVals,
1101-
RenamePassData::LocationVector IncomingLocs,
1102-
std::vector<RenamePassData> &Worklist) {
1116+
void PromoteMem2Reg::RenamePass(BasicBlock *BB, BasicBlock *Pred) {
11031117
// If we are inserting any phi nodes into this BB, they will already be in the
11041118
// block.
11051119
if (PHINode *APN = dyn_cast<PHINode>(BB->begin())) {
@@ -1226,8 +1240,7 @@ void PromoteMem2Reg::RenamePass(BasicBlock *BB, BasicBlock *Pred,
12261240
IncomingVals = Worklist.back().Values;
12271241
IncomingLocs = Worklist.back().Locations;
12281242
}
1229-
Worklist.emplace_back(S, BB, std::move(IncomingVals),
1230-
std::move(IncomingLocs));
1243+
pushToWorklist(S, BB, std::move(IncomingVals), std::move(IncomingLocs));
12311244
}
12321245
}
12331246

0 commit comments

Comments
 (0)