comparison gcc/stmt.c @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
children
comparison
equal deleted inserted replaced
131:84e7813d76e9 145:1830386684a0
1 /* Expands front end tree to back end RTL for GCC 1 /* Expands front end tree to back end RTL for GCC
2 Copyright (C) 1987-2018 Free Software Foundation, Inc. 2 Copyright (C) 1987-2020 Free Software Foundation, Inc.
3 3
4 This file is part of GCC. 4 This file is part of GCC.
5 5
6 GCC is free software; you can redistribute it and/or modify it under 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 7 the terms of the GNU General Public License as published by the Free
48 #include "stmt.h" 48 #include "stmt.h"
49 #include "expr.h" 49 #include "expr.h"
50 #include "langhooks.h" 50 #include "langhooks.h"
51 #include "cfganal.h" 51 #include "cfganal.h"
52 #include "tree-cfg.h" 52 #include "tree-cfg.h"
53 #include "params.h"
54 #include "dumpfile.h" 53 #include "dumpfile.h"
55 #include "builtins.h" 54 #include "builtins.h"
56 55
57 56
58 /* Functions and data structures for expanding case statements. */ 57 /* Functions and data structures for expanding case statements. */
66 65
67 Switch statements are expanded in jump table form. 66 Switch statements are expanded in jump table form.
68 67
69 */ 68 */
70 69
71 struct simple_case_node 70 class simple_case_node
72 { 71 {
72 public:
73 simple_case_node (tree low, tree high, tree code_label): 73 simple_case_node (tree low, tree high, tree code_label):
74 m_low (low), m_high (high), m_code_label (code_label) 74 m_low (low), m_high (high), m_code_label (code_label)
75 {} 75 {}
76 76
77 /* Lowest index value for this label. */ 77 /* Lowest index value for this label. */
519 } 519 }
520 520
521 return true; 521 return true;
522 522
523 failure: 523 failure:
524 error ("duplicate asm operand name %qs", TREE_STRING_POINTER (i_name)); 524 error ("duplicate %<asm%> operand name %qs", TREE_STRING_POINTER (i_name));
525 return false; 525 return false;
526 } 526 }
527 527
528 /* Resolve the names of the operands in *POUTPUTS and *PINPUTS to numbers, 528 /* Resolve the names of the operands in *POUTPUTS and *PINPUTS to numbers,
529 and replace the name expansions in STRING and in the constraints to 529 and replace the name expansions in STRING and in the constraints to
882 int ncases = gimple_switch_num_labels (stmt); 882 int ncases = gimple_switch_num_labels (stmt);
883 tree index_expr = gimple_switch_index (stmt); 883 tree index_expr = gimple_switch_index (stmt);
884 tree index_type = TREE_TYPE (index_expr); 884 tree index_type = TREE_TYPE (index_expr);
885 tree elt; 885 tree elt;
886 basic_block bb = gimple_bb (stmt); 886 basic_block bb = gimple_bb (stmt);
887 gimple *def_stmt;
887 888
888 auto_vec<simple_case_node> case_list; 889 auto_vec<simple_case_node> case_list;
889 890
890 /* An ERROR_MARK occurs for various reasons including invalid data type. 891 /* An ERROR_MARK occurs for various reasons including invalid data type.
891 ??? Can this still happen, with GIMPLE and all? */ 892 ??? Can this still happen, with GIMPLE and all? */
915 if (CASE_HIGH (elt)) 916 if (CASE_HIGH (elt))
916 maxval = fold_convert (index_type, CASE_HIGH (elt)); 917 maxval = fold_convert (index_type, CASE_HIGH (elt));
917 else 918 else
918 maxval = fold_convert (index_type, CASE_LOW (elt)); 919 maxval = fold_convert (index_type, CASE_LOW (elt));
919 920
921 /* Try to narrow the index type if it's larger than a word.
922 That is mainly for -O0 where an equivalent optimization
923 done by forward propagation is not run and is aimed at
924 avoiding a call to a comparison routine of libgcc. */
925 if (TYPE_PRECISION (index_type) > BITS_PER_WORD
926 && TREE_CODE (index_expr) == SSA_NAME
927 && (def_stmt = SSA_NAME_DEF_STMT (index_expr))
928 && is_gimple_assign (def_stmt)
929 && gimple_assign_rhs_code (def_stmt) == NOP_EXPR)
930 {
931 tree inner_index_expr = gimple_assign_rhs1 (def_stmt);
932 tree inner_index_type = TREE_TYPE (inner_index_expr);
933
934 if (INTEGRAL_TYPE_P (inner_index_type)
935 && TYPE_PRECISION (inner_index_type) <= BITS_PER_WORD
936 && int_fits_type_p (minval, inner_index_type)
937 && int_fits_type_p (maxval, inner_index_type))
938 {
939 index_expr = inner_index_expr;
940 index_type = inner_index_type;
941 minval = fold_convert (index_type, minval);
942 maxval = fold_convert (index_type, maxval);
943 }
944 }
945
920 /* Compute span of values. */ 946 /* Compute span of values. */
921 range = fold_build2 (MINUS_EXPR, index_type, maxval, minval); 947 range = fold_build2 (MINUS_EXPR, index_type, maxval, minval);
922 948
923 /* Listify the labels queue and gather some numbers to decide 949 /* Listify the labels queue and gather some numbers to decide
924 how to expand this switch(). */ 950 how to expand this switch(). */
966 type, so we should never get a zero here. */ 992 type, so we should never get a zero here. */
967 gcc_assert (count > 0); 993 gcc_assert (count > 0);
968 994
969 rtx_insn *before_case = get_last_insn (); 995 rtx_insn *before_case = get_last_insn ();
970 996
971 /* Decide how to expand this switch. 997 /* If the default case is unreachable, then set default_label to NULL
972 The two options at this point are a dispatch table (casesi or 998 so that we omit the range check when generating the dispatch table.
973 tablejump) or a decision tree. */ 999 We also remove the edge to the unreachable default case. The block
974 1000 itself will be automatically removed later. */
975 { 1001 if (EDGE_COUNT (default_edge->dest->succs) == 0
976 /* If the default case is unreachable, then set default_label to NULL 1002 && gimple_seq_unreachable_p (bb_seq (default_edge->dest)))
977 so that we omit the range check when generating the dispatch table. 1003 {
978 We also remove the edge to the unreachable default case. The block 1004 default_label = NULL;
979 itself will be automatically removed later. */ 1005 remove_edge (default_edge);
980 if (EDGE_COUNT (default_edge->dest->succs) == 0 1006 default_edge = NULL;
981 && gimple_seq_unreachable_p (bb_seq (default_edge->dest))) 1007 }
982 { 1008
983 default_label = NULL; 1009 emit_case_dispatch_table (index_expr, index_type,
984 remove_edge (default_edge); 1010 case_list, default_label, default_edge,
985 default_edge = NULL; 1011 minval, maxval, range, bb);
986 }
987 emit_case_dispatch_table (index_expr, index_type,
988 case_list, default_label, default_edge,
989 minval, maxval, range, bb);
990 }
991 1012
992 reorder_insns (NEXT_INSN (before_case), get_last_insn (), before_case); 1013 reorder_insns (NEXT_INSN (before_case), get_last_insn (), before_case);
993 1014
994 free_temp_slots (); 1015 free_temp_slots ();
995 } 1016 }