Building Clang/LLVM efficiently Tilmann Scheller LLVM Compiler - - PowerPoint PPT Presentation

building clang llvm efficiently
SMART_READER_LITE
LIVE PREVIEW

Building Clang/LLVM efficiently Tilmann Scheller LLVM Compiler - - PowerPoint PPT Presentation

Building Clang/LLVM efficiently Tilmann Scheller LLVM Compiler Engineer t.scheller@samsung.com Samsung Open Source Group Samsung Research UK EuroLLVM 2015 London, United Kingdom, April 13 14, 2015 Samsung Open Source Group 1 Overview


slide-1
SLIDE 1

1 Samsung Open Source Group

Building Clang/LLVM efficiently

Tilmann Scheller LLVM Compiler Engineer t.scheller@samsung.com Samsung Open Source Group Samsung Research UK EuroLLVM 2015 London, United Kingdom, April 13 – 14, 2015

slide-2
SLIDE 2

2 Samsung Open Source Group

Overview

  • Introduction
  • Performance
  • Summary
slide-3
SLIDE 3

3 Samsung Open Source Group

Introduction

slide-4
SLIDE 4

4 Samsung Open Source Group

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

slide-5
SLIDE 5

5 Samsung Open Source Group

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
  • f static build
slide-6
SLIDE 6

6 Samsung Open Source Group

Performance

slide-7
SLIDE 7

7 Samsung Open Source Group

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
slide-8
SLIDE 8

8 Samsung Open Source Group

Clang vs. GCC compile time

  • Both Clang and GCC are compiled with GCC 4.9.2

Release build Debug build 100 200 300 400 500 600 700 800 538 509 726 755 Clang GCC 4.9.2

seconds

1.48x faster 1.34x faster

slide-9
SLIDE 9

9 Samsung Open Source Group

Only build a subset of Clang/LLVM

  • Only build relevant backends
  • Host Clang built with GCC 4.9.2

Release build Debug build 100 200 300 400 500 600 700 800 583 591 726 755 X86 backend only All backends

seconds

1.27x faster 1.24x faster

slide-10
SLIDE 10

10 Samsung Open Source Group

Use a faster linker

  • Using GNU gold instead of GNU ld
  • Building Clang with GCC 4.9.2

Release build Debug build 100 200 300 400 500 600 700 800 900 1000 726 755 731 873 746 GNU gold + split DWARF GNU gold GNU ld

seconds

1.17x faster

slide-11
SLIDE 11

11 Samsung Open Source Group

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
  • ptimization levels

Clang -O3 GCC -O3 Clang LT O GCC LT O GCC PGO GCC LT O+PGO 400 420 440 460 480 500 520 540 560 537 538 522 547 462 482

Release

seconds

Clang -O3 GCC -O3 Clang LT O GCC LT O GCC PGO GCC LT O+PGO 400 420 440 460 480 500 520 510 509 498 512 450 467

Debug

seconds

PGO 1.16x faster PGO 1.13x faster

slide-12
SLIDE 12

12 Samsung Open Source Group

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)

Build time after edit 5 10 15 20 25 30 5 27 Shared build Static build

seconds

5.4x faster

slide-13
SLIDE 13

13 Samsung Open Source Group

Summary

slide-14
SLIDE 14

14 Samsung Open Source Group

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)

slide-15
SLIDE 15

Thank you.

15 Samsung Open Source Group