LLVM 24.0.0git
PPCRegisterInfo.cpp
Go to the documentation of this file.
1//===-- PPCRegisterInfo.cpp - PowerPC 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 PowerPC implementation of the TargetRegisterInfo
10// class.
11//
12//===----------------------------------------------------------------------===//
13
14#include "PPCRegisterInfo.h"
15#include "PPCFrameLowering.h"
16#include "PPCInstrBuilder.h"
18#include "PPCSubtarget.h"
19#include "PPCTargetMachine.h"
20#include "llvm/ADT/BitVector.h"
21#include "llvm/ADT/Statistic.h"
31#include "llvm/IR/CallingConv.h"
32#include "llvm/IR/Function.h"
33#include "llvm/IR/Type.h"
34#include "llvm/Support/Debug.h"
40
41using namespace llvm;
42
43#define DEBUG_TYPE "reginfo"
44
45#define GET_REGINFO_TARGET_DESC
46#include "PPCGenRegisterInfo.inc"
47
48STATISTIC(InflateGPRC, "Number of gprc inputs for getLargestLegalClass");
49STATISTIC(InflateGP8RC, "Number of g8rc inputs for getLargestLegalClass");
50
51static unsigned offsetMinAlignForOpcode(unsigned OpC);
52
53#ifndef NDEBUG
55 return MBB.getParent()
56 ->getSubtarget<PPCSubtarget>()
57 .getCLOpts()
58 .report_acc_moves;
59}
60#endif
61
63 : PPCGenRegisterInfo(TM.isPPC64() ? PPC::LR8 : PPC::LR,
64 TM.isPPC64() ? 0 : 1,
65 TM.isPPC64() ? 0 : 1),
66 TM(TM) {
67 ImmToIdxMap[PPC::LD] = PPC::LDX; ImmToIdxMap[PPC::STD] = PPC::STDX;
68 ImmToIdxMap[PPC::LBZ] = PPC::LBZX; ImmToIdxMap[PPC::STB] = PPC::STBX;
69 ImmToIdxMap[PPC::LHZ] = PPC::LHZX; ImmToIdxMap[PPC::LHA] = PPC::LHAX;
70 ImmToIdxMap[PPC::LWZ] = PPC::LWZX; ImmToIdxMap[PPC::LWA] = PPC::LWAX;
71 ImmToIdxMap[PPC::LFS] = PPC::LFSX; ImmToIdxMap[PPC::LFD] = PPC::LFDX;
72 ImmToIdxMap[PPC::STH] = PPC::STHX; ImmToIdxMap[PPC::STW] = PPC::STWX;
73 ImmToIdxMap[PPC::STFS] = PPC::STFSX; ImmToIdxMap[PPC::STFD] = PPC::STFDX;
74 ImmToIdxMap[PPC::ADDI] = PPC::ADD4;
75 ImmToIdxMap[PPC::LWA_32] = PPC::LWAX_32;
76
77 // 64-bit
78 ImmToIdxMap[PPC::LHA8] = PPC::LHAX8; ImmToIdxMap[PPC::LBZ8] = PPC::LBZX8;
79 ImmToIdxMap[PPC::LHZ8] = PPC::LHZX8; ImmToIdxMap[PPC::LWZ8] = PPC::LWZX8;
80 ImmToIdxMap[PPC::STB8] = PPC::STBX8; ImmToIdxMap[PPC::STH8] = PPC::STHX8;
81 ImmToIdxMap[PPC::STW8] = PPC::STWX8; ImmToIdxMap[PPC::STDU] = PPC::STDUX;
82 ImmToIdxMap[PPC::ADDI8] = PPC::ADD8;
83 ImmToIdxMap[PPC::LQ] = PPC::LQX_PSEUDO;
84 ImmToIdxMap[PPC::STQ] = PPC::STQX_PSEUDO;
85
86 // VSX
87 ImmToIdxMap[PPC::DFLOADf32] = PPC::LXSSPX;
88 ImmToIdxMap[PPC::DFLOADf64] = PPC::LXSDX;
89 ImmToIdxMap[PPC::SPILLTOVSR_LD] = PPC::SPILLTOVSR_LDX;
90 ImmToIdxMap[PPC::SPILLTOVSR_ST] = PPC::SPILLTOVSR_STX;
91 ImmToIdxMap[PPC::DFSTOREf32] = PPC::STXSSPX;
92 ImmToIdxMap[PPC::DFSTOREf64] = PPC::STXSDX;
93 ImmToIdxMap[PPC::LXV] = PPC::LXVX;
94 ImmToIdxMap[PPC::LXSD] = PPC::LXSDX;
95 ImmToIdxMap[PPC::LXSSP] = PPC::LXSSPX;
96 ImmToIdxMap[PPC::STXV] = PPC::STXVX;
97 ImmToIdxMap[PPC::STXSD] = PPC::STXSDX;
98 ImmToIdxMap[PPC::STXSSP] = PPC::STXSSPX;
99
100 // SPE
101 ImmToIdxMap[PPC::EVLDD] = PPC::EVLDDX;
102 ImmToIdxMap[PPC::EVSTDD] = PPC::EVSTDDX;
103 ImmToIdxMap[PPC::SPESTW] = PPC::SPESTWX;
104 ImmToIdxMap[PPC::SPELWZ] = PPC::SPELWZX;
105
106 // Power10
107 ImmToIdxMap[PPC::PLBZ] = PPC::LBZX; ImmToIdxMap[PPC::PLBZ8] = PPC::LBZX8;
108 ImmToIdxMap[PPC::PLHZ] = PPC::LHZX; ImmToIdxMap[PPC::PLHZ8] = PPC::LHZX8;
109 ImmToIdxMap[PPC::PLHA] = PPC::LHAX; ImmToIdxMap[PPC::PLHA8] = PPC::LHAX8;
110 ImmToIdxMap[PPC::PLWZ] = PPC::LWZX; ImmToIdxMap[PPC::PLWZ8] = PPC::LWZX8;
111 ImmToIdxMap[PPC::PLWA] = PPC::LWAX; ImmToIdxMap[PPC::PLWA8] = PPC::LWAX;
112 ImmToIdxMap[PPC::PLD] = PPC::LDX; ImmToIdxMap[PPC::PSTD] = PPC::STDX;
113
114 ImmToIdxMap[PPC::PSTB] = PPC::STBX; ImmToIdxMap[PPC::PSTB8] = PPC::STBX8;
115 ImmToIdxMap[PPC::PSTH] = PPC::STHX; ImmToIdxMap[PPC::PSTH8] = PPC::STHX8;
116 ImmToIdxMap[PPC::PSTW] = PPC::STWX; ImmToIdxMap[PPC::PSTW8] = PPC::STWX8;
117
118 ImmToIdxMap[PPC::PLFS] = PPC::LFSX; ImmToIdxMap[PPC::PSTFS] = PPC::STFSX;
119 ImmToIdxMap[PPC::PLFD] = PPC::LFDX; ImmToIdxMap[PPC::PSTFD] = PPC::STFDX;
120 ImmToIdxMap[PPC::PLXSSP] = PPC::LXSSPX; ImmToIdxMap[PPC::PSTXSSP] = PPC::STXSSPX;
121 ImmToIdxMap[PPC::PLXSD] = PPC::LXSDX; ImmToIdxMap[PPC::PSTXSD] = PPC::STXSDX;
122 ImmToIdxMap[PPC::PLXV] = PPC::LXVX; ImmToIdxMap[PPC::PSTXV] = PPC::STXVX;
123
124 ImmToIdxMap[PPC::LXVP] = PPC::LXVPX;
125 ImmToIdxMap[PPC::STXVP] = PPC::STXVPX;
126 ImmToIdxMap[PPC::PLXVP] = PPC::LXVPX;
127 ImmToIdxMap[PPC::PSTXVP] = PPC::STXVPX;
128}
129
130const MCPhysReg*
134 if (!TM.isPPC64() && Subtarget.isAIXABI())
135 report_fatal_error("AnyReg unimplemented on 32-bit AIX.");
136 if (Subtarget.hasVSX()) {
137 if (Subtarget.pairedVectorMemops())
138 return CSR_64_AllRegs_VSRP_SaveList;
139 if (Subtarget.isAIXABI() && !Subtarget.isAIXExtendedAltivecABI())
140 return CSR_64_AllRegs_AIX_Dflt_VSX_SaveList;
141 return CSR_64_AllRegs_VSX_SaveList;
142 }
143 if (Subtarget.hasAltivec()) {
144 if (Subtarget.isAIXABI() && !Subtarget.isAIXExtendedAltivecABI())
145 return CSR_64_AllRegs_AIX_Dflt_Altivec_SaveList;
146 return CSR_64_AllRegs_Altivec_SaveList;
147 }
148 return CSR_64_AllRegs_SaveList;
149 }
150
151 // On PPC64, we might need to save r2 (but only if it is not reserved).
152 // We do not need to treat R2 as callee-saved when using PC-Relative calls
153 // because any direct uses of R2 will cause it to be reserved. If the function
154 // is a leaf or the only uses of R2 are implicit uses for calls, the calls
155 // will use the @notoc relocation which will cause this function to set the
156 // st_other bit to 1, thereby communicating to its caller that it arbitrarily
157 // clobbers the TOC.
158 bool SaveR2 = MF->getRegInfo().isAllocatable(PPC::X2) &&
159 !Subtarget.isUsingPCRelativeCalls();
160
161 // Cold calling convention CSRs.
163 if (Subtarget.isAIXABI())
164 report_fatal_error("Cold calling unimplemented on AIX.");
165 if (TM.isPPC64()) {
166 if (Subtarget.pairedVectorMemops())
167 return SaveR2 ? CSR_SVR64_ColdCC_R2_VSRP_SaveList
168 : CSR_SVR64_ColdCC_VSRP_SaveList;
169 if (Subtarget.hasAltivec())
170 return SaveR2 ? CSR_SVR64_ColdCC_R2_Altivec_SaveList
171 : CSR_SVR64_ColdCC_Altivec_SaveList;
172 return SaveR2 ? CSR_SVR64_ColdCC_R2_SaveList
173 : CSR_SVR64_ColdCC_SaveList;
174 }
175 // 32-bit targets.
176 if (Subtarget.pairedVectorMemops())
177 return CSR_SVR32_ColdCC_VSRP_SaveList;
178 else if (Subtarget.hasAltivec())
179 return CSR_SVR32_ColdCC_Altivec_SaveList;
180 else if (Subtarget.hasSPE())
181 return CSR_SVR32_ColdCC_SPE_SaveList;
182 return CSR_SVR32_ColdCC_SaveList;
183 }
184 // Standard calling convention CSRs.
185 if (TM.isPPC64()) {
186 if (Subtarget.pairedVectorMemops()) {
187 if (Subtarget.isAIXABI()) {
188 if (!Subtarget.isAIXExtendedAltivecABI())
189 return SaveR2 ? CSR_PPC64_R2_SaveList : CSR_PPC64_SaveList;
190 return SaveR2 ? CSR_AIX64_R2_VSRP_SaveList : CSR_AIX64_VSRP_SaveList;
191 }
192 return SaveR2 ? CSR_SVR464_R2_VSRP_SaveList : CSR_SVR464_VSRP_SaveList;
193 }
194 if (Subtarget.hasAltivec() &&
195 (!Subtarget.isAIXABI() || Subtarget.isAIXExtendedAltivecABI())) {
196 return SaveR2 ? CSR_PPC64_R2_Altivec_SaveList
197 : CSR_PPC64_Altivec_SaveList;
198 }
199 return SaveR2 ? CSR_PPC64_R2_SaveList : CSR_PPC64_SaveList;
200 }
201 // 32-bit targets.
202 if (Subtarget.isAIXABI()) {
203 if (Subtarget.pairedVectorMemops())
204 return Subtarget.isAIXExtendedAltivecABI() ? CSR_AIX32_VSRP_SaveList
205 : CSR_AIX32_SaveList;
206 if (Subtarget.hasAltivec())
207 return Subtarget.isAIXExtendedAltivecABI() ? CSR_AIX32_Altivec_SaveList
208 : CSR_AIX32_SaveList;
209 return CSR_AIX32_SaveList;
210 }
211 if (Subtarget.pairedVectorMemops())
212 return CSR_SVR432_VSRP_SaveList;
213 if (Subtarget.hasAltivec())
214 return CSR_SVR432_Altivec_SaveList;
215 else if (Subtarget.hasSPE()) {
216 if (TM.isPositionIndependent() && !TM.isPPC64())
217 return CSR_SVR432_SPE_NO_S30_31_SaveList;
218 return CSR_SVR432_SPE_SaveList;
219 }
220 return CSR_SVR432_SaveList;
221}
222
223const uint32_t *
225 CallingConv::ID CC) const {
227 if (CC == CallingConv::AnyReg) {
228 if (Subtarget.hasVSX()) {
229 if (Subtarget.pairedVectorMemops())
230 return CSR_64_AllRegs_VSRP_RegMask;
231 if (Subtarget.isAIXABI() && !Subtarget.isAIXExtendedAltivecABI())
232 return CSR_64_AllRegs_AIX_Dflt_VSX_RegMask;
233 return CSR_64_AllRegs_VSX_RegMask;
234 }
235 if (Subtarget.hasAltivec()) {
236 if (Subtarget.isAIXABI() && !Subtarget.isAIXExtendedAltivecABI())
237 return CSR_64_AllRegs_AIX_Dflt_Altivec_RegMask;
238 return CSR_64_AllRegs_Altivec_RegMask;
239 }
240 return CSR_64_AllRegs_RegMask;
241 }
242
243 if (Subtarget.isAIXABI()) {
244 if (Subtarget.pairedVectorMemops()) {
245 if (!Subtarget.isAIXExtendedAltivecABI())
246 return TM.isPPC64() ? CSR_PPC64_RegMask : CSR_AIX32_RegMask;
247 return TM.isPPC64() ? CSR_AIX64_VSRP_RegMask : CSR_AIX32_VSRP_RegMask;
248 }
249 return TM.isPPC64() ? ((Subtarget.hasAltivec() &&
250 Subtarget.isAIXExtendedAltivecABI())
251 ? CSR_PPC64_Altivec_RegMask
252 : CSR_PPC64_RegMask)
253 : ((Subtarget.hasAltivec() &&
254 Subtarget.isAIXExtendedAltivecABI())
255 ? CSR_AIX32_Altivec_RegMask
256 : CSR_AIX32_RegMask);
257 }
258
259 if (CC == CallingConv::Cold) {
260 if (TM.isPPC64())
261 return Subtarget.pairedVectorMemops()
262 ? CSR_SVR64_ColdCC_VSRP_RegMask
263 : (Subtarget.hasAltivec() ? CSR_SVR64_ColdCC_Altivec_RegMask
264 : CSR_SVR64_ColdCC_RegMask);
265 else
266 return Subtarget.pairedVectorMemops()
267 ? CSR_SVR32_ColdCC_VSRP_RegMask
268 : (Subtarget.hasAltivec()
269 ? CSR_SVR32_ColdCC_Altivec_RegMask
270 : (Subtarget.hasSPE() ? CSR_SVR32_ColdCC_SPE_RegMask
271 : CSR_SVR32_ColdCC_RegMask));
272 }
273
274 if (TM.isPPC64())
275 return Subtarget.pairedVectorMemops()
276 ? CSR_SVR464_VSRP_RegMask
277 : (Subtarget.hasAltivec() ? CSR_PPC64_Altivec_RegMask
278 : CSR_PPC64_RegMask);
279 else
280 return Subtarget.pairedVectorMemops()
281 ? CSR_SVR432_VSRP_RegMask
282 : (Subtarget.hasAltivec()
283 ? CSR_SVR432_Altivec_RegMask
284 : (Subtarget.hasSPE()
285 ? (TM.isPositionIndependent()
286 ? CSR_SVR432_SPE_NO_S30_31_RegMask
287 : CSR_SVR432_SPE_RegMask)
288 : CSR_SVR432_RegMask));
289}
290
291const uint32_t*
293 return CSR_NoRegs_RegMask;
294}
295
297 for (unsigned PseudoReg : {PPC::ZERO, PPC::ZERO8, PPC::RM})
298 Mask[PseudoReg / 32] &= ~(1u << (PseudoReg % 32));
299}
300
302 BitVector Reserved(getNumRegs());
304 const PPCFrameLowering *TFI = getFrameLowering(MF);
305
306 // The ZERO register is not really a register, but the representation of r0
307 // when used in instructions that treat r0 as the constant 0.
308 markSuperRegs(Reserved, PPC::ZERO);
309
310 // The FP register is also not really a register, but is the representation
311 // of the frame pointer register used by ISD::FRAMEADDR.
312 markSuperRegs(Reserved, PPC::FP);
313
314 // The BP register is also not really a register, but is the representation
315 // of the base pointer register used by setjmp.
316 markSuperRegs(Reserved, PPC::BP);
317
318 // The counter registers must be reserved so that counter-based loops can
319 // be correctly formed (and the mtctr instructions are not DCE'd).
320 markSuperRegs(Reserved, PPC::CTR);
321 markSuperRegs(Reserved, PPC::CTR8);
322
323 markSuperRegs(Reserved, PPC::R1);
324 markSuperRegs(Reserved, PPC::LR);
325 markSuperRegs(Reserved, PPC::LR8);
326 markSuperRegs(Reserved, PPC::RM);
327
328 markSuperRegs(Reserved, PPC::VRSAVE);
329
330 const PPCFunctionInfo *FuncInfo = MF.getInfo<PPCFunctionInfo>();
331 bool UsesTOCBasePtr = FuncInfo->usesTOCBasePtr();
332 // The SVR4 ABI reserves r2 and r13
333 if (Subtarget.isSVR4ABI() || Subtarget.isAIXABI()) {
334 // We only reserve r2 if we need to use the TOC pointer. If we have no
335 // explicit uses of the TOC pointer (meaning we're a leaf function with
336 // no constant-pool loads, etc.) and we have no potential uses inside an
337 // inline asm block, then we can treat r2 has an ordinary callee-saved
338 // register.
339 if (!TM.isPPC64() || UsesTOCBasePtr || MF.hasInlineAsm())
340 markSuperRegs(Reserved, PPC::R2); // System-reserved register.
341
342 if (Subtarget.isSVR4ABI())
343 markSuperRegs(Reserved, PPC::R13); // Small Data Area pointer register.
344 }
345
346 // On PPC64, r13 is the thread pointer. Never allocate this register.
347 if (TM.isPPC64())
348 markSuperRegs(Reserved, PPC::R13);
349
350 if (TFI->needsFP(MF))
351 markSuperRegs(Reserved, PPC::R31);
352
353 bool IsPositionIndependent = TM.isPositionIndependent();
354 if (hasBasePointer(MF)) {
355 if (Subtarget.is32BitELFABI() && IsPositionIndependent)
356 markSuperRegs(Reserved, PPC::R29);
357 else
358 markSuperRegs(Reserved, PPC::R30);
359 }
360
361 if (Subtarget.is32BitELFABI() && IsPositionIndependent)
362 markSuperRegs(Reserved, PPC::R30);
363
364 // Reserve Altivec registers when Altivec is unavailable.
365 if (!Subtarget.hasAltivec())
366 for (MCRegister Reg : PPC::VRRCRegClass)
367 markSuperRegs(Reserved, Reg);
368
369 if (Subtarget.isAIXABI() && Subtarget.hasAltivec() &&
370 !Subtarget.isAIXExtendedAltivecABI()) {
371 // In the AIX default Altivec ABI, vector registers VR20-VR31 are reserved
372 // and cannot be used.
373 for (auto Reg : CSR_Altivec_SaveList) {
374 if (Reg == 0)
375 break;
376 markSuperRegs(Reserved, Reg);
377 for (MCRegAliasIterator AS(Reg, this, true); AS.isValid(); ++AS) {
378 Reserved.set(*AS);
379 }
380 }
381 }
382
383 assert(checkAllSuperRegsMarked(Reserved));
384 return Reserved;
385}
386
388 MCRegister PhysReg) const {
389 // CTR and LR registers are always reserved, but they are asm clobberable.
390 if (PhysReg == PPC::CTR || PhysReg == PPC::CTR8 || PhysReg == PPC::LR ||
391 PhysReg == PPC::LR8)
392 return true;
393
394 return !getReservedRegs(MF).test(PhysReg);
395}
396
399 const PPCInstrInfo *InstrInfo = Subtarget.getInstrInfo();
400 const MachineFrameInfo &MFI = MF.getFrameInfo();
401 const std::vector<CalleeSavedInfo> &Info = MFI.getCalleeSavedInfo();
402
403 LLVM_DEBUG(dbgs() << "requiresFrameIndexScavenging for " << MF.getName()
404 << ".\n");
405 // If the callee saved info is invalid we have to default to true for safety.
406 if (!MFI.isCalleeSavedInfoValid()) {
407 LLVM_DEBUG(dbgs() << "TRUE - Invalid callee saved info.\n");
408 return true;
409 }
410
411 // We will require the use of X-Forms because the frame is larger than what
412 // can be represented in signed 16 bits that fit in the immediate of a D-Form.
413 // If we need an X-Form then we need a register to store the address offset.
414 unsigned FrameSize = MFI.getStackSize();
415 // Signed 16 bits means that the FrameSize cannot be more than 15 bits.
416 if (FrameSize & ~0x7FFF) {
417 LLVM_DEBUG(dbgs() << "TRUE - Frame size is too large for D-Form.\n");
418 return true;
419 }
420
421 // The callee saved info is valid so it can be traversed.
422 // Checking for registers that need saving that do not have load or store
423 // forms where the address offset is an immediate.
424 for (const CalleeSavedInfo &CSI : Info) {
425 // If the spill is to a register no scavenging is required.
426 if (CSI.isSpilledToReg())
427 continue;
428
429 int FrIdx = CSI.getFrameIdx();
430 Register Reg = CSI.getReg();
431
432 const TargetRegisterClass *RC = getMinimalPhysRegClass(Reg);
433 unsigned Opcode = InstrInfo->getStoreOpcodeForSpill(RC);
434 if (!MFI.isFixedObjectIndex(FrIdx)) {
435 // This is not a fixed object. If it requires alignment then we may still
436 // need to use the XForm.
437 if (offsetMinAlignForOpcode(Opcode) > 1) {
438 LLVM_DEBUG(dbgs() << "Memory Operand: " << InstrInfo->getName(Opcode)
439 << " for register " << printReg(Reg, this) << ".\n");
440 LLVM_DEBUG(dbgs() << "TRUE - Not fixed frame object that requires "
441 << "alignment.\n");
442 return true;
443 }
444 }
445
446 // This is eiher:
447 // 1) A fixed frame index object which we know are aligned so
448 // as long as we have a valid DForm/DSForm/DQForm (non XForm) we don't
449 // need to consider the alignment here.
450 // 2) A not fixed object but in that case we now know that the min required
451 // alignment is no more than 1 based on the previous check.
452 if (InstrInfo->isXFormMemOp(Opcode)) {
453 LLVM_DEBUG(dbgs() << "Memory Operand: " << InstrInfo->getName(Opcode)
454 << " for register " << printReg(Reg, this) << ".\n");
455 LLVM_DEBUG(dbgs() << "TRUE - Memory operand is X-Form.\n");
456 return true;
457 }
458
459 // This is a spill/restore of a quadword.
460 if ((Opcode == PPC::RESTORE_QUADWORD) || (Opcode == PPC::SPILL_QUADWORD)) {
461 LLVM_DEBUG(dbgs() << "Memory Operand: " << InstrInfo->getName(Opcode)
462 << " for register " << printReg(Reg, this) << ".\n");
463 LLVM_DEBUG(dbgs() << "TRUE - Memory operand is a quadword.\n");
464 return true;
465 }
466 }
467 LLVM_DEBUG(dbgs() << "FALSE - Scavenging is not required.\n");
468 return false;
469}
470
472 const MachineFunction &MF) const {
474 // Do not use virtual base registers when ROP protection is turned on.
475 // Virtual base registers break the layout of the local variable space and may
476 // push the ROP Hash location past the 512 byte range of the ROP store
477 // instruction.
478 return !Subtarget.hasROPProtect();
479}
480
482 const MachineFunction &MF) const {
483 assert(PhysReg.isPhysical());
485 const MachineFrameInfo &MFI = MF.getFrameInfo();
486
487 if (!Subtarget.is64BitELFABI() && !Subtarget.isAIXABI())
488 return false;
489 if (PhysReg == Subtarget.getTOCPointerRegister())
490 // X2/R2 is guaranteed to be preserved within a function if it is reserved.
491 // The reason it's reserved is that it's the TOC pointer (and the function
492 // uses the TOC). In functions where it isn't reserved (i.e. leaf functions
493 // with no TOC access), we can't claim that it is preserved.
494 return (getReservedRegs(MF).test(PhysReg));
495 if (TM.getCLOpts().stack_ptr_caller_preserved &&
496 PhysReg == Subtarget.getStackPointerRegister() &&
497 !MFI.hasVarSizedObjects() && !MFI.hasOpaqueSPAdjustment())
498 // The value of the stack pointer does not change within a function after
499 // the prologue and before the epilogue if there are no dynamic allocations
500 // and no inline asm which clobbers X1/R1.
501 return true;
502 return false;
503}
504
506 Register VirtReg, ArrayRef<MCPhysReg> Order,
508 const VirtRegMap *VRM, const LiveRegMatrix *Matrix) const {
509 const MachineRegisterInfo *MRI = &MF.getRegInfo();
510
511 // Call the base implementation first to set any hints based on the usual
512 // heuristics and decide what the return value should be. We want to return
513 // the same value returned by the base implementation. If the base
514 // implementation decides to return true and force the allocation then we
515 // will leave it as such. On the other hand if the base implementation
516 // decides to return false the following code will not force the allocation
517 // as we are just looking to provide a hint.
518 bool BaseImplRetVal = TargetRegisterInfo::getRegAllocationHints(
519 VirtReg, Order, Hints, MF, VRM, Matrix);
520
521 // Don't use the allocation hints for ISAFuture.
522 // The WACC registers used in ISAFuture are unlike the ACC registers on
523 // Power 10 and so this logic to register allocation hints does not apply.
524 if (MF.getSubtarget<PPCSubtarget>().isISAFuture())
525 return BaseImplRetVal;
526
527 // We are interested in instructions that copy values to ACC/UACC.
528 // The copy into UACC will be simply a COPY to a subreg so we
529 // want to allocate the corresponding physical subreg for the source.
530 // The copy into ACC will be a BUILD_UACC so we want to allocate
531 // the same number UACC for the source.
532 const TargetRegisterClass *RegClass = MRI->getRegClass(VirtReg);
533 for (MachineInstr &Use : MRI->reg_nodbg_instructions(VirtReg)) {
534 const MachineOperand *ResultOp = nullptr;
535 Register ResultReg;
536 switch (Use.getOpcode()) {
537 case TargetOpcode::COPY: {
538 ResultOp = &Use.getOperand(0);
539 ResultReg = ResultOp->getReg();
540 if (ResultReg.isVirtual() &&
541 MRI->getRegClass(ResultReg)->contains(PPC::UACC0) &&
542 VRM->hasPhys(ResultReg)) {
543 Register UACCPhys = VRM->getPhys(ResultReg);
544 Register HintReg;
545 if (RegClass->contains(PPC::VSRp0)) {
546 HintReg = getSubReg(UACCPhys, ResultOp->getSubReg());
547 // Ensure that the hint is a VSRp register.
548 if (HintReg >= PPC::VSRp0 && HintReg <= PPC::VSRp31)
549 Hints.insert(HintReg);
550 } else if (RegClass->contains(PPC::ACC0)) {
551 HintReg = PPC::ACC0 + (UACCPhys - PPC::UACC0);
552 if (HintReg >= PPC::ACC0 && HintReg <= PPC::ACC7)
553 Hints.insert(HintReg);
554 }
555 }
556 break;
557 }
558 case PPC::BUILD_UACC: {
559 ResultOp = &Use.getOperand(0);
560 ResultReg = ResultOp->getReg();
561 if (MRI->getRegClass(ResultReg)->contains(PPC::ACC0) &&
562 VRM->hasPhys(ResultReg)) {
563 Register ACCPhys = VRM->getPhys(ResultReg);
564 assert((ACCPhys >= PPC::ACC0 && ACCPhys <= PPC::ACC7) &&
565 "Expecting an ACC register for BUILD_UACC.");
566 Register HintReg = PPC::UACC0 + (ACCPhys - PPC::ACC0);
567 Hints.insert(HintReg);
568 }
569 break;
570 }
571 }
572 }
573 return BaseImplRetVal;
574}
575
578 if (RC == &PPC::CARRYRCRegClass)
579 return TM.isPPC64() ? &PPC::G8RCRegClass : &PPC::GPRCRegClass;
580 return RC;
581}
582
584 MachineFunction &MF) const {
585 const PPCFrameLowering *TFI = getFrameLowering(MF);
586 const unsigned DefaultSafety = 1;
587
588 switch (RC->getID()) {
589 default:
590 return 0;
591 case PPC::G8RC_NOX0RegClassID:
592 case PPC::GPRC_NOR0RegClassID:
593 case PPC::SPERCRegClassID:
594 case PPC::G8RCRegClassID:
595 case PPC::GPRCRegClassID: {
596 unsigned FP = TFI->hasFP(MF) ? 1 : 0;
597 return 32 - FP - DefaultSafety;
598 }
599 case PPC::F4RCRegClassID:
600 case PPC::F8RCRegClassID:
601 case PPC::VSLRCRegClassID:
602 return 32 - DefaultSafety;
603 case PPC::VFRCRegClassID:
604 case PPC::VRRCRegClassID: {
606 // Vector registers VR20-VR31 are reserved and cannot be used in the default
607 // Altivec ABI on AIX.
608 if (!Subtarget.isAIXExtendedAltivecABI() && Subtarget.isAIXABI())
609 return 20 - DefaultSafety;
610 }
611 return 32 - DefaultSafety;
612 case PPC::VSFRCRegClassID:
613 case PPC::VSSRCRegClassID:
614 case PPC::VSRCRegClassID: {
616 if (!Subtarget.isAIXExtendedAltivecABI() && Subtarget.isAIXABI())
617 // Vector registers VR20-VR31 are reserved and cannot be used in the
618 // default Altivec ABI on AIX.
619 return 52 - DefaultSafety;
620 }
621 return 64 - DefaultSafety;
622 case PPC::CRRCRegClassID:
623 return 8 - DefaultSafety;
624 }
625}
626
629 const MachineFunction &MF) const {
631 const auto *DefaultSuperclass =
633 if (Subtarget.hasVSX()) {
634 // With VSX, we can inflate various sub-register classes to the full VSX
635 // register set.
636
637 // For Power9 we allow the user to enable GPR to vector spills.
638 // FIXME: Currently limited to spilling GP8RC. A follow on patch will add
639 // support to spill GPRC.
640 if (Subtarget.isELFv2ABI() || Subtarget.isAIXABI()) {
641 if (Subtarget.hasP9Vector() && TM.getCLOpts().enable_gpr_to_vsr_spills &&
642 RC == &PPC::G8RCRegClass) {
643 InflateGP8RC++;
644 return &PPC::SPILLTOVSRRCRegClass;
645 }
646 if (RC == &PPC::GPRCRegClass && TM.getCLOpts().enable_gpr_to_vsr_spills)
647 InflateGPRC++;
648 }
649
650 for (unsigned SuperID : RC->superclasses()) {
651 if (getRegSizeInBits(*getRegClass(SuperID)) != getRegSizeInBits(*RC))
652 continue;
653
654 switch (SuperID) {
655 case PPC::VSSRCRegClassID:
656 return Subtarget.hasP8Vector() ? getRegClass(SuperID)
657 : DefaultSuperclass;
658 case PPC::VSFRCRegClassID:
659 case PPC::VSRCRegClassID:
660 return getRegClass(SuperID);
661 case PPC::VSRpRCRegClassID:
662 return Subtarget.pairedVectorMemops() ? getRegClass(SuperID)
663 : DefaultSuperclass;
664 case PPC::ACCRCRegClassID:
665 case PPC::UACCRCRegClassID:
666 return Subtarget.hasMMA() ? getRegClass(SuperID) : DefaultSuperclass;
667 }
668 }
669 }
670
671 return DefaultSuperclass;
672}
673
674//===----------------------------------------------------------------------===//
675// Stack Frame Processing methods
676//===----------------------------------------------------------------------===//
677
678/// lowerDynamicAlloc - Generate the code for allocating an object in the
679/// current frame. The sequence of code will be in the general form
680///
681/// addi R0, SP, \#frameSize ; get the address of the previous frame
682/// stwxu R0, SP, Rnegsize ; add and update the SP with the negated size
683/// addi Rnew, SP, \#maxCalFrameSize ; get the top of the allocation
684///
686 // Get the instruction.
687 MachineInstr &MI = *II;
688 // Get the instruction's basic block.
689 MachineBasicBlock &MBB = *MI.getParent();
690 // Get the basic block's function.
691 MachineFunction &MF = *MBB.getParent();
692 // Get the frame info.
693 MachineFrameInfo &MFI = MF.getFrameInfo();
695 // Get the instruction info.
696 const TargetInstrInfo &TII = *Subtarget.getInstrInfo();
697 // Determine whether 64-bit pointers are used.
698 bool LP64 = TM.isPPC64();
699 DebugLoc dl = MI.getDebugLoc();
700
701 // Get the maximum call stack size.
702 unsigned maxCallFrameSize = MFI.getMaxCallFrameSize();
703 Align MaxAlign = MFI.getMaxAlign();
704 assert(isAligned(MaxAlign, maxCallFrameSize) &&
705 "Maximum call-frame size not sufficiently aligned");
706 (void)MaxAlign;
707
708 const TargetRegisterClass *G8RC = &PPC::G8RCRegClass;
709 const TargetRegisterClass *GPRC = &PPC::GPRCRegClass;
710 Register Reg = MF.getRegInfo().createVirtualRegister(LP64 ? G8RC : GPRC);
711 bool KillNegSizeReg = MI.getOperand(1).isKill();
712 Register NegSizeReg = MI.getOperand(1).getReg();
713
714 prepareDynamicAlloca(II, NegSizeReg, KillNegSizeReg, Reg);
715 // Grow the stack and update the stack pointer link, then determine the
716 // address of new allocated space.
717 if (LP64) {
718 BuildMI(MBB, II, dl, TII.get(PPC::STDUX), PPC::X1)
720 .addReg(PPC::X1)
721 .addReg(NegSizeReg, getKillRegState(KillNegSizeReg));
722 BuildMI(MBB, II, dl, TII.get(PPC::ADDI8), MI.getOperand(0).getReg())
723 .addReg(PPC::X1)
724 .addImm(maxCallFrameSize);
725 } else {
726 BuildMI(MBB, II, dl, TII.get(PPC::STWUX), PPC::R1)
728 .addReg(PPC::R1)
729 .addReg(NegSizeReg, getKillRegState(KillNegSizeReg));
730 BuildMI(MBB, II, dl, TII.get(PPC::ADDI), MI.getOperand(0).getReg())
731 .addReg(PPC::R1)
732 .addImm(maxCallFrameSize);
733 }
734
735 // Discard the DYNALLOC instruction.
736 MBB.erase(II);
737}
738
739/// To accomplish dynamic stack allocation, we have to calculate exact size
740/// subtracted from the stack pointer according alignment information and get
741/// previous frame pointer.
743 Register &NegSizeReg,
744 bool &KillNegSizeReg,
745 Register &FramePointer) const {
746 // Get the instruction.
747 MachineInstr &MI = *II;
748 // Get the instruction's basic block.
749 MachineBasicBlock &MBB = *MI.getParent();
750 // Get the basic block's function.
751 MachineFunction &MF = *MBB.getParent();
752 // Get the frame info.
753 MachineFrameInfo &MFI = MF.getFrameInfo();
755 // Get the instruction info.
756 const TargetInstrInfo &TII = *Subtarget.getInstrInfo();
757 // Determine whether 64-bit pointers are used.
758 bool LP64 = TM.isPPC64();
759 DebugLoc dl = MI.getDebugLoc();
760 // Get the total frame size.
761 unsigned FrameSize = MFI.getStackSize();
762
763 // Get stack alignments.
764 const PPCFrameLowering *TFI = getFrameLowering(MF);
765 Align TargetAlign = TFI->getStackAlign();
766 Align MaxAlign = MFI.getMaxAlign();
767
768 // Determine the previous frame's address. If FrameSize can't be
769 // represented as 16 bits or we need special alignment, then we load the
770 // previous frame's address from 0(SP). Why not do an addis of the hi?
771 // Because R0 is our only safe tmp register and addi/addis treat R0 as zero.
772 // Constructing the constant and adding would take 3 instructions.
773 // Fortunately, a frame greater than 32K is rare.
774 const TargetRegisterClass *G8RC = &PPC::G8RCRegClass;
775 const TargetRegisterClass *GPRC = &PPC::GPRCRegClass;
776
777 if (MaxAlign < TargetAlign && isInt<16>(FrameSize)) {
778 if (LP64)
779 BuildMI(MBB, II, dl, TII.get(PPC::ADDI8), FramePointer)
780 .addReg(PPC::X31)
781 .addImm(FrameSize);
782 else
783 BuildMI(MBB, II, dl, TII.get(PPC::ADDI), FramePointer)
784 .addReg(PPC::R31)
785 .addImm(FrameSize);
786 } else if (LP64) {
787 BuildMI(MBB, II, dl, TII.get(PPC::LD), FramePointer)
788 .addImm(0)
789 .addReg(PPC::X1);
790 } else {
791 BuildMI(MBB, II, dl, TII.get(PPC::LWZ), FramePointer)
792 .addImm(0)
793 .addReg(PPC::R1);
794 }
795 // Determine the actual NegSizeReg according to alignment info.
796 if (LP64) {
797 if (MaxAlign > TargetAlign) {
798 unsigned UnalNegSizeReg = NegSizeReg;
799 NegSizeReg = MF.getRegInfo().createVirtualRegister(G8RC);
800
801 // Unfortunately, there is no andi, only andi., and we can't insert that
802 // here because we might clobber cr0 while it is live.
803 BuildMI(MBB, II, dl, TII.get(PPC::LI8), NegSizeReg)
804 .addImm(~(MaxAlign.value() - 1));
805
806 unsigned NegSizeReg1 = NegSizeReg;
807 NegSizeReg = MF.getRegInfo().createVirtualRegister(G8RC);
808 BuildMI(MBB, II, dl, TII.get(PPC::AND8), NegSizeReg)
809 .addReg(UnalNegSizeReg, getKillRegState(KillNegSizeReg))
810 .addReg(NegSizeReg1, RegState::Kill);
811 KillNegSizeReg = true;
812 }
813 } else {
814 if (MaxAlign > TargetAlign) {
815 unsigned UnalNegSizeReg = NegSizeReg;
816 NegSizeReg = MF.getRegInfo().createVirtualRegister(GPRC);
817
818 // Unfortunately, there is no andi, only andi., and we can't insert that
819 // here because we might clobber cr0 while it is live.
820 BuildMI(MBB, II, dl, TII.get(PPC::LI), NegSizeReg)
821 .addImm(~(MaxAlign.value() - 1));
822
823 unsigned NegSizeReg1 = NegSizeReg;
824 NegSizeReg = MF.getRegInfo().createVirtualRegister(GPRC);
825 BuildMI(MBB, II, dl, TII.get(PPC::AND), NegSizeReg)
826 .addReg(UnalNegSizeReg, getKillRegState(KillNegSizeReg))
827 .addReg(NegSizeReg1, RegState::Kill);
828 KillNegSizeReg = true;
829 }
830 }
831}
832
835 MachineInstr &MI = *II;
836 // Get the instruction's basic block.
837 MachineBasicBlock &MBB = *MI.getParent();
838 // Get the basic block's function.
839 MachineFunction &MF = *MBB.getParent();
841 // Get the instruction info.
842 const TargetInstrInfo &TII = *Subtarget.getInstrInfo();
843 // Determine whether 64-bit pointers are used.
844 bool LP64 = TM.isPPC64();
845 DebugLoc dl = MI.getDebugLoc();
846 Register FramePointer = MI.getOperand(0).getReg();
847 const Register ActualNegSizeReg = MI.getOperand(1).getReg();
848 bool KillNegSizeReg = MI.getOperand(2).isKill();
849 Register NegSizeReg = MI.getOperand(2).getReg();
850 const MCInstrDesc &CopyInst = TII.get(LP64 ? PPC::OR8 : PPC::OR);
851 // RegAllocator might allocate FramePointer and NegSizeReg in the same phyreg.
852 if (FramePointer == NegSizeReg) {
853 assert(KillNegSizeReg && "FramePointer is a def and NegSizeReg is an use, "
854 "NegSizeReg should be killed");
855 // FramePointer is clobbered earlier than the use of NegSizeReg in
856 // prepareDynamicAlloca, save NegSizeReg in ActualNegSizeReg to avoid
857 // misuse.
858 BuildMI(MBB, II, dl, CopyInst, ActualNegSizeReg)
859 .addReg(NegSizeReg)
860 .addReg(NegSizeReg);
861 NegSizeReg = ActualNegSizeReg;
862 KillNegSizeReg = false;
863 }
864 prepareDynamicAlloca(II, NegSizeReg, KillNegSizeReg, FramePointer);
865 // NegSizeReg might be updated in prepareDynamicAlloca if MaxAlign >
866 // TargetAlign.
867 if (NegSizeReg != ActualNegSizeReg)
868 BuildMI(MBB, II, dl, CopyInst, ActualNegSizeReg)
869 .addReg(NegSizeReg)
870 .addReg(NegSizeReg);
871 MBB.erase(II);
872}
873
876 // Get the instruction.
877 MachineInstr &MI = *II;
878 // Get the instruction's basic block.
879 MachineBasicBlock &MBB = *MI.getParent();
880 // Get the basic block's function.
881 MachineFunction &MF = *MBB.getParent();
882 // Get the frame info.
883 MachineFrameInfo &MFI = MF.getFrameInfo();
885 // Get the instruction info.
886 const TargetInstrInfo &TII = *Subtarget.getInstrInfo();
887
888 unsigned maxCallFrameSize = MFI.getMaxCallFrameSize();
889 bool is64Bit = TM.isPPC64();
890 DebugLoc dl = MI.getDebugLoc();
891 BuildMI(MBB, II, dl, TII.get(is64Bit ? PPC::LI8 : PPC::LI),
892 MI.getOperand(0).getReg())
893 .addImm(maxCallFrameSize);
894 MBB.erase(II);
895}
896
897/// lowerCRSpilling - Generate the code for spilling a CR register. Instead of
898/// reserving a whole register (R0), we scrounge for one here. This generates
899/// code like this:
900///
901/// mfcr rA ; Move the conditional register into GPR rA.
902/// rlwinm rA, rA, SB, 0, 31 ; Shift the bits left so they are in CR0's slot.
903/// stw rA, FI ; Store rA to the frame.
904///
906 unsigned FrameIndex) const {
907 // Get the instruction.
908 MachineInstr &MI = *II; // ; SPILL_CR <SrcReg>, <offset>
909 // Get the instruction's basic block.
910 MachineBasicBlock &MBB = *MI.getParent();
911 MachineFunction &MF = *MBB.getParent();
913 const TargetInstrInfo &TII = *Subtarget.getInstrInfo();
914 DebugLoc dl = MI.getDebugLoc();
915
916 bool LP64 = TM.isPPC64();
917 const TargetRegisterClass *G8RC = &PPC::G8RCRegClass;
918 const TargetRegisterClass *GPRC = &PPC::GPRCRegClass;
919
920 Register Reg = MF.getRegInfo().createVirtualRegister(LP64 ? G8RC : GPRC);
921 Register SrcReg = MI.getOperand(0).getReg();
922
923 // We need to store the CR in the low 4-bits of the saved value. First, issue
924 // an MFOCRF to save all of the CRBits and, if needed, kill the SrcReg.
925 BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::MFOCRF8 : PPC::MFOCRF), Reg)
926 .addReg(SrcReg, getKillRegState(MI.getOperand(0).isKill()));
927
928 // If the saved register wasn't CR0, shift the bits left so that they are in
929 // CR0's slot.
930 if (SrcReg != PPC::CR0) {
931 Register Reg1 = Reg;
932 Reg = MF.getRegInfo().createVirtualRegister(LP64 ? G8RC : GPRC);
933
934 // rlwinm rA, rA, ShiftBits, 0, 31.
935 BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::RLWINM8 : PPC::RLWINM), Reg)
936 .addReg(Reg1, RegState::Kill)
937 .addImm(getEncodingValue(SrcReg) * 4)
938 .addImm(0)
939 .addImm(31);
940 }
941
942 addFrameReference(BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::STW8 : PPC::STW))
943 .addReg(Reg, RegState::Kill),
944 FrameIndex);
945
946 // Discard the pseudo instruction.
947 MBB.erase(II);
948}
949
951 unsigned FrameIndex) const {
952 // Get the instruction.
953 MachineInstr &MI = *II; // ; <DestReg> = RESTORE_CR <offset>
954 // Get the instruction's basic block.
955 MachineBasicBlock &MBB = *MI.getParent();
956 MachineFunction &MF = *MBB.getParent();
958 const TargetInstrInfo &TII = *Subtarget.getInstrInfo();
959 DebugLoc dl = MI.getDebugLoc();
960
961 bool LP64 = TM.isPPC64();
962 const TargetRegisterClass *G8RC = &PPC::G8RCRegClass;
963 const TargetRegisterClass *GPRC = &PPC::GPRCRegClass;
964
965 Register Reg = MF.getRegInfo().createVirtualRegister(LP64 ? G8RC : GPRC);
966 Register DestReg = MI.getOperand(0).getReg();
967 assert(MI.definesRegister(DestReg, /*TRI=*/nullptr) &&
968 "RESTORE_CR does not define its destination");
969
970 addFrameReference(BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::LWZ8 : PPC::LWZ),
971 Reg), FrameIndex);
972
973 // If the reloaded register isn't CR0, shift the bits right so that they are
974 // in the right CR's slot.
975 if (DestReg != PPC::CR0) {
976 Register Reg1 = Reg;
977 Reg = MF.getRegInfo().createVirtualRegister(LP64 ? G8RC : GPRC);
978
979 unsigned ShiftBits = getEncodingValue(DestReg)*4;
980 // rlwinm r11, r11, 32-ShiftBits, 0, 31.
981 BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::RLWINM8 : PPC::RLWINM), Reg)
982 .addReg(Reg1, RegState::Kill).addImm(32-ShiftBits).addImm(0)
983 .addImm(31);
984 }
985
986 BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::MTOCRF8 : PPC::MTOCRF), DestReg)
987 .addReg(Reg, RegState::Kill);
988
989 // Discard the pseudo instruction.
990 MBB.erase(II);
991}
992
994 unsigned FrameIndex) const {
995 // Get the instruction.
996 MachineInstr &MI = *II; // ; SPILL_CRBIT <SrcReg>, <offset>
997 // Get the instruction's basic block.
998 MachineBasicBlock &MBB = *MI.getParent();
999 MachineFunction &MF = *MBB.getParent();
1001 const TargetInstrInfo &TII = *Subtarget.getInstrInfo();
1002 const TargetRegisterInfo* TRI = Subtarget.getRegisterInfo();
1003 DebugLoc dl = MI.getDebugLoc();
1004
1005 bool LP64 = TM.isPPC64();
1006 const TargetRegisterClass *G8RC = &PPC::G8RCRegClass;
1007 const TargetRegisterClass *GPRC = &PPC::GPRCRegClass;
1008
1009 Register Reg = MF.getRegInfo().createVirtualRegister(LP64 ? G8RC : GPRC);
1010 Register SrcReg = MI.getOperand(0).getReg();
1011
1012 // Search up the BB to find the definition of the CR bit.
1015 ++Ins;
1016 unsigned CRBitSpillDistance = 0;
1017 bool SeenUse = false;
1018 for (; Ins != Rend; ++Ins) {
1019 // Definition found.
1020 if (Ins->modifiesRegister(SrcReg, TRI))
1021 break;
1022 // Use found.
1023 if (Ins->readsRegister(SrcReg, TRI))
1024 SeenUse = true;
1025 // Unable to find CR bit definition within maximum search distance.
1026 if (CRBitSpillDistance == TM.getCLOpts().max_crbit_spill_dist) {
1027 Ins = MI;
1028 break;
1029 }
1030 // Skip debug instructions when counting CR bit spill distance.
1031 if (!Ins->isDebugInstr())
1032 CRBitSpillDistance++;
1033 }
1034
1035 // Unable to find the definition of the CR bit in the MBB.
1036 if (Ins == MBB.rend())
1037 Ins = MI;
1038
1039 bool SpillsKnownBit = false;
1040 // There is no need to extract the CR bit if its value is already known.
1041 switch (Ins->getOpcode()) {
1042 case PPC::CRUNSET:
1043 BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::LI8 : PPC::LI), Reg)
1044 .addImm(0);
1045 SpillsKnownBit = true;
1046 break;
1047 case PPC::CRSET:
1048 BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::LIS8 : PPC::LIS), Reg)
1049 .addImm(-32768);
1050 SpillsKnownBit = true;
1051 break;
1052 default:
1053 // When spilling a CR bit, the super register may not be explicitly defined
1054 // (i.e. it can be defined by a CR-logical that only defines the subreg) so
1055 // we state that the CR field is undef. Also, in order to preserve the kill
1056 // flag on the CR bit, we add it as an implicit use.
1057
1058 // On Power10, we can use SETNBC to spill all CR bits. SETNBC will set all
1059 // bits (specifically, it produces a -1 if the CR bit is set). Ultimately,
1060 // the bit that is of importance to us is bit 32 (bit 0 of a 32-bit
1061 // register), and SETNBC will set this.
1062 if (Subtarget.isISA3_1()) {
1063 BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::SETNBC8 : PPC::SETNBC), Reg)
1064 .addReg(SrcReg, RegState::Undef)
1065 .addReg(SrcReg, RegState::Implicit |
1066 getKillRegState(MI.getOperand(0).isKill()));
1067 break;
1068 }
1069
1070 // On Power9, we can use SETB to extract the LT bit. This only works for
1071 // the LT bit since SETB produces -1/1/0 for LT/GT/<neither>. So the value
1072 // of the bit we care about (32-bit sign bit) will be set to the value of
1073 // the LT bit (regardless of the other bits in the CR field).
1074 if (Subtarget.isISA3_0()) {
1075 if (SrcReg == PPC::CR0LT || SrcReg == PPC::CR1LT ||
1076 SrcReg == PPC::CR2LT || SrcReg == PPC::CR3LT ||
1077 SrcReg == PPC::CR4LT || SrcReg == PPC::CR5LT ||
1078 SrcReg == PPC::CR6LT || SrcReg == PPC::CR7LT) {
1079 BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::SETB8 : PPC::SETB), Reg)
1081 .addReg(SrcReg, RegState::Implicit |
1082 getKillRegState(MI.getOperand(0).isKill()));
1083 break;
1084 }
1085 }
1086
1087 // We need to move the CR field that contains the CR bit we are spilling.
1088 BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::MFOCRF8 : PPC::MFOCRF), Reg)
1090 .addReg(SrcReg,
1091 RegState::Implicit | getKillRegState(MI.getOperand(0).isKill()));
1092
1093 // If the saved register wasn't CR0LT, shift the bits left so that the bit
1094 // to store is the first one. Mask all but that bit.
1095 Register Reg1 = Reg;
1096 Reg = MF.getRegInfo().createVirtualRegister(LP64 ? G8RC : GPRC);
1097
1098 // rlwinm rA, rA, ShiftBits, 0, 0.
1099 BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::RLWINM8 : PPC::RLWINM), Reg)
1100 .addReg(Reg1, RegState::Kill)
1101 .addImm(getEncodingValue(SrcReg))
1102 .addImm(0).addImm(0);
1103 }
1104 addFrameReference(BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::STW8 : PPC::STW))
1105 .addReg(Reg, RegState::Kill),
1106 FrameIndex);
1107
1108 bool KillsCRBit = MI.killsRegister(SrcReg, TRI);
1109 // Discard the pseudo instruction.
1110 MBB.erase(II);
1111 if (SpillsKnownBit && KillsCRBit && !SeenUse) {
1112 Ins->setDesc(TII.get(PPC::UNENCODED_NOP));
1113 Ins->removeOperand(0);
1114 }
1115}
1116
1118 unsigned FrameIndex) const {
1119 // Get the instruction.
1120 MachineInstr &MI = *II; // ; <DestReg> = RESTORE_CRBIT <offset>
1121 // Get the instruction's basic block.
1122 MachineBasicBlock &MBB = *MI.getParent();
1123 MachineFunction &MF = *MBB.getParent();
1125 const TargetInstrInfo &TII = *Subtarget.getInstrInfo();
1126 DebugLoc dl = MI.getDebugLoc();
1127
1128 bool LP64 = TM.isPPC64();
1129 const TargetRegisterClass *G8RC = &PPC::G8RCRegClass;
1130 const TargetRegisterClass *GPRC = &PPC::GPRCRegClass;
1131
1132 Register Reg = MF.getRegInfo().createVirtualRegister(LP64 ? G8RC : GPRC);
1133 Register DestReg = MI.getOperand(0).getReg();
1134 assert(MI.definesRegister(DestReg, /*TRI=*/nullptr) &&
1135 "RESTORE_CRBIT does not define its destination");
1136
1137 addFrameReference(BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::LWZ8 : PPC::LWZ),
1138 Reg), FrameIndex);
1139
1140 BuildMI(MBB, II, dl, TII.get(TargetOpcode::IMPLICIT_DEF), DestReg);
1141
1142 Register RegO = MF.getRegInfo().createVirtualRegister(LP64 ? G8RC : GPRC);
1143 BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::MFOCRF8 : PPC::MFOCRF), RegO)
1144 .addReg(getCRFromCRBit(DestReg));
1145
1146 unsigned ShiftBits = getEncodingValue(DestReg);
1147 // rlwimi r11, r10, 32-ShiftBits, ..., ...
1148 BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::RLWIMI8 : PPC::RLWIMI), RegO)
1149 .addReg(RegO, RegState::Kill)
1150 .addReg(Reg, RegState::Kill)
1151 .addImm(ShiftBits ? 32 - ShiftBits : 0)
1152 .addImm(ShiftBits)
1153 .addImm(ShiftBits);
1154
1155 BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::MTOCRF8 : PPC::MTOCRF),
1156 getCRFromCRBit(DestReg))
1157 .addReg(RegO, RegState::Kill)
1158 // Make sure we have a use dependency all the way through this
1159 // sequence of instructions. We can't have the other bits in the CR
1160 // modified in between the mfocrf and the mtocrf.
1162
1163 // Discard the pseudo instruction.
1164 MBB.erase(II);
1165}
1166
1168 MCRegister DestReg, MCRegister SrcReg) {
1169#ifdef NDEBUG
1170 return;
1171#else
1172 if (reportAccMoves(MBB)) {
1173 std::string Dest = PPC::ACCRCRegClass.contains(DestReg) ? "acc" : "uacc";
1174 std::string Src = PPC::ACCRCRegClass.contains(SrcReg) ? "acc" : "uacc";
1175 dbgs() << "Emitting copy from " << Src << " to " << Dest << ":\n";
1176 MBB.dump();
1177 }
1178#endif
1179}
1180
1182 bool IsRestore) {
1183#ifdef NDEBUG
1184 return;
1185#else
1186 if (reportAccMoves(MBB)) {
1187 dbgs() << "Emitting " << (IsPrimed ? "acc" : "uacc") << " register "
1188 << (IsRestore ? "restore" : "spill") << ":\n";
1189 MBB.dump();
1190 }
1191#endif
1192}
1193
1194void PPCRegisterInfo::spillRegPair(MachineBasicBlock &MBB,
1196 const TargetInstrInfo &TII,
1197 unsigned FrameIndex, bool IsLittleEndian,
1198 bool IsKilled, Register Reg,
1199 int Offset) const {
1200
1201 // This function does not support virtual registers.
1202 assert(!Reg.isVirtual() &&
1203 "Spilling register pairs does not support virtual registers.");
1204
1206 BuildMI(MBB, II, DL, TII.get(PPC::STXV))
1207 .addReg(TargetRegisterInfo::getSubReg(Reg, PPC::sub_vsx0),
1208 getKillRegState(IsKilled)),
1209 FrameIndex, Offset);
1210
1212 BuildMI(MBB, II, DL, TII.get(PPC::STXV))
1213 .addReg(TargetRegisterInfo::getSubReg(Reg, PPC::sub_vsx1),
1214 getKillRegState(IsKilled)),
1215 FrameIndex, IsLittleEndian ? Offset - 16 : Offset + 16);
1216}
1217
1218/// Remove any STXVP[X] instructions and split them out into a pair of
1219/// STXV[X] instructions when paired vector stores are disabled.
1221 unsigned FrameIndex) const {
1222 MachineInstr &MI = *II; // STXVP <SrcReg>, <offset>
1223 MachineBasicBlock &MBB = *MI.getParent();
1224 MachineFunction &MF = *MBB.getParent();
1226 assert(!Subtarget.enableAutoPairedVecSt() &&
1227 "Expecting to do this only if paired vector stores are disabled.");
1228 const TargetInstrInfo &TII = *Subtarget.getInstrInfo();
1229 DebugLoc DL = MI.getDebugLoc();
1230 Register SrcReg = MI.getOperand(0).getReg();
1231 bool IsLittleEndian = Subtarget.isLittleEndian();
1232 bool IsKilled = MI.getOperand(0).isKill();
1233
1234 spillRegPair(MBB, II, DL, TII, FrameIndex, IsLittleEndian, IsKilled, SrcReg,
1235 IsLittleEndian ? 16 : 0);
1236
1237 // Discard the original instruction.
1238 MBB.erase(II);
1239}
1240
1241static void emitWAccSpillRestoreInfo(MachineBasicBlock &MBB, bool IsRestore) {
1242#ifdef NDEBUG
1243 return;
1244#else
1245 if (reportAccMoves(MBB)) {
1246 dbgs() << "Emitting wacc register " << (IsRestore ? "restore" : "spill")
1247 << ":\n";
1248 MBB.dump();
1249 }
1250#endif
1251}
1252
1253/// lowerACCSpilling - Generate the code for spilling the accumulator register.
1254/// Similarly to other spills/reloads that use pseudo-ops, we do not actually
1255/// eliminate the FrameIndex here nor compute the stack offset. We simply
1256/// create a real instruction with an FI and rely on eliminateFrameIndex to
1257/// handle the FI elimination.
1259 unsigned FrameIndex) const {
1260 MachineInstr &MI = *II; // SPILL_ACC <SrcReg>, <offset>
1261 MachineBasicBlock &MBB = *MI.getParent();
1262 MachineFunction &MF = *MBB.getParent();
1264 const TargetInstrInfo &TII = *Subtarget.getInstrInfo();
1265 DebugLoc DL = MI.getDebugLoc();
1266 Register SrcReg = MI.getOperand(0).getReg();
1267 bool IsKilled = MI.getOperand(0).isKill();
1268
1269 bool IsPrimed = PPC::ACCRCRegClass.contains(SrcReg);
1270 bool IsLittleEndian = Subtarget.isLittleEndian();
1271
1272 emitAccSpillRestoreInfo(MBB, IsPrimed, false);
1273
1274 // De-prime the register being spilled, create two stores for the pair
1275 // subregisters accounting for endianness and then re-prime the register if
1276 // it isn't killed. This uses the Offset parameter to addFrameReference() to
1277 // adjust the offset of the store that is within the 64-byte stack slot.
1278 if (IsPrimed)
1279 BuildMI(MBB, II, DL, TII.get(PPC::XXMFACC), SrcReg).addReg(SrcReg);
1280 if (!Subtarget.enableAutoPairedVecSt()) {
1281 spillRegPair(MBB, II, DL, TII, FrameIndex, IsLittleEndian, IsKilled,
1282 TargetRegisterInfo::getSubReg(SrcReg, PPC::sub_pair0),
1283 IsLittleEndian ? 48 : 0);
1284 spillRegPair(MBB, II, DL, TII, FrameIndex, IsLittleEndian, IsKilled,
1285 TargetRegisterInfo::getSubReg(SrcReg, PPC::sub_pair1),
1286 IsLittleEndian ? 16 : 32);
1287 } else {
1289 BuildMI(MBB, II, DL, TII.get(PPC::STXVP))
1290 .addReg(TargetRegisterInfo::getSubReg(SrcReg, PPC::sub_pair0),
1291 getKillRegState(IsKilled)),
1292 FrameIndex, IsLittleEndian ? 32 : 0);
1294 BuildMI(MBB, II, DL, TII.get(PPC::STXVP))
1295 .addReg(TargetRegisterInfo::getSubReg(SrcReg, PPC::sub_pair1),
1296 getKillRegState(IsKilled)),
1297 FrameIndex, IsLittleEndian ? 0 : 32);
1298 }
1299 if (IsPrimed && !IsKilled)
1300 BuildMI(MBB, II, DL, TII.get(PPC::XXMTACC), SrcReg).addReg(SrcReg);
1301
1302 // Discard the pseudo instruction.
1303 MBB.erase(II);
1304}
1305
1306/// lowerACCRestore - Generate the code to restore the accumulator register.
1308 unsigned FrameIndex) const {
1309 MachineInstr &MI = *II; // <DestReg> = RESTORE_ACC <offset>
1310 MachineBasicBlock &MBB = *MI.getParent();
1311 MachineFunction &MF = *MBB.getParent();
1313 const TargetInstrInfo &TII = *Subtarget.getInstrInfo();
1314 DebugLoc DL = MI.getDebugLoc();
1315
1316 Register DestReg = MI.getOperand(0).getReg();
1317 assert(MI.definesRegister(DestReg, /*TRI=*/nullptr) &&
1318 "RESTORE_ACC does not define its destination");
1319
1320 bool IsPrimed = PPC::ACCRCRegClass.contains(DestReg);
1321 Register Reg =
1322 PPC::VSRp0 + (DestReg - (IsPrimed ? PPC::ACC0 : PPC::UACC0)) * 2;
1323 bool IsLittleEndian = Subtarget.isLittleEndian();
1324
1325 emitAccSpillRestoreInfo(MBB, IsPrimed, true);
1326
1327 // Create two loads for the pair subregisters accounting for endianness and
1328 // then prime the accumulator register being restored.
1329 addFrameReference(BuildMI(MBB, II, DL, TII.get(PPC::LXVP), Reg),
1330 FrameIndex, IsLittleEndian ? 32 : 0);
1331 addFrameReference(BuildMI(MBB, II, DL, TII.get(PPC::LXVP), Reg + 1),
1332 FrameIndex, IsLittleEndian ? 0 : 32);
1333 if (IsPrimed)
1334 BuildMI(MBB, II, DL, TII.get(PPC::XXMTACC), DestReg).addReg(DestReg);
1335
1336 // Discard the pseudo instruction.
1337 MBB.erase(II);
1338}
1339
1340/// lowerWACCSpilling - Generate the code for spilling the wide accumulator
1341/// register.
1343 unsigned FrameIndex) const {
1344 MachineInstr &MI = *II; // SPILL_WACC <SrcReg>, <offset>
1345 MachineBasicBlock &MBB = *MI.getParent();
1346 MachineFunction &MF = *MBB.getParent();
1348 const TargetInstrInfo &TII = *Subtarget.getInstrInfo();
1349 DebugLoc DL = MI.getDebugLoc();
1350 bool IsLittleEndian = Subtarget.isLittleEndian();
1351
1353
1354 const TargetRegisterClass *RC = &PPC::VSRpRCRegClass;
1355 Register VSRpReg0 = MF.getRegInfo().createVirtualRegister(RC);
1356 Register VSRpReg1 = MF.getRegInfo().createVirtualRegister(RC);
1357 Register SrcReg = MI.getOperand(0).getReg();
1358
1359 BuildMI(MBB, II, DL, TII.get(PPC::DMXXEXTFDMR512), VSRpReg0)
1360 .addDef(VSRpReg1)
1361 .addReg(SrcReg);
1362
1363 addFrameReference(BuildMI(MBB, II, DL, TII.get(PPC::STXVP))
1364 .addReg(VSRpReg0, RegState::Kill),
1365 FrameIndex, IsLittleEndian ? 32 : 0);
1366 addFrameReference(BuildMI(MBB, II, DL, TII.get(PPC::STXVP))
1367 .addReg(VSRpReg1, RegState::Kill),
1368 FrameIndex, IsLittleEndian ? 0 : 32);
1369
1370 // Discard the pseudo instruction.
1371 MBB.erase(II);
1372}
1373
1374/// lowerWACCRestore - Generate the code to restore the wide accumulator
1375/// register.
1377 unsigned FrameIndex) const {
1378 MachineInstr &MI = *II; // <DestReg> = RESTORE_WACC <offset>
1379 MachineBasicBlock &MBB = *MI.getParent();
1380 MachineFunction &MF = *MBB.getParent();
1382 const TargetInstrInfo &TII = *Subtarget.getInstrInfo();
1383 DebugLoc DL = MI.getDebugLoc();
1384 bool IsLittleEndian = Subtarget.isLittleEndian();
1385
1387
1388 const TargetRegisterClass *RC = &PPC::VSRpRCRegClass;
1389 Register VSRpReg0 = MF.getRegInfo().createVirtualRegister(RC);
1390 Register VSRpReg1 = MF.getRegInfo().createVirtualRegister(RC);
1391 Register DestReg = MI.getOperand(0).getReg();
1392
1393 addFrameReference(BuildMI(MBB, II, DL, TII.get(PPC::LXVP), VSRpReg0),
1394 FrameIndex, IsLittleEndian ? 32 : 0);
1395 addFrameReference(BuildMI(MBB, II, DL, TII.get(PPC::LXVP), VSRpReg1),
1396 FrameIndex, IsLittleEndian ? 0 : 32);
1397
1398 // Kill VSRpReg0, VSRpReg1 (killedRegState::Killed)
1399 BuildMI(MBB, II, DL, TII.get(PPC::DMXXINSTDMR512), DestReg)
1400 .addReg(VSRpReg0, RegState::Kill)
1401 .addReg(VSRpReg1, RegState::Kill);
1402
1403 // Discard the pseudo instruction.
1404 MBB.erase(II);
1405}
1406
1407/// lowerQuadwordSpilling - Generate code to spill paired general register.
1409 unsigned FrameIndex) const {
1410 MachineInstr &MI = *II;
1411 MachineBasicBlock &MBB = *MI.getParent();
1412 MachineFunction &MF = *MBB.getParent();
1414 const TargetInstrInfo &TII = *Subtarget.getInstrInfo();
1415 DebugLoc DL = MI.getDebugLoc();
1416
1417 Register SrcReg = MI.getOperand(0).getReg();
1418 bool IsKilled = MI.getOperand(0).isKill();
1419
1420 Register Reg = PPC::X0 + (SrcReg - PPC::G8p0) * 2;
1421 bool IsLittleEndian = Subtarget.isLittleEndian();
1422
1423 addFrameReference(BuildMI(MBB, II, DL, TII.get(PPC::STD))
1424 .addReg(Reg, getKillRegState(IsKilled)),
1425 FrameIndex, IsLittleEndian ? 8 : 0);
1426 addFrameReference(BuildMI(MBB, II, DL, TII.get(PPC::STD))
1427 .addReg(Reg + 1, getKillRegState(IsKilled)),
1428 FrameIndex, IsLittleEndian ? 0 : 8);
1429
1430 // Discard the pseudo instruction.
1431 MBB.erase(II);
1432}
1433
1434/// lowerQuadwordRestore - Generate code to restore paired general register.
1436 unsigned FrameIndex) const {
1437 MachineInstr &MI = *II;
1438 MachineBasicBlock &MBB = *MI.getParent();
1439 MachineFunction &MF = *MBB.getParent();
1441 const TargetInstrInfo &TII = *Subtarget.getInstrInfo();
1442 DebugLoc DL = MI.getDebugLoc();
1443
1444 Register DestReg = MI.getOperand(0).getReg();
1445 assert(MI.definesRegister(DestReg, /*TRI=*/nullptr) &&
1446 "RESTORE_QUADWORD does not define its destination");
1447
1448 Register Reg = PPC::X0 + (DestReg - PPC::G8p0) * 2;
1449 bool IsLittleEndian = Subtarget.isLittleEndian();
1450
1451 addFrameReference(BuildMI(MBB, II, DL, TII.get(PPC::LD), Reg), FrameIndex,
1452 IsLittleEndian ? 8 : 0);
1453 addFrameReference(BuildMI(MBB, II, DL, TII.get(PPC::LD), Reg + 1), FrameIndex,
1454 IsLittleEndian ? 0 : 8);
1455
1456 // Discard the pseudo instruction.
1457 MBB.erase(II);
1458}
1459
1460/// lowerDMRSpilling - Generate the code for spilling the DMR register.
1462 unsigned FrameIndex) const {
1463 MachineInstr &MI = *II; // SPILL_DMR <SrcReg>, <offset>
1464 MachineBasicBlock &MBB = *MI.getParent();
1465 MachineFunction &MF = *MBB.getParent();
1467 const TargetInstrInfo &TII = *Subtarget.getInstrInfo();
1468 DebugLoc DL = MI.getDebugLoc();
1469 bool IsLittleEndian = Subtarget.isLittleEndian();
1470
1471 // DMR is made up of WACC and WACC_HI, so DMXXEXTFDMR512 to spill
1472 // the corresponding 512 bits.
1473 const TargetRegisterClass *RC = &PPC::VSRpRCRegClass;
1474 auto spillDMR = [&](Register SrcReg, int BEIdx, int LEIdx) {
1475 auto spillWACC = [&](unsigned Opc, unsigned RegIdx, int IdxBE, int IdxLE) {
1476 Register VSRpReg0 = MF.getRegInfo().createVirtualRegister(RC);
1477 Register VSRpReg1 = MF.getRegInfo().createVirtualRegister(RC);
1478
1479 BuildMI(MBB, II, DL, TII.get(Opc), VSRpReg0)
1480 .addDef(VSRpReg1)
1481 .addReg(TargetRegisterInfo::getSubReg(SrcReg, RegIdx));
1482
1483 addFrameReference(BuildMI(MBB, II, DL, TII.get(PPC::STXVP))
1484 .addReg(VSRpReg0, RegState::Kill),
1485 FrameIndex, IsLittleEndian ? IdxLE : IdxBE);
1486 addFrameReference(BuildMI(MBB, II, DL, TII.get(PPC::STXVP))
1487 .addReg(VSRpReg1, RegState::Kill),
1488 FrameIndex, IsLittleEndian ? IdxLE - 32 : IdxBE + 32);
1489 };
1490 spillWACC(PPC::DMXXEXTFDMR512, PPC::sub_wacc_lo, BEIdx, LEIdx);
1491 spillWACC(PPC::DMXXEXTFDMR512_HI, PPC::sub_wacc_hi, BEIdx + 64, LEIdx - 64);
1492 };
1493
1494 Register SrcReg = MI.getOperand(0).getReg();
1495 if (MI.getOpcode() == PPC::SPILL_DMRP) {
1496 spillDMR(TargetRegisterInfo::getSubReg(SrcReg, PPC::sub_dmr1), 0, 96);
1497 spillDMR(TargetRegisterInfo::getSubReg(SrcReg, PPC::sub_dmr0), 128, 224);
1498 } else
1499 spillDMR(SrcReg, 0, 96);
1500
1501 // Discard the pseudo instruction.
1502 MBB.erase(II);
1503}
1504
1505/// lowerDMRRestore - Generate the code to restore the DMR register.
1507 unsigned FrameIndex) const {
1508 MachineInstr &MI = *II; // <DestReg> = RESTORE_DMR[P] <offset>
1509 MachineBasicBlock &MBB = *MI.getParent();
1510 MachineFunction &MF = *MBB.getParent();
1512 const TargetInstrInfo &TII = *Subtarget.getInstrInfo();
1513 DebugLoc DL = MI.getDebugLoc();
1514 bool IsLittleEndian = Subtarget.isLittleEndian();
1515
1516 const TargetRegisterClass *RC = &PPC::VSRpRCRegClass;
1517 auto restoreDMR = [&](Register DestReg, int BEIdx, int LEIdx) {
1518 auto restoreWACC = [&](unsigned Opc, unsigned RegIdx, int IdxBE,
1519 int IdxLE) {
1520 Register VSRpReg0 = MF.getRegInfo().createVirtualRegister(RC);
1521 Register VSRpReg1 = MF.getRegInfo().createVirtualRegister(RC);
1522
1523 addFrameReference(BuildMI(MBB, II, DL, TII.get(PPC::LXVP), VSRpReg0),
1524 FrameIndex, IsLittleEndian ? IdxLE : IdxBE);
1525 addFrameReference(BuildMI(MBB, II, DL, TII.get(PPC::LXVP), VSRpReg1),
1526 FrameIndex, IsLittleEndian ? IdxLE - 32 : IdxBE + 32);
1527
1528 // Kill virtual registers (killedRegState::Killed).
1529 BuildMI(MBB, II, DL, TII.get(Opc),
1530 TargetRegisterInfo::getSubReg(DestReg, RegIdx))
1531 .addReg(VSRpReg0, RegState::Kill)
1532 .addReg(VSRpReg1, RegState::Kill);
1533 };
1534 restoreWACC(PPC::DMXXINSTDMR512, PPC::sub_wacc_lo, BEIdx, LEIdx);
1535 restoreWACC(PPC::DMXXINSTDMR512_HI, PPC::sub_wacc_hi, BEIdx + 64,
1536 LEIdx - 64);
1537 };
1538
1539 Register DestReg = MI.getOperand(0).getReg();
1540 if (MI.getOpcode() == PPC::RESTORE_DMRP) {
1541 restoreDMR(TargetRegisterInfo::getSubReg(DestReg, PPC::sub_dmr1), 0, 96);
1542 restoreDMR(TargetRegisterInfo::getSubReg(DestReg, PPC::sub_dmr0), 128, 224);
1543 } else
1544 restoreDMR(DestReg, 0, 96);
1545
1546 // Discard the pseudo instruction.
1547 MBB.erase(II);
1548}
1549
1551 Register Reg, int &FrameIdx) const {
1552 // For the nonvolatile condition registers (CR2, CR3, CR4) return true to
1553 // prevent allocating an additional frame slot.
1554 // For 64-bit ELF and AIX, the CR save area is in the linkage area at SP+8,
1555 // for 32-bit AIX the CR save area is in the linkage area at SP+4.
1556 // We have created a FrameIndex to that spill slot to keep the CalleSaveInfos
1557 // valid.
1558 // For 32-bit ELF, we have previously created the stack slot if needed, so
1559 // return its FrameIdx.
1560 if (PPC::CR2 <= Reg && Reg <= PPC::CR4) {
1561 FrameIdx = MF.getInfo<PPCFunctionInfo>()->getCRSpillFrameIndex();
1562 return true;
1563 }
1564 return false;
1565}
1566
1567// If the offset must be a multiple of some value, return what that value is.
1568static unsigned offsetMinAlignForOpcode(unsigned OpC) {
1569 switch (OpC) {
1570 default:
1571 return 1;
1572 case PPC::LWA:
1573 case PPC::LWA_32:
1574 case PPC::LD:
1575 case PPC::LDU:
1576 case PPC::STD:
1577 case PPC::STDU:
1578 case PPC::DFLOADf32:
1579 case PPC::DFLOADf64:
1580 case PPC::DFSTOREf32:
1581 case PPC::DFSTOREf64:
1582 case PPC::LXSD:
1583 case PPC::LXSSP:
1584 case PPC::STXSD:
1585 case PPC::STXSSP:
1586 case PPC::STQ:
1587 return 4;
1588 case PPC::EVLDD:
1589 case PPC::EVSTDD:
1590 return 8;
1591 case PPC::LXV:
1592 case PPC::STXV:
1593 case PPC::LQ:
1594 case PPC::LXVP:
1595 case PPC::STXVP:
1596 return 16;
1597 }
1598}
1599
1600// If the offset must be a multiple of some value, return what that value is.
1601static unsigned offsetMinAlign(const MachineInstr &MI) {
1602 unsigned OpC = MI.getOpcode();
1603 return offsetMinAlignForOpcode(OpC);
1604}
1605
1606// Check that the offset fits in the instruction's immediate displacement field.
1607static bool offsetFitsImmForm(unsigned OpC, int64_t Offset) {
1608 // The SPE doubleword loads and stores have a 5-bit displacement, scaled by 8.
1609 if (OpC == PPC::EVSTDD || OpC == PPC::EVLDD)
1611 return isInt<16>(Offset);
1612}
1613
1614// Return the OffsetOperandNo given the FIOperandNum (and the instruction).
1615static unsigned getOffsetONFromFION(const MachineInstr &MI,
1616 unsigned FIOperandNum) {
1617 // Take into account whether it's an add or mem instruction
1618 unsigned OffsetOperandNo = (FIOperandNum == 2) ? 1 : 2;
1619 if (MI.isInlineAsm())
1620 OffsetOperandNo = FIOperandNum - 1;
1621 else if (MI.getOpcode() == TargetOpcode::STACKMAP ||
1622 MI.getOpcode() == TargetOpcode::PATCHPOINT)
1623 OffsetOperandNo = FIOperandNum + 1;
1624
1625 return OffsetOperandNo;
1626}
1627
1628bool
1630 int SPAdj, unsigned FIOperandNum,
1631 RegScavenger *RS) const {
1632 assert(SPAdj == 0 && "Unexpected");
1633
1634 // Get the instruction.
1635 MachineInstr &MI = *II;
1636 // Get the instruction's basic block.
1637 MachineBasicBlock &MBB = *MI.getParent();
1638 // Get the basic block's function.
1639 MachineFunction &MF = *MBB.getParent();
1641 // Get the instruction info.
1642 const PPCInstrInfo &TII = *Subtarget.getInstrInfo();
1643 // Get the frame info.
1644 MachineFrameInfo &MFI = MF.getFrameInfo();
1645 DebugLoc dl = MI.getDebugLoc();
1646
1647 unsigned OffsetOperandNo = getOffsetONFromFION(MI, FIOperandNum);
1648
1649 // Get the frame index.
1650 int FrameIndex = MI.getOperand(FIOperandNum).getIndex();
1651
1652 // Get the frame pointer save index. Users of this index are primarily
1653 // DYNALLOC instructions.
1655 int FPSI = FI->getFramePointerSaveIndex();
1656 // Get the instruction opcode.
1657 unsigned OpC = MI.getOpcode();
1658
1659 switch (OpC) {
1660 default:
1661 break;
1662 case PPC::DYNAREAOFFSET:
1663 case PPC::DYNAREAOFFSET8:
1665 // lowerDynamicAreaOffset erases II
1666 return true;
1667 case PPC::DYNALLOC:
1668 case PPC::DYNALLOC8: {
1669 // Special case for dynamic alloca.
1670 if (FPSI && FrameIndex == FPSI) {
1671 lowerDynamicAlloc(II); // lowerDynamicAlloc erases II
1672 return true;
1673 }
1674 break;
1675 }
1676 case PPC::PREPARE_PROBED_ALLOCA_64:
1677 case PPC::PREPARE_PROBED_ALLOCA_32:
1678 case PPC::PREPARE_PROBED_ALLOCA_NEGSIZE_SAME_REG_64:
1679 case PPC::PREPARE_PROBED_ALLOCA_NEGSIZE_SAME_REG_32: {
1680 if (FPSI && FrameIndex == FPSI) {
1681 lowerPrepareProbedAlloca(II); // lowerPrepareProbedAlloca erases II
1682 return true;
1683 }
1684 break;
1685 }
1686 case PPC::SPILL_CR:
1687 // Special case for pseudo-ops SPILL_CR and RESTORE_CR, etc.
1688 lowerCRSpilling(II, FrameIndex);
1689 return true;
1690 case PPC::RESTORE_CR:
1691 lowerCRRestore(II, FrameIndex);
1692 return true;
1693 case PPC::SPILL_CRBIT:
1694 lowerCRBitSpilling(II, FrameIndex);
1695 return true;
1696 case PPC::RESTORE_CRBIT:
1697 lowerCRBitRestore(II, FrameIndex);
1698 return true;
1699 case PPC::SPILL_ACC:
1700 case PPC::SPILL_UACC:
1701 lowerACCSpilling(II, FrameIndex);
1702 return true;
1703 case PPC::RESTORE_ACC:
1704 case PPC::RESTORE_UACC:
1705 lowerACCRestore(II, FrameIndex);
1706 return true;
1707 case PPC::STXVP: {
1708 if (!Subtarget.enableAutoPairedVecSt()) {
1709 lowerOctWordSpilling(II, FrameIndex);
1710 return true;
1711 }
1712 break;
1713 }
1714 case PPC::SPILL_WACC:
1715 lowerWACCSpilling(II, FrameIndex);
1716 return true;
1717 case PPC::RESTORE_WACC:
1718 lowerWACCRestore(II, FrameIndex);
1719 return true;
1720 case PPC::SPILL_DMRP:
1721 case PPC::SPILL_DMR:
1722 lowerDMRSpilling(II, FrameIndex);
1723 return true;
1724 case PPC::RESTORE_DMRP:
1725 case PPC::RESTORE_DMR:
1726 lowerDMRRestore(II, FrameIndex);
1727 return true;
1728 case PPC::SPILL_QUADWORD:
1729 lowerQuadwordSpilling(II, FrameIndex);
1730 return true;
1731 case PPC::RESTORE_QUADWORD:
1732 lowerQuadwordRestore(II, FrameIndex);
1733 return true;
1734 }
1735
1736 // Replace the FrameIndex with base register with GPR1 (SP) or GPR31 (FP).
1737 MI.getOperand(FIOperandNum).ChangeToRegister(
1738 FrameIndex < 0 ? getBaseRegister(MF) : getFrameRegister(MF), false);
1739
1740 // If the instruction is not present in ImmToIdxMap, then it has no immediate
1741 // form (and must be r+r).
1742 bool noImmForm = !MI.isInlineAsm() && OpC != TargetOpcode::STACKMAP &&
1743 OpC != TargetOpcode::PATCHPOINT && !ImmToIdxMap.count(OpC);
1744
1745 // Now add the frame object offset to the offset from r1.
1746 int64_t Offset = MFI.getObjectOffset(FrameIndex);
1747 Offset += MI.getOperand(OffsetOperandNo).getImm();
1748
1749 // If we're not using a Frame Pointer that has been set to the value of the
1750 // SP before having the stack size subtracted from it, then add the stack size
1751 // to Offset to get the correct offset.
1752 // Naked functions have stack size 0, although getStackSize may not reflect
1753 // that because we didn't call all the pieces that compute it for naked
1754 // functions.
1755 if (!MF.getFunction().hasFnAttribute(Attribute::Naked)) {
1756 if (!(hasBasePointer(MF) && FrameIndex < 0))
1757 Offset += MFI.getStackSize();
1758 }
1759
1760 // If we encounter an LXVP/STXVP with an offset that doesn't fit, we can
1761 // transform it to the prefixed version so we don't have to use the XForm.
1762 if ((OpC == PPC::LXVP || OpC == PPC::STXVP) &&
1763 (!isInt<16>(Offset) || (Offset % offsetMinAlign(MI)) != 0) &&
1764 Subtarget.hasPrefixInstrs() && Subtarget.hasP10Vector()) {
1765 unsigned NewOpc = OpC == PPC::LXVP ? PPC::PLXVP : PPC::PSTXVP;
1766 MI.setDesc(TII.get(NewOpc));
1767 OpC = NewOpc;
1768 }
1769
1770 // If we can, encode the offset directly into the instruction. If this is a
1771 // normal PPC "ri" instruction, any 16-bit value can be safely encoded. If
1772 // this is a PPC64 "ix" instruction, only a 16-bit value with the low two bits
1773 // clear can be encoded. This is extremely uncommon, because normally you
1774 // only "std" to a stack slot that is at least 4-byte aligned, but it can
1775 // happen in invalid code.
1776 assert(OpC != PPC::DBG_VALUE &&
1777 "This should be handled in a target-independent way");
1778 // FIXME: This should be factored out to a separate function as prefixed
1779 // instructions add a number of opcodes for which we can use 34-bit imm.
1780 bool OffsetFitsMnemonic = offsetFitsImmForm(OpC, Offset);
1781 if (TII.isPrefixed(MI.getOpcode()))
1782 OffsetFitsMnemonic = isInt<34>(Offset);
1783 if (!noImmForm && ((OffsetFitsMnemonic &&
1784 ((Offset % offsetMinAlign(MI)) == 0)) ||
1785 OpC == TargetOpcode::STACKMAP ||
1786 OpC == TargetOpcode::PATCHPOINT)) {
1787 MI.getOperand(OffsetOperandNo).ChangeToImmediate(Offset);
1788 return false;
1789 }
1790
1791 // The offset doesn't fit into a single register, scavenge one to build the
1792 // offset in.
1793
1794 bool is64Bit = TM.isPPC64();
1795 const TargetRegisterClass *G8RC = &PPC::G8RCRegClass;
1796 const TargetRegisterClass *GPRC = &PPC::GPRCRegClass;
1797 const TargetRegisterClass *RC = is64Bit ? G8RC : GPRC;
1798 unsigned NewOpcode = 0u;
1799 bool ScavengingFailed = RS && RS->getRegsAvailable(RC).none() &&
1800 RS->getRegsAvailable(&PPC::VSFRCRegClass).any();
1801 Register SRegHi, SReg, VSReg;
1802
1803 // The register scavenger is unable to get a GPR but can get a VSR. We
1804 // need to stash a GPR into a VSR so that we can free one up.
1805 if (ScavengingFailed && Subtarget.hasDirectMove()) {
1806 // Pick a volatile register and if we are spilling/restoring that
1807 // particular one, pick the next one.
1808 SRegHi = SReg = is64Bit ? PPC::X4 : PPC::R4;
1809 if (MI.getOperand(0).getReg() == SReg)
1810 SRegHi = SReg = SReg + 1;
1811 VSReg = MF.getRegInfo().createVirtualRegister(&PPC::VSFRCRegClass);
1812 BuildMI(MBB, II, dl, TII.get(is64Bit ? PPC::MTVSRD : PPC::MTVSRWZ), VSReg)
1813 .addReg(SReg);
1814 } else {
1815 SRegHi = MF.getRegInfo().createVirtualRegister(RC);
1816 SReg = MF.getRegInfo().createVirtualRegister(RC);
1817 }
1818
1819 // Insert a set of rA with the full offset value before the ld, st, or add
1820 if (isInt<16>(Offset))
1821 BuildMI(MBB, II, dl, TII.get(is64Bit ? PPC::LI8 : PPC::LI), SReg)
1822 .addImm(Offset);
1823 else if (isInt<32>(Offset)) {
1824 BuildMI(MBB, II, dl, TII.get(is64Bit ? PPC::LIS8 : PPC::LIS), SRegHi)
1825 .addImm(Offset >> 16);
1826 BuildMI(MBB, II, dl, TII.get(is64Bit ? PPC::ORI8 : PPC::ORI), SReg)
1827 .addReg(SRegHi, RegState::Kill)
1828 .addImm(Offset);
1829 } else {
1830 assert(is64Bit && "Huge stack is only supported on PPC64");
1831 TII.materializeImmPostRA(MBB, II, dl, SReg, Offset);
1832 }
1833
1834 // Convert into indexed form of the instruction:
1835 //
1836 // sth 0:rA, 1:imm 2:(rB) ==> sthx 0:rA, 2:rB, 1:r0
1837 // addi 0:rA 1:rB, 2, imm ==> add 0:rA, 1:rB, 2:r0
1838 unsigned OperandBase;
1839
1840 if (noImmForm)
1841 OperandBase = 1;
1842 else if (OpC != TargetOpcode::INLINEASM &&
1843 OpC != TargetOpcode::INLINEASM_BR) {
1844 assert(ImmToIdxMap.count(OpC) &&
1845 "No indexed form of load or store available!");
1846 NewOpcode = ImmToIdxMap.find(OpC)->second;
1847 MI.setDesc(TII.get(NewOpcode));
1848 OperandBase = 1;
1849 } else {
1850 OperandBase = OffsetOperandNo;
1851 }
1852
1853 Register StackReg = MI.getOperand(FIOperandNum).getReg();
1854 MI.getOperand(OperandBase).ChangeToRegister(StackReg, false);
1855 MI.getOperand(OperandBase + 1).ChangeToRegister(SReg, false, false, true);
1856
1857 // If we stashed a value from a GPR into a VSR, we need to get it back after
1858 // spilling the register.
1859 if (ScavengingFailed && Subtarget.hasDirectMove())
1860 BuildMI(MBB, ++II, dl, TII.get(is64Bit ? PPC::MFVSRD : PPC::MFVSRWZ), SReg)
1861 .addReg(VSReg);
1862
1863 // Since these are not real X-Form instructions, we must
1864 // add the registers and access 0(NewReg) rather than
1865 // emitting the X-Form pseudo.
1866 if (NewOpcode == PPC::LQX_PSEUDO || NewOpcode == PPC::STQX_PSEUDO) {
1867 assert(is64Bit && "Quadword loads/stores only supported in 64-bit mode");
1868 Register NewReg = MF.getRegInfo().createVirtualRegister(&PPC::G8RCRegClass);
1869 BuildMI(MBB, II, dl, TII.get(PPC::ADD8), NewReg)
1870 .addReg(SReg, RegState::Kill)
1871 .addReg(StackReg);
1872 MI.setDesc(TII.get(NewOpcode == PPC::LQX_PSEUDO ? PPC::LQ : PPC::STQ));
1873 MI.getOperand(OperandBase + 1).ChangeToRegister(NewReg, false);
1874 MI.getOperand(OperandBase).ChangeToImmediate(0);
1875 }
1876 return false;
1877}
1878
1880 const PPCFrameLowering *TFI = getFrameLowering(MF);
1881
1882 if (!TM.isPPC64())
1883 return TFI->hasFP(MF) ? PPC::R31 : PPC::R1;
1884 else
1885 return TFI->hasFP(MF) ? PPC::X31 : PPC::X1;
1886}
1887
1890 if (!hasBasePointer(MF))
1891 return getFrameRegister(MF);
1892
1893 if (TM.isPPC64())
1894 return PPC::X30;
1895
1896 if (Subtarget.isSVR4ABI() && TM.isPositionIndependent())
1897 return PPC::R29;
1898
1899 return PPC::R30;
1900}
1901
1903 if (!TM.getCLOpts().use_base_pointer)
1904 return false;
1905 if (TM.getCLOpts().always_use_base_pointer)
1906 return true;
1907
1908 // If we need to realign the stack, then the stack pointer can no longer
1909 // serve as an offset into the caller's stack space. As a result, we need a
1910 // base pointer.
1911 return hasStackRealignment(MF);
1912}
1913
1914/// Returns true if the instruction's frame index
1915/// reference would be better served by a base register other than FP
1916/// or SP. Used by LocalStackFrameAllocation to determine which frame index
1917/// references it should create new base registers for.
1919needsFrameBaseReg(MachineInstr *MI, int64_t Offset) const {
1920 assert(Offset < 0 && "Local offset must be negative");
1921
1922 // It's the load/store FI references that cause issues, as it can be difficult
1923 // to materialize the offset if it won't fit in the literal field. Estimate
1924 // based on the size of the local frame and some conservative assumptions
1925 // about the rest of the stack frame (note, this is pre-regalloc, so
1926 // we don't know everything for certain yet) whether this offset is likely
1927 // to be out of range of the immediate. Return true if so.
1928
1929 // We only generate virtual base registers for loads and stores that have
1930 // an r+i form. Return false for everything else.
1931 unsigned OpC = MI->getOpcode();
1932 if (!ImmToIdxMap.count(OpC))
1933 return false;
1934
1935 // Don't generate a new virtual base register just to add zero to it.
1936 if ((OpC == PPC::ADDI || OpC == PPC::ADDI8) &&
1937 MI->getOperand(2).getImm() == 0)
1938 return false;
1939
1940 MachineBasicBlock &MBB = *MI->getParent();
1941 MachineFunction &MF = *MBB.getParent();
1942 const PPCFrameLowering *TFI = getFrameLowering(MF);
1943 unsigned StackEst = TFI->determineFrameLayout(MF, true);
1944
1945 // If we likely don't need a stack frame, then we probably don't need a
1946 // virtual base register either.
1947 if (!StackEst)
1948 return false;
1949
1950 // Estimate an offset from the stack pointer.
1951 // The incoming offset is relating to the SP at the start of the function,
1952 // but when we access the local it'll be relative to the SP after local
1953 // allocation, so adjust our SP-relative offset by that allocation size.
1954 Offset += StackEst;
1955
1956 // The frame pointer will point to the end of the stack, so estimate the
1957 // offset as the difference between the object offset and the FP location.
1959}
1960
1961/// Insert defining instruction(s) for BaseReg to
1962/// be a pointer to FrameIdx at the beginning of the basic block.
1964 int FrameIdx,
1965 int64_t Offset) const {
1966 unsigned ADDriOpc = TM.isPPC64() ? PPC::ADDI8 : PPC::ADDI;
1967
1968 MachineBasicBlock::iterator Ins = MBB->begin();
1969 DebugLoc DL; // Defaults to "unknown"
1970 if (Ins != MBB->end())
1971 DL = Ins->getDebugLoc();
1972
1973 const MachineFunction &MF = *MBB->getParent();
1975 const TargetInstrInfo &TII = *Subtarget.getInstrInfo();
1976 const MCInstrDesc &MCID = TII.get(ADDriOpc);
1977 MachineRegisterInfo &MRI = MBB->getParent()->getRegInfo();
1978 Register BaseReg = MRI.createVirtualRegister(TII.getRegClass(MCID, 0));
1979
1980 BuildMI(*MBB, Ins, DL, MCID, BaseReg)
1981 .addFrameIndex(FrameIdx).addImm(Offset);
1982
1983 return BaseReg;
1984}
1985
1987 int64_t Offset) const {
1988 unsigned FIOperandNum = 0;
1989 while (!MI.getOperand(FIOperandNum).isFI()) {
1990 ++FIOperandNum;
1991 assert(FIOperandNum < MI.getNumOperands() &&
1992 "Instr doesn't have FrameIndex operand!");
1993 }
1994
1995 MI.getOperand(FIOperandNum).ChangeToRegister(BaseReg, false);
1996 unsigned OffsetOperandNo = getOffsetONFromFION(MI, FIOperandNum);
1997 Offset += MI.getOperand(OffsetOperandNo).getImm();
1998 MI.getOperand(OffsetOperandNo).ChangeToImmediate(Offset);
1999
2000 MachineBasicBlock &MBB = *MI.getParent();
2001 MachineFunction &MF = *MBB.getParent();
2003 const TargetInstrInfo &TII = *Subtarget.getInstrInfo();
2004 const MCInstrDesc &MCID = MI.getDesc();
2006 MRI.constrainRegClass(BaseReg, TII.getRegClass(MCID, FIOperandNum));
2007}
2008
2010 Register BaseReg,
2011 int64_t Offset) const {
2012 unsigned FIOperandNum = 0;
2013 while (!MI->getOperand(FIOperandNum).isFI()) {
2014 ++FIOperandNum;
2015 assert(FIOperandNum < MI->getNumOperands() &&
2016 "Instr doesn't have FrameIndex operand!");
2017 }
2018
2019 unsigned OffsetOperandNo = getOffsetONFromFION(*MI, FIOperandNum);
2020 Offset += MI->getOperand(OffsetOperandNo).getImm();
2021
2022 return MI->getOpcode() == PPC::DBG_VALUE || // DBG_VALUE is always Reg+Imm
2023 MI->getOpcode() == TargetOpcode::STACKMAP ||
2024 MI->getOpcode() == TargetOpcode::PATCHPOINT ||
2025 (offsetFitsImmForm(MI->getOpcode(), Offset) &&
2026 (Offset % offsetMinAlign(*MI)) == 0);
2027}
const AArch64Subtarget & Subtarget
static const TargetRegisterClass * getRegClass(const MachineInstr &MI, Register Reg)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file implements the BitVector class.
const HexagonInstrInfo * TII
IRTranslator LLVM IR MI
Live Register Matrix
Register Reg
Register const TargetRegisterInfo * TRI
modulo schedule test
uint64_t IntrinsicInst * II
static bool offsetFitsImmForm(unsigned OpC, int64_t Offset)
static void emitWAccSpillRestoreInfo(MachineBasicBlock &MBB, bool IsRestore)
static unsigned getOffsetONFromFION(const MachineInstr &MI, unsigned FIOperandNum)
static bool reportAccMoves(const MachineBasicBlock &MBB)
static unsigned offsetMinAlignForOpcode(unsigned OpC)
static void emitAccSpillRestoreInfo(MachineBasicBlock &MBB, bool IsPrimed, bool IsRestore)
static unsigned offsetMinAlign(const MachineInstr &MI)
RISCVCC::CondCode CC
MachineRegisterInfo & MRI
This file declares the machine register scavenger class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
Definition Statistic.h:171
#define LLVM_DEBUG(...)
Definition Debug.h:119
static bool is64Bit(const char *name)
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
bool test(unsigned Idx) const
Returns true if bit Idx is set.
Definition BitVector.h:483
The CalleeSavedInfo class tracks the information need to locate where a callee saved register is in t...
A debug info location.
Definition DebugLoc.h:127
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
Definition Function.h:273
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition Function.cpp:731
Describe properties that are true of each instruction in the target description file.
MCRegAliasIterator enumerates all registers aliasing Reg.
ArrayRef< unsigned > superclasses() const
Returns a list of super-classes.
unsigned getID() const
getID() - Return the register class ID number.
bool contains(MCRegister Reg) const
contains - Return true if the specified register is included in this register class.
MCRegister getSubReg(MCRegister Reg, unsigned Idx) const
Returns the physical register number of sub-register "Index" for physical register RegNo.
Wrapper class representing physical registers. Should be passed by value.
Definition MCRegister.h:41
constexpr bool isPhysical() const
Return true if the specified register number is in the physical register namespace.
Definition MCRegister.h:72
MachineInstrBundleIterator< MachineInstr, true > reverse_iterator
MachineInstrBundleIterator< MachineInstr > iterator
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects.
Align getMaxAlign() const
Return alignment of this function's frame.
uint64_t getMaxCallFrameSize() const
Return the maximum size of a call frame that must be allocated for an outgoing function call.
bool isCalleeSavedInfoValid() const
Has the callee saved info been calculated yet?
const std::vector< CalleeSavedInfo > & getCalleeSavedInfo() const
Returns a reference to call saved info vector for the current function.
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
bool isFixedObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a fixed stack object.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
bool hasInlineAsm() const
Returns true if the function contains any inline assembly.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Function & getFunction()
Return the LLVM function that this machine code represents.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
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.
const MachineInstrBuilder & addFrameIndex(int Idx) const
const MachineInstrBuilder & addDef(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a virtual register definition operand.
Representation of each machine instruction.
MachineOperand class - Representation of each machine instruction operand.
unsigned getSubReg() const
Register getReg() const
getReg - Returns the register number.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
LLVM_ABI Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
bool isAllocatable(MCRegister PhysReg) const
isAllocatable - Returns true when PhysReg belongs to an allocatable register class and it hasn't been...
uint64_t determineFrameLayout(const MachineFunction &MF, bool UseEstimate=false, unsigned *NewMaxCallFrameSize=nullptr) const
Determine the frame layout but do not update the machine function.
PPCFunctionInfo - This class is derived from MachineFunction private PowerPC target-specific informat...
void resolveFrameIndex(MachineInstr &MI, Register BaseReg, int64_t Offset) const override
Register getFrameRegister(const MachineFunction &MF) const override
bool hasBasePointer(const MachineFunction &MF) const
Register getBaseRegister(const MachineFunction &MF) const
void lowerDMRRestore(MachineBasicBlock::iterator II, unsigned FrameIndex) const
lowerDMRRestore - Generate the code to restore the DMR register.
void prepareDynamicAlloca(MachineBasicBlock::iterator II, Register &NegSizeReg, bool &KillNegSizeReg, Register &FramePointer) const
To accomplish dynamic stack allocation, we have to calculate exact size subtracted from the stack poi...
void lowerCRBitSpilling(MachineBasicBlock::iterator II, unsigned FrameIndex) const
void lowerACCSpilling(MachineBasicBlock::iterator II, unsigned FrameIndex) const
lowerACCSpilling - Generate the code for spilling the accumulator register.
bool requiresFrameIndexScavenging(const MachineFunction &MF) const override
void lowerCRSpilling(MachineBasicBlock::iterator II, unsigned FrameIndex) const
lowerCRSpilling - Generate the code for spilling a CR register.
void lowerDynamicAreaOffset(MachineBasicBlock::iterator II) const
void lowerDynamicAlloc(MachineBasicBlock::iterator II) const
lowerDynamicAlloc - Generate the code for allocating an object in the current frame.
const uint32_t * getCallPreservedMask(const MachineFunction &MF, CallingConv::ID CC) const override
void adjustStackMapLiveOutMask(uint32_t *Mask) const override
bool hasReservedSpillSlot(const MachineFunction &MF, Register Reg, int &FrameIdx) const override
bool isCallerPreservedPhysReg(MCRegister PhysReg, const MachineFunction &MF) const override
bool needsFrameBaseReg(MachineInstr *MI, int64_t Offset) const override
Returns true if the instruction's frame index reference would be better served by a base register oth...
const TargetRegisterClass * getCrossCopyRegClass(const TargetRegisterClass *RC) const override
const uint32_t * getNoPreservedMask() const override
void lowerDMRSpilling(MachineBasicBlock::iterator II, unsigned FrameIndex) const
lowerDMRSpilling - Generate the code for spilling the DMR register.
void lowerCRRestore(MachineBasicBlock::iterator II, unsigned FrameIndex) const
bool eliminateFrameIndex(MachineBasicBlock::iterator II, int SPAdj, unsigned FIOperandNum, RegScavenger *RS=nullptr) const override
void lowerQuadwordRestore(MachineBasicBlock::iterator II, unsigned FrameIndex) const
lowerQuadwordRestore - Generate code to restore paired general register.
static void emitAccCopyInfo(MachineBasicBlock &MBB, MCRegister DestReg, MCRegister SrcReg)
bool requiresVirtualBaseRegisters(const MachineFunction &MF) const override
void lowerCRBitRestore(MachineBasicBlock::iterator II, unsigned FrameIndex) const
const MCPhysReg * getCalleeSavedRegs(const MachineFunction *MF) const override
Code Generation virtual methods...
bool getRegAllocationHints(Register VirtReg, ArrayRef< MCPhysReg > Order, SmallSetVector< MCPhysReg, 16 > &Hints, const MachineFunction &MF, const VirtRegMap *VRM, const LiveRegMatrix *Matrix) const override
Register materializeFrameBaseRegister(MachineBasicBlock *MBB, int FrameIdx, int64_t Offset) const override
Insert defining instruction(s) for BaseReg to be a pointer to FrameIdx at the beginning of the basic ...
unsigned getRegPressureLimit(const TargetRegisterClass *RC, MachineFunction &MF) const override
void lowerWACCRestore(MachineBasicBlock::iterator II, unsigned FrameIndex) const
lowerWACCRestore - Generate the code to restore the wide accumulator register.
void lowerPrepareProbedAlloca(MachineBasicBlock::iterator II) const
void lowerQuadwordSpilling(MachineBasicBlock::iterator II, unsigned FrameIndex) const
lowerQuadwordSpilling - Generate code to spill paired general register.
PPCRegisterInfo(const PPCTargetMachine &TM)
bool isFrameOffsetLegal(const MachineInstr *MI, Register BaseReg, int64_t Offset) const override
void lowerWACCSpilling(MachineBasicBlock::iterator II, unsigned FrameIndex) const
lowerWACCSpilling - Generate the code for spilling the wide accumulator register.
void lowerOctWordSpilling(MachineBasicBlock::iterator II, unsigned FrameIndex) const
Remove any STXVP[X] instructions and split them out into a pair of STXV[X] instructions when paired v...
bool isAsmClobberable(const MachineFunction &MF, MCRegister PhysReg) const override
BitVector getReservedRegs(const MachineFunction &MF) const override
const TargetRegisterClass * getLargestLegalSuperClass(const TargetRegisterClass *RC, const MachineFunction &MF) const override
void lowerACCRestore(MachineBasicBlock::iterator II, unsigned FrameIndex) const
lowerACCRestore - Generate the code to restore the accumulator register.
Common code between 32-bit and 64-bit PowerPC targets.
Wrapper class representing virtual and physical registers.
Definition Register.h:20
constexpr bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
Definition Register.h:79
bool insert(const value_type &X)
Insert a new element into the SetVector.
Definition SetVector.h:157
A SetVector that performs no allocations if smaller than a certain size.
Definition SetVector.h:346
bool hasFP(const MachineFunction &MF) const
hasFP - Return true if the specified function should have a dedicated frame pointer register.
Align getStackAlign() const
getStackAlignment - This method returns the number of bytes to which the stack pointer must be aligne...
TargetInstrInfo - Interface to description of machine instruction set.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual const TargetRegisterClass * getLargestLegalSuperClass(const TargetRegisterClass *RC, const MachineFunction &) const
Returns the largest super class of RC that is legal to use in the current sub-target and has the same...
virtual bool getRegAllocationHints(Register VirtReg, ArrayRef< MCPhysReg > Order, SmallSetVector< MCPhysReg, 16 > &Hints, const MachineFunction &MF, const VirtRegMap *VRM=nullptr, const LiveRegMatrix *Matrix=nullptr) const
Get a list of 'hint' registers that the register allocator should try first when allocating a physica...
A Use represents the edge between a Value definition and its users.
Definition Use.h:35
MCRegister getPhys(Register virtReg) const
returns the physical register mapped to the specified virtual register
Definition VirtRegMap.h:89
bool hasPhys(Register virtReg) const
returns true if the specified virtual register is mapped to a physical register
Definition VirtRegMap.h:85
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
@ AnyReg
OBSOLETED - Used for stack based JavaScript calls.
Definition CallingConv.h:60
@ Cold
Attempts to make code in the caller as efficient as possible under the assumption that the call is no...
Definition CallingConv.h:47
Define some predicates that are used for node matching.
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.
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
Definition MathExtras.h:166
@ Implicit
Not emitted register (e.g. carry, or temporary result).
@ Kill
The last use of a register.
@ Undef
Value of the register doesn't matter.
constexpr RegState getKillRegState(bool B)
bool isAligned(Align Lhs, uint64_t SizeInBytes)
Checks that SizeInBytes is a multiple of the alignment.
Definition Alignment.h:139
static const MachineInstrBuilder & addFrameReference(const MachineInstrBuilder &MIB, int FI, int Offset=0, bool mem=true)
addFrameReference - This function is used to add a reference to the base of an abstract object on the...
static unsigned getCRFromCRBit(unsigned SrcReg)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition Error.cpp:163
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
Definition MCRegister.h:21
LLVM_ABI Printable printReg(Register Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.
constexpr bool isShiftedUInt(uint64_t x)
Checks if a unsigned integer is an N bit number shifted left by S.
Definition MathExtras.h:199
MCRegisterClass TargetRegisterClass
Definition FastISel.h:58
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
constexpr uint64_t value() const
This is a hole in the type system and should not be abused.
Definition Alignment.h:82