From: Krzysztof Parzyszek Date: Mon, 6 Mar 2017 21:26:49 +0000 (+0000) Subject: [TableGen] Ensure proper ordering of subtarget feature names X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=490469a98cf9dfb8487443cf8973dce62d73c719;p=llvm [TableGen] Ensure proper ordering of subtarget feature names Recommit r297039 without the testcase. The MIR testcase did not work well with MC code emitter. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@297080 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/utils/TableGen/SubtargetFeatureInfo.cpp b/utils/TableGen/SubtargetFeatureInfo.cpp index 6c2e8b53c48..72a556182b1 100644 --- a/utils/TableGen/SubtargetFeatureInfo.cpp +++ b/utils/TableGen/SubtargetFeatureInfo.cpp @@ -62,11 +62,24 @@ void SubtargetFeatureInfo::emitSubtargetFeatureFlagEnumeration( void SubtargetFeatureInfo::emitNameTable( std::map &SubtargetFeatures, raw_ostream &OS) { + // Need to sort the name table so that lookup by the log of the enum value + // gives the proper name. More specifically, for a feature of value 1< Names; + if (IndexUB > 0) + Names.resize(IndexUB); + for (const auto &SF : SubtargetFeatures) + Names[SF.second.Index] = SF.second.getEnumName(); + OS << "static const char *SubtargetFeatureNames[] = {\n"; - for (const auto &SF : SubtargetFeatures) { - const SubtargetFeatureInfo &SFI = SF.second; - OS << " \"" << SFI.getEnumName() << "\",\n"; - } + for (uint64_t I = 0; I < IndexUB; ++I) + OS << " \"" << Names[I] << "\",\n"; + // A small number of targets have no predicates. Null terminate the array to // avoid a zero-length array. OS << " nullptr\n"