diff options
author | Roman Divacky <rdivacky@FreeBSD.org> | 2009-11-04 14:58:56 +0000 |
---|---|---|
committer | Roman Divacky <rdivacky@FreeBSD.org> | 2009-11-04 14:58:56 +0000 |
commit | 36bf506ad3c99a309ca8bd73bd03563d8d068ac0 (patch) | |
tree | b4dc751bcee540346911aa4115729eff2f991657 /lib/Target/PIC16 | |
parent | f9666f9b3a3d26810deae8cd54feb6e47ecee61a (diff) |
Notes
Diffstat (limited to 'lib/Target/PIC16')
-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/MCSectionPIC16.h | 88 | ||||
-rw-r--r-- | lib/Target/PIC16/PIC16ABINames.h | 6 | ||||
-rw-r--r-- | lib/Target/PIC16/PIC16InstrInfo.cpp | 22 | ||||
-rw-r--r-- | lib/Target/PIC16/PIC16InstrInfo.h | 5 | ||||
-rw-r--r-- | lib/Target/PIC16/PIC16InstrInfo.td | 6 | ||||
-rw-r--r-- | lib/Target/PIC16/PIC16MemSelOpt.cpp | 11 | ||||
-rw-r--r-- | lib/Target/PIC16/PIC16Passes/Makefile | 2 | ||||
-rw-r--r-- | lib/Target/PIC16/PIC16TargetObjectFile.cpp | 26 | ||||
-rw-r--r-- | lib/Target/PIC16/PIC16TargetObjectFile.h | 8 |
11 files changed, 82 insertions, 99 deletions
diff --git a/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.cpp b/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.cpp index ea0f4941da7af..b2a4c1124ee94 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 b13d9ce3aac6b..838c970e1e54a 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/MCSectionPIC16.h b/lib/Target/PIC16/MCSectionPIC16.h deleted file mode 100644 index 352be99d71c2f..0000000000000 --- a/lib/Target/PIC16/MCSectionPIC16.h +++ /dev/null @@ -1,88 +0,0 @@ -//===- MCSectionPIC16.h - PIC16-specific section representation -*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file declares the MCSectionPIC16 class. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_PIC16SECTION_H -#define LLVM_PIC16SECTION_H - -#include "llvm/MC/MCSection.h" - -namespace llvm { - - /// MCSectionPIC16 - Represents a physical section in PIC16 COFF. - /// Contains data objects. - /// - class MCSectionPIC16 : public MCSection { - /// Name of the section to uniquely identify it. - std::string Name; - - /// User can specify an address at which a section should be placed. - /// Negative value here means user hasn't specified any. - int Address; - - /// Overlay information - Sections with same color can be overlaid on - /// one another. - int Color; - - /// Conatined data objects. - std::vector<const GlobalVariable *>Items; - - /// Total size of all data objects contained here. - unsigned Size; - - MCSectionPIC16(const StringRef &name, SectionKind K, int addr, int color) - : MCSection(K), Name(name), Address(addr), Color(color) { - } - - public: - /// Return the name of the section. - const std::string &getName() const { return Name; } - - /// Return the Address of the section. - int getAddress() const { return Address; } - - /// Return the Color of the section. - int getColor() const { return Color; } - - /// PIC16 Terminology for section kinds is as below. - /// UDATA - BSS - /// IDATA - initialized data (equiv to Metadata) - /// ROMDATA - ReadOnly. - /// UDATA_OVR - Sections that can be overlaid. Section of such type is - /// used to contain function autos an frame. We can think of - /// it as equiv to llvm ThreadBSS) - /// So, let's have some convenience functions to Map PIC16 Section types - /// to SectionKind just for the sake of better readability. - static SectionKind UDATA_Kind() { return SectionKind::getBSS(); } - static SectionKind IDATA_Kind() { return SectionKind::getMetadata(); } - static SectionKind ROMDATA_Kind() { return SectionKind::getReadOnly(); } - static SectionKind UDATA_OVR_Kind() { return SectionKind::getThreadBSS(); } - - // If we could just do getKind() == UDATA_Kind() ? - bool isUDATA_Kind() { return getKind().isBSS(); } - bool isIDATA_Kind() { return getKind().isMetadata(); } - bool isROMDATA_Kind() { return getKind().isMetadata(); } - bool isUDATA_OVR_Kind() { return getKind().isThreadBSS(); } - - /// This would be the only way to create a section. - static MCSectionPIC16 *Create(const StringRef &Name, SectionKind K, - int Address, int Color, MCContext &Ctx); - - /// Override this as PIC16 has its own way of printing switching - /// to a section. - virtual void PrintSwitchToSection(const MCAsmInfo &MAI, - raw_ostream &OS) const; - }; - -} // end namespace llvm - -#endif diff --git a/lib/Target/PIC16/PIC16ABINames.h b/lib/Target/PIC16/PIC16ABINames.h index 7f4c2f1cc28ec..e18ddf158ec83 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/PIC16InstrInfo.cpp b/lib/Target/PIC16/PIC16InstrInfo.cpp index 87bd3d9c7e63e..2fb405e947ff8 100644 --- a/lib/Target/PIC16/PIC16InstrInfo.cpp +++ b/lib/Target/PIC16/PIC16InstrInfo.cpp @@ -214,3 +214,25 @@ InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, // returning NULL. return 0; } + +bool PIC16InstrInfo::AnalyzeBranch(MachineBasicBlock &MBB, + MachineBasicBlock *&TBB, + MachineBasicBlock *&FBB, + SmallVectorImpl<MachineOperand> &Cond, + bool AllowModify) const { + MachineBasicBlock::iterator I = MBB.end(); + if (I == MBB.begin()) + return true; + + // Get the terminator instruction. + --I; + // Handle unconditional branches. If the unconditional branch's target is + // successor basic block then remove the unconditional branch. + if (I->getOpcode() == PIC16::br_uncond && AllowModify) { + if (MBB.isLayoutSuccessor(I->getOperand(0).getMBB())) { + TBB = 0; + I->eraseFromParent(); + } + } + return true; +} diff --git a/lib/Target/PIC16/PIC16InstrInfo.h b/lib/Target/PIC16/PIC16InstrInfo.h index 85c098428c980..56f51f00dd804 100644 --- a/lib/Target/PIC16/PIC16InstrInfo.h +++ b/lib/Target/PIC16/PIC16InstrInfo.h @@ -68,7 +68,10 @@ public: unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, MachineBasicBlock *FBB, const SmallVectorImpl<MachineOperand> &Cond) const; - + virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, + MachineBasicBlock *&FBB, + SmallVectorImpl<MachineOperand> &Cond, + bool AllowModify) const; }; } // namespace llvm diff --git a/lib/Target/PIC16/PIC16InstrInfo.td b/lib/Target/PIC16/PIC16InstrInfo.td index 250ca0a373f21..5eec6c4e66b5c 100644 --- a/lib/Target/PIC16/PIC16InstrInfo.td +++ b/lib/Target/PIC16/PIC16InstrInfo.td @@ -467,9 +467,9 @@ def br_uncond: ControlFormat<0x0, (outs), (ins brtarget:$dst), "goto $dst", [(br bb:$dst)]>; -// SELECT_CC_* - Used to implement the SELECT_CC DAG operation. Expanded by the -// scheduler into a branch sequence. -let usesCustomDAGSchedInserter = 1 in { // Expanded by the scheduler. +// SELECT_CC_* - Used to implement the SELECT_CC DAG operation. Expanded after +// instruction selection into a branch sequence. +let usesCustomInserter = 1 in { // Expanded after instruction selection. def SELECT_CC_Int_ICC : Pseudo<(outs GPR:$dst), (ins GPR:$T, GPR:$F, i8imm:$Cond), "; SELECT_CC_Int_ICC PSEUDO!", diff --git a/lib/Target/PIC16/PIC16MemSelOpt.cpp b/lib/Target/PIC16/PIC16MemSelOpt.cpp index a97dc35b137a0..cc71b04cc2021 100644 --- a/lib/Target/PIC16/PIC16MemSelOpt.cpp +++ b/lib/Target/PIC16/PIC16MemSelOpt.cpp @@ -32,12 +32,11 @@ #include "llvm/Target/TargetMachine.h" #include "llvm/GlobalValue.h" #include "llvm/DerivedTypes.h" -#include "llvm/Support/Compiler.h" using namespace llvm; namespace { - struct VISIBILITY_HIDDEN MemSelOpt : public MachineFunctionPass { + struct MemSelOpt : public MachineFunctionPass { static char ID; MemSelOpt() : MachineFunctionPass(&ID) {} @@ -144,7 +143,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 +155,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/PIC16Passes/Makefile b/lib/Target/PIC16/PIC16Passes/Makefile index cbb34b3e5110e..9684b8d2cae40 100644 --- a/lib/Target/PIC16/PIC16Passes/Makefile +++ b/lib/Target/PIC16/PIC16Passes/Makefile @@ -11,7 +11,5 @@ TARGET = PIC16 LIBRARYNAME = LLVMpic16passes BUILD_ARCHIVE = 1 - - include $(LEVEL)/Makefile.common diff --git a/lib/Target/PIC16/PIC16TargetObjectFile.cpp b/lib/Target/PIC16/PIC16TargetObjectFile.cpp index 7eedf7fe2356d..d7cfe029d359d 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; @@ -125,6 +126,7 @@ void PIC16TargetObjectFile::Initialize(MCContext &Ctx, const TargetMachine &tm){ TM = &tm; ROMDATASection_ = NULL; + SHAREDUDATASection_ = NULL; } /// allocateUDATA - Allocate a un-initialized global to an existing or new UDATA @@ -279,7 +281,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 +294,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 ca07bedafe13d..0b0ad43ff9460 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_; } |