diff --git a/llvm/utils/TableGen/X86FoldTablesEmitter.cpp b/llvm/utils/TableGen/X86FoldTablesEmitter.cpp --- a/llvm/utils/TableGen/X86FoldTablesEmitter.cpp +++ b/llvm/utils/TableGen/X86FoldTablesEmitter.cpp @@ -107,6 +107,24 @@ OS << SimplifiedAttrs << "},\n"; } +#ifndef NDEBUG + bool CheckCorrectness() const { + // Check that Uses, Defs are same for entries in memory folding table + auto &RegInstRec = *RegInst->TheDef; + auto &MemInstRec = *MemInst->TheDef; + auto ListOfUsesReg = RegInstRec.getValueAsListOfDefs("Uses"); + auto ListOfUsesMem = MemInstRec.getValueAsListOfDefs("Uses"); + auto ListOfDefsReg = RegInstRec.getValueAsListOfDefs("Defs"); + auto ListOfDefsMem = MemInstRec.getValueAsListOfDefs("Defs"); + if (ListOfUsesReg != ListOfUsesMem || ListOfDefsReg != ListOfDefsMem) { + errs() << "Error: Incorrect converting "; + errs() << RegInstRec.getName() << " to "; + errs() << MemInstRec.getName() << "\n"; + return false; + } + return true; + } +#endif }; // NOTE: We check the fold tables are sorted in X86InstrFoldTables.cpp by the enum of the @@ -600,6 +618,24 @@ &(Target.getInstruction(MemInstIter)), Entry.Strategy, true); } + #ifndef NDEBUG + // To Check if the instructions convertion in MemFoldTable change the Uses + // and Defs, it's wrong when we convert it and changed its Defs/Uses. + auto CheckMemFoldTable = [] (const FoldTable& table) -> void { + for (const auto &record: table){ + auto& FoldEntry = record.second; + if(!FoldEntry.CheckCorrectness()){ + break; + } + } + }; + CheckMemFoldTable(Table2Addr); + CheckMemFoldTable(Table0); + CheckMemFoldTable(Table1); + CheckMemFoldTable(Table2); + CheckMemFoldTable(Table3); + CheckMemFoldTable(Table4); + #endif // Print all tables. printTable(Table2Addr, "Table2Addr", OS); printTable(Table0, "Table0", OS);