Meaning of the LLVM Optimization Levels

2020-06-11 05:38发布

I recently started working with Clang/LLVM and would like to know if there is any particular documentation on what the -Ox optimization levels do?

I couldn't find much on the LLVM documentation page. Can someone share a few links?

Thanks.

1条回答
Juvenile、少年°
2楼-- · 2020-06-11 06:02

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:

查看更多
登录 后发表回答