[PATCH] D105223: [lld-macho] Add support for LTO optimization level
Steven Wu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 1 09:29:55 PDT 2021
steven_wu added inline comments.
================
Comment at: lld/MachO/Config.h:129
llvm::StringRef thinLTOJobs;
+ uint32_t ltoo = 2;
bool deadStripDylibs = false;
----------------
lgrey wrote:
> thakis wrote:
> > int3 wrote:
> > > lgrey wrote:
> > > > thakis wrote:
> > > > > Is this the same default ld64 seems to use?
> > > > 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?
> > > ld64 has an undocumented `-flto-codegen-only` flag. I haven't looked into what exactly it does, but it seems relevant...
> > > Should we change it to 0 for compat?
> >
> > Yes, I think so.
> >
> > > -flto-codegen-only
> >
> > 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…
> Maybe the legacy LTO implementation bitrotted? The [docs](https://clang.llvm.org/docs/ThinLTO.html#id8) 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?
You cannot control optimization level for `ld64`. It is always on and the pipeline is configured in libLTO.
`-flto-codegen-only` will turn off all the optimization on LLVM IR and only run the code generation pipeline with all optimization on. This is only used for debugging or apple bitcode.
`-O` flag will control how much local optimization is done for each individual .o file (bitcode) before passing to linker for LTO.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D105223/new/
https://reviews.llvm.org/D105223
More information about the llvm-commits
mailing list