From f84d409903dd4107c8cef5a08fcfce6e5c21d4de Mon Sep 17 00:00:00 2001 From: Eric Christopher Date: Sat, 7 Aug 2010 23:08:14 +0000 Subject: [PATCH] Make -funroll-loops turn on loop unrolling in the optimizer instead of just ignoring it. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@110525 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Driver/CC1Options.td | 2 ++ include/clang/Driver/Options.td | 2 +- lib/Driver/Tools.cpp | 1 + lib/Frontend/CompilerInvocation.cpp | 10 +++++++--- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/include/clang/Driver/CC1Options.td b/include/clang/Driver/CC1Options.td index 50c743a7b9..20c23215ec 100644 --- a/include/clang/Driver/CC1Options.td +++ b/include/clang/Driver/CC1Options.td @@ -139,6 +139,8 @@ def ffunction_sections : Flag<"-ffunction-sections">, HelpText<"Place each function in its own section (ELF Only)">; def fdata_sections : Flag<"-fdata-sections">, HelpText<"Place each data in its own section (ELF Only)">; +def funroll_loops : Flag<"-funroll-loops">, + HelpText<"Turn on loop unroller">; def masm_verbose : Flag<"-masm-verbose">, HelpText<"Generate verbose assembly output">; def mcode_model : Separate<"-mcode-model">, diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td index e6204f77ad..5fbebd17bd 100644 --- a/include/clang/Driver/Options.td +++ b/include/clang/Driver/Options.td @@ -385,7 +385,7 @@ def fthreadsafe_statics : Flag<"-fthreadsafe-statics">, Group; def ftime_report : Flag<"-ftime-report">, Group; def ftrapv : Flag<"-ftrapv">, Group; def funit_at_a_time : Flag<"-funit-at-a-time">, Group; -def funroll_loops : Flag<"-funroll-loops">, Group; +def funroll_loops : Flag<"-funroll-loops">, Group; def funsigned_bitfields : Flag<"-funsigned-bitfields">, Group; def funsigned_char : Flag<"-funsigned-char">, Group; def funwind_tables : Flag<"-funwind-tables">, Group; diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index 19a6a92474..8f052791e8 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -1208,6 +1208,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, Args.AddLastArg(CmdArgs, options::OPT_ftrapv); Args.AddLastArg(CmdArgs, options::OPT_fwrapv); Args.AddLastArg(CmdArgs, options::OPT_fwritable_strings); + Args.AddLastArg(CmdArgs, options::OPT_funroll_loops); Args.AddLastArg(CmdArgs, options::OPT_pthread); diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 8f9fa848cb..aa0c317dd8 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -148,9 +148,12 @@ static void CodeGenOptsToArgs(const CodeGenOptions &Opts, // SimplifyLibCalls is only derived. // TimePasses is only derived. // UnitAtATime is unused. - // UnrollLoops is only derived. // Inlining is only derived. - + + // UnrollLoops is derived, but also accepts an option, no + // harm in pushing it back here. + if (Opts.UnrollLoops) + Res.push_back("-funroll-loops"); if (Opts.DataSections) Res.push_back("-fdata-sections"); if (Opts.FunctionSections) @@ -828,7 +831,8 @@ static void ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, Opts.OptimizeSize = Args.hasArg(OPT_Os); Opts.SimplifyLibCalls = !(Args.hasArg(OPT_fno_builtin) || Args.hasArg(OPT_ffreestanding)); - Opts.UnrollLoops = (Opts.OptimizationLevel > 1 && !Opts.OptimizeSize); + Opts.UnrollLoops = Args.hasArg(OPT_funroll_loops) || + (Opts.OptimizationLevel > 1 && !Opts.OptimizeSize); Opts.AsmVerbose = Args.hasArg(OPT_masm_verbose); Opts.CXAAtExit = !Args.hasArg(OPT_fno_use_cxa_atexit); -- 2.40.0