simplify getSectionForMergableConstant to take a SectionKind.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77134 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 582acce..e12a0f2 100644
--- a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -301,17 +301,28 @@
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) {
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 45658e0..47789c1 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 @@
// 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,