Skip to content

Commit df8296d

Browse files
committed
[CMake][PGO] Use check-clang target to generate profdata for PGO builds
When doing a multi-stage PGO build of clang, run the check-clang and check-llvm targets using the instrumented clang and use that profile data for building the final stage2 clang. This is what is recommended by our official documentation: https://llvm.org/docs/HowToBuildWithPGO.html#building-clang-with-pgo I benchmarked this change by compiling the SemaChecking.cpp file from clang. Using check-clang/check-llvm to generate the profile data gives a 25% speedup in the PGO+LTO stage2 clang when compared to the stage1 clang (no-LTO). Prior to this change, I was only seeing ~5% speedup when comparing the stage2 and stage1 builds.
1 parent b41c8bb commit df8296d

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

clang/utils/perf-training/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ if(LLVM_BUILD_INSTRUMENTED)
1515
)
1616

1717
add_custom_target(clear-profraw
18-
COMMAND "${Python3_EXECUTABLE}" ${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py clean ${CMAKE_CURRENT_BINARY_DIR} profraw
18+
COMMAND "${Python3_EXECUTABLE}" ${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py clean ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_BINARY_DIR}/profiles/ profraw
1919
COMMENT "Clearing old profraw data")
2020

2121
if(NOT LLVM_PROFDATA)
@@ -26,9 +26,9 @@ if(LLVM_BUILD_INSTRUMENTED)
2626
message(STATUS "To enable merging PGO data LLVM_PROFDATA has to point to llvm-profdata")
2727
else()
2828
add_custom_target(generate-profdata
29-
COMMAND "${Python3_EXECUTABLE}" ${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py merge ${LLVM_PROFDATA} ${CMAKE_CURRENT_BINARY_DIR}/clang.profdata ${CMAKE_CURRENT_BINARY_DIR}
29+
COMMAND "${Python3_EXECUTABLE}" ${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py merge ${LLVM_PROFDATA} ${CMAKE_CURRENT_BINARY_DIR}/clang.profdata ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_BINARY_DIR}/profiles/
3030
COMMENT "Merging profdata"
31-
DEPENDS generate-profraw)
31+
DEPENDS generate-profraw check-clang check-llvm)
3232
endif()
3333
endif()
3434

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,28 @@ def findFilesWithExtension(path, extension):
3030

3131

3232
def clean(args):
33-
if len(args) != 2:
33+
if len(args) < 2:
3434
print(
35-
"Usage: %s clean <path> <extension>\n" % __file__
35+
"Usage: %s clean <paths> <extension>\n" % __file__
3636
+ "\tRemoves all files with extension from <path>."
3737
)
3838
return 1
39-
for filename in findFilesWithExtension(args[0], args[1]):
40-
os.remove(filename)
39+
for path in args[1:-1]:
40+
for filename in findFilesWithExtension(path, args[-1]):
41+
os.remove(filename)
4142
return 0
4243

4344

4445
def merge(args):
45-
if len(args) != 3:
46+
if len(args) < 3:
4647
print(
47-
"Usage: %s merge <llvm-profdata> <output> <path>\n" % __file__
48+
"Usage: %s merge <llvm-profdata> <output> <paths>\n" % __file__
4849
+ "\tMerges all profraw files from path into output."
4950
)
5051
return 1
5152
cmd = [args[0], "merge", "-o", args[1]]
52-
cmd.extend(findFilesWithExtension(args[2], "profraw"))
53+
for i in range(2, len(args)):
54+
cmd.extend(findFilesWithExtension(args[i], "profraw"))
5355
subprocess.check_call(cmd)
5456
return 0
5557

0 commit comments

Comments
 (0)