[llvm] [TableGen] Use consistent field kind checking in getNumericKey. (PR #83284)
Jason Eckhardt via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 29 08:58:05 PST 2024
https://github.com/nvjle updated https://github.com/llvm/llvm-project/pull/83284
>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 1/2] [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);
>From c241a61473cf2599a5d60186085ac6533081aa2e Mon Sep 17 00:00:00 2001
From: Jason Eckhardt <jeckhardt at nvidia.com>
Date: Thu, 29 Feb 2024 10:49:24 -0600
Subject: [PATCH 2/2] Address review comment-- no else after return.
---
llvm/utils/TableGen/SearchableTableEmitter.cpp | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/llvm/utils/TableGen/SearchableTableEmitter.cpp b/llvm/utils/TableGen/SearchableTableEmitter.cpp
index 52ac926a15f873..51f18f360ed311 100644
--- a/llvm/utils/TableGen/SearchableTableEmitter.cpp
+++ b/llvm/utils/TableGen/SearchableTableEmitter.cpp
@@ -220,7 +220,8 @@ int64_t SearchableTableEmitter::getNumericKey(const SearchIndex &Index,
if (Index.Fields[0].IsInstruction) {
Record *TheDef = Rec->getValueAsDef(Index.Fields[0].Name);
return Target->getInstrIntValue(TheDef);
- } else if (Index.Fields[0].Enum) {
+ }
+ if (Index.Fields[0].Enum) {
Record *EnumEntry = Rec->getValueAsDef(Index.Fields[0].Name);
return Index.Fields[0].Enum->EntryMap[EnumEntry]->second;
}
More information about the llvm-commits
mailing list