forked from OSchip/llvm-project
[BOLT] Improve cmake configs for opensource
Summary: Change cmake config in BOLT to only support Linux. In other platforms, we print a warning that we won't build BOLT. Change configs to determine whether we will build BOLT runtime libs. This only happens in x86 hosts. If true, we will build the runtime and enable bolt-runtime tests. New tests that depend on the bolt_rt lib needs to be marked REQUIRES:bolt-runtime. I updated the relevant tests. Fix cmake to do not crash when building llvm with a target that BOLT does not support. (cherry picked from FBD31935760)
This commit is contained in:
parent
a34c753fe7
commit
0559dab546
|
@ -4,29 +4,55 @@ set(BOLT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
|||
set(BOLT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
|
||||
ExternalProject_Add(bolt_rt
|
||||
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/runtime"
|
||||
STAMP_DIR ${CMAKE_CURRENT_BINARY_DIR}/bolt_rt-stamps
|
||||
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/bolt_rt-bins
|
||||
CMAKE_ARGS -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
|
||||
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
|
||||
-DCMAKE_BUILD_TYPE=Release
|
||||
-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
|
||||
-DCMAKE_INSTALL_PREFIX=${LLVM_BINARY_DIR}
|
||||
# You might want to set this to True if actively developing bolt_rt, otherwise
|
||||
# cmake will not rebuild it after source code changes
|
||||
BUILD_ALWAYS True
|
||||
)
|
||||
if (NOT CMAKE_HOST_SYSTEM_NAME MATCHES Linux)
|
||||
message(WARNING "Not building BOLT on unsupported platform")
|
||||
else()
|
||||
set(BOLT_ENABLE_RUNTIME OFF)
|
||||
if (CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "x86_64")
|
||||
set(BOLT_ENABLE_RUNTIME ON)
|
||||
endif()
|
||||
|
||||
include_directories( ${BOLT_SOURCE_DIR}/include )
|
||||
set(BOLT_INCLUDE_TESTS OFF)
|
||||
if (LLVM_INCLUDE_TESTS)
|
||||
string(FIND "${LLVM_ENABLE_PROJECTS}" "clang" POSITION)
|
||||
if (NOT ${POSITION} EQUAL -1)
|
||||
string(FIND "${LLVM_ENABLE_PROJECTS}" "lld" POSITION)
|
||||
if (NOT ${POSITION} EQUAL -1)
|
||||
set(BOLT_INCLUDE_TESTS ON)
|
||||
else()
|
||||
message(WARNING "Not including BOLT tests since lld is disabled")
|
||||
endif()
|
||||
else()
|
||||
message(WARNING "Not including BOLT tests since clang is disabled")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
install(CODE "execute_process\(COMMAND \${CMAKE_COMMAND} -DCMAKE_INSTALL_PREFIX=\${CMAKE_INSTALL_PREFIX} -P ${CMAKE_CURRENT_BINARY_DIR}/bolt_rt-bins/cmake_install.cmake \)"
|
||||
COMPONENT bolt_rt)
|
||||
if (BOLT_ENABLE_RUNTIME)
|
||||
message(STATUS "Building BOLT runtime libraries for X86")
|
||||
ExternalProject_Add(bolt_rt
|
||||
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/runtime"
|
||||
STAMP_DIR ${CMAKE_CURRENT_BINARY_DIR}/bolt_rt-stamps
|
||||
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/bolt_rt-bins
|
||||
CMAKE_ARGS -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
|
||||
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
|
||||
-DCMAKE_BUILD_TYPE=Release
|
||||
-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
|
||||
-DCMAKE_INSTALL_PREFIX=${LLVM_BINARY_DIR}
|
||||
BUILD_ALWAYS True
|
||||
)
|
||||
install(CODE "execute_process\(COMMAND \${CMAKE_COMMAND} -DCMAKE_INSTALL_PREFIX=\${CMAKE_INSTALL_PREFIX} -P ${CMAKE_CURRENT_BINARY_DIR}/bolt_rt-bins/cmake_install.cmake \)"
|
||||
COMPONENT bolt_rt)
|
||||
add_llvm_install_targets(install-bolt_rt
|
||||
DEPENDS bolt_rt
|
||||
COMPONENT bolt_rt)
|
||||
endif()
|
||||
|
||||
add_llvm_install_targets(install-bolt_rt
|
||||
DEPENDS bolt_rt
|
||||
COMPONENT bolt_rt)
|
||||
include_directories( ${BOLT_SOURCE_DIR}/include )
|
||||
|
||||
add_subdirectory(lib)
|
||||
add_subdirectory(test)
|
||||
add_subdirectory(tools)
|
||||
add_subdirectory(lib)
|
||||
add_subdirectory(tools)
|
||||
|
||||
if (BOLT_INCLUDE_TESTS)
|
||||
add_subdirectory(test)
|
||||
endif()
|
||||
endif()
|
||||
|
|
|
@ -1,4 +1,11 @@
|
|||
foreach(t ${LLVM_TARGETS_TO_BUILD})
|
||||
message(STATUS "Targeting llvm-bolt ${t}")
|
||||
add_subdirectory(${t})
|
||||
endforeach()
|
||||
string(FIND "${LLVM_TARGETS_TO_BUILD}" "X86" POSITION)
|
||||
if (NOT ${POSITION} EQUAL -1)
|
||||
message(STATUS "Targeting X86 in llvm-bolt")
|
||||
add_subdirectory(X86)
|
||||
endif()
|
||||
|
||||
string(FIND "${LLVM_TARGETS_TO_BUILD}" "AArch64" POSITION)
|
||||
if (NOT ${POSITION} EQUAL -1)
|
||||
message(STATUS "Targeting AArch64 in llvm-bolt")
|
||||
add_subdirectory(AArch64)
|
||||
endif()
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
llvm_canonicalize_cmake_booleans(
|
||||
BOLT_ENABLE_RUNTIME
|
||||
)
|
||||
|
||||
configure_lit_site_cfg(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# This reproduces a bug with instrumentation crashes on internal call
|
||||
|
||||
# REQUIRES: system-linux
|
||||
# REQUIRES: system-linux,bolt-runtime
|
||||
|
||||
# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %s -o %t.o
|
||||
# Delete our BB symbols so BOLT doesn't mark them as entry points
|
||||
|
|
|
@ -50,6 +50,9 @@ else:
|
|||
lit_config.warning('Setting a timeout per test not supported. ' + errormsg
|
||||
+ ' Some tests will be skipped.')
|
||||
|
||||
if config.bolt_enable_runtime:
|
||||
config.available_features.add("bolt-runtime")
|
||||
|
||||
llvm_config.use_default_substitutions()
|
||||
|
||||
llvm_config.use_clang()
|
||||
|
|
|
@ -5,6 +5,7 @@ import sys
|
|||
config.llvm_src_root = "@LLVM_SOURCE_DIR@"
|
||||
config.llvm_obj_root = "@LLVM_BINARY_DIR@"
|
||||
config.bolt_obj_root = "@BOLT_BINARY_DIR@"
|
||||
config.bolt_enable_runtime = @BOLT_ENABLE_RUNTIME@
|
||||
config.llvm_tools_dir = "@LLVM_TOOLS_DIR@"
|
||||
config.llvm_libs_dir = "@LLVM_LIBS_DIR@"
|
||||
config.llvm_shlib_dir = "@SHLIBDIR@"
|
||||
|
|
|
@ -50,7 +50,7 @@ define internal void @static_symb_backslash_b() #0 {
|
|||
ret void
|
||||
}
|
||||
|
||||
; REQUIRES: system-linux
|
||||
; REQUIRES: system-linux,bolt-runtime
|
||||
|
||||
; RUN: llc %s -o %t.s
|
||||
; RUN: %clang %cflags -O0 %t.s -o %t.exe -Wl,-q
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
#}
|
||||
|
||||
|
||||
# REQUIRES: system-linux
|
||||
# REQUIRES: system-linux,bolt-runtime
|
||||
|
||||
# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown \
|
||||
# RUN: %s -o %t.o
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
# The solution is to temporarily fix RSP. Check that we correctly instrument
|
||||
# these cases.
|
||||
|
||||
# REQUIRES: system-linux
|
||||
# REQUIRES: system-linux,bolt-runtime
|
||||
|
||||
# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown \
|
||||
# RUN: %s -o %t.o
|
||||
|
|
|
@ -19,7 +19,7 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
|
||||
/*
|
||||
REQUIRES: system-linux
|
||||
REQUIRES: system-linux,bolt-runtime
|
||||
|
||||
RUN: %clang %cflags %s -o %t.exe -Wl,-q -pie -fpie
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ int main(int argc, char **argv) {
|
|||
#endif
|
||||
|
||||
/*
|
||||
REQUIRES: system-linux
|
||||
REQUIRES: system-linux,bolt-runtime
|
||||
|
||||
RUN: %clang %cflags %s -o %t.so -Wl,-q -fpie -fPIC -shared -DLIB
|
||||
RUN: %clang %cflags %s -o %t.exe -Wl,-q -ldl
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# Verify that instrumentation pass handles internal calls
|
||||
|
||||
REQUIRES: x86_64-linux
|
||||
REQUIRES: x86_64-linux,bolt-runtime
|
||||
|
||||
RUN: %clang -O3 %S/Inputs/internalcall-main.c %S/Inputs/internalcall.S -Wl,-q \
|
||||
RUN: -o %t.exe
|
||||
|
|
|
@ -25,7 +25,7 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
|
||||
/*
|
||||
REQUIRES: system-linux
|
||||
REQUIRES: system-linux,bolt-runtime
|
||||
|
||||
RUN: %clang %cflags %s -o %t.exe -Wl,-q
|
||||
|
||||
|
|
|
@ -8,11 +8,17 @@ set(LLVM_LINK_COMPONENTS
|
|||
Support
|
||||
)
|
||||
|
||||
if (BOLT_ENABLE_RUNTIME)
|
||||
set(BOLT_DRIVER_DEPS "bolt_rt")
|
||||
else()
|
||||
set(BOLT_DRIVER_DEPS "")
|
||||
endif()
|
||||
|
||||
add_llvm_tool(llvm-bolt
|
||||
llvm-bolt.cpp
|
||||
|
||||
DEPENDS
|
||||
bolt_rt
|
||||
${BOLT_DRIVER_DEPS}
|
||||
)
|
||||
|
||||
add_llvm_tool_symlink(perf2bolt llvm-bolt)
|
||||
|
|
Loading…
Reference in New Issue