Skip to content

[semantic-arc-opts] Change semantic arc opts to use a SmallBlotSetVec… #26945

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
9 changes: 9 additions & 0 deletions include/swift/Basic/BlotSetVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,15 @@ class BlotSetVector {
return true;
}

/// Return the last element of the blot map vector. Will be None if blotted.
Optional<ValueT> pop_back_val() {
auto result = Vector.pop_back_val();
if (!result)
return result;
Map.erase(*result);
return result;
}

/// Attempt to lookup the index of \p V. Returns None upon failure and the
/// value on success.
Optional<unsigned> getIndex(const ValueT &V) {
Expand Down
15 changes: 10 additions & 5 deletions lib/SILOptimizer/Mandatory/SemanticARCOpts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,20 @@
//===----------------------------------------------------------------------===//

#define DEBUG_TYPE "sil-semantic-arc-opts"
#include "swift/Basic/BlotSetVector.h"
#include "swift/Basic/STLExtras.h"
#include "swift/SIL/BasicBlockUtils.h"
#include "swift/SIL/BranchPropagatedUser.h"
#include "swift/SIL/MemAccessUtils.h"
#include "swift/SIL/OwnershipUtils.h"
#include "swift/SILOptimizer/Utils/Local.h"
#include "swift/SIL/SILArgument.h"
#include "swift/SIL/SILBuilder.h"
#include "swift/SIL/SILInstruction.h"
#include "swift/SIL/SILVisitor.h"
#include "swift/SILOptimizer/Analysis/PostOrderAnalysis.h"
#include "swift/SILOptimizer/PassManager/Passes.h"
#include "swift/SILOptimizer/PassManager/Transforms.h"
#include "swift/SILOptimizer/Utils/Local.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
Expand Down Expand Up @@ -138,7 +139,7 @@ namespace {
/// the worklist before we delete them.
struct SemanticARCOptVisitor
: SILInstructionVisitor<SemanticARCOptVisitor, bool> {
SmallSetVector<SILValue, 32> worklist;
SmallBlotSetVector<SILValue, 32> worklist;
SILFunction &F;
Optional<DeadEndBlocks> TheDeadEndBlocks;

Expand Down Expand Up @@ -175,7 +176,7 @@ struct SemanticARCOptVisitor
// Remove all SILValues of the instruction from the worklist and then erase
// the instruction.
for (SILValue result : i->getResults()) {
worklist.remove(result);
worklist.erase(result);
}
i->eraseFromParent();
}
Expand Down Expand Up @@ -205,7 +206,11 @@ bool SemanticARCOptVisitor::processWorklist() {
bool madeChange = false;

while (!worklist.empty()) {
SILValue next = worklist.pop_back_val();
// Pop the last element off the list. If we were returned None, we blotted
// this element, so skip it.
SILValue next = worklist.pop_back_val().getValueOr(SILValue());
if (!next)
continue;

// First check if this is an instruction that is trivially dead. This can
// occur if we eliminate rr traffic resulting in dead projections and the
Expand All @@ -224,7 +229,7 @@ bool SemanticARCOptVisitor::processWorklist() {
worklist.insert(operand);
}
for (SILValue result : i->getResults()) {
worklist.remove(result);
worklist.erase(result);
}
++NumEliminatedInsts;
});
Expand Down