[PATCH] D85849: [X86] Flatten feature dependency tree at compile-time

Nathan Huckleberry via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 17 10:15:06 PDT 2020


Nathan-Huckleberry updated this revision to Diff 286061.
Nathan-Huckleberry added a comment.

Change dependency map to constexpr array to avoid global constructor


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85849/new/

https://reviews.llvm.org/D85849

Files:
  llvm/lib/Support/X86TargetParser.cpp


Index: llvm/lib/Support/X86TargetParser.cpp
===================================================================
--- llvm/lib/Support/X86TargetParser.cpp
+++ llvm/lib/Support/X86TargetParser.cpp
@@ -115,6 +115,7 @@
 };
 
 struct FlatFeatureDependency {
+  StringLiteral Name;
   FeatureBitset ImpliedEnabledFeatures;
   FeatureBitset ImpliedDisabledFeatures;
 };
@@ -566,7 +567,7 @@
 
 // Traverse the dependency tree at compile time so we don't need to recompute at
 // runtime.
-static constexpr std::pair<StringRef, FlatFeatureDependency>
+static constexpr FlatFeatureDependency
 FlattenFeatureDependencies(unsigned Index) {
   auto I = FeatureInfos[Index];
   FeatureBitset ImpliedEnabled =
@@ -574,13 +575,14 @@
   FeatureBitset ImpliedDisabled =
       ImpliedDisabledFeatures(Index) | FeatureBitset().set(Index);
 
-  return {I.Name, {ImpliedEnabled, ImpliedDisabled}};
+  return {I.Name, ImpliedEnabled, ImpliedDisabled};
 }
 
-static const StringMap<FlatFeatureDependency> FeatureDependencyMap({
+static constexpr FlatFeatureDependency
+    FeatureDependencies[X86::CPU_FEATURE_MAX] = {
 #define X86_FEATURE(ENUM, STR) FlattenFeatureDependencies(__COUNTER__),
 #include "llvm/Support/X86TargetParser.def"
-});
+};
 
 void llvm::X86::getFeaturesForCPU(StringRef CPU,
                                   SmallVectorImpl<StringRef> &EnabledFeatures) {
@@ -605,11 +607,19 @@
     StringMap<bool> &Features) {
 
   FeatureBitset ImpliedBits;
-  FlatFeatureDependency D = FeatureDependencyMap.lookup(Feature);
+  auto D =
+      llvm::find_if(FeatureDependencies, [&](const FlatFeatureDependency &FD) {
+        return FD.Name == Feature;
+      });
+  if (D == std::end(FeatureDependencies)) {
+    // FIXME: This shouldn't happen, but may not have all features in the table
+    // yet.
+    return;
+  }
   if (Enabled)
-    ImpliedBits = D.ImpliedEnabledFeatures;
+    ImpliedBits = D->ImpliedEnabledFeatures;
   else
-    ImpliedBits = D.ImpliedDisabledFeatures;
+    ImpliedBits = D->ImpliedDisabledFeatures;
 
   // Update the map entry for all implied features.
   for (unsigned i = 0; i != CPU_FEATURE_MAX; ++i)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85849.286061.patch
Type: text/x-patch
Size: 2122 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200817/ca99f4be/attachment.bin>


More information about the llvm-commits mailing list