aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
diff options
context:
space:
mode:
authorRahman Lavaee <rahmanl@google.com>2020-04-13 11:39:23 -0700
committerRahman Lavaee <rahmanl@google.com>2020-04-13 11:46:11 -0700
commit0d4ec16d3db3a92514e14101f635e8536c208c4f (patch)
tree1fff57189fd9a875ff3b2023035a26a2287eb11a /llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
parentec228d722c08847c2b5bb12a99191d77df3374af (diff)
downloadllvm-0d4ec16d3db3a92514e14101f635e8536c208c4f.zip
llvm-0d4ec16d3db3a92514e14101f635e8536c208c4f.tar.gz
llvm-0d4ec16d3db3a92514e14101f635e8536c208c4f.tar.bz2
Extend BasicBlock sections to allow specifying clusters of basic blocks
in the same section. This allows specifying BasicBlock clusters like the following example: !foo !!0 1 2 !!4 This places basic blocks 0, 1, and 2 in one section in this order, and places basic block #4 in a single section of its own.
Diffstat (limited to 'llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp')
-rw-r--r--llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp52
1 files changed, 21 insertions, 31 deletions
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index b96cba4..1794669 100644
--- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -769,42 +769,31 @@ MCSection *TargetLoweringObjectFileELF::getSectionForConstant(
MCSection *TargetLoweringObjectFileELF::getSectionForMachineBasicBlock(
const Function &F, const MachineBasicBlock &MBB,
const TargetMachine &TM) const {
+ assert(MBB.isBeginSection() && "Basic block does not start a section!");
SmallString<128> Name;
Name = (static_cast<MCSectionELF *>(MBB.getParent()->getSection()))
->getSectionName();
- if (TM.getUniqueBBSectionNames()) {
- Name += ".";
- Name += MBB.getSymbol()->getName();
- }
- unsigned UniqueID = NextUniqueID++;
- unsigned Flags = ELF::SHF_ALLOC | ELF::SHF_EXECINSTR;
- std::string GroupName = "";
- if (F.hasComdat()) {
- Flags |= ELF::SHF_GROUP;
- GroupName = F.getComdat()->getName().str();
- }
- return getContext().getELFSection(Name, ELF::SHT_PROGBITS, Flags,
- 0 /* Entry Size */, GroupName, UniqueID,
- nullptr);
-}
-
-MCSection *TargetLoweringObjectFileELF::getNamedSectionForMachineBasicBlock(
- const Function &F, const MachineBasicBlock &MBB, const TargetMachine &TM,
- const char *Suffix) const {
- SmallString<128> Name;
- Name = (static_cast<MCSectionELF *>(MBB.getParent()->getSection()))
- ->getSectionName();
+ unsigned UniqueID = MCContext::GenericSectionID;
- // If unique section names is off, explicity add the function name to the
- // section name to make sure named sections for functions are unique
- // across the module.
- if (!TM.getUniqueSectionNames()) {
- Name += ".";
- Name += MBB.getParent()->getName();
+ switch (MBB.getSectionID().Type) {
+ // Append suffixes to represent special cold and exception sections.
+ case MBBSectionID::SectionType::Exception:
+ Name += ".eh";
+ break;
+ case MBBSectionID::SectionType::Cold:
+ Name += ".unlikely";
+ break;
+ // For regular sections, either use a unique name, or a unique ID for the
+ // section.
+ default:
+ if (TM.getUniqueBBSectionNames()) {
+ Name += ".";
+ Name += MBB.getSymbol()->getName();
+ } else
+ UniqueID = NextUniqueID++;
+ break;
}
- Name += Suffix;
-
unsigned Flags = ELF::SHF_ALLOC | ELF::SHF_EXECINSTR;
std::string GroupName = "";
if (F.hasComdat()) {
@@ -812,7 +801,8 @@ MCSection *TargetLoweringObjectFileELF::getNamedSectionForMachineBasicBlock(
GroupName = F.getComdat()->getName().str();
}
return getContext().getELFSection(Name, ELF::SHT_PROGBITS, Flags,
- 0 /* Entry Size */, GroupName);
+ 0 /* Entry Size */, GroupName, UniqueID,
+ nullptr);
}
static MCSectionELF *getStaticStructorSection(MCContext &Ctx, bool UseInitArray,