(re)introduce new simpler apis for creation sectionkinds.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77834 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2009-08-01 23:57:16 +00:00
parent 83d77faf6e
commit 2798119ab4
4 changed files with 83 additions and 73 deletions

View File

@ -117,7 +117,6 @@ public:
protected: protected:
Kind K : 8; Kind K : 8;
public: public:
bool isMetadata() const { return K == Metadata; } bool isMetadata() const { return K == Metadata; }
@ -177,6 +176,25 @@ public:
Res.K = K; Res.K = K;
return Res; return Res;
} }
static SectionKind getMetadata() { return get(Metadata); }
static SectionKind getText() { return get(Text); }
static SectionKind getReadOnly() { return get(ReadOnly); }
static SectionKind getMergeableCString() { return get(MergeableCString); }
static SectionKind getMergeableConst() { return get(MergeableConst); }
static SectionKind getMergeableConst4() { return get(MergeableConst4); }
static SectionKind getMergeableConst8() { return get(MergeableConst8); }
static SectionKind getMergeableConst16() { return get(MergeableConst16); }
static SectionKind getThreadBSS() { return get(ThreadBSS); }
static SectionKind getThreadData() { return get(ThreadData); }
static SectionKind getBSS() { return get(BSS); }
static SectionKind getDataRel() { return get(DataRel); }
static SectionKind getDataRelLocal() { return get(DataRelLocal); }
static SectionKind getDataNoRel() { return get(DataNoRel); }
static SectionKind getReadOnlyWithRel() { return get(ReadOnlyWithRel); }
static SectionKind getReadOnlyWithRelLocal(){
return get(ReadOnlyWithRelLocal);
}
}; };
} // end namespace llvm } // end namespace llvm

View File

@ -336,16 +336,16 @@ void AsmPrinter::EmitConstantPool(MachineConstantPool *MCP) {
SectionKind Kind; SectionKind Kind;
switch (CPE.getRelocationInfo()) { switch (CPE.getRelocationInfo()) {
default: llvm_unreachable("Unknown section kind"); default: llvm_unreachable("Unknown section kind");
case 2: Kind = SectionKind::get(SectionKind::ReadOnlyWithRel); break; case 2: Kind = SectionKind::getReadOnlyWithRel(); break;
case 1: case 1:
Kind = SectionKind::get(SectionKind::ReadOnlyWithRelLocal); Kind = SectionKind::getReadOnlyWithRelLocal();
break; break;
case 0: case 0:
switch (TM.getTargetData()->getTypeAllocSize(CPE.getType())) { switch (TM.getTargetData()->getTypeAllocSize(CPE.getType())) {
case 4: Kind = SectionKind::get(SectionKind::MergeableConst4); break; case 4: Kind = SectionKind::getMergeableConst4(); break;
case 8: Kind = SectionKind::get(SectionKind::MergeableConst8); break; case 8: Kind = SectionKind::getMergeableConst8(); break;
case 16: Kind = SectionKind::get(SectionKind::MergeableConst16);break; case 16: Kind = SectionKind::getMergeableConst16();break;
default: Kind = SectionKind::get(SectionKind::MergeableConst); break; default: Kind = SectionKind::getMergeableConst(); break;
} }
} }
@ -430,8 +430,7 @@ void AsmPrinter::EmitJumpTableInfo(MachineJumpTableInfo *MJTI,
} else { } else {
// Otherwise, drop it in the readonly section. // Otherwise, drop it in the readonly section.
const MCSection *ReadOnlySection = const MCSection *ReadOnlySection =
getObjFileLowering().getSectionForConstant( getObjFileLowering().getSectionForConstant(SectionKind::getReadOnly());
SectionKind::get(SectionKind::ReadOnly));
SwitchToSection(ReadOnlySection); SwitchToSection(ReadOnlySection);
JTInDiffSection = true; JTInDiffSection = true;
} }

View File

@ -182,8 +182,7 @@ ELFSection &ELFWriter::getJumpTableSection() {
const TargetLoweringObjectFile &TLOF = const TargetLoweringObjectFile &TLOF =
TM.getTargetLowering()->getObjFileLowering(); TM.getTargetLowering()->getObjFileLowering();
return getSection(TLOF.getSectionForConstant( return getSection(TLOF.getSectionForConstant(SectionKind::getReadOnly())
SectionKind::get(SectionKind::ReadOnly))
->getName(), ->getName(),
ELFSection::SHT_PROGBITS, ELFSection::SHT_PROGBITS,
ELFSection::SHF_ALLOC, Align); ELFSection::SHF_ALLOC, Align);
@ -194,16 +193,16 @@ ELFSection &ELFWriter::getConstantPoolSection(MachineConstantPoolEntry &CPE) {
SectionKind Kind; SectionKind Kind;
switch (CPE.getRelocationInfo()) { switch (CPE.getRelocationInfo()) {
default: llvm_unreachable("Unknown section kind"); default: llvm_unreachable("Unknown section kind");
case 2: Kind = SectionKind::get(SectionKind::ReadOnlyWithRel); break; case 2: Kind = SectionKind::getReadOnlyWithRel(); break;
case 1: case 1:
Kind = SectionKind::get(SectionKind::ReadOnlyWithRelLocal); Kind = SectionKind::getReadOnlyWithRelLocal();
break; break;
case 0: case 0:
switch (TM.getTargetData()->getTypeAllocSize(CPE.getType())) { switch (TM.getTargetData()->getTypeAllocSize(CPE.getType())) {
case 4: Kind = SectionKind::get(SectionKind::MergeableConst4); break; case 4: Kind = SectionKind::getMergeableConst4(); break;
case 8: Kind = SectionKind::get(SectionKind::MergeableConst8); break; case 8: Kind = SectionKind::getMergeableConst8(); break;
case 16: Kind = SectionKind::get(SectionKind::MergeableConst16); break; case 16: Kind = SectionKind::getMergeableConst16(); break;
default: Kind = SectionKind::get(SectionKind::MergeableConst); break; default: Kind = SectionKind::getMergeableConst(); break;
} }
} }

View File

@ -90,19 +90,19 @@ static SectionKind SectionKindForGlobal(const GlobalValue *GV,
// Early exit - functions should be always in text sections. // Early exit - functions should be always in text sections.
const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV); const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV);
if (GVar == 0) if (GVar == 0)
return SectionKind::get(SectionKind::Text); return SectionKind::getText();
// Handle thread-local data first. // Handle thread-local data first.
if (GVar->isThreadLocal()) { if (GVar->isThreadLocal()) {
if (isSuitableForBSS(GVar)) if (isSuitableForBSS(GVar))
return SectionKind::get(SectionKind::ThreadBSS); return SectionKind::getThreadBSS();
return SectionKind::get(SectionKind::ThreadData); return SectionKind::getThreadData();
} }
// Variable can be easily put to BSS section. // Variable can be easily put to BSS section.
if (isSuitableForBSS(GVar)) if (isSuitableForBSS(GVar))
return SectionKind::get(SectionKind::BSS); return SectionKind::getBSS();
Constant *C = GVar->getInitializer(); Constant *C = GVar->getInitializer();
@ -118,16 +118,16 @@ static SectionKind SectionKindForGlobal(const GlobalValue *GV,
// If initializer is a null-terminated string, put it in a "cstring" // If initializer is a null-terminated string, put it in a "cstring"
// section if the target has it. // section if the target has it.
if (isConstantString(C)) if (isConstantString(C))
return SectionKind::get(SectionKind::MergeableCString); return SectionKind::getMergeableCString();
// Otherwise, just drop it into a mergable constant section. If we have // Otherwise, just drop it into a mergable constant section. If we have
// a section for this size, use it, otherwise use the arbitrary sized // a section for this size, use it, otherwise use the arbitrary sized
// mergable section. // mergable section.
switch (TM.getTargetData()->getTypeAllocSize(C->getType())) { switch (TM.getTargetData()->getTypeAllocSize(C->getType())) {
case 4: return SectionKind::get(SectionKind::MergeableConst4); case 4: return SectionKind::getMergeableConst4();
case 8: return SectionKind::get(SectionKind::MergeableConst8); case 8: return SectionKind::getMergeableConst8();
case 16: return SectionKind::get(SectionKind::MergeableConst16); case 16: return SectionKind::getMergeableConst16();
default: return SectionKind::get(SectionKind::MergeableConst); default: return SectionKind::getMergeableConst();
} }
case Constant::LocalRelocation: case Constant::LocalRelocation:
@ -137,11 +137,11 @@ static SectionKind SectionKindForGlobal(const GlobalValue *GV,
// the linker doesn't take relocations into consideration when it tries to // the linker doesn't take relocations into consideration when it tries to
// merge entries in the section. // merge entries in the section.
if (ReloModel == Reloc::Static) if (ReloModel == Reloc::Static)
return SectionKind::get(SectionKind::ReadOnly); return SectionKind::getReadOnly();
// Otherwise, the dynamic linker needs to fix it up, put it in the // Otherwise, the dynamic linker needs to fix it up, put it in the
// writable data.rel.local section. // writable data.rel.local section.
return SectionKind::get(SectionKind::ReadOnlyWithRelLocal); return SectionKind::getReadOnlyWithRelLocal();
case Constant::GlobalRelocations: case Constant::GlobalRelocations:
// In static relocation model, the linker will resolve all addresses, so // In static relocation model, the linker will resolve all addresses, so
@ -150,11 +150,11 @@ static SectionKind SectionKindForGlobal(const GlobalValue *GV,
// the linker doesn't take relocations into consideration when it tries to // the linker doesn't take relocations into consideration when it tries to
// merge entries in the section. // merge entries in the section.
if (ReloModel == Reloc::Static) if (ReloModel == Reloc::Static)
return SectionKind::get(SectionKind::ReadOnly); return SectionKind::getReadOnly();
// Otherwise, the dynamic linker needs to fix it up, put it in the // Otherwise, the dynamic linker needs to fix it up, put it in the
// writable data.rel section. // writable data.rel section.
return SectionKind::get(SectionKind::ReadOnlyWithRel); return SectionKind::getReadOnlyWithRel();
} }
} }
@ -164,16 +164,16 @@ static SectionKind SectionKindForGlobal(const GlobalValue *GV,
// globals together onto fewer pages, improving the locality of the dynamic // globals together onto fewer pages, improving the locality of the dynamic
// linker. // linker.
if (ReloModel == Reloc::Static) if (ReloModel == Reloc::Static)
return SectionKind::get(SectionKind::DataNoRel); return SectionKind::getDataNoRel();
switch (C->getRelocationInfo()) { switch (C->getRelocationInfo()) {
default: llvm_unreachable("unknown relocation info kind"); default: llvm_unreachable("unknown relocation info kind");
case Constant::NoRelocation: case Constant::NoRelocation:
return SectionKind::get(SectionKind::DataNoRel); return SectionKind::getDataNoRel();
case Constant::LocalRelocation: case Constant::LocalRelocation:
return SectionKind::get(SectionKind::DataRelLocal); return SectionKind::getDataRelLocal();
case Constant::GlobalRelocations: case Constant::GlobalRelocations:
return SectionKind::get(SectionKind::DataRel); return SectionKind::getDataRel();
} }
} }
@ -257,50 +257,44 @@ void TargetLoweringObjectFileELF::Initialize(MCContext &Ctx,
const TargetMachine &TM) { const TargetMachine &TM) {
TargetLoweringObjectFile::Initialize(Ctx, TM); TargetLoweringObjectFile::Initialize(Ctx, TM);
if (!HasCrazyBSS) if (!HasCrazyBSS)
BSSSection = getOrCreateSection("\t.bss", true, BSSSection = getOrCreateSection("\t.bss", true, SectionKind::getBSS());
SectionKind::get(SectionKind::BSS));
else else
// PPC/Linux doesn't support the .bss directive, it needs .section .bss. // PPC/Linux doesn't support the .bss directive, it needs .section .bss.
// FIXME: Does .section .bss work everywhere?? // FIXME: Does .section .bss work everywhere??
// FIXME2: this should just be handle by the section printer. We should get // FIXME2: this should just be handle by the section printer. We should get
// away from syntactic view of the sections and MCSection should just be a // away from syntactic view of the sections and MCSection should just be a
// semantic view. // semantic view.
BSSSection = getOrCreateSection("\t.bss", false, BSSSection = getOrCreateSection("\t.bss", false, SectionKind::getBSS());
SectionKind::get(SectionKind::BSS));
TextSection = getOrCreateSection("\t.text", true, TextSection = getOrCreateSection("\t.text", true, SectionKind::getText());
SectionKind::get(SectionKind::Text)); DataSection = getOrCreateSection("\t.data", true, SectionKind::getDataRel());
DataSection = getOrCreateSection("\t.data", true,
SectionKind::get(SectionKind::DataRel));
ReadOnlySection = ReadOnlySection =
getOrCreateSection("\t.rodata", false, getOrCreateSection("\t.rodata", false, SectionKind::getReadOnly());
SectionKind::get(SectionKind::ReadOnly));
TLSDataSection = TLSDataSection =
getOrCreateSection("\t.tdata", false, getOrCreateSection("\t.tdata", false, SectionKind::getThreadData());
SectionKind::get(SectionKind::ThreadData));
CStringSection = getOrCreateSection("\t.rodata.str", true, CStringSection = getOrCreateSection("\t.rodata.str", true,
SectionKind::get(SectionKind::MergeableCString)); SectionKind::getMergeableCString());
TLSBSSSection = getOrCreateSection("\t.tbss", false, TLSBSSSection = getOrCreateSection("\t.tbss", false,
SectionKind::get(SectionKind::ThreadBSS)); SectionKind::getThreadBSS());
DataRelSection = getOrCreateSection("\t.data.rel", false, DataRelSection = getOrCreateSection("\t.data.rel", false,
SectionKind::get(SectionKind::DataRel)); SectionKind::getDataRel());
DataRelLocalSection = getOrCreateSection("\t.data.rel.local", false, DataRelLocalSection = getOrCreateSection("\t.data.rel.local", false,
SectionKind::get(SectionKind::DataRelLocal)); SectionKind::getDataRelLocal());
DataRelROSection = getOrCreateSection("\t.data.rel.ro", false, DataRelROSection = getOrCreateSection("\t.data.rel.ro", false,
SectionKind::get(SectionKind::ReadOnlyWithRel)); SectionKind::getReadOnlyWithRel());
DataRelROLocalSection = DataRelROLocalSection =
getOrCreateSection("\t.data.rel.ro.local", false, getOrCreateSection("\t.data.rel.ro.local", false,
SectionKind::get(SectionKind::ReadOnlyWithRelLocal)); SectionKind::getReadOnlyWithRelLocal());
MergeableConst4Section = getOrCreateSection(".rodata.cst4", false, MergeableConst4Section = getOrCreateSection(".rodata.cst4", false,
SectionKind::get(SectionKind::MergeableConst4)); SectionKind::getMergeableConst4());
MergeableConst8Section = getOrCreateSection(".rodata.cst8", false, MergeableConst8Section = getOrCreateSection(".rodata.cst8", false,
SectionKind::get(SectionKind::MergeableConst8)); SectionKind::getMergeableConst8());
MergeableConst16Section = getOrCreateSection(".rodata.cst16", false, MergeableConst16Section = getOrCreateSection(".rodata.cst16", false,
SectionKind::get(SectionKind::MergeableConst16)); SectionKind::getMergeableConst16());
} }
@ -313,19 +307,19 @@ getKindForNamedSection(const char *Name, SectionKind K) const {
strncmp(Name, ".llvm.linkonce.b.", 17) == 0 || strncmp(Name, ".llvm.linkonce.b.", 17) == 0 ||
strncmp(Name, ".gnu.linkonce.sb.", 17) == 0 || strncmp(Name, ".gnu.linkonce.sb.", 17) == 0 ||
strncmp(Name, ".llvm.linkonce.sb.", 18) == 0) strncmp(Name, ".llvm.linkonce.sb.", 18) == 0)
return SectionKind::get(SectionKind::BSS); return SectionKind::getBSS();
if (strcmp(Name, ".tdata") == 0 || if (strcmp(Name, ".tdata") == 0 ||
strncmp(Name, ".tdata.", 7) == 0 || strncmp(Name, ".tdata.", 7) == 0 ||
strncmp(Name, ".gnu.linkonce.td.", 17) == 0 || strncmp(Name, ".gnu.linkonce.td.", 17) == 0 ||
strncmp(Name, ".llvm.linkonce.td.", 18) == 0) strncmp(Name, ".llvm.linkonce.td.", 18) == 0)
return SectionKind::get(SectionKind::ThreadData); return SectionKind::getThreadData();
if (strcmp(Name, ".tbss") == 0 || if (strcmp(Name, ".tbss") == 0 ||
strncmp(Name, ".tbss.", 6) == 0 || strncmp(Name, ".tbss.", 6) == 0 ||
strncmp(Name, ".gnu.linkonce.tb.", 17) == 0 || strncmp(Name, ".gnu.linkonce.tb.", 17) == 0 ||
strncmp(Name, ".llvm.linkonce.tb.", 18) == 0) strncmp(Name, ".llvm.linkonce.tb.", 18) == 0)
return SectionKind::get(SectionKind::ThreadBSS); return SectionKind::getThreadBSS();
return K; return K;
} }
@ -429,7 +423,7 @@ SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
std::string Name = CStringSection->getName() + "1." + utostr(Align); std::string Name = CStringSection->getName() + "1." + utostr(Align);
return getOrCreateSection(Name.c_str(), false, return getOrCreateSection(Name.c_str(), false,
SectionKind::get(SectionKind::MergeableCString)); SectionKind::getMergeableCString());
} }
if (Kind.isMergeableConst()) { if (Kind.isMergeableConst()) {
@ -485,16 +479,16 @@ void TargetLoweringObjectFileMachO::Initialize(MCContext &Ctx,
const TargetMachine &TM) { const TargetMachine &TM) {
TargetLoweringObjectFile::Initialize(Ctx, TM); TargetLoweringObjectFile::Initialize(Ctx, TM);
TextSection = getOrCreateSection("\t.text", true, TextSection = getOrCreateSection("\t.text", true,
SectionKind::get(SectionKind::Text)); SectionKind::getText());
DataSection = getOrCreateSection("\t.data", true, DataSection = getOrCreateSection("\t.data", true,
SectionKind::get(SectionKind::DataRel)); SectionKind::getDataRel());
CStringSection = getOrCreateSection("\t.cstring", true, CStringSection = getOrCreateSection("\t.cstring", true,
SectionKind::get(SectionKind::MergeableCString)); SectionKind::getMergeableCString());
FourByteConstantSection = getOrCreateSection("\t.literal4\n", true, FourByteConstantSection = getOrCreateSection("\t.literal4\n", true,
SectionKind::get(SectionKind::MergeableConst4)); SectionKind::getMergeableConst4());
EightByteConstantSection = getOrCreateSection("\t.literal8\n", true, EightByteConstantSection = getOrCreateSection("\t.literal8\n", true,
SectionKind::get(SectionKind::MergeableConst8)); SectionKind::getMergeableConst8());
// ld_classic doesn't support .literal16 in 32-bit mode, and ld64 falls back // ld_classic doesn't support .literal16 in 32-bit mode, and ld64 falls back
// to using it in -static mode. // to using it in -static mode.
@ -502,27 +496,27 @@ void TargetLoweringObjectFileMachO::Initialize(MCContext &Ctx,
TM.getTargetData()->getPointerSize() == 32) TM.getTargetData()->getPointerSize() == 32)
SixteenByteConstantSection = SixteenByteConstantSection =
getOrCreateSection("\t.literal16\n", true, getOrCreateSection("\t.literal16\n", true,
SectionKind::get(SectionKind::MergeableConst16)); SectionKind::getMergeableConst16());
else else
SixteenByteConstantSection = 0; SixteenByteConstantSection = 0;
ReadOnlySection = getOrCreateSection("\t.const", true, ReadOnlySection = getOrCreateSection("\t.const", true,
SectionKind::get(SectionKind::ReadOnly)); SectionKind::getReadOnly());
TextCoalSection = TextCoalSection =
getOrCreateSection("\t__TEXT,__textcoal_nt,coalesced,pure_instructions", getOrCreateSection("\t__TEXT,__textcoal_nt,coalesced,pure_instructions",
false, SectionKind::get(SectionKind::Text)); false, SectionKind::getText());
ConstTextCoalSection = getOrCreateSection("\t__TEXT,__const_coal,coalesced", ConstTextCoalSection = getOrCreateSection("\t__TEXT,__const_coal,coalesced",
false, false,
SectionKind::get(SectionKind::Text)); SectionKind::getText());
ConstDataCoalSection = getOrCreateSection("\t__DATA,__const_coal,coalesced", ConstDataCoalSection = getOrCreateSection("\t__DATA,__const_coal,coalesced",
false, false,
SectionKind::get(SectionKind::Text)); SectionKind::getText());
ConstDataSection = getOrCreateSection("\t.const_data", true, ConstDataSection = getOrCreateSection("\t.const_data", true,
SectionKind::get(SectionKind::ReadOnlyWithRel)); SectionKind::getReadOnlyWithRel());
DataCoalSection = getOrCreateSection("\t__DATA,__datacoal_nt,coalesced", DataCoalSection = getOrCreateSection("\t__DATA,__datacoal_nt,coalesced",
false, false,
SectionKind::get(SectionKind::DataRel)); SectionKind::getDataRel());
} }
const MCSection *TargetLoweringObjectFileMachO:: const MCSection *TargetLoweringObjectFileMachO::
@ -627,9 +621,9 @@ void TargetLoweringObjectFileCOFF::Initialize(MCContext &Ctx,
const TargetMachine &TM) { const TargetMachine &TM) {
TargetLoweringObjectFile::Initialize(Ctx, TM); TargetLoweringObjectFile::Initialize(Ctx, TM);
TextSection = getOrCreateSection("\t.text", true, TextSection = getOrCreateSection("\t.text", true,
SectionKind::get(SectionKind::Text)); SectionKind::getText());
DataSection = getOrCreateSection("\t.data", true, DataSection = getOrCreateSection("\t.data", true,
SectionKind::get(SectionKind::DataRel)); SectionKind::getDataRel());
} }
void TargetLoweringObjectFileCOFF:: void TargetLoweringObjectFileCOFF::