Reputation: 745
I am trying to analyse the LLVM-IR emitted by the rustc
front end. The plan is to emit the IR for specific language elements. Is there such a list of elements and IR code template mapping or list?
The compiler is intelligent enough to remove the unused functions in the emitted IR as wel:, unless something is printed on to the console using println!
, the compiler removes every function used.
This doesn't work as well, having said that x
isn't used anywhere or also when x
is overwritten.
let x = function();
Is there some sort of qualifier in Rust so that emitted IR retains all the functions?
Upvotes: 4
Views: 1015
Reputation: 300429
Is there such a list of elements and IR code template mapping or list?
The rustc
code.
It might seem tongue in the cheek, but it's actually the only answer available.
Rust's ABI is not stable specifically because the Rust developers wish to retain the ability to change these kinds of things whenever a better performing way of doing them appears.
This applies to the in-memory representation of structures, to the calling conventions, etc...
Is there some sort of qualifier in Rust so that emitted IR retains all the functions?
The simplest way to retain a function is:
pub
It's also possible to use #[inline(never)]
but this is more fragile as a smart linker could realize the function is never called. Making the symbol available externally forces the linker's hand into retaining it.
Upvotes: 5