202202 dest = "enable_pgo_generate" ,
203203 default = None ,
204204 help = "Enable profiling with pgo of a binary. This feature is only available "
205- "on linux with gcc and g++ 5.4.1 or newer." )
205+ "on linux with gcc and g++ 5.4.1 or newer and on windows ." )
206206
207207parser .add_argument ("--enable-pgo-use" ,
208208 action = "store_true" ,
209209 dest = "enable_pgo_use" ,
210210 default = None ,
211211 help = "Enable use of the profile generated with --enable-pgo-generate. This "
212- "feature is only available on linux with gcc and g++ 5.4.1 or newer." )
212+ "feature is only available on linux with gcc and g++ 5.4.1 or newer and on windows ." )
213213
214214parser .add_argument ("--enable-lto" ,
215215 action = "store_true" ,
218218 help = "Enable compiling with lto of a binary. This feature is only available "
219219 "with gcc 5.4.1+ or clang 3.9.1+." )
220220
221+ parser .add_argument ("--enable-thin-lto" ,
222+ action = "store_true" ,
223+ dest = "enable_thin_lto" ,
224+ default = None ,
225+ help = "Enable compiling with thin lto of a binary. This feature is only available "
226+ "on windows." )
227+
221228parser .add_argument ("--link-module" ,
222229 action = "append" ,
223230 dest = "linked_module" ,
925932 action = 'store_true' ,
926933 dest = 'with_ltcg' ,
927934 default = None ,
928- help = 'Use Link Time Code Generation. This feature is only available on Windows.' )
935+ help = 'Use Thin LTO scoped to node.exe and libnode only. '
936+ 'This feature is only available on Windows.' )
929937
930938parser .add_argument ('--write-snapshot-as-array-literals' ,
931939 action = 'store_true' ,
@@ -1916,9 +1924,9 @@ def configure_node(o):
19161924 else :
19171925 o ['variables' ]['node_enable_v8_vtunejit' ] = 'false'
19181926
1919- if flavor != 'linux' and (options .enable_pgo_generate or options .enable_pgo_use ):
1927+ if ( flavor != 'linux' and flavor != 'win' ) and (options .enable_pgo_generate or options .enable_pgo_use ):
19201928 raise Exception (
1921- 'The pgo option is supported only on linux.' )
1929+ 'The pgo option is supported only on linux and windows .' )
19221930
19231931 if flavor == 'linux' :
19241932 if options .enable_pgo_generate or options .enable_pgo_use :
@@ -1929,21 +1937,55 @@ def configure_node(o):
19291937 'The options --enable-pgo-generate and --enable-pgo-use '
19301938 f'are supported for gcc and gxx { version_checked_str } or newer only.' )
19311939
1932- if options .enable_pgo_generate and options .enable_pgo_use :
1933- raise Exception (
1934- 'Only one of the --enable-pgo-generate or --enable-pgo-use options '
1935- 'can be specified at a time. You would like to use '
1936- '--enable-pgo-generate first, profile node, and then recompile '
1937- 'with --enable-pgo-use' )
1940+ if options .enable_pgo_generate and options .enable_pgo_use :
1941+ raise Exception (
1942+ 'Only one of the --enable-pgo-generate or --enable-pgo-use options '
1943+ 'can be specified at a time. You would like to use '
1944+ '--enable-pgo-generate first, profile node, and then recompile '
1945+ 'with --enable-pgo-use' )
19381946
19391947 o ['variables' ]['enable_pgo_generate' ] = b (options .enable_pgo_generate )
19401948 o ['variables' ]['enable_pgo_use' ] = b (options .enable_pgo_use )
19411949
1942- if flavor == 'win' and (options .enable_lto ):
1950+ if flavor == 'win' and (options .enable_pgo_generate or options .enable_pgo_use ):
1951+ lib_suffix = 'aarch64' if target_arch == 'arm64' else 'x86_64'
1952+ lib_name = f'clang_rt.profile-{ lib_suffix } .lib'
1953+ msvc_dir = target_arch # 'x64' or 'arm64'
1954+
1955+ vc_tools_dir = os .environ .get ('VCToolsInstallDir' , '' )
1956+ if vc_tools_dir :
1957+ clang_profile_lib = os .path .join (vc_tools_dir , 'lib' , msvc_dir , lib_name )
1958+ if os .path .isfile (clang_profile_lib ):
1959+ o ['variables' ]['clang_profile_lib' ] = clang_profile_lib
1960+ else :
1961+ raise Exception (
1962+ f'PGO profile runtime library not found at { clang_profile_lib } . '
1963+ 'Ensure the ClangCL toolset is installed.' )
1964+ else :
1965+ raise Exception (
1966+ 'VCToolsInstallDir not set. Run from a Visual Studio command prompt.' )
1967+
1968+ if flavor != 'win' and options .enable_thin_lto :
19431969 raise Exception (
1944- 'Use Link Time Code Generation instead.' )
1970+ 'Use --enable-lto instead.' )
1971+
1972+ # LTO mutual exclusion
1973+ if flavor == 'win' :
1974+ lto_options = []
1975+ if options .enable_lto :
1976+ lto_options .append ('--enable-lto' )
1977+ if options .enable_thin_lto :
1978+ lto_options .append ('--enable-thin-lto' )
1979+ if options .with_ltcg :
1980+ lto_options .append ('--with-ltcg' )
1981+ if len (lto_options ) > 1 :
1982+ raise Exception (
1983+ f'Only one LTO option can be specified at a time: { ", " .join (lto_options )} . '
1984+ 'Use --enable-lto for Full LTO (global), '
1985+ '--enable-thin-lto for Thin LTO (global), '
1986+ 'or --with-ltcg for Thin LTO (scoped to node.exe and libnode).' )
19451987
1946- if options .enable_lto :
1988+ if options .enable_lto and flavor != 'win' :
19471989 gcc_version_checked = (5 , 4 , 1 )
19481990 clang_version_checked = (3 , 9 , 1 )
19491991 if not gcc_version_ge (gcc_version_checked ) and not clang_version_ge (clang_version_checked ):
@@ -1954,6 +1996,7 @@ def configure_node(o):
19541996 f'or clang { clang_version_checked_str } + only.' )
19551997
19561998 o ['variables' ]['enable_lto' ] = b (options .enable_lto )
1999+ o ['variables' ]['enable_thin_lto' ] = b (options .enable_thin_lto )
19572000
19582001 if options .node_use_large_pages or options .node_use_large_pages_script_lld :
19592002 warn ('''The `--use-largepages` and `--use-largepages-script-lld` options
0 commit comments