[cfe-commits] r81390 - in /cfe/trunk/lib/Driver: Tools.cpp Tools.h

Daniel Dunbar daniel at zuster.org
Wed Sep 9 15:33:08 PDT 2009


Author: ddunbar
Date: Wed Sep  9 17:33:08 2009
New Revision: 81390

URL: http://llvm.org/viewvc/llvm-project?rev=81390&view=rev
Log:
Move Clang X86 cpu/feature argument translation into AddX86TargetArgs.

Modified:
    cfe/trunk/lib/Driver/Tools.cpp
    cfe/trunk/lib/Driver/Tools.h

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

==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Wed Sep  9 17:33:08 2009
@@ -183,6 +183,52 @@
                        options::OPT_Xpreprocessor);
 }
 
+void Clang::AddX86TargetArgs(const ArgList &Args,
+                             ArgStringList &CmdArgs) const {
+  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.
+
+    // FIXME: Need target hooks.
+    if (memcmp(getToolChain().getOS().c_str(), "darwin", 6) == 0) {
+      if (getToolChain().getArchName() == "x86_64")
+        CmdArgs.push_back("--mcpu=core2");
+      else if (getToolChain().getArchName() == "i386")
+        CmdArgs.push_back("--mcpu=yonah");
+    } else {
+      if (getToolChain().getArchName() == "x86_64")
+        CmdArgs.push_back("--mcpu=x86-64");
+      else if (getToolChain().getArchName() == "i386")
+        CmdArgs.push_back("--mcpu=pentium4");
+    }
+  }
+
+  // FIXME: Use iterator.
+  for (ArgList::const_iterator
+         it = Args.begin(), ie = Args.end(); it != ie; ++it) {
+    const Arg *A = *it;
+    if (A->getOption().matches(options::OPT_m_x86_Features_Group)) {
+      llvm::StringRef Name = A->getOption().getName();
+
+      // Skip over "-m".
+      assert(Name.startswith("-m") && "Invalid feature name.");
+      Name = Name.substr(2);
+
+      bool IsNegative = Name.startswith("no-");
+      if (IsNegative)
+        Name = Name.substr(3);
+
+      A->claim();
+      CmdArgs.push_back("-target-feature");
+      CmdArgs.push_back(Args.MakeArgString((IsNegative ? "-" : "+") + Name));
+    }
+  }
+}
+
 void Clang::ConstructJob(Compilation &C, const JobAction &JA,
                          Job &Dest,
                          const InputInfo &Output,
@@ -352,52 +398,20 @@
   // FIXME: Handle -mtune=.
   (void) Args.hasArg(options::OPT_mtune_EQ);
 
-  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.
-
-    // FIXME: Need target hooks.
-    if (memcmp(getToolChain().getOS().c_str(), "darwin", 6) == 0) {
-      if (getToolChain().getArchName() == "x86_64")
-        CmdArgs.push_back("--mcpu=core2");
-      else if (getToolChain().getArchName() == "i386")
-        CmdArgs.push_back("--mcpu=yonah");
-    } else {
-      if (getToolChain().getArchName() == "x86_64")
-        CmdArgs.push_back("--mcpu=x86-64");
-      else if (getToolChain().getArchName() == "i386")
-        CmdArgs.push_back("--mcpu=pentium4");
-    }
-  }
-
   if (Arg *A = Args.getLastArg(options::OPT_mcmodel_EQ)) {
     CmdArgs.push_back("-code-model");
     CmdArgs.push_back(A->getValue(Args));
   }
 
-  // FIXME: Use iterator.
-  for (ArgList::const_iterator
-         it = Args.begin(), ie = Args.end(); it != ie; ++it) {
-    const Arg *A = *it;
-    if (A->getOption().matches(options::OPT_m_x86_Features_Group)) {
-      llvm::StringRef Name = A->getOption().getName();
-
-      // Skip over "-m".
-      assert(Name.startswith("-m") && "Invalid feature name.");
-      Name = Name.substr(2);
-
-      bool IsNegative = Name.startswith("no-");
-      if (IsNegative)
-        Name = Name.substr(3);
+  // Add target specific cpu and features flags.
+  switch(getToolChain().getTriple().getArch()) {
+  default:
+    break;
 
-      A->claim();
-      CmdArgs.push_back("-target-feature");
-      CmdArgs.push_back(Args.MakeArgString((IsNegative ? "-" : "+") + Name));
-    }
+  case llvm::Triple::x86:
+  case llvm::Triple::x86_64:
+    AddX86TargetArgs(Args, CmdArgs);
+    break;
   }
 
   if (Args.hasFlag(options::OPT_fmath_errno,

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

==============================================================================
--- cfe/trunk/lib/Driver/Tools.h (original)
+++ cfe/trunk/lib/Driver/Tools.h Wed Sep  9 17:33:08 2009
@@ -33,6 +33,8 @@
                                  const InputInfo &Output,
                                  const InputInfoList &Inputs) const;
 
+    void AddX86TargetArgs(const ArgList &Args, ArgStringList &CmdArgs) const;
+
   public:
     Clang(const ToolChain &TC) : Tool("clang", TC) {}
 





More information about the cfe-commits mailing list