Skip to content

Commit 3b71a3c

Browse files
sebpopmadhur13490
authored andcommitted
add -floop-fuse to clang and flang
1 parent b39160d commit 3b71a3c

File tree

15 files changed

+65
-2
lines changed

15 files changed

+65
-2
lines changed

clang/include/clang/Basic/CodeGenOptions.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ CODEGENOPT(TimeTrace , 1, 0, Benign) ///< Set when -ftime-trace is enabl
322322
VALUE_CODEGENOPT(TimeTraceGranularity, 32, 500, Benign) ///< Minimum time granularity (in microseconds),
323323
///< traced by time profiler
324324
CODEGENOPT(InterchangeLoops , 1, 0, Benign) ///< Run loop-interchange.
325+
CODEGENOPT(FuseLoops , 1, 0, Benign) ///< Run loop-fuse.
325326
CODEGENOPT(UnrollLoops , 1, 0, Benign) ///< Control whether loops are unrolled.
326327
CODEGENOPT(RerollLoops , 1, 0, Benign) ///< Control whether loops are rerolled.
327328
CODEGENOPT(NoUseJumpTables , 1, 0, Benign) ///< Set when -fno-jump-tables is enabled.

clang/include/clang/Driver/Options.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4253,6 +4253,10 @@ def floop_interchange : Flag<["-"], "floop-interchange">, Group<f_Group>,
42534253
HelpText<"Enable the loop interchange pass">, Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>;
42544254
def fno_loop_interchange: Flag<["-"], "fno-loop-interchange">, Group<f_Group>,
42554255
HelpText<"Disable the loop interchange pass">, Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>;
4256+
def floop_fuse : Flag<["-"], "floop-fuse">, Group<f_Group>,
4257+
HelpText<"Enable the loop fuse pass">, Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>;
4258+
def fno_loop_fuse: Flag<["-"], "fno-loop-fuse">, Group<f_Group>,
4259+
HelpText<"Disable the loop fuse pass">, Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>;
42564260
def funroll_loops : Flag<["-"], "funroll-loops">, Group<f_Group>,
42574261
HelpText<"Turn on loop unroller">, Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>;
42584262
def fno_unroll_loops : Flag<["-"], "fno-unroll-loops">, Group<f_Group>,

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,7 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
897897
PipelineTuningOptions PTO;
898898
PTO.LoopUnrolling = CodeGenOpts.UnrollLoops;
899899
PTO.LoopInterchange = CodeGenOpts.InterchangeLoops;
900+
PTO.LoopFuse = CodeGenOpts.FuseLoops;
900901
// For historical reasons, loop interleaving is set to mirror setting for loop
901902
// unrolling.
902903
PTO.LoopInterleaving = CodeGenOpts.UnrollLoops;
@@ -1332,6 +1333,7 @@ runThinLTOBackend(CompilerInstance &CI, ModuleSummaryIndex *CombinedIndex,
13321333
Conf.SampleProfile = std::move(SampleProfile);
13331334
Conf.PTO.LoopUnrolling = CGOpts.UnrollLoops;
13341335
Conf.PTO.LoopInterchange = CGOpts.InterchangeLoops;
1336+
Conf.PTO.LoopFuse = CGOpts.FuseLoops;
13351337
// For historical reasons, loop interleaving is set to mirror setting for loop
13361338
// unrolling.
13371339
Conf.PTO.LoopInterleaving = CGOpts.UnrollLoops;

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6869,6 +6869,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
68696869
options::OPT_fno_unroll_loops);
68706870
Args.AddLastArg(CmdArgs, options::OPT_floop_interchange,
68716871
options::OPT_fno_loop_interchange);
6872+
Args.AddLastArg(CmdArgs, options::OPT_floop_fuse, options::OPT_fno_loop_fuse);
68726873

68736874
Args.AddLastArg(CmdArgs, options::OPT_fstrict_flex_arrays_EQ);
68746875

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3265,7 +3265,7 @@ void tools::handleVectorizeSLPArgs(const ArgList &Args,
32653265

32663266
void tools::handleInterchangeLoopsArgs(const ArgList &Args,
32673267
ArgStringList &CmdArgs) {
3268-
// FIXME: instead of relying on shouldEnableVectorizerAtOLevel, we may want to
3268+
// FIXME: Instead of relying on shouldEnableVectorizerAtOLevel, we may want to
32693269
// implement a separate function to infer loop interchange from opt level.
32703270
// For now, enable loop-interchange at the same opt levels as loop-vectorize.
32713271
bool EnableInterchange = shouldEnableVectorizerAtOLevel(Args, false);

clang/lib/Driver/ToolChains/Flang.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ void Flang::addCodegenOptions(const ArgList &Args,
151151
!stackArrays->getOption().matches(options::OPT_fno_stack_arrays))
152152
CmdArgs.push_back("-fstack-arrays");
153153

154+
Args.AddLastArg(CmdArgs, options::OPT_floop_fuse, options::OPT_fno_loop_fuse);
155+
154156
handleInterchangeLoopsArgs(Args, CmdArgs);
155157
handleVectorizeLoopsArgs(Args, CmdArgs);
156158
handleVectorizeSLPArgs(Args, CmdArgs);

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1671,6 +1671,11 @@ void CompilerInvocationBase::GenerateCodeGenArgs(const CodeGenOptions &Opts,
16711671
else
16721672
GenerateArg(Consumer, OPT_fno_loop_interchange);
16731673

1674+
if (Opts.FuseLoops)
1675+
GenerateArg(Consumer, OPT_floop_fuse);
1676+
else
1677+
GenerateArg(Consumer, OPT_fno_loop_fuse);
1678+
16741679
if (!Opts.BinutilsVersion.empty())
16751680
GenerateArg(Consumer, OPT_fbinutils_version_EQ, Opts.BinutilsVersion);
16761681

@@ -1991,6 +1996,7 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args,
19911996
(Opts.OptimizationLevel > 1));
19921997
Opts.InterchangeLoops =
19931998
Args.hasFlag(OPT_floop_interchange, OPT_fno_loop_interchange, false);
1999+
Opts.FuseLoops = Args.hasFlag(OPT_floop_fuse, OPT_fno_loop_fuse, false);
19942000
Opts.BinutilsVersion =
19952001
std::string(Args.getLastArgValue(OPT_fbinutils_version_EQ));
19962002

clang/test/Driver/clang_f_opts.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@
5252
// CHECK-INTERCHANGE-LOOPS: "-floop-interchange"
5353
// CHECK-NO-INTERCHANGE-LOOPS: "-fno-loop-interchange"
5454

55+
// RUN: %clang -### -S -floop-fuse %s 2>&1 | FileCheck -check-prefix=CHECK-FUSE-LOOPS %s
56+
// RUN: %clang -### -S -fno-loop-fuse %s 2>&1 | FileCheck -check-prefix=CHECK-NO-FUSE-LOOPS %s
57+
// RUN: %clang -### -S -fno-loop-fuse -floop-fuse %s 2>&1 | FileCheck -check-prefix=CHECK-FUSE-LOOPS %s
58+
// RUN: %clang -### -S -floop-fuse -fno-loop-fuse %s 2>&1 | FileCheck -check-prefix=CHECK-NO-FUSE-LOOPS %s
59+
// CHECK-FUSE-LOOPS: "-floop-fuse"
60+
// CHECK-NO-FUSE-LOOPS: "-fno-loop-fuse"
61+
5562
// RUN: %clang -### -S -fprofile-sample-accurate %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-SAMPLE-ACCURATE %s
5663
// CHECK-PROFILE-SAMPLE-ACCURATE: "-fprofile-sample-accurate"
5764

flang/docs/ReleaseNotes.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ page](https://llvm.org/releases/).
3232

3333
## New Compiler Flags
3434

35+
* -floop-interchange is now recognized by flang.
36+
* -floop-interchange is enabled by default at -O2 and above.
37+
* -floop-fuse is now recognized by flang.
38+
3539
## Windows Support
3640

3741
## Fortran Language Changes in Flang

flang/include/flang/Frontend/CodeGenOptions.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ CODEGENOPT(StackArrays, 1, 0) ///< -fstack-arrays (enable the stack-arrays pass)
4343
CODEGENOPT(VectorizeLoop, 1, 0) ///< Enable loop vectorization.
4444
CODEGENOPT(VectorizeSLP, 1, 0) ///< Enable SLP vectorization.
4545
CODEGENOPT(InterchangeLoops, 1, 0) ///< Enable loop interchange.
46+
CODEGENOPT(FuseLoops, 1, 0) ///< Enable loop fuse.
4647
CODEGENOPT(LoopVersioning, 1, 0) ///< Enable loop versioning.
4748
CODEGENOPT(UnrollLoops, 1, 0) ///< Enable loop unrolling
4849
CODEGENOPT(AliasAnalysis, 1, 0) ///< Enable alias analysis pass

0 commit comments

Comments
 (0)