LLVM  14.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"

Collaboration diagram for LiveDebugValues::MLocTracker:
Collaboration graph
[legend]

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. More...
 
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. More...
 

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. More...
 
unsigned getLocID (SpillLocationNo Spill, unsigned SpillSubReg)
 Produce location ID number for a spill position. More...
 
unsigned getLocID (SpillLocationNo Spill, StackSlotPos Idx)
 Produce location ID number for a spill position. More...
 
unsigned getSpillIDWithIdx (SpillLocationNo Spill, unsigned Idx)
 Given a spill number, and a slot within the spill, calculate the ID number for that location. More...
 
SpillLocationNo locIDToSpill (unsigned ID) const
 Return the spill number that a location ID corresponds to. More...
 
StackSlotPos locIDToSpillIdx (unsigned ID) const
 Returns the spill-slot size/offs that a location ID corresponds to. More...
 
unsigned getNumLocs () const
 
void setMPhis (unsigned NewCurBB)
 Reset all locations to contain a PHI value at the designated block. More...
 
void loadFromArray (ValueIDNum *Locs, unsigned NewCurBB)
 Load values for each location from array of ValueIDNums. More...
 
void reset ()
 Wipe any un-necessary location records after traversing a block. More...
 
void clear ()
 Clear all data. More...
 
void setMLoc (LocIdx L, ValueIDNum Num)
 Set a locaiton to a certain value. More...
 
ValueIDNum readMLoc (LocIdx L)
 Read the value of a particular location. More...
 
LocIdx trackRegister (unsigned ID)
 Create a LocIdx for an untracked register ID. More...
 
LocIdx lookupOrTrackRegister (unsigned ID)
 
bool isRegisterTracked (Register R)
 Is register R currently tracked by MLocTracker? More...
 
void defReg (Register R, unsigned BB, unsigned Inst)
 Record a definition of the specified register at the given block / inst. More...
 
void setReg (Register R, ValueIDNum ValueID)
 Set a register to a value number. More...
 
ValueIDNum readReg (Register R)
 
void wipeRegister (Register R)
 Reset a register value to zero / empty. More...
 
LocIdx getRegMLoc (Register R)
 Determine the LocIdx of an existing register. More...
 
void writeRegMask (const MachineOperand *MO, unsigned CurBB, unsigned InstID)
 Record a RegMask operand being executed. More...
 
SpillLocationNo getOrTrackSpillLoc (SpillLoc L)
 Find LocIdx for SpillLoc L, creating a new one if it's not tracked. More...
 
LocIdx getSpillMLoc (unsigned SpillID)
 
bool isSpill (LocIdx Idx) const
 Return true if Idx is a spill machine location. More...
 
MLocIterator begin ()
 
MLocIterator end ()
 
iterator_range< MLocIteratorlocations ()
 Return a range over all locations currently tracked. More...
 
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 (Optional< LocIdx > MLoc, const DebugVariable &Var, const DbgValueProperties &Properties)
 Create a DBG_VALUE based on machine location MLoc. More...
 

Public Attributes

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

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

Member Typedef Documentation

◆ LocToValueType

IndexedMap type, mapping from LocIdx to ValueIDNum.

Definition at line 350 of file InstrRefBasedImpl.h.

◆ StackSlotPos

typedef std::pair<unsigned short, unsigned short> LiveDebugValues::MLocTracker::StackSlotPos

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

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

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

References llvm::IndexedMap< T, ToIndexT >::clear(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::clear(), and LiveDebugValues::LocIdx::MakeIllegalLoc().

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

References BB.

Referenced by writeRegMask().

◆ dump()

LLVM_DUMP_METHOD void MLocTracker::dump ( )

Definition at line 796 of file InstrRefBasedImpl.cpp.

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

◆ dump_mloc_map()

LLVM_DUMP_METHOD void MLocTracker::dump_mloc_map ( )

Definition at line 804 of file InstrRefBasedImpl.cpp.

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

◆ emitLoc()

MachineInstrBuilder MLocTracker::emitLoc ( Optional< LocIdx MLoc,
const DebugVariable Var,
const DbgValueProperties Properties 
)

◆ end()

MLocIterator LiveDebugValues::MLocTracker::end ( )
inline

Definition at line 632 of file InstrRefBasedImpl.h.

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

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

References Reg.

Referenced by MLocTracker().

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

References assert(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::end(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::find(), and LiveDebugValues::SpillLocationNo::id().

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

References llvm::MCRegisterInfo::getSubRegIdxOffset(), llvm::MCRegisterInfo::getSubRegIdxSize(), llvm::Check::Size, and TRI.

◆ getNumLocs()

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

Definition at line 497 of file InstrRefBasedImpl.h.

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

◆ getOrTrackSpillLoc()

SpillLocationNo MLocTracker::getOrTrackSpillLoc ( SpillLoc  L)

◆ getRegMLoc()

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

Determine the LocIdx of an existing register.

Definition at line 606 of file InstrRefBasedImpl.h.

References assert().

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

References LiveDebugValues::SpillLocationNo::id().

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

References Index.

◆ isSpill()

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

Return true if Idx is a spill machine location.

Definition at line 628 of file InstrRefBasedImpl.h.

Referenced by TransferTracker::isEntryValueValue(), and TransferTracker::loadInlocs().

◆ loadFromArray()

void LiveDebugValues::MLocTracker::loadFromArray ( ValueIDNum 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 510 of file InstrRefBasedImpl.h.

◆ locations()

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

Return a range over all locations currently tracked.

Definition at line 637 of file InstrRefBasedImpl.h.

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

Referenced by TransferTracker::clobberMloc(), dump(), dump_mloc_map(), TransferTracker::loadInlocs(), and writeRegMask().

◆ locIDToSpill()

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

Return the spill number that a location ID corresponds to.

Definition at line 481 of file InstrRefBasedImpl.h.

References assert().

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

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

Referenced by emitLoc(), and LocIdxToName().

◆ LocIdxToName()

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

◆ lookupOrTrackRegister()

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

Definition at line 558 of file InstrRefBasedImpl.h.

References Index.

Referenced by MLocTracker().

◆ readMLoc()

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

◆ readReg()

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

Definition at line 589 of file InstrRefBasedImpl.h.

◆ reset()

void LiveDebugValues::MLocTracker::reset ( )
inline

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

Definition at line 519 of file InstrRefBasedImpl.h.

References llvm::SmallVectorImpl< T >::clear().

Referenced by MLocTracker().

◆ setMLoc()

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

Set a locaiton to a certain value.

Definition at line 543 of file InstrRefBasedImpl.h.

References assert(), LiveDebugValues::LocIdx::asU64(), 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 502 of file InstrRefBasedImpl.h.

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

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

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

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

References LiveDebugValues::ValueIDNum::EmptyValue.

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

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

Member Data Documentation

◆ CurBB

unsigned LiveDebugValues::MLocTracker::CurBB

Definition at line 380 of file InstrRefBasedImpl.h.

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

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

Referenced by getOrTrackSpillLoc(), and MLocTracker().

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

Referenced by getOrTrackSpillLoc(), and trackRegister().

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

Referenced by trackRegister(), and writeRegMask().

◆ MF

MachineFunction& LiveDebugValues::MLocTracker::MF

Definition at line 344 of file InstrRefBasedImpl.h.

Referenced by emitLoc().

◆ NumRegs

unsigned LiveDebugValues::MLocTracker::NumRegs

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

Definition at line 383 of file InstrRefBasedImpl.h.

Referenced by emitLoc(), TransferTracker::loadInlocs(), 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 388 of file InstrRefBasedImpl.h.

Referenced by getOrTrackSpillLoc(), 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 372 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 376 of file InstrRefBasedImpl.h.

Referenced by emitLoc(), and getOrTrackSpillLoc().

◆ StackIdxesToPos

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

Inverse of StackSlotIdxes.

Definition at line 406 of file InstrRefBasedImpl.h.

Referenced by 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 403 of file InstrRefBasedImpl.h.

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

◆ TII

const TargetInstrInfo& LiveDebugValues::MLocTracker::TII

Definition at line 345 of file InstrRefBasedImpl.h.

Referenced by emitLoc().

◆ TLI

const TargetLowering& LiveDebugValues::MLocTracker::TLI

Definition at line 347 of file InstrRefBasedImpl.h.

Referenced by MLocTracker().

◆ TRI

const TargetRegisterInfo& LiveDebugValues::MLocTracker::TRI

Definition at line 346 of file InstrRefBasedImpl.h.

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


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