xref: /llvm-project/mlir/tools/mlir-linalg-ods-gen/update_core_linalg_named_ops.sh.in (revision bcd6528554281d249ec66e0b9f94b7a1a9df7868)
1#!/usr/bin/env bash
2# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
3# See https://llvm.org/LICENSE.txt for license information.
4# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5
6# Updates the LinalgStructuredOps.yaml file based on the
7# core_named_ops.py source of truth.
8
9set -eu -o errtrace
10shopt -s inherit_errexit
11
12mlir_source_dir="@MLIR_SOURCE_DIR@"
13python_exe="@Python3_EXECUTABLE@"
14mlir_binary_dir="@MLIR_BINARY_DIR@"
15python_package_dir="$mlir_binary_dir/python_packages/mlir_core"
16
17if ! [[ -d "$python_package_dir" ]]; then
18  echo "ERROR: Python bindings not found. Build with -DMLIR_ENABLE_BINDINGS_PYTHON=ON"
19  exit 1
20fi
21
22dest_file="$mlir_source_dir/include/mlir/Dialect/Linalg/IR/LinalgNamedStructuredOps.yaml"
23echo "Updating ops in $dest_file"
24
25export PYTHONPATH="$python_package_dir"
26OUTPUT="$(
27  echo "### AUTOGENERATED from core_named_ops.py" && \
28  echo "### To regenerate, run: bin/update_core_linalg_named_ops.sh" && \
29  "$python_exe" -m mlir.dialects.linalg.opdsl.dump_oplib .ops.core_named_ops \
30)"
31echo "$OUTPUT" > "$dest_file"
32echo "Success."
33