summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAshley Nelson <nashley@google.com>2024-12-19 14:49:16 -0800
committerGitHub <noreply@github.com>2024-12-19 14:49:16 -0800
commit4e1ae4aa5815fb474c829d15d7c93abee0ce14e3 (patch)
tree76920c4663773646fa1c56e0928f5776a5d4259e
parentdcec348ded6d7ab7bf4b758bdb92107e4262dbf4 (diff)
downloadbinaryen-4e1ae4aa5815fb474c829d15d7c93abee0ce14e3.tar.gz
binaryen-4e1ae4aa5815fb474c829d15d7c93abee0ce14e3.tar.bz2
binaryen-4e1ae4aa5815fb474c829d15d7c93abee0ce14e3.zip
[Outlining] Sort sequences by order appeared in function (#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.
-rw-r--r--src/passes/Outlining.cpp19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/passes/Outlining.cpp b/src/passes/Outlining.cpp
index b86e6cd17..0c5c22f18 100644
--- a/src/passes/Outlining.cpp
+++ b/src/passes/Outlining.cpp
@@ -364,11 +364,20 @@ struct Outlining : public Pass {
seqByFunc.end(),
keys.begin(),
[](auto pair) { return pair.first; });
- for (auto funcName : keys) {
- auto* func = module->getFunction(funcName);
- ReconstructStringifyWalker reconstruct(module, func);
- reconstruct.sequences = std::move(seqByFunc[funcName]);
- reconstruct.doWalkFunction(func);
+ for (auto func : keys) {
+ // 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.
+ std::sort(seqByFunc[func].begin(),
+ seqByFunc[func].end(),
+ [](OutliningSequence a, OutliningSequence b) {
+ return a.startIdx < b.startIdx;
+ });
+ ReconstructStringifyWalker reconstruct(module, module->getFunction(func));
+ reconstruct.sequences = std::move(seqByFunc[func]);
+ reconstruct.doWalkFunction(module->getFunction(func));
}
}