Frontend: Add a more explicit -backend-option flag for passing backend command
line options, instead of leveraging the blanket -mllvm option.
 - This allows using the frontend itself without requiring the backend have
   those options available (i.e., if the target wasn't built).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@128087 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/Driver/CC1Options.td b/include/clang/Driver/CC1Options.td
index 4188234..b29d73f 100644
--- a/include/clang/Driver/CC1Options.td
+++ b/include/clang/Driver/CC1Options.td
@@ -155,6 +155,8 @@
   HelpText<"Omit frame pointer setup for leaf functions.">;
 def msoft_float : Flag<"-msoft-float">,
   HelpText<"Use software floating point">;
+def backend_option : Separate<"-backend-option">,
+  HelpText<"Additional arguments to forward to LLVM backend (during code gen)">;
 def mregparm : Separate<"-mregparm">,
   HelpText<"Limit the number of registers available for integer arguments">;
 def mrelax_all : Flag<"-mrelax-all">,
diff --git a/include/clang/Frontend/CodeGenOptions.h b/include/clang/Frontend/CodeGenOptions.h
index 875fbcd..b49c431 100644
--- a/include/clang/Frontend/CodeGenOptions.h
+++ b/include/clang/Frontend/CodeGenOptions.h
@@ -15,6 +15,7 @@
 #define LLVM_CLANG_FRONTEND_CODEGENOPTIONS_H
 
 #include <string>
+#include <vector>
 
 namespace clang {
 
@@ -114,6 +115,9 @@
   /// The name of the relocation model to use.
   std::string RelocationModel;
 
+  /// A list of command-line options to forward to the LLVM backend.
+  std::vector<std::string> BackendOptions;
+
   /// The user specified number of registers to be used for integral arguments,
   /// or 0 if unspecified.
   unsigned NumRegisterParameters;
diff --git a/lib/CodeGen/BackendUtil.cpp b/lib/CodeGen/BackendUtil.cpp
index 9897b1b..ce64dc7 100644
--- a/lib/CodeGen/BackendUtil.cpp
+++ b/lib/CodeGen/BackendUtil.cpp
@@ -248,6 +248,8 @@
   }
   if (llvm::TimePassesIsEnabled)
     BackendArgs.push_back("-time-passes");
+  for (unsigned i = 0, e = CodeGenOpts.BackendOptions.size(); i != e; ++i)
+    BackendArgs.push_back(CodeGenOpts.BackendOptions[i].c_str());
   BackendArgs.push_back(0);
   llvm::cl::ParseCommandLineOptions(BackendArgs.size() - 1,
                                     const_cast<char **>(&BackendArgs[0]));
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp
index 6bfe82a..59cdfe0 100644
--- a/lib/Driver/Tools.cpp
+++ b/lib/Driver/Tools.cpp
@@ -440,7 +440,7 @@
 
   // Disable movt generation, if requested.
 #ifdef DISABLE_ARM_DARWIN_USE_MOVT
-  CmdArgs.push_back("-mllvm");
+  CmdArgs.push_back("-backend-option");
   CmdArgs.push_back("-arm-darwin-use-movt=0");
 #endif
 
@@ -607,10 +607,10 @@
 
   // Kernel code has more strict alignment requirements.
   if (KernelOrKext) {
-    CmdArgs.push_back("-mllvm");
+    CmdArgs.push_back("-backend-option");
     CmdArgs.push_back("-arm-long-calls");
 
-    CmdArgs.push_back("-mllvm");
+    CmdArgs.push_back("-backend-option");
     CmdArgs.push_back("-arm-strict-align");
   }
 }
diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp
index 2b5c289..980c752 100644
--- a/lib/Frontend/CompilerInvocation.cpp
+++ b/lib/Frontend/CompilerInvocation.cpp
@@ -207,6 +207,10 @@
   }
   if (!Opts.VerifyModule)
     Res.push_back("-disable-llvm-verifier");
+  for (unsigned i = 0, e = Opts.BackendOptions.size(); i != e; ++i) {
+    Res.push_back("-backend-option");
+    Res.push_back(Opts.BackendOptions[i]);
+  }
 }
 
 static void DependencyOutputOptsToArgs(const DependencyOutputOptions &Opts,
@@ -927,6 +931,7 @@
   Opts.NoInfsFPMath = Opts.NoNaNsFPMath = Args.hasArg(OPT_cl_finite_math_only)||
                                           Args.hasArg(OPT_cl_fast_relaxed_math);
   Opts.NoZeroInitializedInBSS = Args.hasArg(OPT_mno_zero_initialized_in_bss);
+  Opts.BackendOptions = Args.getAllArgValues(OPT_backend_option);
   Opts.NumRegisterParameters = Args.getLastArgIntValue(OPT_mregparm, 0, Diags);
   Opts.RelaxAll = Args.hasArg(OPT_mrelax_all);
   Opts.OmitLeafFramePointer = Args.hasArg(OPT_momit_leaf_frame_pointer);
diff --git a/test/Driver/apple-kext-mkernel.c b/test/Driver/apple-kext-mkernel.c
index a7a925e..82a6896 100644
--- a/test/Driver/apple-kext-mkernel.c
+++ b/test/Driver/apple-kext-mkernel.c
@@ -11,8 +11,8 @@
 // RUN:   -arch armv7 -mkernel -### -fsyntax-only %s 2> %t
 // RUN: FileCheck --check-prefix=CHECK-ARM < %t %s
 
-// CHECK-ARM: "-mllvm" "-arm-long-calls"
-// CHECK-ARM: "-mllvm" "-arm-strict-align"
+// CHECK-ARM: "-backend-option" "-arm-long-calls"
+// CHECK-ARM: "-backend-option" "-arm-strict-align"
 // CHECK-ARM: "-fno-builtin"
 // CHECK-ARM: "-fno-rtti"
 // CHECK-ARM: "-fno-common"