[llvm-exegesis] Cross compile all enabled targets
authorPhilip Reames <preames@rivosinc.com>
Fri, 9 Sep 2022 15:30:50 +0000 (08:30 -0700)
committerPhilip Reames <listmail@philipreames.com>
Fri, 9 Sep 2022 16:04:55 +0000 (09:04 -0700)
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

llvm/tools/llvm-exegesis/CMakeLists.txt
llvm/tools/llvm-exegesis/lib/CMakeLists.txt
llvm/tools/llvm-exegesis/llvm-exegesis.cpp

index f1e1784..4e5f0fb 100644 (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}
   )
index 2ca0ce4..922162f 100644 (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
index aecae5c..dde1e5c 100644 (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);