Is there a reason why optimization remarks aren't supported for full lto?

I see that in the function lto:backend under LTOBackend.cpp that there is no mention of optimization remarks compared to lto:thinBackend. Is there a reason why this is the case, or have we just not ported the code to full lto backend? Or is there a different way to see optimization remarks from lto passes?

Thanks in advance.

They are supported, at least on Darwin platforms (through libLTO). I don’t fully remember what interface other linkers use, but I think the one that lld uses sets them up in LTO::runRegularLTO.

I do see that it is set up in LTO::runRegularLTO. Perhaps it’s because I’m not enabling it correctly; ld.lld --help returns the flags --opt-remarks-filename, --opt-remarks-passes, --opt-remarks-with-hotness, but when I try to use it as -Wl,-mllvm,--opt-remarks-filename=<file>, it complains that the commandline argument is unknown (specifically that --opt-remarks-passes=pgo-icall-prom is unknown). Do you know of a way I can get the remarks from LTO passes?

On Darwin (so ld64), the clang driver invoked for linking with -fsave-optimization-record will be enough to pass the right flags to the linker: "-mllvm" "-lto-pass-remarks-output" "-mllvm" "a.opt.yaml" "-mllvm" "-lto-pass-remarks-format=yaml".

Not sure how that’s working for lld, but you should be able to pass the same -mllvm options (-lto-pass-remarks-filter included).

If you manage to make it work it would be great to make the driver handle this and possibly update the documentation at Remarks — LLVM 17.0.0git documentation!

1 Like

I can confirm that -fsave-optimization-record will correctly output the file for lld. I’ll experiment a bit more and try to update the documentation. Thanks!