Hacker News new | ask | show | jobs
by dmitriid 2377 days ago
Besides, doesn't LLVM already have an IR which servers as one such higher-level abstraction?
4 comments

LLVM IR is unstable, way too big in scope, and not as machine-independent as people think. There have been several efforts to use it as a target-independent high-level bytecode, and they either are very platform-specific single-vendor affairs (Apple) or were retired in favour of a simpler new language that doesn't have its problems (SPIR became SPIR-V, PNaCl became WebAssembly).
No, LLVM IR is machine specific. Any "native" language is since the ABI of a struct will depend e.g. on the size of pointers for that platform.

E.g. Consider in C int foo[sizeof(void*)];

Open source LLVM IR is machine specific, it doesn't have to be, as proven by watchOS bitcode, or PNaCL.
Both of the examples you gave were very carefully architected to make sure that was the case.
Which doesn't prevent the case of someone contributing back such kind of variants.
> it doesn't have to be, as proven by watchOS bitcode, or PNaCL.

Both of those have fixed 32-bit pointer sizes and are little-endian. When you compile for watchOS bitcode or PNaCL you just target a single virtual machine & "system" ABI. LLVM IR or any related techniques won't ever allow you to produce a 32 / 64 bit or ARM / x86 app that is able to leverage the whole feature set of the platform from the same bitcode.

Yet watchOS migrated from 32 bit to 64 bit.

It is possible, LLVM project just needs to actually want to support such use cases in a portable way.

> Yet watchOS migrated from 32 bit to 64 bit.

that is what they said in the press release but in practice they migrated from "classical" 32bit ARM to ILP-32 (akin to the x32 ABI on linux) so the size of pointers, etc etc does not change from 32-bit. You get more registers & stuff like that which is nice, but that is not moving to 64 bit, just having nicer 32 bit execution on 64 bit CPUs. If you want proper aarch64 support on WatchOS you have to recompile.

Fair enough. Still nothing prevents LLVM bitcode to be fully CPU agnostic, if LLVM guys were willing to keep such variant around.
Google created pretty much this, called it PNaCl and shipped it in Chrome. It now has been retired in favor of WASM.
Because Mozilla went political and came up with asm.js as counter technology.
Or as some other (like, eg Google itself) would say:

> Because Mozilla went political and came up with asm.js as better technology.

I am pretty sure that asm.js would not happened if Chrome already had the market share it enjoys nowadays.

WASM is still catching up to PNaCL in performance, hardly better.

I'm pretty sure it is not stable and not designed for such a use case.
Apple kind of disagrees with watchOS bitcode.
"not designed for that use case" != "isn't used for that use case in practice"

Apple has tight control over the bitcode version and the target platforms supported by Xcode. That's not the same thing as accepting arbitrary LLVM bitcode files.

Nothing prevents LLVM project to adopt such variant, other than unwillingness to do so.