Variable locations now come in two modes, instruction referencing and DBG_VALUE -- I initially assumed that we could use information like the current optimisation level to detect which mode we should use (-O0 uses DBG_VALUE). Unfortunately, it turns out that SelectionDAG fiddles with the optimisation level in the presence of opt-bisect-limit (see the lines in SelectionDAGISel::runOnMachineFunction immediately below my additions), making this not a robust technique. Over in [0] there's a crash observed from this, SelectionDAG produces DBG_VALUEs but the debug-info passes expect to see DBG_INSTR_REFs.
Changing the target options in the middle of a pass is accepted as a horrible hack in the comments in SelectionDAG -- there's not much to do about this, except:
- Store a flag in MachineFunction indicating what flavour of debug-info it contains,
- Plumb the original debug-info flavour through SelectionDAG so that the correct one is picked.
This patch implements the latter: the "use instr-ref?" boolean is stored before the target options are edited, then passed down to the instruction emitting functions. This is mildly ugly, but there aren't any good options.