Skip to content

Commit 136cb4a

Browse files
committed
More review updates
1 parent 19dddf6 commit 136cb4a

File tree

5 files changed

+95
-48
lines changed

5 files changed

+95
-48
lines changed

compiler/rustc_codegen_ssa/src/mir/operand.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,9 @@ impl<'a, 'tcx, V: CodegenObject> OperandRefBuilder<'tcx, V> {
853853
}
854854
}
855855

856-
/// Default size limit for move/copy annotations (in bytes).
856+
/// Default size limit for move/copy annotations (in bytes). 64 bytes is a common size of a cache
857+
/// line, and the assumption is that anything this size or below is very cheap to move/copy, so only
858+
/// annotate copies larger than this.
857859
const MOVE_ANNOTATION_DEFAULT_LIMIT: u64 = 65;
858860

859861
impl<'a, 'tcx, V: CodegenObject> OperandValue<V> {

library/core/src/profiling.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
/// the compiler creates synthetic debug info that makes move operations appear as
77
/// calls to this function in profilers.
88
///
9-
/// The `SIZE` parameter encodes the size of the type being moved.
9+
/// The `SIZE` parameter encodes the size of the type being copied. It's the same as
10+
/// `size_of::<T>()`, and is only present for convenience.
1011
#[unstable(feature = "profiling_marker_api", issue = "none")]
1112
#[lang = "compiler_move"]
1213
pub fn compiler_move<T, const SIZE: usize>(_src: *const T, _dst: *mut T) {
1314
unreachable!(
14-
"compiler_move marks where the compiler generated a copy; it is never actually called"
15+
"compiler_move marks where the compiler-generated a memcpy for moves. It is never actually called."
1516
)
1617
}
1718

@@ -21,11 +22,12 @@ pub fn compiler_move<T, const SIZE: usize>(_src: *const T, _dst: *mut T) {
2122
/// the compiler creates synthetic debug info that makes copy operations appear as
2223
/// calls to this function in profilers.
2324
///
24-
/// The `SIZE` parameter encodes the size of the type being copied.
25+
/// The `SIZE` parameter encodes the size of the type being copied. It's the same as
26+
/// `size_of::<T>()`, and is only present for convenience.
2527
#[unstable(feature = "profiling_marker_api", issue = "none")]
2628
#[lang = "compiler_copy"]
2729
pub fn compiler_copy<T, const SIZE: usize>(_src: *const T, _dst: *mut T) {
2830
unreachable!(
29-
"compiler_copy marks where the compiler generated a copy; it is never actually called"
31+
"compiler_copy marks where the compiler-generated a memcpy for Copies. It is never actually called."
3032
)
3133
}

src/doc/unstable-book/src/compiler-flags/annotate-moves.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# `annotate-moves`
22

3+
The tracking issue for this feature is: [#148197](https://github.com/rust-lang/rust/issues/148197).
4+
5+
------------------------
6+
7+
38
The `-Z annotate-moves` flag enables annotation of compiler-generated
49
move and copy operations, making them visible in profilers and stack traces
510
for performance debugging.

tests/codegen-llvm/annotate-moves/integration.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub fn test_pure_assignment_move() {
4949
pub fn test_pure_assignment_copy() {
5050
let s = ExplicitCopy { data: [42; 20] };
5151
// Arrays are initialized with a loop
52-
// CHECK-NOT: call void @llvm.memcpy{{.*}}, !dbg ![[#ASSIGN_COPY_LOC:]]
52+
// CHECK-NOT: call void @llvm.memcpy{{.*}}, !dbg ![[#]]
5353
let _copied = s;
5454
// CHECK: call void @llvm.memcpy{{.*}}, !dbg ![[#ASSIGN_COPY2_LOC:]]
5555
let _copied_2 = s;

tests/codegen-llvm/annotate-moves/size-limit.rs

Lines changed: 80 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,73 +2,111 @@
22
// Test that custom size limits work correctly
33
#![crate_type = "lib"]
44

5-
struct MediumStruct {
6-
data: [u64; 10], // 80 bytes - below custom 100-byte threshold
5+
struct Struct99 {
6+
data: [u8; 99], // just below custom 100-byte threshold
77
}
88

9-
const _: () = { assert!(std::mem::size_of::<MediumStruct>() == 80) };
9+
const _: () = { assert!(size_of::<Struct99>() == 99) };
1010

11-
impl Clone for MediumStruct {
12-
// CHECK-LABEL: <size_limit::MediumStruct as core::clone::Clone>::clone
11+
impl Clone for Struct99 {
12+
// CHECK-LABEL: <size_limit::Struct99 as core::clone::Clone>::clone
1313
fn clone(&self) -> Self {
1414
// Should NOT be annotated since 80 < 100
15-
// CHECK: call void @llvm.memcpy{{.*}}, !dbg ![[#MEDIUM_COPY_LOC:]]
16-
MediumStruct { data: self.data }
15+
// CHECK: call void @llvm.memcpy{{.*}}, !dbg ![[#SZ99_COPY_LOC:]]
16+
Struct99 { data: self.data }
1717
}
1818
}
1919

20-
struct LargeStruct {
21-
data: [u64; 20], // 160 bytes - above custom 100-byte threshold
20+
// CHECK-LABEL: size_limit::test_99_copy
21+
pub fn test_99_copy() {
22+
let sz99 = Struct99 { data: [42; 99] };
23+
let _copy = sz99.clone();
2224
}
2325

24-
const _: () = { assert!(std::mem::size_of::<LargeStruct>() == 160) };
26+
// CHECK-LABEL: size_limit::test_99_move
27+
pub fn test_99_move() {
28+
let sz99 = Struct99 { data: [42; 99] };
29+
// Should NOT be annotated
30+
// CHECK-NOT: compiler_move
31+
let _moved = sz99;
32+
}
33+
34+
struct Struct100 {
35+
data: [u8; 100], // 160 bytes - above custom 100-byte threshold
36+
}
2537

26-
impl Clone for LargeStruct {
27-
// CHECK-LABEL: <size_limit::LargeStruct as core::clone::Clone>::clone
38+
const _: () = { assert!(size_of::<Struct100>() == 100) };
39+
40+
impl Clone for Struct100 {
41+
// CHECK-LABEL: <size_limit::Struct100 as core::clone::Clone>::clone
2842
fn clone(&self) -> Self {
29-
// CHECK: call void @llvm.memcpy{{.*}}, !dbg ![[#LARGE_COPY_LOC:]]
30-
// CHECK: call void @llvm.memcpy{{.*}}, !dbg ![[#LARGE_RETURN_LOC:]]
31-
LargeStruct { data: self.data }
43+
// CHECK: call void @llvm.memcpy{{.*}}, !dbg ![[#SZ100_COPY_LOC:]]
44+
// CHECK: call void @llvm.memcpy{{.*}}, !dbg ![[#SZ100_RETURN_LOC:]]
45+
Struct100 { data: self.data }
3246
}
3347
}
3448

35-
// CHECK-LABEL: size_limit::test_medium_copy
36-
pub fn test_medium_copy() {
37-
let medium = MediumStruct { data: [42; 10] };
38-
let _copy = medium.clone();
49+
// CHECK-LABEL: size_limit::test_100_copy
50+
pub fn test_100_copy() {
51+
let sz100 = Struct100 { data: [42; 100] };
52+
let _copy = sz100.clone();
3953
}
4054

41-
// CHECK-LABEL: size_limit::test_large_copy
42-
pub fn test_large_copy() {
43-
let large = LargeStruct { data: [42; 20] };
44-
let _copy = large.clone();
55+
// CHECK-LABEL: size_limit::test_100_move
56+
pub fn test_100_move() {
57+
let sz100 = Struct100 { data: [42; 100] };
58+
// CHECK: call void @llvm.memcpy{{.*}}, !dbg ![[#SZ100_MOVE_LOC:]]
59+
let _moved = sz100;
4560
}
4661

47-
// CHECK-LABEL: size_limit::test_medium_move
48-
pub fn test_medium_move() {
49-
let medium = MediumStruct { data: [42; 10] };
50-
// Should NOT be annotated
51-
// CHECK-NOT: compiler_move
52-
let _moved = medium;
62+
struct Struct101 {
63+
data: [u8; 101], // 160 bytes - above custom 101-byte threshold
5364
}
5465

55-
// CHECK-LABEL: size_limit::test_large_move
56-
pub fn test_large_move() {
57-
let large = LargeStruct { data: [42; 20] };
58-
// CHECK: call void @llvm.memcpy{{.*}}, !dbg ![[#LARGE_MOVE_LOC:]]
59-
let _moved = large;
66+
const _: () = { assert!(size_of::<Struct101>() == 101) };
67+
68+
impl Clone for Struct101 {
69+
// CHECK-LABEL: <size_limit::Struct101 as core::clone::Clone>::clone
70+
fn clone(&self) -> Self {
71+
// CHECK: call void @llvm.memcpy{{.*}}, !dbg ![[#SZ101_COPY_LOC:]]
72+
// CHECK: call void @llvm.memcpy{{.*}}, !dbg ![[#SZ101_RETURN_LOC:]]
73+
Struct101 { data: self.data }
74+
}
75+
}
76+
77+
// CHECK-LABEL: size_limit::test_101_copy
78+
pub fn test_101_copy() {
79+
let sz101 = Struct101 { data: [42; 101] };
80+
let _copy = sz101.clone();
81+
}
82+
83+
// CHECK-LABEL: size_limit::test_101_move
84+
pub fn test_101_move() {
85+
let sz101 = Struct101 { data: [42; 101] };
86+
// CHECK: call void @llvm.memcpy{{.*}}, !dbg ![[#SZ101_MOVE_LOC:]]
87+
let _moved = sz101;
6088
}
6189

6290
// The scope for no-annotated is clone function itself
63-
// CHECK-DAG: ![[#MEDIUM_COPY_LOC]] = !DILocation({{.*}}scope: ![[#MEDIUM_COPY_SCOPE:]]
64-
// CHECK-DAG: ![[#MEDIUM_COPY_SCOPE]] = {{(distinct )?}}!DISubprogram(name: "clone",
91+
// CHECK-DAG: ![[#SZ99_COPY_LOC]] = !DILocation({{.*}}scope: ![[#SZ99_COPY_SCOPE:]]
92+
// CHECK-DAG: ![[#SZ99_COPY_SCOPE]] = {{(distinct )?}}!DISubprogram(name: "clone",
93+
94+
// Clone itself is copy, but return is move.
95+
// CHECK-DAG: ![[#SZ100_COPY_LOC]] = !DILocation({{.*}}scope: ![[#SZ100_COPY_SCOPE:]]
96+
// CHECK-DAG: ![[#SZ100_COPY_SCOPE]] = {{(distinct )?}}!DISubprogram(name: "compiler_copy<[u8; 100], 100>"
97+
// CHECK-DAG: ![[#SZ100_RETURN_LOC]] = !DILocation({{.*}}scope: ![[#SZ100_RETURN_SCOPE:]]
98+
// CHECK-DAG: ![[#SZ100_RETURN_SCOPE]] = {{(distinct )?}}!DISubprogram(name: "compiler_move<[u8; 100], 100>"
99+
100+
// Assignment is move
101+
// CHECK-DAG: ![[#SZ100_MOVE_LOC]] = !DILocation({{.*}}scope: ![[#SZ100_MOVE_SCOPE:]]
102+
// CHECK-DAG: ![[#SZ100_MOVE_SCOPE]] = {{(distinct )?}}!DISubprogram(name: "compiler_move<[u8; 100], 100>"
65103

66104
// Clone itself is copy, but return is move.
67-
// CHECK-DAG: ![[#LARGE_COPY_LOC]] = !DILocation({{.*}}scope: ![[#LARGE_COPY_SCOPE:]]
68-
// CHECK-DAG: ![[#LARGE_COPY_SCOPE]] = {{(distinct )?}}!DISubprogram(name: "compiler_copy<[u64; 20], 160>"
69-
// CHECK-DAG: ![[#LARGE_RETURN_LOC]] = !DILocation({{.*}}scope: ![[#LARGE_RETURN_SCOPE:]]
70-
// CHECK-DAG: ![[#LARGE_RETURN_SCOPE]] = {{(distinct )?}}!DISubprogram(name: "compiler_move<[u64; 20], 160>"
105+
// CHECK-DAG: ![[#SZ101_COPY_LOC]] = !DILocation({{.*}}scope: ![[#SZ101_COPY_SCOPE:]]
106+
// CHECK-DAG: ![[#SZ101_COPY_SCOPE]] = {{(distinct )?}}!DISubprogram(name: "compiler_copy<[u8; 101], 101>"
107+
// CHECK-DAG: ![[#SZ101_RETURN_LOC]] = !DILocation({{.*}}scope: ![[#SZ101_RETURN_SCOPE:]]
108+
// CHECK-DAG: ![[#SZ101_RETURN_SCOPE]] = {{(distinct )?}}!DISubprogram(name: "compiler_move<[u8; 101], 101>"
71109

72110
// Assignment is move
73-
// CHECK-DAG: ![[#LARGE_MOVE_LOC]] = !DILocation({{.*}}scope: ![[#LARGE_MOVE_SCOPE:]]
74-
// CHECK-DAG: ![[#LARGE_MOVE_SCOPE]] = {{(distinct )?}}!DISubprogram(name: "compiler_move<[u64; 20], 160>"
111+
// CHECK-DAG: ![[#SZ101_MOVE_LOC]] = !DILocation({{.*}}scope: ![[#SZ101_MOVE_SCOPE:]]
112+
// CHECK-DAG: ![[#SZ101_MOVE_SCOPE]] = {{(distinct )?}}!DISubprogram(name: "compiler_move<[u8; 101], 101>"

0 commit comments

Comments
 (0)