This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Support -mcpu/mtune=native
ClosedPublic

Authored by pcwang-thead on Oct 28 2022, 2:35 AM.

Details

Summary

We may need hosted Clang/LLVM to compile and getHostCpuName
can be used for native detection.

Tests are added in riscv-cpus.c just like what AArch64/PPC
have done.

Diff Detail

Event Timeline

pcwang-thead requested review of this revision.Oct 28 2022, 2:35 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 28 2022, 2:35 AM
pcwang-thead edited the summary of this revision. (Show Details)Oct 28 2022, 2:37 AM
craig.topper added inline comments.Oct 30 2022, 7:57 PM
clang/lib/Driver/ToolChains/Clang.cpp
2190–2193

Why can't we use A->getValue() == "native" here?

clang/lib/Driver/ToolChains/Clang.cpp
2190–2193

Because newly-changed support of other targets (like PowerPC) are in this form, so I think this may benefit from simplification?

kito-cheng added inline comments.Oct 31 2022, 9:44 AM
clang/lib/Driver/ToolChains/Clang.cpp
2190–2193

A->getValue return const char * rather than StringRef? maybe we could use StringRef(A->getValue()) == "native" like X86 to improve that?

https://llvm.org/doxygen/classllvm_1_1opt_1_1Arg.html

grep result from clang folder:

$ grpe "\"native\"" * -R
lib/Driver/ToolChains/Clang.cpp:    if (strcmp(A->getValue(), "native") == 0)
lib/Driver/ToolChains/Clang.cpp:    if (strcmp(A->getValue(), "native") == 0)
lib/Driver/ToolChains/Clang.cpp:    if (Name == "native")
lib/Driver/ToolChains/Clang.cpp:    if (strcmp(A->getValue(), "native") == 0)
lib/Driver/ToolChains/Clang.cpp:    if (Name == "native") {
lib/Driver/ToolChains/CommonArgs.cpp:    // Handle "native" by examining the host. "native" isn't meaningful when
lib/Driver/ToolChains/CommonArgs.cpp:    if (CPU == "native")
lib/Driver/ToolChains/Arch/SystemZ.cpp:    if (CPUName == "native") {
lib/Driver/ToolChains/Arch/X86.cpp:    if (CPU != "native")
lib/Driver/ToolChains/Arch/X86.cpp:    if (StringRef(A->getValue()) == "native") {
lib/Driver/ToolChains/Arch/PPC.cpp:    if (CPUName == "native") {
lib/Driver/ToolChains/Arch/AArch64.cpp:  if (CPU == "native")
lib/Driver/ToolChains/Arch/AArch64.cpp:  if (CPU == "native")
lib/Driver/ToolChains/Arch/AArch64.cpp:  if (Split.first == "native")
lib/Driver/ToolChains/Arch/AArch64.cpp:  if (MtuneLowerCase == "native")
lib/Driver/ToolChains/Arch/Sparc.cpp:    if (CPUName == "native") {
lib/Driver/ToolChains/Arch/ARM.cpp:  if (CPUName == "native") {
lib/Driver/ToolChains/Arch/ARM.cpp:  if (MArch == "native") {
lib/Driver/ToolChains/Arch/ARM.cpp:    if (MCPU == "native")
lib/Driver/ToolChains/Arch/M68k.cpp:    if (CPUName == "native") {
craig.topper added inline comments.Oct 31 2022, 10:21 AM
clang/lib/Driver/ToolChains/Clang.cpp
2190–2193

Thanks. I guess strcmp makes sense then to avoid an implicit call to strlen in the StringRef constructor.

  • Add release note.
  • Add tests to riscv-cpus.c.
  • Add getRISCVTargetCPU.
  • Make diagnostic more exact for native.
pcwang-thead edited the summary of this revision. (Show Details)Nov 2 2022, 12:07 AM
This revision is now accepted and ready to land.Nov 4 2022, 9:57 AM
This revision was automatically updated to reflect the committed changes.