[llvm] r322100 - [lli] Make lli support -mcpu=native for CPU autodetection

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 9 10:14:18 PST 2018


Author: ctopper
Date: Tue Jan  9 10:14:18 2018
New Revision: 322100

URL: http://llvm.org/viewvc/llvm-project?rev=322100&view=rev
Log:
[lli] Make lli support -mcpu=native for CPU autodetection

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 would 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?

Differential Revision: https://reviews.llvm.org/D41833

Modified:
    llvm/trunk/include/llvm/CodeGen/CommandFlags.def
    llvm/trunk/tools/lli/lli.cpp

Modified: llvm/trunk/include/llvm/CodeGen/CommandFlags.def
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/CommandFlags.def?rev=322100&r1=322099&r2=322100&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/CommandFlags.def (original)
+++ llvm/trunk/include/llvm/CodeGen/CommandFlags.def Tue Jan  9 10:14:18 2018
@@ -326,6 +326,26 @@ LLVM_ATTRIBUTE_UNUSED static std::string
   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

Modified: llvm/trunk/tools/lli/lli.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lli/lli.cpp?rev=322100&r1=322099&r2=322100&view=diff
==============================================================================
--- llvm/trunk/tools/lli/lli.cpp (original)
+++ llvm/trunk/tools/lli/lli.cpp Tue Jan  9 10:14:18 2018
@@ -378,8 +378,8 @@ int main(int argc, char **argv, char * c
   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())




More information about the llvm-commits mailing list