diff --git a/include/swift/SILOptimizer/Analysis/Reachability.h b/include/swift/SILOptimizer/Analysis/Reachability.h index e98f9d2901123..1eef74d1d83c3 100644 --- a/include/swift/SILOptimizer/Analysis/Reachability.h +++ b/include/swift/SILOptimizer/Analysis/Reachability.h @@ -149,7 +149,7 @@ class BackwardReachability { /// Effect effectForPhi(SILBasicBlock *); /// /// /// The uses from which reachability will begin. -/// ArrayRef gens(); +/// iterable gens(); /// } template class IterativeBackwardReachability final { diff --git a/lib/SILOptimizer/Transforms/SSADestroyHoisting.cpp b/lib/SILOptimizer/Transforms/SSADestroyHoisting.cpp index df81319a3d424..8e02d310f56c3 100644 --- a/lib/SILOptimizer/Transforms/SSADestroyHoisting.cpp +++ b/lib/SILOptimizer/Transforms/SSADestroyHoisting.cpp @@ -111,7 +111,7 @@ struct KnownStorageUses : UniqueStorageUseVisitor { bool preserveDebugInfo; SmallPtrSet storageUsers; - SmallVector originalDestroys; + SmallSetVector originalDestroys; SmallPtrSet debugInsts; KnownStorageUses(AccessStorage storage, SILFunction *function) @@ -158,7 +158,7 @@ struct KnownStorageUses : UniqueStorageUseVisitor { bool visitStore(Operand *use) override { return recordUser(use->getUser()); } bool visitDestroy(Operand *use) override { - originalDestroys.push_back(use->getUser()); + originalDestroys.insert(use->getUser()); return true; } @@ -283,9 +283,7 @@ class DeinitBarriers final { /// IterativeBackwardReachability::Effects /// VisitBarrierAccessScopes::Effects - ArrayRef gens() { - return result.knownUses.originalDestroys; - } + auto gens() { return result.knownUses.originalDestroys; } Effect effectForInstruction(SILInstruction *instruction); @@ -366,8 +364,7 @@ bool DeinitBarriers::classificationIsBarrier(Classification classification) { DeinitBarriers::DestroyReachability::Effect DeinitBarriers::DestroyReachability::effectForInstruction( SILInstruction *instruction) { - if (llvm::find(result.knownUses.originalDestroys, instruction) != - result.knownUses.originalDestroys.end()) + if (result.knownUses.originalDestroys.contains(instruction)) return Effect::Gen(); auto classification = result.classifyInstruction(instruction); if (recordDeadUsers && classification == Classification::DeadUser) diff --git a/lib/SILOptimizer/Utils/LexicalDestroyHoisting.cpp b/lib/SILOptimizer/Utils/LexicalDestroyHoisting.cpp index 254008483c0a5..91a1374b245a2 100644 --- a/lib/SILOptimizer/Utils/LexicalDestroyHoisting.cpp +++ b/lib/SILOptimizer/Utils/LexicalDestroyHoisting.cpp @@ -67,7 +67,7 @@ struct Usage final { /// Instructions which are users of the simple (i.e. not reborrowed) value. SmallPtrSet users; // The instructions from which the hoisting starts, the destroy_values. - llvm::SmallVector ends; + llvm::SmallSetVector ends; Usage(){}; Usage(Usage const &) = delete; @@ -89,7 +89,7 @@ bool findUsage(Context const &context, Usage &usage) { // flow and determine whether any were reused. They aren't uses over which // we can't hoist though. if (isa(use->getUser())) { - usage.ends.push_back(use->getUser()); + usage.ends.insert(use->getUser()); } else { usage.users.insert(use->getUser()); } @@ -155,7 +155,7 @@ class Dataflow final { /// IterativeBackwardReachability::Effects /// VisitBarrierAccessScopes::Effects - ArrayRef gens() { return uses.ends; } + auto gens() { return uses.ends; } Effect effectForInstruction(SILInstruction *); Effect effectForPhi(SILBasicBlock *); @@ -211,7 +211,7 @@ bool Dataflow::classificationIsBarrier(Classification classification) { } Dataflow::Effect Dataflow::effectForInstruction(SILInstruction *instruction) { - if (llvm::find(uses.ends, instruction) != uses.ends.end()) + if (uses.ends.contains(instruction)) return Effect::Gen(); auto classification = classifyInstruction(instruction); return classificationIsBarrier(classification) ? Effect::Kill() diff --git a/lib/SILOptimizer/Utils/ShrinkBorrowScope.cpp b/lib/SILOptimizer/Utils/ShrinkBorrowScope.cpp index 064eb410dab55..da994b085e4c0 100644 --- a/lib/SILOptimizer/Utils/ShrinkBorrowScope.cpp +++ b/lib/SILOptimizer/Utils/ShrinkBorrowScope.cpp @@ -79,7 +79,7 @@ struct Usage final { SmallPtrSet users; // The instructions from which the shrinking starts, the scope ending // instructions. - llvm::SmallVector ends; + llvm::SmallSetVector ends; Usage(){}; Usage(Usage const &) = delete; @@ -99,7 +99,7 @@ bool findUsage(Context const &context, Usage &usage) { // If a scope ending instruction is not an end_borrow, bail out. if (!isa(instruction)) return false; - usage.ends.push_back(instruction); + usage.ends.insert(instruction); } SmallVector uses; @@ -181,7 +181,7 @@ class Dataflow final { /// IterativeBackwardReachability::Effects /// VisitBarrierAccessScopes::Effects - ArrayRef gens() { return uses.ends; } + auto gens() { return uses.ends; } Effect effectForInstruction(SILInstruction *); @@ -262,7 +262,7 @@ bool Dataflow::classificationIsBarrier(Classification classification) { } Dataflow::Effect Dataflow::effectForInstruction(SILInstruction *instruction) { - if (llvm::find(uses.ends, instruction) != uses.ends.end()) + if (uses.ends.contains(instruction)) return Effect::Gen(); auto classification = classifyInstruction(instruction); if (recordCopies && classification == Classification::Copy)