LLVM 23.0.0git
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)=default
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, bool ClearAllReferencingSegments=false)
 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, MCRegUnit 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
bool isValid () const
 This checks that each LiveInterval referenced in LiveIntervalUnion actually exists in LiveIntervals and is not a dangling pointer.

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 84 of file LiveRegMatrix.h.

Constructor & Destructor Documentation

◆ LiveRegMatrix()

llvm::LiveRegMatrix::LiveRegMatrix ( LiveRegMatrix && Other)
default

References llvm::Other.

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 113 of file LiveRegMatrix.cpp.

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

◆ 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 203 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 227 of file LiveRegMatrix.cpp.

References llvm::LiveRange::addSegment(), llvm::LiveIntervalUnion::Query::checkInterference(), 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 257 of file LiveRegMatrix.cpp.

References llvm::LiveRange::addSegment(), llvm::LiveIntervalUnion::Query::checkInterference(), 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 162 of file LiveRegMatrix.cpp.

References llvm::MCRegister::id(), and llvm::LiveInterval::reg().

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 181 of file LiveRegMatrix.cpp.

References llvm::LiveRange::empty(), foreachUnit(), 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 175 of file LiveRegMatrix.h.

◆ getOneVReg()

Register LiveRegMatrix::getOneVReg ( unsigned PhysReg) const

Definition at line 292 of file LiveRegMatrix.cpp.

References getOneVReg(), llvm::MCRegister::NoRegister, and llvm::LiveInterval::reg().

Referenced by getOneVReg().

◆ init()

◆ 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 82 of file LiveRegMatrix.h.

Referenced by init().

◆ isPhysRegUsed()

bool LiveRegMatrix::isPhysRegUsed ( MCRegister PhysReg) const

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

Definition at line 154 of file LiveRegMatrix.cpp.

◆ isValid()

bool LiveRegMatrix::isValid ( ) const

◆ query()

LiveIntervalUnion::Query & LiveRegMatrix::query ( const LiveRange & LR,
MCRegUnit 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 195 of file LiveRegMatrix.cpp.

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

Referenced by checkInterference().

◆ unassign()

void LiveRegMatrix::unassign ( const LiveInterval & VirtReg,
bool ClearAllReferencingSegments = false )

Unassign VirtReg from its PhysReg.

Assuming that VirtReg was previously assigned to a PhysReg, this undoes the assignment and updates VirtRegMap accordingly. ClearAllReferencingSegments changes the way segments are removed from the matrix:

  • If false (default), only segments that exactly match VirtReg's live range are removed.
  • If true, all segments that reference VirtReg are removed. This is useful when VirtReg's live range(s) is already empty.

Definition at line 130 of file LiveRegMatrix.cpp.

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

◆ LiveRegMatrixAnalysis

friend class LiveRegMatrixAnalysis
friend

Definition at line 42 of file LiveRegMatrix.h.

References Allocator, and LiveRegMatrixAnalysis.

Referenced by LiveRegMatrixAnalysis.

◆ LiveRegMatrixWrapperLegacy

friend class LiveRegMatrixWrapperLegacy
friend

Definition at line 41 of file LiveRegMatrix.h.

References LiveRegMatrixWrapperLegacy.

Referenced by LiveRegMatrixWrapperLegacy.


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