From 306bd2c6aa49db4315770f74a94c42626b5f2a3c Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Mon, 2 Jan 2012 14:19:45 +0000 Subject: Fix PR11685 by implementing -ffast-math and its various friends in the Clang driver. This involves a bunch of silly option parsing code to try to carefully emulate GCC's options. Currently, this takes a conservative approach, and unless all of the unsafe optimizations are enabled, none of them are. The fine grained control doesn't seem particularly useful. If it ever becomes useful, we can add that to LLVM first, and then expose it here. This also fixes a few tiny bugs in the flag management around -fhonor-infinities and -fhonor-nans; the flags now form proper sets both for enabling and disabling, with the last flag winning. I've also implemented a moderately terrifying GCC feature where a language change is also provided by the '-ffast-math' flag by defining the __FAST_MATH__ preprocessor macro. This feature is tracked and serialized in the frontend but it isn't used yet. A subsequent patch will add the preprocessor macro and tests for it. I've manually tested that codegen appears to respect this, but I've not dug in enough to see if there is an easy way to test codegen options w/o relying on the particulars of LLVM's optimizations. llvm-svn: 147434 --- clang/lib/Frontend/CompilerInvocation.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'clang/lib/Frontend/CompilerInvocation.cpp') diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index caeb416..0137774 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -735,6 +735,8 @@ static void LangOptsToArgs(const LangOptions &Opts, Res.push_back("-fheinous-gnu-extensions"); // Optimize is implicit. // OptimizeSize is implicit. + if (Opts.FastMath) + Res.push_back("-ffast-math"); if (Opts.Static) Res.push_back("-static-define"); if (Opts.DumpRecordLayouts) @@ -1117,7 +1119,8 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, Opts.NoDwarf2CFIAsm = Args.hasArg(OPT_fno_dwarf2_cfi_asm); Opts.NoDwarfDirectoryAsm = Args.hasArg(OPT_fno_dwarf_directory_asm); Opts.SoftFloat = Args.hasArg(OPT_msoft_float); - Opts.UnsafeFPMath = Args.hasArg(OPT_cl_unsafe_math_optimizations) || + Opts.UnsafeFPMath = Args.hasArg(OPT_menable_unsafe_fp_math) || + 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"); @@ -1874,6 +1877,8 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK, // FIXME: This is affected by other options (-fno-inline). Opts.NoInline = !Opt; + Opts.FastMath = Args.hasArg(OPT_ffast_math); + unsigned SSP = Args.getLastArgIntValue(OPT_stack_protector, 0, Diags); switch (SSP) { default: -- cgit v1.1