OSDN Git Service

* tree-def (WITH_SIZE_EXPR): New.
[pf3gnuchains/gcc-fork.git] / gcc / tree-ssa-operands.c
1 /* SSA operands management for trees.
2    Copyright (C) 2003 Free Software Foundation, Inc.
3
4 This file is part of GCC.
5
6 GCC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GCC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING.  If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.  */
20
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "tm.h"
25 #include "tree.h"
26 #include "flags.h"
27 #include "function.h"
28 #include "diagnostic.h"
29 #include "tree-flow.h"
30 #include "tree-inline.h"
31 #include "tree-pass.h"
32 #include "ggc.h"
33 #include "timevar.h"
34
35 /* Flags to describe operand properties in get_stmt_operands and helpers.  */
36
37 /* By default, operands are loaded.  */
38 #define opf_none        0
39
40 /* Operand is the target of an assignment expression or a 
41    call-clobbered variable  */
42 #define opf_is_def      (1 << 0)
43
44 /* Operand is the target of an assignment expression.  */
45 #define opf_kill_def    (1 << 2)
46
47 /* No virtual operands should be created in the expression.  This is used
48    when traversing ADDR_EXPR nodes which have different semantics than
49    other expressions.  Inside an ADDR_EXPR node, the only operands that we
50    need to consider are indices into arrays.  For instance, &a.b[i] should
51    generate a USE of 'i' but it should not generate a VUSE for 'a' nor a
52    VUSE for 'b'.  */
53 #define opf_no_vops     (1 << 1)
54
55 /* Array for building all the def operands.  */
56 static GTY (()) varray_type build_defs;
57
58 /* Array for building all the use operands.  */
59 static GTY (()) varray_type build_uses;
60
61 /* Array for building all the v_may_def operands.  */
62 static GTY (()) varray_type build_v_may_defs;
63
64 /* Array for building all the vuse operands.  */
65 static GTY (()) varray_type build_vuses;
66
67 /* Array for building all the v_must_def operands.  */
68 static GTY (()) varray_type build_v_must_defs;
69
70 #ifdef ENABLE_CHECKING
71 tree check_build_stmt;
72 #endif
73
74 typedef struct voperands_d 
75 {
76   v_may_def_optype v_may_def_ops;
77   vuse_optype vuse_ops;
78   v_must_def_optype v_must_def_ops;
79 } *voperands_t;
80
81 static void note_addressable (tree, stmt_ann_t);
82 static void get_expr_operands (tree, tree *, int, voperands_t);
83 static void get_asm_expr_operands (tree, voperands_t);
84 static void get_indirect_ref_operands (tree, tree, int, voperands_t);
85 static void get_call_expr_operands (tree, tree, voperands_t);
86 static inline void append_def (tree *, tree);
87 static inline void append_use (tree *, tree);
88 static void append_v_may_def (tree, tree, voperands_t);
89 static void append_v_must_def (tree, tree, voperands_t);
90 static void add_call_clobber_ops (tree, voperands_t);
91 static void add_call_read_ops (tree, voperands_t);
92 static void add_stmt_operand (tree *, tree, int, voperands_t);
93
94 /* Return a vector of contiguous memory of a specified size.  */
95
96 static inline def_optype
97 allocate_def_optype (unsigned num)
98 {
99   def_optype def_ops;
100   unsigned size;
101   size = sizeof (struct def_optype_d) + sizeof (tree *) * (num - 1);
102   def_ops =  ggc_alloc (size);
103   def_ops->num_defs = num;
104   return def_ops;
105 }
106
107 static inline use_optype
108 allocate_use_optype (unsigned num)
109 {
110   use_optype use_ops;
111   unsigned size;
112   size = sizeof (struct use_optype_d) + sizeof (tree *) * (num - 1);
113   use_ops =  ggc_alloc (size);
114   use_ops->num_uses = num;
115   return use_ops;
116 }
117
118 static inline v_may_def_optype
119 allocate_v_may_def_optype (unsigned num)
120 {
121   v_may_def_optype v_may_def_ops;
122   unsigned size;
123   size = sizeof (struct v_may_def_optype_d) + sizeof (tree) * ((num * 2) - 1);
124   v_may_def_ops =  ggc_alloc (size);
125   v_may_def_ops->num_v_may_defs = num;
126   return v_may_def_ops;
127 }
128
129 static inline vuse_optype
130 allocate_vuse_optype (unsigned num)
131 {
132   vuse_optype vuse_ops;
133   unsigned size;
134   size = sizeof (struct vuse_optype_d) + sizeof (tree) * (num - 1);
135   vuse_ops =  ggc_alloc (size);
136   vuse_ops->num_vuses = num;
137   return vuse_ops;
138 }
139
140 static inline v_must_def_optype
141 allocate_v_must_def_optype (unsigned num)
142 {
143   v_must_def_optype v_must_def_ops;
144   unsigned size;
145   size = sizeof (struct v_must_def_optype_d) + sizeof (tree *) * (num - 1);
146   v_must_def_ops =  ggc_alloc (size);
147   v_must_def_ops->num_v_must_defs = num;
148   return v_must_def_ops;
149 }
150
151 static inline void
152 free_uses (use_optype *uses, bool dealloc)
153 {
154   if (*uses)
155     {
156       if (dealloc)
157         ggc_free (*uses);
158       *uses = NULL;
159     }
160 }
161
162 static inline void
163 free_defs (def_optype *defs, bool dealloc)
164 {
165   if (*defs)
166     {
167       if (dealloc)
168         ggc_free (*defs);
169       *defs = NULL;
170     }
171 }
172
173 static inline void
174 free_vuses (vuse_optype *vuses, bool dealloc)
175 {
176   if (*vuses)
177     {
178       if (dealloc)
179         ggc_free (*vuses);
180       *vuses = NULL;
181     }
182 }
183
184 static inline void
185 free_v_may_defs (v_may_def_optype *v_may_defs, bool dealloc)
186 {
187   if (*v_may_defs)
188     {
189       if (dealloc)
190         ggc_free (*v_may_defs);
191       *v_may_defs = NULL;
192     }
193 }
194
195 static inline void
196 free_v_must_defs (v_must_def_optype *v_must_defs, bool dealloc)
197 {
198   if (*v_must_defs)
199     {
200       if (dealloc)
201         ggc_free (*v_must_defs);
202       *v_must_defs = NULL;
203     }
204 }
205
206 void
207 remove_vuses (tree stmt)
208 {
209   stmt_ann_t ann;
210
211   ann = stmt_ann (stmt);
212   if (ann)
213     free_vuses (&(ann->vuse_ops), true);
214 }
215
216 void
217 remove_v_may_defs (tree stmt)
218 {
219   stmt_ann_t ann;
220
221   ann = stmt_ann (stmt);
222   if (ann)
223     free_v_may_defs (&(ann->v_may_def_ops), true);
224 }
225
226 void
227 remove_v_must_defs (tree stmt)
228 {
229   stmt_ann_t ann;
230
231   ann = stmt_ann (stmt);
232   if (ann)
233     free_v_must_defs (&(ann->v_must_def_ops), true);
234 }
235
236 void
237 init_ssa_operands (void)
238 {
239   VARRAY_TREE_PTR_INIT (build_defs, 5, "build defs");
240   VARRAY_TREE_PTR_INIT (build_uses, 10, "build uses");
241   VARRAY_TREE_INIT (build_v_may_defs, 10, "build v_may_defs");
242   VARRAY_TREE_INIT (build_vuses, 10, "build vuses");
243   VARRAY_TREE_INIT (build_v_must_defs, 10, "build v_must_defs");
244 }
245
246 void
247 fini_ssa_operands (void)
248 {
249 }
250
251 static void
252 finalize_ssa_defs (tree stmt)
253 {
254   unsigned num, x;
255   stmt_ann_t ann;
256   def_optype def_ops;
257
258   num = VARRAY_ACTIVE_SIZE (build_defs);
259   if (num == 0)
260     return;
261
262 #ifdef ENABLE_CHECKING
263   /* There should only be a single real definition per assignment.  */
264   if (TREE_CODE (stmt) == MODIFY_EXPR && num > 1)
265     abort ();
266 #endif
267
268   def_ops = allocate_def_optype (num);
269   for (x = 0; x < num ; x++)
270     def_ops->defs[x].def = VARRAY_TREE_PTR (build_defs, x);
271   VARRAY_POP_ALL (build_defs);
272
273   ann = stmt_ann (stmt);
274   ann->def_ops = def_ops;
275 }
276
277 static void
278 finalize_ssa_uses (tree stmt)
279 {
280   unsigned num, x;
281   use_optype use_ops;
282   stmt_ann_t ann;
283
284   num = VARRAY_ACTIVE_SIZE (build_uses);
285   if (num == 0)
286     return;
287
288 #ifdef ENABLE_CHECKING
289   {
290     unsigned x;
291     /* If the pointer to the operand is the statement itself, something is
292        wrong.  It means that we are pointing to a local variable (the 
293        initial call to get_stmt_operands does not pass a pointer to a 
294        statement).  */
295     for (x = 0; x < num; x++)
296       if (*(VARRAY_TREE_PTR (build_uses, x)) == stmt)
297         abort ();
298   }
299 #endif
300
301   use_ops = allocate_use_optype (num);
302   for (x = 0; x < num ; x++)
303     use_ops->uses[x].use = VARRAY_TREE_PTR (build_uses, x);
304   VARRAY_POP_ALL (build_uses);
305
306   ann = stmt_ann (stmt);
307   ann->use_ops = use_ops;
308 }
309
310 static void
311 finalize_ssa_v_may_defs (tree stmt)
312 {
313   unsigned num, x;
314   v_may_def_optype v_may_def_ops;
315   stmt_ann_t ann;
316
317   num = VARRAY_ACTIVE_SIZE (build_v_may_defs);
318   if (num == 0)
319     return;
320
321 #ifdef ENABLE_CHECKING
322   /* V_MAY_DEFs must be entered in pairs of result/uses.  */
323   if (num % 2 != 0)
324     abort();
325 #endif
326
327   v_may_def_ops = allocate_v_may_def_optype (num / 2);
328   for (x = 0; x < num; x++)
329     v_may_def_ops->v_may_defs[x] = VARRAY_TREE (build_v_may_defs, x);
330   VARRAY_CLEAR (build_v_may_defs);
331
332   ann = stmt_ann (stmt);
333   ann->v_may_def_ops = v_may_def_ops;
334 }
335
336 static inline void
337 finalize_ssa_vuses (tree stmt)
338 {
339   unsigned num, x;
340   stmt_ann_t ann;
341   vuse_optype vuse_ops;
342   v_may_def_optype v_may_defs;
343
344 #ifdef ENABLE_CHECKING
345   if (VARRAY_ACTIVE_SIZE (build_v_may_defs) > 0)
346     {
347       fprintf (stderr, "Please finalize V_MAY_DEFs before finalize VUSES.\n");
348       abort ();
349     }
350 #endif
351
352   num = VARRAY_ACTIVE_SIZE (build_vuses);
353   if (num == 0)
354     return;
355
356   /* Remove superfluous VUSE operands.  If the statement already has a
357    V_MAY_DEF operation for a variable 'a', then a VUSE for 'a' is not
358    needed because V_MAY_DEFs imply a VUSE of the variable.  For instance,
359    suppose that variable 'a' is aliased:
360
361               # VUSE <a_2>
362               # a_3 = V_MAY_DEF <a_2>
363               a = a + 1;
364
365   The VUSE <a_2> is superfluous because it is implied by the V_MAY_DEF
366   operation.  */
367
368   ann = stmt_ann (stmt);
369   v_may_defs = V_MAY_DEF_OPS (ann);
370   if (NUM_V_MAY_DEFS (v_may_defs) > 0)
371     {
372       size_t i, j;
373       for (i = 0; i < VARRAY_ACTIVE_SIZE (build_vuses); i++)
374         {
375           bool found = false;
376           for (j = 0; j < NUM_V_MAY_DEFS (v_may_defs); j++)
377             {
378               tree vuse_var, v_may_def_var;
379               tree vuse = VARRAY_TREE (build_vuses, i);
380               tree v_may_def = V_MAY_DEF_OP (v_may_defs, j);
381
382               if (TREE_CODE (vuse) == SSA_NAME)
383                 vuse_var = SSA_NAME_VAR (vuse);
384               else
385                 vuse_var = vuse;
386
387               if (TREE_CODE (v_may_def) == SSA_NAME)
388                 v_may_def_var = SSA_NAME_VAR (v_may_def);
389               else
390                 v_may_def_var = v_may_def;
391
392             if (vuse_var == v_may_def_var)
393               {
394                 found = true;
395                 break;
396               }
397             }
398
399           /* If we found a useless VUSE operand, remove it from the
400              operand array by replacing it with the last active element
401              in the operand array (unless the useless VUSE was the
402              last operand, in which case we simply remove it.  */
403           if (found)
404             {
405               if (i != VARRAY_ACTIVE_SIZE (build_vuses) - 1)
406                 {
407                   VARRAY_TREE (build_vuses, i)
408                     = VARRAY_TREE (build_vuses,
409                                    VARRAY_ACTIVE_SIZE (build_vuses) - 1);
410                 }
411               VARRAY_POP (build_vuses);
412
413               /* We want to rescan the element at this index, unless
414                  this was the last element, in which case the loop
415                  terminates.  */
416               i--;
417             }
418         }
419     }
420
421   num = VARRAY_ACTIVE_SIZE (build_vuses);
422   /* We could have reduced the size to zero now, however.  */
423   if (num == 0)
424     return;
425
426   vuse_ops = allocate_vuse_optype (num);
427   for (x = 0; x < num; x++)
428     vuse_ops->vuses[x] = VARRAY_TREE (build_vuses, x);
429   VARRAY_CLEAR (build_vuses);
430   ann->vuse_ops = vuse_ops;
431 }
432
433 static void
434 finalize_ssa_v_must_defs (tree stmt)
435 {
436   unsigned num, x;
437   stmt_ann_t ann;
438   v_must_def_optype v_must_def_ops;
439
440   num = VARRAY_ACTIVE_SIZE (build_v_must_defs);
441   if (num == 0)
442     return;
443
444 #ifdef ENABLE_CHECKING
445   /* There should only be a single V_MUST_DEF per assignment.  */
446   if (TREE_CODE (stmt) == MODIFY_EXPR && num > 1)
447     abort ();
448 #endif
449
450   v_must_def_ops = allocate_v_must_def_optype (num);
451   for (x = 0; x < num ; x++)
452     v_must_def_ops->v_must_defs[x] = VARRAY_TREE (build_v_must_defs, x);
453   VARRAY_POP_ALL (build_v_must_defs);
454
455   ann = stmt_ann (stmt);
456   ann->v_must_def_ops = v_must_def_ops;
457 }
458
459 extern void
460 finalize_ssa_stmt_operands (tree stmt)
461 {
462 #ifdef ENABLE_CHECKING
463   if (check_build_stmt == NULL)
464     abort();
465 #endif
466
467   finalize_ssa_defs (stmt);
468   finalize_ssa_uses (stmt);
469   finalize_ssa_v_must_defs (stmt);
470   finalize_ssa_v_may_defs (stmt);
471   finalize_ssa_vuses (stmt);
472
473 #ifdef ENABLE_CHECKING
474   check_build_stmt = NULL;
475 #endif
476 }
477
478
479 extern void
480 verify_start_operands (tree stmt ATTRIBUTE_UNUSED)
481 {
482 #ifdef ENABLE_CHECKING
483   if (VARRAY_ACTIVE_SIZE (build_defs) > 0 
484       || VARRAY_ACTIVE_SIZE (build_uses) > 0
485       || VARRAY_ACTIVE_SIZE (build_vuses) > 0
486       || VARRAY_ACTIVE_SIZE (build_v_may_defs) > 0
487       || VARRAY_ACTIVE_SIZE (build_v_must_defs) > 0)
488     abort ();
489   if (check_build_stmt != NULL)
490     abort();
491   check_build_stmt = stmt;
492 #endif
493 }
494
495
496 /* Add DEF_P to the list of pointers to operands defined by STMT.  */
497
498 static inline void
499 append_def (tree *def_p, tree stmt ATTRIBUTE_UNUSED)
500 {
501 #ifdef ENABLE_CHECKING
502   if (check_build_stmt != stmt)
503     abort();
504 #endif
505   VARRAY_PUSH_TREE_PTR (build_defs, def_p);
506 }
507
508
509 /* Add USE_P to the list of pointers to operands used by STMT.  */
510
511 static inline void
512 append_use (tree *use_p, tree stmt ATTRIBUTE_UNUSED)
513 {
514 #ifdef ENABLE_CHECKING
515   if (check_build_stmt != stmt)
516     abort();
517 #endif
518   VARRAY_PUSH_TREE_PTR (build_uses, use_p);
519 }
520
521
522 /* Add a new virtual def for variable VAR to statement STMT.  If PREV_VOPS
523    is not NULL, the existing entries are preserved and no new entries are
524    added here.  This is done to preserve the SSA numbering of virtual
525    operands.  */
526
527 static void
528 append_v_may_def (tree var, tree stmt, voperands_t prev_vops)
529 {
530   stmt_ann_t ann;
531   size_t i;
532   tree result, source;
533
534 #ifdef ENABLE_CHECKING
535   if (check_build_stmt != stmt)
536     abort();
537 #endif
538
539   ann = stmt_ann (stmt);
540
541   /* Don't allow duplicate entries.  */
542
543   for (i = 0; i < VARRAY_ACTIVE_SIZE (build_v_may_defs); i += 2)
544     {
545       tree result = VARRAY_TREE (build_v_may_defs, i);
546       if (var == result
547           || (TREE_CODE (result) == SSA_NAME
548               && var == SSA_NAME_VAR (result)))
549         return;
550     }
551
552   /* If the statement already had virtual definitions, see if any of the
553      existing V_MAY_DEFs matches VAR.  If so, re-use it, otherwise add a new
554      V_MAY_DEF for VAR.  */
555   result = NULL_TREE;
556   source = NULL_TREE;
557   if (prev_vops)
558     for (i = 0; i < NUM_V_MAY_DEFS (prev_vops->v_may_def_ops); i++)
559       {
560         result = V_MAY_DEF_RESULT (prev_vops->v_may_def_ops, i);
561         if (result == var
562             || (TREE_CODE (result) == SSA_NAME
563                 && SSA_NAME_VAR (result) == var))
564           {
565             source = V_MAY_DEF_OP (prev_vops->v_may_def_ops, i);
566             break;
567           }
568       }
569
570   /* If no previous V_MAY_DEF operand was found for VAR, create one now.  */
571   if (source == NULL_TREE)
572     {
573       result = var;
574       source = var;
575     }
576
577   VARRAY_PUSH_TREE (build_v_may_defs, result);
578   VARRAY_PUSH_TREE (build_v_may_defs, source);
579 }
580
581
582 /* Add VAR to the list of virtual uses for STMT.  If PREV_VOPS
583    is not NULL, the existing entries are preserved and no new entries are
584    added here.  This is done to preserve the SSA numbering of virtual
585    operands.  */
586
587 static void
588 append_vuse (tree var, tree stmt, voperands_t prev_vops)
589 {
590   stmt_ann_t ann;
591   size_t i;
592   bool found;
593   tree vuse;
594
595 #ifdef ENABLE_CHECKING
596   if (check_build_stmt != stmt)
597     abort();
598 #endif
599
600   ann = stmt_ann (stmt);
601
602   /* Don't allow duplicate entries.  */
603   for (i = 0; i < VARRAY_ACTIVE_SIZE (build_vuses); i++)
604     {
605       tree vuse_var = VARRAY_TREE (build_vuses, i);
606       if (var == vuse_var
607           || (TREE_CODE (vuse_var) == SSA_NAME
608               && var == SSA_NAME_VAR (vuse_var)))
609         return;
610     }
611
612   /* If the statement already had virtual uses, see if any of the
613      existing VUSEs matches VAR.  If so, re-use it, otherwise add a new
614      VUSE for VAR.  */
615   found = false;
616   vuse = NULL_TREE;
617   if (prev_vops)
618     for (i = 0; i < NUM_VUSES (prev_vops->vuse_ops); i++)
619       {
620         vuse = VUSE_OP (prev_vops->vuse_ops, i);
621         if (vuse == var
622             || (TREE_CODE (vuse) == SSA_NAME
623                 && SSA_NAME_VAR (vuse) == var))
624           {
625             found = true;
626             break;
627           }
628       }
629
630   /* If VAR existed already in PREV_VOPS, re-use it.  */
631   if (found)
632     var = vuse;
633
634   VARRAY_PUSH_TREE (build_vuses, var);
635 }
636
637 /* Add VAR to the list of virtual must definitions for STMT.  If PREV_VOPS
638    is not NULL, the existing entries are preserved and no new entries are
639    added here.  This is done to preserve the SSA numbering of virtual
640    operands.  */
641
642 static void
643 append_v_must_def (tree var, tree stmt, voperands_t prev_vops)
644 {
645   stmt_ann_t ann;
646   size_t i;
647   bool found;
648   tree v_must_def;
649
650 #ifdef ENABLE_CHECKING
651   if (check_build_stmt != stmt)
652     abort();
653 #endif
654
655   ann = stmt_ann (stmt);
656
657   /* Don't allow duplicate entries.  */
658   for (i = 0; i < VARRAY_ACTIVE_SIZE (build_v_must_defs); i++)
659     {
660       tree v_must_def_var = VARRAY_TREE (build_v_must_defs, i);
661       if (var == v_must_def_var
662           || (TREE_CODE (v_must_def_var) == SSA_NAME
663               && var == SSA_NAME_VAR (v_must_def_var)))
664         return;
665     }
666
667   /* If the statement already had virtual must defs, see if any of the
668      existing V_MUST_DEFs matches VAR.  If so, re-use it, otherwise add a new
669      V_MUST_DEF for VAR.  */
670   found = false;
671   v_must_def = NULL_TREE;
672   if (prev_vops)
673     for (i = 0; i < NUM_V_MUST_DEFS (prev_vops->v_must_def_ops); i++)
674       {
675         v_must_def = V_MUST_DEF_OP (prev_vops->v_must_def_ops, i);
676         if (v_must_def == var
677             || (TREE_CODE (v_must_def) == SSA_NAME
678                 && SSA_NAME_VAR (v_must_def) == var))
679           {
680             found = true;
681             break;
682           }
683       }
684
685   /* If VAR existed already in PREV_VOPS, re-use it.  */
686   if (found)
687     var = v_must_def;
688
689   VARRAY_PUSH_TREE (build_v_must_defs, var);
690 }
691
692
693 /* External entry point which by-passes the previous vops mechanism.  */
694 void
695 add_vuse (tree var, tree stmt)
696 {
697   append_vuse (var, stmt, NULL);
698 }
699
700
701 /* Get the operands of statement STMT.  Note that repeated calls to
702    get_stmt_operands for the same statement will do nothing until the
703    statement is marked modified by a call to modify_stmt().  */
704
705 void
706 get_stmt_operands (tree stmt)
707 {
708   enum tree_code code;
709   stmt_ann_t ann;
710   struct voperands_d prev_vops;
711
712 #if defined ENABLE_CHECKING
713   /* The optimizers cannot handle statements that are nothing but a
714      _DECL.  This indicates a bug in the gimplifier.  */
715   if (SSA_VAR_P (stmt))
716     abort ();
717 #endif
718
719   /* Ignore error statements.  */
720   if (TREE_CODE (stmt) == ERROR_MARK)
721     return;
722
723   ann = get_stmt_ann (stmt);
724
725   /* If the statement has not been modified, the operands are still valid.  */
726   if (!ann->modified)
727     return;
728
729   timevar_push (TV_TREE_OPS);
730
731   /* Initially assume that the statement has no volatile operands, nor
732      makes aliased loads or stores.  */
733   ann->has_volatile_ops = false;
734   ann->makes_aliased_stores = false;
735   ann->makes_aliased_loads = false;
736
737   /* Remove any existing operands as they will be scanned again.  */
738   free_defs (&(ann->def_ops), true);
739   free_uses (&(ann->use_ops), true);
740
741   /* Before removing existing virtual operands, save them in PREV_VOPS so 
742      that we can re-use their SSA versions.  */
743   prev_vops.v_may_def_ops = V_MAY_DEF_OPS (ann);
744   prev_vops.vuse_ops = VUSE_OPS (ann);
745   prev_vops.v_must_def_ops = V_MUST_DEF_OPS (ann);
746
747   /* Don't free the previous values to memory since we're still using them.  */
748   free_v_may_defs (&(ann->v_may_def_ops), false);
749   free_vuses (&(ann->vuse_ops), false);
750   free_v_must_defs (&(ann->v_must_def_ops), false);
751
752   start_ssa_stmt_operands (stmt);
753
754   code = TREE_CODE (stmt);
755   switch (code)
756     {
757     case MODIFY_EXPR:
758       get_expr_operands (stmt, &TREE_OPERAND (stmt, 1), opf_none, &prev_vops);
759       if (TREE_CODE (TREE_OPERAND (stmt, 0)) == ARRAY_REF 
760           || TREE_CODE (TREE_OPERAND (stmt, 0)) == COMPONENT_REF
761           || TREE_CODE (TREE_OPERAND (stmt, 0)) == REALPART_EXPR
762           || TREE_CODE (TREE_OPERAND (stmt, 0)) == IMAGPART_EXPR
763           /* Use a V_MAY_DEF if the RHS might throw, as the LHS won't be
764              modified in that case.  FIXME we should represent somehow
765              that it is killed on the fallthrough path.  */
766           || tree_could_throw_p (TREE_OPERAND (stmt, 1)))
767         get_expr_operands (stmt, &TREE_OPERAND (stmt, 0), opf_is_def, 
768                            &prev_vops);
769       else
770         get_expr_operands (stmt, &TREE_OPERAND (stmt, 0), 
771                            opf_is_def | opf_kill_def, &prev_vops);
772       break;
773
774     case COND_EXPR:
775       get_expr_operands (stmt, &COND_EXPR_COND (stmt), opf_none, &prev_vops);
776       break;
777
778     case SWITCH_EXPR:
779       get_expr_operands (stmt, &SWITCH_COND (stmt), opf_none, &prev_vops);
780       break;
781
782     case ASM_EXPR:
783       get_asm_expr_operands (stmt, &prev_vops);
784       break;
785
786     case RETURN_EXPR:
787       get_expr_operands (stmt, &TREE_OPERAND (stmt, 0), opf_none, &prev_vops);
788       break;
789
790     case GOTO_EXPR:
791       get_expr_operands (stmt, &GOTO_DESTINATION (stmt), opf_none, &prev_vops);
792       break;
793
794     case LABEL_EXPR:
795       get_expr_operands (stmt, &LABEL_EXPR_LABEL (stmt), opf_none, &prev_vops);
796       break;
797
798       /* These nodes contain no variable references.  */
799     case BIND_EXPR:
800     case CASE_LABEL_EXPR:
801     case TRY_CATCH_EXPR:
802     case TRY_FINALLY_EXPR:
803     case EH_FILTER_EXPR:
804     case CATCH_EXPR:
805     case RESX_EXPR:
806       break;
807
808     default:
809       /* Notice that if get_expr_operands tries to use &STMT as the operand
810          pointer (which may only happen for USE operands), we will abort in
811          append_use.  This default will handle statements like empty statements,
812          CALL_EXPRs or VA_ARG_EXPRs that may appear on the RHS of a statement
813          or as statements themselves.  */
814       get_expr_operands (stmt, &stmt, opf_none, &prev_vops);
815       break;
816     }
817
818   finalize_ssa_stmt_operands (stmt);
819
820   /* Now free the previous virtual ops to memory.  */
821   free_v_may_defs (&(prev_vops.v_may_def_ops), true);
822   free_vuses (&(prev_vops.vuse_ops), true);
823   free_v_must_defs (&(prev_vops.v_must_def_ops), true);
824
825   /* Clear the modified bit for STMT.  Subsequent calls to
826      get_stmt_operands for this statement will do nothing until the
827      statement is marked modified by a call to modify_stmt().  */
828   ann->modified = 0;
829
830   timevar_pop (TV_TREE_OPS);
831 }
832
833
834 /* Recursively scan the expression pointed by EXPR_P in statement STMT.
835    FLAGS is one of the OPF_* constants modifying how to interpret the
836    operands found.  PREV_VOPS is as in append_v_may_def and append_vuse.  */
837
838 static void
839 get_expr_operands (tree stmt, tree *expr_p, int flags, voperands_t prev_vops)
840 {
841   enum tree_code code;
842   char class;
843   tree expr = *expr_p;
844
845   if (expr == NULL || expr == error_mark_node)
846     return;
847
848   code = TREE_CODE (expr);
849   class = TREE_CODE_CLASS (code);
850
851   switch (code)
852     {
853     case ADDR_EXPR:
854       /* We could have the address of a component, array member,
855          etc which has interesting variable references.  */
856       /* Taking the address of a variable does not represent a
857          reference to it, but the fact that STMT takes its address will be
858          of interest to some passes (e.g. alias resolution).  */
859       add_stmt_operand (expr_p, stmt, 0, NULL);
860
861       /* If the address is constant (invariant is not sufficient), there will
862          be no interesting variable references inside.  */
863       if (TREE_CONSTANT (expr))
864         return;
865
866       /* There should be no VUSEs created, since the referenced objects are
867          not really accessed.  The only operands that we should find here
868          are ARRAY_REF indices which will always be real operands (GIMPLE
869          does not allow non-registers as array indices).  */
870       flags |= opf_no_vops;
871
872       get_expr_operands (stmt, &TREE_OPERAND (expr, 0), flags, prev_vops);
873       return;
874
875     case SSA_NAME:
876     case VAR_DECL:
877     case PARM_DECL:
878     case RESULT_DECL:
879       /* If we found a variable, add it to DEFS or USES depending
880          on the operand flags.  */
881       add_stmt_operand (expr_p, stmt, flags, prev_vops);
882       return;
883
884     case INDIRECT_REF:
885       get_indirect_ref_operands (stmt, expr, flags, prev_vops);
886       return;
887
888     case ARRAY_REF:
889     case ARRAY_RANGE_REF:
890       /* Treat array references as references to the virtual variable
891          representing the array.  The virtual variable for an ARRAY_REF
892          is the VAR_DECL for the array.  */
893
894       /* Add the virtual variable for the ARRAY_REF to VDEFS or VUSES
895          according to the value of IS_DEF.  Recurse if the LHS of the
896          ARRAY_REF node is not a regular variable.  */
897       if (SSA_VAR_P (TREE_OPERAND (expr, 0)))
898         add_stmt_operand (expr_p, stmt, flags, prev_vops);
899       else
900         get_expr_operands (stmt, &TREE_OPERAND (expr, 0), flags, prev_vops);
901
902       get_expr_operands (stmt, &TREE_OPERAND (expr, 1), opf_none, prev_vops);
903       get_expr_operands (stmt, &TREE_OPERAND (expr, 2), opf_none, prev_vops);
904       get_expr_operands (stmt, &TREE_OPERAND (expr, 3), opf_none, prev_vops);
905       return;
906
907     case COMPONENT_REF:
908     case REALPART_EXPR:
909     case IMAGPART_EXPR:
910       /* Similarly to arrays, references to compound variables (complex
911          types and structures/unions) are globbed.
912
913          FIXME: This means that
914
915                         a.x = 6;
916                         a.y = 7;
917                         foo (a.x, a.y);
918
919          will not be constant propagated because the two partial
920          definitions to 'a' will kill each other.  Note that SRA may be
921          able to fix this problem if 'a' can be scalarized.  */
922
923       /* If the LHS of the compound reference is not a regular variable,
924          recurse to keep looking for more operands in the subexpression.  */
925       if (SSA_VAR_P (TREE_OPERAND (expr, 0)))
926         add_stmt_operand (expr_p, stmt, flags, prev_vops);
927       else
928         get_expr_operands (stmt, &TREE_OPERAND (expr, 0), flags, prev_vops);
929
930       if (code == COMPONENT_REF)
931         get_expr_operands (stmt, &TREE_OPERAND (expr, 2), opf_none, prev_vops);
932       return;
933
934     case WITH_SIZE_EXPR:
935       /* WITH_SIZE_EXPR is a pass-through reference to it's first argument,
936          and an rvalue reference to its second argument.  */
937       get_expr_operands (stmt, &TREE_OPERAND (expr, 1), opf_none, prev_vops);
938       get_expr_operands (stmt, &TREE_OPERAND (expr, 0), flags, prev_vops);
939       return;
940
941     case CALL_EXPR:
942       get_call_expr_operands (stmt, expr, prev_vops);
943       return;
944
945     case MODIFY_EXPR:
946       {
947         int subflags;
948         tree op;
949
950         get_expr_operands (stmt, &TREE_OPERAND (expr, 1), opf_none, prev_vops);
951
952         op = TREE_OPERAND (expr, 0);
953         if (TREE_CODE (op) == WITH_SIZE_EXPR)
954           op = TREE_OPERAND (expr, 0);
955         if (TREE_CODE (op) == ARRAY_REF 
956             || TREE_CODE (op) == COMPONENT_REF
957             || TREE_CODE (op) == REALPART_EXPR
958             || TREE_CODE (op) == IMAGPART_EXPR)
959           subflags = opf_is_def;
960         else
961           subflags = opf_is_def | opf_kill_def;
962
963         get_expr_operands (stmt, &TREE_OPERAND (expr, 0), subflags, prev_vops);
964         return;
965       }
966
967     case VA_ARG_EXPR:
968       /* Mark VA_ARG_EXPR nodes as making volatile references.  FIXME,
969          this is needed because we currently do not gimplify VA_ARG_EXPR
970          properly.  */
971       stmt_ann (stmt)->has_volatile_ops = true;
972       return;
973
974     case TRUTH_NOT_EXPR:
975     case BIT_FIELD_REF:
976     do_unary:
977       get_expr_operands (stmt, &TREE_OPERAND (expr, 0), flags, prev_vops);
978       return;
979
980     case TRUTH_AND_EXPR:
981     case TRUTH_OR_EXPR:
982     case TRUTH_XOR_EXPR:
983     case COMPOUND_EXPR:
984     case OBJ_TYPE_REF:
985     do_binary:
986       {
987         tree op0 = TREE_OPERAND (expr, 0);
988         tree op1 = TREE_OPERAND (expr, 1);
989
990         /* If it would be profitable to swap the operands, then do so to
991            canonicalize the statement, enabling better optimization.
992
993            By placing canonicalization of such expressions here we
994            transparently keep statements in canonical form, even
995            when the statement is modified.  */
996         if (tree_swap_operands_p (op0, op1, false))
997           {
998             /* For relationals we need to swap the operands
999                and change the code.  */
1000             if (code == LT_EXPR
1001                 || code == GT_EXPR
1002                 || code == LE_EXPR
1003                 || code == GE_EXPR)
1004               {
1005                 TREE_SET_CODE (expr, swap_tree_comparison (code));
1006                 TREE_OPERAND (expr, 0) = op1;
1007                 TREE_OPERAND (expr, 1) = op0;
1008               }
1009           
1010             /* For a commutative operator we can just swap the operands.  */
1011             else if (commutative_tree_code (code))
1012               {
1013                 TREE_OPERAND (expr, 0) = op1;
1014                 TREE_OPERAND (expr, 1) = op0;
1015               }
1016           }
1017
1018         get_expr_operands (stmt, &TREE_OPERAND (expr, 0), flags, prev_vops);
1019         get_expr_operands (stmt, &TREE_OPERAND (expr, 1), flags, prev_vops);
1020         return;
1021       }
1022
1023     case BLOCK:
1024     case FUNCTION_DECL:
1025     case EXC_PTR_EXPR:
1026     case FILTER_EXPR:
1027     case LABEL_DECL:
1028     case CONSTRUCTOR:
1029       /* Expressions that make no memory references.  */
1030       return;
1031
1032     default:
1033       if (class == '1')
1034         goto do_unary;
1035       if (class == '2' || class == '<')
1036         goto do_binary;
1037       if (class == 'c' || class == 't')
1038         return;
1039     }
1040
1041   /* If we get here, something has gone wrong.  */
1042   fprintf (stderr, "unhandled expression in get_expr_operands():\n");
1043   debug_tree (expr);
1044   fputs ("\n", stderr);
1045   abort ();
1046 }
1047
1048
1049 /* Scan operands in ASM_EXPR STMT.  PREV_VOPS is as in append_v_may_def and
1050    append_vuse.  */
1051
1052 static void
1053 get_asm_expr_operands (tree stmt, voperands_t prev_vops)
1054 {
1055   int noutputs = list_length (ASM_OUTPUTS (stmt));
1056   const char **oconstraints
1057     = (const char **) alloca ((noutputs) * sizeof (const char *));
1058   int i;
1059   tree link;
1060   const char *constraint;
1061   bool allows_mem, allows_reg, is_inout;
1062   stmt_ann_t s_ann = stmt_ann (stmt);
1063
1064   for (i=0, link = ASM_OUTPUTS (stmt); link; ++i, link = TREE_CHAIN (link))
1065     {
1066       oconstraints[i] = constraint
1067         = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (link)));
1068       parse_output_constraint (&constraint, i, 0, 0,
1069           &allows_mem, &allows_reg, &is_inout);
1070
1071 #if defined ENABLE_CHECKING
1072       /* This should have been split in gimplify_asm_expr.  */
1073       if (allows_reg && is_inout)
1074         abort ();
1075 #endif
1076
1077       /* Memory operands are addressable.  Note that STMT needs the
1078          address of this operand.  */
1079       if (!allows_reg && allows_mem)
1080         {
1081           tree t = get_base_address (TREE_VALUE (link));
1082           if (t && DECL_P (t))
1083             note_addressable (t, s_ann);
1084         }
1085
1086       get_expr_operands (stmt, &TREE_VALUE (link), opf_is_def, prev_vops);
1087     }
1088
1089   for (link = ASM_INPUTS (stmt); link; link = TREE_CHAIN (link))
1090     {
1091       constraint
1092         = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (link)));
1093       parse_input_constraint (&constraint, 0, 0, noutputs, 0,
1094           oconstraints, &allows_mem, &allows_reg);
1095
1096       /* Memory operands are addressable.  Note that STMT needs the
1097          address of this operand.  */
1098       if (!allows_reg && allows_mem)
1099         {
1100           tree t = get_base_address (TREE_VALUE (link));
1101           if (t && DECL_P (t))
1102             note_addressable (t, s_ann);
1103         }
1104
1105       get_expr_operands (stmt, &TREE_VALUE (link), 0, prev_vops);
1106     }
1107
1108
1109   /* Clobber memory for asm ("" : : : "memory");  */
1110   for (link = ASM_CLOBBERS (stmt); link; link = TREE_CHAIN (link))
1111     if (strcmp (TREE_STRING_POINTER (TREE_VALUE (link)), "memory") == 0)
1112       {
1113         size_t i;
1114
1115         /* Clobber all call-clobbered variables (or .GLOBAL_VAR if we
1116            decided to group them).  */
1117         if (global_var)
1118           add_stmt_operand (&global_var, stmt, opf_is_def, prev_vops);
1119         else
1120           EXECUTE_IF_SET_IN_BITMAP (call_clobbered_vars, 0, i,
1121               {
1122                 tree var = referenced_var (i);
1123                 add_stmt_operand (&var, stmt, opf_is_def, prev_vops);
1124               });
1125
1126         /* Now clobber all addressables.  */
1127         EXECUTE_IF_SET_IN_BITMAP (addressable_vars, 0, i,
1128             {
1129               tree var = referenced_var (i);
1130               add_stmt_operand (&var, stmt, opf_is_def, prev_vops);
1131             });
1132
1133         /* If we don't have call-clobbered nor addressable vars and we
1134            still have not computed aliasing information, just mark the
1135            statement as having volatile operands.  If the alias pass
1136            finds some, we will add them at that point.  */
1137         if (!aliases_computed_p)
1138           stmt_ann (stmt)->has_volatile_ops = true;
1139
1140         break;
1141       }
1142 }
1143
1144 /* A subroutine of get_expr_operands to handle INDIRECT_REF.  */
1145
1146 static void
1147 get_indirect_ref_operands (tree stmt, tree expr, int flags,
1148                            voperands_t prev_vops)
1149 {
1150   tree *pptr = &TREE_OPERAND (expr, 0);
1151   tree ptr = *pptr;
1152
1153   if (SSA_VAR_P (ptr))
1154     {
1155       if (!aliases_computed_p)
1156         {
1157           /* If the pointer does not have a memory tag and aliases have not
1158              been computed yet, mark the statement as having volatile
1159              operands to prevent DOM from entering it in equivalence tables
1160              and DCE from killing it.  */
1161           stmt_ann (stmt)->has_volatile_ops = true;
1162         }
1163       else
1164         {
1165           struct ptr_info_def *pi = NULL;
1166
1167           /* If we have computed aliasing already, check if PTR has
1168              flow-sensitive points-to information.  */
1169           if (TREE_CODE (ptr) == SSA_NAME
1170               && (pi = SSA_NAME_PTR_INFO (ptr)) != NULL
1171               && pi->name_mem_tag)
1172             {
1173               /* PTR has its own memory tag.  Use it.  */
1174               add_stmt_operand (&pi->name_mem_tag, stmt, flags, prev_vops);
1175             }
1176           else
1177             {
1178               /* If PTR is not an SSA_NAME or it doesn't have a name
1179                  tag, use its type memory tag.  */
1180               var_ann_t ann;
1181
1182               /* If we are emitting debugging dumps, display a warning if
1183                  PTR is an SSA_NAME with no flow-sensitive alias
1184                  information.  That means that we may need to compute
1185                  aliasing again.  */
1186               if (dump_file
1187                   && TREE_CODE (ptr) == SSA_NAME
1188                   && pi == NULL)
1189                 {
1190                   fprintf (dump_file,
1191                            "NOTE: no flow-sensitive alias info for ");
1192                   print_generic_expr (dump_file, ptr, dump_flags);
1193                   fprintf (dump_file, " in ");
1194                   print_generic_stmt (dump_file, stmt, dump_flags);
1195                 }
1196
1197               if (TREE_CODE (ptr) == SSA_NAME)
1198                 ptr = SSA_NAME_VAR (ptr);
1199               ann = var_ann (ptr);
1200               add_stmt_operand (&ann->type_mem_tag, stmt, flags, prev_vops);
1201             }
1202         }
1203     }
1204
1205   /* If a constant is used as a pointer, we can't generate a real
1206      operand for it but we mark the statement volatile to prevent
1207      optimizations from messing things up.  */
1208   else if (TREE_CODE (ptr) == INTEGER_CST)
1209     {
1210       stmt_ann (stmt)->has_volatile_ops = true;
1211       return;
1212     }
1213
1214   /* Everything else *should* have been folded elsewhere, but users
1215      are smarter than we in finding ways to write invalid code.  We
1216      cannot just abort here.  If we were absolutely certain that we
1217      do handle all valid cases, then we could just do nothing here.
1218      That seems optimistic, so attempt to do something logical... */
1219   else if ((TREE_CODE (ptr) == PLUS_EXPR || TREE_CODE (ptr) == MINUS_EXPR)
1220            && TREE_CODE (TREE_OPERAND (ptr, 0)) == ADDR_EXPR
1221            && TREE_CODE (TREE_OPERAND (ptr, 1)) == INTEGER_CST)
1222     {
1223       /* Make sure we know the object is addressable.  */
1224       pptr = &TREE_OPERAND (ptr, 0);
1225       add_stmt_operand (pptr, stmt, 0, NULL);
1226
1227       /* Mark the object itself with a VUSE.  */
1228       pptr = &TREE_OPERAND (*pptr, 0);
1229       get_expr_operands (stmt, pptr, flags, prev_vops);
1230       return;
1231     }
1232
1233   /* Ok, this isn't even is_gimple_min_invariant.  Something's broke.  */
1234   else
1235     abort ();
1236
1237   /* Add a USE operand for the base pointer.  */
1238   get_expr_operands (stmt, pptr, opf_none, prev_vops);
1239 }
1240
1241 /* A subroutine of get_expr_operands to handle CALL_EXPR.  */
1242
1243 static void
1244 get_call_expr_operands (tree stmt, tree expr, voperands_t prev_vops)
1245 {
1246   tree op;
1247   int call_flags = call_expr_flags (expr);
1248
1249   /* Find uses in the called function.  */
1250   get_expr_operands (stmt, &TREE_OPERAND (expr, 0), opf_none, prev_vops);
1251
1252   for (op = TREE_OPERAND (expr, 1); op; op = TREE_CHAIN (op))
1253     get_expr_operands (stmt, &TREE_VALUE (op), opf_none, prev_vops);
1254
1255   get_expr_operands (stmt, &TREE_OPERAND (expr, 2), opf_none, prev_vops);
1256
1257   if (bitmap_first_set_bit (call_clobbered_vars) >= 0)
1258     {
1259       /* A 'pure' or a 'const' functions never call clobber anything. 
1260          A 'noreturn' function might, but since we don't return anyway 
1261          there is no point in recording that.  */ 
1262       if (!(call_flags
1263             & (ECF_PURE | ECF_CONST | ECF_NORETURN)))
1264         add_call_clobber_ops (stmt, prev_vops);
1265       else if (!(call_flags & (ECF_CONST | ECF_NORETURN)))
1266         add_call_read_ops (stmt, prev_vops);
1267     }
1268   else if (!aliases_computed_p)
1269     stmt_ann (stmt)->has_volatile_ops = true;
1270 }
1271
1272
1273 /* Add *VAR_P to the appropriate operand array of STMT.  FLAGS is as in
1274    get_expr_operands.  If *VAR_P is a GIMPLE register, it will be added to
1275    the statement's real operands, otherwise it is added to virtual
1276    operands.
1277
1278    PREV_VOPS is used when adding virtual operands to statements that
1279       already had them (See append_v_may_def and append_vuse).  */
1280
1281 static void
1282 add_stmt_operand (tree *var_p, tree stmt, int flags, voperands_t prev_vops)
1283 {
1284   bool is_real_op;
1285   tree var, sym;
1286   stmt_ann_t s_ann;
1287   var_ann_t v_ann;
1288
1289   var = *var_p;
1290   STRIP_NOPS (var);
1291
1292   s_ann = stmt_ann (stmt);
1293
1294   /* If the operand is an ADDR_EXPR, add its operand to the list of
1295      variables that have had their address taken in this statement.  */
1296   if (TREE_CODE (var) == ADDR_EXPR)
1297     {
1298       note_addressable (TREE_OPERAND (var, 0), s_ann);
1299       return;
1300     }
1301
1302   /* If the original variable is not a scalar, it will be added to the list
1303      of virtual operands.  In that case, use its base symbol as the virtual
1304      variable representing it.  */
1305   is_real_op = is_gimple_reg (var);
1306   if (!is_real_op && !DECL_P (var))
1307     var = get_virtual_var (var);
1308
1309   /* If VAR is not a variable that we care to optimize, do nothing.  */
1310   if (var == NULL_TREE || !SSA_VAR_P (var))
1311     return;
1312
1313   sym = (TREE_CODE (var) == SSA_NAME ? SSA_NAME_VAR (var) : var);
1314   v_ann = var_ann (sym);
1315
1316   /* Don't expose volatile variables to the optimizers.  */
1317   if (TREE_THIS_VOLATILE (sym))
1318     {
1319       s_ann->has_volatile_ops = true;
1320       return;
1321     }
1322
1323   if (is_real_op)
1324     {
1325       /* The variable is a GIMPLE register.  Add it to real operands.  */
1326       if (flags & opf_is_def)
1327         append_def (var_p, stmt);
1328       else
1329         append_use (var_p, stmt);
1330     }
1331   else
1332     {
1333       varray_type aliases;
1334
1335       /* The variable is not a GIMPLE register.  Add it (or its aliases) to
1336          virtual operands, unless the caller has specifically requested
1337          not to add virtual operands (used when adding operands inside an
1338          ADDR_EXPR expression).  */
1339       if (flags & opf_no_vops)
1340         return;
1341
1342       aliases = v_ann->may_aliases;
1343
1344       /* If alias information hasn't been computed yet, then
1345          addressable variables will not be an alias tag nor will they
1346          have aliases.  In this case, mark the statement as having
1347          volatile operands.  */
1348       if (!aliases_computed_p && may_be_aliased (var))
1349         s_ann->has_volatile_ops = true;
1350
1351       if (aliases == NULL)
1352         {
1353           /* The variable is not aliased or it is an alias tag.  */
1354           if (flags & opf_is_def)
1355             {
1356               if (v_ann->is_alias_tag)
1357                 {
1358                   /* Alias tagged vars get regular V_MAY_DEF  */
1359                   s_ann->makes_aliased_stores = 1;
1360                   append_v_may_def (var, stmt, prev_vops);
1361                 }
1362               else if ((flags & opf_kill_def) 
1363                         && v_ann->mem_tag_kind == NOT_A_TAG)
1364                 /* V_MUST_DEF for non-aliased non-GIMPLE register 
1365                    variable definitions. Avoid memory tags.  */
1366                 append_v_must_def (var, stmt, prev_vops);
1367               else
1368                 /* Call-clobbered variables & memory tags get 
1369                    V_MAY_DEF  */
1370                 append_v_may_def (var, stmt, prev_vops);
1371             }
1372           else
1373             {
1374               append_vuse (var, stmt, prev_vops);
1375               if (v_ann->is_alias_tag)
1376                 s_ann->makes_aliased_loads = 1;
1377             }
1378         }
1379       else
1380         {
1381           size_t i;
1382
1383           /* The variable is aliased.  Add its aliases to the virtual
1384              operands.  */
1385           if (VARRAY_ACTIVE_SIZE (aliases) == 0)
1386             abort ();
1387
1388           if (flags & opf_is_def)
1389             {
1390               /* If the variable is also an alias tag, add a virtual
1391                  operand for it, otherwise we will miss representing
1392                  references to the members of the variable's alias set.
1393                  This fixes the bug in gcc.c-torture/execute/20020503-1.c.  */
1394               if (v_ann->is_alias_tag)
1395                 append_v_may_def (var, stmt, prev_vops);
1396
1397               for (i = 0; i < VARRAY_ACTIVE_SIZE (aliases); i++)
1398                 append_v_may_def (VARRAY_TREE (aliases, i), stmt, prev_vops);
1399
1400               s_ann->makes_aliased_stores = 1;
1401             }
1402           else
1403             {
1404               if (v_ann->is_alias_tag)
1405                 append_vuse (var, stmt, prev_vops);
1406
1407               for (i = 0; i < VARRAY_ACTIVE_SIZE (aliases); i++)
1408                 append_vuse (VARRAY_TREE (aliases, i), stmt, prev_vops);
1409
1410               s_ann->makes_aliased_loads = 1;
1411             }
1412         }
1413     }
1414 }
1415
1416 /* Record that VAR had its address taken in the statement with annotations
1417    S_ANN.  */
1418
1419 static void
1420 note_addressable (tree var, stmt_ann_t s_ann)
1421 {
1422   var = get_base_address (var);
1423   if (var && SSA_VAR_P (var))
1424     {
1425       if (s_ann->addresses_taken == NULL)
1426         s_ann->addresses_taken = BITMAP_GGC_ALLOC ();
1427       bitmap_set_bit (s_ann->addresses_taken, var_ann (var)->uid);
1428     }
1429 }
1430
1431
1432 /* Add clobbering definitions for .GLOBAL_VAR or for each of the call
1433    clobbered variables in the function.  */
1434
1435 static void
1436 add_call_clobber_ops (tree stmt, voperands_t prev_vops)
1437 {
1438   /* Functions that are not const, pure or never return may clobber
1439      call-clobbered variables.  */
1440   stmt_ann (stmt)->makes_clobbering_call = true;
1441
1442   /* If we had created .GLOBAL_VAR earlier, use it.  Otherwise, add 
1443      a V_MAY_DEF operand for every call clobbered variable.  See 
1444      compute_may_aliases for the heuristic used to decide whether 
1445      to create .GLOBAL_VAR or not.  */
1446   if (global_var)
1447     add_stmt_operand (&global_var, stmt, opf_is_def, prev_vops);
1448   else
1449     {
1450       size_t i;
1451
1452       EXECUTE_IF_SET_IN_BITMAP (call_clobbered_vars, 0, i,
1453         {
1454           tree var = referenced_var (i);
1455
1456           /* If VAR is read-only, don't add a V_MAY_DEF, just a 
1457              VUSE operand.  */
1458           if (!TREE_READONLY (var))
1459             add_stmt_operand (&var, stmt, opf_is_def, prev_vops);
1460           else
1461             add_stmt_operand (&var, stmt, opf_none, prev_vops);
1462         });
1463     }
1464 }
1465
1466
1467 /* Add VUSE operands for .GLOBAL_VAR or all call clobbered variables in the
1468    function.  */
1469
1470 static void
1471 add_call_read_ops (tree stmt, voperands_t prev_vops)
1472 {
1473   /* Otherwise, if the function is not pure, it may reference memory.  Add
1474      a VUSE for .GLOBAL_VAR if it has been created.  Otherwise, add a VUSE
1475      for each call-clobbered variable.  See add_referenced_var for the
1476      heuristic used to decide whether to create .GLOBAL_VAR.  */
1477   if (global_var)
1478     add_stmt_operand (&global_var, stmt, opf_none, prev_vops);
1479   else
1480     {
1481       size_t i;
1482
1483       EXECUTE_IF_SET_IN_BITMAP (call_clobbered_vars, 0, i,
1484         {
1485           tree var = referenced_var (i);
1486           add_stmt_operand (&var, stmt, opf_none, prev_vops);
1487         });
1488     }
1489 }
1490
1491 /* Copies virtual operands from SRC to DST.  */
1492
1493 void
1494 copy_virtual_operands (tree dst, tree src)
1495 {
1496   vuse_optype vuses = STMT_VUSE_OPS (src);
1497   v_may_def_optype v_may_defs = STMT_V_MAY_DEF_OPS (src);
1498   v_must_def_optype v_must_defs = STMT_V_MUST_DEF_OPS (src);
1499   vuse_optype *vuses_new = &stmt_ann (dst)->vuse_ops;
1500   v_may_def_optype *v_may_defs_new = &stmt_ann (dst)->v_may_def_ops;
1501   v_must_def_optype *v_must_defs_new = &stmt_ann (dst)->v_must_def_ops;
1502   unsigned i;
1503
1504   if (vuses)
1505     {
1506       *vuses_new = allocate_vuse_optype (NUM_VUSES (vuses));
1507       for (i = 0; i < NUM_VUSES (vuses); i++)
1508         SET_VUSE_OP (*vuses_new, i, VUSE_OP (vuses, i));
1509     }
1510
1511   if (v_may_defs)
1512     {
1513       *v_may_defs_new = allocate_v_may_def_optype (NUM_V_MAY_DEFS (v_may_defs));
1514       for (i = 0; i < NUM_V_MAY_DEFS (v_may_defs); i++)
1515         {
1516           SET_V_MAY_DEF_OP (*v_may_defs_new, i, V_MAY_DEF_OP (v_may_defs, i));
1517           SET_V_MAY_DEF_RESULT (*v_may_defs_new, i, 
1518                                 V_MAY_DEF_RESULT (v_may_defs, i));
1519         }
1520     }
1521
1522   if (v_must_defs)
1523     {
1524       *v_must_defs_new = allocate_v_must_def_optype (NUM_V_MUST_DEFS (v_must_defs));
1525       for (i = 0; i < NUM_V_MUST_DEFS (v_must_defs); i++)
1526         SET_V_MUST_DEF_OP (*v_must_defs_new, i, V_MUST_DEF_OP (v_must_defs, i));
1527     }
1528 }
1529
1530 #include "gt-tree-ssa-operands.h"