For this semesters ‘Program Analysis and Transformation’ seminar I took a look on how you could potentially run Scala on the LLVM. I created an overview the motivation, implementation possibilities and challenges. The full paper is here. This blog post is an short overview that paper.
Scala on LLVM
There are three implementation strategies. The first one it to compile Scala with the LLVM tool chain and use it directly. That’s the approach of this project here. Another approach is to implement a JVM on top of LLVM, like in the VMKit project. The third possibility is combine different approaches. For example compile parts of a Scala application with the LLVM tool chain while other parts are compiled to Java byte code. This is mixed approach is interesting to run Scala on specialized Hardware.
Scala usually runs on the JVM, which provides much higher level services than LLVM. Therefore when you want to create a 100% Scala implementation you have a lot of stuff to consider. Like garbage collection, threading, the Java memory model, reflection, debugging, dynamic class loading and support for existing Java libraries. Of course you can omit some features if they are not needed for a certain environment.
Finally the interesting subsets can be the motivation for porting Scala to LLVM.
One possibility would be to bring Scala to embedded, small systems. Instead of requiring a JVM we could compile Scala down to native code. Of course for such a system it makes sense to remove certain features to keep the implementation small. Stuff like dynamic class loading it probably not needed.
Scala in Flavors
One motivation to port Scala could be to create Scala in ‘flavors’. For example that we can parts of a Scala program on specialized hardware, like a GPU. The idea is to isolate certain parts of program, then compile it with the LLVM tool chain for the specialized hardware. The rest is executed normally on a JVM. While the basic idea is simple, in practice it is hard. Nevertheless its a very interesting idea.
The last thing is to create a full blown, compiled Scala version. However I doubt that it is worth the effort. And you basically can by this already here =).
Again, here’s the full paper with a lot more details. Here are the slides of the presentation. And there is more stuff from the seminar from other people: LLVM Based Bug Detection, Architecture of Clang, Template Instantiation and Concepts in CLANG, LLVM to PTX Backend.
- Secret Agent Miss Oh
- Mixtape Locations