LLVM  5.0.0
PPCRegisterInfo.cpp
Go to the documentation of this file.
1 //===-- PPCRegisterInfo.cpp - PowerPC Register Information ----------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains the PowerPC implementation of the TargetRegisterInfo
11 // class.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #include "PPCRegisterInfo.h"
16 #include "PPC.h"
17 #include "PPCFrameLowering.h"
18 #include "PPCInstrBuilder.h"
19 #include "PPCMachineFunctionInfo.h"
20 #include "PPCSubtarget.h"
21 #include "PPCTargetMachine.h"
22 #include "llvm/ADT/BitVector.h"
23 #include "llvm/ADT/STLExtras.h"
30 #include "llvm/IR/CallingConv.h"
31 #include "llvm/IR/Constants.h"
32 #include "llvm/IR/Function.h"
33 #include "llvm/IR/Type.h"
35 #include "llvm/Support/Debug.h"
43 #include <cstdlib>
44 
45 using namespace llvm;
46 
47 #define DEBUG_TYPE "reginfo"
48 
49 #define GET_REGINFO_TARGET_DESC
50 #include "PPCGenRegisterInfo.inc"
51 
52 static cl::opt<bool>
53 EnableBasePointer("ppc-use-base-pointer", cl::Hidden, cl::init(true),
54  cl::desc("Enable use of a base pointer for complex stack frames"));
55 
56 static cl::opt<bool>
57 AlwaysBasePointer("ppc-always-use-base-pointer", cl::Hidden, cl::init(false),
58  cl::desc("Force the use of a base pointer in every function"));
59 
61  : PPCGenRegisterInfo(TM.isPPC64() ? PPC::LR8 : PPC::LR,
62  TM.isPPC64() ? 0 : 1,
63  TM.isPPC64() ? 0 : 1),
64  TM(TM) {
65  ImmToIdxMap[PPC::LD] = PPC::LDX; ImmToIdxMap[PPC::STD] = PPC::STDX;
66  ImmToIdxMap[PPC::LBZ] = PPC::LBZX; ImmToIdxMap[PPC::STB] = PPC::STBX;
67  ImmToIdxMap[PPC::LHZ] = PPC::LHZX; ImmToIdxMap[PPC::LHA] = PPC::LHAX;
68  ImmToIdxMap[PPC::LWZ] = PPC::LWZX; ImmToIdxMap[PPC::LWA] = PPC::LWAX;
69  ImmToIdxMap[PPC::LFS] = PPC::LFSX; ImmToIdxMap[PPC::LFD] = PPC::LFDX;
70  ImmToIdxMap[PPC::STH] = PPC::STHX; ImmToIdxMap[PPC::STW] = PPC::STWX;
71  ImmToIdxMap[PPC::STFS] = PPC::STFSX; ImmToIdxMap[PPC::STFD] = PPC::STFDX;
72  ImmToIdxMap[PPC::ADDI] = PPC::ADD4;
73  ImmToIdxMap[PPC::LWA_32] = PPC::LWAX_32;
74 
75  // 64-bit
76  ImmToIdxMap[PPC::LHA8] = PPC::LHAX8; ImmToIdxMap[PPC::LBZ8] = PPC::LBZX8;
77  ImmToIdxMap[PPC::LHZ8] = PPC::LHZX8; ImmToIdxMap[PPC::LWZ8] = PPC::LWZX8;
78  ImmToIdxMap[PPC::STB8] = PPC::STBX8; ImmToIdxMap[PPC::STH8] = PPC::STHX8;
79  ImmToIdxMap[PPC::STW8] = PPC::STWX8; ImmToIdxMap[PPC::STDU] = PPC::STDUX;
80  ImmToIdxMap[PPC::ADDI8] = PPC::ADD8;
81 
82  // VSX
83  ImmToIdxMap[PPC::DFLOADf32] = PPC::LXSSPX;
84  ImmToIdxMap[PPC::DFLOADf64] = PPC::LXSDX;
85  ImmToIdxMap[PPC::DFSTOREf32] = PPC::STXSSPX;
86  ImmToIdxMap[PPC::DFSTOREf64] = PPC::STXSDX;
87  ImmToIdxMap[PPC::LXV] = PPC::LXVX;
88  ImmToIdxMap[PPC::LXSD] = PPC::LXSDX;
89  ImmToIdxMap[PPC::LXSSP] = PPC::LXSSPX;
90  ImmToIdxMap[PPC::STXV] = PPC::STXVX;
91  ImmToIdxMap[PPC::STXSD] = PPC::STXSDX;
92  ImmToIdxMap[PPC::STXSSP] = PPC::STXSSPX;
93 }
94 
95 /// getPointerRegClass - Return the register class to use to hold pointers.
96 /// This is used for addressing modes.
97 const TargetRegisterClass *
99  const {
100  // Note that PPCInstrInfo::FoldImmediate also directly uses this Kind value
101  // when it checks for ZERO folding.
102  if (Kind == 1) {
103  if (TM.isPPC64())
104  return &PPC::G8RC_NOX0RegClass;
105  return &PPC::GPRC_NOR0RegClass;
106  }
107 
108  if (TM.isPPC64())
109  return &PPC::G8RCRegClass;
110  return &PPC::GPRCRegClass;
111 }
112 
113 const MCPhysReg*
115  const PPCSubtarget &Subtarget = MF->getSubtarget<PPCSubtarget>();
117  if (Subtarget.hasVSX())
118  return CSR_64_AllRegs_VSX_SaveList;
119  if (Subtarget.hasAltivec())
120  return CSR_64_AllRegs_Altivec_SaveList;
121  return CSR_64_AllRegs_SaveList;
122  }
123 
124  if (Subtarget.isDarwinABI())
125  return TM.isPPC64()
126  ? (Subtarget.hasAltivec() ? CSR_Darwin64_Altivec_SaveList
127  : CSR_Darwin64_SaveList)
128  : (Subtarget.hasAltivec() ? CSR_Darwin32_Altivec_SaveList
129  : CSR_Darwin32_SaveList);
130 
131  if (TM.isPPC64() && MF->getInfo<PPCFunctionInfo>()->isSplitCSR())
132  return CSR_SRV464_TLS_PE_SaveList;
133 
134  // On PPC64, we might need to save r2 (but only if it is not reserved).
135  bool SaveR2 = MF->getRegInfo().isAllocatable(PPC::X2);
136 
137  return TM.isPPC64()
138  ? (Subtarget.hasAltivec()
139  ? (SaveR2 ? CSR_SVR464_R2_Altivec_SaveList
140  : CSR_SVR464_Altivec_SaveList)
141  : (SaveR2 ? CSR_SVR464_R2_SaveList : CSR_SVR464_SaveList))
142  : (Subtarget.hasAltivec() ? CSR_SVR432_Altivec_SaveList
143  : CSR_SVR432_SaveList);
144 }
145 
146 const MCPhysReg *
148  assert(MF && "Invalid MachineFunction pointer.");
149  const PPCSubtarget &Subtarget = MF->getSubtarget<PPCSubtarget>();
150  if (Subtarget.isDarwinABI())
151  return nullptr;
152  if (!TM.isPPC64())
153  return nullptr;
155  return nullptr;
156  if (!MF->getInfo<PPCFunctionInfo>()->isSplitCSR())
157  return nullptr;
158 
159  // On PPC64, we might need to save r2 (but only if it is not reserved).
160  bool SaveR2 = !getReservedRegs(*MF).test(PPC::X2);
161  if (Subtarget.hasAltivec())
162  return SaveR2
163  ? CSR_SVR464_R2_Altivec_ViaCopy_SaveList
164  : CSR_SVR464_Altivec_ViaCopy_SaveList;
165  else
166  return SaveR2
167  ? CSR_SVR464_R2_ViaCopy_SaveList
168  : CSR_SVR464_ViaCopy_SaveList;
169 }
170 
171 const uint32_t *
173  CallingConv::ID CC) const {
174  const PPCSubtarget &Subtarget = MF.getSubtarget<PPCSubtarget>();
175  if (CC == CallingConv::AnyReg) {
176  if (Subtarget.hasVSX())
177  return CSR_64_AllRegs_VSX_RegMask;
178  if (Subtarget.hasAltivec())
179  return CSR_64_AllRegs_Altivec_RegMask;
180  return CSR_64_AllRegs_RegMask;
181  }
182 
183  if (Subtarget.isDarwinABI())
184  return TM.isPPC64() ? (Subtarget.hasAltivec() ? CSR_Darwin64_Altivec_RegMask
185  : CSR_Darwin64_RegMask)
186  : (Subtarget.hasAltivec() ? CSR_Darwin32_Altivec_RegMask
187  : CSR_Darwin32_RegMask);
188 
189  return TM.isPPC64() ? (Subtarget.hasAltivec() ? CSR_SVR464_Altivec_RegMask
190  : CSR_SVR464_RegMask)
191  : (Subtarget.hasAltivec() ? CSR_SVR432_Altivec_RegMask
192  : CSR_SVR432_RegMask);
193 }
194 
195 const uint32_t*
197  return CSR_NoRegs_RegMask;
198 }
199 
201  for (unsigned PseudoReg : {PPC::ZERO, PPC::ZERO8, PPC::RM})
202  Mask[PseudoReg / 32] &= ~(1u << (PseudoReg % 32));
203 }
204 
206  BitVector Reserved(getNumRegs());
207  const PPCSubtarget &Subtarget = MF.getSubtarget<PPCSubtarget>();
208  const PPCFrameLowering *TFI = getFrameLowering(MF);
209 
210  // The ZERO register is not really a register, but the representation of r0
211  // when used in instructions that treat r0 as the constant 0.
212  markSuperRegs(Reserved, PPC::ZERO);
213 
214  // The FP register is also not really a register, but is the representation
215  // of the frame pointer register used by ISD::FRAMEADDR.
216  markSuperRegs(Reserved, PPC::FP);
217 
218  // The BP register is also not really a register, but is the representation
219  // of the base pointer register used by setjmp.
220  markSuperRegs(Reserved, PPC::BP);
221 
222  // The counter registers must be reserved so that counter-based loops can
223  // be correctly formed (and the mtctr instructions are not DCE'd).
224  markSuperRegs(Reserved, PPC::CTR);
225  markSuperRegs(Reserved, PPC::CTR8);
226 
227  markSuperRegs(Reserved, PPC::R1);
228  markSuperRegs(Reserved, PPC::LR);
229  markSuperRegs(Reserved, PPC::LR8);
230  markSuperRegs(Reserved, PPC::RM);
231 
232  if (!Subtarget.isDarwinABI() || !Subtarget.hasAltivec())
233  markSuperRegs(Reserved, PPC::VRSAVE);
234 
235  // The SVR4 ABI reserves r2 and r13
236  if (Subtarget.isSVR4ABI()) {
237  // We only reserve r2 if we need to use the TOC pointer. If we have no
238  // explicit uses of the TOC pointer (meaning we're a leaf function with
239  // no constant-pool loads, etc.) and we have no potential uses inside an
240  // inline asm block, then we can treat r2 has an ordinary callee-saved
241  // register.
242  const PPCFunctionInfo *FuncInfo = MF.getInfo<PPCFunctionInfo>();
243  if (!TM.isPPC64() || FuncInfo->usesTOCBasePtr() || MF.hasInlineAsm())
244  markSuperRegs(Reserved, PPC::R2); // System-reserved register
245  markSuperRegs(Reserved, PPC::R13); // Small Data Area pointer register
246  }
247 
248  // On PPC64, r13 is the thread pointer. Never allocate this register.
249  if (TM.isPPC64())
250  markSuperRegs(Reserved, PPC::R13);
251 
252  if (TFI->needsFP(MF))
253  markSuperRegs(Reserved, PPC::R31);
254 
255  bool IsPositionIndependent = TM.isPositionIndependent();
256  if (hasBasePointer(MF)) {
257  if (Subtarget.isSVR4ABI() && !TM.isPPC64() && IsPositionIndependent)
258  markSuperRegs(Reserved, PPC::R29);
259  else
260  markSuperRegs(Reserved, PPC::R30);
261  }
262 
263  if (Subtarget.isSVR4ABI() && !TM.isPPC64() && IsPositionIndependent)
264  markSuperRegs(Reserved, PPC::R30);
265 
266  // Reserve Altivec registers when Altivec is unavailable.
267  if (!Subtarget.hasAltivec())
268  for (TargetRegisterClass::iterator I = PPC::VRRCRegClass.begin(),
269  IE = PPC::VRRCRegClass.end(); I != IE; ++I)
270  markSuperRegs(Reserved, *I);
271 
272  assert(checkAllSuperRegsMarked(Reserved));
273  return Reserved;
274 }
275 
277  const MachineFunction &MF) const {
279  if (TM.isELFv2ABI() && PhysReg == PPC::X2) {
280  // X2 is guaranteed to be preserved within a function if it is reserved.
281  // The reason it's reserved is that it's the TOC pointer (and the function
282  // uses the TOC). In functions where it isn't reserved (i.e. leaf functions
283  // with no TOC access), we can't claim that it is preserved.
284  return (getReservedRegs(MF).test(PPC::X2));
285  } else {
286  return false;
287  }
288 }
289 
291  MachineFunction &MF) const {
292  const PPCFrameLowering *TFI = getFrameLowering(MF);
293  const unsigned DefaultSafety = 1;
294 
295  switch (RC->getID()) {
296  default:
297  return 0;
298  case PPC::G8RC_NOX0RegClassID:
299  case PPC::GPRC_NOR0RegClassID:
300  case PPC::G8RCRegClassID:
301  case PPC::GPRCRegClassID: {
302  unsigned FP = TFI->hasFP(MF) ? 1 : 0;
303  return 32 - FP - DefaultSafety;
304  }
305  case PPC::F8RCRegClassID:
306  case PPC::F4RCRegClassID:
307  case PPC::QFRCRegClassID:
308  case PPC::QSRCRegClassID:
309  case PPC::QBRCRegClassID:
310  case PPC::VRRCRegClassID:
311  case PPC::VFRCRegClassID:
312  case PPC::VSLRCRegClassID:
313  return 32 - DefaultSafety;
314  case PPC::VSRCRegClassID:
315  case PPC::VSFRCRegClassID:
316  case PPC::VSSRCRegClassID:
317  return 64 - DefaultSafety;
318  case PPC::CRRCRegClassID:
319  return 8 - DefaultSafety;
320  }
321 }
322 
323 const TargetRegisterClass *
325  const MachineFunction &MF) const {
326  const PPCSubtarget &Subtarget = MF.getSubtarget<PPCSubtarget>();
327  if (Subtarget.hasVSX()) {
328  // With VSX, we can inflate various sub-register classes to the full VSX
329  // register set.
330 
331  if (RC == &PPC::F8RCRegClass)
332  return &PPC::VSFRCRegClass;
333  else if (RC == &PPC::VRRCRegClass)
334  return &PPC::VSRCRegClass;
335  else if (RC == &PPC::F4RCRegClass && Subtarget.hasP8Vector())
336  return &PPC::VSSRCRegClass;
337  }
338 
340 }
341 
342 //===----------------------------------------------------------------------===//
343 // Stack Frame Processing methods
344 //===----------------------------------------------------------------------===//
345 
346 /// lowerDynamicAlloc - Generate the code for allocating an object in the
347 /// current frame. The sequence of code will be in the general form
348 ///
349 /// addi R0, SP, \#frameSize ; get the address of the previous frame
350 /// stwxu R0, SP, Rnegsize ; add and update the SP with the negated size
351 /// addi Rnew, SP, \#maxCalFrameSize ; get the top of the allocation
352 ///
354  // Get the instruction.
355  MachineInstr &MI = *II;
356  // Get the instruction's basic block.
357  MachineBasicBlock &MBB = *MI.getParent();
358  // Get the basic block's function.
359  MachineFunction &MF = *MBB.getParent();
360  // Get the frame info.
361  MachineFrameInfo &MFI = MF.getFrameInfo();
362  const PPCSubtarget &Subtarget = MF.getSubtarget<PPCSubtarget>();
363  // Get the instruction info.
364  const TargetInstrInfo &TII = *Subtarget.getInstrInfo();
365  // Determine whether 64-bit pointers are used.
366  bool LP64 = TM.isPPC64();
367  DebugLoc dl = MI.getDebugLoc();
368 
369  // Get the maximum call stack size.
370  unsigned maxCallFrameSize = MFI.getMaxCallFrameSize();
371  // Get the total frame size.
372  unsigned FrameSize = MFI.getStackSize();
373 
374  // Get stack alignments.
375  const PPCFrameLowering *TFI = getFrameLowering(MF);
376  unsigned TargetAlign = TFI->getStackAlignment();
377  unsigned MaxAlign = MFI.getMaxAlignment();
378  assert((maxCallFrameSize & (MaxAlign-1)) == 0 &&
379  "Maximum call-frame size not sufficiently aligned");
380 
381  // Determine the previous frame's address. If FrameSize can't be
382  // represented as 16 bits or we need special alignment, then we load the
383  // previous frame's address from 0(SP). Why not do an addis of the hi?
384  // Because R0 is our only safe tmp register and addi/addis treat R0 as zero.
385  // Constructing the constant and adding would take 3 instructions.
386  // Fortunately, a frame greater than 32K is rare.
387  const TargetRegisterClass *G8RC = &PPC::G8RCRegClass;
388  const TargetRegisterClass *GPRC = &PPC::GPRCRegClass;
389  unsigned Reg = MF.getRegInfo().createVirtualRegister(LP64 ? G8RC : GPRC);
390 
391  if (MaxAlign < TargetAlign && isInt<16>(FrameSize)) {
392  if (LP64)
393  BuildMI(MBB, II, dl, TII.get(PPC::ADDI8), Reg)
394  .addReg(PPC::X31)
395  .addImm(FrameSize);
396  else
397  BuildMI(MBB, II, dl, TII.get(PPC::ADDI), Reg)
398  .addReg(PPC::R31)
399  .addImm(FrameSize);
400  } else if (LP64) {
401  BuildMI(MBB, II, dl, TII.get(PPC::LD), Reg)
402  .addImm(0)
403  .addReg(PPC::X1);
404  } else {
405  BuildMI(MBB, II, dl, TII.get(PPC::LWZ), Reg)
406  .addImm(0)
407  .addReg(PPC::R1);
408  }
409 
410  bool KillNegSizeReg = MI.getOperand(1).isKill();
411  unsigned NegSizeReg = MI.getOperand(1).getReg();
412 
413  // Grow the stack and update the stack pointer link, then determine the
414  // address of new allocated space.
415  if (LP64) {
416  if (MaxAlign > TargetAlign) {
417  unsigned UnalNegSizeReg = NegSizeReg;
418  NegSizeReg = MF.getRegInfo().createVirtualRegister(G8RC);
419 
420  // Unfortunately, there is no andi, only andi., and we can't insert that
421  // here because we might clobber cr0 while it is live.
422  BuildMI(MBB, II, dl, TII.get(PPC::LI8), NegSizeReg)
423  .addImm(~(MaxAlign-1));
424 
425  unsigned NegSizeReg1 = NegSizeReg;
426  NegSizeReg = MF.getRegInfo().createVirtualRegister(G8RC);
427  BuildMI(MBB, II, dl, TII.get(PPC::AND8), NegSizeReg)
428  .addReg(UnalNegSizeReg, getKillRegState(KillNegSizeReg))
429  .addReg(NegSizeReg1, RegState::Kill);
430  KillNegSizeReg = true;
431  }
432 
433  BuildMI(MBB, II, dl, TII.get(PPC::STDUX), PPC::X1)
434  .addReg(Reg, RegState::Kill)
435  .addReg(PPC::X1)
436  .addReg(NegSizeReg, getKillRegState(KillNegSizeReg));
437  BuildMI(MBB, II, dl, TII.get(PPC::ADDI8), MI.getOperand(0).getReg())
438  .addReg(PPC::X1)
439  .addImm(maxCallFrameSize);
440  } else {
441  if (MaxAlign > TargetAlign) {
442  unsigned UnalNegSizeReg = NegSizeReg;
443  NegSizeReg = MF.getRegInfo().createVirtualRegister(GPRC);
444 
445  // Unfortunately, there is no andi, only andi., and we can't insert that
446  // here because we might clobber cr0 while it is live.
447  BuildMI(MBB, II, dl, TII.get(PPC::LI), NegSizeReg)
448  .addImm(~(MaxAlign-1));
449 
450  unsigned NegSizeReg1 = NegSizeReg;
451  NegSizeReg = MF.getRegInfo().createVirtualRegister(GPRC);
452  BuildMI(MBB, II, dl, TII.get(PPC::AND), NegSizeReg)
453  .addReg(UnalNegSizeReg, getKillRegState(KillNegSizeReg))
454  .addReg(NegSizeReg1, RegState::Kill);
455  KillNegSizeReg = true;
456  }
457 
458  BuildMI(MBB, II, dl, TII.get(PPC::STWUX), PPC::R1)
459  .addReg(Reg, RegState::Kill)
460  .addReg(PPC::R1)
461  .addReg(NegSizeReg, getKillRegState(KillNegSizeReg));
462  BuildMI(MBB, II, dl, TII.get(PPC::ADDI), MI.getOperand(0).getReg())
463  .addReg(PPC::R1)
464  .addImm(maxCallFrameSize);
465  }
466 
467  // Discard the DYNALLOC instruction.
468  MBB.erase(II);
469 }
470 
472  MachineBasicBlock::iterator II) const {
473  // Get the instruction.
474  MachineInstr &MI = *II;
475  // Get the instruction's basic block.
476  MachineBasicBlock &MBB = *MI.getParent();
477  // Get the basic block's function.
478  MachineFunction &MF = *MBB.getParent();
479  // Get the frame info.
480  MachineFrameInfo &MFI = MF.getFrameInfo();
481  const PPCSubtarget &Subtarget = MF.getSubtarget<PPCSubtarget>();
482  // Get the instruction info.
483  const TargetInstrInfo &TII = *Subtarget.getInstrInfo();
484 
485  unsigned maxCallFrameSize = MFI.getMaxCallFrameSize();
486  bool is64Bit = TM.isPPC64();
487  DebugLoc dl = MI.getDebugLoc();
488  BuildMI(MBB, II, dl, TII.get(is64Bit ? PPC::LI8 : PPC::LI),
489  MI.getOperand(0).getReg())
490  .addImm(maxCallFrameSize);
491  MBB.erase(II);
492 }
493 
494 /// lowerCRSpilling - Generate the code for spilling a CR register. Instead of
495 /// reserving a whole register (R0), we scrounge for one here. This generates
496 /// code like this:
497 ///
498 /// mfcr rA ; Move the conditional register into GPR rA.
499 /// rlwinm rA, rA, SB, 0, 31 ; Shift the bits left so they are in CR0's slot.
500 /// stw rA, FI ; Store rA to the frame.
501 ///
503  unsigned FrameIndex) const {
504  // Get the instruction.
505  MachineInstr &MI = *II; // ; SPILL_CR <SrcReg>, <offset>
506  // Get the instruction's basic block.
507  MachineBasicBlock &MBB = *MI.getParent();
508  MachineFunction &MF = *MBB.getParent();
509  const PPCSubtarget &Subtarget = MF.getSubtarget<PPCSubtarget>();
510  const TargetInstrInfo &TII = *Subtarget.getInstrInfo();
511  DebugLoc dl = MI.getDebugLoc();
512 
513  bool LP64 = TM.isPPC64();
514  const TargetRegisterClass *G8RC = &PPC::G8RCRegClass;
515  const TargetRegisterClass *GPRC = &PPC::GPRCRegClass;
516 
517  unsigned Reg = MF.getRegInfo().createVirtualRegister(LP64 ? G8RC : GPRC);
518  unsigned SrcReg = MI.getOperand(0).getReg();
519 
520  // We need to store the CR in the low 4-bits of the saved value. First, issue
521  // an MFOCRF to save all of the CRBits and, if needed, kill the SrcReg.
522  BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::MFOCRF8 : PPC::MFOCRF), Reg)
523  .addReg(SrcReg, getKillRegState(MI.getOperand(0).isKill()));
524 
525  // If the saved register wasn't CR0, shift the bits left so that they are in
526  // CR0's slot.
527  if (SrcReg != PPC::CR0) {
528  unsigned Reg1 = Reg;
529  Reg = MF.getRegInfo().createVirtualRegister(LP64 ? G8RC : GPRC);
530 
531  // rlwinm rA, rA, ShiftBits, 0, 31.
532  BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::RLWINM8 : PPC::RLWINM), Reg)
533  .addReg(Reg1, RegState::Kill)
534  .addImm(getEncodingValue(SrcReg) * 4)
535  .addImm(0)
536  .addImm(31);
537  }
538 
539  addFrameReference(BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::STW8 : PPC::STW))
540  .addReg(Reg, RegState::Kill),
541  FrameIndex);
542 
543  // Discard the pseudo instruction.
544  MBB.erase(II);
545 }
546 
548  unsigned FrameIndex) const {
549  // Get the instruction.
550  MachineInstr &MI = *II; // ; <DestReg> = RESTORE_CR <offset>
551  // Get the instruction's basic block.
552  MachineBasicBlock &MBB = *MI.getParent();
553  MachineFunction &MF = *MBB.getParent();
554  const PPCSubtarget &Subtarget = MF.getSubtarget<PPCSubtarget>();
555  const TargetInstrInfo &TII = *Subtarget.getInstrInfo();
556  DebugLoc dl = MI.getDebugLoc();
557 
558  bool LP64 = TM.isPPC64();
559  const TargetRegisterClass *G8RC = &PPC::G8RCRegClass;
560  const TargetRegisterClass *GPRC = &PPC::GPRCRegClass;
561 
562  unsigned Reg = MF.getRegInfo().createVirtualRegister(LP64 ? G8RC : GPRC);
563  unsigned DestReg = MI.getOperand(0).getReg();
564  assert(MI.definesRegister(DestReg) &&
565  "RESTORE_CR does not define its destination");
566 
567  addFrameReference(BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::LWZ8 : PPC::LWZ),
568  Reg), FrameIndex);
569 
570  // If the reloaded register isn't CR0, shift the bits right so that they are
571  // in the right CR's slot.
572  if (DestReg != PPC::CR0) {
573  unsigned Reg1 = Reg;
574  Reg = MF.getRegInfo().createVirtualRegister(LP64 ? G8RC : GPRC);
575 
576  unsigned ShiftBits = getEncodingValue(DestReg)*4;
577  // rlwinm r11, r11, 32-ShiftBits, 0, 31.
578  BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::RLWINM8 : PPC::RLWINM), Reg)
579  .addReg(Reg1, RegState::Kill).addImm(32-ShiftBits).addImm(0)
580  .addImm(31);
581  }
582 
583  BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::MTOCRF8 : PPC::MTOCRF), DestReg)
584  .addReg(Reg, RegState::Kill);
585 
586  // Discard the pseudo instruction.
587  MBB.erase(II);
588 }
589 
591  unsigned FrameIndex) const {
592  // Get the instruction.
593  MachineInstr &MI = *II; // ; SPILL_CRBIT <SrcReg>, <offset>
594  // Get the instruction's basic block.
595  MachineBasicBlock &MBB = *MI.getParent();
596  MachineFunction &MF = *MBB.getParent();
597  const PPCSubtarget &Subtarget = MF.getSubtarget<PPCSubtarget>();
598  const TargetInstrInfo &TII = *Subtarget.getInstrInfo();
599  DebugLoc dl = MI.getDebugLoc();
600 
601  bool LP64 = TM.isPPC64();
602  const TargetRegisterClass *G8RC = &PPC::G8RCRegClass;
603  const TargetRegisterClass *GPRC = &PPC::GPRCRegClass;
604 
605  unsigned Reg = MF.getRegInfo().createVirtualRegister(LP64 ? G8RC : GPRC);
606  unsigned SrcReg = MI.getOperand(0).getReg();
607 
608  BuildMI(MBB, II, dl, TII.get(TargetOpcode::KILL),
609  getCRFromCRBit(SrcReg))
610  .addReg(SrcReg, getKillRegState(MI.getOperand(0).isKill()));
611 
612  BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::MFOCRF8 : PPC::MFOCRF), Reg)
613  .addReg(getCRFromCRBit(SrcReg));
614 
615  // If the saved register wasn't CR0LT, shift the bits left so that the bit to
616  // store is the first one. Mask all but that bit.
617  unsigned Reg1 = Reg;
618  Reg = MF.getRegInfo().createVirtualRegister(LP64 ? G8RC : GPRC);
619 
620  // rlwinm rA, rA, ShiftBits, 0, 0.
621  BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::RLWINM8 : PPC::RLWINM), Reg)
622  .addReg(Reg1, RegState::Kill)
623  .addImm(getEncodingValue(SrcReg))
624  .addImm(0).addImm(0);
625 
626  addFrameReference(BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::STW8 : PPC::STW))
627  .addReg(Reg, RegState::Kill),
628  FrameIndex);
629 
630  // Discard the pseudo instruction.
631  MBB.erase(II);
632 }
633 
635  unsigned FrameIndex) const {
636  // Get the instruction.
637  MachineInstr &MI = *II; // ; <DestReg> = RESTORE_CRBIT <offset>
638  // Get the instruction's basic block.
639  MachineBasicBlock &MBB = *MI.getParent();
640  MachineFunction &MF = *MBB.getParent();
641  const PPCSubtarget &Subtarget = MF.getSubtarget<PPCSubtarget>();
642  const TargetInstrInfo &TII = *Subtarget.getInstrInfo();
643  DebugLoc dl = MI.getDebugLoc();
644 
645  bool LP64 = TM.isPPC64();
646  const TargetRegisterClass *G8RC = &PPC::G8RCRegClass;
647  const TargetRegisterClass *GPRC = &PPC::GPRCRegClass;
648 
649  unsigned Reg = MF.getRegInfo().createVirtualRegister(LP64 ? G8RC : GPRC);
650  unsigned DestReg = MI.getOperand(0).getReg();
651  assert(MI.definesRegister(DestReg) &&
652  "RESTORE_CRBIT does not define its destination");
653 
654  addFrameReference(BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::LWZ8 : PPC::LWZ),
655  Reg), FrameIndex);
656 
657  BuildMI(MBB, II, dl, TII.get(TargetOpcode::IMPLICIT_DEF), DestReg);
658 
659  unsigned RegO = MF.getRegInfo().createVirtualRegister(LP64 ? G8RC : GPRC);
660  BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::MFOCRF8 : PPC::MFOCRF), RegO)
661  .addReg(getCRFromCRBit(DestReg));
662 
663  unsigned ShiftBits = getEncodingValue(DestReg);
664  // rlwimi r11, r10, 32-ShiftBits, ..., ...
665  BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::RLWIMI8 : PPC::RLWIMI), RegO)
666  .addReg(RegO, RegState::Kill)
667  .addReg(Reg, RegState::Kill)
668  .addImm(ShiftBits ? 32 - ShiftBits : 0)
669  .addImm(ShiftBits)
670  .addImm(ShiftBits);
671 
672  BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::MTOCRF8 : PPC::MTOCRF),
673  getCRFromCRBit(DestReg))
674  .addReg(RegO, RegState::Kill)
675  // Make sure we have a use dependency all the way through this
676  // sequence of instructions. We can't have the other bits in the CR
677  // modified in between the mfocrf and the mtocrf.
679 
680  // Discard the pseudo instruction.
681  MBB.erase(II);
682 }
683 
685  unsigned FrameIndex) const {
686  // Get the instruction.
687  MachineInstr &MI = *II; // ; SPILL_VRSAVE <SrcReg>, <offset>
688  // Get the instruction's basic block.
689  MachineBasicBlock &MBB = *MI.getParent();
690  MachineFunction &MF = *MBB.getParent();
691  const PPCSubtarget &Subtarget = MF.getSubtarget<PPCSubtarget>();
692  const TargetInstrInfo &TII = *Subtarget.getInstrInfo();
693  DebugLoc dl = MI.getDebugLoc();
694 
695  const TargetRegisterClass *GPRC = &PPC::GPRCRegClass;
696  unsigned Reg = MF.getRegInfo().createVirtualRegister(GPRC);
697  unsigned SrcReg = MI.getOperand(0).getReg();
698 
699  BuildMI(MBB, II, dl, TII.get(PPC::MFVRSAVEv), Reg)
700  .addReg(SrcReg, getKillRegState(MI.getOperand(0).isKill()));
701 
703  BuildMI(MBB, II, dl, TII.get(PPC::STW)).addReg(Reg, RegState::Kill),
704  FrameIndex);
705 
706  // Discard the pseudo instruction.
707  MBB.erase(II);
708 }
709 
711  unsigned FrameIndex) const {
712  // Get the instruction.
713  MachineInstr &MI = *II; // ; <DestReg> = RESTORE_VRSAVE <offset>
714  // Get the instruction's basic block.
715  MachineBasicBlock &MBB = *MI.getParent();
716  MachineFunction &MF = *MBB.getParent();
717  const PPCSubtarget &Subtarget = MF.getSubtarget<PPCSubtarget>();
718  const TargetInstrInfo &TII = *Subtarget.getInstrInfo();
719  DebugLoc dl = MI.getDebugLoc();
720 
721  const TargetRegisterClass *GPRC = &PPC::GPRCRegClass;
722  unsigned Reg = MF.getRegInfo().createVirtualRegister(GPRC);
723  unsigned DestReg = MI.getOperand(0).getReg();
724  assert(MI.definesRegister(DestReg) &&
725  "RESTORE_VRSAVE does not define its destination");
726 
727  addFrameReference(BuildMI(MBB, II, dl, TII.get(PPC::LWZ),
728  Reg), FrameIndex);
729 
730  BuildMI(MBB, II, dl, TII.get(PPC::MTVRSAVEv), DestReg)
731  .addReg(Reg, RegState::Kill);
732 
733  // Discard the pseudo instruction.
734  MBB.erase(II);
735 }
736 
738  unsigned Reg, int &FrameIdx) const {
739  const PPCSubtarget &Subtarget = MF.getSubtarget<PPCSubtarget>();
740  // For the nonvolatile condition registers (CR2, CR3, CR4) in an SVR4
741  // ABI, return true to prevent allocating an additional frame slot.
742  // For 64-bit, the CR save area is at SP+8; the value of FrameIdx = 0
743  // is arbitrary and will be subsequently ignored. For 32-bit, we have
744  // previously created the stack slot if needed, so return its FrameIdx.
745  if (Subtarget.isSVR4ABI() && PPC::CR2 <= Reg && Reg <= PPC::CR4) {
746  if (TM.isPPC64())
747  FrameIdx = 0;
748  else {
749  const PPCFunctionInfo *FI = MF.getInfo<PPCFunctionInfo>();
750  FrameIdx = FI->getCRSpillFrameIndex();
751  }
752  return true;
753  }
754  return false;
755 }
756 
757 // If the offset must be a multiple of some value, return what that value is.
758 static unsigned offsetMinAlign(const MachineInstr &MI) {
759  unsigned OpC = MI.getOpcode();
760 
761  switch (OpC) {
762  default:
763  return 1;
764  case PPC::LWA:
765  case PPC::LWA_32:
766  case PPC::LD:
767  case PPC::LDU:
768  case PPC::STD:
769  case PPC::STDU:
770  case PPC::DFLOADf32:
771  case PPC::DFLOADf64:
772  case PPC::DFSTOREf32:
773  case PPC::DFSTOREf64:
774  case PPC::LXSD:
775  case PPC::LXSSP:
776  case PPC::STXSD:
777  case PPC::STXSSP:
778  return 4;
779  case PPC::LXV:
780  case PPC::STXV:
781  return 16;
782  }
783 }
784 
785 // Return the OffsetOperandNo given the FIOperandNum (and the instruction).
786 static unsigned getOffsetONFromFION(const MachineInstr &MI,
787  unsigned FIOperandNum) {
788  // Take into account whether it's an add or mem instruction
789  unsigned OffsetOperandNo = (FIOperandNum == 2) ? 1 : 2;
790  if (MI.isInlineAsm())
791  OffsetOperandNo = FIOperandNum - 1;
792  else if (MI.getOpcode() == TargetOpcode::STACKMAP ||
793  MI.getOpcode() == TargetOpcode::PATCHPOINT)
794  OffsetOperandNo = FIOperandNum + 1;
795 
796  return OffsetOperandNo;
797 }
798 
799 void
801  int SPAdj, unsigned FIOperandNum,
802  RegScavenger *RS) const {
803  assert(SPAdj == 0 && "Unexpected");
804 
805  // Get the instruction.
806  MachineInstr &MI = *II;
807  // Get the instruction's basic block.
808  MachineBasicBlock &MBB = *MI.getParent();
809  // Get the basic block's function.
810  MachineFunction &MF = *MBB.getParent();
811  const PPCSubtarget &Subtarget = MF.getSubtarget<PPCSubtarget>();
812  // Get the instruction info.
813  const TargetInstrInfo &TII = *Subtarget.getInstrInfo();
814  // Get the frame info.
815  MachineFrameInfo &MFI = MF.getFrameInfo();
816  DebugLoc dl = MI.getDebugLoc();
817 
818  unsigned OffsetOperandNo = getOffsetONFromFION(MI, FIOperandNum);
819 
820  // Get the frame index.
821  int FrameIndex = MI.getOperand(FIOperandNum).getIndex();
822 
823  // Get the frame pointer save index. Users of this index are primarily
824  // DYNALLOC instructions.
826  int FPSI = FI->getFramePointerSaveIndex();
827  // Get the instruction opcode.
828  unsigned OpC = MI.getOpcode();
829 
830  if ((OpC == PPC::DYNAREAOFFSET || OpC == PPC::DYNAREAOFFSET8)) {
832  return;
833  }
834 
835  // Special case for dynamic alloca.
836  if (FPSI && FrameIndex == FPSI &&
837  (OpC == PPC::DYNALLOC || OpC == PPC::DYNALLOC8)) {
838  lowerDynamicAlloc(II);
839  return;
840  }
841 
842  // Special case for pseudo-ops SPILL_CR and RESTORE_CR, etc.
843  if (OpC == PPC::SPILL_CR) {
844  lowerCRSpilling(II, FrameIndex);
845  return;
846  } else if (OpC == PPC::RESTORE_CR) {
847  lowerCRRestore(II, FrameIndex);
848  return;
849  } else if (OpC == PPC::SPILL_CRBIT) {
850  lowerCRBitSpilling(II, FrameIndex);
851  return;
852  } else if (OpC == PPC::RESTORE_CRBIT) {
853  lowerCRBitRestore(II, FrameIndex);
854  return;
855  } else if (OpC == PPC::SPILL_VRSAVE) {
856  lowerVRSAVESpilling(II, FrameIndex);
857  return;
858  } else if (OpC == PPC::RESTORE_VRSAVE) {
859  lowerVRSAVERestore(II, FrameIndex);
860  return;
861  }
862 
863  // Replace the FrameIndex with base register with GPR1 (SP) or GPR31 (FP).
864  MI.getOperand(FIOperandNum).ChangeToRegister(
865  FrameIndex < 0 ? getBaseRegister(MF) : getFrameRegister(MF), false);
866 
867  // If the instruction is not present in ImmToIdxMap, then it has no immediate
868  // form (and must be r+r).
869  bool noImmForm = !MI.isInlineAsm() && OpC != TargetOpcode::STACKMAP &&
870  OpC != TargetOpcode::PATCHPOINT && !ImmToIdxMap.count(OpC);
871 
872  // Now add the frame object offset to the offset from r1.
873  int Offset = MFI.getObjectOffset(FrameIndex);
874  Offset += MI.getOperand(OffsetOperandNo).getImm();
875 
876  // If we're not using a Frame Pointer that has been set to the value of the
877  // SP before having the stack size subtracted from it, then add the stack size
878  // to Offset to get the correct offset.
879  // Naked functions have stack size 0, although getStackSize may not reflect
880  // that because we didn't call all the pieces that compute it for naked
881  // functions.
882  if (!MF.getFunction()->hasFnAttribute(Attribute::Naked)) {
883  if (!(hasBasePointer(MF) && FrameIndex < 0))
884  Offset += MFI.getStackSize();
885  }
886 
887  // If we can, encode the offset directly into the instruction. If this is a
888  // normal PPC "ri" instruction, any 16-bit value can be safely encoded. If
889  // this is a PPC64 "ix" instruction, only a 16-bit value with the low two bits
890  // clear can be encoded. This is extremely uncommon, because normally you
891  // only "std" to a stack slot that is at least 4-byte aligned, but it can
892  // happen in invalid code.
893  assert(OpC != PPC::DBG_VALUE &&
894  "This should be handled in a target-independent way");
895  if (!noImmForm && ((isInt<16>(Offset) &&
896  ((Offset % offsetMinAlign(MI)) == 0)) ||
897  OpC == TargetOpcode::STACKMAP ||
898  OpC == TargetOpcode::PATCHPOINT)) {
899  MI.getOperand(OffsetOperandNo).ChangeToImmediate(Offset);
900  return;
901  }
902 
903  // The offset doesn't fit into a single register, scavenge one to build the
904  // offset in.
905 
906  bool is64Bit = TM.isPPC64();
907  const TargetRegisterClass *G8RC = &PPC::G8RCRegClass;
908  const TargetRegisterClass *GPRC = &PPC::GPRCRegClass;
909  const TargetRegisterClass *RC = is64Bit ? G8RC : GPRC;
910  unsigned SRegHi = MF.getRegInfo().createVirtualRegister(RC),
911  SReg = MF.getRegInfo().createVirtualRegister(RC);
912 
913  // Insert a set of rA with the full offset value before the ld, st, or add
914  BuildMI(MBB, II, dl, TII.get(is64Bit ? PPC::LIS8 : PPC::LIS), SRegHi)
915  .addImm(Offset >> 16);
916  BuildMI(MBB, II, dl, TII.get(is64Bit ? PPC::ORI8 : PPC::ORI), SReg)
917  .addReg(SRegHi, RegState::Kill)
918  .addImm(Offset);
919 
920  // Convert into indexed form of the instruction:
921  //
922  // sth 0:rA, 1:imm 2:(rB) ==> sthx 0:rA, 2:rB, 1:r0
923  // addi 0:rA 1:rB, 2, imm ==> add 0:rA, 1:rB, 2:r0
924  unsigned OperandBase;
925 
926  if (noImmForm)
927  OperandBase = 1;
928  else if (OpC != TargetOpcode::INLINEASM) {
929  assert(ImmToIdxMap.count(OpC) &&
930  "No indexed form of load or store available!");
931  unsigned NewOpcode = ImmToIdxMap.find(OpC)->second;
932  MI.setDesc(TII.get(NewOpcode));
933  OperandBase = 1;
934  } else {
935  OperandBase = OffsetOperandNo;
936  }
937 
938  unsigned StackReg = MI.getOperand(FIOperandNum).getReg();
939  MI.getOperand(OperandBase).ChangeToRegister(StackReg, false);
940  MI.getOperand(OperandBase + 1).ChangeToRegister(SReg, false, false, true);
941 }
942 
944  const PPCFrameLowering *TFI = getFrameLowering(MF);
945 
946  if (!TM.isPPC64())
947  return TFI->hasFP(MF) ? PPC::R31 : PPC::R1;
948  else
949  return TFI->hasFP(MF) ? PPC::X31 : PPC::X1;
950 }
951 
953  const PPCSubtarget &Subtarget = MF.getSubtarget<PPCSubtarget>();
954  if (!hasBasePointer(MF))
955  return getFrameRegister(MF);
956 
957  if (TM.isPPC64())
958  return PPC::X30;
959 
960  if (Subtarget.isSVR4ABI() && TM.isPositionIndependent())
961  return PPC::R29;
962 
963  return PPC::R30;
964 }
965 
967  if (!EnableBasePointer)
968  return false;
969  if (AlwaysBasePointer)
970  return true;
971 
972  // If we need to realign the stack, then the stack pointer can no longer
973  // serve as an offset into the caller's stack space. As a result, we need a
974  // base pointer.
975  return needsStackRealignment(MF);
976 }
977 
978 /// Returns true if the instruction's frame index
979 /// reference would be better served by a base register other than FP
980 /// or SP. Used by LocalStackFrameAllocation to determine which frame index
981 /// references it should create new base registers for.
984  assert(Offset < 0 && "Local offset must be negative");
985 
986  // It's the load/store FI references that cause issues, as it can be difficult
987  // to materialize the offset if it won't fit in the literal field. Estimate
988  // based on the size of the local frame and some conservative assumptions
989  // about the rest of the stack frame (note, this is pre-regalloc, so
990  // we don't know everything for certain yet) whether this offset is likely
991  // to be out of range of the immediate. Return true if so.
992 
993  // We only generate virtual base registers for loads and stores that have
994  // an r+i form. Return false for everything else.
995  unsigned OpC = MI->getOpcode();
996  if (!ImmToIdxMap.count(OpC))
997  return false;
998 
999  // Don't generate a new virtual base register just to add zero to it.
1000  if ((OpC == PPC::ADDI || OpC == PPC::ADDI8) &&
1001  MI->getOperand(2).getImm() == 0)
1002  return false;
1003 
1004  MachineBasicBlock &MBB = *MI->getParent();
1005  MachineFunction &MF = *MBB.getParent();
1006  const PPCFrameLowering *TFI = getFrameLowering(MF);
1007  unsigned StackEst = TFI->determineFrameLayout(MF, false, true);
1008 
1009  // If we likely don't need a stack frame, then we probably don't need a
1010  // virtual base register either.
1011  if (!StackEst)
1012  return false;
1013 
1014  // Estimate an offset from the stack pointer.
1015  // The incoming offset is relating to the SP at the start of the function,
1016  // but when we access the local it'll be relative to the SP after local
1017  // allocation, so adjust our SP-relative offset by that allocation size.
1018  Offset += StackEst;
1019 
1020  // The frame pointer will point to the end of the stack, so estimate the
1021  // offset as the difference between the object offset and the FP location.
1022  return !isFrameOffsetLegal(MI, getBaseRegister(MF), Offset);
1023 }
1024 
1025 /// Insert defining instruction(s) for BaseReg to
1026 /// be a pointer to FrameIdx at the beginning of the basic block.
1027 void PPCRegisterInfo::
1029  unsigned BaseReg, int FrameIdx,
1030  int64_t Offset) const {
1031  unsigned ADDriOpc = TM.isPPC64() ? PPC::ADDI8 : PPC::ADDI;
1032 
1034  DebugLoc DL; // Defaults to "unknown"
1035  if (Ins != MBB->end())
1036  DL = Ins->getDebugLoc();
1037 
1038  const MachineFunction &MF = *MBB->getParent();
1039  const PPCSubtarget &Subtarget = MF.getSubtarget<PPCSubtarget>();
1040  const TargetInstrInfo &TII = *Subtarget.getInstrInfo();
1041  const MCInstrDesc &MCID = TII.get(ADDriOpc);
1043  MRI.constrainRegClass(BaseReg, TII.getRegClass(MCID, 0, this, MF));
1044 
1045  BuildMI(*MBB, Ins, DL, MCID, BaseReg)
1046  .addFrameIndex(FrameIdx).addImm(Offset);
1047 }
1048 
1050  int64_t Offset) const {
1051  unsigned FIOperandNum = 0;
1052  while (!MI.getOperand(FIOperandNum).isFI()) {
1053  ++FIOperandNum;
1054  assert(FIOperandNum < MI.getNumOperands() &&
1055  "Instr doesn't have FrameIndex operand!");
1056  }
1057 
1058  MI.getOperand(FIOperandNum).ChangeToRegister(BaseReg, false);
1059  unsigned OffsetOperandNo = getOffsetONFromFION(MI, FIOperandNum);
1060  Offset += MI.getOperand(OffsetOperandNo).getImm();
1061  MI.getOperand(OffsetOperandNo).ChangeToImmediate(Offset);
1062 
1063  MachineBasicBlock &MBB = *MI.getParent();
1064  MachineFunction &MF = *MBB.getParent();
1065  const PPCSubtarget &Subtarget = MF.getSubtarget<PPCSubtarget>();
1066  const TargetInstrInfo &TII = *Subtarget.getInstrInfo();
1067  const MCInstrDesc &MCID = MI.getDesc();
1069  MRI.constrainRegClass(BaseReg,
1070  TII.getRegClass(MCID, FIOperandNum, this, MF));
1071 }
1072 
1074  unsigned BaseReg,
1075  int64_t Offset) const {
1076  unsigned FIOperandNum = 0;
1077  while (!MI->getOperand(FIOperandNum).isFI()) {
1078  ++FIOperandNum;
1079  assert(FIOperandNum < MI->getNumOperands() &&
1080  "Instr doesn't have FrameIndex operand!");
1081  }
1082 
1083  unsigned OffsetOperandNo = getOffsetONFromFION(*MI, FIOperandNum);
1084  Offset += MI->getOperand(OffsetOperandNo).getImm();
1085 
1086  return MI->getOpcode() == PPC::DBG_VALUE || // DBG_VALUE is always Reg+Imm
1087  MI->getOpcode() == TargetOpcode::STACKMAP ||
1088  MI->getOpcode() == TargetOpcode::PATCHPOINT ||
1089  (isInt<16>(Offset) && (Offset % offsetMinAlign(*MI)) == 0);
1090 }
const uint32_t * getCallPreservedMask(const MachineFunction &MF, CallingConv::ID CC) const override
unsigned getStackAlignment() const
getStackAlignment - This method returns the number of bytes to which the stack pointer must be aligne...
BitVector getReservedRegs(const MachineFunction &MF) const override
void lowerDynamicAreaOffset(MachineBasicBlock::iterator II) const
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
bool isFrameOffsetLegal(const MachineInstr *MI, unsigned BaseReg, int64_t Offset) const override
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
Definition: Path.cpp:234
void ChangeToRegister(unsigned Reg, bool isDef, bool isImp=false, bool isKill=false, bool isDead=false, bool isUndef=false, bool isDebug=false)
ChangeToRegister - Replace this operand with a new register operand of the specified value...
bool isDarwinABI() const
Definition: PPCSubtarget.h:304
unsigned createVirtualRegister(const TargetRegisterClass *RegClass)
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
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...
Describe properties that are true of each instruction in the target description file.
Definition: MCInstrDesc.h:163
The following two target-specific nodes are used for calls through function pointers in the 64-bit SV...
DataLayout DL
const TargetRegisterClass * getLargestLegalSuperClass(const TargetRegisterClass *RC, const MachineFunction &MF) const override
bool hasInlineAsm() const
Returns true if the function contains any inline assembly.
unsigned getID() const
Return the register class ID number.
const MCInstrDesc & getDesc() const
Returns the target instruction descriptor of this MachineInstr.
Definition: MachineInstr.h:276
constexpr bool isInt< 16 >(int64_t x)
Definition: MathExtras.h:298
A debug info location.
Definition: DebugLoc.h:34
const Function * getFunction() const
getFunction - Return the LLVM function that this machine code represents
void lowerVRSAVERestore(MachineBasicBlock::iterator II, unsigned FrameIndex) const
#define R2(n)
bool hasAltivec() const
Definition: PPCSubtarget.h:239
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
Definition: Function.h:186
unsigned getMaxAlignment() const
Return the alignment in bytes that this function must be aligned to, which is greater than the defaul...
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects...
void eliminateFrameIndex(MachineBasicBlock::iterator II, int SPAdj, unsigned FIOperandNum, RegScavenger *RS=nullptr) const override
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
PPCFunctionInfo - This class is derived from MachineFunction private PowerPC target-specific informat...
DILocation * get() const
Get the underlying DILocation.
Definition: DebugLoc.cpp:22
const HexagonInstrInfo * TII
static unsigned getOffsetONFromFION(const MachineInstr &MI, unsigned FIOperandNum)
Reg
All possible values of the reg field in the ModR/M byte.
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
bool hasFP(const MachineFunction &MF) const override
hasFP - Return true if the specified function should have a dedicated frame pointer register...
bool isCallerPreservedPhysReg(unsigned PhysReg, const MachineFunction &MF) const override
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
INLINEASM - Represents an inline asm block.
Definition: ISDOpcodes.h:633
unsigned getNumOperands() const
Access to explicit operands of the instruction.
Definition: MachineInstr.h:282
bool isKill() const
unsigned getFrameRegister(const MachineFunction &MF) const override
bool isFI() const
isFI - Tests if this is a MO_FrameIndex operand.
R32 = MFOCRF(CRREG, INFLAG) - Represents the MFOCRF instruction.
void lowerVRSAVESpilling(MachineBasicBlock::iterator II, unsigned FrameIndex) const
void lowerCRRestore(MachineBasicBlock::iterator II, unsigned FrameIndex) const
const MCPhysReg * getCalleeSavedRegsViaCopy(const MachineFunction *MF) const
int64_t getImm() const
void adjustStackMapLiveOutMask(uint32_t *Mask) const override
const TargetRegisterClass * constrainRegClass(unsigned Reg, const TargetRegisterClass *RC, unsigned MinNumRegs=0)
constrainRegClass - Constrain the register class of the specified virtual register to be a common sub...
This instruction is lowered in PPCRegisterInfo::eliminateFrameIndex to compute an offset from native ...
unsigned getKillRegState(bool B)
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
Definition: MachineInstr.h:279
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
void ChangeToImmediate(int64_t ImmVal)
ChangeToImmediate - Replace this operand with a new immediate operand of the specified value...
const MachineBasicBlock * getParent() const
Definition: MachineInstr.h:139
TargetInstrInfo - Interface to description of machine instruction set.
const MCPhysReg * getCalleeSavedRegs(const MachineFunction *MF) const override
Code Generation virtual methods...
iterator find(const_arg_type_t< KeyT > Val)
Definition: DenseMap.h:131
void materializeFrameBaseRegister(MachineBasicBlock *MBB, unsigned BaseReg, 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 ...
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:401
This file declares the machine register scavenger class.
unsigned const MachineRegisterInfo * MRI
unsigned getBaseRegister(const MachineFunction &MF) const
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
static bool is64Bit(const char *name)
This file contains the declarations for the subclasses of Constant, which represent the different fla...
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:284
static unsigned offsetMinAlign(const MachineInstr &MI)
bool isPositionIndependent() const
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
Common code between 32-bit and 64-bit PowerPC targets.
bool isSVR4ABI() const
Definition: PPCSubtarget.h:305
void resolveFrameIndex(MachineInstr &MI, unsigned BaseReg, int64_t Offset) const override
PPCRegisterInfo(const PPCTargetMachine &TM)
static unsigned getCRFromCRBit(unsigned SrcReg)
bool definesRegister(unsigned Reg, const TargetRegisterInfo *TRI=nullptr) const
Return true if the MachineInstr fully defines the specified register.
Definition: MachineInstr.h:922
const uint32_t * getNoPreservedMask() const override
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
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...
void lowerDynamicAlloc(MachineBasicBlock::iterator II) const
lowerDynamicAlloc - Generate the code for allocating an object in the current frame.
void setDesc(const MCInstrDesc &tid)
Replace the instruction descriptor (thus opcode) of the current instruction with a new one...
static cl::opt< bool > AlwaysBasePointer("ppc-always-use-base-pointer", cl::Hidden, cl::init(false), cl::desc("Force the use of a base pointer in every function"))
unsigned getRegPressureLimit(const TargetRegisterClass *RC, MachineFunction &MF) const override
const PPCInstrInfo * getInstrInfo() const override
Definition: PPCSubtarget.h:179
bool test(unsigned Idx) const
Definition: BitVector.h:502
bool isInlineAsm() const
Definition: MachineInstr.h:798
unsigned getMaxCallFrameSize() const
Return the maximum size of a call frame that must be allocated for an outgoing function call...
bool isAllocatable(unsigned PhysReg) const
isAllocatable - Returns true when PhysReg belongs to an allocatable register class and it hasn't been...
unsigned determineFrameLayout(MachineFunction &MF, bool UpdateMF=true, bool UseEstimate=false) const
determineFrameLayout - Determine the size of the frame and maximum call frame size.
const MachineInstrBuilder & addFrameIndex(int Idx) const
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
Definition: MachineInstr.h:257
void lowerCRBitRestore(MachineBasicBlock::iterator II, unsigned FrameIndex) const
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
Definition: DenseMap.h:126
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
Representation of each machine instruction.
Definition: MachineInstr.h:59
static bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
Bitwise operators - logical and, logical or, logical xor.
Definition: ISDOpcodes.h:361
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition: Function.h:254
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
const TargetRegisterClass * getPointerRegClass(const MachineFunction &MF, unsigned Kind=0) const override
getPointerRegClass - Return the register class to use to hold pointers.
#define I(x, y, z)
Definition: MD5.cpp:58
bool hasVSX() const
Definition: PPCSubtarget.h:242
bool hasP8Vector() const
Definition: PPCSubtarget.h:243
void lowerCRSpilling(MachineBasicBlock::iterator II, unsigned FrameIndex) const
lowerCRSpilling - Generate the code for spilling a CR register.
const unsigned Kind
unsigned getReg() const
getReg - Returns the register number.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void lowerCRBitSpilling(MachineBasicBlock::iterator II, unsigned FrameIndex) const
static cl::opt< bool > EnableBasePointer("ppc-use-base-pointer", cl::Hidden, cl::init(true), cl::desc("Enable use of a base pointer for complex stack frames"))
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
Definition: BitmaskEnum.h:81
IRTranslator LLVM IR MI
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
bool hasBasePointer(const MachineFunction &MF) const
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...
bool hasReservedSpillSlot(const MachineFunction &MF, unsigned Reg, int &FrameIdx) const override