diff --git a/llvm/lib/CodeGen/MachineBasicBlock.cpp b/llvm/lib/CodeGen/MachineBasicBlock.cpp --- a/llvm/lib/CodeGen/MachineBasicBlock.cpp +++ b/llvm/lib/CodeGen/MachineBasicBlock.cpp @@ -62,30 +62,39 @@ 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(Prefix + Twine(".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("_") + Twine(getNumber())); } } return CachedMCSymbol; diff --git a/llvm/test/CodeGen/X86/basicblock-sections-clusters-branches.ll b/llvm/test/CodeGen/X86/basicblock-sections-clusters-branches.ll --- a/llvm/test/CodeGen/X86/basicblock-sections-clusters-branches.ll +++ b/llvm/test/CodeGen/X86/basicblock-sections-clusters-branches.ll @@ -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 @@ ; 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: diff --git a/llvm/test/CodeGen/X86/basicblock-sections-clusters-eh.ll b/llvm/test/CodeGen/X86/basicblock-sections-clusters-eh.ll --- a/llvm/test/CodeGen/X86/basicblock-sections-clusters-eh.ll +++ b/llvm/test/CodeGen/X86/basicblock-sections-clusters-eh.ll @@ -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 @@ ; 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 @@ ; 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 diff --git a/llvm/test/CodeGen/X86/basicblock-sections-clusters.ll b/llvm/test/CodeGen/X86/basicblock-sections-clusters.ll --- a/llvm/test/CodeGen/X86/basicblock-sections-clusters.ll +++ b/llvm/test/CodeGen/X86/basicblock-sections-clusters.ll @@ -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 @@ ; 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 @@ ; 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 - diff --git a/llvm/test/CodeGen/X86/basicblock-sections-cold.ll b/llvm/test/CodeGen/X86/basicblock-sections-cold.ll --- a/llvm/test/CodeGen/X86/basicblock-sections-cold.ll +++ b/llvm/test/CodeGen/X86/basicblock-sections-cold.ll @@ -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 @@ ; 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 diff --git a/llvm/test/CodeGen/X86/basicblock-sections-directjumps.ll b/llvm/test/CodeGen/X86/basicblock-sections-directjumps.ll --- a/llvm/test/CodeGen/X86/basicblock-sections-directjumps.ll +++ b/llvm/test/CodeGen/X86/basicblock-sections-directjumps.ll @@ -29,10 +29,10 @@ ; 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 diff --git a/llvm/test/CodeGen/X86/basicblock-sections-eh.ll b/llvm/test/CodeGen/X86/basicblock-sections-eh.ll --- a/llvm/test/CodeGen/X86/basicblock-sections-eh.ll +++ b/llvm/test/CodeGen/X86/basicblock-sections-eh.ll @@ -80,5 +80,6 @@ ;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 diff --git a/llvm/test/CodeGen/X86/basicblock-sections-list.ll b/llvm/test/CodeGen/X86/basicblock-sections-list.ll --- a/llvm/test/CodeGen/X86/basicblock-sections-list.ll +++ b/llvm/test/CodeGen/X86/basicblock-sections-list.ll @@ -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 @@ 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 @@ ; 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]+}}: diff --git a/llvm/test/CodeGen/X86/basicblock-sections-listbb.ll b/llvm/test/CodeGen/X86/basicblock-sections-listbb.ll --- a/llvm/test/CodeGen/X86/basicblock-sections-listbb.ll +++ b/llvm/test/CodeGen/X86/basicblock-sections-listbb.ll @@ -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 @_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]+}} diff --git a/llvm/test/CodeGen/X86/basicblock-sections-mir-parse.mir b/llvm/test/CodeGen/X86/basicblock-sections-mir-parse.mir --- a/llvm/test/CodeGen/X86/basicblock-sections-mir-parse.mir +++ b/llvm/test/CodeGen/X86/basicblock-sections-mir-parse.mir @@ -124,8 +124,8 @@ # 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: diff --git a/llvm/test/CodeGen/X86/basicblock-sections.ll b/llvm/test/CodeGen/X86/basicblock-sections.ll --- a/llvm/test/CodeGen/X86/basicblock-sections.ll +++ b/llvm/test/CodeGen/X86/basicblock-sections.ll @@ -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 @@ ; 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