Meaning of the LLVM Optimization Levels

不问归期 提交于 2019-12-03 12:08:06
Oak

Clang's command-line options documentation is indeed very poor, and in particular you are correct that there's almost no explanation of what the optimizations level do.

FreeBSD, however, does add a man page with a useful summary:

-O0 -O1 -O2 -Os -Oz -O3 -O4
Specify which optimization level to use. -O0 means "no optimization": this level compiles the fastest and generates the most debuggable code. -O2 is a moderate level of optimization which enables most optimizations. -Os is like -O2 with extra optimizations to reduce code size. -Oz is like -Os (and thus -O2), but reduces code size further. -O3 is like -O2, except that it enables optimizations that take longer to perform or that may generate larger code (in an attempt to make the program run faster). On supported platforms, -O4 enables link-time optimization; object files are stored in the LLVM bitcode file format and whole program optimization is done at link time. -O1 is somewhere between -O0 and -O2.

If you're looking to find the exact list of passes performed for each optimization, see this Stackoverflow question:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!