::llvm::LogicalResult AddOp::inferReturnTypes( ::mlir::MLIRContext* context, ::std::optional<::mlir::Location> location, ::mlir::ValueRange operands, ::mlir::DictionaryAttr attributes, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions, ::llvm::SmallVectorImpl<::mlir::Type>& inferredReturnTypes){ inferredReturnTypes.resize(1); // Represent AddOp's output as a single type. ::mlir::Builder odsBuilder(context); if (operands.size() <= 0) // Check that there is at least one operand. return ::mlir::failure(); ::mlir::Type odsInferredType0 = operands[0].getType(); inferredReturnTypes[0] = odsInferredType0; // Set the output type to the first operand's type. return ::mlir::success(); }
def Poly_EvalOp : Op<Poly_Dialect, "eval", [AllTypesMatch<["point", "output"]>]> { let summary = "Evaluates a Polynomial at a given input value."; let arguments = (ins Polynomial:$input, AnyInteger:$point); let results = (outs AnyInteger:$output); }
// lib/Dialect/Poly/PolyOps.cpp LogicalResult EvalOp::verify(){ returngetPoint().getType().isSignlessInteger(32) ? success() : emitError("argument point must be a 32-bit integer"); }
template <typename ConcreteType> classHas32BitArguments : public OpTrait::TraitBase<ConcreteType, Has32BitArguments> { public: static LogicalResult verifyTrait(Operation *op){ for (auto type : op->getOperandTypes()) { // OK to skip non-integer operand types if (!type.isIntOrIndex()) continue;
if (!type.isInteger(32)) { return op->emitOpError() << "requires each numeric operand to be a 32-bit integer"; } }