diff --git a/bolt/CMakeLists.txt b/bolt/CMakeLists.txt index f43539b8e475..eb2a17738388 100644 --- a/bolt/CMakeLists.txt +++ b/bolt/CMakeLists.txt @@ -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() diff --git a/bolt/lib/Target/CMakeLists.txt b/bolt/lib/Target/CMakeLists.txt index d929366e7fd2..c939193b720a 100644 --- a/bolt/lib/Target/CMakeLists.txt +++ b/bolt/lib/Target/CMakeLists.txt @@ -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() diff --git a/bolt/test/CMakeLists.txt b/bolt/test/CMakeLists.txt index 120ed869f6ab..2d788e3f1fc8 100644 --- a/bolt/test/CMakeLists.txt +++ b/bolt/test/CMakeLists.txt @@ -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 diff --git a/bolt/test/X86/internal_call_instrument.s b/bolt/test/X86/internal_call_instrument.s index 5ef49ae88c59..9915049210f3 100644 --- a/bolt/test/X86/internal_call_instrument.s +++ b/bolt/test/X86/internal_call_instrument.s @@ -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 diff --git a/bolt/test/lit.cfg.py b/bolt/test/lit.cfg.py index 80a0546295ce..87413a1bb2fe 100644 --- a/bolt/test/lit.cfg.py +++ b/bolt/test/lit.cfg.py @@ -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() diff --git a/bolt/test/lit.site.cfg.py.in b/bolt/test/lit.site.cfg.py.in index 7e63ffec7545..6286491a0d68 100644 --- a/bolt/test/lit.site.cfg.py.in +++ b/bolt/test/lit.site.cfg.py.in @@ -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@" diff --git a/bolt/test/runtime/X86/fdata-escape-chars.ll b/bolt/test/runtime/X86/fdata-escape-chars.ll index dfa053cd6e9e..757a8b609280 100644 --- a/bolt/test/runtime/X86/fdata-escape-chars.ll +++ b/bolt/test/runtime/X86/fdata-escape-chars.ll @@ -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 diff --git a/bolt/test/runtime/X86/instrumentation-dup-jts.s b/bolt/test/runtime/X86/instrumentation-dup-jts.s index c548251d4046..a324b443976f 100755 --- a/bolt/test/runtime/X86/instrumentation-dup-jts.s +++ b/bolt/test/runtime/X86/instrumentation-dup-jts.s @@ -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 diff --git a/bolt/test/runtime/X86/instrumentation-ind-calls.s b/bolt/test/runtime/X86/instrumentation-ind-calls.s index 3c73597a0c0a..0f61441b0068 100755 --- a/bolt/test/runtime/X86/instrumentation-ind-calls.s +++ b/bolt/test/runtime/X86/instrumentation-ind-calls.s @@ -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 diff --git a/bolt/test/runtime/X86/instrumentation-pie.c b/bolt/test/runtime/X86/instrumentation-pie.c index 75951af8c140..2f267252c7d8 100644 --- a/bolt/test/runtime/X86/instrumentation-pie.c +++ b/bolt/test/runtime/X86/instrumentation-pie.c @@ -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 diff --git a/bolt/test/runtime/X86/instrumentation-shlib.c b/bolt/test/runtime/X86/instrumentation-shlib.c index bf2b4c373e3d..f3124270574d 100644 --- a/bolt/test/runtime/X86/instrumentation-shlib.c +++ b/bolt/test/runtime/X86/instrumentation-shlib.c @@ -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 diff --git a/bolt/test/runtime/X86/internal_call_instrument.test b/bolt/test/runtime/X86/internal_call_instrument.test index 7f8bbf4bfc3a..8d359bad1441 100644 --- a/bolt/test/runtime/X86/internal_call_instrument.test +++ b/bolt/test/runtime/X86/internal_call_instrument.test @@ -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 diff --git a/bolt/test/runtime/X86/user-func-reorder.c b/bolt/test/runtime/X86/user-func-reorder.c index cf56cd89ab06..d0b2326bb982 100644 --- a/bolt/test/runtime/X86/user-func-reorder.c +++ b/bolt/test/runtime/X86/user-func-reorder.c @@ -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 diff --git a/bolt/tools/driver/CMakeLists.txt b/bolt/tools/driver/CMakeLists.txt index 8ea0e5c2ee84..f6f0016ad0a6 100644 --- a/bolt/tools/driver/CMakeLists.txt +++ b/bolt/tools/driver/CMakeLists.txt @@ -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)