LLVM 20.0.0git
Classes | Public Types | Public Member Functions | Public Attributes | List of all members
LiveDebugValues::MLocTracker Class Reference

Tracker for what values are in machine locations. More...

#include "CodeGen/LiveDebugValues/InstrRefBasedImpl.h"

Classes

class  MLocIterator
 Iterator for locations and the values they contain. More...
 

Public Types

using LocToValueType = IndexedMap< ValueIDNum, LocIdxToIndexFunctor >
 IndexedMap type, mapping from LocIdx to ValueIDNum.
 
typedef std::pair< unsigned short, unsigned short > StackSlotPos
 Pair for describing a position within a stack slot – first the size in bits, then the offset.
 

Public Member Functions

 MLocTracker (MachineFunction &MF, const TargetInstrInfo &TII, const TargetRegisterInfo &TRI, const TargetLowering &TLI)
 
unsigned getLocID (Register Reg)
 Produce location ID number for a Register.
 
unsigned getLocID (SpillLocationNo Spill, unsigned SpillSubReg)
 Produce location ID number for a spill position.
 
unsigned getLocID (SpillLocationNo Spill, StackSlotPos Idx)
 Produce location ID number for a spill position.
 
unsigned getSpillIDWithIdx (SpillLocationNo Spill, unsigned Idx)
 Given a spill number, and a slot within the spill, calculate the ID number for that location.
 
SpillLocationNo locIDToSpill (unsigned ID) const
 Return the spill number that a location ID corresponds to.
 
StackSlotPos locIDToSpillIdx (unsigned ID) const
 Returns the spill-slot size/offs that a location ID corresponds to.
 
unsigned getNumLocs () const
 
void setMPhis (unsigned NewCurBB)
 Reset all locations to contain a PHI value at the designated block.
 
void loadFromArray (ValueTable &Locs, unsigned NewCurBB)
 Load values for each location from array of ValueIDNums.
 
void reset ()
 Wipe any un-necessary location records after traversing a block.
 
void clear ()
 Clear all data.
 
void setMLoc (LocIdx L, ValueIDNum Num)
 Set a locaiton to a certain value.
 
ValueIDNum readMLoc (LocIdx L)
 Read the value of a particular location.
 
LocIdx trackRegister (unsigned ID)
 Create a LocIdx for an untracked register ID.
 
LocIdx lookupOrTrackRegister (unsigned ID)
 
bool isRegisterTracked (Register R)
 Is register R currently tracked by MLocTracker?
 
void defReg (Register R, unsigned BB, unsigned Inst)
 Record a definition of the specified register at the given block / inst.
 
void setReg (Register R, ValueIDNum ValueID)
 Set a register to a value number.
 
ValueIDNum readReg (Register R)
 
void wipeRegister (Register R)
 Reset a register value to zero / empty.
 
LocIdx getRegMLoc (Register R)
 Determine the LocIdx of an existing register.
 
void writeRegMask (const MachineOperand *MO, unsigned CurBB, unsigned InstID)
 Record a RegMask operand being executed.
 
std::optional< SpillLocationNogetOrTrackSpillLoc (SpillLoc L)
 Find LocIdx for SpillLoc L, creating a new one if it's not tracked.
 
LocIdx getSpillMLoc (unsigned SpillID)
 
bool isSpill (LocIdx Idx) const
 Return true if Idx is a spill machine location.
 
unsigned getLocSizeInBits (LocIdx L) const
 How large is this location (aka, how wide is a value defined there?).
 
MLocIterator begin ()
 
MLocIterator end ()
 
iterator_range< MLocIteratorlocations ()
 Return a range over all locations currently tracked.
 
std::string LocIdxToName (LocIdx Idx) const
 
std::string IDAsString (const ValueIDNum &Num) const
 
LLVM_DUMP_METHOD void dump ()
 
LLVM_DUMP_METHOD void dump_mloc_map ()
 
MachineInstrBuilder emitLoc (const SmallVectorImpl< ResolvedDbgOp > &DbgOps, const DebugVariable &Var, const DILocation *DILoc, const DbgValueProperties &Properties)
 Create a DBG_VALUE based on debug operands DbgOps.
 

Public Attributes

MachineFunctionMF
 
const TargetInstrInfoTII
 
const TargetRegisterInfoTRI
 
const TargetLoweringTLI
 
LocToValueType LocIdxToIDNum
 Map of LocIdxes to the ValueIDNums that they store.
 
std::vector< LocIdxLocIDToLocIdx
 "Map" of machine location IDs (i.e., raw register or spill number) to the LocIdx key / number for that location.
 
IndexedMap< unsigned, LocIdxToIndexFunctorLocIdxToLocID
 Inverse map of LocIDToLocIdx.
 
SmallSet< Register, 8 > SPAliases
 When clobbering register masks, we chose to not believe the machine model and don't clobber SP.
 
UniqueVector< SpillLocSpillLocs
 Unique-ification of spill.
 
unsigned CurBB = -1
 
unsigned NumRegs
 Cached local copy of the number of registers the target has.
 
unsigned NumSlotIdxes
 Number of slot indexes the target has – distinct segments of a stack slot that can take on the value of a subregister, when a super-register is written to the stack.
 
SmallVector< std::pair< const MachineOperand *, unsigned >, 32 > Masks
 Collection of register mask operands that have been observed.
 
DenseMap< StackSlotPos, unsignedStackSlotIdxes
 Map from a size/offset pair describing a position in a stack slot, to a numeric identifier for that position.
 
DenseMap< unsigned, StackSlotPosStackIdxesToPos
 Inverse of StackSlotIdxes.
 

Detailed Description

Tracker for what values are in machine locations.

Listens to the Things being Done by various instructions, and maintains a table of what machine locations have what values (as defined by a ValueIDNum).

There are potentially a much larger number of machine locations on the target machine than the actual working-set size of the function. On x86 for example, we're extremely unlikely to want to track values through control or debug registers. To avoid doing so, MLocTracker has several layers of indirection going on, described below, to avoid unnecessarily tracking any location.

Here's a sort of diagram of the indexes, read from the bottom up:

      Size on stack   Offset on stack
            \              /
     Stack Idx (Where in slot is this?)
                    /
                   /

Slot Num (stack.0) / FrameIdx => SpillNum / \ / SpillID (int) Register number (int) \ / LocationID => LocIdx | LocIdx => ValueIDNum

The aim here is that the LocIdx => ValueIDNum vector is just an array of values in numbered locations, so that later analyses can ignore whether the location is a register or otherwise. To map a register / spill location to a LocIdx, you have to use the (sparse) LocationID => LocIdx map. And to build a LocationID for a stack slot, you need to combine identifiers for which stack slot it is and where within that slot is being described.

Register mask operands cause trouble by technically defining every register; various hacks are used to avoid tracking registers that are never read and only written by regmasks.

Definition at line 698 of file InstrRefBasedImpl.h.

Member Typedef Documentation

◆ LocToValueType

IndexedMap type, mapping from LocIdx to ValueIDNum.

Definition at line 706 of file InstrRefBasedImpl.h.

◆ StackSlotPos

Pair for describing a position within a stack slot – first the size in bits, then the offset.

Definition at line 754 of file InstrRefBasedImpl.h.

Constructor & Destructor Documentation

◆ MLocTracker()

MLocTracker::MLocTracker ( MachineFunction MF,
const TargetInstrInfo TII,
const TargetRegisterInfo TRI,
const TargetLowering TLI 
)

Member Function Documentation

◆ begin()

MLocIterator LiveDebugValues::MLocTracker::begin ( )
inline

Definition at line 1001 of file InstrRefBasedImpl.h.

References LocIdxToIDNum.

Referenced by locations().

◆ clear()

void LiveDebugValues::MLocTracker::clear ( )
inline

◆ defReg()

void LiveDebugValues::MLocTracker::defReg ( Register  R,
unsigned  BB,
unsigned  Inst 
)
inline

Record a definition of the specified register at the given block / inst.

This doesn't take a ValueIDNum, because the definition and its location are synonymous.

Definition at line 930 of file InstrRefBasedImpl.h.

References getLocID(), Idx, LocIdxToIDNum, and lookupOrTrackRegister().

Referenced by writeRegMask().

◆ dump()

LLVM_DUMP_METHOD void MLocTracker::dump ( )

Definition at line 1172 of file InstrRefBasedImpl.cpp.

References llvm::dbgs(), locations(), and LocIdxToName().

◆ dump_mloc_map()

LLVM_DUMP_METHOD void MLocTracker::dump_mloc_map ( )

Definition at line 1180 of file InstrRefBasedImpl.cpp.

References llvm::dbgs(), locations(), and LocIdxToName().

◆ emitLoc()

MachineInstrBuilder MLocTracker::emitLoc ( const SmallVectorImpl< ResolvedDbgOp > &  DbgOps,
const DebugVariable Var,
const DILocation DILoc,
const DbgValueProperties Properties 
)

◆ end()

MLocIterator LiveDebugValues::MLocTracker::end ( )
inline

Definition at line 1003 of file InstrRefBasedImpl.h.

References LocIdxToIDNum, and llvm::IndexedMap< T, ToIndexT >::size().

Referenced by locations().

◆ getLocID() [1/3]

unsigned LiveDebugValues::MLocTracker::getLocID ( Register  Reg)
inline

Produce location ID number for a Register.

Provides some small amount of type safety.

Parameters
RegThe register we're looking up.

Definition at line 803 of file InstrRefBasedImpl.h.

References Reg.

Referenced by defReg(), getLocID(), getRegMLoc(), MLocTracker(), readReg(), setReg(), and wipeRegister().

◆ getLocID() [2/3]

unsigned LiveDebugValues::MLocTracker::getLocID ( SpillLocationNo  Spill,
StackSlotPos  Idx 
)
inline

Produce location ID number for a spill position.

Parameters
SpillThe number of the spill we're fetching the location for. \apram SpillIdx size/offset within the spill slot to be addressed.

Definition at line 817 of file InstrRefBasedImpl.h.

References assert(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::contains(), Idx, NumRegs, NumSlotIdxes, and StackSlotIdxes.

◆ getLocID() [3/3]

unsigned LiveDebugValues::MLocTracker::getLocID ( SpillLocationNo  Spill,
unsigned  SpillSubReg 
)
inline

Produce location ID number for a spill position.

Parameters
SpillThe number of the spill we're fetching the location for.
SpillSubRegSubregister within the spill we're addressing.

Definition at line 808 of file InstrRefBasedImpl.h.

References getLocID(), llvm::TargetRegisterInfo::getSubRegIdxOffset(), llvm::TargetRegisterInfo::getSubRegIdxSize(), Size, and TRI.

◆ getLocSizeInBits()

unsigned LiveDebugValues::MLocTracker::getLocSizeInBits ( LocIdx  L) const
inline

How large is this location (aka, how wide is a value defined there?).

Definition at line 989 of file InstrRefBasedImpl.h.

References llvm::MachineFunction::getRegInfo(), llvm::TargetRegisterInfo::getRegSizeInBits(), isSpill(), locIDToSpillIdx(), LocIdxToLocID, MF, and TRI.

Referenced by emitLoc().

◆ getNumLocs()

unsigned LiveDebugValues::MLocTracker::getNumLocs ( ) const
inline

Definition at line 853 of file InstrRefBasedImpl.h.

References LocIdxToIDNum, and llvm::IndexedMap< T, ToIndexT >::size().

◆ getOrTrackSpillLoc()

std::optional< SpillLocationNo > MLocTracker::getOrTrackSpillLoc ( SpillLoc  L)

Find LocIdx for SpillLoc L, creating a new one if it's not tracked.

Returns std::nullopt when in scenarios where a spill slot could be tracked, but we would likely run into resource limitations.

Definition at line 1124 of file InstrRefBasedImpl.cpp.

References CurBB, getSpillIDWithIdx(), llvm::IndexedMap< T, ToIndexT >::grow(), LiveDebugValues::SpillLocationNo::id(), Idx, LocIDToLocIdx, LocIdxToIDNum, LocIdxToLocID, NumSlotIdxes, llvm::IndexedMap< T, ToIndexT >::size(), SpillLocs, and StackWorkingSetLimit.

◆ getRegMLoc()

LocIdx LiveDebugValues::MLocTracker::getRegMLoc ( Register  R)
inline

Determine the LocIdx of an existing register.

Definition at line 962 of file InstrRefBasedImpl.h.

References assert(), getLocID(), and LocIDToLocIdx.

Referenced by TransferTracker::redefVar().

◆ getSpillIDWithIdx()

unsigned LiveDebugValues::MLocTracker::getSpillIDWithIdx ( SpillLocationNo  Spill,
unsigned  Idx 
)
inline

Given a spill number, and a slot within the spill, calculate the ID number for that location.

Definition at line 828 of file InstrRefBasedImpl.h.

References Idx, NumRegs, and NumSlotIdxes.

Referenced by LiveDebugValues::InstrRefBasedLDV::findLocationForMemOperand(), and getOrTrackSpillLoc().

◆ getSpillMLoc()

LocIdx LiveDebugValues::MLocTracker::getSpillMLoc ( unsigned  SpillID)
inline

◆ IDAsString()

std::string MLocTracker::IDAsString ( const ValueIDNum Num) const

◆ isRegisterTracked()

bool LiveDebugValues::MLocTracker::isRegisterTracked ( Register  R)
inline

Is register R currently tracked by MLocTracker?

Definition at line 922 of file InstrRefBasedImpl.h.

References LocIDToLocIdx.

◆ isSpill()

bool LiveDebugValues::MLocTracker::isSpill ( LocIdx  Idx) const
inline

Return true if Idx is a spill machine location.

Definition at line 986 of file InstrRefBasedImpl.h.

References Idx, LocIdxToLocID, and NumRegs.

Referenced by TransferTracker::getLocQualityIfBetter(), getLocSizeInBits(), and TransferTracker::isEntryValueValue().

◆ loadFromArray()

void LiveDebugValues::MLocTracker::loadFromArray ( ValueTable Locs,
unsigned  NewCurBB 
)
inline

Load values for each location from array of ValueIDNums.

Take current bbnum just in case we read a value from a hitherto untouched register.

Definition at line 866 of file InstrRefBasedImpl.h.

References CurBB, and locations().

◆ locations()

iterator_range< MLocIterator > LiveDebugValues::MLocTracker::locations ( )
inline

◆ locIDToSpill()

SpillLocationNo LiveDebugValues::MLocTracker::locIDToSpill ( unsigned  ID) const
inline

Return the spill number that a location ID corresponds to.

Definition at line 837 of file InstrRefBasedImpl.h.

References assert(), NumRegs, and NumSlotIdxes.

Referenced by emitLoc().

◆ locIDToSpillIdx()

StackSlotPos LiveDebugValues::MLocTracker::locIDToSpillIdx ( unsigned  ID) const
inline

Returns the spill-slot size/offs that a location ID corresponds to.

Definition at line 846 of file InstrRefBasedImpl.h.

References assert(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::find(), Idx, NumRegs, NumSlotIdxes, and StackIdxesToPos.

Referenced by emitLoc(), getLocSizeInBits(), and LocIdxToName().

◆ LocIdxToName()

std::string MLocTracker::LocIdxToName ( LocIdx  Idx) const

◆ lookupOrTrackRegister()

LocIdx LiveDebugValues::MLocTracker::lookupOrTrackRegister ( unsigned  ID)
inline

Definition at line 914 of file InstrRefBasedImpl.h.

References LocIDToLocIdx, and trackRegister().

Referenced by defReg(), MLocTracker(), readReg(), and setReg().

◆ readMLoc()

ValueIDNum LiveDebugValues::MLocTracker::readMLoc ( LocIdx  L)
inline

Read the value of a particular location.

Definition at line 905 of file InstrRefBasedImpl.h.

References assert(), LocIdxToIDNum, and llvm::IndexedMap< T, ToIndexT >::size().

Referenced by TransferTracker::redefVar(), and TransferTracker::transferMlocs().

◆ readReg()

ValueIDNum LiveDebugValues::MLocTracker::readReg ( Register  R)
inline

Definition at line 945 of file InstrRefBasedImpl.h.

References getLocID(), Idx, LocIdxToIDNum, and lookupOrTrackRegister().

◆ reset()

void LiveDebugValues::MLocTracker::reset ( )
inline

Wipe any un-necessary location records after traversing a block.

Definition at line 875 of file InstrRefBasedImpl.h.

References Masks.

Referenced by clear(), and MLocTracker().

◆ setMLoc()

void LiveDebugValues::MLocTracker::setMLoc ( LocIdx  L,
ValueIDNum  Num 
)
inline

Set a locaiton to a certain value.

Definition at line 899 of file InstrRefBasedImpl.h.

References assert(), LocIdxToIDNum, and llvm::IndexedMap< T, ToIndexT >::size().

◆ setMPhis()

void LiveDebugValues::MLocTracker::setMPhis ( unsigned  NewCurBB)
inline

Reset all locations to contain a PHI value at the designated block.

Used sometimes for actual PHI values, othertimes to indicate the block entry value (before any more information is known).

Definition at line 858 of file InstrRefBasedImpl.h.

References CurBB, and locations().

◆ setReg()

void LiveDebugValues::MLocTracker::setReg ( Register  R,
ValueIDNum  ValueID 
)
inline

Set a register to a value number.

To be used if the value number is known in advance.

Definition at line 939 of file InstrRefBasedImpl.h.

References getLocID(), Idx, LocIdxToIDNum, and lookupOrTrackRegister().

◆ trackRegister()

LocIdx MLocTracker::trackRegister ( unsigned  ID)

Create a LocIdx for an untracked register ID.

Initialize it to either an mphi value representing a live-in, or a recent register mask clobber.

Definition at line 1088 of file InstrRefBasedImpl.cpp.

References assert(), CurBB, llvm::IndexedMap< T, ToIndexT >::grow(), LocIdxToIDNum, LocIdxToLocID, Masks, llvm::reverse(), and llvm::IndexedMap< T, ToIndexT >::size().

Referenced by lookupOrTrackRegister().

◆ wipeRegister()

void LiveDebugValues::MLocTracker::wipeRegister ( Register  R)
inline

Reset a register value to zero / empty.

Needed to replicate the VarLoc implementation where a copy to/from a register effectively clears the contents of the source register. (Values can only have one machine location in VarLocBasedImpl).

Definition at line 955 of file InstrRefBasedImpl.h.

References LiveDebugValues::ValueIDNum::EmptyValue, getLocID(), Idx, LocIDToLocIdx, and LocIdxToIDNum.

◆ writeRegMask()

void MLocTracker::writeRegMask ( const MachineOperand MO,
unsigned  CurBB,
unsigned  InstID 
)

Record a RegMask operand being executed.

Defs any register we currently track, stores a pointer to the mask in case we have to account for it later.

Definition at line 1110 of file InstrRefBasedImpl.cpp.

References llvm::MachineOperand::clobbersPhysReg(), CurBB, defReg(), locations(), LocIdxToLocID, Masks, NumRegs, and SPAliases.

Member Data Documentation

◆ CurBB

unsigned LiveDebugValues::MLocTracker::CurBB = -1

◆ LocIDToLocIdx

std::vector<LocIdx> LiveDebugValues::MLocTracker::LocIDToLocIdx

"Map" of machine location IDs (i.e., raw register or spill number) to the LocIdx key / number for that location.

There are always at least as many as the number of registers on the target – if the value in the register is not being tracked, then the LocIdx value will be zero. New entries are appended if a new spill slot begins being tracked. This, and the corresponding reverse map persist for the analysis of the whole function, and is necessarying for decoding various vectors of values.

Definition at line 720 of file InstrRefBasedImpl.h.

Referenced by clear(), getOrTrackSpillLoc(), getRegMLoc(), getSpillMLoc(), isRegisterTracked(), lookupOrTrackRegister(), MLocTracker(), and wipeRegister().

◆ LocIdxToIDNum

LocToValueType LiveDebugValues::MLocTracker::LocIdxToIDNum

Map of LocIdxes to the ValueIDNums that they store.

This is tightly packed, entries only exist for locations that are being tracked.

Definition at line 710 of file InstrRefBasedImpl.h.

Referenced by begin(), clear(), defReg(), end(), getNumLocs(), getOrTrackSpillLoc(), readMLoc(), readReg(), setMLoc(), setReg(), trackRegister(), and wipeRegister().

◆ LocIdxToLocID

IndexedMap<unsigned, LocIdxToIndexFunctor> LiveDebugValues::MLocTracker::LocIdxToLocID

◆ Masks

SmallVector<std::pair<const MachineOperand *, unsigned>, 32> LiveDebugValues::MLocTracker::Masks

Collection of register mask operands that have been observed.

Second part of pair indicates the instruction that they happened in. Used to reconstruct where defs happened if we start tracking a location later on.

Definition at line 750 of file InstrRefBasedImpl.h.

Referenced by reset(), trackRegister(), and writeRegMask().

◆ MF

MachineFunction& LiveDebugValues::MLocTracker::MF

Definition at line 700 of file InstrRefBasedImpl.h.

Referenced by emitLoc(), and getLocSizeInBits().

◆ NumRegs

unsigned LiveDebugValues::MLocTracker::NumRegs

Cached local copy of the number of registers the target has.

Definition at line 739 of file InstrRefBasedImpl.h.

Referenced by clear(), emitLoc(), getLocID(), getSpillIDWithIdx(), TransferTracker::isCalleeSaved(), isSpill(), locIDToSpill(), locIDToSpillIdx(), LocIdxToName(), MLocTracker(), and writeRegMask().

◆ NumSlotIdxes

unsigned LiveDebugValues::MLocTracker::NumSlotIdxes

Number of slot indexes the target has – distinct segments of a stack slot that can take on the value of a subregister, when a super-register is written to the stack.

Definition at line 744 of file InstrRefBasedImpl.h.

Referenced by getLocID(), getOrTrackSpillLoc(), getSpillIDWithIdx(), locIDToSpill(), locIDToSpillIdx(), LocIdxToName(), and MLocTracker().

◆ SPAliases

SmallSet<Register, 8> LiveDebugValues::MLocTracker::SPAliases

When clobbering register masks, we chose to not believe the machine model and don't clobber SP.

Do the same for SP aliases, and for efficiency, keep a set of them here.

Definition at line 728 of file InstrRefBasedImpl.h.

Referenced by MLocTracker(), and writeRegMask().

◆ SpillLocs

UniqueVector<SpillLoc> LiveDebugValues::MLocTracker::SpillLocs

Unique-ification of spill.

Used to number them – their LocID number is the index in SpillLocs minus one plus NumRegs.

Definition at line 732 of file InstrRefBasedImpl.h.

Referenced by clear(), emitLoc(), and getOrTrackSpillLoc().

◆ StackIdxesToPos

DenseMap<unsigned, StackSlotPos> LiveDebugValues::MLocTracker::StackIdxesToPos

Inverse of StackSlotIdxes.

Definition at line 762 of file InstrRefBasedImpl.h.

Referenced by clear(), locIDToSpillIdx(), and MLocTracker().

◆ StackSlotIdxes

DenseMap<StackSlotPos, unsigned> LiveDebugValues::MLocTracker::StackSlotIdxes

Map from a size/offset pair describing a position in a stack slot, to a numeric identifier for that position.

Allows easier identification of individual positions.

Definition at line 759 of file InstrRefBasedImpl.h.

Referenced by clear(), LiveDebugValues::InstrRefBasedLDV::findLocationForMemOperand(), getLocID(), and MLocTracker().

◆ TII

const TargetInstrInfo& LiveDebugValues::MLocTracker::TII

Definition at line 701 of file InstrRefBasedImpl.h.

Referenced by emitLoc().

◆ TLI

const TargetLowering& LiveDebugValues::MLocTracker::TLI

Definition at line 703 of file InstrRefBasedImpl.h.

Referenced by MLocTracker().

◆ TRI

const TargetRegisterInfo& LiveDebugValues::MLocTracker::TRI

Definition at line 702 of file InstrRefBasedImpl.h.

Referenced by emitLoc(), getLocID(), getLocSizeInBits(), LocIdxToName(), and MLocTracker().


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