/LTCG (Link-time Code Generation)
Use /LTCG to perform whole-program optimization, or to create profile-guided optimization (PGO) instrumentation, perform training, and create profile-guided optimized builds.
These options are deprecated starting in Visual Studio 2015:
Specifies that the linker only applies whole program optimization or link-time code generation (LTCG) to the set of files affected by an edit, instead of the entire project. By default, this flag is not set when /LTCG is specified, and the entire project is linked by using whole program optimization.
NOSTATUS | STATUS (optional)
Specifies whether the linker displays a progress indicator that shows what percentage of the link is complete. By default, this status information is not displayed.
Disables link-time code generation. This behavior is the same as when /LTCG is not specified on the command line.
This option is deprecated starting in Visual Studio 2015. Instead, use /LTCG and /GENPROFILE or /FASTGENPROFILE to generate an instrumented build for profile-guided optimization. The data that is collected from instrumented runs is used to create an optimized image. For more information, see Profile Guided Optimization. The short form of this option is /LTCG:PGI.
This option is deprecated starting in Visual Studio 2015. Instead, use /LTCG and /USEPROFILE to build an optimized image. For more information, see Profile Guided Optimization. The short form of this option is /LTCG:PGO.
This option is deprecated starting in Visual Studio 2015. Instead, use /LTCG and /USEPROFILE to rebuild an optimized image. For more information, see Profile Guided Optimization. The short form of this option is /LTCG:PGU.
The /LTCG option tells the linker to call the compiler and perform whole-program optimization. You can also do profile guided optimization. For more information, see Profile Guided Optimization.
With the following exceptions, you cannot add linker options to the PGO combination of /LTCG and /USEPROFILE that were not specified in the previous PGO initialization combination of /LTCG and /GENPROFILE options:
Any linker options that are specified together with the /LTCG and /GENPROFILE options to initialize PGO do not have to be specified when you build by using /LTCG and /USEPROFILE; they are implied.
The rest of this article discusses /LTCG in terms of link-time code generation.
/LTCG is implied with /GL.
The linker invokes link-time code generation if it is passed a module that was compiled by using /GL or an MSIL module (see .netmodule Files as Linker Input). If you do not explicitly specify /LTCG when you pass /GL or MSIL modules to the linker, the linker eventually detects this and restarts the link by using /LTCG. Explicitly specify /LTCG when you pass /GL and MSIL modules to the linker for the fastest possible build performance.
For even faster performance, use /LTCG:INCREMENTAL. This option tells the linker to only re-optimize the set of files that is affected by a source file change, instead of the entire project. This can significantly reduce the link time required. This is not the same option as incremental linking.
/LTCG is not valid for use with /INCREMENTAL.
Interprocedural register allocation (64-bit operating systems only)
Custom calling convention (x86 only)
Small TLS displacement (x86 only)
Stack double alignment (x86 only)
Improved memory disambiguation (better interference information for global variables and input parameters)
The linker determines which optimizations were used to compile each function and applies the same optimizations at link time.
Using /LTCG and /Ogt causes double-alignment optimization.
If /LTCG and /Ogs are specified, double alignment is not performed. If most of the functions in an application are compiled for speed, with a few functions compiled for size (for example, by using the optimize pragma), the compiler double-aligns the functions that are optimized for size if they call functions that require double alignment.
If the compiler can identify all of the call sites of a function, the compiler ignores explicit calling-convention modifiers on a function and tries to optimize the function's calling convention:
pass parameters in registers
reorder parameters for alignment
remove unused parameters
If a function is called through a function pointer, or if a function is called from outside a module that is compiled by using /GL, the compiler does not attempt to optimize the function's calling convention.
If you use /LTCG and redefine
mainCRTStartup, your application can have unpredictable behavior that relates to user code that executes before global objects are initialized. There are three ways to address this issue: do not redefine
mainCRTStartup, do not compile the file that contains
mainCRTStartup by using /LTCG, or initialize global variables and objects statically.
/LTCG and MSIL Modules
/LTCG can accept native object files, and mixed native/managed object files (compiled by using /clr). The /clr:pure and /clr:safe compiler options are deprecated in Visual Studio 2015.
/LTCG:PGI does not accept native modules compiled by using /GL and /clr
To set this compiler option in the Visual Studio development environment
Open the project Property Pages dialog box. See Working with Project Properties.
Select the Configuration Properties > General property page.
Modify the Whole Program Optimization property.
You can also apply /LTCG to specific builds by choosing Build > Profile Guided Optimization on the menu bar, or by choosing one of the Profile Guided Optimization options on the shortcut menu for the project.