[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 07:07:18 PDT 2022


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

Following Shushant's suggestion, the number of changes have been reduced to basically a 2-liner:

- Grace no longer exits as CPU definition in TargetParser,
- the downside is that it no longer appears as a suggestion of a valid CPU when an invalid one is given (`clang/test/Misc/target-invalid-cpu-note.c`)

> I think having an alias capability would be useful, particularly as we sometimes want to enable codenames before an official CPU launch (like happened with "zeus" and "demeter" in GCC) and want to retain the codenames for backwards compatibility with released toolchains. Having "grace" as an explicit alias of "neoverse-v2" would also ensure that any improvements folks make to its tuning benefit "neoverse-v2" as well. If they need to deviate in the future for some good reason then we can be explicit about it and split them into separate CPU options.

Ok, I see there's a use-case for this. Not sure how often code-names comes up for us though, but hey, I could use an alias capability here. So how about this as a strategy. This patch has been reduced to a 2-liner, so impact on the codebase is minimal. I have placed a FIXME that CPU aliases should be supported in TargetParser. Can we support grace like this, while I work on your feature request (free of charge ;-))? A new feature requires a bit of surgery here and there, and it would be nice if grace support doesn't depend on that. Once we have the infrastructure, I will port grace over to that as a first use-case.

What do you think?


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


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,10 @@
     CPU = Mcpu.split("+").first.lower();
   }
 
+  // FIXME: We should be able to define CPU aliases in TargetParser.
+  if (CPU == "grace")
+    return "neoverse-v2";
+
   // Handle CPU name is 'native'.
   if (CPU == "native")
     return std::string(llvm::sys::getHostCPUName());
@@ -124,6 +128,10 @@
   if (CPU == "native")
     CPU = llvm::sys::getHostCPUName();
 
+  // FIXME: We should be able to define CPU aliases in TargetParser.
+  if(CPU == "grace")
+    CPU="neoverse-v2";
+
   if (CPU == "generic") {
     Features.push_back("+neon");
   } else {


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


More information about the llvm-commits mailing list