diff --git a/llvm/lib/Transforms/Scalar/SROA.cpp b/llvm/lib/Transforms/Scalar/SROA.cpp index 2310cb3a7decb..d0186da1bc5e2 100644 --- a/llvm/lib/Transforms/Scalar/SROA.cpp +++ b/llvm/lib/Transforms/Scalar/SROA.cpp @@ -198,7 +198,9 @@ class SROA { SmallSetVector 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. /// @@ -4799,9 +4801,7 @@ bool SROA::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; } @@ -4963,7 +4963,7 @@ AllocaInst *SROA::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 @@ -5598,7 +5598,7 @@ bool SROA::promoteAllocas(Function &F) { LLVM_DEBUG(dbgs() << "Not promoting allocas with mem2reg!\n"); } else { LLVM_DEBUG(dbgs() << "Promoting allocas with mem2reg...\n"); - PromoteMemToReg(PromotableAllocas, DTU->getDomTree(), AC); + PromoteMemToReg(PromotableAllocas.getArrayRef(), DTU->getDomTree(), AC); } PromotableAllocas.clear(); @@ -5615,7 +5615,7 @@ std::pair SROA::runSROA(Function &F) { if (AllocaInst *AI = dyn_cast(I)) { if (DL.getTypeAllocSize(AI->getAllocatedType()).isScalable() && isAllocaPromotable(AI)) - PromotableAllocas.push_back(AI); + PromotableAllocas.insert(AI); else Worklist.insert(AI); } @@ -5639,10 +5639,9 @@ std::pair SROA::runSROA(Function &F) { // 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(); } }