1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-20 03:23:01 +02:00

Eliminate getNamed/getUnnamedSection, adding a new and unified getOrCreateSection

instead.

llvm-svn: 77186
This commit is contained in:
Chris Lattner 2009-07-27 06:17:14 +00:00
parent a2b00bdd7a
commit cd7d963b75
15 changed files with 107 additions and 110 deletions

View File

@ -639,10 +639,9 @@ namespace llvm {
explicit TargetAsmInfo(const TargetMachine &TM);
virtual ~TargetAsmInfo();
const Section* getNamedSection(const char *Name,
SectionKind::Kind K) const;
const Section* getUnnamedSection(const char *Directive,
SectionKind::Kind K) const;
const Section *getOrCreateSection(const char *Name,
bool isDirective,
SectionKind::Kind K) const;
/// Measure the specified inline asm to determine an approximation of its
/// length.

View File

@ -59,7 +59,7 @@ ARMELFTargetAsmInfo::ARMELFTargetAsmInfo(const ARMBaseTargetMachine &TM):
ARMTargetAsmInfo<ELFTargetAsmInfo>(TM) {
Subtarget = &TM.getSubtarget<ARMSubtarget>();
BSSSection_ = getUnnamedSection("\t.bss", SectionKind::BSS);
BSSSection_ = getOrCreateSection("\t.bss", true, SectionKind::BSS);
NeedsSet = false;
HasLEB128 = true;

View File

@ -35,7 +35,7 @@ SPULinuxTargetAsmInfo::SPULinuxTargetAsmInfo(const SPUTargetMachine &TM) :
// BSS section needs to be emitted as ".section"
BSSSection = "\t.section\t.bss";
BSSSection_ = getUnnamedSection("\t.section\t.bss", SectionKind::BSS);
BSSSection_ = getOrCreateSection("\t.bss", false, SectionKind::BSS);
SupportsDebugInformation = true;
NeedsSet = true;

View File

@ -28,30 +28,30 @@ using namespace llvm;
DarwinTargetAsmInfo::DarwinTargetAsmInfo(const TargetMachine &TM)
: TargetAsmInfo(TM) {
CStringSection_ = getUnnamedSection("\t.cstring",
SectionKind::MergeableCString);
FourByteConstantSection = getUnnamedSection("\t.literal4\n",
SectionKind::MergeableConst4);
EightByteConstantSection = getUnnamedSection("\t.literal8\n",
SectionKind::MergeableConst8);
CStringSection_ = getOrCreateSection("\t.cstring", true,
SectionKind::MergeableCString);
FourByteConstantSection = getOrCreateSection("\t.literal4\n", true,
SectionKind::MergeableConst4);
EightByteConstantSection = getOrCreateSection("\t.literal8\n", true,
SectionKind::MergeableConst8);
// Note: 16-byte constant section is subtarget specific and should be provided
// there, if needed.
SixteenByteConstantSection = 0;
ReadOnlySection = getUnnamedSection("\t.const", SectionKind::ReadOnly);
ReadOnlySection = getOrCreateSection("\t.const", true, SectionKind::ReadOnly);
TextCoalSection =
getNamedSection("\t__TEXT,__textcoal_nt,coalesced,pure_instructions",
SectionKind::Text);
ConstTextCoalSection = getNamedSection("\t__TEXT,__const_coal,coalesced",
SectionKind::Text);
ConstDataCoalSection = getNamedSection("\t__DATA,__const_coal,coalesced",
SectionKind::Text);
ConstDataSection = getUnnamedSection("\t.const_data",
SectionKind::ReadOnlyWithRel);
DataCoalSection = getNamedSection("\t__DATA,__datacoal_nt,coalesced",
SectionKind::DataRel);
getOrCreateSection("\t__TEXT,__textcoal_nt,coalesced,pure_instructions",
false, SectionKind::Text);
ConstTextCoalSection = getOrCreateSection("\t__TEXT,__const_coal,coalesced",
false, SectionKind::Text);
ConstDataCoalSection = getOrCreateSection("\t__DATA,__const_coal,coalesced",
false, SectionKind::Text);
ConstDataSection = getOrCreateSection("\t.const_data", true,
SectionKind::ReadOnlyWithRel);
DataCoalSection = getOrCreateSection("\t__DATA,__datacoal_nt,coalesced",
false, SectionKind::DataRel);
// Common settings for all Darwin targets.

View File

@ -26,25 +26,28 @@ using namespace llvm;
ELFTargetAsmInfo::ELFTargetAsmInfo(const TargetMachine &TM)
: TargetAsmInfo(TM) {
ReadOnlySection =
getOrCreateSection("\t.rodata", false, SectionKind::ReadOnly);
TLSDataSection =
getOrCreateSection("\t.tdata", false, SectionKind::ThreadData);
TLSBSSSection = getOrCreateSection("\t.tbss", false, SectionKind::ThreadBSS);
ReadOnlySection = getNamedSection("\t.rodata", SectionKind::ReadOnly);
TLSDataSection = getNamedSection("\t.tdata", SectionKind::ThreadData);
TLSBSSSection = getNamedSection("\t.tbss", SectionKind::ThreadBSS);
DataRelSection = getNamedSection("\t.data.rel", SectionKind::DataRel);
DataRelLocalSection = getNamedSection("\t.data.rel.local",
SectionKind::DataRelLocal);
DataRelROSection = getNamedSection("\t.data.rel.ro",
SectionKind::ReadOnlyWithRel);
DataRelROLocalSection = getNamedSection("\t.data.rel.ro.local",
SectionKind::ReadOnlyWithRelLocal);
DataRelSection = getOrCreateSection("\t.data.rel", false,
SectionKind::DataRel);
DataRelLocalSection = getOrCreateSection("\t.data.rel.local", false,
SectionKind::DataRelLocal);
DataRelROSection = getOrCreateSection("\t.data.rel.ro", false,
SectionKind::ReadOnlyWithRel);
DataRelROLocalSection =
getOrCreateSection("\t.data.rel.ro.local", false,
SectionKind::ReadOnlyWithRelLocal);
MergeableConst4Section = getNamedSection(".rodata.cst4",
SectionKind::MergeableConst4);
MergeableConst8Section = getNamedSection(".rodata.cst8",
SectionKind::MergeableConst8);
MergeableConst16Section = getNamedSection(".rodata.cst16",
SectionKind::MergeableConst16);
MergeableConst4Section = getOrCreateSection(".rodata.cst4", false,
SectionKind::MergeableConst4);
MergeableConst8Section = getOrCreateSection(".rodata.cst8", false,
SectionKind::MergeableConst8);
MergeableConst16Section = getOrCreateSection(".rodata.cst16", false,
SectionKind::MergeableConst16);
}
@ -158,7 +161,8 @@ ELFTargetAsmInfo::MergeableStringSection(const GlobalVariable *GV) const {
Align = Size;
std::string Name = getCStringSection() + utostr(Size) + '.' + utostr(Align);
return getNamedSection(Name.c_str(), SectionKind::MergeableCString);
return getOrCreateSection(Name.c_str(), false,
SectionKind::MergeableCString);
}
return getReadOnlySection();

View File

@ -18,5 +18,5 @@ MSP430TargetAsmInfo::MSP430TargetAsmInfo(const TargetMachine &TM)
: ELFTargetAsmInfo(TM) {
AlignmentIsInBytes = false;
BSSSection_ = getUnnamedSection("\t.bss", SectionKind::BSS);
BSSSection_ = getOrCreateSection("\t.bss", true, SectionKind::BSS);
}

View File

@ -30,7 +30,7 @@ MipsTargetAsmInfo::MipsTargetAsmInfo(const MipsTargetMachine &TM)
BSSSection = "\t.section\t.bss";
CStringSection = ".rodata.str";
BSSSection_ = getUnnamedSection("\t.bss", SectionKind::BSS);
BSSSection_ = getOrCreateSection("\t.bss", true, SectionKind::BSS);
if (!TM.getSubtarget<MipsSubtarget>().hasABICall())
JumpTableDirective = "\t.word\t";

View File

@ -62,7 +62,7 @@ bool PIC16AsmPrinter::runOnMachineFunction(MachineFunction &MF) {
const char *codeSection = PAN::getCodeSectionName(CurrentFnName).c_str();
const Section *fCodeSection =
TAI->getNamedSection(codeSection, SectionKind::Text);
TAI->getOrCreateSection(codeSection, false, SectionKind::Text);
// Start the Code Section.
O << "\n";
SwitchToSection(fCodeSection);
@ -292,7 +292,7 @@ void PIC16AsmPrinter::EmitFunctionFrame(MachineFunction &MF) {
const char *SectionName = PAN::getFrameSectionName(CurrentFnName).c_str();
const Section *fPDataSection =
TAI->getNamedSection(SectionName, SectionKind::DataRel);
TAI->getOrCreateSection(SectionName, false, SectionKind::DataRel);
SwitchToSection(fPDataSection);
// Emit function frame label

View File

@ -37,21 +37,24 @@ PIC16TargetAsmInfo(const PIC16TargetMachine &TM)
ZeroDirective = NULL;
AsciiDirective = " dt ";
AscizDirective = NULL;
BSSSection_ = getNamedSection("udata.# UDATA", SectionKind::BSS);
ReadOnlySection = getNamedSection("romdata.# ROMDATA", SectionKind::ReadOnly);
DataSection = getNamedSection("idata.# IDATA", SectionKind::DataRel);
BSSSection_ = getOrCreateSection("udata.# UDATA", false, SectionKind::BSS);
ReadOnlySection = getOrCreateSection("romdata.# ROMDATA", false,
SectionKind::ReadOnly);
DataSection = getOrCreateSection("idata.# IDATA", false,SectionKind::DataRel);
SwitchToSectionDirective = "";
// Need because otherwise a .text symbol is emitted by DwarfWriter
// in BeginModule, and gpasm cribbs for that .text symbol.
TextSection = getUnnamedSection("", SectionKind::Text);
TextSection = getOrCreateSection("", true, SectionKind::Text);
PIC16Section *ROSection = new PIC16Section(getReadOnlySection());
ROSections.push_back(ROSection);
// FIXME: I don't know what the classification of these sections really is.
ExternalVarDecls = new PIC16Section(getNamedSection("ExternalVarDecls",
SectionKind::Metadata));
ExternalVarDefs = new PIC16Section(getNamedSection("ExternalVarDefs",
SectionKind::Metadata));
ExternalVarDecls = new PIC16Section(getOrCreateSection("ExternalVarDecls",
false,
SectionKind::Metadata));
ExternalVarDefs = new PIC16Section(getOrCreateSection("ExternalVarDefs",
false,
SectionKind::Metadata));
// Set it to false because we weed to generate c file name and not bc file
// name.
HasSingleParameterDotFile = false;
@ -98,9 +101,9 @@ PIC16TargetAsmInfo::getBSSSectionForGlobal(const GlobalVariable *GV) const {
// No BSS section spacious enough was found. Crate a new one.
if (!FoundBSS) {
std::string name = PAN::getUdataSectionName(BSSSections.size());
const Section *NewSection = getNamedSection(name.c_str(),
// FIXME.
SectionKind::Metadata);
const Section *NewSection = getOrCreateSection(name.c_str(), false,
// FIXME.
SectionKind::Metadata);
FoundBSS = new PIC16Section(NewSection);
@ -140,9 +143,10 @@ PIC16TargetAsmInfo::getIDATASectionForGlobal(const GlobalVariable *GV) const {
// No IDATA section spacious enough was found. Crate a new one.
if (!FoundIDATA) {
std::string name = PAN::getIdataSectionName(IDATASections.size());
const Section *NewSection = getNamedSection(name.c_str(),
// FIXME.
SectionKind::Metadata);
const Section *NewSection = getOrCreateSection(name.c_str(),
false,
// FIXME.
SectionKind::Metadata);
FoundIDATA = new PIC16Section(NewSection);
@ -175,9 +179,10 @@ PIC16TargetAsmInfo::getSectionForAuto(const GlobalVariable *GV) const {
// No Auto section was found. Crate a new one.
if (!FoundAutoSec) {
const Section *NewSection = getNamedSection(name.c_str(),
// FIXME.
SectionKind::Metadata);
const Section *NewSection = getOrCreateSection(name.c_str(),
// FIXME.
false,
SectionKind::Metadata);
FoundAutoSec = new PIC16Section(NewSection);
@ -325,7 +330,8 @@ PIC16TargetAsmInfo::CreateBSSSectionForGlobal(const GlobalVariable *GV,
PIC16Section *NewBSS = FoundBSS;
if (NewBSS == NULL) {
const Section *NewSection = getNamedSection(Name.c_str(), SectionKind::BSS);
const Section *NewSection = getOrCreateSection(Name.c_str(),
false, SectionKind::BSS);
NewBSS = new PIC16Section(NewSection);
BSSSections.push_back(NewBSS);
}
@ -376,9 +382,10 @@ PIC16TargetAsmInfo::CreateIDATASectionForGlobal(const GlobalVariable *GV,
PIC16Section *NewIDATASec = FoundIDATASec;
if (NewIDATASec == NULL) {
const Section *NewSection = getNamedSection(Name.c_str(),
// FIXME:
SectionKind::Metadata);
const Section *NewSection = getOrCreateSection(Name.c_str(),
false,
// FIXME:
SectionKind::Metadata);
NewIDATASec = new PIC16Section(NewSection);
IDATASections.push_back(NewIDATASec);
}
@ -416,8 +423,9 @@ PIC16TargetAsmInfo::CreateROSectionForGlobal(const GlobalVariable *GV,
PIC16Section *NewRomSec = FoundROSec;
if (NewRomSec == NULL) {
const Section *NewSection = getNamedSection(Name.c_str(),
SectionKind::ReadOnly);
const Section *NewSection = getOrCreateSection(Name.c_str(),
false,
SectionKind::ReadOnly);
NewRomSec = new PIC16Section(NewSection);
ROSections.push_back(NewRomSec);
}

View File

@ -71,7 +71,7 @@ PPCLinuxTargetAsmInfo::PPCLinuxTargetAsmInfo(const PPCTargetMachine &TM) :
BSSSection = "\t.section\t\".sbss\",\"aw\",@nobits";
// PPC/Linux normally uses named section for BSS.
BSSSection_ = getNamedSection("\t.bss", SectionKind::BSS);
BSSSection_ = getOrCreateSection("\t.bss", true, SectionKind::BSS);
// Debug Information
AbsoluteDebugSectionOffsets = true;

View File

@ -27,7 +27,7 @@ SparcELFTargetAsmInfo::SparcELFTargetAsmInfo(const TargetMachine &TM)
CStringSection=".rodata.str";
// Sparc normally uses named section for BSS.
BSSSection_ = getNamedSection("\t.bss", SectionKind::BSS);
BSSSection_ = getOrCreateSection("\t.bss", true, SectionKind::BSS);
}

View File

@ -28,5 +28,5 @@ SystemZTargetAsmInfo::SystemZTargetAsmInfo(const SystemZTargetMachine &TM)
NonexecutableStackDirective = "\t.section\t.note.GNU-stack,\"\",@progbits";
BSSSection_ = getUnnamedSection("\t.bss", SectionKind::BSS);
BSSSection_ = getOrCreateSection("\t.bss", true, SectionKind::BSS);
}

View File

@ -122,8 +122,8 @@ TargetAsmInfo::TargetAsmInfo(const TargetMachine &tm) : TM(tm) {
DwarfEHFrameSection = ".eh_frame";
DwarfExceptionSection = ".gcc_except_table";
AsmTransCBE = 0;
TextSection = getUnnamedSection("\t.text", SectionKind::Text);
DataSection = getUnnamedSection("\t.data", SectionKind::DataRel);
TextSection = getOrCreateSection("\t.text", true, SectionKind::Text);
DataSection = getOrCreateSection("\t.data", true, SectionKind::DataRel);
}
TargetAsmInfo::~TargetAsmInfo() {
@ -314,7 +314,7 @@ const Section *TargetAsmInfo::SectionForGlobal(const GlobalValue *GV) const {
// section and still get the appropriate section flags printed.
GVKind = getKindForNamedSection(GV->getSection().c_str(), GVKind);
return getNamedSection(GV->getSection().c_str(), GVKind);
return getOrCreateSection(GV->getSection().c_str(), false, GVKind);
}
// If this global is linkonce/weak and the target handles this by emitting it
@ -323,7 +323,7 @@ const Section *TargetAsmInfo::SectionForGlobal(const GlobalValue *GV) const {
if (const char *Prefix = getSectionPrefixForUniqueGlobal(Kind)) {
// FIXME: Use mangler interface (PR4584).
std::string Name = Prefix+GV->getNameStr();
return getNamedSection(Name.c_str(), GVKind);
return getOrCreateSection(Name.c_str(), false, GVKind);
}
}
@ -364,33 +364,20 @@ TargetAsmInfo::getSectionForMergeableConstant(SectionKind Kind) const {
}
const Section *TargetAsmInfo::getNamedSection(const char *Name,
SectionKind::Kind Kind) const {
const Section *TargetAsmInfo::getOrCreateSection(const char *Name,
bool isDirective,
SectionKind::Kind Kind) const {
Section &S = Sections[Name];
// This is newly-created section, set it up properly.
if (S.Name.empty()) {
S.Kind = SectionKind::get(Kind, false /*weak*/, true /*Named*/);
S.Kind = SectionKind::get(Kind, false /*weak*/, !isDirective);
S.Name = Name;
}
return &S;
}
const Section*
TargetAsmInfo::getUnnamedSection(const char *Directive,
SectionKind::Kind Kind) const {
Section& S = Sections[Directive];
// This is newly-created section, set it up properly.
if (S.Name.empty()) {
S.Kind = SectionKind::get(Kind, false /*weak*/, false /*Named*/);
S.Name = Directive;
}
return &S;
}
unsigned TargetAsmInfo::getULEB128Size(unsigned Value) {
unsigned Size = 0;
do {

View File

@ -57,8 +57,8 @@ X86DarwinTargetAsmInfo::X86DarwinTargetAsmInfo(const X86TargetMachine &TM):
ConstantPoolSection = "\t.const\n";
// FIXME: Why don't we always use this section?
if (is64Bit)
SixteenByteConstantSection = getUnnamedSection("\t.literal16\n",
SectionKind::MergeableConst16);
SixteenByteConstantSection =
getOrCreateSection("\t.literal16\n", true, SectionKind::MergeableConst16);
LCOMMDirective = "\t.lcomm\t";
// Leopard and above support aligned common symbols.
@ -100,23 +100,20 @@ X86DarwinTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
bool Global) const {
if (Reason == DwarfEncoding::Functions && Global)
return (DW_EH_PE_pcrel | DW_EH_PE_indirect | DW_EH_PE_sdata4);
else if (Reason == DwarfEncoding::CodeLabels || !Global)
if (Reason == DwarfEncoding::CodeLabels || !Global)
return DW_EH_PE_pcrel;
else
return DW_EH_PE_absptr;
return DW_EH_PE_absptr;
}
const char *
X86DarwinTargetAsmInfo::getEHGlobalPrefix() const
{
X86DarwinTargetAsmInfo::getEHGlobalPrefix() const {
const X86Subtarget* Subtarget = &TM.getSubtarget<X86Subtarget>();
if (Subtarget->getDarwinVers() > 9)
return PrivateGlobalPrefix;
else
return "";
return "";
}
X86ELFTargetAsmInfo::X86ELFTargetAsmInfo(const X86TargetMachine &TM):
X86ELFTargetAsmInfo::X86ELFTargetAsmInfo(const X86TargetMachine &TM) :
X86TargetAsmInfo<ELFTargetAsmInfo>(TM) {
CStringSection = ".rodata.str";
@ -128,7 +125,7 @@ X86ELFTargetAsmInfo::X86ELFTargetAsmInfo(const X86TargetMachine &TM):
// Set up DWARF directives
HasLEB128 = true; // Target asm supports leb128 directives (little-endian)
BSSSection_ = getUnnamedSection("\t.bss", SectionKind::BSS);
BSSSection_ = getOrCreateSection("\t.bss", true, SectionKind::BSS);
// Debug Information
AbsoluteDebugSectionOffsets = true;
@ -314,8 +311,8 @@ X86WinTargetAsmInfo::X86WinTargetAsmInfo(const X86TargetMachine &TM):
AlignmentIsInBytes = true;
TextSection = getUnnamedSection("_text", SectionKind::Text);
DataSection = getUnnamedSection("_data", SectionKind::DataRel);
TextSection = getOrCreateSection("_text", true, SectionKind::Text);
DataSection = getOrCreateSection("_data", true, SectionKind::DataRel);
JumpTableDataSection = NULL;
SwitchToSectionDirective = "";

View File

@ -24,9 +24,9 @@ using namespace llvm;
XCoreTargetAsmInfo::XCoreTargetAsmInfo(const XCoreTargetMachine &TM)
: ELFTargetAsmInfo(TM) {
SupportsDebugInformation = true;
TextSection = getUnnamedSection("\t.text", SectionKind::Text);
DataSection = getNamedSection("\t.dp.data", SectionKind::DataRel);
BSSSection_ = getNamedSection("\t.dp.bss", SectionKind::BSS);
TextSection = getOrCreateSection("\t.text", true, SectionKind::Text);
DataSection = getOrCreateSection("\t.dp.data", false, SectionKind::DataRel);
BSSSection_ = getOrCreateSection("\t.dp.bss", false, SectionKind::BSS);
// TLS globals are lowered in the backend to arrays indexed by the current
// thread id. After lowering they require no special handling by the linker
@ -36,9 +36,11 @@ XCoreTargetAsmInfo::XCoreTargetAsmInfo(const XCoreTargetMachine &TM)
if (TM.getSubtargetImpl()->isXS1A())
// FIXME: Why is this writable???
ReadOnlySection = getNamedSection("\t.dp.rodata", SectionKind::DataRel);
ReadOnlySection = getOrCreateSection("\t.dp.rodata", false,
SectionKind::DataRel);
else
ReadOnlySection = getNamedSection("\t.cp.rodata", SectionKind::ReadOnly);
ReadOnlySection = getOrCreateSection("\t.cp.rodata", false,
SectionKind::ReadOnly);
Data16bitsDirective = "\t.short\t";
Data32bitsDirective = "\t.long\t";
Data64bitsDirective = 0;