[llvm-commits] CVS: llvm/utils/TableGen/DAGISelEmitter.cpp DAGISelEmitter.h

Chris Lattner lattner at cs.uiuc.edu
Tue Sep 13 17:09:35 PDT 2005



Changes in directory llvm/utils/TableGen:

DAGISelEmitter.cpp updated: 1.14 -> 1.15
DAGISelEmitter.h updated: 1.11 -> 1.12
---
Log message:

start parsing instructions into patterns, start doing many more checks of
'set's.


---
Diffs of the changes:  (+61 -4)

 DAGISelEmitter.cpp |   60 +++++++++++++++++++++++++++++++++++++++++++++++++----
 DAGISelEmitter.h   |    5 ++++
 2 files changed, 61 insertions(+), 4 deletions(-)


Index: llvm/utils/TableGen/DAGISelEmitter.cpp
diff -u llvm/utils/TableGen/DAGISelEmitter.cpp:1.14 llvm/utils/TableGen/DAGISelEmitter.cpp:1.15
--- llvm/utils/TableGen/DAGISelEmitter.cpp:1.14	Tue Sep 13 17:05:02 2005
+++ llvm/utils/TableGen/DAGISelEmitter.cpp	Tue Sep 13 19:09:24 2005
@@ -654,17 +654,66 @@
       I->error("Could not infer all types in pattern!");
     }
     
-    // Verify that the top-level forms in the instruction are of void type.
-    for (unsigned j = 0, e = I->getNumTrees(); j != e; ++j)
-      if (I->getTree(j)->getType() != MVT::isVoid) {
+    // Verify that the top-level forms in the instruction are of void type, and
+    // figure out how many of the instruction operands are destinations.
+    for (unsigned j = 0, e = I->getNumTrees(); j != e; ++j) {
+      TreePatternNode *Pat = I->getTree(j);
+      if (Pat->getType() != MVT::isVoid) {
         I->dump();
         I->error("Top-level forms in instruction pattern should have"
                  " void types");
       }
-
+     
+      // Investigate sets.
+      if (Pat->getOperator()->getName() == "set") {
+        if (Pat->getNumChildren() == 0)
+          I->error("set requires operands!");
+        else if (Pat->getNumChildren() & 1)
+          I->error("set requires an even number of operands");
+        
+        // Check the set destinations.
+        unsigned NumValues = Pat->getNumChildren()/2;
+        for (unsigned i = 0; i != NumValues; ++i) {
+          TreePatternNode *Dest = Pat->getChild(i);
+          if (!Dest->isLeaf())
+            I->error("set destination should be a virtual register!");
+          
+          DefInit *Val = dynamic_cast<DefInit*>(Dest->getLeafValue());
+          if (!Val)
+            I->error("set destination should be a virtual register!");
+          
+          if (!Val->getDef()->isSubClassOf("RegisterClass"))
+            I->error("set destination should be a virtual register!");
+        }
+      }
+    }
+              
     DEBUG(I->dump());
     Instructions.push_back(I);
   }
+   
+  // If we can, convert the instructions to be a patterns that are matched!
+  for (unsigned i = 0, e = Instructions.size(); i != e; ++i) {
+    TreePattern *I = Instructions[i];
+    
+    if (I->getNumTrees() != 1) {
+      std::cerr << "CANNOT HANDLE: " << I->getRecord()->getName() << " yet!";
+      continue;
+    }
+    TreePatternNode *Pattern = I->getTree(0);
+    if (Pattern->getOperator()->getName() != "set")
+      continue;  // Not a set (store or something?)
+    
+    if (Pattern->getNumChildren() != 2)
+      continue;  // Not a set of a single value (not handled so far)
+    
+    TreePatternNode *SrcPattern = Pattern->getChild(1)->clone();
+    TreePatternNode *DstPattern = SrcPattern->clone();  // FIXME: WRONG
+    PatternsToMatch.push_back(std::make_pair(SrcPattern, DstPattern));
+    DEBUG(std::cerr << "PATTERN TO MATCH: "; SrcPattern->dump();
+          std::cerr << "\nRESULT DAG      : ";
+          DstPattern->dump(); std::cerr << "\n");
+  }
 }
 
 void DAGISelEmitter::EmitInstructionSelector(std::ostream &OS) {
@@ -697,6 +746,9 @@
   EmitSourceFileHeader("DAG Instruction Selector for the " + Target.getName() +
                        " target", OS);
   
+  OS << "// *** NOTE: This file is #included into the middle of the target\n"
+     << "// *** instruction selector class.  These functions are really "
+     << "methods.\n\n";
   ParseNodeInfo();
   ParseNodeTransforms(OS);
   ParseAndResolvePatternFragments(OS);


Index: llvm/utils/TableGen/DAGISelEmitter.h
diff -u llvm/utils/TableGen/DAGISelEmitter.h:1.11 llvm/utils/TableGen/DAGISelEmitter.h:1.12
--- llvm/utils/TableGen/DAGISelEmitter.h:1.11	Tue Sep 13 16:59:15 2005
+++ llvm/utils/TableGen/DAGISelEmitter.h	Tue Sep 13 19:09:24 2005
@@ -286,6 +286,11 @@
   std::map<Record*, std::pair<Record*, std::string> > SDNodeXForms;
   std::map<Record*, TreePattern*> PatternFragments;
   std::vector<TreePattern*> Instructions;
+  
+  /// PatternsToMatch - All of the things we are matching on the DAG.  The first
+  /// value is the pattern to match, the second pattern is the result to
+  /// emit.
+  std::vector<std::pair<TreePatternNode*, TreePatternNode*> > PatternsToMatch;
 public:
   DAGISelEmitter(RecordKeeper &R) : Records(R) {}
 






More information about the llvm-commits mailing list