switch off of 'Section' onto MCSection.  We're not properly using
MCSection subclasses yet, but this is a step in the right direction.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77708 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Target/PIC16/PIC16AsmPrinter.cpp b/lib/Target/PIC16/PIC16AsmPrinter.cpp
index 743ce9f..604d105 100644
--- a/lib/Target/PIC16/PIC16AsmPrinter.cpp
+++ b/lib/Target/PIC16/PIC16AsmPrinter.cpp
@@ -18,15 +18,15 @@
 #include "llvm/Function.h"
 #include "llvm/Module.h"
 #include "llvm/CodeGen/DwarfWriter.h"
-#include "llvm/Support/FormattedStream.h"
 #include "llvm/CodeGen/MachineFrameInfo.h"
-#include "llvm/Support/Mangler.h"
-#include "llvm/Support/ErrorHandling.h"
 #include "llvm/CodeGen/DwarfWriter.h"
 #include "llvm/CodeGen/MachineModuleInfo.h"
+#include "llvm/MC/MCSection.h"
 #include "llvm/Target/TargetRegistry.h"
 #include "llvm/Target/TargetLoweringObjectFile.h"
-
+#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/FormattedStream.h"
+#include "llvm/Support/Mangler.h"
 using namespace llvm;
 
 #include "PIC16GenAsmWriter.inc"
@@ -71,7 +71,7 @@
   std::string T = PAN::getCodeSectionName(CurrentFnName);
   const char *codeSection = T.c_str();
  
-  const Section *fCodeSection = 
+  const MCSection *fCodeSection = 
     getObjFileLowering().getOrCreateSection(codeSection, false, 
                                             SectionKind::Text);
   // Start the Code Section.
@@ -348,7 +348,7 @@
   std::string T = PAN::getFrameSectionName(CurrentFnName);
   const char *SectionName = T.c_str();
 
-  const Section *fPDataSection =
+  const MCSection *fPDataSection =
     getObjFileLowering().getOrCreateSection(SectionName, false,
                                             SectionKind::DataRel);
   SwitchToSection(fPDataSection);
diff --git a/lib/Target/PIC16/PIC16ISelLowering.cpp b/lib/Target/PIC16/PIC16ISelLowering.cpp
index 811bb1e..87379a6 100644
--- a/lib/Target/PIC16/PIC16ISelLowering.cpp
+++ b/lib/Target/PIC16/PIC16ISelLowering.cpp
@@ -143,7 +143,7 @@
 
 // PIC16TargetLowering Constructor.
 PIC16TargetLowering::PIC16TargetLowering(PIC16TargetMachine &TM)
-  : TargetLowering(TM, new PIC16TargetObjectFile(TM)), TmpSize(0) {
+  : TargetLowering(TM, new PIC16TargetObjectFile()), TmpSize(0) {
  
   Subtarget = &TM.getSubtarget<PIC16Subtarget>();
 
diff --git a/lib/Target/PIC16/PIC16TargetObjectFile.cpp b/lib/Target/PIC16/PIC16TargetObjectFile.cpp
index feec2fd..5a2d4d8 100644
--- a/lib/Target/PIC16/PIC16TargetObjectFile.cpp
+++ b/lib/Target/PIC16/PIC16TargetObjectFile.cpp
@@ -12,11 +12,13 @@
 #include "PIC16TargetMachine.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/Module.h"
+#include "llvm/MC/MCSection.h"
 using namespace llvm;
 
-
-PIC16TargetObjectFile::PIC16TargetObjectFile(const PIC16TargetMachine &tm) 
-: TM (tm) {
+void PIC16TargetObjectFile::Initialize(MCContext &Ctx, const TargetMachine &tm){
+  TargetLoweringObjectFile::Initialize(Ctx, tm);
+  TM = &tm;
+  
   BSSSection_  = getOrCreateSection("udata.# UDATA", false, SectionKind::BSS);
   ReadOnlySection = getOrCreateSection("romdata.# ROMDATA", false,
                                        SectionKind::ReadOnly);
@@ -26,9 +28,7 @@
   // in BeginModule, and gpasm cribbs for that .text symbol.
   TextSection = getOrCreateSection("", true, SectionKind::Text);
 
-  
-  PIC16Section *ROSection = new PIC16Section(ReadOnlySection);
-  ROSections.push_back(ROSection);
+  ROSections.push_back(new PIC16Section(ReadOnlySection));
   
   // FIXME: I don't know what the classification of these sections really is.
   ExternalVarDecls = new PIC16Section(getOrCreateSection("ExternalVarDecls",
@@ -40,14 +40,14 @@
 }
 
 
-const Section *
+const MCSection *
 PIC16TargetObjectFile::getBSSSectionForGlobal(const GlobalVariable *GV) const {
   assert(GV->hasInitializer() && "This global doesn't need space");
   Constant *C = GV->getInitializer();
   assert(C->isNullValue() && "Unitialized globals has non-zero initializer");
 
   // Find how much space this global needs.
-  const TargetData *TD = TM.getTargetData();
+  const TargetData *TD = TM->getTargetData();
   const Type *Ty = C->getType(); 
   unsigned ValSize = TD->getTypeAllocSize(Ty);
  
@@ -64,9 +64,9 @@
   // No BSS section spacious enough was found. Crate a new one.
   if (!FoundBSS) {
     std::string name = PAN::getUdataSectionName(BSSSections.size());
-    const Section *NewSection = getOrCreateSection(name.c_str(), false,
-                                                   // FIXME.
-                                                   SectionKind::Metadata);
+    const MCSection *NewSection = getOrCreateSection(name.c_str(), false,
+                                                     // FIXME.
+                                                     SectionKind::Metadata);
 
     FoundBSS = new PIC16Section(NewSection);
 
@@ -80,7 +80,7 @@
   return FoundBSS->S_;
 } 
 
-const Section *
+const MCSection *
 PIC16TargetObjectFile::getIDATASectionForGlobal(const GlobalVariable *GV) const{
   assert(GV->hasInitializer() && "This global doesn't need space");
   Constant *C = GV->getInitializer();
@@ -89,7 +89,7 @@
          "can split initialized RAM data only");
 
   // Find how much space this global needs.
-  const TargetData *TD = TM.getTargetData();
+  const TargetData *TD = TM->getTargetData();
   const Type *Ty = C->getType(); 
   unsigned ValSize = TD->getTypeAllocSize(Ty);
  
@@ -106,8 +106,7 @@
   // No IDATA section spacious enough was found. Crate a new one.
   if (!FoundIDATA) {
     std::string name = PAN::getIdataSectionName(IDATASections.size());
-    const Section *NewSection = getOrCreateSection(name.c_str(),
-                                                   false,
+    const MCSection *NewSection = getOrCreateSection(name.c_str(), false,
                                                    // FIXME.
                                                    SectionKind::Metadata);
 
@@ -125,7 +124,7 @@
 
 // Get the section for an automatic variable of a function.
 // For PIC16 they are globals only with mangled names.
-const Section *
+const MCSection *
 PIC16TargetObjectFile::getSectionForAuto(const GlobalVariable *GV) const {
 
   const std::string name = PAN::getSectionNameForSym(GV->getName());
@@ -142,10 +141,10 @@
 
   // No Auto section was found. Crate a new one.
   if (!FoundAutoSec) {
-    const Section *NewSection = getOrCreateSection(name.c_str(),
-                                                   // FIXME.
-                                                   false,
-                                                   SectionKind::Metadata);
+    const MCSection *NewSection = getOrCreateSection(name.c_str(),
+                                                     // FIXME.
+                                                     false,
+                                                     SectionKind::Metadata);
 
     FoundAutoSec = new PIC16Section(NewSection);
 
@@ -162,7 +161,7 @@
 
 // Override default implementation to put the true globals into
 // multiple data sections if required.
-const Section*
+const MCSection *
 PIC16TargetObjectFile::SelectSectionForGlobal(const GlobalValue *GV1,
                                               SectionKind Kind,
                                               Mangler *Mang,
@@ -224,7 +223,7 @@
 
 /// getSpecialCasedSectionGlobals - Allow the target to completely override
 /// section assignment of a global.
-const Section *
+const MCSection *
 PIC16TargetObjectFile::getSpecialCasedSectionGlobals(const GlobalValue *GV,
                                                      Mangler *Mang,
                                                      SectionKind Kind) const {
@@ -250,7 +249,7 @@
 
 // Create a new section for global variable. If Addr is given then create
 // section at that address else create by name.
-const Section *
+const MCSection *
 PIC16TargetObjectFile::CreateSectionForGlobal(const GlobalVariable *GV,
                                               Mangler *Mang,
                                               const std::string &Addr) const {
@@ -268,11 +267,11 @@
     return CreateROSectionForGlobal(GV, Addr);
 
   // Else let the default implementation take care of it.
-  return TargetLoweringObjectFile::SectionForGlobal(GV, Mang, TM);
+  return TargetLoweringObjectFile::SectionForGlobal(GV, Mang, *TM);
 }
 
 // Create uninitialized section for a variable.
-const Section *
+const MCSection *
 PIC16TargetObjectFile::CreateBSSSectionForGlobal(const GlobalVariable *GV,
                                                  std::string Addr) const {
   assert(GV->hasInitializer() && "This global doesn't need space");
@@ -297,8 +296,8 @@
   
   PIC16Section *NewBSS = FoundBSS;
   if (NewBSS == NULL) {
-    const Section *NewSection = getOrCreateSection(Name.c_str(),
-                                                   false, SectionKind::BSS);
+    const MCSection *NewSection = getOrCreateSection(Name.c_str(), false,
+                                                     SectionKind::BSS);
     NewBSS = new PIC16Section(NewSection);
     BSSSections.push_back(NewBSS);
   }
@@ -314,14 +313,14 @@
 
 // Get rom section for a variable. Currently there can be only one rom section
 // unless a variable explicitly requests a section.
-const Section *
+const MCSection *
 PIC16TargetObjectFile::getROSectionForGlobal(const GlobalVariable *GV) const {
   ROSections[0]->Items.push_back(GV);
   return ROSections[0]->S_;
 }
 
 // Create initialized data section for a variable.
-const Section *
+const MCSection *
 PIC16TargetObjectFile::CreateIDATASectionForGlobal(const GlobalVariable *GV,
                                                    std::string Addr) const {
   assert(GV->hasInitializer() && "This global doesn't need space");
@@ -349,8 +348,7 @@
 
   PIC16Section *NewIDATASec = FoundIDATASec;
   if (NewIDATASec == NULL) {
-    const Section *NewSection = getOrCreateSection(Name.c_str(),
-                                                   false,
+    const MCSection *NewSection = getOrCreateSection(Name.c_str(), false,
                                                    // FIXME:
                                                    SectionKind::Metadata);
     NewIDATASec = new PIC16Section(NewSection);
@@ -365,7 +363,7 @@
 }
 
 // Create a section in rom for a variable.
-const Section *
+const MCSection *
 PIC16TargetObjectFile::CreateROSectionForGlobal(const GlobalVariable *GV,
                                                 std::string Addr) const {
   assert(GV->getType()->getAddressSpace() == PIC16ISD::ROM_SPACE &&
@@ -390,9 +388,8 @@
 
   PIC16Section *NewRomSec = FoundROSec;
   if (NewRomSec == NULL) {
-    const Section *NewSection = getOrCreateSection(Name.c_str(),
-                                                   false,
-                                                   SectionKind::ReadOnly);
+    const MCSection *NewSection = getOrCreateSection(Name.c_str(), false,
+                                                     SectionKind::ReadOnly);
     NewRomSec = new PIC16Section(NewSection);
     ROSections.push_back(NewRomSec);
   }
diff --git a/lib/Target/PIC16/PIC16TargetObjectFile.h b/lib/Target/PIC16/PIC16TargetObjectFile.h
index 336730d..c296954 100644
--- a/lib/Target/PIC16/PIC16TargetObjectFile.h
+++ b/lib/Target/PIC16/PIC16TargetObjectFile.h
@@ -29,12 +29,12 @@
   /// FIXME: Reimplement by inheriting from MCSection.
   ///
   struct PIC16Section {
-    const Section *S_; // Connection to actual Section.
+    const MCSection *S_; // Connection to actual Section.
     unsigned Size;  // Total size of the objects contained.
     bool SectionPrinted;
     std::vector<const GlobalVariable*> Items;
     
-    PIC16Section(const Section *s) {
+    PIC16Section(const MCSection *s) {
       S_ = s;
       Size = 0;
       SectionPrinted = false;
@@ -44,7 +44,7 @@
   };
   
   class PIC16TargetObjectFile : public TargetLoweringObjectFile {
-    const PIC16TargetMachine &TM;
+    const TargetMachine *TM;
   public:
     mutable std::vector<PIC16Section*> BSSSections;
     mutable std::vector<PIC16Section*> IDATASections;
@@ -53,34 +53,36 @@
     mutable PIC16Section *ExternalVarDecls;
     mutable PIC16Section *ExternalVarDefs;
     
-    PIC16TargetObjectFile(const PIC16TargetMachine &TM);
     ~PIC16TargetObjectFile();
     
+    void Initialize(MCContext &Ctx, const TargetMachine &TM);
+
+    
     /// getSpecialCasedSectionGlobals - Allow the target to completely override
     /// section assignment of a global.
-    virtual const Section *
+    virtual const MCSection *
     getSpecialCasedSectionGlobals(const GlobalValue *GV, Mangler *Mang,
                                   SectionKind Kind) const;
-    virtual const Section *SelectSectionForGlobal(const GlobalValue *GV,
-                                                  SectionKind Kind,
-                                                  Mangler *Mang,
-                                                  const TargetMachine&) const;
+    virtual const MCSection *SelectSectionForGlobal(const GlobalValue *GV,
+                                                    SectionKind Kind,
+                                                    Mangler *Mang,
+                                                    const TargetMachine&) const;
   private:
     std::string getSectionNameForSym(const std::string &Sym) const;
 
-    const Section *getBSSSectionForGlobal(const GlobalVariable *GV) const;
-    const Section *getIDATASectionForGlobal(const GlobalVariable *GV) const;
-    const Section *getSectionForAuto(const GlobalVariable *GV) const;
-    const Section *CreateBSSSectionForGlobal(const GlobalVariable *GV,
-                                             std::string Addr = "") const;
-    const Section *CreateIDATASectionForGlobal(const GlobalVariable *GV,
+    const MCSection *getBSSSectionForGlobal(const GlobalVariable *GV) const;
+    const MCSection *getIDATASectionForGlobal(const GlobalVariable *GV) const;
+    const MCSection *getSectionForAuto(const GlobalVariable *GV) const;
+    const MCSection *CreateBSSSectionForGlobal(const GlobalVariable *GV,
                                                std::string Addr = "") const;
-    const Section *getROSectionForGlobal(const GlobalVariable *GV) const;
-    const Section *CreateROSectionForGlobal(const GlobalVariable *GV,
-                                            std::string Addr = "") const;
-    const Section *CreateSectionForGlobal(const GlobalVariable *GV,
-                                          Mangler *Mang,
-                                          const std::string &Addr = "") const;
+    const MCSection *CreateIDATASectionForGlobal(const GlobalVariable *GV,
+                                                 std::string Addr = "") const;
+    const MCSection *getROSectionForGlobal(const GlobalVariable *GV) const;
+    const MCSection *CreateROSectionForGlobal(const GlobalVariable *GV,
+                                              std::string Addr = "") const;
+    const MCSection *CreateSectionForGlobal(const GlobalVariable *GV,
+                                            Mangler *Mang,
+                                            const std::string &Addr = "") const;
   public:
     void SetSectionForGVs(Module &M);
     const std::vector<PIC16Section*> &getBSSSections() const {