Index: lib/Target/NDS32/CMakeLists.txt =================================================================== --- lib/Target/NDS32/CMakeLists.txt +++ lib/Target/NDS32/CMakeLists.txt @@ -8,6 +8,7 @@ add_llvm_target(NDS32CodeGen NDS32TargetMachine.cpp NDS32Subtarget.cpp + NDS32FrameLowering.cpp ) add_subdirectory(TargetInfo) Index: lib/Target/NDS32/NDS32FrameLowering.h =================================================================== --- /dev/null +++ lib/Target/NDS32/NDS32FrameLowering.h @@ -0,0 +1,58 @@ +//==-- NDS32FrameLowering.h - Define frame lowering for NDS32 --*- C++ -*---==// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIB_TARGET_NDS32_NDS32FRAMELOWERING_H +#define LLVM_LIB_TARGET_NDS32_NDS32FRAMELOWERING_H + +#include "NDS32.h" +#include "llvm/Target/TargetFrameLowering.h" + +namespace llvm { +class NDS32FrameLowering : public TargetFrameLowering { +protected: + +public: + // Frame growing down and always 8-byte alignment for NDS32 target. + // Local area offset is 0 for NDS32. + explicit NDS32FrameLowering() + : TargetFrameLowering(TargetFrameLowering::StackGrowsDown, 8, 0, 8) {} + /// emitProlog/emitEpilog - These methods insert prolog and epilog code into + /// the function. + void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override; + void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override; + + MachineBasicBlock::iterator + eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB, + MachineBasicBlock::iterator I) const override; + + bool spillCalleeSavedRegisters(MachineBasicBlock &MBB, + MachineBasicBlock::iterator MI, + const std::vector &CSI, + const TargetRegisterInfo *TRI) const override; + bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB, + MachineBasicBlock::iterator MI, + const std::vector &CSI, + const TargetRegisterInfo *TRI) const override; + + int getFrameIndexReference(const MachineFunction &MF, int FI, + unsigned &FrameReg) const override; + + bool hasFP(const MachineFunction &MF) const override; + bool hasReservedCallFrame(const MachineFunction &MF) const override; + void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, + RegScavenger *RS) const override; +}; + +} // End llvm namespace + +#endif Index: lib/Target/NDS32/NDS32FrameLowering.cpp =================================================================== --- /dev/null +++ lib/Target/NDS32/NDS32FrameLowering.cpp @@ -0,0 +1,79 @@ +//===-- NDS32FrameLowering.cpp - NDS32 Frame 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 NDS32 implementation of TargetFrameLowering class. +// +//===----------------------------------------------------------------------===// + +#include "NDS32FrameLowering.h" +#include "NDS32Subtarget.h" +#include "llvm/CodeGen/MachineFrameInfo.h" +#include "llvm/CodeGen/MachineFunction.h" +#include "llvm/CodeGen/MachineInstrBuilder.h" +#include "llvm/CodeGen/MachineModuleInfo.h" +#include "llvm/CodeGen/MachineRegisterInfo.h" +#include "llvm/IR/DataLayout.h" +#include "llvm/IR/Function.h" +#include "llvm/Target/TargetOptions.h" + +using namespace llvm; + +bool NDS32FrameLowering::hasFP(const MachineFunction &MF) const { + const MachineFrameInfo &MFI = MF.getFrameInfo(); + + return (MF.getTarget().Options.DisableFramePointerElim(MF) || + MF.getFrameInfo().hasVarSizedObjects() || + MFI.isFrameAddressTaken()); +} + +bool NDS32FrameLowering::hasReservedCallFrame(const MachineFunction &MF) const { + return !MF.getFrameInfo().hasVarSizedObjects(); +} + +void NDS32FrameLowering::emitPrologue(MachineFunction &MF, + MachineBasicBlock &MBB) const { +} + + +void NDS32FrameLowering::emitEpilogue(MachineFunction &MF, + MachineBasicBlock &MBB) const { +} + +bool NDS32FrameLowering:: +spillCalleeSavedRegisters(MachineBasicBlock &MBB, + MachineBasicBlock::iterator MI, + const std::vector &CSI, + const TargetRegisterInfo *TRI) const { + return false; +} + +bool NDS32FrameLowering:: +restoreCalleeSavedRegisters(MachineBasicBlock &MBB, + MachineBasicBlock::iterator MI, + const std::vector &CSI, + const TargetRegisterInfo *TRI) const { + return false; +} + +int NDS32FrameLowering::getFrameIndexReference(const MachineFunction &MF, + int FI, + unsigned &FrameReg) const { + return 0; +} + +MachineBasicBlock::iterator NDS32FrameLowering:: +eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB, + MachineBasicBlock::iterator MI) const { + return MBB.erase(MI); +} + +void NDS32FrameLowering::determineCalleeSaves(MachineFunction &MF, + BitVector &SavedRegs, + RegScavenger *RS) const { +} Index: lib/Target/NDS32/NDS32Subtarget.h =================================================================== --- lib/Target/NDS32/NDS32Subtarget.h +++ lib/Target/NDS32/NDS32Subtarget.h @@ -14,6 +14,7 @@ #ifndef LLVM_LIB_TARGET_NDS32_NDS32SUBTARGET_H #define LLVM_LIB_TARGET_NDS32_NDS32SUBTARGET_H +#include "NDS32FrameLowering.h" #include "llvm/IR/DataLayout.h" #include "llvm/Target/TargetSubtargetInfo.h" #include @@ -26,6 +27,7 @@ class NDS32Subtarget : public NDS32GenSubtargetInfo { virtual void anchor(); + NDS32FrameLowering FrameLowering; public: /// This constructor initializes the data members to match that @@ -40,6 +42,9 @@ /// subtarget options. Definition of function is auto generated by tblgen. void ParseSubtargetFeatures(StringRef CPU, StringRef FS); + const TargetFrameLowering *getFrameLowering() const override { + return &FrameLowering; + } protected: /// No16Bit - Not generate 16-Bit ISA bool No16Bit = false; Index: lib/Target/NDS32/NDS32Subtarget.cpp =================================================================== --- lib/Target/NDS32/NDS32Subtarget.cpp +++ lib/Target/NDS32/NDS32Subtarget.cpp @@ -33,6 +33,6 @@ NDS32Subtarget::NDS32Subtarget(const Triple &TT, const std::string &CPU, const std::string &FS, const TargetMachine &TM) - : NDS32GenSubtargetInfo(TT, CPU, FS) { + : NDS32GenSubtargetInfo(TT, CPU, FS), FrameLowering() { ParseSubtargetFeatures(CPU, FS); }