Commit b4962cd
committed
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.
A new `AnnotateMoves` MIR transform pass runs after MIR optimization
and modifies source scopes for statements containing `Operand::Move`
and `Operand::Copy` to make them appear as if inlined from profiling
marker functions in `core::profiling`.
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.
The transform creates synthetic `SourceScopeData` with the `inlined`
field set to point to the appropriate profiling marker, leveraging the
existing inlining infrastructure.
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)
An early issue was that modifying a statement's SourceInfo to add the
`compiler_move` scope affected the entire statement, including function calls
when the move was a call argument. This made profilers attribute the whole
function call to the move operation, greatly exaggerating its cost.
The solution stores argument move/copy SourceInfo separately in
`Body::call_arg_move_source_info`. During codegen, this SourceInfo is applied
only during argument preparation, then reset to the call site location before
emitting the call instruction itself. This ensures profilers see the argument
copy attributed to `compiler_move` while the function call retains its proper
source attribution.1 parent 4082d6a commit b4962cd
File tree
40 files changed
+1586
-7
lines changed- compiler
- rustc_codegen_ssa/src/mir
- rustc_middle/src/mir
- rustc_mir_build/src/builder/custom
- rustc_mir_transform/src
- rustc_session/src
- rustc_span/src
- library/core/src
- src/doc/unstable-book/src/compiler-flags
- tests
- codegen-llvm/annotate-moves
- mir-opt/annotate-moves
- ui/annotate-moves
40 files changed
+1586
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1151 | 1151 | | |
1152 | 1152 | | |
1153 | 1153 | | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
1154 | 1164 | | |
1155 | 1165 | | |
1156 | 1166 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
331 | 331 | | |
332 | 332 | | |
333 | 333 | | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
334 | 341 | | |
335 | 342 | | |
336 | 343 | | |
| |||
374 | 381 | | |
375 | 382 | | |
376 | 383 | | |
| 384 | + | |
377 | 385 | | |
378 | 386 | | |
379 | 387 | | |
| |||
405 | 413 | | |
406 | 414 | | |
407 | 415 | | |
| 416 | + | |
408 | 417 | | |
409 | 418 | | |
410 | 419 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
| 65 | + | |
65 | 66 | | |
66 | 67 | | |
67 | 68 | | |
| |||
0 commit comments