From 4e1ae4aa5815fb474c829d15d7c93abee0ce14e3 Mon Sep 17 00:00:00 2001 From: Ashley Nelson Date: Thu, 19 Dec 2024 14:49:16 -0800 Subject: [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. --- src/passes/Outlining.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'src/passes/Outlining.cpp') 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)); } } -- cgit v1.2.3