X86: Mark MOV.*_{TC,NOREX} instruction as code gen only, they aren't real.
[oota-llvm.git] / lib / Target / PIC16 / PIC16TargetObjectFile.cpp
index 330722d4a9c34f228d7da0b81b9e8bfae04963f1..ff0f971cc382350a3cd103fcd6afbc26bc07406a 100644 (file)
@@ -8,7 +8,6 @@
 //===----------------------------------------------------------------------===//
 
 #include "PIC16TargetObjectFile.h"
-#include "PIC16ISelLowering.h"
 #include "PIC16TargetMachine.h"
 #include "PIC16Section.h"
 #include "llvm/DerivedTypes.h"
@@ -22,6 +21,21 @@ using namespace llvm;
 PIC16TargetObjectFile::PIC16TargetObjectFile() {
 }
 
+PIC16TargetObjectFile::~PIC16TargetObjectFile() {
+}
+
+/// Find a pic16 section. Return null if not found. Do not create one.
+PIC16Section *PIC16TargetObjectFile::
+findPIC16Section(const std::string &Name) const {
+  /// Return if we have an already existing one.
+  PIC16Section *Entry = SectionsByName[Name];
+  if (Entry)
+    return Entry;
+
+  return NULL;
+}
+
+
 /// Find a pic16 section. If not found, create one.
 PIC16Section *PIC16TargetObjectFile::
 getPIC16Section(const std::string &Name, PIC16SectionType Ty, 
@@ -57,6 +71,7 @@ getPIC16DataSection(const std::string &Name, PIC16SectionType Ty,
   case UDATA: UDATASections_.push_back(Entry); break;
   case IDATA: IDATASections_.push_back(Entry); break;
   case ROMDATA: ROMDATASection_ = Entry; break;
+  case UDATA_SHR: SHAREDUDATASection_ = Entry; break;
   }
 
   return Entry;
@@ -104,20 +119,13 @@ getPIC16UserSection(const std::string &Name, PIC16SectionType Ty,
   return Entry;
 }
 
-/// Do some standard llvm stuff. PIC16 really does not need any of this.
+/// Do some standard initialization.
 void PIC16TargetObjectFile::Initialize(MCContext &Ctx, const TargetMachine &tm){
   TargetLoweringObjectFile::Initialize(Ctx, tm);
   TM = &tm;
   
-  // BSSSection = getPIC16DataSection("udata.#", UDATA);
-  // ReadOnlySection = getPIC16DataSection("romdata.#", ROMDATA);
-  // DataSection = getPIC16DataSection("idata.#", IDATA);
-  
-  // Need because otherwise a .text symbol is emitted by DwarfWriter
-  // in BeginModule, and gpasm cribbs for that .text symbol.
-  // FIXME: below
-  // TextSection = getPIC16DataSection("", UDATA);
   ROMDATASection_ = NULL;
+  SHAREDUDATASection_ = NULL;
 }
 
 /// allocateUDATA - Allocate a un-initialized global to an existing or new UDATA
@@ -125,7 +133,7 @@ void PIC16TargetObjectFile::Initialize(MCContext &Ctx, const TargetMachine &tm){
 const MCSection *
 PIC16TargetObjectFile::allocateUDATA(const GlobalVariable *GV) const {
   assert(GV->hasInitializer() && "This global doesn't need space");
-  Constant *C = GV->getInitializer();
+  const Constant *C = GV->getInitializer();
   assert(C->isNullValue() && "Unitialized globals has non-zero initializer");
 
   // Find how much space this global needs.
@@ -160,7 +168,7 @@ PIC16TargetObjectFile::allocateUDATA(const GlobalVariable *GV) const {
 const MCSection *
 PIC16TargetObjectFile::allocateIDATA(const GlobalVariable *GV) const{
   assert(GV->hasInitializer() && "This global doesn't need space");
-  Constant *C = GV->getInitializer();
+  const Constant *C = GV->getInitializer();
   assert(!C->isNullValue() && "initialized globals has zero initializer");
   assert(GV->getType()->getAddressSpace() == PIC16ISD::RAM_SPACE &&
          "can allocate initialized RAM data only");
@@ -254,22 +262,7 @@ PIC16TargetObjectFile::SelectSectionForGlobal(const GlobalValue *GV1,
   return TargetLoweringObjectFile::SelectSectionForGlobal(GV, Kind, Mang,TM);
 }
 
-PIC16TargetObjectFile::~PIC16TargetObjectFile() {
-#if 0
-  for (unsigned i = 0; i < UDATASections_.size(); i++)
-    delete UDATASections_[i]; 
-  for (unsigned i = 0; i < IDATASections_.size(); i++)
-    delete IDATASections_[i]; 
-  
-  delete ROMDATASection_;
-
-  for (unsigned i = 0; i < AUTOSections_.size(); i++)
-    delete AUTOSections_[i]; 
 
-  for (unsigned i = 0; i < USERSections_.size(); i++)
-    delete USERSections_[i];
-#endif
-}
 
 
 /// getExplicitSectionGlobal - Allow the target to completely override
@@ -287,7 +280,10 @@ getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
     std::string AddrStr = "Address=";
     if (SectName.compare(0, AddrStr.length(), AddrStr) == 0) {
       std::string SectAddr = SectName.substr(AddrStr.length());
-      return allocateAtGivenAddress(GVar, SectAddr);
+      if (SectAddr.compare("NEAR") == 0)
+        return allocateSHARED(GVar, Mang);
+      else
+        return allocateAtGivenAddress(GVar, SectAddr);
     }
      
     // Create the section specified with section attribute. 
@@ -297,10 +293,33 @@ getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
   return getPIC16DataSection(GV->getSection().c_str(), UDATA);
 }
 
+const MCSection *
+PIC16TargetObjectFile::allocateSHARED(const GlobalVariable *GV,
+                                      Mangler *Mang) const {
+  // Make sure that this is an uninitialized global.
+  assert(GV->hasInitializer() && "This global doesn't need space");
+  if (!GV->getInitializer()->isNullValue()) {
+    // FIXME: Generate a warning in this case that near qualifier will be 
+    // ignored.
+    return SelectSectionForGlobal(GV, SectionKind::getDataRel(), Mang, *TM); 
+  } 
+  std::string Name = PAN::getSharedUDataSectionName(); 
+
+  PIC16Section *SharedUDataSect = getPIC16DataSection(Name.c_str(), UDATA_SHR); 
+  // Insert the GV into shared section.
+  SharedUDataSect->Items.push_back(GV);
+  return SharedUDataSect;
+}
+
+
 // Interface used by AsmPrinter to get a code section for a function.
 const PIC16Section *
-PIC16TargetObjectFile::SectionForCode(const std::string &FnName) const {
+PIC16TargetObjectFile::SectionForCode(const std::string &FnName,
+                                      bool isISR) const {
   const std::string &sec_name = PAN::getCodeSectionName(FnName);
+  // If it is ISR, its code section starts at a specific address.
+  if (isISR)
+    return getPIC16Section(sec_name, CODE, PAN::getISRAddr());
   return getPIC16Section(sec_name, CODE);
 }