[llvm-exegesis] Cross compile all enabled targets

llvm-exegesis is rather odd in the LLVM ecosystem in code is selectively compiled based on the native machine. LLVM is cross compiler by default, so this stands out as odd. It's also less then helpful when working on code for a target other than your native dev environment.

This change only changes the build setup. A later change will enable -march support to allow actual benchmarking under e.g. simulators in a cross compilation environment.

Differential Revision: https://reviews.llvm.org/D133150
This commit is contained in:
Philip Reames 2022-09-09 08:30:50 -07:00 committed by Philip Reames
parent 9e7c97d8ce
commit 4d50a39240
3 changed files with 29 additions and 21 deletions

View File

@ -1,8 +1,11 @@
set(LLVM_LINK_COMPONENTS
AllTargetsAsmParsers
AllTargetsCodeGens
AllTargetsDescs
AllTargetsInfos
MC
MCParser
Support
native
)
add_llvm_tool(llvm-exegesis
@ -13,19 +16,23 @@ add_llvm_tool(llvm-exegesis
intrinsics_gen
)
# Has side effect of defining LLVM_EXEGESIS_TARGETS
add_subdirectory(lib)
# Link the native exegesis target if compiled and on the right host.
if ((LLVM_TARGETS_TO_BUILD MATCHES "${LLVM_NATIVE_ARCH}") AND (LLVM_EXEGESIS_TARGETS MATCHES "${LLVM_NATIVE_ARCH}"))
# 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}")
endif()
if (LLVM_EXEGESIS_NATIVE_ARCH)
set(LLVM_EXEGESIS_NATIVE_TARGET "LLVMExegesis${LLVM_EXEGESIS_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
set(libs)
foreach(t ${LLVM_EXEGESIS_TARGETS})
string(STRIP ${t} t)
list(APPEND libs "LLVMExegesis${t}")
endforeach()
target_link_libraries(llvm-exegesis PRIVATE
LLVMExegesis
${LLVM_EXEGESIS_NATIVE_TARGET}
${libs}
)

View File

@ -1,23 +1,23 @@
set(TARGETS_TO_APPEND "")
set(LLVM_EXEGESIS_TARGETS)
if (LLVM_TARGETS_TO_BUILD MATCHES "X86")
add_subdirectory(X86)
set(TARGETS_TO_APPEND "${TARGETS_TO_APPEND} X86")
list(APPEND LLVM_EXEGESIS_TARGETS "X86")
endif()
if (LLVM_TARGETS_TO_BUILD MATCHES "AArch64")
add_subdirectory(AArch64)
set(TARGETS_TO_APPEND "${TARGETS_TO_APPEND} AArch64")
list(APPEND LLVM_EXEGESIS_TARGETS "AArch64")
endif()
if (LLVM_TARGETS_TO_BUILD MATCHES "PowerPC")
add_subdirectory(PowerPC)
set(TARGETS_TO_APPEND "${TARGETS_TO_APPEND} PowerPC")
list(APPEND LLVM_EXEGESIS_TARGETS "PowerPC")
endif()
if (LLVM_TARGETS_TO_BUILD MATCHES "Mips")
add_subdirectory(Mips)
set(TARGETS_TO_APPEND "${TARGETS_TO_APPEND} Mips")
list(APPEND LLVM_EXEGESIS_TARGETS "Mips")
endif()
set(LLVM_EXEGESIS_TARGETS "${LLVM_EXEGESIS_TARGETS} ${TARGETS_TO_APPEND}" PARENT_SCOPE)
set(LLVM_EXEGESIS_TARGETS ${LLVM_EXEGESIS_TARGETS} PARENT_SCOPE)
foreach(t ${LLVM_EXEGESIS_TARGETS})
add_subdirectory(${t})
endforeach()
set(LLVM_LINK_COMPONENTS
Analysis

View File

@ -298,9 +298,10 @@ void benchmarkMain() {
if (exegesis::pfm::pfmInitialize())
ExitWithError("cannot initialize libpfm");
InitializeNativeTarget();
InitializeNativeTargetAsmPrinter();
InitializeNativeTargetAsmParser();
InitializeAllTargets();
InitializeAllTargetMCs();
InitializeAllAsmPrinters();
InitializeAllAsmParsers();
InitializeNativeExegesisTarget();
const LLVMState State(CpuName);