|
| 1 | +//===- SPIRVGraphOps.td - Graph extended insts spec 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 | +// This is the op definition spec of Graph extension ops. |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | + |
| 13 | +#ifndef MLIR_DIALECT_SPIRV_IR_GRAPH_OPS |
| 14 | +#define MLIR_DIALECT_SPIRV_IR_GRAPH_OPS |
| 15 | + |
| 16 | +include "mlir/Dialect/SPIRV/IR/SPIRVBase.td" |
| 17 | +include "mlir/Interfaces/CallInterfaces.td" |
| 18 | +include "mlir/Interfaces/SideEffectInterfaces.td" |
| 19 | +include "mlir/Interfaces/FunctionInterfaces.td" |
| 20 | + |
| 21 | +//===----------------------------------------------------------------------===// |
| 22 | +// SPIR-V Graph opcode specification. |
| 23 | +//===----------------------------------------------------------------------===// |
| 24 | + |
| 25 | +// Base class for all Graph ops. |
| 26 | +class SPIRV_GraphARMOp<string mnemonic, list<Trait> traits = []> : |
| 27 | + SPIRV_ArmVendorOp<mnemonic, traits> { |
| 28 | + |
| 29 | + let availability = [ |
| 30 | + MinVersion<SPIRV_V_1_0>, |
| 31 | + MaxVersion<SPIRV_V_1_6>, |
| 32 | + Extension<[SPV_ARM_graph, SPV_ARM_tensors, SPV_KHR_vulkan_memory_model]>, |
| 33 | + Capability<[SPIRV_C_GraphARM]> |
| 34 | + ]; |
| 35 | +} |
| 36 | + |
| 37 | +def SPIRV_GraphConstantARMOp : SPIRV_GraphARMOp<"GraphConstant", [Pure]> { |
| 38 | + let summary = "Declare a graph constant."; |
| 39 | + |
| 40 | + let description = [{ |
| 41 | + Declare a graph constant. |
| 42 | + Result Type must be an OpTypeTensorARM. |
| 43 | + GraphConstantID must be a 32-bit integer literal. |
| 44 | + }]; |
| 45 | + |
| 46 | + let arguments = (ins |
| 47 | + I32Attr: $graph_constant_id |
| 48 | + ); |
| 49 | + |
| 50 | + let results = (outs |
| 51 | + SPIRV_AnyTensorArm:$output |
| 52 | + ); |
| 53 | + |
| 54 | + let hasVerifier = 0; |
| 55 | + |
| 56 | + let autogenSerialization = 0; |
| 57 | + |
| 58 | + let assemblyFormat = [{ |
| 59 | + attr-dict `:` type($output) |
| 60 | + }]; |
| 61 | +} |
| 62 | + |
| 63 | +// ----- |
| 64 | + |
| 65 | +def SPIRV_GraphARMOp : SPIRV_GraphARMOp<"Graph", [ |
| 66 | + AutomaticAllocationScope, DeclareOpInterfaceMethods<CallableOpInterface>, |
| 67 | + FunctionOpInterface, InModuleScope, IsolatedFromAbove |
| 68 | + ]> { |
| 69 | + |
| 70 | + let summary = "Declare or define a SPIR-V graph"; |
| 71 | + |
| 72 | + let description = [{ |
| 73 | + This op declares or defines a SPIR-V graph using one region, which |
| 74 | + contains one or more blocks. |
| 75 | + |
| 76 | + Different from the SPIR-V binary format, this op is not allowed to |
| 77 | + implicitly capture global values, and all external references must use |
| 78 | + function arguments or symbol references. This op itself defines a symbol |
| 79 | + that is unique in the enclosing module op. |
| 80 | + |
| 81 | + This op itself takes no operands and generates no results. Its region |
| 82 | + can take zero or more arguments and return zero or more values. |
| 83 | + |
| 84 | + ``` |
| 85 | + spv-graph-arm-op ::= `spirv.ARM.Graph` function-signature |
| 86 | + region |
| 87 | + ``` |
| 88 | + }]; |
| 89 | + |
| 90 | + let arguments = (ins |
| 91 | + TypeAttrOf<GraphType>:$function_type, |
| 92 | + OptionalAttr<DictArrayAttr>:$arg_attrs, |
| 93 | + OptionalAttr<DictArrayAttr>:$res_attrs, |
| 94 | + OptionalAttr<BoolAttr>:$entry_point, |
| 95 | + StrAttr:$sym_name |
| 96 | + ); |
| 97 | + |
| 98 | + let results = (outs); |
| 99 | + |
| 100 | + let regions = (region AnyRegion:$body); |
| 101 | + |
| 102 | + let hasVerifier = 0; |
| 103 | + |
| 104 | + let builders = [ |
| 105 | + OpBuilder<(ins "StringRef":$name, "GraphType":$type, |
| 106 | + CArg<"ArrayRef<NamedAttribute>", "{}">:$attrs, CArg<"bool", "false">:$entry_point)>]; |
| 107 | + |
| 108 | + let hasOpcode = 0; |
| 109 | + |
| 110 | + let autogenSerialization = 0; |
| 111 | + |
| 112 | + let extraClassDeclaration = [{ |
| 113 | + /// Hook for FunctionOpInterface, called after verifying that the 'type' |
| 114 | + /// attribute is present and checks if it holds a function type. Ensures |
| 115 | + /// getType, getNumArguments, and getNumResults can be called safely |
| 116 | + LogicalResult verifyType(); |
| 117 | + |
| 118 | + /// Hook for FunctionOpInterface, called after verifying the function |
| 119 | + /// type and the presence of the (potentially empty) function body. |
| 120 | + /// Ensures SPIR-V specific semantics. |
| 121 | + LogicalResult verifyBody(); |
| 122 | + }]; |
| 123 | +} |
| 124 | + |
| 125 | +// Check that an op can only be used within the scope of a spirv.ARM.Graph op. |
| 126 | +def InGraphScope : PredOpTrait< |
| 127 | + "op must appear in a spirv.ARM.Graph op's block", |
| 128 | + CPred<"isNestedInGraphARMOpInterface($_op.getParentOp())">>; |
| 129 | + |
| 130 | +// ----- |
| 131 | + |
| 132 | +def SPIRV_GraphEntryPointARMOp : SPIRV_GraphARMOp<"GraphEntryPoint", [InModuleScope]> { |
| 133 | + let summary = [{ |
| 134 | + Declare a graph entry point and its interface. |
| 135 | + }]; |
| 136 | + |
| 137 | + let description = [{ |
| 138 | + Graph Entry Point must be the Result <id> of an OpGraphARM instruction. |
| 139 | + |
| 140 | + Name is a name string for the graphentry point. A module cannot have two |
| 141 | + OpGraphEntryPointARM instructions with the same Name string. |
| 142 | + |
| 143 | + Interface is a list of symbol references to `spirv.GlobalVariable` |
| 144 | + operations. These declare the set of global variables from a |
| 145 | + module that form the interface of this entry point. The set of |
| 146 | + Interface symbols must be equal to or a superset of the |
| 147 | + `spirv.GlobalVariable`s referenced by the entry point’s static call |
| 148 | + tree, within the interface’s storage classes. |
| 149 | + |
| 150 | + ``` |
| 151 | + entry-point-op ::= ssa-id `=` `spirv.ARM.GraphEntryPoint` |
| 152 | + symbol-reference (`, ` symbol-reference)* |
| 153 | + ``` |
| 154 | + }]; |
| 155 | + |
| 156 | + let arguments = (ins |
| 157 | + FlatSymbolRefAttr:$fn, |
| 158 | + SymbolRefArrayAttr:$interface |
| 159 | + ); |
| 160 | + |
| 161 | + let results = (outs); |
| 162 | + |
| 163 | + let autogenSerialization = 0; |
| 164 | + |
| 165 | + let builders = [ |
| 166 | + OpBuilder<(ins "spirv::GraphARMOp":$graph, "ArrayRef<Attribute>":$interfaceVars)>]; |
| 167 | +} |
| 168 | + |
| 169 | +// ----- |
| 170 | + |
| 171 | +def SPIRV_GraphOutputsARMOp : SPIRV_GraphARMOp<"GraphOutputs", [InGraphScope, Pure, |
| 172 | + Terminator]> { |
| 173 | + |
| 174 | + let summary = "Define graph outputs."; |
| 175 | + |
| 176 | + let description = [{ |
| 177 | + Values are the graph outputs values and must match the GraphOutputs Type |
| 178 | + operand of the OpTypeGraphARM type of the OpGraphARM body this |
| 179 | + instruction is in. |
| 180 | + |
| 181 | + This instruction must be the last instruction in a block. |
| 182 | + |
| 183 | + ``` |
| 184 | + graph-output-op ::= `spirv.ARM.GraphOutputs` ssa-use `:` type-list-no-parens |
| 185 | + ``` |
| 186 | + }]; |
| 187 | + |
| 188 | + let arguments = (ins |
| 189 | + Variadic<SPIRV_AnyTensorArm>:$value |
| 190 | + ); |
| 191 | + |
| 192 | + let results = (outs); |
| 193 | + |
| 194 | + let autogenSerialization = 0; |
| 195 | + |
| 196 | + let hasOpcode = 0; |
| 197 | + |
| 198 | + let assemblyFormat = "$value attr-dict `:` type($value)"; |
| 199 | +} |
| 200 | + |
| 201 | +#endif // MLIR_DIALECT_SPIRV_IR_GRAPH_OPS |
0 commit comments