diff options
author | Rahman Lavaee <rahmanl@google.com> | 2024-01-16 14:15:33 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-16 14:15:33 -0800 |
commit | e1616ef9d742ebcc226451c4ca5ec2204c460840 (patch) | |
tree | 5a93bdc63989b6fed27c99f697586d1176206a3c /llvm/lib/CodeGen/BasicBlockSections.cpp | |
parent | ad50676055cf03fd4fecdda5736c7ac1a940231f (diff) | |
download | llvm-e1616ef9d742ebcc226451c4ca5ec2204c460840.zip llvm-e1616ef9d742ebcc226451c4ca5ec2204c460840.tar.gz llvm-e1616ef9d742ebcc226451c4ca5ec2204c460840.tar.bz2 |
[BasicBlockSections] Always keep the entry block in the beginning of the function. (#74696)
BasicBlockSections must enforce placing the entry block at the beginning
of the function regardless of the basic block sections profile.
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) |