github.com/johnnyeven/libtools@v0.0.0-20191126065708-61829c1adf46/third_party/mlir/lib/Conversion/StandardToSPIRV/StandardToSPIRV.td (about) 1 //==- StandardToSPIRV.td - Standard Ops to SPIR-V Patterns ---*- tablegen -*==// 2 3 // Part of the MLIR 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 // Defines Patterns to lower standard ops to SPIR-V. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #ifdef MLIR_CONVERSION_STANDARDTOSPIRV_TD 14 #else 15 #define MLIR_CONVERSION_STANDARDTOSPIRV_TD 16 17 #ifdef STANDARD_OPS 18 #else 19 include "mlir/Dialect/StandardOps/Ops.td" 20 #endif // STANDARD_OPS 21 22 #ifdef SPIRV_OPS 23 #else 24 include "mlir/Dialect/SPIRV/SPIRVOps.td" 25 #endif // SPIRV_OPS 26 27 def IsScalar : TypeConstraint<CPred<"!($_self.isa<ShapedType>())">, "scalar">; 28 29 class IsVectorLengthPred<int vecLength> : 30 CPred<"($_self.cast<VectorType>().getShape().size() == 1 && " # 31 "$_self.cast<VectorType>().getShape()[0] == " # vecLength # ")">; 32 33 class IsVectorOfLength<int vecLength>: 34 TypeConstraint<And<[IsVectorTypePred, IsVectorLengthPred<vecLength>]>, 35 vecLength # "-element vector">; 36 37 multiclass BinaryOpPattern<Op src, SPV_Op tgt> { 38 def : Pat<(src IsScalar:$l, IsScalar:$r), (tgt $l, $r)>; 39 foreach vecLength = [2, 3, 4] in { 40 def : Pat<(src IsVectorOfLength<vecLength>:$l, 41 IsVectorOfLength<vecLength>:$r), 42 (tgt $l, $r)>; 43 } 44 } 45 46 defm : BinaryOpPattern<AddFOp, SPV_FAddOp>; 47 defm : BinaryOpPattern<MulFOp, SPV_FMulOp>; 48 49 #endif // MLIR_CONVERSION_STANDARDTOSPIRV_TD