[clang] 66af90b - [darwin][driver] Pass through -global-isel LLVM flags to ld.

Amara Emerson via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 22 17:23:53 PDT 2021


Author: Amara Emerson
Date: 2021-03-22T17:23:06-07:00
New Revision: 66af90b46e1fe395806474dde2d49b8dc78bae1a

URL: https://github.com/llvm/llvm-project/commit/66af90b46e1fe395806474dde2d49b8dc78bae1a
DIFF: https://github.com/llvm/llvm-project/commit/66af90b46e1fe395806474dde2d49b8dc78bae1a.diff

LOG: [darwin][driver] Pass through -global-isel LLVM flags to ld.

GlobalISel is currently not enabled when using -flto since the front-end
-mvllm flags don't get passed through. This change fixes this for Darwin
platforms. We have to do this in the driver because the code generator choice
isn't embedded into the bitcode file.

Differential Revision: https://reviews.llvm.org/D99126

Added: 
    

Modified: 
    clang/lib/Driver/ToolChains/Darwin.cpp
    clang/test/Driver/darwin-ld-lto.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp
index a09a69f946ef..bc59b6beafc7 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -373,6 +373,18 @@ void darwin::Linker::AddLinkArgs(Compilation &C, const ArgList &Args,
       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)) {
+      CmdArgs.push_back("-mllvm");
+      CmdArgs.push_back("-global-isel");
+      // Disable abort and fall back to SDAG silently.
+      CmdArgs.push_back("-mllvm");
+      CmdArgs.push_back("-global-isel-abort=0");
+    }
+  }
+
   Args.AddLastArg(CmdArgs, options::OPT_prebind);
   Args.AddLastArg(CmdArgs, options::OPT_noprebind);
   Args.AddLastArg(CmdArgs, options::OPT_nofixprebinding);

diff  --git a/clang/test/Driver/darwin-ld-lto.c b/clang/test/Driver/darwin-ld-lto.c
index 05e6bccd00f0..252ca148c520 100644
--- a/clang/test/Driver/darwin-ld-lto.c
+++ b/clang/test/Driver/darwin-ld-lto.c
@@ -30,3 +30,11 @@
 // THIN_LTO_OBJECT_PATH: {{ld(.exe)?"}}
 // THIN_LTO_OBJECT_PATH-SAME: "-object_path_lto"
 // THIN_LTO_OBJECT_PATH-SAME: {{thinlto\-[a-zA-Z0-9_]+}}
+
+
+// Check that we pass through -fglobal-isel flags to libLTO.
+// RUN: %clang -target arm64-apple-darwin %s -flto -fglobal-isel -### 2>&1 | \
+// RUN:   FileCheck --check-prefix=GISEL %s
+// GISEL: {{ld(.exe)?"}}
+// GISEL: "-mllvm" "-global-isel"
+// GISEL: "-mllvm" "-global-isel-abort=0"


        


More information about the cfe-commits mailing list