[PATCH] D99312: [lld-macho] Add support for --threads

Jez Ng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 24 17:52:28 PDT 2021


int3 created this revision.
int3 added a reviewer: lld-macho.
Herald added a subscriber: dang.
Herald added a project: lld-macho.
int3 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Code and test are largely identical to the LLD-ELF equivalents.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99312

Files:
  lld/MachO/Driver.cpp
  lld/MachO/Options.td
  lld/test/MachO/threads.s


Index: lld/test/MachO/threads.s
===================================================================
--- /dev/null
+++ lld/test/MachO/threads.s
@@ -0,0 +1,16 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o
+
+## A positive integer is allowed.
+# RUN: %lld --threads=1 %t.o -o /dev/null
+# RUN: %lld --threads=2 %t.o -o /dev/null
+
+# RUN: not %lld --threads=all %t.o -o /dev/null 2>&1 | FileCheck %s -DN=all
+# RUN: not %lld --threads=0 %t.o -o /dev/null 2>&1 | FileCheck %s -DN=0
+# RUN: not %lld --threads=-1 %t.o -o /dev/null 2>&1 | FileCheck %s -DN=-1
+
+# CHECK: error: --threads=: expected a positive integer, but got '[[N]]'
+
+.globl _main
+_main:
+  ret
Index: lld/MachO/Options.td
===================================================================
--- lld/MachO/Options.td
+++ lld/MachO/Options.td
@@ -20,6 +20,9 @@
     HelpText<"Use colors in diagnostics (default: auto)">,
     MetaVarName<"[auto,always,never]">,
     Group<grp_lld>;
+def threads_eq : Joined<["--"], "threads=">,
+    HelpText<"Number of threads. '1' disables multi-threading. By default all available hardware threads are used">,
+    Group<grp_lld>;
 def reproduce: Separate<["--"], "reproduce">,
     Group<grp_lld>;
 def reproduce_eq: Joined<["--"], "reproduce=">,
Index: lld/MachO/Driver.cpp
===================================================================
--- lld/MachO/Driver.cpp
+++ lld/MachO/Driver.cpp
@@ -38,6 +38,7 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Host.h"
 #include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/Parallel.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/TarWriter.h"
 #include "llvm/Support/TargetSelect.h"
@@ -852,6 +853,16 @@
   symtab = make<SymbolTable>();
   target = createTargetInfo(args);
 
+  if (auto *arg = args.getLastArg(OPT_threads_eq)) {
+    StringRef v(arg->getValue());
+    unsigned threads = 0;
+    if (!llvm::to_integer(v, threads, 0) || threads == 0)
+      error(arg->getSpelling() + ": expected a positive integer, but got '" +
+            arg->getValue() + "'");
+    parallel::strategy = hardware_concurrency(threads);
+    // FIXME: use this to configure ThinLTO concurrency too
+  }
+
   config->entry = symtab->addUndefined(args.getLastArgValue(OPT_e, "_main"),
                                        /*file=*/nullptr,
                                        /*isWeakRef=*/false);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99312.333183.patch
Type: text/x-patch
Size: 2416 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210325/f46e030f/attachment.bin>


More information about the llvm-commits mailing list