aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/MachineBasicBlock.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/CodeGen/MachineBasicBlock.cpp')
-rw-r--r--llvm/lib/CodeGen/MachineBasicBlock.cpp69
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.