Index: cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td =================================================================== --- cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td +++ cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td @@ -214,4 +214,7 @@ "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; +} \ No newline at end of file Index: cfe/trunk/include/clang/Driver/CC1Options.td =================================================================== --- cfe/trunk/include/clang/Driver/CC1Options.td +++ cfe/trunk/include/clang/Driver/CC1Options.td @@ -664,31 +664,6 @@ 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 //===----------------------------------------------------------------------===// Index: cfe/trunk/include/clang/Driver/Options.td =================================================================== --- cfe/trunk/include/clang/Driver/Options.td +++ cfe/trunk/include/clang/Driver/Options.td @@ -78,6 +78,7 @@ def i_Group : OptionGroup<"">, Group; def clang_i_Group : OptionGroup<"">, Group; def m_Group : OptionGroup<"">, Group; +def opencl_Group : OptionGroup<"">, 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 bundle__loader : Separate<["-"], "bundle_loader">; def bundle : Flag<["-"], "bundle">; def b : JoinedOrSeparate<["-"], "b">, Flags<[Unsupported]>; +def cl_opt_disable : Flag<["-"], "cl-opt-disable">, 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, 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, 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, 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, Flags<[CC1Option]>, + HelpText<"OpenCL only. Generate kernel argument metadata.">; +def cl_unsafe_math_optimizations : Flag<["-"], "cl-unsafe-math-optimizations">, 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, 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, Flags<[CC1Option]>, + HelpText<"OpenCL only. Allow use of less precise MAD computations in the generated binary.">; +def cl_std_EQ : Joined<["-"], "cl-std=">, Group, Flags<[CC1Option]>, + HelpText<"OpenCL language standard to compile for.">; +def cl_denorms_are_zero : Flag<["-"], "cl-denorms-are-zero">, 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">; Index: cfe/trunk/lib/Driver/Tools.cpp =================================================================== --- cfe/trunk/lib/Driver/Tools.cpp +++ cfe/trunk/lib/Driver/Tools.cpp @@ -5109,6 +5109,40 @@ 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)) { Index: cfe/trunk/lib/Frontend/CompilerInvocation.cpp =================================================================== --- cfe/trunk/lib/Frontend/CompilerInvocation.cpp +++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp @@ -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 #include #include @@ -1671,6 +1672,18 @@ 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); Index: cfe/trunk/test/Driver/opencl.cl =================================================================== --- cfe/trunk/test/Driver/opencl.cl +++ cfe/trunk/test/Driver/opencl.cl @@ -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);