rust/compiler/rustc_interface/src
Jeremy Fitzhardinge 5f29f11a4d 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.
2025-11-06 15:39:45 -08:00
..
callbacks.rs Represent diagnostic side effects as dep nodes 2025-03-14 16:01:58 +01:00
errors.rs Move more early buffered lints to dyn lint diagnostics (4/N) 2025-09-14 12:38:12 +02:00
interface.rs Remove current code for embedding command-line args in PDB 2025-10-18 12:24:40 +11:00
lib.rs update cfg(bootstrap) 2025-05-12 15:33:37 +02:00
limits.rs fixup limit handling code 2025-09-08 15:07:12 -07:00
passes.rs Better warning message for crate type unsupported by codegen backend 2025-11-02 12:33:38 +00:00
proc_macro_decls.rs Move methods from Map to TyCtxt, part 4. 2025-03-12 08:55:37 +11:00
queries.rs Skip codegen_crate call in check mode 2025-10-24 10:25:13 +00:00
tests.rs Add -Zannotate-moves for profiler visibility of move/copy operations 2025-11-06 15:39:45 -08:00
util.rs Move warning reporting from flag_to_backend_features to cfg_target_feature 2025-11-05 10:48:29 +00:00