[llvm-commits] [llvm] r96898 - /llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp

Chris Lattner sabre at nondot.org
Mon Feb 22 22:35:46 PST 2010


Author: lattner
Date: Tue Feb 23 00:35:45 2010
New Revision: 96898

URL: http://llvm.org/viewvc/llvm-project?rev=96898&view=rev
Log:
reject patterns that mention a name in the destination pattern
but not in the input.  Previously, this would trigger an abort
late in the isel logic.

Modified:
    llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp

Modified: llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp?rev=96898&r1=96897&r2=96898&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp (original)
+++ llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp Tue Feb 23 00:35:45 2010
@@ -2078,21 +2078,47 @@
     }
     
     Record *Instr = II->first;
-    TreePatternNode *DstPattern = TheInst.getResultPattern();
     AddPatternToMatch(I,
                       PatternToMatch(Instr->getValueAsListInit("Predicates"),
-                                     SrcPattern, DstPattern,
+                                     SrcPattern,
+                                     TheInst.getResultPattern(),
                                      TheInst.getImpResults(),
                                      Instr->getValueAsInt("AddedComplexity")));
   }
 }
 
+static void FindNames(const TreePatternNode *P, 
+                      std::map<std::string, const TreePatternNode*> &Names) {
+  if (!P->getName().empty())
+    Names[P->getName()] = P;
+  
+  if (!P->isLeaf()) {
+    for (unsigned i = 0, e = P->getNumChildren(); i != e; ++i)
+      FindNames(P->getChild(i), Names);
+  }
+}
+
 void CodeGenDAGPatterns::AddPatternToMatch(const TreePattern *Pattern,
                                            const PatternToMatch &PTM) {
+  // Do some sanity checking on the pattern we're about to match.
   std::string Reason;
   if (!PTM.getSrcPattern()->canPatternMatch(Reason, *this))
-    Pattern->error("Instruction can never match: " + Reason);
+    Pattern->error("Pattern can never match: " + Reason);
   
+  // Find all of the named values in the input and output, ensure they have the
+  // same type.
+  std::map<std::string, const TreePatternNode*> SrcNames, DstNames;
+  FindNames(PTM.getSrcPattern(), SrcNames);
+  FindNames(PTM.getDstPattern(), DstNames);
+
+  // Scan all of the named values in the destination pattern, rejecting them if
+  // they don't exist in the input pattern.
+  for (std::map<std::string, const TreePatternNode*>::iterator
+         I = DstNames.begin(), E = DstNames.end(); I != E; ++I)
+    if (SrcNames[I->first] == 0)
+      Pattern->error("Pattern has input without matching name in output: $" +
+                     I->first);
+
   PatternsToMatch.push_back(PTM);
 }
 





More information about the llvm-commits mailing list