mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-30 19:35:54 +00:00
simplify getSectionForMergableConstant to take a SectionKind.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77134 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
f15327290e
commit
5c2f789952
@ -40,8 +40,7 @@ namespace llvm {
|
|||||||
Mangler *Mang) const;
|
Mangler *Mang) const;
|
||||||
|
|
||||||
|
|
||||||
virtual const Section *
|
virtual const Section *getSectionForMergableConstant(SectionKind Kind)const;
|
||||||
getSectionForMergableConstant(uint64_t Size, unsigned ReloInfo) const;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const Section* MergeableStringSection(const GlobalVariable *GV) const;
|
const Section* MergeableStringSection(const GlobalVariable *GV) const;
|
||||||
|
@ -29,7 +29,7 @@ namespace llvm {
|
|||||||
/// specified size and relocation information, return a section that it
|
/// specified size and relocation information, return a section that it
|
||||||
/// should be placed in.
|
/// should be placed in.
|
||||||
virtual const Section *
|
virtual const Section *
|
||||||
getSectionForMergableConstant(uint64_t Size, unsigned ReloInfo) const;
|
getSectionForMergableConstant(SectionKind Kind) const;
|
||||||
|
|
||||||
/// getFlagsForNamedSection - If this target wants to be able to infer
|
/// getFlagsForNamedSection - If this target wants to be able to infer
|
||||||
/// section flags based on the name of the section specified for a global
|
/// section flags based on the name of the section specified for a global
|
||||||
|
@ -710,8 +710,7 @@ namespace llvm {
|
|||||||
/// getSectionForMergableConstant - Given a mergable constant with the
|
/// getSectionForMergableConstant - Given a mergable constant with the
|
||||||
/// specified size and relocation information, return a section that it
|
/// specified size and relocation information, return a section that it
|
||||||
/// should be placed in.
|
/// should be placed in.
|
||||||
virtual const Section *
|
virtual const Section *getSectionForMergableConstant(SectionKind Kind)const;
|
||||||
getSectionForMergableConstant(uint64_t Size, unsigned ReloInfo) const;
|
|
||||||
|
|
||||||
|
|
||||||
/// getSectionPrefixForUniqueGlobal - Return a string that we should prepend
|
/// getSectionPrefixForUniqueGlobal - Return a string that we should prepend
|
||||||
|
@ -301,17 +301,28 @@ void AsmPrinter::EmitConstantPool(MachineConstantPool *MCP) {
|
|||||||
const std::vector<MachineConstantPoolEntry> &CP = MCP->getConstants();
|
const std::vector<MachineConstantPoolEntry> &CP = MCP->getConstants();
|
||||||
if (CP.empty()) return;
|
if (CP.empty()) return;
|
||||||
|
|
||||||
const TargetData &TD = *TM.getTargetData();
|
|
||||||
|
|
||||||
// Calculate sections for constant pool entries. We collect entries to go into
|
// Calculate sections for constant pool entries. We collect entries to go into
|
||||||
// the same section together to reduce amount of section switch statements.
|
// the same section together to reduce amount of section switch statements.
|
||||||
SmallVector<SectionCPs, 4> CPSections;
|
SmallVector<SectionCPs, 4> CPSections;
|
||||||
for (unsigned i = 0, e = CP.size(); i != e; ++i) {
|
for (unsigned i = 0, e = CP.size(); i != e; ++i) {
|
||||||
const MachineConstantPoolEntry &CPE = CP[i];
|
const MachineConstantPoolEntry &CPE = CP[i];
|
||||||
unsigned Align = CPE.getAlignment();
|
unsigned Align = CPE.getAlignment();
|
||||||
uint64_t Size = TD.getTypeAllocSize(CPE.getType());
|
|
||||||
const Section *S =
|
SectionKind Kind;
|
||||||
TAI->getSectionForMergableConstant(Size, CPE.getRelocationInfo());
|
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
|
// The number of sections are small, just do a linear search from the
|
||||||
// last section to the first.
|
// last section to the first.
|
||||||
|
@ -29,7 +29,6 @@
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#define DEBUG_TYPE "elfwriter"
|
#define DEBUG_TYPE "elfwriter"
|
||||||
|
|
||||||
#include "ELF.h"
|
#include "ELF.h"
|
||||||
#include "ELFWriter.h"
|
#include "ELFWriter.h"
|
||||||
#include "ELFCodeEmitter.h"
|
#include "ELFCodeEmitter.h"
|
||||||
@ -155,10 +154,21 @@ ELFSection &ELFWriter::getJumpTableSection() {
|
|||||||
|
|
||||||
// Get a constant pool section based on the section name returned by TAI
|
// Get a constant pool section based on the section name returned by TAI
|
||||||
ELFSection &ELFWriter::getConstantPoolSection(MachineConstantPoolEntry &CPE) {
|
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 =
|
std::string CstPoolName = TAI->getSectionForMergableConstant(Kind)->getName();
|
||||||
TAI->getSectionForMergableConstant(Size,CPE.getRelocationInfo())->getName();
|
|
||||||
return getSection(CstPoolName,
|
return getSection(CstPoolName,
|
||||||
ELFSection::SHT_PROGBITS,
|
ELFSection::SHT_PROGBITS,
|
||||||
ELFSection::SHF_MERGE | ELFSection::SHF_ALLOC,
|
ELFSection::SHF_MERGE | ELFSection::SHF_ALLOC,
|
||||||
|
@ -188,25 +188,18 @@ DarwinTargetAsmInfo::MergeableStringSection(const GlobalVariable *GV) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const Section *
|
const Section *
|
||||||
DarwinTargetAsmInfo::getSectionForMergableConstant(uint64_t Size,
|
DarwinTargetAsmInfo::getSectionForMergableConstant(SectionKind Kind) const {
|
||||||
unsigned ReloInfo) const {
|
|
||||||
// If this constant requires a relocation, we have to put it in the data
|
// If this constant requires a relocation, we have to put it in the data
|
||||||
// segment, not in the text segment.
|
// segment, not in the text segment.
|
||||||
if (ReloInfo != 0)
|
if (Kind.isDataRel())
|
||||||
return ConstDataSection;
|
return ConstDataSection;
|
||||||
|
|
||||||
switch (Size) {
|
if (Kind.isMergableConst4())
|
||||||
default: break;
|
|
||||||
case 4:
|
|
||||||
return FourByteConstantSection;
|
return FourByteConstantSection;
|
||||||
case 8:
|
if (Kind.isMergableConst8())
|
||||||
return EightByteConstantSection;
|
return EightByteConstantSection;
|
||||||
case 16:
|
if (Kind.isMergableConst16() && SixteenByteConstantSection)
|
||||||
if (SixteenByteConstantSection)
|
|
||||||
return SixteenByteConstantSection;
|
return SixteenByteConstantSection;
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ReadOnlySection; // .const
|
return ReadOnlySection; // .const
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,21 +92,8 @@ ELFTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV,
|
|||||||
/// specified size and relocation information, return a section that it
|
/// specified size and relocation information, return a section that it
|
||||||
/// should be placed in.
|
/// should be placed in.
|
||||||
const Section *
|
const Section *
|
||||||
ELFTargetAsmInfo::getSectionForMergableConstant(uint64_t Size,
|
ELFTargetAsmInfo::getSectionForMergableConstant(SectionKind Kind) const {
|
||||||
unsigned ReloInfo) const {
|
return SelectSectionForGlobal(0, Kind);
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// getFlagsForNamedSection - If this target wants to be able to infer
|
/// getFlagsForNamedSection - If this target wants to be able to infer
|
||||||
|
@ -372,9 +372,8 @@ TargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV,
|
|||||||
/// specified size and relocation information, return a section that it
|
/// specified size and relocation information, return a section that it
|
||||||
/// should be placed in.
|
/// should be placed in.
|
||||||
const Section *
|
const Section *
|
||||||
TargetAsmInfo::getSectionForMergableConstant(uint64_t Size,
|
TargetAsmInfo::getSectionForMergableConstant(SectionKind Kind) const {
|
||||||
unsigned ReloInfo) const {
|
if (Kind.isReadOnly())
|
||||||
if (ReloInfo == 0)
|
|
||||||
if (const Section *S = getReadOnlySection())
|
if (const Section *S = getReadOnlySection())
|
||||||
return S;
|
return S;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user