[llvm] 744b12a - [X86]check that Uses, Defs are same for entries in memory folding table

via llvm-commits llvm-commits at lists.llvm.org
Tue May 16 19:54:06 PDT 2023


Author: XinWang10
Date: 2023-05-16T22:53:52-04:00
New Revision: 744b12adb4ec7467a038b75a7fd63dd70e9dca14

URL: https://github.com/llvm/llvm-project/commit/744b12adb4ec7467a038b75a7fd63dd70e9dca14
DIFF: https://github.com/llvm/llvm-project/commit/744b12adb4ec7467a038b75a7fd63dd70e9dca14.diff

LOG: [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

Added: 
    

Modified: 
    llvm/utils/TableGen/X86FoldTablesEmitter.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/utils/TableGen/X86FoldTablesEmitter.cpp b/llvm/utils/TableGen/X86FoldTablesEmitter.cpp
index 475a577c9f30..89d93e4d3cbc 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);


        


More information about the llvm-commits mailing list