1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 03:02:36 +01:00

Descriptive symbol names for machine basic block sections.

Today symbol names generated for machine basic block sections use a
unary encoding to reduce bloat. This is essential when every basic block
in the binary is assigned a symbol however with basic block clusters
(rG05192e585ce175b55f2a26b83b4ed7882785c8e6) when we only need to
generate a few non-temporary symbols we can assign more descriptive
names making them more user friendly. With this change -

Cold cluster section for function foo is named "foo.cold"
Exception cluster section for function foo is named "foo.eh"
Other cluster sections identified by their ids are named "foo.ID"
Using this format works well with existing tools. It will demangle as
expected and works with existing symbolizers, profilers and debuggers
out of the box.

$ c++filt _Z3foov.cold
foo() [clone .cold]

$ c++filt _Z3foov.eh
foo() [clone .eh]

$c++filt _Z3foov.1234
foo() [clone 1234]

Tests for basicblock-sections are updated with some cleanup where
appropriate.

Differential Revision: https://reviews.llvm.org/D79221
This commit is contained in:
Snehasish Kumar 2020-05-04 19:02:57 +00:00
parent d4f7430fcd
commit f377268c0f
11 changed files with 84 additions and 77 deletions

View File

@ -62,30 +62,39 @@ MCSymbol *MachineBasicBlock::getSymbol() const {
MCContext &Ctx = MF->getContext();
auto Prefix = Ctx.getAsmInfo()->getPrivateLabelPrefix();
// We emit a non-temporary symbol for every basic block if we have BBLabels
// or -- with basic block sections -- when a basic block begins a section.
bool BasicBlockSymbols = isBeginSection() || MF->hasBBLabels();
auto Delimiter = BasicBlockSymbols ? "." : "_";
assert(getNumber() >= 0 && "cannot get label for unreachable MBB");
// With Basic Block Sections, we emit a symbol for every basic block. To
// keep the size of strtab small, we choose a unary encoding which can
// compress the symbol names significantly. The basic blocks for function
// foo are named a.BB.foo, aa.BB.foo, and so on.
if (BasicBlockSymbols) {
// We emit a non-temporary symbol for every basic block if we have BBLabels
// or -- with basic block sections -- when a basic block begins a section.
// With basic block symbols, we use a unary encoding which can
// compress the symbol names significantly. For basic block sections where
// this block is the first in a cluster, we use a non-temp descriptive name.
// Otherwise we fall back to use temp label.
if (MF->hasBBLabels()) {
auto Iter = MF->getBBSectionsSymbolPrefix().begin();
if (getNumber() < 0 ||
getNumber() >= (int)MF->getBBSectionsSymbolPrefix().size())
report_fatal_error("Unreachable MBB: " + Twine(getNumber()));
// The basic blocks for function foo are named a.BB.foo, aa.BB.foo, and
// so on.
std::string Prefix(Iter + 1, Iter + getNumber() + 1);
std::reverse(Prefix.begin(), Prefix.end());
CachedMCSymbol =
Ctx.getOrCreateSymbol(Prefix + Twine(Delimiter) + "BB" +
Twine(Delimiter) + Twine(MF->getName()));
Ctx.getOrCreateSymbol(Twine(Prefix) + ".BB." + Twine(MF->getName()));
} else if (MF->hasBBSections() && isBeginSection()) {
SmallString<5> Suffix;
if (SectionID == MBBSectionID::ColdSectionID) {
Suffix += ".cold";
} else if (SectionID == MBBSectionID::ExceptionSectionID) {
Suffix += ".eh";
} else {
Suffix += "." + std::to_string(SectionID.Number);
}
CachedMCSymbol = Ctx.getOrCreateSymbol(MF->getName() + Suffix);
} else {
CachedMCSymbol = Ctx.getOrCreateSymbol(
Twine(Prefix) + "BB" + Twine(MF->getFunctionNumber()) +
Twine(Delimiter) + Twine(getNumber()));
CachedMCSymbol = Ctx.getOrCreateSymbol(Twine(Prefix) + "BB" +
Twine(MF->getFunctionNumber()) +
"_" + Twine(getNumber()));
}
}
return CachedMCSymbol;

View File

@ -17,7 +17,7 @@
; RUN: echo '!!1 3' >> %t2
; RUN: llc < %s -O0 -mtriple=x86_64-pc-linux -function-sections -basicblock-sections=%t2 | FileCheck %s -check-prefix=LINUX-SECTIONS2
define void @foo(i1 zeroext) {
define void @foo(i1 zeroext) nounwind {
%2 = alloca i8, align 1
%3 = zext i1 %0 to i8
store i8 %3, i8* %2, align 1
@ -43,23 +43,23 @@ declare i32 @baz() #1
; LINUX-SECTIONS1: .section .text.foo,"ax",@progbits
; LINUX-SECTIONS1-LABEL: foo:
; LINUX-SECTIONS1: jne a.BB.foo
; LINUX-SECTIONS1: jne foo.1
; LINUX-SECTIONS1-NOT: {{jne|je|jmp}}
; LINUX-SECTIONS1-LABEL: # %bb.2:
; LINUX-SECTIONS1: jmp raa.BB.foo
; LINUX-SECTIONS1: jmp foo.cold
; LINUX-SECTIONS1: .section .text.foo,"ax",@progbits,unique,1
; LINUX-SECTIONS1-LABEL: a.BB.foo:
; LINUX-SECTIONS1: jmp raa.BB.foo
; LINUX-SECTIONS1-LABEL: foo.1:
; LINUX-SECTIONS1: jmp foo.cold
; LINUX-SECTIONS1: .section .text.unlikely.foo,"ax",@progbits
; LINUX-SECTIONS1-LABEL: raa.BB.foo:
; LINUX-SECTIONS1-LABEL: foo.cold:
; LINUX-SECTIONS2: .section .text.foo,"ax",@progbits
; LINUX-SECTIONS2-LABEL: foo:
; LINUX-SECTIONS2: jne a.BB.foo
; LINUX-SECTIONS2: jne foo.0
; LINUX-SECTIONS2-NOT: {{jne|je|jmp}}
; LINUX-SECTIONS2-LABEL: # %bb.2:
; LINUX-SECTIONS2: jmp .LBB0_3
; LINUX-SECTIONS2: .section .text.foo,"ax",@progbits,unique,1
; LINUX-SECTIONS2: a.BB.foo:
; LINUX-SECTIONS2: foo.0:
; LINUX-SECTIONS2-NOT: {{jne|je|jmp}}
; LINUX-SECTIONS2: .LBB0_3:

View File

@ -13,7 +13,6 @@
; RUN: echo '!main' > %t2
; RUN: echo '!!1 2 3' >> %t2
; RUN: llc < %s -O0 -mtriple=x86_64-pc-linux -function-sections -basicblock-sections=%t2 | FileCheck %s -check-prefix=LINUX-SECTIONS2
;
@_ZTIi = external constant i8*
@ -61,9 +60,9 @@ declare i32 @__gxx_personality_v0(...)
; LINUX-SECTIONS1-NOT: .section
; LINUX-SECTIONS1-LABEL: .LBB0_6:
; LINUX-SECTIONS1: .section .text.main,"ax",@progbits,unique,1
; LINUX-SECTIONS1-LABEL: al.BB.main:
; LINUX-SECTIONS1-LABEL: main.0:
; LINUX-SECTIONS1: .section .text.eh.main,"ax",@progbits
; LINUX-SECTIONS1-LABEL: l.BB.main:
; LINUX-SECTIONS1-LABEL: main.eh:
; LINUX-SECTIONS1-NOT: .section
; LINUX-SECTIONS1-LABEL: .LBB0_3:
; LINUX-SECTIONS1-NOT: .section
@ -80,7 +79,7 @@ declare i32 @__gxx_personality_v0(...)
; LINUX-SECTIONS2-NOT: .section
; LINUX-SECTIONS2-LABEL: .LBB0_6:
; LINUX-SECTIONS2: .section .text.main,"ax",@progbits,unique,1
; LINUX-SECTIONS2-LABEL: l.BB.main:
; LINUX-SECTIONS2-LABEL: main.0:
; LINUX-SECTIONS2-NOT: .section
; LINUX-SECTIONS2-LABEL: .LBB0_2:
; LINUX-SECTIONS2-NOT: .section

View File

@ -14,7 +14,7 @@
; RUN: echo '!!1 3' >> %t2
; RUN: llc < %s -O0 -mtriple=x86_64-pc-linux -function-sections -basicblock-sections=%t2 | FileCheck %s -check-prefix=LINUX-SECTIONS2
define void @foo(i1 zeroext) {
define void @foo(i1 zeroext) nounwind {
%2 = alloca i8, align 1
%3 = zext i1 %0 to i8
store i8 %3, i8* %2, align 1
@ -44,12 +44,12 @@ declare i32 @baz() #1
; LINUX-SECTIONS1-NOT: .section
; LINUX-SECTIONS1-LABEL: # %bb.2:
; LINUX-SECTIONS1: .section .text.foo,"ax",@progbits,unique,1
; LINUX-SECTIONS1-LABEL: a.BB.foo:
; LINUX-SECTIONS1-LABEL: foo.1:
; LINUX-SECTIONS1-LABEL: .Ltmp0:
; LINUX-SECTIONS1-NEXT: .size a.BB.foo, .Ltmp0-a.BB.foo
; LINUX-SECTIONS1-NEXT: .size foo.1, .Ltmp0-foo.1
; LINUX-SECTIONS1-NOT: .section
; LINUX-SECTIONS1: .section .text.unlikely.foo,"ax",@progbits
; LINUX-SECTIONS1-LABEL: raa.BB.foo:
; LINUX-SECTIONS1-LABEL: foo.cold:
; LINUX-SECTIONS1: .section .text.foo,"ax",@progbits
; LINUX-SECTIONS1-LABEL: .Lfunc_end0:
; LINUX-SECTIONS1-NEXT: .size foo, .Lfunc_end0-foo
@ -60,12 +60,11 @@ declare i32 @baz() #1
; LINUX-SECTIONS2-NOT: .section
; LINUX-SECTIONS2-LABEL: # %bb.2:
; LINUX-SECTIONS2: .section .text.foo,"ax",@progbits,unique,1
; LINUX-SECTIONS2-NEXT: a.BB.foo:
; LINUX-SECTIONS2-NEXT: foo.0:
; LINUX-SECTIONS2-NOT: .section
; LINUX-SECTIONS2-LABEL: .LBB0_3:
; LINUX-SECTIONS2-LABEL: .Ltmp0:
; LINUX-SECTIONS2-NEXT: .size a.BB.foo, .Ltmp0-a.BB.foo
; LINUX-SECTIONS2-NEXT: .size foo.0, .Ltmp0-foo.0
; LINUX-SECTIONS2: .section .text.foo,"ax",@progbits
; LINUX-SECTIONS2-LABEL: .Lfunc_end0:
; LINUX-SECTIONS2-NEXT: .size foo, .Lfunc_end0-foo

View File

@ -2,10 +2,9 @@
; Basic block with id 1 and 2 must be in the cold section.
; RUN: echo '!_Z3bazb' > %t
; RUN: echo '!!0' >> %t
; RUN: cat %t
; RUN: llc < %s -mtriple=x86_64-pc-linux -function-sections -basicblock-sections=%t -unique-bb-section-names | FileCheck %s -check-prefix=LINUX-SECTIONS
define void @_Z3bazb(i1 zeroext) {
define void @_Z3bazb(i1 zeroext) nounwind {
%2 = alloca i8, align 1
%3 = zext i1 %0 to i8
store i8 %3, i8* %2, align 1
@ -32,10 +31,10 @@ declare i32 @_Z3foov() #1
; LINUX-SECTIONS: .section .text._Z3bazb,"ax",@progbits
; LINUX-SECTIONS: _Z3bazb:
; Check that the basic block with id 1 doesn't get a section.
; LINUX-SECTIONS-NOT: .section .text._Z3bazb.r.BB._Z3bazb,"ax",@progbits,unique
; LINUX-SECTIONS-NOT: .section .text._Z3bazb._Z3bazb.1,"ax",@progbits,unique
; Check that a single cold section is started here and id 1 and 2 blocks are placed here.
; LINUX-SECTIONS: .section .text.unlikely._Z3bazb,"ax",@progbits
; LINUX-SECTIONS: r.BB._Z3bazb:
; LINUX-SECTIONS-NOT: .section .text._Z3bazb.rr.BB._Z3bazb,"ax",@progbits,unique
; LINUX-SECTIONS: _Z3bazb.cold:
; LINUX-SECTIONS-NOT: .section .text._Z3bazb._Z3bazb.2,"ax",@progbits,unique
; LINUX-SECTIONS: .LBB0_2:
; LINUX-SECTIONS: .size _Z3bazb, .Lfunc_end{{[0-9]}}-_Z3bazb

View File

@ -29,10 +29,10 @@ declare i32 @_Z3foov() #1
; LINUX-SECTIONS: .section .text._Z3bazb,"ax",@progbits
; LINUX-SECTIONS: _Z3bazb:
; LINUX-SECTIONS: jmp a.BB._Z3bazb
; LINUX-SECTIONS: .section .text._Z3bazb.a.BB._Z3bazb,"ax",@progbits
; LINUX-SECTIONS: a.BB._Z3bazb:
; LINUX-SECTIONS: jmp aa.BB._Z3bazb
; LINUX-SECTIONS: .section .text._Z3bazb.aa.BB._Z3bazb,"ax",@progbits
; LINUX-SECTIONS: aa.BB._Z3bazb:
; LINUX-SECTIONS: jmp raa.BB._Z3bazb
; LINUX-SECTIONS: jmp _Z3bazb.1
; LINUX-SECTIONS: .section .text._Z3bazb._Z3bazb.1,"ax",@progbits
; LINUX-SECTIONS: _Z3bazb.1:
; LINUX-SECTIONS: jmp _Z3bazb.2
; LINUX-SECTIONS: .section .text._Z3bazb._Z3bazb.2,"ax",@progbits
; LINUX-SECTIONS: _Z3bazb.2:
; LINUX-SECTIONS: jmp _Z3bazb.3

View File

@ -80,5 +80,6 @@ declare void @__cxa_end_catch()
;LINUX-SECTIONS: .section .text._Z3foob,"ax",@progbits
;LINUX-SECTIONS: _Z3foob:
;LINUX-SECTIONS: .section .text._Z3foob.laara.BB._Z3foob,"ax",@progbits
;LINUX-SECTIONS: l{{[a|r]*}}.BB._Z3foob:
;LINUX-SECTIONS: .section .text._Z3foob._Z3foob.{{[0-9]+}},"ax",@progbits
;LINUX-SECTIONS-LABEL: _Z3foob.{{[0-9]+}}:
;LINUX-SECTIONS: calll __cxa_begin_catch

View File

@ -2,7 +2,7 @@
; RUN: echo '!_Z3foob' > %t
; RUN: llc < %s -mtriple=x86_64-pc-linux -function-sections -basicblock-sections=%t -unique-bb-section-names | FileCheck %s -check-prefix=LINUX-SECTIONS
define i32 @_Z3foob(i1 zeroext %0) #0 {
define i32 @_Z3foob(i1 zeroext %0) nounwind {
%2 = alloca i32, align 4
%3 = alloca i8, align 1
%4 = zext i1 %0 to i8
@ -31,7 +31,7 @@ define i32 @_Z3foob(i1 zeroext %0) #0 {
declare i32 @_Z3barv() #1
declare i32 @_Z3bazv() #1
define i32 @_Z3zipb(i1 zeroext %0) #0 {
define i32 @_Z3zipb(i1 zeroext %0) nounwind {
%2 = alloca i32, align 4
%3 = alloca i8, align 1
%4 = zext i1 %0 to i8
@ -59,18 +59,14 @@ define i32 @_Z3zipb(i1 zeroext %0) #0 {
; LINUX-SECTIONS: .section .text._Z3foob,"ax",@progbits
; LINUX-SECTIONS: _Z3foob:
; LINUX-SECTIONS: .section .text._Z3foob.a.BB._Z3foob,"ax",@progbits
; LINUX-SECTIONS: a.BB._Z3foob:
; LINUX-SECTIONS: .section .text._Z3foob.aa.BB._Z3foob,"ax",@progbits
; LINUX-SECTIONS: aa.BB._Z3foob:
; LINUX-SECTIONS: .section .text._Z3foob.raa.BB._Z3foob,"ax",@progbits
; LINUX-SECTIONS: raa.BB._Z3foob:
; LINUX-SECTIONS: .section .text._Z3foob._Z3foob.1,"ax",@progbits
; LINUX-SECTIONS: _Z3foob.1:
; LINUX-SECTIONS: .section .text._Z3foob._Z3foob.2,"ax",@progbits
; LINUX-SECTIONS: _Z3foob.2:
; LINUX-SECTIONS: .section .text._Z3foob._Z3foob.3,"ax",@progbits
; LINUX-SECTIONS: _Z3foob.3:
; LINUX-SECTIONS: .section .text._Z3zipb,"ax",@progbits
; LINUX-SECTIONS: _Z3zipb:
; LINUX-SECTIONS-NOT: .section .text._Z3zipb.a.BB._Z3zipb,"ax",@progbits
; LINUX-SECTIONS-NOT: a.BB._Z3zipb:
; LINUX-SECTIONS-NOT: .section .text._Z3zipb.aa.BB._Z3zipb,"ax",@progbits
; LINUX-SECTIONS-NOT: aa.BB._Z3zipb:
; LINUX-SECTIONS-NOT: .section .text._Z3zipb.raa.BB._Z3zipb,"ax",@progbits
; LINUX-SECTIONS-NOT: raa.BB._Z3zipb:
; LINUX-SECTIONS-NOT: .section .text._Z3zipb._Z3zipb.{{[0-9]+}},"ax",@progbits
; LINUX-SECTIONS-NOT: _Z3zipb.{{[0-9]+}}:

View File

@ -4,7 +4,7 @@
; RUN: echo '!!2' >> %t
; RUN: llc < %s -mtriple=x86_64-pc-linux -function-sections -basicblock-sections=%t -unique-bb-section-names | FileCheck %s -check-prefix=LINUX-SECTIONS
define void @_Z3bazb(i1 zeroext) {
define void @_Z3bazb(i1 zeroext) nounwind {
%2 = alloca i8, align 1
%3 = zext i1 %0 to i8
store i8 %3, i8* %2, align 1
@ -28,12 +28,16 @@ declare i32 @_Z3barv() #1
declare i32 @_Z3foov() #1
; Check that the correct block is found using the call insts for foo and bar.
;
; LINUX-SECTIONS: .section .text._Z3bazb,"ax",@progbits
; LINUX-SECTIONS: _Z3bazb:
; Check that the basic block with id 1 doesn't get a section.
; LINUX-SECTIONS-NOT: .section .text._Z3bazb.r.BB._Z3bazb,"ax",@progbits
; LINUX-SECTIONS: # %bb.1:
; LINUX-SECTIONS: .section .text._Z3bazb.rr.BB._Z3bazb,"ax",@progbits
; LINUX-SECTIONS: rr.BB._Z3bazb:
; LINUX-SECTIONS-NOT: .section .text._Z3bazb._Z3bazb.{{[0-9]+}},"ax",@progbits
; LINUX-SECTIONS-LABEL: # %bb.1:
; LINUX-SECTIONS-NEXT: callq _Z3barv
; LINUX-SECTIONS: .section .text._Z3bazb._Z3bazb.{{[0-9]+}},"ax",@progbits
; LINUX-SECTIONS-LABEL: _Z3bazb.{{[0-9]+}}:
; LINUX-SECTIONS-NEXT: callq _Z3foov
; LINUX-SECTIONS: .Ltmp0:
; LINUX-SECTIONS-NEXT: .size rr.BB._Z3bazb, .Ltmp0-rr.BB._Z3bazb
; LINUX-SECTIONS-NEXT: .size _Z3bazb.{{[0-9]+}}, .Ltmp0-_Z3bazb.{{[0-9]+}}

View File

@ -124,8 +124,8 @@ body: |
# CHECK: _Z3foob:
# CHECK: .section .text,"ax",@progbits,unique
# CHECK: a.BB._Z3foob:
# CHECK: _Z3foob.1:
# CHECK: .section .text,"ax",@progbits,unique
# CHECK: aa.BB._Z3foob:
# CHECK: _Z3foob.2:
# CHECK: .section .text,"ax",@progbits,unique
# CHECK: aaa.BB._Z3foob:
# CHECK: _Z3foob.3:

View File

@ -1,7 +1,7 @@
; RUN: llc < %s -mtriple=x86_64-pc-linux -function-sections -basicblock-sections=all -unique-bb-section-names | FileCheck %s -check-prefix=LINUX-SECTIONS
; RUN: llc < %s -mtriple=i386-unknown-linux-gnu -function-sections -basicblock-sections=all -unique-bb-section-names | FileCheck %s -check-prefix=LINUX-SECTIONS
define void @_Z3bazb(i1 zeroext) {
define void @_Z3bazb(i1 zeroext) nounwind {
%2 = alloca i8, align 1
%3 = zext i1 %0 to i8
store i8 %3, i8* %2, align 1
@ -28,11 +28,11 @@ declare i32 @_Z3foov() #1
; LINUX-SECTIONS: .section .text._Z3bazb,"ax",@progbits
; LINUX-SECTIONS: _Z3bazb:
; LINUX-SECTIONS: .section .text._Z3bazb.r.BB._Z3bazb,"ax",@progbits
; LINUX-SECTIONS: r.BB._Z3bazb:
; LINUX-SECTIONS: .section .text._Z3bazb._Z3bazb.1,"ax",@progbits
; LINUX-SECTIONS: _Z3bazb.1:
; LINUX-SECTIONS: .Ltmp0:
; LINUX-SECTIONS-NEXT: .size r.BB._Z3bazb, .Ltmp0-r.BB._Z3bazb
; LINUX-SECTIONS: .section .text._Z3bazb.rr.BB._Z3bazb,"ax",@progbits
; LINUX-SECTIONS: rr.BB._Z3bazb:
; LINUX-SECTIONS-NEXT: .size _Z3bazb.1, .Ltmp0-_Z3bazb.1
; LINUX-SECTIONS: .section .text._Z3bazb._Z3bazb.2,"ax",@progbits
; LINUX-SECTIONS: _Z3bazb.2:
; LINUX-SECTIONS: .Ltmp1:
; LINUX-SECTIONS-NEXT: .size rr.BB._Z3bazb, .Ltmp1-rr.BB._Z3bazb
; LINUX-SECTIONS-NEXT: .size _Z3bazb.2, .Ltmp1-_Z3bazb.2