I think simplifying life with a couple of wrapper scripts (`nim-pgo-gcc` and 
`nim-pgo-clang`, say) would help would-be PGO'ers, even if said scripts were 
only a starting point for the users' own scripts.

In theory, the Nim compiler could itself grow a 2-phase compilation mode. 
Things are already set up so you can say `nim c --run prog args`. So, all we 
would really need to do is add a `--pgo` that works just like `--run` but A) 
uses a modified namespace/extra name for `compiler.options` (a place to put 
`-fprofile-generate`) and B) re-compiles everything again afterward with 
another modified namespace/extra name for `compiler.options` (a place to put 
`-fprofile-use`).

I'd say that kind of fits well with existing nim CLI workflow. There are only 
minor risks like biasing folks to write programs that do a benchmark run when 
given no args or accidental infinite loop/giant benchmarks but those are both 
intrinsic to PGO in general.

Maybe there is already a way to hack `config.nims` to be this smart? I think a 
lot more people would use it if it were as simple as `nim c --pgo -d:danger 
prog args`.

Reply via email to