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
This commit is contained in:
Chris Lattner
2009-08-04 16:27:13 +00:00
parent 7e88a50428
commit ec409759e9
3 changed files with 18 additions and 19 deletions

View File

@@ -224,6 +224,7 @@ public:
class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile { class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile {
const MCSection *CStringSection; const MCSection *CStringSection;
const MCSection *UStringSection;
const MCSection *TextCoalSection; const MCSection *TextCoalSection;
const MCSection *ConstTextCoalSection; const MCSection *ConstTextCoalSection;
const MCSection *ConstDataCoalSection; const MCSection *ConstDataCoalSection;

View File

@@ -594,6 +594,8 @@ void TargetLoweringObjectFileMachO::Initialize(MCContext &Ctx,
CStringSection = getOrCreateSection("\t.cstring", true, CStringSection = getOrCreateSection("\t.cstring", true,
SectionKind::getMergeable1ByteCString()); SectionKind::getMergeable1ByteCString());
UStringSection = getOrCreateSection("__TEXT,__ustring", false,
SectionKind::getMergeable2ByteCString());
FourByteConstantSection = getOrCreateSection("\t.literal4\n", true, FourByteConstantSection = getOrCreateSection("\t.literal4\n", true,
SectionKind::getMergeableConst4()); SectionKind::getMergeableConst4());
EightByteConstantSection = getOrCreateSection("\t.literal8\n", true, EightByteConstantSection = getOrCreateSection("\t.literal8\n", true,
@@ -704,18 +706,15 @@ SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
} }
// FIXME: Alignment check should be handled by section classifier. // FIXME: Alignment check should be handled by section classifier.
if (Kind.isMergeable1ByteCString()) { if (Kind.isMergeable1ByteCString() ||
Constant *C = cast<GlobalVariable>(GV)->getInitializer(); Kind.isMergeable2ByteCString()) {
const Type *Ty = cast<ArrayType>(C->getType())->getElementType(); if (TM.getTargetData()->getPreferredAlignment(
const TargetData &TD = *TM.getTargetData(); cast<GlobalVariable>(GV)) < 32) {
unsigned Size = TD.getTypeAllocSize(Ty); if (Kind.isMergeable1ByteCString())
if (Size) {
unsigned Align = TD.getPreferredAlignment(cast<GlobalVariable>(GV));
if (Align <= 32)
return CStringSection; return CStringSection;
assert(Kind.isMergeable2ByteCString());
return UStringSection;
} }
return ReadOnlySection;
} }
if (Kind.isMergeableConst()) { if (Kind.isMergeableConst()) {
@@ -725,11 +724,10 @@ SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
return EightByteConstantSection; return EightByteConstantSection;
if (Kind.isMergeableConst16() && SixteenByteConstantSection) if (Kind.isMergeableConst16() && SixteenByteConstantSection)
return SixteenByteConstantSection; return SixteenByteConstantSection;
return ReadOnlySection; // .const
} }
// FIXME: ROData -> const in -static mode that is relocatable but they happen // Otherwise, if it is readonly, but not something we can specially optimize,
// by the static linker. Why not mergeable? // just drop it in .const.
if (Kind.isReadOnly()) if (Kind.isReadOnly())
return ReadOnlySection; return ReadOnlySection;

View File

@@ -101,7 +101,7 @@
@G8 = constant [4 x i16] [ i16 1, i16 2, i16 3, i16 0 ] @G8 = constant [4 x i16] [ i16 1, i16 2, i16 3, i16 0 ]
; DARWIN: .const ; DARWIN: .section __TEXT,__ustring
; DARWIN: .globl _G8 ; DARWIN: .globl _G8
; DARWIN: _G8: ; DARWIN: _G8:
@@ -111,7 +111,7 @@
@G9 = constant [4 x i32] [ i32 1, i32 2, i32 3, i32 0 ] @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: .globl _G9
; DARWIN: _G9: ; DARWIN: _G9: