[cfe-commits] r120877 - in /cfe/trunk: include/clang/Basic/LangOptions.h include/clang/Driver/CC1Options.td lib/Frontend/CompilerInvocation.cpp lib/Sema/SemaExpr.cpp test/CodeGen/cl-single-precision-constant.c
Peter Collingbourne
peter at pcc.me.uk
Fri Dec 3 17:50:56 PST 2010
Author: pcc
Date: Fri Dec 3 19:50:56 2010
New Revision: 120877
URL: http://llvm.org/viewvc/llvm-project?rev=120877&view=rev
Log:
Implement -cl-single-precision-constant
Added:
cfe/trunk/test/CodeGen/cl-single-precision-constant.c
Modified:
cfe/trunk/include/clang/Basic/LangOptions.h
cfe/trunk/include/clang/Driver/CC1Options.td
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
Modified: cfe/trunk/include/clang/Basic/LangOptions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.h?rev=120877&r1=120876&r2=120877&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/LangOptions.h (original)
+++ cfe/trunk/include/clang/Basic/LangOptions.h Fri Dec 3 19:50:56 2010
@@ -110,6 +110,9 @@
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;
@@ -196,6 +199,7 @@
DumpRecordLayouts = 0;
DumpVTableLayouts = 0;
SpellChecking = 1;
+ SinglePrecisionConstants = 0;
NoBitFieldTypeAlign = 0;
}
Modified: cfe/trunk/include/clang/Driver/CC1Options.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=120877&r1=120876&r2=120877&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/CC1Options.td (original)
+++ cfe/trunk/include/clang/Driver/CC1Options.td Fri Dec 3 19:50:56 2010
@@ -599,3 +599,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.">;
Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=120877&r1=120876&r2=120877&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Fri Dec 3 19:50:56 2010
@@ -1418,6 +1418,7 @@
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.
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=120877&r1=120876&r2=120877&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri Dec 3 19:50:56 2010
@@ -2394,6 +2394,9 @@
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 {
Added: cfe/trunk/test/CodeGen/cl-single-precision-constant.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/cl-single-precision-constant.c?rev=120877&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/cl-single-precision-constant.c (added)
+++ cfe/trunk/test/CodeGen/cl-single-precision-constant.c Fri Dec 3 19:50:56 2010
@@ -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.;
+}
More information about the cfe-commits
mailing list