Skip to content

Commit 4e1ae4a

Browse files
authored
[Outlining] Sort sequences by order appeared in function (WebAssembly#7164)
During function reconstruction, a walker iterates thru each instruction of a function, incrementing a counter to find matching sequences. As a result, the sequences of a function must be sorted by smallest start index, otherwise reconstruction will miss outlining a repeat sequence. I considered making a test for this commit, but the sort wasn't needed until the tests started running on GitHub infra. I'm not sure what specific architecture is causing the discrepancy in vector ordering, but let's introduce the sort to be safe.
1 parent dcec348 commit 4e1ae4a

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/passes/Outlining.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -364,11 +364,20 @@ struct Outlining : public Pass {
364364
seqByFunc.end(),
365365
keys.begin(),
366366
[](auto pair) { return pair.first; });
367-
for (auto funcName : keys) {
368-
auto* func = module->getFunction(funcName);
369-
ReconstructStringifyWalker reconstruct(module, func);
370-
reconstruct.sequences = std::move(seqByFunc[funcName]);
371-
reconstruct.doWalkFunction(func);
367+
for (auto func : keys) {
368+
// During function reconstruction, a walker iterates thru each instruction
369+
// of a function, incrementing a counter to find matching sequences. As a
370+
// result, the sequences of a function must be sorted by
371+
// smallest start index, otherwise reconstruction will miss outlining a
372+
// repeat sequence.
373+
std::sort(seqByFunc[func].begin(),
374+
seqByFunc[func].end(),
375+
[](OutliningSequence a, OutliningSequence b) {
376+
return a.startIdx < b.startIdx;
377+
});
378+
ReconstructStringifyWalker reconstruct(module, module->getFunction(func));
379+
reconstruct.sequences = std::move(seqByFunc[func]);
380+
reconstruct.doWalkFunction(module->getFunction(func));
372381
}
373382
}
374383

0 commit comments

Comments
 (0)