LLVM 24.0.0git
SparcRegisterInfo.cpp
Go to the documentation of this file.
1//===-- SparcRegisterInfo.cpp - SPARC Register Information ----------------===//
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 SPARC implementation of the TargetRegisterInfo class.
10//
11//===----------------------------------------------------------------------===//
12
13#include "SparcRegisterInfo.h"
14#include "Sparc.h"
15#include "SparcSubtarget.h"
16#include "llvm/ADT/BitVector.h"
21
22using namespace llvm;
23
24#define GET_REGINFO_TARGET_DESC
25#include "SparcGenRegisterInfo.inc"
26
28
29const MCPhysReg*
31 return CSR_SaveList;
32}
33
34const uint32_t *
36 CallingConv::ID CC) const {
37 return CSR_RegMask;
38}
39
40const uint32_t*
42 return RTCSR_RegMask;
43}
44
46 BitVector Reserved(getNumRegs());
48 // FIXME: G1 reserved for now for large imm generation by frame code.
49 Reserved.set(SP::G1);
50
51 // G1-G4 can be used in applications.
52 if (Subtarget.getCLOpts().reserve_app_registers) {
53 Reserved.set(SP::G2);
54 Reserved.set(SP::G3);
55 Reserved.set(SP::G4);
56 }
57 // G5 is not reserved in 64 bit mode.
58 if (!Subtarget.is64Bit())
59 Reserved.set(SP::G5);
60
61 Reserved.set(SP::O6);
62 Reserved.set(SP::I6);
63 Reserved.set(SP::I7);
64 Reserved.set(SP::G0);
65 Reserved.set(SP::G6);
66 Reserved.set(SP::G7);
67
68 // Also reserve the register pair aliases covering the above
69 // registers, with the same conditions.
70 Reserved.set(SP::G0_G1);
71 if (Subtarget.getCLOpts().reserve_app_registers)
72 Reserved.set(SP::G2_G3);
73 if (Subtarget.getCLOpts().reserve_app_registers || !Subtarget.is64Bit())
74 Reserved.set(SP::G4_G5);
75
76 Reserved.set(SP::O6_O7);
77 Reserved.set(SP::I6_I7);
78 Reserved.set(SP::G6_G7);
79
80 // Unaliased double registers are not available in non-V9 targets.
81 if (!Subtarget.isV9()) {
82 for (unsigned n = 0; n != 16; ++n) {
83 for (MCRegAliasIterator AI(SP::D16 + n, this, true); AI.isValid(); ++AI)
84 Reserved.set(*AI);
85 }
86 }
87
88 // Reserve ASR1-ASR31
89 for (unsigned n = 0; n < 31; n++)
90 Reserved.set(SP::ASR1 + n);
91
92 Reserved.set(SP::FSR);
93
94 for (TargetRegisterClass::iterator i = SP::IntRegsRegClass.begin();
95 i != SP::IntRegsRegClass.end(); ++i) {
97 markSuperRegs(Reserved, *i);
98 }
99
100 assert(checkAllSuperRegsMarked(Reserved));
101 return Reserved;
102}
103
105 MCRegister Reg) const {
106 return getReservedRegs(MF)[Reg];
107}
108
110 MachineInstr &MI, const DebugLoc &dl,
111 unsigned FIOperandNum, int Offset, unsigned FramePtr) {
112 // Replace frame index with a frame pointer reference.
113 if (Offset >= -4096 && Offset <= 4095) {
114 // If the offset is small enough to fit in the immediate field, directly
115 // encode it.
116 MI.getOperand(FIOperandNum).ChangeToRegister(FramePtr, false);
117 MI.getOperand(FIOperandNum + 1).ChangeToImmediate(Offset);
118 return;
119 }
120
122
123 // FIXME: it would be better to scavenge a register here instead of
124 // reserving G1 all of the time.
125 if (Offset >= 0) {
126 // Emit nonnegaive immediates with sethi + or.
127 // sethi %hi(Offset), %g1
128 // add %g1, %fp, %g1
129 // Insert G1+%lo(offset) into the user.
130 BuildMI(*MI.getParent(), II, dl, TII.get(SP::SETHIi), SP::G1)
131 .addImm(HI22(Offset));
132
133
134 // Emit G1 = G1 + I6
135 BuildMI(*MI.getParent(), II, dl, TII.get(SP::ADDrr), SP::G1).addReg(SP::G1)
137 // Insert: G1+%lo(offset) into the user.
138 MI.getOperand(FIOperandNum).ChangeToRegister(SP::G1, false);
139 MI.getOperand(FIOperandNum + 1).ChangeToImmediate(LO10(Offset));
140 return;
141 }
142
143 // Emit Negative numbers with sethi + xor
144 // sethi %hix(Offset), %g1
145 // xor %g1, %lox(offset), %g1
146 // add %g1, %fp, %g1
147 // Insert: G1 + 0 into the user.
148 BuildMI(*MI.getParent(), II, dl, TII.get(SP::SETHIi), SP::G1)
150 BuildMI(*MI.getParent(), II, dl, TII.get(SP::XORri), SP::G1)
151 .addReg(SP::G1).addImm(LOX10(Offset));
152
153 BuildMI(*MI.getParent(), II, dl, TII.get(SP::ADDrr), SP::G1).addReg(SP::G1)
155 // Insert: G1+%lo(offset) into the user.
156 MI.getOperand(FIOperandNum).ChangeToRegister(SP::G1, false);
157 MI.getOperand(FIOperandNum + 1).ChangeToImmediate(0);
158}
159
160
161bool
163 int SPAdj, unsigned FIOperandNum,
164 RegScavenger *RS) const {
165 assert(SPAdj == 0 && "Unexpected");
166
167 MachineInstr &MI = *II;
168 DebugLoc dl = MI.getDebugLoc();
169 int FrameIndex = MI.getOperand(FIOperandNum).getIndex();
170 MachineFunction &MF = *MI.getParent()->getParent();
172 const SparcFrameLowering *TFI = getFrameLowering(MF);
173
174 Register FrameReg;
175 int Offset;
176 Offset = TFI->getFrameIndexReference(MF, FrameIndex, FrameReg).getFixed();
177
178 Offset += MI.getOperand(FIOperandNum + 1).getImm();
179
180 if (!Subtarget.isV9() || !Subtarget.hasHardQuad()) {
181 if (MI.getOpcode() == SP::STQFri) {
182 const TargetInstrInfo &TII = *Subtarget.getInstrInfo();
183 Register SrcReg = MI.getOperand(2).getReg();
184 Register SrcEvenReg = getSubReg(SrcReg, SP::sub_even64);
185 Register SrcOddReg = getSubReg(SrcReg, SP::sub_odd64);
186 MachineInstr *StMI =
187 BuildMI(*MI.getParent(), II, dl, TII.get(SP::STDFri))
188 .addReg(FrameReg).addImm(0).addReg(SrcEvenReg);
189 replaceFI(MF, *StMI, *StMI, dl, 0, Offset, FrameReg);
190 MI.setDesc(TII.get(SP::STDFri));
191 MI.getOperand(2).setReg(SrcOddReg);
192 Offset += 8;
193 } else if (MI.getOpcode() == SP::LDQFri) {
194 const TargetInstrInfo &TII = *Subtarget.getInstrInfo();
195 Register DestReg = MI.getOperand(0).getReg();
196 Register DestEvenReg = getSubReg(DestReg, SP::sub_even64);
197 Register DestOddReg = getSubReg(DestReg, SP::sub_odd64);
198 MachineInstr *LdMI =
199 BuildMI(*MI.getParent(), II, dl, TII.get(SP::LDDFri), DestEvenReg)
200 .addReg(FrameReg).addImm(0);
201 replaceFI(MF, *LdMI, *LdMI, dl, 1, Offset, FrameReg);
202
203 MI.setDesc(TII.get(SP::LDDFri));
204 MI.getOperand(0).setReg(DestOddReg);
205 Offset += 8;
206 }
207 }
208
209 replaceFI(MF, II, MI, dl, FIOperandNum, Offset, FrameReg);
210 // replaceFI never removes II
211 return false;
212}
213
215 return SP::I6;
216}
const AArch64Subtarget & Subtarget
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
const AArch64InstrInfo & TII
This file implements the BitVector class.
IRTranslator LLVM IR MI
uint64_t IntrinsicInst * II
RISCVCC::CondCode CC
static void replaceFI(MachineFunction &MF, MachineBasicBlock::iterator II, MachineInstr &MI, const DebugLoc &dl, unsigned FIOperandNum, int Offset, unsigned FramePtr)
static const unsigned FramePtr
A debug info location.
Definition DebugLoc.h:126
MCRegAliasIterator enumerates all registers aliasing Reg.
const MCPhysReg * iterator
Wrapper class representing physical registers and target specific virtual registers.
Definition MCRegister.h:42
MachineInstrBundleIterator< MachineInstr > iterator
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
const MachineInstrBuilder & addReg(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
Representation of each machine instruction.
Wrapper class representing virtual and physical registers.
Definition Register.h:20
bool isRegisterReserved(MCPhysReg PhysReg) const
TargetInstrInfo - Interface to description of machine instruction set.
virtual const TargetInstrInfo * getInstrInfo() const
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:577
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
static unsigned HI22(int64_t imm)
Definition Sparc.h:199
static unsigned HIX22(int64_t imm)
Definition Sparc.h:207
static unsigned LOX10(int64_t imm)
Definition Sparc.h:211
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
Definition MCRegister.h:21
static unsigned LO10(int64_t imm)
Definition Sparc.h:203
const MCPhysReg * getCalleeSavedRegs(const MachineFunction *MF) const override
Code Generation virtual methods...
bool eliminateFrameIndex(MachineBasicBlock::iterator II, int SPAdj, unsigned FIOperandNum, RegScavenger *RS=nullptr) const override
BitVector getReservedRegs(const MachineFunction &MF) const override
bool isReservedReg(const MachineFunction &MF, MCRegister Reg) const
const uint32_t * getCallPreservedMask(const MachineFunction &MF, CallingConv::ID CC) const override
Register getFrameRegister(const MachineFunction &MF) const override
const uint32_t * getRTCallPreservedMask(CallingConv::ID CC) const