OSDN Git Service

* doc/tree-ssa.texi: Remove references to VDEF and add descriptions
[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.
795      Statements marked with 'has_volatile_ops' are not processed by the
796      optimizers.  */
797   ann->has_volatile_ops = false;
798
799   /* Remove any existing operands as they will be scanned again.  */
800   free_defs (&(ann->def_ops), true);
801   free_uses (&(ann->use_ops), true);
802
803   /* Before removing existing virtual operands, save them in PREV_VOPS so 
804      that we can re-use their SSA versions.  */
805   prev_vops.v_may_def_ops = V_MAY_DEF_OPS (ann);
806   prev_vops.vuse_ops = VUSE_OPS (ann);
807   prev_vops.v_must_def_ops = V_MUST_DEF_OPS (ann);
808
809   /* Dont free the previous values to memory since we're still using them.  */
810   free_v_may_defs (&(ann->v_may_def_ops), false);
811   free_vuses (&(ann->vuse_ops), false);
812   free_v_must_defs (&(ann->v_must_def_ops), false);
813
814   start_ssa_stmt_operands (stmt);
815
816   code = TREE_CODE (stmt);
817   switch (code)
818     {
819     case MODIFY_EXPR:
820       get_expr_operands (stmt, &TREE_OPERAND (stmt, 1), opf_none, &prev_vops);
821       if (TREE_CODE (TREE_OPERAND (stmt, 0)) == ARRAY_REF 
822           || TREE_CODE (TREE_OPERAND (stmt, 0)) == COMPONENT_REF
823           || TREE_CODE (TREE_OPERAND (stmt, 0)) == REALPART_EXPR
824           || TREE_CODE (TREE_OPERAND (stmt, 0)) == IMAGPART_EXPR)
825         get_expr_operands (stmt, &TREE_OPERAND (stmt, 0), opf_is_def, 
826                            &prev_vops);
827       else
828         get_expr_operands (stmt, &TREE_OPERAND (stmt, 0), 
829                            opf_is_def | opf_kill_def, &prev_vops);
830       break;
831
832     case COND_EXPR:
833       get_expr_operands (stmt, &COND_EXPR_COND (stmt), opf_none, &prev_vops);
834       break;
835
836     case SWITCH_EXPR:
837       get_expr_operands (stmt, &SWITCH_COND (stmt), opf_none, &prev_vops);
838       break;
839
840     case ASM_EXPR:
841       {
842         int noutputs = list_length (ASM_OUTPUTS (stmt));
843         const char **oconstraints
844           = (const char **) alloca ((noutputs) * sizeof (const char *));
845         int i;
846         tree link;
847         const char *constraint;
848         bool allows_mem, allows_reg, is_inout;
849
850         for (i=0, link = ASM_OUTPUTS (stmt); link;
851              ++i, link = TREE_CHAIN (link))
852           {
853             oconstraints[i] = constraint
854               = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (link)));
855             parse_output_constraint (&constraint, i, 0, 0,
856                                      &allows_mem, &allows_reg, &is_inout);
857             if (allows_reg && is_inout)
858               /* This should have been split in gimplify_asm_expr.  */
859               abort ();
860
861             if (!allows_reg && allows_mem)
862               {
863                 tree t = get_base_address (TREE_VALUE (link));
864                 if (t && DECL_P (t))
865                   mark_call_clobbered (t);
866               }
867
868             get_expr_operands (stmt, &TREE_VALUE (link), opf_is_def,
869                                &prev_vops);
870           }
871
872         for (link = ASM_INPUTS (stmt); link; link = TREE_CHAIN (link))
873           {
874             constraint
875               = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (link)));
876             parse_input_constraint (&constraint, 0, 0, noutputs, 0,
877                                     oconstraints, &allows_mem, &allows_reg);
878
879             if (!allows_reg && allows_mem)
880               {
881                 tree t = get_base_address (TREE_VALUE (link));
882                 if (t && DECL_P (t))
883                   mark_call_clobbered (t);
884               }
885
886             get_expr_operands (stmt, &TREE_VALUE (link), 0, &prev_vops);
887           }
888
889         /* Clobber memory for asm ("" : : : "memory");  */
890         for (link = ASM_CLOBBERS (stmt); link; link = TREE_CHAIN (link))
891           if (!strcmp (TREE_STRING_POINTER (TREE_VALUE (link)), "memory"))
892             add_call_clobber_ops (stmt, &prev_vops);
893       }
894       break;
895
896     case RETURN_EXPR:
897       get_expr_operands (stmt, &TREE_OPERAND (stmt, 0), opf_none, &prev_vops);
898       break;
899
900     case GOTO_EXPR:
901       get_expr_operands (stmt, &GOTO_DESTINATION (stmt), opf_none, &prev_vops);
902       break;
903
904     case LABEL_EXPR:
905       get_expr_operands (stmt, &LABEL_EXPR_LABEL (stmt), opf_none, &prev_vops);
906       break;
907
908       /* These nodes contain no variable references.  */
909     case BIND_EXPR:
910     case CASE_LABEL_EXPR:
911     case TRY_CATCH_EXPR:
912     case TRY_FINALLY_EXPR:
913     case EH_FILTER_EXPR:
914     case CATCH_EXPR:
915     case RESX_EXPR:
916       break;
917
918     default:
919       /* Notice that if get_expr_operands tries to use &STMT as the operand
920          pointer (which may only happen for USE operands), we will abort in
921          append_use.  This default will handle statements like empty statements,
922          CALL_EXPRs or VA_ARG_EXPRs that may appear on the RHS of a statement
923          or as statements themselves.  */
924       get_expr_operands (stmt, &stmt, opf_none, &prev_vops);
925       break;
926     }
927
928   finalize_ssa_stmt_operands (stmt);
929
930   /* Now free the previous virtual ops to memory.  */
931   free_v_may_defs (&(prev_vops.v_may_def_ops), true);
932   free_vuses (&(prev_vops.vuse_ops), true);
933   free_v_must_defs (&(prev_vops.v_must_def_ops), true);
934
935   /* Clear the modified bit for STMT.  Subsequent calls to
936      get_stmt_operands for this statement will do nothing until the
937      statement is marked modified by a call to modify_stmt().  */
938   ann->modified = 0;
939
940   timevar_pop (TV_TREE_OPS);
941 }
942
943
944 /* Recursively scan the expression pointed by EXPR_P in statement STMT.
945    FLAGS is one of the OPF_* constants modifying how to interpret the
946    operands found.  PREV_VOPS is as in append_v_may_def and append_vuse.  */
947
948 static void
949 get_expr_operands (tree stmt, tree *expr_p, int flags, voperands_t prev_vops)
950 {
951   enum tree_code code;
952   char class;
953   tree expr = *expr_p;
954
955   if (expr == NULL || expr == error_mark_node)
956     return;
957
958   code = TREE_CODE (expr);
959   class = TREE_CODE_CLASS (code);
960
961   /* Expressions that make no memory references.  */
962   if (class == 'c'
963       || class == 't'
964       || code == BLOCK
965       || code == FUNCTION_DECL
966       || code == EXC_PTR_EXPR
967       || code == FILTER_EXPR
968       || code == LABEL_DECL)
969     return;
970
971   /* We could have the address of a component, array member, etc which
972      has interesting variable references.  */
973   if (code == ADDR_EXPR)
974     {
975       enum tree_code subcode = TREE_CODE (TREE_OPERAND (expr, 0));
976
977       /* Taking the address of a variable does not represent a
978          reference to it, but the fact that STMT takes its address will be
979          of interest to some passes (e.g. alias resolution).  */
980       add_stmt_operand (expr_p, stmt, 0, NULL);
981
982       /* If the address is invariant, there may be no interesting variable
983          references inside.  */
984       if (is_gimple_min_invariant (expr))
985         return;
986
987       /* There should be no VUSEs created, since the referenced objects are
988          not really accessed.  The only operands that we should find here
989          are ARRAY_REF indices which will always be real operands (GIMPLE
990          does not allow non-registers as array indices).  */
991       flags |= opf_no_vops;
992
993       /* Avoid recursion.  */
994       code = subcode;
995       class = TREE_CODE_CLASS (code);
996       expr_p = &TREE_OPERAND (expr, 0);
997       expr = *expr_p;
998     }
999
1000   /* If we found a variable, add it to DEFS or USES depending on the
1001      operand flags.  */
1002   if (SSA_VAR_P (expr))
1003     {
1004       add_stmt_operand (expr_p, stmt, flags, prev_vops);
1005       return;
1006     }
1007
1008   /* Pointer dereferences always represent a use of the base pointer.  */
1009   if (code == INDIRECT_REF)
1010     {
1011       tree *pptr = &TREE_OPERAND (expr, 0);
1012       tree ptr = *pptr;
1013
1014       if (SSA_VAR_P (ptr))
1015         {
1016           if (!aliases_computed_p)
1017             {
1018               /* If the pointer does not have a memory tag and aliases have not
1019                  been computed yet, mark the statement as having volatile
1020                  operands to prevent DOM from entering it in equivalence tables
1021                  and DCE from killing it.  */
1022               stmt_ann (stmt)->has_volatile_ops = true;
1023             }
1024           else
1025             {
1026               struct ptr_info_def *pi = NULL;
1027
1028               /* If we have computed aliasing already, check if PTR has
1029                  flow-sensitive points-to information.  */
1030               if (TREE_CODE (ptr) == SSA_NAME
1031                   && (pi = SSA_NAME_PTR_INFO (ptr)) != NULL
1032                   && pi->name_mem_tag)
1033                 {
1034                   /* PTR has its own memory tag.  Use it.  */
1035                   add_stmt_operand (&pi->name_mem_tag, stmt, flags,
1036                                     prev_vops);
1037                 }
1038               else
1039                 {
1040                   /* If PTR is not an SSA_NAME or it doesn't have a name
1041                      tag, use its type memory tag.  */
1042                   var_ann_t ann;
1043
1044                   /* If we are emitting debugging dumps, display a warning if
1045                      PTR is an SSA_NAME with no flow-sensitive alias
1046                      information.  That means that we may need to compute
1047                      aliasing again.  */
1048                   if (dump_file
1049                       && TREE_CODE (ptr) == SSA_NAME
1050                       && pi == NULL)
1051                     {
1052                       fprintf (dump_file,
1053                           "NOTE: no flow-sensitive alias info for ");
1054                       print_generic_expr (dump_file, ptr, dump_flags);
1055                       fprintf (dump_file, " in ");
1056                       print_generic_stmt (dump_file, stmt, dump_flags);
1057                     }
1058
1059                   if (TREE_CODE (ptr) == SSA_NAME)
1060                     ptr = SSA_NAME_VAR (ptr);
1061                   ann = var_ann (ptr);
1062                   add_stmt_operand (&ann->type_mem_tag, stmt, flags, prev_vops);
1063                 }
1064             }
1065         }
1066
1067       /* If a constant is used as a pointer, we can't generate a real
1068          operand for it but we mark the statement volatile to prevent
1069          optimizations from messing things up.  */
1070       else if (TREE_CODE (ptr) == INTEGER_CST)
1071         {
1072           stmt_ann (stmt)->has_volatile_ops = true;
1073           return;
1074         }
1075
1076       /* Everything else *should* have been folded elsewhere, but users
1077          are smarter than we in finding ways to write invalid code.  We
1078          cannot just abort here.  If we were absolutely certain that we
1079          do handle all valid cases, then we could just do nothing here.
1080          That seems optimistic, so attempt to do something logical... */
1081       else if ((TREE_CODE (ptr) == PLUS_EXPR || TREE_CODE (ptr) == MINUS_EXPR)
1082                && TREE_CODE (TREE_OPERAND (ptr, 0)) == ADDR_EXPR
1083                && TREE_CODE (TREE_OPERAND (ptr, 1)) == INTEGER_CST)
1084         {
1085           /* Make sure we know the object is addressable.  */
1086           pptr = &TREE_OPERAND (ptr, 0);
1087           add_stmt_operand (pptr, stmt, 0, NULL);
1088
1089           /* Mark the object itself with a VUSE.  */
1090           pptr = &TREE_OPERAND (*pptr, 0);
1091           get_expr_operands (stmt, pptr, flags, prev_vops);
1092           return;
1093         }
1094
1095       /* Ok, this isn't even is_gimple_min_invariant.  Something's broke.  */
1096       else
1097         abort ();
1098
1099       /* Add a USE operand for the base pointer.  */
1100       get_expr_operands (stmt, pptr, opf_none, prev_vops);
1101       return;
1102     }
1103
1104   /* Treat array references as references to the virtual variable
1105      representing the array.  The virtual variable for an ARRAY_REF
1106      is the VAR_DECL for the array.  */
1107   if (code == ARRAY_REF)
1108     {
1109       /* Add the virtual variable for the ARRAY_REF to VDEFS or VUSES
1110          according to the value of IS_DEF.  Recurse if the LHS of the
1111          ARRAY_REF node is not a regular variable.  */
1112       if (SSA_VAR_P (TREE_OPERAND (expr, 0)))
1113         add_stmt_operand (expr_p, stmt, flags, prev_vops);
1114       else
1115         get_expr_operands (stmt, &TREE_OPERAND (expr, 0), flags, prev_vops);
1116
1117       get_expr_operands (stmt, &TREE_OPERAND (expr, 1), opf_none, prev_vops);
1118       return;
1119     }
1120
1121   /* Similarly to arrays, references to compound variables (complex types
1122      and structures/unions) are globbed.
1123
1124      FIXME: This means that
1125
1126                         a.x = 6;
1127                         a.y = 7;
1128                         foo (a.x, a.y);
1129
1130            will not be constant propagated because the two partial
1131            definitions to 'a' will kill each other.  Note that SRA may be
1132            able to fix this problem if 'a' can be scalarized.  */
1133   if (code == IMAGPART_EXPR || code == REALPART_EXPR || code == COMPONENT_REF)
1134     {
1135       /* If the LHS of the compound reference is not a regular variable,
1136          recurse to keep looking for more operands in the subexpression.  */
1137       if (SSA_VAR_P (TREE_OPERAND (expr, 0)))
1138         add_stmt_operand (expr_p, stmt, flags, prev_vops);
1139       else
1140         get_expr_operands (stmt, &TREE_OPERAND (expr, 0), flags, prev_vops);
1141
1142       return;
1143     }
1144
1145   /* Function calls.  Add every argument to USES.  If the callee is
1146      neither pure nor const, create a VDEF reference for GLOBAL_VAR
1147      (See find_vars_r).  */
1148   if (code == CALL_EXPR)
1149     {
1150       tree op;
1151       int call_flags = call_expr_flags (expr);
1152
1153       /* Find uses in the called function.  */
1154       get_expr_operands (stmt, &TREE_OPERAND (expr, 0), opf_none, prev_vops);
1155
1156       for (op = TREE_OPERAND (expr, 1); op; op = TREE_CHAIN (op))
1157         get_expr_operands (stmt, &TREE_VALUE (op), opf_none, prev_vops);
1158
1159       get_expr_operands (stmt, &TREE_OPERAND (expr, 2), opf_none, prev_vops);
1160
1161       if (bitmap_first_set_bit (call_clobbered_vars) >= 0)
1162         {
1163           /* A 'pure' or a 'const' functions never call clobber anything. 
1164              A 'noreturn' function might, but since we don't return anyway 
1165              there is no point in recording that.  */ 
1166           if (!(call_flags
1167                 & (ECF_PURE | ECF_CONST | ECF_NORETURN)))
1168             add_call_clobber_ops (stmt, prev_vops);
1169           else if (!(call_flags & (ECF_CONST | ECF_NORETURN)))
1170             add_call_read_ops (stmt, prev_vops);
1171         }
1172       else if (!aliases_computed_p)
1173         stmt_ann (stmt)->has_volatile_ops = true;
1174
1175       return;
1176     }
1177
1178   /* Lists.  */
1179   if (code == TREE_LIST)
1180     {
1181       tree op;
1182
1183       for (op = expr; op; op = TREE_CHAIN (op))
1184         get_expr_operands (stmt, &TREE_VALUE (op), flags, prev_vops);
1185
1186       return;
1187     }
1188
1189   /* Assignments.  */
1190   if (code == MODIFY_EXPR)
1191     {
1192       get_expr_operands (stmt, &TREE_OPERAND (expr, 1), opf_none, prev_vops);
1193       if (TREE_CODE (TREE_OPERAND (expr, 0)) == ARRAY_REF 
1194           || TREE_CODE (TREE_OPERAND (expr, 0)) == COMPONENT_REF
1195           || TREE_CODE (TREE_OPERAND (expr, 0)) == REALPART_EXPR
1196           || TREE_CODE (TREE_OPERAND (expr, 0)) == IMAGPART_EXPR)
1197         get_expr_operands (stmt, &TREE_OPERAND (expr, 0), opf_is_def, 
1198                            prev_vops);
1199       else
1200         get_expr_operands (stmt, &TREE_OPERAND (expr, 0), 
1201                            opf_is_def | opf_kill_def, prev_vops);
1202       return;
1203     }
1204
1205
1206   /* Mark VA_ARG_EXPR nodes as making volatile references.  FIXME,
1207      this is needed because we currently do not gimplify VA_ARG_EXPR
1208      properly.  */
1209   if (code == VA_ARG_EXPR)
1210     {
1211       stmt_ann (stmt)->has_volatile_ops = true;
1212       return;
1213     }
1214
1215   /* Unary expressions.  */
1216   if (class == '1'
1217       || code == TRUTH_NOT_EXPR
1218       || code == BIT_FIELD_REF
1219       || code == CONSTRUCTOR)
1220     {
1221       get_expr_operands (stmt, &TREE_OPERAND (expr, 0), flags, prev_vops);
1222       return;
1223     }
1224
1225   /* Binary expressions.  */
1226   if (class == '2'
1227       || class == '<'
1228       || code == TRUTH_AND_EXPR
1229       || code == TRUTH_OR_EXPR
1230       || code == TRUTH_XOR_EXPR
1231       || code == COMPOUND_EXPR)
1232     {
1233       get_expr_operands (stmt, &TREE_OPERAND (expr, 0), flags, prev_vops);
1234       get_expr_operands (stmt, &TREE_OPERAND (expr, 1), flags, prev_vops);
1235       return;
1236     }
1237
1238   /* If we get here, something has gone wrong.  */
1239   fprintf (stderr, "unhandled expression in get_expr_operands():\n");
1240   debug_tree (expr);
1241   fputs ("\n", stderr);
1242   abort ();
1243 }
1244
1245
1246 /* Add *VAR_P to the appropriate operand array of STMT.  FLAGS is as in
1247    get_expr_operands.  If *VAR_P is a GIMPLE register, it will be added to
1248    the statement's real operands, otherwise it is added to virtual
1249    operands.
1250
1251    PREV_VOPS is used when adding virtual operands to statements that
1252       already had them (See append_v_may_def and append_vuse).  */
1253
1254 static void
1255 add_stmt_operand (tree *var_p, tree stmt, int flags, voperands_t prev_vops)
1256 {
1257   bool is_real_op;
1258   tree var, sym;
1259   stmt_ann_t s_ann;
1260   var_ann_t v_ann;
1261
1262   var = *var_p;
1263   STRIP_NOPS (var);
1264
1265   s_ann = stmt_ann (stmt);
1266
1267   /* If the operand is an ADDR_EXPR, add its operand to the list of
1268      variables that have had their address taken in this statement.  */
1269   if (TREE_CODE (var) == ADDR_EXPR)
1270     {
1271       note_addressable (TREE_OPERAND (var, 0), s_ann);
1272       return;
1273     }
1274
1275   /* If the original variable is not a scalar, it will be added to the list
1276      of virtual operands.  In that case, use its base symbol as the virtual
1277      variable representing it.  */
1278   is_real_op = is_gimple_reg (var);
1279   if (!is_real_op && !DECL_P (var))
1280     var = get_virtual_var (var);
1281
1282   /* If VAR is not a variable that we care to optimize, do nothing.  */
1283   if (var == NULL_TREE || !SSA_VAR_P (var))
1284     return;
1285
1286   sym = (TREE_CODE (var) == SSA_NAME ? SSA_NAME_VAR (var) : var);
1287   v_ann = var_ann (sym);
1288
1289   /* FIXME: We currently refuse to optimize variables that have hidden uses
1290      (variables used in VLA declarations, MD builtin calls and variables
1291      from the parent function in nested functions).  This is because not
1292      all uses of these variables are exposed in the IL or the statements
1293      that reference them are not in GIMPLE form.  If that's the case, mark
1294      the statement as having volatile operands and return.  */
1295   if (v_ann->has_hidden_use)
1296     {
1297       s_ann->has_volatile_ops = true;
1298       return;
1299     }
1300
1301   /* Don't expose volatile variables to the optimizers.  */
1302   if (TREE_THIS_VOLATILE (sym))
1303     {
1304       s_ann->has_volatile_ops = true;
1305       return;
1306     }
1307
1308   if (is_real_op)
1309     {
1310       /* The variable is a GIMPLE register.  Add it to real operands.  */
1311       if (flags & opf_is_def)
1312         append_def (var_p, stmt);
1313       else
1314         append_use (var_p, stmt);
1315     }
1316   else
1317     {
1318       varray_type aliases;
1319
1320       /* The variable is not a GIMPLE register.  Add it (or its aliases) to
1321          virtual operands, unless the caller has specifically requested
1322          not to add virtual operands (used when adding operands inside an
1323          ADDR_EXPR expression).  */
1324       if (flags & opf_no_vops)
1325         return;
1326
1327       aliases = v_ann->may_aliases;
1328
1329       /* If alias information hasn't been computed yet, then
1330          addressable variables will not be an alias tag nor will they
1331          have aliases.  In this case, mark the statement as having
1332          volatile operands.  */
1333       if (!aliases_computed_p && may_be_aliased (var))
1334         s_ann->has_volatile_ops = true;
1335
1336       if (aliases == NULL)
1337         {
1338           /* The variable is not aliased or it is an alias tag.  */
1339           if (flags & opf_is_def)
1340             {
1341               if (v_ann->is_alias_tag)
1342                 {
1343                   /* Alias tagged vars get regular V_MAY_DEF  */
1344                   s_ann->makes_aliased_stores = 1;
1345                   append_v_may_def (var, stmt, prev_vops);
1346                 }
1347               else if ((flags & opf_kill_def) 
1348                         && v_ann->mem_tag_kind == NOT_A_TAG)
1349                 /* V_MUST_DEF for non-aliased non-GIMPLE register 
1350                    variable definitions. Avoid memory tags.  */
1351                 append_v_must_def (var, stmt, prev_vops);
1352               else
1353                 /* Call-clobbered variables & memory tags get 
1354                    V_MAY_DEF  */
1355                 append_v_may_def (var, stmt, prev_vops);
1356             }
1357           else
1358             {
1359               append_vuse (var, stmt, prev_vops);
1360               if (v_ann->is_alias_tag)
1361                 s_ann->makes_aliased_loads = 1;
1362             }
1363         }
1364       else
1365         {
1366           size_t i;
1367
1368           /* The variable is aliased.  Add its aliases to the virtual
1369              operands.  */
1370           if (VARRAY_ACTIVE_SIZE (aliases) == 0)
1371             abort ();
1372
1373           if (flags & opf_is_def)
1374             {
1375               /* If the variable is also an alias tag, add a virtual
1376                  operand for it, otherwise we will miss representing
1377                  references to the members of the variable's alias set.
1378                  This fixes the bug in gcc.c-torture/execute/20020503-1.c.  */
1379               if (v_ann->is_alias_tag)
1380                 append_v_may_def (var, stmt, prev_vops);
1381
1382               for (i = 0; i < VARRAY_ACTIVE_SIZE (aliases); i++)
1383                 append_v_may_def (VARRAY_TREE (aliases, i), stmt, prev_vops);
1384
1385               s_ann->makes_aliased_stores = 1;
1386             }
1387           else
1388             {
1389               if (v_ann->is_alias_tag)
1390                 append_vuse (var, stmt, prev_vops);
1391
1392               for (i = 0; i < VARRAY_ACTIVE_SIZE (aliases); i++)
1393                 append_vuse (VARRAY_TREE (aliases, i), stmt, prev_vops);
1394
1395               s_ann->makes_aliased_loads = 1;
1396             }
1397         }
1398     }
1399 }
1400
1401 /* Record that VAR had its address taken in the statement with annotations
1402    S_ANN.  */
1403
1404 static void
1405 note_addressable (tree var, stmt_ann_t s_ann)
1406 {
1407   var = get_base_address (var);
1408   if (var && SSA_VAR_P (var))
1409     {
1410       if (s_ann->addresses_taken == NULL)
1411         s_ann->addresses_taken = BITMAP_GGC_ALLOC ();
1412       bitmap_set_bit (s_ann->addresses_taken, var_ann (var)->uid);
1413     }
1414 }
1415
1416
1417 /* Add clobbering definitions for .GLOBAL_VAR or for each of the call
1418    clobbered variables in the function.  */
1419
1420 static void
1421 add_call_clobber_ops (tree stmt, voperands_t prev_vops)
1422 {
1423   /* Functions that are not const, pure or never return may clobber
1424      call-clobbered variables.  */
1425   stmt_ann (stmt)->makes_clobbering_call = true;
1426
1427   /* If we had created .GLOBAL_VAR earlier, use it.  Otherwise, add 
1428      a V_MAY_DEF operand for every call clobbered variable.  See 
1429      compute_may_aliases for the heuristic used to decide whether 
1430      to create .GLOBAL_VAR or not.  */
1431   if (global_var)
1432     add_stmt_operand (&global_var, stmt, opf_is_def, prev_vops);
1433   else
1434     {
1435       size_t i;
1436
1437       EXECUTE_IF_SET_IN_BITMAP (call_clobbered_vars, 0, i,
1438         {
1439           tree var = referenced_var (i);
1440
1441           /* If VAR is read-only, don't add a V_MAY_DEF, just a 
1442              VUSE operand.  */
1443           if (!TREE_READONLY (var))
1444             add_stmt_operand (&var, stmt, opf_is_def, prev_vops);
1445           else
1446             add_stmt_operand (&var, stmt, opf_none, prev_vops);
1447         });
1448     }
1449 }
1450
1451
1452 /* Add VUSE operands for .GLOBAL_VAR or all call clobbered variables in the
1453    function.  */
1454
1455 static void
1456 add_call_read_ops (tree stmt, voperands_t prev_vops)
1457 {
1458   /* Otherwise, if the function is not pure, it may reference memory.  Add
1459      a VUSE for .GLOBAL_VAR if it has been created.  Otherwise, add a VUSE
1460      for each call-clobbered variable.  See add_referenced_var for the
1461      heuristic used to decide whether to create .GLOBAL_VAR.  */
1462   if (global_var)
1463     add_stmt_operand (&global_var, stmt, opf_none, prev_vops);
1464   else
1465     {
1466       size_t i;
1467
1468       EXECUTE_IF_SET_IN_BITMAP (call_clobbered_vars, 0, i,
1469         {
1470           tree var = referenced_var (i);
1471           add_stmt_operand (&var, stmt, opf_none, prev_vops);
1472         });
1473     }
1474 }
1475
1476 #include "gt-tree-ssa-operands.h"