Mercurial > hg > CbC > CbC_gcc
comparison gcc/loop-iv.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 /* Rtl-level induction variable analysis. | 1 /* Rtl-level induction variable analysis. |
2 Copyright (C) 2004-2018 Free Software Foundation, Inc. | 2 Copyright (C) 2004-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 | 6 GCC is free software; you can redistribute it and/or modify it |
7 under the terms of the GNU General Public License as published by the | 7 under the terms of the GNU General Public License as published by the |
59 #include "diagnostic-core.h" | 59 #include "diagnostic-core.h" |
60 #include "cfgloop.h" | 60 #include "cfgloop.h" |
61 #include "intl.h" | 61 #include "intl.h" |
62 #include "dumpfile.h" | 62 #include "dumpfile.h" |
63 #include "rtl-iter.h" | 63 #include "rtl-iter.h" |
64 #include "tree-ssa-loop-niter.h" | |
65 #include "regs.h" | |
66 #include "function-abi.h" | |
64 | 67 |
65 /* Possible return values of iv_get_reaching_def. */ | 68 /* Possible return values of iv_get_reaching_def. */ |
66 | 69 |
67 enum iv_grd_result | 70 enum iv_grd_result |
68 { | 71 { |
82 GRD_SINGLE_DOM | 85 GRD_SINGLE_DOM |
83 }; | 86 }; |
84 | 87 |
85 /* Information about a biv. */ | 88 /* Information about a biv. */ |
86 | 89 |
87 struct biv_entry | 90 class biv_entry |
88 { | 91 { |
92 public: | |
89 unsigned regno; /* The register of the biv. */ | 93 unsigned regno; /* The register of the biv. */ |
90 struct rtx_iv iv; /* Value of the biv. */ | 94 class rtx_iv iv; /* Value of the biv. */ |
91 }; | 95 }; |
92 | 96 |
93 static bool clean_slate = true; | 97 static bool clean_slate = true; |
94 | 98 |
95 static unsigned int iv_ref_table_size = 0; | 99 static unsigned int iv_ref_table_size = 0; |
96 | 100 |
97 /* Table of rtx_ivs indexed by the df_ref uid field. */ | 101 /* Table of rtx_ivs indexed by the df_ref uid field. */ |
98 static struct rtx_iv ** iv_ref_table; | 102 static class rtx_iv ** iv_ref_table; |
99 | 103 |
100 /* Induction variable stored at the reference. */ | 104 /* Induction variable stored at the reference. */ |
101 #define DF_REF_IV(REF) iv_ref_table[DF_REF_ID (REF)] | 105 #define DF_REF_IV(REF) iv_ref_table[DF_REF_ID (REF)] |
102 #define DF_REF_IV_SET(REF, IV) iv_ref_table[DF_REF_ID (REF)] = (IV) | 106 #define DF_REF_IV_SET(REF, IV) iv_ref_table[DF_REF_ID (REF)] = (IV) |
103 | 107 |
104 /* The current loop. */ | 108 /* The current loop. */ |
105 | 109 |
106 static struct loop *current_loop; | 110 static class loop *current_loop; |
107 | 111 |
108 /* Hashtable helper. */ | 112 /* Hashtable helper. */ |
109 | 113 |
110 struct biv_entry_hasher : free_ptr_hash <biv_entry> | 114 struct biv_entry_hasher : free_ptr_hash <biv_entry> |
111 { | 115 { |
132 | 136 |
133 /* Bivs of the current loop. */ | 137 /* Bivs of the current loop. */ |
134 | 138 |
135 static hash_table<biv_entry_hasher> *bivs; | 139 static hash_table<biv_entry_hasher> *bivs; |
136 | 140 |
137 static bool iv_analyze_op (rtx_insn *, scalar_int_mode, rtx, struct rtx_iv *); | 141 static bool iv_analyze_op (rtx_insn *, scalar_int_mode, rtx, class rtx_iv *); |
138 | 142 |
139 /* Return the RTX code corresponding to the IV extend code EXTEND. */ | 143 /* Return the RTX code corresponding to the IV extend code EXTEND. */ |
140 static inline enum rtx_code | 144 static inline enum rtx_code |
141 iv_extend_to_rtx_code (enum iv_extend_code extend) | 145 iv_extend_to_rtx_code (enum iv_extend_code extend) |
142 { | 146 { |
152 gcc_unreachable (); | 156 gcc_unreachable (); |
153 } | 157 } |
154 | 158 |
155 /* Dumps information about IV to FILE. */ | 159 /* Dumps information about IV to FILE. */ |
156 | 160 |
157 extern void dump_iv_info (FILE *, struct rtx_iv *); | 161 extern void dump_iv_info (FILE *, class rtx_iv *); |
158 void | 162 void |
159 dump_iv_info (FILE *file, struct rtx_iv *iv) | 163 dump_iv_info (FILE *file, class rtx_iv *iv) |
160 { | 164 { |
161 if (!iv->base) | 165 if (!iv->base) |
162 { | 166 { |
163 fprintf (file, "not simple"); | 167 fprintf (file, "not simple"); |
164 return; | 168 return; |
200 check_iv_ref_table_size (void) | 204 check_iv_ref_table_size (void) |
201 { | 205 { |
202 if (iv_ref_table_size < DF_DEFS_TABLE_SIZE ()) | 206 if (iv_ref_table_size < DF_DEFS_TABLE_SIZE ()) |
203 { | 207 { |
204 unsigned int new_size = DF_DEFS_TABLE_SIZE () + (DF_DEFS_TABLE_SIZE () / 4); | 208 unsigned int new_size = DF_DEFS_TABLE_SIZE () + (DF_DEFS_TABLE_SIZE () / 4); |
205 iv_ref_table = XRESIZEVEC (struct rtx_iv *, iv_ref_table, new_size); | 209 iv_ref_table = XRESIZEVEC (class rtx_iv *, iv_ref_table, new_size); |
206 memset (&iv_ref_table[iv_ref_table_size], 0, | 210 memset (&iv_ref_table[iv_ref_table_size], 0, |
207 (new_size - iv_ref_table_size) * sizeof (struct rtx_iv *)); | 211 (new_size - iv_ref_table_size) * sizeof (class rtx_iv *)); |
208 iv_ref_table_size = new_size; | 212 iv_ref_table_size = new_size; |
209 } | 213 } |
210 } | 214 } |
211 | 215 |
212 | 216 |
241 | 245 |
242 static void | 246 static void |
243 clear_iv_info (void) | 247 clear_iv_info (void) |
244 { | 248 { |
245 unsigned i, n_defs = DF_DEFS_TABLE_SIZE (); | 249 unsigned i, n_defs = DF_DEFS_TABLE_SIZE (); |
246 struct rtx_iv *iv; | 250 class rtx_iv *iv; |
247 | 251 |
248 check_iv_ref_table_size (); | 252 check_iv_ref_table_size (); |
249 for (i = 0; i < n_defs; i++) | 253 for (i = 0; i < n_defs; i++) |
250 { | 254 { |
251 iv = iv_ref_table[i]; | 255 iv = iv_ref_table[i]; |
261 | 265 |
262 | 266 |
263 /* Prepare the data for an induction variable analysis of a LOOP. */ | 267 /* Prepare the data for an induction variable analysis of a LOOP. */ |
264 | 268 |
265 void | 269 void |
266 iv_analysis_loop_init (struct loop *loop) | 270 iv_analysis_loop_init (class loop *loop) |
267 { | 271 { |
268 current_loop = loop; | 272 current_loop = loop; |
269 | 273 |
270 /* Clear the information from the analysis of the previous loop. */ | 274 /* Clear the information from the analysis of the previous loop. */ |
271 if (clean_slate) | 275 if (clean_slate) |
299 static bool | 303 static bool |
300 latch_dominating_def (rtx reg, df_ref *def) | 304 latch_dominating_def (rtx reg, df_ref *def) |
301 { | 305 { |
302 df_ref single_rd = NULL, adef; | 306 df_ref single_rd = NULL, adef; |
303 unsigned regno = REGNO (reg); | 307 unsigned regno = REGNO (reg); |
304 struct df_rd_bb_info *bb_info = DF_RD_BB_INFO (current_loop->latch); | 308 class df_rd_bb_info *bb_info = DF_RD_BB_INFO (current_loop->latch); |
305 | 309 |
306 for (adef = DF_REG_DEF_CHAIN (regno); adef; adef = DF_REF_NEXT_REG (adef)) | 310 for (adef = DF_REG_DEF_CHAIN (regno); adef; adef = DF_REF_NEXT_REG (adef)) |
307 { | 311 { |
308 if (!bitmap_bit_p (df->blocks_to_analyze, DF_REF_BBNO (adef)) | 312 if (!bitmap_bit_p (df->blocks_to_analyze, DF_REF_BBNO (adef)) |
309 || !bitmap_bit_p (&bb_info->out, DF_REF_ID (adef))) | 313 || !bitmap_bit_p (&bb_info->out, DF_REF_ID (adef))) |
382 | 386 |
383 /* Sets IV to invariant CST in MODE. Always returns true (just for | 387 /* Sets IV to invariant CST in MODE. Always returns true (just for |
384 consistency with other iv manipulation functions that may fail). */ | 388 consistency with other iv manipulation functions that may fail). */ |
385 | 389 |
386 static bool | 390 static bool |
387 iv_constant (struct rtx_iv *iv, scalar_int_mode mode, rtx cst) | 391 iv_constant (class rtx_iv *iv, scalar_int_mode mode, rtx cst) |
388 { | 392 { |
389 iv->mode = mode; | 393 iv->mode = mode; |
390 iv->base = cst; | 394 iv->base = cst; |
391 iv->step = const0_rtx; | 395 iv->step = const0_rtx; |
392 iv->first_special = false; | 396 iv->first_special = false; |
399 } | 403 } |
400 | 404 |
401 /* Evaluates application of subreg to MODE on IV. */ | 405 /* Evaluates application of subreg to MODE on IV. */ |
402 | 406 |
403 static bool | 407 static bool |
404 iv_subreg (struct rtx_iv *iv, scalar_int_mode mode) | 408 iv_subreg (class rtx_iv *iv, scalar_int_mode mode) |
405 { | 409 { |
406 /* If iv is invariant, just calculate the new value. */ | 410 /* If iv is invariant, just calculate the new value. */ |
407 if (iv->step == const0_rtx | 411 if (iv->step == const0_rtx |
408 && !iv->first_special) | 412 && !iv->first_special) |
409 { | 413 { |
441 } | 445 } |
442 | 446 |
443 /* Evaluates application of EXTEND to MODE on IV. */ | 447 /* Evaluates application of EXTEND to MODE on IV. */ |
444 | 448 |
445 static bool | 449 static bool |
446 iv_extend (struct rtx_iv *iv, enum iv_extend_code extend, scalar_int_mode mode) | 450 iv_extend (class rtx_iv *iv, enum iv_extend_code extend, scalar_int_mode mode) |
447 { | 451 { |
448 /* If iv is invariant, just calculate the new value. */ | 452 /* If iv is invariant, just calculate the new value. */ |
449 if (iv->step == const0_rtx | 453 if (iv->step == const0_rtx |
450 && !iv->first_special) | 454 && !iv->first_special) |
451 { | 455 { |
479 } | 483 } |
480 | 484 |
481 /* Evaluates negation of IV. */ | 485 /* Evaluates negation of IV. */ |
482 | 486 |
483 static bool | 487 static bool |
484 iv_neg (struct rtx_iv *iv) | 488 iv_neg (class rtx_iv *iv) |
485 { | 489 { |
486 if (iv->extend == IV_UNKNOWN_EXTEND) | 490 if (iv->extend == IV_UNKNOWN_EXTEND) |
487 { | 491 { |
488 iv->base = simplify_gen_unary (NEG, iv->extend_mode, | 492 iv->base = simplify_gen_unary (NEG, iv->extend_mode, |
489 iv->base, iv->extend_mode); | 493 iv->base, iv->extend_mode); |
502 } | 506 } |
503 | 507 |
504 /* Evaluates addition or subtraction (according to OP) of IV1 to IV0. */ | 508 /* Evaluates addition or subtraction (according to OP) of IV1 to IV0. */ |
505 | 509 |
506 static bool | 510 static bool |
507 iv_add (struct rtx_iv *iv0, struct rtx_iv *iv1, enum rtx_code op) | 511 iv_add (class rtx_iv *iv0, class rtx_iv *iv1, enum rtx_code op) |
508 { | 512 { |
509 scalar_int_mode mode; | 513 scalar_int_mode mode; |
510 rtx arg; | 514 rtx arg; |
511 | 515 |
512 /* Extend the constant to extend_mode of the other operand if necessary. */ | 516 /* Extend the constant to extend_mode of the other operand if necessary. */ |
572 } | 576 } |
573 | 577 |
574 /* Evaluates multiplication of IV by constant CST. */ | 578 /* Evaluates multiplication of IV by constant CST. */ |
575 | 579 |
576 static bool | 580 static bool |
577 iv_mult (struct rtx_iv *iv, rtx mby) | 581 iv_mult (class rtx_iv *iv, rtx mby) |
578 { | 582 { |
579 scalar_int_mode mode = iv->extend_mode; | 583 scalar_int_mode mode = iv->extend_mode; |
580 | 584 |
581 if (GET_MODE (mby) != VOIDmode | 585 if (GET_MODE (mby) != VOIDmode |
582 && GET_MODE (mby) != mode) | 586 && GET_MODE (mby) != mode) |
597 } | 601 } |
598 | 602 |
599 /* Evaluates shift of IV by constant CST. */ | 603 /* Evaluates shift of IV by constant CST. */ |
600 | 604 |
601 static bool | 605 static bool |
602 iv_shift (struct rtx_iv *iv, rtx mby) | 606 iv_shift (class rtx_iv *iv, rtx mby) |
603 { | 607 { |
604 scalar_int_mode mode = iv->extend_mode; | 608 scalar_int_mode mode = iv->extend_mode; |
605 | 609 |
606 if (GET_MODE (mby) != VOIDmode | 610 if (GET_MODE (mby) != VOIDmode |
607 && GET_MODE (mby) != mode) | 611 && GET_MODE (mby) != mode) |
807 } | 811 } |
808 | 812 |
809 /* Records information that DEF is induction variable IV. */ | 813 /* Records information that DEF is induction variable IV. */ |
810 | 814 |
811 static void | 815 static void |
812 record_iv (df_ref def, struct rtx_iv *iv) | 816 record_iv (df_ref def, class rtx_iv *iv) |
813 { | 817 { |
814 struct rtx_iv *recorded_iv = XNEW (struct rtx_iv); | 818 class rtx_iv *recorded_iv = XNEW (class rtx_iv); |
815 | 819 |
816 *recorded_iv = *iv; | 820 *recorded_iv = *iv; |
817 check_iv_ref_table_size (); | 821 check_iv_ref_table_size (); |
818 DF_REF_IV_SET (def, recorded_iv); | 822 DF_REF_IV_SET (def, recorded_iv); |
819 } | 823 } |
820 | 824 |
821 /* If DEF was already analyzed for bivness, store the description of the biv to | 825 /* If DEF was already analyzed for bivness, store the description of the biv to |
822 IV and return true. Otherwise return false. */ | 826 IV and return true. Otherwise return false. */ |
823 | 827 |
824 static bool | 828 static bool |
825 analyzed_for_bivness_p (rtx def, struct rtx_iv *iv) | 829 analyzed_for_bivness_p (rtx def, class rtx_iv *iv) |
826 { | 830 { |
827 struct biv_entry *biv = bivs->find_with_hash (def, REGNO (def)); | 831 class biv_entry *biv = bivs->find_with_hash (def, REGNO (def)); |
828 | 832 |
829 if (!biv) | 833 if (!biv) |
830 return false; | 834 return false; |
831 | 835 |
832 *iv = biv->iv; | 836 *iv = biv->iv; |
833 return true; | 837 return true; |
834 } | 838 } |
835 | 839 |
836 static void | 840 static void |
837 record_biv (rtx def, struct rtx_iv *iv) | 841 record_biv (rtx def, class rtx_iv *iv) |
838 { | 842 { |
839 struct biv_entry *biv = XNEW (struct biv_entry); | 843 class biv_entry *biv = XNEW (class biv_entry); |
840 biv_entry **slot = bivs->find_slot_with_hash (def, REGNO (def), INSERT); | 844 biv_entry **slot = bivs->find_slot_with_hash (def, REGNO (def), INSERT); |
841 | 845 |
842 biv->regno = REGNO (def); | 846 biv->regno = REGNO (def); |
843 biv->iv = *iv; | 847 biv->iv = *iv; |
844 gcc_assert (!*slot); | 848 gcc_assert (!*slot); |
847 | 851 |
848 /* Determines whether DEF is a biv and if so, stores its description | 852 /* Determines whether DEF is a biv and if so, stores its description |
849 to *IV. OUTER_MODE is the mode of DEF. */ | 853 to *IV. OUTER_MODE is the mode of DEF. */ |
850 | 854 |
851 static bool | 855 static bool |
852 iv_analyze_biv (scalar_int_mode outer_mode, rtx def, struct rtx_iv *iv) | 856 iv_analyze_biv (scalar_int_mode outer_mode, rtx def, class rtx_iv *iv) |
853 { | 857 { |
854 rtx inner_step, outer_step; | 858 rtx inner_step, outer_step; |
855 scalar_int_mode inner_mode; | 859 scalar_int_mode inner_mode; |
856 enum iv_extend_code extend; | 860 enum iv_extend_code extend; |
857 df_ref last_def; | 861 df_ref last_def; |
925 /* Analyzes expression RHS used at INSN and stores the result to *IV. | 929 /* Analyzes expression RHS used at INSN and stores the result to *IV. |
926 The mode of the induction variable is MODE. */ | 930 The mode of the induction variable is MODE. */ |
927 | 931 |
928 bool | 932 bool |
929 iv_analyze_expr (rtx_insn *insn, scalar_int_mode mode, rtx rhs, | 933 iv_analyze_expr (rtx_insn *insn, scalar_int_mode mode, rtx rhs, |
930 struct rtx_iv *iv) | 934 class rtx_iv *iv) |
931 { | 935 { |
932 rtx mby = NULL_RTX; | 936 rtx mby = NULL_RTX; |
933 rtx op0 = NULL_RTX, op1 = NULL_RTX; | 937 rtx op0 = NULL_RTX, op1 = NULL_RTX; |
934 struct rtx_iv iv0, iv1; | 938 class rtx_iv iv0, iv1; |
935 enum rtx_code code = GET_CODE (rhs); | 939 enum rtx_code code = GET_CODE (rhs); |
936 scalar_int_mode omode = mode; | 940 scalar_int_mode omode = mode; |
937 | 941 |
938 iv->base = NULL_RTX; | 942 iv->base = NULL_RTX; |
939 iv->step = NULL_RTX; | 943 iv->step = NULL_RTX; |
1036 } | 1040 } |
1037 | 1041 |
1038 /* Analyzes iv DEF and stores the result to *IV. */ | 1042 /* Analyzes iv DEF and stores the result to *IV. */ |
1039 | 1043 |
1040 static bool | 1044 static bool |
1041 iv_analyze_def (df_ref def, struct rtx_iv *iv) | 1045 iv_analyze_def (df_ref def, class rtx_iv *iv) |
1042 { | 1046 { |
1043 rtx_insn *insn = DF_REF_INSN (def); | 1047 rtx_insn *insn = DF_REF_INSN (def); |
1044 rtx reg = DF_REF_REG (def); | 1048 rtx reg = DF_REF_REG (def); |
1045 rtx set, rhs; | 1049 rtx set, rhs; |
1046 | 1050 |
1100 | 1104 |
1101 /* Analyzes operand OP of INSN and stores the result to *IV. MODE is the | 1105 /* Analyzes operand OP of INSN and stores the result to *IV. MODE is the |
1102 mode of OP. */ | 1106 mode of OP. */ |
1103 | 1107 |
1104 static bool | 1108 static bool |
1105 iv_analyze_op (rtx_insn *insn, scalar_int_mode mode, rtx op, struct rtx_iv *iv) | 1109 iv_analyze_op (rtx_insn *insn, scalar_int_mode mode, rtx op, class rtx_iv *iv) |
1106 { | 1110 { |
1107 df_ref def = NULL; | 1111 df_ref def = NULL; |
1108 enum iv_grd_result res; | 1112 enum iv_grd_result res; |
1109 | 1113 |
1110 if (dump_file) | 1114 if (dump_file) |
1161 | 1165 |
1162 /* Analyzes value VAL at INSN and stores the result to *IV. MODE is the | 1166 /* Analyzes value VAL at INSN and stores the result to *IV. MODE is the |
1163 mode of VAL. */ | 1167 mode of VAL. */ |
1164 | 1168 |
1165 bool | 1169 bool |
1166 iv_analyze (rtx_insn *insn, scalar_int_mode mode, rtx val, struct rtx_iv *iv) | 1170 iv_analyze (rtx_insn *insn, scalar_int_mode mode, rtx val, class rtx_iv *iv) |
1167 { | 1171 { |
1168 rtx reg; | 1172 rtx reg; |
1169 | 1173 |
1170 /* We must find the insn in that val is used, so that we get to UD chains. | 1174 /* We must find the insn in that val is used, so that we get to UD chains. |
1171 Since the function is sometimes called on result of get_condition, | 1175 Since the function is sometimes called on result of get_condition, |
1186 } | 1190 } |
1187 | 1191 |
1188 /* Analyzes definition of DEF in INSN and stores the result to IV. */ | 1192 /* Analyzes definition of DEF in INSN and stores the result to IV. */ |
1189 | 1193 |
1190 bool | 1194 bool |
1191 iv_analyze_result (rtx_insn *insn, rtx def, struct rtx_iv *iv) | 1195 iv_analyze_result (rtx_insn *insn, rtx def, class rtx_iv *iv) |
1192 { | 1196 { |
1193 df_ref adef; | 1197 df_ref adef; |
1194 | 1198 |
1195 adef = df_find_def (insn, def); | 1199 adef = df_find_def (insn, def); |
1196 if (!adef) | 1200 if (!adef) |
1206 iv_analysis_loop_init) for this function to produce a result. */ | 1210 iv_analysis_loop_init) for this function to produce a result. */ |
1207 | 1211 |
1208 bool | 1212 bool |
1209 biv_p (rtx_insn *insn, scalar_int_mode mode, rtx reg) | 1213 biv_p (rtx_insn *insn, scalar_int_mode mode, rtx reg) |
1210 { | 1214 { |
1211 struct rtx_iv iv; | 1215 class rtx_iv iv; |
1212 df_ref def, last_def; | 1216 df_ref def, last_def; |
1213 | 1217 |
1214 if (!simple_reg_p (reg)) | 1218 if (!simple_reg_p (reg)) |
1215 return false; | 1219 return false; |
1216 | 1220 |
1228 } | 1232 } |
1229 | 1233 |
1230 /* Calculates value of IV at ITERATION-th iteration. */ | 1234 /* Calculates value of IV at ITERATION-th iteration. */ |
1231 | 1235 |
1232 rtx | 1236 rtx |
1233 get_iv_value (struct rtx_iv *iv, rtx iteration) | 1237 get_iv_value (class rtx_iv *iv, rtx iteration) |
1234 { | 1238 { |
1235 rtx val; | 1239 rtx val; |
1236 | 1240 |
1237 /* We would need to generate some if_then_else patterns, and so far | 1241 /* We would need to generate some if_then_else patterns, and so far |
1238 it is not needed anywhere. */ | 1242 it is not needed anywhere. */ |
1378 null. */ | 1382 null. */ |
1379 | 1383 |
1380 static rtx | 1384 static rtx |
1381 find_single_def_src (unsigned int regno) | 1385 find_single_def_src (unsigned int regno) |
1382 { | 1386 { |
1383 df_ref adef; | 1387 rtx src = NULL_RTX; |
1384 rtx set, src; | 1388 |
1385 | 1389 /* Don't look through unbounded number of single definition REG copies, |
1386 for (;;) | 1390 there might be loops for sources with uninitialized variables. */ |
1387 { | 1391 for (int cnt = 0; cnt < 128; cnt++) |
1388 rtx note; | 1392 { |
1389 adef = DF_REG_DEF_CHAIN (regno); | 1393 df_ref adef = DF_REG_DEF_CHAIN (regno); |
1390 if (adef == NULL || DF_REF_NEXT_REG (adef) != NULL | 1394 if (adef == NULL || DF_REF_NEXT_REG (adef) != NULL |
1391 || DF_REF_IS_ARTIFICIAL (adef)) | 1395 || DF_REF_IS_ARTIFICIAL (adef)) |
1392 return NULL_RTX; | 1396 return NULL_RTX; |
1393 | 1397 |
1394 set = single_set (DF_REF_INSN (adef)); | 1398 rtx set = single_set (DF_REF_INSN (adef)); |
1395 if (set == NULL || !REG_P (SET_DEST (set)) | 1399 if (set == NULL || !REG_P (SET_DEST (set)) |
1396 || REGNO (SET_DEST (set)) != regno) | 1400 || REGNO (SET_DEST (set)) != regno) |
1397 return NULL_RTX; | 1401 return NULL_RTX; |
1398 | 1402 |
1399 note = find_reg_equal_equiv_note (DF_REF_INSN (adef)); | 1403 rtx note = find_reg_equal_equiv_note (DF_REF_INSN (adef)); |
1400 | |
1401 if (note && function_invariant_p (XEXP (note, 0))) | 1404 if (note && function_invariant_p (XEXP (note, 0))) |
1402 { | 1405 { |
1403 src = XEXP (note, 0); | 1406 src = XEXP (note, 0); |
1404 break; | 1407 break; |
1405 } | 1408 } |
1847 | 1850 |
1848 /* Simplifies *EXPR using initial values at the start of the LOOP. If *EXPR | 1851 /* Simplifies *EXPR using initial values at the start of the LOOP. If *EXPR |
1849 is a list, its elements are assumed to be combined using OP. */ | 1852 is a list, its elements are assumed to be combined using OP. */ |
1850 | 1853 |
1851 static void | 1854 static void |
1852 simplify_using_initial_values (struct loop *loop, enum rtx_code op, rtx *expr) | 1855 simplify_using_initial_values (class loop *loop, enum rtx_code op, rtx *expr) |
1853 { | 1856 { |
1854 bool expression_valid; | 1857 bool expression_valid; |
1855 rtx head, tail, last_valid_expr; | 1858 rtx head, tail, last_valid_expr; |
1856 rtx_expr_list *cond_list; | 1859 rtx_expr_list *cond_list; |
1857 rtx_insn *insn; | 1860 rtx_insn *insn; |
1966 | 1969 |
1967 if (!INSN_P (insn)) | 1970 if (!INSN_P (insn)) |
1968 continue; | 1971 continue; |
1969 | 1972 |
1970 CLEAR_REG_SET (this_altered); | 1973 CLEAR_REG_SET (this_altered); |
1971 note_stores (PATTERN (insn), mark_altered, this_altered); | 1974 note_stores (insn, mark_altered, this_altered); |
1972 if (CALL_P (insn)) | 1975 if (CALL_P (insn)) |
1973 { | 1976 { |
1974 /* Kill all call clobbered registers. */ | 1977 /* Kill all registers that might be clobbered by the call. |
1975 unsigned int i; | 1978 We don't track modes of hard registers, so we need to be |
1976 hard_reg_set_iterator hrsi; | 1979 conservative and assume that partial kills are full kills. */ |
1977 EXECUTE_IF_SET_IN_HARD_REG_SET (regs_invalidated_by_call, | 1980 function_abi callee_abi = insn_callee_abi (insn); |
1978 0, i, hrsi) | 1981 IOR_REG_SET_HRS (this_altered, |
1979 SET_REGNO_REG_SET (this_altered, i); | 1982 callee_abi.full_and_partial_reg_clobbers ()); |
1980 } | 1983 } |
1981 | 1984 |
1982 if (suitable_set_for_replacement (insn, &dest, &src)) | 1985 if (suitable_set_for_replacement (insn, &dest, &src)) |
1983 { | 1986 { |
1984 rtx_expr_list **pnote, **pnote_next; | 1987 rtx_expr_list **pnote, **pnote_next; |
2068 /* Transforms invariant IV into MODE. Adds assumptions based on the fact | 2071 /* Transforms invariant IV into MODE. Adds assumptions based on the fact |
2069 that IV occurs as left operands of comparison COND and its signedness | 2072 that IV occurs as left operands of comparison COND and its signedness |
2070 is SIGNED_P to DESC. */ | 2073 is SIGNED_P to DESC. */ |
2071 | 2074 |
2072 static void | 2075 static void |
2073 shorten_into_mode (struct rtx_iv *iv, scalar_int_mode mode, | 2076 shorten_into_mode (class rtx_iv *iv, scalar_int_mode mode, |
2074 enum rtx_code cond, bool signed_p, struct niter_desc *desc) | 2077 enum rtx_code cond, bool signed_p, class niter_desc *desc) |
2075 { | 2078 { |
2076 rtx mmin, mmax, cond_over, cond_under; | 2079 rtx mmin, mmax, cond_over, cond_under; |
2077 | 2080 |
2078 get_mode_bounds (mode, signed_p, iv->extend_mode, &mmin, &mmax); | 2081 get_mode_bounds (mode, signed_p, iv->extend_mode, &mmin, &mmax); |
2079 cond_under = simplify_gen_relational (LT, SImode, iv->extend_mode, | 2082 cond_under = simplify_gen_relational (LT, SImode, iv->extend_mode, |
2127 /* Transforms IV0 and IV1 compared by COND so that they are both compared as | 2130 /* Transforms IV0 and IV1 compared by COND so that they are both compared as |
2128 subregs of the same mode if possible (sometimes it is necessary to add | 2131 subregs of the same mode if possible (sometimes it is necessary to add |
2129 some assumptions to DESC). */ | 2132 some assumptions to DESC). */ |
2130 | 2133 |
2131 static bool | 2134 static bool |
2132 canonicalize_iv_subregs (struct rtx_iv *iv0, struct rtx_iv *iv1, | 2135 canonicalize_iv_subregs (class rtx_iv *iv0, class rtx_iv *iv1, |
2133 enum rtx_code cond, struct niter_desc *desc) | 2136 enum rtx_code cond, class niter_desc *desc) |
2134 { | 2137 { |
2135 scalar_int_mode comp_mode; | 2138 scalar_int_mode comp_mode; |
2136 bool signed_p; | 2139 bool signed_p; |
2137 | 2140 |
2138 /* If the ivs behave specially in the first iteration, or are | 2141 /* If the ivs behave specially in the first iteration, or are |
2243 result. This function is called from iv_number_of_iterations with | 2246 result. This function is called from iv_number_of_iterations with |
2244 a number of fields in DESC already filled in. OLD_NITER is the original | 2247 a number of fields in DESC already filled in. OLD_NITER is the original |
2245 expression for the number of iterations, before we tried to simplify it. */ | 2248 expression for the number of iterations, before we tried to simplify it. */ |
2246 | 2249 |
2247 static uint64_t | 2250 static uint64_t |
2248 determine_max_iter (struct loop *loop, struct niter_desc *desc, rtx old_niter) | 2251 determine_max_iter (class loop *loop, class niter_desc *desc, rtx old_niter) |
2249 { | 2252 { |
2250 rtx niter = desc->niter_expr; | 2253 rtx niter = desc->niter_expr; |
2251 rtx mmin, mmax, cmp; | 2254 rtx mmin, mmax, cmp; |
2252 uint64_t nmax, inc; | 2255 uint64_t nmax, inc; |
2253 uint64_t andmax = 0; | 2256 uint64_t andmax = 0; |
2301 /* Computes number of iterations of the CONDITION in INSN in LOOP and stores | 2304 /* Computes number of iterations of the CONDITION in INSN in LOOP and stores |
2302 the result into DESC. Very similar to determine_number_of_iterations | 2305 the result into DESC. Very similar to determine_number_of_iterations |
2303 (basically its rtl version), complicated by things like subregs. */ | 2306 (basically its rtl version), complicated by things like subregs. */ |
2304 | 2307 |
2305 static void | 2308 static void |
2306 iv_number_of_iterations (struct loop *loop, rtx_insn *insn, rtx condition, | 2309 iv_number_of_iterations (class loop *loop, rtx_insn *insn, rtx condition, |
2307 struct niter_desc *desc) | 2310 class niter_desc *desc) |
2308 { | 2311 { |
2309 rtx op0, op1, delta, step, bound, may_xform, tmp, tmp0, tmp1; | 2312 rtx op0, op1, delta, step, bound, may_xform, tmp, tmp0, tmp1; |
2310 struct rtx_iv iv0, iv1; | 2313 class rtx_iv iv0, iv1; |
2311 rtx assumption, may_not_xform; | 2314 rtx assumption, may_not_xform; |
2312 enum rtx_code cond; | 2315 enum rtx_code cond; |
2313 machine_mode nonvoid_mode; | 2316 machine_mode nonvoid_mode; |
2314 scalar_int_mode comp_mode; | 2317 scalar_int_mode comp_mode; |
2315 rtx mmin, mmax, mode_mmin, mode_mmax; | 2318 rtx mmin, mmax, mode_mmin, mode_mmax; |
2863 | 2866 |
2864 /* Checks whether E is a simple exit from LOOP and stores its description | 2867 /* Checks whether E is a simple exit from LOOP and stores its description |
2865 into DESC. */ | 2868 into DESC. */ |
2866 | 2869 |
2867 static void | 2870 static void |
2868 check_simple_exit (struct loop *loop, edge e, struct niter_desc *desc) | 2871 check_simple_exit (class loop *loop, edge e, class niter_desc *desc) |
2869 { | 2872 { |
2870 basic_block exit_bb; | 2873 basic_block exit_bb; |
2871 rtx condition; | 2874 rtx condition; |
2872 rtx_insn *at; | 2875 rtx_insn *at; |
2873 edge ein; | 2876 edge ein; |
2911 } | 2914 } |
2912 | 2915 |
2913 /* Finds a simple exit of LOOP and stores its description into DESC. */ | 2916 /* Finds a simple exit of LOOP and stores its description into DESC. */ |
2914 | 2917 |
2915 void | 2918 void |
2916 find_simple_exit (struct loop *loop, struct niter_desc *desc) | 2919 find_simple_exit (class loop *loop, class niter_desc *desc) |
2917 { | 2920 { |
2918 unsigned i; | 2921 unsigned i; |
2919 basic_block *body; | 2922 basic_block *body; |
2920 edge e; | 2923 edge e; |
2921 struct niter_desc act; | 2924 class niter_desc act; |
2922 bool any = false; | 2925 bool any = false; |
2923 edge_iterator ei; | 2926 edge_iterator ei; |
2924 | 2927 |
2925 desc->simple_p = false; | 2928 desc->simple_p = false; |
2926 body = get_loop_body (loop); | 2929 body = get_loop_body (loop); |
2995 } | 2998 } |
2996 else | 2999 else |
2997 fprintf (dump_file, "Loop %d is not simple.\n", loop->num); | 3000 fprintf (dump_file, "Loop %d is not simple.\n", loop->num); |
2998 } | 3001 } |
2999 | 3002 |
3003 /* Fix up the finiteness if possible. We can only do it for single exit, | |
3004 since the loop is finite, but it's possible that we predicate one loop | |
3005 exit to be finite which can not be determined as finite in middle-end as | |
3006 well. It results in incorrect predicate information on the exit condition | |
3007 expression. For example, if says [(int) _1 + -8, + , -8] != 0 finite, | |
3008 it means _1 can exactly divide -8. */ | |
3009 if (desc->infinite && single_exit (loop) && finite_loop_p (loop)) | |
3010 { | |
3011 desc->infinite = NULL_RTX; | |
3012 if (dump_file) | |
3013 fprintf (dump_file, " infinite updated to finite.\n"); | |
3014 } | |
3015 | |
3000 free (body); | 3016 free (body); |
3001 } | 3017 } |
3002 | 3018 |
3003 /* Creates a simple loop description of LOOP if it was not computed | 3019 /* Creates a simple loop description of LOOP if it was not computed |
3004 already. */ | 3020 already. */ |
3005 | 3021 |
3006 struct niter_desc * | 3022 class niter_desc * |
3007 get_simple_loop_desc (struct loop *loop) | 3023 get_simple_loop_desc (class loop *loop) |
3008 { | 3024 { |
3009 struct niter_desc *desc = simple_loop_desc (loop); | 3025 class niter_desc *desc = simple_loop_desc (loop); |
3010 | 3026 |
3011 if (desc) | 3027 if (desc) |
3012 return desc; | 3028 return desc; |
3013 | 3029 |
3014 /* At least desc->infinite is not always initialized by | 3030 /* At least desc->infinite is not always initialized by |
3021 } | 3037 } |
3022 | 3038 |
3023 /* Releases simple loop description for LOOP. */ | 3039 /* Releases simple loop description for LOOP. */ |
3024 | 3040 |
3025 void | 3041 void |
3026 free_simple_loop_desc (struct loop *loop) | 3042 free_simple_loop_desc (class loop *loop) |
3027 { | 3043 { |
3028 struct niter_desc *desc = simple_loop_desc (loop); | 3044 class niter_desc *desc = simple_loop_desc (loop); |
3029 | 3045 |
3030 if (!desc) | 3046 if (!desc) |
3031 return; | 3047 return; |
3032 | 3048 |
3033 ggc_free (desc); | 3049 ggc_free (desc); |