From 26846cab4150ec5b460fee2a3b51c9beeaf42054 Mon Sep 17 00:00:00 2001 From: Jeremy Rand Date: Fri, 17 Jul 2015 23:57:48 -0500 Subject: [PATCH] I have no idea why I thought I did't need a subtarget. I do need one so I have added it. --- lib/Target/WDC65816/CMakeLists.txt | 1 + lib/Target/WDC65816/WDC65816AsmPrinter.cpp | 1 + lib/Target/WDC65816/WDC65816FrameLowering.h | 8 ++- lib/Target/WDC65816/WDC65816ISelDAGToDAG.cpp | 3 +- lib/Target/WDC65816/WDC65816ISelLowering.h | 2 + lib/Target/WDC65816/WDC65816InstrInfo.cpp | 5 +- lib/Target/WDC65816/WDC65816InstrInfo.h | 3 +- lib/Target/WDC65816/WDC65816RegisterInfo.cpp | 6 +- lib/Target/WDC65816/WDC65816RegisterInfo.h | 4 +- lib/Target/WDC65816/WDC65816Subtarget.cpp | 64 +++++++++++++++++++ lib/Target/WDC65816/WDC65816Subtarget.h | 60 +++++++++++++++++ lib/Target/WDC65816/WDC65816TargetMachine.cpp | 9 +-- lib/Target/WDC65816/WDC65816TargetMachine.h | 4 +- 13 files changed, 156 insertions(+), 14 deletions(-) create mode 100644 lib/Target/WDC65816/WDC65816Subtarget.cpp create mode 100644 lib/Target/WDC65816/WDC65816Subtarget.h diff --git a/lib/Target/WDC65816/CMakeLists.txt b/lib/Target/WDC65816/CMakeLists.txt index b3db38ee..03991f7c 100644 --- a/lib/Target/WDC65816/CMakeLists.txt +++ b/lib/Target/WDC65816/CMakeLists.txt @@ -16,6 +16,7 @@ add_llvm_target(WDC65816CodeGen WDC65816FrameLowering.cpp WDC65816MachineFunctionInfo.cpp WDC65816RegisterInfo.cpp + WDC65816Subtarget.cpp WDC65816TargetMachine.cpp WDC65816SelectionDAGInfo.cpp ) diff --git a/lib/Target/WDC65816/WDC65816AsmPrinter.cpp b/lib/Target/WDC65816/WDC65816AsmPrinter.cpp index 2c1974e1..331219db 100644 --- a/lib/Target/WDC65816/WDC65816AsmPrinter.cpp +++ b/lib/Target/WDC65816/WDC65816AsmPrinter.cpp @@ -99,6 +99,7 @@ void WDC65816AsmPrinter::printMemOperand(const MachineInstr *MI, int opNum, bool WDC65816AsmPrinter::printGetPCX(const MachineInstr *MI, unsigned opNum, raw_ostream &O) { // WDC_TODO - print whatever this is here... + return true; } #if 0 // WDC_TODO - How much of this do we need? diff --git a/lib/Target/WDC65816/WDC65816FrameLowering.h b/lib/Target/WDC65816/WDC65816FrameLowering.h index 562aed9f..7173a704 100644 --- a/lib/Target/WDC65816/WDC65816FrameLowering.h +++ b/lib/Target/WDC65816/WDC65816FrameLowering.h @@ -15,14 +15,18 @@ #define WDC65816_FRAMEINFO_H #include "WDC65816.h" +#include "WDC65816Subtarget.h" #include "llvm/Target/TargetFrameLowering.h" namespace llvm { + class WDC65816Subtarget; class WDC65816FrameLowering : public TargetFrameLowering { + const WDC65816Subtarget &SubTarget; public: - explicit WDC65816FrameLowering(void) - : TargetFrameLowering(TargetFrameLowering::StackGrowsDown, 1, 0) {} + explicit WDC65816FrameLowering(const WDC65816Subtarget &ST) + : TargetFrameLowering(TargetFrameLowering::StackGrowsDown, 1, 0), + SubTarget(ST) {} bool hasFP(const MachineFunction &MF) const; diff --git a/lib/Target/WDC65816/WDC65816ISelDAGToDAG.cpp b/lib/Target/WDC65816/WDC65816ISelDAGToDAG.cpp index 8ed61cf0..efee9c50 100644 --- a/lib/Target/WDC65816/WDC65816ISelDAGToDAG.cpp +++ b/lib/Target/WDC65816/WDC65816ISelDAGToDAG.cpp @@ -30,10 +30,11 @@ using namespace llvm; /// namespace { class WDC65816DAGToDAGISel : public SelectionDAGISel { + const WDC65816Subtarget &Subtarget; WDC65816TargetMachine &TM; public: explicit WDC65816DAGToDAGISel(WDC65816TargetMachine &tm) - : SelectionDAGISel(tm), + : SelectionDAGISel(tm), Subtarget(tm.getSubtarget()), TM(tm) { } diff --git a/lib/Target/WDC65816/WDC65816ISelLowering.h b/lib/Target/WDC65816/WDC65816ISelLowering.h index d454e13d..1fc252f6 100644 --- a/lib/Target/WDC65816/WDC65816ISelLowering.h +++ b/lib/Target/WDC65816/WDC65816ISelLowering.h @@ -19,6 +19,7 @@ #include "llvm/Target/TargetLowering.h" namespace llvm { + class WDC65816Subtarget; #if 0 // WDC_TODO - Do I need any of this? namespace SPISD { enum { @@ -52,6 +53,7 @@ namespace llvm { #endif class WDC65816TargetLowering : public TargetLowering { + const WDC65816Subtarget *Subtarget; public: WDC65816TargetLowering(TargetMachine &TM); diff --git a/lib/Target/WDC65816/WDC65816InstrInfo.cpp b/lib/Target/WDC65816/WDC65816InstrInfo.cpp index d3227fb6..0dc22edc 100644 --- a/lib/Target/WDC65816/WDC65816InstrInfo.cpp +++ b/lib/Target/WDC65816/WDC65816InstrInfo.cpp @@ -14,6 +14,7 @@ #include "WDC65816InstrInfo.h" #include "WDC65816.h" #include "WDC65816MachineFunctionInfo.h" +#include "WDC65816Subtarget.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallVector.h" #include "llvm/CodeGen/MachineFrameInfo.h" @@ -32,9 +33,9 @@ using namespace llvm; // Pin the vtable to this file. void WDC65816InstrInfo::anchor() {} -WDC65816InstrInfo::WDC65816InstrInfo(void) +WDC65816InstrInfo::WDC65816InstrInfo(WDC65816Subtarget &ST) : WDC65816GenInstrInfo(WDC::ADJCALLSTACKDOWN, WDC::ADJCALLSTACKUP), -RI() { +RI(ST), Subtarget(ST) { } diff --git a/lib/Target/WDC65816/WDC65816InstrInfo.h b/lib/Target/WDC65816/WDC65816InstrInfo.h index ad614137..e97e804f 100644 --- a/lib/Target/WDC65816/WDC65816InstrInfo.h +++ b/lib/Target/WDC65816/WDC65816InstrInfo.h @@ -24,9 +24,10 @@ namespace llvm { class WDC65816InstrInfo : public WDC65816GenInstrInfo { const WDC65816RegisterInfo RI; + const WDC65816Subtarget& Subtarget; virtual void anchor(); public: - explicit WDC65816InstrInfo(void); + explicit WDC65816InstrInfo(WDC65816Subtarget &ST); /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As /// such, whenever a client has an instance of instruction info, it should diff --git a/lib/Target/WDC65816/WDC65816RegisterInfo.cpp b/lib/Target/WDC65816/WDC65816RegisterInfo.cpp index 4f7b3009..8352a8b5 100644 --- a/lib/Target/WDC65816/WDC65816RegisterInfo.cpp +++ b/lib/Target/WDC65816/WDC65816RegisterInfo.cpp @@ -13,6 +13,8 @@ #include "WDC65816RegisterInfo.h" #include "WDC65816.h" +#include "WDC65816MachineFunctionInfo.h" +#include "WDC65816Subtarget.h" #include "llvm/ADT/BitVector.h" #include "llvm/ADT/STLExtras.h" #include "llvm/CodeGen/MachineFrameInfo.h" @@ -34,8 +36,8 @@ ReserveAppRegisters("sparc-reserve-app-registers", cl::Hidden, cl::init(false), cl::desc("Reserve application registers (%g2-%g4)")); #endif -WDC65816RegisterInfo::WDC65816RegisterInfo(void) -: WDC65816GenRegisterInfo(WDC::P) { +WDC65816RegisterInfo::WDC65816RegisterInfo(WDC65816Subtarget &st) +: WDC65816GenRegisterInfo(WDC::P), Subtarget(st) { } const uint16_t* WDC65816RegisterInfo::getCalleeSavedRegs(const MachineFunction *MF) diff --git a/lib/Target/WDC65816/WDC65816RegisterInfo.h b/lib/Target/WDC65816/WDC65816RegisterInfo.h index 81d927a0..f9239382 100644 --- a/lib/Target/WDC65816/WDC65816RegisterInfo.h +++ b/lib/Target/WDC65816/WDC65816RegisterInfo.h @@ -21,12 +21,14 @@ namespace llvm { + class WDC65816Subtarget; class TargetInstrInfo; class Type; struct WDC65816RegisterInfo : public WDC65816GenRegisterInfo { + WDC65816Subtarget &Subtarget; - WDC65816RegisterInfo(void); + WDC65816RegisterInfo(WDC65816Subtarget &st); /// Code Generation virtual methods... const uint16_t *getCalleeSavedRegs(const MachineFunction *MF = 0) const; diff --git a/lib/Target/WDC65816/WDC65816Subtarget.cpp b/lib/Target/WDC65816/WDC65816Subtarget.cpp new file mode 100644 index 00000000..5e8af1a1 --- /dev/null +++ b/lib/Target/WDC65816/WDC65816Subtarget.cpp @@ -0,0 +1,64 @@ +//===-- WDC65816Subtarget.cpp - WDC65816 Subtarget Information ------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file implements the WDC65816 specific subclass of TargetSubtargetInfo. +// +//===----------------------------------------------------------------------===// + +#include "WDC65816Subtarget.h" +#include "WDC65816.h" +#include "llvm/Support/MathExtras.h" +#include "llvm/Support/TargetRegistry.h" + +#define GET_SUBTARGETINFO_TARGET_DESC +#define GET_SUBTARGETINFO_CTOR +#include "WDC65816GenSubtargetInfo.inc" + +using namespace llvm; + +void WDC65816Subtarget::anchor() { } + +WDC65816Subtarget::WDC65816Subtarget(const std::string &TT, const std::string &CPU, + const std::string &FS) : +WDC65816GenSubtargetInfo(TT, CPU, FS) { + + // Determine default and user specified characteristics + std::string CPUName = CPU; + + // Parse features string. + ParseSubtargetFeatures(CPUName, FS); +} + +#if 0 // WDC_TODO - Do I need this? +int SparcSubtarget::getAdjustedFrameSize(int frameSize) const { + + if (is64Bit()) { + // All 64-bit stack frames must be 16-byte aligned, and must reserve space + // for spilling the 16 window registers at %sp+BIAS..%sp+BIAS+128. + frameSize += 128; + // Frames with calls must also reserve space for 6 outgoing arguments + // whether they are used or not. LowerCall_64 takes care of that. + assert(frameSize % 16 == 0 && "Stack size not 16-byte aligned"); + } else { + // Emit the correct save instruction based on the number of bytes in + // the frame. Minimum stack frame size according to V8 ABI is: + // 16 words for register window spill + // 1 word for address of returned aggregate-value + // + 6 words for passing parameters on the stack + // ---------- + // 23 words * 4 bytes per word = 92 bytes + frameSize += 92; + + // Round up to next doubleword boundary -- a double-word boundary + // is required by the ABI. + frameSize = RoundUpToAlignment(frameSize, 8); + } + return frameSize; +} +#endif diff --git a/lib/Target/WDC65816/WDC65816Subtarget.h b/lib/Target/WDC65816/WDC65816Subtarget.h new file mode 100644 index 00000000..fde227b4 --- /dev/null +++ b/lib/Target/WDC65816/WDC65816Subtarget.h @@ -0,0 +1,60 @@ +//===-- WDC65816Subtarget.h - Define Subtarget for the WDC65816 -*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file declares the WDC65816 specific subclass of TargetSubtargetInfo. +// +//===----------------------------------------------------------------------===// + +#ifndef WDC65816_SUBTARGET_H +#define WDC65816_SUBTARGET_H + +#include "llvm/Target/TargetSubtargetInfo.h" +#include + +#define GET_SUBTARGETINFO_HEADER +#include "WDC65816GenSubtargetInfo.inc" + +namespace llvm { + class StringRef; + + class WDC65816Subtarget : public WDC65816GenSubtargetInfo { + virtual void anchor(); + + public: + WDC65816Subtarget(const std::string &TT, const std::string &CPU, + const std::string &FS); + + + /// ParseSubtargetFeatures - Parses features string setting specified + /// subtarget options. Definition of function is auto generated by tblgen. + void ParseSubtargetFeatures(StringRef CPU, StringRef FS); + + bool is64Bit() const { return false; } + std::string getDataLayout() const { + return std::string("e-p:32:8:8-i16:8:8-f32:8:8-f68:8:8-n16"); + } + +#if 0 // WDC_TODO - do I need any of this? + /// The 64-bit ABI uses biased stack and frame pointers, so the stack frame + /// of the current function is the area from [%sp+BIAS] to [%fp+BIAS]. + int64_t getStackPointerBias() const { + return is64Bit() ? 2047 : 0; + } + + /// Given a actual stack size as determined by FrameInfo, this function + /// returns adjusted framesize which includes space for register window + /// spills and arguments. + int getAdjustedFrameSize(int stackSize) const; +#endif + + }; + +} // end namespace llvm + +#endif diff --git a/lib/Target/WDC65816/WDC65816TargetMachine.cpp b/lib/Target/WDC65816/WDC65816TargetMachine.cpp index 1443b224..56508293 100644 --- a/lib/Target/WDC65816/WDC65816TargetMachine.cpp +++ b/lib/Target/WDC65816/WDC65816TargetMachine.cpp @@ -31,10 +31,11 @@ WDC65816TargetMachine::WDC65816TargetMachine(const Target &T, StringRef TT, Reloc::Model RM, CodeModel::Model CM, CodeGenOpt::Level OL) : LLVMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL), -DL("e-p:32:8:8-i16:8:8-f32:8:8-f68:8:8-n16"), -InstrInfo(), +Subtarget(TT, CPU, FS), +DL(Subtarget.getDataLayout()), +InstrInfo(Subtarget), TLInfo(*this), TSInfo(*this), -FrameLowering() { +FrameLowering(Subtarget) { initAsmInfo(); } @@ -67,5 +68,5 @@ bool WDC65816PassConfig::addInstSelector() { /// passes immediately before machine code is emitted. This should return /// true if -print-machineinstrs should print out the code after the passes. bool WDC65816PassConfig::addPreEmitPass(){ - return true; + return false; } diff --git a/lib/Target/WDC65816/WDC65816TargetMachine.h b/lib/Target/WDC65816/WDC65816TargetMachine.h index 8390b362..fb6aa3d1 100644 --- a/lib/Target/WDC65816/WDC65816TargetMachine.h +++ b/lib/Target/WDC65816/WDC65816TargetMachine.h @@ -18,6 +18,7 @@ #include "WDC65816ISelLowering.h" #include "WDC65816InstrInfo.h" #include "WDC65816SelectionDAGInfo.h" +#include "WDC65816Subtarget.h" #include "llvm/IR/DataLayout.h" #include "llvm/Target/TargetFrameLowering.h" #include "llvm/Target/TargetMachine.h" @@ -25,7 +26,7 @@ namespace llvm { class WDC65816TargetMachine : public LLVMTargetMachine { - // SparcSubtarget Subtarget; WDC_TODO - Do I need this? + WDC65816Subtarget Subtarget; const DataLayout DL; // Calculates type size & alignment WDC65816InstrInfo InstrInfo; WDC65816TargetLowering TLInfo; @@ -41,6 +42,7 @@ namespace llvm { virtual const TargetFrameLowering *getFrameLowering() const { return &FrameLowering; } + virtual const WDC65816Subtarget *getSubtargetImpl() const{ return &Subtarget; } virtual const WDC65816RegisterInfo *getRegisterInfo() const { return &InstrInfo.getRegisterInfo(); }