1//===- SPIRVAvailability.td - Op Availability Base file ----*- tablegen -*-===// 2// 3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4// See https://llvm.org/LICENSE.txt for license information. 5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6// 7//===----------------------------------------------------------------------===// 8 9#ifndef SPIRV_AVAILABILITY 10#define SPIRV_AVAILABILITY 11 12include "mlir/IR/OpBase.td" 13 14//===----------------------------------------------------------------------===// 15// Op availability definitions 16//===----------------------------------------------------------------------===// 17 18// The base class for defining op availability dimensions. 19class Availability { 20 // The following are fields for controlling the generated C++ OpInterface. 21 22 // The name for the generated C++ OpInterface subclass. 23 string interfaceName = ?; 24 // The documentation for the generated C++ OpInterface subclass. 25 string interfaceDescription = ""; 26 27 // The following are fields for controlling the query function signature. 28 29 // The query function's return type in the generated C++ OpInterface subclass. 30 string queryFnRetType = ?; 31 // The query function's name in the generated C++ OpInterface subclass. 32 string queryFnName = ?; 33 34 // The following are fields for controlling the query function implementation. 35 36 // The logic for merging two availability requirements. This is used to derive 37 // the final availability requirement when, for example, an op has two 38 // operands and these two operands have different availability requirements. 39 // 40 // The code should use `$overall` as the placeholder for the final requirement 41 // and `$instance` for the current availability requirement instance. 42 code mergeAction = ?; 43 // The initializer for the final availability requirement. 44 string initializer = ?; 45 // An availability instance's type. 46 string instanceType = ?; 47 48 // The following are fields for a concrete availability instance. 49 50 // The code for preparing a concrete instance. This should be C++ statements 51 // and will be generated before the `mergeAction` logic. 52 code instancePreparation = ""; 53 // The availability requirement carried by a concrete instance. 54 string instance = ?; 55} 56 57class MinVersionBase<string name, I32EnumAttr scheme, I32EnumAttrCase min> 58 : Availability { 59 let interfaceName = name; 60 61 let queryFnRetType = scheme.returnType; 62 let queryFnName = "getMinVersion"; 63 64 let mergeAction = "$overall = static_cast<" # scheme.returnType # ">(" 65 "std::max($overall, $instance))"; 66 let initializer = "static_cast<" # scheme.returnType # ">(uint32_t(0))"; 67 let instanceType = scheme.cppNamespace # "::" # scheme.className; 68 69 let instance = scheme.cppNamespace # "::" # scheme.className # "::" # 70 min.symbol; 71} 72 73class MaxVersionBase<string name, I32EnumAttr scheme, I32EnumAttrCase max> 74 : Availability { 75 let interfaceName = name; 76 77 let queryFnRetType = scheme.returnType; 78 let queryFnName = "getMaxVersion"; 79 80 let mergeAction = "$overall = static_cast<" # scheme.returnType # ">(" 81 "std::min($overall, $instance))"; 82 let initializer = "static_cast<" # scheme.returnType # ">(~uint32_t(0))"; 83 let instanceType = scheme.cppNamespace # "::" # scheme.className; 84 85 let instance = scheme.cppNamespace # "::" # scheme.className # "::" # 86 max.symbol; 87} 88 89#endif // SPIRV_AVAILABILITY 90