Everything (including test) modified from ELF/COFF. Using the same syntax (--lto-O3, etc) as ELF.
Details
- Reviewers
int3 gkm thakis - Group Reviewers
Restricted Project - Commits
- rG6ef37b640daf: [lld/mac] Add test for --lto-O
rGfe08e9c4871e: [lld-macho] Add support for LTO optimization level
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
lld/MachO/Config.h | ||
---|---|---|
129 | AFAICT, it doesn't optimize. $ cat opt_check.c void foo() { return; } int main(int argc, char** argv) { foo(); return 0; } $ clang -flto=thin opt_check.c && nm -pa a.out 0000000100003f80 t _foo 0000000100000000 T __mh_execute_header 0000000100003f90 T _main U dyld_stub_binder Should we change it to 0 for compat? |
lld/MachO/Config.h | ||
---|---|---|
129 | ld64 has an undocumented -flto-codegen-only flag. I haven't looked into what exactly it does, but it seems relevant... |
lld/MachO/Config.h | ||
---|---|---|
129 |
Yes, I think so.
I think that's probably something else. That ends up calling thinlto_codegen_set_codegen_only() in llvm/tools/lto/lto.cpp. …but lto_file.cpp in ld64 doesn't seem to pass an optimization flag, and OptLevel in lto.cpp defaults to 2. Strange that ld64 doesn't get an opt level of 2 then… |
Does this test -O2 or --lto-O2? Do you need two files for checking lto, i.e. it inlines foo across two TUs?
Effectively both, since what it really wants to test is the passthrough, but I don't think there's a way to sense for that directly. This just adapts lld/test/COFF/lto-opt-level.ll, but if there's some way to mock lto::LTO and assert things about its config, that seems like it would be good. Is there?
I think two files aren't necessary since the single file inlining is enough to demonstrate the flag was passed.
lld/MachO/Config.h | ||
---|---|---|
129 | Maybe the legacy LTO implementation bitrotted? The docs bake optimization in: % clang -flto=thin -O2 file1.c file2.c -c % clang -flto=thin -O2 file1.o file2.o -o a.out I tried changing to 0, but this breaks existing behavior, since the default appears to be 2 when omitting opt level from the config. Are we OK with that? |
lld/MachO/Config.h | ||
---|---|---|
129 | You cannot control optimization level for ld64. It is always on and the pipeline is configured in libLTO. -O flag will control how much local optimization is done for each individual .o file (bitcode) before passing to linker for LTO. |
Is this the same default ld64 seems to use?