This is an archive of the discontinued LLVM Phabricator instance.

[Clang][AArch64] Introduce CLANG_AARCH64_DEFAULT_CPU
AbandonedPublic

Authored by SjoerdMeijer on Jul 13 2023, 7:02 AM.

Details

Summary

We would like to default to a particular CPU when -mcpu is not provided on the Clang command line. This introduces a CMake variable CLANG_AARCH64_DEFAULT_CPU, so that a default CPU can be specified at CMake build time.

If CLANG_AARCH64_DEFAULT_CPU is not provided, it will default to "generic", so this will make sure we keep the current behaviour.

If CLANG_AARCH64_DEFAULT_CPU is changed, a companion downstream patch is required at the moment for the tests that check "target-cpu generic" when -mcpu is omitted. Ideally we could somehow parameterize that with something like "target-cpu ${CLANG_AARCH64_DEFAULT_CPU}" in the tests. Maybe that is possible in Lit, in the config files, but I don't know and am still looking into that.

Diff Detail

Event Timeline

SjoerdMeijer created this revision.Jul 13 2023, 7:02 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 13 2023, 7:02 AM
SjoerdMeijer requested review of this revision.Jul 13 2023, 7:02 AM

Clang configuration files are insufficient for this task?
https://clang.llvm.org/docs/UsersManual.html#configuration-files

SjoerdMeijer added a comment.EditedJul 13 2023, 7:15 AM

Clang configuration files are insufficient for this task?
https://clang.llvm.org/docs/UsersManual.html#configuration-files

I don't know, but will look into it.
Ideally, we could change this:

CHECK:  "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "generic"

into:

CHECK:  "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "$(CLANG_AARCH64_DEFAULT_CPU)"

So I feel that this is more of a lit thing. Lit has to understand the value of CLANG_AARCH64_DEFAULT_CPU.

lenary edited reviewers, added: pratlucas; removed: lenary.Jul 13 2023, 7:32 AM

Other approach worth looking at is to push args in Clang.cpp. We can look at AddAArch64TargetArgs() and pass default CPU if -mcpu or mtune is not provided.

Other approach worth looking at is to push args in Clang.cpp. We can look at AddAArch64TargetArgs() and pass default CPU if -mcpu or mtune is not provided.

yes, but I think I prefer this approach if I am able find a solution for the test cases. This approach defines a variable, which we can use to define a "substitution" in the lit configuration file (https://llvm.org/docs/TestingGuide.html#substitutions).

In lit.cfg.py, I am looking to add something along the lines of:

config.substitutions.append(("%AARCH64_DEFAULT_CPU", @CLANG_AARCH64_DEFAULT_CPU@))

And then in the test files we can check for:

"-target-cpu" %(AARCH64_DEFAULT_CPU)

I don't have it working yet, but am working on it.
I think this is the more elegant solution, which pushing an -mcpu value doesn't provide, I think.

I missed the CLANG_SYSTEMZ_DEFAULT_ARCH introduction, but adding this kind of customization is what we strive to avoid and there is trend to remove more CLANG_*_DEFAULT.
Can you use https://clang.llvm.org/docs/UsersManual.html#configuration-files instead?

michaelplatings added inline comments.
clang/CMakeLists.txt
241–243

No need for if(NOT... for cache variables.

SjoerdMeijer abandoned this revision.Jul 13 2023, 9:15 AM

I missed the CLANG_SYSTEMZ_DEFAULT_ARCH introduction, but adding this kind of customization is what we strive to avoid and there is trend to remove more CLANG_*_DEFAULT.
Can you use https://clang.llvm.org/docs/UsersManual.html#configuration-files instead?

Ha, I didn't know about these configuration files!
Sorry @tschuett , you also suggested that, I had not yet looked closely enough.

Thanks for the suggestions. These config files look exactly what I need, so am happy to abandon this.