Originally posted by madscientist159
View Post
LLVM-IR allows inline assembly, which by definition is not portable. Also many languages that can target LLVM-IR, ie. C, C++, Rust, etc. themselves allow conditional code compilation depending on the target (#ifdefs in C-likes, #[cfg()] in Rust), etc., and also inline assembly.
LLVM-IR code is typically optimization-friendly representation of the program, but already in a target-specific, non-portable form (depending on hardware architecture + operating system), in general you cannot recompile it to another target, you need the original source code (and… the original source code also might have target-dependent parts that first need to be ported), so it’s not that easy.
Apple AFAIK uses fat binaries – binaries containing native code for all supported architectures. I believe that’s also what MS is doing with their UWP (although I am not sure). Android with Dalvik is something like what you describe, it has a platform-independent code that gets compiled to native during installation, and new architectures might be added without breaking any existing apps.
JVM bytecode or WebAssembly would be better for target-agnostic applications than LLVM-IR. But JVM bytecode won’t happen here, because Oracle (although Google with Android+Dalvik does exactly this, they have money for legal battles with Oracle) and because of the garbage collector cost of JVM bytecode (again, Google decided to pay that cost, but then again, they also allow native libraries, incompatible with platforms they were not compiled for). WebAssembly is an open standard and does not impose a GC overhead, but it will take a lot of time until we get good, production-proven, optimizing compilers for WebAssembly.
But I can imagine a future in which the regular scenario for a desktop program is that C++ or Rust is first compiled to WebAssembly using a LLVM-based compiler and that gets uploaded to repo (eg. distribution’s repo, or Steam), then on the user’s or repo’s server side it is again compiled, again using LLVM-based compiler, to target native code.
Comment