LLVM 20.0.0git
Public Types | Public Member Functions | Friends | List of all members
llvm::LiveRegMatrix Class Reference

#include "llvm/CodeGen/LiveRegMatrix.h"

Public Types

enum  InterferenceKind { IK_Free = 0 , IK_VirtReg , IK_RegUnit , IK_RegMask }
 

Public Member Functions

 LiveRegMatrix (LiveRegMatrix &&Other)
 
void init (MachineFunction &MF, LiveIntervals &LIS, VirtRegMap &VRM)
 
void invalidateVirtRegs ()
 Invalidate cached interference queries after modifying virtual register live ranges.
 
InterferenceKind checkInterference (const LiveInterval &VirtReg, MCRegister PhysReg)
 Check for interference before assigning VirtReg to PhysReg.
 
bool checkInterference (SlotIndex Start, SlotIndex End, MCRegister PhysReg)
 Check for interference in the segment [Start, End) that may prevent assignment to PhysReg.
 
LaneBitmask checkInterferenceLanes (SlotIndex Start, SlotIndex End, MCRegister PhysReg)
 Check for interference in the segment [Start, End) that may prevent assignment to PhysReg, like checkInterference.
 
void assign (const LiveInterval &VirtReg, MCRegister PhysReg)
 Assign VirtReg to PhysReg.
 
void unassign (const LiveInterval &VirtReg)
 Unassign VirtReg from its PhysReg.
 
bool isPhysRegUsed (MCRegister PhysReg) const
 Returns true if the given PhysReg has any live intervals assigned.
 
bool checkRegMaskInterference (const LiveInterval &VirtReg, MCRegister PhysReg=MCRegister::NoRegister)
 Check for regmask interference only.
 
bool checkRegUnitInterference (const LiveInterval &VirtReg, MCRegister PhysReg)
 Check for regunit interference only.
 
LiveIntervalUnion::Queryquery (const LiveRange &LR, MCRegister RegUnit)
 Query a line of the assigned virtual register matrix directly.
 
LiveIntervalUniongetLiveUnions ()
 Directly access the live interval unions per regunit.
 
Register getOneVReg (unsigned PhysReg) const
 

Friends

class LiveRegMatrixWrapperLegacy
 
class LiveRegMatrixAnalysis
 

Detailed Description

Definition at line 40 of file LiveRegMatrix.h.

Member Enumeration Documentation

◆ InterferenceKind

Enumerator
IK_Free 

No interference, go ahead and assign.

IK_VirtReg 

Virtual register interference.

There are interfering virtual registers assigned to PhysReg or its aliases. This interference could be resolved by unassigning those other virtual registers.

IK_RegUnit 

Register unit interference.

A fixed live range is in the way, typically argument registers for a call. This can't be resolved by unassigning other virtual registers.

IK_RegMask 

RegMask interference.

The live range is crossing an instruction with a regmask operand that doesn't preserve PhysReg. This typically means VirtReg is live across a call, and PhysReg isn't call-preserved.

Definition at line 87 of file LiveRegMatrix.h.

Constructor & Destructor Documentation

◆ LiveRegMatrix()

llvm::LiveRegMatrix::LiveRegMatrix ( LiveRegMatrix &&  Other)
inline

Definition at line 66 of file LiveRegMatrix.h.

Member Function Documentation

◆ assign()

void LiveRegMatrix::assign ( const LiveInterval VirtReg,
MCRegister  PhysReg 
)

Assign VirtReg to PhysReg.

This will mark VirtReg's live range as occupied in the LiveRegMatrix and update VirtRegMap. The live range is expected to be available in PhysReg.

Definition at line 111 of file LiveRegMatrix.cpp.

References assert(), llvm::VirtRegMap::assignVirt2Phys(), llvm::dbgs(), foreachUnit(), llvm::VirtRegMap::hasPhys(), LLVM_DEBUG, llvm::printReg(), llvm::printRegUnit(), Range, and llvm::LiveInterval::reg().

Referenced by llvm::RegAllocBase::allocatePhysRegs().

◆ checkInterference() [1/2]

LiveRegMatrix::InterferenceKind LiveRegMatrix::checkInterference ( const LiveInterval VirtReg,
MCRegister  PhysReg 
)

Check for interference before assigning VirtReg to PhysReg.

If this function returns IK_Free, it is legal to assign(VirtReg, PhysReg). When there is more than one kind of interference, the InterferenceKind with the highest enum value is returned.

Definition at line 193 of file LiveRegMatrix.cpp.

References llvm::LiveIntervalUnion::Query::checkInterference(), checkRegMaskInterference(), checkRegUnitInterference(), llvm::LiveRange::empty(), foreachUnit(), IK_Free, IK_RegMask, IK_RegUnit, IK_VirtReg, and query().

◆ checkInterference() [2/2]

bool LiveRegMatrix::checkInterference ( SlotIndex  Start,
SlotIndex  End,
MCRegister  PhysReg 
)

Check for interference in the segment [Start, End) that may prevent assignment to PhysReg.

If this function returns true, there is interference in the segment [Start, End) of some other interval already assigned to PhysReg. If this function returns false, PhysReg is free at the segment [Start, End).

Definition at line 217 of file LiveRegMatrix.cpp.

References llvm::LiveRange::addSegment(), llvm::LiveIntervalUnion::Query::checkInterference(), End, llvm::MCRegisterInfo::regunits(), and llvm::LiveIntervalUnion::Query::reset().

◆ checkInterferenceLanes()

LaneBitmask LiveRegMatrix::checkInterferenceLanes ( SlotIndex  Start,
SlotIndex  End,
MCRegister  PhysReg 
)

Check for interference in the segment [Start, End) that may prevent assignment to PhysReg, like checkInterference.

Returns a lane mask of which lanes of the physical register interfere in the segment [Start, End) of some other interval already assigned to PhysReg.

If this function returns LaneBitmask::getNone(), PhysReg is completely free at the segment [Start, End).

Definition at line 247 of file LiveRegMatrix.cpp.

References llvm::LiveRange::addSegment(), llvm::LiveIntervalUnion::Query::checkInterference(), End, llvm::MCRegUnitMaskIterator::isValid(), and llvm::LiveIntervalUnion::Query::reset().

◆ checkRegMaskInterference()

bool LiveRegMatrix::checkRegMaskInterference ( const LiveInterval VirtReg,
MCRegister  PhysReg = MCRegister::NoRegister 
)

Check for regmask interference only.

Return true if VirtReg crosses a regmask operand that clobbers PhysReg. If PhysReg is null, check if VirtReg crosses any regmask operands.

Definition at line 153 of file LiveRegMatrix.cpp.

References llvm::LiveIntervals::checkRegMaskInterference(), llvm::BitVector::clear(), llvm::BitVector::empty(), llvm::LiveInterval::reg(), and llvm::BitVector::test().

Referenced by checkInterference().

◆ checkRegUnitInterference()

bool LiveRegMatrix::checkRegUnitInterference ( const LiveInterval VirtReg,
MCRegister  PhysReg 
)

Check for regunit interference only.

Return true if VirtReg overlaps a fixed assignment of one of PhysRegs's register units.

Definition at line 171 of file LiveRegMatrix.cpp.

References llvm::LiveRange::empty(), foreachUnit(), llvm::LiveIntervals::getRegUnit(), llvm::LiveIntervals::getSlotIndexes(), Range, and llvm::LiveInterval::reg().

Referenced by checkInterference().

◆ getLiveUnions()

LiveIntervalUnion * llvm::LiveRegMatrix::getLiveUnions ( )
inline

Directly access the live interval unions per regunit.

This returns an array indexed by the regunit number.

Definition at line 171 of file LiveRegMatrix.h.

References Matrix.

Referenced by llvm::RegAllocEvictionAdvisor::canReassign(), and llvm::RAGreedy::runOnMachineFunction().

◆ getOneVReg()

Register LiveRegMatrix::getOneVReg ( unsigned  PhysReg) const

◆ init()

void LiveRegMatrix::init ( MachineFunction MF,
LiveIntervals LIS,
VirtRegMap VRM 
)

◆ invalidateVirtRegs()

void llvm::LiveRegMatrix::invalidateVirtRegs ( )
inline

Invalidate cached interference queries after modifying virtual register live ranges.

Interference checks may return stale information unless caches are invalidated.

Definition at line 85 of file LiveRegMatrix.h.

Referenced by llvm::RegAllocBase::allocatePhysRegs(), and init().

◆ isPhysRegUsed()

bool LiveRegMatrix::isPhysRegUsed ( MCRegister  PhysReg) const

Returns true if the given PhysReg has any live intervals assigned.

Definition at line 145 of file LiveRegMatrix.cpp.

References llvm::MCRegisterInfo::regunits().

Referenced by llvm::RegAllocEvictionAdvisor::isUnusedCalleeSavedReg().

◆ query()

LiveIntervalUnion::Query & LiveRegMatrix::query ( const LiveRange LR,
MCRegister  RegUnit 
)

Query a line of the assigned virtual register matrix directly.

Use MCRegUnitIterator to enumerate all regunits in the desired PhysReg. This returns a reference to an internal Query data structure that is only valid until the next query() call.

Definition at line 185 of file LiveRegMatrix.cpp.

References llvm::LiveIntervalUnion::Query::init().

Referenced by checkInterference().

◆ unassign()

void LiveRegMatrix::unassign ( const LiveInterval VirtReg)

Unassign VirtReg from its PhysReg.

Assuming that VirtReg was previously assigned to a PhysReg, this undoes the assignment and updates VirtRegMap accordingly.

Definition at line 128 of file LiveRegMatrix.cpp.

References llvm::VirtRegMap::clearVirt(), llvm::dbgs(), foreachUnit(), llvm::VirtRegMap::getPhys(), LLVM_DEBUG, llvm::printReg(), llvm::printRegUnit(), Range, and llvm::LiveInterval::reg().

Friends And Related Function Documentation

◆ LiveRegMatrixAnalysis

friend class LiveRegMatrixAnalysis
friend

Definition at line 42 of file LiveRegMatrix.h.

◆ LiveRegMatrixWrapperLegacy

friend class LiveRegMatrixWrapperLegacy
friend

Definition at line 41 of file LiveRegMatrix.h.


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