This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Ada] gigi fixes - 2


Tested on i686-linux, committed on trunk

Gigi contained an unprotected use of Full_View that should only have been
applied to deferred constants, but was being applied to other entities such
as enumeration literals (where it picked up the Enumeration_Pos Uint field,
causing a blow-up) and variables (where it picked up an unused zero field).
This was only occurring for entities of a private type with unknown
discriminants. The fix is simply to check for an E_Constant before applying
Full_View.

gnat.dg/test_unknown_discrs must compile quietly.

Also, during a non-optimized compilation the compiler only performs very limited
transformations on the raw code generated from the representation of the
program built by the language processor; in particular, no attempts at doing
Common Subexpression Elimination are made.
This can result in a great deal of redundant instructions generated for
pervasive idioms of the language and increase the size of the executable.
This can be observed in Ada for the 'First, 'Last and 'Length attributes of
unconstrained array IN parameters.
The change implements a per-function cache for these attributes in Gigi.
It cuts the number of basic blocks for the following code by a factor of 8:
-----
package P is

  type List is array (Natural range <>) of Integer;

  function "-" (Left, Right : List) return List;

end P;
-----
package body P is

  function "-" (Left, Right : List) return List is
    Internal_Left     : List (1 .. Left'LENGTH)  := Left;
    Internal_Right    : List (1 .. Right'LENGTH) := Right;
    Result            : List (1 .. Left'LENGTH + Right'LENGTH);
    Number_Of_Periods : Natural;
  begin
    if Left'LENGTH = Right'LENGTH and then Left = Right then
      Number_Of_Periods := 0;
    end if;
    return Result;
  end;

end P;

This patch also implements pragma Inspection_Point which was missing in gcc 4
(this feature was not working after the move from gcc 3.4).
A gdb test is the best method to check this feature. So no testcase here.

Gigi has also been enhanced to prevent certain kind of unchecked conversions
between integral types from being effectively eliminated by the Value
Range Propagation pass, most notably in order to properly support the
'Valid attribute.  For such conversions, a special VIEW_CONVERT_EXPR is
generated that the VRP is not allowed to bypass.
However this can be problematic when the underlying object is a constant
because the VIEW_CONVERT_EXPR of a constant is spilled to memory at the
RTL level, which is not allowed at the library level for example.

gnat.dg/specs/uc1.ads must silently compile.

Finally, the Ada compiler uses a custom method to emit debug information for
records with variable-sized fields. It builds a regular "parallel" record type
whose fields encode enough information about the position and alignment of
fields in the original record for the debugger to reconstruct the latter. The
main idea is to replace fields with variable-sized type by pointers to this
type.
The problem here is that the DWARF-2 debug back-end may modify the position of
these pointer fields according to the alignment of the pointer types, whereas
this position is related to the alignment of the original type.

2007-06-06  Gary Dismukes  <dismukes@adacore.com>
	    Eric Botcazou  <ebotcazou@adacore.com>
	    Tristan Gingold  <gingold@adacore.com>
	    Olivier Hainque  <hainque@adacore.com>

	* gigi.h, trans.c (Identifier_to_gnu): Change test for deferred
	constant by adding guard that the entity is an E_Constant before
	testing presence of Full_view (and remove now-unnecessary test that
	entity is not a type).
	For a CONST_DECL used by reference, manually retrieve
	the DECL_INITIAL.  Do not invoke fold in the other DECL_P cases either.
	(struct language_function): Move from utils.c to here.
	(struct parm_attr): New structure.
	(parm_attr, parm_attr vector, parm_attr GC vector): New types.
	(f_parm_attr_cache): New macro.
	(Attribute_to_gnu) <Attr_Length>: When not optimizing, cache the
	expressions for the 'First, 'Last and 'Length attributes of the
	unconstrained array IN parameters.
	(Subprogram_Body_to_gnu): Use gnu_subprog_decl throughout.
	Allocate the information structure for the function earlier, as well
	as the language-specific part.
	If the parameter attributes cache has been populated, evaluate the
	cached expressions on entry.
	(takes_address): Add OPERAND_TYPE parameter.  Handle N_Function_Call,
	N_Procedure_Call_Statement and N_Indexed_Component.
	(Pragma_to_gnu): Translate inspection_point to an asm statement
	containaing a comment and a reference to the object (either its address
	for BLKmode or its value).
	(Identifier_to_gnu): Use TREE_CONSTANT instead of CONST_DECL to decide
	to go to DECL_INITIAL. Together with the size constraint relaxation
	in create_var_decl, enlarges the set of situations in which an
	identifier may be used as an initializer without implying elaboration
	code.
	(Subprogram_Body_to_gnu): Do not fiddle with the debug interface but set
	DECL_IGNORED_P on the function if Needs_Debug_Info is not set on the
	node.
	(maybe_stabilize_reference): Remove lvalues_only parameter.
	(gnat_stabilize_reference): Adjust for above change.
	(gnat_to_gnu): Do not set location information on the result
	if it is a reference.
	(add_cleanup): Add gnat_node parameter and set the location of the
	cleanup to it.
	(Handled_Sequence_Of_Statements_to_gnu): Adjust calls to add_cleanup.
	(Exception_Handler_to_gnu_zcx): Likewise.
	(gigi): Remove the cgraph node if the elaboration procedure is empty.
	(Subprogram_Body_to_gnu): If a stub is attached to the subprogram, emit
	the former right after the latter.
	(start_stmt_group): Make global.
	(end_stmt_group): Likewise.
	(gnu_constraint_error_label_stack, gnu_storage_error_label_stack): New
	vars.
	(gnu_program_error_label_stack): Likewise.
	(gigi): Initialize them.
	(call_to_gnu, gnat_to_gnu, emit_check): Add new arg to build_call_raise.
	(gnat_to_gnu, N_{Push,Pop}_{Constraint,Storage,Program}_Error_Label):
	New cases.
	(push_exception_label_stack): New function.
	(takes_address): New function.

	* utils.c (struct language_function): Move to trans.c from here.
	(unchecked_convert): Do not wrap up integer constants in
	VIEW_CONVERT_EXPRs.
	(create_var_decl_1): Decouple TREE_CONSTANT from CONST_DECL. Prevent
	the latter for aggregate types, unexpected by later passes, and relax an
	arbitrary size constraint on the former.
	(create_field_decl): Use tree_int_cst_equal instead of operand_equal_p
	to compare the sizes.
	(convert_vms_descriptor): When converting to a fat pointer type, be
	prepared for a S descriptor at runtime in spite of a SB specification.
	(shift_unc_components_for_thin_pointers): New function.
	(write_record_type_debug_info): For variable-sized fields, cap the
	alignment of the pointer to the computed alignment.
	(finish_record_type): Change HAS_REP parameter into REP_LEVEL.
	If REP_LEVEL is 2, do not compute the sizes.
	(build_vms_descriptor): Adjust for new prototype of finish_record_type.
	(build_unc_object_type): Likewise.
	(declare_debug_type): New function.

        * ada-tree.def: USE_STMT: removed (not emitted anymore).

        * misc.c (gnat_expand_expr): Call to gnat_expand_stmt removed because
        no statement is expandable anymore.
        (gnat_init_gcc_eh): Do not initialize the DWARF-2 CFI machinery twice.
        (gnat_handle_option): Only allow flag_eliminate_debug_types to be set
        when the user requested it explicitely.
        (gnat_post_options): By default, set flag_eliminate_unused_debug_types
        to 0 for Ada.
        (get_alias_set): Return alias set 0 for a type if
        TYPE_UNIVERSAL_ALIASING_P is set on its main variant.

        * ada-tree.h: (TYPE_UNIVERSAL_ALIASING_P): New macro.
        (DECL_FUNCTION_STUB): New accessor macro.
        (SET_DECL_FUNCTION_STUB): New setter macro.

        * lang.opt (feliminate-unused-debug-types): Intercept this flag for Ada.

	* fe.h (Get_Local_Raise_Call_Entity, Get_RT_Exception_Entity): New
	declarations.

Attachment: difs
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]