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' ,
@@ -1920,9 +1928,9 @@ def configure_node(o):
19201928 else :
19211929 o ['variables' ]['node_enable_v8_vtunejit' ] = 'false'
19221930
1923- if flavor != 'linux' and (options .enable_pgo_generate or options .enable_pgo_use ):
1931+ if ( flavor != 'linux' and flavor != 'win' ) and (options .enable_pgo_generate or options .enable_pgo_use ):
19241932 raise Exception (
1925- 'The pgo option is supported only on linux.' )
1933+ 'The pgo option is supported only on linux and windows .' )
19261934
19271935 if flavor == 'linux' :
19281936 if options .enable_pgo_generate or options .enable_pgo_use :
@@ -1933,21 +1941,55 @@ def configure_node(o):
19331941 'The options --enable-pgo-generate and --enable-pgo-use '
19341942 f'are supported for gcc and gxx { version_checked_str } or newer only.' )
19351943
1936- if options .enable_pgo_generate and options .enable_pgo_use :
1937- raise Exception (
1938- 'Only one of the --enable-pgo-generate or --enable-pgo-use options '
1939- 'can be specified at a time. You would like to use '
1940- '--enable-pgo-generate first, profile node, and then recompile '
1941- 'with --enable-pgo-use' )
1944+ if options .enable_pgo_generate and options .enable_pgo_use :
1945+ raise Exception (
1946+ 'Only one of the --enable-pgo-generate or --enable-pgo-use options '
1947+ 'can be specified at a time. You would like to use '
1948+ '--enable-pgo-generate first, profile node, and then recompile '
1949+ 'with --enable-pgo-use' )
19421950
19431951 o ['variables' ]['enable_pgo_generate' ] = b (options .enable_pgo_generate )
19441952 o ['variables' ]['enable_pgo_use' ] = b (options .enable_pgo_use )
19451953
1946- if flavor == 'win' and (options .enable_lto ):
1954+ if flavor == 'win' and (options .enable_pgo_generate or options .enable_pgo_use ):
1955+ lib_suffix = 'aarch64' if target_arch == 'arm64' else 'x86_64'
1956+ lib_name = f'clang_rt.profile-{ lib_suffix } .lib'
1957+ msvc_dir = target_arch # 'x64' or 'arm64'
1958+
1959+ vc_tools_dir = os .environ .get ('VCToolsInstallDir' , '' )
1960+ if vc_tools_dir :
1961+ clang_profile_lib = os .path .join (vc_tools_dir , 'lib' , msvc_dir , lib_name )
1962+ if os .path .isfile (clang_profile_lib ):
1963+ o ['variables' ]['clang_profile_lib' ] = clang_profile_lib
1964+ else :
1965+ raise Exception (
1966+ f'PGO profile runtime library not found at { clang_profile_lib } . '
1967+ 'Ensure the ClangCL toolset is installed.' )
1968+ else :
1969+ raise Exception (
1970+ 'VCToolsInstallDir not set. Run from a Visual Studio command prompt.' )
1971+
1972+ if flavor != 'win' and options .enable_thin_lto :
19471973 raise Exception (
1948- 'Use Link Time Code Generation instead.' )
1974+ 'Use --enable-lto instead.' )
1975+
1976+ # LTO mutual exclusion
1977+ if flavor == 'win' :
1978+ lto_options = []
1979+ if options .enable_lto :
1980+ lto_options .append ('--enable-lto' )
1981+ if options .enable_thin_lto :
1982+ lto_options .append ('--enable-thin-lto' )
1983+ if options .with_ltcg :
1984+ lto_options .append ('--with-ltcg' )
1985+ if len (lto_options ) > 1 :
1986+ raise Exception (
1987+ f'Only one LTO option can be specified at a time: { ", " .join (lto_options )} . '
1988+ 'Use --enable-lto for Full LTO (global), '
1989+ '--enable-thin-lto for Thin LTO (global), '
1990+ 'or --with-ltcg for Thin LTO (scoped to node.exe and libnode).' )
19491991
1950- if options .enable_lto :
1992+ if options .enable_lto and flavor != 'win' :
19511993 gcc_version_checked = (5 , 4 , 1 )
19521994 clang_version_checked = (3 , 9 , 1 )
19531995 if not gcc_version_ge (gcc_version_checked ) and not clang_version_ge (clang_version_checked ):
@@ -1958,6 +2000,7 @@ def configure_node(o):
19582000 f'or clang { clang_version_checked_str } + only.' )
19592001
19602002 o ['variables' ]['enable_lto' ] = b (options .enable_lto )
2003+ o ['variables' ]['enable_thin_lto' ] = b (options .enable_thin_lto )
19612004
19622005 if options .node_use_large_pages or options .node_use_large_pages_script_lld :
19632006 warn ('''The `--use-largepages` and `--use-largepages-script-lld` options
0 commit comments