|
11 | 11 | //===----------------------------------------------------------------------===//
|
12 | 12 |
|
13 | 13 | #include "mlir/Support/IndentedOstream.h"
|
| 14 | +#include "mlir/TableGen/Argument.h" |
14 | 15 | #include "mlir/TableGen/Attribute.h"
|
15 | 16 | #include "mlir/TableGen/CodeGenHelpers.h"
|
16 | 17 | #include "mlir/TableGen/Format.h"
|
17 | 18 | #include "mlir/TableGen/GenInfo.h"
|
18 | 19 | #include "mlir/TableGen/Operator.h"
|
19 | 20 | #include "mlir/TableGen/Pattern.h"
|
20 | 21 | #include "mlir/TableGen/Predicate.h"
|
| 22 | +#include "mlir/TableGen/Property.h" |
21 | 23 | #include "mlir/TableGen/Type.h"
|
22 | 24 | #include "llvm/ADT/FunctionExtras.h"
|
23 | 25 | #include "llvm/ADT/SetVector.h"
|
@@ -1518,10 +1520,36 @@ std::string PatternEmitter::handleOpCreation(DagNode tree, int resultIndex,
|
1518 | 1520 | // the key. This includes both bound and unbound child nodes.
|
1519 | 1521 | ChildNodeIndexNameMap childNodeNames;
|
1520 | 1522 |
|
| 1523 | + // If the argument is a type constraint, then its an operand. Check if the |
| 1524 | + // op's argument is variadic that the argument in the pattern is too. |
| 1525 | + auto checkIfMatchedVariadic = [&](int i) { |
| 1526 | + // FIXME: This does not yet check for variable/leaf case. |
| 1527 | + // FIXME: Change so that native code call can be handled. |
| 1528 | + const auto *operand = |
| 1529 | + llvm::dyn_cast_if_present<NamedTypeConstraint *>(resultOp.getArg(i)); |
| 1530 | + if (!operand || !operand->isVariadic()) |
| 1531 | + return; |
| 1532 | + |
| 1533 | + auto child = tree.getArgAsNestedDag(i); |
| 1534 | + if (!child) |
| 1535 | + return; |
| 1536 | + |
| 1537 | + // Skip over replaceWithValues. |
| 1538 | + while (child.isReplaceWithValue()) { |
| 1539 | + if (!(child = child.getArgAsNestedDag(0))) |
| 1540 | + return; |
| 1541 | + } |
| 1542 | + if (!child.isNativeCodeCall() && !child.isVariadic()) |
| 1543 | + PrintFatalError(loc, formatv("op expects variadic operand `{0}`, while " |
| 1544 | + "provided is non-variadic", |
| 1545 | + resultOp.getArgName(i))); |
| 1546 | + }; |
| 1547 | + |
1521 | 1548 | // First go through all the child nodes who are nested DAG constructs to
|
1522 | 1549 | // create ops for them and remember the symbol names for them, so that we can
|
1523 | 1550 | // use the results in the current node. This happens in a recursive manner.
|
1524 | 1551 | for (int i = 0, e = tree.getNumArgs() - tail.numDirectives; i != e; ++i) {
|
| 1552 | + checkIfMatchedVariadic(i); |
1525 | 1553 | if (auto child = tree.getArgAsNestedDag(i))
|
1526 | 1554 | childNodeNames[i] = handleResultPattern(child, i, depth + 1);
|
1527 | 1555 | }
|
|
0 commit comments