diff options
Diffstat (limited to 'llvm/lib/CodeGen/BasicBlockSections.cpp')
-rw-r--r-- | llvm/lib/CodeGen/BasicBlockSections.cpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/llvm/lib/CodeGen/BasicBlockSections.cpp b/llvm/lib/CodeGen/BasicBlockSections.cpp index 94b5a50..dbb6ebb 100644 --- a/llvm/lib/CodeGen/BasicBlockSections.cpp +++ b/llvm/lib/CodeGen/BasicBlockSections.cpp @@ -318,9 +318,8 @@ bool BasicBlockSections::runOnMachineFunction(MachineFunction &MF) { MF.setBBSectionsType(BBSectionsType); assignSections(MF, FuncClusterInfo); - // We make sure that the cluster including the entry basic block precedes all - // other clusters. - auto EntryBBSectionID = MF.front().getSectionID(); + const MachineBasicBlock &EntryBB = MF.front(); + auto EntryBBSectionID = EntryBB.getSectionID(); // Helper function for ordering BB sections as follows: // * Entry section (section including the entry block). @@ -341,12 +340,17 @@ bool BasicBlockSections::runOnMachineFunction(MachineFunction &MF) { // contiguous and ordered accordingly. Furthermore, clusters are ordered in // increasing order of their section IDs, with the exception and the // cold section placed at the end of the function. + // Also, we force the entry block of the function to be placed at the + // beginning of the function, regardless of the requested order. auto Comparator = [&](const MachineBasicBlock &X, const MachineBasicBlock &Y) { auto XSectionID = X.getSectionID(); auto YSectionID = Y.getSectionID(); if (XSectionID != YSectionID) return MBBSectionOrder(XSectionID, YSectionID); + // Make sure that the entry block is placed at the beginning. + if (&X == &EntryBB || &Y == &EntryBB) + return &X == &EntryBB; // If the two basic block are in the same section, the order is decided by // their position within the section. if (XSectionID.Type == MBBSectionID::SectionType::Default) |