[llvm] [TableGen][GISel] Learn to import patterns with optional defs (PR #120470)

Sergey Barannikov via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 20 17:22:09 PST 2024


================
@@ -1469,6 +1465,22 @@ Expected<action_iterator> GlobalISelEmitter::importExplicitDefRenderers(
       continue;
     }
 
+    // A discarded explicit def may be an optional physical register.
+    // If this is the case, add the default register and mark it as dead.
+    if (OpInfo.Rec->isSubClassOf("OptionalDefOperand")) {
+      for (const TreePatternNode &DefaultOp :
+           make_pointee_range(CGP.getDefaultOperand(OpInfo.Rec).DefaultOps)) {
+        const Record *Reg = cast<DefInit>(DefaultOp.getLeafValue())->getDef();
+
+        if (!Reg->isSubClassOf("Register") && Reg->getName() != "zero_reg")
+          return failedImport("optional def is not a register");
----------------
s-barannikov wrote:

Added a few negative tests.


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


More information about the llvm-commits mailing list