From 5c2f789952ff315021afb10381f141f2ac3b1a6b Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 26 Jul 2009 06:26:55 +0000 Subject: [PATCH] simplify getSectionForMergableConstant to take a SectionKind. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77134 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Target/DarwinTargetAsmInfo.h | 3 +-- include/llvm/Target/ELFTargetAsmInfo.h | 2 +- include/llvm/Target/TargetAsmInfo.h | 3 +-- lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 21 ++++++++++++++++----- lib/CodeGen/ELFWriter.cpp | 18 ++++++++++++++---- lib/Target/DarwinTargetAsmInfo.cpp | 19 ++++++------------- lib/Target/ELFTargetAsmInfo.cpp | 17 ++--------------- lib/Target/TargetAsmInfo.cpp | 5 ++--- 8 files changed, 43 insertions(+), 45 deletions(-) diff --git a/include/llvm/Target/DarwinTargetAsmInfo.h b/include/llvm/Target/DarwinTargetAsmInfo.h index 3b3b7329f86..02f5834c97e 100644 --- a/include/llvm/Target/DarwinTargetAsmInfo.h +++ b/include/llvm/Target/DarwinTargetAsmInfo.h @@ -40,8 +40,7 @@ namespace llvm { Mangler *Mang) const; - virtual const Section * - getSectionForMergableConstant(uint64_t Size, unsigned ReloInfo) const; + virtual const Section *getSectionForMergableConstant(SectionKind Kind)const; private: const Section* MergeableStringSection(const GlobalVariable *GV) const; diff --git a/include/llvm/Target/ELFTargetAsmInfo.h b/include/llvm/Target/ELFTargetAsmInfo.h index 9d31faa94ad..6744b49adf6 100644 --- a/include/llvm/Target/ELFTargetAsmInfo.h +++ b/include/llvm/Target/ELFTargetAsmInfo.h @@ -29,7 +29,7 @@ namespace llvm { /// specified size and relocation information, return a section that it /// should be placed in. virtual const Section * - getSectionForMergableConstant(uint64_t Size, unsigned ReloInfo) const; + getSectionForMergableConstant(SectionKind Kind) const; /// getFlagsForNamedSection - If this target wants to be able to infer /// section flags based on the name of the section specified for a global diff --git a/include/llvm/Target/TargetAsmInfo.h b/include/llvm/Target/TargetAsmInfo.h index c5bfc4d1ad9..93f2a76a2f5 100644 --- a/include/llvm/Target/TargetAsmInfo.h +++ b/include/llvm/Target/TargetAsmInfo.h @@ -710,8 +710,7 @@ namespace llvm { /// getSectionForMergableConstant - Given a mergable constant with the /// specified size and relocation information, return a section that it /// should be placed in. - virtual const Section * - getSectionForMergableConstant(uint64_t Size, unsigned ReloInfo) const; + virtual const Section *getSectionForMergableConstant(SectionKind Kind)const; /// getSectionPrefixForUniqueGlobal - Return a string that we should prepend diff --git a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 582acce0da3..e12a0f2f0e7 100644 --- a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -301,17 +301,28 @@ void AsmPrinter::EmitConstantPool(MachineConstantPool *MCP) { const std::vector &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 CPSections; for (unsigned i = 0, e = CP.size(); i != e; ++i) { const MachineConstantPoolEntry &CPE = CP[i]; unsigned Align = CPE.getAlignment(); - uint64_t Size = TD.getTypeAllocSize(CPE.getType()); - const Section *S = - TAI->getSectionForMergableConstant(Size, CPE.getRelocationInfo()); + + SectionKind Kind; + switch (CPE.getRelocationInfo()) { + default: llvm_unreachable("Unknown section kind"); + case 2: Kind = SectionKind::getReadOnlyWithRel(); break; + case 1: Kind = SectionKind::getReadOnlyWithRelLocal(); break; + case 0: + switch (TM.getTargetData()->getTypeAllocSize(CPE.getType())) { + case 4: Kind = SectionKind::getMergableConst4(); break; + case 8: Kind = SectionKind::getMergableConst8(); break; + case 16: Kind = SectionKind::getMergableConst16(); break; + default: Kind = SectionKind::getMergableConst(); break; + } + } + + const Section *S = TAI->getSectionForMergableConstant(Kind); // The number of sections are small, just do a linear search from the // last section to the first. diff --git a/lib/CodeGen/ELFWriter.cpp b/lib/CodeGen/ELFWriter.cpp index 45658e06127..47789c1ffe8 100644 --- a/lib/CodeGen/ELFWriter.cpp +++ b/lib/CodeGen/ELFWriter.cpp @@ -29,7 +29,6 @@ //===----------------------------------------------------------------------===// #define DEBUG_TYPE "elfwriter" - #include "ELF.h" #include "ELFWriter.h" #include "ELFCodeEmitter.h" @@ -155,10 +154,21 @@ 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()); + SectionKind Kind; + switch (CPE.getRelocationInfo()) { + default: llvm_unreachable("Unknown section kind"); + case 2: Kind = SectionKind::getReadOnlyWithRel(); break; + case 1: Kind = SectionKind::getReadOnlyWithRelLocal(); break; + case 0: + switch (TM.getTargetData()->getTypeAllocSize(CPE.getType())) { + case 4: Kind = SectionKind::getMergableConst4(); break; + case 8: Kind = SectionKind::getMergableConst8(); break; + case 16: Kind = SectionKind::getMergableConst16(); break; + default: Kind = SectionKind::getMergableConst(); break; + } + } - std::string CstPoolName = - TAI->getSectionForMergableConstant(Size,CPE.getRelocationInfo())->getName(); + std::string CstPoolName = TAI->getSectionForMergableConstant(Kind)->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 1804adf6a4c..778aa22e885 100644 --- a/lib/Target/DarwinTargetAsmInfo.cpp +++ b/lib/Target/DarwinTargetAsmInfo.cpp @@ -188,25 +188,18 @@ DarwinTargetAsmInfo::MergeableStringSection(const GlobalVariable *GV) const { } const Section * -DarwinTargetAsmInfo::getSectionForMergableConstant(uint64_t Size, - unsigned ReloInfo) const { +DarwinTargetAsmInfo::getSectionForMergableConstant(SectionKind Kind) const { // If this constant requires a relocation, we have to put it in the data // segment, not in the text segment. - if (ReloInfo != 0) + if (Kind.isDataRel()) return ConstDataSection; - switch (Size) { - default: break; - case 4: + if (Kind.isMergableConst4()) return FourByteConstantSection; - case 8: + if (Kind.isMergableConst8()) return EightByteConstantSection; - case 16: - if (SixteenByteConstantSection) - return SixteenByteConstantSection; - break; - } - + if (Kind.isMergableConst16() && SixteenByteConstantSection) + return SixteenByteConstantSection; return ReadOnlySection; // .const } diff --git a/lib/Target/ELFTargetAsmInfo.cpp b/lib/Target/ELFTargetAsmInfo.cpp index 82c993b685a..5d8d720cda0 100644 --- a/lib/Target/ELFTargetAsmInfo.cpp +++ b/lib/Target/ELFTargetAsmInfo.cpp @@ -92,21 +92,8 @@ ELFTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV, /// specified size and relocation information, return a section that it /// should be placed in. const Section * -ELFTargetAsmInfo::getSectionForMergableConstant(uint64_t Size, - unsigned ReloInfo) const { - // If this constant pool entry has relocations, stick it into a relocatable - // section. - if (ReloInfo == 2) - return DataRelROSection; - if (ReloInfo == 1) - return DataRelROLocalSection; - - switch (Size) { - default: return ReadOnlySection; // .rodata - case 4: return MergableConst4Section; - case 8: return MergableConst8Section; - case 16: return MergableConst16Section; - } +ELFTargetAsmInfo::getSectionForMergableConstant(SectionKind Kind) const { + return SelectSectionForGlobal(0, Kind); } /// getFlagsForNamedSection - If this target wants to be able to infer diff --git a/lib/Target/TargetAsmInfo.cpp b/lib/Target/TargetAsmInfo.cpp index c68f04b2bca..7abfcf9a623 100644 --- a/lib/Target/TargetAsmInfo.cpp +++ b/lib/Target/TargetAsmInfo.cpp @@ -372,9 +372,8 @@ TargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV, /// specified size and relocation information, return a section that it /// should be placed in. const Section * -TargetAsmInfo::getSectionForMergableConstant(uint64_t Size, - unsigned ReloInfo) const { - if (ReloInfo == 0) +TargetAsmInfo::getSectionForMergableConstant(SectionKind Kind) const { + if (Kind.isReadOnly()) if (const Section *S = getReadOnlySection()) return S;