llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-llvm-transforms Author: Vitaly Buka (vitalybuka) <details> <summary>Changes</summary> `IncomingVals`, `IncomingLocs`, `Worklist` into class members. They are all DFS state related, as `Visited`. But visited is already a class member. On it's own the patch has no value, but it simplify stuff in the next patch. --- Full diff: https://github.com/llvm/llvm-project/pull/142468.diff 1 Files Affected: - (modified) llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp (+36-23) ``````````diff diff --git a/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp b/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp index 62995e57b917c..9ddcbd516e00a 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.assign(Allocas.size(), nullptr); 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.assign(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())) { @@ -1223,12 +1237,11 @@ void PromoteMem2Reg::RenamePass(BasicBlock *BB, BasicBlock *Pred, if (VisitedSuccs.insert(S).second) { if (VisitedSuccs.size() == 1) { // Let the first successor to own allocated arrays. - Worklist.emplace_back(S, BB, std::move(IncomingVals), - std::move(IncomingLocs)); + pushToWorklist(S, BB, std::move(IncomingVals), std::move(IncomingLocs)); } else { // Other successors have to make a copy. - Worklist.emplace_back(S, BB, Worklist.back().Values, - Worklist.back().Locations); + pushToWorklist(S, BB, WorkList.back().Values, + WorkList.back().Locations); } } } `````````` </details> https://github.com/llvm/llvm-project/pull/142468 _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits