Skip to content

Commit

Permalink
llvm: Speed up clang by 1.22x
Browse files Browse the repository at this point in the history
Build libLLVMSupport to generate profiling data, previously we were only
compiling a very simple HelloWorld program for profiling.

This speeds up building llvm with clang by 1.22x

Additionally build with thin LTO instead of full as the memory
requirements for fat LTO are too high with little gain.
  • Loading branch information
joebonrichie committed Oct 18, 2024
1 parent 15771c2 commit 9626ab4
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 25 deletions.
Binary file modified l/llvm/manifest.x86_64.bin
Binary file not shown.
34 changes: 17 additions & 17 deletions l/llvm/manifest.x86_64.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"binary(python3)",
"binutils-devel",
"clang-32bit",
"gcc-32bit-devel",
"g++-32bit",
"glibc-32bit-devel",
"libcxx-32bit-devel",
"pkgconfig(libedit)",
Expand Down Expand Up @@ -198,7 +198,7 @@
"binary(python3)",
"binutils-devel",
"clang-32bit",
"gcc-32bit-devel",
"g++-32bit",
"glibc-32bit-devel",
"libcxx-32bit-devel",
"pkgconfig(libedit)",
Expand All @@ -210,10 +210,10 @@
"pkgconfig(zlib)"
],
"depends": [
"soname(ld-linux.so.2(x86))",
"soname(libc++.so.1(x86))",
"soname(libc.so.6(x86))",
"soname(libm.so.6(x86))"
"soname(ld-linux.so.2(386))",
"soname(libc++.so.1(386))",
"soname(libc.so.6(386))",
"soname(libm.so.6(386))"
],
"files": [
"/usr/lib/clang/18/lib/linux/clang_rt.crtbegin-i386.o",
Expand Down Expand Up @@ -262,7 +262,7 @@
"binary(python3)",
"binutils-devel",
"clang-32bit",
"gcc-32bit-devel",
"g++-32bit",
"glibc-32bit-devel",
"libcxx-32bit-devel",
"pkgconfig(libedit)",
Expand Down Expand Up @@ -1061,7 +1061,7 @@
"binary(python3)",
"binutils-devel",
"clang-32bit",
"gcc-32bit-devel",
"g++-32bit",
"glibc-32bit-devel",
"libcxx-32bit-devel",
"pkgconfig(libedit)",
Expand Down Expand Up @@ -1348,7 +1348,7 @@
"binary(python3)",
"binutils-devel",
"clang-32bit",
"gcc-32bit-devel",
"g++-32bit",
"glibc-32bit-devel",
"libcxx-32bit-devel",
"pkgconfig(libedit)",
Expand Down Expand Up @@ -1393,7 +1393,7 @@
"binary(python3)",
"binutils-devel",
"clang-32bit",
"gcc-32bit-devel",
"g++-32bit",
"glibc-32bit-devel",
"libcxx-32bit-devel",
"pkgconfig(libedit)",
Expand Down Expand Up @@ -1444,7 +1444,7 @@
"binary(python3)",
"binutils-devel",
"clang-32bit",
"gcc-32bit-devel",
"g++-32bit",
"glibc-32bit-devel",
"libcxx-32bit-devel",
"pkgconfig(libedit)",
Expand Down Expand Up @@ -1487,7 +1487,7 @@
"binary(python3)",
"binutils-devel",
"clang-32bit",
"gcc-32bit-devel",
"g++-32bit",
"glibc-32bit-devel",
"libcxx-32bit-devel",
"pkgconfig(libedit)",
Expand Down Expand Up @@ -1698,7 +1698,7 @@
"binary(python3)",
"binutils-devel",
"clang-32bit",
"gcc-32bit-devel",
"g++-32bit",
"glibc-32bit-devel",
"libcxx-32bit-devel",
"pkgconfig(libedit)",
Expand Down Expand Up @@ -3853,7 +3853,7 @@
"binary(python3)",
"binutils-devel",
"clang-32bit",
"gcc-32bit-devel",
"g++-32bit",
"glibc-32bit-devel",
"libcxx-32bit-devel",
"pkgconfig(libedit)",
Expand Down Expand Up @@ -3899,7 +3899,7 @@
"binary(python3)",
"binutils-devel",
"clang-32bit",
"gcc-32bit-devel",
"g++-32bit",
"glibc-32bit-devel",
"libcxx-32bit-devel",
"pkgconfig(libedit)",
Expand Down Expand Up @@ -3930,7 +3930,7 @@
"binary(python3)",
"binutils-devel",
"clang-32bit",
"gcc-32bit-devel",
"g++-32bit",
"glibc-32bit-devel",
"libcxx-32bit-devel",
"pkgconfig(libedit)",
Expand Down Expand Up @@ -4065,6 +4065,6 @@
}
},
"source-name": "llvm",
"source-release": "12",
"source-release": "13",
"source-version": "18.1.8"
}
60 changes: 60 additions & 0 deletions l/llvm/pkg/perf/build-libLLVMSupport-for-perf-training.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
diff --git a/clang/utils/perf-training/lit.cfg b/clang/utils/perf-training/lit.cfg
index 0bd06c0d44f650..b4527c602fc484 100644
--- a/clang/utils/perf-training/lit.cfg
+++ b/clang/utils/perf-training/lit.cfg
@@ -34,8 +34,12 @@ config.test_format = lit.formats.ShTest(use_lit_shell == "0")
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( ('%clang', '%s %s ' % (config.clang, sysroot_flags) ) )
config.substitutions.append( ('%test_root', config.test_exec_root ) )
+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 ) )

+print(config.substitutions)
config.environment['LLVM_PROFILE_FILE'] = 'perf-training-%4m.profraw'

diff --git a/clang/utils/perf-training/lit.site.cfg.in b/clang/utils/perf-training/lit.site.cfg.in
index fae93065a4edf2..9d279d552919ac 100644
--- a/clang/utils/perf-training/lit.site.cfg.in
+++ b/clang/utils/perf-training/lit.site.cfg.in
@@ -8,6 +8,9 @@ config.test_exec_root = "@CMAKE_CURRENT_BINARY_DIR@"
config.test_source_root = "@CLANG_PGO_TRAINING_DATA@"
config.target_triple = "@LLVM_TARGET_TRIPLE@"
config.python_exe = "@Python3_EXECUTABLE@"
+config.cmake_exe = "@CMAKE_COMMAND@"
+config.llvm_src_dir ="@CMAKE_SOURCE_DIR@"
+config.cmake_generator ="@CMAKE_GENERATOR@"

# Let the main config do the real work.
lit_config.load_config(config, "@CLANG_SOURCE_DIR@/utils/perf-training/lit.cfg")
diff --git a/clang/utils/perf-training/llvm-support/build.test b/clang/utils/perf-training/llvm-support/build.test
new file mode 100644
index 00000000000000..f29a594c846869
--- /dev/null
+++ b/clang/utils/perf-training/llvm-support/build.test
@@ -0,0 +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

From 37919a76e3d3aa9456e1c598eab28a2c1f5155bc Mon Sep 17 00:00:00 2001
From: Tom Stellard <[email protected]>
Date: Wed, 9 Oct 2024 21:50:36 +0000
Subject: [PATCH 2/2] Remove debug statement

---
clang/utils/perf-training/lit.cfg | 1 -
1 file changed, 1 deletion(-)

diff --git a/clang/utils/perf-training/lit.cfg b/clang/utils/perf-training/lit.cfg
index b4527c602fc484..654961e215da68 100644
--- a/clang/utils/perf-training/lit.cfg
+++ b/clang/utils/perf-training/lit.cfg
@@ -40,6 +40,5 @@ 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 ) )

-print(config.substitutions)
config.environment['LLVM_PROFILE_FILE'] = 'perf-training-%4m.profraw'
12 changes: 4 additions & 8 deletions l/llvm/stone.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# TODO: Split out clang/etc and build statically against llvm package!
name : llvm
version : 18.1.8
release : 12
release : 13
summary : Low Level Virtual Machine
license :
- Apache-2.0 WITH LLVM-exception
Expand All @@ -22,7 +22,7 @@ builddeps :
- pkgconfig(ncursesw)
- pkgconfig(zlib)
- binutils-devel
- gcc-32bit-devel
- g++-32bit
- glibc-32bit-devel
- libcxx-32bit-devel
- clang-32bit
Expand Down Expand Up @@ -67,9 +67,9 @@ environment : |
# Without RPATH, we need help finding the right libraries to use
export LD_LIBRARY_PATH="%(workdir)/%(builddir)/lib"
setup : |
unset LD_PRELOAD
%patch %(pkgdir)/serpent/0001-Support-serpent-as-a-distro.patch
%patch %(pkgdir)/perf/0001-Reduce-GCC-startup-searches.patch
%patch %(pkgdir)/perf/build-libLLVMSupport-for-perf-training.patch
%patch %(pkgdir)/serpent/0001-Use-correct-Serpent-OS-multilib-paths-for-ld.patch
%patch %(pkgdir)/serpent/0001-Make-gnu-hash-the-default-for-lld-and-clang.patch
%patch %(pkgdir)/serpent/0001-Update-binutils-version-to-match-Serpent-OS.patch
Expand All @@ -82,11 +82,10 @@ setup : |
%cmake -S llvm \
-C clang/cmake/caches/PGO.cmake \
-DLLVM_ENABLE_PROJECTS='clang;lld;llvm;polly' \
-DPGO_INSTRUMENT_LTO=ON \
-DPGO_INSTRUMENT_LTO=Thin \
-B pgo-training \
${llvmopts}
unset LD_PRELOAD
%cmake_build -C pgo-training stage2-instrumented-generate-profdata
find pgo-training -name "clang.profdata" -exec mv {} %(workdir) \;
Expand All @@ -96,16 +95,13 @@ setup : |
-DLLVM_PROFDATA_FILE=%(workdir)/clang.profdata \
${llvmopts}
build : |
unset LD_PRELOAD
%cmake_build
install : |
%cmake_install
%install_dir %(installroot)/%(libdir)/bfd-plugins
ln -srf %(installroot)/%(libdir)/LLVMgold.so %(installroot)/%(libdir)/bfd-plugins/LLVMgold.so
# unset LD_PRELOAD
# # Major clang version
# major_version=$(echo %(version) | cut -d. -f1)
# export PATH="%(installroot)/usr/bin:${PATH}"
Expand Down

0 comments on commit 9626ab4

Please sign in to comment.