diff options
author | Rahman Lavaee <rahmanl@google.com> | 2023-09-22 16:49:12 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-22 13:49:12 -0700 |
commit | 897a0b01d6a4f063b4fa2561a8aeaff14f411053 (patch) | |
tree | 4a1c65f405edefc4a0db0792b72c55535e5e7021 /llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp | |
parent | 233b6ef66cc640bcde317fa2e2bfad78a52b257d (diff) | |
download | llvm-897a0b01d6a4f063b4fa2561a8aeaff14f411053.zip llvm-897a0b01d6a4f063b4fa2561a8aeaff14f411053.tar.gz llvm-897a0b01d6a4f063b4fa2561a8aeaff14f411053.tar.bz2 |
[BasicBlockSections] Split cold parts of custom-section functions. (#66731)
This PR makes `-basic-block-sections` handle functions with custom
non-dot-text sections correctly. Cold parts of such functions must be
placed in the same section (not in `.text.split`) but with a unique id.
Diffstat (limited to 'llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp')
-rw-r--r-- | llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index 622c8ad..6210e7f 100644 --- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -1038,21 +1038,32 @@ MCSection *TargetLoweringObjectFileELF::getSectionForMachineBasicBlock( // under the .text.eh prefix. For regular sections, we either use a unique // name, or a unique ID for the section. SmallString<128> Name; - if (MBB.getSectionID() == MBBSectionID::ColdSectionID) { - Name += BBSectionsColdTextPrefix; - Name += MBB.getParent()->getName(); - } else if (MBB.getSectionID() == MBBSectionID::ExceptionSectionID) { - Name += ".text.eh."; - Name += MBB.getParent()->getName(); - } else { - Name += MBB.getParent()->getSection()->getName(); - if (TM.getUniqueBasicBlockSectionNames()) { - if (!Name.endswith(".")) - Name += "."; - Name += MBB.getSymbol()->getName(); + StringRef FunctionSectionName = MBB.getParent()->getSection()->getName(); + if (FunctionSectionName.equals(".text") || + FunctionSectionName.startswith(".text.")) { + // Function is in a regular .text section. + StringRef FunctionName = MBB.getParent()->getName(); + if (MBB.getSectionID() == MBBSectionID::ColdSectionID) { + Name += BBSectionsColdTextPrefix; + Name += FunctionName; + } else if (MBB.getSectionID() == MBBSectionID::ExceptionSectionID) { + Name += ".text.eh."; + Name += FunctionName; } else { - UniqueID = NextUniqueID++; + Name += FunctionSectionName; + if (TM.getUniqueBasicBlockSectionNames()) { + if (!Name.endswith(".")) + Name += "."; + Name += MBB.getSymbol()->getName(); + } else { + UniqueID = NextUniqueID++; + } } + } else { + // If the original function has a custom non-dot-text section, then emit + // all basic block sections into that section too, each with a unique id. + Name = FunctionSectionName; + UniqueID = NextUniqueID++; } unsigned Flags = ELF::SHF_ALLOC | ELF::SHF_EXECINSTR; |