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

Chris Lattner sabre at nondot.org
Mon Feb 22 22:55:24 PST 2010


Author: lattner
Date: Tue Feb 23 00:55:24 2010
New Revision: 96900

URL: http://llvm.org/viewvc/llvm-project?rev=96900&view=rev
Log:
reject patterns that have dead named arguments in the input pattern
this is tidier and can find bugs.

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=96900&r1=96899&r2=96900&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp (original)
+++ llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp Tue Feb 23 00:55:24 2010
@@ -2087,10 +2087,20 @@
   }
 }
 
+
+typedef std::pair<const TreePatternNode*, unsigned> NameRecord;
+
 static void FindNames(const TreePatternNode *P, 
-                      std::map<std::string, const TreePatternNode*> &Names) {
-  if (!P->getName().empty())
-    Names[P->getName()] = P;
+                      std::map<std::string, NameRecord> &Names) {
+  if (!P->getName().empty()) {
+    NameRecord &Rec = Names[P->getName()];
+    // If this is the first instance of the name, remember the node.
+    if (Rec.second++ == 0)
+      Rec.first = P;
+//    else
+//      assert(Rec.first->getExtTypes() == P->getExtTypes() &&
+//             "Type mismatch on name repetition");
+  }
   
   if (!P->isLeaf()) {
     for (unsigned i = 0, e = P->getNumChildren(); i != e; ++i)
@@ -2107,18 +2117,25 @@
   
   // 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;
+  std::map<std::string, NameRecord> 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
+  for (std::map<std::string, NameRecord>::iterator
          I = DstNames.begin(), E = DstNames.end(); I != E; ++I)
-    if (SrcNames[I->first] == 0)
+    if (SrcNames[I->first].first == 0)
       Pattern->error("Pattern has input without matching name in output: $" +
                      I->first);
-
+  
+  // Scan all of the named values in the source pattern, rejecting them if the
+  // name isn't used in the dest, and isn't used to tie two values together.
+  for (std::map<std::string, NameRecord>::iterator
+       I = SrcNames.begin(), E = SrcNames.end(); I != E; ++I)
+    if (DstNames[I->first].first == 0 && SrcNames[I->first].second == 1)
+      Pattern->error("Pattern has dead named input: $" + I->first);
+  
   PatternsToMatch.push_back(PTM);
 }
 





More information about the llvm-commits mailing list