[llvm] 6afdf40 - [TableGen] Stabilize sort in GET_SUBTARGETINFO_MACRO block
Kevin P. Neal via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 28 05:29:31 PDT 2023
Author: Kevin P. Neal
Date: 2023-06-28T08:28:47-04:00
New Revision: 6afdf4052551bb3eea013c8ffeeb30112ccd69a3
URL: https://github.com/llvm/llvm-project/commit/6afdf4052551bb3eea013c8ffeeb30112ccd69a3
DIFF: https://github.com/llvm/llvm-project/commit/6afdf4052551bb3eea013c8ffeeb30112ccd69a3.diff
LOG: [TableGen] Stabilize sort in GET_SUBTARGETINFO_MACRO block
The sort of the elements in the GET_SUBTARGETINFO_MACRO block is done on
the "Name" field of each record. This field is not guaranteed to be unique,
is not guaranteed to even have a value at all, and is not used in the
output anyway. Change to sort on the "FieldName" field which should be
unique.
Problem spotted when lib/Target/PowerPC/PPCGenSubtargetInfo.inc changed
unexpectedly.
Differential Revision: https://reviews.llvm.org/D153371
Added:
Modified:
llvm/include/llvm/TableGen/Record.h
llvm/utils/TableGen/SubtargetEmitter.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/TableGen/Record.h b/llvm/include/llvm/TableGen/Record.h
index 321b0f4566be84..698e777748cc29 100644
--- a/llvm/include/llvm/TableGen/Record.h
+++ b/llvm/include/llvm/TableGen/Record.h
@@ -2033,6 +2033,15 @@ struct LessRecordFieldName {
}
};
+/// Sorting predicate to sort record pointers by their
+/// FieldName field.
+struct LessRecordFieldFieldName {
+ bool operator()(const Record *Rec1, const Record *Rec2) const {
+ return Rec1->getValueAsString("FieldName") <
+ Rec2->getValueAsString("FieldName");
+ }
+};
+
struct LessRecordRegister {
struct RecordParts {
SmallVector<std::pair< bool, StringRef>, 4> Parts;
diff --git a/llvm/utils/TableGen/SubtargetEmitter.cpp b/llvm/utils/TableGen/SubtargetEmitter.cpp
index 5ab0d8e911d0f6..c63c8f1f4aa931 100644
--- a/llvm/utils/TableGen/SubtargetEmitter.cpp
+++ b/llvm/utils/TableGen/SubtargetEmitter.cpp
@@ -202,7 +202,7 @@ void SubtargetEmitter::EmitSubtargetInfoMacroCalls(raw_ostream &OS) {
std::vector<Record *> FeatureList =
Records.getAllDerivedDefinitions("SubtargetFeature");
- llvm::sort(FeatureList, LessRecordFieldName());
+ llvm::sort(FeatureList, LessRecordFieldFieldName());
for (const Record *Feature : FeatureList) {
const StringRef FieldName = Feature->getValueAsString("FieldName");
More information about the llvm-commits
mailing list