OSDN Git Service

* tree-ssa-alias.c (init_alias_info): Remove a call to
[pf3gnuchains/gcc-fork.git] / gcc / tree-ssa-alias.c
1 /* Alias analysis for trees.
2    Copyright (C) 2004, 2005 Free Software Foundation, Inc.
3    Contributed by Diego Novillo <dnovillo@redhat.com>
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING.  If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.  */
21
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26 #include "tree.h"
27 #include "rtl.h"
28 #include "tm_p.h"
29 #include "hard-reg-set.h"
30 #include "basic-block.h"
31 #include "timevar.h"
32 #include "expr.h"
33 #include "ggc.h"
34 #include "langhooks.h"
35 #include "flags.h"
36 #include "function.h"
37 #include "diagnostic.h"
38 #include "tree-dump.h"
39 #include "tree-gimple.h"
40 #include "tree-flow.h"
41 #include "tree-inline.h"
42 #include "tree-pass.h"
43 #include "convert.h"
44 #include "params.h"
45 #include "vec.h"
46
47 /* 'true' after aliases have been computed (see compute_may_aliases).  */
48 bool aliases_computed_p;
49
50 /* Structure to map a variable to its alias set and keep track of the
51    virtual operands that will be needed to represent it.  */
52 struct alias_map_d
53 {
54   /* Variable and its alias set.  */
55   tree var;
56   HOST_WIDE_INT set;
57
58   /* Total number of virtual operands that will be needed to represent
59      all the aliases of VAR.  */
60   long total_alias_vops;
61
62   /* Nonzero if the aliases for this memory tag have been grouped
63      already.  Used in group_aliases.  */
64   unsigned int grouped_p : 1;
65
66   /* Set of variables aliased with VAR.  This is the exact same
67      information contained in VAR_ANN (VAR)->MAY_ALIASES, but in
68      bitmap form to speed up alias grouping.  */
69   sbitmap may_aliases;
70 };
71
72
73 /* Alias information used by compute_may_aliases and its helpers.  */
74 struct alias_info
75 {
76   /* SSA names visited while collecting points-to information.  If bit I
77      is set, it means that SSA variable with version I has already been
78      visited.  */
79   sbitmap ssa_names_visited;
80
81   /* Array of SSA_NAME pointers processed by the points-to collector.  */
82   varray_type processed_ptrs;
83
84   /* Variables whose address is still needed.  */
85   bitmap addresses_needed;
86
87   /* ADDRESSABLE_VARS contains all the global variables and locals that
88      have had their address taken.  */
89   struct alias_map_d **addressable_vars;
90   size_t num_addressable_vars;
91
92   /* POINTERS contains all the _DECL pointers with unique memory tags
93      that have been referenced in the program.  */
94   struct alias_map_d **pointers;
95   size_t num_pointers;
96
97   /* Number of function calls found in the program.  */
98   size_t num_calls_found;
99
100   /* Number of const/pure function calls found in the program.  */
101   size_t num_pure_const_calls_found;
102
103   /* Array of counters to keep track of how many times each pointer has
104      been dereferenced in the program.  This is used by the alias grouping
105      heuristic in compute_flow_insensitive_aliasing.  */
106   varray_type num_references;
107
108   /* Total number of virtual operands that will be needed to represent
109      all the aliases of all the pointers found in the program.  */
110   long total_alias_vops;
111
112   /* Variables that have been written to.  */
113   bitmap written_vars;
114
115   /* Pointers that have been used in an indirect store operation.  */
116   bitmap dereferenced_ptrs_store;
117
118   /* Pointers that have been used in an indirect load operation.  */
119   bitmap dereferenced_ptrs_load;
120 };
121
122
123 /* Counters used to display statistics on alias analysis.  */
124 struct alias_stats_d
125 {
126   unsigned int alias_queries;
127   unsigned int alias_mayalias;
128   unsigned int alias_noalias;
129   unsigned int simple_queries;
130   unsigned int simple_resolved;
131   unsigned int tbaa_queries;
132   unsigned int tbaa_resolved;
133 };
134
135
136 /* Local variables.  */
137 static struct alias_stats_d alias_stats;
138
139 /* Local functions.  */
140 static void compute_flow_insensitive_aliasing (struct alias_info *);
141 static void dump_alias_stats (FILE *);
142 static bool may_alias_p (tree, HOST_WIDE_INT, tree, HOST_WIDE_INT);
143 static tree create_memory_tag (tree type, bool is_type_tag);
144 static tree get_tmt_for (tree, struct alias_info *);
145 static tree get_nmt_for (tree);
146 static void add_may_alias (tree, tree);
147 static void replace_may_alias (tree, size_t, tree);
148 static struct alias_info *init_alias_info (void);
149 static void delete_alias_info (struct alias_info *);
150 static void compute_points_to_and_addr_escape (struct alias_info *);
151 static void compute_flow_sensitive_aliasing (struct alias_info *);
152 static void setup_pointers_and_addressables (struct alias_info *);
153 static bool collect_points_to_info_r (tree, tree, void *);
154 static bool is_escape_site (tree, struct alias_info *);
155 static void add_pointed_to_var (struct alias_info *, tree, tree);
156 static void create_global_var (void);
157 static void collect_points_to_info_for (struct alias_info *, tree);
158 static void maybe_create_global_var (struct alias_info *ai);
159 static void group_aliases (struct alias_info *);
160 static void set_pt_anything (tree ptr);
161 static void set_pt_malloc (tree ptr);
162
163 /* Global declarations.  */
164
165 /* Call clobbered variables in the function.  If bit I is set, then
166    REFERENCED_VARS (I) is call-clobbered.  */
167 bitmap call_clobbered_vars;
168
169 /* Addressable variables in the function.  If bit I is set, then
170    REFERENCED_VARS (I) has had its address taken.  Note that
171    CALL_CLOBBERED_VARS and ADDRESSABLE_VARS are not related.  An
172    addressable variable is not necessarily call-clobbered (e.g., a
173    local addressable whose address does not escape) and not all
174    call-clobbered variables are addressable (e.g., a local static
175    variable).  */
176 bitmap addressable_vars;
177
178 /* When the program has too many call-clobbered variables and call-sites,
179    this variable is used to represent the clobbering effects of function
180    calls.  In these cases, all the call clobbered variables in the program
181    are forced to alias this variable.  This reduces compile times by not
182    having to keep track of too many V_MAY_DEF expressions at call sites.  */
183 tree global_var;
184
185
186 /* Compute may-alias information for every variable referenced in function
187    FNDECL.
188
189    Alias analysis proceeds in 3 main phases:
190
191    1- Points-to and escape analysis.
192
193    This phase walks the use-def chains in the SSA web looking for three
194    things:
195
196         * Assignments of the form P_i = &VAR
197         * Assignments of the form P_i = malloc()
198         * Pointers and ADDR_EXPR that escape the current function.
199
200    The concept of 'escaping' is the same one used in the Java world.  When
201    a pointer or an ADDR_EXPR escapes, it means that it has been exposed
202    outside of the current function.  So, assignment to global variables,
203    function arguments and returning a pointer are all escape sites, as are
204    conversions between pointers and integers.
205
206    This is where we are currently limited.  Since not everything is renamed
207    into SSA, we lose track of escape properties when a pointer is stashed
208    inside a field in a structure, for instance.  In those cases, we are
209    assuming that the pointer does escape.
210
211    We use escape analysis to determine whether a variable is
212    call-clobbered.  Simply put, if an ADDR_EXPR escapes, then the variable
213    is call-clobbered.  If a pointer P_i escapes, then all the variables
214    pointed-to by P_i (and its memory tag) also escape.
215
216    2- Compute flow-sensitive aliases
217
218    We have two classes of memory tags.  Memory tags associated with the
219    pointed-to data type of the pointers in the program.  These tags are
220    called "type memory tag" (TMT).  The other class are those associated
221    with SSA_NAMEs, called "name memory tag" (NMT). The basic idea is that
222    when adding operands for an INDIRECT_REF *P_i, we will first check
223    whether P_i has a name tag, if it does we use it, because that will have
224    more precise aliasing information.  Otherwise, we use the standard type
225    tag.
226
227    In this phase, we go through all the pointers we found in points-to
228    analysis and create alias sets for the name memory tags associated with
229    each pointer P_i.  If P_i escapes, we mark call-clobbered the variables
230    it points to and its tag.
231
232
233    3- Compute flow-insensitive aliases
234
235    This pass will compare the alias set of every type memory tag and every
236    addressable variable found in the program.  Given a type memory tag TMT
237    and an addressable variable V.  If the alias sets of TMT and V conflict
238    (as computed by may_alias_p), then V is marked as an alias tag and added
239    to the alias set of TMT.
240
241    For instance, consider the following function:
242
243             foo (int i)
244             {
245               int *p, a, b;
246             
247               if (i > 10)
248                 p = &a;
249               else
250                 p = &b;
251             
252               *p = 3;
253               a = b + 2;
254               return *p;
255             }
256
257    After aliasing analysis has finished, the type memory tag for pointer
258    'p' will have two aliases, namely variables 'a' and 'b'.  Every time
259    pointer 'p' is dereferenced, we want to mark the operation as a
260    potential reference to 'a' and 'b'.
261
262             foo (int i)
263             {
264               int *p, a, b;
265
266               if (i_2 > 10)
267                 p_4 = &a;
268               else
269                 p_6 = &b;
270               # p_1 = PHI <p_4(1), p_6(2)>;
271
272               # a_7 = V_MAY_DEF <a_3>;
273               # b_8 = V_MAY_DEF <b_5>;
274               *p_1 = 3;
275
276               # a_9 = V_MAY_DEF <a_7>
277               # VUSE <b_8>
278               a_9 = b_8 + 2;
279
280               # VUSE <a_9>;
281               # VUSE <b_8>;
282               return *p_1;
283             }
284
285    In certain cases, the list of may aliases for a pointer may grow too
286    large.  This may cause an explosion in the number of virtual operands
287    inserted in the code.  Resulting in increased memory consumption and
288    compilation time.
289
290    When the number of virtual operands needed to represent aliased
291    loads and stores grows too large (configurable with @option{--param
292    max-aliased-vops}), alias sets are grouped to avoid severe
293    compile-time slow downs and memory consumption.  See group_aliases.  */
294
295 static void
296 compute_may_aliases (void)
297 {
298   struct alias_info *ai;
299   
300   memset (&alias_stats, 0, sizeof (alias_stats));
301
302   /* Initialize aliasing information.  */
303   ai = init_alias_info ();
304
305   /* For each pointer P_i, determine the sets of variables that P_i may
306      point-to.  For every addressable variable V, determine whether the
307      address of V escapes the current function, making V call-clobbered
308      (i.e., whether &V is stored in a global variable or if its passed as a
309      function call argument).  */
310   compute_points_to_and_addr_escape (ai);
311
312   /* Collect all pointers and addressable variables, compute alias sets,
313      create memory tags for pointers and promote variables whose address is
314      not needed anymore.  */
315   setup_pointers_and_addressables (ai);
316
317   /* Compute flow-sensitive, points-to based aliasing for all the name
318      memory tags.  Note that this pass needs to be done before flow
319      insensitive analysis because it uses the points-to information
320      gathered before to mark call-clobbered type tags.  */
321   compute_flow_sensitive_aliasing (ai);
322
323   /* Compute type-based flow-insensitive aliasing for all the type
324      memory tags.  */
325   compute_flow_insensitive_aliasing (ai);
326
327   /* If the program has too many call-clobbered variables and/or function
328      calls, create .GLOBAL_VAR and use it to model call-clobbering
329      semantics at call sites.  This reduces the number of virtual operands
330      considerably, improving compile times at the expense of lost
331      aliasing precision.  */
332   maybe_create_global_var (ai);
333
334   /* Debugging dumps.  */
335   if (dump_file)
336     {
337       dump_referenced_vars (dump_file);
338       if (dump_flags & TDF_STATS)
339         dump_alias_stats (dump_file);
340       dump_points_to_info (dump_file);
341       dump_alias_info (dump_file);
342     }
343
344   /* Deallocate memory used by aliasing data structures.  */
345   delete_alias_info (ai);
346
347   {
348     block_stmt_iterator bsi;
349     basic_block bb;
350     FOR_EACH_BB (bb)
351       {
352         for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
353           {
354             update_stmt_if_modified (bsi_stmt (bsi));
355           }
356       }
357   }
358
359 }
360
361 struct tree_opt_pass pass_may_alias = 
362 {
363   "alias",                              /* name */
364   NULL,                                 /* gate */
365   compute_may_aliases,                  /* execute */
366   NULL,                                 /* sub */
367   NULL,                                 /* next */
368   0,                                    /* static_pass_number */
369   TV_TREE_MAY_ALIAS,                    /* tv_id */
370   PROP_cfg | PROP_ssa,                  /* properties_required */
371   PROP_alias,                           /* properties_provided */
372   0,                                    /* properties_destroyed */
373   0,                                    /* todo_flags_start */
374   TODO_dump_func | TODO_update_ssa
375     | TODO_ggc_collect | TODO_verify_ssa
376     | TODO_verify_stmts,                /* todo_flags_finish */
377   0                                     /* letter */
378 };
379
380
381 /* Data structure used to count the number of dereferences to PTR
382    inside an expression.  */
383 struct count_ptr_d
384 {
385   tree ptr;
386   unsigned count;
387 };
388
389
390 /* Helper for count_uses_and_derefs.  Called by walk_tree to look for
391    (ALIGN/MISALIGNED_)INDIRECT_REF nodes for the pointer passed in DATA.  */
392
393 static tree
394 count_ptr_derefs (tree *tp, int *walk_subtrees ATTRIBUTE_UNUSED, void *data)
395 {
396   struct count_ptr_d *count_p = (struct count_ptr_d *) data;
397
398   if (INDIRECT_REF_P (*tp) && TREE_OPERAND (*tp, 0) == count_p->ptr)
399     count_p->count++;
400
401   return NULL_TREE;
402 }
403
404
405 /* Count the number of direct and indirect uses for pointer PTR in
406    statement STMT.  The two counts are stored in *NUM_USES_P and
407    *NUM_DEREFS_P respectively.  *IS_STORE_P is set to 'true' if at
408    least one of those dereferences is a store operation.  */
409
410 void
411 count_uses_and_derefs (tree ptr, tree stmt, unsigned *num_uses_p,
412                        unsigned *num_derefs_p, bool *is_store)
413 {
414   ssa_op_iter i;
415   tree use;
416
417   *num_uses_p = 0;
418   *num_derefs_p = 0;
419   *is_store = false;
420
421   /* Find out the total number of uses of PTR in STMT.  */
422   FOR_EACH_SSA_TREE_OPERAND (use, stmt, i, SSA_OP_USE)
423     if (use == ptr)
424       (*num_uses_p)++;
425
426   /* Now count the number of indirect references to PTR.  This is
427      truly awful, but we don't have much choice.  There are no parent
428      pointers inside INDIRECT_REFs, so an expression like
429      '*x_1 = foo (x_1, *x_1)' needs to be traversed piece by piece to
430      find all the indirect and direct uses of x_1 inside.  The only
431      shortcut we can take is the fact that GIMPLE only allows
432      INDIRECT_REFs inside the expressions below.  */
433   if (TREE_CODE (stmt) == MODIFY_EXPR
434       || (TREE_CODE (stmt) == RETURN_EXPR
435           && TREE_CODE (TREE_OPERAND (stmt, 0)) == MODIFY_EXPR)
436       || TREE_CODE (stmt) == ASM_EXPR
437       || TREE_CODE (stmt) == CALL_EXPR)
438     {
439       tree lhs, rhs;
440
441       if (TREE_CODE (stmt) == MODIFY_EXPR)
442         {
443           lhs = TREE_OPERAND (stmt, 0);
444           rhs = TREE_OPERAND (stmt, 1);
445         }
446       else if (TREE_CODE (stmt) == RETURN_EXPR)
447         {
448           tree e = TREE_OPERAND (stmt, 0);
449           lhs = TREE_OPERAND (e, 0);
450           rhs = TREE_OPERAND (e, 1);
451         }
452       else if (TREE_CODE (stmt) == ASM_EXPR)
453         {
454           lhs = ASM_OUTPUTS (stmt);
455           rhs = ASM_INPUTS (stmt);
456         }
457       else
458         {
459           lhs = NULL_TREE;
460           rhs = stmt;
461         }
462
463       if (lhs && (TREE_CODE (lhs) == TREE_LIST || EXPR_P (lhs)))
464         {
465           struct count_ptr_d count;
466           count.ptr = ptr;
467           count.count = 0;
468           walk_tree (&lhs, count_ptr_derefs, &count, NULL);
469           *is_store = true;
470           *num_derefs_p = count.count;
471         }
472
473       if (rhs && (TREE_CODE (rhs) == TREE_LIST || EXPR_P (rhs)))
474         {
475           struct count_ptr_d count;
476           count.ptr = ptr;
477           count.count = 0;
478           walk_tree (&rhs, count_ptr_derefs, &count, NULL);
479           *num_derefs_p += count.count;
480         }
481     }
482
483   gcc_assert (*num_uses_p >= *num_derefs_p);
484 }
485
486
487 /* Initialize the data structures used for alias analysis.  */
488
489 static struct alias_info *
490 init_alias_info (void)
491 {
492   struct alias_info *ai;
493
494   ai = xcalloc (1, sizeof (struct alias_info));
495   ai->ssa_names_visited = sbitmap_alloc (num_ssa_names);
496   sbitmap_zero (ai->ssa_names_visited);
497   VARRAY_TREE_INIT (ai->processed_ptrs, 50, "processed_ptrs");
498   ai->addresses_needed = BITMAP_ALLOC (NULL);
499   VARRAY_UINT_INIT (ai->num_references, num_referenced_vars, "num_references");
500   ai->written_vars = BITMAP_ALLOC (NULL);
501   ai->dereferenced_ptrs_store = BITMAP_ALLOC (NULL);
502   ai->dereferenced_ptrs_load = BITMAP_ALLOC (NULL);
503
504   /* If aliases have been computed before, clear existing information.  */
505   if (aliases_computed_p)
506     {
507       unsigned i;
508   
509       /* Similarly, clear the set of addressable variables.  In this
510          case, we can just clear the set because addressability is
511          only computed here.  */
512       bitmap_clear (addressable_vars);
513
514       /* Clear flow-insensitive alias information from each symbol.  */
515       for (i = 0; i < num_referenced_vars; i++)
516         {
517           tree var = referenced_var (i);
518           var_ann_t ann = var_ann (var);
519
520           ann->is_alias_tag = 0;
521           ann->may_aliases = NULL;
522
523           /* Since we are about to re-discover call-clobbered
524              variables, clear the call-clobbered flag.  Variables that
525              are intrinsically call-clobbered (globals, local statics,
526              etc) will not be marked by the aliasing code, so we can't
527              remove them from CALL_CLOBBERED_VARS.  
528
529              NB: STRUCT_FIELDS are still call clobbered if they are for
530              a global variable, so we *don't* clear their call clobberedness
531              just because they are tags, though we will clear it if they
532              aren't for global variables.  */
533           if (ann->mem_tag_kind == NAME_TAG 
534               || ann->mem_tag_kind == TYPE_TAG 
535               || !is_global_var (var))
536             clear_call_clobbered (var);
537         }
538
539       /* Clear flow-sensitive points-to information from each SSA name.  */
540       for (i = 1; i < num_ssa_names; i++)
541         {
542           tree name = ssa_name (i);
543
544           if (!name || !POINTER_TYPE_P (TREE_TYPE (name)))
545             continue;
546
547           if (SSA_NAME_PTR_INFO (name))
548             {
549               struct ptr_info_def *pi = SSA_NAME_PTR_INFO (name);
550
551               /* Clear all the flags but keep the name tag to
552                  avoid creating new temporaries unnecessarily.  If
553                  this pointer is found to point to a subset or
554                  superset of its former points-to set, then a new
555                  tag will need to be created in create_name_tags.  */
556               pi->pt_anything = 0;
557               pi->pt_malloc = 0;
558               pi->pt_null = 0;
559               pi->value_escapes_p = 0;
560               pi->is_dereferenced = 0;
561               if (pi->pt_vars)
562                 bitmap_clear (pi->pt_vars);
563             }
564         }
565     }
566
567   /* Next time, we will need to reset alias information.  */
568   aliases_computed_p = true;
569
570   return ai;
571 }
572
573
574 /* Deallocate memory used by alias analysis.  */
575
576 static void
577 delete_alias_info (struct alias_info *ai)
578 {
579   size_t i;
580
581   sbitmap_free (ai->ssa_names_visited);
582   ai->processed_ptrs = NULL;
583   BITMAP_FREE (ai->addresses_needed);
584
585   for (i = 0; i < ai->num_addressable_vars; i++)
586     {
587       sbitmap_free (ai->addressable_vars[i]->may_aliases);
588       free (ai->addressable_vars[i]);
589     }
590   free (ai->addressable_vars);
591
592   for (i = 0; i < ai->num_pointers; i++)
593     {
594       sbitmap_free (ai->pointers[i]->may_aliases);
595       free (ai->pointers[i]);
596     }
597   free (ai->pointers);
598
599   ai->num_references = NULL;
600   BITMAP_FREE (ai->written_vars);
601   BITMAP_FREE (ai->dereferenced_ptrs_store);
602   BITMAP_FREE (ai->dereferenced_ptrs_load);
603
604   free (ai);
605 }
606
607
608 /* Walk use-def chains for pointer PTR to determine what variables is PTR
609    pointing to.  */
610
611 static void
612 collect_points_to_info_for (struct alias_info *ai, tree ptr)
613 {
614   gcc_assert (POINTER_TYPE_P (TREE_TYPE (ptr)));
615
616   if (!TEST_BIT (ai->ssa_names_visited, SSA_NAME_VERSION (ptr)))
617     {
618       SET_BIT (ai->ssa_names_visited, SSA_NAME_VERSION (ptr));
619       walk_use_def_chains (ptr, collect_points_to_info_r, ai, true);
620       VARRAY_PUSH_TREE (ai->processed_ptrs, ptr);
621     }
622 }
623
624
625 /* Traverse use-def links for all the pointers in the program to collect
626    address escape and points-to information.
627    
628    This is loosely based on the same idea described in R. Hasti and S.
629    Horwitz, ``Using static single assignment form to improve
630    flow-insensitive pointer analysis,'' in SIGPLAN Conference on
631    Programming Language Design and Implementation, pp. 97-105, 1998.  */
632
633 static void
634 compute_points_to_and_addr_escape (struct alias_info *ai)
635 {
636   basic_block bb;
637   unsigned i;
638   tree op;
639   ssa_op_iter iter;
640
641   timevar_push (TV_TREE_PTA);
642
643   FOR_EACH_BB (bb)
644     {
645       bb_ann_t block_ann = bb_ann (bb);
646       block_stmt_iterator si;
647
648       for (si = bsi_start (bb); !bsi_end_p (si); bsi_next (&si))
649         {
650           bitmap addr_taken;
651           tree stmt = bsi_stmt (si);
652           bool stmt_escapes_p = is_escape_site (stmt, ai);
653           bitmap_iterator bi;
654
655           /* Mark all the variables whose address are taken by the
656              statement.  Note that this will miss all the addresses taken
657              in PHI nodes (those are discovered while following the use-def
658              chains).  */
659           get_stmt_operands (stmt);
660           addr_taken = addresses_taken (stmt);
661           if (addr_taken)
662             EXECUTE_IF_SET_IN_BITMAP (addr_taken, 0, i, bi)
663               {
664                 tree var = referenced_var (i);
665                 bitmap_set_bit (ai->addresses_needed, var_ann (var)->uid);
666                 if (stmt_escapes_p)
667                   mark_call_clobbered (var);
668               }
669
670           if (stmt_escapes_p)
671             block_ann->has_escape_site = 1;
672
673           FOR_EACH_SSA_TREE_OPERAND (op, stmt, iter, SSA_OP_USE)
674             {
675               var_ann_t v_ann = var_ann (SSA_NAME_VAR (op));
676               struct ptr_info_def *pi;
677               bool is_store;
678               unsigned num_uses, num_derefs;
679
680               /* If the operand's variable may be aliased, keep track
681                  of how many times we've referenced it.  This is used
682                  for alias grouping in compute_flow_sensitive_aliasing.
683                  Note that we don't need to grow AI->NUM_REFERENCES
684                  because we are processing regular variables, not
685                  memory tags (the array's initial size is set to
686                  NUM_REFERENCED_VARS).  */
687               if (may_be_aliased (SSA_NAME_VAR (op)))
688                 (VARRAY_UINT (ai->num_references, v_ann->uid))++;
689
690               if (!POINTER_TYPE_P (TREE_TYPE (op)))
691                 continue;
692
693               collect_points_to_info_for (ai, op);
694
695               pi = SSA_NAME_PTR_INFO (op);
696               count_uses_and_derefs (op, stmt, &num_uses, &num_derefs,
697                                      &is_store);
698
699               if (num_derefs > 0)
700                 {
701                   /* Mark OP as dereferenced.  In a subsequent pass,
702                      dereferenced pointers that point to a set of
703                      variables will be assigned a name tag to alias
704                      all the variables OP points to.  */
705                   pi->is_dereferenced = 1;
706
707                   /* Keep track of how many time we've dereferenced each
708                      pointer.  Again, we don't need to grow
709                      AI->NUM_REFERENCES because we're processing
710                      existing program variables.  */
711                   (VARRAY_UINT (ai->num_references, v_ann->uid))++;
712
713                   /* If this is a store operation, mark OP as being
714                      dereferenced to store, otherwise mark it as being
715                      dereferenced to load.  */
716                   if (is_store)
717                     bitmap_set_bit (ai->dereferenced_ptrs_store, v_ann->uid);
718                   else
719                     bitmap_set_bit (ai->dereferenced_ptrs_load, v_ann->uid);
720                 }
721
722               if (stmt_escapes_p && num_derefs < num_uses)
723                 {
724                   /* If STMT is an escape point and STMT contains at
725                      least one direct use of OP, then the value of OP
726                      escapes and so the pointed-to variables need to
727                      be marked call-clobbered.  */
728                   pi->value_escapes_p = 1;
729
730                   /* If the statement makes a function call, assume
731                      that pointer OP will be dereferenced in a store
732                      operation inside the called function.  */
733                   if (get_call_expr_in (stmt))
734                     {
735                       bitmap_set_bit (ai->dereferenced_ptrs_store, v_ann->uid);
736                       pi->is_dereferenced = 1;
737                     }
738                 }
739             }
740
741           /* Update reference counter for definitions to any
742              potentially aliased variable.  This is used in the alias
743              grouping heuristics.  */
744           FOR_EACH_SSA_TREE_OPERAND (op, stmt, iter, SSA_OP_DEF)
745             {
746               tree var = SSA_NAME_VAR (op);
747               var_ann_t ann = var_ann (var);
748               bitmap_set_bit (ai->written_vars, ann->uid);
749               if (may_be_aliased (var))
750                 (VARRAY_UINT (ai->num_references, ann->uid))++;
751
752               if (POINTER_TYPE_P (TREE_TYPE (op)))
753                 collect_points_to_info_for (ai, op);
754             }
755
756           /* Mark variables in V_MAY_DEF operands as being written to.  */
757           FOR_EACH_SSA_TREE_OPERAND (op, stmt, iter, SSA_OP_VIRTUAL_DEFS)
758             {
759               tree var = DECL_P (op) ? op : SSA_NAME_VAR (op);
760               var_ann_t ann = var_ann (var);
761               bitmap_set_bit (ai->written_vars, ann->uid);
762             }
763             
764           /* After promoting variables and computing aliasing we will
765              need to re-scan most statements.  FIXME: Try to minimize the
766              number of statements re-scanned.  It's not really necessary to
767              re-scan *all* statements.  */
768           mark_stmt_modified (stmt);
769         }
770     }
771
772   timevar_pop (TV_TREE_PTA);
773 }
774
775
776 /* Create name tags for all the pointers that have been dereferenced.
777    We only create a name tag for a pointer P if P is found to point to
778    a set of variables (so that we can alias them to *P) or if it is
779    the result of a call to malloc (which means that P cannot point to
780    anything else nor alias any other variable).
781
782    If two pointers P and Q point to the same set of variables, they
783    are assigned the same name tag.  */
784
785 static void
786 create_name_tags (struct alias_info *ai)
787 {
788   size_t i;
789
790   for (i = 0; i < VARRAY_ACTIVE_SIZE (ai->processed_ptrs); i++)
791     {
792       tree ptr = VARRAY_TREE (ai->processed_ptrs, i);
793       struct ptr_info_def *pi = SSA_NAME_PTR_INFO (ptr);
794
795       if (pi->pt_anything || !pi->is_dereferenced)
796         {
797           /* No name tags for pointers that have not been
798              dereferenced or point to an arbitrary location.  */
799           pi->name_mem_tag = NULL_TREE;
800           continue;
801         }
802
803       if (pi->pt_vars && !bitmap_empty_p (pi->pt_vars))
804         {
805           size_t j;
806           tree old_name_tag = pi->name_mem_tag;
807
808           /* If PTR points to a set of variables, check if we don't
809              have another pointer Q with the same points-to set before
810              creating a tag.  If so, use Q's tag instead of creating a
811              new one.
812
813              This is important for not creating unnecessary symbols
814              and also for copy propagation.  If we ever need to
815              propagate PTR into Q or vice-versa, we would run into
816              problems if they both had different name tags because
817              they would have different SSA version numbers (which
818              would force us to take the name tags in and out of SSA).  */
819           for (j = 0; j < i; j++)
820             {
821               tree q = VARRAY_TREE (ai->processed_ptrs, j);
822               struct ptr_info_def *qi = SSA_NAME_PTR_INFO (q);
823
824               if (qi
825                   && qi->pt_vars
826                   && qi->name_mem_tag
827                   && bitmap_equal_p (pi->pt_vars, qi->pt_vars))
828                 {
829                   pi->name_mem_tag = qi->name_mem_tag;
830                   break;
831                 }
832             }
833
834           /* If we didn't find a pointer with the same points-to set
835              as PTR, create a new name tag if needed.  */
836           if (pi->name_mem_tag == NULL_TREE)
837             pi->name_mem_tag = get_nmt_for (ptr);
838
839           /* If the new name tag computed for PTR is different than
840              the old name tag that it used to have, then the old tag
841              needs to be removed from the IL, so we mark it for
842              renaming.  */
843           if (old_name_tag && old_name_tag != pi->name_mem_tag)
844             mark_sym_for_renaming (old_name_tag);
845         }
846       else if (pi->pt_malloc)
847         {
848           /* Otherwise, create a unique name tag for this pointer.  */
849           pi->name_mem_tag = get_nmt_for (ptr);
850         }
851       else
852         {
853           /* Only pointers that may point to malloc or other variables
854              may receive a name tag.  If the pointer does not point to
855              a known spot, we should use type tags.  */
856           set_pt_anything (ptr);
857           continue;
858         }
859
860       TREE_THIS_VOLATILE (pi->name_mem_tag)
861           |= TREE_THIS_VOLATILE (TREE_TYPE (TREE_TYPE (ptr)));
862
863       /* Mark the new name tag for renaming.  */
864       mark_sym_for_renaming (pi->name_mem_tag);
865     }
866 }
867
868
869
870 /* For every pointer P_i in AI->PROCESSED_PTRS, create may-alias sets for
871    the name memory tag (NMT) associated with P_i.  If P_i escapes, then its
872    name tag and the variables it points-to are call-clobbered.  Finally, if
873    P_i escapes and we could not determine where it points to, then all the
874    variables in the same alias set as *P_i are marked call-clobbered.  This
875    is necessary because we must assume that P_i may take the address of any
876    variable in the same alias set.  */
877
878 static void
879 compute_flow_sensitive_aliasing (struct alias_info *ai)
880 {
881   size_t i;
882
883   create_name_tags (ai);
884
885   for (i = 0; i < VARRAY_ACTIVE_SIZE (ai->processed_ptrs); i++)
886     {
887       unsigned j;
888       tree ptr = VARRAY_TREE (ai->processed_ptrs, i);
889       struct ptr_info_def *pi = SSA_NAME_PTR_INFO (ptr);
890       var_ann_t v_ann = var_ann (SSA_NAME_VAR (ptr));
891       bitmap_iterator bi;
892
893       if (pi->value_escapes_p || pi->pt_anything)
894         {
895           /* If PTR escapes or may point to anything, then its associated
896              memory tags and pointed-to variables are call-clobbered.  */
897           if (pi->name_mem_tag)
898             mark_call_clobbered (pi->name_mem_tag);
899
900           if (v_ann->type_mem_tag)
901             mark_call_clobbered (v_ann->type_mem_tag);
902
903           if (pi->pt_vars)
904             EXECUTE_IF_SET_IN_BITMAP (pi->pt_vars, 0, j, bi)
905               {
906                 mark_call_clobbered (referenced_var (j));
907               }
908         }
909
910       /* Set up aliasing information for PTR's name memory tag (if it has
911          one).  Note that only pointers that have been dereferenced will
912          have a name memory tag.  */
913       if (pi->name_mem_tag && pi->pt_vars)
914         EXECUTE_IF_SET_IN_BITMAP (pi->pt_vars, 0, j, bi)
915           {
916             add_may_alias (pi->name_mem_tag, referenced_var (j));
917             add_may_alias (v_ann->type_mem_tag, referenced_var (j));
918           }
919
920       /* If the name tag is call clobbered, so is the type tag
921          associated with the base VAR_DECL.  */
922       if (pi->name_mem_tag
923           && v_ann->type_mem_tag
924           && is_call_clobbered (pi->name_mem_tag))
925         mark_call_clobbered (v_ann->type_mem_tag);
926     }
927 }
928
929
930 /* Compute type-based alias sets.  Traverse all the pointers and
931    addressable variables found in setup_pointers_and_addressables.
932    
933    For every pointer P in AI->POINTERS and addressable variable V in
934    AI->ADDRESSABLE_VARS, add V to the may-alias sets of P's type
935    memory tag (TMT) if their alias sets conflict.  V is then marked as
936    an alias tag so that the operand scanner knows that statements
937    containing V have aliased operands.  */
938
939 static void
940 compute_flow_insensitive_aliasing (struct alias_info *ai)
941 {
942   size_t i;
943
944   /* Initialize counter for the total number of virtual operands that
945      aliasing will introduce.  When AI->TOTAL_ALIAS_VOPS goes beyond the
946      threshold set by --params max-alias-vops, we enable alias
947      grouping.  */
948   ai->total_alias_vops = 0;
949
950   /* For every pointer P, determine which addressable variables may alias
951      with P's type memory tag.  */
952   for (i = 0; i < ai->num_pointers; i++)
953     {
954       size_t j;
955       struct alias_map_d *p_map = ai->pointers[i];
956       tree tag = var_ann (p_map->var)->type_mem_tag;
957       var_ann_t tag_ann = var_ann (tag);
958
959       p_map->total_alias_vops = 0;
960       p_map->may_aliases = sbitmap_alloc (num_referenced_vars);
961       sbitmap_zero (p_map->may_aliases);
962
963       for (j = 0; j < ai->num_addressable_vars; j++)
964         {
965           struct alias_map_d *v_map;
966           var_ann_t v_ann;
967           tree var;
968           bool tag_stored_p, var_stored_p;
969           
970           v_map = ai->addressable_vars[j];
971           var = v_map->var;
972           v_ann = var_ann (var);
973
974           /* Skip memory tags and variables that have never been
975              written to.  We also need to check if the variables are
976              call-clobbered because they may be overwritten by
977              function calls.
978
979              Note this is effectively random accessing elements in
980              the sparse bitset, which can be highly inefficient.
981              So we first check the call_clobbered status of the
982              tag and variable before querying the bitmap.  */
983           tag_stored_p = is_call_clobbered (tag)
984                          || bitmap_bit_p (ai->written_vars, tag_ann->uid);
985           var_stored_p = is_call_clobbered (var)
986                          || bitmap_bit_p (ai->written_vars, v_ann->uid);
987           if (!tag_stored_p && !var_stored_p)
988             continue;
989
990           if (may_alias_p (p_map->var, p_map->set, var, v_map->set))
991             {
992               subvar_t svars;
993               size_t num_tag_refs, num_var_refs;
994
995               num_tag_refs = VARRAY_UINT (ai->num_references, tag_ann->uid);
996               num_var_refs = VARRAY_UINT (ai->num_references, v_ann->uid);
997
998               /* Add VAR to TAG's may-aliases set.  */
999
1000               /* If this is an aggregate, we may have subvariables for it
1001                  that need to be pointed to.  */
1002               if (var_can_have_subvars (var)
1003                   && (svars = get_subvars_for_var (var)))
1004                 {
1005                   subvar_t sv;
1006
1007                   for (sv = svars; sv; sv = sv->next)
1008                     {
1009                       add_may_alias (tag, sv->var);
1010                       /* Update the bitmap used to represent TAG's alias set
1011                          in case we need to group aliases.  */
1012                       SET_BIT (p_map->may_aliases, var_ann (sv->var)->uid);
1013                     }
1014                 }
1015               else
1016                 {
1017                   add_may_alias (tag, var);
1018                   /* Update the bitmap used to represent TAG's alias set
1019                      in case we need to group aliases.  */
1020                   SET_BIT (p_map->may_aliases, var_ann (var)->uid);
1021                 }
1022
1023               /* Update the total number of virtual operands due to
1024                  aliasing.  Since we are adding one more alias to TAG's
1025                  may-aliases set, the total number of virtual operands due
1026                  to aliasing will be increased by the number of references
1027                  made to VAR and TAG (every reference to TAG will also
1028                  count as a reference to VAR).  */
1029               ai->total_alias_vops += (num_var_refs + num_tag_refs);
1030               p_map->total_alias_vops += (num_var_refs + num_tag_refs);
1031
1032
1033             }
1034         }
1035     }
1036
1037   /* Since this analysis is based exclusively on symbols, it fails to
1038      handle cases where two pointers P and Q have different memory
1039      tags with conflicting alias set numbers but no aliased symbols in
1040      common.
1041
1042      For example, suppose that we have two memory tags TMT.1 and TMT.2
1043      such that
1044      
1045                 may-aliases (TMT.1) = { a }
1046                 may-aliases (TMT.2) = { b }
1047
1048      and the alias set number of TMT.1 conflicts with that of TMT.2.
1049      Since they don't have symbols in common, loads and stores from
1050      TMT.1 and TMT.2 will seem independent of each other, which will
1051      lead to the optimizers making invalid transformations (see
1052      testsuite/gcc.c-torture/execute/pr15262-[12].c).
1053
1054      To avoid this problem, we do a final traversal of AI->POINTERS
1055      looking for pairs of pointers that have no aliased symbols in
1056      common and yet have conflicting alias set numbers.  */
1057   for (i = 0; i < ai->num_pointers; i++)
1058     {
1059       size_t j;
1060       struct alias_map_d *p_map1 = ai->pointers[i];
1061       tree tag1 = var_ann (p_map1->var)->type_mem_tag;
1062       sbitmap may_aliases1 = p_map1->may_aliases;
1063
1064       for (j = i + 1; j < ai->num_pointers; j++)
1065         {
1066           struct alias_map_d *p_map2 = ai->pointers[j];
1067           tree tag2 = var_ann (p_map2->var)->type_mem_tag;
1068           sbitmap may_aliases2 = p_map2->may_aliases;
1069
1070           /* If the pointers may not point to each other, do nothing.  */
1071           if (!may_alias_p (p_map1->var, p_map1->set, tag2, p_map2->set))
1072             continue;
1073
1074           /* The two pointers may alias each other.  If they already have
1075              symbols in common, do nothing.  */
1076           if (sbitmap_any_common_bits (may_aliases1, may_aliases2))
1077             continue;
1078
1079           if (sbitmap_first_set_bit (may_aliases2) >= 0)
1080             {
1081               size_t k;
1082
1083               /* Add all the aliases for TAG2 into TAG1's alias set.
1084                  FIXME, update grouping heuristic counters.  */
1085               EXECUTE_IF_SET_IN_SBITMAP (may_aliases2, 0, k,
1086                   add_may_alias (tag1, referenced_var (k)));
1087               sbitmap_a_or_b (may_aliases1, may_aliases1, may_aliases2);
1088             }
1089           else
1090             {
1091               /* Since TAG2 does not have any aliases of its own, add
1092                  TAG2 itself to the alias set of TAG1.  */
1093               add_may_alias (tag1, tag2);
1094               SET_BIT (may_aliases1, var_ann (tag2)->uid);
1095             }
1096         }
1097     }
1098
1099   if (dump_file)
1100     fprintf (dump_file, "%s: Total number of aliased vops: %ld\n",
1101              get_name (current_function_decl),
1102              ai->total_alias_vops);
1103
1104   /* Determine if we need to enable alias grouping.  */
1105   if (ai->total_alias_vops >= MAX_ALIASED_VOPS)
1106     group_aliases (ai);
1107 }
1108
1109
1110 /* Comparison function for qsort used in group_aliases.  */
1111
1112 static int
1113 total_alias_vops_cmp (const void *p, const void *q)
1114 {
1115   const struct alias_map_d **p1 = (const struct alias_map_d **)p;
1116   const struct alias_map_d **p2 = (const struct alias_map_d **)q;
1117   long n1 = (*p1)->total_alias_vops;
1118   long n2 = (*p2)->total_alias_vops;
1119
1120   /* We want to sort in descending order.  */
1121   return (n1 > n2 ? -1 : (n1 == n2) ? 0 : 1);
1122 }
1123
1124 /* Group all the aliases for TAG to make TAG represent all the
1125    variables in its alias set.  Update the total number
1126    of virtual operands due to aliasing (AI->TOTAL_ALIAS_VOPS).  This
1127    function will make TAG be the unique alias tag for all the
1128    variables in its may-aliases.  So, given:
1129
1130         may-aliases(TAG) = { V1, V2, V3 }
1131
1132    This function will group the variables into:
1133
1134         may-aliases(V1) = { TAG }
1135         may-aliases(V2) = { TAG }
1136         may-aliases(V2) = { TAG }  */
1137
1138 static void
1139 group_aliases_into (tree tag, sbitmap tag_aliases, struct alias_info *ai)
1140 {
1141   size_t i;
1142   var_ann_t tag_ann = var_ann (tag);
1143   size_t num_tag_refs = VARRAY_UINT (ai->num_references, tag_ann->uid);
1144
1145   EXECUTE_IF_SET_IN_SBITMAP (tag_aliases, 0, i,
1146     {
1147       tree var = referenced_var (i);
1148       var_ann_t ann = var_ann (var);
1149
1150       /* Make TAG the unique alias of VAR.  */
1151       ann->is_alias_tag = 0;
1152       ann->may_aliases = NULL;
1153
1154       /* Note that VAR and TAG may be the same if the function has no
1155          addressable variables (see the discussion at the end of
1156          setup_pointers_and_addressables).  */
1157       if (var != tag)
1158         add_may_alias (var, tag);
1159
1160       /* Reduce total number of virtual operands contributed
1161          by TAG on behalf of VAR.  Notice that the references to VAR
1162          itself won't be removed.  We will merely replace them with
1163          references to TAG.  */
1164       ai->total_alias_vops -= num_tag_refs;
1165     });
1166
1167   /* We have reduced the number of virtual operands that TAG makes on
1168      behalf of all the variables formerly aliased with it.  However,
1169      we have also "removed" all the virtual operands for TAG itself,
1170      so we add them back.  */
1171   ai->total_alias_vops += num_tag_refs;
1172
1173   /* TAG no longer has any aliases.  */
1174   tag_ann->may_aliases = NULL;
1175 }
1176
1177
1178 /* Group may-aliases sets to reduce the number of virtual operands due
1179    to aliasing.
1180
1181      1- Sort the list of pointers in decreasing number of contributed
1182         virtual operands.
1183
1184      2- Take the first entry in AI->POINTERS and revert the role of
1185         the memory tag and its aliases.  Usually, whenever an aliased
1186         variable Vi is found to alias with a memory tag T, we add Vi
1187         to the may-aliases set for T.  Meaning that after alias
1188         analysis, we will have:
1189
1190                 may-aliases(T) = { V1, V2, V3, ..., Vn }
1191
1192         This means that every statement that references T, will get 'n'
1193         virtual operands for each of the Vi tags.  But, when alias
1194         grouping is enabled, we make T an alias tag and add it to the
1195         alias set of all the Vi variables:
1196
1197                 may-aliases(V1) = { T }
1198                 may-aliases(V2) = { T }
1199                 ...
1200                 may-aliases(Vn) = { T }
1201
1202         This has two effects: (a) statements referencing T will only get
1203         a single virtual operand, and, (b) all the variables Vi will now
1204         appear to alias each other.  So, we lose alias precision to
1205         improve compile time.  But, in theory, a program with such a high
1206         level of aliasing should not be very optimizable in the first
1207         place.
1208
1209      3- Since variables may be in the alias set of more than one
1210         memory tag, the grouping done in step (2) needs to be extended
1211         to all the memory tags that have a non-empty intersection with
1212         the may-aliases set of tag T.  For instance, if we originally
1213         had these may-aliases sets:
1214
1215                 may-aliases(T) = { V1, V2, V3 }
1216                 may-aliases(R) = { V2, V4 }
1217
1218         In step (2) we would have reverted the aliases for T as:
1219
1220                 may-aliases(V1) = { T }
1221                 may-aliases(V2) = { T }
1222                 may-aliases(V3) = { T }
1223
1224         But note that now V2 is no longer aliased with R.  We could
1225         add R to may-aliases(V2), but we are in the process of
1226         grouping aliases to reduce virtual operands so what we do is
1227         add V4 to the grouping to obtain:
1228
1229                 may-aliases(V1) = { T }
1230                 may-aliases(V2) = { T }
1231                 may-aliases(V3) = { T }
1232                 may-aliases(V4) = { T }
1233
1234      4- If the total number of virtual operands due to aliasing is
1235         still above the threshold set by max-alias-vops, go back to (2).  */
1236
1237 static void
1238 group_aliases (struct alias_info *ai)
1239 {
1240   size_t i;
1241
1242   /* Sort the POINTERS array in descending order of contributed
1243      virtual operands.  */
1244   qsort (ai->pointers, ai->num_pointers, sizeof (struct alias_map_d *),
1245          total_alias_vops_cmp);
1246
1247   /* For every pointer in AI->POINTERS, reverse the roles of its tag
1248      and the tag's may-aliases set.  */
1249   for (i = 0; i < ai->num_pointers; i++)
1250     {
1251       size_t j;
1252       tree tag1 = var_ann (ai->pointers[i]->var)->type_mem_tag;
1253       sbitmap tag1_aliases = ai->pointers[i]->may_aliases;
1254
1255       /* Skip tags that have been grouped already.  */
1256       if (ai->pointers[i]->grouped_p)
1257         continue;
1258
1259       /* See if TAG1 had any aliases in common with other type tags.
1260          If we find a TAG2 with common aliases with TAG1, add TAG2's
1261          aliases into TAG1.  */
1262       for (j = i + 1; j < ai->num_pointers; j++)
1263         {
1264           sbitmap tag2_aliases = ai->pointers[j]->may_aliases;
1265
1266           if (sbitmap_any_common_bits (tag1_aliases, tag2_aliases))
1267             {
1268               tree tag2 = var_ann (ai->pointers[j]->var)->type_mem_tag;
1269
1270               sbitmap_a_or_b (tag1_aliases, tag1_aliases, tag2_aliases);
1271
1272               /* TAG2 does not need its aliases anymore.  */
1273               sbitmap_zero (tag2_aliases);
1274               var_ann (tag2)->may_aliases = NULL;
1275
1276               /* TAG1 is the unique alias of TAG2.  */
1277               add_may_alias (tag2, tag1);
1278
1279               ai->pointers[j]->grouped_p = true;
1280             }
1281         }
1282
1283       /* Now group all the aliases we collected into TAG1.  */
1284       group_aliases_into (tag1, tag1_aliases, ai);
1285
1286       /* If we've reduced total number of virtual operands below the
1287          threshold, stop.  */
1288       if (ai->total_alias_vops < MAX_ALIASED_VOPS)
1289         break;
1290     }
1291
1292   /* Finally, all the variables that have been grouped cannot be in
1293      the may-alias set of name memory tags.  Suppose that we have
1294      grouped the aliases in this code so that may-aliases(a) = TMT.20
1295
1296         p_5 = &a;
1297         ...
1298         # a_9 = V_MAY_DEF <a_8>
1299         p_5->field = 0
1300         ... Several modifications to TMT.20 ... 
1301         # VUSE <a_9>
1302         x_30 = p_5->field
1303
1304      Since p_5 points to 'a', the optimizers will try to propagate 0
1305      into p_5->field, but that is wrong because there have been
1306      modifications to 'TMT.20' in between.  To prevent this we have to
1307      replace 'a' with 'TMT.20' in the name tag of p_5.  */
1308   for (i = 0; i < VARRAY_ACTIVE_SIZE (ai->processed_ptrs); i++)
1309     {
1310       size_t j;
1311       tree ptr = VARRAY_TREE (ai->processed_ptrs, i);
1312       tree name_tag = SSA_NAME_PTR_INFO (ptr)->name_mem_tag;
1313       varray_type aliases;
1314       
1315       if (name_tag == NULL_TREE)
1316         continue;
1317
1318       aliases = var_ann (name_tag)->may_aliases;
1319       for (j = 0; aliases && j < VARRAY_ACTIVE_SIZE (aliases); j++)
1320         {
1321           tree alias = VARRAY_TREE (aliases, j);
1322           var_ann_t ann = var_ann (alias);
1323
1324           if ((ann->mem_tag_kind == NOT_A_TAG 
1325                || ann->mem_tag_kind == STRUCT_FIELD)
1326               && ann->may_aliases)
1327             {
1328               tree new_alias;
1329
1330               gcc_assert (VARRAY_ACTIVE_SIZE (ann->may_aliases) == 1);
1331
1332               new_alias = VARRAY_TREE (ann->may_aliases, 0);
1333               replace_may_alias (name_tag, j, new_alias);
1334             }
1335         }
1336     }
1337
1338   if (dump_file)
1339     fprintf (dump_file,
1340              "%s: Total number of aliased vops after grouping: %ld%s\n",
1341              get_name (current_function_decl),
1342              ai->total_alias_vops,
1343              (ai->total_alias_vops < 0) ? " (negative values are OK)" : "");
1344 }
1345
1346
1347 /* Create a new alias set entry for VAR in AI->ADDRESSABLE_VARS.  */
1348
1349 static void
1350 create_alias_map_for (tree var, struct alias_info *ai)
1351 {
1352   struct alias_map_d *alias_map;
1353   alias_map = xcalloc (1, sizeof (*alias_map));
1354   alias_map->var = var;
1355   alias_map->set = get_alias_set (var);
1356   ai->addressable_vars[ai->num_addressable_vars++] = alias_map;
1357 }
1358
1359
1360 /* Create memory tags for all the dereferenced pointers and build the
1361    ADDRESSABLE_VARS and POINTERS arrays used for building the may-alias
1362    sets.  Based on the address escape and points-to information collected
1363    earlier, this pass will also clear the TREE_ADDRESSABLE flag from those
1364    variables whose address is not needed anymore.  */
1365
1366 static void
1367 setup_pointers_and_addressables (struct alias_info *ai)
1368 {
1369   size_t i, n_vars, num_addressable_vars, num_pointers;
1370
1371   /* Size up the arrays ADDRESSABLE_VARS and POINTERS.  */
1372   num_addressable_vars = num_pointers = 0;
1373   for (i = 0; i < num_referenced_vars; i++)
1374     {
1375       tree var = referenced_var (i);
1376
1377       if (may_be_aliased (var))
1378         num_addressable_vars++;
1379
1380       if (POINTER_TYPE_P (TREE_TYPE (var)))
1381         {
1382           /* Since we don't keep track of volatile variables, assume that
1383              these pointers are used in indirect store operations.  */
1384           if (TREE_THIS_VOLATILE (var))
1385             bitmap_set_bit (ai->dereferenced_ptrs_store, var_ann (var)->uid);
1386
1387           num_pointers++;
1388         }
1389     }
1390
1391   /* Create ADDRESSABLE_VARS and POINTERS.  Note that these arrays are
1392      always going to be slightly bigger than we actually need them
1393      because some TREE_ADDRESSABLE variables will be marked
1394      non-addressable below and only pointers with unique type tags are
1395      going to be added to POINTERS.  */
1396   ai->addressable_vars = xcalloc (num_addressable_vars,
1397                                   sizeof (struct alias_map_d *));
1398   ai->pointers = xcalloc (num_pointers, sizeof (struct alias_map_d *));
1399   ai->num_addressable_vars = 0;
1400   ai->num_pointers = 0;
1401
1402   /* Since we will be creating type memory tags within this loop, cache the
1403      value of NUM_REFERENCED_VARS to avoid processing the additional tags
1404      unnecessarily.  */
1405   n_vars = num_referenced_vars;
1406
1407   for (i = 0; i < n_vars; i++)
1408     {
1409       tree var = referenced_var (i);
1410       var_ann_t v_ann = var_ann (var);
1411       subvar_t svars;
1412
1413       /* Name memory tags already have flow-sensitive aliasing
1414          information, so they need not be processed by
1415          compute_flow_insensitive_aliasing.  Similarly, type memory
1416          tags are already accounted for when we process their
1417          associated pointer. 
1418       
1419          Structure fields, on the other hand, have to have some of this
1420          information processed for them, but it's pointless to mark them
1421          non-addressable (since they are fake variables anyway).  */
1422       if (v_ann->mem_tag_kind != NOT_A_TAG
1423           && v_ann->mem_tag_kind != STRUCT_FIELD) 
1424         continue;
1425
1426       /* Remove the ADDRESSABLE flag from every addressable variable whose
1427          address is not needed anymore.  This is caused by the propagation
1428          of ADDR_EXPR constants into INDIRECT_REF expressions and the
1429          removal of dead pointer assignments done by the early scalar
1430          cleanup passes.  */
1431       if (TREE_ADDRESSABLE (var) && v_ann->mem_tag_kind != STRUCT_FIELD)
1432         {
1433           if (!bitmap_bit_p (ai->addresses_needed, v_ann->uid)
1434               && TREE_CODE (var) != RESULT_DECL
1435               && !is_global_var (var))
1436             {
1437               bool okay_to_mark = true;
1438
1439               /* Since VAR is now a regular GIMPLE register, we will need
1440                  to rename VAR into SSA afterwards.  */
1441               mark_sym_for_renaming (var);
1442
1443               if (var_can_have_subvars (var)
1444                   && (svars = get_subvars_for_var (var)))
1445                 {
1446                   subvar_t sv;
1447
1448                   for (sv = svars; sv; sv = sv->next)
1449                     {         
1450                       var_ann_t svann = var_ann (sv->var);
1451                       if (bitmap_bit_p (ai->addresses_needed, svann->uid))
1452                         okay_to_mark = false;
1453                       mark_sym_for_renaming (sv->var);
1454                     }
1455                 }
1456
1457               /* The address of VAR is not needed, remove the
1458                  addressable bit, so that it can be optimized as a
1459                  regular variable.  */
1460               if (okay_to_mark)
1461                 mark_non_addressable (var);
1462             }
1463           else
1464             {
1465               /* Add the variable to the set of addressables.  Mostly
1466                  used when scanning operands for ASM_EXPRs that
1467                  clobber memory.  In those cases, we need to clobber
1468                  all call-clobbered variables and all addressables.  */
1469               bitmap_set_bit (addressable_vars, v_ann->uid);
1470               if (var_can_have_subvars (var)
1471                   && (svars = get_subvars_for_var (var)))
1472                 {
1473                   subvar_t sv;
1474                   for (sv = svars; sv; sv = sv->next)
1475                     bitmap_set_bit (addressable_vars, var_ann (sv->var)->uid);
1476                 }
1477
1478             }
1479         }
1480
1481       /* Global variables and addressable locals may be aliased.  Create an
1482          entry in ADDRESSABLE_VARS for VAR.  */
1483       if (may_be_aliased (var))
1484         {
1485           create_alias_map_for (var, ai);
1486           mark_sym_for_renaming (var);
1487         }
1488
1489       /* Add pointer variables that have been dereferenced to the POINTERS
1490          array and create a type memory tag for them.  */
1491       if (POINTER_TYPE_P (TREE_TYPE (var)))
1492         {
1493           if ((bitmap_bit_p (ai->dereferenced_ptrs_store, v_ann->uid)
1494                 || bitmap_bit_p (ai->dereferenced_ptrs_load, v_ann->uid)))
1495             {
1496               tree tag;
1497               var_ann_t t_ann;
1498
1499               /* If pointer VAR still doesn't have a memory tag
1500                  associated with it, create it now or re-use an
1501                  existing one.  */
1502               tag = get_tmt_for (var, ai);
1503               t_ann = var_ann (tag);
1504
1505               /* The type tag will need to be renamed into SSA
1506                  afterwards. Note that we cannot do this inside
1507                  get_tmt_for because aliasing may run multiple times
1508                  and we only create type tags the first time.  */
1509               mark_sym_for_renaming (tag);
1510
1511               /* Similarly, if pointer VAR used to have another type
1512                  tag, we will need to process it in the renamer to
1513                  remove the stale virtual operands.  */
1514               if (v_ann->type_mem_tag)
1515                 mark_sym_for_renaming (v_ann->type_mem_tag);
1516
1517               /* Associate the tag with pointer VAR.  */
1518               v_ann->type_mem_tag = tag;
1519
1520               /* If pointer VAR has been used in a store operation,
1521                  then its memory tag must be marked as written-to.  */
1522               if (bitmap_bit_p (ai->dereferenced_ptrs_store, v_ann->uid))
1523                 bitmap_set_bit (ai->written_vars, t_ann->uid);
1524
1525               /* If pointer VAR is a global variable or a PARM_DECL,
1526                  then its memory tag should be considered a global
1527                  variable.  */
1528               if (TREE_CODE (var) == PARM_DECL || is_global_var (var))
1529                 mark_call_clobbered (tag);
1530
1531               /* All the dereferences of pointer VAR count as
1532                  references of TAG.  Since TAG can be associated with
1533                  several pointers, add the dereferences of VAR to the
1534                  TAG.  We may need to grow AI->NUM_REFERENCES because
1535                  we have been adding name and type tags.  */
1536               if (t_ann->uid >= VARRAY_SIZE (ai->num_references))
1537                 VARRAY_GROW (ai->num_references, t_ann->uid + 10);
1538
1539               VARRAY_UINT (ai->num_references, t_ann->uid)
1540                 += VARRAY_UINT (ai->num_references, v_ann->uid);
1541             }
1542           else
1543             {
1544               /* The pointer has not been dereferenced.  If it had a
1545                  type memory tag, remove it and mark the old tag for
1546                  renaming to remove it out of the IL.  */
1547               var_ann_t ann = var_ann (var);
1548               tree tag = ann->type_mem_tag;
1549               if (tag)
1550                 {
1551                   mark_sym_for_renaming (tag);
1552                   ann->type_mem_tag = NULL_TREE;
1553                 }
1554             }
1555         }
1556     }
1557 }
1558
1559
1560 /* Determine whether to use .GLOBAL_VAR to model call clobbering semantics. At
1561    every call site, we need to emit V_MAY_DEF expressions to represent the
1562    clobbering effects of the call for variables whose address escapes the
1563    current function.
1564
1565    One approach is to group all call-clobbered variables into a single
1566    representative that is used as an alias of every call-clobbered variable
1567    (.GLOBAL_VAR).  This works well, but it ties the optimizer hands because
1568    references to any call clobbered variable is a reference to .GLOBAL_VAR.
1569
1570    The second approach is to emit a clobbering V_MAY_DEF for every 
1571    call-clobbered variable at call sites.  This is the preferred way in terms 
1572    of optimization opportunities but it may create too many V_MAY_DEF operands
1573    if there are many call clobbered variables and function calls in the 
1574    function.
1575
1576    To decide whether or not to use .GLOBAL_VAR we multiply the number of
1577    function calls found by the number of call-clobbered variables.  If that
1578    product is beyond a certain threshold, as determined by the parameterized
1579    values shown below, we use .GLOBAL_VAR.
1580
1581    FIXME.  This heuristic should be improved.  One idea is to use several
1582    .GLOBAL_VARs of different types instead of a single one.  The thresholds
1583    have been derived from a typical bootstrap cycle, including all target
1584    libraries. Compile times were found increase by ~1% compared to using
1585    .GLOBAL_VAR.  */
1586
1587 static void
1588 maybe_create_global_var (struct alias_info *ai)
1589 {
1590   unsigned i, n_clobbered;
1591   bitmap_iterator bi;
1592   
1593   /* No need to create it, if we have one already.  */
1594   if (global_var == NULL_TREE)
1595     {
1596       /* Count all the call-clobbered variables.  */
1597       n_clobbered = 0;
1598       EXECUTE_IF_SET_IN_BITMAP (call_clobbered_vars, 0, i, bi)
1599         {
1600           n_clobbered++;
1601         }
1602
1603       /* If the number of virtual operands that would be needed to
1604          model all the call-clobbered variables is larger than
1605          GLOBAL_VAR_THRESHOLD, create .GLOBAL_VAR.
1606
1607          Also create .GLOBAL_VAR if there are no call-clobbered
1608          variables and the program contains a mixture of pure/const
1609          and regular function calls.  This is to avoid the problem
1610          described in PR 20115:
1611
1612               int X;
1613               int func_pure (void) { return X; }
1614               int func_non_pure (int a) { X += a; }
1615               int foo ()
1616               {
1617                 int a = func_pure ();
1618                 func_non_pure (a);
1619                 a = func_pure ();
1620                 return a;
1621               }
1622
1623          Since foo() has no call-clobbered variables, there is
1624          no relationship between the calls to func_pure and
1625          func_non_pure.  Since func_pure has no side-effects, value
1626          numbering optimizations elide the second call to func_pure.
1627          So, if we have some pure/const and some regular calls in the
1628          program we create .GLOBAL_VAR to avoid missing these
1629          relations.  */
1630       if (ai->num_calls_found * n_clobbered >= (size_t) GLOBAL_VAR_THRESHOLD
1631           || (n_clobbered == 0
1632               && ai->num_calls_found > 0
1633               && ai->num_pure_const_calls_found > 0
1634               && ai->num_calls_found > ai->num_pure_const_calls_found))
1635         create_global_var ();
1636     }
1637
1638   /* Mark all call-clobbered symbols for renaming.  Since the initial
1639      rewrite into SSA ignored all call sites, we may need to rename
1640      .GLOBAL_VAR and the call-clobbered variables.  */
1641   EXECUTE_IF_SET_IN_BITMAP (call_clobbered_vars, 0, i, bi)
1642     {
1643       tree var = referenced_var (i);
1644
1645       /* If the function has calls to clobbering functions and
1646          .GLOBAL_VAR has been created, make it an alias for all
1647          call-clobbered variables.  */
1648       if (global_var && var != global_var)
1649         {
1650           subvar_t svars;
1651           add_may_alias (var, global_var);
1652           if (var_can_have_subvars (var)
1653               && (svars = get_subvars_for_var (var)))
1654             {
1655               subvar_t sv;
1656               for (sv = svars; sv; sv = sv->next)
1657                 mark_sym_for_renaming (sv->var);
1658             }
1659         }
1660       
1661       mark_sym_for_renaming (var);
1662     }
1663 }
1664
1665
1666 /* Return TRUE if pointer PTR may point to variable VAR.
1667    
1668    MEM_ALIAS_SET is the alias set for the memory location pointed-to by PTR
1669         This is needed because when checking for type conflicts we are
1670         interested in the alias set of the memory location pointed-to by
1671         PTR.  The alias set of PTR itself is irrelevant.
1672    
1673    VAR_ALIAS_SET is the alias set for VAR.  */
1674
1675 static bool
1676 may_alias_p (tree ptr, HOST_WIDE_INT mem_alias_set,
1677              tree var, HOST_WIDE_INT var_alias_set)
1678 {
1679   tree mem;
1680   var_ann_t m_ann;
1681
1682   alias_stats.alias_queries++;
1683   alias_stats.simple_queries++;
1684
1685   /* By convention, a variable cannot alias itself.  */
1686   mem = var_ann (ptr)->type_mem_tag;
1687   if (mem == var)
1688     {
1689       alias_stats.alias_noalias++;
1690       alias_stats.simple_resolved++;
1691       return false;
1692     }
1693   
1694   /* If -fargument-noalias-global is >1, pointer arguments may
1695      not point to global variables.  */
1696   if (flag_argument_noalias > 1 && is_global_var (var)
1697       && TREE_CODE (ptr) == PARM_DECL)
1698     {
1699       alias_stats.alias_noalias++;
1700       alias_stats.simple_resolved++;
1701       return false;
1702     }
1703
1704   /* If either MEM or VAR is a read-only global and the other one
1705      isn't, then PTR cannot point to VAR.  */
1706   if ((unmodifiable_var_p (mem) && !unmodifiable_var_p (var))
1707       || (unmodifiable_var_p (var) && !unmodifiable_var_p (mem)))
1708     {
1709       alias_stats.alias_noalias++;
1710       alias_stats.simple_resolved++;
1711       return false;
1712     }
1713
1714   m_ann = var_ann (mem);
1715
1716   gcc_assert (m_ann->mem_tag_kind == TYPE_TAG);
1717
1718   alias_stats.tbaa_queries++;
1719
1720   /* If VAR is a pointer with the same alias set as PTR, then dereferencing
1721      PTR can't possibly affect VAR.  Note, that we are specifically testing
1722      for PTR's alias set here, not its pointed-to type.  We also can't
1723      do this check with relaxed aliasing enabled.  */
1724   if (POINTER_TYPE_P (TREE_TYPE (var))
1725       && var_alias_set != 0
1726       && mem_alias_set != 0)
1727     {
1728       HOST_WIDE_INT ptr_alias_set = get_alias_set (ptr);
1729       if (ptr_alias_set == var_alias_set)
1730         {
1731           alias_stats.alias_noalias++;
1732           alias_stats.tbaa_resolved++;
1733           return false;
1734         }
1735     }
1736
1737   /* If the alias sets don't conflict then MEM cannot alias VAR.  */
1738   if (!alias_sets_conflict_p (mem_alias_set, var_alias_set))
1739     {
1740       alias_stats.alias_noalias++;
1741       alias_stats.tbaa_resolved++;
1742       return false;
1743     }
1744   alias_stats.alias_mayalias++;
1745   return true;
1746 }
1747
1748
1749 /* Add ALIAS to the set of variables that may alias VAR.  */
1750
1751 static void
1752 add_may_alias (tree var, tree alias)
1753 {
1754   size_t i;
1755   var_ann_t v_ann = get_var_ann (var);
1756   var_ann_t a_ann = get_var_ann (alias);
1757
1758   gcc_assert (var != alias);
1759
1760   if (v_ann->may_aliases == NULL)
1761     VARRAY_TREE_INIT (v_ann->may_aliases, 2, "aliases");
1762
1763   /* Avoid adding duplicates.  */
1764   for (i = 0; i < VARRAY_ACTIVE_SIZE (v_ann->may_aliases); i++)
1765     if (alias == VARRAY_TREE (v_ann->may_aliases, i))
1766       return;
1767
1768   /* If VAR is a call-clobbered variable, so is its new ALIAS.
1769      FIXME, call-clobbering should only depend on whether an address
1770      escapes.  It should be independent of aliasing.  */
1771   if (is_call_clobbered (var))
1772     mark_call_clobbered (alias);
1773
1774   /* Likewise.  If ALIAS is call-clobbered, so is VAR.  */
1775   else if (is_call_clobbered (alias))
1776     mark_call_clobbered (var);
1777
1778   VARRAY_PUSH_TREE (v_ann->may_aliases, alias);
1779   a_ann->is_alias_tag = 1;
1780 }
1781
1782
1783 /* Replace alias I in the alias sets of VAR with NEW_ALIAS.  */
1784
1785 static void
1786 replace_may_alias (tree var, size_t i, tree new_alias)
1787 {
1788   var_ann_t v_ann = var_ann (var);
1789   VARRAY_TREE (v_ann->may_aliases, i) = new_alias;
1790
1791   /* If VAR is a call-clobbered variable, so is NEW_ALIAS.
1792      FIXME, call-clobbering should only depend on whether an address
1793      escapes.  It should be independent of aliasing.  */
1794   if (is_call_clobbered (var))
1795     mark_call_clobbered (new_alias);
1796
1797   /* Likewise.  If NEW_ALIAS is call-clobbered, so is VAR.  */
1798   else if (is_call_clobbered (new_alias))
1799     mark_call_clobbered (var);
1800 }
1801
1802
1803 /* Mark pointer PTR as pointing to an arbitrary memory location.  */
1804
1805 static void
1806 set_pt_anything (tree ptr)
1807 {
1808   struct ptr_info_def *pi = get_ptr_info (ptr);
1809
1810   pi->pt_anything = 1;
1811   pi->pt_malloc = 0;
1812
1813   /* The pointer used to have a name tag, but we now found it pointing
1814      to an arbitrary location.  The name tag needs to be renamed and
1815      disassociated from PTR.  */
1816   if (pi->name_mem_tag)
1817     {
1818       mark_sym_for_renaming (pi->name_mem_tag);
1819       pi->name_mem_tag = NULL_TREE;
1820     }
1821 }
1822
1823
1824 /* Mark pointer PTR as pointing to a malloc'd memory area.  */
1825
1826 static void
1827 set_pt_malloc (tree ptr)
1828 {
1829   struct ptr_info_def *pi = SSA_NAME_PTR_INFO (ptr);
1830
1831   /* If the pointer has already been found to point to arbitrary
1832      memory locations, it is unsafe to mark it as pointing to malloc.  */
1833   if (pi->pt_anything)
1834     return;
1835
1836   pi->pt_malloc = 1;
1837 }
1838
1839
1840 /* Given two different pointers DEST and ORIG.  Merge the points-to
1841    information in ORIG into DEST.  AI contains all the alias
1842    information collected up to this point.  */
1843
1844 static void
1845 merge_pointed_to_info (struct alias_info *ai, tree dest, tree orig)
1846 {
1847   struct ptr_info_def *dest_pi, *orig_pi;
1848
1849   gcc_assert (dest != orig);
1850
1851   /* Make sure we have points-to information for ORIG.  */
1852   collect_points_to_info_for (ai, orig);
1853
1854   dest_pi = get_ptr_info (dest);
1855   orig_pi = SSA_NAME_PTR_INFO (orig);
1856
1857   if (orig_pi)
1858     {
1859       gcc_assert (orig_pi != dest_pi);
1860
1861       /* Notice that we never merge PT_MALLOC.  This attribute is only
1862          true if the pointer is the result of a malloc() call.
1863          Otherwise, we can end up in this situation:
1864
1865          P_i = malloc ();
1866          ...
1867          P_j = P_i + X;
1868
1869          P_j would be marked as PT_MALLOC, however we currently do not
1870          handle cases of more than one pointer pointing to the same
1871          malloc'd area.
1872
1873          FIXME: If the merging comes from an expression that preserves
1874          the PT_MALLOC attribute (copy assignment, address
1875          arithmetic), we ought to merge PT_MALLOC, but then both
1876          pointers would end up getting different name tags because
1877          create_name_tags is not smart enough to determine that the
1878          two come from the same malloc call.  Copy propagation before
1879          aliasing should cure this.  */
1880       dest_pi->pt_malloc = 0;
1881       if (orig_pi->pt_malloc || orig_pi->pt_anything)
1882         set_pt_anything (dest);
1883
1884       dest_pi->pt_null |= orig_pi->pt_null;
1885
1886       if (!dest_pi->pt_anything
1887           && orig_pi->pt_vars
1888           && !bitmap_empty_p (orig_pi->pt_vars))
1889         {
1890           if (dest_pi->pt_vars == NULL)
1891             {
1892               dest_pi->pt_vars = BITMAP_GGC_ALLOC ();
1893               bitmap_copy (dest_pi->pt_vars, orig_pi->pt_vars);
1894             }
1895           else
1896             bitmap_ior_into (dest_pi->pt_vars, orig_pi->pt_vars);
1897         }
1898     }
1899   else
1900     set_pt_anything (dest);
1901 }
1902
1903
1904 /* Add EXPR to the list of expressions pointed-to by PTR.  */
1905
1906 static void
1907 add_pointed_to_expr (struct alias_info *ai, tree ptr, tree expr)
1908 {
1909   if (TREE_CODE (expr) == WITH_SIZE_EXPR)
1910     expr = TREE_OPERAND (expr, 0);
1911
1912   get_ptr_info (ptr);
1913
1914   if (TREE_CODE (expr) == CALL_EXPR
1915       && (call_expr_flags (expr) & (ECF_MALLOC | ECF_MAY_BE_ALLOCA)))
1916     {
1917       /* If EXPR is a malloc-like call, then the area pointed to PTR
1918          is guaranteed to not alias with anything else.  */
1919       set_pt_malloc (ptr);
1920     }
1921   else if (TREE_CODE (expr) == ADDR_EXPR)
1922     {
1923       /* Found P_i = ADDR_EXPR  */
1924       add_pointed_to_var (ai, ptr, expr);
1925     }
1926   else if (TREE_CODE (expr) == SSA_NAME && POINTER_TYPE_P (TREE_TYPE (expr)))
1927     {
1928       /* Found P_i = Q_j.  */
1929       merge_pointed_to_info (ai, ptr, expr);
1930     }
1931   else if (TREE_CODE (expr) == PLUS_EXPR || TREE_CODE (expr) == MINUS_EXPR)
1932     {
1933       /* Found P_i = PLUS_EXPR or P_i = MINUS_EXPR  */
1934       tree op0 = TREE_OPERAND (expr, 0);
1935       tree op1 = TREE_OPERAND (expr, 1);
1936
1937       /* Both operands may be of pointer type.  FIXME: Shouldn't
1938          we just expect PTR + OFFSET always?  */
1939       if (POINTER_TYPE_P (TREE_TYPE (op0))
1940           && TREE_CODE (op0) != INTEGER_CST)
1941         {
1942           if (TREE_CODE (op0) == SSA_NAME)
1943             merge_pointed_to_info (ai, ptr, op0);
1944           else if (TREE_CODE (op0) == ADDR_EXPR)
1945             add_pointed_to_var (ai, ptr, op0);
1946           else
1947             set_pt_anything (ptr);
1948         }
1949
1950       if (POINTER_TYPE_P (TREE_TYPE (op1))
1951           && TREE_CODE (op1) != INTEGER_CST)
1952         {
1953           if (TREE_CODE (op1) == SSA_NAME)
1954             merge_pointed_to_info (ai, ptr, op1);
1955           else if (TREE_CODE (op1) == ADDR_EXPR)
1956             add_pointed_to_var (ai, ptr, op1);
1957           else
1958             set_pt_anything (ptr);
1959         }
1960
1961       /* Neither operand is a pointer?  VAR can be pointing anywhere.
1962          FIXME: Shouldn't we abort here?  If we get here, we found
1963          PTR = INT_CST + INT_CST, which should not be a valid pointer
1964          expression.  */
1965       if (!(POINTER_TYPE_P (TREE_TYPE (op0))
1966             && TREE_CODE (op0) != INTEGER_CST)
1967           && !(POINTER_TYPE_P (TREE_TYPE (op1))
1968                && TREE_CODE (op1) != INTEGER_CST))
1969         set_pt_anything (ptr);
1970     }
1971   else if (integer_zerop (expr))
1972     {
1973       /* EXPR is the NULL pointer.  Mark PTR as pointing to NULL.  */
1974       SSA_NAME_PTR_INFO (ptr)->pt_null = 1;
1975     }
1976   else
1977     {
1978       /* If we can't recognize the expression, assume that PTR may
1979          point anywhere.  */
1980       set_pt_anything (ptr);
1981     }
1982 }
1983
1984
1985 /* If VALUE is of the form &DECL, add DECL to the set of variables
1986    pointed-to by PTR.  Otherwise, add VALUE as a pointed-to expression by
1987    PTR.  AI points to the collected alias information.  */
1988
1989 static void
1990 add_pointed_to_var (struct alias_info *ai, tree ptr, tree value)
1991 {
1992   struct ptr_info_def *pi = get_ptr_info (ptr);
1993   tree pt_var = NULL_TREE;
1994   HOST_WIDE_INT offset, size;
1995   tree addrop;
1996   size_t uid;
1997   tree ref;
1998   subvar_t svars;
1999
2000   gcc_assert (TREE_CODE (value) == ADDR_EXPR);
2001
2002   addrop = TREE_OPERAND (value, 0);
2003   if (REFERENCE_CLASS_P (addrop))
2004     pt_var = get_base_address (addrop);
2005   else 
2006     pt_var = addrop;
2007
2008   /* If this is a component_ref, see if we can get a smaller number of
2009      variables to take the address of.  */
2010   if (TREE_CODE (addrop) == COMPONENT_REF
2011       && (ref = okay_component_ref_for_subvars (addrop, &offset ,&size)))
2012     {    
2013       subvar_t sv;
2014       svars = get_subvars_for_var (ref);
2015
2016       uid = var_ann (pt_var)->uid;
2017       
2018       if (pi->pt_vars == NULL)
2019         pi->pt_vars = BITMAP_GGC_ALLOC ();
2020        /* If the variable is a global, mark the pointer as pointing to
2021          global memory (which will make its tag a global variable).  */
2022       if (is_global_var (pt_var))
2023         pi->pt_global_mem = 1;     
2024
2025       for (sv = svars; sv; sv = sv->next)
2026         {
2027           if (overlap_subvar (offset, size, sv, NULL))
2028             {
2029               bitmap_set_bit (pi->pt_vars, var_ann (sv->var)->uid);
2030               bitmap_set_bit (ai->addresses_needed, var_ann (sv->var)->uid);
2031             }
2032         }
2033     }
2034   else if (pt_var && SSA_VAR_P (pt_var))
2035     {
2036     
2037       uid = var_ann (pt_var)->uid;
2038       
2039       if (pi->pt_vars == NULL)
2040         pi->pt_vars = BITMAP_GGC_ALLOC ();
2041
2042       /* If this is an aggregate, we may have subvariables for it that need
2043          to be pointed to.  */
2044       if (var_can_have_subvars (pt_var)
2045           && (svars = get_subvars_for_var (pt_var)))
2046         {
2047           subvar_t sv;
2048           for (sv = svars; sv; sv = sv->next)
2049             {
2050               uid = var_ann (sv->var)->uid;
2051               bitmap_set_bit (ai->addresses_needed, uid);             
2052               bitmap_set_bit (pi->pt_vars, uid);
2053             }
2054         }
2055       else      
2056         {
2057           bitmap_set_bit (ai->addresses_needed, uid);
2058           bitmap_set_bit (pi->pt_vars, uid);      
2059         }
2060
2061       /* If the variable is a global, mark the pointer as pointing to
2062          global memory (which will make its tag a global variable).  */
2063       if (is_global_var (pt_var))
2064         pi->pt_global_mem = 1;
2065     }
2066 }
2067
2068
2069 /* Callback for walk_use_def_chains to gather points-to information from the
2070    SSA web.
2071    
2072    VAR is an SSA variable or a GIMPLE expression.
2073    
2074    STMT is the statement that generates the SSA variable or, if STMT is a
2075       PHI_NODE, VAR is one of the PHI arguments.
2076
2077    DATA is a pointer to a structure of type ALIAS_INFO.  */
2078
2079 static bool
2080 collect_points_to_info_r (tree var, tree stmt, void *data)
2081 {
2082   struct alias_info *ai = (struct alias_info *) data;
2083
2084   if (dump_file && (dump_flags & TDF_DETAILS))
2085     {
2086       fprintf (dump_file, "Visiting use-def links for ");
2087       print_generic_expr (dump_file, var, dump_flags);
2088       fprintf (dump_file, "\n");
2089     }
2090
2091   switch (TREE_CODE (stmt))
2092     {
2093     case RETURN_EXPR:
2094       gcc_assert (TREE_CODE (TREE_OPERAND (stmt, 0)) == MODIFY_EXPR);
2095       stmt = TREE_OPERAND (stmt, 0);
2096       /* FALLTHRU  */
2097
2098     case MODIFY_EXPR:
2099       {
2100         tree rhs = TREE_OPERAND (stmt, 1);
2101         STRIP_NOPS (rhs);
2102         add_pointed_to_expr (ai, var, rhs);
2103         break;
2104       }
2105
2106     case ASM_EXPR:
2107       /* Pointers defined by __asm__ statements can point anywhere.  */
2108       set_pt_anything (var);
2109       break;
2110
2111     case NOP_EXPR:
2112       if (IS_EMPTY_STMT (stmt))
2113         {
2114           tree decl = SSA_NAME_VAR (var);
2115           
2116           if (TREE_CODE (decl) == PARM_DECL)
2117             add_pointed_to_expr (ai, var, decl);
2118           else if (DECL_INITIAL (decl))
2119             add_pointed_to_expr (ai, var, DECL_INITIAL (decl));
2120           else
2121             add_pointed_to_expr (ai, var, decl);
2122         }
2123       break;
2124
2125     case PHI_NODE:
2126       {
2127         /* It STMT is a PHI node, then VAR is one of its arguments.  The
2128            variable that we are analyzing is the LHS of the PHI node.  */
2129         tree lhs = PHI_RESULT (stmt);
2130
2131         switch (TREE_CODE (var))
2132           {
2133           case ADDR_EXPR:
2134             add_pointed_to_var (ai, lhs, var);
2135             break;
2136             
2137           case SSA_NAME:
2138             /* Avoid unnecessary merges.  */
2139             if (lhs != var)
2140               merge_pointed_to_info (ai, lhs, var);
2141             break;
2142             
2143           default:
2144             gcc_assert (is_gimple_min_invariant (var));
2145             add_pointed_to_expr (ai, lhs, var);
2146             break;
2147           }
2148         break;
2149       }
2150
2151     default:
2152       gcc_unreachable ();
2153     }
2154   
2155   return false;
2156 }
2157
2158
2159 /* Return true if STMT is an "escape" site from the current function.  Escape
2160    sites those statements which might expose the address of a variable
2161    outside the current function.  STMT is an escape site iff:
2162
2163         1- STMT is a function call, or
2164         2- STMT is an __asm__ expression, or
2165         3- STMT is an assignment to a non-local variable, or
2166         4- STMT is a return statement.
2167
2168    AI points to the alias information collected so far.  */
2169
2170 static bool
2171 is_escape_site (tree stmt, struct alias_info *ai)
2172 {
2173   tree call = get_call_expr_in (stmt);
2174   if (call != NULL_TREE)
2175     {
2176       ai->num_calls_found++;
2177
2178       if (!TREE_SIDE_EFFECTS (call))
2179         ai->num_pure_const_calls_found++;
2180
2181       return true;
2182     }
2183   else if (TREE_CODE (stmt) == ASM_EXPR)
2184     return true;
2185   else if (TREE_CODE (stmt) == MODIFY_EXPR)
2186     {
2187       tree lhs = TREE_OPERAND (stmt, 0);
2188
2189       /* Get to the base of _REF nodes.  */
2190       if (TREE_CODE (lhs) != SSA_NAME)
2191         lhs = get_base_address (lhs);
2192
2193       /* If we couldn't recognize the LHS of the assignment, assume that it
2194          is a non-local store.  */
2195       if (lhs == NULL_TREE)
2196         return true;
2197
2198       /* If the RHS is a conversion between a pointer and an integer, the
2199          pointer escapes since we can't track the integer.  */
2200       if ((TREE_CODE (TREE_OPERAND (stmt, 1)) == NOP_EXPR
2201            || TREE_CODE (TREE_OPERAND (stmt, 1)) == CONVERT_EXPR
2202            || TREE_CODE (TREE_OPERAND (stmt, 1)) == VIEW_CONVERT_EXPR)
2203           && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND
2204                                         (TREE_OPERAND (stmt, 1), 0)))
2205           && !POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (stmt, 1))))
2206         return true;
2207
2208       /* If the LHS is an SSA name, it can't possibly represent a non-local
2209          memory store.  */
2210       if (TREE_CODE (lhs) == SSA_NAME)
2211         return false;
2212
2213       /* FIXME: LHS is not an SSA_NAME.  Even if it's an assignment to a
2214          local variables we cannot be sure if it will escape, because we
2215          don't have information about objects not in SSA form.  Need to
2216          implement something along the lines of
2217
2218          J.-D. Choi, M. Gupta, M. J. Serrano, V. C. Sreedhar, and S. P.
2219          Midkiff, ``Escape analysis for java,'' in Proceedings of the
2220          Conference on Object-Oriented Programming Systems, Languages, and
2221          Applications (OOPSLA), pp. 1-19, 1999.  */
2222       return true;
2223     }
2224   else if (TREE_CODE (stmt) == RETURN_EXPR)
2225     return true;
2226
2227   return false;
2228 }
2229
2230
2231 /* Create a new memory tag of type TYPE.  If IS_TYPE_TAG is true, the tag
2232    is considered to represent all the pointers whose pointed-to types are
2233    in the same alias set class.  Otherwise, the tag represents a single
2234    SSA_NAME pointer variable.  */
2235
2236 static tree
2237 create_memory_tag (tree type, bool is_type_tag)
2238 {
2239   var_ann_t ann;
2240   tree tag = create_tmp_var_raw (type, (is_type_tag) ? "TMT" : "NMT");
2241
2242   /* By default, memory tags are local variables.  Alias analysis will
2243      determine whether they should be considered globals.  */
2244   DECL_CONTEXT (tag) = current_function_decl;
2245
2246   /* Memory tags are by definition addressable.  This also prevents
2247      is_gimple_ref frome confusing memory tags with optimizable
2248      variables.  */
2249   TREE_ADDRESSABLE (tag) = 1;
2250
2251   ann = get_var_ann (tag);
2252   ann->mem_tag_kind = (is_type_tag) ? TYPE_TAG : NAME_TAG;
2253   ann->type_mem_tag = NULL_TREE;
2254
2255   /* Add the tag to the symbol table.  */
2256   add_referenced_tmp_var (tag);
2257
2258   return tag;
2259 }
2260
2261
2262 /* Create a name memory tag to represent a specific SSA_NAME pointer P_i.
2263    This is used if P_i has been found to point to a specific set of
2264    variables or to a non-aliased memory location like the address returned
2265    by malloc functions.  */
2266
2267 static tree
2268 get_nmt_for (tree ptr)
2269 {
2270   struct ptr_info_def *pi = get_ptr_info (ptr);
2271   tree tag = pi->name_mem_tag;
2272
2273   if (tag == NULL_TREE)
2274     tag = create_memory_tag (TREE_TYPE (TREE_TYPE (ptr)), false);
2275
2276   /* If PTR is a PARM_DECL, it points to a global variable or malloc,
2277      then its name tag should be considered a global variable.  */
2278   if (TREE_CODE (SSA_NAME_VAR (ptr)) == PARM_DECL
2279       || pi->pt_malloc
2280       || pi->pt_global_mem)
2281     mark_call_clobbered (tag);
2282
2283   return tag;
2284 }
2285
2286
2287 /* Return the type memory tag associated to pointer PTR.  A memory tag is an
2288    artificial variable that represents the memory location pointed-to by
2289    PTR.  It is used to model the effects of pointer de-references on
2290    addressable variables.
2291    
2292    AI points to the data gathered during alias analysis.  This function
2293    populates the array AI->POINTERS.  */
2294
2295 static tree
2296 get_tmt_for (tree ptr, struct alias_info *ai)
2297 {
2298   size_t i;
2299   tree tag;
2300   tree tag_type = TREE_TYPE (TREE_TYPE (ptr));
2301   HOST_WIDE_INT tag_set = get_alias_set (tag_type);
2302
2303   /* To avoid creating unnecessary memory tags, only create one memory tag
2304      per alias set class.  Note that it may be tempting to group
2305      memory tags based on conflicting alias sets instead of
2306      equivalence.  That would be wrong because alias sets are not
2307      necessarily transitive (as demonstrated by the libstdc++ test
2308      23_containers/vector/cons/4.cc).  Given three alias sets A, B, C
2309      such that conflicts (A, B) == true and conflicts (A, C) == true,
2310      it does not necessarily follow that conflicts (B, C) == true.  */
2311   for (i = 0, tag = NULL_TREE; i < ai->num_pointers; i++)
2312     {
2313       struct alias_map_d *curr = ai->pointers[i];
2314       tree curr_tag = var_ann (curr->var)->type_mem_tag;
2315       if (tag_set == curr->set
2316           && TYPE_READONLY (tag_type) == TYPE_READONLY (TREE_TYPE (curr_tag)))
2317         {
2318           tag = curr_tag;
2319           break;
2320         }
2321     }
2322
2323   /* If VAR cannot alias with any of the existing memory tags, create a new
2324      tag for PTR and add it to the POINTERS array.  */
2325   if (tag == NULL_TREE)
2326     {
2327       struct alias_map_d *alias_map;
2328
2329       /* If PTR did not have a type tag already, create a new TMT.*
2330          artificial variable representing the memory location
2331          pointed-to by PTR.  */
2332       if (var_ann (ptr)->type_mem_tag == NULL_TREE)
2333         tag = create_memory_tag (tag_type, true);
2334       else
2335         tag = var_ann (ptr)->type_mem_tag;
2336
2337       /* Add PTR to the POINTERS array.  Note that we are not interested in
2338          PTR's alias set.  Instead, we cache the alias set for the memory that
2339          PTR points to.  */
2340       alias_map = xcalloc (1, sizeof (*alias_map));
2341       alias_map->var = ptr;
2342       alias_map->set = tag_set;
2343       ai->pointers[ai->num_pointers++] = alias_map;
2344     }
2345
2346   /* If the pointed-to type is volatile, so is the tag.  */
2347   TREE_THIS_VOLATILE (tag) |= TREE_THIS_VOLATILE (tag_type);
2348
2349   /* Make sure that the type tag has the same alias set as the
2350      pointed-to type.  */
2351   gcc_assert (tag_set == get_alias_set (tag));
2352
2353   /* If PTR's pointed-to type is read-only, then TAG's type must also
2354      be read-only.  */
2355   gcc_assert (TYPE_READONLY (tag_type) == TYPE_READONLY (TREE_TYPE (tag)));
2356
2357   return tag;
2358 }
2359
2360
2361 /* Create GLOBAL_VAR, an artificial global variable to act as a
2362    representative of all the variables that may be clobbered by function
2363    calls.  */
2364
2365 static void
2366 create_global_var (void)
2367 {
2368   global_var = build_decl (VAR_DECL, get_identifier (".GLOBAL_VAR"),
2369                            void_type_node);
2370   DECL_ARTIFICIAL (global_var) = 1;
2371   TREE_READONLY (global_var) = 0;
2372   DECL_EXTERNAL (global_var) = 1;
2373   TREE_STATIC (global_var) = 1;
2374   TREE_USED (global_var) = 1;
2375   DECL_CONTEXT (global_var) = NULL_TREE;
2376   TREE_THIS_VOLATILE (global_var) = 0;
2377   TREE_ADDRESSABLE (global_var) = 0;
2378
2379   add_referenced_tmp_var (global_var);
2380   mark_sym_for_renaming (global_var);
2381 }
2382
2383
2384 /* Dump alias statistics on FILE.  */
2385
2386 static void 
2387 dump_alias_stats (FILE *file)
2388 {
2389   const char *funcname
2390     = lang_hooks.decl_printable_name (current_function_decl, 2);
2391   fprintf (file, "\nAlias statistics for %s\n\n", funcname);
2392   fprintf (file, "Total alias queries:\t%u\n", alias_stats.alias_queries);
2393   fprintf (file, "Total alias mayalias results:\t%u\n", 
2394            alias_stats.alias_mayalias);
2395   fprintf (file, "Total alias noalias results:\t%u\n",
2396            alias_stats.alias_noalias);
2397   fprintf (file, "Total simple queries:\t%u\n",
2398            alias_stats.simple_queries);
2399   fprintf (file, "Total simple resolved:\t%u\n",
2400            alias_stats.simple_resolved);
2401   fprintf (file, "Total TBAA queries:\t%u\n",
2402            alias_stats.tbaa_queries);
2403   fprintf (file, "Total TBAA resolved:\t%u\n",
2404            alias_stats.tbaa_resolved);
2405 }
2406   
2407
2408 /* Dump alias information on FILE.  */
2409
2410 void
2411 dump_alias_info (FILE *file)
2412 {
2413   size_t i;
2414   const char *funcname
2415     = lang_hooks.decl_printable_name (current_function_decl, 2);
2416
2417   fprintf (file, "\nFlow-insensitive alias information for %s\n\n", funcname);
2418
2419   fprintf (file, "Aliased symbols\n\n");
2420   for (i = 0; i < num_referenced_vars; i++)
2421     {
2422       tree var = referenced_var (i);
2423       if (may_be_aliased (var))
2424         dump_variable (file, var);
2425     }
2426
2427   fprintf (file, "\nDereferenced pointers\n\n");
2428   for (i = 0; i < num_referenced_vars; i++)
2429     {
2430       tree var = referenced_var (i);
2431       var_ann_t ann = var_ann (var);
2432       if (ann->type_mem_tag)
2433         dump_variable (file, var);
2434     }
2435
2436   fprintf (file, "\nType memory tags\n\n");
2437   for (i = 0; i < num_referenced_vars; i++)
2438     {
2439       tree var = referenced_var (i);
2440       var_ann_t ann = var_ann (var);
2441       if (ann->mem_tag_kind == TYPE_TAG)
2442         dump_variable (file, var);
2443     }
2444
2445   fprintf (file, "\n\nFlow-sensitive alias information for %s\n\n", funcname);
2446
2447   fprintf (file, "SSA_NAME pointers\n\n");
2448   for (i = 1; i < num_ssa_names; i++)
2449     {
2450       tree ptr = ssa_name (i);
2451       struct ptr_info_def *pi;
2452       
2453       if (ptr == NULL_TREE)
2454         continue;
2455
2456       pi = SSA_NAME_PTR_INFO (ptr);
2457       if (!SSA_NAME_IN_FREE_LIST (ptr)
2458           && pi
2459           && pi->name_mem_tag)
2460         dump_points_to_info_for (file, ptr);
2461     }
2462
2463   fprintf (file, "\nName memory tags\n\n");
2464   for (i = 0; i < num_referenced_vars; i++)
2465     {
2466       tree var = referenced_var (i);
2467       var_ann_t ann = var_ann (var);
2468       if (ann->mem_tag_kind == NAME_TAG)
2469         dump_variable (file, var);
2470     }
2471
2472   fprintf (file, "\n");
2473 }
2474
2475
2476 /* Dump alias information on stderr.  */
2477
2478 void
2479 debug_alias_info (void)
2480 {
2481   dump_alias_info (stderr);
2482 }
2483
2484
2485 /* Return the alias information associated with pointer T.  It creates a
2486    new instance if none existed.  */
2487
2488 struct ptr_info_def *
2489 get_ptr_info (tree t)
2490 {
2491   struct ptr_info_def *pi;
2492
2493   gcc_assert (POINTER_TYPE_P (TREE_TYPE (t)));
2494
2495   pi = SSA_NAME_PTR_INFO (t);
2496   if (pi == NULL)
2497     {
2498       pi = ggc_alloc (sizeof (*pi));
2499       memset ((void *)pi, 0, sizeof (*pi));
2500       SSA_NAME_PTR_INFO (t) = pi;
2501     }
2502
2503   return pi;
2504 }
2505
2506
2507 /* Dump points-to information for SSA_NAME PTR into FILE.  */
2508
2509 void
2510 dump_points_to_info_for (FILE *file, tree ptr)
2511 {
2512   struct ptr_info_def *pi = SSA_NAME_PTR_INFO (ptr);
2513
2514   print_generic_expr (file, ptr, dump_flags);
2515
2516   if (pi)
2517     {
2518       if (pi->name_mem_tag)
2519         {
2520           fprintf (file, ", name memory tag: ");
2521           print_generic_expr (file, pi->name_mem_tag, dump_flags);
2522         }
2523
2524       if (pi->is_dereferenced)
2525         fprintf (file, ", is dereferenced");
2526
2527       if (pi->value_escapes_p)
2528         fprintf (file, ", its value escapes");
2529
2530       if (pi->pt_anything)
2531         fprintf (file, ", points-to anything");
2532
2533       if (pi->pt_malloc)
2534         fprintf (file, ", points-to malloc");
2535
2536       if (pi->pt_null)
2537         fprintf (file, ", points-to NULL");
2538
2539       if (pi->pt_vars)
2540         {
2541           unsigned ix;
2542           bitmap_iterator bi;
2543
2544           fprintf (file, ", points-to vars: { ");
2545           EXECUTE_IF_SET_IN_BITMAP (pi->pt_vars, 0, ix, bi)
2546             {
2547               print_generic_expr (file, referenced_var (ix), dump_flags);
2548               fprintf (file, " ");
2549             }
2550           fprintf (file, "}");
2551         }
2552     }
2553
2554   fprintf (file, "\n");
2555 }
2556
2557
2558 /* Dump points-to information for VAR into stderr.  */
2559
2560 void
2561 debug_points_to_info_for (tree var)
2562 {
2563   dump_points_to_info_for (stderr, var);
2564 }
2565
2566
2567 /* Dump points-to information into FILE.  NOTE: This function is slow, as
2568    it needs to traverse the whole CFG looking for pointer SSA_NAMEs.  */
2569
2570 void
2571 dump_points_to_info (FILE *file)
2572 {
2573   basic_block bb;
2574   block_stmt_iterator si;
2575   size_t i;
2576   ssa_op_iter iter;
2577   const char *fname =
2578     lang_hooks.decl_printable_name (current_function_decl, 2);
2579
2580   fprintf (file, "\n\nPointed-to sets for pointers in %s\n\n", fname);
2581
2582   /* First dump points-to information for the default definitions of
2583      pointer variables.  This is necessary because default definitions are
2584      not part of the code.  */
2585   for (i = 0; i < num_referenced_vars; i++)
2586     {
2587       tree var = referenced_var (i);
2588       if (POINTER_TYPE_P (TREE_TYPE (var)))
2589         {
2590           var_ann_t ann = var_ann (var);
2591           if (ann->default_def)
2592             dump_points_to_info_for (file, ann->default_def);
2593         }
2594     }
2595
2596   /* Dump points-to information for every pointer defined in the program.  */
2597   FOR_EACH_BB (bb)
2598     {
2599       tree phi;
2600
2601       for (phi = phi_nodes (bb); phi; phi = PHI_CHAIN (phi))
2602         {
2603           tree ptr = PHI_RESULT (phi);
2604           if (POINTER_TYPE_P (TREE_TYPE (ptr)))
2605             dump_points_to_info_for (file, ptr);
2606         }
2607
2608         for (si = bsi_start (bb); !bsi_end_p (si); bsi_next (&si))
2609           {
2610             tree stmt = bsi_stmt (si);
2611             tree def;
2612             FOR_EACH_SSA_TREE_OPERAND (def, stmt, iter, SSA_OP_DEF)
2613               if (POINTER_TYPE_P (TREE_TYPE (def)))
2614                 dump_points_to_info_for (file, def);
2615           }
2616     }
2617
2618   fprintf (file, "\n");
2619 }
2620
2621
2622 /* Dump points-to info pointed by PTO into STDERR.  */
2623
2624 void
2625 debug_points_to_info (void)
2626 {
2627   dump_points_to_info (stderr);
2628 }
2629
2630 /* Dump to FILE the list of variables that may be aliasing VAR.  */
2631
2632 void
2633 dump_may_aliases_for (FILE *file, tree var)
2634 {
2635   varray_type aliases;
2636   
2637   if (TREE_CODE (var) == SSA_NAME)
2638     var = SSA_NAME_VAR (var);
2639
2640   aliases = var_ann (var)->may_aliases;
2641   if (aliases)
2642     {
2643       size_t i;
2644       fprintf (file, "{ ");
2645       for (i = 0; i < VARRAY_ACTIVE_SIZE (aliases); i++)
2646         {
2647           print_generic_expr (file, VARRAY_TREE (aliases, i), dump_flags);
2648           fprintf (file, " ");
2649         }
2650       fprintf (file, "}");
2651     }
2652 }
2653
2654
2655 /* Dump to stderr the list of variables that may be aliasing VAR.  */
2656
2657 void
2658 debug_may_aliases_for (tree var)
2659 {
2660   dump_may_aliases_for (stderr, var);
2661 }
2662
2663 /* Return true if VAR may be aliased.  */
2664
2665 bool
2666 may_be_aliased (tree var)
2667 {
2668   /* Obviously.  */
2669   if (TREE_ADDRESSABLE (var))
2670     return true;
2671
2672   /* Globally visible variables can have their addresses taken by other
2673      translation units.  */
2674   if (DECL_EXTERNAL (var) || TREE_PUBLIC (var))
2675     return true;
2676
2677   /* Automatic variables can't have their addresses escape any other way.
2678      This must be after the check for global variables, as extern declarations
2679      do not have TREE_STATIC set.  */
2680   if (!TREE_STATIC (var))
2681     return false;
2682
2683   /* If we're in unit-at-a-time mode, then we must have seen all occurrences
2684      of address-of operators, and so we can trust TREE_ADDRESSABLE.  Otherwise
2685      we can only be sure the variable isn't addressable if it's local to the
2686      current function.  */
2687   if (flag_unit_at_a_time)
2688     return false;
2689   if (decl_function_context (var) == current_function_decl)
2690     return false;
2691
2692   return true;
2693 }
2694
2695
2696 /* Add VAR to the list of may-aliases of PTR's type tag.  If PTR
2697    doesn't already have a type tag, create one.  */
2698
2699 void
2700 add_type_alias (tree ptr, tree var)
2701 {
2702   varray_type aliases;
2703   tree tag;
2704   var_ann_t ann = var_ann (ptr);
2705   subvar_t svars;
2706
2707   if (ann->type_mem_tag == NULL_TREE)
2708     {
2709       size_t i;
2710       tree q = NULL_TREE;
2711       tree tag_type = TREE_TYPE (TREE_TYPE (ptr));
2712       HOST_WIDE_INT tag_set = get_alias_set (tag_type);
2713
2714       /* PTR doesn't have a type tag, create a new one and add VAR to
2715          the new tag's alias set.
2716
2717          FIXME, This is slower than necessary.  We need to determine
2718          whether there is another pointer Q with the same alias set as
2719          PTR.  This could be sped up by having type tags associated
2720          with types.  */
2721       for (i = 0; i < num_referenced_vars; i++)
2722         {
2723           q = referenced_var (i);
2724
2725           if (POINTER_TYPE_P (TREE_TYPE (q))
2726               && tag_set == get_alias_set (TREE_TYPE (TREE_TYPE (q))))
2727             {
2728               /* Found another pointer Q with the same alias set as
2729                  the PTR's pointed-to type.  If Q has a type tag, use
2730                  it.  Otherwise, create a new memory tag for PTR.  */
2731               var_ann_t ann1 = var_ann (q);
2732               if (ann1->type_mem_tag)
2733                 ann->type_mem_tag = ann1->type_mem_tag;
2734               else
2735                 ann->type_mem_tag = create_memory_tag (tag_type, true);
2736               goto found_tag;
2737             }
2738         }
2739
2740       /* Couldn't find any other pointer with a type tag we could use.
2741          Create a new memory tag for PTR.  */
2742       ann->type_mem_tag = create_memory_tag (tag_type, true);
2743     }
2744
2745 found_tag:
2746   /* If VAR is not already PTR's type tag, add it to the may-alias set
2747      for PTR's type tag.  */
2748   gcc_assert (var_ann (var)->type_mem_tag == NOT_A_TAG);
2749   tag = ann->type_mem_tag;
2750
2751   /* If VAR has subvars, add the subvars to the tag instead of the
2752      actual var.  */
2753   if (var_can_have_subvars (var)
2754       && (svars = get_subvars_for_var (var)))
2755     {
2756       subvar_t sv;      
2757       for (sv = svars; sv; sv = sv->next)
2758         add_may_alias (tag, sv->var);
2759     }
2760   else
2761     add_may_alias (tag, var);
2762
2763   /* TAG and its set of aliases need to be marked for renaming.  */
2764   mark_sym_for_renaming (tag);
2765   if ((aliases = var_ann (tag)->may_aliases) != NULL)
2766     {
2767       size_t i;
2768       for (i = 0; i < VARRAY_ACTIVE_SIZE (aliases); i++)
2769         mark_sym_for_renaming (VARRAY_TREE (aliases, i));
2770     }
2771
2772   /* If we had grouped aliases, VAR may have aliases of its own.  Mark
2773      them for renaming as well.  Other statements referencing the
2774      aliases of VAR will need to be updated.  */
2775   if ((aliases = var_ann (var)->may_aliases) != NULL)
2776     {
2777       size_t i;
2778       for (i = 0; i < VARRAY_ACTIVE_SIZE (aliases); i++)
2779         mark_sym_for_renaming (VARRAY_TREE (aliases, i));
2780     }
2781 }
2782
2783
2784 /* This structure is simply used during pushing fields onto the fieldstack
2785    to track the offset of the field, since bitpos_of_field gives it relative
2786    to its immediate containing type, and we want it relative to the ultimate
2787    containing object.  */
2788
2789 typedef struct fieldoff
2790 {
2791   tree field;
2792   HOST_WIDE_INT offset;  
2793 } *fieldoff_t;
2794
2795 DEF_VEC_MALLOC_P(fieldoff_t);
2796
2797 /* Return the position, in bits, of FIELD_DECL from the beginning of its
2798    structure. 
2799    Return -1 if the position is conditional or otherwise non-constant
2800    integer.  */
2801
2802 static HOST_WIDE_INT
2803 bitpos_of_field (const tree fdecl)
2804 {
2805
2806   if (TREE_CODE (DECL_FIELD_OFFSET (fdecl)) != INTEGER_CST
2807       || TREE_CODE (DECL_FIELD_BIT_OFFSET (fdecl)) != INTEGER_CST)
2808     return -1;
2809
2810   return (tree_low_cst (DECL_FIELD_OFFSET (fdecl), 1) * 8) 
2811     + tree_low_cst (DECL_FIELD_BIT_OFFSET (fdecl), 1);
2812 }
2813
2814 /* Given a TYPE, and a vector of field offsets FIELDSTACK, push all the fields
2815    of TYPE onto fieldstack, recording their offsets along the way.
2816    OFFSET is used to keep track of the offset in this entire structure, rather
2817    than just the immediately containing structure.  */
2818
2819 static void
2820 push_fields_onto_fieldstack (tree type, VEC(fieldoff_t) **fieldstack, 
2821                              HOST_WIDE_INT offset)
2822 {
2823   fieldoff_t pair;
2824   tree field = TYPE_FIELDS (type);
2825   if (!field)
2826     return;
2827   if (var_can_have_subvars (field)
2828       && TREE_CODE (field) == FIELD_DECL)
2829     {
2830       size_t before = VEC_length (fieldoff_t, *fieldstack);
2831       /* Empty structures may have actual size, like in C++. So see if we
2832          actually end up pushing a field, and if not, if the size is nonzero,
2833          push the field onto the stack */
2834       push_fields_onto_fieldstack (TREE_TYPE (field), fieldstack, offset);
2835       if (before == VEC_length (fieldoff_t, *fieldstack)
2836           && DECL_SIZE (field)
2837           && !integer_zerop (DECL_SIZE (field)))
2838         {
2839           pair = xmalloc (sizeof (struct fieldoff));
2840           pair->field = field;
2841           pair->offset = offset;
2842           VEC_safe_push (fieldoff_t, *fieldstack, pair);
2843         }
2844     }
2845   else if (TREE_CODE (field) == FIELD_DECL)
2846     {
2847       pair = xmalloc (sizeof (struct fieldoff));
2848       pair->field = field;
2849       pair->offset = offset + bitpos_of_field (field);
2850       VEC_safe_push (fieldoff_t, *fieldstack, pair);
2851     }
2852   for (field = TREE_CHAIN (field); field; field = TREE_CHAIN (field))
2853     {
2854       if (TREE_CODE (field) != FIELD_DECL)
2855         continue;
2856       if (var_can_have_subvars (field))
2857         {
2858           size_t before = VEC_length (fieldoff_t, *fieldstack);
2859           push_fields_onto_fieldstack (TREE_TYPE (field), fieldstack, 
2860                                        offset + bitpos_of_field (field));
2861       /* Empty structures may have actual size, like in C++. So see if we
2862          actually end up pushing a field, and if not, if the size is nonzero,
2863          push the field onto the stack */
2864           if (before == VEC_length (fieldoff_t, *fieldstack)
2865               && DECL_SIZE (field)
2866               && !integer_zerop (DECL_SIZE (field)))
2867             {
2868               pair = xmalloc (sizeof (struct fieldoff));
2869               pair->field = field;
2870               pair->offset = offset + bitpos_of_field (field);
2871               VEC_safe_push (fieldoff_t, *fieldstack, pair);
2872             }
2873         }
2874       else
2875         {
2876           pair = xmalloc (sizeof (struct fieldoff));
2877           pair->field = field;
2878           pair->offset = offset + bitpos_of_field (field);
2879           VEC_safe_push (fieldoff_t, *fieldstack, pair);
2880         }
2881     }
2882 }
2883
2884
2885 /* This represents the used range of a variable.  */
2886
2887 typedef struct used_part
2888 {
2889   HOST_WIDE_INT minused;
2890   HOST_WIDE_INT maxused;
2891   /* True if we have an explicit use/def of some portion of this variable,
2892      even if it is all of it. i.e. a.b = 5 or temp = a.b.  */
2893   bool explicit_uses;
2894   /* True if we have an implicit use/def of some portion of this
2895      variable.  Implicit uses occur when we can't tell what part we
2896      are referencing, and have to make conservative assumptions.  */
2897   bool implicit_uses;
2898 } *used_part_t;
2899
2900 /* An array of used_part structures, indexed by variable uid.  */
2901
2902 static used_part_t *used_portions;
2903
2904 /* Given a variable uid, UID, get or create the entry in the used portions
2905    table for the variable.  */
2906
2907 static used_part_t
2908 get_or_create_used_part_for (size_t uid)
2909 {
2910   used_part_t up;
2911   if (used_portions[uid] == NULL)
2912     {
2913       up = xcalloc (1, sizeof (struct used_part));
2914       up->minused = INT_MAX;
2915       up->maxused = 0;
2916       up->explicit_uses = false;
2917       up->implicit_uses = false;
2918     }
2919   else
2920     up = used_portions[uid];
2921   return up;
2922 }
2923
2924 /* qsort comparison function for two fieldoff_t's PA and PB */
2925
2926 static int 
2927 fieldoff_compare (const void *pa, const void *pb)
2928 {
2929   const fieldoff_t foa = *(fieldoff_t *)pa;
2930   const fieldoff_t fob = *(fieldoff_t *)pb;
2931   HOST_WIDE_INT foasize, fobsize;
2932   if (foa->offset != fob->offset)
2933     return foa->offset - fob->offset;
2934
2935   foasize = TREE_INT_CST_LOW (DECL_SIZE (foa->field));
2936   fobsize = TREE_INT_CST_LOW (DECL_SIZE (fob->field));
2937   if (foasize != fobsize)
2938     return foasize - fobsize;
2939   return 0;
2940 }
2941
2942 /* Given an aggregate VAR, create the subvariables that represent its
2943    fields.  */
2944
2945 static void
2946 create_overlap_variables_for (tree var)
2947 {
2948   VEC(fieldoff_t) *fieldstack = NULL;
2949   used_part_t up;
2950   size_t uid = var_ann (var)->uid;
2951
2952   if (used_portions[uid] == NULL)
2953     return;
2954
2955   up = used_portions[uid];
2956   push_fields_onto_fieldstack (TREE_TYPE (var), &fieldstack, 0);
2957   if (VEC_length (fieldoff_t, fieldstack) != 0)
2958     {
2959       subvar_t *subvars;
2960       fieldoff_t fo;
2961       bool notokay = false;
2962       int fieldcount = 0;
2963       int i;
2964       HOST_WIDE_INT lastfooffset = -1;
2965       HOST_WIDE_INT lastfosize = -1;
2966       tree lastfotype = NULL_TREE;
2967
2968       /* Not all fields have DECL_SIZE set, and those that don't, we don't
2969          know their size, and thus, can't handle.
2970          The same is true of fields with DECL_SIZE that is not an integer
2971          constant (such as variable sized fields).
2972          Fields with offsets which are not constant will have an offset < 0 
2973          We *could* handle fields that are constant sized arrays, but
2974          currently don't.  Doing so would require some extra changes to
2975          tree-ssa-operands.c.  */
2976
2977       for (i = 0; VEC_iterate (fieldoff_t, fieldstack, i, fo); i++)
2978         {
2979           if (!DECL_SIZE (fo->field) 
2980               || TREE_CODE (DECL_SIZE (fo->field)) != INTEGER_CST
2981               || TREE_CODE (TREE_TYPE (fo->field)) == ARRAY_TYPE
2982               || fo->offset < 0)
2983             {
2984               notokay = true;
2985               break;
2986             }
2987           fieldcount++;
2988         }
2989
2990       /* The current heuristic we use is as follows:
2991          If the variable has no used portions in this function, no
2992          structure vars are created for it.
2993          Otherwise,
2994          If the variable has less than SALIAS_MAX_IMPLICIT_FIELDS,
2995          we always create structure vars for them.
2996          If the variable has more than SALIAS_MAX_IMPLICIT_FIELDS, and
2997          some explicit uses, we create structure vars for them.
2998          If the variable has more than SALIAS_MAX_IMPLICIT_FIELDS, and
2999          no explicit uses, we do not create structure vars for them.
3000       */
3001       
3002       if (fieldcount >= SALIAS_MAX_IMPLICIT_FIELDS
3003           && !up->explicit_uses)
3004         {
3005           if (dump_file && (dump_flags & TDF_DETAILS))
3006             {
3007               fprintf (dump_file, "Variable ");
3008               print_generic_expr (dump_file, var, 0);
3009               fprintf (dump_file, " has no explicit uses in this function, and is > SALIAS_MAX_IMPLICIT_FIELDS, so skipping\n");
3010             }
3011           notokay = true;
3012         }
3013       
3014     
3015       /* Cleanup after ourselves if we can't create overlap variables.  */
3016       if (notokay)
3017         {
3018           while (VEC_length (fieldoff_t, fieldstack) != 0)
3019             {
3020               fo = VEC_pop (fieldoff_t, fieldstack);
3021               free (fo);
3022             }
3023           VEC_free (fieldoff_t, fieldstack);
3024           return;
3025         }
3026       /* Otherwise, create the variables.  */
3027       subvars = lookup_subvars_for_var (var);
3028       
3029       qsort (VEC_address (fieldoff_t, fieldstack), 
3030              VEC_length (fieldoff_t, fieldstack), 
3031              sizeof (fieldoff_t),
3032              fieldoff_compare);
3033
3034       while (VEC_length (fieldoff_t, fieldstack) != 0)
3035         {
3036           subvar_t sv;
3037           HOST_WIDE_INT fosize;
3038           var_ann_t ann;
3039           tree currfotype;
3040
3041           fo = VEC_pop (fieldoff_t, fieldstack);          
3042           fosize = TREE_INT_CST_LOW (DECL_SIZE (fo->field));
3043           currfotype = TREE_TYPE (fo->field);
3044
3045           /* If this field isn't in the used portion,
3046              or it has the exact same offset and size as the last
3047              field, skip it.  */
3048
3049           if (((fo->offset <= up->minused
3050                 && fo->offset + fosize <= up->minused)
3051                || fo->offset >= up->maxused)
3052               || (fo->offset == lastfooffset
3053                   && fosize == lastfosize
3054                   && currfotype == lastfotype))
3055             {
3056               free (fo);
3057               continue;
3058             }
3059           sv = ggc_alloc (sizeof (struct subvar));
3060           sv->offset = fo->offset;
3061           sv->size = fosize;
3062           sv->next = *subvars;
3063           sv->var = create_tmp_var_raw (TREE_TYPE (fo->field), "SFT");
3064           if (dump_file)
3065             {
3066               fprintf (dump_file, "structure field tag %s created for var %s",
3067                        get_name (sv->var), get_name (var));
3068               fprintf (dump_file, " offset " HOST_WIDE_INT_PRINT_DEC,
3069                        sv->offset);
3070               fprintf (dump_file, " size " HOST_WIDE_INT_PRINT_DEC,
3071                        sv->size);
3072               fprintf (dump_file, "\n");
3073               
3074             }
3075           
3076           /* We need to copy the various flags from var to sv->var, so that
3077              they are is_global_var iff the original variable was.  */
3078
3079           DECL_EXTERNAL (sv->var) = DECL_EXTERNAL (var);
3080           TREE_PUBLIC  (sv->var) = TREE_PUBLIC (var);
3081           TREE_STATIC (sv->var) = TREE_STATIC (var);
3082           TREE_READONLY (sv->var) = TREE_READONLY (var);
3083
3084           /* Like other memory tags, these need to be marked addressable to
3085              keep is_gimple_reg from thinking they are real.  */
3086           TREE_ADDRESSABLE (sv->var) = 1;
3087
3088           DECL_CONTEXT (sv->var) = DECL_CONTEXT (var);
3089
3090           ann = get_var_ann (sv->var);
3091           ann->mem_tag_kind = STRUCT_FIELD; 
3092           ann->type_mem_tag = NULL;     
3093           add_referenced_tmp_var (sv->var);
3094           
3095           lastfotype = currfotype;
3096           lastfooffset = fo->offset;
3097           lastfosize = fosize;
3098           *subvars = sv;
3099           free (fo);
3100         }
3101
3102       /* Once we have created subvars, the original is no longer call
3103          clobbered on its own.  Its call clobbered status depends
3104          completely on the call clobbered status of the subvars.
3105
3106          add_referenced_var in the above loop will take care of
3107          marking subvars of global variables as call clobbered for us
3108          to start, since they are global as well.  */
3109       clear_call_clobbered (var);
3110
3111     }
3112
3113   VEC_free (fieldoff_t, fieldstack);
3114 }
3115
3116
3117 /* Find the conservative answer to the question of what portions of what 
3118    structures are used by this statement.  We assume that if we have a
3119    component ref with a known size + offset, that we only need that part
3120    of the structure.  For unknown cases, or cases where we do something
3121    to the whole structure, we assume we need to create fields for the 
3122    entire structure.  */
3123
3124 static tree
3125 find_used_portions (tree *tp, int *walk_subtrees, void *data ATTRIBUTE_UNUSED)
3126 {
3127   switch (TREE_CODE (*tp))
3128     {
3129     case COMPONENT_REF:
3130       {
3131         HOST_WIDE_INT bitsize;
3132         HOST_WIDE_INT bitpos;
3133         tree offset;
3134         enum machine_mode mode;
3135         int unsignedp;
3136         int volatilep;  
3137         tree ref;
3138         ref = get_inner_reference (*tp, &bitsize, &bitpos, &offset, &mode,
3139                                    &unsignedp, &volatilep, false);
3140         if (DECL_P (ref) && offset == NULL && bitsize != -1)
3141           {         
3142             size_t uid = var_ann (ref)->uid;
3143             used_part_t up;
3144
3145             up = get_or_create_used_part_for (uid);         
3146
3147             if (bitpos <= up->minused)
3148               up->minused = bitpos;
3149             if ((bitpos + bitsize >= up->maxused))
3150               up->maxused = bitpos + bitsize;       
3151
3152             up->explicit_uses = true;
3153             used_portions[uid] = up;
3154
3155             *walk_subtrees = 0;
3156             return NULL_TREE;
3157           }
3158         else if (DECL_P (ref))
3159           {
3160             if (DECL_SIZE (ref)
3161                 && var_can_have_subvars (ref)
3162                 && TREE_CODE (DECL_SIZE (ref)) == INTEGER_CST)
3163               {
3164                 used_part_t up;
3165                 size_t uid = var_ann (ref)->uid;
3166
3167                 up = get_or_create_used_part_for (uid);
3168
3169                 up->minused = 0;
3170                 up->maxused = TREE_INT_CST_LOW (DECL_SIZE (ref));
3171
3172                 up->implicit_uses = true;
3173
3174                 used_portions[uid] = up;
3175
3176                 *walk_subtrees = 0;
3177                 return NULL_TREE;
3178               }
3179           }
3180       }
3181       break;
3182     case VAR_DECL:
3183     case PARM_DECL:
3184       {
3185         tree var = *tp;
3186         if (DECL_SIZE (var)
3187             && var_can_have_subvars (var)
3188             && TREE_CODE (DECL_SIZE (var)) == INTEGER_CST)
3189           {
3190             used_part_t up;
3191             size_t uid = var_ann (var)->uid;        
3192             
3193             up = get_or_create_used_part_for (uid);
3194  
3195             up->minused = 0;
3196             up->maxused = TREE_INT_CST_LOW (DECL_SIZE (var));
3197             up->implicit_uses = true;
3198
3199             used_portions[uid] = up;
3200             *walk_subtrees = 0;
3201             return NULL_TREE;
3202           }
3203       }
3204       break;
3205       
3206     default:
3207       break;
3208       
3209     }
3210   return NULL_TREE;
3211 }
3212
3213 /* We are about to create some new referenced variables, and we need the
3214    before size.  */
3215
3216 static size_t old_referenced_vars;
3217
3218
3219 /* Create structure field variables for structures used in this function.  */
3220
3221 static void
3222 create_structure_vars (void)
3223 {
3224   basic_block bb;
3225   size_t i;
3226
3227   old_referenced_vars = num_referenced_vars;
3228   used_portions = xcalloc (num_referenced_vars, sizeof (used_part_t));
3229   
3230   FOR_EACH_BB (bb)
3231     {
3232       block_stmt_iterator bsi;
3233       for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
3234         {
3235           walk_tree_without_duplicates (bsi_stmt_ptr (bsi), 
3236                                         find_used_portions,
3237                                         NULL);
3238         }
3239     }
3240   for (i = 0; i < old_referenced_vars; i++)
3241     {
3242       tree var = referenced_var (i);
3243       /* The C++ FE creates vars without DECL_SIZE set, for some reason.  */
3244       if (var     
3245           && DECL_SIZE (var)
3246           && var_can_have_subvars (var)
3247           && var_ann (var)->mem_tag_kind == NOT_A_TAG
3248           && TREE_CODE (DECL_SIZE (var)) == INTEGER_CST)
3249         create_overlap_variables_for (var);
3250     }
3251   for (i = 0; i < old_referenced_vars; i++)
3252     free (used_portions[i]);
3253
3254   free (used_portions);
3255 }
3256
3257 static bool
3258 gate_structure_vars (void)
3259 {
3260   return flag_tree_salias != 0;
3261 }
3262
3263 struct tree_opt_pass pass_create_structure_vars = 
3264 {
3265   "salias",              /* name */
3266   gate_structure_vars,   /* gate */
3267   create_structure_vars, /* execute */
3268   NULL,                  /* sub */
3269   NULL,                  /* next */
3270   0,                     /* static_pass_number */
3271   0,                     /* tv_id */
3272   PROP_cfg,              /* properties_required */
3273   0,                     /* properties_provided */
3274   0,                     /* properties_destroyed */
3275   0,                     /* todo_flags_start */
3276   TODO_dump_func,        /* todo_flags_finish */
3277   0                      /* letter */
3278 };