Skip to content

Commit fb19437

Browse files
authored
Use os.execv when we only running clang to compile. NFC (#20884)
This saves about 10ms of overhead on my linux machine which is about 10% of the overall overhead or emcc.py over base clang. It will also save on memory since python no longer needs to be resident at the same time as clang.
1 parent 1852e20 commit fb19437

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

emcc.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,15 @@ def get_clang_output_extension(state):
934934
return '.o'
935935

936936

937+
def exec_subprocess_and_exit(cmd):
938+
if utils.WINDOWS:
939+
shared.check_call(cmd)
940+
sys.exit(0)
941+
else:
942+
shared.print_compiler_stage(cmd)
943+
os.execv(cmd[0], cmd)
944+
945+
937946
@ToolchainProfiler.profile_block('compile inputs')
938947
def phase_compile_inputs(options, state, newargs, input_files):
939948
if shared.run_via_emxx:
@@ -982,8 +991,7 @@ def get_clang_command_asm():
982991
# output the dependency rule. Warning: clang and gcc behave differently
983992
# with -MF! (clang seems to not recognize it)
984993
logger.debug(('just preprocessor ' if state.has_dash_E else 'just dependencies: ') + ' '.join(cmd))
985-
shared.check_call(cmd)
986-
sys.exit(0)
994+
exec_subprocess_and_exit(cmd)
987995

988996
# Precompiled headers support
989997
if state.mode == Mode.PCH:
@@ -995,8 +1003,7 @@ def get_clang_command_asm():
9951003
if options.output_file:
9961004
cmd += ['-o', options.output_file]
9971005
logger.debug(f"running (for precompiled headers): {cmd[0]} {' '.join(cmd[1:])}")
998-
shared.check_call(cmd)
999-
sys.exit(0)
1006+
exec_subprocess_and_exit(cmd)
10001007

10011008
if state.mode == Mode.COMPILE_ONLY:
10021009
inputs = [i[1] for i in input_files]
@@ -1009,13 +1016,19 @@ def get_clang_command_asm():
10091016
if get_file_suffix(options.output_file) == '.bc' and not settings.LTO and '-emit-llvm' not in state.orig_args:
10101017
diagnostics.warning('emcc', '.bc output file suffix used without -flto or -emit-llvm. Consider using .o extension since emcc will output an object file, not a bitcode file')
10111018
ext = get_clang_output_extension(state)
1012-
shared.check_call(cmd)
10131019
if not options.output_file and options.default_object_extension != ext:
1020+
# If we are using a non-standard output file extention we cannot use
1021+
# exec_subprocess_and_exit here since we need to rename the files
1022+
# after clang runs (since clang does not support --default-obj-ext)
1023+
# TODO: Remove '--default-obj-ext' to reduce this complexity
1024+
shared.check_call(cmd)
10141025
for i in inputs:
10151026
output = unsuffixed_basename(i) + ext
10161027
new_output = unsuffixed_basename(i) + options.default_object_extension
10171028
shutil.move(output, new_output)
1018-
sys.exit(0)
1029+
sys.exit(0)
1030+
else:
1031+
exec_subprocess_and_exit(cmd)
10191032

10201033
# In COMPILE_AND_LINK we need to compile source files too, but we also need to
10211034
# filter out the link flags

0 commit comments

Comments
 (0)