* gcc.dg/vect/vect-outer-simd-1.c: Remove cleanup-tree-dump directive.
[official-gcc.git] / gcc / sched-deps.c
blob1671ccd501ba757091687c337d3679c5550f7153
1 /* Instruction scheduling pass. This file computes dependencies between
2 instructions.
3 Copyright (C) 1992-2015 Free Software Foundation, Inc.
4 Contributed by Michael Tiemann (tiemann@cygnus.com) Enhanced by,
5 and currently maintained by, Jim Wilson (wilson@cygnus.com)
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
12 version.
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 for more details.
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
23 #include "config.h"
24 #include "system.h"
25 #include "coretypes.h"
26 #include "tm.h"
27 #include "diagnostic-core.h"
28 #include "rtl.h"
29 #include "hash-set.h"
30 #include "machmode.h"
31 #include "vec.h"
32 #include "double-int.h"
33 #include "input.h"
34 #include "alias.h"
35 #include "symtab.h"
36 #include "wide-int.h"
37 #include "inchash.h"
38 #include "tree.h" /* FIXME: Used by call_may_noreturn_p. */
39 #include "tm_p.h"
40 #include "hard-reg-set.h"
41 #include "regs.h"
42 #include "input.h"
43 #include "function.h"
44 #include "flags.h"
45 #include "insn-config.h"
46 #include "insn-attr.h"
47 #include "except.h"
48 #include "recog.h"
49 #include "emit-rtl.h"
50 #include "dominance.h"
51 #include "cfg.h"
52 #include "cfgbuild.h"
53 #include "predict.h"
54 #include "basic-block.h"
55 #include "sched-int.h"
56 #include "params.h"
57 #include "alloc-pool.h"
58 #include "cselib.h"
59 #include "ira.h"
60 #include "target.h"
62 #ifdef INSN_SCHEDULING
64 #ifdef ENABLE_CHECKING
65 #define CHECK (true)
66 #else
67 #define CHECK (false)
68 #endif
70 /* Holds current parameters for the dependency analyzer. */
71 struct sched_deps_info_def *sched_deps_info;
73 /* The data is specific to the Haifa scheduler. */
74 vec<haifa_deps_insn_data_def>
75 h_d_i_d = vNULL;
77 /* Return the major type present in the DS. */
78 enum reg_note
79 ds_to_dk (ds_t ds)
81 if (ds & DEP_TRUE)
82 return REG_DEP_TRUE;
84 if (ds & DEP_OUTPUT)
85 return REG_DEP_OUTPUT;
87 if (ds & DEP_CONTROL)
88 return REG_DEP_CONTROL;
90 gcc_assert (ds & DEP_ANTI);
92 return REG_DEP_ANTI;
95 /* Return equivalent dep_status. */
96 ds_t
97 dk_to_ds (enum reg_note dk)
99 switch (dk)
101 case REG_DEP_TRUE:
102 return DEP_TRUE;
104 case REG_DEP_OUTPUT:
105 return DEP_OUTPUT;
107 case REG_DEP_CONTROL:
108 return DEP_CONTROL;
110 default:
111 gcc_assert (dk == REG_DEP_ANTI);
112 return DEP_ANTI;
116 /* Functions to operate with dependence information container - dep_t. */
118 /* Init DEP with the arguments. */
119 void
120 init_dep_1 (dep_t dep, rtx_insn *pro, rtx_insn *con, enum reg_note type, ds_t ds)
122 DEP_PRO (dep) = pro;
123 DEP_CON (dep) = con;
124 DEP_TYPE (dep) = type;
125 DEP_STATUS (dep) = ds;
126 DEP_COST (dep) = UNKNOWN_DEP_COST;
127 DEP_NONREG (dep) = 0;
128 DEP_MULTIPLE (dep) = 0;
129 DEP_REPLACE (dep) = NULL;
132 /* Init DEP with the arguments.
133 While most of the scheduler (including targets) only need the major type
134 of the dependency, it is convenient to hide full dep_status from them. */
135 void
136 init_dep (dep_t dep, rtx_insn *pro, rtx_insn *con, enum reg_note kind)
138 ds_t ds;
140 if ((current_sched_info->flags & USE_DEPS_LIST))
141 ds = dk_to_ds (kind);
142 else
143 ds = 0;
145 init_dep_1 (dep, pro, con, kind, ds);
148 /* Make a copy of FROM in TO. */
149 static void
150 copy_dep (dep_t to, dep_t from)
152 memcpy (to, from, sizeof (*to));
155 static void dump_ds (FILE *, ds_t);
157 /* Define flags for dump_dep (). */
159 /* Dump producer of the dependence. */
160 #define DUMP_DEP_PRO (2)
162 /* Dump consumer of the dependence. */
163 #define DUMP_DEP_CON (4)
165 /* Dump type of the dependence. */
166 #define DUMP_DEP_TYPE (8)
168 /* Dump status of the dependence. */
169 #define DUMP_DEP_STATUS (16)
171 /* Dump all information about the dependence. */
172 #define DUMP_DEP_ALL (DUMP_DEP_PRO | DUMP_DEP_CON | DUMP_DEP_TYPE \
173 |DUMP_DEP_STATUS)
175 /* Dump DEP to DUMP.
176 FLAGS is a bit mask specifying what information about DEP needs
177 to be printed.
178 If FLAGS has the very first bit set, then dump all information about DEP
179 and propagate this bit into the callee dump functions. */
180 static void
181 dump_dep (FILE *dump, dep_t dep, int flags)
183 if (flags & 1)
184 flags |= DUMP_DEP_ALL;
186 fprintf (dump, "<");
188 if (flags & DUMP_DEP_PRO)
189 fprintf (dump, "%d; ", INSN_UID (DEP_PRO (dep)));
191 if (flags & DUMP_DEP_CON)
192 fprintf (dump, "%d; ", INSN_UID (DEP_CON (dep)));
194 if (flags & DUMP_DEP_TYPE)
196 char t;
197 enum reg_note type = DEP_TYPE (dep);
199 switch (type)
201 case REG_DEP_TRUE:
202 t = 't';
203 break;
205 case REG_DEP_OUTPUT:
206 t = 'o';
207 break;
209 case REG_DEP_CONTROL:
210 t = 'c';
211 break;
213 case REG_DEP_ANTI:
214 t = 'a';
215 break;
217 default:
218 gcc_unreachable ();
219 break;
222 fprintf (dump, "%c; ", t);
225 if (flags & DUMP_DEP_STATUS)
227 if (current_sched_info->flags & USE_DEPS_LIST)
228 dump_ds (dump, DEP_STATUS (dep));
231 fprintf (dump, ">");
234 /* Default flags for dump_dep (). */
235 static int dump_dep_flags = (DUMP_DEP_PRO | DUMP_DEP_CON);
237 /* Dump all fields of DEP to STDERR. */
238 void
239 sd_debug_dep (dep_t dep)
241 dump_dep (stderr, dep, 1);
242 fprintf (stderr, "\n");
245 /* Determine whether DEP is a dependency link of a non-debug insn on a
246 debug insn. */
248 static inline bool
249 depl_on_debug_p (dep_link_t dep)
251 return (DEBUG_INSN_P (DEP_LINK_PRO (dep))
252 && !DEBUG_INSN_P (DEP_LINK_CON (dep)));
255 /* Functions to operate with a single link from the dependencies lists -
256 dep_link_t. */
258 /* Attach L to appear after link X whose &DEP_LINK_NEXT (X) is given by
259 PREV_NEXT_P. */
260 static void
261 attach_dep_link (dep_link_t l, dep_link_t *prev_nextp)
263 dep_link_t next = *prev_nextp;
265 gcc_assert (DEP_LINK_PREV_NEXTP (l) == NULL
266 && DEP_LINK_NEXT (l) == NULL);
268 /* Init node being inserted. */
269 DEP_LINK_PREV_NEXTP (l) = prev_nextp;
270 DEP_LINK_NEXT (l) = next;
272 /* Fix next node. */
273 if (next != NULL)
275 gcc_assert (DEP_LINK_PREV_NEXTP (next) == prev_nextp);
277 DEP_LINK_PREV_NEXTP (next) = &DEP_LINK_NEXT (l);
280 /* Fix prev node. */
281 *prev_nextp = l;
284 /* Add dep_link LINK to deps_list L. */
285 static void
286 add_to_deps_list (dep_link_t link, deps_list_t l)
288 attach_dep_link (link, &DEPS_LIST_FIRST (l));
290 /* Don't count debug deps. */
291 if (!depl_on_debug_p (link))
292 ++DEPS_LIST_N_LINKS (l);
295 /* Detach dep_link L from the list. */
296 static void
297 detach_dep_link (dep_link_t l)
299 dep_link_t *prev_nextp = DEP_LINK_PREV_NEXTP (l);
300 dep_link_t next = DEP_LINK_NEXT (l);
302 *prev_nextp = next;
304 if (next != NULL)
305 DEP_LINK_PREV_NEXTP (next) = prev_nextp;
307 DEP_LINK_PREV_NEXTP (l) = NULL;
308 DEP_LINK_NEXT (l) = NULL;
311 /* Remove link LINK from list LIST. */
312 static void
313 remove_from_deps_list (dep_link_t link, deps_list_t list)
315 detach_dep_link (link);
317 /* Don't count debug deps. */
318 if (!depl_on_debug_p (link))
319 --DEPS_LIST_N_LINKS (list);
322 /* Move link LINK from list FROM to list TO. */
323 static void
324 move_dep_link (dep_link_t link, deps_list_t from, deps_list_t to)
326 remove_from_deps_list (link, from);
327 add_to_deps_list (link, to);
330 /* Return true of LINK is not attached to any list. */
331 static bool
332 dep_link_is_detached_p (dep_link_t link)
334 return DEP_LINK_PREV_NEXTP (link) == NULL;
337 /* Pool to hold all dependency nodes (dep_node_t). */
338 static pool_allocator<_dep_node> *dn_pool;
340 /* Number of dep_nodes out there. */
341 static int dn_pool_diff = 0;
343 /* Create a dep_node. */
344 static dep_node_t
345 create_dep_node (void)
347 dep_node_t n = dn_pool->allocate ();
348 dep_link_t back = DEP_NODE_BACK (n);
349 dep_link_t forw = DEP_NODE_FORW (n);
351 DEP_LINK_NODE (back) = n;
352 DEP_LINK_NEXT (back) = NULL;
353 DEP_LINK_PREV_NEXTP (back) = NULL;
355 DEP_LINK_NODE (forw) = n;
356 DEP_LINK_NEXT (forw) = NULL;
357 DEP_LINK_PREV_NEXTP (forw) = NULL;
359 ++dn_pool_diff;
361 return n;
364 /* Delete dep_node N. N must not be connected to any deps_list. */
365 static void
366 delete_dep_node (dep_node_t n)
368 gcc_assert (dep_link_is_detached_p (DEP_NODE_BACK (n))
369 && dep_link_is_detached_p (DEP_NODE_FORW (n)));
371 XDELETE (DEP_REPLACE (DEP_NODE_DEP (n)));
373 --dn_pool_diff;
375 dn_pool->remove (n);
378 /* Pool to hold dependencies lists (deps_list_t). */
379 static pool_allocator<_deps_list> *dl_pool;
381 /* Number of deps_lists out there. */
382 static int dl_pool_diff = 0;
384 /* Functions to operate with dependences lists - deps_list_t. */
386 /* Return true if list L is empty. */
387 static bool
388 deps_list_empty_p (deps_list_t l)
390 return DEPS_LIST_N_LINKS (l) == 0;
393 /* Create a new deps_list. */
394 static deps_list_t
395 create_deps_list (void)
397 deps_list_t l = dl_pool->allocate ();
399 DEPS_LIST_FIRST (l) = NULL;
400 DEPS_LIST_N_LINKS (l) = 0;
402 ++dl_pool_diff;
403 return l;
406 /* Free deps_list L. */
407 static void
408 free_deps_list (deps_list_t l)
410 gcc_assert (deps_list_empty_p (l));
412 --dl_pool_diff;
414 dl_pool->remove (l);
417 /* Return true if there is no dep_nodes and deps_lists out there.
418 After the region is scheduled all the dependency nodes and lists
419 should [generally] be returned to pool. */
420 bool
421 deps_pools_are_empty_p (void)
423 return dn_pool_diff == 0 && dl_pool_diff == 0;
426 /* Remove all elements from L. */
427 static void
428 clear_deps_list (deps_list_t l)
432 dep_link_t link = DEPS_LIST_FIRST (l);
434 if (link == NULL)
435 break;
437 remove_from_deps_list (link, l);
439 while (1);
442 /* Decide whether a dependency should be treated as a hard or a speculative
443 dependency. */
444 static bool
445 dep_spec_p (dep_t dep)
447 if (current_sched_info->flags & DO_SPECULATION)
449 if (DEP_STATUS (dep) & SPECULATIVE)
450 return true;
452 if (current_sched_info->flags & DO_PREDICATION)
454 if (DEP_TYPE (dep) == REG_DEP_CONTROL)
455 return true;
457 if (DEP_REPLACE (dep) != NULL)
458 return true;
459 return false;
462 static regset reg_pending_sets;
463 static regset reg_pending_clobbers;
464 static regset reg_pending_uses;
465 static regset reg_pending_control_uses;
466 static enum reg_pending_barrier_mode reg_pending_barrier;
468 /* Hard registers implicitly clobbered or used (or may be implicitly
469 clobbered or used) by the currently analyzed insn. For example,
470 insn in its constraint has one register class. Even if there is
471 currently no hard register in the insn, the particular hard
472 register will be in the insn after reload pass because the
473 constraint requires it. */
474 static HARD_REG_SET implicit_reg_pending_clobbers;
475 static HARD_REG_SET implicit_reg_pending_uses;
477 /* To speed up the test for duplicate dependency links we keep a
478 record of dependencies created by add_dependence when the average
479 number of instructions in a basic block is very large.
481 Studies have shown that there is typically around 5 instructions between
482 branches for typical C code. So we can make a guess that the average
483 basic block is approximately 5 instructions long; we will choose 100X
484 the average size as a very large basic block.
486 Each insn has associated bitmaps for its dependencies. Each bitmap
487 has enough entries to represent a dependency on any other insn in
488 the insn chain. All bitmap for true dependencies cache is
489 allocated then the rest two ones are also allocated. */
490 static bitmap_head *true_dependency_cache = NULL;
491 static bitmap_head *output_dependency_cache = NULL;
492 static bitmap_head *anti_dependency_cache = NULL;
493 static bitmap_head *control_dependency_cache = NULL;
494 static bitmap_head *spec_dependency_cache = NULL;
495 static int cache_size;
497 /* True if we should mark added dependencies as a non-register deps. */
498 static bool mark_as_hard;
500 static int deps_may_trap_p (const_rtx);
501 static void add_dependence_1 (rtx_insn *, rtx_insn *, enum reg_note);
502 static void add_dependence_list (rtx_insn *, rtx_insn_list *, int,
503 enum reg_note, bool);
504 static void add_dependence_list_and_free (struct deps_desc *, rtx_insn *,
505 rtx_insn_list **, int, enum reg_note,
506 bool);
507 static void delete_all_dependences (rtx_insn *);
508 static void chain_to_prev_insn (rtx_insn *);
510 static void flush_pending_lists (struct deps_desc *, rtx_insn *, int, int);
511 static void sched_analyze_1 (struct deps_desc *, rtx, rtx_insn *);
512 static void sched_analyze_2 (struct deps_desc *, rtx, rtx_insn *);
513 static void sched_analyze_insn (struct deps_desc *, rtx, rtx_insn *);
515 static bool sched_has_condition_p (const rtx_insn *);
516 static int conditions_mutex_p (const_rtx, const_rtx, bool, bool);
518 static enum DEPS_ADJUST_RESULT maybe_add_or_update_dep_1 (dep_t, bool,
519 rtx, rtx);
520 static enum DEPS_ADJUST_RESULT add_or_update_dep_1 (dep_t, bool, rtx, rtx);
522 #ifdef ENABLE_CHECKING
523 static void check_dep (dep_t, bool);
524 #endif
526 /* Return nonzero if a load of the memory reference MEM can cause a trap. */
528 static int
529 deps_may_trap_p (const_rtx mem)
531 const_rtx addr = XEXP (mem, 0);
533 if (REG_P (addr) && REGNO (addr) >= FIRST_PSEUDO_REGISTER)
535 const_rtx t = get_reg_known_value (REGNO (addr));
536 if (t)
537 addr = t;
539 return rtx_addr_can_trap_p (addr);
543 /* Find the condition under which INSN is executed. If REV is not NULL,
544 it is set to TRUE when the returned comparison should be reversed
545 to get the actual condition. */
546 static rtx
547 sched_get_condition_with_rev_uncached (const rtx_insn *insn, bool *rev)
549 rtx pat = PATTERN (insn);
550 rtx src;
552 if (rev)
553 *rev = false;
555 if (GET_CODE (pat) == COND_EXEC)
556 return COND_EXEC_TEST (pat);
558 if (!any_condjump_p (insn) || !onlyjump_p (insn))
559 return 0;
561 src = SET_SRC (pc_set (insn));
563 if (XEXP (src, 2) == pc_rtx)
564 return XEXP (src, 0);
565 else if (XEXP (src, 1) == pc_rtx)
567 rtx cond = XEXP (src, 0);
568 enum rtx_code revcode = reversed_comparison_code (cond, insn);
570 if (revcode == UNKNOWN)
571 return 0;
573 if (rev)
574 *rev = true;
575 return cond;
578 return 0;
581 /* Return the condition under which INSN does not execute (i.e. the
582 not-taken condition for a conditional branch), or NULL if we cannot
583 find such a condition. The caller should make a copy of the condition
584 before using it. */
586 sched_get_reverse_condition_uncached (const rtx_insn *insn)
588 bool rev;
589 rtx cond = sched_get_condition_with_rev_uncached (insn, &rev);
590 if (cond == NULL_RTX)
591 return cond;
592 if (!rev)
594 enum rtx_code revcode = reversed_comparison_code (cond, insn);
595 cond = gen_rtx_fmt_ee (revcode, GET_MODE (cond),
596 XEXP (cond, 0),
597 XEXP (cond, 1));
599 return cond;
602 /* Caching variant of sched_get_condition_with_rev_uncached.
603 We only do actual work the first time we come here for an insn; the
604 results are cached in INSN_CACHED_COND and INSN_REVERSE_COND. */
605 static rtx
606 sched_get_condition_with_rev (const rtx_insn *insn, bool *rev)
608 bool tmp;
610 if (INSN_LUID (insn) == 0)
611 return sched_get_condition_with_rev_uncached (insn, rev);
613 if (INSN_CACHED_COND (insn) == const_true_rtx)
614 return NULL_RTX;
616 if (INSN_CACHED_COND (insn) != NULL_RTX)
618 if (rev)
619 *rev = INSN_REVERSE_COND (insn);
620 return INSN_CACHED_COND (insn);
623 INSN_CACHED_COND (insn) = sched_get_condition_with_rev_uncached (insn, &tmp);
624 INSN_REVERSE_COND (insn) = tmp;
626 if (INSN_CACHED_COND (insn) == NULL_RTX)
628 INSN_CACHED_COND (insn) = const_true_rtx;
629 return NULL_RTX;
632 if (rev)
633 *rev = INSN_REVERSE_COND (insn);
634 return INSN_CACHED_COND (insn);
637 /* True when we can find a condition under which INSN is executed. */
638 static bool
639 sched_has_condition_p (const rtx_insn *insn)
641 return !! sched_get_condition_with_rev (insn, NULL);
646 /* Return nonzero if conditions COND1 and COND2 can never be both true. */
647 static int
648 conditions_mutex_p (const_rtx cond1, const_rtx cond2, bool rev1, bool rev2)
650 if (COMPARISON_P (cond1)
651 && COMPARISON_P (cond2)
652 && GET_CODE (cond1) ==
653 (rev1==rev2
654 ? reversed_comparison_code (cond2, NULL)
655 : GET_CODE (cond2))
656 && rtx_equal_p (XEXP (cond1, 0), XEXP (cond2, 0))
657 && XEXP (cond1, 1) == XEXP (cond2, 1))
658 return 1;
659 return 0;
662 /* Return true if insn1 and insn2 can never depend on one another because
663 the conditions under which they are executed are mutually exclusive. */
664 bool
665 sched_insns_conditions_mutex_p (const rtx_insn *insn1, const rtx_insn *insn2)
667 rtx cond1, cond2;
668 bool rev1 = false, rev2 = false;
670 /* df doesn't handle conditional lifetimes entirely correctly;
671 calls mess up the conditional lifetimes. */
672 if (!CALL_P (insn1) && !CALL_P (insn2))
674 cond1 = sched_get_condition_with_rev (insn1, &rev1);
675 cond2 = sched_get_condition_with_rev (insn2, &rev2);
676 if (cond1 && cond2
677 && conditions_mutex_p (cond1, cond2, rev1, rev2)
678 /* Make sure first instruction doesn't affect condition of second
679 instruction if switched. */
680 && !modified_in_p (cond1, insn2)
681 /* Make sure second instruction doesn't affect condition of first
682 instruction if switched. */
683 && !modified_in_p (cond2, insn1))
684 return true;
686 return false;
690 /* Return true if INSN can potentially be speculated with type DS. */
691 bool
692 sched_insn_is_legitimate_for_speculation_p (const rtx_insn *insn, ds_t ds)
694 if (HAS_INTERNAL_DEP (insn))
695 return false;
697 if (!NONJUMP_INSN_P (insn))
698 return false;
700 if (SCHED_GROUP_P (insn))
701 return false;
703 if (IS_SPECULATION_CHECK_P (CONST_CAST_RTX_INSN (insn)))
704 return false;
706 if (side_effects_p (PATTERN (insn)))
707 return false;
709 if (ds & BE_IN_SPEC)
710 /* The following instructions, which depend on a speculatively scheduled
711 instruction, cannot be speculatively scheduled along. */
713 if (may_trap_or_fault_p (PATTERN (insn)))
714 /* If instruction might fault, it cannot be speculatively scheduled.
715 For control speculation it's obvious why and for data speculation
716 it's because the insn might get wrong input if speculation
717 wasn't successful. */
718 return false;
720 if ((ds & BE_IN_DATA)
721 && sched_has_condition_p (insn))
722 /* If this is a predicated instruction, then it cannot be
723 speculatively scheduled. See PR35659. */
724 return false;
727 return true;
730 /* Initialize LIST_PTR to point to one of the lists present in TYPES_PTR,
731 initialize RESOLVED_P_PTR with true if that list consists of resolved deps,
732 and remove the type of returned [through LIST_PTR] list from TYPES_PTR.
733 This function is used to switch sd_iterator to the next list.
734 !!! For internal use only. Might consider moving it to sched-int.h. */
735 void
736 sd_next_list (const_rtx insn, sd_list_types_def *types_ptr,
737 deps_list_t *list_ptr, bool *resolved_p_ptr)
739 sd_list_types_def types = *types_ptr;
741 if (types & SD_LIST_HARD_BACK)
743 *list_ptr = INSN_HARD_BACK_DEPS (insn);
744 *resolved_p_ptr = false;
745 *types_ptr = types & ~SD_LIST_HARD_BACK;
747 else if (types & SD_LIST_SPEC_BACK)
749 *list_ptr = INSN_SPEC_BACK_DEPS (insn);
750 *resolved_p_ptr = false;
751 *types_ptr = types & ~SD_LIST_SPEC_BACK;
753 else if (types & SD_LIST_FORW)
755 *list_ptr = INSN_FORW_DEPS (insn);
756 *resolved_p_ptr = false;
757 *types_ptr = types & ~SD_LIST_FORW;
759 else if (types & SD_LIST_RES_BACK)
761 *list_ptr = INSN_RESOLVED_BACK_DEPS (insn);
762 *resolved_p_ptr = true;
763 *types_ptr = types & ~SD_LIST_RES_BACK;
765 else if (types & SD_LIST_RES_FORW)
767 *list_ptr = INSN_RESOLVED_FORW_DEPS (insn);
768 *resolved_p_ptr = true;
769 *types_ptr = types & ~SD_LIST_RES_FORW;
771 else
773 *list_ptr = NULL;
774 *resolved_p_ptr = false;
775 *types_ptr = SD_LIST_NONE;
779 /* Return the summary size of INSN's lists defined by LIST_TYPES. */
781 sd_lists_size (const_rtx insn, sd_list_types_def list_types)
783 int size = 0;
785 while (list_types != SD_LIST_NONE)
787 deps_list_t list;
788 bool resolved_p;
790 sd_next_list (insn, &list_types, &list, &resolved_p);
791 if (list)
792 size += DEPS_LIST_N_LINKS (list);
795 return size;
798 /* Return true if INSN's lists defined by LIST_TYPES are all empty. */
800 bool
801 sd_lists_empty_p (const_rtx insn, sd_list_types_def list_types)
803 while (list_types != SD_LIST_NONE)
805 deps_list_t list;
806 bool resolved_p;
808 sd_next_list (insn, &list_types, &list, &resolved_p);
809 if (!deps_list_empty_p (list))
810 return false;
813 return true;
816 /* Initialize data for INSN. */
817 void
818 sd_init_insn (rtx_insn *insn)
820 INSN_HARD_BACK_DEPS (insn) = create_deps_list ();
821 INSN_SPEC_BACK_DEPS (insn) = create_deps_list ();
822 INSN_RESOLVED_BACK_DEPS (insn) = create_deps_list ();
823 INSN_FORW_DEPS (insn) = create_deps_list ();
824 INSN_RESOLVED_FORW_DEPS (insn) = create_deps_list ();
826 /* ??? It would be nice to allocate dependency caches here. */
829 /* Free data for INSN. */
830 void
831 sd_finish_insn (rtx_insn *insn)
833 /* ??? It would be nice to deallocate dependency caches here. */
835 free_deps_list (INSN_HARD_BACK_DEPS (insn));
836 INSN_HARD_BACK_DEPS (insn) = NULL;
838 free_deps_list (INSN_SPEC_BACK_DEPS (insn));
839 INSN_SPEC_BACK_DEPS (insn) = NULL;
841 free_deps_list (INSN_RESOLVED_BACK_DEPS (insn));
842 INSN_RESOLVED_BACK_DEPS (insn) = NULL;
844 free_deps_list (INSN_FORW_DEPS (insn));
845 INSN_FORW_DEPS (insn) = NULL;
847 free_deps_list (INSN_RESOLVED_FORW_DEPS (insn));
848 INSN_RESOLVED_FORW_DEPS (insn) = NULL;
851 /* Find a dependency between producer PRO and consumer CON.
852 Search through resolved dependency lists if RESOLVED_P is true.
853 If no such dependency is found return NULL,
854 otherwise return the dependency and initialize SD_IT_PTR [if it is nonnull]
855 with an iterator pointing to it. */
856 static dep_t
857 sd_find_dep_between_no_cache (rtx pro, rtx con, bool resolved_p,
858 sd_iterator_def *sd_it_ptr)
860 sd_list_types_def pro_list_type;
861 sd_list_types_def con_list_type;
862 sd_iterator_def sd_it;
863 dep_t dep;
864 bool found_p = false;
866 if (resolved_p)
868 pro_list_type = SD_LIST_RES_FORW;
869 con_list_type = SD_LIST_RES_BACK;
871 else
873 pro_list_type = SD_LIST_FORW;
874 con_list_type = SD_LIST_BACK;
877 /* Walk through either back list of INSN or forw list of ELEM
878 depending on which one is shorter. */
879 if (sd_lists_size (con, con_list_type) < sd_lists_size (pro, pro_list_type))
881 /* Find the dep_link with producer PRO in consumer's back_deps. */
882 FOR_EACH_DEP (con, con_list_type, sd_it, dep)
883 if (DEP_PRO (dep) == pro)
885 found_p = true;
886 break;
889 else
891 /* Find the dep_link with consumer CON in producer's forw_deps. */
892 FOR_EACH_DEP (pro, pro_list_type, sd_it, dep)
893 if (DEP_CON (dep) == con)
895 found_p = true;
896 break;
900 if (found_p)
902 if (sd_it_ptr != NULL)
903 *sd_it_ptr = sd_it;
905 return dep;
908 return NULL;
911 /* Find a dependency between producer PRO and consumer CON.
912 Use dependency [if available] to check if dependency is present at all.
913 Search through resolved dependency lists if RESOLVED_P is true.
914 If the dependency or NULL if none found. */
915 dep_t
916 sd_find_dep_between (rtx pro, rtx con, bool resolved_p)
918 if (true_dependency_cache != NULL)
919 /* Avoiding the list walk below can cut compile times dramatically
920 for some code. */
922 int elem_luid = INSN_LUID (pro);
923 int insn_luid = INSN_LUID (con);
925 if (!bitmap_bit_p (&true_dependency_cache[insn_luid], elem_luid)
926 && !bitmap_bit_p (&output_dependency_cache[insn_luid], elem_luid)
927 && !bitmap_bit_p (&anti_dependency_cache[insn_luid], elem_luid)
928 && !bitmap_bit_p (&control_dependency_cache[insn_luid], elem_luid))
929 return NULL;
932 return sd_find_dep_between_no_cache (pro, con, resolved_p, NULL);
935 /* Add or update a dependence described by DEP.
936 MEM1 and MEM2, if non-null, correspond to memory locations in case of
937 data speculation.
939 The function returns a value indicating if an old entry has been changed
940 or a new entry has been added to insn's backward deps.
942 This function merely checks if producer and consumer is the same insn
943 and doesn't create a dep in this case. Actual manipulation of
944 dependence data structures is performed in add_or_update_dep_1. */
945 static enum DEPS_ADJUST_RESULT
946 maybe_add_or_update_dep_1 (dep_t dep, bool resolved_p, rtx mem1, rtx mem2)
948 rtx_insn *elem = DEP_PRO (dep);
949 rtx_insn *insn = DEP_CON (dep);
951 gcc_assert (INSN_P (insn) && INSN_P (elem));
953 /* Don't depend an insn on itself. */
954 if (insn == elem)
956 if (sched_deps_info->generate_spec_deps)
957 /* INSN has an internal dependence, which we can't overcome. */
958 HAS_INTERNAL_DEP (insn) = 1;
960 return DEP_NODEP;
963 return add_or_update_dep_1 (dep, resolved_p, mem1, mem2);
966 /* Ask dependency caches what needs to be done for dependence DEP.
967 Return DEP_CREATED if new dependence should be created and there is no
968 need to try to find one searching the dependencies lists.
969 Return DEP_PRESENT if there already is a dependence described by DEP and
970 hence nothing is to be done.
971 Return DEP_CHANGED if there already is a dependence, but it should be
972 updated to incorporate additional information from DEP. */
973 static enum DEPS_ADJUST_RESULT
974 ask_dependency_caches (dep_t dep)
976 int elem_luid = INSN_LUID (DEP_PRO (dep));
977 int insn_luid = INSN_LUID (DEP_CON (dep));
979 gcc_assert (true_dependency_cache != NULL
980 && output_dependency_cache != NULL
981 && anti_dependency_cache != NULL
982 && control_dependency_cache != NULL);
984 if (!(current_sched_info->flags & USE_DEPS_LIST))
986 enum reg_note present_dep_type;
988 if (bitmap_bit_p (&true_dependency_cache[insn_luid], elem_luid))
989 present_dep_type = REG_DEP_TRUE;
990 else if (bitmap_bit_p (&output_dependency_cache[insn_luid], elem_luid))
991 present_dep_type = REG_DEP_OUTPUT;
992 else if (bitmap_bit_p (&anti_dependency_cache[insn_luid], elem_luid))
993 present_dep_type = REG_DEP_ANTI;
994 else if (bitmap_bit_p (&control_dependency_cache[insn_luid], elem_luid))
995 present_dep_type = REG_DEP_CONTROL;
996 else
997 /* There is no existing dep so it should be created. */
998 return DEP_CREATED;
1000 if ((int) DEP_TYPE (dep) >= (int) present_dep_type)
1001 /* DEP does not add anything to the existing dependence. */
1002 return DEP_PRESENT;
1004 else
1006 ds_t present_dep_types = 0;
1008 if (bitmap_bit_p (&true_dependency_cache[insn_luid], elem_luid))
1009 present_dep_types |= DEP_TRUE;
1010 if (bitmap_bit_p (&output_dependency_cache[insn_luid], elem_luid))
1011 present_dep_types |= DEP_OUTPUT;
1012 if (bitmap_bit_p (&anti_dependency_cache[insn_luid], elem_luid))
1013 present_dep_types |= DEP_ANTI;
1014 if (bitmap_bit_p (&control_dependency_cache[insn_luid], elem_luid))
1015 present_dep_types |= DEP_CONTROL;
1017 if (present_dep_types == 0)
1018 /* There is no existing dep so it should be created. */
1019 return DEP_CREATED;
1021 if (!(current_sched_info->flags & DO_SPECULATION)
1022 || !bitmap_bit_p (&spec_dependency_cache[insn_luid], elem_luid))
1024 if ((present_dep_types | (DEP_STATUS (dep) & DEP_TYPES))
1025 == present_dep_types)
1026 /* DEP does not add anything to the existing dependence. */
1027 return DEP_PRESENT;
1029 else
1031 /* Only true dependencies can be data speculative and
1032 only anti dependencies can be control speculative. */
1033 gcc_assert ((present_dep_types & (DEP_TRUE | DEP_ANTI))
1034 == present_dep_types);
1036 /* if (DEP is SPECULATIVE) then
1037 ..we should update DEP_STATUS
1038 else
1039 ..we should reset existing dep to non-speculative. */
1043 return DEP_CHANGED;
1046 /* Set dependency caches according to DEP. */
1047 static void
1048 set_dependency_caches (dep_t dep)
1050 int elem_luid = INSN_LUID (DEP_PRO (dep));
1051 int insn_luid = INSN_LUID (DEP_CON (dep));
1053 if (!(current_sched_info->flags & USE_DEPS_LIST))
1055 switch (DEP_TYPE (dep))
1057 case REG_DEP_TRUE:
1058 bitmap_set_bit (&true_dependency_cache[insn_luid], elem_luid);
1059 break;
1061 case REG_DEP_OUTPUT:
1062 bitmap_set_bit (&output_dependency_cache[insn_luid], elem_luid);
1063 break;
1065 case REG_DEP_ANTI:
1066 bitmap_set_bit (&anti_dependency_cache[insn_luid], elem_luid);
1067 break;
1069 case REG_DEP_CONTROL:
1070 bitmap_set_bit (&control_dependency_cache[insn_luid], elem_luid);
1071 break;
1073 default:
1074 gcc_unreachable ();
1077 else
1079 ds_t ds = DEP_STATUS (dep);
1081 if (ds & DEP_TRUE)
1082 bitmap_set_bit (&true_dependency_cache[insn_luid], elem_luid);
1083 if (ds & DEP_OUTPUT)
1084 bitmap_set_bit (&output_dependency_cache[insn_luid], elem_luid);
1085 if (ds & DEP_ANTI)
1086 bitmap_set_bit (&anti_dependency_cache[insn_luid], elem_luid);
1087 if (ds & DEP_CONTROL)
1088 bitmap_set_bit (&control_dependency_cache[insn_luid], elem_luid);
1090 if (ds & SPECULATIVE)
1092 gcc_assert (current_sched_info->flags & DO_SPECULATION);
1093 bitmap_set_bit (&spec_dependency_cache[insn_luid], elem_luid);
1098 /* Type of dependence DEP have changed from OLD_TYPE. Update dependency
1099 caches accordingly. */
1100 static void
1101 update_dependency_caches (dep_t dep, enum reg_note old_type)
1103 int elem_luid = INSN_LUID (DEP_PRO (dep));
1104 int insn_luid = INSN_LUID (DEP_CON (dep));
1106 /* Clear corresponding cache entry because type of the link
1107 may have changed. Keep them if we use_deps_list. */
1108 if (!(current_sched_info->flags & USE_DEPS_LIST))
1110 switch (old_type)
1112 case REG_DEP_OUTPUT:
1113 bitmap_clear_bit (&output_dependency_cache[insn_luid], elem_luid);
1114 break;
1116 case REG_DEP_ANTI:
1117 bitmap_clear_bit (&anti_dependency_cache[insn_luid], elem_luid);
1118 break;
1120 case REG_DEP_CONTROL:
1121 bitmap_clear_bit (&control_dependency_cache[insn_luid], elem_luid);
1122 break;
1124 default:
1125 gcc_unreachable ();
1129 set_dependency_caches (dep);
1132 /* Convert a dependence pointed to by SD_IT to be non-speculative. */
1133 static void
1134 change_spec_dep_to_hard (sd_iterator_def sd_it)
1136 dep_node_t node = DEP_LINK_NODE (*sd_it.linkp);
1137 dep_link_t link = DEP_NODE_BACK (node);
1138 dep_t dep = DEP_NODE_DEP (node);
1139 rtx_insn *elem = DEP_PRO (dep);
1140 rtx_insn *insn = DEP_CON (dep);
1142 move_dep_link (link, INSN_SPEC_BACK_DEPS (insn), INSN_HARD_BACK_DEPS (insn));
1144 DEP_STATUS (dep) &= ~SPECULATIVE;
1146 if (true_dependency_cache != NULL)
1147 /* Clear the cache entry. */
1148 bitmap_clear_bit (&spec_dependency_cache[INSN_LUID (insn)],
1149 INSN_LUID (elem));
1152 /* Update DEP to incorporate information from NEW_DEP.
1153 SD_IT points to DEP in case it should be moved to another list.
1154 MEM1 and MEM2, if nonnull, correspond to memory locations in case if
1155 data-speculative dependence should be updated. */
1156 static enum DEPS_ADJUST_RESULT
1157 update_dep (dep_t dep, dep_t new_dep,
1158 sd_iterator_def sd_it ATTRIBUTE_UNUSED,
1159 rtx mem1 ATTRIBUTE_UNUSED,
1160 rtx mem2 ATTRIBUTE_UNUSED)
1162 enum DEPS_ADJUST_RESULT res = DEP_PRESENT;
1163 enum reg_note old_type = DEP_TYPE (dep);
1164 bool was_spec = dep_spec_p (dep);
1166 DEP_NONREG (dep) |= DEP_NONREG (new_dep);
1167 DEP_MULTIPLE (dep) = 1;
1169 /* If this is a more restrictive type of dependence than the
1170 existing one, then change the existing dependence to this
1171 type. */
1172 if ((int) DEP_TYPE (new_dep) < (int) old_type)
1174 DEP_TYPE (dep) = DEP_TYPE (new_dep);
1175 res = DEP_CHANGED;
1178 if (current_sched_info->flags & USE_DEPS_LIST)
1179 /* Update DEP_STATUS. */
1181 ds_t dep_status = DEP_STATUS (dep);
1182 ds_t ds = DEP_STATUS (new_dep);
1183 ds_t new_status = ds | dep_status;
1185 if (new_status & SPECULATIVE)
1187 /* Either existing dep or a dep we're adding or both are
1188 speculative. */
1189 if (!(ds & SPECULATIVE)
1190 || !(dep_status & SPECULATIVE))
1191 /* The new dep can't be speculative. */
1192 new_status &= ~SPECULATIVE;
1193 else
1195 /* Both are speculative. Merge probabilities. */
1196 if (mem1 != NULL)
1198 dw_t dw;
1200 dw = estimate_dep_weak (mem1, mem2);
1201 ds = set_dep_weak (ds, BEGIN_DATA, dw);
1204 new_status = ds_merge (dep_status, ds);
1208 ds = new_status;
1210 if (dep_status != ds)
1212 DEP_STATUS (dep) = ds;
1213 res = DEP_CHANGED;
1217 if (was_spec && !dep_spec_p (dep))
1218 /* The old dep was speculative, but now it isn't. */
1219 change_spec_dep_to_hard (sd_it);
1221 if (true_dependency_cache != NULL
1222 && res == DEP_CHANGED)
1223 update_dependency_caches (dep, old_type);
1225 return res;
1228 /* Add or update a dependence described by DEP.
1229 MEM1 and MEM2, if non-null, correspond to memory locations in case of
1230 data speculation.
1232 The function returns a value indicating if an old entry has been changed
1233 or a new entry has been added to insn's backward deps or nothing has
1234 been updated at all. */
1235 static enum DEPS_ADJUST_RESULT
1236 add_or_update_dep_1 (dep_t new_dep, bool resolved_p,
1237 rtx mem1 ATTRIBUTE_UNUSED, rtx mem2 ATTRIBUTE_UNUSED)
1239 bool maybe_present_p = true;
1240 bool present_p = false;
1242 gcc_assert (INSN_P (DEP_PRO (new_dep)) && INSN_P (DEP_CON (new_dep))
1243 && DEP_PRO (new_dep) != DEP_CON (new_dep));
1245 #ifdef ENABLE_CHECKING
1246 check_dep (new_dep, mem1 != NULL);
1247 #endif
1249 if (true_dependency_cache != NULL)
1251 switch (ask_dependency_caches (new_dep))
1253 case DEP_PRESENT:
1254 dep_t present_dep;
1255 sd_iterator_def sd_it;
1257 present_dep = sd_find_dep_between_no_cache (DEP_PRO (new_dep),
1258 DEP_CON (new_dep),
1259 resolved_p, &sd_it);
1260 DEP_MULTIPLE (present_dep) = 1;
1261 return DEP_PRESENT;
1263 case DEP_CHANGED:
1264 maybe_present_p = true;
1265 present_p = true;
1266 break;
1268 case DEP_CREATED:
1269 maybe_present_p = false;
1270 present_p = false;
1271 break;
1273 default:
1274 gcc_unreachable ();
1275 break;
1279 /* Check that we don't already have this dependence. */
1280 if (maybe_present_p)
1282 dep_t present_dep;
1283 sd_iterator_def sd_it;
1285 gcc_assert (true_dependency_cache == NULL || present_p);
1287 present_dep = sd_find_dep_between_no_cache (DEP_PRO (new_dep),
1288 DEP_CON (new_dep),
1289 resolved_p, &sd_it);
1291 if (present_dep != NULL)
1292 /* We found an existing dependency between ELEM and INSN. */
1293 return update_dep (present_dep, new_dep, sd_it, mem1, mem2);
1294 else
1295 /* We didn't find a dep, it shouldn't present in the cache. */
1296 gcc_assert (!present_p);
1299 /* Might want to check one level of transitivity to save conses.
1300 This check should be done in maybe_add_or_update_dep_1.
1301 Since we made it to add_or_update_dep_1, we must create
1302 (or update) a link. */
1304 if (mem1 != NULL_RTX)
1306 gcc_assert (sched_deps_info->generate_spec_deps);
1307 DEP_STATUS (new_dep) = set_dep_weak (DEP_STATUS (new_dep), BEGIN_DATA,
1308 estimate_dep_weak (mem1, mem2));
1311 sd_add_dep (new_dep, resolved_p);
1313 return DEP_CREATED;
1316 /* Initialize BACK_LIST_PTR with consumer's backward list and
1317 FORW_LIST_PTR with producer's forward list. If RESOLVED_P is true
1318 initialize with lists that hold resolved deps. */
1319 static void
1320 get_back_and_forw_lists (dep_t dep, bool resolved_p,
1321 deps_list_t *back_list_ptr,
1322 deps_list_t *forw_list_ptr)
1324 rtx_insn *con = DEP_CON (dep);
1326 if (!resolved_p)
1328 if (dep_spec_p (dep))
1329 *back_list_ptr = INSN_SPEC_BACK_DEPS (con);
1330 else
1331 *back_list_ptr = INSN_HARD_BACK_DEPS (con);
1333 *forw_list_ptr = INSN_FORW_DEPS (DEP_PRO (dep));
1335 else
1337 *back_list_ptr = INSN_RESOLVED_BACK_DEPS (con);
1338 *forw_list_ptr = INSN_RESOLVED_FORW_DEPS (DEP_PRO (dep));
1342 /* Add dependence described by DEP.
1343 If RESOLVED_P is true treat the dependence as a resolved one. */
1344 void
1345 sd_add_dep (dep_t dep, bool resolved_p)
1347 dep_node_t n = create_dep_node ();
1348 deps_list_t con_back_deps;
1349 deps_list_t pro_forw_deps;
1350 rtx_insn *elem = DEP_PRO (dep);
1351 rtx_insn *insn = DEP_CON (dep);
1353 gcc_assert (INSN_P (insn) && INSN_P (elem) && insn != elem);
1355 if ((current_sched_info->flags & DO_SPECULATION) == 0
1356 || !sched_insn_is_legitimate_for_speculation_p (insn, DEP_STATUS (dep)))
1357 DEP_STATUS (dep) &= ~SPECULATIVE;
1359 copy_dep (DEP_NODE_DEP (n), dep);
1361 get_back_and_forw_lists (dep, resolved_p, &con_back_deps, &pro_forw_deps);
1363 add_to_deps_list (DEP_NODE_BACK (n), con_back_deps);
1365 #ifdef ENABLE_CHECKING
1366 check_dep (dep, false);
1367 #endif
1369 add_to_deps_list (DEP_NODE_FORW (n), pro_forw_deps);
1371 /* If we are adding a dependency to INSN's LOG_LINKs, then note that
1372 in the bitmap caches of dependency information. */
1373 if (true_dependency_cache != NULL)
1374 set_dependency_caches (dep);
1377 /* Add or update backward dependence between INSN and ELEM
1378 with given type DEP_TYPE and dep_status DS.
1379 This function is a convenience wrapper. */
1380 enum DEPS_ADJUST_RESULT
1381 sd_add_or_update_dep (dep_t dep, bool resolved_p)
1383 return add_or_update_dep_1 (dep, resolved_p, NULL_RTX, NULL_RTX);
1386 /* Resolved dependence pointed to by SD_IT.
1387 SD_IT will advance to the next element. */
1388 void
1389 sd_resolve_dep (sd_iterator_def sd_it)
1391 dep_node_t node = DEP_LINK_NODE (*sd_it.linkp);
1392 dep_t dep = DEP_NODE_DEP (node);
1393 rtx_insn *pro = DEP_PRO (dep);
1394 rtx_insn *con = DEP_CON (dep);
1396 if (dep_spec_p (dep))
1397 move_dep_link (DEP_NODE_BACK (node), INSN_SPEC_BACK_DEPS (con),
1398 INSN_RESOLVED_BACK_DEPS (con));
1399 else
1400 move_dep_link (DEP_NODE_BACK (node), INSN_HARD_BACK_DEPS (con),
1401 INSN_RESOLVED_BACK_DEPS (con));
1403 move_dep_link (DEP_NODE_FORW (node), INSN_FORW_DEPS (pro),
1404 INSN_RESOLVED_FORW_DEPS (pro));
1407 /* Perform the inverse operation of sd_resolve_dep. Restore the dependence
1408 pointed to by SD_IT to unresolved state. */
1409 void
1410 sd_unresolve_dep (sd_iterator_def sd_it)
1412 dep_node_t node = DEP_LINK_NODE (*sd_it.linkp);
1413 dep_t dep = DEP_NODE_DEP (node);
1414 rtx_insn *pro = DEP_PRO (dep);
1415 rtx_insn *con = DEP_CON (dep);
1417 if (dep_spec_p (dep))
1418 move_dep_link (DEP_NODE_BACK (node), INSN_RESOLVED_BACK_DEPS (con),
1419 INSN_SPEC_BACK_DEPS (con));
1420 else
1421 move_dep_link (DEP_NODE_BACK (node), INSN_RESOLVED_BACK_DEPS (con),
1422 INSN_HARD_BACK_DEPS (con));
1424 move_dep_link (DEP_NODE_FORW (node), INSN_RESOLVED_FORW_DEPS (pro),
1425 INSN_FORW_DEPS (pro));
1428 /* Make TO depend on all the FROM's producers.
1429 If RESOLVED_P is true add dependencies to the resolved lists. */
1430 void
1431 sd_copy_back_deps (rtx_insn *to, rtx_insn *from, bool resolved_p)
1433 sd_list_types_def list_type;
1434 sd_iterator_def sd_it;
1435 dep_t dep;
1437 list_type = resolved_p ? SD_LIST_RES_BACK : SD_LIST_BACK;
1439 FOR_EACH_DEP (from, list_type, sd_it, dep)
1441 dep_def _new_dep, *new_dep = &_new_dep;
1443 copy_dep (new_dep, dep);
1444 DEP_CON (new_dep) = to;
1445 sd_add_dep (new_dep, resolved_p);
1449 /* Remove a dependency referred to by SD_IT.
1450 SD_IT will point to the next dependence after removal. */
1451 void
1452 sd_delete_dep (sd_iterator_def sd_it)
1454 dep_node_t n = DEP_LINK_NODE (*sd_it.linkp);
1455 dep_t dep = DEP_NODE_DEP (n);
1456 rtx_insn *pro = DEP_PRO (dep);
1457 rtx_insn *con = DEP_CON (dep);
1458 deps_list_t con_back_deps;
1459 deps_list_t pro_forw_deps;
1461 if (true_dependency_cache != NULL)
1463 int elem_luid = INSN_LUID (pro);
1464 int insn_luid = INSN_LUID (con);
1466 bitmap_clear_bit (&true_dependency_cache[insn_luid], elem_luid);
1467 bitmap_clear_bit (&anti_dependency_cache[insn_luid], elem_luid);
1468 bitmap_clear_bit (&control_dependency_cache[insn_luid], elem_luid);
1469 bitmap_clear_bit (&output_dependency_cache[insn_luid], elem_luid);
1471 if (current_sched_info->flags & DO_SPECULATION)
1472 bitmap_clear_bit (&spec_dependency_cache[insn_luid], elem_luid);
1475 get_back_and_forw_lists (dep, sd_it.resolved_p,
1476 &con_back_deps, &pro_forw_deps);
1478 remove_from_deps_list (DEP_NODE_BACK (n), con_back_deps);
1479 remove_from_deps_list (DEP_NODE_FORW (n), pro_forw_deps);
1481 delete_dep_node (n);
1484 /* Dump size of the lists. */
1485 #define DUMP_LISTS_SIZE (2)
1487 /* Dump dependencies of the lists. */
1488 #define DUMP_LISTS_DEPS (4)
1490 /* Dump all information about the lists. */
1491 #define DUMP_LISTS_ALL (DUMP_LISTS_SIZE | DUMP_LISTS_DEPS)
1493 /* Dump deps_lists of INSN specified by TYPES to DUMP.
1494 FLAGS is a bit mask specifying what information about the lists needs
1495 to be printed.
1496 If FLAGS has the very first bit set, then dump all information about
1497 the lists and propagate this bit into the callee dump functions. */
1498 static void
1499 dump_lists (FILE *dump, rtx insn, sd_list_types_def types, int flags)
1501 sd_iterator_def sd_it;
1502 dep_t dep;
1503 int all;
1505 all = (flags & 1);
1507 if (all)
1508 flags |= DUMP_LISTS_ALL;
1510 fprintf (dump, "[");
1512 if (flags & DUMP_LISTS_SIZE)
1513 fprintf (dump, "%d; ", sd_lists_size (insn, types));
1515 if (flags & DUMP_LISTS_DEPS)
1517 FOR_EACH_DEP (insn, types, sd_it, dep)
1519 dump_dep (dump, dep, dump_dep_flags | all);
1520 fprintf (dump, " ");
1525 /* Dump all information about deps_lists of INSN specified by TYPES
1526 to STDERR. */
1527 void
1528 sd_debug_lists (rtx insn, sd_list_types_def types)
1530 dump_lists (stderr, insn, types, 1);
1531 fprintf (stderr, "\n");
1534 /* A wrapper around add_dependence_1, to add a dependence of CON on
1535 PRO, with type DEP_TYPE. This function implements special handling
1536 for REG_DEP_CONTROL dependencies. For these, we optionally promote
1537 the type to REG_DEP_ANTI if we can determine that predication is
1538 impossible; otherwise we add additional true dependencies on the
1539 INSN_COND_DEPS list of the jump (which PRO must be). */
1540 void
1541 add_dependence (rtx_insn *con, rtx_insn *pro, enum reg_note dep_type)
1543 if (dep_type == REG_DEP_CONTROL
1544 && !(current_sched_info->flags & DO_PREDICATION))
1545 dep_type = REG_DEP_ANTI;
1547 /* A REG_DEP_CONTROL dependence may be eliminated through predication,
1548 so we must also make the insn dependent on the setter of the
1549 condition. */
1550 if (dep_type == REG_DEP_CONTROL)
1552 rtx_insn *real_pro = pro;
1553 rtx_insn *other = real_insn_for_shadow (real_pro);
1554 rtx cond;
1556 if (other != NULL_RTX)
1557 real_pro = other;
1558 cond = sched_get_reverse_condition_uncached (real_pro);
1559 /* Verify that the insn does not use a different value in
1560 the condition register than the one that was present at
1561 the jump. */
1562 if (cond == NULL_RTX)
1563 dep_type = REG_DEP_ANTI;
1564 else if (INSN_CACHED_COND (real_pro) == const_true_rtx)
1566 HARD_REG_SET uses;
1567 CLEAR_HARD_REG_SET (uses);
1568 note_uses (&PATTERN (con), record_hard_reg_uses, &uses);
1569 if (TEST_HARD_REG_BIT (uses, REGNO (XEXP (cond, 0))))
1570 dep_type = REG_DEP_ANTI;
1572 if (dep_type == REG_DEP_CONTROL)
1574 if (sched_verbose >= 5)
1575 fprintf (sched_dump, "making DEP_CONTROL for %d\n",
1576 INSN_UID (real_pro));
1577 add_dependence_list (con, INSN_COND_DEPS (real_pro), 0,
1578 REG_DEP_TRUE, false);
1582 add_dependence_1 (con, pro, dep_type);
1585 /* A convenience wrapper to operate on an entire list. HARD should be
1586 true if DEP_NONREG should be set on newly created dependencies. */
1588 static void
1589 add_dependence_list (rtx_insn *insn, rtx_insn_list *list, int uncond,
1590 enum reg_note dep_type, bool hard)
1592 mark_as_hard = hard;
1593 for (; list; list = list->next ())
1595 if (uncond || ! sched_insns_conditions_mutex_p (insn, list->insn ()))
1596 add_dependence (insn, list->insn (), dep_type);
1598 mark_as_hard = false;
1601 /* Similar, but free *LISTP at the same time, when the context
1602 is not readonly. HARD should be true if DEP_NONREG should be set on
1603 newly created dependencies. */
1605 static void
1606 add_dependence_list_and_free (struct deps_desc *deps, rtx_insn *insn,
1607 rtx_insn_list **listp,
1608 int uncond, enum reg_note dep_type, bool hard)
1610 add_dependence_list (insn, *listp, uncond, dep_type, hard);
1612 /* We don't want to short-circuit dependencies involving debug
1613 insns, because they may cause actual dependencies to be
1614 disregarded. */
1615 if (deps->readonly || DEBUG_INSN_P (insn))
1616 return;
1618 free_INSN_LIST_list (listp);
1621 /* Remove all occurrences of INSN from LIST. Return the number of
1622 occurrences removed. */
1624 static int
1625 remove_from_dependence_list (rtx_insn *insn, rtx_insn_list **listp)
1627 int removed = 0;
1629 while (*listp)
1631 if ((*listp)->insn () == insn)
1633 remove_free_INSN_LIST_node (listp);
1634 removed++;
1635 continue;
1638 listp = (rtx_insn_list **)&XEXP (*listp, 1);
1641 return removed;
1644 /* Same as above, but process two lists at once. */
1645 static int
1646 remove_from_both_dependence_lists (rtx_insn *insn,
1647 rtx_insn_list **listp,
1648 rtx_expr_list **exprp)
1650 int removed = 0;
1652 while (*listp)
1654 if (XEXP (*listp, 0) == insn)
1656 remove_free_INSN_LIST_node (listp);
1657 remove_free_EXPR_LIST_node (exprp);
1658 removed++;
1659 continue;
1662 listp = (rtx_insn_list **)&XEXP (*listp, 1);
1663 exprp = (rtx_expr_list **)&XEXP (*exprp, 1);
1666 return removed;
1669 /* Clear all dependencies for an insn. */
1670 static void
1671 delete_all_dependences (rtx_insn *insn)
1673 sd_iterator_def sd_it;
1674 dep_t dep;
1676 /* The below cycle can be optimized to clear the caches and back_deps
1677 in one call but that would provoke duplication of code from
1678 delete_dep (). */
1680 for (sd_it = sd_iterator_start (insn, SD_LIST_BACK);
1681 sd_iterator_cond (&sd_it, &dep);)
1682 sd_delete_dep (sd_it);
1685 /* All insns in a scheduling group except the first should only have
1686 dependencies on the previous insn in the group. So we find the
1687 first instruction in the scheduling group by walking the dependence
1688 chains backwards. Then we add the dependencies for the group to
1689 the previous nonnote insn. */
1691 static void
1692 chain_to_prev_insn (rtx_insn *insn)
1694 sd_iterator_def sd_it;
1695 dep_t dep;
1696 rtx_insn *prev_nonnote;
1698 FOR_EACH_DEP (insn, SD_LIST_BACK, sd_it, dep)
1700 rtx_insn *i = insn;
1701 rtx_insn *pro = DEP_PRO (dep);
1705 i = prev_nonnote_insn (i);
1707 if (pro == i)
1708 goto next_link;
1709 } while (SCHED_GROUP_P (i) || DEBUG_INSN_P (i));
1711 if (! sched_insns_conditions_mutex_p (i, pro))
1712 add_dependence (i, pro, DEP_TYPE (dep));
1713 next_link:;
1716 delete_all_dependences (insn);
1718 prev_nonnote = prev_nonnote_nondebug_insn (insn);
1719 if (BLOCK_FOR_INSN (insn) == BLOCK_FOR_INSN (prev_nonnote)
1720 && ! sched_insns_conditions_mutex_p (insn, prev_nonnote))
1721 add_dependence (insn, prev_nonnote, REG_DEP_ANTI);
1724 /* Process an insn's memory dependencies. There are four kinds of
1725 dependencies:
1727 (0) read dependence: read follows read
1728 (1) true dependence: read follows write
1729 (2) output dependence: write follows write
1730 (3) anti dependence: write follows read
1732 We are careful to build only dependencies which actually exist, and
1733 use transitivity to avoid building too many links. */
1735 /* Add an INSN and MEM reference pair to a pending INSN_LIST and MEM_LIST.
1736 The MEM is a memory reference contained within INSN, which we are saving
1737 so that we can do memory aliasing on it. */
1739 static void
1740 add_insn_mem_dependence (struct deps_desc *deps, bool read_p,
1741 rtx_insn *insn, rtx mem)
1743 rtx_insn_list **insn_list;
1744 rtx_insn_list *insn_node;
1745 rtx_expr_list **mem_list;
1746 rtx_expr_list *mem_node;
1748 gcc_assert (!deps->readonly);
1749 if (read_p)
1751 insn_list = &deps->pending_read_insns;
1752 mem_list = &deps->pending_read_mems;
1753 if (!DEBUG_INSN_P (insn))
1754 deps->pending_read_list_length++;
1756 else
1758 insn_list = &deps->pending_write_insns;
1759 mem_list = &deps->pending_write_mems;
1760 deps->pending_write_list_length++;
1763 insn_node = alloc_INSN_LIST (insn, *insn_list);
1764 *insn_list = insn_node;
1766 if (sched_deps_info->use_cselib)
1768 mem = shallow_copy_rtx (mem);
1769 XEXP (mem, 0) = cselib_subst_to_values_from_insn (XEXP (mem, 0),
1770 GET_MODE (mem), insn);
1772 mem_node = alloc_EXPR_LIST (VOIDmode, canon_rtx (mem), *mem_list);
1773 *mem_list = mem_node;
1776 /* Make a dependency between every memory reference on the pending lists
1777 and INSN, thus flushing the pending lists. FOR_READ is true if emitting
1778 dependencies for a read operation, similarly with FOR_WRITE. */
1780 static void
1781 flush_pending_lists (struct deps_desc *deps, rtx_insn *insn, int for_read,
1782 int for_write)
1784 if (for_write)
1786 add_dependence_list_and_free (deps, insn, &deps->pending_read_insns,
1787 1, REG_DEP_ANTI, true);
1788 if (!deps->readonly)
1790 free_EXPR_LIST_list (&deps->pending_read_mems);
1791 deps->pending_read_list_length = 0;
1795 add_dependence_list_and_free (deps, insn, &deps->pending_write_insns, 1,
1796 for_read ? REG_DEP_ANTI : REG_DEP_OUTPUT,
1797 true);
1799 add_dependence_list_and_free (deps, insn,
1800 &deps->last_pending_memory_flush, 1,
1801 for_read ? REG_DEP_ANTI : REG_DEP_OUTPUT,
1802 true);
1804 add_dependence_list_and_free (deps, insn, &deps->pending_jump_insns, 1,
1805 REG_DEP_ANTI, true);
1807 if (DEBUG_INSN_P (insn))
1809 if (for_write)
1810 free_INSN_LIST_list (&deps->pending_read_insns);
1811 free_INSN_LIST_list (&deps->pending_write_insns);
1812 free_INSN_LIST_list (&deps->last_pending_memory_flush);
1813 free_INSN_LIST_list (&deps->pending_jump_insns);
1816 if (!deps->readonly)
1818 free_EXPR_LIST_list (&deps->pending_write_mems);
1819 deps->pending_write_list_length = 0;
1821 deps->last_pending_memory_flush = alloc_INSN_LIST (insn, NULL_RTX);
1822 deps->pending_flush_length = 1;
1824 mark_as_hard = false;
1827 /* Instruction which dependencies we are analyzing. */
1828 static rtx_insn *cur_insn = NULL;
1830 /* Implement hooks for haifa scheduler. */
1832 static void
1833 haifa_start_insn (rtx_insn *insn)
1835 gcc_assert (insn && !cur_insn);
1837 cur_insn = insn;
1840 static void
1841 haifa_finish_insn (void)
1843 cur_insn = NULL;
1846 void
1847 haifa_note_reg_set (int regno)
1849 SET_REGNO_REG_SET (reg_pending_sets, regno);
1852 void
1853 haifa_note_reg_clobber (int regno)
1855 SET_REGNO_REG_SET (reg_pending_clobbers, regno);
1858 void
1859 haifa_note_reg_use (int regno)
1861 SET_REGNO_REG_SET (reg_pending_uses, regno);
1864 static void
1865 haifa_note_mem_dep (rtx mem, rtx pending_mem, rtx_insn *pending_insn, ds_t ds)
1867 if (!(ds & SPECULATIVE))
1869 mem = NULL_RTX;
1870 pending_mem = NULL_RTX;
1872 else
1873 gcc_assert (ds & BEGIN_DATA);
1876 dep_def _dep, *dep = &_dep;
1878 init_dep_1 (dep, pending_insn, cur_insn, ds_to_dt (ds),
1879 current_sched_info->flags & USE_DEPS_LIST ? ds : 0);
1880 DEP_NONREG (dep) = 1;
1881 maybe_add_or_update_dep_1 (dep, false, pending_mem, mem);
1886 static void
1887 haifa_note_dep (rtx_insn *elem, ds_t ds)
1889 dep_def _dep;
1890 dep_t dep = &_dep;
1892 init_dep (dep, elem, cur_insn, ds_to_dt (ds));
1893 if (mark_as_hard)
1894 DEP_NONREG (dep) = 1;
1895 maybe_add_or_update_dep_1 (dep, false, NULL_RTX, NULL_RTX);
1898 static void
1899 note_reg_use (int r)
1901 if (sched_deps_info->note_reg_use)
1902 sched_deps_info->note_reg_use (r);
1905 static void
1906 note_reg_set (int r)
1908 if (sched_deps_info->note_reg_set)
1909 sched_deps_info->note_reg_set (r);
1912 static void
1913 note_reg_clobber (int r)
1915 if (sched_deps_info->note_reg_clobber)
1916 sched_deps_info->note_reg_clobber (r);
1919 static void
1920 note_mem_dep (rtx m1, rtx m2, rtx_insn *e, ds_t ds)
1922 if (sched_deps_info->note_mem_dep)
1923 sched_deps_info->note_mem_dep (m1, m2, e, ds);
1926 static void
1927 note_dep (rtx_insn *e, ds_t ds)
1929 if (sched_deps_info->note_dep)
1930 sched_deps_info->note_dep (e, ds);
1933 /* Return corresponding to DS reg_note. */
1934 enum reg_note
1935 ds_to_dt (ds_t ds)
1937 if (ds & DEP_TRUE)
1938 return REG_DEP_TRUE;
1939 else if (ds & DEP_OUTPUT)
1940 return REG_DEP_OUTPUT;
1941 else if (ds & DEP_ANTI)
1942 return REG_DEP_ANTI;
1943 else
1945 gcc_assert (ds & DEP_CONTROL);
1946 return REG_DEP_CONTROL;
1952 /* Functions for computation of info needed for register pressure
1953 sensitive insn scheduling. */
1956 /* Allocate and return reg_use_data structure for REGNO and INSN. */
1957 static struct reg_use_data *
1958 create_insn_reg_use (int regno, rtx_insn *insn)
1960 struct reg_use_data *use;
1962 use = (struct reg_use_data *) xmalloc (sizeof (struct reg_use_data));
1963 use->regno = regno;
1964 use->insn = insn;
1965 use->next_insn_use = INSN_REG_USE_LIST (insn);
1966 INSN_REG_USE_LIST (insn) = use;
1967 return use;
1970 /* Allocate reg_set_data structure for REGNO and INSN. */
1971 static void
1972 create_insn_reg_set (int regno, rtx insn)
1974 struct reg_set_data *set;
1976 set = (struct reg_set_data *) xmalloc (sizeof (struct reg_set_data));
1977 set->regno = regno;
1978 set->insn = insn;
1979 set->next_insn_set = INSN_REG_SET_LIST (insn);
1980 INSN_REG_SET_LIST (insn) = set;
1983 /* Set up insn register uses for INSN and dependency context DEPS. */
1984 static void
1985 setup_insn_reg_uses (struct deps_desc *deps, rtx_insn *insn)
1987 unsigned i;
1988 reg_set_iterator rsi;
1989 struct reg_use_data *use, *use2, *next;
1990 struct deps_reg *reg_last;
1992 EXECUTE_IF_SET_IN_REG_SET (reg_pending_uses, 0, i, rsi)
1994 if (i < FIRST_PSEUDO_REGISTER
1995 && TEST_HARD_REG_BIT (ira_no_alloc_regs, i))
1996 continue;
1998 if (find_regno_note (insn, REG_DEAD, i) == NULL_RTX
1999 && ! REGNO_REG_SET_P (reg_pending_sets, i)
2000 && ! REGNO_REG_SET_P (reg_pending_clobbers, i))
2001 /* Ignore use which is not dying. */
2002 continue;
2004 use = create_insn_reg_use (i, insn);
2005 use->next_regno_use = use;
2006 reg_last = &deps->reg_last[i];
2008 /* Create the cycle list of uses. */
2009 for (rtx_insn_list *list = reg_last->uses; list; list = list->next ())
2011 use2 = create_insn_reg_use (i, list->insn ());
2012 next = use->next_regno_use;
2013 use->next_regno_use = use2;
2014 use2->next_regno_use = next;
2019 /* Register pressure info for the currently processed insn. */
2020 static struct reg_pressure_data reg_pressure_info[N_REG_CLASSES];
2022 /* Return TRUE if INSN has the use structure for REGNO. */
2023 static bool
2024 insn_use_p (rtx insn, int regno)
2026 struct reg_use_data *use;
2028 for (use = INSN_REG_USE_LIST (insn); use != NULL; use = use->next_insn_use)
2029 if (use->regno == regno)
2030 return true;
2031 return false;
2034 /* Update the register pressure info after birth of pseudo register REGNO
2035 in INSN. Arguments CLOBBER_P and UNUSED_P say correspondingly that
2036 the register is in clobber or unused after the insn. */
2037 static void
2038 mark_insn_pseudo_birth (rtx insn, int regno, bool clobber_p, bool unused_p)
2040 int incr, new_incr;
2041 enum reg_class cl;
2043 gcc_assert (regno >= FIRST_PSEUDO_REGISTER);
2044 cl = sched_regno_pressure_class[regno];
2045 if (cl != NO_REGS)
2047 incr = ira_reg_class_max_nregs[cl][PSEUDO_REGNO_MODE (regno)];
2048 if (clobber_p)
2050 new_incr = reg_pressure_info[cl].clobber_increase + incr;
2051 reg_pressure_info[cl].clobber_increase = new_incr;
2053 else if (unused_p)
2055 new_incr = reg_pressure_info[cl].unused_set_increase + incr;
2056 reg_pressure_info[cl].unused_set_increase = new_incr;
2058 else
2060 new_incr = reg_pressure_info[cl].set_increase + incr;
2061 reg_pressure_info[cl].set_increase = new_incr;
2062 if (! insn_use_p (insn, regno))
2063 reg_pressure_info[cl].change += incr;
2064 create_insn_reg_set (regno, insn);
2066 gcc_assert (new_incr < (1 << INCREASE_BITS));
2070 /* Like mark_insn_pseudo_regno_birth except that NREGS saying how many
2071 hard registers involved in the birth. */
2072 static void
2073 mark_insn_hard_regno_birth (rtx insn, int regno, int nregs,
2074 bool clobber_p, bool unused_p)
2076 enum reg_class cl;
2077 int new_incr, last = regno + nregs;
2079 while (regno < last)
2081 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
2082 if (! TEST_HARD_REG_BIT (ira_no_alloc_regs, regno))
2084 cl = sched_regno_pressure_class[regno];
2085 if (cl != NO_REGS)
2087 if (clobber_p)
2089 new_incr = reg_pressure_info[cl].clobber_increase + 1;
2090 reg_pressure_info[cl].clobber_increase = new_incr;
2092 else if (unused_p)
2094 new_incr = reg_pressure_info[cl].unused_set_increase + 1;
2095 reg_pressure_info[cl].unused_set_increase = new_incr;
2097 else
2099 new_incr = reg_pressure_info[cl].set_increase + 1;
2100 reg_pressure_info[cl].set_increase = new_incr;
2101 if (! insn_use_p (insn, regno))
2102 reg_pressure_info[cl].change += 1;
2103 create_insn_reg_set (regno, insn);
2105 gcc_assert (new_incr < (1 << INCREASE_BITS));
2108 regno++;
2112 /* Update the register pressure info after birth of pseudo or hard
2113 register REG in INSN. Arguments CLOBBER_P and UNUSED_P say
2114 correspondingly that the register is in clobber or unused after the
2115 insn. */
2116 static void
2117 mark_insn_reg_birth (rtx insn, rtx reg, bool clobber_p, bool unused_p)
2119 int regno;
2121 if (GET_CODE (reg) == SUBREG)
2122 reg = SUBREG_REG (reg);
2124 if (! REG_P (reg))
2125 return;
2127 regno = REGNO (reg);
2128 if (regno < FIRST_PSEUDO_REGISTER)
2129 mark_insn_hard_regno_birth (insn, regno, REG_NREGS (reg),
2130 clobber_p, unused_p);
2131 else
2132 mark_insn_pseudo_birth (insn, regno, clobber_p, unused_p);
2135 /* Update the register pressure info after death of pseudo register
2136 REGNO. */
2137 static void
2138 mark_pseudo_death (int regno)
2140 int incr;
2141 enum reg_class cl;
2143 gcc_assert (regno >= FIRST_PSEUDO_REGISTER);
2144 cl = sched_regno_pressure_class[regno];
2145 if (cl != NO_REGS)
2147 incr = ira_reg_class_max_nregs[cl][PSEUDO_REGNO_MODE (regno)];
2148 reg_pressure_info[cl].change -= incr;
2152 /* Like mark_pseudo_death except that NREGS saying how many hard
2153 registers involved in the death. */
2154 static void
2155 mark_hard_regno_death (int regno, int nregs)
2157 enum reg_class cl;
2158 int last = regno + nregs;
2160 while (regno < last)
2162 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
2163 if (! TEST_HARD_REG_BIT (ira_no_alloc_regs, regno))
2165 cl = sched_regno_pressure_class[regno];
2166 if (cl != NO_REGS)
2167 reg_pressure_info[cl].change -= 1;
2169 regno++;
2173 /* Update the register pressure info after death of pseudo or hard
2174 register REG. */
2175 static void
2176 mark_reg_death (rtx reg)
2178 int regno;
2180 if (GET_CODE (reg) == SUBREG)
2181 reg = SUBREG_REG (reg);
2183 if (! REG_P (reg))
2184 return;
2186 regno = REGNO (reg);
2187 if (regno < FIRST_PSEUDO_REGISTER)
2188 mark_hard_regno_death (regno, REG_NREGS (reg));
2189 else
2190 mark_pseudo_death (regno);
2193 /* Process SETTER of REG. DATA is an insn containing the setter. */
2194 static void
2195 mark_insn_reg_store (rtx reg, const_rtx setter, void *data)
2197 if (setter != NULL_RTX && GET_CODE (setter) != SET)
2198 return;
2199 mark_insn_reg_birth
2200 ((rtx) data, reg, false,
2201 find_reg_note ((const_rtx) data, REG_UNUSED, reg) != NULL_RTX);
2204 /* Like mark_insn_reg_store except notice just CLOBBERs; ignore SETs. */
2205 static void
2206 mark_insn_reg_clobber (rtx reg, const_rtx setter, void *data)
2208 if (GET_CODE (setter) == CLOBBER)
2209 mark_insn_reg_birth ((rtx) data, reg, true, false);
2212 /* Set up reg pressure info related to INSN. */
2213 void
2214 init_insn_reg_pressure_info (rtx_insn *insn)
2216 int i, len;
2217 enum reg_class cl;
2218 static struct reg_pressure_data *pressure_info;
2219 rtx link;
2221 gcc_assert (sched_pressure != SCHED_PRESSURE_NONE);
2223 if (! INSN_P (insn))
2224 return;
2226 for (i = 0; i < ira_pressure_classes_num; i++)
2228 cl = ira_pressure_classes[i];
2229 reg_pressure_info[cl].clobber_increase = 0;
2230 reg_pressure_info[cl].set_increase = 0;
2231 reg_pressure_info[cl].unused_set_increase = 0;
2232 reg_pressure_info[cl].change = 0;
2235 note_stores (PATTERN (insn), mark_insn_reg_clobber, insn);
2237 note_stores (PATTERN (insn), mark_insn_reg_store, insn);
2239 #ifdef AUTO_INC_DEC
2240 for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
2241 if (REG_NOTE_KIND (link) == REG_INC)
2242 mark_insn_reg_store (XEXP (link, 0), NULL_RTX, insn);
2243 #endif
2245 for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
2246 if (REG_NOTE_KIND (link) == REG_DEAD)
2247 mark_reg_death (XEXP (link, 0));
2249 len = sizeof (struct reg_pressure_data) * ira_pressure_classes_num;
2250 pressure_info
2251 = INSN_REG_PRESSURE (insn) = (struct reg_pressure_data *) xmalloc (len);
2252 if (sched_pressure == SCHED_PRESSURE_WEIGHTED)
2253 INSN_MAX_REG_PRESSURE (insn) = (int *) xcalloc (ira_pressure_classes_num
2254 * sizeof (int), 1);
2255 for (i = 0; i < ira_pressure_classes_num; i++)
2257 cl = ira_pressure_classes[i];
2258 pressure_info[i].clobber_increase
2259 = reg_pressure_info[cl].clobber_increase;
2260 pressure_info[i].set_increase = reg_pressure_info[cl].set_increase;
2261 pressure_info[i].unused_set_increase
2262 = reg_pressure_info[cl].unused_set_increase;
2263 pressure_info[i].change = reg_pressure_info[cl].change;
2270 /* Internal variable for sched_analyze_[12] () functions.
2271 If it is nonzero, this means that sched_analyze_[12] looks
2272 at the most toplevel SET. */
2273 static bool can_start_lhs_rhs_p;
2275 /* Extend reg info for the deps context DEPS given that
2276 we have just generated a register numbered REGNO. */
2277 static void
2278 extend_deps_reg_info (struct deps_desc *deps, int regno)
2280 int max_regno = regno + 1;
2282 gcc_assert (!reload_completed);
2284 /* In a readonly context, it would not hurt to extend info,
2285 but it should not be needed. */
2286 if (reload_completed && deps->readonly)
2288 deps->max_reg = max_regno;
2289 return;
2292 if (max_regno > deps->max_reg)
2294 deps->reg_last = XRESIZEVEC (struct deps_reg, deps->reg_last,
2295 max_regno);
2296 memset (&deps->reg_last[deps->max_reg],
2297 0, (max_regno - deps->max_reg)
2298 * sizeof (struct deps_reg));
2299 deps->max_reg = max_regno;
2303 /* Extends REG_INFO_P if needed. */
2304 void
2305 maybe_extend_reg_info_p (void)
2307 /* Extend REG_INFO_P, if needed. */
2308 if ((unsigned int)max_regno - 1 >= reg_info_p_size)
2310 size_t new_reg_info_p_size = max_regno + 128;
2312 gcc_assert (!reload_completed && sel_sched_p ());
2314 reg_info_p = (struct reg_info_t *) xrecalloc (reg_info_p,
2315 new_reg_info_p_size,
2316 reg_info_p_size,
2317 sizeof (*reg_info_p));
2318 reg_info_p_size = new_reg_info_p_size;
2322 /* Analyze a single reference to register (reg:MODE REGNO) in INSN.
2323 The type of the reference is specified by REF and can be SET,
2324 CLOBBER, PRE_DEC, POST_DEC, PRE_INC, POST_INC or USE. */
2326 static void
2327 sched_analyze_reg (struct deps_desc *deps, int regno, machine_mode mode,
2328 enum rtx_code ref, rtx_insn *insn)
2330 /* We could emit new pseudos in renaming. Extend the reg structures. */
2331 if (!reload_completed && sel_sched_p ()
2332 && (regno >= max_reg_num () - 1 || regno >= deps->max_reg))
2333 extend_deps_reg_info (deps, regno);
2335 maybe_extend_reg_info_p ();
2337 /* A hard reg in a wide mode may really be multiple registers.
2338 If so, mark all of them just like the first. */
2339 if (regno < FIRST_PSEUDO_REGISTER)
2341 int i = hard_regno_nregs[regno][mode];
2342 if (ref == SET)
2344 while (--i >= 0)
2345 note_reg_set (regno + i);
2347 else if (ref == USE)
2349 while (--i >= 0)
2350 note_reg_use (regno + i);
2352 else
2354 while (--i >= 0)
2355 note_reg_clobber (regno + i);
2359 /* ??? Reload sometimes emits USEs and CLOBBERs of pseudos that
2360 it does not reload. Ignore these as they have served their
2361 purpose already. */
2362 else if (regno >= deps->max_reg)
2364 enum rtx_code code = GET_CODE (PATTERN (insn));
2365 gcc_assert (code == USE || code == CLOBBER);
2368 else
2370 if (ref == SET)
2371 note_reg_set (regno);
2372 else if (ref == USE)
2373 note_reg_use (regno);
2374 else
2375 note_reg_clobber (regno);
2377 /* Pseudos that are REG_EQUIV to something may be replaced
2378 by that during reloading. We need only add dependencies for
2379 the address in the REG_EQUIV note. */
2380 if (!reload_completed && get_reg_known_equiv_p (regno))
2382 rtx t = get_reg_known_value (regno);
2383 if (MEM_P (t))
2384 sched_analyze_2 (deps, XEXP (t, 0), insn);
2387 /* Don't let it cross a call after scheduling if it doesn't
2388 already cross one. */
2389 if (REG_N_CALLS_CROSSED (regno) == 0)
2391 if (!deps->readonly && ref == USE && !DEBUG_INSN_P (insn))
2392 deps->sched_before_next_call
2393 = alloc_INSN_LIST (insn, deps->sched_before_next_call);
2394 else
2395 add_dependence_list (insn, deps->last_function_call, 1,
2396 REG_DEP_ANTI, false);
2401 /* Analyze a single SET, CLOBBER, PRE_DEC, POST_DEC, PRE_INC or POST_INC
2402 rtx, X, creating all dependencies generated by the write to the
2403 destination of X, and reads of everything mentioned. */
2405 static void
2406 sched_analyze_1 (struct deps_desc *deps, rtx x, rtx_insn *insn)
2408 rtx dest = XEXP (x, 0);
2409 enum rtx_code code = GET_CODE (x);
2410 bool cslr_p = can_start_lhs_rhs_p;
2412 can_start_lhs_rhs_p = false;
2414 gcc_assert (dest);
2415 if (dest == 0)
2416 return;
2418 if (cslr_p && sched_deps_info->start_lhs)
2419 sched_deps_info->start_lhs (dest);
2421 if (GET_CODE (dest) == PARALLEL)
2423 int i;
2425 for (i = XVECLEN (dest, 0) - 1; i >= 0; i--)
2426 if (XEXP (XVECEXP (dest, 0, i), 0) != 0)
2427 sched_analyze_1 (deps,
2428 gen_rtx_CLOBBER (VOIDmode,
2429 XEXP (XVECEXP (dest, 0, i), 0)),
2430 insn);
2432 if (cslr_p && sched_deps_info->finish_lhs)
2433 sched_deps_info->finish_lhs ();
2435 if (code == SET)
2437 can_start_lhs_rhs_p = cslr_p;
2439 sched_analyze_2 (deps, SET_SRC (x), insn);
2441 can_start_lhs_rhs_p = false;
2444 return;
2447 while (GET_CODE (dest) == STRICT_LOW_PART || GET_CODE (dest) == SUBREG
2448 || GET_CODE (dest) == ZERO_EXTRACT)
2450 if (GET_CODE (dest) == STRICT_LOW_PART
2451 || GET_CODE (dest) == ZERO_EXTRACT
2452 || df_read_modify_subreg_p (dest))
2454 /* These both read and modify the result. We must handle
2455 them as writes to get proper dependencies for following
2456 instructions. We must handle them as reads to get proper
2457 dependencies from this to previous instructions.
2458 Thus we need to call sched_analyze_2. */
2460 sched_analyze_2 (deps, XEXP (dest, 0), insn);
2462 if (GET_CODE (dest) == ZERO_EXTRACT)
2464 /* The second and third arguments are values read by this insn. */
2465 sched_analyze_2 (deps, XEXP (dest, 1), insn);
2466 sched_analyze_2 (deps, XEXP (dest, 2), insn);
2468 dest = XEXP (dest, 0);
2471 if (REG_P (dest))
2473 int regno = REGNO (dest);
2474 machine_mode mode = GET_MODE (dest);
2476 sched_analyze_reg (deps, regno, mode, code, insn);
2478 #ifdef STACK_REGS
2479 /* Treat all writes to a stack register as modifying the TOS. */
2480 if (regno >= FIRST_STACK_REG && regno <= LAST_STACK_REG)
2482 /* Avoid analyzing the same register twice. */
2483 if (regno != FIRST_STACK_REG)
2484 sched_analyze_reg (deps, FIRST_STACK_REG, mode, code, insn);
2486 add_to_hard_reg_set (&implicit_reg_pending_uses, mode,
2487 FIRST_STACK_REG);
2489 #endif
2491 else if (MEM_P (dest))
2493 /* Writing memory. */
2494 rtx t = dest;
2496 if (sched_deps_info->use_cselib)
2498 machine_mode address_mode = get_address_mode (dest);
2500 t = shallow_copy_rtx (dest);
2501 cselib_lookup_from_insn (XEXP (t, 0), address_mode, 1,
2502 GET_MODE (t), insn);
2503 XEXP (t, 0)
2504 = cselib_subst_to_values_from_insn (XEXP (t, 0), GET_MODE (t),
2505 insn);
2507 t = canon_rtx (t);
2509 /* Pending lists can't get larger with a readonly context. */
2510 if (!deps->readonly
2511 && ((deps->pending_read_list_length + deps->pending_write_list_length)
2512 >= MAX_PENDING_LIST_LENGTH))
2514 /* Flush all pending reads and writes to prevent the pending lists
2515 from getting any larger. Insn scheduling runs too slowly when
2516 these lists get long. When compiling GCC with itself,
2517 this flush occurs 8 times for sparc, and 10 times for m88k using
2518 the default value of 32. */
2519 flush_pending_lists (deps, insn, false, true);
2521 else
2523 rtx_insn_list *pending;
2524 rtx_expr_list *pending_mem;
2526 pending = deps->pending_read_insns;
2527 pending_mem = deps->pending_read_mems;
2528 while (pending)
2530 if (anti_dependence (pending_mem->element (), t)
2531 && ! sched_insns_conditions_mutex_p (insn, pending->insn ()))
2532 note_mem_dep (t, pending_mem->element (), pending->insn (),
2533 DEP_ANTI);
2535 pending = pending->next ();
2536 pending_mem = pending_mem->next ();
2539 pending = deps->pending_write_insns;
2540 pending_mem = deps->pending_write_mems;
2541 while (pending)
2543 if (output_dependence (pending_mem->element (), t)
2544 && ! sched_insns_conditions_mutex_p (insn, pending->insn ()))
2545 note_mem_dep (t, pending_mem->element (),
2546 pending->insn (),
2547 DEP_OUTPUT);
2549 pending = pending->next ();
2550 pending_mem = pending_mem-> next ();
2553 add_dependence_list (insn, deps->last_pending_memory_flush, 1,
2554 REG_DEP_ANTI, true);
2555 add_dependence_list (insn, deps->pending_jump_insns, 1,
2556 REG_DEP_CONTROL, true);
2558 if (!deps->readonly)
2559 add_insn_mem_dependence (deps, false, insn, dest);
2561 sched_analyze_2 (deps, XEXP (dest, 0), insn);
2564 if (cslr_p && sched_deps_info->finish_lhs)
2565 sched_deps_info->finish_lhs ();
2567 /* Analyze reads. */
2568 if (GET_CODE (x) == SET)
2570 can_start_lhs_rhs_p = cslr_p;
2572 sched_analyze_2 (deps, SET_SRC (x), insn);
2574 can_start_lhs_rhs_p = false;
2578 /* Analyze the uses of memory and registers in rtx X in INSN. */
2579 static void
2580 sched_analyze_2 (struct deps_desc *deps, rtx x, rtx_insn *insn)
2582 int i;
2583 int j;
2584 enum rtx_code code;
2585 const char *fmt;
2586 bool cslr_p = can_start_lhs_rhs_p;
2588 can_start_lhs_rhs_p = false;
2590 gcc_assert (x);
2591 if (x == 0)
2592 return;
2594 if (cslr_p && sched_deps_info->start_rhs)
2595 sched_deps_info->start_rhs (x);
2597 code = GET_CODE (x);
2599 switch (code)
2601 CASE_CONST_ANY:
2602 case SYMBOL_REF:
2603 case CONST:
2604 case LABEL_REF:
2605 /* Ignore constants. */
2606 if (cslr_p && sched_deps_info->finish_rhs)
2607 sched_deps_info->finish_rhs ();
2609 return;
2611 case CC0:
2612 if (!HAVE_cc0)
2613 gcc_unreachable ();
2615 /* User of CC0 depends on immediately preceding insn. */
2616 SCHED_GROUP_P (insn) = 1;
2617 /* Don't move CC0 setter to another block (it can set up the
2618 same flag for previous CC0 users which is safe). */
2619 CANT_MOVE (prev_nonnote_insn (insn)) = 1;
2621 if (cslr_p && sched_deps_info->finish_rhs)
2622 sched_deps_info->finish_rhs ();
2624 return;
2626 case REG:
2628 int regno = REGNO (x);
2629 machine_mode mode = GET_MODE (x);
2631 sched_analyze_reg (deps, regno, mode, USE, insn);
2633 #ifdef STACK_REGS
2634 /* Treat all reads of a stack register as modifying the TOS. */
2635 if (regno >= FIRST_STACK_REG && regno <= LAST_STACK_REG)
2637 /* Avoid analyzing the same register twice. */
2638 if (regno != FIRST_STACK_REG)
2639 sched_analyze_reg (deps, FIRST_STACK_REG, mode, USE, insn);
2640 sched_analyze_reg (deps, FIRST_STACK_REG, mode, SET, insn);
2642 #endif
2644 if (cslr_p && sched_deps_info->finish_rhs)
2645 sched_deps_info->finish_rhs ();
2647 return;
2650 case MEM:
2652 /* Reading memory. */
2653 rtx_insn_list *u;
2654 rtx_insn_list *pending;
2655 rtx_expr_list *pending_mem;
2656 rtx t = x;
2658 if (sched_deps_info->use_cselib)
2660 machine_mode address_mode = get_address_mode (t);
2662 t = shallow_copy_rtx (t);
2663 cselib_lookup_from_insn (XEXP (t, 0), address_mode, 1,
2664 GET_MODE (t), insn);
2665 XEXP (t, 0)
2666 = cselib_subst_to_values_from_insn (XEXP (t, 0), GET_MODE (t),
2667 insn);
2670 if (!DEBUG_INSN_P (insn))
2672 t = canon_rtx (t);
2673 pending = deps->pending_read_insns;
2674 pending_mem = deps->pending_read_mems;
2675 while (pending)
2677 if (read_dependence (pending_mem->element (), t)
2678 && ! sched_insns_conditions_mutex_p (insn,
2679 pending->insn ()))
2680 note_mem_dep (t, pending_mem->element (),
2681 pending->insn (),
2682 DEP_ANTI);
2684 pending = pending->next ();
2685 pending_mem = pending_mem->next ();
2688 pending = deps->pending_write_insns;
2689 pending_mem = deps->pending_write_mems;
2690 while (pending)
2692 if (true_dependence (pending_mem->element (), VOIDmode, t)
2693 && ! sched_insns_conditions_mutex_p (insn,
2694 pending->insn ()))
2695 note_mem_dep (t, pending_mem->element (),
2696 pending->insn (),
2697 sched_deps_info->generate_spec_deps
2698 ? BEGIN_DATA | DEP_TRUE : DEP_TRUE);
2700 pending = pending->next ();
2701 pending_mem = pending_mem->next ();
2704 for (u = deps->last_pending_memory_flush; u; u = u->next ())
2705 add_dependence (insn, u->insn (), REG_DEP_ANTI);
2707 for (u = deps->pending_jump_insns; u; u = u->next ())
2708 if (deps_may_trap_p (x))
2710 if ((sched_deps_info->generate_spec_deps)
2711 && sel_sched_p () && (spec_info->mask & BEGIN_CONTROL))
2713 ds_t ds = set_dep_weak (DEP_ANTI, BEGIN_CONTROL,
2714 MAX_DEP_WEAK);
2716 note_dep (u->insn (), ds);
2718 else
2719 add_dependence (insn, u->insn (), REG_DEP_CONTROL);
2723 /* Always add these dependencies to pending_reads, since
2724 this insn may be followed by a write. */
2725 if (!deps->readonly)
2727 if ((deps->pending_read_list_length
2728 + deps->pending_write_list_length)
2729 >= MAX_PENDING_LIST_LENGTH
2730 && !DEBUG_INSN_P (insn))
2731 flush_pending_lists (deps, insn, true, true);
2732 add_insn_mem_dependence (deps, true, insn, x);
2735 sched_analyze_2 (deps, XEXP (x, 0), insn);
2737 if (cslr_p && sched_deps_info->finish_rhs)
2738 sched_deps_info->finish_rhs ();
2740 return;
2743 /* Force pending stores to memory in case a trap handler needs them. */
2744 case TRAP_IF:
2745 flush_pending_lists (deps, insn, true, false);
2746 break;
2748 case PREFETCH:
2749 if (PREFETCH_SCHEDULE_BARRIER_P (x))
2750 reg_pending_barrier = TRUE_BARRIER;
2751 /* Prefetch insn contains addresses only. So if the prefetch
2752 address has no registers, there will be no dependencies on
2753 the prefetch insn. This is wrong with result code
2754 correctness point of view as such prefetch can be moved below
2755 a jump insn which usually generates MOVE_BARRIER preventing
2756 to move insns containing registers or memories through the
2757 barrier. It is also wrong with generated code performance
2758 point of view as prefetch withouth dependecies will have a
2759 tendency to be issued later instead of earlier. It is hard
2760 to generate accurate dependencies for prefetch insns as
2761 prefetch has only the start address but it is better to have
2762 something than nothing. */
2763 if (!deps->readonly)
2765 rtx x = gen_rtx_MEM (Pmode, XEXP (PATTERN (insn), 0));
2766 if (sched_deps_info->use_cselib)
2767 cselib_lookup_from_insn (x, Pmode, true, VOIDmode, insn);
2768 add_insn_mem_dependence (deps, true, insn, x);
2770 break;
2772 case UNSPEC_VOLATILE:
2773 flush_pending_lists (deps, insn, true, true);
2774 /* FALLTHRU */
2776 case ASM_OPERANDS:
2777 case ASM_INPUT:
2779 /* Traditional and volatile asm instructions must be considered to use
2780 and clobber all hard registers, all pseudo-registers and all of
2781 memory. So must TRAP_IF and UNSPEC_VOLATILE operations.
2783 Consider for instance a volatile asm that changes the fpu rounding
2784 mode. An insn should not be moved across this even if it only uses
2785 pseudo-regs because it might give an incorrectly rounded result. */
2786 if ((code != ASM_OPERANDS || MEM_VOLATILE_P (x))
2787 && !DEBUG_INSN_P (insn))
2788 reg_pending_barrier = TRUE_BARRIER;
2790 /* For all ASM_OPERANDS, we must traverse the vector of input operands.
2791 We can not just fall through here since then we would be confused
2792 by the ASM_INPUT rtx inside ASM_OPERANDS, which do not indicate
2793 traditional asms unlike their normal usage. */
2795 if (code == ASM_OPERANDS)
2797 for (j = 0; j < ASM_OPERANDS_INPUT_LENGTH (x); j++)
2798 sched_analyze_2 (deps, ASM_OPERANDS_INPUT (x, j), insn);
2800 if (cslr_p && sched_deps_info->finish_rhs)
2801 sched_deps_info->finish_rhs ();
2803 return;
2805 break;
2808 case PRE_DEC:
2809 case POST_DEC:
2810 case PRE_INC:
2811 case POST_INC:
2812 /* These both read and modify the result. We must handle them as writes
2813 to get proper dependencies for following instructions. We must handle
2814 them as reads to get proper dependencies from this to previous
2815 instructions. Thus we need to pass them to both sched_analyze_1
2816 and sched_analyze_2. We must call sched_analyze_2 first in order
2817 to get the proper antecedent for the read. */
2818 sched_analyze_2 (deps, XEXP (x, 0), insn);
2819 sched_analyze_1 (deps, x, insn);
2821 if (cslr_p && sched_deps_info->finish_rhs)
2822 sched_deps_info->finish_rhs ();
2824 return;
2826 case POST_MODIFY:
2827 case PRE_MODIFY:
2828 /* op0 = op0 + op1 */
2829 sched_analyze_2 (deps, XEXP (x, 0), insn);
2830 sched_analyze_2 (deps, XEXP (x, 1), insn);
2831 sched_analyze_1 (deps, x, insn);
2833 if (cslr_p && sched_deps_info->finish_rhs)
2834 sched_deps_info->finish_rhs ();
2836 return;
2838 default:
2839 break;
2842 /* Other cases: walk the insn. */
2843 fmt = GET_RTX_FORMAT (code);
2844 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2846 if (fmt[i] == 'e')
2847 sched_analyze_2 (deps, XEXP (x, i), insn);
2848 else if (fmt[i] == 'E')
2849 for (j = 0; j < XVECLEN (x, i); j++)
2850 sched_analyze_2 (deps, XVECEXP (x, i, j), insn);
2853 if (cslr_p && sched_deps_info->finish_rhs)
2854 sched_deps_info->finish_rhs ();
2857 /* Try to group two fusible insns together to prevent scheduler
2858 from scheduling them apart. */
2860 static void
2861 sched_macro_fuse_insns (rtx_insn *insn)
2863 rtx_insn *prev;
2865 if (any_condjump_p (insn))
2867 unsigned int condreg1, condreg2;
2868 rtx cc_reg_1;
2869 targetm.fixed_condition_code_regs (&condreg1, &condreg2);
2870 cc_reg_1 = gen_rtx_REG (CCmode, condreg1);
2871 prev = prev_nonnote_nondebug_insn (insn);
2872 if (!reg_referenced_p (cc_reg_1, PATTERN (insn))
2873 || !prev
2874 || !modified_in_p (cc_reg_1, prev))
2875 return;
2877 else
2879 rtx insn_set = single_set (insn);
2881 prev = prev_nonnote_nondebug_insn (insn);
2882 if (!prev
2883 || !insn_set
2884 || !single_set (prev))
2885 return;
2889 if (targetm.sched.macro_fusion_pair_p (prev, insn))
2890 SCHED_GROUP_P (insn) = 1;
2894 /* Analyze an INSN with pattern X to find all dependencies. */
2895 static void
2896 sched_analyze_insn (struct deps_desc *deps, rtx x, rtx_insn *insn)
2898 RTX_CODE code = GET_CODE (x);
2899 rtx link;
2900 unsigned i;
2901 reg_set_iterator rsi;
2903 if (! reload_completed)
2905 HARD_REG_SET temp;
2907 extract_insn (insn);
2908 preprocess_constraints (insn);
2909 ira_implicitly_set_insn_hard_regs (&temp);
2910 AND_COMPL_HARD_REG_SET (temp, ira_no_alloc_regs);
2911 IOR_HARD_REG_SET (implicit_reg_pending_clobbers, temp);
2914 can_start_lhs_rhs_p = (NONJUMP_INSN_P (insn)
2915 && code == SET);
2917 /* Group compare and branch insns for macro-fusion. */
2918 if (targetm.sched.macro_fusion_p
2919 && targetm.sched.macro_fusion_p ())
2920 sched_macro_fuse_insns (insn);
2922 if (may_trap_p (x))
2923 /* Avoid moving trapping instructions across function calls that might
2924 not always return. */
2925 add_dependence_list (insn, deps->last_function_call_may_noreturn,
2926 1, REG_DEP_ANTI, true);
2928 /* We must avoid creating a situation in which two successors of the
2929 current block have different unwind info after scheduling. If at any
2930 point the two paths re-join this leads to incorrect unwind info. */
2931 /* ??? There are certain situations involving a forced frame pointer in
2932 which, with extra effort, we could fix up the unwind info at a later
2933 CFG join. However, it seems better to notice these cases earlier
2934 during prologue generation and avoid marking the frame pointer setup
2935 as frame-related at all. */
2936 if (RTX_FRAME_RELATED_P (insn))
2938 /* Make sure prologue insn is scheduled before next jump. */
2939 deps->sched_before_next_jump
2940 = alloc_INSN_LIST (insn, deps->sched_before_next_jump);
2942 /* Make sure epilogue insn is scheduled after preceding jumps. */
2943 add_dependence_list (insn, deps->pending_jump_insns, 1, REG_DEP_ANTI,
2944 true);
2947 if (code == COND_EXEC)
2949 sched_analyze_2 (deps, COND_EXEC_TEST (x), insn);
2951 /* ??? Should be recording conditions so we reduce the number of
2952 false dependencies. */
2953 x = COND_EXEC_CODE (x);
2954 code = GET_CODE (x);
2956 if (code == SET || code == CLOBBER)
2958 sched_analyze_1 (deps, x, insn);
2960 /* Bare clobber insns are used for letting life analysis, reg-stack
2961 and others know that a value is dead. Depend on the last call
2962 instruction so that reg-stack won't get confused. */
2963 if (code == CLOBBER)
2964 add_dependence_list (insn, deps->last_function_call, 1,
2965 REG_DEP_OUTPUT, true);
2967 else if (code == PARALLEL)
2969 for (i = XVECLEN (x, 0); i--;)
2971 rtx sub = XVECEXP (x, 0, i);
2972 code = GET_CODE (sub);
2974 if (code == COND_EXEC)
2976 sched_analyze_2 (deps, COND_EXEC_TEST (sub), insn);
2977 sub = COND_EXEC_CODE (sub);
2978 code = GET_CODE (sub);
2980 if (code == SET || code == CLOBBER)
2981 sched_analyze_1 (deps, sub, insn);
2982 else
2983 sched_analyze_2 (deps, sub, insn);
2986 else
2987 sched_analyze_2 (deps, x, insn);
2989 /* Mark registers CLOBBERED or used by called function. */
2990 if (CALL_P (insn))
2992 for (link = CALL_INSN_FUNCTION_USAGE (insn); link; link = XEXP (link, 1))
2994 if (GET_CODE (XEXP (link, 0)) == CLOBBER)
2995 sched_analyze_1 (deps, XEXP (link, 0), insn);
2996 else if (GET_CODE (XEXP (link, 0)) != SET)
2997 sched_analyze_2 (deps, XEXP (link, 0), insn);
2999 /* Don't schedule anything after a tail call, tail call needs
3000 to use at least all call-saved registers. */
3001 if (SIBLING_CALL_P (insn))
3002 reg_pending_barrier = TRUE_BARRIER;
3003 else if (find_reg_note (insn, REG_SETJMP, NULL))
3004 reg_pending_barrier = MOVE_BARRIER;
3007 if (JUMP_P (insn))
3009 rtx next;
3010 next = next_nonnote_nondebug_insn (insn);
3011 if (next && BARRIER_P (next))
3012 reg_pending_barrier = MOVE_BARRIER;
3013 else
3015 rtx_insn_list *pending;
3016 rtx_expr_list *pending_mem;
3018 if (sched_deps_info->compute_jump_reg_dependencies)
3020 (*sched_deps_info->compute_jump_reg_dependencies)
3021 (insn, reg_pending_control_uses);
3023 /* Make latency of jump equal to 0 by using anti-dependence. */
3024 EXECUTE_IF_SET_IN_REG_SET (reg_pending_control_uses, 0, i, rsi)
3026 struct deps_reg *reg_last = &deps->reg_last[i];
3027 add_dependence_list (insn, reg_last->sets, 0, REG_DEP_ANTI,
3028 false);
3029 add_dependence_list (insn, reg_last->implicit_sets,
3030 0, REG_DEP_ANTI, false);
3031 add_dependence_list (insn, reg_last->clobbers, 0,
3032 REG_DEP_ANTI, false);
3036 /* All memory writes and volatile reads must happen before the
3037 jump. Non-volatile reads must happen before the jump iff
3038 the result is needed by the above register used mask. */
3040 pending = deps->pending_write_insns;
3041 pending_mem = deps->pending_write_mems;
3042 while (pending)
3044 if (! sched_insns_conditions_mutex_p (insn, pending->insn ()))
3045 add_dependence (insn, pending->insn (),
3046 REG_DEP_OUTPUT);
3047 pending = pending->next ();
3048 pending_mem = pending_mem->next ();
3051 pending = deps->pending_read_insns;
3052 pending_mem = deps->pending_read_mems;
3053 while (pending)
3055 if (MEM_VOLATILE_P (pending_mem->element ())
3056 && ! sched_insns_conditions_mutex_p (insn, pending->insn ()))
3057 add_dependence (insn, pending->insn (),
3058 REG_DEP_OUTPUT);
3059 pending = pending->next ();
3060 pending_mem = pending_mem->next ();
3063 add_dependence_list (insn, deps->last_pending_memory_flush, 1,
3064 REG_DEP_ANTI, true);
3065 add_dependence_list (insn, deps->pending_jump_insns, 1,
3066 REG_DEP_ANTI, true);
3070 /* If this instruction can throw an exception, then moving it changes
3071 where block boundaries fall. This is mighty confusing elsewhere.
3072 Therefore, prevent such an instruction from being moved. Same for
3073 non-jump instructions that define block boundaries.
3074 ??? Unclear whether this is still necessary in EBB mode. If not,
3075 add_branch_dependences should be adjusted for RGN mode instead. */
3076 if (((CALL_P (insn) || JUMP_P (insn)) && can_throw_internal (insn))
3077 || (NONJUMP_INSN_P (insn) && control_flow_insn_p (insn)))
3078 reg_pending_barrier = MOVE_BARRIER;
3080 if (sched_pressure != SCHED_PRESSURE_NONE)
3082 setup_insn_reg_uses (deps, insn);
3083 init_insn_reg_pressure_info (insn);
3086 /* Add register dependencies for insn. */
3087 if (DEBUG_INSN_P (insn))
3089 rtx_insn *prev = deps->last_debug_insn;
3090 rtx_insn_list *u;
3092 if (!deps->readonly)
3093 deps->last_debug_insn = insn;
3095 if (prev)
3096 add_dependence (insn, prev, REG_DEP_ANTI);
3098 add_dependence_list (insn, deps->last_function_call, 1,
3099 REG_DEP_ANTI, false);
3101 if (!sel_sched_p ())
3102 for (u = deps->last_pending_memory_flush; u; u = u->next ())
3103 add_dependence (insn, u->insn (), REG_DEP_ANTI);
3105 EXECUTE_IF_SET_IN_REG_SET (reg_pending_uses, 0, i, rsi)
3107 struct deps_reg *reg_last = &deps->reg_last[i];
3108 add_dependence_list (insn, reg_last->sets, 1, REG_DEP_ANTI, false);
3109 /* There's no point in making REG_DEP_CONTROL dependencies for
3110 debug insns. */
3111 add_dependence_list (insn, reg_last->clobbers, 1, REG_DEP_ANTI,
3112 false);
3114 if (!deps->readonly)
3115 reg_last->uses = alloc_INSN_LIST (insn, reg_last->uses);
3117 CLEAR_REG_SET (reg_pending_uses);
3119 /* Quite often, a debug insn will refer to stuff in the
3120 previous instruction, but the reason we want this
3121 dependency here is to make sure the scheduler doesn't
3122 gratuitously move a debug insn ahead. This could dirty
3123 DF flags and cause additional analysis that wouldn't have
3124 occurred in compilation without debug insns, and such
3125 additional analysis can modify the generated code. */
3126 prev = PREV_INSN (insn);
3128 if (prev && NONDEBUG_INSN_P (prev))
3129 add_dependence (insn, prev, REG_DEP_ANTI);
3131 else
3133 regset_head set_or_clobbered;
3135 EXECUTE_IF_SET_IN_REG_SET (reg_pending_uses, 0, i, rsi)
3137 struct deps_reg *reg_last = &deps->reg_last[i];
3138 add_dependence_list (insn, reg_last->sets, 0, REG_DEP_TRUE, false);
3139 add_dependence_list (insn, reg_last->implicit_sets, 0, REG_DEP_ANTI,
3140 false);
3141 add_dependence_list (insn, reg_last->clobbers, 0, REG_DEP_TRUE,
3142 false);
3144 if (!deps->readonly)
3146 reg_last->uses = alloc_INSN_LIST (insn, reg_last->uses);
3147 reg_last->uses_length++;
3151 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3152 if (TEST_HARD_REG_BIT (implicit_reg_pending_uses, i))
3154 struct deps_reg *reg_last = &deps->reg_last[i];
3155 add_dependence_list (insn, reg_last->sets, 0, REG_DEP_TRUE, false);
3156 add_dependence_list (insn, reg_last->implicit_sets, 0,
3157 REG_DEP_ANTI, false);
3158 add_dependence_list (insn, reg_last->clobbers, 0, REG_DEP_TRUE,
3159 false);
3161 if (!deps->readonly)
3163 reg_last->uses = alloc_INSN_LIST (insn, reg_last->uses);
3164 reg_last->uses_length++;
3168 if (targetm.sched.exposed_pipeline)
3170 INIT_REG_SET (&set_or_clobbered);
3171 bitmap_ior (&set_or_clobbered, reg_pending_clobbers,
3172 reg_pending_sets);
3173 EXECUTE_IF_SET_IN_REG_SET (&set_or_clobbered, 0, i, rsi)
3175 struct deps_reg *reg_last = &deps->reg_last[i];
3176 rtx list;
3177 for (list = reg_last->uses; list; list = XEXP (list, 1))
3179 rtx other = XEXP (list, 0);
3180 if (INSN_CACHED_COND (other) != const_true_rtx
3181 && refers_to_regno_p (i, INSN_CACHED_COND (other)))
3182 INSN_CACHED_COND (other) = const_true_rtx;
3187 /* If the current insn is conditional, we can't free any
3188 of the lists. */
3189 if (sched_has_condition_p (insn))
3191 EXECUTE_IF_SET_IN_REG_SET (reg_pending_clobbers, 0, i, rsi)
3193 struct deps_reg *reg_last = &deps->reg_last[i];
3194 add_dependence_list (insn, reg_last->sets, 0, REG_DEP_OUTPUT,
3195 false);
3196 add_dependence_list (insn, reg_last->implicit_sets, 0,
3197 REG_DEP_ANTI, false);
3198 add_dependence_list (insn, reg_last->uses, 0, REG_DEP_ANTI,
3199 false);
3200 add_dependence_list (insn, reg_last->control_uses, 0,
3201 REG_DEP_CONTROL, false);
3203 if (!deps->readonly)
3205 reg_last->clobbers
3206 = alloc_INSN_LIST (insn, reg_last->clobbers);
3207 reg_last->clobbers_length++;
3210 EXECUTE_IF_SET_IN_REG_SET (reg_pending_sets, 0, i, rsi)
3212 struct deps_reg *reg_last = &deps->reg_last[i];
3213 add_dependence_list (insn, reg_last->sets, 0, REG_DEP_OUTPUT,
3214 false);
3215 add_dependence_list (insn, reg_last->implicit_sets, 0,
3216 REG_DEP_ANTI, false);
3217 add_dependence_list (insn, reg_last->clobbers, 0, REG_DEP_OUTPUT,
3218 false);
3219 add_dependence_list (insn, reg_last->uses, 0, REG_DEP_ANTI,
3220 false);
3221 add_dependence_list (insn, reg_last->control_uses, 0,
3222 REG_DEP_CONTROL, false);
3224 if (!deps->readonly)
3225 reg_last->sets = alloc_INSN_LIST (insn, reg_last->sets);
3228 else
3230 EXECUTE_IF_SET_IN_REG_SET (reg_pending_clobbers, 0, i, rsi)
3232 struct deps_reg *reg_last = &deps->reg_last[i];
3233 if (reg_last->uses_length >= MAX_PENDING_LIST_LENGTH
3234 || reg_last->clobbers_length >= MAX_PENDING_LIST_LENGTH)
3236 add_dependence_list_and_free (deps, insn, &reg_last->sets, 0,
3237 REG_DEP_OUTPUT, false);
3238 add_dependence_list_and_free (deps, insn,
3239 &reg_last->implicit_sets, 0,
3240 REG_DEP_ANTI, false);
3241 add_dependence_list_and_free (deps, insn, &reg_last->uses, 0,
3242 REG_DEP_ANTI, false);
3243 add_dependence_list_and_free (deps, insn,
3244 &reg_last->control_uses, 0,
3245 REG_DEP_ANTI, false);
3246 add_dependence_list_and_free (deps, insn,
3247 &reg_last->clobbers, 0,
3248 REG_DEP_OUTPUT, false);
3250 if (!deps->readonly)
3252 reg_last->sets = alloc_INSN_LIST (insn, reg_last->sets);
3253 reg_last->clobbers_length = 0;
3254 reg_last->uses_length = 0;
3257 else
3259 add_dependence_list (insn, reg_last->sets, 0, REG_DEP_OUTPUT,
3260 false);
3261 add_dependence_list (insn, reg_last->implicit_sets, 0,
3262 REG_DEP_ANTI, false);
3263 add_dependence_list (insn, reg_last->uses, 0, REG_DEP_ANTI,
3264 false);
3265 add_dependence_list (insn, reg_last->control_uses, 0,
3266 REG_DEP_CONTROL, false);
3269 if (!deps->readonly)
3271 reg_last->clobbers_length++;
3272 reg_last->clobbers
3273 = alloc_INSN_LIST (insn, reg_last->clobbers);
3276 EXECUTE_IF_SET_IN_REG_SET (reg_pending_sets, 0, i, rsi)
3278 struct deps_reg *reg_last = &deps->reg_last[i];
3280 add_dependence_list_and_free (deps, insn, &reg_last->sets, 0,
3281 REG_DEP_OUTPUT, false);
3282 add_dependence_list_and_free (deps, insn,
3283 &reg_last->implicit_sets,
3284 0, REG_DEP_ANTI, false);
3285 add_dependence_list_and_free (deps, insn, &reg_last->clobbers, 0,
3286 REG_DEP_OUTPUT, false);
3287 add_dependence_list_and_free (deps, insn, &reg_last->uses, 0,
3288 REG_DEP_ANTI, false);
3289 add_dependence_list (insn, reg_last->control_uses, 0,
3290 REG_DEP_CONTROL, false);
3292 if (!deps->readonly)
3294 reg_last->sets = alloc_INSN_LIST (insn, reg_last->sets);
3295 reg_last->uses_length = 0;
3296 reg_last->clobbers_length = 0;
3300 if (!deps->readonly)
3302 EXECUTE_IF_SET_IN_REG_SET (reg_pending_control_uses, 0, i, rsi)
3304 struct deps_reg *reg_last = &deps->reg_last[i];
3305 reg_last->control_uses
3306 = alloc_INSN_LIST (insn, reg_last->control_uses);
3311 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3312 if (TEST_HARD_REG_BIT (implicit_reg_pending_clobbers, i))
3314 struct deps_reg *reg_last = &deps->reg_last[i];
3315 add_dependence_list (insn, reg_last->sets, 0, REG_DEP_ANTI, false);
3316 add_dependence_list (insn, reg_last->clobbers, 0, REG_DEP_ANTI, false);
3317 add_dependence_list (insn, reg_last->uses, 0, REG_DEP_ANTI, false);
3318 add_dependence_list (insn, reg_last->control_uses, 0, REG_DEP_ANTI,
3319 false);
3321 if (!deps->readonly)
3322 reg_last->implicit_sets
3323 = alloc_INSN_LIST (insn, reg_last->implicit_sets);
3326 if (!deps->readonly)
3328 IOR_REG_SET (&deps->reg_last_in_use, reg_pending_uses);
3329 IOR_REG_SET (&deps->reg_last_in_use, reg_pending_clobbers);
3330 IOR_REG_SET (&deps->reg_last_in_use, reg_pending_sets);
3331 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3332 if (TEST_HARD_REG_BIT (implicit_reg_pending_uses, i)
3333 || TEST_HARD_REG_BIT (implicit_reg_pending_clobbers, i))
3334 SET_REGNO_REG_SET (&deps->reg_last_in_use, i);
3336 /* Set up the pending barrier found. */
3337 deps->last_reg_pending_barrier = reg_pending_barrier;
3340 CLEAR_REG_SET (reg_pending_uses);
3341 CLEAR_REG_SET (reg_pending_clobbers);
3342 CLEAR_REG_SET (reg_pending_sets);
3343 CLEAR_REG_SET (reg_pending_control_uses);
3344 CLEAR_HARD_REG_SET (implicit_reg_pending_clobbers);
3345 CLEAR_HARD_REG_SET (implicit_reg_pending_uses);
3347 /* Add dependencies if a scheduling barrier was found. */
3348 if (reg_pending_barrier)
3350 /* In the case of barrier the most added dependencies are not
3351 real, so we use anti-dependence here. */
3352 if (sched_has_condition_p (insn))
3354 EXECUTE_IF_SET_IN_REG_SET (&deps->reg_last_in_use, 0, i, rsi)
3356 struct deps_reg *reg_last = &deps->reg_last[i];
3357 add_dependence_list (insn, reg_last->uses, 0, REG_DEP_ANTI,
3358 true);
3359 add_dependence_list (insn, reg_last->sets, 0,
3360 reg_pending_barrier == TRUE_BARRIER
3361 ? REG_DEP_TRUE : REG_DEP_ANTI, true);
3362 add_dependence_list (insn, reg_last->implicit_sets, 0,
3363 REG_DEP_ANTI, true);
3364 add_dependence_list (insn, reg_last->clobbers, 0,
3365 reg_pending_barrier == TRUE_BARRIER
3366 ? REG_DEP_TRUE : REG_DEP_ANTI, true);
3369 else
3371 EXECUTE_IF_SET_IN_REG_SET (&deps->reg_last_in_use, 0, i, rsi)
3373 struct deps_reg *reg_last = &deps->reg_last[i];
3374 add_dependence_list_and_free (deps, insn, &reg_last->uses, 0,
3375 REG_DEP_ANTI, true);
3376 add_dependence_list_and_free (deps, insn,
3377 &reg_last->control_uses, 0,
3378 REG_DEP_CONTROL, true);
3379 add_dependence_list_and_free (deps, insn, &reg_last->sets, 0,
3380 reg_pending_barrier == TRUE_BARRIER
3381 ? REG_DEP_TRUE : REG_DEP_ANTI,
3382 true);
3383 add_dependence_list_and_free (deps, insn,
3384 &reg_last->implicit_sets, 0,
3385 REG_DEP_ANTI, true);
3386 add_dependence_list_and_free (deps, insn, &reg_last->clobbers, 0,
3387 reg_pending_barrier == TRUE_BARRIER
3388 ? REG_DEP_TRUE : REG_DEP_ANTI,
3389 true);
3391 if (!deps->readonly)
3393 reg_last->uses_length = 0;
3394 reg_last->clobbers_length = 0;
3399 if (!deps->readonly)
3400 for (i = 0; i < (unsigned)deps->max_reg; i++)
3402 struct deps_reg *reg_last = &deps->reg_last[i];
3403 reg_last->sets = alloc_INSN_LIST (insn, reg_last->sets);
3404 SET_REGNO_REG_SET (&deps->reg_last_in_use, i);
3407 /* Don't flush pending lists on speculative checks for
3408 selective scheduling. */
3409 if (!sel_sched_p () || !sel_insn_is_speculation_check (insn))
3410 flush_pending_lists (deps, insn, true, true);
3412 reg_pending_barrier = NOT_A_BARRIER;
3415 /* If a post-call group is still open, see if it should remain so.
3416 This insn must be a simple move of a hard reg to a pseudo or
3417 vice-versa.
3419 We must avoid moving these insns for correctness on targets
3420 with small register classes, and for special registers like
3421 PIC_OFFSET_TABLE_REGNUM. For simplicity, extend this to all
3422 hard regs for all targets. */
3424 if (deps->in_post_call_group_p)
3426 rtx tmp, set = single_set (insn);
3427 int src_regno, dest_regno;
3429 if (set == NULL)
3431 if (DEBUG_INSN_P (insn))
3432 /* We don't want to mark debug insns as part of the same
3433 sched group. We know they really aren't, but if we use
3434 debug insns to tell that a call group is over, we'll
3435 get different code if debug insns are not there and
3436 instructions that follow seem like they should be part
3437 of the call group.
3439 Also, if we did, chain_to_prev_insn would move the
3440 deps of the debug insn to the call insn, modifying
3441 non-debug post-dependency counts of the debug insn
3442 dependencies and otherwise messing with the scheduling
3443 order.
3445 Instead, let such debug insns be scheduled freely, but
3446 keep the call group open in case there are insns that
3447 should be part of it afterwards. Since we grant debug
3448 insns higher priority than even sched group insns, it
3449 will all turn out all right. */
3450 goto debug_dont_end_call_group;
3451 else
3452 goto end_call_group;
3455 tmp = SET_DEST (set);
3456 if (GET_CODE (tmp) == SUBREG)
3457 tmp = SUBREG_REG (tmp);
3458 if (REG_P (tmp))
3459 dest_regno = REGNO (tmp);
3460 else
3461 goto end_call_group;
3463 tmp = SET_SRC (set);
3464 if (GET_CODE (tmp) == SUBREG)
3465 tmp = SUBREG_REG (tmp);
3466 if ((GET_CODE (tmp) == PLUS
3467 || GET_CODE (tmp) == MINUS)
3468 && REG_P (XEXP (tmp, 0))
3469 && REGNO (XEXP (tmp, 0)) == STACK_POINTER_REGNUM
3470 && dest_regno == STACK_POINTER_REGNUM)
3471 src_regno = STACK_POINTER_REGNUM;
3472 else if (REG_P (tmp))
3473 src_regno = REGNO (tmp);
3474 else
3475 goto end_call_group;
3477 if (src_regno < FIRST_PSEUDO_REGISTER
3478 || dest_regno < FIRST_PSEUDO_REGISTER)
3480 if (!deps->readonly
3481 && deps->in_post_call_group_p == post_call_initial)
3482 deps->in_post_call_group_p = post_call;
3484 if (!sel_sched_p () || sched_emulate_haifa_p)
3486 SCHED_GROUP_P (insn) = 1;
3487 CANT_MOVE (insn) = 1;
3490 else
3492 end_call_group:
3493 if (!deps->readonly)
3494 deps->in_post_call_group_p = not_post_call;
3498 debug_dont_end_call_group:
3499 if ((current_sched_info->flags & DO_SPECULATION)
3500 && !sched_insn_is_legitimate_for_speculation_p (insn, 0))
3501 /* INSN has an internal dependency (e.g. r14 = [r14]) and thus cannot
3502 be speculated. */
3504 if (sel_sched_p ())
3505 sel_mark_hard_insn (insn);
3506 else
3508 sd_iterator_def sd_it;
3509 dep_t dep;
3511 for (sd_it = sd_iterator_start (insn, SD_LIST_SPEC_BACK);
3512 sd_iterator_cond (&sd_it, &dep);)
3513 change_spec_dep_to_hard (sd_it);
3517 /* We do not yet have code to adjust REG_ARGS_SIZE, therefore we must
3518 honor their original ordering. */
3519 if (find_reg_note (insn, REG_ARGS_SIZE, NULL))
3521 if (deps->last_args_size)
3522 add_dependence (insn, deps->last_args_size, REG_DEP_OUTPUT);
3523 deps->last_args_size = insn;
3527 /* Return TRUE if INSN might not always return normally (e.g. call exit,
3528 longjmp, loop forever, ...). */
3529 /* FIXME: Why can't this function just use flags_from_decl_or_type and
3530 test for ECF_NORETURN? */
3531 static bool
3532 call_may_noreturn_p (rtx_insn *insn)
3534 rtx call;
3536 /* const or pure calls that aren't looping will always return. */
3537 if (RTL_CONST_OR_PURE_CALL_P (insn)
3538 && !RTL_LOOPING_CONST_OR_PURE_CALL_P (insn))
3539 return false;
3541 call = get_call_rtx_from (insn);
3542 if (call && GET_CODE (XEXP (XEXP (call, 0), 0)) == SYMBOL_REF)
3544 rtx symbol = XEXP (XEXP (call, 0), 0);
3545 if (SYMBOL_REF_DECL (symbol)
3546 && TREE_CODE (SYMBOL_REF_DECL (symbol)) == FUNCTION_DECL)
3548 if (DECL_BUILT_IN_CLASS (SYMBOL_REF_DECL (symbol))
3549 == BUILT_IN_NORMAL)
3550 switch (DECL_FUNCTION_CODE (SYMBOL_REF_DECL (symbol)))
3552 case BUILT_IN_BCMP:
3553 case BUILT_IN_BCOPY:
3554 case BUILT_IN_BZERO:
3555 case BUILT_IN_INDEX:
3556 case BUILT_IN_MEMCHR:
3557 case BUILT_IN_MEMCMP:
3558 case BUILT_IN_MEMCPY:
3559 case BUILT_IN_MEMMOVE:
3560 case BUILT_IN_MEMPCPY:
3561 case BUILT_IN_MEMSET:
3562 case BUILT_IN_RINDEX:
3563 case BUILT_IN_STPCPY:
3564 case BUILT_IN_STPNCPY:
3565 case BUILT_IN_STRCAT:
3566 case BUILT_IN_STRCHR:
3567 case BUILT_IN_STRCMP:
3568 case BUILT_IN_STRCPY:
3569 case BUILT_IN_STRCSPN:
3570 case BUILT_IN_STRLEN:
3571 case BUILT_IN_STRNCAT:
3572 case BUILT_IN_STRNCMP:
3573 case BUILT_IN_STRNCPY:
3574 case BUILT_IN_STRPBRK:
3575 case BUILT_IN_STRRCHR:
3576 case BUILT_IN_STRSPN:
3577 case BUILT_IN_STRSTR:
3578 /* Assume certain string/memory builtins always return. */
3579 return false;
3580 default:
3581 break;
3586 /* For all other calls assume that they might not always return. */
3587 return true;
3590 /* Return true if INSN should be made dependent on the previous instruction
3591 group, and if all INSN's dependencies should be moved to the first
3592 instruction of that group. */
3594 static bool
3595 chain_to_prev_insn_p (rtx_insn *insn)
3597 rtx prev, x;
3599 /* INSN forms a group with the previous instruction. */
3600 if (SCHED_GROUP_P (insn))
3601 return true;
3603 /* If the previous instruction clobbers a register R and this one sets
3604 part of R, the clobber was added specifically to help us track the
3605 liveness of R. There's no point scheduling the clobber and leaving
3606 INSN behind, especially if we move the clobber to another block. */
3607 prev = prev_nonnote_nondebug_insn (insn);
3608 if (prev
3609 && INSN_P (prev)
3610 && BLOCK_FOR_INSN (prev) == BLOCK_FOR_INSN (insn)
3611 && GET_CODE (PATTERN (prev)) == CLOBBER)
3613 x = XEXP (PATTERN (prev), 0);
3614 if (set_of (x, insn))
3615 return true;
3618 return false;
3621 /* Analyze INSN with DEPS as a context. */
3622 void
3623 deps_analyze_insn (struct deps_desc *deps, rtx_insn *insn)
3625 if (sched_deps_info->start_insn)
3626 sched_deps_info->start_insn (insn);
3628 /* Record the condition for this insn. */
3629 if (NONDEBUG_INSN_P (insn))
3631 rtx t;
3632 sched_get_condition_with_rev (insn, NULL);
3633 t = INSN_CACHED_COND (insn);
3634 INSN_COND_DEPS (insn) = NULL;
3635 if (reload_completed
3636 && (current_sched_info->flags & DO_PREDICATION)
3637 && COMPARISON_P (t)
3638 && REG_P (XEXP (t, 0))
3639 && CONSTANT_P (XEXP (t, 1)))
3641 unsigned int regno;
3642 int nregs;
3643 rtx_insn_list *cond_deps = NULL;
3644 t = XEXP (t, 0);
3645 regno = REGNO (t);
3646 nregs = REG_NREGS (t);
3647 while (nregs-- > 0)
3649 struct deps_reg *reg_last = &deps->reg_last[regno + nregs];
3650 cond_deps = concat_INSN_LIST (reg_last->sets, cond_deps);
3651 cond_deps = concat_INSN_LIST (reg_last->clobbers, cond_deps);
3652 cond_deps = concat_INSN_LIST (reg_last->implicit_sets, cond_deps);
3654 INSN_COND_DEPS (insn) = cond_deps;
3658 if (JUMP_P (insn))
3660 /* Make each JUMP_INSN (but not a speculative check)
3661 a scheduling barrier for memory references. */
3662 if (!deps->readonly
3663 && !(sel_sched_p ()
3664 && sel_insn_is_speculation_check (insn)))
3666 /* Keep the list a reasonable size. */
3667 if (deps->pending_flush_length++ >= MAX_PENDING_LIST_LENGTH)
3668 flush_pending_lists (deps, insn, true, true);
3669 else
3670 deps->pending_jump_insns
3671 = alloc_INSN_LIST (insn, deps->pending_jump_insns);
3674 /* For each insn which shouldn't cross a jump, add a dependence. */
3675 add_dependence_list_and_free (deps, insn,
3676 &deps->sched_before_next_jump, 1,
3677 REG_DEP_ANTI, true);
3679 sched_analyze_insn (deps, PATTERN (insn), insn);
3681 else if (NONJUMP_INSN_P (insn) || DEBUG_INSN_P (insn))
3683 sched_analyze_insn (deps, PATTERN (insn), insn);
3685 else if (CALL_P (insn))
3687 int i;
3689 CANT_MOVE (insn) = 1;
3691 if (find_reg_note (insn, REG_SETJMP, NULL))
3693 /* This is setjmp. Assume that all registers, not just
3694 hard registers, may be clobbered by this call. */
3695 reg_pending_barrier = MOVE_BARRIER;
3697 else
3699 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3700 /* A call may read and modify global register variables. */
3701 if (global_regs[i])
3703 SET_REGNO_REG_SET (reg_pending_sets, i);
3704 SET_HARD_REG_BIT (implicit_reg_pending_uses, i);
3706 /* Other call-clobbered hard regs may be clobbered.
3707 Since we only have a choice between 'might be clobbered'
3708 and 'definitely not clobbered', we must include all
3709 partly call-clobbered registers here. */
3710 else if (HARD_REGNO_CALL_PART_CLOBBERED (i, reg_raw_mode[i])
3711 || TEST_HARD_REG_BIT (regs_invalidated_by_call, i))
3712 SET_REGNO_REG_SET (reg_pending_clobbers, i);
3713 /* We don't know what set of fixed registers might be used
3714 by the function, but it is certain that the stack pointer
3715 is among them, but be conservative. */
3716 else if (fixed_regs[i])
3717 SET_HARD_REG_BIT (implicit_reg_pending_uses, i);
3718 /* The frame pointer is normally not used by the function
3719 itself, but by the debugger. */
3720 /* ??? MIPS o32 is an exception. It uses the frame pointer
3721 in the macro expansion of jal but does not represent this
3722 fact in the call_insn rtl. */
3723 else if (i == FRAME_POINTER_REGNUM
3724 || (i == HARD_FRAME_POINTER_REGNUM
3725 && (! reload_completed || frame_pointer_needed)))
3726 SET_HARD_REG_BIT (implicit_reg_pending_uses, i);
3729 /* For each insn which shouldn't cross a call, add a dependence
3730 between that insn and this call insn. */
3731 add_dependence_list_and_free (deps, insn,
3732 &deps->sched_before_next_call, 1,
3733 REG_DEP_ANTI, true);
3735 sched_analyze_insn (deps, PATTERN (insn), insn);
3737 /* If CALL would be in a sched group, then this will violate
3738 convention that sched group insns have dependencies only on the
3739 previous instruction.
3741 Of course one can say: "Hey! What about head of the sched group?"
3742 And I will answer: "Basic principles (one dep per insn) are always
3743 the same." */
3744 gcc_assert (!SCHED_GROUP_P (insn));
3746 /* In the absence of interprocedural alias analysis, we must flush
3747 all pending reads and writes, and start new dependencies starting
3748 from here. But only flush writes for constant calls (which may
3749 be passed a pointer to something we haven't written yet). */
3750 flush_pending_lists (deps, insn, true, ! RTL_CONST_OR_PURE_CALL_P (insn));
3752 if (!deps->readonly)
3754 /* Remember the last function call for limiting lifetimes. */
3755 free_INSN_LIST_list (&deps->last_function_call);
3756 deps->last_function_call = alloc_INSN_LIST (insn, NULL_RTX);
3758 if (call_may_noreturn_p (insn))
3760 /* Remember the last function call that might not always return
3761 normally for limiting moves of trapping insns. */
3762 free_INSN_LIST_list (&deps->last_function_call_may_noreturn);
3763 deps->last_function_call_may_noreturn
3764 = alloc_INSN_LIST (insn, NULL_RTX);
3767 /* Before reload, begin a post-call group, so as to keep the
3768 lifetimes of hard registers correct. */
3769 if (! reload_completed)
3770 deps->in_post_call_group_p = post_call;
3774 if (sched_deps_info->use_cselib)
3775 cselib_process_insn (insn);
3777 if (sched_deps_info->finish_insn)
3778 sched_deps_info->finish_insn ();
3780 /* Fixup the dependencies in the sched group. */
3781 if ((NONJUMP_INSN_P (insn) || JUMP_P (insn))
3782 && chain_to_prev_insn_p (insn)
3783 && !sel_sched_p ())
3784 chain_to_prev_insn (insn);
3787 /* Initialize DEPS for the new block beginning with HEAD. */
3788 void
3789 deps_start_bb (struct deps_desc *deps, rtx_insn *head)
3791 gcc_assert (!deps->readonly);
3793 /* Before reload, if the previous block ended in a call, show that
3794 we are inside a post-call group, so as to keep the lifetimes of
3795 hard registers correct. */
3796 if (! reload_completed && !LABEL_P (head))
3798 rtx_insn *insn = prev_nonnote_nondebug_insn (head);
3800 if (insn && CALL_P (insn))
3801 deps->in_post_call_group_p = post_call_initial;
3805 /* Analyze every insn between HEAD and TAIL inclusive, creating backward
3806 dependencies for each insn. */
3807 void
3808 sched_analyze (struct deps_desc *deps, rtx_insn *head, rtx_insn *tail)
3810 rtx_insn *insn;
3812 if (sched_deps_info->use_cselib)
3813 cselib_init (CSELIB_RECORD_MEMORY);
3815 deps_start_bb (deps, head);
3817 for (insn = head;; insn = NEXT_INSN (insn))
3820 if (INSN_P (insn))
3822 /* And initialize deps_lists. */
3823 sd_init_insn (insn);
3824 /* Clean up SCHED_GROUP_P which may be set by last
3825 scheduler pass. */
3826 if (SCHED_GROUP_P (insn))
3827 SCHED_GROUP_P (insn) = 0;
3830 deps_analyze_insn (deps, insn);
3832 if (insn == tail)
3834 if (sched_deps_info->use_cselib)
3835 cselib_finish ();
3836 return;
3839 gcc_unreachable ();
3842 /* Helper for sched_free_deps ().
3843 Delete INSN's (RESOLVED_P) backward dependencies. */
3844 static void
3845 delete_dep_nodes_in_back_deps (rtx_insn *insn, bool resolved_p)
3847 sd_iterator_def sd_it;
3848 dep_t dep;
3849 sd_list_types_def types;
3851 if (resolved_p)
3852 types = SD_LIST_RES_BACK;
3853 else
3854 types = SD_LIST_BACK;
3856 for (sd_it = sd_iterator_start (insn, types);
3857 sd_iterator_cond (&sd_it, &dep);)
3859 dep_link_t link = *sd_it.linkp;
3860 dep_node_t node = DEP_LINK_NODE (link);
3861 deps_list_t back_list;
3862 deps_list_t forw_list;
3864 get_back_and_forw_lists (dep, resolved_p, &back_list, &forw_list);
3865 remove_from_deps_list (link, back_list);
3866 delete_dep_node (node);
3870 /* Delete (RESOLVED_P) dependencies between HEAD and TAIL together with
3871 deps_lists. */
3872 void
3873 sched_free_deps (rtx_insn *head, rtx_insn *tail, bool resolved_p)
3875 rtx_insn *insn;
3876 rtx_insn *next_tail = NEXT_INSN (tail);
3878 /* We make two passes since some insns may be scheduled before their
3879 dependencies are resolved. */
3880 for (insn = head; insn != next_tail; insn = NEXT_INSN (insn))
3881 if (INSN_P (insn) && INSN_LUID (insn) > 0)
3883 /* Clear forward deps and leave the dep_nodes to the
3884 corresponding back_deps list. */
3885 if (resolved_p)
3886 clear_deps_list (INSN_RESOLVED_FORW_DEPS (insn));
3887 else
3888 clear_deps_list (INSN_FORW_DEPS (insn));
3890 for (insn = head; insn != next_tail; insn = NEXT_INSN (insn))
3891 if (INSN_P (insn) && INSN_LUID (insn) > 0)
3893 /* Clear resolved back deps together with its dep_nodes. */
3894 delete_dep_nodes_in_back_deps (insn, resolved_p);
3896 sd_finish_insn (insn);
3900 /* Initialize variables for region data dependence analysis.
3901 When LAZY_REG_LAST is true, do not allocate reg_last array
3902 of struct deps_desc immediately. */
3904 void
3905 init_deps (struct deps_desc *deps, bool lazy_reg_last)
3907 int max_reg = (reload_completed ? FIRST_PSEUDO_REGISTER : max_reg_num ());
3909 deps->max_reg = max_reg;
3910 if (lazy_reg_last)
3911 deps->reg_last = NULL;
3912 else
3913 deps->reg_last = XCNEWVEC (struct deps_reg, max_reg);
3914 INIT_REG_SET (&deps->reg_last_in_use);
3916 deps->pending_read_insns = 0;
3917 deps->pending_read_mems = 0;
3918 deps->pending_write_insns = 0;
3919 deps->pending_write_mems = 0;
3920 deps->pending_jump_insns = 0;
3921 deps->pending_read_list_length = 0;
3922 deps->pending_write_list_length = 0;
3923 deps->pending_flush_length = 0;
3924 deps->last_pending_memory_flush = 0;
3925 deps->last_function_call = 0;
3926 deps->last_function_call_may_noreturn = 0;
3927 deps->sched_before_next_call = 0;
3928 deps->sched_before_next_jump = 0;
3929 deps->in_post_call_group_p = not_post_call;
3930 deps->last_debug_insn = 0;
3931 deps->last_args_size = 0;
3932 deps->last_reg_pending_barrier = NOT_A_BARRIER;
3933 deps->readonly = 0;
3936 /* Init only reg_last field of DEPS, which was not allocated before as
3937 we inited DEPS lazily. */
3938 void
3939 init_deps_reg_last (struct deps_desc *deps)
3941 gcc_assert (deps && deps->max_reg > 0);
3942 gcc_assert (deps->reg_last == NULL);
3944 deps->reg_last = XCNEWVEC (struct deps_reg, deps->max_reg);
3948 /* Free insn lists found in DEPS. */
3950 void
3951 free_deps (struct deps_desc *deps)
3953 unsigned i;
3954 reg_set_iterator rsi;
3956 /* We set max_reg to 0 when this context was already freed. */
3957 if (deps->max_reg == 0)
3959 gcc_assert (deps->reg_last == NULL);
3960 return;
3962 deps->max_reg = 0;
3964 free_INSN_LIST_list (&deps->pending_read_insns);
3965 free_EXPR_LIST_list (&deps->pending_read_mems);
3966 free_INSN_LIST_list (&deps->pending_write_insns);
3967 free_EXPR_LIST_list (&deps->pending_write_mems);
3968 free_INSN_LIST_list (&deps->last_pending_memory_flush);
3970 /* Without the EXECUTE_IF_SET, this loop is executed max_reg * nr_regions
3971 times. For a testcase with 42000 regs and 8000 small basic blocks,
3972 this loop accounted for nearly 60% (84 sec) of the total -O2 runtime. */
3973 EXECUTE_IF_SET_IN_REG_SET (&deps->reg_last_in_use, 0, i, rsi)
3975 struct deps_reg *reg_last = &deps->reg_last[i];
3976 if (reg_last->uses)
3977 free_INSN_LIST_list (&reg_last->uses);
3978 if (reg_last->sets)
3979 free_INSN_LIST_list (&reg_last->sets);
3980 if (reg_last->implicit_sets)
3981 free_INSN_LIST_list (&reg_last->implicit_sets);
3982 if (reg_last->control_uses)
3983 free_INSN_LIST_list (&reg_last->control_uses);
3984 if (reg_last->clobbers)
3985 free_INSN_LIST_list (&reg_last->clobbers);
3987 CLEAR_REG_SET (&deps->reg_last_in_use);
3989 /* As we initialize reg_last lazily, it is possible that we didn't allocate
3990 it at all. */
3991 free (deps->reg_last);
3992 deps->reg_last = NULL;
3994 deps = NULL;
3997 /* Remove INSN from dependence contexts DEPS. */
3998 void
3999 remove_from_deps (struct deps_desc *deps, rtx_insn *insn)
4001 int removed;
4002 unsigned i;
4003 reg_set_iterator rsi;
4005 removed = remove_from_both_dependence_lists (insn, &deps->pending_read_insns,
4006 &deps->pending_read_mems);
4007 if (!DEBUG_INSN_P (insn))
4008 deps->pending_read_list_length -= removed;
4009 removed = remove_from_both_dependence_lists (insn, &deps->pending_write_insns,
4010 &deps->pending_write_mems);
4011 deps->pending_write_list_length -= removed;
4013 removed = remove_from_dependence_list (insn, &deps->pending_jump_insns);
4014 deps->pending_flush_length -= removed;
4015 removed = remove_from_dependence_list (insn, &deps->last_pending_memory_flush);
4016 deps->pending_flush_length -= removed;
4018 EXECUTE_IF_SET_IN_REG_SET (&deps->reg_last_in_use, 0, i, rsi)
4020 struct deps_reg *reg_last = &deps->reg_last[i];
4021 if (reg_last->uses)
4022 remove_from_dependence_list (insn, &reg_last->uses);
4023 if (reg_last->sets)
4024 remove_from_dependence_list (insn, &reg_last->sets);
4025 if (reg_last->implicit_sets)
4026 remove_from_dependence_list (insn, &reg_last->implicit_sets);
4027 if (reg_last->clobbers)
4028 remove_from_dependence_list (insn, &reg_last->clobbers);
4029 if (!reg_last->uses && !reg_last->sets && !reg_last->implicit_sets
4030 && !reg_last->clobbers)
4031 CLEAR_REGNO_REG_SET (&deps->reg_last_in_use, i);
4034 if (CALL_P (insn))
4036 remove_from_dependence_list (insn, &deps->last_function_call);
4037 remove_from_dependence_list (insn,
4038 &deps->last_function_call_may_noreturn);
4040 remove_from_dependence_list (insn, &deps->sched_before_next_call);
4043 /* Init deps data vector. */
4044 static void
4045 init_deps_data_vector (void)
4047 int reserve = (sched_max_luid + 1 - h_d_i_d.length ());
4048 if (reserve > 0 && ! h_d_i_d.space (reserve))
4049 h_d_i_d.safe_grow_cleared (3 * sched_max_luid / 2);
4052 /* If it is profitable to use them, initialize or extend (depending on
4053 GLOBAL_P) dependency data. */
4054 void
4055 sched_deps_init (bool global_p)
4057 /* Average number of insns in the basic block.
4058 '+ 1' is used to make it nonzero. */
4059 int insns_in_block = sched_max_luid / n_basic_blocks_for_fn (cfun) + 1;
4061 init_deps_data_vector ();
4063 /* We use another caching mechanism for selective scheduling, so
4064 we don't use this one. */
4065 if (!sel_sched_p () && global_p && insns_in_block > 100 * 5)
4067 /* ?!? We could save some memory by computing a per-region luid mapping
4068 which could reduce both the number of vectors in the cache and the
4069 size of each vector. Instead we just avoid the cache entirely unless
4070 the average number of instructions in a basic block is very high. See
4071 the comment before the declaration of true_dependency_cache for
4072 what we consider "very high". */
4073 cache_size = 0;
4074 extend_dependency_caches (sched_max_luid, true);
4077 if (global_p)
4079 dl_pool = new pool_allocator<_deps_list> ("deps_list",
4080 /* Allocate lists for one block at a time. */
4081 insns_in_block);
4082 dn_pool = new pool_allocator<_dep_node> ("dep_node",
4083 /* Allocate nodes for one block at a time.
4084 We assume that average insn has
4085 5 producers. */
4086 5 * insns_in_block);
4091 /* Create or extend (depending on CREATE_P) dependency caches to
4092 size N. */
4093 void
4094 extend_dependency_caches (int n, bool create_p)
4096 if (create_p || true_dependency_cache)
4098 int i, luid = cache_size + n;
4100 true_dependency_cache = XRESIZEVEC (bitmap_head, true_dependency_cache,
4101 luid);
4102 output_dependency_cache = XRESIZEVEC (bitmap_head,
4103 output_dependency_cache, luid);
4104 anti_dependency_cache = XRESIZEVEC (bitmap_head, anti_dependency_cache,
4105 luid);
4106 control_dependency_cache = XRESIZEVEC (bitmap_head, control_dependency_cache,
4107 luid);
4109 if (current_sched_info->flags & DO_SPECULATION)
4110 spec_dependency_cache = XRESIZEVEC (bitmap_head, spec_dependency_cache,
4111 luid);
4113 for (i = cache_size; i < luid; i++)
4115 bitmap_initialize (&true_dependency_cache[i], 0);
4116 bitmap_initialize (&output_dependency_cache[i], 0);
4117 bitmap_initialize (&anti_dependency_cache[i], 0);
4118 bitmap_initialize (&control_dependency_cache[i], 0);
4120 if (current_sched_info->flags & DO_SPECULATION)
4121 bitmap_initialize (&spec_dependency_cache[i], 0);
4123 cache_size = luid;
4127 /* Finalize dependency information for the whole function. */
4128 void
4129 sched_deps_finish (void)
4131 gcc_assert (deps_pools_are_empty_p ());
4132 dn_pool->release_if_empty ();
4133 dn_pool = NULL;
4134 dl_pool->release_if_empty ();
4135 dl_pool = NULL;
4137 h_d_i_d.release ();
4138 cache_size = 0;
4140 if (true_dependency_cache)
4142 int i;
4144 for (i = 0; i < cache_size; i++)
4146 bitmap_clear (&true_dependency_cache[i]);
4147 bitmap_clear (&output_dependency_cache[i]);
4148 bitmap_clear (&anti_dependency_cache[i]);
4149 bitmap_clear (&control_dependency_cache[i]);
4151 if (sched_deps_info->generate_spec_deps)
4152 bitmap_clear (&spec_dependency_cache[i]);
4154 free (true_dependency_cache);
4155 true_dependency_cache = NULL;
4156 free (output_dependency_cache);
4157 output_dependency_cache = NULL;
4158 free (anti_dependency_cache);
4159 anti_dependency_cache = NULL;
4160 free (control_dependency_cache);
4161 control_dependency_cache = NULL;
4163 if (sched_deps_info->generate_spec_deps)
4165 free (spec_dependency_cache);
4166 spec_dependency_cache = NULL;
4172 /* Initialize some global variables needed by the dependency analysis
4173 code. */
4175 void
4176 init_deps_global (void)
4178 CLEAR_HARD_REG_SET (implicit_reg_pending_clobbers);
4179 CLEAR_HARD_REG_SET (implicit_reg_pending_uses);
4180 reg_pending_sets = ALLOC_REG_SET (&reg_obstack);
4181 reg_pending_clobbers = ALLOC_REG_SET (&reg_obstack);
4182 reg_pending_uses = ALLOC_REG_SET (&reg_obstack);
4183 reg_pending_control_uses = ALLOC_REG_SET (&reg_obstack);
4184 reg_pending_barrier = NOT_A_BARRIER;
4186 if (!sel_sched_p () || sched_emulate_haifa_p)
4188 sched_deps_info->start_insn = haifa_start_insn;
4189 sched_deps_info->finish_insn = haifa_finish_insn;
4191 sched_deps_info->note_reg_set = haifa_note_reg_set;
4192 sched_deps_info->note_reg_clobber = haifa_note_reg_clobber;
4193 sched_deps_info->note_reg_use = haifa_note_reg_use;
4195 sched_deps_info->note_mem_dep = haifa_note_mem_dep;
4196 sched_deps_info->note_dep = haifa_note_dep;
4200 /* Free everything used by the dependency analysis code. */
4202 void
4203 finish_deps_global (void)
4205 FREE_REG_SET (reg_pending_sets);
4206 FREE_REG_SET (reg_pending_clobbers);
4207 FREE_REG_SET (reg_pending_uses);
4208 FREE_REG_SET (reg_pending_control_uses);
4211 /* Estimate the weakness of dependence between MEM1 and MEM2. */
4212 dw_t
4213 estimate_dep_weak (rtx mem1, rtx mem2)
4215 rtx r1, r2;
4217 if (mem1 == mem2)
4218 /* MEMs are the same - don't speculate. */
4219 return MIN_DEP_WEAK;
4221 r1 = XEXP (mem1, 0);
4222 r2 = XEXP (mem2, 0);
4224 if (r1 == r2
4225 || (REG_P (r1) && REG_P (r2)
4226 && REGNO (r1) == REGNO (r2)))
4227 /* Again, MEMs are the same. */
4228 return MIN_DEP_WEAK;
4229 else if ((REG_P (r1) && !REG_P (r2))
4230 || (!REG_P (r1) && REG_P (r2)))
4231 /* Different addressing modes - reason to be more speculative,
4232 than usual. */
4233 return NO_DEP_WEAK - (NO_DEP_WEAK - UNCERTAIN_DEP_WEAK) / 2;
4234 else
4235 /* We can't say anything about the dependence. */
4236 return UNCERTAIN_DEP_WEAK;
4239 /* Add or update backward dependence between INSN and ELEM with type DEP_TYPE.
4240 This function can handle same INSN and ELEM (INSN == ELEM).
4241 It is a convenience wrapper. */
4242 static void
4243 add_dependence_1 (rtx_insn *insn, rtx_insn *elem, enum reg_note dep_type)
4245 ds_t ds;
4246 bool internal;
4248 if (dep_type == REG_DEP_TRUE)
4249 ds = DEP_TRUE;
4250 else if (dep_type == REG_DEP_OUTPUT)
4251 ds = DEP_OUTPUT;
4252 else if (dep_type == REG_DEP_CONTROL)
4253 ds = DEP_CONTROL;
4254 else
4256 gcc_assert (dep_type == REG_DEP_ANTI);
4257 ds = DEP_ANTI;
4260 /* When add_dependence is called from inside sched-deps.c, we expect
4261 cur_insn to be non-null. */
4262 internal = cur_insn != NULL;
4263 if (internal)
4264 gcc_assert (insn == cur_insn);
4265 else
4266 cur_insn = insn;
4268 note_dep (elem, ds);
4269 if (!internal)
4270 cur_insn = NULL;
4273 /* Return weakness of speculative type TYPE in the dep_status DS,
4274 without checking to prevent ICEs on malformed input. */
4275 static dw_t
4276 get_dep_weak_1 (ds_t ds, ds_t type)
4278 ds = ds & type;
4280 switch (type)
4282 case BEGIN_DATA: ds >>= BEGIN_DATA_BITS_OFFSET; break;
4283 case BE_IN_DATA: ds >>= BE_IN_DATA_BITS_OFFSET; break;
4284 case BEGIN_CONTROL: ds >>= BEGIN_CONTROL_BITS_OFFSET; break;
4285 case BE_IN_CONTROL: ds >>= BE_IN_CONTROL_BITS_OFFSET; break;
4286 default: gcc_unreachable ();
4289 return (dw_t) ds;
4292 /* Return weakness of speculative type TYPE in the dep_status DS. */
4293 dw_t
4294 get_dep_weak (ds_t ds, ds_t type)
4296 dw_t dw = get_dep_weak_1 (ds, type);
4298 gcc_assert (MIN_DEP_WEAK <= dw && dw <= MAX_DEP_WEAK);
4299 return dw;
4302 /* Return the dep_status, which has the same parameters as DS, except for
4303 speculative type TYPE, that will have weakness DW. */
4304 ds_t
4305 set_dep_weak (ds_t ds, ds_t type, dw_t dw)
4307 gcc_assert (MIN_DEP_WEAK <= dw && dw <= MAX_DEP_WEAK);
4309 ds &= ~type;
4310 switch (type)
4312 case BEGIN_DATA: ds |= ((ds_t) dw) << BEGIN_DATA_BITS_OFFSET; break;
4313 case BE_IN_DATA: ds |= ((ds_t) dw) << BE_IN_DATA_BITS_OFFSET; break;
4314 case BEGIN_CONTROL: ds |= ((ds_t) dw) << BEGIN_CONTROL_BITS_OFFSET; break;
4315 case BE_IN_CONTROL: ds |= ((ds_t) dw) << BE_IN_CONTROL_BITS_OFFSET; break;
4316 default: gcc_unreachable ();
4318 return ds;
4321 /* Return the join of two dep_statuses DS1 and DS2.
4322 If MAX_P is true then choose the greater probability,
4323 otherwise multiply probabilities.
4324 This function assumes that both DS1 and DS2 contain speculative bits. */
4325 static ds_t
4326 ds_merge_1 (ds_t ds1, ds_t ds2, bool max_p)
4328 ds_t ds, t;
4330 gcc_assert ((ds1 & SPECULATIVE) && (ds2 & SPECULATIVE));
4332 ds = (ds1 & DEP_TYPES) | (ds2 & DEP_TYPES);
4334 t = FIRST_SPEC_TYPE;
4337 if ((ds1 & t) && !(ds2 & t))
4338 ds |= ds1 & t;
4339 else if (!(ds1 & t) && (ds2 & t))
4340 ds |= ds2 & t;
4341 else if ((ds1 & t) && (ds2 & t))
4343 dw_t dw1 = get_dep_weak (ds1, t);
4344 dw_t dw2 = get_dep_weak (ds2, t);
4345 ds_t dw;
4347 if (!max_p)
4349 dw = ((ds_t) dw1) * ((ds_t) dw2);
4350 dw /= MAX_DEP_WEAK;
4351 if (dw < MIN_DEP_WEAK)
4352 dw = MIN_DEP_WEAK;
4354 else
4356 if (dw1 >= dw2)
4357 dw = dw1;
4358 else
4359 dw = dw2;
4362 ds = set_dep_weak (ds, t, (dw_t) dw);
4365 if (t == LAST_SPEC_TYPE)
4366 break;
4367 t <<= SPEC_TYPE_SHIFT;
4369 while (1);
4371 return ds;
4374 /* Return the join of two dep_statuses DS1 and DS2.
4375 This function assumes that both DS1 and DS2 contain speculative bits. */
4376 ds_t
4377 ds_merge (ds_t ds1, ds_t ds2)
4379 return ds_merge_1 (ds1, ds2, false);
4382 /* Return the join of two dep_statuses DS1 and DS2. */
4383 ds_t
4384 ds_full_merge (ds_t ds, ds_t ds2, rtx mem1, rtx mem2)
4386 ds_t new_status = ds | ds2;
4388 if (new_status & SPECULATIVE)
4390 if ((ds && !(ds & SPECULATIVE))
4391 || (ds2 && !(ds2 & SPECULATIVE)))
4392 /* Then this dep can't be speculative. */
4393 new_status &= ~SPECULATIVE;
4394 else
4396 /* Both are speculative. Merging probabilities. */
4397 if (mem1)
4399 dw_t dw;
4401 dw = estimate_dep_weak (mem1, mem2);
4402 ds = set_dep_weak (ds, BEGIN_DATA, dw);
4405 if (!ds)
4406 new_status = ds2;
4407 else if (!ds2)
4408 new_status = ds;
4409 else
4410 new_status = ds_merge (ds2, ds);
4414 return new_status;
4417 /* Return the join of DS1 and DS2. Use maximum instead of multiplying
4418 probabilities. */
4419 ds_t
4420 ds_max_merge (ds_t ds1, ds_t ds2)
4422 if (ds1 == 0 && ds2 == 0)
4423 return 0;
4425 if (ds1 == 0 && ds2 != 0)
4426 return ds2;
4428 if (ds1 != 0 && ds2 == 0)
4429 return ds1;
4431 return ds_merge_1 (ds1, ds2, true);
4434 /* Return the probability of speculation success for the speculation
4435 status DS. */
4436 dw_t
4437 ds_weak (ds_t ds)
4439 ds_t res = 1, dt;
4440 int n = 0;
4442 dt = FIRST_SPEC_TYPE;
4445 if (ds & dt)
4447 res *= (ds_t) get_dep_weak (ds, dt);
4448 n++;
4451 if (dt == LAST_SPEC_TYPE)
4452 break;
4453 dt <<= SPEC_TYPE_SHIFT;
4455 while (1);
4457 gcc_assert (n);
4458 while (--n)
4459 res /= MAX_DEP_WEAK;
4461 if (res < MIN_DEP_WEAK)
4462 res = MIN_DEP_WEAK;
4464 gcc_assert (res <= MAX_DEP_WEAK);
4466 return (dw_t) res;
4469 /* Return a dep status that contains all speculation types of DS. */
4470 ds_t
4471 ds_get_speculation_types (ds_t ds)
4473 if (ds & BEGIN_DATA)
4474 ds |= BEGIN_DATA;
4475 if (ds & BE_IN_DATA)
4476 ds |= BE_IN_DATA;
4477 if (ds & BEGIN_CONTROL)
4478 ds |= BEGIN_CONTROL;
4479 if (ds & BE_IN_CONTROL)
4480 ds |= BE_IN_CONTROL;
4482 return ds & SPECULATIVE;
4485 /* Return a dep status that contains maximal weakness for each speculation
4486 type present in DS. */
4487 ds_t
4488 ds_get_max_dep_weak (ds_t ds)
4490 if (ds & BEGIN_DATA)
4491 ds = set_dep_weak (ds, BEGIN_DATA, MAX_DEP_WEAK);
4492 if (ds & BE_IN_DATA)
4493 ds = set_dep_weak (ds, BE_IN_DATA, MAX_DEP_WEAK);
4494 if (ds & BEGIN_CONTROL)
4495 ds = set_dep_weak (ds, BEGIN_CONTROL, MAX_DEP_WEAK);
4496 if (ds & BE_IN_CONTROL)
4497 ds = set_dep_weak (ds, BE_IN_CONTROL, MAX_DEP_WEAK);
4499 return ds;
4502 /* Dump information about the dependence status S. */
4503 static void
4504 dump_ds (FILE *f, ds_t s)
4506 fprintf (f, "{");
4508 if (s & BEGIN_DATA)
4509 fprintf (f, "BEGIN_DATA: %d; ", get_dep_weak_1 (s, BEGIN_DATA));
4510 if (s & BE_IN_DATA)
4511 fprintf (f, "BE_IN_DATA: %d; ", get_dep_weak_1 (s, BE_IN_DATA));
4512 if (s & BEGIN_CONTROL)
4513 fprintf (f, "BEGIN_CONTROL: %d; ", get_dep_weak_1 (s, BEGIN_CONTROL));
4514 if (s & BE_IN_CONTROL)
4515 fprintf (f, "BE_IN_CONTROL: %d; ", get_dep_weak_1 (s, BE_IN_CONTROL));
4517 if (s & HARD_DEP)
4518 fprintf (f, "HARD_DEP; ");
4520 if (s & DEP_TRUE)
4521 fprintf (f, "DEP_TRUE; ");
4522 if (s & DEP_OUTPUT)
4523 fprintf (f, "DEP_OUTPUT; ");
4524 if (s & DEP_ANTI)
4525 fprintf (f, "DEP_ANTI; ");
4526 if (s & DEP_CONTROL)
4527 fprintf (f, "DEP_CONTROL; ");
4529 fprintf (f, "}");
4532 DEBUG_FUNCTION void
4533 debug_ds (ds_t s)
4535 dump_ds (stderr, s);
4536 fprintf (stderr, "\n");
4539 #ifdef ENABLE_CHECKING
4540 /* Verify that dependence type and status are consistent.
4541 If RELAXED_P is true, then skip dep_weakness checks. */
4542 static void
4543 check_dep (dep_t dep, bool relaxed_p)
4545 enum reg_note dt = DEP_TYPE (dep);
4546 ds_t ds = DEP_STATUS (dep);
4548 gcc_assert (DEP_PRO (dep) != DEP_CON (dep));
4550 if (!(current_sched_info->flags & USE_DEPS_LIST))
4552 gcc_assert (ds == 0);
4553 return;
4556 /* Check that dependence type contains the same bits as the status. */
4557 if (dt == REG_DEP_TRUE)
4558 gcc_assert (ds & DEP_TRUE);
4559 else if (dt == REG_DEP_OUTPUT)
4560 gcc_assert ((ds & DEP_OUTPUT)
4561 && !(ds & DEP_TRUE));
4562 else if (dt == REG_DEP_ANTI)
4563 gcc_assert ((ds & DEP_ANTI)
4564 && !(ds & (DEP_OUTPUT | DEP_TRUE)));
4565 else
4566 gcc_assert (dt == REG_DEP_CONTROL
4567 && (ds & DEP_CONTROL)
4568 && !(ds & (DEP_OUTPUT | DEP_ANTI | DEP_TRUE)));
4570 /* HARD_DEP can not appear in dep_status of a link. */
4571 gcc_assert (!(ds & HARD_DEP));
4573 /* Check that dependence status is set correctly when speculation is not
4574 supported. */
4575 if (!sched_deps_info->generate_spec_deps)
4576 gcc_assert (!(ds & SPECULATIVE));
4577 else if (ds & SPECULATIVE)
4579 if (!relaxed_p)
4581 ds_t type = FIRST_SPEC_TYPE;
4583 /* Check that dependence weakness is in proper range. */
4586 if (ds & type)
4587 get_dep_weak (ds, type);
4589 if (type == LAST_SPEC_TYPE)
4590 break;
4591 type <<= SPEC_TYPE_SHIFT;
4593 while (1);
4596 if (ds & BEGIN_SPEC)
4598 /* Only true dependence can be data speculative. */
4599 if (ds & BEGIN_DATA)
4600 gcc_assert (ds & DEP_TRUE);
4602 /* Control dependencies in the insn scheduler are represented by
4603 anti-dependencies, therefore only anti dependence can be
4604 control speculative. */
4605 if (ds & BEGIN_CONTROL)
4606 gcc_assert (ds & DEP_ANTI);
4608 else
4610 /* Subsequent speculations should resolve true dependencies. */
4611 gcc_assert ((ds & DEP_TYPES) == DEP_TRUE);
4614 /* Check that true and anti dependencies can't have other speculative
4615 statuses. */
4616 if (ds & DEP_TRUE)
4617 gcc_assert (ds & (BEGIN_DATA | BE_IN_SPEC));
4618 /* An output dependence can't be speculative at all. */
4619 gcc_assert (!(ds & DEP_OUTPUT));
4620 if (ds & DEP_ANTI)
4621 gcc_assert (ds & BEGIN_CONTROL);
4624 #endif /* ENABLE_CHECKING */
4626 /* The following code discovers opportunities to switch a memory reference
4627 and an increment by modifying the address. We ensure that this is done
4628 only for dependencies that are only used to show a single register
4629 dependence (using DEP_NONREG and DEP_MULTIPLE), and so that every memory
4630 instruction involved is subject to only one dep that can cause a pattern
4631 change.
4633 When we discover a suitable dependency, we fill in the dep_replacement
4634 structure to show how to modify the memory reference. */
4636 /* Holds information about a pair of memory reference and register increment
4637 insns which depend on each other, but could possibly be interchanged. */
4638 struct mem_inc_info
4640 rtx_insn *inc_insn;
4641 rtx_insn *mem_insn;
4643 rtx *mem_loc;
4644 /* A register occurring in the memory address for which we wish to break
4645 the dependence. This must be identical to the destination register of
4646 the increment. */
4647 rtx mem_reg0;
4648 /* Any kind of index that is added to that register. */
4649 rtx mem_index;
4650 /* The constant offset used in the memory address. */
4651 HOST_WIDE_INT mem_constant;
4652 /* The constant added in the increment insn. Negated if the increment is
4653 after the memory address. */
4654 HOST_WIDE_INT inc_constant;
4655 /* The source register used in the increment. May be different from mem_reg0
4656 if the increment occurs before the memory address. */
4657 rtx inc_input;
4660 /* Verify that the memory location described in MII can be replaced with
4661 one using NEW_ADDR. Return the new memory reference or NULL_RTX. The
4662 insn remains unchanged by this function. */
4664 static rtx
4665 attempt_change (struct mem_inc_info *mii, rtx new_addr)
4667 rtx mem = *mii->mem_loc;
4668 rtx new_mem;
4670 /* Jump through a lot of hoops to keep the attributes up to date. We
4671 do not want to call one of the change address variants that take
4672 an offset even though we know the offset in many cases. These
4673 assume you are changing where the address is pointing by the
4674 offset. */
4675 new_mem = replace_equiv_address_nv (mem, new_addr);
4676 if (! validate_change (mii->mem_insn, mii->mem_loc, new_mem, 0))
4678 if (sched_verbose >= 5)
4679 fprintf (sched_dump, "validation failure\n");
4680 return NULL_RTX;
4683 /* Put back the old one. */
4684 validate_change (mii->mem_insn, mii->mem_loc, mem, 0);
4686 return new_mem;
4689 /* Return true if INSN is of a form "a = b op c" where a and b are
4690 regs. op is + if c is a reg and +|- if c is a const. Fill in
4691 informantion in MII about what is found.
4692 BEFORE_MEM indicates whether the increment is found before or after
4693 a corresponding memory reference. */
4695 static bool
4696 parse_add_or_inc (struct mem_inc_info *mii, rtx_insn *insn, bool before_mem)
4698 rtx pat = single_set (insn);
4699 rtx src, cst;
4700 bool regs_equal;
4702 if (RTX_FRAME_RELATED_P (insn) || !pat)
4703 return false;
4705 /* Result must be single reg. */
4706 if (!REG_P (SET_DEST (pat)))
4707 return false;
4709 if (GET_CODE (SET_SRC (pat)) != PLUS)
4710 return false;
4712 mii->inc_insn = insn;
4713 src = SET_SRC (pat);
4714 mii->inc_input = XEXP (src, 0);
4716 if (!REG_P (XEXP (src, 0)))
4717 return false;
4719 if (!rtx_equal_p (SET_DEST (pat), mii->mem_reg0))
4720 return false;
4722 cst = XEXP (src, 1);
4723 if (!CONST_INT_P (cst))
4724 return false;
4725 mii->inc_constant = INTVAL (cst);
4727 regs_equal = rtx_equal_p (mii->inc_input, mii->mem_reg0);
4729 if (!before_mem)
4731 mii->inc_constant = -mii->inc_constant;
4732 if (!regs_equal)
4733 return false;
4736 if (regs_equal && REGNO (SET_DEST (pat)) == STACK_POINTER_REGNUM)
4738 /* Note that the sign has already been reversed for !before_mem. */
4739 if (STACK_GROWS_DOWNWARD)
4740 return mii->inc_constant > 0;
4741 else
4742 return mii->inc_constant < 0;
4744 return true;
4747 /* Once a suitable mem reference has been found and the corresponding data
4748 in MII has been filled in, this function is called to find a suitable
4749 add or inc insn involving the register we found in the memory
4750 reference. */
4752 static bool
4753 find_inc (struct mem_inc_info *mii, bool backwards)
4755 sd_iterator_def sd_it;
4756 dep_t dep;
4758 sd_it = sd_iterator_start (mii->mem_insn,
4759 backwards ? SD_LIST_HARD_BACK : SD_LIST_FORW);
4760 while (sd_iterator_cond (&sd_it, &dep))
4762 dep_node_t node = DEP_LINK_NODE (*sd_it.linkp);
4763 rtx_insn *pro = DEP_PRO (dep);
4764 rtx_insn *con = DEP_CON (dep);
4765 rtx_insn *inc_cand = backwards ? pro : con;
4766 if (DEP_NONREG (dep) || DEP_MULTIPLE (dep))
4767 goto next;
4768 if (parse_add_or_inc (mii, inc_cand, backwards))
4770 struct dep_replacement *desc;
4771 df_ref def;
4772 rtx newaddr, newmem;
4774 if (sched_verbose >= 5)
4775 fprintf (sched_dump, "candidate mem/inc pair: %d %d\n",
4776 INSN_UID (mii->mem_insn), INSN_UID (inc_cand));
4778 /* Need to assure that none of the operands of the inc
4779 instruction are assigned to by the mem insn. */
4780 FOR_EACH_INSN_DEF (def, mii->mem_insn)
4781 if (reg_overlap_mentioned_p (DF_REF_REG (def), mii->inc_input)
4782 || reg_overlap_mentioned_p (DF_REF_REG (def), mii->mem_reg0))
4784 if (sched_verbose >= 5)
4785 fprintf (sched_dump,
4786 "inc conflicts with store failure.\n");
4787 goto next;
4790 newaddr = mii->inc_input;
4791 if (mii->mem_index != NULL_RTX)
4792 newaddr = gen_rtx_PLUS (GET_MODE (newaddr), newaddr,
4793 mii->mem_index);
4794 newaddr = plus_constant (GET_MODE (newaddr), newaddr,
4795 mii->mem_constant + mii->inc_constant);
4796 newmem = attempt_change (mii, newaddr);
4797 if (newmem == NULL_RTX)
4798 goto next;
4799 if (sched_verbose >= 5)
4800 fprintf (sched_dump, "successful address replacement\n");
4801 desc = XCNEW (struct dep_replacement);
4802 DEP_REPLACE (dep) = desc;
4803 desc->loc = mii->mem_loc;
4804 desc->newval = newmem;
4805 desc->orig = *desc->loc;
4806 desc->insn = mii->mem_insn;
4807 move_dep_link (DEP_NODE_BACK (node), INSN_HARD_BACK_DEPS (con),
4808 INSN_SPEC_BACK_DEPS (con));
4809 if (backwards)
4811 FOR_EACH_DEP (mii->inc_insn, SD_LIST_BACK, sd_it, dep)
4812 add_dependence_1 (mii->mem_insn, DEP_PRO (dep),
4813 REG_DEP_TRUE);
4815 else
4817 FOR_EACH_DEP (mii->inc_insn, SD_LIST_FORW, sd_it, dep)
4818 add_dependence_1 (DEP_CON (dep), mii->mem_insn,
4819 REG_DEP_ANTI);
4821 return true;
4823 next:
4824 sd_iterator_next (&sd_it);
4826 return false;
4829 /* A recursive function that walks ADDRESS_OF_X to find memory references
4830 which could be modified during scheduling. We call find_inc for each
4831 one we find that has a recognizable form. MII holds information about
4832 the pair of memory/increment instructions.
4833 We ensure that every instruction with a memory reference (which will be
4834 the location of the replacement) is assigned at most one breakable
4835 dependency. */
4837 static bool
4838 find_mem (struct mem_inc_info *mii, rtx *address_of_x)
4840 rtx x = *address_of_x;
4841 enum rtx_code code = GET_CODE (x);
4842 const char *const fmt = GET_RTX_FORMAT (code);
4843 int i;
4845 if (code == MEM)
4847 rtx reg0 = XEXP (x, 0);
4849 mii->mem_loc = address_of_x;
4850 mii->mem_index = NULL_RTX;
4851 mii->mem_constant = 0;
4852 if (GET_CODE (reg0) == PLUS && CONST_INT_P (XEXP (reg0, 1)))
4854 mii->mem_constant = INTVAL (XEXP (reg0, 1));
4855 reg0 = XEXP (reg0, 0);
4857 if (GET_CODE (reg0) == PLUS)
4859 mii->mem_index = XEXP (reg0, 1);
4860 reg0 = XEXP (reg0, 0);
4862 if (REG_P (reg0))
4864 df_ref use;
4865 int occurrences = 0;
4867 /* Make sure this reg appears only once in this insn. Can't use
4868 count_occurrences since that only works for pseudos. */
4869 FOR_EACH_INSN_USE (use, mii->mem_insn)
4870 if (reg_overlap_mentioned_p (reg0, DF_REF_REG (use)))
4871 if (++occurrences > 1)
4873 if (sched_verbose >= 5)
4874 fprintf (sched_dump, "mem count failure\n");
4875 return false;
4878 mii->mem_reg0 = reg0;
4879 return find_inc (mii, true) || find_inc (mii, false);
4881 return false;
4884 if (code == SIGN_EXTRACT || code == ZERO_EXTRACT)
4886 /* If REG occurs inside a MEM used in a bit-field reference,
4887 that is unacceptable. */
4888 return false;
4891 /* Time for some deep diving. */
4892 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
4894 if (fmt[i] == 'e')
4896 if (find_mem (mii, &XEXP (x, i)))
4897 return true;
4899 else if (fmt[i] == 'E')
4901 int j;
4902 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
4903 if (find_mem (mii, &XVECEXP (x, i, j)))
4904 return true;
4907 return false;
4911 /* Examine the instructions between HEAD and TAIL and try to find
4912 dependencies that can be broken by modifying one of the patterns. */
4914 void
4915 find_modifiable_mems (rtx_insn *head, rtx_insn *tail)
4917 rtx_insn *insn, *next_tail = NEXT_INSN (tail);
4918 int success_in_block = 0;
4920 for (insn = head; insn != next_tail; insn = NEXT_INSN (insn))
4922 struct mem_inc_info mii;
4924 if (!NONDEBUG_INSN_P (insn) || RTX_FRAME_RELATED_P (insn))
4925 continue;
4927 mii.mem_insn = insn;
4928 if (find_mem (&mii, &PATTERN (insn)))
4929 success_in_block++;
4931 if (success_in_block && sched_verbose >= 5)
4932 fprintf (sched_dump, "%d candidates for address modification found.\n",
4933 success_in_block);
4936 #endif /* INSN_SCHEDULING */