Skip to content

Commit d4480da

Browse files
committed
Fixes for PGO
1 parent 9aa48ac commit d4480da

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

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

Lines changed: 19 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,24 @@ 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_CXX_COMPILER_LAUNCHER='{0}' -DCMAKE_C_COMPILER_LAUNCHER='{0}' -DCMAKE_C_COMPILER='{1}' -DCMAKE_CXX_COMPILER='{1};--driver-mode=g++'".format(
29+
re.sub(r"\s+", ";", perf_wrapper.rstrip()),
30+
re.sub(r"\s+", ";", clang_nowrapper)
31+
)
32+
33+
# We need to limit the number of build jobs with perf in order to avoid this
34+
# error:
35+
#
36+
# | Permission error mapping pages.
37+
# | Consider increasing /proc/sys/kernel/perf_event_mlock_kb,
38+
# | or try again with a smaller value of -m/--mmap_pages.
39+
ninja_args = ""
40+
if clang_bolt_mode != "instrument":
41+
ninja_args = "-j1"
2642

2743
config.name = "Clang Perf Training"
2844
config.suffixes = [
@@ -49,6 +65,8 @@ config.substitutions.append(("%clang_cpp", f" {config.clang} --driver-mode=g++ "
4965
config.substitutions.append(("%clang_skip_driver", config.clang))
5066
config.substitutions.append(("%clang", config.clang))
5167
config.substitutions.append(("%test_root", config.test_exec_root))
68+
config.substitutions.append(("%cmake_compiler_args", config.cmake_compiler_args))
5269
config.substitutions.append(('%cmake_generator', config.cmake_generator))
5370
config.substitutions.append(('%cmake', config.cmake_exe))
5471
config.substitutions.append(('%llvm_src_dir', config.llvm_src_dir))
72+
config.substitutions.append(('%ninja_args', ninja_args))

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( ('%ninja_args', '' ) )
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: %cmake --build %t %ninja_args -v --target LLVMSupport

0 commit comments

Comments
 (0)