diff --git a/llvm/include/llvm/TableGen/Record.h b/llvm/include/llvm/TableGen/Record.h --- a/llvm/include/llvm/TableGen/Record.h +++ b/llvm/include/llvm/TableGen/Record.h @@ -1999,17 +1999,19 @@ /// Get all the concrete records that inherit from the one specified /// class. The class must be defined. - std::vector getAllDerivedDefinitions(StringRef ClassName) const; + std::vector getAllDerivedDefinitions(StringRef ClassName, + bool SortNumeric = true) const; /// Get all the concrete records that inherit from all the specified /// classes. The classes must be defined. - std::vector getAllDerivedDefinitions( - ArrayRef ClassNames) const; + std::vector getAllDerivedDefinitions(ArrayRef ClassNames, + bool SortNumeric = true) const; /// Get all the concrete records that inherit from specified class, if the /// class is defined. Returns an empty vector if the class is not defined. std::vector - getAllDerivedDefinitionsIfDefined(StringRef ClassName) const; + getAllDerivedDefinitionsIfDefined(StringRef ClassName, + bool SortNumeric = true) const; void dump() const; diff --git a/llvm/lib/TableGen/Record.cpp b/llvm/lib/TableGen/Record.cpp --- a/llvm/lib/TableGen/Record.cpp +++ b/llvm/lib/TableGen/Record.cpp @@ -2976,18 +2976,21 @@ } std::vector -RecordKeeper::getAllDerivedDefinitions(StringRef ClassName) const { +RecordKeeper::getAllDerivedDefinitions(StringRef ClassName, + bool SortNumeric) const { // We cache the record vectors for single classes. Many backends request // the same vectors multiple times. auto Pair = ClassRecordsMap.try_emplace(ClassName); if (Pair.second) - Pair.first->second = getAllDerivedDefinitions(ArrayRef(ClassName)); + Pair.first->second = + getAllDerivedDefinitions(ArrayRef(ClassName), SortNumeric); return Pair.first->second; } -std::vector RecordKeeper::getAllDerivedDefinitions( - ArrayRef ClassNames) const { +std::vector +RecordKeeper::getAllDerivedDefinitions(ArrayRef ClassNames, + bool SortNumeric) const { SmallVector ClassRecs; std::vector Defs; @@ -3006,12 +3009,18 @@ Defs.push_back(OneDef.second.get()); } + if (SortNumeric) + llvm::sort(Defs, [](Record *LHS, Record *RHS) { + return LHS->getName().compare_numeric(RHS->getName()) < 0; + }); + return Defs; } std::vector -RecordKeeper::getAllDerivedDefinitionsIfDefined(StringRef ClassName) const { - return getClass(ClassName) ? getAllDerivedDefinitions(ClassName) +RecordKeeper::getAllDerivedDefinitionsIfDefined(StringRef ClassName, + bool SortNumeric) const { + return getClass(ClassName) ? getAllDerivedDefinitions(ClassName, SortNumeric) : std::vector(); } diff --git a/llvm/utils/TableGen/CodeGenRegisters.cpp b/llvm/utils/TableGen/CodeGenRegisters.cpp --- a/llvm/utils/TableGen/CodeGenRegisters.cpp +++ b/llvm/utils/TableGen/CodeGenRegisters.cpp @@ -1174,8 +1174,8 @@ getReg(Regs[i]); // Expand tuples and number the new registers. - std::vector Tups = - Records.getAllDerivedDefinitions("RegisterTuples"); + std::vector Tups = + Records.getAllDerivedDefinitions("RegisterTuples", false); for (Record *R : Tups) { std::vector TupRegs = *Sets.expand(R);