aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorThomas Koenig <tkoenig@gcc.gnu.org>2019-12-20 11:51:05 +0000
committerThomas Koenig <tkoenig@gcc.gnu.org>2019-12-20 11:51:05 +0000
commit95d27703bc8777efe9cdf2a1d8cac7a08b1f7168 (patch)
tree2ced2afc4d48ec55f5d67887dcf87f78589301db /gcc
parentde89b5748d68b76b06e3beca4a956060afb79a3d (diff)
downloadgcc-95d27703bc8777efe9cdf2a1d8cac7a08b1f7168.zip
gcc-95d27703bc8777efe9cdf2a1d8cac7a08b1f7168.tar.gz
gcc-95d27703bc8777efe9cdf2a1d8cac7a08b1f7168.tar.bz2
Introduce -finline-arg-packing.
2019-12-20 Thomas Koenig <tkoenig@gcc.gnu.org> PR middle-end/91512 PR fortran/92738 * invoke.texi: Document -finline-arg-packing. * lang.opt: Add -finline-arg-packing. * options.c (gfc_post_options): Handle -finline-arg-packing. * trans-array.c (gfc_conv_array_parameter): Use flag_inline_arg_packing instead of checking for optimize and optimize_size. 2019-12-20 Thomas Koenig <tkoenig@gcc.gnu.org> PR middle-end/91512 PR fortran/92738 * gfortran.dg/inline_pack_25.f90: New test. From-SVN: r279639
Diffstat (limited to 'gcc')
-rw-r--r--gcc/fortran/ChangeLog6
-rw-r--r--gcc/fortran/invoke.texi33
-rw-r--r--gcc/fortran/lang.opt4
-rw-r--r--gcc/fortran/options.c5
-rw-r--r--gcc/fortran/trans-array.c2
-rw-r--r--gcc/testsuite/ChangeLog11
-rw-r--r--gcc/testsuite/gfortran.dg/internal_pack_25.f9019
7 files changed, 77 insertions, 3 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index 8d480c5..f1c71ba 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,3 +1,9 @@
+2019-12-20 Thomas Koenig <tkoenig@gcc.gnu.org>
+
+ PR middle-end/91512
+ PR fortran/92738
+ * gfortran.dg/inline_pack_25.f90: New test.
+
2019-12-20 Tobias Burnus <tobias@codesourcery.com>
PR fortran/92996
diff --git a/gcc/fortran/invoke.texi b/gcc/fortran/invoke.texi
index 0bc054f..299fc9f 100644
--- a/gcc/fortran/invoke.texi
+++ b/gcc/fortran/invoke.texi
@@ -192,8 +192,9 @@ and warnings}.
-ffrontend-loop-interchange -ffrontend-optimize @gol
-finit-character=@var{n} -finit-integer=@var{n} -finit-local-zero @gol
-finit-derived -finit-logical=@var{<true|false>} @gol
--finit-real=@var{<zero|inf|-inf|nan|snan>} @gol
--finline-matmul-limit=@var{n} -fmax-array-constructor=@var{n} @gol
+-finit-real=@var{<zero|inf|-inf|nan|snan>}
+-finline-matmul-limit=@var{n} @gol
+-finline-arg-packing -fmax-array-constructor=@var{n} @gol
-fmax-stack-var-size=@var{n} -fno-align-commons -fno-automatic @gol
-fno-protect-parens -fno-underscoring -fsecond-underscore @gol
-fpack-derived -frealloc-lhs -frecursive -frepack-arrays @gol
@@ -1779,6 +1780,34 @@ compiled with the @option{-fshort-enums} option. It will make
GNU Fortran choose the smallest @code{INTEGER} kind a given
enumerator set will fit in, and give all its enumerators this kind.
+@item -finline-arg-packing
+@opindex @code{finline-arg-packing}
+When passing an assumed-shape argument of a procedure as actual
+argument to an assumed-size or explicit size or as argument to a
+procedure that does not have an explicit interface, the argument may
+have to be packed, that is put into contiguous memory. An example is
+the call to @code{foo} in
+@smallexample
+ subroutine foo(a)
+ real, dimension(*) :: a
+ end subroutine foo
+ subroutine bar(b)
+ real, dimension(:) :: b
+ call foo(b)
+ end subroutine bar
+@end smallexample
+
+When @option{-finline-arg-packing} is in effect, this packing will be
+performed by inline code. This allows for more optimization while
+increasing code size.
+
+@option{-finline-arg-packing} is implied by any of the @option{-O} options
+except when optimizing for size via @option{-Os}. If the code
+contains a very large number of argument that have to be packed, code
+size and also compilation time may become excessive. If that is the
+case, it may be better to disable this option. Instances of packing
+can be found by using by using @option{-Warray-temporaries}.
+
@item -fexternal-blas
@opindex @code{fexternal-blas}
This option will make @command{gfortran} generate calls to BLAS functions
diff --git a/gcc/fortran/lang.opt b/gcc/fortran/lang.opt
index 5fcd1ff..38c8891 100644
--- a/gcc/fortran/lang.opt
+++ b/gcc/fortran/lang.opt
@@ -647,6 +647,10 @@ Enum(gfc_init_local_real) String(inf) Value(GFC_INIT_REAL_INF)
EnumValue
Enum(gfc_init_local_real) String(-inf) Value(GFC_INIT_REAL_NEG_INF)
+finline-arg-packing
+Fortran Var(flag_inline_arg_packing) Init(-1)
+-finline-arg-packing Perform argument packing inline
+
finline-matmul-limit=
Fortran RejectNegative Joined UInteger Var(flag_inline_matmul_limit) Init(-1)
-finline-matmul-limit=<n> Specify the size of the largest matrix for which matmul will be inlined.
diff --git a/gcc/fortran/options.c b/gcc/fortran/options.c
index f7a5299..19e68d5 100644
--- a/gcc/fortran/options.c
+++ b/gcc/fortran/options.c
@@ -467,6 +467,11 @@ gfc_post_options (const char **pfilename)
if (flag_frontend_loop_interchange == -1)
flag_frontend_loop_interchange = optimize;
+ /* Do inline packing by default if optimizing, but not if
+ optimizing for size. */
+ if (flag_inline_arg_packing == -1)
+ flag_inline_arg_packing = optimize && !optimize_size;
+
if (flag_max_array_constructor < 65535)
flag_max_array_constructor = 65535;
diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c
index e879ea1..226fc3a 100644
--- a/gcc/fortran/trans-array.c
+++ b/gcc/fortran/trans-array.c
@@ -8139,7 +8139,7 @@ gfc_conv_array_parameter (gfc_se * se, gfc_expr * expr, bool g77,
making the packing and unpacking operation visible to the
optimizers. */
- if (g77 && optimize && !optimize_size && expr->expr_type == EXPR_VARIABLE
+ if (g77 && flag_inline_arg_packing && expr->expr_type == EXPR_VARIABLE
&& !is_pointer (expr) && ! gfc_has_dimen_vector_ref (expr)
&& !(expr->symtree->n.sym->as
&& expr->symtree->n.sym->as->type == AS_ASSUMED_RANK)
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index d5bd666..957f62a 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,14 @@
+2019-12-20 Thomas Koenig <tkoenig@gcc.gnu.org>
+
+ PR middle-end/91512
+ PR fortran/92738
+ * invoke.texi: Document -finline-arg-packing.
+ * lang.opt: Add -finline-arg-packing.
+ * options.c (gfc_post_options): Handle -finline-arg-packing.
+ * trans-array.c (gfc_conv_array_parameter): Use
+ flag_inline_arg_packing instead of checking for optimize and
+ optimize_size.
+
2019-12-20 Tobias Burnus <tobias@codesourcery.com>
PR fortran/92996
diff --git a/gcc/testsuite/gfortran.dg/internal_pack_25.f90 b/gcc/testsuite/gfortran.dg/internal_pack_25.f90
new file mode 100644
index 0000000..ac9f7e9
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/internal_pack_25.f90
@@ -0,0 +1,19 @@
+! { dg-do compile }
+! { dg-options "-fno-inline-arg-packing -O -fdump-tree-original" }
+! PR fortran/92738, middle-end/91512
+! Check that -fno-inline-pack does indeed suppress inline packing.
+module x
+ implicit none
+contains
+ subroutine foo(x)
+ real, dimension(:), intent(inout) :: x
+ call bar (x, size(x))
+ end subroutine foo
+ subroutine bar (x, n)
+ integer, intent(in) :: n
+ real, dimension(n) :: x
+ x = -x
+ end subroutine bar
+end module x
+! { dg-final { scan-tree-dump-times "_gfortran_internal_pack" 1 "original" } }
+! { dg-final { scan-tree-dump-times "_gfortran_internal_unpack" 1 "original" } }