diff options
author | Sriraman Tallam <tmsriram@google.com> | 2020-03-16 15:56:02 -0700 |
---|---|---|
committer | Sriraman Tallam <tmsriram@google.com> | 2020-03-16 16:06:54 -0700 |
commit | df082ac45aa034b8b5194123035554a93ed6d38e (patch) | |
tree | c48dfbcf08328371ef2bbb7c822305fb39d754f3 /llvm/lib/CodeGen/MachineFunction.cpp | |
parent | 30dc342f084d5ca9cd4ba9f8a7de37a783c8687e (diff) | |
download | llvm-df082ac45aa034b8b5194123035554a93ed6d38e.zip llvm-df082ac45aa034b8b5194123035554a93ed6d38e.tar.gz llvm-df082ac45aa034b8b5194123035554a93ed6d38e.tar.bz2 |
Basic Block Sections support in LLVM.
This is the second patch in a series of patches to enable basic block
sections support.
This patch adds support for:
* Creating direct jumps at the end of basic blocks that have fall
through instructions.
* New pass, bbsections-prepare, that analyzes placement of basic blocks
in sections.
* Actual placing of a basic block in a unique section with special
handling of exception handling blocks.
* Supports placing a subset of basic blocks in a unique section.
* Support for MIR serialization and deserialization with basic block
sections.
Parent patch : D68063
Differential Revision: https://reviews.llvm.org/D73674
Diffstat (limited to 'llvm/lib/CodeGen/MachineFunction.cpp')
-rw-r--r-- | llvm/lib/CodeGen/MachineFunction.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/MachineFunction.cpp b/llvm/lib/CodeGen/MachineFunction.cpp index b00907f..76a1bd9 100644 --- a/llvm/lib/CodeGen/MachineFunction.cpp +++ b/llvm/lib/CodeGen/MachineFunction.cpp @@ -33,6 +33,7 @@ #include "llvm/CodeGen/MachineRegisterInfo.h" #include "llvm/CodeGen/PseudoSourceValue.h" #include "llvm/CodeGen/TargetFrameLowering.h" +#include "llvm/CodeGen/TargetInstrInfo.h" #include "llvm/CodeGen/TargetLowering.h" #include "llvm/CodeGen/TargetRegisterInfo.h" #include "llvm/CodeGen/TargetSubtargetInfo.h" @@ -71,6 +72,7 @@ #include <cstdint> #include <iterator> #include <string> +#include <type_traits> #include <utility> #include <vector> @@ -339,6 +341,59 @@ 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. +void MachineFunction::createBBLabels() { + const TargetInstrInfo *TII = getSubtarget().getInstrInfo(); + this->BBSectionsSymbolPrefix.resize(getNumBlockIDs(), 'a'); + for (auto MBBI = begin(), E = end(); MBBI != E; ++MBBI) { + assert( + (MBBI->getNumber() >= 0 && MBBI->getNumber() < (int)getNumBlockIDs()) && + "BasicBlock number was out of range!"); + // 'a' - Normal block. + // 'r' - Return block. + // 'l' - Landing Pad. + // 'L' - Return and landing pad. + bool isEHPad = MBBI->isEHPad(); + bool isRetBlock = MBBI->isReturnBlock() && !TII->isTailCall(MBBI->back()); + char type = 'a'; + if (isEHPad && isRetBlock) + type = 'L'; + else if (isEHPad) + type = 'l'; + else if (isRetBlock) + type = 'r'; + BBSectionsSymbolPrefix[MBBI->getNumber()] = type; + } +} + /// Allocate a new MachineInstr. Use this instead of `new MachineInstr'. MachineInstr *MachineFunction::CreateMachineInstr(const MCInstrDesc &MCID, const DebugLoc &DL, |