Building Clang/LLVM Efficiently
Total Page:16
File Type:pdf, Size:1020Kb
Building Clang/LLVM efficiently Tilmann Scheller LLVM Compiler Engineer [email protected] Samsung Open Source Group Samsung Research UK EuroLLVM 2015 London, United Kingdom, April 13 – 14, 2015 Samsung Open Source Group 1 Overview ● Introduction ● Performance ● Summary Samsung Open Source Group 2 Introduction Samsung Open Source Group 3 Introduction ● Clang/LLVM are large pieces of C++ software ● Long turnaround time harms developer productivity ● Squeeze maximum performance out of the toolchain ● Speed up the build without buying new hardware ● Focus on x86-64 Linux ● Test machine: Fedora 21 on i7-4770K CPU @ 3.50GHz, 16GB RAM, 1TB 7200RPM HDD Samsung Open Source Group 4 Ideas ● Build with Clang instead of GCC ● Only build what you really need (e.g. only build relevant backends) ● Use a faster linker: GNU gold instead of GNU ld ● Use a heavily optimized compiler binary for the build (LTO, PGO, LTO+PGO) ● For incremental debug builds: shared library build instead of static build Samsung Open Source Group 5 Performance Samsung Open Source Group 6 Measurement ● GCC 4.9.2 shipping with Fedora 21 ● Clang trunk snapshot (r234392 from April 8, 2015) ● Standard debug/release builds of Clang (CMake build with default generator) unless otherwise noted ● Using GNU gold 2.24 for linking ● Make invoked with -j8 ● Best of five runs Samsung Open Source Group 7 Clang vs. GCC compile time ● Both Clang and GCC are compiled with GCC 4.9.2 755 Debug build 1.48x faster 509 Clang GCC 4.9.2 726 Release build 538 1.34x faster 0 100 200 300 400 500 600 700 800 seconds Samsung Open Source Group 8 Only build a subset of Clang/LLVM ● Only build relevant backends ● Host Clang built with GCC 4.9.2 755 Debug build 1.27x faster 591 X86 backend only All backends 726 Release build 583 1.24x faster 0 100 200 300 400 500 600 700 800 seconds Samsung Open Source Group 9 Use a faster linker ● Using GNU gold instead of GNU ld ● Building Clang with GCC 4.9.2 873 Debug build 755 1.17x faster 746 GNU gold + split DWARF GNU gold 731 GNU ld Release build 726 0 100 200 300 400 500 600 700 800 900 1000 seconds Samsung Open Source Group 10 Optimize host compiler binary aggressively ● Building Clang with a heavily optimized host Clang build ● Host Clang was compiled with Clang or GCC at the various different optimization levels Release Debug 560 520 547 510 509 512 537 538 540 498 522 500 520 480 500 467 482 s s d d 480 460 n n 450 o o 462 c c e e 460 s s 440 440 420 420 400 400 GCC -O3 GCC LTO GCC LTO+PGO GCC -O3 GCC LTO GCC LTO+PGO Clang -O3 Clang LTO GCC PGO Clang -O3 Clang LTO GCC PGO PGO 1.16x faster PGO 1.13x faster Samsung Open Source Group 11 Speeding up incremental builds ● Shared library build rather than static build ● Debug build of Clang with GCC 4.9.2 ● Incremental build after changing a single file in the ARM backend (ARMISelLowering.cpp) 27 Build time after edit Shared build Static build 5 5.4x faster 0 5 10 15 20 25 30 seconds Samsung Open Source Group 12 Summary Samsung Open Source Group 13 Summary ● Always build with Clang if you care about compile time ● Use GNU gold rather than GNU ld ● Building Clang with GCC and PGO produces fastest binary ● Shared library builds speed up incremental debug builds tremendously ● Overall speedup: 1.58x for release builds and 1.94x for debug builds (Switching from GCC + GNU ld to a PGO build of Clang + GNU gold) Samsung Open Source Group 14 Thank you. Samsung Open Source Group 15.