aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Collingbourne <peter@pcc.me.uk>2010-12-04 01:50:56 +0000
committerPeter Collingbourne <peter@pcc.me.uk>2010-12-04 01:50:56 +0000
commit0982136cb748f4a842141bf199d133126d6be882 (patch)
tree30ee87d2a35c1d37c6c1eed58671c20cbce241e4
parent61e07861dd3a70c31f658bad8c4b911994e4933b (diff)
Implement -cl-single-precision-constant
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@120877 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Basic/LangOptions.h4
-rw-r--r--include/clang/Driver/CC1Options.td2
-rw-r--r--lib/Frontend/CompilerInvocation.cpp1
-rw-r--r--lib/Sema/SemaExpr.cpp3
-rw-r--r--test/CodeGen/cl-single-precision-constant.c7
5 files changed, 17 insertions, 0 deletions
diff --git a/include/clang/Basic/LangOptions.h b/include/clang/Basic/LangOptions.h
index aa4eae069d..88e3c8a215 100644
--- a/include/clang/Basic/LangOptions.h
+++ b/include/clang/Basic/LangOptions.h
@@ -110,6 +110,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;
@@ -196,6 +199,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 27db9cf5bf..eab473b4b7 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 8795b38a41..7f9d4a560e 100644
--- a/lib/Frontend/CompilerInvocation.cpp
+++ b/lib/Frontend/CompilerInvocation.cpp
@@ -1418,6 +1418,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 270aa3e06b..177d61cc82 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -2394,6 +2394,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 0000000000..adde19361b
--- /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.;
+}