Too much time to compile clang. Suggestions for a starter?

I would like to start “touching” a bit the code, trying to create some functionalities, but I have no idea where to start, and I will need many trials/tests…

So, one thing I was expecting is fast times to try (Modify-Compile-Run).

I did:

make clang
and it needed like 3-4 hours. I am ok with that.

Then, I add some “stupid” statement like ‘int a = 3;’ somewhere in llvm/tools/clang/lib/Frontend/Rewrite/FixItRewriter.cpp (FixitRewriter::Diag), and it needed:

  • 6.57s. to compile the target (‘make clangRewriteFrontend’).
  • 4min 36.36s to link and build clang (make clang).
    In both cases it spends almost all the time linking (first to a static lib, then to the clang binary itself).

This is really a lot of time to try bit a bit without knowledge of the whole clang, compiling process, etc. Waiting up to is just really time consuming.

What would you do to try the modifications faster?

Any recomendation/blog/guide to follow as a starter trying to modify a bit the codebase of clang?

You can use gold <https://en.wikipedia.org/wiki/Gold_(linker)&gt; to link.
To do so, pass -DLLVM_USE_LINKER=gold at CMake configure time.

This is also a good opportunity to point at a minor issue with CMake
configuration, where even after passing the above switch CMake will
still print

-- Linker detection: GNU ld

instead of

-- Linker detection: GNU Gold

I don't know whether it "just works" for others, but
<https://reviews.llvm.org/D38665&gt; (unreviewed) fixes it for me.

Did you try to run make in parallel using the -j option? That and linking with Gold (as Oleksii mentioned) should greatly improve build times.

Especially for incremental builds, ninja tends to be a much better
option.

Joerg

A few links that Google found in a simple search:
  - this thread: http://lists.llvm.org/pipermail/llvm-dev/2016-October/106186.html
  - https://llvm.org/devmtg/2015-04/slides/eurollvm-2015-build.pdf and these two blog posts: https://blogs.s-osg.org/an-introduction-to-accelerating-your-build-with-clang/ and https://blogs.s-osg.org/a-conclusion-to-accelerating-your-build-with-clang/

I personally took most of the advices from the last blog posts:
  - Ninja, use Clang to build
  - for Debug builds: -DBUILD_SHARED_LIBS=ON -DLLVM_USE_SPLIT_DWARF=ON -DLLVM_OPTIMIZED_TABLEGEN=ON

Cheers,
Jonas

Thank you very much, Jonas, Nicolas and Oleksii.

I read those blogs and applied just this:

cp ../../llvm-support/AddLLVM.cmake.gold ../cmake/modules/AddLLVM.cmake
(I modified those lines in the reviews.llvm.org).
CXX=clang++ CC=clang cmake LD=ld.gold -G Ninja .. -DLLVM_USE_LINKER=gold
-DBUILD_SHARED_LIBS=ON -DLLVM_USE_SPLIT_DWARF=ON
-DLLVM_OPTIMIZED_TABLEGEN=ON .. && ninja clang

And with just the same modification (int a = 22; in that class) I get
compiled/linked in JUST 10-3 SECONDS.

Impressive!

Thanks again. This thread can be closed.

You might also consider building only those backends you are actually using.
E. g.:
cmake -DLLVM_TARGETS_TO_BUILD=X86 ...

More info:
https://llvm.org/docs/CMake.html#llvm-specific-variables