I’m a newbie when it comes to compilers (and even close-to-machine coding), but recently started working on my own language and am using LLVM as the mid/backend. Currently I’m generating .ll files from a front-end written in Scala. The language is not really serious, just a way to learn more about compilers (and LLVM) and maybe serve as a base for further experiments. It’s somewhat based on Kaleidoscope, but with more Scala-like syntax.
I want to experiment with avoiding mutable state as far as I can. At the moment there are no mutable variables – only immutable value types (numerics, bool, vectors, tuples) and I’ve been doing everything in LLVM registers. The compiler doesn’t generate a single alloca, load or store at the moment.
I wonder if it was maybe a bad idea to do it this way? Because a lot of stuff in LLVM seem to be only available through pointers. e.g. extractvalue takes only constant indices, but GEP can take variables. Some things seem to be possible only by bitcasting pointers, e.g. splitting a Vector into equal-sized parts to partially compute the sum of it’s elements with SIMD instructions…
And there may of course be some penalty for passing large(-ish) structures by-value. I haven’t investigated at which sizes does that become worse than passing pointers.
Maybe a better alternative would be to allocate memory for every local value, and let the mem2reg pass optimize?
I hope these kind of questions are appropriate for this list.