Stream: t-compiler

Topic: cross-lang-lto and assembly


Jake Goulding (Dec 19 2018 at 19:41, on Zulip):

Hey @mw, do you know of any reason that cross-language LTO shouldn't work if my C file is actually an assembly file?

simulacrum (Dec 19 2018 at 19:42, on Zulip):

@Jake Goulding Yeah, that I think would be expected -- LLVM doesn't uplift assembly into LLVM IR so it can't run optimization passes based on it?

Not sure if that's what you mean though

Jake Goulding (Dec 19 2018 at 19:43, on Zulip):

I don't think I phrased my question well, let me try again: Do you think cross-language LTO will work when the two languages are Rust + assembly?

Jake Goulding (Dec 19 2018 at 19:44, on Zulip):

I have not tried anything, so I have no clue ;-)

Jake Goulding (Dec 19 2018 at 19:44, on Zulip):

But, if I understand you correctly, cross-language LTO only works when there's LLVM IR available. Assembly wouldn't have that, so LTO is not possible?

simulacrum (Dec 19 2018 at 19:46, on Zulip):

I suppose it depends on definition of LTO -- LLVM might be able to strip out symbols/reduce code size by inlining still, I guess

simulacrum (Dec 19 2018 at 19:47, on Zulip):

But the "intelligent" optimization I think wouldn't happen

rkruppe (Dec 19 2018 at 20:00, on Zulip):

AFAIK there is no existing infrastructure in LLVM for doing any non-trivial optimizing starting from textual assembly (beyond what linkers could already do). Even the low level machine-specific peephole optimizations work on a much richer IR (MachineInstr) than what LLVM can get back out of textual assembly (MCInstr).

Jake Goulding (Dec 19 2018 at 20:34, on Zulip):

I'm thinking even beyond text — if I have two fully compiled object files (just machine code), can those somehow be optimized (esp. inlined) with each other?

Jake Goulding (Dec 19 2018 at 20:36, on Zulip):

Like, I guess I got mislead by the belief that "linkers just combine machine code", thus link-time optimization would be on that machine code. However, in this case we have enhanced object files that also have LLVM IR in it, so "link time" is also "code generation time"

rkruppe (Dec 19 2018 at 21:34, on Zulip):

FWIW object file vs textual asm isn't a big difference in any way that matters for this subject

nagisa (Dec 19 2018 at 22:09, on Zulip):

@rkruppe what matters is ability to inline

nagisa (Dec 19 2018 at 22:09, on Zulip):

object file produced from external assembly will not be able to get rid of the call-overhead

nagisa (Dec 19 2018 at 22:17, on Zulip):

though in practice it seems seldom necessary

mw (Dec 20 2018 at 08:52, on Zulip):

Yes, as the others already mentioned, cross-lang LTO needs LLVM IR for all code involved in order to do anything useful. Linkers can handle mixes of LLVM IR and regular libs/object files but the latter won't take part in the optimization passes.

Last update: Nov 16 2019 at 02:40UTC