diff --git a/llvm/include/llvm/Transforms/Scalar/SROA.h b/llvm/include/llvm/Transforms/Scalar/SROA.h index 26348da220211678c0acc9d2126ed5886ef16e9c..913a19194fe25db3f51e03f1bf2bd2b18a95d842 100644 --- a/llvm/include/llvm/Transforms/Scalar/SROA.h +++ b/llvm/include/llvm/Transforms/Scalar/SROA.h @@ -123,8 +123,9 @@ class SROAPass : public PassInfoMixin { SetVector> PostPromotionWorklist; /// A collection of alloca instructions we can directly promote. - std::vector PromotableAllocas; - + SetVector, + SmallPtrSet, 16> + PromotableAllocas; /// A worklist of PHIs to speculate prior to promoting allocas. /// /// All of these PHIs have been checked for the safety of speculation and by diff --git a/llvm/lib/Transforms/Scalar/SROA.cpp b/llvm/lib/Transforms/Scalar/SROA.cpp index 818d64725893265a228cdebc133abc16633ffd00..8fc39031f1c9a04be9b206e9c21c531c3474ad8d 100644 --- a/llvm/lib/Transforms/Scalar/SROA.cpp +++ b/llvm/lib/Transforms/Scalar/SROA.cpp @@ -4572,9 +4572,7 @@ bool SROAPass::presplitLoadsAndStores(AllocaInst &AI, AllocaSlices &AS) { // Finally, don't try to promote any allocas that new require re-splitting. // They have already been added to the worklist above. - llvm::erase_if(PromotableAllocas, [&](AllocaInst *AI) { - return ResplitPromotableAllocas.count(AI); - }); + PromotableAllocas.set_subtract(ResplitPromotableAllocas); return true; } @@ -4736,7 +4734,7 @@ AllocaInst *SROAPass::rewritePartition(AllocaInst &AI, AllocaSlices &AS, } if (PHIUsers.empty() && SelectUsers.empty()) { // Promote the alloca. - PromotableAllocas.push_back(NewAI); + PromotableAllocas.insert(NewAI); } else { // If we have either PHIs or Selects to speculate, add them to those // worklists and re-queue the new alloca so that we promote in on the @@ -5110,7 +5108,7 @@ bool SROAPass::promoteAllocas(Function &F) { NumPromoted += PromotableAllocas.size(); LLVM_DEBUG(dbgs() << "Promoting allocas with mem2reg...\n"); - PromoteMemToReg(PromotableAllocas, DTU->getDomTree(), AC); + PromoteMemToReg(PromotableAllocas.getArrayRef(), DTU->getDomTree(), AC); PromotableAllocas.clear(); return true; } @@ -5128,7 +5126,7 @@ PreservedAnalyses SROAPass::runImpl(Function &F, DomTreeUpdater &RunDTU, if (AllocaInst *AI = dyn_cast(I)) { if (isa(AI->getAllocatedType())) { if (isAllocaPromotable(AI)) - PromotableAllocas.push_back(AI); + PromotableAllocas.insert(AI); } else { Worklist.insert(AI); } @@ -5153,10 +5151,9 @@ PreservedAnalyses SROAPass::runImpl(Function &F, DomTreeUpdater &RunDTU, // Remove the deleted allocas from various lists so that we don't try to // continue processing them. if (!DeletedAllocas.empty()) { - auto IsInSet = [&](AllocaInst *AI) { return DeletedAllocas.count(AI); }; - Worklist.remove_if(IsInSet); - PostPromotionWorklist.remove_if(IsInSet); - llvm::erase_if(PromotableAllocas, IsInSet); + Worklist.set_subtract(DeletedAllocas); + PostPromotionWorklist.set_subtract(DeletedAllocas); + PromotableAllocas.set_subtract(DeletedAllocas); DeletedAllocas.clear(); } }