1 /* Instruction scheduling pass. This file computes dependencies between
3 Copyright (C) 1992-2015 Free Software Foundation, Inc.
4 Contributed by Michael Tiemann (tiemann@cygnus.com) Enhanced by,
5 and currently maintained by, Jim Wilson (wilson@cygnus.com)
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
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"
32 #include "double-int.h"
38 #include "tree.h" /* FIXME: Used by call_may_noreturn_p. */
40 #include "hard-reg-set.h"
45 #include "insn-config.h"
46 #include "insn-attr.h"
50 #include "dominance.h"
54 #include "basic-block.h"
55 #include "sched-int.h"
62 #ifdef INSN_SCHEDULING
64 #ifdef ENABLE_CHECKING
70 /* Holds current parameters for the dependency analyzer. */
71 struct sched_deps_info_def
*sched_deps_info
;
73 /* The data is specific to the Haifa scheduler. */
74 vec
<haifa_deps_insn_data_def
>
77 /* Return the major type present in the DS. */
85 return REG_DEP_OUTPUT
;
88 return REG_DEP_CONTROL
;
90 gcc_assert (ds
& DEP_ANTI
);
95 /* Return equivalent dep_status. */
97 dk_to_ds (enum reg_note dk
)
107 case REG_DEP_CONTROL
:
111 gcc_assert (dk
== REG_DEP_ANTI
);
116 /* Functions to operate with dependence information container - dep_t. */
118 /* Init DEP with the arguments. */
120 init_dep_1 (dep_t dep
, rtx_insn
*pro
, rtx_insn
*con
, enum reg_note type
, ds_t ds
)
124 DEP_TYPE (dep
) = type
;
125 DEP_STATUS (dep
) = ds
;
126 DEP_COST (dep
) = UNKNOWN_DEP_COST
;
127 DEP_NONREG (dep
) = 0;
128 DEP_MULTIPLE (dep
) = 0;
129 DEP_REPLACE (dep
) = NULL
;
132 /* Init DEP with the arguments.
133 While most of the scheduler (including targets) only need the major type
134 of the dependency, it is convenient to hide full dep_status from them. */
136 init_dep (dep_t dep
, rtx_insn
*pro
, rtx_insn
*con
, enum reg_note kind
)
140 if ((current_sched_info
->flags
& USE_DEPS_LIST
))
141 ds
= dk_to_ds (kind
);
145 init_dep_1 (dep
, pro
, con
, kind
, ds
);
148 /* Make a copy of FROM in TO. */
150 copy_dep (dep_t to
, dep_t from
)
152 memcpy (to
, from
, sizeof (*to
));
155 static void dump_ds (FILE *, ds_t
);
157 /* Define flags for dump_dep (). */
159 /* Dump producer of the dependence. */
160 #define DUMP_DEP_PRO (2)
162 /* Dump consumer of the dependence. */
163 #define DUMP_DEP_CON (4)
165 /* Dump type of the dependence. */
166 #define DUMP_DEP_TYPE (8)
168 /* Dump status of the dependence. */
169 #define DUMP_DEP_STATUS (16)
171 /* Dump all information about the dependence. */
172 #define DUMP_DEP_ALL (DUMP_DEP_PRO | DUMP_DEP_CON | DUMP_DEP_TYPE \
176 FLAGS is a bit mask specifying what information about DEP needs
178 If FLAGS has the very first bit set, then dump all information about DEP
179 and propagate this bit into the callee dump functions. */
181 dump_dep (FILE *dump
, dep_t dep
, int flags
)
184 flags
|= DUMP_DEP_ALL
;
188 if (flags
& DUMP_DEP_PRO
)
189 fprintf (dump
, "%d; ", INSN_UID (DEP_PRO (dep
)));
191 if (flags
& DUMP_DEP_CON
)
192 fprintf (dump
, "%d; ", INSN_UID (DEP_CON (dep
)));
194 if (flags
& DUMP_DEP_TYPE
)
197 enum reg_note type
= DEP_TYPE (dep
);
209 case REG_DEP_CONTROL
:
222 fprintf (dump
, "%c; ", t
);
225 if (flags
& DUMP_DEP_STATUS
)
227 if (current_sched_info
->flags
& USE_DEPS_LIST
)
228 dump_ds (dump
, DEP_STATUS (dep
));
234 /* Default flags for dump_dep (). */
235 static int dump_dep_flags
= (DUMP_DEP_PRO
| DUMP_DEP_CON
);
237 /* Dump all fields of DEP to STDERR. */
239 sd_debug_dep (dep_t dep
)
241 dump_dep (stderr
, dep
, 1);
242 fprintf (stderr
, "\n");
245 /* Determine whether DEP is a dependency link of a non-debug insn on a
249 depl_on_debug_p (dep_link_t dep
)
251 return (DEBUG_INSN_P (DEP_LINK_PRO (dep
))
252 && !DEBUG_INSN_P (DEP_LINK_CON (dep
)));
255 /* Functions to operate with a single link from the dependencies lists -
258 /* Attach L to appear after link X whose &DEP_LINK_NEXT (X) is given by
261 attach_dep_link (dep_link_t l
, dep_link_t
*prev_nextp
)
263 dep_link_t next
= *prev_nextp
;
265 gcc_assert (DEP_LINK_PREV_NEXTP (l
) == NULL
266 && DEP_LINK_NEXT (l
) == NULL
);
268 /* Init node being inserted. */
269 DEP_LINK_PREV_NEXTP (l
) = prev_nextp
;
270 DEP_LINK_NEXT (l
) = next
;
275 gcc_assert (DEP_LINK_PREV_NEXTP (next
) == prev_nextp
);
277 DEP_LINK_PREV_NEXTP (next
) = &DEP_LINK_NEXT (l
);
284 /* Add dep_link LINK to deps_list L. */
286 add_to_deps_list (dep_link_t link
, deps_list_t l
)
288 attach_dep_link (link
, &DEPS_LIST_FIRST (l
));
290 /* Don't count debug deps. */
291 if (!depl_on_debug_p (link
))
292 ++DEPS_LIST_N_LINKS (l
);
295 /* Detach dep_link L from the list. */
297 detach_dep_link (dep_link_t l
)
299 dep_link_t
*prev_nextp
= DEP_LINK_PREV_NEXTP (l
);
300 dep_link_t next
= DEP_LINK_NEXT (l
);
305 DEP_LINK_PREV_NEXTP (next
) = prev_nextp
;
307 DEP_LINK_PREV_NEXTP (l
) = NULL
;
308 DEP_LINK_NEXT (l
) = NULL
;
311 /* Remove link LINK from list LIST. */
313 remove_from_deps_list (dep_link_t link
, deps_list_t list
)
315 detach_dep_link (link
);
317 /* Don't count debug deps. */
318 if (!depl_on_debug_p (link
))
319 --DEPS_LIST_N_LINKS (list
);
322 /* Move link LINK from list FROM to list TO. */
324 move_dep_link (dep_link_t link
, deps_list_t from
, deps_list_t to
)
326 remove_from_deps_list (link
, from
);
327 add_to_deps_list (link
, to
);
330 /* Return true of LINK is not attached to any list. */
332 dep_link_is_detached_p (dep_link_t link
)
334 return DEP_LINK_PREV_NEXTP (link
) == NULL
;
337 /* Pool to hold all dependency nodes (dep_node_t). */
338 static alloc_pool dn_pool
;
340 /* Number of dep_nodes out there. */
341 static int dn_pool_diff
= 0;
343 /* Create a dep_node. */
345 create_dep_node (void)
347 dep_node_t n
= (dep_node_t
) pool_alloc (dn_pool
);
348 dep_link_t back
= DEP_NODE_BACK (n
);
349 dep_link_t forw
= DEP_NODE_FORW (n
);
351 DEP_LINK_NODE (back
) = n
;
352 DEP_LINK_NEXT (back
) = NULL
;
353 DEP_LINK_PREV_NEXTP (back
) = NULL
;
355 DEP_LINK_NODE (forw
) = n
;
356 DEP_LINK_NEXT (forw
) = NULL
;
357 DEP_LINK_PREV_NEXTP (forw
) = NULL
;
364 /* Delete dep_node N. N must not be connected to any deps_list. */
366 delete_dep_node (dep_node_t n
)
368 gcc_assert (dep_link_is_detached_p (DEP_NODE_BACK (n
))
369 && dep_link_is_detached_p (DEP_NODE_FORW (n
)));
371 XDELETE (DEP_REPLACE (DEP_NODE_DEP (n
)));
375 pool_free (dn_pool
, n
);
378 /* Pool to hold dependencies lists (deps_list_t). */
379 static alloc_pool dl_pool
;
381 /* Number of deps_lists out there. */
382 static int dl_pool_diff
= 0;
384 /* Functions to operate with dependences lists - deps_list_t. */
386 /* Return true if list L is empty. */
388 deps_list_empty_p (deps_list_t l
)
390 return DEPS_LIST_N_LINKS (l
) == 0;
393 /* Create a new deps_list. */
395 create_deps_list (void)
397 deps_list_t l
= (deps_list_t
) pool_alloc (dl_pool
);
399 DEPS_LIST_FIRST (l
) = NULL
;
400 DEPS_LIST_N_LINKS (l
) = 0;
406 /* Free deps_list L. */
408 free_deps_list (deps_list_t l
)
410 gcc_assert (deps_list_empty_p (l
));
414 pool_free (dl_pool
, l
);
417 /* Return true if there is no dep_nodes and deps_lists out there.
418 After the region is scheduled all the dependency nodes and lists
419 should [generally] be returned to pool. */
421 deps_pools_are_empty_p (void)
423 return dn_pool_diff
== 0 && dl_pool_diff
== 0;
426 /* Remove all elements from L. */
428 clear_deps_list (deps_list_t l
)
432 dep_link_t link
= DEPS_LIST_FIRST (l
);
437 remove_from_deps_list (link
, l
);
442 /* Decide whether a dependency should be treated as a hard or a speculative
445 dep_spec_p (dep_t dep
)
447 if (current_sched_info
->flags
& DO_SPECULATION
)
449 if (DEP_STATUS (dep
) & SPECULATIVE
)
452 if (current_sched_info
->flags
& DO_PREDICATION
)
454 if (DEP_TYPE (dep
) == REG_DEP_CONTROL
)
457 if (DEP_REPLACE (dep
) != NULL
)
462 static regset reg_pending_sets
;
463 static regset reg_pending_clobbers
;
464 static regset reg_pending_uses
;
465 static regset reg_pending_control_uses
;
466 static enum reg_pending_barrier_mode reg_pending_barrier
;
468 /* Hard registers implicitly clobbered or used (or may be implicitly
469 clobbered or used) by the currently analyzed insn. For example,
470 insn in its constraint has one register class. Even if there is
471 currently no hard register in the insn, the particular hard
472 register will be in the insn after reload pass because the
473 constraint requires it. */
474 static HARD_REG_SET implicit_reg_pending_clobbers
;
475 static HARD_REG_SET implicit_reg_pending_uses
;
477 /* To speed up the test for duplicate dependency links we keep a
478 record of dependencies created by add_dependence when the average
479 number of instructions in a basic block is very large.
481 Studies have shown that there is typically around 5 instructions between
482 branches for typical C code. So we can make a guess that the average
483 basic block is approximately 5 instructions long; we will choose 100X
484 the average size as a very large basic block.
486 Each insn has associated bitmaps for its dependencies. Each bitmap
487 has enough entries to represent a dependency on any other insn in
488 the insn chain. All bitmap for true dependencies cache is
489 allocated then the rest two ones are also allocated. */
490 static bitmap_head
*true_dependency_cache
= NULL
;
491 static bitmap_head
*output_dependency_cache
= NULL
;
492 static bitmap_head
*anti_dependency_cache
= NULL
;
493 static bitmap_head
*control_dependency_cache
= NULL
;
494 static bitmap_head
*spec_dependency_cache
= NULL
;
495 static int cache_size
;
497 /* True if we should mark added dependencies as a non-register deps. */
498 static bool mark_as_hard
;
500 static int deps_may_trap_p (const_rtx
);
501 static void add_dependence_1 (rtx_insn
*, rtx_insn
*, enum reg_note
);
502 static void add_dependence_list (rtx_insn
*, rtx_insn_list
*, int,
503 enum reg_note
, bool);
504 static void add_dependence_list_and_free (struct deps_desc
*, rtx_insn
*,
505 rtx_insn_list
**, int, enum reg_note
,
507 static void delete_all_dependences (rtx
);
508 static void chain_to_prev_insn (rtx_insn
*);
510 static void flush_pending_lists (struct deps_desc
*, rtx_insn
*, int, int);
511 static void sched_analyze_1 (struct deps_desc
*, rtx
, rtx_insn
*);
512 static void sched_analyze_2 (struct deps_desc
*, rtx
, rtx_insn
*);
513 static void sched_analyze_insn (struct deps_desc
*, rtx
, rtx_insn
*);
515 static bool sched_has_condition_p (const rtx_insn
*);
516 static int conditions_mutex_p (const_rtx
, const_rtx
, bool, bool);
518 static enum DEPS_ADJUST_RESULT
maybe_add_or_update_dep_1 (dep_t
, bool,
520 static enum DEPS_ADJUST_RESULT
add_or_update_dep_1 (dep_t
, bool, rtx
, rtx
);
522 #ifdef ENABLE_CHECKING
523 static void check_dep (dep_t
, bool);
526 /* Return nonzero if a load of the memory reference MEM can cause a trap. */
529 deps_may_trap_p (const_rtx mem
)
531 const_rtx addr
= XEXP (mem
, 0);
533 if (REG_P (addr
) && REGNO (addr
) >= FIRST_PSEUDO_REGISTER
)
535 const_rtx t
= get_reg_known_value (REGNO (addr
));
539 return rtx_addr_can_trap_p (addr
);
543 /* Find the condition under which INSN is executed. If REV is not NULL,
544 it is set to TRUE when the returned comparison should be reversed
545 to get the actual condition. */
547 sched_get_condition_with_rev_uncached (const rtx_insn
*insn
, bool *rev
)
549 rtx pat
= PATTERN (insn
);
555 if (GET_CODE (pat
) == COND_EXEC
)
556 return COND_EXEC_TEST (pat
);
558 if (!any_condjump_p (insn
) || !onlyjump_p (insn
))
561 src
= SET_SRC (pc_set (insn
));
563 if (XEXP (src
, 2) == pc_rtx
)
564 return XEXP (src
, 0);
565 else if (XEXP (src
, 1) == pc_rtx
)
567 rtx cond
= XEXP (src
, 0);
568 enum rtx_code revcode
= reversed_comparison_code (cond
, insn
);
570 if (revcode
== UNKNOWN
)
581 /* Return the condition under which INSN does not execute (i.e. the
582 not-taken condition for a conditional branch), or NULL if we cannot
583 find such a condition. The caller should make a copy of the condition
586 sched_get_reverse_condition_uncached (const rtx_insn
*insn
)
589 rtx cond
= sched_get_condition_with_rev_uncached (insn
, &rev
);
590 if (cond
== NULL_RTX
)
594 enum rtx_code revcode
= reversed_comparison_code (cond
, insn
);
595 cond
= gen_rtx_fmt_ee (revcode
, GET_MODE (cond
),
602 /* Caching variant of sched_get_condition_with_rev_uncached.
603 We only do actual work the first time we come here for an insn; the
604 results are cached in INSN_CACHED_COND and INSN_REVERSE_COND. */
606 sched_get_condition_with_rev (const rtx_insn
*insn
, bool *rev
)
610 if (INSN_LUID (insn
) == 0)
611 return sched_get_condition_with_rev_uncached (insn
, rev
);
613 if (INSN_CACHED_COND (insn
) == const_true_rtx
)
616 if (INSN_CACHED_COND (insn
) != NULL_RTX
)
619 *rev
= INSN_REVERSE_COND (insn
);
620 return INSN_CACHED_COND (insn
);
623 INSN_CACHED_COND (insn
) = sched_get_condition_with_rev_uncached (insn
, &tmp
);
624 INSN_REVERSE_COND (insn
) = tmp
;
626 if (INSN_CACHED_COND (insn
) == NULL_RTX
)
628 INSN_CACHED_COND (insn
) = const_true_rtx
;
633 *rev
= INSN_REVERSE_COND (insn
);
634 return INSN_CACHED_COND (insn
);
637 /* True when we can find a condition under which INSN is executed. */
639 sched_has_condition_p (const rtx_insn
*insn
)
641 return !! sched_get_condition_with_rev (insn
, NULL
);
646 /* Return nonzero if conditions COND1 and COND2 can never be both true. */
648 conditions_mutex_p (const_rtx cond1
, const_rtx cond2
, bool rev1
, bool rev2
)
650 if (COMPARISON_P (cond1
)
651 && COMPARISON_P (cond2
)
652 && GET_CODE (cond1
) ==
654 ? reversed_comparison_code (cond2
, NULL
)
656 && rtx_equal_p (XEXP (cond1
, 0), XEXP (cond2
, 0))
657 && XEXP (cond1
, 1) == XEXP (cond2
, 1))
662 /* Return true if insn1 and insn2 can never depend on one another because
663 the conditions under which they are executed are mutually exclusive. */
665 sched_insns_conditions_mutex_p (const rtx_insn
*insn1
, const rtx_insn
*insn2
)
668 bool rev1
= false, rev2
= false;
670 /* df doesn't handle conditional lifetimes entirely correctly;
671 calls mess up the conditional lifetimes. */
672 if (!CALL_P (insn1
) && !CALL_P (insn2
))
674 cond1
= sched_get_condition_with_rev (insn1
, &rev1
);
675 cond2
= sched_get_condition_with_rev (insn2
, &rev2
);
677 && conditions_mutex_p (cond1
, cond2
, rev1
, rev2
)
678 /* Make sure first instruction doesn't affect condition of second
679 instruction if switched. */
680 && !modified_in_p (cond1
, insn2
)
681 /* Make sure second instruction doesn't affect condition of first
682 instruction if switched. */
683 && !modified_in_p (cond2
, insn1
))
690 /* Return true if INSN can potentially be speculated with type DS. */
692 sched_insn_is_legitimate_for_speculation_p (const rtx_insn
*insn
, ds_t ds
)
694 if (HAS_INTERNAL_DEP (insn
))
697 if (!NONJUMP_INSN_P (insn
))
700 if (SCHED_GROUP_P (insn
))
703 if (IS_SPECULATION_CHECK_P (CONST_CAST_RTX_INSN (insn
)))
706 if (side_effects_p (PATTERN (insn
)))
710 /* The following instructions, which depend on a speculatively scheduled
711 instruction, cannot be speculatively scheduled along. */
713 if (may_trap_or_fault_p (PATTERN (insn
)))
714 /* If instruction might fault, it cannot be speculatively scheduled.
715 For control speculation it's obvious why and for data speculation
716 it's because the insn might get wrong input if speculation
717 wasn't successful. */
720 if ((ds
& BE_IN_DATA
)
721 && sched_has_condition_p (insn
))
722 /* If this is a predicated instruction, then it cannot be
723 speculatively scheduled. See PR35659. */
730 /* Initialize LIST_PTR to point to one of the lists present in TYPES_PTR,
731 initialize RESOLVED_P_PTR with true if that list consists of resolved deps,
732 and remove the type of returned [through LIST_PTR] list from TYPES_PTR.
733 This function is used to switch sd_iterator to the next list.
734 !!! For internal use only. Might consider moving it to sched-int.h. */
736 sd_next_list (const_rtx insn
, sd_list_types_def
*types_ptr
,
737 deps_list_t
*list_ptr
, bool *resolved_p_ptr
)
739 sd_list_types_def types
= *types_ptr
;
741 if (types
& SD_LIST_HARD_BACK
)
743 *list_ptr
= INSN_HARD_BACK_DEPS (insn
);
744 *resolved_p_ptr
= false;
745 *types_ptr
= types
& ~SD_LIST_HARD_BACK
;
747 else if (types
& SD_LIST_SPEC_BACK
)
749 *list_ptr
= INSN_SPEC_BACK_DEPS (insn
);
750 *resolved_p_ptr
= false;
751 *types_ptr
= types
& ~SD_LIST_SPEC_BACK
;
753 else if (types
& SD_LIST_FORW
)
755 *list_ptr
= INSN_FORW_DEPS (insn
);
756 *resolved_p_ptr
= false;
757 *types_ptr
= types
& ~SD_LIST_FORW
;
759 else if (types
& SD_LIST_RES_BACK
)
761 *list_ptr
= INSN_RESOLVED_BACK_DEPS (insn
);
762 *resolved_p_ptr
= true;
763 *types_ptr
= types
& ~SD_LIST_RES_BACK
;
765 else if (types
& SD_LIST_RES_FORW
)
767 *list_ptr
= INSN_RESOLVED_FORW_DEPS (insn
);
768 *resolved_p_ptr
= true;
769 *types_ptr
= types
& ~SD_LIST_RES_FORW
;
774 *resolved_p_ptr
= false;
775 *types_ptr
= SD_LIST_NONE
;
779 /* Return the summary size of INSN's lists defined by LIST_TYPES. */
781 sd_lists_size (const_rtx insn
, sd_list_types_def list_types
)
785 while (list_types
!= SD_LIST_NONE
)
790 sd_next_list (insn
, &list_types
, &list
, &resolved_p
);
792 size
+= DEPS_LIST_N_LINKS (list
);
798 /* Return true if INSN's lists defined by LIST_TYPES are all empty. */
801 sd_lists_empty_p (const_rtx insn
, sd_list_types_def list_types
)
803 while (list_types
!= SD_LIST_NONE
)
808 sd_next_list (insn
, &list_types
, &list
, &resolved_p
);
809 if (!deps_list_empty_p (list
))
816 /* Initialize data for INSN. */
818 sd_init_insn (rtx insn
)
820 INSN_HARD_BACK_DEPS (insn
) = create_deps_list ();
821 INSN_SPEC_BACK_DEPS (insn
) = create_deps_list ();
822 INSN_RESOLVED_BACK_DEPS (insn
) = create_deps_list ();
823 INSN_FORW_DEPS (insn
) = create_deps_list ();
824 INSN_RESOLVED_FORW_DEPS (insn
) = create_deps_list ();
826 /* ??? It would be nice to allocate dependency caches here. */
829 /* Free data for INSN. */
831 sd_finish_insn (rtx insn
)
833 /* ??? It would be nice to deallocate dependency caches here. */
835 free_deps_list (INSN_HARD_BACK_DEPS (insn
));
836 INSN_HARD_BACK_DEPS (insn
) = NULL
;
838 free_deps_list (INSN_SPEC_BACK_DEPS (insn
));
839 INSN_SPEC_BACK_DEPS (insn
) = NULL
;
841 free_deps_list (INSN_RESOLVED_BACK_DEPS (insn
));
842 INSN_RESOLVED_BACK_DEPS (insn
) = NULL
;
844 free_deps_list (INSN_FORW_DEPS (insn
));
845 INSN_FORW_DEPS (insn
) = NULL
;
847 free_deps_list (INSN_RESOLVED_FORW_DEPS (insn
));
848 INSN_RESOLVED_FORW_DEPS (insn
) = NULL
;
851 /* Find a dependency between producer PRO and consumer CON.
852 Search through resolved dependency lists if RESOLVED_P is true.
853 If no such dependency is found return NULL,
854 otherwise return the dependency and initialize SD_IT_PTR [if it is nonnull]
855 with an iterator pointing to it. */
857 sd_find_dep_between_no_cache (rtx pro
, rtx con
, bool resolved_p
,
858 sd_iterator_def
*sd_it_ptr
)
860 sd_list_types_def pro_list_type
;
861 sd_list_types_def con_list_type
;
862 sd_iterator_def sd_it
;
864 bool found_p
= false;
868 pro_list_type
= SD_LIST_RES_FORW
;
869 con_list_type
= SD_LIST_RES_BACK
;
873 pro_list_type
= SD_LIST_FORW
;
874 con_list_type
= SD_LIST_BACK
;
877 /* Walk through either back list of INSN or forw list of ELEM
878 depending on which one is shorter. */
879 if (sd_lists_size (con
, con_list_type
) < sd_lists_size (pro
, pro_list_type
))
881 /* Find the dep_link with producer PRO in consumer's back_deps. */
882 FOR_EACH_DEP (con
, con_list_type
, sd_it
, dep
)
883 if (DEP_PRO (dep
) == pro
)
891 /* Find the dep_link with consumer CON in producer's forw_deps. */
892 FOR_EACH_DEP (pro
, pro_list_type
, sd_it
, dep
)
893 if (DEP_CON (dep
) == con
)
902 if (sd_it_ptr
!= NULL
)
911 /* Find a dependency between producer PRO and consumer CON.
912 Use dependency [if available] to check if dependency is present at all.
913 Search through resolved dependency lists if RESOLVED_P is true.
914 If the dependency or NULL if none found. */
916 sd_find_dep_between (rtx pro
, rtx con
, bool resolved_p
)
918 if (true_dependency_cache
!= NULL
)
919 /* Avoiding the list walk below can cut compile times dramatically
922 int elem_luid
= INSN_LUID (pro
);
923 int insn_luid
= INSN_LUID (con
);
925 if (!bitmap_bit_p (&true_dependency_cache
[insn_luid
], elem_luid
)
926 && !bitmap_bit_p (&output_dependency_cache
[insn_luid
], elem_luid
)
927 && !bitmap_bit_p (&anti_dependency_cache
[insn_luid
], elem_luid
)
928 && !bitmap_bit_p (&control_dependency_cache
[insn_luid
], elem_luid
))
932 return sd_find_dep_between_no_cache (pro
, con
, resolved_p
, NULL
);
935 /* Add or update a dependence described by DEP.
936 MEM1 and MEM2, if non-null, correspond to memory locations in case of
939 The function returns a value indicating if an old entry has been changed
940 or a new entry has been added to insn's backward deps.
942 This function merely checks if producer and consumer is the same insn
943 and doesn't create a dep in this case. Actual manipulation of
944 dependence data structures is performed in add_or_update_dep_1. */
945 static enum DEPS_ADJUST_RESULT
946 maybe_add_or_update_dep_1 (dep_t dep
, bool resolved_p
, rtx mem1
, rtx mem2
)
948 rtx_insn
*elem
= DEP_PRO (dep
);
949 rtx_insn
*insn
= DEP_CON (dep
);
951 gcc_assert (INSN_P (insn
) && INSN_P (elem
));
953 /* Don't depend an insn on itself. */
956 if (sched_deps_info
->generate_spec_deps
)
957 /* INSN has an internal dependence, which we can't overcome. */
958 HAS_INTERNAL_DEP (insn
) = 1;
963 return add_or_update_dep_1 (dep
, resolved_p
, mem1
, mem2
);
966 /* Ask dependency caches what needs to be done for dependence DEP.
967 Return DEP_CREATED if new dependence should be created and there is no
968 need to try to find one searching the dependencies lists.
969 Return DEP_PRESENT if there already is a dependence described by DEP and
970 hence nothing is to be done.
971 Return DEP_CHANGED if there already is a dependence, but it should be
972 updated to incorporate additional information from DEP. */
973 static enum DEPS_ADJUST_RESULT
974 ask_dependency_caches (dep_t dep
)
976 int elem_luid
= INSN_LUID (DEP_PRO (dep
));
977 int insn_luid
= INSN_LUID (DEP_CON (dep
));
979 gcc_assert (true_dependency_cache
!= NULL
980 && output_dependency_cache
!= NULL
981 && anti_dependency_cache
!= NULL
982 && control_dependency_cache
!= NULL
);
984 if (!(current_sched_info
->flags
& USE_DEPS_LIST
))
986 enum reg_note present_dep_type
;
988 if (bitmap_bit_p (&true_dependency_cache
[insn_luid
], elem_luid
))
989 present_dep_type
= REG_DEP_TRUE
;
990 else if (bitmap_bit_p (&output_dependency_cache
[insn_luid
], elem_luid
))
991 present_dep_type
= REG_DEP_OUTPUT
;
992 else if (bitmap_bit_p (&anti_dependency_cache
[insn_luid
], elem_luid
))
993 present_dep_type
= REG_DEP_ANTI
;
994 else if (bitmap_bit_p (&control_dependency_cache
[insn_luid
], elem_luid
))
995 present_dep_type
= REG_DEP_CONTROL
;
997 /* There is no existing dep so it should be created. */
1000 if ((int) DEP_TYPE (dep
) >= (int) present_dep_type
)
1001 /* DEP does not add anything to the existing dependence. */
1006 ds_t present_dep_types
= 0;
1008 if (bitmap_bit_p (&true_dependency_cache
[insn_luid
], elem_luid
))
1009 present_dep_types
|= DEP_TRUE
;
1010 if (bitmap_bit_p (&output_dependency_cache
[insn_luid
], elem_luid
))
1011 present_dep_types
|= DEP_OUTPUT
;
1012 if (bitmap_bit_p (&anti_dependency_cache
[insn_luid
], elem_luid
))
1013 present_dep_types
|= DEP_ANTI
;
1014 if (bitmap_bit_p (&control_dependency_cache
[insn_luid
], elem_luid
))
1015 present_dep_types
|= DEP_CONTROL
;
1017 if (present_dep_types
== 0)
1018 /* There is no existing dep so it should be created. */
1021 if (!(current_sched_info
->flags
& DO_SPECULATION
)
1022 || !bitmap_bit_p (&spec_dependency_cache
[insn_luid
], elem_luid
))
1024 if ((present_dep_types
| (DEP_STATUS (dep
) & DEP_TYPES
))
1025 == present_dep_types
)
1026 /* DEP does not add anything to the existing dependence. */
1031 /* Only true dependencies can be data speculative and
1032 only anti dependencies can be control speculative. */
1033 gcc_assert ((present_dep_types
& (DEP_TRUE
| DEP_ANTI
))
1034 == present_dep_types
);
1036 /* if (DEP is SPECULATIVE) then
1037 ..we should update DEP_STATUS
1039 ..we should reset existing dep to non-speculative. */
1046 /* Set dependency caches according to DEP. */
1048 set_dependency_caches (dep_t dep
)
1050 int elem_luid
= INSN_LUID (DEP_PRO (dep
));
1051 int insn_luid
= INSN_LUID (DEP_CON (dep
));
1053 if (!(current_sched_info
->flags
& USE_DEPS_LIST
))
1055 switch (DEP_TYPE (dep
))
1058 bitmap_set_bit (&true_dependency_cache
[insn_luid
], elem_luid
);
1061 case REG_DEP_OUTPUT
:
1062 bitmap_set_bit (&output_dependency_cache
[insn_luid
], elem_luid
);
1066 bitmap_set_bit (&anti_dependency_cache
[insn_luid
], elem_luid
);
1069 case REG_DEP_CONTROL
:
1070 bitmap_set_bit (&control_dependency_cache
[insn_luid
], elem_luid
);
1079 ds_t ds
= DEP_STATUS (dep
);
1082 bitmap_set_bit (&true_dependency_cache
[insn_luid
], elem_luid
);
1083 if (ds
& DEP_OUTPUT
)
1084 bitmap_set_bit (&output_dependency_cache
[insn_luid
], elem_luid
);
1086 bitmap_set_bit (&anti_dependency_cache
[insn_luid
], elem_luid
);
1087 if (ds
& DEP_CONTROL
)
1088 bitmap_set_bit (&control_dependency_cache
[insn_luid
], elem_luid
);
1090 if (ds
& SPECULATIVE
)
1092 gcc_assert (current_sched_info
->flags
& DO_SPECULATION
);
1093 bitmap_set_bit (&spec_dependency_cache
[insn_luid
], elem_luid
);
1098 /* Type of dependence DEP have changed from OLD_TYPE. Update dependency
1099 caches accordingly. */
1101 update_dependency_caches (dep_t dep
, enum reg_note old_type
)
1103 int elem_luid
= INSN_LUID (DEP_PRO (dep
));
1104 int insn_luid
= INSN_LUID (DEP_CON (dep
));
1106 /* Clear corresponding cache entry because type of the link
1107 may have changed. Keep them if we use_deps_list. */
1108 if (!(current_sched_info
->flags
& USE_DEPS_LIST
))
1112 case REG_DEP_OUTPUT
:
1113 bitmap_clear_bit (&output_dependency_cache
[insn_luid
], elem_luid
);
1117 bitmap_clear_bit (&anti_dependency_cache
[insn_luid
], elem_luid
);
1120 case REG_DEP_CONTROL
:
1121 bitmap_clear_bit (&control_dependency_cache
[insn_luid
], elem_luid
);
1129 set_dependency_caches (dep
);
1132 /* Convert a dependence pointed to by SD_IT to be non-speculative. */
1134 change_spec_dep_to_hard (sd_iterator_def sd_it
)
1136 dep_node_t node
= DEP_LINK_NODE (*sd_it
.linkp
);
1137 dep_link_t link
= DEP_NODE_BACK (node
);
1138 dep_t dep
= DEP_NODE_DEP (node
);
1139 rtx_insn
*elem
= DEP_PRO (dep
);
1140 rtx_insn
*insn
= DEP_CON (dep
);
1142 move_dep_link (link
, INSN_SPEC_BACK_DEPS (insn
), INSN_HARD_BACK_DEPS (insn
));
1144 DEP_STATUS (dep
) &= ~SPECULATIVE
;
1146 if (true_dependency_cache
!= NULL
)
1147 /* Clear the cache entry. */
1148 bitmap_clear_bit (&spec_dependency_cache
[INSN_LUID (insn
)],
1152 /* Update DEP to incorporate information from NEW_DEP.
1153 SD_IT points to DEP in case it should be moved to another list.
1154 MEM1 and MEM2, if nonnull, correspond to memory locations in case if
1155 data-speculative dependence should be updated. */
1156 static enum DEPS_ADJUST_RESULT
1157 update_dep (dep_t dep
, dep_t new_dep
,
1158 sd_iterator_def sd_it ATTRIBUTE_UNUSED
,
1159 rtx mem1 ATTRIBUTE_UNUSED
,
1160 rtx mem2 ATTRIBUTE_UNUSED
)
1162 enum DEPS_ADJUST_RESULT res
= DEP_PRESENT
;
1163 enum reg_note old_type
= DEP_TYPE (dep
);
1164 bool was_spec
= dep_spec_p (dep
);
1166 DEP_NONREG (dep
) |= DEP_NONREG (new_dep
);
1167 DEP_MULTIPLE (dep
) = 1;
1169 /* If this is a more restrictive type of dependence than the
1170 existing one, then change the existing dependence to this
1172 if ((int) DEP_TYPE (new_dep
) < (int) old_type
)
1174 DEP_TYPE (dep
) = DEP_TYPE (new_dep
);
1178 if (current_sched_info
->flags
& USE_DEPS_LIST
)
1179 /* Update DEP_STATUS. */
1181 ds_t dep_status
= DEP_STATUS (dep
);
1182 ds_t ds
= DEP_STATUS (new_dep
);
1183 ds_t new_status
= ds
| dep_status
;
1185 if (new_status
& SPECULATIVE
)
1187 /* Either existing dep or a dep we're adding or both are
1189 if (!(ds
& SPECULATIVE
)
1190 || !(dep_status
& SPECULATIVE
))
1191 /* The new dep can't be speculative. */
1192 new_status
&= ~SPECULATIVE
;
1195 /* Both are speculative. Merge probabilities. */
1200 dw
= estimate_dep_weak (mem1
, mem2
);
1201 ds
= set_dep_weak (ds
, BEGIN_DATA
, dw
);
1204 new_status
= ds_merge (dep_status
, ds
);
1210 if (dep_status
!= ds
)
1212 DEP_STATUS (dep
) = ds
;
1217 if (was_spec
&& !dep_spec_p (dep
))
1218 /* The old dep was speculative, but now it isn't. */
1219 change_spec_dep_to_hard (sd_it
);
1221 if (true_dependency_cache
!= NULL
1222 && res
== DEP_CHANGED
)
1223 update_dependency_caches (dep
, old_type
);
1228 /* Add or update a dependence described by DEP.
1229 MEM1 and MEM2, if non-null, correspond to memory locations in case of
1232 The function returns a value indicating if an old entry has been changed
1233 or a new entry has been added to insn's backward deps or nothing has
1234 been updated at all. */
1235 static enum DEPS_ADJUST_RESULT
1236 add_or_update_dep_1 (dep_t new_dep
, bool resolved_p
,
1237 rtx mem1 ATTRIBUTE_UNUSED
, rtx mem2 ATTRIBUTE_UNUSED
)
1239 bool maybe_present_p
= true;
1240 bool present_p
= false;
1242 gcc_assert (INSN_P (DEP_PRO (new_dep
)) && INSN_P (DEP_CON (new_dep
))
1243 && DEP_PRO (new_dep
) != DEP_CON (new_dep
));
1245 #ifdef ENABLE_CHECKING
1246 check_dep (new_dep
, mem1
!= NULL
);
1249 if (true_dependency_cache
!= NULL
)
1251 switch (ask_dependency_caches (new_dep
))
1255 sd_iterator_def sd_it
;
1257 present_dep
= sd_find_dep_between_no_cache (DEP_PRO (new_dep
),
1259 resolved_p
, &sd_it
);
1260 DEP_MULTIPLE (present_dep
) = 1;
1264 maybe_present_p
= true;
1269 maybe_present_p
= false;
1279 /* Check that we don't already have this dependence. */
1280 if (maybe_present_p
)
1283 sd_iterator_def sd_it
;
1285 gcc_assert (true_dependency_cache
== NULL
|| present_p
);
1287 present_dep
= sd_find_dep_between_no_cache (DEP_PRO (new_dep
),
1289 resolved_p
, &sd_it
);
1291 if (present_dep
!= NULL
)
1292 /* We found an existing dependency between ELEM and INSN. */
1293 return update_dep (present_dep
, new_dep
, sd_it
, mem1
, mem2
);
1295 /* We didn't find a dep, it shouldn't present in the cache. */
1296 gcc_assert (!present_p
);
1299 /* Might want to check one level of transitivity to save conses.
1300 This check should be done in maybe_add_or_update_dep_1.
1301 Since we made it to add_or_update_dep_1, we must create
1302 (or update) a link. */
1304 if (mem1
!= NULL_RTX
)
1306 gcc_assert (sched_deps_info
->generate_spec_deps
);
1307 DEP_STATUS (new_dep
) = set_dep_weak (DEP_STATUS (new_dep
), BEGIN_DATA
,
1308 estimate_dep_weak (mem1
, mem2
));
1311 sd_add_dep (new_dep
, resolved_p
);
1316 /* Initialize BACK_LIST_PTR with consumer's backward list and
1317 FORW_LIST_PTR with producer's forward list. If RESOLVED_P is true
1318 initialize with lists that hold resolved deps. */
1320 get_back_and_forw_lists (dep_t dep
, bool resolved_p
,
1321 deps_list_t
*back_list_ptr
,
1322 deps_list_t
*forw_list_ptr
)
1324 rtx_insn
*con
= DEP_CON (dep
);
1328 if (dep_spec_p (dep
))
1329 *back_list_ptr
= INSN_SPEC_BACK_DEPS (con
);
1331 *back_list_ptr
= INSN_HARD_BACK_DEPS (con
);
1333 *forw_list_ptr
= INSN_FORW_DEPS (DEP_PRO (dep
));
1337 *back_list_ptr
= INSN_RESOLVED_BACK_DEPS (con
);
1338 *forw_list_ptr
= INSN_RESOLVED_FORW_DEPS (DEP_PRO (dep
));
1342 /* Add dependence described by DEP.
1343 If RESOLVED_P is true treat the dependence as a resolved one. */
1345 sd_add_dep (dep_t dep
, bool resolved_p
)
1347 dep_node_t n
= create_dep_node ();
1348 deps_list_t con_back_deps
;
1349 deps_list_t pro_forw_deps
;
1350 rtx_insn
*elem
= DEP_PRO (dep
);
1351 rtx_insn
*insn
= DEP_CON (dep
);
1353 gcc_assert (INSN_P (insn
) && INSN_P (elem
) && insn
!= elem
);
1355 if ((current_sched_info
->flags
& DO_SPECULATION
) == 0
1356 || !sched_insn_is_legitimate_for_speculation_p (insn
, DEP_STATUS (dep
)))
1357 DEP_STATUS (dep
) &= ~SPECULATIVE
;
1359 copy_dep (DEP_NODE_DEP (n
), dep
);
1361 get_back_and_forw_lists (dep
, resolved_p
, &con_back_deps
, &pro_forw_deps
);
1363 add_to_deps_list (DEP_NODE_BACK (n
), con_back_deps
);
1365 #ifdef ENABLE_CHECKING
1366 check_dep (dep
, false);
1369 add_to_deps_list (DEP_NODE_FORW (n
), pro_forw_deps
);
1371 /* If we are adding a dependency to INSN's LOG_LINKs, then note that
1372 in the bitmap caches of dependency information. */
1373 if (true_dependency_cache
!= NULL
)
1374 set_dependency_caches (dep
);
1377 /* Add or update backward dependence between INSN and ELEM
1378 with given type DEP_TYPE and dep_status DS.
1379 This function is a convenience wrapper. */
1380 enum DEPS_ADJUST_RESULT
1381 sd_add_or_update_dep (dep_t dep
, bool resolved_p
)
1383 return add_or_update_dep_1 (dep
, resolved_p
, NULL_RTX
, NULL_RTX
);
1386 /* Resolved dependence pointed to by SD_IT.
1387 SD_IT will advance to the next element. */
1389 sd_resolve_dep (sd_iterator_def sd_it
)
1391 dep_node_t node
= DEP_LINK_NODE (*sd_it
.linkp
);
1392 dep_t dep
= DEP_NODE_DEP (node
);
1393 rtx_insn
*pro
= DEP_PRO (dep
);
1394 rtx_insn
*con
= DEP_CON (dep
);
1396 if (dep_spec_p (dep
))
1397 move_dep_link (DEP_NODE_BACK (node
), INSN_SPEC_BACK_DEPS (con
),
1398 INSN_RESOLVED_BACK_DEPS (con
));
1400 move_dep_link (DEP_NODE_BACK (node
), INSN_HARD_BACK_DEPS (con
),
1401 INSN_RESOLVED_BACK_DEPS (con
));
1403 move_dep_link (DEP_NODE_FORW (node
), INSN_FORW_DEPS (pro
),
1404 INSN_RESOLVED_FORW_DEPS (pro
));
1407 /* Perform the inverse operation of sd_resolve_dep. Restore the dependence
1408 pointed to by SD_IT to unresolved state. */
1410 sd_unresolve_dep (sd_iterator_def sd_it
)
1412 dep_node_t node
= DEP_LINK_NODE (*sd_it
.linkp
);
1413 dep_t dep
= DEP_NODE_DEP (node
);
1414 rtx_insn
*pro
= DEP_PRO (dep
);
1415 rtx_insn
*con
= DEP_CON (dep
);
1417 if (dep_spec_p (dep
))
1418 move_dep_link (DEP_NODE_BACK (node
), INSN_RESOLVED_BACK_DEPS (con
),
1419 INSN_SPEC_BACK_DEPS (con
));
1421 move_dep_link (DEP_NODE_BACK (node
), INSN_RESOLVED_BACK_DEPS (con
),
1422 INSN_HARD_BACK_DEPS (con
));
1424 move_dep_link (DEP_NODE_FORW (node
), INSN_RESOLVED_FORW_DEPS (pro
),
1425 INSN_FORW_DEPS (pro
));
1428 /* Make TO depend on all the FROM's producers.
1429 If RESOLVED_P is true add dependencies to the resolved lists. */
1431 sd_copy_back_deps (rtx_insn
*to
, rtx_insn
*from
, bool resolved_p
)
1433 sd_list_types_def list_type
;
1434 sd_iterator_def sd_it
;
1437 list_type
= resolved_p
? SD_LIST_RES_BACK
: SD_LIST_BACK
;
1439 FOR_EACH_DEP (from
, list_type
, sd_it
, dep
)
1441 dep_def _new_dep
, *new_dep
= &_new_dep
;
1443 copy_dep (new_dep
, dep
);
1444 DEP_CON (new_dep
) = to
;
1445 sd_add_dep (new_dep
, resolved_p
);
1449 /* Remove a dependency referred to by SD_IT.
1450 SD_IT will point to the next dependence after removal. */
1452 sd_delete_dep (sd_iterator_def sd_it
)
1454 dep_node_t n
= DEP_LINK_NODE (*sd_it
.linkp
);
1455 dep_t dep
= DEP_NODE_DEP (n
);
1456 rtx_insn
*pro
= DEP_PRO (dep
);
1457 rtx_insn
*con
= DEP_CON (dep
);
1458 deps_list_t con_back_deps
;
1459 deps_list_t pro_forw_deps
;
1461 if (true_dependency_cache
!= NULL
)
1463 int elem_luid
= INSN_LUID (pro
);
1464 int insn_luid
= INSN_LUID (con
);
1466 bitmap_clear_bit (&true_dependency_cache
[insn_luid
], elem_luid
);
1467 bitmap_clear_bit (&anti_dependency_cache
[insn_luid
], elem_luid
);
1468 bitmap_clear_bit (&control_dependency_cache
[insn_luid
], elem_luid
);
1469 bitmap_clear_bit (&output_dependency_cache
[insn_luid
], elem_luid
);
1471 if (current_sched_info
->flags
& DO_SPECULATION
)
1472 bitmap_clear_bit (&spec_dependency_cache
[insn_luid
], elem_luid
);
1475 get_back_and_forw_lists (dep
, sd_it
.resolved_p
,
1476 &con_back_deps
, &pro_forw_deps
);
1478 remove_from_deps_list (DEP_NODE_BACK (n
), con_back_deps
);
1479 remove_from_deps_list (DEP_NODE_FORW (n
), pro_forw_deps
);
1481 delete_dep_node (n
);
1484 /* Dump size of the lists. */
1485 #define DUMP_LISTS_SIZE (2)
1487 /* Dump dependencies of the lists. */
1488 #define DUMP_LISTS_DEPS (4)
1490 /* Dump all information about the lists. */
1491 #define DUMP_LISTS_ALL (DUMP_LISTS_SIZE | DUMP_LISTS_DEPS)
1493 /* Dump deps_lists of INSN specified by TYPES to DUMP.
1494 FLAGS is a bit mask specifying what information about the lists needs
1496 If FLAGS has the very first bit set, then dump all information about
1497 the lists and propagate this bit into the callee dump functions. */
1499 dump_lists (FILE *dump
, rtx insn
, sd_list_types_def types
, int flags
)
1501 sd_iterator_def sd_it
;
1508 flags
|= DUMP_LISTS_ALL
;
1510 fprintf (dump
, "[");
1512 if (flags
& DUMP_LISTS_SIZE
)
1513 fprintf (dump
, "%d; ", sd_lists_size (insn
, types
));
1515 if (flags
& DUMP_LISTS_DEPS
)
1517 FOR_EACH_DEP (insn
, types
, sd_it
, dep
)
1519 dump_dep (dump
, dep
, dump_dep_flags
| all
);
1520 fprintf (dump
, " ");
1525 /* Dump all information about deps_lists of INSN specified by TYPES
1528 sd_debug_lists (rtx insn
, sd_list_types_def types
)
1530 dump_lists (stderr
, insn
, types
, 1);
1531 fprintf (stderr
, "\n");
1534 /* A wrapper around add_dependence_1, to add a dependence of CON on
1535 PRO, with type DEP_TYPE. This function implements special handling
1536 for REG_DEP_CONTROL dependencies. For these, we optionally promote
1537 the type to REG_DEP_ANTI if we can determine that predication is
1538 impossible; otherwise we add additional true dependencies on the
1539 INSN_COND_DEPS list of the jump (which PRO must be). */
1541 add_dependence (rtx_insn
*con
, rtx_insn
*pro
, enum reg_note dep_type
)
1543 if (dep_type
== REG_DEP_CONTROL
1544 && !(current_sched_info
->flags
& DO_PREDICATION
))
1545 dep_type
= REG_DEP_ANTI
;
1547 /* A REG_DEP_CONTROL dependence may be eliminated through predication,
1548 so we must also make the insn dependent on the setter of the
1550 if (dep_type
== REG_DEP_CONTROL
)
1552 rtx_insn
*real_pro
= pro
;
1553 rtx_insn
*other
= real_insn_for_shadow (real_pro
);
1556 if (other
!= NULL_RTX
)
1558 cond
= sched_get_reverse_condition_uncached (real_pro
);
1559 /* Verify that the insn does not use a different value in
1560 the condition register than the one that was present at
1562 if (cond
== NULL_RTX
)
1563 dep_type
= REG_DEP_ANTI
;
1564 else if (INSN_CACHED_COND (real_pro
) == const_true_rtx
)
1567 CLEAR_HARD_REG_SET (uses
);
1568 note_uses (&PATTERN (con
), record_hard_reg_uses
, &uses
);
1569 if (TEST_HARD_REG_BIT (uses
, REGNO (XEXP (cond
, 0))))
1570 dep_type
= REG_DEP_ANTI
;
1572 if (dep_type
== REG_DEP_CONTROL
)
1574 if (sched_verbose
>= 5)
1575 fprintf (sched_dump
, "making DEP_CONTROL for %d\n",
1576 INSN_UID (real_pro
));
1577 add_dependence_list (con
, INSN_COND_DEPS (real_pro
), 0,
1578 REG_DEP_TRUE
, false);
1582 add_dependence_1 (con
, pro
, dep_type
);
1585 /* A convenience wrapper to operate on an entire list. HARD should be
1586 true if DEP_NONREG should be set on newly created dependencies. */
1589 add_dependence_list (rtx_insn
*insn
, rtx_insn_list
*list
, int uncond
,
1590 enum reg_note dep_type
, bool hard
)
1592 mark_as_hard
= hard
;
1593 for (; list
; list
= list
->next ())
1595 if (uncond
|| ! sched_insns_conditions_mutex_p (insn
, list
->insn ()))
1596 add_dependence (insn
, list
->insn (), dep_type
);
1598 mark_as_hard
= false;
1601 /* Similar, but free *LISTP at the same time, when the context
1602 is not readonly. HARD should be true if DEP_NONREG should be set on
1603 newly created dependencies. */
1606 add_dependence_list_and_free (struct deps_desc
*deps
, rtx_insn
*insn
,
1607 rtx_insn_list
**listp
,
1608 int uncond
, enum reg_note dep_type
, bool hard
)
1610 add_dependence_list (insn
, *listp
, uncond
, dep_type
, hard
);
1612 /* We don't want to short-circuit dependencies involving debug
1613 insns, because they may cause actual dependencies to be
1615 if (deps
->readonly
|| DEBUG_INSN_P (insn
))
1618 free_INSN_LIST_list (listp
);
1621 /* Remove all occurrences of INSN from LIST. Return the number of
1622 occurrences removed. */
1625 remove_from_dependence_list (rtx insn
, rtx_insn_list
**listp
)
1631 if ((*listp
)->insn () == insn
)
1633 remove_free_INSN_LIST_node (listp
);
1638 listp
= (rtx_insn_list
**)&XEXP (*listp
, 1);
1644 /* Same as above, but process two lists at once. */
1646 remove_from_both_dependence_lists (rtx insn
,
1647 rtx_insn_list
**listp
,
1648 rtx_expr_list
**exprp
)
1654 if (XEXP (*listp
, 0) == insn
)
1656 remove_free_INSN_LIST_node (listp
);
1657 remove_free_EXPR_LIST_node (exprp
);
1662 listp
= (rtx_insn_list
**)&XEXP (*listp
, 1);
1663 exprp
= (rtx_expr_list
**)&XEXP (*exprp
, 1);
1669 /* Clear all dependencies for an insn. */
1671 delete_all_dependences (rtx insn
)
1673 sd_iterator_def sd_it
;
1676 /* The below cycle can be optimized to clear the caches and back_deps
1677 in one call but that would provoke duplication of code from
1680 for (sd_it
= sd_iterator_start (insn
, SD_LIST_BACK
);
1681 sd_iterator_cond (&sd_it
, &dep
);)
1682 sd_delete_dep (sd_it
);
1685 /* All insns in a scheduling group except the first should only have
1686 dependencies on the previous insn in the group. So we find the
1687 first instruction in the scheduling group by walking the dependence
1688 chains backwards. Then we add the dependencies for the group to
1689 the previous nonnote insn. */
1692 chain_to_prev_insn (rtx_insn
*insn
)
1694 sd_iterator_def sd_it
;
1696 rtx_insn
*prev_nonnote
;
1698 FOR_EACH_DEP (insn
, SD_LIST_BACK
, sd_it
, dep
)
1701 rtx_insn
*pro
= DEP_PRO (dep
);
1705 i
= prev_nonnote_insn (i
);
1709 } while (SCHED_GROUP_P (i
) || DEBUG_INSN_P (i
));
1711 if (! sched_insns_conditions_mutex_p (i
, pro
))
1712 add_dependence (i
, pro
, DEP_TYPE (dep
));
1716 delete_all_dependences (insn
);
1718 prev_nonnote
= prev_nonnote_nondebug_insn (insn
);
1719 if (BLOCK_FOR_INSN (insn
) == BLOCK_FOR_INSN (prev_nonnote
)
1720 && ! sched_insns_conditions_mutex_p (insn
, prev_nonnote
))
1721 add_dependence (insn
, prev_nonnote
, REG_DEP_ANTI
);
1724 /* Process an insn's memory dependencies. There are four kinds of
1727 (0) read dependence: read follows read
1728 (1) true dependence: read follows write
1729 (2) output dependence: write follows write
1730 (3) anti dependence: write follows read
1732 We are careful to build only dependencies which actually exist, and
1733 use transitivity to avoid building too many links. */
1735 /* Add an INSN and MEM reference pair to a pending INSN_LIST and MEM_LIST.
1736 The MEM is a memory reference contained within INSN, which we are saving
1737 so that we can do memory aliasing on it. */
1740 add_insn_mem_dependence (struct deps_desc
*deps
, bool read_p
,
1741 rtx_insn
*insn
, rtx mem
)
1743 rtx_insn_list
**insn_list
;
1744 rtx_insn_list
*insn_node
;
1745 rtx_expr_list
**mem_list
;
1746 rtx_expr_list
*mem_node
;
1748 gcc_assert (!deps
->readonly
);
1751 insn_list
= &deps
->pending_read_insns
;
1752 mem_list
= &deps
->pending_read_mems
;
1753 if (!DEBUG_INSN_P (insn
))
1754 deps
->pending_read_list_length
++;
1758 insn_list
= &deps
->pending_write_insns
;
1759 mem_list
= &deps
->pending_write_mems
;
1760 deps
->pending_write_list_length
++;
1763 insn_node
= alloc_INSN_LIST (insn
, *insn_list
);
1764 *insn_list
= insn_node
;
1766 if (sched_deps_info
->use_cselib
)
1768 mem
= shallow_copy_rtx (mem
);
1769 XEXP (mem
, 0) = cselib_subst_to_values_from_insn (XEXP (mem
, 0),
1770 GET_MODE (mem
), insn
);
1772 mem_node
= alloc_EXPR_LIST (VOIDmode
, canon_rtx (mem
), *mem_list
);
1773 *mem_list
= mem_node
;
1776 /* Make a dependency between every memory reference on the pending lists
1777 and INSN, thus flushing the pending lists. FOR_READ is true if emitting
1778 dependencies for a read operation, similarly with FOR_WRITE. */
1781 flush_pending_lists (struct deps_desc
*deps
, rtx_insn
*insn
, int for_read
,
1786 add_dependence_list_and_free (deps
, insn
, &deps
->pending_read_insns
,
1787 1, REG_DEP_ANTI
, true);
1788 if (!deps
->readonly
)
1790 free_EXPR_LIST_list (&deps
->pending_read_mems
);
1791 deps
->pending_read_list_length
= 0;
1795 add_dependence_list_and_free (deps
, insn
, &deps
->pending_write_insns
, 1,
1796 for_read
? REG_DEP_ANTI
: REG_DEP_OUTPUT
,
1799 add_dependence_list_and_free (deps
, insn
,
1800 &deps
->last_pending_memory_flush
, 1,
1801 for_read
? REG_DEP_ANTI
: REG_DEP_OUTPUT
,
1804 add_dependence_list_and_free (deps
, insn
, &deps
->pending_jump_insns
, 1,
1805 REG_DEP_ANTI
, true);
1807 if (DEBUG_INSN_P (insn
))
1810 free_INSN_LIST_list (&deps
->pending_read_insns
);
1811 free_INSN_LIST_list (&deps
->pending_write_insns
);
1812 free_INSN_LIST_list (&deps
->last_pending_memory_flush
);
1813 free_INSN_LIST_list (&deps
->pending_jump_insns
);
1816 if (!deps
->readonly
)
1818 free_EXPR_LIST_list (&deps
->pending_write_mems
);
1819 deps
->pending_write_list_length
= 0;
1821 deps
->last_pending_memory_flush
= alloc_INSN_LIST (insn
, NULL_RTX
);
1822 deps
->pending_flush_length
= 1;
1824 mark_as_hard
= false;
1827 /* Instruction which dependencies we are analyzing. */
1828 static rtx_insn
*cur_insn
= NULL
;
1830 /* Implement hooks for haifa scheduler. */
1833 haifa_start_insn (rtx_insn
*insn
)
1835 gcc_assert (insn
&& !cur_insn
);
1841 haifa_finish_insn (void)
1847 haifa_note_reg_set (int regno
)
1849 SET_REGNO_REG_SET (reg_pending_sets
, regno
);
1853 haifa_note_reg_clobber (int regno
)
1855 SET_REGNO_REG_SET (reg_pending_clobbers
, regno
);
1859 haifa_note_reg_use (int regno
)
1861 SET_REGNO_REG_SET (reg_pending_uses
, regno
);
1865 haifa_note_mem_dep (rtx mem
, rtx pending_mem
, rtx_insn
*pending_insn
, ds_t ds
)
1867 if (!(ds
& SPECULATIVE
))
1870 pending_mem
= NULL_RTX
;
1873 gcc_assert (ds
& BEGIN_DATA
);
1876 dep_def _dep
, *dep
= &_dep
;
1878 init_dep_1 (dep
, pending_insn
, cur_insn
, ds_to_dt (ds
),
1879 current_sched_info
->flags
& USE_DEPS_LIST
? ds
: 0);
1880 DEP_NONREG (dep
) = 1;
1881 maybe_add_or_update_dep_1 (dep
, false, pending_mem
, mem
);
1887 haifa_note_dep (rtx_insn
*elem
, ds_t ds
)
1892 init_dep (dep
, elem
, cur_insn
, ds_to_dt (ds
));
1894 DEP_NONREG (dep
) = 1;
1895 maybe_add_or_update_dep_1 (dep
, false, NULL_RTX
, NULL_RTX
);
1899 note_reg_use (int r
)
1901 if (sched_deps_info
->note_reg_use
)
1902 sched_deps_info
->note_reg_use (r
);
1906 note_reg_set (int r
)
1908 if (sched_deps_info
->note_reg_set
)
1909 sched_deps_info
->note_reg_set (r
);
1913 note_reg_clobber (int r
)
1915 if (sched_deps_info
->note_reg_clobber
)
1916 sched_deps_info
->note_reg_clobber (r
);
1920 note_mem_dep (rtx m1
, rtx m2
, rtx_insn
*e
, ds_t ds
)
1922 if (sched_deps_info
->note_mem_dep
)
1923 sched_deps_info
->note_mem_dep (m1
, m2
, e
, ds
);
1927 note_dep (rtx_insn
*e
, ds_t ds
)
1929 if (sched_deps_info
->note_dep
)
1930 sched_deps_info
->note_dep (e
, ds
);
1933 /* Return corresponding to DS reg_note. */
1938 return REG_DEP_TRUE
;
1939 else if (ds
& DEP_OUTPUT
)
1940 return REG_DEP_OUTPUT
;
1941 else if (ds
& DEP_ANTI
)
1942 return REG_DEP_ANTI
;
1945 gcc_assert (ds
& DEP_CONTROL
);
1946 return REG_DEP_CONTROL
;
1952 /* Functions for computation of info needed for register pressure
1953 sensitive insn scheduling. */
1956 /* Allocate and return reg_use_data structure for REGNO and INSN. */
1957 static struct reg_use_data
*
1958 create_insn_reg_use (int regno
, rtx_insn
*insn
)
1960 struct reg_use_data
*use
;
1962 use
= (struct reg_use_data
*) xmalloc (sizeof (struct reg_use_data
));
1965 use
->next_insn_use
= INSN_REG_USE_LIST (insn
);
1966 INSN_REG_USE_LIST (insn
) = use
;
1970 /* Allocate reg_set_data structure for REGNO and INSN. */
1972 create_insn_reg_set (int regno
, rtx insn
)
1974 struct reg_set_data
*set
;
1976 set
= (struct reg_set_data
*) xmalloc (sizeof (struct reg_set_data
));
1979 set
->next_insn_set
= INSN_REG_SET_LIST (insn
);
1980 INSN_REG_SET_LIST (insn
) = set
;
1983 /* Set up insn register uses for INSN and dependency context DEPS. */
1985 setup_insn_reg_uses (struct deps_desc
*deps
, rtx_insn
*insn
)
1988 reg_set_iterator rsi
;
1989 struct reg_use_data
*use
, *use2
, *next
;
1990 struct deps_reg
*reg_last
;
1992 EXECUTE_IF_SET_IN_REG_SET (reg_pending_uses
, 0, i
, rsi
)
1994 if (i
< FIRST_PSEUDO_REGISTER
1995 && TEST_HARD_REG_BIT (ira_no_alloc_regs
, i
))
1998 if (find_regno_note (insn
, REG_DEAD
, i
) == NULL_RTX
1999 && ! REGNO_REG_SET_P (reg_pending_sets
, i
)
2000 && ! REGNO_REG_SET_P (reg_pending_clobbers
, i
))
2001 /* Ignore use which is not dying. */
2004 use
= create_insn_reg_use (i
, insn
);
2005 use
->next_regno_use
= use
;
2006 reg_last
= &deps
->reg_last
[i
];
2008 /* Create the cycle list of uses. */
2009 for (rtx_insn_list
*list
= reg_last
->uses
; list
; list
= list
->next ())
2011 use2
= create_insn_reg_use (i
, list
->insn ());
2012 next
= use
->next_regno_use
;
2013 use
->next_regno_use
= use2
;
2014 use2
->next_regno_use
= next
;
2019 /* Register pressure info for the currently processed insn. */
2020 static struct reg_pressure_data reg_pressure_info
[N_REG_CLASSES
];
2022 /* Return TRUE if INSN has the use structure for REGNO. */
2024 insn_use_p (rtx insn
, int regno
)
2026 struct reg_use_data
*use
;
2028 for (use
= INSN_REG_USE_LIST (insn
); use
!= NULL
; use
= use
->next_insn_use
)
2029 if (use
->regno
== regno
)
2034 /* Update the register pressure info after birth of pseudo register REGNO
2035 in INSN. Arguments CLOBBER_P and UNUSED_P say correspondingly that
2036 the register is in clobber or unused after the insn. */
2038 mark_insn_pseudo_birth (rtx insn
, int regno
, bool clobber_p
, bool unused_p
)
2043 gcc_assert (regno
>= FIRST_PSEUDO_REGISTER
);
2044 cl
= sched_regno_pressure_class
[regno
];
2047 incr
= ira_reg_class_max_nregs
[cl
][PSEUDO_REGNO_MODE (regno
)];
2050 new_incr
= reg_pressure_info
[cl
].clobber_increase
+ incr
;
2051 reg_pressure_info
[cl
].clobber_increase
= new_incr
;
2055 new_incr
= reg_pressure_info
[cl
].unused_set_increase
+ incr
;
2056 reg_pressure_info
[cl
].unused_set_increase
= new_incr
;
2060 new_incr
= reg_pressure_info
[cl
].set_increase
+ incr
;
2061 reg_pressure_info
[cl
].set_increase
= new_incr
;
2062 if (! insn_use_p (insn
, regno
))
2063 reg_pressure_info
[cl
].change
+= incr
;
2064 create_insn_reg_set (regno
, insn
);
2066 gcc_assert (new_incr
< (1 << INCREASE_BITS
));
2070 /* Like mark_insn_pseudo_regno_birth except that NREGS saying how many
2071 hard registers involved in the birth. */
2073 mark_insn_hard_regno_birth (rtx insn
, int regno
, int nregs
,
2074 bool clobber_p
, bool unused_p
)
2077 int new_incr
, last
= regno
+ nregs
;
2079 while (regno
< last
)
2081 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
2082 if (! TEST_HARD_REG_BIT (ira_no_alloc_regs
, regno
))
2084 cl
= sched_regno_pressure_class
[regno
];
2089 new_incr
= reg_pressure_info
[cl
].clobber_increase
+ 1;
2090 reg_pressure_info
[cl
].clobber_increase
= new_incr
;
2094 new_incr
= reg_pressure_info
[cl
].unused_set_increase
+ 1;
2095 reg_pressure_info
[cl
].unused_set_increase
= new_incr
;
2099 new_incr
= reg_pressure_info
[cl
].set_increase
+ 1;
2100 reg_pressure_info
[cl
].set_increase
= new_incr
;
2101 if (! insn_use_p (insn
, regno
))
2102 reg_pressure_info
[cl
].change
+= 1;
2103 create_insn_reg_set (regno
, insn
);
2105 gcc_assert (new_incr
< (1 << INCREASE_BITS
));
2112 /* Update the register pressure info after birth of pseudo or hard
2113 register REG in INSN. Arguments CLOBBER_P and UNUSED_P say
2114 correspondingly that the register is in clobber or unused after the
2117 mark_insn_reg_birth (rtx insn
, rtx reg
, bool clobber_p
, bool unused_p
)
2121 if (GET_CODE (reg
) == SUBREG
)
2122 reg
= SUBREG_REG (reg
);
2127 regno
= REGNO (reg
);
2128 if (regno
< FIRST_PSEUDO_REGISTER
)
2129 mark_insn_hard_regno_birth (insn
, regno
,
2130 hard_regno_nregs
[regno
][GET_MODE (reg
)],
2131 clobber_p
, unused_p
);
2133 mark_insn_pseudo_birth (insn
, regno
, clobber_p
, unused_p
);
2136 /* Update the register pressure info after death of pseudo register
2139 mark_pseudo_death (int regno
)
2144 gcc_assert (regno
>= FIRST_PSEUDO_REGISTER
);
2145 cl
= sched_regno_pressure_class
[regno
];
2148 incr
= ira_reg_class_max_nregs
[cl
][PSEUDO_REGNO_MODE (regno
)];
2149 reg_pressure_info
[cl
].change
-= incr
;
2153 /* Like mark_pseudo_death except that NREGS saying how many hard
2154 registers involved in the death. */
2156 mark_hard_regno_death (int regno
, int nregs
)
2159 int last
= regno
+ nregs
;
2161 while (regno
< last
)
2163 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
2164 if (! TEST_HARD_REG_BIT (ira_no_alloc_regs
, regno
))
2166 cl
= sched_regno_pressure_class
[regno
];
2168 reg_pressure_info
[cl
].change
-= 1;
2174 /* Update the register pressure info after death of pseudo or hard
2177 mark_reg_death (rtx reg
)
2181 if (GET_CODE (reg
) == SUBREG
)
2182 reg
= SUBREG_REG (reg
);
2187 regno
= REGNO (reg
);
2188 if (regno
< FIRST_PSEUDO_REGISTER
)
2189 mark_hard_regno_death (regno
, hard_regno_nregs
[regno
][GET_MODE (reg
)]);
2191 mark_pseudo_death (regno
);
2194 /* Process SETTER of REG. DATA is an insn containing the setter. */
2196 mark_insn_reg_store (rtx reg
, const_rtx setter
, void *data
)
2198 if (setter
!= NULL_RTX
&& GET_CODE (setter
) != SET
)
2201 ((rtx
) data
, reg
, false,
2202 find_reg_note ((const_rtx
) data
, REG_UNUSED
, reg
) != NULL_RTX
);
2205 /* Like mark_insn_reg_store except notice just CLOBBERs; ignore SETs. */
2207 mark_insn_reg_clobber (rtx reg
, const_rtx setter
, void *data
)
2209 if (GET_CODE (setter
) == CLOBBER
)
2210 mark_insn_reg_birth ((rtx
) data
, reg
, true, false);
2213 /* Set up reg pressure info related to INSN. */
2215 init_insn_reg_pressure_info (rtx insn
)
2219 static struct reg_pressure_data
*pressure_info
;
2222 gcc_assert (sched_pressure
!= SCHED_PRESSURE_NONE
);
2224 if (! INSN_P (insn
))
2227 for (i
= 0; i
< ira_pressure_classes_num
; i
++)
2229 cl
= ira_pressure_classes
[i
];
2230 reg_pressure_info
[cl
].clobber_increase
= 0;
2231 reg_pressure_info
[cl
].set_increase
= 0;
2232 reg_pressure_info
[cl
].unused_set_increase
= 0;
2233 reg_pressure_info
[cl
].change
= 0;
2236 note_stores (PATTERN (insn
), mark_insn_reg_clobber
, insn
);
2238 note_stores (PATTERN (insn
), mark_insn_reg_store
, insn
);
2241 for (link
= REG_NOTES (insn
); link
; link
= XEXP (link
, 1))
2242 if (REG_NOTE_KIND (link
) == REG_INC
)
2243 mark_insn_reg_store (XEXP (link
, 0), NULL_RTX
, insn
);
2246 for (link
= REG_NOTES (insn
); link
; link
= XEXP (link
, 1))
2247 if (REG_NOTE_KIND (link
) == REG_DEAD
)
2248 mark_reg_death (XEXP (link
, 0));
2250 len
= sizeof (struct reg_pressure_data
) * ira_pressure_classes_num
;
2252 = INSN_REG_PRESSURE (insn
) = (struct reg_pressure_data
*) xmalloc (len
);
2253 if (sched_pressure
== SCHED_PRESSURE_WEIGHTED
)
2254 INSN_MAX_REG_PRESSURE (insn
) = (int *) xcalloc (ira_pressure_classes_num
2256 for (i
= 0; i
< ira_pressure_classes_num
; i
++)
2258 cl
= ira_pressure_classes
[i
];
2259 pressure_info
[i
].clobber_increase
2260 = reg_pressure_info
[cl
].clobber_increase
;
2261 pressure_info
[i
].set_increase
= reg_pressure_info
[cl
].set_increase
;
2262 pressure_info
[i
].unused_set_increase
2263 = reg_pressure_info
[cl
].unused_set_increase
;
2264 pressure_info
[i
].change
= reg_pressure_info
[cl
].change
;
2271 /* Internal variable for sched_analyze_[12] () functions.
2272 If it is nonzero, this means that sched_analyze_[12] looks
2273 at the most toplevel SET. */
2274 static bool can_start_lhs_rhs_p
;
2276 /* Extend reg info for the deps context DEPS given that
2277 we have just generated a register numbered REGNO. */
2279 extend_deps_reg_info (struct deps_desc
*deps
, int regno
)
2281 int max_regno
= regno
+ 1;
2283 gcc_assert (!reload_completed
);
2285 /* In a readonly context, it would not hurt to extend info,
2286 but it should not be needed. */
2287 if (reload_completed
&& deps
->readonly
)
2289 deps
->max_reg
= max_regno
;
2293 if (max_regno
> deps
->max_reg
)
2295 deps
->reg_last
= XRESIZEVEC (struct deps_reg
, deps
->reg_last
,
2297 memset (&deps
->reg_last
[deps
->max_reg
],
2298 0, (max_regno
- deps
->max_reg
)
2299 * sizeof (struct deps_reg
));
2300 deps
->max_reg
= max_regno
;
2304 /* Extends REG_INFO_P if needed. */
2306 maybe_extend_reg_info_p (void)
2308 /* Extend REG_INFO_P, if needed. */
2309 if ((unsigned int)max_regno
- 1 >= reg_info_p_size
)
2311 size_t new_reg_info_p_size
= max_regno
+ 128;
2313 gcc_assert (!reload_completed
&& sel_sched_p ());
2315 reg_info_p
= (struct reg_info_t
*) xrecalloc (reg_info_p
,
2316 new_reg_info_p_size
,
2318 sizeof (*reg_info_p
));
2319 reg_info_p_size
= new_reg_info_p_size
;
2323 /* Analyze a single reference to register (reg:MODE REGNO) in INSN.
2324 The type of the reference is specified by REF and can be SET,
2325 CLOBBER, PRE_DEC, POST_DEC, PRE_INC, POST_INC or USE. */
2328 sched_analyze_reg (struct deps_desc
*deps
, int regno
, machine_mode mode
,
2329 enum rtx_code ref
, rtx_insn
*insn
)
2331 /* We could emit new pseudos in renaming. Extend the reg structures. */
2332 if (!reload_completed
&& sel_sched_p ()
2333 && (regno
>= max_reg_num () - 1 || regno
>= deps
->max_reg
))
2334 extend_deps_reg_info (deps
, regno
);
2336 maybe_extend_reg_info_p ();
2338 /* A hard reg in a wide mode may really be multiple registers.
2339 If so, mark all of them just like the first. */
2340 if (regno
< FIRST_PSEUDO_REGISTER
)
2342 int i
= hard_regno_nregs
[regno
][mode
];
2346 note_reg_set (regno
+ i
);
2348 else if (ref
== USE
)
2351 note_reg_use (regno
+ i
);
2356 note_reg_clobber (regno
+ i
);
2360 /* ??? Reload sometimes emits USEs and CLOBBERs of pseudos that
2361 it does not reload. Ignore these as they have served their
2363 else if (regno
>= deps
->max_reg
)
2365 enum rtx_code code
= GET_CODE (PATTERN (insn
));
2366 gcc_assert (code
== USE
|| code
== CLOBBER
);
2372 note_reg_set (regno
);
2373 else if (ref
== USE
)
2374 note_reg_use (regno
);
2376 note_reg_clobber (regno
);
2378 /* Pseudos that are REG_EQUIV to something may be replaced
2379 by that during reloading. We need only add dependencies for
2380 the address in the REG_EQUIV note. */
2381 if (!reload_completed
&& get_reg_known_equiv_p (regno
))
2383 rtx t
= get_reg_known_value (regno
);
2385 sched_analyze_2 (deps
, XEXP (t
, 0), insn
);
2388 /* Don't let it cross a call after scheduling if it doesn't
2389 already cross one. */
2390 if (REG_N_CALLS_CROSSED (regno
) == 0)
2392 if (!deps
->readonly
&& ref
== USE
&& !DEBUG_INSN_P (insn
))
2393 deps
->sched_before_next_call
2394 = alloc_INSN_LIST (insn
, deps
->sched_before_next_call
);
2396 add_dependence_list (insn
, deps
->last_function_call
, 1,
2397 REG_DEP_ANTI
, false);
2402 /* Analyze a single SET, CLOBBER, PRE_DEC, POST_DEC, PRE_INC or POST_INC
2403 rtx, X, creating all dependencies generated by the write to the
2404 destination of X, and reads of everything mentioned. */
2407 sched_analyze_1 (struct deps_desc
*deps
, rtx x
, rtx_insn
*insn
)
2409 rtx dest
= XEXP (x
, 0);
2410 enum rtx_code code
= GET_CODE (x
);
2411 bool cslr_p
= can_start_lhs_rhs_p
;
2413 can_start_lhs_rhs_p
= false;
2419 if (cslr_p
&& sched_deps_info
->start_lhs
)
2420 sched_deps_info
->start_lhs (dest
);
2422 if (GET_CODE (dest
) == PARALLEL
)
2426 for (i
= XVECLEN (dest
, 0) - 1; i
>= 0; i
--)
2427 if (XEXP (XVECEXP (dest
, 0, i
), 0) != 0)
2428 sched_analyze_1 (deps
,
2429 gen_rtx_CLOBBER (VOIDmode
,
2430 XEXP (XVECEXP (dest
, 0, i
), 0)),
2433 if (cslr_p
&& sched_deps_info
->finish_lhs
)
2434 sched_deps_info
->finish_lhs ();
2438 can_start_lhs_rhs_p
= cslr_p
;
2440 sched_analyze_2 (deps
, SET_SRC (x
), insn
);
2442 can_start_lhs_rhs_p
= false;
2448 while (GET_CODE (dest
) == STRICT_LOW_PART
|| GET_CODE (dest
) == SUBREG
2449 || GET_CODE (dest
) == ZERO_EXTRACT
)
2451 if (GET_CODE (dest
) == STRICT_LOW_PART
2452 || GET_CODE (dest
) == ZERO_EXTRACT
2453 || df_read_modify_subreg_p (dest
))
2455 /* These both read and modify the result. We must handle
2456 them as writes to get proper dependencies for following
2457 instructions. We must handle them as reads to get proper
2458 dependencies from this to previous instructions.
2459 Thus we need to call sched_analyze_2. */
2461 sched_analyze_2 (deps
, XEXP (dest
, 0), insn
);
2463 if (GET_CODE (dest
) == ZERO_EXTRACT
)
2465 /* The second and third arguments are values read by this insn. */
2466 sched_analyze_2 (deps
, XEXP (dest
, 1), insn
);
2467 sched_analyze_2 (deps
, XEXP (dest
, 2), insn
);
2469 dest
= XEXP (dest
, 0);
2474 int regno
= REGNO (dest
);
2475 machine_mode mode
= GET_MODE (dest
);
2477 sched_analyze_reg (deps
, regno
, mode
, code
, insn
);
2480 /* Treat all writes to a stack register as modifying the TOS. */
2481 if (regno
>= FIRST_STACK_REG
&& regno
<= LAST_STACK_REG
)
2483 /* Avoid analyzing the same register twice. */
2484 if (regno
!= FIRST_STACK_REG
)
2485 sched_analyze_reg (deps
, FIRST_STACK_REG
, mode
, code
, insn
);
2487 add_to_hard_reg_set (&implicit_reg_pending_uses
, mode
,
2492 else if (MEM_P (dest
))
2494 /* Writing memory. */
2497 if (sched_deps_info
->use_cselib
)
2499 machine_mode address_mode
= get_address_mode (dest
);
2501 t
= shallow_copy_rtx (dest
);
2502 cselib_lookup_from_insn (XEXP (t
, 0), address_mode
, 1,
2503 GET_MODE (t
), insn
);
2505 = cselib_subst_to_values_from_insn (XEXP (t
, 0), GET_MODE (t
),
2510 /* Pending lists can't get larger with a readonly context. */
2512 && ((deps
->pending_read_list_length
+ deps
->pending_write_list_length
)
2513 >= MAX_PENDING_LIST_LENGTH
))
2515 /* Flush all pending reads and writes to prevent the pending lists
2516 from getting any larger. Insn scheduling runs too slowly when
2517 these lists get long. When compiling GCC with itself,
2518 this flush occurs 8 times for sparc, and 10 times for m88k using
2519 the default value of 32. */
2520 flush_pending_lists (deps
, insn
, false, true);
2524 rtx_insn_list
*pending
;
2525 rtx_expr_list
*pending_mem
;
2527 pending
= deps
->pending_read_insns
;
2528 pending_mem
= deps
->pending_read_mems
;
2531 if (anti_dependence (pending_mem
->element (), t
)
2532 && ! sched_insns_conditions_mutex_p (insn
, pending
->insn ()))
2533 note_mem_dep (t
, pending_mem
->element (), pending
->insn (),
2536 pending
= pending
->next ();
2537 pending_mem
= pending_mem
->next ();
2540 pending
= deps
->pending_write_insns
;
2541 pending_mem
= deps
->pending_write_mems
;
2544 if (output_dependence (pending_mem
->element (), t
)
2545 && ! sched_insns_conditions_mutex_p (insn
, pending
->insn ()))
2546 note_mem_dep (t
, pending_mem
->element (),
2550 pending
= pending
->next ();
2551 pending_mem
= pending_mem
-> next ();
2554 add_dependence_list (insn
, deps
->last_pending_memory_flush
, 1,
2555 REG_DEP_ANTI
, true);
2556 add_dependence_list (insn
, deps
->pending_jump_insns
, 1,
2557 REG_DEP_CONTROL
, true);
2559 if (!deps
->readonly
)
2560 add_insn_mem_dependence (deps
, false, insn
, dest
);
2562 sched_analyze_2 (deps
, XEXP (dest
, 0), insn
);
2565 if (cslr_p
&& sched_deps_info
->finish_lhs
)
2566 sched_deps_info
->finish_lhs ();
2568 /* Analyze reads. */
2569 if (GET_CODE (x
) == SET
)
2571 can_start_lhs_rhs_p
= cslr_p
;
2573 sched_analyze_2 (deps
, SET_SRC (x
), insn
);
2575 can_start_lhs_rhs_p
= false;
2579 /* Analyze the uses of memory and registers in rtx X in INSN. */
2581 sched_analyze_2 (struct deps_desc
*deps
, rtx x
, rtx_insn
*insn
)
2587 bool cslr_p
= can_start_lhs_rhs_p
;
2589 can_start_lhs_rhs_p
= false;
2595 if (cslr_p
&& sched_deps_info
->start_rhs
)
2596 sched_deps_info
->start_rhs (x
);
2598 code
= GET_CODE (x
);
2606 /* Ignore constants. */
2607 if (cslr_p
&& sched_deps_info
->finish_rhs
)
2608 sched_deps_info
->finish_rhs ();
2614 /* User of CC0 depends on immediately preceding insn. */
2615 SCHED_GROUP_P (insn
) = 1;
2616 /* Don't move CC0 setter to another block (it can set up the
2617 same flag for previous CC0 users which is safe). */
2618 CANT_MOVE (prev_nonnote_insn (insn
)) = 1;
2620 if (cslr_p
&& sched_deps_info
->finish_rhs
)
2621 sched_deps_info
->finish_rhs ();
2628 int regno
= REGNO (x
);
2629 machine_mode mode
= GET_MODE (x
);
2631 sched_analyze_reg (deps
, regno
, mode
, USE
, insn
);
2634 /* Treat all reads of a stack register as modifying the TOS. */
2635 if (regno
>= FIRST_STACK_REG
&& regno
<= LAST_STACK_REG
)
2637 /* Avoid analyzing the same register twice. */
2638 if (regno
!= FIRST_STACK_REG
)
2639 sched_analyze_reg (deps
, FIRST_STACK_REG
, mode
, USE
, insn
);
2640 sched_analyze_reg (deps
, FIRST_STACK_REG
, mode
, SET
, insn
);
2644 if (cslr_p
&& sched_deps_info
->finish_rhs
)
2645 sched_deps_info
->finish_rhs ();
2652 /* Reading memory. */
2654 rtx_insn_list
*pending
;
2655 rtx_expr_list
*pending_mem
;
2658 if (sched_deps_info
->use_cselib
)
2660 machine_mode address_mode
= get_address_mode (t
);
2662 t
= shallow_copy_rtx (t
);
2663 cselib_lookup_from_insn (XEXP (t
, 0), address_mode
, 1,
2664 GET_MODE (t
), insn
);
2666 = cselib_subst_to_values_from_insn (XEXP (t
, 0), GET_MODE (t
),
2670 if (!DEBUG_INSN_P (insn
))
2673 pending
= deps
->pending_read_insns
;
2674 pending_mem
= deps
->pending_read_mems
;
2677 if (read_dependence (pending_mem
->element (), t
)
2678 && ! sched_insns_conditions_mutex_p (insn
,
2680 note_mem_dep (t
, pending_mem
->element (),
2684 pending
= pending
->next ();
2685 pending_mem
= pending_mem
->next ();
2688 pending
= deps
->pending_write_insns
;
2689 pending_mem
= deps
->pending_write_mems
;
2692 if (true_dependence (pending_mem
->element (), VOIDmode
, t
)
2693 && ! sched_insns_conditions_mutex_p (insn
,
2695 note_mem_dep (t
, pending_mem
->element (),
2697 sched_deps_info
->generate_spec_deps
2698 ? BEGIN_DATA
| DEP_TRUE
: DEP_TRUE
);
2700 pending
= pending
->next ();
2701 pending_mem
= pending_mem
->next ();
2704 for (u
= deps
->last_pending_memory_flush
; u
; u
= XEXP (u
, 1))
2705 add_dependence (insn
, as_a
<rtx_insn
*> (XEXP (u
, 0)),
2708 for (u
= deps
->pending_jump_insns
; u
; u
= XEXP (u
, 1))
2709 if (deps_may_trap_p (x
))
2711 if ((sched_deps_info
->generate_spec_deps
)
2712 && sel_sched_p () && (spec_info
->mask
& BEGIN_CONTROL
))
2714 ds_t ds
= set_dep_weak (DEP_ANTI
, BEGIN_CONTROL
,
2717 note_dep (as_a
<rtx_insn
*> (XEXP (u
, 0)), ds
);
2720 add_dependence (insn
, as_a
<rtx_insn
*> (XEXP (u
, 0)),
2725 /* Always add these dependencies to pending_reads, since
2726 this insn may be followed by a write. */
2727 if (!deps
->readonly
)
2729 if ((deps
->pending_read_list_length
2730 + deps
->pending_write_list_length
)
2731 >= MAX_PENDING_LIST_LENGTH
2732 && !DEBUG_INSN_P (insn
))
2733 flush_pending_lists (deps
, insn
, true, true);
2734 add_insn_mem_dependence (deps
, true, insn
, x
);
2737 sched_analyze_2 (deps
, XEXP (x
, 0), insn
);
2739 if (cslr_p
&& sched_deps_info
->finish_rhs
)
2740 sched_deps_info
->finish_rhs ();
2745 /* Force pending stores to memory in case a trap handler needs them. */
2747 flush_pending_lists (deps
, insn
, true, false);
2751 if (PREFETCH_SCHEDULE_BARRIER_P (x
))
2752 reg_pending_barrier
= TRUE_BARRIER
;
2753 /* Prefetch insn contains addresses only. So if the prefetch
2754 address has no registers, there will be no dependencies on
2755 the prefetch insn. This is wrong with result code
2756 correctness point of view as such prefetch can be moved below
2757 a jump insn which usually generates MOVE_BARRIER preventing
2758 to move insns containing registers or memories through the
2759 barrier. It is also wrong with generated code performance
2760 point of view as prefetch withouth dependecies will have a
2761 tendency to be issued later instead of earlier. It is hard
2762 to generate accurate dependencies for prefetch insns as
2763 prefetch has only the start address but it is better to have
2764 something than nothing. */
2765 if (!deps
->readonly
)
2767 rtx x
= gen_rtx_MEM (Pmode
, XEXP (PATTERN (insn
), 0));
2768 if (sched_deps_info
->use_cselib
)
2769 cselib_lookup_from_insn (x
, Pmode
, true, VOIDmode
, insn
);
2770 add_insn_mem_dependence (deps
, true, insn
, x
);
2774 case UNSPEC_VOLATILE
:
2775 flush_pending_lists (deps
, insn
, true, true);
2781 /* Traditional and volatile asm instructions must be considered to use
2782 and clobber all hard registers, all pseudo-registers and all of
2783 memory. So must TRAP_IF and UNSPEC_VOLATILE operations.
2785 Consider for instance a volatile asm that changes the fpu rounding
2786 mode. An insn should not be moved across this even if it only uses
2787 pseudo-regs because it might give an incorrectly rounded result. */
2788 if ((code
!= ASM_OPERANDS
|| MEM_VOLATILE_P (x
))
2789 && !DEBUG_INSN_P (insn
))
2790 reg_pending_barrier
= TRUE_BARRIER
;
2792 /* For all ASM_OPERANDS, we must traverse the vector of input operands.
2793 We can not just fall through here since then we would be confused
2794 by the ASM_INPUT rtx inside ASM_OPERANDS, which do not indicate
2795 traditional asms unlike their normal usage. */
2797 if (code
== ASM_OPERANDS
)
2799 for (j
= 0; j
< ASM_OPERANDS_INPUT_LENGTH (x
); j
++)
2800 sched_analyze_2 (deps
, ASM_OPERANDS_INPUT (x
, j
), insn
);
2802 if (cslr_p
&& sched_deps_info
->finish_rhs
)
2803 sched_deps_info
->finish_rhs ();
2814 /* These both read and modify the result. We must handle them as writes
2815 to get proper dependencies for following instructions. We must handle
2816 them as reads to get proper dependencies from this to previous
2817 instructions. Thus we need to pass them to both sched_analyze_1
2818 and sched_analyze_2. We must call sched_analyze_2 first in order
2819 to get the proper antecedent for the read. */
2820 sched_analyze_2 (deps
, XEXP (x
, 0), insn
);
2821 sched_analyze_1 (deps
, x
, insn
);
2823 if (cslr_p
&& sched_deps_info
->finish_rhs
)
2824 sched_deps_info
->finish_rhs ();
2830 /* op0 = op0 + op1 */
2831 sched_analyze_2 (deps
, XEXP (x
, 0), insn
);
2832 sched_analyze_2 (deps
, XEXP (x
, 1), insn
);
2833 sched_analyze_1 (deps
, x
, insn
);
2835 if (cslr_p
&& sched_deps_info
->finish_rhs
)
2836 sched_deps_info
->finish_rhs ();
2844 /* Other cases: walk the insn. */
2845 fmt
= GET_RTX_FORMAT (code
);
2846 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2849 sched_analyze_2 (deps
, XEXP (x
, i
), insn
);
2850 else if (fmt
[i
] == 'E')
2851 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2852 sched_analyze_2 (deps
, XVECEXP (x
, i
, j
), insn
);
2855 if (cslr_p
&& sched_deps_info
->finish_rhs
)
2856 sched_deps_info
->finish_rhs ();
2859 /* Try to group two fuseable insns together to prevent scheduler
2860 from scheduling them apart. */
2863 sched_macro_fuse_insns (rtx_insn
*insn
)
2867 if (any_condjump_p (insn
))
2869 unsigned int condreg1
, condreg2
;
2871 targetm
.fixed_condition_code_regs (&condreg1
, &condreg2
);
2872 cc_reg_1
= gen_rtx_REG (CCmode
, condreg1
);
2873 prev
= prev_nonnote_nondebug_insn (insn
);
2874 if (!reg_referenced_p (cc_reg_1
, PATTERN (insn
))
2876 || !modified_in_p (cc_reg_1
, prev
))
2881 rtx insn_set
= single_set (insn
);
2883 prev
= prev_nonnote_nondebug_insn (insn
);
2886 || !single_set (prev
))
2891 if (targetm
.sched
.macro_fusion_pair_p (prev
, insn
))
2892 SCHED_GROUP_P (insn
) = 1;
2896 /* Analyze an INSN with pattern X to find all dependencies. */
2898 sched_analyze_insn (struct deps_desc
*deps
, rtx x
, rtx_insn
*insn
)
2900 RTX_CODE code
= GET_CODE (x
);
2903 reg_set_iterator rsi
;
2905 if (! reload_completed
)
2909 extract_insn (insn
);
2910 preprocess_constraints (insn
);
2911 alternative_mask prefrred
= get_preferred_alternatives (insn
);
2912 ira_implicitly_set_insn_hard_regs (&temp
, prefrred
);
2913 AND_COMPL_HARD_REG_SET (temp
, ira_no_alloc_regs
);
2914 IOR_HARD_REG_SET (implicit_reg_pending_clobbers
, temp
);
2917 can_start_lhs_rhs_p
= (NONJUMP_INSN_P (insn
)
2920 /* Group compare and branch insns for macro-fusion. */
2921 if (targetm
.sched
.macro_fusion_p
2922 && targetm
.sched
.macro_fusion_p ())
2923 sched_macro_fuse_insns (insn
);
2926 /* Avoid moving trapping instructions across function calls that might
2927 not always return. */
2928 add_dependence_list (insn
, deps
->last_function_call_may_noreturn
,
2929 1, REG_DEP_ANTI
, true);
2931 /* We must avoid creating a situation in which two successors of the
2932 current block have different unwind info after scheduling. If at any
2933 point the two paths re-join this leads to incorrect unwind info. */
2934 /* ??? There are certain situations involving a forced frame pointer in
2935 which, with extra effort, we could fix up the unwind info at a later
2936 CFG join. However, it seems better to notice these cases earlier
2937 during prologue generation and avoid marking the frame pointer setup
2938 as frame-related at all. */
2939 if (RTX_FRAME_RELATED_P (insn
))
2941 /* Make sure prologue insn is scheduled before next jump. */
2942 deps
->sched_before_next_jump
2943 = alloc_INSN_LIST (insn
, deps
->sched_before_next_jump
);
2945 /* Make sure epilogue insn is scheduled after preceding jumps. */
2946 add_dependence_list (insn
, deps
->pending_jump_insns
, 1, REG_DEP_ANTI
,
2950 if (code
== COND_EXEC
)
2952 sched_analyze_2 (deps
, COND_EXEC_TEST (x
), insn
);
2954 /* ??? Should be recording conditions so we reduce the number of
2955 false dependencies. */
2956 x
= COND_EXEC_CODE (x
);
2957 code
= GET_CODE (x
);
2959 if (code
== SET
|| code
== CLOBBER
)
2961 sched_analyze_1 (deps
, x
, insn
);
2963 /* Bare clobber insns are used for letting life analysis, reg-stack
2964 and others know that a value is dead. Depend on the last call
2965 instruction so that reg-stack won't get confused. */
2966 if (code
== CLOBBER
)
2967 add_dependence_list (insn
, deps
->last_function_call
, 1,
2968 REG_DEP_OUTPUT
, true);
2970 else if (code
== PARALLEL
)
2972 for (i
= XVECLEN (x
, 0); i
--;)
2974 rtx sub
= XVECEXP (x
, 0, i
);
2975 code
= GET_CODE (sub
);
2977 if (code
== COND_EXEC
)
2979 sched_analyze_2 (deps
, COND_EXEC_TEST (sub
), insn
);
2980 sub
= COND_EXEC_CODE (sub
);
2981 code
= GET_CODE (sub
);
2983 if (code
== SET
|| code
== CLOBBER
)
2984 sched_analyze_1 (deps
, sub
, insn
);
2986 sched_analyze_2 (deps
, sub
, insn
);
2990 sched_analyze_2 (deps
, x
, insn
);
2992 /* Mark registers CLOBBERED or used by called function. */
2995 for (link
= CALL_INSN_FUNCTION_USAGE (insn
); link
; link
= XEXP (link
, 1))
2997 if (GET_CODE (XEXP (link
, 0)) == CLOBBER
)
2998 sched_analyze_1 (deps
, XEXP (link
, 0), insn
);
2999 else if (GET_CODE (XEXP (link
, 0)) != SET
)
3000 sched_analyze_2 (deps
, XEXP (link
, 0), insn
);
3002 /* Don't schedule anything after a tail call, tail call needs
3003 to use at least all call-saved registers. */
3004 if (SIBLING_CALL_P (insn
))
3005 reg_pending_barrier
= TRUE_BARRIER
;
3006 else if (find_reg_note (insn
, REG_SETJMP
, NULL
))
3007 reg_pending_barrier
= MOVE_BARRIER
;
3013 next
= next_nonnote_nondebug_insn (insn
);
3014 if (next
&& BARRIER_P (next
))
3015 reg_pending_barrier
= MOVE_BARRIER
;
3018 rtx_insn_list
*pending
;
3019 rtx_expr_list
*pending_mem
;
3021 if (sched_deps_info
->compute_jump_reg_dependencies
)
3023 (*sched_deps_info
->compute_jump_reg_dependencies
)
3024 (insn
, reg_pending_control_uses
);
3026 /* Make latency of jump equal to 0 by using anti-dependence. */
3027 EXECUTE_IF_SET_IN_REG_SET (reg_pending_control_uses
, 0, i
, rsi
)
3029 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
3030 add_dependence_list (insn
, reg_last
->sets
, 0, REG_DEP_ANTI
,
3032 add_dependence_list (insn
, reg_last
->implicit_sets
,
3033 0, REG_DEP_ANTI
, false);
3034 add_dependence_list (insn
, reg_last
->clobbers
, 0,
3035 REG_DEP_ANTI
, false);
3039 /* All memory writes and volatile reads must happen before the
3040 jump. Non-volatile reads must happen before the jump iff
3041 the result is needed by the above register used mask. */
3043 pending
= deps
->pending_write_insns
;
3044 pending_mem
= deps
->pending_write_mems
;
3047 if (! sched_insns_conditions_mutex_p (insn
, pending
->insn ()))
3048 add_dependence (insn
, pending
->insn (),
3050 pending
= pending
->next ();
3051 pending_mem
= pending_mem
->next ();
3054 pending
= deps
->pending_read_insns
;
3055 pending_mem
= deps
->pending_read_mems
;
3058 if (MEM_VOLATILE_P (pending_mem
->element ())
3059 && ! sched_insns_conditions_mutex_p (insn
, pending
->insn ()))
3060 add_dependence (insn
, pending
->insn (),
3062 pending
= pending
->next ();
3063 pending_mem
= pending_mem
->next ();
3066 add_dependence_list (insn
, deps
->last_pending_memory_flush
, 1,
3067 REG_DEP_ANTI
, true);
3068 add_dependence_list (insn
, deps
->pending_jump_insns
, 1,
3069 REG_DEP_ANTI
, true);
3073 /* If this instruction can throw an exception, then moving it changes
3074 where block boundaries fall. This is mighty confusing elsewhere.
3075 Therefore, prevent such an instruction from being moved. Same for
3076 non-jump instructions that define block boundaries.
3077 ??? Unclear whether this is still necessary in EBB mode. If not,
3078 add_branch_dependences should be adjusted for RGN mode instead. */
3079 if (((CALL_P (insn
) || JUMP_P (insn
)) && can_throw_internal (insn
))
3080 || (NONJUMP_INSN_P (insn
) && control_flow_insn_p (insn
)))
3081 reg_pending_barrier
= MOVE_BARRIER
;
3083 if (sched_pressure
!= SCHED_PRESSURE_NONE
)
3085 setup_insn_reg_uses (deps
, insn
);
3086 init_insn_reg_pressure_info (insn
);
3089 /* Add register dependencies for insn. */
3090 if (DEBUG_INSN_P (insn
))
3092 rtx_insn
*prev
= deps
->last_debug_insn
;
3095 if (!deps
->readonly
)
3096 deps
->last_debug_insn
= insn
;
3099 add_dependence (insn
, prev
, REG_DEP_ANTI
);
3101 add_dependence_list (insn
, deps
->last_function_call
, 1,
3102 REG_DEP_ANTI
, false);
3104 if (!sel_sched_p ())
3105 for (u
= deps
->last_pending_memory_flush
; u
; u
= XEXP (u
, 1))
3106 add_dependence (insn
, as_a
<rtx_insn
*> (XEXP (u
, 0)), REG_DEP_ANTI
);
3108 EXECUTE_IF_SET_IN_REG_SET (reg_pending_uses
, 0, i
, rsi
)
3110 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
3111 add_dependence_list (insn
, reg_last
->sets
, 1, REG_DEP_ANTI
, false);
3112 /* There's no point in making REG_DEP_CONTROL dependencies for
3114 add_dependence_list (insn
, reg_last
->clobbers
, 1, REG_DEP_ANTI
,
3117 if (!deps
->readonly
)
3118 reg_last
->uses
= alloc_INSN_LIST (insn
, reg_last
->uses
);
3120 CLEAR_REG_SET (reg_pending_uses
);
3122 /* Quite often, a debug insn will refer to stuff in the
3123 previous instruction, but the reason we want this
3124 dependency here is to make sure the scheduler doesn't
3125 gratuitously move a debug insn ahead. This could dirty
3126 DF flags and cause additional analysis that wouldn't have
3127 occurred in compilation without debug insns, and such
3128 additional analysis can modify the generated code. */
3129 prev
= PREV_INSN (insn
);
3131 if (prev
&& NONDEBUG_INSN_P (prev
))
3132 add_dependence (insn
, prev
, REG_DEP_ANTI
);
3136 regset_head set_or_clobbered
;
3138 EXECUTE_IF_SET_IN_REG_SET (reg_pending_uses
, 0, i
, rsi
)
3140 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
3141 add_dependence_list (insn
, reg_last
->sets
, 0, REG_DEP_TRUE
, false);
3142 add_dependence_list (insn
, reg_last
->implicit_sets
, 0, REG_DEP_ANTI
,
3144 add_dependence_list (insn
, reg_last
->clobbers
, 0, REG_DEP_TRUE
,
3147 if (!deps
->readonly
)
3149 reg_last
->uses
= alloc_INSN_LIST (insn
, reg_last
->uses
);
3150 reg_last
->uses_length
++;
3154 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3155 if (TEST_HARD_REG_BIT (implicit_reg_pending_uses
, i
))
3157 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
3158 add_dependence_list (insn
, reg_last
->sets
, 0, REG_DEP_TRUE
, false);
3159 add_dependence_list (insn
, reg_last
->implicit_sets
, 0,
3160 REG_DEP_ANTI
, false);
3161 add_dependence_list (insn
, reg_last
->clobbers
, 0, REG_DEP_TRUE
,
3164 if (!deps
->readonly
)
3166 reg_last
->uses
= alloc_INSN_LIST (insn
, reg_last
->uses
);
3167 reg_last
->uses_length
++;
3171 if (targetm
.sched
.exposed_pipeline
)
3173 INIT_REG_SET (&set_or_clobbered
);
3174 bitmap_ior (&set_or_clobbered
, reg_pending_clobbers
,
3176 EXECUTE_IF_SET_IN_REG_SET (&set_or_clobbered
, 0, i
, rsi
)
3178 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
3180 for (list
= reg_last
->uses
; list
; list
= XEXP (list
, 1))
3182 rtx other
= XEXP (list
, 0);
3183 if (INSN_CACHED_COND (other
) != const_true_rtx
3184 && refers_to_regno_p (i
, INSN_CACHED_COND (other
)))
3185 INSN_CACHED_COND (other
) = const_true_rtx
;
3190 /* If the current insn is conditional, we can't free any
3192 if (sched_has_condition_p (insn
))
3194 EXECUTE_IF_SET_IN_REG_SET (reg_pending_clobbers
, 0, i
, rsi
)
3196 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
3197 add_dependence_list (insn
, reg_last
->sets
, 0, REG_DEP_OUTPUT
,
3199 add_dependence_list (insn
, reg_last
->implicit_sets
, 0,
3200 REG_DEP_ANTI
, false);
3201 add_dependence_list (insn
, reg_last
->uses
, 0, REG_DEP_ANTI
,
3203 add_dependence_list (insn
, reg_last
->control_uses
, 0,
3204 REG_DEP_CONTROL
, false);
3206 if (!deps
->readonly
)
3209 = alloc_INSN_LIST (insn
, reg_last
->clobbers
);
3210 reg_last
->clobbers_length
++;
3213 EXECUTE_IF_SET_IN_REG_SET (reg_pending_sets
, 0, i
, rsi
)
3215 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
3216 add_dependence_list (insn
, reg_last
->sets
, 0, REG_DEP_OUTPUT
,
3218 add_dependence_list (insn
, reg_last
->implicit_sets
, 0,
3219 REG_DEP_ANTI
, false);
3220 add_dependence_list (insn
, reg_last
->clobbers
, 0, REG_DEP_OUTPUT
,
3222 add_dependence_list (insn
, reg_last
->uses
, 0, REG_DEP_ANTI
,
3224 add_dependence_list (insn
, reg_last
->control_uses
, 0,
3225 REG_DEP_CONTROL
, false);
3227 if (!deps
->readonly
)
3228 reg_last
->sets
= alloc_INSN_LIST (insn
, reg_last
->sets
);
3233 EXECUTE_IF_SET_IN_REG_SET (reg_pending_clobbers
, 0, i
, rsi
)
3235 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
3236 if (reg_last
->uses_length
>= MAX_PENDING_LIST_LENGTH
3237 || reg_last
->clobbers_length
>= MAX_PENDING_LIST_LENGTH
)
3239 add_dependence_list_and_free (deps
, insn
, ®_last
->sets
, 0,
3240 REG_DEP_OUTPUT
, false);
3241 add_dependence_list_and_free (deps
, insn
,
3242 ®_last
->implicit_sets
, 0,
3243 REG_DEP_ANTI
, false);
3244 add_dependence_list_and_free (deps
, insn
, ®_last
->uses
, 0,
3245 REG_DEP_ANTI
, false);
3246 add_dependence_list_and_free (deps
, insn
,
3247 ®_last
->control_uses
, 0,
3248 REG_DEP_ANTI
, false);
3249 add_dependence_list_and_free (deps
, insn
,
3250 ®_last
->clobbers
, 0,
3251 REG_DEP_OUTPUT
, false);
3253 if (!deps
->readonly
)
3255 reg_last
->sets
= alloc_INSN_LIST (insn
, reg_last
->sets
);
3256 reg_last
->clobbers_length
= 0;
3257 reg_last
->uses_length
= 0;
3262 add_dependence_list (insn
, reg_last
->sets
, 0, REG_DEP_OUTPUT
,
3264 add_dependence_list (insn
, reg_last
->implicit_sets
, 0,
3265 REG_DEP_ANTI
, false);
3266 add_dependence_list (insn
, reg_last
->uses
, 0, REG_DEP_ANTI
,
3268 add_dependence_list (insn
, reg_last
->control_uses
, 0,
3269 REG_DEP_CONTROL
, false);
3272 if (!deps
->readonly
)
3274 reg_last
->clobbers_length
++;
3276 = alloc_INSN_LIST (insn
, reg_last
->clobbers
);
3279 EXECUTE_IF_SET_IN_REG_SET (reg_pending_sets
, 0, i
, rsi
)
3281 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
3283 add_dependence_list_and_free (deps
, insn
, ®_last
->sets
, 0,
3284 REG_DEP_OUTPUT
, false);
3285 add_dependence_list_and_free (deps
, insn
,
3286 ®_last
->implicit_sets
,
3287 0, REG_DEP_ANTI
, false);
3288 add_dependence_list_and_free (deps
, insn
, ®_last
->clobbers
, 0,
3289 REG_DEP_OUTPUT
, false);
3290 add_dependence_list_and_free (deps
, insn
, ®_last
->uses
, 0,
3291 REG_DEP_ANTI
, false);
3292 add_dependence_list (insn
, reg_last
->control_uses
, 0,
3293 REG_DEP_CONTROL
, false);
3295 if (!deps
->readonly
)
3297 reg_last
->sets
= alloc_INSN_LIST (insn
, reg_last
->sets
);
3298 reg_last
->uses_length
= 0;
3299 reg_last
->clobbers_length
= 0;
3303 if (!deps
->readonly
)
3305 EXECUTE_IF_SET_IN_REG_SET (reg_pending_control_uses
, 0, i
, rsi
)
3307 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
3308 reg_last
->control_uses
3309 = alloc_INSN_LIST (insn
, reg_last
->control_uses
);
3314 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3315 if (TEST_HARD_REG_BIT (implicit_reg_pending_clobbers
, i
))
3317 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
3318 add_dependence_list (insn
, reg_last
->sets
, 0, REG_DEP_ANTI
, false);
3319 add_dependence_list (insn
, reg_last
->clobbers
, 0, REG_DEP_ANTI
, false);
3320 add_dependence_list (insn
, reg_last
->uses
, 0, REG_DEP_ANTI
, false);
3321 add_dependence_list (insn
, reg_last
->control_uses
, 0, REG_DEP_ANTI
,
3324 if (!deps
->readonly
)
3325 reg_last
->implicit_sets
3326 = alloc_INSN_LIST (insn
, reg_last
->implicit_sets
);
3329 if (!deps
->readonly
)
3331 IOR_REG_SET (&deps
->reg_last_in_use
, reg_pending_uses
);
3332 IOR_REG_SET (&deps
->reg_last_in_use
, reg_pending_clobbers
);
3333 IOR_REG_SET (&deps
->reg_last_in_use
, reg_pending_sets
);
3334 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3335 if (TEST_HARD_REG_BIT (implicit_reg_pending_uses
, i
)
3336 || TEST_HARD_REG_BIT (implicit_reg_pending_clobbers
, i
))
3337 SET_REGNO_REG_SET (&deps
->reg_last_in_use
, i
);
3339 /* Set up the pending barrier found. */
3340 deps
->last_reg_pending_barrier
= reg_pending_barrier
;
3343 CLEAR_REG_SET (reg_pending_uses
);
3344 CLEAR_REG_SET (reg_pending_clobbers
);
3345 CLEAR_REG_SET (reg_pending_sets
);
3346 CLEAR_REG_SET (reg_pending_control_uses
);
3347 CLEAR_HARD_REG_SET (implicit_reg_pending_clobbers
);
3348 CLEAR_HARD_REG_SET (implicit_reg_pending_uses
);
3350 /* Add dependencies if a scheduling barrier was found. */
3351 if (reg_pending_barrier
)
3353 /* In the case of barrier the most added dependencies are not
3354 real, so we use anti-dependence here. */
3355 if (sched_has_condition_p (insn
))
3357 EXECUTE_IF_SET_IN_REG_SET (&deps
->reg_last_in_use
, 0, i
, rsi
)
3359 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
3360 add_dependence_list (insn
, reg_last
->uses
, 0, REG_DEP_ANTI
,
3362 add_dependence_list (insn
, reg_last
->sets
, 0,
3363 reg_pending_barrier
== TRUE_BARRIER
3364 ? REG_DEP_TRUE
: REG_DEP_ANTI
, true);
3365 add_dependence_list (insn
, reg_last
->implicit_sets
, 0,
3366 REG_DEP_ANTI
, true);
3367 add_dependence_list (insn
, reg_last
->clobbers
, 0,
3368 reg_pending_barrier
== TRUE_BARRIER
3369 ? REG_DEP_TRUE
: REG_DEP_ANTI
, true);
3374 EXECUTE_IF_SET_IN_REG_SET (&deps
->reg_last_in_use
, 0, i
, rsi
)
3376 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
3377 add_dependence_list_and_free (deps
, insn
, ®_last
->uses
, 0,
3378 REG_DEP_ANTI
, true);
3379 add_dependence_list_and_free (deps
, insn
,
3380 ®_last
->control_uses
, 0,
3381 REG_DEP_CONTROL
, true);
3382 add_dependence_list_and_free (deps
, insn
, ®_last
->sets
, 0,
3383 reg_pending_barrier
== TRUE_BARRIER
3384 ? REG_DEP_TRUE
: REG_DEP_ANTI
,
3386 add_dependence_list_and_free (deps
, insn
,
3387 ®_last
->implicit_sets
, 0,
3388 REG_DEP_ANTI
, true);
3389 add_dependence_list_and_free (deps
, insn
, ®_last
->clobbers
, 0,
3390 reg_pending_barrier
== TRUE_BARRIER
3391 ? REG_DEP_TRUE
: REG_DEP_ANTI
,
3394 if (!deps
->readonly
)
3396 reg_last
->uses_length
= 0;
3397 reg_last
->clobbers_length
= 0;
3402 if (!deps
->readonly
)
3403 for (i
= 0; i
< (unsigned)deps
->max_reg
; i
++)
3405 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
3406 reg_last
->sets
= alloc_INSN_LIST (insn
, reg_last
->sets
);
3407 SET_REGNO_REG_SET (&deps
->reg_last_in_use
, i
);
3410 /* Don't flush pending lists on speculative checks for
3411 selective scheduling. */
3412 if (!sel_sched_p () || !sel_insn_is_speculation_check (insn
))
3413 flush_pending_lists (deps
, insn
, true, true);
3415 reg_pending_barrier
= NOT_A_BARRIER
;
3418 /* If a post-call group is still open, see if it should remain so.
3419 This insn must be a simple move of a hard reg to a pseudo or
3422 We must avoid moving these insns for correctness on targets
3423 with small register classes, and for special registers like
3424 PIC_OFFSET_TABLE_REGNUM. For simplicity, extend this to all
3425 hard regs for all targets. */
3427 if (deps
->in_post_call_group_p
)
3429 rtx tmp
, set
= single_set (insn
);
3430 int src_regno
, dest_regno
;
3434 if (DEBUG_INSN_P (insn
))
3435 /* We don't want to mark debug insns as part of the same
3436 sched group. We know they really aren't, but if we use
3437 debug insns to tell that a call group is over, we'll
3438 get different code if debug insns are not there and
3439 instructions that follow seem like they should be part
3442 Also, if we did, chain_to_prev_insn would move the
3443 deps of the debug insn to the call insn, modifying
3444 non-debug post-dependency counts of the debug insn
3445 dependencies and otherwise messing with the scheduling
3448 Instead, let such debug insns be scheduled freely, but
3449 keep the call group open in case there are insns that
3450 should be part of it afterwards. Since we grant debug
3451 insns higher priority than even sched group insns, it
3452 will all turn out all right. */
3453 goto debug_dont_end_call_group
;
3455 goto end_call_group
;
3458 tmp
= SET_DEST (set
);
3459 if (GET_CODE (tmp
) == SUBREG
)
3460 tmp
= SUBREG_REG (tmp
);
3462 dest_regno
= REGNO (tmp
);
3464 goto end_call_group
;
3466 tmp
= SET_SRC (set
);
3467 if (GET_CODE (tmp
) == SUBREG
)
3468 tmp
= SUBREG_REG (tmp
);
3469 if ((GET_CODE (tmp
) == PLUS
3470 || GET_CODE (tmp
) == MINUS
)
3471 && REG_P (XEXP (tmp
, 0))
3472 && REGNO (XEXP (tmp
, 0)) == STACK_POINTER_REGNUM
3473 && dest_regno
== STACK_POINTER_REGNUM
)
3474 src_regno
= STACK_POINTER_REGNUM
;
3475 else if (REG_P (tmp
))
3476 src_regno
= REGNO (tmp
);
3478 goto end_call_group
;
3480 if (src_regno
< FIRST_PSEUDO_REGISTER
3481 || dest_regno
< FIRST_PSEUDO_REGISTER
)
3484 && deps
->in_post_call_group_p
== post_call_initial
)
3485 deps
->in_post_call_group_p
= post_call
;
3487 if (!sel_sched_p () || sched_emulate_haifa_p
)
3489 SCHED_GROUP_P (insn
) = 1;
3490 CANT_MOVE (insn
) = 1;
3496 if (!deps
->readonly
)
3497 deps
->in_post_call_group_p
= not_post_call
;
3501 debug_dont_end_call_group
:
3502 if ((current_sched_info
->flags
& DO_SPECULATION
)
3503 && !sched_insn_is_legitimate_for_speculation_p (insn
, 0))
3504 /* INSN has an internal dependency (e.g. r14 = [r14]) and thus cannot
3508 sel_mark_hard_insn (insn
);
3511 sd_iterator_def sd_it
;
3514 for (sd_it
= sd_iterator_start (insn
, SD_LIST_SPEC_BACK
);
3515 sd_iterator_cond (&sd_it
, &dep
);)
3516 change_spec_dep_to_hard (sd_it
);
3520 /* We do not yet have code to adjust REG_ARGS_SIZE, therefore we must
3521 honor their original ordering. */
3522 if (find_reg_note (insn
, REG_ARGS_SIZE
, NULL
))
3524 if (deps
->last_args_size
)
3525 add_dependence (insn
, deps
->last_args_size
, REG_DEP_OUTPUT
);
3526 deps
->last_args_size
= insn
;
3530 /* Return TRUE if INSN might not always return normally (e.g. call exit,
3531 longjmp, loop forever, ...). */
3532 /* FIXME: Why can't this function just use flags_from_decl_or_type and
3533 test for ECF_NORETURN? */
3535 call_may_noreturn_p (rtx insn
)
3539 /* const or pure calls that aren't looping will always return. */
3540 if (RTL_CONST_OR_PURE_CALL_P (insn
)
3541 && !RTL_LOOPING_CONST_OR_PURE_CALL_P (insn
))
3544 call
= get_call_rtx_from (insn
);
3545 if (call
&& GET_CODE (XEXP (XEXP (call
, 0), 0)) == SYMBOL_REF
)
3547 rtx symbol
= XEXP (XEXP (call
, 0), 0);
3548 if (SYMBOL_REF_DECL (symbol
)
3549 && TREE_CODE (SYMBOL_REF_DECL (symbol
)) == FUNCTION_DECL
)
3551 if (DECL_BUILT_IN_CLASS (SYMBOL_REF_DECL (symbol
))
3553 switch (DECL_FUNCTION_CODE (SYMBOL_REF_DECL (symbol
)))
3556 case BUILT_IN_BCOPY
:
3557 case BUILT_IN_BZERO
:
3558 case BUILT_IN_INDEX
:
3559 case BUILT_IN_MEMCHR
:
3560 case BUILT_IN_MEMCMP
:
3561 case BUILT_IN_MEMCPY
:
3562 case BUILT_IN_MEMMOVE
:
3563 case BUILT_IN_MEMPCPY
:
3564 case BUILT_IN_MEMSET
:
3565 case BUILT_IN_RINDEX
:
3566 case BUILT_IN_STPCPY
:
3567 case BUILT_IN_STPNCPY
:
3568 case BUILT_IN_STRCAT
:
3569 case BUILT_IN_STRCHR
:
3570 case BUILT_IN_STRCMP
:
3571 case BUILT_IN_STRCPY
:
3572 case BUILT_IN_STRCSPN
:
3573 case BUILT_IN_STRLEN
:
3574 case BUILT_IN_STRNCAT
:
3575 case BUILT_IN_STRNCMP
:
3576 case BUILT_IN_STRNCPY
:
3577 case BUILT_IN_STRPBRK
:
3578 case BUILT_IN_STRRCHR
:
3579 case BUILT_IN_STRSPN
:
3580 case BUILT_IN_STRSTR
:
3581 /* Assume certain string/memory builtins always return. */
3589 /* For all other calls assume that they might not always return. */
3593 /* Return true if INSN should be made dependent on the previous instruction
3594 group, and if all INSN's dependencies should be moved to the first
3595 instruction of that group. */
3598 chain_to_prev_insn_p (rtx insn
)
3602 /* INSN forms a group with the previous instruction. */
3603 if (SCHED_GROUP_P (insn
))
3606 /* If the previous instruction clobbers a register R and this one sets
3607 part of R, the clobber was added specifically to help us track the
3608 liveness of R. There's no point scheduling the clobber and leaving
3609 INSN behind, especially if we move the clobber to another block. */
3610 prev
= prev_nonnote_nondebug_insn (insn
);
3613 && BLOCK_FOR_INSN (prev
) == BLOCK_FOR_INSN (insn
)
3614 && GET_CODE (PATTERN (prev
)) == CLOBBER
)
3616 x
= XEXP (PATTERN (prev
), 0);
3617 if (set_of (x
, insn
))
3624 /* Analyze INSN with DEPS as a context. */
3626 deps_analyze_insn (struct deps_desc
*deps
, rtx_insn
*insn
)
3628 if (sched_deps_info
->start_insn
)
3629 sched_deps_info
->start_insn (insn
);
3631 /* Record the condition for this insn. */
3632 if (NONDEBUG_INSN_P (insn
))
3635 sched_get_condition_with_rev (insn
, NULL
);
3636 t
= INSN_CACHED_COND (insn
);
3637 INSN_COND_DEPS (insn
) = NULL
;
3638 if (reload_completed
3639 && (current_sched_info
->flags
& DO_PREDICATION
)
3641 && REG_P (XEXP (t
, 0))
3642 && CONSTANT_P (XEXP (t
, 1)))
3646 rtx_insn_list
*cond_deps
= NULL
;
3649 nregs
= hard_regno_nregs
[regno
][GET_MODE (t
)];
3652 struct deps_reg
*reg_last
= &deps
->reg_last
[regno
+ nregs
];
3653 cond_deps
= concat_INSN_LIST (reg_last
->sets
, cond_deps
);
3654 cond_deps
= concat_INSN_LIST (reg_last
->clobbers
, cond_deps
);
3655 cond_deps
= concat_INSN_LIST (reg_last
->implicit_sets
, cond_deps
);
3657 INSN_COND_DEPS (insn
) = cond_deps
;
3663 /* Make each JUMP_INSN (but not a speculative check)
3664 a scheduling barrier for memory references. */
3667 && sel_insn_is_speculation_check (insn
)))
3669 /* Keep the list a reasonable size. */
3670 if (deps
->pending_flush_length
++ >= MAX_PENDING_LIST_LENGTH
)
3671 flush_pending_lists (deps
, insn
, true, true);
3673 deps
->pending_jump_insns
3674 = alloc_INSN_LIST (insn
, deps
->pending_jump_insns
);
3677 /* For each insn which shouldn't cross a jump, add a dependence. */
3678 add_dependence_list_and_free (deps
, insn
,
3679 &deps
->sched_before_next_jump
, 1,
3680 REG_DEP_ANTI
, true);
3682 sched_analyze_insn (deps
, PATTERN (insn
), insn
);
3684 else if (NONJUMP_INSN_P (insn
) || DEBUG_INSN_P (insn
))
3686 sched_analyze_insn (deps
, PATTERN (insn
), insn
);
3688 else if (CALL_P (insn
))
3692 CANT_MOVE (insn
) = 1;
3694 if (find_reg_note (insn
, REG_SETJMP
, NULL
))
3696 /* This is setjmp. Assume that all registers, not just
3697 hard registers, may be clobbered by this call. */
3698 reg_pending_barrier
= MOVE_BARRIER
;
3702 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3703 /* A call may read and modify global register variables. */
3706 SET_REGNO_REG_SET (reg_pending_sets
, i
);
3707 SET_HARD_REG_BIT (implicit_reg_pending_uses
, i
);
3709 /* Other call-clobbered hard regs may be clobbered.
3710 Since we only have a choice between 'might be clobbered'
3711 and 'definitely not clobbered', we must include all
3712 partly call-clobbered registers here. */
3713 else if (HARD_REGNO_CALL_PART_CLOBBERED (i
, reg_raw_mode
[i
])
3714 || TEST_HARD_REG_BIT (regs_invalidated_by_call
, i
))
3715 SET_REGNO_REG_SET (reg_pending_clobbers
, i
);
3716 /* We don't know what set of fixed registers might be used
3717 by the function, but it is certain that the stack pointer
3718 is among them, but be conservative. */
3719 else if (fixed_regs
[i
])
3720 SET_HARD_REG_BIT (implicit_reg_pending_uses
, i
);
3721 /* The frame pointer is normally not used by the function
3722 itself, but by the debugger. */
3723 /* ??? MIPS o32 is an exception. It uses the frame pointer
3724 in the macro expansion of jal but does not represent this
3725 fact in the call_insn rtl. */
3726 else if (i
== FRAME_POINTER_REGNUM
3727 || (i
== HARD_FRAME_POINTER_REGNUM
3728 && (! reload_completed
|| frame_pointer_needed
)))
3729 SET_HARD_REG_BIT (implicit_reg_pending_uses
, i
);
3732 /* For each insn which shouldn't cross a call, add a dependence
3733 between that insn and this call insn. */
3734 add_dependence_list_and_free (deps
, insn
,
3735 &deps
->sched_before_next_call
, 1,
3736 REG_DEP_ANTI
, true);
3738 sched_analyze_insn (deps
, PATTERN (insn
), insn
);
3740 /* If CALL would be in a sched group, then this will violate
3741 convention that sched group insns have dependencies only on the
3742 previous instruction.
3744 Of course one can say: "Hey! What about head of the sched group?"
3745 And I will answer: "Basic principles (one dep per insn) are always
3747 gcc_assert (!SCHED_GROUP_P (insn
));
3749 /* In the absence of interprocedural alias analysis, we must flush
3750 all pending reads and writes, and start new dependencies starting
3751 from here. But only flush writes for constant calls (which may
3752 be passed a pointer to something we haven't written yet). */
3753 flush_pending_lists (deps
, insn
, true, ! RTL_CONST_OR_PURE_CALL_P (insn
));
3755 if (!deps
->readonly
)
3757 /* Remember the last function call for limiting lifetimes. */
3758 free_INSN_LIST_list (&deps
->last_function_call
);
3759 deps
->last_function_call
= alloc_INSN_LIST (insn
, NULL_RTX
);
3761 if (call_may_noreturn_p (insn
))
3763 /* Remember the last function call that might not always return
3764 normally for limiting moves of trapping insns. */
3765 free_INSN_LIST_list (&deps
->last_function_call_may_noreturn
);
3766 deps
->last_function_call_may_noreturn
3767 = alloc_INSN_LIST (insn
, NULL_RTX
);
3770 /* Before reload, begin a post-call group, so as to keep the
3771 lifetimes of hard registers correct. */
3772 if (! reload_completed
)
3773 deps
->in_post_call_group_p
= post_call
;
3777 if (sched_deps_info
->use_cselib
)
3778 cselib_process_insn (insn
);
3780 if (sched_deps_info
->finish_insn
)
3781 sched_deps_info
->finish_insn ();
3783 /* Fixup the dependencies in the sched group. */
3784 if ((NONJUMP_INSN_P (insn
) || JUMP_P (insn
))
3785 && chain_to_prev_insn_p (insn
)
3787 chain_to_prev_insn (insn
);
3790 /* Initialize DEPS for the new block beginning with HEAD. */
3792 deps_start_bb (struct deps_desc
*deps
, rtx_insn
*head
)
3794 gcc_assert (!deps
->readonly
);
3796 /* Before reload, if the previous block ended in a call, show that
3797 we are inside a post-call group, so as to keep the lifetimes of
3798 hard registers correct. */
3799 if (! reload_completed
&& !LABEL_P (head
))
3801 rtx_insn
*insn
= prev_nonnote_nondebug_insn (head
);
3803 if (insn
&& CALL_P (insn
))
3804 deps
->in_post_call_group_p
= post_call_initial
;
3808 /* Analyze every insn between HEAD and TAIL inclusive, creating backward
3809 dependencies for each insn. */
3811 sched_analyze (struct deps_desc
*deps
, rtx_insn
*head
, rtx_insn
*tail
)
3815 if (sched_deps_info
->use_cselib
)
3816 cselib_init (CSELIB_RECORD_MEMORY
);
3818 deps_start_bb (deps
, head
);
3820 for (insn
= head
;; insn
= NEXT_INSN (insn
))
3825 /* And initialize deps_lists. */
3826 sd_init_insn (insn
);
3827 /* Clean up SCHED_GROUP_P which may be set by last
3829 if (SCHED_GROUP_P (insn
))
3830 SCHED_GROUP_P (insn
) = 0;
3833 deps_analyze_insn (deps
, insn
);
3837 if (sched_deps_info
->use_cselib
)
3845 /* Helper for sched_free_deps ().
3846 Delete INSN's (RESOLVED_P) backward dependencies. */
3848 delete_dep_nodes_in_back_deps (rtx insn
, bool resolved_p
)
3850 sd_iterator_def sd_it
;
3852 sd_list_types_def types
;
3855 types
= SD_LIST_RES_BACK
;
3857 types
= SD_LIST_BACK
;
3859 for (sd_it
= sd_iterator_start (insn
, types
);
3860 sd_iterator_cond (&sd_it
, &dep
);)
3862 dep_link_t link
= *sd_it
.linkp
;
3863 dep_node_t node
= DEP_LINK_NODE (link
);
3864 deps_list_t back_list
;
3865 deps_list_t forw_list
;
3867 get_back_and_forw_lists (dep
, resolved_p
, &back_list
, &forw_list
);
3868 remove_from_deps_list (link
, back_list
);
3869 delete_dep_node (node
);
3873 /* Delete (RESOLVED_P) dependencies between HEAD and TAIL together with
3876 sched_free_deps (rtx_insn
*head
, rtx_insn
*tail
, bool resolved_p
)
3879 rtx_insn
*next_tail
= NEXT_INSN (tail
);
3881 /* We make two passes since some insns may be scheduled before their
3882 dependencies are resolved. */
3883 for (insn
= head
; insn
!= next_tail
; insn
= NEXT_INSN (insn
))
3884 if (INSN_P (insn
) && INSN_LUID (insn
) > 0)
3886 /* Clear forward deps and leave the dep_nodes to the
3887 corresponding back_deps list. */
3889 clear_deps_list (INSN_RESOLVED_FORW_DEPS (insn
));
3891 clear_deps_list (INSN_FORW_DEPS (insn
));
3893 for (insn
= head
; insn
!= next_tail
; insn
= NEXT_INSN (insn
))
3894 if (INSN_P (insn
) && INSN_LUID (insn
) > 0)
3896 /* Clear resolved back deps together with its dep_nodes. */
3897 delete_dep_nodes_in_back_deps (insn
, resolved_p
);
3899 sd_finish_insn (insn
);
3903 /* Initialize variables for region data dependence analysis.
3904 When LAZY_REG_LAST is true, do not allocate reg_last array
3905 of struct deps_desc immediately. */
3908 init_deps (struct deps_desc
*deps
, bool lazy_reg_last
)
3910 int max_reg
= (reload_completed
? FIRST_PSEUDO_REGISTER
: max_reg_num ());
3912 deps
->max_reg
= max_reg
;
3914 deps
->reg_last
= NULL
;
3916 deps
->reg_last
= XCNEWVEC (struct deps_reg
, max_reg
);
3917 INIT_REG_SET (&deps
->reg_last_in_use
);
3919 deps
->pending_read_insns
= 0;
3920 deps
->pending_read_mems
= 0;
3921 deps
->pending_write_insns
= 0;
3922 deps
->pending_write_mems
= 0;
3923 deps
->pending_jump_insns
= 0;
3924 deps
->pending_read_list_length
= 0;
3925 deps
->pending_write_list_length
= 0;
3926 deps
->pending_flush_length
= 0;
3927 deps
->last_pending_memory_flush
= 0;
3928 deps
->last_function_call
= 0;
3929 deps
->last_function_call_may_noreturn
= 0;
3930 deps
->sched_before_next_call
= 0;
3931 deps
->sched_before_next_jump
= 0;
3932 deps
->in_post_call_group_p
= not_post_call
;
3933 deps
->last_debug_insn
= 0;
3934 deps
->last_args_size
= 0;
3935 deps
->last_reg_pending_barrier
= NOT_A_BARRIER
;
3939 /* Init only reg_last field of DEPS, which was not allocated before as
3940 we inited DEPS lazily. */
3942 init_deps_reg_last (struct deps_desc
*deps
)
3944 gcc_assert (deps
&& deps
->max_reg
> 0);
3945 gcc_assert (deps
->reg_last
== NULL
);
3947 deps
->reg_last
= XCNEWVEC (struct deps_reg
, deps
->max_reg
);
3951 /* Free insn lists found in DEPS. */
3954 free_deps (struct deps_desc
*deps
)
3957 reg_set_iterator rsi
;
3959 /* We set max_reg to 0 when this context was already freed. */
3960 if (deps
->max_reg
== 0)
3962 gcc_assert (deps
->reg_last
== NULL
);
3967 free_INSN_LIST_list (&deps
->pending_read_insns
);
3968 free_EXPR_LIST_list (&deps
->pending_read_mems
);
3969 free_INSN_LIST_list (&deps
->pending_write_insns
);
3970 free_EXPR_LIST_list (&deps
->pending_write_mems
);
3971 free_INSN_LIST_list (&deps
->last_pending_memory_flush
);
3973 /* Without the EXECUTE_IF_SET, this loop is executed max_reg * nr_regions
3974 times. For a testcase with 42000 regs and 8000 small basic blocks,
3975 this loop accounted for nearly 60% (84 sec) of the total -O2 runtime. */
3976 EXECUTE_IF_SET_IN_REG_SET (&deps
->reg_last_in_use
, 0, i
, rsi
)
3978 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
3980 free_INSN_LIST_list (®_last
->uses
);
3982 free_INSN_LIST_list (®_last
->sets
);
3983 if (reg_last
->implicit_sets
)
3984 free_INSN_LIST_list (®_last
->implicit_sets
);
3985 if (reg_last
->control_uses
)
3986 free_INSN_LIST_list (®_last
->control_uses
);
3987 if (reg_last
->clobbers
)
3988 free_INSN_LIST_list (®_last
->clobbers
);
3990 CLEAR_REG_SET (&deps
->reg_last_in_use
);
3992 /* As we initialize reg_last lazily, it is possible that we didn't allocate
3994 free (deps
->reg_last
);
3995 deps
->reg_last
= NULL
;
4000 /* Remove INSN from dependence contexts DEPS. */
4002 remove_from_deps (struct deps_desc
*deps
, rtx_insn
*insn
)
4006 reg_set_iterator rsi
;
4008 removed
= remove_from_both_dependence_lists (insn
, &deps
->pending_read_insns
,
4009 &deps
->pending_read_mems
);
4010 if (!DEBUG_INSN_P (insn
))
4011 deps
->pending_read_list_length
-= removed
;
4012 removed
= remove_from_both_dependence_lists (insn
, &deps
->pending_write_insns
,
4013 &deps
->pending_write_mems
);
4014 deps
->pending_write_list_length
-= removed
;
4016 removed
= remove_from_dependence_list (insn
, &deps
->pending_jump_insns
);
4017 deps
->pending_flush_length
-= removed
;
4018 removed
= remove_from_dependence_list (insn
, &deps
->last_pending_memory_flush
);
4019 deps
->pending_flush_length
-= removed
;
4021 EXECUTE_IF_SET_IN_REG_SET (&deps
->reg_last_in_use
, 0, i
, rsi
)
4023 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
4025 remove_from_dependence_list (insn
, ®_last
->uses
);
4027 remove_from_dependence_list (insn
, ®_last
->sets
);
4028 if (reg_last
->implicit_sets
)
4029 remove_from_dependence_list (insn
, ®_last
->implicit_sets
);
4030 if (reg_last
->clobbers
)
4031 remove_from_dependence_list (insn
, ®_last
->clobbers
);
4032 if (!reg_last
->uses
&& !reg_last
->sets
&& !reg_last
->implicit_sets
4033 && !reg_last
->clobbers
)
4034 CLEAR_REGNO_REG_SET (&deps
->reg_last_in_use
, i
);
4039 remove_from_dependence_list (insn
, &deps
->last_function_call
);
4040 remove_from_dependence_list (insn
,
4041 &deps
->last_function_call_may_noreturn
);
4043 remove_from_dependence_list (insn
, &deps
->sched_before_next_call
);
4046 /* Init deps data vector. */
4048 init_deps_data_vector (void)
4050 int reserve
= (sched_max_luid
+ 1 - h_d_i_d
.length ());
4051 if (reserve
> 0 && ! h_d_i_d
.space (reserve
))
4052 h_d_i_d
.safe_grow_cleared (3 * sched_max_luid
/ 2);
4055 /* If it is profitable to use them, initialize or extend (depending on
4056 GLOBAL_P) dependency data. */
4058 sched_deps_init (bool global_p
)
4060 /* Average number of insns in the basic block.
4061 '+ 1' is used to make it nonzero. */
4062 int insns_in_block
= sched_max_luid
/ n_basic_blocks_for_fn (cfun
) + 1;
4064 init_deps_data_vector ();
4066 /* We use another caching mechanism for selective scheduling, so
4067 we don't use this one. */
4068 if (!sel_sched_p () && global_p
&& insns_in_block
> 100 * 5)
4070 /* ?!? We could save some memory by computing a per-region luid mapping
4071 which could reduce both the number of vectors in the cache and the
4072 size of each vector. Instead we just avoid the cache entirely unless
4073 the average number of instructions in a basic block is very high. See
4074 the comment before the declaration of true_dependency_cache for
4075 what we consider "very high". */
4077 extend_dependency_caches (sched_max_luid
, true);
4082 dl_pool
= create_alloc_pool ("deps_list", sizeof (struct _deps_list
),
4083 /* Allocate lists for one block at a time. */
4085 dn_pool
= create_alloc_pool ("dep_node", sizeof (struct _dep_node
),
4086 /* Allocate nodes for one block at a time.
4087 We assume that average insn has
4089 5 * insns_in_block
);
4094 /* Create or extend (depending on CREATE_P) dependency caches to
4097 extend_dependency_caches (int n
, bool create_p
)
4099 if (create_p
|| true_dependency_cache
)
4101 int i
, luid
= cache_size
+ n
;
4103 true_dependency_cache
= XRESIZEVEC (bitmap_head
, true_dependency_cache
,
4105 output_dependency_cache
= XRESIZEVEC (bitmap_head
,
4106 output_dependency_cache
, luid
);
4107 anti_dependency_cache
= XRESIZEVEC (bitmap_head
, anti_dependency_cache
,
4109 control_dependency_cache
= XRESIZEVEC (bitmap_head
, control_dependency_cache
,
4112 if (current_sched_info
->flags
& DO_SPECULATION
)
4113 spec_dependency_cache
= XRESIZEVEC (bitmap_head
, spec_dependency_cache
,
4116 for (i
= cache_size
; i
< luid
; i
++)
4118 bitmap_initialize (&true_dependency_cache
[i
], 0);
4119 bitmap_initialize (&output_dependency_cache
[i
], 0);
4120 bitmap_initialize (&anti_dependency_cache
[i
], 0);
4121 bitmap_initialize (&control_dependency_cache
[i
], 0);
4123 if (current_sched_info
->flags
& DO_SPECULATION
)
4124 bitmap_initialize (&spec_dependency_cache
[i
], 0);
4130 /* Finalize dependency information for the whole function. */
4132 sched_deps_finish (void)
4134 gcc_assert (deps_pools_are_empty_p ());
4135 free_alloc_pool_if_empty (&dn_pool
);
4136 free_alloc_pool_if_empty (&dl_pool
);
4137 gcc_assert (dn_pool
== NULL
&& dl_pool
== NULL
);
4142 if (true_dependency_cache
)
4146 for (i
= 0; i
< cache_size
; i
++)
4148 bitmap_clear (&true_dependency_cache
[i
]);
4149 bitmap_clear (&output_dependency_cache
[i
]);
4150 bitmap_clear (&anti_dependency_cache
[i
]);
4151 bitmap_clear (&control_dependency_cache
[i
]);
4153 if (sched_deps_info
->generate_spec_deps
)
4154 bitmap_clear (&spec_dependency_cache
[i
]);
4156 free (true_dependency_cache
);
4157 true_dependency_cache
= NULL
;
4158 free (output_dependency_cache
);
4159 output_dependency_cache
= NULL
;
4160 free (anti_dependency_cache
);
4161 anti_dependency_cache
= NULL
;
4162 free (control_dependency_cache
);
4163 control_dependency_cache
= NULL
;
4165 if (sched_deps_info
->generate_spec_deps
)
4167 free (spec_dependency_cache
);
4168 spec_dependency_cache
= NULL
;
4174 /* Initialize some global variables needed by the dependency analysis
4178 init_deps_global (void)
4180 CLEAR_HARD_REG_SET (implicit_reg_pending_clobbers
);
4181 CLEAR_HARD_REG_SET (implicit_reg_pending_uses
);
4182 reg_pending_sets
= ALLOC_REG_SET (®_obstack
);
4183 reg_pending_clobbers
= ALLOC_REG_SET (®_obstack
);
4184 reg_pending_uses
= ALLOC_REG_SET (®_obstack
);
4185 reg_pending_control_uses
= ALLOC_REG_SET (®_obstack
);
4186 reg_pending_barrier
= NOT_A_BARRIER
;
4188 if (!sel_sched_p () || sched_emulate_haifa_p
)
4190 sched_deps_info
->start_insn
= haifa_start_insn
;
4191 sched_deps_info
->finish_insn
= haifa_finish_insn
;
4193 sched_deps_info
->note_reg_set
= haifa_note_reg_set
;
4194 sched_deps_info
->note_reg_clobber
= haifa_note_reg_clobber
;
4195 sched_deps_info
->note_reg_use
= haifa_note_reg_use
;
4197 sched_deps_info
->note_mem_dep
= haifa_note_mem_dep
;
4198 sched_deps_info
->note_dep
= haifa_note_dep
;
4202 /* Free everything used by the dependency analysis code. */
4205 finish_deps_global (void)
4207 FREE_REG_SET (reg_pending_sets
);
4208 FREE_REG_SET (reg_pending_clobbers
);
4209 FREE_REG_SET (reg_pending_uses
);
4210 FREE_REG_SET (reg_pending_control_uses
);
4213 /* Estimate the weakness of dependence between MEM1 and MEM2. */
4215 estimate_dep_weak (rtx mem1
, rtx mem2
)
4220 /* MEMs are the same - don't speculate. */
4221 return MIN_DEP_WEAK
;
4223 r1
= XEXP (mem1
, 0);
4224 r2
= XEXP (mem2
, 0);
4227 || (REG_P (r1
) && REG_P (r2
)
4228 && REGNO (r1
) == REGNO (r2
)))
4229 /* Again, MEMs are the same. */
4230 return MIN_DEP_WEAK
;
4231 else if ((REG_P (r1
) && !REG_P (r2
))
4232 || (!REG_P (r1
) && REG_P (r2
)))
4233 /* Different addressing modes - reason to be more speculative,
4235 return NO_DEP_WEAK
- (NO_DEP_WEAK
- UNCERTAIN_DEP_WEAK
) / 2;
4237 /* We can't say anything about the dependence. */
4238 return UNCERTAIN_DEP_WEAK
;
4241 /* Add or update backward dependence between INSN and ELEM with type DEP_TYPE.
4242 This function can handle same INSN and ELEM (INSN == ELEM).
4243 It is a convenience wrapper. */
4245 add_dependence_1 (rtx_insn
*insn
, rtx_insn
*elem
, enum reg_note dep_type
)
4250 if (dep_type
== REG_DEP_TRUE
)
4252 else if (dep_type
== REG_DEP_OUTPUT
)
4254 else if (dep_type
== REG_DEP_CONTROL
)
4258 gcc_assert (dep_type
== REG_DEP_ANTI
);
4262 /* When add_dependence is called from inside sched-deps.c, we expect
4263 cur_insn to be non-null. */
4264 internal
= cur_insn
!= NULL
;
4266 gcc_assert (insn
== cur_insn
);
4270 note_dep (elem
, ds
);
4275 /* Return weakness of speculative type TYPE in the dep_status DS,
4276 without checking to prevent ICEs on malformed input. */
4278 get_dep_weak_1 (ds_t ds
, ds_t type
)
4284 case BEGIN_DATA
: ds
>>= BEGIN_DATA_BITS_OFFSET
; break;
4285 case BE_IN_DATA
: ds
>>= BE_IN_DATA_BITS_OFFSET
; break;
4286 case BEGIN_CONTROL
: ds
>>= BEGIN_CONTROL_BITS_OFFSET
; break;
4287 case BE_IN_CONTROL
: ds
>>= BE_IN_CONTROL_BITS_OFFSET
; break;
4288 default: gcc_unreachable ();
4294 /* Return weakness of speculative type TYPE in the dep_status DS. */
4296 get_dep_weak (ds_t ds
, ds_t type
)
4298 dw_t dw
= get_dep_weak_1 (ds
, type
);
4300 gcc_assert (MIN_DEP_WEAK
<= dw
&& dw
<= MAX_DEP_WEAK
);
4304 /* Return the dep_status, which has the same parameters as DS, except for
4305 speculative type TYPE, that will have weakness DW. */
4307 set_dep_weak (ds_t ds
, ds_t type
, dw_t dw
)
4309 gcc_assert (MIN_DEP_WEAK
<= dw
&& dw
<= MAX_DEP_WEAK
);
4314 case BEGIN_DATA
: ds
|= ((ds_t
) dw
) << BEGIN_DATA_BITS_OFFSET
; break;
4315 case BE_IN_DATA
: ds
|= ((ds_t
) dw
) << BE_IN_DATA_BITS_OFFSET
; break;
4316 case BEGIN_CONTROL
: ds
|= ((ds_t
) dw
) << BEGIN_CONTROL_BITS_OFFSET
; break;
4317 case BE_IN_CONTROL
: ds
|= ((ds_t
) dw
) << BE_IN_CONTROL_BITS_OFFSET
; break;
4318 default: gcc_unreachable ();
4323 /* Return the join of two dep_statuses DS1 and DS2.
4324 If MAX_P is true then choose the greater probability,
4325 otherwise multiply probabilities.
4326 This function assumes that both DS1 and DS2 contain speculative bits. */
4328 ds_merge_1 (ds_t ds1
, ds_t ds2
, bool max_p
)
4332 gcc_assert ((ds1
& SPECULATIVE
) && (ds2
& SPECULATIVE
));
4334 ds
= (ds1
& DEP_TYPES
) | (ds2
& DEP_TYPES
);
4336 t
= FIRST_SPEC_TYPE
;
4339 if ((ds1
& t
) && !(ds2
& t
))
4341 else if (!(ds1
& t
) && (ds2
& t
))
4343 else if ((ds1
& t
) && (ds2
& t
))
4345 dw_t dw1
= get_dep_weak (ds1
, t
);
4346 dw_t dw2
= get_dep_weak (ds2
, t
);
4351 dw
= ((ds_t
) dw1
) * ((ds_t
) dw2
);
4353 if (dw
< MIN_DEP_WEAK
)
4364 ds
= set_dep_weak (ds
, t
, (dw_t
) dw
);
4367 if (t
== LAST_SPEC_TYPE
)
4369 t
<<= SPEC_TYPE_SHIFT
;
4376 /* Return the join of two dep_statuses DS1 and DS2.
4377 This function assumes that both DS1 and DS2 contain speculative bits. */
4379 ds_merge (ds_t ds1
, ds_t ds2
)
4381 return ds_merge_1 (ds1
, ds2
, false);
4384 /* Return the join of two dep_statuses DS1 and DS2. */
4386 ds_full_merge (ds_t ds
, ds_t ds2
, rtx mem1
, rtx mem2
)
4388 ds_t new_status
= ds
| ds2
;
4390 if (new_status
& SPECULATIVE
)
4392 if ((ds
&& !(ds
& SPECULATIVE
))
4393 || (ds2
&& !(ds2
& SPECULATIVE
)))
4394 /* Then this dep can't be speculative. */
4395 new_status
&= ~SPECULATIVE
;
4398 /* Both are speculative. Merging probabilities. */
4403 dw
= estimate_dep_weak (mem1
, mem2
);
4404 ds
= set_dep_weak (ds
, BEGIN_DATA
, dw
);
4412 new_status
= ds_merge (ds2
, ds
);
4419 /* Return the join of DS1 and DS2. Use maximum instead of multiplying
4422 ds_max_merge (ds_t ds1
, ds_t ds2
)
4424 if (ds1
== 0 && ds2
== 0)
4427 if (ds1
== 0 && ds2
!= 0)
4430 if (ds1
!= 0 && ds2
== 0)
4433 return ds_merge_1 (ds1
, ds2
, true);
4436 /* Return the probability of speculation success for the speculation
4444 dt
= FIRST_SPEC_TYPE
;
4449 res
*= (ds_t
) get_dep_weak (ds
, dt
);
4453 if (dt
== LAST_SPEC_TYPE
)
4455 dt
<<= SPEC_TYPE_SHIFT
;
4461 res
/= MAX_DEP_WEAK
;
4463 if (res
< MIN_DEP_WEAK
)
4466 gcc_assert (res
<= MAX_DEP_WEAK
);
4471 /* Return a dep status that contains all speculation types of DS. */
4473 ds_get_speculation_types (ds_t ds
)
4475 if (ds
& BEGIN_DATA
)
4477 if (ds
& BE_IN_DATA
)
4479 if (ds
& BEGIN_CONTROL
)
4480 ds
|= BEGIN_CONTROL
;
4481 if (ds
& BE_IN_CONTROL
)
4482 ds
|= BE_IN_CONTROL
;
4484 return ds
& SPECULATIVE
;
4487 /* Return a dep status that contains maximal weakness for each speculation
4488 type present in DS. */
4490 ds_get_max_dep_weak (ds_t ds
)
4492 if (ds
& BEGIN_DATA
)
4493 ds
= set_dep_weak (ds
, BEGIN_DATA
, MAX_DEP_WEAK
);
4494 if (ds
& BE_IN_DATA
)
4495 ds
= set_dep_weak (ds
, BE_IN_DATA
, MAX_DEP_WEAK
);
4496 if (ds
& BEGIN_CONTROL
)
4497 ds
= set_dep_weak (ds
, BEGIN_CONTROL
, MAX_DEP_WEAK
);
4498 if (ds
& BE_IN_CONTROL
)
4499 ds
= set_dep_weak (ds
, BE_IN_CONTROL
, MAX_DEP_WEAK
);
4504 /* Dump information about the dependence status S. */
4506 dump_ds (FILE *f
, ds_t s
)
4511 fprintf (f
, "BEGIN_DATA: %d; ", get_dep_weak_1 (s
, BEGIN_DATA
));
4513 fprintf (f
, "BE_IN_DATA: %d; ", get_dep_weak_1 (s
, BE_IN_DATA
));
4514 if (s
& BEGIN_CONTROL
)
4515 fprintf (f
, "BEGIN_CONTROL: %d; ", get_dep_weak_1 (s
, BEGIN_CONTROL
));
4516 if (s
& BE_IN_CONTROL
)
4517 fprintf (f
, "BE_IN_CONTROL: %d; ", get_dep_weak_1 (s
, BE_IN_CONTROL
));
4520 fprintf (f
, "HARD_DEP; ");
4523 fprintf (f
, "DEP_TRUE; ");
4525 fprintf (f
, "DEP_OUTPUT; ");
4527 fprintf (f
, "DEP_ANTI; ");
4528 if (s
& DEP_CONTROL
)
4529 fprintf (f
, "DEP_CONTROL; ");
4537 dump_ds (stderr
, s
);
4538 fprintf (stderr
, "\n");
4541 #ifdef ENABLE_CHECKING
4542 /* Verify that dependence type and status are consistent.
4543 If RELAXED_P is true, then skip dep_weakness checks. */
4545 check_dep (dep_t dep
, bool relaxed_p
)
4547 enum reg_note dt
= DEP_TYPE (dep
);
4548 ds_t ds
= DEP_STATUS (dep
);
4550 gcc_assert (DEP_PRO (dep
) != DEP_CON (dep
));
4552 if (!(current_sched_info
->flags
& USE_DEPS_LIST
))
4554 gcc_assert (ds
== 0);
4558 /* Check that dependence type contains the same bits as the status. */
4559 if (dt
== REG_DEP_TRUE
)
4560 gcc_assert (ds
& DEP_TRUE
);
4561 else if (dt
== REG_DEP_OUTPUT
)
4562 gcc_assert ((ds
& DEP_OUTPUT
)
4563 && !(ds
& DEP_TRUE
));
4564 else if (dt
== REG_DEP_ANTI
)
4565 gcc_assert ((ds
& DEP_ANTI
)
4566 && !(ds
& (DEP_OUTPUT
| DEP_TRUE
)));
4568 gcc_assert (dt
== REG_DEP_CONTROL
4569 && (ds
& DEP_CONTROL
)
4570 && !(ds
& (DEP_OUTPUT
| DEP_ANTI
| DEP_TRUE
)));
4572 /* HARD_DEP can not appear in dep_status of a link. */
4573 gcc_assert (!(ds
& HARD_DEP
));
4575 /* Check that dependence status is set correctly when speculation is not
4577 if (!sched_deps_info
->generate_spec_deps
)
4578 gcc_assert (!(ds
& SPECULATIVE
));
4579 else if (ds
& SPECULATIVE
)
4583 ds_t type
= FIRST_SPEC_TYPE
;
4585 /* Check that dependence weakness is in proper range. */
4589 get_dep_weak (ds
, type
);
4591 if (type
== LAST_SPEC_TYPE
)
4593 type
<<= SPEC_TYPE_SHIFT
;
4598 if (ds
& BEGIN_SPEC
)
4600 /* Only true dependence can be data speculative. */
4601 if (ds
& BEGIN_DATA
)
4602 gcc_assert (ds
& DEP_TRUE
);
4604 /* Control dependencies in the insn scheduler are represented by
4605 anti-dependencies, therefore only anti dependence can be
4606 control speculative. */
4607 if (ds
& BEGIN_CONTROL
)
4608 gcc_assert (ds
& DEP_ANTI
);
4612 /* Subsequent speculations should resolve true dependencies. */
4613 gcc_assert ((ds
& DEP_TYPES
) == DEP_TRUE
);
4616 /* Check that true and anti dependencies can't have other speculative
4619 gcc_assert (ds
& (BEGIN_DATA
| BE_IN_SPEC
));
4620 /* An output dependence can't be speculative at all. */
4621 gcc_assert (!(ds
& DEP_OUTPUT
));
4623 gcc_assert (ds
& BEGIN_CONTROL
);
4626 #endif /* ENABLE_CHECKING */
4628 /* The following code discovers opportunities to switch a memory reference
4629 and an increment by modifying the address. We ensure that this is done
4630 only for dependencies that are only used to show a single register
4631 dependence (using DEP_NONREG and DEP_MULTIPLE), and so that every memory
4632 instruction involved is subject to only one dep that can cause a pattern
4635 When we discover a suitable dependency, we fill in the dep_replacement
4636 structure to show how to modify the memory reference. */
4638 /* Holds information about a pair of memory reference and register increment
4639 insns which depend on each other, but could possibly be interchanged. */
4646 /* A register occurring in the memory address for which we wish to break
4647 the dependence. This must be identical to the destination register of
4650 /* Any kind of index that is added to that register. */
4652 /* The constant offset used in the memory address. */
4653 HOST_WIDE_INT mem_constant
;
4654 /* The constant added in the increment insn. Negated if the increment is
4655 after the memory address. */
4656 HOST_WIDE_INT inc_constant
;
4657 /* The source register used in the increment. May be different from mem_reg0
4658 if the increment occurs before the memory address. */
4662 /* Verify that the memory location described in MII can be replaced with
4663 one using NEW_ADDR. Return the new memory reference or NULL_RTX. The
4664 insn remains unchanged by this function. */
4667 attempt_change (struct mem_inc_info
*mii
, rtx new_addr
)
4669 rtx mem
= *mii
->mem_loc
;
4672 /* Jump through a lot of hoops to keep the attributes up to date. We
4673 do not want to call one of the change address variants that take
4674 an offset even though we know the offset in many cases. These
4675 assume you are changing where the address is pointing by the
4677 new_mem
= replace_equiv_address_nv (mem
, new_addr
);
4678 if (! validate_change (mii
->mem_insn
, mii
->mem_loc
, new_mem
, 0))
4680 if (sched_verbose
>= 5)
4681 fprintf (sched_dump
, "validation failure\n");
4685 /* Put back the old one. */
4686 validate_change (mii
->mem_insn
, mii
->mem_loc
, mem
, 0);
4691 /* Return true if INSN is of a form "a = b op c" where a and b are
4692 regs. op is + if c is a reg and +|- if c is a const. Fill in
4693 informantion in MII about what is found.
4694 BEFORE_MEM indicates whether the increment is found before or after
4695 a corresponding memory reference. */
4698 parse_add_or_inc (struct mem_inc_info
*mii
, rtx_insn
*insn
, bool before_mem
)
4700 rtx pat
= single_set (insn
);
4704 if (RTX_FRAME_RELATED_P (insn
) || !pat
)
4707 /* Result must be single reg. */
4708 if (!REG_P (SET_DEST (pat
)))
4711 if (GET_CODE (SET_SRC (pat
)) != PLUS
)
4714 mii
->inc_insn
= insn
;
4715 src
= SET_SRC (pat
);
4716 mii
->inc_input
= XEXP (src
, 0);
4718 if (!REG_P (XEXP (src
, 0)))
4721 if (!rtx_equal_p (SET_DEST (pat
), mii
->mem_reg0
))
4724 cst
= XEXP (src
, 1);
4725 if (!CONST_INT_P (cst
))
4727 mii
->inc_constant
= INTVAL (cst
);
4729 regs_equal
= rtx_equal_p (mii
->inc_input
, mii
->mem_reg0
);
4733 mii
->inc_constant
= -mii
->inc_constant
;
4738 if (regs_equal
&& REGNO (SET_DEST (pat
)) == STACK_POINTER_REGNUM
)
4740 /* Note that the sign has already been reversed for !before_mem. */
4741 #ifdef STACK_GROWS_DOWNWARD
4742 return mii
->inc_constant
> 0;
4744 return mii
->inc_constant
< 0;
4750 /* Once a suitable mem reference has been found and the corresponding data
4751 in MII has been filled in, this function is called to find a suitable
4752 add or inc insn involving the register we found in the memory
4756 find_inc (struct mem_inc_info
*mii
, bool backwards
)
4758 sd_iterator_def sd_it
;
4761 sd_it
= sd_iterator_start (mii
->mem_insn
,
4762 backwards
? SD_LIST_HARD_BACK
: SD_LIST_FORW
);
4763 while (sd_iterator_cond (&sd_it
, &dep
))
4765 dep_node_t node
= DEP_LINK_NODE (*sd_it
.linkp
);
4766 rtx_insn
*pro
= DEP_PRO (dep
);
4767 rtx_insn
*con
= DEP_CON (dep
);
4768 rtx_insn
*inc_cand
= backwards
? pro
: con
;
4769 if (DEP_NONREG (dep
) || DEP_MULTIPLE (dep
))
4771 if (parse_add_or_inc (mii
, inc_cand
, backwards
))
4773 struct dep_replacement
*desc
;
4775 rtx newaddr
, newmem
;
4777 if (sched_verbose
>= 5)
4778 fprintf (sched_dump
, "candidate mem/inc pair: %d %d\n",
4779 INSN_UID (mii
->mem_insn
), INSN_UID (inc_cand
));
4781 /* Need to assure that none of the operands of the inc
4782 instruction are assigned to by the mem insn. */
4783 FOR_EACH_INSN_DEF (def
, mii
->mem_insn
)
4784 if (reg_overlap_mentioned_p (DF_REF_REG (def
), mii
->inc_input
)
4785 || reg_overlap_mentioned_p (DF_REF_REG (def
), mii
->mem_reg0
))
4787 if (sched_verbose
>= 5)
4788 fprintf (sched_dump
,
4789 "inc conflicts with store failure.\n");
4793 newaddr
= mii
->inc_input
;
4794 if (mii
->mem_index
!= NULL_RTX
)
4795 newaddr
= gen_rtx_PLUS (GET_MODE (newaddr
), newaddr
,
4797 newaddr
= plus_constant (GET_MODE (newaddr
), newaddr
,
4798 mii
->mem_constant
+ mii
->inc_constant
);
4799 newmem
= attempt_change (mii
, newaddr
);
4800 if (newmem
== NULL_RTX
)
4802 if (sched_verbose
>= 5)
4803 fprintf (sched_dump
, "successful address replacement\n");
4804 desc
= XCNEW (struct dep_replacement
);
4805 DEP_REPLACE (dep
) = desc
;
4806 desc
->loc
= mii
->mem_loc
;
4807 desc
->newval
= newmem
;
4808 desc
->orig
= *desc
->loc
;
4809 desc
->insn
= mii
->mem_insn
;
4810 move_dep_link (DEP_NODE_BACK (node
), INSN_HARD_BACK_DEPS (con
),
4811 INSN_SPEC_BACK_DEPS (con
));
4814 FOR_EACH_DEP (mii
->inc_insn
, SD_LIST_BACK
, sd_it
, dep
)
4815 add_dependence_1 (mii
->mem_insn
, DEP_PRO (dep
),
4820 FOR_EACH_DEP (mii
->inc_insn
, SD_LIST_FORW
, sd_it
, dep
)
4821 add_dependence_1 (DEP_CON (dep
), mii
->mem_insn
,
4827 sd_iterator_next (&sd_it
);
4832 /* A recursive function that walks ADDRESS_OF_X to find memory references
4833 which could be modified during scheduling. We call find_inc for each
4834 one we find that has a recognizable form. MII holds information about
4835 the pair of memory/increment instructions.
4836 We ensure that every instruction with a memory reference (which will be
4837 the location of the replacement) is assigned at most one breakable
4841 find_mem (struct mem_inc_info
*mii
, rtx
*address_of_x
)
4843 rtx x
= *address_of_x
;
4844 enum rtx_code code
= GET_CODE (x
);
4845 const char *const fmt
= GET_RTX_FORMAT (code
);
4850 rtx reg0
= XEXP (x
, 0);
4852 mii
->mem_loc
= address_of_x
;
4853 mii
->mem_index
= NULL_RTX
;
4854 mii
->mem_constant
= 0;
4855 if (GET_CODE (reg0
) == PLUS
&& CONST_INT_P (XEXP (reg0
, 1)))
4857 mii
->mem_constant
= INTVAL (XEXP (reg0
, 1));
4858 reg0
= XEXP (reg0
, 0);
4860 if (GET_CODE (reg0
) == PLUS
)
4862 mii
->mem_index
= XEXP (reg0
, 1);
4863 reg0
= XEXP (reg0
, 0);
4868 int occurrences
= 0;
4870 /* Make sure this reg appears only once in this insn. Can't use
4871 count_occurrences since that only works for pseudos. */
4872 FOR_EACH_INSN_USE (use
, mii
->mem_insn
)
4873 if (reg_overlap_mentioned_p (reg0
, DF_REF_REG (use
)))
4874 if (++occurrences
> 1)
4876 if (sched_verbose
>= 5)
4877 fprintf (sched_dump
, "mem count failure\n");
4881 mii
->mem_reg0
= reg0
;
4882 return find_inc (mii
, true) || find_inc (mii
, false);
4887 if (code
== SIGN_EXTRACT
|| code
== ZERO_EXTRACT
)
4889 /* If REG occurs inside a MEM used in a bit-field reference,
4890 that is unacceptable. */
4894 /* Time for some deep diving. */
4895 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
4899 if (find_mem (mii
, &XEXP (x
, i
)))
4902 else if (fmt
[i
] == 'E')
4905 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
4906 if (find_mem (mii
, &XVECEXP (x
, i
, j
)))
4914 /* Examine the instructions between HEAD and TAIL and try to find
4915 dependencies that can be broken by modifying one of the patterns. */
4918 find_modifiable_mems (rtx_insn
*head
, rtx_insn
*tail
)
4920 rtx_insn
*insn
, *next_tail
= NEXT_INSN (tail
);
4921 int success_in_block
= 0;
4923 for (insn
= head
; insn
!= next_tail
; insn
= NEXT_INSN (insn
))
4925 struct mem_inc_info mii
;
4927 if (!NONDEBUG_INSN_P (insn
) || RTX_FRAME_RELATED_P (insn
))
4930 mii
.mem_insn
= insn
;
4931 if (find_mem (&mii
, &PATTERN (insn
)))
4934 if (success_in_block
&& sched_verbose
>= 5)
4935 fprintf (sched_dump
, "%d candidates for address modification found.\n",
4939 #endif /* INSN_SCHEDULING */