cargo-llvm-lines

github crates.io build status

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

Installation

Install with cargo install cargo-llvm-lines.

Output

One line per function with three columns of output:

  1. Total number of lines of LLVM IR generated across all instantiations of the function (and the percentage of the total).
  2. Number of instantiations of the function (and the percentage of the total). For a generic function, roughly the number of distinct combinations of generic type parameters it is called with.
  3. Name of the function.

``` $ cargo llvm-lines | head -20

Lines Copies Function name ----- ------ ------------- 30737 (100%) 1107 (100%) (TOTAL) 1395 (4.5%) 83 (7.5%) core::ptr::dropinplace 760 (2.5%) 2 (0.2%) alloc::slice::mergesort 734 (2.4%) 2 (0.2%) alloc::rawvec::RawVec::reserveinternal 666 (2.2%) 1 (0.1%) cargollvmlines::countlines 490 (1.6%) 1 (0.1%) ::pipeto 476 (1.5%) 6 (0.5%) core::result::Result::map 440 (1.4%) 1 (0.1%) cargollvmlines::readllvmir 422 (1.4%) 2 (0.2%) alloc::slice::merge 399 (1.3%) 4 (0.4%) alloc::vec::Vec::extenddesugared 388 (1.3%) 2 (0.2%) alloc::slice::inserthead 366 (1.2%) 5 (0.5%) core::option::Option::map 304 (1.0%) 6 (0.5%) alloc::alloc::boxfree 296 (1.0%) 4 (0.4%) core::result::Result::maperr 295 (1.0%) 1 (0.1%) cargollvmlines::wrapargs 291 (0.9%) 1 (0.1%) core::char::methods::::encodeutf8 286 (0.9%) 1 (0.1%) cargollvmlines::runcargorustc 284 (0.9%) 4 (0.4%) core::option::Option::okor_else ```


License

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.