Find a file
Hristian Kirtchev 529749b948 [Ada] In-place initialization for Initialize_Scalars
This patch optimizes the initialization and allocation of scalar array objects
when pragma Initialize_Scalars is in effect. The patch also extends the syntax
and semantics of pragma Initialize_Scalars to allow for the specification of
invalid values pertaining to families of scalar types. The new syntax is as
follows:

   pragma Initialize_Scalars
     [ ( TYPE_VALUE_PAIR {, TYPE_VALUE_PAIR} ) ];

   TYPE_VALUE_PAIR ::=
     SCALAR_TYPE => static_EXPRESSION

   SCALAR_TYPE :=
     Short_Float
   | Float
   | Long_Float
   | Long_Long_Flat
   | Signed_8
   | Signed_16
   | Signed_32
   | Signed_64
   | Unsigned_8
   | Unsigned_16
   | Unsigned_32
   | Unsigned_64

Depending on the value specified by pragma Initialize_Scalars, the backend may
optimize the creation of the scalar array object into a fast memset.

------------
-- Source --
------------

--  gnat.adc

pragma Initialize_Scalars
  (Short_Float     => 0.0,
   Float           => 0.0,
   Long_Float      => 0.0,
   Long_Long_Float => 0.0,
   Signed_8        => 0,
   Signed_16       => 0,
   Signed_32       => 0,
   Signed_64       => 0,
   Unsigned_8      => 0,
   Unsigned_16     => 0,
   Unsigned_32     => 0,
   Unsigned_64     => 0);

--  types.ads

with System;

package Types is
   Max : constant := 10_000;
   subtype Big is Integer range 1 .. Max;

   type Byte is range 0 .. 255;
   for Byte'Size use System.Storage_Unit;

   type Byte_Arr_1 is array (1 .. Max) of Byte;
   type Byte_Arr_2 is array (Big) of Byte;
   type Byte_Arr_3 is array (Integer range <>) of Byte;
   type Byte_Arr_4 is array (Integer range <>,
                             Integer range <>) of Byte;
   type Constr_Arr_1 is array (1 .. Max) of Integer;
   type Constr_Arr_2 is array (Big) of Integer;
   type Constr_Arr_3 is array (1 .. Max, 1 .. Max) of Integer;
   type Constr_Arr_4 is array (Big, Big) of Integer;

   type Unconstr_Arr_1 is array (Integer range <>) of Integer;
   type Unconstr_Arr_2 is array (Integer range <>,
                                 Integer range <>) of Integer;

   subtype Subt_Arr_1 is Unconstr_Arr_1 (1 .. Max);
   subtype Subt_Arr_2 is Unconstr_Arr_1 (Big);
   subtype Subt_Arr_3 is Unconstr_Arr_2 (1 .. Max, 1 .. Max);
   subtype Subt_Arr_4 is Unconstr_Arr_2 (Big, Big);

   subtype Subt_Str_1 is String (1 .. Max);
   subtype Subt_Str_2 is String (Big);

   type Byte_Arr_1_Ptr     is access Byte_Arr_1;
   type Byte_Arr_2_Ptr     is access Byte_Arr_2;
   type Byte_Arr_3_Ptr     is access Byte_Arr_3;
   type Byte_Arr_4_Ptr     is access Byte_Arr_4;
   type Constr_Arr_1_Ptr   is access Constr_Arr_1;
   type Constr_Arr_2_Ptr   is access Constr_Arr_2;
   type Constr_Arr_3_Ptr   is access Constr_Arr_3;
   type Constr_Arr_4_Ptr   is access Constr_Arr_4;
   type Unconstr_Arr_1_Ptr is access Unconstr_Arr_1;
   type Unconstr_Arr_2_Ptr is access Unconstr_Arr_2;
   type Subt_Arr_1_Ptr     is access Subt_Arr_1;
   type Subt_Arr_2_Ptr     is access Subt_Arr_2;
   type Subt_Arr_3_Ptr     is access Subt_Arr_3;
   type Subt_Arr_4_Ptr     is access Subt_Arr_4;
   type Str_Ptr            is access String;
   type Subt_Str_1_Ptr     is access Subt_Str_1;
   type Subt_Str_2_Ptr     is access Subt_Str_2;
end Types;

--  main.adb

with Types; use Types;

procedure Main is
   Byte_Arr_1_Obj     : Byte_Arr_1;
   Byte_Arr_2_Obj     : Byte_Arr_2;
   Byte_Arr_3_Obj     : Byte_Arr_3 (1 .. Max);
   Byte_Arr_4_Obj     : Byte_Arr_3 (Big);
   Byte_Arr_5_Obj     : Byte_Arr_4 (1 .. Max, 1 .. Max);
   Byte_Arr_6_Obj     : Byte_Arr_4 (Big, Big);
   Constr_Arr_1_Obj   : Constr_Arr_1;
   Constr_Arr_2_Obj   : Constr_Arr_2;
   Constr_Arr_3_Obj   : Constr_Arr_3;
   Constr_Arr_4_Obj   : Constr_Arr_4;
   Unconstr_Arr_1_Obj : Unconstr_Arr_1 (1 .. Max);
   Unconstr_Arr_2_Obj : Unconstr_Arr_1 (Big);
   Unconstr_Arr_3_Obj : Unconstr_Arr_2 (1 .. Max, 1 .. Max);
   Unconstr_Arr_4_Obj : Unconstr_Arr_2 (Big, Big);
   Subt_Arr_1_Obj     : Subt_Arr_1;
   Subt_Arr_2_Obj     : Subt_Arr_2;
   Subt_Arr_3_Obj     : Subt_Arr_3;
   Subt_Arr_4_Obj     : Subt_Arr_4;
   Str_1_Obj          : String (1 .. Max);
   Str_2_Obj          : String (Big);
   Subt_Str_1_Obj     : Subt_Str_1;
   Subt_Str_2_Obj     : Subt_Str_2;

   Byte_Arr_1_Ptr_Obj     : Byte_Arr_1_Ptr     := new Byte_Arr_1;
   Byte_Arr_2_Ptr_Obj     : Byte_Arr_2_Ptr     := new Byte_Arr_2;
   Byte_Arr_3_Ptr_Obj     : Byte_Arr_3_Ptr     := new Byte_Arr_3 (1 .. Max);
   Byte_Arr_4_Ptr_Obj     : Byte_Arr_3_Ptr     := new Byte_Arr_3 (Big);
   Byte_Arr_5_Ptr_Obj     : Byte_Arr_4_Ptr     :=
                              new Byte_Arr_4 (1 .. Max, 1 .. Max);
   Byte_Arr_6_Ptr_Obj     : Byte_Arr_4_Ptr     := new Byte_Arr_4 (Big, Big);
   Constr_Arr_1_Ptr_Obj   : Constr_Arr_1_Ptr   := new Constr_Arr_1;
   Constr_Arr_2_Ptr_Obj   : Constr_Arr_2_Ptr   := new Constr_Arr_2;
   Constr_Arr_3_Ptr_Obj   : Constr_Arr_3_Ptr   := new Constr_Arr_3;
   Constr_Arr_4_Ptr_Obj   : Constr_Arr_4_Ptr   := new Constr_Arr_4;
   Unconstr_Arr_1_Ptr_Obj : Unconstr_Arr_1_Ptr :=
                              new Unconstr_Arr_1 (1 .. Max);
   Unconstr_Arr_2_Ptr_Obj : Unconstr_Arr_1_Ptr := new Unconstr_Arr_1 (Big);
   Unconstr_Arr_3_Ptr_Obj : Unconstr_Arr_2_Ptr :=
                              new Unconstr_Arr_2 (1 .. Max, 1 .. Max);
   Unconstr_Arr_4_Ptr_Obj : Unconstr_Arr_2_Ptr :=
                              new Unconstr_Arr_2 (Big, Big);
   Subt_Arr_1_Ptr_Obj     : Subt_Arr_1_Ptr     := new Subt_Arr_1;
   Subt_Arr_2_Ptr_Obj     : Subt_Arr_2_Ptr     := new Subt_Arr_2;
   Subt_Arr_3_Ptr_Obj     : Subt_Arr_3_Ptr     := new Subt_Arr_3;
   Subt_Arr_4_Ptr_Obj     : Subt_Arr_4_Ptr     := new Subt_Arr_4;
   Str_Ptr_1_Obj          : Str_Ptr            := new String (1 .. Max);
   Str_Ptr_2_Obj          : Str_Ptr            := new String (Big);
   Subt_Str_1_Ptr_Obj     : Subt_Str_1_Ptr     := new Subt_Str_1;
   Subt_Str_2_Ptr_Obj     : Subt_Str_2_Ptr     := new Subt_Str_2;
begin null; end Main;

----------------------------
-- Compilation and output --
----------------------------

$ gcc -c -S -gnatDG -gnatws main.adb
$ grep -c "others => types__TbyteB!(0));" main.adb.dg
$ grep -c "others => integer!(0));" main.adb.dg
$ grep -c "others => character!(0));" main.adb.dg
$ grep -c "others => types__TbyteB!(0));" main.adb.dg
$ grep -c "memset" main.s
8
12
8
8
44

2018-05-22  Hristian Kirtchev  <kirtchev@adacore.com>

gcc/ada/

	* exp_aggr.adb (Aggr_Assignment_OK_For_Backend): Strip away any
	conversions before extracting the value of the expression.
	* exp_ch3.adb (Default_Initialize_Object): Optimize the default
	initialization of an array of scalars.
	(Get_Simple_Init_Val): Add processing for array types. Remove the
	processing of strings because this case is already handled by the array
	case.
	(Needs_Simple_Initialization): Moved to Sem_Util.
	(Simple_Init_Array_Type): New routine.
	(Simple_Init_Initialize_Scalars_Type): Reimplemented to use the new
	facilities from Sem_Util.
	(Simple_Initialization_OK): New routine.
	* exp_ch3.ads (Needs_Simple_Initialization): Moved to Sem_Util.
	* exp_ch4.adb (Expand_N_Allocator): Optimize the default allocation of
	an array of scalars.
	* sem_prag.adb (Analyze_Float_Value): New routine.
	(Analyze_Integer_Value): New routine.
	(Analyze_Pragma): Reimplement the analysis of pragma Initialize_Scalars
	to handled the extended form of the pragma.
	(Analyze_Type_Value_Pair): New routine.
	* sem_util.adb: Add invalid value-related data structures.
	(Examine_Array_Bounds): New routine.
	(Has_Static_Array_Bounds): Reimplemented.
	(Has_Static_Non_Empty_Array_Bounds): New routine.
	(Invalid_Scalar_Value): New routine.
	(Needs_Simple_Initialization): Moved from Exp_Ch3.
	(Set_Invalid_Scalar_Value): New routines.
	* sem_util.ads (Has_Static_Non_Empty_Array_Bounds): New routine.
	(Invalid_Scalar_Value): New routine.
	(Needs_Simple_Initialization): Moved from Exp_Ch3.
	(Set_Invalid_Scalar_Value): New routines.
	* snames.ads-tmpl: Add names for the salar type families used by pragma
	Initialize_Scalars.

From-SVN: r260529
2018-05-22 13:26:28 +00:00
config Improve boostrap-ubsan config (PR bootstrap/64914). 2018-05-10 10:15:42 +00:00
contrib re PR bootstrap/85571 (non-bootstrap-debug miscompare with trunk) 2018-05-08 08:50:33 +00:00
fixincludes re PR jit/85384 (libgccjit does not work if --with-gcc-major-version is used) 2018-04-18 11:46:58 +02:00
gcc [Ada] In-place initialization for Initialize_Scalars 2018-05-22 13:26:28 +00:00
gnattools Update copyright years. 2018-01-03 11:03:58 +01:00
gotools go/build, cmd/go: update to match recent changes to gc 2018-05-09 21:49:47 +00:00
include ansidecl.h (ATTRIBUTE_NONSTRING): Define. 2018-05-02 19:21:45 +09:30
INSTALL
intl Require ngettext in test of system gettext implementation 2017-11-07 15:24:01 +10:30
libada re PR jit/85384 (libgccjit does not work if --with-gcc-major-version is used) 2018-04-18 11:46:58 +02:00
libatomic [testsuite] Add scan-ltrans-tree-dump 2018-05-02 12:16:32 +00:00
libbacktrace Regenerate configure of target libraries 2018-04-24 09:45:26 -07:00
libcc1 PR c++/69560 - wrong alignof(double) on x86. 2018-04-23 16:49:38 -04:00
libcpp line-map.c (linemap_init): Use placement new. 2018-05-17 19:28:34 -04:00
libdecnumber Do not use bit and for conjunction of predicates (PR c/81272). 2018-02-19 18:29:20 +00:00
libffi Backport of RISC-V support for libffi 2018-05-08 10:29:16 +00:00
libgcc RISC-V: Add RV32E support. 2018-05-18 15:53:55 -07:00
libgfortran re PR fortran/54613 ([F08] Add FINDLOC plus support MAXLOC/MINLOC with KIND=/BACK=) 2018-05-08 07:47:19 +00:00
libgo go/build, cmd/go: update to match recent changes to gc 2018-05-09 21:49:47 +00:00
libgomp re PR fortran/85841 ([F2018] reject deleted features) 2018-05-21 22:48:59 +02:00
libhsail-rt [BRIGFE] phsa-specific optimizations 2018-05-04 19:43:57 +00:00
libiberty Improve boostrap-ubsan config (PR bootstrap/64914). 2018-05-10 10:15:42 +00:00
libitm PR c++/58407 - deprecated implicit copy ops. 2018-05-18 16:02:48 -04:00
libmpx Regenerate configure of target libraries 2018-04-24 09:45:26 -07:00
libobjc Regenerate configure of target libraries 2018-04-24 09:45:26 -07:00
liboffloadmic re PR jit/85384 (libgccjit does not work if --with-gcc-major-version is used) 2018-04-18 11:46:58 +02:00
libquadmath Regenerate configure of target libraries 2018-04-24 09:45:26 -07:00
libsanitizer If someone has access to a 64-bit mips-linux system to test this (with the obvious edit), that'd be really nice. 2018-04-26 01:16:47 +00:00
libssp Regenerate configure of target libraries 2018-04-24 09:45:26 -07:00
libstdc++-v3 Add support for opening file streams from wide character strings 2018-05-21 18:18:35 +01:00
libvtv [testsuite] Add scan-ltrans-tree-dump 2018-05-02 12:16:32 +00:00
lto-plugin re PR jit/85384 (libgccjit does not work if --with-gcc-major-version is used) 2018-04-18 11:46:58 +02:00
maintainer-scripts re PR other/85622 (gcc-8.1.0/NEWS says it's not released yet) 2018-05-03 11:29:39 +02:00
zlib re PR bootstrap/79771 (in-tree zlib breaks build) 2017-03-14 23:01:23 -06:00
.dir-locals.el
.gitattributes
.gitignore .gitignore: Ignore in-tree prerequisites. 2016-09-09 17:20:55 -04:00
ABOUT-NLS
ChangeLog * MAINTAINERS (loop-optimizer): Add myself. 2018-05-22 08:26:50 +00:00
ChangeLog.jit
ChangeLog.tree-ssa
compile
config-ml.in config-ml.in: Remove references to GCJ. 2016-11-15 16:34:02 +00:00
config.guess config.guess: Import latest version. 2018-01-03 15:25:18 +11:00
config.rpath
config.sub config.guess: Import latest version. 2018-01-03 15:25:18 +11:00
configure Add the Netronome Flow Processor (nfp) as a build target to the top-level configure.ac file. 2018-05-01 15:26:51 +00:00
configure.ac Add the Netronome Flow Processor (nfp) as a build target to the top-level configure.ac file. 2018-05-01 15:26:51 +00:00
COPYING
COPYING.LIB
COPYING.RUNTIME
COPYING3
COPYING3.LIB
depcomp
install-sh
libtool-ldflags
libtool.m4
ltgcc.m4
ltmain.sh
ltoptions.m4
ltsugar.m4
ltversion.m4
lt~obsolete.m4
MAINTAINERS * MAINTAINERS (loop-optimizer): Add myself. 2018-05-22 08:26:50 +00:00
Makefile.def Remove Cilk Plus support. 2017-11-28 11:35:37 +01:00
Makefile.in re PR bootstrap/85571 (non-bootstrap-debug miscompare with trunk) 2018-04-30 08:18:03 +00:00
Makefile.tpl re PR bootstrap/85571 (non-bootstrap-debug miscompare with trunk) 2018-04-30 08:18:03 +00:00
missing
mkdep
mkinstalldirs
move-if-change
README
symlink-tree
ylwrap

This directory contains the GNU Compiler Collection (GCC).

The GNU Compiler Collection is free software.  See the files whose
names start with COPYING for copying permission.  The manuals, and
some of the runtime libraries, are under different terms; see the
individual source files for details.

The directory INSTALL contains copies of the installation information
as HTML and plain text.  The source of this information is
gcc/doc/install.texi.  The installation information includes details
of what is included in the GCC sources and what files GCC installs.

See the file gcc/doc/gcc.texi (together with other files that it
includes) for usage and porting information.  An online readable
version of the manual is in the files gcc/doc/gcc.info*.

See http://gcc.gnu.org/bugs/ for how to report bugs usefully.

Copyright years on GCC source files may be listed using range
notation, e.g., 1987-2012, indicating that every year in the range,
inclusive, is a copyrightable year that could otherwise be listed
individually.