Count the number of lines of LLVM IR across all instantiations of a generic function. Based on a suggestion from @eddyb on how to count monomorphized functions in order to debug compiler memory usage, executable size and compile time.
\
unoptimized LLVM IR
\first used grep '^define' to get only the lines defining function bodies
\then regex replace in my editor to remove everything before @ and everything after (
\then sort | uniq -c
Install with cargo install cargo-llvm-lines
.
One line per function with three columns of output:
``` $ cargo llvm-lines | head -20
Lines Copies Function name
----- ------ -------------
52262 1872 (TOTAL)
1815 (3.5%, 3.5%) 1 (0.1%, 0.1%)
```
Interpreting the output in the presence of multiple crates and generics can be
tricky. cargo llvm-lines
only shows the contribution of the root crate;
dependencies are not included. To assess the contribution of an intermediate
crate, use the -p
flag:
console
$ cargo llvm-lines -p some-depenency
Note however, that Rust generics are monomorphised — a generic function will be accounted for in the crates that use it, rather than in the defining crate.
There is a trick to get a holistic view: enabling link time optimization causes all code generation to happen in the root crate. So you can use the following invocation to get a full picture:
console
$ CARGO_PROFILE_RELEASE_LTO=fat cargo llvm-lines --release
Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.