diff options
author | Krzysztof Parzyszek <kparzysz@codeaurora.org> | 2017-03-06 18:08:37 +0000 |
---|---|---|
committer | Krzysztof Parzyszek <kparzysz@codeaurora.org> | 2017-03-06 18:08:37 +0000 |
commit | b69b5c5449aebe77528c62c45674fe6898418085 (patch) | |
tree | c727e4c58fb07a9821e63db0c4d7e305bac5a248 /utils/TableGen/SubtargetFeatureInfo.cpp | |
parent | 08b86793476e08fc0937e70058e2a94808c988e7 (diff) |
[TableGen] Ensure proper ordering of subtarget feature names
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@297039 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/TableGen/SubtargetFeatureInfo.cpp')
-rw-r--r-- | utils/TableGen/SubtargetFeatureInfo.cpp | 21 |
1 files changed, 17 insertions, 4 deletions
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<Record *, SubtargetFeatureInfo, LessRecordByID> &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<<n, + // SubtargetFeatureNames[n] should be the name of the feature. + uint64_t IndexUB = 0; + for (const auto &SF : SubtargetFeatures) + if (IndexUB <= SF.second.Index) + IndexUB = SF.second.Index+1; + + std::vector<std::string> 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" |