[llvm] 0c68155 - [llvm-jitlink] Fix llvm-jitlink for LLVM_ENABLE_THREADS=Off.

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 1 23:23:53 PST 2025


Author: Lang Hames
Date: 2025-01-02T18:23:46+11:00
New Revision: 0c68155002edb30d6b0df3f17fe1f44a01afacd9

URL: https://github.com/llvm/llvm-project/commit/0c68155002edb30d6b0df3f17fe1f44a01afacd9
DIFF: https://github.com/llvm/llvm-project/commit/0c68155002edb30d6b0df3f17fe1f44a01afacd9.diff

LOG: [llvm-jitlink] Fix llvm-jitlink for LLVM_ENABLE_THREADS=Off.

Commit edca1d9bad2 enabled threaded linking by default in llvm-jitlink, but we
need to handle the case where LLVM is built with -DLLVM_ENABLE_THREADS=Off.

This patch updates the llvm-jitlink tool to switch back to materialization on
the main thread (equivalent to llvm-jitlink -num-threads=0 ...) when LLVM is
built without thread support.

Added: 
    

Modified: 
    llvm/tools/llvm-jitlink/llvm-jitlink.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
index 5b238233172796..646d4cef01a57b 100644
--- a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
+++ b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
@@ -996,9 +996,14 @@ Expected<std::unique_ptr<Session>> Session::Create(Triple TT,
     std::unique_ptr<TaskDispatcher> Dispatcher;
     if (MaterializationThreads == 0)
       Dispatcher = std::make_unique<InPlaceTaskDispatcher>();
-    else
+    else {
+#if LLVM_ENABLE_THREADS
       Dispatcher = std::make_unique<DynamicThreadPoolTaskDispatcher>(
           MaterializationThreads);
+#else
+      llvm_unreachable("MaterializationThreads should be 0");
+#endif
+    }
 
     EPC = std::make_unique<SelfExecutorProcessControl>(
         std::make_shared<SymbolStringPool>(), std::move(Dispatcher),
@@ -1628,15 +1633,24 @@ static Error sanitizeArguments(const Triple &TT, const char *ArgV0) {
     }
   }
 
+#if LLVM_ENABLE_THREADS
   if (MaterializationThreads == std::numeric_limits<size_t>::max()) {
     if (auto HC = std::thread::hardware_concurrency())
       MaterializationThreads = HC;
     else {
       errs() << "Warning: std::thread::hardware_concurrency() returned 0, "
-                "defaulting to -threads=1.\n";
+                "defaulting to -num-threads=1.\n";
       MaterializationThreads = 1;
     }
   }
+#else
+  if (MaterializationThreads.getNumOccurrences() &&
+      MaterializationThreads != 0) {
+    errs() << "Warning: -num-threads was set, but LLVM was built with threads "
+              "disabled. Resetting to -num-threads=0\n";
+  }
+  MaterializationThreads = 0;
+#endif
 
   if (!!OutOfProcessExecutor.getNumOccurrences() ||
       !!OutOfProcessExecutorConnect.getNumOccurrences()) {


        


More information about the llvm-commits mailing list