]> granicus.if.org Git - clang/commitdiff
Driver: refactor OpenCL argument forwarding
authorSaleem Abdulrasool <compnerd@compnerd.org>
Tue, 29 Aug 2017 23:59:07 +0000 (23:59 +0000)
committerSaleem Abdulrasool <compnerd@compnerd.org>
Tue, 29 Aug 2017 23:59:07 +0000 (23:59 +0000)
Extract the argument forwarding for OpenCL arguments.  Make this more
data driven as we are just repeating the argument name and spelling.
This costs a slight bit more memory due to the string duplication, but
makes it easier to follow.  It should be possible to forward the
internal string representation from the TableGen data to avoid this.
But, this makes the code simpler to follow for now.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@312083 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Driver/ToolChains/Clang.cpp

index e18a9413f2d0fbbef13cbc27dff2071931dab5bf..c941cf80633f3cdf1862dfa4ef5bad90da9b5b88 100644 (file)
@@ -1968,6 +1968,31 @@ static void CollectArgsForIntegratedAssembler(Compilation &C,
   }
 }
 
+static void RenderOpenCLOptions(const ArgList &Args, ArgStringList &CmdArgs) {
+  const unsigned ForwardedArguments[] = {
+      options::OPT_cl_opt_disable,
+      options::OPT_cl_strict_aliasing,
+      options::OPT_cl_single_precision_constant,
+      options::OPT_cl_finite_math_only,
+      options::OPT_cl_kernel_arg_info,
+      options::OPT_cl_unsafe_math_optimizations,
+      options::OPT_cl_fast_relaxed_math,
+      options::OPT_cl_mad_enable,
+      options::OPT_cl_no_signed_zeros,
+      options::OPT_cl_denorms_are_zero,
+      options::OPT_cl_fp32_correctly_rounded_divide_sqrt,
+  };
+
+  if (Arg *A = Args.getLastArg(options::OPT_cl_std_EQ)) {
+    std::string CLStdStr = std::string("-cl-std=") + A->getValue();
+    CmdArgs.push_back(Args.MakeArgString(CLStdStr));
+  }
+
+  for (const auto &Arg : ForwardedArguments)
+    if (const auto *A = Args.getLastArg(Arg))
+      CmdArgs.push_back(Args.MakeArgString(A->getOption().getPrefixedName()));
+}
+
 void Clang::ConstructJob(Compilation &C, const JobAction &JA,
                          const InputInfo &Output, const InputInfoList &Inputs,
                          const ArgList &Args, const char *LinkingOutput) const {
@@ -3476,44 +3501,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
   }
 
   // Forward -cl options to -cc1
-  if (Args.getLastArg(options::OPT_cl_opt_disable)) {
-    CmdArgs.push_back("-cl-opt-disable");
-  }
-  if (Args.getLastArg(options::OPT_cl_strict_aliasing)) {
-    CmdArgs.push_back("-cl-strict-aliasing");
-  }
-  if (Args.getLastArg(options::OPT_cl_single_precision_constant)) {
-    CmdArgs.push_back("-cl-single-precision-constant");
-  }
-  if (Args.getLastArg(options::OPT_cl_finite_math_only)) {
-    CmdArgs.push_back("-cl-finite-math-only");
-  }
-  if (Args.getLastArg(options::OPT_cl_kernel_arg_info)) {
-    CmdArgs.push_back("-cl-kernel-arg-info");
-  }
-  if (Args.getLastArg(options::OPT_cl_unsafe_math_optimizations)) {
-    CmdArgs.push_back("-cl-unsafe-math-optimizations");
-  }
-  if (Args.getLastArg(options::OPT_cl_fast_relaxed_math)) {
-    CmdArgs.push_back("-cl-fast-relaxed-math");
-  }
-  if (Args.getLastArg(options::OPT_cl_mad_enable)) {
-    CmdArgs.push_back("-cl-mad-enable");
-  }
-  if (Args.getLastArg(options::OPT_cl_no_signed_zeros)) {
-    CmdArgs.push_back("-cl-no-signed-zeros");
-  }
-  if (Arg *A = Args.getLastArg(options::OPT_cl_std_EQ)) {
-    std::string CLStdStr = "-cl-std=";
-    CLStdStr += A->getValue();
-    CmdArgs.push_back(Args.MakeArgString(CLStdStr));
-  }
-  if (Args.getLastArg(options::OPT_cl_denorms_are_zero)) {
-    CmdArgs.push_back("-cl-denorms-are-zero");
-  }
-  if (Args.getLastArg(options::OPT_cl_fp32_correctly_rounded_divide_sqrt)) {
-    CmdArgs.push_back("-cl-fp32-correctly-rounded-divide-sqrt");
-  }
+  RenderOpenCLOptions(Args, CmdArgs);
 
   // Forward -f options with positive and negative forms; we translate
   // these by hand.