From 636bef1f35eb7ca4c605d57aa6b8fbe9ff8207a8 Mon Sep 17 00:00:00 2001 From: Evan Cheng Date: Wed, 29 Jul 2009 05:06:11 +0000 Subject: [PATCH] Revert AsmWriterEmitter.cpp to 74742. The recent changes are causing serious compile time regression. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77431 91177308-0d34-0410-b5e6-96231b3b80d8 --- utils/TableGen/AsmWriterEmitter.cpp | 234 +++------------------------- 1 file changed, 21 insertions(+), 213 deletions(-) diff --git a/utils/TableGen/AsmWriterEmitter.cpp b/utils/TableGen/AsmWriterEmitter.cpp index 069578056c4..f34feef0c28 100644 --- a/utils/TableGen/AsmWriterEmitter.cpp +++ b/utils/TableGen/AsmWriterEmitter.cpp @@ -19,7 +19,6 @@ #include "llvm/Support/Debug.h" #include "llvm/Support/MathExtras.h" #include -#include #include using namespace llvm; @@ -33,11 +32,7 @@ static bool isIdentChar(char C) { // 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 @@ namespace llvm { 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 @@ namespace llvm { std::vector 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 @@ std::string AsmWriterOperand::getCode() const { 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 @@ std::string AsmWriterOperand::getCode() const { /// 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 @@ AsmWriterInst::AsmWriterInst(const CodeGenInstruction &CGI, unsigned Variant) 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 @@ AsmWriterInst::AsmWriterInst(const CodeGenInstruction &CGI, unsigned Variant) 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 @@ AsmWriterInst::AsmWriterInst(const CodeGenInstruction &CGI, unsigned Variant) 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 @@ AsmWriterInst::AsmWriterInst(const CodeGenInstruction &CGI, unsigned Variant) } } - Operands.push_back( - AsmWriterOperand("EmitComments(*MI);\n", - AsmWriterOperand::isLiteralStatementOperand)); AddLiteralString("\\n"); } @@ -516,6 +357,7 @@ static void EmitInstructions(std::vector &Insts, } O << "\n"; } + O << " break;\n"; } @@ -543,9 +385,8 @@ FindUniqueOperandCommands(std::vector &UniqueOperandCommands, 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 @@ FindUniqueOperandCommands(std::vector &UniqueOperandCommands, // 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 @@ FindUniqueOperandCommands(std::vector &UniqueOperandCommands, // 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 @@ FindUniqueOperandCommands(std::vector &UniqueOperandCommands, 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 @@ void AsmWriterEmitter::run(raw_ostream &O) { UniqueOperandCommands.push_back(" return true;\n"); isFirst = false; } - + std::vector InstIdxs; std::vector NumInstOpsHandled; FindUniqueOperandCommands(UniqueOperandCommands, InstIdxs, @@ -846,28 +675,8 @@ void AsmWriterEmitter::run(raw_ostream &O) { 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 @@ void AsmWriterEmitter::run(raw_ostream &O) { O << " }\n"; O << " return true;\n"; } - - O << " return true;\n"; + O << "}\n"; } -- 2.34.1