[cfe-commits] r81435 - /cfe/trunk/lib/Driver/Tools.cpp

Daniel Dunbar daniel at zuster.org
Wed Sep 9 23:49:20 PDT 2009


Author: ddunbar
Date: Thu Sep 10 01:49:20 2009
New Revision: 81435

URL: http://llvm.org/viewvc/llvm-project?rev=81435&view=rev
Log:
Add code to mangle the triple for LLVM on ARM.
 - I think we should get rid of this distinction though, but I need to discuss with the interested parties.

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

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

==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Thu Sep 10 01:49:20 2009
@@ -200,9 +200,11 @@
                        options::OPT_Xpreprocessor);
 }
 
+/// getARMTargetCPU - Get the (LLVM) name of the ARM cpu we are targetting.
+//
+// FIXME: tblgen this.
 static llvm::StringRef getARMTargetCPU(const ArgList &Args) {
-  // FIXME: Check the relative priority of these options against gcc. Also, what
-  // happens if the -mcpu and -march mismatch?
+  // FIXME: Warn on inconsistent use of -mcpu and -march.
 
   // If we have -mcpu=, use that.
   if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
@@ -252,6 +254,57 @@
   return "arm7tdmi";
 }
 
+/// getLLVMArchNameForARM - Get the LLVM arch name to use for a particular
+/// CPU.
+//
+// FIXME: This is redundant with -mcpu, why does LLVM use this.
+// FIXME: tblgen this, or kill it!
+static const char *getLLVMArchNameForARM(llvm::StringRef CPU, bool Thumb) {
+  if (CPU == "arm7tdmi" || CPU == "arm7tdmi-s" || CPU == "arm710t" ||
+      CPU == "arm720t" || CPU == "arm9" || CPU == "arm9tdmi" ||
+      CPU == "arm920" || CPU == "arm920t" || CPU == "arm922t" ||
+      CPU == "arm940t" || CPU == "ep9312")
+    return Thumb ? "thumbv4t" : "armv4t";
+
+  if (CPU == "arm10tdmi" || CPU == "arm1020t")
+    return Thumb ? "thumb5" : "armv5";
+
+  if (CPU == "arm9e" || CPU == "arm926ej-s" || CPU == "arm946e-s" ||
+      CPU == "arm966e-s" || CPU == "arm968e-s" || CPU == "arm10e" ||
+      CPU == "arm1020e" || CPU == "arm1022e" || CPU == "xscale" ||
+      CPU == "iwmmxt")
+    return Thumb ? "thumbv5e" : "armv5e";
+
+  if (CPU == "arm1136j-s" || CPU == "arm1136jf-s" || CPU == "arm1176jz-s" ||
+      CPU == "arm1176jzf-s" || CPU == "mpcorenovfp" || CPU == "mpcore")
+    return Thumb ? "thumbv6" : "armv6";
+
+  if (CPU == "arm1156t2-s" || CPU == "arm1156t2f-s")
+    return Thumb ? "thumbv6t2" : "armv6t2";
+
+  if (CPU == "cortex-a8" || CPU == "cortex-a9")
+    return Thumb ? "thumbv7" : "armv7";
+
+  return Thumb ? "thumb" : "arm";
+}
+
+/// getLLVMTriple - Get the LLVM triple to use for a particular toolchain, which
+/// may depend on command line arguments.
+static std::string getLLVMTriple(const ToolChain &TC, const ArgList &Args) {
+  switch (TC.getTriple().getArch()) {
+  default:
+    return TC.getTripleString();
+
+  case llvm::Triple::arm:
+  case llvm::Triple::thumb: {
+    llvm::Triple Triple = TC.getTriple();
+    Triple.setArchName(getLLVMArchNameForARM(getARMTargetCPU(Args),
+                                             /*FIXME:Thumb=*/false));
+    return Triple.getTriple();
+  }
+  }
+}
+
 void Clang::AddARMTargetArgs(const ArgList &Args,
                              ArgStringList &CmdArgs) const {
   // Set the CPU based on -march= and -mcpu=.
@@ -320,8 +373,9 @@
   assert(Inputs.size() == 1 && "Unable to handle multiple inputs.");
 
   CmdArgs.push_back("-triple");
+
   const char *TripleStr =
-    Args.MakeArgString(getToolChain().getTripleString());
+    Args.MakeArgString(getLLVMTriple(getToolChain(), Args));
   CmdArgs.push_back(TripleStr);
 
   if (isa<AnalyzeJobAction>(JA)) {
@@ -1091,7 +1145,7 @@
     for (ArgList::const_iterator it = Args.begin(),
            ie = Args.end(); it != ie; ++it) {
       const Arg *A = *it;
-      if (A->getOption().matches(options::OPT_f_Group) || 
+      if (A->getOption().matches(options::OPT_f_Group) ||
           A->getOption().matches(options::OPT_fsyntax_only)) {
         if (!A->getOption().matches(options::OPT_fbuiltin_strcat) &&
             !A->getOption().matches(options::OPT_fbuiltin_strcpy)) {





More information about the cfe-commits mailing list