OSDN Git Service

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