Fix code emission for FAIL_ALLOC predictor
authorMartin Liska <mliska@suse.cz>
Thu, 16 Jun 2016 12:21:55 +0000 (14:21 +0200)
committerMartin Liska <marxin@gcc.gnu.org>
Thu, 16 Jun 2016 12:21:55 +0000 (12:21 +0000)
* predict.def: Define a new predictor.
* trans-array.c (gfc_array_allocate): Do not generate expect
stmt.
* trans.c (gfc_allocate_using_malloc): Properly set FAIL_ALLOC
predictor for malloc return value.
(gfc_allocate_allocatable): Use REALLOC predictor instead of
FAIL_ALLOC.
(gfc_deallocate_with_status): Likewise.

From-SVN: r237524

gcc/ChangeLog
gcc/fortran/ChangeLog
gcc/fortran/trans-array.c
gcc/fortran/trans.c
gcc/predict.def

index 9138fd3a44995338f1dc349676a4fb6a4dcc0a51..0e95c7028f67af4af968399082bed1cdab258cd0 100644 (file)
@@ -1,3 +1,7 @@
+2016-06-16  Martin Liska  <mliska@suse.cz>
+
+       * predict.def: Define a new predictor.
+
 2016-06-16  Claudiu Zissulescu  <claziss@synopsys.com>
 
        * config/arc/arc.opt (mtp-regno): Update text.
index 998255a9bff26f8b71bc0efe4e3cf2cc6edad170..9ba155430802df01ec264f47c5ea7e617a3181d8 100644 (file)
@@ -1,3 +1,13 @@
+2016-06-16  Martin Liska  <mliska@suse.cz>
+
+       * trans-array.c (gfc_array_allocate): Do not generate expect
+       stmt.
+       * trans.c (gfc_allocate_using_malloc): Properly set FAIL_ALLOC
+       predictor for malloc return value.
+       (gfc_allocate_allocatable): Use REALLOC predictor instead of
+       FAIL_ALLOC.
+       (gfc_deallocate_with_status): Likewise.
+
 2016-06-13  Paul Thomas  <pault@gcc.gnu.org>
 
        PR fortran/70673
index 403ce3a750dd96d56768fe7992388d1e8ccb7ab4..e95c8dd82353ea3c785d05bcde253415151dbcdc 100644 (file)
@@ -5553,7 +5553,7 @@ gfc_array_allocate (gfc_se * se, gfc_expr * expr, tree status, tree errmsg,
                          build_int_cst (TREE_TYPE (status), 0));
       gfc_add_expr_to_block (&se->pre,
                 fold_build3_loc (input_location, COND_EXPR, void_type_node,
-                                 gfc_likely (cond, PRED_FORTRAN_FAIL_ALLOC),
+                                 cond,
                                  set_descriptor,
                                  build_empty_stmt (input_location)));
     }
index c6688d351a790e76b37aa5c359cdfeccd842ef5d..d6b4a564bf5fb85f7947a2e52d8e85902c8a814b 100644 (file)
@@ -672,9 +672,6 @@ gfc_allocate_using_malloc (stmtblock_t * block, tree pointer,
   gfc_start_block (&on_error);
   if (status != NULL_TREE)
     {
-      gfc_add_expr_to_block (&on_error,
-                            build_predict_expr (PRED_FORTRAN_FAIL_ALLOC,
-                                                NOT_TAKEN));
       tmp = fold_build2_loc (input_location, MODIFY_EXPR, status_type, status,
                             build_int_cst (status_type, LIBERROR_ALLOCATION));
       gfc_add_expr_to_block (&on_error, tmp);
@@ -693,7 +690,8 @@ gfc_allocate_using_malloc (stmtblock_t * block, tree pointer,
                                boolean_type_node, pointer,
                                build_int_cst (prvoid_type_node, 0));
   tmp = fold_build3_loc (input_location, COND_EXPR, void_type_node,
-                        error_cond, gfc_finish_block (&on_error),
+                        gfc_unlikely (error_cond, PRED_FORTRAN_FAIL_ALLOC),
+                        gfc_finish_block (&on_error),
                         build_empty_stmt (input_location));
 
   gfc_add_expr_to_block (block, tmp);
@@ -796,7 +794,7 @@ gfc_allocate_allocatable (stmtblock_t * block, tree mem, tree size, tree token,
   null_mem = gfc_unlikely (fold_build2_loc (input_location, NE_EXPR,
                                            boolean_type_node, mem,
                                            build_int_cst (type, 0)),
-                          PRED_FORTRAN_FAIL_ALLOC);
+                          PRED_FORTRAN_REALLOC);
 
   /* If mem is NULL, we call gfc_allocate_using_malloc or
      gfc_allocate_using_lib.  */
@@ -1385,7 +1383,7 @@ gfc_deallocate_with_status (tree pointer, tree status, tree errmsg,
          cond2 = fold_build2_loc (input_location, NE_EXPR, boolean_type_node,
                                   stat, build_zero_cst (TREE_TYPE (stat)));
          tmp = fold_build3_loc (input_location, COND_EXPR, void_type_node,
-                                gfc_unlikely (cond2, PRED_FORTRAN_FAIL_ALLOC),
+                                gfc_unlikely (cond2, PRED_FORTRAN_REALLOC),
                                 tmp, build_empty_stmt (input_location));
          gfc_add_expr_to_block (&non_null, tmp);
        }
index c0a3f3684a9683e2c192571aa2d905293272de03..da4f9ab78285f5d34c853ffb5761e23f6c59f977 100644 (file)
@@ -163,12 +163,15 @@ DEF_PREDICTOR (PRED_FORTRAN_OVERFLOW, "overflow", PROB_ALWAYS,
               PRED_FLAG_FIRST_MATCH)
 
 /* Branch leading to a failure status are unlikely.  This can occur for out
-   of memory or when trying to allocate an already allocated allocated or
-   deallocating an already deallocated allocatable.  This predictor only
-   occurs when the user explicitly asked for a return status.  By default,
-   the code aborts, which is handled via PRED_NORETURN.
-   FIXME: the hitrate really ought to be close to 100%.  */
-DEF_PREDICTOR (PRED_FORTRAN_FAIL_ALLOC, "fail alloc", HITRATE (62), 0)
+   of memory.  This predictor only occurs when the user explicitly asked
+   for a return status.  By default, the code aborts,
+   which is handled via PRED_NORETURN.  */
+DEF_PREDICTOR (PRED_FORTRAN_FAIL_ALLOC, "fail alloc", PROB_VERY_LIKELY, 0)
+
+/* Predictor is used for an allocation of an already allocated memory or
+   deallocating an already deallocated allocatable.  */
+DEF_PREDICTOR (PRED_FORTRAN_REALLOC, "repeated allocation/deallocation", \
+              PROB_LIKELY, 0)
 
 /* Branch leading to an I/O failure status are unlikely.  This predictor is
    used for I/O failures such as for invalid unit numbers.  This predictor