Skip to content

Commit 4949c9b

Browse files
committed
Address review comments
1 parent 1ca9ce9 commit 4949c9b

File tree

4 files changed

+24
-35
lines changed

4 files changed

+24
-35
lines changed

clang/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -853,19 +853,19 @@ endif()
853853
set(CLANG_BOLT "INSTRUMENT" CACHE STRING "Apply BOLT optimization to Clang. \
854854
May be specified as Instrument or Perf or LBR to use a particular profiling \
855855
mechanism.")
856-
string(TOUPPER "${CLANG_BOLT}" uppercase_CLANG_BOLT)
856+
string(TOUPPER "${CLANG_BOLT}" CLANG_BOLT)
857857

858858
if (CLANG_BOLT AND NOT LLVM_BUILD_INSTRUMENTED)
859859
set(CLANG_PATH ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang)
860860
set(CLANG_INSTRUMENTED ${LLVM_RUNTIME_OUTPUT_INTDIR}/${CLANG_BOLT_INSTRUMENTED})
861861
set(BOLT_FDATA ${CMAKE_CURRENT_BINARY_DIR}/utils/perf-training/prof.fdata)
862862

863863
# Pass extra flag in no-LBR mode
864-
if (uppercase_CLANG_BOLT STREQUAL "PERF")
864+
if (CLANG_BOLT STREQUAL "PERF")
865865
set(BOLT_NO_LBR "-nl")
866866
endif()
867867

868-
if (uppercase_CLANG_BOLT STREQUAL "INSTRUMENT")
868+
if (CLANG_BOLT STREQUAL "INSTRUMENT")
869869
# Instrument clang with BOLT
870870
add_custom_target(clang-instrumented
871871
DEPENDS ${CLANG_INSTRUMENTED}

clang/utils/perf-training/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,13 @@ if(CLANG_BOLT AND NOT LLVM_BUILD_INSTRUMENTED)
8484
COMMAND "${Python3_EXECUTABLE}" ${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py clean ${CMAKE_CURRENT_BINARY_DIR} perf.data
8585
COMMENT "Clearing old perf data")
8686

87-
string(TOUPPER "${CLANG_BOLT}" uppercase_CLANG_BOLT)
88-
if (uppercase_CLANG_BOLT STREQUAL "LBR")
87+
string(TOUPPER "${CLANG_BOLT}" CLANG_BOLT)
88+
if (CLANG_BOLT STREQUAL "LBR")
8989
set(BOLT_LBR "--lbr")
9090
endif()
9191

9292
add_custom_target(merge-fdata-deps)
93-
if (uppercase_CLANG_BOLT STREQUAL "INSTRUMENT")
93+
if (CLANG_BOLT STREQUAL "INSTRUMENT")
9494
add_dependencies(merge-fdata-deps generate-bolt-fdata)
9595
else()
9696
# Convert perf profiles into fdata

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

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,21 @@ import lit.util
66
import os
77
import subprocess
88

9+
clang_bolt_mode = config.clang_bolt_mode.lower()
910
clang_binary = "clang"
10-
perf_wrapper = ""
11-
if config.clang_bolt_mode.lower() == "instrument":
11+
perf_wrapper = f"{config.python_exe} {config.perf_helper_dir}/perf-helper.py perf "
12+
13+
if clang_bolt_mode == "instrument":
14+
perf_wrapper = ""
1215
clang_binary = config.clang_bolt_name
13-
else: # perf or LBR
14-
perf_wrapper = "%s %s/perf-helper.py perf" % (
15-
config.python_exe,
16-
config.perf_helper_dir,
17-
)
18-
if config.clang_bolt_mode.lower() == "lbr":
19-
perf_wrapper += " --lbr"
16+
elif clang_bolt_mode == "lbr":
17+
perf_wrapper += " --lbr -- "
18+
elif clang_bolt_mode == "perf":
2019
perf_wrapper += " -- "
20+
else:
21+
assert 0, "Unsupported CLANG_BOLT_MODE variable"
2122

22-
config.clang = os.path.realpath(
23+
config.clang = perf_wrapper + os.path.realpath(
2324
lit.util.which(clang_binary, config.clang_tools_dir)
2425
).replace("\\", "/")
2526

@@ -42,16 +43,9 @@ config.suffixes = [
4243
use_lit_shell = os.environ.get("LIT_USE_INTERNAL_SHELL")
4344
config.test_format = lit.formats.ShTest(use_lit_shell == "0")
4445
config.substitutions.append(
45-
(
46-
"%clang_cpp_skip_driver",
47-
" %s %s --driver-mode=g++ " % (perf_wrapper, config.clang),
48-
)
49-
)
50-
config.substitutions.append(
51-
("%clang_cpp", " %s %s --driver-mode=g++ " % (perf_wrapper, config.clang))
52-
)
53-
config.substitutions.append(
54-
("%clang_skip_driver", " %s %s " % (perf_wrapper, config.clang))
46+
("%clang_cpp_skip_driver", f" {config.clang} --driver-mode=g++ ")
5547
)
56-
config.substitutions.append(("%clang", " %s %s " % (perf_wrapper, config.clang)))
48+
config.substitutions.append(("%clang_cpp", f" {config.clang} --driver-mode=g++ "))
49+
config.substitutions.append(("%clang_skip_driver", config.clang))
50+
config.substitutions.append(("%clang", config.clang))
5751
config.substitutions.append(("%test_root", config.test_exec_root))

clang/utils/perf-training/perf-helper.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,10 @@ def perf(args):
7474
parser.add_argument(
7575
"--lbr", action="store_true", help="Use perf with branch stacks"
7676
)
77-
parser.add_argument("cmd", nargs="*", help="")
77+
parser.add_argument("cmd", nargs=argparse.REMAINDER, help="")
7878

79-
# Use python's arg parser to handle all leading option arguments, but pass
80-
# everything else through to perf
81-
first_cmd = next(arg for arg in args if not arg.startswith("--"))
82-
last_arg_idx = args.index(first_cmd)
83-
84-
opts = parser.parse_args(args[:last_arg_idx])
85-
cmd = args[last_arg_idx:]
79+
opts = parser.parse_args()
80+
cmd = opts["cmd"][1:]
8681

8782
perf_args = [
8883
"perf",

0 commit comments

Comments
 (0)