This is an archive of the discontinued LLVM Phabricator instance.

Make opt-viewer more usable by general developers - part 1/N
AbandonedPublic

Authored by OfekShilon on Aug 9 2022, 1:24 PM.

Details

Summary

This is a submission of the OptView2 project to be considered upstream.

The suggested changes mostly try to improve SnR (for general devs, as opposed to compiler authors):

  1. Exclude system headers by default,
  2. Collect only optimization failures by default,
    1. Create option to split processing into subfolders ('--split-top-folders') to enable processing of large projects that typically break otherwise.
  3. Trim repeated remark annotations in source - keep only 5 per line.
  4. Enable filtering by remark name/text, preferrably via config file (but possible via command line too). Check config.yaml for some examples.
  5. A complete rewrite of the index html, making the table sortable and resizable, display a single entry per file/line, use abridged func names, and display remark name instead of pass.

Except the rewrite of index.html and culling of duplicities, all changes can be reverted by command line options.
I uploaded some results of runs over medium/large projects, to get an impression of it:

  1. cpython
  2. opencv
  3. mujoco

Diff Detail

Event Timeline

OfekShilon created this revision.Aug 9 2022, 1:24 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 9 2022, 1:24 PM
OfekShilon requested review of this revision.Aug 9 2022, 1:24 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 9 2022, 1:24 PM

(1) As far as I can see the debian build failure has nothing to do with this diff:

...
unsupported_code_directive	1
unsupported_compiler_option	0
unsupported_source_language	0
🚨 Error: The command exited with status 1

Perhaps the build can be invoked again?

(2) Forgot to mention explicitly: this submission includes a sample cpp project. I hope to extend it later with some guidance on how to use attributes (restrict, const, pure, noescape) to solve common opt remarks. Where might be a good place to add that?

Thank you very much for sharing those improvements!

The improvements in both UI and remark handling look very desirable in general. Some of the changes seem unrelated, would it be possible to split the patch up in multiple separate patches to make them easier to review individually? E.g. move the UI changes in one or more separate patches, individual patches for the new options, the example and so on.

llvm/tools/opt-viewer/cpp_optimization_example/main.cc
2

Adding an example is great! Ig might also be good to use it as an end-to-end-test, although this may a bit more complicated, as it would require Clang to also be built.

It would also be good to mention this example in some of our documentation.

llvm/tools/opt-viewer/requirements.txt
4

Is this needed or not?

OfekShilon updated this revision to Diff 452434.EditedAug 13 2022, 9:36 AM
OfekShilon retitled this revision from Make opt-viewer more usable by general developers to Make opt-viewer more usable by general developers - part 1/N.

@fhahn You're right of course. I trimmed this patch to include just the added example and the two-line python requirements file. Hopefully this would be an easy approval and I'll add more gradual patches to be reviewed.

Regarding documentation, 3 directions come to mind:

  1. Since llvm is on now github, a README.md file can be used. I have a decent starting point ready here (after renaming from "OptView2" of course) and this might be the easiest.
  2. Alternatively, this content can be spilled into ./llvm/docs/Remarks.rst - extending the existing opt-viewer section
  3. Finally I can create a separate ./llvm/docs/OptViewer.rst and link to it from Remarks.rst.

This will probably be the last patch I submit anyway. What do you think?

Added cpp-example and python requirements files (and not .gitignore) to the CMakeList installation.

fhahn added a comment.Aug 14 2022, 9:02 AM

@fhahn You're right of course. I trimmed this patch to include just the added example and the two-line python requirements file. Hopefully this would be an easy approval and I'll add more gradual patches to be reviewed.

Regarding documentation, 3 directions come to mind:

  1. Since llvm is on now github, a README.md file can be used. I have a decent starting point ready here (after renaming from "OptView2" of course) and this might be the easiest.
  2. Alternatively, this content can be spilled into ./llvm/docs/Remarks.rst - extending the existing opt-viewer section
  3. Finally I can create a separate ./llvm/docs/OptViewer.rst and link to it from Remarks.rst.

This will probably be the last patch I submit anyway. What do you think?

Sounds good to me. I think we should probably have a readme and it might be worth to split off the existing opt-viewer section and add a separate .rst for it.

llvm/tools/opt-viewer/cpp_optimization_example/Makefile
1

Not sure if there's an easy way to do it, but if possible it would be good to default to custom build of clang, if that's enabled. Not sure fi that's easily possible though.

llvm/tools/opt-viewer/cpp_optimization_example/main.cc
1

It would probably be good to add the llvm license header here

5

It would probably be good to format this with clang-format and the LLVM code style.

14

nit: stray new line?

llvm/tools/opt-viewer/cpp_optimization_example/run_optview.sh
2

Should this also create a virtual-env and install dependencies?

fhahn added a comment.Aug 14 2022, 9:04 AM

I think the pre-commit tests are failing because llvm/tools/opt-viewer/cpp_optimization_example/main.cc doesn't meet the LLVM style guide and needs re-formatting with clang-format. In the LLVM codebase we also usually use .cpp instead of .cc as file extension.

OfekShilon marked an inline comment as done.Oct 9 2022, 4:51 AM

I apologize - I dropped this for too long and am having a hard time resurrecting it now. I'm closing this and will start again in a fresh review request in the near days.

llvm/tools/opt-viewer/cpp_optimization_example/main.cc
5

@fhahn How do I do that?

14

fixed

llvm/tools/opt-viewer/requirements.txt
4

Needed, in parts not yet included in this first patch

OfekShilon abandoned this revision.Oct 9 2022, 4:54 AM
OfekShilon marked an inline comment as done.
fhahn added a comment.Oct 12 2022, 7:58 AM

I apologize - I dropped this for too long and am having a hard time resurrecting it now. I'm closing this and will start again in a fresh review request in the near days.

No worries, thanks!