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");
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];
92 auto &
Entries = VarEntries[Var];
113static std::optional<ArrayRef<InsnRange>::iterator>
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()) &&
163 (Scope->getScopeNode() == LocalVar->getScope()))
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) {
243 Offsets[EntryIdx] = CurOffset;
248 for (
auto &
Entry : HistoryMapEntries)
255 HistoryMapEntries.erase(HistoryMapEntries.begin() +
Idx);
267 if (
MI->isUndefDebugValue())
277 assert(
MI.isDebugLabel() &&
"not a DBG_LABEL");
278 LabelInstr[Label] = &
MI;
285using RegDescribedVarsMap = std::map<unsigned, SmallVector<InlinedEntity, 1>>;
291using 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]) {
337 assert(Entry.isDbgValue() &&
"Not a DBG_VALUE in LiveEntries");
338 if (Entry.getInstr()->isDebugEntryValue())
340 if (Entry.getInstr()->hasDebugOperandForReg(RegNo)) {
342 Entry.endEntry(ClobberIndex);
343 for (
const auto &MO : Entry.getInstr()->debug_operands())
344 if (MO.isReg() && MO.getReg() && MO.getReg() != RegNo)
345 MaybeRemovedRegisters.
insert(MO.getReg());
347 for (
const auto &MO : Entry.getInstr()->debug_operands())
348 if (MO.isReg() && MO.getReg())
349 KeepRegisters.
insert(MO.getReg());
353 for (
Register Reg : MaybeRemovedRegisters)
358 for (
auto Index : IndicesToErase)
359 LiveEntries[Var].erase(
Index);
364 RegDescribedVarsMap &RegVars,
365 DbgValueEntriesMap &LiveEntries,
375 for (
auto Index : LiveEntries[Var]) {
377 assert(Entry.isDbgValue() &&
"Not a DBG_VALUE in LiveEntries");
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)
498 if (MO.getReg().isVirtual())
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))
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) {
567 dbgs() <<
" - " << LocalVar->getName() <<
" at ";
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";
ReachingDefAnalysis InstSet & ToRemove
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
static std::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.
static void addRegDescribedVar(RegDescribedVarsMap &RegVars, unsigned RegNo, InlinedEntity Var)
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...
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.
static void dropRegDescribedVar(RegDescribedVarsMap &RegVars, unsigned RegNo, InlinedEntity Var)
static void clobberRegisterUses(RegDescribedVarsMap &RegVars, RegDescribedVarsMap::iterator I, DbgValueHistoryMap &HistMap, DbgValueEntriesMap &LiveEntries, const MachineInstr &ClobberingInstr)
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
unsigned const TargetRegisterInfo * TRI
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallSet class.
This file defines the SmallVector class.
This file describes how to lower LLVM code to machine code.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
static bool fragmentsOverlap(const FragmentInfo &A, const FragmentInfo &B)
Check if fragments overlap between a pair of FragmentInfos.
bool isValidLocationForIntrinsic(const DILocation *DL) const
Check that a location is valid for this label.
bool isValidLocationForIntrinsic(const DILocation *DL) const
Check that a location is valid for this variable.
For each inlined instance of a source-level label, keep the corresponding DBG_LABEL instruction.
std::pair< const DINode *, const DILocation * > InlinedEntity
void addInstr(InlinedEntity Label, const MachineInstr &MI)
Specifies a change in a variable's debug value history.
const MachineInstr * getInstr() const
EntryIndex getEndIndex() const
void endEntry(EntryIndex EndIndex)
For each user variable, keep a list of instruction ranges where this variable is accessible.
bool startDbgValue(InlinedEntity Var, const MachineInstr &MI, EntryIndex &NewIndex)
void trimLocationRanges(const MachineFunction &MF, LexicalScopes &LScopes, const InstructionOrdering &Ordering)
Drop location ranges which exist entirely outside each variable's scope.
size_t EntryIndex
Index in the entry vector.
EntryIndex startClobber(InlinedEntity Var, const MachineInstr &MI)
Entry & getEntry(InlinedEntity Var, EntryIndex Index)
static const EntryIndex NoEntry
Special value to indicate that an entry is valid until the end of the function.
bool hasNonEmptyLocation(const Entries &Entries) const
Test whether a vector of entries features any non-empty locations.
std::pair< const DINode *, const DILocation * > InlinedEntity
LLVM_DUMP_METHOD void dump() const
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
Record instruction ordering so we can query their relative positions within a function.
void initialize(const MachineFunction &MF)
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...
LexicalScope - This class is used to track scope information.
LexicalScopes - This class provides interface to collect and use lexical scoping information from mac...
LexicalScope * findLexicalScope(const DILocation *DL)
findLexicalScope - Find lexical scope, either regular or inlined, for the given DebugLoc.
LexicalScope * findInlinedScope(const DILocalScope *N, const DILocation *IA)
findInlinedScope - Find an inlined scope for the given scope/inlined-at.
MCRegAliasIterator enumerates all registers aliasing Reg.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
const MachineBasicBlock & back() const
Representation of each machine 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...
const DIExpression * getDebugExpression() const
Return the complex address expression referenced by this DBG_VALUE instruction.
bool isDebugEntryValue() const
A DBG_VALUE is an entry value iff its debug expression contains the DW_OP_LLVM_entry_value operation.
MachineOperand class - Representation of each machine instruction operand.
Wrapper class representing virtual and physical registers.
static bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
bool contains(const T &V) const
Check if the SmallSet contains the given element.
std::pair< const_iterator, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void assign(size_type NumElts, ValueParamT Elt)
reference emplace_back(ArgTypes &&... Args)
void push_back(const T &Elt)
Register getStackPointerRegisterToSaveRestore() const
If a physical register, this specifies the register that llvm.savestack/llvm.restorestack should save...
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual const TargetLowering * getTargetLowering() const
This is an optimization pass for GlobalISel generic memory operations.
auto find(R &&Range, const T &Val)
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly.
void calculateDbgEntityHistory(const MachineFunction *MF, const TargetRegisterInfo *TRI, DbgValueHistoryMap &DbgValues, DbgLabelInstrMap &DbgLabels)
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are are tuples (A,...
auto reverse(ContainerTy &&C)
void sort(IteratorTy Start, IteratorTy End)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.