1 1.1 mrg /* Post reload partially redundant load elimination 2 1.1 mrg Copyright (C) 2004-2022 Free Software Foundation, Inc. 3 1.1 mrg 4 1.1 mrg This file is part of GCC. 5 1.1 mrg 6 1.1 mrg GCC is free software; you can redistribute it and/or modify it under 7 1.1 mrg the terms of the GNU General Public License as published by the Free 8 1.1 mrg Software Foundation; either version 3, or (at your option) any later 9 1.1 mrg version. 10 1.1 mrg 11 1.1 mrg GCC is distributed in the hope that it will be useful, but WITHOUT ANY 12 1.1 mrg WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 1.1 mrg FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 1.1 mrg for more details. 15 1.1 mrg 16 1.1 mrg You should have received a copy of the GNU General Public License 17 1.1 mrg along with GCC; see the file COPYING3. If not see 18 1.1 mrg <http://www.gnu.org/licenses/>. */ 19 1.1 mrg 20 1.1 mrg #include "config.h" 21 1.1 mrg #include "system.h" 22 1.1 mrg #include "coretypes.h" 23 1.1 mrg #include "backend.h" 24 1.1 mrg #include "target.h" 25 1.1 mrg #include "rtl.h" 26 1.1 mrg #include "tree.h" 27 1.1 mrg #include "predict.h" 28 1.1 mrg #include "df.h" 29 1.1 mrg #include "memmodel.h" 30 1.1 mrg #include "tm_p.h" 31 1.1 mrg #include "insn-config.h" 32 1.1 mrg #include "emit-rtl.h" 33 1.1 mrg #include "recog.h" 34 1.1 mrg 35 1.1 mrg #include "cfgrtl.h" 36 1.1 mrg #include "profile.h" 37 1.1 mrg #include "expr.h" 38 1.1 mrg #include "tree-pass.h" 39 1.1 mrg #include "dbgcnt.h" 40 1.1 mrg #include "intl.h" 41 1.1 mrg #include "gcse-common.h" 42 1.1 mrg #include "gcse.h" 43 1.1 mrg #include "regs.h" 44 1.1 mrg #include "function-abi.h" 45 1.1 mrg 46 1.1 mrg /* The following code implements gcse after reload, the purpose of this 47 1.1 mrg pass is to cleanup redundant loads generated by reload and other 48 1.1 mrg optimizations that come after gcse. It searches for simple inter-block 49 1.1 mrg redundancies and tries to eliminate them by adding moves and loads 50 1.1 mrg in cold places. 51 1.1 mrg 52 1.1 mrg Perform partially redundant load elimination, try to eliminate redundant 53 1.1 mrg loads created by the reload pass. We try to look for full or partial 54 1.1 mrg redundant loads fed by one or more loads/stores in predecessor BBs, 55 1.1 mrg and try adding loads to make them fully redundant. We also check if 56 1.1 mrg it's worth adding loads to be able to delete the redundant load. 57 1.1 mrg 58 1.1 mrg Algorithm: 59 1.1 mrg 1. Build available expressions hash table: 60 1.1 mrg For each load/store instruction, if the loaded/stored memory didn't 61 1.1 mrg change until the end of the basic block add this memory expression to 62 1.1 mrg the hash table. 63 1.1 mrg 2. Perform Redundancy elimination: 64 1.1 mrg For each load instruction do the following: 65 1.1 mrg perform partial redundancy elimination, check if it's worth adding 66 1.1 mrg loads to make the load fully redundant. If so add loads and 67 1.1 mrg register copies and delete the load. 68 1.1 mrg 3. Delete instructions made redundant in step 2. 69 1.1 mrg 70 1.1 mrg Future enhancement: 71 1.1 mrg If the loaded register is used/defined between load and some store, 72 1.1 mrg look for some other free register between load and all its stores, 73 1.1 mrg and replace the load with a copy from this register to the loaded 74 1.1 mrg register. 75 1.1 mrg */ 76 1.1 mrg 77 1.1 mrg 79 1.1 mrg /* Keep statistics of this pass. */ 80 1.1 mrg static struct 81 1.1 mrg { 82 1.1 mrg int moves_inserted; 83 1.1 mrg int copies_inserted; 84 1.1 mrg int insns_deleted; 85 1.1 mrg } stats; 86 1.1 mrg 87 1.1 mrg /* We need to keep a hash table of expressions. The table entries are of 88 1.1 mrg type 'struct expr', and for each expression there is a single linked 89 1.1 mrg list of occurrences. */ 90 1.1 mrg 91 1.1 mrg /* Expression elements in the hash table. */ 92 1.1 mrg struct expr 93 1.1 mrg { 94 1.1 mrg /* The expression (SET_SRC for expressions, PATTERN for assignments). */ 95 1.1 mrg rtx expr; 96 1.1 mrg 97 1.1 mrg /* The same hash for this entry. */ 98 1.1 mrg hashval_t hash; 99 1.1 mrg 100 1.1 mrg /* Index in the transparent bitmaps. */ 101 1.1 mrg unsigned int bitmap_index; 102 1.1 mrg 103 1.1 mrg /* List of available occurrence in basic blocks in the function. */ 104 1.1 mrg struct occr *avail_occr; 105 1.1 mrg }; 106 1.1 mrg 107 1.1 mrg /* Hashtable helpers. */ 108 1.1 mrg 109 1.1 mrg struct expr_hasher : nofree_ptr_hash <expr> 110 1.1 mrg { 111 1.1 mrg static inline hashval_t hash (const expr *); 112 1.1 mrg static inline bool equal (const expr *, const expr *); 113 1.1 mrg }; 114 1.1 mrg 115 1.1 mrg 116 1.1 mrg /* Hash expression X. 117 1.1 mrg DO_NOT_RECORD_P is a boolean indicating if a volatile operand is found 118 1.1 mrg or if the expression contains something we don't want to insert in the 119 1.1 mrg table. */ 120 1.1 mrg 121 1.1 mrg static hashval_t 122 1.1 mrg hash_expr (rtx x, int *do_not_record_p) 123 1.1 mrg { 124 1.1 mrg *do_not_record_p = 0; 125 1.1 mrg return hash_rtx (x, GET_MODE (x), do_not_record_p, 126 1.1 mrg NULL, /*have_reg_qty=*/false); 127 1.1 mrg } 128 1.1 mrg 129 1.1 mrg /* Callback for hashtab. 130 1.1 mrg Return the hash value for expression EXP. We don't actually hash 131 1.1 mrg here, we just return the cached hash value. */ 132 1.1 mrg 133 1.1 mrg inline hashval_t 134 1.1 mrg expr_hasher::hash (const expr *exp) 135 1.1 mrg { 136 1.1 mrg return exp->hash; 137 1.1 mrg } 138 1.1 mrg 139 1.1 mrg /* Callback for hashtab. 140 1.1 mrg Return nonzero if exp1 is equivalent to exp2. */ 141 1.1 mrg 142 1.1 mrg inline bool 143 1.1 mrg expr_hasher::equal (const expr *exp1, const expr *exp2) 144 1.1 mrg { 145 1.1 mrg int equiv_p = exp_equiv_p (exp1->expr, exp2->expr, 0, true); 146 1.1 mrg 147 1.1 mrg gcc_assert (!equiv_p || exp1->hash == exp2->hash); 148 1.1 mrg return equiv_p; 149 1.1 mrg } 150 1.1 mrg 151 1.1 mrg /* The table itself. */ 152 1.1 mrg static hash_table<expr_hasher> *expr_table; 153 1.1 mrg 154 1.1 mrg 156 1.1 mrg static struct obstack expr_obstack; 157 1.1 mrg 158 1.1 mrg /* Occurrence of an expression. 159 1.1 mrg There is at most one occurrence per basic block. If a pattern appears 160 1.1 mrg more than once, the last appearance is used. */ 161 1.1 mrg 162 1.1 mrg struct occr 163 1.1 mrg { 164 1.1 mrg /* Next occurrence of this expression. */ 165 1.1 mrg struct occr *next; 166 1.1 mrg /* The insn that computes the expression. */ 167 1.1 mrg rtx_insn *insn; 168 1.1 mrg /* Nonzero if this [anticipatable] occurrence has been deleted. */ 169 1.1 mrg char deleted_p; 170 1.1 mrg }; 171 1.1 mrg 172 1.1 mrg static struct obstack occr_obstack; 173 1.1 mrg 174 1.1 mrg /* The following structure holds the information about the occurrences of 175 1.1 mrg the redundant instructions. */ 176 1.1 mrg struct unoccr 177 1.1 mrg { 178 1.1 mrg struct unoccr *next; 179 1.1 mrg edge pred; 180 1.1 mrg rtx_insn *insn; 181 1.1 mrg }; 182 1.1 mrg 183 1.1 mrg static struct obstack unoccr_obstack; 184 1.1 mrg 185 1.1 mrg /* Array where each element is the CUID if the insn that last set the hard 186 1.1 mrg register with the number of the element, since the start of the current 187 1.1 mrg basic block. 188 1.1 mrg 189 1.1 mrg This array is used during the building of the hash table (step 1) to 190 1.1 mrg determine if a reg is killed before the end of a basic block. 191 1.1 mrg 192 1.1 mrg It is also used when eliminating partial redundancies (step 2) to see 193 1.1 mrg if a reg was modified since the start of a basic block. */ 194 1.1 mrg static int *reg_avail_info; 195 1.1 mrg 196 1.1 mrg /* A list of insns that may modify memory within the current basic block. */ 197 1.1 mrg struct modifies_mem 198 1.1 mrg { 199 1.1 mrg rtx_insn *insn; 200 1.1 mrg struct modifies_mem *next; 201 1.1 mrg }; 202 1.1 mrg static struct modifies_mem *modifies_mem_list; 203 1.1 mrg 204 1.1 mrg /* The modifies_mem structs also go on an obstack, only this obstack is 205 1.1 mrg freed each time after completing the analysis or transformations on 206 1.1 mrg a basic block. So we allocate a dummy modifies_mem_obstack_bottom 207 1.1 mrg object on the obstack to keep track of the bottom of the obstack. */ 208 1.1 mrg static struct obstack modifies_mem_obstack; 209 1.1 mrg static struct modifies_mem *modifies_mem_obstack_bottom; 210 1.1 mrg 211 1.1 mrg /* Mapping of insn UIDs to CUIDs. 212 1.1 mrg CUIDs are like UIDs except they increase monotonically in each basic 213 1.1 mrg block, have no gaps, and only apply to real insns. */ 214 1.1 mrg static int *uid_cuid; 215 1.1 mrg #define INSN_CUID(INSN) (uid_cuid[INSN_UID (INSN)]) 216 1.1 mrg 217 1.1 mrg /* Bitmap of blocks which have memory stores. */ 218 1.1 mrg static bitmap modify_mem_list_set; 219 1.1 mrg 220 1.1 mrg /* Bitmap of blocks which have calls. */ 221 1.1 mrg static bitmap blocks_with_calls; 222 1.1 mrg 223 1.1 mrg /* Vector indexed by block # with a list of all the insns that 224 1.1 mrg modify memory within the block. */ 225 1.1 mrg static vec<rtx_insn *> *modify_mem_list; 226 1.1 mrg 227 1.1 mrg /* Vector indexed by block # with a canonicalized list of insns 228 1.1 mrg that modify memory in the block. */ 229 1.1 mrg static vec<modify_pair> *canon_modify_mem_list; 230 1.1 mrg 231 1.1 mrg /* Vector of simple bitmaps indexed by block number. Each component sbitmap 232 1.1 mrg indicates which expressions are transparent through the block. */ 233 1.1 mrg static sbitmap *transp; 234 1.1 mrg 235 1.1 mrg 237 1.1 mrg /* Helpers for memory allocation/freeing. */ 238 1.1 mrg static void alloc_mem (void); 239 1.1 mrg static void free_mem (void); 240 1.1 mrg 241 1.1 mrg /* Support for hash table construction and transformations. */ 242 1.1 mrg static bool oprs_unchanged_p (rtx, rtx_insn *, bool); 243 1.1 mrg static void record_last_reg_set_info (rtx_insn *, rtx); 244 1.1 mrg static void record_last_reg_set_info_regno (rtx_insn *, int); 245 1.1 mrg static void record_last_mem_set_info (rtx_insn *); 246 1.1 mrg static void record_last_set_info (rtx, const_rtx, void *); 247 1.1 mrg static void record_opr_changes (rtx_insn *); 248 1.1 mrg 249 1.1 mrg static void find_mem_conflicts (rtx, const_rtx, void *); 250 1.1 mrg static int load_killed_in_block_p (int, rtx, bool); 251 1.1 mrg static void reset_opr_set_tables (void); 252 1.1 mrg 253 1.1 mrg /* Hash table support. */ 254 1.1 mrg static hashval_t hash_expr (rtx, int *); 255 1.1 mrg static void insert_expr_in_table (rtx, rtx_insn *); 256 1.1 mrg static struct expr *lookup_expr_in_table (rtx); 257 1.1 mrg static void dump_hash_table (FILE *); 258 1.1 mrg 259 1.1 mrg /* Helpers for eliminate_partially_redundant_load. */ 260 1.1 mrg static bool reg_killed_on_edge (rtx, edge); 261 1.1 mrg static bool reg_used_on_edge (rtx, edge); 262 1.1 mrg 263 1.1 mrg static rtx get_avail_load_store_reg (rtx_insn *); 264 1.1 mrg 265 1.1 mrg static bool bb_has_well_behaved_predecessors (basic_block); 266 1.1 mrg static struct occr* get_bb_avail_insn (basic_block, struct occr *, int); 267 1.1 mrg static void hash_scan_set (rtx_insn *); 268 1.1 mrg static void compute_hash_table (void); 269 1.1 mrg 270 1.1 mrg /* The work horses of this pass. */ 271 1.1 mrg static void eliminate_partially_redundant_load (basic_block, 272 1.1 mrg rtx_insn *, 273 1.1 mrg struct expr *); 274 1.1 mrg static void eliminate_partially_redundant_loads (void); 275 1.1 mrg 276 1.1 mrg 278 1.1 mrg /* Allocate memory for the CUID mapping array and register/memory 279 1.1 mrg tracking tables. */ 280 1.1 mrg 281 1.1 mrg static void 282 1.1 mrg alloc_mem (void) 283 1.1 mrg { 284 1.1 mrg int i; 285 1.1 mrg basic_block bb; 286 1.1 mrg rtx_insn *insn; 287 1.1 mrg 288 1.1 mrg /* Find the largest UID and create a mapping from UIDs to CUIDs. */ 289 1.1 mrg uid_cuid = XCNEWVEC (int, get_max_uid () + 1); 290 1.1 mrg i = 1; 291 1.1 mrg FOR_EACH_BB_FN (bb, cfun) 292 1.1 mrg FOR_BB_INSNS (bb, insn) 293 1.1 mrg { 294 1.1 mrg if (INSN_P (insn)) 295 1.1 mrg uid_cuid[INSN_UID (insn)] = i++; 296 1.1 mrg else 297 1.1 mrg uid_cuid[INSN_UID (insn)] = i; 298 1.1 mrg } 299 1.1 mrg 300 1.1 mrg /* Allocate the available expressions hash table. We don't want to 301 1.1 mrg make the hash table too small, but unnecessarily making it too large 302 1.1 mrg also doesn't help. The i/4 is a gcse.cc relic, and seems like a 303 1.1 mrg reasonable choice. */ 304 1.1 mrg expr_table = new hash_table<expr_hasher> (MAX (i / 4, 13)); 305 1.1 mrg 306 1.1 mrg /* We allocate everything on obstacks because we often can roll back 307 1.1 mrg the whole obstack to some point. Freeing obstacks is very fast. */ 308 1.1 mrg gcc_obstack_init (&expr_obstack); 309 1.1 mrg gcc_obstack_init (&occr_obstack); 310 1.1 mrg gcc_obstack_init (&unoccr_obstack); 311 1.1 mrg gcc_obstack_init (&modifies_mem_obstack); 312 1.1 mrg 313 1.1 mrg /* Working array used to track the last set for each register 314 1.1 mrg in the current block. */ 315 1.1 mrg reg_avail_info = (int *) xmalloc (FIRST_PSEUDO_REGISTER * sizeof (int)); 316 1.1 mrg 317 1.1 mrg /* Put a dummy modifies_mem object on the modifies_mem_obstack, so we 318 1.1 mrg can roll it back in reset_opr_set_tables. */ 319 1.1 mrg modifies_mem_obstack_bottom = 320 1.1 mrg (struct modifies_mem *) obstack_alloc (&modifies_mem_obstack, 321 1.1 mrg sizeof (struct modifies_mem)); 322 1.1 mrg 323 1.1 mrg blocks_with_calls = BITMAP_ALLOC (NULL); 324 1.1 mrg modify_mem_list_set = BITMAP_ALLOC (NULL); 325 1.1 mrg 326 1.1 mrg modify_mem_list = (vec_rtx_heap *) xcalloc (last_basic_block_for_fn (cfun), 327 1.1 mrg sizeof (vec_rtx_heap)); 328 1.1 mrg canon_modify_mem_list 329 1.1 mrg = (vec_modify_pair_heap *) xcalloc (last_basic_block_for_fn (cfun), 330 1.1 mrg sizeof (vec_modify_pair_heap)); 331 1.1 mrg } 332 1.1 mrg 333 1.1 mrg /* Free memory allocated by alloc_mem. */ 334 1.1 mrg 335 1.1 mrg static void 336 1.1 mrg free_mem (void) 337 1.1 mrg { 338 1.1 mrg free (uid_cuid); 339 1.1 mrg 340 1.1 mrg delete expr_table; 341 1.1 mrg expr_table = NULL; 342 1.1 mrg 343 1.1 mrg obstack_free (&expr_obstack, NULL); 344 1.1 mrg obstack_free (&occr_obstack, NULL); 345 1.1 mrg obstack_free (&unoccr_obstack, NULL); 346 1.1 mrg obstack_free (&modifies_mem_obstack, NULL); 347 1.1 mrg 348 1.1 mrg unsigned i; 349 1.1 mrg bitmap_iterator bi; 350 1.1 mrg EXECUTE_IF_SET_IN_BITMAP (modify_mem_list_set, 0, i, bi) 351 1.1 mrg { 352 1.1 mrg modify_mem_list[i].release (); 353 1.1 mrg canon_modify_mem_list[i].release (); 354 1.1 mrg } 355 1.1 mrg 356 1.1 mrg BITMAP_FREE (blocks_with_calls); 357 1.1 mrg BITMAP_FREE (modify_mem_list_set); 358 1.1 mrg free (reg_avail_info); 359 1.1 mrg free (modify_mem_list); 360 1.1 mrg free (canon_modify_mem_list); 361 1.1 mrg } 362 1.1 mrg 363 1.1 mrg 365 1.1 mrg /* Insert expression X in INSN in the hash TABLE. 366 1.1 mrg If it is already present, record it as the last occurrence in INSN's 367 1.1 mrg basic block. */ 368 1.1 mrg 369 1.1 mrg static void 370 1.1 mrg insert_expr_in_table (rtx x, rtx_insn *insn) 371 1.1 mrg { 372 1.1 mrg int do_not_record_p; 373 1.1 mrg hashval_t hash; 374 1.1 mrg struct expr *cur_expr, **slot; 375 1.1 mrg struct occr *avail_occr; 376 1.1 mrg 377 1.1 mrg hash = hash_expr (x, &do_not_record_p); 378 1.1 mrg 379 1.1 mrg /* Do not insert expression in the table if it contains volatile operands, 380 1.1 mrg or if hash_expr determines the expression is something we don't want 381 1.1 mrg to or can't handle. */ 382 1.1 mrg if (do_not_record_p) 383 1.1 mrg return; 384 1.1 mrg 385 1.1 mrg /* We anticipate that redundant expressions are rare, so for convenience 386 1.1 mrg allocate a new hash table element here already and set its fields. 387 1.1 mrg If we don't do this, we need a hack with a static struct expr. Anyway, 388 1.1 mrg obstack_free is really fast and one more obstack_alloc doesn't hurt if 389 1.1 mrg we're going to see more expressions later on. */ 390 1.1 mrg cur_expr = (struct expr *) obstack_alloc (&expr_obstack, 391 1.1 mrg sizeof (struct expr)); 392 1.1 mrg cur_expr->expr = x; 393 1.1 mrg cur_expr->hash = hash; 394 1.1 mrg cur_expr->avail_occr = NULL; 395 1.1 mrg 396 1.1 mrg slot = expr_table->find_slot_with_hash (cur_expr, hash, INSERT); 397 1.1 mrg 398 1.1 mrg if (! (*slot)) 399 1.1 mrg { 400 1.1 mrg /* The expression isn't found, so insert it. */ 401 1.1 mrg *slot = cur_expr; 402 1.1 mrg 403 1.1 mrg /* Anytime we add an entry to the table, record the index 404 1.1 mrg of the new entry. The bitmap index starts counting 405 1.1 mrg at zero. */ 406 1.1 mrg cur_expr->bitmap_index = expr_table->elements () - 1; 407 1.1 mrg } 408 1.1 mrg else 409 1.1 mrg { 410 1.1 mrg /* The expression is already in the table, so roll back the 411 1.1 mrg obstack and use the existing table entry. */ 412 1.1 mrg obstack_free (&expr_obstack, cur_expr); 413 1.1 mrg cur_expr = *slot; 414 1.1 mrg } 415 1.1 mrg 416 1.1 mrg /* Search for another occurrence in the same basic block. We insert 417 1.1 mrg insns blockwise from start to end, so keep appending to the 418 1.1 mrg start of the list so we have to check only a single element. */ 419 1.1 mrg avail_occr = cur_expr->avail_occr; 420 1.1 mrg if (avail_occr 421 1.1 mrg && BLOCK_FOR_INSN (avail_occr->insn) == BLOCK_FOR_INSN (insn)) 422 1.1 mrg avail_occr->insn = insn; 423 1.1 mrg else 424 1.1 mrg { 425 1.1 mrg /* First occurrence of this expression in this basic block. */ 426 1.1 mrg avail_occr = (struct occr *) obstack_alloc (&occr_obstack, 427 1.1 mrg sizeof (struct occr)); 428 1.1 mrg avail_occr->insn = insn; 429 1.1 mrg avail_occr->next = cur_expr->avail_occr; 430 1.1 mrg avail_occr->deleted_p = 0; 431 1.1 mrg cur_expr->avail_occr = avail_occr; 432 1.1 mrg } 433 1.1 mrg } 434 1.1 mrg 435 1.1 mrg 437 1.1 mrg /* Lookup pattern PAT in the expression hash table. 438 1.1 mrg The result is a pointer to the table entry, or NULL if not found. */ 439 1.1 mrg 440 1.1 mrg static struct expr * 441 1.1 mrg lookup_expr_in_table (rtx pat) 442 1.1 mrg { 443 1.1 mrg int do_not_record_p; 444 1.1 mrg struct expr **slot, *tmp_expr; 445 1.1 mrg hashval_t hash = hash_expr (pat, &do_not_record_p); 446 1.1 mrg 447 1.1 mrg if (do_not_record_p) 448 1.1 mrg return NULL; 449 1.1 mrg 450 1.1 mrg tmp_expr = (struct expr *) obstack_alloc (&expr_obstack, 451 1.1 mrg sizeof (struct expr)); 452 1.1 mrg tmp_expr->expr = pat; 453 1.1 mrg tmp_expr->hash = hash; 454 1.1 mrg tmp_expr->avail_occr = NULL; 455 1.1 mrg 456 1.1 mrg slot = expr_table->find_slot_with_hash (tmp_expr, hash, INSERT); 457 1.1 mrg obstack_free (&expr_obstack, tmp_expr); 458 1.1 mrg 459 1.1 mrg if (!slot) 460 1.1 mrg return NULL; 461 1.1 mrg else 462 1.1 mrg return (*slot); 463 1.1 mrg } 464 1.1 mrg 465 1.1 mrg 467 1.1 mrg /* Dump all expressions and occurrences that are currently in the 468 1.1 mrg expression hash table to FILE. */ 469 1.1 mrg 470 1.1 mrg /* This helper is called via htab_traverse. */ 471 1.1 mrg int 472 1.1 mrg dump_expr_hash_table_entry (expr **slot, FILE *file) 473 1.1 mrg { 474 1.1 mrg struct expr *exprs = *slot; 475 1.1 mrg struct occr *occr; 476 1.1 mrg 477 1.1 mrg fprintf (file, "expr: "); 478 1.1 mrg print_rtl (file, exprs->expr); 479 1.1 mrg fprintf (file,"\nhashcode: %u\n", exprs->hash); 480 1.1 mrg fprintf (file,"list of occurrences:\n"); 481 1.1 mrg occr = exprs->avail_occr; 482 1.1 mrg while (occr) 483 1.1 mrg { 484 1.1 mrg rtx_insn *insn = occr->insn; 485 1.1 mrg print_rtl_single (file, insn); 486 1.1 mrg fprintf (file, "\n"); 487 1.1 mrg occr = occr->next; 488 1.1 mrg } 489 1.1 mrg fprintf (file, "\n"); 490 1.1 mrg return 1; 491 1.1 mrg } 492 1.1 mrg 493 1.1 mrg static void 494 1.1 mrg dump_hash_table (FILE *file) 495 1.1 mrg { 496 1.1 mrg fprintf (file, "\n\nexpression hash table\n"); 497 1.1 mrg fprintf (file, "size %ld, %ld elements, %f collision/search ratio\n", 498 1.1 mrg (long) expr_table->size (), 499 1.1 mrg (long) expr_table->elements (), 500 1.1 mrg expr_table->collisions ()); 501 1.1 mrg if (!expr_table->is_empty ()) 502 1.1 mrg { 503 1.1 mrg fprintf (file, "\n\ntable entries:\n"); 504 1.1 mrg expr_table->traverse <FILE *, dump_expr_hash_table_entry> (file); 505 1.1 mrg } 506 1.1 mrg fprintf (file, "\n"); 507 1.1 mrg } 508 1.1 mrg 509 1.1 mrg /* Return true if register X is recorded as being set by an instruction 511 1.1 mrg whose CUID is greater than the one given. */ 512 1.1 mrg 513 1.1 mrg static bool 514 1.1 mrg reg_changed_after_insn_p (rtx x, int cuid) 515 1.1 mrg { 516 1.1 mrg unsigned int regno, end_regno; 517 1.1 mrg 518 1.1 mrg regno = REGNO (x); 519 1.1 mrg end_regno = END_REGNO (x); 520 1.1 mrg do 521 1.1 mrg if (reg_avail_info[regno] > cuid) 522 1.1 mrg return true; 523 1.1 mrg while (++regno < end_regno); 524 1.1 mrg return false; 525 1.1 mrg } 526 1.1 mrg 527 1.1 mrg /* Return nonzero if the operands of expression X are unchanged 528 1.1 mrg 1) from the start of INSN's basic block up to but not including INSN 529 1.1 mrg if AFTER_INSN is false, or 530 1.1 mrg 2) from INSN to the end of INSN's basic block if AFTER_INSN is true. */ 531 1.1 mrg 532 1.1 mrg static bool 533 1.1 mrg oprs_unchanged_p (rtx x, rtx_insn *insn, bool after_insn) 534 1.1 mrg { 535 1.1 mrg int i, j; 536 1.1 mrg enum rtx_code code; 537 1.1 mrg const char *fmt; 538 1.1 mrg 539 1.1 mrg if (x == 0) 540 1.1 mrg return 1; 541 1.1 mrg 542 1.1 mrg code = GET_CODE (x); 543 1.1 mrg switch (code) 544 1.1 mrg { 545 1.1 mrg case REG: 546 1.1 mrg /* We are called after register allocation. */ 547 1.1 mrg gcc_assert (REGNO (x) < FIRST_PSEUDO_REGISTER); 548 1.1 mrg if (after_insn) 549 1.1 mrg return !reg_changed_after_insn_p (x, INSN_CUID (insn) - 1); 550 1.1 mrg else 551 1.1 mrg return !reg_changed_after_insn_p (x, 0); 552 1.1 mrg 553 1.1 mrg case MEM: 554 1.1 mrg if (load_killed_in_block_p (INSN_CUID (insn), x, after_insn)) 555 1.1 mrg return 0; 556 1.1 mrg else 557 1.1 mrg return oprs_unchanged_p (XEXP (x, 0), insn, after_insn); 558 1.1 mrg 559 1.1 mrg case PC: 560 1.1 mrg case CONST: 561 1.1 mrg CASE_CONST_ANY: 562 1.1 mrg case SYMBOL_REF: 563 1.1 mrg case LABEL_REF: 564 1.1 mrg case ADDR_VEC: 565 1.1 mrg case ADDR_DIFF_VEC: 566 1.1 mrg return 1; 567 1.1 mrg 568 1.1 mrg case PRE_DEC: 569 1.1 mrg case PRE_INC: 570 1.1 mrg case POST_DEC: 571 1.1 mrg case POST_INC: 572 1.1 mrg case PRE_MODIFY: 573 1.1 mrg case POST_MODIFY: 574 1.1 mrg if (after_insn) 575 1.1 mrg return 0; 576 1.1 mrg break; 577 1.1 mrg 578 1.1 mrg default: 579 1.1 mrg break; 580 1.1 mrg } 581 1.1 mrg 582 1.1 mrg for (i = GET_RTX_LENGTH (code) - 1, fmt = GET_RTX_FORMAT (code); i >= 0; i--) 583 1.1 mrg { 584 1.1 mrg if (fmt[i] == 'e') 585 1.1 mrg { 586 1.1 mrg if (! oprs_unchanged_p (XEXP (x, i), insn, after_insn)) 587 1.1 mrg return 0; 588 1.1 mrg } 589 1.1 mrg else if (fmt[i] == 'E') 590 1.1 mrg for (j = 0; j < XVECLEN (x, i); j++) 591 1.1 mrg if (! oprs_unchanged_p (XVECEXP (x, i, j), insn, after_insn)) 592 1.1 mrg return 0; 593 1.1 mrg } 594 1.1 mrg 595 1.1 mrg return 1; 596 1.1 mrg } 597 1.1 mrg 598 1.1 mrg 600 1.1 mrg /* Used for communication between find_mem_conflicts and 601 1.1 mrg load_killed_in_block_p. Nonzero if find_mem_conflicts finds a 602 1.1 mrg conflict between two memory references. 603 1.1 mrg This is a bit of a hack to work around the limitations of note_stores. */ 604 1.1 mrg static int mems_conflict_p; 605 1.1 mrg 606 1.1 mrg /* DEST is the output of an instruction. If it is a memory reference, and 607 1.1 mrg possibly conflicts with the load found in DATA, then set mems_conflict_p 608 1.1 mrg to a nonzero value. */ 609 1.1 mrg 610 1.1 mrg static void 611 1.1 mrg find_mem_conflicts (rtx dest, const_rtx setter ATTRIBUTE_UNUSED, 612 1.1 mrg void *data) 613 1.1 mrg { 614 1.1 mrg rtx mem_op = (rtx) data; 615 1.1 mrg 616 1.1 mrg while (GET_CODE (dest) == SUBREG 617 1.1 mrg || GET_CODE (dest) == ZERO_EXTRACT 618 1.1 mrg || GET_CODE (dest) == STRICT_LOW_PART) 619 1.1 mrg dest = XEXP (dest, 0); 620 1.1 mrg 621 1.1 mrg /* If DEST is not a MEM, then it will not conflict with the load. Note 622 1.1 mrg that function calls are assumed to clobber memory, but are handled 623 1.1 mrg elsewhere. */ 624 1.1 mrg if (! MEM_P (dest)) 625 1.1 mrg return; 626 1.1 mrg 627 1.1 mrg if (true_dependence (dest, GET_MODE (dest), mem_op)) 628 1.1 mrg mems_conflict_p = 1; 629 1.1 mrg } 630 1.1 mrg 631 1.1 mrg 633 1.1 mrg /* Return nonzero if the expression in X (a memory reference) is killed 634 1.1 mrg in the current basic block before (if AFTER_INSN is false) or after 635 1.1 mrg (if AFTER_INSN is true) the insn with the CUID in UID_LIMIT. 636 1.1 mrg 637 1.1 mrg This function assumes that the modifies_mem table is flushed when 638 1.1 mrg the hash table construction or redundancy elimination phases start 639 1.1 mrg processing a new basic block. */ 640 1.1 mrg 641 1.1 mrg static int 642 1.1 mrg load_killed_in_block_p (int uid_limit, rtx x, bool after_insn) 643 1.1 mrg { 644 1.1 mrg struct modifies_mem *list_entry = modifies_mem_list; 645 1.1 mrg 646 1.1 mrg while (list_entry) 647 1.1 mrg { 648 1.1 mrg rtx_insn *setter = list_entry->insn; 649 1.1 mrg 650 1.1 mrg /* Ignore entries in the list that do not apply. */ 651 1.1 mrg if ((after_insn 652 1.1 mrg && INSN_CUID (setter) < uid_limit) 653 1.1 mrg || (! after_insn 654 1.1 mrg && INSN_CUID (setter) > uid_limit)) 655 1.1 mrg { 656 1.1 mrg list_entry = list_entry->next; 657 1.1 mrg continue; 658 1.1 mrg } 659 1.1 mrg 660 1.1 mrg /* If SETTER is a call everything is clobbered. Note that calls 661 1.1 mrg to pure functions are never put on the list, so we need not 662 1.1 mrg worry about them. */ 663 1.1 mrg if (CALL_P (setter)) 664 1.1 mrg return 1; 665 1.1 mrg 666 1.1 mrg /* SETTER must be an insn of some kind that sets memory. Call 667 1.1 mrg note_stores to examine each hunk of memory that is modified. 668 1.1 mrg It will set mems_conflict_p to nonzero if there may be a 669 1.1 mrg conflict between X and SETTER. */ 670 1.1 mrg mems_conflict_p = 0; 671 1.1 mrg note_stores (setter, find_mem_conflicts, x); 672 1.1 mrg if (mems_conflict_p) 673 1.1 mrg return 1; 674 1.1 mrg 675 1.1 mrg list_entry = list_entry->next; 676 1.1 mrg } 677 1.1 mrg return 0; 678 1.1 mrg } 679 1.1 mrg 680 1.1 mrg 682 1.1 mrg /* Record register first/last/block set information for REGNO in INSN. */ 683 1.1 mrg 684 1.1 mrg static inline void 685 1.1 mrg record_last_reg_set_info (rtx_insn *insn, rtx reg) 686 1.1 mrg { 687 1.1 mrg unsigned int regno, end_regno; 688 1.1 mrg 689 1.1 mrg regno = REGNO (reg); 690 1.1 mrg end_regno = END_REGNO (reg); 691 1.1 mrg do 692 1.1 mrg reg_avail_info[regno] = INSN_CUID (insn); 693 1.1 mrg while (++regno < end_regno); 694 1.1 mrg } 695 1.1 mrg 696 1.1 mrg static inline void 697 1.1 mrg record_last_reg_set_info_regno (rtx_insn *insn, int regno) 698 1.1 mrg { 699 1.1 mrg reg_avail_info[regno] = INSN_CUID (insn); 700 1.1 mrg } 701 1.1 mrg 702 1.1 mrg 703 1.1 mrg /* Record memory modification information for INSN. We do not actually care 704 1.1 mrg about the memory location(s) that are set, or even how they are set (consider 705 1.1 mrg a CALL_INSN). We merely need to record which insns modify memory. */ 706 1.1 mrg 707 1.1 mrg static void 708 1.1 mrg record_last_mem_set_info (rtx_insn *insn) 709 1.1 mrg { 710 1.1 mrg struct modifies_mem *list_entry; 711 1.1 mrg 712 1.1 mrg list_entry = (struct modifies_mem *) obstack_alloc (&modifies_mem_obstack, 713 1.1 mrg sizeof (struct modifies_mem)); 714 1.1 mrg list_entry->insn = insn; 715 1.1 mrg list_entry->next = modifies_mem_list; 716 1.1 mrg modifies_mem_list = list_entry; 717 1.1 mrg 718 1.1 mrg record_last_mem_set_info_common (insn, modify_mem_list, 719 1.1 mrg canon_modify_mem_list, 720 1.1 mrg modify_mem_list_set, 721 1.1 mrg blocks_with_calls); 722 1.1 mrg } 723 1.1 mrg 724 1.1 mrg /* Called from compute_hash_table via note_stores to handle one 725 1.1 mrg SET or CLOBBER in an insn. DATA is really the instruction in which 726 1.1 mrg the SET is taking place. */ 727 1.1 mrg 728 1.1 mrg static void 729 1.1 mrg record_last_set_info (rtx dest, const_rtx setter ATTRIBUTE_UNUSED, void *data) 730 1.1 mrg { 731 1.1 mrg rtx_insn *last_set_insn = (rtx_insn *) data; 732 1.1 mrg 733 1.1 mrg if (GET_CODE (dest) == SUBREG) 734 1.1 mrg dest = SUBREG_REG (dest); 735 1.1 mrg 736 1.1 mrg if (REG_P (dest)) 737 1.1 mrg record_last_reg_set_info (last_set_insn, dest); 738 1.1 mrg else if (MEM_P (dest)) 739 1.1 mrg { 740 1.1 mrg /* Ignore pushes, they don't clobber memory. They may still 741 1.1 mrg clobber the stack pointer though. Some targets do argument 742 1.1 mrg pushes without adding REG_INC notes. See e.g. PR25196, 743 1.1 mrg where a pushsi2 on i386 doesn't have REG_INC notes. Note 744 1.1 mrg such changes here too. */ 745 1.1 mrg if (! push_operand (dest, GET_MODE (dest))) 746 1.1 mrg record_last_mem_set_info (last_set_insn); 747 1.1 mrg else 748 1.1 mrg record_last_reg_set_info_regno (last_set_insn, STACK_POINTER_REGNUM); 749 1.1 mrg } 750 1.1 mrg } 751 1.1 mrg 752 1.1 mrg 753 1.1 mrg /* Reset tables used to keep track of what's still available since the 754 1.1 mrg start of the block. */ 755 1.1 mrg 756 1.1 mrg static void 757 1.1 mrg reset_opr_set_tables (void) 758 1.1 mrg { 759 1.1 mrg memset (reg_avail_info, 0, FIRST_PSEUDO_REGISTER * sizeof (int)); 760 1.1 mrg obstack_free (&modifies_mem_obstack, modifies_mem_obstack_bottom); 761 1.1 mrg modifies_mem_list = NULL; 762 1.1 mrg } 763 1.1 mrg 764 1.1 mrg 766 1.1 mrg /* Record things set by INSN. 767 1.1 mrg This data is used by oprs_unchanged_p. */ 768 1.1 mrg 769 1.1 mrg static void 770 1.1 mrg record_opr_changes (rtx_insn *insn) 771 1.1 mrg { 772 1.1 mrg rtx note; 773 1.1 mrg 774 1.1 mrg /* Find all stores and record them. */ 775 1.1 mrg note_stores (insn, record_last_set_info, insn); 776 1.1 mrg 777 1.1 mrg /* Also record autoincremented REGs for this insn as changed. */ 778 1.1 mrg for (note = REG_NOTES (insn); note; note = XEXP (note, 1)) 779 1.1 mrg if (REG_NOTE_KIND (note) == REG_INC) 780 1.1 mrg record_last_reg_set_info (insn, XEXP (note, 0)); 781 1.1 mrg 782 1.1 mrg /* Finally, if this is a call, record all call clobbers. */ 783 1.1 mrg if (CALL_P (insn)) 784 1.1 mrg { 785 1.1 mrg unsigned int regno; 786 1.1 mrg hard_reg_set_iterator hrsi; 787 1.1 mrg /* We don't track modes of hard registers, so we need to be 788 1.1 mrg conservative and assume that partial kills are full kills. */ 789 1.1 mrg HARD_REG_SET callee_clobbers 790 1.1 mrg = insn_callee_abi (insn).full_and_partial_reg_clobbers (); 791 1.1 mrg EXECUTE_IF_SET_IN_HARD_REG_SET (callee_clobbers, 0, regno, hrsi) 792 1.1 mrg record_last_reg_set_info_regno (insn, regno); 793 1.1 mrg 794 1.1 mrg if (! RTL_CONST_OR_PURE_CALL_P (insn) 795 1.1 mrg || RTL_LOOPING_CONST_OR_PURE_CALL_P (insn) 796 1.1 mrg || can_throw_external (insn)) 797 1.1 mrg record_last_mem_set_info (insn); 798 1.1 mrg } 799 1.1 mrg } 800 1.1 mrg 801 1.1 mrg 803 1.1 mrg /* Scan the pattern of INSN and add an entry to the hash TABLE. 804 1.1 mrg After reload we are interested in loads/stores only. */ 805 1.1 mrg 806 1.1 mrg static void 807 1.1 mrg hash_scan_set (rtx_insn *insn) 808 1.1 mrg { 809 1.1 mrg rtx pat = PATTERN (insn); 810 1.1 mrg rtx src = SET_SRC (pat); 811 1.1 mrg rtx dest = SET_DEST (pat); 812 1.1 mrg 813 1.1 mrg /* We are only interested in loads and stores. */ 814 1.1 mrg if (! MEM_P (src) && ! MEM_P (dest)) 815 1.1 mrg return; 816 1.1 mrg 817 1.1 mrg /* Don't mess with jumps and nops. */ 818 1.1 mrg if (JUMP_P (insn) || set_noop_p (pat)) 819 1.1 mrg return; 820 1.1 mrg 821 1.1 mrg if (REG_P (dest)) 822 1.1 mrg { 823 1.1 mrg if (/* Don't CSE something if we can't do a reg/reg copy. */ 824 1.1 mrg can_copy_p (GET_MODE (dest)) 825 1.1 mrg /* Is SET_SRC something we want to gcse? */ 826 1.1 mrg && general_operand (src, GET_MODE (src)) 827 1.1 mrg #ifdef STACK_REGS 828 1.1 mrg /* Never consider insns touching the register stack. It may 829 1.1 mrg create situations that reg-stack cannot handle (e.g. a stack 830 1.1 mrg register live across an abnormal edge). */ 831 1.1 mrg && (REGNO (dest) < FIRST_STACK_REG || REGNO (dest) > LAST_STACK_REG) 832 1.1 mrg #endif 833 1.1 mrg /* An expression is not available if its operands are 834 1.1 mrg subsequently modified, including this insn. */ 835 1.1 mrg && oprs_unchanged_p (src, insn, true)) 836 1.1 mrg { 837 1.1 mrg insert_expr_in_table (src, insn); 838 1.1 mrg } 839 1.1 mrg } 840 1.1 mrg else if (REG_P (src)) 841 1.1 mrg { 842 1.1 mrg /* Only record sets of pseudo-regs in the hash table. */ 843 1.1 mrg if (/* Don't CSE something if we can't do a reg/reg copy. */ 844 1.1 mrg can_copy_p (GET_MODE (src)) 845 1.1 mrg /* Is SET_DEST something we want to gcse? */ 846 1.1 mrg && general_operand (dest, GET_MODE (dest)) 847 1.1 mrg #ifdef STACK_REGS 848 1.1 mrg /* As above for STACK_REGS. */ 849 1.1 mrg && (REGNO (src) < FIRST_STACK_REG || REGNO (src) > LAST_STACK_REG) 850 1.1 mrg #endif 851 1.1 mrg && ! (flag_float_store && FLOAT_MODE_P (GET_MODE (dest))) 852 1.1 mrg /* Check if the memory expression is killed after insn. */ 853 1.1 mrg && ! load_killed_in_block_p (INSN_CUID (insn) + 1, dest, true) 854 1.1 mrg && oprs_unchanged_p (XEXP (dest, 0), insn, true)) 855 1.1 mrg { 856 1.1 mrg insert_expr_in_table (dest, insn); 857 1.1 mrg } 858 1.1 mrg } 859 1.1 mrg } 860 1.1 mrg 861 1.1 mrg 863 1.1 mrg /* Create hash table of memory expressions available at end of basic 864 1.1 mrg blocks. Basically you should think of this hash table as the 865 1.1 mrg representation of AVAIL_OUT. This is the set of expressions that 866 1.1 mrg is generated in a basic block and not killed before the end of the 867 1.1 mrg same basic block. Notice that this is really a local computation. */ 868 1.1 mrg 869 1.1 mrg static void 870 1.1 mrg compute_hash_table (void) 871 1.1 mrg { 872 1.1 mrg basic_block bb; 873 1.1 mrg 874 1.1 mrg FOR_EACH_BB_FN (bb, cfun) 875 1.1 mrg { 876 1.1 mrg rtx_insn *insn; 877 1.1 mrg 878 1.1 mrg /* First pass over the instructions records information used to 879 1.1 mrg determine when registers and memory are last set. 880 1.1 mrg Since we compute a "local" AVAIL_OUT, reset the tables that 881 1.1 mrg help us keep track of what has been modified since the start 882 1.1 mrg of the block. */ 883 1.1 mrg reset_opr_set_tables (); 884 1.1 mrg FOR_BB_INSNS (bb, insn) 885 1.1 mrg { 886 1.1 mrg if (INSN_P (insn)) 887 1.1 mrg record_opr_changes (insn); 888 1.1 mrg } 889 1.1 mrg 890 1.1 mrg /* The next pass actually builds the hash table. */ 891 1.1 mrg FOR_BB_INSNS (bb, insn) 892 1.1 mrg if (INSN_P (insn) && GET_CODE (PATTERN (insn)) == SET) 893 1.1 mrg hash_scan_set (insn); 894 1.1 mrg } 895 1.1 mrg } 896 1.1 mrg 897 1.1 mrg 899 1.1 mrg /* Check if register REG is killed in any insn waiting to be inserted on 900 1.1 mrg edge E. This function is required to check that our data flow analysis 901 1.1 mrg is still valid prior to commit_edge_insertions. */ 902 1.1 mrg 903 1.1 mrg static bool 904 1.1 mrg reg_killed_on_edge (rtx reg, edge e) 905 1.1 mrg { 906 1.1 mrg rtx_insn *insn; 907 1.1 mrg 908 1.1 mrg for (insn = e->insns.r; insn; insn = NEXT_INSN (insn)) 909 1.1 mrg if (INSN_P (insn) && reg_set_p (reg, insn)) 910 1.1 mrg return true; 911 1.1 mrg 912 1.1 mrg return false; 913 1.1 mrg } 914 1.1 mrg 915 1.1 mrg /* Similar to above - check if register REG is used in any insn waiting 916 1.1 mrg to be inserted on edge E. 917 1.1 mrg Assumes no such insn can be a CALL_INSN; if so call reg_used_between_p 918 1.1 mrg with PREV(insn),NEXT(insn) instead of calling reg_overlap_mentioned_p. */ 919 1.1 mrg 920 1.1 mrg static bool 921 1.1 mrg reg_used_on_edge (rtx reg, edge e) 922 1.1 mrg { 923 1.1 mrg rtx_insn *insn; 924 1.1 mrg 925 1.1 mrg for (insn = e->insns.r; insn; insn = NEXT_INSN (insn)) 926 1.1 mrg if (INSN_P (insn) && reg_overlap_mentioned_p (reg, PATTERN (insn))) 927 1.1 mrg return true; 928 1.1 mrg 929 1.1 mrg return false; 930 1.1 mrg } 931 1.1 mrg 932 1.1 mrg /* Return the loaded/stored register of a load/store instruction. */ 934 1.1 mrg 935 1.1 mrg static rtx 936 1.1 mrg get_avail_load_store_reg (rtx_insn *insn) 937 1.1 mrg { 938 1.1 mrg if (REG_P (SET_DEST (PATTERN (insn)))) 939 1.1 mrg /* A load. */ 940 1.1 mrg return SET_DEST (PATTERN (insn)); 941 1.1 mrg else 942 1.1 mrg { 943 1.1 mrg /* A store. */ 944 1.1 mrg gcc_assert (REG_P (SET_SRC (PATTERN (insn)))); 945 1.1 mrg return SET_SRC (PATTERN (insn)); 946 1.1 mrg } 947 1.1 mrg } 948 1.1 mrg 949 1.1 mrg /* Return nonzero if the predecessors of BB are "well behaved". */ 950 1.1 mrg 951 1.1 mrg static bool 952 1.1 mrg bb_has_well_behaved_predecessors (basic_block bb) 953 1.1 mrg { 954 1.1 mrg edge pred; 955 1.1 mrg edge_iterator ei; 956 1.1 mrg 957 1.1 mrg if (EDGE_COUNT (bb->preds) == 0) 958 1.1 mrg return false; 959 1.1 mrg 960 1.1 mrg FOR_EACH_EDGE (pred, ei, bb->preds) 961 1.1 mrg { 962 1.1 mrg /* commit_one_edge_insertion refuses to insert on abnormal edges even if 963 1.1 mrg the source has only one successor so EDGE_CRITICAL_P is too weak. */ 964 1.1 mrg if ((pred->flags & EDGE_ABNORMAL) && !single_pred_p (pred->dest)) 965 1.1 mrg return false; 966 1.1 mrg 967 1.1 mrg if ((pred->flags & EDGE_ABNORMAL_CALL) && cfun->has_nonlocal_label) 968 1.1 mrg return false; 969 1.1 mrg 970 1.1 mrg if (tablejump_p (BB_END (pred->src), NULL, NULL)) 971 1.1 mrg return false; 972 1.1 mrg } 973 1.1 mrg return true; 974 1.1 mrg } 975 1.1 mrg 976 1.1 mrg 977 1.1 mrg /* Search for the occurrences of expression in BB. */ 978 1.1 mrg 979 1.1 mrg static struct occr* 980 1.1 mrg get_bb_avail_insn (basic_block bb, struct occr *orig_occr, int bitmap_index) 981 1.1 mrg { 982 1.1 mrg struct occr *occr = orig_occr; 983 1.1 mrg 984 1.1 mrg for (; occr != NULL; occr = occr->next) 985 1.1 mrg if (BLOCK_FOR_INSN (occr->insn) == bb) 986 1.1 mrg return occr; 987 1.1 mrg 988 1.1 mrg /* If we could not find an occurrence in BB, see if BB 989 1.1 mrg has a single predecessor with an occurrence that is 990 1.1 mrg transparent through BB. */ 991 1.1 mrg if (transp 992 1.1 mrg && single_pred_p (bb) 993 1.1 mrg && bitmap_bit_p (transp[bb->index], bitmap_index) 994 1.1 mrg && (occr = get_bb_avail_insn (single_pred (bb), orig_occr, bitmap_index))) 995 1.1 mrg { 996 1.1 mrg rtx avail_reg = get_avail_load_store_reg (occr->insn); 997 1.1 mrg if (!reg_set_between_p (avail_reg, 998 1.1 mrg PREV_INSN (BB_HEAD (bb)), 999 1.1 mrg NEXT_INSN (BB_END (bb))) 1000 1.1 mrg && !reg_killed_on_edge (avail_reg, single_pred_edge (bb))) 1001 1.1 mrg return occr; 1002 1.1 mrg } 1003 1.1 mrg 1004 1.1 mrg return NULL; 1005 1.1 mrg } 1006 1.1 mrg 1007 1.1 mrg 1008 1.1 mrg /* This helper is called via htab_traverse. */ 1009 1.1 mrg int 1010 1.1 mrg compute_expr_transp (expr **slot, FILE *dump_file ATTRIBUTE_UNUSED) 1011 1.1 mrg { 1012 1.1 mrg struct expr *expr = *slot; 1013 1.1 mrg 1014 1.1 mrg compute_transp (expr->expr, expr->bitmap_index, transp, 1015 1.1 mrg blocks_with_calls, modify_mem_list_set, 1016 1.1 mrg canon_modify_mem_list); 1017 1.1 mrg return 1; 1018 1.1 mrg } 1019 1.1 mrg 1020 1.1 mrg /* This handles the case where several stores feed a partially redundant 1021 1.1 mrg load. It checks if the redundancy elimination is possible and if it's 1022 1.1 mrg worth it. 1023 1.1 mrg 1024 1.1 mrg Redundancy elimination is possible if, 1025 1.1 mrg 1) None of the operands of an insn have been modified since the start 1026 1.1 mrg of the current basic block. 1027 1.1 mrg 2) In any predecessor of the current basic block, the same expression 1028 1.1 mrg is generated. 1029 1.1 mrg 1030 1.1 mrg See the function body for the heuristics that determine if eliminating 1031 1.1 mrg a redundancy is also worth doing, assuming it is possible. */ 1032 1.1 mrg 1033 1.1 mrg static void 1034 1.1 mrg eliminate_partially_redundant_load (basic_block bb, rtx_insn *insn, 1035 1.1 mrg struct expr *expr) 1036 1.1 mrg { 1037 1.1 mrg edge pred; 1038 1.1 mrg rtx_insn *avail_insn = NULL; 1039 1.1 mrg rtx avail_reg; 1040 1.1 mrg rtx dest, pat; 1041 1.1 mrg struct occr *a_occr; 1042 1.1 mrg struct unoccr *occr, *avail_occrs = NULL; 1043 1.1 mrg struct unoccr *unoccr, *unavail_occrs = NULL, *rollback_unoccr = NULL; 1044 1.1 mrg int npred_ok = 0; 1045 1.1 mrg profile_count ok_count = profile_count::zero (); 1046 1.1 mrg /* Redundant load execution count. */ 1047 1.1 mrg profile_count critical_count = profile_count::zero (); 1048 1.1 mrg /* Execution count of critical edges. */ 1049 1.1 mrg edge_iterator ei; 1050 1.1 mrg bool critical_edge_split = false; 1051 1.1 mrg 1052 1.1 mrg /* The execution count of the loads to be added to make the 1053 1.1 mrg load fully redundant. */ 1054 1.1 mrg profile_count not_ok_count = profile_count::zero (); 1055 1.1 mrg basic_block pred_bb; 1056 1.1 mrg 1057 1.1 mrg pat = PATTERN (insn); 1058 1.1 mrg dest = SET_DEST (pat); 1059 1.1 mrg 1060 1.1 mrg /* Check that the loaded register is not used, set, or killed from the 1061 1.1 mrg beginning of the block. */ 1062 1.1 mrg if (reg_changed_after_insn_p (dest, 0) 1063 1.1 mrg || reg_used_between_p (dest, PREV_INSN (BB_HEAD (bb)), insn)) 1064 1.1 mrg return; 1065 1.1 mrg 1066 1.1 mrg /* Check potential for replacing load with copy for predecessors. */ 1067 1.1 mrg FOR_EACH_EDGE (pred, ei, bb->preds) 1068 1.1 mrg { 1069 1.1 mrg rtx_insn *next_pred_bb_end; 1070 1.1 mrg 1071 1.1 mrg avail_insn = NULL; 1072 1.1 mrg avail_reg = NULL_RTX; 1073 1.1 mrg pred_bb = pred->src; 1074 1.1 mrg for (a_occr = get_bb_avail_insn (pred_bb, 1075 1.1 mrg expr->avail_occr, 1076 1.1 mrg expr->bitmap_index); 1077 1.1 mrg a_occr; 1078 1.1 mrg a_occr = get_bb_avail_insn (pred_bb, 1079 1.1 mrg a_occr->next, 1080 1.1 mrg expr->bitmap_index)) 1081 1.1 mrg { 1082 1.1 mrg /* Check if the loaded register is not used. */ 1083 1.1 mrg avail_insn = a_occr->insn; 1084 1.1 mrg avail_reg = get_avail_load_store_reg (avail_insn); 1085 1.1 mrg gcc_assert (avail_reg); 1086 1.1 mrg 1087 1.1 mrg /* Make sure we can generate a move from register avail_reg to 1088 1.1 mrg dest. */ 1089 1.1 mrg rtx_insn *move = gen_move_insn (copy_rtx (dest), 1090 1.1 mrg copy_rtx (avail_reg)); 1091 1.1 mrg extract_insn (move); 1092 1.1 mrg if (! constrain_operands (1, get_preferred_alternatives (insn, 1093 1.1 mrg pred_bb)) 1094 1.1 mrg || reg_killed_on_edge (avail_reg, pred) 1095 1.1 mrg || reg_used_on_edge (dest, pred)) 1096 1.1 mrg { 1097 1.1 mrg avail_insn = NULL; 1098 1.1 mrg continue; 1099 1.1 mrg } 1100 1.1 mrg next_pred_bb_end = NEXT_INSN (BB_END (BLOCK_FOR_INSN (avail_insn))); 1101 1.1 mrg if (!reg_set_between_p (avail_reg, avail_insn, next_pred_bb_end)) 1102 1.1 mrg /* AVAIL_INSN remains non-null. */ 1103 1.1 mrg break; 1104 1.1 mrg else 1105 1.1 mrg avail_insn = NULL; 1106 1.1 mrg } 1107 1.1 mrg 1108 1.1 mrg if (EDGE_CRITICAL_P (pred) && pred->count ().initialized_p ()) 1109 1.1 mrg critical_count += pred->count (); 1110 1.1 mrg 1111 1.1 mrg if (avail_insn != NULL_RTX) 1112 1.1 mrg { 1113 1.1 mrg npred_ok++; 1114 1.1 mrg if (pred->count ().initialized_p ()) 1115 1.1 mrg ok_count = ok_count + pred->count (); 1116 1.1 mrg if (! set_noop_p (PATTERN (gen_move_insn (copy_rtx (dest), 1117 1.1 mrg copy_rtx (avail_reg))))) 1118 1.1 mrg { 1119 1.1 mrg /* Check if there is going to be a split. */ 1120 1.1 mrg if (EDGE_CRITICAL_P (pred)) 1121 1.1 mrg critical_edge_split = true; 1122 1.1 mrg } 1123 1.1 mrg else /* Its a dead move no need to generate. */ 1124 1.1 mrg continue; 1125 1.1 mrg occr = (struct unoccr *) obstack_alloc (&unoccr_obstack, 1126 1.1 mrg sizeof (struct unoccr)); 1127 1.1 mrg occr->insn = avail_insn; 1128 1.1 mrg occr->pred = pred; 1129 1.1 mrg occr->next = avail_occrs; 1130 1.1 mrg avail_occrs = occr; 1131 1.1 mrg if (! rollback_unoccr) 1132 1.1 mrg rollback_unoccr = occr; 1133 1.1 mrg } 1134 1.1 mrg else 1135 1.1 mrg { 1136 1.1 mrg /* Adding a load on a critical edge will cause a split. */ 1137 1.1 mrg if (EDGE_CRITICAL_P (pred)) 1138 1.1 mrg critical_edge_split = true; 1139 1.1 mrg if (pred->count ().initialized_p ()) 1140 1.1 mrg not_ok_count = not_ok_count + pred->count (); 1141 1.1 mrg unoccr = (struct unoccr *) obstack_alloc (&unoccr_obstack, 1142 1.1 mrg sizeof (struct unoccr)); 1143 1.1 mrg unoccr->insn = NULL; 1144 1.1 mrg unoccr->pred = pred; 1145 1.1 mrg unoccr->next = unavail_occrs; 1146 1.1 mrg unavail_occrs = unoccr; 1147 1.1 mrg if (! rollback_unoccr) 1148 1.1 mrg rollback_unoccr = unoccr; 1149 1.1 mrg } 1150 1.1 mrg } 1151 1.1 mrg 1152 1.1 mrg if (/* No load can be replaced by copy. */ 1153 1.1 mrg npred_ok == 0 1154 1.1 mrg /* Prevent exploding the code. */ 1155 1.1 mrg || (optimize_bb_for_size_p (bb) && npred_ok > 1) 1156 1.1 mrg /* If we don't have profile information we cannot tell if splitting 1157 1.1 mrg a critical edge is profitable or not so don't do it. */ 1158 1.1 mrg || ((!profile_info || profile_status_for_fn (cfun) != PROFILE_READ 1159 1.1 mrg || targetm.cannot_modify_jumps_p ()) 1160 1.1 mrg && critical_edge_split)) 1161 1.1 mrg goto cleanup; 1162 1.1 mrg 1163 1.1 mrg /* Check if it's worth applying the partial redundancy elimination. */ 1164 1.1 mrg if (ok_count.to_gcov_type () 1165 1.1 mrg < param_gcse_after_reload_partial_fraction * not_ok_count.to_gcov_type ()) 1166 1.1 mrg goto cleanup; 1167 1.1 mrg 1168 1.1 mrg gcov_type threshold; 1169 1.1 mrg #if (GCC_VERSION >= 5000) 1170 1.1 mrg if (__builtin_mul_overflow (param_gcse_after_reload_critical_fraction, 1171 1.1 mrg critical_count.to_gcov_type (), &threshold)) 1172 1.1 mrg threshold = profile_count::max_count; 1173 1.1 mrg #else 1174 1.1 mrg threshold 1175 1.1 mrg = (param_gcse_after_reload_critical_fraction 1176 1.1 mrg * critical_count.to_gcov_type ()); 1177 1.1 mrg #endif 1178 1.1 mrg 1179 1.1 mrg if (ok_count.to_gcov_type () < threshold) 1180 1.1 mrg goto cleanup; 1181 1.1 mrg 1182 1.1 mrg /* Generate moves to the loaded register from where 1183 1.1 mrg the memory is available. */ 1184 1.1 mrg for (occr = avail_occrs; occr; occr = occr->next) 1185 1.1 mrg { 1186 1.1 mrg avail_insn = occr->insn; 1187 1.1 mrg pred = occr->pred; 1188 1.1 mrg /* Set avail_reg to be the register having the value of the 1189 1.1 mrg memory. */ 1190 1.1 mrg avail_reg = get_avail_load_store_reg (avail_insn); 1191 1.1 mrg gcc_assert (avail_reg); 1192 1.1 mrg 1193 1.1 mrg insert_insn_on_edge (gen_move_insn (copy_rtx (dest), 1194 1.1 mrg copy_rtx (avail_reg)), 1195 1.1 mrg pred); 1196 1.1 mrg stats.moves_inserted++; 1197 1.1 mrg 1198 1.1 mrg if (dump_file) 1199 1.1 mrg fprintf (dump_file, 1200 1.1 mrg "generating move from %d to %d on edge from %d to %d\n", 1201 1.1 mrg REGNO (avail_reg), 1202 1.1 mrg REGNO (dest), 1203 1.1 mrg pred->src->index, 1204 1.1 mrg pred->dest->index); 1205 1.1 mrg } 1206 1.1 mrg 1207 1.1 mrg /* Regenerate loads where the memory is unavailable. */ 1208 1.1 mrg for (unoccr = unavail_occrs; unoccr; unoccr = unoccr->next) 1209 1.1 mrg { 1210 1.1 mrg pred = unoccr->pred; 1211 1.1 mrg insert_insn_on_edge (copy_insn (PATTERN (insn)), pred); 1212 1.1 mrg stats.copies_inserted++; 1213 1.1 mrg 1214 1.1 mrg if (dump_file) 1215 1.1 mrg { 1216 1.1 mrg fprintf (dump_file, 1217 1.1 mrg "generating on edge from %d to %d a copy of load: ", 1218 1.1 mrg pred->src->index, 1219 1.1 mrg pred->dest->index); 1220 1.1 mrg print_rtl (dump_file, PATTERN (insn)); 1221 1.1 mrg fprintf (dump_file, "\n"); 1222 1.1 mrg } 1223 1.1 mrg } 1224 1.1 mrg 1225 1.1 mrg /* Delete the insn if it is not available in this block and mark it 1226 1.1 mrg for deletion if it is available. If insn is available it may help 1227 1.1 mrg discover additional redundancies, so mark it for later deletion. */ 1228 1.1 mrg for (a_occr = get_bb_avail_insn (bb, expr->avail_occr, expr->bitmap_index); 1229 1.1 mrg a_occr && (a_occr->insn != insn); 1230 1.1 mrg a_occr = get_bb_avail_insn (bb, a_occr->next, expr->bitmap_index)) 1231 1.1 mrg ; 1232 1.1 mrg 1233 1.1 mrg if (!a_occr) 1234 1.1 mrg { 1235 1.1 mrg stats.insns_deleted++; 1236 1.1 mrg 1237 1.1 mrg if (dump_file) 1238 1.1 mrg { 1239 1.1 mrg fprintf (dump_file, "deleting insn:\n"); 1240 1.1 mrg print_rtl_single (dump_file, insn); 1241 1.1 mrg fprintf (dump_file, "\n"); 1242 1.1 mrg } 1243 1.1 mrg delete_insn (insn); 1244 1.1 mrg } 1245 1.1 mrg else 1246 1.1 mrg a_occr->deleted_p = 1; 1247 1.1 mrg 1248 1.1 mrg cleanup: 1249 1.1 mrg if (rollback_unoccr) 1250 1.1 mrg obstack_free (&unoccr_obstack, rollback_unoccr); 1251 1.1 mrg } 1252 1.1 mrg 1253 1.1 mrg /* Performing the redundancy elimination as described before. */ 1254 1.1 mrg 1255 1.1 mrg static void 1256 1.1 mrg eliminate_partially_redundant_loads (void) 1257 1.1 mrg { 1258 1.1 mrg rtx_insn *insn; 1259 1.1 mrg basic_block bb; 1260 1.1 mrg 1261 1.1 mrg /* Note we start at block 1. */ 1262 1.1 mrg 1263 1.1 mrg if (ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb == EXIT_BLOCK_PTR_FOR_FN (cfun)) 1264 1.1 mrg return; 1265 1.1 mrg 1266 1.1 mrg FOR_BB_BETWEEN (bb, 1267 1.1 mrg ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb->next_bb, 1268 1.1 mrg EXIT_BLOCK_PTR_FOR_FN (cfun), 1269 1.1 mrg next_bb) 1270 1.1 mrg { 1271 1.1 mrg /* Don't try anything on basic blocks with strange predecessors. */ 1272 1.1 mrg if (! bb_has_well_behaved_predecessors (bb)) 1273 1.1 mrg continue; 1274 1.1 mrg 1275 1.1 mrg /* Do not try anything on cold basic blocks. */ 1276 1.1 mrg if (optimize_bb_for_size_p (bb)) 1277 1.1 mrg continue; 1278 1.1 mrg 1279 1.1 mrg /* Reset the table of things changed since the start of the current 1280 1.1 mrg basic block. */ 1281 1.1 mrg reset_opr_set_tables (); 1282 1.1 mrg 1283 1.1 mrg /* Look at all insns in the current basic block and see if there are 1284 1.1 mrg any loads in it that we can record. */ 1285 1.1 mrg FOR_BB_INSNS (bb, insn) 1286 1.1 mrg { 1287 1.1 mrg /* Is it a load - of the form (set (reg) (mem))? */ 1288 1.1 mrg if (NONJUMP_INSN_P (insn) 1289 1.1 mrg && GET_CODE (PATTERN (insn)) == SET 1290 1.1 mrg && REG_P (SET_DEST (PATTERN (insn))) 1291 1.1 mrg && MEM_P (SET_SRC (PATTERN (insn)))) 1292 1.1 mrg { 1293 1.1 mrg rtx pat = PATTERN (insn); 1294 1.1 mrg rtx src = SET_SRC (pat); 1295 1.1 mrg struct expr *expr; 1296 1.1 mrg 1297 1.1 mrg if (!MEM_VOLATILE_P (src) 1298 1.1 mrg && GET_MODE (src) != BLKmode 1299 1.1 mrg && general_operand (src, GET_MODE (src)) 1300 1.1 mrg /* Are the operands unchanged since the start of the 1301 1.1 mrg block? */ 1302 1.1 mrg && oprs_unchanged_p (src, insn, false) 1303 1.1 mrg && !(cfun->can_throw_non_call_exceptions && may_trap_p (src)) 1304 1.1 mrg && !side_effects_p (src) 1305 1.1 mrg /* Is the expression recorded? */ 1306 1.1 mrg && (expr = lookup_expr_in_table (src)) != NULL) 1307 1.1 mrg { 1308 1.1 mrg /* We now have a load (insn) and an available memory at 1309 1.1 mrg its BB start (expr). Try to remove the loads if it is 1310 1.1 mrg redundant. */ 1311 1.1 mrg eliminate_partially_redundant_load (bb, insn, expr); 1312 1.1 mrg } 1313 1.1 mrg } 1314 1.1 mrg 1315 1.1 mrg /* Keep track of everything modified by this insn, so that we 1316 1.1 mrg know what has been modified since the start of the current 1317 1.1 mrg basic block. */ 1318 1.1 mrg if (INSN_P (insn)) 1319 1.1 mrg record_opr_changes (insn); 1320 1.1 mrg } 1321 1.1 mrg } 1322 1.1 mrg 1323 1.1 mrg commit_edge_insertions (); 1324 1.1 mrg } 1325 1.1 mrg 1326 1.1 mrg /* Go over the expression hash table and delete insns that were 1327 1.1 mrg marked for later deletion. */ 1328 1.1 mrg 1329 1.1 mrg /* This helper is called via htab_traverse. */ 1330 1.1 mrg int 1331 1.1 mrg delete_redundant_insns_1 (expr **slot, void *data ATTRIBUTE_UNUSED) 1332 1.1 mrg { 1333 1.1 mrg struct expr *exprs = *slot; 1334 1.1 mrg struct occr *occr; 1335 1.1 mrg 1336 1.1 mrg for (occr = exprs->avail_occr; occr != NULL; occr = occr->next) 1337 1.1 mrg { 1338 1.1 mrg if (occr->deleted_p && dbg_cnt (gcse2_delete)) 1339 1.1 mrg { 1340 1.1 mrg delete_insn (occr->insn); 1341 1.1 mrg stats.insns_deleted++; 1342 1.1 mrg 1343 1.1 mrg if (dump_file) 1344 1.1 mrg { 1345 1.1 mrg fprintf (dump_file, "deleting insn:\n"); 1346 1.1 mrg print_rtl_single (dump_file, occr->insn); 1347 1.1 mrg fprintf (dump_file, "\n"); 1348 1.1 mrg } 1349 1.1 mrg } 1350 1.1 mrg } 1351 1.1 mrg 1352 1.1 mrg return 1; 1353 1.1 mrg } 1354 1.1 mrg 1355 1.1 mrg static void 1356 1.1 mrg delete_redundant_insns (void) 1357 1.1 mrg { 1358 1.1 mrg expr_table->traverse <void *, delete_redundant_insns_1> (NULL); 1359 1.1 mrg if (dump_file) 1360 1.1 mrg fprintf (dump_file, "\n"); 1361 1.1 mrg } 1362 1.1 mrg 1363 1.1 mrg /* Main entry point of the GCSE after reload - clean some redundant loads 1364 1.1 mrg due to spilling. */ 1365 1.1 mrg 1366 1.1 mrg static void 1367 1.1 mrg gcse_after_reload_main (rtx f ATTRIBUTE_UNUSED) 1368 1.1 mrg { 1369 1.1 mrg /* Disable computing transparentness if it is too expensive. */ 1370 1.1 mrg bool do_transp 1371 1.1 mrg = !gcse_or_cprop_is_too_expensive (_("using simple load CSE after register " 1372 1.1 mrg "allocation")); 1373 1.1 mrg 1374 1.1 mrg memset (&stats, 0, sizeof (stats)); 1375 1.1 mrg 1376 1.1 mrg /* Allocate memory for this pass. 1377 1.1 mrg Also computes and initializes the insns' CUIDs. */ 1378 1.1 mrg alloc_mem (); 1379 1.1 mrg 1380 1.1 mrg /* We need alias analysis. */ 1381 1.1 mrg init_alias_analysis (); 1382 1.1 mrg 1383 1.1 mrg compute_hash_table (); 1384 1.1 mrg 1385 1.1 mrg if (dump_file) 1386 1.1 mrg dump_hash_table (dump_file); 1387 1.1 mrg 1388 1.1 mrg if (!expr_table->is_empty ()) 1389 1.1 mrg { 1390 1.1 mrg /* Knowing which MEMs are transparent through a block can signifiantly 1391 1.1 mrg increase the number of redundant loads found. So compute transparency 1392 1.1 mrg information for each memory expression in the hash table. */ 1393 1.1 mrg df_analyze (); 1394 1.1 mrg if (do_transp) 1395 1.1 mrg { 1396 1.1 mrg /* This cannot be part of the normal allocation routine because 1397 1.1 mrg we have to know the number of elements in the hash table. */ 1398 1.1 mrg transp = sbitmap_vector_alloc (last_basic_block_for_fn (cfun), 1399 1.1 mrg expr_table->elements ()); 1400 1.1 mrg bitmap_vector_ones (transp, last_basic_block_for_fn (cfun)); 1401 1.1 mrg expr_table->traverse <FILE *, compute_expr_transp> (dump_file); 1402 1.1 mrg } 1403 1.1 mrg else 1404 1.1 mrg transp = NULL; 1405 1.1 mrg eliminate_partially_redundant_loads (); 1406 1.1 mrg delete_redundant_insns (); 1407 1.1 mrg if (do_transp) 1408 1.1 mrg sbitmap_vector_free (transp); 1409 1.1 mrg 1410 1.1 mrg if (dump_file) 1411 1.1 mrg { 1412 1.1 mrg fprintf (dump_file, "GCSE AFTER RELOAD stats:\n"); 1413 1.1 mrg fprintf (dump_file, "copies inserted: %d\n", stats.copies_inserted); 1414 1.1 mrg fprintf (dump_file, "moves inserted: %d\n", stats.moves_inserted); 1415 1.1 mrg fprintf (dump_file, "insns deleted: %d\n", stats.insns_deleted); 1416 1.1 mrg fprintf (dump_file, "\n\n"); 1417 1.1 mrg } 1418 1.1 mrg 1419 1.1 mrg statistics_counter_event (cfun, "copies inserted", 1420 1.1 mrg stats.copies_inserted); 1421 1.1 mrg statistics_counter_event (cfun, "moves inserted", 1422 1.1 mrg stats.moves_inserted); 1423 1.1 mrg statistics_counter_event (cfun, "insns deleted", 1424 1.1 mrg stats.insns_deleted); 1425 1.1 mrg } 1426 1.1 mrg 1427 1.1 mrg /* We are finished with alias. */ 1428 1.1 mrg end_alias_analysis (); 1429 1.1 mrg 1430 1.1 mrg free_mem (); 1431 1.1 mrg } 1432 1.1 mrg 1433 1.1 mrg 1434 1.1 mrg 1436 1.1 mrg static unsigned int 1437 1.1 mrg rest_of_handle_gcse2 (void) 1438 1.1 mrg { 1439 1.1 mrg gcse_after_reload_main (get_insns ()); 1440 1.1 mrg rebuild_jump_labels (get_insns ()); 1441 1.1 mrg return 0; 1442 1.1 mrg } 1443 1.1 mrg 1444 1.1 mrg namespace { 1445 1.1 mrg 1446 1.1 mrg const pass_data pass_data_gcse2 = 1447 1.1 mrg { 1448 1.1 mrg RTL_PASS, /* type */ 1449 1.1 mrg "gcse2", /* name */ 1450 1.1 mrg OPTGROUP_NONE, /* optinfo_flags */ 1451 1.1 mrg TV_GCSE_AFTER_RELOAD, /* tv_id */ 1452 1.1 mrg 0, /* properties_required */ 1453 1.1 mrg 0, /* properties_provided */ 1454 1.1 mrg 0, /* properties_destroyed */ 1455 1.1 mrg 0, /* todo_flags_start */ 1456 1.1 mrg 0, /* todo_flags_finish */ 1457 1.1 mrg }; 1458 1.1 mrg 1459 1.1 mrg class pass_gcse2 : public rtl_opt_pass 1460 1.1 mrg { 1461 1.1 mrg public: 1462 1.1 mrg pass_gcse2 (gcc::context *ctxt) 1463 1.1 mrg : rtl_opt_pass (pass_data_gcse2, ctxt) 1464 1.1 mrg {} 1465 1.1 mrg 1466 1.1 mrg /* opt_pass methods: */ 1467 virtual bool gate (function *fun) 1468 { 1469 return (optimize > 0 && flag_gcse_after_reload 1470 && optimize_function_for_speed_p (fun)); 1471 } 1472 1473 virtual unsigned int execute (function *) { return rest_of_handle_gcse2 (); } 1474 1475 }; // class pass_gcse2 1476 1477 } // anon namespace 1478 1479 rtl_opt_pass * 1480 make_pass_gcse2 (gcc::context *ctxt) 1481 { 1482 return new pass_gcse2 (ctxt); 1483 } 1484