39#define DEBUG_TYPE "regalloc"
41STATISTIC(NumNewQueued,
"Number of new live ranges queued");
58void RegAllocBase::anchor() {}
68 MRI->freezeReservedRegs();
77void RegAllocBase::seedLiveRegs() {
80 for (
unsigned i = 0, e =
MRI->getNumVirtRegs(); i != e; ++i) {
82 if (
MRI->reg_nodbg_empty(Reg))
95 assert(!
VRM->hasPhys(VirtReg->reg()) &&
"Register already assigned");
98 if (
MRI->reg_nodbg_empty(VirtReg->reg())) {
101 LIS->removeInterval(VirtReg->reg());
106 Matrix->invalidateVirtRegs();
112 <<
TRI->getRegClassName(
MRI->getRegClass(VirtReg->reg()))
113 <<
':' << *VirtReg <<
'\n');
117 VirtRegVec SplitVRegs;
120 if (AvailablePhysReg == ~0u) {
126 if (
MI->isInlineAsm())
135 }
else if (AvailablePhysReg)
136 Matrix->assign(*VirtReg, AvailablePhysReg);
142 assert(!
VRM->hasPhys(SplitVirtReg->
reg()) &&
"Register already assigned");
143 if (
MRI->reg_nodbg_empty(SplitVirtReg->
reg())) {
144 assert(SplitVirtReg->
empty() &&
"Non-empty but used interval");
145 LLVM_DEBUG(
dbgs() <<
"not queueing unused " << *SplitVirtReg <<
'\n');
147 LIS->removeInterval(SplitVirtReg->
reg());
150 LLVM_DEBUG(
dbgs() <<
"queuing new interval: " << *SplitVirtReg <<
"\n");
152 "expect split value in virtual register");
163 assert(
Matrix->isValid() &&
"LiveRegMatrix validation failed");
166 LIS->RemoveMachineInstrFromMaps(*DeadInst);
167 DeadInst->eraseFromParent();
184 if (!
MRI->isReserved(PhysReg)) {
199 MRI->replaceRegWith(FailedReg, PhysReg);
200 LIS->removeInterval(FailedReg);
206 return MO.getReg() == FailedReg || MO.getReg() == PhysReg;
210 std::optional<bool> AssignedIsDead;
211 bool AnyLive =
false;
214 if (IsErrorDef(MO)) {
215 AnyLive |= !MO.isDead();
216 if (
MRI->isReserved(PhysReg))
223 DefReg =
TRI->getSubReg(PhysReg, MO.getSubReg());
225 SlotIndex DefIdx = Idx.getRegSlot(MO.isEarlyClobber());
226 for (MCRegUnit Unit :
TRI->regunits(DefReg)) {
228 if (LR && !LR->
liveAt(DefIdx))
231 }
else if (Reg.isVirtual() &&
VRM->hasPhys(Reg)) {
234 AssignedReg =
TRI->getSubReg(AssignedReg, MO.getSubReg());
235 if (AssignedReg == PhysReg)
236 AssignedIsDead = MO.isDead();
242 bool IsDead = AssignedIsDead.value_or(!AnyLive);
252 assert(Reg.isVirtual() &&
"Can only enqueue virtual registers");
254 if (
VRM->hasPhys(Reg))
262 <<
" in skipped register class\n");
280 if (AllocOrder.
empty()) {
288 "no registers from class available to allocate", Fn,
292 assert(!RawRegs.
empty() &&
"register classes cannot have no registers");
293 return RawRegs.
front();
299 "inline assembly requires more registers than available");
302 "ran out of registers during register allocation", Fn,
307 return AllocOrder.
front();
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Module.h This file contains the declarations for the Module class.
This header defines classes/functions to handle pass execution timing information with interfaces for...
MachineRegisterInfo & MRI
static cl::opt< bool, true > VerifyRegAlloc("verify-regalloc", cl::location(RegAllocBase::VerifyEnabled), cl::Hidden, cl::desc("Verify during register allocation"))
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)
Represent a constant reference to an array (0 or more elements consecutively in memory),...
const T & front() const
Get the first element.
bool empty() const
Check if the array is empty.
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
This is an important class for using LLVM in a threaded context.
LiveInterval - This class represents the liveness of a register, or stack slot.
LiveInterval & getInterval(Register Reg)
This class represents the liveness of a register, stack slot, etc.
bool liveAt(SlotIndex index) const
LLVM_ABI VNInfo * createDeadDef(SlotIndex Def, VNInfo::Allocator &VNIAlloc)
createDeadDef - Make sure the range has a value defined at Def.
MCRegAliasIterator enumerates all registers aliasing Reg.
ArrayRef< MCPhysReg > getRegisters() const
Wrapper class representing physical registers. Should be passed by value.
Function & getFunction()
Return the LLVM function that this machine code represents.
const MachineFunctionProperties & getProperties() const
Get the function properties.
Representation of each machine instruction.
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
LLVM_ABI void emitInlineAsmError(const Twine &ErrMsg) const
Emit an error referring to the source location of this instruction.
MachineOperand class - Representation of each machine instruction operand.
virtual void aboutToRemoveInterval(const LiveInterval &LI)
Method called when the allocator is about to remove a LiveInterval.
virtual MCRegister selectOrSplit(const LiveInterval &VirtReg, SmallVectorImpl< Register > &splitLVRs)=0
MCPhysReg getErrorAssignment(const TargetRegisterClass &RC, const MachineInstr *CtxMI=nullptr)
Query a physical register to use as a filler in contexts where the allocation has failed.
void enqueue(const LiveInterval *LI)
enqueue - Add VirtReg to the priority queue of unassigned registers.
SmallPtrSet< MachineInstr *, 32 > DeadRemats
Inst which is a def of an original reg and whose defs are already all dead after remat is saved in De...
void cleanupFailedVReg(Register FailedVReg, MCRegister PhysReg, SmallVectorImpl< Register > &SplitRegs)
Perform cleanups on registers that failed to allocate.
SmallSet< Register, 2 > FailedVRegs
void cleanupFailedDefs(MachineInstr &MI, Register FailedReg, MCRegister PhysReg)
Add the defs of FailedReg on MI to the PhysReg regunit live ranges, and make the defs of PhysReg on M...
virtual Spiller & spiller()=0
const TargetRegisterInfo * TRI
static const char TimerGroupName[]
static const char TimerGroupDescription[]
void init(VirtRegMap &vrm, LiveIntervals &lis, LiveRegMatrix &mat, RegisterClassInfo &rci)
virtual const LiveInterval * dequeue()=0
dequeue - Return the next unassigned register, or NULL.
virtual void postOptimization()
MachineRegisterInfo * MRI
virtual void enqueueImpl(const LiveInterval *LI)=0
enqueue - Add VirtReg to the priority queue of unassigned registers.
bool shouldAllocateRegister(Register Reg)
Get whether a given register should be allocated.
RegisterClassInfo * RegClassInfo
static bool VerifyEnabled
VerifyEnabled - True when -verify-regalloc is given.
Wrapper class representing virtual and physical registers.
static Register index2VirtReg(unsigned Index)
Convert a 0-based index to a virtual register number.
constexpr bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
SlotIndex - An opaque wrapper around machine indexes.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
virtual void postOptimization()
MachineRegisterInfo & getRegInfo() const
const TargetRegisterInfo & getTargetRegInfo() const
LocationClass< Ty > location(Ty &L)
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI bool TimePassesIsEnabled
If the user specifies the -time-passes argument on an LLVM tool command line then the value of this b...
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
LLVM_ABI 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.
MCRegisterClass TargetRegisterClass
This class is basically a combination of TimeRegion and Timer.