@@ -37,22 +37,6 @@ namespace {
37
37
using EntryIndex = DbgValueHistoryMap::EntryIndex;
38
38
}
39
39
40
- // If @MI is a DBG_VALUE with debug value described by a
41
- // defined register, returns the number of this register.
42
- // In the other case, returns 0.
43
- static Register isDescribedByReg (const MachineInstr &MI) {
44
- assert (MI.isDebugValue ());
45
- assert (MI.getNumOperands () == 4 );
46
- // If the location of variable is an entry value (DW_OP_LLVM_entry_value)
47
- // do not consider it as a register location.
48
- if (MI.getDebugExpression ()->isEntryValue ())
49
- return 0 ;
50
- // If location of variable is described using a register (directly or
51
- // indirectly), this register is always a first operand.
52
- return MI.getDebugOperand (0 ).isReg () ? MI.getDebugOperand (0 ).getReg ()
53
- : Register ();
54
- }
55
-
56
40
void InstructionOrdering::initialize (const MachineFunction &MF) {
57
41
// We give meta instructions the same ordinal as the preceding instruction
58
42
// because this class is written for the task of comparing positions of
@@ -333,24 +317,44 @@ static void addRegDescribedVar(RegDescribedVarsMap &RegVars, unsigned RegNo,
333
317
}
334
318
335
319
// / Create a clobbering entry and end all open debug value entries
336
- // / for \p Var that are described by \p RegNo using that entry.
320
+ // / for \p Var that are described by \p RegNo using that entry. Inserts into \p
321
+ // / FellowRegisters the set of Registers that were also used to describe \p Var
322
+ // / alongside \p RegNo.
337
323
static void clobberRegEntries (InlinedEntity Var, unsigned RegNo,
338
324
const MachineInstr &ClobberingInstr,
339
325
DbgValueEntriesMap &LiveEntries,
340
- DbgValueHistoryMap &HistMap) {
326
+ DbgValueHistoryMap &HistMap,
327
+ SmallVectorImpl<Register> &FellowRegisters) {
341
328
EntryIndex ClobberIndex = HistMap.startClobber (Var, ClobberingInstr);
342
-
343
329
// Close all entries whose values are described by the register.
344
330
SmallVector<EntryIndex, 4 > IndicesToErase;
331
+ // If a given register appears in a live DBG_VALUE_LIST for Var alongside the
332
+ // clobbered register, and never appears in a live DBG_VALUE* for Var without
333
+ // the clobbered register, then it is no longer linked to the variable.
334
+ SmallSet<Register, 4 > MaybeRemovedRegisters;
335
+ SmallSet<Register, 4 > KeepRegisters;
345
336
for (auto Index : LiveEntries[Var]) {
346
337
auto &Entry = HistMap.getEntry (Var, Index);
347
338
assert (Entry.isDbgValue () && " Not a DBG_VALUE in LiveEntries" );
348
- if (isDescribedByReg (*Entry.getInstr ()) == RegNo) {
339
+ if (Entry.getInstr ()->isDebugEntryValue ())
340
+ continue ;
341
+ if (Entry.getInstr ()->hasDebugOperandForReg (RegNo)) {
349
342
IndicesToErase.push_back (Index);
350
343
Entry.endEntry (ClobberIndex);
344
+ for (auto &MO : Entry.getInstr ()->debug_operands ())
345
+ if (MO.isReg () && MO.getReg () && MO.getReg () != RegNo)
346
+ MaybeRemovedRegisters.insert (MO.getReg ());
347
+ } else {
348
+ for (auto &MO : Entry.getInstr ()->debug_operands ())
349
+ if (MO.isReg () && MO.getReg ())
350
+ KeepRegisters.insert (MO.getReg ());
351
351
}
352
352
}
353
353
354
+ for (Register Reg : MaybeRemovedRegisters)
355
+ if (!KeepRegisters.contains (Reg))
356
+ FellowRegisters.push_back (Reg);
357
+
354
358
// Drop all entries that have ended.
355
359
for (auto Index : IndicesToErase)
356
360
LiveEntries[Var].erase (Index);
@@ -378,17 +382,24 @@ static void handleNewDebugValue(InlinedEntity Var, const MachineInstr &DV,
378
382
IndicesToErase.push_back (Index);
379
383
Entry.endEntry (NewIndex);
380
384
}
381
- if (Register Reg = isDescribedByReg (DV))
382
- TrackedRegs[Reg] |= !Overlaps;
385
+ if (!DV.isDebugEntryValue ())
386
+ for (const MachineOperand &Op : DV.debug_operands ())
387
+ if (Op.isReg () && Op.getReg ())
388
+ TrackedRegs[Op.getReg ()] |= !Overlaps;
383
389
}
384
390
385
391
// If the new debug value is described by a register, add tracking of
386
392
// that register if it is not already tracked.
387
- if (Register NewReg = isDescribedByReg (DV)) {
388
- if (!TrackedRegs.count (NewReg))
389
- addRegDescribedVar (RegVars, NewReg, Var);
390
- LiveEntries[Var].insert (NewIndex);
391
- TrackedRegs[NewReg] = true ;
393
+ if (!DV.isDebugEntryValue ()) {
394
+ for (const MachineOperand &Op : DV.debug_operands ()) {
395
+ if (Op.isReg () && Op.getReg ()) {
396
+ Register NewReg = Op.getReg ();
397
+ if (!TrackedRegs.count (NewReg))
398
+ addRegDescribedVar (RegVars, NewReg, Var);
399
+ LiveEntries[Var].insert (NewIndex);
400
+ TrackedRegs[NewReg] = true ;
401
+ }
402
+ }
392
403
}
393
404
394
405
// Drop tracking of registers that are no longer used.
@@ -411,9 +422,16 @@ static void clobberRegisterUses(RegDescribedVarsMap &RegVars,
411
422
DbgValueEntriesMap &LiveEntries,
412
423
const MachineInstr &ClobberingInstr) {
413
424
// Iterate over all variables described by this register and add this
414
- // instruction to their history, clobbering it.
415
- for (const auto &Var : I->second )
416
- clobberRegEntries (Var, I->first , ClobberingInstr, LiveEntries, HistMap);
425
+ // instruction to their history, clobbering it. All registers that also
426
+ // describe the clobbered variables (i.e. in variadic debug values) will have
427
+ // those Variables removed from their DescribedVars.
428
+ for (const auto &Var : I->second ) {
429
+ SmallVector<Register, 4 > FellowRegisters;
430
+ clobberRegEntries (Var, I->first , ClobberingInstr, LiveEntries, HistMap,
431
+ FellowRegisters);
432
+ for (Register RegNo : FellowRegisters)
433
+ dropRegDescribedVar (RegVars, RegNo, Var);
434
+ }
417
435
RegVars.erase (I);
418
436
}
419
437
0 commit comments