[Mlir-commits] [mlir] 2f78b43 - [mlir][ods] Fix builder gen for VariadicRegion with inferred types
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Apr 7 11:22:53 PDT 2022
Author: Mogball
Date: 2022-04-07T18:22:49Z
New Revision: 2f78b43f4bafaed09f6549da393bd9ee056ed851
URL: https://github.com/llvm/llvm-project/commit/2f78b43f4bafaed09f6549da393bd9ee056ed851
DIFF: https://github.com/llvm/llvm-project/commit/2f78b43f4bafaed09f6549da393bd9ee056ed851.diff
LOG: [mlir][ods] Fix builder gen for VariadicRegion with inferred types
Builders generated for ops with variadic regions and inferred return types were not being correctly generated (missing parameter).
Added:
Modified:
mlir/test/lib/Dialect/Test/TestOps.td
mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
Removed:
################################################################################
diff --git a/mlir/test/lib/Dialect/Test/TestOps.td b/mlir/test/lib/Dialect/Test/TestOps.td
index 36e31d1ff1750..9902b57323ca3 100644
--- a/mlir/test/lib/Dialect/Test/TestOps.td
+++ b/mlir/test/lib/Dialect/Test/TestOps.td
@@ -347,6 +347,22 @@ def SizedRegionOp : TEST_Op<"sized_region_op", []> {
let regions = (region SizedRegion<2>:$my_region, SizedRegion<1>);
}
+def VariadicRegionInferredTypesOp : TEST_Op<"variadic_region_inferred",
+ [InferTypeOpInterface]> {
+ let regions = (region VariadicRegion<AnyRegion>:$bodies);
+ let results = (outs Variadic<AnyType>);
+
+ let extraClassDeclaration = [{
+ static mlir::LogicalResult 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();
+ }
+ }];
+}
+
//===----------------------------------------------------------------------===//
// NoTerminator Operation
//===----------------------------------------------------------------------===//
diff --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
index d54bd7e493ab7..be7ff05e2c993 100644
--- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
@@ -1373,13 +1373,16 @@ void OpEmitter::genUseOperandAsResultTypeCollectiveParamBuilder() {
}
void OpEmitter::genInferredTypeCollectiveParamBuilder() {
- // TODO: Expand to support regions.
SmallVector<MethodParameter> paramList;
paramList.emplace_back("::mlir::OpBuilder &", "odsBuilder");
paramList.emplace_back("::mlir::OperationState &", builderOpState);
paramList.emplace_back("::mlir::ValueRange", "operands");
+ StringRef attributesDefaultValue = op.getNumVariadicRegions() ? "" : "{}";
paramList.emplace_back("::llvm::ArrayRef<::mlir::NamedAttribute>",
- "attributes", "{}");
+ "attributes", attributesDefaultValue);
+ if (op.getNumVariadicRegions())
+ paramList.emplace_back("unsigned", "numRegions");
+
auto *m = opClass.addStaticMethod("void", "build", std::move(paramList));
// If the builder is redundant, skip generating the method
if (!m)
More information about the Mlir-commits
mailing list