diff options
author | Chris Lattner <sabre@nondot.org> | 2009-08-04 05:35:56 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-08-04 05:35:56 +0000 |
commit | 3b24c0172069a2546cd095e4b91f8b88c1ea0722 (patch) | |
tree | 3604ba3eb4d0677a31f20d5e7dda389e009916b8 /lib/Target/TargetLoweringObjectFile.cpp | |
parent | 37442b77d83e7a35a8cb704c2dc704834090fb4b (diff) |
make MergeableCString be a SectionKind "abstract class", and
add new concrete versions for 1/2/4-byte mergable strings.
These are not actually created yet.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78055 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/TargetLoweringObjectFile.cpp')
-rw-r--r-- | lib/Target/TargetLoweringObjectFile.cpp | 48 |
1 files changed, 35 insertions, 13 deletions
diff --git a/lib/Target/TargetLoweringObjectFile.cpp b/lib/Target/TargetLoweringObjectFile.cpp index ab4e24fea6..f2c7988a08 100644 --- a/lib/Target/TargetLoweringObjectFile.cpp +++ b/lib/Target/TargetLoweringObjectFile.cpp @@ -135,8 +135,10 @@ static SectionKind SectionKindForGlobal(const GlobalValue *GV, // If initializer is a null-terminated string, put it in a "cstring" // section if the target has it. if (isConstantString(C)) - return SectionKind::getMergeableCString(); + return SectionKind::getMergeable1ByteCString(); + // FIXME: Detect 2/4 byte strings. + // 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. @@ -290,8 +292,10 @@ void TargetLoweringObjectFileELF::Initialize(MCContext &Ctx, getOrCreateSection("\t.rodata", false, SectionKind::getReadOnly()); TLSDataSection = getOrCreateSection("\t.tdata", false, SectionKind::getThreadData()); + + // FIXME: No reason to make this. CStringSection = getOrCreateSection("\t.rodata.str", true, - SectionKind::getMergeableCString()); + SectionKind::getMergeable1ByteCString()); TLSBSSSection = getOrCreateSection("\t.tbss", false, SectionKind::getThreadBSS()); @@ -392,12 +396,16 @@ getSectionFlagsAsString(SectionKind Kind, SmallVectorImpl<char> &Str) const { Str.push_back('x'); if (Kind.isWriteable()) Str.push_back('w'); - if (Kind.isMergeableCString() || + if (Kind.isMergeable1ByteCString() || + Kind.isMergeable2ByteCString() || + Kind.isMergeable4ByteCString() || Kind.isMergeableConst4() || Kind.isMergeableConst8() || Kind.isMergeableConst16()) Str.push_back('M'); - if (Kind.isMergeableCString()) + if (Kind.isMergeable1ByteCString() || + Kind.isMergeable2ByteCString() || + Kind.isMergeable4ByteCString()) Str.push_back('S'); if (Kind.isThreadLocal()) Str.push_back('T'); @@ -419,11 +427,15 @@ getSectionFlagsAsString(SectionKind Kind, SmallVectorImpl<char> &Str) const { Str.append(KindStr, KindStr+strlen(KindStr)); - if (Kind.isMergeableCString()) { - // TODO: Eventually handle multiple byte character strings. For now, all - // mergable C strings are single byte. + if (Kind.isMergeable1ByteCString()) { Str.push_back(','); Str.push_back('1'); + } else if (Kind.isMergeable2ByteCString()) { + Str.push_back(','); + Str.push_back('2'); + } else if (Kind.isMergeable4ByteCString()) { + Str.push_back(','); + Str.push_back('4'); } else if (Kind.isMergeableConst4()) { Str.push_back(','); Str.push_back('4'); @@ -469,7 +481,9 @@ SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, if (Kind.isText()) return TextSection; - if (Kind.isMergeableCString()) { + if (Kind.isMergeable1ByteCString() || + Kind.isMergeable2ByteCString() || + Kind.isMergeable4ByteCString()) { assert(CStringSection && "Should have string section prefix"); // We also need alignment here. @@ -478,9 +492,17 @@ SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, unsigned Align = TM.getTargetData()->getPreferredAlignment(cast<GlobalVariable>(GV)); - std::string Name = CStringSection->getName() + "1." + utostr(Align); - return getOrCreateSection(Name.c_str(), false, - SectionKind::getMergeableCString()); + const char *SizeSpec = "1."; + if (Kind.isMergeable2ByteCString()) + SizeSpec = "2."; + else if (Kind.isMergeable4ByteCString()) + SizeSpec = "4."; + else + assert(Kind.isMergeable1ByteCString() && "unknown string width"); + + + std::string Name = CStringSection->getName() + SizeSpec + utostr(Align); + return getOrCreateSection(Name.c_str(), false, Kind); } if (Kind.isMergeableConst()) { @@ -549,7 +571,7 @@ void TargetLoweringObjectFileMachO::Initialize(MCContext &Ctx, SectionKind::getDataRel()); CStringSection = getOrCreateSection("\t.cstring", true, - SectionKind::getMergeableCString()); + SectionKind::getMergeable1ByteCString()); FourByteConstantSection = getOrCreateSection("\t.literal4\n", true, SectionKind::getMergeableConst4()); EightByteConstantSection = getOrCreateSection("\t.literal8\n", true, @@ -660,7 +682,7 @@ SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, } // FIXME: Alignment check should be handled by section classifier. - if (Kind.isMergeableCString()) { + if (Kind.isMergeable1ByteCString()) { Constant *C = cast<GlobalVariable>(GV)->getInitializer(); const Type *Ty = cast<ArrayType>(C->getType())->getElementType(); const TargetData &TD = *TM.getTargetData(); |