[llvm-commits] [llvm] r77236 - in /llvm/trunk: include/llvm/Target/COFFTargetAsmInfo.h include/llvm/Target/ELFTargetAsmInfo.h include/llvm/Target/TargetAsmInfo.h lib/Target/COFFTargetAsmInfo.cpp lib/Target/ELFTargetAsmInfo.cpp lib/Target/TargetAsmInfo.cpp

Chris Lattner sabre at nondot.org
Mon Jul 27 12:14:15 PDT 2009


Author: lattner
Date: Mon Jul 27 14:14:14 2009
New Revision: 77236

URL: http://llvm.org/viewvc/llvm-project?rev=77236&view=rev
Log:
Sink getSectionPrefixForUniqueGlobal down into the TAI 
implementations that need it, rearrange ELFTAI.

Modified:
    llvm/trunk/include/llvm/Target/COFFTargetAsmInfo.h
    llvm/trunk/include/llvm/Target/ELFTargetAsmInfo.h
    llvm/trunk/include/llvm/Target/TargetAsmInfo.h
    llvm/trunk/lib/Target/COFFTargetAsmInfo.cpp
    llvm/trunk/lib/Target/ELFTargetAsmInfo.cpp
    llvm/trunk/lib/Target/TargetAsmInfo.cpp

Modified: llvm/trunk/include/llvm/Target/COFFTargetAsmInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/COFFTargetAsmInfo.h?rev=77236&r1=77235&r2=77236&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Target/COFFTargetAsmInfo.h (original)
+++ llvm/trunk/include/llvm/Target/COFFTargetAsmInfo.h Mon Jul 27 14:14:14 2009
@@ -17,12 +17,12 @@
   protected:
     explicit COFFTargetAsmInfo(const TargetMachine &TM);
   public:
-
-    virtual const char *
-    getSectionPrefixForUniqueGlobal(SectionKind kind) const;
-    
     virtual void getSectionFlagsAsString(SectionKind Kind,
                                          SmallVectorImpl<char> &Str) const;
+    
+    virtual const Section *
+    SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind) const;
+      
   };
 }
 

Modified: llvm/trunk/include/llvm/Target/ELFTargetAsmInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/ELFTargetAsmInfo.h?rev=77236&r1=77235&r2=77236&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Target/ELFTargetAsmInfo.h (original)
+++ llvm/trunk/include/llvm/Target/ELFTargetAsmInfo.h Mon Jul 27 14:14:14 2009
@@ -33,8 +33,6 @@
     void getSectionFlagsAsString(SectionKind Kind,
                                  SmallVectorImpl<char> &Str) const;
     
-    const char *getSectionPrefixForUniqueGlobal(SectionKind Kind) const;
-    
     virtual const Section* SelectSectionForGlobal(const GlobalValue *GV,
                                                   SectionKind Kind) const;
     

Modified: llvm/trunk/include/llvm/Target/TargetAsmInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetAsmInfo.h?rev=77236&r1=77235&r2=77236&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Target/TargetAsmInfo.h (original)
+++ llvm/trunk/include/llvm/Target/TargetAsmInfo.h Mon Jul 27 14:14:14 2009
@@ -144,6 +144,9 @@
     bool ExplicitSection : 1;
   public:
     
+    // FIXME: REMOVE.
+    Kind getKind() const { return K; }
+    
     bool isWeak() const { return Weak; }
     bool hasExplicitSection() const { return ExplicitSection; }
     
@@ -669,15 +672,6 @@
     virtual const Section *getSectionForMergeableConstant(SectionKind Kind)const;
 
     
-    /// getSectionPrefixForUniqueGlobal - Return a string that we should prepend
-    /// onto a global's name in order to get the unique section name for the
-    /// global.  This is important for globals that need to be merged across
-    /// translation units.
-    virtual const char *
-    getSectionPrefixForUniqueGlobal(SectionKind Kind) const {
-      return 0;
-    }
-    
     /// getKindForNamedSection - If this target wants to be able to override
     /// section flags based on the name of the section specified for a global
     /// variable, it can implement this.  This is used on ELF systems so that

Modified: llvm/trunk/lib/Target/COFFTargetAsmInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/COFFTargetAsmInfo.cpp?rev=77236&r1=77235&r2=77236&view=diff

==============================================================================
--- llvm/trunk/lib/Target/COFFTargetAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/COFFTargetAsmInfo.cpp Mon Jul 27 14:14:14 2009
@@ -53,15 +53,6 @@
   DwarfMacroInfoSection = "\t.section\t.debug_macinfo,\"dr\"";
 }
 
-const char *COFFTargetAsmInfo::
-getSectionPrefixForUniqueGlobal(SectionKind Kind) const {
-  if (Kind.isText())
-    return ".text$linkonce";
-  if (Kind.isWriteable())
-    return ".data$linkonce";
-  return ".rdata$linkonce";
-}
-
 void COFFTargetAsmInfo::getSectionFlagsAsString(SectionKind Kind,
                                             SmallVectorImpl<char> &Str) const {
   // FIXME: Inefficient.
@@ -74,3 +65,45 @@
   
   Str.append(Res.begin(), Res.end());
 }
+
+//===----------------------------------------------------------------------===//
+// Move to AsmPrinter (mangler access).
+//===----------------------------------------------------------------------===//
+
+#include "llvm/GlobalVariable.h"
+
+static const char *getSectionPrefixForUniqueGlobal(SectionKind Kind) {
+  if (Kind.isText())
+    return ".text$linkonce";
+  if (Kind.isWriteable())
+    return ".data$linkonce";
+  return ".rdata$linkonce";
+}
+
+const Section *
+COFFTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV,
+                                          SectionKind Kind) const {
+  assert(!Kind.isThreadLocal() && "Doesn't support TLS");
+  
+  // If this global is linkonce/weak and the target handles this by emitting it
+  // into a 'uniqued' section name, create and return the section now.
+  if (Kind.isWeak()) {
+    const char *Prefix = getSectionPrefixForUniqueGlobal(Kind);
+    // FIXME: Use mangler interface (PR4584).
+    std::string Name = Prefix+GV->getNameStr();
+    return getOrCreateSection(Name.c_str(), false, Kind.getKind());
+  }
+  
+  if (Kind.isText())
+    return getTextSection();
+  
+  if (Kind.isBSS())
+    if (const Section *S = getBSSSection_())
+      return S;
+  
+  if (Kind.isReadOnly())
+    if (const Section *S = getReadOnlySection())
+      return S;
+  
+  return getDataSection();
+}

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

==============================================================================
--- llvm/trunk/lib/Target/ELFTargetAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/ELFTargetAsmInfo.cpp Mon Jul 27 14:14:14 2009
@@ -12,16 +12,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "llvm/Constants.h"
-#include "llvm/DerivedTypes.h"
-#include "llvm/Function.h"
-#include "llvm/GlobalVariable.h"
-#include "llvm/ADT/StringExtras.h"
-#include "llvm/CodeGen/MachineConstantPool.h"
-#include "llvm/Support/ErrorHandling.h"
 #include "llvm/Target/ELFTargetAsmInfo.h"
-#include "llvm/Target/TargetMachine.h"
-#include "llvm/Target/TargetData.h"
+#include "llvm/ADT/SmallVector.h"
 using namespace llvm;
 
 ELFTargetAsmInfo::ELFTargetAsmInfo(const TargetMachine &TM)
@@ -53,72 +45,6 @@
                                                SectionKind::MergeableConst16);
 }
 
-
-const Section*
-ELFTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV,
-                                         SectionKind Kind) const {
-  if (Kind.isText()) return TextSection;
-  if (Kind.isMergeableCString()) {
-    const TargetData *TD = TM.getTargetData();
-    Constant *C = cast<GlobalVariable>(GV)->getInitializer();
-    const Type *Ty = cast<ArrayType>(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())
-      return MergeableConst4Section;
-    if (Kind.isMergeableConst8())
-      return MergeableConst8Section;
-    if (Kind.isMergeableConst16())
-      return MergeableConst16Section;
-    return ReadOnlySection;  // .const
-  }
-  
-  if (Kind.isReadOnly())             return getReadOnlySection();
-  
-  
-  if (Kind.isThreadData())           return TLSDataSection;
-  if (Kind.isThreadBSS())            return TLSBSSSection;
-
-  if (Kind.isBSS())                  return getBSSSection_();
-  
-  
-  if (Kind.isDataNoRel())            return DataSection;
-  if (Kind.isDataRelLocal())         return DataRelLocalSection;
-  if (Kind.isDataRel())              return DataRelSection;
-  if (Kind.isReadOnlyWithRelLocal()) return DataRelROLocalSection;
-  
-  assert(Kind.isReadOnlyWithRel() && "Unknown section kind");
-  return DataRelROSection;
-}
-
-/// getSectionForMergeableConstant - Given a Mergeable constant with the
-/// specified size and relocation information, return a section that it
-/// should be placed in.
-const Section *
-ELFTargetAsmInfo::getSectionForMergeableConstant(SectionKind Kind) const {
-  return SelectSectionForGlobal(0, Kind);
-}
-
 /// getFlagsForNamedSection - If this target wants to be able to infer
 /// section flags based on the name of the section specified for a global
 /// variable, it can implement this.
@@ -148,24 +74,6 @@
   return K;
 }
 
-const char *
-ELFTargetAsmInfo::getSectionPrefixForUniqueGlobal(SectionKind Kind) const{
-  if (Kind.isText())                 return ".gnu.linkonce.t.";
-  if (Kind.isReadOnly())             return ".gnu.linkonce.r.";
-  
-  if (Kind.isThreadData())           return ".gnu.linkonce.td.";
-  if (Kind.isThreadBSS())            return ".gnu.linkonce.tb.";
-
-  if (Kind.isBSS())                  return ".gnu.linkonce.b.";
-  if (Kind.isDataNoRel())            return ".gnu.linkonce.d.";
-  if (Kind.isDataRelLocal())         return ".gnu.linkonce.d.rel.local.";
-  if (Kind.isDataRel())              return ".gnu.linkonce.d.rel.";
-  if (Kind.isReadOnlyWithRelLocal()) return ".gnu.linkonce.d.rel.ro.local.";
-  
-  assert(Kind.isReadOnlyWithRel() && "Unknown section kind");
-  return ".gnu.linkonce.d.rel.ro.";
-}
-
 
 void ELFTargetAsmInfo::getSectionFlagsAsString(SectionKind Kind,
                                              SmallVectorImpl<char> &Str) const {
@@ -219,3 +127,108 @@
     Str.push_back('6');
   }
 }
+
+
+
+//===----------------------------------------------------------------------===//
+// Move to AsmPrinter (mangler access).
+//===----------------------------------------------------------------------===//
+
+#include "llvm/DerivedTypes.h"
+#include "llvm/GlobalVariable.h"
+#include "llvm/Target/TargetData.h"
+#include "llvm/Target/TargetMachine.h"
+#include "llvm/ADT/StringExtras.h"
+
+static const char *getSectionPrefixForUniqueGlobal(SectionKind Kind) {
+  if (Kind.isText())                 return ".gnu.linkonce.t.";
+  if (Kind.isReadOnly())             return ".gnu.linkonce.r.";
+  
+  if (Kind.isThreadData())           return ".gnu.linkonce.td.";
+  if (Kind.isThreadBSS())            return ".gnu.linkonce.tb.";
+  
+  if (Kind.isBSS())                  return ".gnu.linkonce.b.";
+  if (Kind.isDataNoRel())            return ".gnu.linkonce.d.";
+  if (Kind.isDataRelLocal())         return ".gnu.linkonce.d.rel.local.";
+  if (Kind.isDataRel())              return ".gnu.linkonce.d.rel.";
+  if (Kind.isReadOnlyWithRelLocal()) return ".gnu.linkonce.d.rel.ro.local.";
+  
+  assert(Kind.isReadOnlyWithRel() && "Unknown section kind");
+  return ".gnu.linkonce.d.rel.ro.";
+}
+
+const Section*
+ELFTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV,
+                                         SectionKind Kind) const {
+  
+  // If this global is linkonce/weak and the target handles this by emitting it
+  // into a 'uniqued' section name, create and return the section now.
+  if (Kind.isWeak()) {
+    const char *Prefix = getSectionPrefixForUniqueGlobal(Kind);
+    // FIXME: Use mangler interface (PR4584).
+    std::string Name = Prefix+GV->getNameStr();
+    return getOrCreateSection(Name.c_str(), false, Kind.getKind());
+  }
+  
+  if (Kind.isText()) return TextSection;
+  if (Kind.isMergeableCString()) {
+    const TargetData *TD = TM.getTargetData();
+    Constant *C = cast<GlobalVariable>(GV)->getInitializer();
+    const Type *Ty = cast<ArrayType>(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())
+      return MergeableConst4Section;
+    if (Kind.isMergeableConst8())
+      return MergeableConst8Section;
+    if (Kind.isMergeableConst16())
+      return MergeableConst16Section;
+    return ReadOnlySection;  // .const
+  }
+  
+  if (Kind.isReadOnly())             return getReadOnlySection();
+  
+  
+  if (Kind.isThreadData())           return TLSDataSection;
+  if (Kind.isThreadBSS())            return TLSBSSSection;
+  
+  if (Kind.isBSS())                  return getBSSSection_();
+  
+  
+  if (Kind.isDataNoRel())            return DataSection;
+  if (Kind.isDataRelLocal())         return DataRelLocalSection;
+  if (Kind.isDataRel())              return DataRelSection;
+  if (Kind.isReadOnlyWithRelLocal()) return DataRelROLocalSection;
+  
+  assert(Kind.isReadOnlyWithRel() && "Unknown section kind");
+  return DataRelROSection;
+}
+
+/// getSectionForMergeableConstant - Given a Mergeable constant with the
+/// specified size and relocation information, return a section that it
+/// should be placed in.
+const Section *
+ELFTargetAsmInfo::getSectionForMergeableConstant(SectionKind Kind) const {
+  return SelectSectionForGlobal(0, Kind);
+}
+

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

==============================================================================
--- llvm/trunk/lib/Target/TargetAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/TargetAsmInfo.cpp Mon Jul 27 14:14:14 2009
@@ -319,15 +319,6 @@
     return getOrCreateSection(GV->getSection().c_str(), false, GVKind);
   }
 
-  // If this global is linkonce/weak and the target handles this by emitting it
-  // into a 'uniqued' section name, create and return the section now.
-  if (Kind.isWeak()) {
-    if (const char *Prefix = getSectionPrefixForUniqueGlobal(Kind)) {
-      // FIXME: Use mangler interface (PR4584).
-      std::string Name = Prefix+GV->getNameStr();
-      return getOrCreateSection(Name.c_str(), false, GVKind);
-    }
-  }
   
   // Use default section depending on the 'type' of global
   return SelectSectionForGlobal(GV, Kind);





More information about the llvm-commits mailing list