LLVM 24.0.0git
RISCVRegisterInfo.h
Go to the documentation of this file.
1//===-- RISCVRegisterInfo.h - RISC-V Register Information Impl --*- 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 RISC-V implementation of the TargetRegisterInfo class.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_LIB_TARGET_RISCV_RISCVREGISTERINFO_H
14#define LLVM_LIB_TARGET_RISCV_RISCVREGISTERINFO_H
15
18
19#define GET_REGINFO_HEADER
20#include "RISCVGenRegisterInfo.inc"
21
22namespace llvm {
23
24namespace RISCVRI {
25enum : uint8_t {
26 // The IsVRegClass value of this RegisterClass.
29 // The VLMul value of this RegisterClass. This value is valid iff IsVRegClass
30 // is true.
33
34 // The NF value of this RegisterClass. This value is valid iff IsVRegClass is
35 // true.
37 NFShiftMask = 0b111 << NFShift,
38};
39
40/// Register allocation hints for Zilsd register pairs
41enum {
42 // Used for Zilsd LD/SD register pairs
45};
46
47/// \returns the IsVRegClass for the register class.
48static inline bool isVRegClass(uint8_t TSFlags) {
49 return (TSFlags & IsVRegClassShiftMask) >> IsVRegClassShift;
50}
51
52/// \returns the LMUL for the register class.
53static inline RISCVVType::VLMUL getLMul(uint8_t TSFlags) {
54 return static_cast<RISCVVType::VLMUL>((TSFlags & VLMulShiftMask) >>
56}
57
58/// \returns the NF for the register class.
59static inline unsigned getNF(uint8_t TSFlags) {
60 return static_cast<unsigned>((TSFlags & NFShiftMask) >> NFShift) + 1;
61}
62} // namespace RISCVRI
63
65
66 RISCVRegisterInfo(unsigned HwMode);
67
69 CallingConv::ID) const override;
70
71 unsigned getCSRCost() const override {
72 // The cost will be compared against BlockFrequency where entry has the
73 // value of 1 << 14. A value of 5 will choose to spill or split cold
74 // path instead of using a callee-saved register.
75 return 5;
76 }
77
78 const MCPhysReg *getCalleeSavedRegs(const MachineFunction *MF) const override;
79
82 const MachineRegisterInfo &MRI) const override;
83
85 getRegClassForTypeOnBank(LLT Ty, const RegisterBank &RB, bool Is64Bit) const;
86
87 const MCPhysReg *getIPRACSRegs(const MachineFunction *MF) const override;
88
89 BitVector getReservedRegs(const MachineFunction &MF) const override;
90 bool isAsmClobberable(const MachineFunction &MF,
91 MCRegister PhysReg) const override;
92
93 const uint32_t *getNoPreservedMask() const override;
94
95 // Update DestReg to have the value SrcReg plus an offset. This is
96 // used during frame layout, and we may need to ensure that if we
97 // split the offset internally that the DestReg is always aligned,
98 // assuming that source reg was.
100 const DebugLoc &DL, Register DestReg, Register SrcReg,
102 MaybeAlign RequiredAlign) const;
103
105 unsigned FIOperandNum,
106 RegScavenger *RS = nullptr) const override;
107
108 bool requiresVirtualBaseRegisters(const MachineFunction &MF) const override;
109
110 bool needsFrameBaseReg(MachineInstr *MI, int64_t Offset) const override;
111
112 bool isFrameOffsetLegal(const MachineInstr *MI, Register BaseReg,
113 int64_t Offset) const override;
114
116 int64_t Offset) const override;
117
119 int64_t Offset) const override;
120
122 int Idx) const override;
123
125 bool IsSpill) const;
126
127 Register getFrameRegister(const MachineFunction &MF) const override;
128
129 bool isArgumentRegister(const MachineFunction &MF,
130 MCRegister Reg) const override;
131
132 StringRef getRegAsmName(MCRegister Reg) const override;
133
134 bool requiresRegisterScavenging(const MachineFunction &MF) const override {
135 return true;
136 }
137
138 bool requiresFrameIndexScavenging(const MachineFunction &MF) const override {
139 return true;
140 }
141
142 const TargetRegisterClass *
143 getPointerRegClass(unsigned Kind = 0) const override {
144 return &RISCV::GPRRegClass;
145 }
146
147 const TargetRegisterClass *
149 const MachineFunction &) const override;
150
152 SmallVectorImpl<uint64_t> &Ops) const override;
153
154 unsigned getRegisterCostTableIndex(const MachineFunction &MF) const override;
155
156 float getSpillWeightScaleFactor(const TargetRegisterClass *RC) const override;
157
160 const MachineFunction &MF, const VirtRegMap *VRM,
161 const LiveRegMatrix *Matrix) const override;
162
164 MachineFunction &MF) const override;
165
167 uint16_t Encoding) const;
168
169 static bool isVRRegClass(const TargetRegisterClass *RC) {
170 return RISCVRI::isVRegClass(RC->TSFlags) &&
171 RISCVRI::getNF(RC->TSFlags) == 1;
172 }
173
174 static bool isVRNRegClass(const TargetRegisterClass *RC) {
175 return RISCVRI::isVRegClass(RC->TSFlags) && RISCVRI::getNF(RC->TSFlags) > 1;
176 }
177
178 static bool isRVVRegClass(const TargetRegisterClass *RC) {
179 return RISCVRI::isVRegClass(RC->TSFlags);
180 }
181
183 return RISCV::FPR16RegClass.contains(Reg) ||
184 RISCV::FPR32RegClass.contains(Reg) ||
185 RISCV::FPR64RegClass.contains(Reg) ||
186 RISCV::FPR128RegClass.contains(Reg);
187 }
188};
189} // namespace llvm
190
191#endif
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
IRTranslator LLVM IR MI
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
Live Register Matrix
Register Reg
uint64_t IntrinsicInst * II
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
A debug info location.
Definition DebugLoc.h:126
const uint8_t TSFlags
Configurable target specific flags.
Wrapper class representing physical registers. Should be passed by value.
Definition MCRegister.h:41
MachineInstrBundleIterator< MachineInstr > iterator
Representation of each machine instruction.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
This class implements the register bank concept.
Wrapper class representing virtual and physical registers.
Definition Register.h:20
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
StackOffset holds a fixed and a scalable offset in bytes.
Definition TypeSize.h:30
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
static unsigned getNF(uint8_t TSFlags)
static bool isVRegClass(uint8_t TSFlags)
static RISCVVType::VLMUL getLMul(uint8_t TSFlags)
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:578
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
Definition MCRegister.h:21
MCRegisterClass TargetRegisterClass
Definition FastISel.h:58
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition Alignment.h:106
bool needsFrameBaseReg(MachineInstr *MI, int64_t Offset) const override
bool requiresVirtualBaseRegisters(const MachineFunction &MF) const override
Register findVRegWithEncoding(const TargetRegisterClass &RegClass, uint16_t Encoding) const
bool requiresRegisterScavenging(const MachineFunction &MF) const override
const TargetRegisterClass * getLargestLegalSuperClass(const TargetRegisterClass *RC, const MachineFunction &) const override
bool isArgumentRegister(const MachineFunction &MF, MCRegister Reg) const override
unsigned getCSRCost() const override
const MCPhysReg * getCalleeSavedRegs(const MachineFunction *MF) const override
BitVector getReservedRegs(const MachineFunction &MF) const override
const uint32_t * getCallPreservedMask(const MachineFunction &MF, CallingConv::ID) const override
static bool isVRNRegClass(const TargetRegisterClass *RC)
bool requiresFrameIndexScavenging(const MachineFunction &MF) const override
Register materializeFrameBaseRegister(MachineBasicBlock *MBB, int FrameIdx, int64_t Offset) const override
RISCVRegisterInfo(unsigned HwMode)
void getOffsetOpcodes(const StackOffset &Offset, SmallVectorImpl< uint64_t > &Ops) const override
bool isFrameOffsetLegal(const MachineInstr *MI, Register BaseReg, int64_t Offset) const override
static bool isRVVRegClass(const TargetRegisterClass *RC)
Register getFrameRegister(const MachineFunction &MF) const override
static bool isFPRegister(MCRegister Reg)
const MCPhysReg * getIPRACSRegs(const MachineFunction *MF) const override
void lowerSegmentSpillReload(MachineBasicBlock::iterator II, bool IsSpill) const
const TargetRegisterClass * getRegClassForTypeOnBank(LLT Ty, const RegisterBank &RB, bool Is64Bit) const
const TargetRegisterClass * getPointerRegClass(unsigned Kind=0) const override
void adjustReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator II, const DebugLoc &DL, Register DestReg, Register SrcReg, StackOffset Offset, MachineInstr::MIFlag Flag, MaybeAlign RequiredAlign) const
void updateRegAllocHint(Register Reg, Register NewReg, MachineFunction &MF) const override
bool isAsmClobberable(const MachineFunction &MF, MCRegister PhysReg) const override
const uint32_t * getNoPreservedMask() const override
float getSpillWeightScaleFactor(const TargetRegisterClass *RC) const override
const TargetRegisterClass * getConstrainedRegClassForReg(Register Reg, const MachineRegisterInfo &MRI) const override
static bool isVRRegClass(const TargetRegisterClass *RC)
void resolveFrameIndex(MachineInstr &MI, Register BaseReg, int64_t Offset) const override
bool getRegAllocationHints(Register VirtReg, ArrayRef< MCPhysReg > Order, SmallVectorImpl< MCPhysReg > &Hints, const MachineFunction &MF, const VirtRegMap *VRM, const LiveRegMatrix *Matrix) const override
int64_t getFrameIndexInstrOffset(const MachineInstr *MI, int Idx) const override
unsigned getRegisterCostTableIndex(const MachineFunction &MF) const override
StringRef getRegAsmName(MCRegister Reg) const override
bool eliminateFrameIndex(MachineBasicBlock::iterator MI, int SPAdj, unsigned FIOperandNum, RegScavenger *RS=nullptr) const override