xref: /llvm-project/mlir/utils/spirv/define_inst.sh (revision b8bea837f34534c36fd07477e51b41dd222fb869)
1#!/bin/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# Script for defining a new op using SPIR-V spec from the Internet.
7#
8# Run as:
9# ./define_inst.sh <filename> <baseclass> (<opname>)*
10
11# <filename> is required, which is the file name of MLIR SPIR-V op definitions
12# spec.
13# <baseclass> is required. It will be the direct base class the newly defined
14# op will drive from.
15# If <opname> is missing, this script updates existing ones in <filename>.
16
17# For example:
18# ./define_inst.sh SPIRVArithmeticOps.td ArithmeticBinaryOp OpIAdd
19# ./define_inst.sh SPIRVLogicalOps.td LogicalOp OpFOrdEqual
20set -e
21
22file_name=$1
23baseclass=$2
24
25case $baseclass in
26  Op | ArithmeticBinaryOp | ArithmeticUnaryOp \
27     | LogicalBinaryOp | LogicalUnaryOp \
28     | CastOp | ControlFlowOp | StructureOp \
29     | AtomicUpdateOp | AtomicUpdateWithValueOp \
30     | KhrVendorOp | ExtVendorOp | IntelVendorOp | NvVendorOp )
31  ;;
32  *)
33    echo "Usage : " $0 "<filename> <baseclass> (<opname>)*"
34    echo "<filename> is the file name of MLIR SPIR-V op definitions spec"
35    echo "<baseclass> must be one of " \
36      "(Op|ArithmeticBinaryOp|ArithmeticUnaryOp|LogicalBinaryOp|LogicalUnaryOp|CastOp|ControlFlowOp|StructureOp|AtomicUpdateOp|KhrVendorOp|ExtVendorOp|IntelVendorOp|NvVendorOp)"
37    exit 1;
38  ;;
39esac
40
41shift
42shift
43
44current_file="$(readlink -f "$0")"
45current_dir="$(dirname "$current_file")"
46
47python3 ${current_dir}/gen_spirv_dialect.py \
48  --op-td-path \
49  ${current_dir}/../../include/mlir/Dialect/SPIRV/IR/${file_name} \
50  --inst-category $baseclass --new-inst "$@"
51
52${current_dir}/define_opcodes.sh "$@"
53
54