Go to the documentation of this file.
33 #define DEBUG_TYPE "dwarfdebug"
56 unsigned Position = 0;
59 InstNumberMap[&
MI] =
MI.isMetaInstruction() ? Position : ++Position;
64 assert(A->getParent() &&
B->getParent() &&
"Operands must have a parent");
65 assert(A->getMF() ==
B->getMF() &&
66 "Operands must be in the same MachineFunction");
67 return InstNumberMap.lookup(A) < InstNumberMap.lookup(
B);
75 assert(
MI.isDebugValue() &&
"not a DBG_VALUE");
76 auto &
Entries = VarEntries[Var];
79 Entries.back().getInstr()->isIdenticalTo(
MI)) {
81 <<
"\t" <<
Entries.back().getInstr() <<
"\t" <<
MI
92 auto &
Entries = VarEntries[Var];
117 for (
auto RangesI = Ranges.
begin(), RangesE = Ranges.
end();
118 RangesI != RangesE; ++RangesI) {
119 if (EndMI && Ordering.
isBefore(EndMI, RangesI->first))
121 if (EndMI && !Ordering.
isBefore(RangesI->second, EndMI))
123 if (Ordering.
isBefore(StartMI, RangesI->second))
141 for (
auto &
Record : VarEntries) {
142 auto &HistoryMapEntries =
Record.second;
143 if (HistoryMapEntries.empty())
150 if (
const DILocation *InlinedAt = Entity.second) {
162 (
Scope->getScopeNode() ==
Scope->getScopeNode()->getSubprogram()) &&
174 ReferenceCount.
assign(HistoryMapEntries.size(), 0);
179 for (
auto EI = HistoryMapEntries.begin(), EE = HistoryMapEntries.end();
180 EI != EE; ++EI, ++StartIndex) {
182 if (!EI->isDbgValue())
189 ReferenceCount[EndIndex] += 1;
194 if (ReferenceCount[StartIndex] > 0)
199 ? HistoryMapEntries[EndIndex].getInstr()
203 if (
auto R =
intersects(StartMI, EndMI, ScopeRanges, Ordering)) {
215 ReferenceCount[EndIndex] -= 1;
224 for (
size_t i = 0;
i < HistoryMapEntries.size(); ++
i)
225 if (ReferenceCount[
i] <= 0 && HistoryMapEntries[
i].isClobber())
233 Offsets.assign(HistoryMapEntries.size(), 0);
234 size_t CurOffset = 0;
235 auto ToRemoveItr =
ToRemove.begin();
236 for (
size_t EntryIdx = *ToRemoveItr; EntryIdx < HistoryMapEntries.size();
239 if (ToRemoveItr !=
ToRemove.end() && *ToRemoveItr == EntryIdx) {
248 for (
auto &
Entry : HistoryMapEntries)
255 HistoryMapEntries.erase(HistoryMapEntries.begin() + Idx);
267 if (
MI->getOperand(0).isReg() &&
MI->getOperand(0).getReg() == 0)
277 assert(
MI.isDebugLabel() &&
"not a DBG_LABEL");
278 LabelInstr[Label] = &
MI;
285 using RegDescribedVarsMap = std::map<unsigned, SmallVector<InlinedEntity, 1>>;
291 using DbgValueEntriesMap = std::map<InlinedEntity, SmallSet<EntryIndex, 1>>;
298 const auto &
I = RegVars.find(RegNo);
299 assert(RegNo != 0U &&
I != RegVars.end());
300 auto &VarSet =
I->second;
302 assert(VarPos != VarSet.end());
303 VarSet.erase(VarPos);
313 auto &VarSet = RegVars[RegNo];
315 VarSet.push_back(Var);
324 DbgValueEntriesMap &LiveEntries,
335 for (
auto Index : LiveEntries[Var]) {
336 auto &Entry = HistMap.
getEntry(Var, Index);
337 assert(Entry.isDbgValue() &&
"Not a DBG_VALUE in LiveEntries");
338 if (Entry.getInstr()->isDebugEntryValue())
340 if (Entry.getInstr()->hasDebugOperandForReg(RegNo)) {
341 IndicesToErase.push_back(Index);
342 Entry.endEntry(ClobberIndex);
343 for (
auto &MO : Entry.getInstr()->debug_operands())
344 if (MO.isReg() && MO.getReg() && MO.getReg() != RegNo)
345 MaybeRemovedRegisters.
insert(MO.getReg());
347 for (
auto &MO : Entry.getInstr()->debug_operands())
348 if (MO.isReg() && MO.getReg())
349 KeepRegisters.
insert(MO.getReg());
355 FellowRegisters.push_back(
Reg);
358 for (
auto Index : IndicesToErase)
359 LiveEntries[Var].
erase(Index);
364 RegDescribedVarsMap &RegVars,
365 DbgValueEntriesMap &LiveEntries,
375 for (
auto Index : LiveEntries[Var]) {
376 auto &Entry = HistMap.
getEntry(Var, Index);
377 assert(Entry.isDbgValue() &&
"Not a DBG_VALUE in LiveEntries");
381 IndicesToErase.push_back(Index);
382 Entry.endEntry(NewIndex);
386 if (
Op.isReg() &&
Op.getReg())
387 TrackedRegs[
Op.getReg()] |= !Overlaps;
394 if (
Op.isReg() &&
Op.getReg()) {
396 if (!TrackedRegs.
count(NewReg))
398 LiveEntries[Var].insert(NewIndex);
399 TrackedRegs[NewReg] =
true;
405 for (
auto I : TrackedRegs)
410 for (
auto Index : IndicesToErase)
411 LiveEntries[Var].erase(Index);
412 LiveEntries[Var].insert(NewIndex);
419 RegDescribedVarsMap::iterator
I,
421 DbgValueEntriesMap &LiveEntries,
427 for (
const auto &Var :
I->second) {
431 for (
Register RegNo : FellowRegisters)
441 DbgValueEntriesMap &LiveEntries,
443 const auto &
I = RegVars.find(RegNo);
444 if (
I == RegVars.end())
456 RegDescribedVarsMap RegVars;
457 DbgValueEntriesMap LiveEntries;
458 for (
const auto &
MBB : *MF) {
459 for (
const auto &
MI :
MBB) {
460 if (
MI.isDebugValue()) {
461 assert(
MI.getNumOperands() > 1 &&
"Invalid DBG_VALUE instruction!");
467 "Expected inlined-at fields to agree");
471 }
else if (
MI.isDebugLabel()) {
472 assert(
MI.getNumOperands() == 1 &&
"Invalid DBG_LABEL instruction!");
473 const DILabel *RawLabel =
MI.getDebugLabel();
475 "Expected inlined-at fields to agree");
485 if (
MI.isMetaInstruction())
491 if (MO.isReg() && MO.isDef() && MO.getReg()) {
494 if (
MI.isCall() && MO.getReg() == SP)
505 else if (MO.getReg() != FrameReg ||
512 }
else if (MO.isRegMask()) {
517 for (
auto It : RegVars) {
518 unsigned int Reg = It.first;
520 MO.clobbersPhysReg(
Reg))
521 RegsToClobber.push_back(
Reg);
524 for (
unsigned Reg : RegsToClobber) {
536 for (
auto &Pair : LiveEntries) {
537 if (Pair.second.empty())
557 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
559 dbgs() <<
"DbgValueHistoryMap:\n";
560 for (
const auto &VarRangePair : *
this) {
570 dbgs() << Location->getFilename() <<
":" << Location->getLine() <<
":"
571 << Location->getColumn();
573 dbgs() <<
"<unknown location>";
578 const auto &
Entry =
E.value();
579 dbgs() <<
" Entry[" <<
E.index() <<
"]: ";
581 dbgs() <<
"Debug value\n";
583 dbgs() <<
"Clobber\n";
587 dbgs() <<
" - Valid until end of function\n";
void initialize(const MachineFunction &MF)
Register getStackPointerRegisterToSaveRestore() const
If a physical register, this specifies the register that llvm.savestack/llvm.restorestack should save...
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
This is an optimization pass for GlobalISel generic memory operations.
iterator erase(const_iterator CI)
For each inlined instance of a source-level label, keep the corresponding DBG_LABEL instruction.
iterator_range< mop_iterator > debug_operands()
Returns a range over all operands that are used to determine the variable location for this DBG_VALUE...
Specifies a change in a variable's debug value history.
LexicalScope - This class is used to track scope information.
detail::enumerator< R > enumerate(R &&TheRange)
Given an input range, returns a new range whose values are are pair (A,B) such that A is the 0-based ...
ReachingDefAnalysis InstSet & ToRemove
Reg
All possible values of the reg field in the ModR/M byte.
size_t EntryIndex
Index in the entry vector.
static Optional< ArrayRef< InsnRange >::iterator > intersects(const MachineInstr *StartMI, const MachineInstr *EndMI, const ArrayRef< InsnRange > &Ranges, const InstructionOrdering &Ordering)
Check if the instruction range [StartMI, EndMI] intersects any instruction range in Ranges.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
auto reverse(ContainerTy &&C, std::enable_if_t< has_rbegin< ContainerTy >::value > *=nullptr)
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
llvm::DenseMapBase< SmallDenseMap< KeyT, ValueT, 4, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >, KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >::count size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
unsigned const TargetRegisterInfo * TRI
bool startDbgValue(InlinedEntity Var, const MachineInstr &MI, EntryIndex &NewIndex)
EntryIndex getEndIndex() const
bool isValidLocationForIntrinsic(const DILocation *DL) const
Check that a location is valid for this label.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
const MachineInstr * getInstr() const
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
static bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
void calculateDbgEntityHistory(const MachineFunction *MF, const TargetRegisterInfo *TRI, DbgValueHistoryMap &DbgValues, DbgLabelInstrMap &DbgLabels)
bool isBefore(const MachineInstr *A, const MachineInstr *B) const
Check if instruction A comes before B, where A and B both belong to the MachineFunction passed to ini...
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
MachineOperand class - Representation of each machine instruction operand.
std::pair< const DINode *, const DILocation * > InlinedEntity
bool isValidLocationForIntrinsic(const DILocation *DL) const
Check that a location is valid for this variable.
bool hasNonEmptyLocation(const Entries &Entries) const
Test whether a vector of entries features any non-empty locations.
Record instruction ordering so we can query their relative positions within a function.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
EntryIndex startClobber(InlinedEntity Var, const MachineInstr &MI)
LLVM_DUMP_METHOD void dump() const
static void handleNewDebugValue(InlinedEntity Var, const MachineInstr &DV, RegDescribedVarsMap &RegVars, DbgValueEntriesMap &LiveEntries, DbgValueHistoryMap &HistMap)
Add a new debug value for Var. Closes all overlapping debug values.
const DIExpression * getDebugExpression() const
Return the complex address expression referenced by this DBG_VALUE instruction.
Representation of each machine instruction.
auto find(R &&Range, const T &Val)
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly.
virtual Register getFrameRegister(const MachineFunction &MF) const =0
Debug information queries.
static const EntryIndex NoEntry
Special value to indicate that an entry is valid until the end of the function.
bool is_contained(R &&Range, const E &Element)
Wrapper function around std::find to detect if an element exists in a container.
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void endEntry(EntryIndex EndIndex)
Entry & getEntry(InlinedEntity Var, EntryIndex Index)
void trimLocationRanges(const MachineFunction &MF, LexicalScopes &LScopes, const InstructionOrdering &Ordering)
Drop location ranges which exist entirely outside each variable's scope.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Scope
Defines the scope in which this symbol should be visible: Default – Visible in the public interface o...
std::pair< NoneType, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
Wrapper class representing virtual and physical registers.
For each user variable, keep a list of instruction ranges where this variable is accessible.
void addInstr(InlinedEntity Label, const MachineInstr &MI)
void assign(size_type NumElts, ValueParamT Elt)
LexicalScope * findInlinedScope(const DILocalScope *N, const DILocation *IA)
findInlinedScope - Find an inlined scope for the given scope/inlined-at.
LexicalScope * findLexicalScope(const DILocation *DL)
findLexicalScope - Find lexical scope, either regular or inlined, for the given DebugLoc.
bool isDebugEntryValue() const
A DBG_VALUE is an entry value iff its debug expression contains the DW_OP_LLVM_entry_value operation.
void sort(IteratorTy Start, IteratorTy End)
std::pair< const DINode *, const DILocation * > InlinedEntity
static void clobberRegEntries(InlinedEntity Var, unsigned RegNo, const MachineInstr &ClobberingInstr, DbgValueEntriesMap &LiveEntries, DbgValueHistoryMap &HistMap, SmallVectorImpl< Register > &FellowRegisters)
Create a clobbering entry and end all open debug value entries for Var that are described by RegNo us...
virtual const TargetLowering * getTargetLowering() const
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
static void dropRegDescribedVar(RegDescribedVarsMap &RegVars, unsigned RegNo, InlinedEntity Var)
static void addRegDescribedVar(RegDescribedVarsMap &RegVars, unsigned RegNo, InlinedEntity Var)
LexicalScopes - This class provides interface to collect and use lexical scoping information from mac...
static void clobberRegisterUses(RegDescribedVarsMap &RegVars, RegDescribedVarsMap::iterator I, DbgValueHistoryMap &HistMap, DbgValueEntriesMap &LiveEntries, const MachineInstr &ClobberingInstr)
bool contains(const T &V) const
Check if the SmallSet contains the given element.
MCRegAliasIterator enumerates all registers aliasing Reg.
reference emplace_back(ArgTypes &&... Args)
static bool fragmentsOverlap(const FragmentInfo &A, const FragmentInfo &B)
Check if fragments overlap between a pair of FragmentInfos.