From c8ac29ab1d798f16999541cd9f08d58ebaa1b4c1 Mon Sep 17 00:00:00 2001 From: Snehasish Kumar Date: Mon, 4 May 2020 19:02:57 +0000 Subject: Descriptive symbol names for machine basic block sections. Today symbol names generated for machine basic block sections use a unary encoding to reduce bloat. This is essential when every basic block in the binary is assigned a symbol however with basic block clusters (rG05192e585ce175b55f2a26b83b4ed7882785c8e6) when we only need to generate a few non-temporary symbols we can assign more descriptive names making them more user friendly. With this change - Cold cluster section for function foo is named "foo.cold" Exception cluster section for function foo is named "foo.eh" Other cluster sections identified by their ids are named "foo.ID" Using this format works well with existing tools. It will demangle as expected and works with existing symbolizers, profilers and debuggers out of the box. $ c++filt _Z3foov.cold foo() [clone .cold] $ c++filt _Z3foov.eh foo() [clone .eh] $c++filt _Z3foov.1234 foo() [clone 1234] Tests for basicblock-sections are updated with some cleanup where appropriate. Differential Revision: https://reviews.llvm.org/D79221 --- llvm/lib/CodeGen/MachineBasicBlock.cpp | 37 +++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 14 deletions(-) (limited to 'llvm/lib/CodeGen/MachineBasicBlock.cpp') diff --git a/llvm/lib/CodeGen/MachineBasicBlock.cpp b/llvm/lib/CodeGen/MachineBasicBlock.cpp index 57dd8d3..09e31af 100644 --- a/llvm/lib/CodeGen/MachineBasicBlock.cpp +++ b/llvm/lib/CodeGen/MachineBasicBlock.cpp @@ -62,30 +62,39 @@ MCSymbol *MachineBasicBlock::getSymbol() const { MCContext &Ctx = MF->getContext(); auto Prefix = Ctx.getAsmInfo()->getPrivateLabelPrefix(); - // We emit a non-temporary symbol for every basic block if we have BBLabels - // or -- with basic block sections -- when a basic block begins a section. - bool BasicBlockSymbols = isBeginSection() || MF->hasBBLabels(); - auto Delimiter = BasicBlockSymbols ? "." : "_"; assert(getNumber() >= 0 && "cannot get label for unreachable MBB"); - // 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) { + // We emit a non-temporary symbol for every basic block if we have BBLabels + // or -- with basic block sections -- when a basic block begins a section. + // With basic block symbols, we use a unary encoding which can + // compress the symbol names significantly. For basic block sections where + // this block is the first in a cluster, we use a non-temp descriptive name. + // Otherwise we fall back to use temp label. + if (MF->hasBBLabels()) { auto Iter = MF->getBBSectionsSymbolPrefix().begin(); if (getNumber() < 0 || getNumber() >= (int)MF->getBBSectionsSymbolPrefix().size()) report_fatal_error("Unreachable MBB: " + Twine(getNumber())); + // The basic blocks for function foo are named a.BB.foo, aa.BB.foo, and + // so on. 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())); + Ctx.getOrCreateSymbol(Twine(Prefix) + ".BB." + Twine(MF->getName())); + } else if (MF->hasBBSections() && isBeginSection()) { + SmallString<5> Suffix; + if (SectionID == MBBSectionID::ColdSectionID) { + Suffix += ".cold"; + } else if (SectionID == MBBSectionID::ExceptionSectionID) { + Suffix += ".eh"; + } else { + Suffix += "." + std::to_string(SectionID.Number); + } + CachedMCSymbol = Ctx.getOrCreateSymbol(MF->getName() + Suffix); } else { - CachedMCSymbol = Ctx.getOrCreateSymbol( - Twine(Prefix) + "BB" + Twine(MF->getFunctionNumber()) + - Twine(Delimiter) + Twine(getNumber())); + CachedMCSymbol = Ctx.getOrCreateSymbol(Twine(Prefix) + "BB" + + Twine(MF->getFunctionNumber()) + + "_" + Twine(getNumber())); } } return CachedMCSymbol; -- cgit v1.1