Index: include/clang/Driver/CC1Options.td =================================================================== --- include/clang/Driver/CC1Options.td +++ include/clang/Driver/CC1Options.td @@ -235,6 +235,10 @@ HelpText<"Run the Loop vectorization passes">; def vectorize_slp : Flag<["-"], "vectorize-slp">, HelpText<"Run the SLP vectorization passes">; +def proactive_loop_fusion : Flag<["-"], "proactive-loop-fusion">, + HelpText<"Run the Loop fusion passes">; +def proactive_loop_fusion_analysis : Flag<["-"], "proactive-loop-fusion-analysis">, + HelpText<"Run the Loop fusion call graph passes">; def vectorize_slp_aggressive : Flag<["-"], "vectorize-slp-aggressive">, HelpText<"Run the BB vectorization passes">; def dependent_lib : Joined<["--"], "dependent-lib=">, Index: include/clang/Driver/Options.td =================================================================== --- include/clang/Driver/Options.td +++ include/clang/Driver/Options.td @@ -907,6 +907,14 @@ def foperator_arrow_depth_EQ : Joined<["-"], "foperator-arrow-depth=">, Group; def ftest_coverage : Flag<["-"], "ftest-coverage">, Group; + +def fproactive_loop_fusion : Flag<["-"], "fproactive-loop-fusion">, Group, + HelpText<"Enable the loop fusion passes">; +def fno_proactive_loop_fusion : Flag<["-"], "fno-proactive-loop-fusion">, Group; +def fproactive_loop_fusion_analysis : Flag<["-"], "fproactive-loop-fusion-analysis">, Group, + HelpText<"Enable the loop fusion analysis passes">; +def fno_proactive_loop_fusion_analysis : Flag<["-"], "fno-proactive-loop-fusion analysis">, Group; + def fvectorize : Flag<["-"], "fvectorize">, Group, HelpText<"Enable the loop vectorization passes">; def fno_vectorize : Flag<["-"], "fno-vectorize">, Group; Index: include/clang/Frontend/CodeGenOptions.def =================================================================== --- include/clang/Frontend/CodeGenOptions.def +++ include/clang/Frontend/CodeGenOptions.def @@ -124,6 +124,8 @@ CODEGENOPT(VectorizeBB , 1, 0) ///< Run basic block vectorizer. CODEGENOPT(VectorizeLoop , 1, 0) ///< Run loop vectorizer. CODEGENOPT(VectorizeSLP , 1, 0) ///< Run SLP vectorizer. +CODEGENOPT(ProactiveLoopFusion, 1, 0) ///< Run proactive loop fusion. +CODEGENOPT(ProactiveLoopFusionAnalysis, 1, 0) ///< Run proactive loop fusion analysis. /// Attempt to use register sized accesses to bit-fields in structures, when /// possible. Index: lib/CodeGen/BackendUtil.cpp =================================================================== --- lib/CodeGen/BackendUtil.cpp +++ lib/CodeGen/BackendUtil.cpp @@ -263,12 +263,16 @@ PMBuilder.BBVectorize = CodeGenOpts.VectorizeBB; PMBuilder.SLPVectorize = CodeGenOpts.VectorizeSLP; PMBuilder.LoopVectorize = CodeGenOpts.VectorizeLoop; + PMBuilder.ProactiveLoopFusion = CodeGenOpts.ProactiveLoopFusion; + PMBuilder.ProactiveLoopFusionAnalysis = CodeGenOpts.ProactiveLoopFusionAnalysis; PMBuilder.DisableTailCalls = CodeGenOpts.DisableTailCalls; PMBuilder.DisableUnitAtATime = !CodeGenOpts.UnitAtATime; PMBuilder.DisableUnrollLoops = !CodeGenOpts.UnrollLoops; PMBuilder.MergeFunctions = CodeGenOpts.MergeFunctions; PMBuilder.RerollLoops = CodeGenOpts.RerollLoops; + PMBuilder.ProactiveLoopFusionAnalysis = CodeGenOpts.ProactiveLoopFusionAnalysis; + PMBuilder.ProactiveLoopFusion = CodeGenOpts.ProactiveLoopFusion; PMBuilder.addExtension(PassManagerBuilder::EP_EarlyAsPossible, addAddDiscriminatorsPass); Index: lib/Driver/Tools.cpp =================================================================== --- lib/Driver/Tools.cpp +++ lib/Driver/Tools.cpp @@ -4334,9 +4334,19 @@ bool EnableSLPVec = shouldEnableVectorizerAtOLevel(Args, true); OptSpecifier SLPVectAliasOption = EnableSLPVec ? options::OPT_O_Group : options::OPT_fslp_vectorize; + if (Args.hasFlag(options::OPT_fslp_vectorize, SLPVectAliasOption, options::OPT_fno_slp_vectorize, EnableSLPVec)) CmdArgs.push_back("-vectorize-slp"); + if (Args.hasFlag(options::OPT_fproactive_loop_fusion_analysis, + options::OPT_fno_proactive_loop_fusion_analysis,false)) { + CmdArgs.push_back("-proactive-loop-fusion-analysis"); + } + + if (Args.hasFlag(options::OPT_fproactive_loop_fusion, + options::OPT_fno_proactive_loop_fusion,false)) { + CmdArgs.push_back("-proactive-loop-fusion"); + } // -fno-slp-vectorize-aggressive is default. if (Args.hasFlag(options::OPT_fslp_vectorize_aggressive, @@ -6680,6 +6690,18 @@ if (D.IsUsingLTO(Args)) AddGoldPlugin(ToolChain, Args, CmdArgs); + if (D.IsUsingLTO(Args)) { + if (Args.hasFlag(options::OPT_fproactive_loop_fusion_analysis, + options::OPT_fno_proactive_loop_fusion_analysis,false)) { + CmdArgs.push_back("-plugin-opt=proactive-loop-fusion-analysis"); + } + + if (Args.hasFlag(options::OPT_fproactive_loop_fusion, + options::OPT_fno_proactive_loop_fusion,false)) { + CmdArgs.push_back("-plugin-opt=proactive-loop-fusion"); + } + } + bool NeedsSanitizerDeps = addSanitizerRuntimes(ToolChain, Args, CmdArgs); AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs); @@ -7511,6 +7533,18 @@ if (D.IsUsingLTO(Args)) AddGoldPlugin(ToolChain, Args, CmdArgs); + if (D.IsUsingLTO(Args)) { + if (Args.hasFlag(options::OPT_fproactive_loop_fusion_analysis, + options::OPT_fno_proactive_loop_fusion_analysis,false)) { + CmdArgs.push_back("-plugin-opt=proactive-loop-fusion-analysis"); + } + + if (Args.hasFlag(options::OPT_fproactive_loop_fusion, + options::OPT_fno_proactive_loop_fusion,false)) { + CmdArgs.push_back("-plugin-opt=proactive-loop-fusion"); + } + } + if (Args.hasArg(options::OPT_Z_Xlinker__no_demangle)) CmdArgs.push_back("--no-demangle"); Index: lib/Frontend/CompilerInvocation.cpp =================================================================== --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -477,6 +477,8 @@ Opts.VectorizeBB = Args.hasArg(OPT_vectorize_slp_aggressive); Opts.VectorizeLoop = Args.hasArg(OPT_vectorize_loops); Opts.VectorizeSLP = Args.hasArg(OPT_vectorize_slp); + Opts.ProactiveLoopFusion = Args.hasArg(OPT_proactive_loop_fusion); + Opts.ProactiveLoopFusionAnalysis = Args.hasArg(OPT_proactive_loop_fusion_analysis); Opts.MainFileName = Args.getLastArgValue(OPT_main_file_name); Opts.VerifyModule = !Args.hasArg(OPT_disable_llvm_verifier);