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? Thanks, -- Peter [1] http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20101025/035808.html
>From eb014f0d0d723f37f5f8dfb74ea78d76d943ed42 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 83b2dad..20f0843 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -770,6 +770,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; @@ -847,19 +853,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. @@ -1402,8 +1404,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 @@ -1559,11 +1560,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 d01e1d2fe17814af74201a3079ad866432ff9eb9 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 dee123d..fc8447e 100644 --- a/include/clang/Driver/CC1Options.td +++ b/include/clang/Driver/CC1Options.td @@ -585,3 +585,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 20f0843..40639c7 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -773,7 +773,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 3ddf5589fa12aaf227b015e0222d47869fc7fe14 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 +++ 4 files changed, 10 insertions(+), 0 deletions(-) diff --git a/include/clang/Basic/LangOptions.h b/include/clang/Basic/LangOptions.h index fe69067..16e0386 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; @@ -191,6 +194,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 fc8447e..51c8d4a 100644 --- a/include/clang/Driver/CC1Options.td +++ b/include/clang/Driver/CC1Options.td @@ -592,3 +592,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 40639c7..1d5ae13 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -1405,6 +1405,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 7555af3..33d4675 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -2317,6 +2317,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 { -- 1.7.1
>From 6944e86009f7850cb4d1ccb170b450ba5681a2e8 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 51c8d4a..a6166ec 100644 --- a/include/clang/Driver/CC1Options.td +++ b/include/clang/Driver/CC1Options.td @@ -594,3 +594,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 1d5ae13..fcae53d 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.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 d7eaff0caf95daaf50aa232626dbcbd08aa529ae 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 a6166ec..c7bd1e3 100644 --- a/include/clang/Driver/CC1Options.td +++ b/include/clang/Driver/CC1Options.td @@ -596,3 +596,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 fcae53d..c07c538 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -901,6 +901,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 a2fea65b732bd9a8accf6de075d1a13f19736155 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 16e0386..50c4ee2 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; @@ -195,6 +197,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 c7bd1e3..cdc3c66 100644 --- a/include/clang/Driver/CC1Options.td +++ b/include/clang/Driver/CC1Options.td @@ -598,3 +598,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 c07c538..70ca585 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -896,12 +896,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"); @@ -1408,6 +1410,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 7275733..53cd925 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 0cea792c6666feb01848af9c06d2fcd119c14e52 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 cdc3c66..78ad3c7 100644 --- a/include/clang/Driver/CC1Options.td +++ b/include/clang/Driver/CC1Options.td @@ -600,3 +600,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 70ca585..c791c09 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -895,6 +895,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 5f3ed67bbe85bd2dc287c6f3f337811dda051ef8 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 78ad3c7..ade8c60 100644 --- a/include/clang/Driver/CC1Options.td +++ b/include/clang/Driver/CC1Options.td @@ -602,3 +602,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 c791c09..40e1219 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -1311,6 +1311,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
