diff options
Diffstat (limited to 'gcc/tree-ssa-alias.c')
-rw-r--r-- | gcc/tree-ssa-alias.c | 162 |
1 files changed, 95 insertions, 67 deletions
diff --git a/gcc/tree-ssa-alias.c b/gcc/tree-ssa-alias.c index 230004b..1fa94c3 100644 --- a/gcc/tree-ssa-alias.c +++ b/gcc/tree-ssa-alias.c @@ -155,6 +155,7 @@ static void collect_points_to_info_for (struct alias_info *, tree); static bool ptr_is_dereferenced_by (tree, tree, bool *); static void maybe_create_global_var (struct alias_info *ai); static void group_aliases (struct alias_info *); +static struct ptr_info_def *get_ptr_info (tree t); /* Global declarations. */ @@ -427,7 +428,7 @@ collect_points_to_info_for (struct alias_info *ai, tree ptr) if (!bitmap_bit_p (ai->ssa_names_visited, SSA_NAME_VERSION (ptr))) { - ssa_name_ann_t ann; + struct ptr_info_def *pi; bitmap_set_bit (ai->ssa_names_visited, SSA_NAME_VERSION (ptr)); walk_use_def_chains (ptr, collect_points_to_info_r, ai); @@ -436,11 +437,11 @@ collect_points_to_info_for (struct alias_info *ai, tree ptr) /* If we could not determine where PTR was pointing to, clear all the other points-to information. */ - ann = ssa_name_ann (ptr); - if (ann->pt_anything) + pi = SSA_NAME_PTR_INFO (ptr); + if (pi->pt_anything) { - ann->pt_malloc = 0; - ann->pt_vars = NULL; + pi->pt_malloc = 0; + pi->pt_vars = NULL; } } } @@ -559,12 +560,13 @@ compute_points_to_and_addr_escape (struct alias_info *ai) if (stmt_escapes_p) block_ann->has_escape_site = 1; - /* Special case for silly ADDR_EXPR tricks. If this - statement is an assignment to a non-pointer variable and - the RHS takes the address of a variable, assume that the - variable on the RHS is call-clobbered. We could add the - LHS to the list of "pointers" and follow it to see if it - really escapes, but it's not worth the pain. */ + /* Special case for silly ADDR_EXPR tricks + (gcc.c-torture/unsorted/pass.c). If this statement is an + assignment to a non-pointer variable and the RHS takes the + address of a variable, assume that the variable on the RHS is + call-clobbered. We could add the LHS to the list of + "pointers" and follow it to see if it really escapes, but it's + not worth the pain. */ if (addr_taken && TREE_CODE (stmt) == MODIFY_EXPR && !POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (stmt, 0)))) @@ -580,7 +582,7 @@ compute_points_to_and_addr_escape (struct alias_info *ai) { tree op = USE_OP (uses, i); var_ann_t v_ann = var_ann (SSA_NAME_VAR (op)); - ssa_name_ann_t ptr_ann; + struct ptr_info_def *pi; bool is_store; /* If the operand's variable may be aliased, keep track @@ -598,7 +600,7 @@ compute_points_to_and_addr_escape (struct alias_info *ai) collect_points_to_info_for (ai, op); - ptr_ann = ssa_name_ann (op); + pi = SSA_NAME_PTR_INFO (op); if (ptr_is_dereferenced_by (op, stmt, &is_store)) { /* If we found OP to point to a set of variables or @@ -609,8 +611,8 @@ compute_points_to_and_addr_escape (struct alias_info *ai) FIXME: Cycles in the SSA web and the lack of SSA information for structures will prevent the creation of name tags. Find ways around this limitation. */ - if (ptr_ann->pt_malloc || ptr_ann->pt_vars) - ptr_ann->name_mem_tag = get_nmt_for (op); + if (pi->pt_malloc || pi->pt_vars) + pi->name_mem_tag = get_nmt_for (op); /* Keep track of how many time we've dereferenced each pointer. Again, we don't need to grow @@ -632,7 +634,7 @@ compute_points_to_and_addr_escape (struct alias_info *ai) will not escape if it is being dereferenced. That's why we only check for escape points if OP is not dereferenced by STMT. */ - ptr_ann->value_escapes_p = 1; + pi->value_escapes_p = 1; /* If the statement makes a function call, assume that pointer OP will be dereferenced in a store @@ -695,15 +697,15 @@ compute_flow_sensitive_aliasing (struct alias_info *ai) { size_t j; tree ptr = VARRAY_TREE (ai->processed_ptrs, i); - ssa_name_ann_t ann = ssa_name_ann (ptr); + struct ptr_info_def *pi = SSA_NAME_PTR_INFO (ptr); var_ann_t v_ann = var_ann (SSA_NAME_VAR (ptr)); - if (ann->value_escapes_p || ann->pt_anything) + if (pi->value_escapes_p || pi->pt_anything) { /* If PTR escapes or may point to anything, then its associated memory tags are call-clobbered. */ - if (ann->name_mem_tag) - mark_call_clobbered (ann->name_mem_tag); + if (pi->name_mem_tag) + mark_call_clobbered (pi->name_mem_tag); if (v_ann->type_mem_tag) mark_call_clobbered (v_ann->type_mem_tag); @@ -711,7 +713,7 @@ compute_flow_sensitive_aliasing (struct alias_info *ai) /* If PTR may point to anything, mark call-clobbered all the addressables with the same alias set as the type pointed-to by PTR. */ - if (ann->pt_anything) + if (pi->pt_anything) { HOST_WIDE_INT ptr_set; ptr_set = get_alias_set (TREE_TYPE (TREE_TYPE (ptr))); @@ -730,23 +732,25 @@ compute_flow_sensitive_aliasing (struct alias_info *ai) name memory tag, which will have been marked call-clobbered. This will in turn mark the pointed-to variables as call-clobbered when we call add_may_alias below. */ - if (ann->value_escapes_p && !ann->name_mem_tag && ann->pt_vars) - EXECUTE_IF_SET_IN_BITMAP (ann->pt_vars, 0, j, + if (pi->value_escapes_p + && pi->name_mem_tag == NULL_TREE + && pi->pt_vars) + EXECUTE_IF_SET_IN_BITMAP (pi->pt_vars, 0, j, mark_call_clobbered (referenced_var (j))); } /* Set up aliasing information for PTR's name memory tag (if it has one). Note that only pointers that have been dereferenced will have a name memory tag. */ - if (ann->name_mem_tag && ann->pt_vars) - EXECUTE_IF_SET_IN_BITMAP (ann->pt_vars, 0, j, - add_may_alias (ann->name_mem_tag, referenced_var (j))); + if (pi->name_mem_tag && pi->pt_vars) + EXECUTE_IF_SET_IN_BITMAP (pi->pt_vars, 0, j, + add_may_alias (pi->name_mem_tag, referenced_var (j))); /* If the name tag is call clobbered, so is the type tag associated with the base VAR_DECL. */ - if (ann->name_mem_tag + if (pi->name_mem_tag && v_ann->type_mem_tag - && is_call_clobbered (ann->name_mem_tag)) + && is_call_clobbered (pi->name_mem_tag)) mark_call_clobbered (v_ann->type_mem_tag); } } @@ -1050,7 +1054,7 @@ group_aliases (struct alias_info *ai) { size_t j; tree ptr = VARRAY_TREE (ai->processed_ptrs, i); - tree name_tag = ssa_name_ann (ptr)->name_mem_tag; + tree name_tag = SSA_NAME_PTR_INFO (ptr)->name_mem_tag; varray_type aliases; if (name_tag == NULL_TREE) @@ -1509,31 +1513,31 @@ add_may_alias (tree var, tree alias) static void merge_pointed_to_info (struct alias_info *ai, tree dest, tree orig) { - ssa_name_ann_t dest_ann, orig_ann; + struct ptr_info_def *dest_pi, *orig_pi; /* Make sure we have points-to information for ORIG. */ collect_points_to_info_for (ai, orig); - dest_ann = get_ssa_name_ann (dest); - orig_ann = ssa_name_ann (orig); + dest_pi = get_ptr_info (dest); + orig_pi = SSA_NAME_PTR_INFO (orig); - if (orig_ann) + if (orig_pi) { - dest_ann->pt_anything |= orig_ann->pt_anything; - dest_ann->pt_malloc |= orig_ann->pt_malloc; + dest_pi->pt_anything |= orig_pi->pt_anything; + dest_pi->pt_malloc |= orig_pi->pt_malloc; - if (orig_ann->pt_vars) + if (orig_pi->pt_vars) { - if (dest_ann->pt_vars == NULL) + if (dest_pi->pt_vars == NULL) { - dest_ann->pt_vars = BITMAP_GGC_ALLOC (); - bitmap_copy (dest_ann->pt_vars, orig_ann->pt_vars); + dest_pi->pt_vars = BITMAP_GGC_ALLOC (); + bitmap_copy (dest_pi->pt_vars, orig_pi->pt_vars); } else - bitmap_a_or_b (dest_ann->pt_vars, - dest_ann->pt_vars, - orig_ann->pt_vars); - } + bitmap_a_or_b (dest_pi->pt_vars, + dest_pi->pt_vars, + orig_pi->pt_vars); + } } } @@ -1543,7 +1547,7 @@ merge_pointed_to_info (struct alias_info *ai, tree dest, tree orig) static void add_pointed_to_expr (tree ptr, tree value) { - ssa_name_ann_t ann; + struct ptr_info_def *pi; #if defined ENABLE_CHECKING /* Pointer variables should have been handled by merge_pointed_to_info. */ @@ -1552,22 +1556,22 @@ add_pointed_to_expr (tree ptr, tree value) abort (); #endif - ann = get_ssa_name_ann (ptr); + pi = get_ptr_info (ptr); /* If VALUE is the result of a malloc-like call, then the area pointed to PTR is guaranteed to not alias with anything else. */ if (TREE_CODE (value) == CALL_EXPR && (call_expr_flags (value) & (ECF_MALLOC | ECF_MAY_BE_ALLOCA))) - ann->pt_malloc = 1; + pi->pt_malloc = 1; else - ann->pt_anything = 1; + pi->pt_anything = 1; if (dump_file) { fprintf (dump_file, "Pointer "); print_generic_expr (dump_file, ptr, dump_flags); fprintf (dump_file, " points to "); - if (ann->pt_malloc) + if (pi->pt_malloc) fprintf (dump_file, "malloc space: "); else fprintf (dump_file, "an arbitrary address: "); @@ -1587,7 +1591,7 @@ add_pointed_to_var (struct alias_info *ai, tree ptr, tree value) if (TREE_CODE (value) == ADDR_EXPR) { tree pt_var; - ssa_name_ann_t ann; + struct ptr_info_def *pi; size_t uid; pt_var = TREE_OPERAND (value, 0); @@ -1596,11 +1600,11 @@ add_pointed_to_var (struct alias_info *ai, tree ptr, tree value) if (pt_var && SSA_VAR_P (pt_var)) { - ann = get_ssa_name_ann (ptr); + pi = get_ptr_info (ptr); uid = var_ann (pt_var)->uid; - if (ann->pt_vars == NULL) - ann->pt_vars = BITMAP_GGC_ALLOC (); - bitmap_set_bit (ann->pt_vars, uid); + if (pi->pt_vars == NULL) + pi->pt_vars = BITMAP_GGC_ALLOC (); + bitmap_set_bit (pi->pt_vars, uid); bitmap_set_bit (ai->addresses_needed, uid); } else @@ -1675,8 +1679,7 @@ collect_points_to_info_r (tree var, tree stmt, void *data) else if (TREE_CODE (stmt) == ASM_EXPR) { /* Pointers defined by __asm__ statements can point anywhere. */ - ssa_name_ann_t ann = get_ssa_name_ann (var); - ann->pt_anything = 1; + get_ptr_info (var)->pt_anything = 1; } else if (IS_EMPTY_STMT (stmt)) { @@ -1810,8 +1813,8 @@ create_memory_tag (tree type, bool is_type_tag) static tree get_nmt_for (tree ptr) { - ssa_name_ann_t ptr_ann = ssa_name_ann (ptr); - tree tag = ptr_ann->name_mem_tag; + struct ptr_info_def *pi = get_ptr_info (ptr); + tree tag = pi->name_mem_tag; if (tag == NULL_TREE) { @@ -1823,7 +1826,7 @@ get_nmt_for (tree ptr) mark_call_clobbered (tag); /* Similarly, if PTR points to malloc, then TAG is a global. */ - if (ptr_ann->pt_malloc) + if (pi->pt_malloc) mark_call_clobbered (tag); } @@ -1976,40 +1979,65 @@ debug_alias_info (void) } +/* Return the alias information associated with pointer T. It creates a + new instance if none existed. */ + +static struct ptr_info_def * +get_ptr_info (tree t) +{ + struct ptr_info_def *pi; + +#if defined ENABLE_CHECKING + if (!POINTER_TYPE_P (TREE_TYPE (t))) + abort (); +#endif + + pi = SSA_NAME_PTR_INFO (t); + if (pi == NULL) + { + pi = ggc_alloc (sizeof (*pi)); + memset ((void *)pi, 0, sizeof (*pi)); + SSA_NAME_PTR_INFO (t) = pi; + } + + return pi; +} + + /* Dump points-to information for SSA_NAME PTR into FILE. */ static void dump_points_to_info_for (FILE *file, tree ptr) { - ssa_name_ann_t ann = ssa_name_ann (ptr); + struct ptr_info_def *pi = SSA_NAME_PTR_INFO (ptr); fprintf (file, "Pointer "); print_generic_expr (file, ptr, dump_flags); - if (ann == NULL) + if (pi == NULL) return; - if (ann->name_mem_tag) + if (pi->name_mem_tag) { fprintf (file, ", name memory tag: "); - print_generic_expr (file, ann->name_mem_tag, dump_flags); + print_generic_expr (file, pi->name_mem_tag, dump_flags); } - if (ann->value_escapes_p) + if (pi->value_escapes_p) fprintf (file, ", its value escapes"); - if (ann->pt_anything) + if (pi->pt_anything) fprintf (file, ", points-to anything"); - if (ann->pt_malloc) + if (pi->pt_malloc) fprintf (file, ", points-to malloc"); - if (ann->pt_vars) + if (pi->pt_vars) { unsigned ix; fprintf (file, ", points-to vars: { "); - EXECUTE_IF_SET_IN_BITMAP (ann->pt_vars, 0, ix, + EXECUTE_IF_SET_IN_BITMAP (pi->pt_vars, 0, ix, { print_generic_expr (file, referenced_var (ix), dump_flags); fprintf (file, " "); |