[llvm] 47afaf2 - [llvm-exegesis] Initialize all supported targets

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 22 09:03:23 PDT 2022


Author: Philip Reames
Date: 2022-09-22T09:02:22-07:00
New Revision: 47afaf2eb02b1424a9aba241ccd02393a0cbc648

URL: https://github.com/llvm/llvm-project/commit/47afaf2eb02b1424a9aba241ccd02393a0cbc648
DIFF: https://github.com/llvm/llvm-project/commit/47afaf2eb02b1424a9aba241ccd02393a0cbc648.diff

LOG: [llvm-exegesis] Initialize all supported targets

Enable registration of multiple exegesis targets at once. Use idiomatic approach to defining target select macros, but leave code in the llvm-mca sub-directories for now.

This is a stepping stone towards allowing llvm-exegesis benchmarking via simulator or testing in non-target dependent tests.

Differential Revision: https://reviews.llvm.org/D133605

Added: 
    llvm/include/llvm/Config/TargetExegesis.def.in

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

Removed: 
    


################################################################################
diff  --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt
index 571f82d54b36..f8fdd13976e9 100644
--- a/llvm/CMakeLists.txt
+++ b/llvm/CMakeLists.txt
@@ -878,6 +878,7 @@ set(LLVM_ENUM_ASM_PRINTERS "")
 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 @@ foreach(t ${LLVM_TARGETS_TO_BUILD})
     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 @@ configure_file(
   ${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
index 000000000000..884a15455158
--- /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
+
+ at LLVM_ENUM_EXEGESIS@
+
+#undef LLVM_EXEGESIS

diff  --git a/llvm/tools/llvm-exegesis/CMakeLists.txt b/llvm/tools/llvm-exegesis/CMakeLists.txt
index 2eb6e24b04f0..561b4cf93765 100644
--- a/llvm/tools/llvm-exegesis/CMakeLists.txt
+++ b/llvm/tools/llvm-exegesis/CMakeLists.txt
@@ -20,13 +20,7 @@ add_llvm_tool(llvm-exegesis
 # 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
index 003d12e6e7bf..c8c6a1cd532a 100644
--- 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
index 6949a002a8cd..9f1317d2565f 100644
--- a/llvm/tools/llvm-exegesis/llvm-exegesis.cpp
+++ b/llvm/tools/llvm-exegesis/llvm-exegesis.cpp
@@ -302,7 +302,7 @@ void benchmarkMain() {
   InitializeAllTargetMCs();
   InitializeAllAsmPrinters();
   InitializeAllAsmParsers();
-  InitializeNativeExegesisTarget();
+  InitializeAllExegesisTargets();
 
   const LLVMState State = ExitOnErr(LLVMState::Create("", CpuName));
 
@@ -411,10 +411,11 @@ static void analysisMain() {
         "and --analysis-inconsistencies-output-file must be specified");
   }
 
-  InitializeNativeTarget();
-  InitializeNativeTargetAsmPrinter();
-  InitializeNativeTargetDisassembler();
-  InitializeNativeExegesisTarget();
+  InitializeAllTargets();
+  InitializeAllTargetMCs();
+  InitializeAllAsmPrinters();
+  InitializeAllDisassemblers();
+  InitializeAllExegesisTargets();
 
   auto MemoryBuffer = ExitOnFileError(
       BenchmarkFile,


        


More information about the llvm-commits mailing list