rust/compiler/rustc_codegen_ssa/src
bors bbb6f68e28 Auto merge of #147803 - jsgf:move-copy-codegen, r=madsmtm,saethlin
Add -Zannotate-moves for profiler visibility of move/copy operations (codegen)

**Note:** this is an alternative implementation of https://github.com/rust-lang/rust/pull/147206; rather than being a MIR transform, it adds the annotations closer to codegen. It's functionally the same but the implementation is lower impact and it could be more correct.

---

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:
   - We're generating debug info and the feature is enabled.
   - Meets the size threshold (default: 65 bytes, configurable via `-Zannotate-moves=SIZE`), and is non-zero
   - Has a memory representation

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-08 07:57:14 +00:00
..
back Rollup merge of #145768 - ZuseZ4:offload-device, r=oli-obk 2025-11-07 00:21:17 -05:00
debuginfo Flatten ifs in rustc_codegen_ssa 2025-03-17 18:56:52 +00:00
mir Add -Zannotate-moves for profiler visibility of move/copy operations 2025-11-06 15:39:45 -08:00
traits Add -Zannotate-moves for profiler visibility of move/copy operations 2025-11-06 15:39:45 -08:00
assert_module_sources.rs Print CGU reuse statistics when -Zprint-mono-items is enabled 2025-08-04 15:43:50 +02:00
base.rs rustc_target: allow unenumerated architectures 2025-11-04 21:28:28 -05:00
codegen_attrs.rs Use span from parsed attribute 2025-10-14 16:17:36 +02:00
common.rs Move NativeLibKind from rustc_session to rustc_hir 2025-08-27 20:24:59 +02:00
errors.rs Fix double error for #[no_mangle] on closures 2025-10-08 17:46:33 +02:00
lib.rs Unify the configuration of the compiler docs 2025-11-05 11:25:27 +00:00
meth.rs Remove DynKind 2025-09-17 04:46:46 +02:00
mono_item.rs Port the #[linkage] attribute to the new attribute system 2025-08-13 21:01:37 +02:00
size_of_val.rs remove explicit deref of AbiAlign for most methods 2025-09-28 15:02:14 -07:00
target_features.rs Auto merge of #148516 - bjorn3:target_feature_parsing_improvements, r=WaffleLapkin 2025-11-05 17:56:16 +00:00