From 744b12adb4ec7467a038b75a7fd63dd70e9dca14 Mon Sep 17 00:00:00 2001 From: XinWang10 Date: Tue, 16 May 2023 22:53:02 -0400 Subject: [PATCH] [X86]check that Uses, Defs are same for entries in memory folding table Add expensive check that Uses, Defs are same for entries in memory folding table. MemFolding could not change the Uses/Defs. Reviewed By: skan Differential Revision: https://reviews.llvm.org/D150633 --- llvm/utils/TableGen/X86FoldTablesEmitter.cpp | 29 ++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/llvm/utils/TableGen/X86FoldTablesEmitter.cpp b/llvm/utils/TableGen/X86FoldTablesEmitter.cpp index 475a577..89d93e4 100644 --- a/llvm/utils/TableGen/X86FoldTablesEmitter.cpp +++ b/llvm/utils/TableGen/X86FoldTablesEmitter.cpp @@ -107,6 +107,21 @@ class X86FoldTablesEmitter { OS << SimplifiedAttrs << "},\n"; } +#ifndef NDEBUG + // Check that Uses and Defs are same after memory fold. + void checkCorrectness() const { + 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) + report_fatal_error("Uses/Defs couldn't be changed after folding " + + RegInstRec.getName() + " to " + + MemInstRec.getName()); + } +#endif }; // NOTE: We check the fold tables are sorted in X86InstrFoldTables.cpp by the enum of the @@ -600,6 +615,20 @@ void X86FoldTablesEmitter::run(raw_ostream &o) { &(Target.getInstruction(MemInstIter)), Entry.Strategy, true); } +#ifndef NDEBUG + auto CheckMemFoldTable = [](const FoldTable &Table) -> void { + for (const auto &Record : Table) { + auto &FoldEntry = Record.second; + FoldEntry.checkCorrectness(); + } + }; + CheckMemFoldTable(Table2Addr); + CheckMemFoldTable(Table0); + CheckMemFoldTable(Table1); + CheckMemFoldTable(Table2); + CheckMemFoldTable(Table3); + CheckMemFoldTable(Table4); +#endif // Print all tables. printTable(Table2Addr, "Table2Addr", OS); printTable(Table0, "Table0", OS); -- 2.7.4