Skip to content

Commit ea6e135

Browse files
authored
[clang][perf-training] Fix profiling with -DCLANG_BOLT=perf (#119117)
This fixes the llvm-support build that generates the profile data, and wraps the whole `cmake --build` command with perf instead of wrapping each individual clang invocation. This limits the number of profile files generated and reduces the time spent running perf2bolt.
1 parent 602bbf2 commit ea6e135

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

clang/utils/perf-training/bolt.lit.cfg

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ from lit import Test
44
import lit.formats
55
import lit.util
66
import os
7+
import re
78
import subprocess
89

910
clang_bolt_mode = config.clang_bolt_mode.lower()
@@ -20,9 +21,13 @@ elif clang_bolt_mode == "perf":
2021
else:
2122
assert 0, "Unsupported CLANG_BOLT_MODE variable"
2223

23-
config.clang = perf_wrapper + os.path.realpath(
24+
clang_nowrapper = os.path.realpath(
2425
lit.util.which(clang_binary, config.clang_tools_dir)
2526
).replace("\\", "/")
27+
config.clang = perf_wrapper + clang_nowrapper
28+
config.cmake_compiler_args = "-DCMAKE_C_COMPILER='{0}' -DCMAKE_CXX_COMPILER='{0};--driver-mode=g++'".format(
29+
re.sub(r"\s+", ";", clang_nowrapper)
30+
)
2631

2732
config.name = "Clang Perf Training"
2833
config.suffixes = [
@@ -49,6 +54,8 @@ config.substitutions.append(("%clang_cpp", f" {config.clang} --driver-mode=g++ "
4954
config.substitutions.append(("%clang_skip_driver", config.clang))
5055
config.substitutions.append(("%clang", config.clang))
5156
config.substitutions.append(("%test_root", config.test_exec_root))
57+
config.substitutions.append(("%cmake_compiler_args", config.cmake_compiler_args))
5258
config.substitutions.append(('%cmake_generator', config.cmake_generator))
5359
config.substitutions.append(('%cmake', config.cmake_exe))
5460
config.substitutions.append(('%llvm_src_dir', config.llvm_src_dir))
61+
config.substitutions.append(('%perf_wrapper', perf_wrapper))

clang/utils/perf-training/lit.cfg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,19 @@ cc1_wrapper = '%s %s/perf-helper.py cc1' % (config.python_exe, config.perf_helpe
3131

3232
use_lit_shell = os.environ.get("LIT_USE_INTERNAL_SHELL")
3333
config.test_format = lit.formats.ShTest(use_lit_shell == "0")
34+
config.cmake_compiler_args = '-DCMAKE_C_COMPILER="{0}" -DCMAKE_CXX_COMPILER="{0};--driver-mode=g++"'.format(
35+
config.clang.replace(' ', ';')
36+
)
3437
config.substitutions.append( ('%clang_cpp_skip_driver', ' %s %s %s ' % (cc1_wrapper, config.clang, sysroot_flags)))
3538
config.substitutions.append( ('%clang_cpp', ' %s --driver-mode=g++ %s ' % (config.clang, sysroot_flags)))
3639
config.substitutions.append( ('%clang_skip_driver', ' %s %s %s ' % (cc1_wrapper, config.clang, sysroot_flags)))
3740
config.substitutions.append( ('%clang', '%s %s ' % (config.clang, sysroot_flags) ) )
3841
config.substitutions.append( ('%test_root', config.test_exec_root ) )
42+
config.substitutions.append( ('%cmake_compiler_args', config.cmake_compiler_args))
3943
config.substitutions.append( ('%cmake_generator', config.cmake_generator ) )
4044
config.substitutions.append( ('%cmake', config.cmake_exe ) )
4145
config.substitutions.append( ('%llvm_src_dir', config.llvm_src_dir ) )
46+
config.substitutions.append( ('%perf_wrapper', '' ) )
4247

4348
config.environment['LLVM_PROFILE_FILE'] = 'perf-training-%4m.profraw'
4449

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
RUN: %cmake -G %cmake_generator -B %t -S %llvm_src_dir -DCMAKE_C_COMPILER=%clang -DCMAKE_CXX_COMPILER=%clang -DCMAKE_CXX_FLAGS="--driver-mode=g++" -DCMAKE_BUILD_TYPE=Release
2-
RUN: %cmake --build %t -v --target LLVMSupport
1+
RUN: %cmake -G %cmake_generator -B %t -S %llvm_src_dir %cmake_compiler_args -DCMAKE_BUILD_TYPE=Release
2+
RUN: %perf_wrapper %cmake --build %t -v --target LLVMSupport

0 commit comments

Comments
 (0)