[llvm-commits] [llvm] r76949 - /llvm/trunk/lib/Target/ELFTargetAsmInfo.cpp

Chris Lattner sabre at nondot.org
Thu Jul 23 21:52:39 PDT 2009


Author: lattner
Date: Thu Jul 23 23:52:38 2009
New Revision: 76949

URL: http://llvm.org/viewvc/llvm-project?rev=76949&view=rev
Log:
the 'isWeakForLinker' code is common between functions and globals, hoist it
and simplify some other code.

Modified:
    llvm/trunk/lib/Target/ELFTargetAsmInfo.cpp

Modified: llvm/trunk/lib/Target/ELFTargetAsmInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ELFTargetAsmInfo.cpp?rev=76949&r1=76948&r2=76949&view=diff

==============================================================================
--- llvm/trunk/lib/Target/ELFTargetAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/ELFTargetAsmInfo.cpp Thu Jul 23 23:52:38 2009
@@ -77,65 +77,54 @@
 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<Function>(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<GlobalVariable>(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<GlobalVariable>(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





More information about the llvm-commits mailing list