1 /* Instruction scheduling pass. This file computes dependencies between
3 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998,
4 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
5 Free Software Foundation, Inc.
6 Contributed by Michael Tiemann (tiemann@cygnus.com) Enhanced by,
7 and currently maintained by, Jim Wilson (wilson@cygnus.com)
9 This file is part of GCC.
11 GCC is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free
13 Software Foundation; either version 3, or (at your option) any later
16 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
17 WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with GCC; see the file COPYING3. If not see
23 <http://www.gnu.org/licenses/>. */
27 #include "coretypes.h"
29 #include "diagnostic-core.h"
32 #include "hard-reg-set.h"
36 #include "insn-config.h"
37 #include "insn-attr.h"
40 #include "sched-int.h"
46 #ifdef INSN_SCHEDULING
48 #ifdef ENABLE_CHECKING
54 /* In deps->last_pending_memory_flush marks JUMP_INSNs that weren't
55 added to the list because of flush_pending_lists, stands just
56 for itself and not for any other pending memory reads/writes. */
57 #define NON_FLUSH_JUMP_KIND REG_DEP_ANTI
58 #define NON_FLUSH_JUMP_P(x) (REG_NOTE_KIND (x) == NON_FLUSH_JUMP_KIND)
60 /* Holds current parameters for the dependency analyzer. */
61 struct sched_deps_info_def
*sched_deps_info
;
63 /* The data is specific to the Haifa scheduler. */
64 VEC(haifa_deps_insn_data_def
, heap
) *h_d_i_d
= NULL
;
66 /* Return the major type present in the DS. */
74 return REG_DEP_OUTPUT
;
76 gcc_assert (ds
& DEP_ANTI
);
81 /* Return equivalent dep_status. */
83 dk_to_ds (enum reg_note dk
)
94 gcc_assert (dk
== REG_DEP_ANTI
);
99 /* Functions to operate with dependence information container - dep_t. */
101 /* Init DEP with the arguments. */
103 init_dep_1 (dep_t dep
, rtx pro
, rtx con
, enum reg_note type
, ds_t ds
)
107 DEP_TYPE (dep
) = type
;
108 DEP_STATUS (dep
) = ds
;
111 /* Init DEP with the arguments.
112 While most of the scheduler (including targets) only need the major type
113 of the dependency, it is convenient to hide full dep_status from them. */
115 init_dep (dep_t dep
, rtx pro
, rtx con
, enum reg_note kind
)
119 if ((current_sched_info
->flags
& USE_DEPS_LIST
))
120 ds
= dk_to_ds (kind
);
124 init_dep_1 (dep
, pro
, con
, kind
, ds
);
127 /* Make a copy of FROM in TO. */
129 copy_dep (dep_t to
, dep_t from
)
131 memcpy (to
, from
, sizeof (*to
));
134 static void dump_ds (FILE *, ds_t
);
136 /* Define flags for dump_dep (). */
138 /* Dump producer of the dependence. */
139 #define DUMP_DEP_PRO (2)
141 /* Dump consumer of the dependence. */
142 #define DUMP_DEP_CON (4)
144 /* Dump type of the dependence. */
145 #define DUMP_DEP_TYPE (8)
147 /* Dump status of the dependence. */
148 #define DUMP_DEP_STATUS (16)
150 /* Dump all information about the dependence. */
151 #define DUMP_DEP_ALL (DUMP_DEP_PRO | DUMP_DEP_CON | DUMP_DEP_TYPE \
155 FLAGS is a bit mask specifying what information about DEP needs
157 If FLAGS has the very first bit set, then dump all information about DEP
158 and propagate this bit into the callee dump functions. */
160 dump_dep (FILE *dump
, dep_t dep
, int flags
)
163 flags
|= DUMP_DEP_ALL
;
167 if (flags
& DUMP_DEP_PRO
)
168 fprintf (dump
, "%d; ", INSN_UID (DEP_PRO (dep
)));
170 if (flags
& DUMP_DEP_CON
)
171 fprintf (dump
, "%d; ", INSN_UID (DEP_CON (dep
)));
173 if (flags
& DUMP_DEP_TYPE
)
176 enum reg_note type
= DEP_TYPE (dep
);
197 fprintf (dump
, "%c; ", t
);
200 if (flags
& DUMP_DEP_STATUS
)
202 if (current_sched_info
->flags
& USE_DEPS_LIST
)
203 dump_ds (dump
, DEP_STATUS (dep
));
209 /* Default flags for dump_dep (). */
210 static int dump_dep_flags
= (DUMP_DEP_PRO
| DUMP_DEP_CON
);
212 /* Dump all fields of DEP to STDERR. */
214 sd_debug_dep (dep_t dep
)
216 dump_dep (stderr
, dep
, 1);
217 fprintf (stderr
, "\n");
220 /* Determine whether DEP is a dependency link of a non-debug insn on a
224 depl_on_debug_p (dep_link_t dep
)
226 return (DEBUG_INSN_P (DEP_LINK_PRO (dep
))
227 && !DEBUG_INSN_P (DEP_LINK_CON (dep
)));
230 /* Functions to operate with a single link from the dependencies lists -
233 /* Attach L to appear after link X whose &DEP_LINK_NEXT (X) is given by
236 attach_dep_link (dep_link_t l
, dep_link_t
*prev_nextp
)
238 dep_link_t next
= *prev_nextp
;
240 gcc_assert (DEP_LINK_PREV_NEXTP (l
) == NULL
241 && DEP_LINK_NEXT (l
) == NULL
);
243 /* Init node being inserted. */
244 DEP_LINK_PREV_NEXTP (l
) = prev_nextp
;
245 DEP_LINK_NEXT (l
) = next
;
250 gcc_assert (DEP_LINK_PREV_NEXTP (next
) == prev_nextp
);
252 DEP_LINK_PREV_NEXTP (next
) = &DEP_LINK_NEXT (l
);
259 /* Add dep_link LINK to deps_list L. */
261 add_to_deps_list (dep_link_t link
, deps_list_t l
)
263 attach_dep_link (link
, &DEPS_LIST_FIRST (l
));
265 /* Don't count debug deps. */
266 if (!depl_on_debug_p (link
))
267 ++DEPS_LIST_N_LINKS (l
);
270 /* Detach dep_link L from the list. */
272 detach_dep_link (dep_link_t l
)
274 dep_link_t
*prev_nextp
= DEP_LINK_PREV_NEXTP (l
);
275 dep_link_t next
= DEP_LINK_NEXT (l
);
280 DEP_LINK_PREV_NEXTP (next
) = prev_nextp
;
282 DEP_LINK_PREV_NEXTP (l
) = NULL
;
283 DEP_LINK_NEXT (l
) = NULL
;
286 /* Remove link LINK from list LIST. */
288 remove_from_deps_list (dep_link_t link
, deps_list_t list
)
290 detach_dep_link (link
);
292 /* Don't count debug deps. */
293 if (!depl_on_debug_p (link
))
294 --DEPS_LIST_N_LINKS (list
);
297 /* Move link LINK from list FROM to list TO. */
299 move_dep_link (dep_link_t link
, deps_list_t from
, deps_list_t to
)
301 remove_from_deps_list (link
, from
);
302 add_to_deps_list (link
, to
);
305 /* Return true of LINK is not attached to any list. */
307 dep_link_is_detached_p (dep_link_t link
)
309 return DEP_LINK_PREV_NEXTP (link
) == NULL
;
312 /* Pool to hold all dependency nodes (dep_node_t). */
313 static alloc_pool dn_pool
;
315 /* Number of dep_nodes out there. */
316 static int dn_pool_diff
= 0;
318 /* Create a dep_node. */
320 create_dep_node (void)
322 dep_node_t n
= (dep_node_t
) pool_alloc (dn_pool
);
323 dep_link_t back
= DEP_NODE_BACK (n
);
324 dep_link_t forw
= DEP_NODE_FORW (n
);
326 DEP_LINK_NODE (back
) = n
;
327 DEP_LINK_NEXT (back
) = NULL
;
328 DEP_LINK_PREV_NEXTP (back
) = NULL
;
330 DEP_LINK_NODE (forw
) = n
;
331 DEP_LINK_NEXT (forw
) = NULL
;
332 DEP_LINK_PREV_NEXTP (forw
) = NULL
;
339 /* Delete dep_node N. N must not be connected to any deps_list. */
341 delete_dep_node (dep_node_t n
)
343 gcc_assert (dep_link_is_detached_p (DEP_NODE_BACK (n
))
344 && dep_link_is_detached_p (DEP_NODE_FORW (n
)));
348 pool_free (dn_pool
, n
);
351 /* Pool to hold dependencies lists (deps_list_t). */
352 static alloc_pool dl_pool
;
354 /* Number of deps_lists out there. */
355 static int dl_pool_diff
= 0;
357 /* Functions to operate with dependences lists - deps_list_t. */
359 /* Return true if list L is empty. */
361 deps_list_empty_p (deps_list_t l
)
363 return DEPS_LIST_N_LINKS (l
) == 0;
366 /* Create a new deps_list. */
368 create_deps_list (void)
370 deps_list_t l
= (deps_list_t
) pool_alloc (dl_pool
);
372 DEPS_LIST_FIRST (l
) = NULL
;
373 DEPS_LIST_N_LINKS (l
) = 0;
379 /* Free deps_list L. */
381 free_deps_list (deps_list_t l
)
383 gcc_assert (deps_list_empty_p (l
));
387 pool_free (dl_pool
, l
);
390 /* Return true if there is no dep_nodes and deps_lists out there.
391 After the region is scheduled all the dependency nodes and lists
392 should [generally] be returned to pool. */
394 deps_pools_are_empty_p (void)
396 return dn_pool_diff
== 0 && dl_pool_diff
== 0;
399 /* Remove all elements from L. */
401 clear_deps_list (deps_list_t l
)
405 dep_link_t link
= DEPS_LIST_FIRST (l
);
410 remove_from_deps_list (link
, l
);
415 static regset reg_pending_sets
;
416 static regset reg_pending_clobbers
;
417 static regset reg_pending_uses
;
418 static enum reg_pending_barrier_mode reg_pending_barrier
;
420 /* Hard registers implicitly clobbered or used (or may be implicitly
421 clobbered or used) by the currently analyzed insn. For example,
422 insn in its constraint has one register class. Even if there is
423 currently no hard register in the insn, the particular hard
424 register will be in the insn after reload pass because the
425 constraint requires it. */
426 static HARD_REG_SET implicit_reg_pending_clobbers
;
427 static HARD_REG_SET implicit_reg_pending_uses
;
429 /* To speed up the test for duplicate dependency links we keep a
430 record of dependencies created by add_dependence when the average
431 number of instructions in a basic block is very large.
433 Studies have shown that there is typically around 5 instructions between
434 branches for typical C code. So we can make a guess that the average
435 basic block is approximately 5 instructions long; we will choose 100X
436 the average size as a very large basic block.
438 Each insn has associated bitmaps for its dependencies. Each bitmap
439 has enough entries to represent a dependency on any other insn in
440 the insn chain. All bitmap for true dependencies cache is
441 allocated then the rest two ones are also allocated. */
442 static bitmap_head
*true_dependency_cache
= NULL
;
443 static bitmap_head
*output_dependency_cache
= NULL
;
444 static bitmap_head
*anti_dependency_cache
= NULL
;
445 static bitmap_head
*spec_dependency_cache
= NULL
;
446 static int cache_size
;
448 static int deps_may_trap_p (const_rtx
);
449 static void add_dependence_list (rtx
, rtx
, int, enum reg_note
);
450 static void add_dependence_list_and_free (struct deps_desc
*, rtx
,
451 rtx
*, int, enum reg_note
);
452 static void delete_all_dependences (rtx
);
453 static void fixup_sched_groups (rtx
);
455 static void flush_pending_lists (struct deps_desc
*, rtx
, int, int);
456 static void sched_analyze_1 (struct deps_desc
*, rtx
, rtx
);
457 static void sched_analyze_2 (struct deps_desc
*, rtx
, rtx
);
458 static void sched_analyze_insn (struct deps_desc
*, rtx
, rtx
);
460 static bool sched_has_condition_p (const_rtx
);
461 static int conditions_mutex_p (const_rtx
, const_rtx
, bool, bool);
463 static enum DEPS_ADJUST_RESULT
maybe_add_or_update_dep_1 (dep_t
, bool,
465 static enum DEPS_ADJUST_RESULT
add_or_update_dep_1 (dep_t
, bool, rtx
, rtx
);
467 #ifdef ENABLE_CHECKING
468 static void check_dep (dep_t
, bool);
471 /* Return nonzero if a load of the memory reference MEM can cause a trap. */
474 deps_may_trap_p (const_rtx mem
)
476 const_rtx addr
= XEXP (mem
, 0);
478 if (REG_P (addr
) && REGNO (addr
) >= FIRST_PSEUDO_REGISTER
)
480 const_rtx t
= get_reg_known_value (REGNO (addr
));
484 return rtx_addr_can_trap_p (addr
);
488 /* Find the condition under which INSN is executed. If REV is not NULL,
489 it is set to TRUE when the returned comparison should be reversed
490 to get the actual condition. */
492 sched_get_condition_with_rev (const_rtx insn
, bool *rev
)
494 rtx pat
= PATTERN (insn
);
503 if (GET_CODE (pat
) == COND_EXEC
)
504 return COND_EXEC_TEST (pat
);
506 if (!any_condjump_p (insn
) || !onlyjump_p (insn
))
509 src
= SET_SRC (pc_set (insn
));
511 if (XEXP (src
, 2) == pc_rtx
)
512 return XEXP (src
, 0);
513 else if (XEXP (src
, 1) == pc_rtx
)
515 rtx cond
= XEXP (src
, 0);
516 enum rtx_code revcode
= reversed_comparison_code (cond
, insn
);
518 if (revcode
== UNKNOWN
)
529 /* True when we can find a condition under which INSN is executed. */
531 sched_has_condition_p (const_rtx insn
)
533 return !! sched_get_condition_with_rev (insn
, NULL
);
538 /* Return nonzero if conditions COND1 and COND2 can never be both true. */
540 conditions_mutex_p (const_rtx cond1
, const_rtx cond2
, bool rev1
, bool rev2
)
542 if (COMPARISON_P (cond1
)
543 && COMPARISON_P (cond2
)
544 && GET_CODE (cond1
) ==
546 ? reversed_comparison_code (cond2
, NULL
)
548 && XEXP (cond1
, 0) == XEXP (cond2
, 0)
549 && XEXP (cond1
, 1) == XEXP (cond2
, 1))
554 /* Return true if insn1 and insn2 can never depend on one another because
555 the conditions under which they are executed are mutually exclusive. */
557 sched_insns_conditions_mutex_p (const_rtx insn1
, const_rtx insn2
)
560 bool rev1
= false, rev2
= false;
562 /* df doesn't handle conditional lifetimes entirely correctly;
563 calls mess up the conditional lifetimes. */
564 if (!CALL_P (insn1
) && !CALL_P (insn2
))
566 cond1
= sched_get_condition_with_rev (insn1
, &rev1
);
567 cond2
= sched_get_condition_with_rev (insn2
, &rev2
);
569 && conditions_mutex_p (cond1
, cond2
, rev1
, rev2
)
570 /* Make sure first instruction doesn't affect condition of second
571 instruction if switched. */
572 && !modified_in_p (cond1
, insn2
)
573 /* Make sure second instruction doesn't affect condition of first
574 instruction if switched. */
575 && !modified_in_p (cond2
, insn1
))
582 /* Return true if INSN can potentially be speculated with type DS. */
584 sched_insn_is_legitimate_for_speculation_p (const_rtx insn
, ds_t ds
)
586 if (HAS_INTERNAL_DEP (insn
))
589 if (!NONJUMP_INSN_P (insn
))
592 if (SCHED_GROUP_P (insn
))
595 if (IS_SPECULATION_CHECK_P (CONST_CAST_RTX (insn
)))
598 if (side_effects_p (PATTERN (insn
)))
602 /* The following instructions, which depend on a speculatively scheduled
603 instruction, cannot be speculatively scheduled along. */
605 if (may_trap_or_fault_p (PATTERN (insn
)))
606 /* If instruction might fault, it cannot be speculatively scheduled.
607 For control speculation it's obvious why and for data speculation
608 it's because the insn might get wrong input if speculation
609 wasn't successful. */
612 if ((ds
& BE_IN_DATA
)
613 && sched_has_condition_p (insn
))
614 /* If this is a predicated instruction, then it cannot be
615 speculatively scheduled. See PR35659. */
622 /* Initialize LIST_PTR to point to one of the lists present in TYPES_PTR,
623 initialize RESOLVED_P_PTR with true if that list consists of resolved deps,
624 and remove the type of returned [through LIST_PTR] list from TYPES_PTR.
625 This function is used to switch sd_iterator to the next list.
626 !!! For internal use only. Might consider moving it to sched-int.h. */
628 sd_next_list (const_rtx insn
, sd_list_types_def
*types_ptr
,
629 deps_list_t
*list_ptr
, bool *resolved_p_ptr
)
631 sd_list_types_def types
= *types_ptr
;
633 if (types
& SD_LIST_HARD_BACK
)
635 *list_ptr
= INSN_HARD_BACK_DEPS (insn
);
636 *resolved_p_ptr
= false;
637 *types_ptr
= types
& ~SD_LIST_HARD_BACK
;
639 else if (types
& SD_LIST_SPEC_BACK
)
641 *list_ptr
= INSN_SPEC_BACK_DEPS (insn
);
642 *resolved_p_ptr
= false;
643 *types_ptr
= types
& ~SD_LIST_SPEC_BACK
;
645 else if (types
& SD_LIST_FORW
)
647 *list_ptr
= INSN_FORW_DEPS (insn
);
648 *resolved_p_ptr
= false;
649 *types_ptr
= types
& ~SD_LIST_FORW
;
651 else if (types
& SD_LIST_RES_BACK
)
653 *list_ptr
= INSN_RESOLVED_BACK_DEPS (insn
);
654 *resolved_p_ptr
= true;
655 *types_ptr
= types
& ~SD_LIST_RES_BACK
;
657 else if (types
& SD_LIST_RES_FORW
)
659 *list_ptr
= INSN_RESOLVED_FORW_DEPS (insn
);
660 *resolved_p_ptr
= true;
661 *types_ptr
= types
& ~SD_LIST_RES_FORW
;
666 *resolved_p_ptr
= false;
667 *types_ptr
= SD_LIST_NONE
;
671 /* Return the summary size of INSN's lists defined by LIST_TYPES. */
673 sd_lists_size (const_rtx insn
, sd_list_types_def list_types
)
677 while (list_types
!= SD_LIST_NONE
)
682 sd_next_list (insn
, &list_types
, &list
, &resolved_p
);
684 size
+= DEPS_LIST_N_LINKS (list
);
690 /* Return true if INSN's lists defined by LIST_TYPES are all empty. */
693 sd_lists_empty_p (const_rtx insn
, sd_list_types_def list_types
)
695 while (list_types
!= SD_LIST_NONE
)
700 sd_next_list (insn
, &list_types
, &list
, &resolved_p
);
701 if (!deps_list_empty_p (list
))
708 /* Initialize data for INSN. */
710 sd_init_insn (rtx insn
)
712 INSN_HARD_BACK_DEPS (insn
) = create_deps_list ();
713 INSN_SPEC_BACK_DEPS (insn
) = create_deps_list ();
714 INSN_RESOLVED_BACK_DEPS (insn
) = create_deps_list ();
715 INSN_FORW_DEPS (insn
) = create_deps_list ();
716 INSN_RESOLVED_FORW_DEPS (insn
) = create_deps_list ();
718 /* ??? It would be nice to allocate dependency caches here. */
721 /* Free data for INSN. */
723 sd_finish_insn (rtx insn
)
725 /* ??? It would be nice to deallocate dependency caches here. */
727 free_deps_list (INSN_HARD_BACK_DEPS (insn
));
728 INSN_HARD_BACK_DEPS (insn
) = NULL
;
730 free_deps_list (INSN_SPEC_BACK_DEPS (insn
));
731 INSN_SPEC_BACK_DEPS (insn
) = NULL
;
733 free_deps_list (INSN_RESOLVED_BACK_DEPS (insn
));
734 INSN_RESOLVED_BACK_DEPS (insn
) = NULL
;
736 free_deps_list (INSN_FORW_DEPS (insn
));
737 INSN_FORW_DEPS (insn
) = NULL
;
739 free_deps_list (INSN_RESOLVED_FORW_DEPS (insn
));
740 INSN_RESOLVED_FORW_DEPS (insn
) = NULL
;
743 /* Find a dependency between producer PRO and consumer CON.
744 Search through resolved dependency lists if RESOLVED_P is true.
745 If no such dependency is found return NULL,
746 otherwise return the dependency and initialize SD_IT_PTR [if it is nonnull]
747 with an iterator pointing to it. */
749 sd_find_dep_between_no_cache (rtx pro
, rtx con
, bool resolved_p
,
750 sd_iterator_def
*sd_it_ptr
)
752 sd_list_types_def pro_list_type
;
753 sd_list_types_def con_list_type
;
754 sd_iterator_def sd_it
;
756 bool found_p
= false;
760 pro_list_type
= SD_LIST_RES_FORW
;
761 con_list_type
= SD_LIST_RES_BACK
;
765 pro_list_type
= SD_LIST_FORW
;
766 con_list_type
= SD_LIST_BACK
;
769 /* Walk through either back list of INSN or forw list of ELEM
770 depending on which one is shorter. */
771 if (sd_lists_size (con
, con_list_type
) < sd_lists_size (pro
, pro_list_type
))
773 /* Find the dep_link with producer PRO in consumer's back_deps. */
774 FOR_EACH_DEP (con
, con_list_type
, sd_it
, dep
)
775 if (DEP_PRO (dep
) == pro
)
783 /* Find the dep_link with consumer CON in producer's forw_deps. */
784 FOR_EACH_DEP (pro
, pro_list_type
, sd_it
, dep
)
785 if (DEP_CON (dep
) == con
)
794 if (sd_it_ptr
!= NULL
)
803 /* Find a dependency between producer PRO and consumer CON.
804 Use dependency [if available] to check if dependency is present at all.
805 Search through resolved dependency lists if RESOLVED_P is true.
806 If the dependency or NULL if none found. */
808 sd_find_dep_between (rtx pro
, rtx con
, bool resolved_p
)
810 if (true_dependency_cache
!= NULL
)
811 /* Avoiding the list walk below can cut compile times dramatically
814 int elem_luid
= INSN_LUID (pro
);
815 int insn_luid
= INSN_LUID (con
);
817 gcc_assert (output_dependency_cache
!= NULL
818 && anti_dependency_cache
!= NULL
);
820 if (!bitmap_bit_p (&true_dependency_cache
[insn_luid
], elem_luid
)
821 && !bitmap_bit_p (&output_dependency_cache
[insn_luid
], elem_luid
)
822 && !bitmap_bit_p (&anti_dependency_cache
[insn_luid
], elem_luid
))
826 return sd_find_dep_between_no_cache (pro
, con
, resolved_p
, NULL
);
829 /* Add or update a dependence described by DEP.
830 MEM1 and MEM2, if non-null, correspond to memory locations in case of
833 The function returns a value indicating if an old entry has been changed
834 or a new entry has been added to insn's backward deps.
836 This function merely checks if producer and consumer is the same insn
837 and doesn't create a dep in this case. Actual manipulation of
838 dependence data structures is performed in add_or_update_dep_1. */
839 static enum DEPS_ADJUST_RESULT
840 maybe_add_or_update_dep_1 (dep_t dep
, bool resolved_p
, rtx mem1
, rtx mem2
)
842 rtx elem
= DEP_PRO (dep
);
843 rtx insn
= DEP_CON (dep
);
845 gcc_assert (INSN_P (insn
) && INSN_P (elem
));
847 /* Don't depend an insn on itself. */
850 if (sched_deps_info
->generate_spec_deps
)
851 /* INSN has an internal dependence, which we can't overcome. */
852 HAS_INTERNAL_DEP (insn
) = 1;
857 return add_or_update_dep_1 (dep
, resolved_p
, mem1
, mem2
);
860 /* Ask dependency caches what needs to be done for dependence DEP.
861 Return DEP_CREATED if new dependence should be created and there is no
862 need to try to find one searching the dependencies lists.
863 Return DEP_PRESENT if there already is a dependence described by DEP and
864 hence nothing is to be done.
865 Return DEP_CHANGED if there already is a dependence, but it should be
866 updated to incorporate additional information from DEP. */
867 static enum DEPS_ADJUST_RESULT
868 ask_dependency_caches (dep_t dep
)
870 int elem_luid
= INSN_LUID (DEP_PRO (dep
));
871 int insn_luid
= INSN_LUID (DEP_CON (dep
));
873 gcc_assert (true_dependency_cache
!= NULL
874 && output_dependency_cache
!= NULL
875 && anti_dependency_cache
!= NULL
);
877 if (!(current_sched_info
->flags
& USE_DEPS_LIST
))
879 enum reg_note present_dep_type
;
881 if (bitmap_bit_p (&true_dependency_cache
[insn_luid
], elem_luid
))
882 present_dep_type
= REG_DEP_TRUE
;
883 else if (bitmap_bit_p (&output_dependency_cache
[insn_luid
], elem_luid
))
884 present_dep_type
= REG_DEP_OUTPUT
;
885 else if (bitmap_bit_p (&anti_dependency_cache
[insn_luid
], elem_luid
))
886 present_dep_type
= REG_DEP_ANTI
;
888 /* There is no existing dep so it should be created. */
891 if ((int) DEP_TYPE (dep
) >= (int) present_dep_type
)
892 /* DEP does not add anything to the existing dependence. */
897 ds_t present_dep_types
= 0;
899 if (bitmap_bit_p (&true_dependency_cache
[insn_luid
], elem_luid
))
900 present_dep_types
|= DEP_TRUE
;
901 if (bitmap_bit_p (&output_dependency_cache
[insn_luid
], elem_luid
))
902 present_dep_types
|= DEP_OUTPUT
;
903 if (bitmap_bit_p (&anti_dependency_cache
[insn_luid
], elem_luid
))
904 present_dep_types
|= DEP_ANTI
;
906 if (present_dep_types
== 0)
907 /* There is no existing dep so it should be created. */
910 if (!(current_sched_info
->flags
& DO_SPECULATION
)
911 || !bitmap_bit_p (&spec_dependency_cache
[insn_luid
], elem_luid
))
913 if ((present_dep_types
| (DEP_STATUS (dep
) & DEP_TYPES
))
914 == present_dep_types
)
915 /* DEP does not add anything to the existing dependence. */
920 /* Only true dependencies can be data speculative and
921 only anti dependencies can be control speculative. */
922 gcc_assert ((present_dep_types
& (DEP_TRUE
| DEP_ANTI
))
923 == present_dep_types
);
925 /* if (DEP is SPECULATIVE) then
926 ..we should update DEP_STATUS
928 ..we should reset existing dep to non-speculative. */
935 /* Set dependency caches according to DEP. */
937 set_dependency_caches (dep_t dep
)
939 int elem_luid
= INSN_LUID (DEP_PRO (dep
));
940 int insn_luid
= INSN_LUID (DEP_CON (dep
));
942 if (!(current_sched_info
->flags
& USE_DEPS_LIST
))
944 switch (DEP_TYPE (dep
))
947 bitmap_set_bit (&true_dependency_cache
[insn_luid
], elem_luid
);
951 bitmap_set_bit (&output_dependency_cache
[insn_luid
], elem_luid
);
955 bitmap_set_bit (&anti_dependency_cache
[insn_luid
], elem_luid
);
964 ds_t ds
= DEP_STATUS (dep
);
967 bitmap_set_bit (&true_dependency_cache
[insn_luid
], elem_luid
);
969 bitmap_set_bit (&output_dependency_cache
[insn_luid
], elem_luid
);
971 bitmap_set_bit (&anti_dependency_cache
[insn_luid
], elem_luid
);
973 if (ds
& SPECULATIVE
)
975 gcc_assert (current_sched_info
->flags
& DO_SPECULATION
);
976 bitmap_set_bit (&spec_dependency_cache
[insn_luid
], elem_luid
);
981 /* Type of dependence DEP have changed from OLD_TYPE. Update dependency
982 caches accordingly. */
984 update_dependency_caches (dep_t dep
, enum reg_note old_type
)
986 int elem_luid
= INSN_LUID (DEP_PRO (dep
));
987 int insn_luid
= INSN_LUID (DEP_CON (dep
));
989 /* Clear corresponding cache entry because type of the link
990 may have changed. Keep them if we use_deps_list. */
991 if (!(current_sched_info
->flags
& USE_DEPS_LIST
))
996 bitmap_clear_bit (&output_dependency_cache
[insn_luid
], elem_luid
);
1000 bitmap_clear_bit (&anti_dependency_cache
[insn_luid
], elem_luid
);
1008 set_dependency_caches (dep
);
1011 /* Convert a dependence pointed to by SD_IT to be non-speculative. */
1013 change_spec_dep_to_hard (sd_iterator_def sd_it
)
1015 dep_node_t node
= DEP_LINK_NODE (*sd_it
.linkp
);
1016 dep_link_t link
= DEP_NODE_BACK (node
);
1017 dep_t dep
= DEP_NODE_DEP (node
);
1018 rtx elem
= DEP_PRO (dep
);
1019 rtx insn
= DEP_CON (dep
);
1021 move_dep_link (link
, INSN_SPEC_BACK_DEPS (insn
), INSN_HARD_BACK_DEPS (insn
));
1023 DEP_STATUS (dep
) &= ~SPECULATIVE
;
1025 if (true_dependency_cache
!= NULL
)
1026 /* Clear the cache entry. */
1027 bitmap_clear_bit (&spec_dependency_cache
[INSN_LUID (insn
)],
1031 /* Update DEP to incorporate information from NEW_DEP.
1032 SD_IT points to DEP in case it should be moved to another list.
1033 MEM1 and MEM2, if nonnull, correspond to memory locations in case if
1034 data-speculative dependence should be updated. */
1035 static enum DEPS_ADJUST_RESULT
1036 update_dep (dep_t dep
, dep_t new_dep
,
1037 sd_iterator_def sd_it ATTRIBUTE_UNUSED
,
1038 rtx mem1 ATTRIBUTE_UNUSED
,
1039 rtx mem2 ATTRIBUTE_UNUSED
)
1041 enum DEPS_ADJUST_RESULT res
= DEP_PRESENT
;
1042 enum reg_note old_type
= DEP_TYPE (dep
);
1044 /* If this is a more restrictive type of dependence than the
1045 existing one, then change the existing dependence to this
1047 if ((int) DEP_TYPE (new_dep
) < (int) old_type
)
1049 DEP_TYPE (dep
) = DEP_TYPE (new_dep
);
1053 if (current_sched_info
->flags
& USE_DEPS_LIST
)
1054 /* Update DEP_STATUS. */
1056 ds_t dep_status
= DEP_STATUS (dep
);
1057 ds_t ds
= DEP_STATUS (new_dep
);
1058 ds_t new_status
= ds
| dep_status
;
1060 if (new_status
& SPECULATIVE
)
1061 /* Either existing dep or a dep we're adding or both are
1064 if (!(ds
& SPECULATIVE
)
1065 || !(dep_status
& SPECULATIVE
))
1066 /* The new dep can't be speculative. */
1068 new_status
&= ~SPECULATIVE
;
1070 if (dep_status
& SPECULATIVE
)
1071 /* The old dep was speculative, but now it
1073 change_spec_dep_to_hard (sd_it
);
1077 /* Both are speculative. Merge probabilities. */
1082 dw
= estimate_dep_weak (mem1
, mem2
);
1083 ds
= set_dep_weak (ds
, BEGIN_DATA
, dw
);
1086 new_status
= ds_merge (dep_status
, ds
);
1092 if (dep_status
!= ds
)
1094 DEP_STATUS (dep
) = ds
;
1099 if (true_dependency_cache
!= NULL
1100 && res
== DEP_CHANGED
)
1101 update_dependency_caches (dep
, old_type
);
1106 /* Add or update a dependence described by DEP.
1107 MEM1 and MEM2, if non-null, correspond to memory locations in case of
1110 The function returns a value indicating if an old entry has been changed
1111 or a new entry has been added to insn's backward deps or nothing has
1112 been updated at all. */
1113 static enum DEPS_ADJUST_RESULT
1114 add_or_update_dep_1 (dep_t new_dep
, bool resolved_p
,
1115 rtx mem1 ATTRIBUTE_UNUSED
, rtx mem2 ATTRIBUTE_UNUSED
)
1117 bool maybe_present_p
= true;
1118 bool present_p
= false;
1120 gcc_assert (INSN_P (DEP_PRO (new_dep
)) && INSN_P (DEP_CON (new_dep
))
1121 && DEP_PRO (new_dep
) != DEP_CON (new_dep
));
1123 #ifdef ENABLE_CHECKING
1124 check_dep (new_dep
, mem1
!= NULL
);
1127 if (true_dependency_cache
!= NULL
)
1129 switch (ask_dependency_caches (new_dep
))
1135 maybe_present_p
= true;
1140 maybe_present_p
= false;
1150 /* Check that we don't already have this dependence. */
1151 if (maybe_present_p
)
1154 sd_iterator_def sd_it
;
1156 gcc_assert (true_dependency_cache
== NULL
|| present_p
);
1158 present_dep
= sd_find_dep_between_no_cache (DEP_PRO (new_dep
),
1160 resolved_p
, &sd_it
);
1162 if (present_dep
!= NULL
)
1163 /* We found an existing dependency between ELEM and INSN. */
1164 return update_dep (present_dep
, new_dep
, sd_it
, mem1
, mem2
);
1166 /* We didn't find a dep, it shouldn't present in the cache. */
1167 gcc_assert (!present_p
);
1170 /* Might want to check one level of transitivity to save conses.
1171 This check should be done in maybe_add_or_update_dep_1.
1172 Since we made it to add_or_update_dep_1, we must create
1173 (or update) a link. */
1175 if (mem1
!= NULL_RTX
)
1177 gcc_assert (sched_deps_info
->generate_spec_deps
);
1178 DEP_STATUS (new_dep
) = set_dep_weak (DEP_STATUS (new_dep
), BEGIN_DATA
,
1179 estimate_dep_weak (mem1
, mem2
));
1182 sd_add_dep (new_dep
, resolved_p
);
1187 /* Initialize BACK_LIST_PTR with consumer's backward list and
1188 FORW_LIST_PTR with producer's forward list. If RESOLVED_P is true
1189 initialize with lists that hold resolved deps. */
1191 get_back_and_forw_lists (dep_t dep
, bool resolved_p
,
1192 deps_list_t
*back_list_ptr
,
1193 deps_list_t
*forw_list_ptr
)
1195 rtx con
= DEP_CON (dep
);
1199 if ((current_sched_info
->flags
& DO_SPECULATION
)
1200 && (DEP_STATUS (dep
) & SPECULATIVE
))
1201 *back_list_ptr
= INSN_SPEC_BACK_DEPS (con
);
1203 *back_list_ptr
= INSN_HARD_BACK_DEPS (con
);
1205 *forw_list_ptr
= INSN_FORW_DEPS (DEP_PRO (dep
));
1209 *back_list_ptr
= INSN_RESOLVED_BACK_DEPS (con
);
1210 *forw_list_ptr
= INSN_RESOLVED_FORW_DEPS (DEP_PRO (dep
));
1214 /* Add dependence described by DEP.
1215 If RESOLVED_P is true treat the dependence as a resolved one. */
1217 sd_add_dep (dep_t dep
, bool resolved_p
)
1219 dep_node_t n
= create_dep_node ();
1220 deps_list_t con_back_deps
;
1221 deps_list_t pro_forw_deps
;
1222 rtx elem
= DEP_PRO (dep
);
1223 rtx insn
= DEP_CON (dep
);
1225 gcc_assert (INSN_P (insn
) && INSN_P (elem
) && insn
!= elem
);
1227 if ((current_sched_info
->flags
& DO_SPECULATION
)
1228 && !sched_insn_is_legitimate_for_speculation_p (insn
, DEP_STATUS (dep
)))
1229 DEP_STATUS (dep
) &= ~SPECULATIVE
;
1231 copy_dep (DEP_NODE_DEP (n
), dep
);
1233 get_back_and_forw_lists (dep
, resolved_p
, &con_back_deps
, &pro_forw_deps
);
1235 add_to_deps_list (DEP_NODE_BACK (n
), con_back_deps
);
1237 #ifdef ENABLE_CHECKING
1238 check_dep (dep
, false);
1241 add_to_deps_list (DEP_NODE_FORW (n
), pro_forw_deps
);
1243 /* If we are adding a dependency to INSN's LOG_LINKs, then note that
1244 in the bitmap caches of dependency information. */
1245 if (true_dependency_cache
!= NULL
)
1246 set_dependency_caches (dep
);
1249 /* Add or update backward dependence between INSN and ELEM
1250 with given type DEP_TYPE and dep_status DS.
1251 This function is a convenience wrapper. */
1252 enum DEPS_ADJUST_RESULT
1253 sd_add_or_update_dep (dep_t dep
, bool resolved_p
)
1255 return add_or_update_dep_1 (dep
, resolved_p
, NULL_RTX
, NULL_RTX
);
1258 /* Resolved dependence pointed to by SD_IT.
1259 SD_IT will advance to the next element. */
1261 sd_resolve_dep (sd_iterator_def sd_it
)
1263 dep_node_t node
= DEP_LINK_NODE (*sd_it
.linkp
);
1264 dep_t dep
= DEP_NODE_DEP (node
);
1265 rtx pro
= DEP_PRO (dep
);
1266 rtx con
= DEP_CON (dep
);
1268 if ((current_sched_info
->flags
& DO_SPECULATION
)
1269 && (DEP_STATUS (dep
) & SPECULATIVE
))
1270 move_dep_link (DEP_NODE_BACK (node
), INSN_SPEC_BACK_DEPS (con
),
1271 INSN_RESOLVED_BACK_DEPS (con
));
1273 move_dep_link (DEP_NODE_BACK (node
), INSN_HARD_BACK_DEPS (con
),
1274 INSN_RESOLVED_BACK_DEPS (con
));
1276 move_dep_link (DEP_NODE_FORW (node
), INSN_FORW_DEPS (pro
),
1277 INSN_RESOLVED_FORW_DEPS (pro
));
1280 /* Make TO depend on all the FROM's producers.
1281 If RESOLVED_P is true add dependencies to the resolved lists. */
1283 sd_copy_back_deps (rtx to
, rtx from
, bool resolved_p
)
1285 sd_list_types_def list_type
;
1286 sd_iterator_def sd_it
;
1289 list_type
= resolved_p
? SD_LIST_RES_BACK
: SD_LIST_BACK
;
1291 FOR_EACH_DEP (from
, list_type
, sd_it
, dep
)
1293 dep_def _new_dep
, *new_dep
= &_new_dep
;
1295 copy_dep (new_dep
, dep
);
1296 DEP_CON (new_dep
) = to
;
1297 sd_add_dep (new_dep
, resolved_p
);
1301 /* Remove a dependency referred to by SD_IT.
1302 SD_IT will point to the next dependence after removal. */
1304 sd_delete_dep (sd_iterator_def sd_it
)
1306 dep_node_t n
= DEP_LINK_NODE (*sd_it
.linkp
);
1307 dep_t dep
= DEP_NODE_DEP (n
);
1308 rtx pro
= DEP_PRO (dep
);
1309 rtx con
= DEP_CON (dep
);
1310 deps_list_t con_back_deps
;
1311 deps_list_t pro_forw_deps
;
1313 if (true_dependency_cache
!= NULL
)
1315 int elem_luid
= INSN_LUID (pro
);
1316 int insn_luid
= INSN_LUID (con
);
1318 bitmap_clear_bit (&true_dependency_cache
[insn_luid
], elem_luid
);
1319 bitmap_clear_bit (&anti_dependency_cache
[insn_luid
], elem_luid
);
1320 bitmap_clear_bit (&output_dependency_cache
[insn_luid
], elem_luid
);
1322 if (current_sched_info
->flags
& DO_SPECULATION
)
1323 bitmap_clear_bit (&spec_dependency_cache
[insn_luid
], elem_luid
);
1326 get_back_and_forw_lists (dep
, sd_it
.resolved_p
,
1327 &con_back_deps
, &pro_forw_deps
);
1329 remove_from_deps_list (DEP_NODE_BACK (n
), con_back_deps
);
1330 remove_from_deps_list (DEP_NODE_FORW (n
), pro_forw_deps
);
1332 delete_dep_node (n
);
1335 /* Dump size of the lists. */
1336 #define DUMP_LISTS_SIZE (2)
1338 /* Dump dependencies of the lists. */
1339 #define DUMP_LISTS_DEPS (4)
1341 /* Dump all information about the lists. */
1342 #define DUMP_LISTS_ALL (DUMP_LISTS_SIZE | DUMP_LISTS_DEPS)
1344 /* Dump deps_lists of INSN specified by TYPES to DUMP.
1345 FLAGS is a bit mask specifying what information about the lists needs
1347 If FLAGS has the very first bit set, then dump all information about
1348 the lists and propagate this bit into the callee dump functions. */
1350 dump_lists (FILE *dump
, rtx insn
, sd_list_types_def types
, int flags
)
1352 sd_iterator_def sd_it
;
1359 flags
|= DUMP_LISTS_ALL
;
1361 fprintf (dump
, "[");
1363 if (flags
& DUMP_LISTS_SIZE
)
1364 fprintf (dump
, "%d; ", sd_lists_size (insn
, types
));
1366 if (flags
& DUMP_LISTS_DEPS
)
1368 FOR_EACH_DEP (insn
, types
, sd_it
, dep
)
1370 dump_dep (dump
, dep
, dump_dep_flags
| all
);
1371 fprintf (dump
, " ");
1376 /* Dump all information about deps_lists of INSN specified by TYPES
1379 sd_debug_lists (rtx insn
, sd_list_types_def types
)
1381 dump_lists (stderr
, insn
, types
, 1);
1382 fprintf (stderr
, "\n");
1385 /* A convenience wrapper to operate on an entire list. */
1388 add_dependence_list (rtx insn
, rtx list
, int uncond
, enum reg_note dep_type
)
1390 for (; list
; list
= XEXP (list
, 1))
1392 if (uncond
|| ! sched_insns_conditions_mutex_p (insn
, XEXP (list
, 0)))
1393 add_dependence (insn
, XEXP (list
, 0), dep_type
);
1397 /* Similar, but free *LISTP at the same time, when the context
1401 add_dependence_list_and_free (struct deps_desc
*deps
, rtx insn
, rtx
*listp
,
1402 int uncond
, enum reg_note dep_type
)
1406 /* We don't want to short-circuit dependencies involving debug
1407 insns, because they may cause actual dependencies to be
1409 if (deps
->readonly
|| DEBUG_INSN_P (insn
))
1411 add_dependence_list (insn
, *listp
, uncond
, dep_type
);
1415 for (list
= *listp
, *listp
= NULL
; list
; list
= next
)
1417 next
= XEXP (list
, 1);
1418 if (uncond
|| ! sched_insns_conditions_mutex_p (insn
, XEXP (list
, 0)))
1419 add_dependence (insn
, XEXP (list
, 0), dep_type
);
1420 free_INSN_LIST_node (list
);
1424 /* Remove all occurences of INSN from LIST. Return the number of
1425 occurences removed. */
1428 remove_from_dependence_list (rtx insn
, rtx
* listp
)
1434 if (XEXP (*listp
, 0) == insn
)
1436 remove_free_INSN_LIST_node (listp
);
1441 listp
= &XEXP (*listp
, 1);
1447 /* Same as above, but process two lists at once. */
1449 remove_from_both_dependence_lists (rtx insn
, rtx
*listp
, rtx
*exprp
)
1455 if (XEXP (*listp
, 0) == insn
)
1457 remove_free_INSN_LIST_node (listp
);
1458 remove_free_EXPR_LIST_node (exprp
);
1463 listp
= &XEXP (*listp
, 1);
1464 exprp
= &XEXP (*exprp
, 1);
1470 /* Clear all dependencies for an insn. */
1472 delete_all_dependences (rtx insn
)
1474 sd_iterator_def sd_it
;
1477 /* The below cycle can be optimized to clear the caches and back_deps
1478 in one call but that would provoke duplication of code from
1481 for (sd_it
= sd_iterator_start (insn
, SD_LIST_BACK
);
1482 sd_iterator_cond (&sd_it
, &dep
);)
1483 sd_delete_dep (sd_it
);
1486 /* All insns in a scheduling group except the first should only have
1487 dependencies on the previous insn in the group. So we find the
1488 first instruction in the scheduling group by walking the dependence
1489 chains backwards. Then we add the dependencies for the group to
1490 the previous nonnote insn. */
1493 fixup_sched_groups (rtx insn
)
1495 sd_iterator_def sd_it
;
1499 FOR_EACH_DEP (insn
, SD_LIST_BACK
, sd_it
, dep
)
1502 rtx pro
= DEP_PRO (dep
);
1506 i
= prev_nonnote_insn (i
);
1510 } while (SCHED_GROUP_P (i
) || DEBUG_INSN_P (i
));
1512 if (! sched_insns_conditions_mutex_p (i
, pro
))
1513 add_dependence (i
, pro
, DEP_TYPE (dep
));
1517 delete_all_dependences (insn
);
1519 prev_nonnote
= prev_nonnote_nondebug_insn (insn
);
1520 if (BLOCK_FOR_INSN (insn
) == BLOCK_FOR_INSN (prev_nonnote
)
1521 && ! sched_insns_conditions_mutex_p (insn
, prev_nonnote
))
1522 add_dependence (insn
, prev_nonnote
, REG_DEP_ANTI
);
1525 /* Process an insn's memory dependencies. There are four kinds of
1528 (0) read dependence: read follows read
1529 (1) true dependence: read follows write
1530 (2) output dependence: write follows write
1531 (3) anti dependence: write follows read
1533 We are careful to build only dependencies which actually exist, and
1534 use transitivity to avoid building too many links. */
1536 /* Add an INSN and MEM reference pair to a pending INSN_LIST and MEM_LIST.
1537 The MEM is a memory reference contained within INSN, which we are saving
1538 so that we can do memory aliasing on it. */
1541 add_insn_mem_dependence (struct deps_desc
*deps
, bool read_p
,
1548 gcc_assert (!deps
->readonly
);
1551 insn_list
= &deps
->pending_read_insns
;
1552 mem_list
= &deps
->pending_read_mems
;
1553 if (!DEBUG_INSN_P (insn
))
1554 deps
->pending_read_list_length
++;
1558 insn_list
= &deps
->pending_write_insns
;
1559 mem_list
= &deps
->pending_write_mems
;
1560 deps
->pending_write_list_length
++;
1563 link
= alloc_INSN_LIST (insn
, *insn_list
);
1566 if (sched_deps_info
->use_cselib
)
1568 mem
= shallow_copy_rtx (mem
);
1569 XEXP (mem
, 0) = cselib_subst_to_values (XEXP (mem
, 0), GET_MODE (mem
));
1571 link
= alloc_EXPR_LIST (VOIDmode
, canon_rtx (mem
), *mem_list
);
1575 /* Make a dependency between every memory reference on the pending lists
1576 and INSN, thus flushing the pending lists. FOR_READ is true if emitting
1577 dependencies for a read operation, similarly with FOR_WRITE. */
1580 flush_pending_lists (struct deps_desc
*deps
, rtx insn
, int for_read
,
1585 add_dependence_list_and_free (deps
, insn
, &deps
->pending_read_insns
,
1587 if (!deps
->readonly
)
1589 free_EXPR_LIST_list (&deps
->pending_read_mems
);
1590 deps
->pending_read_list_length
= 0;
1594 add_dependence_list_and_free (deps
, insn
, &deps
->pending_write_insns
, 1,
1595 for_read
? REG_DEP_ANTI
: REG_DEP_OUTPUT
);
1597 add_dependence_list_and_free (deps
, insn
,
1598 &deps
->last_pending_memory_flush
, 1,
1599 for_read
? REG_DEP_ANTI
: REG_DEP_OUTPUT
);
1600 if (!deps
->readonly
)
1602 free_EXPR_LIST_list (&deps
->pending_write_mems
);
1603 deps
->pending_write_list_length
= 0;
1605 deps
->last_pending_memory_flush
= alloc_INSN_LIST (insn
, NULL_RTX
);
1606 deps
->pending_flush_length
= 1;
1610 /* Instruction which dependencies we are analyzing. */
1611 static rtx cur_insn
= NULL_RTX
;
1613 /* Implement hooks for haifa scheduler. */
1616 haifa_start_insn (rtx insn
)
1618 gcc_assert (insn
&& !cur_insn
);
1624 haifa_finish_insn (void)
1630 haifa_note_reg_set (int regno
)
1632 SET_REGNO_REG_SET (reg_pending_sets
, regno
);
1636 haifa_note_reg_clobber (int regno
)
1638 SET_REGNO_REG_SET (reg_pending_clobbers
, regno
);
1642 haifa_note_reg_use (int regno
)
1644 SET_REGNO_REG_SET (reg_pending_uses
, regno
);
1648 haifa_note_mem_dep (rtx mem
, rtx pending_mem
, rtx pending_insn
, ds_t ds
)
1650 if (!(ds
& SPECULATIVE
))
1653 pending_mem
= NULL_RTX
;
1656 gcc_assert (ds
& BEGIN_DATA
);
1659 dep_def _dep
, *dep
= &_dep
;
1661 init_dep_1 (dep
, pending_insn
, cur_insn
, ds_to_dt (ds
),
1662 current_sched_info
->flags
& USE_DEPS_LIST
? ds
: -1);
1663 maybe_add_or_update_dep_1 (dep
, false, pending_mem
, mem
);
1669 haifa_note_dep (rtx elem
, ds_t ds
)
1674 init_dep (dep
, elem
, cur_insn
, ds_to_dt (ds
));
1675 maybe_add_or_update_dep_1 (dep
, false, NULL_RTX
, NULL_RTX
);
1679 note_reg_use (int r
)
1681 if (sched_deps_info
->note_reg_use
)
1682 sched_deps_info
->note_reg_use (r
);
1686 note_reg_set (int r
)
1688 if (sched_deps_info
->note_reg_set
)
1689 sched_deps_info
->note_reg_set (r
);
1693 note_reg_clobber (int r
)
1695 if (sched_deps_info
->note_reg_clobber
)
1696 sched_deps_info
->note_reg_clobber (r
);
1700 note_mem_dep (rtx m1
, rtx m2
, rtx e
, ds_t ds
)
1702 if (sched_deps_info
->note_mem_dep
)
1703 sched_deps_info
->note_mem_dep (m1
, m2
, e
, ds
);
1707 note_dep (rtx e
, ds_t ds
)
1709 if (sched_deps_info
->note_dep
)
1710 sched_deps_info
->note_dep (e
, ds
);
1713 /* Return corresponding to DS reg_note. */
1718 return REG_DEP_TRUE
;
1719 else if (ds
& DEP_OUTPUT
)
1720 return REG_DEP_OUTPUT
;
1723 gcc_assert (ds
& DEP_ANTI
);
1724 return REG_DEP_ANTI
;
1730 /* Functions for computation of info needed for register pressure
1731 sensitive insn scheduling. */
1734 /* Allocate and return reg_use_data structure for REGNO and INSN. */
1735 static struct reg_use_data
*
1736 create_insn_reg_use (int regno
, rtx insn
)
1738 struct reg_use_data
*use
;
1740 use
= (struct reg_use_data
*) xmalloc (sizeof (struct reg_use_data
));
1743 use
->next_insn_use
= INSN_REG_USE_LIST (insn
);
1744 INSN_REG_USE_LIST (insn
) = use
;
1748 /* Allocate and return reg_set_data structure for REGNO and INSN. */
1749 static struct reg_set_data
*
1750 create_insn_reg_set (int regno
, rtx insn
)
1752 struct reg_set_data
*set
;
1754 set
= (struct reg_set_data
*) xmalloc (sizeof (struct reg_set_data
));
1757 set
->next_insn_set
= INSN_REG_SET_LIST (insn
);
1758 INSN_REG_SET_LIST (insn
) = set
;
1762 /* Set up insn register uses for INSN and dependency context DEPS. */
1764 setup_insn_reg_uses (struct deps_desc
*deps
, rtx insn
)
1767 reg_set_iterator rsi
;
1769 struct reg_use_data
*use
, *use2
, *next
;
1770 struct deps_reg
*reg_last
;
1772 EXECUTE_IF_SET_IN_REG_SET (reg_pending_uses
, 0, i
, rsi
)
1774 if (i
< FIRST_PSEUDO_REGISTER
1775 && TEST_HARD_REG_BIT (ira_no_alloc_regs
, i
))
1778 if (find_regno_note (insn
, REG_DEAD
, i
) == NULL_RTX
1779 && ! REGNO_REG_SET_P (reg_pending_sets
, i
)
1780 && ! REGNO_REG_SET_P (reg_pending_clobbers
, i
))
1781 /* Ignore use which is not dying. */
1784 use
= create_insn_reg_use (i
, insn
);
1785 use
->next_regno_use
= use
;
1786 reg_last
= &deps
->reg_last
[i
];
1788 /* Create the cycle list of uses. */
1789 for (list
= reg_last
->uses
; list
; list
= XEXP (list
, 1))
1791 use2
= create_insn_reg_use (i
, XEXP (list
, 0));
1792 next
= use
->next_regno_use
;
1793 use
->next_regno_use
= use2
;
1794 use2
->next_regno_use
= next
;
1799 /* Register pressure info for the currently processed insn. */
1800 static struct reg_pressure_data reg_pressure_info
[N_REG_CLASSES
];
1802 /* Return TRUE if INSN has the use structure for REGNO. */
1804 insn_use_p (rtx insn
, int regno
)
1806 struct reg_use_data
*use
;
1808 for (use
= INSN_REG_USE_LIST (insn
); use
!= NULL
; use
= use
->next_insn_use
)
1809 if (use
->regno
== regno
)
1814 /* Update the register pressure info after birth of pseudo register REGNO
1815 in INSN. Arguments CLOBBER_P and UNUSED_P say correspondingly that
1816 the register is in clobber or unused after the insn. */
1818 mark_insn_pseudo_birth (rtx insn
, int regno
, bool clobber_p
, bool unused_p
)
1823 gcc_assert (regno
>= FIRST_PSEUDO_REGISTER
);
1824 cl
= sched_regno_cover_class
[regno
];
1827 incr
= ira_reg_class_nregs
[cl
][PSEUDO_REGNO_MODE (regno
)];
1830 new_incr
= reg_pressure_info
[cl
].clobber_increase
+ incr
;
1831 reg_pressure_info
[cl
].clobber_increase
= new_incr
;
1835 new_incr
= reg_pressure_info
[cl
].unused_set_increase
+ incr
;
1836 reg_pressure_info
[cl
].unused_set_increase
= new_incr
;
1840 new_incr
= reg_pressure_info
[cl
].set_increase
+ incr
;
1841 reg_pressure_info
[cl
].set_increase
= new_incr
;
1842 if (! insn_use_p (insn
, regno
))
1843 reg_pressure_info
[cl
].change
+= incr
;
1844 create_insn_reg_set (regno
, insn
);
1846 gcc_assert (new_incr
< (1 << INCREASE_BITS
));
1850 /* Like mark_insn_pseudo_regno_birth except that NREGS saying how many
1851 hard registers involved in the birth. */
1853 mark_insn_hard_regno_birth (rtx insn
, int regno
, int nregs
,
1854 bool clobber_p
, bool unused_p
)
1857 int new_incr
, last
= regno
+ nregs
;
1859 while (regno
< last
)
1861 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
1862 if (! TEST_HARD_REG_BIT (ira_no_alloc_regs
, regno
))
1864 cl
= sched_regno_cover_class
[regno
];
1869 new_incr
= reg_pressure_info
[cl
].clobber_increase
+ 1;
1870 reg_pressure_info
[cl
].clobber_increase
= new_incr
;
1874 new_incr
= reg_pressure_info
[cl
].unused_set_increase
+ 1;
1875 reg_pressure_info
[cl
].unused_set_increase
= new_incr
;
1879 new_incr
= reg_pressure_info
[cl
].set_increase
+ 1;
1880 reg_pressure_info
[cl
].set_increase
= new_incr
;
1881 if (! insn_use_p (insn
, regno
))
1882 reg_pressure_info
[cl
].change
+= 1;
1883 create_insn_reg_set (regno
, insn
);
1885 gcc_assert (new_incr
< (1 << INCREASE_BITS
));
1892 /* Update the register pressure info after birth of pseudo or hard
1893 register REG in INSN. Arguments CLOBBER_P and UNUSED_P say
1894 correspondingly that the register is in clobber or unused after the
1897 mark_insn_reg_birth (rtx insn
, rtx reg
, bool clobber_p
, bool unused_p
)
1901 if (GET_CODE (reg
) == SUBREG
)
1902 reg
= SUBREG_REG (reg
);
1907 regno
= REGNO (reg
);
1908 if (regno
< FIRST_PSEUDO_REGISTER
)
1909 mark_insn_hard_regno_birth (insn
, regno
,
1910 hard_regno_nregs
[regno
][GET_MODE (reg
)],
1911 clobber_p
, unused_p
);
1913 mark_insn_pseudo_birth (insn
, regno
, clobber_p
, unused_p
);
1916 /* Update the register pressure info after death of pseudo register
1919 mark_pseudo_death (int regno
)
1924 gcc_assert (regno
>= FIRST_PSEUDO_REGISTER
);
1925 cl
= sched_regno_cover_class
[regno
];
1928 incr
= ira_reg_class_nregs
[cl
][PSEUDO_REGNO_MODE (regno
)];
1929 reg_pressure_info
[cl
].change
-= incr
;
1933 /* Like mark_pseudo_death except that NREGS saying how many hard
1934 registers involved in the death. */
1936 mark_hard_regno_death (int regno
, int nregs
)
1939 int last
= regno
+ nregs
;
1941 while (regno
< last
)
1943 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
1944 if (! TEST_HARD_REG_BIT (ira_no_alloc_regs
, regno
))
1946 cl
= sched_regno_cover_class
[regno
];
1948 reg_pressure_info
[cl
].change
-= 1;
1954 /* Update the register pressure info after death of pseudo or hard
1957 mark_reg_death (rtx reg
)
1961 if (GET_CODE (reg
) == SUBREG
)
1962 reg
= SUBREG_REG (reg
);
1967 regno
= REGNO (reg
);
1968 if (regno
< FIRST_PSEUDO_REGISTER
)
1969 mark_hard_regno_death (regno
, hard_regno_nregs
[regno
][GET_MODE (reg
)]);
1971 mark_pseudo_death (regno
);
1974 /* Process SETTER of REG. DATA is an insn containing the setter. */
1976 mark_insn_reg_store (rtx reg
, const_rtx setter
, void *data
)
1978 if (setter
!= NULL_RTX
&& GET_CODE (setter
) != SET
)
1981 ((rtx
) data
, reg
, false,
1982 find_reg_note ((const_rtx
) data
, REG_UNUSED
, reg
) != NULL_RTX
);
1985 /* Like mark_insn_reg_store except notice just CLOBBERs; ignore SETs. */
1987 mark_insn_reg_clobber (rtx reg
, const_rtx setter
, void *data
)
1989 if (GET_CODE (setter
) == CLOBBER
)
1990 mark_insn_reg_birth ((rtx
) data
, reg
, true, false);
1993 /* Set up reg pressure info related to INSN. */
1995 setup_insn_reg_pressure_info (rtx insn
)
1999 static struct reg_pressure_data
*pressure_info
;
2002 gcc_assert (sched_pressure_p
);
2004 if (! INSN_P (insn
))
2007 for (i
= 0; i
< ira_reg_class_cover_size
; i
++)
2009 cl
= ira_reg_class_cover
[i
];
2010 reg_pressure_info
[cl
].clobber_increase
= 0;
2011 reg_pressure_info
[cl
].set_increase
= 0;
2012 reg_pressure_info
[cl
].unused_set_increase
= 0;
2013 reg_pressure_info
[cl
].change
= 0;
2016 note_stores (PATTERN (insn
), mark_insn_reg_clobber
, insn
);
2018 note_stores (PATTERN (insn
), mark_insn_reg_store
, insn
);
2021 for (link
= REG_NOTES (insn
); link
; link
= XEXP (link
, 1))
2022 if (REG_NOTE_KIND (link
) == REG_INC
)
2023 mark_insn_reg_store (XEXP (link
, 0), NULL_RTX
, insn
);
2026 for (link
= REG_NOTES (insn
); link
; link
= XEXP (link
, 1))
2027 if (REG_NOTE_KIND (link
) == REG_DEAD
)
2028 mark_reg_death (XEXP (link
, 0));
2030 len
= sizeof (struct reg_pressure_data
) * ira_reg_class_cover_size
;
2032 = INSN_REG_PRESSURE (insn
) = (struct reg_pressure_data
*) xmalloc (len
);
2033 INSN_MAX_REG_PRESSURE (insn
) = (int *) xcalloc (ira_reg_class_cover_size
2035 for (i
= 0; i
< ira_reg_class_cover_size
; i
++)
2037 cl
= ira_reg_class_cover
[i
];
2038 pressure_info
[i
].clobber_increase
2039 = reg_pressure_info
[cl
].clobber_increase
;
2040 pressure_info
[i
].set_increase
= reg_pressure_info
[cl
].set_increase
;
2041 pressure_info
[i
].unused_set_increase
2042 = reg_pressure_info
[cl
].unused_set_increase
;
2043 pressure_info
[i
].change
= reg_pressure_info
[cl
].change
;
2050 /* Internal variable for sched_analyze_[12] () functions.
2051 If it is nonzero, this means that sched_analyze_[12] looks
2052 at the most toplevel SET. */
2053 static bool can_start_lhs_rhs_p
;
2055 /* Extend reg info for the deps context DEPS given that
2056 we have just generated a register numbered REGNO. */
2058 extend_deps_reg_info (struct deps_desc
*deps
, int regno
)
2060 int max_regno
= regno
+ 1;
2062 gcc_assert (!reload_completed
);
2064 /* In a readonly context, it would not hurt to extend info,
2065 but it should not be needed. */
2066 if (reload_completed
&& deps
->readonly
)
2068 deps
->max_reg
= max_regno
;
2072 if (max_regno
> deps
->max_reg
)
2074 deps
->reg_last
= XRESIZEVEC (struct deps_reg
, deps
->reg_last
,
2076 memset (&deps
->reg_last
[deps
->max_reg
],
2077 0, (max_regno
- deps
->max_reg
)
2078 * sizeof (struct deps_reg
));
2079 deps
->max_reg
= max_regno
;
2083 /* Extends REG_INFO_P if needed. */
2085 maybe_extend_reg_info_p (void)
2087 /* Extend REG_INFO_P, if needed. */
2088 if ((unsigned int)max_regno
- 1 >= reg_info_p_size
)
2090 size_t new_reg_info_p_size
= max_regno
+ 128;
2092 gcc_assert (!reload_completed
&& sel_sched_p ());
2094 reg_info_p
= (struct reg_info_t
*) xrecalloc (reg_info_p
,
2095 new_reg_info_p_size
,
2097 sizeof (*reg_info_p
));
2098 reg_info_p_size
= new_reg_info_p_size
;
2102 /* Analyze a single reference to register (reg:MODE REGNO) in INSN.
2103 The type of the reference is specified by REF and can be SET,
2104 CLOBBER, PRE_DEC, POST_DEC, PRE_INC, POST_INC or USE. */
2107 sched_analyze_reg (struct deps_desc
*deps
, int regno
, enum machine_mode mode
,
2108 enum rtx_code ref
, rtx insn
)
2110 /* We could emit new pseudos in renaming. Extend the reg structures. */
2111 if (!reload_completed
&& sel_sched_p ()
2112 && (regno
>= max_reg_num () - 1 || regno
>= deps
->max_reg
))
2113 extend_deps_reg_info (deps
, regno
);
2115 maybe_extend_reg_info_p ();
2117 /* A hard reg in a wide mode may really be multiple registers.
2118 If so, mark all of them just like the first. */
2119 if (regno
< FIRST_PSEUDO_REGISTER
)
2121 int i
= hard_regno_nregs
[regno
][mode
];
2125 note_reg_set (regno
+ i
);
2127 else if (ref
== USE
)
2130 note_reg_use (regno
+ i
);
2135 note_reg_clobber (regno
+ i
);
2139 /* ??? Reload sometimes emits USEs and CLOBBERs of pseudos that
2140 it does not reload. Ignore these as they have served their
2142 else if (regno
>= deps
->max_reg
)
2144 enum rtx_code code
= GET_CODE (PATTERN (insn
));
2145 gcc_assert (code
== USE
|| code
== CLOBBER
);
2151 note_reg_set (regno
);
2152 else if (ref
== USE
)
2153 note_reg_use (regno
);
2155 note_reg_clobber (regno
);
2157 /* Pseudos that are REG_EQUIV to something may be replaced
2158 by that during reloading. We need only add dependencies for
2159 the address in the REG_EQUIV note. */
2160 if (!reload_completed
&& get_reg_known_equiv_p (regno
))
2162 rtx t
= get_reg_known_value (regno
);
2164 sched_analyze_2 (deps
, XEXP (t
, 0), insn
);
2167 /* Don't let it cross a call after scheduling if it doesn't
2168 already cross one. */
2169 if (REG_N_CALLS_CROSSED (regno
) == 0)
2171 if (!deps
->readonly
&& ref
== USE
&& !DEBUG_INSN_P (insn
))
2172 deps
->sched_before_next_call
2173 = alloc_INSN_LIST (insn
, deps
->sched_before_next_call
);
2175 add_dependence_list (insn
, deps
->last_function_call
, 1,
2181 /* Analyze a single SET, CLOBBER, PRE_DEC, POST_DEC, PRE_INC or POST_INC
2182 rtx, X, creating all dependencies generated by the write to the
2183 destination of X, and reads of everything mentioned. */
2186 sched_analyze_1 (struct deps_desc
*deps
, rtx x
, rtx insn
)
2188 rtx dest
= XEXP (x
, 0);
2189 enum rtx_code code
= GET_CODE (x
);
2190 bool cslr_p
= can_start_lhs_rhs_p
;
2192 can_start_lhs_rhs_p
= false;
2198 if (cslr_p
&& sched_deps_info
->start_lhs
)
2199 sched_deps_info
->start_lhs (dest
);
2201 if (GET_CODE (dest
) == PARALLEL
)
2205 for (i
= XVECLEN (dest
, 0) - 1; i
>= 0; i
--)
2206 if (XEXP (XVECEXP (dest
, 0, i
), 0) != 0)
2207 sched_analyze_1 (deps
,
2208 gen_rtx_CLOBBER (VOIDmode
,
2209 XEXP (XVECEXP (dest
, 0, i
), 0)),
2212 if (cslr_p
&& sched_deps_info
->finish_lhs
)
2213 sched_deps_info
->finish_lhs ();
2217 can_start_lhs_rhs_p
= cslr_p
;
2219 sched_analyze_2 (deps
, SET_SRC (x
), insn
);
2221 can_start_lhs_rhs_p
= false;
2227 while (GET_CODE (dest
) == STRICT_LOW_PART
|| GET_CODE (dest
) == SUBREG
2228 || GET_CODE (dest
) == ZERO_EXTRACT
)
2230 if (GET_CODE (dest
) == STRICT_LOW_PART
2231 || GET_CODE (dest
) == ZERO_EXTRACT
2232 || df_read_modify_subreg_p (dest
))
2234 /* These both read and modify the result. We must handle
2235 them as writes to get proper dependencies for following
2236 instructions. We must handle them as reads to get proper
2237 dependencies from this to previous instructions.
2238 Thus we need to call sched_analyze_2. */
2240 sched_analyze_2 (deps
, XEXP (dest
, 0), insn
);
2242 if (GET_CODE (dest
) == ZERO_EXTRACT
)
2244 /* The second and third arguments are values read by this insn. */
2245 sched_analyze_2 (deps
, XEXP (dest
, 1), insn
);
2246 sched_analyze_2 (deps
, XEXP (dest
, 2), insn
);
2248 dest
= XEXP (dest
, 0);
2253 int regno
= REGNO (dest
);
2254 enum machine_mode mode
= GET_MODE (dest
);
2256 sched_analyze_reg (deps
, regno
, mode
, code
, insn
);
2259 /* Treat all writes to a stack register as modifying the TOS. */
2260 if (regno
>= FIRST_STACK_REG
&& regno
<= LAST_STACK_REG
)
2264 /* Avoid analyzing the same register twice. */
2265 if (regno
!= FIRST_STACK_REG
)
2266 sched_analyze_reg (deps
, FIRST_STACK_REG
, mode
, code
, insn
);
2268 nregs
= hard_regno_nregs
[FIRST_STACK_REG
][mode
];
2269 while (--nregs
>= 0)
2270 SET_HARD_REG_BIT (implicit_reg_pending_uses
,
2271 FIRST_STACK_REG
+ nregs
);
2275 else if (MEM_P (dest
))
2277 /* Writing memory. */
2280 if (sched_deps_info
->use_cselib
)
2282 enum machine_mode address_mode
2283 = targetm
.addr_space
.address_mode (MEM_ADDR_SPACE (dest
));
2285 t
= shallow_copy_rtx (dest
);
2286 cselib_lookup_from_insn (XEXP (t
, 0), address_mode
, 1,
2287 GET_MODE (t
), insn
);
2288 XEXP (t
, 0) = cselib_subst_to_values (XEXP (t
, 0), GET_MODE (t
));
2292 /* Pending lists can't get larger with a readonly context. */
2294 && ((deps
->pending_read_list_length
+ deps
->pending_write_list_length
)
2295 > MAX_PENDING_LIST_LENGTH
))
2297 /* Flush all pending reads and writes to prevent the pending lists
2298 from getting any larger. Insn scheduling runs too slowly when
2299 these lists get long. When compiling GCC with itself,
2300 this flush occurs 8 times for sparc, and 10 times for m88k using
2301 the default value of 32. */
2302 flush_pending_lists (deps
, insn
, false, true);
2306 rtx pending
, pending_mem
;
2308 pending
= deps
->pending_read_insns
;
2309 pending_mem
= deps
->pending_read_mems
;
2312 if (anti_dependence (XEXP (pending_mem
, 0), t
)
2313 && ! sched_insns_conditions_mutex_p (insn
, XEXP (pending
, 0)))
2314 note_mem_dep (t
, XEXP (pending_mem
, 0), XEXP (pending
, 0),
2317 pending
= XEXP (pending
, 1);
2318 pending_mem
= XEXP (pending_mem
, 1);
2321 pending
= deps
->pending_write_insns
;
2322 pending_mem
= deps
->pending_write_mems
;
2325 if (output_dependence (XEXP (pending_mem
, 0), t
)
2326 && ! sched_insns_conditions_mutex_p (insn
, XEXP (pending
, 0)))
2327 note_mem_dep (t
, XEXP (pending_mem
, 0), XEXP (pending
, 0),
2330 pending
= XEXP (pending
, 1);
2331 pending_mem
= XEXP (pending_mem
, 1);
2334 add_dependence_list (insn
, deps
->last_pending_memory_flush
, 1,
2337 if (!deps
->readonly
)
2338 add_insn_mem_dependence (deps
, false, insn
, dest
);
2340 sched_analyze_2 (deps
, XEXP (dest
, 0), insn
);
2343 if (cslr_p
&& sched_deps_info
->finish_lhs
)
2344 sched_deps_info
->finish_lhs ();
2346 /* Analyze reads. */
2347 if (GET_CODE (x
) == SET
)
2349 can_start_lhs_rhs_p
= cslr_p
;
2351 sched_analyze_2 (deps
, SET_SRC (x
), insn
);
2353 can_start_lhs_rhs_p
= false;
2357 /* Analyze the uses of memory and registers in rtx X in INSN. */
2359 sched_analyze_2 (struct deps_desc
*deps
, rtx x
, rtx insn
)
2365 bool cslr_p
= can_start_lhs_rhs_p
;
2367 can_start_lhs_rhs_p
= false;
2373 if (cslr_p
&& sched_deps_info
->start_rhs
)
2374 sched_deps_info
->start_rhs (x
);
2376 code
= GET_CODE (x
);
2387 /* Ignore constants. */
2388 if (cslr_p
&& sched_deps_info
->finish_rhs
)
2389 sched_deps_info
->finish_rhs ();
2395 /* User of CC0 depends on immediately preceding insn. */
2396 SCHED_GROUP_P (insn
) = 1;
2397 /* Don't move CC0 setter to another block (it can set up the
2398 same flag for previous CC0 users which is safe). */
2399 CANT_MOVE (prev_nonnote_insn (insn
)) = 1;
2401 if (cslr_p
&& sched_deps_info
->finish_rhs
)
2402 sched_deps_info
->finish_rhs ();
2409 int regno
= REGNO (x
);
2410 enum machine_mode mode
= GET_MODE (x
);
2412 sched_analyze_reg (deps
, regno
, mode
, USE
, insn
);
2415 /* Treat all reads of a stack register as modifying the TOS. */
2416 if (regno
>= FIRST_STACK_REG
&& regno
<= LAST_STACK_REG
)
2418 /* Avoid analyzing the same register twice. */
2419 if (regno
!= FIRST_STACK_REG
)
2420 sched_analyze_reg (deps
, FIRST_STACK_REG
, mode
, USE
, insn
);
2421 sched_analyze_reg (deps
, FIRST_STACK_REG
, mode
, SET
, insn
);
2425 if (cslr_p
&& sched_deps_info
->finish_rhs
)
2426 sched_deps_info
->finish_rhs ();
2433 /* Reading memory. */
2435 rtx pending
, pending_mem
;
2438 if (sched_deps_info
->use_cselib
)
2440 enum machine_mode address_mode
2441 = targetm
.addr_space
.address_mode (MEM_ADDR_SPACE (t
));
2443 t
= shallow_copy_rtx (t
);
2444 cselib_lookup_from_insn (XEXP (t
, 0), address_mode
, 1,
2445 GET_MODE (t
), insn
);
2446 XEXP (t
, 0) = cselib_subst_to_values (XEXP (t
, 0), GET_MODE (t
));
2449 if (!DEBUG_INSN_P (insn
))
2452 pending
= deps
->pending_read_insns
;
2453 pending_mem
= deps
->pending_read_mems
;
2456 if (read_dependence (XEXP (pending_mem
, 0), t
)
2457 && ! sched_insns_conditions_mutex_p (insn
,
2459 note_mem_dep (t
, XEXP (pending_mem
, 0), XEXP (pending
, 0),
2462 pending
= XEXP (pending
, 1);
2463 pending_mem
= XEXP (pending_mem
, 1);
2466 pending
= deps
->pending_write_insns
;
2467 pending_mem
= deps
->pending_write_mems
;
2470 if (true_dependence (XEXP (pending_mem
, 0), VOIDmode
,
2472 && ! sched_insns_conditions_mutex_p (insn
,
2474 note_mem_dep (t
, XEXP (pending_mem
, 0), XEXP (pending
, 0),
2475 sched_deps_info
->generate_spec_deps
2476 ? BEGIN_DATA
| DEP_TRUE
: DEP_TRUE
);
2478 pending
= XEXP (pending
, 1);
2479 pending_mem
= XEXP (pending_mem
, 1);
2482 for (u
= deps
->last_pending_memory_flush
; u
; u
= XEXP (u
, 1))
2484 if (! NON_FLUSH_JUMP_P (u
))
2485 add_dependence (insn
, XEXP (u
, 0), REG_DEP_ANTI
);
2486 else if (deps_may_trap_p (x
))
2488 if ((sched_deps_info
->generate_spec_deps
)
2489 && sel_sched_p () && (spec_info
->mask
& BEGIN_CONTROL
))
2491 ds_t ds
= set_dep_weak (DEP_ANTI
, BEGIN_CONTROL
,
2494 note_dep (XEXP (u
, 0), ds
);
2497 add_dependence (insn
, XEXP (u
, 0), REG_DEP_ANTI
);
2502 /* Always add these dependencies to pending_reads, since
2503 this insn may be followed by a write. */
2504 if (!deps
->readonly
)
2505 add_insn_mem_dependence (deps
, true, insn
, x
);
2507 sched_analyze_2 (deps
, XEXP (x
, 0), insn
);
2509 if (cslr_p
&& sched_deps_info
->finish_rhs
)
2510 sched_deps_info
->finish_rhs ();
2515 /* Force pending stores to memory in case a trap handler needs them. */
2517 flush_pending_lists (deps
, insn
, true, false);
2521 if (PREFETCH_SCHEDULE_BARRIER_P (x
))
2522 reg_pending_barrier
= TRUE_BARRIER
;
2525 case UNSPEC_VOLATILE
:
2526 flush_pending_lists (deps
, insn
, true, true);
2532 /* Traditional and volatile asm instructions must be considered to use
2533 and clobber all hard registers, all pseudo-registers and all of
2534 memory. So must TRAP_IF and UNSPEC_VOLATILE operations.
2536 Consider for instance a volatile asm that changes the fpu rounding
2537 mode. An insn should not be moved across this even if it only uses
2538 pseudo-regs because it might give an incorrectly rounded result. */
2539 if (code
!= ASM_OPERANDS
|| MEM_VOLATILE_P (x
))
2540 reg_pending_barrier
= TRUE_BARRIER
;
2542 /* For all ASM_OPERANDS, we must traverse the vector of input operands.
2543 We can not just fall through here since then we would be confused
2544 by the ASM_INPUT rtx inside ASM_OPERANDS, which do not indicate
2545 traditional asms unlike their normal usage. */
2547 if (code
== ASM_OPERANDS
)
2549 for (j
= 0; j
< ASM_OPERANDS_INPUT_LENGTH (x
); j
++)
2550 sched_analyze_2 (deps
, ASM_OPERANDS_INPUT (x
, j
), insn
);
2552 if (cslr_p
&& sched_deps_info
->finish_rhs
)
2553 sched_deps_info
->finish_rhs ();
2564 /* These both read and modify the result. We must handle them as writes
2565 to get proper dependencies for following instructions. We must handle
2566 them as reads to get proper dependencies from this to previous
2567 instructions. Thus we need to pass them to both sched_analyze_1
2568 and sched_analyze_2. We must call sched_analyze_2 first in order
2569 to get the proper antecedent for the read. */
2570 sched_analyze_2 (deps
, XEXP (x
, 0), insn
);
2571 sched_analyze_1 (deps
, x
, insn
);
2573 if (cslr_p
&& sched_deps_info
->finish_rhs
)
2574 sched_deps_info
->finish_rhs ();
2580 /* op0 = op0 + op1 */
2581 sched_analyze_2 (deps
, XEXP (x
, 0), insn
);
2582 sched_analyze_2 (deps
, XEXP (x
, 1), insn
);
2583 sched_analyze_1 (deps
, x
, insn
);
2585 if (cslr_p
&& sched_deps_info
->finish_rhs
)
2586 sched_deps_info
->finish_rhs ();
2594 /* Other cases: walk the insn. */
2595 fmt
= GET_RTX_FORMAT (code
);
2596 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2599 sched_analyze_2 (deps
, XEXP (x
, i
), insn
);
2600 else if (fmt
[i
] == 'E')
2601 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2602 sched_analyze_2 (deps
, XVECEXP (x
, i
, j
), insn
);
2605 if (cslr_p
&& sched_deps_info
->finish_rhs
)
2606 sched_deps_info
->finish_rhs ();
2609 /* Analyze an INSN with pattern X to find all dependencies. */
2611 sched_analyze_insn (struct deps_desc
*deps
, rtx x
, rtx insn
)
2613 RTX_CODE code
= GET_CODE (x
);
2616 reg_set_iterator rsi
;
2618 if (! reload_completed
)
2622 extract_insn (insn
);
2623 preprocess_constraints ();
2624 ira_implicitly_set_insn_hard_regs (&temp
);
2625 AND_COMPL_HARD_REG_SET (temp
, ira_no_alloc_regs
);
2626 IOR_HARD_REG_SET (implicit_reg_pending_clobbers
, temp
);
2629 can_start_lhs_rhs_p
= (NONJUMP_INSN_P (insn
)
2633 /* Avoid moving trapping instructions accross function calls that might
2634 not always return. */
2635 add_dependence_list (insn
, deps
->last_function_call_may_noreturn
,
2638 if (code
== COND_EXEC
)
2640 sched_analyze_2 (deps
, COND_EXEC_TEST (x
), insn
);
2642 /* ??? Should be recording conditions so we reduce the number of
2643 false dependencies. */
2644 x
= COND_EXEC_CODE (x
);
2645 code
= GET_CODE (x
);
2647 if (code
== SET
|| code
== CLOBBER
)
2649 sched_analyze_1 (deps
, x
, insn
);
2651 /* Bare clobber insns are used for letting life analysis, reg-stack
2652 and others know that a value is dead. Depend on the last call
2653 instruction so that reg-stack won't get confused. */
2654 if (code
== CLOBBER
)
2655 add_dependence_list (insn
, deps
->last_function_call
, 1,
2658 else if (code
== PARALLEL
)
2660 for (i
= XVECLEN (x
, 0); i
--;)
2662 rtx sub
= XVECEXP (x
, 0, i
);
2663 code
= GET_CODE (sub
);
2665 if (code
== COND_EXEC
)
2667 sched_analyze_2 (deps
, COND_EXEC_TEST (sub
), insn
);
2668 sub
= COND_EXEC_CODE (sub
);
2669 code
= GET_CODE (sub
);
2671 if (code
== SET
|| code
== CLOBBER
)
2672 sched_analyze_1 (deps
, sub
, insn
);
2674 sched_analyze_2 (deps
, sub
, insn
);
2678 sched_analyze_2 (deps
, x
, insn
);
2680 /* Mark registers CLOBBERED or used by called function. */
2683 for (link
= CALL_INSN_FUNCTION_USAGE (insn
); link
; link
= XEXP (link
, 1))
2685 if (GET_CODE (XEXP (link
, 0)) == CLOBBER
)
2686 sched_analyze_1 (deps
, XEXP (link
, 0), insn
);
2688 sched_analyze_2 (deps
, XEXP (link
, 0), insn
);
2690 /* Don't schedule anything after a tail call, tail call needs
2691 to use at least all call-saved registers. */
2692 if (SIBLING_CALL_P (insn
))
2693 reg_pending_barrier
= TRUE_BARRIER
;
2694 else if (find_reg_note (insn
, REG_SETJMP
, NULL
))
2695 reg_pending_barrier
= MOVE_BARRIER
;
2701 next
= next_nonnote_nondebug_insn (insn
);
2702 if (next
&& BARRIER_P (next
))
2703 reg_pending_barrier
= MOVE_BARRIER
;
2706 rtx pending
, pending_mem
;
2708 if (sched_deps_info
->compute_jump_reg_dependencies
)
2710 regset_head tmp_uses
, tmp_sets
;
2711 INIT_REG_SET (&tmp_uses
);
2712 INIT_REG_SET (&tmp_sets
);
2714 (*sched_deps_info
->compute_jump_reg_dependencies
)
2715 (insn
, &deps
->reg_conditional_sets
, &tmp_uses
, &tmp_sets
);
2716 /* Make latency of jump equal to 0 by using anti-dependence. */
2717 EXECUTE_IF_SET_IN_REG_SET (&tmp_uses
, 0, i
, rsi
)
2719 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
2720 add_dependence_list (insn
, reg_last
->sets
, 0, REG_DEP_ANTI
);
2721 add_dependence_list (insn
, reg_last
->implicit_sets
,
2723 add_dependence_list (insn
, reg_last
->clobbers
, 0,
2726 if (!deps
->readonly
)
2728 reg_last
->uses_length
++;
2729 reg_last
->uses
= alloc_INSN_LIST (insn
, reg_last
->uses
);
2732 IOR_REG_SET (reg_pending_sets
, &tmp_sets
);
2734 CLEAR_REG_SET (&tmp_uses
);
2735 CLEAR_REG_SET (&tmp_sets
);
2738 /* All memory writes and volatile reads must happen before the
2739 jump. Non-volatile reads must happen before the jump iff
2740 the result is needed by the above register used mask. */
2742 pending
= deps
->pending_write_insns
;
2743 pending_mem
= deps
->pending_write_mems
;
2746 if (! sched_insns_conditions_mutex_p (insn
, XEXP (pending
, 0)))
2747 add_dependence (insn
, XEXP (pending
, 0), REG_DEP_OUTPUT
);
2748 pending
= XEXP (pending
, 1);
2749 pending_mem
= XEXP (pending_mem
, 1);
2752 pending
= deps
->pending_read_insns
;
2753 pending_mem
= deps
->pending_read_mems
;
2756 if (MEM_VOLATILE_P (XEXP (pending_mem
, 0))
2757 && ! sched_insns_conditions_mutex_p (insn
, XEXP (pending
, 0)))
2758 add_dependence (insn
, XEXP (pending
, 0), REG_DEP_OUTPUT
);
2759 pending
= XEXP (pending
, 1);
2760 pending_mem
= XEXP (pending_mem
, 1);
2763 add_dependence_list (insn
, deps
->last_pending_memory_flush
, 1,
2768 /* If this instruction can throw an exception, then moving it changes
2769 where block boundaries fall. This is mighty confusing elsewhere.
2770 Therefore, prevent such an instruction from being moved. Same for
2771 non-jump instructions that define block boundaries.
2772 ??? Unclear whether this is still necessary in EBB mode. If not,
2773 add_branch_dependences should be adjusted for RGN mode instead. */
2774 if (((CALL_P (insn
) || JUMP_P (insn
)) && can_throw_internal (insn
))
2775 || (NONJUMP_INSN_P (insn
) && control_flow_insn_p (insn
)))
2776 reg_pending_barrier
= MOVE_BARRIER
;
2778 if (sched_pressure_p
)
2780 setup_insn_reg_uses (deps
, insn
);
2781 setup_insn_reg_pressure_info (insn
);
2784 /* Add register dependencies for insn. */
2785 if (DEBUG_INSN_P (insn
))
2787 rtx prev
= deps
->last_debug_insn
;
2790 if (!deps
->readonly
)
2791 deps
->last_debug_insn
= insn
;
2794 add_dependence (insn
, prev
, REG_DEP_ANTI
);
2796 add_dependence_list (insn
, deps
->last_function_call
, 1,
2799 for (u
= deps
->last_pending_memory_flush
; u
; u
= XEXP (u
, 1))
2800 if (! NON_FLUSH_JUMP_P (u
) || !sel_sched_p ())
2801 add_dependence (insn
, XEXP (u
, 0), REG_DEP_ANTI
);
2803 EXECUTE_IF_SET_IN_REG_SET (reg_pending_uses
, 0, i
, rsi
)
2805 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
2806 add_dependence_list (insn
, reg_last
->sets
, 1, REG_DEP_ANTI
);
2807 add_dependence_list (insn
, reg_last
->clobbers
, 1, REG_DEP_ANTI
);
2809 if (!deps
->readonly
)
2810 reg_last
->uses
= alloc_INSN_LIST (insn
, reg_last
->uses
);
2812 CLEAR_REG_SET (reg_pending_uses
);
2814 /* Quite often, a debug insn will refer to stuff in the
2815 previous instruction, but the reason we want this
2816 dependency here is to make sure the scheduler doesn't
2817 gratuitously move a debug insn ahead. This could dirty
2818 DF flags and cause additional analysis that wouldn't have
2819 occurred in compilation without debug insns, and such
2820 additional analysis can modify the generated code. */
2821 prev
= PREV_INSN (insn
);
2823 if (prev
&& NONDEBUG_INSN_P (prev
))
2824 add_dependence (insn
, prev
, REG_DEP_ANTI
);
2828 EXECUTE_IF_SET_IN_REG_SET (reg_pending_uses
, 0, i
, rsi
)
2830 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
2831 add_dependence_list (insn
, reg_last
->sets
, 0, REG_DEP_TRUE
);
2832 add_dependence_list (insn
, reg_last
->implicit_sets
, 0, REG_DEP_ANTI
);
2833 add_dependence_list (insn
, reg_last
->clobbers
, 0, REG_DEP_TRUE
);
2835 if (!deps
->readonly
)
2837 reg_last
->uses
= alloc_INSN_LIST (insn
, reg_last
->uses
);
2838 reg_last
->uses_length
++;
2842 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
2843 if (TEST_HARD_REG_BIT (implicit_reg_pending_uses
, i
))
2845 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
2846 add_dependence_list (insn
, reg_last
->sets
, 0, REG_DEP_TRUE
);
2847 add_dependence_list (insn
, reg_last
->implicit_sets
, 0,
2849 add_dependence_list (insn
, reg_last
->clobbers
, 0, REG_DEP_TRUE
);
2851 if (!deps
->readonly
)
2853 reg_last
->uses
= alloc_INSN_LIST (insn
, reg_last
->uses
);
2854 reg_last
->uses_length
++;
2858 /* If the current insn is conditional, we can't free any
2860 if (sched_has_condition_p (insn
))
2862 EXECUTE_IF_SET_IN_REG_SET (reg_pending_clobbers
, 0, i
, rsi
)
2864 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
2865 add_dependence_list (insn
, reg_last
->sets
, 0, REG_DEP_OUTPUT
);
2866 add_dependence_list (insn
, reg_last
->implicit_sets
, 0,
2868 add_dependence_list (insn
, reg_last
->uses
, 0, REG_DEP_ANTI
);
2870 if (!deps
->readonly
)
2873 = alloc_INSN_LIST (insn
, reg_last
->clobbers
);
2874 reg_last
->clobbers_length
++;
2877 EXECUTE_IF_SET_IN_REG_SET (reg_pending_sets
, 0, i
, rsi
)
2879 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
2880 add_dependence_list (insn
, reg_last
->sets
, 0, REG_DEP_OUTPUT
);
2881 add_dependence_list (insn
, reg_last
->implicit_sets
, 0,
2883 add_dependence_list (insn
, reg_last
->clobbers
, 0, REG_DEP_OUTPUT
);
2884 add_dependence_list (insn
, reg_last
->uses
, 0, REG_DEP_ANTI
);
2886 if (!deps
->readonly
)
2888 reg_last
->sets
= alloc_INSN_LIST (insn
, reg_last
->sets
);
2889 SET_REGNO_REG_SET (&deps
->reg_conditional_sets
, i
);
2895 EXECUTE_IF_SET_IN_REG_SET (reg_pending_clobbers
, 0, i
, rsi
)
2897 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
2898 if (reg_last
->uses_length
> MAX_PENDING_LIST_LENGTH
2899 || reg_last
->clobbers_length
> MAX_PENDING_LIST_LENGTH
)
2901 add_dependence_list_and_free (deps
, insn
, ®_last
->sets
, 0,
2903 add_dependence_list_and_free (deps
, insn
,
2904 ®_last
->implicit_sets
, 0,
2906 add_dependence_list_and_free (deps
, insn
, ®_last
->uses
, 0,
2908 add_dependence_list_and_free
2909 (deps
, insn
, ®_last
->clobbers
, 0, REG_DEP_OUTPUT
);
2911 if (!deps
->readonly
)
2913 reg_last
->sets
= alloc_INSN_LIST (insn
, reg_last
->sets
);
2914 reg_last
->clobbers_length
= 0;
2915 reg_last
->uses_length
= 0;
2920 add_dependence_list (insn
, reg_last
->sets
, 0, REG_DEP_OUTPUT
);
2921 add_dependence_list (insn
, reg_last
->implicit_sets
, 0,
2923 add_dependence_list (insn
, reg_last
->uses
, 0, REG_DEP_ANTI
);
2926 if (!deps
->readonly
)
2928 reg_last
->clobbers_length
++;
2930 = alloc_INSN_LIST (insn
, reg_last
->clobbers
);
2933 EXECUTE_IF_SET_IN_REG_SET (reg_pending_sets
, 0, i
, rsi
)
2935 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
2937 add_dependence_list_and_free (deps
, insn
, ®_last
->sets
, 0,
2939 add_dependence_list_and_free (deps
, insn
,
2940 ®_last
->implicit_sets
,
2942 add_dependence_list_and_free (deps
, insn
, ®_last
->clobbers
, 0,
2944 add_dependence_list_and_free (deps
, insn
, ®_last
->uses
, 0,
2947 if (!deps
->readonly
)
2949 reg_last
->sets
= alloc_INSN_LIST (insn
, reg_last
->sets
);
2950 reg_last
->uses_length
= 0;
2951 reg_last
->clobbers_length
= 0;
2952 CLEAR_REGNO_REG_SET (&deps
->reg_conditional_sets
, i
);
2958 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
2959 if (TEST_HARD_REG_BIT (implicit_reg_pending_clobbers
, i
))
2961 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
2962 add_dependence_list (insn
, reg_last
->sets
, 0, REG_DEP_ANTI
);
2963 add_dependence_list (insn
, reg_last
->clobbers
, 0, REG_DEP_ANTI
);
2964 add_dependence_list (insn
, reg_last
->uses
, 0, REG_DEP_ANTI
);
2966 if (!deps
->readonly
)
2967 reg_last
->implicit_sets
2968 = alloc_INSN_LIST (insn
, reg_last
->implicit_sets
);
2971 if (!deps
->readonly
)
2973 IOR_REG_SET (&deps
->reg_last_in_use
, reg_pending_uses
);
2974 IOR_REG_SET (&deps
->reg_last_in_use
, reg_pending_clobbers
);
2975 IOR_REG_SET (&deps
->reg_last_in_use
, reg_pending_sets
);
2976 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
2977 if (TEST_HARD_REG_BIT (implicit_reg_pending_uses
, i
)
2978 || TEST_HARD_REG_BIT (implicit_reg_pending_clobbers
, i
))
2979 SET_REGNO_REG_SET (&deps
->reg_last_in_use
, i
);
2981 /* Set up the pending barrier found. */
2982 deps
->last_reg_pending_barrier
= reg_pending_barrier
;
2985 CLEAR_REG_SET (reg_pending_uses
);
2986 CLEAR_REG_SET (reg_pending_clobbers
);
2987 CLEAR_REG_SET (reg_pending_sets
);
2988 CLEAR_HARD_REG_SET (implicit_reg_pending_clobbers
);
2989 CLEAR_HARD_REG_SET (implicit_reg_pending_uses
);
2991 /* Add dependencies if a scheduling barrier was found. */
2992 if (reg_pending_barrier
)
2994 /* In the case of barrier the most added dependencies are not
2995 real, so we use anti-dependence here. */
2996 if (sched_has_condition_p (insn
))
2998 EXECUTE_IF_SET_IN_REG_SET (&deps
->reg_last_in_use
, 0, i
, rsi
)
3000 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
3001 add_dependence_list (insn
, reg_last
->uses
, 0, REG_DEP_ANTI
);
3002 add_dependence_list (insn
, reg_last
->sets
, 0,
3003 reg_pending_barrier
== TRUE_BARRIER
3004 ? REG_DEP_TRUE
: REG_DEP_ANTI
);
3005 add_dependence_list (insn
, reg_last
->implicit_sets
, 0,
3007 add_dependence_list (insn
, reg_last
->clobbers
, 0,
3008 reg_pending_barrier
== TRUE_BARRIER
3009 ? REG_DEP_TRUE
: REG_DEP_ANTI
);
3014 EXECUTE_IF_SET_IN_REG_SET (&deps
->reg_last_in_use
, 0, i
, rsi
)
3016 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
3017 add_dependence_list_and_free (deps
, insn
, ®_last
->uses
, 0,
3019 add_dependence_list_and_free (deps
, insn
, ®_last
->sets
, 0,
3020 reg_pending_barrier
== TRUE_BARRIER
3021 ? REG_DEP_TRUE
: REG_DEP_ANTI
);
3022 add_dependence_list_and_free (deps
, insn
,
3023 ®_last
->implicit_sets
, 0,
3025 add_dependence_list_and_free (deps
, insn
, ®_last
->clobbers
, 0,
3026 reg_pending_barrier
== TRUE_BARRIER
3027 ? REG_DEP_TRUE
: REG_DEP_ANTI
);
3029 if (!deps
->readonly
)
3031 reg_last
->uses_length
= 0;
3032 reg_last
->clobbers_length
= 0;
3037 if (!deps
->readonly
)
3038 for (i
= 0; i
< (unsigned)deps
->max_reg
; i
++)
3040 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
3041 reg_last
->sets
= alloc_INSN_LIST (insn
, reg_last
->sets
);
3042 SET_REGNO_REG_SET (&deps
->reg_last_in_use
, i
);
3045 /* Flush pending lists on jumps, but not on speculative checks. */
3046 if (JUMP_P (insn
) && !(sel_sched_p ()
3047 && sel_insn_is_speculation_check (insn
)))
3048 flush_pending_lists (deps
, insn
, true, true);
3050 if (!deps
->readonly
)
3051 CLEAR_REG_SET (&deps
->reg_conditional_sets
);
3052 reg_pending_barrier
= NOT_A_BARRIER
;
3055 /* If a post-call group is still open, see if it should remain so.
3056 This insn must be a simple move of a hard reg to a pseudo or
3059 We must avoid moving these insns for correctness on targets
3060 with small register classes, and for special registers like
3061 PIC_OFFSET_TABLE_REGNUM. For simplicity, extend this to all
3062 hard regs for all targets. */
3064 if (deps
->in_post_call_group_p
)
3066 rtx tmp
, set
= single_set (insn
);
3067 int src_regno
, dest_regno
;
3071 if (DEBUG_INSN_P (insn
))
3072 /* We don't want to mark debug insns as part of the same
3073 sched group. We know they really aren't, but if we use
3074 debug insns to tell that a call group is over, we'll
3075 get different code if debug insns are not there and
3076 instructions that follow seem like they should be part
3079 Also, if we did, fixup_sched_groups() would move the
3080 deps of the debug insn to the call insn, modifying
3081 non-debug post-dependency counts of the debug insn
3082 dependencies and otherwise messing with the scheduling
3085 Instead, let such debug insns be scheduled freely, but
3086 keep the call group open in case there are insns that
3087 should be part of it afterwards. Since we grant debug
3088 insns higher priority than even sched group insns, it
3089 will all turn out all right. */
3090 goto debug_dont_end_call_group
;
3092 goto end_call_group
;
3095 tmp
= SET_DEST (set
);
3096 if (GET_CODE (tmp
) == SUBREG
)
3097 tmp
= SUBREG_REG (tmp
);
3099 dest_regno
= REGNO (tmp
);
3101 goto end_call_group
;
3103 tmp
= SET_SRC (set
);
3104 if (GET_CODE (tmp
) == SUBREG
)
3105 tmp
= SUBREG_REG (tmp
);
3106 if ((GET_CODE (tmp
) == PLUS
3107 || GET_CODE (tmp
) == MINUS
)
3108 && REG_P (XEXP (tmp
, 0))
3109 && REGNO (XEXP (tmp
, 0)) == STACK_POINTER_REGNUM
3110 && dest_regno
== STACK_POINTER_REGNUM
)
3111 src_regno
= STACK_POINTER_REGNUM
;
3112 else if (REG_P (tmp
))
3113 src_regno
= REGNO (tmp
);
3115 goto end_call_group
;
3117 if (src_regno
< FIRST_PSEUDO_REGISTER
3118 || dest_regno
< FIRST_PSEUDO_REGISTER
)
3121 && deps
->in_post_call_group_p
== post_call_initial
)
3122 deps
->in_post_call_group_p
= post_call
;
3124 if (!sel_sched_p () || sched_emulate_haifa_p
)
3126 SCHED_GROUP_P (insn
) = 1;
3127 CANT_MOVE (insn
) = 1;
3133 if (!deps
->readonly
)
3134 deps
->in_post_call_group_p
= not_post_call
;
3138 debug_dont_end_call_group
:
3139 if ((current_sched_info
->flags
& DO_SPECULATION
)
3140 && !sched_insn_is_legitimate_for_speculation_p (insn
, 0))
3141 /* INSN has an internal dependency (e.g. r14 = [r14]) and thus cannot
3145 sel_mark_hard_insn (insn
);
3148 sd_iterator_def sd_it
;
3151 for (sd_it
= sd_iterator_start (insn
, SD_LIST_SPEC_BACK
);
3152 sd_iterator_cond (&sd_it
, &dep
);)
3153 change_spec_dep_to_hard (sd_it
);
3158 /* Return TRUE if INSN might not always return normally (e.g. call exit,
3159 longjmp, loop forever, ...). */
3161 call_may_noreturn_p (rtx insn
)
3165 /* const or pure calls that aren't looping will always return. */
3166 if (RTL_CONST_OR_PURE_CALL_P (insn
)
3167 && !RTL_LOOPING_CONST_OR_PURE_CALL_P (insn
))
3170 call
= PATTERN (insn
);
3171 if (GET_CODE (call
) == PARALLEL
)
3172 call
= XVECEXP (call
, 0, 0);
3173 if (GET_CODE (call
) == SET
)
3174 call
= SET_SRC (call
);
3175 if (GET_CODE (call
) == CALL
3176 && MEM_P (XEXP (call
, 0))
3177 && GET_CODE (XEXP (XEXP (call
, 0), 0)) == SYMBOL_REF
)
3179 rtx symbol
= XEXP (XEXP (call
, 0), 0);
3180 if (SYMBOL_REF_DECL (symbol
)
3181 && TREE_CODE (SYMBOL_REF_DECL (symbol
)) == FUNCTION_DECL
)
3183 if (DECL_BUILT_IN_CLASS (SYMBOL_REF_DECL (symbol
))
3185 switch (DECL_FUNCTION_CODE (SYMBOL_REF_DECL (symbol
)))
3188 case BUILT_IN_BCOPY
:
3189 case BUILT_IN_BZERO
:
3190 case BUILT_IN_INDEX
:
3191 case BUILT_IN_MEMCHR
:
3192 case BUILT_IN_MEMCMP
:
3193 case BUILT_IN_MEMCPY
:
3194 case BUILT_IN_MEMMOVE
:
3195 case BUILT_IN_MEMPCPY
:
3196 case BUILT_IN_MEMSET
:
3197 case BUILT_IN_RINDEX
:
3198 case BUILT_IN_STPCPY
:
3199 case BUILT_IN_STPNCPY
:
3200 case BUILT_IN_STRCAT
:
3201 case BUILT_IN_STRCHR
:
3202 case BUILT_IN_STRCMP
:
3203 case BUILT_IN_STRCPY
:
3204 case BUILT_IN_STRCSPN
:
3205 case BUILT_IN_STRLEN
:
3206 case BUILT_IN_STRNCAT
:
3207 case BUILT_IN_STRNCMP
:
3208 case BUILT_IN_STRNCPY
:
3209 case BUILT_IN_STRPBRK
:
3210 case BUILT_IN_STRRCHR
:
3211 case BUILT_IN_STRSPN
:
3212 case BUILT_IN_STRSTR
:
3213 /* Assume certain string/memory builtins always return. */
3221 /* For all other calls assume that they might not always return. */
3225 /* Analyze INSN with DEPS as a context. */
3227 deps_analyze_insn (struct deps_desc
*deps
, rtx insn
)
3229 if (sched_deps_info
->start_insn
)
3230 sched_deps_info
->start_insn (insn
);
3232 if (NONJUMP_INSN_P (insn
) || DEBUG_INSN_P (insn
) || JUMP_P (insn
))
3234 /* Make each JUMP_INSN (but not a speculative check)
3235 a scheduling barrier for memory references. */
3239 && sel_insn_is_speculation_check (insn
)))
3241 /* Keep the list a reasonable size. */
3242 if (deps
->pending_flush_length
++ > MAX_PENDING_LIST_LENGTH
)
3243 flush_pending_lists (deps
, insn
, true, true);
3246 deps
->last_pending_memory_flush
3247 = alloc_INSN_LIST (insn
, deps
->last_pending_memory_flush
);
3248 /* Signal to sched_analyze_insn that this jump stands
3249 just for its own, not any other pending memory
3250 reads/writes flush_pending_lists had to flush. */
3251 PUT_REG_NOTE_KIND (deps
->last_pending_memory_flush
,
3252 NON_FLUSH_JUMP_KIND
);
3256 sched_analyze_insn (deps
, PATTERN (insn
), insn
);
3258 else if (CALL_P (insn
))
3262 CANT_MOVE (insn
) = 1;
3264 if (find_reg_note (insn
, REG_SETJMP
, NULL
))
3266 /* This is setjmp. Assume that all registers, not just
3267 hard registers, may be clobbered by this call. */
3268 reg_pending_barrier
= MOVE_BARRIER
;
3272 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3273 /* A call may read and modify global register variables. */
3276 SET_REGNO_REG_SET (reg_pending_sets
, i
);
3277 SET_HARD_REG_BIT (implicit_reg_pending_uses
, i
);
3279 /* Other call-clobbered hard regs may be clobbered.
3280 Since we only have a choice between 'might be clobbered'
3281 and 'definitely not clobbered', we must include all
3282 partly call-clobbered registers here. */
3283 else if (HARD_REGNO_CALL_PART_CLOBBERED (i
, reg_raw_mode
[i
])
3284 || TEST_HARD_REG_BIT (regs_invalidated_by_call
, i
))
3285 SET_REGNO_REG_SET (reg_pending_clobbers
, i
);
3286 /* We don't know what set of fixed registers might be used
3287 by the function, but it is certain that the stack pointer
3288 is among them, but be conservative. */
3289 else if (fixed_regs
[i
])
3290 SET_HARD_REG_BIT (implicit_reg_pending_uses
, i
);
3291 /* The frame pointer is normally not used by the function
3292 itself, but by the debugger. */
3293 /* ??? MIPS o32 is an exception. It uses the frame pointer
3294 in the macro expansion of jal but does not represent this
3295 fact in the call_insn rtl. */
3296 else if (i
== FRAME_POINTER_REGNUM
3297 || (i
== HARD_FRAME_POINTER_REGNUM
3298 && (! reload_completed
|| frame_pointer_needed
)))
3299 SET_HARD_REG_BIT (implicit_reg_pending_uses
, i
);
3302 /* For each insn which shouldn't cross a call, add a dependence
3303 between that insn and this call insn. */
3304 add_dependence_list_and_free (deps
, insn
,
3305 &deps
->sched_before_next_call
, 1,
3308 sched_analyze_insn (deps
, PATTERN (insn
), insn
);
3310 /* If CALL would be in a sched group, then this will violate
3311 convention that sched group insns have dependencies only on the
3312 previous instruction.
3314 Of course one can say: "Hey! What about head of the sched group?"
3315 And I will answer: "Basic principles (one dep per insn) are always
3317 gcc_assert (!SCHED_GROUP_P (insn
));
3319 /* In the absence of interprocedural alias analysis, we must flush
3320 all pending reads and writes, and start new dependencies starting
3321 from here. But only flush writes for constant calls (which may
3322 be passed a pointer to something we haven't written yet). */
3323 flush_pending_lists (deps
, insn
, true, ! RTL_CONST_OR_PURE_CALL_P (insn
));
3325 if (!deps
->readonly
)
3327 /* Remember the last function call for limiting lifetimes. */
3328 free_INSN_LIST_list (&deps
->last_function_call
);
3329 deps
->last_function_call
= alloc_INSN_LIST (insn
, NULL_RTX
);
3331 if (call_may_noreturn_p (insn
))
3333 /* Remember the last function call that might not always return
3334 normally for limiting moves of trapping insns. */
3335 free_INSN_LIST_list (&deps
->last_function_call_may_noreturn
);
3336 deps
->last_function_call_may_noreturn
3337 = alloc_INSN_LIST (insn
, NULL_RTX
);
3340 /* Before reload, begin a post-call group, so as to keep the
3341 lifetimes of hard registers correct. */
3342 if (! reload_completed
)
3343 deps
->in_post_call_group_p
= post_call
;
3347 if (sched_deps_info
->use_cselib
)
3348 cselib_process_insn (insn
);
3350 /* EH_REGION insn notes can not appear until well after we complete
3353 gcc_assert (NOTE_KIND (insn
) != NOTE_INSN_EH_REGION_BEG
3354 && NOTE_KIND (insn
) != NOTE_INSN_EH_REGION_END
);
3356 if (sched_deps_info
->finish_insn
)
3357 sched_deps_info
->finish_insn ();
3359 /* Fixup the dependencies in the sched group. */
3360 if ((NONJUMP_INSN_P (insn
) || JUMP_P (insn
))
3361 && SCHED_GROUP_P (insn
) && !sel_sched_p ())
3362 fixup_sched_groups (insn
);
3365 /* Initialize DEPS for the new block beginning with HEAD. */
3367 deps_start_bb (struct deps_desc
*deps
, rtx head
)
3369 gcc_assert (!deps
->readonly
);
3371 /* Before reload, if the previous block ended in a call, show that
3372 we are inside a post-call group, so as to keep the lifetimes of
3373 hard registers correct. */
3374 if (! reload_completed
&& !LABEL_P (head
))
3376 rtx insn
= prev_nonnote_nondebug_insn (head
);
3378 if (insn
&& CALL_P (insn
))
3379 deps
->in_post_call_group_p
= post_call_initial
;
3383 /* Analyze every insn between HEAD and TAIL inclusive, creating backward
3384 dependencies for each insn. */
3386 sched_analyze (struct deps_desc
*deps
, rtx head
, rtx tail
)
3390 if (sched_deps_info
->use_cselib
)
3391 cselib_init (CSELIB_RECORD_MEMORY
);
3393 deps_start_bb (deps
, head
);
3395 for (insn
= head
;; insn
= NEXT_INSN (insn
))
3400 /* And initialize deps_lists. */
3401 sd_init_insn (insn
);
3404 deps_analyze_insn (deps
, insn
);
3408 if (sched_deps_info
->use_cselib
)
3416 /* Helper for sched_free_deps ().
3417 Delete INSN's (RESOLVED_P) backward dependencies. */
3419 delete_dep_nodes_in_back_deps (rtx insn
, bool resolved_p
)
3421 sd_iterator_def sd_it
;
3423 sd_list_types_def types
;
3426 types
= SD_LIST_RES_BACK
;
3428 types
= SD_LIST_BACK
;
3430 for (sd_it
= sd_iterator_start (insn
, types
);
3431 sd_iterator_cond (&sd_it
, &dep
);)
3433 dep_link_t link
= *sd_it
.linkp
;
3434 dep_node_t node
= DEP_LINK_NODE (link
);
3435 deps_list_t back_list
;
3436 deps_list_t forw_list
;
3438 get_back_and_forw_lists (dep
, resolved_p
, &back_list
, &forw_list
);
3439 remove_from_deps_list (link
, back_list
);
3440 delete_dep_node (node
);
3444 /* Delete (RESOLVED_P) dependencies between HEAD and TAIL together with
3447 sched_free_deps (rtx head
, rtx tail
, bool resolved_p
)
3450 rtx next_tail
= NEXT_INSN (tail
);
3452 for (insn
= head
; insn
!= next_tail
; insn
= NEXT_INSN (insn
))
3453 if (INSN_P (insn
) && INSN_LUID (insn
) > 0)
3455 /* Clear resolved back deps together with its dep_nodes. */
3456 delete_dep_nodes_in_back_deps (insn
, resolved_p
);
3458 /* Clear forward deps and leave the dep_nodes to the
3459 corresponding back_deps list. */
3461 clear_deps_list (INSN_RESOLVED_FORW_DEPS (insn
));
3463 clear_deps_list (INSN_FORW_DEPS (insn
));
3465 sd_finish_insn (insn
);
3469 /* Initialize variables for region data dependence analysis.
3470 When LAZY_REG_LAST is true, do not allocate reg_last array
3471 of struct deps_desc immediately. */
3474 init_deps (struct deps_desc
*deps
, bool lazy_reg_last
)
3476 int max_reg
= (reload_completed
? FIRST_PSEUDO_REGISTER
: max_reg_num ());
3478 deps
->max_reg
= max_reg
;
3480 deps
->reg_last
= NULL
;
3482 deps
->reg_last
= XCNEWVEC (struct deps_reg
, max_reg
);
3483 INIT_REG_SET (&deps
->reg_last_in_use
);
3484 INIT_REG_SET (&deps
->reg_conditional_sets
);
3486 deps
->pending_read_insns
= 0;
3487 deps
->pending_read_mems
= 0;
3488 deps
->pending_write_insns
= 0;
3489 deps
->pending_write_mems
= 0;
3490 deps
->pending_read_list_length
= 0;
3491 deps
->pending_write_list_length
= 0;
3492 deps
->pending_flush_length
= 0;
3493 deps
->last_pending_memory_flush
= 0;
3494 deps
->last_function_call
= 0;
3495 deps
->last_function_call_may_noreturn
= 0;
3496 deps
->sched_before_next_call
= 0;
3497 deps
->in_post_call_group_p
= not_post_call
;
3498 deps
->last_debug_insn
= 0;
3499 deps
->last_reg_pending_barrier
= NOT_A_BARRIER
;
3503 /* Init only reg_last field of DEPS, which was not allocated before as
3504 we inited DEPS lazily. */
3506 init_deps_reg_last (struct deps_desc
*deps
)
3508 gcc_assert (deps
&& deps
->max_reg
> 0);
3509 gcc_assert (deps
->reg_last
== NULL
);
3511 deps
->reg_last
= XCNEWVEC (struct deps_reg
, deps
->max_reg
);
3515 /* Free insn lists found in DEPS. */
3518 free_deps (struct deps_desc
*deps
)
3521 reg_set_iterator rsi
;
3523 /* We set max_reg to 0 when this context was already freed. */
3524 if (deps
->max_reg
== 0)
3526 gcc_assert (deps
->reg_last
== NULL
);
3531 free_INSN_LIST_list (&deps
->pending_read_insns
);
3532 free_EXPR_LIST_list (&deps
->pending_read_mems
);
3533 free_INSN_LIST_list (&deps
->pending_write_insns
);
3534 free_EXPR_LIST_list (&deps
->pending_write_mems
);
3535 free_INSN_LIST_list (&deps
->last_pending_memory_flush
);
3537 /* Without the EXECUTE_IF_SET, this loop is executed max_reg * nr_regions
3538 times. For a testcase with 42000 regs and 8000 small basic blocks,
3539 this loop accounted for nearly 60% (84 sec) of the total -O2 runtime. */
3540 EXECUTE_IF_SET_IN_REG_SET (&deps
->reg_last_in_use
, 0, i
, rsi
)
3542 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
3544 free_INSN_LIST_list (®_last
->uses
);
3546 free_INSN_LIST_list (®_last
->sets
);
3547 if (reg_last
->implicit_sets
)
3548 free_INSN_LIST_list (®_last
->implicit_sets
);
3549 if (reg_last
->clobbers
)
3550 free_INSN_LIST_list (®_last
->clobbers
);
3552 CLEAR_REG_SET (&deps
->reg_last_in_use
);
3553 CLEAR_REG_SET (&deps
->reg_conditional_sets
);
3555 /* As we initialize reg_last lazily, it is possible that we didn't allocate
3558 free (deps
->reg_last
);
3559 deps
->reg_last
= NULL
;
3564 /* Remove INSN from dependence contexts DEPS. Caution: reg_conditional_sets
3567 remove_from_deps (struct deps_desc
*deps
, rtx insn
)
3571 reg_set_iterator rsi
;
3573 removed
= remove_from_both_dependence_lists (insn
, &deps
->pending_read_insns
,
3574 &deps
->pending_read_mems
);
3575 if (!DEBUG_INSN_P (insn
))
3576 deps
->pending_read_list_length
-= removed
;
3577 removed
= remove_from_both_dependence_lists (insn
, &deps
->pending_write_insns
,
3578 &deps
->pending_write_mems
);
3579 deps
->pending_write_list_length
-= removed
;
3580 removed
= remove_from_dependence_list (insn
, &deps
->last_pending_memory_flush
);
3581 deps
->pending_flush_length
-= removed
;
3583 EXECUTE_IF_SET_IN_REG_SET (&deps
->reg_last_in_use
, 0, i
, rsi
)
3585 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
3587 remove_from_dependence_list (insn
, ®_last
->uses
);
3589 remove_from_dependence_list (insn
, ®_last
->sets
);
3590 if (reg_last
->implicit_sets
)
3591 remove_from_dependence_list (insn
, ®_last
->implicit_sets
);
3592 if (reg_last
->clobbers
)
3593 remove_from_dependence_list (insn
, ®_last
->clobbers
);
3594 if (!reg_last
->uses
&& !reg_last
->sets
&& !reg_last
->implicit_sets
3595 && !reg_last
->clobbers
)
3596 CLEAR_REGNO_REG_SET (&deps
->reg_last_in_use
, i
);
3601 remove_from_dependence_list (insn
, &deps
->last_function_call
);
3602 remove_from_dependence_list (insn
,
3603 &deps
->last_function_call_may_noreturn
);
3605 remove_from_dependence_list (insn
, &deps
->sched_before_next_call
);
3608 /* Init deps data vector. */
3610 init_deps_data_vector (void)
3612 int reserve
= (sched_max_luid
+ 1
3613 - VEC_length (haifa_deps_insn_data_def
, h_d_i_d
));
3615 && ! VEC_space (haifa_deps_insn_data_def
, h_d_i_d
, reserve
))
3616 VEC_safe_grow_cleared (haifa_deps_insn_data_def
, heap
, h_d_i_d
,
3617 3 * sched_max_luid
/ 2);
3620 /* If it is profitable to use them, initialize or extend (depending on
3621 GLOBAL_P) dependency data. */
3623 sched_deps_init (bool global_p
)
3625 /* Average number of insns in the basic block.
3626 '+ 1' is used to make it nonzero. */
3627 int insns_in_block
= sched_max_luid
/ n_basic_blocks
+ 1;
3629 init_deps_data_vector ();
3631 /* We use another caching mechanism for selective scheduling, so
3632 we don't use this one. */
3633 if (!sel_sched_p () && global_p
&& insns_in_block
> 100 * 5)
3635 /* ?!? We could save some memory by computing a per-region luid mapping
3636 which could reduce both the number of vectors in the cache and the
3637 size of each vector. Instead we just avoid the cache entirely unless
3638 the average number of instructions in a basic block is very high. See
3639 the comment before the declaration of true_dependency_cache for
3640 what we consider "very high". */
3642 extend_dependency_caches (sched_max_luid
, true);
3647 dl_pool
= create_alloc_pool ("deps_list", sizeof (struct _deps_list
),
3648 /* Allocate lists for one block at a time. */
3650 dn_pool
= create_alloc_pool ("dep_node", sizeof (struct _dep_node
),
3651 /* Allocate nodes for one block at a time.
3652 We assume that average insn has
3654 5 * insns_in_block
);
3659 /* Create or extend (depending on CREATE_P) dependency caches to
3662 extend_dependency_caches (int n
, bool create_p
)
3664 if (create_p
|| true_dependency_cache
)
3666 int i
, luid
= cache_size
+ n
;
3668 true_dependency_cache
= XRESIZEVEC (bitmap_head
, true_dependency_cache
,
3670 output_dependency_cache
= XRESIZEVEC (bitmap_head
,
3671 output_dependency_cache
, luid
);
3672 anti_dependency_cache
= XRESIZEVEC (bitmap_head
, anti_dependency_cache
,
3675 if (current_sched_info
->flags
& DO_SPECULATION
)
3676 spec_dependency_cache
= XRESIZEVEC (bitmap_head
, spec_dependency_cache
,
3679 for (i
= cache_size
; i
< luid
; i
++)
3681 bitmap_initialize (&true_dependency_cache
[i
], 0);
3682 bitmap_initialize (&output_dependency_cache
[i
], 0);
3683 bitmap_initialize (&anti_dependency_cache
[i
], 0);
3685 if (current_sched_info
->flags
& DO_SPECULATION
)
3686 bitmap_initialize (&spec_dependency_cache
[i
], 0);
3692 /* Finalize dependency information for the whole function. */
3694 sched_deps_finish (void)
3696 gcc_assert (deps_pools_are_empty_p ());
3697 free_alloc_pool_if_empty (&dn_pool
);
3698 free_alloc_pool_if_empty (&dl_pool
);
3699 gcc_assert (dn_pool
== NULL
&& dl_pool
== NULL
);
3701 VEC_free (haifa_deps_insn_data_def
, heap
, h_d_i_d
);
3704 if (true_dependency_cache
)
3708 for (i
= 0; i
< cache_size
; i
++)
3710 bitmap_clear (&true_dependency_cache
[i
]);
3711 bitmap_clear (&output_dependency_cache
[i
]);
3712 bitmap_clear (&anti_dependency_cache
[i
]);
3714 if (sched_deps_info
->generate_spec_deps
)
3715 bitmap_clear (&spec_dependency_cache
[i
]);
3717 free (true_dependency_cache
);
3718 true_dependency_cache
= NULL
;
3719 free (output_dependency_cache
);
3720 output_dependency_cache
= NULL
;
3721 free (anti_dependency_cache
);
3722 anti_dependency_cache
= NULL
;
3724 if (sched_deps_info
->generate_spec_deps
)
3726 free (spec_dependency_cache
);
3727 spec_dependency_cache
= NULL
;
3733 /* Initialize some global variables needed by the dependency analysis
3737 init_deps_global (void)
3739 CLEAR_HARD_REG_SET (implicit_reg_pending_clobbers
);
3740 CLEAR_HARD_REG_SET (implicit_reg_pending_uses
);
3741 reg_pending_sets
= ALLOC_REG_SET (®_obstack
);
3742 reg_pending_clobbers
= ALLOC_REG_SET (®_obstack
);
3743 reg_pending_uses
= ALLOC_REG_SET (®_obstack
);
3744 reg_pending_barrier
= NOT_A_BARRIER
;
3746 if (!sel_sched_p () || sched_emulate_haifa_p
)
3748 sched_deps_info
->start_insn
= haifa_start_insn
;
3749 sched_deps_info
->finish_insn
= haifa_finish_insn
;
3751 sched_deps_info
->note_reg_set
= haifa_note_reg_set
;
3752 sched_deps_info
->note_reg_clobber
= haifa_note_reg_clobber
;
3753 sched_deps_info
->note_reg_use
= haifa_note_reg_use
;
3755 sched_deps_info
->note_mem_dep
= haifa_note_mem_dep
;
3756 sched_deps_info
->note_dep
= haifa_note_dep
;
3760 /* Free everything used by the dependency analysis code. */
3763 finish_deps_global (void)
3765 FREE_REG_SET (reg_pending_sets
);
3766 FREE_REG_SET (reg_pending_clobbers
);
3767 FREE_REG_SET (reg_pending_uses
);
3770 /* Estimate the weakness of dependence between MEM1 and MEM2. */
3772 estimate_dep_weak (rtx mem1
, rtx mem2
)
3777 /* MEMs are the same - don't speculate. */
3778 return MIN_DEP_WEAK
;
3780 r1
= XEXP (mem1
, 0);
3781 r2
= XEXP (mem2
, 0);
3784 || (REG_P (r1
) && REG_P (r2
)
3785 && REGNO (r1
) == REGNO (r2
)))
3786 /* Again, MEMs are the same. */
3787 return MIN_DEP_WEAK
;
3788 else if ((REG_P (r1
) && !REG_P (r2
))
3789 || (!REG_P (r1
) && REG_P (r2
)))
3790 /* Different addressing modes - reason to be more speculative,
3792 return NO_DEP_WEAK
- (NO_DEP_WEAK
- UNCERTAIN_DEP_WEAK
) / 2;
3794 /* We can't say anything about the dependence. */
3795 return UNCERTAIN_DEP_WEAK
;
3798 /* Add or update backward dependence between INSN and ELEM with type DEP_TYPE.
3799 This function can handle same INSN and ELEM (INSN == ELEM).
3800 It is a convenience wrapper. */
3802 add_dependence (rtx insn
, rtx elem
, enum reg_note dep_type
)
3807 if (dep_type
== REG_DEP_TRUE
)
3809 else if (dep_type
== REG_DEP_OUTPUT
)
3813 gcc_assert (dep_type
== REG_DEP_ANTI
);
3817 /* When add_dependence is called from inside sched-deps.c, we expect
3818 cur_insn to be non-null. */
3819 internal
= cur_insn
!= NULL
;
3821 gcc_assert (insn
== cur_insn
);
3825 note_dep (elem
, ds
);
3830 /* Return weakness of speculative type TYPE in the dep_status DS. */
3832 get_dep_weak_1 (ds_t ds
, ds_t type
)
3838 case BEGIN_DATA
: ds
>>= BEGIN_DATA_BITS_OFFSET
; break;
3839 case BE_IN_DATA
: ds
>>= BE_IN_DATA_BITS_OFFSET
; break;
3840 case BEGIN_CONTROL
: ds
>>= BEGIN_CONTROL_BITS_OFFSET
; break;
3841 case BE_IN_CONTROL
: ds
>>= BE_IN_CONTROL_BITS_OFFSET
; break;
3842 default: gcc_unreachable ();
3849 get_dep_weak (ds_t ds
, ds_t type
)
3851 dw_t dw
= get_dep_weak_1 (ds
, type
);
3853 gcc_assert (MIN_DEP_WEAK
<= dw
&& dw
<= MAX_DEP_WEAK
);
3857 /* Return the dep_status, which has the same parameters as DS, except for
3858 speculative type TYPE, that will have weakness DW. */
3860 set_dep_weak (ds_t ds
, ds_t type
, dw_t dw
)
3862 gcc_assert (MIN_DEP_WEAK
<= dw
&& dw
<= MAX_DEP_WEAK
);
3867 case BEGIN_DATA
: ds
|= ((ds_t
) dw
) << BEGIN_DATA_BITS_OFFSET
; break;
3868 case BE_IN_DATA
: ds
|= ((ds_t
) dw
) << BE_IN_DATA_BITS_OFFSET
; break;
3869 case BEGIN_CONTROL
: ds
|= ((ds_t
) dw
) << BEGIN_CONTROL_BITS_OFFSET
; break;
3870 case BE_IN_CONTROL
: ds
|= ((ds_t
) dw
) << BE_IN_CONTROL_BITS_OFFSET
; break;
3871 default: gcc_unreachable ();
3876 /* Return the join of two dep_statuses DS1 and DS2.
3877 If MAX_P is true then choose the greater probability,
3878 otherwise multiply probabilities.
3879 This function assumes that both DS1 and DS2 contain speculative bits. */
3881 ds_merge_1 (ds_t ds1
, ds_t ds2
, bool max_p
)
3885 gcc_assert ((ds1
& SPECULATIVE
) && (ds2
& SPECULATIVE
));
3887 ds
= (ds1
& DEP_TYPES
) | (ds2
& DEP_TYPES
);
3889 t
= FIRST_SPEC_TYPE
;
3892 if ((ds1
& t
) && !(ds2
& t
))
3894 else if (!(ds1
& t
) && (ds2
& t
))
3896 else if ((ds1
& t
) && (ds2
& t
))
3898 dw_t dw1
= get_dep_weak (ds1
, t
);
3899 dw_t dw2
= get_dep_weak (ds2
, t
);
3904 dw
= ((ds_t
) dw1
) * ((ds_t
) dw2
);
3906 if (dw
< MIN_DEP_WEAK
)
3917 ds
= set_dep_weak (ds
, t
, (dw_t
) dw
);
3920 if (t
== LAST_SPEC_TYPE
)
3922 t
<<= SPEC_TYPE_SHIFT
;
3929 /* Return the join of two dep_statuses DS1 and DS2.
3930 This function assumes that both DS1 and DS2 contain speculative bits. */
3932 ds_merge (ds_t ds1
, ds_t ds2
)
3934 return ds_merge_1 (ds1
, ds2
, false);
3937 /* Return the join of two dep_statuses DS1 and DS2. */
3939 ds_full_merge (ds_t ds
, ds_t ds2
, rtx mem1
, rtx mem2
)
3941 ds_t new_status
= ds
| ds2
;
3943 if (new_status
& SPECULATIVE
)
3945 if ((ds
&& !(ds
& SPECULATIVE
))
3946 || (ds2
&& !(ds2
& SPECULATIVE
)))
3947 /* Then this dep can't be speculative. */
3948 new_status
&= ~SPECULATIVE
;
3951 /* Both are speculative. Merging probabilities. */
3956 dw
= estimate_dep_weak (mem1
, mem2
);
3957 ds
= set_dep_weak (ds
, BEGIN_DATA
, dw
);
3965 new_status
= ds_merge (ds2
, ds
);
3972 /* Return the join of DS1 and DS2. Use maximum instead of multiplying
3975 ds_max_merge (ds_t ds1
, ds_t ds2
)
3977 if (ds1
== 0 && ds2
== 0)
3980 if (ds1
== 0 && ds2
!= 0)
3983 if (ds1
!= 0 && ds2
== 0)
3986 return ds_merge_1 (ds1
, ds2
, true);
3989 /* Return the probability of speculation success for the speculation
3997 dt
= FIRST_SPEC_TYPE
;
4002 res
*= (ds_t
) get_dep_weak (ds
, dt
);
4006 if (dt
== LAST_SPEC_TYPE
)
4008 dt
<<= SPEC_TYPE_SHIFT
;
4014 res
/= MAX_DEP_WEAK
;
4016 if (res
< MIN_DEP_WEAK
)
4019 gcc_assert (res
<= MAX_DEP_WEAK
);
4024 /* Return a dep status that contains all speculation types of DS. */
4026 ds_get_speculation_types (ds_t ds
)
4028 if (ds
& BEGIN_DATA
)
4030 if (ds
& BE_IN_DATA
)
4032 if (ds
& BEGIN_CONTROL
)
4033 ds
|= BEGIN_CONTROL
;
4034 if (ds
& BE_IN_CONTROL
)
4035 ds
|= BE_IN_CONTROL
;
4037 return ds
& SPECULATIVE
;
4040 /* Return a dep status that contains maximal weakness for each speculation
4041 type present in DS. */
4043 ds_get_max_dep_weak (ds_t ds
)
4045 if (ds
& BEGIN_DATA
)
4046 ds
= set_dep_weak (ds
, BEGIN_DATA
, MAX_DEP_WEAK
);
4047 if (ds
& BE_IN_DATA
)
4048 ds
= set_dep_weak (ds
, BE_IN_DATA
, MAX_DEP_WEAK
);
4049 if (ds
& BEGIN_CONTROL
)
4050 ds
= set_dep_weak (ds
, BEGIN_CONTROL
, MAX_DEP_WEAK
);
4051 if (ds
& BE_IN_CONTROL
)
4052 ds
= set_dep_weak (ds
, BE_IN_CONTROL
, MAX_DEP_WEAK
);
4057 /* Dump information about the dependence status S. */
4059 dump_ds (FILE *f
, ds_t s
)
4064 fprintf (f
, "BEGIN_DATA: %d; ", get_dep_weak_1 (s
, BEGIN_DATA
));
4066 fprintf (f
, "BE_IN_DATA: %d; ", get_dep_weak_1 (s
, BE_IN_DATA
));
4067 if (s
& BEGIN_CONTROL
)
4068 fprintf (f
, "BEGIN_CONTROL: %d; ", get_dep_weak_1 (s
, BEGIN_CONTROL
));
4069 if (s
& BE_IN_CONTROL
)
4070 fprintf (f
, "BE_IN_CONTROL: %d; ", get_dep_weak_1 (s
, BE_IN_CONTROL
));
4073 fprintf (f
, "HARD_DEP; ");
4076 fprintf (f
, "DEP_TRUE; ");
4078 fprintf (f
, "DEP_ANTI; ");
4080 fprintf (f
, "DEP_OUTPUT; ");
4088 dump_ds (stderr
, s
);
4089 fprintf (stderr
, "\n");
4092 #ifdef ENABLE_CHECKING
4093 /* Verify that dependence type and status are consistent.
4094 If RELAXED_P is true, then skip dep_weakness checks. */
4096 check_dep (dep_t dep
, bool relaxed_p
)
4098 enum reg_note dt
= DEP_TYPE (dep
);
4099 ds_t ds
= DEP_STATUS (dep
);
4101 gcc_assert (DEP_PRO (dep
) != DEP_CON (dep
));
4103 if (!(current_sched_info
->flags
& USE_DEPS_LIST
))
4105 gcc_assert (ds
== -1);
4109 /* Check that dependence type contains the same bits as the status. */
4110 if (dt
== REG_DEP_TRUE
)
4111 gcc_assert (ds
& DEP_TRUE
);
4112 else if (dt
== REG_DEP_OUTPUT
)
4113 gcc_assert ((ds
& DEP_OUTPUT
)
4114 && !(ds
& DEP_TRUE
));
4116 gcc_assert ((dt
== REG_DEP_ANTI
)
4118 && !(ds
& (DEP_OUTPUT
| DEP_TRUE
)));
4120 /* HARD_DEP can not appear in dep_status of a link. */
4121 gcc_assert (!(ds
& HARD_DEP
));
4123 /* Check that dependence status is set correctly when speculation is not
4125 if (!sched_deps_info
->generate_spec_deps
)
4126 gcc_assert (!(ds
& SPECULATIVE
));
4127 else if (ds
& SPECULATIVE
)
4131 ds_t type
= FIRST_SPEC_TYPE
;
4133 /* Check that dependence weakness is in proper range. */
4137 get_dep_weak (ds
, type
);
4139 if (type
== LAST_SPEC_TYPE
)
4141 type
<<= SPEC_TYPE_SHIFT
;
4146 if (ds
& BEGIN_SPEC
)
4148 /* Only true dependence can be data speculative. */
4149 if (ds
& BEGIN_DATA
)
4150 gcc_assert (ds
& DEP_TRUE
);
4152 /* Control dependencies in the insn scheduler are represented by
4153 anti-dependencies, therefore only anti dependence can be
4154 control speculative. */
4155 if (ds
& BEGIN_CONTROL
)
4156 gcc_assert (ds
& DEP_ANTI
);
4160 /* Subsequent speculations should resolve true dependencies. */
4161 gcc_assert ((ds
& DEP_TYPES
) == DEP_TRUE
);
4164 /* Check that true and anti dependencies can't have other speculative
4167 gcc_assert (ds
& (BEGIN_DATA
| BE_IN_SPEC
));
4168 /* An output dependence can't be speculative at all. */
4169 gcc_assert (!(ds
& DEP_OUTPUT
));
4171 gcc_assert (ds
& BEGIN_CONTROL
);
4174 #endif /* ENABLE_CHECKING */
4176 #endif /* INSN_SCHEDULING */