This is an archive of the discontinued LLVM Phabricator instance.

[Clang][RISCV] Add CMake options to configure default CPU
AbandonedPublic

Authored by pcwang-thead on Feb 27 2023, 1:33 AM.

Details

Summary

For GCC, we can configure default target with with-{tune/arch/abi}
options. While for Clang, we don't have the similar way to configure.

Here we add two CMake options CLANG_RISCV32_DEFAULT_CPU and
CLANG_RISCV64_DEFAULT_CPU to configure default CPU for riscv32
and riscv64.

By specifying these two options when compiling Clang/LLVM, we can
achieve the same goal just like GCC's with-{tune/arch/abi}:

  • Tune/arch info can be inferred from CPU info.
  • Default ABI can be computed from arch string.

And we can do native detection via specifying default CPU to native.

Test clang/test/Driver/riscv-march-mcpu-mtune.c will failed if we
specify different default CPU.

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptFeb 27 2023, 1:33 AM
pcwang-thead requested review of this revision.Feb 27 2023, 1:33 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 27 2023, 1:33 AM
asb added a comment.Feb 27 2023, 8:09 AM

If this is a useful thing to have, would it make more sense as a target-independent option?

craig.topper added inline comments.Feb 27 2023, 9:15 PM
clang/lib/Driver/ToolChains/Arch/RISCV.cpp
322

Can we initialize CPU to the default CPU at the top? Remove the CPU.empty() check. Then we don't need a second "native" check.

If this is a useful thing to have, would it make more sense as a target-independent option?

Yes, I agree.

I need to do some researches here to figure out if all targets have the same behavior for CPU generic and some other stuffs.

Would this make more sense in a config file rather than a CMake option? @MaskRay

I object to this change which further complicates the build system and makes the difference difficult to observe by users.
If your clang executable is at bin/clang, just create bin/riscv64-unknown-linux-gnu.cfg with -mcpu=xxx.
You may configure LLVM_DEFAULT_TARGET_TRIPLE=riscv64-unknown-linux-gnu so that the driver doesn't need extra --target=.

pcwang-thead abandoned this revision.Feb 28 2023, 12:34 AM

I object to this change which further complicates the build system and makes the difference difficult to observe by users.
If your clang executable is at bin/clang, just create bin/riscv64-unknown-linux-gnu.cfg with -mcpu=xxx.
You may configure LLVM_DEFAULT_TARGET_TRIPLE=riscv64-unknown-linux-gnu so that the driver doesn't need extra --target=.

Thanks! I almost forget about config file.
I think this change is unnecessary now and thanks all for your time to review this patch. :-)