Skip to content

Commit 5085e45

Browse files
authored
Merge pull request swiftlang#26945 from gottesmm/pr-380b7ca9a019868d2a9fe0de564bfbaabcabe894
[semantic-arc-opts] Change semantic arc opts to use a SmallBlotSetVec…
2 parents d128664 + dee2627 commit 5085e45

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

include/swift/Basic/BlotSetVector.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,15 @@ class BlotSetVector {
125125
return true;
126126
}
127127

128+
/// Return the last element of the blot map vector. Will be None if blotted.
129+
Optional<ValueT> pop_back_val() {
130+
auto result = Vector.pop_back_val();
131+
if (!result)
132+
return result;
133+
Map.erase(*result);
134+
return result;
135+
}
136+
128137
/// Attempt to lookup the index of \p V. Returns None upon failure and the
129138
/// value on success.
130139
Optional<unsigned> getIndex(const ValueT &V) {

lib/SILOptimizer/Mandatory/SemanticARCOpts.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,20 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#define DEBUG_TYPE "sil-semantic-arc-opts"
14+
#include "swift/Basic/BlotSetVector.h"
1415
#include "swift/Basic/STLExtras.h"
1516
#include "swift/SIL/BasicBlockUtils.h"
1617
#include "swift/SIL/BranchPropagatedUser.h"
1718
#include "swift/SIL/MemAccessUtils.h"
1819
#include "swift/SIL/OwnershipUtils.h"
19-
#include "swift/SILOptimizer/Utils/Local.h"
2020
#include "swift/SIL/SILArgument.h"
2121
#include "swift/SIL/SILBuilder.h"
2222
#include "swift/SIL/SILInstruction.h"
2323
#include "swift/SIL/SILVisitor.h"
2424
#include "swift/SILOptimizer/Analysis/PostOrderAnalysis.h"
2525
#include "swift/SILOptimizer/PassManager/Passes.h"
2626
#include "swift/SILOptimizer/PassManager/Transforms.h"
27+
#include "swift/SILOptimizer/Utils/Local.h"
2728
#include "llvm/ADT/SmallPtrSet.h"
2829
#include "llvm/ADT/SmallVector.h"
2930
#include "llvm/ADT/Statistic.h"
@@ -138,7 +139,7 @@ namespace {
138139
/// the worklist before we delete them.
139140
struct SemanticARCOptVisitor
140141
: SILInstructionVisitor<SemanticARCOptVisitor, bool> {
141-
SmallSetVector<SILValue, 32> worklist;
142+
SmallBlotSetVector<SILValue, 32> worklist;
142143
SILFunction &F;
143144
Optional<DeadEndBlocks> TheDeadEndBlocks;
144145

@@ -175,7 +176,7 @@ struct SemanticARCOptVisitor
175176
// Remove all SILValues of the instruction from the worklist and then erase
176177
// the instruction.
177178
for (SILValue result : i->getResults()) {
178-
worklist.remove(result);
179+
worklist.erase(result);
179180
}
180181
i->eraseFromParent();
181182
}
@@ -205,7 +206,11 @@ bool SemanticARCOptVisitor::processWorklist() {
205206
bool madeChange = false;
206207

207208
while (!worklist.empty()) {
208-
SILValue next = worklist.pop_back_val();
209+
// Pop the last element off the list. If we were returned None, we blotted
210+
// this element, so skip it.
211+
SILValue next = worklist.pop_back_val().getValueOr(SILValue());
212+
if (!next)
213+
continue;
209214

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

0 commit comments

Comments
 (0)