[llvm] 0cc063a - Use .text.unlikely and .text.eh prefixes for MachineBasicBlock sections.
Sriraman Tallam via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 24 15:08:25 PDT 2020
Author: Snehasish Kumar
Date: 2020-04-24T15:07:38-07:00
New Revision: 0cc063a8ffc896aa82ebe4b11003f0bbd78d6d5b
URL: https://github.com/llvm/llvm-project/commit/0cc063a8ffc896aa82ebe4b11003f0bbd78d6d5b
DIFF: https://github.com/llvm/llvm-project/commit/0cc063a8ffc896aa82ebe4b11003f0bbd78d6d5b.diff
LOG: Use .text.unlikely and .text.eh prefixes for MachineBasicBlock sections.
Summary:
Instead of adding a ".unlikely" or ".eh" suffix for machine basic blocks,
this change updates the behaviour to use an appropriate prefix
instead. This allows lld to group basic block sections together
when -z,keep-text-section-prefix is specified and matches the behaviour
observed in gcc.
Reviewers: tmsriram, mtrofin, efriedma
Reviewed By: tmsriram, efriedma
Subscribers: eli.friedman, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D78742
Added:
Modified:
llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
llvm/test/CodeGen/X86/basicblock-sections-clusters-branches.ll
llvm/test/CodeGen/X86/basicblock-sections-clusters-eh.ll
llvm/test/CodeGen/X86/basicblock-sections-clusters.ll
llvm/test/CodeGen/X86/basicblock-sections-cold.ll
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index 8ed3e8673a84..a2dfa0a5734f 100644
--- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -859,28 +859,28 @@ 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()))->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:
+ // 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. Similarly all exception blocks are grouped by symbol name
+ // 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 += ".text.unlikely.";
+ 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.getUniqueBBSectionNames()) {
Name += ".";
Name += MBB.getSymbol()->getName();
- } else
+ } else {
UniqueID = NextUniqueID++;
- break;
+ }
}
unsigned Flags = ELF::SHF_ALLOC | ELF::SHF_EXECINSTR;
diff --git a/llvm/test/CodeGen/X86/basicblock-sections-clusters-branches.ll b/llvm/test/CodeGen/X86/basicblock-sections-clusters-branches.ll
index 9baea85112cd..c85f01b91984 100644
--- a/llvm/test/CodeGen/X86/basicblock-sections-clusters-branches.ll
+++ b/llvm/test/CodeGen/X86/basicblock-sections-clusters-branches.ll
@@ -50,7 +50,7 @@ declare i32 @baz() #1
; 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
diff --git a/llvm/test/CodeGen/X86/basicblock-sections-clusters-eh.ll b/llvm/test/CodeGen/X86/basicblock-sections-clusters-eh.ll
index f4e6ef370770..cadbdd355db0 100644
--- a/llvm/test/CodeGen/X86/basicblock-sections-clusters-eh.ll
+++ b/llvm/test/CodeGen/X86/basicblock-sections-clusters-eh.ll
@@ -62,7 +62,7 @@ declare i32 @__gxx_personality_v0(...)
; LINUX-SECTIONS1-LABEL: .LBB0_6:
; LINUX-SECTIONS1: .section .text.main,"ax", at progbits,unique,1
; LINUX-SECTIONS1-LABEL: al.BB.main:
-; LINUX-SECTIONS1: .section .text.main.eh,"ax", at progbits
+; LINUX-SECTIONS1: .section .text.eh.main,"ax", at progbits
; LINUX-SECTIONS1-LABEL: l.BB.main:
; LINUX-SECTIONS1-NOT: .section
; LINUX-SECTIONS1-LABEL: .LBB0_3:
diff --git a/llvm/test/CodeGen/X86/basicblock-sections-clusters.ll b/llvm/test/CodeGen/X86/basicblock-sections-clusters.ll
index 3daf3a3c0ec0..39d0b3898e42 100644
--- a/llvm/test/CodeGen/X86/basicblock-sections-clusters.ll
+++ b/llvm/test/CodeGen/X86/basicblock-sections-clusters.ll
@@ -48,7 +48,7 @@ declare i32 @baz() #1
; 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:
diff --git a/llvm/test/CodeGen/X86/basicblock-sections-cold.ll b/llvm/test/CodeGen/X86/basicblock-sections-cold.ll
index 114ea8fe539d..b2a36e8d2ffc 100644
--- a/llvm/test/CodeGen/X86/basicblock-sections-cold.ll
+++ b/llvm/test/CodeGen/X86/basicblock-sections-cold.ll
@@ -34,7 +34,7 @@ declare i32 @_Z3foov() #1
; 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:
More information about the llvm-commits
mailing list