In VC++ what is the #pragma equivalent of /O2 compiler option (optimize for speed)

蹲街弑〆低调 提交于 2019-12-05 22:17:23
bosmacs

The Microsoft Docs article /O1, /O2 (Minimize Size, Maximize Speed) says for Visual Studio 2017:

The /O1 and /O2 compiler options are a quick way to set several specific optimization options at once. The /O1 option sets the individual optimization options that create the smallest code in the majority of cases. The /O2 option sets the options that create the fastest code in the majority of cases. The /O2 option is the default for release builds. This table shows the specific options that are set by /O1 and /O2:

Option                   Equivalent to
/O1 (Minimize Size)     /Og /Os /Oy /Ob2 /GF /Gy
/O2 (Maximize Speed)    /Og /Oi /Ot /Oy /Ob2 /GF /Gy

From the Microsoft Docs article /O Options (Optimize Code):

  1. /Og enables global optimizations
  2. /Oi generates intrinsic functions for appropriate function calls.
  3. /Ot (a default setting) tells the compiler to favor optimizations for speed over optimizations for size.
  4. /Oy suppresses the creation of frame pointers on the call stack for quicker function calls.
  5. /Ob2 expands functions marked as inline or __inline and any other function that the compiler chooses

The /G options are:

  1. /GF (Eliminate Duplicate Strings)
  2. /Gy (Enable Function-Level Linking)

The /G options aren't strictly optimizations, so that leaves us with /Og and /Ot, plus #pragma intrinsic (for item 2 in the list), #pragma auto_inline (for item 5 in the list) and possibly #pragma inline_depth. See Microsoft Docs article Optimization Pragmas and Keywords

See also Microsoft Docs article /Ox (Enable Most Speed Optimizations) which indicates the /Ox option is similar to the /O2 option except that it does not turn on /GF nor /Gy. See as well What is the difference between the /Ox and /O2 compiler options?

The Microsoft Docs article Compiler options listed by category has a list of compiler options with links as to what they mean.

I don't think there is a direct equivalent.

#pragma optimise("gty", off)

Should cancel for a file, most of the effect of /O2 at the project level, but

#pragma optimise("gty", on)

Just says "use the compiler switch", so you need /O2 or /Og /Ot /Oy.

I can't find pragmas for the /G parts and they do optimisation 'like' things.

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