This is an archive of the discontinued LLVM Phabricator instance.

[libc][NFC] Detect host CPU features using try_compile instead of try_run.
Needs ReviewPublic

Authored by sivachandra on Jan 18 2023, 1:00 AM.
This revision needs review, but all reviewers have resigned.

Details

Reviewers
gchatelet
Summary

This fixes scenarios like the runtime build wherein the clang is
built to use libcxx or libunwind by default which are either not yet
built or not yet installed in the places where the clang driver expects
them.

Fixes llvm/llvm-project#59762

Diff Detail

Event Timeline

sivachandra created this revision.Jan 18 2023, 1:00 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJan 18 2023, 1:00 AM
sivachandra requested review of this revision.Jan 18 2023, 1:00 AM

Thx for the patch @sivachandra! It's definitely better than what I did, I was unhappy with the design but it was a first step.

There are still a few issues in my opinion:

  • in msvc features have a different name, this means that the way we refer to features in CMake cannot be the same as what is put into the file,
  • the way we detect features in CMake and in llvm libc can be different,
  • what is actually compiled by CMake is hard to understand.

I think this can be improved further.

Here is what I have in mind :

  • Add preprocessor feature detection to something like libc/src/__support/cpu_features.h (we already have LIBC_TARGET_HAS_FMA in libc/src/__support/architectures.h). This file would only depend on freestanding headers like compiler_features.h or architectures.h (sidenote we should probably make it clear in the filename that these headers are freestanding / only preprocessor)
  • Create one cpp file per feature with a filename similar to the LIBC preprocessor definition. We don't have a lot of features so the number of files will stay low. This file would use the libc header so we have consistent detection between CMake (Bazel?) and the code.

WDYT? I can take a look at it if you want?

I think this can be improved further.

Here is what I have in mind :

  • Add preprocessor feature detection to something like libc/src/__support/cpu_features.h (we already have LIBC_TARGET_HAS_FMA in libc/src/__support/architectures.h). This file would only depend on freestanding headers like compiler_features.h or architectures.h (sidenote we should probably make it clear in the filename that these headers are freestanding / only preprocessor)
  • Create one cpp file per feature with a filename similar to the LIBC preprocessor definition. We don't have a lot of features so the number of files will stay low. This file would use the libc header so we have consistent detection between CMake (Bazel?) and the code.

WDYT? I can take a look at it if you want?

I think the essential idea you are proposing is to move feature detection from config time to build time. Is that correct? If yes, that sounds OK to me as long as we can do the detection without having to run fully linked executables (which is the core problem this patch is trying to solve.)

I've created https://reviews.llvm.org/D142108 as a replacement for this patch. Let me know what you think.

https://reviews.llvm.org/D142108 has been submitted, this patch can be marked as abandoned.

gchatelet resigned from this revision.Jul 18 2023, 5:59 AM