Closed sanjaybharadwaj closed 7 years ago
Thank you :-) I do hope that we eventually get around to completing the document. I don't currently use LLVM much, but I plan to do so sometime in the future, at which point the document might come to life again.
LLVM IR is mostly suited for being generated by tools such as compilers. I've tried writing LLVM IR by hand a number of times and it quickly gets painful. Furthermore, you cannot make "portable" LLVM IR programs because it has no notion of "word size"; you have to specify the platform's word size using one of the built-in types (i32 or i64).
I am hoping that Michael Rodler, the new primary maintainer of this document, will add some or many of the missing things in the document, but perhaps I'll contribute a bit here and there.
Please feel free to submit issues and ideas for this project. The more people that inspire us to work, the better it will eventually become :-)
Cheers, Mikael Egevig (original author of the document, albeit under another name)
Thank you for the reply. You said that you tried writing directly in IR, do you have some code? or some material that you tried?
I tried to write program in C++ ( with an external function), generated the IR. The definition of the external function was written in Rust and then I generated the IR from this as well.
I manually tried to merge these generated IR codes (using llvm-link tool) and created a merged code. I compiled this IR and generated the application. This executable works somehow :D
If you tried something like this, please let me know.
Thank you and Best regards, Sanjay
Writing directly in IR is tedious and is generally something you do not want to do (mostly because of the SSA form and also because of the mentioned missing notion of word-sized integer types).
Mixing different programming languages such as C++ and Rust, which both compile down to LLVM IR is working only as long as you use the most primitive object types. As soon as you start considering complex objects and try to manage the lifetime of objects, you are definitely gonna get into very ugly situations. I wouldn't do this and this is not what LLVM IR is intended for. This should be done on a source language level. If you want to mix C++ and Rust, both are able to expose a C-style ABI for functions. extern "C" {}
blocks in C++ and #[no_mangle]
in rust. So you can compile both and with the help of FFI you can convert to the right datatypes. There are a couple of resources around on how to achieve that.
That said you could use LLVM to perform some kind of cross-language link-time optimization, but I'm not sure if that would go well ;)
The document is definitely gonna grow as soon as I have a little bit more time on my hand. I'm open for any pull request ;)
Hi Forki,
This is one of the interesting document that I found online. Since all the front ends developed using LLVM will almost generate similar code (except for language specific elements like std libraries), I can actually write the whole program in IR independent of programming language. Is my understanding right?
Also is there a plan to create such a mapping for different programming languages? The interesting application of such an analysis will be to develop a language independent compilation platform & Merging of code from different programming languages.
Thank you and Best Regards,