Skip to content

Commit 21eb097

Browse files
build,win: enable x64 PGO
1 parent ed05549 commit 21eb097

4 files changed

Lines changed: 77 additions & 22 deletions

File tree

common.gypi

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,30 @@
242242
},],
243243
],
244244
},],
245+
['OS=="win"', {
246+
'conditions': [
247+
['enable_pgo_generate=="true"', {
248+
'msvs_settings': {
249+
'VCCLCompilerTool': {
250+
'AdditionalOptions': ['-fprofile-generate'],
251+
},
252+
'VCLinkerTool': {
253+
'AdditionalOptions': ['-fprofile-generate'],
254+
},
255+
},
256+
},],
257+
['enable_pgo_use=="true"', {
258+
'msvs_settings': {
259+
'VCCLCompilerTool': {
260+
'AdditionalOptions': ['-fprofile-use=$(SolutionDir)node.profdata'],
261+
},
262+
'VCLinkerTool': {
263+
'AdditionalOptions': ['-fprofile-use=$(SolutionDir)node.profdata'],
264+
},
265+
},
266+
},],
267+
],
268+
},],
245269
['OS == "android"', {
246270
'cflags': [ '-fPIC', '-I<(android_ndk_path)/sources/android/cpufeatures' ],
247271
'ldflags': [ '-fPIC' ]

configure.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -202,14 +202,14 @@
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

207207
parser.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

214214
parser.add_argument("--enable-lto",
215215
action="store_true",
@@ -1909,9 +1909,9 @@ def configure_node(o):
19091909
else:
19101910
o['variables']['node_enable_v8_vtunejit'] = 'false'
19111911

1912-
if flavor != 'linux' and (options.enable_pgo_generate or options.enable_pgo_use):
1912+
if (flavor != 'linux' and flavor != 'win') and (options.enable_pgo_generate or options.enable_pgo_use):
19131913
raise Exception(
1914-
'The pgo option is supported only on linux.')
1914+
'The pgo option is supported only on linux and windows.')
19151915

19161916
if flavor == 'linux':
19171917
if options.enable_pgo_generate or options.enable_pgo_use:
@@ -1922,12 +1922,17 @@ def configure_node(o):
19221922
'The options --enable-pgo-generate and --enable-pgo-use '
19231923
f'are supported for gcc and gxx {version_checked_str} or newer only.')
19241924

1925-
if options.enable_pgo_generate and options.enable_pgo_use:
1926-
raise Exception(
1927-
'Only one of the --enable-pgo-generate or --enable-pgo-use options '
1928-
'can be specified at a time. You would like to use '
1929-
'--enable-pgo-generate first, profile node, and then recompile '
1930-
'with --enable-pgo-use')
1925+
if options.enable_pgo_generate and options.enable_pgo_use:
1926+
raise Exception(
1927+
'Only one of the --enable-pgo-generate or --enable-pgo-use options '
1928+
'can be specified at a time. You would like to use '
1929+
'--enable-pgo-generate first, profile node, and then recompile '
1930+
'with --enable-pgo-use')
1931+
1932+
if flavor == 'win' and options.with_ltcg and (options.enable_pgo_generate or options.enable_pgo_use):
1933+
raise Exception(
1934+
'The --with-ltcg option cannot be used with --enable-pgo-generate or --enable-pgo-use. '
1935+
'PGO uses /LTCG:PGInstrument or /LTCG:PGOptimize while LTCG uses /LTCG:INCREMENTAL.')
19311936

19321937
o['variables']['enable_pgo_generate'] = b(options.enable_pgo_generate)
19331938
o['variables']['enable_pgo_use'] = b(options.enable_pgo_use)

node.gyp

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -730,25 +730,35 @@
730730
'Ws2_32.lib',
731731
],
732732
}],
733-
['node_with_ltcg=="true"', {
733+
# Whole-program optimization: either LTCG or PGO
734+
['node_with_ltcg=="true" or enable_pgo_generate=="true" or enable_pgo_use=="true"', {
734735
'msvs_settings': {
735736
'VCCLCompilerTool': {
736-
'WholeProgramOptimization': 'true' # /GL, whole program optimization, needed for LTCG
737-
},
738-
'VCLibrarianTool': {
739-
'AdditionalOptions': [
740-
'/LTCG:INCREMENTAL', # link time code generation
741-
],
737+
'WholeProgramOptimization': 'true' # /GL, whole program optimization, needed for both LTCG and PGO
742738
},
743739
'VCLinkerTool': {
744740
'OptimizeReferences': 2, # /OPT:REF
745741
'EnableCOMDATFolding': 2, # /OPT:ICF
746742
'LinkIncremental': 1, # disable incremental linking
747-
'AdditionalOptions': [
748-
'/LTCG:INCREMENTAL', # incremental link-time code generation
749-
],
750743
}
751-
}
744+
},
745+
'conditions': [
746+
# LTCG-specific settings (only when PGO not active)
747+
['node_with_ltcg=="true" and enable_pgo_generate!="true" and enable_pgo_use!="true"', {
748+
'msvs_settings': {
749+
'VCLibrarianTool': {
750+
'AdditionalOptions': [
751+
'/LTCG:INCREMENTAL', # link time code generation
752+
],
753+
},
754+
'VCLinkerTool': {
755+
'AdditionalOptions': [
756+
'/LTCG:INCREMENTAL', # incremental link-time code generation
757+
],
758+
},
759+
},
760+
}],
761+
]
752762
}, {
753763
'msvs_settings': {
754764
'VCCLCompilerTool': {

vcbuild.bat

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ set config=Release
2424
set target=Build
2525
set target_arch=x64
2626
set ltcg=
27+
set pgo_generate=
28+
set pgo_use=
2729
set target_env=
2830
set noprojgen=
2931
set projgen=
@@ -104,6 +106,8 @@ if /i "%1"=="sign" set sign=1&goto arg-ok
104106
if /i "%1"=="nosnapshot" set nosnapshot=1&goto arg-ok
105107
if /i "%1"=="nonpm" set nonpm=1&goto arg-ok
106108
if /i "%1"=="ltcg" set ltcg=1&goto arg-ok
109+
if /i "%1"=="pgo-generate" set pgo_generate=1&goto arg-ok
110+
if /i "%1"=="pgo-use" set pgo_use=1&goto arg-ok
107111
if /i "%1"=="v8temporal" set v8temporal=1&goto arg-ok
108112
if /i "%1"=="v8windbg" set v8windbg=1&goto arg-ok
109113
if /i "%1"=="licensertf" set licensertf=1&goto arg-ok
@@ -179,6 +183,14 @@ goto next-arg
179183

180184
:args-done
181185

186+
:: PGO mutual exclusion
187+
if defined pgo_generate if defined pgo_use (
188+
echo Error: Only one of 'pgo-generate' or 'pgo-use' can be specified.
189+
echo pgo-generate : build instrumented binary, then profile it
190+
echo pgo-use : rebuild using the collected profile data
191+
exit /b 1
192+
)
193+
182194
if defined build_release (
183195
set config=Release
184196
set package=1
@@ -212,6 +224,8 @@ if "%config%"=="Debug" set configure_flags=%configure_flags% --debug
212224
if defined nosnapshot set configure_flags=%configure_flags% --without-snapshot
213225
if defined nonpm set configure_flags=%configure_flags% --without-npm
214226
if defined ltcg set configure_flags=%configure_flags% --with-ltcg
227+
if defined pgo_generate set configure_flags=%configure_flags% --enable-pgo-generate
228+
if defined pgo_use set configure_flags=%configure_flags% --enable-pgo-use
215229
if defined release_urlbase set configure_flags=%configure_flags% --release-urlbase=%release_urlbase%
216230
if defined download_arg set configure_flags=%configure_flags% %download_arg%
217231
if defined enable_vtune_arg set configure_flags=%configure_flags% --enable-vtune-profiling
@@ -875,7 +889,7 @@ set exit_code=1
875889
goto exit
876890

877891
:help
878-
echo vcbuild.bat [debug/release] [msi] [doc] [test/test-all/test-addons/test-doc/test-js-native-api/test-node-api/test-internet/test-tick-processor/test-known-issues/test-node-inspect/test-check-deopts/test-npm/test-v8/test-v8-intl/test-v8-benchmarks/test-v8-all] [build-addons/build-js-native-api-tests/build-node-api-tests/build-ffi-tests] [ignore-flaky] [static/dll] [noprojgen] [projgen] [clang-cl] [ccache path-to-ccache] [small-icu/full-icu/without-intl] [nobuild] [nosnapshot] [nonpm] [ltcg] [licensetf] [sign] [x64/arm64] [vs2022/vs2026] [download-all] [enable-vtune] [lint/lint-ci/lint-js/lint-md] [lint-md-build] [format-md] [package] [build-release] [upload] [no-NODE-OPTIONS] [link-module path-to-module] [debug-http2] [debug-nghttp2] [clean] [cctest] [no-cctest] [openssl-no-asm]
892+
echo vcbuild.bat [debug/release] [msi] [doc] [test/test-all/test-addons/test-doc/test-js-native-api/test-node-api/test-internet/test-tick-processor/test-known-issues/test-node-inspect/test-check-deopts/test-npm/test-v8/test-v8-intl/test-v8-benchmarks/test-v8-all] [build-addons/build-js-native-api-tests/build-node-api-tests/build-ffi-tests] [ignore-flaky] [static/dll] [noprojgen] [projgen] [clang-cl] [ccache path-to-ccache] [small-icu/full-icu/without-intl] [nobuild] [nosnapshot] [nonpm] [ltcg] [pgo-generate] [pgo-use] [licensetf] [sign] [x64/arm64] [vs2022/vs2026] [download-all] [enable-vtune] [lint/lint-ci/lint-js/lint-md] [lint-md-build] [format-md] [package] [build-release] [upload] [no-NODE-OPTIONS] [link-module path-to-module] [debug-http2] [debug-nghttp2] [clean] [cctest] [no-cctest] [openssl-no-asm]
879893
echo Examples:
880894
echo vcbuild.bat : builds release build
881895
echo vcbuild.bat debug : builds debug build
@@ -887,6 +901,8 @@ echo vcbuild.bat link-module my_module.js : bundles my_module as built-in modu
887901
echo vcbuild.bat lint : runs the C++, documentation and JavaScript linter
888902
echo vcbuild.bat no-cctest : skip building cctest.exe
889903
echo vcbuild.bat ccache c:\ccache\ : use ccache to speed build
904+
echo vcbuild.bat pgo-generate : builds instrumented binary for PGO (profile first, then rebuild with pgo-use)
905+
echo vcbuild.bat pgo-use : builds optimized binary using PGO profile data
890906
goto exit
891907

892908
:exit

0 commit comments

Comments
 (0)