[llvm] [LLVM][TableGen] Support type casts of nodes with multiple results (PR #109728)

Stephen Chou via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 25 22:51:00 PDT 2024


================
@@ -2896,6 +2896,35 @@ TreePatternNodePtr TreePattern::ParseTreePattern(Init *TheInit,
     error("Pattern has unexpected init kind!");
     return nullptr;
   }
+
+  auto ParseCastOperand = [this](DagInit *Dag, StringRef OpName) {
+    if (Dag->getNumArgs() != 1)
+      error("Type cast only takes one operand!");
+
+    if (!OpName.empty())
+      error("Type cast should not have a name!");
+
+    return ParseTreePattern(Dag->getArg(0), Dag->getArgNameStr(0));
+  };
+
+  if (ListInit *LI = dyn_cast<ListInit>(Dag->getOperator())) {
+    // If the operator is a list (of value types), then this must be "type cast"
+    // of a leaf node with multiple results.
+    TreePatternNodePtr New = ParseCastOperand(Dag, OpName);
+
+    unsigned NumTypes = New->getNumTypes();
+    if (NumTypes != LI->size())
+      error("Invalid number of type casts!");
----------------
stephenchouca wrote:

Done.

https://github.com/llvm/llvm-project/pull/109728


More information about the llvm-commits mailing list