[PATCH] D41833: [lli] Make lli support -mcpu=native for CPU autodetection

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 8 12:37:09 PST 2018


craig.topper created this revision.
craig.topper added a reviewer: lhames.

llc, opt, and clang can all autodetect the CPU and supported features. lli cannot as far as I could tell.

This patch uses the getCPUStr() and introduces a new getCPUFeatureList() and uses those in lli in place of MCPU and MAttrs.

Ideally, we should merge getCPUFeatureList and getCPUFeatureStr, but opt and llc need a string and lli wanted a list. Maybe we should just return the SubtargetFeature object and let the caller decide what it needs?


https://reviews.llvm.org/D41833

Files:
  include/llvm/CodeGen/CommandFlags.def
  tools/lli/lli.cpp


Index: tools/lli/lli.cpp
===================================================================
--- tools/lli/lli.cpp
+++ tools/lli/lli.cpp
@@ -378,8 +378,8 @@
   std::string ErrorMsg;
   EngineBuilder builder(std::move(Owner));
   builder.setMArch(MArch);
-  builder.setMCPU(MCPU);
-  builder.setMAttrs(MAttrs);
+  builder.setMCPU(getCPUStr());
+  builder.setMAttrs(getFeatureList());
   if (RelocModel.getNumOccurrences())
     builder.setRelocationModel(RelocModel);
   if (CMModel.getNumOccurrences())
Index: include/llvm/CodeGen/CommandFlags.def
===================================================================
--- include/llvm/CodeGen/CommandFlags.def
+++ include/llvm/CodeGen/CommandFlags.def
@@ -326,6 +326,26 @@
   return Features.getString();
 }
 
+LLVM_ATTRIBUTE_UNUSED static std::vector<std::string> getFeatureList() {
+  SubtargetFeatures Features;
+
+  // If user asked for the 'native' CPU, we need to autodetect features.
+  // This is necessary for x86 where the CPU might not support all the
+  // features the autodetected CPU name lists in the target. For example,
+  // not all Sandybridge processors support AVX.
+  if (MCPU == "native") {
+    StringMap<bool> HostFeatures;
+    if (sys::getHostCPUFeatures(HostFeatures))
+      for (auto &F : HostFeatures)
+        Features.AddFeature(F.first(), F.second);
+  }
+
+  for (unsigned i = 0; i != MAttrs.size(); ++i)
+    Features.AddFeature(MAttrs[i]);
+
+  return Features.getFeatures();
+}
+
 /// \brief Set function attributes of functions in Module M based on CPU,
 /// Features, and command line flags.
 LLVM_ATTRIBUTE_UNUSED static void


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41833.128969.patch
Type: text/x-patch
Size: 1616 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180108/7e0fa781/attachment.bin>


More information about the llvm-commits mailing list