[PATCH] D153371: [TableGen] Stabilize sort in GET_SUBTARGETINFO_MACRO block
Kevin P. Neal via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 20 11:35:48 PDT 2023
kpn created this revision.
kpn added reviewers: pengfei, chapuni, akshaykhadse.
Herald added subscribers: steven.zhang, mgrang.
Herald added a project: All.
kpn requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
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 "Attribute" field which should be unique.
Problem spotted when lib/Target/PowerPC/PPCGenSubtargetInfo.inc changed unexpectedly.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D153371
Files:
llvm/include/llvm/TableGen/Record.h
llvm/utils/TableGen/SubtargetEmitter.cpp
Index: llvm/utils/TableGen/SubtargetEmitter.cpp
===================================================================
--- llvm/utils/TableGen/SubtargetEmitter.cpp
+++ llvm/utils/TableGen/SubtargetEmitter.cpp
@@ -202,7 +202,7 @@
std::vector<Record *> FeatureList =
Records.getAllDerivedDefinitions("SubtargetFeature");
- llvm::sort(FeatureList, LessRecordFieldName());
+ llvm::sort(FeatureList, LessRecordFieldAttribute());
for (const Record *Feature : FeatureList) {
const StringRef Attribute = Feature->getValueAsString("Attribute");
Index: llvm/include/llvm/TableGen/Record.h
===================================================================
--- llvm/include/llvm/TableGen/Record.h
+++ llvm/include/llvm/TableGen/Record.h
@@ -2033,6 +2033,15 @@
}
};
+/// Sorting predicate to sort record pointers by their
+/// attribute field.
+struct LessRecordFieldAttribute {
+ bool operator()(const Record *Rec1, const Record *Rec2) const {
+ return Rec1->getValueAsString("Attribute") <
+ Rec2->getValueAsString("Attribute");
+ }
+};
+
struct LessRecordRegister {
struct RecordParts {
SmallVector<std::pair< bool, StringRef>, 4> Parts;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153371.532997.patch
Type: text/x-patch
Size: 1181 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230620/e391fb74/attachment.bin>
More information about the llvm-commits
mailing list