1//===- InferTypeOpInterface.td - Infer Type interfaces -----*- 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 file contains a set of interfaces that can be used to define information 10// related to type inference. 11// 12//===----------------------------------------------------------------------===// 13 14#ifndef MLIR_INFERTYPEOPINTERFACE 15#define MLIR_INFERTYPEOPINTERFACE 16 17include "mlir/IR/OpBase.td" 18 19// OpInterface to compute the return type of an operation. The arguments match 20// those in Operation::create with the exception that the location is optional 21// (if no location is provided, then the method will not emit an error on 22// mismatch). 23def InferTypeOpInterface : OpInterface<"InferTypeOpInterface"> { 24 let description = [{ 25 Interface to infer the return types for an operation that could be used 26 during op construction, verification or type inference. 27 }]; 28 let cppNamespace = "::mlir"; 29 30 let methods = [ 31 StaticInterfaceMethod< 32 /*desc=*/[{Infer the return types that an op would generate. 33 34 The method takes an optional location which, if set, will be used to 35 report errors on. The operands and attributes correspond to those with 36 which an Operation would be created (e.g., as used in Operation::create) 37 and the regions of the op. 38 }], 39 /*retTy=*/"::mlir::LogicalResult", 40 /*methodName=*/"inferReturnTypes", 41 /*args=*/(ins "::mlir::MLIRContext *":$context, 42 "::llvm::Optional<::mlir::Location>":$location, 43 "::mlir::ValueRange":$operands, 44 "::mlir::DictionaryAttr":$attributes, 45 "::mlir::RegionRange":$regions, 46 "::llvm::SmallVectorImpl<::mlir::Type>&":$inferredReturnTypes) 47 >, 48 StaticInterfaceMethod< 49 /*desc=*/"Returns whether two array of types are compatible result types" 50 " for an op.", 51 /*retTy=*/"bool", 52 /*methodName=*/"isCompatibleReturnTypes", 53 /*args=*/(ins "::llvm::ArrayRef<::mlir::Type>":$lhs, 54 "::llvm::ArrayRef<::mlir::Type>":$rhs), 55 /*methodBody=*/[{ 56 return ConcreteOp::isCompatibleReturnTypes(lhs, rhs); 57 }], 58 /*defaultImplementation=*/[{ 59 /// Returns whether two arrays are equal as strongest check for 60 /// compatibility by default. 61 return lhs == rhs; 62 }] 63 >, 64 ]; 65 66 let verify = [{ 67 return detail::verifyInferredResultTypes($_op); 68 }]; 69} 70 71def InferShapedTypeOpInterface : OpInterface<"InferShapedTypeOpInterface"> { 72 let description = [{ 73 Interface to infer the components of a ShapedType returned by an operation 74 that could be used during op construction, verification or shape inference. 75 76 The components consists of element type, shape and raw attribute. 77 }]; 78 let cppNamespace = "::mlir"; 79 80 let methods = [ 81 StaticInterfaceMethod< 82 /*desc=*/[{Infer the components of return type of shape containter. 83 84 The method takes an optional location which, if set, will be used to 85 report errors on. The operands and attributes correspond to those with 86 which an Operation would be created (e.g., as used in Operation::create) 87 and the regions of the op. 88 89 Unknown (e.g., unranked) shape and nullptrs for element type and attribute 90 may be returned by this function while returning success. E.g., partial 91 population of components is not error condition. 92 }], 93 /*retTy=*/"LogicalResult", 94 /*methodName=*/"inferReturnTypeComponents", 95 /*args=*/(ins "MLIRContext*":$context, 96 "Optional<Location>":$location, 97 "ValueRange":$operands, 98 "DictionaryAttr":$attributes, 99 "RegionRange":$regions, 100 "SmallVectorImpl<ShapedTypeComponents>&": 101 $inferredReturnShapes) 102 >, 103 InterfaceMethod< 104 /*desc=*/[{Reify the shape computation for the operation. 105 106 Insert operations using the given OpBuilder that computes the result 107 shape. 108 }], 109 /*retTy=*/"LogicalResult", 110 /*methodName=*/"reifyReturnTypeShapes", 111 /*args=*/(ins "OpBuilder&":$builder, 112 "SmallVectorImpl<Value>&":$reifiedReturnShapes), 113 /*methodBody=*/[{}], 114 /*defaultImplementation=*/[{ return failure(); }] 115 >, 116 ]; 117} 118 119#endif // MLIR_INFERTYPEOPINTERFACE 120