LLVM 20.0.0git
Classes | Public Member Functions | List of all members
llvm::RegScavenger Class Reference

#include "llvm/CodeGen/RegisterScavenging.h"

Public Member Functions

 RegScavenger ()=default
 
void assignRegToScavengingIndex (int FI, Register Reg, MachineInstr *Restore=nullptr)
 Record that Reg is in use at scavenging index FI.
 
void enterBasicBlock (MachineBasicBlock &MBB)
 Start tracking liveness from the begin of basic block MBB.
 
void enterBasicBlockEnd (MachineBasicBlock &MBB)
 Start tracking liveness from the end of basic block MBB.
 
void backward ()
 Update internal register state and move MBB iterator backwards.
 
void backward (MachineBasicBlock::iterator I)
 Call backward() to update internal register state to just before *I.
 
bool isRegUsed (Register Reg, bool includeReserved=true) const
 Return if a specific register is currently used.
 
BitVector getRegsAvailable (const TargetRegisterClass *RC)
 Return all available registers in the register class in Mask.
 
Register FindUnusedReg (const TargetRegisterClass *RC) const
 Find an unused register of the specified register class.
 
void addScavengingFrameIndex (int FI)
 Add a scavenging frame index.
 
bool isScavengingFrameIndex (int FI) const
 Query whether a frame index is a scavenging frame index.
 
void getScavengingFrameIndices (SmallVectorImpl< int > &A) const
 Get an array of scavenging frame indices.
 
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 place before To.
 
void setRegUsed (Register Reg, LaneBitmask LaneMask=LaneBitmask::getAll())
 Tell the scavenger a register is used.
 

Detailed Description

Definition at line 34 of file RegisterScavenging.h.

Constructor & Destructor Documentation

◆ RegScavenger()

llvm::RegScavenger::RegScavenger ( )
default

Member Function Documentation

◆ addScavengingFrameIndex()

void llvm::RegScavenger::addScavengingFrameIndex ( int  FI)
inline

◆ assignRegToScavengingIndex()

void llvm::RegScavenger::assignRegToScavengingIndex ( int  FI,
Register  Reg,
MachineInstr Restore = nullptr 
)
inline

Record that Reg is in use at scavenging index FI.

This is for targets which need to directly manage the spilling process, and need to update the scavenger's internal state. It's expected this be called a second time with Restore set to a non-null value, so that the externally inserted restore instruction resets the scavenged slot liveness when encountered.

Definition at line 70 of file RegisterScavenging.h.

References assert(), llvm_unreachable, and Reg.

Referenced by llvm::SGPRSpillBuilder::prepare(), and llvm::SGPRSpillBuilder::restore().

◆ backward() [1/2]

void RegScavenger::backward ( )

Update internal register state and move MBB iterator backwards.

This method gives precise results even in the absence of kill flags.

Definition at line 81 of file RegisterScavenging.cpp.

References I, MI, and llvm::LiveRegUnits::stepBackward().

Referenced by analyzeCompressibleUses(), backward(), indirectCopyToAGPR(), llvm::Mips16InstrInfo::loadImmediate(), llvm::AArch64FrameLowering::processFunctionBeforeFrameFinalized(), llvm::SIFrameLowering::processFunctionBeforeFrameFinalized(), and scavengeFrameVirtualRegsInBlock().

◆ backward() [2/2]

void llvm::RegScavenger::backward ( MachineBasicBlock::iterator  I)
inline

Call backward() to update internal register state to just before *I.

Definition at line 96 of file RegisterScavenging.h.

References backward(), I, and MBBI.

◆ enterBasicBlock()

void RegScavenger::enterBasicBlock ( MachineBasicBlock MBB)

Start tracking liveness from the begin of basic block MBB.

Definition at line 69 of file RegisterScavenging.cpp.

References llvm::LiveRegUnits::addLiveIns(), llvm::MachineBasicBlock::begin(), and MBB.

Referenced by llvm::RISCVFrameLowering::canUseAsPrologue(), and llvm::SIInstrInfo::insertIndirectBranch().

◆ enterBasicBlockEnd()

void RegScavenger::enterBasicBlockEnd ( MachineBasicBlock MBB)

◆ FindUnusedReg()

Register RegScavenger::FindUnusedReg ( const TargetRegisterClass RC) const

◆ getRegsAvailable()

BitVector RegScavenger::getRegsAvailable ( const TargetRegisterClass RC)

Return all available registers in the register class in Mask.

Definition at line 111 of file RegisterScavenging.cpp.

References llvm::MCRegisterInfo::getNumRegs(), and isRegUsed().

Referenced by llvm::PPCRegisterInfo::eliminateFrameIndex(), and llvm::Mips16InstrInfo::loadImmediate().

◆ getScavengingFrameIndices()

void llvm::RegScavenger::getScavengingFrameIndices ( SmallVectorImpl< int > &  A) const
inline

Get an array of scavenging frame indices.

Definition at line 126 of file RegisterScavenging.h.

References A, and I.

◆ isRegUsed()

bool RegScavenger::isRegUsed ( Register  Reg,
bool  includeReserved = true 
) const

◆ isScavengingFrameIndex()

bool llvm::RegScavenger::isScavengingFrameIndex ( int  FI) const
inline

Query whether a frame index is a scavenging frame index.

Definition at line 117 of file RegisterScavenging.h.

Referenced by llvm::AArch64RegisterInfo::eliminateFrameIndex(), llvm::ARMBaseRegisterInfo::eliminateFrameIndex(), and llvm::ThumbRegisterInfo::eliminateFrameIndex().

◆ scavengeRegisterBackwards()

Register RegScavenger::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 place before To.

If RestoreAfter is true this includes the instruction following the current position. SPAdj is the stack adjustment due to call frame, it's passed along to eliminateFrameIndex(). Returns the scavenged register.

If AllowSpill is false, fail if a spill is required to make the register available, and return NoRegister.

Definition at line 295 of file RegisterScavenging.cpp.

References assert(), llvm::dbgs(), llvm::MachineBasicBlock::end(), findSurvivorBackwards(), llvm::MachineBasicBlock::getParent(), llvm::TargetRegisterClass::getRawAllocationOrder(), LLVM_DEBUG, MBB, P, llvm::printReg(), llvm::LiveRegUnits::removeReg(), and UseMI.

Referenced by analyzeCompressibleUses(), llvm::SIRegisterInfo::buildSpillLoadStore(), llvm::LanaiRegisterInfo::eliminateFrameIndex(), llvm::SIRegisterInfo::eliminateFrameIndex(), llvm::SIInstrInfo::getAddNoCarry(), indirectCopyToAGPR(), InsertFPConstInst(), llvm::XtensaInstrInfo::insertIndirectBranch(), llvm::SIInstrInfo::insertIndirectBranch(), llvm::LoongArchInstrInfo::insertIndirectBranch(), llvm::RISCVInstrInfo::insertIndirectBranch(), InsertSPConstInst(), llvm::SGPRSpillBuilder::prepare(), replaceFrameIndex(), and scavengeVReg().

◆ setRegUsed()

void RegScavenger::setRegUsed ( Register  Reg,
LaneBitmask  LaneMask = LaneBitmask::getAll() 
)

The documentation for this class was generated from the following files: