aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-07-26 06:11:33 +0000
committerChris Lattner <sabre@nondot.org>2009-07-26 06:11:33 +0000
commit2a7dd7d0637aa439195f82e7f2f4014a96ba93d1 (patch)
tree7e3781cf005482bc6daab4023dcc73d3387839f2 /lib
parent56acf5c9f629fa3fafe06097d056765784b1be2a (diff)
downloadexternal_llvm-2a7dd7d0637aa439195f82e7f2f4014a96ba93d1.zip
external_llvm-2a7dd7d0637aa439195f82e7f2f4014a96ba93d1.tar.gz
external_llvm-2a7dd7d0637aa439195f82e7f2f4014a96ba93d1.tar.bz2
introduce specialized mergable const sectionkinds for elements of size 4/8/16 to
simplify targets. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77132 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Target/DarwinTargetAsmInfo.cpp10
-rw-r--r--lib/Target/ELFTargetAsmInfo.cpp3
-rw-r--r--lib/Target/TargetAsmInfo.cpp18
3 files changed, 22 insertions, 9 deletions
diff --git a/lib/Target/DarwinTargetAsmInfo.cpp b/lib/Target/DarwinTargetAsmInfo.cpp
index 7321b18..1804adf 100644
--- a/lib/Target/DarwinTargetAsmInfo.cpp
+++ b/lib/Target/DarwinTargetAsmInfo.cpp
@@ -148,9 +148,13 @@ DarwinTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV,
return MergeableStringSection(cast<GlobalVariable>(GV));
if (Kind.isMergableConst()) {
- const Type *Ty = cast<GlobalVariable>(GV)->getInitializer()->getType();
- const TargetData *TD = TM.getTargetData();
- return getSectionForMergableConstant(TD->getTypeAllocSize(Ty), 0);
+ if (Kind.isMergableConst4())
+ return FourByteConstantSection;
+ if (Kind.isMergableConst8())
+ return EightByteConstantSection;
+ if (Kind.isMergableConst16() && SixteenByteConstantSection)
+ return SixteenByteConstantSection;
+ return ReadOnlySection; // .const
}
// FIXME: ROData -> const in -static mode that is relocatable but they happen
diff --git a/lib/Target/ELFTargetAsmInfo.cpp b/lib/Target/ELFTargetAsmInfo.cpp
index 2ba7b96..4631cda 100644
--- a/lib/Target/ELFTargetAsmInfo.cpp
+++ b/lib/Target/ELFTargetAsmInfo.cpp
@@ -52,6 +52,7 @@ ELFTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV,
if (Kind.isText()) return TextSection;
if (Kind.isMergableCString())
return MergeableStringSection(cast<GlobalVariable>(GV));
+
if (Kind.isMergableConst()) {
const Type *Ty = cast<GlobalVariable>(GV)->getInitializer()->getType();
const TargetData *TD = TM.getTargetData();
@@ -132,8 +133,6 @@ unsigned ELFTargetAsmInfo::getFlagsForNamedSection(const char *Name) const {
return Flags;
}
-
-
const char *
ELFTargetAsmInfo::getSectionPrefixForUniqueGlobal(SectionKind Kind) const{
if (Kind.isText()) return ".gnu.linkonce.t.";
diff --git a/lib/Target/TargetAsmInfo.cpp b/lib/Target/TargetAsmInfo.cpp
index 51042da..c68f04b 100644
--- a/lib/Target/TargetAsmInfo.cpp
+++ b/lib/Target/TargetAsmInfo.cpp
@@ -19,6 +19,7 @@
#include "llvm/Module.h"
#include "llvm/Type.h"
#include "llvm/Target/TargetAsmInfo.h"
+#include "llvm/Target/TargetData.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetOptions.h"
#include "llvm/Support/Dwarf.h"
@@ -217,7 +218,9 @@ static unsigned SectionFlagsForGlobal(const GlobalValue *GV,
}
static SectionKind SectionKindForGlobal(const GlobalValue *GV,
- Reloc::Model ReloModel) {
+ const TargetMachine &TM) {
+ Reloc::Model ReloModel = TM.getRelocationModel();
+
// Early exit - functions should be always in text sections.
const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV);
if (GVar == 0)
@@ -249,8 +252,15 @@ static SectionKind SectionKindForGlobal(const GlobalValue *GV,
if (isConstantString(C))
return SectionKind::getMergableCString();
- // Otherwise, just drop it into a mergable constant section.
- return SectionKind::getMergableConst();
+ // Otherwise, just drop it into a mergable constant section. If we have
+ // a section for this size, use it, otherwise use the arbitrary sized
+ // mergable section.
+ switch (TM.getTargetData()->getTypeAllocSize(C->getType())) {
+ case 4: return SectionKind::getMergableConst4();
+ case 8: return SectionKind::getMergableConst8();
+ case 16: return SectionKind::getMergableConst16();
+ default: return SectionKind::getMergableConst();
+ }
case Constant::LocalRelocation:
// In static relocation model, the linker will resolve all addresses, so
@@ -299,7 +309,7 @@ const Section *TargetAsmInfo::SectionForGlobal(const GlobalValue *GV) const {
assert(!GV->isDeclaration() && !GV->hasAvailableExternallyLinkage() &&
"Can only be used for global definitions");
- SectionKind Kind = SectionKindForGlobal(GV, TM.getRelocationModel());
+ SectionKind Kind = SectionKindForGlobal(GV, TM);
// Select section name.
if (GV->hasSection()) {