The switch --plugin-opt=emit-asm can be used with the gold linker to dump the final assembly code generated by LTO in a user-friendly way. Unfortunately it doesn't work with lld. I'm hooking it up with lld. With that switch, lld emits assembly code into the output file (specified by -o) and if there are multiple input files, each of their assembly code will be emitted into a separate file named by suffixing the output file name with a unique number, respectively. The linking then stops after generating those assembly files.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Test Plan: ninja check-lld
This can be omitted as it does add value to the description. Almost every change will need check-lld (or check-lld-elf during development if you are confident non-ELF is not affected.)
lld/test/ELF/lto/emit-asm.ll | ||
---|---|---|
9 | Now sure if the partition stably places f1 in the first assembly and f2 in the second. So I'm using CHECK-DAG on the merged output. What do you think? |
lld/ELF/Driver.cpp | ||
---|---|---|
891 | It looks inconsistent with another OPT_lto* options we have: config->ltoAAPipeline = args.getLastArgValue(OPT_lto_aa_pipeline); config->ltoCSProfileGenerate = args.hasArg(OPT_lto_cs_profile_generate); config->ltoCSProfileFile = args.getLastArgValue(OPT_lto_cs_profile_file); ... Should it be called config->ltoEmitAsm to be consistent? Or, instead, it could be args.hasArg(OPT_plugin_opt_emit_asm, false), what also would make sense it seems. What do other reviewers think? | |
1963 | That the last 2 comments have a large common part. Also it seems that if thinLTOIndexOnly, emitLLVM and emitAsm were added at once and not separatelly, we would not split them. I think it might be better to rewrite these 3 comments into a single one and do: // <A shorter and nicer comment here> if (config->thinLTOIndexOnly || config->emitLLVM || config->emitAsm) return; |
lld/ELF/Driver.cpp | ||
---|---|---|
1963 | "That the last 2..." -> "Last 2..." |
lld/ELF/Driver.cpp | ||
---|---|---|
891 | Well, on the second thought, I'm thinking maybe just removing the --lto-emit-asm switch and only having --plugin-opt=emit-asm, since it is not lld-exclusive. What do you think? |
lld/ELF/Driver.cpp | ||
---|---|---|
891 | ||
1963 |
+1 | |
lld/ELF/LTO.cpp | ||
338 | To be honest, the output file naming (--save-temps and the new emit-asm) here also looks strange to me. Why is 1 special cased? @pcc @tejohnson |
lld/ELF/LTO.cpp | ||
---|---|---|
338 | My understanding is that output 0 has no suffix on the output file name, and suffix starts from output 1. Is that your question? |
lld/ELF/Driver.cpp | ||
---|---|---|
891 | For compatibility, please do add support for the plugin-opt version, even if it is just an alias for a new --lto-emit-asm. | |
lld/ELF/LTO.cpp | ||
338 | I think @pcc added that handling to gold-plugin, but I believe it is so there is no suffix when we are doing regular LTO where there is one task. |
lld/ELF/Driver.cpp | ||
---|---|---|
891 |
Seems nobody yet said something against this and it is anyways easy to add an additional alias option later if needed.
+1, I'd also would like to hear Peter's opinion. |
lld/ELF/Driver.cpp | ||
---|---|---|
920 | Delete , false which is redundant |
lld/ELF/Options.td | ||
---|---|---|
544 | This is not done. |
lld/ELF/Options.td | ||
---|---|---|
544 | Yeah, I overlooked this. I'm a bit confused here. I'm seeing every other lto switche has only one dash. What's the convention here? |
lld/ELF/Options.td | ||
---|---|---|
544 | I fixed Alias for in 42bb5cc502da0e01e5e714800dbec7d13603d399. GNU ld has very loose parsing rules. It accepts either single-dash or double-dash options. For compatibility we have to do the same. For commonly used single-dash options e.g. -shared -pie (Their compiler driver counterparts use this form), I stick with them. For everything unclear, I use the double dash form. -lto-... is bad because it conflicts with -l |
Mostly good correct. @tejohnson ^^
I'm planning to land this shortly. Thanks!
This sentence does not look right. There are still a few comments not addressed. One is a critical one: ; REQUIRES: x86. Without it the test will fail on a built LLVM with the x86 target disabled. Some people maintaining ARM bots will assuredly revert your change.
lld/test/ELF/lto/emit-asm.ll | ||
---|---|---|
2 | Oops, I overlooked this one. Why doesn't it work on non-X86? |
lld/ELF/Options.td | ||
---|---|---|
543 | Move it before emit_llvm for local lexicographical order. |
@hoyFB LLVM is very loose by giving commit access to everyone, but we are expecting people to act in good faith. Your initial action (adding a colleague (with all due respect) who has no contribution to lld yet) and your word I'm planning to land this shortly made me very concerned that you wanted to bypass the usual review process. (I would not have overreacted if I had seen some lld contribution from you)
@MaskRay I think there is a misunderstanding going on here. I was hoping to have this change in sooner because we really need it on our side. That being said, we didn't intend to bypass any code reviewers to commit the change silently, as you can see that the change has been pending here for three weeks and all feedbacks from all reviewers have been addressed. If by an accident there are more feedbacks after this is committed, we will always address them in a new change or revert this change.
lld/test/ELF/lto/emit-asm.ll | ||
---|---|---|
5 | Line 3 and Line 4? |
Thanks for persisting. The latest version looks good to me. Give some time for @grimar or @tejohnson to sign off since they've commented.
@MaskRay @grimar @tejohnson Thank you all for your great code reviews! I'm going to close this.
Delete unnecessary Phabricator tags with:
arcfilter () { arc amend git log -1 --pretty=%B | awk '/Reviewers:|Subscribers:/{p=1} /Reviewed By:|Differential Revision:/{p=0} !p && !/^Summary:$/ {sub(/^Summary: /,"");print}' | git commit --amend -F - }
Thanks for the tips. seems a bit late. The change has just been committed. I'll do this for future changes. Do you still want amend for this commit?
Phabricator added some tags automatically. Among them, Summary: Reviewers: Tags: are considered not useful (discussed on a previous llvm-dev thread).
Reviewed-by: is useful and should be retained.
It is said that we can patch server-side Phabricator to hide these tags: http://lists.llvm.org/pipermail/llvm-dev/2020-April/140810.html
but no administrator has made action here.
I just train myself to use arcfilter; git fetch origin master && git rebase origin/master; ninja -C /path/to/build check-lld-elf && git push origin HEAD:master
It looks inconsistent with another OPT_lto* options we have:
Should it be called config->ltoEmitAsm to be consistent?
Or, instead, it could be args.hasArg(OPT_plugin_opt_emit_asm, false), what also would make sense it seems.
What do other reviewers think?