Speakers | |
---|---|
David Chisnall | |
Schedule | |
Day | Sunday |
Room | Janson |
Capacity | 1400 |
Start time | 14:00 |
End time | 14:50 |
Duration | 00:50 |
Info | |
Track | Development Track |
Attachments | |
Implementing DSLs with LLVM Slides (slides) | |
Examples (other) |
Implementing Domain-Specific Languages with LLVM
Any sufficiently complex application eventually evolves its own scripting framework or domain-specific language. These can be simple things, like a graphical scripting language for connecting pre-existing building blocks together, a domain-specific language for performing image convolutions, or a general-purpose language like a Lisp or JavaScript dialect for writing extensions.
These are usually implemented as ad-hoc interpreters, which limits their utility things that are not performance critical. With LLVM, it is very easy to turn a quick-and-dirty interpreter into a high-speed JIT or static compiler. This talk will explain how to plug LLVM into your application and allow code in your scripting language to run (almost) as fast as compiled C.
LLVM is a set of libraries that can be assembled to build compilers and related tools. This talk will give a close look at some of the APIs, the core abstractions that they present, and how they are used.
LLVM is probably best known for the clang front end, which allows it to work as a drop-in replacement for gcc when compiling C-family languages. This use hides much of the power of LLVM. It is not a monolithic compiler, but a set of libraries that can be assembled to build a static compiler, a JIT compiler, or a variety of other things.
Most complex applications include some kind of scripting capability. These come in a variety of forms. Some include simple macro languages that allow the user to automate repetitive tasks. Some, such as EMACS and Firefox, include such powerful scripting environments that a significant fraction of the application ends up being written using them, making scripting performance very important. Graphical applications may embed a domain-specific language for things like image convolutions, which would benefit from being compiled down to SIMD instructions for the user's CPU.
Embedding LLVM in other applications is a relatively easy way of providing any of these. It is relatively easy to adapt an existing interpreter to use LLVM as a JIT compiler, or to write a new language front end and leave all of the code generation to LLVM. If you write a JIT compiler that uses LLVM, then it is trivial to extend it to provide static compilation, so anything written in your scripting language and embedded in the application can be compiled to native code ahead of time and linked into the binary, just like C code.
This talk will give a quick overview of the semantics of the LLVM intermediate representation and cover the main classes that a front end would need to use to generate it. It will draw on the experience from writing Étoilé's Smalltalk implementation, which uses the same underlying object model as Objective-C, to provide suggestions for closely integrating scripted and native code, as well as mechanisms for adding profile-driven optimisations that are specific to a given language.
Links:
Concurrent events:
Next (up to 3) talks in the same room (Janson):
When | Event | Track |
---|---|---|
15:00-15:50 | The Apache Cassandra storage engine | Development |
16:00-16:50 | From Dev to DevOps | Development |
17:00-17:50 | Freedom, Out of the Box! | Keynotes |