Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a6e9987

Browse filesBrowse files
StefanStojanovicaduh95
authored andcommitted
build,win: enable x64 PGO
PR-URL: #62761 Refs: #61964 Reviewed-By: Xuguang Mei <meixuguang@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
1 parent 8146a97 commit a6e9987
Copy full SHA for a6e9987

9 files changed

+357-30Lines changed: 357 additions & 30 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎common.gypi‎

Copy file name to clipboardExpand all lines: common.gypi
+60Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
'msvs_multi_core_compile': '0', # we do enable multicore compiles, but not using the V8 way
1313
'enable_pgo_generate%': '0',
1414
'enable_pgo_use%': '0',
15+
'clang_profile_lib%': '',
1516
'python%': 'python',
1617

1718
'node_shared%': 'false',
@@ -243,6 +244,65 @@
243244
},],
244245
],
245246
},],
247+
['OS=="win"', {
248+
'conditions': [
249+
['enable_lto=="true"', {
250+
'msvs_settings': {
251+
'VCCLCompilerTool': {
252+
'AdditionalOptions': ['-flto=full'],
253+
},
254+
'VCLibrarianTool': {
255+
'AdditionalOptions': ['-flto=full'],
256+
},
257+
'VCLinkerTool': {
258+
'AdditionalOptions': ['-flto=full'],
259+
},
260+
},
261+
},],
262+
['enable_thin_lto=="true"', {
263+
'msvs_settings': {
264+
'VCCLCompilerTool': {
265+
'AdditionalOptions': ['-flto=thin'],
266+
},
267+
'VCLibrarianTool': {
268+
'AdditionalOptions': ['-flto=thin'],
269+
},
270+
'VCLinkerTool': {
271+
'AdditionalOptions': ['-flto=thin'],
272+
},
273+
},
274+
},],
275+
],
276+
'target_conditions': [
277+
['_toolset=="target"', {
278+
'conditions': [
279+
['enable_pgo_generate=="true"', {
280+
'msvs_settings': {
281+
'VCCLCompilerTool': {
282+
'AdditionalOptions': ['-fprofile-generate'],
283+
},
284+
'VCLinkerTool': {
285+
'AdditionalOptions': [
286+
'/NODEFAULTLIB:clang_rt.profile.lib',
287+
'"<(clang_profile_lib)"',
288+
],
289+
},
290+
},
291+
},],
292+
['enable_pgo_use=="true"', {
293+
'msvs_settings': {
294+
'VCCLCompilerTool': {
295+
'AdditionalOptions': ['-fprofile-use=$(SolutionDir)node.profdata'],
296+
},
297+
'VCLinkerTool': {
298+
'AdditionalOptions': ['-fprofile-use=$(SolutionDir)node.profdata'],
299+
},
300+
},
301+
},],
302+
],
303+
},],
304+
],
305+
},],
246306
['OS == "android"', {
247307
'cflags': [ '-fPIC', '-I<(android_ndk_path)/sources/android/cpufeatures' ],
248308
'ldflags': [ '-fPIC' ]
Collapse file

‎configure.py‎

Copy file name to clipboardExpand all lines: configure.py
+57-14Lines changed: 57 additions & 14 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",
@@ -218,6 +218,13 @@
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+
221228
parser.add_argument("--link-module",
222229
action="append",
223230
dest="linked_module",
@@ -925,7 +932,8 @@
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

930938
parser.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
Collapse file

‎deps/openssl/openssl-cli.gypi‎

Copy file name to clipboardExpand all lines: deps/openssl/openssl-cli.gypi
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,15 @@
2525
['enable_lto=="true"', {
2626
'ldflags': [ '-fno-lto' ],
2727
}],
28+
['node_with_ltcg=="true" or enable_lto=="true" or enable_thin_lto=="true"', {
29+
'msvs_settings': {
30+
'VCCLCompilerTool': {
31+
'AdditionalOptions': ['-fno-lto'],
32+
},
33+
'VCLinkerTool': {
34+
'AdditionalOptions': ['-fno-lto'],
35+
},
36+
},
37+
}],
2838
],
2939
}
Collapse file

‎deps/openssl/openssl.gyp‎

Copy file name to clipboardExpand all lines: deps/openssl/openssl.gyp
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,16 @@
7777
['enable_lto=="true"', {
7878
'ldflags': [ '-fno-lto' ],
7979
}],
80+
['node_with_ltcg=="true" or enable_lto=="true" or enable_thin_lto=="true"', {
81+
'msvs_settings': {
82+
'VCCLCompilerTool': {
83+
'AdditionalOptions': ['-fno-lto'],
84+
},
85+
'VCLinkerTool': {
86+
'AdditionalOptions': ['-fno-lto'],
87+
},
88+
},
89+
}],
8090
]
8191
}, {
8292
# openssl-fipsmodule target
Collapse file

‎node.gyp‎

Copy file name to clipboardExpand all lines: node.gyp
+65-15Lines changed: 65 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -730,35 +730,34 @@
730730
'Ws2_32.lib',
731731
],
732732
}],
733+
# Thin LTO for node_main.cc and linker (scoped to node_exe)
733734
['node_with_ltcg=="true"', {
734735
'msvs_settings': {
735736
'VCCLCompilerTool': {
736-
'WholeProgramOptimization': 'true' # /GL, whole program optimization, needed for LTCG
737+
'AdditionalOptions': ['-flto=thin'],
737738
},
738-
'VCLibrarianTool': {
739-
'AdditionalOptions': [
740-
'/LTCG:INCREMENTAL', # link time code generation
741-
],
739+
'VCLinkerTool': {
740+
'AdditionalOptions': ['-flto=thin'],
742741
},
742+
},
743+
}],
744+
# Whole-program optimization: either Thin LTO or PGO
745+
['node_with_ltcg=="true" or enable_lto=="true" or enable_thin_lto=="true" or enable_pgo_generate=="true" or enable_pgo_use=="true"', {
746+
'msvs_settings': {
743747
'VCLinkerTool': {
744748
'OptimizeReferences': 2, # /OPT:REF
745749
'EnableCOMDATFolding': 2, # /OPT:ICF
746750
'LinkIncremental': 1, # disable incremental linking
747-
'AdditionalOptions': [
748-
'/LTCG:INCREMENTAL', # incremental link-time code generation
749-
],
750-
}
751-
}
751+
},
752+
},
752753
}, {
754+
# No whole-program optimization
753755
'msvs_settings': {
754-
'VCCLCompilerTool': {
755-
'WholeProgramOptimization': 'false'
756-
},
757756
'VCLinkerTool': {
758-
'LinkIncremental': 2 # enable incremental linking
757+
'LinkIncremental': 2, # enable incremental linking
759758
},
760759
},
761-
}],
760+
}],
762761
['node_use_node_snapshot=="true"', {
763762
'dependencies': [
764763
'node_mksnapshot',
@@ -1139,6 +1138,17 @@
11391138
[ 'debug_nghttp2==1', {
11401139
'defines': [ 'NODE_DEBUG_NGHTTP2=1' ]
11411140
}],
1141+
# Thin LTO for node sources (scoped to libnode, not global)
1142+
['node_with_ltcg=="true"', {
1143+
'msvs_settings': {
1144+
'VCCLCompilerTool': {
1145+
'AdditionalOptions': ['-flto=thin'],
1146+
},
1147+
'VCLibrarianTool': {
1148+
'AdditionalOptions': ['-flto=thin'],
1149+
},
1150+
},
1151+
}],
11421152
],
11431153
'actions': [
11441154
{
@@ -1439,6 +1449,16 @@
14391449
['enable_lto=="true"', {
14401450
'ldflags': [ '-fno-lto' ],
14411451
}],
1452+
['node_with_ltcg=="true" or enable_lto=="true" or enable_thin_lto=="true"', {
1453+
'msvs_settings': {
1454+
'VCCLCompilerTool': {
1455+
'AdditionalOptions': ['-fno-lto'],
1456+
},
1457+
'VCLinkerTool': {
1458+
'AdditionalOptions': ['-fno-lto'],
1459+
},
1460+
},
1461+
}],
14421462
],
14431463
}, # cctest
14441464

@@ -1503,6 +1523,16 @@
15031523
['enable_lto=="true"', {
15041524
'ldflags': [ '-fno-lto' ],
15051525
}],
1526+
['node_with_ltcg=="true" or enable_lto=="true" or enable_thin_lto=="true"', {
1527+
'msvs_settings': {
1528+
'VCCLCompilerTool': {
1529+
'AdditionalOptions': ['-fno-lto'],
1530+
},
1531+
'VCLinkerTool': {
1532+
'AdditionalOptions': ['-fno-lto'],
1533+
},
1534+
},
1535+
}],
15061536
],
15071537
}, # embedtest
15081538

@@ -1580,6 +1610,16 @@
15801610
['enable_lto=="true"', {
15811611
'ldflags': [ '-fno-lto' ],
15821612
}],
1613+
['node_with_ltcg=="true" or enable_lto=="true" or enable_thin_lto=="true"', {
1614+
'msvs_settings': {
1615+
'VCCLCompilerTool': {
1616+
'AdditionalOptions': ['-fno-lto'],
1617+
},
1618+
'VCLinkerTool': {
1619+
'AdditionalOptions': ['-fno-lto'],
1620+
},
1621+
},
1622+
}],
15831623
]
15841624
}, # overlapped-checker
15851625
{
@@ -1706,6 +1746,16 @@
17061746
['enable_lto=="true"', {
17071747
'ldflags': [ '-fno-lto' ],
17081748
}],
1749+
['node_with_ltcg=="true" or enable_lto=="true" or enable_thin_lto=="true"', {
1750+
'msvs_settings': {
1751+
'VCCLCompilerTool': {
1752+
'AdditionalOptions': ['-fno-lto'],
1753+
},
1754+
'VCLinkerTool': {
1755+
'AdditionalOptions': ['-fno-lto'],
1756+
},
1757+
},
1758+
}],
17091759
],
17101760
}, # node_mksnapshot
17111761
], # end targets

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.