rust/compiler/rustc_codegen_llvm/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 Fix device code generation, to account for an implicit dyn_ptr argument. 2025-11-06 03:34:38 -05:00
builder Fix device code generation, to account for an implicit dyn_ptr argument. 2025-11-06 03:34:38 -05:00
coverageinfo Add coverage scope for controlling paths in code coverage 2025-10-27 12:54:24 +01:00
debuginfo Add -Zannotate-moves for profiler visibility of move/copy operations 2025-11-06 15:39:45 -08:00
llvm Fix device code generation, to account for an implicit dyn_ptr argument. 2025-11-06 03:34:38 -05:00
abi.rs Add -Zannotate-moves for profiler visibility of move/copy operations 2025-11-06 15:39:45 -08:00
allocator.rs miri: use allocator_shim_contents codegen helper 2025-10-15 21:23:14 +02:00
asm.rs Allow vector-scalar (vs) registers in ppc inline assembly 2025-10-14 09:52:56 -05:00
attributes.rs Rollup merge of #147043 - ilovepi:default-sanitizers, r=petrochenkov 2025-11-06 14:07:16 +11:00
base.rs Consistently import llvm::Type and llvm::Value 2025-10-06 13:09:16 +11:00
builder.rs Add -Zannotate-moves for profiler visibility of move/copy operations 2025-11-06 15:39:45 -08:00
callee.rs rustc_target: introduce Arch 2025-11-04 21:27:22 -05:00
common.rs Fix ICE on offsetted ZST pointer 2025-10-15 20:06:46 -04:00
consts.rs rustc_target: introduce Arch 2025-11-04 21:27:22 -05:00
context.rs rustc_target: introduce Arch 2025-11-04 21:27:22 -05:00
declare.rs refactor: Remove LLVMRustInsertPrivateGlobal and define_private_global 2025-10-08 21:59:48 +02:00
errors.rs Use the object crate rather than LLVM for extracting bitcode sections 2025-07-25 11:21:28 +00:00
intrinsic.rs Add alignment parameter to simd_masked_{load,store} 2025-11-04 02:30:59 +05:30
lib.rs Auto merge of #148544 - matthiaskrgr:rollup-n9dqgwc, r=matthiaskrgr 2025-11-05 21:07:24 +00:00
llvm_util.rs Auto merge of #148516 - bjorn3:target_feature_parsing_improvements, r=WaffleLapkin 2025-11-05 17:56:16 +00:00
macros.rs use declarative macro for #[derive(TryFromU32)] 2025-10-06 14:54:38 +00:00
mono_item.rs rustc_target: introduce Arch 2025-11-04 21:27:22 -05:00
type_.rs Fix device code generation, to account for an implicit dyn_ptr argument. 2025-11-06 03:34:38 -05:00
type_of.rs Consistently import llvm::Type and llvm::Value 2025-10-06 13:09:16 +11:00
typetree.rs autodiff: typetree recursive depth query from enzyme with fallback 2025-09-19 05:42:27 +00:00
va_arg.rs rustc_target: introduce Arch 2025-11-04 21:27:22 -05:00
value.rs Consistently import llvm::Type and llvm::Value 2025-10-06 13:09:16 +11:00