Skip to content

Commit 1a8f5ef

Browse files
committed
rustc_codegen_ssa: only "spill" SSA-like values to the stack for debuginfo.
1 parent ef63e88 commit 1a8f5ef

File tree

3 files changed

+35
-33
lines changed

3 files changed

+35
-33
lines changed

src/librustc_codegen_ssa/mir/analyze.rs

-19
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use rustc::mir::visit::{
88
MutatingUseContext, NonMutatingUseContext, NonUseContext, PlaceContext, Visitor,
99
};
1010
use rustc::mir::{self, Location, TerminatorKind};
11-
use rustc::session::config::DebugInfo;
1211
use rustc::ty;
1312
use rustc::ty::layout::{HasTyCtxt, LayoutOf};
1413
use rustc_data_structures::graph::dominators::Dominators;
@@ -24,15 +23,6 @@ pub fn non_ssa_locals<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
2423
analyzer.visit_body(mir);
2524

2625
for (local, decl) in mir.local_decls.iter_enumerated() {
27-
// FIXME(eddyb): We should figure out how to use llvm.dbg.value instead
28-
// of putting everything in allocas just so we can use llvm.dbg.declare.
29-
if fx.cx.sess().opts.debuginfo == DebugInfo::Full {
30-
if fx.mir.local_kind(local) == mir::LocalKind::Arg {
31-
analyzer.not_ssa(local);
32-
continue;
33-
}
34-
}
35-
3626
let ty = fx.monomorphize(&decl.ty);
3727
debug!("local {:?} has type `{}`", local, ty);
3828
let layout = fx.cx.spanned_layout_of(ty, decl.source_info.span);
@@ -281,15 +271,6 @@ impl<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
281271
self.assign(local, location);
282272
}
283273

284-
PlaceContext::NonUse(NonUseContext::VarDebugInfo) => {
285-
// We need to keep locals in `alloca`s for debuginfo.
286-
// FIXME(eddyb): We should figure out how to use `llvm.dbg.value` instead
287-
// of putting everything in allocas just so we can use `llvm.dbg.declare`.
288-
if self.fx.cx.sess().opts.debuginfo == DebugInfo::Full {
289-
self.not_ssa(local);
290-
}
291-
}
292-
293274
PlaceContext::NonUse(_) | PlaceContext::MutatingUse(MutatingUseContext::Retag) => {}
294275

295276
PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy)

src/librustc_codegen_ssa/mir/debuginfo.rs

+34-13
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ use rustc_index::vec::IndexVec;
99
use rustc_span::symbol::{kw, Symbol};
1010
use rustc_span::{BytePos, Span};
1111

12-
use super::OperandValue;
12+
use super::operand::OperandValue;
13+
use super::place::PlaceRef;
1314
use super::{FunctionCx, LocalRef};
1415

1516
pub struct FunctionDebugContext<D> {
@@ -111,8 +112,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
111112

112113
/// Apply debuginfo and/or name, after creating the `alloca` for a local,
113114
/// or initializing the local with an operand (whichever applies).
114-
// FIXME(eddyb) use `llvm.dbg.value` (which would work for operands),
115-
// not just `llvm.dbg.declare` (which requires `alloca`).
116115
pub fn debug_introduce_local(&self, bx: &mut Bx, local: mir::Local) {
117116
let full_debug_info = bx.sess().opts.debuginfo == DebugInfo::Full;
118117

@@ -180,38 +179,60 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
180179

181180
let local_ref = &self.locals[local];
182181

183-
if !bx.sess().fewer_names() {
184-
let name = match whole_local_var.or(fallback_var) {
182+
let name = if bx.sess().fewer_names() {
183+
None
184+
} else {
185+
Some(match whole_local_var.or(fallback_var) {
185186
Some(var) if var.name != kw::Invalid => var.name.to_string(),
186187
_ => format!("{:?}", local),
187-
};
188+
})
189+
};
190+
191+
if let Some(name) = &name {
188192
match local_ref {
189193
LocalRef::Place(place) | LocalRef::UnsizedPlace(place) => {
190-
bx.set_var_name(place.llval, &name);
194+
bx.set_var_name(place.llval, name);
191195
}
192196
LocalRef::Operand(Some(operand)) => match operand.val {
193197
OperandValue::Ref(x, ..) | OperandValue::Immediate(x) => {
194-
bx.set_var_name(x, &name);
198+
bx.set_var_name(x, name);
195199
}
196200
OperandValue::Pair(a, b) => {
197201
// FIXME(eddyb) these are scalar components,
198202
// maybe extract the high-level fields?
199203
bx.set_var_name(a, &(name.clone() + ".0"));
200-
bx.set_var_name(b, &(name + ".1"));
204+
bx.set_var_name(b, &(name.clone() + ".1"));
201205
}
202206
},
203207
LocalRef::Operand(None) => {}
204208
}
205209
}
206210

207-
if !full_debug_info {
211+
if !full_debug_info || vars.is_empty() && fallback_var.is_none() {
208212
return;
209213
}
210214

211-
// FIXME(eddyb) add debuginfo for unsized places too.
212215
let base = match local_ref {
213-
LocalRef::Place(place) => place,
214-
_ => return,
216+
LocalRef::Operand(None) => return,
217+
218+
LocalRef::Operand(Some(operand)) => {
219+
// "Spill" the value onto the stack, for debuginfo,
220+
// without forcing non-debuginfo uses of the local
221+
// to also load from the stack every single time.
222+
// FIXME(#68817) use `llvm.dbg.value` instead,
223+
// at least for the cases which LLVM handles correctly.
224+
let spill_slot = PlaceRef::alloca(bx, operand.layout);
225+
if let Some(name) = name {
226+
bx.set_var_name(spill_slot.llval, &(name + ".dbg.spill"));
227+
}
228+
operand.val.store(bx, spill_slot);
229+
spill_slot
230+
}
231+
232+
LocalRef::Place(place) => *place,
233+
234+
// FIXME(eddyb) add debuginfo for unsized places too.
235+
LocalRef::UnsizedPlace(_) => return,
215236
};
216237

217238
let vars = vars.iter().copied().chain(fallback_var);

src/test/debuginfo/issue-12886.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
// gdb-command:run
88
// gdb-command:next
9-
// gdb-check:[...]25[...]s
9+
// gdb-check:[...]24[...]let s = Some(5).unwrap(); // #break
1010
// gdb-command:continue
1111

1212
#![feature(omit_gdb_pretty_printer_section)]

0 commit comments

Comments
 (0)