[Ada] Simplify return mechanism handling in gigi

Eric Botcazou ebotcazou@adacore.com
Thu Apr 8 20:20:00 GMT 2010


Gigi currently supports 4 mechanisms for returning a value from a function:

 1. Regular return,
 2. Return by direct reference, i.e. the callee returns a pointer to a memory 
location it has allocated, the caller dereferences the pointer.
 3. Return by invisible reference, i.e. the caller passes a pointer to a 
memory location it has allocated, the callee dereferences the pointer.
 4. Return by target pointer, i.e. the caller passes a pointer to a memory 
location it has allocated as first argument, the callee dereferences the 
pointer.

#3 can be simplified a little.  #4 is quite similar to #3.  In fact #4 was 
born out of #3 during the GCC 3 -> GCC 4 transition, because #3 is entirely 
implemented in the back-end and broke; #4 is basically #3 but redone in gigi.

The patch folds back #4 into #1 (contrained return types with non-fixed size) 
and #3 (unconstrained return types with default discriminants), thus bringing 
us back to the GCC 3 state.  This saves a bit of code as well eliminates a 
pessimization:

          /* ??? We may be about to create a static temporary if we happen to
             be at the global binding level.  That's a regression from what
             the 3.x back-end would generate in the same situation, but we
             don't have a mechanism in Gigi for creating automatic variables
             in the elaboration routines.  */


Tested on i586-suse-linux and x86_64-suse-linux on top of
  http://gcc.gnu.org/ml/gcc-patches/2010-04/msg00301.html
and applied on the mainline.


2010-04-08  Eric Botcazou  <ebotcazou@adacore.com>

	* gcc-interface/ada-tree.h (TYPE_RETURNS_UNCONSTRAINED_P): Rename into.
	(TYPE_RETURN_UNCONSTRAINED_P): ...this.
	(TYPE_RETURNS_BY_REF_P): Rename into.
	(TYPE_RETURN_BY_DIRECT_REF_P): ...this.
	(TYPE_RETURNS_BY_TARGET_PTR_P): Delete.
	* gcc-interface/gigi.h (create_subprog_type): Adjust parameter names.
	(build_return_expr): Likewise.
	* gcc-interface/decl.c (gnat_to_gnu_entity) <E_Subprogram_Type>:
	Rename local variables.  If the return Mechanism is By_Reference, pass
	return_by_invisible_ref_p to create_subprog_type instead of toggling
	TREE_ADDRESSABLE.  Test return_by_invisible_ref_p in order to annotate
	the mechanism.  Use regular return for contrained types with non-static
	size and return by invisible reference for unconstrained return types
	with default discriminants.  Update comment.
	* gcc-interface/trans.c (Subprogram_Body_to_gnu): If the function
	returns by invisible reference, turn the RESULT_DECL into a pointer.
	Do not handle DECL_BY_REF_P in the CICO case here.
	(call_to_gnu): Remove code handling return by target pointer.  For a
	function call, if the return type has non-constant size, generate the
	assignment with an INIT_EXPR.
	(gnat_to_gnu) <N_Return_Statement>: Remove dead code in the CICO case.
	If the function returns by invisible reference, build the copy return
	operation manually.
	(add_decl_expr): Initialize the variable with an INIT_EXPR.
	* gcc-interface/utils.c (create_subprog_type): Adjust parameter names.
	Adjust for renaming of macros.  Copy the node only when necessary.
	(create_subprog_decl): Do not toggle TREE_ADDRESSABLE on the return
	type, only change DECL_BY_REFERENCE on the RETURN_DECL.
	(convert_from_reference): Delete.
	(is_byref_result): Likewise.
	(gnat_genericize_r): Likewise.
	(gnat_genericize): Likewise.
	(end_subprog_body): Do not call gnat_genericize.
	* gcc-interface/utils2.c (build_binary_op) <INIT_EXPR>: New case.
	(build_return_expr): Adjust parameter names, logic and comment.


-- 
Eric Botcazou
-------------- next part --------------
A non-text attachment was scrubbed...
Name: p.diff
Type: text/x-diff
Size: 47645 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20100408/431edda8/attachment.bin>


More information about the Gcc-patches mailing list