Skip to content

Commit f7b6605

Browse files
jsgfJeremy Fitzhardinge
authored andcommitted
Add -Zannotate-moves for profiler visibility of move/copy operations
This implements a new unstable compiler flag `-Zannotate-moves` that makes move and copy operations visible in profilers by creating synthetic debug information. This is achieved with zero runtime cost by manipulating debug info scopes to make moves/copies appear as calls to `compiler_move<T, SIZE>` and `compiler_copy<T, SIZE>` marker functions in profiling tools. This allows developers to identify expensive move/copy operations in their code using standard profiling tools, without requiring specialized tooling or runtime instrumentation. The implementation works at codegen time. When processing MIR operands (`Operand::Move` and `Operand::Copy`), the codegen creates an `OperandRef` with an optional `move_annotation` field containing an `Instance` of the appropriate profiling marker function. When storing the operand, `store_with_annotation()` wraps the store operation in a synthetic debug scope that makes it appear inlined from the marker. Two marker functions (`compiler_move` and `compiler_copy`) are defined in `library/core/src/profiling.rs`. These are never actually called - they exist solely as debug info anchors. Operations are only annotated if the type: - Meets the size threshold (default: 65 bytes, configurable via `-Zannotate-moves=SIZE`) - Has a non-scalar backend representation (scalars use registers, not memcpy) This has a very small size impact on object file size. With the default limit it's well under 0.1%, and even with a very small limit of 8 bytes it's still ~1.5%. This could be enabled by default.
1 parent 7d3a456 commit f7b6605

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1069,7 +1069,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
10691069
OperandValue::Ref(place.val)
10701070
};
10711071

1072-
OperandRef { val, layout: place.layout }
1072+
OperandRef { val, layout: place.layout, move_annotation: None }
10731073
}
10741074

10751075
fn write_operand_repeatedly(

src/debuginfo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use crate::context::CodegenCx;
1919
pub(super) const UNKNOWN_LINE_NUMBER: u32 = 0;
2020
pub(super) const UNKNOWN_COLUMN_NUMBER: u32 = 0;
2121

22-
impl<'a, 'gcc, 'tcx> DebugInfoBuilderMethods for Builder<'a, 'gcc, 'tcx> {
22+
impl<'a, 'gcc, 'tcx> DebugInfoBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
2323
// FIXME(eddyb) find a common convention for all of the debuginfo-related
2424
// names (choose between `dbg`, `debug`, `debuginfo`, `debug_info` etc.).
2525
fn dbg_var_addr(

0 commit comments

Comments
 (0)