[llvm-commits] [llvm] r77431 - /llvm/trunk/utils/TableGen/AsmWriterEmitter.cpp

Evan Cheng evan.cheng at apple.com
Tue Jul 28 22:06:12 PDT 2009


Author: evancheng
Date: Wed Jul 29 00:06:11 2009
New Revision: 77431

URL: http://llvm.org/viewvc/llvm-project?rev=77431&view=rev
Log:
Revert AsmWriterEmitter.cpp to 74742. The recent changes are causing serious compile time regression.

Modified:
    llvm/trunk/utils/TableGen/AsmWriterEmitter.cpp

Modified: llvm/trunk/utils/TableGen/AsmWriterEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/AsmWriterEmitter.cpp?rev=77431&r1=77430&r2=77431&view=diff

==============================================================================
--- llvm/trunk/utils/TableGen/AsmWriterEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/AsmWriterEmitter.cpp Wed Jul 29 00:06:11 2009
@@ -19,7 +19,6 @@
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/MathExtras.h"
 #include <algorithm>
-#include <sstream>
 #include <iostream>
 using namespace llvm;
 
@@ -33,11 +32,7 @@
 // This should be an anon namespace, this works around a GCC warning.
 namespace llvm {  
   struct AsmWriterOperand {
-    enum OpType {
-      isLiteralTextOperand, 
-      isMachineInstrOperand,
-      isLiteralStatementOperand
-    } OperandType;
+    enum { isLiteralTextOperand, isMachineInstrOperand } OperandType;
 
     /// Str - For isLiteralTextOperand, this IS the literal text.  For
     /// isMachineInstrOperand, this is the PrinterMethodName for the operand.
@@ -52,16 +47,14 @@
     std::string MiModifier;
 
     // To make VS STL happy
-    AsmWriterOperand(OpType op = isLiteralTextOperand):OperandType(op) {}
+    AsmWriterOperand():OperandType(isLiteralTextOperand) {}
 
-    AsmWriterOperand(const std::string &LitStr,
-                     OpType op = isLiteralTextOperand)
-      : OperandType(op), Str(LitStr) {}
+    explicit AsmWriterOperand(const std::string &LitStr)
+      : OperandType(isLiteralTextOperand), Str(LitStr) {}
 
     AsmWriterOperand(const std::string &Printer, unsigned OpNo, 
-                     const std::string &Modifier,
-                     OpType op = isMachineInstrOperand) 
-      : OperandType(op), Str(Printer), MIOpNo(OpNo),
+                     const std::string &Modifier) 
+      : OperandType(isMachineInstrOperand), Str(Printer), MIOpNo(OpNo),
       MiModifier(Modifier) {}
 
     bool operator!=(const AsmWriterOperand &Other) const {
@@ -85,29 +78,6 @@
     std::vector<AsmWriterOperand> Operands;
     const CodeGenInstruction *CGI;
 
-    /// MAX_GROUP_NESTING_LEVEL - The maximum number of group nesting
-    /// levels we ever expect to see in an asm operand.
-    static const int MAX_GROUP_NESTING_LEVEL = 10;
-
-    /// GroupLevel - The level of nesting of the current operand
-    /// group, such as [reg + (reg + offset)].  -1 means we are not in
-    /// a group.
-    int GroupLevel;
-
-    /// GroupDelim - Remember the delimeter for a group operand.
-    char GroupDelim[MAX_GROUP_NESTING_LEVEL];
-
-    /// ReadingWhitespace - Tell whether we just read some whitespace.
-    bool ReadingWhitespace;
-
-    /// InGroup - Determine whether we are in the middle of an
-    /// operand group.
-    bool InGroup() const { return GroupLevel != -1; }
-
-    /// InWhitespace - Determine whether we are in the middle of
-    /// emitting whitespace.
-    bool InWhitespace() const { return ReadingWhitespace; }
-
     AsmWriterInst(const CodeGenInstruction &CGI, unsigned Variant);
 
     /// MatchesAllButOneOp - If this instruction is exactly identical to the
@@ -133,18 +103,6 @@
   if (OperandType == isLiteralTextOperand)
     return "O << \"" + Str + "\"; ";
 
-  if (OperandType == isLiteralStatementOperand) {
-    return Str;
-  }
-
-  if (OperandType == isLiteralStatementOperand) {
-    return Str;
-  }
-
-  if (OperandType == isLiteralStatementOperand) {
-    return Str;
-  }
-
   std::string Result = Str + "(MI";
   if (MIOpNo != ~0U)
     Result += ", " + utostr(MIOpNo);
@@ -157,8 +115,7 @@
 /// ParseAsmString - Parse the specified Instruction's AsmString into this
 /// AsmWriterInst.
 ///
-AsmWriterInst::AsmWriterInst(const CodeGenInstruction &CGI, unsigned Variant)
-    : GroupLevel(-1), ReadingWhitespace(false) {
+AsmWriterInst::AsmWriterInst(const CodeGenInstruction &CGI, unsigned Variant) {
   this->CGI = &CGI;
   unsigned CurVariant = ~0U;  // ~0 if we are outside a {.|.|.} region, other #.
 
@@ -173,92 +130,15 @@
     if (DollarPos == std::string::npos) DollarPos = AsmString.size();
 
     // Emit a constant string fragment.
-
-    // TODO: Recognize an operand separator to determine when to pad
-    // to the next operator.
     if (DollarPos != LastEmitted) {
       if (CurVariant == Variant || CurVariant == ~0U) {
         for (; LastEmitted != DollarPos; ++LastEmitted)
           switch (AsmString[LastEmitted]) {
-          case '\n':
-            assert(!InGroup() && "Missing matching group delimeter");
-            ReadingWhitespace = false;
-            AddLiteralString("\\n");
-            break;
-          case '\t': 
-            if (!InGroup()) {
-              ReadingWhitespace = true;
-            }
-            AddLiteralString("\\t"); 
-            break;
-          case '"':
-            if (InWhitespace() && !InGroup())
-              Operands.push_back(
-                AsmWriterOperand(
-                  "O.PadToColumn(TAI->getOperandColumn(OperandColumn++));\n",
-                  AsmWriterOperand::isLiteralStatementOperand));
-            ReadingWhitespace = false;
-            AddLiteralString("\\\"");
-            break;
-          case '\\':
-            if (InWhitespace() && !InGroup())
-              Operands.push_back(
-                AsmWriterOperand(
-                  "O.PadToColumn(TAI->getOperandColumn(OperandColumn++));\n",
-                  AsmWriterOperand::isLiteralStatementOperand));
-            ReadingWhitespace = false;
-            AddLiteralString("\\\\");
-            break;
-
-          case '(':  // Fallthrough
-          case '[':
-            if (InWhitespace() && !InGroup())
-              Operands.push_back(
-                AsmWriterOperand(
-                  "O.PadToColumn(TAI->getOperandColumn(OperandColumn++));\n",
-                  AsmWriterOperand::isLiteralStatementOperand));
-            ReadingWhitespace = false;
-
-            ++GroupLevel;
-            assert(GroupLevel < MAX_GROUP_NESTING_LEVEL
-                   && "Exceeded maximum operand group nesting level");
-            GroupDelim[GroupLevel] = AsmString[LastEmitted];
-            AddLiteralString(std::string(1, AsmString[LastEmitted]));
-            break;
-
-          case ')':  // Fallthrough
-          case ']':
-            if (InWhitespace() && !InGroup())
-              Operands.push_back(
-                AsmWriterOperand(
-                  "O.PadToColumn(TAI->getOperandColumn(OperandColumn++));\n",
-                  AsmWriterOperand::isLiteralStatementOperand));
-            ReadingWhitespace = false;
-
-            if (AsmString[LastEmitted] == ')')
-              assert(GroupDelim[GroupLevel] == '(' && "Mismatched delimeters");
-            else
-              assert(GroupDelim[GroupLevel] == '[' && "Mismatched delimeters");
-            
-            --GroupLevel;
-            assert(GroupLevel > -2 && "Too many end delimeters!");
-            AddLiteralString(std::string(1, AsmString[LastEmitted]));
-            break;
-            
+          case '\n': AddLiteralString("\\n"); break;
+          case '\t': AddLiteralString("\\t"); break;
+          case '"': AddLiteralString("\\\""); break;
+          case '\\': AddLiteralString("\\\\"); break;
           default:
-            if (AsmString[LastEmitted] != ' ' &&
-                AsmString[LastEmitted] != '\t') {
-              if (!InGroup() && InWhitespace())
-                Operands.push_back(
-                  AsmWriterOperand(
-                    "O.PadToColumn(TAI->getOperandColumn(OperandColumn++));\n",
-                    AsmWriterOperand::isLiteralStatementOperand));
-              ReadingWhitespace = false;
-            }
-            else 
-              if (!InGroup())
-                ReadingWhitespace = true;
-
             AddLiteralString(std::string(1, AsmString[LastEmitted]));
             break;
           }
@@ -269,33 +149,11 @@
       if (DollarPos+1 != AsmString.size() &&
           (CurVariant == Variant || CurVariant == ~0U)) {
         if (AsmString[DollarPos+1] == 'n') {
-          assert(!InGroup() && "Missing matching group delimeter");
-          ReadingWhitespace = false;
           AddLiteralString("\\n");
         } else if (AsmString[DollarPos+1] == 't') {
-          if (!InGroup()) {
-            ReadingWhitespace = true;
-          }
           AddLiteralString("\\t");
         } else if (std::string("${|}\\").find(AsmString[DollarPos+1]) 
                    != std::string::npos) {
-          if (InWhitespace() && !InGroup())
-            Operands.push_back(
-              AsmWriterOperand(
-                "O.PadToColumn(TAI->getOperandColumn(OperandColumn++));\n",
-                AsmWriterOperand::isLiteralStatementOperand));
-          ReadingWhitespace = false;
-
-          if (AsmString[DollarPos+1] == '{') {
-            ++GroupLevel;
-            assert(GroupLevel < MAX_GROUP_NESTING_LEVEL
-                   && "Exceeded maximum operand group nesting level");
-            GroupDelim[GroupLevel] = AsmString[DollarPos+1];
-          } else if (AsmString[DollarPos+1] == '}') {
-            assert(GroupDelim[GroupLevel] == '{' && "Mismatched delimeters");
-            --GroupLevel;
-            assert(GroupLevel > -2 && "Too many end delimeters!");
-          }
           AddLiteralString(std::string(1, AsmString[DollarPos+1]));
         } else {
           throw "Non-supported escaped character found in instruction '" +
@@ -324,27 +182,13 @@
       CurVariant = ~0U;
     } else if (DollarPos+1 != AsmString.size() &&
                AsmString[DollarPos+1] == '$') {
-      if (CurVariant == Variant || CurVariant == ~0U) {
-        if (InWhitespace() && !InGroup())
-          Operands.push_back(
-            AsmWriterOperand(
-              "O.PadToColumn(TAI->getOperandColumn(OperandColumn++));\n",
-              AsmWriterOperand::isLiteralStatementOperand));
-        ReadingWhitespace = false;
+      if (CurVariant == Variant || CurVariant == ~0U) 
         AddLiteralString("$");  // "$$" -> $
-      }
       LastEmitted = DollarPos+2;
     } else {
-      if (InWhitespace() && !InGroup())
-        Operands.push_back(
-          AsmWriterOperand(
-            "O.PadToColumn(TAI->getOperandColumn(OperandColumn++));\n",
-            AsmWriterOperand::isLiteralStatementOperand));
-      ReadingWhitespace = false;
-
       // Get the name of the variable.
       std::string::size_type VarEnd = DollarPos+1;
- 
+
       // handle ${foo}bar as $foo by detecting whether the character following
       // the dollar sign is a curly brace.  If so, advance VarEnd and DollarPos
       // so the variable name does not contain the leading curly brace.
@@ -416,9 +260,6 @@
     }
   }
 
-  Operands.push_back(
-    AsmWriterOperand("EmitComments(*MI);\n",
-                     AsmWriterOperand::isLiteralStatementOperand));
   AddLiteralString("\\n");
 }
 
@@ -516,6 +357,7 @@
     }
     O << "\n";
   }
+
   O << "    break;\n";
 }
 
@@ -543,9 +385,8 @@
     Command = "    " + Inst->Operands[0].getCode() + "\n";
 
     // If this is the last operand, emit a return.
-    if (Inst->Operands.size() == 1) {
+    if (Inst->Operands.size() == 1)
       Command += "    return true;\n";
-    }
     
     // Check to see if we already have 'Command' in UniqueOperandCommands.
     // If not, add it.
@@ -590,10 +431,7 @@
       // Otherwise, scan to see if all of the other instructions in this command
       // set share the operand.
       bool AllSame = true;
-      // Keep track of the maximum, number of operands or any
-      // instruction we see in the group.
-      size_t MaxSize = FirstInst->Operands.size();
-
+      
       for (NIT = std::find(NIT+1, InstIdxs.end(), CommandIdx);
            NIT != InstIdxs.end();
            NIT = std::find(NIT+1, InstIdxs.end(), CommandIdx)) {
@@ -601,11 +439,6 @@
         // matches, we're ok, otherwise bail out.
         const AsmWriterInst *OtherInst = 
           getAsmWriterInstByID(NIT-InstIdxs.begin());
-
-        if (OtherInst &&
-            OtherInst->Operands.size() > FirstInst->Operands.size())
-          MaxSize = std::max(MaxSize, OtherInst->Operands.size());
-
         if (!OtherInst || OtherInst->Operands.size() == Op ||
             OtherInst->Operands[Op] != FirstInst->Operands[Op]) {
           AllSame = false;
@@ -619,12 +452,8 @@
       std::string Command = "    " + FirstInst->Operands[Op].getCode() + "\n";
       
       // If this is the last operand, emit a return after the code.
-      if (FirstInst->Operands.size() == Op+1 &&
-          // Don't early-out too soon.  Other instructions in this
-          // group may have more operands.
-          FirstInst->Operands.size() == MaxSize) {
+      if (FirstInst->Operands.size() == Op+1)
         Command += "    return true;\n";
-      }
       
       UniqueOperandCommands[CommandIdx] += Command;
       InstOpsUsed[CommandIdx]++;
@@ -738,7 +567,7 @@
       UniqueOperandCommands.push_back("    return true;\n");
       isFirst = false;
     }
-
+    
     std::vector<unsigned> InstIdxs;
     std::vector<unsigned> NumInstOpsHandled;
     FindUniqueOperandCommands(UniqueOperandCommands, InstIdxs,
@@ -846,28 +675,8 @@
 
   O << "  // Emit the opcode for the instruction.\n"
     << "  unsigned Bits = OpInfo[MI->getOpcode()];\n"
-    << "  if (Bits == 0) return false;\n\n";
-  
-  O << "  unsigned OperandColumn = 1;\n\n"
-    << "  if (TAI->getOperandColumn(1) > 0) {\n"
-    << "    // Don't emit trailing whitespace, let the column padding do it.  This\n"
-    << "    // guarantees that a stray long opcode + tab won't upset the alignment.\n"
-    << "    unsigned OpLength = std::strlen(AsmStrs+(Bits & " << (1 << AsmStrBits)-1 << "));\n"
-    << "    if (OpLength > 0 &&\n"
-    << "        ((AsmStrs+(Bits & " << (1 << AsmStrBits)-1 << "))[OpLength-1] == ' ' ||\n"
-    << "         (AsmStrs+(Bits & " << (1 << AsmStrBits)-1 << "))[OpLength-1] == '\\t')) {\n"
-    << "      do {\n"
-    << "        --OpLength;\n"
-    << "      } while ((AsmStrs+(Bits & " << (1 << AsmStrBits)-1 << "))[OpLength-1] == ' ' ||\n"
-    << "               (AsmStrs+(Bits & " << (1 << AsmStrBits)-1 << "))[OpLength-1] == '\\t');\n"
-    << "      for (unsigned Idx = 0; Idx < OpLength; ++Idx)\n"
-    << "        O << (AsmStrs+(Bits & " << (1 << AsmStrBits)-1 << "))[Idx];\n"
-    << "      O.PadToColumn(TAI->getOperandColumn(OperandColumn++), 1);\n"
-    << "    }\n"
-    << "  } else {\n"
-    << "    O << AsmStrs+(Bits & " << (1 << AsmStrBits)-1 << ");\n"
-    << "  }\n\n";
-  
+    << "  if (Bits == 0) return false;\n"
+    << "  O << AsmStrs+(Bits & " << (1 << AsmStrBits)-1 << ");\n\n";
 
   // Output the table driven operand information.
   BitsLeft = 32-AsmStrBits;
@@ -932,7 +741,6 @@
     O << "  }\n";
     O << "  return true;\n";
   }
-
-  O << "  return true;\n";
+  
   O << "}\n";
 }





More information about the llvm-commits mailing list