summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-08-04 16:27:13 +0000
committerChris Lattner <sabre@nondot.org>2009-08-04 16:27:13 +0000
commitec409759e94cc395e4896ba6ade3fa77200c5cfd (patch)
tree3c6716c04a076c6d27d0cb82698c844703859ba0
parent7e88a50428377813606c66ac47111d9c3ea44feb (diff)
downloadllvm-ec409759e94cc395e4896ba6ade3fa77200c5cfd.tar.gz
llvm-ec409759e94cc395e4896ba6ade3fa77200c5cfd.tar.bz2
llvm-ec409759e94cc395e4896ba6ade3fa77200c5cfd.tar.xz
enhance codegen to put 16-bit character strings into the
__TEXT,__ustring section on darwin. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78068 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/Target/TargetLoweringObjectFile.h1
-rw-r--r--lib/Target/TargetLoweringObjectFile.cpp32
-rw-r--r--test/CodeGen/X86/global-sections.ll4
3 files changed, 18 insertions, 19 deletions
diff --git a/include/llvm/Target/TargetLoweringObjectFile.h b/include/llvm/Target/TargetLoweringObjectFile.h
index 3715a6585a..10ce48158a 100644
--- a/include/llvm/Target/TargetLoweringObjectFile.h
+++ b/include/llvm/Target/TargetLoweringObjectFile.h
@@ -224,6 +224,7 @@ public:
class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile {
const MCSection *CStringSection;
+ const MCSection *UStringSection;
const MCSection *TextCoalSection;
const MCSection *ConstTextCoalSection;
const MCSection *ConstDataCoalSection;
diff --git a/lib/Target/TargetLoweringObjectFile.cpp b/lib/Target/TargetLoweringObjectFile.cpp
index 730d32f542..7489883998 100644
--- a/lib/Target/TargetLoweringObjectFile.cpp
+++ b/lib/Target/TargetLoweringObjectFile.cpp
@@ -593,11 +593,13 @@ void TargetLoweringObjectFileMachO::Initialize(MCContext &Ctx,
SectionKind::getDataRel());
CStringSection = getOrCreateSection("\t.cstring", true,
- SectionKind::getMergeable1ByteCString());
+ SectionKind::getMergeable1ByteCString());
+ UStringSection = getOrCreateSection("__TEXT,__ustring", false,
+ SectionKind::getMergeable2ByteCString());
FourByteConstantSection = getOrCreateSection("\t.literal4\n", true,
- SectionKind::getMergeableConst4());
+ SectionKind::getMergeableConst4());
EightByteConstantSection = getOrCreateSection("\t.literal8\n", true,
- SectionKind::getMergeableConst8());
+ SectionKind::getMergeableConst8());
// ld_classic doesn't support .literal16 in 32-bit mode, and ld64 falls back
// to using it in -static mode.
@@ -704,18 +706,15 @@ SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
}
// FIXME: Alignment check should be handled by section classifier.
- if (Kind.isMergeable1ByteCString()) {
- Constant *C = cast<GlobalVariable>(GV)->getInitializer();
- const Type *Ty = cast<ArrayType>(C->getType())->getElementType();
- const TargetData &TD = *TM.getTargetData();
- unsigned Size = TD.getTypeAllocSize(Ty);
- if (Size) {
- unsigned Align = TD.getPreferredAlignment(cast<GlobalVariable>(GV));
- if (Align <= 32)
+ if (Kind.isMergeable1ByteCString() ||
+ Kind.isMergeable2ByteCString()) {
+ if (TM.getTargetData()->getPreferredAlignment(
+ cast<GlobalVariable>(GV)) < 32) {
+ if (Kind.isMergeable1ByteCString())
return CStringSection;
+ assert(Kind.isMergeable2ByteCString());
+ return UStringSection;
}
-
- return ReadOnlySection;
}
if (Kind.isMergeableConst()) {
@@ -725,11 +724,10 @@ SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
return EightByteConstantSection;
if (Kind.isMergeableConst16() && SixteenByteConstantSection)
return SixteenByteConstantSection;
- return ReadOnlySection; // .const
}
-
- // FIXME: ROData -> const in -static mode that is relocatable but they happen
- // by the static linker. Why not mergeable?
+
+ // Otherwise, if it is readonly, but not something we can specially optimize,
+ // just drop it in .const.
if (Kind.isReadOnly())
return ReadOnlySection;
diff --git a/test/CodeGen/X86/global-sections.ll b/test/CodeGen/X86/global-sections.ll
index 4f4c4bcf1c..7d39a02095 100644
--- a/test/CodeGen/X86/global-sections.ll
+++ b/test/CodeGen/X86/global-sections.ll
@@ -101,7 +101,7 @@
@G8 = constant [4 x i16] [ i16 1, i16 2, i16 3, i16 0 ]
-; DARWIN: .const
+; DARWIN: .section __TEXT,__ustring
; DARWIN: .globl _G8
; DARWIN: _G8:
@@ -111,7 +111,7 @@
@G9 = constant [4 x i32] [ i32 1, i32 2, i32 3, i32 0 ]
-; ARWIN: .const [[ already in const section]]
+; DARWIN: .const
; DARWIN: .globl _G9
; DARWIN: _G9: