Skip to content

Commit 9be1555

Browse files
Octavian SoldeaGabriel Schulhof
Octavian Soldea
authored and
Gabriel Schulhof
committed
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 fdf829e commit 9be1555

File tree

2 files changed

+61
-10
lines changed

2 files changed

+61
-10
lines changed

common.gypi

Lines changed: 10 additions & 0 deletions
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

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,23 @@ parser.add_option("--enable-vtune-profiling",
157157
"JavaScript code executed in nodejs. This feature is only available "
158158
"for x32, x86, and x64 architectures.")
159159

160+
parser.add_option("--enable-pgo-generate",
161+
action="store_true",
162+
dest="enable_pgo_generate",
163+
help="Enable profiling with pgo of a binary. This feature is only available "
164+
"on linux with gcc and g++ 5.4.1 or newer.")
165+
166+
parser.add_option("--enable-pgo-use",
167+
action="store_true",
168+
dest="enable_pgo_use",
169+
help="Enable use of the profile generated with --enable-pgo-generate. This "
170+
"feature is only available on linux with gcc and g++ 5.4.1 or newer.")
171+
160172
parser.add_option("--enable-lto",
161173
action="store_true",
162174
dest="enable_lto",
163175
help="Enable compiling with lto of a binary. This feature is only available "
164-
"on linux with gcc and g++.")
176+
"on linux with gcc and g++ 5.4.1 or newer.")
165177

166178
parser.add_option("--link-module",
167179
action="append",
@@ -898,6 +910,16 @@ def configure_mips(o):
898910
o['variables']['mips_fpu_mode'] = options.mips_fpu_mode
899911

900912

913+
def gcc_version_ge(version_checked):
914+
for compiler in [(CC, 'c'), (CXX, 'c++')]:
915+
ok, is_clang, clang_version, compiler_version = \
916+
try_check_compiler(compiler[0], compiler[1])
917+
compiler_version_num = tuple(map(int, compiler_version))
918+
if is_clang or compiler_version_num < version_checked:
919+
return False
920+
return True
921+
922+
901923
def configure_node(o):
902924
if options.dest_os == 'android':
903925
o['variables']['OS'] = 'android'
@@ -942,22 +964,41 @@ def configure_node(o):
942964
else:
943965
o['variables']['node_enable_v8_vtunejit'] = 'false'
944966

967+
if flavor != 'linux' and (options.enable_pgo_generate or options.enable_pgo_use):
968+
raise Exception(
969+
'The pgo option is supported only on linux.')
970+
971+
if flavor == 'linux':
972+
if options.enable_pgo_generate or options.enable_pgo_use:
973+
version_checked = (5, 4, 1)
974+
if not gcc_version_ge(version_checked):
975+
version_checked_str = ".".join(map(str, version_checked))
976+
raise Exception(
977+
'The options --enable-pgo-generate and --enable-pgo-use '
978+
'are supported for gcc and gxx %s or newer only.' % (version_checked_str))
979+
980+
if options.enable_pgo_generate and options.enable_pgo_use:
981+
raise Exception(
982+
'Only one of the --enable-pgo-generate or --enable-pgo-use options '
983+
'can be specified at a time. You would like to use '
984+
'--enable-pgo-generate first, profile node, and then recompile '
985+
'with --enable-pgo-use')
986+
987+
o['variables']['enable_pgo_generate'] = b(options.enable_pgo_generate)
988+
o['variables']['enable_pgo_use'] = b(options.enable_pgo_use)
989+
945990
if flavor != 'linux' and (options.enable_lto):
946991
raise Exception(
947992
'The lto option is supported only on linux.')
948993

949994
if flavor == 'linux':
950995
if options.enable_lto:
951996
version_checked = (5, 4, 1)
952-
for compiler in [(CC, 'c'), (CXX, 'c++')]:
953-
ok, is_clang, clang_version, compiler_version = \
954-
try_check_compiler(compiler[0], compiler[1])
955-
compiler_version_num = tuple(map(int, compiler_version))
956-
if is_clang or compiler_version_num < version_checked:
957-
version_checked_str = ".".join(map(str, version_checked))
958-
raise Exception(
959-
'The option --enable-lto is supported for gcc and gxx %s'
960-
' or newer only.' % (version_checked_str))
997+
if not gcc_version_ge(version_checked):
998+
version_checked_str = ".".join(map(str, version_checked))
999+
raise Exception(
1000+
'The option --enable-lto is supported for gcc and gxx %s'
1001+
' or newer only.' % (version_checked_str))
9611002

9621003
o['variables']['enable_lto'] = b(options.enable_lto)
9631004

0 commit comments

Comments
 (0)