[PATCH] D78742: Use .text.unlikely prefix for cold MachineBasicBlock sections.
Snehasish Kumar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 23 12:28:28 PDT 2020
snehasish created this revision.
snehasish added reviewers: tmsriram, mtrofin.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
Instead of adding a ".unlikely" suffix for cold machine basic blocks,
this change updates the behaviour to use a ".text.unlikely" prefix
instead. This allows lld to group cold basic block sections together
when -z,keep-text-section-prefix is specified.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D78742
Files:
llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
llvm/test/CodeGen/X86/basicblock-sections-clusters-branches.ll
llvm/test/CodeGen/X86/basicblock-sections-clusters.ll
llvm/test/CodeGen/X86/basicblock-sections-cold.ll
Index: llvm/test/CodeGen/X86/basicblock-sections-cold.ll
===================================================================
--- llvm/test/CodeGen/X86/basicblock-sections-cold.ll
+++ llvm/test/CodeGen/X86/basicblock-sections-cold.ll
@@ -34,7 +34,7 @@
; Check that the basic block with id 1 doesn't get a section.
; LINUX-SECTIONS-NOT: .section .text._Z3bazb.r.BB._Z3bazb,"ax", at progbits,unique
; Check that a single cold section is started here and id 1 and 2 blocks are placed here.
-; LINUX-SECTIONS: .section .text._Z3bazb.unlikely,"ax", at progbits
+; LINUX-SECTIONS: .section .text.unlikely._Z3bazb,"ax", at progbits
; LINUX-SECTIONS: r.BB._Z3bazb:
; LINUX-SECTIONS-NOT: .section .text._Z3bazb.rr.BB._Z3bazb,"ax", at progbits,unique
; LINUX-SECTIONS: .LBB0_2:
Index: llvm/test/CodeGen/X86/basicblock-sections-clusters.ll
===================================================================
--- llvm/test/CodeGen/X86/basicblock-sections-clusters.ll
+++ llvm/test/CodeGen/X86/basicblock-sections-clusters.ll
@@ -48,7 +48,7 @@
; LINUX-SECTIONS1-LABEL: .Ltmp0:
; LINUX-SECTIONS1-NEXT: .size a.BB.foo, .Ltmp0-a.BB.foo
; LINUX-SECTIONS1-NOT: .section
-; LINUX-SECTIONS1: .section .text.foo.unlikely,"ax", at progbits
+; LINUX-SECTIONS1: .section .text.unlikely.foo,"ax", at progbits
; LINUX-SECTIONS1-LABEL: raa.BB.foo:
; LINUX-SECTIONS1: .section .text.foo,"ax", at progbits
; LINUX-SECTIONS1-LABEL: .Lfunc_end0:
Index: llvm/test/CodeGen/X86/basicblock-sections-clusters-branches.ll
===================================================================
--- llvm/test/CodeGen/X86/basicblock-sections-clusters-branches.ll
+++ llvm/test/CodeGen/X86/basicblock-sections-clusters-branches.ll
@@ -50,7 +50,7 @@
; LINUX-SECTIONS1: .section .text.foo,"ax", at progbits,unique,1
; LINUX-SECTIONS1-LABEL: a.BB.foo:
; LINUX-SECTIONS1: jmp raa.BB.foo
-; LINUX-SECTIONS1: .section .text.foo.unlikely,"ax", at progbits
+; LINUX-SECTIONS1: .section .text.unlikely.foo,"ax", at progbits
; LINUX-SECTIONS1-LABEL: raa.BB.foo:
; LINUX-SECTIONS2: .section .text.foo,"ax", at progbits
Index: llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
===================================================================
--- llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -859,28 +859,31 @@
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()))->getName();
unsigned UniqueID = MCContext::GenericSectionID;
- 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;
+ // For cold sections use the .text.unlikely prefix along with the parent
+ // function name. All cold blocks for the same function go to the same
+ // section. For exception blocks add a suffix to identify. For regular
+ // sections, either use a unique name, or a unique ID for the section.
+ SmallString<128> Name;
+ if (MBB.getSectionID() == MBBSectionID::ColdSectionID) {
+ Name += ".text.unlikely.";
+ Name += MBB.getParent()->getName();
+ } else {
+ Name += MBB.getParent()->getSection()->getName();
+ switch (MBB.getSectionID().Type) {
+ case MBBSectionID::SectionType::Exception: {
+ Name += ".eh";
+ break;
+ }
+ default:
+ if (TM.getUniqueBBSectionNames()) {
+ Name += ".";
+ Name += MBB.getSymbol()->getName();
+ } else
+ UniqueID = NextUniqueID++;
+ break;
+ }
}
unsigned Flags = ELF::SHF_ALLOC | ELF::SHF_EXECINSTR;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78742.259658.patch
Type: text/x-patch
Size: 4163 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200423/70345cac/attachment.bin>
More information about the llvm-commits
mailing list