[PATCH] D137269: [Clang][AArch64][Darwin] Enable GlobalISel by default for Darwin ARM64 platforms.

Amara Emerson via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 2 10:07:34 PDT 2022


aemerson created this revision.
aemerson added reviewers: paquette, Gerolf, ab, t.p.northover, arsenm.
aemerson added a project: LLVM.
Herald added a subscriber: kristof.beyls.
Herald added a project: All.
aemerson requested review of this revision.
Herald added subscribers: MaskRay, wdng.
Herald added a project: clang.

We do this in the front-end instead of the backend so as to not change the default behavior for llc.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137269

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/test/Driver/global-isel.c


Index: clang/test/Driver/global-isel.c
===================================================================
--- clang/test/Driver/global-isel.c
+++ clang/test/Driver/global-isel.c
@@ -6,6 +6,7 @@
 // RUN: %clang -target aarch64 -fglobal-isel -S %s -### 2>&1 | FileCheck --check-prefix=ARM64-DEFAULT %s
 // RUN: %clang -target aarch64 -fglobal-isel -S -O0 %s -### 2>&1 | FileCheck --check-prefix=ARM64-O0 %s
 // RUN: %clang -target aarch64 -fglobal-isel -S -O2 %s -### 2>&1 | FileCheck --check-prefix=ARM64-O2 %s
+// RUN: %clang -arch arm64 -fglobal-isel -S -O2 %s -### 2>&1 | FileCheck --check-prefixes=DARWIN-ARM64-O2,ENABLED %s
 // RUN: %clang -target aarch64 -fglobal-isel -Wno-global-isel -S -O2 %s -### 2>&1 | FileCheck --check-prefix=ARM64-O2-NOWARN %s
 
 // RUN: %clang -target x86_64 -fglobal-isel -S %s -### 2>&1 | FileCheck --check-prefix=X86_64 %s
@@ -27,6 +28,7 @@
 // ARM64-DEFAULT-NOT: warning: -fglobal-isel
 // ARM64-DEFAULT-NOT: "-global-isel-abort=2"
 // ARM64-O0-NOT: warning: -fglobal-isel
+// DARWIN-ARM64-O2-NOT: warning: -fglobal-isel
 // ARM64-O2: warning: -fglobal-isel support is incomplete for this architecture at the current optimization level
 // ARM64-O2: "-mllvm" "-global-isel-abort=2"
 // ARM64-O2-NOWARN-NOT: warning: -fglobal-isel
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -381,10 +381,11 @@
       D.Diag(diag::err_drv_bitcode_unsupported_on_toolchain);
   }
 
-  // If GlobalISel is enabled, pass it through to LLVM.
-  if (Arg *A = Args.getLastArg(options::OPT_fglobal_isel,
-                               options::OPT_fno_global_isel)) {
-    if (A->getOption().matches(options::OPT_fglobal_isel)) {
+  // GlobalISel is enabled by default on AArch64 Darwin.
+  if (getToolChain().getArch() == llvm::Triple::aarch64) {
+    Arg *A = Args.getLastArg(options::OPT_fglobal_isel,
+                             options::OPT_fno_global_isel);
+    if (!A || !A->getOption().matches(options::OPT_fno_global_isel)) {
       CmdArgs.push_back("-mllvm");
       CmdArgs.push_back("-global-isel");
       // Disable abort and fall back to SDAG silently.
Index: clang/lib/Driver/ToolChains/Clang.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -7203,15 +7203,29 @@
   if (SplitLTOUnit)
     CmdArgs.push_back("-fsplit-lto-unit");
 
-  if (Arg *A = Args.getLastArg(options::OPT_fglobal_isel,
-                               options::OPT_fno_global_isel)) {
+  A = Args.getLastArg(options::OPT_fglobal_isel, options::OPT_fno_global_isel);
+  // If a configuration is fully supported, we don't issue any warnings or
+  // remarks.
+  bool IsFullySupported = getToolChain().getTriple().isOSDarwin() &&
+                          Triple.getArch() == llvm::Triple::aarch64;
+  if (IsFullySupported) {
+    if (A && A->getOption().matches(options::OPT_fno_global_isel)) {
+      CmdArgs.push_back("-mllvm");
+      CmdArgs.push_back("-global-isel=0");
+    } else {
+      CmdArgs.push_back("-mllvm");
+      CmdArgs.push_back("-global-isel=1");
+      CmdArgs.push_back("-mllvm");
+      CmdArgs.push_back("-global-isel-abort=0");
+    }
+  } else if (A) {
     CmdArgs.push_back("-mllvm");
     if (A->getOption().matches(options::OPT_fglobal_isel)) {
       CmdArgs.push_back("-global-isel=1");
 
       // GISel is on by default on AArch64 -O0, so don't bother adding
       // the fallback remarks for it. Other combinations will add a warning of
-      // some kind.
+      // some kind, unless we're on Darwin.
       bool IsArchSupported = Triple.getArch() == llvm::Triple::aarch64;
       bool IsOptLevelSupported = false;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137269.472668.patch
Type: text/x-patch
Size: 3826 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221102/b81eada7/attachment.bin>


More information about the cfe-commits mailing list