| Alex Bradbury | 8971842 | 2017-10-19 21:37:38 +0000 | [diff] [blame] | 1 | //===-- RISCVFrameLowering.cpp - RISCV Frame Information ------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file contains the RISCV implementation of TargetFrameLowering class. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "RISCVFrameLowering.h" |
| 15 | #include "RISCVSubtarget.h" |
| 16 | #include "llvm/CodeGen/MachineFrameInfo.h" |
| 17 | #include "llvm/CodeGen/MachineFunction.h" |
| 18 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
| 19 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
| 20 | |
| 21 | using namespace llvm; |
| 22 | |
| 23 | bool RISCVFrameLowering::hasFP(const MachineFunction &MF) const { return true; } |
| 24 | |
| 25 | void RISCVFrameLowering::emitPrologue(MachineFunction &MF, |
| 26 | MachineBasicBlock &MBB) const {} |
| 27 | |
| 28 | void RISCVFrameLowering::emitEpilogue(MachineFunction &MF, |
| 29 | MachineBasicBlock &MBB) const {} |
| Alex Bradbury | 660bcce | 2017-12-11 11:53:54 +0000 | [diff] [blame] | 30 | |
| 31 | int RISCVFrameLowering::getFrameIndexReference(const MachineFunction &MF, |
| 32 | int FI, |
| 33 | unsigned &FrameReg) const { |
| 34 | const MachineFrameInfo &MFI = MF.getFrameInfo(); |
| 35 | const TargetRegisterInfo *RI = MF.getSubtarget().getRegisterInfo(); |
| 36 | |
| 37 | // Callee-saved registers should be referenced relative to the stack |
| 38 | // pointer (positive offset), otherwise use the frame pointer (negative |
| 39 | // offset). |
| 40 | const std::vector<CalleeSavedInfo> &CSI = MFI.getCalleeSavedInfo(); |
| 41 | int MinCSFI = 0; |
| 42 | int MaxCSFI = -1; |
| 43 | |
| 44 | int Offset = MFI.getObjectOffset(FI) - getOffsetOfLocalArea() + |
| 45 | MFI.getOffsetAdjustment(); |
| 46 | |
| 47 | if (CSI.size()) { |
| 48 | MinCSFI = CSI[0].getFrameIdx(); |
| 49 | MaxCSFI = CSI[CSI.size() - 1].getFrameIdx(); |
| 50 | } |
| 51 | |
| 52 | FrameReg = RI->getFrameRegister(MF); |
| 53 | if (FI >= MinCSFI && FI <= MaxCSFI) { |
| 54 | FrameReg = RISCV::X2; |
| 55 | Offset += MF.getFrameInfo().getStackSize(); |
| 56 | } |
| 57 | return Offset; |
| 58 | } |