Fix several fixmes and clean up code by sinking *all* section
authorChris Lattner <sabre@nondot.org>
Thu, 6 Aug 2009 16:39:58 +0000 (16:39 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 6 Aug 2009 16:39:58 +0000 (16:39 +0000)
creation activity into the target-specific subclasses of TLOF.
Before this, globals with explicit sections could be created by
the base class.

1. make getOrCreateSection protected, add a new getExplicitSectionGlobal
   pure virtual method to assign sections to globals with a specified
   section.
2. eliminate getSpecialCasedSectionGlobals, which is now PIC specific.
3. eliminate the getKindForNamedSection virtual method, which is
   now just a static method for ELF.
4. Add implementions of getExplicitSectionGlobal for ELF/PECOFF/Darwin/PIC16.
   They are now all detangled and understandable, woo! :)

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78319 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Target/TargetLoweringObjectFile.h
lib/Target/PIC16/PIC16TargetObjectFile.cpp
lib/Target/PIC16/PIC16TargetObjectFile.h
lib/Target/TargetLoweringObjectFile.cpp

index 630f9d0604b55068f27c7a5bda5766ad5e709c7f..0972dcde072baa61e68f077d584a8a27a7743260 100644 (file)
@@ -80,8 +80,7 @@ protected:
   const MCSection *DwarfRangesSection;
   const MCSection *DwarfMacroInfoSection;
   
-public:
-  // FIXME: NONPUB.
+protected:
   const MCSection *getOrCreateSection(const char *Name,
                                       bool isDirective,
                                       SectionKind K) const;
@@ -132,15 +131,6 @@ public:
   /// section that it should be placed in.
   virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
   
-  /// 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
-  /// ".tbss" gets the TLS bit set etc.
-  virtual SectionKind getKindForNamedSection(const char *Section,
-                                             SectionKind K) const {
-    return K;
-  }
-  
   /// getKindForGlobal - Classify the specified global variable into a set of
   /// target independent categories embodied in SectionKind.
   static SectionKind getKindForGlobal(const GlobalValue *GV,
@@ -162,10 +152,17 @@ public:
     return SectionForGlobal(GV, getKindForGlobal(GV, TM), Mang, TM);
   }
   
+  
+  
+  /// getExplicitSectionGlobal - Targets should implement this method to assign
+  /// a section to globals with an explicit section specfied.  The
+  /// implementation of this method can assume that GV->hasSection() is true.
+  virtual const MCSection *
+  getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, 
+                           Mangler *Mang, const TargetMachine &TM) const = 0;
+  
   /// getSpecialCasedSectionGlobals - Allow the target to completely override
   /// section assignment of a global.
-  /// FIXME: ELIMINATE this by making PIC16 implement ADDRESS with
-  /// getFlagsForNamedSection.
   virtual const MCSection *
   getSpecialCasedSectionGlobals(const GlobalValue *GV, Mangler *Mang,
                                 SectionKind Kind) const {
@@ -224,8 +221,11 @@ public:
   /// section that it should be placed in.
   virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
   
-  virtual SectionKind getKindForNamedSection(const char *Section,
-                                             SectionKind K) const;
+  
+  virtual const MCSection *
+  getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, 
+                           Mangler *Mang, const TargetMachine &TM) const;
+  
   void getSectionFlagsAsString(SectionKind Kind,
                                SmallVectorImpl<char> &Str) const;
   
@@ -255,6 +255,10 @@ public:
   SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
                          Mangler *Mang, const TargetMachine &TM) const;
   
+  virtual const MCSection *
+  getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, 
+                           Mangler *Mang, const TargetMachine &TM) const;
+  
   virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
   
   /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
@@ -275,6 +279,10 @@ class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {
 public:
   virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
   
+  virtual const MCSection *
+  getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, 
+                           Mangler *Mang, const TargetMachine &TM) const;
+  
   virtual void getSectionFlagsAsString(SectionKind Kind,
                                        SmallVectorImpl<char> &Str) const;
   
index f15f3321c7ca7985c2dd12744dc7ef03b8200390..b09ad305c28222a9e462bf7fc50daecd3cc7f161 100644 (file)
@@ -242,28 +242,26 @@ PIC16TargetObjectFile::~PIC16TargetObjectFile() {
 
 /// getSpecialCasedSectionGlobals - Allow the target to completely override
 /// section assignment of a global.
-const MCSection *
-PIC16TargetObjectFile::getSpecialCasedSectionGlobals(const GlobalValue *GV,
-                                                     Mangler *Mang,
-                                                     SectionKind Kind) const {
-  // If GV has a sectin name or section address create that section now.
-  if (GV->hasSection()) {
-    if (const GlobalVariable *GVar = cast<GlobalVariable>(GV)) {
-      std::string SectName = GVar->getSection();
-      // If address for a variable is specified, get the address and create
-      // section.
-      std::string AddrStr = "Address=";
-      if (SectName.compare(0, AddrStr.length(), AddrStr) == 0) {
-        std::string SectAddr = SectName.substr(AddrStr.length());
-        return CreateSectionForGlobal(GVar, Mang, SectAddr);
-      }
-       
-      // Create the section specified with section attribute. 
-      return CreateSectionForGlobal(GVar, Mang);
+const MCSection *PIC16TargetObjectFile::
+getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, 
+                         Mangler *Mang, const TargetMachine &TM) const {
+  assert(GV->hasSection());
+  
+  if (const GlobalVariable *GVar = cast<GlobalVariable>(GV)) {
+    std::string SectName = GVar->getSection();
+    // If address for a variable is specified, get the address and create
+    // section.
+    std::string AddrStr = "Address=";
+    if (SectName.compare(0, AddrStr.length(), AddrStr) == 0) {
+      std::string SectAddr = SectName.substr(AddrStr.length());
+      return CreateSectionForGlobal(GVar, Mang, SectAddr);
     }
+     
+    // Create the section specified with section attribute. 
+    return CreateSectionForGlobal(GVar, Mang);
   }
 
-  return 0;
+  return getOrCreateSection(GV->getSection().c_str(), false, Kind);
 }
 
 // Create a new section for global variable. If Addr is given then create
index 6cc7054e63b5e5676ec6b73c49720a23822b0158..c2611087b50688cb273d3422527fc99ca49e93f2 100644 (file)
@@ -59,11 +59,9 @@ namespace llvm {
     void Initialize(MCContext &Ctx, const TargetMachine &TM);
 
     
-    /// getSpecialCasedSectionGlobals - Allow the target to completely override
-    /// section assignment of a global.
     virtual const MCSection *
-    getSpecialCasedSectionGlobals(const GlobalValue *GV, Mangler *Mang,
-                                  SectionKind Kind) const;
+    getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, 
+                             Mangler *Mang, const TargetMachine &TM) const;
     
     virtual const MCSection *SelectSectionForGlobal(const GlobalValue *GV,
                                                     SectionKind Kind,
index 23e549a42b08442140be4b0a328dd8c1fe2e11ec..6aca6da8afef6dad72cdccd49157b4d2e6429c40 100644 (file)
@@ -233,20 +233,9 @@ const MCSection *TargetLoweringObjectFile::
 SectionForGlobal(const GlobalValue *GV, SectionKind Kind, Mangler *Mang,
                  const TargetMachine &TM) const {
   // Select section name.
-  if (GV->hasSection()) {
-    // If the target has special section hacks for specifically named globals,
-    // return them now.
-    if (const MCSection *TS = getSpecialCasedSectionGlobals(GV, Mang, Kind))
-      return TS;
-    
-    // If the target has magic semantics for certain section names, make sure to
-    // pick up the flags.  This allows the user to write things with attribute
-    // section and still get the appropriate section flags printed.
-    Kind = getKindForNamedSection(GV->getSection().c_str(), Kind);
-    
-    return getOrCreateSection(GV->getSection().c_str(), false, Kind);
-  }
-
+  if (GV->hasSection())
+    return getExplicitSectionGlobal(GV, Kind, Mang, TM);
+  
   
   // Use default section depending on the 'type' of global
   return SelectSectionForGlobal(GV, Kind, Mang, TM);
@@ -381,8 +370,8 @@ void TargetLoweringObjectFileELF::Initialize(MCContext &Ctx,
 }
 
 
-SectionKind TargetLoweringObjectFileELF::
-getKindForNamedSection(const char *Name, SectionKind K) const {
+static SectionKind 
+getELFKindForNamedSection(const char *Name, SectionKind K) {
   if (Name[0] != '.') return K;
   
   // Some lame default implementation based on some magic section names.
@@ -407,6 +396,17 @@ getKindForNamedSection(const char *Name, SectionKind K) const {
   return K;
 }
 
+const MCSection *TargetLoweringObjectFileELF::
+getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, 
+                         Mangler *Mang, const TargetMachine &TM) const {
+  // Infer section flags from the section name if we can.
+  Kind = getELFKindForNamedSection(GV->getSection().c_str(), Kind);
+  
+  return getOrCreateSection(GV->getSection().c_str(), false, Kind);
+}
+      
+      
+      
 void TargetLoweringObjectFileELF::
 getSectionFlagsAsString(SectionKind Kind, SmallVectorImpl<char> &Str) const {
   Str.push_back(',');
@@ -688,6 +688,12 @@ void TargetLoweringObjectFileMachO::Initialize(MCContext &Ctx,
                        SectionKind::getMetadata());
 }
 
+const MCSection *TargetLoweringObjectFileMachO::
+getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, 
+                         Mangler *Mang, const TargetMachine &TM) const {
+  return getOrCreateSection(GV->getSection().c_str(), false, Kind);
+}
+
 const MCSection *TargetLoweringObjectFileMachO::
 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
                        Mangler *Mang, const TargetMachine &TM) const {
@@ -837,6 +843,13 @@ void TargetLoweringObjectFileCOFF::Initialize(MCContext &Ctx,
                        true, SectionKind::getMetadata());
 }
 
+const MCSection *TargetLoweringObjectFileCOFF::
+getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, 
+                         Mangler *Mang, const TargetMachine &TM) const {
+  return getOrCreateSection(GV->getSection().c_str(), false, Kind);
+}
+
+
 void TargetLoweringObjectFileCOFF::
 getSectionFlagsAsString(SectionKind Kind, SmallVectorImpl<char> &Str) const {
   // FIXME: Inefficient.