From 5a1c4b82830214504c9e8c4a7bc0492478035605 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Mon, 14 Jul 2014 22:06:29 +0000 Subject: [PATCH] CodeGen: Add a getSectionKind method to MachineConstantPoolEntry This is just a helper routine, no functionality has changed. llvm-svn: 212993 --- llvm/include/llvm/CodeGen/MachineConstantPool.h | 3 +++ llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 16 +------------ llvm/lib/CodeGen/MachineFunction.cpp | 31 +++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 15 deletions(-) diff --git a/llvm/include/llvm/CodeGen/MachineConstantPool.h b/llvm/include/llvm/CodeGen/MachineConstantPool.h index 912ce89..c619afb 100644 --- a/llvm/include/llvm/CodeGen/MachineConstantPool.h +++ b/llvm/include/llvm/CodeGen/MachineConstantPool.h @@ -17,6 +17,7 @@ #define LLVM_CODEGEN_MACHINECONSTANTPOOL_H #include "llvm/ADT/DenseSet.h" +#include "llvm/MC/SectionKind.h" #include #include #include @@ -119,6 +120,8 @@ public: /// them. /// 2: This entry may have arbitrary relocations. unsigned getRelocationInfo() const; + + SectionKind getSectionKind(const DataLayout *DL) const; }; /// The MachineConstantPool class keeps track of constants referenced by a diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index f80fdea..4c3e6aa 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -1062,21 +1062,7 @@ void AsmPrinter::EmitConstantPool() { const MachineConstantPoolEntry &CPE = CP[i]; unsigned Align = CPE.getAlignment(); - 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.getDataLayout()->getTypeAllocSize(CPE.getType())) { - case 4: Kind = SectionKind::getMergeableConst4(); break; - case 8: Kind = SectionKind::getMergeableConst8(); break; - case 16: Kind = SectionKind::getMergeableConst16();break; - default: Kind = SectionKind::getMergeableConst(); break; - } - } + SectionKind Kind = CPE.getSectionKind(TM.getDataLayout()); const MCSection *S = getObjFileLowering().getSectionForConstant(Kind); diff --git a/llvm/lib/CodeGen/MachineFunction.cpp b/llvm/lib/CodeGen/MachineFunction.cpp index 6138aef..7e9b755 100644 --- a/llvm/lib/CodeGen/MachineFunction.cpp +++ b/llvm/lib/CodeGen/MachineFunction.cpp @@ -836,6 +836,37 @@ unsigned MachineConstantPoolEntry::getRelocationInfo() const { return Val.ConstVal->getRelocationInfo(); } +SectionKind +MachineConstantPoolEntry::getSectionKind(const DataLayout *DL) const { + SectionKind Kind; + switch (getRelocationInfo()) { + default: + llvm_unreachable("Unknown section kind"); + case 2: + Kind = SectionKind::getReadOnlyWithRel(); + break; + case 1: + Kind = SectionKind::getReadOnlyWithRelLocal(); + break; + case 0: + switch (DL->getTypeAllocSize(getType())) { + case 4: + Kind = SectionKind::getMergeableConst4(); + break; + case 8: + Kind = SectionKind::getMergeableConst8(); + break; + case 16: + Kind = SectionKind::getMergeableConst16(); + break; + default: + Kind = SectionKind::getMergeableConst(); + break; + } + } + return Kind; +} + MachineConstantPool::~MachineConstantPool() { for (unsigned i = 0, e = Constants.size(); i != e; ++i) if (Constants[i].isMachineConstantPoolEntry()) -- 2.7.4