@@ -37,6 +37,22 @@ 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
+
40
56
void InstructionOrdering::initialize (const MachineFunction &MF) {
41
57
// We give meta instructions the same ordinal as the preceding instruction
42
58
// because this class is written for the task of comparing positions of
@@ -317,44 +333,24 @@ static void addRegDescribedVar(RegDescribedVarsMap &RegVars, unsigned RegNo,
317
333
}
318
334
319
335
// / Create a clobbering entry and end all open debug value entries
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.
336
+ // / for \p Var that are described by \p RegNo using that entry.
323
337
static void clobberRegEntries (InlinedEntity Var, unsigned RegNo,
324
338
const MachineInstr &ClobberingInstr,
325
339
DbgValueEntriesMap &LiveEntries,
326
- DbgValueHistoryMap &HistMap,
327
- SmallVectorImpl<Register> &FellowRegisters) {
340
+ DbgValueHistoryMap &HistMap) {
328
341
EntryIndex ClobberIndex = HistMap.startClobber (Var, ClobberingInstr);
342
+
329
343
// Close all entries whose values are described by the register.
330
344
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;
336
345
for (auto Index : LiveEntries[Var]) {
337
346
auto &Entry = HistMap.getEntry (Var, Index);
338
347
assert (Entry.isDbgValue () && " Not a DBG_VALUE in LiveEntries" );
339
- if (Entry.getInstr ()->isDebugEntryValue ())
340
- continue ;
341
- if (Entry.getInstr ()->hasDebugOperandForReg (RegNo)) {
348
+ if (isDescribedByReg (*Entry.getInstr ()) == RegNo) {
342
349
IndicesToErase.push_back (Index);
343
350
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
-
358
354
// Drop all entries that have ended.
359
355
for (auto Index : IndicesToErase)
360
356
LiveEntries[Var].erase (Index);
@@ -382,24 +378,17 @@ static void handleNewDebugValue(InlinedEntity Var, const MachineInstr &DV,
382
378
IndicesToErase.push_back (Index);
383
379
Entry.endEntry (NewIndex);
384
380
}
385
- if (!DV.isDebugEntryValue ())
386
- for (const MachineOperand &Op : DV.debug_operands ())
387
- if (Op.isReg () && Op.getReg ())
388
- TrackedRegs[Op.getReg ()] |= !Overlaps;
381
+ if (Register Reg = isDescribedByReg (DV))
382
+ TrackedRegs[Reg] |= !Overlaps;
389
383
}
390
384
391
385
// If the new debug value is described by a register, add tracking of
392
386
// that register if it is not already tracked.
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
- }
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 ;
403
392
}
404
393
405
394
// Drop tracking of registers that are no longer used.
@@ -422,16 +411,9 @@ static void clobberRegisterUses(RegDescribedVarsMap &RegVars,
422
411
DbgValueEntriesMap &LiveEntries,
423
412
const MachineInstr &ClobberingInstr) {
424
413
// Iterate over all variables described by this register and add this
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
- }
414
+ // instruction to their history, clobbering it.
415
+ for (const auto &Var : I->second )
416
+ clobberRegEntries (Var, I->first , ClobberingInstr, LiveEntries, HistMap);
435
417
RegVars.erase (I);
436
418
}
437
419
0 commit comments