WASM version of LLVM itself (original) (raw)

So, LLVM can be used to create WASM versions of C++ libraries. LLVM is itself a C++ library. Could LLVM be used to create a WASM version of itself?

I ask because in our own project, we use LLVM to create machine code versions of computationally expensive models. It would be nice to be able to have a WASM version of that library, which created WASM versions of computationally expensive models, which it could then run. So I wouldn’t need the WASM version of LLVM to generate anything other than WASM itself.

Is this at all reasonable?

You can cross-compile LLVM to wasm for several of the runtime targets; I have two examples

There is also clang/build.sh at main · YoWASP/clang · GitHub by @whitequark (see [RFC] Building LLVM for WebAssembly).

lpsmith May 22, 2025, 4:54pm 3

Oh, that’s excellent. Thank you!

agarny May 22, 2025, 10:11pm 4

Hi Lucian,

To create a WASM version of LLVM+Clang is definitely possible, but… 2 years ago, I wasn’t able to make use of the WASM because I couldn’t look up symbols (see here). Also, apparently, even if we could look up symbols, to execute the code wouldn’t be easy, if not impossible (see here). (That’s why, in the end, we had to create an interpreter so that we could run our models from WASM.)

Now, maybe things have changed in the past 2 years…?

Alan