LLVM 22.0.0git
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

LLVM_ABI_FOR_TEST 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.
LLVM_ABI_FOR_TEST 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.
LLVM_ABI_FOR_TEST 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 693 of file InstrRefBasedImpl.h.

Member Typedef Documentation

◆ LocToValueType

◆ StackSlotPos

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

Definition at line 749 of file InstrRefBasedImpl.h.

Constructor & Destructor Documentation

◆ MLocTracker()

Member Function Documentation

◆ begin()

MLocIterator LiveDebugValues::MLocTracker::begin ( )
inline

Definition at line 998 of file InstrRefBasedImpl.h.

References LocIdxToIDNum.

Referenced by locations().

◆ clear()

void LiveDebugValues::MLocTracker::clear ( )
inline

Clear all data.

Destroys the LocID <=> LocIdx map, which makes most of the information in this pass uninterpretable.

Definition at line 880 of file InstrRefBasedImpl.h.

References LocIDToLocIdx, LocIdxToIDNum, LocIdxToLocID, LiveDebugValues::LocIdx::MakeIllegalLoc(), NumRegs, reset(), SpillLocs, StackIdxesToPos, and StackSlotIdxes.

◆ 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 926 of file InstrRefBasedImpl.h.

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

Referenced by writeRegMask().

◆ dump()

LLVM_DUMP_METHOD void MLocTracker::dump ( )

Definition at line 1187 of file InstrRefBasedImpl.cpp.

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

◆ dump_mloc_map()

LLVM_DUMP_METHOD void MLocTracker::dump_mloc_map ( )

Definition at line 1195 of file InstrRefBasedImpl.cpp.

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

◆ emitLoc()

◆ end()

MLocIterator LiveDebugValues::MLocTracker::end ( )
inline

Definition at line 1000 of file InstrRefBasedImpl.h.

References LocIdxToIDNum.

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 799 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 813 of file InstrRefBasedImpl.h.

References assert(), 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 804 of file InstrRefBasedImpl.h.

References getLocID(), 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 986 of file InstrRefBasedImpl.h.

References isSpill(), locIDToSpillIdx(), LocIdxToLocID, MF, Register, and TRI.

Referenced by emitLoc().

◆ getNumLocs()

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

Definition at line 849 of file InstrRefBasedImpl.h.

References LocIdxToIDNum.

◆ 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 1139 of file InstrRefBasedImpl.cpp.

References CurBB, getSpillIDWithIdx(), LiveDebugValues::SpillLocationNo::id(), LocIDToLocIdx, LocIdxToIDNum, LocIdxToLocID, NumSlotIdxes, SpillLocs, and StackWorkingSetLimit.

◆ getRegMLoc()

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

Determine the LocIdx of an existing register.

Definition at line 958 of file InstrRefBasedImpl.h.

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

◆ 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 824 of file InstrRefBasedImpl.h.

References NumRegs, and NumSlotIdxes.

Referenced by getOrTrackSpillLoc().

◆ getSpillMLoc()

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

Definition at line 977 of file InstrRefBasedImpl.h.

References assert(), and LocIDToLocIdx.

◆ 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 918 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 983 of file InstrRefBasedImpl.h.

References LocIdxToLocID, and NumRegs.

Referenced by getLocSizeInBits().

◆ 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 862 of file InstrRefBasedImpl.h.

References CurBB, and locations().

◆ locations()

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

Return a range over all locations currently tracked.

Definition at line 1005 of file InstrRefBasedImpl.h.

References begin(), end(), and llvm::make_range().

Referenced by dump(), dump_mloc_map(), loadFromArray(), setMPhis(), and writeRegMask().

◆ locIDToSpill()

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

Return the spill number that a location ID corresponds to.

Definition at line 833 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 842 of file InstrRefBasedImpl.h.

References assert(), 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 910 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 901 of file InstrRefBasedImpl.h.

References assert(), and LocIdxToIDNum.

◆ readReg()

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

Definition at line 941 of file InstrRefBasedImpl.h.

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

◆ reset()

void LiveDebugValues::MLocTracker::reset ( )
inline

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

Definition at line 871 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 895 of file InstrRefBasedImpl.h.

References assert(), and LocIdxToIDNum.

◆ 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 854 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 935 of file InstrRefBasedImpl.h.

References getLocID(), 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 1103 of file InstrRefBasedImpl.cpp.

References assert(), CurBB, LocIdxToIDNum, LocIdxToLocID, Masks, and llvm::reverse().

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 951 of file InstrRefBasedImpl.h.

References LiveDebugValues::ValueIDNum::EmptyValue, getLocID(), 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 1125 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 715 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 705 of file InstrRefBasedImpl.h.

Referenced by begin(), clear(), defReg(), end(), getNumLocs(), getOrTrackSpillLoc(), MLocTracker(), 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 745 of file InstrRefBasedImpl.h.

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

◆ MF

MachineFunction& LiveDebugValues::MLocTracker::MF

Definition at line 695 of file InstrRefBasedImpl.h.

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

◆ NumRegs

unsigned LiveDebugValues::MLocTracker::NumRegs

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

Definition at line 734 of file InstrRefBasedImpl.h.

Referenced by clear(), emitLoc(), getLocID(), getSpillIDWithIdx(), 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 739 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 723 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 727 of file InstrRefBasedImpl.h.

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

◆ StackIdxesToPos

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

Inverse of StackSlotIdxes.

Definition at line 757 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 754 of file InstrRefBasedImpl.h.

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

◆ TII

const TargetInstrInfo& LiveDebugValues::MLocTracker::TII

Definition at line 696 of file InstrRefBasedImpl.h.

Referenced by emitLoc(), and MLocTracker().

◆ TLI

const TargetLowering& LiveDebugValues::MLocTracker::TLI

Definition at line 698 of file InstrRefBasedImpl.h.

Referenced by MLocTracker().

◆ TRI

const TargetRegisterInfo& LiveDebugValues::MLocTracker::TRI

Definition at line 697 of file InstrRefBasedImpl.h.

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


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