# Compiling Racket to LLVM

**URL:** <https://racket.discourse.group/t/compiling-racket-to-llvm/1336>\
**Category:** General\
**Tags:** llvm, implementations\
**Created:** [September 29, 2022, 6:11pm UTC](https://racket.discourse.group/t/compiling-racket-to-llvm/1336 "2022-09-29T18:11:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jbclements](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/jbclements/32/11_2.png) [@jbclements](https://racket.discourse.group/u/jbclements)\
**Post date:** [September 29, 2022, 6:11pm UTC](https://racket.discourse.group/t/compiling-racket-to-llvm/1336/1 "2022-09-29T18:11:37Z")

</div>

I found myself in a conversation today with Adam Perlin about compiling racket to LLVM, and I found myself wondering why there was no LLVM back-end for Racket[\*]. After thinking about it for a while, I decided that the most likely reason was that with the pb back-end, compiling to LLVM (and then to some other target) probably isn't much of a win, or maybe even a win at all. Does that sound reasonable, or am I missing something obvious?

Thanks!

John

[\*] Er... that I'm aware of?

---

<div class="post-metadata">

**Author:** ![samth](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/samth/32/3_2.png) [@samth](https://racket.discourse.group/u/samth)\
**Post date:** [September 29, 2022, 7:14pm UTC](https://racket.discourse.group/t/compiling-racket-to-llvm/1336/2 "2022-09-29T19:14:52Z")

</div>

1. I don't think pb and compiling to LLVM are that related. pb is a bytecode with an interpreter, LLVM does not run via a portable interpreter.
2. The reason not to compile via LLVM is that it's hard, particularly for a GC'ed language with a non-trivial VM. It's possible to make it work but definitely non-trivial.
3. There was an effort by Eli Barzilay and Alex Friedman to write an LLVM backend for Racket in 2006; you can read more about it here: [Racket: [plt-scheme] llvm and all that](https://lists.racket-lang.org/users/archive/2006-August/014366.html)

---

<div class="post-metadata">

**Author:** ![hendrikboom3](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/hendrikboom3/32/2748_2.png) [@hendrikboom3](https://racket.discourse.group/u/hendrikboom3)\
**Post date:** [September 29, 2022, 7:29pm UTC](https://racket.discourse.group/t/compiling-racket-to-llvm/1336/3 "2022-09-29T19:29:31Z")

</div>

When I looked at LLVM a few years ago, there were three things it did not understand:

- Garbage collection
- That sometimes you want to add an integer to a pointer and NOT HAVE IT SCALED!
- That it makes sense to access and use the fields of a structure before the definition of the structure is complete.

-- hendrik

---

<div class="post-metadata">

**Author:** ![countvajhula](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/countvajhula/32/65_2.png) [@countvajhula](https://racket.discourse.group/u/countvajhula)\
**Post date:** [September 30, 2022, 3:52pm UTC](https://racket.discourse.group/t/compiling-racket-to-llvm/1336/4 "2022-09-30T15:52:28Z")

</div>

This may be relevant: [[2005.09028] Sham: A DSL for Fast DSLs](https://arxiv.org/abs/2005.09028). Excerpt:

 ![Screen Shot 2022-09-30 at 8.48.32 AM](https://global.discourse-cdn.com/free1/uploads/racket/original/1X/a81e60812839fa531b134513b388844611253baf.png)
