Skip to content

Commit 3ef21aa

Browse files
committed
[semantic-arc] Change SemanticARCOptVisitor to be a SILValueVisitor instead of a SILInstructionVisitor.
Our worklist already uses values, so it makes sense to use a SILValueVisitor. It will also let me throw in a few ARC dead argument elimination optimizations so clean up a pattern from my ARC RAUW thing. Once we have simplify-cfg it will not be needed, but I want to know I am good before I flip the switch.
1 parent 27ece6f commit 3ef21aa

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

lib/SILOptimizer/SemanticARC/SemanticARCOptVisitor.h

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace semanticarc {
3636
/// visitors do, we maintain a visitedSinceLastMutation list to ensure that we
3737
/// revisit all interesting instructions in between mutations.
3838
struct LLVM_LIBRARY_VISIBILITY SemanticARCOptVisitor
39-
: SILInstructionVisitor<SemanticARCOptVisitor, bool> {
39+
: SILValueVisitor<SemanticARCOptVisitor, bool> {
4040
/// Our main worklist. We use this after an initial run through.
4141
SmallBlotSetVector<SILValue, 32> worklist;
4242

@@ -127,9 +127,19 @@ struct LLVM_LIBRARY_VISIBILITY SemanticARCOptVisitor
127127
});
128128
}
129129

130-
/// The default visitor.
131130
bool visitSILInstruction(SILInstruction *i) {
132-
assert(!isa<OwnershipForwardingInst>(i) &&
131+
assert((isa<OwnershipForwardingTermInst>(i) ||
132+
!isa<OwnershipForwardingInst>(i)) &&
133+
"Should have forwarding visitor for all ownership forwarding "
134+
"non-term instructions");
135+
return false;
136+
}
137+
138+
/// The default visitor.
139+
bool visitValueBase(ValueBase *v) {
140+
auto *inst = v->getDefiningInstruction();
141+
(void)inst;
142+
assert((!inst || !isa<OwnershipForwardingInst>(inst)) &&
133143
"Should have forwarding visitor for all ownership forwarding "
134144
"instructions");
135145
return false;
@@ -138,6 +148,7 @@ struct LLVM_LIBRARY_VISIBILITY SemanticARCOptVisitor
138148
bool visitCopyValueInst(CopyValueInst *cvi);
139149
bool visitBeginBorrowInst(BeginBorrowInst *bbi);
140150
bool visitLoadInst(LoadInst *li);
151+
141152
static bool shouldVisitInst(SILInstruction *i) {
142153
switch (i->getKind()) {
143154
default:
@@ -187,20 +198,6 @@ struct LLVM_LIBRARY_VISIBILITY SemanticARCOptVisitor
187198
FORWARDING_INST(LinearFunctionExtract)
188199
#undef FORWARDING_INST
189200

190-
#define FORWARDING_TERM(NAME) \
191-
bool visit##NAME##Inst(NAME##Inst *cls) { \
192-
for (auto succValues : cls->getSuccessorBlockArgumentLists()) { \
193-
for (SILValue v : succValues) { \
194-
worklist.insert(v); \
195-
} \
196-
} \
197-
return false; \
198-
}
199-
FORWARDING_TERM(SwitchEnum)
200-
FORWARDING_TERM(CheckedCastBranch)
201-
FORWARDING_TERM(Branch)
202-
#undef FORWARDING_TERM
203-
204201
bool processWorklist();
205202
bool optimize();
206203
bool optimizeWithoutFixedPoint();

0 commit comments

Comments
 (0)