Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_gcc/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1069,7 +1069,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
OperandValue::Ref(place.val)
};

OperandRef { val, layout: place.layout }
OperandRef { val, layout: place.layout, move_annotation: None }
}

fn write_operand_repeatedly(
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_gcc/src/debuginfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::context::CodegenCx;
pub(super) const UNKNOWN_LINE_NUMBER: u32 = 0;
pub(super) const UNKNOWN_COLUMN_NUMBER: u32 = 0;

impl<'a, 'gcc, 'tcx> DebugInfoBuilderMethods for Builder<'a, 'gcc, 'tcx> {
impl<'a, 'gcc, 'tcx> DebugInfoBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
// FIXME(eddyb) find a common convention for all of the debuginfo-related
// names (choose between `dbg`, `debug`, `debuginfo`, `debug_info` etc.).
fn dbg_var_addr(
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ impl<'ll, 'tcx> ArgAbiExt<'ll, 'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
);
bx.lifetime_end(llscratch, scratch_size);
}
_ => {
PassMode::Pair(..) | PassMode::Direct { .. } => {
OperandRef::from_immediate_or_packed_pair(bx, val, self.layout).val.store(bx, dst);
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ fn report_inline_asm(
llvm::DiagnosticLevel::Warning => Level::Warning,
llvm::DiagnosticLevel::Note | llvm::DiagnosticLevel::Remark => Level::Note,
};
let msg = msg.strip_prefix("error: ").unwrap_or(&msg).to_string();
let msg = msg.trim_prefix("error: ").to_string();
cgcx.diag_emitter.inline_asm_error(span, msg, level, source);
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
OperandValue::Ref(place.val)
};

OperandRef { val, layout: place.layout }
OperandRef { val, layout: place.layout, move_annotation: None }
}

fn write_operand_repeatedly(
Expand Down
53 changes: 52 additions & 1 deletion compiler/rustc_codegen_llvm/src/debuginfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl<'ll> Builder<'_, 'll, '_> {
}
}

impl<'ll> DebugInfoBuilderMethods for Builder<'_, 'll, '_> {
impl<'ll, 'tcx> DebugInfoBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
// FIXME(eddyb) find a common convention for all of the debuginfo-related
// names (choose between `dbg`, `debug`, `debuginfo`, `debug_info` etc.).
fn dbg_var_addr(
Expand Down Expand Up @@ -284,6 +284,57 @@ impl<'ll> DebugInfoBuilderMethods for Builder<'_, 'll, '_> {
llvm::set_value_name(value, name.as_bytes());
}
}

/// Annotate move/copy operations with debug info for profiling.
///
/// This creates a temporary debug scope that makes the move/copy appear as an inlined call to
/// `compiler_move<T, SIZE>()` or `compiler_copy<T, SIZE>()`. The provided closure is executed
/// with this temporary debug location active.
///
/// The `instance` parameter should be the monomorphized instance of the `compiler_move` or
/// `compiler_copy` function with the actual type and size.
fn with_move_annotation<R>(
&mut self,
instance: ty::Instance<'tcx>,
f: impl FnOnce(&mut Self) -> R,
) -> R {
// Save the current debug location
let saved_loc = self.get_dbg_loc();

// Create a DIScope for the compiler_move/compiler_copy function
// We use the function's FnAbi for debug info generation
let fn_abi = self
.cx()
.tcx
.fn_abi_of_instance(
self.cx().typing_env().as_query_input((instance, ty::List::empty())),
)
.unwrap();

let di_scope = self.cx().dbg_scope_fn(instance, fn_abi, None);

// Create an inlined debug location:
// - scope: the compiler_move/compiler_copy function
// - inlined_at: the current location (where the move/copy actually occurs)
// - span: use the function's definition span
let fn_span = self.cx().tcx.def_span(instance.def_id());
let inlined_loc = self.cx().dbg_loc(di_scope, saved_loc, fn_span);

// Set the temporary debug location
self.set_dbg_loc(inlined_loc);

// Execute the closure (which will generate the memcpy)
let result = f(self);

// Restore the original debug location
if let Some(loc) = saved_loc {
self.set_dbg_loc(loc);
} else {
self.clear_dbg_loc();
}

result
}
}

/// A source code location used to generate debug information.
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_codegen_llvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#![feature(macro_derive)]
#![feature(rustdoc_internals)]
#![feature(slice_as_array)]
#![feature(trim_prefix_suffix)]
#![feature(try_blocks)]
// tidy-alphabetical-end

Expand Down
14 changes: 8 additions & 6 deletions compiler/rustc_codegen_ssa/src/mir/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,9 +557,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
let op = match self.locals[mir::RETURN_PLACE] {
LocalRef::Operand(op) => op,
LocalRef::PendingOperand => bug!("use of return before def"),
LocalRef::Place(cg_place) => {
OperandRef { val: Ref(cg_place.val), layout: cg_place.layout }
}
LocalRef::Place(cg_place) => OperandRef {
val: Ref(cg_place.val),
layout: cg_place.layout,
move_annotation: None,
},
LocalRef::UnsizedPlace(_) => bug!("return type must be sized"),
};
let llslot = match op.val {
Expand Down Expand Up @@ -1155,7 +1157,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
| (&mir::Operand::Constant(_), Ref(PlaceValue { llextra: None, .. })) => {
let tmp = PlaceRef::alloca(bx, op.layout);
bx.lifetime_start(tmp.val.llval, tmp.layout.size);
op.val.store(bx, tmp);
op.store_with_annotation(bx, tmp);
op.val = Ref(tmp.val);
lifetime_ends_after_call.push((tmp.val.llval, tmp.layout.size));
}
Expand Down Expand Up @@ -1563,13 +1565,13 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
};
let scratch = PlaceValue::alloca(bx, arg.layout.size, required_align);
bx.lifetime_start(scratch.llval, arg.layout.size);
op.val.store(bx, scratch.with_type(arg.layout));
op.store_with_annotation(bx, scratch.with_type(arg.layout));
lifetime_ends_after_call.push((scratch.llval, arg.layout.size));
(scratch.llval, scratch.align, true)
}
PassMode::Cast { .. } => {
let scratch = PlaceRef::alloca(bx, arg.layout);
op.val.store(bx, scratch);
op.store_with_annotation(bx, scratch);
(scratch.val.llval, scratch.val.align, true)
}
_ => (op.immediate_or_packed_pair(bx), arg.layout.align.abi, false),
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_codegen_ssa/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ fn arg_local_refs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
return local(OperandRef {
val: OperandValue::Pair(a, b),
layout: arg.layout,
move_annotation: None,
});
}
_ => {}
Expand Down Expand Up @@ -552,6 +553,7 @@ fn arg_local_refs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
fx.caller_location = Some(OperandRef {
val: OperandValue::Immediate(bx.get_param(llarg_idx)),
layout: arg.layout,
move_annotation: None,
});
}

Expand Down
Loading
Loading