[cfe-commits] r81471 - in /cfe/trunk: include/clang/Basic/DiagnosticDriverKinds.td include/clang/Driver/Options.def lib/Driver/Tools.cpp

Daniel Dunbar daniel at zuster.org
Thu Sep 10 16:00:09 PDT 2009


Author: ddunbar
Date: Thu Sep 10 18:00:09 2009
New Revision: 81471

URL: http://llvm.org/viewvc/llvm-project?rev=81471&view=rev
Log:
Initial handling of -m{soft-float,hard-float,float-abi=} for ARM.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
    cfe/trunk/include/clang/Driver/Options.def
    cfe/trunk/lib/Driver/Tools.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td?rev=81471&r1=81470&r2=81471&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td Thu Sep 10 18:00:09 2009
@@ -53,6 +53,8 @@
   "%0 command failed with exit code %1 (use -v to see invocation)">;
 def err_drv_command_signalled : Error<
   "%0 command failed due to signal %1 (use -v to see invocation)">;
+def err_drv_invalid_mfloat_abi : Error<
+  "invalid float ABI '%0'">;
 
 def warn_drv_input_file_unused : Warning<
   "%0: '%1' input unused when '%2' is present">;
@@ -68,5 +70,7 @@
   "not using the clang compiler for the '%0' architecture">;
 def warn_drv_clang_unsupported : Warning<
   "the clang compiler does not support '%0'">;
+def warn_drv_assuming_mfloat_abi_is : Warning<
+  "unknown platform, assuming -mfloat-abi=%0">;
 
 }

Modified: cfe/trunk/include/clang/Driver/Options.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.def?rev=81471&r1=81470&r2=81471&view=diff

==============================================================================
--- cfe/trunk/include/clang/Driver/Options.def (original)
+++ cfe/trunk/include/clang/Driver/Options.def Thu Sep 10 18:00:09 2009
@@ -516,6 +516,8 @@
 OPTION("-mcpu=", mcpu_EQ, Joined, m_Group, INVALID, "d", 0, 0, 0)
 OPTION("-mdynamic-no-pic", mdynamic_no_pic, Joined, m_Group, INVALID, "q", 0, 0, 0)
 OPTION("-mfix-and-continue", mfix_and_continue, Flag, clang_ignored_m_Group, INVALID, "", 0, 0, 0)
+OPTION("-mfloat-abi=", mfloat_abi_EQ, Joined, m_Group, INVALID, "", 0, 0, 0)
+OPTION("-mhard-float", mhard_float, Flag, m_Group, INVALID, "", 0, 0, 0)
 OPTION("-miphoneos-version-min=", miphoneos_version_min_EQ, Joined, m_Group, INVALID, "", 0, 0, 0)
 OPTION("-mkernel", mkernel, Flag, m_Group, INVALID, "", 0, 0, 0)
 OPTION("-mllvm", mllvm, Separate, INVALID, INVALID, "", 0, 0, 0)

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

==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Thu Sep 10 18:00:09 2009
@@ -309,12 +309,70 @@
 
 void Clang::AddARMTargetArgs(const ArgList &Args,
                              ArgStringList &CmdArgs) const {
+  const Driver &D = getToolChain().getHost().getDriver();
+
   // Set the CPU based on -march= and -mcpu=.
   CmdArgs.push_back(Args.MakeArgString("-mcpu=" + getARMTargetCPU(Args)));
 
-  // FIXME: Set the "neon" feature.
-  // FIXME: Set -soft-float.
-  // FIXME: Set -float-abi=hard.
+  // Select the float ABI as determined by -msoft-float, -mhard-float, and
+  // -mfloat-abi=.
+  llvm::StringRef FloatABI;
+  if (Arg *A = Args.getLastArg(options::OPT_msoft_float,
+                               options::OPT_mhard_float,
+                               options::OPT_mfloat_abi_EQ)) {
+    if (A->getOption().matches(options::OPT_msoft_float))
+      FloatABI = "soft";
+    else if (A->getOption().matches(options::OPT_mhard_float))
+      FloatABI = "hard";
+    else {
+      FloatABI = A->getValue(Args);
+      if (FloatABI != "soft" && FloatABI != "softfp" && FloatABI != "hard") {
+        D.Diag(clang::diag::err_drv_invalid_mfloat_abi)
+          << A->getAsString(Args);
+        FloatABI = "soft";
+      }
+    }
+  }
+
+  // If unspecified, choose the default based on the platform.
+  if (FloatABI.empty()) {
+    // FIXME: This is wrong for non-Darwin, we don't have a mechanism yet for
+    // distinguishing things like linux-eabi vs linux-elf.
+    switch (getToolChain().getTriple().getOS()) {
+    case llvm::Triple::Darwin: {
+      // Darwin defaults to "softfp" for v6 and v7.
+      //
+      // FIXME: Factor out an ARM class so we can cache the arch somewhere.
+      llvm::StringRef ArchName = getLLVMArchSuffixForARM(getARMTargetCPU(Args));
+      if (ArchName.startswith("v6") || ArchName.startswith("v7"))
+        FloatABI = "softfp";
+      else
+        FloatABI = "soft";
+      break;
+    }
+
+    default:
+      // Assume "soft", but warn the user we are guessing.
+      FloatABI = "soft";
+      D.Diag(clang::diag::warn_drv_assuming_mfloat_abi_is) << "soft";
+      break;
+    }
+  }
+
+  if (FloatABI == "soft") {
+    // Floating point operations and argument passing are soft.
+    //
+    // FIXME: This changes CPP defines, we need -target-soft-float.
+    CmdArgs.push_back("-soft-float");
+    CmdArgs.push_back("-float-abi=soft");
+  } else if (FloatABI == "softfp") {
+    // Floating point operations are hard, but argument passing is soft.
+    CmdArgs.push_back("-float-abi=soft");
+  } else {
+    // Floating point operations and argument passing are hard.
+    assert(FloatABI == "hard" && "Invalid float abi!");
+    CmdArgs.push_back("-float-abi=hard");
+  }
 }
 
 void Clang::AddX86TargetArgs(const ArgList &Args,





More information about the cfe-commits mailing list