[LLVMdev] JVM Backend
David Roberts
d at vidr.cc
Mon Nov 23 21:51:10 PST 2009
Hi,
I've written a backend for LLVM that allows LLVM IR to be transformed
to a Java/JVM class file (llvm-jvm.patch.gz attached).
Indirect function calls don't work yet, and there's probably some
minor bugs in it, but it works well for the test cases that I've run
through it. Also, several instructions are emulated by method calls
due to deficiencies in the JVM instruction set (e.g. lack of unsigned
arithmetic), so performance could also be improved in this area
(although the JVM should inline the calls when it feels it necessary).
In order to link and run the output, the LLJVM[1] runtime is required,
which is essentially a compatibility layer allowing things such as
pointers to be used (emulated) within the JVM. Jasmin[2] is also
required to assemble the output code.
In order to transform LLVM IR to a class file and run it, the
following process is required:
llc -march=jvm foo.bc -o foo.j
# link references to external functions/variables with
# a basic I/O class and the Java math library
java -jar path/to/lljvm.jar ld BasicIO java.lang.Math < foo.j > foo.linked.j
mv -f foo.linked.j foo.j
# assemble
java -jar path/to/jasmin.jar foo.j
# run
java -classpath path/to/lljvm.jar:. foo
At the moment only very basic I/O is available (attached
BasicIO.{java,class}) due to the lack of the C Standard Library.
Before I go reinventing the wheel, has anyone had any luck with
compiling a libc implementation (e.g. newlib) to LLVM IR (without any
platform-dependent inline assembly, etc)?
What is the process for requesting this patch be applied to the LLVM
source tree?
[1] Homepage: http://da.vidr.cc/projects/lljvm/
Download: http://lljvm.googlecode.com/files/lljvm-0.1.jar
[2] http://jasmin.sf.net/
--
David Roberts
http://da.vidr.cc/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: llvm-jvm.patch.gz
Type: application/x-gzip
Size: 13136 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20091124/74d9cc00/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: BasicIO.class
Type: application/octet-stream
Size: 1040 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20091124/74d9cc00/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: BasicIO.java
Type: text/x-java
Size: 1036 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20091124/74d9cc00/attachment.java>
More information about the llvm-dev
mailing list