[llvm] [mlgo] Allow passing pre-emitc-ed models (PR #227941)
Mircea Trofin via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 30 20:58:44 PDT 2026
https://github.com/mtrofin updated https://github.com/llvm/llvm-project/pull/227941
>From edb0ee631f9a93e387d8e2d693728837637b9870 Mon Sep 17 00:00:00 2001
From: Mircea Trofin <mtrofin at google.com>
Date: Wed, 30 Sep 2026 20:43:27 -0700
Subject: [PATCH] [mlgo] Allow passing pre-emitc-ed models
---
llvm/CMakeLists.txt | 15 +-
llvm/cmake/modules/MLGOLower.cmake | 143 ++++++++++--------
llvm/include/llvm/Analysis/Utils/MLGOUtils.h | 15 +-
llvm/lib/Analysis/CMakeLists.txt | 25 +--
llvm/lib/Analysis/MLInlineAdvisor.cpp | 14 +-
.../Analysis/models/inline-oz-test-model.inc | 98 ++++++++++++
.../models/regalloc-eviction-test-model.inc | 49 ++++++
llvm/lib/CodeGen/CMakeLists.txt | 25 +--
llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp | 15 +-
llvm/test/CMakeLists.txt | 10 --
.../MLRegAlloc/default-eviction-advisor.ll | 4 +-
llvm/test/CodeGen/MLRegAlloc/rel-codepath.ll | 8 +-
.../Transforms/Inline/ML/bounds-checks.ll | 9 +-
.../Inline/ML/coro-split-func-levels.ll | 5 +-
llvm/test/Transforms/Inline/ML/dead-callee.ll | 5 +-
.../ML/enable-inline-advisor-printing-ml.ll | 10 +-
llvm/test/Transforms/Inline/ML/fpi-update.ll | 10 +-
.../Inline/ML/ml-test-release-mode.ll | 5 +-
llvm/test/Transforms/Inline/ML/recursive.ll | 5 +-
.../Inline/ML/scc-dead-accounting.ll | 6 +-
.../Transforms/Inline/ML/skip-unreachable.ll | 5 +-
.../ML/state-accounting-skip-non-cold.ll | 10 +-
.../Inline/inlining-advisor-default.ll | 4 +-
llvm/test/lit.cfg.py | 6 -
llvm/test/lit.site.cfg.py.in | 2 -
llvm/unittests/Analysis/MLGOUtilsTest.cpp | 16 +-
26 files changed, 324 insertions(+), 195 deletions(-)
create mode 100644 llvm/lib/Analysis/models/inline-oz-test-model.inc
create mode 100644 llvm/lib/Analysis/models/regalloc-eviction-test-model.inc
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..62a204f8e3626
--- /dev/null
+++ b/llvm/lib/Analysis/models/inline-oz-test-model.inc
@@ -0,0 +1,98 @@
+#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..dff4371881eea
--- /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)v10;
+ int32_t v12 = (int32_t)v11;
+ v7[i8] = v12;
+ }
+ int64_t v13;
+ int64_t *v14 = &v13;
+ v14[v1] = v6;
+ int32_t v15;
+ int32_t *v16 = &v15;
+ v16[v1] = v5;
+ for (size_t i17 = v4; i17 < v3; i17 += v2) {
+ int32_t v18 = v7[i17];
+ int64_t v19 = v14[v1];
+ int32_t v20 = v16[v1];
+ ptrdiff_t v21 = (ptrdiff_t)i17;
+ int64_t v22 = (int64_t)v21;
+ bool v23 = v18 > v20;
+ bool v24 = v18 > v20;
+ int32_t v25 = v24 ? v18 : v20;
+ int64_t v26 = v23 ? v22 : v19;
+ v14[v1] = v26;
+ v16[v1] = v25;
+ }
+ int64_t v27 = v14[v1];
+ return v27;
+ }
+};
diff --git a/llvm/lib/CodeGen/CMakeLists.txt b/llvm/lib/CodeGen/CMakeLists.txt
index 99dfb4bb09df7..c3d1559b2b3b4 100644
--- a/llvm/lib/CodeGen/CMakeLists.txt
+++ b/llvm/lib/CodeGen/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}"
- regalloc
- llvm/CodeGen
- RegAllocEvictModels
- 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}"
+ regalloc
+ llvm/CodeGen
+ RegAllocEvictModels
+ "../Analysis/models/regalloc-eviction-test-model.inc"
+ "${LLVM_MAIN_SRC_DIR}/../mlir/test/Integration/Dialect/EmitC/regalloc-eviction-test-model-tosa.mlir"
+ MLDeps
+)
+if (DEFINED LLVM_HAVE_TF_AOT OR LLVM_HAVE_TFLITE)
include(TensorFlowCompile)
set(LLVM_RAEVICT_MODEL_PATH_DEFAULT "models/regalloc-eviction")
diff --git a/llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp b/llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp
index 0ed413a7707ad..0225a017f115c 100644
--- a/llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp
+++ b/llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp
@@ -54,8 +54,6 @@ using CompiledModelType = RegAllocEvictModel;
using CompiledModelType = NoopSavedModelImpl;
#endif
-#if defined(LLVM_HAVE_MLIR_LOWERING_REGALLOC)
-constexpr bool HaveMLIRLoweringRegAlloc = true;
#include "llvm/Analysis/EmitCModelRunner.h"
#include "llvm/CodeGen/RegAllocEvictModels.h"
@@ -90,16 +88,6 @@ createMLGORegAllocModelRunner(LLVMContext &Ctx,
}
llvm_unreachable("Unknown MLGO model type!");
}
-#else
-constexpr bool HaveMLIRLoweringRegAlloc = false;
-enum class MLGORegAllocModelChoice { Default };
-static const MLGORegAllocModelChoice SelectedMLGORegAllocModel =
- MLGORegAllocModelChoice::Default;
-static inline std::unique_ptr<MLModelRunner>
-createMLGORegAllocModelRunner(LLVMContext &, const std::vector<TensorSpec> &) {
- return nullptr;
-}
-#endif
static cl::opt<std::string> InteractiveChannelBaseName(
"regalloc-evict-interactive-channel-base", cl::Hidden,
@@ -414,8 +402,7 @@ class ReleaseModeEvictionAdvisorProvider final
getAdvisor(const MachineFunction &MF, const RAGreedy &RA,
MachineBlockFrequencyInfo *MBFI, MachineLoopInfo *Loops) override {
if (!Runner) {
- Runner = createReleaseModeModelRunner<CompiledModelType,
- HaveMLIRLoweringRegAlloc>(
+ Runner = createReleaseModeModelRunner<CompiledModelType>(
MF.getFunction().getContext(), InputFeatures, DecisionName,
InteractiveChannelBaseName, DecisionSpec,
createMLGORegAllocModelRunner);
diff --git a/llvm/test/CMakeLists.txt b/llvm/test/CMakeLists.txt
index 18f176c3fe17f..e58e848e1a2a4 100644
--- a/llvm/test/CMakeLists.txt
+++ b/llvm/test/CMakeLists.txt
@@ -1,11 +1,3 @@
-if(TARGET mlgo_models_gen_inliner)
- set(LLVM_HAVE_MLIR_LOWERING_INLINER ON)
-endif()
-
-if(TARGET mlgo_models_gen_regalloc)
- set(LLVM_HAVE_MLIR_LOWERING_REGALLOC ON)
-endif()
-
llvm_canonicalize_cmake_booleans(
BUILD_SHARED_LIBS
HAVE_OCAMLOPT
@@ -29,8 +21,6 @@ llvm_canonicalize_cmake_booleans(
LLVM_HAVE_TF_AOT
LLVM_HAVE_TFLITE
LLVM_HAVE_MLIR_LOWERING
- LLVM_HAVE_MLIR_LOWERING_INLINER
- LLVM_HAVE_MLIR_LOWERING_REGALLOC
LLVM_ENABLE_PROFCHECK
LLVM_INLINER_MODEL_AUTOGENERATED
LLVM_RAEVICT_MODEL_AUTOGENERATED
diff --git a/llvm/test/CodeGen/MLRegAlloc/default-eviction-advisor.ll b/llvm/test/CodeGen/MLRegAlloc/default-eviction-advisor.ll
index 9e79cb4e3cf1f..5d36fc8671475 100644
--- a/llvm/test/CodeGen/MLRegAlloc/default-eviction-advisor.ll
+++ b/llvm/test/CodeGen/MLRegAlloc/default-eviction-advisor.ll
@@ -9,8 +9,8 @@
; RUN: %if x86-registered-target %{ not llc -O2 -enable-new-pm -mtriple=x86_64-linux-unknown -regalloc-enable-advisor=development < %s 2>&1 | FileCheck %s %}
; RUN: %if x86-registered-target %{ not llc -O2 -enable-new-pm -mtriple=x86_64-linux-unknown -regalloc-enable-advisor=release < %s 2>&1 | FileCheck %s %}
; RUN: %if x86-registered-target %{ llc -O2 -enable-new-pm -mtriple=x86_64-linux-unknown -regalloc-enable-advisor=default < %s 2>&1 | FileCheck %s --check-prefix=DEFAULT %}
-; RUN: %if have_mlir_lowering_regalloc %{ not llc -O2 -regalloc-enable-advisor=release -regalloc-mlgo-model=default < %s 2>&1 | FileCheck %s %}
-; RUN: %if have_mlir_lowering_regalloc %{ not llc -O2 -regalloc-enable-advisor=release -regalloc-mlgo-model=invalid_model < %s 2>&1 | FileCheck %s --check-prefix=INVALID %}
+; RUN: not llc -O2 -regalloc-enable-advisor=release -regalloc-mlgo-model=default < %s 2>&1 | FileCheck %s
+; RUN: not llc -O2 -regalloc-enable-advisor=release -regalloc-mlgo-model=invalid_model < %s 2>&1 | FileCheck %s --check-prefix=INVALID
; regalloc-enable-advisor is not enabled for NVPTX
; UNSUPPORTED: target=nvptx{{.*}}
diff --git a/llvm/test/CodeGen/MLRegAlloc/rel-codepath.ll b/llvm/test/CodeGen/MLRegAlloc/rel-codepath.ll
index 1e42954a5cdc8..810b179e8bba2 100644
--- a/llvm/test/CodeGen/MLRegAlloc/rel-codepath.ll
+++ b/llvm/test/CodeGen/MLRegAlloc/rel-codepath.ll
@@ -1,6 +1,4 @@
-; REQUIRES: have_tf_aot || have_mlir_lowering_regalloc
; REQUIRES: x86_64-linux
-; REQUIRES: llvm_raevict_model_autogenerated || have_mlir_lowering_regalloc
;
; Check the code path for release mode is correctly taken. It is shared with
; development mode, and we separately test the internals of that (logged
@@ -10,7 +8,9 @@
; RUN: llc -mtriple=x86_64-linux-unknown -regalloc=greedy -regalloc-enable-advisor=default \
; RUN: %S/Inputs/input.ll -o %t.default
-; RUN: llc -mtriple=x86_64-linux-unknown -regalloc=greedy %if have_mlir_lowering_regalloc %{ -regalloc-enable-advisor=release -regalloc-mlgo-model=regalloc %} %else %{ -regalloc-enable-advisor=release %} \
+; RUN: llc -mtriple=x86_64-linux-unknown -regalloc=greedy -regalloc-enable-advisor=release -regalloc-mlgo-model=_test_inc \
; RUN: %S/Inputs/input.ll -o %t.release
-
; RUN: not diff %t.release %t.default
+
+; RUN: %if have_mlir_lowering %{ llc -mtriple=x86_64-linux-unknown -regalloc=greedy -regalloc-enable-advisor=release -regalloc-mlgo-model=_test_mlir %S/Inputs/input.ll -o %t.release.mlir && not diff %t.release.mlir %t.default %}
+; RUN: %if llvm_raevict_model_autogenerated %{ llc -mtriple=x86_64-linux-unknown -regalloc=greedy -regalloc-enable-advisor=release %S/Inputs/input.ll -o %t.release.aot && not diff %t.release.aot %t.default %}
diff --git a/llvm/test/Transforms/Inline/ML/bounds-checks.ll b/llvm/test/Transforms/Inline/ML/bounds-checks.ll
index d796b1cba9aa2..71ea2179be016 100644
--- a/llvm/test/Transforms/Inline/ML/bounds-checks.ll
+++ b/llvm/test/Transforms/Inline/ML/bounds-checks.ll
@@ -2,9 +2,12 @@
; In all cases, the end result is the same: mandatory inlinings must happen.
; However, when we discover we 'trip' over the artificially-low size increase
; factor, we don't inline anymore.
-; REQUIRES: llvm_inliner_model_autogenerated || have_mlir_lowering_inliner
-; RUN: opt -passes=scc-oz-module-inliner %if have_mlir_lowering_inliner %{ -enable-ml-inliner=release -mlgo-model=inliner %} %else %{ -enable-ml-inliner=release %} -ml-advisor-size-increase-threshold=10.0 -S < %s 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=NOBOUNDS
-; RUN: opt -passes=scc-oz-module-inliner %if have_mlir_lowering_inliner %{ -enable-ml-inliner=release -mlgo-model=inliner %} %else %{ -enable-ml-inliner=release %} -ml-advisor-size-increase-threshold=1.0 -S < %s 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=BOUNDS
+; RUN: opt -passes=scc-oz-module-inliner -enable-ml-inliner=release -mlgo-model=_test_inc -ml-advisor-size-increase-threshold=10.0 -S < %s 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=NOBOUNDS
+; RUN: opt -passes=scc-oz-module-inliner -enable-ml-inliner=release -mlgo-model=_test_inc -ml-advisor-size-increase-threshold=1.0 -S < %s 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=BOUNDS
+; RUN: %if have_mlir_lowering %{ opt -passes=scc-oz-module-inliner -enable-ml-inliner=release -mlgo-model=_test_mlir -ml-advisor-size-increase-threshold=10.0 -S < %s 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=NOBOUNDS %}
+; RUN: %if have_mlir_lowering %{ opt -passes=scc-oz-module-inliner -enable-ml-inliner=release -mlgo-model=_test_mlir -ml-advisor-size-increase-threshold=1.0 -S < %s 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=BOUNDS %}
+; RUN: %if llvm_inliner_model_autogenerated %{ opt -passes=scc-oz-module-inliner -enable-ml-inliner=release -ml-advisor-size-increase-threshold=10.0 -S < %s 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=NOBOUNDS %}
+; RUN: %if llvm_inliner_model_autogenerated %{ opt -passes=scc-oz-module-inliner -enable-ml-inliner=release -ml-advisor-size-increase-threshold=1.0 -S < %s 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=BOUNDS %}
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-grtev4-linux-gnu"
diff --git a/llvm/test/Transforms/Inline/ML/coro-split-func-levels.ll b/llvm/test/Transforms/Inline/ML/coro-split-func-levels.ll
index bb14ea327069c..d4ba2a4ecb7cf 100644
--- a/llvm/test/Transforms/Inline/ML/coro-split-func-levels.ll
+++ b/llvm/test/Transforms/Inline/ML/coro-split-func-levels.ll
@@ -1,6 +1,7 @@
-; REQUIRES: llvm_inliner_model_autogenerated || have_mlir_lowering_inliner
; RUN: opt -S -passes='coro-early,scc-oz-module-inliner,print<inline-advisor>' \
-; RUN: %if have_mlir_lowering_inliner %{ -enable-ml-inliner=release -mlgo-model=inliner %} %else %{ -enable-ml-inliner=release %} -keep-inline-advisor-for-printing < %s
+; RUN: -enable-ml-inliner=release -mlgo-model=_test_inc -keep-inline-advisor-for-printing < %s
+; RUN: %if have_mlir_lowering %{ opt -S -passes='coro-early,scc-oz-module-inliner,print<inline-advisor>' -enable-ml-inliner=release -mlgo-model=_test_mlir -keep-inline-advisor-for-printing < %s %}
+; RUN: %if llvm_inliner_model_autogenerated %{ opt -S -passes='coro-early,scc-oz-module-inliner,print<inline-advisor>' -enable-ml-inliner=release -keep-inline-advisor-for-printing < %s %}
define void @_Z5get_sv() presplitcoroutine {
%1 = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr null)
diff --git a/llvm/test/Transforms/Inline/ML/dead-callee.ll b/llvm/test/Transforms/Inline/ML/dead-callee.ll
index ffb2b53f1b027..2d95ff7082025 100644
--- a/llvm/test/Transforms/Inline/ML/dead-callee.ll
+++ b/llvm/test/Transforms/Inline/ML/dead-callee.ll
@@ -1,5 +1,6 @@
-; REQUIRES: llvm_inliner_model_autogenerated || have_mlir_lowering_inliner
-; RUN: opt %if have_mlir_lowering_inliner %{ -passes=inliner-ml-advisor-release -mlgo-model=inliner %} %else %{ -passes=inliner-ml-advisor-release %} -S < %s | FileCheck %s
+; RUN: opt -passes=inliner-ml-advisor-release -mlgo-model=_test_inc -S < %s | FileCheck %s
+; RUN: %if have_mlir_lowering %{ opt -passes=inliner-ml-advisor-release -mlgo-model=_test_mlir -S < %s | FileCheck %s %}
+; RUN: %if llvm_inliner_model_autogenerated %{ opt -passes=inliner-ml-advisor-release -S < %s | FileCheck %s %}
; Check that our accounting works when a function in a non-trivial SCC is dead.
diff --git a/llvm/test/Transforms/Inline/ML/enable-inline-advisor-printing-ml.ll b/llvm/test/Transforms/Inline/ML/enable-inline-advisor-printing-ml.ll
index de414f0bcb457..96b7af8c40329 100644
--- a/llvm/test/Transforms/Inline/ML/enable-inline-advisor-printing-ml.ll
+++ b/llvm/test/Transforms/Inline/ML/enable-inline-advisor-printing-ml.ll
@@ -1,13 +1,15 @@
-; REQUIRES: llvm_inliner_model_autogenerated || have_mlir_lowering_inliner
-
-; RUN: opt %if have_mlir_lowering_inliner %{ -enable-ml-inliner=release -mlgo-model=inliner %} %else %{ -enable-ml-inliner=release %} -passes=scc-oz-module-inliner \
+; RUN: opt -enable-ml-inliner=release -mlgo-model=_test_inc -passes=scc-oz-module-inliner \
; RUN: -keep-inline-advisor-for-printing -mandatory-inlining-first=1 \
; RUN: -enable-scc-inline-advisor-printing -S < %s 2>&1 | FileCheck %s
+; RUN: %if have_mlir_lowering %{ opt -enable-ml-inliner=release -mlgo-model=_test_mlir -passes=scc-oz-module-inliner -keep-inline-advisor-for-printing -mandatory-inlining-first=1 -enable-scc-inline-advisor-printing -S < %s 2>&1 | FileCheck %s %}
+; RUN: %if llvm_inliner_model_autogenerated %{ opt -enable-ml-inliner=release -passes=scc-oz-module-inliner -keep-inline-advisor-for-printing -mandatory-inlining-first=1 -enable-scc-inline-advisor-printing -S < %s 2>&1 | FileCheck %s %}
-; RUN: opt %if have_mlir_lowering_inliner %{ -enable-ml-inliner=release -mlgo-model=inliner %} %else %{ -enable-ml-inliner=release %} -passes=scc-oz-module-inliner \
+; RUN: opt -enable-ml-inliner=release -mlgo-model=_test_inc -passes=scc-oz-module-inliner \
; RUN: -keep-inline-advisor-for-printing -mandatory-inlining-first=0 \
; RUN: -enable-scc-inline-advisor-printing -S < %s 2>&1 \
; RUN: | FileCheck %s --check-prefix=TWO
+; RUN: %if have_mlir_lowering %{ opt -enable-ml-inliner=release -mlgo-model=_test_mlir -passes=scc-oz-module-inliner -keep-inline-advisor-for-printing -mandatory-inlining-first=0 -enable-scc-inline-advisor-printing -S < %s 2>&1 | FileCheck %s --check-prefix=TWO %}
+; RUN: %if llvm_inliner_model_autogenerated %{ opt -enable-ml-inliner=release -passes=scc-oz-module-inliner -keep-inline-advisor-for-printing -mandatory-inlining-first=0 -enable-scc-inline-advisor-printing -S < %s 2>&1 | FileCheck %s --check-prefix=TWO %}
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
diff --git a/llvm/test/Transforms/Inline/ML/fpi-update.ll b/llvm/test/Transforms/Inline/ML/fpi-update.ll
index 0799bb9edc0aa..a219c126b98c8 100644
--- a/llvm/test/Transforms/Inline/ML/fpi-update.ll
+++ b/llvm/test/Transforms/Inline/ML/fpi-update.ll
@@ -1,13 +1,11 @@
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-grtev4-linux-gnu"
-; TODO: we could instantiate the MLInliner with a non-model generated evaluator
-; and drop the requirement
-; REQUIRES: llvm_inliner_model_autogenerated || have_mlir_lowering_inliner
-
-; RUN: opt %if have_mlir_lowering_inliner %{ -enable-ml-inliner=release -mlgo-model=inliner %} %else %{ -enable-ml-inliner=release %} -passes='scc-oz-module-inliner,print<inline-advisor>' \
+; RUN: opt -enable-ml-inliner=release -mlgo-model=_test_inc -passes='scc-oz-module-inliner,print<inline-advisor>' \
; RUN: -keep-inline-advisor-for-printing -max-devirt-iterations=0 \
-; RUN: -mandatory-inlining-first=0 -S < %s 2>&1 | FileCheck %s
+; RUN: -mandatory-inlining-first=0 -S < %s 2>&1 | FileCheck %s
+; RUN: %if have_mlir_lowering %{ opt -enable-ml-inliner=release -mlgo-model=_test_mlir -passes='scc-oz-module-inliner,print<inline-advisor>' -keep-inline-advisor-for-printing -max-devirt-iterations=0 -mandatory-inlining-first=0 -S < %s 2>&1 | FileCheck %s %}
+; RUN: %if llvm_inliner_model_autogenerated %{ opt -enable-ml-inliner=release -passes='scc-oz-module-inliner,print<inline-advisor>' -keep-inline-advisor-for-printing -max-devirt-iterations=0 -mandatory-inlining-first=0 -S < %s 2>&1 | FileCheck %s %}
define void @caller(i32 %i) #1 {
call void @callee(i32 %i)
diff --git a/llvm/test/Transforms/Inline/ML/ml-test-release-mode.ll b/llvm/test/Transforms/Inline/ML/ml-test-release-mode.ll
index 7e0aaa592f072..5a0a2923eb8ab 100644
--- a/llvm/test/Transforms/Inline/ML/ml-test-release-mode.ll
+++ b/llvm/test/Transforms/Inline/ML/ml-test-release-mode.ll
@@ -5,6 +5,7 @@
; This test uses Inputs/test-module.ll, as it will share it with a similar test
; for the 'development' mode.
;
-; REQUIRES: llvm_inliner_model_autogenerated || have_mlir_lowering_inliner
-; RUN: opt -passes=scc-oz-module-inliner %if have_mlir_lowering_inliner %{ -enable-ml-inliner=release -mlgo-model=inliner %} %else %{ -enable-ml-inliner=release %} -S < %S/Inputs/test-module.ll 2>&1 | FileCheck %S/Inputs/test-module.ll --check-prefix=CHECK
+; RUN: opt -passes=scc-oz-module-inliner -enable-ml-inliner=release -mlgo-model=_test_inc -S < %S/Inputs/test-module.ll 2>&1 | FileCheck %S/Inputs/test-module.ll --check-prefix=CHECK
+; RUN: %if have_mlir_lowering %{ opt -passes=scc-oz-module-inliner -enable-ml-inliner=release -mlgo-model=_test_mlir -S < %S/Inputs/test-module.ll 2>&1 | FileCheck %S/Inputs/test-module.ll --check-prefix=CHECK %}
+; RUN: %if llvm_inliner_model_autogenerated %{ opt -passes=scc-oz-module-inliner -enable-ml-inliner=release -S < %S/Inputs/test-module.ll 2>&1 | FileCheck %S/Inputs/test-module.ll --check-prefix=CHECK %}
; RUN: opt -passes=scc-oz-module-inliner -enable-ml-inliner=default -S < %S/Inputs/test-module.ll 2>&1 | FileCheck %S/Inputs/test-module.ll --check-prefix=DEFAULT
diff --git a/llvm/test/Transforms/Inline/ML/recursive.ll b/llvm/test/Transforms/Inline/ML/recursive.ll
index f17b85a367806..bcbda43e7d8a4 100644
--- a/llvm/test/Transforms/Inline/ML/recursive.ll
+++ b/llvm/test/Transforms/Inline/ML/recursive.ll
@@ -1,6 +1,7 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals all --version 6
-; REQUIRES: llvm_inliner_model_autogenerated || have_mlir_lowering_inliner
-; RUN: opt -S %s -o - %if have_mlir_lowering_inliner %{ -passes='inliner-ml-advisor-release' -mlgo-model=inliner %} %else %{ -passes='inliner-ml-advisor-release' %} -ml-inliner-skip-policy=if-caller-not-cold | FileCheck %s
+; RUN: opt -S %s -o - -passes='inliner-ml-advisor-release' -mlgo-model=_test_inc -ml-inliner-skip-policy=if-caller-not-cold | FileCheck %s
+; RUN: %if have_mlir_lowering %{ opt -S %s -o - -passes='inliner-ml-advisor-release' -mlgo-model=_test_mlir -ml-inliner-skip-policy=if-caller-not-cold | FileCheck %s %}
+; RUN: %if llvm_inliner_model_autogenerated %{ opt -S %s -o - -passes='inliner-ml-advisor-release' -ml-inliner-skip-policy=if-caller-not-cold | FileCheck %s %}
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32"
target triple = "aarch64-unknown-linux-android29"
diff --git a/llvm/test/Transforms/Inline/ML/scc-dead-accounting.ll b/llvm/test/Transforms/Inline/ML/scc-dead-accounting.ll
index c6e6b0e5ff42c..5c3a980a9969a 100644
--- a/llvm/test/Transforms/Inline/ML/scc-dead-accounting.ll
+++ b/llvm/test/Transforms/Inline/ML/scc-dead-accounting.ll
@@ -9,11 +9,11 @@
; In this example if loop-unroll is ran after a mandatory inlining CGSCC pass,
; edges would increase but wouldn't be tracked
-; REQUIRES: llvm_inliner_model_autogenerated || have_mlir_lowering_inliner
-
-; RUN: opt %if have_mlir_lowering_inliner %{ -enable-ml-inliner=release -mlgo-model=inliner %} %else %{ -enable-ml-inliner=release %} -passes=inliner-ml-advisor-release \
+; RUN: opt -enable-ml-inliner=release -mlgo-model=_test_inc -passes=inliner-ml-advisor-release \
; RUN: -keep-inline-advisor-for-printing \
; RUN: -enable-scc-inline-advisor-printing -S < %s 2>&1 | FileCheck %s
+; RUN: %if have_mlir_lowering %{ opt -enable-ml-inliner=release -mlgo-model=_test_mlir -passes=inliner-ml-advisor-release -keep-inline-advisor-for-printing -enable-scc-inline-advisor-printing -S < %s 2>&1 | FileCheck %s %}
+; RUN: %if llvm_inliner_model_autogenerated %{ opt -enable-ml-inliner=release -passes=inliner-ml-advisor-release -keep-inline-advisor-for-printing -enable-scc-inline-advisor-printing -S < %s 2>&1 | FileCheck %s %}
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
diff --git a/llvm/test/Transforms/Inline/ML/skip-unreachable.ll b/llvm/test/Transforms/Inline/ML/skip-unreachable.ll
index b10e1fcd037c2..eac67f702dea6 100644
--- a/llvm/test/Transforms/Inline/ML/skip-unreachable.ll
+++ b/llvm/test/Transforms/Inline/ML/skip-unreachable.ll
@@ -1,7 +1,8 @@
; Test skipping inlining when the callsite is unreachable (for both mandatory
; and non-mandatory cases)
-; REQUIRES: llvm_inliner_model_autogenerated || have_mlir_lowering_inliner
-; RUN: opt %if have_mlir_lowering_inliner %{ -passes=inliner-ml-advisor-release -mlgo-model=inliner %} %else %{ -passes=inliner-ml-advisor-release %} -S < %s | FileCheck %s --check-prefix=CHECK
+; RUN: opt -passes=inliner-ml-advisor-release -mlgo-model=_test_inc -S < %s | FileCheck %s --check-prefix=CHECK
+; RUN: %if have_mlir_lowering %{ opt -passes=inliner-ml-advisor-release -mlgo-model=_test_mlir -S < %s | FileCheck %s --check-prefix=CHECK %}
+; RUN: %if llvm_inliner_model_autogenerated %{ opt -passes=inliner-ml-advisor-release -S < %s | FileCheck %s --check-prefix=CHECK %}
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-grtev4-linux-gnu"
diff --git a/llvm/test/Transforms/Inline/ML/state-accounting-skip-non-cold.ll b/llvm/test/Transforms/Inline/ML/state-accounting-skip-non-cold.ll
index 6688a1b533f73..0bbbe0161be2e 100644
--- a/llvm/test/Transforms/Inline/ML/state-accounting-skip-non-cold.ll
+++ b/llvm/test/Transforms/Inline/ML/state-accounting-skip-non-cold.ll
@@ -1,7 +1,11 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
-; REQUIRES: (llvm_inliner_model_autogenerated || have_mlir_lowering_inliner) && asserts
-; RUN: opt -passes='default<O3>' %if have_mlir_lowering_inliner %{ -enable-ml-inliner=release -mlgo-model=inliner %} %else %{ -enable-ml-inliner=release %} -ml-inliner-skip-policy=if-caller-not-cold -S %s -o - | FileCheck %s
-; RUN: opt -passes='default<O3>' -ml-inliner-stop-immediately %if have_mlir_lowering_inliner %{ -enable-ml-inliner=release -mlgo-model=inliner %} %else %{ -enable-ml-inliner=release %} -ml-inliner-skip-policy=if-caller-not-cold -S %s -o - | FileCheck %s
+; REQUIRES: asserts
+; RUN: opt -passes='default<O3>' -enable-ml-inliner=release -mlgo-model=_test_inc -ml-inliner-skip-policy=if-caller-not-cold -S %s -o - | FileCheck %s
+; RUN: opt -passes='default<O3>' -ml-inliner-stop-immediately -enable-ml-inliner=release -mlgo-model=_test_inc -ml-inliner-skip-policy=if-caller-not-cold -S %s -o - | FileCheck %s
+; RUN: %if have_mlir_lowering %{ opt -passes='default<O3>' -enable-ml-inliner=release -mlgo-model=_test_mlir -ml-inliner-skip-policy=if-caller-not-cold -S %s -o - | FileCheck %s %}
+; RUN: %if have_mlir_lowering %{ opt -passes='default<O3>' -ml-inliner-stop-immediately -enable-ml-inliner=release -mlgo-model=_test_mlir -ml-inliner-skip-policy=if-caller-not-cold -S %s -o - | FileCheck %s %}
+; RUN: %if llvm_inliner_model_autogenerated %{ opt -passes='default<O3>' -enable-ml-inliner=release -ml-inliner-skip-policy=if-caller-not-cold -S %s -o - | FileCheck %s %}
+; RUN: %if llvm_inliner_model_autogenerated %{ opt -passes='default<O3>' -ml-inliner-stop-immediately -enable-ml-inliner=release -ml-inliner-skip-policy=if-caller-not-cold -S %s -o - | FileCheck %s %}
declare ptr @f()
diff --git a/llvm/test/Transforms/Inline/inlining-advisor-default.ll b/llvm/test/Transforms/Inline/inlining-advisor-default.ll
index 2026121514397..1c6bef5558d0f 100644
--- a/llvm/test/Transforms/Inline/inlining-advisor-default.ll
+++ b/llvm/test/Transforms/Inline/inlining-advisor-default.ll
@@ -4,8 +4,8 @@
; REQUIRES: !have_tflite
; RUN: not opt -passes=scc-oz-module-inliner -enable-ml-inliner=development -S < %s 2>&1 | FileCheck %s
; RUN: not opt -passes=scc-oz-module-inliner -enable-ml-inliner=release -S < %s 2>&1 | FileCheck %s
-; RUN: %if have_mlir_lowering_inliner %{ not opt -passes=scc-oz-module-inliner -enable-ml-inliner=release -mlgo-model=default -S < %s 2>&1 | FileCheck %s %}
-; RUN: %if have_mlir_lowering_inliner %{ not opt -passes=scc-oz-module-inliner -enable-ml-inliner=release -mlgo-model=invalid_model -S < %s 2>&1 | FileCheck %s --check-prefix=INVALID %}
+; RUN: not opt -passes=scc-oz-module-inliner -enable-ml-inliner=release -mlgo-model=default -S < %s 2>&1 | FileCheck %s
+; RUN: not opt -passes=scc-oz-module-inliner -enable-ml-inliner=release -mlgo-model=invalid_model -S < %s 2>&1 | FileCheck %s --check-prefix=INVALID
declare i64 @f1()
diff --git a/llvm/test/lit.cfg.py b/llvm/test/lit.cfg.py
index d8913b1fbdc87..ba3c0d6c7e518 100644
--- a/llvm/test/lit.cfg.py
+++ b/llvm/test/lit.cfg.py
@@ -588,12 +588,6 @@ def enable_ptxas(ptxas_executable):
if getattr(config, "have_mlir_lowering", False):
config.available_features.add("have_mlir_lowering")
-if getattr(config, "have_mlir_lowering_inliner", False):
- config.available_features.add("have_mlir_lowering_inliner")
-
-if getattr(config, "have_mlir_lowering_regalloc", False):
- config.available_features.add("have_mlir_lowering_regalloc")
-
if getattr(config, "have_opencsd", False):
config.available_features.add("opencsd")
diff --git a/llvm/test/lit.site.cfg.py.in b/llvm/test/lit.site.cfg.py.in
index 60b22ef5a7a85..c54a687c06e74 100644
--- a/llvm/test/lit.site.cfg.py.in
+++ b/llvm/test/lit.site.cfg.py.in
@@ -60,8 +60,6 @@ config.linked_bye_extension = @LLVM_BYE_LINK_INTO_TOOLS@
config.linked_exampleirtransforms_extension = @LLVM_EXAMPLEIRTRANSFORMS_LINK_INTO_TOOLS@
config.have_tf_aot = @LLVM_HAVE_TF_AOT@
config.have_mlir_lowering = @LLVM_HAVE_MLIR_LOWERING@
-config.have_mlir_lowering_inliner = @LLVM_HAVE_MLIR_LOWERING_INLINER@
-config.have_mlir_lowering_regalloc = @LLVM_HAVE_MLIR_LOWERING_REGALLOC@
config.have_tflite = @LLVM_HAVE_TFLITE@
config.enable_profcheck = @LLVM_ENABLE_PROFCHECK@
config.llvm_inliner_model_autogenerated = @LLVM_INLINER_MODEL_AUTOGENERATED@
diff --git a/llvm/unittests/Analysis/MLGOUtilsTest.cpp b/llvm/unittests/Analysis/MLGOUtilsTest.cpp
index 34e2e1a71b3c9..8122c251a015b 100644
--- a/llvm/unittests/Analysis/MLGOUtilsTest.cpp
+++ b/llvm/unittests/Analysis/MLGOUtilsTest.cpp
@@ -128,8 +128,7 @@ TEST(MLGOUtilsTest, CreateReleaseModeModelRunnerModelSelection) {
}
llvm_unreachable("unknown model choice");
};
- return createReleaseModeModelRunner<NoopSavedModelImpl,
- /*HaveMLIRLowering=*/true>(
+ return createReleaseModeModelRunner<NoopSavedModelImpl>(
Ctx, Inputs, "decision", "", OutputSpec, Factory);
};
@@ -159,16 +158,11 @@ TEST(MLGOUtilsTest, CreateReleaseModeModelRunnerAOTFallback) {
TensorSpec::createSpec<int64_t>("b", {1})};
TensorSpec OutputSpec = TensorSpec::createSpec<int64_t>("result", {1});
- auto DummyEmitCFactory =
- [](LLVMContext &,
- const std::vector<TensorSpec> &) -> std::unique_ptr<MLModelRunner> {
- llvm_unreachable(
- "EmitC factory should not be called when HaveMLIRLowering=false");
- };
+ auto DummyEmitCFactory = [](LLVMContext &, const std::vector<TensorSpec> &)
+ -> std::unique_ptr<MLModelRunner> { return nullptr; };
- auto Runner =
- createReleaseModeModelRunner<MockAOTModel, /*HaveMLIRLowering=*/false>(
- Ctx, Inputs, "result", "", OutputSpec, DummyEmitCFactory);
+ auto Runner = createReleaseModeModelRunner<MockAOTModel>(
+ Ctx, Inputs, "result", "", OutputSpec, DummyEmitCFactory);
ASSERT_NE(Runner, nullptr);
EXPECT_TRUE(ReleaseModeModelRunner<MockAOTModel>::classof(Runner.get()));
*Runner->getTensor<int64_t>(0) = 10;
More information about the llvm-commits
mailing list