This is an archive of the discontinued LLVM Phabricator instance.

[Remarks] Add -foptimization-record-passes to filter remark emission
ClosedPublic

Authored by thegameg on Mar 12 2019, 10:57 AM.

Details

Summary

Currently we have -Rpass for filtering the remarks that are displayed as diagnostics, but when using -fsave-optimization-record, there is no way to filter the remarks while generating them.

This adds support for filtering remarks by passes using a regex.

Ex:

clang -fsave-optimization-record -foptimization-record-passes=inline

will only emit the remarks coming from the pass inline.

This adds:

  • -fsave-optimization-record to the driver
  • -opt-record-passes to cc1
  • -lto-pass-remarks-passes to the LTOCodeGenerator
  • --opt-remarks-passes to lld
  • -pass-remarks-passes to llc, opt, llvm-lto, llvm-lto2
  • -opt-remarks-passes to gold-plugin

The naming is chosen to be consistent with the output filename.

Diff Detail

Repository
rL LLVM

Event Timeline

thegameg created this revision.Mar 12 2019, 10:57 AM
paquette accepted this revision.Mar 12 2019, 11:40 AM

Awesome!

The code LGTM. I have a few minor nits, which are mostly personal taste.

clang/include/clang/Driver/CC1Options.td
607 ↗(On Diff #190293)

This is kind of clunky IMO

Maybe like

"Only record remark information for passes whose names match the given regular expression"

clang/include/clang/Driver/Options.td
1720 ↗(On Diff #190293)

"Only include passes which match a specified regular expression in the generated optimization record"

Also, maybe we should make it clear that the default behaviour is to include all passes?

clang/test/CodeGen/opt-record-MIR.c
27 ↗(On Diff #190293)

Not hugely critical, but can we avoid explicit line numbers in these tests? I think it's kind of flaky. It would be nice to have remarks tests be robust against unrelated changes as much as possible.

llvm/test/CodeGen/AArch64/machine-outliner-size-info.mir has an example of how you can combine the YAML output and standard remark output.

llvm/lib/IR/RemarkStreamer.cpp
35–37 ↗(On Diff #190293)

Maybe we should keep track of the number of passes we matched? If it's 0, then we can emit a warning saying that we didn't match anything.

I can imagine people misspelling pass names/writing bad regexes etc and maybe wanting this information.

I guess that could be done in a follow-up though.

llvm/lib/LTO/LTOCodeGenerator.cpp
91 ↗(On Diff #190293)

Why is this cl::desc different from the others?

llvm/tools/gold/gold-plugin.cpp
210 ↗(On Diff #190293)

I feel like if I didn't know anything about this, I would assume that this defaults to all passes.

Maybe OptRemarksFilter would be a better name?

llvm/tools/llc/llc.cpp
152 ↗(On Diff #190293)

Maybe "-pass-remarks-only" or "pass-remarks-filter" instead of "passes"?

This is a matter of personal taste though, so I won't be offended if you leave it as is.

153 ↗(On Diff #190293)

The other remarks descriptions all follow this format

"Enable optimization remarks from passes whose name match the given regular expression"

So maybe something like this would be more idiomatic

"Only record optimization remarks from passes whose names match the given regular expression"

This revision is now accepted and ready to land.Mar 12 2019, 11:40 AM
This revision was automatically updated to reflect the committed changes.
thegameg marked 7 inline comments as done.

Thanks Jessica!

llvm/lib/IR/RemarkStreamer.cpp
35–37 ↗(On Diff #190293)

That's a good idea, yes! I'll do that in a separate patch, thanks