1 /* Instruction scheduling pass. This file computes dependencies between
3 Copyright (C) 1992-2014 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
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
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/>. */
25 #include "coretypes.h"
27 #include "diagnostic-core.h"
29 #include "tree.h" /* FIXME: Used by call_may_noreturn_p. */
31 #include "hard-reg-set.h"
35 #include "insn-config.h"
36 #include "insn-attr.h"
40 #include "sched-int.h"
46 #ifdef INSN_SCHEDULING
48 #ifdef ENABLE_CHECKING
54 /* Holds current parameters for the dependency analyzer. */
55 struct sched_deps_info_def
*sched_deps_info
;
57 /* The data is specific to the Haifa scheduler. */
58 vec
<haifa_deps_insn_data_def
>
61 /* Return the major type present in the DS. */
69 return REG_DEP_OUTPUT
;
72 return REG_DEP_CONTROL
;
74 gcc_assert (ds
& DEP_ANTI
);
79 /* Return equivalent dep_status. */
81 dk_to_ds (enum reg_note dk
)
95 gcc_assert (dk
== REG_DEP_ANTI
);
100 /* Functions to operate with dependence information container - dep_t. */
102 /* Init DEP with the arguments. */
104 init_dep_1 (dep_t dep
, rtx_insn
*pro
, rtx_insn
*con
, enum reg_note type
, ds_t ds
)
108 DEP_TYPE (dep
) = type
;
109 DEP_STATUS (dep
) = ds
;
110 DEP_COST (dep
) = UNKNOWN_DEP_COST
;
111 DEP_NONREG (dep
) = 0;
112 DEP_MULTIPLE (dep
) = 0;
113 DEP_REPLACE (dep
) = NULL
;
116 /* Init DEP with the arguments.
117 While most of the scheduler (including targets) only need the major type
118 of the dependency, it is convenient to hide full dep_status from them. */
120 init_dep (dep_t dep
, rtx_insn
*pro
, rtx_insn
*con
, enum reg_note kind
)
124 if ((current_sched_info
->flags
& USE_DEPS_LIST
))
125 ds
= dk_to_ds (kind
);
129 init_dep_1 (dep
, pro
, con
, kind
, ds
);
132 /* Make a copy of FROM in TO. */
134 copy_dep (dep_t to
, dep_t from
)
136 memcpy (to
, from
, sizeof (*to
));
139 static void dump_ds (FILE *, ds_t
);
141 /* Define flags for dump_dep (). */
143 /* Dump producer of the dependence. */
144 #define DUMP_DEP_PRO (2)
146 /* Dump consumer of the dependence. */
147 #define DUMP_DEP_CON (4)
149 /* Dump type of the dependence. */
150 #define DUMP_DEP_TYPE (8)
152 /* Dump status of the dependence. */
153 #define DUMP_DEP_STATUS (16)
155 /* Dump all information about the dependence. */
156 #define DUMP_DEP_ALL (DUMP_DEP_PRO | DUMP_DEP_CON | DUMP_DEP_TYPE \
160 FLAGS is a bit mask specifying what information about DEP needs
162 If FLAGS has the very first bit set, then dump all information about DEP
163 and propagate this bit into the callee dump functions. */
165 dump_dep (FILE *dump
, dep_t dep
, int flags
)
168 flags
|= DUMP_DEP_ALL
;
172 if (flags
& DUMP_DEP_PRO
)
173 fprintf (dump
, "%d; ", INSN_UID (DEP_PRO (dep
)));
175 if (flags
& DUMP_DEP_CON
)
176 fprintf (dump
, "%d; ", INSN_UID (DEP_CON (dep
)));
178 if (flags
& DUMP_DEP_TYPE
)
181 enum reg_note type
= DEP_TYPE (dep
);
193 case REG_DEP_CONTROL
:
206 fprintf (dump
, "%c; ", t
);
209 if (flags
& DUMP_DEP_STATUS
)
211 if (current_sched_info
->flags
& USE_DEPS_LIST
)
212 dump_ds (dump
, DEP_STATUS (dep
));
218 /* Default flags for dump_dep (). */
219 static int dump_dep_flags
= (DUMP_DEP_PRO
| DUMP_DEP_CON
);
221 /* Dump all fields of DEP to STDERR. */
223 sd_debug_dep (dep_t dep
)
225 dump_dep (stderr
, dep
, 1);
226 fprintf (stderr
, "\n");
229 /* Determine whether DEP is a dependency link of a non-debug insn on a
233 depl_on_debug_p (dep_link_t dep
)
235 return (DEBUG_INSN_P (DEP_LINK_PRO (dep
))
236 && !DEBUG_INSN_P (DEP_LINK_CON (dep
)));
239 /* Functions to operate with a single link from the dependencies lists -
242 /* Attach L to appear after link X whose &DEP_LINK_NEXT (X) is given by
245 attach_dep_link (dep_link_t l
, dep_link_t
*prev_nextp
)
247 dep_link_t next
= *prev_nextp
;
249 gcc_assert (DEP_LINK_PREV_NEXTP (l
) == NULL
250 && DEP_LINK_NEXT (l
) == NULL
);
252 /* Init node being inserted. */
253 DEP_LINK_PREV_NEXTP (l
) = prev_nextp
;
254 DEP_LINK_NEXT (l
) = next
;
259 gcc_assert (DEP_LINK_PREV_NEXTP (next
) == prev_nextp
);
261 DEP_LINK_PREV_NEXTP (next
) = &DEP_LINK_NEXT (l
);
268 /* Add dep_link LINK to deps_list L. */
270 add_to_deps_list (dep_link_t link
, deps_list_t l
)
272 attach_dep_link (link
, &DEPS_LIST_FIRST (l
));
274 /* Don't count debug deps. */
275 if (!depl_on_debug_p (link
))
276 ++DEPS_LIST_N_LINKS (l
);
279 /* Detach dep_link L from the list. */
281 detach_dep_link (dep_link_t l
)
283 dep_link_t
*prev_nextp
= DEP_LINK_PREV_NEXTP (l
);
284 dep_link_t next
= DEP_LINK_NEXT (l
);
289 DEP_LINK_PREV_NEXTP (next
) = prev_nextp
;
291 DEP_LINK_PREV_NEXTP (l
) = NULL
;
292 DEP_LINK_NEXT (l
) = NULL
;
295 /* Remove link LINK from list LIST. */
297 remove_from_deps_list (dep_link_t link
, deps_list_t list
)
299 detach_dep_link (link
);
301 /* Don't count debug deps. */
302 if (!depl_on_debug_p (link
))
303 --DEPS_LIST_N_LINKS (list
);
306 /* Move link LINK from list FROM to list TO. */
308 move_dep_link (dep_link_t link
, deps_list_t from
, deps_list_t to
)
310 remove_from_deps_list (link
, from
);
311 add_to_deps_list (link
, to
);
314 /* Return true of LINK is not attached to any list. */
316 dep_link_is_detached_p (dep_link_t link
)
318 return DEP_LINK_PREV_NEXTP (link
) == NULL
;
321 /* Pool to hold all dependency nodes (dep_node_t). */
322 static alloc_pool dn_pool
;
324 /* Number of dep_nodes out there. */
325 static int dn_pool_diff
= 0;
327 /* Create a dep_node. */
329 create_dep_node (void)
331 dep_node_t n
= (dep_node_t
) pool_alloc (dn_pool
);
332 dep_link_t back
= DEP_NODE_BACK (n
);
333 dep_link_t forw
= DEP_NODE_FORW (n
);
335 DEP_LINK_NODE (back
) = n
;
336 DEP_LINK_NEXT (back
) = NULL
;
337 DEP_LINK_PREV_NEXTP (back
) = NULL
;
339 DEP_LINK_NODE (forw
) = n
;
340 DEP_LINK_NEXT (forw
) = NULL
;
341 DEP_LINK_PREV_NEXTP (forw
) = NULL
;
348 /* Delete dep_node N. N must not be connected to any deps_list. */
350 delete_dep_node (dep_node_t n
)
352 gcc_assert (dep_link_is_detached_p (DEP_NODE_BACK (n
))
353 && dep_link_is_detached_p (DEP_NODE_FORW (n
)));
355 XDELETE (DEP_REPLACE (DEP_NODE_DEP (n
)));
359 pool_free (dn_pool
, n
);
362 /* Pool to hold dependencies lists (deps_list_t). */
363 static alloc_pool dl_pool
;
365 /* Number of deps_lists out there. */
366 static int dl_pool_diff
= 0;
368 /* Functions to operate with dependences lists - deps_list_t. */
370 /* Return true if list L is empty. */
372 deps_list_empty_p (deps_list_t l
)
374 return DEPS_LIST_N_LINKS (l
) == 0;
377 /* Create a new deps_list. */
379 create_deps_list (void)
381 deps_list_t l
= (deps_list_t
) pool_alloc (dl_pool
);
383 DEPS_LIST_FIRST (l
) = NULL
;
384 DEPS_LIST_N_LINKS (l
) = 0;
390 /* Free deps_list L. */
392 free_deps_list (deps_list_t l
)
394 gcc_assert (deps_list_empty_p (l
));
398 pool_free (dl_pool
, l
);
401 /* Return true if there is no dep_nodes and deps_lists out there.
402 After the region is scheduled all the dependency nodes and lists
403 should [generally] be returned to pool. */
405 deps_pools_are_empty_p (void)
407 return dn_pool_diff
== 0 && dl_pool_diff
== 0;
410 /* Remove all elements from L. */
412 clear_deps_list (deps_list_t l
)
416 dep_link_t link
= DEPS_LIST_FIRST (l
);
421 remove_from_deps_list (link
, l
);
426 /* Decide whether a dependency should be treated as a hard or a speculative
429 dep_spec_p (dep_t dep
)
431 if (current_sched_info
->flags
& DO_SPECULATION
)
433 if (DEP_STATUS (dep
) & SPECULATIVE
)
436 if (current_sched_info
->flags
& DO_PREDICATION
)
438 if (DEP_TYPE (dep
) == REG_DEP_CONTROL
)
441 if (DEP_REPLACE (dep
) != NULL
)
446 static regset reg_pending_sets
;
447 static regset reg_pending_clobbers
;
448 static regset reg_pending_uses
;
449 static regset reg_pending_control_uses
;
450 static enum reg_pending_barrier_mode reg_pending_barrier
;
452 /* Hard registers implicitly clobbered or used (or may be implicitly
453 clobbered or used) by the currently analyzed insn. For example,
454 insn in its constraint has one register class. Even if there is
455 currently no hard register in the insn, the particular hard
456 register will be in the insn after reload pass because the
457 constraint requires it. */
458 static HARD_REG_SET implicit_reg_pending_clobbers
;
459 static HARD_REG_SET implicit_reg_pending_uses
;
461 /* To speed up the test for duplicate dependency links we keep a
462 record of dependencies created by add_dependence when the average
463 number of instructions in a basic block is very large.
465 Studies have shown that there is typically around 5 instructions between
466 branches for typical C code. So we can make a guess that the average
467 basic block is approximately 5 instructions long; we will choose 100X
468 the average size as a very large basic block.
470 Each insn has associated bitmaps for its dependencies. Each bitmap
471 has enough entries to represent a dependency on any other insn in
472 the insn chain. All bitmap for true dependencies cache is
473 allocated then the rest two ones are also allocated. */
474 static bitmap_head
*true_dependency_cache
= NULL
;
475 static bitmap_head
*output_dependency_cache
= NULL
;
476 static bitmap_head
*anti_dependency_cache
= NULL
;
477 static bitmap_head
*control_dependency_cache
= NULL
;
478 static bitmap_head
*spec_dependency_cache
= NULL
;
479 static int cache_size
;
481 /* True if we should mark added dependencies as a non-register deps. */
482 static bool mark_as_hard
;
484 static int deps_may_trap_p (const_rtx
);
485 static void add_dependence_1 (rtx_insn
*, rtx_insn
*, enum reg_note
);
486 static void add_dependence_list (rtx_insn
*, rtx_insn_list
*, int,
487 enum reg_note
, bool);
488 static void add_dependence_list_and_free (struct deps_desc
*, rtx_insn
*,
489 rtx_insn_list
**, int, enum reg_note
,
491 static void delete_all_dependences (rtx
);
492 static void chain_to_prev_insn (rtx_insn
*);
494 static void flush_pending_lists (struct deps_desc
*, rtx_insn
*, int, int);
495 static void sched_analyze_1 (struct deps_desc
*, rtx
, rtx_insn
*);
496 static void sched_analyze_2 (struct deps_desc
*, rtx
, rtx_insn
*);
497 static void sched_analyze_insn (struct deps_desc
*, rtx
, rtx_insn
*);
499 static bool sched_has_condition_p (const_rtx
);
500 static int conditions_mutex_p (const_rtx
, const_rtx
, bool, bool);
502 static enum DEPS_ADJUST_RESULT
maybe_add_or_update_dep_1 (dep_t
, bool,
504 static enum DEPS_ADJUST_RESULT
add_or_update_dep_1 (dep_t
, bool, rtx
, rtx
);
506 #ifdef ENABLE_CHECKING
507 static void check_dep (dep_t
, bool);
510 /* Return nonzero if a load of the memory reference MEM can cause a trap. */
513 deps_may_trap_p (const_rtx mem
)
515 const_rtx addr
= XEXP (mem
, 0);
517 if (REG_P (addr
) && REGNO (addr
) >= FIRST_PSEUDO_REGISTER
)
519 const_rtx t
= get_reg_known_value (REGNO (addr
));
523 return rtx_addr_can_trap_p (addr
);
527 /* Find the condition under which INSN is executed. If REV is not NULL,
528 it is set to TRUE when the returned comparison should be reversed
529 to get the actual condition. */
531 sched_get_condition_with_rev_uncached (const_rtx insn
, bool *rev
)
533 rtx pat
= PATTERN (insn
);
539 if (GET_CODE (pat
) == COND_EXEC
)
540 return COND_EXEC_TEST (pat
);
542 if (!any_condjump_p (insn
) || !onlyjump_p (insn
))
545 src
= SET_SRC (pc_set (insn
));
547 if (XEXP (src
, 2) == pc_rtx
)
548 return XEXP (src
, 0);
549 else if (XEXP (src
, 1) == pc_rtx
)
551 rtx cond
= XEXP (src
, 0);
552 enum rtx_code revcode
= reversed_comparison_code (cond
, insn
);
554 if (revcode
== UNKNOWN
)
565 /* Return the condition under which INSN does not execute (i.e. the
566 not-taken condition for a conditional branch), or NULL if we cannot
567 find such a condition. The caller should make a copy of the condition
570 sched_get_reverse_condition_uncached (const_rtx insn
)
573 rtx cond
= sched_get_condition_with_rev_uncached (insn
, &rev
);
574 if (cond
== NULL_RTX
)
578 enum rtx_code revcode
= reversed_comparison_code (cond
, insn
);
579 cond
= gen_rtx_fmt_ee (revcode
, GET_MODE (cond
),
586 /* Caching variant of sched_get_condition_with_rev_uncached.
587 We only do actual work the first time we come here for an insn; the
588 results are cached in INSN_CACHED_COND and INSN_REVERSE_COND. */
590 sched_get_condition_with_rev (const_rtx insn
, bool *rev
)
594 if (INSN_LUID (insn
) == 0)
595 return sched_get_condition_with_rev_uncached (insn
, rev
);
597 if (INSN_CACHED_COND (insn
) == const_true_rtx
)
600 if (INSN_CACHED_COND (insn
) != NULL_RTX
)
603 *rev
= INSN_REVERSE_COND (insn
);
604 return INSN_CACHED_COND (insn
);
607 INSN_CACHED_COND (insn
) = sched_get_condition_with_rev_uncached (insn
, &tmp
);
608 INSN_REVERSE_COND (insn
) = tmp
;
610 if (INSN_CACHED_COND (insn
) == NULL_RTX
)
612 INSN_CACHED_COND (insn
) = const_true_rtx
;
617 *rev
= INSN_REVERSE_COND (insn
);
618 return INSN_CACHED_COND (insn
);
621 /* True when we can find a condition under which INSN is executed. */
623 sched_has_condition_p (const_rtx insn
)
625 return !! sched_get_condition_with_rev (insn
, NULL
);
630 /* Return nonzero if conditions COND1 and COND2 can never be both true. */
632 conditions_mutex_p (const_rtx cond1
, const_rtx cond2
, bool rev1
, bool rev2
)
634 if (COMPARISON_P (cond1
)
635 && COMPARISON_P (cond2
)
636 && GET_CODE (cond1
) ==
638 ? reversed_comparison_code (cond2
, NULL
)
640 && rtx_equal_p (XEXP (cond1
, 0), XEXP (cond2
, 0))
641 && XEXP (cond1
, 1) == XEXP (cond2
, 1))
646 /* Return true if insn1 and insn2 can never depend on one another because
647 the conditions under which they are executed are mutually exclusive. */
649 sched_insns_conditions_mutex_p (const_rtx insn1
, const_rtx insn2
)
652 bool rev1
= false, rev2
= false;
654 /* df doesn't handle conditional lifetimes entirely correctly;
655 calls mess up the conditional lifetimes. */
656 if (!CALL_P (insn1
) && !CALL_P (insn2
))
658 cond1
= sched_get_condition_with_rev (insn1
, &rev1
);
659 cond2
= sched_get_condition_with_rev (insn2
, &rev2
);
661 && conditions_mutex_p (cond1
, cond2
, rev1
, rev2
)
662 /* Make sure first instruction doesn't affect condition of second
663 instruction if switched. */
664 && !modified_in_p (cond1
, insn2
)
665 /* Make sure second instruction doesn't affect condition of first
666 instruction if switched. */
667 && !modified_in_p (cond2
, insn1
))
674 /* Return true if INSN can potentially be speculated with type DS. */
676 sched_insn_is_legitimate_for_speculation_p (const_rtx insn
, ds_t ds
)
678 if (HAS_INTERNAL_DEP (insn
))
681 if (!NONJUMP_INSN_P (insn
))
684 if (SCHED_GROUP_P (insn
))
687 if (IS_SPECULATION_CHECK_P (CONST_CAST_RTX (insn
)))
690 if (side_effects_p (PATTERN (insn
)))
694 /* The following instructions, which depend on a speculatively scheduled
695 instruction, cannot be speculatively scheduled along. */
697 if (may_trap_or_fault_p (PATTERN (insn
)))
698 /* If instruction might fault, it cannot be speculatively scheduled.
699 For control speculation it's obvious why and for data speculation
700 it's because the insn might get wrong input if speculation
701 wasn't successful. */
704 if ((ds
& BE_IN_DATA
)
705 && sched_has_condition_p (insn
))
706 /* If this is a predicated instruction, then it cannot be
707 speculatively scheduled. See PR35659. */
714 /* Initialize LIST_PTR to point to one of the lists present in TYPES_PTR,
715 initialize RESOLVED_P_PTR with true if that list consists of resolved deps,
716 and remove the type of returned [through LIST_PTR] list from TYPES_PTR.
717 This function is used to switch sd_iterator to the next list.
718 !!! For internal use only. Might consider moving it to sched-int.h. */
720 sd_next_list (const_rtx insn
, sd_list_types_def
*types_ptr
,
721 deps_list_t
*list_ptr
, bool *resolved_p_ptr
)
723 sd_list_types_def types
= *types_ptr
;
725 if (types
& SD_LIST_HARD_BACK
)
727 *list_ptr
= INSN_HARD_BACK_DEPS (insn
);
728 *resolved_p_ptr
= false;
729 *types_ptr
= types
& ~SD_LIST_HARD_BACK
;
731 else if (types
& SD_LIST_SPEC_BACK
)
733 *list_ptr
= INSN_SPEC_BACK_DEPS (insn
);
734 *resolved_p_ptr
= false;
735 *types_ptr
= types
& ~SD_LIST_SPEC_BACK
;
737 else if (types
& SD_LIST_FORW
)
739 *list_ptr
= INSN_FORW_DEPS (insn
);
740 *resolved_p_ptr
= false;
741 *types_ptr
= types
& ~SD_LIST_FORW
;
743 else if (types
& SD_LIST_RES_BACK
)
745 *list_ptr
= INSN_RESOLVED_BACK_DEPS (insn
);
746 *resolved_p_ptr
= true;
747 *types_ptr
= types
& ~SD_LIST_RES_BACK
;
749 else if (types
& SD_LIST_RES_FORW
)
751 *list_ptr
= INSN_RESOLVED_FORW_DEPS (insn
);
752 *resolved_p_ptr
= true;
753 *types_ptr
= types
& ~SD_LIST_RES_FORW
;
758 *resolved_p_ptr
= false;
759 *types_ptr
= SD_LIST_NONE
;
763 /* Return the summary size of INSN's lists defined by LIST_TYPES. */
765 sd_lists_size (const_rtx insn
, sd_list_types_def list_types
)
769 while (list_types
!= SD_LIST_NONE
)
774 sd_next_list (insn
, &list_types
, &list
, &resolved_p
);
776 size
+= DEPS_LIST_N_LINKS (list
);
782 /* Return true if INSN's lists defined by LIST_TYPES are all empty. */
785 sd_lists_empty_p (const_rtx insn
, sd_list_types_def list_types
)
787 while (list_types
!= SD_LIST_NONE
)
792 sd_next_list (insn
, &list_types
, &list
, &resolved_p
);
793 if (!deps_list_empty_p (list
))
800 /* Initialize data for INSN. */
802 sd_init_insn (rtx insn
)
804 INSN_HARD_BACK_DEPS (insn
) = create_deps_list ();
805 INSN_SPEC_BACK_DEPS (insn
) = create_deps_list ();
806 INSN_RESOLVED_BACK_DEPS (insn
) = create_deps_list ();
807 INSN_FORW_DEPS (insn
) = create_deps_list ();
808 INSN_RESOLVED_FORW_DEPS (insn
) = create_deps_list ();
810 /* ??? It would be nice to allocate dependency caches here. */
813 /* Free data for INSN. */
815 sd_finish_insn (rtx insn
)
817 /* ??? It would be nice to deallocate dependency caches here. */
819 free_deps_list (INSN_HARD_BACK_DEPS (insn
));
820 INSN_HARD_BACK_DEPS (insn
) = NULL
;
822 free_deps_list (INSN_SPEC_BACK_DEPS (insn
));
823 INSN_SPEC_BACK_DEPS (insn
) = NULL
;
825 free_deps_list (INSN_RESOLVED_BACK_DEPS (insn
));
826 INSN_RESOLVED_BACK_DEPS (insn
) = NULL
;
828 free_deps_list (INSN_FORW_DEPS (insn
));
829 INSN_FORW_DEPS (insn
) = NULL
;
831 free_deps_list (INSN_RESOLVED_FORW_DEPS (insn
));
832 INSN_RESOLVED_FORW_DEPS (insn
) = NULL
;
835 /* Find a dependency between producer PRO and consumer CON.
836 Search through resolved dependency lists if RESOLVED_P is true.
837 If no such dependency is found return NULL,
838 otherwise return the dependency and initialize SD_IT_PTR [if it is nonnull]
839 with an iterator pointing to it. */
841 sd_find_dep_between_no_cache (rtx pro
, rtx con
, bool resolved_p
,
842 sd_iterator_def
*sd_it_ptr
)
844 sd_list_types_def pro_list_type
;
845 sd_list_types_def con_list_type
;
846 sd_iterator_def sd_it
;
848 bool found_p
= false;
852 pro_list_type
= SD_LIST_RES_FORW
;
853 con_list_type
= SD_LIST_RES_BACK
;
857 pro_list_type
= SD_LIST_FORW
;
858 con_list_type
= SD_LIST_BACK
;
861 /* Walk through either back list of INSN or forw list of ELEM
862 depending on which one is shorter. */
863 if (sd_lists_size (con
, con_list_type
) < sd_lists_size (pro
, pro_list_type
))
865 /* Find the dep_link with producer PRO in consumer's back_deps. */
866 FOR_EACH_DEP (con
, con_list_type
, sd_it
, dep
)
867 if (DEP_PRO (dep
) == pro
)
875 /* Find the dep_link with consumer CON in producer's forw_deps. */
876 FOR_EACH_DEP (pro
, pro_list_type
, sd_it
, dep
)
877 if (DEP_CON (dep
) == con
)
886 if (sd_it_ptr
!= NULL
)
895 /* Find a dependency between producer PRO and consumer CON.
896 Use dependency [if available] to check if dependency is present at all.
897 Search through resolved dependency lists if RESOLVED_P is true.
898 If the dependency or NULL if none found. */
900 sd_find_dep_between (rtx pro
, rtx con
, bool resolved_p
)
902 if (true_dependency_cache
!= NULL
)
903 /* Avoiding the list walk below can cut compile times dramatically
906 int elem_luid
= INSN_LUID (pro
);
907 int insn_luid
= INSN_LUID (con
);
909 if (!bitmap_bit_p (&true_dependency_cache
[insn_luid
], elem_luid
)
910 && !bitmap_bit_p (&output_dependency_cache
[insn_luid
], elem_luid
)
911 && !bitmap_bit_p (&anti_dependency_cache
[insn_luid
], elem_luid
)
912 && !bitmap_bit_p (&control_dependency_cache
[insn_luid
], elem_luid
))
916 return sd_find_dep_between_no_cache (pro
, con
, resolved_p
, NULL
);
919 /* Add or update a dependence described by DEP.
920 MEM1 and MEM2, if non-null, correspond to memory locations in case of
923 The function returns a value indicating if an old entry has been changed
924 or a new entry has been added to insn's backward deps.
926 This function merely checks if producer and consumer is the same insn
927 and doesn't create a dep in this case. Actual manipulation of
928 dependence data structures is performed in add_or_update_dep_1. */
929 static enum DEPS_ADJUST_RESULT
930 maybe_add_or_update_dep_1 (dep_t dep
, bool resolved_p
, rtx mem1
, rtx mem2
)
932 rtx_insn
*elem
= DEP_PRO (dep
);
933 rtx_insn
*insn
= DEP_CON (dep
);
935 gcc_assert (INSN_P (insn
) && INSN_P (elem
));
937 /* Don't depend an insn on itself. */
940 if (sched_deps_info
->generate_spec_deps
)
941 /* INSN has an internal dependence, which we can't overcome. */
942 HAS_INTERNAL_DEP (insn
) = 1;
947 return add_or_update_dep_1 (dep
, resolved_p
, mem1
, mem2
);
950 /* Ask dependency caches what needs to be done for dependence DEP.
951 Return DEP_CREATED if new dependence should be created and there is no
952 need to try to find one searching the dependencies lists.
953 Return DEP_PRESENT if there already is a dependence described by DEP and
954 hence nothing is to be done.
955 Return DEP_CHANGED if there already is a dependence, but it should be
956 updated to incorporate additional information from DEP. */
957 static enum DEPS_ADJUST_RESULT
958 ask_dependency_caches (dep_t dep
)
960 int elem_luid
= INSN_LUID (DEP_PRO (dep
));
961 int insn_luid
= INSN_LUID (DEP_CON (dep
));
963 gcc_assert (true_dependency_cache
!= NULL
964 && output_dependency_cache
!= NULL
965 && anti_dependency_cache
!= NULL
966 && control_dependency_cache
!= NULL
);
968 if (!(current_sched_info
->flags
& USE_DEPS_LIST
))
970 enum reg_note present_dep_type
;
972 if (bitmap_bit_p (&true_dependency_cache
[insn_luid
], elem_luid
))
973 present_dep_type
= REG_DEP_TRUE
;
974 else if (bitmap_bit_p (&output_dependency_cache
[insn_luid
], elem_luid
))
975 present_dep_type
= REG_DEP_OUTPUT
;
976 else if (bitmap_bit_p (&anti_dependency_cache
[insn_luid
], elem_luid
))
977 present_dep_type
= REG_DEP_ANTI
;
978 else if (bitmap_bit_p (&control_dependency_cache
[insn_luid
], elem_luid
))
979 present_dep_type
= REG_DEP_CONTROL
;
981 /* There is no existing dep so it should be created. */
984 if ((int) DEP_TYPE (dep
) >= (int) present_dep_type
)
985 /* DEP does not add anything to the existing dependence. */
990 ds_t present_dep_types
= 0;
992 if (bitmap_bit_p (&true_dependency_cache
[insn_luid
], elem_luid
))
993 present_dep_types
|= DEP_TRUE
;
994 if (bitmap_bit_p (&output_dependency_cache
[insn_luid
], elem_luid
))
995 present_dep_types
|= DEP_OUTPUT
;
996 if (bitmap_bit_p (&anti_dependency_cache
[insn_luid
], elem_luid
))
997 present_dep_types
|= DEP_ANTI
;
998 if (bitmap_bit_p (&control_dependency_cache
[insn_luid
], elem_luid
))
999 present_dep_types
|= DEP_CONTROL
;
1001 if (present_dep_types
== 0)
1002 /* There is no existing dep so it should be created. */
1005 if (!(current_sched_info
->flags
& DO_SPECULATION
)
1006 || !bitmap_bit_p (&spec_dependency_cache
[insn_luid
], elem_luid
))
1008 if ((present_dep_types
| (DEP_STATUS (dep
) & DEP_TYPES
))
1009 == present_dep_types
)
1010 /* DEP does not add anything to the existing dependence. */
1015 /* Only true dependencies can be data speculative and
1016 only anti dependencies can be control speculative. */
1017 gcc_assert ((present_dep_types
& (DEP_TRUE
| DEP_ANTI
))
1018 == present_dep_types
);
1020 /* if (DEP is SPECULATIVE) then
1021 ..we should update DEP_STATUS
1023 ..we should reset existing dep to non-speculative. */
1030 /* Set dependency caches according to DEP. */
1032 set_dependency_caches (dep_t dep
)
1034 int elem_luid
= INSN_LUID (DEP_PRO (dep
));
1035 int insn_luid
= INSN_LUID (DEP_CON (dep
));
1037 if (!(current_sched_info
->flags
& USE_DEPS_LIST
))
1039 switch (DEP_TYPE (dep
))
1042 bitmap_set_bit (&true_dependency_cache
[insn_luid
], elem_luid
);
1045 case REG_DEP_OUTPUT
:
1046 bitmap_set_bit (&output_dependency_cache
[insn_luid
], elem_luid
);
1050 bitmap_set_bit (&anti_dependency_cache
[insn_luid
], elem_luid
);
1053 case REG_DEP_CONTROL
:
1054 bitmap_set_bit (&control_dependency_cache
[insn_luid
], elem_luid
);
1063 ds_t ds
= DEP_STATUS (dep
);
1066 bitmap_set_bit (&true_dependency_cache
[insn_luid
], elem_luid
);
1067 if (ds
& DEP_OUTPUT
)
1068 bitmap_set_bit (&output_dependency_cache
[insn_luid
], elem_luid
);
1070 bitmap_set_bit (&anti_dependency_cache
[insn_luid
], elem_luid
);
1071 if (ds
& DEP_CONTROL
)
1072 bitmap_set_bit (&control_dependency_cache
[insn_luid
], elem_luid
);
1074 if (ds
& SPECULATIVE
)
1076 gcc_assert (current_sched_info
->flags
& DO_SPECULATION
);
1077 bitmap_set_bit (&spec_dependency_cache
[insn_luid
], elem_luid
);
1082 /* Type of dependence DEP have changed from OLD_TYPE. Update dependency
1083 caches accordingly. */
1085 update_dependency_caches (dep_t dep
, enum reg_note old_type
)
1087 int elem_luid
= INSN_LUID (DEP_PRO (dep
));
1088 int insn_luid
= INSN_LUID (DEP_CON (dep
));
1090 /* Clear corresponding cache entry because type of the link
1091 may have changed. Keep them if we use_deps_list. */
1092 if (!(current_sched_info
->flags
& USE_DEPS_LIST
))
1096 case REG_DEP_OUTPUT
:
1097 bitmap_clear_bit (&output_dependency_cache
[insn_luid
], elem_luid
);
1101 bitmap_clear_bit (&anti_dependency_cache
[insn_luid
], elem_luid
);
1104 case REG_DEP_CONTROL
:
1105 bitmap_clear_bit (&control_dependency_cache
[insn_luid
], elem_luid
);
1113 set_dependency_caches (dep
);
1116 /* Convert a dependence pointed to by SD_IT to be non-speculative. */
1118 change_spec_dep_to_hard (sd_iterator_def sd_it
)
1120 dep_node_t node
= DEP_LINK_NODE (*sd_it
.linkp
);
1121 dep_link_t link
= DEP_NODE_BACK (node
);
1122 dep_t dep
= DEP_NODE_DEP (node
);
1123 rtx_insn
*elem
= DEP_PRO (dep
);
1124 rtx_insn
*insn
= DEP_CON (dep
);
1126 move_dep_link (link
, INSN_SPEC_BACK_DEPS (insn
), INSN_HARD_BACK_DEPS (insn
));
1128 DEP_STATUS (dep
) &= ~SPECULATIVE
;
1130 if (true_dependency_cache
!= NULL
)
1131 /* Clear the cache entry. */
1132 bitmap_clear_bit (&spec_dependency_cache
[INSN_LUID (insn
)],
1136 /* Update DEP to incorporate information from NEW_DEP.
1137 SD_IT points to DEP in case it should be moved to another list.
1138 MEM1 and MEM2, if nonnull, correspond to memory locations in case if
1139 data-speculative dependence should be updated. */
1140 static enum DEPS_ADJUST_RESULT
1141 update_dep (dep_t dep
, dep_t new_dep
,
1142 sd_iterator_def sd_it ATTRIBUTE_UNUSED
,
1143 rtx mem1 ATTRIBUTE_UNUSED
,
1144 rtx mem2 ATTRIBUTE_UNUSED
)
1146 enum DEPS_ADJUST_RESULT res
= DEP_PRESENT
;
1147 enum reg_note old_type
= DEP_TYPE (dep
);
1148 bool was_spec
= dep_spec_p (dep
);
1150 DEP_NONREG (dep
) |= DEP_NONREG (new_dep
);
1151 DEP_MULTIPLE (dep
) = 1;
1153 /* If this is a more restrictive type of dependence than the
1154 existing one, then change the existing dependence to this
1156 if ((int) DEP_TYPE (new_dep
) < (int) old_type
)
1158 DEP_TYPE (dep
) = DEP_TYPE (new_dep
);
1162 if (current_sched_info
->flags
& USE_DEPS_LIST
)
1163 /* Update DEP_STATUS. */
1165 ds_t dep_status
= DEP_STATUS (dep
);
1166 ds_t ds
= DEP_STATUS (new_dep
);
1167 ds_t new_status
= ds
| dep_status
;
1169 if (new_status
& SPECULATIVE
)
1171 /* Either existing dep or a dep we're adding or both are
1173 if (!(ds
& SPECULATIVE
)
1174 || !(dep_status
& SPECULATIVE
))
1175 /* The new dep can't be speculative. */
1176 new_status
&= ~SPECULATIVE
;
1179 /* Both are speculative. Merge probabilities. */
1184 dw
= estimate_dep_weak (mem1
, mem2
);
1185 ds
= set_dep_weak (ds
, BEGIN_DATA
, dw
);
1188 new_status
= ds_merge (dep_status
, ds
);
1194 if (dep_status
!= ds
)
1196 DEP_STATUS (dep
) = ds
;
1201 if (was_spec
&& !dep_spec_p (dep
))
1202 /* The old dep was speculative, but now it isn't. */
1203 change_spec_dep_to_hard (sd_it
);
1205 if (true_dependency_cache
!= NULL
1206 && res
== DEP_CHANGED
)
1207 update_dependency_caches (dep
, old_type
);
1212 /* Add or update a dependence described by DEP.
1213 MEM1 and MEM2, if non-null, correspond to memory locations in case of
1216 The function returns a value indicating if an old entry has been changed
1217 or a new entry has been added to insn's backward deps or nothing has
1218 been updated at all. */
1219 static enum DEPS_ADJUST_RESULT
1220 add_or_update_dep_1 (dep_t new_dep
, bool resolved_p
,
1221 rtx mem1 ATTRIBUTE_UNUSED
, rtx mem2 ATTRIBUTE_UNUSED
)
1223 bool maybe_present_p
= true;
1224 bool present_p
= false;
1226 gcc_assert (INSN_P (DEP_PRO (new_dep
)) && INSN_P (DEP_CON (new_dep
))
1227 && DEP_PRO (new_dep
) != DEP_CON (new_dep
));
1229 #ifdef ENABLE_CHECKING
1230 check_dep (new_dep
, mem1
!= NULL
);
1233 if (true_dependency_cache
!= NULL
)
1235 switch (ask_dependency_caches (new_dep
))
1239 sd_iterator_def sd_it
;
1241 present_dep
= sd_find_dep_between_no_cache (DEP_PRO (new_dep
),
1243 resolved_p
, &sd_it
);
1244 DEP_MULTIPLE (present_dep
) = 1;
1248 maybe_present_p
= true;
1253 maybe_present_p
= false;
1263 /* Check that we don't already have this dependence. */
1264 if (maybe_present_p
)
1267 sd_iterator_def sd_it
;
1269 gcc_assert (true_dependency_cache
== NULL
|| present_p
);
1271 present_dep
= sd_find_dep_between_no_cache (DEP_PRO (new_dep
),
1273 resolved_p
, &sd_it
);
1275 if (present_dep
!= NULL
)
1276 /* We found an existing dependency between ELEM and INSN. */
1277 return update_dep (present_dep
, new_dep
, sd_it
, mem1
, mem2
);
1279 /* We didn't find a dep, it shouldn't present in the cache. */
1280 gcc_assert (!present_p
);
1283 /* Might want to check one level of transitivity to save conses.
1284 This check should be done in maybe_add_or_update_dep_1.
1285 Since we made it to add_or_update_dep_1, we must create
1286 (or update) a link. */
1288 if (mem1
!= NULL_RTX
)
1290 gcc_assert (sched_deps_info
->generate_spec_deps
);
1291 DEP_STATUS (new_dep
) = set_dep_weak (DEP_STATUS (new_dep
), BEGIN_DATA
,
1292 estimate_dep_weak (mem1
, mem2
));
1295 sd_add_dep (new_dep
, resolved_p
);
1300 /* Initialize BACK_LIST_PTR with consumer's backward list and
1301 FORW_LIST_PTR with producer's forward list. If RESOLVED_P is true
1302 initialize with lists that hold resolved deps. */
1304 get_back_and_forw_lists (dep_t dep
, bool resolved_p
,
1305 deps_list_t
*back_list_ptr
,
1306 deps_list_t
*forw_list_ptr
)
1308 rtx_insn
*con
= DEP_CON (dep
);
1312 if (dep_spec_p (dep
))
1313 *back_list_ptr
= INSN_SPEC_BACK_DEPS (con
);
1315 *back_list_ptr
= INSN_HARD_BACK_DEPS (con
);
1317 *forw_list_ptr
= INSN_FORW_DEPS (DEP_PRO (dep
));
1321 *back_list_ptr
= INSN_RESOLVED_BACK_DEPS (con
);
1322 *forw_list_ptr
= INSN_RESOLVED_FORW_DEPS (DEP_PRO (dep
));
1326 /* Add dependence described by DEP.
1327 If RESOLVED_P is true treat the dependence as a resolved one. */
1329 sd_add_dep (dep_t dep
, bool resolved_p
)
1331 dep_node_t n
= create_dep_node ();
1332 deps_list_t con_back_deps
;
1333 deps_list_t pro_forw_deps
;
1334 rtx_insn
*elem
= DEP_PRO (dep
);
1335 rtx_insn
*insn
= DEP_CON (dep
);
1337 gcc_assert (INSN_P (insn
) && INSN_P (elem
) && insn
!= elem
);
1339 if ((current_sched_info
->flags
& DO_SPECULATION
) == 0
1340 || !sched_insn_is_legitimate_for_speculation_p (insn
, DEP_STATUS (dep
)))
1341 DEP_STATUS (dep
) &= ~SPECULATIVE
;
1343 copy_dep (DEP_NODE_DEP (n
), dep
);
1345 get_back_and_forw_lists (dep
, resolved_p
, &con_back_deps
, &pro_forw_deps
);
1347 add_to_deps_list (DEP_NODE_BACK (n
), con_back_deps
);
1349 #ifdef ENABLE_CHECKING
1350 check_dep (dep
, false);
1353 add_to_deps_list (DEP_NODE_FORW (n
), pro_forw_deps
);
1355 /* If we are adding a dependency to INSN's LOG_LINKs, then note that
1356 in the bitmap caches of dependency information. */
1357 if (true_dependency_cache
!= NULL
)
1358 set_dependency_caches (dep
);
1361 /* Add or update backward dependence between INSN and ELEM
1362 with given type DEP_TYPE and dep_status DS.
1363 This function is a convenience wrapper. */
1364 enum DEPS_ADJUST_RESULT
1365 sd_add_or_update_dep (dep_t dep
, bool resolved_p
)
1367 return add_or_update_dep_1 (dep
, resolved_p
, NULL_RTX
, NULL_RTX
);
1370 /* Resolved dependence pointed to by SD_IT.
1371 SD_IT will advance to the next element. */
1373 sd_resolve_dep (sd_iterator_def sd_it
)
1375 dep_node_t node
= DEP_LINK_NODE (*sd_it
.linkp
);
1376 dep_t dep
= DEP_NODE_DEP (node
);
1377 rtx_insn
*pro
= DEP_PRO (dep
);
1378 rtx_insn
*con
= DEP_CON (dep
);
1380 if (dep_spec_p (dep
))
1381 move_dep_link (DEP_NODE_BACK (node
), INSN_SPEC_BACK_DEPS (con
),
1382 INSN_RESOLVED_BACK_DEPS (con
));
1384 move_dep_link (DEP_NODE_BACK (node
), INSN_HARD_BACK_DEPS (con
),
1385 INSN_RESOLVED_BACK_DEPS (con
));
1387 move_dep_link (DEP_NODE_FORW (node
), INSN_FORW_DEPS (pro
),
1388 INSN_RESOLVED_FORW_DEPS (pro
));
1391 /* Perform the inverse operation of sd_resolve_dep. Restore the dependence
1392 pointed to by SD_IT to unresolved state. */
1394 sd_unresolve_dep (sd_iterator_def sd_it
)
1396 dep_node_t node
= DEP_LINK_NODE (*sd_it
.linkp
);
1397 dep_t dep
= DEP_NODE_DEP (node
);
1398 rtx_insn
*pro
= DEP_PRO (dep
);
1399 rtx_insn
*con
= DEP_CON (dep
);
1401 if (dep_spec_p (dep
))
1402 move_dep_link (DEP_NODE_BACK (node
), INSN_RESOLVED_BACK_DEPS (con
),
1403 INSN_SPEC_BACK_DEPS (con
));
1405 move_dep_link (DEP_NODE_BACK (node
), INSN_RESOLVED_BACK_DEPS (con
),
1406 INSN_HARD_BACK_DEPS (con
));
1408 move_dep_link (DEP_NODE_FORW (node
), INSN_RESOLVED_FORW_DEPS (pro
),
1409 INSN_FORW_DEPS (pro
));
1412 /* Make TO depend on all the FROM's producers.
1413 If RESOLVED_P is true add dependencies to the resolved lists. */
1415 sd_copy_back_deps (rtx_insn
*to
, rtx_insn
*from
, bool resolved_p
)
1417 sd_list_types_def list_type
;
1418 sd_iterator_def sd_it
;
1421 list_type
= resolved_p
? SD_LIST_RES_BACK
: SD_LIST_BACK
;
1423 FOR_EACH_DEP (from
, list_type
, sd_it
, dep
)
1425 dep_def _new_dep
, *new_dep
= &_new_dep
;
1427 copy_dep (new_dep
, dep
);
1428 DEP_CON (new_dep
) = to
;
1429 sd_add_dep (new_dep
, resolved_p
);
1433 /* Remove a dependency referred to by SD_IT.
1434 SD_IT will point to the next dependence after removal. */
1436 sd_delete_dep (sd_iterator_def sd_it
)
1438 dep_node_t n
= DEP_LINK_NODE (*sd_it
.linkp
);
1439 dep_t dep
= DEP_NODE_DEP (n
);
1440 rtx_insn
*pro
= DEP_PRO (dep
);
1441 rtx_insn
*con
= DEP_CON (dep
);
1442 deps_list_t con_back_deps
;
1443 deps_list_t pro_forw_deps
;
1445 if (true_dependency_cache
!= NULL
)
1447 int elem_luid
= INSN_LUID (pro
);
1448 int insn_luid
= INSN_LUID (con
);
1450 bitmap_clear_bit (&true_dependency_cache
[insn_luid
], elem_luid
);
1451 bitmap_clear_bit (&anti_dependency_cache
[insn_luid
], elem_luid
);
1452 bitmap_clear_bit (&control_dependency_cache
[insn_luid
], elem_luid
);
1453 bitmap_clear_bit (&output_dependency_cache
[insn_luid
], elem_luid
);
1455 if (current_sched_info
->flags
& DO_SPECULATION
)
1456 bitmap_clear_bit (&spec_dependency_cache
[insn_luid
], elem_luid
);
1459 get_back_and_forw_lists (dep
, sd_it
.resolved_p
,
1460 &con_back_deps
, &pro_forw_deps
);
1462 remove_from_deps_list (DEP_NODE_BACK (n
), con_back_deps
);
1463 remove_from_deps_list (DEP_NODE_FORW (n
), pro_forw_deps
);
1465 delete_dep_node (n
);
1468 /* Dump size of the lists. */
1469 #define DUMP_LISTS_SIZE (2)
1471 /* Dump dependencies of the lists. */
1472 #define DUMP_LISTS_DEPS (4)
1474 /* Dump all information about the lists. */
1475 #define DUMP_LISTS_ALL (DUMP_LISTS_SIZE | DUMP_LISTS_DEPS)
1477 /* Dump deps_lists of INSN specified by TYPES to DUMP.
1478 FLAGS is a bit mask specifying what information about the lists needs
1480 If FLAGS has the very first bit set, then dump all information about
1481 the lists and propagate this bit into the callee dump functions. */
1483 dump_lists (FILE *dump
, rtx insn
, sd_list_types_def types
, int flags
)
1485 sd_iterator_def sd_it
;
1492 flags
|= DUMP_LISTS_ALL
;
1494 fprintf (dump
, "[");
1496 if (flags
& DUMP_LISTS_SIZE
)
1497 fprintf (dump
, "%d; ", sd_lists_size (insn
, types
));
1499 if (flags
& DUMP_LISTS_DEPS
)
1501 FOR_EACH_DEP (insn
, types
, sd_it
, dep
)
1503 dump_dep (dump
, dep
, dump_dep_flags
| all
);
1504 fprintf (dump
, " ");
1509 /* Dump all information about deps_lists of INSN specified by TYPES
1512 sd_debug_lists (rtx insn
, sd_list_types_def types
)
1514 dump_lists (stderr
, insn
, types
, 1);
1515 fprintf (stderr
, "\n");
1518 /* A wrapper around add_dependence_1, to add a dependence of CON on
1519 PRO, with type DEP_TYPE. This function implements special handling
1520 for REG_DEP_CONTROL dependencies. For these, we optionally promote
1521 the type to REG_DEP_ANTI if we can determine that predication is
1522 impossible; otherwise we add additional true dependencies on the
1523 INSN_COND_DEPS list of the jump (which PRO must be). */
1525 add_dependence (rtx_insn
*con
, rtx_insn
*pro
, enum reg_note dep_type
)
1527 if (dep_type
== REG_DEP_CONTROL
1528 && !(current_sched_info
->flags
& DO_PREDICATION
))
1529 dep_type
= REG_DEP_ANTI
;
1531 /* A REG_DEP_CONTROL dependence may be eliminated through predication,
1532 so we must also make the insn dependent on the setter of the
1534 if (dep_type
== REG_DEP_CONTROL
)
1536 rtx_insn
*real_pro
= pro
;
1537 rtx_insn
*other
= real_insn_for_shadow (real_pro
);
1540 if (other
!= NULL_RTX
)
1542 cond
= sched_get_reverse_condition_uncached (real_pro
);
1543 /* Verify that the insn does not use a different value in
1544 the condition register than the one that was present at
1546 if (cond
== NULL_RTX
)
1547 dep_type
= REG_DEP_ANTI
;
1548 else if (INSN_CACHED_COND (real_pro
) == const_true_rtx
)
1551 CLEAR_HARD_REG_SET (uses
);
1552 note_uses (&PATTERN (con
), record_hard_reg_uses
, &uses
);
1553 if (TEST_HARD_REG_BIT (uses
, REGNO (XEXP (cond
, 0))))
1554 dep_type
= REG_DEP_ANTI
;
1556 if (dep_type
== REG_DEP_CONTROL
)
1558 if (sched_verbose
>= 5)
1559 fprintf (sched_dump
, "making DEP_CONTROL for %d\n",
1560 INSN_UID (real_pro
));
1561 add_dependence_list (con
, INSN_COND_DEPS (real_pro
), 0,
1562 REG_DEP_TRUE
, false);
1566 add_dependence_1 (con
, pro
, dep_type
);
1569 /* A convenience wrapper to operate on an entire list. HARD should be
1570 true if DEP_NONREG should be set on newly created dependencies. */
1573 add_dependence_list (rtx_insn
*insn
, rtx_insn_list
*list
, int uncond
,
1574 enum reg_note dep_type
, bool hard
)
1576 mark_as_hard
= hard
;
1577 for (; list
; list
= list
->next ())
1579 if (uncond
|| ! sched_insns_conditions_mutex_p (insn
, list
->insn ()))
1580 add_dependence (insn
, list
->insn (), dep_type
);
1582 mark_as_hard
= false;
1585 /* Similar, but free *LISTP at the same time, when the context
1586 is not readonly. HARD should be true if DEP_NONREG should be set on
1587 newly created dependencies. */
1590 add_dependence_list_and_free (struct deps_desc
*deps
, rtx_insn
*insn
,
1591 rtx_insn_list
**listp
,
1592 int uncond
, enum reg_note dep_type
, bool hard
)
1594 add_dependence_list (insn
, *listp
, uncond
, dep_type
, hard
);
1596 /* We don't want to short-circuit dependencies involving debug
1597 insns, because they may cause actual dependencies to be
1599 if (deps
->readonly
|| DEBUG_INSN_P (insn
))
1602 free_INSN_LIST_list (listp
);
1605 /* Remove all occurrences of INSN from LIST. Return the number of
1606 occurrences removed. */
1609 remove_from_dependence_list (rtx insn
, rtx_insn_list
**listp
)
1615 if ((*listp
)->insn () == insn
)
1617 remove_free_INSN_LIST_node (listp
);
1622 listp
= (rtx_insn_list
**)&XEXP (*listp
, 1);
1628 /* Same as above, but process two lists at once. */
1630 remove_from_both_dependence_lists (rtx insn
,
1631 rtx_insn_list
**listp
,
1632 rtx_expr_list
**exprp
)
1638 if (XEXP (*listp
, 0) == insn
)
1640 remove_free_INSN_LIST_node (listp
);
1641 remove_free_EXPR_LIST_node (exprp
);
1646 listp
= (rtx_insn_list
**)&XEXP (*listp
, 1);
1647 exprp
= (rtx_expr_list
**)&XEXP (*exprp
, 1);
1653 /* Clear all dependencies for an insn. */
1655 delete_all_dependences (rtx insn
)
1657 sd_iterator_def sd_it
;
1660 /* The below cycle can be optimized to clear the caches and back_deps
1661 in one call but that would provoke duplication of code from
1664 for (sd_it
= sd_iterator_start (insn
, SD_LIST_BACK
);
1665 sd_iterator_cond (&sd_it
, &dep
);)
1666 sd_delete_dep (sd_it
);
1669 /* All insns in a scheduling group except the first should only have
1670 dependencies on the previous insn in the group. So we find the
1671 first instruction in the scheduling group by walking the dependence
1672 chains backwards. Then we add the dependencies for the group to
1673 the previous nonnote insn. */
1676 chain_to_prev_insn (rtx_insn
*insn
)
1678 sd_iterator_def sd_it
;
1680 rtx_insn
*prev_nonnote
;
1682 FOR_EACH_DEP (insn
, SD_LIST_BACK
, sd_it
, dep
)
1685 rtx_insn
*pro
= DEP_PRO (dep
);
1689 i
= prev_nonnote_insn (i
);
1693 } while (SCHED_GROUP_P (i
) || DEBUG_INSN_P (i
));
1695 if (! sched_insns_conditions_mutex_p (i
, pro
))
1696 add_dependence (i
, pro
, DEP_TYPE (dep
));
1700 delete_all_dependences (insn
);
1702 prev_nonnote
= prev_nonnote_nondebug_insn (insn
);
1703 if (BLOCK_FOR_INSN (insn
) == BLOCK_FOR_INSN (prev_nonnote
)
1704 && ! sched_insns_conditions_mutex_p (insn
, prev_nonnote
))
1705 add_dependence (insn
, prev_nonnote
, REG_DEP_ANTI
);
1708 /* Process an insn's memory dependencies. There are four kinds of
1711 (0) read dependence: read follows read
1712 (1) true dependence: read follows write
1713 (2) output dependence: write follows write
1714 (3) anti dependence: write follows read
1716 We are careful to build only dependencies which actually exist, and
1717 use transitivity to avoid building too many links. */
1719 /* Add an INSN and MEM reference pair to a pending INSN_LIST and MEM_LIST.
1720 The MEM is a memory reference contained within INSN, which we are saving
1721 so that we can do memory aliasing on it. */
1724 add_insn_mem_dependence (struct deps_desc
*deps
, bool read_p
,
1725 rtx_insn
*insn
, rtx mem
)
1727 rtx_insn_list
**insn_list
;
1728 rtx_insn_list
*insn_node
;
1729 rtx_expr_list
**mem_list
;
1730 rtx_expr_list
*mem_node
;
1732 gcc_assert (!deps
->readonly
);
1735 insn_list
= &deps
->pending_read_insns
;
1736 mem_list
= &deps
->pending_read_mems
;
1737 if (!DEBUG_INSN_P (insn
))
1738 deps
->pending_read_list_length
++;
1742 insn_list
= &deps
->pending_write_insns
;
1743 mem_list
= &deps
->pending_write_mems
;
1744 deps
->pending_write_list_length
++;
1747 insn_node
= alloc_INSN_LIST (insn
, *insn_list
);
1748 *insn_list
= insn_node
;
1750 if (sched_deps_info
->use_cselib
)
1752 mem
= shallow_copy_rtx (mem
);
1753 XEXP (mem
, 0) = cselib_subst_to_values_from_insn (XEXP (mem
, 0),
1754 GET_MODE (mem
), insn
);
1756 mem_node
= alloc_EXPR_LIST (VOIDmode
, canon_rtx (mem
), *mem_list
);
1757 *mem_list
= mem_node
;
1760 /* Make a dependency between every memory reference on the pending lists
1761 and INSN, thus flushing the pending lists. FOR_READ is true if emitting
1762 dependencies for a read operation, similarly with FOR_WRITE. */
1765 flush_pending_lists (struct deps_desc
*deps
, rtx_insn
*insn
, int for_read
,
1770 add_dependence_list_and_free (deps
, insn
, &deps
->pending_read_insns
,
1771 1, REG_DEP_ANTI
, true);
1772 if (!deps
->readonly
)
1774 free_EXPR_LIST_list (&deps
->pending_read_mems
);
1775 deps
->pending_read_list_length
= 0;
1779 add_dependence_list_and_free (deps
, insn
, &deps
->pending_write_insns
, 1,
1780 for_read
? REG_DEP_ANTI
: REG_DEP_OUTPUT
,
1783 add_dependence_list_and_free (deps
, insn
,
1784 &deps
->last_pending_memory_flush
, 1,
1785 for_read
? REG_DEP_ANTI
: REG_DEP_OUTPUT
,
1788 add_dependence_list_and_free (deps
, insn
, &deps
->pending_jump_insns
, 1,
1789 REG_DEP_ANTI
, true);
1791 if (DEBUG_INSN_P (insn
))
1794 free_INSN_LIST_list (&deps
->pending_read_insns
);
1795 free_INSN_LIST_list (&deps
->pending_write_insns
);
1796 free_INSN_LIST_list (&deps
->last_pending_memory_flush
);
1797 free_INSN_LIST_list (&deps
->pending_jump_insns
);
1800 if (!deps
->readonly
)
1802 free_EXPR_LIST_list (&deps
->pending_write_mems
);
1803 deps
->pending_write_list_length
= 0;
1805 deps
->last_pending_memory_flush
= alloc_INSN_LIST (insn
, NULL_RTX
);
1806 deps
->pending_flush_length
= 1;
1808 mark_as_hard
= false;
1811 /* Instruction which dependencies we are analyzing. */
1812 static rtx_insn
*cur_insn
= NULL
;
1814 /* Implement hooks for haifa scheduler. */
1817 haifa_start_insn (rtx_insn
*insn
)
1819 gcc_assert (insn
&& !cur_insn
);
1825 haifa_finish_insn (void)
1831 haifa_note_reg_set (int regno
)
1833 SET_REGNO_REG_SET (reg_pending_sets
, regno
);
1837 haifa_note_reg_clobber (int regno
)
1839 SET_REGNO_REG_SET (reg_pending_clobbers
, regno
);
1843 haifa_note_reg_use (int regno
)
1845 SET_REGNO_REG_SET (reg_pending_uses
, regno
);
1849 haifa_note_mem_dep (rtx mem
, rtx pending_mem
, rtx_insn
*pending_insn
, ds_t ds
)
1851 if (!(ds
& SPECULATIVE
))
1854 pending_mem
= NULL_RTX
;
1857 gcc_assert (ds
& BEGIN_DATA
);
1860 dep_def _dep
, *dep
= &_dep
;
1862 init_dep_1 (dep
, pending_insn
, cur_insn
, ds_to_dt (ds
),
1863 current_sched_info
->flags
& USE_DEPS_LIST
? ds
: 0);
1864 DEP_NONREG (dep
) = 1;
1865 maybe_add_or_update_dep_1 (dep
, false, pending_mem
, mem
);
1871 haifa_note_dep (rtx_insn
*elem
, ds_t ds
)
1876 init_dep (dep
, elem
, cur_insn
, ds_to_dt (ds
));
1878 DEP_NONREG (dep
) = 1;
1879 maybe_add_or_update_dep_1 (dep
, false, NULL_RTX
, NULL_RTX
);
1883 note_reg_use (int r
)
1885 if (sched_deps_info
->note_reg_use
)
1886 sched_deps_info
->note_reg_use (r
);
1890 note_reg_set (int r
)
1892 if (sched_deps_info
->note_reg_set
)
1893 sched_deps_info
->note_reg_set (r
);
1897 note_reg_clobber (int r
)
1899 if (sched_deps_info
->note_reg_clobber
)
1900 sched_deps_info
->note_reg_clobber (r
);
1904 note_mem_dep (rtx m1
, rtx m2
, rtx_insn
*e
, ds_t ds
)
1906 if (sched_deps_info
->note_mem_dep
)
1907 sched_deps_info
->note_mem_dep (m1
, m2
, e
, ds
);
1911 note_dep (rtx_insn
*e
, ds_t ds
)
1913 if (sched_deps_info
->note_dep
)
1914 sched_deps_info
->note_dep (e
, ds
);
1917 /* Return corresponding to DS reg_note. */
1922 return REG_DEP_TRUE
;
1923 else if (ds
& DEP_OUTPUT
)
1924 return REG_DEP_OUTPUT
;
1925 else if (ds
& DEP_ANTI
)
1926 return REG_DEP_ANTI
;
1929 gcc_assert (ds
& DEP_CONTROL
);
1930 return REG_DEP_CONTROL
;
1936 /* Functions for computation of info needed for register pressure
1937 sensitive insn scheduling. */
1940 /* Allocate and return reg_use_data structure for REGNO and INSN. */
1941 static struct reg_use_data
*
1942 create_insn_reg_use (int regno
, rtx_insn
*insn
)
1944 struct reg_use_data
*use
;
1946 use
= (struct reg_use_data
*) xmalloc (sizeof (struct reg_use_data
));
1949 use
->next_insn_use
= INSN_REG_USE_LIST (insn
);
1950 INSN_REG_USE_LIST (insn
) = use
;
1954 /* Allocate reg_set_data structure for REGNO and INSN. */
1956 create_insn_reg_set (int regno
, rtx insn
)
1958 struct reg_set_data
*set
;
1960 set
= (struct reg_set_data
*) xmalloc (sizeof (struct reg_set_data
));
1963 set
->next_insn_set
= INSN_REG_SET_LIST (insn
);
1964 INSN_REG_SET_LIST (insn
) = set
;
1967 /* Set up insn register uses for INSN and dependency context DEPS. */
1969 setup_insn_reg_uses (struct deps_desc
*deps
, rtx_insn
*insn
)
1972 reg_set_iterator rsi
;
1974 struct reg_use_data
*use
, *use2
, *next
;
1975 struct deps_reg
*reg_last
;
1977 EXECUTE_IF_SET_IN_REG_SET (reg_pending_uses
, 0, i
, rsi
)
1979 if (i
< FIRST_PSEUDO_REGISTER
1980 && TEST_HARD_REG_BIT (ira_no_alloc_regs
, i
))
1983 if (find_regno_note (insn
, REG_DEAD
, i
) == NULL_RTX
1984 && ! REGNO_REG_SET_P (reg_pending_sets
, i
)
1985 && ! REGNO_REG_SET_P (reg_pending_clobbers
, i
))
1986 /* Ignore use which is not dying. */
1989 use
= create_insn_reg_use (i
, insn
);
1990 use
->next_regno_use
= use
;
1991 reg_last
= &deps
->reg_last
[i
];
1993 /* Create the cycle list of uses. */
1994 for (list
= reg_last
->uses
; list
; list
= XEXP (list
, 1))
1996 use2
= create_insn_reg_use (i
, as_a
<rtx_insn
*> (XEXP (list
, 0)));
1997 next
= use
->next_regno_use
;
1998 use
->next_regno_use
= use2
;
1999 use2
->next_regno_use
= next
;
2004 /* Register pressure info for the currently processed insn. */
2005 static struct reg_pressure_data reg_pressure_info
[N_REG_CLASSES
];
2007 /* Return TRUE if INSN has the use structure for REGNO. */
2009 insn_use_p (rtx insn
, int regno
)
2011 struct reg_use_data
*use
;
2013 for (use
= INSN_REG_USE_LIST (insn
); use
!= NULL
; use
= use
->next_insn_use
)
2014 if (use
->regno
== regno
)
2019 /* Update the register pressure info after birth of pseudo register REGNO
2020 in INSN. Arguments CLOBBER_P and UNUSED_P say correspondingly that
2021 the register is in clobber or unused after the insn. */
2023 mark_insn_pseudo_birth (rtx insn
, int regno
, bool clobber_p
, bool unused_p
)
2028 gcc_assert (regno
>= FIRST_PSEUDO_REGISTER
);
2029 cl
= sched_regno_pressure_class
[regno
];
2032 incr
= ira_reg_class_max_nregs
[cl
][PSEUDO_REGNO_MODE (regno
)];
2035 new_incr
= reg_pressure_info
[cl
].clobber_increase
+ incr
;
2036 reg_pressure_info
[cl
].clobber_increase
= new_incr
;
2040 new_incr
= reg_pressure_info
[cl
].unused_set_increase
+ incr
;
2041 reg_pressure_info
[cl
].unused_set_increase
= new_incr
;
2045 new_incr
= reg_pressure_info
[cl
].set_increase
+ incr
;
2046 reg_pressure_info
[cl
].set_increase
= new_incr
;
2047 if (! insn_use_p (insn
, regno
))
2048 reg_pressure_info
[cl
].change
+= incr
;
2049 create_insn_reg_set (regno
, insn
);
2051 gcc_assert (new_incr
< (1 << INCREASE_BITS
));
2055 /* Like mark_insn_pseudo_regno_birth except that NREGS saying how many
2056 hard registers involved in the birth. */
2058 mark_insn_hard_regno_birth (rtx insn
, int regno
, int nregs
,
2059 bool clobber_p
, bool unused_p
)
2062 int new_incr
, last
= regno
+ nregs
;
2064 while (regno
< last
)
2066 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
2067 if (! TEST_HARD_REG_BIT (ira_no_alloc_regs
, regno
))
2069 cl
= sched_regno_pressure_class
[regno
];
2074 new_incr
= reg_pressure_info
[cl
].clobber_increase
+ 1;
2075 reg_pressure_info
[cl
].clobber_increase
= new_incr
;
2079 new_incr
= reg_pressure_info
[cl
].unused_set_increase
+ 1;
2080 reg_pressure_info
[cl
].unused_set_increase
= new_incr
;
2084 new_incr
= reg_pressure_info
[cl
].set_increase
+ 1;
2085 reg_pressure_info
[cl
].set_increase
= new_incr
;
2086 if (! insn_use_p (insn
, regno
))
2087 reg_pressure_info
[cl
].change
+= 1;
2088 create_insn_reg_set (regno
, insn
);
2090 gcc_assert (new_incr
< (1 << INCREASE_BITS
));
2097 /* Update the register pressure info after birth of pseudo or hard
2098 register REG in INSN. Arguments CLOBBER_P and UNUSED_P say
2099 correspondingly that the register is in clobber or unused after the
2102 mark_insn_reg_birth (rtx insn
, rtx reg
, bool clobber_p
, bool unused_p
)
2106 if (GET_CODE (reg
) == SUBREG
)
2107 reg
= SUBREG_REG (reg
);
2112 regno
= REGNO (reg
);
2113 if (regno
< FIRST_PSEUDO_REGISTER
)
2114 mark_insn_hard_regno_birth (insn
, regno
,
2115 hard_regno_nregs
[regno
][GET_MODE (reg
)],
2116 clobber_p
, unused_p
);
2118 mark_insn_pseudo_birth (insn
, regno
, clobber_p
, unused_p
);
2121 /* Update the register pressure info after death of pseudo register
2124 mark_pseudo_death (int regno
)
2129 gcc_assert (regno
>= FIRST_PSEUDO_REGISTER
);
2130 cl
= sched_regno_pressure_class
[regno
];
2133 incr
= ira_reg_class_max_nregs
[cl
][PSEUDO_REGNO_MODE (regno
)];
2134 reg_pressure_info
[cl
].change
-= incr
;
2138 /* Like mark_pseudo_death except that NREGS saying how many hard
2139 registers involved in the death. */
2141 mark_hard_regno_death (int regno
, int nregs
)
2144 int last
= regno
+ nregs
;
2146 while (regno
< last
)
2148 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
2149 if (! TEST_HARD_REG_BIT (ira_no_alloc_regs
, regno
))
2151 cl
= sched_regno_pressure_class
[regno
];
2153 reg_pressure_info
[cl
].change
-= 1;
2159 /* Update the register pressure info after death of pseudo or hard
2162 mark_reg_death (rtx reg
)
2166 if (GET_CODE (reg
) == SUBREG
)
2167 reg
= SUBREG_REG (reg
);
2172 regno
= REGNO (reg
);
2173 if (regno
< FIRST_PSEUDO_REGISTER
)
2174 mark_hard_regno_death (regno
, hard_regno_nregs
[regno
][GET_MODE (reg
)]);
2176 mark_pseudo_death (regno
);
2179 /* Process SETTER of REG. DATA is an insn containing the setter. */
2181 mark_insn_reg_store (rtx reg
, const_rtx setter
, void *data
)
2183 if (setter
!= NULL_RTX
&& GET_CODE (setter
) != SET
)
2186 ((rtx
) data
, reg
, false,
2187 find_reg_note ((const_rtx
) data
, REG_UNUSED
, reg
) != NULL_RTX
);
2190 /* Like mark_insn_reg_store except notice just CLOBBERs; ignore SETs. */
2192 mark_insn_reg_clobber (rtx reg
, const_rtx setter
, void *data
)
2194 if (GET_CODE (setter
) == CLOBBER
)
2195 mark_insn_reg_birth ((rtx
) data
, reg
, true, false);
2198 /* Set up reg pressure info related to INSN. */
2200 init_insn_reg_pressure_info (rtx insn
)
2204 static struct reg_pressure_data
*pressure_info
;
2207 gcc_assert (sched_pressure
!= SCHED_PRESSURE_NONE
);
2209 if (! INSN_P (insn
))
2212 for (i
= 0; i
< ira_pressure_classes_num
; i
++)
2214 cl
= ira_pressure_classes
[i
];
2215 reg_pressure_info
[cl
].clobber_increase
= 0;
2216 reg_pressure_info
[cl
].set_increase
= 0;
2217 reg_pressure_info
[cl
].unused_set_increase
= 0;
2218 reg_pressure_info
[cl
].change
= 0;
2221 note_stores (PATTERN (insn
), mark_insn_reg_clobber
, insn
);
2223 note_stores (PATTERN (insn
), mark_insn_reg_store
, insn
);
2226 for (link
= REG_NOTES (insn
); link
; link
= XEXP (link
, 1))
2227 if (REG_NOTE_KIND (link
) == REG_INC
)
2228 mark_insn_reg_store (XEXP (link
, 0), NULL_RTX
, insn
);
2231 for (link
= REG_NOTES (insn
); link
; link
= XEXP (link
, 1))
2232 if (REG_NOTE_KIND (link
) == REG_DEAD
)
2233 mark_reg_death (XEXP (link
, 0));
2235 len
= sizeof (struct reg_pressure_data
) * ira_pressure_classes_num
;
2237 = INSN_REG_PRESSURE (insn
) = (struct reg_pressure_data
*) xmalloc (len
);
2238 if (sched_pressure
== SCHED_PRESSURE_WEIGHTED
)
2239 INSN_MAX_REG_PRESSURE (insn
) = (int *) xcalloc (ira_pressure_classes_num
2241 for (i
= 0; i
< ira_pressure_classes_num
; i
++)
2243 cl
= ira_pressure_classes
[i
];
2244 pressure_info
[i
].clobber_increase
2245 = reg_pressure_info
[cl
].clobber_increase
;
2246 pressure_info
[i
].set_increase
= reg_pressure_info
[cl
].set_increase
;
2247 pressure_info
[i
].unused_set_increase
2248 = reg_pressure_info
[cl
].unused_set_increase
;
2249 pressure_info
[i
].change
= reg_pressure_info
[cl
].change
;
2256 /* Internal variable for sched_analyze_[12] () functions.
2257 If it is nonzero, this means that sched_analyze_[12] looks
2258 at the most toplevel SET. */
2259 static bool can_start_lhs_rhs_p
;
2261 /* Extend reg info for the deps context DEPS given that
2262 we have just generated a register numbered REGNO. */
2264 extend_deps_reg_info (struct deps_desc
*deps
, int regno
)
2266 int max_regno
= regno
+ 1;
2268 gcc_assert (!reload_completed
);
2270 /* In a readonly context, it would not hurt to extend info,
2271 but it should not be needed. */
2272 if (reload_completed
&& deps
->readonly
)
2274 deps
->max_reg
= max_regno
;
2278 if (max_regno
> deps
->max_reg
)
2280 deps
->reg_last
= XRESIZEVEC (struct deps_reg
, deps
->reg_last
,
2282 memset (&deps
->reg_last
[deps
->max_reg
],
2283 0, (max_regno
- deps
->max_reg
)
2284 * sizeof (struct deps_reg
));
2285 deps
->max_reg
= max_regno
;
2289 /* Extends REG_INFO_P if needed. */
2291 maybe_extend_reg_info_p (void)
2293 /* Extend REG_INFO_P, if needed. */
2294 if ((unsigned int)max_regno
- 1 >= reg_info_p_size
)
2296 size_t new_reg_info_p_size
= max_regno
+ 128;
2298 gcc_assert (!reload_completed
&& sel_sched_p ());
2300 reg_info_p
= (struct reg_info_t
*) xrecalloc (reg_info_p
,
2301 new_reg_info_p_size
,
2303 sizeof (*reg_info_p
));
2304 reg_info_p_size
= new_reg_info_p_size
;
2308 /* Analyze a single reference to register (reg:MODE REGNO) in INSN.
2309 The type of the reference is specified by REF and can be SET,
2310 CLOBBER, PRE_DEC, POST_DEC, PRE_INC, POST_INC or USE. */
2313 sched_analyze_reg (struct deps_desc
*deps
, int regno
, enum machine_mode mode
,
2314 enum rtx_code ref
, rtx_insn
*insn
)
2316 /* We could emit new pseudos in renaming. Extend the reg structures. */
2317 if (!reload_completed
&& sel_sched_p ()
2318 && (regno
>= max_reg_num () - 1 || regno
>= deps
->max_reg
))
2319 extend_deps_reg_info (deps
, regno
);
2321 maybe_extend_reg_info_p ();
2323 /* A hard reg in a wide mode may really be multiple registers.
2324 If so, mark all of them just like the first. */
2325 if (regno
< FIRST_PSEUDO_REGISTER
)
2327 int i
= hard_regno_nregs
[regno
][mode
];
2331 note_reg_set (regno
+ i
);
2333 else if (ref
== USE
)
2336 note_reg_use (regno
+ i
);
2341 note_reg_clobber (regno
+ i
);
2345 /* ??? Reload sometimes emits USEs and CLOBBERs of pseudos that
2346 it does not reload. Ignore these as they have served their
2348 else if (regno
>= deps
->max_reg
)
2350 enum rtx_code code
= GET_CODE (PATTERN (insn
));
2351 gcc_assert (code
== USE
|| code
== CLOBBER
);
2357 note_reg_set (regno
);
2358 else if (ref
== USE
)
2359 note_reg_use (regno
);
2361 note_reg_clobber (regno
);
2363 /* Pseudos that are REG_EQUIV to something may be replaced
2364 by that during reloading. We need only add dependencies for
2365 the address in the REG_EQUIV note. */
2366 if (!reload_completed
&& get_reg_known_equiv_p (regno
))
2368 rtx t
= get_reg_known_value (regno
);
2370 sched_analyze_2 (deps
, XEXP (t
, 0), insn
);
2373 /* Don't let it cross a call after scheduling if it doesn't
2374 already cross one. */
2375 if (REG_N_CALLS_CROSSED (regno
) == 0)
2377 if (!deps
->readonly
&& ref
== USE
&& !DEBUG_INSN_P (insn
))
2378 deps
->sched_before_next_call
2379 = alloc_INSN_LIST (insn
, deps
->sched_before_next_call
);
2381 add_dependence_list (insn
, deps
->last_function_call
, 1,
2382 REG_DEP_ANTI
, false);
2387 /* Analyze a single SET, CLOBBER, PRE_DEC, POST_DEC, PRE_INC or POST_INC
2388 rtx, X, creating all dependencies generated by the write to the
2389 destination of X, and reads of everything mentioned. */
2392 sched_analyze_1 (struct deps_desc
*deps
, rtx x
, rtx_insn
*insn
)
2394 rtx dest
= XEXP (x
, 0);
2395 enum rtx_code code
= GET_CODE (x
);
2396 bool cslr_p
= can_start_lhs_rhs_p
;
2398 can_start_lhs_rhs_p
= false;
2404 if (cslr_p
&& sched_deps_info
->start_lhs
)
2405 sched_deps_info
->start_lhs (dest
);
2407 if (GET_CODE (dest
) == PARALLEL
)
2411 for (i
= XVECLEN (dest
, 0) - 1; i
>= 0; i
--)
2412 if (XEXP (XVECEXP (dest
, 0, i
), 0) != 0)
2413 sched_analyze_1 (deps
,
2414 gen_rtx_CLOBBER (VOIDmode
,
2415 XEXP (XVECEXP (dest
, 0, i
), 0)),
2418 if (cslr_p
&& sched_deps_info
->finish_lhs
)
2419 sched_deps_info
->finish_lhs ();
2423 can_start_lhs_rhs_p
= cslr_p
;
2425 sched_analyze_2 (deps
, SET_SRC (x
), insn
);
2427 can_start_lhs_rhs_p
= false;
2433 while (GET_CODE (dest
) == STRICT_LOW_PART
|| GET_CODE (dest
) == SUBREG
2434 || GET_CODE (dest
) == ZERO_EXTRACT
)
2436 if (GET_CODE (dest
) == STRICT_LOW_PART
2437 || GET_CODE (dest
) == ZERO_EXTRACT
2438 || df_read_modify_subreg_p (dest
))
2440 /* These both read and modify the result. We must handle
2441 them as writes to get proper dependencies for following
2442 instructions. We must handle them as reads to get proper
2443 dependencies from this to previous instructions.
2444 Thus we need to call sched_analyze_2. */
2446 sched_analyze_2 (deps
, XEXP (dest
, 0), insn
);
2448 if (GET_CODE (dest
) == ZERO_EXTRACT
)
2450 /* The second and third arguments are values read by this insn. */
2451 sched_analyze_2 (deps
, XEXP (dest
, 1), insn
);
2452 sched_analyze_2 (deps
, XEXP (dest
, 2), insn
);
2454 dest
= XEXP (dest
, 0);
2459 int regno
= REGNO (dest
);
2460 enum machine_mode mode
= GET_MODE (dest
);
2462 sched_analyze_reg (deps
, regno
, mode
, code
, insn
);
2465 /* Treat all writes to a stack register as modifying the TOS. */
2466 if (regno
>= FIRST_STACK_REG
&& regno
<= LAST_STACK_REG
)
2468 /* Avoid analyzing the same register twice. */
2469 if (regno
!= FIRST_STACK_REG
)
2470 sched_analyze_reg (deps
, FIRST_STACK_REG
, mode
, code
, insn
);
2472 add_to_hard_reg_set (&implicit_reg_pending_uses
, mode
,
2477 else if (MEM_P (dest
))
2479 /* Writing memory. */
2482 if (sched_deps_info
->use_cselib
)
2484 enum machine_mode address_mode
= get_address_mode (dest
);
2486 t
= shallow_copy_rtx (dest
);
2487 cselib_lookup_from_insn (XEXP (t
, 0), address_mode
, 1,
2488 GET_MODE (t
), insn
);
2490 = cselib_subst_to_values_from_insn (XEXP (t
, 0), GET_MODE (t
),
2495 /* Pending lists can't get larger with a readonly context. */
2497 && ((deps
->pending_read_list_length
+ deps
->pending_write_list_length
)
2498 > MAX_PENDING_LIST_LENGTH
))
2500 /* Flush all pending reads and writes to prevent the pending lists
2501 from getting any larger. Insn scheduling runs too slowly when
2502 these lists get long. When compiling GCC with itself,
2503 this flush occurs 8 times for sparc, and 10 times for m88k using
2504 the default value of 32. */
2505 flush_pending_lists (deps
, insn
, false, true);
2509 rtx pending
, pending_mem
;
2511 pending
= deps
->pending_read_insns
;
2512 pending_mem
= deps
->pending_read_mems
;
2515 if (anti_dependence (XEXP (pending_mem
, 0), t
)
2516 && ! sched_insns_conditions_mutex_p (insn
, XEXP (pending
, 0)))
2517 note_mem_dep (t
, XEXP (pending_mem
, 0), as_a
<rtx_insn
*> (XEXP (pending
, 0)),
2520 pending
= XEXP (pending
, 1);
2521 pending_mem
= XEXP (pending_mem
, 1);
2524 pending
= deps
->pending_write_insns
;
2525 pending_mem
= deps
->pending_write_mems
;
2528 if (output_dependence (XEXP (pending_mem
, 0), t
)
2529 && ! sched_insns_conditions_mutex_p (insn
, XEXP (pending
, 0)))
2530 note_mem_dep (t
, XEXP (pending_mem
, 0),
2531 as_a
<rtx_insn
*> (XEXP (pending
, 0)),
2534 pending
= XEXP (pending
, 1);
2535 pending_mem
= XEXP (pending_mem
, 1);
2538 add_dependence_list (insn
, deps
->last_pending_memory_flush
, 1,
2539 REG_DEP_ANTI
, true);
2540 add_dependence_list (insn
, deps
->pending_jump_insns
, 1,
2541 REG_DEP_CONTROL
, true);
2543 if (!deps
->readonly
)
2544 add_insn_mem_dependence (deps
, false, insn
, dest
);
2546 sched_analyze_2 (deps
, XEXP (dest
, 0), insn
);
2549 if (cslr_p
&& sched_deps_info
->finish_lhs
)
2550 sched_deps_info
->finish_lhs ();
2552 /* Analyze reads. */
2553 if (GET_CODE (x
) == SET
)
2555 can_start_lhs_rhs_p
= cslr_p
;
2557 sched_analyze_2 (deps
, SET_SRC (x
), insn
);
2559 can_start_lhs_rhs_p
= false;
2563 /* Analyze the uses of memory and registers in rtx X in INSN. */
2565 sched_analyze_2 (struct deps_desc
*deps
, rtx x
, rtx_insn
*insn
)
2571 bool cslr_p
= can_start_lhs_rhs_p
;
2573 can_start_lhs_rhs_p
= false;
2579 if (cslr_p
&& sched_deps_info
->start_rhs
)
2580 sched_deps_info
->start_rhs (x
);
2582 code
= GET_CODE (x
);
2590 /* Ignore constants. */
2591 if (cslr_p
&& sched_deps_info
->finish_rhs
)
2592 sched_deps_info
->finish_rhs ();
2598 /* User of CC0 depends on immediately preceding insn. */
2599 SCHED_GROUP_P (insn
) = 1;
2600 /* Don't move CC0 setter to another block (it can set up the
2601 same flag for previous CC0 users which is safe). */
2602 CANT_MOVE (prev_nonnote_insn (insn
)) = 1;
2604 if (cslr_p
&& sched_deps_info
->finish_rhs
)
2605 sched_deps_info
->finish_rhs ();
2612 int regno
= REGNO (x
);
2613 enum machine_mode mode
= GET_MODE (x
);
2615 sched_analyze_reg (deps
, regno
, mode
, USE
, insn
);
2618 /* Treat all reads of a stack register as modifying the TOS. */
2619 if (regno
>= FIRST_STACK_REG
&& regno
<= LAST_STACK_REG
)
2621 /* Avoid analyzing the same register twice. */
2622 if (regno
!= FIRST_STACK_REG
)
2623 sched_analyze_reg (deps
, FIRST_STACK_REG
, mode
, USE
, insn
);
2624 sched_analyze_reg (deps
, FIRST_STACK_REG
, mode
, SET
, insn
);
2628 if (cslr_p
&& sched_deps_info
->finish_rhs
)
2629 sched_deps_info
->finish_rhs ();
2636 /* Reading memory. */
2638 rtx pending
, pending_mem
;
2641 if (sched_deps_info
->use_cselib
)
2643 enum machine_mode address_mode
= get_address_mode (t
);
2645 t
= shallow_copy_rtx (t
);
2646 cselib_lookup_from_insn (XEXP (t
, 0), address_mode
, 1,
2647 GET_MODE (t
), insn
);
2649 = cselib_subst_to_values_from_insn (XEXP (t
, 0), GET_MODE (t
),
2653 if (!DEBUG_INSN_P (insn
))
2656 pending
= deps
->pending_read_insns
;
2657 pending_mem
= deps
->pending_read_mems
;
2660 if (read_dependence (XEXP (pending_mem
, 0), t
)
2661 && ! sched_insns_conditions_mutex_p (insn
,
2663 note_mem_dep (t
, XEXP (pending_mem
, 0),
2664 as_a
<rtx_insn
*> (XEXP (pending
, 0)),
2667 pending
= XEXP (pending
, 1);
2668 pending_mem
= XEXP (pending_mem
, 1);
2671 pending
= deps
->pending_write_insns
;
2672 pending_mem
= deps
->pending_write_mems
;
2675 if (true_dependence (XEXP (pending_mem
, 0), VOIDmode
, t
)
2676 && ! sched_insns_conditions_mutex_p (insn
,
2678 note_mem_dep (t
, XEXP (pending_mem
, 0),
2679 as_a
<rtx_insn
*> (XEXP (pending
, 0)),
2680 sched_deps_info
->generate_spec_deps
2681 ? BEGIN_DATA
| DEP_TRUE
: DEP_TRUE
);
2683 pending
= XEXP (pending
, 1);
2684 pending_mem
= XEXP (pending_mem
, 1);
2687 for (u
= deps
->last_pending_memory_flush
; u
; u
= XEXP (u
, 1))
2688 add_dependence (insn
, as_a
<rtx_insn
*> (XEXP (u
, 0)),
2691 for (u
= deps
->pending_jump_insns
; u
; u
= XEXP (u
, 1))
2692 if (deps_may_trap_p (x
))
2694 if ((sched_deps_info
->generate_spec_deps
)
2695 && sel_sched_p () && (spec_info
->mask
& BEGIN_CONTROL
))
2697 ds_t ds
= set_dep_weak (DEP_ANTI
, BEGIN_CONTROL
,
2700 note_dep (as_a
<rtx_insn
*> (XEXP (u
, 0)), ds
);
2703 add_dependence (insn
, as_a
<rtx_insn
*> (XEXP (u
, 0)),
2708 /* Always add these dependencies to pending_reads, since
2709 this insn may be followed by a write. */
2710 if (!deps
->readonly
)
2712 if ((deps
->pending_read_list_length
2713 + deps
->pending_write_list_length
)
2714 > MAX_PENDING_LIST_LENGTH
2715 && !DEBUG_INSN_P (insn
))
2716 flush_pending_lists (deps
, insn
, true, true);
2717 add_insn_mem_dependence (deps
, true, insn
, x
);
2720 sched_analyze_2 (deps
, XEXP (x
, 0), insn
);
2722 if (cslr_p
&& sched_deps_info
->finish_rhs
)
2723 sched_deps_info
->finish_rhs ();
2728 /* Force pending stores to memory in case a trap handler needs them. */
2730 flush_pending_lists (deps
, insn
, true, false);
2734 if (PREFETCH_SCHEDULE_BARRIER_P (x
))
2735 reg_pending_barrier
= TRUE_BARRIER
;
2736 /* Prefetch insn contains addresses only. So if the prefetch
2737 address has no registers, there will be no dependencies on
2738 the prefetch insn. This is wrong with result code
2739 correctness point of view as such prefetch can be moved below
2740 a jump insn which usually generates MOVE_BARRIER preventing
2741 to move insns containing registers or memories through the
2742 barrier. It is also wrong with generated code performance
2743 point of view as prefetch withouth dependecies will have a
2744 tendency to be issued later instead of earlier. It is hard
2745 to generate accurate dependencies for prefetch insns as
2746 prefetch has only the start address but it is better to have
2747 something than nothing. */
2748 if (!deps
->readonly
)
2750 rtx x
= gen_rtx_MEM (Pmode
, XEXP (PATTERN (insn
), 0));
2751 if (sched_deps_info
->use_cselib
)
2752 cselib_lookup_from_insn (x
, Pmode
, true, VOIDmode
, insn
);
2753 add_insn_mem_dependence (deps
, true, insn
, x
);
2757 case UNSPEC_VOLATILE
:
2758 flush_pending_lists (deps
, insn
, true, true);
2764 /* Traditional and volatile asm instructions must be considered to use
2765 and clobber all hard registers, all pseudo-registers and all of
2766 memory. So must TRAP_IF and UNSPEC_VOLATILE operations.
2768 Consider for instance a volatile asm that changes the fpu rounding
2769 mode. An insn should not be moved across this even if it only uses
2770 pseudo-regs because it might give an incorrectly rounded result. */
2771 if ((code
!= ASM_OPERANDS
|| MEM_VOLATILE_P (x
))
2772 && !DEBUG_INSN_P (insn
))
2773 reg_pending_barrier
= TRUE_BARRIER
;
2775 /* For all ASM_OPERANDS, we must traverse the vector of input operands.
2776 We can not just fall through here since then we would be confused
2777 by the ASM_INPUT rtx inside ASM_OPERANDS, which do not indicate
2778 traditional asms unlike their normal usage. */
2780 if (code
== ASM_OPERANDS
)
2782 for (j
= 0; j
< ASM_OPERANDS_INPUT_LENGTH (x
); j
++)
2783 sched_analyze_2 (deps
, ASM_OPERANDS_INPUT (x
, j
), insn
);
2785 if (cslr_p
&& sched_deps_info
->finish_rhs
)
2786 sched_deps_info
->finish_rhs ();
2797 /* These both read and modify the result. We must handle them as writes
2798 to get proper dependencies for following instructions. We must handle
2799 them as reads to get proper dependencies from this to previous
2800 instructions. Thus we need to pass them to both sched_analyze_1
2801 and sched_analyze_2. We must call sched_analyze_2 first in order
2802 to get the proper antecedent for the read. */
2803 sched_analyze_2 (deps
, XEXP (x
, 0), insn
);
2804 sched_analyze_1 (deps
, x
, insn
);
2806 if (cslr_p
&& sched_deps_info
->finish_rhs
)
2807 sched_deps_info
->finish_rhs ();
2813 /* op0 = op0 + op1 */
2814 sched_analyze_2 (deps
, XEXP (x
, 0), insn
);
2815 sched_analyze_2 (deps
, XEXP (x
, 1), insn
);
2816 sched_analyze_1 (deps
, x
, insn
);
2818 if (cslr_p
&& sched_deps_info
->finish_rhs
)
2819 sched_deps_info
->finish_rhs ();
2827 /* Other cases: walk the insn. */
2828 fmt
= GET_RTX_FORMAT (code
);
2829 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2832 sched_analyze_2 (deps
, XEXP (x
, i
), insn
);
2833 else if (fmt
[i
] == 'E')
2834 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2835 sched_analyze_2 (deps
, XVECEXP (x
, i
, j
), insn
);
2838 if (cslr_p
&& sched_deps_info
->finish_rhs
)
2839 sched_deps_info
->finish_rhs ();
2842 /* Try to group two fuseable insns together to prevent scheduler
2843 from scheduling them apart. */
2846 sched_macro_fuse_insns (rtx_insn
*insn
)
2850 if (any_condjump_p (insn
))
2852 unsigned int condreg1
, condreg2
;
2854 targetm
.fixed_condition_code_regs (&condreg1
, &condreg2
);
2855 cc_reg_1
= gen_rtx_REG (CCmode
, condreg1
);
2856 prev
= prev_nonnote_nondebug_insn (insn
);
2857 if (!reg_referenced_p (cc_reg_1
, PATTERN (insn
))
2859 || !modified_in_p (cc_reg_1
, prev
))
2864 rtx insn_set
= single_set (insn
);
2866 prev
= prev_nonnote_nondebug_insn (insn
);
2869 || !single_set (prev
)
2870 || !modified_in_p (SET_DEST (insn_set
), prev
))
2875 if (targetm
.sched
.macro_fusion_pair_p (prev
, insn
))
2876 SCHED_GROUP_P (insn
) = 1;
2880 /* Analyze an INSN with pattern X to find all dependencies. */
2882 sched_analyze_insn (struct deps_desc
*deps
, rtx x
, rtx_insn
*insn
)
2884 RTX_CODE code
= GET_CODE (x
);
2887 reg_set_iterator rsi
;
2889 if (! reload_completed
)
2893 extract_insn (insn
);
2894 preprocess_constraints (insn
);
2895 ira_implicitly_set_insn_hard_regs (&temp
);
2896 AND_COMPL_HARD_REG_SET (temp
, ira_no_alloc_regs
);
2897 IOR_HARD_REG_SET (implicit_reg_pending_clobbers
, temp
);
2900 can_start_lhs_rhs_p
= (NONJUMP_INSN_P (insn
)
2903 /* Group compare and branch insns for macro-fusion. */
2904 if (targetm
.sched
.macro_fusion_p
2905 && targetm
.sched
.macro_fusion_p ())
2906 sched_macro_fuse_insns (insn
);
2909 /* Avoid moving trapping instructions across function calls that might
2910 not always return. */
2911 add_dependence_list (insn
, deps
->last_function_call_may_noreturn
,
2912 1, REG_DEP_ANTI
, true);
2914 /* We must avoid creating a situation in which two successors of the
2915 current block have different unwind info after scheduling. If at any
2916 point the two paths re-join this leads to incorrect unwind info. */
2917 /* ??? There are certain situations involving a forced frame pointer in
2918 which, with extra effort, we could fix up the unwind info at a later
2919 CFG join. However, it seems better to notice these cases earlier
2920 during prologue generation and avoid marking the frame pointer setup
2921 as frame-related at all. */
2922 if (RTX_FRAME_RELATED_P (insn
))
2924 /* Make sure prologue insn is scheduled before next jump. */
2925 deps
->sched_before_next_jump
2926 = alloc_INSN_LIST (insn
, deps
->sched_before_next_jump
);
2928 /* Make sure epilogue insn is scheduled after preceding jumps. */
2929 add_dependence_list (insn
, deps
->pending_jump_insns
, 1, REG_DEP_ANTI
,
2933 if (code
== COND_EXEC
)
2935 sched_analyze_2 (deps
, COND_EXEC_TEST (x
), insn
);
2937 /* ??? Should be recording conditions so we reduce the number of
2938 false dependencies. */
2939 x
= COND_EXEC_CODE (x
);
2940 code
= GET_CODE (x
);
2942 if (code
== SET
|| code
== CLOBBER
)
2944 sched_analyze_1 (deps
, x
, insn
);
2946 /* Bare clobber insns are used for letting life analysis, reg-stack
2947 and others know that a value is dead. Depend on the last call
2948 instruction so that reg-stack won't get confused. */
2949 if (code
== CLOBBER
)
2950 add_dependence_list (insn
, deps
->last_function_call
, 1,
2951 REG_DEP_OUTPUT
, true);
2953 else if (code
== PARALLEL
)
2955 for (i
= XVECLEN (x
, 0); i
--;)
2957 rtx sub
= XVECEXP (x
, 0, i
);
2958 code
= GET_CODE (sub
);
2960 if (code
== COND_EXEC
)
2962 sched_analyze_2 (deps
, COND_EXEC_TEST (sub
), insn
);
2963 sub
= COND_EXEC_CODE (sub
);
2964 code
= GET_CODE (sub
);
2966 if (code
== SET
|| code
== CLOBBER
)
2967 sched_analyze_1 (deps
, sub
, insn
);
2969 sched_analyze_2 (deps
, sub
, insn
);
2973 sched_analyze_2 (deps
, x
, insn
);
2975 /* Mark registers CLOBBERED or used by called function. */
2978 for (link
= CALL_INSN_FUNCTION_USAGE (insn
); link
; link
= XEXP (link
, 1))
2980 if (GET_CODE (XEXP (link
, 0)) == CLOBBER
)
2981 sched_analyze_1 (deps
, XEXP (link
, 0), insn
);
2982 else if (GET_CODE (XEXP (link
, 0)) != SET
)
2983 sched_analyze_2 (deps
, XEXP (link
, 0), insn
);
2985 /* Don't schedule anything after a tail call, tail call needs
2986 to use at least all call-saved registers. */
2987 if (SIBLING_CALL_P (insn
))
2988 reg_pending_barrier
= TRUE_BARRIER
;
2989 else if (find_reg_note (insn
, REG_SETJMP
, NULL
))
2990 reg_pending_barrier
= MOVE_BARRIER
;
2996 next
= next_nonnote_nondebug_insn (insn
);
2997 if (next
&& BARRIER_P (next
))
2998 reg_pending_barrier
= MOVE_BARRIER
;
3001 rtx pending
, pending_mem
;
3003 if (sched_deps_info
->compute_jump_reg_dependencies
)
3005 (*sched_deps_info
->compute_jump_reg_dependencies
)
3006 (insn
, reg_pending_control_uses
);
3008 /* Make latency of jump equal to 0 by using anti-dependence. */
3009 EXECUTE_IF_SET_IN_REG_SET (reg_pending_control_uses
, 0, i
, rsi
)
3011 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
3012 add_dependence_list (insn
, reg_last
->sets
, 0, REG_DEP_ANTI
,
3014 add_dependence_list (insn
, reg_last
->implicit_sets
,
3015 0, REG_DEP_ANTI
, false);
3016 add_dependence_list (insn
, reg_last
->clobbers
, 0,
3017 REG_DEP_ANTI
, false);
3021 /* All memory writes and volatile reads must happen before the
3022 jump. Non-volatile reads must happen before the jump iff
3023 the result is needed by the above register used mask. */
3025 pending
= deps
->pending_write_insns
;
3026 pending_mem
= deps
->pending_write_mems
;
3029 if (! sched_insns_conditions_mutex_p (insn
, XEXP (pending
, 0)))
3030 add_dependence (insn
, as_a
<rtx_insn
*> (XEXP (pending
, 0)),
3032 pending
= XEXP (pending
, 1);
3033 pending_mem
= XEXP (pending_mem
, 1);
3036 pending
= deps
->pending_read_insns
;
3037 pending_mem
= deps
->pending_read_mems
;
3040 if (MEM_VOLATILE_P (XEXP (pending_mem
, 0))
3041 && ! sched_insns_conditions_mutex_p (insn
, XEXP (pending
, 0)))
3042 add_dependence (insn
, as_a
<rtx_insn
*> (XEXP (pending
, 0)),
3044 pending
= XEXP (pending
, 1);
3045 pending_mem
= XEXP (pending_mem
, 1);
3048 add_dependence_list (insn
, deps
->last_pending_memory_flush
, 1,
3049 REG_DEP_ANTI
, true);
3050 add_dependence_list (insn
, deps
->pending_jump_insns
, 1,
3051 REG_DEP_ANTI
, true);
3055 /* If this instruction can throw an exception, then moving it changes
3056 where block boundaries fall. This is mighty confusing elsewhere.
3057 Therefore, prevent such an instruction from being moved. Same for
3058 non-jump instructions that define block boundaries.
3059 ??? Unclear whether this is still necessary in EBB mode. If not,
3060 add_branch_dependences should be adjusted for RGN mode instead. */
3061 if (((CALL_P (insn
) || JUMP_P (insn
)) && can_throw_internal (insn
))
3062 || (NONJUMP_INSN_P (insn
) && control_flow_insn_p (insn
)))
3063 reg_pending_barrier
= MOVE_BARRIER
;
3065 if (sched_pressure
!= SCHED_PRESSURE_NONE
)
3067 setup_insn_reg_uses (deps
, insn
);
3068 init_insn_reg_pressure_info (insn
);
3071 /* Add register dependencies for insn. */
3072 if (DEBUG_INSN_P (insn
))
3074 rtx_insn
*prev
= deps
->last_debug_insn
;
3077 if (!deps
->readonly
)
3078 deps
->last_debug_insn
= insn
;
3081 add_dependence (insn
, prev
, REG_DEP_ANTI
);
3083 add_dependence_list (insn
, deps
->last_function_call
, 1,
3084 REG_DEP_ANTI
, false);
3086 if (!sel_sched_p ())
3087 for (u
= deps
->last_pending_memory_flush
; u
; u
= XEXP (u
, 1))
3088 add_dependence (insn
, as_a
<rtx_insn
*> (XEXP (u
, 0)), REG_DEP_ANTI
);
3090 EXECUTE_IF_SET_IN_REG_SET (reg_pending_uses
, 0, i
, rsi
)
3092 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
3093 add_dependence_list (insn
, reg_last
->sets
, 1, REG_DEP_ANTI
, false);
3094 /* There's no point in making REG_DEP_CONTROL dependencies for
3096 add_dependence_list (insn
, reg_last
->clobbers
, 1, REG_DEP_ANTI
,
3099 if (!deps
->readonly
)
3100 reg_last
->uses
= alloc_INSN_LIST (insn
, reg_last
->uses
);
3102 CLEAR_REG_SET (reg_pending_uses
);
3104 /* Quite often, a debug insn will refer to stuff in the
3105 previous instruction, but the reason we want this
3106 dependency here is to make sure the scheduler doesn't
3107 gratuitously move a debug insn ahead. This could dirty
3108 DF flags and cause additional analysis that wouldn't have
3109 occurred in compilation without debug insns, and such
3110 additional analysis can modify the generated code. */
3111 prev
= PREV_INSN (insn
);
3113 if (prev
&& NONDEBUG_INSN_P (prev
))
3114 add_dependence (insn
, prev
, REG_DEP_ANTI
);
3118 regset_head set_or_clobbered
;
3120 EXECUTE_IF_SET_IN_REG_SET (reg_pending_uses
, 0, i
, rsi
)
3122 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
3123 add_dependence_list (insn
, reg_last
->sets
, 0, REG_DEP_TRUE
, false);
3124 add_dependence_list (insn
, reg_last
->implicit_sets
, 0, REG_DEP_ANTI
,
3126 add_dependence_list (insn
, reg_last
->clobbers
, 0, REG_DEP_TRUE
,
3129 if (!deps
->readonly
)
3131 reg_last
->uses
= alloc_INSN_LIST (insn
, reg_last
->uses
);
3132 reg_last
->uses_length
++;
3136 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3137 if (TEST_HARD_REG_BIT (implicit_reg_pending_uses
, i
))
3139 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
3140 add_dependence_list (insn
, reg_last
->sets
, 0, REG_DEP_TRUE
, false);
3141 add_dependence_list (insn
, reg_last
->implicit_sets
, 0,
3142 REG_DEP_ANTI
, false);
3143 add_dependence_list (insn
, reg_last
->clobbers
, 0, REG_DEP_TRUE
,
3146 if (!deps
->readonly
)
3148 reg_last
->uses
= alloc_INSN_LIST (insn
, reg_last
->uses
);
3149 reg_last
->uses_length
++;
3153 if (targetm
.sched
.exposed_pipeline
)
3155 INIT_REG_SET (&set_or_clobbered
);
3156 bitmap_ior (&set_or_clobbered
, reg_pending_clobbers
,
3158 EXECUTE_IF_SET_IN_REG_SET (&set_or_clobbered
, 0, i
, rsi
)
3160 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
3162 for (list
= reg_last
->uses
; list
; list
= XEXP (list
, 1))
3164 rtx other
= XEXP (list
, 0);
3165 if (INSN_CACHED_COND (other
) != const_true_rtx
3166 && refers_to_regno_p (i
, i
+ 1, INSN_CACHED_COND (other
), NULL
))
3167 INSN_CACHED_COND (other
) = const_true_rtx
;
3172 /* If the current insn is conditional, we can't free any
3174 if (sched_has_condition_p (insn
))
3176 EXECUTE_IF_SET_IN_REG_SET (reg_pending_clobbers
, 0, i
, rsi
)
3178 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
3179 add_dependence_list (insn
, reg_last
->sets
, 0, REG_DEP_OUTPUT
,
3181 add_dependence_list (insn
, reg_last
->implicit_sets
, 0,
3182 REG_DEP_ANTI
, false);
3183 add_dependence_list (insn
, reg_last
->uses
, 0, REG_DEP_ANTI
,
3185 add_dependence_list (insn
, reg_last
->control_uses
, 0,
3186 REG_DEP_CONTROL
, false);
3188 if (!deps
->readonly
)
3191 = alloc_INSN_LIST (insn
, reg_last
->clobbers
);
3192 reg_last
->clobbers_length
++;
3195 EXECUTE_IF_SET_IN_REG_SET (reg_pending_sets
, 0, i
, rsi
)
3197 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
3198 add_dependence_list (insn
, reg_last
->sets
, 0, REG_DEP_OUTPUT
,
3200 add_dependence_list (insn
, reg_last
->implicit_sets
, 0,
3201 REG_DEP_ANTI
, false);
3202 add_dependence_list (insn
, reg_last
->clobbers
, 0, REG_DEP_OUTPUT
,
3204 add_dependence_list (insn
, reg_last
->uses
, 0, REG_DEP_ANTI
,
3206 add_dependence_list (insn
, reg_last
->control_uses
, 0,
3207 REG_DEP_CONTROL
, false);
3209 if (!deps
->readonly
)
3210 reg_last
->sets
= alloc_INSN_LIST (insn
, reg_last
->sets
);
3215 EXECUTE_IF_SET_IN_REG_SET (reg_pending_clobbers
, 0, i
, rsi
)
3217 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
3218 if (reg_last
->uses_length
> MAX_PENDING_LIST_LENGTH
3219 || reg_last
->clobbers_length
> MAX_PENDING_LIST_LENGTH
)
3221 add_dependence_list_and_free (deps
, insn
, ®_last
->sets
, 0,
3222 REG_DEP_OUTPUT
, false);
3223 add_dependence_list_and_free (deps
, insn
,
3224 ®_last
->implicit_sets
, 0,
3225 REG_DEP_ANTI
, false);
3226 add_dependence_list_and_free (deps
, insn
, ®_last
->uses
, 0,
3227 REG_DEP_ANTI
, false);
3228 add_dependence_list_and_free (deps
, insn
,
3229 ®_last
->control_uses
, 0,
3230 REG_DEP_ANTI
, false);
3231 add_dependence_list_and_free (deps
, insn
,
3232 ®_last
->clobbers
, 0,
3233 REG_DEP_OUTPUT
, false);
3235 if (!deps
->readonly
)
3237 reg_last
->sets
= alloc_INSN_LIST (insn
, reg_last
->sets
);
3238 reg_last
->clobbers_length
= 0;
3239 reg_last
->uses_length
= 0;
3244 add_dependence_list (insn
, reg_last
->sets
, 0, REG_DEP_OUTPUT
,
3246 add_dependence_list (insn
, reg_last
->implicit_sets
, 0,
3247 REG_DEP_ANTI
, false);
3248 add_dependence_list (insn
, reg_last
->uses
, 0, REG_DEP_ANTI
,
3250 add_dependence_list (insn
, reg_last
->control_uses
, 0,
3251 REG_DEP_CONTROL
, false);
3254 if (!deps
->readonly
)
3256 reg_last
->clobbers_length
++;
3258 = alloc_INSN_LIST (insn
, reg_last
->clobbers
);
3261 EXECUTE_IF_SET_IN_REG_SET (reg_pending_sets
, 0, i
, rsi
)
3263 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
3265 add_dependence_list_and_free (deps
, insn
, ®_last
->sets
, 0,
3266 REG_DEP_OUTPUT
, false);
3267 add_dependence_list_and_free (deps
, insn
,
3268 ®_last
->implicit_sets
,
3269 0, REG_DEP_ANTI
, false);
3270 add_dependence_list_and_free (deps
, insn
, ®_last
->clobbers
, 0,
3271 REG_DEP_OUTPUT
, false);
3272 add_dependence_list_and_free (deps
, insn
, ®_last
->uses
, 0,
3273 REG_DEP_ANTI
, false);
3274 add_dependence_list (insn
, reg_last
->control_uses
, 0,
3275 REG_DEP_CONTROL
, false);
3277 if (!deps
->readonly
)
3279 reg_last
->sets
= alloc_INSN_LIST (insn
, reg_last
->sets
);
3280 reg_last
->uses_length
= 0;
3281 reg_last
->clobbers_length
= 0;
3285 if (!deps
->readonly
)
3287 EXECUTE_IF_SET_IN_REG_SET (reg_pending_control_uses
, 0, i
, rsi
)
3289 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
3290 reg_last
->control_uses
3291 = alloc_INSN_LIST (insn
, reg_last
->control_uses
);
3296 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3297 if (TEST_HARD_REG_BIT (implicit_reg_pending_clobbers
, i
))
3299 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
3300 add_dependence_list (insn
, reg_last
->sets
, 0, REG_DEP_ANTI
, false);
3301 add_dependence_list (insn
, reg_last
->clobbers
, 0, REG_DEP_ANTI
, false);
3302 add_dependence_list (insn
, reg_last
->uses
, 0, REG_DEP_ANTI
, false);
3303 add_dependence_list (insn
, reg_last
->control_uses
, 0, REG_DEP_ANTI
,
3306 if (!deps
->readonly
)
3307 reg_last
->implicit_sets
3308 = alloc_INSN_LIST (insn
, reg_last
->implicit_sets
);
3311 if (!deps
->readonly
)
3313 IOR_REG_SET (&deps
->reg_last_in_use
, reg_pending_uses
);
3314 IOR_REG_SET (&deps
->reg_last_in_use
, reg_pending_clobbers
);
3315 IOR_REG_SET (&deps
->reg_last_in_use
, reg_pending_sets
);
3316 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3317 if (TEST_HARD_REG_BIT (implicit_reg_pending_uses
, i
)
3318 || TEST_HARD_REG_BIT (implicit_reg_pending_clobbers
, i
))
3319 SET_REGNO_REG_SET (&deps
->reg_last_in_use
, i
);
3321 /* Set up the pending barrier found. */
3322 deps
->last_reg_pending_barrier
= reg_pending_barrier
;
3325 CLEAR_REG_SET (reg_pending_uses
);
3326 CLEAR_REG_SET (reg_pending_clobbers
);
3327 CLEAR_REG_SET (reg_pending_sets
);
3328 CLEAR_REG_SET (reg_pending_control_uses
);
3329 CLEAR_HARD_REG_SET (implicit_reg_pending_clobbers
);
3330 CLEAR_HARD_REG_SET (implicit_reg_pending_uses
);
3332 /* Add dependencies if a scheduling barrier was found. */
3333 if (reg_pending_barrier
)
3335 /* In the case of barrier the most added dependencies are not
3336 real, so we use anti-dependence here. */
3337 if (sched_has_condition_p (insn
))
3339 EXECUTE_IF_SET_IN_REG_SET (&deps
->reg_last_in_use
, 0, i
, rsi
)
3341 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
3342 add_dependence_list (insn
, reg_last
->uses
, 0, REG_DEP_ANTI
,
3344 add_dependence_list (insn
, reg_last
->sets
, 0,
3345 reg_pending_barrier
== TRUE_BARRIER
3346 ? REG_DEP_TRUE
: REG_DEP_ANTI
, true);
3347 add_dependence_list (insn
, reg_last
->implicit_sets
, 0,
3348 REG_DEP_ANTI
, true);
3349 add_dependence_list (insn
, reg_last
->clobbers
, 0,
3350 reg_pending_barrier
== TRUE_BARRIER
3351 ? REG_DEP_TRUE
: REG_DEP_ANTI
, true);
3356 EXECUTE_IF_SET_IN_REG_SET (&deps
->reg_last_in_use
, 0, i
, rsi
)
3358 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
3359 add_dependence_list_and_free (deps
, insn
, ®_last
->uses
, 0,
3360 REG_DEP_ANTI
, true);
3361 add_dependence_list_and_free (deps
, insn
,
3362 ®_last
->control_uses
, 0,
3363 REG_DEP_CONTROL
, true);
3364 add_dependence_list_and_free (deps
, insn
, ®_last
->sets
, 0,
3365 reg_pending_barrier
== TRUE_BARRIER
3366 ? REG_DEP_TRUE
: REG_DEP_ANTI
,
3368 add_dependence_list_and_free (deps
, insn
,
3369 ®_last
->implicit_sets
, 0,
3370 REG_DEP_ANTI
, true);
3371 add_dependence_list_and_free (deps
, insn
, ®_last
->clobbers
, 0,
3372 reg_pending_barrier
== TRUE_BARRIER
3373 ? REG_DEP_TRUE
: REG_DEP_ANTI
,
3376 if (!deps
->readonly
)
3378 reg_last
->uses_length
= 0;
3379 reg_last
->clobbers_length
= 0;
3384 if (!deps
->readonly
)
3385 for (i
= 0; i
< (unsigned)deps
->max_reg
; i
++)
3387 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
3388 reg_last
->sets
= alloc_INSN_LIST (insn
, reg_last
->sets
);
3389 SET_REGNO_REG_SET (&deps
->reg_last_in_use
, i
);
3392 /* Don't flush pending lists on speculative checks for
3393 selective scheduling. */
3394 if (!sel_sched_p () || !sel_insn_is_speculation_check (insn
))
3395 flush_pending_lists (deps
, insn
, true, true);
3397 reg_pending_barrier
= NOT_A_BARRIER
;
3400 /* If a post-call group is still open, see if it should remain so.
3401 This insn must be a simple move of a hard reg to a pseudo or
3404 We must avoid moving these insns for correctness on targets
3405 with small register classes, and for special registers like
3406 PIC_OFFSET_TABLE_REGNUM. For simplicity, extend this to all
3407 hard regs for all targets. */
3409 if (deps
->in_post_call_group_p
)
3411 rtx tmp
, set
= single_set (insn
);
3412 int src_regno
, dest_regno
;
3416 if (DEBUG_INSN_P (insn
))
3417 /* We don't want to mark debug insns as part of the same
3418 sched group. We know they really aren't, but if we use
3419 debug insns to tell that a call group is over, we'll
3420 get different code if debug insns are not there and
3421 instructions that follow seem like they should be part
3424 Also, if we did, chain_to_prev_insn would move the
3425 deps of the debug insn to the call insn, modifying
3426 non-debug post-dependency counts of the debug insn
3427 dependencies and otherwise messing with the scheduling
3430 Instead, let such debug insns be scheduled freely, but
3431 keep the call group open in case there are insns that
3432 should be part of it afterwards. Since we grant debug
3433 insns higher priority than even sched group insns, it
3434 will all turn out all right. */
3435 goto debug_dont_end_call_group
;
3437 goto end_call_group
;
3440 tmp
= SET_DEST (set
);
3441 if (GET_CODE (tmp
) == SUBREG
)
3442 tmp
= SUBREG_REG (tmp
);
3444 dest_regno
= REGNO (tmp
);
3446 goto end_call_group
;
3448 tmp
= SET_SRC (set
);
3449 if (GET_CODE (tmp
) == SUBREG
)
3450 tmp
= SUBREG_REG (tmp
);
3451 if ((GET_CODE (tmp
) == PLUS
3452 || GET_CODE (tmp
) == MINUS
)
3453 && REG_P (XEXP (tmp
, 0))
3454 && REGNO (XEXP (tmp
, 0)) == STACK_POINTER_REGNUM
3455 && dest_regno
== STACK_POINTER_REGNUM
)
3456 src_regno
= STACK_POINTER_REGNUM
;
3457 else if (REG_P (tmp
))
3458 src_regno
= REGNO (tmp
);
3460 goto end_call_group
;
3462 if (src_regno
< FIRST_PSEUDO_REGISTER
3463 || dest_regno
< FIRST_PSEUDO_REGISTER
)
3466 && deps
->in_post_call_group_p
== post_call_initial
)
3467 deps
->in_post_call_group_p
= post_call
;
3469 if (!sel_sched_p () || sched_emulate_haifa_p
)
3471 SCHED_GROUP_P (insn
) = 1;
3472 CANT_MOVE (insn
) = 1;
3478 if (!deps
->readonly
)
3479 deps
->in_post_call_group_p
= not_post_call
;
3483 debug_dont_end_call_group
:
3484 if ((current_sched_info
->flags
& DO_SPECULATION
)
3485 && !sched_insn_is_legitimate_for_speculation_p (insn
, 0))
3486 /* INSN has an internal dependency (e.g. r14 = [r14]) and thus cannot
3490 sel_mark_hard_insn (insn
);
3493 sd_iterator_def sd_it
;
3496 for (sd_it
= sd_iterator_start (insn
, SD_LIST_SPEC_BACK
);
3497 sd_iterator_cond (&sd_it
, &dep
);)
3498 change_spec_dep_to_hard (sd_it
);
3502 /* We do not yet have code to adjust REG_ARGS_SIZE, therefore we must
3503 honor their original ordering. */
3504 if (find_reg_note (insn
, REG_ARGS_SIZE
, NULL
))
3506 if (deps
->last_args_size
)
3507 add_dependence (insn
, deps
->last_args_size
, REG_DEP_OUTPUT
);
3508 deps
->last_args_size
= insn
;
3512 /* Return TRUE if INSN might not always return normally (e.g. call exit,
3513 longjmp, loop forever, ...). */
3514 /* FIXME: Why can't this function just use flags_from_decl_or_type and
3515 test for ECF_NORETURN? */
3517 call_may_noreturn_p (rtx insn
)
3521 /* const or pure calls that aren't looping will always return. */
3522 if (RTL_CONST_OR_PURE_CALL_P (insn
)
3523 && !RTL_LOOPING_CONST_OR_PURE_CALL_P (insn
))
3526 call
= get_call_rtx_from (insn
);
3527 if (call
&& GET_CODE (XEXP (XEXP (call
, 0), 0)) == SYMBOL_REF
)
3529 rtx symbol
= XEXP (XEXP (call
, 0), 0);
3530 if (SYMBOL_REF_DECL (symbol
)
3531 && TREE_CODE (SYMBOL_REF_DECL (symbol
)) == FUNCTION_DECL
)
3533 if (DECL_BUILT_IN_CLASS (SYMBOL_REF_DECL (symbol
))
3535 switch (DECL_FUNCTION_CODE (SYMBOL_REF_DECL (symbol
)))
3538 case BUILT_IN_BCOPY
:
3539 case BUILT_IN_BZERO
:
3540 case BUILT_IN_INDEX
:
3541 case BUILT_IN_MEMCHR
:
3542 case BUILT_IN_MEMCMP
:
3543 case BUILT_IN_MEMCPY
:
3544 case BUILT_IN_MEMMOVE
:
3545 case BUILT_IN_MEMPCPY
:
3546 case BUILT_IN_MEMSET
:
3547 case BUILT_IN_RINDEX
:
3548 case BUILT_IN_STPCPY
:
3549 case BUILT_IN_STPNCPY
:
3550 case BUILT_IN_STRCAT
:
3551 case BUILT_IN_STRCHR
:
3552 case BUILT_IN_STRCMP
:
3553 case BUILT_IN_STRCPY
:
3554 case BUILT_IN_STRCSPN
:
3555 case BUILT_IN_STRLEN
:
3556 case BUILT_IN_STRNCAT
:
3557 case BUILT_IN_STRNCMP
:
3558 case BUILT_IN_STRNCPY
:
3559 case BUILT_IN_STRPBRK
:
3560 case BUILT_IN_STRRCHR
:
3561 case BUILT_IN_STRSPN
:
3562 case BUILT_IN_STRSTR
:
3563 /* Assume certain string/memory builtins always return. */
3571 /* For all other calls assume that they might not always return. */
3575 /* Return true if INSN should be made dependent on the previous instruction
3576 group, and if all INSN's dependencies should be moved to the first
3577 instruction of that group. */
3580 chain_to_prev_insn_p (rtx insn
)
3584 /* INSN forms a group with the previous instruction. */
3585 if (SCHED_GROUP_P (insn
))
3588 /* If the previous instruction clobbers a register R and this one sets
3589 part of R, the clobber was added specifically to help us track the
3590 liveness of R. There's no point scheduling the clobber and leaving
3591 INSN behind, especially if we move the clobber to another block. */
3592 prev
= prev_nonnote_nondebug_insn (insn
);
3595 && BLOCK_FOR_INSN (prev
) == BLOCK_FOR_INSN (insn
)
3596 && GET_CODE (PATTERN (prev
)) == CLOBBER
)
3598 x
= XEXP (PATTERN (prev
), 0);
3599 if (set_of (x
, insn
))
3606 /* Analyze INSN with DEPS as a context. */
3608 deps_analyze_insn (struct deps_desc
*deps
, rtx_insn
*insn
)
3610 if (sched_deps_info
->start_insn
)
3611 sched_deps_info
->start_insn (insn
);
3613 /* Record the condition for this insn. */
3614 if (NONDEBUG_INSN_P (insn
))
3617 sched_get_condition_with_rev (insn
, NULL
);
3618 t
= INSN_CACHED_COND (insn
);
3619 INSN_COND_DEPS (insn
) = NULL
;
3620 if (reload_completed
3621 && (current_sched_info
->flags
& DO_PREDICATION
)
3623 && REG_P (XEXP (t
, 0))
3624 && CONSTANT_P (XEXP (t
, 1)))
3628 rtx_insn_list
*cond_deps
= NULL
;
3631 nregs
= hard_regno_nregs
[regno
][GET_MODE (t
)];
3634 struct deps_reg
*reg_last
= &deps
->reg_last
[regno
+ nregs
];
3635 cond_deps
= concat_INSN_LIST (reg_last
->sets
, cond_deps
);
3636 cond_deps
= concat_INSN_LIST (reg_last
->clobbers
, cond_deps
);
3637 cond_deps
= concat_INSN_LIST (reg_last
->implicit_sets
, cond_deps
);
3639 INSN_COND_DEPS (insn
) = cond_deps
;
3645 /* Make each JUMP_INSN (but not a speculative check)
3646 a scheduling barrier for memory references. */
3649 && sel_insn_is_speculation_check (insn
)))
3651 /* Keep the list a reasonable size. */
3652 if (deps
->pending_flush_length
++ > MAX_PENDING_LIST_LENGTH
)
3653 flush_pending_lists (deps
, insn
, true, true);
3655 deps
->pending_jump_insns
3656 = alloc_INSN_LIST (insn
, deps
->pending_jump_insns
);
3659 /* For each insn which shouldn't cross a jump, add a dependence. */
3660 add_dependence_list_and_free (deps
, insn
,
3661 &deps
->sched_before_next_jump
, 1,
3662 REG_DEP_ANTI
, true);
3664 sched_analyze_insn (deps
, PATTERN (insn
), insn
);
3666 else if (NONJUMP_INSN_P (insn
) || DEBUG_INSN_P (insn
))
3668 sched_analyze_insn (deps
, PATTERN (insn
), insn
);
3670 else if (CALL_P (insn
))
3674 CANT_MOVE (insn
) = 1;
3676 if (find_reg_note (insn
, REG_SETJMP
, NULL
))
3678 /* This is setjmp. Assume that all registers, not just
3679 hard registers, may be clobbered by this call. */
3680 reg_pending_barrier
= MOVE_BARRIER
;
3684 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3685 /* A call may read and modify global register variables. */
3688 SET_REGNO_REG_SET (reg_pending_sets
, i
);
3689 SET_HARD_REG_BIT (implicit_reg_pending_uses
, i
);
3691 /* Other call-clobbered hard regs may be clobbered.
3692 Since we only have a choice between 'might be clobbered'
3693 and 'definitely not clobbered', we must include all
3694 partly call-clobbered registers here. */
3695 else if (HARD_REGNO_CALL_PART_CLOBBERED (i
, reg_raw_mode
[i
])
3696 || TEST_HARD_REG_BIT (regs_invalidated_by_call
, i
))
3697 SET_REGNO_REG_SET (reg_pending_clobbers
, i
);
3698 /* We don't know what set of fixed registers might be used
3699 by the function, but it is certain that the stack pointer
3700 is among them, but be conservative. */
3701 else if (fixed_regs
[i
])
3702 SET_HARD_REG_BIT (implicit_reg_pending_uses
, i
);
3703 /* The frame pointer is normally not used by the function
3704 itself, but by the debugger. */
3705 /* ??? MIPS o32 is an exception. It uses the frame pointer
3706 in the macro expansion of jal but does not represent this
3707 fact in the call_insn rtl. */
3708 else if (i
== FRAME_POINTER_REGNUM
3709 || (i
== HARD_FRAME_POINTER_REGNUM
3710 && (! reload_completed
|| frame_pointer_needed
)))
3711 SET_HARD_REG_BIT (implicit_reg_pending_uses
, i
);
3714 /* For each insn which shouldn't cross a call, add a dependence
3715 between that insn and this call insn. */
3716 add_dependence_list_and_free (deps
, insn
,
3717 &deps
->sched_before_next_call
, 1,
3718 REG_DEP_ANTI
, true);
3720 sched_analyze_insn (deps
, PATTERN (insn
), insn
);
3722 /* If CALL would be in a sched group, then this will violate
3723 convention that sched group insns have dependencies only on the
3724 previous instruction.
3726 Of course one can say: "Hey! What about head of the sched group?"
3727 And I will answer: "Basic principles (one dep per insn) are always
3729 gcc_assert (!SCHED_GROUP_P (insn
));
3731 /* In the absence of interprocedural alias analysis, we must flush
3732 all pending reads and writes, and start new dependencies starting
3733 from here. But only flush writes for constant calls (which may
3734 be passed a pointer to something we haven't written yet). */
3735 flush_pending_lists (deps
, insn
, true, ! RTL_CONST_OR_PURE_CALL_P (insn
));
3737 if (!deps
->readonly
)
3739 /* Remember the last function call for limiting lifetimes. */
3740 free_INSN_LIST_list (&deps
->last_function_call
);
3741 deps
->last_function_call
= alloc_INSN_LIST (insn
, NULL_RTX
);
3743 if (call_may_noreturn_p (insn
))
3745 /* Remember the last function call that might not always return
3746 normally for limiting moves of trapping insns. */
3747 free_INSN_LIST_list (&deps
->last_function_call_may_noreturn
);
3748 deps
->last_function_call_may_noreturn
3749 = alloc_INSN_LIST (insn
, NULL_RTX
);
3752 /* Before reload, begin a post-call group, so as to keep the
3753 lifetimes of hard registers correct. */
3754 if (! reload_completed
)
3755 deps
->in_post_call_group_p
= post_call
;
3759 if (sched_deps_info
->use_cselib
)
3760 cselib_process_insn (insn
);
3762 if (sched_deps_info
->finish_insn
)
3763 sched_deps_info
->finish_insn ();
3765 /* Fixup the dependencies in the sched group. */
3766 if ((NONJUMP_INSN_P (insn
) || JUMP_P (insn
))
3767 && chain_to_prev_insn_p (insn
)
3769 chain_to_prev_insn (insn
);
3772 /* Initialize DEPS for the new block beginning with HEAD. */
3774 deps_start_bb (struct deps_desc
*deps
, rtx head
)
3776 gcc_assert (!deps
->readonly
);
3778 /* Before reload, if the previous block ended in a call, show that
3779 we are inside a post-call group, so as to keep the lifetimes of
3780 hard registers correct. */
3781 if (! reload_completed
&& !LABEL_P (head
))
3783 rtx insn
= prev_nonnote_nondebug_insn (head
);
3785 if (insn
&& CALL_P (insn
))
3786 deps
->in_post_call_group_p
= post_call_initial
;
3790 /* Analyze every insn between HEAD and TAIL inclusive, creating backward
3791 dependencies for each insn. */
3793 sched_analyze (struct deps_desc
*deps
, rtx_insn
*head
, rtx_insn
*tail
)
3797 if (sched_deps_info
->use_cselib
)
3798 cselib_init (CSELIB_RECORD_MEMORY
);
3800 deps_start_bb (deps
, head
);
3802 for (insn
= head
;; insn
= NEXT_INSN (insn
))
3807 /* And initialize deps_lists. */
3808 sd_init_insn (insn
);
3809 /* Clean up SCHED_GROUP_P which may be set by last
3811 if (SCHED_GROUP_P (insn
))
3812 SCHED_GROUP_P (insn
) = 0;
3815 deps_analyze_insn (deps
, insn
);
3819 if (sched_deps_info
->use_cselib
)
3827 /* Helper for sched_free_deps ().
3828 Delete INSN's (RESOLVED_P) backward dependencies. */
3830 delete_dep_nodes_in_back_deps (rtx insn
, bool resolved_p
)
3832 sd_iterator_def sd_it
;
3834 sd_list_types_def types
;
3837 types
= SD_LIST_RES_BACK
;
3839 types
= SD_LIST_BACK
;
3841 for (sd_it
= sd_iterator_start (insn
, types
);
3842 sd_iterator_cond (&sd_it
, &dep
);)
3844 dep_link_t link
= *sd_it
.linkp
;
3845 dep_node_t node
= DEP_LINK_NODE (link
);
3846 deps_list_t back_list
;
3847 deps_list_t forw_list
;
3849 get_back_and_forw_lists (dep
, resolved_p
, &back_list
, &forw_list
);
3850 remove_from_deps_list (link
, back_list
);
3851 delete_dep_node (node
);
3855 /* Delete (RESOLVED_P) dependencies between HEAD and TAIL together with
3858 sched_free_deps (rtx_insn
*head
, rtx_insn
*tail
, bool resolved_p
)
3861 rtx_insn
*next_tail
= NEXT_INSN (tail
);
3863 /* We make two passes since some insns may be scheduled before their
3864 dependencies are resolved. */
3865 for (insn
= head
; insn
!= next_tail
; insn
= NEXT_INSN (insn
))
3866 if (INSN_P (insn
) && INSN_LUID (insn
) > 0)
3868 /* Clear forward deps and leave the dep_nodes to the
3869 corresponding back_deps list. */
3871 clear_deps_list (INSN_RESOLVED_FORW_DEPS (insn
));
3873 clear_deps_list (INSN_FORW_DEPS (insn
));
3875 for (insn
= head
; insn
!= next_tail
; insn
= NEXT_INSN (insn
))
3876 if (INSN_P (insn
) && INSN_LUID (insn
) > 0)
3878 /* Clear resolved back deps together with its dep_nodes. */
3879 delete_dep_nodes_in_back_deps (insn
, resolved_p
);
3881 sd_finish_insn (insn
);
3885 /* Initialize variables for region data dependence analysis.
3886 When LAZY_REG_LAST is true, do not allocate reg_last array
3887 of struct deps_desc immediately. */
3890 init_deps (struct deps_desc
*deps
, bool lazy_reg_last
)
3892 int max_reg
= (reload_completed
? FIRST_PSEUDO_REGISTER
: max_reg_num ());
3894 deps
->max_reg
= max_reg
;
3896 deps
->reg_last
= NULL
;
3898 deps
->reg_last
= XCNEWVEC (struct deps_reg
, max_reg
);
3899 INIT_REG_SET (&deps
->reg_last_in_use
);
3901 deps
->pending_read_insns
= 0;
3902 deps
->pending_read_mems
= 0;
3903 deps
->pending_write_insns
= 0;
3904 deps
->pending_write_mems
= 0;
3905 deps
->pending_jump_insns
= 0;
3906 deps
->pending_read_list_length
= 0;
3907 deps
->pending_write_list_length
= 0;
3908 deps
->pending_flush_length
= 0;
3909 deps
->last_pending_memory_flush
= 0;
3910 deps
->last_function_call
= 0;
3911 deps
->last_function_call_may_noreturn
= 0;
3912 deps
->sched_before_next_call
= 0;
3913 deps
->sched_before_next_jump
= 0;
3914 deps
->in_post_call_group_p
= not_post_call
;
3915 deps
->last_debug_insn
= 0;
3916 deps
->last_args_size
= 0;
3917 deps
->last_reg_pending_barrier
= NOT_A_BARRIER
;
3921 /* Init only reg_last field of DEPS, which was not allocated before as
3922 we inited DEPS lazily. */
3924 init_deps_reg_last (struct deps_desc
*deps
)
3926 gcc_assert (deps
&& deps
->max_reg
> 0);
3927 gcc_assert (deps
->reg_last
== NULL
);
3929 deps
->reg_last
= XCNEWVEC (struct deps_reg
, deps
->max_reg
);
3933 /* Free insn lists found in DEPS. */
3936 free_deps (struct deps_desc
*deps
)
3939 reg_set_iterator rsi
;
3941 /* We set max_reg to 0 when this context was already freed. */
3942 if (deps
->max_reg
== 0)
3944 gcc_assert (deps
->reg_last
== NULL
);
3949 free_INSN_LIST_list (&deps
->pending_read_insns
);
3950 free_EXPR_LIST_list (&deps
->pending_read_mems
);
3951 free_INSN_LIST_list (&deps
->pending_write_insns
);
3952 free_EXPR_LIST_list (&deps
->pending_write_mems
);
3953 free_INSN_LIST_list (&deps
->last_pending_memory_flush
);
3955 /* Without the EXECUTE_IF_SET, this loop is executed max_reg * nr_regions
3956 times. For a testcase with 42000 regs and 8000 small basic blocks,
3957 this loop accounted for nearly 60% (84 sec) of the total -O2 runtime. */
3958 EXECUTE_IF_SET_IN_REG_SET (&deps
->reg_last_in_use
, 0, i
, rsi
)
3960 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
3962 free_INSN_LIST_list (®_last
->uses
);
3964 free_INSN_LIST_list (®_last
->sets
);
3965 if (reg_last
->implicit_sets
)
3966 free_INSN_LIST_list (®_last
->implicit_sets
);
3967 if (reg_last
->control_uses
)
3968 free_INSN_LIST_list (®_last
->control_uses
);
3969 if (reg_last
->clobbers
)
3970 free_INSN_LIST_list (®_last
->clobbers
);
3972 CLEAR_REG_SET (&deps
->reg_last_in_use
);
3974 /* As we initialize reg_last lazily, it is possible that we didn't allocate
3976 free (deps
->reg_last
);
3977 deps
->reg_last
= NULL
;
3982 /* Remove INSN from dependence contexts DEPS. */
3984 remove_from_deps (struct deps_desc
*deps
, rtx_insn
*insn
)
3988 reg_set_iterator rsi
;
3990 removed
= remove_from_both_dependence_lists (insn
, &deps
->pending_read_insns
,
3991 &deps
->pending_read_mems
);
3992 if (!DEBUG_INSN_P (insn
))
3993 deps
->pending_read_list_length
-= removed
;
3994 removed
= remove_from_both_dependence_lists (insn
, &deps
->pending_write_insns
,
3995 &deps
->pending_write_mems
);
3996 deps
->pending_write_list_length
-= removed
;
3998 removed
= remove_from_dependence_list (insn
, &deps
->pending_jump_insns
);
3999 deps
->pending_flush_length
-= removed
;
4000 removed
= remove_from_dependence_list (insn
, &deps
->last_pending_memory_flush
);
4001 deps
->pending_flush_length
-= removed
;
4003 EXECUTE_IF_SET_IN_REG_SET (&deps
->reg_last_in_use
, 0, i
, rsi
)
4005 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
4007 remove_from_dependence_list (insn
, ®_last
->uses
);
4009 remove_from_dependence_list (insn
, ®_last
->sets
);
4010 if (reg_last
->implicit_sets
)
4011 remove_from_dependence_list (insn
, ®_last
->implicit_sets
);
4012 if (reg_last
->clobbers
)
4013 remove_from_dependence_list (insn
, ®_last
->clobbers
);
4014 if (!reg_last
->uses
&& !reg_last
->sets
&& !reg_last
->implicit_sets
4015 && !reg_last
->clobbers
)
4016 CLEAR_REGNO_REG_SET (&deps
->reg_last_in_use
, i
);
4021 remove_from_dependence_list (insn
, &deps
->last_function_call
);
4022 remove_from_dependence_list (insn
,
4023 &deps
->last_function_call_may_noreturn
);
4025 remove_from_dependence_list (insn
, &deps
->sched_before_next_call
);
4028 /* Init deps data vector. */
4030 init_deps_data_vector (void)
4032 int reserve
= (sched_max_luid
+ 1 - h_d_i_d
.length ());
4033 if (reserve
> 0 && ! h_d_i_d
.space (reserve
))
4034 h_d_i_d
.safe_grow_cleared (3 * sched_max_luid
/ 2);
4037 /* If it is profitable to use them, initialize or extend (depending on
4038 GLOBAL_P) dependency data. */
4040 sched_deps_init (bool global_p
)
4042 /* Average number of insns in the basic block.
4043 '+ 1' is used to make it nonzero. */
4044 int insns_in_block
= sched_max_luid
/ n_basic_blocks_for_fn (cfun
) + 1;
4046 init_deps_data_vector ();
4048 /* We use another caching mechanism for selective scheduling, so
4049 we don't use this one. */
4050 if (!sel_sched_p () && global_p
&& insns_in_block
> 100 * 5)
4052 /* ?!? We could save some memory by computing a per-region luid mapping
4053 which could reduce both the number of vectors in the cache and the
4054 size of each vector. Instead we just avoid the cache entirely unless
4055 the average number of instructions in a basic block is very high. See
4056 the comment before the declaration of true_dependency_cache for
4057 what we consider "very high". */
4059 extend_dependency_caches (sched_max_luid
, true);
4064 dl_pool
= create_alloc_pool ("deps_list", sizeof (struct _deps_list
),
4065 /* Allocate lists for one block at a time. */
4067 dn_pool
= create_alloc_pool ("dep_node", sizeof (struct _dep_node
),
4068 /* Allocate nodes for one block at a time.
4069 We assume that average insn has
4071 5 * insns_in_block
);
4076 /* Create or extend (depending on CREATE_P) dependency caches to
4079 extend_dependency_caches (int n
, bool create_p
)
4081 if (create_p
|| true_dependency_cache
)
4083 int i
, luid
= cache_size
+ n
;
4085 true_dependency_cache
= XRESIZEVEC (bitmap_head
, true_dependency_cache
,
4087 output_dependency_cache
= XRESIZEVEC (bitmap_head
,
4088 output_dependency_cache
, luid
);
4089 anti_dependency_cache
= XRESIZEVEC (bitmap_head
, anti_dependency_cache
,
4091 control_dependency_cache
= XRESIZEVEC (bitmap_head
, control_dependency_cache
,
4094 if (current_sched_info
->flags
& DO_SPECULATION
)
4095 spec_dependency_cache
= XRESIZEVEC (bitmap_head
, spec_dependency_cache
,
4098 for (i
= cache_size
; i
< luid
; i
++)
4100 bitmap_initialize (&true_dependency_cache
[i
], 0);
4101 bitmap_initialize (&output_dependency_cache
[i
], 0);
4102 bitmap_initialize (&anti_dependency_cache
[i
], 0);
4103 bitmap_initialize (&control_dependency_cache
[i
], 0);
4105 if (current_sched_info
->flags
& DO_SPECULATION
)
4106 bitmap_initialize (&spec_dependency_cache
[i
], 0);
4112 /* Finalize dependency information for the whole function. */
4114 sched_deps_finish (void)
4116 gcc_assert (deps_pools_are_empty_p ());
4117 free_alloc_pool_if_empty (&dn_pool
);
4118 free_alloc_pool_if_empty (&dl_pool
);
4119 gcc_assert (dn_pool
== NULL
&& dl_pool
== NULL
);
4124 if (true_dependency_cache
)
4128 for (i
= 0; i
< cache_size
; i
++)
4130 bitmap_clear (&true_dependency_cache
[i
]);
4131 bitmap_clear (&output_dependency_cache
[i
]);
4132 bitmap_clear (&anti_dependency_cache
[i
]);
4133 bitmap_clear (&control_dependency_cache
[i
]);
4135 if (sched_deps_info
->generate_spec_deps
)
4136 bitmap_clear (&spec_dependency_cache
[i
]);
4138 free (true_dependency_cache
);
4139 true_dependency_cache
= NULL
;
4140 free (output_dependency_cache
);
4141 output_dependency_cache
= NULL
;
4142 free (anti_dependency_cache
);
4143 anti_dependency_cache
= NULL
;
4144 free (control_dependency_cache
);
4145 control_dependency_cache
= NULL
;
4147 if (sched_deps_info
->generate_spec_deps
)
4149 free (spec_dependency_cache
);
4150 spec_dependency_cache
= NULL
;
4156 /* Initialize some global variables needed by the dependency analysis
4160 init_deps_global (void)
4162 CLEAR_HARD_REG_SET (implicit_reg_pending_clobbers
);
4163 CLEAR_HARD_REG_SET (implicit_reg_pending_uses
);
4164 reg_pending_sets
= ALLOC_REG_SET (®_obstack
);
4165 reg_pending_clobbers
= ALLOC_REG_SET (®_obstack
);
4166 reg_pending_uses
= ALLOC_REG_SET (®_obstack
);
4167 reg_pending_control_uses
= ALLOC_REG_SET (®_obstack
);
4168 reg_pending_barrier
= NOT_A_BARRIER
;
4170 if (!sel_sched_p () || sched_emulate_haifa_p
)
4172 sched_deps_info
->start_insn
= haifa_start_insn
;
4173 sched_deps_info
->finish_insn
= haifa_finish_insn
;
4175 sched_deps_info
->note_reg_set
= haifa_note_reg_set
;
4176 sched_deps_info
->note_reg_clobber
= haifa_note_reg_clobber
;
4177 sched_deps_info
->note_reg_use
= haifa_note_reg_use
;
4179 sched_deps_info
->note_mem_dep
= haifa_note_mem_dep
;
4180 sched_deps_info
->note_dep
= haifa_note_dep
;
4184 /* Free everything used by the dependency analysis code. */
4187 finish_deps_global (void)
4189 FREE_REG_SET (reg_pending_sets
);
4190 FREE_REG_SET (reg_pending_clobbers
);
4191 FREE_REG_SET (reg_pending_uses
);
4192 FREE_REG_SET (reg_pending_control_uses
);
4195 /* Estimate the weakness of dependence between MEM1 and MEM2. */
4197 estimate_dep_weak (rtx mem1
, rtx mem2
)
4202 /* MEMs are the same - don't speculate. */
4203 return MIN_DEP_WEAK
;
4205 r1
= XEXP (mem1
, 0);
4206 r2
= XEXP (mem2
, 0);
4209 || (REG_P (r1
) && REG_P (r2
)
4210 && REGNO (r1
) == REGNO (r2
)))
4211 /* Again, MEMs are the same. */
4212 return MIN_DEP_WEAK
;
4213 else if ((REG_P (r1
) && !REG_P (r2
))
4214 || (!REG_P (r1
) && REG_P (r2
)))
4215 /* Different addressing modes - reason to be more speculative,
4217 return NO_DEP_WEAK
- (NO_DEP_WEAK
- UNCERTAIN_DEP_WEAK
) / 2;
4219 /* We can't say anything about the dependence. */
4220 return UNCERTAIN_DEP_WEAK
;
4223 /* Add or update backward dependence between INSN and ELEM with type DEP_TYPE.
4224 This function can handle same INSN and ELEM (INSN == ELEM).
4225 It is a convenience wrapper. */
4227 add_dependence_1 (rtx_insn
*insn
, rtx_insn
*elem
, enum reg_note dep_type
)
4232 if (dep_type
== REG_DEP_TRUE
)
4234 else if (dep_type
== REG_DEP_OUTPUT
)
4236 else if (dep_type
== REG_DEP_CONTROL
)
4240 gcc_assert (dep_type
== REG_DEP_ANTI
);
4244 /* When add_dependence is called from inside sched-deps.c, we expect
4245 cur_insn to be non-null. */
4246 internal
= cur_insn
!= NULL
;
4248 gcc_assert (insn
== cur_insn
);
4252 note_dep (elem
, ds
);
4257 /* Return weakness of speculative type TYPE in the dep_status DS,
4258 without checking to prevent ICEs on malformed input. */
4260 get_dep_weak_1 (ds_t ds
, ds_t type
)
4266 case BEGIN_DATA
: ds
>>= BEGIN_DATA_BITS_OFFSET
; break;
4267 case BE_IN_DATA
: ds
>>= BE_IN_DATA_BITS_OFFSET
; break;
4268 case BEGIN_CONTROL
: ds
>>= BEGIN_CONTROL_BITS_OFFSET
; break;
4269 case BE_IN_CONTROL
: ds
>>= BE_IN_CONTROL_BITS_OFFSET
; break;
4270 default: gcc_unreachable ();
4276 /* Return weakness of speculative type TYPE in the dep_status DS. */
4278 get_dep_weak (ds_t ds
, ds_t type
)
4280 dw_t dw
= get_dep_weak_1 (ds
, type
);
4282 gcc_assert (MIN_DEP_WEAK
<= dw
&& dw
<= MAX_DEP_WEAK
);
4286 /* Return the dep_status, which has the same parameters as DS, except for
4287 speculative type TYPE, that will have weakness DW. */
4289 set_dep_weak (ds_t ds
, ds_t type
, dw_t dw
)
4291 gcc_assert (MIN_DEP_WEAK
<= dw
&& dw
<= MAX_DEP_WEAK
);
4296 case BEGIN_DATA
: ds
|= ((ds_t
) dw
) << BEGIN_DATA_BITS_OFFSET
; break;
4297 case BE_IN_DATA
: ds
|= ((ds_t
) dw
) << BE_IN_DATA_BITS_OFFSET
; break;
4298 case BEGIN_CONTROL
: ds
|= ((ds_t
) dw
) << BEGIN_CONTROL_BITS_OFFSET
; break;
4299 case BE_IN_CONTROL
: ds
|= ((ds_t
) dw
) << BE_IN_CONTROL_BITS_OFFSET
; break;
4300 default: gcc_unreachable ();
4305 /* Return the join of two dep_statuses DS1 and DS2.
4306 If MAX_P is true then choose the greater probability,
4307 otherwise multiply probabilities.
4308 This function assumes that both DS1 and DS2 contain speculative bits. */
4310 ds_merge_1 (ds_t ds1
, ds_t ds2
, bool max_p
)
4314 gcc_assert ((ds1
& SPECULATIVE
) && (ds2
& SPECULATIVE
));
4316 ds
= (ds1
& DEP_TYPES
) | (ds2
& DEP_TYPES
);
4318 t
= FIRST_SPEC_TYPE
;
4321 if ((ds1
& t
) && !(ds2
& t
))
4323 else if (!(ds1
& t
) && (ds2
& t
))
4325 else if ((ds1
& t
) && (ds2
& t
))
4327 dw_t dw1
= get_dep_weak (ds1
, t
);
4328 dw_t dw2
= get_dep_weak (ds2
, t
);
4333 dw
= ((ds_t
) dw1
) * ((ds_t
) dw2
);
4335 if (dw
< MIN_DEP_WEAK
)
4346 ds
= set_dep_weak (ds
, t
, (dw_t
) dw
);
4349 if (t
== LAST_SPEC_TYPE
)
4351 t
<<= SPEC_TYPE_SHIFT
;
4358 /* Return the join of two dep_statuses DS1 and DS2.
4359 This function assumes that both DS1 and DS2 contain speculative bits. */
4361 ds_merge (ds_t ds1
, ds_t ds2
)
4363 return ds_merge_1 (ds1
, ds2
, false);
4366 /* Return the join of two dep_statuses DS1 and DS2. */
4368 ds_full_merge (ds_t ds
, ds_t ds2
, rtx mem1
, rtx mem2
)
4370 ds_t new_status
= ds
| ds2
;
4372 if (new_status
& SPECULATIVE
)
4374 if ((ds
&& !(ds
& SPECULATIVE
))
4375 || (ds2
&& !(ds2
& SPECULATIVE
)))
4376 /* Then this dep can't be speculative. */
4377 new_status
&= ~SPECULATIVE
;
4380 /* Both are speculative. Merging probabilities. */
4385 dw
= estimate_dep_weak (mem1
, mem2
);
4386 ds
= set_dep_weak (ds
, BEGIN_DATA
, dw
);
4394 new_status
= ds_merge (ds2
, ds
);
4401 /* Return the join of DS1 and DS2. Use maximum instead of multiplying
4404 ds_max_merge (ds_t ds1
, ds_t ds2
)
4406 if (ds1
== 0 && ds2
== 0)
4409 if (ds1
== 0 && ds2
!= 0)
4412 if (ds1
!= 0 && ds2
== 0)
4415 return ds_merge_1 (ds1
, ds2
, true);
4418 /* Return the probability of speculation success for the speculation
4426 dt
= FIRST_SPEC_TYPE
;
4431 res
*= (ds_t
) get_dep_weak (ds
, dt
);
4435 if (dt
== LAST_SPEC_TYPE
)
4437 dt
<<= SPEC_TYPE_SHIFT
;
4443 res
/= MAX_DEP_WEAK
;
4445 if (res
< MIN_DEP_WEAK
)
4448 gcc_assert (res
<= MAX_DEP_WEAK
);
4453 /* Return a dep status that contains all speculation types of DS. */
4455 ds_get_speculation_types (ds_t ds
)
4457 if (ds
& BEGIN_DATA
)
4459 if (ds
& BE_IN_DATA
)
4461 if (ds
& BEGIN_CONTROL
)
4462 ds
|= BEGIN_CONTROL
;
4463 if (ds
& BE_IN_CONTROL
)
4464 ds
|= BE_IN_CONTROL
;
4466 return ds
& SPECULATIVE
;
4469 /* Return a dep status that contains maximal weakness for each speculation
4470 type present in DS. */
4472 ds_get_max_dep_weak (ds_t ds
)
4474 if (ds
& BEGIN_DATA
)
4475 ds
= set_dep_weak (ds
, BEGIN_DATA
, MAX_DEP_WEAK
);
4476 if (ds
& BE_IN_DATA
)
4477 ds
= set_dep_weak (ds
, BE_IN_DATA
, MAX_DEP_WEAK
);
4478 if (ds
& BEGIN_CONTROL
)
4479 ds
= set_dep_weak (ds
, BEGIN_CONTROL
, MAX_DEP_WEAK
);
4480 if (ds
& BE_IN_CONTROL
)
4481 ds
= set_dep_weak (ds
, BE_IN_CONTROL
, MAX_DEP_WEAK
);
4486 /* Dump information about the dependence status S. */
4488 dump_ds (FILE *f
, ds_t s
)
4493 fprintf (f
, "BEGIN_DATA: %d; ", get_dep_weak_1 (s
, BEGIN_DATA
));
4495 fprintf (f
, "BE_IN_DATA: %d; ", get_dep_weak_1 (s
, BE_IN_DATA
));
4496 if (s
& BEGIN_CONTROL
)
4497 fprintf (f
, "BEGIN_CONTROL: %d; ", get_dep_weak_1 (s
, BEGIN_CONTROL
));
4498 if (s
& BE_IN_CONTROL
)
4499 fprintf (f
, "BE_IN_CONTROL: %d; ", get_dep_weak_1 (s
, BE_IN_CONTROL
));
4502 fprintf (f
, "HARD_DEP; ");
4505 fprintf (f
, "DEP_TRUE; ");
4507 fprintf (f
, "DEP_OUTPUT; ");
4509 fprintf (f
, "DEP_ANTI; ");
4510 if (s
& DEP_CONTROL
)
4511 fprintf (f
, "DEP_CONTROL; ");
4519 dump_ds (stderr
, s
);
4520 fprintf (stderr
, "\n");
4523 #ifdef ENABLE_CHECKING
4524 /* Verify that dependence type and status are consistent.
4525 If RELAXED_P is true, then skip dep_weakness checks. */
4527 check_dep (dep_t dep
, bool relaxed_p
)
4529 enum reg_note dt
= DEP_TYPE (dep
);
4530 ds_t ds
= DEP_STATUS (dep
);
4532 gcc_assert (DEP_PRO (dep
) != DEP_CON (dep
));
4534 if (!(current_sched_info
->flags
& USE_DEPS_LIST
))
4536 gcc_assert (ds
== 0);
4540 /* Check that dependence type contains the same bits as the status. */
4541 if (dt
== REG_DEP_TRUE
)
4542 gcc_assert (ds
& DEP_TRUE
);
4543 else if (dt
== REG_DEP_OUTPUT
)
4544 gcc_assert ((ds
& DEP_OUTPUT
)
4545 && !(ds
& DEP_TRUE
));
4546 else if (dt
== REG_DEP_ANTI
)
4547 gcc_assert ((ds
& DEP_ANTI
)
4548 && !(ds
& (DEP_OUTPUT
| DEP_TRUE
)));
4550 gcc_assert (dt
== REG_DEP_CONTROL
4551 && (ds
& DEP_CONTROL
)
4552 && !(ds
& (DEP_OUTPUT
| DEP_ANTI
| DEP_TRUE
)));
4554 /* HARD_DEP can not appear in dep_status of a link. */
4555 gcc_assert (!(ds
& HARD_DEP
));
4557 /* Check that dependence status is set correctly when speculation is not
4559 if (!sched_deps_info
->generate_spec_deps
)
4560 gcc_assert (!(ds
& SPECULATIVE
));
4561 else if (ds
& SPECULATIVE
)
4565 ds_t type
= FIRST_SPEC_TYPE
;
4567 /* Check that dependence weakness is in proper range. */
4571 get_dep_weak (ds
, type
);
4573 if (type
== LAST_SPEC_TYPE
)
4575 type
<<= SPEC_TYPE_SHIFT
;
4580 if (ds
& BEGIN_SPEC
)
4582 /* Only true dependence can be data speculative. */
4583 if (ds
& BEGIN_DATA
)
4584 gcc_assert (ds
& DEP_TRUE
);
4586 /* Control dependencies in the insn scheduler are represented by
4587 anti-dependencies, therefore only anti dependence can be
4588 control speculative. */
4589 if (ds
& BEGIN_CONTROL
)
4590 gcc_assert (ds
& DEP_ANTI
);
4594 /* Subsequent speculations should resolve true dependencies. */
4595 gcc_assert ((ds
& DEP_TYPES
) == DEP_TRUE
);
4598 /* Check that true and anti dependencies can't have other speculative
4601 gcc_assert (ds
& (BEGIN_DATA
| BE_IN_SPEC
));
4602 /* An output dependence can't be speculative at all. */
4603 gcc_assert (!(ds
& DEP_OUTPUT
));
4605 gcc_assert (ds
& BEGIN_CONTROL
);
4608 #endif /* ENABLE_CHECKING */
4610 /* The following code discovers opportunities to switch a memory reference
4611 and an increment by modifying the address. We ensure that this is done
4612 only for dependencies that are only used to show a single register
4613 dependence (using DEP_NONREG and DEP_MULTIPLE), and so that every memory
4614 instruction involved is subject to only one dep that can cause a pattern
4617 When we discover a suitable dependency, we fill in the dep_replacement
4618 structure to show how to modify the memory reference. */
4620 /* Holds information about a pair of memory reference and register increment
4621 insns which depend on each other, but could possibly be interchanged. */
4628 /* A register occurring in the memory address for which we wish to break
4629 the dependence. This must be identical to the destination register of
4632 /* Any kind of index that is added to that register. */
4634 /* The constant offset used in the memory address. */
4635 HOST_WIDE_INT mem_constant
;
4636 /* The constant added in the increment insn. Negated if the increment is
4637 after the memory address. */
4638 HOST_WIDE_INT inc_constant
;
4639 /* The source register used in the increment. May be different from mem_reg0
4640 if the increment occurs before the memory address. */
4644 /* Verify that the memory location described in MII can be replaced with
4645 one using NEW_ADDR. Return the new memory reference or NULL_RTX. The
4646 insn remains unchanged by this function. */
4649 attempt_change (struct mem_inc_info
*mii
, rtx new_addr
)
4651 rtx mem
= *mii
->mem_loc
;
4654 /* Jump through a lot of hoops to keep the attributes up to date. We
4655 do not want to call one of the change address variants that take
4656 an offset even though we know the offset in many cases. These
4657 assume you are changing where the address is pointing by the
4659 new_mem
= replace_equiv_address_nv (mem
, new_addr
);
4660 if (! validate_change (mii
->mem_insn
, mii
->mem_loc
, new_mem
, 0))
4662 if (sched_verbose
>= 5)
4663 fprintf (sched_dump
, "validation failure\n");
4667 /* Put back the old one. */
4668 validate_change (mii
->mem_insn
, mii
->mem_loc
, mem
, 0);
4673 /* Return true if INSN is of a form "a = b op c" where a and b are
4674 regs. op is + if c is a reg and +|- if c is a const. Fill in
4675 informantion in MII about what is found.
4676 BEFORE_MEM indicates whether the increment is found before or after
4677 a corresponding memory reference. */
4680 parse_add_or_inc (struct mem_inc_info
*mii
, rtx_insn
*insn
, bool before_mem
)
4682 rtx pat
= single_set (insn
);
4686 if (RTX_FRAME_RELATED_P (insn
) || !pat
)
4689 /* Result must be single reg. */
4690 if (!REG_P (SET_DEST (pat
)))
4693 if (GET_CODE (SET_SRC (pat
)) != PLUS
)
4696 mii
->inc_insn
= insn
;
4697 src
= SET_SRC (pat
);
4698 mii
->inc_input
= XEXP (src
, 0);
4700 if (!REG_P (XEXP (src
, 0)))
4703 if (!rtx_equal_p (SET_DEST (pat
), mii
->mem_reg0
))
4706 cst
= XEXP (src
, 1);
4707 if (!CONST_INT_P (cst
))
4709 mii
->inc_constant
= INTVAL (cst
);
4711 regs_equal
= rtx_equal_p (mii
->inc_input
, mii
->mem_reg0
);
4715 mii
->inc_constant
= -mii
->inc_constant
;
4720 if (regs_equal
&& REGNO (SET_DEST (pat
)) == STACK_POINTER_REGNUM
)
4722 /* Note that the sign has already been reversed for !before_mem. */
4723 #ifdef STACK_GROWS_DOWNWARD
4724 return mii
->inc_constant
> 0;
4726 return mii
->inc_constant
< 0;
4732 /* Once a suitable mem reference has been found and the corresponding data
4733 in MII has been filled in, this function is called to find a suitable
4734 add or inc insn involving the register we found in the memory
4738 find_inc (struct mem_inc_info
*mii
, bool backwards
)
4740 sd_iterator_def sd_it
;
4743 sd_it
= sd_iterator_start (mii
->mem_insn
,
4744 backwards
? SD_LIST_HARD_BACK
: SD_LIST_FORW
);
4745 while (sd_iterator_cond (&sd_it
, &dep
))
4747 dep_node_t node
= DEP_LINK_NODE (*sd_it
.linkp
);
4748 rtx_insn
*pro
= DEP_PRO (dep
);
4749 rtx_insn
*con
= DEP_CON (dep
);
4750 rtx_insn
*inc_cand
= backwards
? pro
: con
;
4751 if (DEP_NONREG (dep
) || DEP_MULTIPLE (dep
))
4753 if (parse_add_or_inc (mii
, inc_cand
, backwards
))
4755 struct dep_replacement
*desc
;
4757 rtx newaddr
, newmem
;
4759 if (sched_verbose
>= 5)
4760 fprintf (sched_dump
, "candidate mem/inc pair: %d %d\n",
4761 INSN_UID (mii
->mem_insn
), INSN_UID (inc_cand
));
4763 /* Need to assure that none of the operands of the inc
4764 instruction are assigned to by the mem insn. */
4765 FOR_EACH_INSN_DEF (def
, mii
->mem_insn
)
4766 if (reg_overlap_mentioned_p (DF_REF_REG (def
), mii
->inc_input
)
4767 || reg_overlap_mentioned_p (DF_REF_REG (def
), mii
->mem_reg0
))
4769 if (sched_verbose
>= 5)
4770 fprintf (sched_dump
,
4771 "inc conflicts with store failure.\n");
4775 newaddr
= mii
->inc_input
;
4776 if (mii
->mem_index
!= NULL_RTX
)
4777 newaddr
= gen_rtx_PLUS (GET_MODE (newaddr
), newaddr
,
4779 newaddr
= plus_constant (GET_MODE (newaddr
), newaddr
,
4780 mii
->mem_constant
+ mii
->inc_constant
);
4781 newmem
= attempt_change (mii
, newaddr
);
4782 if (newmem
== NULL_RTX
)
4784 if (sched_verbose
>= 5)
4785 fprintf (sched_dump
, "successful address replacement\n");
4786 desc
= XCNEW (struct dep_replacement
);
4787 DEP_REPLACE (dep
) = desc
;
4788 desc
->loc
= mii
->mem_loc
;
4789 desc
->newval
= newmem
;
4790 desc
->orig
= *desc
->loc
;
4791 desc
->insn
= mii
->mem_insn
;
4792 move_dep_link (DEP_NODE_BACK (node
), INSN_HARD_BACK_DEPS (con
),
4793 INSN_SPEC_BACK_DEPS (con
));
4796 FOR_EACH_DEP (mii
->inc_insn
, SD_LIST_BACK
, sd_it
, dep
)
4797 add_dependence_1 (mii
->mem_insn
, DEP_PRO (dep
),
4802 FOR_EACH_DEP (mii
->inc_insn
, SD_LIST_FORW
, sd_it
, dep
)
4803 add_dependence_1 (DEP_CON (dep
), mii
->mem_insn
,
4809 sd_iterator_next (&sd_it
);
4814 /* A recursive function that walks ADDRESS_OF_X to find memory references
4815 which could be modified during scheduling. We call find_inc for each
4816 one we find that has a recognizable form. MII holds information about
4817 the pair of memory/increment instructions.
4818 We ensure that every instruction with a memory reference (which will be
4819 the location of the replacement) is assigned at most one breakable
4823 find_mem (struct mem_inc_info
*mii
, rtx
*address_of_x
)
4825 rtx x
= *address_of_x
;
4826 enum rtx_code code
= GET_CODE (x
);
4827 const char *const fmt
= GET_RTX_FORMAT (code
);
4832 rtx reg0
= XEXP (x
, 0);
4834 mii
->mem_loc
= address_of_x
;
4835 mii
->mem_index
= NULL_RTX
;
4836 mii
->mem_constant
= 0;
4837 if (GET_CODE (reg0
) == PLUS
&& CONST_INT_P (XEXP (reg0
, 1)))
4839 mii
->mem_constant
= INTVAL (XEXP (reg0
, 1));
4840 reg0
= XEXP (reg0
, 0);
4842 if (GET_CODE (reg0
) == PLUS
)
4844 mii
->mem_index
= XEXP (reg0
, 1);
4845 reg0
= XEXP (reg0
, 0);
4850 int occurrences
= 0;
4852 /* Make sure this reg appears only once in this insn. Can't use
4853 count_occurrences since that only works for pseudos. */
4854 FOR_EACH_INSN_USE (use
, mii
->mem_insn
)
4855 if (reg_overlap_mentioned_p (reg0
, DF_REF_REG (use
)))
4856 if (++occurrences
> 1)
4858 if (sched_verbose
>= 5)
4859 fprintf (sched_dump
, "mem count failure\n");
4863 mii
->mem_reg0
= reg0
;
4864 return find_inc (mii
, true) || find_inc (mii
, false);
4869 if (code
== SIGN_EXTRACT
|| code
== ZERO_EXTRACT
)
4871 /* If REG occurs inside a MEM used in a bit-field reference,
4872 that is unacceptable. */
4876 /* Time for some deep diving. */
4877 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
4881 if (find_mem (mii
, &XEXP (x
, i
)))
4884 else if (fmt
[i
] == 'E')
4887 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
4888 if (find_mem (mii
, &XVECEXP (x
, i
, j
)))
4896 /* Examine the instructions between HEAD and TAIL and try to find
4897 dependencies that can be broken by modifying one of the patterns. */
4900 find_modifiable_mems (rtx_insn
*head
, rtx_insn
*tail
)
4902 rtx_insn
*insn
, *next_tail
= NEXT_INSN (tail
);
4903 int success_in_block
= 0;
4905 for (insn
= head
; insn
!= next_tail
; insn
= NEXT_INSN (insn
))
4907 struct mem_inc_info mii
;
4909 if (!NONDEBUG_INSN_P (insn
) || RTX_FRAME_RELATED_P (insn
))
4912 mii
.mem_insn
= insn
;
4913 if (find_mem (&mii
, &PATTERN (insn
)))
4916 if (success_in_block
&& sched_verbose
>= 5)
4917 fprintf (sched_dump
, "%d candidates for address modification found.\n",
4921 #endif /* INSN_SCHEDULING */