put instructions into a map instead of a vector for quick lookup
authorChris Lattner <sabre@nondot.org>
Thu, 15 Sep 2005 21:57:35 +0000 (21:57 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 15 Sep 2005 21:57:35 +0000 (21:57 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23368 91177308-0d34-0410-b5e6-96231b3b80d8

utils/TableGen/DAGISelEmitter.cpp
utils/TableGen/DAGISelEmitter.h

index dcdbb1cb6ad2dfec834b378fc0442f2d7b7e7db6..e5a436bb133de64cfc7954c9f035478aa9455ba6 100644 (file)
@@ -326,6 +326,10 @@ bool TreePatternNode::ApplyTypeConstraints(TreePattern &TP) {
     return MadeChange;  
   } else {
     assert(getOperator()->isSubClassOf("Instruction") && "Unknown node type!");
+    
+    const DAGInstruction &Inst =
+      TP.getDAGISelEmitter().getInstruction(getOperator());
+    
     // TODO: type inference for instructions.
     return false;
   }
@@ -874,13 +878,15 @@ void DAGISelEmitter::ParseInstructions() {
       new TreePatternNode(I->getRecord(), ResultNodeOperands);
     
     DEBUG(I->dump());
-    Instructions.push_back(DAGInstruction(I, ResultTypes, OperandTypes,
-                                          ResultPattern));
+    Instructions.insert(std::make_pair(I->getRecord(),
+                                       DAGInstruction(I, ResultTypes,
+                                                OperandTypes, ResultPattern)));
   }
    
   // If we can, convert the instructions to be patterns that are matched!
-  for (unsigned i = 0, e = Instructions.size(); i != e; ++i) {
-    TreePattern *I = Instructions[i].getPattern();
+  for (std::map<Record*, DAGInstruction>::iterator II = Instructions.begin(),
+       E = Instructions.end(); II != E; ++II) {
+    TreePattern *I = II->second.getPattern();
     
     if (I->getNumTrees() != 1) {
       std::cerr << "CANNOT HANDLE: " << I->getRecord()->getName() << " yet!";
@@ -894,7 +900,7 @@ void DAGISelEmitter::ParseInstructions() {
       continue;  // Not a set of a single value (not handled so far)
     
     TreePatternNode *SrcPattern = Pattern->getChild(1)->clone();
-    TreePatternNode *DstPattern = Instructions[i].getResultPattern();
+    TreePatternNode *DstPattern = II->second.getResultPattern();
     PatternsToMatch.push_back(std::make_pair(SrcPattern, DstPattern));
   }
 }
@@ -931,7 +937,7 @@ void DAGISelEmitter::ParsePatterns() {
     // never do anything with this pattern: report it to the user.
 #if 0  // FIXME: ENABLE when we can infer though instructions!
     if (!Result->InferAllTypes())
-      Result->error("Could not infer all types in pattern!");
+      Result->error("Could not infer all types in pattern result!");
 #endif
    
     if (Result->getNumTrees() != 1)
index a8726d9b8dc30b9d1302c0dea13b16d2f4598e96..bd1018b5312bdc12ed794eee103791bbe0e9fb1b 100644 (file)
@@ -317,7 +317,7 @@ class DAGISelEmitter : public TableGenBackend {
   std::map<Record*, SDNodeInfo> SDNodes;
   std::map<Record*, std::pair<Record*, std::string> > SDNodeXForms;
   std::map<Record*, TreePattern*> PatternFragments;
-  std::vector<DAGInstruction> Instructions;
+  std::map<Record*, DAGInstruction> 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
@@ -344,6 +344,11 @@ public:
     return SDNodeXForms.find(R)->second;
   }
   
+  const DAGInstruction &getInstruction(Record *R) const {
+    assert(Instructions.count(R) && "Unknown instruction!");
+    return Instructions.find(R)->second;
+  }
+  
 private:
   void ParseNodeInfo();
   void ParseNodeTransforms(std::ostream &OS);