|
1 | 1 | ---
|
2 |
| -description: "Learn more about: /GL (Whole Program Optimization)" |
3 |
| -title: "/GL (Whole Program Optimization)" |
4 |
| -ms.date: "11/04/2016" |
5 |
| -f1_keywords: ["/gl"] |
| 2 | +description: "Learn more about: /GL (Whole program optimization)" |
| 3 | +title: "/GL (Whole program optimization)" |
| 4 | +ms.date: 03/05/2021 |
| 5 | +f1_keywords: ["/GL"] |
6 | 6 | helpviewer_keywords: ["/GL compiler option [C++]", "whole program optimizations and C++ compiler", "-GL compiler option [C++]", "GL compiler option [C++]"]
|
7 |
| -ms.assetid: 09d51e2d-9728-4bd0-b5dc-3b8284aca1d1 |
8 | 7 | ---
|
9 |
| -# /GL (Whole Program Optimization) |
| 8 | +# `/GL` (Whole program optimization) |
10 | 9 |
|
11 | 10 | Enables whole program optimization.
|
12 | 11 |
|
13 | 12 | ## Syntax
|
14 | 13 |
|
15 |
| -``` |
16 |
| -/GL[-] |
17 |
| -``` |
| 14 | +> **`/GL`**[**`-`**] |
18 | 15 |
|
19 | 16 | ## Remarks
|
20 | 17 |
|
21 |
| -Whole program optimization allows the compiler to perform optimizations with information on all modules in the program. Without whole program optimization, optimizations are performed on a per module (compiland) basis. |
| 18 | +Whole program optimization allows the compiler to perform optimizations with information on all modules in the program. Without whole program optimization, optimizations are performed on a per-module (compiland) basis. |
22 | 19 |
|
23 |
| -Whole program optimization is off by default and must be explicitly enabled. However, it is also possible to explicitly disable it with **/GL-**. |
| 20 | +Whole program optimization is off by default and must be explicitly enabled. However, it's also possible to explicitly disable it with **`/GL-`**. |
24 | 21 |
|
25 | 22 | With information on all modules, the compiler can:
|
26 | 23 |
|
27 | 24 | - Optimize the use of registers across function boundaries.
|
28 | 25 |
|
29 | 26 | - Do a better job of tracking modifications to global data, allowing a reduction in the number of loads and stores.
|
30 | 27 |
|
31 |
| -- Do a better job of tracking the possible set of items modified by a pointer dereference, reducing the numbers of loads and stores. |
| 28 | +- Track the possible set of items modified by a pointer dereference, reducing the required loads and stores. |
32 | 29 |
|
33 | 30 | - Inline a function in a module even when the function is defined in another module.
|
34 | 31 |
|
35 |
| -.obj files produced with **/GL** will not be available to such linker utilities as [EDITBIN](editbin-reference.md) and [DUMPBIN](dumpbin-reference.md). |
| 32 | +*`.obj`* files produced with **`/GL`** aren't usable by linker utilities such as [`EDITBIN`](editbin-reference.md) and [`DUMPBIN`](dumpbin-reference.md). |
36 | 33 |
|
37 |
| -If you compile your program with **/GL** and [/c](c-compile-without-linking.md), you should use the /LTCG linker option to create the output file. |
| 34 | +If you compile your program with **`/GL`** and [`/c`](c-compile-without-linking.md), you should use the /LTCG linker option to create the output file. |
38 | 35 |
|
39 |
| -[/ZI](z7-zi-zi-debug-information-format.md) cannot be used with **/GL** |
| 36 | +[`/ZI`](z7-zi-zi-debug-information-format.md) can't be used with **`/GL`** |
40 | 37 |
|
41 |
| -The format of files produced with **/GL** in the current version may not be readable by subsequent versions of Visual C++. You should not ship a .lib file comprised of .obj files that were produced with **/GL** unless you are willing to ship copies of the .lib file for all versions of Visual C++ you expect your users to use, now and in the future. |
| 38 | +The format of files produced with **`/GL`** in the current version often isn't readable by later versions of Visual Studio and the MSVC toolset. Unless you're willing to ship copies of the *`.lib`* file for all versions of Visual Studio you expect your users to use, now and in the future, don't ship a *`.lib`* file made up of *`.obj`* files produced by **`/GL`** . For more information, see [Restrictions on binary compatibility](../../porting/binary-compat-2015-2017.md#restrictions). |
42 | 39 |
|
43 |
| -.obj files produced with **/GL** and precompiled header files should not be used to build a .lib file unless the .lib file will be linked on the same machine that produced the **/GL** .obj file. Information from the .obj file's precompiled header file will be needed at link time. |
| 40 | +*`.obj`* files produced by **`/GL`** and precompiled header files shouldn't be used to build a *`.lib`* file unless the *`.lib`* file is linked on the same machine that produced the **`/GL`** *`.obj`* file. Information from the *`.obj`* file's precompiled header file is needed at link time. |
44 | 41 |
|
45 |
| -For more information on the optimizations available with and the limitations of whole program optimization, see [/LTCG](ltcg-link-time-code-generation.md). **/GL** also makes profile guided optimization available; see /LTCG. When compiling for profile guided optimizations and if you want function ordering from your profile guided optimizations, you must compile with [/Gy](gy-enable-function-level-linking.md) or a compiler option that implies /Gy. |
| 42 | +For more information on the optimizations available with and the limitations of whole program optimization, see [`/LTCG`](ltcg-link-time-code-generation.md). **`/GL`** also makes profile guided optimization available. When compiling for profile guided optimizations and if you want function ordering from your profile guided optimizations, you must compile with [`/Gy`](gy-enable-function-level-linking.md) or a compiler option that implies /Gy. |
46 | 43 |
|
47 | 44 | ### To set this linker option in the Visual Studio development environment
|
48 | 45 |
|
49 |
| -1. See [/LTCG (Link-time Code Generation)](ltcg-link-time-code-generation.md) for information on how to specify **/GL** in the development environment. |
| 46 | +For more information on how to specify **`/GL`** in the development environment, see [`/LTCG` (Link-time code generation)](ltcg-link-time-code-generation.md) . |
50 | 47 |
|
51 | 48 | ### To set this linker option programmatically
|
52 | 49 |
|
53 |
| -1. See <xref:Microsoft.VisualStudio.VCProjectEngine.VCCLCompilerTool.WholeProgramOptimization%2A>. |
| 50 | +- See <xref:Microsoft.VisualStudio.VCProjectEngine.VCCLCompilerTool.WholeProgramOptimization%2A>. |
54 | 51 |
|
55 | 52 | ## See also
|
56 | 53 |
|
57 |
| -[MSVC Compiler Options](compiler-options.md)<br/> |
58 |
| -[MSVC Compiler Command-Line Syntax](compiler-command-line-syntax.md) |
| 54 | +[MSVC compiler options](compiler-options.md)\ |
| 55 | +[MSVC compiler command-line syntax](compiler-command-line-syntax.md) |
0 commit comments