[PATCH] D96039: [JITLink] Infer default value for -use-orc-runtime option from CMake

Stefan Gränitz via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 4 07:49:53 PST 2021


sgraenitz created this revision.
sgraenitz added a reviewer: lhames.
Herald added a subscriber: mgorny.
sgraenitz requested review of this revision.
Herald added a project: LLVM.

If compiler-rt is enabled and the ORC runtime target for the active platform exists, we can default enable the UseOrcRuntime option in llvm-jitlink.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96039

Files:
  llvm/tools/llvm-jitlink/CMakeLists.txt
  llvm/tools/llvm-jitlink/llvm-jitlink-config.h.in
  llvm/tools/llvm-jitlink/llvm-jitlink.cpp


Index: llvm/tools/llvm-jitlink/llvm-jitlink.cpp
===================================================================
--- llvm/tools/llvm-jitlink/llvm-jitlink.cpp
+++ llvm/tools/llvm-jitlink/llvm-jitlink.cpp
@@ -50,6 +50,8 @@
 #include <unistd.h>
 #endif // LLVM_ON_UNIX
 
+#include "llvm-jitlink-config.h"
+
 #define DEBUG_TYPE "llvm_jitlink"
 
 using namespace llvm;
@@ -155,10 +157,10 @@
     "oop-executor-connect",
     cl::desc("Connect to an out-of-process executor via TCP"));
 
-// TODO: Default to false if compiler-rt is not built.
-static cl::opt<bool> UseOrcRuntime("use-orc-runtime",
-                                   cl::desc("Do not required/load ORC runtime"),
-                                   cl::init(true));
+static cl::opt<bool>
+    UseOrcRuntime("use-orc-runtime",
+                  cl::desc("Do not required/load ORC runtime"),
+                  cl::init(LLVM_JITLINK_USE_ORC_RUNTIME_DEFAULT));
 
 static cl::opt<std::string>
     OrcRuntimePath("orc-runtime-path", cl::desc("Add orc runtime to session"),
@@ -1101,7 +1103,14 @@
                         "lib/clang/12.0.0/lib/darwin/libclang_rt.orc_osx.a");
       OrcRuntimePath = DefaultOrcRuntimePath.str().str();
     }
+
+    if (!sys::fs::exists(OrcRuntimePath))
+      return make_error<StringError>(
+          formatv("Cannot find static archive for ORC runtime: {0}",
+                  OrcRuntimePath),
+          inconvertibleErrorCode());
   }
+
   return Error::success();
 }
 
Index: llvm/tools/llvm-jitlink/llvm-jitlink-config.h.in
===================================================================
--- /dev/null
+++ llvm/tools/llvm-jitlink/llvm-jitlink-config.h.in
@@ -0,0 +1 @@
+#define LLVM_JITLINK_USE_ORC_RUNTIME_DEFAULT @USE_ORC_RUNTIME_DEFAULT@
Index: llvm/tools/llvm-jitlink/CMakeLists.txt
===================================================================
--- llvm/tools/llvm-jitlink/CMakeLists.txt
+++ llvm/tools/llvm-jitlink/CMakeLists.txt
@@ -24,4 +24,22 @@
   llvm-jitlink-macho.cpp
   )
 
+# If compiler-rt is enabled in this build and the ORC runtime target
+# for our platform exists, we can default enable the UseOrcRuntime option
+# in llvm-jitlink.
+if (APPLE AND CMAKE_SYSTEM_NAME MATCHES Darwin)
+  # We cannot use get_target_property() here, because compiler-rt is configured
+  # after LLVM (so the respective target doesn't exist yet). Instead we use a
+  # generator expression, which evaluates after all targets were configured.
+  # For that to work we add a manual generation-step for the config file below.
+  set(USE_ORC_RUNTIME_DEFAULT $<TARGET_EXISTS:clang_rt.orc_osx>)
+else()
+  set(USE_ORC_RUNTIME_DEFAULT 0)
+endif()
+
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/llvm-jitlink-config.h.in
+               ${CMAKE_CURRENT_BINARY_DIR}/llvm-jitlink-config.h.conf @ONLY)
+file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/llvm-jitlink-config.h
+              INPUT ${CMAKE_CURRENT_BINARY_DIR}/llvm-jitlink-config.h.conf)
+
 export_executable_symbols(llvm-jitlink)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D96039.321429.patch
Type: text/x-patch
Size: 2991 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210204/89c8c732/attachment.bin>


More information about the llvm-commits mailing list