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