diff options
author | Chris Lattner <sabre@nondot.org> | 2009-07-22 00:28:43 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-07-22 00:28:43 +0000 |
commit | 680c6f69828e44b73f2dbea9922c35c8cd481f52 (patch) | |
tree | 603a6eb1a17ad2fa32f99daa34a77c5e7e42de9f /lib/Target | |
parent | 5454456ad84ec6080b09188456f27493d9ca4b87 (diff) | |
download | external_llvm-680c6f69828e44b73f2dbea9922c35c8cd481f52.zip external_llvm-680c6f69828e44b73f2dbea9922c35c8cd481f52.tar.gz external_llvm-680c6f69828e44b73f2dbea9922c35c8cd481f52.tar.bz2 |
remove the SelectSectionForMachineConst hook, replacing it with
a new getSectionForMergableConstant hook. This removes one dependence
of TAI on Type, and provides the hook with enough info to make the
right decision based on whether the global has relocations etc.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@76705 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target')
-rw-r--r-- | lib/Target/DarwinTargetAsmInfo.cpp | 42 | ||||
-rw-r--r-- | lib/Target/ELFTargetAsmInfo.cpp | 44 | ||||
-rw-r--r-- | lib/Target/TargetAsmInfo.cpp | 13 |
3 files changed, 58 insertions, 41 deletions
diff --git a/lib/Target/DarwinTargetAsmInfo.cpp b/lib/Target/DarwinTargetAsmInfo.cpp index 30468ef..ad9dd68 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 1bcfaf9..fe006a3 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 96814fe..d8c331e 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 { |