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