[llvm] [mlgo] Allow passing pre-emitc-ed models (PR #227941)

via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 30 20:55:05 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlgo

Author: Mircea Trofin (mtrofin)

<details>
<summary>Changes</summary>

Support pre-lowering models and then passing them via the exact same mechanism - i.e. `LLVM_MLGO_MODELS`. The extension for the pre-generated ones needs to be `.inc`. High level, this just skips trying to run the mlir toolchain over those. Mixing `.inc` and `.mlir` is supported. The mlir toolchain isn't required unless `.mlir` are passed in the list.

  
As a result we can test the AOT case in regular builds. We just always append to the `LLVM_MLGO_MODELS`list the test models, with an "ugly" command line flag (a `_test` prefix). 

The bulk of the change is changing tests accordingly, and the addition of the same models we use in the mlir case, but EmitC-ed.

---

Patch is 47.10 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/227941.diff


26 Files Affected:

- (modified) llvm/CMakeLists.txt (+5-10) 
- (modified) llvm/cmake/modules/MLGOLower.cmake (+82-61) 
- (modified) llvm/include/llvm/Analysis/Utils/MLGOUtils.h (+8-7) 
- (modified) llvm/lib/Analysis/CMakeLists.txt (+13-12) 
- (modified) llvm/lib/Analysis/MLInlineAdvisor.cpp (+1-13) 
- (added) llvm/lib/Analysis/models/inline-oz-test-model.inc (+56) 
- (added) llvm/lib/Analysis/models/regalloc-eviction-test-model.inc (+49) 
- (modified) llvm/lib/CodeGen/CMakeLists.txt (+13-12) 
- (modified) llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp (+1-14) 
- (modified) llvm/test/CMakeLists.txt (-10) 
- (modified) llvm/test/CodeGen/MLRegAlloc/default-eviction-advisor.ll (+2-2) 
- (modified) llvm/test/CodeGen/MLRegAlloc/rel-codepath.ll (+4-4) 
- (modified) llvm/test/Transforms/Inline/ML/bounds-checks.ll (+6-3) 
- (modified) llvm/test/Transforms/Inline/ML/coro-split-func-levels.ll (+3-2) 
- (modified) llvm/test/Transforms/Inline/ML/dead-callee.ll (+3-2) 
- (modified) llvm/test/Transforms/Inline/ML/enable-inline-advisor-printing-ml.ll (+6-4) 
- (modified) llvm/test/Transforms/Inline/ML/fpi-update.ll (+4-6) 
- (modified) llvm/test/Transforms/Inline/ML/ml-test-release-mode.ll (+3-2) 
- (modified) llvm/test/Transforms/Inline/ML/recursive.ll (+3-2) 
- (modified) llvm/test/Transforms/Inline/ML/scc-dead-accounting.ll (+3-3) 
- (modified) llvm/test/Transforms/Inline/ML/skip-unreachable.ll (+3-2) 
- (modified) llvm/test/Transforms/Inline/ML/state-accounting-skip-non-cold.ll (+7-3) 
- (modified) llvm/test/Transforms/Inline/inlining-advisor-default.ll (+2-2) 
- (modified) llvm/test/lit.cfg.py (-6) 
- (modified) llvm/test/lit.site.cfg.py.in (-2) 
- (modified) llvm/unittests/Analysis/MLGOUtilsTest.cpp (+4-7) 


``````````diff
diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt
index 28e96fc28b5aa..e80f418d933ac 100644
--- a/llvm/CMakeLists.txt
+++ b/llvm/CMakeLists.txt
@@ -1240,16 +1240,14 @@ set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LLVM_LIBRARY_DIR} )
 set(LLVM_HAVE_TFLITE "" CACHE BOOL "Use tflite")
 
 set(LLVM_MLGO_MODELS "" CACHE STRING "List of MLGO models")
-set(LLVM_MLGO_MLIR_OPT "mlir-opt" CACHE STRING "Path or system binary name for mlir-opt")
-set(LLVM_MLGO_MLIR_TRANSLATE "mlir-translate" CACHE STRING "Path or system binary name for mlir-translate")
+set(LLVM_MLGO_MLIR_OPT "" CACHE STRING "Path or system binary name for mlir-opt")
+set(LLVM_MLGO_MLIR_TRANSLATE "" CACHE STRING "Path or system binary name for mlir-translate")
 
 set(LLVM_HAVE_MLIR_LOWERING OFF)
-if (NOT LLVM_MLGO_MODELS STREQUAL "")
+if (NOT LLVM_MLGO_MLIR_OPT STREQUAL "" AND NOT LLVM_MLGO_MLIR_TRANSLATE STREQUAL "")
   set(LLVM_HAVE_MLIR_LOWERING ON)
-endif()
-
-if (LLVM_HAVE_MLIR_LOWERING AND LLVM_HAVE_TFLITE)
-  message(FATAL_ERROR "Only one of LLVM_HAVE_TFLITE and LLVM_HAVE_MLIR_LOWERING can be enabled.")
+elseif (NOT LLVM_MLGO_MLIR_OPT STREQUAL "" OR NOT LLVM_MLGO_MLIR_TRANSLATE STREQUAL "")
+  message(FATAL_ERROR "Both LLVM_MLGO_MLIR_OPT and LLVM_MLGO_MLIR_TRANSLATE must be specified together.")
 endif()
 
 if (LLVM_HAVE_TFLITE)
@@ -1281,9 +1279,6 @@ if (NOT TENSORFLOW_AOT_PATH STREQUAL "")
     ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT tf_xla_runtime)
   set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS tf_xla_runtime)
 
-  if (LLVM_HAVE_TF_AOT AND LLVM_HAVE_MLIR_LOWERING)
-    message(FATAL_ERROR "Only one of LLVM_HAVE_TF_AOT and LLVM_HAVE_MLIR_LOWERING can be enabled.")
-  endif()
   # Once we add more modules, we should handle this more automatically.
   if (DEFINED LLVM_OVERRIDE_MODEL_HEADER_INLINERSIZEMODEL)
     set(LLVM_INLINER_MODEL_PATH "none")
diff --git a/llvm/cmake/modules/MLGOLower.cmake b/llvm/cmake/modules/MLGOLower.cmake
index 63408314a9d75..3f690e005924d 100644
--- a/llvm/cmake/modules/MLGOLower.cmake
+++ b/llvm/cmake/modules/MLGOLower.cmake
@@ -1,28 +1,28 @@
 # Lower MLGO models to C++ headers via the MLIR-based pipeline.
 #
-# Each entry in ${models} has the form "cli-flag,path/to/model.mlir,type".
+# Each entry in ${models} has the form "cli-flag,path/to/model.{mlir,inc},type".
+# In addition to user-provided models, ${test_inc_model} is unconditionally
+# registered as "_test_inc", and when LLVM_HAVE_MLIR_LOWERING is enabled,
+# ${test_mlir_model} is registered as "_test_mlir".
 # For entries whose type matches ${target_type}, this function:
 #   1. Lowers model MLIR with ${mlir_opt} and translates it with ${mlir_translate}
-#      to a C++ header defining Model<N> in ${LLVM_INCLUDE_DIR}/${include_subdir}.
+#      (or copies a pre-generated .inc header) to a C++ header in
+#      ${LLVM_INCLUDE_DIR}/${include_subdir}.
 #   2. Generates ${generated_file_basename}.def in ${LLVM_INCLUDE_DIR}/${include_subdir}
 #      with one MLGO_MODEL(ClassName, "cli-flag") entry per model.
 #   3. Generates ${generated_file_basename}.h in ${LLVM_INCLUDE_DIR}/${include_subdir}
 #      including all generated model headers.
 #   4. Appends the target driving generation to ${out_var} in the caller's scope.
-#   5. Defines LLVM_HAVE_MLIR_LOWERING_<TARGET_TYPE>.
 function(mlgo_lower_models models mlir_opt mlir_translate target_type
-         include_subdir generated_file_basename out_var)
+         include_subdir generated_file_basename test_inc_model test_mlir_model
+         out_var)
+  list(APPEND models "_test_inc,${test_inc_model},${target_type}")
+  if (LLVM_HAVE_MLIR_LOWERING)
+    list(APPEND models "_test_mlir,${test_mlir_model},${target_type}")
+  endif()
   set(def_file "${generated_file_basename}.def")
   set(umbrella_header "${generated_file_basename}.h")
 
-  if(NOT IS_ABSOLUTE "${mlir_opt}")
-    cmake_path(ABSOLUTE_PATH mlir_opt BASE_DIRECTORY "${CMAKE_BINARY_DIR}")
-  endif()
-
-  if(NOT IS_ABSOLUTE "${mlir_translate}")
-    cmake_path(ABSOLUTE_PATH mlir_translate BASE_DIRECTORY "${CMAKE_BINARY_DIR}")
-  endif()
-
   string(APPEND def_content
     "/* Auto-generated by CMake */\n"
     "#ifndef MLGO_MODEL\n"
@@ -54,55 +54,78 @@ function(mlgo_lower_models models mlir_opt mlir_translate target_type
       get_filename_component(model_path "${model_path}" ABSOLUTE BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
     endif()
 
-    set(emitc_mlir "${CMAKE_CURRENT_BINARY_DIR}/${class_name}_emitc.mlir")
     set(header_file "${LLVM_INCLUDE_DIR}/${include_subdir}/${class_name}.h")
-
-    # Pass pipeline to lower MLIR models to EmitC dialect
-    # TODO: Simplify with builtin pipeline for translation.
-    # TODO: It isn't ideal to hardcode this pass pipeline here. It would be better to use the transform dialect.
-    # TODO: This pipeline is tested independently in the following files. Make sure that tests and this CMake logic share the definition.
-    # mlir/test/Integration/Dialect/EmitC/inline-oz-test-model-tosa.mlir
-    # mlir/test/Integration/Dialect/EmitC/regalloc-eviction-test-model-tosa.mlir
-    set(mlir_passes
-      "func.func(tosa-to-linalg-named,tosa-to-linalg,tosa-to-arith,tosa-to-tensor)"
-      "symbol-privatize"
-      "scalarize-single-element-tensor-return"
-      "one-shot-bufferize{bufferize-function-boundaries=true function-boundary-type-conversion=identity-layout-map buffer-alignment=0}"
-      "buffer-results-to-out-params{hoist-static-allocs=true}"
-      "func.func(promote-buffers-to-stack)"
-      "buffer-deallocation-pipeline"
-      "func.func(convert-linalg-to-loops)"
-      "expand-strided-metadata"
-      "canonicalize"
-      "memref-elide-reinterpret-cast"
-      "convert-to-emitc"
-      "math-expand-ops{ops=rsqrt}"
-      "arith-expand{include-min-max-f=true include-min-max-i=true}"
-      "convert-math-to-emitc"
-      "convert-arith-to-emitc"
-      "wrap-emitc-func-in-class{class-name-format=${class_name}}"
-      "mlgo-add-reflection-map{included-field-attrs=tf_saved_model.index_path}"
-    )
-    string(JOIN "," pass_pipeline ${mlir_passes})
-    set(pass_pipeline "builtin.module(${pass_pipeline})")
-
-    # 1. Run MLIR pipeline to lower model_path to EmitC MLIR
-    add_custom_command(OUTPUT ${emitc_mlir}
-      COMMAND ${mlir_opt} "--pass-pipeline=${pass_pipeline}"
-      ${model_path} -o ${emitc_mlir}
-      DEPENDS ${model_path}
-      VERBATIM
-    )
-
-    # 2. Translate EmitC MLIR to C++ header
-    add_custom_command(OUTPUT ${header_file}
-      COMMAND ${mlir_translate} -mlir-to-cpp ${emitc_mlir} -o ${header_file} --mlir-print-stacktrace-on-diagnostic
-      DEPENDS ${emitc_mlir}
-      VERBATIM
-    )
+    cmake_path(GET model_path EXTENSION LAST_ONLY model_ext)
+
+    if (model_ext STREQUAL ".inc")
+      add_custom_command(OUTPUT ${header_file}
+        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${model_path} ${header_file}
+        DEPENDS ${model_path}
+        VERBATIM
+      )
+    elseif (model_ext STREQUAL ".mlir")
+      if (mlir_opt STREQUAL "" OR mlir_translate STREQUAL "")
+        message(FATAL_ERROR "LLVM_MLGO_MLIR_OPT and LLVM_MLGO_MLIR_TRANSLATE must be specified to lower '${model_path}'.")
+      endif()
+      if(NOT IS_ABSOLUTE "${mlir_opt}")
+        cmake_path(ABSOLUTE_PATH mlir_opt BASE_DIRECTORY "${CMAKE_BINARY_DIR}")
+      endif()
+      if(NOT IS_ABSOLUTE "${mlir_translate}")
+        cmake_path(ABSOLUTE_PATH mlir_translate BASE_DIRECTORY "${CMAKE_BINARY_DIR}")
+      endif()
+
+      set(emitc_mlir "${CMAKE_CURRENT_BINARY_DIR}/${class_name}_emitc.mlir")
+
+      # Pass pipeline to lower MLIR models to EmitC dialect
+      # TODO: Simplify with builtin pipeline for translation.
+      # TODO: It isn't ideal to hardcode this pass pipeline here. It would be better to use the transform dialect.
+      # TODO: This pipeline is tested independently in the following files. Make sure that tests and this CMake logic share the definition.
+      # mlir/test/Integration/Dialect/EmitC/inline-oz-test-model-tosa.mlir
+      # mlir/test/Integration/Dialect/EmitC/regalloc-eviction-test-model-tosa.mlir
+      set(mlir_passes
+        "func.func(tosa-to-linalg-named,tosa-to-linalg,tosa-to-arith,tosa-to-tensor)"
+        "symbol-privatize"
+        "scalarize-single-element-tensor-return"
+        "one-shot-bufferize{bufferize-function-boundaries=true function-boundary-type-conversion=identity-layout-map buffer-alignment=0}"
+        "buffer-results-to-out-params{hoist-static-allocs=true}"
+        "func.func(promote-buffers-to-stack)"
+        "buffer-deallocation-pipeline"
+        "func.func(convert-linalg-to-loops)"
+        "expand-strided-metadata"
+        "canonicalize"
+        "memref-elide-reinterpret-cast"
+        "convert-to-emitc"
+        "math-expand-ops{ops=rsqrt}"
+        "arith-expand{include-min-max-f=true include-min-max-i=true}"
+        "convert-math-to-emitc"
+        "convert-arith-to-emitc"
+        "wrap-emitc-func-in-class{class-name-format=Model}"
+        "mlgo-add-reflection-map{included-field-attrs=tf_saved_model.index_path}"
+      )
+      string(JOIN "," pass_pipeline ${mlir_passes})
+      set(pass_pipeline "builtin.module(${pass_pipeline})")
+
+      # 1. Run MLIR pipeline to lower model_path to EmitC MLIR
+      add_custom_command(OUTPUT ${emitc_mlir}
+        COMMAND ${mlir_opt} "--pass-pipeline=${pass_pipeline}"
+        ${model_path} -o ${emitc_mlir}
+        DEPENDS ${model_path}
+        VERBATIM
+      )
+
+      # 2. Translate EmitC MLIR to C++ header
+      add_custom_command(OUTPUT ${header_file}
+        COMMAND ${mlir_translate} -mlir-to-cpp ${emitc_mlir} -o ${header_file} --mlir-print-stacktrace-on-diagnostic
+        DEPENDS ${emitc_mlir}
+        VERBATIM
+      )
+
+      set_source_files_properties(${emitc_mlir} PROPERTIES GENERATED 1)
+    else()
+      message(FATAL_ERROR "Unsupported MLGO model file extension '${model_ext}' for '${model_path}'. Expected '.mlir' or '.inc'.")
+    endif()
 
     # Set properties so CMake knows these are generated during the build
-    set_source_files_properties(${emitc_mlir} PROPERTIES GENERATED 1)
     set_source_files_properties(${header_file} PROPERTIES GENERATED 1)
 
     # Custom target to force generation of this header
@@ -117,7 +140,7 @@ function(mlgo_lower_models models mlir_opt mlir_translate target_type
       "namespace ${class_name}_ns {\n"
       "#include \"${include_subdir}/${class_name}.h\"\n"
       "} // namespace ${class_name}_ns\n"
-      "using ${class_name}_ns::${class_name};\n"
+      "using ${class_name} = ${class_name}_ns::Model;\n"
     )
   endforeach()
 
@@ -137,7 +160,5 @@ function(mlgo_lower_models models mlir_opt mlir_translate target_type
   if (mlgo_gen_targets)
     add_custom_target(mlgo_models_gen_${target_type} DEPENDS ${mlgo_gen_targets})
     set(${out_var} ${${out_var}} mlgo_models_gen_${target_type} PARENT_SCOPE)
-    string(TOUPPER ${target_type} target_type_allcaps)
-    add_compile_definitions(LLVM_HAVE_MLIR_LOWERING_${target_type_allcaps})
   endif()
 endfunction()
diff --git a/llvm/include/llvm/Analysis/Utils/MLGOUtils.h b/llvm/include/llvm/Analysis/Utils/MLGOUtils.h
index 6bd69d26ae8a5..ba0101007f891 100644
--- a/llvm/include/llvm/Analysis/Utils/MLGOUtils.h
+++ b/llvm/include/llvm/Analysis/Utils/MLGOUtils.h
@@ -54,9 +54,10 @@ bool isReleaseModelValid(StringRef InteractiveChannelBaseName,
 
 /// Helper to construct the appropriate MLModelRunner in release mode:
 /// 1. InteractiveModelRunner if an interactive channel is specified.
-/// 2. EmitCModelRunner if MLIR lowering is enabled.
-/// 3. ReleaseModeModelRunner<CompiledModelType> otherwise.
-template <class CompiledModelType, bool HaveMLIRLowering, class CreateEmitCFunc>
+/// 2. EmitCModelRunner if an EmitC model is selected.
+/// 3. ReleaseModeModelRunner<CompiledModelType> if an embedded AOT model is
+///    available.
+template <class CompiledModelType, class CreateEmitCFunc>
 std::unique_ptr<MLModelRunner> createReleaseModeModelRunner(
     LLVMContext &Ctx, const std::vector<TensorSpec> &InputFeatures,
     StringRef DecisionName, const std::string &InteractiveChannelBaseName,
@@ -69,12 +70,12 @@ std::unique_ptr<MLModelRunner> createReleaseModeModelRunner(
         InteractiveChannelBaseName + ".out",
         InteractiveChannelBaseName + ".in");
   }
-  if constexpr (HaveMLIRLowering) {
-    return CreateEmitCModelRunner(Ctx, InputFeatures);
-  } else {
+  if (auto EmitCRunner = CreateEmitCModelRunner(Ctx, InputFeatures))
+    return EmitCRunner;
+  if (isEmbeddedModelEvaluatorValid<CompiledModelType>())
     return std::make_unique<ReleaseModeModelRunner<CompiledModelType>>(
         Ctx, InputFeatures, DecisionName, Options);
-  }
+  return nullptr;
 }
 
 } // namespace llvm
diff --git a/llvm/lib/Analysis/CMakeLists.txt b/llvm/lib/Analysis/CMakeLists.txt
index 73250fc99e5a7..e7e32678f9f78 100644
--- a/llvm/lib/Analysis/CMakeLists.txt
+++ b/llvm/lib/Analysis/CMakeLists.txt
@@ -1,15 +1,16 @@
-if (LLVM_HAVE_MLIR_LOWERING)
-  include(MLGOLower)
-  mlgo_lower_models(
-    "${LLVM_MLGO_MODELS}"
-    "${LLVM_MLGO_MLIR_OPT}"
-    "${LLVM_MLGO_MLIR_TRANSLATE}"
-    inliner
-    llvm/Analysis
-    InlinerModels
-    MLDeps
-  )
-elseif (DEFINED LLVM_HAVE_TF_AOT OR LLVM_HAVE_TFLITE)
+include(MLGOLower)
+mlgo_lower_models(
+  "${LLVM_MLGO_MODELS}"
+  "${LLVM_MLGO_MLIR_OPT}"
+  "${LLVM_MLGO_MLIR_TRANSLATE}"
+  inliner
+  llvm/Analysis
+  InlinerModels
+  "models/inline-oz-test-model.inc"
+  "${LLVM_MAIN_SRC_DIR}/../mlir/test/Integration/Dialect/EmitC/inline-oz-test-model-tosa.mlir"
+  MLDeps
+)
+if (DEFINED LLVM_HAVE_TF_AOT OR LLVM_HAVE_TFLITE)
   include(TensorFlowCompile)
   set(LLVM_INLINER_MODEL_PATH_DEFAULT "models/inliner-Oz")
 
diff --git a/llvm/lib/Analysis/MLInlineAdvisor.cpp b/llvm/lib/Analysis/MLInlineAdvisor.cpp
index fd0e4b152bcc2..1846eff2eb7e1 100644
--- a/llvm/lib/Analysis/MLInlineAdvisor.cpp
+++ b/llvm/lib/Analysis/MLInlineAdvisor.cpp
@@ -72,8 +72,6 @@ using CompiledModelType = llvm::InlinerSizeModel;
 using CompiledModelType = NoopSavedModelImpl;
 #endif
 
-#if defined(LLVM_HAVE_MLIR_LOWERING_INLINER)
-constexpr bool HaveMLIRLoweringInliner = true;
 #include "llvm/Analysis/EmitCModelRunner.h"
 #include "llvm/Analysis/InlinerModels.h"
 
@@ -107,15 +105,6 @@ createEmitCModelRunner(LLVMContext &Ctx,
   }
   llvm_unreachable("Unknown MLGO model type!");
 }
-#else
-constexpr bool HaveMLIRLoweringInliner = false;
-enum class EmitCModelChoice { Default };
-static const EmitCModelChoice SelectedMLGOModel = EmitCModelChoice::Default;
-static inline std::unique_ptr<MLModelRunner>
-createEmitCModelRunner(LLVMContext &, const std::vector<TensorSpec> &) {
-  return nullptr;
-}
-#endif
 
 std::unique_ptr<InlineAdvisor>
 llvm::getReleaseModeAdvisor(Module &M, ModuleAnalysisManager &MAM,
@@ -125,8 +114,7 @@ llvm::getReleaseModeAdvisor(Module &M, ModuleAnalysisManager &MAM,
     return nullptr;
   auto RunnerFactory = [&](const std::vector<TensorSpec> &InputFeatures)
       -> std::unique_ptr<MLModelRunner> {
-    return createReleaseModeModelRunner<CompiledModelType,
-                                        HaveMLIRLoweringInliner>(
+    return createReleaseModeModelRunner<CompiledModelType>(
         M.getContext(), InputFeatures, DecisionName, InteractiveChannelBaseName,
         InlineDecisionSpec, createEmitCModelRunner,
         EmbeddedModelRunnerOptions().setModelSelector(ModelSelector));
diff --git a/llvm/lib/Analysis/models/inline-oz-test-model.inc b/llvm/lib/Analysis/models/inline-oz-test-model.inc
new file mode 100644
index 0000000000000..68dd731380838
--- /dev/null
+++ b/llvm/lib/Analysis/models/inline-oz-test-model.inc
@@ -0,0 +1,56 @@
+#include <map>
+#include <string>
+static const int64_t __constant_xi64 = 1;
+class Model {
+ public:
+  int64_t* fieldName0;
+  int64_t* fieldName1;
+  int64_t* fieldName2;
+  int64_t* fieldName3;
+  int64_t* fieldName4;
+  int64_t* fieldName5;
+  int64_t* fieldName6;
+  int64_t* fieldName7;
+  int64_t* fieldName8;
+  int64_t* fieldName9;
+  int64_t* fieldName10;
+  int64_t* fieldName11;
+  int64_t* fieldName12;
+  int64_t* fieldName13;
+  int64_t* fieldName14;
+  int64_t* fieldName15;
+  int64_t* fieldName16;
+  int64_t* fieldName17;
+  int64_t* fieldName18;
+  int64_t* fieldName19;
+  int64_t* fieldName20;
+  int64_t* fieldName21;
+  int64_t* fieldName22;
+  int64_t* fieldName23;
+  int64_t* fieldName24;
+  int64_t* fieldName25;
+  int64_t* fieldName26;
+  int32_t* fieldName27;
+  int64_t* fieldName28;
+  int64_t* fieldName29;
+  int64_t* fieldName30;
+  int64_t* fieldName31;
+  int64_t* fieldName32;
+  int64_t* fieldName33;
+  int64_t* fieldName34;
+  int64_t* fieldName35;
+  int64_t* fieldName36;
+  float* fieldName37;
+  int64_t* fieldName38;
+  float* fieldName39;
+  const std::map<std::string, char*> reflectionMap = { { "callsite_cost", reinterpret_cast<char*>(&fieldName0) }, { "is_multiple_blocks", reinterpret_cast<char*>(&fieldName1) }, { "caller_conditionally_executed_blocks", reinterpret_cast<char*>(&fieldName2) }, { "cold_cc_penalty", reinterpret_cast<char*>(&fieldName3) }, { "callee_conditionally_executed_blocks", reinterpret_cast<char*>(&fieldName4) }, { "callee_users", reinterpret_cast<char*>(&fieldName5) }, { "callee_basic_block_count", reinterpret_cast<char*>(&fieldName6) }, { "nr_ctant_params", reinterpret_cast<char*>(&fieldName7) }, { "load_relative_intrinsic", reinterpret_cast<char*>(&fieldName8) }, { "jump_table_penalty", reinterpret_cast<char*>(&fieldName9) }, { "unsimplified_common_instructions", reinterpret_cast<char*>(&fieldName10) }, { "indirect_call_penalty", reinterpret_cast<char*>(&fieldName11) }, { "load_elimination", reinterpret_cast<char*>(&fieldName12) }, { "is_caller_avail_external", reinterpret_cast<char*>(&fieldName13) }, { "call_penalty", reinterpret_cast<char*>(&fieldName14) }, { "cost_estimate", reinterpret_cast<char*>(&fieldName15) }, { "case_cluster_penalty", reinterpret_cast<char*>(&fieldName16) }, { "node_count", reinterpret_cast<char*>(&fieldName17) }, { "call_argument_setup", reinterpret_cast<char*>(&fieldName18) }, { "sroa_savings", reinterpret_cast<char*>(&fieldName19) }, { "lowered_call_arg_setup", reinterpret_cast<char*>(&fieldName20) }, { "threshold", reinterpret_cast<char*>(&fieldName21) }, { "dead_blocks", reinterpret_cast<char*>(&fieldName22) }, { "constant_args", reinterpret_cast<char*>(&fieldName23) }, { "sroa_losses", reinterpret_cast<char*>(&fieldName24) }, { "simplified_instructions", reinterpret_cast<char*>(&fieldName25) }, { "num_loops", reinterpret_cast<char*>(&fieldName26) }, { "step_type", reinterpret_cast<char*>(&fieldName27) }, { "edge_count", reinterpret_cast<char*>(&fieldName28) }, { "is_callee_avail_external", reinterpret_cast<char*>(&fieldName29) }, { "nested_inlines", reinterpret_cast<char*>(&fieldName30) }, { "caller_basic_block_count", reinterpret_cast<char*>(&fieldName31) }, { "last_call_to_static_bonus", reinterpret_cast<char*>(&fieldName32) }, { "nested_inline_cost_estimate", reinterpret_cast<char*>(&fieldName33) }, { "callsite_height", reinterpret_cast<char*>(&fieldName34) }, { "constant_offset_ptr_args", reinterpret_cast<char*>(&fieldName35) }, { "switch_penalty", reinterpret_cast<char*>(&fieldName36) }, { "discount", reinterpret_cast<char*>(&fieldName37) }, { "caller_users", reinterpret_cast<char*>(&fieldName38) }, { "reward", reinterpret_cast<char*>(&fieldName39) } };
+  char* getBufferForName(std::string v1) {
+    char* v2 = reflectionMap.at(v1);
+    return v2;
+  }
+  int64_t operator()() {
+    int64_t v1 = 1;
+    return v1;
+  }
+};
+
diff --git a/llvm/lib/Analysis/models/regalloc-eviction-test-model.inc b/llvm/lib/Analysis/models/regalloc-eviction-test-model.inc
new file mode 100644
index 0000000000000..0f4d5f9758b03
--- /dev/null
+++ b/llvm/lib/Analysis/models/regalloc-eviction-test-model.inc
@@ -0,0 +1,49 @@
+#include <map>
+#include <string>
+class Model {
+ public:
+  int64_t fieldName0[33];
+  const std::map<std::string, char*> reflectionMap = { { "mask", reinterpret_cast<char*>(&fieldName0) } };
+  char* getBufferForName(std::string v1) {
+    char* v2 = reflectionMap.at(v1);
+    return v2;
+  }
+  int64_t operator()() {
+    size_t v1 = 0;
+    size_t v2 = 1;
+    size_t v3 = 33;
+    size_t v4 = 0;
+    int32_t v5 = -2147483648;
+    int64_t v6 = 0;
+    int32_t v7[33];
+    for (size_t i8 = v4; i8 < v3; i8 += v2) {
+      int64_t v9 = fieldName0[i8];
+      uint64_t v10 = (uint64_t) v9;
+      uint32_t v11 = (uint32_t) v...
[truncated]

``````````

</details>


https://github.com/llvm/llvm-project/pull/227941


More information about the llvm-commits mailing list