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

Krzysztof Parzyszek via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 6 10:08:38 PST 2017


Author: kparzysz
Date: Mon Mar  6 12:08:37 2017
New Revision: 297039

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

Added:
    llvm/trunk/test/CodeGen/Hexagon/tablegen-order-subtargetfeaturenames.mir
Modified:
    llvm/trunk/utils/TableGen/SubtargetFeatureInfo.cpp

Added: llvm/trunk/test/CodeGen/Hexagon/tablegen-order-subtargetfeaturenames.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Hexagon/tablegen-order-subtargetfeaturenames.mir?rev=297039&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/Hexagon/tablegen-order-subtargetfeaturenames.mir (added)
+++ llvm/trunk/test/CodeGen/Hexagon/tablegen-order-subtargetfeaturenames.mir Mon Mar  6 12:08:37 2017
@@ -0,0 +1,27 @@
+# RUN: not llc -march=hexagon -start-after=patchable-function %s -mcpu=hexagonv55 -filetype=obj -o /dev/null 2>&1 | FileCheck %s
+
+# This is checking for the ordering of feature names in SubtargetFeatureNames,
+# generated by TableGen. An incorrect order could cause a wrong name to be
+# printed.
+
+# CHECK: Attempting to emit J2_jumptpt instruction but the Feature_HasV60T predicate(s) are not met
+
+--- |
+  define void @fred() {
+    ret void
+  }
+...
+
+---
+name: fred
+registers:
+body: |
+  bb.0:
+    liveins: %p0
+    ; Instruction not available on Hexagon V55.
+    J2_jumptpt %p0, %bb.1, implicit-def %pc
+
+  bb.1:
+    J2_jumpr %r31, implicit-def %pc
+...
+

Modified: llvm/trunk/utils/TableGen/SubtargetFeatureInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/SubtargetFeatureInfo.cpp?rev=297039&r1=297038&r2=297039&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/SubtargetFeatureInfo.cpp (original)
+++ llvm/trunk/utils/TableGen/SubtargetFeatureInfo.cpp Mon Mar  6 12:08:37 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