diff options
author | Sanjiv Gupta <sanjiv.gupta@microchip.com> | 2009-10-24 18:02:44 +0000 |
---|---|---|
committer | Sanjiv Gupta <sanjiv.gupta@microchip.com> | 2009-10-24 18:02:44 +0000 |
commit | 209e6c69d9f87a07cc840e20344b55982762f3ba (patch) | |
tree | a3ffe287af796dfeada7b4755ed32d26cb0bbc61 | |
parent | c7b1382e351249774be63bd73839e8a0671635e1 (diff) | |
download | external_llvm-209e6c69d9f87a07cc840e20344b55982762f3ba.zip external_llvm-209e6c69d9f87a07cc840e20344b55982762f3ba.tar.gz external_llvm-209e6c69d9f87a07cc840e20344b55982762f3ba.tar.bz2 |
Adding support for placing global objects in shared data memory.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@85006 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.cpp | 6 | ||||
-rw-r--r-- | lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.h | 1 | ||||
-rw-r--r-- | lib/Target/PIC16/PIC16ABINames.h | 6 | ||||
-rw-r--r-- | lib/Target/PIC16/PIC16MemSelOpt.cpp | 8 | ||||
-rw-r--r-- | lib/Target/PIC16/PIC16TargetObjectFile.cpp | 25 | ||||
-rw-r--r-- | lib/Target/PIC16/PIC16TargetObjectFile.h | 8 |
6 files changed, 51 insertions, 3 deletions
diff --git a/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.cpp b/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.cpp index ea0f494..b2a4c11 100644 --- a/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.cpp +++ b/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.cpp @@ -298,6 +298,7 @@ bool PIC16AsmPrinter::doInitialization(Module &M) { EmitIData(M); EmitUData(M); EmitRomData(M); + EmitSharedUdata(M); EmitUserSections(M); return Result; } @@ -370,6 +371,11 @@ void PIC16AsmPrinter::EmitRomData(Module &M) { EmitSingleSection(PTOF->ROMDATASection()); } +// Emit Shared section udata. +void PIC16AsmPrinter::EmitSharedUdata(Module &M) { + EmitSingleSection(PTOF->SHAREDUDATASection()); +} + bool PIC16AsmPrinter::doFinalization(Module &M) { EmitAllAutos(M); printLibcallDecls(); diff --git a/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.h b/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.h index b13d9ce..838c970 100644 --- a/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.h +++ b/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.h @@ -55,6 +55,7 @@ namespace llvm { void EmitUData (Module &M); void EmitAllAutos (Module &M); void EmitRomData (Module &M); + void EmitSharedUdata(Module &M); void EmitUserSections (Module &M); void EmitFunctionFrame(MachineFunction &MF); void printLibcallDecls(); diff --git a/lib/Target/PIC16/PIC16ABINames.h b/lib/Target/PIC16/PIC16ABINames.h index 7f4c2f1..e18ddf1 100644 --- a/lib/Target/PIC16/PIC16ABINames.h +++ b/lib/Target/PIC16/PIC16ABINames.h @@ -234,6 +234,12 @@ namespace llvm { return "romdata.#"; } + static std::string getSharedUDataSectionName() { + std::ostringstream o; + o << getTagName(PREFIX_SYMBOL) << "udata_shr" << ".#"; + return o.str(); + } + static std::string getRomdataSectionName(unsigned num, std::string prefix = "") { std::ostringstream o; diff --git a/lib/Target/PIC16/PIC16MemSelOpt.cpp b/lib/Target/PIC16/PIC16MemSelOpt.cpp index a97dc35..93ccdd2 100644 --- a/lib/Target/PIC16/PIC16MemSelOpt.cpp +++ b/lib/Target/PIC16/PIC16MemSelOpt.cpp @@ -144,7 +144,7 @@ bool MemSelOpt::processInstruction(MachineInstr *MI) { } // Get the section name(NewBank) for MemOp. - // This assumes that the section names for globals are laready set by + // This assumes that the section names for globals are already set by // AsmPrinter->doInitialization. std::string NewBank = CurBank; if (Op.getType() == MachineOperand::MO_GlobalAddress && @@ -156,7 +156,11 @@ bool MemSelOpt::processInstruction(MachineInstr *MI) { std::string Sym = Op.getSymbolName(); NewBank = PAN::getSectionNameForSym(Sym); } - + + // If the section is shared section, do not emit banksel. + if (NewBank == PAN::getSharedUDataSectionName()) + return Changed; + // If the previous and new section names are same, we don't need to // emit banksel. if (NewBank.compare(CurBank) != 0 ) { diff --git a/lib/Target/PIC16/PIC16TargetObjectFile.cpp b/lib/Target/PIC16/PIC16TargetObjectFile.cpp index 7eedf7f..846715d 100644 --- a/lib/Target/PIC16/PIC16TargetObjectFile.cpp +++ b/lib/Target/PIC16/PIC16TargetObjectFile.cpp @@ -72,6 +72,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; @@ -279,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. @@ -289,6 +293,25 @@ 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 { diff --git a/lib/Target/PIC16/PIC16TargetObjectFile.h b/lib/Target/PIC16/PIC16TargetObjectFile.h index ca07bed..0b0ad43 100644 --- a/lib/Target/PIC16/PIC16TargetObjectFile.h +++ b/lib/Target/PIC16/PIC16TargetObjectFile.h @@ -56,6 +56,7 @@ namespace llvm { mutable std::vector<PIC16Section *> UDATASections_; mutable std::vector<PIC16Section *> IDATASections_; mutable PIC16Section * ROMDATASection_; + mutable PIC16Section * SHAREDUDATASection_; /// Standard Auto Sections. mutable std::vector<PIC16Section *> AUTOSections_; @@ -110,6 +111,10 @@ namespace llvm { /// Allocate DATA at user specified address. const MCSection *allocateAtGivenAddress(const GlobalVariable *GV, const std::string &Addr) const; + + /// Allocate a shared variable to SHARED section. + const MCSection *allocateSHARED(const GlobalVariable *GV, + Mangler *Mang) const; public: PIC16TargetObjectFile(); @@ -147,6 +152,9 @@ namespace llvm { const PIC16Section *ROMDATASection() const { return ROMDATASection_; } + const PIC16Section *SHAREDUDATASection() const { + return SHAREDUDATASection_; + } const std::vector<PIC16Section *> &AUTOSections() const { return AUTOSections_; } |