From: Saleem Abdulrasool Date: Tue, 29 Aug 2017 23:59:07 +0000 (+0000) Subject: Driver: refactor OpenCL argument forwarding X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fb4868312dc83ddf28511c15a6f3f8844d146641;p=clang Driver: refactor OpenCL argument forwarding 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 --- diff --git a/lib/Driver/ToolChains/Clang.cpp b/lib/Driver/ToolChains/Clang.cpp index e18a9413f2..c941cf8063 100644 --- a/lib/Driver/ToolChains/Clang.cpp +++ b/lib/Driver/ToolChains/Clang.cpp @@ -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.