[clang] ea6e135 - [clang][perf-training] Fix profiling with -DCLANG_BOLT=perf (#119117)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 12 15:50:37 PST 2024
Author: Tom Stellard
Date: 2024-12-12T15:50:33-08:00
New Revision: ea6e13586ce22291e9e7a4e382f6b2409b406da9
URL: https://github.com/llvm/llvm-project/commit/ea6e13586ce22291e9e7a4e382f6b2409b406da9
DIFF: https://github.com/llvm/llvm-project/commit/ea6e13586ce22291e9e7a4e382f6b2409b406da9.diff
LOG: [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.
Added:
Modified:
clang/utils/perf-training/bolt.lit.cfg
clang/utils/perf-training/lit.cfg
clang/utils/perf-training/llvm-support/build.test
Removed:
################################################################################
diff --git a/clang/utils/perf-training/bolt.lit.cfg b/clang/utils/perf-training/bolt.lit.cfg
index 1d0cf9a8a17a8e..dbb2dd3fd85879 100644
--- a/clang/utils/perf-training/bolt.lit.cfg
+++ b/clang/utils/perf-training/bolt.lit.cfg
@@ -4,6 +4,7 @@ from lit import Test
import lit.formats
import lit.util
import os
+import re
import subprocess
clang_bolt_mode = config.clang_bolt_mode.lower()
@@ -20,9 +21,13 @@ elif clang_bolt_mode == "perf":
else:
assert 0, "Unsupported CLANG_BOLT_MODE variable"
-config.clang = perf_wrapper + os.path.realpath(
+clang_nowrapper = os.path.realpath(
lit.util.which(clang_binary, config.clang_tools_dir)
).replace("\\", "/")
+config.clang = perf_wrapper + clang_nowrapper
+config.cmake_compiler_args = "-DCMAKE_C_COMPILER='{0}' -DCMAKE_CXX_COMPILER='{0};--driver-mode=g++'".format(
+ re.sub(r"\s+", ";", clang_nowrapper)
+)
config.name = "Clang Perf Training"
config.suffixes = [
@@ -49,6 +54,8 @@ config.substitutions.append(("%clang_cpp", f" {config.clang} --driver-mode=g++ "
config.substitutions.append(("%clang_skip_driver", config.clang))
config.substitutions.append(("%clang", config.clang))
config.substitutions.append(("%test_root", config.test_exec_root))
+config.substitutions.append(("%cmake_compiler_args", config.cmake_compiler_args))
config.substitutions.append(('%cmake_generator', config.cmake_generator))
config.substitutions.append(('%cmake', config.cmake_exe))
config.substitutions.append(('%llvm_src_dir', config.llvm_src_dir))
+config.substitutions.append(('%perf_wrapper', perf_wrapper))
diff --git a/clang/utils/perf-training/lit.cfg b/clang/utils/perf-training/lit.cfg
index 654961e215da68..adefc7893ac44c 100644
--- a/clang/utils/perf-training/lit.cfg
+++ b/clang/utils/perf-training/lit.cfg
@@ -31,14 +31,19 @@ cc1_wrapper = '%s %s/perf-helper.py cc1' % (config.python_exe, config.perf_helpe
use_lit_shell = os.environ.get("LIT_USE_INTERNAL_SHELL")
config.test_format = lit.formats.ShTest(use_lit_shell == "0")
+config.cmake_compiler_args = '-DCMAKE_C_COMPILER="{0}" -DCMAKE_CXX_COMPILER="{0};--driver-mode=g++"'.format(
+ config.clang.replace(' ', ';')
+)
config.substitutions.append( ('%clang_cpp_skip_driver', ' %s %s %s ' % (cc1_wrapper, config.clang, sysroot_flags)))
config.substitutions.append( ('%clang_cpp', ' %s --driver-mode=g++ %s ' % (config.clang, sysroot_flags)))
config.substitutions.append( ('%clang_skip_driver', ' %s %s %s ' % (cc1_wrapper, config.clang, sysroot_flags)))
config.substitutions.append( ('%clang', '%s %s ' % (config.clang, sysroot_flags) ) )
config.substitutions.append( ('%test_root', config.test_exec_root ) )
+config.substitutions.append( ('%cmake_compiler_args', config.cmake_compiler_args))
config.substitutions.append( ('%cmake_generator', config.cmake_generator ) )
config.substitutions.append( ('%cmake', config.cmake_exe ) )
config.substitutions.append( ('%llvm_src_dir', config.llvm_src_dir ) )
+config.substitutions.append( ('%perf_wrapper', '' ) )
config.environment['LLVM_PROFILE_FILE'] = 'perf-training-%4m.profraw'
diff --git a/clang/utils/perf-training/llvm-support/build.test b/clang/utils/perf-training/llvm-support/build.test
index f29a594c846869..32ce9a870b91df 100644
--- a/clang/utils/perf-training/llvm-support/build.test
+++ b/clang/utils/perf-training/llvm-support/build.test
@@ -1,2 +1,2 @@
-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
-RUN: %cmake --build %t -v --target LLVMSupport
+RUN: %cmake -G %cmake_generator -B %t -S %llvm_src_dir %cmake_compiler_args -DCMAKE_BUILD_TYPE=Release
+RUN: %perf_wrapper %cmake --build %t -v --target LLVMSupport
More information about the cfe-commits
mailing list