summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2015-02-20 23:28:28 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2015-02-20 23:28:28 +0000
commit9075f7706491af3532389b482c6d048b44e867f3 (patch)
tree728234b38c4faba4312637310162dc36e0439847
parent0068408001bcf21ac629808cd6b3a04a0a21a192 (diff)
downloadbcm5719-llvm-9075f7706491af3532389b482c6d048b44e867f3.tar.gz
bcm5719-llvm-9075f7706491af3532389b482c6d048b44e867f3.zip
Use short names for jumptable sections.
Also refactor code to remove some duplication. llvm-svn: 230087
-rw-r--r--llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp54
-rw-r--r--llvm/test/CodeGen/X86/global-sections-comdat.ll7
2 files changed, 32 insertions, 29 deletions
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index 0ef10bfa440..49d0b091e31 100644
--- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -249,6 +249,27 @@ static StringRef getSectionPrefixForGlobal(SectionKind Kind) {
return ".data.rel.ro";
}
+static const MCSection *
+getUniqueELFSection(MCContext &Ctx, const GlobalValue &GV, SectionKind Kind,
+ Mangler &Mang, const TargetMachine &TM, unsigned Flags) {
+ StringRef Prefix = getSectionPrefixForGlobal(Kind);
+
+ SmallString<128> Name(Prefix);
+ bool UniqueSectionNames = TM.getUniqueSectionNames();
+ if (UniqueSectionNames) {
+ Name.push_back('.');
+ TM.getNameWithPrefix(Name, &GV, Mang, true);
+ }
+ StringRef Group = "";
+ if (const Comdat *C = getELFComdat(&GV)) {
+ Flags |= ELF::SHF_GROUP;
+ Group = C->getName();
+ }
+
+ return Ctx.getELFSection(Name, getELFSectionType(Name, Kind), Flags, 0, Group,
+ !UniqueSectionNames);
+}
+
const MCSection *TargetLoweringObjectFileELF::
SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
Mangler &Mang, const TargetMachine &TM) const {
@@ -264,24 +285,8 @@ SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
EmitUniquedSection = TM.getDataSections();
}
- if (EmitUniquedSection || GV->hasComdat()) {
- StringRef Prefix = getSectionPrefixForGlobal(Kind);
-
- SmallString<128> Name(Prefix);
- bool UniqueSectionNames = TM.getUniqueSectionNames();
- if (UniqueSectionNames) {
- Name.push_back('.');
- TM.getNameWithPrefix(Name, GV, Mang, true);
- }
- StringRef Group = "";
- if (const Comdat *C = getELFComdat(GV)) {
- Flags |= ELF::SHF_GROUP;
- Group = C->getName();
- }
-
- return getContext().getELFSection(Name, getELFSectionType(Name, Kind),
- Flags, 0, Group, !UniqueSectionNames);
- }
+ if (EmitUniquedSection || GV->hasComdat())
+ return getUniqueELFSection(getContext(), *GV, Kind, Mang, TM, Flags);
if (Kind.isText()) return TextSection;
@@ -346,17 +351,8 @@ const MCSection *TargetLoweringObjectFileELF::getSectionForJumpTable(
if (!EmitUniqueSection)
return ReadOnlySection;
- SmallString<128> Name(".rodata.");
- TM.getNameWithPrefix(Name, &F, Mang, true);
-
- unsigned Flags = ELF::SHF_ALLOC;
- StringRef Group = "";
- if (C) {
- Flags |= ELF::SHF_GROUP;
- Group = C->getName();
- }
-
- return getContext().getELFSection(Name, ELF::SHT_PROGBITS, Flags, 0, Group);
+ return getUniqueELFSection(getContext(), F, SectionKind::getReadOnly(), Mang,
+ TM, ELF::SHF_ALLOC);
}
bool TargetLoweringObjectFileELF::shouldPutJumpTableInFunctionSection(
diff --git a/llvm/test/CodeGen/X86/global-sections-comdat.ll b/llvm/test/CodeGen/X86/global-sections-comdat.ll
index 0557d9a0ee1..7b4d74c2a33 100644
--- a/llvm/test/CodeGen/X86/global-sections-comdat.ll
+++ b/llvm/test/CodeGen/X86/global-sections-comdat.ll
@@ -1,5 +1,6 @@
; RUN: llc < %s -mtriple=i386-unknown-linux | FileCheck %s -check-prefix=LINUX
; RUN: llc < %s -mtriple=i386-unknown-linux -data-sections -function-sections | FileCheck %s -check-prefix=LINUX-SECTIONS
+; RUN: llc < %s -mtriple=i386-unknown-linux -data-sections -function-sections -unique-section-names=false | FileCheck %s -check-prefix=LINUX-SECTIONS-SHORT
$F1 = comdat any
define void @F1(i32 %y) comdat {
@@ -32,8 +33,14 @@ bb5:
; LINUX-SECTIONS-NEXT: .cfi_endproc
; LINUX-SECTIONS-NEXT: .section .rodata.F1,"aG",@progbits,F1,comdat
+; LINUX-SECTIONS-SHORT: .section .text,"axG",@progbits,F1,comdat
+; LINUX-SECTIONS-SHORT: .size F1,
+; LINUX-SECTIONS-SHORT-NEXT: .cfi_endproc
+; LINUX-SECTIONS-SHORT-NEXT: .section .rodata,"aG",@progbits,F1,comdat
+
$G16 = comdat any
@G16 = unnamed_addr constant i32 42, comdat
; LINUX: .section .rodata.G16,"aG",@progbits,G16,comdat
; LINUX-SECTIONS: .section .rodata.G16,"aG",@progbits,G16,comdat
+; LINUX-SECTIONS-SHORT: .section .rodata,"aG",@progbits,G16,comdat
OpenPOWER on IntegriCloud