1*349cc55cSDimitry Andric //===-- CSKYRegisterInfo.h - CSKY Register Information Impl ---*- C++ -*---===// 2*349cc55cSDimitry Andric // 3*349cc55cSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*349cc55cSDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5*349cc55cSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*349cc55cSDimitry Andric // 7*349cc55cSDimitry Andric //===----------------------------------------------------------------------===// 8*349cc55cSDimitry Andric // 9*349cc55cSDimitry Andric // This file contains the CSKY implementation of the TargetRegisterInfo class. 10*349cc55cSDimitry Andric // 11*349cc55cSDimitry Andric //===----------------------------------------------------------------------===// 12*349cc55cSDimitry Andric 13*349cc55cSDimitry Andric #include "CSKYRegisterInfo.h" 14*349cc55cSDimitry Andric #include "CSKY.h" 15*349cc55cSDimitry Andric #include "CSKYSubtarget.h" 16*349cc55cSDimitry Andric #include "llvm/CodeGen/MachineFunction.h" 17*349cc55cSDimitry Andric #include "llvm/CodeGen/RegisterScavenging.h" 18*349cc55cSDimitry Andric #include "llvm/MC/MCContext.h" 19*349cc55cSDimitry Andric 20*349cc55cSDimitry Andric #define GET_REGINFO_TARGET_DESC 21*349cc55cSDimitry Andric #include "CSKYGenRegisterInfo.inc" 22*349cc55cSDimitry Andric 23*349cc55cSDimitry Andric using namespace llvm; 24*349cc55cSDimitry Andric 25*349cc55cSDimitry Andric CSKYRegisterInfo::CSKYRegisterInfo() 26*349cc55cSDimitry Andric : CSKYGenRegisterInfo(CSKY::R15, 0, 0, 0) {} 27*349cc55cSDimitry Andric 28*349cc55cSDimitry Andric const uint32_t * 29*349cc55cSDimitry Andric CSKYRegisterInfo::getCallPreservedMask(const MachineFunction &MF, 30*349cc55cSDimitry Andric CallingConv::ID Id) const { 31*349cc55cSDimitry Andric const CSKYSubtarget &STI = MF.getSubtarget<CSKYSubtarget>(); 32*349cc55cSDimitry Andric return CSR_I32_RegMask; 33*349cc55cSDimitry Andric } 34*349cc55cSDimitry Andric 35*349cc55cSDimitry Andric Register CSKYRegisterInfo::getFrameRegister(const MachineFunction &MF) const { 36*349cc55cSDimitry Andric const TargetFrameLowering *TFI = getFrameLowering(MF); 37*349cc55cSDimitry Andric return TFI->hasFP(MF) ? CSKY::R8 : CSKY::R14; 38*349cc55cSDimitry Andric } 39*349cc55cSDimitry Andric 40*349cc55cSDimitry Andric BitVector CSKYRegisterInfo::getReservedRegs(const MachineFunction &MF) const { 41*349cc55cSDimitry Andric const CSKYFrameLowering *TFI = getFrameLowering(MF); 42*349cc55cSDimitry Andric const CSKYSubtarget &STI = MF.getSubtarget<CSKYSubtarget>(); 43*349cc55cSDimitry Andric BitVector Reserved(getNumRegs()); 44*349cc55cSDimitry Andric 45*349cc55cSDimitry Andric // Reserve the base register if we need to allocate 46*349cc55cSDimitry Andric // variable-sized objects at runtime. 47*349cc55cSDimitry Andric if (TFI->hasBP(MF)) 48*349cc55cSDimitry Andric markSuperRegs(Reserved, CSKY::R7); // bp 49*349cc55cSDimitry Andric 50*349cc55cSDimitry Andric if (TFI->hasFP(MF)) 51*349cc55cSDimitry Andric markSuperRegs(Reserved, CSKY::R8); // fp 52*349cc55cSDimitry Andric 53*349cc55cSDimitry Andric if (!STI.hasE2()) { 54*349cc55cSDimitry Andric for (unsigned i = 0; i < 6; i++) 55*349cc55cSDimitry Andric markSuperRegs(Reserved, CSKY::R8 + i); // R8 - R13 56*349cc55cSDimitry Andric } 57*349cc55cSDimitry Andric 58*349cc55cSDimitry Andric markSuperRegs(Reserved, CSKY::R14); // sp 59*349cc55cSDimitry Andric markSuperRegs(Reserved, CSKY::R15); // lr 60*349cc55cSDimitry Andric 61*349cc55cSDimitry Andric if (!STI.hasHighRegisters()) { 62*349cc55cSDimitry Andric for (unsigned i = 0; i < 10; i++) 63*349cc55cSDimitry Andric markSuperRegs(Reserved, CSKY::R16 + i); // R16 - R25 64*349cc55cSDimitry Andric } 65*349cc55cSDimitry Andric 66*349cc55cSDimitry Andric markSuperRegs(Reserved, CSKY::R26); 67*349cc55cSDimitry Andric markSuperRegs(Reserved, CSKY::R27); 68*349cc55cSDimitry Andric markSuperRegs(Reserved, CSKY::R28); // gp 69*349cc55cSDimitry Andric markSuperRegs(Reserved, CSKY::R29); 70*349cc55cSDimitry Andric markSuperRegs(Reserved, CSKY::R30); 71*349cc55cSDimitry Andric markSuperRegs(Reserved, CSKY::R31); // tp 72*349cc55cSDimitry Andric 73*349cc55cSDimitry Andric assert(checkAllSuperRegsMarked(Reserved)); 74*349cc55cSDimitry Andric return Reserved; 75*349cc55cSDimitry Andric } 76*349cc55cSDimitry Andric 77*349cc55cSDimitry Andric const uint32_t *CSKYRegisterInfo::getNoPreservedMask() const { 78*349cc55cSDimitry Andric return CSR_NoRegs_RegMask; 79*349cc55cSDimitry Andric } 80*349cc55cSDimitry Andric 81*349cc55cSDimitry Andric const MCPhysReg * 82*349cc55cSDimitry Andric CSKYRegisterInfo::getCalleeSavedRegs(const MachineFunction *MF) const { 83*349cc55cSDimitry Andric const CSKYSubtarget &STI = MF->getSubtarget<CSKYSubtarget>(); 84*349cc55cSDimitry Andric if (MF->getFunction().hasFnAttribute("interrupt")) { 85*349cc55cSDimitry Andric return CSR_GPR_ISR_SaveList; 86*349cc55cSDimitry Andric } 87*349cc55cSDimitry Andric 88*349cc55cSDimitry Andric return CSR_I32_SaveList; 89*349cc55cSDimitry Andric } 90*349cc55cSDimitry Andric 91*349cc55cSDimitry Andric void CSKYRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II, 92*349cc55cSDimitry Andric int SPAdj, unsigned FIOperandNum, 93*349cc55cSDimitry Andric RegScavenger *RS) const { 94*349cc55cSDimitry Andric assert(SPAdj == 0 && "Unexpected non-zero SPAdj value"); 95*349cc55cSDimitry Andric }