LLVM  8.0.1
RISCVRegisterInfo.cpp
Go to the documentation of this file.
1 //===-- RISCVRegisterInfo.cpp - RISCV Register Information ------*- C++ -*-===//
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 the TargetRegisterInfo class.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "RISCVRegisterInfo.h"
15 #include "RISCV.h"
16 #include "RISCVSubtarget.h"
24 
25 #define GET_REGINFO_TARGET_DESC
26 #include "RISCVGenRegisterInfo.inc"
27 
28 using namespace llvm;
29 
31  : RISCVGenRegisterInfo(RISCV::X1, /*DwarfFlavour*/0, /*EHFlavor*/0,
32  /*PC*/0, HwMode) {}
33 
34 const MCPhysReg *
36  if (MF->getFunction().hasFnAttribute("interrupt")) {
38  return CSR_XLEN_F64_Interrupt_SaveList;
40  return CSR_XLEN_F32_Interrupt_SaveList;
41  return CSR_Interrupt_SaveList;
42  }
43  return CSR_SaveList;
44 }
45 
47  BitVector Reserved(getNumRegs());
48 
49  // Use markSuperRegs to ensure any register aliases are also reserved
50  markSuperRegs(Reserved, RISCV::X0); // zero
51  markSuperRegs(Reserved, RISCV::X1); // ra
52  markSuperRegs(Reserved, RISCV::X2); // sp
53  markSuperRegs(Reserved, RISCV::X3); // gp
54  markSuperRegs(Reserved, RISCV::X4); // tp
55  markSuperRegs(Reserved, RISCV::X8); // fp
56  assert(checkAllSuperRegsMarked(Reserved));
57  return Reserved;
58 }
59 
60 bool RISCVRegisterInfo::isConstantPhysReg(unsigned PhysReg) const {
61  return PhysReg == RISCV::X0;
62 }
63 
65  return CSR_NoRegs_RegMask;
66 }
67 
69  int SPAdj, unsigned FIOperandNum,
70  RegScavenger *RS) const {
71  assert(SPAdj == 0 && "Unexpected non-zero SPAdj value");
72 
73  MachineInstr &MI = *II;
74  MachineFunction &MF = *MI.getParent()->getParent();
76  const RISCVInstrInfo *TII = MF.getSubtarget<RISCVSubtarget>().getInstrInfo();
77  DebugLoc DL = MI.getDebugLoc();
78 
79  int FrameIndex = MI.getOperand(FIOperandNum).getIndex();
80  unsigned FrameReg;
81  int Offset =
82  getFrameLowering(MF)->getFrameIndexReference(MF, FrameIndex, FrameReg) +
83  MI.getOperand(FIOperandNum + 1).getImm();
84 
85  if (!isInt<32>(Offset)) {
87  "Frame offsets outside of the signed 32-bit range not supported");
88  }
89 
90  MachineBasicBlock &MBB = *MI.getParent();
91  bool FrameRegIsKill = false;
92 
93  if (!isInt<12>(Offset)) {
94  assert(isInt<32>(Offset) && "Int32 expected");
95  // The offset won't fit in an immediate, so use a scratch register instead
96  // Modify Offset and FrameReg appropriately
97  unsigned ScratchReg = MRI.createVirtualRegister(&RISCV::GPRRegClass);
98  TII->movImm32(MBB, II, DL, ScratchReg, Offset);
99  BuildMI(MBB, II, DL, TII->get(RISCV::ADD), ScratchReg)
100  .addReg(FrameReg)
101  .addReg(ScratchReg, RegState::Kill);
102  Offset = 0;
103  FrameReg = ScratchReg;
104  FrameRegIsKill = true;
105  }
106 
107  MI.getOperand(FIOperandNum)
108  .ChangeToRegister(FrameReg, false, false, FrameRegIsKill);
109  MI.getOperand(FIOperandNum + 1).ChangeToImmediate(Offset);
110 }
111 
113  const TargetFrameLowering *TFI = getFrameLowering(MF);
114  return TFI->hasFP(MF) ? RISCV::X8 : RISCV::X2;
115 }
116 
117 const uint32_t *
119  CallingConv::ID /*CC*/) const {
120  if (MF.getFunction().hasFnAttribute("interrupt")) {
122  return CSR_XLEN_F64_Interrupt_RegMask;
124  return CSR_XLEN_F32_Interrupt_RegMask;
125  return CSR_Interrupt_RegMask;
126  }
127  return CSR_RegMask;
128 }
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:140
This class represents lattice values for constants.
Definition: AllocatorList.h:24
void ChangeToRegister(unsigned Reg, bool isDef, bool isImp=false, bool isKill=false, bool isDead=false, bool isUndef=false, bool isDebug=false)
ChangeToRegister - Replace this operand with a new register operand of the specified value...
const uint32_t * getNoPreservedMask() const override
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
Definition: MachineInstr.h:383
BitVector getReservedRegs(const MachineFunction &MF) const override
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition: Function.h:321
A debug info location.
Definition: DebugLoc.h:34
bool isConstantPhysReg(unsigned PhysReg) const override
RISCVRegisterInfo(unsigned HwMode)
const HexagonInstrInfo * TII
virtual bool hasFP(const MachineFunction &MF) const =0
hasFP - Return true if the specified function should have a dedicated frame pointer register...
Simple integer binary arithmetic operators.
Definition: ISDOpcodes.h:201
const MCPhysReg * getCalleeSavedRegs(const MachineFunction *MF) const override
void movImm32(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, unsigned DstReg, uint64_t Val, MachineInstr::MIFlag Flag=MachineInstr::NoFlags) const
const uint32_t * getCallPreservedMask(const MachineFunction &MF, CallingConv::ID) const override
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
void ChangeToImmediate(int64_t ImmVal)
ChangeToImmediate - Replace this operand with a new immediate operand of the specified value...
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
This file declares the machine register scavenger class.
unsigned const MachineRegisterInfo * MRI
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
bool hasStdExtF() const
void eliminateFrameIndex(MachineBasicBlock::iterator MI, int SPAdj, unsigned FIOperandNum, RegScavenger *RS=nullptr) const override
unsigned getFrameRegister(const MachineFunction &MF) const override
bool hasStdExtD() const
constexpr bool isInt< 32 >(int64_t x)
Definition: MathExtras.h:309
Information about stack frame layout on the target.
int64_t getImm() const
const Function & getFunction() const
Return the LLVM function that this machine code represents.
const MachineBasicBlock * getParent() const
Definition: MachineInstr.h:254
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
Representation of each machine instruction.
Definition: MachineInstr.h:64
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
IRTranslator LLVM IR MI
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:414
unsigned createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...