1//===- SPIRVOCLOps.td - OpenCL 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 OpenCL extension ops. 10// 11//===----------------------------------------------------------------------===// 12 13#ifndef SPIRV_OCL_OPS 14#define SPIRV_OCL_OPS 15 16include "mlir/Dialect/SPIRV/SPIRVBase.td" 17 18//===----------------------------------------------------------------------===// 19// SPIR-V OpenCL opcode specification. 20//===----------------------------------------------------------------------===// 21 22// Base class for all OpenCL ops. 23class SPV_OCLOp<string mnemonic, int opcode, list<OpTrait> traits = []> : 24 SPV_ExtInstOp<mnemonic, "OCL", "OpenCL.std", opcode, traits>; 25 26// Base class for OpenCL unary ops. 27class SPV_OCLUnaryOp<string mnemonic, int opcode, Type resultType, 28 Type operandType, list<OpTrait> traits = []> : 29 SPV_OCLOp<mnemonic, opcode, !listconcat([NoSideEffect], traits)> { 30 31 let arguments = (ins 32 SPV_ScalarOrVectorOf<operandType>:$operand 33 ); 34 35 let results = (outs 36 SPV_ScalarOrVectorOf<resultType>:$result 37 ); 38 39 let parser = [{ return parseUnaryOp(parser, result); }]; 40 41 let printer = [{ return printUnaryOp(getOperation(), p); }]; 42 43 let verifier = [{ return success(); }]; 44} 45 46// Base class for OpenCL Unary arithmetic ops where return type matches 47// the operand type. 48class SPV_OCLUnaryArithmeticOp<string mnemonic, int opcode, Type type, 49 list<OpTrait> traits = []> : 50 SPV_OCLUnaryOp<mnemonic, opcode, type, type, traits>; 51 52// Base class for OpenCL binary ops. 53class SPV_OCLBinaryOp<string mnemonic, int opcode, Type resultType, 54 Type operandType, list<OpTrait> traits = []> : 55 SPV_OCLOp<mnemonic, opcode, !listconcat([NoSideEffect], traits)> { 56 57 let arguments = (ins 58 SPV_ScalarOrVectorOf<operandType>:$lhs, 59 SPV_ScalarOrVectorOf<operandType>:$rhs 60 ); 61 62 let results = (outs 63 SPV_ScalarOrVectorOf<resultType>:$result 64 ); 65 66 let parser = [{ return impl::parseOneResultSameOperandTypeOp(parser, result); }]; 67 68 let printer = [{ return impl::printOneResultOp(getOperation(), p); }]; 69 70 let verifier = [{ return success(); }]; 71} 72 73// Base class for OpenCL Binary arithmetic ops where operand types and 74// return type matches. 75class SPV_OCLBinaryArithmeticOp<string mnemonic, int opcode, Type type, 76 list<OpTrait> traits = []> : 77 SPV_OCLBinaryOp<mnemonic, opcode, type, type, traits>; 78 79// ----- 80 81def SPV_OCLExpOp : SPV_OCLUnaryArithmeticOp<"exp", 19, SPV_Float> { 82 let summary = "Exponentiation of Operand 1"; 83 84 let description = [{ 85 Compute the base-e exponential of x. (i.e. ex) 86 87 Result Type and x must be floating-point or vector(2,3,4,8,16) of 88 floating-point values. 89 90 All of the operands, including the Result Type operand, 91 must be of the same type. 92 93 <!-- End of AutoGen section --> 94 ``` 95 float-scalar-vector-type ::= float-type | 96 `vector<` integer-literal `x` float-type `>` 97 exp-op ::= ssa-id `=` `spv.OCL.exp` ssa-use `:` 98 float-scalar-vector-type 99 ``` 100 #### Example: 101 102 ```mlir 103 %2 = spv.OCL.exp %0 : f32 104 %3 = spv.OCL.exp %1 : vector<3xf16> 105 ``` 106 }]; 107} 108 109// ----- 110 111def SPV_OCLFAbsOp : SPV_OCLUnaryArithmeticOp<"fabs", 23, SPV_Float> { 112 let summary = "Absolute value of operand"; 113 114 let description = [{ 115 Compute the absolute value of x. 116 117 Result Type and x must be floating-point or vector(2,3,4,8,16) of 118 floating-point values. 119 120 All of the operands, including the Result Type operand, 121 must be of the same type. 122 123 <!-- End of AutoGen section --> 124 ``` 125 float-scalar-vector-type ::= float-type | 126 `vector<` integer-literal `x` float-type `>` 127 abs-op ::= ssa-id `=` `spv.OCL.fabs` ssa-use `:` 128 float-scalar-vector-type 129 ``` 130 #### Example: 131 132 ```mlir 133 %2 = spv.OCL.fabs %0 : f32 134 %3 = spv.OCL.fabs %1 : vector<3xf16> 135 ``` 136 }]; 137} 138 139// ----- 140 141def SPV_OCLSAbsOp : SPV_OCLUnaryArithmeticOp<"s_abs", 141, SPV_Integer> { 142 let summary = "Absolute value of operand"; 143 144 let description = [{ 145 Returns |x|, where x is treated as signed integer. 146 147 Result Type and x must be integer or vector(2,3,4,8,16) of 148 integer values. 149 150 All of the operands, including the Result Type operand, 151 must be of the same type. 152 153 <!-- End of AutoGen section --> 154 ``` 155 integer-scalar-vector-type ::= integer-type | 156 `vector<` integer-literal `x` integer-type `>` 157 abs-op ::= ssa-id `=` `spv.OCL.s_abs` ssa-use `:` 158 integer-scalar-vector-type 159 ``` 160 #### Example: 161 162 ```mlir 163 %2 = spv.OCL.s_abs %0 : i32 164 %3 = spv.OCL.s_abs %1 : vector<3xi16> 165 ``` 166 }]; 167} 168 169#endif // SPIRV_OCL_OPS 170