I am playing with Mono LLVM (http://www.mono-project.com/Mono:Runtime:Documentation:LLVM) and it seems like they are using LLVM here as a JIT, not really as a code generator. But according to the docs, they go through LLVM-IR before generating native code :
So, I am wondering if there any way to catch this 3rd phase and use the IR to feed my LLVM backend. That would allow me to get C# to LLVM-IR front end for free.
Thanks for any help!
LLVM IR is a low-level intermediate representation used by the LLVM compiler framework. You can think of LLVM IR as a platform-independent assembly language with an infinite number of function local registers.
Mono has an option to use LLVM for JIT compilation.
The rules are intended as a balance between convenience for llvm users and not imposing a big burden on llvm developers: The textual format is not backwards compatible.
LLVM is designed around a language-independent intermediate representation (IR) that serves as a portable, high-level assembly language that can be optimized with a variety of transformations over multiple passes.
Mono's LLVM support works by attempting to load libmono-llvm.so
from the appropriate $libdir
, e.g. on OSX /usr/bin/mono
will load /Library/Frameworks/Mono.framework/Libraries/libmono-llvm.dylib
. See the LLVM loading code in mono/mini/mini-llvm.h, specifically mono_llvm_load() and try_llvm_load().
So it looks like if you name your LLVM backend mono-llvm
, it will be used when you launch mono as mono --llvm
. That said, mono_llvm_load()
appears to require particular exports from the mono-llvm
library, such as mono_llvm_init
and mono_llvm_cleanup
, so I'm sure that some additional work will be needed to your LLVM backend in order to allow Mono to use it, and I'm not sure where to find this out (other than grep
ping for "LLVM" in Mono's sources...).
This also means that the LLVM backend may not be reusable from a prebuilt mono; that is, you may need to build your own mono in order to use your LLVM backend, as a prebuild mono will be providing a mono-llvm
backend that may not be pluggable. (I have no idea how pluggable or not pluggable the LLVM backend is.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With