Fix PR ada/97504 on hppa*-*-hpux*.
[official-gcc.git] / gcc / tree-switch-conversion.h
blob7515e952eb361c855df686795f302c30b342b763
1 /* Tree switch conversion for GNU compiler.
2 Copyright (C) 2017-2020 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #ifndef TREE_SWITCH_CONVERSION_H
21 #define TREE_SWITCH_CONVERSION_H
23 namespace tree_switch_conversion {
25 /* Type of cluster. */
27 enum cluster_type
29 SIMPLE_CASE,
30 JUMP_TABLE,
31 BIT_TEST
34 #define PRINT_CASE(f,c) print_generic_expr (f, c)
36 /* Abstract base class for representing a cluster of cases.
38 Here is the inheritance hierarachy, and the enum_cluster_type
39 values for the concrete subclasses:
41 cluster
42 |-simple_cluster (SIMPLE_CASE)
43 `-group_cluster
44 |-jump_table_cluster (JUMP_TABLE)
45 `-bit_test_cluster (BIT_TEST). */
47 class cluster
49 public:
50 /* Constructor. */
51 cluster (tree case_label_expr, basic_block case_bb, profile_probability prob,
52 profile_probability subtree_prob);
54 /* Destructor. */
55 virtual ~cluster ()
58 /* Return type. */
59 virtual cluster_type get_type () = 0;
61 /* Get low value covered by a cluster. */
62 virtual tree get_low () = 0;
64 /* Get high value covered by a cluster. */
65 virtual tree get_high () = 0;
67 /* Debug content of a cluster. */
68 virtual void debug () = 0;
70 /* Dump content of a cluster. */
71 virtual void dump (FILE *f, bool details = false) = 0;
73 /* Emit GIMPLE code to handle the cluster. */
74 virtual void emit (tree, tree, tree, basic_block) = 0;
76 /* Return true if a cluster handles only a single case value and the
77 value is not a range. */
78 virtual bool is_single_value_p ()
80 return false;
83 /* Return range of a cluster. If value would overflow in type of LOW,
84 then return 0. */
85 static unsigned HOST_WIDE_INT get_range (tree low, tree high)
87 wide_int w = wi::to_wide (high) - wi::to_wide (low);
88 if (wi::neg_p (w, TYPE_SIGN (TREE_TYPE (low))) || !wi::fits_uhwi_p (w))
89 return 0;
90 return w.to_uhwi () + 1;
93 /* Case label. */
94 tree m_case_label_expr;
96 /* Basic block of the case. */
97 basic_block m_case_bb;
99 /* Probability of taking this cluster. */
100 profile_probability m_prob;
102 /* Probability of reaching subtree rooted at this node. */
103 profile_probability m_subtree_prob;
105 protected:
106 /* Default constructor. */
107 cluster () {}
110 cluster::cluster (tree case_label_expr, basic_block case_bb,
111 profile_probability prob, profile_probability subtree_prob):
112 m_case_label_expr (case_label_expr), m_case_bb (case_bb), m_prob (prob),
113 m_subtree_prob (subtree_prob)
117 /* Subclass of cluster representing a simple contiguous range
118 from [low..high]. */
120 class simple_cluster: public cluster
122 public:
123 /* Constructor. */
124 simple_cluster (tree low, tree high, tree case_label_expr,
125 basic_block case_bb, profile_probability prob);
127 /* Destructor. */
128 ~simple_cluster ()
131 cluster_type
132 get_type ()
134 return SIMPLE_CASE;
137 tree
138 get_low ()
140 return m_low;
143 tree
144 get_high ()
146 return m_high;
149 void
150 debug ()
152 dump (stderr);
155 void
156 dump (FILE *f, bool details ATTRIBUTE_UNUSED = false)
158 PRINT_CASE (f, get_low ());
159 if (get_low () != get_high ())
161 fprintf (f, "-");
162 PRINT_CASE (f, get_high ());
164 fprintf (f, " ");
167 void emit (tree, tree, tree, basic_block)
169 gcc_unreachable ();
172 bool is_single_value_p ()
174 return tree_int_cst_equal (get_low (), get_high ());
177 /* Low value of the case. */
178 tree m_low;
180 /* High value of the case. */
181 tree m_high;
183 /* True if case is a range. */
184 bool m_range_p;
187 simple_cluster::simple_cluster (tree low, tree high, tree case_label_expr,
188 basic_block case_bb, profile_probability prob):
189 cluster (case_label_expr, case_bb, prob, prob),
190 m_low (low), m_high (high)
192 m_range_p = m_high != NULL;
193 if (m_high == NULL)
194 m_high = m_low;
197 /* Abstract subclass of jump table and bit test cluster,
198 handling a collection of simple_cluster instances. */
200 class group_cluster: public cluster
202 public:
203 /* Constructor. */
204 group_cluster (vec<cluster *> &clusters, unsigned start, unsigned end);
206 /* Destructor. */
207 ~group_cluster ();
209 tree
210 get_low ()
212 return m_cases[0]->get_low ();
215 tree
216 get_high ()
218 return m_cases[m_cases.length () - 1]->get_high ();
221 void
222 debug ()
224 dump (stderr);
227 void dump (FILE *f, bool details = false);
229 /* List of simple clusters handled by the group. */
230 vec<simple_cluster *> m_cases;
233 /* Concrete subclass of group_cluster representing a collection
234 of cases to be implemented as a jump table.
235 The "emit" vfunc gernerates a nested switch statement which
236 is later lowered to a jump table. */
238 class jump_table_cluster: public group_cluster
240 public:
241 /* Constructor. */
242 jump_table_cluster (vec<cluster *> &clusters, unsigned start, unsigned end)
243 : group_cluster (clusters, start, end)
246 cluster_type
247 get_type ()
249 return JUMP_TABLE;
252 void emit (tree index_expr, tree index_type,
253 tree default_label_expr, basic_block default_bb);
255 /* Find jump tables of given CLUSTERS, where all members of the vector
256 are of type simple_cluster. New clusters are returned. */
257 static vec<cluster *> find_jump_tables (vec<cluster *> &clusters);
259 /* Return true when cluster starting at START and ending at END (inclusive)
260 can build a jump-table. */
261 static bool can_be_handled (const vec<cluster *> &clusters, unsigned start,
262 unsigned end);
264 /* Return true if cluster starting at START and ending at END (inclusive)
265 is profitable transformation. */
266 static bool is_beneficial (const vec<cluster *> &clusters, unsigned start,
267 unsigned end);
269 /* Return the smallest number of different values for which it is best
270 to use a jump-table instead of a tree of conditional branches. */
271 static inline unsigned int case_values_threshold (void);
273 /* Return whether jump table expansion is allowed. */
274 static bool is_enabled (void);
277 /* A GIMPLE switch statement can be expanded to a short sequence of bit-wise
278 comparisons. "switch(x)" is converted into "if ((1 << (x-MINVAL)) & CST)"
279 where CST and MINVAL are integer constants. This is better than a series
280 of compare-and-banch insns in some cases, e.g. we can implement:
282 if ((x==4) || (x==6) || (x==9) || (x==11))
284 as a single bit test:
286 if ((1<<x) & ((1<<4)|(1<<6)|(1<<9)|(1<<11)))
288 This transformation is only applied if the number of case targets is small,
289 if CST constains at least 3 bits, and "1 << x" is cheap. The bit tests are
290 performed in "word_mode".
292 The following example shows the code the transformation generates:
294 int bar(int x)
296 switch (x)
298 case '0': case '1': case '2': case '3': case '4':
299 case '5': case '6': case '7': case '8': case '9':
300 case 'A': case 'B': case 'C': case 'D': case 'E':
301 case 'F':
302 return 1;
304 return 0;
309 bar (int x)
311 tmp1 = x - 48;
312 if (tmp1 > (70 - 48)) goto L2;
313 tmp2 = 1 << tmp1;
314 tmp3 = 0b11111100000001111111111;
315 if ((tmp2 & tmp3) != 0) goto L1 ; else goto L2;
317 return 1;
319 return 0;
322 TODO: There are still some improvements to this transformation that could
323 be implemented:
325 * A narrower mode than word_mode could be used if that is cheaper, e.g.
326 for x86_64 where a narrower-mode shift may result in smaller code.
328 * The compounded constant could be shifted rather than the one. The
329 test would be either on the sign bit or on the least significant bit,
330 depending on the direction of the shift. On some machines, the test
331 for the branch would be free if the bit to test is already set by the
332 shift operation.
334 This transformation was contributed by Roger Sayle, see this e-mail:
335 http://gcc.gnu.org/ml/gcc-patches/2003-01/msg01950.html
338 class bit_test_cluster: public group_cluster
340 public:
341 /* Constructor. */
342 bit_test_cluster (vec<cluster *> &clusters, unsigned start, unsigned end,
343 bool handles_entire_switch)
344 :group_cluster (clusters, start, end),
345 m_handles_entire_switch (handles_entire_switch)
348 cluster_type
349 get_type ()
351 return BIT_TEST;
354 /* Expand a switch statement by a short sequence of bit-wise
355 comparisons. "switch(x)" is effectively converted into
356 "if ((1 << (x-MINVAL)) & CST)" where CST and MINVAL are
357 integer constants.
359 INDEX_EXPR is the value being switched on.
361 MINVAL is the lowest case value of in the case nodes,
362 and RANGE is highest value minus MINVAL. MINVAL and RANGE
363 are not guaranteed to be of the same type as INDEX_EXPR
364 (the gimplifier doesn't change the type of case label values,
365 and MINVAL and RANGE are derived from those values).
366 MAXVAL is MINVAL + RANGE.
368 There *MUST* be max_case_bit_tests or less unique case
369 node targets. */
370 void emit (tree index_expr, tree index_type,
371 tree default_label_expr, basic_block default_bb);
373 /* Find bit tests of given CLUSTERS, where all members of the vector
374 are of type simple_cluster. New clusters are returned. */
375 static vec<cluster *> find_bit_tests (vec<cluster *> &clusters);
377 /* Return true when RANGE of case values with UNIQ labels
378 can build a bit test. */
379 static bool can_be_handled (unsigned HOST_WIDE_INT range, unsigned uniq);
381 /* Return true when cluster starting at START and ending at END (inclusive)
382 can build a bit test. */
383 static bool can_be_handled (const vec<cluster *> &clusters, unsigned start,
384 unsigned end);
386 /* Return true when COUNT of cases of UNIQ labels is beneficial for bit test
387 transformation. */
388 static bool is_beneficial (unsigned count, unsigned uniq);
390 /* Return true if cluster starting at START and ending at END (inclusive)
391 is profitable transformation. */
392 static bool is_beneficial (const vec<cluster *> &clusters, unsigned start,
393 unsigned end);
395 /* Split the basic block at the statement pointed to by GSIP, and insert
396 a branch to the target basic block of E_TRUE conditional on tree
397 expression COND.
399 It is assumed that there is already an edge from the to-be-split
400 basic block to E_TRUE->dest block. This edge is removed, and the
401 profile information on the edge is re-used for the new conditional
402 jump.
404 The CFG is updated. The dominator tree will not be valid after
405 this transformation, but the immediate dominators are updated if
406 UPDATE_DOMINATORS is true.
408 Returns the newly created basic block. */
409 static basic_block hoist_edge_and_branch_if_true (gimple_stmt_iterator *gsip,
410 tree cond,
411 basic_block case_bb,
412 profile_probability prob);
414 /* Return whether bit test expansion is allowed. */
415 static inline bool is_enabled (void)
417 return flag_bit_tests;
420 /* True when the jump table handles an entire switch statement. */
421 bool m_handles_entire_switch;
423 /* Maximum number of different basic blocks that can be handled by
424 a bit test. */
425 static const int m_max_case_bit_tests = 3;
428 /* Helper struct to find minimal clusters. */
430 class min_cluster_item
432 public:
433 /* Constructor. */
434 min_cluster_item (unsigned count, unsigned start, unsigned non_jt_cases):
435 m_count (count), m_start (start), m_non_jt_cases (non_jt_cases)
438 /* Count of clusters. */
439 unsigned m_count;
441 /* Index where is cluster boundary. */
442 unsigned m_start;
444 /* Total number of cases that will not be in a jump table. */
445 unsigned m_non_jt_cases;
448 /* Helper struct to represent switch decision tree. */
450 class case_tree_node
452 public:
453 /* Empty Constructor. */
454 case_tree_node ();
456 /* Return true when it has a child. */
457 bool has_child ()
459 return m_left != NULL || m_right != NULL;
462 /* Left son in binary tree. */
463 case_tree_node *m_left;
465 /* Right son in binary tree; also node chain. */
466 case_tree_node *m_right;
468 /* Parent of node in binary tree. */
469 case_tree_node *m_parent;
471 /* Cluster represented by this tree node. */
472 cluster *m_c;
475 inline
476 case_tree_node::case_tree_node ():
477 m_left (NULL), m_right (NULL), m_parent (NULL), m_c (NULL)
481 unsigned int
482 jump_table_cluster::case_values_threshold (void)
484 unsigned int threshold = param_case_values_threshold;
486 if (threshold == 0)
487 threshold = targetm.case_values_threshold ();
489 return threshold;
492 /* Return whether jump table expansion is allowed. */
493 bool jump_table_cluster::is_enabled (void)
495 /* If neither casesi or tablejump is available, or flag_jump_tables
496 over-ruled us, we really have no choice. */
497 if (!targetm.have_casesi () && !targetm.have_tablejump ())
498 return false;
499 if (!flag_jump_tables)
500 return false;
501 #ifndef ASM_OUTPUT_ADDR_DIFF_ELT
502 if (flag_pic)
503 return false;
504 #endif
506 return true;
509 /* A case_bit_test represents a set of case nodes that may be
510 selected from using a bit-wise comparison. HI and LO hold
511 the integer to be tested against, TARGET_EDGE contains the
512 edge to the basic block to jump to upon success and BITS
513 counts the number of case nodes handled by this test,
514 typically the number of bits set in HI:LO. The LABEL field
515 is used to quickly identify all cases in this set without
516 looking at label_to_block for every case label. */
518 class case_bit_test
520 public:
521 wide_int mask;
522 basic_block target_bb;
523 tree label;
524 int bits;
526 /* Comparison function for qsort to order bit tests by decreasing
527 probability of execution. */
528 static int cmp (const void *p1, const void *p2);
531 class switch_decision_tree
533 public:
534 /* Constructor. */
535 switch_decision_tree (gswitch *swtch): m_switch (swtch), m_phi_mapping (),
536 m_case_bbs (), m_case_node_pool ("struct case_node pool"),
537 m_case_list (NULL)
541 /* Analyze switch statement and return true when the statement is expanded
542 as decision tree. */
543 bool analyze_switch_statement ();
545 /* Attempt to expand CLUSTERS as a decision tree. Return true when
546 expanded. */
547 bool try_switch_expansion (vec<cluster *> &clusters);
548 /* Compute the number of case labels that correspond to each outgoing edge of
549 switch statement. Record this information in the aux field of the edge.
551 void compute_cases_per_edge ();
553 /* Before switch transformation, record all SSA_NAMEs defined in switch BB
554 and used in a label basic block. */
555 void record_phi_operand_mapping ();
557 /* Append new operands to PHI statements that were introduced due to
558 addition of new edges to case labels. */
559 void fix_phi_operands_for_edges ();
561 /* Generate a decision tree, switching on INDEX_EXPR and jumping to
562 one of the labels in CASE_LIST or to the DEFAULT_LABEL.
564 We generate a binary decision tree to select the appropriate target
565 code. */
566 void emit (basic_block bb, tree index_expr,
567 profile_probability default_prob, tree index_type);
569 /* Emit step-by-step code to select a case for the value of INDEX.
570 The thus generated decision tree follows the form of the
571 case-node binary tree NODE, whose nodes represent test conditions.
572 DEFAULT_PROB is probability of cases leading to default BB.
573 INDEX_TYPE is the type of the index of the switch. */
574 basic_block emit_case_nodes (basic_block bb, tree index,
575 case_tree_node *node,
576 profile_probability default_prob,
577 tree index_type, location_t);
579 /* Take an ordered list of case nodes
580 and transform them into a near optimal binary tree,
581 on the assumption that any target code selection value is as
582 likely as any other.
584 The transformation is performed by splitting the ordered
585 list into two equal sections plus a pivot. The parts are
586 then attached to the pivot as left and right branches. Each
587 branch is then transformed recursively. */
588 static void balance_case_nodes (case_tree_node **head,
589 case_tree_node *parent);
591 /* Dump ROOT, a list or tree of case nodes, to file F. */
592 static void dump_case_nodes (FILE *f, case_tree_node *root, int indent_step,
593 int indent_level);
595 /* Add an unconditional jump to CASE_BB that happens in basic block BB. */
596 static void emit_jump (basic_block bb, basic_block case_bb);
598 /* Generate code to compare OP0 with OP1 so that the condition codes are
599 set and to jump to LABEL_BB if the condition is true.
600 COMPARISON is the GIMPLE comparison (EQ, NE, GT, etc.).
601 PROB is the probability of jumping to LABEL_BB. */
602 static basic_block emit_cmp_and_jump_insns (basic_block bb, tree op0,
603 tree op1, tree_code comparison,
604 basic_block label_bb,
605 profile_probability prob,
606 location_t);
608 /* Generate code to jump to LABEL if OP0 and OP1 are equal in mode MODE.
609 PROB is the probability of jumping to LABEL_BB. */
610 static basic_block do_jump_if_equal (basic_block bb, tree op0, tree op1,
611 basic_block label_bb,
612 profile_probability prob,
613 location_t);
615 /* Reset the aux field of all outgoing edges of switch basic block. */
616 static inline void reset_out_edges_aux (gswitch *swtch);
618 /* Switch statement. */
619 gswitch *m_switch;
621 /* Map of PHI nodes that have to be fixed after expansion. */
622 hash_map<tree, tree> m_phi_mapping;
624 /* List of basic blocks that belong to labels of the switch. */
625 auto_vec<basic_block> m_case_bbs;
627 /* Basic block with default label. */
628 basic_block m_default_bb;
630 /* A pool for case nodes. */
631 object_allocator<case_tree_node> m_case_node_pool;
633 /* Balanced tree of case nodes. */
634 case_tree_node *m_case_list;
638 Switch initialization conversion
640 The following pass changes simple initializations of scalars in a switch
641 statement into initializations from a static array. Obviously, the values
642 must be constant and known at compile time and a default branch must be
643 provided. For example, the following code:
645 int a,b;
647 switch (argc)
649 case 1:
650 case 2:
651 a_1 = 8;
652 b_1 = 6;
653 break;
654 case 3:
655 a_2 = 9;
656 b_2 = 5;
657 break;
658 case 12:
659 a_3 = 10;
660 b_3 = 4;
661 break;
662 default:
663 a_4 = 16;
664 b_4 = 1;
665 break;
667 a_5 = PHI <a_1, a_2, a_3, a_4>
668 b_5 = PHI <b_1, b_2, b_3, b_4>
671 is changed into:
673 static const int = CSWTCH01[] = {6, 6, 5, 1, 1, 1, 1, 1, 1, 1, 1, 4};
674 static const int = CSWTCH02[] = {8, 8, 9, 16, 16, 16, 16, 16, 16, 16,
675 16, 16, 10};
677 if (((unsigned) argc) - 1 < 11)
679 a_6 = CSWTCH02[argc - 1];
680 b_6 = CSWTCH01[argc - 1];
682 else
684 a_7 = 16;
685 b_7 = 1;
687 a_5 = PHI <a_6, a_7>
688 b_b = PHI <b_6, b_7>
690 There are further constraints. Specifically, the range of values across all
691 case labels must not be bigger than param_switch_conversion_branch_ratio
692 (default eight) times the number of the actual switch branches.
694 This transformation was contributed by Martin Jambor, see this e-mail:
695 http://gcc.gnu.org/ml/gcc-patches/2008-07/msg00011.html */
697 /* The main structure of the pass. */
698 class switch_conversion
700 public:
701 /* Constructor. */
702 switch_conversion ();
704 /* Destructor. */
705 ~switch_conversion ();
707 /* The following function is invoked on every switch statement (the current
708 one is given in SWTCH) and runs the individual phases of switch
709 conversion on it one after another until one fails or the conversion
710 is completed. On success, NULL is in m_reason, otherwise points
711 to a string with the reason why the conversion failed. */
712 void expand (gswitch *swtch);
714 /* Collection information about SWTCH statement. */
715 void collect (gswitch *swtch);
717 /* Checks whether the range given by individual case statements of the switch
718 switch statement isn't too big and whether the number of branches actually
719 satisfies the size of the new array. */
720 bool check_range ();
722 /* Checks whether all but the final BB basic blocks are empty. */
723 bool check_all_empty_except_final ();
725 /* This function checks whether all required values in phi nodes in final_bb
726 are constants. Required values are those that correspond to a basic block
727 which is a part of the examined switch statement. It returns true if the
728 phi nodes are OK, otherwise false. */
729 bool check_final_bb ();
731 /* The following function allocates default_values, target_{in,out}_names and
732 constructors arrays. The last one is also populated with pointers to
733 vectors that will become constructors of new arrays. */
734 void create_temp_arrays ();
736 /* Populate the array of default values in the order of phi nodes.
737 DEFAULT_CASE is the CASE_LABEL_EXPR for the default switch branch
738 if the range is non-contiguous or the default case has standard
739 structure, otherwise it is the first non-default case instead. */
740 void gather_default_values (tree default_case);
742 /* The following function populates the vectors in the constructors array with
743 future contents of the static arrays. The vectors are populated in the
744 order of phi nodes. */
745 void build_constructors ();
747 /* If all values in the constructor vector are products of a linear function
748 a * x + b, then return true. When true, COEFF_A and COEFF_B and
749 coefficients of the linear function. Note that equal values are special
750 case of a linear function with a and b equal to zero. */
751 bool contains_linear_function_p (vec<constructor_elt, va_gc> *vec,
752 wide_int *coeff_a, wide_int *coeff_b);
754 /* Return type which should be used for array elements, either TYPE's
755 main variant or, for integral types, some smaller integral type
756 that can still hold all the constants. */
757 tree array_value_type (tree type, int num);
759 /* Create an appropriate array type and declaration and assemble a static
760 array variable. Also create a load statement that initializes
761 the variable in question with a value from the static array. SWTCH is
762 the switch statement being converted, NUM is the index to
763 arrays of constructors, default values and target SSA names
764 for this particular array. ARR_INDEX_TYPE is the type of the index
765 of the new array, PHI is the phi node of the final BB that corresponds
766 to the value that will be loaded from the created array. TIDX
767 is an ssa name of a temporary variable holding the index for loads from the
768 new array. */
769 void build_one_array (int num, tree arr_index_type,
770 gphi *phi, tree tidx);
772 /* Builds and initializes static arrays initialized with values gathered from
773 the switch statement. Also creates statements that load values from
774 them. */
775 void build_arrays ();
777 /* Generates and appropriately inserts loads of default values at the position
778 given by GSI. Returns the last inserted statement. */
779 gassign *gen_def_assigns (gimple_stmt_iterator *gsi);
781 /* Deletes the unused bbs and edges that now contain the switch statement and
782 its empty branch bbs. BBD is the now dead BB containing
783 the original switch statement, FINAL is the last BB of the converted
784 switch statement (in terms of succession). */
785 void prune_bbs (basic_block bbd, basic_block final, basic_block default_bb);
787 /* Add values to phi nodes in final_bb for the two new edges. E1F is the edge
788 from the basic block loading values from an array and E2F from the basic
789 block loading default values. BBF is the last switch basic block (see the
790 bbf description in the comment below). */
791 void fix_phi_nodes (edge e1f, edge e2f, basic_block bbf);
793 /* Creates a check whether the switch expression value actually falls into the
794 range given by all the cases. If it does not, the temporaries are loaded
795 with default values instead. */
796 void gen_inbound_check ();
798 /* Switch statement for which switch conversion takes place. */
799 gswitch *m_switch;
801 /* The expression used to decide the switch branch. */
802 tree m_index_expr;
804 /* The following integer constants store the minimum and maximum value
805 covered by the case labels. */
806 tree m_range_min;
807 tree m_range_max;
809 /* The difference between the above two numbers. Stored here because it
810 is used in all the conversion heuristics, as well as for some of the
811 transformation, and it is expensive to re-compute it all the time. */
812 tree m_range_size;
814 /* Basic block that contains the actual GIMPLE_SWITCH. */
815 basic_block m_switch_bb;
817 /* Basic block that is the target of the default case. */
818 basic_block m_default_bb;
820 /* The single successor block of all branches out of the GIMPLE_SWITCH,
821 if such a block exists. Otherwise NULL. */
822 basic_block m_final_bb;
824 /* The probability of the default edge in the replaced switch. */
825 profile_probability m_default_prob;
827 /* Number of phi nodes in the final bb (that we'll be replacing). */
828 int m_phi_count;
830 /* Constructors of new static arrays. */
831 vec<constructor_elt, va_gc> **m_constructors;
833 /* Array of default values, in the same order as phi nodes. */
834 tree *m_default_values;
836 /* Array of ssa names that are initialized with a value from a new static
837 array. */
838 tree *m_target_inbound_names;
840 /* Array of ssa names that are initialized with the default value if the
841 switch expression is out of range. */
842 tree *m_target_outbound_names;
844 /* VOP SSA_NAME. */
845 tree m_target_vop;
847 /* The first load statement that loads a temporary from a new static array.
849 gimple *m_arr_ref_first;
851 /* The last load statement that loads a temporary from a new static array. */
852 gimple *m_arr_ref_last;
854 /* String reason why the case wasn't a good candidate that is written to the
855 dump file, if there is one. */
856 const char *m_reason;
858 /* True if default case is not used for any value between range_min and
859 range_max inclusive. */
860 bool m_contiguous_range;
862 /* True if default case does not have the required shape for other case
863 labels. */
864 bool m_default_case_nonstandard;
866 /* Number of uniq labels for non-default edges. */
867 unsigned int m_uniq;
869 /* Count is number of non-default edges. */
870 unsigned int m_count;
872 /* True if CFG has been changed. */
873 bool m_cfg_altered;
876 void
877 switch_decision_tree::reset_out_edges_aux (gswitch *swtch)
879 basic_block bb = gimple_bb (swtch);
880 edge e;
881 edge_iterator ei;
882 FOR_EACH_EDGE (e, ei, bb->succs)
883 e->aux = (void *) 0;
886 } // tree_switch_conversion namespace
888 #endif // TREE_SWITCH_CONVERSION_H