return builder.create<TestOpConstant>(loc, type, value);
}
+::mlir::LogicalResult FormatInferType2Op::inferReturnTypes(
+ ::mlir::MLIRContext *context, ::llvm::Optional<::mlir::Location> location,
+ ::mlir::ValueRange operands, ::mlir::DictionaryAttr attributes,
+ ::mlir::RegionRange regions,
+ ::llvm::SmallVectorImpl<::mlir::Type> &inferredReturnTypes) {
+ inferredReturnTypes.assign({::mlir::IntegerType::get(context, 16)});
+ return ::mlir::success();
+}
+
void *TestDialect::getRegisteredInterfaceForOp(TypeID typeID,
OperationName opName) {
if (opName.getIdentifier() == "test.unregistered_side_effect_op" &&
}];
}
+// Check that formatget supports DeclareOpInterfaceMethods.
+def FormatInferType2Op : TEST_Op<"format_infer_type2", [DeclareOpInterfaceMethods<InferTypeOpInterface>]> {
+ let results = (outs AnyType);
+ let assemblyFormat = "attr-dict";
+}
+
// Base class for testing mixing allOperandTypes, allOperands, and
// inferResultTypes.
class FormatInferAllTypesBaseOp<string mnemonic, list<OpTrait> traits = []>
//===----------------------------------------------------------------------===//
// CHECK: test.format_infer_type
-%ignored_res7 = test.format_infer_type
+%ignored_res7a = test.format_infer_type
+
+// CHECK: test.format_infer_type2
+%ignored_res7b = test.format_infer_type2
// CHECK: test.format_infer_type_all_operands_and_types(%[[I64]], %[[I32]]) : i64, i32
%ignored_res8:2 = test.format_infer_type_all_operands_and_types(%i64, %i32) : i64, i32
handleSameTypesConstraint(variableTyResolver, /*includeResults=*/true);
} else if (def.isSubClassOf("TypesMatchWith")) {
handleTypesMatchConstraint(variableTyResolver, def);
- } else if (def.getName() == "InferTypeOpInterface" &&
- !op.allResultTypesKnown()) {
- canInferResultTypes = true;
+ } else if (!op.allResultTypesKnown()) {
+ // This doesn't check the name directly to handle
+ // DeclareOpInterfaceMethods<InferTypeOpInterface>
+ // and the like.
+ // TODO: Add hasCppInterface check.
+ if (auto name = def.getValueAsOptionalString("cppClassName")) {
+ if (*name == "InferTypeOpInterface" &&
+ def.getValueAsString("cppNamespace") == "::mlir")
+ canInferResultTypes = true;
+ }
}
}