Finish implementation of the type inference engine.
authorChris Lattner <sabre@nondot.org>
Thu, 7 Aug 2003 06:02:15 +0000 (06:02 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 7 Aug 2003 06:02:15 +0000 (06:02 +0000)
Start working on reading in nonterminals

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7671 91177308-0d34-0410-b5e6-96231b3b80d8

support/tools/TableGen/InstrSelectorEmitter.cpp
support/tools/TableGen/InstrSelectorEmitter.h
utils/TableGen/InstrSelectorEmitter.cpp
utils/TableGen/InstrSelectorEmitter.h

index a2bd08c7948c996ff9e734861aa42746769ad0b4..dbc1b66ffc1fb622be89c3f5a9bed6127db1ea2e 100644 (file)
@@ -82,11 +82,13 @@ static MVT::ValueType getIntrinsicType(Record *R) {
       return getValueType(R->getValueAsDef("RegType"));
     } else if (SuperClasses[i]->getName() == "Register") {
       std::cerr << "WARNING: Explicit registers not handled yet!\n";
+      return MVT::Other;
     } else if (SuperClasses[i]->getName() == "Nonterminal") {
+      //std::cerr << "Warning nonterminal type not handled yet:" << R->getName()
+      //          << "\n";
+      return MVT::Other;
     }
-  //throw "Error: Unknown value used: " + R->getName();
-
-  return MVT::Other;
+  throw "Error: Unknown value used: " + R->getName();
 }
 
 // Parse the specified DagInit into a TreePattern which we can use.
@@ -159,13 +161,15 @@ bool InstrSelectorEmitter::InferTypes(TreePatternNode *N,
 
     switch (NT.ArgTypes[i]) {
     case NodeType::Arg0:
-      MadeChange |=UpdateNodeType(Children[i], Children[0]->getType(), RecName);
+      MadeChange |= UpdateNodeType(Children[i], Children[0]->getType(),RecName);
       break;
     case NodeType::Val:
       if (Children[i]->getType() == MVT::isVoid)
         throw "In pattern for " + RecName + " should not get a void node!";
       break;
-    case NodeType::Ptr: // FIXME
+    case NodeType::Ptr:
+      MadeChange |= UpdateNodeType(Children[i],Target.getPointerType(),RecName);
+      break;
     default: assert(0 && "Invalid argument ArgType!");
     }
   }
@@ -179,8 +183,14 @@ bool InstrSelectorEmitter::InferTypes(TreePatternNode *N,
     MadeChange |= UpdateNodeType(N, Children[0]->getType(), RecName);
     break;
 
-  case NodeType::Ptr:   // FIXME: get from target
+  case NodeType::Ptr:
+    MadeChange |= UpdateNodeType(N, Target.getPointerType(), RecName);
+    break;
   case NodeType::Val:
+    if (N->getType() == MVT::isVoid)
+      throw "In pattern for " + RecName + " should not get a void node!";
+    break;
+  default:
     assert(0 && "Unhandled type constraint!");
     break;
   }
@@ -210,6 +220,19 @@ TreePatternNode *InstrSelectorEmitter::ReadAndCheckPattern(DagInit *DI,
   return Pattern;
 }
 
+// ProcessNonTerminals - Read in all nonterminals and incorporate them into
+// our pattern database.
+void InstrSelectorEmitter::ProcessNonTerminals() {
+  std::vector<Record*> NTs = Records.getAllDerivedDefinitions("Nonterminal");
+  for (unsigned i = 0, e = NTs.size(); i != e; ++i) {
+    DagInit *DI = NTs[i]->getValueAsDag("Pattern");
+
+    TreePatternNode *Pattern = ReadAndCheckPattern(DI, NTs[i]->getName());
+
+    DEBUG(std::cerr << "Parsed nonterm pattern " << NTs[i]->getName() << "\t= "
+          << *Pattern << "\n");
+  }
+}
 
 
 /// ProcessInstructionPatterns - Read in all subclasses of Instruction, and
@@ -222,7 +245,6 @@ void InstrSelectorEmitter::ProcessInstructionPatterns() {
     if (DagInit *DI = dynamic_cast<DagInit*>(Inst->getValueInit("Pattern"))) {
       TreePatternNode *Pattern = ReadAndCheckPattern(DI, Inst->getName());
 
-
       DEBUG(std::cerr << "Parsed inst pattern " << Inst->getName() << "\t= "
                       << *Pattern << "\n");
     }
@@ -235,6 +257,7 @@ void InstrSelectorEmitter::run(std::ostream &OS) {
   ProcessNodeTypes();
   
   // Read in all of the nonterminals...
+  //ProcessNonTerminals();
 
   // Read all of the instruction patterns in...
   ProcessInstructionPatterns();
index dc16fb20f4709d02cca6fa150f3a1176d214ba8a..108aeee20c6e0aba9430c947816b3d5d704ac61d 100644 (file)
@@ -9,7 +9,7 @@
 #define INSTRSELECTOR_EMITTER_H
 
 #include "TableGenBackend.h"
-#include "llvm/CodeGen/ValueTypes.h"
+#include "CodeGenWrappers.h"
 #include <vector>
 #include <map>
 class DagInit;
@@ -82,6 +82,7 @@ std::ostream &operator<<(std::ostream &OS, const TreePatternNode &N);
 
 class InstrSelectorEmitter : public TableGenBackend {
   RecordKeeper &Records;
+  CodeGenTarget Target;
 
   std::map<Record*, NodeType> NodeTypes;
 public:
@@ -96,6 +97,10 @@ private:
   // structure.
   void ProcessNodeTypes();
 
+  // ProcessNonTerminals - Read in all nonterminals and incorporate them into
+  // our pattern database.
+  void ProcessNonTerminals();
+
   // ProcessInstructionPatterns - Read in all subclasses of Instruction, and
   // process those with a useful Pattern field.
   void ProcessInstructionPatterns();
index a2bd08c7948c996ff9e734861aa42746769ad0b4..dbc1b66ffc1fb622be89c3f5a9bed6127db1ea2e 100644 (file)
@@ -82,11 +82,13 @@ static MVT::ValueType getIntrinsicType(Record *R) {
       return getValueType(R->getValueAsDef("RegType"));
     } else if (SuperClasses[i]->getName() == "Register") {
       std::cerr << "WARNING: Explicit registers not handled yet!\n";
+      return MVT::Other;
     } else if (SuperClasses[i]->getName() == "Nonterminal") {
+      //std::cerr << "Warning nonterminal type not handled yet:" << R->getName()
+      //          << "\n";
+      return MVT::Other;
     }
-  //throw "Error: Unknown value used: " + R->getName();
-
-  return MVT::Other;
+  throw "Error: Unknown value used: " + R->getName();
 }
 
 // Parse the specified DagInit into a TreePattern which we can use.
@@ -159,13 +161,15 @@ bool InstrSelectorEmitter::InferTypes(TreePatternNode *N,
 
     switch (NT.ArgTypes[i]) {
     case NodeType::Arg0:
-      MadeChange |=UpdateNodeType(Children[i], Children[0]->getType(), RecName);
+      MadeChange |= UpdateNodeType(Children[i], Children[0]->getType(),RecName);
       break;
     case NodeType::Val:
       if (Children[i]->getType() == MVT::isVoid)
         throw "In pattern for " + RecName + " should not get a void node!";
       break;
-    case NodeType::Ptr: // FIXME
+    case NodeType::Ptr:
+      MadeChange |= UpdateNodeType(Children[i],Target.getPointerType(),RecName);
+      break;
     default: assert(0 && "Invalid argument ArgType!");
     }
   }
@@ -179,8 +183,14 @@ bool InstrSelectorEmitter::InferTypes(TreePatternNode *N,
     MadeChange |= UpdateNodeType(N, Children[0]->getType(), RecName);
     break;
 
-  case NodeType::Ptr:   // FIXME: get from target
+  case NodeType::Ptr:
+    MadeChange |= UpdateNodeType(N, Target.getPointerType(), RecName);
+    break;
   case NodeType::Val:
+    if (N->getType() == MVT::isVoid)
+      throw "In pattern for " + RecName + " should not get a void node!";
+    break;
+  default:
     assert(0 && "Unhandled type constraint!");
     break;
   }
@@ -210,6 +220,19 @@ TreePatternNode *InstrSelectorEmitter::ReadAndCheckPattern(DagInit *DI,
   return Pattern;
 }
 
+// ProcessNonTerminals - Read in all nonterminals and incorporate them into
+// our pattern database.
+void InstrSelectorEmitter::ProcessNonTerminals() {
+  std::vector<Record*> NTs = Records.getAllDerivedDefinitions("Nonterminal");
+  for (unsigned i = 0, e = NTs.size(); i != e; ++i) {
+    DagInit *DI = NTs[i]->getValueAsDag("Pattern");
+
+    TreePatternNode *Pattern = ReadAndCheckPattern(DI, NTs[i]->getName());
+
+    DEBUG(std::cerr << "Parsed nonterm pattern " << NTs[i]->getName() << "\t= "
+          << *Pattern << "\n");
+  }
+}
 
 
 /// ProcessInstructionPatterns - Read in all subclasses of Instruction, and
@@ -222,7 +245,6 @@ void InstrSelectorEmitter::ProcessInstructionPatterns() {
     if (DagInit *DI = dynamic_cast<DagInit*>(Inst->getValueInit("Pattern"))) {
       TreePatternNode *Pattern = ReadAndCheckPattern(DI, Inst->getName());
 
-
       DEBUG(std::cerr << "Parsed inst pattern " << Inst->getName() << "\t= "
                       << *Pattern << "\n");
     }
@@ -235,6 +257,7 @@ void InstrSelectorEmitter::run(std::ostream &OS) {
   ProcessNodeTypes();
   
   // Read in all of the nonterminals...
+  //ProcessNonTerminals();
 
   // Read all of the instruction patterns in...
   ProcessInstructionPatterns();
index dc16fb20f4709d02cca6fa150f3a1176d214ba8a..108aeee20c6e0aba9430c947816b3d5d704ac61d 100644 (file)
@@ -9,7 +9,7 @@
 #define INSTRSELECTOR_EMITTER_H
 
 #include "TableGenBackend.h"
-#include "llvm/CodeGen/ValueTypes.h"
+#include "CodeGenWrappers.h"
 #include <vector>
 #include <map>
 class DagInit;
@@ -82,6 +82,7 @@ std::ostream &operator<<(std::ostream &OS, const TreePatternNode &N);
 
 class InstrSelectorEmitter : public TableGenBackend {
   RecordKeeper &Records;
+  CodeGenTarget Target;
 
   std::map<Record*, NodeType> NodeTypes;
 public:
@@ -96,6 +97,10 @@ private:
   // structure.
   void ProcessNodeTypes();
 
+  // ProcessNonTerminals - Read in all nonterminals and incorporate them into
+  // our pattern database.
+  void ProcessNonTerminals();
+
   // ProcessInstructionPatterns - Read in all subclasses of Instruction, and
   // process those with a useful Pattern field.
   void ProcessInstructionPatterns();