LTOCodeGenerator and the llvm-lto utility can currently only emit object code.
With this patch, we gain the ability to output assembly and bitcode if desired.
This is primarily useful for testing (e.g. lit tests of LTO CodeGen). Our
linker also has a -save-temps option to save assembly during LTO which can be
implemented on top of this functionality.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
I don't think this is necessary. There is already a LTOCodeGenerator::writeMergedModules() function that you can use to write the bitcode. If you would like to test the module splitting functionality, you can use llvm-split on that bitcode file.
Ah I wasn't aware of the llvm-split utility - makes sense. It would still be useful to get bitcode out of llvm-lto for testing. But that could be built on top of writeMergedModule, as you mentioned.
The part about emitting assembly remains, though.
I'll update the patch.
The bitcode->assembly part is available with llc though, not sure why it's not enough?
Yes... but I'd rather not have our linker depend on llc or, alternatively, set up its own CodeGen pass manager just to emit assembly. Also, if we're using module splitting, there'd be an additional step: bitcode -> llvm-split -> llc. The option in LTOCodeGenerator seems a lot cleaner to me.
Sorry, I missed the fact that the point was to enable an interface for your linker, I just thought about the llvm-lto case. If you need this functionality in your linker, then it makes sense.
Updated patch with Peter and Mehdi's comments - thank you both!
The patch now only adds the ability to emit assembly to LTOCodeGenerator, and a new option -save-merged-module to llvm-lto to write out the merged module before CodeGen for testing.
LGTM
test/LTO/X86/llvm-lto-output.ll | ||
---|---|---|
12 ↗ | (On Diff #40151) | Will the asm look like this on every architecture? I think so, but it may be safest to specify a target explicitly. |
The llvm-lto changes seems unrelated to the ability to write ASM from LTOCodeGenerator right? This could be committed separately.
test/LTO/X86/llvm-lto-output.ll | ||
---|---|---|
12 ↗ | (On Diff #40151) | Especially since the test is in the "X86" folder. I'd expect an X86 triple at least. |