[Ada] Optimize calls to pure functions with by-ref In parameter

Eric Botcazou ebotcazou@adacore.com
Sat Jul 7 10:06:00 GMT 2018


With GNAT you can declare a function as pure with a dedicated pragma, even if 
it takes a parameter passed by reference.  In this case, if the parameter is 
declared as In (the default), the language additionally guarantees that it is 
not modified, thus making the function also pure in the GCC sense.

Tested on x86-64/Linux, applied on the mainline.


2018-07-07  Eric Botcazou  <ebotcazou@adacore.com>

	* gcc-interface/decl.c (gnat_to_gnu_param): Minor tweak.
	(gnat_to_gnu_subprog_type): New pure_flag local variable.  Set it for
	a pure Ada function with a by-ref In parameter.  Propagate it onto the
	function type by means of the TYPE_QUAL_RESTRICT flag.
	* gcc-interface/utils.c (finish_subprog_decl): Set DECL_PURE_P if the
	function type has the TYPE_QUAL_RESTRICT flag set.


2018-07-07  Eric Botcazou  <ebotcazou@adacore.com>

	* gnat.dg/pure_function3a.adb: New test.
	* gnat.dg/pure_function3b.adb: Likewise.
	* gnat.dg/pure_function3c.adb: Likewise.
	* gnat.dg/pure_function3_pkg.ads: New helper.

-- 
Eric Botcazou
-------------- next part --------------
A non-text attachment was scrubbed...
Name: p.diff
Type: text/x-patch
Size: 4226 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20180707/07d942fa/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pure_function3_pkg.ads
Type: text/x-adasrc
Size: 329 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20180707/07d942fa/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pure_function3a.adb
Type: text/x-adasrc
Size: 364 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20180707/07d942fa/attachment-0002.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pure_function3b.adb
Type: text/x-adasrc
Size: 384 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20180707/07d942fa/attachment-0003.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pure_function3c.adb
Type: text/x-adasrc
Size: 380 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20180707/07d942fa/attachment-0004.bin>


More information about the Gcc-patches mailing list