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

Chris Lattner lattner at cs.uiuc.edu
Tue Jul 18 10:56:20 PDT 2006



Changes in directory llvm/utils/TableGen:

AsmWriterEmitter.cpp updated: 1.35 -> 1.36
AsmWriterEmitter.h updated: 1.3 -> 1.4
---
Log message:

Change generator to remove operands as it processes them.  No change in 
generated file.


---
Diffs of the changes:  (+22 -17)

 AsmWriterEmitter.cpp |   36 +++++++++++++++++++++---------------
 AsmWriterEmitter.h   |    3 +--
 2 files changed, 22 insertions(+), 17 deletions(-)


Index: llvm/utils/TableGen/AsmWriterEmitter.cpp
diff -u llvm/utils/TableGen/AsmWriterEmitter.cpp:1.35 llvm/utils/TableGen/AsmWriterEmitter.cpp:1.36
--- llvm/utils/TableGen/AsmWriterEmitter.cpp:1.35	Tue Jul 18 12:50:22 2006
+++ llvm/utils/TableGen/AsmWriterEmitter.cpp	Tue Jul 18 12:56:07 2006
@@ -330,7 +330,7 @@
 
 void AsmWriterEmitter::
 FindUniqueOperandCommands(std::vector<std::string> &UniqueOperandCommands, 
-                          std::vector<unsigned> &InstIdxs, unsigned Op) const {
+                          std::vector<unsigned> &InstIdxs) const {
   InstIdxs.clear();
   InstIdxs.resize(NumberedInstructions.size());
   
@@ -345,13 +345,13 @@
     if (Inst == 0) continue;  // PHI, INLINEASM, etc.
     
     std::string Command;
-    if (Op >= Inst->Operands.size())
+    if (Inst->Operands.empty())
       continue;   // Instruction already done.
 
-    Command = "    " + Inst->Operands[Op].getCode() + "\n";
+    Command = "    " + Inst->Operands[0].getCode() + "\n";
 
     // If this is the last operand, emit a return.
-    if (Op == Inst->Operands.size()-1)
+    if (Inst->Operands.size() == 1)
       Command += "    return true;\n";
     
     // Check to see if we already have 'Command' in UniqueOperandCommands.
@@ -463,16 +463,19 @@
 
   std::vector<std::vector<std::string> > TableDrivenOperandPrinters;
   
-  for (unsigned i = 0; ; ++i) {
+  bool isFirst = true;
+  while (1) {
     std::vector<std::string> UniqueOperandCommands;
 
     // For the first operand check, add a default value that unhandled
     // instructions will use.
-    if (i == 0)
+    if (isFirst) {
       UniqueOperandCommands.push_back("    return false;\n");
+      isFirst = false;
+    }
     
     std::vector<unsigned> InstIdxs;
-    FindUniqueOperandCommands(UniqueOperandCommands, InstIdxs, i);
+    FindUniqueOperandCommands(UniqueOperandCommands, InstIdxs);
     
     // If we ran out of operands to print, we're done.
     if (UniqueOperandCommands.empty()) break;
@@ -495,6 +498,14 @@
     for (unsigned i = 0, e = InstIdxs.size(); i != e; ++i)
       OpcodeInfo[i] |= InstIdxs[i] << (BitsLeft+AsmStrBits);
     
+    // Remove the info about this operand.
+    for (unsigned i = 0, e = NumberedInstructions.size(); i != e; ++i) {
+      if (AsmWriterInst *Inst = getAsmWriterInstByID(i))
+        if (!Inst->Operands.empty())
+          Inst->Operands.erase(Inst->Operands.begin());
+    }
+    
+    // Remember the handlers for this set of operands.
     TableDrivenOperandPrinters.push_back(UniqueOperandCommands);
   }
   
@@ -590,18 +601,13 @@
     }
   }
   
-  // Okay, go through and strip out the operand information that we just
-  // emitted.
-  unsigned NumOpsToRemove = TableDrivenOperandPrinters.size();
+  // Okay, delete instructions with no operand info left.
   for (unsigned i = 0, e = Instructions.size(); i != e; ++i) {
     // Entire instruction has been emitted?
     AsmWriterInst &Inst = Instructions[i];
-    if (Inst.Operands.size() <= NumOpsToRemove) {
+    if (Inst.Operands.empty()) {
       Instructions.erase(Instructions.begin()+i);
-      --i; --e;      
-    } else {
-      Inst.Operands.erase(Inst.Operands.begin(),
-                          Inst.Operands.begin()+NumOpsToRemove);
+      --i; --e;
     }
   }
 


Index: llvm/utils/TableGen/AsmWriterEmitter.h
diff -u llvm/utils/TableGen/AsmWriterEmitter.h:1.3 llvm/utils/TableGen/AsmWriterEmitter.h:1.4
--- llvm/utils/TableGen/AsmWriterEmitter.h:1.3	Tue Jul 18 12:18:03 2006
+++ llvm/utils/TableGen/AsmWriterEmitter.h	Tue Jul 18 12:56:07 2006
@@ -43,8 +43,7 @@
       return I->second;
     }
     void FindUniqueOperandCommands(std::vector<std::string> &UOC,
-                                   std::vector<unsigned> &InstIdxs, 
-                                   unsigned Op) const;
+                                   std::vector<unsigned> &InstIdxs) const;
   };
 }
 #endif






More information about the llvm-commits mailing list