Skip to content

[SILOpt] Used SetVector for fast contains check. #59057

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/swift/SILOptimizer/Analysis/Reachability.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class BackwardReachability {
/// Effect effectForPhi(SILBasicBlock *);
///
/// /// The uses from which reachability will begin.
/// ArrayRef<SILInstruction *> gens();
/// iterable gens();
/// }
template <typename Effects>
class IterativeBackwardReachability final {
Expand Down
11 changes: 4 additions & 7 deletions lib/SILOptimizer/Transforms/SSADestroyHoisting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ struct KnownStorageUses : UniqueStorageUseVisitor {
bool preserveDebugInfo;

SmallPtrSet<SILInstruction *, 16> storageUsers;
SmallVector<SILInstruction *, 4> originalDestroys;
SmallSetVector<SILInstruction *, 4> originalDestroys;
SmallPtrSet<SILInstruction *, 4> debugInsts;

KnownStorageUses(AccessStorage storage, SILFunction *function)
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -283,9 +283,7 @@ class DeinitBarriers final {
/// IterativeBackwardReachability::Effects
/// VisitBarrierAccessScopes::Effects

ArrayRef<SILInstruction *> gens() {
return result.knownUses.originalDestroys;
}
auto gens() { return result.knownUses.originalDestroys; }

Effect effectForInstruction(SILInstruction *instruction);

Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions lib/SILOptimizer/Utils/LexicalDestroyHoisting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ struct Usage final {
/// Instructions which are users of the simple (i.e. not reborrowed) value.
SmallPtrSet<SILInstruction *, 16> users;
// The instructions from which the hoisting starts, the destroy_values.
llvm::SmallVector<SILInstruction *, 4> ends;
llvm::SmallSetVector<SILInstruction *, 4> ends;

Usage(){};
Usage(Usage const &) = delete;
Expand All @@ -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<DestroyValueInst>(use->getUser())) {
usage.ends.push_back(use->getUser());
usage.ends.insert(use->getUser());
} else {
usage.users.insert(use->getUser());
}
Expand Down Expand Up @@ -155,7 +155,7 @@ class Dataflow final {
/// IterativeBackwardReachability::Effects
/// VisitBarrierAccessScopes::Effects

ArrayRef<SILInstruction *> gens() { return uses.ends; }
auto gens() { return uses.ends; }

Effect effectForInstruction(SILInstruction *);
Effect effectForPhi(SILBasicBlock *);
Expand Down Expand Up @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions lib/SILOptimizer/Utils/ShrinkBorrowScope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ struct Usage final {
SmallPtrSet<SILInstruction *, 16> users;
// The instructions from which the shrinking starts, the scope ending
// instructions.
llvm::SmallVector<SILInstruction *, 4> ends;
llvm::SmallSetVector<SILInstruction *, 4> ends;

Usage(){};
Usage(Usage const &) = delete;
Expand All @@ -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<EndBorrowInst>(instruction))
return false;
usage.ends.push_back(instruction);
usage.ends.insert(instruction);
}

SmallVector<Operand *, 16> uses;
Expand Down Expand Up @@ -181,7 +181,7 @@ class Dataflow final {
/// IterativeBackwardReachability::Effects
/// VisitBarrierAccessScopes::Effects

ArrayRef<SILInstruction *> gens() { return uses.ends; }
auto gens() { return uses.ends; }

Effect effectForInstruction(SILInstruction *);

Expand Down Expand Up @@ -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)
Expand Down