LLVM 20.0.0git
RegisterScavenging.cpp
Go to the documentation of this file.
1//===- RegisterScavenging.cpp - Machine register scavenging ---------------===//
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/// This file implements the machine register scavenger. It can provide
11/// information, such as unused registers, at any point in a machine basic
12/// block. It also provides a mechanism to make registers available by evicting
13/// them to spill slots.
14//
15//===----------------------------------------------------------------------===//
16
18#include "llvm/ADT/ArrayRef.h"
19#include "llvm/ADT/BitVector.h"
21#include "llvm/ADT/Statistic.h"
35#include "llvm/Pass.h"
36#include "llvm/Support/Debug.h"
39#include <cassert>
40#include <iterator>
41#include <limits>
42#include <utility>
43
44using namespace llvm;
45
46#define DEBUG_TYPE "reg-scavenging"
47
48STATISTIC(NumScavengedRegs, "Number of frame index regs scavenged");
49
51 LiveUnits.addRegMasked(Reg, LaneMask);
52}
53
54void RegScavenger::init(MachineBasicBlock &MBB) {
56 TII = MF.getSubtarget().getInstrInfo();
57 TRI = MF.getSubtarget().getRegisterInfo();
58 MRI = &MF.getRegInfo();
59 LiveUnits.init(*TRI);
60
61 this->MBB = &MBB;
62
63 for (ScavengedInfo &SI : Scavenged) {
64 SI.Reg = 0;
65 SI.Restore = nullptr;
66 }
67}
68
70 init(MBB);
71 LiveUnits.addLiveIns(MBB);
72 MBBI = MBB.begin();
73}
74
76 init(MBB);
77 LiveUnits.addLiveOuts(MBB);
78 MBBI = MBB.end();
79}
80
82 const MachineInstr &MI = *--MBBI;
83 LiveUnits.stepBackward(MI);
84
85 // Expire scavenge spill frameindex uses.
86 for (ScavengedInfo &I : Scavenged) {
87 if (I.Restore == &MI) {
88 I.Reg = 0;
89 I.Restore = nullptr;
90 }
91 }
92}
93
94bool RegScavenger::isRegUsed(Register Reg, bool includeReserved) const {
95 if (isReserved(Reg))
96 return includeReserved;
97 return !LiveUnits.available(Reg);
98}
99
101 for (Register Reg : *RC) {
102 if (!isRegUsed(Reg)) {
103 LLVM_DEBUG(dbgs() << "Scavenger found unused reg: " << printReg(Reg, TRI)
104 << "\n");
105 return Reg;
106 }
107 }
108 return 0;
109}
110
112 BitVector Mask(TRI->getNumRegs());
113 for (Register Reg : *RC)
114 if (!isRegUsed(Reg))
115 Mask.set(Reg);
116 return Mask;
117}
118
119/// Given the bitvector \p Available of free register units at position
120/// \p From. Search backwards to find a register that is part of \p
121/// Candidates and not used/clobbered until the point \p To. If there is
122/// multiple candidates continue searching and pick the one that is not used/
123/// clobbered for the longest time.
124/// Returns the register and the earliest position we know it to be free or
125/// the position MBB.end() if no register is available.
126static std::pair<MCPhysReg, MachineBasicBlock::iterator>
130 bool RestoreAfter) {
131 bool FoundTo = false;
132 MCPhysReg Survivor = 0;
134 MachineBasicBlock &MBB = *From->getParent();
135 unsigned InstrLimit = 25;
136 unsigned InstrCountDown = InstrLimit;
137 const TargetRegisterInfo &TRI = *MRI.getTargetRegisterInfo();
138 LiveRegUnits Used(TRI);
139
140 assert(From->getParent() == To->getParent() &&
141 "Target instruction is in other than current basic block, use "
142 "enterBasicBlockEnd first");
143
144 for (MachineBasicBlock::iterator I = From;; --I) {
145 const MachineInstr &MI = *I;
146
147 Used.accumulate(MI);
148
149 if (I == To) {
150 // See if one of the registers in RC wasn't used so far.
151 for (MCPhysReg Reg : AllocationOrder) {
152 if (!MRI.isReserved(Reg) && Used.available(Reg) &&
153 LiveOut.available(Reg))
154 return std::make_pair(Reg, MBB.end());
155 }
156 // Otherwise we will continue up to InstrLimit instructions to find
157 // the register which is not defined/used for the longest time.
158 FoundTo = true;
159 Pos = To;
160 // Note: It was fine so far to start our search at From, however now that
161 // we have to spill, and can only place the restore after From then
162 // add the regs used/defed by std::next(From) to the set.
163 if (RestoreAfter)
164 Used.accumulate(*std::next(From));
165 }
166 if (FoundTo) {
167 // Don't search to FrameSetup instructions if we were searching from
168 // Non-FrameSetup instructions. Otherwise, the spill position may point
169 // before FrameSetup instructions.
170 if (!From->getFlag(MachineInstr::FrameSetup) &&
172 break;
173
174 if (Survivor == 0 || !Used.available(Survivor)) {
175 MCPhysReg AvilableReg = 0;
176 for (MCPhysReg Reg : AllocationOrder) {
177 if (!MRI.isReserved(Reg) && Used.available(Reg)) {
178 AvilableReg = Reg;
179 break;
180 }
181 }
182 if (AvilableReg == 0)
183 break;
184 Survivor = AvilableReg;
185 }
186 if (--InstrCountDown == 0)
187 break;
188
189 // Keep searching when we find a vreg since the spilled register will
190 // be usefull for this other vreg as well later.
191 bool FoundVReg = false;
192 for (const MachineOperand &MO : MI.operands()) {
193 if (MO.isReg() && MO.getReg().isVirtual()) {
194 FoundVReg = true;
195 break;
196 }
197 }
198 if (FoundVReg) {
199 InstrCountDown = InstrLimit;
200 Pos = I;
201 }
202 if (I == MBB.begin())
203 break;
204 }
205 assert(I != MBB.begin() && "Did not find target instruction while "
206 "iterating backwards");
207 }
208
209 return std::make_pair(Survivor, Pos);
210}
211
213 unsigned i = 0;
214 while (!MI.getOperand(i).isFI()) {
215 ++i;
216 assert(i < MI.getNumOperands() && "Instr doesn't have FrameIndex operand!");
217 }
218 return i;
219}
220
221RegScavenger::ScavengedInfo &
222RegScavenger::spill(Register Reg, const TargetRegisterClass &RC, int SPAdj,
225 // Find an available scavenging slot with size and alignment matching
226 // the requirements of the class RC.
227 const MachineFunction &MF = *Before->getMF();
228 const MachineFrameInfo &MFI = MF.getFrameInfo();
229 unsigned NeedSize = TRI->getSpillSize(RC);
230 Align NeedAlign = TRI->getSpillAlign(RC);
231
232 unsigned SI = Scavenged.size(), Diff = std::numeric_limits<unsigned>::max();
233 int FIB = MFI.getObjectIndexBegin(), FIE = MFI.getObjectIndexEnd();
234 for (unsigned I = 0; I < Scavenged.size(); ++I) {
235 if (Scavenged[I].Reg != 0)
236 continue;
237 // Verify that this slot is valid for this register.
238 int FI = Scavenged[I].FrameIndex;
239 if (FI < FIB || FI >= FIE)
240 continue;
241 unsigned S = MFI.getObjectSize(FI);
242 Align A = MFI.getObjectAlign(FI);
243 if (NeedSize > S || NeedAlign > A)
244 continue;
245 // Avoid wasting slots with large size and/or large alignment. Pick one
246 // that is the best fit for this register class (in street metric).
247 // Picking a larger slot than necessary could happen if a slot for a
248 // larger register is reserved before a slot for a smaller one. When
249 // trying to spill a smaller register, the large slot would be found
250 // first, thus making it impossible to spill the larger register later.
251 unsigned D = (S - NeedSize) + (A.value() - NeedAlign.value());
252 if (D < Diff) {
253 SI = I;
254 Diff = D;
255 }
256 }
257
258 if (SI == Scavenged.size()) {
259 // We need to scavenge a register but have no spill slot, the target
260 // must know how to do it (if not, we'll assert below).
261 Scavenged.push_back(ScavengedInfo(FIE));
262 }
263
264 // Avoid infinite regress
265 Scavenged[SI].Reg = Reg;
266
267 // If the target knows how to save/restore the register, let it do so;
268 // otherwise, use the emergency stack spill slot.
269 if (!TRI->saveScavengerRegister(*MBB, Before, UseMI, &RC, Reg)) {
270 // Spill the scavenged register before \p Before.
271 int FI = Scavenged[SI].FrameIndex;
272 if (FI < FIB || FI >= FIE) {
273 report_fatal_error(Twine("Error while trying to spill ") +
274 TRI->getName(Reg) + " from class " +
275 TRI->getRegClassName(&RC) +
276 ": Cannot scavenge register without an emergency "
277 "spill slot!");
278 }
279 TII->storeRegToStackSlot(*MBB, Before, Reg, true, FI, &RC, TRI, Register());
281
282 unsigned FIOperandNum = getFrameIndexOperandNum(*II);
283 TRI->eliminateFrameIndex(II, SPAdj, FIOperandNum, this);
284
285 // Restore the scavenged register before its use (or first terminator).
286 TII->loadRegFromStackSlot(*MBB, UseMI, Reg, FI, &RC, TRI, Register());
287 II = std::prev(UseMI);
288
289 FIOperandNum = getFrameIndexOperandNum(*II);
290 TRI->eliminateFrameIndex(II, SPAdj, FIOperandNum, this);
291 }
292 return Scavenged[SI];
293}
294
297 bool RestoreAfter, int SPAdj,
298 bool AllowSpill) {
299 const MachineBasicBlock &MBB = *To->getParent();
300 const MachineFunction &MF = *MBB.getParent();
301
302 // Find the register whose use is furthest away.
305 std::pair<MCPhysReg, MachineBasicBlock::iterator> P = findSurvivorBackwards(
306 *MRI, std::prev(MBBI), To, LiveUnits, AllocationOrder, RestoreAfter);
307 MCPhysReg Reg = P.first;
308 MachineBasicBlock::iterator SpillBefore = P.second;
309 // Found an available register?
310 if (Reg != 0 && SpillBefore == MBB.end()) {
311 LLVM_DEBUG(dbgs() << "Scavenged free register: " << printReg(Reg, TRI)
312 << '\n');
313 return Reg;
314 }
315
316 if (!AllowSpill)
317 return 0;
318
319 assert(Reg != 0 && "No register left to scavenge!");
320
321 MachineBasicBlock::iterator ReloadBefore =
322 RestoreAfter ? std::next(MBBI) : MBBI;
323 if (ReloadBefore != MBB.end())
324 LLVM_DEBUG(dbgs() << "Reload before: " << *ReloadBefore << '\n');
325 ScavengedInfo &Scavenged = spill(Reg, RC, SPAdj, SpillBefore, ReloadBefore);
326 Scavenged.Restore = &*std::prev(SpillBefore);
327 LiveUnits.removeReg(Reg);
328 LLVM_DEBUG(dbgs() << "Scavenged register with spill: " << printReg(Reg, TRI)
329 << " until " << *SpillBefore);
330 return Reg;
331}
332
333/// Allocate a register for the virtual register \p VReg. The last use of
334/// \p VReg is around the current position of the register scavenger \p RS.
335/// \p ReserveAfter controls whether the scavenged register needs to be reserved
336/// after the current instruction, otherwise it will only be reserved before the
337/// current instruction.
339 Register VReg, bool ReserveAfter) {
340 const TargetRegisterInfo &TRI = *MRI.getTargetRegisterInfo();
341#ifndef NDEBUG
342 // Verify that all definitions and uses are in the same basic block.
343 const MachineBasicBlock *CommonMBB = nullptr;
344 // Real definition for the reg, re-definitions are not considered.
345 const MachineInstr *RealDef = nullptr;
346 for (MachineOperand &MO : MRI.reg_nodbg_operands(VReg)) {
347 MachineBasicBlock *MBB = MO.getParent()->getParent();
348 if (CommonMBB == nullptr)
349 CommonMBB = MBB;
350 assert(MBB == CommonMBB && "All defs+uses must be in the same basic block");
351 if (MO.isDef()) {
352 const MachineInstr &MI = *MO.getParent();
353 if (!MI.readsRegister(VReg, &TRI)) {
354 assert((!RealDef || RealDef == &MI) &&
355 "Can have at most one definition which is not a redefinition");
356 RealDef = &MI;
357 }
358 }
359 }
360 assert(RealDef != nullptr && "Must have at least 1 Def");
361#endif
362
363 // We should only have one definition of the register. However to accommodate
364 // the requirements of two address code we also allow definitions in
365 // subsequent instructions provided they also read the register. That way
366 // we get a single contiguous lifetime.
367 //
368 // Definitions in MRI.def_begin() are unordered, search for the first.
370 MRI.def_operands(VReg), [VReg, &TRI](const MachineOperand &MO) {
371 return !MO.getParent()->readsRegister(VReg, &TRI);
372 });
373 assert(FirstDef != MRI.def_end() &&
374 "Must have one definition that does not redefine vreg");
375 MachineInstr &DefMI = *FirstDef->getParent();
376
377 // The register scavenger will report a free register inserting an emergency
378 // spill/reload if necessary.
379 int SPAdj = 0;
380 const TargetRegisterClass &RC = *MRI.getRegClass(VReg);
381 Register SReg = RS.scavengeRegisterBackwards(RC, DefMI.getIterator(),
382 ReserveAfter, SPAdj);
383 MRI.replaceRegWith(VReg, SReg);
384 ++NumScavengedRegs;
385 return SReg;
386}
387
388/// Allocate (scavenge) vregs inside a single basic block.
389/// Returns true if the target spill callback created new vregs and a 2nd pass
390/// is necessary.
392 RegScavenger &RS,
394 const TargetRegisterInfo &TRI = *MRI.getTargetRegisterInfo();
396
397 unsigned InitialNumVirtRegs = MRI.getNumVirtRegs();
398 bool NextInstructionReadsVReg = false;
399 for (MachineBasicBlock::iterator I = MBB.end(); I != MBB.begin(); ) {
400 // Move RegScavenger to the position between *std::prev(I) and *I.
401 RS.backward(I);
402 --I;
403
404 // Look for unassigned vregs in the uses of *std::next(I).
405 if (NextInstructionReadsVReg) {
406 MachineBasicBlock::iterator N = std::next(I);
407 const MachineInstr &NMI = *N;
408 for (const MachineOperand &MO : NMI.operands()) {
409 if (!MO.isReg())
410 continue;
411 Register Reg = MO.getReg();
412 // We only care about virtual registers and ignore virtual registers
413 // created by the target callbacks in the process (those will be handled
414 // in a scavenging round).
415 if (!Reg.isVirtual() ||
416 Register::virtReg2Index(Reg) >= InitialNumVirtRegs)
417 continue;
418 if (!MO.readsReg())
419 continue;
420
421 Register SReg = scavengeVReg(MRI, RS, Reg, true);
422 N->addRegisterKilled(SReg, &TRI, false);
423 RS.setRegUsed(SReg);
424 }
425 }
426
427 // Look for unassigned vregs in the defs of *I.
428 NextInstructionReadsVReg = false;
429 const MachineInstr &MI = *I;
430 for (const MachineOperand &MO : MI.operands()) {
431 if (!MO.isReg())
432 continue;
433 Register Reg = MO.getReg();
434 // Only vregs, no newly created vregs (see above).
435 if (!Reg.isVirtual() ||
436 Register::virtReg2Index(Reg) >= InitialNumVirtRegs)
437 continue;
438 // We have to look at all operands anyway so we can precalculate here
439 // whether there is a reading operand. This allows use to skip the use
440 // step in the next iteration if there was none.
441 assert(!MO.isInternalRead() && "Cannot assign inside bundles");
442 assert((!MO.isUndef() || MO.isDef()) && "Cannot handle undef uses");
443 if (MO.readsReg()) {
444 NextInstructionReadsVReg = true;
445 }
446 if (MO.isDef()) {
447 Register SReg = scavengeVReg(MRI, RS, Reg, false);
448 I->addRegisterDead(SReg, &TRI, false);
449 }
450 }
451 }
452#ifndef NDEBUG
453 for (const MachineOperand &MO : MBB.front().operands()) {
454 if (!MO.isReg() || !MO.getReg().isVirtual())
455 continue;
456 assert(!MO.isInternalRead() && "Cannot assign inside bundles");
457 assert((!MO.isUndef() || MO.isDef()) && "Cannot handle undef uses");
458 assert(!MO.readsReg() && "Vreg use in first instruction not allowed");
459 }
460#endif
461
462 return MRI.getNumVirtRegs() != InitialNumVirtRegs;
463}
464
466 // FIXME: Iterating over the instruction stream is unnecessary. We can simply
467 // iterate over the vreg use list, which at this point only contains machine
468 // operands for which eliminateFrameIndex need a new scratch reg.
470 // Shortcut.
471 if (MRI.getNumVirtRegs() == 0) {
473 return;
474 }
475
476 // Run through the instructions and find any virtual registers.
477 for (MachineBasicBlock &MBB : MF) {
478 if (MBB.empty())
479 continue;
480
481 bool Again = scavengeFrameVirtualRegsInBlock(MRI, RS, MBB);
482 if (Again) {
483 LLVM_DEBUG(dbgs() << "Warning: Required two scavenging passes for block "
484 << MBB.getName() << '\n');
486 // The target required a 2nd run (because it created new vregs while
487 // spilling). Refuse to do another pass to keep compiletime in check.
488 if (Again)
489 report_fatal_error("Incomplete scavenging after 2nd pass");
490 }
491 }
492
493 MRI.clearVirtRegs();
495}
496
497namespace {
498
499/// This class runs register scavenging independ of the PrologEpilogInserter.
500/// This is used in for testing.
501class ScavengerTest : public MachineFunctionPass {
502public:
503 static char ID;
504
505 ScavengerTest() : MachineFunctionPass(ID) {}
506
507 bool runOnMachineFunction(MachineFunction &MF) override {
508 const TargetSubtargetInfo &STI = MF.getSubtarget();
509 const TargetFrameLowering &TFL = *STI.getFrameLowering();
510
511 RegScavenger RS;
512 // Let's hope that calling those outside of PrologEpilogueInserter works
513 // well enough to initialize the scavenger with some emergency spillslots
514 // for the target.
515 BitVector SavedRegs;
516 TFL.determineCalleeSaves(MF, SavedRegs, &RS);
518
519 // Let's scavenge the current function
521 return true;
522 }
523};
524
525} // end anonymous namespace
526
527char ScavengerTest::ID;
528
529INITIALIZE_PASS(ScavengerTest, "scavenger-test",
530 "Scavenge virtual registers inside basic blocks", false, false)
unsigned const MachineRegisterInfo * MRI
MachineInstrBuilder & UseMI
MachineInstrBuilder MachineInstrBuilder & DefMI
MachineBasicBlock & MBB
This file implements the BitVector class.
BlockVerifier::State From
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static cl::opt< unsigned > InstrLimit("dfa-instr-limit", cl::Hidden, cl::init(0), cl::desc("If present, stops packetizing after N instructions"))
#define LLVM_DEBUG(...)
Definition: Debug.h:106
IRTranslator LLVM IR MI
A set of register units.
#define I(x, y, z)
Definition: MD5.cpp:58
unsigned const TargetRegisterInfo * TRI
uint64_t IntrinsicInst * II
#define P(N)
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:38
static Register scavengeVReg(MachineRegisterInfo &MRI, RegScavenger &RS, Register VReg, bool ReserveAfter)
Allocate a register for the virtual register VReg.
static unsigned getFrameIndexOperandNum(MachineInstr &MI)
static bool scavengeFrameVirtualRegsInBlock(MachineRegisterInfo &MRI, RegScavenger &RS, MachineBasicBlock &MBB)
Allocate (scavenge) vregs inside a single basic block.
static std::pair< MCPhysReg, MachineBasicBlock::iterator > findSurvivorBackwards(const MachineRegisterInfo &MRI, MachineBasicBlock::iterator From, MachineBasicBlock::iterator To, const LiveRegUnits &LiveOut, ArrayRef< MCPhysReg > AllocationOrder, bool RestoreAfter)
Given the bitvector Available of free register units at position From.
This file declares the machine register scavenger class.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallVector class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
Definition: Statistic.h:166
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
A set of register units used to track register liveness.
Definition: LiveRegUnits.h:30
void addRegMasked(MCPhysReg Reg, LaneBitmask Mask)
Adds register units covered by physical register Reg that are part of the lanemask Mask.
Definition: LiveRegUnits.h:93
bool available(MCPhysReg Reg) const
Returns true if no part of physical register Reg is live.
Definition: LiveRegUnits.h:116
void init(const TargetRegisterInfo &TRI)
Initialize and clear the set.
Definition: LiveRegUnits.h:73
void stepBackward(const MachineInstr &MI)
Updates liveness when stepping backwards over the instruction MI.
void addLiveOuts(const MachineBasicBlock &MBB)
Adds registers living out of block MBB.
void addLiveIns(const MachineBasicBlock &MBB)
Adds registers living into block MBB.
void removeReg(MCPhysReg Reg)
Removes all register units covered by physical register Reg.
Definition: LiveRegUnits.h:102
const char * getName(MCRegister RegNo) const
Return the human-readable symbolic target-specific name for the specified physical register.
unsigned getNumRegs() const
Return the number of registers this target has (useful for sizing arrays holding per register informa...
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
StringRef getName() const
Return the name of the corresponding LLVM basic block, or an empty string.
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
Align getObjectAlign(int ObjectIdx) const
Return the alignment of the specified stack object.
int64_t getObjectSize(int ObjectIdx) const
Return the size of the specified object.
int getObjectIndexEnd() const
Return one past the maximum frame object index.
int getObjectIndexBegin() const
Return the minimum frame object index.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
MachineFunctionProperties & set(Property P)
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.
const MachineFunctionProperties & getProperties() const
Get the function properties.
Representation of each machine instruction.
Definition: MachineInstr.h:69
iterator_range< mop_iterator > operands()
Definition: MachineInstr.h:691
MachineOperand class - Representation of each machine instruction operand.
MachineInstr * getParent()
getParent - Return the instruction that this operand belongs to.
reg_begin/reg_end - Provide iteration support to walk over all definitions and uses of a register wit...
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
void enterBasicBlockEnd(MachineBasicBlock &MBB)
Start tracking liveness from the end of basic block MBB.
bool isRegUsed(Register Reg, bool includeReserved=true) const
Return if a specific register is currently used.
Register FindUnusedReg(const TargetRegisterClass *RC) const
Find an unused register of the specified register class.
void setRegUsed(Register Reg, LaneBitmask LaneMask=LaneBitmask::getAll())
Tell the scavenger a register is used.
void backward()
Update internal register state and move MBB iterator backwards.
void enterBasicBlock(MachineBasicBlock &MBB)
Start tracking liveness from the begin of basic block MBB.
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...
BitVector getRegsAvailable(const TargetRegisterClass *RC)
Return all available registers in the register class in Mask.
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
static unsigned virtReg2Index(Register Reg)
Convert a virtual register number to a 0-based index.
Definition: Register.h:77
size_t size() const
Definition: SmallVector.h:78
void push_back(const T &Elt)
Definition: SmallVector.h:413
Information about stack frame layout on the target.
virtual void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS=nullptr) const
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
virtual void processFunctionBeforeFrameFinalized(MachineFunction &MF, RegScavenger *RS=nullptr) const
processFunctionBeforeFrameFinalized - This method is called immediately before the specified function...
virtual void loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, Register DestReg, int FrameIndex, const TargetRegisterClass *RC, const TargetRegisterInfo *TRI, Register VReg) const
Load the specified register of the given register class from the specified stack frame index.
virtual void storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, Register SrcReg, bool isKill, int FrameIndex, const TargetRegisterClass *RC, const TargetRegisterInfo *TRI, Register VReg) const
Store the specified register of the given register class to the specified stack frame index.
ArrayRef< MCPhysReg > getRawAllocationOrder(const MachineFunction &MF) const
Returns the preferred order for allocating registers from this register class in MF.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
Align getSpillAlign(const TargetRegisterClass &RC) const
Return the minimum required alignment in bytes for a spill slot for a register of this class.
virtual bool eliminateFrameIndex(MachineBasicBlock::iterator MI, int SPAdj, unsigned FIOperandNum, RegScavenger *RS=nullptr) const =0
This method must be overriden to eliminate abstract frame indices from instructions which may use the...
virtual bool saveScavengerRegister(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, MachineBasicBlock::iterator &UseMI, const TargetRegisterClass *RC, Register Reg) const
Spill the register so it can be used by the register scavenger.
unsigned getSpillSize(const TargetRegisterClass &RC) const
Return the size in bytes of the stack slot allocated to hold a spilled copy of a register from class ...
const char * getRegClassName(const TargetRegisterClass *Class) const
Returns the name of the register class.
TargetSubtargetInfo - Generic base class for all target subtargets.
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
virtual const TargetFrameLowering * getFrameLowering() const
virtual const TargetInstrInfo * getInstrInfo() const
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
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.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
void scavengeFrameVirtualRegs(MachineFunction &MF, RegScavenger &RS)
Replaces all frame index virtual registers with physical registers.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:167
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1766
Printable printReg(Register Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.
#define N
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
uint64_t value() const
This is a hole in the type system and should not be abused.
Definition: Alignment.h:85