[llvm] 4d50a39 - [llvm-exegesis] Cross compile all enabled targets

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 9 09:05:04 PDT 2022


Author: Philip Reames
Date: 2022-09-09T09:04:55-07:00
New Revision: 4d50a392401c0d34a21c77529a2f3b9f9568339a

URL: https://github.com/llvm/llvm-project/commit/4d50a392401c0d34a21c77529a2f3b9f9568339a
DIFF: https://github.com/llvm/llvm-project/commit/4d50a392401c0d34a21c77529a2f3b9f9568339a.diff

LOG: [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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/tools/llvm-exegesis/CMakeLists.txt b/llvm/tools/llvm-exegesis/CMakeLists.txt
index f1e17844c4860..4e5f0fbaf50a7 100644
--- a/llvm/tools/llvm-exegesis/CMakeLists.txt
+++ b/llvm/tools/llvm-exegesis/CMakeLists.txt
@@ -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}
   )

diff  --git a/llvm/tools/llvm-exegesis/lib/CMakeLists.txt b/llvm/tools/llvm-exegesis/lib/CMakeLists.txt
index 2ca0ce4f905a0..922162f77d60c 100644
--- a/llvm/tools/llvm-exegesis/lib/CMakeLists.txt
+++ b/llvm/tools/llvm-exegesis/lib/CMakeLists.txt
@@ -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

diff  --git a/llvm/tools/llvm-exegesis/llvm-exegesis.cpp b/llvm/tools/llvm-exegesis/llvm-exegesis.cpp
index aecae5c949e54..dde1e5c9ada86 100644
--- a/llvm/tools/llvm-exegesis/llvm-exegesis.cpp
+++ b/llvm/tools/llvm-exegesis/llvm-exegesis.cpp
@@ -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);


        


More information about the llvm-commits mailing list