1 /* SSA operands management for trees.
2 Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GCC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING. If not, write to
18 the Free Software Foundation, 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA. */
23 #include "coretypes.h"
28 #include "diagnostic.h"
29 #include "tree-flow.h"
30 #include "tree-inline.h"
31 #include "tree-pass.h"
35 #include "langhooks.h"
36 #include "ipa-reference.h"
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.
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.
50 The routines in this file are concerned with creating this operand cache
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 5 of these routines, each representing one of the
57 5 types of operands. Defs, Uses, Virtual Uses, Virtual May Defs, and
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.
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 5 operand vectors which have been built up.
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.
75 i.e., if a stmt had a VUSE of 'a_5', and 'a' occurs in the new operand
76 vector for VUSE, then the new vector will also be modified such that
77 it contains 'a_5' rather than 'a'.
82 /* Flags to describe operand properties in helpers. */
84 /* By default, operands are loaded. */
87 /* Operand is the target of an assignment expression or a
88 call-clobbered variable */
89 #define opf_is_def (1 << 0)
91 /* Operand is the target of an assignment expression. */
92 #define opf_kill_def (1 << 1)
94 /* No virtual operands should be created in the expression. This is used
95 when traversing ADDR_EXPR nodes which have different semantics than
96 other expressions. Inside an ADDR_EXPR node, the only operands that we
97 need to consider are indices into arrays. For instance, &a.b[i] should
98 generate a USE of 'i' but it should not generate a VUSE for 'a' nor a
100 #define opf_no_vops (1 << 2)
102 /* Operand is a "non-specific" kill for call-clobbers and such. This is used
103 to distinguish "reset the world" events from explicit MODIFY_EXPRs. */
104 #define opf_non_specific (1 << 3)
107 /* Array for building all the def operands. */
108 static VEC(tree
,heap
) *build_defs
;
110 /* Array for building all the use operands. */
111 static VEC(tree
,heap
) *build_uses
;
113 /* Array for building all the v_may_def operands. */
114 static VEC(tree
,heap
) *build_v_may_defs
;
116 /* Array for building all the vuse operands. */
117 static VEC(tree
,heap
) *build_vuses
;
119 /* Array for building all the v_must_def operands. */
120 static VEC(tree
,heap
) *build_v_must_defs
;
123 /* These arrays are the cached operand vectors for call clobbered calls. */
124 static bool ops_active
= false;
126 static GTY (()) struct ssa_operand_memory_d
*operand_memory
= NULL
;
127 static unsigned operand_memory_index
;
129 static void get_expr_operands (tree
, tree
*, int);
130 static void get_asm_expr_operands (tree
);
131 static void get_indirect_ref_operands (tree
, tree
, int);
132 static void get_tmr_operands (tree
, tree
, int);
133 static void get_call_expr_operands (tree
, tree
);
134 static inline void append_def (tree
*);
135 static inline void append_use (tree
*);
136 static void append_v_may_def (tree
);
137 static void append_v_must_def (tree
);
138 static void add_call_clobber_ops (tree
, tree
);
139 static void add_call_read_ops (tree
, tree
);
140 static void add_stmt_operand (tree
*, stmt_ann_t
, int);
141 static void build_ssa_operands (tree stmt
);
143 static def_optype_p free_defs
= NULL
;
144 static use_optype_p free_uses
= NULL
;
145 static vuse_optype_p free_vuses
= NULL
;
146 static maydef_optype_p free_maydefs
= NULL
;
147 static mustdef_optype_p free_mustdefs
= NULL
;
150 /* Return the DECL_UID of the base variable of T. */
152 static inline unsigned
153 get_name_decl (tree t
)
155 if (TREE_CODE (t
) != SSA_NAME
)
158 return DECL_UID (SSA_NAME_VAR (t
));
161 /* Comparison function for qsort used in operand_build_sort_virtual. */
164 operand_build_cmp (const void *p
, const void *q
)
166 tree e1
= *((const tree
*)p
);
167 tree e2
= *((const tree
*)q
);
170 u1
= get_name_decl (e1
);
171 u2
= get_name_decl (e2
);
173 /* We want to sort in ascending order. They can never be equal. */
174 #ifdef ENABLE_CHECKING
175 gcc_assert (u1
!= u2
);
177 return (u1
> u2
? 1 : -1);
180 /* Sort the virtual operands in LIST from lowest DECL_UID to highest. */
183 operand_build_sort_virtual (VEC(tree
,heap
) *list
)
185 int num
= VEC_length (tree
, list
);
190 if (get_name_decl (VEC_index (tree
, list
, 0))
191 > get_name_decl (VEC_index (tree
, list
, 1)))
193 /* Swap elements if in the wrong order. */
194 tree tmp
= VEC_index (tree
, list
, 0);
195 VEC_replace (tree
, list
, 0, VEC_index (tree
, list
, 1));
196 VEC_replace (tree
, list
, 1, tmp
);
200 /* There are 3 or more elements, call qsort. */
201 qsort (VEC_address (tree
, list
),
202 VEC_length (tree
, list
),
209 /* Return true if the ssa operands cache is active. */
212 ssa_operands_active (void)
217 /* Structure storing statistics on how many call clobbers we have, and
218 how many where avoided. */
221 /* Number of call-clobbered ops we attempt to add to calls in
222 add_call_clobber_ops. */
223 unsigned int clobbered_vars
;
225 /* Number of write-clobbers (v_may_defs) avoided by using
226 not_written information. */
227 unsigned int static_write_clobbers_avoided
;
229 /* Number of reads (vuses) avoided by using not_read
231 unsigned int static_read_clobbers_avoided
;
233 /* Number of write-clobbers avoided because the variable can't escape to
235 unsigned int unescapable_clobbers_avoided
;
237 /* Number of readonly uses we attempt to add to calls in
238 add_call_read_ops. */
239 unsigned int readonly_clobbers
;
241 /* Number of readonly uses we avoid using not_read information. */
242 unsigned int static_readonly_clobbers_avoided
;
245 /* Initialize the operand cache routines. */
248 init_ssa_operands (void)
250 build_defs
= VEC_alloc (tree
, heap
, 5);
251 build_uses
= VEC_alloc (tree
, heap
, 10);
252 build_vuses
= VEC_alloc (tree
, heap
, 25);
253 build_v_may_defs
= VEC_alloc (tree
, heap
, 25);
254 build_v_must_defs
= VEC_alloc (tree
, heap
, 25);
256 gcc_assert (operand_memory
== NULL
);
257 operand_memory_index
= SSA_OPERAND_MEMORY_SIZE
;
259 memset (&clobber_stats
, 0, sizeof (clobber_stats
));
264 /* Dispose of anything required by the operand routines. */
267 fini_ssa_operands (void)
269 struct ssa_operand_memory_d
*ptr
;
270 VEC_free (tree
, heap
, build_defs
);
271 VEC_free (tree
, heap
, build_uses
);
272 VEC_free (tree
, heap
, build_v_must_defs
);
273 VEC_free (tree
, heap
, build_v_may_defs
);
274 VEC_free (tree
, heap
, build_vuses
);
279 free_mustdefs
= NULL
;
280 while ((ptr
= operand_memory
) != NULL
)
282 operand_memory
= operand_memory
->next
;
288 if (dump_file
&& (dump_flags
& TDF_STATS
))
290 fprintf (dump_file
, "Original clobbered vars:%d\n", clobber_stats
.clobbered_vars
);
291 fprintf (dump_file
, "Static write clobbers avoided:%d\n", clobber_stats
.static_write_clobbers_avoided
);
292 fprintf (dump_file
, "Static read clobbers avoided:%d\n", clobber_stats
.static_read_clobbers_avoided
);
293 fprintf (dump_file
, "Unescapable clobbers avoided:%d\n", clobber_stats
.unescapable_clobbers_avoided
);
294 fprintf (dump_file
, "Original readonly clobbers:%d\n", clobber_stats
.readonly_clobbers
);
295 fprintf (dump_file
, "Static readonly clobbers avoided:%d\n", clobber_stats
.static_readonly_clobbers_avoided
);
300 /* Return memory for operands of SIZE chunks. */
303 ssa_operand_alloc (unsigned size
)
306 if (operand_memory_index
+ size
>= SSA_OPERAND_MEMORY_SIZE
)
308 struct ssa_operand_memory_d
*ptr
;
309 ptr
= GGC_NEW (struct ssa_operand_memory_d
);
310 ptr
->next
= operand_memory
;
311 operand_memory
= ptr
;
312 operand_memory_index
= 0;
314 ptr
= &(operand_memory
->mem
[operand_memory_index
]);
315 operand_memory_index
+= size
;
320 /* Make sure PTR is in the correct immediate use list. Since uses are simply
321 pointers into the stmt TREE, there is no way of telling if anyone has
322 changed what this pointer points to via TREE_OPERANDS (exp, 0) = <...>.
323 The contents are different, but the pointer is still the same. This
324 routine will check to make sure PTR is in the correct list, and if it isn't
325 put it in the correct list. We cannot simply check the previous node
326 because all nodes in the same stmt might have be changed. */
329 correct_use_link (use_operand_p ptr
, tree stmt
)
334 /* Fold_stmt () may have changed the stmt pointers. */
335 if (ptr
->stmt
!= stmt
)
341 /* Find the root element, making sure we skip any safe iterators. */
342 while (prev
->use
!= NULL
|| prev
->stmt
== NULL
)
345 /* Get the ssa_name of the list the node is in. */
347 /* If it's the right list, simply return. */
348 if (root
== *(ptr
->use
))
351 /* Its in the wrong list if we reach here. */
352 delink_imm_use (ptr
);
353 link_imm_use (ptr
, *(ptr
->use
));
357 /* This routine makes sure that PTR is in an immediate use list, and makes
358 sure the stmt pointer is set to the current stmt. Virtual uses do not need
359 the overhead of correct_use_link since they cannot be directly manipulated
360 like a real use can be. (They don't exist in the TREE_OPERAND nodes.) */
362 set_virtual_use_link (use_operand_p ptr
, tree stmt
)
364 /* Fold_stmt () may have changed the stmt pointers. */
365 if (ptr
->stmt
!= stmt
)
368 /* If this use isn't in a list, add it to the correct list. */
370 link_imm_use (ptr
, *(ptr
->use
));
375 #define FINALIZE_OPBUILD build_defs
376 #define FINALIZE_OPBUILD_BASE(I) (tree *)VEC_index (tree, \
378 #define FINALIZE_OPBUILD_ELEM(I) (tree *)VEC_index (tree, \
380 #define FINALIZE_FUNC finalize_ssa_def_ops
381 #define FINALIZE_ALLOC alloc_def
382 #define FINALIZE_FREE free_defs
383 #define FINALIZE_TYPE struct def_optype_d
384 #define FINALIZE_ELEM(PTR) ((PTR)->def_ptr)
385 #define FINALIZE_OPS DEF_OPS
386 #define FINALIZE_BASE(VAR) VAR
387 #define FINALIZE_BASE_TYPE tree *
388 #define FINALIZE_BASE_ZERO NULL
389 #define FINALIZE_INITIALIZE(PTR, VAL, STMT) FINALIZE_ELEM (PTR) = (VAL)
390 #include "tree-ssa-opfinalize.h"
393 /* This routine will create stmt operands for STMT from the def build list. */
396 finalize_ssa_defs (tree stmt
)
398 unsigned int num
= VEC_length (tree
, build_defs
);
399 /* There should only be a single real definition per assignment. */
400 gcc_assert ((stmt
&& TREE_CODE (stmt
) != MODIFY_EXPR
) || num
<= 1);
402 /* If there is an old list, often the new list is identical, or close, so
403 find the elements at the beginning that are the same as the vector. */
405 finalize_ssa_def_ops (stmt
);
406 VEC_truncate (tree
, build_defs
, 0);
409 #define FINALIZE_OPBUILD build_uses
410 #define FINALIZE_OPBUILD_BASE(I) (tree *)VEC_index (tree, \
412 #define FINALIZE_OPBUILD_ELEM(I) (tree *)VEC_index (tree, \
414 #define FINALIZE_FUNC finalize_ssa_use_ops
415 #define FINALIZE_ALLOC alloc_use
416 #define FINALIZE_FREE free_uses
417 #define FINALIZE_TYPE struct use_optype_d
418 #define FINALIZE_ELEM(PTR) ((PTR)->use_ptr.use)
419 #define FINALIZE_OPS USE_OPS
420 #define FINALIZE_USE_PTR(PTR) USE_OP_PTR (PTR)
421 #define FINALIZE_CORRECT_USE correct_use_link
422 #define FINALIZE_BASE(VAR) VAR
423 #define FINALIZE_BASE_TYPE tree *
424 #define FINALIZE_BASE_ZERO NULL
425 #define FINALIZE_INITIALIZE(PTR, VAL, STMT) \
426 (PTR)->use_ptr.use = (VAL); \
427 link_imm_use_stmt (&((PTR)->use_ptr), \
429 #include "tree-ssa-opfinalize.h"
431 /* Return a new use operand vector for STMT, comparing to OLD_OPS_P. */
434 finalize_ssa_uses (tree stmt
)
436 #ifdef ENABLE_CHECKING
439 unsigned num
= VEC_length (tree
, build_uses
);
441 /* If the pointer to the operand is the statement itself, something is
442 wrong. It means that we are pointing to a local variable (the
443 initial call to get_stmt_operands does not pass a pointer to a
445 for (x
= 0; x
< num
; x
++)
446 gcc_assert (*((tree
*)VEC_index (tree
, build_uses
, x
)) != stmt
);
449 finalize_ssa_use_ops (stmt
);
450 VEC_truncate (tree
, build_uses
, 0);
454 /* Return a new v_may_def operand vector for STMT, comparing to OLD_OPS_P. */
455 #define FINALIZE_OPBUILD build_v_may_defs
456 #define FINALIZE_OPBUILD_ELEM(I) VEC_index (tree, build_v_may_defs, (I))
457 #define FINALIZE_OPBUILD_BASE(I) get_name_decl (VEC_index (tree, \
458 build_v_may_defs, (I)))
459 #define FINALIZE_FUNC finalize_ssa_v_may_def_ops
460 #define FINALIZE_ALLOC alloc_maydef
461 #define FINALIZE_FREE free_maydefs
462 #define FINALIZE_TYPE struct maydef_optype_d
463 #define FINALIZE_ELEM(PTR) MAYDEF_RESULT (PTR)
464 #define FINALIZE_OPS MAYDEF_OPS
465 #define FINALIZE_USE_PTR(PTR) MAYDEF_OP_PTR (PTR)
466 #define FINALIZE_CORRECT_USE set_virtual_use_link
467 #define FINALIZE_BASE_ZERO 0
468 #define FINALIZE_BASE(VAR) get_name_decl (VAR)
469 #define FINALIZE_BASE_TYPE unsigned
470 #define FINALIZE_INITIALIZE(PTR, VAL, STMT) \
471 (PTR)->def_var = (VAL); \
472 (PTR)->use_var = (VAL); \
473 (PTR)->use_ptr.use = &((PTR)->use_var); \
474 link_imm_use_stmt (&((PTR)->use_ptr), \
476 #include "tree-ssa-opfinalize.h"
480 finalize_ssa_v_may_defs (tree stmt
)
482 finalize_ssa_v_may_def_ops (stmt
);
486 /* Clear the in_list bits and empty the build array for v_may_defs. */
489 cleanup_v_may_defs (void)
492 num
= VEC_length (tree
, build_v_may_defs
);
494 for (x
= 0; x
< num
; x
++)
496 tree t
= VEC_index (tree
, build_v_may_defs
, x
);
497 if (TREE_CODE (t
) != SSA_NAME
)
499 var_ann_t ann
= var_ann (t
);
500 ann
->in_v_may_def_list
= 0;
503 VEC_truncate (tree
, build_v_may_defs
, 0);
507 #define FINALIZE_OPBUILD build_vuses
508 #define FINALIZE_OPBUILD_ELEM(I) VEC_index (tree, build_vuses, (I))
509 #define FINALIZE_OPBUILD_BASE(I) get_name_decl (VEC_index (tree, \
511 #define FINALIZE_FUNC finalize_ssa_vuse_ops
512 #define FINALIZE_ALLOC alloc_vuse
513 #define FINALIZE_FREE free_vuses
514 #define FINALIZE_TYPE struct vuse_optype_d
515 #define FINALIZE_ELEM(PTR) VUSE_OP (PTR)
516 #define FINALIZE_OPS VUSE_OPS
517 #define FINALIZE_USE_PTR(PTR) VUSE_OP_PTR (PTR)
518 #define FINALIZE_CORRECT_USE set_virtual_use_link
519 #define FINALIZE_BASE_ZERO 0
520 #define FINALIZE_BASE(VAR) get_name_decl (VAR)
521 #define FINALIZE_BASE_TYPE unsigned
522 #define FINALIZE_INITIALIZE(PTR, VAL, STMT) \
523 (PTR)->use_var = (VAL); \
524 (PTR)->use_ptr.use = &((PTR)->use_var); \
525 link_imm_use_stmt (&((PTR)->use_ptr), \
527 #include "tree-ssa-opfinalize.h"
530 /* Return a new vuse operand vector, comparing to OLD_OPS_P. */
533 finalize_ssa_vuses (tree stmt
)
535 unsigned num
, num_v_may_defs
;
538 /* Remove superfluous VUSE operands. If the statement already has a
539 V_MAY_DEF operation for a variable 'a', then a VUSE for 'a' is not
540 needed because V_MAY_DEFs imply a VUSE of the variable. For instance,
541 suppose that variable 'a' is aliased:
544 # a_3 = V_MAY_DEF <a_2>
547 The VUSE <a_2> is superfluous because it is implied by the V_MAY_DEF
550 num
= VEC_length (tree
, build_vuses
);
551 num_v_may_defs
= VEC_length (tree
, build_v_may_defs
);
553 if (num
> 0 && num_v_may_defs
> 0)
555 for (vuse_index
= 0; vuse_index
< VEC_length (tree
, build_vuses
); )
558 vuse
= VEC_index (tree
, build_vuses
, vuse_index
);
559 if (TREE_CODE (vuse
) != SSA_NAME
)
561 var_ann_t ann
= var_ann (vuse
);
562 ann
->in_vuse_list
= 0;
563 if (ann
->in_v_may_def_list
)
565 VEC_ordered_remove (tree
, build_vuses
, vuse_index
);
573 /* Clear out the in_list bits. */
575 vuse_index
< VEC_length (tree
, build_vuses
);
578 tree t
= VEC_index (tree
, build_vuses
, vuse_index
);
579 if (TREE_CODE (t
) != SSA_NAME
)
581 var_ann_t ann
= var_ann (t
);
582 ann
->in_vuse_list
= 0;
586 finalize_ssa_vuse_ops (stmt
);
587 /* The v_may_def build vector wasn't cleaned up because we needed it. */
588 cleanup_v_may_defs ();
590 /* Free the vuses build vector. */
591 VEC_truncate (tree
, build_vuses
, 0);
595 /* Return a new v_must_def operand vector for STMT, comparing to OLD_OPS_P. */
597 #define FINALIZE_OPBUILD build_v_must_defs
598 #define FINALIZE_OPBUILD_ELEM(I) VEC_index (tree, build_v_must_defs, (I))
599 #define FINALIZE_OPBUILD_BASE(I) get_name_decl (VEC_index (tree, \
600 build_v_must_defs, (I)))
601 #define FINALIZE_FUNC finalize_ssa_v_must_def_ops
602 #define FINALIZE_ALLOC alloc_mustdef
603 #define FINALIZE_FREE free_mustdefs
604 #define FINALIZE_TYPE struct mustdef_optype_d
605 #define FINALIZE_ELEM(PTR) MUSTDEF_RESULT (PTR)
606 #define FINALIZE_OPS MUSTDEF_OPS
607 #define FINALIZE_USE_PTR(PTR) MUSTDEF_KILL_PTR (PTR)
608 #define FINALIZE_CORRECT_USE set_virtual_use_link
609 #define FINALIZE_BASE_ZERO 0
610 #define FINALIZE_BASE(VAR) get_name_decl (VAR)
611 #define FINALIZE_BASE_TYPE unsigned
612 #define FINALIZE_INITIALIZE(PTR, VAL, STMT) \
613 (PTR)->def_var = (VAL); \
614 (PTR)->kill_var = (VAL); \
615 (PTR)->use_ptr.use = &((PTR)->kill_var);\
616 link_imm_use_stmt (&((PTR)->use_ptr), \
618 #include "tree-ssa-opfinalize.h"
622 finalize_ssa_v_must_defs (tree stmt
)
624 /* In the presence of subvars, there may be more than one V_MUST_DEF per
625 statement (one for each subvar). It is a bit expensive to verify that
626 all must-defs in a statement belong to subvars if there is more than one
627 MUST-def, so we don't do it. Suffice to say, if you reach here without
628 having subvars, and have num >1, you have hit a bug. */
630 finalize_ssa_v_must_def_ops (stmt
);
631 VEC_truncate (tree
, build_v_must_defs
, 0);
635 /* Finalize all the build vectors, fill the new ones into INFO. */
638 finalize_ssa_stmt_operands (tree stmt
)
640 finalize_ssa_defs (stmt
);
641 finalize_ssa_uses (stmt
);
642 finalize_ssa_v_must_defs (stmt
);
643 finalize_ssa_v_may_defs (stmt
);
644 finalize_ssa_vuses (stmt
);
648 /* Start the process of building up operands vectors in INFO. */
651 start_ssa_stmt_operands (void)
653 gcc_assert (VEC_length (tree
, build_defs
) == 0);
654 gcc_assert (VEC_length (tree
, build_uses
) == 0);
655 gcc_assert (VEC_length (tree
, build_vuses
) == 0);
656 gcc_assert (VEC_length (tree
, build_v_may_defs
) == 0);
657 gcc_assert (VEC_length (tree
, build_v_must_defs
) == 0);
661 /* Add DEF_P to the list of pointers to operands. */
664 append_def (tree
*def_p
)
666 VEC_safe_push (tree
, heap
, build_defs
, (tree
)def_p
);
670 /* Add USE_P to the list of pointers to operands. */
673 append_use (tree
*use_p
)
675 VEC_safe_push (tree
, heap
, build_uses
, (tree
)use_p
);
679 /* Add a new virtual may def for variable VAR to the build array. */
682 append_v_may_def (tree var
)
684 if (TREE_CODE (var
) != SSA_NAME
)
686 var_ann_t ann
= get_var_ann (var
);
688 /* Don't allow duplicate entries. */
689 if (ann
->in_v_may_def_list
)
691 ann
->in_v_may_def_list
= 1;
694 VEC_safe_push (tree
, heap
, build_v_may_defs
, (tree
)var
);
698 /* Add VAR to the list of virtual uses. */
701 append_vuse (tree var
)
704 /* Don't allow duplicate entries. */
705 if (TREE_CODE (var
) != SSA_NAME
)
707 var_ann_t ann
= get_var_ann (var
);
709 if (ann
->in_vuse_list
|| ann
->in_v_may_def_list
)
711 ann
->in_vuse_list
= 1;
714 VEC_safe_push (tree
, heap
, build_vuses
, (tree
)var
);
718 /* Add VAR to the list of virtual must definitions for INFO. */
721 append_v_must_def (tree var
)
725 /* Don't allow duplicate entries. */
726 for (i
= 0; i
< VEC_length (tree
, build_v_must_defs
); i
++)
727 if (var
== VEC_index (tree
, build_v_must_defs
, i
))
730 VEC_safe_push (tree
, heap
, build_v_must_defs
, (tree
)var
);
734 /* Parse STMT looking for operands. OLD_OPS is the original stmt operand
735 cache for STMT, if it existed before. When finished, the various build_*
736 operand vectors will have potential operands. in them. */
739 parse_ssa_operands (tree stmt
)
743 code
= TREE_CODE (stmt
);
747 /* First get operands from the RHS. For the LHS, we use a V_MAY_DEF if
748 either only part of LHS is modified or if the RHS might throw,
749 otherwise, use V_MUST_DEF.
751 ??? If it might throw, we should represent somehow that it is killed
752 on the fallthrough path. */
754 tree lhs
= TREE_OPERAND (stmt
, 0);
755 int lhs_flags
= opf_is_def
;
757 get_expr_operands (stmt
, &TREE_OPERAND (stmt
, 1), opf_none
);
759 /* If the LHS is a VIEW_CONVERT_EXPR, it isn't changing whether
760 or not the entire LHS is modified; that depends on what's
761 inside the VIEW_CONVERT_EXPR. */
762 if (TREE_CODE (lhs
) == VIEW_CONVERT_EXPR
)
763 lhs
= TREE_OPERAND (lhs
, 0);
765 if (TREE_CODE (lhs
) != ARRAY_RANGE_REF
766 && TREE_CODE (lhs
) != BIT_FIELD_REF
)
767 lhs_flags
|= opf_kill_def
;
769 get_expr_operands (stmt
, &TREE_OPERAND (stmt
, 0), lhs_flags
);
774 get_expr_operands (stmt
, &COND_EXPR_COND (stmt
), opf_none
);
778 get_expr_operands (stmt
, &SWITCH_COND (stmt
), opf_none
);
782 get_asm_expr_operands (stmt
);
786 get_expr_operands (stmt
, &TREE_OPERAND (stmt
, 0), opf_none
);
790 get_expr_operands (stmt
, &GOTO_DESTINATION (stmt
), opf_none
);
794 get_expr_operands (stmt
, &LABEL_EXPR_LABEL (stmt
), opf_none
);
797 /* These nodes contain no variable references. */
799 case CASE_LABEL_EXPR
:
801 case TRY_FINALLY_EXPR
:
808 /* Notice that if get_expr_operands tries to use &STMT as the operand
809 pointer (which may only happen for USE operands), we will fail in
810 append_use. This default will handle statements like empty
811 statements, or CALL_EXPRs that may appear on the RHS of a statement
812 or as statements themselves. */
813 get_expr_operands (stmt
, &stmt
, opf_none
);
818 /* Create an operands cache for STMT. */
821 build_ssa_operands (tree stmt
)
823 stmt_ann_t ann
= get_stmt_ann (stmt
);
825 /* Initially assume that the statement has no volatile operands. */
827 ann
->has_volatile_ops
= false;
829 start_ssa_stmt_operands ();
831 parse_ssa_operands (stmt
);
832 operand_build_sort_virtual (build_vuses
);
833 operand_build_sort_virtual (build_v_may_defs
);
834 operand_build_sort_virtual (build_v_must_defs
);
836 finalize_ssa_stmt_operands (stmt
);
840 /* Free any operands vectors in OPS. */
842 free_ssa_operands (stmt_operands_p ops
)
846 ops
->maydef_ops
= NULL
;
847 ops
->mustdef_ops
= NULL
;
848 ops
->vuse_ops
= NULL
;
852 /* Get the operands of statement STMT. Note that repeated calls to
853 get_stmt_operands for the same statement will do nothing until the
854 statement is marked modified by a call to mark_stmt_modified(). */
857 update_stmt_operands (tree stmt
)
859 stmt_ann_t ann
= get_stmt_ann (stmt
);
860 /* If get_stmt_operands is called before SSA is initialized, dont
862 if (!ssa_operands_active ())
864 /* The optimizers cannot handle statements that are nothing but a
865 _DECL. This indicates a bug in the gimplifier. */
866 gcc_assert (!SSA_VAR_P (stmt
));
868 gcc_assert (ann
->modified
);
870 timevar_push (TV_TREE_OPS
);
872 build_ssa_operands (stmt
);
874 /* Clear the modified bit for STMT. Subsequent calls to
875 get_stmt_operands for this statement will do nothing until the
876 statement is marked modified by a call to mark_stmt_modified(). */
879 timevar_pop (TV_TREE_OPS
);
883 /* Copies virtual operands from SRC to DST. */
886 copy_virtual_operands (tree dest
, tree src
)
889 ssa_op_iter iter
, old_iter
;
890 use_operand_p use_p
, u2
;
891 def_operand_p def_p
, d2
;
893 build_ssa_operands (dest
);
895 /* Copy all the virtual fields. */
896 FOR_EACH_SSA_TREE_OPERAND (t
, src
, iter
, SSA_OP_VUSE
)
898 FOR_EACH_SSA_TREE_OPERAND (t
, src
, iter
, SSA_OP_VMAYDEF
)
899 append_v_may_def (t
);
900 FOR_EACH_SSA_TREE_OPERAND (t
, src
, iter
, SSA_OP_VMUSTDEF
)
901 append_v_must_def (t
);
903 if (VEC_length (tree
, build_vuses
) == 0
904 && VEC_length (tree
, build_v_may_defs
) == 0
905 && VEC_length (tree
, build_v_must_defs
) == 0)
908 /* Now commit the virtual operands to this stmt. */
909 finalize_ssa_v_must_defs (dest
);
910 finalize_ssa_v_may_defs (dest
);
911 finalize_ssa_vuses (dest
);
913 /* Finally, set the field to the same values as then originals. */
916 t
= op_iter_init_tree (&old_iter
, src
, SSA_OP_VUSE
);
917 FOR_EACH_SSA_USE_OPERAND (use_p
, dest
, iter
, SSA_OP_VUSE
)
919 gcc_assert (!op_iter_done (&old_iter
));
921 t
= op_iter_next_tree (&old_iter
);
923 gcc_assert (op_iter_done (&old_iter
));
925 op_iter_init_maydef (&old_iter
, src
, &u2
, &d2
);
926 FOR_EACH_SSA_MAYDEF_OPERAND (def_p
, use_p
, dest
, iter
)
928 gcc_assert (!op_iter_done (&old_iter
));
929 SET_USE (use_p
, USE_FROM_PTR (u2
));
930 SET_DEF (def_p
, DEF_FROM_PTR (d2
));
931 op_iter_next_maymustdef (&u2
, &d2
, &old_iter
);
933 gcc_assert (op_iter_done (&old_iter
));
935 op_iter_init_mustdef (&old_iter
, src
, &u2
, &d2
);
936 FOR_EACH_SSA_MUSTDEF_OPERAND (def_p
, use_p
, dest
, iter
)
938 gcc_assert (!op_iter_done (&old_iter
));
939 SET_USE (use_p
, USE_FROM_PTR (u2
));
940 SET_DEF (def_p
, DEF_FROM_PTR (d2
));
941 op_iter_next_maymustdef (&u2
, &d2
, &old_iter
);
943 gcc_assert (op_iter_done (&old_iter
));
948 /* Specifically for use in DOM's expression analysis. Given a store, we
949 create an artificial stmt which looks like a load from the store, this can
950 be used to eliminate redundant loads. OLD_OPS are the operands from the
951 store stmt, and NEW_STMT is the new load which represents a load of the
955 create_ssa_artficial_load_stmt (tree new_stmt
, tree old_stmt
)
963 ann
= get_stmt_ann (new_stmt
);
965 /* process the stmt looking for operands. */
966 start_ssa_stmt_operands ();
967 parse_ssa_operands (new_stmt
);
969 for (x
= 0; x
< VEC_length (tree
, build_vuses
); x
++)
971 tree t
= VEC_index (tree
, build_vuses
, x
);
972 if (TREE_CODE (t
) != SSA_NAME
)
974 var_ann_t ann
= var_ann (t
);
975 ann
->in_vuse_list
= 0;
979 for (x
= 0; x
< VEC_length (tree
, build_v_may_defs
); x
++)
981 tree t
= VEC_index (tree
, build_v_may_defs
, x
);
982 if (TREE_CODE (t
) != SSA_NAME
)
984 var_ann_t ann
= var_ann (t
);
985 ann
->in_v_may_def_list
= 0;
988 /* Remove any virtual operands that were found. */
989 VEC_truncate (tree
, build_v_may_defs
, 0);
990 VEC_truncate (tree
, build_v_must_defs
, 0);
991 VEC_truncate (tree
, build_vuses
, 0);
993 /* For each VDEF on the original statement, we want to create a
994 VUSE of the V_MAY_DEF result or V_MUST_DEF op on the new
996 FOR_EACH_SSA_TREE_OPERAND (op
, old_stmt
, iter
,
997 (SSA_OP_VMAYDEF
| SSA_OP_VMUSTDEF
))
1000 /* Now build the operands for this new stmt. */
1001 finalize_ssa_stmt_operands (new_stmt
);
1003 /* All uses in this fake stmt must not be in the immediate use lists. */
1004 FOR_EACH_SSA_USE_OPERAND (use_p
, new_stmt
, iter
, SSA_OP_ALL_USES
)
1005 delink_imm_use (use_p
);
1009 swap_tree_operands (tree stmt
, tree
*exp0
, tree
*exp1
)
1015 /* If the operand cache is active, attempt to preserve the relative positions
1016 of these two operands in their respective immediate use lists. */
1017 if (ssa_operands_active () && op0
!= op1
)
1019 use_optype_p use0
, use1
, ptr
;
1021 /* Find the 2 operands in the cache, if they are there. */
1022 for (ptr
= USE_OPS (stmt
); ptr
; ptr
= ptr
->next
)
1023 if (USE_OP_PTR (ptr
)->use
== exp0
)
1028 for (ptr
= USE_OPS (stmt
); ptr
; ptr
= ptr
->next
)
1029 if (USE_OP_PTR (ptr
)->use
== exp1
)
1034 /* If both uses don't have operand entries, there isn't much we can do
1035 at this point. Presumably we dont need to worry about it. */
1038 tree
*tmp
= USE_OP_PTR (use1
)->use
;
1039 USE_OP_PTR (use1
)->use
= USE_OP_PTR (use0
)->use
;
1040 USE_OP_PTR (use0
)->use
= tmp
;
1044 /* Now swap the data. */
1049 /* Recursively scan the expression pointed to by EXPR_P in statement referred
1050 to by INFO. FLAGS is one of the OPF_* constants modifying how to interpret
1051 the operands found. */
1054 get_expr_operands (tree stmt
, tree
*expr_p
, int flags
)
1056 enum tree_code code
;
1057 enum tree_code_class
class;
1058 tree expr
= *expr_p
;
1059 stmt_ann_t s_ann
= stmt_ann (stmt
);
1064 code
= TREE_CODE (expr
);
1065 class = TREE_CODE_CLASS (code
);
1070 /* Taking the address of a variable does not represent a
1071 reference to it, but the fact that the stmt takes its address will be
1072 of interest to some passes (e.g. alias resolution). */
1073 add_to_addressable_set (TREE_OPERAND (expr
, 0),
1074 &s_ann
->addresses_taken
);
1076 /* If the address is invariant, there may be no interesting variable
1077 references inside. */
1078 if (is_gimple_min_invariant (expr
))
1081 /* There should be no VUSEs created, since the referenced objects are
1082 not really accessed. The only operands that we should find here
1083 are ARRAY_REF indices which will always be real operands (GIMPLE
1084 does not allow non-registers as array indices). */
1085 flags
|= opf_no_vops
;
1087 get_expr_operands (stmt
, &TREE_OPERAND (expr
, 0), flags
);
1091 case STRUCT_FIELD_TAG
:
1092 case TYPE_MEMORY_TAG
:
1093 case NAME_MEMORY_TAG
:
1095 add_stmt_operand (expr_p
, s_ann
, flags
);
1104 /* Add the subvars for a variable if it has subvars, to DEFS or USES.
1105 Otherwise, add the variable itself.
1106 Whether it goes to USES or DEFS depends on the operand flags. */
1107 if (var_can_have_subvars (expr
)
1108 && (svars
= get_subvars_for_var (expr
)))
1111 for (sv
= svars
; sv
; sv
= sv
->next
)
1112 add_stmt_operand (&sv
->var
, s_ann
, flags
);
1116 add_stmt_operand (expr_p
, s_ann
, flags
);
1120 case MISALIGNED_INDIRECT_REF
:
1121 get_expr_operands (stmt
, &TREE_OPERAND (expr
, 1), flags
);
1124 case ALIGN_INDIRECT_REF
:
1126 get_indirect_ref_operands (stmt
, expr
, flags
);
1129 case TARGET_MEM_REF
:
1130 get_tmr_operands (stmt
, expr
, flags
);
1133 case ARRAY_RANGE_REF
:
1134 /* Treat array references as references to the virtual variable
1135 representing the array. The virtual variable for an ARRAY_REF
1136 is the VAR_DECL for the array. */
1138 /* Add the virtual variable for the ARRAY_REF to VDEFS or VUSES
1139 according to the value of IS_DEF. */
1140 get_expr_operands (stmt
, &TREE_OPERAND (expr
, 0), flags
);
1141 get_expr_operands (stmt
, &TREE_OPERAND (expr
, 1), opf_none
);
1142 get_expr_operands (stmt
, &TREE_OPERAND (expr
, 2), opf_none
);
1143 get_expr_operands (stmt
, &TREE_OPERAND (expr
, 3), opf_none
);
1152 HOST_WIDE_INT offset
, size
, maxsize
;
1154 /* This component ref becomes an access to all of the subvariables
1155 it can touch, if we can determine that, but *NOT* the real one.
1156 If we can't determine which fields we could touch, the recursion
1157 will eventually get to a variable and add *all* of its subvars, or
1158 whatever is the minimum correct subset. */
1160 ref
= get_ref_base_and_extent (expr
, &offset
, &size
, &maxsize
);
1161 if (SSA_VAR_P (ref
) && get_subvars_for_var (ref
))
1163 subvar_t svars
= get_subvars_for_var (ref
);
1165 for (sv
= svars
; sv
; sv
= sv
->next
)
1168 if (overlap_subvar (offset
, maxsize
, sv
, &exact
))
1170 int subvar_flags
= flags
;
1174 subvar_flags
&= ~opf_kill_def
;
1175 add_stmt_operand (&sv
->var
, s_ann
, subvar_flags
);
1179 flags
|= opf_no_vops
;
1182 /* Even if we found subvars above we need to ensure to see
1183 immediate uses for d in s.a[d]. In case of s.a having
1184 a subvar we'd miss it otherwise. */
1185 get_expr_operands (stmt
, &TREE_OPERAND (expr
, 0),
1186 flags
& ~opf_kill_def
);
1188 if (code
== COMPONENT_REF
)
1190 if (s_ann
&& TREE_THIS_VOLATILE (TREE_OPERAND (expr
, 1)))
1191 s_ann
->has_volatile_ops
= true;
1192 get_expr_operands (stmt
, &TREE_OPERAND (expr
, 2), opf_none
);
1194 else if (code
== ARRAY_REF
)
1196 get_expr_operands (stmt
, &TREE_OPERAND (expr
, 1), opf_none
);
1197 get_expr_operands (stmt
, &TREE_OPERAND (expr
, 2), opf_none
);
1198 get_expr_operands (stmt
, &TREE_OPERAND (expr
, 3), opf_none
);
1202 case WITH_SIZE_EXPR
:
1203 /* WITH_SIZE_EXPR is a pass-through reference to its first argument,
1204 and an rvalue reference to its second argument. */
1205 get_expr_operands (stmt
, &TREE_OPERAND (expr
, 1), opf_none
);
1206 get_expr_operands (stmt
, &TREE_OPERAND (expr
, 0), flags
);
1210 get_call_expr_operands (stmt
, expr
);
1215 get_expr_operands (stmt
, &TREE_OPERAND (expr
, 0), opf_none
);
1216 get_expr_operands (stmt
, &TREE_OPERAND (expr
, 1), opf_none
);
1217 get_expr_operands (stmt
, &TREE_OPERAND (expr
, 2), opf_none
);
1225 get_expr_operands (stmt
, &TREE_OPERAND (expr
, 1), opf_none
);
1227 op
= TREE_OPERAND (expr
, 0);
1228 if (TREE_CODE (op
) == WITH_SIZE_EXPR
)
1229 op
= TREE_OPERAND (expr
, 0);
1230 if (TREE_CODE (op
) == ARRAY_RANGE_REF
1231 || TREE_CODE (op
) == REALPART_EXPR
1232 || TREE_CODE (op
) == IMAGPART_EXPR
)
1233 subflags
= opf_is_def
;
1235 subflags
= opf_is_def
| opf_kill_def
;
1237 get_expr_operands (stmt
, &TREE_OPERAND (expr
, 0), subflags
);
1243 /* General aggregate CONSTRUCTORs have been decomposed, but they
1244 are still in use as the COMPLEX_EXPR equivalent for vectors. */
1245 constructor_elt
*ce
;
1246 unsigned HOST_WIDE_INT idx
;
1249 VEC_iterate (constructor_elt
, CONSTRUCTOR_ELTS (expr
), idx
, ce
);
1251 get_expr_operands (stmt
, &ce
->value
, opf_none
);
1256 case TRUTH_NOT_EXPR
:
1258 case VIEW_CONVERT_EXPR
:
1260 get_expr_operands (stmt
, &TREE_OPERAND (expr
, 0), flags
);
1263 case TRUTH_AND_EXPR
:
1265 case TRUTH_XOR_EXPR
:
1271 get_expr_operands (stmt
, &TREE_OPERAND (expr
, 0), flags
);
1272 get_expr_operands (stmt
, &TREE_OPERAND (expr
, 1), flags
);
1277 case REALIGN_LOAD_EXPR
:
1279 get_expr_operands (stmt
, &TREE_OPERAND (expr
, 0), flags
);
1280 get_expr_operands (stmt
, &TREE_OPERAND (expr
, 1), flags
);
1281 get_expr_operands (stmt
, &TREE_OPERAND (expr
, 2), flags
);
1294 case OMP_RETURN_EXPR
:
1299 /* Expressions that make no memory references. */
1303 if (class == tcc_unary
)
1305 if (class == tcc_binary
|| class == tcc_comparison
)
1307 if (class == tcc_constant
|| class == tcc_type
)
1311 /* If we get here, something has gone wrong. */
1312 #ifdef ENABLE_CHECKING
1313 fprintf (stderr
, "unhandled expression in get_expr_operands():\n");
1315 fputs ("\n", stderr
);
1316 internal_error ("internal error");
1322 /* Scan operands in the ASM_EXPR stmt referred to in INFO. */
1325 get_asm_expr_operands (tree stmt
)
1327 stmt_ann_t s_ann
= stmt_ann (stmt
);
1328 int noutputs
= list_length (ASM_OUTPUTS (stmt
));
1329 const char **oconstraints
1330 = (const char **) alloca ((noutputs
) * sizeof (const char *));
1333 const char *constraint
;
1334 bool allows_mem
, allows_reg
, is_inout
;
1336 for (i
=0, link
= ASM_OUTPUTS (stmt
); link
; ++i
, link
= TREE_CHAIN (link
))
1338 oconstraints
[i
] = constraint
1339 = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (link
)));
1340 parse_output_constraint (&constraint
, i
, 0, 0,
1341 &allows_mem
, &allows_reg
, &is_inout
);
1343 /* This should have been split in gimplify_asm_expr. */
1344 gcc_assert (!allows_reg
|| !is_inout
);
1346 /* Memory operands are addressable. Note that STMT needs the
1347 address of this operand. */
1348 if (!allows_reg
&& allows_mem
)
1350 tree t
= get_base_address (TREE_VALUE (link
));
1351 if (t
&& DECL_P (t
) && s_ann
)
1352 add_to_addressable_set (t
, &s_ann
->addresses_taken
);
1355 get_expr_operands (stmt
, &TREE_VALUE (link
), opf_is_def
);
1358 for (link
= ASM_INPUTS (stmt
); link
; link
= TREE_CHAIN (link
))
1361 = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (link
)));
1362 parse_input_constraint (&constraint
, 0, 0, noutputs
, 0,
1363 oconstraints
, &allows_mem
, &allows_reg
);
1365 /* Memory operands are addressable. Note that STMT needs the
1366 address of this operand. */
1367 if (!allows_reg
&& allows_mem
)
1369 tree t
= get_base_address (TREE_VALUE (link
));
1370 if (t
&& DECL_P (t
) && s_ann
)
1371 add_to_addressable_set (t
, &s_ann
->addresses_taken
);
1374 get_expr_operands (stmt
, &TREE_VALUE (link
), 0);
1378 /* Clobber memory for asm ("" : : : "memory"); */
1379 for (link
= ASM_CLOBBERS (stmt
); link
; link
= TREE_CHAIN (link
))
1380 if (strcmp (TREE_STRING_POINTER (TREE_VALUE (link
)), "memory") == 0)
1385 /* Clobber all call-clobbered variables (or .GLOBAL_VAR if we
1386 decided to group them). */
1388 add_stmt_operand (&global_var
, s_ann
, opf_is_def
);
1390 EXECUTE_IF_SET_IN_BITMAP (call_clobbered_vars
, 0, i
, bi
)
1392 tree var
= referenced_var (i
);
1393 add_stmt_operand (&var
, s_ann
, opf_is_def
| opf_non_specific
);
1396 /* Now clobber all addressables. */
1397 EXECUTE_IF_SET_IN_BITMAP (addressable_vars
, 0, i
, bi
)
1399 tree var
= referenced_var (i
);
1401 /* Subvars are explicitly represented in this list, so
1402 we don't need the original to be added to the clobber
1403 ops, but the original *will* be in this list because
1404 we keep the addressability of the original
1405 variable up-to-date so we don't screw up the rest of
1407 if (var_can_have_subvars (var
)
1408 && get_subvars_for_var (var
) != NULL
)
1411 add_stmt_operand (&var
, s_ann
, opf_is_def
| opf_non_specific
);
1418 /* A subroutine of get_expr_operands to handle INDIRECT_REF,
1419 ALIGN_INDIRECT_REF and MISALIGNED_INDIRECT_REF. */
1422 get_indirect_ref_operands (tree stmt
, tree expr
, int flags
)
1424 tree
*pptr
= &TREE_OPERAND (expr
, 0);
1426 stmt_ann_t s_ann
= stmt_ann (stmt
);
1428 /* Stores into INDIRECT_REF operands are never killing definitions. */
1429 flags
&= ~opf_kill_def
;
1431 if (SSA_VAR_P (ptr
))
1433 struct ptr_info_def
*pi
= NULL
;
1435 /* If PTR has flow-sensitive points-to information, use it. */
1436 if (TREE_CODE (ptr
) == SSA_NAME
1437 && (pi
= SSA_NAME_PTR_INFO (ptr
)) != NULL
1438 && pi
->name_mem_tag
)
1440 /* PTR has its own memory tag. Use it. */
1441 add_stmt_operand (&pi
->name_mem_tag
, s_ann
, flags
);
1445 /* If PTR is not an SSA_NAME or it doesn't have a name
1446 tag, use its type memory tag. */
1449 /* If we are emitting debugging dumps, display a warning if
1450 PTR is an SSA_NAME with no flow-sensitive alias
1451 information. That means that we may need to compute
1454 && TREE_CODE (ptr
) == SSA_NAME
1458 "NOTE: no flow-sensitive alias info for ");
1459 print_generic_expr (dump_file
, ptr
, dump_flags
);
1460 fprintf (dump_file
, " in ");
1461 print_generic_stmt (dump_file
, stmt
, dump_flags
);
1464 if (TREE_CODE (ptr
) == SSA_NAME
)
1465 ptr
= SSA_NAME_VAR (ptr
);
1466 v_ann
= var_ann (ptr
);
1467 if (v_ann
->type_mem_tag
)
1468 add_stmt_operand (&v_ann
->type_mem_tag
, s_ann
, flags
);
1472 /* If a constant is used as a pointer, we can't generate a real
1473 operand for it but we mark the statement volatile to prevent
1474 optimizations from messing things up. */
1475 else if (TREE_CODE (ptr
) == INTEGER_CST
)
1478 s_ann
->has_volatile_ops
= true;
1481 /* Ok, this isn't even is_gimple_min_invariant. Something's broke. */
1485 /* Add a USE operand for the base pointer. */
1486 get_expr_operands (stmt
, pptr
, opf_none
);
1489 /* A subroutine of get_expr_operands to handle TARGET_MEM_REF. */
1492 get_tmr_operands (tree stmt
, tree expr
, int flags
)
1494 tree tag
= TMR_TAG (expr
), ref
;
1495 HOST_WIDE_INT offset
, size
, maxsize
;
1497 stmt_ann_t s_ann
= stmt_ann (stmt
);
1499 /* First record the real operands. */
1500 get_expr_operands (stmt
, &TMR_BASE (expr
), opf_none
);
1501 get_expr_operands (stmt
, &TMR_INDEX (expr
), opf_none
);
1503 /* MEM_REFs should never be killing. */
1504 flags
&= ~opf_kill_def
;
1506 if (TMR_SYMBOL (expr
))
1508 stmt_ann_t ann
= stmt_ann (stmt
);
1509 add_to_addressable_set (TMR_SYMBOL (expr
), &ann
->addresses_taken
);
1514 /* Something weird, so ensure that we will be careful. */
1515 stmt_ann (stmt
)->has_volatile_ops
= true;
1521 get_expr_operands (stmt
, &tag
, flags
);
1525 ref
= get_ref_base_and_extent (tag
, &offset
, &size
, &maxsize
);
1526 gcc_assert (ref
!= NULL_TREE
);
1527 svars
= get_subvars_for_var (ref
);
1528 for (sv
= svars
; sv
; sv
= sv
->next
)
1531 if (overlap_subvar (offset
, maxsize
, sv
, &exact
))
1533 int subvar_flags
= flags
;
1534 if (!exact
|| size
!= maxsize
)
1535 subvar_flags
&= ~opf_kill_def
;
1536 add_stmt_operand (&sv
->var
, s_ann
, subvar_flags
);
1541 /* A subroutine of get_expr_operands to handle CALL_EXPR. */
1544 get_call_expr_operands (tree stmt
, tree expr
)
1547 int call_flags
= call_expr_flags (expr
);
1549 /* If aliases have been computed already, add V_MAY_DEF or V_USE
1550 operands for all the symbols that have been found to be
1553 Note that if aliases have not been computed, the global effects
1554 of calls will not be included in the SSA web. This is fine
1555 because no optimizer should run before aliases have been
1556 computed. By not bothering with virtual operands for CALL_EXPRs
1557 we avoid adding superfluous virtual operands, which can be a
1558 significant compile time sink (See PR 15855). */
1559 if (aliases_computed_p
1560 && !bitmap_empty_p (call_clobbered_vars
)
1561 && !(call_flags
& ECF_NOVOPS
))
1563 /* A 'pure' or a 'const' function never call-clobbers anything.
1564 A 'noreturn' function might, but since we don't return anyway
1565 there is no point in recording that. */
1566 if (TREE_SIDE_EFFECTS (expr
)
1567 && !(call_flags
& (ECF_PURE
| ECF_CONST
| ECF_NORETURN
)))
1568 add_call_clobber_ops (stmt
, get_callee_fndecl (expr
));
1569 else if (!(call_flags
& ECF_CONST
))
1570 add_call_read_ops (stmt
, get_callee_fndecl (expr
));
1573 /* Find uses in the called function. */
1574 get_expr_operands (stmt
, &TREE_OPERAND (expr
, 0), opf_none
);
1576 for (op
= TREE_OPERAND (expr
, 1); op
; op
= TREE_CHAIN (op
))
1577 get_expr_operands (stmt
, &TREE_VALUE (op
), opf_none
);
1579 get_expr_operands (stmt
, &TREE_OPERAND (expr
, 2), opf_none
);
1584 /* Add *VAR_P to the appropriate operand array for INFO. FLAGS is as in
1585 get_expr_operands. If *VAR_P is a GIMPLE register, it will be added to
1586 the statement's real operands, otherwise it is added to virtual
1590 add_stmt_operand (tree
*var_p
, stmt_ann_t s_ann
, int flags
)
1597 gcc_assert (SSA_VAR_P (var
));
1599 is_real_op
= is_gimple_reg (var
);
1600 /* If this is a real operand, the operand is either ssa name or decl.
1601 Virtual operands may only be decls. */
1602 gcc_assert (is_real_op
|| DECL_P (var
));
1604 sym
= (TREE_CODE (var
) == SSA_NAME
? SSA_NAME_VAR (var
) : var
);
1605 v_ann
= var_ann (sym
);
1607 /* Mark statements with volatile operands. Optimizers should back
1608 off from statements having volatile operands. */
1609 if (TREE_THIS_VOLATILE (sym
) && s_ann
)
1610 s_ann
->has_volatile_ops
= true;
1612 /* If the variable cannot be modified and this is a V_MAY_DEF change
1613 it into a VUSE. This happens when read-only variables are marked
1614 call-clobbered and/or aliased to writable variables. So we only
1615 check that this only happens on non-specific stores.
1617 Note that if this is a specific store, i.e. associated with a
1618 modify_expr, then we can't suppress the V_DEF, lest we run into
1619 validation problems.
1621 This can happen when programs cast away const, leaving us with a
1622 store to read-only memory. If the statement is actually executed
1623 at runtime, then the program is ill formed. If the statement is
1624 not executed then all is well. At the very least, we cannot ICE. */
1625 if ((flags
& opf_non_specific
) && unmodifiable_var_p (var
))
1627 gcc_assert (!is_real_op
);
1628 flags
&= ~(opf_is_def
| opf_kill_def
);
1633 /* The variable is a GIMPLE register. Add it to real operands. */
1634 if (flags
& opf_is_def
)
1641 VEC(tree
,gc
) *aliases
;
1643 /* The variable is not a GIMPLE register. Add it (or its aliases) to
1644 virtual operands, unless the caller has specifically requested
1645 not to add virtual operands (used when adding operands inside an
1646 ADDR_EXPR expression). */
1647 if (flags
& opf_no_vops
)
1650 aliases
= v_ann
->may_aliases
;
1652 if (aliases
== NULL
)
1654 /* The variable is not aliased or it is an alias tag. */
1655 if (flags
& opf_is_def
)
1657 if (flags
& opf_kill_def
)
1659 /* Only regular variables or struct fields may get a
1660 V_MUST_DEF operand. */
1661 gcc_assert (!MTAG_P (var
)
1662 || TREE_CODE (var
) == STRUCT_FIELD_TAG
);
1663 /* V_MUST_DEF for non-aliased, non-GIMPLE register
1664 variable definitions. */
1665 append_v_must_def (var
);
1669 /* Add a V_MAY_DEF for call-clobbered variables and
1671 append_v_may_def (var
);
1682 /* The variable is aliased. Add its aliases to the virtual
1684 gcc_assert (VEC_length (tree
, aliases
) != 0);
1686 if (flags
& opf_is_def
)
1688 /* If the variable is also an alias tag, add a virtual
1689 operand for it, otherwise we will miss representing
1690 references to the members of the variable's alias set.
1691 This fixes the bug in gcc.c-torture/execute/20020503-1.c. */
1692 if (v_ann
->is_alias_tag
)
1693 append_v_may_def (var
);
1695 for (i
= 0; VEC_iterate (tree
, aliases
, i
, al
); i
++)
1696 append_v_may_def (al
);
1700 /* Similarly, append a virtual uses for VAR itself, when
1701 it is an alias tag. */
1702 if (v_ann
->is_alias_tag
)
1705 for (i
= 0; VEC_iterate (tree
, aliases
, i
, al
); i
++)
1713 /* Add the base address of REF to the set *ADDRESSES_TAKEN. If
1714 *ADDRESSES_TAKEN is NULL, a new set is created. REF may be
1715 a single variable whose address has been taken or any other valid
1716 GIMPLE memory reference (structure reference, array, etc). If the
1717 base address of REF is a decl that has sub-variables, also add all
1718 of its sub-variables. */
1721 add_to_addressable_set (tree ref
, bitmap
*addresses_taken
)
1726 gcc_assert (addresses_taken
);
1728 /* Note that it is *NOT OKAY* to use the target of a COMPONENT_REF
1729 as the only thing we take the address of. If VAR is a structure,
1730 taking the address of a field means that the whole structure may
1731 be referenced using pointer arithmetic. See PR 21407 and the
1732 ensuing mailing list discussion. */
1733 var
= get_base_address (ref
);
1734 if (var
&& SSA_VAR_P (var
))
1736 if (*addresses_taken
== NULL
)
1737 *addresses_taken
= BITMAP_GGC_ALLOC ();
1739 if (var_can_have_subvars (var
)
1740 && (svars
= get_subvars_for_var (var
)))
1743 for (sv
= svars
; sv
; sv
= sv
->next
)
1745 bitmap_set_bit (*addresses_taken
, DECL_UID (sv
->var
));
1746 TREE_ADDRESSABLE (sv
->var
) = 1;
1751 bitmap_set_bit (*addresses_taken
, DECL_UID (var
));
1752 TREE_ADDRESSABLE (var
) = 1;
1757 /* Add clobbering definitions for .GLOBAL_VAR or for each of the call
1758 clobbered variables in the function. */
1761 add_call_clobber_ops (tree stmt
, tree callee
)
1765 stmt_ann_t s_ann
= stmt_ann (stmt
);
1766 bitmap not_read_b
, not_written_b
;
1768 /* Functions that are not const, pure or never return may clobber
1769 call-clobbered variables. */
1771 s_ann
->makes_clobbering_call
= true;
1773 /* If we created .GLOBAL_VAR earlier, just use it. See compute_may_aliases
1774 for the heuristic used to decide whether to create .GLOBAL_VAR or not. */
1777 add_stmt_operand (&global_var
, s_ann
, opf_is_def
);
1781 /* Get info for local and module level statics. There is a bit
1782 set for each static if the call being processed does not read
1783 or write that variable. */
1785 not_read_b
= callee
? ipa_reference_get_not_read_global (callee
) : NULL
;
1786 not_written_b
= callee
? ipa_reference_get_not_written_global (callee
) : NULL
;
1787 /* Add a V_MAY_DEF operand for every call clobbered variable. */
1788 EXECUTE_IF_SET_IN_BITMAP (call_clobbered_vars
, 0, u
, bi
)
1790 tree var
= referenced_var_lookup (u
);
1791 unsigned int escape_mask
= var_ann (var
)->escape_mask
;
1792 tree real_var
= var
;
1796 /* Not read and not written are computed on regular vars, not
1797 subvars, so look at the parent var if this is an SFT. */
1799 if (TREE_CODE (var
) == STRUCT_FIELD_TAG
)
1800 real_var
= SFT_PARENT_VAR (var
);
1802 not_read
= not_read_b
? bitmap_bit_p (not_read_b
,
1803 DECL_UID (real_var
)) : false;
1804 not_written
= not_written_b
? bitmap_bit_p (not_written_b
,
1805 DECL_UID (real_var
)) : false;
1806 gcc_assert (!unmodifiable_var_p (var
));
1808 clobber_stats
.clobbered_vars
++;
1810 /* See if this variable is really clobbered by this function. */
1812 /* Trivial case: Things escaping only to pure/const are not
1813 clobbered by non-pure-const, and only read by pure/const. */
1814 if ((escape_mask
& ~(ESCAPE_TO_PURE_CONST
)) == 0)
1816 tree call
= get_call_expr_in (stmt
);
1817 if (call_expr_flags (call
) & (ECF_CONST
| ECF_PURE
))
1819 add_stmt_operand (&var
, s_ann
, opf_none
);
1820 clobber_stats
.unescapable_clobbers_avoided
++;
1825 clobber_stats
.unescapable_clobbers_avoided
++;
1832 clobber_stats
.static_write_clobbers_avoided
++;
1834 add_stmt_operand (&var
, s_ann
, opf_none
);
1836 clobber_stats
.static_read_clobbers_avoided
++;
1839 add_stmt_operand (&var
, s_ann
, opf_is_def
);
1845 /* Add VUSE operands for .GLOBAL_VAR or all call clobbered variables in the
1849 add_call_read_ops (tree stmt
, tree callee
)
1853 stmt_ann_t s_ann
= stmt_ann (stmt
);
1856 /* if the function is not pure, it may reference memory. Add
1857 a VUSE for .GLOBAL_VAR if it has been created. See add_referenced_var
1858 for the heuristic used to decide whether to create .GLOBAL_VAR. */
1861 add_stmt_operand (&global_var
, s_ann
, opf_none
);
1865 not_read_b
= callee
? ipa_reference_get_not_read_global (callee
) : NULL
;
1867 /* Add a VUSE for each call-clobbered variable. */
1868 EXECUTE_IF_SET_IN_BITMAP (call_clobbered_vars
, 0, u
, bi
)
1870 tree var
= referenced_var (u
);
1871 tree real_var
= var
;
1874 clobber_stats
.readonly_clobbers
++;
1876 /* Not read and not written are computed on regular vars, not
1877 subvars, so look at the parent var if this is an SFT. */
1879 if (TREE_CODE (var
) == STRUCT_FIELD_TAG
)
1880 real_var
= SFT_PARENT_VAR (var
);
1882 not_read
= not_read_b
? bitmap_bit_p (not_read_b
,
1883 DECL_UID (real_var
)) : false;
1887 clobber_stats
.static_readonly_clobbers_avoided
++;
1891 add_stmt_operand (&var
, s_ann
, opf_none
| opf_non_specific
);
1896 /* Scan the immediate_use list for VAR making sure its linked properly.
1897 return RTUE iof there is a problem. */
1900 verify_imm_links (FILE *f
, tree var
)
1902 use_operand_p ptr
, prev
, list
;
1905 gcc_assert (TREE_CODE (var
) == SSA_NAME
);
1907 list
= &(SSA_NAME_IMM_USE_NODE (var
));
1908 gcc_assert (list
->use
== NULL
);
1910 if (list
->prev
== NULL
)
1912 gcc_assert (list
->next
== NULL
);
1918 for (ptr
= list
->next
; ptr
!= list
; )
1920 if (prev
!= ptr
->prev
)
1923 if (ptr
->use
== NULL
)
1924 goto error
; /* 2 roots, or SAFE guard node. */
1925 else if (*(ptr
->use
) != var
)
1930 /* Avoid infinite loops. 50,000,000 uses probably indicates a problem. */
1931 if (count
++ > 50000000)
1935 /* Verify list in the other direction. */
1937 for (ptr
= list
->prev
; ptr
!= list
; )
1939 if (prev
!= ptr
->next
)
1953 if (ptr
->stmt
&& stmt_modified_p (ptr
->stmt
))
1955 fprintf (f
, " STMT MODIFIED. - <%p> ", (void *)ptr
->stmt
);
1956 print_generic_stmt (f
, ptr
->stmt
, TDF_SLIM
);
1958 fprintf (f
, " IMM ERROR : (use_p : tree - %p:%p)", (void *)ptr
,
1960 print_generic_expr (f
, USE_FROM_PTR (ptr
), TDF_SLIM
);
1966 /* Dump all the immediate uses to FILE. */
1969 dump_immediate_uses_for (FILE *file
, tree var
)
1971 imm_use_iterator iter
;
1972 use_operand_p use_p
;
1974 gcc_assert (var
&& TREE_CODE (var
) == SSA_NAME
);
1976 print_generic_expr (file
, var
, TDF_SLIM
);
1977 fprintf (file
, " : -->");
1978 if (has_zero_uses (var
))
1979 fprintf (file
, " no uses.\n");
1981 if (has_single_use (var
))
1982 fprintf (file
, " single use.\n");
1984 fprintf (file
, "%d uses.\n", num_imm_uses (var
));
1986 FOR_EACH_IMM_USE_FAST (use_p
, iter
, var
)
1988 if (!is_gimple_reg (USE_FROM_PTR (use_p
)))
1989 print_generic_stmt (file
, USE_STMT (use_p
), TDF_VOPS
);
1991 print_generic_stmt (file
, USE_STMT (use_p
), TDF_SLIM
);
1993 fprintf(file
, "\n");
1996 /* Dump all the immediate uses to FILE. */
1999 dump_immediate_uses (FILE *file
)
2004 fprintf (file
, "Immediate_uses: \n\n");
2005 for (x
= 1; x
< num_ssa_names
; x
++)
2010 dump_immediate_uses_for (file
, var
);
2015 /* Dump def-use edges on stderr. */
2018 debug_immediate_uses (void)
2020 dump_immediate_uses (stderr
);
2023 /* Dump def-use edges on stderr. */
2026 debug_immediate_uses_for (tree var
)
2028 dump_immediate_uses_for (stderr
, var
);
2030 #include "gt-tree-ssa-operands.h"