LLVM  9.0.0svn
RISCVRegisterInfo.cpp
Go to the documentation of this file.
1 //===-- RISCVRegisterInfo.cpp - RISCV Register Information ------*- C++ -*-===//
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 RISCV implementation of the TargetRegisterInfo class.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "RISCVRegisterInfo.h"
14 #include "RISCV.h"
15 #include "RISCVSubtarget.h"
23 
24 #define GET_REGINFO_TARGET_DESC
25 #include "RISCVGenRegisterInfo.inc"
26 
27 using namespace llvm;
28 
30  : RISCVGenRegisterInfo(RISCV::X1, /*DwarfFlavour*/0, /*EHFlavor*/0,
31  /*PC*/0, HwMode) {}
32 
33 const MCPhysReg *
35  if (MF->getFunction().hasFnAttribute("interrupt")) {
37  return CSR_XLEN_F64_Interrupt_SaveList;
39  return CSR_XLEN_F32_Interrupt_SaveList;
40  return CSR_Interrupt_SaveList;
41  }
42  return CSR_SaveList;
43 }
44 
46  BitVector Reserved(getNumRegs());
47 
48  // Use markSuperRegs to ensure any register aliases are also reserved
49  markSuperRegs(Reserved, RISCV::X0); // zero
50  markSuperRegs(Reserved, RISCV::X1); // ra
51  markSuperRegs(Reserved, RISCV::X2); // sp
52  markSuperRegs(Reserved, RISCV::X3); // gp
53  markSuperRegs(Reserved, RISCV::X4); // tp
54  markSuperRegs(Reserved, RISCV::X8); // fp
55  assert(checkAllSuperRegsMarked(Reserved));
56  return Reserved;
57 }
58 
59 bool RISCVRegisterInfo::isConstantPhysReg(unsigned PhysReg) const {
60  return PhysReg == RISCV::X0;
61 }
62 
64  return CSR_NoRegs_RegMask;
65 }
66 
68  int SPAdj, unsigned FIOperandNum,
69  RegScavenger *RS) const {
70  assert(SPAdj == 0 && "Unexpected non-zero SPAdj value");
71 
72  MachineInstr &MI = *II;
73  MachineFunction &MF = *MI.getParent()->getParent();
75  const RISCVInstrInfo *TII = MF.getSubtarget<RISCVSubtarget>().getInstrInfo();
76  DebugLoc DL = MI.getDebugLoc();
77 
78  int FrameIndex = MI.getOperand(FIOperandNum).getIndex();
79  unsigned FrameReg;
80  int Offset =
81  getFrameLowering(MF)->getFrameIndexReference(MF, FrameIndex, FrameReg) +
82  MI.getOperand(FIOperandNum + 1).getImm();
83 
84  if (!isInt<32>(Offset)) {
86  "Frame offsets outside of the signed 32-bit range not supported");
87  }
88 
89  MachineBasicBlock &MBB = *MI.getParent();
90  bool FrameRegIsKill = false;
91 
92  if (!isInt<12>(Offset)) {
93  assert(isInt<32>(Offset) && "Int32 expected");
94  // The offset won't fit in an immediate, so use a scratch register instead
95  // Modify Offset and FrameReg appropriately
96  unsigned ScratchReg = MRI.createVirtualRegister(&RISCV::GPRRegClass);
97  TII->movImm32(MBB, II, DL, ScratchReg, Offset);
98  BuildMI(MBB, II, DL, TII->get(RISCV::ADD), ScratchReg)
99  .addReg(FrameReg)
100  .addReg(ScratchReg, RegState::Kill);
101  Offset = 0;
102  FrameReg = ScratchReg;
103  FrameRegIsKill = true;
104  }
105 
106  MI.getOperand(FIOperandNum)
107  .ChangeToRegister(FrameReg, false, false, FrameRegIsKill);
108  MI.getOperand(FIOperandNum + 1).ChangeToImmediate(Offset);
109 }
110 
112  const TargetFrameLowering *TFI = getFrameLowering(MF);
113  return TFI->hasFP(MF) ? RISCV::X8 : RISCV::X2;
114 }
115 
116 const uint32_t *
118  CallingConv::ID /*CC*/) const {
119  if (MF.getFunction().hasFnAttribute("interrupt")) {
121  return CSR_XLEN_F64_Interrupt_RegMask;
123  return CSR_XLEN_F32_Interrupt_RegMask;
124  return CSR_Interrupt_RegMask;
125  }
126  return CSR_RegMask;
127 }
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:139
This class represents lattice values for constants.
Definition: AllocatorList.h:23
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:382
BitVector getReservedRegs(const MachineFunction &MF) const override
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition: Function.h:320
A debug info location.
Definition: DebugLoc.h:33
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:200
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:308
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:253
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:63
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:413
unsigned createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...