From: Chris Lattner
Date: Mon, 11 Oct 2010 05:44:40 +0000 (+0000)
Subject: Per discussion with Sanjiv, remove the PIC16 target from mainline. When/if
X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=60cb528246dd01b80b1b1260a2a877ea488e620a;p=oota-llvm.git
Per discussion with Sanjiv, remove the PIC16 target from mainline. When/if
it comes back, it will be largely a rewrite, so keeping the old codebase
in tree isn't helping anyone.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@116190 91177308-0d34-0410-b5e6-96231b3b80d8
---
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d473f51b59b..414c32e0056 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -64,7 +64,6 @@ set(LLVM_ALL_TARGETS
Mips
MBlaze
MSP430
- PIC16
PowerPC
PTX
Sparc
@@ -342,11 +341,6 @@ foreach(t ${LLVM_TARGETS_TO_BUILD})
set(CURRENT_LLVM_TARGET)
endforeach(t)
-# PIC16 contains an odd library:
-if( LLVM_TARGETS_TO_BUILD MATCHES ".*PIC16.*" )
- add_subdirectory(lib/Target/PIC16/PIC16Passes)
-endif()
-
# Produce llvm/Config/AsmPrinters.def
configure_file(
${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmPrinters.def.in
diff --git a/cmake/config-ix.cmake b/cmake/config-ix.cmake
index b84fa5d6808..16c17e20ec9 100755
--- a/cmake/config-ix.cmake
+++ b/cmake/config-ix.cmake
@@ -197,8 +197,6 @@ elseif (LLVM_NATIVE_ARCH MATCHES "arm")
set(LLVM_NATIVE_ARCH ARM)
elseif (LLVM_NATIVE_ARCH MATCHES "mips")
set(LLVM_NATIVE_ARCH Mips)
-elseif (LLVM_NATIVE_ARCH MATCHES "pic16")
- set(LLVM_NATIVE_ARCH "PIC16")
elseif (LLVM_NATIVE_ARCH MATCHES "xcore")
set(LLVM_NATIVE_ARCH XCore)
elseif (LLVM_NATIVE_ARCH MATCHES "msp430")
diff --git a/cmake/modules/LLVMLibDeps.cmake b/cmake/modules/LLVMLibDeps.cmake
index 77b2bcf2d42..67a016c641a 100644
--- a/cmake/modules/LLVMLibDeps.cmake
+++ b/cmake/modules/LLVMLibDeps.cmake
@@ -34,7 +34,7 @@ set(MSVC_LIB_DEPS_LLVMMBlazeAsmPrinter LLVMAsmPrinter LLVMCodeGen LLVMCore LLVMM
set(MSVC_LIB_DEPS_LLVMMBlazeCodeGen LLVMCodeGen LLVMCore LLVMMBlazeInfo LLVMMC LLVMSelectionDAG LLVMSupport LLVMSystem LLVMTarget)
set(MSVC_LIB_DEPS_LLVMMBlazeInfo LLVMSupport)
set(MSVC_LIB_DEPS_LLVMMC LLVMSupport LLVMSystem)
-set(MSVC_LIB_DEPS_LLVMMCDisassembler LLVMARMAsmParser LLVMARMCodeGen LLVMARMDisassembler LLVMARMInfo LLVMAlphaAsmPrinter LLVMAlphaCodeGen LLVMAlphaInfo LLVMBlackfinAsmPrinter LLVMBlackfinCodeGen LLVMBlackfinInfo LLVMCBackend LLVMCBackendInfo LLVMCellSPUAsmPrinter LLVMCellSPUCodeGen LLVMCellSPUInfo LLVMCppBackend LLVMCppBackendInfo LLVMMBlazeAsmPrinter LLVMMBlazeCodeGen LLVMMBlazeInfo LLVMMC LLVMMCParser LLVMMSP430CodeGen LLVMMSP430Info LLVMMipsAsmPrinter LLVMMipsCodeGen LLVMMipsInfo LLVMPIC16AsmPrinter LLVMPIC16CodeGen LLVMPIC16Info LLVMPTXAsmPrinter LLVMPTXCodeGen LLVMPTXInfo LLVMPowerPCAsmPrinter LLVMPowerPCCodeGen LLVMPowerPCInfo LLVMSparcAsmPrinter LLVMSparcCodeGen LLVMSparcInfo LLVMSupport LLVMSystem LLVMSystemZAsmPrinter LLVMSystemZCodeGen LLVMSystemZInfo LLVMX86AsmParser LLVMX86CodeGen LLVMX86Disassembler LLVMX86Info LLVMXCoreAsmPrinter LLVMXCoreCodeGen LLVMXCoreInfo)
+set(MSVC_LIB_DEPS_LLVMMCDisassembler LLVMARMAsmParser LLVMARMCodeGen LLVMARMDisassembler LLVMARMInfo LLVMAlphaAsmPrinter LLVMAlphaCodeGen LLVMAlphaInfo LLVMBlackfinAsmPrinter LLVMBlackfinCodeGen LLVMBlackfinInfo LLVMCBackend LLVMCBackendInfo LLVMCellSPUAsmPrinter LLVMCellSPUCodeGen LLVMCellSPUInfo LLVMCppBackend LLVMCppBackendInfo LLVMMBlazeAsmPrinter LLVMMBlazeCodeGen LLVMMBlazeInfo LLVMMC LLVMMCParser LLVMMSP430CodeGen LLVMMSP430Info LLVMMipsAsmPrinter LLVMMipsCodeGen LLVMMipsInfo LLVMPTXAsmPrinter LLVMPTXCodeGen LLVMPTXInfo LLVMPowerPCAsmPrinter LLVMPowerPCCodeGen LLVMPowerPCInfo LLVMSparcAsmPrinter LLVMSparcCodeGen LLVMSparcInfo LLVMSupport LLVMSystem LLVMSystemZAsmPrinter LLVMSystemZCodeGen LLVMSystemZInfo LLVMX86AsmParser LLVMX86CodeGen LLVMX86Disassembler LLVMX86Info LLVMXCoreAsmPrinter LLVMXCoreCodeGen LLVMXCoreInfo)
set(MSVC_LIB_DEPS_LLVMMCParser LLVMMC LLVMSupport)
set(MSVC_LIB_DEPS_LLVMMSP430AsmPrinter LLVMMC LLVMSupport)
set(MSVC_LIB_DEPS_LLVMMSP430CodeGen LLVMAsmPrinter LLVMCodeGen LLVMCore LLVMMC LLVMMSP430AsmPrinter LLVMMSP430Info LLVMSelectionDAG LLVMSupport LLVMSystem LLVMTarget)
@@ -42,10 +42,6 @@ set(MSVC_LIB_DEPS_LLVMMSP430Info LLVMSupport)
set(MSVC_LIB_DEPS_LLVMMipsAsmPrinter LLVMAsmPrinter LLVMCodeGen LLVMCore LLVMMC LLVMMipsCodeGen LLVMMipsInfo LLVMSupport LLVMTarget)
set(MSVC_LIB_DEPS_LLVMMipsCodeGen LLVMCodeGen LLVMCore LLVMMC LLVMMipsInfo LLVMSelectionDAG LLVMSupport LLVMSystem LLVMTarget)
set(MSVC_LIB_DEPS_LLVMMipsInfo LLVMSupport)
-set(MSVC_LIB_DEPS_LLVMPIC16AsmPrinter LLVMAsmPrinter LLVMCodeGen LLVMCore LLVMMC LLVMPIC16CodeGen LLVMPIC16Info LLVMSupport LLVMTarget)
-set(MSVC_LIB_DEPS_LLVMPIC16CodeGen LLVMAnalysis LLVMCodeGen LLVMCore LLVMMC LLVMPIC16Info LLVMSelectionDAG LLVMSupport LLVMTarget)
-set(MSVC_LIB_DEPS_LLVMPIC16Info LLVMSupport)
-set(MSVC_LIB_DEPS_LLVMPIC16Passes LLVMCore LLVMSupport LLVMSystem LLVMTransformUtils LLVMipa)
set(MSVC_LIB_DEPS_LLVMPTXAsmPrinter LLVMAsmPrinter LLVMCodeGen LLVMCore LLVMPTXCodeGen LLVMPTXInfo LLVMSupport)
set(MSVC_LIB_DEPS_LLVMPTXCodeGen LLVMCodeGen LLVMCore LLVMMC LLVMPTXInfo LLVMSelectionDAG LLVMSupport LLVMTarget)
set(MSVC_LIB_DEPS_LLVMPTXInfo LLVMSupport)
diff --git a/configure b/configure
index ba31b9650cc..365c1d76798 100755
--- a/configure
+++ b/configure
@@ -2356,7 +2356,6 @@ else
alpha*-*) llvm_cv_target_arch="Alpha" ;;
arm*-*) llvm_cv_target_arch="ARM" ;;
mips-*) llvm_cv_target_arch="Mips" ;;
- pic16-*) llvm_cv_target_arch="PIC16" ;;
xcore-*) llvm_cv_target_arch="XCore" ;;
msp430-*) llvm_cv_target_arch="MSP430" ;;
s390x-*) llvm_cv_target_arch="SystemZ" ;;
@@ -4817,8 +4816,6 @@ else
ARM) TARGET_HAS_JIT=1
;;
Mips) TARGET_HAS_JIT=0
- ;;
- PIC16) TARGET_HAS_JIT=0
;;
XCore) TARGET_HAS_JIT=0
;;
@@ -4959,7 +4956,7 @@ if test "$enableval" = host-only ; then
enableval=host
fi
case "$enableval" in
- all) TARGETS_TO_BUILD="X86 Sparc PowerPC Alpha ARM Mips CellSPU PIC16 XCore MSP430 SystemZ Blackfin CBackend CppBackend MBlaze PTX" ;;
+ all) TARGETS_TO_BUILD="X86 Sparc PowerPC Alpha ARM Mips CellSPU XCore MSP430 SystemZ Blackfin CBackend CppBackend MBlaze PTX" ;;
*)for a_target in `echo $enableval|sed -e 's/,/ /g' ` ; do
case "$a_target" in
x86) TARGETS_TO_BUILD="X86 $TARGETS_TO_BUILD" ;;
@@ -4970,7 +4967,6 @@ case "$enableval" in
arm) TARGETS_TO_BUILD="ARM $TARGETS_TO_BUILD" ;;
mips) TARGETS_TO_BUILD="Mips $TARGETS_TO_BUILD" ;;
spu) TARGETS_TO_BUILD="CellSPU $TARGETS_TO_BUILD" ;;
- pic16) TARGETS_TO_BUILD="PIC16 $TARGETS_TO_BUILD" ;;
xcore) TARGETS_TO_BUILD="XCore $TARGETS_TO_BUILD" ;;
msp430) TARGETS_TO_BUILD="MSP430 $TARGETS_TO_BUILD" ;;
systemz) TARGETS_TO_BUILD="SystemZ $TARGETS_TO_BUILD" ;;
@@ -4989,7 +4985,6 @@ case "$enableval" in
Mips) TARGETS_TO_BUILD="Mips $TARGETS_TO_BUILD" ;;
MBlaze) TARGETS_TO_BUILD="MBlaze $TARGETS_TO_BUILD" ;;
CellSPU|SPU) TARGETS_TO_BUILD="CellSPU $TARGETS_TO_BUILD" ;;
- PIC16) TARGETS_TO_BUILD="PIC16 $TARGETS_TO_BUILD" ;;
XCore) TARGETS_TO_BUILD="XCore $TARGETS_TO_BUILD" ;;
MSP430) TARGETS_TO_BUILD="MSP430 $TARGETS_TO_BUILD" ;;
s390x) TARGETS_TO_BUILD="SystemZ $TARGETS_TO_BUILD" ;;
diff --git a/docs/ReleaseNotes.html b/docs/ReleaseNotes.html
index 826540afae8..cc6937ebd8a 100644
--- a/docs/ReleaseNotes.html
+++ b/docs/ReleaseNotes.html
@@ -1103,7 +1103,7 @@ components, please contact us on the LLVMdev list.
-- The Alpha, Blackfin, CellSPU, MicroBlaze, MSP430, MIPS, PIC16, SystemZ
+
- The Alpha, Blackfin, CellSPU, MicroBlaze, MSP430, MIPS, SystemZ
and XCore backends are experimental.
- llc "-filetype=obj" is experimental on all targets
other than darwin-i386 and darwin-x86_64.
diff --git a/include/llvm/MC/MCSection.h b/include/llvm/MC/MCSection.h
index 3e5b5f13f32..b741216f94a 100644
--- a/include/llvm/MC/MCSection.h
+++ b/include/llvm/MC/MCSection.h
@@ -32,8 +32,7 @@ namespace llvm {
enum SectionVariant {
SV_COFF = 0,
SV_ELF,
- SV_MachO,
- SV_PIC16
+ SV_MachO
};
private:
diff --git a/lib/CodeGen/VirtRegRewriter.cpp b/lib/CodeGen/VirtRegRewriter.cpp
index 8b8fc73608b..f44eccd40cc 100644
--- a/lib/CodeGen/VirtRegRewriter.cpp
+++ b/lib/CodeGen/VirtRegRewriter.cpp
@@ -297,7 +297,7 @@ ComputeReloadLoc(MachineBasicBlock::iterator const InsertLoc,
const TargetLowering *TL = MF.getTarget().getTargetLowering();
if (!TL->isTypeLegal(TL->getPointerTy()))
- // Believe it or not, this is true on PIC16.
+ // Believe it or not, this is true on 16-bit targets like PIC16.
return InsertLoc;
const TargetRegisterClass *ptrRegClass =
diff --git a/lib/Target/PIC16/AsmPrinter/CMakeLists.txt b/lib/Target/PIC16/AsmPrinter/CMakeLists.txt
deleted file mode 100644
index f24c78a59d2..00000000000
--- a/lib/Target/PIC16/AsmPrinter/CMakeLists.txt
+++ /dev/null
@@ -1,10 +0,0 @@
-include_directories(
- ${CMAKE_CURRENT_BINARY_DIR}/..
- ${CMAKE_CURRENT_SOURCE_DIR}/..
- )
-
-add_llvm_library(LLVMPIC16AsmPrinter
- PIC16AsmPrinter.cpp
- )
-
-add_dependencies(LLVMPIC16AsmPrinter PIC16CodeGenTable_gen)
diff --git a/lib/Target/PIC16/AsmPrinter/Makefile b/lib/Target/PIC16/AsmPrinter/Makefile
deleted file mode 100644
index e3c0684ebcf..00000000000
--- a/lib/Target/PIC16/AsmPrinter/Makefile
+++ /dev/null
@@ -1,15 +0,0 @@
-##===- lib/Target/PIC16/AsmPrinter/Makefile ----------------*- Makefile -*-===##
-#
-# The LLVM Compiler Infrastructure
-#
-# This file is distributed under the University of Illinois Open Source
-# License. See LICENSE.TXT for details.
-#
-##===----------------------------------------------------------------------===##
-LEVEL = ../../../..
-LIBRARYNAME = LLVMPIC16AsmPrinter
-
-# Hack: we need to include 'main' pic16 target directory to grab private headers
-CPP.Flags += -I$(PROJ_OBJ_DIR)/.. -I$(PROJ_SRC_DIR)/..
-
-include $(LEVEL)/Makefile.common
diff --git a/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.cpp b/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.cpp
deleted file mode 100644
index b665817e614..00000000000
--- a/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.cpp
+++ /dev/null
@@ -1,512 +0,0 @@
-//===-- PIC16AsmPrinter.cpp - PIC16 LLVM assembly writer ------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file contains a printer that converts from our internal representation
-// of machine-dependent LLVM code to PIC16 assembly language.
-//
-//===----------------------------------------------------------------------===//
-
-#include "PIC16ABINames.h"
-#include "PIC16AsmPrinter.h"
-#include "PIC16Section.h"
-#include "PIC16MCAsmInfo.h"
-#include "PIC16MachineFunctionInfo.h"
-#include "llvm/DerivedTypes.h"
-#include "llvm/Function.h"
-#include "llvm/Module.h"
-#include "llvm/CodeGen/MachineFrameInfo.h"
-#include "llvm/CodeGen/MachineModuleInfo.h"
-#include "llvm/MC/MCStreamer.h"
-#include "llvm/MC/MCSymbol.h"
-#include "llvm/Target/Mangler.h"
-#include "llvm/Target/TargetRegistry.h"
-#include "llvm/Target/TargetLoweringObjectFile.h"
-#include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/raw_ostream.h"
-#include "llvm/ADT/SmallString.h"
-#include
-using namespace llvm;
-
-#include "PIC16GenAsmWriter.inc"
-
-PIC16AsmPrinter::PIC16AsmPrinter(TargetMachine &TM, MCStreamer &Streamer)
-: AsmPrinter(TM, Streamer), DbgInfo(Streamer, TM.getMCAsmInfo()) {
- PMAI = static_cast(TM.getMCAsmInfo());
- PTOF = &getObjFileLowering();
-}
-
-void PIC16AsmPrinter::EmitInstruction(const MachineInstr *MI) {
- SmallString<128> Str;
- raw_svector_ostream OS(Str);
- printInstruction(MI, OS);
-
- OutStreamer.EmitRawText(OS.str());
-}
-
-static int getFunctionColor(const Function *F) {
- if (F->hasSection()) {
- std::string Sectn = F->getSection();
- std::string StrToFind = "Overlay=";
- std::string::size_type Pos = Sectn.find(StrToFind);
-
- // Retreive the color number if the key is found.
- if (Pos != std::string::npos) {
- Pos += StrToFind.length();
- std::string Color = "";
- char c = Sectn.at(Pos);
- // A Color can only consist of digits.
- while (c >= '0' && c<= '9') {
- Color.append(1,c);
- Pos++;
- if (Pos >= Sectn.length())
- break;
- c = Sectn.at(Pos);
- }
- return atoi(Color.c_str());
- }
- }
-
- // Color was not set for function, so return -1.
- return -1;
-}
-
-// Color the Auto section of the given function.
-void PIC16AsmPrinter::ColorAutoSection(const Function *F) {
- std::string SectionName = PAN::getAutosSectionName(CurrentFnSym->getName());
- PIC16Section* Section = PTOF->findPIC16Section(SectionName);
- if (Section != NULL) {
- int Color = getFunctionColor(F);
- if (Color >= 0)
- Section->setColor(Color);
- }
-}
-
-
-/// runOnMachineFunction - This emits the frame section, autos section and
-/// assembly for each instruction. Also takes care of function begin debug
-/// directive and file begin debug directive (if required) for the function.
-///
-bool PIC16AsmPrinter::runOnMachineFunction(MachineFunction &MF) {
- // This calls the base class function required to be called at beginning
- // of runOnMachineFunction.
- SetupMachineFunction(MF);
-
- // Put the color information from function to its auto section.
- const Function *F = MF.getFunction();
- ColorAutoSection(F);
-
- // Emit the function frame (args and temps).
- EmitFunctionFrame(MF);
-
- DbgInfo.BeginFunction(MF);
-
- // Now emit the instructions of function in its code section.
- const MCSection *fCodeSection =
- getObjFileLowering().SectionForCode(CurrentFnSym->getName(),
- PAN::isISR(F->getSection()));
-
- // Start the Code Section.
- OutStreamer.SwitchSection(fCodeSection);
-
- // Emit the frame address of the function at the beginning of code.
- OutStreamer.EmitRawText("\tretlw low(" +
- Twine(PAN::getFrameLabel(CurrentFnSym->getName())) +
- ")");
- OutStreamer.EmitRawText("\tretlw high(" +
- Twine(PAN::getFrameLabel(CurrentFnSym->getName())) +
- ")");
-
- // Emit function start label.
- OutStreamer.EmitLabel(CurrentFnSym);
-
- DebugLoc CurDL;
- // Print out code for the function.
- for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
- I != E; ++I) {
-
- // Print a label for the basic block.
- if (I != MF.begin())
- EmitBasicBlockStart(I);
-
- // Print a basic block.
- for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
- II != E; ++II) {
- // Emit the line directive if source line changed.
- DebugLoc DL = II->getDebugLoc();
- if (!DL.isUnknown() && DL != CurDL) {
- DbgInfo.ChangeDebugLoc(MF, DL);
- CurDL = DL;
- }
-
- // Print the assembly for the instruction.
- EmitInstruction(II);
- }
- }
-
- // Emit function end debug directives.
- DbgInfo.EndFunction(MF);
-
- return false; // we didn't modify anything.
-}
-
-
-// printOperand - print operand of insn.
-void PIC16AsmPrinter::printOperand(const MachineInstr *MI, int opNum,
- raw_ostream &O) {
- const MachineOperand &MO = MI->getOperand(opNum);
- const Function *F = MI->getParent()->getParent()->getFunction();
-
- switch (MO.getType()) {
- case MachineOperand::MO_Register:
- {
- // For indirect load/store insns, the fsr name is printed as INDF.
- std::string RegName = getRegisterName(MO.getReg());
- if ((MI->getOpcode() == PIC16::load_indirect) ||
- (MI->getOpcode() == PIC16::store_indirect))
- RegName.replace (0, 3, "INDF");
- O << RegName;
- }
- return;
-
- case MachineOperand::MO_Immediate:
- O << (int)MO.getImm();
- return;
-
- case MachineOperand::MO_GlobalAddress: {
- MCSymbol *Sym = Mang->getSymbol(MO.getGlobal());
- // FIXME: currently we do not have a memcpy def coming in the module
- // by any chance, as we do not link in those as .bc lib. So these calls
- // are always external and it is safe to emit an extern.
- if (PAN::isMemIntrinsic(Sym->getName()))
- LibcallDecls.insert(Sym->getName());
-
- O << *Sym;
- break;
- }
- case MachineOperand::MO_ExternalSymbol: {
- const char *Sname = MO.getSymbolName();
- std::string Printname = Sname;
-
- // Intrinsic stuff needs to be renamed if we are printing IL fn.
- if (PAN::isIntrinsicStuff(Printname)) {
- if (PAN::isISR(F->getSection())) {
- Printname = PAN::Rename(Sname);
- }
- // Record these decls, we need to print them in asm as extern.
- LibcallDecls.insert(Printname);
- }
-
- O << Printname;
- break;
- }
- case MachineOperand::MO_MachineBasicBlock:
- O << *MO.getMBB()->getSymbol();
- return;
-
- default:
- llvm_unreachable(" Operand type not supported.");
- }
-}
-
-/// printCCOperand - Print the cond code operand.
-///
-void PIC16AsmPrinter::printCCOperand(const MachineInstr *MI, int opNum,
- raw_ostream &O) {
- int CC = (int)MI->getOperand(opNum).getImm();
- O << PIC16CondCodeToString((PIC16CC::CondCodes)CC);
-}
-
-/// printLibcallDecls - print the extern declarations for compiler
-/// intrinsics.
-///
-void PIC16AsmPrinter::printLibcallDecls() {
- // If no libcalls used, return.
- if (LibcallDecls.empty()) return;
-
- OutStreamer.AddComment("External decls for libcalls - BEGIN");
- OutStreamer.AddBlankLine();
-
- for (std::set::const_iterator I = LibcallDecls.begin(),
- E = LibcallDecls.end(); I != E; I++)
- OutStreamer.EmitRawText(MAI->getExternDirective() + Twine(*I));
-
- OutStreamer.AddComment("External decls for libcalls - END");
- OutStreamer.AddBlankLine();
-}
-
-/// doInitialization - Perform Module level initializations here.
-/// One task that we do here is to sectionize all global variables.
-/// The MemSelOptimizer pass depends on the sectionizing.
-///
-bool PIC16AsmPrinter::doInitialization(Module &M) {
- bool Result = AsmPrinter::doInitialization(M);
-
- // Every asmbly contains these std headers.
- OutStreamer.EmitRawText(StringRef("\n#include p16f1xxx.inc"));
- OutStreamer.EmitRawText(StringRef("#include stdmacros.inc"));
-
- // Set the section names for all globals.
- for (Module::global_iterator I = M.global_begin(), E = M.global_end();
- I != E; ++I) {
-
- // Record External Var Decls.
- if (I->isDeclaration()) {
- ExternalVarDecls.push_back(I);
- continue;
- }
-
- // Record Exteranl Var Defs.
- if (I->hasExternalLinkage() || I->hasCommonLinkage()) {
- ExternalVarDefs.push_back(I);
- }
-
- // Sectionify actual data.
- if (!I->hasAvailableExternallyLinkage()) {
- const MCSection *S = getObjFileLowering().SectionForGlobal(I, Mang, TM);
-
- I->setSection(((const PIC16Section *)S)->getName());
- }
- }
-
- DbgInfo.BeginModule(M);
- EmitFunctionDecls(M);
- EmitUndefinedVars(M);
- EmitDefinedVars(M);
- EmitIData(M);
- EmitUData(M);
- EmitRomData(M);
- EmitSharedUdata(M);
- EmitUserSections(M);
- return Result;
-}
-
-/// Emit extern decls for functions imported from other modules, and emit
-/// global declarations for function defined in this module and which are
-/// available to other modules.
-///
-void PIC16AsmPrinter::EmitFunctionDecls(Module &M) {
- // Emit declarations for external functions.
- OutStreamer.AddComment("Function Declarations - BEGIN");
- OutStreamer.AddBlankLine();
- for (Module::iterator I = M.begin(), E = M.end(); I != E; I++) {
- if (I->isIntrinsic() || I->getName() == "@abort")
- continue;
-
- if (!I->isDeclaration() && !I->hasExternalLinkage())
- continue;
-
- MCSymbol *Sym = Mang->getSymbol(I);
-
- // Do not emit memcpy, memset, and memmove here.
- // Calls to these routines can be generated in two ways,
- // 1. User calling the standard lib function
- // 2. Codegen generating these calls for llvm intrinsics.
- // In the first case a prototype is alread availale, while in
- // second case the call is via and externalsym and the prototype is missing.
- // So declarations for these are currently always getting printing by
- // tracking both kind of references in printInstrunction.
- if (I->isDeclaration() && PAN::isMemIntrinsic(Sym->getName())) continue;
-
- const char *directive = I->isDeclaration() ? MAI->getExternDirective() :
- MAI->getGlobalDirective();
-
- OutStreamer.EmitRawText(directive + Twine(Sym->getName()));
- OutStreamer.EmitRawText(directive +
- Twine(PAN::getRetvalLabel(Sym->getName())));
- OutStreamer.EmitRawText(directive +
- Twine(PAN::getArgsLabel(Sym->getName())));
- }
-
- OutStreamer.AddComment("Function Declarations - END");
- OutStreamer.AddBlankLine();
-
-}
-
-// Emit variables imported from other Modules.
-void PIC16AsmPrinter::EmitUndefinedVars(Module &M) {
- std::vector Items = ExternalVarDecls;
- if (!Items.size()) return;
-
- OutStreamer.AddComment("Imported Variables - BEGIN");
- OutStreamer.AddBlankLine();
- for (unsigned j = 0; j < Items.size(); j++)
- OutStreamer.EmitRawText(MAI->getExternDirective() +
- Twine(Mang->getSymbol(Items[j])->getName()));
-
- OutStreamer.AddComment("Imported Variables - END");
- OutStreamer.AddBlankLine();
-}
-
-// Emit variables defined in this module and are available to other modules.
-void PIC16AsmPrinter::EmitDefinedVars(Module &M) {
- std::vector Items = ExternalVarDefs;
- if (!Items.size()) return;
-
- OutStreamer.AddComment("Exported Variables - BEGIN");
- OutStreamer.AddBlankLine();
-
- for (unsigned j = 0; j < Items.size(); j++)
- OutStreamer.EmitRawText(MAI->getGlobalDirective() +
- Twine(Mang->getSymbol(Items[j])->getName()));
- OutStreamer.AddComment("Exported Variables - END");
- OutStreamer.AddBlankLine();
-}
-
-// Emit initialized data placed in ROM.
-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();
- DbgInfo.EndModule(M);
- OutStreamer.EmitRawText(StringRef("\tEND"));
- return AsmPrinter::doFinalization(M);
-}
-
-void PIC16AsmPrinter::EmitFunctionFrame(MachineFunction &MF) {
- const Function *F = MF.getFunction();
- const TargetData *TD = TM.getTargetData();
- PIC16MachineFunctionInfo *FuncInfo = MF.getInfo();
-
- // Emit the data section name.
-
- PIC16Section *fPDataSection =
- const_cast(getObjFileLowering().
- SectionForFrame(CurrentFnSym->getName()));
-
- fPDataSection->setColor(getFunctionColor(F));
- OutStreamer.SwitchSection(fPDataSection);
-
- // Emit function frame label
- OutStreamer.EmitRawText(PAN::getFrameLabel(CurrentFnSym->getName()) +
- Twine(":"));
-
- const Type *RetType = F->getReturnType();
- unsigned RetSize = 0;
- if (RetType->getTypeID() != Type::VoidTyID)
- RetSize = TD->getTypeAllocSize(RetType);
-
- //Emit function return value space
- // FIXME: Do not emit RetvalLable when retsize is zero. To do this
- // we will need to avoid printing a global directive for Retval label
- // in emitExternandGloblas.
- if(RetSize > 0)
- OutStreamer.EmitRawText(PAN::getRetvalLabel(CurrentFnSym->getName()) +
- Twine(" RES ") + Twine(RetSize));
- else
- OutStreamer.EmitRawText(PAN::getRetvalLabel(CurrentFnSym->getName()) +
- Twine(":"));
-
- // Emit variable to hold the space for function arguments
- unsigned ArgSize = 0;
- for (Function::const_arg_iterator argi = F->arg_begin(),
- arge = F->arg_end(); argi != arge ; ++argi) {
- const Type *Ty = argi->getType();
- ArgSize += TD->getTypeAllocSize(Ty);
- }
-
- OutStreamer.EmitRawText(PAN::getArgsLabel(CurrentFnSym->getName()) +
- Twine(" RES ") + Twine(ArgSize));
-
- // Emit temporary space
- int TempSize = FuncInfo->getTmpSize();
- if (TempSize > 0)
- OutStreamer.EmitRawText(PAN::getTempdataLabel(CurrentFnSym->getName()) +
- Twine(" RES ") + Twine(TempSize));
-}
-
-
-void PIC16AsmPrinter::EmitInitializedDataSection(const PIC16Section *S) {
- /// Emit Section header.
- OutStreamer.SwitchSection(S);
-
- std::vector Items = S->Items;
- for (unsigned j = 0; j < Items.size(); j++) {
- Constant *C = Items[j]->getInitializer();
- int AddrSpace = Items[j]->getType()->getAddressSpace();
- OutStreamer.EmitRawText(Mang->getSymbol(Items[j])->getName());
- EmitGlobalConstant(C, AddrSpace);
- }
-}
-
-// Print all IDATA sections.
-void PIC16AsmPrinter::EmitIData(Module &M) {
- EmitSectionList (M, PTOF->IDATASections());
-}
-
-void PIC16AsmPrinter::
-EmitUninitializedDataSection(const PIC16Section *S) {
- const TargetData *TD = TM.getTargetData();
- OutStreamer.SwitchSection(S);
- std::vector Items = S->Items;
- for (unsigned j = 0; j < Items.size(); j++) {
- Constant *C = Items[j]->getInitializer();
- const Type *Ty = C->getType();
- unsigned Size = TD->getTypeAllocSize(Ty);
- OutStreamer.EmitRawText(Mang->getSymbol(Items[j])->getName() +
- Twine(" RES ") + Twine(Size));
- }
-}
-
-// Print all UDATA sections.
-void PIC16AsmPrinter::EmitUData(Module &M) {
- EmitSectionList (M, PTOF->UDATASections());
-}
-
-// Print all USER sections.
-void PIC16AsmPrinter::EmitUserSections(Module &M) {
- EmitSectionList (M, PTOF->USERSections());
-}
-
-// Print all AUTO sections.
-void PIC16AsmPrinter::EmitAllAutos(Module &M) {
- EmitSectionList (M, PTOF->AUTOSections());
-}
-
-extern "C" void LLVMInitializePIC16AsmPrinter() {
- RegisterAsmPrinter X(ThePIC16Target);
-}
-
-// Emit one data section using correct section emitter based on section type.
-void PIC16AsmPrinter::EmitSingleSection(const PIC16Section *S) {
- if (S == NULL) return;
-
- switch (S->getType()) {
- default: llvm_unreachable ("unknow user section type");
- case UDATA:
- case UDATA_SHR:
- case UDATA_OVR:
- EmitUninitializedDataSection(S);
- break;
- case IDATA:
- case ROMDATA:
- EmitInitializedDataSection(S);
- break;
- }
-}
-
-// Emit a list of sections.
-void PIC16AsmPrinter::
-EmitSectionList(Module &M, const std::vector &SList) {
- for (unsigned i = 0; i < SList.size(); i++) {
- // Exclude llvm specific metadata sections.
- if (SList[i]->getName().find("llvm.") != std::string::npos)
- continue;
- OutStreamer.AddBlankLine();
- EmitSingleSection(SList[i]);
- }
-}
-
diff --git a/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.h b/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.h
deleted file mode 100644
index aa2e1f4f486..00000000000
--- a/lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.h
+++ /dev/null
@@ -1,88 +0,0 @@
-//===-- PIC16AsmPrinter.h - PIC16 LLVM assembly writer ----------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file contains a printer that converts from our internal representation
-// of machine-dependent LLVM code to PIC16 assembly language.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef PIC16ASMPRINTER_H
-#define PIC16ASMPRINTER_H
-
-#include "PIC16.h"
-#include "PIC16TargetMachine.h"
-#include "PIC16DebugInfo.h"
-#include "PIC16MCAsmInfo.h"
-#include "PIC16TargetObjectFile.h"
-#include "llvm/Analysis/DebugInfo.h"
-#include "llvm/CodeGen/AsmPrinter.h"
-#include "llvm/Support/CommandLine.h"
-#include "llvm/Target/TargetMachine.h"
-#include
-#include
-#include
-
-namespace llvm {
- class LLVM_LIBRARY_VISIBILITY PIC16AsmPrinter : public AsmPrinter {
- public:
- explicit PIC16AsmPrinter(TargetMachine &TM, MCStreamer &Streamer);
- private:
- virtual const char *getPassName() const {
- return "PIC16 Assembly Printer";
- }
-
- const PIC16TargetObjectFile &getObjFileLowering() const {
- return (const PIC16TargetObjectFile &)AsmPrinter::getObjFileLowering();
- }
-
- bool runOnMachineFunction(MachineFunction &F);
- void printOperand(const MachineInstr *MI, int opNum, raw_ostream &O);
- void printCCOperand(const MachineInstr *MI, int opNum, raw_ostream &O);
- void printInstruction(const MachineInstr *MI, raw_ostream &O);
- static const char *getRegisterName(unsigned RegNo);
-
- void EmitInstruction(const MachineInstr *MI);
- void EmitFunctionDecls (Module &M);
- void EmitUndefinedVars (Module &M);
- void EmitDefinedVars (Module &M);
- void EmitIData (Module &M);
- 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();
- void EmitUninitializedDataSection(const PIC16Section *S);
- void EmitInitializedDataSection(const PIC16Section *S);
- void EmitSingleSection(const PIC16Section *S);
- void EmitSectionList(Module &M,
- const std::vector< PIC16Section *> &SList);
- void ColorAutoSection(const Function *F);
- protected:
- bool doInitialization(Module &M);
- bool doFinalization(Module &M);
-
- /// EmitGlobalVariable - Emit the specified global variable and its
- /// initializer to the output stream.
- virtual void EmitGlobalVariable(const GlobalVariable *GV) {
- // PIC16 doesn't use normal hooks for this.
- }
-
- private:
- const PIC16TargetObjectFile *PTOF;
- PIC16DbgInfo DbgInfo;
- const PIC16MCAsmInfo *PMAI;
- std::set LibcallDecls; // Sorted & uniqued set of extern decls.
- std::vector ExternalVarDecls;
- std::vector ExternalVarDefs;
- };
-} // end of namespace
-
-#endif
diff --git a/lib/Target/PIC16/CMakeLists.txt b/lib/Target/PIC16/CMakeLists.txt
deleted file mode 100644
index 2b6cb9e4e46..00000000000
--- a/lib/Target/PIC16/CMakeLists.txt
+++ /dev/null
@@ -1,26 +0,0 @@
-set(LLVM_TARGET_DEFINITIONS PIC16.td)
-
-tablegen(PIC16GenRegisterInfo.h.inc -gen-register-desc-header)
-tablegen(PIC16GenRegisterNames.inc -gen-register-enums)
-tablegen(PIC16GenRegisterInfo.inc -gen-register-desc)
-tablegen(PIC16GenInstrNames.inc -gen-instr-enums)
-tablegen(PIC16GenInstrInfo.inc -gen-instr-desc)
-tablegen(PIC16GenAsmWriter.inc -gen-asm-writer)
-tablegen(PIC16GenDAGISel.inc -gen-dag-isel)
-tablegen(PIC16GenCallingConv.inc -gen-callingconv)
-tablegen(PIC16GenSubtarget.inc -gen-subtarget)
-
-add_llvm_target(PIC16CodeGen
- PIC16DebugInfo.cpp
- PIC16InstrInfo.cpp
- PIC16ISelDAGToDAG.cpp
- PIC16ISelLowering.cpp
- PIC16MemSelOpt.cpp
- PIC16MCAsmInfo.cpp
- PIC16RegisterInfo.cpp
- PIC16Section.cpp
- PIC16Subtarget.cpp
- PIC16TargetMachine.cpp
- PIC16TargetObjectFile.cpp
- PIC16SelectionDAGInfo.cpp
- )
diff --git a/lib/Target/PIC16/Makefile b/lib/Target/PIC16/Makefile
deleted file mode 100644
index 9e784d1d726..00000000000
--- a/lib/Target/PIC16/Makefile
+++ /dev/null
@@ -1,24 +0,0 @@
-##===- lib/Target/PIC16/Makefile ---------------------------*- Makefile -*-===##
-#
-# The LLVM Compiler Infrastructure
-#
-# This file is distributed under the University of Illinois Open Source
-# License. See LICENSE.TXT for details.
-#
-##===----------------------------------------------------------------------===##
-
-LEVEL = ../../..
-LIBRARYNAME = LLVMPIC16CodeGen
-TARGET = PIC16
-
-# Make sure that tblgen is run, first thing.
-BUILT_SOURCES = PIC16GenRegisterInfo.h.inc PIC16GenRegisterNames.inc \
- PIC16GenRegisterInfo.inc PIC16GenInstrNames.inc \
- PIC16GenInstrInfo.inc PIC16GenAsmWriter.inc \
- PIC16GenDAGISel.inc PIC16GenCallingConv.inc \
- PIC16GenSubtarget.inc
-
-DIRS = AsmPrinter TargetInfo PIC16Passes
-
-include $(LEVEL)/Makefile.common
-
diff --git a/lib/Target/PIC16/PIC16.h b/lib/Target/PIC16/PIC16.h
deleted file mode 100644
index 08bb3e6f055..00000000000
--- a/lib/Target/PIC16/PIC16.h
+++ /dev/null
@@ -1,134 +0,0 @@
-//===-- PIC16.h - Top-level interface for PIC16 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 contains the entry points for global functions defined in
-// the LLVM PIC16 back-end.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_TARGET_PIC16_H
-#define LLVM_TARGET_PIC16_H
-
-#include "llvm/Support/ErrorHandling.h"
-#include "llvm/Target/TargetMachine.h"
-#include
-#include
-#include
-#include
-#include
-
-namespace llvm {
- class PIC16TargetMachine;
- class FunctionPass;
- class MachineCodeEmitter;
- class formatted_raw_ostream;
-
-namespace PIC16CC {
- enum CondCodes {
- EQ,
- NE,
- LT,
- LE,
- GT,
- GE,
- ULT,
- UGT,
- ULE,
- UGE
- };
-}
-
- enum PIC16SectionType {
- CODE,
- UDATA,
- IDATA,
- ROMDATA,
- UDATA_OVR,
- UDATA_SHR
- };
-
- class ESNames {
- std::vector stk;
- ESNames() {}
- public:
- ~ESNames() {
- while (!stk.empty())
- {
- char* p = stk.back();
- delete [] p;
- stk.pop_back();
- }
- }
-
- // External symbol names require memory to live till the program end.
- // So we have to allocate it and keep. Push all such allocations into a
- // vector so that they get freed up on termination.
- inline static const char *createESName (const std::string &name) {
- static ESNames esn;
- char *tmpName = new char[name.size() + 1];
- memcpy(tmpName, name.c_str(), name.size() + 1);
- esn.stk.push_back(tmpName);
- return tmpName;
- }
-
- };
-
- inline static const char *PIC16CondCodeToString(PIC16CC::CondCodes CC) {
- switch (CC) {
- default: llvm_unreachable("Unknown condition code");
- case PIC16CC::NE: return "ne";
- case PIC16CC::EQ: return "eq";
- case PIC16CC::LT: return "lt";
- case PIC16CC::ULT: return "lt";
- case PIC16CC::LE: return "le";
- case PIC16CC::ULE: return "le";
- case PIC16CC::GT: return "gt";
- case PIC16CC::UGT: return "gt";
- case PIC16CC::GE: return "ge";
- case PIC16CC::UGE: return "ge";
- }
- }
-
- inline static bool isSignedComparison(PIC16CC::CondCodes CC) {
- switch (CC) {
- default: llvm_unreachable("Unknown condition code");
- case PIC16CC::NE:
- case PIC16CC::EQ:
- case PIC16CC::LT:
- case PIC16CC::LE:
- case PIC16CC::GE:
- case PIC16CC::GT:
- return true;
- case PIC16CC::ULT:
- case PIC16CC::UGT:
- case PIC16CC::ULE:
- case PIC16CC::UGE:
- return false; // condition codes for unsigned comparison.
- }
- }
-
-
-
- FunctionPass *createPIC16ISelDag(PIC16TargetMachine &TM);
- // Banksel optimizer pass.
- FunctionPass *createPIC16MemSelOptimizerPass();
-
- extern Target ThePIC16Target;
- extern Target TheCooperTarget;
-
-} // end namespace llvm;
-
-// Defines symbolic names for PIC16 registers. This defines a mapping from
-// register name to register number.
-#include "PIC16GenRegisterNames.inc"
-
-// Defines symbolic names for the PIC16 instructions.
-#include "PIC16GenInstrNames.inc"
-
-#endif
diff --git a/lib/Target/PIC16/PIC16.td b/lib/Target/PIC16/PIC16.td
deleted file mode 100644
index b2b9b1cd171..00000000000
--- a/lib/Target/PIC16/PIC16.td
+++ /dev/null
@@ -1,40 +0,0 @@
-//===- PIC16.td - Describe the PIC16 Target Machine -----------*- tblgen -*-==//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-// This is the top level entry point for the PIC16 target.
-//===----------------------------------------------------------------------===//
-
-//===----------------------------------------------------------------------===//
-// Target-independent interfaces
-//===----------------------------------------------------------------------===//
-
-include "llvm/Target/Target.td"
-
-include "PIC16RegisterInfo.td"
-include "PIC16InstrInfo.td"
-
-//===----------------------------------------------------------------------===//
-// Subtarget Features.
-//===----------------------------------------------------------------------===//
-def FeatureCooper : SubtargetFeature<"cooper", "IsCooper", "true",
- "PIC16 Cooper ISA Support">;
-
-//===----------------------------------------------------------------------===//
-// PIC16 supported processors.
-//===----------------------------------------------------------------------===//
-
-def : Processor<"generic", NoItineraries, []>;
-def : Processor<"cooper", NoItineraries, [FeatureCooper]>;
-
-
-def PIC16InstrInfo : InstrInfo {}
-
-def PIC16 : Target {
- let InstructionSet = PIC16InstrInfo;
-}
-
diff --git a/lib/Target/PIC16/PIC16ABINames.h b/lib/Target/PIC16/PIC16ABINames.h
deleted file mode 100644
index 4c1a8da286c..00000000000
--- a/lib/Target/PIC16/PIC16ABINames.h
+++ /dev/null
@@ -1,399 +0,0 @@
-//===-- PIC16ABINames.h - PIC16 Naming conventios for ABI----- --*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file contains the functions to manage ABI Naming conventions for PIC16.
-//
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_TARGET_PIC16ABINAMES_H
-#define LLVM_TARGET_PIC16ABINAMES_H
-
-#include "llvm/Support/ErrorHandling.h"
-#include "llvm/Target/TargetMachine.h"
-#include
-#include
-#include
-#include
-
-namespace llvm {
- class PIC16TargetMachine;
- class FunctionPass;
- class MachineCodeEmitter;
- class formatted_raw_ostream;
-
- // A Central class to manage all ABI naming conventions.
- // PAN - [P]ic16 [A]BI [N]ames
- class PAN {
- public:
- // Map the name of the symbol to its section name.
- // Current ABI:
- // -----------------------------------------------------
- // ALL Names are prefixed with the symobl '@'.
- // ------------------------------------------------------
- // Global variables do not have any '.' in their names.
- // These are maily function names and global variable names.
- // Example - @foo, @i
- // Static local variables - @.
- // -------------------------------------------------------
- // Functions and auto variables.
- // Names are mangled as ..
- // Where is '@' and is any one of
- // the following
- // .auto. - an automatic var of a function.
- // .temp. - temproray data of a function.
- // .ret. - return value label for a function.
- // .frame. - Frame label for a function where retval, args
- // and temps are stored.
- // .args. - Label used to pass arguments to a direct call.
- // Example - Function name: @foo
- // Its frame: @foo.frame.
- // Its retval: @foo.ret.
- // Its local vars: @foo.auto.a
- // Its temp data: @foo.temp.
- // Its arg passing: @foo.args.
- //----------------------------------------------
- // Libcall - compiler generated libcall names must start with .lib.
- // This id will be used to emit extern decls for libcalls.
- // Example - libcall name: @.lib.sra.i8
- // To pass args: @.lib.sra.i8.args.
- // To return val: @.lib.sra.i8.ret.
- //----------------------------------------------
- // SECTION Names
- // uninitialized globals - @udata..#
- // initialized globals - @idata..#
- // Program memory data - @romdata.#
- // Variables with user defined section name -
- // Variables with user defined address - @.user_section..#
- // Function frame - @.frame_section.
- // Function autos - @.autos_section.
- // Overlay sections - @.##
- // Declarations - Enclosed in comments. No section for them.
- //----------------------------------------------------------
-
- // Tags used to mangle different names.
- enum TAGS {
- PREFIX_SYMBOL,
- GLOBAL,
- STATIC_LOCAL,
- AUTOS_LABEL,
- FRAME_LABEL,
- RET_LABEL,
- ARGS_LABEL,
- TEMPS_LABEL,
-
- LIBCALL,
-
- FRAME_SECTION,
- AUTOS_SECTION,
- CODE_SECTION,
- USER_SECTION
- };
-
- // Textual names of the tags.
- inline static const char *getTagName(TAGS tag) {
- switch (tag) {
- default: return "";
- case PREFIX_SYMBOL: return "@";
- case AUTOS_LABEL: return ".auto.";
- case FRAME_LABEL: return ".frame.";
- case TEMPS_LABEL: return ".temp.";
- case ARGS_LABEL: return ".args.";
- case RET_LABEL: return ".ret.";
- case LIBCALL: return ".lib.";
- case FRAME_SECTION: return ".frame_section.";
- case AUTOS_SECTION: return ".autos_section.";
- case CODE_SECTION: return ".code_section.";
- case USER_SECTION: return ".user_section.";
- }
- }
-
- // Get tag type for the Symbol.
- inline static TAGS getSymbolTag(const std::string &Sym) {
- if (Sym.find(getTagName(TEMPS_LABEL)) != std::string::npos)
- return TEMPS_LABEL;
-
- if (Sym.find(getTagName(FRAME_LABEL)) != std::string::npos)
- return FRAME_LABEL;
-
- if (Sym.find(getTagName(RET_LABEL)) != std::string::npos)
- return RET_LABEL;
-
- if (Sym.find(getTagName(ARGS_LABEL)) != std::string::npos)
- return ARGS_LABEL;
-
- if (Sym.find(getTagName(AUTOS_LABEL)) != std::string::npos)
- return AUTOS_LABEL;
-
- if (Sym.find(getTagName(LIBCALL)) != std::string::npos)
- return LIBCALL;
-
- // It does not have any Tag. So its a true global or static local.
- if (Sym.find(".") == std::string::npos)
- return GLOBAL;
-
- // If a . is there, then it may be static local.
- // We should mangle these as well in clang.
- if (Sym.find(".") != std::string::npos)
- return STATIC_LOCAL;
-
- assert (0 && "Could not determine Symbol's tag");
- return PREFIX_SYMBOL; // Silence warning when assertions are turned off.
- }
-
- // addPrefix - add prefix symbol to a name if there isn't one already.
- inline static std::string addPrefix (const std::string &Name) {
- std::string prefix = getTagName (PREFIX_SYMBOL);
-
- // If this name already has a prefix, nothing to do.
- if (Name.compare(0, prefix.size(), prefix) == 0)
- return Name;
-
- return prefix + Name;
- }
-
- // Get mangled func name from a mangled sym name.
- // In all cases func name is the first component before a '.'.
- static inline std::string getFuncNameForSym(const std::string &Sym1) {
- assert (getSymbolTag(Sym1) != GLOBAL && "not belongs to a function");
-
- std::string Sym = addPrefix(Sym1);
-
- // Position of the . after func name. That's where func name ends.
- size_t func_name_end = Sym.find ('.');
-
- return Sym.substr (0, func_name_end);
- }
-
- // Get Frame start label for a func.
- static std::string getFrameLabel(const std::string &Func) {
- std::string Func1 = addPrefix(Func);
- std::string tag = getTagName(FRAME_LABEL);
- return Func1 + tag;
- }
-
- // Get the retval label for the given function.
- static std::string getRetvalLabel(const std::string &Func) {
- std::string Func1 = addPrefix(Func);
- std::string tag = getTagName(RET_LABEL);
- return Func1 + tag;
- }
-
- // Get the argument label for the given function.
- static std::string getArgsLabel(const std::string &Func) {
- std::string Func1 = addPrefix(Func);
- std::string tag = getTagName(ARGS_LABEL);
- return Func1 + tag;
- }
-
- // Get the tempdata label for the given function.
- static std::string getTempdataLabel(const std::string &Func) {
- std::string Func1 = addPrefix(Func);
- std::string tag = getTagName(TEMPS_LABEL);
- return Func1 + tag;
- }
-
- static std::string getFrameSectionName(const std::string &Func) {
- std::string Func1 = addPrefix(Func);
- std::string tag = getTagName(FRAME_SECTION);
- return Func1 + tag + "#";
- }
-
- static std::string getAutosSectionName(const std::string &Func) {
- std::string Func1 = addPrefix(Func);
- std::string tag = getTagName(AUTOS_SECTION);
- return Func1 + tag + "#";
- }
-
- static std::string getCodeSectionName(const std::string &Func) {
- std::string Func1 = addPrefix(Func);
- std::string tag = getTagName(CODE_SECTION);
- return Func1 + tag + "#";
- }
-
- static std::string getUserSectionName(const std::string &Name) {
- std::string sname = addPrefix(Name);;
- std::string tag = getTagName(USER_SECTION);
- return sname + tag + "#";
- }
-
- // udata, romdata and idata section names are generated by a given number.
- // @udata..#
- static std::string getUdataSectionName(unsigned num,
- std::string prefix = "") {
- std::ostringstream o;
- o << getTagName(PREFIX_SYMBOL) << prefix << "udata." << num
- << ".#";
- return o.str();
- }
-
- static std::string getRomdataSectionName() {
- 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;
- o << getTagName(PREFIX_SYMBOL) << prefix << "romdata." << num
- << ".#";
- return o.str();
- }
-
- static std::string getIdataSectionName(unsigned num,
- std::string prefix = "") {
- std::ostringstream o;
- o << getTagName(PREFIX_SYMBOL) << prefix << "idata." << num
- << ".#";
- return o.str();
- }
-
- inline static bool isLocalName (const std::string &Name) {
- if (getSymbolTag(Name) == AUTOS_LABEL)
- return true;
-
- return false;
- }
-
-
- inline static bool isMemIntrinsic (const std::string &Name) {
- if (Name.compare("@memcpy") == 0 || Name.compare("@memset") == 0 ||
- Name.compare("@memmove") == 0) {
- return true;
- }
-
- return false;
- }
-
- // Currently names of libcalls are assigned during TargetLowering
- // object construction. There is no provision to change the when the
- // code for a function IL function being generated.
- // So we have to change these names while printing assembly.
- // We need to do that mainly for names related to intrinsics. This
- // function returns true if a name needs to be cloned.
- inline static bool isIntrinsicStuff(const std::string &Name) {
- // Return true if the name contains LIBCALL marker, or a MemIntrinisc.
- // these are mainly ARGS_LABEL, RET_LABEL, and the LIBCALL name itself.
- if ((Name.find(getTagName(LIBCALL)) != std::string::npos)
- || isMemIntrinsic(Name))
- return true;
-
- return false;
- }
-
- // Rename the name for IL.
- inline static std::string Rename(const std::string &Name) {
- std::string Newname;
- // If its a label (LIBCALL+Func+LABEL), change it to
- // (LIBCALL+Func+IL+LABEL).
- TAGS id = getSymbolTag(Name);
- if (id == ARGS_LABEL || id == RET_LABEL) {
- std::size_t pos = Name.find(getTagName(id));
- Newname = Name.substr(0, pos) + ".IL" + getTagName(id);
- return Newname;
- }
-
- // Else, just append IL to name.
- return Name + ".IL";
- }
-
-
-
-
- inline static bool isLocalToFunc (std::string &Func, std::string &Var) {
- if (! isLocalName(Var)) return false;
-
- std::string Func1 = addPrefix(Func);
- // Extract func name of the varilable.
- const std::string &fname = getFuncNameForSym(Var);
-
- if (fname.compare(Func1) == 0)
- return true;
-
- return false;
- }
-
-
- // Get the section for the given external symbol names.
- // This tries to find the type (Tag) of the symbol from its mangled name
- // and return appropriate section name for it.
- static inline std::string getSectionNameForSym(const std::string &Sym1) {
- std::string Sym = addPrefix(Sym1);
-
- std::string SectionName;
-
- std::string Fname = getFuncNameForSym (Sym);
- TAGS id = getSymbolTag (Sym);
-
- switch (id) {
- default : assert (0 && "Could not determine external symbol type");
- case FRAME_LABEL:
- case RET_LABEL:
- case TEMPS_LABEL:
- case ARGS_LABEL: {
- return getFrameSectionName(Fname);
- }
- case AUTOS_LABEL: {
- return getAutosSectionName(Fname);
- }
- }
- }
-
- /// Return Overlay Name for the section.
- /// The ABI Convention is: @.##.
- /// The section_tag is retrieved from the SectName parameter and
- /// and Color is passed in parameter.
- static inline std::string getOverlayName(std::string SectName, int Color) {
- // FIXME: Only autos_section and frame_section are colored.
- // So check and assert if the passed SectName does not have AUTOS_SECTION
- // or FRAME_SECTION tag in it.
- std::ostringstream o;
- o << getTagName(PREFIX_SYMBOL) << Color << ".##"
- << SectName.substr(SectName.find("."));
-
- return o.str();
- }
-
- // Return true if the current function is an ISR
- inline static bool isISR(const std::string SectName) {
- if (SectName.find("interrupt") != std::string::npos)
- return true;
-
- return false;
- }
-
- // Return the address for ISR starts in rom.
- inline static std::string getISRAddr(void) {
- return "0x4";
- }
-
- // Returns the name of clone of a function.
- static std::string getCloneFnName(const std::string &Func) {
- return (Func + ".IL");
- }
-
- // Returns the name of clone of a variable.
- static std::string getCloneVarName(const std::string &Fn,
- const std::string &Var) {
- std::string cloneVarName = Var;
- // These vars are named like fun.auto.var.
- // Just replace the function name, with clone function name.
- std::string cloneFnName = getCloneFnName(Fn);
- cloneVarName.replace(cloneVarName.find(Fn), Fn.length(), cloneFnName);
- return cloneVarName;
- }
- }; // class PAN.
-} // end namespace llvm;
-
-#endif
diff --git a/lib/Target/PIC16/PIC16DebugInfo.cpp b/lib/Target/PIC16/PIC16DebugInfo.cpp
deleted file mode 100644
index 7a948def3cf..00000000000
--- a/lib/Target/PIC16/PIC16DebugInfo.cpp
+++ /dev/null
@@ -1,490 +0,0 @@
-
-//===-- PIC16DebugInfo.cpp - Implementation for PIC16 Debug Information ======//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file contains the helper functions for representing debug information.
-//
-//===----------------------------------------------------------------------===//
-
-#include "PIC16.h"
-#include "PIC16ABINames.h"
-#include "PIC16DebugInfo.h"
-#include "llvm/GlobalVariable.h"
-#include "llvm/CodeGen/MachineFunction.h"
-#include "llvm/MC/MCAsmInfo.h"
-#include "llvm/MC/MCStreamer.h"
-#include "llvm/Support/DebugLoc.h"
-#include "llvm/ADT/SmallString.h"
-#include "llvm/ADT/StringExtras.h"
-using namespace llvm;
-
-/// PopulateDebugInfo - Populate the TypeNo, Aux[] and TagName from Ty.
-///
-void PIC16DbgInfo::PopulateDebugInfo (DIType Ty, unsigned short &TypeNo,
- bool &HasAux, int Aux[],
- std::string &TagName) {
- if (Ty.isBasicType())
- PopulateBasicTypeInfo (Ty, TypeNo);
- else if (Ty.isCompositeType())
- PopulateCompositeTypeInfo (Ty, TypeNo, HasAux, Aux, TagName);
- else if (Ty.isDerivedType())
- PopulateDerivedTypeInfo (Ty, TypeNo, HasAux, Aux, TagName);
- else {
- TypeNo = PIC16Dbg::T_NULL;
- HasAux = false;
- }
- return;
-}
-
-/// PopulateBasicTypeInfo- Populate TypeNo for basic type from Ty.
-///
-void PIC16DbgInfo::PopulateBasicTypeInfo (DIType Ty, unsigned short &TypeNo) {
- std::string Name = Ty.getName();
- unsigned short BaseTy = GetTypeDebugNumber(Name);
- TypeNo = TypeNo << PIC16Dbg::S_BASIC;
- TypeNo = TypeNo | (0xffff & BaseTy);
-}
-
-/// PopulateDerivedTypeInfo - Populate TypeNo, Aux[], TagName for derived type
-/// from Ty. Derived types are mostly pointers.
-///
-void PIC16DbgInfo::PopulateDerivedTypeInfo (DIType Ty, unsigned short &TypeNo,
- bool &HasAux, int Aux[],
- std::string &TagName) {
-
- switch(Ty.getTag())
- {
- case dwarf::DW_TAG_pointer_type:
- TypeNo = TypeNo << PIC16Dbg::S_DERIVED;
- TypeNo = TypeNo | PIC16Dbg::DT_PTR;
- break;
- default:
- TypeNo = TypeNo << PIC16Dbg::S_DERIVED;
- }
-
- // We also need to encode the information about the base type of
- // pointer in TypeNo.
- DIType BaseType = DIDerivedType(Ty).getTypeDerivedFrom();
- PopulateDebugInfo(BaseType, TypeNo, HasAux, Aux, TagName);
-}
-
-/// PopulateArrayTypeInfo - Populate TypeNo, Aux[] for array from Ty.
-void PIC16DbgInfo::PopulateArrayTypeInfo (DIType Ty, unsigned short &TypeNo,
- bool &HasAux, int Aux[],
- std::string &TagName) {
-
- DICompositeType CTy = DICompositeType(Ty);
- DIArray Elements = CTy.getTypeArray();
- unsigned short size = 1;
- unsigned short Dimension[4]={0,0,0,0};
- for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) {
- DIDescriptor Element = Elements.getElement(i);
- if (Element.getTag() == dwarf::DW_TAG_subrange_type) {
- TypeNo = TypeNo << PIC16Dbg::S_DERIVED;
- TypeNo = TypeNo | PIC16Dbg::DT_ARY;
- DISubrange SubRange = DISubrange(Element);
- Dimension[i] = SubRange.getHi() - SubRange.getLo() + 1;
- // Each dimension is represented by 2 bytes starting at byte 9.
- Aux[8+i*2+0] = Dimension[i];
- Aux[8+i*2+1] = Dimension[i] >> 8;
- size = size * Dimension[i];
- }
- }
- HasAux = true;
- // In auxillary entry for array, 7th and 8th byte represent array size.
- Aux[6] = size & 0xff;
- Aux[7] = size >> 8;
- DIType BaseType = CTy.getTypeDerivedFrom();
- PopulateDebugInfo(BaseType, TypeNo, HasAux, Aux, TagName);
-}
-
-/// PopulateStructOrUnionTypeInfo - Populate TypeNo, Aux[] , TagName for
-/// structure or union.
-///
-void PIC16DbgInfo::PopulateStructOrUnionTypeInfo (DIType Ty,
- unsigned short &TypeNo,
- bool &HasAux, int Aux[],
- std::string &TagName) {
- DICompositeType CTy = DICompositeType(Ty);
- TypeNo = TypeNo << PIC16Dbg::S_BASIC;
- if (Ty.getTag() == dwarf::DW_TAG_structure_type)
- TypeNo = TypeNo | PIC16Dbg::T_STRUCT;
- else
- TypeNo = TypeNo | PIC16Dbg::T_UNION;
- TagName = CTy.getName();
- // UniqueSuffix is .number where number is obtained from
- // llvm.dbg.composite.
- // FIXME: This will break when composite type is not represented by
- // llvm.dbg.composite* global variable. Since we need to revisit
- // PIC16DebugInfo implementation anyways after the MDNodes based
- // framework is done, let us continue with the way it is.
- std::string UniqueSuffix = "." + Ty->getNameStr().substr(18);
- TagName += UniqueSuffix;
- unsigned short size = CTy.getSizeInBits()/8;
- // 7th and 8th byte represent size.
- HasAux = true;
- Aux[6] = size & 0xff;
- Aux[7] = size >> 8;
-}
-
-/// PopulateEnumTypeInfo - Populate TypeNo for enum from Ty.
-void PIC16DbgInfo::PopulateEnumTypeInfo (DIType Ty, unsigned short &TypeNo) {
- TypeNo = TypeNo << PIC16Dbg::S_BASIC;
- TypeNo = TypeNo | PIC16Dbg::T_ENUM;
-}
-
-/// PopulateCompositeTypeInfo - Populate TypeNo, Aux[] and TagName for
-/// composite types from Ty.
-///
-void PIC16DbgInfo::PopulateCompositeTypeInfo (DIType Ty, unsigned short &TypeNo,
- bool &HasAux, int Aux[],
- std::string &TagName) {
- switch (Ty.getTag()) {
- case dwarf::DW_TAG_array_type: {
- PopulateArrayTypeInfo (Ty, TypeNo, HasAux, Aux, TagName);
- break;
- }
- case dwarf:: DW_TAG_union_type:
- case dwarf::DW_TAG_structure_type: {
- PopulateStructOrUnionTypeInfo (Ty, TypeNo, HasAux, Aux, TagName);
- break;
- }
- case dwarf::DW_TAG_enumeration_type: {
- PopulateEnumTypeInfo (Ty, TypeNo);
- break;
- }
- default:
- TypeNo = TypeNo << PIC16Dbg::S_DERIVED;
- }
-}
-
-/// GetTypeDebugNumber - Get debug type number for given type.
-///
-unsigned PIC16DbgInfo::GetTypeDebugNumber(std::string &type) {
- if (type == "char")
- return PIC16Dbg::T_CHAR;
- else if (type == "short")
- return PIC16Dbg::T_SHORT;
- else if (type == "int")
- return PIC16Dbg::T_INT;
- else if (type == "long")
- return PIC16Dbg::T_LONG;
- else if (type == "unsigned char")
- return PIC16Dbg::T_UCHAR;
- else if (type == "unsigned short")
- return PIC16Dbg::T_USHORT;
- else if (type == "unsigned int")
- return PIC16Dbg::T_UINT;
- else if (type == "unsigned long")
- return PIC16Dbg::T_ULONG;
- else
- return 0;
-}
-
-/// GetStorageClass - Get storage class for give debug variable.
-///
-short PIC16DbgInfo::getStorageClass(DIGlobalVariable DIGV) {
- short ClassNo;
- if (PAN::isLocalName(DIGV.getName())) {
- // Generating C_AUTO here fails due to error in linker. Change it once
- // linker is fixed.
- ClassNo = PIC16Dbg::C_STAT;
- }
- else if (DIGV.isLocalToUnit())
- ClassNo = PIC16Dbg::C_STAT;
- else
- ClassNo = PIC16Dbg::C_EXT;
- return ClassNo;
-}
-
-/// BeginModule - Emit necessary debug info to start a Module and do other
-/// required initializations.
-void PIC16DbgInfo::BeginModule(Module &M) {
- // Emit file directive for module.
- DebugInfoFinder DbgFinder;
- DbgFinder.processModule(M);
- if (DbgFinder.compile_unit_count() != 0) {
- // FIXME : What if more then one CUs are present in a module ?
- MDNode *CU = *DbgFinder.compile_unit_begin();
- EmitDebugDirectives = true;
- SwitchToCU(CU);
- }
- // Emit debug info for decls of composite types.
- EmitCompositeTypeDecls(M);
-}
-
-/// Helper to find first valid debug loc for a function.
-///
-static const DebugLoc GetDebugLocForFunction(const MachineFunction &MF) {
- DebugLoc DL;
- for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
- I != E; ++I) {
- for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
- II != E; ++II) {
- DL = II->getDebugLoc();
- if (!DL.isUnknown())
- return DL;
- }
- }
- return DL;
-}
-
-/// BeginFunction - Emit necessary debug info to start a function.
-///
-void PIC16DbgInfo::BeginFunction(const MachineFunction &MF) {
- if (! EmitDebugDirectives) return;
-
- // Retreive the first valid debug Loc and process it.
- const DebugLoc &DL = GetDebugLocForFunction(MF);
- // Emit debug info only if valid debug info is available.
- if (!DL.isUnknown()) {
- ChangeDebugLoc(MF, DL, true);
- EmitFunctBeginDI(MF.getFunction());
- }
- // Set current line to 0 so that.line directive is genearted after .bf.
- CurLine = 0;
-}
-
-/// ChangeDebugLoc - Take necessary steps when DebugLoc changes.
-/// CurFile and CurLine may change as a result of this.
-///
-void PIC16DbgInfo::ChangeDebugLoc(const MachineFunction &MF,
- const DebugLoc &DL, bool IsInBeginFunction) {
- if (!EmitDebugDirectives) return;
- assert(!DL.isUnknown() && "can't change to invalid debug loc");
-
- SwitchToCU(DL.getScope(MF.getFunction()->getContext()));
- SwitchToLine(DL.getLine(), IsInBeginFunction);
-}
-
-/// SwitchToLine - Emit line directive for a new line.
-///
-void PIC16DbgInfo::SwitchToLine(unsigned Line, bool IsInBeginFunction) {
- if (CurLine == Line) return;
- if (!IsInBeginFunction)
- OS.EmitRawText("\n\t.line " + Twine(Line));
- CurLine = Line;
-}
-
-/// EndFunction - Emit .ef for end of function.
-///
-void PIC16DbgInfo::EndFunction(const MachineFunction &MF) {
- if (! EmitDebugDirectives) return;
- const DebugLoc &DL = GetDebugLocForFunction(MF);
- // Emit debug info only if valid debug info is available.
- if (!DL.isUnknown())
- EmitFunctEndDI(MF.getFunction(), CurLine);
-}
-
-/// EndModule - Emit .eof for end of module.
-///
-void PIC16DbgInfo::EndModule(Module &M) {
- if (! EmitDebugDirectives) return;
- EmitVarDebugInfo(M);
- if (CurFile != "") OS.EmitRawText(StringRef("\n\t.eof"));
-}
-
-/// EmitCompositeTypeElements - Emit debug information for members of a
-/// composite type.
-///
-void PIC16DbgInfo::EmitCompositeTypeElements (DICompositeType CTy,
- std::string SuffixNo) {
- unsigned long Value = 0;
- DIArray Elements = CTy.getTypeArray();
- for (unsigned i = 0, N = Elements.getNumElements(); i < N; i++) {
- DIDescriptor Element = Elements.getElement(i);
- unsigned short TypeNo = 0;
- bool HasAux = false;
- int ElementAux[PIC16Dbg::AuxSize] = { 0 };
- std::string TagName = "";
- DIDerivedType DITy(Element);
- unsigned short ElementSize = DITy.getSizeInBits()/8;
- // Get mangleddd name for this structure/union element.
- std::string MangMemName = DITy.getName().str() + SuffixNo;
- PopulateDebugInfo(DITy, TypeNo, HasAux, ElementAux, TagName);
- short Class = 0;
- if( CTy.getTag() == dwarf::DW_TAG_union_type)
- Class = PIC16Dbg::C_MOU;
- else if (CTy.getTag() == dwarf::DW_TAG_structure_type)
- Class = PIC16Dbg::C_MOS;
- EmitSymbol(MangMemName.c_str(), Class, TypeNo, Value);
- if (CTy.getTag() == dwarf::DW_TAG_structure_type)
- Value += ElementSize;
- if (HasAux)
- EmitAuxEntry(MangMemName.c_str(), ElementAux, PIC16Dbg::AuxSize, TagName);
- }
-}
-
-/// EmitCompositeTypeDecls - Emit composite type declarations like structure
-/// and union declarations.
-///
-void PIC16DbgInfo::EmitCompositeTypeDecls(Module &M) {
- DebugInfoFinder DbgFinder;
- DbgFinder.processModule(M);
- for (DebugInfoFinder::iterator I = DbgFinder.type_begin(),
- E = DbgFinder.type_end(); I != E; ++I) {
- DICompositeType CTy(*I);
- if (!CTy.Verify())
- continue;
- if (CTy.getTag() == dwarf::DW_TAG_union_type ||
- CTy.getTag() == dwarf::DW_TAG_structure_type ) {
- // Get the number after llvm.dbg.composite and make UniqueSuffix from
- // it.
- std::string DIVar = CTy->getNameStr();
- std::string UniqueSuffix = "." + DIVar.substr(18);
- std::string MangledCTyName = CTy.getName().str() + UniqueSuffix;
- unsigned short size = CTy.getSizeInBits()/8;
- int Aux[PIC16Dbg::AuxSize] = {0};
- // 7th and 8th byte represent size of structure/union.
- Aux[6] = size & 0xff;
- Aux[7] = size >> 8;
- // Emit .def for structure/union tag.
- if( CTy.getTag() == dwarf::DW_TAG_union_type)
- EmitSymbol(MangledCTyName.c_str(), PIC16Dbg::C_UNTAG);
- else if (CTy.getTag() == dwarf::DW_TAG_structure_type)
- EmitSymbol(MangledCTyName.c_str(), PIC16Dbg::C_STRTAG);
-
- // Emit auxiliary debug information for structure/union tag.
- EmitAuxEntry(MangledCTyName.c_str(), Aux, PIC16Dbg::AuxSize);
-
- // Emit members.
- EmitCompositeTypeElements (CTy, UniqueSuffix);
-
- // Emit mangled Symbol for end of structure/union.
- std::string EOSSymbol = ".eos" + UniqueSuffix;
- EmitSymbol(EOSSymbol.c_str(), PIC16Dbg::C_EOS);
- EmitAuxEntry(EOSSymbol.c_str(), Aux, PIC16Dbg::AuxSize,
- MangledCTyName.c_str());
- }
- }
-}
-
-
-/// EmitFunctBeginDI - Emit .bf for function.
-///
-void PIC16DbgInfo::EmitFunctBeginDI(const Function *F) {
- std::string FunctName = F->getName();
- if (EmitDebugDirectives) {
- std::string FunctBeginSym = ".bf." + FunctName;
- std::string BlockBeginSym = ".bb." + FunctName;
-
- int BFAux[PIC16Dbg::AuxSize] = {0};
- BFAux[4] = CurLine;
- BFAux[5] = CurLine >> 8;
-
- // Emit debug directives for beginning of function.
- EmitSymbol(FunctBeginSym, PIC16Dbg::C_FCN);
- EmitAuxEntry(FunctBeginSym, BFAux, PIC16Dbg::AuxSize);
-
- EmitSymbol(BlockBeginSym, PIC16Dbg::C_BLOCK);
- EmitAuxEntry(BlockBeginSym, BFAux, PIC16Dbg::AuxSize);
- }
-}
-
-/// EmitFunctEndDI - Emit .ef for function end.
-///
-void PIC16DbgInfo::EmitFunctEndDI(const Function *F, unsigned Line) {
- std::string FunctName = F->getName();
- if (EmitDebugDirectives) {
- std::string FunctEndSym = ".ef." + FunctName;
- std::string BlockEndSym = ".eb." + FunctName;
-
- // Emit debug directives for end of function.
- EmitSymbol(BlockEndSym, PIC16Dbg::C_BLOCK);
- int EFAux[PIC16Dbg::AuxSize] = {0};
- // 5th and 6th byte stand for line number.
- EFAux[4] = CurLine;
- EFAux[5] = CurLine >> 8;
- EmitAuxEntry(BlockEndSym, EFAux, PIC16Dbg::AuxSize);
- EmitSymbol(FunctEndSym, PIC16Dbg::C_FCN);
- EmitAuxEntry(FunctEndSym, EFAux, PIC16Dbg::AuxSize);
- }
-}
-
-/// EmitAuxEntry - Emit Auxiliary debug information.
-///
-void PIC16DbgInfo::EmitAuxEntry(const std::string VarName, int Aux[], int Num,
- std::string TagName) {
- std::string Tmp;
- // TagName is emitted in case of structure/union objects.
- if (!TagName.empty()) Tmp += ", " + TagName;
-
- for (int i = 0; i 0)
- Tmp = ", value = " + utostr(Value);
-
- OS.EmitRawText("\n\t.def " + Twine(Name) + ", type = " + utostr(Type) +
- ", class = " + utostr(Class) + Tmp);
-}
-
-/// EmitVarDebugInfo - Emit debug information for all variables.
-///
-void PIC16DbgInfo::EmitVarDebugInfo(Module &M) {
- DebugInfoFinder DbgFinder;
- DbgFinder.processModule(M);
-
- for (DebugInfoFinder::iterator I = DbgFinder.global_variable_begin(),
- E = DbgFinder.global_variable_end(); I != E; ++I) {
- DIGlobalVariable DIGV(*I);
- DIType Ty = DIGV.getType();
- unsigned short TypeNo = 0;
- bool HasAux = false;
- int Aux[PIC16Dbg::AuxSize] = { 0 };
- std::string TagName = "";
- std::string VarName = DIGV.getName();
- VarName = MAI->getGlobalPrefix() + VarName;
- PopulateDebugInfo(Ty, TypeNo, HasAux, Aux, TagName);
- // Emit debug info only if type information is availaible.
- if (TypeNo != PIC16Dbg::T_NULL) {
- OS.EmitRawText("\t.type " + Twine(VarName) + ", " + Twine(TypeNo));
- short ClassNo = getStorageClass(DIGV);
- OS.EmitRawText("\t.class " + Twine(VarName) + ", " + Twine(ClassNo));
- if (HasAux)
- EmitAuxEntry(VarName, Aux, PIC16Dbg::AuxSize, TagName);
- }
- }
-}
-
-/// SwitchToCU - Switch to a new compilation unit.
-///
-void PIC16DbgInfo::SwitchToCU(MDNode *CU) {
- // Get the file path from CU.
- DICompileUnit cu(CU);
- std::string DirName = cu.getDirectory();
- std::string FileName = cu.getFilename();
- std::string FilePath = DirName + "/" + FileName;
-
- // Nothing to do if source file is still same.
- if ( FilePath == CurFile ) return;
-
- // Else, close the current one and start a new.
- if (CurFile != "")
- OS.EmitRawText(StringRef("\t.eof"));
- OS.EmitRawText("\n\t.file\t\"" + Twine(FilePath) + "\"");
- CurFile = FilePath;
- CurLine = 0;
-}
-
-/// EmitEOF - Emit .eof for end of file.
-///
-void PIC16DbgInfo::EmitEOF() {
- if (CurFile != "")
- OS.EmitRawText(StringRef("\t.EOF"));
-}
-
diff --git a/lib/Target/PIC16/PIC16DebugInfo.h b/lib/Target/PIC16/PIC16DebugInfo.h
deleted file mode 100644
index 031dcf092f0..00000000000
--- a/lib/Target/PIC16/PIC16DebugInfo.h
+++ /dev/null
@@ -1,156 +0,0 @@
-//===-- PIC16DebugInfo.h - Interfaces for PIC16 Debug Information ============//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file contains the helper functions for representing debug information.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef PIC16DBG_H
-#define PIC16DBG_H
-
-#include "llvm/Analysis/DebugInfo.h"
-#include "llvm/Module.h"
-
-namespace llvm {
- class MachineFunction;
- class DebugLoc;
- class MCStreamer;
-
- namespace PIC16Dbg {
- enum VarType {
- T_NULL,
- T_VOID,
- T_CHAR,
- T_SHORT,
- T_INT,
- T_LONG,
- T_FLOAT,
- T_DOUBLE,
- T_STRUCT,
- T_UNION,
- T_ENUM,
- T_MOE,
- T_UCHAR,
- T_USHORT,
- T_UINT,
- T_ULONG
- };
- enum DerivedType {
- DT_NONE,
- DT_PTR,
- DT_FCN,
- DT_ARY
- };
- enum TypeSize {
- S_BASIC = 5,
- S_DERIVED = 3
- };
- enum DbgClass {
- C_NULL,
- C_AUTO,
- C_EXT,
- C_STAT,
- C_REG,
- C_EXTDEF,
- C_LABEL,
- C_ULABEL,
- C_MOS,
- C_ARG,
- C_STRTAG,
- C_MOU,
- C_UNTAG,
- C_TPDEF,
- C_USTATIC,
- C_ENTAG,
- C_MOE,
- C_REGPARM,
- C_FIELD,
- C_AUTOARG,
- C_LASTENT,
- C_BLOCK = 100,
- C_FCN,
- C_EOS,
- C_FILE,
- C_LINE,
- C_ALIAS,
- C_HIDDEN,
- C_EOF,
- C_LIST,
- C_SECTION,
- C_EFCN = 255
- };
- enum SymbolSize {
- AuxSize =20
- };
- }
-
- class PIC16DbgInfo {
- MCStreamer &OS;
- const MCAsmInfo *MAI;
- std::string CurFile;
- unsigned CurLine;
-
- // EmitDebugDirectives is set if debug information is available. Default
- // value for it is false.
- bool EmitDebugDirectives;
-
- public:
- PIC16DbgInfo(MCStreamer &os, const MCAsmInfo *T) : OS(os), MAI(T) {
- CurFile = "";
- CurLine = 0;
- EmitDebugDirectives = false;
- }
-
- void BeginModule (Module &M);
- void BeginFunction (const MachineFunction &MF);
- void ChangeDebugLoc (const MachineFunction &MF, const DebugLoc &DL,
- bool IsInBeginFunction = false);
- void EndFunction (const MachineFunction &MF);
- void EndModule (Module &M);
-
-
- private:
- void SwitchToCU (MDNode *CU);
- void SwitchToLine (unsigned Line, bool IsInBeginFunction = false);
-
- void PopulateDebugInfo (DIType Ty, unsigned short &TypeNo, bool &HasAux,
- int Aux[], std::string &TypeName);
- void PopulateBasicTypeInfo (DIType Ty, unsigned short &TypeNo);
- void PopulateDerivedTypeInfo (DIType Ty, unsigned short &TypeNo,
- bool &HasAux, int Aux[],
- std::string &TypeName);
-
- void PopulateCompositeTypeInfo (DIType Ty, unsigned short &TypeNo,
- bool &HasAux, int Aux[],
- std::string &TypeName);
- void PopulateArrayTypeInfo (DIType Ty, unsigned short &TypeNo,
- bool &HasAux, int Aux[],
- std::string &TypeName);
-
- void PopulateStructOrUnionTypeInfo (DIType Ty, unsigned short &TypeNo,
- bool &HasAux, int Aux[],
- std::string &TypeName);
- void PopulateEnumTypeInfo (DIType Ty, unsigned short &TypeNo);
-
- unsigned GetTypeDebugNumber(std::string &Type);
- short getStorageClass(DIGlobalVariable DIGV);
- void EmitFunctBeginDI(const Function *F);
- void EmitCompositeTypeDecls(Module &M);
- void EmitCompositeTypeElements (DICompositeType CTy, std::string Suffix);
- void EmitFunctEndDI(const Function *F, unsigned Line);
- void EmitAuxEntry(const std::string VarName, int Aux[],
- int num = PIC16Dbg::AuxSize, std::string TagName = "");
- inline void EmitSymbol(std::string Name, short Class,
- unsigned short Type = PIC16Dbg::T_NULL,
- unsigned long Value = 0);
- void EmitVarDebugInfo(Module &M);
- void EmitEOF();
- };
-} // end namespace llvm;
-#endif
diff --git a/lib/Target/PIC16/PIC16ISelDAGToDAG.cpp b/lib/Target/PIC16/PIC16ISelDAGToDAG.cpp
deleted file mode 100644
index 7be8147bc55..00000000000
--- a/lib/Target/PIC16/PIC16ISelDAGToDAG.cpp
+++ /dev/null
@@ -1,49 +0,0 @@
-//===-- PIC16ISelDAGToDAG.cpp - A dag to dag inst selector for PIC16 ------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file defines an instruction selector for the PIC16 target.
-//
-//===----------------------------------------------------------------------===//
-
-#define DEBUG_TYPE "pic16-isel"
-
-#include "llvm/Support/ErrorHandling.h"
-#include "PIC16ISelDAGToDAG.h"
-using namespace llvm;
-
-/// createPIC16ISelDag - This pass converts a legalized DAG into a
-/// PIC16-specific DAG, ready for instruction scheduling.
-FunctionPass *llvm::createPIC16ISelDag(PIC16TargetMachine &TM) {
- return new PIC16DAGToDAGISel(TM);
-}
-
-
-/// Select - Select instructions not customized! Used for
-/// expanded, promoted and normal instructions.
-SDNode* PIC16DAGToDAGISel::Select(SDNode *N) {
-
- // Select the default instruction.
- SDNode *ResNode = SelectCode(N);
-
- return ResNode;
-}
-
-
-// SelectDirectAddr - Match a direct address for DAG.
-// A direct address could be a globaladdress or externalsymbol.
-bool PIC16DAGToDAGISel::SelectDirectAddr(SDValue N, SDValue &Address) {
- // Return true if TGA or ES.
- if (N.getOpcode() == ISD::TargetGlobalAddress
- || N.getOpcode() == ISD::TargetExternalSymbol) {
- Address = N;
- return true;
- }
-
- return false;
-}
diff --git a/lib/Target/PIC16/PIC16ISelDAGToDAG.h b/lib/Target/PIC16/PIC16ISelDAGToDAG.h
deleted file mode 100644
index d2550810886..00000000000
--- a/lib/Target/PIC16/PIC16ISelDAGToDAG.h
+++ /dev/null
@@ -1,60 +0,0 @@
-//===-- PIC16ISelDAGToDAG.cpp - A dag to dag inst selector for PIC16 ------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file defines an instruction selector for the PIC16 target.
-//
-//===----------------------------------------------------------------------===//
-
-#define DEBUG_TYPE "pic16-isel"
-
-#include "PIC16.h"
-#include "PIC16RegisterInfo.h"
-#include "PIC16TargetMachine.h"
-#include "PIC16MachineFunctionInfo.h"
-#include "llvm/CodeGen/SelectionDAGISel.h"
-#include "llvm/Support/Compiler.h"
-#include "llvm/Support/raw_ostream.h"
-#include "llvm/Support/Debug.h"
-#include "llvm/Intrinsics.h"
-using namespace llvm;
-
-namespace {
-
-class LLVM_LIBRARY_VISIBILITY PIC16DAGToDAGISel : public SelectionDAGISel {
-
- /// TM - Keep a reference to PIC16TargetMachine.
- const PIC16TargetMachine &TM;
-
- /// PIC16Lowering - This object fully describes how to lower LLVM code to an
- /// PIC16-specific SelectionDAG.
- const PIC16TargetLowering &PIC16Lowering;
-
-public:
- explicit PIC16DAGToDAGISel(PIC16TargetMachine &tm) :
- SelectionDAGISel(tm),
- TM(tm), PIC16Lowering(*TM.getTargetLowering()) {}
-
- // Pass Name
- virtual const char *getPassName() const {
- return "PIC16 DAG->DAG Pattern Instruction Selection";
- }
-
-private:
- // Include the pieces autogenerated from the target description.
-#include "PIC16GenDAGISel.inc"
-
- SDNode *Select(SDNode *N);
-
- // Match direct address complex pattern.
- bool SelectDirectAddr(SDValue N, SDValue &Address);
-
-};
-
-}
-
diff --git a/lib/Target/PIC16/PIC16ISelLowering.cpp b/lib/Target/PIC16/PIC16ISelLowering.cpp
deleted file mode 100644
index 4cb7a370301..00000000000
--- a/lib/Target/PIC16/PIC16ISelLowering.cpp
+++ /dev/null
@@ -1,2000 +0,0 @@
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file defines the interfaces that PIC16 uses to lower LLVM code into a
-// selection DAG.
-//
-//===----------------------------------------------------------------------===//
-
-#define DEBUG_TYPE "pic16-lower"
-#include "PIC16ABINames.h"
-#include "PIC16ISelLowering.h"
-#include "PIC16TargetObjectFile.h"
-#include "PIC16TargetMachine.h"
-#include "PIC16MachineFunctionInfo.h"
-#include "llvm/DerivedTypes.h"
-#include "llvm/GlobalValue.h"
-#include "llvm/Function.h"
-#include "llvm/CallingConv.h"
-#include "llvm/CodeGen/MachineFrameInfo.h"
-#include "llvm/CodeGen/MachineFunction.h"
-#include "llvm/CodeGen/MachineInstrBuilder.h"
-#include "llvm/CodeGen/MachineRegisterInfo.h"
-#include "llvm/CodeGen/SelectionDAGISel.h"
-#include "llvm/Support/ErrorHandling.h"
-
-
-using namespace llvm;
-
-static const char *getIntrinsicName(unsigned opcode) {
- std::string Basename;
- switch(opcode) {
- default: llvm_unreachable("do not know intrinsic name");
- // Arithmetic Right shift for integer types.
- case PIC16ISD::SRA_I8: Basename = "sra.i8"; break;
- case RTLIB::SRA_I16: Basename = "sra.i16"; break;
- case RTLIB::SRA_I32: Basename = "sra.i32"; break;
-
- // Left shift for integer types.
- case PIC16ISD::SLL_I8: Basename = "sll.i8"; break;
- case RTLIB::SHL_I16: Basename = "sll.i16"; break;
- case RTLIB::SHL_I32: Basename = "sll.i32"; break;
-
- // Logical Right Shift for integer types.
- case PIC16ISD::SRL_I8: Basename = "srl.i8"; break;
- case RTLIB::SRL_I16: Basename = "srl.i16"; break;
- case RTLIB::SRL_I32: Basename = "srl.i32"; break;
-
- // Multiply for integer types.
- case PIC16ISD::MUL_I8: Basename = "mul.i8"; break;
- case RTLIB::MUL_I16: Basename = "mul.i16"; break;
- case RTLIB::MUL_I32: Basename = "mul.i32"; break;
-
- // Signed division for integers.
- case RTLIB::SDIV_I16: Basename = "sdiv.i16"; break;
- case RTLIB::SDIV_I32: Basename = "sdiv.i32"; break;
-
- // Unsigned division for integers.
- case RTLIB::UDIV_I16: Basename = "udiv.i16"; break;
- case RTLIB::UDIV_I32: Basename = "udiv.i32"; break;
-
- // Signed Modulas for integers.
- case RTLIB::SREM_I16: Basename = "srem.i16"; break;
- case RTLIB::SREM_I32: Basename = "srem.i32"; break;
-
- // Unsigned Modulas for integers.
- case RTLIB::UREM_I16: Basename = "urem.i16"; break;
- case RTLIB::UREM_I32: Basename = "urem.i32"; break;
-
- //////////////////////
- // LIBCALLS FOR FLOATS
- //////////////////////
-
- // Float to signed integrals
- case RTLIB::FPTOSINT_F32_I8: Basename = "f32_to_si32"; break;
- case RTLIB::FPTOSINT_F32_I16: Basename = "f32_to_si32"; break;
- case RTLIB::FPTOSINT_F32_I32: Basename = "f32_to_si32"; break;
-
- // Signed integrals to float. char and int are first sign extended to i32
- // before being converted to float, so an I8_F32 or I16_F32 isn't required.
- case RTLIB::SINTTOFP_I32_F32: Basename = "si32_to_f32"; break;
-
- // Float to Unsigned conversions.
- // Signed conversion can be used for unsigned conversion as well.
- // In signed and unsigned versions only the interpretation of the
- // MSB is different. Bit representation remains the same.
- case RTLIB::FPTOUINT_F32_I8: Basename = "f32_to_si32"; break;
- case RTLIB::FPTOUINT_F32_I16: Basename = "f32_to_si32"; break;
- case RTLIB::FPTOUINT_F32_I32: Basename = "f32_to_si32"; break;
-
- // Unsigned to Float conversions. char and int are first zero extended
- // before being converted to float.
- case RTLIB::UINTTOFP_I32_F32: Basename = "ui32_to_f32"; break;
-
- // Floating point add, sub, mul, div.
- case RTLIB::ADD_F32: Basename = "add.f32"; break;
- case RTLIB::SUB_F32: Basename = "sub.f32"; break;
- case RTLIB::MUL_F32: Basename = "mul.f32"; break;
- case RTLIB::DIV_F32: Basename = "div.f32"; break;
-
- // Floating point comparison
- case RTLIB::O_F32: Basename = "unordered.f32"; break;
- case RTLIB::UO_F32: Basename = "unordered.f32"; break;
- case RTLIB::OLE_F32: Basename = "le.f32"; break;
- case RTLIB::OGE_F32: Basename = "ge.f32"; break;
- case RTLIB::OLT_F32: Basename = "lt.f32"; break;
- case RTLIB::OGT_F32: Basename = "gt.f32"; break;
- case RTLIB::OEQ_F32: Basename = "eq.f32"; break;
- case RTLIB::UNE_F32: Basename = "neq.f32"; break;
- }
-
- std::string prefix = PAN::getTagName(PAN::PREFIX_SYMBOL);
- std::string tagname = PAN::getTagName(PAN::LIBCALL);
- std::string Fullname = prefix + tagname + Basename;
-
- // The name has to live through program life.
- return ESNames::createESName(Fullname);
-}
-
-// getStdLibCallName - Get the name for the standard library function.
-static const char *getStdLibCallName(unsigned opcode) {
- std::string BaseName;
- switch(opcode) {
- case RTLIB::COS_F32: BaseName = "cos";
- break;
- case RTLIB::SIN_F32: BaseName = "sin";
- break;
- case RTLIB::MEMCPY: BaseName = "memcpy";
- break;
- case RTLIB::MEMSET: BaseName = "memset";
- break;
- case RTLIB::MEMMOVE: BaseName = "memmove";
- break;
- default: llvm_unreachable("do not know std lib call name");
- }
- std::string prefix = PAN::getTagName(PAN::PREFIX_SYMBOL);
- std::string LibCallName = prefix + BaseName;
-
- // The name has to live through program life.
- return ESNames::createESName(LibCallName);
-}
-
-// PIC16TargetLowering Constructor.
-PIC16TargetLowering::PIC16TargetLowering(PIC16TargetMachine &TM)
- : TargetLowering(TM, new PIC16TargetObjectFile()) {
-
- Subtarget = &TM.getSubtarget();
-
- addRegisterClass(MVT::i8, PIC16::GPRRegisterClass);
-
- setShiftAmountType(MVT::i8);
-
- // Std lib call names
- setLibcallName(RTLIB::COS_F32, getStdLibCallName(RTLIB::COS_F32));
- setLibcallName(RTLIB::SIN_F32, getStdLibCallName(RTLIB::SIN_F32));
- setLibcallName(RTLIB::MEMCPY, getStdLibCallName(RTLIB::MEMCPY));
- setLibcallName(RTLIB::MEMSET, getStdLibCallName(RTLIB::MEMSET));
- setLibcallName(RTLIB::MEMMOVE, getStdLibCallName(RTLIB::MEMMOVE));
-
- // SRA library call names
- setPIC16LibcallName(PIC16ISD::SRA_I8, getIntrinsicName(PIC16ISD::SRA_I8));
- setLibcallName(RTLIB::SRA_I16, getIntrinsicName(RTLIB::SRA_I16));
- setLibcallName(RTLIB::SRA_I32, getIntrinsicName(RTLIB::SRA_I32));
-
- // SHL library call names
- setPIC16LibcallName(PIC16ISD::SLL_I8, getIntrinsicName(PIC16ISD::SLL_I8));
- setLibcallName(RTLIB::SHL_I16, getIntrinsicName(RTLIB::SHL_I16));
- setLibcallName(RTLIB::SHL_I32, getIntrinsicName(RTLIB::SHL_I32));
-
- // SRL library call names
- setPIC16LibcallName(PIC16ISD::SRL_I8, getIntrinsicName(PIC16ISD::SRL_I8));
- setLibcallName(RTLIB::SRL_I16, getIntrinsicName(RTLIB::SRL_I16));
- setLibcallName(RTLIB::SRL_I32, getIntrinsicName(RTLIB::SRL_I32));
-
- // MUL Library call names
- setPIC16LibcallName(PIC16ISD::MUL_I8, getIntrinsicName(PIC16ISD::MUL_I8));
- setLibcallName(RTLIB::MUL_I16, getIntrinsicName(RTLIB::MUL_I16));
- setLibcallName(RTLIB::MUL_I32, getIntrinsicName(RTLIB::MUL_I32));
-
- // Signed division lib call names
- setLibcallName(RTLIB::SDIV_I16, getIntrinsicName(RTLIB::SDIV_I16));
- setLibcallName(RTLIB::SDIV_I32, getIntrinsicName(RTLIB::SDIV_I32));
-
- // Unsigned division lib call names
- setLibcallName(RTLIB::UDIV_I16, getIntrinsicName(RTLIB::UDIV_I16));
- setLibcallName(RTLIB::UDIV_I32, getIntrinsicName(RTLIB::UDIV_I32));
-
- // Signed remainder lib call names
- setLibcallName(RTLIB::SREM_I16, getIntrinsicName(RTLIB::SREM_I16));
- setLibcallName(RTLIB::SREM_I32, getIntrinsicName(RTLIB::SREM_I32));
-
- // Unsigned remainder lib call names
- setLibcallName(RTLIB::UREM_I16, getIntrinsicName(RTLIB::UREM_I16));
- setLibcallName(RTLIB::UREM_I32, getIntrinsicName(RTLIB::UREM_I32));
-
- // Floating point to signed int conversions.
- setLibcallName(RTLIB::FPTOSINT_F32_I8,
- getIntrinsicName(RTLIB::FPTOSINT_F32_I8));
- setLibcallName(RTLIB::FPTOSINT_F32_I16,
- getIntrinsicName(RTLIB::FPTOSINT_F32_I16));
- setLibcallName(RTLIB::FPTOSINT_F32_I32,
- getIntrinsicName(RTLIB::FPTOSINT_F32_I32));
-
- // Signed int to floats.
- setLibcallName(RTLIB::SINTTOFP_I32_F32,
- getIntrinsicName(RTLIB::SINTTOFP_I32_F32));
-
- // Floating points to unsigned ints.
- setLibcallName(RTLIB::FPTOUINT_F32_I8,
- getIntrinsicName(RTLIB::FPTOUINT_F32_I8));
- setLibcallName(RTLIB::FPTOUINT_F32_I16,
- getIntrinsicName(RTLIB::FPTOUINT_F32_I16));
- setLibcallName(RTLIB::FPTOUINT_F32_I32,
- getIntrinsicName(RTLIB::FPTOUINT_F32_I32));
-
- // Unsigned int to floats.
- setLibcallName(RTLIB::UINTTOFP_I32_F32,
- getIntrinsicName(RTLIB::UINTTOFP_I32_F32));
-
- // Floating point add, sub, mul ,div.
- setLibcallName(RTLIB::ADD_F32, getIntrinsicName(RTLIB::ADD_F32));
- setLibcallName(RTLIB::SUB_F32, getIntrinsicName(RTLIB::SUB_F32));
- setLibcallName(RTLIB::MUL_F32, getIntrinsicName(RTLIB::MUL_F32));
- setLibcallName(RTLIB::DIV_F32, getIntrinsicName(RTLIB::DIV_F32));
-
- // Floationg point comparison
- setLibcallName(RTLIB::O_F32, getIntrinsicName(RTLIB::O_F32));
- setLibcallName(RTLIB::UO_F32, getIntrinsicName(RTLIB::UO_F32));
- setLibcallName(RTLIB::OLE_F32, getIntrinsicName(RTLIB::OLE_F32));
- setLibcallName(RTLIB::OGE_F32, getIntrinsicName(RTLIB::OGE_F32));
- setLibcallName(RTLIB::OLT_F32, getIntrinsicName(RTLIB::OLT_F32));
- setLibcallName(RTLIB::OGT_F32, getIntrinsicName(RTLIB::OGT_F32));
- setLibcallName(RTLIB::OEQ_F32, getIntrinsicName(RTLIB::OEQ_F32));
- setLibcallName(RTLIB::UNE_F32, getIntrinsicName(RTLIB::UNE_F32));
-
- // Return value comparisons of floating point calls.
- setCmpLibcallCC(RTLIB::OEQ_F32, ISD::SETNE);
- setCmpLibcallCC(RTLIB::UNE_F32, ISD::SETNE);
- setCmpLibcallCC(RTLIB::OLT_F32, ISD::SETNE);
- setCmpLibcallCC(RTLIB::OLE_F32, ISD::SETNE);
- setCmpLibcallCC(RTLIB::OGE_F32, ISD::SETNE);
- setCmpLibcallCC(RTLIB::OGT_F32, ISD::SETNE);
- setCmpLibcallCC(RTLIB::UO_F32, ISD::SETNE);
- setCmpLibcallCC(RTLIB::O_F32, ISD::SETEQ);
-
- setOperationAction(ISD::GlobalAddress, MVT::i16, Custom);
- setOperationAction(ISD::ExternalSymbol, MVT::i16, Custom);
-
- setOperationAction(ISD::LOAD, MVT::i8, Legal);
- setOperationAction(ISD::LOAD, MVT::i16, Custom);
- setOperationAction(ISD::LOAD, MVT::i32, Custom);
-
- setOperationAction(ISD::STORE, MVT::i8, Legal);
- setOperationAction(ISD::STORE, MVT::i16, Custom);
- setOperationAction(ISD::STORE, MVT::i32, Custom);
- setOperationAction(ISD::STORE, MVT::i64, Custom);
-
- setOperationAction(ISD::ADDE, MVT::i8, Custom);
- setOperationAction(ISD::ADDC, MVT::i8, Custom);
- setOperationAction(ISD::SUBE, MVT::i8, Custom);
- setOperationAction(ISD::SUBC, MVT::i8, Custom);
- setOperationAction(ISD::SUB, MVT::i8, Custom);
- setOperationAction(ISD::ADD, MVT::i8, Custom);
- setOperationAction(ISD::ADD, MVT::i16, Custom);
-
- setOperationAction(ISD::OR, MVT::i8, Custom);
- setOperationAction(ISD::AND, MVT::i8, Custom);
- setOperationAction(ISD::XOR, MVT::i8, Custom);
-
- setOperationAction(ISD::FrameIndex, MVT::i16, Custom);
-
- setOperationAction(ISD::MUL, MVT::i8, Custom);
-
- setOperationAction(ISD::SMUL_LOHI, MVT::i8, Expand);
- setOperationAction(ISD::UMUL_LOHI, MVT::i8, Expand);
- setOperationAction(ISD::MULHU, MVT::i8, Expand);
- setOperationAction(ISD::MULHS, MVT::i8, Expand);
-
- setOperationAction(ISD::SRA, MVT::i8, Custom);
- setOperationAction(ISD::SHL, MVT::i8, Custom);
- setOperationAction(ISD::SRL, MVT::i8, Custom);
-
- setOperationAction(ISD::ROTL, MVT::i8, Expand);
- setOperationAction(ISD::ROTR, MVT::i8, Expand);
-
- setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1, Expand);
-
- // PIC16 does not support shift parts
- setOperationAction(ISD::SRA_PARTS, MVT::i8, Expand);
- setOperationAction(ISD::SHL_PARTS, MVT::i8, Expand);
- setOperationAction(ISD::SRL_PARTS, MVT::i8, Expand);
-
-
- // PIC16 does not have a SETCC, expand it to SELECT_CC.
- setOperationAction(ISD::SETCC, MVT::i8, Expand);
- setOperationAction(ISD::SELECT, MVT::i8, Expand);
- setOperationAction(ISD::BRCOND, MVT::Other, Expand);
- setOperationAction(ISD::BRIND, MVT::Other, Expand);
-
- setOperationAction(ISD::SELECT_CC, MVT::i8, Custom);
- setOperationAction(ISD::BR_CC, MVT::i8, Custom);
-
- //setOperationAction(ISD::TRUNCATE, MVT::i16, Custom);
- setTruncStoreAction(MVT::i16, MVT::i8, Custom);
-
- // Now deduce the information based on the above mentioned
- // actions
- computeRegisterProperties();
-}
-
-std::pair
-PIC16TargetLowering::findRepresentativeClass(EVT VT) const {
- switch (VT.getSimpleVT().SimpleTy) {
- default:
- return TargetLowering::findRepresentativeClass(VT);
- case MVT::i16:
- return std::make_pair(PIC16::FSR16RegisterClass, 1);
- }
-}
-
-// getOutFlag - Extract the flag result if the Op has it.
-static SDValue getOutFlag(SDValue &Op) {
- // Flag is the last value of the node.
- SDValue Flag = Op.getValue(Op.getNode()->getNumValues() - 1);
-
- assert (Flag.getValueType() == MVT::Flag
- && "Node does not have an out Flag");
-
- return Flag;
-}
-// Get the TmpOffset for FrameIndex
-unsigned PIC16TargetLowering::GetTmpOffsetForFI(unsigned FI, unsigned size,
- MachineFunction &MF) const {
- PIC16MachineFunctionInfo *FuncInfo = MF.getInfo();
- std::map &FiTmpOffsetMap = FuncInfo->getFiTmpOffsetMap();
-
- std::map::iterator
- MapIt = FiTmpOffsetMap.find(FI);
- if (MapIt != FiTmpOffsetMap.end())
- return MapIt->second;
-
- // This FI (FrameIndex) is not yet mapped, so map it
- FiTmpOffsetMap[FI] = FuncInfo->getTmpSize();
- FuncInfo->setTmpSize(FuncInfo->getTmpSize() + size);
- return FiTmpOffsetMap[FI];
-}
-
-void PIC16TargetLowering::ResetTmpOffsetMap(SelectionDAG &DAG) const {
- MachineFunction &MF = DAG.getMachineFunction();
- PIC16MachineFunctionInfo *FuncInfo = MF.getInfo();
- FuncInfo->getFiTmpOffsetMap().clear();
- FuncInfo->setTmpSize(0);
-}
-
-// To extract chain value from the SDValue Nodes
-// This function will help to maintain the chain extracting
-// code at one place. In case of any change in future it will
-// help maintain the code.
-static SDValue getChain(SDValue &Op) {
- SDValue Chain = Op.getValue(Op.getNode()->getNumValues() - 1);
-
- // If the last value returned in Flag then the chain is
- // second last value returned.
- if (Chain.getValueType() == MVT::Flag)
- Chain = Op.getValue(Op.getNode()->getNumValues() - 2);
-
- // All nodes may not produce a chain. Therefore following assert
- // verifies that the node is returning a chain only.
- assert (Chain.getValueType() == MVT::Other
- && "Node does not have a chain");
-
- return Chain;
-}
-
-/// PopulateResults - Helper function to LowerOperation.
-/// If a node wants to return multiple results after lowering,
-/// it stuffs them into an array of SDValue called Results.
-
-static void PopulateResults(SDValue N, SmallVectorImpl&Results) {
- if (N.getOpcode() == ISD::MERGE_VALUES) {
- int NumResults = N.getNumOperands();
- for( int i = 0; i < NumResults; i++)
- Results.push_back(N.getOperand(i));
- }
- else
- Results.push_back(N);
-}
-
-MVT::SimpleValueType
-PIC16TargetLowering::getSetCCResultType(EVT ValType) const {
- return MVT::i8;
-}
-
-MVT::SimpleValueType
-PIC16TargetLowering::getCmpLibcallReturnType() const {
- return MVT::i8;
-}
-
-/// The type legalizer framework of generating legalizer can generate libcalls
-/// only when the operand/result types are illegal.
-/// PIC16 needs to generate libcalls even for the legal types (i8) for some ops.
-/// For example an arithmetic right shift. These functions are used to lower
-/// such operations that generate libcall for legal types.
-
-void
-PIC16TargetLowering::setPIC16LibcallName(PIC16ISD::PIC16Libcall Call,
- const char *Name) {
- PIC16LibcallNames[Call] = Name;
-}
-
-const char *
-PIC16TargetLowering::getPIC16LibcallName(PIC16ISD::PIC16Libcall Call) const {
- return PIC16LibcallNames[Call];
-}
-
-SDValue
-PIC16TargetLowering::MakePIC16Libcall(PIC16ISD::PIC16Libcall Call,
- EVT RetVT, const SDValue *Ops,
- unsigned NumOps, bool isSigned,
- SelectionDAG &DAG, DebugLoc dl) const {
-
- TargetLowering::ArgListTy Args;
- Args.reserve(NumOps);
-
- TargetLowering::ArgListEntry Entry;
- for (unsigned i = 0; i != NumOps; ++i) {
- Entry.Node = Ops[i];
- Entry.Ty = Entry.Node.getValueType().getTypeForEVT(*DAG.getContext());
- Entry.isSExt = isSigned;
- Entry.isZExt = !isSigned;
- Args.push_back(Entry);
- }
-
- SDValue Callee = DAG.getExternalSymbol(getPIC16LibcallName(Call), MVT::i16);
-
- const Type *RetTy = RetVT.getTypeForEVT(*DAG.getContext());
- std::pair CallInfo =
- LowerCallTo(DAG.getEntryNode(), RetTy, isSigned, !isSigned, false,
- false, 0, CallingConv::C, false,
- /*isReturnValueUsed=*/true,
- Callee, Args, DAG, dl);
-
- return CallInfo.first;
-}
-
-const char *PIC16TargetLowering::getTargetNodeName(unsigned Opcode) const {
- switch (Opcode) {
- default: return NULL;
- case PIC16ISD::Lo: return "PIC16ISD::Lo";
- case PIC16ISD::Hi: return "PIC16ISD::Hi";
- case PIC16ISD::MTLO: return "PIC16ISD::MTLO";
- case PIC16ISD::MTHI: return "PIC16ISD::MTHI";
- case PIC16ISD::MTPCLATH: return "PIC16ISD::MTPCLATH";
- case PIC16ISD::PIC16Connect: return "PIC16ISD::PIC16Connect";
- case PIC16ISD::Banksel: return "PIC16ISD::Banksel";
- case PIC16ISD::PIC16Load: return "PIC16ISD::PIC16Load";
- case PIC16ISD::PIC16LdArg: return "PIC16ISD::PIC16LdArg";
- case PIC16ISD::PIC16LdWF: return "PIC16ISD::PIC16LdWF";
- case PIC16ISD::PIC16Store: return "PIC16ISD::PIC16Store";
- case PIC16ISD::PIC16StWF: return "PIC16ISD::PIC16StWF";
- case PIC16ISD::BCF: return "PIC16ISD::BCF";
- case PIC16ISD::LSLF: return "PIC16ISD::LSLF";
- case PIC16ISD::LRLF: return "PIC16ISD::LRLF";
- case PIC16ISD::RLF: return "PIC16ISD::RLF";
- case PIC16ISD::RRF: return "PIC16ISD::RRF";
- case PIC16ISD::CALL: return "PIC16ISD::CALL";
- case PIC16ISD::CALLW: return "PIC16ISD::CALLW";
- case PIC16ISD::SUBCC: return "PIC16ISD::SUBCC";
- case PIC16ISD::SELECT_ICC: return "PIC16ISD::SELECT_ICC";
- case PIC16ISD::BRCOND: return "PIC16ISD::BRCOND";
- case PIC16ISD::RET: return "PIC16ISD::RET";
- case PIC16ISD::Dummy: return "PIC16ISD::Dummy";
- }
-}
-
-void PIC16TargetLowering::ReplaceNodeResults(SDNode *N,
- SmallVectorImpl&Results,
- SelectionDAG &DAG) const {
-
- switch (N->getOpcode()) {
- case ISD::GlobalAddress:
- Results.push_back(ExpandGlobalAddress(N, DAG));
- return;
- case ISD::ExternalSymbol:
- Results.push_back(ExpandExternalSymbol(N, DAG));
- return;
- case ISD::STORE:
- Results.push_back(ExpandStore(N, DAG));
- return;
- case ISD::LOAD:
- PopulateResults(ExpandLoad(N, DAG), Results);
- return;
- case ISD::ADD:
- // Results.push_back(ExpandAdd(N, DAG));
- return;
- case ISD::FrameIndex:
- Results.push_back(ExpandFrameIndex(N, DAG));
- return;
- default:
- assert (0 && "not implemented");
- return;
- }
-}
-
-SDValue PIC16TargetLowering::ExpandFrameIndex(SDNode *N,
- SelectionDAG &DAG) const {
-
- // Currently handling FrameIndex of size MVT::i16 only
- // One example of this scenario is when return value is written on
- // FrameIndex#0
-
- if (N->getValueType(0) != MVT::i16)
- return SDValue();
-
- // Expand the FrameIndex into ExternalSymbol and a Constant node
- // The constant will represent the frame index number
- // Get the current function frame
- MachineFunction &MF = DAG.getMachineFunction();
- const Function *Func = MF.getFunction();
- const std::string Name = Func->getName();
-
- FrameIndexSDNode *FR = dyn_cast(SDValue(N,0));
- // FIXME there isn't really debug info here
- DebugLoc dl = FR->getDebugLoc();
-
- // Expand FrameIndex like GlobalAddress and ExternalSymbol
- // Also use Offset field for lo and hi parts. The default
- // offset is zero.
-
- SDValue ES;
- int FrameOffset;
- SDValue FI = SDValue(N,0);
- LegalizeFrameIndex(FI, DAG, ES, FrameOffset);
- SDValue Offset = DAG.getConstant(FrameOffset, MVT::i8);
- SDValue Lo = DAG.getNode(PIC16ISD::Lo, dl, MVT::i8, ES, Offset);
- SDValue Hi = DAG.getNode(PIC16ISD::Hi, dl, MVT::i8, ES, Offset);
- return DAG.getNode(ISD::BUILD_PAIR, dl, N->getValueType(0), Lo, Hi);
-}
-
-
-SDValue PIC16TargetLowering::ExpandStore(SDNode *N, SelectionDAG &DAG) const {
- StoreSDNode *St = cast(N);
- SDValue Chain = St->getChain();
- SDValue Src = St->getValue();
- SDValue Ptr = St->getBasePtr();
- EVT ValueType = Src.getValueType();
- unsigned StoreOffset = 0;
- DebugLoc dl = N->getDebugLoc();
-
- SDValue PtrLo, PtrHi;
- LegalizeAddress(Ptr, DAG, PtrLo, PtrHi, StoreOffset, dl);
-
- if (ValueType == MVT::i8) {
- return DAG.getNode (PIC16ISD::PIC16Store, dl, MVT::Other, Chain, Src,
- PtrLo, PtrHi,
- DAG.getConstant (0 + StoreOffset, MVT::i8));
- }
- else if (ValueType == MVT::i16) {
- // Get the Lo and Hi parts from MERGE_VALUE or BUILD_PAIR.
- SDValue SrcLo, SrcHi;
- GetExpandedParts(Src, DAG, SrcLo, SrcHi);
- SDValue ChainLo = Chain, ChainHi = Chain;
- // FIXME: This makes unsafe assumptions. The Chain may be a TokenFactor
- // created for an unrelated purpose, in which case it may not have
- // exactly two operands. Also, even if it does have two operands, they
- // may not be the low and high parts of an aligned load that was split.
- if (Chain.getOpcode() == ISD::TokenFactor) {
- ChainLo = Chain.getOperand(0);
- ChainHi = Chain.getOperand(1);
- }
- SDValue Store1 = DAG.getNode(PIC16ISD::PIC16Store, dl, MVT::Other,
- ChainLo,
- SrcLo, PtrLo, PtrHi,
- DAG.getConstant (0 + StoreOffset, MVT::i8));
-
- SDValue Store2 = DAG.getNode(PIC16ISD::PIC16Store, dl, MVT::Other, ChainHi,
- SrcHi, PtrLo, PtrHi,
- DAG.getConstant (1 + StoreOffset, MVT::i8));
-
- return DAG.getNode(ISD::TokenFactor, dl, MVT::Other, getChain(Store1),
- getChain(Store2));
- }
- else if (ValueType == MVT::i32) {
- // Get the Lo and Hi parts from MERGE_VALUE or BUILD_PAIR.
- SDValue SrcLo, SrcHi;
- GetExpandedParts(Src, DAG, SrcLo, SrcHi);
-
- // Get the expanded parts of each of SrcLo and SrcHi.
- SDValue SrcLo1, SrcLo2, SrcHi1, SrcHi2;
- GetExpandedParts(SrcLo, DAG, SrcLo1, SrcLo2);
- GetExpandedParts(SrcHi, DAG, SrcHi1, SrcHi2);
-
- SDValue ChainLo = Chain, ChainHi = Chain;
- // FIXME: This makes unsafe assumptions; see the FIXME above.
- if (Chain.getOpcode() == ISD::TokenFactor) {
- ChainLo = Chain.getOperand(0);
- ChainHi = Chain.getOperand(1);
- }
- SDValue ChainLo1 = ChainLo, ChainLo2 = ChainLo, ChainHi1 = ChainHi,
- ChainHi2 = ChainHi;
- // FIXME: This makes unsafe assumptions; see the FIXME above.
- if (ChainLo.getOpcode() == ISD::TokenFactor) {
- ChainLo1 = ChainLo.getOperand(0);
- ChainLo2 = ChainLo.getOperand(1);
- }
- // FIXME: This makes unsafe assumptions; see the FIXME above.
- if (ChainHi.getOpcode() == ISD::TokenFactor) {
- ChainHi1 = ChainHi.getOperand(0);
- ChainHi2 = ChainHi.getOperand(1);
- }
- SDValue Store1 = DAG.getNode(PIC16ISD::PIC16Store, dl, MVT::Other,
- ChainLo1,
- SrcLo1, PtrLo, PtrHi,
- DAG.getConstant (0 + StoreOffset, MVT::i8));
-
- SDValue Store2 = DAG.getNode(PIC16ISD::PIC16Store, dl, MVT::Other, ChainLo2,
- SrcLo2, PtrLo, PtrHi,
- DAG.getConstant (1 + StoreOffset, MVT::i8));
-
- SDValue Store3 = DAG.getNode(PIC16ISD::PIC16Store, dl, MVT::Other, ChainHi1,
- SrcHi1, PtrLo, PtrHi,
- DAG.getConstant (2 + StoreOffset, MVT::i8));
-
- SDValue Store4 = DAG.getNode(PIC16ISD::PIC16Store, dl, MVT::Other, ChainHi2,
- SrcHi2, PtrLo, PtrHi,
- DAG.getConstant (3 + StoreOffset, MVT::i8));
-
- SDValue RetLo = DAG.getNode(ISD::TokenFactor, dl, MVT::Other,
- getChain(Store1), getChain(Store2));
- SDValue RetHi = DAG.getNode(ISD::TokenFactor, dl, MVT::Other,
- getChain(Store3), getChain(Store4));
- return DAG.getNode(ISD::TokenFactor, dl, MVT::Other, RetLo, RetHi);
-
- } else if (ValueType == MVT::i64) {
- SDValue SrcLo, SrcHi;
- GetExpandedParts(Src, DAG, SrcLo, SrcHi);
- SDValue ChainLo = Chain, ChainHi = Chain;
- // FIXME: This makes unsafe assumptions; see the FIXME above.
- if (Chain.getOpcode() == ISD::TokenFactor) {
- ChainLo = Chain.getOperand(0);
- ChainHi = Chain.getOperand(1);
- }
- SDValue Store1 = DAG.getStore(ChainLo, dl, SrcLo, Ptr, MachinePointerInfo(),
- false, false, 0);
-
- Ptr = DAG.getNode(ISD::ADD, dl, Ptr.getValueType(), Ptr,
- DAG.getConstant(4, Ptr.getValueType()));
- SDValue Store2 = DAG.getStore(ChainHi, dl, SrcHi, Ptr, MachinePointerInfo(),
- false, false, 0);
-
- return DAG.getNode(ISD::TokenFactor, dl, MVT::Other, Store1,
- Store2);
- } else {
- assert (0 && "value type not supported");
- return SDValue();
- }
-}
-
-SDValue PIC16TargetLowering::ExpandExternalSymbol(SDNode *N,
- SelectionDAG &DAG)
- const {
- ExternalSymbolSDNode *ES = dyn_cast(SDValue(N, 0));
- // FIXME there isn't really debug info here
- DebugLoc dl = ES->getDebugLoc();
-
- SDValue TES = DAG.getTargetExternalSymbol(ES->getSymbol(), MVT::i8);
- SDValue Offset = DAG.getConstant(0, MVT::i8);
- SDValue Lo = DAG.getNode(PIC16ISD::Lo, dl, MVT::i8, TES, Offset);
- SDValue Hi = DAG.getNode(PIC16ISD::Hi, dl, MVT::i8, TES, Offset);
-
- return DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i16, Lo, Hi);
-}
-
-// ExpandGlobalAddress -
-SDValue PIC16TargetLowering::ExpandGlobalAddress(SDNode *N,
- SelectionDAG &DAG) const {
- GlobalAddressSDNode *G = dyn_cast(SDValue(N, 0));
- // FIXME there isn't really debug info here
- DebugLoc dl = G->getDebugLoc();
-
- SDValue TGA = DAG.getTargetGlobalAddress(G->getGlobal(), N->getDebugLoc(),
- MVT::i8,
- G->getOffset());
-
- SDValue Offset = DAG.getConstant(0, MVT::i8);
- SDValue Lo = DAG.getNode(PIC16ISD::Lo, dl, MVT::i8, TGA, Offset);
- SDValue Hi = DAG.getNode(PIC16ISD::Hi, dl, MVT::i8, TGA, Offset);
-
- return DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i16, Lo, Hi);
-}
-
-bool PIC16TargetLowering::isDirectAddress(const SDValue &Op) const {
- assert (Op.getNode() != NULL && "Can't operate on NULL SDNode!!");
-
- if (Op.getOpcode() == ISD::BUILD_PAIR) {
- if (Op.getOperand(0).getOpcode() == PIC16ISD::Lo)
- return true;
- }
- return false;
-}
-
-// Return true if DirectAddress is in ROM_SPACE
-bool PIC16TargetLowering::isRomAddress(const SDValue &Op) const {
-
- // RomAddress is a GlobalAddress in ROM_SPACE_
- // If the Op is not a GlobalAddress return NULL without checking
- // anything further.
- if (!isDirectAddress(Op))
- return false;
-
- // Its a GlobalAddress.
- // It is BUILD_PAIR((PIC16Lo TGA), (PIC16Hi TGA)) and Op is BUILD_PAIR
- SDValue TGA = Op.getOperand(0).getOperand(0);
- GlobalAddressSDNode *GSDN = dyn_cast(TGA);
-
- if (GSDN->getAddressSpace() == PIC16ISD::ROM_SPACE)
- return true;
-
- // Any other address space return it false
- return false;
-}
-
-
-// GetExpandedParts - This function is on the similiar lines as
-// the GetExpandedInteger in type legalizer is. This returns expanded
-// parts of Op in Lo and Hi.
-
-void PIC16TargetLowering::GetExpandedParts(SDValue Op, SelectionDAG &DAG,
- SDValue &Lo, SDValue &Hi) const {
- SDNode *N = Op.getNode();
- DebugLoc dl = N->getDebugLoc();
- EVT NewVT = getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
-
- // Extract the lo component.
- Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, NewVT, Op,
- DAG.getConstant(0, MVT::i8));
-
- // extract the hi component
- Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, NewVT, Op,
- DAG.getConstant(1, MVT::i8));
-}
-
-// Legalize FrameIndex into ExternalSymbol and offset.
-void
-PIC16TargetLowering::LegalizeFrameIndex(SDValue Op, SelectionDAG &DAG,
- SDValue &ES, int &Offset) const {
-
- MachineFunction &MF = DAG.getMachineFunction();
- const Function *Func = MF.getFunction();
- MachineFrameInfo *MFI = MF.getFrameInfo();
- PIC16MachineFunctionInfo *FuncInfo = MF.getInfo();
- const std::string Name = Func->getName();
-
- FrameIndexSDNode *FR = dyn_cast(Op);
-
- // FrameIndices are not stack offsets. But they represent the request
- // for space on stack. That space requested may be more than one byte.
- // Therefore, to calculate the stack offset that a FrameIndex aligns
- // with, we need to traverse all the FrameIndices available earlier in
- // the list and add their requested size.
- unsigned FIndex = FR->getIndex();
- const char *tmpName;
- if (FIndex < FuncInfo->getReservedFrameCount()) {
- tmpName = ESNames::createESName(PAN::getFrameLabel(Name));
- ES = DAG.getTargetExternalSymbol(tmpName, MVT::i8);
- Offset = 0;
- for (unsigned i=0; igetObjectSize(i);
- }
- } else {
- // FrameIndex has been made for some temporary storage
- tmpName = ESNames::createESName(PAN::getTempdataLabel(Name));
- ES = DAG.getTargetExternalSymbol(tmpName, MVT::i8);
- Offset = GetTmpOffsetForFI(FIndex, MFI->getObjectSize(FIndex), MF);
- }
-
- return;
-}
-
-// This function legalizes the PIC16 Addresses. If the Pointer is
-// -- Direct address variable residing
-// --> then a Banksel for that variable will be created.
-// -- Rom variable
-// --> then it will be treated as an indirect address.
-// -- Indirect address
-// --> then the address will be loaded into FSR
-// -- ADD with constant operand
-// --> then constant operand of ADD will be returned as Offset
-// and non-constant operand of ADD will be treated as pointer.
-// Returns the high and lo part of the address, and the offset(in case of ADD).
-
-void PIC16TargetLowering::LegalizeAddress(SDValue Ptr, SelectionDAG &DAG,
- SDValue &Lo, SDValue &Hi,
- unsigned &Offset, DebugLoc dl) const {
-
- // Offset, by default, should be 0
- Offset = 0;
-
- // If the pointer is ADD with constant,
- // return the constant value as the offset
- if (Ptr.getOpcode() == ISD::ADD) {
- SDValue OperLeft = Ptr.getOperand(0);
- SDValue OperRight = Ptr.getOperand(1);
- if ((OperLeft.getOpcode() == ISD::Constant) &&
- (dyn_cast(OperLeft)->getZExtValue() < 32 )) {
- Offset = dyn_cast(OperLeft)->getZExtValue();
- Ptr = OperRight;
- } else if ((OperRight.getOpcode() == ISD::Constant) &&
- (dyn_cast(OperRight)->getZExtValue() < 32 )){
- Offset = dyn_cast(OperRight)->getZExtValue();
- Ptr = OperLeft;
- }
- }
-
- // If the pointer is Type i8 and an external symbol
- // then treat it as direct address.
- // One example for such case is storing and loading
- // from function frame during a call
- if (Ptr.getValueType() == MVT::i8) {
- switch (Ptr.getOpcode()) {
- case ISD::TargetExternalSymbol:
- Lo = Ptr;
- Hi = DAG.getConstant(1, MVT::i8);
- return;
- }
- }
-
- // Expansion of FrameIndex has Lo/Hi parts
- if (isDirectAddress(Ptr)) {
- SDValue TFI = Ptr.getOperand(0).getOperand(0);
- int FrameOffset;
- if (TFI.getOpcode() == ISD::TargetFrameIndex) {
- LegalizeFrameIndex(TFI, DAG, Lo, FrameOffset);
- Hi = DAG.getConstant(1, MVT::i8);
- Offset += FrameOffset;
- return;
- } else if (TFI.getOpcode() == ISD::TargetExternalSymbol) {
- // FrameIndex has already been expanded.
- // Now just make use of its expansion
- Lo = TFI;
- Hi = DAG.getConstant(1, MVT::i8);
- SDValue FOffset = Ptr.getOperand(0).getOperand(1);
- assert (FOffset.getOpcode() == ISD::Constant &&
- "Invalid operand of PIC16ISD::Lo");
- Offset += dyn_cast(FOffset)->getZExtValue();
- return;
- }
- }
-
- if (isDirectAddress(Ptr) && !isRomAddress(Ptr)) {
- // Direct addressing case for RAM variables. The Hi part is constant
- // and the Lo part is the TGA itself.
- Lo = Ptr.getOperand(0).getOperand(0);
-
- // For direct addresses Hi is a constant. Value 1 for the constant
- // signifies that banksel needs to generated for it. Value 0 for
- // the constant signifies that banksel does not need to be generated
- // for it. Mark it as 1 now and optimize later.
- Hi = DAG.getConstant(1, MVT::i8);
- return;
- }
-
- // Indirect addresses. Get the hi and lo parts of ptr.
- GetExpandedParts(Ptr, DAG, Lo, Hi);
-
- // Put the hi and lo parts into FSR.
- Lo = DAG.getNode(PIC16ISD::MTLO, dl, MVT::i8, Lo);
- Hi = DAG.getNode(PIC16ISD::MTHI, dl, MVT::i8, Hi);
-
- return;
-}
-
-SDValue PIC16TargetLowering::ExpandLoad(SDNode *N, SelectionDAG &DAG) const {
- LoadSDNode *LD = dyn_cast(SDValue(N, 0));
- SDValue Chain = LD->getChain();
- SDValue Ptr = LD->getBasePtr();
- DebugLoc dl = LD->getDebugLoc();
-
- SDValue Load, Offset;
- SDVTList Tys;
- EVT VT, NewVT;
- SDValue PtrLo, PtrHi;
- unsigned LoadOffset;
-
- // Legalize direct/indirect addresses. This will give the lo and hi parts
- // of the address and the offset.
- LegalizeAddress(Ptr, DAG, PtrLo, PtrHi, LoadOffset, dl);
-
- // Load from the pointer (direct address or FSR)
- VT = N->getValueType(0);
- unsigned NumLoads = VT.getSizeInBits() / 8;
- std::vector PICLoads;
- unsigned iter;
- EVT MemVT = LD->getMemoryVT();
- if(ISD::isNON_EXTLoad(N)) {
- for (iter=0; itergetMemoryVT();
- unsigned MemBytes = MemVT.getSizeInBits() / 8;
- // if MVT::i1 is extended to MVT::i8 then MemBytes will be zero
- // So set it to one
- if (MemBytes == 0) MemBytes = 1;
-
- unsigned ExtdBytes = VT.getSizeInBits() / 8;
- Offset = DAG.getConstant(LoadOffset, MVT::i8);
-
- Tys = DAG.getVTList(MVT::i8, MVT::Other);
- // For MemBytes generate PIC16Load with proper offset
- for (iter=0; iter < MemBytes; ++iter) {
- // Add the pointer offset if any
- Offset = DAG.getConstant(iter + LoadOffset, MVT::i8);
- Load = DAG.getNode(PIC16ISD::PIC16Load, dl, Tys, Chain, PtrLo, PtrHi,
- Offset);
- PICLoads.push_back(Load);
- }
-
- // For SignExtendedLoad
- if (ISD::isSEXTLoad(N)) {
- // For all ExtdBytes use the Right Shifted(Arithmetic) Value of the
- // highest MemByte
- SDValue SRA = DAG.getNode(ISD::SRA, dl, MVT::i8, Load,
- DAG.getConstant(7, MVT::i8));
- for (iter=MemBytes; itergetOperand(0);
- SDValue Amt = N->getOperand(1);
- PIC16ISD::PIC16Libcall CallCode;
- switch (N->getOpcode()) {
- case ISD::SRA:
- CallCode = PIC16ISD::SRA_I8;
- break;
- case ISD::SHL:
- CallCode = PIC16ISD::SLL_I8;
- break;
- case ISD::SRL:
- CallCode = PIC16ISD::SRL_I8;
- break;
- default:
- assert ( 0 && "This shift is not implemented yet.");
- return SDValue();
- }
- SmallVector Ops(2);
- Ops[0] = Value;
- Ops[1] = Amt;
- SDValue Call = MakePIC16Libcall(CallCode, N->getValueType(0), &Ops[0], 2,
- true, DAG, N->getDebugLoc());
- return Call;
-}
-
-SDValue PIC16TargetLowering::LowerMUL(SDValue Op, SelectionDAG &DAG) const {
- // We should have handled larger operands in type legalizer itself.
- assert (Op.getValueType() == MVT::i8 && "illegal multiply to lower");
-
- SDNode *N = Op.getNode();
- SmallVector Ops(2);
- Ops[0] = N->getOperand(0);
- Ops[1] = N->getOperand(1);
- SDValue Call = MakePIC16Libcall(PIC16ISD::MUL_I8, N->getValueType(0),
- &Ops[0], 2, true, DAG, N->getDebugLoc());
- return Call;
-}
-
-void
-PIC16TargetLowering::LowerOperationWrapper(SDNode *N,
- SmallVectorImpl&Results,
- SelectionDAG &DAG) const {
- SDValue Op = SDValue(N, 0);
- SDValue Res;
- unsigned i;
- switch (Op.getOpcode()) {
- case ISD::LOAD:
- Res = ExpandLoad(Op.getNode(), DAG); break;
- default: {
- // All other operations are handled in LowerOperation.
- Res = LowerOperation(Op, DAG);
- if (Res.getNode())
- Results.push_back(Res);
-
- return;
- }
- }
-
- N = Res.getNode();
- unsigned NumValues = N->getNumValues();
- for (i = 0; i < NumValues ; i++) {
- Results.push_back(SDValue(N, i));
- }
-}
-
-SDValue PIC16TargetLowering::LowerOperation(SDValue Op,
- SelectionDAG &DAG) const {
- switch (Op.getOpcode()) {
- case ISD::ADD:
- case ISD::ADDC:
- case ISD::ADDE:
- return LowerADD(Op, DAG);
- case ISD::SUB:
- case ISD::SUBC:
- case ISD::SUBE:
- return LowerSUB(Op, DAG);
- case ISD::LOAD:
- return ExpandLoad(Op.getNode(), DAG);
- case ISD::STORE:
- return ExpandStore(Op.getNode(), DAG);
- case ISD::MUL:
- return LowerMUL(Op, DAG);
- case ISD::SHL:
- case ISD::SRA:
- case ISD::SRL:
- return LowerShift(Op, DAG);
- case ISD::OR:
- case ISD::AND:
- case ISD::XOR:
- return LowerBinOp(Op, DAG);
- case ISD::BR_CC:
- return LowerBR_CC(Op, DAG);
- case ISD::SELECT_CC:
- return LowerSELECT_CC(Op, DAG);
- }
- return SDValue();
-}
-
-SDValue PIC16TargetLowering::ConvertToMemOperand(SDValue Op,
- SelectionDAG &DAG,
- DebugLoc dl) const {
- assert (Op.getValueType() == MVT::i8
- && "illegal value type to store on stack.");
-
- MachineFunction &MF = DAG.getMachineFunction();
- const Function *Func = MF.getFunction();
- const std::string FuncName = Func->getName();
-
-
- // Put the value on stack.
- // Get a stack slot index and convert to es.
- int FI = MF.getFrameInfo()->CreateStackObject(1, 1, false);
- const char *tmpName = ESNames::createESName(PAN::getTempdataLabel(FuncName));
- SDValue ES = DAG.getTargetExternalSymbol(tmpName, MVT::i8);
-
- // Store the value to ES.
- SDValue Store = DAG.getNode (PIC16ISD::PIC16Store, dl, MVT::Other,
- DAG.getEntryNode(),
- Op, ES,
- DAG.getConstant (1, MVT::i8), // Banksel.
- DAG.getConstant (GetTmpOffsetForFI(FI, 1, MF),
- MVT::i8));
-
- // Load the value from ES.
- SDVTList Tys = DAG.getVTList(MVT::i8, MVT::Other);
- SDValue Load = DAG.getNode(PIC16ISD::PIC16Load, dl, Tys, Store,
- ES, DAG.getConstant (1, MVT::i8),
- DAG.getConstant (GetTmpOffsetForFI(FI, 1, MF),
- MVT::i8));
-
- return Load.getValue(0);
-}
-
-SDValue PIC16TargetLowering::
-LowerIndirectCallArguments(SDValue Chain, SDValue InFlag,
- SDValue DataAddr_Lo, SDValue DataAddr_Hi,
- const SmallVectorImpl &Outs,
- const SmallVectorImpl &OutVals,
- const SmallVectorImpl &Ins,
- DebugLoc dl, SelectionDAG &DAG) const {
- unsigned NumOps = Outs.size();
-
- // If call has no arguments then do nothing and return.
- if (NumOps == 0)
- return Chain;
-
- std::vector Ops;
- SDVTList Tys = DAG.getVTList(MVT::Other, MVT::Flag);
- SDValue Arg, StoreRet;
-
- // For PIC16 ABI the arguments come after the return value.
- unsigned RetVals = Ins.size();
- for (unsigned i = 0, ArgOffset = RetVals; i < NumOps; i++) {
- // Get the arguments
- Arg = OutVals[i];
-
- Ops.clear();
- Ops.push_back(Chain);
- Ops.push_back(Arg);
- Ops.push_back(DataAddr_Lo);
- Ops.push_back(DataAddr_Hi);
- Ops.push_back(DAG.getConstant(ArgOffset, MVT::i8));
- Ops.push_back(InFlag);
-
- StoreRet = DAG.getNode (PIC16ISD::PIC16StWF, dl, Tys, &Ops[0], Ops.size());
-
- Chain = getChain(StoreRet);
- InFlag = getOutFlag(StoreRet);
- ArgOffset++;
- }
- return Chain;
-}
-
-SDValue PIC16TargetLowering::
-LowerDirectCallArguments(SDValue ArgLabel, SDValue Chain, SDValue InFlag,
- const SmallVectorImpl &Outs,
- const SmallVectorImpl &OutVals,
- DebugLoc dl, SelectionDAG &DAG) const {
- unsigned NumOps = Outs.size();
- std::string Name;
- SDValue Arg, StoreAt;
- EVT ArgVT;
- unsigned Size=0;
-
- // If call has no arguments then do nothing and return.
- if (NumOps == 0)
- return Chain;
-
- // FIXME: This portion of code currently assumes only
- // primitive types being passed as arguments.
-
- // Legalize the address before use
- SDValue PtrLo, PtrHi;
- unsigned AddressOffset;
- int StoreOffset = 0;
- LegalizeAddress(ArgLabel, DAG, PtrLo, PtrHi, AddressOffset, dl);
- SDValue StoreRet;
-
- std::vector Ops;
- SDVTList Tys = DAG.getVTList(MVT::Other, MVT::Flag);
- for (unsigned i=0, Offset = 0; i &Ins,
- DebugLoc dl, SelectionDAG &DAG,
- SmallVectorImpl &InVals) const {
- unsigned RetVals = Ins.size();
-
- // If call does not have anything to return
- // then do nothing and go back.
- if (RetVals == 0)
- return Chain;
-
- // Call has something to return
- SDValue LoadRet;
-
- SDVTList Tys = DAG.getVTList(MVT::i8, MVT::Other, MVT::Flag);
- for(unsigned i=0;i &Ins,
- DebugLoc dl, SelectionDAG &DAG,
- SmallVectorImpl &InVals) const {
-
- // Currently handling primitive types only. They will come in
- // i8 parts
- unsigned RetVals = Ins.size();
-
- // Return immediately if the return type is void
- if (RetVals == 0)
- return Chain;
-
- // Call has something to return
-
- // Legalize the address before use
- SDValue LdLo, LdHi;
- unsigned LdOffset;
- LegalizeAddress(RetLabel, DAG, LdLo, LdHi, LdOffset, dl);
-
- SDVTList Tys = DAG.getVTList(MVT::i8, MVT::Other, MVT::Flag);
- SDValue LoadRet;
-
- for(unsigned i=0, Offset=0;i &Outs,
- const SmallVectorImpl &OutVals,
- DebugLoc dl, SelectionDAG &DAG) const {
-
- // Number of values to return
- unsigned NumRet = Outs.size();
-
- // Function returns value always on stack with the offset starting
- // from 0
- MachineFunction &MF = DAG.getMachineFunction();
- const Function *F = MF.getFunction();
- std::string FuncName = F->getName();
-
- const char *tmpName = ESNames::createESName(PAN::getFrameLabel(FuncName));
- SDValue ES = DAG.getTargetExternalSymbol(tmpName, MVT::i8);
- SDValue BS = DAG.getConstant(1, MVT::i8);
- SDValue RetVal;
- for(unsigned i=0;i &Outs,
- const SmallVectorImpl &OutVals,
- const SmallVectorImpl &Ins,
- DebugLoc dl, SelectionDAG &DAG,
- SmallVectorImpl &InVals) const {
- // PIC16 target does not yet support tail call optimization.
- isTailCall = false;
-
- assert(Callee.getValueType() == MVT::i16 &&
- "Don't know how to legalize this call node!!!");
-
- // The flag to track if this is a direct or indirect call.
- bool IsDirectCall = true;
- unsigned RetVals = Ins.size();
- unsigned NumArgs = Outs.size();
-
- SDValue DataAddr_Lo, DataAddr_Hi;
- if (!isa(Callee) &&
- !isa(Callee)) {
- IsDirectCall = false; // This is indirect call
-
- // If this is an indirect call then to pass the arguments
- // and read the return value back, we need the data address
- // of the function being called.
- // To get the data address two more calls need to be made.
-
- // Come here for indirect calls
- SDValue Lo, Hi;
- // Indirect addresses. Get the hi and lo parts of ptr.
- GetExpandedParts(Callee, DAG, Lo, Hi);
- // Connect Lo and Hi parts of the callee with the PIC16Connect
- Callee = DAG.getNode(PIC16ISD::PIC16Connect, dl, MVT::i8, Lo, Hi);
-
- // Read DataAddress only if we have to pass arguments or
- // read return value.
- if ((RetVals > 0) || (NumArgs > 0))
- GetDataAddress(dl, Callee, Chain, DataAddr_Lo, DataAddr_Hi, DAG);
- }
-
- SDValue ZeroOperand = DAG.getConstant(0, MVT::i8);
-
- // Start the call sequence.
- // Carring the Constant 0 along the CALLSEQSTART
- // because there is nothing else to carry.
- SDValue SeqStart = DAG.getCALLSEQ_START(Chain, ZeroOperand);
- Chain = getChain(SeqStart);
- SDValue OperFlag = getOutFlag(SeqStart); // To manage the data dependency
- std::string Name;
-
- // For any direct call - callee will be GlobalAddressNode or
- // ExternalSymbol
- SDValue ArgLabel, RetLabel;
- if (IsDirectCall) {
- // Considering the GlobalAddressNode case here.
- if (GlobalAddressSDNode *G = dyn_cast(Callee)) {
- const GlobalValue *GV = G->getGlobal();
- Callee = DAG.getTargetGlobalAddress(GV, dl, MVT::i8);
- Name = G->getGlobal()->getName();
- } else {// Considering the ExternalSymbol case here
- ExternalSymbolSDNode *ES = dyn_cast(Callee);
- Callee = DAG.getTargetExternalSymbol(ES->getSymbol(), MVT::i8);
- Name = ES->getSymbol();
- }
-
- // Label for argument passing
- const char *argFrame = ESNames::createESName(PAN::getArgsLabel(Name));
- ArgLabel = DAG.getTargetExternalSymbol(argFrame, MVT::i8);
-
- // Label for reading return value
- const char *retName = ESNames::createESName(PAN::getRetvalLabel(Name));
- RetLabel = DAG.getTargetExternalSymbol(retName, MVT::i8);
- } else {
- // if indirect call
- SDValue CodeAddr_Lo = Callee.getOperand(0);
- SDValue CodeAddr_Hi = Callee.getOperand(1);
-
- /*CodeAddr_Lo = DAG.getNode(ISD::ADD, dl, MVT::i8, CodeAddr_Lo,
- DAG.getConstant(2, MVT::i8));*/
-
- // move Hi part in PCLATH
- CodeAddr_Hi = DAG.getNode(PIC16ISD::MTPCLATH, dl, MVT::i8, CodeAddr_Hi);
- Callee = DAG.getNode(PIC16ISD::PIC16Connect, dl, MVT::i8, CodeAddr_Lo,
- CodeAddr_Hi);
- }
-
- // Pass the argument to function before making the call.
- SDValue CallArgs;
- if (IsDirectCall) {
- CallArgs = LowerDirectCallArguments(ArgLabel, Chain, OperFlag,
- Outs, OutVals, dl, DAG);
- Chain = getChain(CallArgs);
- OperFlag = getOutFlag(CallArgs);
- } else {
- CallArgs = LowerIndirectCallArguments(Chain, OperFlag, DataAddr_Lo,
- DataAddr_Hi, Outs, OutVals, Ins,
- dl, DAG);
- Chain = getChain(CallArgs);
- OperFlag = getOutFlag(CallArgs);
- }
-
- SDVTList Tys = DAG.getVTList(MVT::Other, MVT::Flag);
- SDValue PICCall = DAG.getNode(PIC16ISD::CALL, dl, Tys, Chain, Callee,
- OperFlag);
- Chain = getChain(PICCall);
- OperFlag = getOutFlag(PICCall);
-
-
- // Carrying the Constant 0 along the CALLSEQSTART
- // because there is nothing else to carry.
- SDValue SeqEnd = DAG.getCALLSEQ_END(Chain, ZeroOperand, ZeroOperand,
- OperFlag);
- Chain = getChain(SeqEnd);
- OperFlag = getOutFlag(SeqEnd);
-
- // Lower the return value reading after the call.
- if (IsDirectCall)
- return LowerDirectCallReturn(RetLabel, Chain, OperFlag,
- Ins, dl, DAG, InVals);
- else
- return LowerIndirectCallReturn(Chain, OperFlag, DataAddr_Lo,
- DataAddr_Hi, Ins, dl, DAG, InVals);
-}
-
-bool PIC16TargetLowering::isDirectLoad(const SDValue Op) const {
- if (Op.getOpcode() == PIC16ISD::PIC16Load)
- if (Op.getOperand(1).getOpcode() == ISD::TargetGlobalAddress
- || Op.getOperand(1).getOpcode() == ISD::TargetExternalSymbol)
- return true;
- return false;
-}
-
-// NeedToConvertToMemOp - Returns true if one of the operands of the
-// operation 'Op' needs to be put into memory. Also returns the
-// operand no. of the operand to be converted in 'MemOp'. Remember, PIC16 has
-// no instruction that can operation on two registers. Most insns take
-// one register and one memory operand (addwf) / Constant (addlw).
-bool PIC16TargetLowering::NeedToConvertToMemOp(SDValue Op, unsigned &MemOp,
- SelectionDAG &DAG) const {
- // If one of the operand is a constant, return false.
- if (Op.getOperand(0).getOpcode() == ISD::Constant ||
- Op.getOperand(1).getOpcode() == ISD::Constant)
- return false;
-
- // Return false if one of the operands is already a direct
- // load and that operand has only one use.
- if (isDirectLoad(Op.getOperand(0))) {
- if (Op.getOperand(0).hasOneUse()) {
- // Legal and profitable folding check uses the NodeId of DAG nodes.
- // This NodeId is assigned by topological order. Therefore first
- // assign topological order then perform legal and profitable check.
- // Note:- Though this ordering is done before begining with legalization,
- // newly added node during legalization process have NodeId=-1 (NewNode)
- // therefore before performing any check proper ordering of the node is
- // required.
- DAG.AssignTopologicalOrder();
-
- // Direct load operands are folded in binary operations. But before folding
- // verify if this folding is legal. Fold only if it is legal otherwise
- // convert this direct load to a separate memory operation.
- if (SelectionDAGISel::IsLegalToFold(Op.getOperand(0),
- Op.getNode(), Op.getNode(),
- CodeGenOpt::Default))
- return false;
- else
- MemOp = 0;
- }
- }
-
- // For operations that are non-cummutative there is no need to check
- // for right operand because folding right operand may result in
- // incorrect operation.
- if (! SelectionDAG::isCommutativeBinOp(Op.getOpcode()))
- return true;
-
- if (isDirectLoad(Op.getOperand(1))) {
- if (Op.getOperand(1).hasOneUse()) {
- // Legal and profitable folding check uses the NodeId of DAG nodes.
- // This NodeId is assigned by topological order. Therefore first
- // assign topological order then perform legal and profitable check.
- // Note:- Though this ordering is done before begining with legalization,
- // newly added node during legalization process have NodeId=-1 (NewNode)
- // therefore before performing any check proper ordering of the node is
- // required.
- DAG.AssignTopologicalOrder();
-
- // Direct load operands are folded in binary operations. But before folding
- // verify if this folding is legal. Fold only if it is legal otherwise
- // convert this direct load to a separate memory operation.
- if (SelectionDAGISel::IsLegalToFold(Op.getOperand(1),
- Op.getNode(), Op.getNode(),
- CodeGenOpt::Default))
- return false;
- else
- MemOp = 1;
- }
- }
- return true;
-}
-
-// LowerBinOp - Lower a commutative binary operation that does not
-// affect status flag carry.
-SDValue PIC16TargetLowering::LowerBinOp(SDValue Op, SelectionDAG &DAG) const {
- DebugLoc dl = Op.getDebugLoc();
-
- // We should have handled larger operands in type legalizer itself.
- assert (Op.getValueType() == MVT::i8 && "illegal Op to lower");
-
- unsigned MemOp = 1;
- if (NeedToConvertToMemOp(Op, MemOp, DAG)) {
- // Put one value on stack.
- SDValue NewVal = ConvertToMemOperand (Op.getOperand(MemOp), DAG, dl);
-
- return DAG.getNode(Op.getOpcode(), dl, MVT::i8, Op.getOperand(MemOp ^ 1),
- NewVal);
- }
- else {
- return Op;
- }
-}
-
-// LowerADD - Lower all types of ADD operations including the ones
-// that affects carry.
-SDValue PIC16TargetLowering::LowerADD(SDValue Op, SelectionDAG &DAG) const {
- // We should have handled larger operands in type legalizer itself.
- assert (Op.getValueType() == MVT::i8 && "illegal add to lower");
- DebugLoc dl = Op.getDebugLoc();
- unsigned MemOp = 1;
- if (NeedToConvertToMemOp(Op, MemOp, DAG)) {
- // Put one value on stack.
- SDValue NewVal = ConvertToMemOperand (Op.getOperand(MemOp), DAG, dl);
-
- // ADDC and ADDE produce two results.
- SDVTList Tys = DAG.getVTList(MVT::i8, MVT::Flag);
-
- // ADDE has three operands, the last one is the carry bit.
- if (Op.getOpcode() == ISD::ADDE)
- return DAG.getNode(Op.getOpcode(), dl, Tys, Op.getOperand(MemOp ^ 1),
- NewVal, Op.getOperand(2));
- // ADDC has two operands.
- else if (Op.getOpcode() == ISD::ADDC)
- return DAG.getNode(Op.getOpcode(), dl, Tys, Op.getOperand(MemOp ^ 1),
- NewVal);
- // ADD it is. It produces only one result.
- else
- return DAG.getNode(Op.getOpcode(), dl, MVT::i8, Op.getOperand(MemOp ^ 1),
- NewVal);
- }
- else
- return Op;
-}
-
-SDValue PIC16TargetLowering::LowerSUB(SDValue Op, SelectionDAG &DAG) const {
- DebugLoc dl = Op.getDebugLoc();
- // We should have handled larger operands in type legalizer itself.
- assert (Op.getValueType() == MVT::i8 && "illegal sub to lower");
- unsigned MemOp = 1;
- SDVTList Tys = DAG.getVTList(MVT::i8, MVT::Flag);
-
- // Since we don't have an instruction for X - c ,
- // we can change it to X + (-c)
- ConstantSDNode *C = dyn_cast(Op.getOperand(1));
- if (C && (Op.getOpcode() == ISD::SUB))
- {
- return DAG.getNode(ISD::ADD,
- dl, MVT::i8, Op.getOperand(0),
- DAG.getConstant(0-(C->getZExtValue()), MVT::i8));
- }
-
- if (NeedToConvertToMemOp(Op, MemOp, DAG) ||
- (isDirectLoad(Op.getOperand(1)) &&
- (!isDirectLoad(Op.getOperand(0))) &&
- (Op.getOperand(0).getOpcode() != ISD::Constant)))
- {
- // Put first operand on stack.
- SDValue NewVal = ConvertToMemOperand (Op.getOperand(0), DAG, dl);
-
- switch (Op.getOpcode()) {
- default:
- assert (0 && "Opcode unknown.");
- case ISD::SUBE:
- return DAG.getNode(Op.getOpcode(),
- dl, Tys, NewVal, Op.getOperand(1),
- Op.getOperand(2));
- break;
- case ISD::SUBC:
- return DAG.getNode(Op.getOpcode(),
- dl, Tys, NewVal, Op.getOperand(1));
- break;
- case ISD::SUB:
- return DAG.getNode(Op.getOpcode(),
- dl, MVT::i8, NewVal, Op.getOperand(1));
- break;
- }
- }
- else
- return Op;
-}
-
-void PIC16TargetLowering::InitReservedFrameCount(const Function *F,
- SelectionDAG &DAG) const {
- MachineFunction &MF = DAG.getMachineFunction();
- PIC16MachineFunctionInfo *FuncInfo = MF.getInfo();
-
- unsigned NumArgs = F->arg_size();
-
- bool isVoidFunc = (F->getReturnType()->getTypeID() == Type::VoidTyID);
-
- if (isVoidFunc)
- FuncInfo->setReservedFrameCount(NumArgs);
- else
- FuncInfo->setReservedFrameCount(NumArgs + 1);
-}
-
-// LowerFormalArguments - Argument values are loaded from the
-// .args + offset. All arguments are already broken to leaglized
-// types, so the offset just runs from 0 to NumArgVals - 1.
-
-SDValue
-PIC16TargetLowering::LowerFormalArguments(SDValue Chain,
- CallingConv::ID CallConv,
- bool isVarArg,
- const SmallVectorImpl &Ins,
- DebugLoc dl,
- SelectionDAG &DAG,
- SmallVectorImpl &InVals)
- const {
- unsigned NumArgVals = Ins.size();
-
- // Get the callee's name to create the .args label to pass args.
- MachineFunction &MF = DAG.getMachineFunction();
- const Function *F = MF.getFunction();
- std::string FuncName = F->getName();
-
- // Reset the map of FI and TmpOffset
- ResetTmpOffsetMap(DAG);
- // Initialize the ReserveFrameCount
- InitReservedFrameCount(F, DAG);
-
- // Create the .args external symbol.
- const char *tmpName = ESNames::createESName(PAN::getArgsLabel(FuncName));
- SDValue ES = DAG.getTargetExternalSymbol(tmpName, MVT::i8);
-
- // Load arg values from the label + offset.
- SDVTList VTs = DAG.getVTList (MVT::i8, MVT::Other);
- SDValue BS = DAG.getConstant(1, MVT::i8);
- for (unsigned i = 0; i < NumArgVals ; ++i) {
- SDValue Offset = DAG.getConstant(i, MVT::i8);
- SDValue PICLoad = DAG.getNode(PIC16ISD::PIC16LdArg, dl, VTs, Chain, ES, BS,
- Offset);
- Chain = getChain(PICLoad);
- InVals.push_back(PICLoad);
- }
-
- return Chain;
-}
-
-// Perform DAGCombine of PIC16Load.
-// FIXME - Need a more elaborate comment here.
-SDValue PIC16TargetLowering::
-PerformPIC16LoadCombine(SDNode *N, DAGCombinerInfo &DCI) const {
- SelectionDAG &DAG = DCI.DAG;
- SDValue Chain = N->getOperand(0);
- if (N->hasNUsesOfValue(0, 0)) {
- DAG.ReplaceAllUsesOfValueWith(SDValue(N,1), Chain);
- }
- return SDValue();
-}
-
-// For all the functions with arguments some STORE nodes are generated
-// that store the argument on the frameindex. However in PIC16 the arguments
-// are passed on stack only. Therefore these STORE nodes are redundant.
-// To remove these STORE nodes will be removed in PerformStoreCombine
-//
-// Currently this function is doint nothing and will be updated for removing
-// unwanted store operations
-SDValue PIC16TargetLowering::
-PerformStoreCombine(SDNode *N, DAGCombinerInfo &DCI) const {
- return SDValue(N, 0);
- /*
- // Storing an undef value is of no use, so remove it
- if (isStoringUndef(N, Chain, DAG)) {
- return Chain; // remove the store and return the chain
- }
- //else everything is ok.
- return SDValue(N, 0);
- */
-}
-
-SDValue PIC16TargetLowering::PerformDAGCombine(SDNode *N,
- DAGCombinerInfo &DCI) const {
- switch (N->getOpcode()) {
- case ISD::STORE:
- return PerformStoreCombine(N, DCI);
- case PIC16ISD::PIC16Load:
- return PerformPIC16LoadCombine(N, DCI);
- }
- return SDValue();
-}
-
-static PIC16CC::CondCodes IntCCToPIC16CC(ISD::CondCode CC) {
- switch (CC) {
- default: llvm_unreachable("Unknown condition code!");
- case ISD::SETNE: return PIC16CC::NE;
- case ISD::SETEQ: return PIC16CC::EQ;
- case ISD::SETGT: return PIC16CC::GT;
- case ISD::SETGE: return PIC16CC::GE;
- case ISD::SETLT: return PIC16CC::LT;
- case ISD::SETLE: return PIC16CC::LE;
- case ISD::SETULT: return PIC16CC::ULT;
- case ISD::SETULE: return PIC16CC::ULE;
- case ISD::SETUGE: return PIC16CC::UGE;
- case ISD::SETUGT: return PIC16CC::UGT;
- }
-}
-
-// Look at LHS/RHS/CC and see if they are a lowered setcc instruction. If so
-// set LHS/RHS and SPCC to the LHS/RHS of the setcc and SPCC to the condition.
-static void LookThroughSetCC(SDValue &LHS, SDValue &RHS,
- ISD::CondCode CC, unsigned &SPCC) {
- if (isa(RHS) &&
- cast(RHS)->isNullValue() &&
- CC == ISD::SETNE &&
- (LHS.getOpcode() == PIC16ISD::SELECT_ICC &&
- LHS.getOperand(3).getOpcode() == PIC16ISD::SUBCC) &&
- isa(LHS.getOperand(0)) &&
- isa(LHS.getOperand(1)) &&
- cast(LHS.getOperand(0))->isOne() &&
- cast(LHS.getOperand(1))->isNullValue()) {
- SDValue CMPCC = LHS.getOperand(3);
- SPCC = cast(LHS.getOperand(2))->getZExtValue();
- LHS = CMPCC.getOperand(0);
- RHS = CMPCC.getOperand(1);
- }
-}
-
-// Returns appropriate CMP insn and corresponding condition code in PIC16CC
-SDValue PIC16TargetLowering::getPIC16Cmp(SDValue LHS, SDValue RHS,
- unsigned CC, SDValue &PIC16CC,
- SelectionDAG &DAG, DebugLoc dl) const {
- PIC16CC::CondCodes CondCode = (PIC16CC::CondCodes) CC;
-
- // PIC16 sub is literal - W. So Swap the operands and condition if needed.
- // i.e. a < 12 can be rewritten as 12 > a.
- if (RHS.getOpcode() == ISD::Constant) {
-
- SDValue Tmp = LHS;
- LHS = RHS;
- RHS = Tmp;
-
- switch (CondCode) {
- default: break;
- case PIC16CC::LT:
- CondCode = PIC16CC::GT;
- break;
- case PIC16CC::GT:
- CondCode = PIC16CC::LT;
- break;
- case PIC16CC::ULT:
- CondCode = PIC16CC::UGT;
- break;
- case PIC16CC::UGT:
- CondCode = PIC16CC::ULT;
- break;
- case PIC16CC::GE:
- CondCode = PIC16CC::LE;
- break;
- case PIC16CC::LE:
- CondCode = PIC16CC::GE;
- break;
- case PIC16CC::ULE:
- CondCode = PIC16CC::UGE;
- break;
- case PIC16CC::UGE:
- CondCode = PIC16CC::ULE;
- break;
- }
- }
-
- PIC16CC = DAG.getConstant(CondCode, MVT::i8);
-
- // These are signed comparisons.
- SDValue Mask = DAG.getConstant(128, MVT::i8);
- if (isSignedComparison(CondCode)) {
- LHS = DAG.getNode (ISD::XOR, dl, MVT::i8, LHS, Mask);
- RHS = DAG.getNode (ISD::XOR, dl, MVT::i8, RHS, Mask);
- }
-
- SDVTList VTs = DAG.getVTList (MVT::i8, MVT::Flag);
- // We can use a subtract operation to set the condition codes. But
- // we need to put one operand in memory if required.
- // Nothing to do if the first operand is already a valid type (direct load
- // for subwf and literal for sublw) and it is used by this operation only.
- if ((LHS.getOpcode() == ISD::Constant || isDirectLoad(LHS))
- && LHS.hasOneUse())
- return DAG.getNode(PIC16ISD::SUBCC, dl, VTs, LHS, RHS);
-
- // else convert the first operand to mem.
- LHS = ConvertToMemOperand (LHS, DAG, dl);
- return DAG.getNode(PIC16ISD::SUBCC, dl, VTs, LHS, RHS);
-}
-
-
-SDValue PIC16TargetLowering::LowerSELECT_CC(SDValue Op,
- SelectionDAG &DAG) const {
- SDValue LHS = Op.getOperand(0);
- SDValue RHS = Op.getOperand(1);
- ISD::CondCode CC = cast(Op.getOperand(4))->get();
- SDValue TrueVal = Op.getOperand(2);
- SDValue FalseVal = Op.getOperand(3);
- unsigned ORIGCC = ~0;
- DebugLoc dl = Op.getDebugLoc();
-
- // If this is a select_cc of a "setcc", and if the setcc got lowered into
- // an CMP[IF]CC/SELECT_[IF]CC pair, find the original compared values.
- // i.e.
- // A setcc: lhs, rhs, cc is expanded by llvm to
- // select_cc: result of setcc, 0, 1, 0, setne
- // We can think of it as:
- // select_cc: lhs, rhs, 1, 0, cc
- LookThroughSetCC(LHS, RHS, CC, ORIGCC);
- if (ORIGCC == ~0U) ORIGCC = IntCCToPIC16CC (CC);
-
- SDValue PIC16CC;
- SDValue Cmp = getPIC16Cmp(LHS, RHS, ORIGCC, PIC16CC, DAG, dl);
-
- return DAG.getNode (PIC16ISD::SELECT_ICC, dl, TrueVal.getValueType(), TrueVal,
- FalseVal, PIC16CC, Cmp.getValue(1));
-}
-
-MachineBasicBlock *
-PIC16TargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI,
- MachineBasicBlock *BB) const {
- const TargetInstrInfo &TII = *getTargetMachine().getInstrInfo();
- unsigned CC = (PIC16CC::CondCodes)MI->getOperand(3).getImm();
- DebugLoc dl = MI->getDebugLoc();
-
- // To "insert" a SELECT_CC instruction, we actually have to insert the diamond
- // control-flow pattern. The incoming instruction knows the destination vreg
- // to set, the condition code register to branch on, the true/false values to
- // select between, and a branch opcode to use.
- const BasicBlock *LLVM_BB = BB->getBasicBlock();
- MachineFunction::iterator It = BB;
- ++It;
-
- // thisMBB:
- // ...
- // TrueVal = ...
- // [f]bCC copy1MBB
- // fallthrough --> copy0MBB
- MachineBasicBlock *thisMBB = BB;
- MachineFunction *F = BB->getParent();
- MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB);
- MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB);
- BuildMI(BB, dl, TII.get(PIC16::pic16brcond)).addMBB(sinkMBB).addImm(CC);
- F->insert(It, copy0MBB);
- F->insert(It, sinkMBB);
-
- // Transfer the remainder of BB and its successor edges to sinkMBB.
- sinkMBB->splice(sinkMBB->begin(), BB,
- llvm::next(MachineBasicBlock::iterator(MI)),
- BB->end());
- sinkMBB->transferSuccessorsAndUpdatePHIs(BB);
-
- // Next, add the true and fallthrough blocks as its successors.
- BB->addSuccessor(copy0MBB);
- BB->addSuccessor(sinkMBB);
-
- // copy0MBB:
- // %FalseValue = ...
- // # fallthrough to sinkMBB
- BB = copy0MBB;
-
- // Update machine-CFG edges
- BB->addSuccessor(sinkMBB);
-
- // sinkMBB:
- // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ]
- // ...
- BB = sinkMBB;
- BuildMI(*BB, BB->begin(), dl,
- TII.get(PIC16::PHI), MI->getOperand(0).getReg())
- .addReg(MI->getOperand(2).getReg()).addMBB(copy0MBB)
- .addReg(MI->getOperand(1).getReg()).addMBB(thisMBB);
-
- MI->eraseFromParent(); // The pseudo instruction is gone now.
- return BB;
-}
-
-
-SDValue PIC16TargetLowering::LowerBR_CC(SDValue Op, SelectionDAG &DAG) const {
- SDValue Chain = Op.getOperand(0);
- ISD::CondCode CC = cast(Op.getOperand(1))->get();
- SDValue LHS = Op.getOperand(2); // LHS of the condition.
- SDValue RHS = Op.getOperand(3); // RHS of the condition.
- SDValue Dest = Op.getOperand(4); // BB to jump to
- unsigned ORIGCC = ~0;
- DebugLoc dl = Op.getDebugLoc();
-
- // If this is a br_cc of a "setcc", and if the setcc got lowered into
- // an CMP[IF]CC/SELECT_[IF]CC pair, find the original compared values.
- LookThroughSetCC(LHS, RHS, CC, ORIGCC);
- if (ORIGCC == ~0U) ORIGCC = IntCCToPIC16CC (CC);
-
- // Get the Compare insn and condition code.
- SDValue PIC16CC;
- SDValue Cmp = getPIC16Cmp(LHS, RHS, ORIGCC, PIC16CC, DAG, dl);
-
- return DAG.getNode(PIC16ISD::BRCOND, dl, MVT::Other, Chain, Dest, PIC16CC,
- Cmp.getValue(1));
-}
-
diff --git a/lib/Target/PIC16/PIC16ISelLowering.h b/lib/Target/PIC16/PIC16ISelLowering.h
deleted file mode 100644
index d942af46a9e..00000000000
--- a/lib/Target/PIC16/PIC16ISelLowering.h
+++ /dev/null
@@ -1,253 +0,0 @@
-//===-- PIC16ISelLowering.h - PIC16 DAG Lowering Interface ------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file defines the interfaces that PIC16 uses to lower LLVM code into a
-// selection DAG.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef PIC16ISELLOWERING_H
-#define PIC16ISELLOWERING_H
-
-#include "PIC16.h"
-#include "PIC16Subtarget.h"
-#include "llvm/CodeGen/SelectionDAG.h"
-#include "llvm/Target/TargetLowering.h"
-#include