How are LLVM-IR passes done in Rust?

Hello,

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:

1 Like

Oh, ok so it does use Rust binding for LLVM IR C++ API? For example, if I want to try and implement a custom pass I can't reuse that piece separately?

You would need to modify that part of the compiler to implement your own pass. Probably somewhere near this function.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.