LLVM  16.0.0git
SIRegisterInfo.cpp
Go to the documentation of this file.
1 //===-- SIRegisterInfo.cpp - SI 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 /// \file
10 /// SI implementation of the TargetRegisterInfo class.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "SIRegisterInfo.h"
15 #include "AMDGPU.h"
16 #include "AMDGPURegisterBankInfo.h"
17 #include "GCNSubtarget.h"
20 #include "SIMachineFunctionInfo.h"
26 
27 using namespace llvm;
28 
29 #define GET_REGINFO_TARGET_DESC
30 #include "AMDGPUGenRegisterInfo.inc"
31 
33  "amdgpu-spill-sgpr-to-vgpr",
34  cl::desc("Enable spilling VGPRs to SGPRs"),
36  cl::init(true));
37 
38 std::array<std::vector<int16_t>, 16> SIRegisterInfo::RegSplitParts;
39 std::array<std::array<uint16_t, 32>, 9> SIRegisterInfo::SubRegFromChannelTable;
40 
41 // Map numbers of DWORDs to indexes in SubRegFromChannelTable.
42 // Valid indexes are shifted 1, such that a 0 mapping means unsupported.
43 // e.g. for 8 DWORDs (256-bit), SubRegFromChannelTableWidthMap[8] = 8,
44 // meaning index 7 in SubRegFromChannelTable.
45 static const std::array<unsigned, 17> SubRegFromChannelTableWidthMap = {
46  0, 1, 2, 3, 4, 5, 6, 7, 8, 0, 0, 0, 0, 0, 0, 0, 9};
47 
48 namespace llvm {
49 
50 // A temporary struct to spill SGPRs.
51 // This is mostly to spill SGPRs to memory. Spilling SGPRs into VGPR lanes emits
52 // just v_writelane and v_readlane.
53 //
54 // When spilling to memory, the SGPRs are written into VGPR lanes and the VGPR
55 // is saved to scratch (or the other way around for loads).
56 // For this, a VGPR is required where the needed lanes can be clobbered. The
57 // RegScavenger can provide a VGPR where currently active lanes can be
58 // clobbered, but we still need to save inactive lanes.
59 // The high-level steps are:
60 // - Try to scavenge SGPR(s) to save exec
61 // - Try to scavenge VGPR
62 // - Save needed, all or inactive lanes of a TmpVGPR
63 // - Spill/Restore SGPRs using TmpVGPR
64 // - Restore TmpVGPR
65 //
66 // To save all lanes of TmpVGPR, exec needs to be saved and modified. If we
67 // cannot scavenge temporary SGPRs to save exec, we use the following code:
68 // buffer_store_dword TmpVGPR ; only if active lanes need to be saved
69 // s_not exec, exec
70 // buffer_store_dword TmpVGPR ; save inactive lanes
71 // s_not exec, exec
73  struct PerVGPRData {
74  unsigned PerVGPR;
75  unsigned NumVGPRs;
76  int64_t VGPRLanes;
77  };
78 
79  // The SGPR to save
83  unsigned NumSubRegs;
84  bool IsKill;
85  const DebugLoc &DL;
86 
87  /* When spilling to stack */
88  // The SGPRs are written into this VGPR, which is then written to scratch
89  // (or vice versa for loads).
90  Register TmpVGPR = AMDGPU::NoRegister;
91  // Temporary spill slot to save TmpVGPR to.
92  int TmpVGPRIndex = 0;
93  // If TmpVGPR is live before the spill or if it is scavenged.
94  bool TmpVGPRLive = false;
95  // Scavenged SGPR to save EXEC.
96  Register SavedExecReg = AMDGPU::NoRegister;
97  // Stack index to write the SGPRs to.
98  int Index;
99  unsigned EltSize = 4;
100 
105  const SIInstrInfo &TII;
107  bool IsWave32;
109  unsigned MovOpc;
110  unsigned NotOpc;
111 
114  RegScavenger *RS)
115  : SGPRSpillBuilder(TRI, TII, IsWave32, MI, MI->getOperand(0).getReg(),
116  MI->getOperand(0).isKill(), Index, RS) {}
117 
120  bool IsKill, int Index, RegScavenger *RS)
121  : SuperReg(Reg), MI(MI), IsKill(IsKill), DL(MI->getDebugLoc()),
122  Index(Index), RS(RS), MBB(MI->getParent()), MF(*MBB->getParent()),
123  MFI(*MF.getInfo<SIMachineFunctionInfo>()), TII(TII), TRI(TRI),
124  IsWave32(IsWave32) {
128 
129  if (IsWave32) {
130  ExecReg = AMDGPU::EXEC_LO;
131  MovOpc = AMDGPU::S_MOV_B32;
132  NotOpc = AMDGPU::S_NOT_B32;
133  } else {
134  ExecReg = AMDGPU::EXEC;
135  MovOpc = AMDGPU::S_MOV_B64;
136  NotOpc = AMDGPU::S_NOT_B64;
137  }
138 
139  assert(SuperReg != AMDGPU::M0 && "m0 should never spill");
140  assert(SuperReg != AMDGPU::EXEC_LO && SuperReg != AMDGPU::EXEC_HI &&
141  SuperReg != AMDGPU::EXEC && "exec should never spill");
142  }
143 
146  Data.PerVGPR = IsWave32 ? 32 : 64;
147  Data.NumVGPRs = (NumSubRegs + (Data.PerVGPR - 1)) / Data.PerVGPR;
148  Data.VGPRLanes = (1LL << std::min(Data.PerVGPR, NumSubRegs)) - 1LL;
149  return Data;
150  }
151 
152  // Tries to scavenge SGPRs to save EXEC and a VGPR. Uses v0 if no VGPR is
153  // free.
154  // Writes these instructions if an SGPR can be scavenged:
155  // s_mov_b64 s[6:7], exec ; Save exec
156  // s_mov_b64 exec, 3 ; Wanted lanemask
157  // buffer_store_dword v1 ; Write scavenged VGPR to emergency slot
158  //
159  // Writes these instructions if no SGPR can be scavenged:
160  // buffer_store_dword v0 ; Only if no free VGPR was found
161  // s_not_b64 exec, exec
162  // buffer_store_dword v0 ; Save inactive lanes
163  // ; exec stays inverted, it is flipped back in
164  // ; restore.
165  void prepare() {
166  // Scavenged temporary VGPR to use. It must be scavenged once for any number
167  // of spilled subregs.
168  // FIXME: The liveness analysis is limited and does not tell if a register
169  // is in use in lanes that are currently inactive. We can never be sure if
170  // a register as actually in use in another lane, so we need to save all
171  // used lanes of the chosen VGPR.
172  assert(RS && "Cannot spill SGPR to memory without RegScavenger");
173  TmpVGPR = RS->scavengeRegister(&AMDGPU::VGPR_32RegClass, MI, 0, false);
174 
175  // Reserve temporary stack slot
177  if (TmpVGPR) {
178  // Found a register that is dead in the currently active lanes, we only
179  // need to spill inactive lanes.
180  TmpVGPRLive = false;
181  } else {
182  // Pick v0 because it doesn't make a difference.
183  TmpVGPR = AMDGPU::VGPR0;
184  TmpVGPRLive = true;
185  }
186 
187  if (TmpVGPRLive) {
188  // We need to inform the scavenger that this index is already in use until
189  // we're done with the custom emergency spill.
191  }
192 
193  // We may end up recursively calling the scavenger, and don't want to re-use
194  // the same register.
196 
197  // Try to scavenge SGPRs to save exec
198  assert(!SavedExecReg && "Exec is already saved, refuse to save again");
199  const TargetRegisterClass &RC =
200  IsWave32 ? AMDGPU::SGPR_32RegClass : AMDGPU::SGPR_64RegClass;
202  SavedExecReg = RS->scavengeRegister(&RC, MI, 0, false);
203 
204  int64_t VGPRLanes = getPerVGPRData().VGPRLanes;
205 
206  if (SavedExecReg) {
208  // Set exec to needed lanes
210  auto I =
211  BuildMI(*MBB, MI, DL, TII.get(MovOpc), ExecReg).addImm(VGPRLanes);
212  if (!TmpVGPRLive)
214  // Spill needed lanes
215  TRI.buildVGPRSpillLoadStore(*this, TmpVGPRIndex, 0, /*IsLoad*/ false);
216  } else {
217  // The modify and restore of exec clobber SCC, which we would have to save
218  // and restore. FIXME: We probably would need to reserve a register for
219  // this.
220  if (RS->isRegUsed(AMDGPU::SCC))
221  MI->emitError("unhandled SGPR spill to memory");
222 
223  // Spill active lanes
224  if (TmpVGPRLive)
225  TRI.buildVGPRSpillLoadStore(*this, TmpVGPRIndex, 0, /*IsLoad*/ false,
226  /*IsKill*/ false);
227  // Spill inactive lanes
228  auto I = BuildMI(*MBB, MI, DL, TII.get(NotOpc), ExecReg).addReg(ExecReg);
229  if (!TmpVGPRLive)
231  I->getOperand(2).setIsDead(); // Mark SCC as dead.
232  TRI.buildVGPRSpillLoadStore(*this, TmpVGPRIndex, 0, /*IsLoad*/ false);
233  }
234  }
235 
236  // Writes these instructions if an SGPR can be scavenged:
237  // buffer_load_dword v1 ; Write scavenged VGPR to emergency slot
238  // s_waitcnt vmcnt(0) ; If a free VGPR was found
239  // s_mov_b64 exec, s[6:7] ; Save exec
240  //
241  // Writes these instructions if no SGPR can be scavenged:
242  // buffer_load_dword v0 ; Restore inactive lanes
243  // s_waitcnt vmcnt(0) ; If a free VGPR was found
244  // s_not_b64 exec, exec
245  // buffer_load_dword v0 ; Only if no free VGPR was found
246  void restore() {
247  if (SavedExecReg) {
248  // Restore used lanes
249  TRI.buildVGPRSpillLoadStore(*this, TmpVGPRIndex, 0, /*IsLoad*/ true,
250  /*IsKill*/ false);
251  // Restore exec
252  auto I = BuildMI(*MBB, MI, DL, TII.get(MovOpc), ExecReg)
254  // Add an implicit use of the load so it is not dead.
255  // FIXME This inserts an unnecessary waitcnt
256  if (!TmpVGPRLive) {
258  }
259  } else {
260  // Restore inactive lanes
261  TRI.buildVGPRSpillLoadStore(*this, TmpVGPRIndex, 0, /*IsLoad*/ true,
262  /*IsKill*/ false);
263  auto I = BuildMI(*MBB, MI, DL, TII.get(NotOpc), ExecReg).addReg(ExecReg);
264  if (!TmpVGPRLive)
266  I->getOperand(2).setIsDead(); // Mark SCC as dead.
267 
268  // Restore active lanes
269  if (TmpVGPRLive)
270  TRI.buildVGPRSpillLoadStore(*this, TmpVGPRIndex, 0, /*IsLoad*/ true);
271  }
272 
273  // Inform the scavenger where we're releasing our custom scavenged register.
274  if (TmpVGPRLive) {
275  MachineBasicBlock::iterator RestorePt = std::prev(MI);
277  }
278  }
279 
280  // Write TmpVGPR to memory or read TmpVGPR from memory.
281  // Either using a single buffer_load/store if exec is set to the needed mask
282  // or using
283  // buffer_load
284  // s_not exec, exec
285  // buffer_load
286  // s_not exec, exec
287  void readWriteTmpVGPR(unsigned Offset, bool IsLoad) {
288  if (SavedExecReg) {
289  // Spill needed lanes
290  TRI.buildVGPRSpillLoadStore(*this, Index, Offset, IsLoad);
291  } else {
292  // The modify and restore of exec clobber SCC, which we would have to save
293  // and restore. FIXME: We probably would need to reserve a register for
294  // this.
295  if (RS->isRegUsed(AMDGPU::SCC))
296  MI->emitError("unhandled SGPR spill to memory");
297 
298  // Spill active lanes
299  TRI.buildVGPRSpillLoadStore(*this, Index, Offset, IsLoad,
300  /*IsKill*/ false);
301  // Spill inactive lanes
302  auto Not0 = BuildMI(*MBB, MI, DL, TII.get(NotOpc), ExecReg).addReg(ExecReg);
303  Not0->getOperand(2).setIsDead(); // Mark SCC as dead.
304  TRI.buildVGPRSpillLoadStore(*this, Index, Offset, IsLoad);
305  auto Not1 = BuildMI(*MBB, MI, DL, TII.get(NotOpc), ExecReg).addReg(ExecReg);
306  Not1->getOperand(2).setIsDead(); // Mark SCC as dead.
307  }
308  }
309 
311  assert(MBB->getParent() == &MF);
312  MI = NewMI;
313  MBB = NewMBB;
314  }
315 };
316 
317 } // namespace llvm
318 
320  : AMDGPUGenRegisterInfo(AMDGPU::PC_REG, ST.getAMDGPUDwarfFlavour()), ST(ST),
321  SpillSGPRToVGPR(EnableSpillSGPRToVGPR), isWave32(ST.isWave32()) {
322 
323  assert(getSubRegIndexLaneMask(AMDGPU::sub0).getAsInteger() == 3 &&
324  getSubRegIndexLaneMask(AMDGPU::sub31).getAsInteger() == (3ULL << 62) &&
325  (getSubRegIndexLaneMask(AMDGPU::lo16) |
326  getSubRegIndexLaneMask(AMDGPU::hi16)).getAsInteger() ==
327  getSubRegIndexLaneMask(AMDGPU::sub0).getAsInteger() &&
328  "getNumCoveredRegs() will not work with generated subreg masks!");
329 
330  RegPressureIgnoredUnits.resize(getNumRegUnits());
331  RegPressureIgnoredUnits.set(
333  for (auto Reg : AMDGPU::VGPR_HI16RegClass)
334  RegPressureIgnoredUnits.set(*MCRegUnitIterator(Reg, this));
335 
336  // HACK: Until this is fully tablegen'd.
337  static llvm::once_flag InitializeRegSplitPartsFlag;
338 
339  static auto InitializeRegSplitPartsOnce = [this]() {
340  for (unsigned Idx = 1, E = getNumSubRegIndices() - 1; Idx < E; ++Idx) {
341  unsigned Size = getSubRegIdxSize(Idx);
342  if (Size & 31)
343  continue;
344  std::vector<int16_t> &Vec = RegSplitParts[Size / 32 - 1];
345  unsigned Pos = getSubRegIdxOffset(Idx);
346  if (Pos % Size)
347  continue;
348  Pos /= Size;
349  if (Vec.empty()) {
350  unsigned MaxNumParts = 1024 / Size; // Maximum register is 1024 bits.
351  Vec.resize(MaxNumParts);
352  }
353  Vec[Pos] = Idx;
354  }
355  };
356 
357  static llvm::once_flag InitializeSubRegFromChannelTableFlag;
358 
359  static auto InitializeSubRegFromChannelTableOnce = [this]() {
360  for (auto &Row : SubRegFromChannelTable)
361  Row.fill(AMDGPU::NoSubRegister);
362  for (unsigned Idx = 1; Idx < getNumSubRegIndices(); ++Idx) {
363  unsigned Width = AMDGPUSubRegIdxRanges[Idx].Size / 32;
364  unsigned Offset = AMDGPUSubRegIdxRanges[Idx].Offset / 32;
367  if (Width == 0)
368  continue;
369  unsigned TableIdx = Width - 1;
370  assert(TableIdx < SubRegFromChannelTable.size());
371  assert(Offset < SubRegFromChannelTable[TableIdx].size());
372  SubRegFromChannelTable[TableIdx][Offset] = Idx;
373  }
374  };
375 
376  llvm::call_once(InitializeRegSplitPartsFlag, InitializeRegSplitPartsOnce);
377  llvm::call_once(InitializeSubRegFromChannelTableFlag,
378  InitializeSubRegFromChannelTableOnce);
379 }
380 
381 void SIRegisterInfo::reserveRegisterTuples(BitVector &Reserved,
382  MCRegister Reg) const {
383  MCRegAliasIterator R(Reg, this, true);
384 
385  for (; R.isValid(); ++R)
386  Reserved.set(*R);
387 }
388 
389 // Forced to be here by one .inc
391  const MachineFunction *MF) const {
393  switch (CC) {
394  case CallingConv::C:
395  case CallingConv::Fast:
396  case CallingConv::Cold:
397  return ST.hasGFX90AInsts() ? CSR_AMDGPU_GFX90AInsts_SaveList
398  : CSR_AMDGPU_SaveList;
400  return ST.hasGFX90AInsts() ? CSR_AMDGPU_SI_Gfx_GFX90AInsts_SaveList
401  : CSR_AMDGPU_SI_Gfx_SaveList;
402  default: {
403  // Dummy to not crash RegisterClassInfo.
404  static const MCPhysReg NoCalleeSavedReg = AMDGPU::NoRegister;
405  return &NoCalleeSavedReg;
406  }
407  }
408 }
409 
410 const MCPhysReg *
412  return nullptr;
413 }
414 
416  CallingConv::ID CC) const {
417  switch (CC) {
418  case CallingConv::C:
419  case CallingConv::Fast:
420  case CallingConv::Cold:
421  return ST.hasGFX90AInsts() ? CSR_AMDGPU_GFX90AInsts_RegMask
422  : CSR_AMDGPU_RegMask;
424  return ST.hasGFX90AInsts() ? CSR_AMDGPU_SI_Gfx_GFX90AInsts_RegMask
425  : CSR_AMDGPU_SI_Gfx_RegMask;
426  default:
427  return nullptr;
428  }
429 }
430 
432  return CSR_AMDGPU_NoRegs_RegMask;
433 }
434 
435 const TargetRegisterClass *
437  const MachineFunction &MF) const {
438  // FIXME: Should have a helper function like getEquivalentVGPRClass to get the
439  // equivalent AV class. If used one, the verifier will crash after
440  // RegBankSelect in the GISel flow. The aligned regclasses are not fully given
441  // until Instruction selection.
442  if (ST.hasMAIInsts() && (isVGPRClass(RC) || isAGPRClass(RC))) {
443  if (RC == &AMDGPU::VGPR_32RegClass || RC == &AMDGPU::AGPR_32RegClass)
444  return &AMDGPU::AV_32RegClass;
445  if (RC == &AMDGPU::VReg_64RegClass || RC == &AMDGPU::AReg_64RegClass)
446  return &AMDGPU::AV_64RegClass;
447  if (RC == &AMDGPU::VReg_64_Align2RegClass ||
448  RC == &AMDGPU::AReg_64_Align2RegClass)
449  return &AMDGPU::AV_64_Align2RegClass;
450  if (RC == &AMDGPU::VReg_96RegClass || RC == &AMDGPU::AReg_96RegClass)
451  return &AMDGPU::AV_96RegClass;
452  if (RC == &AMDGPU::VReg_96_Align2RegClass ||
453  RC == &AMDGPU::AReg_96_Align2RegClass)
454  return &AMDGPU::AV_96_Align2RegClass;
455  if (RC == &AMDGPU::VReg_128RegClass || RC == &AMDGPU::AReg_128RegClass)
456  return &AMDGPU::AV_128RegClass;
457  if (RC == &AMDGPU::VReg_128_Align2RegClass ||
458  RC == &AMDGPU::AReg_128_Align2RegClass)
459  return &AMDGPU::AV_128_Align2RegClass;
460  if (RC == &AMDGPU::VReg_160RegClass || RC == &AMDGPU::AReg_160RegClass)
461  return &AMDGPU::AV_160RegClass;
462  if (RC == &AMDGPU::VReg_160_Align2RegClass ||
463  RC == &AMDGPU::AReg_160_Align2RegClass)
464  return &AMDGPU::AV_160_Align2RegClass;
465  if (RC == &AMDGPU::VReg_192RegClass || RC == &AMDGPU::AReg_192RegClass)
466  return &AMDGPU::AV_192RegClass;
467  if (RC == &AMDGPU::VReg_192_Align2RegClass ||
468  RC == &AMDGPU::AReg_192_Align2RegClass)
469  return &AMDGPU::AV_192_Align2RegClass;
470  if (RC == &AMDGPU::VReg_256RegClass || RC == &AMDGPU::AReg_256RegClass)
471  return &AMDGPU::AV_256RegClass;
472  if (RC == &AMDGPU::VReg_256_Align2RegClass ||
473  RC == &AMDGPU::AReg_256_Align2RegClass)
474  return &AMDGPU::AV_256_Align2RegClass;
475  if (RC == &AMDGPU::VReg_512RegClass || RC == &AMDGPU::AReg_512RegClass)
476  return &AMDGPU::AV_512RegClass;
477  if (RC == &AMDGPU::VReg_512_Align2RegClass ||
478  RC == &AMDGPU::AReg_512_Align2RegClass)
479  return &AMDGPU::AV_512_Align2RegClass;
480  if (RC == &AMDGPU::VReg_1024RegClass || RC == &AMDGPU::AReg_1024RegClass)
481  return &AMDGPU::AV_1024RegClass;
482  if (RC == &AMDGPU::VReg_1024_Align2RegClass ||
483  RC == &AMDGPU::AReg_1024_Align2RegClass)
484  return &AMDGPU::AV_1024_Align2RegClass;
485  }
486 
488 }
489 
491  const SIFrameLowering *TFI = ST.getFrameLowering();
492  const SIMachineFunctionInfo *FuncInfo = MF.getInfo<SIMachineFunctionInfo>();
493  // During ISel lowering we always reserve the stack pointer in entry
494  // functions, but never actually want to reference it when accessing our own
495  // frame. If we need a frame pointer we use it, but otherwise we can just use
496  // an immediate "0" which we represent by returning NoRegister.
497  if (FuncInfo->isEntryFunction()) {
498  return TFI->hasFP(MF) ? FuncInfo->getFrameOffsetReg() : Register();
499  }
500  return TFI->hasFP(MF) ? FuncInfo->getFrameOffsetReg()
501  : FuncInfo->getStackPtrOffsetReg();
502 }
503 
505  // When we need stack realignment, we can't reference off of the
506  // stack pointer, so we reserve a base pointer.
507  const MachineFrameInfo &MFI = MF.getFrameInfo();
508  return MFI.getNumFixedObjects() && shouldRealignStack(MF);
509 }
510 
511 Register SIRegisterInfo::getBaseRegister() const { return AMDGPU::SGPR34; }
512 
514  return AMDGPU_AllVGPRs_RegMask;
515 }
516 
518  return AMDGPU_AllAGPRs_RegMask;
519 }
520 
522  return AMDGPU_AllVectorRegs_RegMask;
523 }
524 
526  return AMDGPU_AllAllocatableSRegs_RegMask;
527 }
528 
529 unsigned SIRegisterInfo::getSubRegFromChannel(unsigned Channel,
530  unsigned NumRegs) {
531  assert(NumRegs < SubRegFromChannelTableWidthMap.size());
532  unsigned NumRegIndex = SubRegFromChannelTableWidthMap[NumRegs];
533  assert(NumRegIndex && "Not implemented");
534  assert(Channel < SubRegFromChannelTable[NumRegIndex - 1].size());
535  return SubRegFromChannelTable[NumRegIndex - 1][Channel];
536 }
537 
539  const MachineFunction &MF) const {
540  unsigned BaseIdx = alignDown(ST.getMaxNumSGPRs(MF), 4) - 4;
541  MCRegister BaseReg(AMDGPU::SGPR_32RegClass.getRegister(BaseIdx));
542  return getMatchingSuperReg(BaseReg, AMDGPU::sub0, &AMDGPU::SGPR_128RegClass);
543 }
544 
546  BitVector Reserved(getNumRegs());
547  Reserved.set(AMDGPU::MODE);
548 
550 
551  // Reserve special purpose registers.
552  //
553  // EXEC_LO and EXEC_HI could be allocated and used as regular register, but
554  // this seems likely to result in bugs, so I'm marking them as reserved.
555  reserveRegisterTuples(Reserved, AMDGPU::EXEC);
556  reserveRegisterTuples(Reserved, AMDGPU::FLAT_SCR);
557 
558  // M0 has to be reserved so that llvm accepts it as a live-in into a block.
559  reserveRegisterTuples(Reserved, AMDGPU::M0);
560 
561  // Reserve src_vccz, src_execz, src_scc.
562  reserveRegisterTuples(Reserved, AMDGPU::SRC_VCCZ);
563  reserveRegisterTuples(Reserved, AMDGPU::SRC_EXECZ);
564  reserveRegisterTuples(Reserved, AMDGPU::SRC_SCC);
565 
566  // Reserve the memory aperture registers
567  reserveRegisterTuples(Reserved, AMDGPU::SRC_SHARED_BASE);
568  reserveRegisterTuples(Reserved, AMDGPU::SRC_SHARED_LIMIT);
569  reserveRegisterTuples(Reserved, AMDGPU::SRC_PRIVATE_BASE);
570  reserveRegisterTuples(Reserved, AMDGPU::SRC_PRIVATE_LIMIT);
571 
572  // Reserve src_pops_exiting_wave_id - support is not implemented in Codegen.
573  reserveRegisterTuples(Reserved, AMDGPU::SRC_POPS_EXITING_WAVE_ID);
574 
575  // Reserve xnack_mask registers - support is not implemented in Codegen.
576  reserveRegisterTuples(Reserved, AMDGPU::XNACK_MASK);
577 
578  // Reserve lds_direct register - support is not implemented in Codegen.
579  reserveRegisterTuples(Reserved, AMDGPU::LDS_DIRECT);
580 
581  // Reserve Trap Handler registers - support is not implemented in Codegen.
582  reserveRegisterTuples(Reserved, AMDGPU::TBA);
583  reserveRegisterTuples(Reserved, AMDGPU::TMA);
584  reserveRegisterTuples(Reserved, AMDGPU::TTMP0_TTMP1);
585  reserveRegisterTuples(Reserved, AMDGPU::TTMP2_TTMP3);
586  reserveRegisterTuples(Reserved, AMDGPU::TTMP4_TTMP5);
587  reserveRegisterTuples(Reserved, AMDGPU::TTMP6_TTMP7);
588  reserveRegisterTuples(Reserved, AMDGPU::TTMP8_TTMP9);
589  reserveRegisterTuples(Reserved, AMDGPU::TTMP10_TTMP11);
590  reserveRegisterTuples(Reserved, AMDGPU::TTMP12_TTMP13);
591  reserveRegisterTuples(Reserved, AMDGPU::TTMP14_TTMP15);
592 
593  // Reserve null register - it shall never be allocated
594  reserveRegisterTuples(Reserved, AMDGPU::SGPR_NULL64);
595 
596  // Disallow vcc_hi allocation in wave32. It may be allocated but most likely
597  // will result in bugs.
598  if (isWave32) {
599  Reserved.set(AMDGPU::VCC);
600  Reserved.set(AMDGPU::VCC_HI);
601  }
602 
603  // Reserve SGPRs.
604  //
605  unsigned MaxNumSGPRs = ST.getMaxNumSGPRs(MF);
606  unsigned TotalNumSGPRs = AMDGPU::SGPR_32RegClass.getNumRegs();
607  for (unsigned i = MaxNumSGPRs; i < TotalNumSGPRs; ++i) {
608  unsigned Reg = AMDGPU::SGPR_32RegClass.getRegister(i);
609  reserveRegisterTuples(Reserved, Reg);
610  }
611 
612  for (auto Reg : AMDGPU::SReg_32RegClass) {
613  Reserved.set(getSubReg(Reg, AMDGPU::hi16));
614  Register Low = getSubReg(Reg, AMDGPU::lo16);
615  // This is to prevent BB vcc liveness errors.
616  if (!AMDGPU::SGPR_LO16RegClass.contains(Low))
617  Reserved.set(Low);
618  }
619 
620  Register ScratchRSrcReg = MFI->getScratchRSrcReg();
621  if (ScratchRSrcReg != AMDGPU::NoRegister) {
622  // Reserve 4 SGPRs for the scratch buffer resource descriptor in case we
623  // need to spill.
624  // TODO: May need to reserve a VGPR if doing LDS spilling.
625  reserveRegisterTuples(Reserved, ScratchRSrcReg);
626  }
627 
628  // We have to assume the SP is needed in case there are calls in the function,
629  // which is detected after the function is lowered. If we aren't really going
630  // to need SP, don't bother reserving it.
631  MCRegister StackPtrReg = MFI->getStackPtrOffsetReg();
632  if (StackPtrReg) {
633  reserveRegisterTuples(Reserved, StackPtrReg);
634  assert(!isSubRegister(ScratchRSrcReg, StackPtrReg));
635  }
636 
637  MCRegister FrameReg = MFI->getFrameOffsetReg();
638  if (FrameReg) {
639  reserveRegisterTuples(Reserved, FrameReg);
640  assert(!isSubRegister(ScratchRSrcReg, FrameReg));
641  }
642 
643  if (hasBasePointer(MF)) {
644  MCRegister BasePtrReg = getBaseRegister();
645  reserveRegisterTuples(Reserved, BasePtrReg);
646  assert(!isSubRegister(ScratchRSrcReg, BasePtrReg));
647  }
648 
649  // Reserve VGPRs/AGPRs.
650  //
651  unsigned MaxNumVGPRs = ST.getMaxNumVGPRs(MF);
652  unsigned MaxNumAGPRs = MaxNumVGPRs;
653  unsigned TotalNumVGPRs = AMDGPU::VGPR_32RegClass.getNumRegs();
654 
655  // Reserve all the AGPRs if there are no instructions to use it.
656  if (!ST.hasMAIInsts()) {
657  for (unsigned i = 0; i < MaxNumAGPRs; ++i) {
658  unsigned Reg = AMDGPU::AGPR_32RegClass.getRegister(i);
659  reserveRegisterTuples(Reserved, Reg);
660  }
661  }
662 
663  for (auto Reg : AMDGPU::AGPR_32RegClass) {
664  Reserved.set(getSubReg(Reg, AMDGPU::hi16));
665  }
666 
667  // On GFX90A, the number of VGPRs and AGPRs need not be equal. Theoretically,
668  // a wave may have up to 512 total vector registers combining together both
669  // VGPRs and AGPRs. Hence, in an entry function without calls and without
670  // AGPRs used within it, it is possible to use the whole vector register
671  // budget for VGPRs.
672  //
673  // TODO: it shall be possible to estimate maximum AGPR/VGPR pressure and split
674  // register file accordingly.
675  if (ST.hasGFX90AInsts()) {
676  if (MFI->usesAGPRs(MF)) {
677  MaxNumVGPRs /= 2;
678  MaxNumAGPRs = MaxNumVGPRs;
679  } else {
680  if (MaxNumVGPRs > TotalNumVGPRs) {
681  MaxNumAGPRs = MaxNumVGPRs - TotalNumVGPRs;
682  MaxNumVGPRs = TotalNumVGPRs;
683  } else
684  MaxNumAGPRs = 0;
685  }
686  }
687 
688  for (unsigned i = MaxNumVGPRs; i < TotalNumVGPRs; ++i) {
689  unsigned Reg = AMDGPU::VGPR_32RegClass.getRegister(i);
690  reserveRegisterTuples(Reserved, Reg);
691  }
692 
693  for (unsigned i = MaxNumAGPRs; i < TotalNumVGPRs; ++i) {
694  unsigned Reg = AMDGPU::AGPR_32RegClass.getRegister(i);
695  reserveRegisterTuples(Reserved, Reg);
696  }
697 
698  // On GFX908, in order to guarantee copying between AGPRs, we need a scratch
699  // VGPR available at all times.
700  if (ST.hasMAIInsts() && !ST.hasGFX90AInsts()) {
701  reserveRegisterTuples(Reserved, MFI->getVGPRForAGPRCopy());
702  }
703 
704  for (Register Reg : MFI->WWMReservedRegs)
705  reserveRegisterTuples(Reserved, Reg);
706 
707  // FIXME: Stop using reserved registers for this.
708  for (MCPhysReg Reg : MFI->getAGPRSpillVGPRs())
709  reserveRegisterTuples(Reserved, Reg);
710 
711  for (MCPhysReg Reg : MFI->getVGPRSpillAGPRs())
712  reserveRegisterTuples(Reserved, Reg);
713 
714  for (auto SSpill : MFI->getSGPRSpillVGPRs())
715  reserveRegisterTuples(Reserved, SSpill.VGPR);
716 
717  return Reserved;
718 }
719 
721  MCRegister PhysReg) const {
722  return !MF.getRegInfo().isReserved(PhysReg);
723 }
724 
727  // On entry, the base address is 0, so it can't possibly need any more
728  // alignment.
729 
730  // FIXME: Should be able to specify the entry frame alignment per calling
731  // convention instead.
732  if (Info->isEntryFunction())
733  return false;
734 
736 }
737 
740  if (Info->isEntryFunction()) {
741  const MachineFrameInfo &MFI = Fn.getFrameInfo();
742  return MFI.hasStackObjects() || MFI.hasCalls();
743  }
744 
745  // May need scavenger for dealing with callee saved registers.
746  return true;
747 }
748 
750  const MachineFunction &MF) const {
751  // Do not use frame virtual registers. They used to be used for SGPRs, but
752  // once we reach PrologEpilogInserter, we can no longer spill SGPRs. If the
753  // scavenger fails, we can increment/decrement the necessary SGPRs to avoid a
754  // spill.
755  return false;
756 }
757 
759  const MachineFunction &MF) const {
760  const MachineFrameInfo &MFI = MF.getFrameInfo();
761  return MFI.hasStackObjects();
762 }
763 
765  const MachineFunction &) const {
766  // There are no special dedicated stack or frame pointers.
767  return true;
768 }
769 
772 
773  int OffIdx = AMDGPU::getNamedOperandIdx(MI->getOpcode(),
774  AMDGPU::OpName::offset);
775  return MI->getOperand(OffIdx).getImm();
776 }
777 
779  int Idx) const {
781  return 0;
782 
783  assert((Idx == AMDGPU::getNamedOperandIdx(MI->getOpcode(),
784  AMDGPU::OpName::vaddr) ||
785  (Idx == AMDGPU::getNamedOperandIdx(MI->getOpcode(),
786  AMDGPU::OpName::saddr))) &&
787  "Should never see frame index on non-address operand");
788 
789  return getScratchInstrOffset(MI);
790 }
791 
792 bool SIRegisterInfo::needsFrameBaseReg(MachineInstr *MI, int64_t Offset) const {
794  return false;
795 
796  int64_t FullOffset = Offset + getScratchInstrOffset(MI);
797 
798  if (SIInstrInfo::isMUBUF(*MI))
799  return !SIInstrInfo::isLegalMUBUFImmOffset(FullOffset);
800 
801  const SIInstrInfo *TII = ST.getInstrInfo();
802  return !TII->isLegalFLATOffset(FullOffset, AMDGPUAS::PRIVATE_ADDRESS,
804 }
805 
807  int FrameIdx,
808  int64_t Offset) const {
810  DebugLoc DL; // Defaults to "unknown"
811 
812  if (Ins != MBB->end())
813  DL = Ins->getDebugLoc();
814 
815  MachineFunction *MF = MBB->getParent();
816  const SIInstrInfo *TII = ST.getInstrInfo();
818  unsigned MovOpc = ST.enableFlatScratch() ? AMDGPU::S_MOV_B32
819  : AMDGPU::V_MOV_B32_e32;
820 
822  ST.enableFlatScratch() ? &AMDGPU::SReg_32_XEXEC_HIRegClass
823  : &AMDGPU::VGPR_32RegClass);
824 
825  if (Offset == 0) {
826  BuildMI(*MBB, Ins, DL, TII->get(MovOpc), BaseReg)
827  .addFrameIndex(FrameIdx);
828  return BaseReg;
829  }
830 
831  Register OffsetReg = MRI.createVirtualRegister(&AMDGPU::SReg_32_XM0RegClass);
832 
834  ST.enableFlatScratch() ? &AMDGPU::SReg_32_XM0RegClass
835  : &AMDGPU::VGPR_32RegClass);
836 
837  BuildMI(*MBB, Ins, DL, TII->get(AMDGPU::S_MOV_B32), OffsetReg)
838  .addImm(Offset);
839  BuildMI(*MBB, Ins, DL, TII->get(MovOpc), FIReg)
840  .addFrameIndex(FrameIdx);
841 
842  if (ST.enableFlatScratch() ) {
843  BuildMI(*MBB, Ins, DL, TII->get(AMDGPU::S_ADD_I32), BaseReg)
844  .addReg(OffsetReg, RegState::Kill)
845  .addReg(FIReg);
846  return BaseReg;
847  }
848 
849  TII->getAddNoCarry(*MBB, Ins, DL, BaseReg)
850  .addReg(OffsetReg, RegState::Kill)
851  .addReg(FIReg)
852  .addImm(0); // clamp bit
853 
854  return BaseReg;
855 }
856 
858  int64_t Offset) const {
859  const SIInstrInfo *TII = ST.getInstrInfo();
860  bool IsFlat = TII->isFLATScratch(MI);
861 
862 #ifndef NDEBUG
863  // FIXME: Is it possible to be storing a frame index to itself?
864  bool SeenFI = false;
865  for (const MachineOperand &MO: MI.operands()) {
866  if (MO.isFI()) {
867  if (SeenFI)
868  llvm_unreachable("should not see multiple frame indices");
869 
870  SeenFI = true;
871  }
872  }
873 #endif
874 
875  MachineOperand *FIOp =
876  TII->getNamedOperand(MI, IsFlat ? AMDGPU::OpName::saddr
877  : AMDGPU::OpName::vaddr);
878 
879  MachineOperand *OffsetOp = TII->getNamedOperand(MI, AMDGPU::OpName::offset);
880  int64_t NewOffset = OffsetOp->getImm() + Offset;
881 
882  assert(FIOp && FIOp->isFI() && "frame index must be address operand");
883  assert(TII->isMUBUF(MI) || TII->isFLATScratch(MI));
884 
885  if (IsFlat) {
886  assert(TII->isLegalFLATOffset(NewOffset, AMDGPUAS::PRIVATE_ADDRESS,
888  "offset should be legal");
889  FIOp->ChangeToRegister(BaseReg, false);
890  OffsetOp->setImm(NewOffset);
891  return;
892  }
893 
894 #ifndef NDEBUG
895  MachineOperand *SOffset = TII->getNamedOperand(MI, AMDGPU::OpName::soffset);
896  assert(SOffset->isImm() && SOffset->getImm() == 0);
897 #endif
898 
900  "offset should be legal");
901 
902  FIOp->ChangeToRegister(BaseReg, false);
903  OffsetOp->setImm(NewOffset);
904 }
905 
907  Register BaseReg,
908  int64_t Offset) const {
910  return false;
911 
912  int64_t NewOffset = Offset + getScratchInstrOffset(MI);
913 
914  if (SIInstrInfo::isMUBUF(*MI))
915  return SIInstrInfo::isLegalMUBUFImmOffset(NewOffset);
916 
917  const SIInstrInfo *TII = ST.getInstrInfo();
918  return TII->isLegalFLATOffset(NewOffset, AMDGPUAS::PRIVATE_ADDRESS,
920 }
921 
923  const MachineFunction &MF, unsigned Kind) const {
924  // This is inaccurate. It depends on the instruction and address space. The
925  // only place where we should hit this is for dealing with frame indexes /
926  // private accesses, so this is correct in that case.
927  return &AMDGPU::VGPR_32RegClass;
928 }
929 
930 const TargetRegisterClass *
932  if (isAGPRClass(RC) && !ST.hasGFX90AInsts())
933  return getEquivalentVGPRClass(RC);
934  if (RC == &AMDGPU::SCC_CLASSRegClass)
935  return getWaveMaskRegClass();
936 
937  return RC;
938 }
939 
940 static unsigned getNumSubRegsForSpillOp(unsigned Op) {
941 
942  switch (Op) {
943  case AMDGPU::SI_SPILL_S1024_SAVE:
944  case AMDGPU::SI_SPILL_S1024_RESTORE:
945  case AMDGPU::SI_SPILL_V1024_SAVE:
946  case AMDGPU::SI_SPILL_V1024_RESTORE:
947  case AMDGPU::SI_SPILL_A1024_SAVE:
948  case AMDGPU::SI_SPILL_A1024_RESTORE:
949  case AMDGPU::SI_SPILL_AV1024_SAVE:
950  case AMDGPU::SI_SPILL_AV1024_RESTORE:
951  return 32;
952  case AMDGPU::SI_SPILL_S512_SAVE:
953  case AMDGPU::SI_SPILL_S512_RESTORE:
954  case AMDGPU::SI_SPILL_V512_SAVE:
955  case AMDGPU::SI_SPILL_V512_RESTORE:
956  case AMDGPU::SI_SPILL_A512_SAVE:
957  case AMDGPU::SI_SPILL_A512_RESTORE:
958  case AMDGPU::SI_SPILL_AV512_SAVE:
959  case AMDGPU::SI_SPILL_AV512_RESTORE:
960  return 16;
961  case AMDGPU::SI_SPILL_S256_SAVE:
962  case AMDGPU::SI_SPILL_S256_RESTORE:
963  case AMDGPU::SI_SPILL_V256_SAVE:
964  case AMDGPU::SI_SPILL_V256_RESTORE:
965  case AMDGPU::SI_SPILL_A256_SAVE:
966  case AMDGPU::SI_SPILL_A256_RESTORE:
967  case AMDGPU::SI_SPILL_AV256_SAVE:
968  case AMDGPU::SI_SPILL_AV256_RESTORE:
969  return 8;
970  case AMDGPU::SI_SPILL_S224_SAVE:
971  case AMDGPU::SI_SPILL_S224_RESTORE:
972  case AMDGPU::SI_SPILL_V224_SAVE:
973  case AMDGPU::SI_SPILL_V224_RESTORE:
974  case AMDGPU::SI_SPILL_A224_SAVE:
975  case AMDGPU::SI_SPILL_A224_RESTORE:
976  case AMDGPU::SI_SPILL_AV224_SAVE:
977  case AMDGPU::SI_SPILL_AV224_RESTORE:
978  return 7;
979  case AMDGPU::SI_SPILL_S192_SAVE:
980  case AMDGPU::SI_SPILL_S192_RESTORE:
981  case AMDGPU::SI_SPILL_V192_SAVE:
982  case AMDGPU::SI_SPILL_V192_RESTORE:
983  case AMDGPU::SI_SPILL_A192_SAVE:
984  case AMDGPU::SI_SPILL_A192_RESTORE:
985  case AMDGPU::SI_SPILL_AV192_SAVE:
986  case AMDGPU::SI_SPILL_AV192_RESTORE:
987  return 6;
988  case AMDGPU::SI_SPILL_S160_SAVE:
989  case AMDGPU::SI_SPILL_S160_RESTORE:
990  case AMDGPU::SI_SPILL_V160_SAVE:
991  case AMDGPU::SI_SPILL_V160_RESTORE:
992  case AMDGPU::SI_SPILL_A160_SAVE:
993  case AMDGPU::SI_SPILL_A160_RESTORE:
994  case AMDGPU::SI_SPILL_AV160_SAVE:
995  case AMDGPU::SI_SPILL_AV160_RESTORE:
996  return 5;
997  case AMDGPU::SI_SPILL_S128_SAVE:
998  case AMDGPU::SI_SPILL_S128_RESTORE:
999  case AMDGPU::SI_SPILL_V128_SAVE:
1000  case AMDGPU::SI_SPILL_V128_RESTORE:
1001  case AMDGPU::SI_SPILL_A128_SAVE:
1002  case AMDGPU::SI_SPILL_A128_RESTORE:
1003  case AMDGPU::SI_SPILL_AV128_SAVE:
1004  case AMDGPU::SI_SPILL_AV128_RESTORE:
1005  return 4;
1006  case AMDGPU::SI_SPILL_S96_SAVE:
1007  case AMDGPU::SI_SPILL_S96_RESTORE:
1008  case AMDGPU::SI_SPILL_V96_SAVE:
1009  case AMDGPU::SI_SPILL_V96_RESTORE:
1010  case AMDGPU::SI_SPILL_A96_SAVE:
1011  case AMDGPU::SI_SPILL_A96_RESTORE:
1012  case AMDGPU::SI_SPILL_AV96_SAVE:
1013  case AMDGPU::SI_SPILL_AV96_RESTORE:
1014  return 3;
1015  case AMDGPU::SI_SPILL_S64_SAVE:
1016  case AMDGPU::SI_SPILL_S64_RESTORE:
1017  case AMDGPU::SI_SPILL_V64_SAVE:
1018  case AMDGPU::SI_SPILL_V64_RESTORE:
1019  case AMDGPU::SI_SPILL_A64_SAVE:
1020  case AMDGPU::SI_SPILL_A64_RESTORE:
1021  case AMDGPU::SI_SPILL_AV64_SAVE:
1022  case AMDGPU::SI_SPILL_AV64_RESTORE:
1023  return 2;
1024  case AMDGPU::SI_SPILL_S32_SAVE:
1025  case AMDGPU::SI_SPILL_S32_RESTORE:
1026  case AMDGPU::SI_SPILL_V32_SAVE:
1027  case AMDGPU::SI_SPILL_V32_RESTORE:
1028  case AMDGPU::SI_SPILL_A32_SAVE:
1029  case AMDGPU::SI_SPILL_A32_RESTORE:
1030  case AMDGPU::SI_SPILL_AV32_SAVE:
1031  case AMDGPU::SI_SPILL_AV32_RESTORE:
1032  return 1;
1033  default: llvm_unreachable("Invalid spill opcode");
1034  }
1035 }
1036 
1037 static int getOffsetMUBUFStore(unsigned Opc) {
1038  switch (Opc) {
1039  case AMDGPU::BUFFER_STORE_DWORD_OFFEN:
1040  return AMDGPU::BUFFER_STORE_DWORD_OFFSET;
1041  case AMDGPU::BUFFER_STORE_BYTE_OFFEN:
1042  return AMDGPU::BUFFER_STORE_BYTE_OFFSET;
1043  case AMDGPU::BUFFER_STORE_SHORT_OFFEN:
1044  return AMDGPU::BUFFER_STORE_SHORT_OFFSET;
1045  case AMDGPU::BUFFER_STORE_DWORDX2_OFFEN:
1046  return AMDGPU::BUFFER_STORE_DWORDX2_OFFSET;
1047  case AMDGPU::BUFFER_STORE_DWORDX3_OFFEN:
1048  return AMDGPU::BUFFER_STORE_DWORDX3_OFFSET;
1049  case AMDGPU::BUFFER_STORE_DWORDX4_OFFEN:
1050  return AMDGPU::BUFFER_STORE_DWORDX4_OFFSET;
1051  case AMDGPU::BUFFER_STORE_SHORT_D16_HI_OFFEN:
1052  return AMDGPU::BUFFER_STORE_SHORT_D16_HI_OFFSET;
1053  case AMDGPU::BUFFER_STORE_BYTE_D16_HI_OFFEN:
1054  return AMDGPU::BUFFER_STORE_BYTE_D16_HI_OFFSET;
1055  default:
1056  return -1;
1057  }
1058 }
1059 
1060 static int getOffsetMUBUFLoad(unsigned Opc) {
1061  switch (Opc) {
1062  case AMDGPU::BUFFER_LOAD_DWORD_OFFEN:
1063  return AMDGPU::BUFFER_LOAD_DWORD_OFFSET;
1064  case AMDGPU::BUFFER_LOAD_UBYTE_OFFEN:
1065  return AMDGPU::BUFFER_LOAD_UBYTE_OFFSET;
1066  case AMDGPU::BUFFER_LOAD_SBYTE_OFFEN:
1067  return AMDGPU::BUFFER_LOAD_SBYTE_OFFSET;
1068  case AMDGPU::BUFFER_LOAD_USHORT_OFFEN:
1069  return AMDGPU::BUFFER_LOAD_USHORT_OFFSET;
1070  case AMDGPU::BUFFER_LOAD_SSHORT_OFFEN:
1071  return AMDGPU::BUFFER_LOAD_SSHORT_OFFSET;
1072  case AMDGPU::BUFFER_LOAD_DWORDX2_OFFEN:
1073  return AMDGPU::BUFFER_LOAD_DWORDX2_OFFSET;
1074  case AMDGPU::BUFFER_LOAD_DWORDX3_OFFEN:
1075  return AMDGPU::BUFFER_LOAD_DWORDX3_OFFSET;
1076  case AMDGPU::BUFFER_LOAD_DWORDX4_OFFEN:
1077  return AMDGPU::BUFFER_LOAD_DWORDX4_OFFSET;
1078  case AMDGPU::BUFFER_LOAD_UBYTE_D16_OFFEN:
1079  return AMDGPU::BUFFER_LOAD_UBYTE_D16_OFFSET;
1080  case AMDGPU::BUFFER_LOAD_UBYTE_D16_HI_OFFEN:
1081  return AMDGPU::BUFFER_LOAD_UBYTE_D16_HI_OFFSET;
1082  case AMDGPU::BUFFER_LOAD_SBYTE_D16_OFFEN:
1083  return AMDGPU::BUFFER_LOAD_SBYTE_D16_OFFSET;
1084  case AMDGPU::BUFFER_LOAD_SBYTE_D16_HI_OFFEN:
1085  return AMDGPU::BUFFER_LOAD_SBYTE_D16_HI_OFFSET;
1086  case AMDGPU::BUFFER_LOAD_SHORT_D16_OFFEN:
1087  return AMDGPU::BUFFER_LOAD_SHORT_D16_OFFSET;
1088  case AMDGPU::BUFFER_LOAD_SHORT_D16_HI_OFFEN:
1089  return AMDGPU::BUFFER_LOAD_SHORT_D16_HI_OFFSET;
1090  default:
1091  return -1;
1092  }
1093 }
1094 
1095 static int getOffenMUBUFStore(unsigned Opc) {
1096  switch (Opc) {
1097  case AMDGPU::BUFFER_STORE_DWORD_OFFSET:
1098  return AMDGPU::BUFFER_STORE_DWORD_OFFEN;
1099  case AMDGPU::BUFFER_STORE_BYTE_OFFSET:
1100  return AMDGPU::BUFFER_STORE_BYTE_OFFEN;
1101  case AMDGPU::BUFFER_STORE_SHORT_OFFSET:
1102  return AMDGPU::BUFFER_STORE_SHORT_OFFEN;
1103  case AMDGPU::BUFFER_STORE_DWORDX2_OFFSET:
1104  return AMDGPU::BUFFER_STORE_DWORDX2_OFFEN;
1105  case AMDGPU::BUFFER_STORE_DWORDX3_OFFSET:
1106  return AMDGPU::BUFFER_STORE_DWORDX3_OFFEN;
1107  case AMDGPU::BUFFER_STORE_DWORDX4_OFFSET:
1108  return AMDGPU::BUFFER_STORE_DWORDX4_OFFEN;
1109  case AMDGPU::BUFFER_STORE_SHORT_D16_HI_OFFSET:
1110  return AMDGPU::BUFFER_STORE_SHORT_D16_HI_OFFEN;
1111  case AMDGPU::BUFFER_STORE_BYTE_D16_HI_OFFSET:
1112  return AMDGPU::BUFFER_STORE_BYTE_D16_HI_OFFEN;
1113  default:
1114  return -1;
1115  }
1116 }
1117 
1118 static int getOffenMUBUFLoad(unsigned Opc) {
1119  switch (Opc) {
1120  case AMDGPU::BUFFER_LOAD_DWORD_OFFSET:
1121  return AMDGPU::BUFFER_LOAD_DWORD_OFFEN;
1122  case AMDGPU::BUFFER_LOAD_UBYTE_OFFSET:
1123  return AMDGPU::BUFFER_LOAD_UBYTE_OFFEN;
1124  case AMDGPU::BUFFER_LOAD_SBYTE_OFFSET:
1125  return AMDGPU::BUFFER_LOAD_SBYTE_OFFEN;
1126  case AMDGPU::BUFFER_LOAD_USHORT_OFFSET:
1127  return AMDGPU::BUFFER_LOAD_USHORT_OFFEN;
1128  case AMDGPU::BUFFER_LOAD_SSHORT_OFFSET:
1129  return AMDGPU::BUFFER_LOAD_SSHORT_OFFEN;
1130  case AMDGPU::BUFFER_LOAD_DWORDX2_OFFSET:
1131  return AMDGPU::BUFFER_LOAD_DWORDX2_OFFEN;
1132  case AMDGPU::BUFFER_LOAD_DWORDX3_OFFSET:
1133  return AMDGPU::BUFFER_LOAD_DWORDX3_OFFEN;
1134  case AMDGPU::BUFFER_LOAD_DWORDX4_OFFSET:
1135  return AMDGPU::BUFFER_LOAD_DWORDX4_OFFEN;
1136  case AMDGPU::BUFFER_LOAD_UBYTE_D16_OFFSET:
1137  return AMDGPU::BUFFER_LOAD_UBYTE_D16_OFFEN;
1138  case AMDGPU::BUFFER_LOAD_UBYTE_D16_HI_OFFSET:
1139  return AMDGPU::BUFFER_LOAD_UBYTE_D16_HI_OFFEN;
1140  case AMDGPU::BUFFER_LOAD_SBYTE_D16_OFFSET:
1141  return AMDGPU::BUFFER_LOAD_SBYTE_D16_OFFEN;
1142  case AMDGPU::BUFFER_LOAD_SBYTE_D16_HI_OFFSET:
1143  return AMDGPU::BUFFER_LOAD_SBYTE_D16_HI_OFFEN;
1144  case AMDGPU::BUFFER_LOAD_SHORT_D16_OFFSET:
1145  return AMDGPU::BUFFER_LOAD_SHORT_D16_OFFEN;
1146  case AMDGPU::BUFFER_LOAD_SHORT_D16_HI_OFFSET:
1147  return AMDGPU::BUFFER_LOAD_SHORT_D16_HI_OFFEN;
1148  default:
1149  return -1;
1150  }
1151 }
1152 
1156  int Index, unsigned Lane,
1157  unsigned ValueReg, bool IsKill) {
1158  MachineFunction *MF = MBB.getParent();
1160  const SIInstrInfo *TII = ST.getInstrInfo();
1161 
1162  MCPhysReg Reg = MFI->getVGPRToAGPRSpill(Index, Lane);
1163 
1164  if (Reg == AMDGPU::NoRegister)
1165  return MachineInstrBuilder();
1166 
1167  bool IsStore = MI->mayStore();
1169  auto *TRI = static_cast<const SIRegisterInfo*>(MRI.getTargetRegisterInfo());
1170 
1171  unsigned Dst = IsStore ? Reg : ValueReg;
1172  unsigned Src = IsStore ? ValueReg : Reg;
1173  bool IsVGPR = TRI->isVGPR(MRI, Reg);
1174  DebugLoc DL = MI->getDebugLoc();
1175  if (IsVGPR == TRI->isVGPR(MRI, ValueReg)) {
1176  // Spiller during regalloc may restore a spilled register to its superclass.
1177  // It could result in AGPR spills restored to VGPRs or the other way around,
1178  // making the src and dst with identical regclasses at this point. It just
1179  // needs a copy in such cases.
1180  auto CopyMIB = BuildMI(MBB, MI, DL, TII->get(AMDGPU::COPY), Dst)
1181  .addReg(Src, getKillRegState(IsKill));
1183  return CopyMIB;
1184  }
1185  unsigned Opc = (IsStore ^ IsVGPR) ? AMDGPU::V_ACCVGPR_WRITE_B32_e64
1186  : AMDGPU::V_ACCVGPR_READ_B32_e64;
1187 
1188  auto MIB = BuildMI(MBB, MI, DL, TII->get(Opc), Dst)
1189  .addReg(Src, getKillRegState(IsKill));
1191  return MIB;
1192 }
1193 
1194 // This differs from buildSpillLoadStore by only scavenging a VGPR. It does not
1195 // need to handle the case where an SGPR may need to be spilled while spilling.
1197  MachineFrameInfo &MFI,
1199  int Index,
1200  int64_t Offset) {
1201  const SIInstrInfo *TII = ST.getInstrInfo();
1202  MachineBasicBlock *MBB = MI->getParent();
1203  const DebugLoc &DL = MI->getDebugLoc();
1204  bool IsStore = MI->mayStore();
1205 
1206  unsigned Opc = MI->getOpcode();
1207  int LoadStoreOp = IsStore ?
1209  if (LoadStoreOp == -1)
1210  return false;
1211 
1212  const MachineOperand *Reg = TII->getNamedOperand(*MI, AMDGPU::OpName::vdata);
1213  if (spillVGPRtoAGPR(ST, *MBB, MI, Index, 0, Reg->getReg(), false).getInstr())
1214  return true;
1215 
1216  MachineInstrBuilder NewMI =
1217  BuildMI(*MBB, MI, DL, TII->get(LoadStoreOp))
1218  .add(*Reg)
1219  .add(*TII->getNamedOperand(*MI, AMDGPU::OpName::srsrc))
1220  .add(*TII->getNamedOperand(*MI, AMDGPU::OpName::soffset))
1221  .addImm(Offset)
1222  .addImm(0) // cpol
1223  .addImm(0) // swz
1224  .cloneMemRefs(*MI);
1225 
1226  const MachineOperand *VDataIn = TII->getNamedOperand(*MI,
1227  AMDGPU::OpName::vdata_in);
1228  if (VDataIn)
1229  NewMI.add(*VDataIn);
1230  return true;
1231 }
1232 
1234  unsigned LoadStoreOp,
1235  unsigned EltSize) {
1236  bool IsStore = TII->get(LoadStoreOp).mayStore();
1237  bool HasVAddr = AMDGPU::hasNamedOperand(LoadStoreOp, AMDGPU::OpName::vaddr);
1238  bool UseST =
1239  !HasVAddr && !AMDGPU::hasNamedOperand(LoadStoreOp, AMDGPU::OpName::saddr);
1240 
1241  switch (EltSize) {
1242  case 4:
1243  LoadStoreOp = IsStore ? AMDGPU::SCRATCH_STORE_DWORD_SADDR
1244  : AMDGPU::SCRATCH_LOAD_DWORD_SADDR;
1245  break;
1246  case 8:
1247  LoadStoreOp = IsStore ? AMDGPU::SCRATCH_STORE_DWORDX2_SADDR
1248  : AMDGPU::SCRATCH_LOAD_DWORDX2_SADDR;
1249  break;
1250  case 12:
1251  LoadStoreOp = IsStore ? AMDGPU::SCRATCH_STORE_DWORDX3_SADDR
1252  : AMDGPU::SCRATCH_LOAD_DWORDX3_SADDR;
1253  break;
1254  case 16:
1255  LoadStoreOp = IsStore ? AMDGPU::SCRATCH_STORE_DWORDX4_SADDR
1256  : AMDGPU::SCRATCH_LOAD_DWORDX4_SADDR;
1257  break;
1258  default:
1259  llvm_unreachable("Unexpected spill load/store size!");
1260  }
1261 
1262  if (HasVAddr)
1263  LoadStoreOp = AMDGPU::getFlatScratchInstSVfromSS(LoadStoreOp);
1264  else if (UseST)
1265  LoadStoreOp = AMDGPU::getFlatScratchInstSTfromSS(LoadStoreOp);
1266 
1267  return LoadStoreOp;
1268 }
1269 
1272  unsigned LoadStoreOp, int Index, Register ValueReg, bool IsKill,
1273  MCRegister ScratchOffsetReg, int64_t InstOffset, MachineMemOperand *MMO,
1274  RegScavenger *RS, LivePhysRegs *LiveRegs) const {
1275  assert((!RS || !LiveRegs) && "Only RS or LiveRegs can be set but not both");
1276 
1277  MachineFunction *MF = MBB.getParent();
1278  const SIInstrInfo *TII = ST.getInstrInfo();
1279  const MachineFrameInfo &MFI = MF->getFrameInfo();
1280  const SIMachineFunctionInfo *FuncInfo = MF->getInfo<SIMachineFunctionInfo>();
1281 
1282  const MCInstrDesc *Desc = &TII->get(LoadStoreOp);
1283  bool IsStore = Desc->mayStore();
1284  bool IsFlat = TII->isFLATScratch(LoadStoreOp);
1285 
1286  bool CanClobberSCC = false;
1287  bool Scavenged = false;
1288  MCRegister SOffset = ScratchOffsetReg;
1289 
1290  const TargetRegisterClass *RC = getRegClassForReg(MF->getRegInfo(), ValueReg);
1291  // On gfx90a+ AGPR is a regular VGPR acceptable for loads and stores.
1292  const bool IsAGPR = !ST.hasGFX90AInsts() && isAGPRClass(RC);
1293  const unsigned RegWidth = AMDGPU::getRegBitWidth(RC->getID()) / 8;
1294 
1295  // Always use 4 byte operations for AGPRs because we need to scavenge
1296  // a temporary VGPR.
1297  unsigned EltSize = (IsFlat && !IsAGPR) ? std::min(RegWidth, 16u) : 4u;
1298  unsigned NumSubRegs = RegWidth / EltSize;
1299  unsigned Size = NumSubRegs * EltSize;
1300  unsigned RemSize = RegWidth - Size;
1301  unsigned NumRemSubRegs = RemSize ? 1 : 0;
1302  int64_t Offset = InstOffset + MFI.getObjectOffset(Index);
1303  int64_t MaterializedOffset = Offset;
1304 
1305  int64_t MaxOffset = Offset + Size + RemSize - EltSize;
1306  int64_t ScratchOffsetRegDelta = 0;
1307 
1308  if (IsFlat && EltSize > 4) {
1309  LoadStoreOp = getFlatScratchSpillOpcode(TII, LoadStoreOp, EltSize);
1310  Desc = &TII->get(LoadStoreOp);
1311  }
1312 
1313  Align Alignment = MFI.getObjectAlign(Index);
1314  const MachinePointerInfo &BasePtrInfo = MMO->getPointerInfo();
1315 
1316  assert((IsFlat || ((Offset % EltSize) == 0)) &&
1317  "unexpected VGPR spill offset");
1318 
1319  // Track a VGPR to use for a constant offset we need to materialize.
1320  Register TmpOffsetVGPR;
1321 
1322  // Track a VGPR to use as an intermediate value.
1323  Register TmpIntermediateVGPR;
1324  bool UseVGPROffset = false;
1325 
1326  // Materialize a VGPR offset required for the given SGPR/VGPR/Immediate
1327  // combination.
1328  auto MaterializeVOffset = [&](Register SGPRBase, Register TmpVGPR,
1329  int64_t VOffset) {
1330  // We are using a VGPR offset
1331  if (IsFlat && SGPRBase) {
1332  // We only have 1 VGPR offset, or 1 SGPR offset. We don't have a free
1333  // SGPR, so perform the add as vector.
1334  // We don't need a base SGPR in the kernel.
1335 
1336  if (ST.getConstantBusLimit(AMDGPU::V_ADD_U32_e64) >= 2) {
1337  BuildMI(MBB, MI, DL, TII->get(AMDGPU::V_ADD_U32_e64), TmpVGPR)
1338  .addReg(SGPRBase)
1339  .addImm(VOffset)
1340  .addImm(0); // clamp
1341  } else {
1342  BuildMI(MBB, MI, DL, TII->get(AMDGPU::V_MOV_B32_e32), TmpVGPR)
1343  .addReg(SGPRBase);
1344  BuildMI(MBB, MI, DL, TII->get(AMDGPU::V_ADD_U32_e32), TmpVGPR)
1345  .addImm(VOffset)
1346  .addReg(TmpOffsetVGPR);
1347  }
1348  } else {
1349  assert(TmpOffsetVGPR);
1350  BuildMI(MBB, MI, DL, TII->get(AMDGPU::V_MOV_B32_e32), TmpVGPR)
1351  .addImm(VOffset);
1352  }
1353  };
1354 
1355  bool IsOffsetLegal =
1356  IsFlat ? TII->isLegalFLATOffset(MaxOffset, AMDGPUAS::PRIVATE_ADDRESS,
1359  if (!IsOffsetLegal || (IsFlat && !SOffset && !ST.hasFlatScratchSTMode())) {
1360  SOffset = MCRegister();
1361 
1362  // We don't have access to the register scavenger if this function is called
1363  // during PEI::scavengeFrameVirtualRegs() so use LiveRegs in this case.
1364  // TODO: Clobbering SCC is not necessary for scratch instructions in the
1365  // entry.
1366  if (RS) {
1367  SOffset = RS->scavengeRegisterBackwards(AMDGPU::SGPR_32RegClass, MI, false, 0, false);
1368 
1369  // Piggy back on the liveness scan we just did see if SCC is dead.
1370  CanClobberSCC = !RS->isRegUsed(AMDGPU::SCC);
1371  } else if (LiveRegs) {
1372  CanClobberSCC = !LiveRegs->contains(AMDGPU::SCC);
1373  for (MCRegister Reg : AMDGPU::SGPR_32RegClass) {
1374  if (LiveRegs->available(MF->getRegInfo(), Reg)) {
1375  SOffset = Reg;
1376  break;
1377  }
1378  }
1379  }
1380 
1381  if (ScratchOffsetReg != AMDGPU::NoRegister && !CanClobberSCC)
1382  SOffset = Register();
1383 
1384  if (!SOffset) {
1385  UseVGPROffset = true;
1386 
1387  if (RS) {
1388  TmpOffsetVGPR = RS->scavengeRegisterBackwards(AMDGPU::VGPR_32RegClass, MI, false, 0);
1389  } else {
1390  assert(LiveRegs);
1391  for (MCRegister Reg : AMDGPU::VGPR_32RegClass) {
1392  if (LiveRegs->available(MF->getRegInfo(), Reg)) {
1393  TmpOffsetVGPR = Reg;
1394  break;
1395  }
1396  }
1397  }
1398 
1399  assert(TmpOffsetVGPR);
1400  } else if (!SOffset && CanClobberSCC) {
1401  // There are no free SGPRs, and since we are in the process of spilling
1402  // VGPRs too. Since we need a VGPR in order to spill SGPRs (this is true
1403  // on SI/CI and on VI it is true until we implement spilling using scalar
1404  // stores), we have no way to free up an SGPR. Our solution here is to
1405  // add the offset directly to the ScratchOffset or StackPtrOffset
1406  // register, and then subtract the offset after the spill to return the
1407  // register to it's original value.
1408 
1409  // TODO: If we don't have to do an emergency stack slot spill, converting
1410  // to use the VGPR offset is fewer instructions.
1411  if (!ScratchOffsetReg)
1412  ScratchOffsetReg = FuncInfo->getStackPtrOffsetReg();
1413  SOffset = ScratchOffsetReg;
1414  ScratchOffsetRegDelta = Offset;
1415  } else {
1416  Scavenged = true;
1417  }
1418 
1419  // We currently only support spilling VGPRs to EltSize boundaries, meaning
1420  // we can simplify the adjustment of Offset here to just scale with
1421  // WavefrontSize.
1422  if (!IsFlat && !UseVGPROffset)
1423  Offset *= ST.getWavefrontSize();
1424 
1425  if (!UseVGPROffset && !SOffset)
1426  report_fatal_error("could not scavenge SGPR to spill in entry function");
1427 
1428  if (UseVGPROffset) {
1429  // We are using a VGPR offset
1430  MaterializeVOffset(ScratchOffsetReg, TmpOffsetVGPR, Offset);
1431  } else if (ScratchOffsetReg == AMDGPU::NoRegister) {
1432  BuildMI(MBB, MI, DL, TII->get(AMDGPU::S_MOV_B32), SOffset).addImm(Offset);
1433  } else {
1434  assert(Offset != 0);
1435  auto Add = BuildMI(MBB, MI, DL, TII->get(AMDGPU::S_ADD_I32), SOffset)
1436  .addReg(ScratchOffsetReg)
1437  .addImm(Offset);
1438  Add->getOperand(3).setIsDead(); // Mark SCC as dead.
1439  }
1440 
1441  Offset = 0;
1442  }
1443 
1444  if (IsFlat && SOffset == AMDGPU::NoRegister) {
1445  assert(AMDGPU::getNamedOperandIdx(LoadStoreOp, AMDGPU::OpName::vaddr) < 0
1446  && "Unexpected vaddr for flat scratch with a FI operand");
1447 
1448  if (UseVGPROffset) {
1449  LoadStoreOp = AMDGPU::getFlatScratchInstSVfromSS(LoadStoreOp);
1450  } else {
1452  LoadStoreOp = AMDGPU::getFlatScratchInstSTfromSS(LoadStoreOp);
1453  }
1454 
1455  Desc = &TII->get(LoadStoreOp);
1456  }
1457 
1458  for (unsigned i = 0, e = NumSubRegs + NumRemSubRegs, RegOffset = 0; i != e;
1459  ++i, RegOffset += EltSize) {
1460  if (i == NumSubRegs) {
1461  EltSize = RemSize;
1462  LoadStoreOp = getFlatScratchSpillOpcode(TII, LoadStoreOp, EltSize);
1463  }
1464  Desc = &TII->get(LoadStoreOp);
1465 
1466  if (!IsFlat && UseVGPROffset) {
1467  int NewLoadStoreOp = IsStore ? getOffenMUBUFStore(LoadStoreOp)
1468  : getOffenMUBUFLoad(LoadStoreOp);
1469  Desc = &TII->get(NewLoadStoreOp);
1470  }
1471 
1472  if (UseVGPROffset && TmpOffsetVGPR == TmpIntermediateVGPR) {
1473  // If we are spilling an AGPR beyond the range of the memory instruction
1474  // offset and need to use a VGPR offset, we ideally have at least 2
1475  // scratch VGPRs. If we don't have a second free VGPR without spilling,
1476  // recycle the VGPR used for the offset which requires resetting after
1477  // each subregister.
1478 
1479  MaterializeVOffset(ScratchOffsetReg, TmpOffsetVGPR, MaterializedOffset);
1480  }
1481 
1482  unsigned NumRegs = EltSize / 4;
1483  Register SubReg = e == 1
1484  ? ValueReg
1485  : Register(getSubReg(ValueReg,
1486  getSubRegFromChannel(RegOffset / 4, NumRegs)));
1487 
1488  unsigned SOffsetRegState = 0;
1489  unsigned SrcDstRegState = getDefRegState(!IsStore);
1490  const bool IsLastSubReg = i + 1 == e;
1491  if (IsLastSubReg) {
1492  SOffsetRegState |= getKillRegState(Scavenged);
1493  // The last implicit use carries the "Kill" flag.
1494  SrcDstRegState |= getKillRegState(IsKill);
1495  }
1496 
1497  // Make sure the whole register is defined if there are undef components by
1498  // adding an implicit def of the super-reg on the first instruction.
1499  bool NeedSuperRegDef = e > 1 && IsStore && i == 0;
1500  bool NeedSuperRegImpOperand = e > 1;
1501 
1502  // Remaining element size to spill into memory after some parts of it
1503  // spilled into either AGPRs or VGPRs.
1504  unsigned RemEltSize = EltSize;
1505 
1506  // AGPRs to spill VGPRs and vice versa are allocated in a reverse order,
1507  // starting from the last lane. In case if a register cannot be completely
1508  // spilled into another register that will ensure its alignment does not
1509  // change. For targets with VGPR alignment requirement this is important
1510  // in case of flat scratch usage as we might get a scratch_load or
1511  // scratch_store of an unaligned register otherwise.
1512  for (int LaneS = (RegOffset + EltSize) / 4 - 1, Lane = LaneS,
1513  LaneE = RegOffset / 4;
1514  Lane >= LaneE; --Lane) {
1515  bool IsSubReg = e > 1 || EltSize > 4;
1516  Register Sub = IsSubReg
1517  ? Register(getSubReg(ValueReg, getSubRegFromChannel(Lane)))
1518  : ValueReg;
1519  auto MIB = spillVGPRtoAGPR(ST, MBB, MI, Index, Lane, Sub, IsKill);
1520  if (!MIB.getInstr())
1521  break;
1522  if (NeedSuperRegDef || (IsSubReg && IsStore && Lane == LaneS && !i)) {
1523  MIB.addReg(ValueReg, RegState::ImplicitDefine);
1524  NeedSuperRegDef = false;
1525  }
1526  if (IsSubReg || NeedSuperRegImpOperand) {
1527  NeedSuperRegImpOperand = true;
1528  unsigned State = SrcDstRegState;
1529  if (Lane != LaneE)
1530  State &= ~RegState::Kill;
1531  MIB.addReg(ValueReg, RegState::Implicit | State);
1532  }
1533  RemEltSize -= 4;
1534  }
1535 
1536  if (!RemEltSize) // Fully spilled into AGPRs.
1537  continue;
1538 
1539  if (RemEltSize != EltSize) { // Partially spilled to AGPRs
1540  assert(IsFlat && EltSize > 4);
1541 
1542  unsigned NumRegs = RemEltSize / 4;
1543  SubReg = Register(getSubReg(ValueReg,
1544  getSubRegFromChannel(RegOffset / 4, NumRegs)));
1545  unsigned Opc = getFlatScratchSpillOpcode(TII, LoadStoreOp, RemEltSize);
1546  Desc = &TII->get(Opc);
1547  }
1548 
1549  unsigned FinalReg = SubReg;
1550 
1551  if (IsAGPR) {
1552  assert(EltSize == 4);
1553 
1554  if (!TmpIntermediateVGPR) {
1555  TmpIntermediateVGPR = FuncInfo->getVGPRForAGPRCopy();
1556  assert(MF->getRegInfo().isReserved(TmpIntermediateVGPR));
1557  }
1558  if (IsStore) {
1559  auto AccRead = BuildMI(MBB, MI, DL,
1560  TII->get(AMDGPU::V_ACCVGPR_READ_B32_e64),
1561  TmpIntermediateVGPR)
1562  .addReg(SubReg, getKillRegState(IsKill));
1563  if (NeedSuperRegDef)
1564  AccRead.addReg(ValueReg, RegState::ImplicitDefine);
1566  }
1567  SubReg = TmpIntermediateVGPR;
1568  } else if (UseVGPROffset) {
1569  // FIXME: change to scavengeRegisterBackwards()
1570  if (!TmpOffsetVGPR) {
1571  TmpOffsetVGPR = RS->scavengeRegister(&AMDGPU::VGPR_32RegClass, MI, 0);
1572  RS->setRegUsed(TmpOffsetVGPR);
1573  }
1574  }
1575 
1576  MachinePointerInfo PInfo = BasePtrInfo.getWithOffset(RegOffset);
1577  MachineMemOperand *NewMMO =
1578  MF->getMachineMemOperand(PInfo, MMO->getFlags(), RemEltSize,
1579  commonAlignment(Alignment, RegOffset));
1580 
1581  auto MIB =
1582  BuildMI(MBB, MI, DL, *Desc)
1583  .addReg(SubReg, getDefRegState(!IsStore) | getKillRegState(IsKill));
1584 
1585  if (UseVGPROffset) {
1586  // For an AGPR spill, we reuse the same temp VGPR for the offset and the
1587  // intermediate accvgpr_write.
1588  MIB.addReg(TmpOffsetVGPR, getKillRegState(IsLastSubReg && !IsAGPR));
1589  }
1590 
1591  if (!IsFlat)
1592  MIB.addReg(FuncInfo->getScratchRSrcReg());
1593 
1594  if (SOffset == AMDGPU::NoRegister) {
1595  if (!IsFlat) {
1596  if (UseVGPROffset && ScratchOffsetReg) {
1597  MIB.addReg(ScratchOffsetReg);
1598  } else {
1599  assert(FuncInfo->isEntryFunction());
1600  MIB.addImm(0);
1601  }
1602  }
1603  } else {
1604  MIB.addReg(SOffset, SOffsetRegState);
1605  }
1606  MIB.addImm(Offset + RegOffset)
1607  .addImm(0); // cpol
1608  if (!IsFlat)
1609  MIB.addImm(0); // swz
1610  MIB.addMemOperand(NewMMO);
1611 
1612  if (!IsAGPR && NeedSuperRegDef)
1613  MIB.addReg(ValueReg, RegState::ImplicitDefine);
1614 
1615  if (!IsStore && IsAGPR && TmpIntermediateVGPR != AMDGPU::NoRegister) {
1616  MIB = BuildMI(MBB, MI, DL, TII->get(AMDGPU::V_ACCVGPR_WRITE_B32_e64),
1617  FinalReg)
1618  .addReg(TmpIntermediateVGPR, RegState::Kill);
1620  }
1621 
1622  if (NeedSuperRegImpOperand)
1623  MIB.addReg(ValueReg, RegState::Implicit | SrcDstRegState);
1624  }
1625 
1626  if (ScratchOffsetRegDelta != 0) {
1627  // Subtract the offset we added to the ScratchOffset register.
1628  BuildMI(MBB, MI, DL, TII->get(AMDGPU::S_ADD_I32), SOffset)
1629  .addReg(SOffset)
1630  .addImm(-ScratchOffsetRegDelta);
1631  }
1632 }
1633 
1635  int Offset, bool IsLoad,
1636  bool IsKill) const {
1637  // Load/store VGPR
1638  MachineFrameInfo &FrameInfo = SB.MF.getFrameInfo();
1640 
1641  Register FrameReg =
1642  FrameInfo.isFixedObjectIndex(Index) && hasBasePointer(SB.MF)
1643  ? getBaseRegister()
1644  : getFrameRegister(SB.MF);
1645 
1646  Align Alignment = FrameInfo.getObjectAlign(Index);
1650  SB.EltSize, Alignment);
1651 
1652  if (IsLoad) {
1653  unsigned Opc = ST.enableFlatScratch() ? AMDGPU::SCRATCH_LOAD_DWORD_SADDR
1654  : AMDGPU::BUFFER_LOAD_DWORD_OFFSET;
1655  buildSpillLoadStore(*SB.MBB, SB.MI, SB.DL, Opc, Index, SB.TmpVGPR, false,
1656  FrameReg, Offset * SB.EltSize, MMO, SB.RS);
1657  } else {
1658  unsigned Opc = ST.enableFlatScratch() ? AMDGPU::SCRATCH_STORE_DWORD_SADDR
1659  : AMDGPU::BUFFER_STORE_DWORD_OFFSET;
1660  buildSpillLoadStore(*SB.MBB, SB.MI, SB.DL, Opc, Index, SB.TmpVGPR, IsKill,
1661  FrameReg, Offset * SB.EltSize, MMO, SB.RS);
1662  // This only ever adds one VGPR spill
1663  SB.MFI.addToSpilledVGPRs(1);
1664  }
1665 }
1666 
1668  RegScavenger *RS, SlotIndexes *Indexes,
1669  LiveIntervals *LIS, bool OnlyToVGPR) const {
1670  SGPRSpillBuilder SB(*this, *ST.getInstrInfo(), isWave32, MI, Index, RS);
1671 
1673  bool SpillToVGPR = !VGPRSpills.empty();
1674  if (OnlyToVGPR && !SpillToVGPR)
1675  return false;
1676 
1677  assert(SpillToVGPR || (SB.SuperReg != SB.MFI.getStackPtrOffsetReg() &&
1678  SB.SuperReg != SB.MFI.getFrameOffsetReg()));
1679 
1680  if (SpillToVGPR) {
1681 
1682  assert(SB.NumSubRegs == VGPRSpills.size() &&
1683  "Num of VGPR lanes should be equal to num of SGPRs spilled");
1684 
1685  for (unsigned i = 0, e = SB.NumSubRegs; i < e; ++i) {
1686  Register SubReg =
1687  SB.NumSubRegs == 1
1688  ? SB.SuperReg
1689  : Register(getSubReg(SB.SuperReg, SB.SplitParts[i]));
1690  SpilledReg Spill = VGPRSpills[i];
1691 
1692  bool UseKill = SB.IsKill && i == SB.NumSubRegs - 1;
1693 
1694  // Mark the "old value of vgpr" input undef only if this is the first sgpr
1695  // spill to this specific vgpr in the first basic block.
1696  auto MIB = BuildMI(*SB.MBB, MI, SB.DL,
1697  SB.TII.get(AMDGPU::V_WRITELANE_B32), Spill.VGPR)
1698  .addReg(SubReg, getKillRegState(UseKill))
1699  .addImm(Spill.Lane)
1700  .addReg(Spill.VGPR);
1701  if (Indexes) {
1702  if (i == 0)
1703  Indexes->replaceMachineInstrInMaps(*MI, *MIB);
1704  else
1705  Indexes->insertMachineInstrInMaps(*MIB);
1706  }
1707 
1708  if (i == 0 && SB.NumSubRegs > 1) {
1709  // We may be spilling a super-register which is only partially defined,
1710  // and need to ensure later spills think the value is defined.
1711  MIB.addReg(SB.SuperReg, RegState::ImplicitDefine);
1712  }
1713 
1714  if (SB.NumSubRegs > 1)
1715  MIB.addReg(SB.SuperReg, getKillRegState(UseKill) | RegState::Implicit);
1716 
1717  // FIXME: Since this spills to another register instead of an actual
1718  // frame index, we should delete the frame index when all references to
1719  // it are fixed.
1720  }
1721  } else {
1722  SB.prepare();
1723 
1724  // SubReg carries the "Kill" flag when SubReg == SB.SuperReg.
1725  unsigned SubKillState = getKillRegState((SB.NumSubRegs == 1) && SB.IsKill);
1726 
1727  // Per VGPR helper data
1728  auto PVD = SB.getPerVGPRData();
1729 
1730  for (unsigned Offset = 0; Offset < PVD.NumVGPRs; ++Offset) {
1731  unsigned TmpVGPRFlags = RegState::Undef;
1732 
1733  // Write sub registers into the VGPR
1734  for (unsigned i = Offset * PVD.PerVGPR,
1735  e = std::min((Offset + 1) * PVD.PerVGPR, SB.NumSubRegs);
1736  i < e; ++i) {
1737  Register SubReg =
1738  SB.NumSubRegs == 1
1739  ? SB.SuperReg
1740  : Register(getSubReg(SB.SuperReg, SB.SplitParts[i]));
1741 
1742  MachineInstrBuilder WriteLane =
1743  BuildMI(*SB.MBB, MI, SB.DL, SB.TII.get(AMDGPU::V_WRITELANE_B32),
1744  SB.TmpVGPR)
1745  .addReg(SubReg, SubKillState)
1746  .addImm(i % PVD.PerVGPR)
1747  .addReg(SB.TmpVGPR, TmpVGPRFlags);
1748  TmpVGPRFlags = 0;
1749 
1750  if (Indexes) {
1751  if (i == 0)
1752  Indexes->replaceMachineInstrInMaps(*MI, *WriteLane);
1753  else
1754  Indexes->insertMachineInstrInMaps(*WriteLane);
1755  }
1756 
1757  // There could be undef components of a spilled super register.
1758  // TODO: Can we detect this and skip the spill?
1759  if (SB.NumSubRegs > 1) {
1760  // The last implicit use of the SB.SuperReg carries the "Kill" flag.
1761  unsigned SuperKillState = 0;
1762  if (i + 1 == SB.NumSubRegs)
1763  SuperKillState |= getKillRegState(SB.IsKill);
1764  WriteLane.addReg(SB.SuperReg, RegState::Implicit | SuperKillState);
1765  }
1766  }
1767 
1768  // Write out VGPR
1769  SB.readWriteTmpVGPR(Offset, /*IsLoad*/ false);
1770  }
1771 
1772  SB.restore();
1773  }
1774 
1775  MI->eraseFromParent();
1777 
1778  if (LIS)
1780 
1781  return true;
1782 }
1783 
1785  RegScavenger *RS, SlotIndexes *Indexes,
1786  LiveIntervals *LIS, bool OnlyToVGPR) const {
1787  SGPRSpillBuilder SB(*this, *ST.getInstrInfo(), isWave32, MI, Index, RS);
1788 
1790  bool SpillToVGPR = !VGPRSpills.empty();
1791  if (OnlyToVGPR && !SpillToVGPR)
1792  return false;
1793 
1794  if (SpillToVGPR) {
1795  for (unsigned i = 0, e = SB.NumSubRegs; i < e; ++i) {
1796  Register SubReg =
1797  SB.NumSubRegs == 1
1798  ? SB.SuperReg
1799  : Register(getSubReg(SB.SuperReg, SB.SplitParts[i]));
1800 
1801  SpilledReg Spill = VGPRSpills[i];
1802  auto MIB = BuildMI(*SB.MBB, MI, SB.DL, SB.TII.get(AMDGPU::V_READLANE_B32),
1803  SubReg)
1804  .addReg(Spill.VGPR)
1805  .addImm(Spill.Lane);
1806  if (SB.NumSubRegs > 1 && i == 0)
1808  if (Indexes) {
1809  if (i == e - 1)
1810  Indexes->replaceMachineInstrInMaps(*MI, *MIB);
1811  else
1812  Indexes->insertMachineInstrInMaps(*MIB);
1813  }
1814  }
1815  } else {
1816  SB.prepare();
1817 
1818  // Per VGPR helper data
1819  auto PVD = SB.getPerVGPRData();
1820 
1821  for (unsigned Offset = 0; Offset < PVD.NumVGPRs; ++Offset) {
1822  // Load in VGPR data
1823  SB.readWriteTmpVGPR(Offset, /*IsLoad*/ true);
1824 
1825  // Unpack lanes
1826  for (unsigned i = Offset * PVD.PerVGPR,
1827  e = std::min((Offset + 1) * PVD.PerVGPR, SB.NumSubRegs);
1828  i < e; ++i) {
1829  Register SubReg =
1830  SB.NumSubRegs == 1
1831  ? SB.SuperReg
1832  : Register(getSubReg(SB.SuperReg, SB.SplitParts[i]));
1833 
1834  bool LastSubReg = (i + 1 == e);
1835  auto MIB = BuildMI(*SB.MBB, MI, SB.DL,
1836  SB.TII.get(AMDGPU::V_READLANE_B32), SubReg)
1837  .addReg(SB.TmpVGPR, getKillRegState(LastSubReg))
1838  .addImm(i);
1839  if (SB.NumSubRegs > 1 && i == 0)
1841  if (Indexes) {
1842  if (i == e - 1)
1843  Indexes->replaceMachineInstrInMaps(*MI, *MIB);
1844  else
1845  Indexes->insertMachineInstrInMaps(*MIB);
1846  }
1847  }
1848  }
1849 
1850  SB.restore();
1851  }
1852 
1853  MI->eraseFromParent();
1854 
1855  if (LIS)
1857 
1858  return true;
1859 }
1860 
1862  MachineBasicBlock &RestoreMBB,
1863  Register SGPR, RegScavenger *RS) const {
1864  SGPRSpillBuilder SB(*this, *ST.getInstrInfo(), isWave32, MI, SGPR, false, 0,
1865  RS);
1866  SB.prepare();
1867  // Generate the spill of SGPR to SB.TmpVGPR.
1868  unsigned SubKillState = getKillRegState((SB.NumSubRegs == 1) && SB.IsKill);
1869  auto PVD = SB.getPerVGPRData();
1870  for (unsigned Offset = 0; Offset < PVD.NumVGPRs; ++Offset) {
1871  unsigned TmpVGPRFlags = RegState::Undef;
1872  // Write sub registers into the VGPR
1873  for (unsigned i = Offset * PVD.PerVGPR,
1874  e = std::min((Offset + 1) * PVD.PerVGPR, SB.NumSubRegs);
1875  i < e; ++i) {
1876  Register SubReg =
1877  SB.NumSubRegs == 1
1878  ? SB.SuperReg
1879  : Register(getSubReg(SB.SuperReg, SB.SplitParts[i]));
1880 
1881  MachineInstrBuilder WriteLane =
1882  BuildMI(*SB.MBB, MI, SB.DL, SB.TII.get(AMDGPU::V_WRITELANE_B32),
1883  SB.TmpVGPR)
1884  .addReg(SubReg, SubKillState)
1885  .addImm(i % PVD.PerVGPR)
1886  .addReg(SB.TmpVGPR, TmpVGPRFlags);
1887  TmpVGPRFlags = 0;
1888  // There could be undef components of a spilled super register.
1889  // TODO: Can we detect this and skip the spill?
1890  if (SB.NumSubRegs > 1) {
1891  // The last implicit use of the SB.SuperReg carries the "Kill" flag.
1892  unsigned SuperKillState = 0;
1893  if (i + 1 == SB.NumSubRegs)
1894  SuperKillState |= getKillRegState(SB.IsKill);
1895  WriteLane.addReg(SB.SuperReg, RegState::Implicit | SuperKillState);
1896  }
1897  }
1898  // Don't need to write VGPR out.
1899  }
1900 
1901  // Restore clobbered registers in the specified restore block.
1902  MI = RestoreMBB.end();
1903  SB.setMI(&RestoreMBB, MI);
1904  // Generate the restore of SGPR from SB.TmpVGPR.
1905  for (unsigned Offset = 0; Offset < PVD.NumVGPRs; ++Offset) {
1906  // Don't need to load VGPR in.
1907  // Unpack lanes
1908  for (unsigned i = Offset * PVD.PerVGPR,
1909  e = std::min((Offset + 1) * PVD.PerVGPR, SB.NumSubRegs);
1910  i < e; ++i) {
1911  Register SubReg =
1912  SB.NumSubRegs == 1
1913  ? SB.SuperReg
1914  : Register(getSubReg(SB.SuperReg, SB.SplitParts[i]));
1915  bool LastSubReg = (i + 1 == e);
1916  auto MIB = BuildMI(*SB.MBB, MI, SB.DL, SB.TII.get(AMDGPU::V_READLANE_B32),
1917  SubReg)
1918  .addReg(SB.TmpVGPR, getKillRegState(LastSubReg))
1919  .addImm(i);
1920  if (SB.NumSubRegs > 1 && i == 0)
1922  }
1923  }
1924  SB.restore();
1925 
1927  return false;
1928 }
1929 
1930 /// Special case of eliminateFrameIndex. Returns true if the SGPR was spilled to
1931 /// a VGPR and the stack slot can be safely eliminated when all other users are
1932 /// handled.
1935  SlotIndexes *Indexes, LiveIntervals *LIS) const {
1936  switch (MI->getOpcode()) {
1937  case AMDGPU::SI_SPILL_S1024_SAVE:
1938  case AMDGPU::SI_SPILL_S512_SAVE:
1939  case AMDGPU::SI_SPILL_S256_SAVE:
1940  case AMDGPU::SI_SPILL_S224_SAVE:
1941  case AMDGPU::SI_SPILL_S192_SAVE:
1942  case AMDGPU::SI_SPILL_S160_SAVE:
1943  case AMDGPU::SI_SPILL_S128_SAVE:
1944  case AMDGPU::SI_SPILL_S96_SAVE:
1945  case AMDGPU::SI_SPILL_S64_SAVE:
1946  case AMDGPU::SI_SPILL_S32_SAVE:
1947  return spillSGPR(MI, FI, RS, Indexes, LIS, true);
1948  case AMDGPU::SI_SPILL_S1024_RESTORE:
1949  case AMDGPU::SI_SPILL_S512_RESTORE:
1950  case AMDGPU::SI_SPILL_S256_RESTORE:
1951  case AMDGPU::SI_SPILL_S224_RESTORE:
1952  case AMDGPU::SI_SPILL_S192_RESTORE:
1953  case AMDGPU::SI_SPILL_S160_RESTORE:
1954  case AMDGPU::SI_SPILL_S128_RESTORE:
1955  case AMDGPU::SI_SPILL_S96_RESTORE:
1956  case AMDGPU::SI_SPILL_S64_RESTORE:
1957  case AMDGPU::SI_SPILL_S32_RESTORE:
1958  return restoreSGPR(MI, FI, RS, Indexes, LIS, true);
1959  default:
1960  llvm_unreachable("not an SGPR spill instruction");
1961  }
1962 }
1963 
1965  int SPAdj, unsigned FIOperandNum,
1966  RegScavenger *RS) const {
1967  MachineFunction *MF = MI->getParent()->getParent();
1968  MachineBasicBlock *MBB = MI->getParent();
1970  MachineFrameInfo &FrameInfo = MF->getFrameInfo();
1971  const SIInstrInfo *TII = ST.getInstrInfo();
1972  DebugLoc DL = MI->getDebugLoc();
1973 
1974  assert(SPAdj == 0 && "unhandled SP adjustment in call sequence?");
1975 
1976  MachineOperand &FIOp = MI->getOperand(FIOperandNum);
1977  int Index = MI->getOperand(FIOperandNum).getIndex();
1978 
1979  Register FrameReg = FrameInfo.isFixedObjectIndex(Index) && hasBasePointer(*MF)
1980  ? getBaseRegister()
1981  : getFrameRegister(*MF);
1982 
1983  switch (MI->getOpcode()) {
1984  // SGPR register spill
1985  case AMDGPU::SI_SPILL_S1024_SAVE:
1986  case AMDGPU::SI_SPILL_S512_SAVE:
1987  case AMDGPU::SI_SPILL_S256_SAVE:
1988  case AMDGPU::SI_SPILL_S224_SAVE:
1989  case AMDGPU::SI_SPILL_S192_SAVE:
1990  case AMDGPU::SI_SPILL_S160_SAVE:
1991  case AMDGPU::SI_SPILL_S128_SAVE:
1992  case AMDGPU::SI_SPILL_S96_SAVE:
1993  case AMDGPU::SI_SPILL_S64_SAVE:
1994  case AMDGPU::SI_SPILL_S32_SAVE: {
1995  return spillSGPR(MI, Index, RS);
1996  }
1997 
1998  // SGPR register restore
1999  case AMDGPU::SI_SPILL_S1024_RESTORE:
2000  case AMDGPU::SI_SPILL_S512_RESTORE:
2001  case AMDGPU::SI_SPILL_S256_RESTORE:
2002  case AMDGPU::SI_SPILL_S224_RESTORE:
2003  case AMDGPU::SI_SPILL_S192_RESTORE:
2004  case AMDGPU::SI_SPILL_S160_RESTORE:
2005  case AMDGPU::SI_SPILL_S128_RESTORE:
2006  case AMDGPU::SI_SPILL_S96_RESTORE:
2007  case AMDGPU::SI_SPILL_S64_RESTORE:
2008  case AMDGPU::SI_SPILL_S32_RESTORE: {
2009  return restoreSGPR(MI, Index, RS);
2010  }
2011 
2012  // VGPR register spill
2013  case AMDGPU::SI_SPILL_V1024_SAVE:
2014  case AMDGPU::SI_SPILL_V512_SAVE:
2015  case AMDGPU::SI_SPILL_V256_SAVE:
2016  case AMDGPU::SI_SPILL_V224_SAVE:
2017  case AMDGPU::SI_SPILL_V192_SAVE:
2018  case AMDGPU::SI_SPILL_V160_SAVE:
2019  case AMDGPU::SI_SPILL_V128_SAVE:
2020  case AMDGPU::SI_SPILL_V96_SAVE:
2021  case AMDGPU::SI_SPILL_V64_SAVE:
2022  case AMDGPU::SI_SPILL_V32_SAVE:
2023  case AMDGPU::SI_SPILL_A1024_SAVE:
2024  case AMDGPU::SI_SPILL_A512_SAVE:
2025  case AMDGPU::SI_SPILL_A256_SAVE:
2026  case AMDGPU::SI_SPILL_A224_SAVE:
2027  case AMDGPU::SI_SPILL_A192_SAVE:
2028  case AMDGPU::SI_SPILL_A160_SAVE:
2029  case AMDGPU::SI_SPILL_A128_SAVE:
2030  case AMDGPU::SI_SPILL_A96_SAVE:
2031  case AMDGPU::SI_SPILL_A64_SAVE:
2032  case AMDGPU::SI_SPILL_A32_SAVE:
2033  case AMDGPU::SI_SPILL_AV1024_SAVE:
2034  case AMDGPU::SI_SPILL_AV512_SAVE:
2035  case AMDGPU::SI_SPILL_AV256_SAVE:
2036  case AMDGPU::SI_SPILL_AV224_SAVE:
2037  case AMDGPU::SI_SPILL_AV192_SAVE:
2038  case AMDGPU::SI_SPILL_AV160_SAVE:
2039  case AMDGPU::SI_SPILL_AV128_SAVE:
2040  case AMDGPU::SI_SPILL_AV96_SAVE:
2041  case AMDGPU::SI_SPILL_AV64_SAVE:
2042  case AMDGPU::SI_SPILL_AV32_SAVE: {
2043  const MachineOperand *VData = TII->getNamedOperand(*MI,
2044  AMDGPU::OpName::vdata);
2045  assert(TII->getNamedOperand(*MI, AMDGPU::OpName::soffset)->getReg() ==
2046  MFI->getStackPtrOffsetReg());
2047 
2048  unsigned Opc = ST.enableFlatScratch() ? AMDGPU::SCRATCH_STORE_DWORD_SADDR
2049  : AMDGPU::BUFFER_STORE_DWORD_OFFSET;
2050  auto *MBB = MI->getParent();
2052  *MBB, MI, DL, Opc, Index, VData->getReg(), VData->isKill(), FrameReg,
2053  TII->getNamedOperand(*MI, AMDGPU::OpName::offset)->getImm(),
2054  *MI->memoperands_begin(), RS);
2055  MFI->addToSpilledVGPRs(getNumSubRegsForSpillOp(MI->getOpcode()));
2056  MI->eraseFromParent();
2057  return true;
2058  }
2059  case AMDGPU::SI_SPILL_V32_RESTORE:
2060  case AMDGPU::SI_SPILL_V64_RESTORE:
2061  case AMDGPU::SI_SPILL_V96_RESTORE:
2062  case AMDGPU::SI_SPILL_V128_RESTORE:
2063  case AMDGPU::SI_SPILL_V160_RESTORE:
2064  case AMDGPU::SI_SPILL_V192_RESTORE:
2065  case AMDGPU::SI_SPILL_V224_RESTORE:
2066  case AMDGPU::SI_SPILL_V256_RESTORE:
2067  case AMDGPU::SI_SPILL_V512_RESTORE:
2068  case AMDGPU::SI_SPILL_V1024_RESTORE:
2069  case AMDGPU::SI_SPILL_A32_RESTORE:
2070  case AMDGPU::SI_SPILL_A64_RESTORE:
2071  case AMDGPU::SI_SPILL_A96_RESTORE:
2072  case AMDGPU::SI_SPILL_A128_RESTORE:
2073  case AMDGPU::SI_SPILL_A160_RESTORE:
2074  case AMDGPU::SI_SPILL_A192_RESTORE:
2075  case AMDGPU::SI_SPILL_A224_RESTORE:
2076  case AMDGPU::SI_SPILL_A256_RESTORE:
2077  case AMDGPU::SI_SPILL_A512_RESTORE:
2078  case AMDGPU::SI_SPILL_A1024_RESTORE:
2079  case AMDGPU::SI_SPILL_AV32_RESTORE:
2080  case AMDGPU::SI_SPILL_AV64_RESTORE:
2081  case AMDGPU::SI_SPILL_AV96_RESTORE:
2082  case AMDGPU::SI_SPILL_AV128_RESTORE:
2083  case AMDGPU::SI_SPILL_AV160_RESTORE:
2084  case AMDGPU::SI_SPILL_AV192_RESTORE:
2085  case AMDGPU::SI_SPILL_AV224_RESTORE:
2086  case AMDGPU::SI_SPILL_AV256_RESTORE:
2087  case AMDGPU::SI_SPILL_AV512_RESTORE:
2088  case AMDGPU::SI_SPILL_AV1024_RESTORE: {
2089  const MachineOperand *VData = TII->getNamedOperand(*MI,
2090  AMDGPU::OpName::vdata);
2091  assert(TII->getNamedOperand(*MI, AMDGPU::OpName::soffset)->getReg() ==
2092  MFI->getStackPtrOffsetReg());
2093 
2094  unsigned Opc = ST.enableFlatScratch() ? AMDGPU::SCRATCH_LOAD_DWORD_SADDR
2095  : AMDGPU::BUFFER_LOAD_DWORD_OFFSET;
2096  auto *MBB = MI->getParent();
2098  *MBB, MI, DL, Opc, Index, VData->getReg(), VData->isKill(), FrameReg,
2099  TII->getNamedOperand(*MI, AMDGPU::OpName::offset)->getImm(),
2100  *MI->memoperands_begin(), RS);
2101  MI->eraseFromParent();
2102  return true;
2103  }
2104 
2105  default: {
2106  // Other access to frame index
2107  const DebugLoc &DL = MI->getDebugLoc();
2108 
2109  int64_t Offset = FrameInfo.getObjectOffset(Index);
2110  if (ST.enableFlatScratch()) {
2111  if (TII->isFLATScratch(*MI)) {
2112  assert((int16_t)FIOperandNum ==
2113  AMDGPU::getNamedOperandIdx(MI->getOpcode(),
2114  AMDGPU::OpName::saddr));
2115 
2116  // The offset is always swizzled, just replace it
2117  if (FrameReg)
2118  FIOp.ChangeToRegister(FrameReg, false);
2119 
2120  if (!Offset)
2121  return false;
2122 
2123  MachineOperand *OffsetOp =
2124  TII->getNamedOperand(*MI, AMDGPU::OpName::offset);
2125  int64_t NewOffset = Offset + OffsetOp->getImm();
2126  if (TII->isLegalFLATOffset(NewOffset, AMDGPUAS::PRIVATE_ADDRESS,
2128  OffsetOp->setImm(NewOffset);
2129  if (FrameReg)
2130  return false;
2131  Offset = 0;
2132  }
2133 
2134  if (!Offset) {
2135  unsigned Opc = MI->getOpcode();
2136  int NewOpc = -1;
2137  if (AMDGPU::hasNamedOperand(Opc, AMDGPU::OpName::vaddr)) {
2139  } else if (ST.hasFlatScratchSTMode()) {
2140  // On GFX10 we have ST mode to use no registers for an address.
2141  // Otherwise we need to materialize 0 into an SGPR.
2142  NewOpc = AMDGPU::getFlatScratchInstSTfromSS(Opc);
2143  }
2144 
2145  if (NewOpc != -1) {
2146  // removeOperand doesn't fixup tied operand indexes as it goes, so
2147  // it asserts. Untie vdst_in for now and retie them afterwards.
2148  int VDstIn = AMDGPU::getNamedOperandIdx(Opc,
2149  AMDGPU::OpName::vdst_in);
2150  bool TiedVDst = VDstIn != -1 &&
2151  MI->getOperand(VDstIn).isReg() &&
2152  MI->getOperand(VDstIn).isTied();
2153  if (TiedVDst)
2154  MI->untieRegOperand(VDstIn);
2155 
2156  MI->removeOperand(
2157  AMDGPU::getNamedOperandIdx(Opc, AMDGPU::OpName::saddr));
2158 
2159  if (TiedVDst) {
2160  int NewVDst =
2161  AMDGPU::getNamedOperandIdx(NewOpc, AMDGPU::OpName::vdst);
2162  int NewVDstIn =
2163  AMDGPU::getNamedOperandIdx(NewOpc, AMDGPU::OpName::vdst_in);
2164  assert (NewVDst != -1 && NewVDstIn != -1 && "Must be tied!");
2165  MI->tieOperands(NewVDst, NewVDstIn);
2166  }
2167  MI->setDesc(TII->get(NewOpc));
2168  return false;
2169  }
2170  }
2171  }
2172 
2173  if (!FrameReg) {
2174  FIOp.ChangeToImmediate(Offset);
2175  if (TII->isImmOperandLegal(*MI, FIOperandNum, FIOp))
2176  return false;
2177  }
2178 
2179  // We need to use register here. Check if we can use an SGPR or need
2180  // a VGPR.
2181  FIOp.ChangeToRegister(AMDGPU::M0, false);
2182  bool UseSGPR = TII->isOperandLegal(*MI, FIOperandNum, &FIOp);
2183 
2184  if (!Offset && FrameReg && UseSGPR) {
2185  FIOp.setReg(FrameReg);
2186  return false;
2187  }
2188 
2189  const TargetRegisterClass *RC = UseSGPR ? &AMDGPU::SReg_32_XM0RegClass
2190  : &AMDGPU::VGPR_32RegClass;
2191 
2192  Register TmpReg = RS->scavengeRegister(RC, MI, 0, !UseSGPR);
2193  FIOp.setReg(TmpReg);
2194  FIOp.setIsKill();
2195 
2196  if ((!FrameReg || !Offset) && TmpReg) {
2197  unsigned Opc = UseSGPR ? AMDGPU::S_MOV_B32 : AMDGPU::V_MOV_B32_e32;
2198  auto MIB = BuildMI(*MBB, MI, DL, TII->get(Opc), TmpReg);
2199  if (FrameReg)
2200  MIB.addReg(FrameReg);
2201  else
2202  MIB.addImm(Offset);
2203 
2204  return false;
2205  }
2206 
2207  bool NeedSaveSCC =
2208  RS->isRegUsed(AMDGPU::SCC) && !MI->definesRegister(AMDGPU::SCC);
2209 
2210  Register TmpSReg =
2211  UseSGPR ? TmpReg
2212  : RS->scavengeRegister(&AMDGPU::SReg_32_XM0RegClass, MI, 0,
2213  !UseSGPR);
2214 
2215  // TODO: for flat scratch another attempt can be made with a VGPR index
2216  // if no SGPRs can be scavenged.
2217  if ((!TmpSReg && !FrameReg) || (!TmpReg && !UseSGPR))
2218  report_fatal_error("Cannot scavenge register in FI elimination!");
2219 
2220  if (!TmpSReg) {
2221  // Use frame register and restore it after.
2222  TmpSReg = FrameReg;
2223  FIOp.setReg(FrameReg);
2224  FIOp.setIsKill(false);
2225  }
2226 
2227  if (NeedSaveSCC) {
2228  assert(!(Offset & 0x1) && "Flat scratch offset must be aligned!");
2229  BuildMI(*MBB, MI, DL, TII->get(AMDGPU::S_ADDC_U32), TmpSReg)
2230  .addReg(FrameReg)
2231  .addImm(Offset);
2232  BuildMI(*MBB, MI, DL, TII->get(AMDGPU::S_BITCMP1_B32))
2233  .addReg(TmpSReg)
2234  .addImm(0);
2235  BuildMI(*MBB, MI, DL, TII->get(AMDGPU::S_BITSET0_B32), TmpSReg)
2236  .addImm(0)
2237  .addReg(TmpSReg);
2238  } else {
2239  BuildMI(*MBB, MI, DL, TII->get(AMDGPU::S_ADD_I32), TmpSReg)
2240  .addReg(FrameReg)
2241  .addImm(Offset);
2242  }
2243 
2244  if (!UseSGPR)
2245  BuildMI(*MBB, MI, DL, TII->get(AMDGPU::V_MOV_B32_e32), TmpReg)
2246  .addReg(TmpSReg, RegState::Kill);
2247 
2248  if (TmpSReg == FrameReg) {
2249  // Undo frame register modification.
2250  if (NeedSaveSCC && !MI->registerDefIsDead(AMDGPU::SCC)) {
2252  BuildMI(*MBB, std::next(MI), DL, TII->get(AMDGPU::S_ADDC_U32),
2253  TmpSReg)
2254  .addReg(FrameReg)
2255  .addImm(-Offset);
2256  I = BuildMI(*MBB, std::next(I), DL, TII->get(AMDGPU::S_BITCMP1_B32))
2257  .addReg(TmpSReg)
2258  .addImm(0);
2259  BuildMI(*MBB, std::next(I), DL, TII->get(AMDGPU::S_BITSET0_B32),
2260  TmpSReg)
2261  .addImm(0)
2262  .addReg(TmpSReg);
2263  } else {
2264  BuildMI(*MBB, std::next(MI), DL, TII->get(AMDGPU::S_ADD_I32),
2265  FrameReg)
2266  .addReg(FrameReg)
2267  .addImm(-Offset);
2268  }
2269  }
2270 
2271  return false;
2272  }
2273 
2274  bool IsMUBUF = TII->isMUBUF(*MI);
2275 
2276  if (!IsMUBUF && !MFI->isEntryFunction()) {
2277  // Convert to a swizzled stack address by scaling by the wave size.
2278  // In an entry function/kernel the offset is already swizzled.
2279  bool IsSALU = isSGPRClass(TII->getOpRegClass(*MI, FIOperandNum));
2280  bool LiveSCC =
2281  RS->isRegUsed(AMDGPU::SCC) && !MI->definesRegister(AMDGPU::SCC);
2282  const TargetRegisterClass *RC = IsSALU && !LiveSCC
2283  ? &AMDGPU::SReg_32RegClass
2284  : &AMDGPU::VGPR_32RegClass;
2285  bool IsCopy = MI->getOpcode() == AMDGPU::V_MOV_B32_e32 ||
2286  MI->getOpcode() == AMDGPU::V_MOV_B32_e64;
2287  Register ResultReg = IsCopy ? MI->getOperand(0).getReg()
2288  : RS->scavengeRegister(RC, MI, 0);
2289 
2290  int64_t Offset = FrameInfo.getObjectOffset(Index);
2291  if (Offset == 0) {
2292  unsigned OpCode = IsSALU && !LiveSCC ? AMDGPU::S_LSHR_B32
2293  : AMDGPU::V_LSHRREV_B32_e64;
2294  // XXX - This never happens because of emergency scavenging slot at 0?
2295  auto Shift = BuildMI(*MBB, MI, DL, TII->get(OpCode), ResultReg)
2297  .addReg(FrameReg);
2298  if (IsSALU && !LiveSCC)
2299  Shift.getInstr()->getOperand(3).setIsDead(); // Mark SCC as dead.
2300  if (IsSALU && LiveSCC) {
2301  Register NewDest =
2302  RS->scavengeRegister(&AMDGPU::SReg_32RegClass, Shift, 0);
2303  BuildMI(*MBB, MI, DL, TII->get(AMDGPU::V_READFIRSTLANE_B32),
2304  NewDest)
2305  .addReg(ResultReg);
2306  ResultReg = NewDest;
2307  }
2308  } else {
2309  MachineInstrBuilder MIB;
2310  if (!IsSALU) {
2311  if ((MIB = TII->getAddNoCarry(*MBB, MI, DL, ResultReg, *RS)) !=
2312  nullptr) {
2313  // Reuse ResultReg in intermediate step.
2314  Register ScaledReg = ResultReg;
2315 
2316  BuildMI(*MBB, *MIB, DL, TII->get(AMDGPU::V_LSHRREV_B32_e64),
2317  ScaledReg)
2319  .addReg(FrameReg);
2320 
2321  const bool IsVOP2 = MIB->getOpcode() == AMDGPU::V_ADD_U32_e32;
2322 
2323  // TODO: Fold if use instruction is another add of a constant.
2324  if (IsVOP2 || AMDGPU::isInlinableLiteral32(Offset, ST.hasInv2PiInlineImm())) {
2325  // FIXME: This can fail
2326  MIB.addImm(Offset);
2327  MIB.addReg(ScaledReg, RegState::Kill);
2328  if (!IsVOP2)
2329  MIB.addImm(0); // clamp bit
2330  } else {
2331  assert(MIB->getOpcode() == AMDGPU::V_ADD_CO_U32_e64 &&
2332  "Need to reuse carry out register");
2333 
2334  // Use scavenged unused carry out as offset register.
2335  Register ConstOffsetReg;
2336  if (!isWave32)
2337  ConstOffsetReg = getSubReg(MIB.getReg(1), AMDGPU::sub0);
2338  else
2339  ConstOffsetReg = MIB.getReg(1);
2340 
2341  BuildMI(*MBB, *MIB, DL, TII->get(AMDGPU::S_MOV_B32), ConstOffsetReg)
2342  .addImm(Offset);
2343  MIB.addReg(ConstOffsetReg, RegState::Kill);
2344  MIB.addReg(ScaledReg, RegState::Kill);
2345  MIB.addImm(0); // clamp bit
2346  }
2347  }
2348  }
2349  if (!MIB || IsSALU) {
2350  // We have to produce a carry out, and there isn't a free SGPR pair
2351  // for it. We can keep the whole computation on the SALU to avoid
2352  // clobbering an additional register at the cost of an extra mov.
2353 
2354  // We may have 1 free scratch SGPR even though a carry out is
2355  // unavailable. Only one additional mov is needed.
2356  Register TmpScaledReg =
2357  RS->scavengeRegister(&AMDGPU::SReg_32_XM0RegClass, MI, 0, false);
2358  Register ScaledReg = TmpScaledReg.isValid() ? TmpScaledReg : FrameReg;
2359 
2360  BuildMI(*MBB, MI, DL, TII->get(AMDGPU::S_LSHR_B32), ScaledReg)
2361  .addReg(FrameReg)
2363  BuildMI(*MBB, MI, DL, TII->get(AMDGPU::S_ADD_I32), ScaledReg)
2364  .addReg(ScaledReg, RegState::Kill)
2365  .addImm(Offset);
2366  if (!IsSALU)
2367  BuildMI(*MBB, MI, DL, TII->get(AMDGPU::COPY), ResultReg)
2368  .addReg(ScaledReg, RegState::Kill);
2369  else
2370  ResultReg = ScaledReg;
2371 
2372  // If there were truly no free SGPRs, we need to undo everything.
2373  if (!TmpScaledReg.isValid()) {
2374  BuildMI(*MBB, MI, DL, TII->get(AMDGPU::S_ADD_I32), ScaledReg)
2375  .addReg(ScaledReg, RegState::Kill)
2376  .addImm(-Offset);
2377  BuildMI(*MBB, MI, DL, TII->get(AMDGPU::S_LSHL_B32), ScaledReg)
2378  .addReg(FrameReg)
2380  }
2381  }
2382  }
2383 
2384  // Don't introduce an extra copy if we're just materializing in a mov.
2385  if (IsCopy) {
2386  MI->eraseFromParent();
2387  return true;
2388  }
2389  FIOp.ChangeToRegister(ResultReg, false, false, true);
2390  return false;
2391  }
2392 
2393  if (IsMUBUF) {
2394  // Disable offen so we don't need a 0 vgpr base.
2395  assert(static_cast<int>(FIOperandNum) ==
2396  AMDGPU::getNamedOperandIdx(MI->getOpcode(),
2397  AMDGPU::OpName::vaddr));
2398 
2399  auto &SOffset = *TII->getNamedOperand(*MI, AMDGPU::OpName::soffset);
2400  assert((SOffset.isImm() && SOffset.getImm() == 0));
2401 
2402  if (FrameReg != AMDGPU::NoRegister)
2403  SOffset.ChangeToRegister(FrameReg, false);
2404 
2405  int64_t Offset = FrameInfo.getObjectOffset(Index);
2406  int64_t OldImm
2407  = TII->getNamedOperand(*MI, AMDGPU::OpName::offset)->getImm();
2408  int64_t NewOffset = OldImm + Offset;
2409 
2410  if (SIInstrInfo::isLegalMUBUFImmOffset(NewOffset) &&
2411  buildMUBUFOffsetLoadStore(ST, FrameInfo, MI, Index, NewOffset)) {
2412  MI->eraseFromParent();
2413  return true;
2414  }
2415  }
2416 
2417  // If the offset is simply too big, don't convert to a scratch wave offset
2418  // relative index.
2419 
2420  FIOp.ChangeToImmediate(Offset);
2421  if (!TII->isImmOperandLegal(*MI, FIOperandNum, FIOp)) {
2422  Register TmpReg = RS->scavengeRegister(&AMDGPU::VGPR_32RegClass, MI, 0);
2423  BuildMI(*MBB, MI, DL, TII->get(AMDGPU::V_MOV_B32_e32), TmpReg)
2424  .addImm(Offset);
2425  FIOp.ChangeToRegister(TmpReg, false, false, true);
2426  }
2427  }
2428  }
2429  return false;
2430 }
2431 
2434 }
2435 
2436 static const TargetRegisterClass *
2438  if (BitWidth <= 64)
2439  return &AMDGPU::VReg_64RegClass;
2440  if (BitWidth <= 96)
2441  return &AMDGPU::VReg_96RegClass;
2442  if (BitWidth <= 128)
2443  return &AMDGPU::VReg_128RegClass;
2444  if (BitWidth <= 160)
2445  return &AMDGPU::VReg_160RegClass;
2446  if (BitWidth <= 192)
2447  return &AMDGPU::VReg_192RegClass;
2448  if (BitWidth <= 224)
2449  return &AMDGPU::VReg_224RegClass;
2450  if (BitWidth <= 256)
2451  return &AMDGPU::VReg_256RegClass;
2452  if (BitWidth <= 512)
2453  return &AMDGPU::VReg_512RegClass;
2454  if (BitWidth <= 1024)
2455  return &AMDGPU::VReg_1024RegClass;
2456 
2457  return nullptr;
2458 }
2459 
2460 static const TargetRegisterClass *
2462  if (BitWidth <= 64)
2463  return &AMDGPU::VReg_64_Align2RegClass;
2464  if (BitWidth <= 96)
2465  return &AMDGPU::VReg_96_Align2RegClass;
2466  if (BitWidth <= 128)
2467  return &AMDGPU::VReg_128_Align2RegClass;
2468  if (BitWidth <= 160)
2469  return &AMDGPU::VReg_160_Align2RegClass;
2470  if (BitWidth <= 192)
2471  return &AMDGPU::VReg_192_Align2RegClass;
2472  if (BitWidth <= 224)
2473  return &AMDGPU::VReg_224_Align2RegClass;
2474  if (BitWidth <= 256)
2475  return &AMDGPU::VReg_256_Align2RegClass;
2476  if (BitWidth <= 512)
2477  return &AMDGPU::VReg_512_Align2RegClass;
2478  if (BitWidth <= 1024)
2479  return &AMDGPU::VReg_1024_Align2RegClass;
2480 
2481  return nullptr;
2482 }
2483 
2484 const TargetRegisterClass *
2486  if (BitWidth == 1)
2487  return &AMDGPU::VReg_1RegClass;
2488  if (BitWidth <= 16)
2489  return &AMDGPU::VGPR_LO16RegClass;
2490  if (BitWidth <= 32)
2491  return &AMDGPU::VGPR_32RegClass;
2494 }
2495 
2496 static const TargetRegisterClass *
2498  if (BitWidth <= 64)
2499  return &AMDGPU::AReg_64RegClass;
2500  if (BitWidth <= 96)
2501  return &AMDGPU::AReg_96RegClass;
2502  if (BitWidth <= 128)
2503  return &AMDGPU::AReg_128RegClass;
2504  if (BitWidth <= 160)
2505  return &AMDGPU::AReg_160RegClass;
2506  if (BitWidth <= 192)
2507  return &AMDGPU::AReg_192RegClass;
2508  if (BitWidth <= 224)
2509  return &AMDGPU::AReg_224RegClass;
2510  if (BitWidth <= 256)
2511  return &AMDGPU::AReg_256RegClass;
2512  if (BitWidth <= 512)
2513  return &AMDGPU::AReg_512RegClass;
2514  if (BitWidth <= 1024)
2515  return &AMDGPU::AReg_1024RegClass;
2516 
2517  return nullptr;
2518 }
2519 
2520 static const TargetRegisterClass *
2522  if (BitWidth <= 64)
2523  return &AMDGPU::AReg_64_Align2RegClass;
2524  if (BitWidth <= 96)
2525  return &AMDGPU::AReg_96_Align2RegClass;
2526  if (BitWidth <= 128)
2527  return &AMDGPU::AReg_128_Align2RegClass;
2528  if (BitWidth <= 160)
2529  return &AMDGPU::AReg_160_Align2RegClass;
2530  if (BitWidth <= 192)
2531  return &AMDGPU::AReg_192_Align2RegClass;
2532  if (BitWidth <= 224)
2533  return &AMDGPU::AReg_224_Align2RegClass;
2534  if (BitWidth <= 256)
2535  return &AMDGPU::AReg_256_Align2RegClass;
2536  if (BitWidth <= 512)
2537  return &AMDGPU::AReg_512_Align2RegClass;
2538  if (BitWidth <= 1024)
2539  return &AMDGPU::AReg_1024_Align2RegClass;
2540 
2541  return nullptr;
2542 }
2543 
2544 const TargetRegisterClass *
2546  if (BitWidth <= 16)
2547  return &AMDGPU::AGPR_LO16RegClass;
2548  if (BitWidth <= 32)
2549  return &AMDGPU::AGPR_32RegClass;
2552 }
2553 
2554 static const TargetRegisterClass *
2556  if (BitWidth <= 64)
2557  return &AMDGPU::AV_64RegClass;
2558  if (BitWidth <= 96)
2559  return &AMDGPU::AV_96RegClass;
2560  if (BitWidth <= 128)
2561  return &AMDGPU::AV_128RegClass;
2562  if (BitWidth <= 160)
2563  return &AMDGPU::AV_160RegClass;
2564  if (BitWidth <= 192)
2565  return &AMDGPU::AV_192RegClass;
2566  if (BitWidth <= 224)
2567  return &AMDGPU::AV_224RegClass;
2568  if (BitWidth <= 256)
2569  return &AMDGPU::AV_256RegClass;
2570  if (BitWidth <= 512)
2571  return &AMDGPU::AV_512RegClass;
2572  if (BitWidth <= 1024)
2573  return &AMDGPU::AV_1024RegClass;
2574 
2575  return nullptr;
2576 }
2577 
2578 static const TargetRegisterClass *
2580  if (BitWidth <= 64)
2581  return &AMDGPU::AV_64_Align2RegClass;
2582  if (BitWidth <= 96)
2583  return &AMDGPU::AV_96_Align2RegClass;
2584  if (BitWidth <= 128)
2585  return &AMDGPU::AV_128_Align2RegClass;
2586  if (BitWidth <= 160)
2587  return &AMDGPU::AV_160_Align2RegClass;
2588  if (BitWidth <= 192)
2589  return &AMDGPU::AV_192_Align2RegClass;
2590  if (BitWidth <= 224)
2591  return &AMDGPU::AV_224_Align2RegClass;
2592  if (BitWidth <= 256)
2593  return &AMDGPU::AV_256_Align2RegClass;
2594  if (BitWidth <= 512)
2595  return &AMDGPU::AV_512_Align2RegClass;
2596  if (BitWidth <= 1024)
2597  return &AMDGPU::AV_1024_Align2RegClass;
2598 
2599  return nullptr;
2600 }
2601 
2602 const TargetRegisterClass *
2604  if (BitWidth <= 16)
2605  return &AMDGPU::VGPR_LO16RegClass;
2606  if (BitWidth <= 32)
2607  return &AMDGPU::AV_32RegClass;
2608  return ST.needsAlignedVGPRs()
2611 }
2612 
2613 const TargetRegisterClass *
2615  if (BitWidth <= 16)
2616  return &AMDGPU::SGPR_LO16RegClass;
2617  if (BitWidth <= 32)
2618  return &AMDGPU::SReg_32RegClass;
2619  if (BitWidth <= 64)
2620  return &AMDGPU::SReg_64RegClass;
2621  if (BitWidth <= 96)
2622  return &AMDGPU::SGPR_96RegClass;
2623  if (BitWidth <= 128)
2624  return &AMDGPU::SGPR_128RegClass;
2625  if (BitWidth <= 160)
2626  return &AMDGPU::SGPR_160RegClass;
2627  if (BitWidth <= 192)
2628  return &AMDGPU::SGPR_192RegClass;
2629  if (BitWidth <= 224)
2630  return &AMDGPU::SGPR_224RegClass;
2631  if (BitWidth <= 256)
2632  return &AMDGPU::SGPR_256RegClass;
2633  if (BitWidth <= 512)
2634  return &AMDGPU::SGPR_512RegClass;
2635  if (BitWidth <= 1024)
2636  return &AMDGPU::SGPR_1024RegClass;
2637 
2638  return nullptr;
2639 }
2640 
2641 // FIXME: This is very slow. It might be worth creating a map from physreg to
2642 // register class.
2643 const TargetRegisterClass *
2645  static const TargetRegisterClass *const BaseClasses[] = {
2646  &AMDGPU::VGPR_LO16RegClass,
2647  &AMDGPU::VGPR_HI16RegClass,
2648  &AMDGPU::SReg_LO16RegClass,
2649  &AMDGPU::AGPR_LO16RegClass,
2650  &AMDGPU::VGPR_32RegClass,
2651  &AMDGPU::SReg_32RegClass,
2652  &AMDGPU::AGPR_32RegClass,
2653  &AMDGPU::AGPR_32RegClass,
2654  &AMDGPU::VReg_64_Align2RegClass,
2655  &AMDGPU::VReg_64RegClass,
2656  &AMDGPU::SReg_64RegClass,
2657  &AMDGPU::AReg_64_Align2RegClass,
2658  &AMDGPU::AReg_64RegClass,
2659  &AMDGPU::VReg_96_Align2RegClass,
2660  &AMDGPU::VReg_96RegClass,
2661  &AMDGPU::SReg_96RegClass,
2662  &AMDGPU::AReg_96_Align2RegClass,
2663  &AMDGPU::AReg_96RegClass,
2664  &AMDGPU::VReg_128_Align2RegClass,
2665  &AMDGPU::VReg_128RegClass,
2666  &AMDGPU::SReg_128RegClass,
2667  &AMDGPU::AReg_128_Align2RegClass,
2668  &AMDGPU::AReg_128RegClass,
2669  &AMDGPU::VReg_160_Align2RegClass,
2670  &AMDGPU::VReg_160RegClass,
2671  &AMDGPU::SReg_160RegClass,
2672  &AMDGPU::AReg_160_Align2RegClass,
2673  &AMDGPU::AReg_160RegClass,
2674  &AMDGPU::VReg_192_Align2RegClass,
2675  &AMDGPU::VReg_192RegClass,
2676  &AMDGPU::SReg_192RegClass,
2677  &AMDGPU::AReg_192_Align2RegClass,
2678  &AMDGPU::AReg_192RegClass,
2679  &AMDGPU::VReg_224_Align2RegClass,
2680  &AMDGPU::VReg_224RegClass,
2681  &AMDGPU::SReg_224RegClass,
2682  &AMDGPU::AReg_224_Align2RegClass,
2683  &AMDGPU::AReg_224RegClass,
2684  &AMDGPU::VReg_256_Align2RegClass,
2685  &AMDGPU::VReg_256RegClass,
2686  &AMDGPU::SReg_256RegClass,
2687  &AMDGPU::AReg_256_Align2RegClass,
2688  &AMDGPU::AReg_256RegClass,
2689  &AMDGPU::VReg_512_Align2RegClass,
2690  &AMDGPU::VReg_512RegClass,
2691  &AMDGPU::SReg_512RegClass,
2692  &AMDGPU::AReg_512_Align2RegClass,
2693  &AMDGPU::AReg_512RegClass,
2694  &AMDGPU::SReg_1024RegClass,
2695  &AMDGPU::VReg_1024_Align2RegClass,
2696  &AMDGPU::VReg_1024RegClass,
2697  &AMDGPU::AReg_1024_Align2RegClass,
2698  &AMDGPU::AReg_1024RegClass,
2699  &AMDGPU::SCC_CLASSRegClass,
2700  &AMDGPU::Pseudo_SReg_32RegClass,
2701  &AMDGPU::Pseudo_SReg_128RegClass,
2702  };
2703 
2704  for (const TargetRegisterClass *BaseClass : BaseClasses) {
2705  if (BaseClass->contains(Reg)) {
2706  return BaseClass;
2707  }
2708  }
2709  return nullptr;
2710 }
2711 
2713  Register Reg) const {
2714  const TargetRegisterClass *RC;
2715  if (Reg.isVirtual())
2716  RC = MRI.getRegClass(Reg);
2717  else
2718  RC = getPhysRegClass(Reg);
2719  return RC ? isSGPRClass(RC) : false;
2720 }
2721 
2722 const TargetRegisterClass *
2724  unsigned Size = getRegSizeInBits(*SRC);
2725  const TargetRegisterClass *VRC = getVGPRClassForBitWidth(Size);
2726  assert(VRC && "Invalid register class size");
2727  return VRC;
2728 }
2729 
2730 const TargetRegisterClass *
2732  unsigned Size = getRegSizeInBits(*SRC);
2733  const TargetRegisterClass *ARC = getAGPRClassForBitWidth(Size);
2734  assert(ARC && "Invalid register class size");
2735  return ARC;
2736 }
2737 
2738 const TargetRegisterClass *
2740  unsigned Size = getRegSizeInBits(*VRC);
2741  if (Size == 32)
2742  return &AMDGPU::SGPR_32RegClass;
2743  const TargetRegisterClass *SRC = getSGPRClassForBitWidth(Size);
2744  assert(SRC && "Invalid register class size");
2745  return SRC;
2746 }
2747 
2748 const TargetRegisterClass *
2750  const TargetRegisterClass *SubRC,
2751  unsigned SubIdx) const {
2752  // Ensure this subregister index is aligned in the super register.
2753  const TargetRegisterClass *MatchRC =
2754  getMatchingSuperRegClass(SuperRC, SubRC, SubIdx);
2755  return MatchRC && MatchRC->hasSubClassEq(SuperRC) ? MatchRC : nullptr;
2756 }
2757 
2758 bool SIRegisterInfo::opCanUseInlineConstant(unsigned OpType) const {
2759  if (OpType >= AMDGPU::OPERAND_REG_INLINE_AC_FIRST &&
2761  return !ST.hasMFMAInlineLiteralBug();
2762 
2763  return OpType >= AMDGPU::OPERAND_SRC_FIRST &&
2764  OpType <= AMDGPU::OPERAND_SRC_LAST;
2765 }
2766 
2768  const TargetRegisterClass *DefRC,
2769  unsigned DefSubReg,
2770  const TargetRegisterClass *SrcRC,
2771  unsigned SrcSubReg) const {
2772  // We want to prefer the smallest register class possible, so we don't want to
2773  // stop and rewrite on anything that looks like a subregister
2774  // extract. Operations mostly don't care about the super register class, so we
2775  // only want to stop on the most basic of copies between the same register
2776  // class.
2777  //
2778  // e.g. if we have something like
2779  // %0 = ...
2780  // %1 = ...
2781  // %2 = REG_SEQUENCE %0, sub0, %1, sub1, %2, sub2
2782  // %3 = COPY %2, sub0
2783  //
2784  // We want to look through the COPY to find:
2785  // => %3 = COPY %0
2786 
2787  // Plain copy.
2788  return getCommonSubClass(DefRC, SrcRC) != nullptr;
2789 }
2790 
2791 bool SIRegisterInfo::opCanUseLiteralConstant(unsigned OpType) const {
2792  // TODO: 64-bit operands have extending behavior from 32-bit literal.
2793  return OpType >= AMDGPU::OPERAND_REG_IMM_FIRST &&
2794  OpType <= AMDGPU::OPERAND_REG_IMM_LAST;
2795 }
2796 
2797 /// Returns a lowest register that is not used at any point in the function.
2798 /// If all registers are used, then this function will return
2799 /// AMDGPU::NoRegister. If \p ReserveHighestVGPR = true, then return
2800 /// highest unused register.
2802  const TargetRegisterClass *RC,
2803  const MachineFunction &MF,
2804  bool ReserveHighestVGPR) const {
2805  if (ReserveHighestVGPR) {
2806  for (MCRegister Reg : reverse(*RC))
2808  return Reg;
2809  } else {
2810  for (MCRegister Reg : *RC)
2812  return Reg;
2813  }
2814  return MCRegister();
2815 }
2816 
2818  unsigned EltSize) const {
2819  const unsigned RegBitWidth = AMDGPU::getRegBitWidth(*RC->MC);
2820  assert(RegBitWidth >= 32 && RegBitWidth <= 1024);
2821 
2822  const unsigned RegDWORDs = RegBitWidth / 32;
2823  const unsigned EltDWORDs = EltSize / 4;
2824  assert(RegSplitParts.size() + 1 >= EltDWORDs);
2825 
2826  const std::vector<int16_t> &Parts = RegSplitParts[EltDWORDs - 1];
2827  const unsigned NumParts = RegDWORDs / EltDWORDs;
2828 
2829  return makeArrayRef(Parts.data(), NumParts);
2830 }
2831 
2832 const TargetRegisterClass*
2834  Register Reg) const {
2835  return Reg.isVirtual() ? MRI.getRegClass(Reg) : getPhysRegClass(Reg);
2836 }
2837 
2838 const TargetRegisterClass *
2840  const MachineOperand &MO) const {
2841  const TargetRegisterClass *SrcRC = getRegClassForReg(MRI, MO.getReg());
2842  return getSubRegisterClass(SrcRC, MO.getSubReg());
2843 }
2844 
2846  Register Reg) const {
2848  // Registers without classes are unaddressable, SGPR-like registers.
2849  return RC && isVGPRClass(RC);
2850 }
2851 
2853  Register Reg) const {
2855 
2856  // Registers without classes are unaddressable, SGPR-like registers.
2857  return RC && isAGPRClass(RC);
2858 }
2859 
2861  const TargetRegisterClass *SrcRC,
2862  unsigned SubReg,
2863  const TargetRegisterClass *DstRC,
2864  unsigned DstSubReg,
2865  const TargetRegisterClass *NewRC,
2866  LiveIntervals &LIS) const {
2867  unsigned SrcSize = getRegSizeInBits(*SrcRC);
2868  unsigned DstSize = getRegSizeInBits(*DstRC);
2869  unsigned NewSize = getRegSizeInBits(*NewRC);
2870 
2871  // Do not increase size of registers beyond dword, we would need to allocate
2872  // adjacent registers and constraint regalloc more than needed.
2873 
2874  // Always allow dword coalescing.
2875  if (SrcSize <= 32 || DstSize <= 32)
2876  return true;
2877 
2878  return NewSize <= DstSize || NewSize <= SrcSize;
2879 }
2880 
2882  MachineFunction &MF) const {
2884 
2885  unsigned Occupancy = ST.getOccupancyWithLocalMemSize(MFI->getLDSSize(),
2886  MF.getFunction());
2887  switch (RC->getID()) {
2888  default:
2889  return AMDGPUGenRegisterInfo::getRegPressureLimit(RC, MF);
2890  case AMDGPU::VGPR_32RegClassID:
2891  case AMDGPU::VGPR_LO16RegClassID:
2892  case AMDGPU::VGPR_HI16RegClassID:
2893  return std::min(ST.getMaxNumVGPRs(Occupancy), ST.getMaxNumVGPRs(MF));
2894  case AMDGPU::SGPR_32RegClassID:
2895  case AMDGPU::SGPR_LO16RegClassID:
2896  return std::min(ST.getMaxNumSGPRs(Occupancy, true), ST.getMaxNumSGPRs(MF));
2897  }
2898 }
2899 
2901  unsigned Idx) const {
2902  if (Idx == AMDGPU::RegisterPressureSets::VGPR_32 ||
2903  Idx == AMDGPU::RegisterPressureSets::AGPR_32)
2904  return getRegPressureLimit(&AMDGPU::VGPR_32RegClass,
2905  const_cast<MachineFunction &>(MF));
2906 
2907  if (Idx == AMDGPU::RegisterPressureSets::SReg_32)
2908  return getRegPressureLimit(&AMDGPU::SGPR_32RegClass,
2909  const_cast<MachineFunction &>(MF));
2910 
2911  llvm_unreachable("Unexpected register pressure set!");
2912 }
2913 
2914 const int *SIRegisterInfo::getRegUnitPressureSets(unsigned RegUnit) const {
2915  static const int Empty[] = { -1 };
2916 
2917  if (RegPressureIgnoredUnits[RegUnit])
2918  return Empty;
2919 
2920  return AMDGPUGenRegisterInfo::getRegUnitPressureSets(RegUnit);
2921 }
2922 
2924  // Not a callee saved register.
2925  return AMDGPU::SGPR30_SGPR31;
2926 }
2927 
2928 const TargetRegisterClass *
2930  const RegisterBank &RB) const {
2931  switch (RB.getID()) {
2932  case AMDGPU::VGPRRegBankID:
2933  return getVGPRClassForBitWidth(std::max(32u, Size));
2934  case AMDGPU::VCCRegBankID:
2935  assert(Size == 1);
2936  return isWave32 ? &AMDGPU::SReg_32_XM0_XEXECRegClass
2937  : &AMDGPU::SReg_64_XEXECRegClass;
2938  case AMDGPU::SGPRRegBankID:
2939  return getSGPRClassForBitWidth(std::max(32u, Size));
2940  case AMDGPU::AGPRRegBankID:
2941  return getAGPRClassForBitWidth(std::max(32u, Size));
2942  default:
2943  llvm_unreachable("unknown register bank");
2944  }
2945 }
2946 
2947 const TargetRegisterClass *
2949  const MachineRegisterInfo &MRI) const {
2950  const RegClassOrRegBank &RCOrRB = MRI.getRegClassOrRegBank(MO.getReg());
2951  if (const RegisterBank *RB = RCOrRB.dyn_cast<const RegisterBank*>())
2952  return getRegClassForTypeOnBank(MRI.getType(MO.getReg()), *RB);
2953 
2954  if (const auto *RC = RCOrRB.dyn_cast<const TargetRegisterClass *>())
2955  return getAllocatableClass(RC);
2956 
2957  return nullptr;
2958 }
2959 
2961  return isWave32 ? AMDGPU::VCC_LO : AMDGPU::VCC;
2962 }
2963 
2965  return isWave32 ? AMDGPU::EXEC_LO : AMDGPU::EXEC;
2966 }
2967 
2969  // VGPR tuples have an alignment requirement on gfx90a variants.
2970  return ST.needsAlignedVGPRs() ? &AMDGPU::VReg_64_Align2RegClass
2971  : &AMDGPU::VReg_64RegClass;
2972 }
2973 
2974 const TargetRegisterClass *
2975 SIRegisterInfo::getRegClass(unsigned RCID) const {
2976  switch ((int)RCID) {
2977  case AMDGPU::SReg_1RegClassID:
2978  return getBoolRC();
2979  case AMDGPU::SReg_1_XEXECRegClassID:
2980  return isWave32 ? &AMDGPU::SReg_32_XM0_XEXECRegClass
2981  : &AMDGPU::SReg_64_XEXECRegClass;
2982  case -1:
2983  return nullptr;
2984  default:
2986  }
2987 }
2988 
2989 // Find reaching register definition
2991  MachineInstr &Use,
2993  LiveIntervals *LIS) const {
2994  auto &MDT = LIS->getAnalysis<MachineDominatorTree>();
2995  SlotIndex UseIdx = LIS->getInstructionIndex(Use);
2996  SlotIndex DefIdx;
2997 
2998  if (Reg.isVirtual()) {
2999  if (!LIS->hasInterval(Reg))
3000  return nullptr;
3001  LiveInterval &LI = LIS->getInterval(Reg);
3002  LaneBitmask SubLanes = SubReg ? getSubRegIndexLaneMask(SubReg)
3004  VNInfo *V = nullptr;
3005  if (LI.hasSubRanges()) {
3006  for (auto &S : LI.subranges()) {
3007  if ((S.LaneMask & SubLanes) == SubLanes) {
3008  V = S.getVNInfoAt(UseIdx);
3009  break;
3010  }
3011  }
3012  } else {
3013  V = LI.getVNInfoAt(UseIdx);
3014  }
3015  if (!V)
3016  return nullptr;
3017  DefIdx = V->def;
3018  } else {
3019  // Find last def.
3020  for (MCRegUnitIterator Units(Reg.asMCReg(), this); Units.isValid();
3021  ++Units) {
3022  LiveRange &LR = LIS->getRegUnit(*Units);
3023  if (VNInfo *V = LR.getVNInfoAt(UseIdx)) {
3024  if (!DefIdx.isValid() ||
3025  MDT.dominates(LIS->getInstructionFromIndex(DefIdx),
3026  LIS->getInstructionFromIndex(V->def)))
3027  DefIdx = V->def;
3028  } else {
3029  return nullptr;
3030  }
3031  }
3032  }
3033 
3034  MachineInstr *Def = LIS->getInstructionFromIndex(DefIdx);
3035 
3036  if (!Def || !MDT.dominates(Def, &Use))
3037  return nullptr;
3038 
3039  assert(Def->modifiesRegister(Reg, this));
3040 
3041  return Def;
3042 }
3043 
3045  assert(getRegSizeInBits(*getPhysRegClass(Reg)) <= 32);
3046 
3047  for (const TargetRegisterClass &RC : { AMDGPU::VGPR_32RegClass,
3048  AMDGPU::SReg_32RegClass,
3049  AMDGPU::AGPR_32RegClass } ) {
3050  if (MCPhysReg Super = getMatchingSuperReg(Reg, AMDGPU::lo16, &RC))
3051  return Super;
3052  }
3053  if (MCPhysReg Super = getMatchingSuperReg(Reg, AMDGPU::hi16,
3054  &AMDGPU::VGPR_32RegClass)) {
3055  return Super;
3056  }
3057 
3058  return AMDGPU::NoRegister;
3059 }
3060 
3062  if (!ST.needsAlignedVGPRs())
3063  return true;
3064 
3065  if (isVGPRClass(&RC))
3066  return RC.hasSuperClassEq(getVGPRClassForBitWidth(getRegSizeInBits(RC)));
3067  if (isAGPRClass(&RC))
3068  return RC.hasSuperClassEq(getAGPRClassForBitWidth(getRegSizeInBits(RC)));
3069  if (isVectorSuperClass(&RC))
3070  return RC.hasSuperClassEq(
3071  getVectorSuperClassForBitWidth(getRegSizeInBits(RC)));
3072 
3073  return true;
3074 }
3075 
3076 const TargetRegisterClass *
3078  if (!RC || !ST.needsAlignedVGPRs())
3079  return RC;
3080 
3081  unsigned Size = getRegSizeInBits(*RC);
3082  if (Size <= 32)
3083  return RC;
3084 
3085  if (isVGPRClass(RC))
3086  return getAlignedVGPRClassForBitWidth(Size);
3087  if (isAGPRClass(RC))
3088  return getAlignedAGPRClassForBitWidth(Size);
3089  if (isVectorSuperClass(RC))
3091 
3092  return RC;
3093 }
3094 
3097  return makeArrayRef(AMDGPU::SGPR_128RegClass.begin(),
3098  ST.getMaxNumSGPRs(MF) / 4);
3099 }
3100 
3103  return makeArrayRef(AMDGPU::SGPR_64RegClass.begin(),
3104  ST.getMaxNumSGPRs(MF) / 2);
3105 }
3106 
3109  return makeArrayRef(AMDGPU::SGPR_32RegClass.begin(), ST.getMaxNumSGPRs(MF));
3110 }
llvm::LaneBitmask
Definition: LaneBitmask.h:40
i
i
Definition: README.txt:29
llvm::TargetRegisterInfo::getLargestLegalSuperClass
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...
Definition: TargetRegisterInfo.h:809
llvm::SIRegisterInfo::getVGPRClassForBitWidth
const LLVM_READONLY TargetRegisterClass * getVGPRClassForBitWidth(unsigned BitWidth) const
Definition: SIRegisterInfo.cpp:2485
llvm::SIRegisterInfo::getCalleeSavedRegs
const MCPhysReg * getCalleeSavedRegs(const MachineFunction *MF) const override
Definition: SIRegisterInfo.cpp:390
llvm::SIRegisterInfo::getEquivalentVGPRClass
const TargetRegisterClass * getEquivalentVGPRClass(const TargetRegisterClass *SRC) const
Definition: SIRegisterInfo.cpp:2723
llvm::SIMachineFunctionInfo::getSGPRSpillVGPRs
ArrayRef< SGPRSpillVGPR > getSGPRSpillVGPRs() const
Definition: SIMachineFunctionInfo.h:570
getAlignedVectorSuperClassForBitWidth
static const TargetRegisterClass * getAlignedVectorSuperClassForBitWidth(unsigned BitWidth)
Definition: SIRegisterInfo.cpp:2579
llvm::AMDGPUSubtarget::hasInv2PiInlineImm
bool hasInv2PiInlineImm() const
Definition: AMDGPUSubtarget.h:184
llvm::SIRegisterInfo::isAGPRClass
static bool isAGPRClass(const TargetRegisterClass *RC)
Definition: SIRegisterInfo.h:207
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:108
llvm::SGPRSpillBuilder::TRI
const SIRegisterInfo & TRI
Definition: SIRegisterInfo.cpp:106
llvm::MachineInstrBuilder::addImm
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
Definition: MachineInstrBuilder.h:131
llvm::TargetRegisterClass::getID
unsigned getID() const
Return the register class ID number.
Definition: TargetRegisterInfo.h:75
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::tgtok::Def
@ Def
Definition: TGLexer.h:50
llvm::MachineRegisterInfo::isPhysRegUsed
bool isPhysRegUsed(MCRegister PhysReg, bool SkipRegMaskTest=false) const
Return true if the specified register is modified or read in this function.
Definition: MachineRegisterInfo.cpp:587
llvm::Pass::getAnalysis
AnalysisType & getAnalysis() const
getAnalysis<AnalysisType>() - This function is used by subclasses to get to the analysis information ...
Definition: PassAnalysisSupport.h:230
llvm::SIMachineFunctionInfo::getVGPRForAGPRCopy
Register getVGPRForAGPRCopy() const
Definition: SIMachineFunctionInfo.h:519
llvm::SIRegisterInfo::needsFrameBaseReg
bool needsFrameBaseReg(MachineInstr *MI, int64_t Offset) const override
Definition: SIRegisterInfo.cpp:792
llvm::AMDGPU::getFlatScratchInstSVfromSS
LLVM_READONLY int getFlatScratchInstSVfromSS(uint16_t Opcode)
llvm::MachineRegisterInfo::createVirtualRegister
Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
Definition: MachineRegisterInfo.cpp:156
llvm::MachineFrameInfo::getNumFixedObjects
unsigned getNumFixedObjects() const
Return the number of fixed objects.
Definition: MachineFrameInfo.h:413
llvm::SIRegisterInfo::getRegClass
const TargetRegisterClass * getRegClass(unsigned RCID) const
Definition: SIRegisterInfo.cpp:2975
llvm::SGPRSpillBuilder::PerVGPRData
Definition: SIRegisterInfo.cpp:73
llvm::SIRegisterInfo::requiresVirtualBaseRegisters
bool requiresVirtualBaseRegisters(const MachineFunction &Fn) const override
Definition: SIRegisterInfo.cpp:764
SIMachineFunctionInfo.h
llvm::SlotIndex::isValid
bool isValid() const
Returns true if this is a valid index.
Definition: SlotIndexes.h:152
llvm::GCNSubtarget::getFrameLowering
const SIFrameLowering * getFrameLowering() const override
Definition: GCNSubtarget.h:220
llvm::MachineRegisterInfo
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Definition: MachineRegisterInfo.h:50
llvm::MCRegister::from
static MCRegister from(unsigned Val)
Check the provided unsigned value is a valid MCRegister.
Definition: MCRegister.h:67
llvm::MachineInstrBuilder::add
const MachineInstrBuilder & add(const MachineOperand &MO) const
Definition: MachineInstrBuilder.h:224
llvm::BitVector::set
BitVector & set()
Definition: BitVector.h:344
llvm::RegScavenger::scavengeRegisterBackwards
Register scavengeRegisterBackwards(const TargetRegisterClass &RC, MachineBasicBlock::iterator To, bool RestoreAfter, int SPAdj, bool AllowSpill=true)
Make a register of the specific register class available from the current position backwards to the p...
Definition: RegisterScavenging.cpp:592
contains
return AArch64::GPR64RegClass contains(Reg)
llvm::SIRegisterInfo::getAllSGPR128
ArrayRef< MCPhysReg > getAllSGPR128(const MachineFunction &MF) const
Return all SGPR128 which satisfy the waves per execution unit requirement of the subtarget.
Definition: SIRegisterInfo.cpp:3096
llvm::MachineOperand::setIsKill
void setIsKill(bool Val=true)
Definition: MachineOperand.h:509
llvm::RegState::ImplicitKill
@ ImplicitKill
Definition: MachineInstrBuilder.h:64
llvm::SIRegisterInfo::getFrameIndexInstrOffset
int64_t getFrameIndexInstrOffset(const MachineInstr *MI, int Idx) const override
Definition: SIRegisterInfo.cpp:778
llvm::SIRegisterInfo::getRegUnitPressureSets
const int * getRegUnitPressureSets(unsigned RegUnit) const override
Definition: SIRegisterInfo.cpp:2914
llvm::SIRegisterInfo::getScratchInstrOffset
int64_t getScratchInstrOffset(const MachineInstr *MI) const
Definition: SIRegisterInfo.cpp:770
llvm::SGPRSpillBuilder::IsKill
bool IsKill
Definition: SIRegisterInfo.cpp:84
llvm::MachineFunction::getMachineMemOperand
MachineMemOperand * getMachineMemOperand(MachinePointerInfo PtrInfo, MachineMemOperand::Flags f, uint64_t s, Align base_alignment, const AAMDNodes &AAInfo=AAMDNodes(), const MDNode *Ranges=nullptr, SyncScope::ID SSID=SyncScope::System, AtomicOrdering Ordering=AtomicOrdering::NotAtomic, AtomicOrdering FailureOrdering=AtomicOrdering::NotAtomic)
getMachineMemOperand - Allocate a new MachineMemOperand.
Definition: MachineFunction.cpp:454
llvm::SIRegisterInfo::getAllSGPR64
ArrayRef< MCPhysReg > getAllSGPR64(const MachineFunction &MF) const
Return all SGPR64 which satisfy the waves per execution unit requirement of the subtarget.
Definition: SIRegisterInfo.cpp:3102
llvm::LiveIntervals::getInstructionFromIndex
MachineInstr * getInstructionFromIndex(SlotIndex index) const
Returns the instruction associated with the given index.
Definition: LiveIntervals.h:225
llvm::GCNSubtarget::needsAlignedVGPRs
bool needsAlignedVGPRs() const
Return if operations acting on VGPR tuples require even alignment.
Definition: GCNSubtarget.h:1067
llvm::X86Disassembler::Reg
Reg
All possible values of the reg field in the ModR/M byte.
Definition: X86DisassemblerDecoder.h:462
llvm::MachineRegisterInfo::getTargetRegisterInfo
const TargetRegisterInfo * getTargetRegisterInfo() const
Definition: MachineRegisterInfo.h:151
llvm::SIRegisterInfo::SpilledReg
Definition: SIRegisterInfo.h:54
llvm::CallingConv::Cold
@ Cold
Attempts to make code in the caller as efficient as possible under the assumption that the call is no...
Definition: CallingConv.h:47
llvm::TargetRegisterInfo::shouldRealignStack
virtual bool shouldRealignStack(const MachineFunction &MF) const
True if storage within the function requires the stack pointer to be aligned more than the normal cal...
Definition: TargetRegisterInfo.cpp:483
llvm::LivePhysRegs
A set of physical registers with utility functions to track liveness when walking backward/forward th...
Definition: LivePhysRegs.h:50
llvm::SIRegisterInfo::SIRegisterInfo
SIRegisterInfo(const GCNSubtarget &ST)
Definition: SIRegisterInfo.cpp:319
llvm::VNInfo::def
SlotIndex def
The index of the defining instruction.
Definition: LiveInterval.h:61
getOffsetMUBUFStore
static int getOffsetMUBUFStore(unsigned Opc)
Definition: SIRegisterInfo.cpp:1037
llvm::MachineOperand::setImm
void setImm(int64_t immVal)
Definition: MachineOperand.h:664
llvm::SIRegisterInfo::getVectorSuperClassForBitWidth
const LLVM_READONLY TargetRegisterClass * getVectorSuperClassForBitWidth(unsigned BitWidth) const
Definition: SIRegisterInfo.cpp:2603
llvm::AMDGPUSubtarget::getOccupancyWithLocalMemSize
unsigned getOccupancyWithLocalMemSize(uint32_t Bytes, const Function &) const
Inverse of getMaxLocalMemWithWaveCount.
Definition: AMDGPUSubtarget.cpp:319
llvm::SIRegisterInfo::getWaveMaskRegClass
const TargetRegisterClass * getWaveMaskRegClass() const
Definition: SIRegisterInfo.h:335
llvm::LiveIntervals::removeAllRegUnitsForPhysReg
void removeAllRegUnitsForPhysReg(MCRegister Reg)
Remove associated live ranges for the register units associated with Reg.
Definition: LiveIntervals.h:419
llvm::AMDGPUMachineFunction::getLDSSize
uint32_t getLDSSize() const
Definition: AMDGPUMachineFunction.h:72
llvm::SIRegisterInfo::getExec
MCRegister getExec() const
Definition: SIRegisterInfo.cpp:2964
Shift
bool Shift
Definition: README.txt:468
llvm::BitVector::resize
void resize(unsigned N, bool t=false)
resize - Grow or shrink the bitvector.
Definition: BitVector.h:334
llvm::MachineMemOperand
A description of a memory reference used in the backend.
Definition: MachineMemOperand.h:127
llvm::sys::path::begin
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
Definition: Path.cpp:226
llvm::LivePhysRegs::contains
bool contains(MCPhysReg Reg) const
Returns true if register Reg is contained in the set.
Definition: LivePhysRegs.h:108
llvm::SIRegisterInfo::getRegClassForSizeOnBank
const TargetRegisterClass * getRegClassForSizeOnBank(unsigned Size, const RegisterBank &Bank) const
Definition: SIRegisterInfo.cpp:2929
llvm::SIRegisterInfo::getEquivalentAGPRClass
const TargetRegisterClass * getEquivalentAGPRClass(const TargetRegisterClass *SRC) const
Definition: SIRegisterInfo.cpp:2731
llvm::SIRegisterInfo::materializeFrameBaseRegister
Register materializeFrameBaseRegister(MachineBasicBlock *MBB, int FrameIdx, int64_t Offset) const override
Definition: SIRegisterInfo.cpp:806
getOffenMUBUFStore
static int getOffenMUBUFStore(unsigned Opc)
Definition: SIRegisterInfo.cpp:1095
llvm::SIRegisterInfo::spillSGPR
bool spillSGPR(MachineBasicBlock::iterator MI, int FI, RegScavenger *RS, SlotIndexes *Indexes=nullptr, LiveIntervals *LIS=nullptr, bool OnlyToVGPR=false) const
If OnlyToVGPR is true, this will only succeed if this.
Definition: SIRegisterInfo.cpp:1667
llvm::SGPRSpillBuilder::TII
const SIInstrInfo & TII
Definition: SIRegisterInfo.cpp:105
llvm::GCNSubtarget
Definition: GCNSubtarget.h:31
llvm::SIRegisterInfo::getAllAllocatableSRegMask
const uint32_t * getAllAllocatableSRegMask() const
Definition: SIRegisterInfo.cpp:525
llvm::max
Expected< ExpressionValue > max(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
Definition: FileCheck.cpp:337
llvm::SIRegisterInfo::isAsmClobberable
bool isAsmClobberable(const MachineFunction &MF, MCRegister PhysReg) const override
Definition: SIRegisterInfo.cpp:720
llvm::AMDGPU::OPERAND_REG_IMM_LAST
@ OPERAND_REG_IMM_LAST
Definition: SIDefines.h:195
getAlignedVGPRClassForBitWidth
static const TargetRegisterClass * getAlignedVGPRClassForBitWidth(unsigned BitWidth)
Definition: SIRegisterInfo.cpp:2461
llvm::AMDGPU::getNamedOperandIdx
LLVM_READONLY int16_t getNamedOperandIdx(uint16_t Opcode, uint16_t NamedIdx)
llvm::SIRegisterInfo::getProperlyAlignedRC
const TargetRegisterClass * getProperlyAlignedRC(const TargetRegisterClass *RC) const
Definition: SIRegisterInfo.cpp:3077
llvm::SIRegisterInfo::requiresFrameIndexReplacementScavenging
bool requiresFrameIndexReplacementScavenging(const MachineFunction &MF) const override
Definition: SIRegisterInfo.cpp:758
llvm::MachineOperand::isFI
bool isFI() const
isFI - Tests if this is a MO_FrameIndex operand.
Definition: MachineOperand.h:330
TRI
unsigned const TargetRegisterInfo * TRI
Definition: MachineSink.cpp:1628
llvm::cl::ReallyHidden
@ ReallyHidden
Definition: CommandLine.h:141
llvm::Data
@ Data
Definition: SIMachineScheduler.h:55
llvm::ArrayRef::empty
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:159
llvm::SIRegisterInfo::buildVGPRSpillLoadStore
void buildVGPRSpillLoadStore(SGPRSpillBuilder &SB, int Index, int Offset, bool IsLoad, bool IsKill=true) const
Definition: SIRegisterInfo.cpp:1634
llvm::commonAlignment
Align commonAlignment(Align A, uint64_t Offset)
Returns the alignment that satisfies both alignments.
Definition: Alignment.h:213
llvm::SIRegisterInfo::findReachingDef
MachineInstr * findReachingDef(Register Reg, unsigned SubReg, MachineInstr &Use, MachineRegisterInfo &MRI, LiveIntervals *LIS) const
Definition: SIRegisterInfo.cpp:2990
llvm::LiveIntervals::getInstructionIndex
SlotIndex getInstructionIndex(const MachineInstr &Instr) const
Returns the base index of the given instruction.
Definition: LiveIntervals.h:220
llvm::GCNSubtarget::getInstrInfo
const SIInstrInfo * getInstrInfo() const override
Definition: GCNSubtarget.h:216
llvm::RegScavenger::isRegUsed
bool isRegUsed(Register Reg, bool includeReserved=true) const
Return if a specific register is currently used.
Definition: RegisterScavenging.cpp:260
llvm::SGPRSpillBuilder::getPerVGPRData
PerVGPRData getPerVGPRData()
Definition: SIRegisterInfo.cpp:144
getAnyVGPRClassForBitWidth
static const TargetRegisterClass * getAnyVGPRClassForBitWidth(unsigned BitWidth)
Definition: SIRegisterInfo.cpp:2437
llvm::MachineFrameInfo::hasStackObjects
bool hasStackObjects() const
Return true if there are any stack objects in this function.
Definition: MachineFrameInfo.h:350
llvm::SIFrameLowering::hasFP
bool hasFP(const MachineFunction &MF) const override
hasFP - Return true if the specified function should have a dedicated frame pointer register.
Definition: SIFrameLowering.cpp:1472
llvm::MachineMemOperand::getPointerInfo
const MachinePointerInfo & getPointerInfo() const
Definition: MachineMemOperand.h:201
llvm::MachineOperand::isKill
bool isKill() const
Definition: MachineOperand.h:389
llvm::SIRegisterInfo::getCrossCopyRegClass
const TargetRegisterClass * getCrossCopyRegClass(const TargetRegisterClass *RC) const override
Returns a legal register class to copy a register in the specified class to or from.
Definition: SIRegisterInfo.cpp:931
llvm::SIRegisterInfo::getFrameRegister
Register getFrameRegister(const MachineFunction &MF) const override
Definition: SIRegisterInfo.cpp:490
llvm::AMDGPU::hasNamedOperand
LLVM_READONLY bool hasNamedOperand(uint64_t Opcode, uint64_t NamedIdx)
Definition: AMDGPUBaseInfo.h:303
llvm::AMDGPU::OPERAND_REG_INLINE_AC_LAST
@ OPERAND_REG_INLINE_AC_LAST
Definition: SIDefines.h:201
llvm::getDefRegState
unsigned getDefRegState(bool B)
Definition: MachineInstrBuilder.h:540
llvm::MachineFunction::getRegInfo
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Definition: MachineFunction.h:667
lo16
We lo16(.CPI_X_0)(r2) lis r2
llvm::RegisterBank
This class implements the register bank concept.
Definition: RegisterBank.h:28
getReg
static unsigned getReg(const MCDisassembler *D, unsigned RC, unsigned RegNo)
Definition: MipsDisassembler.cpp:517
llvm::GCNSubtarget::getMaxNumSGPRs
unsigned getMaxNumSGPRs(unsigned WavesPerEU, bool Addressable) const
Definition: GCNSubtarget.h:1157
llvm::MachineOperand::ChangeToRegister
void ChangeToRegister(Register 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.
Definition: MachineOperand.cpp:241
GCNSubtarget.h
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::MachineOperand::getImm
int64_t getImm() const
Definition: MachineOperand.h:546
llvm::MachineFunction::getInfo
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
Definition: MachineFunction.h:755
llvm::RegScavenger::scavengeRegister
Register scavengeRegister(const TargetRegisterClass *RC, MachineBasicBlock::iterator I, int SPAdj, bool AllowSpill=true)
Make a register of the specific register class available and do the appropriate bookkeeping.
Definition: RegisterScavenging.cpp:525
llvm::SGPRSpillBuilder::SGPRSpillBuilder
SGPRSpillBuilder(const SIRegisterInfo &TRI, const SIInstrInfo &TII, bool IsWave32, MachineBasicBlock::iterator MI, Register Reg, bool IsKill, int Index, RegScavenger *RS)
Definition: SIRegisterInfo.cpp:118
llvm::MachineInstr::getOperand
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:526
llvm::MachineRegisterInfo::isReserved
bool isReserved(MCRegister PhysReg) const
isReserved - Returns true when PhysReg is a reserved register.
Definition: MachineRegisterInfo.h:930
llvm::SGPRSpillBuilder::setMI
void setMI(MachineBasicBlock *NewMBB, MachineBasicBlock::iterator NewMI)
Definition: SIRegisterInfo.cpp:310
llvm::SIRegisterInfo::getLargestLegalSuperClass
const TargetRegisterClass * getLargestLegalSuperClass(const TargetRegisterClass *RC, const MachineFunction &MF) const override
Definition: SIRegisterInfo.cpp:436
llvm::TargetRegisterClass
Definition: TargetRegisterInfo.h:46
llvm::SIRegisterInfo::getReturnAddressReg
MCRegister getReturnAddressReg(const MachineFunction &MF) const
Definition: SIRegisterInfo.cpp:2923
llvm::SIRegisterInfo::getRegClassForReg
const TargetRegisterClass * getRegClassForReg(const MachineRegisterInfo &MRI, Register Reg) const
Definition: SIRegisterInfo.cpp:2833
llvm::SIRegisterInfo::isAGPR
bool isAGPR(const MachineRegisterInfo &MRI, Register Reg) const
Definition: SIRegisterInfo.cpp:2852
TII
const HexagonInstrInfo * TII
Definition: HexagonCopyToCombine.cpp:125
llvm::dwarf::Index
Index
Definition: Dwarf.h:472
llvm::MachineOperand::ChangeToImmediate
void ChangeToImmediate(int64_t ImmVal, unsigned TargetFlags=0)
ChangeToImmediate - Replace this operand with a new immediate operand of the specified value.
Definition: MachineOperand.cpp:156
llvm::alignDown
uint64_t alignDown(uint64_t Value, uint64_t Align, uint64_t Skew=0)
Returns the largest uint64_t less than or equal to Value and is Skew mod Align.
Definition: MathExtras.h:694
llvm::MCInstrDesc
Describe properties that are true of each instruction in the target description file.
Definition: MCInstrDesc.h:197
llvm::MachineOperand
MachineOperand class - Representation of each machine instruction operand.
Definition: MachineOperand.h:48
llvm::SGPRSpillBuilder::SavedExecReg
Register SavedExecReg
Definition: SIRegisterInfo.cpp:96
llvm::CallingConv::C
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
AMDGPU
Definition: AMDGPUReplaceLDSUseWithPointer.cpp:114
llvm::M0
unsigned M0(unsigned Val)
Definition: VE.h:465
llvm::SIRegisterInfo::getRegPressureLimit
unsigned getRegPressureLimit(const TargetRegisterClass *RC, MachineFunction &MF) const override
Definition: SIRegisterInfo.cpp:2881
llvm::SIMachineFunctionInfo::getStackPtrOffsetReg
Register getStackPtrOffsetReg() const
Definition: SIMachineFunctionInfo.h:814
llvm::SIMachineFunctionInfo::usesAGPRs
bool usesAGPRs(const MachineFunction &MF) const
Definition: SIMachineFunctionInfo.cpp:699
llvm::TargetRegisterClass::hasSuperClassEq
bool hasSuperClassEq(const TargetRegisterClass *RC) const
Returns true if RC is a super-class of or equal to this class.
Definition: TargetRegisterInfo.h:142
llvm::report_fatal_error
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:145
getAlignedAGPRClassForBitWidth
static const TargetRegisterClass * getAlignedAGPRClassForBitWidth(unsigned BitWidth)
Definition: SIRegisterInfo.cpp:2521
llvm::MachineFrameInfo::getStackID
uint8_t getStackID(int ObjectIdx) const
Definition: MachineFrameInfo.h:731
llvm::SGPRSpillBuilder::IsWave32
bool IsWave32
Definition: SIRegisterInfo.cpp:107
llvm::SIRegisterInfo::SpilledReg::VGPR
Register VGPR
Definition: SIRegisterInfo.h:55
llvm::RegisterBank::getID
unsigned getID() const
Get the identifier of this register bank.
Definition: RegisterBank.h:47
llvm::ThreadPriority::Low
@ Low
Lower the current thread's priority such that it does not affect foreground tasks significantly.
llvm::SlotIndexes
SlotIndexes pass.
Definition: SlotIndexes.h:319
llvm::SIRegisterInfo::getSubRegFromChannel
static unsigned getSubRegFromChannel(unsigned Channel, unsigned NumRegs=1)
Definition: SIRegisterInfo.cpp:529
buildMUBUFOffsetLoadStore
static bool buildMUBUFOffsetLoadStore(const GCNSubtarget &ST, MachineFrameInfo &MFI, MachineBasicBlock::iterator MI, int Index, int64_t Offset)
Definition: SIRegisterInfo.cpp:1196
llvm::SGPRSpillBuilder::ExecReg
Register ExecReg
Definition: SIRegisterInfo.cpp:108
llvm::MachineFrameInfo::getObjectOffset
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
Definition: MachineFrameInfo.h:526
llvm::SIRegisterInfo::isSGPRClass
static bool isSGPRClass(const TargetRegisterClass *RC)
Definition: SIRegisterInfo.h:190
Info
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
llvm::SIRegisterInfo
Definition: SIRegisterInfo.h:30
llvm::SIRegisterInfo::getCallPreservedMask
const uint32_t * getCallPreservedMask(const MachineFunction &MF, CallingConv::ID) const override
Definition: SIRegisterInfo.cpp:415
llvm::SIRegisterInfo::getVCC
MCRegister getVCC() const
Definition: SIRegisterInfo.cpp:2960
llvm::BitVector
Definition: BitVector.h:75
llvm::SGPRSpillBuilder::EltSize
unsigned EltSize
Definition: SIRegisterInfo.cpp:99
getOffenMUBUFLoad
static int getOffenMUBUFLoad(unsigned Opc)
Definition: SIRegisterInfo.cpp:1118
llvm::SIRegisterInfo::getVGPR64Class
const TargetRegisterClass * getVGPR64Class() const
Definition: SIRegisterInfo.cpp:2968
llvm::SGPRSpillBuilder::TmpVGPRIndex
int TmpVGPRIndex
Definition: SIRegisterInfo.cpp:92
llvm::LiveInterval
LiveInterval - This class represents the liveness of a register, or stack slot.
Definition: LiveInterval.h:686
llvm::SIFrameLowering
Definition: SIFrameLowering.h:16
llvm::MachineFrameInfo::isFixedObjectIndex
bool isFixedObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a fixed stack object.
Definition: MachineFrameInfo.h:688
llvm::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
llvm::SlotIndex
SlotIndex - An opaque wrapper around machine indexes.
Definition: SlotIndexes.h:82
llvm::SIMachineFunctionInfo::getSGPRToVGPRSpills
ArrayRef< SIRegisterInfo::SpilledReg > getSGPRToVGPRSpills(int FrameIndex) const
Definition: SIMachineFunctionInfo.h:563
llvm::GCNSubtarget::getMaxNumVGPRs
unsigned getMaxNumVGPRs(unsigned WavesPerEU) const
Definition: GCNSubtarget.h:1227
llvm::CallingConv::ID
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
llvm::MachineInstrBuilder::getReg
Register getReg(unsigned Idx) const
Get the register for the operand index.
Definition: MachineInstrBuilder.h:94
llvm::MachineBasicBlock
Definition: MachineBasicBlock.h:94
llvm::SIRegisterInfo::eliminateSGPRToVGPRSpillFrameIndex
bool eliminateSGPRToVGPRSpillFrameIndex(MachineBasicBlock::iterator MI, int FI, RegScavenger *RS, SlotIndexes *Indexes=nullptr, LiveIntervals *LIS=nullptr) const
Special case of eliminateFrameIndex.
Definition: SIRegisterInfo.cpp:1933
llvm::SlotIndexes::insertMachineInstrInMaps
SlotIndex insertMachineInstrInMaps(MachineInstr &MI, bool Late=false)
Insert the given machine instruction into the mapping.
Definition: SlotIndexes.h:540
llvm::MachineInstrBuilder::cloneMemRefs
const MachineInstrBuilder & cloneMemRefs(const MachineInstr &OtherMI) const
Definition: MachineInstrBuilder.h:213
llvm::MachineRegisterInfo::getRegClass
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
Definition: MachineRegisterInfo.h:647
llvm::AMDGPUSubtarget::getWavefrontSize
unsigned getWavefrontSize() const
Definition: AMDGPUSubtarget.h:200
llvm::SIRegisterInfo::opCanUseLiteralConstant
bool opCanUseLiteralConstant(unsigned OpType) const
Definition: SIRegisterInfo.cpp:2791
llvm::SIRegisterInfo::isFrameOffsetLegal
bool isFrameOffsetLegal(const MachineInstr *MI, Register BaseReg, int64_t Offset) const override
Definition: SIRegisterInfo.cpp:906
llvm::SIRegisterInfo::getBaseRegister
Register getBaseRegister() const
Definition: SIRegisterInfo.cpp:511
llvm::SIRegisterInfo::eliminateFrameIndex
bool eliminateFrameIndex(MachineBasicBlock::iterator MI, int SPAdj, unsigned FIOperandNum, RegScavenger *RS) const override
Definition: SIRegisterInfo.cpp:1964
llvm::MachineInstrBuilder::addFrameIndex
const MachineInstrBuilder & addFrameIndex(int Idx) const
Definition: MachineInstrBuilder.h:152
llvm::AMDGPU::getFlatScratchInstSVfromSVS
LLVM_READONLY int getFlatScratchInstSVfromSVS(uint16_t Opcode)
llvm::cl::opt< bool >
llvm::SIRegisterInfo::getAllVGPRRegMask
const uint32_t * getAllVGPRRegMask() const
Definition: SIRegisterInfo.cpp:513
llvm::AMDGPU::getRegBitWidth
unsigned getRegBitWidth(unsigned RCID)
Get the size in bits of a register from the register class RC.
Definition: AMDGPUBaseInfo.cpp:2095
llvm::SIMachineFunctionInfo::getVGPRSpillAGPRs
ArrayRef< MCPhysReg > getVGPRSpillAGPRs() const
Definition: SIMachineFunctionInfo.h:576
AMDGPURegisterBankInfo.h
llvm::SGPRSpillBuilder::SplitParts
ArrayRef< int16_t > SplitParts
Definition: SIRegisterInfo.cpp:82
AMDGPUMCTargetDesc.h
llvm::MachineOperand::setIsDead
void setIsDead(bool Val=true)
Definition: MachineOperand.h:515
llvm::RegState::Undef
@ Undef
Value of the register doesn't matter.
Definition: MachineInstrBuilder.h:52
llvm::SIRegisterInfo::shouldRewriteCopySrc
bool shouldRewriteCopySrc(const TargetRegisterClass *DefRC, unsigned DefSubReg, const TargetRegisterClass *SrcRC, unsigned SrcSubReg) const override
Definition: SIRegisterInfo.cpp:2767
llvm::SIRegisterInfo::shouldRealignStack
bool shouldRealignStack(const MachineFunction &MF) const override
Definition: SIRegisterInfo.cpp:725
llvm::MachineInstr
Representation of each machine instruction.
Definition: MachineInstr.h:66
llvm::MachineInstrBuilder
Definition: MachineInstrBuilder.h:69
llvm::SIRegisterInfo::getRegAsmName
StringRef getRegAsmName(MCRegister Reg) const override
Definition: SIRegisterInfo.cpp:2432
LiveIntervals.h
llvm::MachineInstr::ReloadReuse
@ ReloadReuse
Definition: MachineInstr.h:77
llvm::SIRegisterInfo::isVGPRClass
static bool isVGPRClass(const TargetRegisterClass *RC)
Definition: SIRegisterInfo.h:202
llvm::Function::getCallingConv
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
Definition: Function.h:238
llvm::SGPRSpillBuilder::NumSubRegs
unsigned NumSubRegs
Definition: SIRegisterInfo.cpp:83
llvm::LiveRange
This class represents the liveness of a register, stack slot, etc.
Definition: LiveInterval.h:157
llvm::ARM_MB::ST
@ ST
Definition: ARMBaseInfo.h:73
llvm::SIRegisterInfo::requiresFrameIndexScavenging
bool requiresFrameIndexScavenging(const MachineFunction &MF) const override
Definition: SIRegisterInfo.cpp:749
llvm::SlotIndexes::replaceMachineInstrInMaps
SlotIndex replaceMachineInstrInMaps(MachineInstr &MI, MachineInstr &NewMI)
ReplaceMachineInstrInMaps - Replacing a machine instr with a new one in maps used by register allocat...
Definition: SlotIndexes.h:597
llvm::SIRegisterInfo::hasBasePointer
bool hasBasePointer(const MachineFunction &MF) const
Definition: SIRegisterInfo.cpp:504
llvm::PointerUnion::dyn_cast
T dyn_cast() const
Returns the current pointer if it is of the specified pointer type, otherwise returns null.
Definition: PointerUnion.h:162
llvm::LivePhysRegs::available
bool available(const MachineRegisterInfo &MRI, MCPhysReg Reg) const
Returns true if register Reg and no aliasing register is in the set.
Definition: LivePhysRegs.cpp:141
llvm::MachinePointerInfo
This class contains a discriminated union of information about pointers in memory operands,...
Definition: MachineMemOperand.h:39
llvm::SGPRSpillBuilder::PerVGPRData::VGPRLanes
int64_t VGPRLanes
Definition: SIRegisterInfo.cpp:76
llvm::numbers::e
constexpr double e
Definition: MathExtras.h:53
llvm::SIInstrInfo::isFLATScratch
static bool isFLATScratch(const MachineInstr &MI)
Definition: SIInstrInfo.h:541
llvm::SIRegisterInfo::getAllVectorRegMask
const uint32_t * getAllVectorRegMask() const
Definition: SIRegisterInfo.cpp:521
llvm::AMDGPU::OPERAND_SRC_FIRST
@ OPERAND_SRC_FIRST
Definition: SIDefines.h:203
llvm::GCNSubtarget::hasMFMAInlineLiteralBug
bool hasMFMAInlineLiteralBug() const
Definition: GCNSubtarget.h:960
llvm::SIRegisterInfo::isSGPRReg
bool isSGPRReg(const MachineRegisterInfo &MRI, Register Reg) const
Definition: SIRegisterInfo.cpp:2712
I
#define I(x, y, z)
Definition: MD5.cpp:58
llvm::MCPhysReg
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
Definition: MCRegister.h:21
llvm::RegScavenger
Definition: RegisterScavenging.h:34
llvm::MachineFrameInfo::getObjectAlign
Align getObjectAlign(int ObjectIdx) const
Return the alignment of the specified stack object.
Definition: MachineFrameInfo.h:484
llvm::AMDGPUMachineFunction::isEntryFunction
bool isEntryFunction() const
Definition: AMDGPUMachineFunction.h:80
llvm::SIRegisterInfo::isVGPR
bool isVGPR(const MachineRegisterInfo &MRI, Register Reg) const
Definition: SIRegisterInfo.cpp:2845
llvm::cl::init
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:447
llvm::SIMachineFunctionInfo::WWMReservedRegs
SmallSetVector< Register, 8 > WWMReservedRegs
Definition: SIMachineFunctionInfo.h:479
AMDGPUInstPrinter.h
llvm::SIRegisterInfo::getBoolRC
const TargetRegisterClass * getBoolRC() const
Definition: SIRegisterInfo.h:330
llvm::MachineRegisterInfo::isAllocatable
bool isAllocatable(MCRegister PhysReg) const
isAllocatable - Returns true when PhysReg belongs to an allocatable register class and it hasn't been...
Definition: MachineRegisterInfo.h:948
llvm::SIRegisterInfo::getRegClassForOperandReg
const TargetRegisterClass * getRegClassForOperandReg(const MachineRegisterInfo &MRI, const MachineOperand &MO) const
Definition: SIRegisterInfo.cpp:2839
llvm::SIRegisterInfo::SpilledReg::Lane
int Lane
Definition: SIRegisterInfo.h:56
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::SIRegisterInfo::restoreSGPR
bool restoreSGPR(MachineBasicBlock::iterator MI, int FI, RegScavenger *RS, SlotIndexes *Indexes=nullptr, LiveIntervals *LIS=nullptr, bool OnlyToVGPR=false) const
Definition: SIRegisterInfo.cpp:1784
llvm::SIRegisterInfo::getRegSplitParts
ArrayRef< int16_t > getRegSplitParts(const TargetRegisterClass *RC, unsigned EltSize) const
Definition: SIRegisterInfo.cpp:2817
llvm::MachineFunction::getFrameInfo
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
Definition: MachineFunction.h:673
llvm::SIMachineFunctionInfo::getScavengeFI
int getScavengeFI(MachineFrameInfo &MFI, const SIRegisterInfo &TRI)
Definition: SIMachineFunctionInfo.cpp:488
llvm::MachineBasicBlock::getParent
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
Definition: MachineBasicBlock.h:261
llvm::AMDGPUAS::PRIVATE_ADDRESS
@ PRIVATE_ADDRESS
Address space for private memory.
Definition: AMDGPU.h:377
llvm::GCNSubtarget::hasGFX90AInsts
bool hasGFX90AInsts() const
Definition: GCNSubtarget.h:1048
llvm::MachineInstrBuilder::addReg
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
Definition: MachineInstrBuilder.h:97
llvm::MachineOperand::getReg
Register getReg() const
getReg - Returns the register number.
Definition: MachineOperand.h:359
llvm::SIMachineFunctionInfo::addToSpilledSGPRs
void addToSpilledSGPRs(unsigned num)
Definition: SIMachineFunctionInfo.h:866
llvm::SIRegisterInfo::getAllAGPRRegMask
const uint32_t * getAllAGPRRegMask() const
Definition: SIRegisterInfo.cpp:517
llvm::RegScavenger::assignRegToScavengingIndex
void assignRegToScavengingIndex(int FI, Register Reg, MachineInstr *Restore=nullptr)
Record that Reg is in use at scavenging index FI.
Definition: RegisterScavenging.h:79
llvm::LiveIntervals::getInterval
LiveInterval & getInterval(Register Reg)
Definition: LiveIntervals.h:112
llvm::MachinePointerInfo::getWithOffset
MachinePointerInfo getWithOffset(int64_t O) const
Definition: MachineMemOperand.h:79
spillVGPRtoAGPR
static MachineInstrBuilder spillVGPRtoAGPR(const GCNSubtarget &ST, MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, int Index, unsigned Lane, unsigned ValueReg, bool IsKill)
Definition: SIRegisterInfo.cpp:1153
llvm::MachineRegisterInfo::getRegClassOrRegBank
const RegClassOrRegBank & getRegClassOrRegBank(Register Reg) const
Return the register bank or register class of Reg.
Definition: MachineRegisterInfo.h:681
llvm::MachineFunction
Definition: MachineFunction.h:257
llvm::AMDGPU::getFlatScratchInstSTfromSS
LLVM_READONLY int getFlatScratchInstSTfromSS(uint16_t Opcode)
llvm::size
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
Definition: STLExtras.h:1690
llvm::AMDGPU::CPol::SCC
@ SCC
Definition: SIDefines.h:307
llvm::SIRegisterInfo::getNoPreservedMask
const uint32_t * getNoPreservedMask() const override
Definition: SIRegisterInfo.cpp:431
getDebugLoc
static DebugLoc getDebugLoc(MachineBasicBlock::instr_iterator FirstMI, MachineBasicBlock::instr_iterator LastMI)
Return the first found DebugLoc that has a DILocation, given a range of instructions.
Definition: MachineInstrBundle.cpp:110
llvm::SIRegisterInfo::get32BitRegister
MCPhysReg get32BitRegister(MCPhysReg Reg) const
Definition: SIRegisterInfo.cpp:3044
llvm::ArrayRef< int16_t >
llvm::SIRegisterInfo::isVectorSuperClass
bool isVectorSuperClass(const TargetRegisterClass *RC) const
Definition: SIRegisterInfo.h:212
llvm::min
Expected< ExpressionValue > min(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
Definition: FileCheck.cpp:357
llvm::SGPRSpillBuilder::NotOpc
unsigned NotOpc
Definition: SIRegisterInfo.cpp:110
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
AMDGPU.h
llvm::MachineInstr::getOpcode
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
Definition: MachineInstr.h:516
llvm::SGPRSpillBuilder::TmpVGPR
Register TmpVGPR
Definition: SIRegisterInfo.cpp:90
llvm::SIRegisterInfo::isProperlyAlignedRC
bool isProperlyAlignedRC(const TargetRegisterClass &RC) const
Definition: SIRegisterInfo.cpp:3061
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:143
llvm::AMDGPUInstPrinter::getRegisterName
static const char * getRegisterName(unsigned RegNo)
llvm::RegState::Implicit
@ Implicit
Not emitted register (e.g. carry, or temporary result).
Definition: MachineInstrBuilder.h:46
getNumSubRegsForSpillOp
static unsigned getNumSubRegsForSpillOp(unsigned Op)
Definition: SIRegisterInfo.cpp:940
llvm::SGPRSpillBuilder::TmpVGPRLive
bool TmpVGPRLive
Definition: SIRegisterInfo.cpp:94
getParent
static const Function * getParent(const Value *V)
Definition: BasicAliasAnalysis.cpp:805
uint32_t
llvm::SGPRSpillBuilder::prepare
void prepare()
Definition: SIRegisterInfo.cpp:165
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition: AArch64SLSHardening.cpp:76
llvm::SIMachineFunctionInfo::getVGPRToAGPRSpill
MCPhysReg getVGPRToAGPRSpill(int FrameIndex, unsigned Lane) const
Definition: SIMachineFunctionInfo.h:580
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
SubRegFromChannelTableWidthMap
static const std::array< unsigned, 17 > SubRegFromChannelTableWidthMap
Definition: SIRegisterInfo.cpp:45
CC
auto CC
Definition: RISCVRedundantCopyElimination.cpp:79
llvm::SIRegisterInfo::getCalleeSavedRegsViaCopy
const MCPhysReg * getCalleeSavedRegsViaCopy(const MachineFunction *MF) const
Definition: SIRegisterInfo.cpp:411
llvm::SIMachineFunctionInfo::getScratchRSrcReg
Register getScratchRSrcReg() const
Returns the physical register reserved for use as the resource descriptor for scratch accesses.
Definition: SIMachineFunctionInfo.h:787
llvm::once_flag
std::once_flag once_flag
Definition: Threading.h:56
llvm::SIInstrInfo::isMUBUF
static bool isMUBUF(const MachineInstr &MI)
Definition: SIInstrInfo.h:465
llvm::SIRegisterInfo::resolveFrameIndex
void resolveFrameIndex(MachineInstr &MI, Register BaseReg, int64_t Offset) const override
Definition: SIRegisterInfo.cpp:857
llvm::SIRegisterInfo::buildSpillLoadStore
void buildSpillLoadStore(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, const DebugLoc &DL, unsigned LoadStoreOp, int Index, Register ValueReg, bool ValueIsKill, MCRegister ScratchOffsetReg, int64_t InstrOffset, MachineMemOperand *MMO, RegScavenger *RS, LivePhysRegs *LiveRegs=nullptr) const
Definition: SIRegisterInfo.cpp:1270
llvm::SGPRSpillBuilder::Index
int Index
Definition: SIRegisterInfo.cpp:98
llvm::MachineInstrBuilder::getInstr
MachineInstr * getInstr() const
If conversion operators fail, use this method to get the MachineInstr explicitly.
Definition: MachineInstrBuilder.h:89
llvm::SGPRSpillBuilder
Definition: SIRegisterInfo.cpp:72
llvm::SGPRSpillBuilder::MBB
MachineBasicBlock * MBB
Definition: SIRegisterInfo.cpp:102
llvm::MachineMemOperand::MOLoad
@ MOLoad
The memory access reads data.
Definition: MachineMemOperand.h:134
MRI
unsigned const MachineRegisterInfo * MRI
Definition: AArch64AdvSIMDScalarPass.cpp:105
llvm::PointerUnion
A discriminated union of two or more pointer types, with the discriminator in the low bit of the poin...
Definition: PointerUnion.h:112
llvm::Register
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
llvm::MachineOperand::getSubReg
unsigned getSubReg() const
Definition: MachineOperand.h:364
llvm::GCNSubtarget::hasFlatScratchSTMode
bool hasFlatScratchSTMode() const
Definition: GCNSubtarget.h:586
llvm::SIRegisterInfo::getRegPressureSetLimit
unsigned getRegPressureSetLimit(const MachineFunction &MF, unsigned Idx) const override
Definition: SIRegisterInfo.cpp:2900
llvm::MachineFrameInfo::hasCalls
bool hasCalls() const
Return true if the current function has any function calls.
Definition: MachineFrameInfo.h:613
llvm::SIInstrInfo::isLegalMUBUFImmOffset
static bool isLegalMUBUFImmOffset(unsigned Imm)
Definition: SIInstrInfo.h:1119
llvm::SIRegisterInfo::getAllSGPR32
ArrayRef< MCPhysReg > getAllSGPR32(const MachineFunction &MF) const
Return all SGPR32 which satisfy the waves per execution unit requirement of the subtarget.
Definition: SIRegisterInfo.cpp:3108
llvm::SIRegisterInfo::getRegClassForTypeOnBank
const TargetRegisterClass * getRegClassForTypeOnBank(LLT Ty, const RegisterBank &Bank) const
Definition: SIRegisterInfo.h:322
getRegClass
static const TargetRegisterClass * getRegClass(const MachineInstr &MI, Register Reg)
Definition: AArch64InstrInfo.cpp:3228
MBB
MachineBasicBlock & MBB
Definition: AArch64SLSHardening.cpp:74
llvm::SGPRSpillBuilder::RS
RegScavenger * RS
Definition: SIRegisterInfo.cpp:101
llvm::AMDGPU::OPERAND_SRC_LAST
@ OPERAND_SRC_LAST
Definition: SIDefines.h:204
llvm::SIInstrFlags::FlatScratch
@ FlatScratch
Definition: SIDefines.h:123
llvm::MachineRegisterInfo::getMaxLaneMaskForVReg
LaneBitmask getMaxLaneMaskForVReg(Register Reg) const
Returns a mask covering all bits that can appear in lane masks of subregisters of the virtual registe...
Definition: MachineRegisterInfo.cpp:495
llvm::call_once
void call_once(once_flag &flag, Function &&F, Args &&... ArgList)
Execute the function specified as a parameter once.
Definition: Threading.h:86
llvm::RegState::ImplicitDefine
@ ImplicitDefine
Definition: MachineInstrBuilder.h:63
llvm::MachineFunction::getFunction
Function & getFunction()
Return the LLVM function that this machine code represents.
Definition: MachineFunction.h:623
llvm::SGPRSpillBuilder::PerVGPRData::NumVGPRs
unsigned NumVGPRs
Definition: SIRegisterInfo.cpp:75
uint16_t
llvm::SGPRSpillBuilder::MI
MachineBasicBlock::iterator MI
Definition: SIRegisterInfo.cpp:81
llvm::AMDGPU::SendMsg::Op
Op
Definition: SIDefines.h:348
AMDGPUGenRegisterInfo
llvm::MachineInstr::setAsmPrinterFlag
void setAsmPrinterFlag(uint8_t Flag)
Set a flag for the AsmPrinter.
Definition: MachineInstr.h:342
MachineFrameInfo.h
getAnyVectorSuperClassForBitWidth
static const TargetRegisterClass * getAnyVectorSuperClassForBitWidth(unsigned BitWidth)
Definition: SIRegisterInfo.cpp:2555
llvm::RegScavenger::setRegUsed
void setRegUsed(Register Reg, LaneBitmask LaneMask=LaneBitmask::getAll())
Tell the scavenger a register is used.
Definition: RegisterScavenging.cpp:51
llvm::RegState::Kill
@ Kill
The last use of a register.
Definition: MachineInstrBuilder.h:48
llvm::BitWidth
constexpr unsigned BitWidth
Definition: BitmaskEnum.h:147
llvm::SGPRSpillBuilder::readWriteTmpVGPR
void readWriteTmpVGPR(unsigned Offset, bool IsLoad)
Definition: SIRegisterInfo.cpp:287
llvm::SIMachineFunctionInfo::getAGPRSpillVGPRs
ArrayRef< MCPhysReg > getAGPRSpillVGPRs() const
Definition: SIMachineFunctionInfo.h:572
llvm::LiveIntervals
Definition: LiveIntervals.h:53
llvm::VNInfo
VNInfo - Value Number Information.
Definition: LiveInterval.h:53
llvm::LiveRange::getVNInfoAt
VNInfo * getVNInfoAt(SlotIndex Idx) const
getVNInfoAt - Return the VNInfo that is live at Idx, or NULL.
Definition: LiveInterval.h:421
llvm::TargetRegisterClass::MC
const MCRegisterClass * MC
Definition: TargetRegisterInfo.h:53
llvm::TargetStackID::SGPRSpill
@ SGPRSpill
Definition: TargetFrameLowering.h:29
llvm::MachineOperand::isImm
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
Definition: MachineOperand.h:322
llvm::MachineMemOperand::MOStore
@ MOStore
The memory access writes data.
Definition: MachineMemOperand.h:136
llvm::AMDGPU::Hwreg::Width
Width
Definition: SIDefines.h:439
llvm::SGPRSpillBuilder::SuperReg
Register SuperReg
Definition: SIRegisterInfo.cpp:80
llvm::AMDGPU::OPERAND_REG_IMM_FIRST
@ OPERAND_REG_IMM_FIRST
Definition: SIDefines.h:194
llvm::makeArrayRef
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:475
llvm::SGPRSpillBuilder::MFI
SIMachineFunctionInfo & MFI
Definition: SIRegisterInfo.cpp:104
llvm::SIInstrInfo
Definition: SIInstrInfo.h:44
llvm::GCNSubtarget::enableFlatScratch
bool enableFlatScratch() const
Definition: GCNSubtarget.h:596
llvm::AMDGPU::isInlinableLiteral32
bool isInlinableLiteral32(int32_t Literal, bool HasInv2Pi)
Definition: AMDGPUBaseInfo.cpp:2228
llvm::SIRegisterInfo::requiresRegisterScavenging
bool requiresRegisterScavenging(const MachineFunction &Fn) const override
Definition: SIRegisterInfo.cpp:738
llvm::SIRegisterInfo::getConstrainedRegClassForOperand
const TargetRegisterClass * getConstrainedRegClassForOperand(const MachineOperand &MO, const MachineRegisterInfo &MRI) const override
Definition: SIRegisterInfo.cpp:2948
llvm::MCRegUnitIterator
Definition: MCRegisterInfo.h:680
llvm::SGPRSpillBuilder::restore
void restore()
Definition: SIRegisterInfo.cpp:246
llvm::getKillRegState
unsigned getKillRegState(bool B)
Definition: MachineInstrBuilder.h:546
llvm::MachineFrameInfo
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
Definition: MachineFrameInfo.h:106
llvm::SGPRSpillBuilder::DL
const DebugLoc & DL
Definition: SIRegisterInfo.cpp:85
llvm::BuildMI
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
Definition: MachineInstrBuilder.h:357
llvm::GCNSubtarget::getConstantBusLimit
unsigned getConstantBusLimit(unsigned Opcode) const
Definition: AMDGPUSubtarget.cpp:184
llvm::MachinePointerInfo::getFixedStack
static MachinePointerInfo getFixedStack(MachineFunction &MF, int FI, int64_t Offset=0)
Return a MachinePointerInfo record that refers to the specified FrameIndex.
Definition: MachineOperand.cpp:1018
llvm::MachineBasicBlock::begin
iterator begin()
Definition: MachineBasicBlock.h:305
llvm::MachineRegisterInfo::getType
LLT getType(Register Reg) const
Get the low-level type of Reg or LLT{} if Reg is not a generic (target independent) virtual register.
Definition: MachineRegisterInfo.h:745
llvm::SGPRSpillBuilder::PerVGPRData::PerVGPR
unsigned PerVGPR
Definition: SIRegisterInfo.cpp:74
llvm::CallingConv::Fast
@ Fast
Attempts to make calls as fast as possible (e.g.
Definition: CallingConv.h:41
llvm::Register::isValid
bool isValid() const
Definition: Register.h:126
llvm::MCRegisterInfo::DiffListIterator::isValid
bool isValid() const
isValid - returns true if this iterator is not yet at the end.
Definition: MCRegisterInfo.h:224
llvm::MachineOperand::setReg
void setReg(Register Reg)
Change the register this operand corresponds to.
Definition: MachineOperand.cpp:55
llvm::SIMachineFunctionInfo
This class keeps track of the SPI_SP_INPUT_ADDR config register, which tells the hardware which inter...
Definition: SIMachineFunctionInfo.h:351
llvm::PseudoProbeAttributes::Reserved
@ Reserved
llvm::LiveInterval::hasSubRanges
bool hasSubRanges() const
Returns true if subregister liveness information is available.
Definition: LiveInterval.h:803
llvm::ArrayRef::size
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:164
llvm::SIRegisterInfo::findUnusedRegister
MCRegister findUnusedRegister(const MachineRegisterInfo &MRI, const TargetRegisterClass *RC, const MachineFunction &MF, bool ReserveHighestVGPR=false) const
Returns a lowest register that is not used at any point in the function.
Definition: SIRegisterInfo.cpp:2801
llvm::CallingConv::AMDGPU_Gfx
@ AMDGPU_Gfx
Used for AMD graphics targets.
Definition: CallingConv.h:233
llvm::SGPRSpillBuilder::MovOpc
unsigned MovOpc
Definition: SIRegisterInfo.cpp:109
llvm::MipsISD::Ins
@ Ins
Definition: MipsISelLowering.h:160
llvm::reverse
auto reverse(ContainerTy &&C)
Definition: STLExtras.h:485
llvm::SIRegisterInfo::getCompatibleSubRegClass
const TargetRegisterClass * getCompatibleSubRegClass(const TargetRegisterClass *SuperRC, const TargetRegisterClass *SubRC, unsigned SubIdx) const
Returns a register class which is compatible with SuperRC, such that a subregister exists with class ...
Definition: SIRegisterInfo.cpp:2749
llvm::SIRegisterInfo::getAGPRClassForBitWidth
const LLVM_READONLY TargetRegisterClass * getAGPRClassForBitWidth(unsigned BitWidth) const
Definition: SIRegisterInfo.cpp:2545
llvm::TargetRegisterClass::hasSubClassEq
bool hasSubClassEq(const TargetRegisterClass *RC) const
Returns true if RC is a sub-class of or equal to this class.
Definition: TargetRegisterInfo.h:130
llvm::AMDGPU::OPERAND_REG_INLINE_AC_FIRST
@ OPERAND_REG_INLINE_AC_FIRST
Definition: SIDefines.h:200
getOffsetMUBUFLoad
static int getOffsetMUBUFLoad(unsigned Opc)
Definition: SIRegisterInfo.cpp:1060
llvm::SIMachineFunctionInfo::addToSpilledVGPRs
void addToSpilledVGPRs(unsigned num)
Definition: SIMachineFunctionInfo.h:870
llvm::SGPRSpillBuilder::MF
MachineFunction & MF
Definition: SIRegisterInfo.cpp:103
getAnyAGPRClassForBitWidth
static const TargetRegisterClass * getAnyAGPRClassForBitWidth(unsigned BitWidth)
Definition: SIRegisterInfo.cpp:2497
llvm::LiveIntervals::hasInterval
bool hasInterval(Register Reg) const
Definition: LiveIntervals.h:123
llvm::DebugLoc
A debug info location.
Definition: DebugLoc.h:33
llvm::cl::desc
Definition: CommandLine.h:413
llvm::SIRegisterInfo::opCanUseInlineConstant
bool opCanUseInlineConstant(unsigned OpType) const
Definition: SIRegisterInfo.cpp:2758
llvm::SIRegisterInfo::shouldCoalesce
bool shouldCoalesce(MachineInstr *MI, const TargetRegisterClass *SrcRC, unsigned SubReg, const TargetRegisterClass *DstRC, unsigned DstSubReg, const TargetRegisterClass *NewRC, LiveIntervals &LIS) const override
Definition: SIRegisterInfo.cpp:2860
RegisterScavenging.h
llvm::MachineDominatorTree
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
Definition: MachineDominators.h:51
llvm::SGPRSpillBuilder::SGPRSpillBuilder
SGPRSpillBuilder(const SIRegisterInfo &TRI, const SIInstrInfo &TII, bool IsWave32, MachineBasicBlock::iterator MI, int Index, RegScavenger *RS)
Definition: SIRegisterInfo.cpp:112
llvm::AMDGPUSubtarget::getWavefrontSizeLog2
unsigned getWavefrontSizeLog2() const
Definition: AMDGPUSubtarget.h:204
llvm::SIRegisterInfo::spillEmergencySGPR
bool spillEmergencySGPR(MachineBasicBlock::iterator MI, MachineBasicBlock &RestoreMBB, Register SGPR, RegScavenger *RS) const
Definition: SIRegisterInfo.cpp:1861
llvm::MachineInstrBundleIterator< MachineInstr >
getFlatScratchSpillOpcode
static unsigned getFlatScratchSpillOpcode(const SIInstrInfo *TII, unsigned LoadStoreOp, unsigned EltSize)
Definition: SIRegisterInfo.cpp:1233
llvm::MachineMemOperand::getFlags
Flags getFlags() const
Return the raw flags of the source value,.
Definition: MachineMemOperand.h:219
llvm::SIRegisterInfo::getEquivalentSGPRClass
const TargetRegisterClass * getEquivalentSGPRClass(const TargetRegisterClass *VRC) const
Definition: SIRegisterInfo.cpp:2739
SIRegisterInfo.h
llvm::MachineBasicBlock::end
iterator end()
Definition: MachineBasicBlock.h:307
SubReg
unsigned SubReg
Definition: AArch64AdvSIMDScalarPass.cpp:104
llvm::SIRegisterInfo::reservedPrivateSegmentBufferReg
MCRegister reservedPrivateSegmentBufferReg(const MachineFunction &MF) const
Return the end register initially reserved for the scratch buffer in case spilling is needed.
Definition: SIRegisterInfo.cpp:538
llvm::SIRegisterInfo::getPhysRegClass
const TargetRegisterClass * getPhysRegClass(MCRegister Reg) const
Return the 'base' register class for this register.
Definition: SIRegisterInfo.cpp:2644
llvm::SIRegisterInfo::getReservedRegs
BitVector getReservedRegs(const MachineFunction &MF) const override
Definition: SIRegisterInfo.cpp:545
llvm::SIMachineFunctionInfo::getFrameOffsetReg
Register getFrameOffsetReg() const
Definition: SIMachineFunctionInfo.h:796
llvm::SIRegisterInfo::getPointerRegClass
const TargetRegisterClass * getPointerRegClass(const MachineFunction &MF, unsigned Kind=0) const override
Definition: SIRegisterInfo.cpp:922
llvm::MCRegAliasIterator
MCRegAliasIterator enumerates all registers aliasing Reg.
Definition: MCRegisterInfo.h:788
EnableSpillSGPRToVGPR
static cl::opt< bool > EnableSpillSGPRToVGPR("amdgpu-spill-sgpr-to-vgpr", cl::desc("Enable spilling VGPRs to SGPRs"), cl::ReallyHidden, cl::init(true))
llvm::Use
A Use represents the edge between a Value definition and its users.
Definition: Use.h:43
llvm::LiveIntervals::getRegUnit
LiveRange & getRegUnit(unsigned Unit)
Return the live range for register unit Unit.
Definition: LiveIntervals.h:387
llvm::GCNSubtarget::hasMAIInsts
bool hasMAIInsts() const
Definition: GCNSubtarget.h:730
MachineDominators.h
llvm::MCRegister
Wrapper class representing physical registers. Should be passed by value.
Definition: MCRegister.h:24
llvm::SIRegisterInfo::getSGPRClassForBitWidth
static const LLVM_READONLY TargetRegisterClass * getSGPRClassForBitWidth(unsigned BitWidth)
Definition: SIRegisterInfo.cpp:2614
LivePhysRegs.h
llvm::LiveInterval::subranges
iterator_range< subrange_iterator > subranges()
Definition: LiveInterval.h:775