LLVM 20.0.0git
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
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, const TargetPassConfig &TPC)
 
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 177 of file InstrRefBasedImpl.cpp.

Member Typedef Documentation

◆ ValueLocPair

Definition at line 322 of file InstrRefBasedImpl.cpp.

Member Enumeration Documentation

◆ LocationQuality

Enumerator
Illegal 
Register 
CalleeSavedRegister 
SpillSlot 
Best 

Definition at line 296 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,
const TargetPassConfig TPC 
)
inline

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

References llvm::detail::DenseSetImpl< ValueT, MapTy, ValueInfoT >::insert(), UseBeforeDefs, and UseBeforeDefVariables.

Referenced by loadVarInloc().

◆ checkInstForNewValues()

void TransferTracker::checkInstForNewValues ( unsigned  Inst,
MachineBasicBlock::iterator  pos 
)
inline

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

References ActiveMLocs, LiveDebugValues::LocIdx::asU64(), clobberMloc(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::end(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::find(), and VarLocs.

Referenced by clobberMloc().

◆ clobberMloc() [2/2]

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

◆ emitMOLoc()

MachineInstrBuilder TransferTracker::emitMOLoc ( const MachineOperand MO,
const DebugVariable Var,
const DbgValueProperties Properties 
)
inline

◆ flushDbgValues()

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

◆ 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()

bool TransferTracker::isEntryValueVariable ( const DebugVariable Var,
const DIExpression Expr 
) const
inline

◆ loadInlocs()

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

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

References ActiveMLocs, ActiveVLocs, addUseBeforeDef(), assert(), llvm::SmallVectorTemplateCommon< T, typename >::begin(), DVMap, LiveDebugValues::MLocTracker::emitLoc(), llvm::SmallVectorTemplateCommon< T, typename >::end(), LiveDebugValues::DbgOpIDMap::find(), LiveDebugValues::ValueIDNum::getBlock(), LiveDebugValues::ValueIDNum::getInst(), llvm::MachineBasicBlock::getNumber(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::insert(), LiveDebugValues::ValueIDNum::isPHI(), LiveDebugValues::DebugVariableMap::lookupDVID(), MBB, MTracker, PendingDbgValues, llvm::SmallVectorTemplateBase< T, bool >::push_back(), recoverAsEntryValue(), and ValueToLocSort().

Referenced by loadInlocs().

◆ recoverAsEntryValue()

bool TransferTracker::recoverAsEntryValue ( DebugVariableID  VarID,
const DbgValueProperties Prop,
const ValueIDNum Num 
)
inline

◆ 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

◆ transferMlocs()

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

◆ ValueToLocSort()

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

Definition at line 324 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 233 of file InstrRefBasedImpl.cpp.

Referenced by clobberMloc(), loadInlocs(), loadVarInloc(), 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 238 of file InstrRefBasedImpl.cpp.

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

◆ CalleeSavedRegs

const BitVector& TransferTracker::CalleeSavedRegs

Definition at line 268 of file InstrRefBasedImpl.cpp.

Referenced by isCalleeSaved().

◆ DVMap

const DebugVariableMap& TransferTracker::DVMap

◆ MF

MachineFunction& TransferTracker::MF

Definition at line 185 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 184 of file InstrRefBasedImpl.cpp.

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

◆ PendingDbgValues

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

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

Definition at line 241 of file InstrRefBasedImpl.cpp.

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

◆ ShouldEmitDebugEntryValues

bool TransferTracker::ShouldEmitDebugEntryValues

Definition at line 187 of file InstrRefBasedImpl.cpp.

Referenced by recoverAsEntryValue(), and TransferTracker().

◆ TII

const TargetInstrInfo* TransferTracker::TII

Definition at line 179 of file InstrRefBasedImpl.cpp.

Referenced by emitMOLoc().

◆ TLI

const TargetLowering* TransferTracker::TLI

Definition at line 180 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 222 of file InstrRefBasedImpl.cpp.

Referenced by flushDbgValues().

◆ TRI

const TargetRegisterInfo& TransferTracker::TRI

Definition at line 267 of file InstrRefBasedImpl.cpp.

Referenced by isCalleeSaved(), and isEntryValueValue().

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

Referenced by addUseBeforeDef(), checkInstForNewValues(), loadInlocs(), 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 228 of file InstrRefBasedImpl.cpp.

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


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