[llvm] r297080 - [TableGen] Ensure proper ordering of subtarget feature names

Krzysztof Parzyszek via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 6 13:26:49 PST 2017


Author: kparzysz
Date: Mon Mar  6 15:26:49 2017
New Revision: 297080

URL: http://llvm.org/viewvc/llvm-project?rev=297080&view=rev
Log:
[TableGen] Ensure proper ordering of subtarget feature names

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

Modified:
    llvm/trunk/utils/TableGen/SubtargetFeatureInfo.cpp

Modified: llvm/trunk/utils/TableGen/SubtargetFeatureInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/SubtargetFeatureInfo.cpp?rev=297080&r1=297079&r2=297080&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/SubtargetFeatureInfo.cpp (original)
+++ llvm/trunk/utils/TableGen/SubtargetFeatureInfo.cpp Mon Mar  6 15:26:49 2017
@@ -62,11 +62,24 @@ void SubtargetFeatureInfo::emitSubtarget
 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"




More information about the llvm-commits mailing list