Go to the documentation of this file.
9 #ifndef LLVM_LIB_CODEGEN_LIVEDEBUGVALUES_INSTRREFBASEDLDV_H
10 #define LLVM_LIB_CODEGEN_LIVEDEBUGVALUES_INSTRREFBASEDLDV_H
28 class InstrRefLDVTest;
46 LocIdx() : Location(UINT_MAX) {}
49 #define NUM_LOC_BITS 24
61 bool isIllegal()
const {
return Location == UINT_MAX; }
65 bool operator==(
unsigned L)
const {
return Location == L; }
69 bool operator!=(
unsigned L)
const {
return !(*
this == L); }
74 return Location <
Other.Location;
84 return std::make_pair(SpillBase, SpillOffset) ==
85 std::make_pair(
Other.SpillBase,
Other.SpillOffset);
88 return std::make_tuple(SpillBase, SpillOffset.
getFixed(),
90 std::make_tuple(
Other.SpillBase,
Other.SpillOffset.getFixed(),
91 Other.SpillOffset.getScalable());
117 static_assert(
sizeof(u) == 8,
"Badly packed ValueIDNum?");
125 u.s = {Block, Inst, Loc};
129 u.s = {Block, Inst, Loc.
asU64()};
135 bool isPHI()
const {
return u.s.InstNo == 0; }
146 return asU64() <
Other.asU64();
150 return u.Value ==
Other.u.Value;
155 std::string
asString(
const std::string &mlocname)
const {
156 return Twine(
"Value{bb: ")
184 unsigned id()
const {
return SpillNo; }
187 return SpillNo <
Other.SpillNo;
191 return SpillNo ==
Other.SpillNo;
194 return !(*
this ==
Other);
203 : DIExpr(DIExpr), Indirect(Indirect) {}
208 DIExpr =
MI.getDebugExpression();
209 Indirect =
MI.getOperand(1).isImm();
213 return std::tie(DIExpr, Indirect) == std::tie(
Other.DIExpr,
Other.Indirect);
217 return !(*
this ==
Other);
267 :
ID(
ValueIDNum::EmptyValue), MO(MO), BlockNo(0), Properties(Prop),
276 "Empty DbgValue constructor must pass in Undef kind");
284 if (std::tie(
Kind, Properties) != std::tie(
Other.Kind,
Other.Properties))
288 else if (
Kind == NoVal && BlockNo !=
Other.BlockNo)
290 else if (
Kind == Const)
292 else if (
Kind == VPHI && BlockNo !=
Other.BlockNo)
433 return Idx ==
Other.Idx;
437 return !(*
this ==
Other);
459 return getLocID(Spill, {Size, Offs});
466 unsigned SlotNo = Spill.
id() - 1;
467 SlotNo *= NumSlotIdxes;
469 SlotNo += StackSlotIdxes[Idx];
477 unsigned SlotNo = Spill.
id() - 1;
478 SlotNo *= NumSlotIdxes;
497 unsigned Idx =
ID % NumSlotIdxes;
498 return StackIdxesToPos.
find(Idx)->second;
508 for (
auto Location : locations())
509 Location.Value = {CurBB, 0, Location.Idx};
518 for (
auto Location : locations())
519 Location.Value = Locs[Location.Idx.asU64()];
534 LocIDToLocIdx.clear();
535 LocIdxToLocID.
clear();
536 LocIdxToIDNum.
clear();
539 SpillLocs = decltype(SpillLocs)();
540 StackSlotIdxes.
clear();
541 StackIdxesToPos.
clear();
549 LocIdxToIDNum[L] = Num;
555 return LocIdxToIDNum[L];
564 if (Index.isIllegal())
565 Index = trackRegister(
ID);
571 LocIdx &Index = LocIDToLocIdx[R];
572 return !Index.isIllegal();
579 unsigned ID = getLocID(R);
580 LocIdx Idx = lookupOrTrackRegister(
ID);
582 LocIdxToIDNum[Idx] = ValueID;
588 unsigned ID = getLocID(R);
589 LocIdx Idx = lookupOrTrackRegister(
ID);
590 LocIdxToIDNum[Idx] = ValueID;
594 unsigned ID = getLocID(R);
595 LocIdx Idx = lookupOrTrackRegister(
ID);
596 return LocIdxToIDNum[Idx];
604 unsigned ID = getLocID(R);
611 unsigned ID = getLocID(R);
613 assert(LocIDToLocIdx[
ID] != UINT_MAX);
614 return LocIDToLocIdx[
ID];
620 void writeRegMask(
const MachineOperand *MO,
unsigned CurBB,
unsigned InstID);
629 assert(LocIDToLocIdx[SpillID] != UINT_MAX);
630 return LocIDToLocIdx[SpillID];
638 unsigned ID = LocIdxToLocID[L];
660 std::string LocIdxToName(
LocIdx Idx)
const;
662 std::string IDAsString(
const ValueIDNum &Num)
const;
681 std::pair<const DILocalVariable *, DIExpression::FragmentInfo>;
707 : OverlappingFragments(
O), EmptyProperties(EmptyExpr,
false) {}
713 MI.getDebugLoc()->getInlinedAt());
718 auto Result = Vars.
insert(std::make_pair(Var, Rec));
720 Result.first->second = Rec;
721 Scopes[Var] =
MI.getDebugLoc().get();
723 considerOverlaps(Var,
MI.getDebugLoc().get());
730 MI.getDebugLoc()->getInlinedAt());
735 auto Result = Vars.
insert(std::make_pair(Var, Rec));
737 Result.first->second = Rec;
738 Scopes[Var] =
MI.getDebugLoc().get();
740 considerOverlaps(Var,
MI.getDebugLoc().get());
744 auto Overlaps = OverlappingFragments.
find(
746 if (Overlaps == OverlappingFragments.
end())
750 for (
auto FragmentInfo : Overlaps->second) {
755 if (DebugVariable::isDefaultFragment(FragmentInfo))
756 OptFragmentInfo =
None;
763 auto Result = Vars.
insert(std::make_pair(Overlapped, Rec));
765 Result.first->second = Rec;
766 Scopes[Overlapped] = Loc;
779 friend class ::InstrRefLDVTest;
800 using InValueT = std::pair<MachineBasicBlock *, DbgValue *>;
862 using InstAndNum = std::pair<const MachineInstr *, unsigned>;
866 std::map<uint64_t, InstAndNum> DebugInstrNumToInstr;
869 class DebugPHIRecord {
882 operator unsigned()
const {
return InstrNum; }
893 VarToFragments SeenFragments;
904 bool AdjustsStackInCalls =
false;
994 unsigned MaxNumBlocks);
1020 void placePHIsForSingleVarDefinition(
1071 void buildVLocValueMap(
const DILocation *DILoc,
1113 const ScopeToDILocT &ScopeToDILocation,
1114 ScopeToAssignBlocksT &AssignBlocks);
1121 bool depthFirstVLocAndEmit(
1122 unsigned MaxNumBlocks,
const ScopeToDILocT &ScopeToDILocation,
1123 const ScopeToVarsT &ScopeToVars, ScopeToAssignBlocksT &ScopeToBlocks,
1131 unsigned InputDbgValLimit)
override;
1138 void dump_mloc_transfer(
const MLocTransferMap &mloc_transfer)
const;
1140 bool isCalleeSaved(
LocIdx L)
const;
1146 if (!
MI.hasOneMemOperand())
1148 auto *MemOperand = *
MI.memoperands_begin();
1149 return MemOperand->isStore() &&
1150 MemOperand->getPseudoValue() &&
1151 MemOperand->getPseudoValue()->kind() == PseudoSourceValue::FixedStack
1152 && !MemOperand->getPseudoValue()->isAliased(MFI);
Iterator for locations and the values they contain.
void setReg(Register R, ValueIDNum ValueID)
Set a register to a value number.
iterator_range< MLocIterator > locations()
Return a range over all locations currently tracked.
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
DbgValue(const MachineOperand &MO, const DbgValueProperties &Prop, KindT Kind)
This is an optimization pass for GlobalISel generic memory operations.
const DIExpression * DIExpr
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
Information about stack frame layout on the target.
MLocIterator(LocToValueType &ValueMap, LocIdx Idx)
unsigned NumRegs
Cached local copy of the number of registers the target has.
static LocIdx getEmptyKey()
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
bool operator!=(unsigned L) const
DbgValue(const ValueIDNum &Val, const DbgValueProperties &Prop, KindT Kind)
@ Undef
Value of the register doesn't matter.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Unique identifier for a value defined by an instruction, as a value type.
bool operator==(const ValueIDNum &Other) const
Reg
All possible values of the reg field in the ModR/M byte.
void setMLoc(LocIdx L, ValueIDNum Num)
Set a locaiton to a certain value.
bool operator<(const SpillLoc &Other) const
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
bool operator<(const LocIdx &Other) const
uint64_t InstNo
The block where the def happens.
bool operator!=(const DbgValueProperties &Other) const
const_iterator end(StringRef path)
Get end iterator over path.
SmallDenseMap< DebugVariable, const DILocation *, 8 > Scopes
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
bool operator==(const LocIdx &L) const
This class implements a map that also provides access to all stored values in a deterministic order.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
static bool isEqual(const ValueIDNum &A, const ValueIDNum &B)
const TargetRegisterInfo & TRI
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
bool operator==(unsigned L) const
unsigned const TargetRegisterInfo * TRI
const TargetInstrInfo & TII
Tracker for converting machine value locations and variable values into variable locations (the outpu...
ValueIDNum ID
If Kind is Def, the value number that this value is based on.
std::unique_ptr< ValueTable[]> FuncValueTable
Type for a table-of-table-of-values, i.e., the collection of either live-in or live-out values for ea...
bool operator<(const SpillLocationNo &Other) const
void wipeRegister(Register R)
Reset a register value to zero / empty.
std::pair< unsigned short, unsigned short > StackSlotPos
Pair for describing a position within a stack slot – first the size in bits, then the offset.
SmallVector< std::pair< const MachineOperand *, unsigned >, 32 > Masks
Collection of register mask operands that have been observed.
An information struct used to provide DenseMap with the various necessary components for a given valu...
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
TargetInstrInfo - Interface to description of machine instruction set.
unsigned operator()(const LocIdx &L) const
void reset()
Wipe any un-necessary location records after traversing a block.
StorageT::size_type size() const
unsigned getNumLocs() const
const TargetLowering & TLI
ValueIDNum & Value
Read-only index of this location.
StackSlotPos locIDToSpillIdx(unsigned ID) const
Returns the spill-slot size/offs that a location ID corresponds to.
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
FragmentInfo getFragmentOrDefault() const
std::vector< LocIdx > LocIDToLocIdx
"Map" of machine location IDs (i.e., raw register or spill number) to the LocIdx key / number for tha...
const HexagonInstrInfo * TII
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
MachineOperand class - Representation of each machine instruction operand.
LocIdx getSpillMLoc(unsigned SpillID)
bool operator!=(const ValueIDNum &Other) const
bool operator<(const ValueIDNum &Other) const
unsigned getLocID(Register Reg)
Produce location ID number for a Register.
DbgValueProperties EmptyProperties
uint64_t getBlock() const
UniqueVector - This class produces a sequential ID number (base 1) for each unique entry that is adde...
void defReg(Register R, unsigned BB, unsigned Inst)
Record a definition of the specified register at the given block / inst.
unsigned getLocID(SpillLocationNo Spill, StackSlotPos Idx)
Produce location ID number for a spill position.
const DILocalVariable * getVariable() const
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
DbgValueProperties Properties
Qualifiers for the ValueIDNum above.
std::pair< const DILocalVariable *, DIExpression::FragmentInfo > FragmentOfVar
Types for recording sets of variable fragments that overlap.
IndexedMap< unsigned, LocIdxToIndexFunctor > LocIdxToLocID
Inverse map of LocIDToLocIdx.
const OverlapMap & OverlappingFragments
bool operator!=(const SpillLocationNo &Other) const
std::string str() const
Return the twine contents as a std::string.
bool operator!=(const DbgValue &Other) const
void loadFromArray(ValueTable &Locs, unsigned NewCurBB)
Load values for each location from array of ValueIDNums.
Target-Independent Code Generator Pass Configuration Options.
LocIdx lookupOrTrackRegister(unsigned ID)
DbgValueProperties(const MachineInstr &MI)
Extract properties from an existing DBG_VALUE instruction.
Class recording the (high level) value of a variable.
std::pair< MachineBasicBlock *, DbgValue * > InValueT
Type for a live-in value: the predecessor block, and its value.
Representation of each machine instruction.
bool operator==(const DbgValue &Other) const
multiplies can be turned into SHL s
Identifies a unique instance of a variable.
static StackOffset getScalable(ScalarTy Scalable)
detail::concat_range< ValueT, RangeTs... > concat(RangeTs &&... Ranges)
Concatenated range across two or more ranges.
static unsigned getHashValue(const LocIdx &Loc)
value_type(LocIdx Idx, ValueIDNum &Value)
iterator find(const_arg_type_t< KeyT > Val)
Collection of DBG_VALUEs observed when traversing a block.
DenseMap< unsigned, StackSlotPos > StackIdxesToPos
Inverse of StackSlotIdxes.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static LocIdx getTombstoneKey()
bool hasFoldedStackStore(const MachineInstr &MI)
DbgValue(const DbgValueProperties &Prop, KindT Kind)
Tracker for what values are in machine locations.
static unsigned getHashValue(const ValueIDNum &Val)
static ValueIDNum getTombstoneKey()
UniqueVector< SpillLoc > SpillLocs
Unique-ification of spill.
Handle-class for a particular "location".
void considerOverlaps(const DebugVariable &Var, const DILocation *Loc)
unsigned getLocID(SpillLocationNo Spill, unsigned SpillSubReg)
Produce location ID number for a spill position.
static ValueIDNum fromU64(uint64_t v)
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
void defVar(const MachineInstr &MI, const DbgValueProperties &Properties, Optional< ValueIDNum > ID)
DbgValue(unsigned BlockNo, const DbgValueProperties &Prop, KindT Kind)
StringRef - Represent a constant reference to a string, i.e.
SmallSet< Register, 8 > SPAliases
When clobbering register masks, we chose to not believe the machine model and don't clobber SP.
StackOffset is a class to represent an offset with 2 dimensions, named fixed and scalable,...
SpillLocationNo locIDToSpill(unsigned ID) const
Return the spill number that a location ID corresponds to.
unsigned getLocSizeInBits(LocIdx L) const
How large is this location (aka, how wide is a value defined there?).
Meta qualifiers for a value.
hash_code hash_value(const IEEEFloat &Arg)
unsigned getSpillIDWithIdx(SpillLocationNo Spill, unsigned Idx)
Given a spill number, and a slot within the spill, calculate the ID number for that location.
static StackOffset getFixed(ScalarTy Fixed)
static LocIdx MakeIllegalLoc()
SpillLocationNo(unsigned SpillNo)
static ValueIDNum getEmptyKey()
unsigned const MachineRegisterInfo * MRI
Wrapper class representing virtual and physical registers.
KindT Kind
Discriminator for whether this is a constant or an in-program value.
DenseMap< StackSlotPos, unsigned > StackSlotIdxes
Map from a size/offset pair describing a position in a stack slot, to a numeric identifier for that p...
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
MapVector< DebugVariable, DbgValue > Vars
Map DebugVariable to the latest Value it's defined to have.
ValueIDNum readReg(Register R)
unsigned getRegSizeInBits(const TargetRegisterClass &RC) const
Return the size in bits of a register from class RC.
Thin wrapper around an integer – designed to give more type safety to spill location numbers.
LocIdx getRegMLoc(Register R)
Determine the LocIdx of an existing register.
static cl::opt< unsigned > InputBBLimit("livedebugvalues-input-bb-limit", cl::desc("Maximum input basic blocks before DBG_VALUE limit applies"), cl::init(10000), cl::Hidden)
VLocTracker(const OverlapMap &O, const DIExpression *EmptyExpr)
LocToValueType LocIdxToIDNum
Map of LocIdxes to the ValueIDNums that they store.
bool operator==(const MLocIterator &Other) const
bool isSpill(LocIdx Idx) const
Return true if Idx is a spill machine location.
std::unique_ptr< ValueIDNum[]> ValueTable
Type for a table of values in a block.
std::string asString(const std::string &mlocname) const
bool operator!=(const MLocIterator &Other) const
Optional< MachineOperand > MO
If Kind is Const, the MachineOperand defining this value.
Holds the characteristics of one fragment of a larger variable.
DbgValueProperties(const DIExpression *DIExpr, bool Indirect)
void setMPhis(unsigned NewCurBB)
Reset all locations to contain a PHI value at the designated block.
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
bool operator==(const SpillLoc &Other) const
void clear()
Clear all data.
static ValueIDNum EmptyValue
A range adaptor for a pair of iterators.
std::pair< DebugVariable, DbgValue > VarAndLoc
unsigned getSubRegIdxOffset(unsigned Idx) const
Get the offset of the bit range covered by a sub-register index.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void defVar(const MachineInstr &MI, const MachineOperand &MO)
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
static ValueIDNum TombstoneValue
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM BB
bool operator!=(const LocIdx &L) const
ValueIDNum(uint64_t Block, uint64_t Inst, LocIdx Loc)
bool operator==(const SpillLocationNo &Other) const
bool isRegisterTracked(Register R)
Is register R currently tracked by MLocTracker?
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
LexicalScopes - This class provides interface to collect and use lexical scoping information from mac...
bool operator==(const DbgValueProperties &Other) const
static LocIdx MakeTombstoneLoc()
ValueIDNum readMLoc(LocIdx L)
Read the value of a particular location.
int BlockNo
For a NoVal or VPHI DbgValue, which block it was generated in.
LLVM Value Representation.
ValueIDNum(uint64_t Block, uint64_t Inst, uint64_t Loc)
Optional< std::vector< StOtherPiece > > Other
bool isIdenticalTo(const MachineOperand &Other) const
Returns true if this operand is identical to the specified operand except for liveness related flags ...
unsigned NumSlotIdxes
Number of slot indexes the target has – distinct segments of a stack slot that can take on the value ...
static bool isEqual(const LocIdx &A, const LocIdx &B)
const DILocation * getInlinedAt() const
Twine concat(const Twine &Suffix) const
unsigned getSubRegIdxSize(unsigned Idx) const
Get the size of the bit range covered by a sub-register index.