Skip to content

Commit 46efee7

Browse files
committed
[flang] add -floop-interchange to flang driver
This patch allows flang to recognize the flags -floop-interchange and -fno-loop-interchange. -floop-interchange adds the loop interchange pass to the pass pipeline.
1 parent 4bdd116 commit 46efee7

File tree

7 files changed

+19
-2
lines changed

7 files changed

+19
-2
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4186,9 +4186,9 @@ def ftrap_function_EQ : Joined<["-"], "ftrap-function=">, Group<f_Group>,
41864186
HelpText<"Issue call to specified function rather than a trap instruction">,
41874187
MarshallingInfoString<CodeGenOpts<"TrapFuncName">>;
41884188
def floop_interchange : Flag<["-"], "floop-interchange">, Group<f_Group>,
4189-
HelpText<"Enable the loop interchange pass">, Visibility<[ClangOption, CC1Option]>;
4189+
HelpText<"Enable the loop interchange pass">, Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>;
41904190
def fno_loop_interchange: Flag<["-"], "fno-loop-interchange">, Group<f_Group>,
4191-
HelpText<"Disable the loop interchange pass">, Visibility<[ClangOption, CC1Option]>;
4191+
HelpText<"Disable the loop interchange pass">, Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>;
41924192
def funroll_loops : Flag<["-"], "funroll-loops">, Group<f_Group>,
41934193
HelpText<"Turn on loop unroller">, Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>;
41944194
def fno_unroll_loops : Flag<["-"], "fno-unroll-loops">, Group<f_Group>,

clang/lib/Driver/ToolChains/Flang.cpp

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

155+
Args.AddLastArg(CmdArgs, options::OPT_floop_interchange,
156+
options::OPT_fno_loop_interchange);
157+
155158
handleVectorizeLoopsArgs(Args, CmdArgs);
156159
handleVectorizeSLPArgs(Args, CmdArgs);
157160

flang/docs/ReleaseNotes.md

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

3333
## New Compiler Flags
3434

35+
* -floop-interchange is now recognized by flang.
36+
3537
## Windows Support
3638

3739
## 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
@@ -35,6 +35,7 @@ CODEGENOPT(PrepareForThinLTO , 1, 0) ///< Set when -flto=thin is enabled on the
3535
CODEGENOPT(StackArrays, 1, 0) ///< -fstack-arrays (enable the stack-arrays pass)
3636
CODEGENOPT(VectorizeLoop, 1, 0) ///< Enable loop vectorization.
3737
CODEGENOPT(VectorizeSLP, 1, 0) ///< Enable SLP vectorization.
38+
CODEGENOPT(InterchangeLoops, 1, 0) ///< Enable loop interchange.
3839
CODEGENOPT(LoopVersioning, 1, 0) ///< Enable loop versioning.
3940
CODEGENOPT(UnrollLoops, 1, 0) ///< Enable loop unrolling
4041
CODEGENOPT(AliasAnalysis, 1, 0) ///< Enable alias analysis pass

flang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,9 @@ static void parseCodeGenArgs(Fortran::frontend::CodeGenOptions &opts,
269269
clang::driver::options::OPT_fno_stack_arrays, false))
270270
opts.StackArrays = 1;
271271

272+
if (args.getLastArg(clang::driver::options::OPT_floop_interchange))
273+
opts.InterchangeLoops = 1;
274+
272275
if (args.getLastArg(clang::driver::options::OPT_vectorize_loops))
273276
opts.VectorizeLoop = 1;
274277

flang/lib/Frontend/FrontendActions.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,7 @@ void CodeGenAction::runOptimizationPipeline(llvm::raw_pwrite_stream &os) {
922922
if (ci.isTimingEnabled())
923923
si.getTimePasses().setOutStream(ci.getTimingStreamLLVM());
924924
pto.LoopUnrolling = opts.UnrollLoops;
925+
pto.LoopInterchange = opts.InterchangeLoops;
925926
pto.LoopInterleaving = opts.UnrollLoops;
926927
pto.LoopVectorization = opts.VectorizeLoop;
927928
pto.SLPVectorization = opts.VectorizeSLP;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
! RUN: %flang -### -S -floop-interchange %s 2>&1 | FileCheck -check-prefix=CHECK-LOOP-INTERCHANGE %s
2+
! RUN: %flang -### -S -fno-loop-interchange %s 2>&1 | FileCheck -check-prefix=CHECK-NO-LOOP-INTERCHANGE %s
3+
! CHECK-LOOP-INTERCHANGE: "-floop-interchange"
4+
! CHECK-NO-LOOP-INTERCHANGE: "-fno-loop-interchange"
5+
6+
program test
7+
end program

0 commit comments

Comments
 (0)