[cfe-dev] Which -O is the default for clang?

Keane, Erich via cfe-dev cfe-dev at lists.llvm.org
Tue Jan 29 14:37:56 PST 2019


If you don't set it, neither does the default clang driver.  You can tell this by running a the driver with the parameter -###, which will print the output.

The top of CompilerInvocation.cpp has the function that determines the optimization level based on the parameter to the CC1 invocation.  That should answer your questions about the different versions.  Note a handful of language options appear in the function so it isn't that easy of a question to just answer.

-----Original Message-----
From: cfe-dev [mailto:cfe-dev-bounces at lists.llvm.org] On Behalf Of Peng Yu via cfe-dev
Sent: Tuesday, January 29, 2019 2:31 PM
To: cfe-dev <cfe-dev at lists.llvm.org>
Subject: [cfe-dev] Which -O is the default for clang?

Hi,

I don't see the manpage mentions which -O is the default for clang.
Does anybody know? Thanks.

   Code Generation Options
       -O0, -O1, -O2, -O3, -Ofast, -Os, -Oz, -Og, -O, -O4
              Specify which optimization level to use:
                 -O0 Means "no optimization": this level compiles the fastest and generates the most debuggable code.

                 -O1 Somewhere between -O0 and -O2.

                 -O2 Moderate level of optimization which enables most optimizations.

                 -O3  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).

                 -Ofast Enables all the optimizations from -O3 along with other aggressive optimizations that may violate strict compliance with language standards.

                 -Os Like -O2 with extra optimizations to reduce code size.

                 -Oz Like -Os (and thus -O2), but reduces code size further.

                 -Og Like -O1. In future versions, this option might disable different optimizations in order to improve debuggability.

                 -O Equivalent to -O2.

                 -O4 and higher
                     Currently equivalent to -O3

--
Regards,
Peng
_______________________________________________
cfe-dev mailing list
cfe-dev at lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


More information about the cfe-dev mailing list