[llvm] [ORC-RT] Initial check-in for a new, top-level ORC runtime project. (PR #113499)

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 23 17:25:31 PDT 2024


https://github.com/lhames updated https://github.com/llvm/llvm-project/pull/113499

>From fb7698d5d1377e85d1fd6a00fcbbc5a87cbb1323 Mon Sep 17 00:00:00 2001
From: Lang Hames <lhames at gmail.com>
Date: Thu, 24 Oct 2024 08:23:41 +1100
Subject: [PATCH 1/2] [ORC-RT] Initial check-in for a new, top-level ORC
 runtime project.

Includes CMake files and a placeholder header, library, and tool.

See discussion at
https://discourse.llvm.org/t/rfc-move-orc-executor-support-into-top-level-project/81049
---
 llvm/CMakeLists.txt                        |  2 +-
 llvm/projects/CMakeLists.txt               |  2 +
 orc-rt/CMakeLists.txt                      | 47 ++++++++++++++++++++++
 orc-rt/include/orc-rt-c/orc-rt.h           | 27 +++++++++++++
 orc-rt/lib/CMakeLists.txt                  |  1 +
 orc-rt/lib/prelink/CMakeLists.txt          |  1 +
 orc-rt/lib/prelink/orc-rt-prelink.cpp      |  5 +++
 orc-rt/tools/CMakeLists.txt                |  1 +
 orc-rt/tools/orc-executor/CMakeLists.txt   |  3 ++
 orc-rt/tools/orc-executor/orc-executor.cpp |  6 +++
 runtimes/CMakeLists.txt                    |  2 +-
 11 files changed, 95 insertions(+), 2 deletions(-)
 create mode 100644 orc-rt/CMakeLists.txt
 create mode 100644 orc-rt/include/orc-rt-c/orc-rt.h
 create mode 100644 orc-rt/lib/CMakeLists.txt
 create mode 100644 orc-rt/lib/prelink/CMakeLists.txt
 create mode 100644 orc-rt/lib/prelink/orc-rt-prelink.cpp
 create mode 100644 orc-rt/tools/CMakeLists.txt
 create mode 100644 orc-rt/tools/orc-executor/CMakeLists.txt
 create mode 100644 orc-rt/tools/orc-executor/orc-executor.cpp

diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt
index cde4a999ea2e74..19e2eb9ae4108b 100644
--- a/llvm/CMakeLists.txt
+++ b/llvm/CMakeLists.txt
@@ -155,7 +155,7 @@ endif()
 # As we migrate runtimes to using the bootstrapping build, the set of default runtimes
 # should grow as we remove those runtimes from LLVM_ENABLE_PROJECTS above.
 set(LLVM_DEFAULT_RUNTIMES "libcxx;libcxxabi;libunwind")
-set(LLVM_SUPPORTED_RUNTIMES "libc;libunwind;libcxxabi;pstl;libcxx;compiler-rt;openmp;llvm-libgcc;offload")
+set(LLVM_SUPPORTED_RUNTIMES "libc;libunwind;libcxxabi;pstl;libcxx;compiler-rt;openmp;llvm-libgcc;offload;orc-rt")
 set(LLVM_ENABLE_RUNTIMES "" CACHE STRING
   "Semicolon-separated list of runtimes to build, or \"all\" (${LLVM_DEFAULT_RUNTIMES}). Supported runtimes are ${LLVM_SUPPORTED_RUNTIMES}.")
 if(LLVM_ENABLE_RUNTIMES STREQUAL "all")
diff --git a/llvm/projects/CMakeLists.txt b/llvm/projects/CMakeLists.txt
index 08f2fa522420b0..4bf482365feb1b 100644
--- a/llvm/projects/CMakeLists.txt
+++ b/llvm/projects/CMakeLists.txt
@@ -9,6 +9,7 @@ foreach(entry ${entries})
        (NOT ${entry} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}/libcxx) AND
        (NOT ${entry} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}/libcxxabi) AND
        (NOT ${entry} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}/libunwind) AND
+       (NOT ${entry} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}/orc-rt) AND
        (NOT ${entry} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}/test-suite) AND
        (NOT ${entry} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}/openmp) AND
        (NOT ${entry} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}/cross-project-tests))
@@ -33,6 +34,7 @@ if(${LLVM_BUILD_RUNTIME})
     add_llvm_external_project(libc)
     add_llvm_external_project(libcxxabi)
     add_llvm_external_project(libcxx)
+    add_llvm_external_project(orc-rt)
   endif()
   if(NOT LLVM_BUILD_EXTERNAL_COMPILER_RT)
     add_llvm_external_project(compiler-rt)
diff --git a/orc-rt/CMakeLists.txt b/orc-rt/CMakeLists.txt
new file mode 100644
index 00000000000000..f48773e1bed7f0
--- /dev/null
+++ b/orc-rt/CMakeLists.txt
@@ -0,0 +1,47 @@
+# CMake build for ORC-RT.
+
+#===============================================================================
+# Setup Project
+#===============================================================================
+
+cmake_minimum_required(VERSION 3.20.0)
+set(LLVM_SUBPROJECT_TITLE "orc-rt")
+
+set(LLVM_COMMON_CMAKE_UTILS ${CMAKE_CURRENT_SOURCE_DIR}/../cmake)
+
+include(${LLVM_COMMON_CMAKE_UTILS}/Modules/CMakePolicy.cmake
+  NO_POLICY_SCOPE)
+
+# Add path for custom orc-rt modules.
+list(INSERT CMAKE_MODULE_PATH 0
+#  "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
+#  "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
+  "${LLVM_COMMON_CMAKE_UTILS}"
+  "${LLVM_COMMON_CMAKE_UTILS}/Modules"
+  )
+
+set(CMAKE_FOLDER "orc-rt")
+
+set(LIBORCRT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
+set(LIBORCRT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
+
+#===============================================================================
+# Setup CMake Options
+#===============================================================================
+
+set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to conform to")
+set(CMAKE_CXX_STANDARD_REQUIRED YES)
+set(CMAKE_CXX_EXTENSIONS NO)
+
+#================================
+# Setup Compiler Flags
+#================================
+
+# Configure compiler. Must happen after setting the target flags.
+
+#===============================================================================
+# Setup Source Code
+#===============================================================================
+
+add_subdirectory(lib)
+add_subdirectory(tools)
diff --git a/orc-rt/include/orc-rt-c/orc-rt.h b/orc-rt/include/orc-rt-c/orc-rt.h
new file mode 100644
index 00000000000000..fdc0fd29976d4a
--- /dev/null
+++ b/orc-rt/include/orc-rt-c/orc-rt.h
@@ -0,0 +1,27 @@
+/*===- orc-rt-c/orc-rt.h - Placeholder header for orc-rt ----------*- C -*-===*\
+|*                                                                            *|
+|* Part of the LLVM Project, under the Apache License v2.0 with LLVM          *|
+|* Exceptions.                                                                *|
+|* See https://llvm.org/LICENSE.txt for license information.                  *|
+|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception                    *|
+|*                                                                            *|
+|*===----------------------------------------------------------------------===*|
+|*                                                                            *|
+|* Placeholder header for initial orc-rt checkin                              *|
+|*                                                                            *|
+\*===----------------------------------------------------------------------===*/
+
+#ifndef ORC_RT_C_ORC_RT_H
+#define ORC_RT_C_ORC_RT_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void orc_rt(void);
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif /* ORC_RT_C_ORC_RT_H */
diff --git a/orc-rt/lib/CMakeLists.txt b/orc-rt/lib/CMakeLists.txt
new file mode 100644
index 00000000000000..6080b84a51fcad
--- /dev/null
+++ b/orc-rt/lib/CMakeLists.txt
@@ -0,0 +1 @@
+add_subdirectory(prelink)
diff --git a/orc-rt/lib/prelink/CMakeLists.txt b/orc-rt/lib/prelink/CMakeLists.txt
new file mode 100644
index 00000000000000..4e951e77764369
--- /dev/null
+++ b/orc-rt/lib/prelink/CMakeLists.txt
@@ -0,0 +1 @@
+add_library(orc-rt-prelink STATIC orc-rt-prelink.cpp)
diff --git a/orc-rt/lib/prelink/orc-rt-prelink.cpp b/orc-rt/lib/prelink/orc-rt-prelink.cpp
new file mode 100644
index 00000000000000..d24d5838a25cc9
--- /dev/null
+++ b/orc-rt/lib/prelink/orc-rt-prelink.cpp
@@ -0,0 +1,5 @@
+#include <stdio.h>
+
+extern "C" void orc_rt(void) {
+  printf("hello, world!\n");
+}
diff --git a/orc-rt/tools/CMakeLists.txt b/orc-rt/tools/CMakeLists.txt
new file mode 100644
index 00000000000000..fc78ea41316067
--- /dev/null
+++ b/orc-rt/tools/CMakeLists.txt
@@ -0,0 +1 @@
+add_subdirectory(orc-executor)
diff --git a/orc-rt/tools/orc-executor/CMakeLists.txt b/orc-rt/tools/orc-executor/CMakeLists.txt
new file mode 100644
index 00000000000000..7750afc61c4b84
--- /dev/null
+++ b/orc-rt/tools/orc-executor/CMakeLists.txt
@@ -0,0 +1,3 @@
+add_executable(orc-executor orc-executor.cpp)
+target_link_libraries(orc-executor PRIVATE orc-rt-prelink)
+target_include_directories(orc-executor PRIVATE ../../include)
diff --git a/orc-rt/tools/orc-executor/orc-executor.cpp b/orc-rt/tools/orc-executor/orc-executor.cpp
new file mode 100644
index 00000000000000..4a03ac64710d22
--- /dev/null
+++ b/orc-rt/tools/orc-executor/orc-executor.cpp
@@ -0,0 +1,6 @@
+#include "orc-rt-c/orc-rt.h"
+
+int main(int argc, char *argv[]) {
+  orc_rt();
+  return 0;
+}
diff --git a/runtimes/CMakeLists.txt b/runtimes/CMakeLists.txt
index 830165c799c2ab..a99890180a0e88 100644
--- a/runtimes/CMakeLists.txt
+++ b/runtimes/CMakeLists.txt
@@ -23,7 +23,7 @@ list(INSERT CMAKE_MODULE_PATH 0
 
 # We order libraries to mirror roughly how they are layered, except that compiler-rt can depend
 # on libc++, so we put it after.
-set(LLVM_DEFAULT_RUNTIMES "libc;libunwind;libcxxabi;pstl;libcxx;compiler-rt;openmp;offload")
+set(LLVM_DEFAULT_RUNTIMES "libc;libunwind;libcxxabi;pstl;libcxx;compiler-rt;openmp;offload;orc-rt")
 set(LLVM_SUPPORTED_RUNTIMES "${LLVM_DEFAULT_RUNTIMES};llvm-libgcc")
 set(LLVM_ENABLE_RUNTIMES "" CACHE STRING
   "Semicolon-separated list of runtimes to build, or \"all\" (${LLVM_DEFAULT_RUNTIMES}). Supported runtimes are ${LLVM_SUPPORTED_RUNTIMES}.")

>From f801afbede00b602351ae8015c15aeab35ee278b Mon Sep 17 00:00:00 2001
From: Lang Hames <lhames at gmail.com>
Date: Thu, 24 Oct 2024 11:25:16 +1100
Subject: [PATCH 2/2] clang-format

---
 orc-rt/lib/prelink/orc-rt-prelink.cpp | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/orc-rt/lib/prelink/orc-rt-prelink.cpp b/orc-rt/lib/prelink/orc-rt-prelink.cpp
index d24d5838a25cc9..b97d9cd22a0a23 100644
--- a/orc-rt/lib/prelink/orc-rt-prelink.cpp
+++ b/orc-rt/lib/prelink/orc-rt-prelink.cpp
@@ -1,5 +1,3 @@
 #include <stdio.h>
 
-extern "C" void orc_rt(void) {
-  printf("hello, world!\n");
-}
+extern "C" void orc_rt(void) { printf("hello, world!\n"); }



More information about the llvm-commits mailing list