[PATCH] D150633: [X86]check that Uses, Defs are same for entries in memory folding table

Wang, Xin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 15 21:28:47 PDT 2023


XinWang10 updated this revision to Diff 522427.
XinWang10 added a comment.

- resolve comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150633/new/

https://reviews.llvm.org/D150633

Files:
  llvm/utils/TableGen/X86FoldTablesEmitter.cpp


Index: llvm/utils/TableGen/X86FoldTablesEmitter.cpp
===================================================================
--- llvm/utils/TableGen/X86FoldTablesEmitter.cpp
+++ 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 ListOfUsesLHS = RegInstRec.getValueAsListOfDefs("Uses");
+      auto ListOfUsesRHS = MemInstRec.getValueAsListOfDefs("Uses");
+      auto ListOfDefsLHS = RegInstRec.getValueAsListOfDefs("Defs");
+      auto ListOfDefsRHS = MemInstRec.getValueAsListOfDefs("Defs");
+      if (ListOfUsesLHS != ListOfUsesRHS || ListOfDefsLHS != ListOfDefsRHS) {
+        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);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150633.522427.patch
Type: text/x-patch
Size: 2009 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230516/28cff2cb/attachment.bin>


More information about the llvm-commits mailing list