1 /* Control flow functions for trees.
2 Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
3 Contributed by Diego Novillo <dnovillo@redhat.com>
5 This file is part of GCC.
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 2, or (at your option)
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.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
24 #include "coretypes.h"
29 #include "hard-reg-set.h"
30 #include "basic-block.h"
37 #include "langhooks.h"
38 #include "diagnostic.h"
39 #include "tree-flow.h"
41 #include "tree-dump.h"
42 #include "tree-pass.h"
46 #include "cfglayout.h"
49 /* This file contains functions for building the Control Flow Graph (CFG)
50 for a function tree. */
52 /* Local declarations. */
54 /* Initial capacity for the basic block array. */
55 static const int initial_cfg_capacity = 20;
57 /* This hash table allows us to efficiently lookup all CASE_LABEL_EXPRs
58 which use a particular edge. The CASE_LABEL_EXPRs are chained together
59 via their TREE_CHAIN field, which we clear after we're done with the
60 hash table to prevent problems with duplication of SWITCH_EXPRs.
62 Access to this list of CASE_LABEL_EXPRs allows us to efficiently
63 update the case vector in response to edge redirections.
65 Right now this table is set up and torn down at key points in the
66 compilation process. It would be nice if we could make the table
67 more persistent. The key is getting notification of changes to
68 the CFG (particularly edge removal, creation and redirection). */
70 struct edge_to_cases_elt
72 /* The edge itself. Necessary for hashing and equality tests. */
75 /* The case labels associated with this edge. We link these up via
76 their TREE_CHAIN field, then we wipe out the TREE_CHAIN fields
77 when we destroy the hash table. This prevents problems when copying
82 static htab_t edge_to_cases;
87 long num_merged_labels;
90 static struct cfg_stats_d cfg_stats;
92 /* Nonzero if we found a computed goto while building basic blocks. */
93 static bool found_computed_goto;
95 /* Basic blocks and flowgraphs. */
96 static basic_block create_bb (void *, void *, basic_block);
97 static void create_block_annotation (basic_block);
98 static void free_blocks_annotations (void);
99 static void clear_blocks_annotations (void);
100 static void make_blocks (tree);
101 static void factor_computed_gotos (void);
104 static void make_edges (void);
105 static void make_ctrl_stmt_edges (basic_block);
106 static void make_exit_edges (basic_block);
107 static void make_cond_expr_edges (basic_block);
108 static void make_switch_expr_edges (basic_block);
109 static void make_goto_expr_edges (basic_block);
110 static edge tree_redirect_edge_and_branch (edge, basic_block);
111 static edge tree_try_redirect_by_replacing_jump (edge, basic_block);
112 static void split_critical_edges (void);
113 static bool remove_fallthru_edge (VEC(edge,gc) *);
115 /* Various helpers. */
116 static inline bool stmt_starts_bb_p (tree, tree);
117 static int tree_verify_flow_info (void);
118 static void tree_make_forwarder_block (edge);
119 static bool tree_forwarder_block_p (basic_block, bool);
120 static void tree_cfg2vcg (FILE *);
122 /* Flowgraph optimization and cleanup. */
123 static void tree_merge_blocks (basic_block, basic_block);
124 static bool tree_can_merge_blocks_p (basic_block, basic_block);
125 static void remove_bb (basic_block);
126 static bool cleanup_control_flow (void);
127 static bool cleanup_control_expr_graph (basic_block, block_stmt_iterator);
128 static edge find_taken_edge_computed_goto (basic_block, tree);
129 static edge find_taken_edge_cond_expr (basic_block, tree);
130 static edge find_taken_edge_switch_expr (basic_block, tree);
131 static tree find_case_label_for_value (tree, tree);
132 static bool phi_alternatives_equal (basic_block, edge, edge);
133 static bool cleanup_forwarder_blocks (void);
136 init_empty_tree_cfg (void)
138 /* Initialize the basic block array. */
140 profile_status = PROFILE_ABSENT;
142 last_basic_block = 0;
143 VARRAY_BB_INIT (basic_block_info, initial_cfg_capacity, "basic_block_info");
145 /* Build a mapping of labels to their associated blocks. */
146 VARRAY_BB_INIT (label_to_block_map, initial_cfg_capacity,
147 "label to block map");
149 ENTRY_BLOCK_PTR->next_bb = EXIT_BLOCK_PTR;
150 EXIT_BLOCK_PTR->prev_bb = ENTRY_BLOCK_PTR;
152 create_block_annotation (ENTRY_BLOCK_PTR);
153 create_block_annotation (EXIT_BLOCK_PTR);
156 /*---------------------------------------------------------------------------
158 ---------------------------------------------------------------------------*/
160 /* Entry point to the CFG builder for trees. TP points to the list of
161 statements to be added to the flowgraph. */
164 build_tree_cfg (tree *tp)
166 /* Register specific tree functions. */
167 tree_register_cfg_hooks ();
169 memset ((void *) &cfg_stats, 0, sizeof (cfg_stats));
171 init_empty_tree_cfg ();
173 found_computed_goto = 0;
176 /* Computed gotos are hell to deal with, especially if there are
177 lots of them with a large number of destinations. So we factor
178 them to a common computed goto location before we build the
179 edge list. After we convert back to normal form, we will un-factor
180 the computed gotos since factoring introduces an unwanted jump. */
181 if (found_computed_goto)
182 factor_computed_gotos ();
184 /* Make sure there is always at least one block, even if it's empty. */
185 if (n_basic_blocks == 0)
186 create_empty_bb (ENTRY_BLOCK_PTR);
188 /* Adjust the size of the array. */
189 VARRAY_GROW (basic_block_info, n_basic_blocks);
191 /* To speed up statement iterator walks, we first purge dead labels. */
192 cleanup_dead_labels ();
194 /* Group case nodes to reduce the number of edges.
195 We do this after cleaning up dead labels because otherwise we miss
196 a lot of obvious case merging opportunities. */
197 group_case_labels ();
199 /* Create the edges of the flowgraph. */
202 /* Debugging dumps. */
204 /* Write the flowgraph to a VCG file. */
206 int local_dump_flags;
207 FILE *dump_file = dump_begin (TDI_vcg, &local_dump_flags);
210 tree_cfg2vcg (dump_file);
211 dump_end (TDI_vcg, dump_file);
215 #ifdef ENABLE_CHECKING
219 /* Dump a textual representation of the flowgraph. */
221 dump_tree_cfg (dump_file, dump_flags);
225 execute_build_cfg (void)
227 build_tree_cfg (&DECL_SAVED_TREE (current_function_decl));
230 struct tree_opt_pass pass_build_cfg =
234 execute_build_cfg, /* execute */
237 0, /* static_pass_number */
238 TV_TREE_CFG, /* tv_id */
239 PROP_gimple_leh, /* properties_required */
240 PROP_cfg, /* properties_provided */
241 0, /* properties_destroyed */
242 0, /* todo_flags_start */
243 TODO_verify_stmts, /* todo_flags_finish */
247 /* Search the CFG for any computed gotos. If found, factor them to a
248 common computed goto site. Also record the location of that site so
249 that we can un-factor the gotos after we have converted back to
253 factor_computed_gotos (void)
256 tree factored_label_decl = NULL;
258 tree factored_computed_goto_label = NULL;
259 tree factored_computed_goto = NULL;
261 /* We know there are one or more computed gotos in this function.
262 Examine the last statement in each basic block to see if the block
263 ends with a computed goto. */
267 block_stmt_iterator bsi = bsi_last (bb);
272 last = bsi_stmt (bsi);
274 /* Ignore the computed goto we create when we factor the original
276 if (last == factored_computed_goto)
279 /* If the last statement is a computed goto, factor it. */
280 if (computed_goto_p (last))
284 /* The first time we find a computed goto we need to create
285 the factored goto block and the variable each original
286 computed goto will use for their goto destination. */
287 if (! factored_computed_goto)
289 basic_block new_bb = create_empty_bb (bb);
290 block_stmt_iterator new_bsi = bsi_start (new_bb);
292 /* Create the destination of the factored goto. Each original
293 computed goto will put its desired destination into this
294 variable and jump to the label we create immediately
296 var = create_tmp_var (ptr_type_node, "gotovar");
298 /* Build a label for the new block which will contain the
299 factored computed goto. */
300 factored_label_decl = create_artificial_label ();
301 factored_computed_goto_label
302 = build1 (LABEL_EXPR, void_type_node, factored_label_decl);
303 bsi_insert_after (&new_bsi, factored_computed_goto_label,
306 /* Build our new computed goto. */
307 factored_computed_goto = build1 (GOTO_EXPR, void_type_node, var);
308 bsi_insert_after (&new_bsi, factored_computed_goto,
312 /* Copy the original computed goto's destination into VAR. */
313 assignment = build (MODIFY_EXPR, ptr_type_node,
314 var, GOTO_DESTINATION (last));
315 bsi_insert_before (&bsi, assignment, BSI_SAME_STMT);
317 /* And re-vector the computed goto to the new destination. */
318 GOTO_DESTINATION (last) = factored_label_decl;
324 /* Create annotations for a single basic block. */
327 create_block_annotation (basic_block bb)
329 /* Verify that the tree_annotations field is clear. */
330 gcc_assert (!bb->tree_annotations);
331 bb->tree_annotations = ggc_alloc_cleared (sizeof (struct bb_ann_d));
335 /* Free the annotations for all the basic blocks. */
337 static void free_blocks_annotations (void)
339 clear_blocks_annotations ();
343 /* Clear the annotations for all the basic blocks. */
346 clear_blocks_annotations (void)
350 FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR, NULL, next_bb)
351 bb->tree_annotations = NULL;
355 /* Build a flowgraph for the statement_list STMT_LIST. */
358 make_blocks (tree stmt_list)
360 tree_stmt_iterator i = tsi_start (stmt_list);
362 bool start_new_block = true;
363 bool first_stmt_of_list = true;
364 basic_block bb = ENTRY_BLOCK_PTR;
366 while (!tsi_end_p (i))
373 /* If the statement starts a new basic block or if we have determined
374 in a previous pass that we need to create a new block for STMT, do
376 if (start_new_block || stmt_starts_bb_p (stmt, prev_stmt))
378 if (!first_stmt_of_list)
379 stmt_list = tsi_split_statement_list_before (&i);
380 bb = create_basic_block (stmt_list, NULL, bb);
381 start_new_block = false;
384 /* Now add STMT to BB and create the subgraphs for special statement
386 set_bb_for_stmt (stmt, bb);
388 if (computed_goto_p (stmt))
389 found_computed_goto = true;
391 /* If STMT is a basic block terminator, set START_NEW_BLOCK for the
393 if (stmt_ends_bb_p (stmt))
394 start_new_block = true;
397 first_stmt_of_list = false;
402 /* Create and return a new empty basic block after bb AFTER. */
405 create_bb (void *h, void *e, basic_block after)
411 /* Create and initialize a new basic block. Since alloc_block uses
412 ggc_alloc_cleared to allocate a basic block, we do not have to
413 clear the newly allocated basic block here. */
416 bb->index = last_basic_block;
418 bb->stmt_list = h ? h : alloc_stmt_list ();
420 /* Add the new block to the linked list of blocks. */
421 link_block (bb, after);
423 /* Grow the basic block array if needed. */
424 if ((size_t) last_basic_block == VARRAY_SIZE (basic_block_info))
426 size_t new_size = last_basic_block + (last_basic_block + 3) / 4;
427 VARRAY_GROW (basic_block_info, new_size);
430 /* Add the newly created block to the array. */
431 BASIC_BLOCK (last_basic_block) = bb;
433 create_block_annotation (bb);
438 initialize_bb_rbi (bb);
443 /*---------------------------------------------------------------------------
445 ---------------------------------------------------------------------------*/
447 /* Fold COND_EXPR_COND of each COND_EXPR. */
450 fold_cond_expr_cond (void)
456 tree stmt = last_stmt (bb);
459 && TREE_CODE (stmt) == COND_EXPR)
461 tree cond = fold (COND_EXPR_COND (stmt));
462 if (integer_zerop (cond))
463 COND_EXPR_COND (stmt) = boolean_false_node;
464 else if (integer_onep (cond))
465 COND_EXPR_COND (stmt) = boolean_true_node;
470 /* Join all the blocks in the flowgraph. */
477 /* Create an edge from entry to the first block with executable
479 make_edge (ENTRY_BLOCK_PTR, BASIC_BLOCK (0), EDGE_FALLTHRU);
481 /* Traverse the basic block array placing edges. */
484 tree first = first_stmt (bb);
485 tree last = last_stmt (bb);
489 /* Edges for statements that always alter flow control. */
490 if (is_ctrl_stmt (last))
491 make_ctrl_stmt_edges (bb);
493 /* Edges for statements that sometimes alter flow control. */
494 if (is_ctrl_altering_stmt (last))
495 make_exit_edges (bb);
498 /* Finally, if no edges were created above, this is a regular
499 basic block that only needs a fallthru edge. */
500 if (EDGE_COUNT (bb->succs) == 0)
501 make_edge (bb, bb->next_bb, EDGE_FALLTHRU);
504 /* We do not care about fake edges, so remove any that the CFG
505 builder inserted for completeness. */
506 remove_fake_exit_edges ();
508 /* Fold COND_EXPR_COND of each COND_EXPR. */
509 fold_cond_expr_cond ();
511 /* Clean up the graph and warn for unreachable code. */
516 /* Create edges for control statement at basic block BB. */
519 make_ctrl_stmt_edges (basic_block bb)
521 tree last = last_stmt (bb);
524 switch (TREE_CODE (last))
527 make_goto_expr_edges (bb);
531 make_edge (bb, EXIT_BLOCK_PTR, 0);
535 make_cond_expr_edges (bb);
539 make_switch_expr_edges (bb);
543 make_eh_edges (last);
544 /* Yet another NORETURN hack. */
545 if (EDGE_COUNT (bb->succs) == 0)
546 make_edge (bb, EXIT_BLOCK_PTR, EDGE_FAKE);
555 /* Create exit edges for statements in block BB that alter the flow of
556 control. Statements that alter the control flow are 'goto', 'return'
557 and calls to non-returning functions. */
560 make_exit_edges (basic_block bb)
562 tree last = last_stmt (bb), op;
565 switch (TREE_CODE (last))
570 /* If this function receives a nonlocal goto, then we need to
571 make edges from this call site to all the nonlocal goto
573 if (TREE_SIDE_EFFECTS (last)
574 && current_function_has_nonlocal_label)
575 make_goto_expr_edges (bb);
577 /* If this statement has reachable exception handlers, then
578 create abnormal edges to them. */
579 make_eh_edges (last);
581 /* Some calls are known not to return. For such calls we create
584 We really need to revamp how we build edges so that it's not
585 such a bloody pain to avoid creating edges for this case since
586 all we do is remove these edges when we're done building the
588 if (call_expr_flags (last) & ECF_NORETURN)
590 make_edge (bb, EXIT_BLOCK_PTR, EDGE_FAKE);
594 /* Don't forget the fall-thru edge. */
595 make_edge (bb, bb->next_bb, EDGE_FALLTHRU);
599 /* A MODIFY_EXPR may have a CALL_EXPR on its RHS and the CALL_EXPR
600 may have an abnormal edge. Search the RHS for this case and
601 create any required edges. */
602 op = get_call_expr_in (last);
603 if (op && TREE_SIDE_EFFECTS (op)
604 && current_function_has_nonlocal_label)
605 make_goto_expr_edges (bb);
607 make_eh_edges (last);
608 make_edge (bb, bb->next_bb, EDGE_FALLTHRU);
617 /* Create the edges for a COND_EXPR starting at block BB.
618 At this point, both clauses must contain only simple gotos. */
621 make_cond_expr_edges (basic_block bb)
623 tree entry = last_stmt (bb);
624 basic_block then_bb, else_bb;
625 tree then_label, else_label;
628 gcc_assert (TREE_CODE (entry) == COND_EXPR);
630 /* Entry basic blocks for each component. */
631 then_label = GOTO_DESTINATION (COND_EXPR_THEN (entry));
632 else_label = GOTO_DESTINATION (COND_EXPR_ELSE (entry));
633 then_bb = label_to_block (then_label);
634 else_bb = label_to_block (else_label);
636 make_edge (bb, then_bb, EDGE_TRUE_VALUE);
637 make_edge (bb, else_bb, EDGE_FALSE_VALUE);
640 /* Hashing routine for EDGE_TO_CASES. */
643 edge_to_cases_hash (const void *p)
645 edge e = ((struct edge_to_cases_elt *)p)->e;
647 /* Hash on the edge itself (which is a pointer). */
648 return htab_hash_pointer (e);
651 /* Equality routine for EDGE_TO_CASES, edges are unique, so testing
652 for equality is just a pointer comparison. */
655 edge_to_cases_eq (const void *p1, const void *p2)
657 edge e1 = ((struct edge_to_cases_elt *)p1)->e;
658 edge e2 = ((struct edge_to_cases_elt *)p2)->e;
663 /* Called for each element in the hash table (P) as we delete the
664 edge to cases hash table.
666 Clear all the TREE_CHAINs to prevent problems with copying of
667 SWITCH_EXPRs and structure sharing rules, then free the hash table
671 edge_to_cases_cleanup (void *p)
673 struct edge_to_cases_elt *elt = p;
676 for (t = elt->case_labels; t; t = next)
678 next = TREE_CHAIN (t);
679 TREE_CHAIN (t) = NULL;
684 /* Start recording information mapping edges to case labels. */
687 start_recording_case_labels (void)
689 gcc_assert (edge_to_cases == NULL);
691 edge_to_cases = htab_create (37,
694 edge_to_cases_cleanup);
697 /* Return nonzero if we are recording information for case labels. */
700 recording_case_labels_p (void)
702 return (edge_to_cases != NULL);
705 /* Stop recording information mapping edges to case labels and
706 remove any information we have recorded. */
708 end_recording_case_labels (void)
710 htab_delete (edge_to_cases);
711 edge_to_cases = NULL;
714 /* Record that CASE_LABEL (a CASE_LABEL_EXPR) references edge E. */
717 record_switch_edge (edge e, tree case_label)
719 struct edge_to_cases_elt *elt;
722 /* Build a hash table element so we can see if E is already
724 elt = xmalloc (sizeof (struct edge_to_cases_elt));
726 elt->case_labels = case_label;
728 slot = htab_find_slot (edge_to_cases, elt, INSERT);
732 /* E was not in the hash table. Install E into the hash table. */
737 /* E was already in the hash table. Free ELT as we do not need it
741 /* Get the entry stored in the hash table. */
742 elt = (struct edge_to_cases_elt *) *slot;
744 /* Add it to the chain of CASE_LABEL_EXPRs referencing E. */
745 TREE_CHAIN (case_label) = elt->case_labels;
746 elt->case_labels = case_label;
750 /* If we are inside a {start,end}_recording_cases block, then return
751 a chain of CASE_LABEL_EXPRs from T which reference E.
753 Otherwise return NULL. */
756 get_cases_for_edge (edge e, tree t)
758 struct edge_to_cases_elt elt, *elt_p;
763 /* If we are not recording cases, then we do not have CASE_LABEL_EXPR
764 chains available. Return NULL so the caller can detect this case. */
765 if (!recording_case_labels_p ())
770 elt.case_labels = NULL;
771 slot = htab_find_slot (edge_to_cases, &elt, NO_INSERT);
775 elt_p = (struct edge_to_cases_elt *)*slot;
776 return elt_p->case_labels;
779 /* If we did not find E in the hash table, then this must be the first
780 time we have been queried for information about E & T. Add all the
781 elements from T to the hash table then perform the query again. */
783 vec = SWITCH_LABELS (t);
784 n = TREE_VEC_LENGTH (vec);
785 for (i = 0; i < n; i++)
787 tree lab = CASE_LABEL (TREE_VEC_ELT (vec, i));
788 basic_block label_bb = label_to_block (lab);
789 record_switch_edge (find_edge (e->src, label_bb), TREE_VEC_ELT (vec, i));
794 /* Create the edges for a SWITCH_EXPR starting at block BB.
795 At this point, the switch body has been lowered and the
796 SWITCH_LABELS filled in, so this is in effect a multi-way branch. */
799 make_switch_expr_edges (basic_block bb)
801 tree entry = last_stmt (bb);
805 vec = SWITCH_LABELS (entry);
806 n = TREE_VEC_LENGTH (vec);
808 for (i = 0; i < n; ++i)
810 tree lab = CASE_LABEL (TREE_VEC_ELT (vec, i));
811 basic_block label_bb = label_to_block (lab);
812 make_edge (bb, label_bb, 0);
817 /* Return the basic block holding label DEST. */
820 label_to_block_fn (struct function *ifun, tree dest)
822 int uid = LABEL_DECL_UID (dest);
824 /* We would die hard when faced by an undefined label. Emit a label to
825 the very first basic block. This will hopefully make even the dataflow
826 and undefined variable warnings quite right. */
827 if ((errorcount || sorrycount) && uid < 0)
829 block_stmt_iterator bsi = bsi_start (BASIC_BLOCK (0));
832 stmt = build1 (LABEL_EXPR, void_type_node, dest);
833 bsi_insert_before (&bsi, stmt, BSI_NEW_STMT);
834 uid = LABEL_DECL_UID (dest);
836 if (VARRAY_SIZE (ifun->cfg->x_label_to_block_map) <= (unsigned int)uid)
838 return VARRAY_BB (ifun->cfg->x_label_to_block_map, uid);
841 /* Create edges for a goto statement at block BB. */
844 make_goto_expr_edges (basic_block bb)
847 basic_block target_bb;
849 block_stmt_iterator last = bsi_last (bb);
851 goto_t = bsi_stmt (last);
853 /* If the last statement is not a GOTO (i.e., it is a RETURN_EXPR,
854 CALL_EXPR or MODIFY_EXPR), then the edge is an abnormal edge resulting
855 from a nonlocal goto. */
856 if (TREE_CODE (goto_t) != GOTO_EXPR)
860 tree dest = GOTO_DESTINATION (goto_t);
863 /* A GOTO to a local label creates normal edges. */
864 if (simple_goto_p (goto_t))
866 edge e = make_edge (bb, label_to_block (dest), EDGE_FALLTHRU);
867 #ifdef USE_MAPPED_LOCATION
868 e->goto_locus = EXPR_LOCATION (goto_t);
870 e->goto_locus = EXPR_LOCUS (goto_t);
876 /* Nothing more to do for nonlocal gotos. */
877 if (TREE_CODE (dest) == LABEL_DECL)
880 /* Computed gotos remain. */
883 /* Look for the block starting with the destination label. In the
884 case of a computed goto, make an edge to any label block we find
886 FOR_EACH_BB (target_bb)
888 block_stmt_iterator bsi;
890 for (bsi = bsi_start (target_bb); !bsi_end_p (bsi); bsi_next (&bsi))
892 tree target = bsi_stmt (bsi);
894 if (TREE_CODE (target) != LABEL_EXPR)
898 /* Computed GOTOs. Make an edge to every label block that has
899 been marked as a potential target for a computed goto. */
900 (FORCED_LABEL (LABEL_EXPR_LABEL (target)) && for_call == 0)
901 /* Nonlocal GOTO target. Make an edge to every label block
902 that has been marked as a potential target for a nonlocal
904 || (DECL_NONLOCAL (LABEL_EXPR_LABEL (target)) && for_call == 1))
906 make_edge (bb, target_bb, EDGE_ABNORMAL);
912 /* Degenerate case of computed goto with no labels. */
913 if (!for_call && EDGE_COUNT (bb->succs) == 0)
914 make_edge (bb, EXIT_BLOCK_PTR, EDGE_FAKE);
918 /*---------------------------------------------------------------------------
920 ---------------------------------------------------------------------------*/
922 /* Remove unreachable blocks and other miscellaneous clean up work. */
925 cleanup_tree_cfg (void)
929 timevar_push (TV_TREE_CLEANUP_CFG);
931 retval = cleanup_control_flow ();
932 retval |= delete_unreachable_blocks ();
934 /* cleanup_forwarder_blocks can redirect edges out of SWITCH_EXPRs,
935 which can get expensive. So we want to enable recording of edge
936 to CASE_LABEL_EXPR mappings around the call to
937 cleanup_forwarder_blocks. */
938 start_recording_case_labels ();
939 retval |= cleanup_forwarder_blocks ();
940 end_recording_case_labels ();
942 #ifdef ENABLE_CHECKING
945 gcc_assert (!cleanup_control_flow ());
946 gcc_assert (!delete_unreachable_blocks ());
947 gcc_assert (!cleanup_forwarder_blocks ());
951 /* Merging the blocks creates no new opportunities for the other
952 optimizations, so do it here. */
953 retval |= merge_seq_blocks ();
957 #ifdef ENABLE_CHECKING
960 timevar_pop (TV_TREE_CLEANUP_CFG);
965 /* Cleanup cfg and repair loop structures. */
968 cleanup_tree_cfg_loop (void)
970 bitmap changed_bbs = BITMAP_ALLOC (NULL);
974 fix_loop_structure (current_loops, changed_bbs);
975 calculate_dominance_info (CDI_DOMINATORS);
977 /* This usually does nothing. But sometimes parts of cfg that originally
978 were inside a loop get out of it due to edge removal (since they
979 become unreachable by back edges from latch). */
980 rewrite_into_loop_closed_ssa (changed_bbs, TODO_update_ssa);
982 BITMAP_FREE (changed_bbs);
984 #ifdef ENABLE_CHECKING
985 verify_loop_structure (current_loops);
989 /* Cleanup useless labels in basic blocks. This is something we wish
990 to do early because it allows us to group case labels before creating
991 the edges for the CFG, and it speeds up block statement iterators in
993 We only run this pass once, running it more than once is probably not
996 /* A map from basic block index to the leading label of that block. */
997 static tree *label_for_bb;
999 /* Callback for for_each_eh_region. Helper for cleanup_dead_labels. */
1001 update_eh_label (struct eh_region *region)
1003 tree old_label = get_eh_region_tree_label (region);
1007 basic_block bb = label_to_block (old_label);
1009 /* ??? After optimizing, there may be EH regions with labels
1010 that have already been removed from the function body, so
1011 there is no basic block for them. */
1015 new_label = label_for_bb[bb->index];
1016 set_eh_region_tree_label (region, new_label);
1020 /* Given LABEL return the first label in the same basic block. */
1022 main_block_label (tree label)
1024 basic_block bb = label_to_block (label);
1026 /* label_to_block possibly inserted undefined label into the chain. */
1027 if (!label_for_bb[bb->index])
1028 label_for_bb[bb->index] = label;
1029 return label_for_bb[bb->index];
1032 /* Cleanup redundant labels. This is a three-step process:
1033 1) Find the leading label for each block.
1034 2) Redirect all references to labels to the leading labels.
1035 3) Cleanup all useless labels. */
1038 cleanup_dead_labels (void)
1041 label_for_bb = xcalloc (last_basic_block, sizeof (tree));
1043 /* Find a suitable label for each block. We use the first user-defined
1044 label if there is one, or otherwise just the first label we see. */
1047 block_stmt_iterator i;
1049 for (i = bsi_start (bb); !bsi_end_p (i); bsi_next (&i))
1051 tree label, stmt = bsi_stmt (i);
1053 if (TREE_CODE (stmt) != LABEL_EXPR)
1056 label = LABEL_EXPR_LABEL (stmt);
1058 /* If we have not yet seen a label for the current block,
1059 remember this one and see if there are more labels. */
1060 if (! label_for_bb[bb->index])
1062 label_for_bb[bb->index] = label;
1066 /* If we did see a label for the current block already, but it
1067 is an artificially created label, replace it if the current
1068 label is a user defined label. */
1069 if (! DECL_ARTIFICIAL (label)
1070 && DECL_ARTIFICIAL (label_for_bb[bb->index]))
1072 label_for_bb[bb->index] = label;
1078 /* Now redirect all jumps/branches to the selected label.
1079 First do so for each block ending in a control statement. */
1082 tree stmt = last_stmt (bb);
1086 switch (TREE_CODE (stmt))
1090 tree true_branch, false_branch;
1092 true_branch = COND_EXPR_THEN (stmt);
1093 false_branch = COND_EXPR_ELSE (stmt);
1095 GOTO_DESTINATION (true_branch)
1096 = main_block_label (GOTO_DESTINATION (true_branch));
1097 GOTO_DESTINATION (false_branch)
1098 = main_block_label (GOTO_DESTINATION (false_branch));
1106 tree vec = SWITCH_LABELS (stmt);
1107 size_t n = TREE_VEC_LENGTH (vec);
1109 /* Replace all destination labels. */
1110 for (i = 0; i < n; ++i)
1112 tree elt = TREE_VEC_ELT (vec, i);
1113 tree label = main_block_label (CASE_LABEL (elt));
1114 CASE_LABEL (elt) = label;
1119 /* We have to handle GOTO_EXPRs until they're removed, and we don't
1120 remove them until after we've created the CFG edges. */
1122 if (! computed_goto_p (stmt))
1124 GOTO_DESTINATION (stmt)
1125 = main_block_label (GOTO_DESTINATION (stmt));
1134 for_each_eh_region (update_eh_label);
1136 /* Finally, purge dead labels. All user-defined labels and labels that
1137 can be the target of non-local gotos are preserved. */
1140 block_stmt_iterator i;
1141 tree label_for_this_bb = label_for_bb[bb->index];
1143 if (! label_for_this_bb)
1146 for (i = bsi_start (bb); !bsi_end_p (i); )
1148 tree label, stmt = bsi_stmt (i);
1150 if (TREE_CODE (stmt) != LABEL_EXPR)
1153 label = LABEL_EXPR_LABEL (stmt);
1155 if (label == label_for_this_bb
1156 || ! DECL_ARTIFICIAL (label)
1157 || DECL_NONLOCAL (label))
1164 free (label_for_bb);
1167 /* Look for blocks ending in a multiway branch (a SWITCH_EXPR in GIMPLE),
1168 and scan the sorted vector of cases. Combine the ones jumping to the
1170 Eg. three separate entries 1: 2: 3: become one entry 1..3: */
1173 group_case_labels (void)
1179 tree stmt = last_stmt (bb);
1180 if (stmt && TREE_CODE (stmt) == SWITCH_EXPR)
1182 tree labels = SWITCH_LABELS (stmt);
1183 int old_size = TREE_VEC_LENGTH (labels);
1184 int i, j, new_size = old_size;
1185 tree default_case = TREE_VEC_ELT (labels, old_size - 1);
1188 /* The default label is always the last case in a switch
1189 statement after gimplification. */
1190 default_label = CASE_LABEL (default_case);
1192 /* Look for possible opportunities to merge cases.
1193 Ignore the last element of the label vector because it
1194 must be the default case. */
1196 while (i < old_size - 1)
1198 tree base_case, base_label, base_high;
1199 base_case = TREE_VEC_ELT (labels, i);
1201 gcc_assert (base_case);
1202 base_label = CASE_LABEL (base_case);
1204 /* Discard cases that have the same destination as the
1206 if (base_label == default_label)
1208 TREE_VEC_ELT (labels, i) = NULL_TREE;
1214 base_high = CASE_HIGH (base_case) ?
1215 CASE_HIGH (base_case) : CASE_LOW (base_case);
1217 /* Try to merge case labels. Break out when we reach the end
1218 of the label vector or when we cannot merge the next case
1219 label with the current one. */
1220 while (i < old_size - 1)
1222 tree merge_case = TREE_VEC_ELT (labels, i);
1223 tree merge_label = CASE_LABEL (merge_case);
1224 tree t = int_const_binop (PLUS_EXPR, base_high,
1225 integer_one_node, 1);
1227 /* Merge the cases if they jump to the same place,
1228 and their ranges are consecutive. */
1229 if (merge_label == base_label
1230 && tree_int_cst_equal (CASE_LOW (merge_case), t))
1232 base_high = CASE_HIGH (merge_case) ?
1233 CASE_HIGH (merge_case) : CASE_LOW (merge_case);
1234 CASE_HIGH (base_case) = base_high;
1235 TREE_VEC_ELT (labels, i) = NULL_TREE;
1244 /* Compress the case labels in the label vector, and adjust the
1245 length of the vector. */
1246 for (i = 0, j = 0; i < new_size; i++)
1248 while (! TREE_VEC_ELT (labels, j))
1250 TREE_VEC_ELT (labels, i) = TREE_VEC_ELT (labels, j++);
1252 TREE_VEC_LENGTH (labels) = new_size;
1257 /* Checks whether we can merge block B into block A. */
1260 tree_can_merge_blocks_p (basic_block a, basic_block b)
1263 block_stmt_iterator bsi;
1266 if (!single_succ_p (a))
1269 if (single_succ_edge (a)->flags & EDGE_ABNORMAL)
1272 if (single_succ (a) != b)
1275 if (!single_pred_p (b))
1278 if (b == EXIT_BLOCK_PTR)
1281 /* If A ends by a statement causing exceptions or something similar, we
1282 cannot merge the blocks. */
1283 stmt = last_stmt (a);
1284 if (stmt && stmt_ends_bb_p (stmt))
1287 /* Do not allow a block with only a non-local label to be merged. */
1288 if (stmt && TREE_CODE (stmt) == LABEL_EXPR
1289 && DECL_NONLOCAL (LABEL_EXPR_LABEL (stmt)))
1292 /* It must be possible to eliminate all phi nodes in B. If ssa form
1293 is not up-to-date, we cannot eliminate any phis. */
1294 phi = phi_nodes (b);
1297 if (need_ssa_update_p ())
1300 for (; phi; phi = PHI_CHAIN (phi))
1301 if (!is_gimple_reg (PHI_RESULT (phi))
1302 && !may_propagate_copy (PHI_RESULT (phi), PHI_ARG_DEF (phi, 0)))
1306 /* Do not remove user labels. */
1307 for (bsi = bsi_start (b); !bsi_end_p (bsi); bsi_next (&bsi))
1309 stmt = bsi_stmt (bsi);
1310 if (TREE_CODE (stmt) != LABEL_EXPR)
1312 if (!DECL_ARTIFICIAL (LABEL_EXPR_LABEL (stmt)))
1316 /* Protect the loop latches. */
1318 && b->loop_father->latch == b)
1324 /* Replaces all uses of NAME by VAL. */
1327 replace_uses_by (tree name, tree val)
1329 imm_use_iterator imm_iter;
1334 VEC(tree,heap) *stmts = VEC_alloc (tree, heap, 20);
1336 FOR_EACH_IMM_USE_SAFE (use, imm_iter, name)
1338 stmt = USE_STMT (use);
1342 if (TREE_CODE (stmt) == PHI_NODE)
1344 e = PHI_ARG_EDGE (stmt, PHI_ARG_INDEX_FROM_USE (use));
1345 if (e->flags & EDGE_ABNORMAL)
1347 /* This can only occur for virtual operands, since
1348 for the real ones SSA_NAME_OCCURS_IN_ABNORMAL_PHI (name))
1349 would prevent replacement. */
1350 gcc_assert (!is_gimple_reg (name));
1351 SSA_NAME_OCCURS_IN_ABNORMAL_PHI (val) = 1;
1355 VEC_safe_push (tree, heap, stmts, stmt);
1358 /* We do not update the statements in the loop above. Consider
1361 If we performed the update in the first loop, the statement
1362 would be rescanned after first occurence of w is replaced,
1363 the new uses would be placed to the beginning of the list,
1364 and we would never process them. */
1365 for (i = 0; VEC_iterate (tree, stmts, i, stmt); i++)
1367 fold_stmt_inplace (stmt);
1371 VEC_free (tree, heap, stmts);
1374 /* Merge block B into block A. */
1377 tree_merge_blocks (basic_block a, basic_block b)
1379 block_stmt_iterator bsi;
1380 tree_stmt_iterator last;
1384 fprintf (dump_file, "Merging blocks %d and %d\n", a->index, b->index);
1386 /* Remove the phi nodes. */
1388 for (phi = phi_nodes (b); phi; phi = phi_nodes (b))
1390 tree def = PHI_RESULT (phi), use = PHI_ARG_DEF (phi, 0);
1393 if (!may_propagate_copy (def, use)
1394 /* Propagating pointers might cause the set of vops for statements
1395 to be changed, and thus require ssa form update. */
1396 || (is_gimple_reg (def)
1397 && POINTER_TYPE_P (TREE_TYPE (def))))
1399 gcc_assert (is_gimple_reg (def));
1401 /* Note that just emiting the copies is fine -- there is no problem
1402 with ordering of phi nodes. This is because A is the single
1403 predecessor of B, therefore results of the phi nodes cannot
1404 appear as arguments of the phi nodes. */
1405 copy = build2 (MODIFY_EXPR, void_type_node, def, use);
1406 bsi_insert_after (&bsi, copy, BSI_NEW_STMT);
1407 SET_PHI_RESULT (phi, NULL_TREE);
1408 SSA_NAME_DEF_STMT (def) = copy;
1411 replace_uses_by (def, use);
1412 remove_phi_node (phi, NULL);
1415 /* Ensure that B follows A. */
1416 move_block_after (b, a);
1418 gcc_assert (single_succ_edge (a)->flags & EDGE_FALLTHRU);
1419 gcc_assert (!last_stmt (a) || !stmt_ends_bb_p (last_stmt (a)));
1421 /* Remove labels from B and set bb_for_stmt to A for other statements. */
1422 for (bsi = bsi_start (b); !bsi_end_p (bsi);)
1424 if (TREE_CODE (bsi_stmt (bsi)) == LABEL_EXPR)
1426 tree label = bsi_stmt (bsi);
1429 /* Now that we can thread computed gotos, we might have
1430 a situation where we have a forced label in block B
1431 However, the label at the start of block B might still be
1432 used in other ways (think about the runtime checking for
1433 Fortran assigned gotos). So we can not just delete the
1434 label. Instead we move the label to the start of block A. */
1435 if (FORCED_LABEL (LABEL_EXPR_LABEL (label)))
1437 block_stmt_iterator dest_bsi = bsi_start (a);
1438 bsi_insert_before (&dest_bsi, label, BSI_NEW_STMT);
1443 set_bb_for_stmt (bsi_stmt (bsi), a);
1448 /* Merge the chains. */
1449 last = tsi_last (a->stmt_list);
1450 tsi_link_after (&last, b->stmt_list, TSI_NEW_STMT);
1451 b->stmt_list = NULL;
1455 /* Walk the function tree removing unnecessary statements.
1457 * Empty statement nodes are removed
1459 * Unnecessary TRY_FINALLY and TRY_CATCH blocks are removed
1461 * Unnecessary COND_EXPRs are removed
1463 * Some unnecessary BIND_EXPRs are removed
1465 Clearly more work could be done. The trick is doing the analysis
1466 and removal fast enough to be a net improvement in compile times.
1468 Note that when we remove a control structure such as a COND_EXPR
1469 BIND_EXPR, or TRY block, we will need to repeat this optimization pass
1470 to ensure we eliminate all the useless code. */
1481 static void remove_useless_stmts_1 (tree *, struct rus_data *);
1484 remove_useless_stmts_warn_notreached (tree stmt)
1486 if (EXPR_HAS_LOCATION (stmt))
1488 location_t loc = EXPR_LOCATION (stmt);
1489 if (LOCATION_LINE (loc) > 0)
1491 warning (0, "%Hwill never be executed", &loc);
1496 switch (TREE_CODE (stmt))
1498 case STATEMENT_LIST:
1500 tree_stmt_iterator i;
1501 for (i = tsi_start (stmt); !tsi_end_p (i); tsi_next (&i))
1502 if (remove_useless_stmts_warn_notreached (tsi_stmt (i)))
1508 if (remove_useless_stmts_warn_notreached (COND_EXPR_COND (stmt)))
1510 if (remove_useless_stmts_warn_notreached (COND_EXPR_THEN (stmt)))
1512 if (remove_useless_stmts_warn_notreached (COND_EXPR_ELSE (stmt)))
1516 case TRY_FINALLY_EXPR:
1517 case TRY_CATCH_EXPR:
1518 if (remove_useless_stmts_warn_notreached (TREE_OPERAND (stmt, 0)))
1520 if (remove_useless_stmts_warn_notreached (TREE_OPERAND (stmt, 1)))
1525 return remove_useless_stmts_warn_notreached (CATCH_BODY (stmt));
1526 case EH_FILTER_EXPR:
1527 return remove_useless_stmts_warn_notreached (EH_FILTER_FAILURE (stmt));
1529 return remove_useless_stmts_warn_notreached (BIND_EXPR_BLOCK (stmt));
1532 /* Not a live container. */
1540 remove_useless_stmts_cond (tree *stmt_p, struct rus_data *data)
1542 tree then_clause, else_clause, cond;
1543 bool save_has_label, then_has_label, else_has_label;
1545 save_has_label = data->has_label;
1546 data->has_label = false;
1547 data->last_goto = NULL;
1549 remove_useless_stmts_1 (&COND_EXPR_THEN (*stmt_p), data);
1551 then_has_label = data->has_label;
1552 data->has_label = false;
1553 data->last_goto = NULL;
1555 remove_useless_stmts_1 (&COND_EXPR_ELSE (*stmt_p), data);
1557 else_has_label = data->has_label;
1558 data->has_label = save_has_label | then_has_label | else_has_label;
1560 then_clause = COND_EXPR_THEN (*stmt_p);
1561 else_clause = COND_EXPR_ELSE (*stmt_p);
1562 cond = fold (COND_EXPR_COND (*stmt_p));
1564 /* If neither arm does anything at all, we can remove the whole IF. */
1565 if (!TREE_SIDE_EFFECTS (then_clause) && !TREE_SIDE_EFFECTS (else_clause))
1567 *stmt_p = build_empty_stmt ();
1568 data->repeat = true;
1571 /* If there are no reachable statements in an arm, then we can
1572 zap the entire conditional. */
1573 else if (integer_nonzerop (cond) && !else_has_label)
1575 if (warn_notreached)
1576 remove_useless_stmts_warn_notreached (else_clause);
1577 *stmt_p = then_clause;
1578 data->repeat = true;
1580 else if (integer_zerop (cond) && !then_has_label)
1582 if (warn_notreached)
1583 remove_useless_stmts_warn_notreached (then_clause);
1584 *stmt_p = else_clause;
1585 data->repeat = true;
1588 /* Check a couple of simple things on then/else with single stmts. */
1591 tree then_stmt = expr_only (then_clause);
1592 tree else_stmt = expr_only (else_clause);
1594 /* Notice branches to a common destination. */
1595 if (then_stmt && else_stmt
1596 && TREE_CODE (then_stmt) == GOTO_EXPR
1597 && TREE_CODE (else_stmt) == GOTO_EXPR
1598 && (GOTO_DESTINATION (then_stmt) == GOTO_DESTINATION (else_stmt)))
1600 *stmt_p = then_stmt;
1601 data->repeat = true;
1604 /* If the THEN/ELSE clause merely assigns a value to a variable or
1605 parameter which is already known to contain that value, then
1606 remove the useless THEN/ELSE clause. */
1607 else if (TREE_CODE (cond) == VAR_DECL || TREE_CODE (cond) == PARM_DECL)
1610 && TREE_CODE (else_stmt) == MODIFY_EXPR
1611 && TREE_OPERAND (else_stmt, 0) == cond
1612 && integer_zerop (TREE_OPERAND (else_stmt, 1)))
1613 COND_EXPR_ELSE (*stmt_p) = alloc_stmt_list ();
1615 else if ((TREE_CODE (cond) == EQ_EXPR || TREE_CODE (cond) == NE_EXPR)
1616 && (TREE_CODE (TREE_OPERAND (cond, 0)) == VAR_DECL
1617 || TREE_CODE (TREE_OPERAND (cond, 0)) == PARM_DECL)
1618 && TREE_CONSTANT (TREE_OPERAND (cond, 1)))
1620 tree stmt = (TREE_CODE (cond) == EQ_EXPR
1621 ? then_stmt : else_stmt);
1622 tree *location = (TREE_CODE (cond) == EQ_EXPR
1623 ? &COND_EXPR_THEN (*stmt_p)
1624 : &COND_EXPR_ELSE (*stmt_p));
1627 && TREE_CODE (stmt) == MODIFY_EXPR
1628 && TREE_OPERAND (stmt, 0) == TREE_OPERAND (cond, 0)
1629 && TREE_OPERAND (stmt, 1) == TREE_OPERAND (cond, 1))
1630 *location = alloc_stmt_list ();
1634 /* Protect GOTOs in the arm of COND_EXPRs from being removed. They
1635 would be re-introduced during lowering. */
1636 data->last_goto = NULL;
1641 remove_useless_stmts_tf (tree *stmt_p, struct rus_data *data)
1643 bool save_may_branch, save_may_throw;
1644 bool this_may_branch, this_may_throw;
1646 /* Collect may_branch and may_throw information for the body only. */
1647 save_may_branch = data->may_branch;
1648 save_may_throw = data->may_throw;
1649 data->may_branch = false;
1650 data->may_throw = false;
1651 data->last_goto = NULL;
1653 remove_useless_stmts_1 (&TREE_OPERAND (*stmt_p, 0), data);
1655 this_may_branch = data->may_branch;
1656 this_may_throw = data->may_throw;
1657 data->may_branch |= save_may_branch;
1658 data->may_throw |= save_may_throw;
1659 data->last_goto = NULL;
1661 remove_useless_stmts_1 (&TREE_OPERAND (*stmt_p, 1), data);
1663 /* If the body is empty, then we can emit the FINALLY block without
1664 the enclosing TRY_FINALLY_EXPR. */
1665 if (!TREE_SIDE_EFFECTS (TREE_OPERAND (*stmt_p, 0)))
1667 *stmt_p = TREE_OPERAND (*stmt_p, 1);
1668 data->repeat = true;
1671 /* If the handler is empty, then we can emit the TRY block without
1672 the enclosing TRY_FINALLY_EXPR. */
1673 else if (!TREE_SIDE_EFFECTS (TREE_OPERAND (*stmt_p, 1)))
1675 *stmt_p = TREE_OPERAND (*stmt_p, 0);
1676 data->repeat = true;
1679 /* If the body neither throws, nor branches, then we can safely
1680 string the TRY and FINALLY blocks together. */
1681 else if (!this_may_branch && !this_may_throw)
1683 tree stmt = *stmt_p;
1684 *stmt_p = TREE_OPERAND (stmt, 0);
1685 append_to_statement_list (TREE_OPERAND (stmt, 1), stmt_p);
1686 data->repeat = true;
1692 remove_useless_stmts_tc (tree *stmt_p, struct rus_data *data)
1694 bool save_may_throw, this_may_throw;
1695 tree_stmt_iterator i;
1698 /* Collect may_throw information for the body only. */
1699 save_may_throw = data->may_throw;
1700 data->may_throw = false;
1701 data->last_goto = NULL;
1703 remove_useless_stmts_1 (&TREE_OPERAND (*stmt_p, 0), data);
1705 this_may_throw = data->may_throw;
1706 data->may_throw = save_may_throw;
1708 /* If the body cannot throw, then we can drop the entire TRY_CATCH_EXPR. */
1709 if (!this_may_throw)
1711 if (warn_notreached)
1712 remove_useless_stmts_warn_notreached (TREE_OPERAND (*stmt_p, 1));
1713 *stmt_p = TREE_OPERAND (*stmt_p, 0);
1714 data->repeat = true;
1718 /* Process the catch clause specially. We may be able to tell that
1719 no exceptions propagate past this point. */
1721 this_may_throw = true;
1722 i = tsi_start (TREE_OPERAND (*stmt_p, 1));
1723 stmt = tsi_stmt (i);
1724 data->last_goto = NULL;
1726 switch (TREE_CODE (stmt))
1729 for (; !tsi_end_p (i); tsi_next (&i))
1731 stmt = tsi_stmt (i);
1732 /* If we catch all exceptions, then the body does not
1733 propagate exceptions past this point. */
1734 if (CATCH_TYPES (stmt) == NULL)
1735 this_may_throw = false;
1736 data->last_goto = NULL;
1737 remove_useless_stmts_1 (&CATCH_BODY (stmt), data);
1741 case EH_FILTER_EXPR:
1742 if (EH_FILTER_MUST_NOT_THROW (stmt))
1743 this_may_throw = false;
1744 else if (EH_FILTER_TYPES (stmt) == NULL)
1745 this_may_throw = false;
1746 remove_useless_stmts_1 (&EH_FILTER_FAILURE (stmt), data);
1750 /* Otherwise this is a cleanup. */
1751 remove_useless_stmts_1 (&TREE_OPERAND (*stmt_p, 1), data);
1753 /* If the cleanup is empty, then we can emit the TRY block without
1754 the enclosing TRY_CATCH_EXPR. */
1755 if (!TREE_SIDE_EFFECTS (TREE_OPERAND (*stmt_p, 1)))
1757 *stmt_p = TREE_OPERAND (*stmt_p, 0);
1758 data->repeat = true;
1762 data->may_throw |= this_may_throw;
1767 remove_useless_stmts_bind (tree *stmt_p, struct rus_data *data)
1771 /* First remove anything underneath the BIND_EXPR. */
1772 remove_useless_stmts_1 (&BIND_EXPR_BODY (*stmt_p), data);
1774 /* If the BIND_EXPR has no variables, then we can pull everything
1775 up one level and remove the BIND_EXPR, unless this is the toplevel
1776 BIND_EXPR for the current function or an inlined function.
1778 When this situation occurs we will want to apply this
1779 optimization again. */
1780 block = BIND_EXPR_BLOCK (*stmt_p);
1781 if (BIND_EXPR_VARS (*stmt_p) == NULL_TREE
1782 && *stmt_p != DECL_SAVED_TREE (current_function_decl)
1784 || ! BLOCK_ABSTRACT_ORIGIN (block)
1785 || (TREE_CODE (BLOCK_ABSTRACT_ORIGIN (block))
1788 *stmt_p = BIND_EXPR_BODY (*stmt_p);
1789 data->repeat = true;
1795 remove_useless_stmts_goto (tree *stmt_p, struct rus_data *data)
1797 tree dest = GOTO_DESTINATION (*stmt_p);
1799 data->may_branch = true;
1800 data->last_goto = NULL;
1802 /* Record the last goto expr, so that we can delete it if unnecessary. */
1803 if (TREE_CODE (dest) == LABEL_DECL)
1804 data->last_goto = stmt_p;
1809 remove_useless_stmts_label (tree *stmt_p, struct rus_data *data)
1811 tree label = LABEL_EXPR_LABEL (*stmt_p);
1813 data->has_label = true;
1815 /* We do want to jump across non-local label receiver code. */
1816 if (DECL_NONLOCAL (label))
1817 data->last_goto = NULL;
1819 else if (data->last_goto && GOTO_DESTINATION (*data->last_goto) == label)
1821 *data->last_goto = build_empty_stmt ();
1822 data->repeat = true;
1825 /* ??? Add something here to delete unused labels. */
1829 /* If the function is "const" or "pure", then clear TREE_SIDE_EFFECTS on its
1830 decl. This allows us to eliminate redundant or useless
1831 calls to "const" functions.
1833 Gimplifier already does the same operation, but we may notice functions
1834 being const and pure once their calls has been gimplified, so we need
1835 to update the flag. */
1838 update_call_expr_flags (tree call)
1840 tree decl = get_callee_fndecl (call);
1843 if (call_expr_flags (call) & (ECF_CONST | ECF_PURE))
1844 TREE_SIDE_EFFECTS (call) = 0;
1845 if (TREE_NOTHROW (decl))
1846 TREE_NOTHROW (call) = 1;
1850 /* T is CALL_EXPR. Set current_function_calls_* flags. */
1853 notice_special_calls (tree t)
1855 int flags = call_expr_flags (t);
1857 if (flags & ECF_MAY_BE_ALLOCA)
1858 current_function_calls_alloca = true;
1859 if (flags & ECF_RETURNS_TWICE)
1860 current_function_calls_setjmp = true;
1864 /* Clear flags set by notice_special_calls. Used by dead code removal
1865 to update the flags. */
1868 clear_special_calls (void)
1870 current_function_calls_alloca = false;
1871 current_function_calls_setjmp = false;
1876 remove_useless_stmts_1 (tree *tp, struct rus_data *data)
1880 switch (TREE_CODE (t))
1883 remove_useless_stmts_cond (tp, data);
1886 case TRY_FINALLY_EXPR:
1887 remove_useless_stmts_tf (tp, data);
1890 case TRY_CATCH_EXPR:
1891 remove_useless_stmts_tc (tp, data);
1895 remove_useless_stmts_bind (tp, data);
1899 remove_useless_stmts_goto (tp, data);
1903 remove_useless_stmts_label (tp, data);
1908 data->last_goto = NULL;
1909 data->may_branch = true;
1914 data->last_goto = NULL;
1915 notice_special_calls (t);
1916 update_call_expr_flags (t);
1917 if (tree_could_throw_p (t))
1918 data->may_throw = true;
1922 data->last_goto = NULL;
1924 op = get_call_expr_in (t);
1927 update_call_expr_flags (op);
1928 notice_special_calls (op);
1930 if (tree_could_throw_p (t))
1931 data->may_throw = true;
1934 case STATEMENT_LIST:
1936 tree_stmt_iterator i = tsi_start (t);
1937 while (!tsi_end_p (i))
1940 if (IS_EMPTY_STMT (t))
1946 remove_useless_stmts_1 (tsi_stmt_ptr (i), data);
1949 if (TREE_CODE (t) == STATEMENT_LIST)
1951 tsi_link_before (&i, t, TSI_SAME_STMT);
1961 data->last_goto = NULL;
1965 data->last_goto = NULL;
1971 remove_useless_stmts (void)
1973 struct rus_data data;
1975 clear_special_calls ();
1979 memset (&data, 0, sizeof (data));
1980 remove_useless_stmts_1 (&DECL_SAVED_TREE (current_function_decl), &data);
1982 while (data.repeat);
1986 struct tree_opt_pass pass_remove_useless_stmts =
1988 "useless", /* name */
1990 remove_useless_stmts, /* execute */
1993 0, /* static_pass_number */
1995 PROP_gimple_any, /* properties_required */
1996 0, /* properties_provided */
1997 0, /* properties_destroyed */
1998 0, /* todo_flags_start */
1999 TODO_dump_func, /* todo_flags_finish */
2003 /* Remove PHI nodes associated with basic block BB and all edges out of BB. */
2006 remove_phi_nodes_and_edges_for_unreachable_block (basic_block bb)
2010 /* Since this block is no longer reachable, we can just delete all
2011 of its PHI nodes. */
2012 phi = phi_nodes (bb);
2015 tree next = PHI_CHAIN (phi);
2016 remove_phi_node (phi, NULL_TREE);
2020 /* Remove edges to BB's successors. */
2021 while (EDGE_COUNT (bb->succs) > 0)
2022 remove_edge (EDGE_SUCC (bb, 0));
2026 /* Remove statements of basic block BB. */
2029 remove_bb (basic_block bb)
2031 block_stmt_iterator i;
2032 #ifdef USE_MAPPED_LOCATION
2033 source_location loc = UNKNOWN_LOCATION;
2035 source_locus loc = 0;
2040 fprintf (dump_file, "Removing basic block %d\n", bb->index);
2041 if (dump_flags & TDF_DETAILS)
2043 dump_bb (bb, dump_file, 0);
2044 fprintf (dump_file, "\n");
2048 /* If we remove the header or the latch of a loop, mark the loop for
2049 removal by setting its header and latch to NULL. */
2052 struct loop *loop = bb->loop_father;
2054 if (loop->latch == bb
2055 || loop->header == bb)
2058 loop->header = NULL;
2062 /* Remove all the instructions in the block. */
2063 for (i = bsi_start (bb); !bsi_end_p (i);)
2065 tree stmt = bsi_stmt (i);
2066 if (TREE_CODE (stmt) == LABEL_EXPR
2067 && FORCED_LABEL (LABEL_EXPR_LABEL (stmt)))
2069 basic_block new_bb = bb->prev_bb;
2070 block_stmt_iterator new_bsi = bsi_start (new_bb);
2073 bsi_insert_before (&new_bsi, stmt, BSI_NEW_STMT);
2077 release_defs (stmt);
2082 /* Don't warn for removed gotos. Gotos are often removed due to
2083 jump threading, thus resulting in bogus warnings. Not great,
2084 since this way we lose warnings for gotos in the original
2085 program that are indeed unreachable. */
2086 if (TREE_CODE (stmt) != GOTO_EXPR && EXPR_HAS_LOCATION (stmt) && !loc)
2088 #ifdef USE_MAPPED_LOCATION
2089 if (EXPR_HAS_LOCATION (stmt))
2090 loc = EXPR_LOCATION (stmt);
2093 t = EXPR_LOCUS (stmt);
2094 if (t && LOCATION_LINE (*t) > 0)
2100 /* If requested, give a warning that the first statement in the
2101 block is unreachable. We walk statements backwards in the
2102 loop above, so the last statement we process is the first statement
2104 #ifdef USE_MAPPED_LOCATION
2105 if (warn_notreached && loc > BUILTINS_LOCATION)
2106 warning (0, "%Hwill never be executed", &loc);
2108 if (warn_notreached && loc)
2109 warning (0, "%Hwill never be executed", loc);
2112 remove_phi_nodes_and_edges_for_unreachable_block (bb);
2115 /* A list of all the noreturn calls passed to modify_stmt.
2116 cleanup_control_flow uses it to detect cases where a mid-block
2117 indirect call has been turned into a noreturn call. When this
2118 happens, all the instructions after the call are no longer
2119 reachable and must be deleted as dead. */
2121 VEC(tree,gc) *modified_noreturn_calls;
2123 /* Try to remove superfluous control structures. */
2126 cleanup_control_flow (void)
2129 block_stmt_iterator bsi;
2130 bool retval = false;
2133 /* Detect cases where a mid-block call is now known not to return. */
2134 while (VEC_length (tree, modified_noreturn_calls))
2136 stmt = VEC_pop (tree, modified_noreturn_calls);
2137 bb = bb_for_stmt (stmt);
2138 if (bb != NULL && last_stmt (bb) != stmt && noreturn_call_p (stmt))
2139 split_block (bb, stmt);
2144 bsi = bsi_last (bb);
2146 if (bsi_end_p (bsi))
2149 stmt = bsi_stmt (bsi);
2150 if (TREE_CODE (stmt) == COND_EXPR
2151 || TREE_CODE (stmt) == SWITCH_EXPR)
2152 retval |= cleanup_control_expr_graph (bb, bsi);
2154 /* If we had a computed goto which has a compile-time determinable
2155 destination, then we can eliminate the goto. */
2156 if (TREE_CODE (stmt) == GOTO_EXPR
2157 && TREE_CODE (GOTO_DESTINATION (stmt)) == ADDR_EXPR
2158 && TREE_CODE (TREE_OPERAND (GOTO_DESTINATION (stmt), 0)) == LABEL_DECL)
2163 basic_block target_block;
2164 bool removed_edge = false;
2166 /* First look at all the outgoing edges. Delete any outgoing
2167 edges which do not go to the right block. For the one
2168 edge which goes to the right block, fix up its flags. */
2169 label = TREE_OPERAND (GOTO_DESTINATION (stmt), 0);
2170 target_block = label_to_block (label);
2171 for (ei = ei_start (bb->succs); (e = ei_safe_edge (ei)); )
2173 if (e->dest != target_block)
2175 removed_edge = true;
2180 /* Turn off the EDGE_ABNORMAL flag. */
2181 e->flags &= ~EDGE_ABNORMAL;
2183 /* And set EDGE_FALLTHRU. */
2184 e->flags |= EDGE_FALLTHRU;
2189 /* If we removed one or more edges, then we will need to fix the
2190 dominators. It may be possible to incrementally update them. */
2192 free_dominance_info (CDI_DOMINATORS);
2194 /* Remove the GOTO_EXPR as it is not needed. The CFG has all the
2195 relevant information we need. */
2200 /* Check for indirect calls that have been turned into
2202 if (noreturn_call_p (stmt) && remove_fallthru_edge (bb->succs))
2204 free_dominance_info (CDI_DOMINATORS);
2212 /* Disconnect an unreachable block in the control expression starting
2216 cleanup_control_expr_graph (basic_block bb, block_stmt_iterator bsi)
2219 bool retval = false;
2220 tree expr = bsi_stmt (bsi), val;
2222 if (!single_succ_p (bb))
2227 switch (TREE_CODE (expr))
2230 val = COND_EXPR_COND (expr);
2234 val = SWITCH_COND (expr);
2235 if (TREE_CODE (val) != INTEGER_CST)
2243 taken_edge = find_taken_edge (bb, val);
2247 /* Remove all the edges except the one that is always executed. */
2248 for (ei = ei_start (bb->succs); (e = ei_safe_edge (ei)); )
2250 if (e != taken_edge)
2252 taken_edge->probability += e->probability;
2253 taken_edge->count += e->count;
2260 if (taken_edge->probability > REG_BR_PROB_BASE)
2261 taken_edge->probability = REG_BR_PROB_BASE;
2264 taken_edge = single_succ_edge (bb);
2267 taken_edge->flags = EDGE_FALLTHRU;
2269 /* We removed some paths from the cfg. */
2270 free_dominance_info (CDI_DOMINATORS);
2275 /* Remove any fallthru edge from EV. Return true if an edge was removed. */
2278 remove_fallthru_edge (VEC(edge,gc) *ev)
2283 FOR_EACH_EDGE (e, ei, ev)
2284 if ((e->flags & EDGE_FALLTHRU) != 0)
2292 /* Given a basic block BB ending with COND_EXPR or SWITCH_EXPR, and a
2293 predicate VAL, return the edge that will be taken out of the block.
2294 If VAL does not match a unique edge, NULL is returned. */
2297 find_taken_edge (basic_block bb, tree val)
2301 stmt = last_stmt (bb);
2304 gcc_assert (is_ctrl_stmt (stmt));
2307 if (! is_gimple_min_invariant (val))
2310 if (TREE_CODE (stmt) == COND_EXPR)
2311 return find_taken_edge_cond_expr (bb, val);
2313 if (TREE_CODE (stmt) == SWITCH_EXPR)
2314 return find_taken_edge_switch_expr (bb, val);
2316 if (computed_goto_p (stmt))
2317 return find_taken_edge_computed_goto (bb, TREE_OPERAND( val, 0));
2322 /* Given a constant value VAL and the entry block BB to a GOTO_EXPR
2323 statement, determine which of the outgoing edges will be taken out of the
2324 block. Return NULL if either edge may be taken. */
2327 find_taken_edge_computed_goto (basic_block bb, tree val)
2332 dest = label_to_block (val);
2335 e = find_edge (bb, dest);
2336 gcc_assert (e != NULL);
2342 /* Given a constant value VAL and the entry block BB to a COND_EXPR
2343 statement, determine which of the two edges will be taken out of the
2344 block. Return NULL if either edge may be taken. */
2347 find_taken_edge_cond_expr (basic_block bb, tree val)
2349 edge true_edge, false_edge;
2351 extract_true_false_edges_from_block (bb, &true_edge, &false_edge);
2353 gcc_assert (TREE_CODE (val) == INTEGER_CST);
2354 return (zero_p (val) ? false_edge : true_edge);
2357 /* Given an INTEGER_CST VAL and the entry block BB to a SWITCH_EXPR
2358 statement, determine which edge will be taken out of the block. Return
2359 NULL if any edge may be taken. */
2362 find_taken_edge_switch_expr (basic_block bb, tree val)
2364 tree switch_expr, taken_case;
2365 basic_block dest_bb;
2368 switch_expr = last_stmt (bb);
2369 taken_case = find_case_label_for_value (switch_expr, val);
2370 dest_bb = label_to_block (CASE_LABEL (taken_case));
2372 e = find_edge (bb, dest_bb);
2378 /* Return the CASE_LABEL_EXPR that SWITCH_EXPR will take for VAL.
2379 We can make optimal use here of the fact that the case labels are
2380 sorted: We can do a binary search for a case matching VAL. */
2383 find_case_label_for_value (tree switch_expr, tree val)
2385 tree vec = SWITCH_LABELS (switch_expr);
2386 size_t low, high, n = TREE_VEC_LENGTH (vec);
2387 tree default_case = TREE_VEC_ELT (vec, n - 1);
2389 for (low = -1, high = n - 1; high - low > 1; )
2391 size_t i = (high + low) / 2;
2392 tree t = TREE_VEC_ELT (vec, i);
2395 /* Cache the result of comparing CASE_LOW and val. */
2396 cmp = tree_int_cst_compare (CASE_LOW (t), val);
2403 if (CASE_HIGH (t) == NULL)
2405 /* A singe-valued case label. */
2411 /* A case range. We can only handle integer ranges. */
2412 if (cmp <= 0 && tree_int_cst_compare (CASE_HIGH (t), val) >= 0)
2417 return default_case;
2421 /* If all the PHI nodes in DEST have alternatives for E1 and E2 and
2422 those alternatives are equal in each of the PHI nodes, then return
2423 true, else return false. */
2426 phi_alternatives_equal (basic_block dest, edge e1, edge e2)
2428 int n1 = e1->dest_idx;
2429 int n2 = e2->dest_idx;
2432 for (phi = phi_nodes (dest); phi; phi = PHI_CHAIN (phi))
2434 tree val1 = PHI_ARG_DEF (phi, n1);
2435 tree val2 = PHI_ARG_DEF (phi, n2);
2437 gcc_assert (val1 != NULL_TREE);
2438 gcc_assert (val2 != NULL_TREE);
2440 if (!operand_equal_for_phi_arg_p (val1, val2))
2448 /*---------------------------------------------------------------------------
2450 ---------------------------------------------------------------------------*/
2452 /* Dump tree-specific information of block BB to file OUTF. */
2455 tree_dump_bb (basic_block bb, FILE *outf, int indent)
2457 dump_generic_bb (outf, bb, indent, TDF_VOPS);
2461 /* Dump a basic block on stderr. */
2464 debug_tree_bb (basic_block bb)
2466 dump_bb (bb, stderr, 0);
2470 /* Dump basic block with index N on stderr. */
2473 debug_tree_bb_n (int n)
2475 debug_tree_bb (BASIC_BLOCK (n));
2476 return BASIC_BLOCK (n);
2480 /* Dump the CFG on stderr.
2482 FLAGS are the same used by the tree dumping functions
2483 (see TDF_* in tree.h). */
2486 debug_tree_cfg (int flags)
2488 dump_tree_cfg (stderr, flags);
2492 /* Dump the program showing basic block boundaries on the given FILE.
2494 FLAGS are the same used by the tree dumping functions (see TDF_* in
2498 dump_tree_cfg (FILE *file, int flags)
2500 if (flags & TDF_DETAILS)
2502 const char *funcname
2503 = lang_hooks.decl_printable_name (current_function_decl, 2);
2506 fprintf (file, ";; Function %s\n\n", funcname);
2507 fprintf (file, ";; \n%d basic blocks, %d edges, last basic block %d.\n\n",
2508 n_basic_blocks, n_edges, last_basic_block);
2510 brief_dump_cfg (file);
2511 fprintf (file, "\n");
2514 if (flags & TDF_STATS)
2515 dump_cfg_stats (file);
2517 dump_function_to_file (current_function_decl, file, flags | TDF_BLOCKS);
2521 /* Dump CFG statistics on FILE. */
2524 dump_cfg_stats (FILE *file)
2526 static long max_num_merged_labels = 0;
2527 unsigned long size, total = 0;
2530 const char * const fmt_str = "%-30s%-13s%12s\n";
2531 const char * const fmt_str_1 = "%-30s%13d%11lu%c\n";
2532 const char * const fmt_str_3 = "%-43s%11lu%c\n";
2533 const char *funcname
2534 = lang_hooks.decl_printable_name (current_function_decl, 2);
2537 fprintf (file, "\nCFG Statistics for %s\n\n", funcname);
2539 fprintf (file, "---------------------------------------------------------\n");
2540 fprintf (file, fmt_str, "", " Number of ", "Memory");
2541 fprintf (file, fmt_str, "", " instances ", "used ");
2542 fprintf (file, "---------------------------------------------------------\n");
2544 size = n_basic_blocks * sizeof (struct basic_block_def);
2546 fprintf (file, fmt_str_1, "Basic blocks", n_basic_blocks,
2547 SCALE (size), LABEL (size));
2551 num_edges += EDGE_COUNT (bb->succs);
2552 size = num_edges * sizeof (struct edge_def);
2554 fprintf (file, fmt_str_1, "Edges", num_edges, SCALE (size), LABEL (size));
2556 size = n_basic_blocks * sizeof (struct bb_ann_d);
2558 fprintf (file, fmt_str_1, "Basic block annotations", n_basic_blocks,
2559 SCALE (size), LABEL (size));
2561 fprintf (file, "---------------------------------------------------------\n");
2562 fprintf (file, fmt_str_3, "Total memory used by CFG data", SCALE (total),
2564 fprintf (file, "---------------------------------------------------------\n");
2565 fprintf (file, "\n");
2567 if (cfg_stats.num_merged_labels > max_num_merged_labels)
2568 max_num_merged_labels = cfg_stats.num_merged_labels;
2570 fprintf (file, "Coalesced label blocks: %ld (Max so far: %ld)\n",
2571 cfg_stats.num_merged_labels, max_num_merged_labels);
2573 fprintf (file, "\n");
2577 /* Dump CFG statistics on stderr. Keep extern so that it's always
2578 linked in the final executable. */
2581 debug_cfg_stats (void)
2583 dump_cfg_stats (stderr);
2587 /* Dump the flowgraph to a .vcg FILE. */
2590 tree_cfg2vcg (FILE *file)
2595 const char *funcname
2596 = lang_hooks.decl_printable_name (current_function_decl, 2);
2598 /* Write the file header. */
2599 fprintf (file, "graph: { title: \"%s\"\n", funcname);
2600 fprintf (file, "node: { title: \"ENTRY\" label: \"ENTRY\" }\n");
2601 fprintf (file, "node: { title: \"EXIT\" label: \"EXIT\" }\n");
2603 /* Write blocks and edges. */
2604 FOR_EACH_EDGE (e, ei, ENTRY_BLOCK_PTR->succs)
2606 fprintf (file, "edge: { sourcename: \"ENTRY\" targetname: \"%d\"",
2609 if (e->flags & EDGE_FAKE)
2610 fprintf (file, " linestyle: dotted priority: 10");
2612 fprintf (file, " linestyle: solid priority: 100");
2614 fprintf (file, " }\n");
2620 enum tree_code head_code, end_code;
2621 const char *head_name, *end_name;
2624 tree first = first_stmt (bb);
2625 tree last = last_stmt (bb);
2629 head_code = TREE_CODE (first);
2630 head_name = tree_code_name[head_code];
2631 head_line = get_lineno (first);
2634 head_name = "no-statement";
2638 end_code = TREE_CODE (last);
2639 end_name = tree_code_name[end_code];
2640 end_line = get_lineno (last);
2643 end_name = "no-statement";
2645 fprintf (file, "node: { title: \"%d\" label: \"#%d\\n%s (%d)\\n%s (%d)\"}\n",
2646 bb->index, bb->index, head_name, head_line, end_name,
2649 FOR_EACH_EDGE (e, ei, bb->succs)
2651 if (e->dest == EXIT_BLOCK_PTR)
2652 fprintf (file, "edge: { sourcename: \"%d\" targetname: \"EXIT\"", bb->index);
2654 fprintf (file, "edge: { sourcename: \"%d\" targetname: \"%d\"", bb->index, e->dest->index);
2656 if (e->flags & EDGE_FAKE)
2657 fprintf (file, " priority: 10 linestyle: dotted");
2659 fprintf (file, " priority: 100 linestyle: solid");
2661 fprintf (file, " }\n");
2664 if (bb->next_bb != EXIT_BLOCK_PTR)
2668 fputs ("}\n\n", file);
2673 /*---------------------------------------------------------------------------
2674 Miscellaneous helpers
2675 ---------------------------------------------------------------------------*/
2677 /* Return true if T represents a stmt that always transfers control. */
2680 is_ctrl_stmt (tree t)
2682 return (TREE_CODE (t) == COND_EXPR
2683 || TREE_CODE (t) == SWITCH_EXPR
2684 || TREE_CODE (t) == GOTO_EXPR
2685 || TREE_CODE (t) == RETURN_EXPR
2686 || TREE_CODE (t) == RESX_EXPR);
2690 /* Return true if T is a statement that may alter the flow of control
2691 (e.g., a call to a non-returning function). */
2694 is_ctrl_altering_stmt (tree t)
2699 call = get_call_expr_in (t);
2702 /* A non-pure/const CALL_EXPR alters flow control if the current
2703 function has nonlocal labels. */
2704 if (TREE_SIDE_EFFECTS (call) && current_function_has_nonlocal_label)
2707 /* A CALL_EXPR also alters control flow if it does not return. */
2708 if (call_expr_flags (call) & ECF_NORETURN)
2712 /* If a statement can throw, it alters control flow. */
2713 return tree_can_throw_internal (t);
2717 /* Return true if T is a computed goto. */
2720 computed_goto_p (tree t)
2722 return (TREE_CODE (t) == GOTO_EXPR
2723 && TREE_CODE (GOTO_DESTINATION (t)) != LABEL_DECL);
2727 /* Checks whether EXPR is a simple local goto. */
2730 simple_goto_p (tree expr)
2732 return (TREE_CODE (expr) == GOTO_EXPR
2733 && TREE_CODE (GOTO_DESTINATION (expr)) == LABEL_DECL);
2737 /* Return true if T should start a new basic block. PREV_T is the
2738 statement preceding T. It is used when T is a label or a case label.
2739 Labels should only start a new basic block if their previous statement
2740 wasn't a label. Otherwise, sequence of labels would generate
2741 unnecessary basic blocks that only contain a single label. */
2744 stmt_starts_bb_p (tree t, tree prev_t)
2749 /* LABEL_EXPRs start a new basic block only if the preceding
2750 statement wasn't a label of the same type. This prevents the
2751 creation of consecutive blocks that have nothing but a single
2753 if (TREE_CODE (t) == LABEL_EXPR)
2755 /* Nonlocal and computed GOTO targets always start a new block. */
2756 if (DECL_NONLOCAL (LABEL_EXPR_LABEL (t))
2757 || FORCED_LABEL (LABEL_EXPR_LABEL (t)))
2760 if (prev_t && TREE_CODE (prev_t) == LABEL_EXPR)
2762 if (DECL_NONLOCAL (LABEL_EXPR_LABEL (prev_t)))
2765 cfg_stats.num_merged_labels++;
2776 /* Return true if T should end a basic block. */
2779 stmt_ends_bb_p (tree t)
2781 return is_ctrl_stmt (t) || is_ctrl_altering_stmt (t);
2785 /* Add gotos that used to be represented implicitly in the CFG. */
2788 disband_implicit_edges (void)
2791 block_stmt_iterator last;
2798 last = bsi_last (bb);
2799 stmt = last_stmt (bb);
2801 if (stmt && TREE_CODE (stmt) == COND_EXPR)
2803 /* Remove superfluous gotos from COND_EXPR branches. Moved
2804 from cfg_remove_useless_stmts here since it violates the
2805 invariants for tree--cfg correspondence and thus fits better
2806 here where we do it anyway. */
2807 e = find_edge (bb, bb->next_bb);
2810 if (e->flags & EDGE_TRUE_VALUE)
2811 COND_EXPR_THEN (stmt) = build_empty_stmt ();
2812 else if (e->flags & EDGE_FALSE_VALUE)
2813 COND_EXPR_ELSE (stmt) = build_empty_stmt ();
2816 e->flags |= EDGE_FALLTHRU;
2822 if (stmt && TREE_CODE (stmt) == RETURN_EXPR)
2824 /* Remove the RETURN_EXPR if we may fall though to the exit
2826 gcc_assert (single_succ_p (bb));
2827 gcc_assert (single_succ (bb) == EXIT_BLOCK_PTR);
2829 if (bb->next_bb == EXIT_BLOCK_PTR
2830 && !TREE_OPERAND (stmt, 0))
2833 single_succ_edge (bb)->flags |= EDGE_FALLTHRU;
2838 /* There can be no fallthru edge if the last statement is a control
2840 if (stmt && is_ctrl_stmt (stmt))
2843 /* Find a fallthru edge and emit the goto if necessary. */
2844 FOR_EACH_EDGE (e, ei, bb->succs)
2845 if (e->flags & EDGE_FALLTHRU)
2848 if (!e || e->dest == bb->next_bb)
2851 gcc_assert (e->dest != EXIT_BLOCK_PTR);
2852 label = tree_block_label (e->dest);
2854 stmt = build1 (GOTO_EXPR, void_type_node, label);
2855 #ifdef USE_MAPPED_LOCATION
2856 SET_EXPR_LOCATION (stmt, e->goto_locus);
2858 SET_EXPR_LOCUS (stmt, e->goto_locus);
2860 bsi_insert_after (&last, stmt, BSI_NEW_STMT);
2861 e->flags &= ~EDGE_FALLTHRU;
2865 /* Remove block annotations and other datastructures. */
2868 delete_tree_cfg_annotations (void)
2871 if (n_basic_blocks > 0)
2872 free_blocks_annotations ();
2874 label_to_block_map = NULL;
2880 /* Return the first statement in basic block BB. */
2883 first_stmt (basic_block bb)
2885 block_stmt_iterator i = bsi_start (bb);
2886 return !bsi_end_p (i) ? bsi_stmt (i) : NULL_TREE;
2890 /* Return the last statement in basic block BB. */
2893 last_stmt (basic_block bb)
2895 block_stmt_iterator b = bsi_last (bb);
2896 return !bsi_end_p (b) ? bsi_stmt (b) : NULL_TREE;
2900 /* Return a pointer to the last statement in block BB. */
2903 last_stmt_ptr (basic_block bb)
2905 block_stmt_iterator last = bsi_last (bb);
2906 return !bsi_end_p (last) ? bsi_stmt_ptr (last) : NULL;
2910 /* Return the last statement of an otherwise empty block. Return NULL
2911 if the block is totally empty, or if it contains more than one
2915 last_and_only_stmt (basic_block bb)
2917 block_stmt_iterator i = bsi_last (bb);
2923 last = bsi_stmt (i);
2928 /* Empty statements should no longer appear in the instruction stream.
2929 Everything that might have appeared before should be deleted by
2930 remove_useless_stmts, and the optimizers should just bsi_remove
2931 instead of smashing with build_empty_stmt.
2933 Thus the only thing that should appear here in a block containing
2934 one executable statement is a label. */
2935 prev = bsi_stmt (i);
2936 if (TREE_CODE (prev) == LABEL_EXPR)
2943 /* Mark BB as the basic block holding statement T. */
2946 set_bb_for_stmt (tree t, basic_block bb)
2948 if (TREE_CODE (t) == PHI_NODE)
2950 else if (TREE_CODE (t) == STATEMENT_LIST)
2952 tree_stmt_iterator i;
2953 for (i = tsi_start (t); !tsi_end_p (i); tsi_next (&i))
2954 set_bb_for_stmt (tsi_stmt (i), bb);
2958 stmt_ann_t ann = get_stmt_ann (t);
2961 /* If the statement is a label, add the label to block-to-labels map
2962 so that we can speed up edge creation for GOTO_EXPRs. */
2963 if (TREE_CODE (t) == LABEL_EXPR)
2967 t = LABEL_EXPR_LABEL (t);
2968 uid = LABEL_DECL_UID (t);
2971 LABEL_DECL_UID (t) = uid = cfun->last_label_uid++;
2972 if (VARRAY_SIZE (label_to_block_map) <= (unsigned) uid)
2973 VARRAY_GROW (label_to_block_map, 3 * uid / 2);
2976 /* We're moving an existing label. Make sure that we've
2977 removed it from the old block. */
2978 gcc_assert (!bb || !VARRAY_BB (label_to_block_map, uid));
2979 VARRAY_BB (label_to_block_map, uid) = bb;
2984 /* Finds iterator for STMT. */
2986 extern block_stmt_iterator
2987 bsi_for_stmt (tree stmt)
2989 block_stmt_iterator bsi;
2991 for (bsi = bsi_start (bb_for_stmt (stmt)); !bsi_end_p (bsi); bsi_next (&bsi))
2992 if (bsi_stmt (bsi) == stmt)
2998 /* Mark statement T as modified, and update it. */
3000 update_modified_stmts (tree t)
3002 if (TREE_CODE (t) == STATEMENT_LIST)
3004 tree_stmt_iterator i;
3006 for (i = tsi_start (t); !tsi_end_p (i); tsi_next (&i))
3008 stmt = tsi_stmt (i);
3009 update_stmt_if_modified (stmt);
3013 update_stmt_if_modified (t);
3016 /* Insert statement (or statement list) T before the statement
3017 pointed-to by iterator I. M specifies how to update iterator I
3018 after insertion (see enum bsi_iterator_update). */
3021 bsi_insert_before (block_stmt_iterator *i, tree t, enum bsi_iterator_update m)
3023 set_bb_for_stmt (t, i->bb);
3024 update_modified_stmts (t);
3025 tsi_link_before (&i->tsi, t, m);
3029 /* Insert statement (or statement list) T after the statement
3030 pointed-to by iterator I. M specifies how to update iterator I
3031 after insertion (see enum bsi_iterator_update). */
3034 bsi_insert_after (block_stmt_iterator *i, tree t, enum bsi_iterator_update m)
3036 set_bb_for_stmt (t, i->bb);
3037 update_modified_stmts (t);
3038 tsi_link_after (&i->tsi, t, m);
3042 /* Remove the statement pointed to by iterator I. The iterator is updated
3043 to the next statement. */
3046 bsi_remove (block_stmt_iterator *i)
3048 tree t = bsi_stmt (*i);
3049 set_bb_for_stmt (t, NULL);
3050 delink_stmt_imm_use (t);
3051 tsi_delink (&i->tsi);
3052 mark_stmt_modified (t);
3056 /* Move the statement at FROM so it comes right after the statement at TO. */
3059 bsi_move_after (block_stmt_iterator *from, block_stmt_iterator *to)
3061 tree stmt = bsi_stmt (*from);
3063 bsi_insert_after (to, stmt, BSI_SAME_STMT);
3067 /* Move the statement at FROM so it comes right before the statement at TO. */
3070 bsi_move_before (block_stmt_iterator *from, block_stmt_iterator *to)
3072 tree stmt = bsi_stmt (*from);
3074 bsi_insert_before (to, stmt, BSI_SAME_STMT);
3078 /* Move the statement at FROM to the end of basic block BB. */
3081 bsi_move_to_bb_end (block_stmt_iterator *from, basic_block bb)
3083 block_stmt_iterator last = bsi_last (bb);
3085 /* Have to check bsi_end_p because it could be an empty block. */
3086 if (!bsi_end_p (last) && is_ctrl_stmt (bsi_stmt (last)))
3087 bsi_move_before (from, &last);
3089 bsi_move_after (from, &last);
3093 /* Replace the contents of the statement pointed to by iterator BSI
3094 with STMT. If PRESERVE_EH_INFO is true, the exception handling
3095 information of the original statement is preserved. */
3098 bsi_replace (const block_stmt_iterator *bsi, tree stmt, bool preserve_eh_info)
3101 tree orig_stmt = bsi_stmt (*bsi);
3103 SET_EXPR_LOCUS (stmt, EXPR_LOCUS (orig_stmt));
3104 set_bb_for_stmt (stmt, bsi->bb);
3106 /* Preserve EH region information from the original statement, if
3107 requested by the caller. */
3108 if (preserve_eh_info)
3110 eh_region = lookup_stmt_eh_region (orig_stmt);
3112 add_stmt_to_eh_region (stmt, eh_region);
3115 delink_stmt_imm_use (orig_stmt);
3116 *bsi_stmt_ptr (*bsi) = stmt;
3117 mark_stmt_modified (stmt);
3118 update_modified_stmts (stmt);
3122 /* Insert the statement pointed-to by BSI into edge E. Every attempt
3123 is made to place the statement in an existing basic block, but
3124 sometimes that isn't possible. When it isn't possible, the edge is
3125 split and the statement is added to the new block.
3127 In all cases, the returned *BSI points to the correct location. The
3128 return value is true if insertion should be done after the location,
3129 or false if it should be done before the location. If new basic block
3130 has to be created, it is stored in *NEW_BB. */
3133 tree_find_edge_insert_loc (edge e, block_stmt_iterator *bsi,
3134 basic_block *new_bb)
3136 basic_block dest, src;
3142 /* If the destination has one predecessor which has no PHI nodes,
3143 insert there. Except for the exit block.
3145 The requirement for no PHI nodes could be relaxed. Basically we
3146 would have to examine the PHIs to prove that none of them used
3147 the value set by the statement we want to insert on E. That
3148 hardly seems worth the effort. */
3149 if (single_pred_p (dest)
3150 && ! phi_nodes (dest)
3151 && dest != EXIT_BLOCK_PTR)
3153 *bsi = bsi_start (dest);
3154 if (bsi_end_p (*bsi))
3157 /* Make sure we insert after any leading labels. */
3158 tmp = bsi_stmt (*bsi);
3159 while (TREE_CODE (tmp) == LABEL_EXPR)
3162 if (bsi_end_p (*bsi))
3164 tmp = bsi_stmt (*bsi);
3167 if (bsi_end_p (*bsi))
3169 *bsi = bsi_last (dest);
3176 /* If the source has one successor, the edge is not abnormal and
3177 the last statement does not end a basic block, insert there.
3178 Except for the entry block. */
3180 if ((e->flags & EDGE_ABNORMAL) == 0
3181 && single_succ_p (src)
3182 && src != ENTRY_BLOCK_PTR)
3184 *bsi = bsi_last (src);
3185 if (bsi_end_p (*bsi))
3188 tmp = bsi_stmt (*bsi);
3189 if (!stmt_ends_bb_p (tmp))
3192 /* Insert code just before returning the value. We may need to decompose
3193 the return in the case it contains non-trivial operand. */
3194 if (TREE_CODE (tmp) == RETURN_EXPR)
3196 tree op = TREE_OPERAND (tmp, 0);
3197 if (!is_gimple_val (op))
3199 gcc_assert (TREE_CODE (op) == MODIFY_EXPR);
3200 bsi_insert_before (bsi, op, BSI_NEW_STMT);
3201 TREE_OPERAND (tmp, 0) = TREE_OPERAND (op, 0);
3208 /* Otherwise, create a new basic block, and split this edge. */
3209 dest = split_edge (e);
3212 e = single_pred_edge (dest);
3217 /* This routine will commit all pending edge insertions, creating any new
3218 basic blocks which are necessary. */
3221 bsi_commit_edge_inserts (void)
3227 bsi_commit_one_edge_insert (single_succ_edge (ENTRY_BLOCK_PTR), NULL);
3230 FOR_EACH_EDGE (e, ei, bb->succs)
3231 bsi_commit_one_edge_insert (e, NULL);
3235 /* Commit insertions pending at edge E. If a new block is created, set NEW_BB
3236 to this block, otherwise set it to NULL. */
3239 bsi_commit_one_edge_insert (edge e, basic_block *new_bb)
3243 if (PENDING_STMT (e))
3245 block_stmt_iterator bsi;
3246 tree stmt = PENDING_STMT (e);
3248 PENDING_STMT (e) = NULL_TREE;
3250 if (tree_find_edge_insert_loc (e, &bsi, new_bb))
3251 bsi_insert_after (&bsi, stmt, BSI_NEW_STMT);
3253 bsi_insert_before (&bsi, stmt, BSI_NEW_STMT);
3258 /* Add STMT to the pending list of edge E. No actual insertion is
3259 made until a call to bsi_commit_edge_inserts () is made. */
3262 bsi_insert_on_edge (edge e, tree stmt)
3264 append_to_statement_list (stmt, &PENDING_STMT (e));
3267 /* Similar to bsi_insert_on_edge+bsi_commit_edge_inserts. If a new
3268 block has to be created, it is returned. */
3271 bsi_insert_on_edge_immediate (edge e, tree stmt)
3273 block_stmt_iterator bsi;
3274 basic_block new_bb = NULL;
3276 gcc_assert (!PENDING_STMT (e));
3278 if (tree_find_edge_insert_loc (e, &bsi, &new_bb))
3279 bsi_insert_after (&bsi, stmt, BSI_NEW_STMT);
3281 bsi_insert_before (&bsi, stmt, BSI_NEW_STMT);
3286 /*---------------------------------------------------------------------------
3287 Tree specific functions for CFG manipulation
3288 ---------------------------------------------------------------------------*/
3290 /* Reinstall those PHI arguments queued in OLD_EDGE to NEW_EDGE. */
3293 reinstall_phi_args (edge new_edge, edge old_edge)
3297 if (!PENDING_STMT (old_edge))
3300 for (var = PENDING_STMT (old_edge), phi = phi_nodes (new_edge->dest);
3302 var = TREE_CHAIN (var), phi = PHI_CHAIN (phi))
3304 tree result = TREE_PURPOSE (var);
3305 tree arg = TREE_VALUE (var);
3307 gcc_assert (result == PHI_RESULT (phi));
3309 add_phi_arg (phi, arg, new_edge);
3312 PENDING_STMT (old_edge) = NULL;
3315 /* Split a (typically critical) edge EDGE_IN. Return the new block.
3316 Abort on abnormal edges. */
3319 tree_split_edge (edge edge_in)
3321 basic_block new_bb, after_bb, dest, src;
3324 /* Abnormal edges cannot be split. */
3325 gcc_assert (!(edge_in->flags & EDGE_ABNORMAL));
3328 dest = edge_in->dest;
3330 /* Place the new block in the block list. Try to keep the new block
3331 near its "logical" location. This is of most help to humans looking
3332 at debugging dumps. */
3333 if (dest->prev_bb && find_edge (dest->prev_bb, dest))
3334 after_bb = edge_in->src;
3336 after_bb = dest->prev_bb;
3338 new_bb = create_empty_bb (after_bb);
3339 new_bb->frequency = EDGE_FREQUENCY (edge_in);
3340 new_bb->count = edge_in->count;
3341 new_edge = make_edge (new_bb, dest, EDGE_FALLTHRU);
3342 new_edge->probability = REG_BR_PROB_BASE;
3343 new_edge->count = edge_in->count;
3345 e = redirect_edge_and_branch (edge_in, new_bb);
3347 reinstall_phi_args (new_edge, e);
3353 /* Return true when BB has label LABEL in it. */
3356 has_label_p (basic_block bb, tree label)
3358 block_stmt_iterator bsi;
3360 for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
3362 tree stmt = bsi_stmt (bsi);
3364 if (TREE_CODE (stmt) != LABEL_EXPR)
3366 if (LABEL_EXPR_LABEL (stmt) == label)
3373 /* Callback for walk_tree, check that all elements with address taken are
3374 properly noticed as such. The DATA is an int* that is 1 if TP was seen
3375 inside a PHI node. */
3378 verify_expr (tree *tp, int *walk_subtrees, void *data ATTRIBUTE_UNUSED)
3381 bool in_phi = (data != NULL);
3386 /* Check operand N for being valid GIMPLE and give error MSG if not.
3387 We check for constants explicitly since they are not considered
3388 gimple invariants if they overflowed. */
3389 #define CHECK_OP(N, MSG) \
3390 do { if (!CONSTANT_CLASS_P (TREE_OPERAND (t, N)) \
3391 && !is_gimple_val (TREE_OPERAND (t, N))) \
3392 { error (MSG); return TREE_OPERAND (t, N); }} while (0)
3394 switch (TREE_CODE (t))
3397 if (SSA_NAME_IN_FREE_LIST (t))
3399 error ("SSA name in freelist but still referenced");
3405 x = fold (ASSERT_EXPR_COND (t));
3406 if (x == boolean_false_node)
3408 error ("ASSERT_EXPR with an always-false condition");
3414 x = TREE_OPERAND (t, 0);
3415 if (TREE_CODE (x) == BIT_FIELD_REF
3416 && is_gimple_reg (TREE_OPERAND (x, 0)))
3418 error ("GIMPLE register modified with BIT_FIELD_REF");
3424 /* ??? tree-ssa-alias.c may have overlooked dead PHI nodes, missing
3425 dead PHIs that take the address of something. But if the PHI
3426 result is dead, the fact that it takes the address of anything
3427 is irrelevant. Because we can not tell from here if a PHI result
3428 is dead, we just skip this check for PHIs altogether. This means
3429 we may be missing "valid" checks, but what can you do?
3430 This was PR19217. */
3434 /* Skip any references (they will be checked when we recurse down the
3435 tree) and ensure that any variable used as a prefix is marked
3437 for (x = TREE_OPERAND (t, 0);
3438 handled_component_p (x);
3439 x = TREE_OPERAND (x, 0))
3442 if (TREE_CODE (x) != VAR_DECL && TREE_CODE (x) != PARM_DECL)
3444 if (!TREE_ADDRESSABLE (x))
3446 error ("address taken, but ADDRESSABLE bit not set");
3452 x = COND_EXPR_COND (t);
3453 if (TREE_CODE (TREE_TYPE (x)) != BOOLEAN_TYPE)
3455 error ("non-boolean used in condition");
3462 case FIX_TRUNC_EXPR:
3464 case FIX_FLOOR_EXPR:
3465 case FIX_ROUND_EXPR:
3470 case NON_LVALUE_EXPR:
3471 case TRUTH_NOT_EXPR:
3472 CHECK_OP (0, "Invalid operand to unary operator");
3479 case ARRAY_RANGE_REF:
3481 case VIEW_CONVERT_EXPR:
3482 /* We have a nest of references. Verify that each of the operands
3483 that determine where to reference is either a constant or a variable,
3484 verify that the base is valid, and then show we've already checked
3486 while (handled_component_p (t))
3488 if (TREE_CODE (t) == COMPONENT_REF && TREE_OPERAND (t, 2))
3489 CHECK_OP (2, "Invalid COMPONENT_REF offset operator");
3490 else if (TREE_CODE (t) == ARRAY_REF
3491 || TREE_CODE (t) == ARRAY_RANGE_REF)
3493 CHECK_OP (1, "Invalid array index.");
3494 if (TREE_OPERAND (t, 2))
3495 CHECK_OP (2, "Invalid array lower bound.");
3496 if (TREE_OPERAND (t, 3))
3497 CHECK_OP (3, "Invalid array stride.");
3499 else if (TREE_CODE (t) == BIT_FIELD_REF)
3501 CHECK_OP (1, "Invalid operand to BIT_FIELD_REF");
3502 CHECK_OP (2, "Invalid operand to BIT_FIELD_REF");
3505 t = TREE_OPERAND (t, 0);
3508 if (!CONSTANT_CLASS_P (t) && !is_gimple_lvalue (t))
3510 error ("Invalid reference prefix.");
3522 case UNORDERED_EXPR:
3533 case TRUNC_DIV_EXPR:
3535 case FLOOR_DIV_EXPR:
3536 case ROUND_DIV_EXPR:
3537 case TRUNC_MOD_EXPR:
3539 case FLOOR_MOD_EXPR:
3540 case ROUND_MOD_EXPR:
3542 case EXACT_DIV_EXPR:
3552 CHECK_OP (0, "Invalid operand to binary operator");
3553 CHECK_OP (1, "Invalid operand to binary operator");
3565 /* Verify STMT, return true if STMT is not in GIMPLE form.
3566 TODO: Implement type checking. */
3569 verify_stmt (tree stmt, bool last_in_block)
3573 if (!is_gimple_stmt (stmt))
3575 error ("Is not a valid GIMPLE statement.");
3579 addr = walk_tree (&stmt, verify_expr, NULL, NULL);
3582 debug_generic_stmt (addr);
3586 /* If the statement is marked as part of an EH region, then it is
3587 expected that the statement could throw. Verify that when we
3588 have optimizations that simplify statements such that we prove
3589 that they cannot throw, that we update other data structures
3591 if (lookup_stmt_eh_region (stmt) >= 0)
3593 if (!tree_could_throw_p (stmt))
3595 error ("Statement marked for throw, but doesn%'t.");
3598 if (!last_in_block && tree_can_throw_internal (stmt))
3600 error ("Statement marked for throw in middle of block.");
3608 debug_generic_stmt (stmt);
3613 /* Return true when the T can be shared. */
3616 tree_node_can_be_shared (tree t)
3618 if (IS_TYPE_OR_DECL_P (t)
3619 /* We check for constants explicitly since they are not considered
3620 gimple invariants if they overflowed. */
3621 || CONSTANT_CLASS_P (t)
3622 || is_gimple_min_invariant (t)
3623 || TREE_CODE (t) == SSA_NAME
3624 || t == error_mark_node)
3627 if (TREE_CODE (t) == CASE_LABEL_EXPR)
3630 while (((TREE_CODE (t) == ARRAY_REF || TREE_CODE (t) == ARRAY_RANGE_REF)
3631 /* We check for constants explicitly since they are not considered
3632 gimple invariants if they overflowed. */
3633 && (CONSTANT_CLASS_P (TREE_OPERAND (t, 1))
3634 || is_gimple_min_invariant (TREE_OPERAND (t, 1))))
3635 || (TREE_CODE (t) == COMPONENT_REF
3636 || TREE_CODE (t) == REALPART_EXPR
3637 || TREE_CODE (t) == IMAGPART_EXPR))
3638 t = TREE_OPERAND (t, 0);
3647 /* Called via walk_trees. Verify tree sharing. */
3650 verify_node_sharing (tree * tp, int *walk_subtrees, void *data)
3652 htab_t htab = (htab_t) data;
3655 if (tree_node_can_be_shared (*tp))
3657 *walk_subtrees = false;
3661 slot = htab_find_slot (htab, *tp, INSERT);
3670 /* Verify the GIMPLE statement chain. */
3676 block_stmt_iterator bsi;
3681 timevar_push (TV_TREE_STMT_VERIFY);
3682 htab = htab_create (37, htab_hash_pointer, htab_eq_pointer, NULL);
3689 for (phi = phi_nodes (bb); phi; phi = PHI_CHAIN (phi))
3691 int phi_num_args = PHI_NUM_ARGS (phi);
3693 if (bb_for_stmt (phi) != bb)
3695 error ("bb_for_stmt (phi) is set to a wrong basic block\n");
3699 for (i = 0; i < phi_num_args; i++)
3701 tree t = PHI_ARG_DEF (phi, i);
3704 /* Addressable variables do have SSA_NAMEs but they
3705 are not considered gimple values. */
3706 if (TREE_CODE (t) != SSA_NAME
3707 && TREE_CODE (t) != FUNCTION_DECL
3708 && !is_gimple_val (t))
3710 error ("PHI def is not a GIMPLE value");
3711 debug_generic_stmt (phi);