Skip to content

Commit 180099a

Browse files
Octavian Soldeatargos
Octavian Soldea
authored andcommitted
build: enabling pgo at configure
This modification allows for compiling with profiled guided optimization (pgo) using the flags --enable-pgo-generate and --enable-pgo-use. Refs: #21583 Refs: #1409 PR-URL: #21596 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Denys Otrishko <[email protected]>
1 parent 8191bee commit 180099a

File tree

2 files changed

+61
-10
lines changed

2 files changed

+61
-10
lines changed

common.gypi

+10
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,19 @@
179179
}],
180180
['OS=="linux"', {
181181
'variables': {
182+
'pgo_generate': ' -fprofile-generate ',
183+
'pgo_use': ' -fprofile-use -fprofile-correction ',
182184
'lto': ' -flto=4 -fuse-linker-plugin -ffat-lto-objects ',
183185
},
184186
'conditions': [
187+
['enable_pgo_generate=="true"', {
188+
'cflags': ['<(pgo_generate)'],
189+
'ldflags': ['<(pgo_generate)'],
190+
},],
191+
['enable_pgo_use=="true"', {
192+
'cflags': ['<(pgo_use)'],
193+
'ldflags': ['<(pgo_use)'],
194+
},],
185195
['enable_lto=="true"', {
186196
'cflags': ['<(lto)'],
187197
'ldflags': ['<(lto)'],

configure.py

+51-10
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,23 @@
132132
"JavaScript code executed in nodejs. This feature is only available "
133133
"for x32, x86, and x64 architectures.")
134134

135+
parser.add_option("--enable-pgo-generate",
136+
action="store_true",
137+
dest="enable_pgo_generate",
138+
help="Enable profiling with pgo of a binary. This feature is only available "
139+
"on linux with gcc and g++ 5.4.1 or newer.")
140+
141+
parser.add_option("--enable-pgo-use",
142+
action="store_true",
143+
dest="enable_pgo_use",
144+
help="Enable use of the profile generated with --enable-pgo-generate. This "
145+
"feature is only available on linux with gcc and g++ 5.4.1 or newer.")
146+
135147
parser.add_option("--enable-lto",
136148
action="store_true",
137149
dest="enable_lto",
138150
help="Enable compiling with lto of a binary. This feature is only available "
139-
"on linux with gcc and g++.")
151+
"on linux with gcc and g++ 5.4.1 or newer.")
140152

141153
parser.add_option("--link-module",
142154
action="append",
@@ -887,6 +899,16 @@ def configure_mips(o):
887899
o['variables']['mips_fpu_mode'] = options.mips_fpu_mode
888900

889901

902+
def gcc_version_ge(version_checked):
903+
for compiler in [(CC, 'c'), (CXX, 'c++')]:
904+
ok, is_clang, clang_version, compiler_version = \
905+
try_check_compiler(compiler[0], compiler[1])
906+
compiler_version_num = tuple(map(int, compiler_version))
907+
if is_clang or compiler_version_num < version_checked:
908+
return False
909+
return True
910+
911+
890912
def configure_node(o):
891913
if options.dest_os == 'android':
892914
o['variables']['OS'] = 'android'
@@ -931,22 +953,41 @@ def configure_node(o):
931953
else:
932954
o['variables']['node_enable_v8_vtunejit'] = 'false'
933955

956+
if flavor != 'linux' and (options.enable_pgo_generate or options.enable_pgo_use):
957+
raise Exception(
958+
'The pgo option is supported only on linux.')
959+
960+
if flavor == 'linux':
961+
if options.enable_pgo_generate or options.enable_pgo_use:
962+
version_checked = (5, 4, 1)
963+
if not gcc_version_ge(version_checked):
964+
version_checked_str = ".".join(map(str, version_checked))
965+
raise Exception(
966+
'The options --enable-pgo-generate and --enable-pgo-use '
967+
'are supported for gcc and gxx %s or newer only.' % (version_checked_str))
968+
969+
if options.enable_pgo_generate and options.enable_pgo_use:
970+
raise Exception(
971+
'Only one of the --enable-pgo-generate or --enable-pgo-use options '
972+
'can be specified at a time. You would like to use '
973+
'--enable-pgo-generate first, profile node, and then recompile '
974+
'with --enable-pgo-use')
975+
976+
o['variables']['enable_pgo_generate'] = b(options.enable_pgo_generate)
977+
o['variables']['enable_pgo_use'] = b(options.enable_pgo_use)
978+
934979
if flavor != 'linux' and (options.enable_lto):
935980
raise Exception(
936981
'The lto option is supported only on linux.')
937982

938983
if flavor == 'linux':
939984
if options.enable_lto:
940985
version_checked = (5, 4, 1)
941-
for compiler in [(CC, 'c'), (CXX, 'c++')]:
942-
ok, is_clang, clang_version, compiler_version = \
943-
try_check_compiler(compiler[0], compiler[1])
944-
compiler_version_num = tuple(map(int, compiler_version))
945-
if is_clang or compiler_version_num < version_checked:
946-
version_checked_str = ".".join(map(str, version_checked))
947-
raise Exception(
948-
'The option --enable-lto is supported for gcc and gxx %s'
949-
' or newer only.' % (version_checked_str))
986+
if not gcc_version_ge(version_checked):
987+
version_checked_str = ".".join(map(str, version_checked))
988+
raise Exception(
989+
'The option --enable-lto is supported for gcc and gxx %s'
990+
' or newer only.' % (version_checked_str))
950991

951992
o['variables']['enable_lto'] = b(options.enable_lto)
952993

0 commit comments

Comments
 (0)