OSDN Git Service

* gcc/ChangeLog: Fix ChangeLog.
[pf3gnuchains/gcc-fork.git] / gcc / tree-ssa-operands.c
1 /* SSA operands management for trees.
2    Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008
3    Free Software Foundation, Inc.
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
11
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3.  If not see
19 <http://www.gnu.org/licenses/>.  */
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 #include "toplev.h"
35 #include "langhooks.h"
36 #include "ipa-reference.h"
37
38 /* This file contains the code required to manage the operands cache of the 
39    SSA optimizer.  For every stmt, we maintain an operand cache in the stmt 
40    annotation.  This cache contains operands that will be of interest to 
41    optimizers and other passes wishing to manipulate the IL. 
42
43    The operand type are broken up into REAL and VIRTUAL operands.  The real 
44    operands are represented as pointers into the stmt's operand tree.  Thus 
45    any manipulation of the real operands will be reflected in the actual tree.
46    Virtual operands are represented solely in the cache, although the base 
47    variable for the SSA_NAME may, or may not occur in the stmt's tree.  
48    Manipulation of the virtual operands will not be reflected in the stmt tree.
49
50    The routines in this file are concerned with creating this operand cache 
51    from a stmt tree.
52
53    The operand tree is the parsed by the various get_* routines which look 
54    through the stmt tree for the occurrence of operands which may be of 
55    interest, and calls are made to the append_* routines whenever one is 
56    found.  There are 4 of these routines, each representing one of the 
57    4 types of operands. Defs, Uses, Virtual Uses, and Virtual May Defs.
58
59    The append_* routines check for duplication, and simply keep a list of 
60    unique objects for each operand type in the build_* extendable vectors.
61
62    Once the stmt tree is completely parsed, the finalize_ssa_operands() 
63    routine is called, which proceeds to perform the finalization routine 
64    on each of the 4 operand vectors which have been built up.
65
66    If the stmt had a previous operand cache, the finalization routines 
67    attempt to match up the new operands with the old ones.  If it's a perfect 
68    match, the old vector is simply reused.  If it isn't a perfect match, then 
69    a new vector is created and the new operands are placed there.  For 
70    virtual operands, if the previous cache had SSA_NAME version of a 
71    variable, and that same variable occurs in the same operands cache, then 
72    the new cache vector will also get the same SSA_NAME.
73
74    i.e., if a stmt had a VUSE of 'a_5', and 'a' occurs in the new
75    operand vector for VUSE, then the new vector will also be modified
76    such that it contains 'a_5' rather than 'a'.  */
77
78 /* Structure storing statistics on how many call clobbers we have, and
79    how many where avoided.  */
80
81 static struct 
82 {
83   /* Number of call-clobbered ops we attempt to add to calls in
84      add_call_clobbered_mem_symbols.  */
85   unsigned int clobbered_vars;
86
87   /* Number of write-clobbers (VDEFs) avoided by using
88      not_written information.  */
89   unsigned int static_write_clobbers_avoided;
90
91   /* Number of reads (VUSEs) avoided by using not_read information.  */
92   unsigned int static_read_clobbers_avoided;
93   
94   /* Number of write-clobbers avoided because the variable can't escape to
95      this call.  */
96   unsigned int unescapable_clobbers_avoided;
97
98   /* Number of read-only uses we attempt to add to calls in
99      add_call_read_mem_symbols.  */
100   unsigned int readonly_clobbers;
101
102   /* Number of read-only uses we avoid using not_read information.  */
103   unsigned int static_readonly_clobbers_avoided;
104 } clobber_stats;
105
106
107 /* Flags to describe operand properties in helpers.  */
108
109 /* By default, operands are loaded.  */
110 #define opf_use         0
111
112 /* Operand is the target of an assignment expression or a 
113    call-clobbered variable.  */
114 #define opf_def         (1 << 0)
115
116 /* No virtual operands should be created in the expression.  This is used
117    when traversing ADDR_EXPR nodes which have different semantics than
118    other expressions.  Inside an ADDR_EXPR node, the only operands that we
119    need to consider are indices into arrays.  For instance, &a.b[i] should
120    generate a USE of 'i' but it should not generate a VUSE for 'a' nor a
121    VUSE for 'b'.  */
122 #define opf_no_vops     (1 << 1)
123
124 /* Operand is an implicit reference.  This is used to distinguish
125    explicit assignments in the form of MODIFY_EXPR from
126    clobbering sites like function calls or ASM_EXPRs.  */
127 #define opf_implicit    (1 << 2)
128
129 /* Array for building all the def operands.  */
130 static VEC(tree,heap) *build_defs;
131
132 /* Array for building all the use operands.  */
133 static VEC(tree,heap) *build_uses;
134
135 /* The built VDEF operand.  */
136 static tree build_vdef;
137
138 /* The built VUSE operand.  */
139 static tree build_vuse;
140
141 /* Bitmap obstack for our datastructures that needs to survive across   
142    compilations of multiple functions.  */
143 static bitmap_obstack operands_bitmap_obstack;
144
145 static void get_expr_operands (gimple, tree *, int);
146
147 /* Number of functions with initialized ssa_operands.  */
148 static int n_initialized = 0;
149
150 /* Stack of statements to change.  Every call to
151    push_stmt_changes pushes the stmt onto the stack.  Calls to
152    pop_stmt_changes pop a stmt off of the stack and compute the set
153    of changes for the popped statement.  */
154 static VEC(gimple_p,heap) *scb_stack;
155
156 /* Return the DECL_UID of the base variable of T.  */
157
158 static inline unsigned
159 get_name_decl (const_tree t)
160 {
161   if (TREE_CODE (t) != SSA_NAME)
162     return DECL_UID (t);
163   else
164     return DECL_UID (SSA_NAME_VAR (t));
165 }
166
167
168 /*  Return true if the SSA operands cache is active.  */
169
170 bool
171 ssa_operands_active (void)
172 {
173   /* This function may be invoked from contexts where CFUN is NULL
174      (IPA passes), return false for now.  FIXME: operands may be
175      active in each individual function, maybe this function should
176      take CFUN as a parameter.  */
177   if (cfun == NULL)
178     return false;
179
180   return cfun->gimple_df && gimple_ssa_operands (cfun)->ops_active;
181 }
182
183  
184 /* Create the VOP variable, an artificial global variable to act as a
185    representative of all of the virtual operands FUD chain.  */
186
187 static void
188 create_vop_var (void)
189 {
190   tree global_var;
191
192   gcc_assert (cfun->gimple_df->vop == NULL_TREE);
193
194   global_var = build_decl (VAR_DECL, get_identifier (".MEM"),
195                            void_type_node);
196   DECL_ARTIFICIAL (global_var) = 1;
197   TREE_READONLY (global_var) = 0;
198   DECL_EXTERNAL (global_var) = 1;
199   TREE_STATIC (global_var) = 1;
200   TREE_USED (global_var) = 1;
201   DECL_CONTEXT (global_var) = NULL_TREE;
202   TREE_THIS_VOLATILE (global_var) = 0;
203   TREE_ADDRESSABLE (global_var) = 0;
204
205   create_var_ann (global_var);
206   add_referenced_var (global_var);
207   cfun->gimple_df->vop = global_var;
208 }
209
210 /* These are the sizes of the operand memory buffer in bytes which gets
211    allocated each time more operands space is required.  The final value is
212    the amount that is allocated every time after that.
213    In 1k we can fit 25 use operands (or 63 def operands) on a host with
214    8 byte pointers, that would be 10 statements each with 1 def and 2
215    uses.  */
216   
217 #define OP_SIZE_INIT    0
218 #define OP_SIZE_1       (1024 - sizeof (void *))
219 #define OP_SIZE_2       (1024 * 4 - sizeof (void *))
220 #define OP_SIZE_3       (1024 * 16 - sizeof (void *))
221
222 /* Initialize the operand cache routines.  */
223
224 void
225 init_ssa_operands (void)
226 {
227   if (!n_initialized++)
228     {
229       build_defs = VEC_alloc (tree, heap, 5);
230       build_uses = VEC_alloc (tree, heap, 10);
231       build_vuse = NULL_TREE;
232       build_vdef = NULL_TREE;
233       bitmap_obstack_initialize (&operands_bitmap_obstack);
234       scb_stack = VEC_alloc (gimple_p, heap, 20);
235     }
236
237   gcc_assert (gimple_ssa_operands (cfun)->operand_memory == NULL);
238   gimple_ssa_operands (cfun)->operand_memory_index
239      = gimple_ssa_operands (cfun)->ssa_operand_mem_size;
240   gimple_ssa_operands (cfun)->ops_active = true;
241   memset (&clobber_stats, 0, sizeof (clobber_stats));
242   gimple_ssa_operands (cfun)->ssa_operand_mem_size = OP_SIZE_INIT;
243   create_vop_var ();
244 }
245
246
247 /* Dispose of anything required by the operand routines.  */
248
249 void
250 fini_ssa_operands (void)
251 {
252   struct ssa_operand_memory_d *ptr;
253
254   if (!--n_initialized)
255     {
256       VEC_free (tree, heap, build_defs);
257       VEC_free (tree, heap, build_uses);
258       build_vdef = NULL_TREE;
259       build_vuse = NULL_TREE;
260
261       /* The change buffer stack had better be empty.  */
262       gcc_assert (VEC_length (gimple_p, scb_stack) == 0);
263       VEC_free (gimple_p, heap, scb_stack);
264       scb_stack = NULL;
265     }
266
267   gimple_ssa_operands (cfun)->free_defs = NULL;
268   gimple_ssa_operands (cfun)->free_uses = NULL;
269
270   while ((ptr = gimple_ssa_operands (cfun)->operand_memory) != NULL)
271     {
272       gimple_ssa_operands (cfun)->operand_memory
273         = gimple_ssa_operands (cfun)->operand_memory->next;
274       ggc_free (ptr);
275     }
276
277   gimple_ssa_operands (cfun)->ops_active = false;
278
279   if (!n_initialized)
280     bitmap_obstack_release (&operands_bitmap_obstack);
281
282   cfun->gimple_df->vop = NULL_TREE;
283
284   if (dump_file && (dump_flags & TDF_STATS))
285     {
286       fprintf (dump_file, "Original clobbered vars:           %d\n",
287                clobber_stats.clobbered_vars);
288       fprintf (dump_file, "Static write clobbers avoided:     %d\n",
289                clobber_stats.static_write_clobbers_avoided);
290       fprintf (dump_file, "Static read clobbers avoided:      %d\n",
291                clobber_stats.static_read_clobbers_avoided);
292       fprintf (dump_file, "Unescapable clobbers avoided:      %d\n",
293                clobber_stats.unescapable_clobbers_avoided);
294       fprintf (dump_file, "Original read-only clobbers:       %d\n",
295                clobber_stats.readonly_clobbers);
296       fprintf (dump_file, "Static read-only clobbers avoided: %d\n",
297                clobber_stats.static_readonly_clobbers_avoided);
298     }
299 }
300
301
302 /* Return memory for an operand of size SIZE.  */
303                                                                               
304 static inline void *
305 ssa_operand_alloc (unsigned size)
306 {
307   char *ptr;
308
309   gcc_assert (size == sizeof (struct use_optype_d)
310               || size == sizeof (struct def_optype_d));
311
312   if (gimple_ssa_operands (cfun)->operand_memory_index + size
313       >= gimple_ssa_operands (cfun)->ssa_operand_mem_size)
314     {
315       struct ssa_operand_memory_d *ptr;
316
317       switch (gimple_ssa_operands (cfun)->ssa_operand_mem_size)
318         {
319         case OP_SIZE_INIT:
320           gimple_ssa_operands (cfun)->ssa_operand_mem_size = OP_SIZE_1;
321           break;
322         case OP_SIZE_1:
323           gimple_ssa_operands (cfun)->ssa_operand_mem_size = OP_SIZE_2;
324           break;
325         case OP_SIZE_2:
326         case OP_SIZE_3:
327           gimple_ssa_operands (cfun)->ssa_operand_mem_size = OP_SIZE_3;
328           break;
329         default:
330           gcc_unreachable ();
331         }
332
333       ptr = (struct ssa_operand_memory_d *) 
334               ggc_alloc (sizeof (void *)
335                          + gimple_ssa_operands (cfun)->ssa_operand_mem_size);
336       ptr->next = gimple_ssa_operands (cfun)->operand_memory;
337       gimple_ssa_operands (cfun)->operand_memory = ptr;
338       gimple_ssa_operands (cfun)->operand_memory_index = 0;
339     }
340
341   ptr = &(gimple_ssa_operands (cfun)->operand_memory
342           ->mem[gimple_ssa_operands (cfun)->operand_memory_index]);
343   gimple_ssa_operands (cfun)->operand_memory_index += size;
344   return ptr;
345 }
346
347
348 /* Allocate a DEF operand.  */
349
350 static inline struct def_optype_d *
351 alloc_def (void)
352 {
353   struct def_optype_d *ret;
354   if (gimple_ssa_operands (cfun)->free_defs)
355     {
356       ret = gimple_ssa_operands (cfun)->free_defs;
357       gimple_ssa_operands (cfun)->free_defs
358         = gimple_ssa_operands (cfun)->free_defs->next;
359     }
360   else
361     ret = (struct def_optype_d *)
362           ssa_operand_alloc (sizeof (struct def_optype_d));
363   return ret;
364 }
365
366
367 /* Allocate a USE operand.  */
368
369 static inline struct use_optype_d *
370 alloc_use (void)
371 {
372   struct use_optype_d *ret;
373   if (gimple_ssa_operands (cfun)->free_uses)
374     {
375       ret = gimple_ssa_operands (cfun)->free_uses;
376       gimple_ssa_operands (cfun)->free_uses
377         = gimple_ssa_operands (cfun)->free_uses->next;
378     }
379   else
380     ret = (struct use_optype_d *)
381           ssa_operand_alloc (sizeof (struct use_optype_d));
382   return ret;
383 }
384
385
386 /* Adds OP to the list of defs after LAST.  */
387
388 static inline def_optype_p 
389 add_def_op (tree *op, def_optype_p last)
390 {
391   def_optype_p new_def;
392
393   new_def = alloc_def ();
394   DEF_OP_PTR (new_def) = op;
395   last->next = new_def;
396   new_def->next = NULL;
397   return new_def;
398 }
399
400
401 /* Adds OP to the list of uses of statement STMT after LAST.  */
402
403 static inline use_optype_p
404 add_use_op (gimple stmt, tree *op, use_optype_p last)
405 {
406   use_optype_p new_use;
407
408   new_use = alloc_use ();
409   USE_OP_PTR (new_use)->use = op;
410   link_imm_use_stmt (USE_OP_PTR (new_use), *op, stmt);
411   last->next = new_use;
412   new_use->next = NULL;
413   return new_use;
414 }
415
416
417
418 /* Takes elements from build_defs and turns them into def operands of STMT.
419    TODO -- Make build_defs VEC of tree *.  */
420
421 static inline void
422 finalize_ssa_defs (gimple stmt)
423 {
424   unsigned new_i;
425   struct def_optype_d new_list;
426   def_optype_p old_ops, last;
427   unsigned int num = VEC_length (tree, build_defs);
428
429   /* There should only be a single real definition per assignment.  */
430   gcc_assert ((stmt && gimple_code (stmt) != GIMPLE_ASSIGN) || num <= 1);
431
432   /* Pre-pend the vdef we may have built.  */
433   if (build_vdef != NULL_TREE)
434     {
435       tree oldvdef = gimple_vdef (stmt);
436       if (oldvdef
437           && TREE_CODE (oldvdef) == SSA_NAME)
438         oldvdef = SSA_NAME_VAR (oldvdef);
439       if (oldvdef != build_vdef)
440         gimple_set_vdef (stmt, build_vdef);
441       VEC_safe_insert (tree, heap, build_defs, 0, (tree)gimple_vdef_ptr (stmt));
442       ++num;
443     }
444
445   new_list.next = NULL;
446   last = &new_list;
447
448   old_ops = gimple_def_ops (stmt);
449
450   new_i = 0;
451
452   /* Clear and unlink a no longer necessary VDEF.  */
453   if (build_vdef == NULL_TREE
454       && gimple_vdef (stmt) != NULL_TREE)
455     {
456       if (TREE_CODE (gimple_vdef (stmt)) == SSA_NAME)
457         {
458           unlink_stmt_vdef (stmt);
459           release_ssa_name (gimple_vdef (stmt));
460         }
461       gimple_set_vdef (stmt, NULL_TREE);
462     }
463
464   /* If we have a non-SSA_NAME VDEF, mark it for renaming.  */
465   if (gimple_vdef (stmt)
466       && TREE_CODE (gimple_vdef (stmt)) != SSA_NAME)
467     mark_sym_for_renaming (gimple_vdef (stmt));
468
469   /* Check for the common case of 1 def that hasn't changed.  */
470   if (old_ops && old_ops->next == NULL && num == 1
471       && (tree *) VEC_index (tree, build_defs, 0) == DEF_OP_PTR (old_ops))
472     return;
473
474   /* If there is anything in the old list, free it.  */
475   if (old_ops)
476     {
477       old_ops->next = gimple_ssa_operands (cfun)->free_defs;
478       gimple_ssa_operands (cfun)->free_defs = old_ops;
479     }
480
481   /* If there is anything remaining in the build_defs list, simply emit it.  */
482   for ( ; new_i < num; new_i++)
483     last = add_def_op ((tree *) VEC_index (tree, build_defs, new_i), last);
484
485   /* Now set the stmt's operands.  */
486   gimple_set_def_ops (stmt, new_list.next);
487 }
488
489
490 /* Takes elements from build_uses and turns them into use operands of STMT.
491    TODO -- Make build_uses VEC of tree *.  */
492
493 static inline void
494 finalize_ssa_uses (gimple stmt)
495 {
496   unsigned new_i;
497   struct use_optype_d new_list;
498   use_optype_p old_ops, ptr, last;
499
500   /* Pre-pend the VUSE we may have built.  */
501   if (build_vuse != NULL_TREE)
502     {
503       tree oldvuse = gimple_vuse (stmt);
504       if (oldvuse
505           && TREE_CODE (oldvuse) == SSA_NAME)
506         oldvuse = SSA_NAME_VAR (oldvuse);
507       if (oldvuse != (build_vuse != NULL_TREE
508                       ? build_vuse : build_vdef))
509         gimple_set_vuse (stmt, NULL_TREE);
510       VEC_safe_insert (tree, heap, build_uses, 0, (tree)gimple_vuse_ptr (stmt));
511     }
512
513   new_list.next = NULL;
514   last = &new_list;
515
516   old_ops = gimple_use_ops (stmt);
517
518   /* Clear a no longer necessary VUSE.  */
519   if (build_vuse == NULL_TREE
520       && gimple_vuse (stmt) != NULL_TREE)
521     gimple_set_vuse (stmt, NULL_TREE);
522
523   /* If there is anything in the old list, free it.  */
524   if (old_ops)
525     {
526       for (ptr = old_ops; ptr; ptr = ptr->next)
527         delink_imm_use (USE_OP_PTR (ptr));
528       old_ops->next = gimple_ssa_operands (cfun)->free_uses;
529       gimple_ssa_operands (cfun)->free_uses = old_ops;
530     }
531
532   /* If we added a VUSE, make sure to set the operand if it is not already
533      present and mark it for renaming.  */
534   if (build_vuse != NULL_TREE
535       && gimple_vuse (stmt) == NULL_TREE)
536     {
537       gimple_set_vuse (stmt, gimple_vop (cfun));
538       mark_sym_for_renaming (gimple_vop (cfun));
539     }
540
541   /* Now create nodes for all the new nodes.  */
542   for (new_i = 0; new_i < VEC_length (tree, build_uses); new_i++)
543     last = add_use_op (stmt, 
544                        (tree *) VEC_index (tree, build_uses, new_i), 
545                        last);
546
547   /* Now set the stmt's operands.  */
548   gimple_set_use_ops (stmt, new_list.next);
549 }
550
551
552 /* Clear the in_list bits and empty the build array for VDEFs and
553    VUSEs.  */
554
555 static inline void
556 cleanup_build_arrays (void)
557 {
558   build_vdef = NULL_TREE;
559   build_vuse = NULL_TREE;
560   VEC_truncate (tree, build_defs, 0);
561   VEC_truncate (tree, build_uses, 0);
562 }
563
564
565 /* Finalize all the build vectors, fill the new ones into INFO.  */
566                                                                               
567 static inline void
568 finalize_ssa_stmt_operands (gimple stmt)
569 {
570   finalize_ssa_defs (stmt);
571   finalize_ssa_uses (stmt);
572   cleanup_build_arrays ();
573 }
574
575
576 /* Start the process of building up operands vectors in INFO.  */
577
578 static inline void
579 start_ssa_stmt_operands (void)
580 {
581   gcc_assert (VEC_length (tree, build_defs) == 0);
582   gcc_assert (VEC_length (tree, build_uses) == 0);
583   gcc_assert (build_vuse == NULL_TREE);
584   gcc_assert (build_vdef == NULL_TREE);
585 }
586
587
588 /* Add DEF_P to the list of pointers to operands.  */
589
590 static inline void
591 append_def (tree *def_p)
592 {
593   VEC_safe_push (tree, heap, build_defs, (tree) def_p);
594 }
595
596
597 /* Add USE_P to the list of pointers to operands.  */
598
599 static inline void
600 append_use (tree *use_p)
601 {
602   VEC_safe_push (tree, heap, build_uses, (tree) use_p);
603 }
604
605
606 /* Add VAR to the set of variables that require a VDEF operator.  */
607
608 static inline void
609 append_vdef (tree var)
610 {
611   if (!optimize)
612     return;
613
614   gcc_assert ((build_vdef == NULL_TREE
615                || build_vdef == var)
616               && (build_vuse == NULL_TREE
617                   || build_vuse == var));
618
619   build_vdef = var;
620   build_vuse = var;
621 }
622
623
624 /* Add VAR to the set of variables that require a VUSE operator.  */
625
626 static inline void
627 append_vuse (tree var)
628 {
629   if (!optimize)
630     return;
631
632   gcc_assert (build_vuse == NULL_TREE
633               || build_vuse == var);
634
635   build_vuse = var;
636 }
637
638 /* Add virtual operands for STMT.  FLAGS is as in get_expr_operands.  */
639
640 static void
641 add_virtual_operand (gimple stmt ATTRIBUTE_UNUSED, int flags)
642 {
643   /* Add virtual operands to the stmt, unless the caller has specifically
644      requested not to do that (used when adding operands inside an
645      ADDR_EXPR expression).  */
646   if (flags & opf_no_vops)
647     return;
648
649   if (flags & opf_def)
650     append_vdef (gimple_vop (cfun));
651   else
652     append_vuse (gimple_vop (cfun));
653 }
654
655
656 /* Add *VAR_P to the appropriate operand array for statement STMT.
657    FLAGS is as in get_expr_operands.  If *VAR_P is a GIMPLE register,
658    it will be added to the statement's real operands, otherwise it is
659    added to virtual operands.  */
660
661 static void
662 add_stmt_operand (tree *var_p, gimple stmt, int flags)
663 {
664   tree var, sym;
665   var_ann_t v_ann;
666
667   gcc_assert (SSA_VAR_P (*var_p));
668
669   var = *var_p;
670   sym = (TREE_CODE (var) == SSA_NAME ? SSA_NAME_VAR (var) : var);
671   v_ann = var_ann (sym);
672
673   /* Mark statements with volatile operands.  */
674   if (TREE_THIS_VOLATILE (sym))
675     gimple_set_has_volatile_ops (stmt, true);
676
677   if (is_gimple_reg (sym))
678     {
679       /* The variable is a GIMPLE register.  Add it to real operands.  */
680       if (flags & opf_def)
681         append_def (var_p);
682       else
683         append_use (var_p);
684     }
685   else
686     add_virtual_operand (stmt, flags);
687 }
688
689 /* Add the base address of REF to SET.  */
690
691 static void
692 add_to_addressable_set (tree ref, bitmap *set)
693 {
694   tree var;
695
696   /* Note that it is *NOT OKAY* to use the target of a COMPONENT_REF
697      as the only thing we take the address of.  If VAR is a structure,
698      taking the address of a field means that the whole structure may
699      be referenced using pointer arithmetic.  See PR 21407 and the
700      ensuing mailing list discussion.  */
701   var = get_base_address (ref);
702   if (var && SSA_VAR_P (var))
703     {
704       if (*set == NULL)
705         *set = BITMAP_ALLOC (&operands_bitmap_obstack);
706
707       bitmap_set_bit (*set, DECL_UID (var));
708       TREE_ADDRESSABLE (var) = 1;
709     }
710 }
711
712 /* Add the base address of REF to the set of addresses taken by STMT.
713    REF may be a single variable whose address has been taken or any
714    other valid GIMPLE memory reference (structure reference, array,
715    etc).  If the base address of REF is a decl that has sub-variables,
716    also add all of its sub-variables.  */
717
718 static void
719 gimple_add_to_addresses_taken (gimple stmt, tree ref)
720 {
721   gcc_assert (gimple_has_ops (stmt));
722   add_to_addressable_set (ref, gimple_addresses_taken_ptr (stmt));
723 }
724
725
726 /* A subroutine of get_expr_operands to handle INDIRECT_REF,
727    ALIGN_INDIRECT_REF and MISALIGNED_INDIRECT_REF.  
728
729    STMT is the statement being processed, EXPR is the INDIRECT_REF
730       that got us here.
731    
732    FLAGS is as in get_expr_operands.
733
734    RECURSE_ON_BASE should be set to true if we want to continue
735       calling get_expr_operands on the base pointer, and false if
736       something else will do it for us.  */
737
738 static void
739 get_indirect_ref_operands (gimple stmt, tree expr, int flags,
740                            bool recurse_on_base)
741 {
742   tree *pptr = &TREE_OPERAND (expr, 0);
743
744   if (TREE_THIS_VOLATILE (expr))
745     gimple_set_has_volatile_ops (stmt, true);
746
747   /* Add the VOP.  */
748   add_virtual_operand (stmt, flags);
749
750   /* If requested, add a USE operand for the base pointer.  */
751   if (recurse_on_base)
752     get_expr_operands (stmt, pptr, opf_use);
753 }
754
755
756 /* A subroutine of get_expr_operands to handle TARGET_MEM_REF.  */
757
758 static void
759 get_tmr_operands (gimple stmt, tree expr, int flags)
760 {
761   /* First record the real operands.  */
762   get_expr_operands (stmt, &TMR_BASE (expr), opf_use);
763   get_expr_operands (stmt, &TMR_INDEX (expr), opf_use);
764
765   if (TMR_SYMBOL (expr))
766     gimple_add_to_addresses_taken (stmt, TMR_SYMBOL (expr));
767
768   add_virtual_operand (stmt, flags);
769 }
770
771
772 /* If STMT is a call that may clobber globals and other symbols that
773    escape, add them to the VDEF/VUSE lists for it.  */
774
775 static void
776 maybe_add_call_vops (gimple stmt)
777 {
778   int call_flags = gimple_call_flags (stmt);
779
780   /* If aliases have been computed already, add VDEF or VUSE
781      operands for all the symbols that have been found to be
782      call-clobbered.  */
783   if (!(call_flags & ECF_NOVOPS))
784     {
785       /* A 'pure' or a 'const' function never call-clobbers anything. 
786          A 'noreturn' function might, but since we don't return anyway 
787          there is no point in recording that.  */ 
788       if (!(call_flags & (ECF_PURE | ECF_CONST | ECF_NORETURN)))
789         add_virtual_operand (stmt, opf_def);
790       else if (!(call_flags & ECF_CONST))
791         add_virtual_operand (stmt, opf_use);
792     }
793 }
794
795
796 /* Scan operands in the ASM_EXPR stmt referred to in INFO.  */
797
798 static void
799 get_asm_expr_operands (gimple stmt)
800 {
801   size_t i, noutputs;
802   const char **oconstraints;
803   const char *constraint;
804   bool allows_mem, allows_reg, is_inout;
805
806   noutputs = gimple_asm_noutputs (stmt);
807   oconstraints = (const char **) alloca ((noutputs) * sizeof (const char *));
808
809   /* Gather all output operands.  */
810   for (i = 0; i < gimple_asm_noutputs (stmt); i++)
811     {
812       tree link = gimple_asm_output_op (stmt, i);
813       constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (link)));
814       oconstraints[i] = constraint;
815       parse_output_constraint (&constraint, i, 0, 0, &allows_mem,
816                                &allows_reg, &is_inout);
817
818       /* This should have been split in gimplify_asm_expr.  */
819       gcc_assert (!allows_reg || !is_inout);
820
821       /* Memory operands are addressable.  Note that STMT needs the
822          address of this operand.  */
823       if (!allows_reg && allows_mem)
824         {
825           tree t = get_base_address (TREE_VALUE (link));
826           if (t && DECL_P (t))
827             gimple_add_to_addresses_taken (stmt, t);
828         }
829
830       get_expr_operands (stmt, &TREE_VALUE (link), opf_def);
831     }
832
833   /* Gather all input operands.  */
834   for (i = 0; i < gimple_asm_ninputs (stmt); i++)
835     {
836       tree link = gimple_asm_input_op (stmt, i);
837       constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (link)));
838       parse_input_constraint (&constraint, 0, 0, noutputs, 0, oconstraints,
839                               &allows_mem, &allows_reg);
840
841       /* Memory operands are addressable.  Note that STMT needs the
842          address of this operand.  */
843       if (!allows_reg && allows_mem)
844         {
845           tree t = get_base_address (TREE_VALUE (link));
846           if (t && DECL_P (t))
847             gimple_add_to_addresses_taken (stmt, t);
848         }
849
850       get_expr_operands (stmt, &TREE_VALUE (link), 0);
851     }
852
853   /* Clobber all memory and addressable symbols for asm ("" : : : "memory");  */
854   for (i = 0; i < gimple_asm_nclobbers (stmt); i++)
855     {
856       tree link = gimple_asm_clobber_op (stmt, i);
857       if (strcmp (TREE_STRING_POINTER (TREE_VALUE (link)), "memory") == 0)
858         {
859           add_virtual_operand (stmt, opf_def);
860           break;
861         }
862     }
863 }
864
865
866 /* Recursively scan the expression pointed to by EXPR_P in statement
867    STMT.  FLAGS is one of the OPF_* constants modifying how to
868    interpret the operands found.  */
869
870 static void
871 get_expr_operands (gimple stmt, tree *expr_p, int flags)
872 {
873   enum tree_code code;
874   enum tree_code_class codeclass;
875   tree expr = *expr_p;
876
877   if (expr == NULL)
878     return;
879
880   code = TREE_CODE (expr);
881   codeclass = TREE_CODE_CLASS (code);
882
883   switch (code)
884     {
885     case ADDR_EXPR:
886       /* Taking the address of a variable does not represent a
887          reference to it, but the fact that the statement takes its
888          address will be of interest to some passes (e.g. alias
889          resolution).  */
890       gimple_add_to_addresses_taken (stmt, TREE_OPERAND (expr, 0));
891
892       /* If the address is invariant, there may be no interesting
893          variable references inside.  */
894       if (is_gimple_min_invariant (expr))
895         return;
896
897       /* Otherwise, there may be variables referenced inside but there
898          should be no VUSEs created, since the referenced objects are
899          not really accessed.  The only operands that we should find
900          here are ARRAY_REF indices which will always be real operands
901          (GIMPLE does not allow non-registers as array indices).  */
902       flags |= opf_no_vops;
903       get_expr_operands (stmt, &TREE_OPERAND (expr, 0), flags);
904       return;
905
906     case SSA_NAME:
907      add_stmt_operand (expr_p, stmt, flags);
908      return;
909
910     case VAR_DECL:
911     case PARM_DECL:
912     case RESULT_DECL:
913       add_stmt_operand (expr_p, stmt, flags);
914       return;
915
916     case MISALIGNED_INDIRECT_REF:
917       get_expr_operands (stmt, &TREE_OPERAND (expr, 1), flags);
918       /* fall through */
919
920     case ALIGN_INDIRECT_REF:
921     case INDIRECT_REF:
922       get_indirect_ref_operands (stmt, expr, flags, true);
923       return;
924
925     case TARGET_MEM_REF:
926       get_tmr_operands (stmt, expr, flags);
927       return;
928
929     case ARRAY_REF:
930     case ARRAY_RANGE_REF:
931     case COMPONENT_REF:
932     case REALPART_EXPR:
933     case IMAGPART_EXPR:
934       {
935         tree ref;
936         HOST_WIDE_INT offset, size, maxsize;
937
938         if (TREE_THIS_VOLATILE (expr))
939           gimple_set_has_volatile_ops (stmt, true);
940
941         ref = get_ref_base_and_extent (expr, &offset, &size, &maxsize);
942         if (TREE_CODE (ref) == INDIRECT_REF)
943           {
944             get_indirect_ref_operands (stmt, ref, flags, false);
945             flags |= opf_no_vops;
946           }
947
948         get_expr_operands (stmt, &TREE_OPERAND (expr, 0), flags);
949         
950         if (code == COMPONENT_REF)
951           {
952             if (TREE_THIS_VOLATILE (TREE_OPERAND (expr, 1)))
953               gimple_set_has_volatile_ops (stmt, true);
954             get_expr_operands (stmt, &TREE_OPERAND (expr, 2), opf_use);
955           }
956         else if (code == ARRAY_REF || code == ARRAY_RANGE_REF)
957           {
958             get_expr_operands (stmt, &TREE_OPERAND (expr, 1), opf_use);
959             get_expr_operands (stmt, &TREE_OPERAND (expr, 2), opf_use);
960             get_expr_operands (stmt, &TREE_OPERAND (expr, 3), opf_use);
961           }
962
963         return;
964       }
965
966     case WITH_SIZE_EXPR:
967       /* WITH_SIZE_EXPR is a pass-through reference to its first argument,
968          and an rvalue reference to its second argument.  */
969       get_expr_operands (stmt, &TREE_OPERAND (expr, 1), opf_use);
970       get_expr_operands (stmt, &TREE_OPERAND (expr, 0), flags);
971       return;
972
973     case COND_EXPR:
974     case VEC_COND_EXPR:
975       get_expr_operands (stmt, &TREE_OPERAND (expr, 0), opf_use);
976       get_expr_operands (stmt, &TREE_OPERAND (expr, 1), opf_use);
977       get_expr_operands (stmt, &TREE_OPERAND (expr, 2), opf_use);
978       return;
979
980     case CONSTRUCTOR:
981       {
982         /* General aggregate CONSTRUCTORs have been decomposed, but they
983            are still in use as the COMPLEX_EXPR equivalent for vectors.  */
984         constructor_elt *ce;
985         unsigned HOST_WIDE_INT idx;
986
987         for (idx = 0;
988              VEC_iterate (constructor_elt, CONSTRUCTOR_ELTS (expr), idx, ce);
989              idx++)
990           get_expr_operands (stmt, &ce->value, opf_use);
991
992         return;
993       }
994
995     case BIT_FIELD_REF:
996       if (TREE_THIS_VOLATILE (expr))
997         gimple_set_has_volatile_ops (stmt, true);
998       /* FALLTHRU */
999
1000     case TRUTH_NOT_EXPR:
1001     case VIEW_CONVERT_EXPR:
1002     do_unary:
1003       get_expr_operands (stmt, &TREE_OPERAND (expr, 0), flags);
1004       return;
1005
1006     case TRUTH_AND_EXPR:
1007     case TRUTH_OR_EXPR:
1008     case TRUTH_XOR_EXPR:
1009     case COMPOUND_EXPR:
1010     case OBJ_TYPE_REF:
1011     case ASSERT_EXPR:
1012     do_binary:
1013       {
1014         get_expr_operands (stmt, &TREE_OPERAND (expr, 0), flags);
1015         get_expr_operands (stmt, &TREE_OPERAND (expr, 1), flags);
1016         return;
1017       }
1018
1019     case DOT_PROD_EXPR:
1020     case REALIGN_LOAD_EXPR:
1021       {
1022         get_expr_operands (stmt, &TREE_OPERAND (expr, 0), flags);
1023         get_expr_operands (stmt, &TREE_OPERAND (expr, 1), flags);
1024         get_expr_operands (stmt, &TREE_OPERAND (expr, 2), flags);
1025         return;
1026       }
1027
1028     case CHANGE_DYNAMIC_TYPE_EXPR:
1029       gcc_unreachable ();
1030
1031     case FUNCTION_DECL:
1032     case LABEL_DECL:
1033     case CONST_DECL:
1034     case CASE_LABEL_EXPR:
1035     case FILTER_EXPR:
1036     case EXC_PTR_EXPR:
1037       /* Expressions that make no memory references.  */
1038       return;
1039
1040     default:
1041       if (codeclass == tcc_unary)
1042         goto do_unary;
1043       if (codeclass == tcc_binary || codeclass == tcc_comparison)
1044         goto do_binary;
1045       if (codeclass == tcc_constant || codeclass == tcc_type)
1046         return;
1047     }
1048
1049   /* If we get here, something has gone wrong.  */
1050 #ifdef ENABLE_CHECKING
1051   fprintf (stderr, "unhandled expression in get_expr_operands():\n");
1052   debug_tree (expr);
1053   fputs ("\n", stderr);
1054 #endif
1055   gcc_unreachable ();
1056 }
1057
1058
1059 /* Parse STMT looking for operands.  When finished, the various
1060    build_* operand vectors will have potential operands in them.  */
1061
1062 static void
1063 parse_ssa_operands (gimple stmt)
1064 {
1065   enum gimple_code code = gimple_code (stmt);
1066
1067   if (code == GIMPLE_ASM)
1068     get_asm_expr_operands (stmt);
1069   else
1070     {
1071       size_t i, start = 0;
1072
1073       if (code == GIMPLE_ASSIGN || code == GIMPLE_CALL)
1074         {
1075           get_expr_operands (stmt, gimple_op_ptr (stmt, 0), opf_def);
1076           start = 1;
1077         }
1078
1079       for (i = start; i < gimple_num_ops (stmt); i++)
1080         get_expr_operands (stmt, gimple_op_ptr (stmt, i), opf_use);
1081
1082       /* Add call-clobbered operands, if needed.  */
1083       if (code == GIMPLE_CALL)
1084         maybe_add_call_vops (stmt);
1085     }
1086 }
1087
1088
1089 /* Create an operands cache for STMT.  */
1090
1091 static void
1092 build_ssa_operands (gimple stmt)
1093 {
1094   /* Initially assume that the statement has no volatile operands and
1095      makes no memory references.  */
1096   gimple_set_has_volatile_ops (stmt, false);
1097
1098   /* Just clear the bitmap so we don't end up reallocating it over and over.  */
1099   if (gimple_addresses_taken (stmt))
1100     bitmap_clear (gimple_addresses_taken (stmt));
1101
1102   start_ssa_stmt_operands ();
1103   parse_ssa_operands (stmt);
1104   finalize_ssa_stmt_operands (stmt);
1105 }
1106
1107
1108 /* Releases the operands of STMT back to their freelists, and clears
1109    the stmt operand lists.  */
1110
1111 void
1112 free_stmt_operands (gimple stmt)
1113 {
1114   def_optype_p defs = gimple_def_ops (stmt), last_def;
1115   use_optype_p uses = gimple_use_ops (stmt), last_use;
1116
1117   if (defs)
1118     {
1119       for (last_def = defs; last_def->next; last_def = last_def->next)
1120         continue;
1121       last_def->next = gimple_ssa_operands (cfun)->free_defs;
1122       gimple_ssa_operands (cfun)->free_defs = defs;
1123       gimple_set_def_ops (stmt, NULL);
1124     }
1125
1126   if (uses)
1127     {
1128       for (last_use = uses; last_use->next; last_use = last_use->next)
1129         delink_imm_use (USE_OP_PTR (last_use));
1130       delink_imm_use (USE_OP_PTR (last_use));
1131       last_use->next = gimple_ssa_operands (cfun)->free_uses;
1132       gimple_ssa_operands (cfun)->free_uses = uses;
1133       gimple_set_use_ops (stmt, NULL);
1134     }
1135
1136   if (gimple_has_ops (stmt))
1137     gimple_set_addresses_taken (stmt, NULL);
1138
1139   if (gimple_has_mem_ops (stmt))
1140     {
1141       gimple_set_vuse (stmt, NULL_TREE);
1142       gimple_set_vdef (stmt, NULL_TREE);
1143     }
1144 }
1145
1146
1147 /* Get the operands of statement STMT.  */
1148
1149 void
1150 update_stmt_operands (gimple stmt)
1151 {
1152   /* If update_stmt_operands is called before SSA is initialized, do
1153      nothing.  */
1154   if (!ssa_operands_active ())
1155     return;
1156
1157   timevar_push (TV_TREE_OPS);
1158
1159   gcc_assert (gimple_modified_p (stmt));
1160   build_ssa_operands (stmt);
1161   gimple_set_modified (stmt, false);
1162
1163   timevar_pop (TV_TREE_OPS);
1164 }
1165
1166
1167 /* Swap operands EXP0 and EXP1 in statement STMT.  No attempt is done
1168    to test the validity of the swap operation.  */
1169
1170 void
1171 swap_tree_operands (gimple stmt, tree *exp0, tree *exp1)
1172 {
1173   tree op0, op1;
1174   op0 = *exp0;
1175   op1 = *exp1;
1176
1177   /* If the operand cache is active, attempt to preserve the relative
1178      positions of these two operands in their respective immediate use
1179      lists.  */
1180   if (ssa_operands_active () && op0 != op1)
1181     {
1182       use_optype_p use0, use1, ptr;
1183       use0 = use1 = NULL;
1184
1185       /* Find the 2 operands in the cache, if they are there.  */
1186       for (ptr = gimple_use_ops (stmt); ptr; ptr = ptr->next)
1187         if (USE_OP_PTR (ptr)->use == exp0)
1188           {
1189             use0 = ptr;
1190             break;
1191           }
1192
1193       for (ptr = gimple_use_ops (stmt); ptr; ptr = ptr->next)
1194         if (USE_OP_PTR (ptr)->use == exp1)
1195           {
1196             use1 = ptr;
1197             break;
1198           }
1199
1200       /* If both uses don't have operand entries, there isn't much we can do
1201          at this point.  Presumably we don't need to worry about it.  */
1202       if (use0 && use1)
1203         {
1204           tree *tmp = USE_OP_PTR (use1)->use;
1205           USE_OP_PTR (use1)->use = USE_OP_PTR (use0)->use;
1206           USE_OP_PTR (use0)->use = tmp;
1207         }
1208     }
1209
1210   /* Now swap the data.  */
1211   *exp0 = op1;
1212   *exp1 = op0;
1213 }
1214
1215
1216 /* Scan the immediate_use list for VAR making sure its linked properly.
1217    Return TRUE if there is a problem and emit an error message to F.  */
1218
1219 bool
1220 verify_imm_links (FILE *f, tree var)
1221 {
1222   use_operand_p ptr, prev, list;
1223   int count;
1224
1225   gcc_assert (TREE_CODE (var) == SSA_NAME);
1226
1227   list = &(SSA_NAME_IMM_USE_NODE (var));
1228   gcc_assert (list->use == NULL);
1229
1230   if (list->prev == NULL)
1231     {
1232       gcc_assert (list->next == NULL);
1233       return false;
1234     }
1235
1236   prev = list;
1237   count = 0;
1238   for (ptr = list->next; ptr != list; )
1239     {
1240       if (prev != ptr->prev)
1241         goto error;
1242       
1243       if (ptr->use == NULL)
1244         goto error; /* 2 roots, or SAFE guard node.  */
1245       else if (*(ptr->use) != var)
1246         goto error;
1247
1248       prev = ptr;
1249       ptr = ptr->next;
1250
1251       /* Avoid infinite loops.  50,000,000 uses probably indicates a
1252          problem.  */
1253       if (count++ > 50000000)
1254         goto error;
1255     }
1256
1257   /* Verify list in the other direction.  */
1258   prev = list;
1259   for (ptr = list->prev; ptr != list; )
1260     {
1261       if (prev != ptr->next)
1262         goto error;
1263       prev = ptr;
1264       ptr = ptr->prev;
1265       if (count-- < 0)
1266         goto error;
1267     }
1268
1269   if (count != 0)
1270     goto error;
1271
1272   return false;
1273
1274  error:
1275   if (ptr->loc.stmt && gimple_modified_p (ptr->loc.stmt))
1276     {
1277       fprintf (f, " STMT MODIFIED. - <%p> ", (void *)ptr->loc.stmt);
1278       print_gimple_stmt (f, ptr->loc.stmt, 0, TDF_SLIM);
1279     }
1280   fprintf (f, " IMM ERROR : (use_p : tree - %p:%p)", (void *)ptr, 
1281            (void *)ptr->use);
1282   print_generic_expr (f, USE_FROM_PTR (ptr), TDF_SLIM);
1283   fprintf(f, "\n");
1284   return true;
1285 }
1286
1287
1288 /* Dump all the immediate uses to FILE.  */
1289
1290 void
1291 dump_immediate_uses_for (FILE *file, tree var)
1292 {
1293   imm_use_iterator iter;
1294   use_operand_p use_p;
1295
1296   gcc_assert (var && TREE_CODE (var) == SSA_NAME);
1297
1298   print_generic_expr (file, var, TDF_SLIM);
1299   fprintf (file, " : -->");
1300   if (has_zero_uses (var))
1301     fprintf (file, " no uses.\n");
1302   else
1303     if (has_single_use (var))
1304       fprintf (file, " single use.\n");
1305     else
1306       fprintf (file, "%d uses.\n", num_imm_uses (var));
1307
1308   FOR_EACH_IMM_USE_FAST (use_p, iter, var)
1309     {
1310       if (use_p->loc.stmt == NULL && use_p->use == NULL)
1311         fprintf (file, "***end of stmt iterator marker***\n");
1312       else
1313         if (!is_gimple_reg (USE_FROM_PTR (use_p)))
1314           print_gimple_stmt (file, USE_STMT (use_p), 0, TDF_VOPS|TDF_MEMSYMS);
1315         else
1316           print_gimple_stmt (file, USE_STMT (use_p), 0, TDF_SLIM);
1317     }
1318   fprintf(file, "\n");
1319 }
1320
1321
1322 /* Dump all the immediate uses to FILE.  */
1323
1324 void
1325 dump_immediate_uses (FILE *file)
1326 {
1327   tree var;
1328   unsigned int x;
1329
1330   fprintf (file, "Immediate_uses: \n\n");
1331   for (x = 1; x < num_ssa_names; x++)
1332     {
1333       var = ssa_name(x);
1334       if (!var)
1335         continue;
1336       dump_immediate_uses_for (file, var);
1337     }
1338 }
1339
1340
1341 /* Dump def-use edges on stderr.  */
1342
1343 void
1344 debug_immediate_uses (void)
1345 {
1346   dump_immediate_uses (stderr);
1347 }
1348
1349
1350 /* Dump def-use edges on stderr.  */
1351
1352 void
1353 debug_immediate_uses_for (tree var)
1354 {
1355   dump_immediate_uses_for (stderr, var);
1356 }
1357
1358
1359 /* Push *STMT_P on the SCB_STACK.  This function is deprecated, do not
1360    introduce new uses of it.  */
1361
1362 void
1363 push_stmt_changes (gimple *stmt_p)
1364 {
1365   gimple stmt = *stmt_p;
1366
1367   /* It makes no sense to keep track of PHI nodes.  */
1368   if (gimple_code (stmt) == GIMPLE_PHI)
1369     return;
1370
1371   VEC_safe_push (gimple_p, heap, scb_stack, stmt_p);
1372 }
1373
1374 /* Pop the top stmt from SCB_STACK and act on the differences between
1375    what was recorded by push_stmt_changes and the current state of
1376    the statement.  This function is deprecated, do not introduce
1377    new uses of it.  */
1378
1379 void
1380 pop_stmt_changes (gimple *stmt_p)
1381 {
1382   gimple *stmt2_p, stmt = *stmt_p;
1383
1384   /* It makes no sense to keep track of PHI nodes.  */
1385   if (gimple_code (stmt) == GIMPLE_PHI)
1386     return;
1387
1388   stmt2_p = VEC_pop (gimple_p, scb_stack);
1389   gcc_assert (stmt_p == stmt2_p);
1390
1391   /* Force an operand re-scan on the statement and mark any newly
1392      exposed variables.  This also will mark the virtual operand
1393      for renaming if necessary.  */
1394   update_stmt (stmt);
1395 }
1396
1397 /* Discard the topmost stmt from SCB_STACK.  This is useful
1398    when the caller realized that it did not actually modified the
1399    statement.  It avoids the expensive operand re-scan.
1400    This function is deprecated, do not introduce new uses of it.  */
1401
1402 void
1403 discard_stmt_changes (gimple *stmt_p)
1404 {
1405   gimple *stmt2_p, stmt = *stmt_p;
1406   
1407   /* It makes no sense to keep track of PHI nodes.  */
1408   if (gimple_code (stmt) == GIMPLE_PHI)
1409     return;
1410
1411   stmt2_p = VEC_pop (gimple_p, scb_stack);
1412   gcc_assert (stmt_p == stmt2_p);
1413 }
1414
1415 /* Unlink STMTs virtual definition from the IL by propagating its use.  */
1416
1417 void
1418 unlink_stmt_vdef (gimple stmt)
1419 {
1420   use_operand_p use_p;
1421   imm_use_iterator iter;
1422   gimple use_stmt;
1423   tree vdef = gimple_vdef (stmt);
1424
1425   if (!vdef
1426       || TREE_CODE (vdef) != SSA_NAME)
1427     return;
1428
1429   FOR_EACH_IMM_USE_STMT (use_stmt, iter, gimple_vdef (stmt))
1430     {
1431       FOR_EACH_IMM_USE_ON_STMT (use_p, iter)
1432         SET_USE (use_p, gimple_vuse (stmt));
1433     }
1434
1435   if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (gimple_vdef (stmt)))
1436     SSA_NAME_OCCURS_IN_ABNORMAL_PHI (gimple_vuse (stmt)) = 1;
1437 }
1438