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/MachineBasicBlock.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/MachineBasicBlock.cpp')
-rw-r--r-- | llvm/lib/CodeGen/MachineBasicBlock.cpp | 69 |
1 files changed, 65 insertions, 4 deletions
diff --git a/llvm/lib/CodeGen/MachineBasicBlock.cpp b/llvm/lib/CodeGen/MachineBasicBlock.cpp index c2f459e..b273da8 100644 --- a/llvm/lib/CodeGen/MachineBasicBlock.cpp +++ b/llvm/lib/CodeGen/MachineBasicBlock.cpp @@ -61,12 +61,31 @@ MCSymbol *MachineBasicBlock::getSymbol() const { const MachineFunction *MF = getParent(); MCContext &Ctx = MF->getContext(); auto Prefix = Ctx.getAsmInfo()->getPrivateLabelPrefix(); + + bool BasicBlockSymbols = MF->hasBBSections() || MF->hasBBLabels(); + auto Delimiter = BasicBlockSymbols ? "." : "_"; assert(getNumber() >= 0 && "cannot get label for unreachable MBB"); - CachedMCSymbol = Ctx.getOrCreateSymbol(Twine(Prefix) + "BB" + - Twine(MF->getFunctionNumber()) + - "_" + Twine(getNumber())); - } + // With Basic Block Sections, we emit a symbol for every basic block. To + // keep the size of strtab small, we choose a unary encoding which can + // compress the symbol names significantly. The basic blocks for function + // foo are named a.BB.foo, aa.BB.foo, and so on. + if (BasicBlockSymbols) { + auto Iter = MF->getBBSectionsSymbolPrefix().begin(); + if (getNumber() < 0 || + getNumber() >= (int)MF->getBBSectionsSymbolPrefix().size()) + report_fatal_error("Unreachable MBB: " + Twine(getNumber())); + std::string Prefix(Iter + 1, Iter + getNumber() + 1); + std::reverse(Prefix.begin(), Prefix.end()); + CachedMCSymbol = + Ctx.getOrCreateSymbol(Prefix + Twine(Delimiter) + "BB" + + Twine(Delimiter) + Twine(MF->getName())); + } else { + CachedMCSymbol = Ctx.getOrCreateSymbol( + Twine(Prefix) + "BB" + Twine(MF->getFunctionNumber()) + + Twine(Delimiter) + Twine(getNumber())); + } + } return CachedMCSymbol; } @@ -529,6 +548,48 @@ void MachineBasicBlock::moveAfter(MachineBasicBlock *NewBefore) { getParent()->splice(++NewBefore->getIterator(), getIterator()); } +// Returns true if this basic block and the Other are in the same section. +bool MachineBasicBlock::sameSection(const MachineBasicBlock *Other) const { + if (this == Other) + return true; + + if (this->getSectionType() != Other->getSectionType()) + return false; + + // If either is in a unique section, return false. + if (this->getSectionType() == llvm::MachineBasicBlockSection::MBBS_Unique || + Other->getSectionType() == llvm::MachineBasicBlockSection::MBBS_Unique) + return false; + + return true; +} + +const MachineBasicBlock *MachineBasicBlock::getSectionEndMBB() const { + if (this->isEndSection()) + return this; + auto I = std::next(this->getIterator()); + const MachineFunction *MF = getParent(); + while (I != MF->end()) { + const MachineBasicBlock &MBB = *I; + if (MBB.isEndSection()) + return &MBB; + I = std::next(I); + } + llvm_unreachable("No End Basic Block for this section."); +} + +// Returns true if this block begins any section. +bool MachineBasicBlock::isBeginSection() const { + return (SectionType == MBBS_Entry || SectionType == MBBS_Unique || + getParent()->isSectionStartMBB(getNumber())); +} + +// Returns true if this block begins any section. +bool MachineBasicBlock::isEndSection() const { + return (SectionType == MBBS_Entry || SectionType == MBBS_Unique || + getParent()->isSectionEndMBB(getNumber())); +} + void MachineBasicBlock::updateTerminator() { const TargetInstrInfo *TII = getParent()->getSubtarget().getInstrInfo(); // A block with no successors has no concerns with fall-through edges. |