llc: Add support for -mcpu=native.
authorJim Grosbach <grosbach@apple.com>
Sat, 12 Apr 2014 01:34:31 +0000 (01:34 +0000)
committerJim Grosbach <grosbach@apple.com>
Sat, 12 Apr 2014 01:34:31 +0000 (01:34 +0000)
When -mcpu=native is passed, autodetect the host CPU and pass that
as the CPU name to the TargetMachine factory method.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206095 91177308-0d34-0410-b5e6-96231b3b80d8

tools/llc/llc.cpp

index 8fbdc49e5eeb14ff90f6f5a624c7a4333418d0c2..0c8d14d11db6d5078f58971146dcde2b1eb97f8d 100644 (file)
@@ -213,6 +213,12 @@ static int compileModule(char **argv, LLVMContext &Context) {
   bool SkipModule = MCPU == "help" ||
                     (!MAttrs.empty() && MAttrs.front() == "help");
 
+  // If user asked for the 'native' CPU, autodetect here. If autodection fails,
+  // this will set the CPU to an empty string which tells the target to
+  // pick a basic default.
+  if (MCPU == "native")
+    MCPU = sys::getHostCPUName();
+
   // If user just wants to list available options, skip module loading
   if (!SkipModule) {
     M.reset(ParseIRFile(InputFilename, Err, Context));