[cfe-commits] r88819 - in /cfe/trunk: lib/Driver/Tools.cpp test/Driver/clang-translation.c

Daniel Dunbar daniel at zuster.org
Sat Nov 14 14:04:55 PST 2009


Author: ddunbar
Date: Sat Nov 14 16:04:54 2009
New Revision: 88819

URL: http://llvm.org/viewvc/llvm-project?rev=88819&view=rev
Log:
Add clang -mcpu=native support, patch by Roman Divacky, varioustweaks by me.
 - We still need support for detecting the target features, since the name
   doesn't actually do a good job of decribing what the CPU supports (for LLVM).

Modified:
    cfe/trunk/lib/Driver/Tools.cpp
    cfe/trunk/test/Driver/clang-translation.c

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=88819&r1=88818&r2=88819&view=diff

==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Sat Nov 14 16:04:54 2009
@@ -26,6 +26,7 @@
 #include "llvm/ADT/Twine.h"
 #include "llvm/Support/Format.h"
 #include "llvm/Support/raw_ostream.h"
+#include "llvm/System/Host.h"
 #include "llvm/System/Process.h"
 
 #include "InputInfo.h"
@@ -428,28 +429,42 @@
                    false))
     CmdArgs.push_back("--no-implicit-float");
 
+  const char *CPUName = 0;
   if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) {
-    // FIXME: We may need some translation here from the options gcc takes to
-    // names the LLVM backend understand?
-    CmdArgs.push_back("-mcpu");
-    CmdArgs.push_back(A->getValue(Args));
-  } else {
-    // Select default CPU.
+    if (llvm::StringRef(A->getValue(Args)) == "native") {
+      // FIXME: Reject attempts to use -march=native unless the target matches
+      // the host.
+      //
+      // FIXME: We should also incorporate the detected target features for use
+      // with -native.
+      std::string CPU = llvm::sys::getHostCPUName();
+      if (!CPU.empty())
+        CPUName = Args.MakeArgString(CPU);
+    } else
+      CPUName = A->getValue(Args);
+  }
 
+  // Select the default CPU if none was given (or detection failed).
+  if (!CPUName) {
     // FIXME: Need target hooks.
     if (memcmp(getToolChain().getOS().c_str(), "darwin", 6) == 0) {
       if (getToolChain().getArchName() == "x86_64")
-        CmdArgs.push_back("--mcpu=core2");
+        CPUName = "core2";
       else if (getToolChain().getArchName() == "i386")
-        CmdArgs.push_back("--mcpu=yonah");
+        CPUName = "yonah";
     } else {
       if (getToolChain().getArchName() == "x86_64")
-        CmdArgs.push_back("--mcpu=x86-64");
+        CPUName = "x86-64";
       else if (getToolChain().getArchName() == "i386")
-        CmdArgs.push_back("--mcpu=pentium4");
+        CPUName = "pentium4";
     }
   }
 
+  if (CPUName) {
+    CmdArgs.push_back("--mcpu");
+    CmdArgs.push_back(CPUName);
+  }
+
   // FIXME: Use iterator.
   for (ArgList::const_iterator
          it = Args.begin(), ie = Args.end(); it != ie; ++it) {

Modified: cfe/trunk/test/Driver/clang-translation.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/clang-translation.c?rev=88819&r1=88818&r2=88819&view=diff

==============================================================================
--- cfe/trunk/test/Driver/clang-translation.c (original)
+++ cfe/trunk/test/Driver/clang-translation.c Sat Nov 14 16:04:54 2009
@@ -10,6 +10,6 @@
 // RUN: grep '"-o" .*clang-translation.*' %t.log
 // RUN: grep '"--asm-verbose"' %t.log
 // RUN: clang -ccc-host-triple i386-apple-darwin9 -### -S %s -o %t.s 2> %t.log
-// RUN: grep '"--mcpu=yonah"' %t.log
+// RUN: grep '"--mcpu" "yonah"' %t.log
 // RUN: clang -ccc-host-triple x86_64-apple-darwin9 -### -S %s -o %t.s 2> %t.log
-// RUN: grep '"--mcpu=core2"' %t.log
+// RUN: grep '"--mcpu" "core2"' %t.log





More information about the cfe-commits mailing list