diff mbox series

llvm: Enable MLIR support

Message ID 20260625133120.2111653-1-luca.fancellu@arm.com
State New
Headers show
Series llvm: Enable MLIR support | expand

Commit Message

Luca Fancellu June 25, 2026, 1:31 p.m. UTC
Enable the MLIR LLVM project in the clang folder so the compiler
flow can use MLIR and TOSA APIs that are not provided by a plain
LLVM build.

Add a patch that fix the install targets for mlir-src-sharder
and mlir-irdl-to-cpp.

Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
---
 ...l-helper-tools-used-by-CMake-exports.patch | 59 +++++++++++++++++
 meta/recipes-devtools/clang/common.inc        |  1 +
 meta/recipes-devtools/clang/llvm-mlir_git.bb  | 66 +++++++++++++++++++
 3 files changed, 126 insertions(+)
 create mode 100644 meta/recipes-devtools/clang/clang/0042-MLIR-Install-helper-tools-used-by-CMake-exports.patch
 create mode 100644 meta/recipes-devtools/clang/llvm-mlir_git.bb

Comments

Alexander Kanavin June 25, 2026, 3:22 p.m. UTC | #1
On Thu, 25 Jun 2026 at 15:31, luca fancellu via lists.openembedded.org
<luca.fancellu=arm.com@lists.openembedded.org> wrote:
>
> Enable the MLIR LLVM project in the clang folder so the compiler
> flow can use MLIR and TOSA APIs that are not provided by a plain
> LLVM build.

This needs a bit more justification. What is 'MLIR', what is 'TOSA'
and why are those things important enough to be provided by oe-core?
The recipe is added, but not used by anything.

Alex
diff mbox series

Patch

diff --git a/meta/recipes-devtools/clang/clang/0042-MLIR-Install-helper-tools-used-by-CMake-exports.patch b/meta/recipes-devtools/clang/clang/0042-MLIR-Install-helper-tools-used-by-CMake-exports.patch
new file mode 100644
index 000000000000..6079e61c9cc2
--- /dev/null
+++ b/meta/recipes-devtools/clang/clang/0042-MLIR-Install-helper-tools-used-by-CMake-exports.patch
@@ -0,0 +1,59 @@ 
+From e5f6551510eb2adb1fffe9564965101e05ca9720 Mon Sep 17 00:00:00 2001
+From: Momchil Velikov <momchil.velikov@arm.com>
+Date: Fri, 19 Jun 2026 18:00:51 +0000
+Subject: [PATCH] [MLIR] Install missing standalone helper tools
+
+Standalone MLIR installs CMake package files that can reference helper
+executables needed by downstream builds. Most helper tools already have
+install paths available through existing LLVM tool and utility install
+options, but mlir-src-sharder does not pass an install destination to
+add_tablegen and mlir-irdl-to-cpp does not define an install rule.
+
+Install those two missing helpers.
+
+Co-Authored-by: Luca Fancellu <luca.fancellu@arm.com>
+Upstream-Status: Submitted [https://github.com/llvm/llvm-project/pull/205066]
+
+Backported to oe-core version of clang.
+
+Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
+---
+ mlir/tools/mlir-irdl-to-cpp/CMakeLists.txt | 11 +++++++++++
+ mlir/tools/mlir-src-sharder/CMakeLists.txt |  2 ++
+ 2 files changed, 13 insertions(+)
+
+diff --git a/mlir/tools/mlir-irdl-to-cpp/CMakeLists.txt b/mlir/tools/mlir-irdl-to-cpp/CMakeLists.txt
+index 27a7e22db7d7..5b69b364c6b3 100644
+--- a/mlir/tools/mlir-irdl-to-cpp/CMakeLists.txt
++++ b/mlir/tools/mlir-irdl-to-cpp/CMakeLists.txt
+@@ -7,3 +7,14 @@ mlir_target_link_libraries(mlir-irdl-to-cpp
+   )
+ 
+ setup_host_tool(mlir-irdl-to-cpp MLIR_IRDL_TO_CPP MLIR_IRDL_TO_CPP_EXE MLIR_IRDL_TO_CPP_TARGET)
++
++if(NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
++  install(TARGETS mlir-irdl-to-cpp
++          RUNTIME DESTINATION "${MLIR_TOOLS_INSTALL_DIR}"
++          COMPONENT mlir-irdl-to-cpp)
++  if(NOT LLVM_ENABLE_IDE)
++    add_llvm_install_targets(install-mlir-irdl-to-cpp
++                             DEPENDS mlir-irdl-to-cpp
++                             COMPONENT mlir-irdl-to-cpp)
++  endif()
++endif()
+diff --git a/mlir/tools/mlir-src-sharder/CMakeLists.txt b/mlir/tools/mlir-src-sharder/CMakeLists.txt
+index 6f98bd15fc18..07ad45e52592 100644
+--- a/mlir/tools/mlir-src-sharder/CMakeLists.txt
++++ b/mlir/tools/mlir-src-sharder/CMakeLists.txt
+@@ -2,6 +2,8 @@ set(LLVM_LINK_COMPONENTS Support)
+ set(LIBS MLIRSupport)
+ 
+ add_tablegen(mlir-src-sharder MLIR_SRC_SHARDER
++  DESTINATION "${MLIR_TOOLS_INSTALL_DIR}"
++  EXPORT MLIR
+   mlir-src-sharder.cpp
+ 
+   DEPENDS
+-- 
+2.34.1
+
diff --git a/meta/recipes-devtools/clang/common.inc b/meta/recipes-devtools/clang/common.inc
index 441ea099a9e1..96c6f1217176 100644
--- a/meta/recipes-devtools/clang/common.inc
+++ b/meta/recipes-devtools/clang/common.inc
@@ -60,6 +60,7 @@  SRC_URI = "\
     file://0039-Rename-UNUSED-and-UNKNOWN-elements-of-OffloadArch-enum.patch \
     file://0040-libcxxabi-declare-__gnu_unwind_frame-in-cxa_personal.patch \
     file://0041-Consolidate-and-fix-sysroot-based-compiler-rt-search.patch \
+    file://0042-MLIR-Install-helper-tools-used-by-CMake-exports.patch \
 "
 # Fallback to no-PIE if not set
 GCCPIE ??= ""
diff --git a/meta/recipes-devtools/clang/llvm-mlir_git.bb b/meta/recipes-devtools/clang/llvm-mlir_git.bb
new file mode 100644
index 000000000000..f9f52a236489
--- /dev/null
+++ b/meta/recipes-devtools/clang/llvm-mlir_git.bb
@@ -0,0 +1,66 @@ 
+#
+# SPDX-FileCopyrightText: <text>Copyright 2026 Arm Limited and/or its
+# affiliates <open-source-office@arm.com></text>
+#
+# SPDX-License-Identifier: MIT
+
+SUMMARY = "MLIR compiler infrastructure"
+DESCRIPTION = "MLIR is a reusable and extensible compiler infrastructure from the LLVM project."
+HOMEPAGE = "https://mlir.llvm.org"
+SECTION = "devel"
+
+require common-clang.inc
+require common-source.inc
+
+LICENSE = "Apache-2.0-with-LLVM-exception"
+LIC_FILES_CHKSUM = "file://mlir/LICENSE.TXT;md5=7ef1911355f6e321fa0d7971689b7a67"
+
+inherit cmake pkgconfig
+
+DEPENDS = "llvm"
+DEPENDS:append:class-target = " llvm-mlir-native"
+DEPENDS:append:class-nativesdk = " llvm-mlir-native"
+
+OECMAKE_SOURCEPATH = "${S}/mlir"
+
+PACKAGECONFIG ??= "shared-libs"
+PACKAGECONFIG[shared-libs] = "\
+    -DLLVM_BUILD_LLVM_DYLIB=ON -DLLVM_LINK_LLVM_DYLIB=ON -DMLIR_LINK_MLIR_DYLIB=ON, \
+    -DLLVM_BUILD_LLVM_DYLIB=OFF -DLLVM_LINK_LLVM_DYLIB=OFF -DMLIR_LINK_MLIR_DYLIB=OFF, \
+"
+
+MLIR_NATIVE_TOOLS_OECMAKE = "\
+    -DLLVM_NATIVE_TOOL_DIR=${STAGING_BINDIR_NATIVE} \
+    -DMLIR_TABLEGEN=${STAGING_BINDIR_NATIVE}/mlir-tblgen \
+    -DMLIR_PDLL_TABLEGEN=${STAGING_BINDIR_NATIVE}/mlir-pdll \
+    -DMLIR_IRDL_TO_CPP=${STAGING_BINDIR_NATIVE}/mlir-irdl-to-cpp \
+    -DMLIR_LINALG_ODS_YAML_GEN=${STAGING_BINDIR_NATIVE}/mlir-linalg-ods-yaml-gen \
+"
+MLIR_NATIVE_TOOLS_OECMAKE:class-native = ""
+
+EXTRA_OECMAKE += "\
+    -DCMAKE_BUILD_TYPE=MinSizeRel \
+    -DLLVM_DIR=${STAGING_LIBDIR}/cmake/llvm \
+    -DLLVM_ENABLE_ASSERTIONS=OFF \
+    -DLLVM_ENABLE_PIC=ON \
+    -DMLIR_ENABLE_BINDINGS_PYTHON=OFF \
+    -DMLIR_INCLUDE_TESTS=OFF \
+    -DMLIR_INCLUDE_INTEGRATION_TESTS=OFF \
+    -DCROSS_TOOLCHAIN_FLAGS_NATIVE='-DCMAKE_TOOLCHAIN_FILE=${WORKDIR}/toolchain-native.cmake' \
+    -DLLVM_BUILD_UTILS=ON \
+    -DLLVM_BUILD_TOOLS=ON \
+    -DLLVM_INSTALL_TOOLCHAIN_ONLY=OFF \
+    ${MLIR_NATIVE_TOOLS_OECMAKE} \
+"
+
+OECMAKE_TARGET_COMPILE:class-native = "all mlir-src-sharder"
+
+PACKAGES =+ "${PN}-tools"
+
+FILES:${PN}-tools += "\
+    ${bindir}/mlir-* \
+    ${bindir}/tblgen-* \
+"
+FILES:${PN}-dev += "${libdir}/objects-*"
+
+BBCLASSEXTEND = "native nativesdk"