[PATCH] D79705: [TableGen] Fix register class handling in TableGen's DAG ISel Matcher Generator

Victor Campos via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 11 04:15:30 PDT 2020


vhscampos created this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
vhscampos added a reviewer: rampitec.

In TableGen's instruction selection table generator, references to
register classes were handled by generating a matcher table entry in the
form of "EmitStringInteger, MVT::i32, 'RegisterClassID'". This ID is in
fact the enum integer value corresponding to the register class.

However, both the table generator and the table consumer
(SelectionDAGISel) assume that this ID is less than or equal to 127,
i.e. at most 7 bits. Values greater than this threshold cause completely
wrong behaviours in the instruction selection process.

This patch adds a check to determine if the enum integer value is
greater than the limit of 127. In finding so, the generator emits an
"EmitInteger" instead, which properly supports values with arbitrary
sizes.

Commit f8d044bbcfdc9e1ddc02247ffb86fe39e1f277f0 <https://reviews.llvm.org/rGf8d044bbcfdc9e1ddc02247ffb86fe39e1f277f0> fixed the very same bug
for register subindices. The present patch now extends this cover to
register classes.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D79705

Files:
  llvm/utils/TableGen/DAGISelMatcherGen.cpp


Index: llvm/utils/TableGen/DAGISelMatcherGen.cpp
===================================================================
--- llvm/utils/TableGen/DAGISelMatcherGen.cpp
+++ llvm/utils/TableGen/DAGISelMatcherGen.cpp
@@ -707,9 +707,19 @@
     if (Def->isSubClassOf("RegisterOperand"))
       Def = Def->getValueAsDef("RegClass");
     if (Def->isSubClassOf("RegisterClass")) {
-      std::string Value = getQualifiedName(Def) + "RegClassID";
-      AddMatcher(new EmitStringIntegerMatcher(Value, MVT::i32));
-      ResultOps.push_back(NextRecordedOperandNo++);
+      // If the register class has an enum integer value greater than 127, the
+      // encoding overflows the limit of 7 bits, which precludes the use of
+      // StringIntegerMatcher. In this case, fallback to using IntegerMatcher.
+      const CodeGenRegisterClass &RC =
+          CGP.getTargetInfo().getRegisterClass(Def);
+      if (RC.EnumValue <= 127) {
+        std::string Value = getQualifiedName(Def) + "RegClassID";
+        AddMatcher(new EmitStringIntegerMatcher(Value, MVT::i32));
+        ResultOps.push_back(NextRecordedOperandNo++);
+      } else {
+        AddMatcher(new EmitIntegerMatcher(RC.EnumValue, MVT::i32));
+        ResultOps.push_back(NextRecordedOperandNo++);
+      }
       return;
     }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79705.263141.patch
Type: text/x-patch
Size: 1281 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200511/5fb7709a/attachment.bin>


More information about the llvm-commits mailing list