[llvm-commits] [llvm] r53305 - in /llvm/trunk/lib/Target: TargetAsmInfo.cpp X86/X86TargetAsmInfo.cpp X86/X86TargetAsmInfo.h

Anton Korobeynikov asl at math.spbu.ru
Wed Jul 9 06:23:08 PDT 2008


Author: asl
Date: Wed Jul  9 08:23:08 2008
New Revision: 53305

URL: http://llvm.org/viewvc/llvm-project?rev=53305&view=rev
Log:
Provide section selection for X86 ELF targets

Modified:
    llvm/trunk/lib/Target/TargetAsmInfo.cpp
    llvm/trunk/lib/Target/X86/X86TargetAsmInfo.cpp
    llvm/trunk/lib/Target/X86/X86TargetAsmInfo.h

Modified: llvm/trunk/lib/Target/TargetAsmInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/TargetAsmInfo.cpp?rev=53305&r1=53304&r2=53305&view=diff

==============================================================================
--- llvm/trunk/lib/Target/TargetAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/TargetAsmInfo.cpp Wed Jul  9 08:23:08 2008
@@ -261,6 +261,9 @@
 
   std::string Name;
 
+  // FIXME: Should we use some hashing based on section name and just check
+  // flags?
+
   // Select section name
   if (GV->hasSection()) {
     // Honour section already set, if any

Modified: llvm/trunk/lib/Target/X86/X86TargetAsmInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86TargetAsmInfo.cpp?rev=53305&r1=53304&r2=53305&view=diff

==============================================================================
--- llvm/trunk/lib/Target/X86/X86TargetAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86TargetAsmInfo.cpp Wed Jul  9 08:23:08 2008
@@ -313,6 +313,51 @@
   }
 }
 
+std::string
+X86ELFTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
+  SectionKind::Kind kind = SectionKindForGlobal(GV);
+
+  if (const Function *F = dyn_cast<Function>(GV)) {
+    switch (F->getLinkage()) {
+     default: assert(0 && "Unknown linkage type!");
+     case Function::InternalLinkage:
+     case Function::DLLExportLinkage:
+     case Function::ExternalLinkage:
+      return getTextSection();
+     case Function::WeakLinkage:
+     case Function::LinkOnceLinkage:
+      return UniqueSectionForGlobal(F, kind);
+    }
+  } else if (const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV)) {
+    if (GVar->hasCommonLinkage() ||
+        GVar->hasLinkOnceLinkage() ||
+        GVar->hasWeakLinkage())
+      return UniqueSectionForGlobal(GVar, kind);
+    else {
+      switch (kind) {
+       case SectionKind::Data:
+        return getDataSection();
+       case SectionKind::BSS:
+        // ELF targets usually have BSS sections
+        return getBSSSection();
+       case SectionKind::ROData:
+       case SectionKind::RODataMergeStr:
+       case SectionKind::RODataMergeConst:
+        // FIXME: Temporary
+        return getReadOnlySection();
+       case SectionKind::ThreadData:
+        // ELF targets usually support TLS stuff
+        return getTLSDataSection();
+       case SectionKind::ThreadBSS:
+        return getTLSBSSSection();
+       default:
+        assert(0 && "Unsuported section kind for global");
+      }
+    }
+  } else
+    assert(0 && "Unsupported global");
+}
+
 std::string X86ELFTargetAsmInfo::PrintSectionFlags(unsigned flags) const {
   std::string Flags = ",\"";
 
@@ -472,67 +517,3 @@
   DataSectionStartSuffix = "\tsegment 'DATA'";
   SectionEndDirectiveSuffix = "\tends\n";
 }
-
-std::string X86TargetAsmInfo::SectionForGlobal(const GlobalValue *GV) const {
-  SectionKind::Kind kind = SectionKindForGlobal(GV);
-  unsigned flags = SectionFlagsForGlobal(GV, GV->getSection().c_str());
-  std::string Name;
-
-  // FIXME: Should we use some hashing based on section name and just check
-  // flags?
-  // FIXME: It seems, that Darwin uses much more sections.
-
-  // Select section name
-  if (GV->hasSection()) {
-    // Honour section already set, if any
-    Name = GV->getSection();
-  } else {
-    // Use default section depending on the 'type' of global
-    if (const Function *F = dyn_cast<Function>(GV)) {
-      switch (F->getLinkage()) {
-       default: assert(0 && "Unknown linkage type!");
-       case Function::InternalLinkage:
-       case Function::DLLExportLinkage:
-       case Function::ExternalLinkage:
-        Name = getTextSection();
-        break;
-       case Function::WeakLinkage:
-       case Function::LinkOnceLinkage:
-        Name = UniqueSectionForGlobal(F, kind);
-        break;
-      }
-    } else if (const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV)) {
-      if (GVar->hasCommonLinkage() ||
-          GVar->hasLinkOnceLinkage() ||
-          GVar->hasWeakLinkage())
-        Name = UniqueSectionForGlobal(GVar, kind);
-      else {
-        switch (kind) {
-         case SectionKind::Data:
-          Name = getDataSection();
-          break;
-         case SectionKind::BSS:
-          Name = (getBSSSection() ? getBSSSection() : getDataSection());
-          break;
-         case SectionKind::ROData:
-         case SectionKind::RODataMergeStr:
-         case SectionKind::RODataMergeConst:
-          // FIXME: Temporary
-          Name = getDataSection();
-          break;
-         case SectionKind::ThreadData:
-          Name = (getTLSDataSection() ? getTLSDataSection() : getDataSection());
-          break;
-         case SectionKind::ThreadBSS:
-          Name = (getTLSBSSSection() ? getTLSBSSSection() : getDataSection());
-         default:
-          assert(0 && "Unsuported section kind for global");
-        }
-      }
-    } else
-      assert(0 && "Unsupported global");
-  }
-
-  Name += PrintSectionFlags(flags);
-  return Name;
-}

Modified: llvm/trunk/lib/Target/X86/X86TargetAsmInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86TargetAsmInfo.h?rev=53305&r1=53304&r2=53305&view=diff

==============================================================================
--- llvm/trunk/lib/Target/X86/X86TargetAsmInfo.h (original)
+++ llvm/trunk/lib/Target/X86/X86TargetAsmInfo.h Wed Jul  9 08:23:08 2008
@@ -45,6 +45,8 @@
     explicit X86ELFTargetAsmInfo(const X86TargetMachine &TM);
     virtual unsigned PreferredEHDataFormat(DwarfEncoding::Target Reason,
                                            bool Global) const;
+
+    virtual std::string SelectSectionForGlobal(const GlobalValue *GV) const;
     virtual std::string PrintSectionFlags(unsigned flags) const;
   };
 





More information about the llvm-commits mailing list