diff options
author | Rahman Lavaee <rahmanl@google.com> | 2020-04-13 12:14:42 -0700 |
---|---|---|
committer | Rahman Lavaee <rahmanl@google.com> | 2020-04-13 12:19:59 -0700 |
commit | 05192e585ce175b55f2a26b83b4ed7882785c8e6 (patch) | |
tree | 40533ae82158ebb980b70d5bc6c65130c766ef09 /llvm/lib/CodeGen/MachineFunction.cpp | |
parent | 4ddf7ab454b0b0e885e4970f3896adc53d1c64e4 (diff) | |
download | llvm-05192e585ce175b55f2a26b83b4ed7882785c8e6.zip llvm-05192e585ce175b55f2a26b83b4ed7882785c8e6.tar.gz llvm-05192e585ce175b55f2a26b83b4ed7882785c8e6.tar.bz2 |
Extend BasicBlock sections to allow specifying clusters of basic blocks in the same section.
Differential Revision: https://reviews.llvm.org/D76954
Diffstat (limited to 'llvm/lib/CodeGen/MachineFunction.cpp')
-rw-r--r-- | llvm/lib/CodeGen/MachineFunction.cpp | 42 |
1 files changed, 16 insertions, 26 deletions
diff --git a/llvm/lib/CodeGen/MachineFunction.cpp b/llvm/lib/CodeGen/MachineFunction.cpp index 1b89333..464f389 100644 --- a/llvm/lib/CodeGen/MachineFunction.cpp +++ b/llvm/lib/CodeGen/MachineFunction.cpp @@ -340,32 +340,6 @@ void MachineFunction::RenumberBlocks(MachineBasicBlock *MBB) { MBBNumbering.resize(BlockNo); } -/// This sets the section ranges of cold or exception section with basic block -/// sections. -void MachineFunction::setSectionRange() { - // Compute the Section Range of cold and exception basic blocks. Find the - // first and last block of each range. - auto SectionRange = - ([&](llvm::MachineBasicBlockSection S) -> std::pair<int, int> { - auto MBBP = - std::find_if(begin(), end(), [&](MachineBasicBlock &MBB) -> bool { - return MBB.getSectionType() == S; - }); - if (MBBP == end()) - return std::make_pair(-1, -1); - - auto MBBQ = - std::find_if(rbegin(), rend(), [&](MachineBasicBlock &MBB) -> bool { - return MBB.getSectionType() == S; - }); - assert(MBBQ != rend() && "Section end not found!"); - return std::make_pair(MBBP->getNumber(), MBBQ->getNumber()); - }); - - ExceptionSectionRange = SectionRange(MBBS_Exception); - ColdSectionRange = SectionRange(llvm::MBBS_Cold); -} - /// This is used with -fbasicblock-sections or -fbasicblock-labels option. /// A unary encoding of basic block labels is done to keep ".strtab" sizes /// small. @@ -393,6 +367,22 @@ void MachineFunction::createBBLabels() { } } +/// This method iterates over the basic blocks and assigns their IsBeginSection +/// and IsEndSection fields. This must be called after MBB layout is finalized +/// and the SectionID's are assigned to MBBs. +void MachineFunction::assignBeginEndSections() { + front().setIsBeginSection(); + auto CurrentSectionID = front().getSectionID(); + for (auto MBBI = std::next(begin()), E = end(); MBBI != E; ++MBBI) { + if (MBBI->getSectionID() == CurrentSectionID) + continue; + MBBI->setIsBeginSection(); + std::prev(MBBI)->setIsEndSection(); + CurrentSectionID = MBBI->getSectionID(); + } + back().setIsEndSection(); +} + /// Allocate a new MachineInstr. Use this instead of `new MachineInstr'. MachineInstr *MachineFunction::CreateMachineInstr(const MCInstrDesc &MCID, const DebugLoc &DL, |