ponylang / ponyc

Pony is an open-source, actor-model, capabilities-secure, high performance programming language
http://www.ponylang.io
BSD 2-Clause "Simplified" License
5.71k stars 415 forks source link

Allow to set optimization level for codegen #2682

Open jirutka opened 6 years ago

jirutka commented 6 years ago

Why is optimization level hard-coded to -O3? https://github.com/ponylang/ponyc/blob/c76e5900a3453c6f922d68a3e78bb6e0dafeb971/src/libponyc/codegen/genexe.c#L361

I’d expect to be able to specify optimization level using CLI argument for ponyc.

jemc commented 6 years ago

If nothing else, this may be useful for debugging code generation problems.

jemc commented 6 years ago

In the sync call, @kulibali mentioned that the actual place for setting optimization level for LLVM codegen is here: https://github.com/ponylang/ponyc/blob/master/src/libponyc/codegen/genopt.cc#L1366

The line shown above is only for the linker.

@mfelsche is going to read about whether it would be a good idea to allow lowering the linker optimization level.

mfelsche commented 6 years ago

To avoid confusion, and to chime into what @jemc wrote, this is only a linker optimization flag.

The -O flag here is only setting a linker optimization level, and as far as i understand both the ld and gold linker docs and sources (my understanding might be very shallow), this is only used for optimizing the output file size, not actually doing optimizations as a C compiler would do (inlining and stuff). And this is also unrelated to what is known as link-time-optimization afaik. But i am happy to stand corrected.

Regardless of this being true or not, it might be interesting to set the linker optimization level from the ponyc command line.

I would rather consider this an enhancement, then a bug.

jirutka commented 6 years ago

The -O flag here is only setting a linker optimization level … this is only used for optimizing the output file size …

That’s actually what I’m currently interested in, to optimize size of the output binary (i.e. compile with -Os).