From 33ae7a453bcb32c4ed4e8202743a4b6c875cbe73 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 27 Jul 2009 16:27:32 +0000 Subject: [PATCH] inline a method. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77198 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Target/ELFTargetAsmInfo.h | 7 +--- lib/Target/ELFTargetAsmInfo.cpp | 52 ++++++++++++-------------- 2 files changed, 25 insertions(+), 34 deletions(-) diff --git a/include/llvm/Target/ELFTargetAsmInfo.h b/include/llvm/Target/ELFTargetAsmInfo.h index 8d25d5b6e59..1f7a21e30fe 100644 --- a/include/llvm/Target/ELFTargetAsmInfo.h +++ b/include/llvm/Target/ELFTargetAsmInfo.h @@ -19,10 +19,8 @@ namespace llvm { class GlobalValue; - class GlobalVariable; - class Type; - struct ELFTargetAsmInfo: public TargetAsmInfo { + struct ELFTargetAsmInfo : public TargetAsmInfo { ELFTargetAsmInfo(const TargetMachine &TM); /// getSectionForMergeableConstant - Given a mergeable constant with the @@ -49,9 +47,6 @@ namespace llvm { const Section *MergeableConst4Section; const Section *MergeableConst8Section; const Section *MergeableConst16Section; - - private: - const Section *MergeableStringSection(const GlobalVariable *GV) const; }; } diff --git a/lib/Target/ELFTargetAsmInfo.cpp b/lib/Target/ELFTargetAsmInfo.cpp index 391e348ba21..dbb2ce30ca0 100644 --- a/lib/Target/ELFTargetAsmInfo.cpp +++ b/lib/Target/ELFTargetAsmInfo.cpp @@ -58,8 +58,30 @@ const Section* ELFTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind) const { if (Kind.isText()) return TextSection; - if (Kind.isMergeableCString()) - return MergeableStringSection(cast(GV)); + if (Kind.isMergeableCString()) { + const TargetData *TD = TM.getTargetData(); + Constant *C = cast(GV)->getInitializer(); + const Type *Ty = cast(C->getType())->getElementType(); + + unsigned Size = TD->getTypeAllocSize(Ty); + if (Size <= 16) { + assert(getCStringSection() && "Should have string section prefix"); + + // We also need alignment here. + // FIXME: this is getting the alignment of the character, not the + // alignment of the string!! + unsigned Align = TD->getPrefTypeAlignment(Ty); + if (Align < Size) + Align = Size; + + std::string Name = getCStringSection() + utostr(Size) + '.' + + utostr(Align); + return getOrCreateSection(Name.c_str(), false, + SectionKind::MergeableCString); + } + + return getReadOnlySection(); + } if (Kind.isMergeableConst()) { if (Kind.isMergeableConst4()) @@ -145,32 +167,6 @@ ELFTargetAsmInfo::getSectionPrefixForUniqueGlobal(SectionKind Kind) const{ } - -const Section* -ELFTargetAsmInfo::MergeableStringSection(const GlobalVariable *GV) const { - const TargetData *TD = TM.getTargetData(); - Constant *C = cast(GV)->getInitializer(); - const Type *Ty = cast(C->getType())->getElementType(); - - unsigned Size = TD->getTypeAllocSize(Ty); - if (Size <= 16) { - assert(getCStringSection() && "Should have string section prefix"); - - // We also need alignment here. - // FIXME: this is getting the alignment of the character, not the alignment - // of the string!! - unsigned Align = TD->getPrefTypeAlignment(Ty); - if (Align < Size) - Align = Size; - - std::string Name = getCStringSection() + utostr(Size) + '.' + utostr(Align); - return getOrCreateSection(Name.c_str(), false, - SectionKind::MergeableCString); - } - - return getReadOnlySection(); -} - void ELFTargetAsmInfo::getSectionFlagsAsString(SectionKind Kind, SmallVectorImpl &Str) const { Str.push_back(',');