This is an archive of the discontinued LLVM Phabricator instance.

[LTO] Add option to emit assembly and bitcode from LTO CodeGen
ClosedPublic

Authored by tobiasvk on Nov 10 2015, 2:38 PM.

Details

Summary

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.

Diff Detail

Event Timeline

tobiasvk updated this revision to Diff 39852.Nov 10 2015, 2:38 PM
tobiasvk retitled this revision from to [LTO] Add option to emit assembly and bitcode from LTO CodeGen.
tobiasvk updated this object.
tobiasvk added reviewers: rafael, dexonsmith.
pcc added a subscriber: pcc.Nov 10 2015, 2:52 PM

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?

In D14554#286654, @joker.eph wrote:

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.

tobiasvk updated this revision to Diff 40151.Nov 13 2015, 7:57 AM

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.

pcc accepted this revision.Nov 17 2015, 4:06 PM
pcc added a reviewer: pcc.

LGTM

test/LTO/X86/llvm-lto-output.ll
12

Will the asm look like this on every architecture? I think so, but it may be safest to specify a target explicitly.

This revision is now accepted and ready to land.Nov 17 2015, 4:06 PM

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

Especially since the test is in the "X86" folder. I'd expect an X86 triple at least.

I meant the "SaveModuleFile" option in llvm-lto.

This revision was automatically updated to reflect the committed changes.