From 86800abc8135e7860be46239d598f0a76132ce48 Mon Sep 17 00:00:00 2001 From: Facebook Github Bot Date: Wed, 24 Jul 2019 11:05:08 -0700 Subject: [PATCH] [BOLT][PR] Target compilation based on LLVM CMake configuration Summary: Minimalist implementation of target configurable compilation. Fixes https://github.com/facebookincubator/BOLT/issues/59 Pull Request resolved: https://github.com/facebookincubator/BOLT/pull/60 GitHub Author: Pierre RAMOIN (cherry picked from FBD16461879) --- bolt/src/CMakeLists.txt | 22 ++++++++++++++++++++-- bolt/src/RewriteInstance.cpp | 17 ++++++++++------- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/bolt/src/CMakeLists.txt b/bolt/src/CMakeLists.txt index 6b60171355f7..d265e98a966d 100644 --- a/bolt/src/CMakeLists.txt +++ b/bolt/src/CMakeLists.txt @@ -48,8 +48,6 @@ add_public_gen_version_target(GenBoltRevision) set(LLVM_LINK_COMPONENTS ${LLVM_TARGETS_TO_BUILD} BOLTPasses - BOLTTargetAArch64 - BOLTTargetX86 CodeGen Core DebugInfoDWARF @@ -61,6 +59,18 @@ set(LLVM_LINK_COMPONENTS Support ) +string(FIND "${LLVM_TARGETS_TO_BUILD}" "AArch64" POSITION) +if (NOT ${POSITION} EQUAL -1) + list(APPEND LLVM_LINK_COMPONENTS BOLTTargetAArch64) + set(BOLT_AArcb64 On) +endif() + +string(FIND "${LLVM_TARGETS_TO_BUILD}" "X86" POSITION) +if (NOT ${POSITION} EQUAL -1) + list(APPEND LLVM_LINK_COMPONENTS BOLTTargetX86) + set(BOLT_X64 On) +endif() + add_llvm_tool(llvm-bolt llvm-bolt.cpp BinaryBasicBlock.cpp @@ -93,6 +103,14 @@ add_llvm_tool(llvm-bolt intrinsics_gen ) +if (DEFINED BOLT_AArcb64) + target_compile_definitions(llvm-bolt PRIVATE AARCH64_AVAILABLE) +endif() + +if (DEFINED BOLT_X64) + target_compile_definitions(llvm-bolt PRIVATE X86_AVAILABLE) +endif() + add_llvm_tool_symlink(perf2bolt llvm-bolt) add_llvm_tool_symlink(llvm-boltdiff llvm-bolt) add_llvm_tool_symlink(llvm-bolt-heatmap llvm-bolt) diff --git a/bolt/src/RewriteInstance.cpp b/bolt/src/RewriteInstance.cpp index 6bdceca1c9f4..58c6e20486b6 100644 --- a/bolt/src/RewriteInstance.cpp +++ b/bolt/src/RewriteInstance.cpp @@ -535,15 +535,18 @@ namespace { MCPlusBuilder *createMCPlusBuilder(const Triple::ArchType Arch, const MCInstrAnalysis *Analysis, const MCInstrInfo *Info, const MCRegisterInfo *RegInfo) { - if (Arch == Triple::x86_64) { +#ifdef X86_AVAILABLE + if (Arch == Triple::x86_64) return createX86MCPlusBuilder(Analysis, Info, RegInfo); - } else if (Arch == Triple::aarch64) { - return createAArch64MCPlusBuilder(Analysis, Info, RegInfo); - } else { - llvm_unreachable("architecture unsupport by MCPlusBuilder"); - } -} +#endif +#ifdef AARCH64_AVAILABLE + if (Arch == Triple::aarch64) + return createAArch64MCPlusBuilder(Analysis, Info, RegInfo); +#endif + + llvm_unreachable("architecture unsupport by MCPlusBuilder"); +} } constexpr const char *RewriteInstance::SectionsToOverwrite[];