[PATCH] D69825: [Clang][Driver] Bypass cc1 process and re-enter driver main

Alexandre Ganea via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 4 13:58:59 PST 2019


aganea created this revision.
aganea added reviewers: thakis, hans, rnk.
aganea added a project: clang.
Herald added subscribers: llvm-commits, cfe-commits, hiraditya.
Herald added a reviewer: jfb.
Herald added a project: LLVM.

This patch is an optimization for speed: it will bypass the cc1 process invocation when possible, and instead will re-enter the driver process.
On Windows, this has a great impact on build times:

F10626773: clang-bypass-cc1-6-core.png <https://reviews.llvm.org/F10626773>

F10626775: clang-bypass-cc1-36-core.png <https://reviews.llvm.org/F10626775>

CFG (control flow guard) is disabled on Windows.
//Side-note: I've also observed an improvement when switching to Windows 10 build 1903: all builds are faster, generally by ~2-3 min on the 6-core machine.//

The cc1 bypass mildly improves build times on Linux as well (although it's a old machine):

F10626777: clang-bypass-cc1-6-core-linux.png <https://reviews.llvm.org/F10626777>

All tests pass (ninja check-all) on Windows with the following config:

  cmake -G"Ninja" %ROOT%/llvm -DCMAKE_BUILD_TYPE=Release -DLLVM_OPTIMIZED_TABLEGEN=true -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_ENABLE_LIBXML2=OFF -DLLVM_USE_CRT_RELEASE=MT -DCMAKE_C_COMPILER="C:/Program Files/LLVM/bin/clang-cl.exe" -DCMAKE_CXX_COMPILER="C:/Program Files/LLVM/bin/clang-cl.exe" -DCMAKE_LINKER="c:/Program Files/LLVM/bin/lld-link.exe" -DLLVM_ENABLE_LLD=true -DCMAKE_CXX_FLAGS="/arch:AVX /GS- /D_ITERATOR_DEBUG_LEVEL=0" -DCMAKE_C_FLAGS="/arch:AVX /GS- /D_ITERATOR_DEBUG_LEVEL=0" -DLLVM_ENABLE_PDB=true -DLLVM_ENABLE_PROJECTS="clang;lld;clang-tools-extra;compiler-rt"

..then followed by a second stage build.

As for re-entering `main()` in the code:
In some cases, when using clang-as-a-library, we cannot re-enter `main()`; and we shouldn't take the address of `main()` as per [C++11: 3.6.1/3] (that's what I meant at the LLVM conf. by saying that "we shouldn't be doing that"). I therefore used `llvm::sys::DynamicLibrary::AddSymbol` to keep a weak link to `main()`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D69825

Files:
  clang/include/clang/Driver/Job.h
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/Job.cpp
  clang/tools/driver/driver.cpp
  llvm/include/llvm/Support/CrashRecoveryContext.h
  llvm/lib/Support/CrashRecoveryContext.cpp
  llvm/lib/Support/Windows/Signals.inc

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69825.227772.patch
Type: text/x-patch
Size: 14517 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191104/a6a7ee9b/attachment-0001.bin>


More information about the cfe-commits mailing list