35#define DEBUG_TYPE "regalloc"
37STATISTIC(NumAssigned ,
"Number of registers assigned");
38STATISTIC(NumUnassigned ,
"Number of registers unassigned");
42 "Live Register Matrix",
false,
false)
58 LRM.init(MF, LIS, VRM);
68 unsigned NumRegUnits = TRI->getNumRegUnits();
69 if (NumRegUnits != Matrix.size())
71 Matrix.
init(*LIUAlloc, NumRegUnits);
79void LiveRegMatrix::releaseMemory() {
80 for (
unsigned i = 0, e =
Matrix.size(); i != e; ++i) {
81 Matrix[
static_cast<MCRegUnit
>(i)].clear();
88template <
typename Callable>
94 MCRegUnit Unit = (*Units).first;
97 if ((S.LaneMask & Mask).any()) {
105 for (MCRegUnit Unit :
TRI->regunits(PhysReg)) {
106 if (Func(Unit, VRegInterval))
116 assert(!VRM->hasPhys(VirtReg.
reg()) &&
"Duplicate VirtReg assignment");
117 VRM->assignVirt2Phys(VirtReg.
reg(), PhysReg);
120 TRI, VirtReg, PhysReg, [&](MCRegUnit Unit,
const LiveRange &
Range) {
122 Matrix[Unit].unify(VirtReg,
Range);
131 bool ClearAllReferencingSegments) {
134 <<
" from " <<
printReg(PhysReg, TRI) <<
':');
135 VRM->clearVirt(VirtReg.
reg());
137 if (!ClearAllReferencingSegments) {
141 Matrix[Unit].extract(VirtReg,
Range);
145 for (MCRegUnit Unit : TRI->regunits(PhysReg)) {
146 Matrix[Unit].clearAllSegmentsReferencing(VirtReg);
155 for (MCRegUnit Unit : TRI->regunits(PhysReg)) {
156 if (!Matrix[Unit].empty())
167 if (RegMaskVirtReg != VirtReg.
reg() || RegMaskTag != UserTag) {
168 RegMaskVirtReg = VirtReg.
reg();
169 RegMaskTag = UserTag;
170 RegMaskUsable.clear();
171 LIS->checkRegMaskInterference(VirtReg, RegMaskUsable);
177 return !RegMaskUsable.empty() &&
178 (!PhysReg || !RegMaskUsable.test(PhysReg.
id()));
188 TRI, VirtReg, PhysReg, [&](MCRegUnit Unit,
const LiveRange &
Range) {
189 const LiveRange &UnitRange = LIS->getRegUnit(Unit);
190 return Range.overlaps(UnitRange, CP, *LIS->getSlotIndexes());
198 Q.
init(UserTag, LR, Matrix[RegUnit]);
217 bool Interference =
foreachUnit(TRI, VirtReg, PhysReg,
218 [&](MCRegUnit Unit,
const LiveRange &LR) {
236 for (MCRegUnit Unit : TRI->regunits(PhysReg)) {
250 Q.
reset(UserTag, LR, Matrix[Unit]);
270 auto [Unit, Lanes] = *MCRU;
284 Q.
reset(UserTag, LR, Matrix[Unit]);
286 InterferingLanes |= Lanes;
289 return InterferingLanes;
294 for (MCRegUnit Unit : TRI->regunits(PhysReg)) {
295 if ((VRegInterval = Matrix[Unit].
getOneVReg()))
296 return VRegInterval->
reg();
306 for (
unsigned RegIdx = 0, NumRegs = VRM->getRegInfo().getNumVirtRegs();
307 RegIdx < NumRegs; ++RegIdx) {
310 if (VRM->hasPhys(VReg) && LIS->hasInterval(VReg))
311 ValidIntervals.
insert(&LIS->getInterval(VReg));
315 unsigned NumDanglingPointers = 0;
316 for (
unsigned I = 0,
Size = Matrix.size();
I <
Size; ++
I) {
317 MCRegUnit Unit =
static_cast<MCRegUnit
>(
I);
320 ++NumDanglingPointers;
321 dbgs() <<
"ERROR: LiveInterval pointer is not found in LiveIntervals:\n"
322 <<
" Register Unit: " <<
printRegUnit(Unit, TRI) <<
'\n'
323 <<
" LiveInterval pointer: " << LI <<
'\n';
327 return NumDanglingPointers == 0;
338 LRM.
init(MF, LIS, VRM);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the DenseSet and SmallDenseSet classes.
A common definition of LaneBitmask for use in TableGen and CodeGen.
static bool foreachUnit(const TargetRegisterInfo *TRI, const LiveInterval &VRegInterval, MCRegister PhysReg, Callable Func)
Register const TargetRegisterInfo * TRI
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Represent the analysis usage information of a pass.
A helper class for register coalescers.
Implements a dense probed hash-table based set.
Query interferences between a single live virtual register and a live interval union.
void init(unsigned NewUserTag, const LiveRange &NewLR, const LiveIntervalUnion &NewLiveUnion)
void reset(unsigned NewUserTag, const LiveRange &NewLR, const LiveIntervalUnion &NewLiveUnion)
A live range for subregisters.
LiveInterval - This class represents the liveness of a register, or stack slot.
bool hasSubRanges() const
Returns true if subregister liveness information is available.
iterator_range< subrange_iterator > subranges()
This class represents the liveness of a register, stack slot, etc.
LLVM_ABI iterator addSegment(Segment S)
Add the specified Segment to this range, merging segments as appropriate.
LiveRegMatrix run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
void releaseMemory() override
releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memo...
LiveRegMatrixWrapperLegacy()
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
bool checkRegMaskInterference(const LiveInterval &VirtReg, MCRegister PhysReg=MCRegister::NoRegister)
Check for regmask interference only.
bool isPhysRegUsed(MCRegister PhysReg) const
Returns true if the given PhysReg has any live intervals assigned.
void invalidateVirtRegs()
Invalidate cached interference queries after modifying virtual register live ranges.
Register getOneVReg(unsigned PhysReg) const
LiveIntervalUnion::Query & query(const LiveRange &LR, MCRegUnit RegUnit)
Query a line of the assigned virtual register matrix directly.
void unassign(const LiveInterval &VirtReg, bool ClearAllReferencingSegments=false)
Unassign VirtReg from its PhysReg.
bool isValid() const
This checks that each LiveInterval referenced in LiveIntervalUnion actually exists in LiveIntervals a...
@ IK_VirtReg
Virtual register interference.
@ IK_RegUnit
Register unit interference.
@ IK_Free
No interference, go ahead and assign.
@ IK_RegMask
RegMask interference.
void init(MachineFunction &MF, LiveIntervals &LIS, VirtRegMap &VRM)
void assign(const LiveInterval &VirtReg, MCRegister PhysReg)
Assign VirtReg to PhysReg.
InterferenceKind checkInterference(const LiveInterval &VirtReg, MCRegister PhysReg)
Check for interference before assigning VirtReg to PhysReg.
bool checkRegUnitInterference(const LiveInterval &VirtReg, MCRegister PhysReg)
Check for regunit interference only.
LaneBitmask checkInterferenceLanes(SlotIndex Start, SlotIndex End, MCRegister PhysReg)
Check for interference in the segment [Start, End) that may prevent assignment to PhysReg,...
MCRegUnitMaskIterator enumerates a list of register units and their associated lane masks for Reg.
bool isValid() const
Returns true if this iterator is not yet at the end.
Wrapper class representing physical registers. Should be passed by value.
static constexpr unsigned NoRegister
constexpr unsigned id() const
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
AnalysisType & getAnalysis() const
getAnalysis<AnalysisType>() - This function is used by subclasses to get to the analysis information ...
Wrapper class representing virtual and physical registers.
static Register index2VirtReg(unsigned Index)
Convert a 0-based index to a virtual register number.
SlotIndex - An opaque wrapper around machine indexes.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
VNInfo - Value Number Information.
LLVM_ABI void init(MachineFunction &MF)
std::pair< iterator, bool > insert(const ValueT &V)
bool contains(const_arg_type_t< ValueT > V) const
Check if the set contains the given element.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI Printable printRegUnit(MCRegUnit Unit, const TargetRegisterInfo *TRI)
Create Printable object to print register units on a raw_ostream.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
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.
A special type used by analysis passes to provide an address that identifies that particular analysis...
This represents a simple continuous liveness interval for a value.