meson-plus-plus icon indicating copy to clipboard operation
meson-plus-plus copied to clipboard

Add a peephole optimization for `cc.has_argument()`

Open dcbaker opened this issue 1 year ago • 0 comments

I'm marking this as a moderate issue because there currently isn't any sort of framework for doing peephole optimizations, everything is done one instruction at at time.

In particular, there are loops that look like this:

cc = meson.get_compiler('c')
foreach a : ['-Wno-foo', '-Wbar', '-Werror=thing']
  if cc.has_argument(a)
    add_project_arguments(a, language : 'c')
  endif
endforeach

This could be optimized to:

cc = meson.get_compiler('c')
add_project_arguments(cc.get_supported_arguments(['-Wno-foo', '-Wbar', '-Werror=thing']), language : 'c'))

A couple of questions to be answered here: do we do this before loop unrolling, after loop unrolling, or at the AST level. I see some advantages to all of these approaches.

If we're unrolling, then we're looking at a basic block that has a single node, add_*_arguments, which may be more difficult to see than at the AST level.

dcbaker avatar Oct 24 '24 19:10 dcbaker