diff --git a/mlir/lib/Tools/PDLL/CodeGen/MLIRGen.cpp b/mlir/lib/Tools/PDLL/CodeGen/MLIRGen.cpp --- a/mlir/lib/Tools/PDLL/CodeGen/MLIRGen.cpp +++ b/mlir/lib/Tools/PDLL/CodeGen/MLIRGen.cpp @@ -444,11 +444,19 @@ assert(opType.getName() && "expected valid operation name"); const ods::Operation *odsOp = odsContext.lookupOperation(*opType.getName()); - assert(odsOp && "expected valid ODS operation information"); + + unsigned resultIndex; + if (!odsOp) { + assert(llvm::isDigit(name[0]) && "unregistered op only allows numeric indexing"); + name.getAsInteger(/*Radix=*/10, resultIndex); + IntegerAttr index = builder.getI32IntegerAttr(resultIndex); + return builder.create(loc, genType(expr->getType()), + parentExprs[0], index); + } // Find the result with the member name or by index. ArrayRef results = odsOp->getResults(); - unsigned resultIndex = results.size(); + resultIndex = results.size(); if (llvm::isDigit(name[0])) { name.getAsInteger(/*Radix=*/10, resultIndex); } else { diff --git a/mlir/lib/Tools/PDLL/Parser/Parser.cpp b/mlir/lib/Tools/PDLL/Parser/Parser.cpp --- a/mlir/lib/Tools/PDLL/Parser/Parser.cpp +++ b/mlir/lib/Tools/PDLL/Parser/Parser.cpp @@ -2683,8 +2683,11 @@ }); if (it != results.end()) return it->isVariadic() ? valueRangeTy : valueTy; + } else if (llvm::isDigit(name[0])) { + // For unregistered op, we allow unchecked numeric indexing and it'll be + // supposed to be a single value. + return valueTy; } - } else if (auto tupleType = parentType.dyn_cast()) { // Handle indexed results. unsigned index = 0; diff --git a/mlir/test/mlir-pdll/CodeGen/MLIR/expr.pdll b/mlir/test/mlir-pdll/CodeGen/MLIR/expr.pdll --- a/mlir/test/mlir-pdll/CodeGen/MLIR/expr.pdll +++ b/mlir/test/mlir-pdll/CodeGen/MLIR/expr.pdll @@ -55,6 +55,19 @@ // ----- +// Handle result indexing on unregistered op. +// CHECK: pdl.pattern @UnregisteredOpResultIndexing +// CHECK: %[[BAR_OP:.*]] = operation "unregistered.bar" +// CHECK: %[[BAR_RES:.*]] = result 0 of %[[BAR_OP]] +// CHECK: operation "unregistered.foo"(%[[BAR_RES]] : !pdl.value) +Pattern UnregisteredOpResultIndexing { + let bar : Op; + let op = op(bar.0); + erase op; +} + +// ----- + // Handle implicit "named" operation results access. #include "include/ops.td" diff --git a/mlir/test/mlir-pdll/Parser/expr.pdll b/mlir/test/mlir-pdll/Parser/expr.pdll --- a/mlir/test/mlir-pdll/Parser/expr.pdll +++ b/mlir/test/mlir-pdll/Parser/expr.pdll @@ -90,6 +90,26 @@ // ----- +// CHECK: Module +// CHECK: `-VariableDecl {{.*}} Name Type> +// CHECK: `-OperationExpr {{.*}} Type> +// CHECK: `-OpNameDecl {{.*}} Name +// CHECK: `Operands` +// CHECK: `-MemberAccessExpr {{.*}} Member<0> Type +// CHECK: `-OperationExpr {{.*}} Type> +// CHECK: `-OpNameDecl {{.*}} Name +// CHECK: `Operands` +// CHECK: `-DeclRefExpr {{.*}} Type +// CHECK: `-VariableDecl {{.*}} Name<_> Type +// CHECK: `Constraints` +// CHECK: `-ValueRangeConstraintDecl +Pattern { + let op = op(op.0); + erase op; +} + +// ----- + //===----------------------------------------------------------------------===// // OperationExpr //===----------------------------------------------------------------------===//