diff --git a/llvm/include/llvm/ProfileData/ProfileCommon.h b/llvm/include/llvm/ProfileData/ProfileCommon.h --- a/llvm/include/llvm/ProfileData/ProfileCommon.h +++ b/llvm/include/llvm/ProfileData/ProfileCommon.h @@ -33,8 +33,8 @@ } // end namespace sampleprof -inline const char *getHotSectionPrefix() { return ".hot"; } -inline const char *getUnlikelySectionPrefix() { return ".unlikely"; } +inline const char *getHotSectionPrefix() { return "hot"; } +inline const char *getUnlikelySectionPrefix() { return "unlikely"; } class ProfileSummaryBuilder { private: diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp --- a/llvm/lib/CodeGen/CodeGenPrepare.cpp +++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp @@ -473,12 +473,12 @@ OptSize = F.hasOptSize(); if (ProfileGuidedSectionPrefix) { if (PSI->isFunctionHotInCallGraph(&F, *BFI)) - F.setSectionPrefix(".hot"); + F.setSectionPrefix("hot"); else if (PSI->isFunctionColdInCallGraph(&F, *BFI)) - F.setSectionPrefix(".unlikely"); + F.setSectionPrefix("unlikely"); else if (ProfileUnknownInSpecialSection && PSI->hasPartialSampleProfile() && PSI->isFunctionHotnessUnknown(F)) - F.setSectionPrefix(".unknown"); + F.setSectionPrefix("unknown"); } /// This optimization identifies DIV instructions that can be diff --git a/llvm/lib/CodeGen/MachineFunctionSplitter.cpp b/llvm/lib/CodeGen/MachineFunctionSplitter.cpp --- a/llvm/lib/CodeGen/MachineFunctionSplitter.cpp +++ b/llvm/lib/CodeGen/MachineFunctionSplitter.cpp @@ -107,8 +107,8 @@ // or functions of unknown hotness. Lukewarm functions have no prefix. Optional SectionPrefix = MF.getFunction().getSectionPrefix(); if (SectionPrefix.hasValue() && - (SectionPrefix.getValue().equals(".unlikely") || - SectionPrefix.getValue().equals(".unknown"))) { + (SectionPrefix.getValue().equals("unlikely") || + SectionPrefix.getValue().equals("unknown"))) { return false; } diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp --- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -621,7 +621,7 @@ bool HasPrefix = false; if (const auto *F = dyn_cast(GO)) { if (Optional Prefix = F->getSectionPrefix()) { - Name += *Prefix; + raw_svector_ostream(Name) << '.' << *Prefix; HasPrefix = true; } } @@ -1573,6 +1573,10 @@ MCSymbol *Sym = TM.getSymbol(ComdatGV); StringRef COMDATSymName = Sym->getName(); + if (const auto *F = dyn_cast(GO)) + if (Optional Prefix = F->getSectionPrefix()) + raw_svector_ostream(Name) << '$' << *Prefix; + // Append "$symbol" to the section name *before* IR-level mangling is // applied when targetting mingw. This is what GCC does, and the ld.bfd // COFF linker will not properly handle comdats otherwise. @@ -2020,7 +2024,7 @@ if (const auto *F = dyn_cast(GO)) { const auto &OptionalPrefix = F->getSectionPrefix(); if (OptionalPrefix) - Name += *OptionalPrefix; + raw_svector_ostream(Name) << '.' << *OptionalPrefix; } if (EmitUniqueSection && UniqueSectionNames) { diff --git a/llvm/test/CodeGen/X86/machine-function-splitter.ll b/llvm/test/CodeGen/X86/machine-function-splitter.ll --- a/llvm/test/CodeGen/X86/machine-function-splitter.ll +++ b/llvm/test/CodeGen/X86/machine-function-splitter.ll @@ -207,8 +207,8 @@ !12 = !{i32 999900, i64 100, i32 1} !13 = !{i32 999999, i64 1, i32 2} !14 = !{!"function_entry_count", i64 7000} -!15 = !{!"function_section_prefix", !".hot"} -!16 = !{!"function_section_prefix", !".unlikely"} +!15 = !{!"function_section_prefix", !"hot"} +!16 = !{!"function_section_prefix", !"unlikely"} !17 = !{!"branch_weights", i32 7000, i32 0} !18 = !{!"branch_weights", i32 3000, i32 4000} !19 = !{!"branch_weights", i32 1000, i32 6000} diff --git a/llvm/test/CodeGen/X86/text-section-prefix.ll b/llvm/test/CodeGen/X86/text-section-prefix.ll new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/X86/text-section-prefix.ll @@ -0,0 +1,24 @@ +; RUN: llc -mtriple x86_64-linux-gnu -function-sections %s -o - | FileCheck %s --check-prefix=ELF +; RUN: llc -mtriple x86_64-linux-gnu -unique-section-names=0 -function-sections %s -o - | FileCheck %s --check-prefix=ELF-NOUNIQ +; RUN: llc -mtriple x86_64-windows-msvc -function-sections %s -o - | FileCheck %s --check-prefix=COFF +; RUN: llc -mtriple x86_64-windows-mingw64 -function-sections %s -o - | FileCheck %s --check-prefix=COFF + +define void @foo1(i1 zeroext %0) nounwind !section_prefix !0 { +;; CHECK hot section name +; ELF: .section .text.hot.foo1,"ax",@progbits +; ELF-NOUNIQ: .section .text.hot.,"ax",@progbits,unique,1 +; COFF: .section .text$hot,"xr",one_only,foo1 + ret void +} + +define void @foo2(i1 zeroext %0) nounwind !section_prefix !1 { +;; CHECK unlikely section name +; ELF: .section .text.unlikely.foo2,"ax",@progbits +; ELF-NOUNIQ: .section .text.unlikely.,"ax",@progbits,unique,2 +; COFF: .section .text$unlikely,"xr",one_only,foo2 + ret void +} + +!0 = !{!"function_section_prefix", !"hot"} +!1 = !{!"function_section_prefix", !"unlikely"} + diff --git a/llvm/test/Transforms/CodeGenPrepare/X86/section-samplepgo.ll b/llvm/test/Transforms/CodeGenPrepare/X86/section-samplepgo.ll --- a/llvm/test/Transforms/CodeGenPrepare/X86/section-samplepgo.ll +++ b/llvm/test/Transforms/CodeGenPrepare/X86/section-samplepgo.ll @@ -34,8 +34,8 @@ ret void } -; CHECK: ![[HOT_ID]] = !{!"function_section_prefix", !".hot"} -; CHECK: ![[COLD_ID]] = !{!"function_section_prefix", !".unlikely"} +; CHECK: ![[HOT_ID]] = !{!"function_section_prefix", !"hot"} +; CHECK: ![[COLD_ID]] = !{!"function_section_prefix", !"unlikely"} !llvm.module.flags = !{!1} !1 = !{i32 1, !"ProfileSummary", !2} !2 = !{!3, !4, !5, !6, !7, !8, !9, !10} diff --git a/llvm/test/Transforms/CodeGenPrepare/X86/section.ll b/llvm/test/Transforms/CodeGenPrepare/X86/section.ll --- a/llvm/test/Transforms/CodeGenPrepare/X86/section.ll +++ b/llvm/test/Transforms/CodeGenPrepare/X86/section.ll @@ -66,8 +66,8 @@ ret void } -; CHECK: ![[HOT_ID]] = !{!"function_section_prefix", !".hot"} -; CHECK: ![[COLD_ID]] = !{!"function_section_prefix", !".unlikely"} +; CHECK: ![[HOT_ID]] = !{!"function_section_prefix", !"hot"} +; CHECK: ![[COLD_ID]] = !{!"function_section_prefix", !"unlikely"} !llvm.module.flags = !{!1} !1 = !{i32 1, !"ProfileSummary", !2} !2 = !{!3, !4, !5, !6, !7, !8, !9, !10} diff --git a/llvm/test/Transforms/HotColdSplit/coldentrycount.ll b/llvm/test/Transforms/HotColdSplit/coldentrycount.ll --- a/llvm/test/Transforms/HotColdSplit/coldentrycount.ll +++ b/llvm/test/Transforms/HotColdSplit/coldentrycount.ll @@ -27,9 +27,9 @@ ; CHECK: define {{.*}} @fun.cold.1{{.*}} ![[PROF:[0-9]+]] {{.*}}section_prefix ![[UNLIKELY:[0-9]+]] ; CHECK: ![[HOTPROF]] = !{!"function_entry_count", i64 100} -; CHECK: ![[LIKELY]] = !{!"function_section_prefix", !".hot"} +; CHECK: ![[LIKELY]] = !{!"function_section_prefix", !"hot"} ; CHECK: ![[PROF]] = !{!"function_entry_count", i64 0} -; CHECK: ![[UNLIKELY]] = !{!"function_section_prefix", !".unlikely"} +; CHECK: ![[UNLIKELY]] = !{!"function_section_prefix", !"unlikely"} !llvm.module.flags = !{!0} !0 = !{i32 1, !"ProfileSummary", !1} @@ -47,6 +47,6 @@ !12 = !{i32 999000, i64 100, i32 1} !13 = !{i32 999999, i64 1, i32 2} !14 = !{!"function_entry_count", i64 100} -!15 = !{!"function_section_prefix", !".hot"} +!15 = !{!"function_section_prefix", !"hot"} !16 = !{!"function_entry_count", i64 0} -!17 = !{!"function_section_prefix", !".unlikely"} +!17 = !{!"function_section_prefix", !"unlikely"} diff --git a/llvm/test/Transforms/SampleProfile/section-accurate-samplepgo.ll b/llvm/test/Transforms/SampleProfile/section-accurate-samplepgo.ll --- a/llvm/test/Transforms/SampleProfile/section-accurate-samplepgo.ll +++ b/llvm/test/Transforms/SampleProfile/section-accurate-samplepgo.ll @@ -36,11 +36,11 @@ ; CHECK: ![[NOPROFILE_ID]] = !{!"function_entry_count", i64 -1} ; CHECK: ![[ZERO_ID]] = !{!"function_entry_count", i64 0} -; CHECK: ![[COLD_ID]] = !{!"function_section_prefix", !".unlikely"} +; CHECK: ![[COLD_ID]] = !{!"function_section_prefix", !"unlikely"} ; UNKNOWN: ![[NOPROFILE_ID]] = !{!"function_entry_count", i64 -1} -; UNKNOWN: ![[UNKNOWN_ID]] = !{!"function_section_prefix", !".unknown"} +; UNKNOWN: ![[UNKNOWN_ID]] = !{!"function_section_prefix", !"unknown"} ; ACCURATE: ![[ZERO_ID]] = !{!"function_entry_count", i64 0} -; ACCURATE: ![[COLD_ID]] = !{!"function_section_prefix", !".unlikely"} +; ACCURATE: ![[COLD_ID]] = !{!"function_section_prefix", !"unlikely"} !llvm.module.flags = !{!1} !1 = !{i32 1, !"ProfileSummary", !2} !2 = !{!3, !4, !5, !6, !7, !8, !9, !10}