From 56f4fa247d89f4313197018c5bf5c958348d01ef Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Sat, 1 Jun 2019 06:20:55 +0000 Subject: [PATCH] [X86] Make the X86FoldTablesEmitter functional again. Fix the spacing in the output to make it easier to diff. Fix a few other formatting issues in the manual table. And remove some old FIXMEs. llvm-svn: 362287 --- lib/Target/X86/X86InstrFoldTables.cpp | 6 +-- utils/TableGen/X86FoldTablesEmitter.cpp | 61 +++++++++++++++---------- 2 files changed, 39 insertions(+), 28 deletions(-) diff --git a/lib/Target/X86/X86InstrFoldTables.cpp b/lib/Target/X86/X86InstrFoldTables.cpp index 59e62da55f2..7ab4dc4df7c 100644 --- a/lib/Target/X86/X86InstrFoldTables.cpp +++ b/lib/Target/X86/X86InstrFoldTables.cpp @@ -248,7 +248,7 @@ static const X86MemoryFoldTableEntry MemoryFoldTable2Addr[] = { { X86::XOR64rr, X86::XOR64mr, 0 }, { X86::XOR8ri, X86::XOR8mi, 0 }, { X86::XOR8ri8, X86::XOR8mi8, 0 }, - { X86::XOR8rr, X86::XOR8mr, 0 } + { X86::XOR8rr, X86::XOR8mr, 0 }, }; static const X86MemoryFoldTableEntry MemoryFoldTable0[] = { @@ -614,7 +614,6 @@ static const X86MemoryFoldTableEntry MemoryFoldTable1[] = { { X86::SQRTSSr, X86::SQRTSSm, 0 }, { X86::T1MSKC32rr, X86::T1MSKC32rm, 0 }, { X86::T1MSKC64rr, X86::T1MSKC64rm, 0 }, - // FIXME: TEST*rr EAX,EAX ---> CMP [mem], 0 { X86::TZCNT16rr, X86::TZCNT16rm, 0 }, { X86::TZCNT32rr, X86::TZCNT32rm, 0 }, { X86::TZCNT64rr, X86::TZCNT64rm, 0 }, @@ -649,7 +648,7 @@ static const X86MemoryFoldTableEntry MemoryFoldTable1[] = { { X86::VCOMISSrr_Int, X86::VCOMISSrm_Int, TB_NO_REVERSE }, { X86::VCVTDQ2PDYrr, X86::VCVTDQ2PDYrm, 0 }, { X86::VCVTDQ2PDZ128rr, X86::VCVTDQ2PDZ128rm, TB_NO_REVERSE }, - { X86::VCVTDQ2PDZ256rr, X86::VCVTDQ2PDZ256rm, 0 }, + { X86::VCVTDQ2PDZ256rr, X86::VCVTDQ2PDZ256rm, 0 }, { X86::VCVTDQ2PDZrr, X86::VCVTDQ2PDZrm, 0 }, { X86::VCVTDQ2PDrr, X86::VCVTDQ2PDrm, TB_NO_REVERSE }, { X86::VCVTDQ2PSYrr, X86::VCVTDQ2PSYrm, 0 }, @@ -1518,7 +1517,6 @@ static const X86MemoryFoldTableEntry MemoryFoldTable2[] = { { X86::SUBSDrr_Int, X86::SUBSDrm_Int, TB_NO_REVERSE }, { X86::SUBSSrr, X86::SUBSSrm, 0 }, { X86::SUBSSrr_Int, X86::SUBSSrm_Int, TB_NO_REVERSE }, - // FIXME: TEST*rr -> swapped operand of TEST *mr. { X86::UNPCKHPDrr, X86::UNPCKHPDrm, TB_ALIGN_16 }, { X86::UNPCKHPSrr, X86::UNPCKHPSrm, TB_ALIGN_16 }, { X86::UNPCKLPDrr, X86::UNPCKLPDrm, TB_ALIGN_16 }, diff --git a/utils/TableGen/X86FoldTablesEmitter.cpp b/utils/TableGen/X86FoldTablesEmitter.cpp index 0f646470f6a..2c15e35f234 100644 --- a/utils/TableGen/X86FoldTablesEmitter.cpp +++ b/utils/TableGen/X86FoldTablesEmitter.cpp @@ -13,6 +13,7 @@ #include "CodeGenTarget.h" #include "X86RecognizableInstr.h" +#include "llvm/Support/FormattedStream.h" #include "llvm/TableGen/Error.h" #include "llvm/TableGen/TableGenBackend.h" @@ -108,23 +109,23 @@ class X86FoldTablesEmitter { const CodeGenInstruction *MemInst) : RegInst(RegInst), MemInst(MemInst) {} - friend raw_ostream &operator<<(raw_ostream &OS, - const X86FoldTableEntry &E) { - OS << "{ X86::" << E.RegInst->TheDef->getName() - << ", X86::" << E.MemInst->TheDef->getName() << ", "; + void print(formatted_raw_ostream &OS) const { + OS.indent(2); + OS << "{ X86::" << RegInst->TheDef->getName() << ","; + OS.PadToColumn(40); + OS << "X86::" << MemInst->TheDef->getName() << ","; + OS.PadToColumn(75); - if (E.IsLoad) + if (IsLoad) OS << "TB_FOLDED_LOAD | "; - if (E.IsStore) + if (IsStore) OS << "TB_FOLDED_STORE | "; - if (E.CannotUnfold) + if (CannotUnfold) OS << "TB_NO_REVERSE | "; - if (E.IsAligned) - OS << "TB_ALIGN_" << E.Alignment << " | "; + if (IsAligned) + OS << "TB_ALIGN_" << Alignment << " | "; OS << "0 },\n"; - - return OS; } }; @@ -144,7 +145,7 @@ public: X86FoldTablesEmitter(RecordKeeper &R) : Records(R), Target(R) {} // run - Generate the 6 X86 memory fold tables. - void run(raw_ostream &OS); + void run(formatted_raw_ostream &OS); private: // Decides to which table to add the entry with the given instructions. @@ -162,21 +163,21 @@ private: // Print the given table as a static const C++ array of type // X86MemoryFoldTableEntry. void printTable(const FoldTable &Table, StringRef TableName, - raw_ostream &OS) { + formatted_raw_ostream &OS) { OS << "static const X86MemoryFoldTableEntry MemoryFold" << TableName << "[] = {\n"; for (const X86FoldTableEntry &E : Table) - OS << E; + E.print(OS); - OS << "};\n"; + OS << "};\n\n"; } }; // Return true if one of the instruction's operands is a RST register class static bool hasRSTRegClass(const CodeGenInstruction *Inst) { return any_of(Inst->Operands, [](const CGIOperandList::OperandInfo &OpIn) { - return OpIn.Rec->getName() == "RST"; + return OpIn.Rec->getName() == "RST" || OpIn.Rec->getName() == "RSTi"; }); } @@ -347,10 +348,18 @@ public: MemRec->getValueAsBit("hasLockPrefix") || RegRec->getValueAsBit("hasNoTrackPrefix") != MemRec->getValueAsBit("hasNoTrackPrefix") || - !equalBitsInits(RegRec->getValueAsBitsInit("EVEX_LL"), - MemRec->getValueAsBitsInit("EVEX_LL")) || - !equalBitsInits(RegRec->getValueAsBitsInit("VEX_WPrefix"), - MemRec->getValueAsBitsInit("VEX_WPrefix")) || + RegRec->getValueAsBit("hasVEX_L") != + MemRec->getValueAsBit("hasVEX_L") || + RegRec->getValueAsBit("hasEVEX_L2") != + MemRec->getValueAsBit("hasEVEX_L2") || + RegRec->getValueAsBit("ignoresVEX_L") != + MemRec->getValueAsBit("ignoresVEX_L") || + RegRec->getValueAsBit("HasVEX_W") != + MemRec->getValueAsBit("HasVEX_W") || + RegRec->getValueAsBit("IgnoresVEX_W") != + MemRec->getValueAsBit("IgnoresVEX_W") || + RegRec->getValueAsBit("EVEX_W1_VEX_W0") != + MemRec->getValueAsBit("EVEX_W1_VEX_W0") || // Instruction's format - The register form's "Form" field should be // the opposite of the memory form's "Form" field. !areOppositeForms(RegRec->getValueAsBitsInit("FormBits"), @@ -423,6 +432,7 @@ private: (MemFormNum == X86Local::MRM6m && RegFormNum == X86Local::MRM6r) || (MemFormNum == X86Local::MRM7m && RegFormNum == X86Local::MRM7r) || (MemFormNum == X86Local::MRMXm && RegFormNum == X86Local::MRMXr) || + (MemFormNum == X86Local::MRMXmCC && RegFormNum == X86Local::MRMXrCC) || (MemFormNum == X86Local::MRMDestMem && RegFormNum == X86Local::MRMDestReg) || (MemFormNum == X86Local::MRMSrcMem && @@ -430,7 +440,9 @@ private: (MemFormNum == X86Local::MRMSrcMem4VOp3 && RegFormNum == X86Local::MRMSrcReg4VOp3) || (MemFormNum == X86Local::MRMSrcMemOp4 && - RegFormNum == X86Local::MRMSrcRegOp4)) + RegFormNum == X86Local::MRMSrcRegOp4) || + (MemFormNum == X86Local::MRMSrcMemCC && + RegFormNum == X86Local::MRMSrcRegCC)) return true; return false; @@ -560,7 +572,7 @@ void X86FoldTablesEmitter::updateTables(const CodeGenInstruction *RegInstr, return; } -void X86FoldTablesEmitter::run(raw_ostream &OS) { +void X86FoldTablesEmitter::run(formatted_raw_ostream &OS) { emitSourceFileHeader("X86 fold tables", OS); // Holds all memory instructions @@ -641,7 +653,7 @@ void X86FoldTablesEmitter::run(raw_ostream &OS) { &(Target.getInstruction(MemInstIter)), Entry.Strategy); } - // Print all tables to raw_ostream OS. + // Print all tables. printTable(Table2Addr, "Table2Addr", OS); printTable(Table0, "Table0", OS); printTable(Table1, "Table1", OS); @@ -652,7 +664,8 @@ void X86FoldTablesEmitter::run(raw_ostream &OS) { namespace llvm { -void EmitX86FoldTables(RecordKeeper &RK, raw_ostream &OS) { +void EmitX86FoldTables(RecordKeeper &RK, raw_ostream &o) { + formatted_raw_ostream OS(o); X86FoldTablesEmitter(RK).run(OS); } } // namespace llvm