Rearrange all the SectionKinds and structure them into a hierarchical
group instead of a bunch of random unrelated ideas. Provide predicates
to categorize a SectionKind into a group, and use them instead of
getKind() throughout the code.
This also renames a ton of SectionKinds to be more consistent and
evocative, and adds a huge number of comments on the enums so that
I will hopefully be able to remember how this stuff works long from
now.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77129 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Target/DarwinTargetAsmInfo.cpp b/lib/Target/DarwinTargetAsmInfo.cpp
index 1356f67..7321b18 100644
--- a/lib/Target/DarwinTargetAsmInfo.cpp
+++ b/lib/Target/DarwinTargetAsmInfo.cpp
@@ -127,12 +127,12 @@
const Section*
DarwinTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV,
SectionKind Kind) const {
- assert(!Kind.isTLS() && "Darwin doesn't support TLS");
+ assert(!Kind.isThreadLocal() && "Darwin doesn't support TLS");
// FIXME: Use sectionflags:linkonce instead of isWeakForLinker() here.
bool isWeak = GV->isWeakForLinker();
- if (Kind.isCode())
+ if (Kind.isText())
return isWeak ? TextCoalSection : TextSection;
// If this is weak/linkonce, put this in a coalescable section, either in text
@@ -144,24 +144,24 @@
}
// FIXME: Alignment check should be handled by section classifier.
- if (Kind.isMergableString())
+ if (Kind.isMergableCString())
return MergeableStringSection(cast<GlobalVariable>(GV));
- if (Kind.isMergableConstant()) {
+ if (Kind.isMergableConst()) {
const Type *Ty = cast<GlobalVariable>(GV)->getInitializer()->getType();
const TargetData *TD = TM.getTargetData();
return getSectionForMergableConstant(TD->getTypeAllocSize(Ty), 0);
}
-
- // If this is marked const, put it into a const section. But if the dynamic
- // linker needs to write to it, put it in the data segment.
- if (Kind.isReadOnlyWithDynamicInit())
- return ConstDataSection;
// FIXME: ROData -> const in -static mode that is relocatable but they happen
// by the static linker. Why not mergable?
if (Kind.isReadOnly())
return getReadOnlySection();
+
+ // If this is marked const, put it into a const section. But if the dynamic
+ // linker needs to write to it, put it in the data segment.
+ if (Kind.isReadOnlyWithRel())
+ return ConstDataSection;
// Otherwise, just drop the variable in the normal data section.
return DataSection;
diff --git a/lib/Target/ELFTargetAsmInfo.cpp b/lib/Target/ELFTargetAsmInfo.cpp
index 880dfbc..c401109 100644
--- a/lib/Target/ELFTargetAsmInfo.cpp
+++ b/lib/Target/ELFTargetAsmInfo.cpp
@@ -49,28 +49,30 @@
const Section*
ELFTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV,
SectionKind Kind) const {
- switch (Kind.getKind()) {
- default: llvm_unreachable("Unknown section kind");
- case SectionKind::Text: return TextSection;
- case SectionKind::BSS: return getBSSSection_();
- case SectionKind::Data: return DataSection;
- case SectionKind::DataRel: return DataRelSection;
- case SectionKind::DataRelLocal: return DataRelLocalSection;
- case SectionKind::DataRelRO: return DataRelROSection;
- case SectionKind::DataRelROLocal: return DataRelROLocalSection;
- case SectionKind::ROData: return getReadOnlySection();
- case SectionKind::RODataMergeStr:
+ if (Kind.isText()) return TextSection;
+ if (Kind.isMergableCString())
return MergeableStringSection(cast<GlobalVariable>(GV));
- case SectionKind::RODataMergeConst: {
+ if (Kind.isMergableConst()) {
const Type *Ty = cast<GlobalVariable>(GV)->getInitializer()->getType();
const TargetData *TD = TM.getTargetData();
return getSectionForMergableConstant(TD->getTypeAllocSize(Ty), 0);
}
- case SectionKind::ThreadData:
- return TLSDataSection;
- case SectionKind::ThreadBSS:
- return TLSBSSSection;
- }
+ if (Kind.isReadOnly()) return getReadOnlySection();
+
+
+ if (Kind.isThreadData()) return TLSDataSection;
+ if (Kind.isThreadBSS()) return TLSBSSSection;
+
+ if (Kind.isBSS()) return getBSSSection_();
+
+
+ if (Kind.isDataNoRel()) return DataSection;
+ if (Kind.isDataRelLocal()) return DataRelLocalSection;
+ if (Kind.isDataRel()) return DataRelSection;
+ if (Kind.isReadOnlyWithRelLocal()) return DataRelROLocalSection;
+
+ assert(Kind.isReadOnlyWithRel() && "Unknown section kind");
+ return DataRelROSection;
}
/// getSectionForMergableConstant - Given a mergable constant with the
@@ -129,21 +131,20 @@
const char *
ELFTargetAsmInfo::getSectionPrefixForUniqueGlobal(SectionKind Kind) const{
- switch (Kind.getKind()) {
- default: llvm_unreachable("Unknown section kind");
- case SectionKind::Text: return ".gnu.linkonce.t.";
- case SectionKind::Data: return ".gnu.linkonce.d.";
- case SectionKind::DataRel: return ".gnu.linkonce.d.rel.";
- case SectionKind::DataRelLocal: return ".gnu.linkonce.d.rel.local.";
- case SectionKind::DataRelRO: return ".gnu.linkonce.d.rel.ro.";
- case SectionKind::DataRelROLocal: return ".gnu.linkonce.d.rel.ro.local.";
- case SectionKind::BSS: return ".gnu.linkonce.b.";
- case SectionKind::ROData:
- case SectionKind::RODataMergeConst:
- case SectionKind::RODataMergeStr: return ".gnu.linkonce.r.";
- case SectionKind::ThreadData: return ".gnu.linkonce.td.";
- case SectionKind::ThreadBSS: return ".gnu.linkonce.tb.";
- }
+ if (Kind.isText()) return ".gnu.linkonce.t.";
+ if (Kind.isReadOnly()) return ".gnu.linkonce.r.";
+
+ if (Kind.isThreadData()) return ".gnu.linkonce.td.";
+ if (Kind.isThreadBSS()) return ".gnu.linkonce.tb.";
+
+ if (Kind.isBSS()) return ".gnu.linkonce.b.";
+ if (Kind.isDataNoRel()) return ".gnu.linkonce.d.";
+ if (Kind.isDataRelLocal()) return ".gnu.linkonce.d.rel.local.";
+ if (Kind.isDataRel()) return ".gnu.linkonce.d.rel.";
+ if (Kind.isReadOnlyWithRelLocal()) return ".gnu.linkonce.d.rel.ro.local.";
+
+ assert(Kind.isReadOnlyWithRel() && "Unknown section kind");
+ return ".gnu.linkonce.d.rel.ro.";
}
diff --git a/lib/Target/TargetAsmInfo.cpp b/lib/Target/TargetAsmInfo.cpp
index c3fb942..02e01be 100644
--- a/lib/Target/TargetAsmInfo.cpp
+++ b/lib/Target/TargetAsmInfo.cpp
@@ -204,11 +204,11 @@
unsigned Flags = SectionFlags::None;
if (GV->isWeakForLinker())
Flags |= SectionFlags::Linkonce;
- if (Kind.isBSS())
+ if (Kind.isBSS() || Kind.isThreadBSS())
Flags |= SectionFlags::BSS;
- if (Kind.isTLS())
+ if (Kind.isThreadLocal())
Flags |= SectionFlags::TLS;
- if (Kind.isCode())
+ if (Kind.isText())
Flags |= SectionFlags::Code;
if (Kind.isWritable())
Flags |= SectionFlags::Writable;
@@ -247,32 +247,32 @@
// If initializer is a null-terminated string, put it in a "cstring"
// section if the target has it.
if (isConstantString(C))
- return SectionKind::getRODataMergeStr();
+ return SectionKind::getMergableCString();
// Otherwise, just drop it into a mergable constant section.
- return SectionKind::getRODataMergeConst();
+ return SectionKind::getMergableConst();
case Constant::LocalRelocation:
// In static relocation model, the linker will resolve all addresses, so
// the relocation entries will actually be constants by the time the app
// starts up.
if (ReloModel == Reloc::Static)
- return SectionKind::getROData();
+ return SectionKind::getReadOnly();
// Otherwise, the dynamic linker needs to fix it up, put it in the
// writable data.rel.local section.
- return SectionKind::getDataRelROLocal();
+ return SectionKind::getReadOnlyWithRelLocal();
case Constant::GlobalRelocations:
// In static relocation model, the linker will resolve all addresses, so
// the relocation entries will actually be constants by the time the app
// starts up.
if (ReloModel == Reloc::Static)
- return SectionKind::getROData();
+ return SectionKind::getReadOnly();
// Otherwise, the dynamic linker needs to fix it up, put it in the
// writable data.rel section.
- return SectionKind::getDataRelRO();
+ return SectionKind::getReadOnlyWithRel();
}
}
@@ -282,11 +282,11 @@
// globals together onto fewer pages, improving the locality of the dynamic
// linker.
if (ReloModel == Reloc::Static)
- return SectionKind::getData();
+ return SectionKind::getDataNoRel();
switch (C->getRelocationInfo()) {
default: llvm_unreachable("unknown relocation info kind");
- case Constant::NoRelocation: return SectionKind::getData();
+ case Constant::NoRelocation: return SectionKind::getDataNoRel();
case Constant::LocalRelocation: return SectionKind::getDataRelLocal();
case Constant::GlobalRelocations: return SectionKind::getDataRel();
}
@@ -342,7 +342,9 @@
const Section*
TargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV,
SectionKind Kind) const {
- if (Kind.isCode())
+ assert(!Kind.isThreadLocal() && "Doesn't support TLS");
+
+ if (Kind.isText())
return getTextSection();
if (Kind.isBSS())
diff --git a/lib/Target/X86/X86TargetAsmInfo.cpp b/lib/Target/X86/X86TargetAsmInfo.cpp
index 39dfb00..9e7973a 100644
--- a/lib/Target/X86/X86TargetAsmInfo.cpp
+++ b/lib/Target/X86/X86TargetAsmInfo.cpp
@@ -267,7 +267,7 @@
const char *X86COFFTargetAsmInfo::
getSectionPrefixForUniqueGlobal(SectionKind Kind) const {
- if (Kind.isCode())
+ if (Kind.isText())
return ".text$linkonce";
if (Kind.isWritable())
return ".data$linkonce";