From ab0c0ef5158e868befbd32612ab317a85789901d Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 24 Jul 2009 04:52:38 +0000 Subject: [PATCH] the 'isWeakForLinker' code is common between functions and globals, hoist it and simplify some other code. llvm-svn: 76949 --- llvm/lib/Target/ELFTargetAsmInfo.cpp | 99 ++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 55 deletions(-) diff --git a/llvm/lib/Target/ELFTargetAsmInfo.cpp b/llvm/lib/Target/ELFTargetAsmInfo.cpp index 735adce..872b472 100644 --- a/llvm/lib/Target/ELFTargetAsmInfo.cpp +++ b/llvm/lib/Target/ELFTargetAsmInfo.cpp @@ -77,65 +77,54 @@ const Section* ELFTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const { SectionKind::Kind Kind = SectionKindForGlobal(GV); + if (GV->isWeakForLinker()) { + // FIXME: Use mangler interface (PR4584). + std::string Name = getSectionPrefixForUniqueGlobal(Kind)+GV->getName(); + unsigned Flags = SectionFlagsForGlobal(GV, Name.c_str()); + return getNamedSection(Name.c_str(), Flags); + } + if (const Function *F = dyn_cast(GV)) { switch (F->getLinkage()) { - default: llvm_unreachable("Unknown linkage type!"); - case Function::PrivateLinkage: - case Function::LinkerPrivateLinkage: - case Function::InternalLinkage: - case Function::DLLExportLinkage: - case Function::ExternalLinkage: - return TextSection; - case Function::WeakAnyLinkage: - case Function::WeakODRLinkage: - case Function::LinkOnceAnyLinkage: - case Function::LinkOnceODRLinkage: - // FIXME: Use mangler interface (PR4584). - std::string Name = getSectionPrefixForUniqueGlobal(Kind)+GV->getName(); - unsigned Flags = SectionFlagsForGlobal(GV, Name.c_str()); - return getNamedSection(Name.c_str(), Flags); + default: llvm_unreachable("Unknown linkage type!"); + case Function::PrivateLinkage: + case Function::LinkerPrivateLinkage: + case Function::InternalLinkage: + case Function::DLLExportLinkage: + case Function::ExternalLinkage: + return TextSection; } - } else if (const GlobalVariable *GVar = dyn_cast(GV)) { - if (GVar->isWeakForLinker()) { - // FIXME: Use mangler interface (PR4584). - std::string Name = getSectionPrefixForUniqueGlobal(Kind)+GV->getName(); - unsigned Flags = SectionFlagsForGlobal(GVar, Name.c_str()); - return getNamedSection(Name.c_str(), Flags); - } else { - switch (Kind) { - case SectionKind::Data: - case SectionKind::DataRel: - return DataRelSection; - case SectionKind::DataRelLocal: - return DataRelLocalSection; - case SectionKind::DataRelRO: - return DataRelROSection; - case SectionKind::DataRelROLocal: - return DataRelROLocalSection; - case SectionKind::BSS: - return getBSSSection_(); - case SectionKind::ROData: - return getReadOnlySection(); - case SectionKind::RODataMergeStr: - return MergeableStringSection(GVar); - case SectionKind::RODataMergeConst: { - const Type *Ty = GVar->getInitializer()->getType(); - const TargetData *TD = TM.getTargetData(); - return getSectionForMergableConstant(TD->getTypeAllocSize(Ty), 0); - } - case SectionKind::ThreadData: - // ELF targets usually support TLS stuff - return TLSDataSection; - case SectionKind::ThreadBSS: - return TLSBSSSection; - default: - llvm_unreachable("Unsuported section kind for global"); - } + } else { + const GlobalVariable *GVar = cast(GV); + switch (Kind) { + default: llvm_unreachable("Unsuported section kind for global"); + case SectionKind::Data: + case SectionKind::DataRel: + return DataRelSection; + case SectionKind::DataRelLocal: + return DataRelLocalSection; + case SectionKind::DataRelRO: + return DataRelROSection; + case SectionKind::DataRelROLocal: + return DataRelROLocalSection; + case SectionKind::BSS: + return getBSSSection_(); + case SectionKind::ROData: + return getReadOnlySection(); + case SectionKind::RODataMergeStr: + return MergeableStringSection(GVar); + case SectionKind::RODataMergeConst: { + const Type *Ty = GVar->getInitializer()->getType(); + const TargetData *TD = TM.getTargetData(); + return getSectionForMergableConstant(TD->getTypeAllocSize(Ty), 0); } - } else - llvm_unreachable("Unsupported global"); - - return NULL; + case SectionKind::ThreadData: + // ELF targets usually support TLS stuff + return TLSDataSection; + case SectionKind::ThreadBSS: + return TLSBSSSection; + } + } } /// getSectionForMergableConstant - Given a mergable constant with the -- 2.7.4