From 71196d4e64ec6408e9a45a92d76abb9e715d8cc1 Mon Sep 17 00:00:00 2001 From: Eric Botcazou Date: Fri, 7 Oct 2011 11:17:55 +0000 Subject: gigi.h (gnat_useless_type_conversion): Declare. * gcc-interface/gigi.h (gnat_useless_type_conversion): Declare. (rest_of_subprog_body_compilation): Likewise. * gcc-interface/decl.c (gnat_to_gnu_entity) : For renaming, test for useless conversions by means of gnat_useless_type_conversion. * gcc-interface/trans.c: Include bitmap.h and cgraph.h. (language_function): Add named_ret_val and other_ret_val. (f_named_ret_val): New macro. (f_other_ret_val): Likewise. (gigi): Call rest_of_subprog_body_compilation. (struct nrv_data): New structure. (is_nrv_p): New predicate. (prune_nrv_r): New helper function. (prune_nrv_in_block): New function. (finalize_nrv_r): New helper function. (finalize_nrv): New function. (return_value_ok_for_nrv_p): New predicate. (build_return_expr): If optimization is enabled, record candidates for the Named Return Value optimization. (build_function_stub): Call rest_of_subprog_body_compilation. (Subprogram_Body_to_gnu): If optimization is enabled and there are candidates, finalize the Named Return Value optimization. Call rest_of_subprog_body_compilation. (call_to_gnu): At the end, if a return value is needed, simplify the result before wrapping it up in a COMPOUND_EXPR. * gcc-interface/utils.c (end_subprog_body): Split into... (rest_of_subprog_body_compilation): ...this. New function. (gnat_useless_type_conversion): Likewise. From-SVN: r179650 --- gcc/ada/gcc-interface/utils.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'gcc/ada/gcc-interface/utils.c') diff --git a/gcc/ada/gcc-interface/utils.c b/gcc/ada/gcc-interface/utils.c index feae636..62d9d67 100644 --- a/gcc/ada/gcc-interface/utils.c +++ b/gcc/ada/gcc-interface/utils.c @@ -1958,7 +1958,7 @@ begin_subprog_body (tree subprog_decl) make_decl_rtl (subprog_decl); } -/* Finish the definition of the current subprogram BODY and finalize it. */ +/* Finish translating the current subprogram and set its BODY. */ void end_subprog_body (tree body) @@ -1983,7 +1983,13 @@ end_subprog_body (tree body) DECL_SAVED_TREE (fndecl) = body; current_function_decl = DECL_CONTEXT (fndecl); +} + +/* Wrap up compilation of SUBPROG_DECL, a subprogram body. */ +void +rest_of_subprog_body_compilation (tree subprog_decl) +{ /* We cannot track the location of errors past this point. */ error_gnat_node = Empty; @@ -1992,15 +1998,15 @@ end_subprog_body (tree body) return; /* Dump functions before gimplification. */ - dump_function (TDI_original, fndecl); + dump_function (TDI_original, subprog_decl); /* ??? This special handling of nested functions is probably obsolete. */ - if (!DECL_CONTEXT (fndecl)) - cgraph_finalize_function (fndecl, false); + if (!DECL_CONTEXT (subprog_decl)) + cgraph_finalize_function (subprog_decl, false); else /* Register this function with cgraph just far enough to get it added to our parent's nested function list. */ - (void) cgraph_get_create_node (fndecl); + (void) cgraph_get_create_node (subprog_decl); } tree @@ -2194,6 +2200,20 @@ gnat_types_compatible_p (tree t1, tree t2) return 0; } +/* Return true if EXPR is a useless type conversion. */ + +bool +gnat_useless_type_conversion (tree expr) +{ + if (CONVERT_EXPR_P (expr) + || TREE_CODE (expr) == VIEW_CONVERT_EXPR + || TREE_CODE (expr) == NON_LVALUE_EXPR) + return gnat_types_compatible_p (TREE_TYPE (expr), + TREE_TYPE (TREE_OPERAND (expr, 0))); + + return false; +} + /* Return true if T, a FUNCTION_TYPE, has the specified list of flags. */ bool -- cgit v1.1