r274150 - [OpenCL] Allow -cl-std and other standard -cl- options in driver

Liu, Yaxun (Sam) via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 30 08:44:12 PDT 2016


We will take a look. Thanks.

Sam

-----Original Message-----
From: Benjamin Kramer [mailto:benny.kra at gmail.com] 
Sent: Thursday, June 30, 2016 5:27 AM
To: Liu, Yaxun (Sam) <Yaxun.Liu at amd.com>; Shi, Aaron (en ye) <Aaronenye.Shi at amd.com>; anastasia.stulova at arm.com
Cc: cfe-commits <cfe-commits at lists.llvm.org>
Subject: Re: r274150 - [OpenCL] Allow -cl-std and other standard -cl- options in driver

The opencl.cl test never ran due to a lit misconfiguration (see r274221). Now that's fixed but the test doesn't pass, so I marked it as XFAIL. Can you take a look?

On Wed, Jun 29, 2016 at 9:39 PM, Yaxun Liu via cfe-commits <cfe-commits at lists.llvm.org> wrote:
> Author: yaxunl
> Date: Wed Jun 29 14:39:32 2016
> New Revision: 274150
>
> URL: http://llvm.org/viewvc/llvm-project?rev=274150&view=rev
> Log:
> [OpenCL] Allow -cl-std and other standard -cl- options in driver
>
> Allow -cl-std and other standard -cl- options from cc1 to driver.
>
> Added a test for the options moved.
>
> Patch by Aaron En Ye Shi.
>
> Differential Revision: http://reviews.llvm.org/D21031
>
> Modified:
>     cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td
>     cfe/trunk/include/clang/Driver/CC1Options.td
>     cfe/trunk/include/clang/Driver/Options.td
>     cfe/trunk/lib/Driver/Tools.cpp
>     cfe/trunk/lib/Frontend/CompilerInvocation.cpp
>     cfe/trunk/test/Driver/opencl.cl
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Diag
> nosticFrontendKinds.td?rev=274150&r1=274149&r2=274150&view=diff
> ======================================================================
> ========
> --- cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td 
> (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td Wed Jun 
> +++ 29 14:39:32 2016
> @@ -214,4 +214,7 @@ def err_missing_vfs_overlay_file : Error
>    "virtual filesystem overlay file '%0' not found">, DefaultFatal;  
> def err_invalid_vfs_overlay : Error<
>    "invalid virtual filesystem overlay file '%0'">, DefaultFatal; -}
> +
> +def warn_option_invalid_ocl_version : Warning<
> +  "OpenCL version %0 does not support the option '%1'">, 
> +InGroup<Deprecated>; }
> \ No newline at end of file
>
> Modified: cfe/trunk/include/clang/Driver/CC1Options.td
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1
> Options.td?rev=274150&r1=274149&r2=274150&view=diff
> ======================================================================
> ========
> --- cfe/trunk/include/clang/Driver/CC1Options.td (original)
> +++ cfe/trunk/include/clang/Driver/CC1Options.td Wed Jun 29 14:39:32 
> +++ 2016
> @@ -664,31 +664,6 @@ def detailed_preprocessing_record : Flag
>    HelpText<"include a detailed record of preprocessing actions">;
>
>  
> //===-----------------------------------------------------------------
> -----===//
> -// OpenCL Options
> -//===----------------------------------------------------------------
> ------===//
> -
> -def cl_opt_disable : Flag<["-"], "cl-opt-disable">,
> -  HelpText<"OpenCL only. This option disables all optimizations. The 
> default is optimizations are enabled.">; -def cl_strict_aliasing : 
> Flag<["-"], "cl-strict-aliasing">,
> -  HelpText<"OpenCL only. This option does nothing and is for 
> compatibility with OpenCL 1.0">; -def cl_single_precision_constant : 
> Flag<["-"], "cl-single-precision-constant">,
> -  HelpText<"OpenCL only. Treat double precision floating-point 
> constant as single precision constant.">; -def cl_finite_math_only : 
> Flag<["-"], "cl-finite-math-only">,
> -  HelpText<"OpenCL only. Allow floating-point optimizations that 
> assume arguments and results are not NaNs or +-Inf.">; -def 
> cl_kernel_arg_info : Flag<["-"], "cl-kernel-arg-info">,
> -  HelpText<"OpenCL only. Generate kernel argument metadata.">; -def 
> cl_unsafe_math_optimizations : Flag<["-"], 
> "cl-unsafe-math-optimizations">,
> -  HelpText<"OpenCL only. Allow unsafe floating-point optimizations.  
> Also implies -cl-no-signed-zeros and -cl-mad-enable">; -def 
> cl_fast_relaxed_math : Flag<["-"], "cl-fast-relaxed-math">,
> -  HelpText<"OpenCL only. Sets -cl-finite-math-only and 
> -cl-unsafe-math-optimizations, and defines __FAST_RELAXED_MATH__">; 
> -def cl_mad_enable : Flag<["-"], "cl-mad-enable">,
> -  HelpText<"OpenCL only. Enable less precise MAD instructions to be 
> generated.">; -def cl_std_EQ : Joined<["-"], "cl-std=">,
> -  HelpText<"OpenCL language standard to compile for">; -def 
> cl_denorms_are_zero : Flag<["-"], "cl-denorms-are-zero">,
> -  HelpText<"OpenCL only. Allow denormals to be flushed to zero">;
> -
> -//===----------------------------------------------------------------
> ------===//
>  // CUDA Options
>  
> //===-----------------------------------------------------------------
> -----===//
>
>
> Modified: cfe/trunk/include/clang/Driver/Options.td
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Opt
> ions.td?rev=274150&r1=274149&r2=274150&view=diff
> ======================================================================
> ========
> --- cfe/trunk/include/clang/Driver/Options.td (original)
> +++ cfe/trunk/include/clang/Driver/Options.td Wed Jun 29 14:39:32 2016
> @@ -78,6 +78,7 @@ def g_flags_Group         : OptionGroup<
>  def i_Group               : OptionGroup<"<i group>">, Group<CompileOnly_Group>;
>  def clang_i_Group         : OptionGroup<"<clang i group>">, Group<i_Group>;
>  def m_Group               : OptionGroup<"<m group>">, Group<CompileOnly_Group>;
> +def opencl_Group          : OptionGroup<"<opencl group>">, Group<CompileOnly_Group>;
>
>  // Feature groups - these take command line options that correspond 
> directly to  // target specific features and can be translated 
> directly from command line @@ -366,6 +367,26 @@ def bind__at__load : 
> Flag<["-"], "bind_a  def bundle__loader : Separate<["-"], 
> "bundle_loader">;  def bundle : Flag<["-"], "bundle">;  def b : 
> JoinedOrSeparate<["-"], "b">, Flags<[Unsupported]>;
> +def cl_opt_disable : Flag<["-"], "cl-opt-disable">, 
> +Group<opencl_Group>, Flags<[CC1Option]>,
> +  HelpText<"OpenCL only. This option disables all optimizations. By 
> +default optimizations are enabled.">; def cl_strict_aliasing : 
> +Flag<["-"], "cl-strict-aliasing">, Group<opencl_Group>, 
> +Flags<[CC1Option]>,
> +  HelpText<"OpenCL only. This option is added for compatibility with 
> +OpenCL 1.0.">; def cl_single_precision_constant : Flag<["-"], 
> +"cl-single-precision-constant">, Group<opencl_Group>, 
> +Flags<[CC1Option]>,
> +  HelpText<"OpenCL only. Treat double precision floating-point 
> +constant as single precision constant.">; def cl_finite_math_only : 
> +Flag<["-"], "cl-finite-math-only">, Group<opencl_Group>, 
> +Flags<[CC1Option]>,
> +  HelpText<"OpenCL only. Allow floating-point optimizations that 
> +assume arguments and results are not NaNs or +-Inf.">; def 
> +cl_kernel_arg_info : Flag<["-"], "cl-kernel-arg-info">, 
> +Group<opencl_Group>, Flags<[CC1Option]>,
> +  HelpText<"OpenCL only. Generate kernel argument metadata.">; def 
> +cl_unsafe_math_optimizations : Flag<["-"], 
> +"cl-unsafe-math-optimizations">, Group<opencl_Group>, 
> +Flags<[CC1Option]>,
> +  HelpText<"OpenCL only. Allow unsafe floating-point optimizations.  
> +Also implies -cl-no-signed-zeros and -cl-mad-enable.">; def 
> +cl_fast_relaxed_math : Flag<["-"], "cl-fast-relaxed-math">, 
> +Group<opencl_Group>, Flags<[CC1Option]>,
> +  HelpText<"OpenCL only. Sets -cl-finite-math-only and 
> +-cl-unsafe-math-optimizations, and defines __FAST_RELAXED_MATH__.">; 
> +def cl_mad_enable : Flag<["-"], "cl-mad-enable">, 
> +Group<opencl_Group>, Flags<[CC1Option]>,
> +  HelpText<"OpenCL only. Allow use of less precise MAD computations 
> +in the generated binary.">; def cl_std_EQ : Joined<["-"], "cl-std=">, 
> +Group<opencl_Group>, Flags<[CC1Option]>,
> +  HelpText<"OpenCL language standard to compile for.">; def 
> +cl_denorms_are_zero : Flag<["-"], "cl-denorms-are-zero">, 
> +Group<opencl_Group>, Flags<[CC1Option]>,
> +  HelpText<"OpenCL only. Allow denormals to be flushed to zero.">;
>  def client__name : JoinedOrSeparate<["-"], "client_name">;  def 
> combine : Flag<["-", "--"], "combine">, Flags<[DriverOption, 
> Unsupported]>;  def compatibility__version : JoinedOrSeparate<["-"], 
> "compatibility_version">;
>
> Modified: cfe/trunk/lib/Driver/Tools.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev
> =274150&r1=274149&r2=274150&view=diff
> ======================================================================
> ========
> --- cfe/trunk/lib/Driver/Tools.cpp (original)
> +++ cfe/trunk/lib/Driver/Tools.cpp Wed Jun 29 14:39:32 2016
> @@ -5109,6 +5109,40 @@ void Clang::ConstructJob(Compilation &C,
>      CmdArgs.push_back("-arm-restrict-it");
>    }
>
> +  // 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 (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");
> +  }
> +
>    // Forward -f options with positive and negative forms; we translate
>    // these by hand.
>    if (Arg *A = Args.getLastArg(options::OPT_fprofile_sample_use_EQ)) 
> {
>
> Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInv
> ocation.cpp?rev=274150&r1=274149&r2=274150&view=diff
> ======================================================================
> ========
> --- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
> +++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Wed Jun 29 14:39:32 
> +++ 2016
> @@ -41,6 +41,7 @@
>  #include "llvm/Support/Path.h"
>  #include "llvm/Support/Process.h"
>  #include "llvm/Target/TargetOptions.h"
> +#include "llvm/Support/ScopedPrinter.h"
>  #include <atomic>
>  #include <memory>
>  #include <sys/stat.h>
> @@ -1671,6 +1672,18 @@ static void ParseLangArgs(LangOptions &O
>        LangStd = OpenCLLangStd;
>    }
>
> +  // -cl-strict-aliasing needs to emit diagnostic in the case where CL > 1.0.
> +  // This option should be deprecated for CL > 1.0 because  // this 
> + option was added for compatibility with OpenCL 1.0.
> +  if (const Arg *A = Args.getLastArg(OPT_cl_strict_aliasing))
> +    if (Opts.OpenCLVersion > 100) {
> +      std::string VerSpec = llvm::to_string(Opts.OpenCLVersion / 100) +
> +                            std::string (".") +
> +                            llvm::to_string((Opts.OpenCLVersion % 100) / 10);
> +      Diags.Report(diag::warn_option_invalid_ocl_version)
> +      << VerSpec << A->getAsString(Args);
> +    }
> +
>    Opts.IncludeDefaultHeader = 
> Args.hasArg(OPT_finclude_default_header);
>
>    llvm::Triple T(TargetOpts.Triple);
>
> Modified: cfe/trunk/test/Driver/opencl.cl
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/opencl.cl?re
> v=274150&r1=274149&r2=274150&view=diff
> ======================================================================
> ========
> --- cfe/trunk/test/Driver/opencl.cl (original)
> +++ cfe/trunk/test/Driver/opencl.cl Wed Jun 29 14:39:32 2016
> @@ -1,15 +1,39 @@
> -// RUN: %clang -fsyntax-only %s
> -// RUN: %clang -fsyntax-only -std=cl %s -// RUN: %clang -fsyntax-only 
> -std=cl1.1 %s -// RUN: %clang -fsyntax-only -std=cl1.2 %s -// RUN: 
> %clang -fsyntax-only -std=cl2.0 %s -// RUN: %clang -fsyntax-only 
> -std=CL %s -// RUN: %clang -fsyntax-only -std=CL1.1 %s -// RUN: %clang 
> -fsyntax-only -std=CL1.2 %s -// RUN: %clang -fsyntax-only -std=CL2.0 
> %s -// RUN: not %clang_cc1 -std=c99 -DOPENCL %s 2>&1 | FileCheck 
> --check-prefix=CHECK-C99 %s -// RUN: not %clang_cc1 -std=invalid 
> -DOPENCL %s 2>&1 | FileCheck --check-prefix=CHECK-INVALID %s -// 
> CHECK-C99: error: invalid argument '-std=c99' not allowed with 'OpenCL'
> -// CHECK-INVALID: error: invalid value 'invalid' in '-std=invalid'
> +// RUN: %clang -S -### -cl-std=CL %s | FileCheck 
> +--check-prefix=CHECK-CL %s // RUN: %clang -S -### -cl-std=CL1.1 %s | 
> +FileCheck --check-prefix=CHECK-CL11 %s // RUN: %clang -S -### 
> +-cl-std=CL1.2 %s | FileCheck --check-prefix=CHECK-CL12 %s // RUN: 
> +%clang -S -### -cl-std=CL2.0 %s | FileCheck --check-prefix=CHECK-CL20 
> +%s // RUN: %clang -S -### -cl-opt-disable %s | FileCheck 
> +--check-prefix=CHECK-OPT-DISABLE %s // RUN: %clang -S -### 
> +-cl-strict-aliasing %s | FileCheck 
> +--check-prefix=CHECK-STRICT-ALIASING %s // RUN: %clang -S -### 
> +-cl-std=CL1.1 -cl-strict-aliasing %s | FileCheck 
> +--check-prefix=CHECK-INVALID-OPENCL-VERSION11 %s // RUN: %clang -S 
> +-### -cl-std=CL1.2 -cl-strict-aliasing %s | FileCheck 
> +--check-prefix=CHECK-INVALID-OPENCL-VERSION12 %s // RUN: %clang -S 
> +-### -cl-std=CL2.0 -cl-strict-aliasing %s | FileCheck 
> +--check-prefix=CHECK-INVALID-OPENCL-VERSION20 %s // RUN: %clang -S 
> +-### -cl-single-precision-constant %s | FileCheck 
> +--check-prefix=CHECK-SINGLE-PRECISION-CONST %s // RUN: %clang -S -### 
> +-cl-finite-math-only %s | FileCheck 
> +--check-prefix=CHECK-FINITE-MATH-ONLY %s // RUN: %clang -S -### 
> +-cl-kernel-arg-info %s | FileCheck 
> +--check-prefix=CHECK-KERNEL-ARG-INFO %s // RUN: %clang -S -### 
> +-cl-unsafe-math-optimizations %s | FileCheck 
> +--check-prefix=CHECK-UNSAFE-MATH-OPT %s // RUN: %clang -S -### 
> +-cl-fast-relaxed-math %s | FileCheck 
> +--check-prefix=CHECK-FAST-RELAXED-MATH %s // RUN: %clang -S -### 
> +-cl-mad-enable %s | FileCheck --check-prefix=CHECK-MAD-ENABLE %s // 
> +RUN: %clang -S -### -cl-denorms-are-zero %s | FileCheck 
> +--check-prefix=CHECK-DENORMS-ARE-ZERO %s // RUN: not %clang_cc1 
> +-cl-std=c99 -DOPENCL %s 2>&1 | FileCheck --check-prefix=CHECK-C99 %s 
> +// RUN: not %clang_cc1 -cl-std=invalid -DOPENCL %s 2>&1 | FileCheck 
> +--check-prefix=CHECK-INVALID %s
> +
> +// CHECK-CL: .*clang.* "-cc1" .* "-cl-std=CL"
> +// CHECK-CL11: .*clang.* "-cc1" .* "-cl-std=CL1.1"
> +// CHECK-CL12: .*clang.* "-cc1" .* "-cl-std=CL1.2"
> +// CHECK-CL20: .*clang.* "-cc1" .* "-cl-std=CL2.0"
> +// CHECK-OPT-DISABLE: .*clang.* "-cc1" .* "-cl-opt-disable"
> +// CHECK-STRICT-ALIASING: .*clang.* "-cc1" .* "-cl-strict-aliasing"
> +// CHECK-INVALID-OPENCL-VERSION11: OpenCL version 1.1 does not support the option 'cl-strict-aliasing'
> +// CHECK-INVALID-OPENCL-VERSION12: OpenCL version 1.2 does not support the option 'cl-strict-aliasing'
> +// CHECK-INVALID-OPENCL-VERSION20: OpenCL version 2.0 does not support the option 'cl-strict-aliasing'
> +// CHECK-SINGLE-PRECISION-CONST: .*clang.* "-cc1" .* "-cl-single-precision-constant"
> +// CHECK-FINITE-MATH-ONLY: .*clang.* "-cc1" .* "-cl-finite-math-only"
> +// CHECK-KERNEL-ARG-INFO: .*clang.* "-cc1" .* "-cl-kernel-arg-info"
> +// CHECK-UNSAFE-MATH-OPT: .*clang.* "-cc1" .* "-cl-unsafe-math-optimizations"
> +// CHECK-FAST-RELAXED-MATH: .*clang.* "-cc1" .* "-cl-fast-relaxed-math"
> +// CHECK-MAD-ENABLE: .*clang.* "-cc1" .* "-cl-mad-enable"
> +// CHECK-DENORMS-ARE-ZERO: .*clang.* "-cc1" .* "-cl-denorms-are-zero"
> +// CHECK-C99: error: invalid argument '-cl-std=c99' not allowed with 'OpenCL'
> +// CHECK-INVALID: error: invalid value 'invalid' in '-cl-std=invalid'
>
>  kernel void func(void);
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


More information about the cfe-commits mailing list