The backend now has the capability to save information from optimizations, the same information that can be used to generate optimization diagnostics but in machine-consumable form, into an output file. This can be enabled when using opt (see r282539), and this patch will enable it when using clang. The idea is that other tools will be able to consume these files, and perhaps in combination with the original source code, produce various kinds of optimization reports for users (and for compiler developers).
This patch proposes the name -fsave-optimization-record (and -fsave-optimization-record=filename). Bikeshedding welcome.
Sorry, one more thing: if PGO is available, I think we want to set Ctx.setDiagnosticHotnessRequested as well. Without that, you'd have to pass -fsave-optimization-record and -fdiagnostics-show-hotness to get hotness info into the YAML file which feels strange. I am certainly fine if we do this later but I wanted to bring it up since it's seems related.