This is an archive of the discontinued LLVM Phabricator instance.

[BOLT][CMAKE] Accept BOLT_CLANG_EXE and BOLT_LLD_EXE
ClosedPublic

Authored by Amir on Jan 11 2022, 3:50 PM.

Details

Summary

Add CMake options to supply clang and lld binaries for use in check-bolt
instead of requiring the build of clang and lld projects.

Suggested by Mehdi Amini in https://lists.llvm.org/pipermail/llvm-dev/2021-December/154426.html

Test Plan:

cmake -G Ninja ~/local/llvm-project/llvm \
-DLLVM_TARGETS_TO_BUILD="X86"  \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DLLVM_ENABLE_PROJECTS="bolt"  \
-DBOLT_CLANG_EXE=~/local/bin/clang \
-DBOLT_LLD_EXE=~/local/bin/lld

ninja check-bolt
...
llvm-lit: /home/aaupov/local/llvm-project/llvm/utils/lit/lit/llvm/config.py:436: note: using clang: /home/aaupov/local/bin/clang
llvm-lit: /home/aaupov/local/llvm-project/llvm/utils/lit/lit/llvm/config.py:436: note: using ld.lld: /home/aaupov/local/bin/ld.lld
llvm-lit: /home/aaupov/local/llvm-project/llvm/utils/lit/lit/llvm/config.py:436: note: using lld-link: /home/aaupov/local/bin/lld-link
llvm-lit: /home/aaupov/local/llvm-project/llvm/utils/lit/lit/llvm/config.py:436: note: using ld64.lld: /home/aaupov/local/bin/ld64.lld
llvm-lit: /home/aaupov/local/llvm-project/llvm/utils/lit/lit/llvm/config.py:436: note: using wasm-ld: /home/aaupov/local/bin/wasm-ld
...

Tested all configurations:

  • LLVM_ENABLE_PROJECTS="bolt;clang;lld" + no BOLT_*_EXE
  • LLVM_ENABLE_PROJECTS="bolt;clang" + BOLT_LLD_EXE
  • LLVM_ENABLE_PROJECTS="bolt;lld" + BOLT_CLANG_EXE
  • LLVM_ENABLE_PROJECTS="bolt" + BOLT_CLANG_EXE + BOLT_LLD_EXE
  • LLVM_ENABLE_PROJECTS="bolt;clang;lld" + BOLT_CLANG_EXE + BOLT_LLD_EXE

Diff Detail

Event Timeline

Amir created this revision.Jan 11 2022, 3:50 PM
Amir requested review of this revision.Jan 11 2022, 3:50 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 11 2022, 3:50 PM
maksfb accepted this revision.Jan 12 2022, 7:43 PM

LGTM

This revision is now accepted and ready to land.Jan 12 2022, 7:43 PM
Amir added a comment.Jan 12 2022, 8:43 PM

@smeenai:

Hi Shoaib, can you please take a look at the CMake changes? I’m in no way a CMake expert and would love to hear the feedback about how idiomatic this code is.

Looks mostly good, just had one question.

bolt/CMakeLists.txt
18–19

Not your diff, but CMake has if(IN_LIST) now, which you can use instead of the string(FIND), e.g.

if("clang" IN_LIST LLVM_ENABLE_PROJECTS)
bolt/test/CMakeLists.txt
17

Hmm, will these targets not clash with the clang and lld targets from those LLVM subprojects, if you have those enabled? Is the assumption that you would only use BOLT_CLANG_EXE and BOLT_LLD_EXE if you're not enabling those subprojects?

Amir added inline comments.Jan 13 2022, 9:40 PM
bolt/CMakeLists.txt
18–19

Thanks! Will fix in a separate diff.

bolt/test/CMakeLists.txt
17

Yes, that's the assumption. I thought about it a bit more and realized that if clang project is enabled, it will be picked up by logic in lit.cfg.py because BOLT_CLANG_EXE directory is used as an extra search path.

So the fix should be as follows:

  1. Emit a warning in bolt/CMakeLists.txt if BOLT_CLANG_EXE is set and clang project is enabled about which one will be used (built-in clang).
  2. Only add the clang target if BOLT_CLANG_EXE is set but clang project is not enabled to satisfy the dependency on clang in BOLT_TEST_DEPS.
Amir marked an inline comment as done.Jan 14 2022, 4:06 PM
Amir updated this revision to Diff 400176.Jan 14 2022, 4:07 PM

Addressed the feedback from Shoaib

Amir marked an inline comment as done.Jan 14 2022, 4:07 PM
Amir updated this revision to Diff 400190.EditedJan 14 2022, 4:42 PM

Updated warning message. BOLT_CLANG_EXE and BOLT_LLD_EXE take precedence over
project-built clang and lld (additional_tool_dirs is prepended to search paths).

Amir edited the summary of this revision. (Show Details)Jan 15 2022, 4:36 AM
This revision was landed with ongoing or failed builds.Jan 15 2022, 4:37 AM
This revision was automatically updated to reflect the committed changes.