On Tue, Nov 16, 2010 at 10:51:16PM +0000, Peter Collingbourne wrote: > Hi, > > This patch series adds Clang support for all build options listed > in section 5.6.3 of the OpenCL 1.1 specification, except for > -cl-denorms-are-zero and -cl-no-signed-zeros, which (as far as I can > tell) do not have a counterpart in LLVM/Clang. > > Note that the patches only modify the frontend and not the driver. > This was simply because I did not require driver support (I use the > frontend directly in my OpenCL implementation, and I suspect other > implementations do not need the driver either). Is it fine to add > frontend-only support for now? > > The patches build on my earlier setLangDefaults patch [1]. Please > let me know if you would like a series that does not build on this > patch. > > OK to commit?
Ping. I also added a test case to patch 3. Thanks, -- Peter
>From 6670819676e15d6d8353928b4086ff7f0259c26c Mon Sep 17 00:00:00 2001 From: Peter Collingbourne <[email protected]> Date: Tue, 16 Nov 2010 16:39:29 +0000 Subject: [PATCH 1/8] Refactor optimisation level code --- lib/Frontend/CompilerInvocation.cpp | 29 +++++++++++++++-------------- 1 files changed, 15 insertions(+), 14 deletions(-) diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index d507c4e..66a8d2e 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -771,6 +771,12 @@ using namespace clang::driver::cc1options; // +static unsigned getOptimizationLevel(ArgList &Args, InputKind IK, + Diagnostic &Diags) { + // -Os implies -O2 + return Args.hasArg(OPT_Os) ? 2 : Args.getLastArgIntValue(OPT_O, 0, Diags); +} + static void ParseAnalyzerArgs(AnalyzerOptions &Opts, ArgList &Args, Diagnostic &Diags) { using namespace cc1options; @@ -848,19 +854,15 @@ static void ParseAnalyzerArgs(AnalyzerOptions &Opts, ArgList &Args, Opts.IdempotentOps = Args.hasArg(OPT_analysis_WarnIdempotentOps); } -static void ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, +static void ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, Diagnostic &Diags) { using namespace cc1options; - // -Os implies -O2 - if (Args.hasArg(OPT_Os)) - Opts.OptimizationLevel = 2; - else { - Opts.OptimizationLevel = Args.getLastArgIntValue(OPT_O, 0, Diags); - if (Opts.OptimizationLevel > 3) { - Diags.Report(diag::err_drv_invalid_value) - << Args.getLastArg(OPT_O)->getAsString(Args) << Opts.OptimizationLevel; - Opts.OptimizationLevel = 3; - } + + Opts.OptimizationLevel = getOptimizationLevel(Args, IK, Diags); + if (Opts.OptimizationLevel > 3) { + Diags.Report(diag::err_drv_invalid_value) + << Args.getLastArg(OPT_O)->getAsString(Args) << Opts.OptimizationLevel; + Opts.OptimizationLevel = 3; } // We must always run at least the always inlining pass. @@ -1407,8 +1409,7 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK, Opts.OptimizeSize = 0; // FIXME: Eliminate this dependency. - unsigned Opt = - Args.hasArg(OPT_Os) ? 2 : Args.getLastArgIntValue(OPT_O, 0, Diags); + unsigned Opt = getOptimizationLevel(Args, IK, Diags); Opts.Optimize = Opt != 0; // This is the __NO_INLINE__ define, which just depends on things like the @@ -1562,11 +1563,11 @@ void CompilerInvocation::CreateFromArgs(CompilerInvocation &Res, Diags.Report(diag::err_drv_unknown_argument) << (*it)->getAsString(*Args); ParseAnalyzerArgs(Res.getAnalyzerOpts(), *Args, Diags); - ParseCodeGenArgs(Res.getCodeGenOpts(), *Args, Diags); ParseDependencyOutputArgs(Res.getDependencyOutputOpts(), *Args); ParseDiagnosticArgs(Res.getDiagnosticOpts(), *Args, Diags); ParseFileSystemArgs(Res.getFileSystemOpts(), *Args); InputKind DashX = ParseFrontendArgs(Res.getFrontendOpts(), *Args, Diags); + ParseCodeGenArgs(Res.getCodeGenOpts(), *Args, DashX, Diags); ParseHeaderSearchArgs(Res.getHeaderSearchOpts(), *Args); if (DashX != IK_AST && DashX != IK_LLVM_IR) ParseLangArgs(Res.getLangOpts(), *Args, DashX, Diags); -- 1.7.1
>From eace1ee612cb22c19650990b57a99b7a5bb69d5e Mon Sep 17 00:00:00 2001 From: Peter Collingbourne <[email protected]> Date: Tue, 16 Nov 2010 18:32:18 +0000 Subject: [PATCH 2/8] Implement -cl-opt-disable --- include/clang/Driver/CC1Options.td | 7 +++++++ lib/Frontend/CompilerInvocation.cpp | 6 +++++- test/CodeGen/ext-vector-shuffle.c | 6 +++--- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/include/clang/Driver/CC1Options.td b/include/clang/Driver/CC1Options.td index 03a4dd9..27db9cf 100644 --- a/include/clang/Driver/CC1Options.td +++ b/include/clang/Driver/CC1Options.td @@ -592,3 +592,10 @@ def dD : Flag<"-dD">, HelpText<"Print macro definitions in -E mode in addition to normal output">; def H : Flag<"-H">, HelpText<"Show header includes and nesting depth">; + +//===----------------------------------------------------------------------===// +// OpenCL Options +//===----------------------------------------------------------------------===// + +def cl_opt_disable : Flag<"-cl-opt-disable">, + HelpText<"OpenCL only. This option disables all optimizations. The default is optimizations are enabled.">; diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 66a8d2e..587fbb4 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -774,7 +774,11 @@ using namespace clang::driver::cc1options; static unsigned getOptimizationLevel(ArgList &Args, InputKind IK, Diagnostic &Diags) { // -Os implies -O2 - return Args.hasArg(OPT_Os) ? 2 : Args.getLastArgIntValue(OPT_O, 0, Diags); + unsigned DefaultOpt = 0; + if (IK == IK_OpenCL && !Args.hasArg(OPT_cl_opt_disable)) + DefaultOpt = 2; + return Args.hasArg(OPT_Os) ? 2 : + Args.getLastArgIntValue(OPT_O, DefaultOpt, Diags); } static void ParseAnalyzerArgs(AnalyzerOptions &Opts, ArgList &Args, diff --git a/test/CodeGen/ext-vector-shuffle.c b/test/CodeGen/ext-vector-shuffle.c index 1d147a3..d26602a 100644 --- a/test/CodeGen/ext-vector-shuffle.c +++ b/test/CodeGen/ext-vector-shuffle.c @@ -1,6 +1,6 @@ -// RUN: %clang_cc1 %s -x cl -emit-llvm -o - | not grep 'extractelement' -// RUN: %clang_cc1 %s -x cl -emit-llvm -o - | not grep 'insertelement' -// RUN: %clang_cc1 %s -x cl -emit-llvm -o - | grep 'shufflevector' +// RUN: %clang_cc1 %s -x cl -cl-opt-disable -emit-llvm -o - | not grep 'extractelement' +// RUN: %clang_cc1 %s -x cl -cl-opt-disable -emit-llvm -o - | not grep 'insertelement' +// RUN: %clang_cc1 %s -x cl -cl-opt-disable -emit-llvm -o - | grep 'shufflevector' typedef __attribute__(( ext_vector_type(2) )) float float2; typedef __attribute__(( ext_vector_type(4) )) float float4; -- 1.7.1
>From 1e6a35410408eb3d0d6a0c10479b0dd20b8e2f77 Mon Sep 17 00:00:00 2001 From: Peter Collingbourne <[email protected]> Date: Tue, 16 Nov 2010 18:44:55 +0000 Subject: [PATCH 3/8] Implement -cl-single-precision-constant --- include/clang/Basic/LangOptions.h | 4 ++++ include/clang/Driver/CC1Options.td | 2 ++ lib/Frontend/CompilerInvocation.cpp | 1 + lib/Sema/SemaExpr.cpp | 3 +++ test/CodeGen/cl-single-precision-constant.c | 7 +++++++ 5 files changed, 17 insertions(+), 0 deletions(-) create mode 100644 test/CodeGen/cl-single-precision-constant.c diff --git a/include/clang/Basic/LangOptions.h b/include/clang/Basic/LangOptions.h index 2fef7ba..12cfec3 100644 --- a/include/clang/Basic/LangOptions.h +++ b/include/clang/Basic/LangOptions.h @@ -109,6 +109,9 @@ public: unsigned SpellChecking : 1; // Whether to perform spell-checking for error // recovery. + unsigned SinglePrecisionConstants : 1; // Whether to treat double-precision + // floating point constants as + // single precision constants. // FIXME: This is just a temporary option, for testing purposes. unsigned NoBitFieldTypeAlign : 1; @@ -195,6 +198,7 @@ public: DumpRecordLayouts = 0; DumpVTableLayouts = 0; SpellChecking = 1; + SinglePrecisionConstants = 0; NoBitFieldTypeAlign = 0; } diff --git a/include/clang/Driver/CC1Options.td b/include/clang/Driver/CC1Options.td index 27db9cf..eab473b 100644 --- a/include/clang/Driver/CC1Options.td +++ b/include/clang/Driver/CC1Options.td @@ -599,3 +599,5 @@ def H : Flag<"-H">, def cl_opt_disable : Flag<"-cl-opt-disable">, HelpText<"OpenCL only. This option disables all optimizations. The default is optimizations are enabled.">; +def cl_single_precision_constant : Flag<"-cl-single-precision-constant">, + HelpText<"OpenCL only. Treat double precision floating-point constant as single precision constant.">; diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 587fbb4..acd106e 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -1410,6 +1410,7 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK, Opts.DumpVTableLayouts = Args.hasArg(OPT_fdump_vtable_layouts); Opts.SpellChecking = !Args.hasArg(OPT_fno_spell_checking); Opts.NoBitFieldTypeAlign = Args.hasArg(OPT_fno_bitfield_type_align); + Opts.SinglePrecisionConstants = Args.hasArg(OPT_cl_single_precision_constant); Opts.OptimizeSize = 0; // FIXME: Eliminate this dependency. diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index e802540..c2475f8 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -2381,6 +2381,9 @@ ExprResult Sema::ActOnNumericConstant(const Token &Tok) { bool isExact = (result == APFloat::opOK); Res = FloatingLiteral::Create(Context, Val, isExact, Ty, Tok.getLocation()); + if (getLangOptions().SinglePrecisionConstants && Ty == Context.DoubleTy) + ImpCastExprToType(Res, Context.FloatTy, CK_FloatingCast); + } else if (!Literal.isIntegerLiteral()) { return ExprError(); } else { diff --git a/test/CodeGen/cl-single-precision-constant.c b/test/CodeGen/cl-single-precision-constant.c new file mode 100644 index 0000000..adde193 --- /dev/null +++ b/test/CodeGen/cl-single-precision-constant.c @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 %s -x cl -cl-single-precision-constant -emit-llvm -o - | FileCheck %s + +float fn(float f) { + // CHECK: fmul float + // CHECK: fadd float + return f*2. + 1.; +} -- 1.7.1
>From de196d21c4b498da16901a27e8b233b3bb10e651 Mon Sep 17 00:00:00 2001 From: Peter Collingbourne <[email protected]> Date: Tue, 16 Nov 2010 20:24:58 +0000 Subject: [PATCH 4/8] Implement -cl-finite-math-only --- include/clang/Driver/CC1Options.td | 2 ++ include/clang/Frontend/CodeGenOptions.h | 4 ++++ lib/CodeGen/BackendUtil.cpp | 2 ++ lib/Frontend/CompilerInvocation.cpp | 1 + 4 files changed, 9 insertions(+), 0 deletions(-) diff --git a/include/clang/Driver/CC1Options.td b/include/clang/Driver/CC1Options.td index eab473b..19d3a24 100644 --- a/include/clang/Driver/CC1Options.td +++ b/include/clang/Driver/CC1Options.td @@ -601,3 +601,5 @@ def cl_opt_disable : Flag<"-cl-opt-disable">, HelpText<"OpenCL only. This option disables all optimizations. The default is optimizations are enabled.">; 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.">; diff --git a/include/clang/Frontend/CodeGenOptions.h b/include/clang/Frontend/CodeGenOptions.h index 171cfd9..3ca3104 100644 --- a/include/clang/Frontend/CodeGenOptions.h +++ b/include/clang/Frontend/CodeGenOptions.h @@ -59,6 +59,8 @@ public: unsigned MergeAllConstants : 1; /// Merge identical constants. unsigned NoCommon : 1; /// Set when -fno-common or C++ is enabled. unsigned NoImplicitFloat : 1; /// Set when -mno-implicit-float is enabled. + unsigned NoInfsFPMath : 1; /// Assume FP arguments, results not +-Inf. + unsigned NoNaNsFPMath : 1; /// Assume FP arguments, results not NaN. unsigned NoZeroInitializedInBSS : 1; /// -fno-zero-initialized-in-bss unsigned ObjCDispatchMethod : 2; /// Method of Objective-C dispatch to use. unsigned OmitLeafFramePointer : 1; /// Set when -momit-leaf-frame-pointer is @@ -123,6 +125,8 @@ public: MergeAllConstants = 1; NoCommon = 0; NoImplicitFloat = 0; + NoInfsFPMath = 0; + NoNaNsFPMath = 0; NoZeroInitializedInBSS = 0; ObjCDispatchMethod = Legacy; OmitLeafFramePointer = 0; diff --git a/lib/CodeGen/BackendUtil.cpp b/lib/CodeGen/BackendUtil.cpp index 82b4b50..ad70b60 100644 --- a/lib/CodeGen/BackendUtil.cpp +++ b/lib/CodeGen/BackendUtil.cpp @@ -183,6 +183,8 @@ bool EmitAssemblyHelper::AddEmitPasses(BackendAction Action, llvm::FloatABIType = llvm::FloatABI::Default; } + llvm::NoInfsFPMath = CodeGenOpts.NoInfsFPMath; + llvm::NoNaNsFPMath = CodeGenOpts.NoNaNsFPMath; NoZerosInBSS = CodeGenOpts.NoZeroInitializedInBSS; llvm::UseSoftFloat = CodeGenOpts.SoftFloat; UnwindTablesMandatory = CodeGenOpts.UnwindTables; diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index acd106e..75637c9 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -897,6 +897,7 @@ static void ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, Opts.FloatABI = Args.getLastArgValue(OPT_mfloat_abi); Opts.HiddenWeakVTables = Args.hasArg(OPT_fhidden_weak_vtables); Opts.LimitFloatPrecision = Args.getLastArgValue(OPT_mlimit_float_precision); + Opts.NoInfsFPMath = Opts.NoNaNsFPMath = Args.hasArg(OPT_cl_finite_math_only); Opts.NoZeroInitializedInBSS = Args.hasArg(OPT_mno_zero_initialized_in_bss); Opts.RelaxAll = Args.hasArg(OPT_mrelax_all); Opts.OmitLeafFramePointer = Args.hasArg(OPT_momit_leaf_frame_pointer); -- 1.7.1
>From 6bcb3b68d5a30828d7e6e9ddce8857e73a284943 Mon Sep 17 00:00:00 2001 From: Peter Collingbourne <[email protected]> Date: Tue, 16 Nov 2010 21:18:25 +0000 Subject: [PATCH 5/8] Implement -cl-unsafe-math-optimizations --- include/clang/Driver/CC1Options.td | 2 ++ include/clang/Frontend/CodeGenOptions.h | 2 ++ lib/CodeGen/BackendUtil.cpp | 1 + lib/Frontend/CompilerInvocation.cpp | 1 + 4 files changed, 6 insertions(+), 0 deletions(-) diff --git a/include/clang/Driver/CC1Options.td b/include/clang/Driver/CC1Options.td index 19d3a24..a7b2692 100644 --- a/include/clang/Driver/CC1Options.td +++ b/include/clang/Driver/CC1Options.td @@ -603,3 +603,5 @@ 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_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">; diff --git a/include/clang/Frontend/CodeGenOptions.h b/include/clang/Frontend/CodeGenOptions.h index 3ca3104..84f5003 100644 --- a/include/clang/Frontend/CodeGenOptions.h +++ b/include/clang/Frontend/CodeGenOptions.h @@ -75,6 +75,7 @@ public: unsigned UnitAtATime : 1; /// Unused. For mirroring GCC optimization /// selection. unsigned UnrollLoops : 1; /// Control whether loops are unrolled. + unsigned UnsafeFPMath : 1; /// Allow unsafe floating point optzns. unsigned UnwindTables : 1; /// Emit unwind tables. unsigned VerifyModule : 1; /// Control whether the module should be run /// through the LLVM Verifier. @@ -139,6 +140,7 @@ public: TimePasses = 0; UnitAtATime = 1; UnrollLoops = 0; + UnsafeFPMath = 0; UnwindTables = 0; VerifyModule = 1; diff --git a/lib/CodeGen/BackendUtil.cpp b/lib/CodeGen/BackendUtil.cpp index ad70b60..2808b4a 100644 --- a/lib/CodeGen/BackendUtil.cpp +++ b/lib/CodeGen/BackendUtil.cpp @@ -186,6 +186,7 @@ bool EmitAssemblyHelper::AddEmitPasses(BackendAction Action, llvm::NoInfsFPMath = CodeGenOpts.NoInfsFPMath; llvm::NoNaNsFPMath = CodeGenOpts.NoNaNsFPMath; NoZerosInBSS = CodeGenOpts.NoZeroInitializedInBSS; + llvm::UnsafeFPMath = CodeGenOpts.UnsafeFPMath; llvm::UseSoftFloat = CodeGenOpts.SoftFloat; UnwindTablesMandatory = CodeGenOpts.UnwindTables; diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 75637c9..bee4868 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -902,6 +902,7 @@ static void ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, Opts.RelaxAll = Args.hasArg(OPT_mrelax_all); Opts.OmitLeafFramePointer = Args.hasArg(OPT_momit_leaf_frame_pointer); Opts.SoftFloat = Args.hasArg(OPT_msoft_float); + Opts.UnsafeFPMath = Args.hasArg(OPT_cl_unsafe_math_optimizations); Opts.UnwindTables = Args.hasArg(OPT_munwind_tables); Opts.RelocationModel = Args.getLastArgValue(OPT_mrelocation_model, "pic"); -- 1.7.1
>From 1ecb16c67214260b18774c4f7158ff57027fe48d Mon Sep 17 00:00:00 2001 From: Peter Collingbourne <[email protected]> Date: Tue, 16 Nov 2010 21:49:42 +0000 Subject: [PATCH 6/8] Implement -cl-fast-relaxed-math --- include/clang/Basic/LangOptions.h | 3 +++ include/clang/Driver/CC1Options.td | 2 ++ lib/Frontend/CompilerInvocation.cpp | 7 +++++-- lib/Frontend/InitPreprocessor.cpp | 3 +++ 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/include/clang/Basic/LangOptions.h b/include/clang/Basic/LangOptions.h index 12cfec3..424fdfe 100644 --- a/include/clang/Basic/LangOptions.h +++ b/include/clang/Basic/LangOptions.h @@ -112,6 +112,8 @@ public: unsigned SinglePrecisionConstants : 1; // Whether to treat double-precision // floating point constants as // single precision constants. + unsigned FastRelaxedMath : 1; // OpenCL fast relaxed math (on its own, + // defines __FAST_RELAXED_MATH__). // FIXME: This is just a temporary option, for testing purposes. unsigned NoBitFieldTypeAlign : 1; @@ -199,6 +201,7 @@ public: DumpVTableLayouts = 0; SpellChecking = 1; SinglePrecisionConstants = 0; + FastRelaxedMath = 0; NoBitFieldTypeAlign = 0; } diff --git a/include/clang/Driver/CC1Options.td b/include/clang/Driver/CC1Options.td index a7b2692..13919aa 100644 --- a/include/clang/Driver/CC1Options.td +++ b/include/clang/Driver/CC1Options.td @@ -605,3 +605,5 @@ 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_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__">; diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index bee4868..29018aa 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -897,12 +897,14 @@ static void ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, Opts.FloatABI = Args.getLastArgValue(OPT_mfloat_abi); Opts.HiddenWeakVTables = Args.hasArg(OPT_fhidden_weak_vtables); Opts.LimitFloatPrecision = Args.getLastArgValue(OPT_mlimit_float_precision); - Opts.NoInfsFPMath = Opts.NoNaNsFPMath = Args.hasArg(OPT_cl_finite_math_only); + 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.RelaxAll = Args.hasArg(OPT_mrelax_all); Opts.OmitLeafFramePointer = Args.hasArg(OPT_momit_leaf_frame_pointer); Opts.SoftFloat = Args.hasArg(OPT_msoft_float); - Opts.UnsafeFPMath = Args.hasArg(OPT_cl_unsafe_math_optimizations); + Opts.UnsafeFPMath = Args.hasArg(OPT_cl_unsafe_math_optimizations) || + Args.hasArg(OPT_cl_fast_relaxed_math); Opts.UnwindTables = Args.hasArg(OPT_munwind_tables); Opts.RelocationModel = Args.getLastArgValue(OPT_mrelocation_model, "pic"); @@ -1413,6 +1415,7 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK, Opts.SpellChecking = !Args.hasArg(OPT_fno_spell_checking); Opts.NoBitFieldTypeAlign = Args.hasArg(OPT_fno_bitfield_type_align); Opts.SinglePrecisionConstants = Args.hasArg(OPT_cl_single_precision_constant); + Opts.FastRelaxedMath = Args.hasArg(OPT_cl_fast_relaxed_math); Opts.OptimizeSize = 0; // FIXME: Eliminate this dependency. diff --git a/lib/Frontend/InitPreprocessor.cpp b/lib/Frontend/InitPreprocessor.cpp index e3279c2..1f15556 100644 --- a/lib/Frontend/InitPreprocessor.cpp +++ b/lib/Frontend/InitPreprocessor.cpp @@ -469,6 +469,9 @@ static void InitializePredefinedMacros(const TargetInfo &TI, if (FEOpts.ProgramAction == frontend::RunAnalysis) Builder.defineMacro("__clang_analyzer__"); + if (LangOpts.FastRelaxedMath) + Builder.defineMacro("__FAST_RELAXED_MATH__"); + // Get other target #defines. TI.getTargetDefines(LangOpts, Builder); } -- 1.7.1
>From 472a9ecb3fccb70235aaa98d580ac0a7c6d60c0c Mon Sep 17 00:00:00 2001 From: Peter Collingbourne <[email protected]> Date: Tue, 16 Nov 2010 22:01:04 +0000 Subject: [PATCH 7/8] Implement -cl-mad-enable --- include/clang/Driver/CC1Options.td | 2 ++ include/clang/Frontend/CodeGenOptions.h | 3 +++ lib/CodeGen/BackendUtil.cpp | 1 + lib/Frontend/CompilerInvocation.cpp | 1 + 4 files changed, 7 insertions(+), 0 deletions(-) diff --git a/include/clang/Driver/CC1Options.td b/include/clang/Driver/CC1Options.td index 13919aa..f34a484 100644 --- a/include/clang/Driver/CC1Options.td +++ b/include/clang/Driver/CC1Options.td @@ -607,3 +607,5 @@ 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.">; diff --git a/include/clang/Frontend/CodeGenOptions.h b/include/clang/Frontend/CodeGenOptions.h index 84f5003..52fb144 100644 --- a/include/clang/Frontend/CodeGenOptions.h +++ b/include/clang/Frontend/CodeGenOptions.h @@ -56,6 +56,8 @@ public: unsigned HiddenWeakVTables : 1; /// Emit weak vtables, RTTI, and thunks with /// hidden visibility unsigned InstrumentFunctions : 1; /// Set when -finstrument-functions is enabled + unsigned LessPreciseFPMAD : 1; /// Enable less precise MAD instructions to be + /// generated. unsigned MergeAllConstants : 1; /// Merge identical constants. unsigned NoCommon : 1; /// Set when -fno-common or C++ is enabled. unsigned NoImplicitFloat : 1; /// Set when -mno-implicit-float is enabled. @@ -123,6 +125,7 @@ public: HiddenWeakTemplateVTables = 0; HiddenWeakVTables = 0; InstrumentFunctions = 0; + LessPreciseFPMAD = 0; MergeAllConstants = 1; NoCommon = 0; NoImplicitFloat = 0; diff --git a/lib/CodeGen/BackendUtil.cpp b/lib/CodeGen/BackendUtil.cpp index 2808b4a..f12715a 100644 --- a/lib/CodeGen/BackendUtil.cpp +++ b/lib/CodeGen/BackendUtil.cpp @@ -183,6 +183,7 @@ bool EmitAssemblyHelper::AddEmitPasses(BackendAction Action, llvm::FloatABIType = llvm::FloatABI::Default; } + llvm::LessPreciseFPMADOption = CodeGenOpts.LessPreciseFPMAD; llvm::NoInfsFPMath = CodeGenOpts.NoInfsFPMath; llvm::NoNaNsFPMath = CodeGenOpts.NoNaNsFPMath; NoZerosInBSS = CodeGenOpts.NoZeroInitializedInBSS; diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 29018aa..c05ca27 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -896,6 +896,7 @@ static void ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, Opts.DisableFPElim = Args.hasArg(OPT_mdisable_fp_elim); Opts.FloatABI = Args.getLastArgValue(OPT_mfloat_abi); Opts.HiddenWeakVTables = Args.hasArg(OPT_fhidden_weak_vtables); + Opts.LessPreciseFPMAD = Args.hasArg(OPT_cl_mad_enable); Opts.LimitFloatPrecision = Args.getLastArgValue(OPT_mlimit_float_precision); Opts.NoInfsFPMath = Opts.NoNaNsFPMath = Args.hasArg(OPT_cl_finite_math_only)|| Args.hasArg(OPT_cl_fast_relaxed_math); -- 1.7.1
>From b622b78265786eac8cdb82d763917cb5458cc3f8 Mon Sep 17 00:00:00 2001 From: Peter Collingbourne <[email protected]> Date: Tue, 16 Nov 2010 22:28:46 +0000 Subject: [PATCH 8/8] Implement -cl-std= --- include/clang/Driver/CC1Options.td | 2 ++ lib/Frontend/CompilerInvocation.cpp | 7 +++++++ 2 files changed, 9 insertions(+), 0 deletions(-) diff --git a/include/clang/Driver/CC1Options.td b/include/clang/Driver/CC1Options.td index f34a484..28a31ca 100644 --- a/include/clang/Driver/CC1Options.td +++ b/include/clang/Driver/CC1Options.td @@ -609,3 +609,5 @@ 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">; diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index c05ca27..27e0525 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -1314,6 +1314,13 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK, << A->getAsString(Args) << A->getValue(Args); } + if (const Arg *A = Args.getLastArg(OPT_cl_std_EQ)) { + if (strcmp(A->getValue(Args), "CL1.1") != 0) { + Diags.Report(diag::err_drv_invalid_value) + << A->getAsString(Args) << A->getValue(Args); + } + } + CompilerInvocation::setLangDefaults(Opts, IK, LangStd); // We abuse '-f[no-]gnu-keywords' to force overriding all GNU-extension -- 1.7.1
_______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
