[Infra] Fix version-check workflow (#100090)
[llvm-project.git] / mlir / utils / spirv / define_inst.sh
blobeb37cef602a4ad2f60d5395b0ed4444d340d4079
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
6 # Script for defining a new op using SPIR-V spec from the Internet.
8 # Run as:
9 # ./define_inst.sh <filename> <baseclass> (<opname>)*
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>.
17 # For example:
18 # ./define_inst.sh SPIRVArithmeticOps.td ArithmeticBinaryOp OpIAdd
19 # ./define_inst.sh SPIRVLogicalOps.td LogicalOp OpFOrdEqual
20 set -e
22 file_name=$1
23 baseclass=$2
25 case $baseclass in
26 Op | ArithmeticBinaryOp | ArithmeticUnaryOp \
27 | LogicalBinaryOp | LogicalUnaryOp \
28 | CastOp | ControlFlowOp | StructureOp \
29 | AtomicUpdateOp | AtomicUpdateWithValueOp \
30 | KhrVendorOp | ExtVendorOp | IntelVendorOp | NvVendorOp )
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;
39 esac
41 shift
42 shift
44 current_file="$(readlink -f "$0")"
45 current_dir="$(dirname "$current_file")"
47 python3 ${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 "$@"
52 ${current_dir}/define_opcodes.sh "$@"