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

Chris Lattner lattner at cs.uiuc.edu
Tue Jul 18 10:32:40 PDT 2006



Changes in directory llvm/utils/TableGen:

AsmWriterEmitter.cpp updated: 1.31 -> 1.32
---
Log message:

Merge operand info and asmstr idx into a single 32-bit field.  No other change.


---
Diffs of the changes:  (+18 -16)

 AsmWriterEmitter.cpp |   34 ++++++++++++++++++----------------
 1 files changed, 18 insertions(+), 16 deletions(-)


Index: llvm/utils/TableGen/AsmWriterEmitter.cpp
diff -u llvm/utils/TableGen/AsmWriterEmitter.cpp:1.31 llvm/utils/TableGen/AsmWriterEmitter.cpp:1.32
--- llvm/utils/TableGen/AsmWriterEmitter.cpp:1.31	Tue Jul 18 12:18:03 2006
+++ llvm/utils/TableGen/AsmWriterEmitter.cpp	Tue Jul 18 12:32:27 2006
@@ -423,10 +423,11 @@
   std::string AggregateString;
   AggregateString += '\0';
   
-  /// OpcodeInfo - The first value in the pair is the index into the string, the
-  /// second is an index used for operand printing information.
-  std::vector<std::pair<unsigned short, unsigned short> > OpcodeInfo;
+  /// OpcodeInfo - Theis encodes the index of the string to use for the first
+  /// chunk of the output as well as indices used for operand printing.
+  std::vector<unsigned> OpcodeInfo;
   
+  unsigned MaxStringIdx = 0;
   for (unsigned i = 0, e = NumberedInstructions.size(); i != e; ++i) {
     AsmWriterInst *AWI = CGIAWIMap[NumberedInstructions[i]];
     unsigned Idx;
@@ -437,21 +438,23 @@
       unsigned &Entry = StringOffset[AWI->Operands[0].Str];
       if (Entry == 0) {
         // Add the string to the aggregate if this is the first time found.
-        Entry = AggregateString.size();
+        MaxStringIdx = Entry = AggregateString.size();
         std::string Str = AWI->Operands[0].Str;
         UnescapeString(Str);
         AggregateString += Str;
         AggregateString += '\0';
       }
       Idx = Entry;
-      assert(Entry < 65536 && "Must not use unsigned short for table idx!");
 
       // Nuke the string from the operand list.  It is now handled!
       AWI->Operands.erase(AWI->Operands.begin());
     }
-    OpcodeInfo.push_back(std::pair<unsigned short, unsigned short>(Idx,0));
+    OpcodeInfo.push_back(Idx);
   }
   
+  // Figure out how many bits we used for the string index.
+  unsigned AsmStrBits = Log2_32_Ceil(MaxStringIdx);
+  
   // To reduce code size, we compactify common instructions into a few bits
   // in the opcode-indexed table.
   // 16 bits to play with.
@@ -489,20 +492,20 @@
     // Otherwise, we can include this in the initial lookup table.  Add it in.
     BitsLeft -= NumBits;
     for (unsigned i = 0, e = InstIdxs.size(); i != e; ++i)
-      OpcodeInfo[i].second |= InstIdxs[i] << BitsLeft;
+      OpcodeInfo[i] |= InstIdxs[i] << (BitsLeft+AsmStrBits);
     
     TableDrivenOperandPrinters.push_back(UniqueOperandCommands);
   }
   
   
   
-  O<<"  static const struct { unsigned short StrIdx, Bits; } OpInfo[] = {\n";
+  O<<"  static const unsigned OpInfo[] = {\n";
   for (unsigned i = 0, e = NumberedInstructions.size(); i != e; ++i) {
-    O << "    { " << OpcodeInfo[i].first << ", " << OpcodeInfo[i].second
-      << " },\t// " << NumberedInstructions[i]->TheDef->getName() << "\n";
+    O << "    " << OpcodeInfo[i] << ",\t// "
+      << NumberedInstructions[i]->TheDef->getName() << "\n";
   }
   // Add a dummy entry so the array init doesn't end with a comma.
-  O << "    { 65535, 65535 }\n";
+  O << "    0U\n";
   O << "  };\n\n";
   
   // Emit the string itself.
@@ -541,11 +544,10 @@
     << "  }\n\n";
   
   O << "  // Emit the opcode for the instruction.\n"
-    << "  O << AsmStrs+OpInfo[MI->getOpcode()].StrIdx;\n\n";
+    << "  unsigned Bits = OpInfo[MI->getOpcode()];\n"
+    << "  O << AsmStrs+(Bits & " << (1 << AsmStrBits)-1 << ");\n\n";
 
   // Output the table driven operand information.
-  O << "  unsigned short Bits = OpInfo[MI->getOpcode()].Bits;\n";
-
   BitsLeft = 16;
   for (unsigned i = 0, e = TableDrivenOperandPrinters.size(); i != e; ++i) {
     std::vector<std::string> &Commands = TableDrivenOperandPrinters[i];
@@ -560,8 +562,8 @@
     
     O << "\n  // Fragment " << i << " encoded into " << NumBits
       << " bits for " << Commands.size() << " unique commands.\n"
-      << "  switch ((Bits >> " << BitsLeft << ") & " << ((1 << NumBits)-1)
-      << ") {\n"
+      << "  switch ((Bits >> " << (BitsLeft+AsmStrBits) << ") & "
+      << ((1 << NumBits)-1) << ") {\n"
       << "  default:   // unreachable.\n";
     
     // Print out all the cases.






More information about the llvm-commits mailing list