aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/MachineFunction.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/CodeGen/MachineFunction.cpp')
-rw-r--r--llvm/lib/CodeGen/MachineFunction.cpp42
1 files changed, 26 insertions, 16 deletions
diff --git a/llvm/lib/CodeGen/MachineFunction.cpp b/llvm/lib/CodeGen/MachineFunction.cpp
index 464f389..1b89333 100644
--- a/llvm/lib/CodeGen/MachineFunction.cpp
+++ b/llvm/lib/CodeGen/MachineFunction.cpp
@@ -340,6 +340,32 @@ 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.
@@ -367,22 +393,6 @@ 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,