diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 9 | ||||
-rw-r--r-- | lib/CodeGen/ELFWriter.cpp | 4 | ||||
-rw-r--r-- | lib/Target/DarwinTargetAsmInfo.cpp | 42 | ||||
-rw-r--r-- | lib/Target/ELFTargetAsmInfo.cpp | 44 | ||||
-rw-r--r-- | lib/Target/TargetAsmInfo.cpp | 13 |
5 files changed, 68 insertions, 44 deletions
diff --git a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 7b7a9a5a97..e31a39c7a3 100644 --- a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -302,13 +302,18 @@ void AsmPrinter::EmitConstantPool(MachineConstantPool *MCP) { const std::vector<MachineConstantPoolEntry> &CP = MCP->getConstants(); if (CP.empty()) return; + const TargetData &TD = *TM.getTargetData(); + // Calculate sections for constant pool entries. We collect entries to go into // the same section together to reduce amount of section switch statements. SmallVector<SectionCPs, 4> CPSections; for (unsigned i = 0, e = CP.size(); i != e; ++i) { - MachineConstantPoolEntry CPE = CP[i]; + const MachineConstantPoolEntry &CPE = CP[i]; unsigned Align = CPE.getAlignment(); - const Section* S = TAI->SelectSectionForMachineConst(CPE.getType()); + uint64_t Size = TD.getTypeAllocSize(CPE.getType()); + const Section *S = + TAI->getSectionForMergableConstant(Size, CPE.getRelocationInfo()); + // The number of sections are small, just do a linear search from the // last section to the first. bool Found = false; diff --git a/lib/CodeGen/ELFWriter.cpp b/lib/CodeGen/ELFWriter.cpp index f4cd94a988..8cbaf6f13b 100644 --- a/lib/CodeGen/ELFWriter.cpp +++ b/lib/CodeGen/ELFWriter.cpp @@ -155,8 +155,10 @@ ELFSection &ELFWriter::getJumpTableSection() { // Get a constant pool section based on the section name returned by TAI ELFSection &ELFWriter::getConstantPoolSection(MachineConstantPoolEntry &CPE) { + uint64_t Size = TM.getTargetData()->getTypeAllocSize(CPE.getType()); + std::string CstPoolName = - TAI->SelectSectionForMachineConst(CPE.getType())->getName(); + TAI->getSectionForMergableConstant(Size,CPE.getRelocationInfo())->getName(); return getSection(CstPoolName, ELFSection::SHT_PROGBITS, ELFSection::SHF_MERGE | ELFSection::SHF_ALLOC, diff --git a/lib/Target/DarwinTargetAsmInfo.cpp b/lib/Target/DarwinTargetAsmInfo.cpp index 30468efe3e..ad9dd6884f 100644 --- a/lib/Target/DarwinTargetAsmInfo.cpp +++ b/lib/Target/DarwinTargetAsmInfo.cpp @@ -29,7 +29,7 @@ DarwinTargetAsmInfo::DarwinTargetAsmInfo(const TargetMachine &TM) : TargetAsmInfo(TM) { CStringSection_ = getUnnamedSection("\t.cstring", - SectionFlags::Mergeable | SectionFlags::Strings); + SectionFlags::Mergeable |SectionFlags::Strings); FourByteConstantSection = getUnnamedSection("\t.literal4\n", SectionFlags::Mergeable); EightByteConstantSection = getUnnamedSection("\t.literal8\n", @@ -182,28 +182,30 @@ DarwinTargetAsmInfo::MergeableStringSection(const GlobalVariable *GV) const { const Section* DarwinTargetAsmInfo::MergeableConstSection(const Type *Ty) const { const TargetData *TD = TM.getTargetData(); - - unsigned Size = TD->getTypeAllocSize(Ty); - if (Size == 4) - return FourByteConstantSection; - else if (Size == 8) - return EightByteConstantSection; - else if (Size == 16 && SixteenByteConstantSection) - return SixteenByteConstantSection; - - return getReadOnlySection(); + return getSectionForMergableConstant(TD->getTypeAllocSize(Ty), 0); } -const Section* -DarwinTargetAsmInfo::SelectSectionForMachineConst(const Type *Ty) const { - const Section* S = MergeableConstSection(Ty); - - // Handle weird special case, when compiling PIC stuff. - if (S == getReadOnlySection() && - TM.getRelocationModel() != Reloc::Static) +const Section * +DarwinTargetAsmInfo::getSectionForMergableConstant(uint64_t Size, + unsigned ReloInfo) const { + // If this constant requires a relocation, we have to put it in the data + // segment, not in the text segment. + if (ReloInfo != 0) return ConstDataSection; - - return S; + + switch (Size) { + default: break; + case 4: + return FourByteConstantSection; + case 8: + return EightByteConstantSection; + case 16: + if (SixteenByteConstantSection) + return SixteenByteConstantSection; + break; + } + + return ReadOnlySection; // .const } std::string diff --git a/lib/Target/ELFTargetAsmInfo.cpp b/lib/Target/ELFTargetAsmInfo.cpp index 1bcfaf91ad..fe006a3c60 100644 --- a/lib/Target/ELFTargetAsmInfo.cpp +++ b/lib/Target/ELFTargetAsmInfo.cpp @@ -138,29 +138,37 @@ ELFTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const { return NULL; } -const Section* -ELFTargetAsmInfo::SelectSectionForMachineConst(const Type *Ty) const { - // FIXME: Support data.rel stuff someday - return MergeableConstSection(Ty); +/// getSectionForMergableConstant - Given a mergable constant with the +/// specified size and relocation information, return a section that it +/// should be placed in. +const Section * +ELFTargetAsmInfo::getSectionForMergableConstant(uint64_t Size, + unsigned ReloInfo) const { + // FIXME: IF this global requires a relocation, can we really put it in + // rodata??? This should check ReloInfo like darwin. + + const char *SecName = 0; + switch (Size) { + default: break; + case 4: SecName = ".rodata.cst4"; break; + case 8: SecName = ".rodata.cst8"; break; + case 16: SecName = ".rodata.cst16"; break; + } + + if (SecName) + return getNamedSection(SecName, + SectionFlags::setEntitySize(SectionFlags::Mergeable| + SectionFlags::Small, + Size)); + + return getReadOnlySection(); // .rodata } + const Section* ELFTargetAsmInfo::MergeableConstSection(const Type *Ty) const { const TargetData *TD = TM.getTargetData(); - - // FIXME: string here is temporary, until stuff will fully land in. - // We cannot use {Four,Eight,Sixteen}ByteConstantSection here, since it's - // currently directly used by asmprinter. - unsigned Size = TD->getTypeAllocSize(Ty); - if (Size == 4 || Size == 8 || Size == 16) { - std::string Name = ".rodata.cst" + utostr(Size); - - return getNamedSection(Name.c_str(), - SectionFlags::setEntitySize(SectionFlags::Mergeable, - Size)); - } - - return getReadOnlySection(); + return getSectionForMergableConstant(TD->getTypeAllocSize(Ty), 0); } const Section* diff --git a/lib/Target/TargetAsmInfo.cpp b/lib/Target/TargetAsmInfo.cpp index 96814fee4c..d8c331eb40 100644 --- a/lib/Target/TargetAsmInfo.cpp +++ b/lib/Target/TargetAsmInfo.cpp @@ -329,13 +329,20 @@ TargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const { return getDataSection(); } -// Lame default implementation. Calculate the section name for machine const. -const Section* -TargetAsmInfo::SelectSectionForMachineConst(const Type *Ty) const { +/// getSectionForMergableConstant - Given a mergable constant with the +/// specified size and relocation information, return a section that it +/// should be placed in. +const Section * +TargetAsmInfo::getSectionForMergableConstant(uint64_t Size, + unsigned ReloInfo) const { // FIXME: Support data.rel stuff someday + // Lame default implementation. Calculate the section name for machine const. return getDataSection(); } + + + std::string TargetAsmInfo::UniqueSectionForGlobal(const GlobalValue* GV, SectionKind::Kind Kind) const { |