@@ -28,43 +28,57 @@ number of lines of LLVM IR across all instantiations of a generic function.
28
28
Since most of the time compiling rustc is spent in LLVM, the idea is that by
29
29
reducing the amount of code passed to LLVM, compiling rustc gets faster.
30
30
31
+ To use ` cargo-llvm-lines ` together with somewhat custom rustc build process, you can use
32
+ ` -C save-temps ` to obtain required LLVM IR. The option preserves temporary work products
33
+ created during compilation. Among those is LLVM IR that represents an input to the
34
+ optimization pipeline; ideal for our purposes. It is stored in files with ` *.no-opt.bc `
35
+ extension in LLVM bitcode format.
36
+
31
37
Example usage:
32
38
```
33
39
cargo install cargo-llvm-lines
34
40
# On a normal crate you could now run `cargo llvm-lines`, but x.py isn't normal :P
35
41
36
42
# Do a clean before every run, to not mix in the results from previous runs.
37
43
./x.py clean
38
- RUSTFLAGS="--emit=llvm-ir" ./x.py build --stage 0 compiler/rustc
39
-
40
- # Single crate, eg. rustc_middle
41
- cargo llvm-lines --files ./build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/debug/deps/rustc_middle-a539a639bdab6513.ll > llvm-lines-middle.txt
42
- # Specify all crates of the compiler. (Relies on the glob support of your shell.)
43
- cargo llvm-lines --files ./build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/debug/deps/*.ll > llvm-lines.txt
44
+ env RUSTFLAGS=-Csave-temps ./x.py build --stage 0 compiler/rustc
45
+
46
+ # Single crate, e.g., rustc_middle. (Relies on the glob support of your shell.)
47
+ # Convert unoptimized LLVM bitcode into a human readable LLVM assembly accepted by cargo-llvm-lines.
48
+ for f in build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/rustc_middle-*.no-opt.bc; do
49
+ ./build/x86_64-unknown-linux-gnu/llvm/bin/llvm-dis "$f"
50
+ done
51
+ cargo llvm-lines --files ./build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/rustc_middle-*.ll > llvm-lines-middle.txt
52
+
53
+ # Specify all crates of the compiler.
54
+ for f in build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/*.no-opt.bc; do
55
+ ./build/x86_64-unknown-linux-gnu/llvm/bin/llvm-dis "$f"
56
+ done
57
+ cargo llvm-lines --files ./build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/*.ll > llvm-lines.txt
44
58
```
45
59
46
- Example output:
60
+ Example output for the compiler :
47
61
```
48
- Lines Copies Function name
49
- ----- ------ -------------
50
- 11802479 (100%) 52848 (100%) (TOTAL)
51
- 1663902 (14.1 %) 400 (0.8 %) rustc_query_system::query::plumbing::get_query_impl::{{closure}}
52
- 683526 (5.8 %) 10579 (20.0 %) core::ptr::drop_in_place
53
- 568523 (4.8 %) 528 (1.0 %) rustc_query_system::query::plumbing::get_query_impl
54
- 472715 (4.0 %) 1134 (2.1 %) hashbrown::raw::RawTable <T>::reserve_rehash
55
- 306782 (2.6 %) 1320 (2.5 %) rustc_middle::ty::query::plumbing::<impl rustc_query_system::query::QueryContext for rustc_middle::ty::context::TyCtxt>::start_query::{{closure}}::{{closure}}::{{closure}}
56
- 212800 (1.8 %) 514 (1.0 %) rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
57
- 194813 (1.7 %) 124 (0.2 %) rustc_query_system::query::plumbing::force_query_impl
58
- 158488 (1.3 %) 1 (0.0 %) rustc_middle::ty::query::<impl rustc_middle::ty::context::TyCtxt >::alloc_self_profile_query_strings
59
- 119768 (1.0 %) 418 (0.8 %) core::ops::function::FnOnce::call_once
60
- 119644 (1.0 %) 1 (0.0 %) rustc_target::spec::load_specific
61
- 104153 (0.9 %) 7 (0.0 %) rustc_middle::ty::context::_DERIVE_rustc_serialize_Decodable_D_FOR_TypeckResults::<impl rustc_serialize::serialize::Decodable<__D> for rustc_middle::ty::context::TypeckResults>::decode::{{closure}}
62
- 81173 (0.7 %) 1 (0.0 %) rustc_middle::ty::query::stats::query_stats
63
- 80306 (0.7 %) 2029 (3.8 %) core::ops::function::FnOnce::call_once{{vtable.shim}}
64
- 78019 (0.7%) 1611 (3.0 %) stacker::grow::{{closure}}
65
- 69720 (0.6 %) 3286 (6 .2%) <&T as core::fmt::Debug >::fmt
66
- 56327 (0.5 %) 186 (0.4 %) rustc_query_system::query::plumbing::incremental_verify_ich
67
- 49714 (0.4 %) 14 (0.0%) rustc_mir::dataflow::framework::graphviz::BlockFormatter<A>::write_node_label
62
+ Lines Copies Function name
63
+ ----- ------ -------------
64
+ 45207720 (100%) 1583774 (100%) (TOTAL)
65
+ 2102350 (4.7 %) 146650 (9.3 %) core::ptr::drop_in_place
66
+ 615080 (1.4 %) 8392 (0.5 %) std::thread::local::LocalKey<T>::try_with
67
+ 594296 (1.3 %) 1780 (0.1 %) hashbrown::raw::RawTable<T>::rehash_in_place
68
+ 592071 (1.3 %) 9691 (0.6 %) core::option::Option <T>::map
69
+ 528172 (1.2 %) 5741 (0.4 %) core::alloc::layout::Layout::array
70
+ 466854 (1.0 %) 8863 (0.6 %) core::ptr::swap_nonoverlapping_one
71
+ 412736 (0.9 %) 1780 (0.1 %) hashbrown::raw::RawTable<T>::resize
72
+ 367776 (0.8 %) 2554 (0.2 %) alloc::raw_vec::RawVec<T,A >::grow_amortized
73
+ 367507 (0.8 %) 643 (0.0 %) rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
74
+ 355882 (0.8 %) 6332 (0.4 %) alloc::alloc::box_free
75
+ 354556 (0.8 %) 14213 (0.9 %) core::ptr::write
76
+ 354361 (0.8 %) 3590 (0.2 %) core::iter::traits::iterator::Iterator::fold
77
+ 347761 (0.8 %) 3873 (0.2 %) rustc_middle::ty::context::tls::set_tlv
78
+ 337534 (0.7%) 2377 (0.2 %) alloc::raw_vec::RawVec<T,A>::allocate_in
79
+ 331690 (0.7 %) 3192 (0 .2%) hashbrown::raw::RawTable<T >::find
80
+ 328756 (0.7 %) 3978 (0.3 %) rustc_middle::ty::context::tls::with_context_opt
81
+ 326903 (0.7 %) 642 (0.0%) rustc_query_system::query::plumbing::try_execute_query
68
82
```
69
83
70
84
Since this doesn't seem to work with incremental compilation or ` x.py check ` ,
0 commit comments