Author: Rahul Joshi Date: 2020-12-01T13:36:25-08:00 New Revision: 6b043ecdb71bb0354cbd64d766cc21b7d20dca84
URL: https://github.com/llvm/llvm-project/commit/6b043ecdb71bb0354cbd64d766cc21b7d20dca84 DIFF: https://github.com/llvm/llvm-project/commit/6b043ecdb71bb0354cbd64d766cc21b7d20dca84.diff LOG: [MLIR] Fix genTypeInterfaceMethods() to work correctly with InferTypeOpInterface - Change InferTypeOpInterface::inferResultTypes to use fully qualified types matching the ones generated by genTypeInterfaceMethods, so the redundancy can be detected. - Move genTypeInterfaceMethods() before genOpInterfaceMethods() so that the inferResultTypes method generated by genTypeInterfaceMethods() takes precedence over the declaration that might be generated by genOpInterfaceMethods() - Modified an op in the test dialect to exercise this (the modified op would fail to generate valid C++ code due to duplicate inferResultTypes methods). Differential Revision: https://reviews.llvm.org/D92414 Added: Modified: mlir/include/mlir/Interfaces/InferTypeOpInterface.td mlir/test/lib/Dialect/Test/TestOps.td mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp Removed: ################################################################################ diff --git a/mlir/include/mlir/Interfaces/InferTypeOpInterface.td b/mlir/include/mlir/Interfaces/InferTypeOpInterface.td index c5132986ec97..ed62e9015bde 100644 --- a/mlir/include/mlir/Interfaces/InferTypeOpInterface.td +++ b/mlir/include/mlir/Interfaces/InferTypeOpInterface.td @@ -38,19 +38,20 @@ def InferTypeOpInterface : OpInterface<"InferTypeOpInterface"> { }], /*retTy=*/"LogicalResult", /*methodName=*/"inferReturnTypes", - /*args=*/(ins "MLIRContext*":$context, - "Optional<Location>":$location, - "ValueRange":$operands, - "DictionaryAttr":$attributes, - "RegionRange":$regions, - "SmallVectorImpl<Type>&":$inferredReturnTypes) + /*args=*/(ins "::mlir::MLIRContext *":$context, + "::llvm::Optional<::mlir::Location>":$location, + "::mlir::ValueRange":$operands, + "::mlir::DictionaryAttr":$attributes, + "::mlir::RegionRange":$regions, + "::llvm::SmallVectorImpl<::mlir::Type>&":$inferredReturnTypes) >, StaticInterfaceMethod< /*desc=*/"Returns whether two array of types are compatible result types" " for an op.", /*retTy=*/"bool", /*methodName=*/"isCompatibleReturnTypes", - /*args=*/(ins "ArrayRef<Type>":$lhs, "ArrayRef<Type>":$rhs), + /*args=*/(ins "::llvm::ArrayRef<::mlir::Type>":$lhs, + "::llvm::ArrayRef<::mlir::Type>":$rhs), /*methodBody=*/[{ return ConcreteOp::isCompatibleReturnTypes(lhs, rhs); }], diff --git a/mlir/test/lib/Dialect/Test/TestOps.td b/mlir/test/lib/Dialect/Test/TestOps.td index 5a17eebfd32c..995022ab2115 100644 --- a/mlir/test/lib/Dialect/Test/TestOps.td +++ b/mlir/test/lib/Dialect/Test/TestOps.td @@ -1000,7 +1000,7 @@ def ThreeResultOp : TEST_Op<"three_result"> { let results = (outs I32:$result1, F32:$result2, F32:$result3); } -def AnotherThreeResultOp : TEST_Op<"another_three_result"> { +def AnotherThreeResultOp : TEST_Op<"another_three_result", [DeclareOpInterfaceMethods<InferTypeOpInterface>]> { let arguments = (ins MultiResultOpEnum:$kind); let results = (outs I32:$result1, F32:$result2, F32:$result3); } diff --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp index 65ae32f4f5a4..eabdd06fad5d 100644 --- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp +++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp @@ -453,10 +453,10 @@ OpEmitter::OpEmitter(const Operator &op) genVerifier(); genCanonicalizerDecls(); genFolderDecls(); + genTypeInterfaceMethods(); genOpInterfaceMethods(); generateOpFormat(op, opClass); genSideEffectInterfaceMethods(); - genTypeInterfaceMethods(); } void OpEmitter::emitDecl(const Operator &op, raw_ostream &os) { @@ -1739,7 +1739,6 @@ void OpEmitter::genTypeInterfaceMethods() { auto *method = opClass.addMethodAndPrune("::mlir::LogicalResult", "inferReturnTypes", OpMethod::MP_Static, std::move(paramList)); - auto &body = method->body(); body << " inferredReturnTypes.resize(" << op.getNumResults() << ");\n"; _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits