static void fini_copy_prop (void) { unsigned i; /* Set the final copy-of value for each variable by traversing the copy-of chains. */ for (i = 1; i < num_ssa_names; i++) { tree var = ssa_name (i); if (!var || !copy_of[i].value || copy_of[i].value == var) continue; /* In theory the points-to solution of all members of the copy chain is their intersection. For now we do not bother to compute this but only make sure we do not lose points-to information completely by setting the points-to solution of the representative to the first solution we find if it doesn't have one already. */ if (copy_of[i].value != var && TREE_CODE (copy_of[i].value) == SSA_NAME && POINTER_TYPE_P (TREE_TYPE (var)) && SSA_NAME_PTR_INFO (var) && !SSA_NAME_PTR_INFO (copy_of[i].value)) duplicate_ssa_name_ptr_info (copy_of[i].value, SSA_NAME_PTR_INFO (var)); } /* Don't do DCE if we have loops. That's the simplest way to not destroy the scev cache. */ substitute_and_fold (get_value, NULL, !current_loops); free (copy_of); }
/* Return SSA names that are unused to GGC memory and compact the SSA version namespace. This is used to keep footprint of compiler during interprocedural optimization. */ static unsigned int release_dead_ssa_names (void) { unsigned i, j; int n = vec_safe_length (FREE_SSANAMES (cfun)); /* Now release the freelist. */ vec_free (FREE_SSANAMES (cfun)); /* And compact the SSA number space. We make sure to not change the relative order of SSA versions. */ for (i = 1, j = 1; i < cfun->gimple_df->ssa_names->length (); ++i) { tree name = ssa_name (i); if (name) { if (i != j) { SSA_NAME_VERSION (name) = j; (*cfun->gimple_df->ssa_names)[j] = name; } j++; } } cfun->gimple_df->ssa_names->truncate (j); statistics_counter_event (cfun, "SSA names released", n); statistics_counter_event (cfun, "SSA name holes removed", i - j); if (dump_file) fprintf (dump_file, "Released %i names, %.2f%%, removed %i holes\n", n, n * 100.0 / num_ssa_names, i - j); return 0; }
static temp_expr_table_p new_temp_expr_table (var_map map) { temp_expr_table_p t; unsigned x; t = XNEW (struct temp_expr_table_d); t->map = map; t->partition_dependencies = XCNEWVEC (bitmap, num_ssa_names + 1); t->expr_decl_uids = XCNEWVEC (bitmap, num_ssa_names + 1); t->kill_list = XCNEWVEC (bitmap, num_var_partitions (map) + 1); t->partition_in_use = BITMAP_ALLOC (NULL); t->virtual_partition = num_var_partitions (map); t->new_replaceable_dependencies = BITMAP_ALLOC (NULL); t->replaceable_expressions = NULL; t->num_in_part = XCNEWVEC (int, num_var_partitions (map)); for (x = 1; x < num_ssa_names; x++) { int p; tree name = ssa_name (x); if (!name) continue; p = var_to_partition (map, name); if (p != NO_PARTITION) t->num_in_part[p]++; } return t; }
tree make_ssa_name_fn (struct function *fn, tree var, gimple stmt) { tree t; use_operand_p imm; gcc_assert (TREE_CODE (var) == VAR_DECL || TREE_CODE (var) == PARM_DECL || TREE_CODE (var) == RESULT_DECL || (TYPE_P (var) && is_gimple_reg_type (var))); /* If our free list has an element, then use it. */ if (!vec_safe_is_empty (FREE_SSANAMES (fn))) { t = FREE_SSANAMES (fn)->pop (); if (GATHER_STATISTICS) ssa_name_nodes_reused++; /* The node was cleared out when we put it on the free list, so there is no need to do so again here. */ gcc_assert (ssa_name (SSA_NAME_VERSION (t)) == NULL); (*SSANAMES (fn))[SSA_NAME_VERSION (t)] = t; } else { t = make_node (SSA_NAME); SSA_NAME_VERSION (t) = SSANAMES (fn)->length (); vec_safe_push (SSANAMES (fn), t); if (GATHER_STATISTICS) ssa_name_nodes_created++; } if (TYPE_P (var)) { TREE_TYPE (t) = var; SET_SSA_NAME_VAR_OR_IDENTIFIER (t, NULL_TREE); } else { TREE_TYPE (t) = TREE_TYPE (var); SET_SSA_NAME_VAR_OR_IDENTIFIER (t, var); } SSA_NAME_DEF_STMT (t) = stmt; if (POINTER_TYPE_P (TREE_TYPE (t))) SSA_NAME_PTR_INFO (t) = NULL; else SSA_NAME_RANGE_INFO (t) = NULL; SSA_NAME_IN_FREE_LIST (t) = 0; SSA_NAME_IS_DEFAULT_DEF (t) = 0; imm = &(SSA_NAME_IMM_USE_NODE (t)); imm->use = NULL; imm->prev = imm; imm->next = imm; imm->loc.ssa_name = t; return t; }
tree make_ssa_name (tree var, tree stmt) { tree t; use_operand_p imm; gcc_assert (DECL_P (var) || TREE_CODE (var) == INDIRECT_REF); gcc_assert (!stmt || EXPR_P (stmt) || GIMPLE_STMT_P (stmt) || TREE_CODE (stmt) == PHI_NODE); /* If our free list has an element, then use it. */ if (FREE_SSANAMES (cfun)) { t = FREE_SSANAMES (cfun); FREE_SSANAMES (cfun) = TREE_CHAIN (FREE_SSANAMES (cfun)); #ifdef GATHER_STATISTICS ssa_name_nodes_reused++; #endif /* The node was cleared out when we put it on the free list, so there is no need to do so again here. */ gcc_assert (ssa_name (SSA_NAME_VERSION (t)) == NULL); VEC_replace (tree, SSANAMES (cfun), SSA_NAME_VERSION (t), t); } else { t = make_node (SSA_NAME); SSA_NAME_VERSION (t) = num_ssa_names; VEC_safe_push (tree, gc, SSANAMES (cfun), t); #ifdef GATHER_STATISTICS ssa_name_nodes_created++; #endif } TREE_TYPE (t) = TREE_TYPE (var); SSA_NAME_VAR (t) = var; SSA_NAME_DEF_STMT (t) = stmt; SSA_NAME_PTR_INFO (t) = NULL; SSA_NAME_IN_FREE_LIST (t) = 0; SSA_NAME_IS_DEFAULT_DEF (t) = 0; imm = &(SSA_NAME_IMM_USE_NODE (t)); imm->use = NULL; imm->prev = imm; imm->next = imm; imm->stmt = t; return t; }
void dump_immediate_uses (FILE *file) { tree var; unsigned int x; fprintf (file, "Immediate_uses: \n\n"); for (x = 1; x < num_ssa_names; x++) { var = ssa_name(x); if (!var) continue; dump_immediate_uses_for (file, var); } }
tree make_ssa_name_fn (struct function *fn, tree var, gimple stmt) { tree t; use_operand_p imm; gcc_assert (DECL_P (var)); /* If our free list has an element, then use it. */ if (FREE_SSANAMES (fn)) { t = FREE_SSANAMES (fn); FREE_SSANAMES (fn) = TREE_CHAIN (FREE_SSANAMES (fn)); #ifdef GATHER_STATISTICS ssa_name_nodes_reused++; #endif /* The node was cleared out when we put it on the free list, so there is no need to do so again here. */ gcc_assert (ssa_name (SSA_NAME_VERSION (t)) == NULL); VEC_replace (tree, SSANAMES (fn), SSA_NAME_VERSION (t), t); } else { t = make_node (SSA_NAME); SSA_NAME_VERSION (t) = VEC_length (tree, SSANAMES (fn)); VEC_safe_push (tree, gc, SSANAMES (fn), t); #ifdef GATHER_STATISTICS ssa_name_nodes_created++; #endif } TREE_TYPE (t) = TREE_TYPE (var); SSA_NAME_VAR (t) = var; SSA_NAME_DEF_STMT (t) = stmt; SSA_NAME_PTR_INFO (t) = NULL; SSA_NAME_IN_FREE_LIST (t) = 0; SSA_NAME_IS_DEFAULT_DEF (t) = 0; imm = &(SSA_NAME_IMM_USE_NODE (t)); imm->use = NULL; imm->prev = imm; imm->next = imm; imm->loc.ssa_name = t; return t; }
void dump_alias_info (FILE *file) { size_t i; const char *funcname = lang_hooks.decl_printable_name (current_function_decl, 2); referenced_var_iterator rvi; tree var; fprintf (file, "\n\nAlias information for %s\n\n", funcname); fprintf (file, "Aliased symbols\n\n"); FOR_EACH_REFERENCED_VAR (var, rvi) { if (may_be_aliased (var)) dump_variable (file, var); } fprintf (file, "\nCall clobber information\n"); fprintf (file, "\nESCAPED"); dump_points_to_solution (file, &cfun->gimple_df->escaped); fprintf (file, "\nCALLUSED"); dump_points_to_solution (file, &cfun->gimple_df->callused); fprintf (file, "\n\nFlow-insensitive points-to information\n\n"); for (i = 1; i < num_ssa_names; i++) { tree ptr = ssa_name (i); struct ptr_info_def *pi; if (ptr == NULL_TREE || SSA_NAME_IN_FREE_LIST (ptr)) continue; pi = SSA_NAME_PTR_INFO (ptr); if (pi) dump_points_to_info_for (file, ptr); } fprintf (file, "\n"); }
/* Return SSA names that are unused to GGC memory and compact the SSA version namespace. This is used to keep footprint of compiler during interprocedural optimization. */ static unsigned int release_dead_ssa_names (void) { tree t; unsigned i, j; int n = VEC_length (tree, FREE_SSANAMES (cfun)); referenced_var_iterator rvi; /* Current defs point to various dead SSA names that in turn point to eventually dead variables so a bunch of memory is held live. */ FOR_EACH_REFERENCED_VAR (cfun, t, rvi) set_current_def (t, NULL); /* Now release the freelist. */ VEC_free (tree, gc, FREE_SSANAMES (cfun)); FREE_SSANAMES (cfun) = NULL; /* And compact the SSA number space. We make sure to not change the relative order of SSA versions. */ for (i = 1, j = 1; i < VEC_length (tree, cfun->gimple_df->ssa_names); ++i) { tree name = ssa_name (i); if (name) { if (i != j) { SSA_NAME_VERSION (name) = j; VEC_replace (tree, cfun->gimple_df->ssa_names, j, name); } j++; } } VEC_truncate (tree, cfun->gimple_df->ssa_names, j); statistics_counter_event (cfun, "SSA names released", n); statistics_counter_event (cfun, "SSA name holes removed", i - j); if (dump_file) fprintf (dump_file, "Released %i names, %.2f%%, removed %i holes\n", n, n * 100.0 / num_ssa_names, i - j); return 0; }
static void fini_copy_prop (void) { size_t i; prop_value_t *tmp; /* Set the final copy-of value for each variable by traversing the copy-of chains. */ tmp = XCNEWVEC (prop_value_t, num_ssa_names); for (i = 1; i < num_ssa_names; i++) { tree var = ssa_name (i); if (var && copy_of[i].value && copy_of[i].value != var) tmp[i].value = get_last_copy_of (var); } substitute_and_fold (tmp, false); free (cached_last_copy_of); free (copy_of); free (tmp); }
static void fini_copy_prop (void) { size_t i; prop_value_t *tmp; /* Set the final copy-of value for each variable by traversing the copy-of chains. */ tmp = XCNEWVEC (prop_value_t, num_ssa_names); for (i = 1; i < num_ssa_names; i++) { tree var = ssa_name (i); if (!var || !copy_of[i].value || copy_of[i].value == var) continue; tmp[i].value = get_last_copy_of (var); /* In theory the points-to solution of all members of the copy chain is their intersection. For now we do not bother to compute this but only make sure we do not lose points-to information completely by setting the points-to solution of the representative to the first solution we find if it doesn't have one already. */ if (tmp[i].value != var && POINTER_TYPE_P (TREE_TYPE (var)) && SSA_NAME_PTR_INFO (var) && !SSA_NAME_PTR_INFO (tmp[i].value)) duplicate_ssa_name_ptr_info (tmp[i].value, SSA_NAME_PTR_INFO (var)); } substitute_and_fold (tmp, false); free (cached_last_copy_of); free (copy_of); free (tmp); }
static unsigned int rename_ssa_copies (void) { var_map map; basic_block bb; gimple_stmt_iterator gsi; tree var, part_var; gimple stmt, phi; unsigned x; FILE *debug; bool updated = false; memset (&stats, 0, sizeof (stats)); if (dump_file && (dump_flags & TDF_DETAILS)) debug = dump_file; else debug = NULL; map = init_var_map (num_ssa_names); FOR_EACH_BB (bb) { /* Scan for real copies. */ for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) { stmt = gsi_stmt (gsi); if (gimple_assign_ssa_name_copy_p (stmt)) { tree lhs = gimple_assign_lhs (stmt); tree rhs = gimple_assign_rhs1 (stmt); updated |= copy_rename_partition_coalesce (map, lhs, rhs, debug); } } } FOR_EACH_BB (bb) { /* Treat PHI nodes as copies between the result and each argument. */ for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi)) { size_t i; tree res; phi = gsi_stmt (gsi); res = gimple_phi_result (phi); /* Do not process virtual SSA_NAMES. */ if (virtual_operand_p (res)) continue; /* Make sure to only use the same partition for an argument as the result but never the other way around. */ if (SSA_NAME_VAR (res) && !DECL_IGNORED_P (SSA_NAME_VAR (res))) for (i = 0; i < gimple_phi_num_args (phi); i++) { tree arg = PHI_ARG_DEF (phi, i); if (TREE_CODE (arg) == SSA_NAME) updated |= copy_rename_partition_coalesce (map, res, arg, debug); } /* Else if all arguments are in the same partition try to merge it with the result. */ else { int all_p_same = -1; int p = -1; for (i = 0; i < gimple_phi_num_args (phi); i++) { tree arg = PHI_ARG_DEF (phi, i); if (TREE_CODE (arg) != SSA_NAME) { all_p_same = 0; break; } else if (all_p_same == -1) { p = partition_find (map->var_partition, SSA_NAME_VERSION (arg)); all_p_same = 1; } else if (all_p_same == 1 && p != partition_find (map->var_partition, SSA_NAME_VERSION (arg))) { all_p_same = 0; break; } } if (all_p_same == 1) updated |= copy_rename_partition_coalesce (map, res, PHI_ARG_DEF (phi, 0), debug); } } } if (debug) dump_var_map (debug, map); /* Now one more pass to make all elements of a partition share the same root variable. */ for (x = 1; x < num_ssa_names; x++) { part_var = partition_to_var (map, x); if (!part_var) continue; var = ssa_name (x); if (SSA_NAME_VAR (var) == SSA_NAME_VAR (part_var)) continue; if (debug) { fprintf (debug, "Coalesced "); print_generic_expr (debug, var, TDF_SLIM); fprintf (debug, " to "); print_generic_expr (debug, part_var, TDF_SLIM); fprintf (debug, "\n"); } stats.coalesced++; replace_ssa_name_symbol (var, SSA_NAME_VAR (part_var)); } statistics_counter_event (cfun, "copies coalesced", stats.coalesced); delete_var_map (map); return updated ? TODO_remove_unused_locals : 0; }
unsigned HOST_WIDE_INT compute_builtin_object_size (tree ptr, int object_size_type) { gcc_assert (object_size_type >= 0 && object_size_type <= 3); if (! offset_limit) init_offset_limit (); if (TREE_CODE (ptr) == ADDR_EXPR) return addr_object_size (ptr, object_size_type); else if (TREE_CODE (ptr) == CALL_EXPR) { tree arg = pass_through_call (ptr); if (arg) return compute_builtin_object_size (arg, object_size_type); else return alloc_object_size (ptr, object_size_type); } else if (TREE_CODE (ptr) == SSA_NAME && POINTER_TYPE_P (TREE_TYPE (ptr)) && object_sizes[object_size_type] != NULL) { if (!bitmap_bit_p (computed[object_size_type], SSA_NAME_VERSION (ptr))) { struct object_size_info osi; bitmap_iterator bi; unsigned int i; if (dump_file) { fprintf (dump_file, "Computing %s %sobject size for ", (object_size_type & 2) ? "minimum" : "maximum", (object_size_type & 1) ? "sub" : ""); print_generic_expr (dump_file, ptr, dump_flags); fprintf (dump_file, ":\n"); } osi.visited = BITMAP_ALLOC (NULL); osi.reexamine = BITMAP_ALLOC (NULL); osi.object_size_type = object_size_type; osi.depths = NULL; osi.stack = NULL; osi.tos = NULL; /* First pass: walk UD chains, compute object sizes that can be computed. osi.reexamine bitmap at the end will contain what variables were found in dependency cycles and therefore need to be reexamined. */ osi.pass = 0; osi.changed = false; collect_object_sizes_for (&osi, ptr); /* Second pass: keep recomputing object sizes of variables that need reexamination, until no object sizes are increased or all object sizes are computed. */ if (! bitmap_empty_p (osi.reexamine)) { bitmap reexamine = BITMAP_ALLOC (NULL); /* If looking for minimum instead of maximum object size, detect cases where a pointer is increased in a loop. Although even without this detection pass 2 would eventually terminate, it could take a long time. If a pointer is increasing this way, we need to assume 0 object size. E.g. p = &buf[0]; while (cond) p = p + 4; */ if (object_size_type & 2) { osi.depths = xcalloc (num_ssa_names, sizeof (unsigned int)); osi.stack = xmalloc (num_ssa_names * sizeof (unsigned int)); osi.tos = osi.stack; osi.pass = 1; /* collect_object_sizes_for is changing osi.reexamine bitmap, so iterate over a copy. */ bitmap_copy (reexamine, osi.reexamine); EXECUTE_IF_SET_IN_BITMAP (reexamine, 0, i, bi) if (bitmap_bit_p (osi.reexamine, i)) check_for_plus_in_loops (&osi, ssa_name (i)); free (osi.depths); osi.depths = NULL; free (osi.stack); osi.stack = NULL; osi.tos = NULL; } do { osi.pass = 2; osi.changed = false; /* collect_object_sizes_for is changing osi.reexamine bitmap, so iterate over a copy. */ bitmap_copy (reexamine, osi.reexamine); EXECUTE_IF_SET_IN_BITMAP (reexamine, 0, i, bi) if (bitmap_bit_p (osi.reexamine, i)) { collect_object_sizes_for (&osi, ssa_name (i)); if (dump_file && (dump_flags & TDF_DETAILS)) { fprintf (dump_file, "Reexamining "); print_generic_expr (dump_file, ssa_name (i), dump_flags); fprintf (dump_file, "\n"); } } } while (osi.changed); BITMAP_FREE (reexamine); } EXECUTE_IF_SET_IN_BITMAP (osi.reexamine, 0, i, bi) bitmap_set_bit (computed[object_size_type], i); /* Debugging dumps. */ if (dump_file) { EXECUTE_IF_SET_IN_BITMAP (osi.visited, 0, i, bi) if (object_sizes[object_size_type][i] != unknown[object_size_type]) { print_generic_expr (dump_file, ssa_name (i), dump_flags); fprintf (dump_file, ": %s %sobject size " HOST_WIDE_INT_PRINT_UNSIGNED "\n", (object_size_type & 2) ? "minimum" : "maximum", (object_size_type & 1) ? "sub" : "", object_sizes[object_size_type][i]); } } BITMAP_FREE (osi.reexamine); BITMAP_FREE (osi.visited); }
static unsigned int rename_ssa_copies (void) { var_map map; basic_block bb; gimple_stmt_iterator gsi; tree var, part_var; gimple stmt, phi; unsigned x; FILE *debug; bool updated = false; if (dump_file && (dump_flags & TDF_DETAILS)) debug = dump_file; else debug = NULL; map = init_var_map (num_ssa_names); FOR_EACH_BB (bb) { /* Scan for real copies. */ for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) { stmt = gsi_stmt (gsi); if (gimple_assign_ssa_name_copy_p (stmt)) { tree lhs = gimple_assign_lhs (stmt); tree rhs = gimple_assign_rhs1 (stmt); updated |= copy_rename_partition_coalesce (map, lhs, rhs, debug); } } } FOR_EACH_BB (bb) { /* Treat PHI nodes as copies between the result and each argument. */ for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi)) { size_t i; tree res; phi = gsi_stmt (gsi); res = gimple_phi_result (phi); /* Do not process virtual SSA_NAMES. */ if (!is_gimple_reg (SSA_NAME_VAR (res))) continue; for (i = 0; i < gimple_phi_num_args (phi); i++) { tree arg = gimple_phi_arg (phi, i)->def; if (TREE_CODE (arg) == SSA_NAME) updated |= copy_rename_partition_coalesce (map, res, arg, debug); } } } if (debug) dump_var_map (debug, map); /* Now one more pass to make all elements of a partition share the same root variable. */ for (x = 1; x < num_ssa_names; x++) { part_var = partition_to_var (map, x); if (!part_var) continue; var = ssa_name (x); if (debug) { if (SSA_NAME_VAR (var) != SSA_NAME_VAR (part_var)) { fprintf (debug, "Coalesced "); print_generic_expr (debug, var, TDF_SLIM); fprintf (debug, " to "); print_generic_expr (debug, part_var, TDF_SLIM); fprintf (debug, "\n"); } } replace_ssa_name_symbol (var, SSA_NAME_VAR (part_var)); } delete_var_map (map); return updated ? TODO_remove_unused_locals : 0; }
static void restrict_range_to_consts() { size_t i; unsigned num_vr_values = num_ssa_names; for (i = 0; i < num_vr_values; i++) if (vr_value[i]) { value_range_t *vr = vr_value[i]; tree type = TREE_TYPE (ssa_name(i)); tree minimum = NULL; tree maximum = NULL; unsigned var_prec = TYPE_PRECISION(type); //fprintf(stderr, "%ld\n", i); if (INTEGRAL_TYPE_P(type) && vr->min && vr->max) { bool is_neg_inf = is_negative_overflow_infinity (vr->min) || (INTEGRAL_TYPE_P (type) && !TYPE_UNSIGNED (type) && vrp_val_is_min (vr->min)); bool is_pos_inf = is_positive_overflow_infinity (vr->max) || (INTEGRAL_TYPE_P (type) && vrp_val_is_max (vr->max)); if(TREE_CODE (vr->min) != INTEGER_CST && !is_neg_inf) { /// check if greater than zero bool strict_overflow_p; tree val = compare_name_with_value(GE_EXPR, ssa_name(i), integer_zero_node, &strict_overflow_p); if(!strict_overflow_p && val) { if(integer_onep (val)) { minimum = integer_zero_node; } else { tree neg_const; unsigned prec_index = 1; while(prec_index < var_prec && !strict_overflow_p) { neg_const = build_int_cst (type, -(((unsigned HOST_WIDE_INT)1) << prec_index)); tree val = compare_name_with_value(GE_EXPR, ssa_name(i), neg_const, &strict_overflow_p); if(val && integer_onep (val)) { minimum = neg_const; break; } ++prec_index; } } } } else if(is_neg_inf) minimum = vr->min; if(TREE_CODE (vr->max) != INTEGER_CST && !is_pos_inf) { bool strict_overflow_p=false; tree pos_const; unsigned prec_index = 0; while(prec_index < var_prec && !strict_overflow_p) { pos_const = build_int_cst (type, (((unsigned HOST_WIDE_INT)1) << prec_index)); tree val = compare_name_with_value(LT_EXPR, ssa_name(i), pos_const, &strict_overflow_p); if(val && integer_onep (val)) { maximum = build_int_cst (type, (((unsigned HOST_WIDE_INT)1) << prec_index)-1); break; } ++prec_index; } } else if(is_pos_inf) maximum = vr->max; if(minimum) { vr->min = minimum; vr->type = VR_RANGE; } if(maximum) { vr->max = maximum; vr->type = VR_RANGE; } } } // do further restrictions by exploiting assert_expr for (i = 0; i < num_vr_values; i++) if (vr_value[i]) { tree type = TREE_TYPE (ssa_name(i)); value_range_t *vr = vr_value[i]; if(INTEGRAL_TYPE_P(type) && vr->type == VR_RANGE && vr->min && vr->max) { tree sa_var = ssa_name(i); GIMPLE_type def_stmt = SSA_NAME_DEF_STMT (sa_var ); if(is_gimple_assign (def_stmt) && gimple_assign_rhs_code (def_stmt) == ASSERT_EXPR) { tree src_var = ASSERT_EXPR_VAR (gimple_assign_rhs1 (def_stmt)); value_range_t *src_vr = vr_value[SSA_NAME_VERSION(src_var)]; if(src_vr && src_vr->type == VR_RANGE && src_vr->min && src_vr->max) { bool strict_overflow_p=false; tree val = compare_name_with_value(LT_EXPR, src_var, vr->max, &strict_overflow_p); if(val && integer_onep (val)) vr->max = src_vr->max; strict_overflow_p=false; val = compare_name_with_value(GT_EXPR, src_var, vr->min, &strict_overflow_p); if(val && integer_onep (val)) vr->min = src_vr->min; } } } } }
static bool fini_copy_prop (void) { unsigned i; /* Set the final copy-of value for each variable by traversing the copy-of chains. */ for (i = 1; i < num_ssa_names; i++) { tree var = ssa_name (i); if (!var || !copy_of[i].value || copy_of[i].value == var) continue; /* In theory the points-to solution of all members of the copy chain is their intersection. For now we do not bother to compute this but only make sure we do not lose points-to information completely by setting the points-to solution of the representative to the first solution we find if it doesn't have one already. */ if (copy_of[i].value != var && TREE_CODE (copy_of[i].value) == SSA_NAME) { basic_block copy_of_bb = gimple_bb (SSA_NAME_DEF_STMT (copy_of[i].value)); basic_block var_bb = gimple_bb (SSA_NAME_DEF_STMT (var)); if (POINTER_TYPE_P (TREE_TYPE (var)) && SSA_NAME_PTR_INFO (var) && !SSA_NAME_PTR_INFO (copy_of[i].value)) { duplicate_ssa_name_ptr_info (copy_of[i].value, SSA_NAME_PTR_INFO (var)); /* Points-to information is cfg insensitive, but alignment info might be cfg sensitive, if it e.g. is derived from VRP derived non-zero bits. So, do not copy alignment info if the two SSA_NAMEs aren't defined in the same basic block. */ if (var_bb != copy_of_bb) mark_ptr_info_alignment_unknown (SSA_NAME_PTR_INFO (copy_of[i].value)); } else if (!POINTER_TYPE_P (TREE_TYPE (var)) && SSA_NAME_RANGE_INFO (var) && !SSA_NAME_RANGE_INFO (copy_of[i].value) && var_bb == copy_of_bb) duplicate_ssa_name_range_info (copy_of[i].value, SSA_NAME_RANGE_TYPE (var), SSA_NAME_RANGE_INFO (var)); } } bool changed = substitute_and_fold (get_value, NULL, true); if (changed) { free_numbers_of_iterations_estimates (); if (scev_initialized_p ()) scev_reset (); } free (copy_of); return changed; }
bool compute_builtin_object_size (tree ptr, int object_size_type, unsigned HOST_WIDE_INT *psize) { gcc_assert (object_size_type >= 0 && object_size_type <= 3); /* Set to unknown and overwrite just before returning if the size could be determined. */ *psize = unknown[object_size_type]; if (! offset_limit) init_offset_limit (); if (TREE_CODE (ptr) == ADDR_EXPR) return addr_object_size (NULL, ptr, object_size_type, psize); if (TREE_CODE (ptr) != SSA_NAME || !POINTER_TYPE_P (TREE_TYPE (ptr))) return false; if (computed[object_size_type] == NULL) { if (optimize || object_size_type & 1) return false; /* When not optimizing, rather than failing, make a small effort to determine the object size without the full benefit of the (costly) computation below. */ gimple *def = SSA_NAME_DEF_STMT (ptr); if (gimple_code (def) == GIMPLE_ASSIGN) { tree_code code = gimple_assign_rhs_code (def); if (code == POINTER_PLUS_EXPR) { tree offset = gimple_assign_rhs2 (def); ptr = gimple_assign_rhs1 (def); if (tree_fits_shwi_p (offset) && compute_builtin_object_size (ptr, object_size_type, psize)) { /* Return zero when the offset is out of bounds. */ unsigned HOST_WIDE_INT off = tree_to_shwi (offset); *psize = off < *psize ? *psize - off : 0; return true; } } } return false; } if (!bitmap_bit_p (computed[object_size_type], SSA_NAME_VERSION (ptr))) { struct object_size_info osi; bitmap_iterator bi; unsigned int i; if (num_ssa_names > object_sizes[object_size_type].length ()) object_sizes[object_size_type].safe_grow (num_ssa_names); if (dump_file) { fprintf (dump_file, "Computing %s %sobject size for ", (object_size_type & 2) ? "minimum" : "maximum", (object_size_type & 1) ? "sub" : ""); print_generic_expr (dump_file, ptr, dump_flags); fprintf (dump_file, ":\n"); } osi.visited = BITMAP_ALLOC (NULL); osi.reexamine = BITMAP_ALLOC (NULL); osi.object_size_type = object_size_type; osi.depths = NULL; osi.stack = NULL; osi.tos = NULL; /* First pass: walk UD chains, compute object sizes that can be computed. osi.reexamine bitmap at the end will contain what variables were found in dependency cycles and therefore need to be reexamined. */ osi.pass = 0; osi.changed = false; collect_object_sizes_for (&osi, ptr); /* Second pass: keep recomputing object sizes of variables that need reexamination, until no object sizes are increased or all object sizes are computed. */ if (! bitmap_empty_p (osi.reexamine)) { bitmap reexamine = BITMAP_ALLOC (NULL); /* If looking for minimum instead of maximum object size, detect cases where a pointer is increased in a loop. Although even without this detection pass 2 would eventually terminate, it could take a long time. If a pointer is increasing this way, we need to assume 0 object size. E.g. p = &buf[0]; while (cond) p = p + 4; */ if (object_size_type & 2) { osi.depths = XCNEWVEC (unsigned int, num_ssa_names); osi.stack = XNEWVEC (unsigned int, num_ssa_names); osi.tos = osi.stack; osi.pass = 1; /* collect_object_sizes_for is changing osi.reexamine bitmap, so iterate over a copy. */ bitmap_copy (reexamine, osi.reexamine); EXECUTE_IF_SET_IN_BITMAP (reexamine, 0, i, bi) if (bitmap_bit_p (osi.reexamine, i)) check_for_plus_in_loops (&osi, ssa_name (i)); free (osi.depths); osi.depths = NULL; free (osi.stack); osi.stack = NULL; osi.tos = NULL; } do { osi.pass = 2; osi.changed = false; /* collect_object_sizes_for is changing osi.reexamine bitmap, so iterate over a copy. */ bitmap_copy (reexamine, osi.reexamine); EXECUTE_IF_SET_IN_BITMAP (reexamine, 0, i, bi) if (bitmap_bit_p (osi.reexamine, i)) { collect_object_sizes_for (&osi, ssa_name (i)); if (dump_file && (dump_flags & TDF_DETAILS)) { fprintf (dump_file, "Reexamining "); print_generic_expr (dump_file, ssa_name (i), dump_flags); fprintf (dump_file, "\n"); } } } while (osi.changed); BITMAP_FREE (reexamine); }