[llvm] [PGO][NFC] Make CFGMST debug dump order deterministic (PR #200835)
Yaxun Liu via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 30 08:40:03 PDT 2026
================
@@ -286,12 +286,30 @@ template <class Edge, class BBInfo> class CFGMST {
if (!Message.str().empty())
OS << Message << "\n";
OS << " Number of Basic Blocks: " << BBInfos.size() << "\n";
- for (auto &BI : BBInfos) {
- const BasicBlock *BB = BI.first;
+ // Collect and sort BBInfos deterministically by their assigned Index.
+ std::vector<std::pair<const BasicBlock *, const BBInfo *>> SortedBBInfos;
+ SortedBBInfos.reserve(BBInfos.size());
+ for (const auto &BI : BBInfos)
+ SortedBBInfos.emplace_back(BI.first, BI.second.get());
+
+ llvm::sort(SortedBBInfos, [](const auto &A, const auto &B) {
+ // Primary key: BBInfo Index
+ if (A.second->Index != B.second->Index)
+ return A.second->Index < B.second->Index;
+ // Secondary key: name string to keep a stable order even if
+ // indices tie (ties shouldn't happen, but this makes ordering
+ // explicit).
----------------
yxsamliu wrote:
Added a debug-only assert to check that BBInfo indices are unique before sorting. Release builds have no extra cost, and the name tiebreaker is still kept for deterministic dump output.
https://github.com/llvm/llvm-project/pull/200835
More information about the llvm-commits
mailing list