[PATCH] D136425: [Clang][AArch64] Add support for -mcpu=grace

Sjoerd Meijer via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 21 08:39:36 PDT 2022


SjoerdMeijer updated this revision to Diff 469619.
SjoerdMeijer added a comment.

This now uses a new helper `resolveCPUAlias`.

> can you make sure that llc -mcpu=grace also works, in the next version of the patch?

Hm, this is a good point. And, of course, it doesn't work yet, that would have been too easy. 
The problem of course is that options parsing is all over the place, the MC layers has its own bits and pieces, which doesn't handle this yet so would need to resolve aliases in some way.

So what this patch achieves is that the user-facing tool Clang understands mcpu=grace, but the developer tools (opt, llc) not yet. That is certainly not ideal, but probably something I can live with as a first step.

> You cannot put grace into this file:
> https://github.com/llvm/llvm-project/blob/main/llvm/lib/Target/AArch64/AArch64.td
> With the same settings as a neoverse-v2?

In my first revision I had a grace definition in AArch64TargetParser.def. Fair enough, that was the Clang side, not LLVM, but point is that if a CPU is pure alias we want to map onto an existing definition, which we don't achieve in that way.

I think I am half happy for now; this patch addresses the Clang part, the not yet existing LLVM part counter part needs looking into.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D136425/new/

https://reviews.llvm.org/D136425

Files:
  clang/lib/Driver/ToolChains/Arch/AArch64.cpp
  clang/test/Driver/aarch64-mcpu.c
  llvm/include/llvm/Support/AArch64TargetParser.h


Index: llvm/include/llvm/Support/AArch64TargetParser.h
===================================================================
--- llvm/include/llvm/Support/AArch64TargetParser.h
+++ llvm/include/llvm/Support/AArch64TargetParser.h
@@ -138,6 +138,13 @@
 StringRef getArchExtFeature(StringRef ArchExt);
 ArchKind convertV9toV8(ArchKind AK);
 
+// FIXME: We should be able to define CPU aliases in TargetParser.
+inline StringRef resolveCPUAlias(StringRef CPU) {
+  if (CPU == "grace")
+    return "neoverse-v2";
+  return CPU;
+}
+
 // Information by Name
 unsigned getDefaultFPU(StringRef CPU, ArchKind AK);
 uint64_t getDefaultExtensions(StringRef CPU, ArchKind AK);
Index: clang/test/Driver/aarch64-mcpu.c
===================================================================
--- clang/test/Driver/aarch64-mcpu.c
+++ clang/test/Driver/aarch64-mcpu.c
@@ -61,6 +61,9 @@
 // RUN: %clang -target aarch64 -mcpu=cortex-r82  -### -c %s 2>&1 | FileCheck -check-prefix=CORTEXR82 %s
 // CORTEXR82: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "cortex-r82"
 
+// RUN: %clang -target aarch64 -mcpu=grace -### -c %s 2>&1 | FileCheck -check-prefix=GRACE %s
+// GRACE: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "neoverse-v2"
+
 // ================== Check whether -mcpu and -mtune accept mixed-case values.
 // RUN: %clang -target aarch64 -mcpu=Cortex-a53 -### -c %s 2>&1 | FileCheck -check-prefix=CASE-INSENSITIVE-CA53 %s
 // RUN: %clang -target aarch64 -mtune=Cortex-a53 -### -c %s 2>&1 | FileCheck -check-prefix=CASE-INSENSITIVE-CA53-TUNE %s
Index: clang/lib/Driver/ToolChains/Arch/AArch64.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Arch/AArch64.cpp
+++ clang/lib/Driver/ToolChains/Arch/AArch64.cpp
@@ -38,6 +38,8 @@
     CPU = Mcpu.split("+").first.lower();
   }
 
+  CPU = llvm::AArch64::resolveCPUAlias(CPU);
+
   // Handle CPU name is 'native'.
   if (CPU == "native")
     return std::string(llvm::sys::getHostCPUName());
@@ -121,6 +123,8 @@
   CPU = Split.first;
   llvm::AArch64::ArchKind ArchKind = llvm::AArch64::ArchKind::ARMV8A;
 
+  CPU = llvm::AArch64::resolveCPUAlias(CPU);
+
   if (CPU == "native")
     CPU = llvm::sys::getHostCPUName();
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D136425.469619.patch
Type: text/x-patch
Size: 2219 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221021/5f3cecc0/attachment.bin>


More information about the llvm-commits mailing list