1//===-- MipsSEInstrInfo.cpp - Mips32/64 Instruction 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 Mips32/64 implementation of the TargetInstrInfo class.
10//
11//===----------------------------------------------------------------------===//
12
13#include "MipsSEInstrInfo.h"
14#include "MipsAnalyzeImmediate.h"
15#include "MipsTargetMachine.h"
16#include "llvm/CodeGen/MachineInstrBuilder.h"
17#include "llvm/CodeGen/MachineRegisterInfo.h"
18#include "llvm/MC/TargetRegistry.h"
19#include "llvm/Support/ErrorHandling.h"
20#include "llvm/Support/MathExtras.h"
21
22using namespace llvm;
23
24static unsigned getUnconditionalBranch(const MipsSubtarget &STI) {
25 if (STI.inMicroMipsMode())
26 return STI.isPositionIndependent() ? Mips::B_MM : Mips::J_MM;
27 return STI.isPositionIndependent() ? Mips::B : Mips::J;
28}
29
30MipsSEInstrInfo::MipsSEInstrInfo(const MipsSubtarget &STI)
31 : MipsInstrInfo(STI, RI, getUnconditionalBranch(STI)), RI(STI) {}
32
33/// isLoadFromStackSlot - If the specified machine instruction is a direct
34/// load from a stack slot, return the virtual or physical register number of
35/// the destination along with the FrameIndex of the loaded stack slot. If
36/// not, return 0. This predicate must return 0 if the instruction has
37/// any side effects other than loading from the stack slot.
38Register MipsSEInstrInfo::isLoadFromStackSlot(const MachineInstr &MI,
39 int &FrameIndex) const {
40 unsigned Opc = MI.getOpcode();
41
42 if ((Opc == Mips::LW) || (Opc == Mips::LD) ||
43 (Opc == Mips::LWC1) || (Opc == Mips::LDC1) || (Opc == Mips::LDC164)) {
44 if ((MI.getOperand(i: 1).isFI()) && // is a stack slot
45 (MI.getOperand(i: 2).isImm()) && // the imm is zero
46 (isZeroImm(op: MI.getOperand(i: 2)))) {
47 FrameIndex = MI.getOperand(i: 1).getIndex();
48 return MI.getOperand(i: 0).getReg();
49 }
50 }
51
52 return 0;
53}
54
55/// isStoreToStackSlot - If the specified machine instruction is a direct
56/// store to a stack slot, return the virtual or physical register number of
57/// the source reg along with the FrameIndex of the loaded stack slot. If
58/// not, return 0. This predicate must return 0 if the instruction has
59/// any side effects other than storing to the stack slot.
60Register MipsSEInstrInfo::isStoreToStackSlot(const MachineInstr &MI,
61 int &FrameIndex) const {
62 unsigned Opc = MI.getOpcode();
63
64 if ((Opc == Mips::SW) || (Opc == Mips::SD) ||
65 (Opc == Mips::SWC1) || (Opc == Mips::SDC1) || (Opc == Mips::SDC164)) {
66 if ((MI.getOperand(i: 1).isFI()) && // is a stack slot
67 (MI.getOperand(i: 2).isImm()) && // the imm is zero
68 (isZeroImm(op: MI.getOperand(i: 2)))) {
69 FrameIndex = MI.getOperand(i: 1).getIndex();
70 return MI.getOperand(i: 0).getReg();
71 }
72 }
73 return 0;
74}
75
76void MipsSEInstrInfo::copyPhysReg(MachineBasicBlock &MBB,
77 MachineBasicBlock::iterator I,
78 const DebugLoc &DL, Register DestReg,
79 Register SrcReg, bool KillSrc,
80 bool RenamableDest, bool RenamableSrc) const {
81 unsigned Opc = 0, ZeroReg = 0;
82 bool isMicroMips = Subtarget.inMicroMipsMode();
83
84 if (Mips::GPR32RegClass.contains(Reg: DestReg)) { // Copy to CPU Reg.
85 if (Mips::GPR32RegClass.contains(Reg: SrcReg)) {
86 if (Subtarget.hasNanoMips())
87 Opc = Mips::MOVE_NM;
88 else if (isMicroMips)
89 Opc = Mips::MOVE16_MM;
90 else
91 Opc = Mips::OR, ZeroReg = Mips::R0;
92 } else if (Mips::CCRRegClass.contains(Reg: SrcReg))
93 Opc = Mips::CFC1;
94 else if (Mips::FGR32RegClass.contains(Reg: SrcReg))
95 Opc = Mips::MFC1;
96 else if (Mips::HI32RegClass.contains(Reg: SrcReg)) {
97 Opc = isMicroMips ? Mips::MFHI16_MM : Mips::MFHI;
98 SrcReg = 0;
99 } else if (Mips::LO32RegClass.contains(Reg: SrcReg)) {
100 Opc = isMicroMips ? Mips::MFLO16_MM : Mips::MFLO;
101 SrcReg = 0;
102 } else if (Mips::HI32DSPRegClass.contains(Reg: SrcReg))
103 Opc = Mips::MFHI_DSP;
104 else if (Mips::LO32DSPRegClass.contains(Reg: SrcReg))
105 Opc = Mips::MFLO_DSP;
106 else if (Mips::DSPCCRegClass.contains(Reg: SrcReg)) {
107 BuildMI(BB&: MBB, I, MIMD: DL, MCID: get(Opcode: Mips::RDDSP), DestReg).addImm(Val: 1 << 4)
108 .addReg(RegNo: SrcReg, Flags: RegState::Implicit | getKillRegState(B: KillSrc));
109 return;
110 } else if (Mips::MSACtrlRegClass.contains(Reg: SrcReg)) {
111 Opc = Mips::CFCMSA;
112 }
113 }
114 else if (Mips::GPR32RegClass.contains(Reg: SrcReg)) { // Copy from CPU Reg.
115 if (Mips::CCRRegClass.contains(Reg: DestReg))
116 Opc = Mips::CTC1;
117 else if (Mips::FGR32RegClass.contains(Reg: DestReg))
118 Opc = Mips::MTC1;
119 else if (Mips::HI32RegClass.contains(Reg: DestReg))
120 Opc = Mips::MTHI, DestReg = 0;
121 else if (Mips::LO32RegClass.contains(Reg: DestReg))
122 Opc = Mips::MTLO, DestReg = 0;
123 else if (Mips::HI32DSPRegClass.contains(Reg: DestReg))
124 Opc = Mips::MTHI_DSP;
125 else if (Mips::LO32DSPRegClass.contains(Reg: DestReg))
126 Opc = Mips::MTLO_DSP;
127 else if (Mips::DSPCCRegClass.contains(Reg: DestReg)) {
128 BuildMI(BB&: MBB, I, MIMD: DL, MCID: get(Opcode: Mips::WRDSP))
129 .addReg(RegNo: SrcReg, Flags: getKillRegState(B: KillSrc)).addImm(Val: 1 << 4)
130 .addReg(RegNo: DestReg, Flags: RegState::ImplicitDefine);
131 return;
132 } else if (Mips::MSACtrlRegClass.contains(Reg: DestReg)) {
133 BuildMI(BB&: MBB, I, MIMD: DL, MCID: get(Opcode: Mips::CTCMSA))
134 .addReg(RegNo: DestReg)
135 .addReg(RegNo: SrcReg, Flags: getKillRegState(B: KillSrc));
136 return;
137 }
138 }
139 else if (Mips::FGR32RegClass.contains(Reg1: DestReg, Reg2: SrcReg))
140 Opc = Mips::FMOV_S;
141 else if (Mips::AFGR64RegClass.contains(Reg1: DestReg, Reg2: SrcReg))
142 Opc = Mips::FMOV_D32;
143 else if (Mips::FGR64RegClass.contains(Reg1: DestReg, Reg2: SrcReg))
144 Opc = Mips::FMOV_D64;
145 else if (Mips::GPR64RegClass.contains(Reg: DestReg)) { // Copy to CPU64 Reg.
146 if (Mips::GPR64RegClass.contains(Reg: SrcReg))
147 Opc = Mips::OR64, ZeroReg = Mips::R0_64;
148 else if (Mips::HI64RegClass.contains(Reg: SrcReg))
149 Opc = Mips::MFHI64, SrcReg = 0;
150 else if (Mips::LO64RegClass.contains(Reg: SrcReg))
151 Opc = Mips::MFLO64, SrcReg = 0;
152 else if (Mips::FGR64RegClass.contains(Reg: SrcReg))
153 Opc = Mips::DMFC1;
154 }
155 else if (Mips::GPR64RegClass.contains(Reg: SrcReg)) { // Copy from CPU64 Reg.
156 if (Mips::HI64RegClass.contains(Reg: DestReg))
157 Opc = Mips::MTHI64, DestReg = 0;
158 else if (Mips::LO64RegClass.contains(Reg: DestReg))
159 Opc = Mips::MTLO64, DestReg = 0;
160 else if (Mips::FGR64RegClass.contains(Reg: DestReg))
161 Opc = Mips::DMTC1;
162 } else if (Mips::MSA128BRegClass.contains(Reg: DestReg)) { // Copy to MSA reg
163 if (Mips::MSA128BRegClass.contains(Reg: SrcReg))
164 Opc = Mips::MOVE_V;
165 }
166
167 assert(Opc && "Cannot copy registers");
168
169 MachineInstrBuilder MIB = BuildMI(BB&: MBB, I, MIMD: DL, MCID: get(Opcode: Opc));
170
171 if (DestReg)
172 MIB.addReg(RegNo: DestReg, Flags: RegState::Define);
173
174 if (SrcReg)
175 MIB.addReg(RegNo: SrcReg, Flags: getKillRegState(B: KillSrc));
176
177 if (ZeroReg)
178 MIB.addReg(RegNo: ZeroReg);
179}
180
181static bool isORCopyInst(const MachineInstr &MI) {
182 switch (MI.getOpcode()) {
183 default:
184 break;
185 case Mips::OR_MM:
186 case Mips::OR:
187 if (MI.getOperand(i: 2).getReg() == Mips::R0)
188 return true;
189 break;
190 case Mips::OR64:
191 if (MI.getOperand(i: 2).getReg() == Mips::R0_64)
192 return true;
193 break;
194 }
195 return false;
196}
197
198/// We check for the common case of 'or', as it's MIPS' preferred instruction
199/// for GPRs but we have to check the operands to ensure that is the case.
200/// Other move instructions for MIPS are directly identifiable.
201std::optional<DestSourcePair>
202MipsSEInstrInfo::isCopyInstrImpl(const MachineInstr &MI) const {
203 if (MI.isMoveReg() || isORCopyInst(MI))
204 return DestSourcePair{MI.getOperand(i: 0), MI.getOperand(i: 1)};
205
206 return std::nullopt;
207}
208
209void MipsSEInstrInfo::storeRegToStack(MachineBasicBlock &MBB,
210 MachineBasicBlock::iterator I,
211 Register SrcReg, bool isKill, int FI,
212 const TargetRegisterClass *RC,
213 int64_t Offset,
214 MachineInstr::MIFlag Flags) const {
215 DebugLoc DL;
216 MachineMemOperand *MMO = GetMemOperand(MBB, FI, Flags: MachineMemOperand::MOStore);
217
218 unsigned Opc = 0;
219
220 if (Mips::GPR32RegClass.hasSubClassEq(RC))
221 Opc = Subtarget.hasNanoMips() ? Mips::SW_NM : Mips::SW;
222 else if (Mips::GPR64RegClass.hasSubClassEq(RC))
223 Opc = Mips::SD;
224 else if (Mips::ACC64RegClass.hasSubClassEq(RC))
225 Opc = Mips::STORE_ACC64;
226 else if (Mips::ACC64DSPRegClass.hasSubClassEq(RC))
227 Opc = Mips::STORE_ACC64DSP;
228 else if (Mips::ACC128RegClass.hasSubClassEq(RC))
229 Opc = Mips::STORE_ACC128;
230 else if (Mips::DSPCCRegClass.hasSubClassEq(RC))
231 Opc = Mips::STORE_CCOND_DSP;
232 else if (Mips::FGR32RegClass.hasSubClassEq(RC))
233 Opc = Mips::SWC1;
234 else if (Mips::AFGR64RegClass.hasSubClassEq(RC))
235 Opc = Mips::SDC1;
236 else if (Mips::FGR64RegClass.hasSubClassEq(RC))
237 Opc = Mips::SDC164;
238 else if (RI.isTypeLegalForClass(RC: *RC, T: MVT::v16i8))
239 Opc = Mips::ST_B;
240 else if (RI.isTypeLegalForClass(RC: *RC, T: MVT::v8i16) ||
241 RI.isTypeLegalForClass(RC: *RC, T: MVT::v8f16))
242 Opc = Mips::ST_H;
243 else if (RI.isTypeLegalForClass(RC: *RC, T: MVT::v4i32) ||
244 RI.isTypeLegalForClass(RC: *RC, T: MVT::v4f32))
245 Opc = Mips::ST_W;
246 else if (RI.isTypeLegalForClass(RC: *RC, T: MVT::v2i64) ||
247 RI.isTypeLegalForClass(RC: *RC, T: MVT::v2f64))
248 Opc = Mips::ST_D;
249 else if (Mips::LO32RegClass.hasSubClassEq(RC))
250 Opc = Mips::SW;
251 else if (Mips::LO64RegClass.hasSubClassEq(RC))
252 Opc = Mips::SD;
253 else if (Mips::HI32RegClass.hasSubClassEq(RC))
254 Opc = Mips::SW;
255 else if (Mips::HI64RegClass.hasSubClassEq(RC))
256 Opc = Mips::SD;
257 else if (Mips::DSPRRegClass.hasSubClassEq(RC))
258 Opc = Mips::SWDSP;
259
260 // Hi, Lo are normally caller save but they are callee save
261 // for interrupt handling.
262 const Function &Func = MBB.getParent()->getFunction();
263 if (Func.hasFnAttribute(Kind: "interrupt")) {
264 if (Mips::HI32RegClass.hasSubClassEq(RC)) {
265 BuildMI(BB&: MBB, I, MIMD: DL, MCID: get(Opcode: Mips::MFHI), DestReg: Mips::R26);
266 SrcReg = Mips::R26;
267 } else if (Mips::HI64RegClass.hasSubClassEq(RC)) {
268 BuildMI(BB&: MBB, I, MIMD: DL, MCID: get(Opcode: Mips::MFHI64), DestReg: Mips::R26_64);
269 SrcReg = Mips::R26_64;
270 } else if (Mips::LO32RegClass.hasSubClassEq(RC)) {
271 BuildMI(BB&: MBB, I, MIMD: DL, MCID: get(Opcode: Mips::MFLO), DestReg: Mips::R26);
272 SrcReg = Mips::R26;
273 } else if (Mips::LO64RegClass.hasSubClassEq(RC)) {
274 BuildMI(BB&: MBB, I, MIMD: DL, MCID: get(Opcode: Mips::MFLO64), DestReg: Mips::R26_64);
275 SrcReg = Mips::R26_64;
276 }
277 }
278
279 assert(Opc && "Register class not handled!");
280 BuildMI(BB&: MBB, I, MIMD: DL, MCID: get(Opcode: Opc)).addReg(RegNo: SrcReg, Flags: getKillRegState(B: isKill))
281 .addFrameIndex(Idx: FI).addImm(Val: Offset).addMemOperand(MMO);
282}
283
284void MipsSEInstrInfo::loadRegFromStack(MachineBasicBlock &MBB,
285 MachineBasicBlock::iterator I,
286 Register DestReg, int FI,
287 const TargetRegisterClass *RC,
288 int64_t Offset,
289 MachineInstr::MIFlag Flags) const {
290 DebugLoc DL;
291 if (I != MBB.end()) DL = I->getDebugLoc();
292 MachineMemOperand *MMO = GetMemOperand(MBB, FI, Flags: MachineMemOperand::MOLoad);
293 unsigned Opc = 0;
294
295 const Function &Func = MBB.getParent()->getFunction();
296 bool ReqIndirectLoad = Func.hasFnAttribute(Kind: "interrupt") &&
297 (DestReg == Mips::LO0 || DestReg == Mips::LO0_64 ||
298 DestReg == Mips::HI0 || DestReg == Mips::HI0_64);
299
300 if (Mips::GPR32RegClass.hasSubClassEq(RC))
301 Opc = Subtarget.hasNanoMips() ? Mips::LW_NM : Mips::LW;
302 else if (Mips::GPR64RegClass.hasSubClassEq(RC))
303 Opc = Mips::LD;
304 else if (Mips::ACC64RegClass.hasSubClassEq(RC))
305 Opc = Mips::LOAD_ACC64;
306 else if (Mips::ACC64DSPRegClass.hasSubClassEq(RC))
307 Opc = Mips::LOAD_ACC64DSP;
308 else if (Mips::ACC128RegClass.hasSubClassEq(RC))
309 Opc = Mips::LOAD_ACC128;
310 else if (Mips::DSPCCRegClass.hasSubClassEq(RC))
311 Opc = Mips::LOAD_CCOND_DSP;
312 else if (Mips::FGR32RegClass.hasSubClassEq(RC))
313 Opc = Mips::LWC1;
314 else if (Mips::AFGR64RegClass.hasSubClassEq(RC))
315 Opc = Mips::LDC1;
316 else if (Mips::FGR64RegClass.hasSubClassEq(RC))
317 Opc = Mips::LDC164;
318 else if (RI.isTypeLegalForClass(RC: *RC, T: MVT::v16i8))
319 Opc = Mips::LD_B;
320 else if (RI.isTypeLegalForClass(RC: *RC, T: MVT::v8i16) ||
321 RI.isTypeLegalForClass(RC: *RC, T: MVT::v8f16))
322 Opc = Mips::LD_H;
323 else if (RI.isTypeLegalForClass(RC: *RC, T: MVT::v4i32) ||
324 RI.isTypeLegalForClass(RC: *RC, T: MVT::v4f32))
325 Opc = Mips::LD_W;
326 else if (RI.isTypeLegalForClass(RC: *RC, T: MVT::v2i64) ||
327 RI.isTypeLegalForClass(RC: *RC, T: MVT::v2f64))
328 Opc = Mips::LD_D;
329 else if (Mips::HI32RegClass.hasSubClassEq(RC))
330 Opc = Mips::LW;
331 else if (Mips::HI64RegClass.hasSubClassEq(RC))
332 Opc = Mips::LD;
333 else if (Mips::LO32RegClass.hasSubClassEq(RC))
334 Opc = Mips::LW;
335 else if (Mips::LO64RegClass.hasSubClassEq(RC))
336 Opc = Mips::LD;
337 else if (Mips::DSPRRegClass.hasSubClassEq(RC))
338 Opc = Mips::LWDSP;
339
340 assert(Opc && "Register class not handled!");
341
342 if (!ReqIndirectLoad)
343 BuildMI(BB&: MBB, I, MIMD: DL, MCID: get(Opcode: Opc), DestReg)
344 .addFrameIndex(Idx: FI)
345 .addImm(Val: Offset)
346 .addMemOperand(MMO);
347 else {
348 // Load HI/LO through K0. Notably the DestReg is encoded into the
349 // instruction itself.
350 unsigned Reg = Mips::R26;
351 unsigned LdOp = Mips::MTLO;
352 if (DestReg == Mips::HI0)
353 LdOp = Mips::MTHI;
354
355 if (Subtarget.getABI().ArePtrs64bit()) {
356 Reg = Mips::R26_64;
357 if (DestReg == Mips::HI0_64)
358 LdOp = Mips::MTHI64;
359 else
360 LdOp = Mips::MTLO64;
361 }
362
363 BuildMI(BB&: MBB, I, MIMD: DL, MCID: get(Opcode: Opc), DestReg: Reg)
364 .addFrameIndex(Idx: FI)
365 .addImm(Val: Offset)
366 .addMemOperand(MMO);
367 BuildMI(BB&: MBB, I, MIMD: DL, MCID: get(Opcode: LdOp)).addReg(RegNo: Reg);
368 }
369}
370
371bool MipsSEInstrInfo::expandPostRAPseudo(MachineInstr &MI) const {
372 MachineBasicBlock &MBB = *MI.getParent();
373 bool isMicroMips = Subtarget.inMicroMipsMode();
374 unsigned Opc;
375
376 switch (MI.getDesc().getOpcode()) {
377 default:
378 return false;
379 case Mips::RetRA:
380 expandRetRA(MBB, I: MI);
381 break;
382 case Mips::ERet:
383 expandERet(MBB, I: MI);
384 break;
385 case Mips::PseudoMFHI:
386 expandPseudoMFHiLo(MBB, I: MI, NewOpc: Mips::MFHI);
387 break;
388 case Mips::PseudoMFHI_MM:
389 expandPseudoMFHiLo(MBB, I: MI, NewOpc: Mips::MFHI16_MM);
390 break;
391 case Mips::PseudoMFLO:
392 expandPseudoMFHiLo(MBB, I: MI, NewOpc: Mips::MFLO);
393 break;
394 case Mips::PseudoMFLO_MM:
395 expandPseudoMFHiLo(MBB, I: MI, NewOpc: Mips::MFLO16_MM);
396 break;
397 case Mips::PseudoMFHI64:
398 expandPseudoMFHiLo(MBB, I: MI, NewOpc: Mips::MFHI64);
399 break;
400 case Mips::PseudoMFLO64:
401 expandPseudoMFHiLo(MBB, I: MI, NewOpc: Mips::MFLO64);
402 break;
403 case Mips::PseudoMTLOHI:
404 expandPseudoMTLoHi(MBB, I: MI, LoOpc: Mips::MTLO, HiOpc: Mips::MTHI, HasExplicitDef: false);
405 break;
406 case Mips::PseudoMTLOHI64:
407 expandPseudoMTLoHi(MBB, I: MI, LoOpc: Mips::MTLO64, HiOpc: Mips::MTHI64, HasExplicitDef: false);
408 break;
409 case Mips::PseudoMTLOHI_DSP:
410 expandPseudoMTLoHi(MBB, I: MI, LoOpc: Mips::MTLO_DSP, HiOpc: Mips::MTHI_DSP, HasExplicitDef: true);
411 break;
412 case Mips::PseudoMTLOHI_MM:
413 expandPseudoMTLoHi(MBB, I: MI, LoOpc: Mips::MTLO_MM, HiOpc: Mips::MTHI_MM, HasExplicitDef: false);
414 break;
415 case Mips::PseudoCVT_S_W:
416 expandCvtFPInt(MBB, I: MI, CvtOpc: Mips::CVT_S_W, MovOpc: Mips::MTC1, IsI64: false);
417 break;
418 case Mips::PseudoCVT_D32_W:
419 Opc = isMicroMips ? Mips::CVT_D32_W_MM : Mips::CVT_D32_W;
420 expandCvtFPInt(MBB, I: MI, CvtOpc: Opc, MovOpc: Mips::MTC1, IsI64: false);
421 break;
422 case Mips::PseudoCVT_S_L:
423 expandCvtFPInt(MBB, I: MI, CvtOpc: Mips::CVT_S_L, MovOpc: Mips::DMTC1, IsI64: true);
424 break;
425 case Mips::PseudoCVT_D64_W:
426 Opc = isMicroMips ? Mips::CVT_D64_W_MM : Mips::CVT_D64_W;
427 expandCvtFPInt(MBB, I: MI, CvtOpc: Opc, MovOpc: Mips::MTC1, IsI64: true);
428 break;
429 case Mips::PseudoCVT_D64_L:
430 expandCvtFPInt(MBB, I: MI, CvtOpc: Mips::CVT_D64_L, MovOpc: Mips::DMTC1, IsI64: true);
431 break;
432 case Mips::BuildPairF64:
433 expandBuildPairF64(MBB, I: MI, isMicroMips, FP64: false);
434 break;
435 case Mips::BuildPairF64_FPR:
436 MI.eraseFromParent();
437 return true;
438 case Mips::BuildPairF64_64:
439 expandBuildPairF64(MBB, I: MI, isMicroMips, FP64: true);
440 break;
441 case Mips::ExtractElementF64:
442 expandExtractElementF64(MBB, I: MI, isMicroMips, FP64: false);
443 break;
444 case Mips::ExtractElementF64_64:
445 expandExtractElementF64(MBB, I: MI, isMicroMips, FP64: true);
446 break;
447 case Mips::MIPSeh_return32:
448 case Mips::MIPSeh_return64:
449 expandEhReturn(MBB, I: MI);
450 break;
451 }
452
453 MBB.erase(I: MI);
454 return true;
455}
456
457/// isBranchWithImm - Return true if the branch contains an immediate
458/// operand (\see lib/Target/Mips/MipsBranchExpansion.cpp).
459bool MipsSEInstrInfo::isBranchWithImm(unsigned Opc) const {
460 switch (Opc) {
461 default:
462 return false;
463 case Mips::BBIT0:
464 case Mips::BBIT1:
465 case Mips::BBIT032:
466 case Mips::BBIT132:
467 return true;
468 }
469}
470
471/// getOppositeBranchOpc - Return the inverse of the specified
472/// opcode, e.g. turning BEQ to BNE.
473unsigned MipsSEInstrInfo::getOppositeBranchOpc(unsigned Opc) const {
474 switch (Opc) {
475 default: llvm_unreachable("Illegal opcode!");
476 case Mips::BEQ: return Mips::BNE;
477 case Mips::BEQ_MM: return Mips::BNE_MM;
478 case Mips::BNE: return Mips::BEQ;
479 case Mips::BNE_MM: return Mips::BEQ_MM;
480 case Mips::BGTZ: return Mips::BLEZ;
481 case Mips::BGEZ: return Mips::BLTZ;
482 case Mips::BLTZ: return Mips::BGEZ;
483 case Mips::BLEZ: return Mips::BGTZ;
484 case Mips::BGTZ_MM: return Mips::BLEZ_MM;
485 case Mips::BGEZ_MM: return Mips::BLTZ_MM;
486 case Mips::BLTZ_MM: return Mips::BGEZ_MM;
487 case Mips::BLEZ_MM: return Mips::BGTZ_MM;
488 case Mips::BEQ64: return Mips::BNE64;
489 case Mips::BNE64: return Mips::BEQ64;
490 case Mips::BGTZ64: return Mips::BLEZ64;
491 case Mips::BGEZ64: return Mips::BLTZ64;
492 case Mips::BLTZ64: return Mips::BGEZ64;
493 case Mips::BLEZ64: return Mips::BGTZ64;
494 case Mips::BC1T: return Mips::BC1F;
495 case Mips::BC1F: return Mips::BC1T;
496 case Mips::BC1T_MM: return Mips::BC1F_MM;
497 case Mips::BC1F_MM: return Mips::BC1T_MM;
498 case Mips::BEQZ16_MM: return Mips::BNEZ16_MM;
499 case Mips::BNEZ16_MM: return Mips::BEQZ16_MM;
500 case Mips::BEQZC_MM: return Mips::BNEZC_MM;
501 case Mips::BNEZC_MM: return Mips::BEQZC_MM;
502 case Mips::BEQZC: return Mips::BNEZC;
503 case Mips::BNEZC: return Mips::BEQZC;
504 case Mips::BLEZC: return Mips::BGTZC;
505 case Mips::BGEZC: return Mips::BLTZC;
506 case Mips::BGEC: return Mips::BLTC;
507 case Mips::BGTZC: return Mips::BLEZC;
508 case Mips::BLTZC: return Mips::BGEZC;
509 case Mips::BLTC: return Mips::BGEC;
510 case Mips::BGEUC: return Mips::BLTUC;
511 case Mips::BLTUC: return Mips::BGEUC;
512 case Mips::BEQC: return Mips::BNEC;
513 case Mips::BNEC: return Mips::BEQC;
514 case Mips::BC1EQZ: return Mips::BC1NEZ;
515 case Mips::BC1NEZ: return Mips::BC1EQZ;
516 case Mips::BEQZC_MMR6: return Mips::BNEZC_MMR6;
517 case Mips::BNEZC_MMR6: return Mips::BEQZC_MMR6;
518 case Mips::BLEZC_MMR6: return Mips::BGTZC_MMR6;
519 case Mips::BGEZC_MMR6: return Mips::BLTZC_MMR6;
520 case Mips::BGEC_MMR6: return Mips::BLTC_MMR6;
521 case Mips::BGTZC_MMR6: return Mips::BLEZC_MMR6;
522 case Mips::BLTZC_MMR6: return Mips::BGEZC_MMR6;
523 case Mips::BLTC_MMR6: return Mips::BGEC_MMR6;
524 case Mips::BGEUC_MMR6: return Mips::BLTUC_MMR6;
525 case Mips::BLTUC_MMR6: return Mips::BGEUC_MMR6;
526 case Mips::BEQC_MMR6: return Mips::BNEC_MMR6;
527 case Mips::BNEC_MMR6: return Mips::BEQC_MMR6;
528 case Mips::BC1EQZC_MMR6: return Mips::BC1NEZC_MMR6;
529 case Mips::BC1NEZC_MMR6: return Mips::BC1EQZC_MMR6;
530 case Mips::BEQZC64: return Mips::BNEZC64;
531 case Mips::BNEZC64: return Mips::BEQZC64;
532 case Mips::BEQC64: return Mips::BNEC64;
533 case Mips::BNEC64: return Mips::BEQC64;
534 case Mips::BGEC64: return Mips::BLTC64;
535 case Mips::BGEUC64: return Mips::BLTUC64;
536 case Mips::BLTC64: return Mips::BGEC64;
537 case Mips::BLTUC64: return Mips::BGEUC64;
538 case Mips::BGTZC64: return Mips::BLEZC64;
539 case Mips::BGEZC64: return Mips::BLTZC64;
540 case Mips::BLTZC64: return Mips::BGEZC64;
541 case Mips::BLEZC64: return Mips::BGTZC64;
542 case Mips::BBIT0: return Mips::BBIT1;
543 case Mips::BBIT1: return Mips::BBIT0;
544 case Mips::BBIT032: return Mips::BBIT132;
545 case Mips::BBIT132: return Mips::BBIT032;
546 case Mips::BZ_B: return Mips::BNZ_B;
547 case Mips::BZ_H: return Mips::BNZ_H;
548 case Mips::BZ_W: return Mips::BNZ_W;
549 case Mips::BZ_D: return Mips::BNZ_D;
550 case Mips::BZ_V: return Mips::BNZ_V;
551 case Mips::BNZ_B: return Mips::BZ_B;
552 case Mips::BNZ_H: return Mips::BZ_H;
553 case Mips::BNZ_W: return Mips::BZ_W;
554 case Mips::BNZ_D: return Mips::BZ_D;
555 case Mips::BNZ_V: return Mips::BZ_V;
556 }
557}
558
559/// Adjust SP by Amount bytes.
560void MipsSEInstrInfo::adjustStackPtr(unsigned SP, int64_t Amount,
561 MachineBasicBlock &MBB,
562 MachineBasicBlock::iterator I) const {
563 MipsABIInfo ABI = Subtarget.getABI();
564 DebugLoc DL;
565 unsigned ADDiu = ABI.GetPtrAddiuOp();
566
567 if (Amount == 0)
568 return;
569
570 if (isInt<16>(x: Amount)) {
571 // addi sp, sp, amount
572 BuildMI(BB&: MBB, I, MIMD: DL, MCID: get(Opcode: ADDiu), DestReg: SP).addReg(RegNo: SP).addImm(Val: Amount);
573 } else {
574 // For numbers which are not 16bit integers we synthesize Amount inline
575 // then add or subtract it from sp.
576 unsigned Opc = ABI.GetPtrAdduOp();
577 if (Amount < 0) {
578 Opc = ABI.GetPtrSubuOp();
579 Amount = -Amount;
580 }
581 unsigned Reg = loadImmediate(Imm: Amount, MBB, II: I, DL, NewImm: nullptr);
582 BuildMI(BB&: MBB, I, MIMD: DL, MCID: get(Opcode: Opc), DestReg: SP).addReg(RegNo: SP).addReg(RegNo: Reg, Flags: RegState::Kill);
583 }
584}
585
586/// This function generates the sequence of instructions needed to get the
587/// result of adding register REG and immediate IMM.
588unsigned MipsSEInstrInfo::loadImmediate(int64_t Imm, MachineBasicBlock &MBB,
589 MachineBasicBlock::iterator II,
590 const DebugLoc &DL,
591 unsigned *NewImm) const {
592 MipsAnalyzeImmediate AnalyzeImm;
593 const MipsSubtarget &STI = Subtarget;
594 MachineRegisterInfo &RegInfo = MBB.getParent()->getRegInfo();
595 unsigned Size = STI.isABI_N64() ? 64 : 32;
596 unsigned LUi = STI.isABI_N64() ? Mips::LUi64 : Mips::LUi;
597 unsigned ZEROReg = STI.isABI_N64() ? Mips::R0_64 : Mips::R0;
598 const TargetRegisterClass *RC = STI.isABI_N64() ?
599 &Mips::GPR64RegClass : &Mips::GPR32RegClass;
600 bool LastInstrIsADDiu = NewImm;
601
602 const MipsAnalyzeImmediate::InstSeq &Seq =
603 AnalyzeImm.Analyze(Imm, Size, LastInstrIsADDiu);
604 MipsAnalyzeImmediate::InstSeq::const_iterator Inst = Seq.begin();
605
606 assert(Seq.size() && (!LastInstrIsADDiu || (Seq.size() > 1)));
607
608 // The first instruction can be a LUi, which is different from other
609 // instructions (ADDiu, ORI and SLL) in that it does not have a register
610 // operand.
611 Register Reg = RegInfo.createVirtualRegister(RegClass: RC);
612
613 if (Inst->Opc == LUi)
614 BuildMI(BB&: MBB, I: II, MIMD: DL, MCID: get(Opcode: LUi), DestReg: Reg).addImm(Val: SignExtend64<16>(x: Inst->ImmOpnd));
615 else
616 BuildMI(BB&: MBB, I: II, MIMD: DL, MCID: get(Opcode: Inst->Opc), DestReg: Reg).addReg(RegNo: ZEROReg)
617 .addImm(Val: SignExtend64<16>(x: Inst->ImmOpnd));
618
619 // Build the remaining instructions in Seq.
620 for (++Inst; Inst != Seq.end() - LastInstrIsADDiu; ++Inst)
621 BuildMI(BB&: MBB, I: II, MIMD: DL, MCID: get(Opcode: Inst->Opc), DestReg: Reg).addReg(RegNo: Reg, Flags: RegState::Kill)
622 .addImm(Val: SignExtend64<16>(x: Inst->ImmOpnd));
623
624 if (LastInstrIsADDiu)
625 *NewImm = Inst->ImmOpnd;
626
627 return Reg;
628}
629
630unsigned MipsSEInstrInfo::getAnalyzableBrOpc(unsigned Opc) const {
631 return (Opc == Mips::BEQ || Opc == Mips::BEQ_MM || Opc == Mips::BNE ||
632 Opc == Mips::BNE_MM || Opc == Mips::BGTZ || Opc == Mips::BGEZ ||
633 Opc == Mips::BLTZ || Opc == Mips::BLEZ || Opc == Mips::BEQ64 ||
634 Opc == Mips::BNE64 || Opc == Mips::BGTZ64 || Opc == Mips::BGEZ64 ||
635 Opc == Mips::BLTZ64 || Opc == Mips::BLEZ64 || Opc == Mips::BC1T ||
636 Opc == Mips::BC1F || Opc == Mips::B || Opc == Mips::J ||
637 Opc == Mips::J_MM || Opc == Mips::B_MM || Opc == Mips::BEQZC_MM ||
638 Opc == Mips::BNEZC_MM || Opc == Mips::BEQC || Opc == Mips::BNEC ||
639 Opc == Mips::BLTC || Opc == Mips::BGEC || Opc == Mips::BLTUC ||
640 Opc == Mips::BGEUC || Opc == Mips::BGTZC || Opc == Mips::BLEZC ||
641 Opc == Mips::BGEZC || Opc == Mips::BLTZC || Opc == Mips::BEQZC ||
642 Opc == Mips::BNEZC || Opc == Mips::BEQZC64 || Opc == Mips::BNEZC64 ||
643 Opc == Mips::BEQC64 || Opc == Mips::BNEC64 || Opc == Mips::BGEC64 ||
644 Opc == Mips::BGEUC64 || Opc == Mips::BLTC64 || Opc == Mips::BLTUC64 ||
645 Opc == Mips::BGTZC64 || Opc == Mips::BGEZC64 ||
646 Opc == Mips::BLTZC64 || Opc == Mips::BLEZC64 || Opc == Mips::BC ||
647 Opc == Mips::BC1EQZ || Opc == Mips::BC1NEZ || Opc == Mips::BBIT0 ||
648 Opc == Mips::BBIT1 || Opc == Mips::BBIT032 || Opc == Mips::BBIT132 ||
649 Opc == Mips::BC_MMR6 || Opc == Mips::BEQC_MMR6 ||
650 Opc == Mips::BNEC_MMR6 || Opc == Mips::BLTC_MMR6 ||
651 Opc == Mips::BGEC_MMR6 || Opc == Mips::BLTUC_MMR6 ||
652 Opc == Mips::BGEUC_MMR6 || Opc == Mips::BGTZC_MMR6 ||
653 Opc == Mips::BLEZC_MMR6 || Opc == Mips::BGEZC_MMR6 ||
654 Opc == Mips::BLTZC_MMR6 || Opc == Mips::BEQZC_MMR6 ||
655 Opc == Mips::BNEZC_MMR6 || Opc == Mips::BC1EQZC_MMR6 ||
656 Opc == Mips::BC1NEZC_MMR6)
657 ? Opc
658 : 0;
659}
660
661void MipsSEInstrInfo::expandRetRA(MachineBasicBlock &MBB,
662 MachineBasicBlock::iterator I) const {
663
664 MachineInstrBuilder MIB;
665 if (Subtarget.isGP64bit())
666 MIB = BuildMI(BB&: MBB, I, MIMD: I->getDebugLoc(), MCID: get(Opcode: Mips::PseudoReturn64))
667 .addReg(RegNo: Mips::RA_64, Flags: RegState::Undef);
668 else
669 MIB = BuildMI(BB&: MBB, I, MIMD: I->getDebugLoc(), MCID: get(Opcode: Mips::PseudoReturn))
670 .addReg(RegNo: Mips::RA, Flags: RegState::Undef);
671
672 // Retain any imp-use flags.
673 for (auto & MO : I->operands()) {
674 if (MO.isImplicit())
675 MIB.add(MO);
676 }
677}
678
679void MipsSEInstrInfo::expandERet(MachineBasicBlock &MBB,
680 MachineBasicBlock::iterator I) const {
681 BuildMI(BB&: MBB, I, MIMD: I->getDebugLoc(), MCID: get(Opcode: Mips::ERET));
682}
683
684std::pair<bool, bool>
685MipsSEInstrInfo::compareOpndSize(unsigned Opc,
686 const MachineFunction &MF) const {
687 const MCInstrDesc &Desc = get(Opcode: Opc);
688 assert(Desc.NumOperands == 2 && "Unary instruction expected.");
689 const MipsRegisterInfo *RI = &getRegisterInfo();
690 unsigned DstRegSize = RI->getRegSizeInBits(RC: *getRegClass(MCID: Desc, OpNum: 0));
691 unsigned SrcRegSize = RI->getRegSizeInBits(RC: *getRegClass(MCID: Desc, OpNum: 1));
692
693 return std::make_pair(x: DstRegSize > SrcRegSize, y: DstRegSize < SrcRegSize);
694}
695
696void MipsSEInstrInfo::expandPseudoMFHiLo(MachineBasicBlock &MBB,
697 MachineBasicBlock::iterator I,
698 unsigned NewOpc) const {
699 BuildMI(BB&: MBB, I, MIMD: I->getDebugLoc(), MCID: get(Opcode: NewOpc), DestReg: I->getOperand(i: 0).getReg());
700}
701
702void MipsSEInstrInfo::expandPseudoMTLoHi(MachineBasicBlock &MBB,
703 MachineBasicBlock::iterator I,
704 unsigned LoOpc,
705 unsigned HiOpc,
706 bool HasExplicitDef) const {
707 // Expand
708 // lo_hi pseudomtlohi $gpr0, $gpr1
709 // to these two instructions:
710 // mtlo $gpr0
711 // mthi $gpr1
712
713 DebugLoc DL = I->getDebugLoc();
714 const MachineOperand &SrcLo = I->getOperand(i: 1), &SrcHi = I->getOperand(i: 2);
715 MachineInstrBuilder LoInst = BuildMI(BB&: MBB, I, MIMD: DL, MCID: get(Opcode: LoOpc));
716 MachineInstrBuilder HiInst = BuildMI(BB&: MBB, I, MIMD: DL, MCID: get(Opcode: HiOpc));
717
718 // Add lo/hi registers if the mtlo/hi instructions created have explicit
719 // def registers.
720 if (HasExplicitDef) {
721 Register DstReg = I->getOperand(i: 0).getReg();
722 Register DstLo = getRegisterInfo().getSubReg(Reg: DstReg, Idx: Mips::sub_lo);
723 Register DstHi = getRegisterInfo().getSubReg(Reg: DstReg, Idx: Mips::sub_hi);
724 LoInst.addReg(RegNo: DstLo, Flags: RegState::Define);
725 HiInst.addReg(RegNo: DstHi, Flags: RegState::Define);
726 }
727
728 LoInst.addReg(RegNo: SrcLo.getReg(), Flags: getKillRegState(B: SrcLo.isKill()));
729 HiInst.addReg(RegNo: SrcHi.getReg(), Flags: getKillRegState(B: SrcHi.isKill()));
730}
731
732void MipsSEInstrInfo::expandCvtFPInt(MachineBasicBlock &MBB,
733 MachineBasicBlock::iterator I,
734 unsigned CvtOpc, unsigned MovOpc,
735 bool IsI64) const {
736 const MCInstrDesc &CvtDesc = get(Opcode: CvtOpc), &MovDesc = get(Opcode: MovOpc);
737 const MachineOperand &Dst = I->getOperand(i: 0), &Src = I->getOperand(i: 1);
738 unsigned DstReg = Dst.getReg(), SrcReg = Src.getReg(), TmpReg = DstReg;
739 RegState KillSrc = getKillRegState(B: Src.isKill());
740 DebugLoc DL = I->getDebugLoc();
741 bool DstIsLarger, SrcIsLarger;
742
743 std::tie(args&: DstIsLarger, args&: SrcIsLarger) =
744 compareOpndSize(Opc: CvtOpc, MF: *MBB.getParent());
745
746 if (DstIsLarger)
747 TmpReg = getRegisterInfo().getSubReg(Reg: DstReg, Idx: Mips::sub_lo);
748
749 if (SrcIsLarger)
750 DstReg = getRegisterInfo().getSubReg(Reg: DstReg, Idx: Mips::sub_lo);
751
752 BuildMI(BB&: MBB, I, MIMD: DL, MCID: MovDesc, DestReg: TmpReg).addReg(RegNo: SrcReg, Flags: KillSrc);
753 BuildMI(BB&: MBB, I, MIMD: DL, MCID: CvtDesc, DestReg: DstReg).addReg(RegNo: TmpReg, Flags: RegState::Kill);
754}
755
756void MipsSEInstrInfo::expandExtractElementF64(MachineBasicBlock &MBB,
757 MachineBasicBlock::iterator I,
758 bool isMicroMips,
759 bool FP64) const {
760 Register DstReg = I->getOperand(i: 0).getReg();
761 Register SrcReg = I->getOperand(i: 1).getReg();
762 unsigned N = I->getOperand(i: 2).getImm();
763 DebugLoc dl = I->getDebugLoc();
764
765 assert(N < 2 && "Invalid immediate");
766 unsigned SubIdx = N ? Mips::sub_hi : Mips::sub_lo;
767 Register SubReg = getRegisterInfo().getSubReg(Reg: SrcReg, Idx: SubIdx);
768
769 // FPXX/FP64 without MFHC1 should have been handled with a spill/reload
770 // in MipsSEFrameLowering.cpp.
771 assert(!((Subtarget.isABI_FPXX() || FP64) && !Subtarget.hasMTHC1()));
772
773 // FP64A (FP64 with nooddspreg) should have been handled with a spill/reload
774 // in MipsSEFrameLowering.cpp.
775 assert(!(Subtarget.isFP64bit() && !Subtarget.useOddSPReg()));
776
777 if (SubIdx == Mips::sub_hi && Subtarget.hasMTHC1()) {
778 // FIXME: Strictly speaking MFHC1 only reads the top 32-bits however, we
779 // claim to read the whole 64-bits as part of a white lie used to
780 // temporarily work around a widespread bug in the -mfp64 support.
781 // The problem is that none of the 32-bit fpu ops mention the fact
782 // that they clobber the upper 32-bits of the 64-bit FPR. Fixing that
783 // requires a major overhaul of the FPU implementation which can't
784 // be done right now due to time constraints.
785 // MFHC1 is one of two instructions that are affected since they are
786 // the only instructions that don't read the lower 32-bits.
787 // We therefore pretend that it reads the bottom 32-bits to
788 // artificially create a dependency and prevent the scheduler
789 // changing the behaviour of the code.
790 BuildMI(BB&: MBB, I, MIMD: dl,
791 MCID: get(Opcode: isMicroMips ? (FP64 ? Mips::MFHC1_D64_MM : Mips::MFHC1_D32_MM)
792 : (FP64 ? Mips::MFHC1_D64 : Mips::MFHC1_D32)),
793 DestReg: DstReg)
794 .addReg(RegNo: SrcReg);
795 } else
796 BuildMI(BB&: MBB, I, MIMD: dl, MCID: get(Opcode: Mips::MFC1), DestReg: DstReg).addReg(RegNo: SubReg);
797}
798
799void MipsSEInstrInfo::expandBuildPairF64(MachineBasicBlock &MBB,
800 MachineBasicBlock::iterator I,
801 bool isMicroMips, bool FP64) const {
802 Register DstReg = I->getOperand(i: 0).getReg();
803 unsigned LoReg = I->getOperand(i: 1).getReg(), HiReg = I->getOperand(i: 2).getReg();
804 const MCInstrDesc& Mtc1Tdd = get(Opcode: Mips::MTC1);
805 DebugLoc dl = I->getDebugLoc();
806 const TargetRegisterInfo &TRI = getRegisterInfo();
807
808 // When mthc1 is available, use:
809 // mtc1 Lo, $fp
810 // mthc1 Hi, $fp
811 //
812 // Otherwise, for FPXX/FP64:
813 // spill + reload via ldc1
814 // This case is handled by the frame lowering code.
815 //
816 // Otherwise, for FP32:
817 // mtc1 Lo, $fp
818 // mtc1 Hi, $fp + 1
819 //
820 // The case where 64-bit GPRs can be used doesn't need to be handled here
821 // because it never creates a BuildPairF64 node.
822
823 // FPXX/FP64 without MTHC1 should have been handled with a spill/reload
824 // in MipsSEFrameLowering.cpp.
825 assert(!((Subtarget.isABI_FPXX() || FP64) && !Subtarget.hasMTHC1()));
826
827 // FP64A (FP64 with nooddspreg) should have been handled with a spill/reload
828 // in MipsSEFrameLowering.cpp.
829 assert(!(Subtarget.isFP64bit() && !Subtarget.useOddSPReg()));
830
831 BuildMI(BB&: MBB, I, MIMD: dl, MCID: Mtc1Tdd, DestReg: TRI.getSubReg(Reg: DstReg, Idx: Mips::sub_lo))
832 .addReg(RegNo: LoReg);
833
834 if (Subtarget.hasMTHC1()) {
835 // FIXME: The .addReg(DstReg) is a white lie used to temporarily work
836 // around a widespread bug in the -mfp64 support.
837 // The problem is that none of the 32-bit fpu ops mention the fact
838 // that they clobber the upper 32-bits of the 64-bit FPR. Fixing that
839 // requires a major overhaul of the FPU implementation which can't
840 // be done right now due to time constraints.
841 // MTHC1 is one of two instructions that are affected since they are
842 // the only instructions that don't read the lower 32-bits.
843 // We therefore pretend that it reads the bottom 32-bits to
844 // artificially create a dependency and prevent the scheduler
845 // changing the behaviour of the code.
846 BuildMI(BB&: MBB, I, MIMD: dl,
847 MCID: get(Opcode: isMicroMips ? (FP64 ? Mips::MTHC1_D64_MM : Mips::MTHC1_D32_MM)
848 : (FP64 ? Mips::MTHC1_D64 : Mips::MTHC1_D32)),
849 DestReg: DstReg)
850 .addReg(RegNo: DstReg)
851 .addReg(RegNo: HiReg);
852 } else if (Subtarget.isABI_FPXX())
853 llvm_unreachable("BuildPairF64 not expanded in frame lowering code!");
854 else
855 BuildMI(BB&: MBB, I, MIMD: dl, MCID: Mtc1Tdd, DestReg: TRI.getSubReg(Reg: DstReg, Idx: Mips::sub_hi))
856 .addReg(RegNo: HiReg);
857}
858
859void MipsSEInstrInfo::expandEhReturn(MachineBasicBlock &MBB,
860 MachineBasicBlock::iterator I) const {
861 // This pseudo instruction is generated as part of the lowering of
862 // ISD::EH_RETURN. We convert it to a stack increment by OffsetReg, and
863 // indirect jump to TargetReg
864 MipsABIInfo ABI = Subtarget.getABI();
865 unsigned ADDU = ABI.GetPtrAdduOp();
866 unsigned SP = Subtarget.isGP64bit() ? Mips::SP_64 : Mips::SP;
867 unsigned RA = Subtarget.isGP64bit() ? Mips::RA_64 : Mips::RA;
868 unsigned T9 = ABI.getTempReg(I: 9, Is64Bit: Subtarget.isGP64bit());
869 unsigned ZERO = Subtarget.isGP64bit() ? Mips::R0_64 : Mips::R0;
870 Register OffsetReg = I->getOperand(i: 0).getReg();
871 Register TargetReg = I->getOperand(i: 1).getReg();
872
873 // addu $ra, $v0, $zero
874 // addu $sp, $sp, $v1
875 // jr $ra (via RetRA)
876 const TargetMachine &TM = MBB.getParent()->getTarget();
877 if (TM.isPositionIndependent())
878 BuildMI(BB&: MBB, I, MIMD: I->getDebugLoc(), MCID: get(Opcode: ADDU), DestReg: T9)
879 .addReg(RegNo: TargetReg)
880 .addReg(RegNo: ZERO);
881 BuildMI(BB&: MBB, I, MIMD: I->getDebugLoc(), MCID: get(Opcode: ADDU), DestReg: RA)
882 .addReg(RegNo: TargetReg)
883 .addReg(RegNo: ZERO);
884 BuildMI(BB&: MBB, I, MIMD: I->getDebugLoc(), MCID: get(Opcode: ADDU), DestReg: SP).addReg(RegNo: SP).addReg(RegNo: OffsetReg);
885 expandRetRA(MBB, I);
886}
887
888const MipsInstrInfo *llvm::createMipsSEInstrInfo(const MipsSubtarget &STI) {
889 return new MipsSEInstrInfo(STI);
890}
891