Skip to content

Commit 05a8c8d

Browse files
authored
[Outlining] Filter in nested control flow (#7411)
Fixes a bug where stringify walker was not removing outlining candidates with restricted expressions because they were in nested control flow.
1 parent a7d93ef commit 05a8c8d

File tree

4 files changed

+62
-4
lines changed

4 files changed

+62
-4
lines changed

src/passes/hash-stringify-walker.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ std::vector<SuffixTree::RepeatedSubstring> StringifyProcessor::filter(
204204
void walk(Expression* curr) {
205205
hasFilterValue = false;
206206
Super::walk(curr);
207+
flushControlFlowQueue();
207208
}
208209

209210
void addUniqueSymbol(SeparatorReason reason) {}

src/passes/stringify-walker-impl.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ inline void StringifyWalker<SubType>::doWalkFunction(Function* func) {
4242
addUniqueSymbol(SeparatorReason::makeFuncStart(func));
4343
Super::walk(func->body);
4444
addUniqueSymbol(SeparatorReason::makeEnd());
45-
while (!controlFlowQueue.empty()) {
46-
dequeueControlFlow();
47-
}
45+
flushControlFlowQueue();
4846
}
4947

5048
template<typename SubType>

src/passes/stringify-walker.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,11 @@ struct StringifyWalker
191191
static void scan(SubType* self, Expression** currp);
192192
static void doVisitExpression(SubType* self, Expression** currp);
193193

194-
private:
194+
void flushControlFlowQueue() {
195+
while (!controlFlowQueue.empty()) {
196+
dequeueControlFlow();
197+
}
198+
}
195199
void dequeueControlFlow();
196200
};
197201

test/lit/passes/outlining.wast

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,3 +1109,58 @@
11091109
unreachable
11101110
)
11111111
)
1112+
1113+
;; Tests that restricted expressions (local.set) are filtered from outlining
1114+
;; even when nested within control flow.
1115+
(module
1116+
;; CHECK: (type $0 (func))
1117+
1118+
;; CHECK: (func $a (type $0)
1119+
;; CHECK-NEXT: (local $x i32)
1120+
;; CHECK-NEXT: (if
1121+
;; CHECK-NEXT: (i32.const 0)
1122+
;; CHECK-NEXT: (then
1123+
;; CHECK-NEXT: (local.set $x
1124+
;; CHECK-NEXT: (i32.const 1)
1125+
;; CHECK-NEXT: )
1126+
;; CHECK-NEXT: )
1127+
;; CHECK-NEXT: )
1128+
;; CHECK-NEXT: )
1129+
(func $a
1130+
(local $x i32)
1131+
(block
1132+
(if
1133+
(i32.const 0)
1134+
(then
1135+
(local.set $x
1136+
(i32.const 1)
1137+
)
1138+
)
1139+
)
1140+
)
1141+
)
1142+
;; CHECK: (func $b (type $0)
1143+
;; CHECK-NEXT: (local $x i32)
1144+
;; CHECK-NEXT: (if
1145+
;; CHECK-NEXT: (i32.const 0)
1146+
;; CHECK-NEXT: (then
1147+
;; CHECK-NEXT: (local.set $x
1148+
;; CHECK-NEXT: (i32.const 1)
1149+
;; CHECK-NEXT: )
1150+
;; CHECK-NEXT: )
1151+
;; CHECK-NEXT: )
1152+
;; CHECK-NEXT: )
1153+
(func $b
1154+
(local $x i32)
1155+
(block
1156+
(if
1157+
(i32.const 0)
1158+
(then
1159+
(local.set $x
1160+
(i32.const 1)
1161+
)
1162+
)
1163+
)
1164+
)
1165+
)
1166+
)

0 commit comments

Comments
 (0)