I recently got introduced to the LLVM-IR and implemented a couple of sanitizers myself using its C++ API. I know that Rust's compiler is built using LLVM infrastructure and it does several passes as well. My question is: as LLVM IR doesn't have Rust API how does the Rust compiler handles optimizations, and does Passes? Does it use C++ code to do that or there is a Rust binding for it? Crates I found for binding are somewhat personal projects?! I don't think Rust's compiler is built using those crates.
Or Rust doesn't use LLVM IR and it does something else to optimize code and do sanitization etc.?
rustc has its own internal Rust binding for LLVM. It is not published as a crate and while it is (necessarily) battle tested, it probably is not reusable at all outside rustc. Here it is: