1 //===-- CSKYFrameLowering.cpp - CSKY Frame Information ------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file contains the CSKY implementation of TargetFrameLowering class. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #include "CSKYFrameLowering.h" 14 #include "CSKYSubtarget.h" 15 #include "llvm/CodeGen/MachineFrameInfo.h" 16 #include "llvm/CodeGen/MachineFunction.h" 17 #include "llvm/CodeGen/MachineInstrBuilder.h" 18 #include "llvm/CodeGen/MachineRegisterInfo.h" 19 #include "llvm/CodeGen/RegisterScavenging.h" 20 #include "llvm/IR/DiagnosticInfo.h" 21 #include "llvm/MC/MCDwarf.h" 22 23 using namespace llvm; 24 25 #define DEBUG_TYPE "csky-frame-lowering" 26 27 // Returns the register used to hold the frame pointer. 28 static Register getFPReg(const CSKYSubtarget &STI) { return CSKY::R8; } 29 30 // To avoid the BP value clobbered by a function call, we need to choose a 31 // callee saved register to save the value. 32 static Register getBPReg(const CSKYSubtarget &STI) { return CSKY::R7; } 33 34 bool CSKYFrameLowering::hasFP(const MachineFunction &MF) const { 35 const TargetRegisterInfo *RegInfo = MF.getSubtarget().getRegisterInfo(); 36 37 const MachineFrameInfo &MFI = MF.getFrameInfo(); 38 return MF.getTarget().Options.DisableFramePointerElim(MF) || 39 RegInfo->hasStackRealignment(MF) || MFI.hasVarSizedObjects() || 40 MFI.isFrameAddressTaken(); 41 } 42 43 bool CSKYFrameLowering::hasBP(const MachineFunction &MF) const { 44 const MachineFrameInfo &MFI = MF.getFrameInfo(); 45 46 return MFI.hasVarSizedObjects(); 47 } 48 49 void CSKYFrameLowering::emitPrologue(MachineFunction &MF, 50 MachineBasicBlock &MBB) const { 51 // FIXME: Implement this when we have function calls 52 } 53 54 void CSKYFrameLowering::emitEpilogue(MachineFunction &MF, 55 MachineBasicBlock &MBB) const { 56 // FIXME: Implement this when we have function calls 57 }