1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-22 04:22:57 +02:00

[TableGen] Ensure proper ordering of subtarget feature names

Recommit r297039 without the testcase. The MIR testcase did not work
well with MC code emitter.

llvm-svn: 297080
This commit is contained in:
Krzysztof Parzyszek 2017-03-06 21:26:49 +00:00
parent 65d8e44da8
commit ca42fcdaff

View File

@ -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"