[llvm] [BOLT] Enable standalone build (PR #97130)
Tristan Ross via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 28 17:35:02 PDT 2024
https://github.com/RossComputerGuy created https://github.com/llvm/llvm-project/pull/97130
Continue from #87196 as author did not have much time, I have taken over working on this PR. We would like to have this so it'll be easier to package for Nix.
>From c371760c32d712ab4bdaf5d0200ecd79dec307b0 Mon Sep 17 00:00:00 2001
From: pca006132 <john.lck40 at gmail.com>
Date: Mon, 1 Apr 2024 00:53:50 +0800
Subject: [PATCH 1/5] [BOLT] Enable standalone build
---
bolt/CMakeLists.txt | 146 ++++++++++++++++++++++++-
bolt/lib/Target/AArch64/CMakeLists.txt | 33 ++++++
bolt/lib/Target/RISCV/CMakeLists.txt | 31 ++++++
bolt/lib/Target/X86/CMakeLists.txt | 26 +++++
bolt/lib/Utils/CMakeLists.txt | 36 +++++-
bolt/lib/Utils/CommandLineOpts.cpp | 2 +-
6 files changed, 268 insertions(+), 6 deletions(-)
diff --git a/bolt/CMakeLists.txt b/bolt/CMakeLists.txt
index 74907ad118d12f..29763d32e0dd65 100644
--- a/bolt/CMakeLists.txt
+++ b/bolt/CMakeLists.txt
@@ -1,6 +1,17 @@
+cmake_minimum_required(VERSION 3.20.0)
+
set(LLVM_SUBPROJECT_TITLE "BOLT")
-include(ExternalProject)
+if(NOT DEFINED LLVM_COMMON_CMAKE_UTILS)
+ set(LLVM_COMMON_CMAKE_UTILS ${CMAKE_CURRENT_SOURCE_DIR}/../cmake)
+endif()
+include(${LLVM_COMMON_CMAKE_UTILS}/Modules/CMakePolicy.cmake
+ NO_POLICY_SCOPE)
+
+if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
+ project(bolt)
+ set(BOLT_BUILT_STANDALONE TRUE)
+endif()
set(BOLT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(BOLT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
@@ -9,6 +20,137 @@ set(CMAKE_CXX_STANDARD 17)
# Add path for custom modules.
list(INSERT CMAKE_MODULE_PATH 0 "${BOLT_SOURCE_DIR}/cmake/modules")
+# standalone build, copied from clang
+if(BOLT_BUILT_STANDALONE)
+ set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to conform to")
+ set(CMAKE_CXX_STANDARD_REQUIRED YES)
+ set(CMAKE_CXX_EXTENSIONS NO)
+
+ if(NOT MSVC_IDE)
+ set(LLVM_ENABLE_ASSERTIONS ${ENABLE_ASSERTIONS}
+ CACHE BOOL "Enable assertions")
+ # Assertions should follow llvm-config's.
+ mark_as_advanced(LLVM_ENABLE_ASSERTIONS)
+ endif()
+
+ find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_DIR}")
+ list(APPEND CMAKE_MODULE_PATH "${LLVM_DIR}")
+
+ # Turn into CACHE PATHs for overwritting
+
+ # We can't check LLVM_CONFIG here, because find_package(LLVM ...) also sets
+ # LLVM_CONFIG.
+ if (NOT LLVM_CONFIG_FOUND)
+ # Pull values from LLVMConfig.cmake. We can drop this once the llvm-config
+ # path is removed.
+ set(INCLUDE_DIRS ${LLVM_INCLUDE_DIRS})
+ set(LLVM_OBJ_DIR "${LLVM_BINARY_DIR}")
+ # N.B. this is just a default value, the CACHE PATHs below can be overridden.
+ set(MAIN_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../llvm")
+ else()
+ set(INCLUDE_DIRS "${LLVM_BINARY_DIR}/include" "${MAIN_INCLUDE_DIR}")
+ endif()
+
+ set(LLVM_INCLUDE_DIRS ${INCLUDE_DIRS} CACHE PATH "Path to llvm/include and any other header dirs needed")
+ set(LLVM_BINARY_DIR "${LLVM_OBJ_ROOT}" CACHE PATH "Path to LLVM build tree")
+ set(LLVM_MAIN_SRC_DIR "${MAIN_SRC_DIR}" CACHE PATH "Path to LLVM source tree")
+
+ set(LLVM_TOOLS_BINARY_DIR "${LLVM_TOOLS_BINARY_DIR}" CACHE PATH "Path to llvm/bin")
+ set(LLVM_LIBRARY_DIR "${LLVM_LIBRARY_DIR}" CACHE PATH "Path to llvm/lib")
+
+ find_program(LLVM_TABLEGEN_EXE "llvm-tblgen" ${LLVM_TOOLS_BINARY_DIR}
+ NO_DEFAULT_PATH)
+
+ # They are used as destination of target generators.
+ set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin)
+ set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX})
+ if(WIN32 OR CYGWIN)
+ # DLL platform -- put DLLs into bin.
+ set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_RUNTIME_OUTPUT_INTDIR})
+ else()
+ set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
+ endif()
+
+ option(LLVM_INSTALL_TOOLCHAIN_ONLY
+ "Only include toolchain files in the 'install' target." OFF)
+
+ option(LLVM_FORCE_USE_OLD_TOOLCHAIN
+ "Set to ON to force using an old, unsupported host toolchain." OFF)
+ option(CLANG_ENABLE_BOOTSTRAP "Generate the clang bootstrap target" OFF)
+ option(LLVM_ENABLE_LIBXML2 "Use libxml2 if available." ON)
+
+ include(AddLLVM)
+ include(TableGen)
+ include(HandleLLVMOptions)
+ include(CheckAtomic)
+ include(GetErrcMessages)
+ include(LLVMDistributionSupport)
+
+ if (NOT DEFINED LLVM_INCLUDE_TESTS)
+ set(LLVM_INCLUDE_TESTS ON)
+ endif()
+
+ include_directories(${LLVM_INCLUDE_DIRS})
+ link_directories("${LLVM_LIBRARY_DIR}")
+
+ set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin )
+ set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} )
+ set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} )
+
+ find_package(Python3 ${LLVM_MINIMUM_PYTHON_VERSION} REQUIRED
+ COMPONENTS Interpreter)
+
+ if(LLVM_INCLUDE_TESTS)
+ # Check prebuilt llvm/utils.
+ if(EXISTS ${LLVM_TOOLS_BINARY_DIR}/FileCheck${CMAKE_EXECUTABLE_SUFFIX}
+ AND EXISTS ${LLVM_TOOLS_BINARY_DIR}/count${CMAKE_EXECUTABLE_SUFFIX}
+ AND EXISTS ${LLVM_TOOLS_BINARY_DIR}/not${CMAKE_EXECUTABLE_SUFFIX})
+ set(LLVM_UTILS_PROVIDED ON)
+ endif()
+
+ # Seek installed Lit.
+ find_program(LLVM_LIT
+ NAMES llvm-lit lit.py lit
+ PATHS "${LLVM_MAIN_SRC_DIR}/utils/lit"
+ DOC "Path to lit.py")
+
+ if(EXISTS ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py)
+ # Note: path not really used, except for checking if lit was found
+ if(EXISTS ${LLVM_MAIN_SRC_DIR}/utils/llvm-lit)
+ add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/llvm-lit utils/llvm-lit)
+ endif()
+ if(NOT LLVM_UTILS_PROVIDED)
+ add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/FileCheck utils/FileCheck)
+ add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/count utils/count)
+ add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/not utils/not)
+ set(LLVM_UTILS_PROVIDED ON)
+ set(CLANG_TEST_DEPS FileCheck count not)
+ endif()
+ endif()
+
+ if(LLVM_LIT)
+ # Define the default arguments to use with 'lit', and an option for the user
+ # to override.
+ set(LIT_ARGS_DEFAULT "-sv")
+ if (MSVC OR XCODE)
+ set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
+ endif()
+ set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit")
+
+ get_errc_messages(LLVM_LIT_ERRC_MESSAGES)
+
+ # On Win32 hosts, provide an option to specify the path to the GnuWin32 tools.
+ if( WIN32 AND NOT CYGWIN )
+ set(LLVM_LIT_TOOLS_DIR "" CACHE PATH "Path to GnuWin32 tools")
+ endif()
+ else()
+ set(LLVM_INCLUDE_TESTS OFF)
+ endif()
+
+ umbrella_lit_testsuite_begin(check-all)
+ endif() # LLVM_INCLUDE_TESTS
+endif() # standalone
+
# Determine default set of targets to build -- the intersection of
# those BOLT supports and those LLVM is targeting.
set(BOLT_TARGETS_TO_BUILD_all "AArch64;X86;RISCV")
@@ -94,6 +236,8 @@ if (BOLT_ENABLE_RUNTIME)
if(CMAKE_SYSROOT)
list(APPEND extra_args -DCMAKE_SYSROOT=${CMAKE_SYSROOT})
endif()
+
+ include(ExternalProject)
ExternalProject_Add(bolt_rt
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/runtime"
STAMP_DIR ${CMAKE_CURRENT_BINARY_DIR}/bolt_rt-stamps
diff --git a/bolt/lib/Target/AArch64/CMakeLists.txt b/bolt/lib/Target/AArch64/CMakeLists.txt
index be03e247aa96b1..ba7be426203bdd 100644
--- a/bolt/lib/Target/AArch64/CMakeLists.txt
+++ b/bolt/lib/Target/AArch64/CMakeLists.txt
@@ -4,6 +4,39 @@ set(LLVM_LINK_COMPONENTS
AArch64Desc
)
+if(BOLT_BUILT_STANDALONE)
+ # tablegen, copied from llvm/lib/Target/AAarch64/CMakeLists.txt
+ set(LLVM_TARGET_DEFINITIONS ${LLVM_MAIN_SRC_DIR}/lib/Target/AArch64/AArch64.td)
+ list(APPEND LLVM_TABLEGEN_FLAGS -I ${LLVM_MAIN_SRC_DIR}/lib/Target/AArch64)
+ tablegen(LLVM AArch64GenAsmMatcher.inc -gen-asm-matcher)
+ tablegen(LLVM AArch64GenAsmWriter.inc -gen-asm-writer)
+ tablegen(LLVM AArch64GenAsmWriter1.inc -gen-asm-writer -asmwriternum=1)
+ tablegen(LLVM AArch64GenCallingConv.inc -gen-callingconv)
+ tablegen(LLVM AArch64GenDAGISel.inc -gen-dag-isel)
+ tablegen(LLVM AArch64GenDisassemblerTables.inc -gen-disassembler)
+ tablegen(LLVM AArch64GenFastISel.inc -gen-fast-isel)
+ tablegen(LLVM AArch64GenGlobalISel.inc -gen-global-isel)
+ tablegen(LLVM AArch64GenO0PreLegalizeGICombiner.inc -gen-global-isel-combiner
+ -combiners="AArch64O0PreLegalizerCombiner")
+ tablegen(LLVM AArch64GenPreLegalizeGICombiner.inc -gen-global-isel-combiner
+ -combiners="AArch64PreLegalizerCombiner")
+ tablegen(LLVM AArch64GenPostLegalizeGICombiner.inc -gen-global-isel-combiner
+ -combiners="AArch64PostLegalizerCombiner")
+ tablegen(LLVM AArch64GenPostLegalizeGILowering.inc -gen-global-isel-combiner
+ -combiners="AArch64PostLegalizerLowering")
+ tablegen(LLVM AArch64GenInstrInfo.inc -gen-instr-info)
+ tablegen(LLVM AArch64GenMCCodeEmitter.inc -gen-emitter)
+ tablegen(LLVM AArch64GenMCPseudoLowering.inc -gen-pseudo-lowering)
+ tablegen(LLVM AArch64GenRegisterBank.inc -gen-register-bank)
+ tablegen(LLVM AArch64GenRegisterInfo.inc -gen-register-info)
+ tablegen(LLVM AArch64GenSubtargetInfo.inc -gen-subtarget)
+ tablegen(LLVM AArch64GenSystemOperands.inc -gen-searchable-tables)
+ tablegen(LLVM AArch64GenExegesis.inc -gen-exegesis)
+
+ add_public_tablegen_target(AArch64CommonTableGen)
+ include_directories(${CMAKE_CURRENT_BINARY_DIR})
+endif()
+
add_llvm_library(LLVMBOLTTargetAArch64
AArch64MCPlusBuilder.cpp
diff --git a/bolt/lib/Target/RISCV/CMakeLists.txt b/bolt/lib/Target/RISCV/CMakeLists.txt
index 7f955760632008..6016a13a1b0829 100644
--- a/bolt/lib/Target/RISCV/CMakeLists.txt
+++ b/bolt/lib/Target/RISCV/CMakeLists.txt
@@ -4,6 +4,37 @@ set(LLVM_LINK_COMPONENTS
RISCVDesc
)
+if(BOLT_BUILT_STANDALONE)
+ # tablegen, copied from llvm/lib/Target/RISCV/CMakeLists.txt
+ set(LLVM_TARGET_DEFINITIONS ${LLVM_MAIN_SRC_DIR}/lib/Target/RISCV/RISCV.td)
+ list(APPEND LLVM_TABLEGEN_FLAGS -I ${LLVM_MAIN_SRC_DIR}/lib/Target/RISCV)
+ tablegen(LLVM RISCVGenAsmMatcher.inc -gen-asm-matcher)
+ tablegen(LLVM RISCVGenAsmWriter.inc -gen-asm-writer)
+ tablegen(LLVM RISCVGenCompressInstEmitter.inc -gen-compress-inst-emitter)
+ tablegen(LLVM RISCVGenMacroFusion.inc -gen-macro-fusion-pred)
+ tablegen(LLVM RISCVGenDAGISel.inc -gen-dag-isel)
+ tablegen(LLVM RISCVGenDisassemblerTables.inc -gen-disassembler)
+ tablegen(LLVM RISCVGenInstrInfo.inc -gen-instr-info)
+ tablegen(LLVM RISCVGenMCCodeEmitter.inc -gen-emitter)
+ tablegen(LLVM RISCVGenMCPseudoLowering.inc -gen-pseudo-lowering)
+ tablegen(LLVM RISCVGenRegisterBank.inc -gen-register-bank)
+ tablegen(LLVM RISCVGenRegisterInfo.inc -gen-register-info)
+ tablegen(LLVM RISCVGenSearchableTables.inc -gen-searchable-tables)
+ tablegen(LLVM RISCVGenSubtargetInfo.inc -gen-subtarget)
+
+ set(LLVM_TARGET_DEFINITIONS ${LLVM_MAIN_SRC_DIR}/lib/Target/RISCV/RISCVGISel.td)
+ tablegen(LLVM RISCVGenGlobalISel.inc -gen-global-isel)
+ tablegen(LLVM RISCVGenO0PreLegalizeGICombiner.inc -gen-global-isel-combiner
+ -combiners="RISCVO0PreLegalizerCombiner")
+ tablegen(LLVM RISCVGenPreLegalizeGICombiner.inc -gen-global-isel-combiner
+ -combiners="RISCVPreLegalizerCombiner")
+ tablegen(LLVM RISCVGenPostLegalizeGICombiner.inc -gen-global-isel-combiner
+ -combiners="RISCVPostLegalizerCombiner")
+
+ add_public_tablegen_target(RISCVCommonTableGen)
+ include_directories(${CMAKE_CURRENT_BINARY_DIR})
+endif()
+
add_llvm_library(LLVMBOLTTargetRISCV
RISCVMCPlusBuilder.cpp
diff --git a/bolt/lib/Target/X86/CMakeLists.txt b/bolt/lib/Target/X86/CMakeLists.txt
index 2b769bc7e7f5ce..4527c454012379 100644
--- a/bolt/lib/Target/X86/CMakeLists.txt
+++ b/bolt/lib/Target/X86/CMakeLists.txt
@@ -5,6 +5,32 @@ set(LLVM_LINK_COMPONENTS
X86Desc
)
+if(BOLT_BUILT_STANDALONE)
+ # tablegen, copied from llvm/lib/Target/X86/CMakeLists.txt
+ set(LLVM_TARGET_DEFINITIONS ${LLVM_MAIN_SRC_DIR}/lib/Target/X86/X86.td)
+ list(APPEND LLVM_TABLEGEN_FLAGS -I ${LLVM_MAIN_SRC_DIR}/lib/Target/X86)
+ tablegen(LLVM X86GenAsmMatcher.inc -gen-asm-matcher)
+ tablegen(LLVM X86GenAsmWriter.inc -gen-asm-writer)
+ tablegen(LLVM X86GenAsmWriter1.inc -gen-asm-writer -asmwriternum=1)
+ tablegen(LLVM X86GenCallingConv.inc -gen-callingconv)
+ tablegen(LLVM X86GenDAGISel.inc -gen-dag-isel)
+ tablegen(LLVM X86GenDisassemblerTables.inc -gen-disassembler)
+ tablegen(LLVM X86GenCompressEVEXTables.inc -gen-x86-compress-evex-tables)
+ tablegen(LLVM X86GenExegesis.inc -gen-exegesis)
+ tablegen(LLVM X86GenFastISel.inc -gen-fast-isel)
+ tablegen(LLVM X86GenGlobalISel.inc -gen-global-isel)
+ tablegen(LLVM X86GenInstrInfo.inc -gen-instr-info
+ -instr-info-expand-mi-operand-info=0)
+ tablegen(LLVM X86GenMnemonicTables.inc -gen-x86-mnemonic-tables -asmwriternum=1)
+ tablegen(LLVM X86GenRegisterBank.inc -gen-register-bank)
+ tablegen(LLVM X86GenRegisterInfo.inc -gen-register-info)
+ tablegen(LLVM X86GenSubtargetInfo.inc -gen-subtarget)
+ tablegen(LLVM X86GenFoldTables.inc -gen-x86-fold-tables -asmwriternum=1)
+
+ add_public_tablegen_target(X86CommonTableGen)
+ include_directories(${CMAKE_CURRENT_BINARY_DIR})
+endif()
+
add_llvm_library(LLVMBOLTTargetX86
X86MCPlusBuilder.cpp
X86MCSymbolizer.cpp
diff --git a/bolt/lib/Utils/CMakeLists.txt b/bolt/lib/Utils/CMakeLists.txt
index d1403314274bd6..79623b33f4e816 100644
--- a/bolt/lib/Utils/CMakeLists.txt
+++ b/bolt/lib/Utils/CMakeLists.txt
@@ -1,15 +1,43 @@
+find_first_existing_vc_file("${LLVM_MAIN_SRC_DIR}" llvm_vc)
+find_first_existing_vc_file("${BOLT_SOURCE_DIR}" bolt_vc)
+
+# The VC revision include that we want to generate.
+set(version_inc "${CMAKE_CURRENT_BINARY_DIR}/VCSVersion.inc")
+
+set(generate_vcs_version_script "${LLVM_CMAKE_DIR}/GenerateVersionFromVCS.cmake")
+
+if(llvm_vc AND LLVM_APPEND_VC_REV)
+ set(llvm_source_dir ${LLVM_MAIN_SRC_DIR})
+endif()
+
+# Create custom target to generate the VC revision include.
+add_custom_command(OUTPUT "${version_inc}"
+ DEPENDS "${llvm_vc}" "${bolt_vc}" "${generate_vcs_version_script}"
+ COMMAND ${CMAKE_COMMAND} "-DNAMES=BOLT"
+ "-DHEADER_FILE=${version_inc}"
+ "-DBOLT_SOURCE_DIR=${BOLT_SOURCE_DIR}"
+ "-DLLVM_VC_REPOSITORY=${llvm_vc_repository}"
+ "-DLLVM_VC_REVISION=${llvm_vc_revision}"
+ "-DLLVM_FORCE_VC_REVISION=${LLVM_FORCE_VC_REVISION}"
+ "-DLLVM_FORCE_VC_REPOSITORY=${LLVM_FORCE_VC_REPOSITORY}"
+ -P "${generate_vcs_version_script}")
+
+# Mark the generated header as being generated.
+set_source_files_properties("${version_inc}"
+ PROPERTIES GENERATED TRUE
+ HEADER_FILE_ONLY TRUE)
+
+include_directories(${CMAKE_CURRENT_BINARY_DIR})
+
add_llvm_library(LLVMBOLTUtils
CommandLineOpts.cpp
Utils.cpp
-
+ ${version_inc}
DISABLE_LLVM_LINK_LLVM_DYLIB
LINK_LIBS
${LLVM_PTHREAD_LIB}
- DEPENDS
- llvm_vcsrevision_h
-
LINK_COMPONENTS
Support
)
diff --git a/bolt/lib/Utils/CommandLineOpts.cpp b/bolt/lib/Utils/CommandLineOpts.cpp
index 41c89bc8aeba4e..7a398cf5073d6e 100644
--- a/bolt/lib/Utils/CommandLineOpts.cpp
+++ b/bolt/lib/Utils/CommandLineOpts.cpp
@@ -11,7 +11,7 @@
//===----------------------------------------------------------------------===//
#include "bolt/Utils/CommandLineOpts.h"
-#include "llvm/Support/VCSRevision.h"
+#include "VCSVersion.inc"
using namespace llvm;
>From 7f47082a423c1a8de801926c1c2438fd5a88eb9a Mon Sep 17 00:00:00 2001
From: pca006132 <john.lck40 at gmail.com>
Date: Mon, 1 Apr 2024 00:54:54 +0800
Subject: [PATCH 2/5] [RISCV] Remove unused include in RISCVMCTargetDesc.h
Needed for standalone BOLT build
---
llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCTargetDesc.h | 1 -
1 file changed, 1 deletion(-)
diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCTargetDesc.h b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCTargetDesc.h
index d4aa0fe99078e1..6cc22af601fdb7 100644
--- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCTargetDesc.h
+++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCTargetDesc.h
@@ -13,7 +13,6 @@
#ifndef LLVM_LIB_TARGET_RISCV_MCTARGETDESC_RISCVMCTARGETDESC_H
#define LLVM_LIB_TARGET_RISCV_MCTARGETDESC_RISCVMCTARGETDESC_H
-#include "llvm/Config/config.h"
#include "llvm/MC/MCTargetOptions.h"
#include "llvm/Support/DataTypes.h"
#include <memory>
>From 3a11fbef49fe64674ba4d88d6f29614506487ddc Mon Sep 17 00:00:00 2001
From: pca006132 <john.lck40 at gmail.com>
Date: Mon, 1 Apr 2024 09:48:57 +0800
Subject: [PATCH 3/5] [BOLT] CMakeLists.txt: drop use of llvm-config
---
bolt/CMakeLists.txt | 21 +++------------------
1 file changed, 3 insertions(+), 18 deletions(-)
diff --git a/bolt/CMakeLists.txt b/bolt/CMakeLists.txt
index 29763d32e0dd65..27c873df669570 100644
--- a/bolt/CMakeLists.txt
+++ b/bolt/CMakeLists.txt
@@ -37,24 +37,9 @@ if(BOLT_BUILT_STANDALONE)
list(APPEND CMAKE_MODULE_PATH "${LLVM_DIR}")
# Turn into CACHE PATHs for overwritting
-
- # We can't check LLVM_CONFIG here, because find_package(LLVM ...) also sets
- # LLVM_CONFIG.
- if (NOT LLVM_CONFIG_FOUND)
- # Pull values from LLVMConfig.cmake. We can drop this once the llvm-config
- # path is removed.
- set(INCLUDE_DIRS ${LLVM_INCLUDE_DIRS})
- set(LLVM_OBJ_DIR "${LLVM_BINARY_DIR}")
- # N.B. this is just a default value, the CACHE PATHs below can be overridden.
- set(MAIN_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../llvm")
- else()
- set(INCLUDE_DIRS "${LLVM_BINARY_DIR}/include" "${MAIN_INCLUDE_DIR}")
- endif()
-
- set(LLVM_INCLUDE_DIRS ${INCLUDE_DIRS} CACHE PATH "Path to llvm/include and any other header dirs needed")
- set(LLVM_BINARY_DIR "${LLVM_OBJ_ROOT}" CACHE PATH "Path to LLVM build tree")
- set(LLVM_MAIN_SRC_DIR "${MAIN_SRC_DIR}" CACHE PATH "Path to LLVM source tree")
-
+ set(LLVM_INCLUDE_DIRS ${LLVM_INCLUDE_DIRS} CACHE PATH "Path to llvm/include and any other header dirs needed")
+ set(LLVM_BINARY_DIR "${LLVM_BINARY_DIR}" CACHE PATH "Path to LLVM build tree")
+ set(LLVM_MAIN_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../llvm" CACHE PATH "Path to LLVM source tree")
set(LLVM_TOOLS_BINARY_DIR "${LLVM_TOOLS_BINARY_DIR}" CACHE PATH "Path to llvm/bin")
set(LLVM_LIBRARY_DIR "${LLVM_LIBRARY_DIR}" CACHE PATH "Path to llvm/lib")
>From a41ad4a91afa8bb7044cad7815505bc3d279bb1b Mon Sep 17 00:00:00 2001
From: pca006132 <john.lck40 at gmail.com>
Date: Mon, 1 Apr 2024 20:59:26 +0800
Subject: [PATCH 4/5] [BOLT] CMakeLists.txt: Remove unused settings
---
bolt/CMakeLists.txt | 83 ---------------------------------------------
1 file changed, 83 deletions(-)
diff --git a/bolt/CMakeLists.txt b/bolt/CMakeLists.txt
index 27c873df669570..ce8e7b9bb2b931 100644
--- a/bolt/CMakeLists.txt
+++ b/bolt/CMakeLists.txt
@@ -36,104 +36,21 @@ if(BOLT_BUILT_STANDALONE)
find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_DIR}")
list(APPEND CMAKE_MODULE_PATH "${LLVM_DIR}")
- # Turn into CACHE PATHs for overwritting
- set(LLVM_INCLUDE_DIRS ${LLVM_INCLUDE_DIRS} CACHE PATH "Path to llvm/include and any other header dirs needed")
- set(LLVM_BINARY_DIR "${LLVM_BINARY_DIR}" CACHE PATH "Path to LLVM build tree")
set(LLVM_MAIN_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../llvm" CACHE PATH "Path to LLVM source tree")
- set(LLVM_TOOLS_BINARY_DIR "${LLVM_TOOLS_BINARY_DIR}" CACHE PATH "Path to llvm/bin")
- set(LLVM_LIBRARY_DIR "${LLVM_LIBRARY_DIR}" CACHE PATH "Path to llvm/lib")
-
find_program(LLVM_TABLEGEN_EXE "llvm-tblgen" ${LLVM_TOOLS_BINARY_DIR}
NO_DEFAULT_PATH)
# They are used as destination of target generators.
set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin)
set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX})
- if(WIN32 OR CYGWIN)
- # DLL platform -- put DLLs into bin.
- set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_RUNTIME_OUTPUT_INTDIR})
- else()
- set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
- endif()
-
- option(LLVM_INSTALL_TOOLCHAIN_ONLY
- "Only include toolchain files in the 'install' target." OFF)
-
- option(LLVM_FORCE_USE_OLD_TOOLCHAIN
- "Set to ON to force using an old, unsupported host toolchain." OFF)
- option(CLANG_ENABLE_BOOTSTRAP "Generate the clang bootstrap target" OFF)
- option(LLVM_ENABLE_LIBXML2 "Use libxml2 if available." ON)
include(AddLLVM)
include(TableGen)
- include(HandleLLVMOptions)
- include(CheckAtomic)
- include(GetErrcMessages)
- include(LLVMDistributionSupport)
-
- if (NOT DEFINED LLVM_INCLUDE_TESTS)
- set(LLVM_INCLUDE_TESTS ON)
- endif()
-
include_directories(${LLVM_INCLUDE_DIRS})
- link_directories("${LLVM_LIBRARY_DIR}")
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin )
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} )
set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} )
-
- find_package(Python3 ${LLVM_MINIMUM_PYTHON_VERSION} REQUIRED
- COMPONENTS Interpreter)
-
- if(LLVM_INCLUDE_TESTS)
- # Check prebuilt llvm/utils.
- if(EXISTS ${LLVM_TOOLS_BINARY_DIR}/FileCheck${CMAKE_EXECUTABLE_SUFFIX}
- AND EXISTS ${LLVM_TOOLS_BINARY_DIR}/count${CMAKE_EXECUTABLE_SUFFIX}
- AND EXISTS ${LLVM_TOOLS_BINARY_DIR}/not${CMAKE_EXECUTABLE_SUFFIX})
- set(LLVM_UTILS_PROVIDED ON)
- endif()
-
- # Seek installed Lit.
- find_program(LLVM_LIT
- NAMES llvm-lit lit.py lit
- PATHS "${LLVM_MAIN_SRC_DIR}/utils/lit"
- DOC "Path to lit.py")
-
- if(EXISTS ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py)
- # Note: path not really used, except for checking if lit was found
- if(EXISTS ${LLVM_MAIN_SRC_DIR}/utils/llvm-lit)
- add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/llvm-lit utils/llvm-lit)
- endif()
- if(NOT LLVM_UTILS_PROVIDED)
- add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/FileCheck utils/FileCheck)
- add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/count utils/count)
- add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/not utils/not)
- set(LLVM_UTILS_PROVIDED ON)
- set(CLANG_TEST_DEPS FileCheck count not)
- endif()
- endif()
-
- if(LLVM_LIT)
- # Define the default arguments to use with 'lit', and an option for the user
- # to override.
- set(LIT_ARGS_DEFAULT "-sv")
- if (MSVC OR XCODE)
- set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
- endif()
- set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit")
-
- get_errc_messages(LLVM_LIT_ERRC_MESSAGES)
-
- # On Win32 hosts, provide an option to specify the path to the GnuWin32 tools.
- if( WIN32 AND NOT CYGWIN )
- set(LLVM_LIT_TOOLS_DIR "" CACHE PATH "Path to GnuWin32 tools")
- endif()
- else()
- set(LLVM_INCLUDE_TESTS OFF)
- endif()
-
- umbrella_lit_testsuite_begin(check-all)
- endif() # LLVM_INCLUDE_TESTS
endif() # standalone
# Determine default set of targets to build -- the intersection of
>From c5e21f8bb74f7533700df4335bfcca25170fd8b6 Mon Sep 17 00:00:00 2001
From: pca006132 <john.lck40 at gmail.com>
Date: Sun, 7 Apr 2024 00:51:54 +0800
Subject: [PATCH 5/5] [BOLT] avoid setting ARCHIVE_OUTPUT_DIRECTORY as
LLVM_LIBRARY_DIR
---
bolt/runtime/CMakeLists.txt | 2 --
1 file changed, 2 deletions(-)
diff --git a/bolt/runtime/CMakeLists.txt b/bolt/runtime/CMakeLists.txt
index 6a65f80fb9079f..fb395e481aba6d 100644
--- a/bolt/runtime/CMakeLists.txt
+++ b/bolt/runtime/CMakeLists.txt
@@ -16,12 +16,10 @@ add_library(bolt_rt_instr STATIC
instr.cpp
${CMAKE_CURRENT_BINARY_DIR}/config.h
)
-set_target_properties(bolt_rt_instr PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${LLVM_LIBRARY_DIR}")
add_library(bolt_rt_hugify STATIC
hugify.cpp
${CMAKE_CURRENT_BINARY_DIR}/config.h
)
-set_target_properties(bolt_rt_hugify PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${LLVM_LIBRARY_DIR}")
set(BOLT_RT_FLAGS
-ffreestanding
More information about the llvm-commits
mailing list