[llvm] [MLGO] Model selection for models lowered through EmitC (PR #212650)
Paul Kirth via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 29 09:56:58 PDT 2026
================
@@ -0,0 +1,123 @@
+# Compile MLGO models expressed as MLIR to C++ headers via the EmitC pipeline.
+#
+# Each entry of ${models} has the form
+# "cli-flag,path/to/model.mlir,type". Entries whose type matches
+# ${target_type} are lowered with ${mlir_opt} and translated with
+# ${mlir_translate} to a C++ header defining Model<N>, placed in
+# ${LLVM_INCLUDE_DIR}/${include_subdir}. In the same directory, generate
+# ${def_file}, with one MLGO_MODEL(ClassName, "cli-flag") entry per model, and
+# ${umbrella_header}, including all the generated model headers.
+# Append the target driving generation to MLDeps in the caller's scope, and
+# define LLVM_HAVE_EMITC_COMPILE_<TARGET_TYPE>.
+function(mlgo_compile_models models mlir_opt mlir_translate target_type
+ include_subdir def_file umbrella_header)
+ if ("${mlir_opt}" MATCHES "/")
+ get_filename_component(mlir_opt "${mlir_opt}" ABSOLUTE BASE_DIR "${CMAKE_BINARY_DIR}")
+ endif()
+ if ("${mlir_translate}" MATCHES "/")
+ get_filename_component(mlir_translate "${mlir_translate}" ABSOLUTE BASE_DIR "${CMAKE_BINARY_DIR}")
+ endif()
+
+ set(DEF_CONTENT "/* Auto-generated by CMake */\n")
+ set(DEF_CONTENT "${DEF_CONTENT}#ifndef MLGO_MODEL\n#define MLGO_MODEL(CLASS_NAME, CLI_FLAG)\n#endif\n\n")
----------------
ilovepi wrote:
```suggestion
string(APPEND DEF_CONTENT
"/* Auto-generated by CMake */\n"
"#ifndef MLGO_MODEL\n"
"# define MLGO_MODEL(CLASS_NAME, CLI_FLAG)\n"
"#endif\n\n"
)
```
Seems a bit nicer. There's also `[=[ ... ]=]` syntax which is also an option, but IDK if we use it too much in tree and would avoid the need for `\n`.
https://github.com/llvm/llvm-project/pull/212650
More information about the llvm-commits
mailing list