diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt --- a/llvm/CMakeLists.txt +++ b/llvm/CMakeLists.txt @@ -878,6 +878,7 @@ set(LLVM_ENUM_ASM_PARSERS "") set(LLVM_ENUM_DISASSEMBLERS "") set(LLVM_ENUM_TARGETMCAS "") +set(LLVM_ENUM_EXEGESIS "") foreach(t ${LLVM_TARGETS_TO_BUILD}) set( td ${LLVM_MAIN_SRC_DIR}/lib/Target/${t} ) @@ -907,10 +908,14 @@ set(LLVM_ENUM_DISASSEMBLERS "${LLVM_ENUM_DISASSEMBLERS}LLVM_DISASSEMBLER(${t})\n") endif() - if( EXISTS ${td}/MCA/CMakeLists.txt ) + if( EXISTS ${td}/MCA/CMakeLists.txt ) set(LLVM_ENUM_TARGETMCAS "${LLVM_ENUM_TARGETMCAS}LLVM_TARGETMCA(${t})\n") endif() + if( EXISTS ${LLVM_MAIN_SRC_DIR}/tools/llvm-exegesis/lib/${t}/CMakeLists.txt ) + set(LLVM_ENUM_EXEGESIS + "${LLVM_ENUM_EXEGESIS}LLVM_EXEGESIS(${t})\n") + endif() endforeach(t) # Provide an LLVM_ namespaced alias for use in #cmakedefine. @@ -938,6 +943,10 @@ ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/TargetMCAs.def.in ${LLVM_INCLUDE_DIR}/llvm/Config/TargetMCAs.def ) +configure_file( + ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/TargetExegesis.def.in + ${LLVM_INCLUDE_DIR}/llvm/Config/TargetExegesis.def + ) # They are not referenced. See set_output_directory(). set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_TOOLS_BINARY_DIR} ) diff --git a/llvm/include/llvm/Config/TargetExegesis.def.in b/llvm/include/llvm/Config/TargetExegesis.def.in new file mode 100644 --- /dev/null +++ b/llvm/include/llvm/Config/TargetExegesis.def.in @@ -0,0 +1,29 @@ +/*===----- llvm/Config/TargetExegesis.def - LLVM Target Exegesis-*- 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 *| +|* *| +|*===----------------------------------------------------------------------===*| +|* *| +|* This file enumerates all of the target's of llvm-exegesis *| +|* supported by this build of LLVM. Clients of this file should define *| +|* the LLVM_EXEGISIS macro to be a function-like macro with a *| +|* single parameter (the name of the target whose assembly can be *| +|* generated); including this file will then enumerate all of the *| +|* targets with target llvm-exegsis support. *| +|* *| +|* The set of targets supported by LLVM is generated at configuration *| +|* time, at which point this header is generated. Do not modify this *| +|* header directly. *| +|* *| +\*===----------------------------------------------------------------------===*/ + +#ifndef LLVM_EXEGESIS +# error Please define the macro LLVM_EXEGESIS(TargetName) +#endif + +@LLVM_ENUM_EXEGESIS@ + +#undef LLVM_EXEGESIS diff --git a/llvm/tools/llvm-exegesis/CMakeLists.txt b/llvm/tools/llvm-exegesis/CMakeLists.txt --- a/llvm/tools/llvm-exegesis/CMakeLists.txt +++ b/llvm/tools/llvm-exegesis/CMakeLists.txt @@ -20,13 +20,7 @@ # Has side effect of defining LLVM_EXEGESIS_TARGETS add_subdirectory(lib) -# Register the native target (we don't yet support -march) -if (LLVM_EXEGESIS_TARGETS MATCHES "${LLVM_NATIVE_ARCH}") - set(LLVM_EXEGESIS_NATIVE_ARCH "${LLVM_NATIVE_ARCH}") - set_source_files_properties(llvm-exegesis.cpp PROPERTIES COMPILE_FLAGS "-DLLVM_EXEGESIS_INITIALIZE_NATIVE_TARGET=Initialize${LLVM_EXEGESIS_NATIVE_ARCH}ExegesisTarget") -endif() - -# Link the native exegesis targets +# Link all enabled exegesis targets set(libs) foreach(t ${LLVM_EXEGESIS_TARGETS}) string(STRIP ${t} t) diff --git a/llvm/tools/llvm-exegesis/lib/TargetSelect.h b/llvm/tools/llvm-exegesis/lib/TargetSelect.h --- a/llvm/tools/llvm-exegesis/lib/TargetSelect.h +++ b/llvm/tools/llvm-exegesis/lib/TargetSelect.h @@ -8,30 +8,26 @@ /// /// \file /// -/// Utilities to handle the creation of the native exegesis target. +/// Utilities to handle the creation of the enabled exegesis target(s). /// //===----------------------------------------------------------------------===// #ifndef LLVM_TOOLS_LLVM_EXEGESIS_TARGET_SELECT_H #define LLVM_TOOLS_LLVM_EXEGESIS_TARGET_SELECT_H +#include "llvm/Config/llvm-config.h" + namespace llvm { namespace exegesis { -#ifdef LLVM_EXEGESIS_INITIALIZE_NATIVE_TARGET -void LLVM_EXEGESIS_INITIALIZE_NATIVE_TARGET(); -#endif +// Forward declare all of the initialize methods for targets compiled in +#define LLVM_EXEGESIS(TargetName) void Initialize##TargetName##ExegesisTarget(); +#include "llvm/Config/TargetExegesis.def" -// Initializes the native exegesis target, or returns false if there is no -// native target (either because llvm-exegesis does not support the target or -// because it's not linked in). -inline bool InitializeNativeExegesisTarget() { -#ifdef LLVM_EXEGESIS_INITIALIZE_NATIVE_TARGET - LLVM_EXEGESIS_INITIALIZE_NATIVE_TARGET(); - return true; -#else - return false; -#endif +// Initializes all exegesis targets compiled in. +inline void InitializeAllExegesisTargets() { +#define LLVM_EXEGESIS(TargetName) Initialize##TargetName##ExegesisTarget(); +#include "llvm/Config/TargetExegesis.def" } } // namespace exegesis diff --git a/llvm/tools/llvm-exegesis/llvm-exegesis.cpp b/llvm/tools/llvm-exegesis/llvm-exegesis.cpp --- a/llvm/tools/llvm-exegesis/llvm-exegesis.cpp +++ b/llvm/tools/llvm-exegesis/llvm-exegesis.cpp @@ -302,7 +302,7 @@ InitializeAllTargetMCs(); InitializeAllAsmPrinters(); InitializeAllAsmParsers(); - InitializeNativeExegesisTarget(); + InitializeAllExegesisTargets(); const LLVMState State = ExitOnErr(LLVMState::Create("", CpuName)); @@ -411,10 +411,11 @@ "and --analysis-inconsistencies-output-file must be specified"); } - InitializeNativeTarget(); - InitializeNativeTargetAsmPrinter(); - InitializeNativeTargetDisassembler(); - InitializeNativeExegesisTarget(); + InitializeAllTargets(); + InitializeAllTargetMCs(); + InitializeAllAsmPrinters(); + InitializeAllDisassemblers(); + InitializeAllExegesisTargets(); auto MemoryBuffer = ExitOnFileError( BenchmarkFile,