1//===- CastInterfaces.td - Cast Interfaces for ops ---------*- 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 cast-like operations. 11// 12//===----------------------------------------------------------------------===// 13 14#ifndef MLIR_INTERFACES_CASTINTERFACES 15#define MLIR_INTERFACES_CASTINTERFACES 16 17include "mlir/IR/OpBase.td" 18 19def CastOpInterface : OpInterface<"CastOpInterface"> { 20 let description = [{ 21 A cast-like operation is one that converts from a set of input types to a 22 set of output types. The arity of the inputs may be from 0-N, whereas the 23 arity of the outputs may be anything from 1-N. Cast-like operations are 24 trivially removable in cases where they produce an No-op, i.e when the 25 input types and output types match 1-1. 26 }]; 27 let cppNamespace = "::mlir"; 28 29 let methods = [ 30 StaticInterfaceMethod<[{ 31 Returns true if the given set of input and result types are compatible 32 to cast using this cast operation. 33 }], 34 "bool", "areCastCompatible", 35 (ins "::mlir::TypeRange":$inputs, "::mlir::TypeRange":$outputs) 36 >, 37 ]; 38 39 let extraTraitClassDeclaration = [{ 40 /// Attempt to fold the given cast operation. 41 static LogicalResult foldTrait(Operation *op, ArrayRef<Attribute> operands, 42 SmallVectorImpl<OpFoldResult> &results) { 43 return impl::foldCastInterfaceOp(op, operands, results); 44 } 45 }]; 46 let verify = [{ 47 return impl::verifyCastInterfaceOp($_op); 48 }]; 49} 50 51#endif // MLIR_INTERFACES_CASTINTERFACES 52