LLVM 22.0.0git
SILowerSGPRSpills.cpp
Go to the documentation of this file.
1//===-- SILowerSGPRSPills.cpp ---------------------------------------------===//
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// Handle SGPR spills. This pass takes the place of PrologEpilogInserter for all
10// SGPR spills, so must insert CSR SGPR spills as well as expand them.
11//
12// This pass must never create new SGPR virtual registers.
13//
14// FIXME: Must stop RegScavenger spills in later passes.
15//
16//===----------------------------------------------------------------------===//
17
18#include "SILowerSGPRSpills.h"
19#include "AMDGPU.h"
20#include "GCNSubtarget.h"
28
29using namespace llvm;
30
31#define DEBUG_TYPE "si-lower-sgpr-spills"
32
34
35namespace {
36
37static cl::opt<unsigned> MaxNumVGPRsForWwmAllocation(
38 "amdgpu-num-vgprs-for-wwm-alloc",
39 cl::desc("Max num VGPRs for whole-wave register allocation."),
41
42class SILowerSGPRSpills {
43private:
44 const SIRegisterInfo *TRI = nullptr;
45 const SIInstrInfo *TII = nullptr;
46 LiveIntervals *LIS = nullptr;
47 SlotIndexes *Indexes = nullptr;
48 MachineDominatorTree *MDT = nullptr;
49
50 // Save and Restore blocks of the current function. Typically there is a
51 // single save block, unless Windows EH funclets are involved.
52 MBBVector SaveBlocks;
53 MBBVector RestoreBlocks;
54
55public:
56 SILowerSGPRSpills(LiveIntervals *LIS, SlotIndexes *Indexes,
58 : LIS(LIS), Indexes(Indexes), MDT(MDT) {}
59 bool run(MachineFunction &MF);
60 void calculateSaveRestoreBlocks(MachineFunction &MF);
61 bool spillCalleeSavedRegs(MachineFunction &MF,
62 SmallVectorImpl<int> &CalleeSavedFIs);
63 void updateLaneVGPRDomInstr(
66 void determineRegsForWWMAllocation(MachineFunction &MF, BitVector &RegMask);
67};
68
69class SILowerSGPRSpillsLegacy : public MachineFunctionPass {
70public:
71 static char ID;
72
73 SILowerSGPRSpillsLegacy() : MachineFunctionPass(ID) {}
74
75 bool runOnMachineFunction(MachineFunction &MF) override;
76
77 void getAnalysisUsage(AnalysisUsage &AU) const override {
79 AU.setPreservesAll();
81 }
82
84 // SILowerSGPRSpills introduces new Virtual VGPRs for spilling SGPRs.
85 return MachineFunctionProperties().setIsSSA().setNoVRegs();
86 }
87};
88
89} // end anonymous namespace
90
91char SILowerSGPRSpillsLegacy::ID = 0;
92
93INITIALIZE_PASS_BEGIN(SILowerSGPRSpillsLegacy, DEBUG_TYPE,
94 "SI lower SGPR spill instructions", false, false)
98INITIALIZE_PASS_END(SILowerSGPRSpillsLegacy, DEBUG_TYPE,
99 "SI lower SGPR spill instructions", false, false)
100
101char &llvm::SILowerSGPRSpillsLegacyID = SILowerSGPRSpillsLegacy::ID;
102
105 for (MCRegAliasIterator R(Reg, TRI, true); R.isValid(); ++R) {
106 if (MBB.isLiveIn(*R)) {
107 return true;
108 }
109 }
110 return false;
111}
112
113/// Insert spill code for the callee-saved registers used in the function.
114static void insertCSRSaves(MachineBasicBlock &SaveBlock,
116 LiveIntervals *LIS) {
117 MachineFunction &MF = *SaveBlock.getParent();
121 const GCNSubtarget &ST = MF.getSubtarget<GCNSubtarget>();
122 const SIRegisterInfo *RI = ST.getRegisterInfo();
123
124 MachineBasicBlock::iterator I = SaveBlock.begin();
125 if (!TFI->spillCalleeSavedRegisters(SaveBlock, I, CSI, TRI)) {
126 for (const CalleeSavedInfo &CS : CSI) {
127 // Insert the spill to the stack frame.
128 MCRegister Reg = CS.getReg();
129
130 MachineInstrSpan MIS(I, &SaveBlock);
131 const TargetRegisterClass *RC = TRI->getMinimalPhysRegClass(
132 Reg, Reg == RI->getReturnAddressReg(MF) ? MVT::i64 : MVT::i32);
133
134 // If this value was already livein, we probably have a direct use of the
135 // incoming register value, so don't kill at the spill point. This happens
136 // since we pass some special inputs (workgroup IDs) in the callee saved
137 // range.
138 const bool IsLiveIn = isLiveIntoMBB(Reg, SaveBlock, TRI);
139 TII.storeRegToStackSlot(SaveBlock, I, Reg, !IsLiveIn, CS.getFrameIdx(),
140 RC, TRI, Register());
141
142 if (Indexes) {
143 assert(std::distance(MIS.begin(), I) == 1);
144 MachineInstr &Inst = *std::prev(I);
145 Indexes->insertMachineInstrInMaps(Inst);
146 }
147
148 if (LIS)
150 }
151 } else {
152 // TFI doesn't update Indexes and LIS, so we have to do it separately.
153 if (Indexes)
154 Indexes->repairIndexesInRange(&SaveBlock, SaveBlock.begin(), I);
155
156 if (LIS)
157 for (const CalleeSavedInfo &CS : CSI)
158 LIS->removeAllRegUnitsForPhysReg(CS.getReg());
159 }
160}
161
162/// Insert restore code for the callee-saved registers used in the function.
163static void insertCSRRestores(MachineBasicBlock &RestoreBlock,
165 SlotIndexes *Indexes, LiveIntervals *LIS) {
166 MachineFunction &MF = *RestoreBlock.getParent();
170 // Restore all registers immediately before the return and any
171 // terminators that precede it.
173 const MachineBasicBlock::iterator BeforeRestoresI =
174 I == RestoreBlock.begin() ? I : std::prev(I);
175
176 // FIXME: Just emit the readlane/writelane directly
177 if (!TFI->restoreCalleeSavedRegisters(RestoreBlock, I, CSI, TRI)) {
178 for (const CalleeSavedInfo &CI : reverse(CSI)) {
179 // Insert in reverse order. loadRegFromStackSlot can insert
180 // multiple instructions.
181 TFI->restoreCalleeSavedRegister(RestoreBlock, I, CI, &TII, TRI);
182
183 if (Indexes) {
184 MachineInstr &Inst = *std::prev(I);
185 Indexes->insertMachineInstrInMaps(Inst);
186 }
187
188 if (LIS)
189 LIS->removeAllRegUnitsForPhysReg(CI.getReg());
190 }
191 } else {
192 // TFI doesn't update Indexes and LIS, so we have to do it separately.
193 if (Indexes)
194 Indexes->repairIndexesInRange(&RestoreBlock, BeforeRestoresI,
195 RestoreBlock.getFirstTerminator());
196
197 if (LIS)
198 for (const CalleeSavedInfo &CS : CSI)
199 LIS->removeAllRegUnitsForPhysReg(CS.getReg());
200 }
201}
202
203/// Compute the sets of entry and return blocks for saving and restoring
204/// callee-saved registers, and placing prolog and epilog code.
205void SILowerSGPRSpills::calculateSaveRestoreBlocks(MachineFunction &MF) {
206 const MachineFrameInfo &MFI = MF.getFrameInfo();
207
208 // Even when we do not change any CSR, we still want to insert the
209 // prologue and epilogue of the function.
210 // So set the save points for those.
211
212 // Use the points found by shrink-wrapping, if any.
213 if (!MFI.getSavePoints().empty()) {
214 assert(MFI.getSavePoints().size() == 1 &&
215 "Multiple save points not yet supported!");
216 SaveBlocks.push_back(MFI.getSavePoints().front());
217 assert(MFI.getRestorePoints().size() == 1 &&
218 "Multiple restore points not yet supported!");
219 MachineBasicBlock *RestoreBlock = MFI.getRestorePoints().front();
220 // If RestoreBlock does not have any successor and is not a return block
221 // then the end point is unreachable and we do not need to insert any
222 // epilogue.
223 if (!RestoreBlock->succ_empty() || RestoreBlock->isReturnBlock())
224 RestoreBlocks.push_back(RestoreBlock);
225 return;
226 }
227
228 // Save refs to entry and return blocks.
229 SaveBlocks.push_back(&MF.front());
230 for (MachineBasicBlock &MBB : MF) {
231 if (MBB.isEHFuncletEntry())
232 SaveBlocks.push_back(&MBB);
233 if (MBB.isReturnBlock())
234 RestoreBlocks.push_back(&MBB);
235 }
236}
237
238// TODO: To support shrink wrapping, this would need to copy
239// PrologEpilogInserter's updateLiveness.
241 MachineBasicBlock &EntryBB = MF.front();
242
243 for (const CalleeSavedInfo &CSIReg : CSI)
244 EntryBB.addLiveIn(CSIReg.getReg());
245 EntryBB.sortUniqueLiveIns();
246}
247
248bool SILowerSGPRSpills::spillCalleeSavedRegs(
249 MachineFunction &MF, SmallVectorImpl<int> &CalleeSavedFIs) {
251 const Function &F = MF.getFunction();
253 const SIFrameLowering *TFI = ST.getFrameLowering();
254 MachineFrameInfo &MFI = MF.getFrameInfo();
255 RegScavenger *RS = nullptr;
256
257 // Determine which of the registers in the callee save list should be saved.
258 BitVector SavedRegs;
259 TFI->determineCalleeSavesSGPR(MF, SavedRegs, RS);
260
261 // Add the code to save and restore the callee saved registers.
262 if (!F.hasFnAttribute(Attribute::Naked)) {
263 // FIXME: This is a lie. The CalleeSavedInfo is incomplete, but this is
264 // necessary for verifier liveness checks.
265 MFI.setCalleeSavedInfoValid(true);
266
267 std::vector<CalleeSavedInfo> CSI;
268 const MCPhysReg *CSRegs = MRI.getCalleeSavedRegs();
269
270 for (unsigned I = 0; CSRegs[I]; ++I) {
271 MCRegister Reg = CSRegs[I];
272
273 if (SavedRegs.test(Reg)) {
274 const TargetRegisterClass *RC =
275 TRI->getMinimalPhysRegClass(Reg, MVT::i32);
276 int JunkFI = MFI.CreateStackObject(TRI->getSpillSize(*RC),
277 TRI->getSpillAlign(*RC), true);
278
279 CSI.emplace_back(Reg, JunkFI);
280 CalleeSavedFIs.push_back(JunkFI);
281 }
282 }
283
284 if (!CSI.empty()) {
285 for (MachineBasicBlock *SaveBlock : SaveBlocks)
286 insertCSRSaves(*SaveBlock, CSI, Indexes, LIS);
287
288 // Add live ins to save blocks.
289 assert(SaveBlocks.size() == 1 && "shrink wrapping not fully implemented");
290 updateLiveness(MF, CSI);
291
292 for (MachineBasicBlock *RestoreBlock : RestoreBlocks)
293 insertCSRRestores(*RestoreBlock, CSI, Indexes, LIS);
294 return true;
295 }
296 }
297
298 return false;
299}
300
301void SILowerSGPRSpills::updateLaneVGPRDomInstr(
304 // For the Def of a virtual LaneVPGR to dominate all its uses, we should
305 // insert an IMPLICIT_DEF before the dominating spill. Switching to a
306 // depth first order doesn't really help since the machine function can be in
307 // the unstructured control flow post-SSA. For each virtual register, hence
308 // finding the common dominator to get either the dominating spill or a block
309 // dominating all spills.
310 SIMachineFunctionInfo *FuncInfo =
313 FuncInfo->getSGPRSpillToVirtualVGPRLanes(FI);
314 Register PrevLaneVGPR;
315 for (auto &Spill : VGPRSpills) {
316 if (PrevLaneVGPR == Spill.VGPR)
317 continue;
318
319 PrevLaneVGPR = Spill.VGPR;
320 auto I = LaneVGPRDomInstr.find(Spill.VGPR);
321 if (Spill.Lane == 0 && I == LaneVGPRDomInstr.end()) {
322 // Initially add the spill instruction itself for Insertion point.
323 LaneVGPRDomInstr[Spill.VGPR] = InsertPt;
324 } else {
325 assert(I != LaneVGPRDomInstr.end());
326 auto PrevInsertPt = I->second;
327 MachineBasicBlock *DomMBB = PrevInsertPt->getParent();
328 if (DomMBB == MBB) {
329 // The insertion point earlier selected in a predecessor block whose
330 // spills are currently being lowered. The earlier InsertPt would be
331 // the one just before the block terminator and it should be changed
332 // if we insert any new spill in it.
333 if (MDT->dominates(&*InsertPt, &*PrevInsertPt))
334 I->second = InsertPt;
335
336 continue;
337 }
338
339 // Find the common dominator block between PrevInsertPt and the
340 // current spill.
341 DomMBB = MDT->findNearestCommonDominator(DomMBB, MBB);
342 if (DomMBB == MBB)
343 I->second = InsertPt;
344 else if (DomMBB != PrevInsertPt->getParent())
345 I->second = &(*DomMBB->getFirstTerminator());
346 }
347 }
348}
349
350void SILowerSGPRSpills::determineRegsForWWMAllocation(MachineFunction &MF,
351 BitVector &RegMask) {
352 // Determine an optimal number of VGPRs for WWM allocation. The complement
353 // list will be available for allocating other VGPR virtual registers.
356 BitVector ReservedRegs = TRI->getReservedRegs(MF);
357 BitVector NonWwmAllocMask(TRI->getNumRegs());
359
360 // FIXME: MaxNumVGPRsForWwmAllocation might need to be adjusted in the future
361 // to have a balanced allocation between WWM values and per-thread vector
362 // register operands.
363 unsigned NumRegs = MaxNumVGPRsForWwmAllocation;
364 NumRegs =
365 std::min(static_cast<unsigned>(MFI->getSGPRSpillVGPRs().size()), NumRegs);
366
367 auto [MaxNumVGPRs, MaxNumAGPRs] = ST.getMaxNumVectorRegs(MF.getFunction());
368 // Try to use the highest available registers for now. Later after
369 // vgpr-regalloc, they can be shifted to the lowest range.
370 unsigned I = 0;
371 for (unsigned Reg = AMDGPU::VGPR0 + MaxNumVGPRs - 1;
372 (I < NumRegs) && (Reg >= AMDGPU::VGPR0); --Reg) {
373 if (!ReservedRegs.test(Reg) &&
374 !MRI.isPhysRegUsed(Reg, /*SkipRegMaskTest=*/true)) {
375 TRI->markSuperRegs(RegMask, Reg);
376 ++I;
377 }
378 }
379
380 if (I != NumRegs) {
381 // Reserve an arbitrary register and report the error.
382 TRI->markSuperRegs(RegMask, AMDGPU::VGPR0);
384 "cannot find enough VGPRs for wwm-regalloc");
385 }
386}
387
388bool SILowerSGPRSpillsLegacy::runOnMachineFunction(MachineFunction &MF) {
389 auto *LISWrapper = getAnalysisIfAvailable<LiveIntervalsWrapperPass>();
390 LiveIntervals *LIS = LISWrapper ? &LISWrapper->getLIS() : nullptr;
391 auto *SIWrapper = getAnalysisIfAvailable<SlotIndexesWrapperPass>();
392 SlotIndexes *Indexes = SIWrapper ? &SIWrapper->getSI() : nullptr;
394 &getAnalysis<MachineDominatorTreeWrapperPass>().getDomTree();
395 return SILowerSGPRSpills(LIS, Indexes, MDT).run(MF);
396}
397
398bool SILowerSGPRSpills::run(MachineFunction &MF) {
400 TII = ST.getInstrInfo();
401 TRI = &TII->getRegisterInfo();
402
403 assert(SaveBlocks.empty() && RestoreBlocks.empty());
404
405 // First, expose any CSR SGPR spills. This is mostly the same as what PEI
406 // does, but somewhat simpler.
407 calculateSaveRestoreBlocks(MF);
408 SmallVector<int> CalleeSavedFIs;
409 bool HasCSRs = spillCalleeSavedRegs(MF, CalleeSavedFIs);
410
411 MachineFrameInfo &MFI = MF.getFrameInfo();
414
415 if (!MFI.hasStackObjects() && !HasCSRs) {
416 SaveBlocks.clear();
417 RestoreBlocks.clear();
418 return false;
419 }
420
421 bool MadeChange = false;
422 bool SpilledToVirtVGPRLanes = false;
423
424 // TODO: CSR VGPRs will never be spilled to AGPRs. These can probably be
425 // handled as SpilledToReg in regular PrologEpilogInserter.
426 const bool HasSGPRSpillToVGPR = TRI->spillSGPRToVGPR() &&
427 (HasCSRs || FuncInfo->hasSpilledSGPRs());
428 if (HasSGPRSpillToVGPR) {
429 // Process all SGPR spills before frame offsets are finalized. Ideally SGPRs
430 // are spilled to VGPRs, in which case we can eliminate the stack usage.
431 //
432 // This operates under the assumption that only other SGPR spills are users
433 // of the frame index.
434
435 // To track the spill frame indices handled in this pass.
436 BitVector SpillFIs(MFI.getObjectIndexEnd(), false);
437
438 // To track the IMPLICIT_DEF insertion point for the lane vgprs.
440
441 for (MachineBasicBlock &MBB : MF) {
443 if (!TII->isSGPRSpill(MI))
444 continue;
445
446 if (MI.getOperand(0).isUndef()) {
447 if (Indexes)
449 MI.eraseFromParent();
450 continue;
451 }
452
453 int FI = TII->getNamedOperand(MI, AMDGPU::OpName::addr)->getIndex();
455
456 bool IsCalleeSaveSGPRSpill = llvm::is_contained(CalleeSavedFIs, FI);
457 if (IsCalleeSaveSGPRSpill) {
458 // Spill callee-saved SGPRs into physical VGPR lanes.
459
460 // TODO: This is to ensure the CFIs are static for efficient frame
461 // unwinding in the debugger. Spilling them into virtual VGPR lanes
462 // involve regalloc to allocate the physical VGPRs and that might
463 // cause intermediate spill/split of such liveranges for successful
464 // allocation. This would result in broken CFI encoding unless the
465 // regalloc aware CFI generation to insert new CFIs along with the
466 // intermediate spills is implemented. There is no such support
467 // currently exist in the LLVM compiler.
468 if (FuncInfo->allocateSGPRSpillToVGPRLane(
469 MF, FI, /*SpillToPhysVGPRLane=*/true)) {
470 bool Spilled = TRI->eliminateSGPRToVGPRSpillFrameIndex(
471 MI, FI, nullptr, Indexes, LIS, true);
472 if (!Spilled)
474 "failed to spill SGPR to physical VGPR lane when allocated");
475 }
476 } else {
477 MachineInstrSpan MIS(&MI, &MBB);
478 if (FuncInfo->allocateSGPRSpillToVGPRLane(MF, FI)) {
479 bool Spilled = TRI->eliminateSGPRToVGPRSpillFrameIndex(
480 MI, FI, nullptr, Indexes, LIS);
481 if (!Spilled)
483 "failed to spill SGPR to virtual VGPR lane when allocated");
484 SpillFIs.set(FI);
485 updateLaneVGPRDomInstr(FI, &MBB, MIS.begin(), LaneVGPRDomInstr);
486 SpilledToVirtVGPRLanes = true;
487 }
488 }
489 }
490 }
491
492 for (auto Reg : FuncInfo->getSGPRSpillVGPRs()) {
493 auto InsertPt = LaneVGPRDomInstr[Reg];
494 // Insert the IMPLICIT_DEF at the identified points.
495 MachineBasicBlock &Block = *InsertPt->getParent();
496 DebugLoc DL = Block.findDebugLoc(InsertPt);
497 auto MIB =
498 BuildMI(Block, *InsertPt, DL, TII->get(AMDGPU::IMPLICIT_DEF), Reg);
499
500 // Add WWM flag to the virtual register.
502
503 // Set SGPR_SPILL asm printer flag
504 MIB->setAsmPrinterFlag(AMDGPU::SGPR_SPILL);
505 if (LIS) {
506 LIS->InsertMachineInstrInMaps(*MIB);
508 }
509 }
510
511 // Determine the registers for WWM allocation and also compute the register
512 // mask for non-wwm VGPR allocation.
513 if (FuncInfo->getSGPRSpillVGPRs().size()) {
514 BitVector WwmRegMask(TRI->getNumRegs());
515
516 determineRegsForWWMAllocation(MF, WwmRegMask);
517
518 BitVector NonWwmRegMask(WwmRegMask);
519 NonWwmRegMask.flip().clearBitsNotInMask(TRI->getAllVGPRRegMask());
520
521 // The complement set will be the registers for non-wwm (per-thread) vgpr
522 // allocation.
523 FuncInfo->updateNonWWMRegMask(NonWwmRegMask);
524 }
525
526 for (MachineBasicBlock &MBB : MF) {
527 // FIXME: The dead frame indices are replaced with a null register from
528 // the debug value instructions. We should instead, update it with the
529 // correct register value. But not sure the register value alone is
530 // adequate to lower the DIExpression. It should be worked out later.
531 for (MachineInstr &MI : MBB) {
532 if (MI.isDebugValue()) {
533 uint32_t StackOperandIdx = MI.isDebugValueList() ? 2 : 0;
534 if (MI.getOperand(StackOperandIdx).isFI() &&
536 MI.getOperand(StackOperandIdx).getIndex()) &&
537 SpillFIs[MI.getOperand(StackOperandIdx).getIndex()]) {
538 MI.getOperand(StackOperandIdx)
539 .ChangeToRegister(Register(), false /*isDef*/);
540 }
541 }
542 }
543 }
544
545 // All those frame indices which are dead by now should be removed from the
546 // function frame. Otherwise, there is a side effect such as re-mapping of
547 // free frame index ids by the later pass(es) like "stack slot coloring"
548 // which in turn could mess-up with the book keeping of "frame index to VGPR
549 // lane".
550 FuncInfo->removeDeadFrameIndices(MFI, /*ResetSGPRSpillStackIDs*/ false);
551
552 MadeChange = true;
553 }
554
555 if (SpilledToVirtVGPRLanes) {
556 const TargetRegisterClass *RC = TRI->getWaveMaskRegClass();
557 // Shift back the reserved SGPR for EXEC copy into the lowest range.
558 // This SGPR is reserved to handle the whole-wave spill/copy operations
559 // that might get inserted during vgpr regalloc.
560 Register UnusedLowSGPR = TRI->findUnusedRegister(MRI, RC, MF);
561 if (UnusedLowSGPR && TRI->getHWRegIndex(UnusedLowSGPR) <
562 TRI->getHWRegIndex(FuncInfo->getSGPRForEXECCopy()))
563 FuncInfo->setSGPRForEXECCopy(UnusedLowSGPR);
564 } else {
565 // No SGPR spills to virtual VGPR lanes and hence there won't be any WWM
566 // spills/copies. Reset the SGPR reserved for EXEC copy.
567 FuncInfo->setSGPRForEXECCopy(AMDGPU::NoRegister);
568 }
569
570 SaveBlocks.clear();
571 RestoreBlocks.clear();
572
573 return MadeChange;
574}
575
579 MFPropsModifier _(*this, MF);
580 auto *LIS = MFAM.getCachedResult<LiveIntervalsAnalysis>(MF);
581 auto *Indexes = MFAM.getCachedResult<SlotIndexesAnalysis>(MF);
583 SILowerSGPRSpills(LIS, Indexes, MDT).run(MF);
584 return PreservedAnalyses::all();
585}
unsigned const MachineRegisterInfo * MRI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
aarch64 promote const
Provides AMDGPU specific target descriptions.
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
AMD GCN specific subclass of TargetSubtarget.
const HexagonInstrInfo * TII
#define _
IRTranslator LLVM IR MI
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
Register const TargetRegisterInfo * TRI
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition: PassSupport.h:42
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:44
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:39
This file declares the machine register scavenger class.
static void updateLiveness(MachineFunction &MF, ArrayRef< CalleeSavedInfo > CSI)
static bool isLiveIntoMBB(MCRegister Reg, MachineBasicBlock &MBB, const TargetRegisterInfo *TRI)
static void insertCSRRestores(MachineBasicBlock &RestoreBlock, MutableArrayRef< CalleeSavedInfo > CSI, SlotIndexes *Indexes, LiveIntervals *LIS)
Insert restore code for the callee-saved registers used in the function.
SI lower SGPR spill instructions
static void insertCSRSaves(MachineBasicBlock &SaveBlock, ArrayRef< CalleeSavedInfo > CSI, SlotIndexes *Indexes, LiveIntervals *LIS)
Insert spill code for the callee-saved registers used in the function.
#define DEBUG_TYPE
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:255
PassT::Result * getCachedResult(IRUnitT &IR) const
Get the cached result of an analysis pass for a given IR unit.
Definition: PassManager.h:431
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Definition: PassManager.h:412
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
void setPreservesAll()
Set by analyses that do not transform their input at all.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
bool test(unsigned Idx) const
Definition: BitVector.h:461
The CalleeSavedInfo class tracks the information need to locate where a callee saved register is in t...
A debug info location.
Definition: DebugLoc.h:124
iterator find(const_arg_type_t< KeyT > Val)
Definition: DenseMap.h:177
iterator end()
Definition: DenseMap.h:87
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
Definition: Function.cpp:359
void storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, Register SrcReg, bool isKill, int FrameIndex, const TargetRegisterClass *RC, const TargetRegisterInfo *TRI, Register VReg, MachineInstr::MIFlag Flags=MachineInstr::NoFlags) const override
Store the specified register of the given register class to the specified stack frame index.
LLVM_ABI void emitError(const Instruction *I, const Twine &ErrorStr)
emitError - Emit an error message to the currently installed error handler with optional location inf...
void removeAllRegUnitsForPhysReg(MCRegister Reg)
Remove associated live ranges for the register units associated with Reg.
SlotIndex InsertMachineInstrInMaps(MachineInstr &MI)
LiveInterval & createAndComputeVirtRegInterval(Register Reg)
MCRegAliasIterator enumerates all registers aliasing Reg.
Wrapper class representing physical registers. Should be passed by value.
Definition: MCRegister.h:33
An RAII based helper class to modify MachineFunctionProperties when running pass.
bool isEHFuncletEntry() const
Returns true if this is the entry block of an EH funclet.
LLVM_ABI iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
bool isReturnBlock() const
Convenience function that returns true if the block ends in a return instruction.
LLVM_ABI void sortUniqueLiveIns()
Sorts and uniques the LiveIns vector.
void addLiveIn(MCRegister PhysReg, LaneBitmask LaneMask=LaneBitmask::getAll())
Adds the specified register as a live in.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
LLVM_ABI bool isLiveIn(MCRegister Reg, LaneBitmask LaneMask=LaneBitmask::getAll()) const
Return true if the specified register is in the live in set.
Analysis pass which computes a MachineDominatorTree.
LLVM_ABI Result run(MachineFunction &MF, MachineFunctionAnalysisManager &)
Analysis pass which computes a MachineDominatorTree.
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
LLVM_ABI int CreateStackObject(uint64_t Size, Align Alignment, bool isSpillSlot, const AllocaInst *Alloca=nullptr, uint8_t ID=0)
Create a new statically sized stack object, returning a nonnegative identifier to represent it.
ArrayRef< MachineBasicBlock * > getSavePoints() const
ArrayRef< MachineBasicBlock * > getRestorePoints() const
void setCalleeSavedInfoValid(bool v)
int getObjectIndexEnd() const
Return one past the maximum frame object index.
bool hasStackObjects() const
Return true if there are any stack objects in this function.
uint8_t getStackID(int ObjectIdx) const
bool isFixedObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a fixed stack object.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
virtual MachineFunctionProperties getClearedProperties() const
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
virtual bool runOnMachineFunction(MachineFunction &MF)=0
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
Properties which a MachineFunction may have at a given point in time.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Function & getFunction()
Return the LLVM function that this machine code represents.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
const MachineBasicBlock & front() const
MachineInstrSpan provides an interface to get an iteration range containing the instruction it was in...
MachineBasicBlock::iterator begin()
Representation of each machine instruction.
Definition: MachineInstr.h:72
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:303
A set of analyses that are preserved following a run of a transformation pass.
Definition: Analysis.h:112
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: Analysis.h:118
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
This class keeps track of the SPI_SP_INPUT_ADDR config register, which tells the hardware which inter...
void setFlag(Register Reg, uint8_t Flag)
ArrayRef< SIRegisterInfo::SpilledReg > getSGPRSpillToVirtualVGPRLanes(int FrameIndex) const
bool allocateSGPRSpillToVGPRLane(MachineFunction &MF, int FI, bool SpillToPhysVGPRLane=false, bool IsPrologEpilog=false)
bool removeDeadFrameIndices(MachineFrameInfo &MFI, bool ResetSGPRSpillStackIDs)
If ResetSGPRSpillStackIDs is true, reset the stack ID from sgpr-spill to the default stack.
void updateNonWWMRegMask(BitVector &RegMask)
ArrayRef< Register > getSGPRSpillVGPRs() const
SlotIndexes pass.
Definition: SlotIndexes.h:298
SlotIndex insertMachineInstrInMaps(MachineInstr &MI, bool Late=false)
Insert the given machine instruction into the mapping.
Definition: SlotIndexes.h:532
LLVM_ABI void removeMachineInstrFromMaps(MachineInstr &MI, bool AllowBundled=false)
Removes machine instruction (bundle) MI from the mapping.
LLVM_ABI void repairIndexesInRange(MachineBasicBlock *MBB, MachineBasicBlock::iterator Begin, MachineBasicBlock::iterator End)
Repair indexes after adding and removing instructions.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:574
void push_back(const T &Elt)
Definition: SmallVector.h:414
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1197
Information about stack frame layout on the target.
void restoreCalleeSavedRegister(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, const CalleeSavedInfo &CS, const TargetInstrInfo *TII, const TargetRegisterInfo *TRI) const
virtual bool spillCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, ArrayRef< CalleeSavedInfo > CSI, const TargetRegisterInfo *TRI) const
spillCalleeSavedRegisters - Issues instruction(s) to spill all callee saved registers and returns tru...
virtual bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, MutableArrayRef< CalleeSavedInfo > CSI, const TargetRegisterInfo *TRI) const
restoreCalleeSavedRegisters - Issues instruction(s) to restore all callee saved registers and returns...
TargetInstrInfo - Interface to description of machine instruction set.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual const TargetFrameLowering * getFrameLowering() const
virtual const TargetInstrInfo * getInstrInfo() const
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
Reg
All possible values of the reg field in the ModR/M byte.
@ ReallyHidden
Definition: CommandLine.h:139
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:444
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
Definition: STLExtras.h:663
auto reverse(ContainerTy &&C)
Definition: STLExtras.h:428
char & SILowerSGPRSpillsLegacyID
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition: STLExtras.h:1916