Thanks to visit codestin.com
Credit goes to llvm.org

LLVM 22.0.0git
TransferTracker Class Reference

Tracker for converting machine value locations and variable values into variable locations (the output of LiveDebugValues), recorded as DBG_VALUEs specifying block live-in locations and transfers within blocks. More...

Classes

class  LocationAndQuality
struct  ResolvedDbgValue
 Stores the resolved operands (machine locations and constants) and qualifying meta-information needed to construct a concrete DBG_VALUE-like instruction. More...
struct  Transfer
 Record of all changes in variable locations at a block position. More...
struct  UseBeforeDef
 Record of a use-before-def: created when a value that's live-in to the current block isn't available in any machine location, but it will be defined in this block. More...

Public Types

enum class  LocationQuality : unsigned char {
  Illegal = 0 , Register , CalleeSavedRegister , SpillSlot ,
  Best = SpillSlot
}
using ValueLocPair = std::pair<ValueIDNum, LocationAndQuality>

Public Member Functions

 TransferTracker (const TargetInstrInfo *TII, MLocTracker *MTracker, MachineFunction &MF, const DebugVariableMap &DVMap, const TargetRegisterInfo &TRI, const BitVector &CalleeSavedRegs, bool ShouldEmitDebugEntryValues)
bool isCalleeSaved (LocIdx L) const
std::optional< LocationQualitygetLocQualityIfBetter (LocIdx L, LocationQuality Min) const
void loadVarInloc (MachineBasicBlock &MBB, DbgOpIDMap &DbgOpStore, const SmallVectorImpl< ValueLocPair > &ValueToLoc, DebugVariableID VarID, DbgValue Value)
 For a variable Var with the live-in value Value, attempts to resolve the DbgValue to a concrete DBG_VALUE, emitting that value and loading the tracking information to track Var throughout the block.
void loadInlocs (MachineBasicBlock &MBB, ValueTable &MLocs, DbgOpIDMap &DbgOpStore, const SmallVectorImpl< std::pair< DebugVariableID, DbgValue > > &VLocs, unsigned NumLocs)
 Load object with live-in variable values.
void addUseBeforeDef (DebugVariableID VarID, const DbgValueProperties &Properties, const SmallVectorImpl< DbgOp > &DbgOps, unsigned Inst)
 Record that Var has value ID, a value that becomes available later in the function.
void checkInstForNewValues (unsigned Inst, MachineBasicBlock::iterator pos)
 After the instruction at index Inst and position pos has been processed, check whether it defines a variable value in a use-before-def.
void flushDbgValues (MachineBasicBlock::iterator Pos, MachineBasicBlock *MBB)
 Helper to move created DBG_VALUEs into Transfers collection.
bool isEntryValueVariable (const DebugVariable &Var, const DIExpression *Expr) const
bool isEntryValueValue (const ValueIDNum &Val) const
bool recoverAsEntryValue (DebugVariableID VarID, const DbgValueProperties &Prop, const ValueIDNum &Num)
void redefVar (const MachineInstr &MI)
 Change a variable value after encountering a DBG_VALUE inside a block.
void redefVar (const MachineInstr &MI, const DbgValueProperties &Properties, SmallVectorImpl< ResolvedDbgOp > &NewLocs)
 Handle a change in variable location within a block.
void clobberMloc (LocIdx MLoc, MachineBasicBlock::iterator Pos, bool MakeUndef=true)
 Account for a location mloc being clobbered.
void clobberMloc (LocIdx MLoc, ValueIDNum OldValue, MachineBasicBlock::iterator Pos, bool MakeUndef=true)
 Overload that takes an explicit value OldValue for when the value in MLoc has changed and the TransferTracker's locations have not been updated yet.
void transferMlocs (LocIdx Src, LocIdx Dst, MachineBasicBlock::iterator Pos)
 Transfer variables based on Src to be based on Dst.
MachineInstrBuilder emitMOLoc (const MachineOperand &MO, const DebugVariable &Var, const DbgValueProperties &Properties)

Static Public Member Functions

static bool ValueToLocSort (const ValueLocPair &A, const ValueLocPair &B)

Public Attributes

const TargetInstrInfoTII
const TargetLoweringTLI
MLocTrackerMTracker
 This machine location tracker is assumed to always contain the up-to-date value mapping for all machine locations.
MachineFunctionMF
const DebugVariableMapDVMap
bool ShouldEmitDebugEntryValues
SmallVector< Transfer, 32 > Transfers
 Collection of transfers (DBG_VALUEs) to be inserted.
SmallVector< ValueIDNum, 32 > VarLocs
 Local cache of what-value-is-in-what-LocIdx.
DenseMap< LocIdx, SmallSet< DebugVariableID, 4 > > ActiveMLocs
 Map from LocIdxes to which DebugVariables are based that location.
DenseMap< DebugVariableID, ResolvedDbgValueActiveVLocs
 Map from DebugVariable to it's current location and qualifying meta information.
SmallVector< std::pair< DebugVariableID, MachineInstr * >, 4 > PendingDbgValues
 Temporary cache of DBG_VALUEs to be entered into the Transfers collection.
DenseMap< unsigned, SmallVector< UseBeforeDef, 1 > > UseBeforeDefs
 Map from instruction index (within the block) to the set of UseBeforeDefs that become defined at that instruction.
DenseSet< DebugVariableIDUseBeforeDefVariables
 The set of variables that are in UseBeforeDefs and can become a location once the relevant value is defined.
const TargetRegisterInfoTRI
const BitVectorCalleeSavedRegs

Detailed Description

Tracker for converting machine value locations and variable values into variable locations (the output of LiveDebugValues), recorded as DBG_VALUEs specifying block live-in locations and transfers within blocks.

Operating on a per-block basis, this class takes a (pre-loaded) MLocTracker and must be initialized with the set of variable values that are live-in to the block. The caller then repeatedly calls process(). TransferTracker picks out variable locations for the live-in variable values (if there is a location) and creates the corresponding DBG_VALUEs. Then, as the block is stepped through, transfers of values between machine locations are identified and if profitable, a DBG_VALUE created.

This is where debug use-before-defs would be resolved: a variable with an unavailable value could materialize in the middle of a block, when the value becomes available. Or, we could detect clobbers and re-specify the variable in a backup location. (XXX these are unimplemented).

Definition at line 176 of file InstrRefBasedImpl.cpp.

Member Typedef Documentation

◆ ValueLocPair

Definition at line 321 of file InstrRefBasedImpl.cpp.

Member Enumeration Documentation

◆ LocationQuality

Enumerator
Illegal 
Register 
CalleeSavedRegister 
SpillSlot 
Best 

Definition at line 295 of file InstrRefBasedImpl.cpp.

Constructor & Destructor Documentation

◆ TransferTracker()

TransferTracker::TransferTracker ( const TargetInstrInfo * TII,
MLocTracker * MTracker,
MachineFunction & MF,
const DebugVariableMap & DVMap,
const TargetRegisterInfo & TRI,
const BitVector & CalleeSavedRegs,
bool ShouldEmitDebugEntryValues )
inline

Definition at line 269 of file InstrRefBasedImpl.cpp.

References CalleeSavedRegs, DVMap, MF, MTracker, ShouldEmitDebugEntryValues, TII, TLI, and TRI.

Member Function Documentation

◆ addUseBeforeDef()

void TransferTracker::addUseBeforeDef ( DebugVariableID VarID,
const DbgValueProperties & Properties,
const SmallVectorImpl< DbgOp > & DbgOps,
unsigned Inst )
inline

Record that Var has value ID, a value that becomes available later in the function.

Definition at line 520 of file InstrRefBasedImpl.cpp.

References UseBeforeDefs, and UseBeforeDefVariables.

Referenced by loadVarInloc().

◆ checkInstForNewValues()

◆ clobberMloc() [1/2]

void TransferTracker::clobberMloc ( LocIdx MLoc,
MachineBasicBlock::iterator Pos,
bool MakeUndef = true )
inline

Account for a location mloc being clobbered.

Examine the variable locations that will be terminated: and try to recover them by using another location. Optionally, given MakeUndef, emit a DBG_VALUE to explicitly terminate a location if it can't be recovered.

Definition at line 818 of file InstrRefBasedImpl.cpp.

References ActiveMLocs, LiveDebugValues::LocIdx::asU64(), clobberMloc(), and VarLocs.

Referenced by clobberMloc().

◆ clobberMloc() [2/2]

◆ emitMOLoc()

◆ flushDbgValues()

void TransferTracker::flushDbgValues ( MachineBasicBlock::iterator Pos,
MachineBasicBlock * MBB )
inline

Helper to move created DBG_VALUEs into Transfers collection.

Definition at line 613 of file InstrRefBasedImpl.cpp.

References llvm::getBundleStart(), MBB, PendingDbgValues, and Transfers.

Referenced by checkInstForNewValues(), clobberMloc(), loadInlocs(), and transferMlocs().

◆ getLocQualityIfBetter()

std::optional< LocationQuality > TransferTracker::getLocQualityIfBetter ( LocIdx L,
LocationQuality Min ) const
inline

◆ isCalleeSaved()

bool TransferTracker::isCalleeSaved ( LocIdx L) const
inline

◆ isEntryValueValue()

bool TransferTracker::isEntryValueValue ( const ValueIDNum & Val) const
inline

◆ isEntryValueVariable()

◆ loadInlocs()

void TransferTracker::loadInlocs ( MachineBasicBlock & MBB,
ValueTable & MLocs,
DbgOpIDMap & DbgOpStore,
const SmallVectorImpl< std::pair< DebugVariableID, DbgValue > > & VLocs,
unsigned NumLocs )
inline

Load object with live-in variable values.

mlocs contains the live-in values in each machine location, while vlocs the live-in variable values. This method picks variable locations for the live-in variables, creates DBG_VALUEs and puts them in Transfers, then prepares the other object fields to track variable locations as we step through the block. FIXME: could just examine mloctracker instead of passing in mlocs?

Definition at line 459 of file InstrRefBasedImpl.cpp.

References ActiveMLocs, ActiveVLocs, LiveDebugValues::LocIdx::asU64(), LiveDebugValues::DbgValue::Def, LiveDebugValues::ValueIDNum::EmptyValue, llvm::SmallVectorTemplateCommon< T, typename >::end(), LiveDebugValues::DbgOpIDMap::find(), flushDbgValues(), getLocQualityIfBetter(), LiveDebugValues::DbgOp::ID, loadVarInloc(), llvm::lower_bound(), MBB, MTracker, llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::sort(), UseBeforeDefs, UseBeforeDefVariables, ValueToLocSort(), and VarLocs.

◆ loadVarInloc()

void TransferTracker::loadVarInloc ( MachineBasicBlock & MBB,
DbgOpIDMap & DbgOpStore,
const SmallVectorImpl< ValueLocPair > & ValueToLoc,
DebugVariableID VarID,
DbgValue Value )
inline

For a variable Var with the live-in value Value, attempts to resolve the DbgValue to a concrete DBG_VALUE, emitting that value and loading the tracking information to track Var throughout the block.

ValueToLoc is a map containing the best known location for every ValueIDNum that Value may use. MBB is the basic block that we are loading the live-in value for. DbgOpStore is the map containing the DbgOpID->DbgOp mapping needed to determine the values used by Value.

Definition at line 355 of file InstrRefBasedImpl.cpp.

References ActiveMLocs, ActiveVLocs, addUseBeforeDef(), assert(), DVMap, llvm::SmallVectorTemplateCommon< T, typename >::end(), LiveDebugValues::DbgOpIDMap::find(), LiveDebugValues::ValueIDNum::getBlock(), LiveDebugValues::ValueIDNum::getInst(), LiveDebugValues::ValueIDNum::isPHI(), llvm::lower_bound(), MBB, MTracker, PendingDbgValues, llvm::SmallVectorTemplateBase< T, bool >::push_back(), recoverAsEntryValue(), and ValueToLocSort().

Referenced by loadInlocs().

◆ recoverAsEntryValue()

◆ redefVar() [1/2]

void TransferTracker::redefVar ( const MachineInstr & MI)
inline

◆ redefVar() [2/2]

void TransferTracker::redefVar ( const MachineInstr & MI,
const DbgValueProperties & Properties,
SmallVectorImpl< ResolvedDbgOp > & NewLocs )
inline

Handle a change in variable location within a block.

Terminate the variables current location, and record the value it now refers to, so that we can detect location transfers later on.

Definition at line 748 of file InstrRefBasedImpl.cpp.

References ActiveMLocs, ActiveVLocs, LiveDebugValues::LocIdx::asU64(), DVMap, llvm::SmallVectorImpl< T >::emplace_back(), llvm::SmallVectorTemplateCommon< T, typename >::empty(), MI, MTracker, P, UseBeforeDefVariables, and VarLocs.

◆ transferMlocs()

void TransferTracker::transferMlocs ( LocIdx Src,
LocIdx Dst,
MachineBasicBlock::iterator Pos )
inline

Transfer variables based on Src to be based on Dst.

This handles both register copies as well as spills and restores. Creates DBG_VALUEs describing the movement.

Definition at line 927 of file InstrRefBasedImpl.cpp.

References ActiveMLocs, ActiveVLocs, assert(), DVMap, LiveDebugValues::ValueIDNum::EmptyValue, EmulateOldLDV, flushDbgValues(), MI, MTracker, PendingDbgValues, llvm::replace(), and VarLocs.

◆ ValueToLocSort()

bool TransferTracker::ValueToLocSort ( const ValueLocPair & A,
const ValueLocPair & B )
inlinestatic

Definition at line 323 of file InstrRefBasedImpl.cpp.

References A(), and B().

Referenced by loadInlocs(), and loadVarInloc().

Member Data Documentation

◆ ActiveMLocs

DenseMap<LocIdx, SmallSet<DebugVariableID, 4> > TransferTracker::ActiveMLocs

Map from LocIdxes to which DebugVariables are based that location.

Mantained while stepping through the block. Not accurate if VarLocs[Idx] != MTracker->LocIdxToIDNum[Idx].

Definition at line 232 of file InstrRefBasedImpl.cpp.

Referenced by clobberMloc(), clobberMloc(), loadInlocs(), loadVarInloc(), redefVar(), redefVar(), and transferMlocs().

◆ ActiveVLocs

DenseMap<DebugVariableID, ResolvedDbgValue> TransferTracker::ActiveVLocs

Map from DebugVariable to it's current location and qualifying meta information.

To be used in conjunction with ActiveMLocs to construct enough information for the DBG_VALUEs for a particular LocIdx.

Definition at line 237 of file InstrRefBasedImpl.cpp.

Referenced by clobberMloc(), loadInlocs(), loadVarInloc(), redefVar(), redefVar(), and transferMlocs().

◆ CalleeSavedRegs

const BitVector& TransferTracker::CalleeSavedRegs

Definition at line 267 of file InstrRefBasedImpl.cpp.

Referenced by isCalleeSaved(), and TransferTracker().

◆ DVMap

◆ MF

MachineFunction& TransferTracker::MF

Definition at line 184 of file InstrRefBasedImpl.cpp.

Referenced by emitMOLoc(), isEntryValueValue(), and TransferTracker().

◆ MTracker

MLocTracker* TransferTracker::MTracker

This machine location tracker is assumed to always contain the up-to-date value mapping for all machine locations.

TransferTracker only reads information from it. (XXX make it const?)

Definition at line 183 of file InstrRefBasedImpl.cpp.

Referenced by checkInstForNewValues(), clobberMloc(), getLocQualityIfBetter(), isCalleeSaved(), isEntryValueValue(), loadInlocs(), loadVarInloc(), recoverAsEntryValue(), redefVar(), redefVar(), transferMlocs(), and TransferTracker().

◆ PendingDbgValues

SmallVector<std::pair<DebugVariableID, MachineInstr *>, 4> TransferTracker::PendingDbgValues

Temporary cache of DBG_VALUEs to be entered into the Transfers collection.

Definition at line 240 of file InstrRefBasedImpl.cpp.

Referenced by checkInstForNewValues(), clobberMloc(), flushDbgValues(), loadVarInloc(), recoverAsEntryValue(), and transferMlocs().

◆ ShouldEmitDebugEntryValues

bool TransferTracker::ShouldEmitDebugEntryValues

Definition at line 186 of file InstrRefBasedImpl.cpp.

Referenced by recoverAsEntryValue(), and TransferTracker().

◆ TII

const TargetInstrInfo* TransferTracker::TII

Definition at line 178 of file InstrRefBasedImpl.cpp.

Referenced by emitMOLoc(), and TransferTracker().

◆ TLI

const TargetLowering* TransferTracker::TLI

Definition at line 179 of file InstrRefBasedImpl.cpp.

Referenced by isEntryValueValue(), and TransferTracker().

◆ Transfers

SmallVector<Transfer, 32> TransferTracker::Transfers

Collection of transfers (DBG_VALUEs) to be inserted.

Definition at line 221 of file InstrRefBasedImpl.cpp.

Referenced by flushDbgValues().

◆ TRI

const TargetRegisterInfo& TransferTracker::TRI

Definition at line 266 of file InstrRefBasedImpl.cpp.

Referenced by isCalleeSaved(), isEntryValueValue(), and TransferTracker().

◆ UseBeforeDefs

DenseMap<unsigned, SmallVector<UseBeforeDef, 1> > TransferTracker::UseBeforeDefs

Map from instruction index (within the block) to the set of UseBeforeDefs that become defined at that instruction.

Definition at line 259 of file InstrRefBasedImpl.cpp.

Referenced by addUseBeforeDef(), checkInstForNewValues(), and loadInlocs().

◆ UseBeforeDefVariables

DenseSet<DebugVariableID> TransferTracker::UseBeforeDefVariables

The set of variables that are in UseBeforeDefs and can become a location once the relevant value is defined.

An element being erased from this collection prevents the use-before-def materializing.

Definition at line 264 of file InstrRefBasedImpl.cpp.

Referenced by addUseBeforeDef(), checkInstForNewValues(), loadInlocs(), redefVar(), and redefVar().

◆ VarLocs

SmallVector<ValueIDNum, 32> TransferTracker::VarLocs

Local cache of what-value-is-in-what-LocIdx.

Used to identify differences between TransferTrackers view of variable locations and MLocTrackers. For example, MLocTracker observes all clobbers, but TransferTracker lazily does not.

Definition at line 227 of file InstrRefBasedImpl.cpp.

Referenced by clobberMloc(), clobberMloc(), loadInlocs(), redefVar(), and transferMlocs().


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