diff options
Diffstat (limited to 'llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp')
-rw-r--r-- | llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index 6ab6d18..3c2c7c8 100644 --- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -24,6 +24,7 @@ #include "llvm/CodeGen/BasicBlockSectionUtils.h" #include "llvm/CodeGen/MachineBasicBlock.h" #include "llvm/CodeGen/MachineFunction.h" +#include "llvm/CodeGen/MachineJumpTableInfo.h" #include "llvm/CodeGen/MachineModuleInfo.h" #include "llvm/CodeGen/MachineModuleInfoImpls.h" #include "llvm/IR/Comdat.h" @@ -648,7 +649,8 @@ static StringRef getSectionPrefixForGlobal(SectionKind Kind, bool IsLarge) { static SmallString<128> getELFSectionNameForGlobal(const GlobalObject *GO, SectionKind Kind, Mangler &Mang, const TargetMachine &TM, - unsigned EntrySize, bool UniqueSectionName) { + unsigned EntrySize, bool UniqueSectionName, + const MachineJumpTableEntry *JTE) { SmallString<128> Name = getSectionPrefixForGlobal(Kind, TM.isLargeGlobalValue(GO)); if (Kind.isMergeableCString()) { @@ -669,7 +671,19 @@ getELFSectionNameForGlobal(const GlobalObject *GO, SectionKind Kind, bool HasPrefix = false; if (const auto *F = dyn_cast<Function>(GO)) { - if (std::optional<StringRef> Prefix = F->getSectionPrefix()) { + // Jump table hotness takes precedence over its enclosing function's hotness + // if it's known. The function's section prefix is used if jump table entry + // hotness is unknown. + if (JTE && JTE->Hotness != MachineFunctionDataHotness::Unknown) { + if (JTE->Hotness == MachineFunctionDataHotness::Hot) { + raw_svector_ostream(Name) << ".hot"; + } else { + assert(JTE->Hotness == MachineFunctionDataHotness::Cold && + "Hotness must be cold"); + raw_svector_ostream(Name) << ".unlikely"; + } + HasPrefix = true; + } else if (std::optional<StringRef> Prefix = F->getSectionPrefix()) { raw_svector_ostream(Name) << '.' << *Prefix; HasPrefix = true; } @@ -767,8 +781,8 @@ calcUniqueIDUpdateFlagsAndSize(const GlobalObject *GO, StringRef SectionName, // implicitly for this symbol e.g. .rodata.str1.1, then we don't need // to unique the section as the entry size for this symbol will be // compatible with implicitly created sections. - SmallString<128> ImplicitSectionNameStem = - getELFSectionNameForGlobal(GO, Kind, Mang, TM, EntrySize, false); + SmallString<128> ImplicitSectionNameStem = getELFSectionNameForGlobal( + GO, Kind, Mang, TM, EntrySize, false, /*MJTE=*/nullptr); if (SymbolMergeable && Ctx.isELFImplicitMergeableSectionNamePrefix(SectionName) && SectionName.starts_with(ImplicitSectionNameStem)) @@ -874,7 +888,8 @@ MCSection *TargetLoweringObjectFileELF::getExplicitSectionGlobal( static MCSectionELF *selectELFSectionForGlobal( MCContext &Ctx, const GlobalObject *GO, SectionKind Kind, Mangler &Mang, const TargetMachine &TM, bool EmitUniqueSection, unsigned Flags, - unsigned *NextUniqueID, const MCSymbolELF *AssociatedSymbol) { + unsigned *NextUniqueID, const MCSymbolELF *AssociatedSymbol, + const MachineJumpTableEntry *MJTE = nullptr) { auto [Group, IsComdat, ExtraFlags] = getGlobalObjectInfo(GO, TM); Flags |= ExtraFlags; @@ -893,7 +908,7 @@ static MCSectionELF *selectELFSectionForGlobal( } } SmallString<128> Name = getELFSectionNameForGlobal( - GO, Kind, Mang, TM, EntrySize, UniqueSectionName); + GO, Kind, Mang, TM, EntrySize, UniqueSectionName, MJTE); // Use 0 as the unique ID for execute-only text. if (Kind.isExecuteOnly()) @@ -967,17 +982,23 @@ MCSection *TargetLoweringObjectFileELF::getUniqueSectionForFunction( MCSection *TargetLoweringObjectFileELF::getSectionForJumpTable( const Function &F, const TargetMachine &TM) const { + return getSectionForJumpTable(F, TM, /*JTE=*/nullptr); +} + +MCSection *TargetLoweringObjectFileELF::getSectionForJumpTable( + const Function &F, const TargetMachine &TM, + const MachineJumpTableEntry *JTE) const { // If the function can be removed, produce a unique section so that // the table doesn't prevent the removal. const Comdat *C = F.getComdat(); bool EmitUniqueSection = TM.getFunctionSections() || C; - if (!EmitUniqueSection) + if (!EmitUniqueSection && !TM.getEnableStaticDataPartitioning()) return ReadOnlySection; return selectELFSectionForGlobal(getContext(), &F, SectionKind::getReadOnly(), getMangler(), TM, EmitUniqueSection, ELF::SHF_ALLOC, &NextUniqueID, - /* AssociatedSymbol */ nullptr); + /* AssociatedSymbol */ nullptr, JTE); } MCSection *TargetLoweringObjectFileELF::getSectionForLSDA( |