[llvm] c2b92a4 - [SROA] Use SetVector for PromotableAllocas (#105809)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 4 05:10:55 PDT 2024
Author: Bartłomiej Chmiel
Date: 2024-09-04T14:10:51+02:00
New Revision: c2b92a4250b3f514685676ba8985ea73450f14d3
URL: https://github.com/llvm/llvm-project/commit/c2b92a4250b3f514685676ba8985ea73450f14d3
DIFF: https://github.com/llvm/llvm-project/commit/c2b92a4250b3f514685676ba8985ea73450f14d3.diff
LOG: [SROA] Use SetVector for PromotableAllocas (#105809)
Use SetVector to make operations more efficient
if there is a very large number of allocas.
Added:
Modified:
llvm/lib/Transforms/Scalar/SROA.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/SROA.cpp b/llvm/lib/Transforms/Scalar/SROA.cpp
index 2310cb3a7decbb..d0186da1bc5e22 100644
--- a/llvm/lib/Transforms/Scalar/SROA.cpp
+++ b/llvm/lib/Transforms/Scalar/SROA.cpp
@@ -198,7 +198,9 @@ class SROA {
SmallSetVector<AllocaInst *, 16> PostPromotionWorklist;
/// A collection of alloca instructions we can directly promote.
- std::vector<AllocaInst *> PromotableAllocas;
+ SetVector<AllocaInst *, SmallVector<AllocaInst *>,
+ SmallPtrSet<AllocaInst *, 16>, 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<bool /*Changed*/, bool /*CFGChanged*/> SROA::runSROA(Function &F) {
if (AllocaInst *AI = dyn_cast<AllocaInst>(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<bool /*Changed*/, bool /*CFGChanged*/> 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();
}
}
More information about the llvm-commits
mailing list