[llvm] [gn] port c90b6414e607 (mlgo EmitC models) (PR #231035)

Nico Weber via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 11 14:14:57 PDT 2026


https://github.com/nico created https://github.com/llvm/llvm-project/pull/231035

Ports ab547095ead5 since it's needed unconditionally after c90b6414e607.

Register only the checked-in, pre-lowered _test_inc test model.
Lowering .mlir models is still not implemented in the GN build.

>From f8ed7cf3d0ca3da396b4cbecac759280e7e52fc7 Mon Sep 17 00:00:00 2001
From: Nico Weber <thakis at chromium.org>
Date: Sun, 11 Oct 2026 17:07:54 -0400
Subject: [PATCH] [gn] port c90b6414e607 (mlgo EmitC models)

Ports ab547095ead5 since it's needed unconditionally after c90b6414e607.

Register only the checked-in, pre-lowered _test_inc test model.
Lowering .mlir models is still not implemented in the GN build.
---
 .../llvm/include/llvm/Analysis/BUILD.gn       | 55 +++++++++++++++++++
 .../llvm/include/llvm/CodeGen/BUILD.gn        | 55 +++++++++++++++++++
 .../gn/secondary/llvm/lib/Analysis/BUILD.gn   |  1 +
 .../gn/secondary/llvm/lib/CodeGen/BUILD.gn    |  1 +
 llvm/utils/gn/secondary/llvm/test/BUILD.gn    |  2 -
 5 files changed, 112 insertions(+), 2 deletions(-)

diff --git a/llvm/utils/gn/secondary/llvm/include/llvm/Analysis/BUILD.gn b/llvm/utils/gn/secondary/llvm/include/llvm/Analysis/BUILD.gn
index 3807de70aa052..185f5b26a9541 100644
--- a/llvm/utils/gn/secondary/llvm/include/llvm/Analysis/BUILD.gn
+++ b/llvm/utils/gn/secondary/llvm/include/llvm/Analysis/BUILD.gn
@@ -3,3 +3,58 @@ import("//llvm/utils/TableGen/tablegen.gni")
 tablegen("TargetLibraryInfo") {
   args = [ "-gen-target-library-info" ]
 }
+
+# Corresponds to mlgo_lower_models() in llvm/lib/Analysis/CMakeLists.txt.
+# The GN build doesn't support lowering .mlir models (LLVM_MLGO_MODELS),
+# it only registers the built-in pre-lowered test model.
+copy("inliner_Model1") {
+  sources = [ "//llvm/lib/Analysis/models/inline-oz-test-model.inc" ]
+  outputs = [ "$target_gen_dir/inliner_Model1.h" ]
+}
+
+action("InlinerModels_def") {
+  script = "//llvm/utils/gn/build/write_file.py"
+  outputs = [ "$target_gen_dir/InlinerModels.def" ]
+  args = [
+    rebase_path(outputs[0], root_build_dir),
+    string_join("\n",
+                [
+                  "/* Auto-generated by GN */",
+                  "#ifndef MLGO_MODEL",
+                  "#  define MLGO_MODEL(CLASS_NAME, CLI_FLAG)",
+                  "#endif",
+                  "",
+                  "MLGO_MODEL(inliner_Model1, \"_test_inc\")",
+                  "",
+                  "#undef MLGO_MODEL",
+                  "",
+                ]),
+  ]
+}
+
+action("InlinerModels_h") {
+  script = "//llvm/utils/gn/build/write_file.py"
+  outputs = [ "$target_gen_dir/InlinerModels.h" ]
+  args = [
+    rebase_path(outputs[0], root_build_dir),
+    string_join("\n",
+                [
+                  "/* Auto-generated by GN */",
+                  "namespace llvm {",
+                  "namespace inliner_Model1_ns {",
+                  "#include \"llvm/Analysis/inliner_Model1.h\"",
+                  "} // namespace inliner_Model1_ns",
+                  "using inliner_Model1 = inliner_Model1_ns::Model;",
+                  "} // namespace llvm",
+                  "",
+                ]),
+  ]
+}
+
+group("InlinerModels") {
+  deps = [
+    ":InlinerModels_def",
+    ":InlinerModels_h",
+    ":inliner_Model1",
+  ]
+}
diff --git a/llvm/utils/gn/secondary/llvm/include/llvm/CodeGen/BUILD.gn b/llvm/utils/gn/secondary/llvm/include/llvm/CodeGen/BUILD.gn
index fdbe4f92d564e..c34eec46a881f 100644
--- a/llvm/utils/gn/secondary/llvm/include/llvm/CodeGen/BUILD.gn
+++ b/llvm/utils/gn/secondary/llvm/include/llvm/CodeGen/BUILD.gn
@@ -5,3 +5,58 @@ tablegen("GenVT") {
   td_file = "//llvm/include/llvm/CodeGen/ValueTypes.td"
   tblgen_target = "//llvm/utils/TableGen:llvm-min-tblgen"
 }
+
+# Corresponds to mlgo_lower_models() in llvm/lib/CodeGen/CMakeLists.txt.
+# The GN build doesn't support lowering .mlir models (LLVM_MLGO_MODELS),
+# it only registers the built-in pre-lowered test model.
+copy("regalloc_Model1") {
+  sources = [ "//llvm/lib/Analysis/models/regalloc-eviction-test-model.inc" ]
+  outputs = [ "$target_gen_dir/regalloc_Model1.h" ]
+}
+
+action("RegAllocEvictModels_def") {
+  script = "//llvm/utils/gn/build/write_file.py"
+  outputs = [ "$target_gen_dir/RegAllocEvictModels.def" ]
+  args = [
+    rebase_path(outputs[0], root_build_dir),
+    string_join("\n",
+                [
+                  "/* Auto-generated by GN */",
+                  "#ifndef MLGO_MODEL",
+                  "#  define MLGO_MODEL(CLASS_NAME, CLI_FLAG)",
+                  "#endif",
+                  "",
+                  "MLGO_MODEL(regalloc_Model1, \"_test_inc\")",
+                  "",
+                  "#undef MLGO_MODEL",
+                  "",
+                ]),
+  ]
+}
+
+action("RegAllocEvictModels_h") {
+  script = "//llvm/utils/gn/build/write_file.py"
+  outputs = [ "$target_gen_dir/RegAllocEvictModels.h" ]
+  args = [
+    rebase_path(outputs[0], root_build_dir),
+    string_join("\n",
+                [
+                  "/* Auto-generated by GN */",
+                  "namespace llvm {",
+                  "namespace regalloc_Model1_ns {",
+                  "#include \"llvm/CodeGen/regalloc_Model1.h\"",
+                  "} // namespace regalloc_Model1_ns",
+                  "using regalloc_Model1 = regalloc_Model1_ns::Model;",
+                  "} // namespace llvm",
+                  "",
+                ]),
+  ]
+}
+
+group("RegAllocEvictModels") {
+  deps = [
+    ":RegAllocEvictModels_def",
+    ":RegAllocEvictModels_h",
+    ":regalloc_Model1",
+  ]
+}
diff --git a/llvm/utils/gn/secondary/llvm/lib/Analysis/BUILD.gn b/llvm/utils/gn/secondary/llvm/lib/Analysis/BUILD.gn
index 6494f712f60e1..0f8f958bcae81 100644
--- a/llvm/utils/gn/secondary/llvm/lib/Analysis/BUILD.gn
+++ b/llvm/utils/gn/secondary/llvm/lib/Analysis/BUILD.gn
@@ -9,6 +9,7 @@ static_library("Analysis") {
     "//llvm/include/llvm/Config:llvm-config",
   ]
   deps = [
+    "//llvm/include/llvm/Analysis:InlinerModels",
     "//llvm/include/llvm/Config:config",
     "//llvm/lib/BinaryFormat",
     "//llvm/lib/Frontend/HLSL",
diff --git a/llvm/utils/gn/secondary/llvm/lib/CodeGen/BUILD.gn b/llvm/utils/gn/secondary/llvm/lib/CodeGen/BUILD.gn
index dfcb12d75a465..b22f0bec55bae 100644
--- a/llvm/utils/gn/secondary/llvm/lib/CodeGen/BUILD.gn
+++ b/llvm/utils/gn/secondary/llvm/lib/CodeGen/BUILD.gn
@@ -14,6 +14,7 @@ static_library("CodeGen") {
   deps = [
     ":CodeGenOptions",
     "//llvm/include/llvm/CodeGen:GenVT",
+    "//llvm/include/llvm/CodeGen:RegAllocEvictModels",
     "//llvm/lib/Analysis",
     "//llvm/lib/Bitcode/Reader",
     "//llvm/lib/Bitcode/Writer",
diff --git a/llvm/utils/gn/secondary/llvm/test/BUILD.gn b/llvm/utils/gn/secondary/llvm/test/BUILD.gn
index 414ce1264cf32..37dbd1e5532b6 100644
--- a/llvm/utils/gn/secondary/llvm/test/BUILD.gn
+++ b/llvm/utils/gn/secondary/llvm/test/BUILD.gn
@@ -102,8 +102,6 @@ write_lit_config("lit_site_cfg") {
     "LLVM_INCLUDE_EXAMPLES=0",
     "LLVM_HAVE_OPENCSD=0",
     "LLVM_HAVE_MLIR_LOWERING=0",
-    "LLVM_HAVE_MLIR_LOWERING_INLINER=0",
-    "LLVM_HAVE_MLIR_LOWERING_REGALLOC=0",
     "LLVM_HAVE_TF_AOT=0",
     "LLVM_HAVE_TFLITE=0",
     "LLVM_INLINER_MODEL_AUTOGENERATED=0",



More information about the llvm-commits mailing list