LLVM 20.0.0git
|
A set of physical registers with utility functions to track liveness when walking backward/forward through a basic block. More...
#include "llvm/CodeGen/LivePhysRegs.h"
Public Types | |
using | const_iterator = RegisterSet::const_iterator |
Public Member Functions | |
LivePhysRegs ()=default | |
Constructs an unitialized set. init() needs to be called to initialize it. | |
LivePhysRegs (const TargetRegisterInfo &TRI) | |
Constructs and initializes an empty set. | |
LivePhysRegs (const LivePhysRegs &)=delete | |
LivePhysRegs & | operator= (const LivePhysRegs &)=delete |
void | init (const TargetRegisterInfo &TRI) |
(re-)initializes and clears the set. | |
void | clear () |
Clears the set. | |
bool | empty () const |
Returns true if the set is empty. | |
void | addReg (MCPhysReg Reg) |
Adds a physical register and all its sub-registers to the set. | |
void | removeReg (MCPhysReg Reg) |
Removes a physical register, all its sub-registers, and all its super-registers from the set. | |
void | removeRegsInMask (const MachineOperand &MO, SmallVectorImpl< std::pair< MCPhysReg, const MachineOperand * > > *Clobbers=nullptr) |
Removes physical registers clobbered by the regmask operand MO . | |
bool | contains (MCPhysReg Reg) const |
Returns true if register Reg is contained in the set. | |
bool | available (const MachineRegisterInfo &MRI, MCPhysReg Reg) const |
Returns true if register Reg and no aliasing register is in the set. | |
void | removeDefs (const MachineInstr &MI) |
Remove defined registers and regmask kills from the set. | |
void | addUses (const MachineInstr &MI) |
Add uses to the set. | |
void | stepBackward (const MachineInstr &MI) |
Simulates liveness when stepping backwards over an instruction(bundle). | |
void | stepForward (const MachineInstr &MI, SmallVectorImpl< std::pair< MCPhysReg, const MachineOperand * > > &Clobbers) |
Simulates liveness when stepping forward over an instruction(bundle). | |
void | addLiveIns (const MachineBasicBlock &MBB) |
Adds all live-in registers of basic block MBB . | |
void | addLiveInsNoPristines (const MachineBasicBlock &MBB) |
Adds all live-in registers of basic block MBB but skips pristine registers. | |
void | addLiveOuts (const MachineBasicBlock &MBB) |
Adds all live-out registers of basic block MBB . | |
void | addLiveOutsNoPristines (const MachineBasicBlock &MBB) |
Adds all live-out registers of basic block MBB but skips pristine registers. | |
const_iterator | begin () const |
const_iterator | end () const |
void | print (raw_ostream &OS) const |
Prints the currently live registers to OS . | |
void | dump () const |
Dumps the currently live registers to the debug output. | |
A set of physical registers with utility functions to track liveness when walking backward/forward through a basic block.
Definition at line 52 of file LivePhysRegs.h.
Definition at line 156 of file LivePhysRegs.h.
|
default |
Constructs an unitialized set. init() needs to be called to initialize it.
|
inline |
Constructs and initializes an empty set.
Definition at line 62 of file LivePhysRegs.h.
References llvm::SparseSet< ValueT, KeyFunctorT, SparseT >::setUniverse(), and TRI.
|
delete |
void LivePhysRegs::addLiveIns | ( | const MachineBasicBlock & | MBB | ) |
Adds all live-in registers of basic block MBB
.
Live in registers are the registers in the blocks live-in list and the pristine registers.
Definition at line 238 of file LivePhysRegs.cpp.
References llvm::MachineBasicBlock::getParent(), and MBB.
Referenced by getLiveInRegsAt(), and getLiveRegsForEntryMBB().
void LivePhysRegs::addLiveInsNoPristines | ( | const MachineBasicBlock & | MBB | ) |
Adds all live-in registers of basic block MBB
but skips pristine registers.
Definition at line 244 of file LivePhysRegs.cpp.
References MBB.
void LivePhysRegs::addLiveOuts | ( | const MachineBasicBlock & | MBB | ) |
Adds all live-out registers of basic block MBB
.
Live out registers are the union of the live-in registers of the successor blocks and pristine registers. Live out registers of the end block are the callee saved registers. If a register is not added by this method, it is guaranteed to not be live out from MBB, although a sub-register may be. This is true both before and after regalloc.
Definition at line 232 of file LivePhysRegs.cpp.
References addLiveOutsNoPristines(), llvm::MachineBasicBlock::getParent(), and MBB.
Referenced by getLiveOutRegsAt(), getLivePhysRegsUpTo(), llvm::X86InstrInfo::replaceBranchWithTailCall(), and llvm::MachineBasicBlock::splitAt().
void LivePhysRegs::addLiveOutsNoPristines | ( | const MachineBasicBlock & | MBB | ) |
Adds all live-out registers of basic block MBB
but skips pristine registers.
Definition at line 209 of file LivePhysRegs.cpp.
References addReg(), llvm::MachineFrameInfo::getCalleeSavedInfo(), llvm::MachineFunction::getFrameInfo(), llvm::MachineBasicBlock::getParent(), Info, llvm::MachineFrameInfo::isCalleeSavedInfoValid(), llvm::MachineBasicBlock::isReturnBlock(), MBB, and llvm::MachineBasicBlock::successors().
Referenced by addLiveOuts(), llvm::computeLiveIns(), and llvm::recomputeLivenessFlags().
|
inline |
Adds a physical register and all its sub-registers to the set.
Definition at line 83 of file LivePhysRegs.h.
References assert(), llvm::SparseSet< ValueT, KeyFunctorT, SparseT >::insert(), Reg, SubReg, and TRI.
Referenced by addCalleeSavedRegs(), addLiveOutsNoPristines(), addUses(), getLiveRegsForEntryMBB(), and stepForward().
void LivePhysRegs::addUses | ( | const MachineInstr & | MI | ) |
Add uses to the set.
Definition at line 58 of file LivePhysRegs.cpp.
References addReg(), MI, and llvm::phys_regs_and_masks().
Referenced by llvm::recomputeLivenessFlags(), and stepBackward().
bool LivePhysRegs::available | ( | const MachineRegisterInfo & | MRI, |
MCPhysReg | Reg | ||
) | const |
Returns true if register Reg
and no aliasing register is in the set.
Definition at line 141 of file LivePhysRegs.cpp.
References llvm::SparseSet< ValueT, KeyFunctorT, SparseT >::count(), and MRI.
Referenced by llvm::AArch64FrameLowering::canUseAsPrologue(), llvm::HexagonInstrInfo::expandPostRAPseudo(), findScratchNonCalleeSaveRegister(), INITIALIZE_PASS(), and llvm::recomputeLivenessFlags().
|
inline |
Definition at line 158 of file LivePhysRegs.h.
References llvm::SparseSet< ValueT, KeyFunctorT, SparseT >::begin().
|
inline |
Clears the set.
Definition at line 77 of file LivePhysRegs.h.
References llvm::SparseSet< ValueT, KeyFunctorT, SparseT >::clear().
Returns true if register Reg
is contained in the set.
This also works if only the super register of Reg
has been defined, because addReg() always adds all sub-registers to the set as well. Note: Returns false if just some sub registers are live, use available() when searching a free register.
Definition at line 109 of file LivePhysRegs.h.
References llvm::SparseSet< ValueT, KeyFunctorT, SparseT >::count(), and Reg.
Referenced by CMSEPushCalleeSaves(), and llvm::HexagonInstrInfo::copyPhysReg().
LLVM_DUMP_METHOD void LivePhysRegs::dump | ( | ) | const |
Dumps the currently live registers to the debug output.
Definition at line 136 of file LivePhysRegs.cpp.
References llvm::dbgs().
|
inline |
Returns true if the set is empty.
Definition at line 80 of file LivePhysRegs.h.
References llvm::SparseSet< ValueT, KeyFunctorT, SparseT >::empty().
Referenced by print().
|
inline |
Definition at line 159 of file LivePhysRegs.h.
References llvm::SparseSet< ValueT, KeyFunctorT, SparseT >::end().
|
inline |
(re-)initializes and clears the set.
Definition at line 70 of file LivePhysRegs.h.
References llvm::SparseSet< ValueT, KeyFunctorT, SparseT >::clear(), llvm::SparseSet< ValueT, KeyFunctorT, SparseT >::setUniverse(), and TRI.
Referenced by llvm::computeLiveIns(), llvm::recomputeLivenessFlags(), and llvm::MachineBasicBlock::splitAt().
|
delete |
void LivePhysRegs::print | ( | raw_ostream & | OS | ) | const |
Prints the currently live registers to OS
.
Print the currently live registers to OS.
Definition at line 118 of file LivePhysRegs.cpp.
References empty(), OS, and llvm::printReg().
Referenced by llvm::operator<<().
void LivePhysRegs::removeDefs | ( | const MachineInstr & | MI | ) |
Remove defined registers and regmask kills from the set.
Definition at line 45 of file LivePhysRegs.cpp.
References MI, llvm::phys_regs_and_masks(), removeReg(), and removeRegsInMask().
Referenced by llvm::recomputeLivenessFlags(), and stepBackward().
|
inline |
Removes a physical register, all its sub-registers, and all its super-registers from the set.
Definition at line 92 of file LivePhysRegs.h.
References assert(), llvm::SparseSet< ValueT, KeyFunctorT, SparseT >::erase(), Reg, and TRI.
Referenced by llvm::AArch64FrameLowering::emitPrologue(), removeDefs(), and stepForward().
void LivePhysRegs::removeRegsInMask | ( | const MachineOperand & | MO, |
SmallVectorImpl< std::pair< MCPhysReg, const MachineOperand * > > * | Clobbers = nullptr |
||
) |
Removes physical registers clobbered by the regmask operand MO
.
Remove all registers from the set that get clobbered by the register mask.
The clobbers set will be the list of live registers clobbered by the regmask.
Definition at line 31 of file LivePhysRegs.cpp.
References llvm::SparseSet< ValueT, KeyFunctorT, SparseT >::begin(), llvm::MachineOperand::clobbersPhysReg(), llvm::SparseSet< ValueT, KeyFunctorT, SparseT >::end(), and llvm::SparseSet< ValueT, KeyFunctorT, SparseT >::erase().
Referenced by removeDefs(), and stepForward().
void LivePhysRegs::stepBackward | ( | const MachineInstr & | MI | ) |
Simulates liveness when stepping backwards over an instruction(bundle).
Simulates liveness when stepping backwards over an instruction(bundle): Remove Defs, add uses.
Remove Defs, add uses. This is the recommended way of calculating liveness.
This is the recommended way of calculating liveness.
Definition at line 68 of file LivePhysRegs.cpp.
References addUses(), MI, and removeDefs().
Referenced by llvm::computeLiveIns(), getLiveOutRegsAt(), getLivePhysRegsUpTo(), and llvm::MachineBasicBlock::splitAt().
void LivePhysRegs::stepForward | ( | const MachineInstr & | MI, |
SmallVectorImpl< std::pair< MCPhysReg, const MachineOperand * > > & | Clobbers | ||
) |
Simulates liveness when stepping forward over an instruction(bundle).
Simulates liveness when stepping forward over an instruction(bundle): Remove killed-uses, add defs.
Remove killed-uses, add defs. This is the not recommended way, because it depends on accurate kill flags. If possible use stepBackward() instead of this function. The clobbers set will be the list of registers either defined or clobbered by a regmask. The operand will identify whether this is a regmask or register operand.
This is the not recommended way, because it depends on accurate kill flags. If possible use stepBackward() instead of this function.
Definition at line 80 of file LivePhysRegs.cpp.
References addReg(), assert(), llvm::MachineOperand::clobbersPhysReg(), MI, removeReg(), and removeRegsInMask().
Referenced by getLiveInRegsAt(), llvm::X86InstrInfo::replaceBranchWithTailCall(), and UpdatePredRedefs().