5 ms·
A few points: -LLVM at the IR level still has platform specific information - calling conventions, vector types, pointer widths, etc. -what was true then is s
by munin 13y ago
A few points:
-LLVM at the IR level still has platform specific information - calling conventions, vector types, pointer widths, etc.
-what was true then is still true now: http://lists.cs.uiuc.edu/pipermail/llvmdev/2011-October/043719.html http://lists.cs.uiuc.edu/pipermail/llvmdev/2011-October/0437...
-typed assembly languages have existed for a while, no one uses them
- majke 13y ago> platform specific stuff Yes. If I were to write IR for a real project, I'd probably keep a few pretty large functions to avoid overhead caused by calling conventions. Very interesting link. Thank you! Though I find the arguments unconvincing. More data needed... > typed assembly Yes. But now _every_ mac user and plenty of other people have a typed assembly compiler on their machines! IR is reasonably popular and quite well documented. I'm not saying it's new, I'm saying it's cool :)
- azakai 13y agoIt's not just calling conventions. LLVM IR also bakes in various assumptions about the target platform, from endianness to structure alignment to miscellaneous facts like whether char is signed or unsigned. In many of those there is no going back to the original representation, they are one-way. If you have IR that you can compile to various archs and have it work there, that is a lucky thing in that particular case. But it is not what LLVM IR was designed for nor should that work in general.
- phaemon 13y agoI don't understand what this means. Could you please give an example of some code that loses information in this way when compiled with LLVM?
- azakai 13y agoSay you have a struct type X with properties int, double, int. The offset of the last property depends on how alignment works on the target platform - it could be 12 or 16 on some common ones. LLVM IR can contain a read from offset 12, hardcoded. Whereas the C code contains X.propertyThree, which is more portable.
- phaemon 13y agoAh, I think I see....you mean I could write non-portable IR code by doing that, although LLVM would never produce code like that? I guess there must always be IR that the frontend will never produce then?
- KenoFischer 13y agoNo, every LLVM frontend (e.g. Clang) has to do so all the time for things to work.
- phaemon 13y agoThat makes no sense at all. You've just said that every LLVM frontend has to produce code that every LLVM frontend won't produce! If you mean something different, then could you please be clearer, as I really don't understand what you're talking about. [EDIT: caf's post made it clearer. I know what you meant now]
- caf 13y agoNo, the implication is that the LLVM IR that the frontend produces changes depending on the ultimate target that the LLVM IR will be compiled to. In other words, the frontends aren't backend-agnostic.
- phaemon 13y agoOh, right! That makes more sense. So you have to specify the backend when you start the process? I didn't know LLVM did that.
- bodyfour 13y agoint a() { return sizeof(void *); } Obviously a trivial example, but it's illustrative: the front-end compiler knows a bunch of things about your target and bakes that information into the IL. If you took IL generated by the compiler with "-arch i386" and then compiled the IL using "-arch x86_64" it's quite possible to get a non-working executable. It's possible to carefully write IL that will work on multiple platforms as done in this blog post, but I'm not sure how useful that really is. You're still giving up the exact control that assembly gives you, so I don't know how much better you'd get than clang-produced IR. In other words, if you want "portable assembly language" use C. Still, its an interesting blog post. It's good to show people how the compiler works behind the curtain.
- gngeal 13y agoYes. But now _every_ mac user and plenty of other people have a typed assembly compiler on their machines! Really? Where? Which one? The last time I looked, TAL was only a proposal.
- pyre 13y agoI think the parent is referring to the IR being like having a typed assembly language. IIRC, Apple uses LLVM.
- thinkmoore 13y agoLLVM IR is not strongly-typed in the way TAL proposes. Plenty can still go wrong.
- kstenerud 13y agoCounterpoint: http://lists.cs.uiuc.edu/pipermail/llvmdev/2011-October/043730.html http://lists.cs.uiuc.edu/pipermail/llvmdev/2011-October/0437...