[llvm] [TableGen] Use consistent field kind checking in getNumericKey. (PR #83284)

Jason Eckhardt via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 28 08:16:18 PST 2024


https://github.com/nvjle created https://github.com/llvm/llvm-project/pull/83284

Fields GenericField::IsInstruction and GenericField::Enum can be simultaneously active for a given field.  Methods compareBy and primaryRepresentation both order the checking of IsInstruction before GenericField::Enum. Do the same in getNumericKey for consistency.

>From 928d3f9074ed3405da4f2cdbbc789477ce381c20 Mon Sep 17 00:00:00 2001
From: Jason Eckhardt <jeckhardt at nvidia.com>
Date: Wed, 28 Feb 2024 09:53:16 -0600
Subject: [PATCH] [TableGen] Use consistent field kind checking in
 getNumericKey.

Fields GenericField::IsInstruction and GenericField::Enum can be
simultaneously active for a given field.  Methods compareBy and
primaryRepresentation both order the checking of IsInstruction before
GenericField::Enum. Do the same in getNumericKey for consistency.
---
 llvm/utils/TableGen/SearchableTableEmitter.cpp | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/llvm/utils/TableGen/SearchableTableEmitter.cpp b/llvm/utils/TableGen/SearchableTableEmitter.cpp
index 5bab4ff188e8ed..52ac926a15f873 100644
--- a/llvm/utils/TableGen/SearchableTableEmitter.cpp
+++ b/llvm/utils/TableGen/SearchableTableEmitter.cpp
@@ -215,12 +215,14 @@ int64_t SearchableTableEmitter::getNumericKey(const SearchIndex &Index,
                                               Record *Rec) {
   assert(Index.Fields.size() == 1);
 
-  if (Index.Fields[0].Enum) {
-    Record *EnumEntry = Rec->getValueAsDef(Index.Fields[0].Name);
-    return Index.Fields[0].Enum->EntryMap[EnumEntry]->second;
-  } else if (Index.Fields[0].IsInstruction) {
+  // To be consistent with compareBy and primaryRepresentation elsewhere,
+  // we check for IsInstruction before Enum-- these fields are not exclusive.
+  if (Index.Fields[0].IsInstruction) {
     Record *TheDef = Rec->getValueAsDef(Index.Fields[0].Name);
     return Target->getInstrIntValue(TheDef);
+  } else if (Index.Fields[0].Enum) {
+    Record *EnumEntry = Rec->getValueAsDef(Index.Fields[0].Name);
+    return Index.Fields[0].Enum->EntryMap[EnumEntry]->second;
   }
 
   return getInt(Rec, Index.Fields[0].Name);



More information about the llvm-commits mailing list