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,
6 Free Software Foundation, Inc.
7 Contributed by Michael Tiemann (tiemann@cygnus.com) Enhanced by,
8 and currently maintained by, Jim Wilson (wilson@cygnus.com)
10 This file is part of GCC.
12 GCC is free software; you can redistribute it and/or modify it under
13 the terms of the GNU General Public License as published by the Free
14 Software Foundation; either version 3, or (at your option) any later
17 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
18 WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 You should have received a copy of the GNU General Public License
23 along with GCC; see the file COPYING3. If not see
24 <http://www.gnu.org/licenses/>. */
28 #include "coretypes.h"
30 #include "diagnostic-core.h"
33 #include "hard-reg-set.h"
37 #include "insn-config.h"
38 #include "insn-attr.h"
41 #include "sched-int.h"
47 #ifdef INSN_SCHEDULING
49 #ifdef ENABLE_CHECKING
55 /* In deps->last_pending_memory_flush marks JUMP_INSNs that weren't
56 added to the list because of flush_pending_lists, stands just
57 for itself and not for any other pending memory reads/writes. */
58 #define NON_FLUSH_JUMP_KIND REG_DEP_ANTI
59 #define NON_FLUSH_JUMP_P(x) (REG_NOTE_KIND (x) == NON_FLUSH_JUMP_KIND)
61 /* Holds current parameters for the dependency analyzer. */
62 struct sched_deps_info_def
*sched_deps_info
;
64 /* The data is specific to the Haifa scheduler. */
65 VEC(haifa_deps_insn_data_def
, heap
) *h_d_i_d
= NULL
;
67 /* Return the major type present in the DS. */
75 return REG_DEP_OUTPUT
;
77 gcc_assert (ds
& DEP_ANTI
);
82 /* Return equivalent dep_status. */
84 dk_to_ds (enum reg_note dk
)
95 gcc_assert (dk
== REG_DEP_ANTI
);
100 /* Functions to operate with dependence information container - dep_t. */
102 /* Init DEP with the arguments. */
104 init_dep_1 (dep_t dep
, rtx pro
, rtx con
, enum reg_note type
, ds_t ds
)
108 DEP_TYPE (dep
) = type
;
109 DEP_STATUS (dep
) = ds
;
112 /* Init DEP with the arguments.
113 While most of the scheduler (including targets) only need the major type
114 of the dependency, it is convenient to hide full dep_status from them. */
116 init_dep (dep_t dep
, rtx pro
, rtx con
, enum reg_note kind
)
120 if ((current_sched_info
->flags
& USE_DEPS_LIST
))
121 ds
= dk_to_ds (kind
);
125 init_dep_1 (dep
, pro
, con
, kind
, ds
);
128 /* Make a copy of FROM in TO. */
130 copy_dep (dep_t to
, dep_t from
)
132 memcpy (to
, from
, sizeof (*to
));
135 static void dump_ds (FILE *, ds_t
);
137 /* Define flags for dump_dep (). */
139 /* Dump producer of the dependence. */
140 #define DUMP_DEP_PRO (2)
142 /* Dump consumer of the dependence. */
143 #define DUMP_DEP_CON (4)
145 /* Dump type of the dependence. */
146 #define DUMP_DEP_TYPE (8)
148 /* Dump status of the dependence. */
149 #define DUMP_DEP_STATUS (16)
151 /* Dump all information about the dependence. */
152 #define DUMP_DEP_ALL (DUMP_DEP_PRO | DUMP_DEP_CON | DUMP_DEP_TYPE \
156 FLAGS is a bit mask specifying what information about DEP needs
158 If FLAGS has the very first bit set, then dump all information about DEP
159 and propagate this bit into the callee dump functions. */
161 dump_dep (FILE *dump
, dep_t dep
, int flags
)
164 flags
|= DUMP_DEP_ALL
;
168 if (flags
& DUMP_DEP_PRO
)
169 fprintf (dump
, "%d; ", INSN_UID (DEP_PRO (dep
)));
171 if (flags
& DUMP_DEP_CON
)
172 fprintf (dump
, "%d; ", INSN_UID (DEP_CON (dep
)));
174 if (flags
& DUMP_DEP_TYPE
)
177 enum reg_note type
= DEP_TYPE (dep
);
198 fprintf (dump
, "%c; ", t
);
201 if (flags
& DUMP_DEP_STATUS
)
203 if (current_sched_info
->flags
& USE_DEPS_LIST
)
204 dump_ds (dump
, DEP_STATUS (dep
));
210 /* Default flags for dump_dep (). */
211 static int dump_dep_flags
= (DUMP_DEP_PRO
| DUMP_DEP_CON
);
213 /* Dump all fields of DEP to STDERR. */
215 sd_debug_dep (dep_t dep
)
217 dump_dep (stderr
, dep
, 1);
218 fprintf (stderr
, "\n");
221 /* Determine whether DEP is a dependency link of a non-debug insn on a
225 depl_on_debug_p (dep_link_t dep
)
227 return (DEBUG_INSN_P (DEP_LINK_PRO (dep
))
228 && !DEBUG_INSN_P (DEP_LINK_CON (dep
)));
231 /* Functions to operate with a single link from the dependencies lists -
234 /* Attach L to appear after link X whose &DEP_LINK_NEXT (X) is given by
237 attach_dep_link (dep_link_t l
, dep_link_t
*prev_nextp
)
239 dep_link_t next
= *prev_nextp
;
241 gcc_assert (DEP_LINK_PREV_NEXTP (l
) == NULL
242 && DEP_LINK_NEXT (l
) == NULL
);
244 /* Init node being inserted. */
245 DEP_LINK_PREV_NEXTP (l
) = prev_nextp
;
246 DEP_LINK_NEXT (l
) = next
;
251 gcc_assert (DEP_LINK_PREV_NEXTP (next
) == prev_nextp
);
253 DEP_LINK_PREV_NEXTP (next
) = &DEP_LINK_NEXT (l
);
260 /* Add dep_link LINK to deps_list L. */
262 add_to_deps_list (dep_link_t link
, deps_list_t l
)
264 attach_dep_link (link
, &DEPS_LIST_FIRST (l
));
266 /* Don't count debug deps. */
267 if (!depl_on_debug_p (link
))
268 ++DEPS_LIST_N_LINKS (l
);
271 /* Detach dep_link L from the list. */
273 detach_dep_link (dep_link_t l
)
275 dep_link_t
*prev_nextp
= DEP_LINK_PREV_NEXTP (l
);
276 dep_link_t next
= DEP_LINK_NEXT (l
);
281 DEP_LINK_PREV_NEXTP (next
) = prev_nextp
;
283 DEP_LINK_PREV_NEXTP (l
) = NULL
;
284 DEP_LINK_NEXT (l
) = NULL
;
287 /* Remove link LINK from list LIST. */
289 remove_from_deps_list (dep_link_t link
, deps_list_t list
)
291 detach_dep_link (link
);
293 /* Don't count debug deps. */
294 if (!depl_on_debug_p (link
))
295 --DEPS_LIST_N_LINKS (list
);
298 /* Move link LINK from list FROM to list TO. */
300 move_dep_link (dep_link_t link
, deps_list_t from
, deps_list_t to
)
302 remove_from_deps_list (link
, from
);
303 add_to_deps_list (link
, to
);
306 /* Return true of LINK is not attached to any list. */
308 dep_link_is_detached_p (dep_link_t link
)
310 return DEP_LINK_PREV_NEXTP (link
) == NULL
;
313 /* Pool to hold all dependency nodes (dep_node_t). */
314 static alloc_pool dn_pool
;
316 /* Number of dep_nodes out there. */
317 static int dn_pool_diff
= 0;
319 /* Create a dep_node. */
321 create_dep_node (void)
323 dep_node_t n
= (dep_node_t
) pool_alloc (dn_pool
);
324 dep_link_t back
= DEP_NODE_BACK (n
);
325 dep_link_t forw
= DEP_NODE_FORW (n
);
327 DEP_LINK_NODE (back
) = n
;
328 DEP_LINK_NEXT (back
) = NULL
;
329 DEP_LINK_PREV_NEXTP (back
) = NULL
;
331 DEP_LINK_NODE (forw
) = n
;
332 DEP_LINK_NEXT (forw
) = NULL
;
333 DEP_LINK_PREV_NEXTP (forw
) = NULL
;
340 /* Delete dep_node N. N must not be connected to any deps_list. */
342 delete_dep_node (dep_node_t n
)
344 gcc_assert (dep_link_is_detached_p (DEP_NODE_BACK (n
))
345 && dep_link_is_detached_p (DEP_NODE_FORW (n
)));
349 pool_free (dn_pool
, n
);
352 /* Pool to hold dependencies lists (deps_list_t). */
353 static alloc_pool dl_pool
;
355 /* Number of deps_lists out there. */
356 static int dl_pool_diff
= 0;
358 /* Functions to operate with dependences lists - deps_list_t. */
360 /* Return true if list L is empty. */
362 deps_list_empty_p (deps_list_t l
)
364 return DEPS_LIST_N_LINKS (l
) == 0;
367 /* Create a new deps_list. */
369 create_deps_list (void)
371 deps_list_t l
= (deps_list_t
) pool_alloc (dl_pool
);
373 DEPS_LIST_FIRST (l
) = NULL
;
374 DEPS_LIST_N_LINKS (l
) = 0;
380 /* Free deps_list L. */
382 free_deps_list (deps_list_t l
)
384 gcc_assert (deps_list_empty_p (l
));
388 pool_free (dl_pool
, l
);
391 /* Return true if there is no dep_nodes and deps_lists out there.
392 After the region is scheduled all the dependency nodes and lists
393 should [generally] be returned to pool. */
395 deps_pools_are_empty_p (void)
397 return dn_pool_diff
== 0 && dl_pool_diff
== 0;
400 /* Remove all elements from L. */
402 clear_deps_list (deps_list_t l
)
406 dep_link_t link
= DEPS_LIST_FIRST (l
);
411 remove_from_deps_list (link
, l
);
416 static regset reg_pending_sets
;
417 static regset reg_pending_clobbers
;
418 static regset reg_pending_uses
;
419 static enum reg_pending_barrier_mode reg_pending_barrier
;
421 /* Hard registers implicitly clobbered or used (or may be implicitly
422 clobbered or used) by the currently analyzed insn. For example,
423 insn in its constraint has one register class. Even if there is
424 currently no hard register in the insn, the particular hard
425 register will be in the insn after reload pass because the
426 constraint requires it. */
427 static HARD_REG_SET implicit_reg_pending_clobbers
;
428 static HARD_REG_SET implicit_reg_pending_uses
;
430 /* To speed up the test for duplicate dependency links we keep a
431 record of dependencies created by add_dependence when the average
432 number of instructions in a basic block is very large.
434 Studies have shown that there is typically around 5 instructions between
435 branches for typical C code. So we can make a guess that the average
436 basic block is approximately 5 instructions long; we will choose 100X
437 the average size as a very large basic block.
439 Each insn has associated bitmaps for its dependencies. Each bitmap
440 has enough entries to represent a dependency on any other insn in
441 the insn chain. All bitmap for true dependencies cache is
442 allocated then the rest two ones are also allocated. */
443 static bitmap_head
*true_dependency_cache
= NULL
;
444 static bitmap_head
*output_dependency_cache
= NULL
;
445 static bitmap_head
*anti_dependency_cache
= NULL
;
446 static bitmap_head
*spec_dependency_cache
= NULL
;
447 static int cache_size
;
449 static int deps_may_trap_p (const_rtx
);
450 static void add_dependence_list (rtx
, rtx
, int, enum reg_note
);
451 static void add_dependence_list_and_free (struct deps_desc
*, rtx
,
452 rtx
*, int, enum reg_note
);
453 static void delete_all_dependences (rtx
);
454 static void fixup_sched_groups (rtx
);
456 static void flush_pending_lists (struct deps_desc
*, rtx
, int, int);
457 static void sched_analyze_1 (struct deps_desc
*, rtx
, rtx
);
458 static void sched_analyze_2 (struct deps_desc
*, rtx
, rtx
);
459 static void sched_analyze_insn (struct deps_desc
*, rtx
, rtx
);
461 static bool sched_has_condition_p (const_rtx
);
462 static int conditions_mutex_p (const_rtx
, const_rtx
, bool, bool);
464 static enum DEPS_ADJUST_RESULT
maybe_add_or_update_dep_1 (dep_t
, bool,
466 static enum DEPS_ADJUST_RESULT
add_or_update_dep_1 (dep_t
, bool, rtx
, rtx
);
468 #ifdef ENABLE_CHECKING
469 static void check_dep (dep_t
, bool);
472 /* Return nonzero if a load of the memory reference MEM can cause a trap. */
475 deps_may_trap_p (const_rtx mem
)
477 const_rtx addr
= XEXP (mem
, 0);
479 if (REG_P (addr
) && REGNO (addr
) >= FIRST_PSEUDO_REGISTER
)
481 const_rtx t
= get_reg_known_value (REGNO (addr
));
485 return rtx_addr_can_trap_p (addr
);
489 /* Find the condition under which INSN is executed. If REV is not NULL,
490 it is set to TRUE when the returned comparison should be reversed
491 to get the actual condition.
492 We only do actual work the first time we come here for an insn; the
493 results are cached in INSN_COND and INSN_REVERSE_COND. */
495 sched_get_condition_with_rev (const_rtx insn
, bool *rev
)
497 rtx pat
= PATTERN (insn
);
500 if (INSN_COND (insn
) == const_true_rtx
)
503 if (INSN_COND (insn
) != NULL_RTX
)
506 *rev
= INSN_REVERSE_COND (insn
);
507 return INSN_COND (insn
);
510 INSN_COND (insn
) = const_true_rtx
;
511 INSN_REVERSE_COND (insn
) = false;
518 if (GET_CODE (pat
) == COND_EXEC
)
520 INSN_COND (insn
) = COND_EXEC_TEST (pat
);
521 return COND_EXEC_TEST (pat
);
524 if (!any_condjump_p (insn
) || !onlyjump_p (insn
))
527 src
= SET_SRC (pc_set (insn
));
529 if (XEXP (src
, 2) == pc_rtx
)
531 INSN_COND (insn
) = XEXP (src
, 0);
532 return XEXP (src
, 0);
534 else if (XEXP (src
, 1) == pc_rtx
)
536 rtx cond
= XEXP (src
, 0);
537 enum rtx_code revcode
= reversed_comparison_code (cond
, insn
);
539 if (revcode
== UNKNOWN
)
544 INSN_COND (insn
) = cond
;
545 INSN_REVERSE_COND (insn
) = true;
552 /* True when we can find a condition under which INSN is executed. */
554 sched_has_condition_p (const_rtx insn
)
556 return !! sched_get_condition_with_rev (insn
, NULL
);
561 /* Return nonzero if conditions COND1 and COND2 can never be both true. */
563 conditions_mutex_p (const_rtx cond1
, const_rtx cond2
, bool rev1
, bool rev2
)
565 if (COMPARISON_P (cond1
)
566 && COMPARISON_P (cond2
)
567 && GET_CODE (cond1
) ==
569 ? reversed_comparison_code (cond2
, NULL
)
571 && XEXP (cond1
, 0) == XEXP (cond2
, 0)
572 && XEXP (cond1
, 1) == XEXP (cond2
, 1))
577 /* Return true if insn1 and insn2 can never depend on one another because
578 the conditions under which they are executed are mutually exclusive. */
580 sched_insns_conditions_mutex_p (const_rtx insn1
, const_rtx insn2
)
583 bool rev1
= false, rev2
= false;
585 /* df doesn't handle conditional lifetimes entirely correctly;
586 calls mess up the conditional lifetimes. */
587 if (!CALL_P (insn1
) && !CALL_P (insn2
))
589 cond1
= sched_get_condition_with_rev (insn1
, &rev1
);
590 cond2
= sched_get_condition_with_rev (insn2
, &rev2
);
592 && conditions_mutex_p (cond1
, cond2
, rev1
, rev2
)
593 /* Make sure first instruction doesn't affect condition of second
594 instruction if switched. */
595 && !modified_in_p (cond1
, insn2
)
596 /* Make sure second instruction doesn't affect condition of first
597 instruction if switched. */
598 && !modified_in_p (cond2
, insn1
))
605 /* Return true if INSN can potentially be speculated with type DS. */
607 sched_insn_is_legitimate_for_speculation_p (const_rtx insn
, ds_t ds
)
609 if (HAS_INTERNAL_DEP (insn
))
612 if (!NONJUMP_INSN_P (insn
))
615 if (SCHED_GROUP_P (insn
))
618 if (IS_SPECULATION_CHECK_P (CONST_CAST_RTX (insn
)))
621 if (side_effects_p (PATTERN (insn
)))
625 /* The following instructions, which depend on a speculatively scheduled
626 instruction, cannot be speculatively scheduled along. */
628 if (may_trap_or_fault_p (PATTERN (insn
)))
629 /* If instruction might fault, it cannot be speculatively scheduled.
630 For control speculation it's obvious why and for data speculation
631 it's because the insn might get wrong input if speculation
632 wasn't successful. */
635 if ((ds
& BE_IN_DATA
)
636 && sched_has_condition_p (insn
))
637 /* If this is a predicated instruction, then it cannot be
638 speculatively scheduled. See PR35659. */
645 /* Initialize LIST_PTR to point to one of the lists present in TYPES_PTR,
646 initialize RESOLVED_P_PTR with true if that list consists of resolved deps,
647 and remove the type of returned [through LIST_PTR] list from TYPES_PTR.
648 This function is used to switch sd_iterator to the next list.
649 !!! For internal use only. Might consider moving it to sched-int.h. */
651 sd_next_list (const_rtx insn
, sd_list_types_def
*types_ptr
,
652 deps_list_t
*list_ptr
, bool *resolved_p_ptr
)
654 sd_list_types_def types
= *types_ptr
;
656 if (types
& SD_LIST_HARD_BACK
)
658 *list_ptr
= INSN_HARD_BACK_DEPS (insn
);
659 *resolved_p_ptr
= false;
660 *types_ptr
= types
& ~SD_LIST_HARD_BACK
;
662 else if (types
& SD_LIST_SPEC_BACK
)
664 *list_ptr
= INSN_SPEC_BACK_DEPS (insn
);
665 *resolved_p_ptr
= false;
666 *types_ptr
= types
& ~SD_LIST_SPEC_BACK
;
668 else if (types
& SD_LIST_FORW
)
670 *list_ptr
= INSN_FORW_DEPS (insn
);
671 *resolved_p_ptr
= false;
672 *types_ptr
= types
& ~SD_LIST_FORW
;
674 else if (types
& SD_LIST_RES_BACK
)
676 *list_ptr
= INSN_RESOLVED_BACK_DEPS (insn
);
677 *resolved_p_ptr
= true;
678 *types_ptr
= types
& ~SD_LIST_RES_BACK
;
680 else if (types
& SD_LIST_RES_FORW
)
682 *list_ptr
= INSN_RESOLVED_FORW_DEPS (insn
);
683 *resolved_p_ptr
= true;
684 *types_ptr
= types
& ~SD_LIST_RES_FORW
;
689 *resolved_p_ptr
= false;
690 *types_ptr
= SD_LIST_NONE
;
694 /* Return the summary size of INSN's lists defined by LIST_TYPES. */
696 sd_lists_size (const_rtx insn
, sd_list_types_def list_types
)
700 while (list_types
!= SD_LIST_NONE
)
705 sd_next_list (insn
, &list_types
, &list
, &resolved_p
);
707 size
+= DEPS_LIST_N_LINKS (list
);
713 /* Return true if INSN's lists defined by LIST_TYPES are all empty. */
716 sd_lists_empty_p (const_rtx insn
, sd_list_types_def list_types
)
718 while (list_types
!= SD_LIST_NONE
)
723 sd_next_list (insn
, &list_types
, &list
, &resolved_p
);
724 if (!deps_list_empty_p (list
))
731 /* Initialize data for INSN. */
733 sd_init_insn (rtx insn
)
735 INSN_HARD_BACK_DEPS (insn
) = create_deps_list ();
736 INSN_SPEC_BACK_DEPS (insn
) = create_deps_list ();
737 INSN_RESOLVED_BACK_DEPS (insn
) = create_deps_list ();
738 INSN_FORW_DEPS (insn
) = create_deps_list ();
739 INSN_RESOLVED_FORW_DEPS (insn
) = create_deps_list ();
741 /* ??? It would be nice to allocate dependency caches here. */
744 /* Free data for INSN. */
746 sd_finish_insn (rtx insn
)
748 /* ??? It would be nice to deallocate dependency caches here. */
750 free_deps_list (INSN_HARD_BACK_DEPS (insn
));
751 INSN_HARD_BACK_DEPS (insn
) = NULL
;
753 free_deps_list (INSN_SPEC_BACK_DEPS (insn
));
754 INSN_SPEC_BACK_DEPS (insn
) = NULL
;
756 free_deps_list (INSN_RESOLVED_BACK_DEPS (insn
));
757 INSN_RESOLVED_BACK_DEPS (insn
) = NULL
;
759 free_deps_list (INSN_FORW_DEPS (insn
));
760 INSN_FORW_DEPS (insn
) = NULL
;
762 free_deps_list (INSN_RESOLVED_FORW_DEPS (insn
));
763 INSN_RESOLVED_FORW_DEPS (insn
) = NULL
;
766 /* Find a dependency between producer PRO and consumer CON.
767 Search through resolved dependency lists if RESOLVED_P is true.
768 If no such dependency is found return NULL,
769 otherwise return the dependency and initialize SD_IT_PTR [if it is nonnull]
770 with an iterator pointing to it. */
772 sd_find_dep_between_no_cache (rtx pro
, rtx con
, bool resolved_p
,
773 sd_iterator_def
*sd_it_ptr
)
775 sd_list_types_def pro_list_type
;
776 sd_list_types_def con_list_type
;
777 sd_iterator_def sd_it
;
779 bool found_p
= false;
783 pro_list_type
= SD_LIST_RES_FORW
;
784 con_list_type
= SD_LIST_RES_BACK
;
788 pro_list_type
= SD_LIST_FORW
;
789 con_list_type
= SD_LIST_BACK
;
792 /* Walk through either back list of INSN or forw list of ELEM
793 depending on which one is shorter. */
794 if (sd_lists_size (con
, con_list_type
) < sd_lists_size (pro
, pro_list_type
))
796 /* Find the dep_link with producer PRO in consumer's back_deps. */
797 FOR_EACH_DEP (con
, con_list_type
, sd_it
, dep
)
798 if (DEP_PRO (dep
) == pro
)
806 /* Find the dep_link with consumer CON in producer's forw_deps. */
807 FOR_EACH_DEP (pro
, pro_list_type
, sd_it
, dep
)
808 if (DEP_CON (dep
) == con
)
817 if (sd_it_ptr
!= NULL
)
826 /* Find a dependency between producer PRO and consumer CON.
827 Use dependency [if available] to check if dependency is present at all.
828 Search through resolved dependency lists if RESOLVED_P is true.
829 If the dependency or NULL if none found. */
831 sd_find_dep_between (rtx pro
, rtx con
, bool resolved_p
)
833 if (true_dependency_cache
!= NULL
)
834 /* Avoiding the list walk below can cut compile times dramatically
837 int elem_luid
= INSN_LUID (pro
);
838 int insn_luid
= INSN_LUID (con
);
840 gcc_assert (output_dependency_cache
!= NULL
841 && anti_dependency_cache
!= NULL
);
843 if (!bitmap_bit_p (&true_dependency_cache
[insn_luid
], elem_luid
)
844 && !bitmap_bit_p (&output_dependency_cache
[insn_luid
], elem_luid
)
845 && !bitmap_bit_p (&anti_dependency_cache
[insn_luid
], elem_luid
))
849 return sd_find_dep_between_no_cache (pro
, con
, resolved_p
, NULL
);
852 /* Add or update a dependence described by DEP.
853 MEM1 and MEM2, if non-null, correspond to memory locations in case of
856 The function returns a value indicating if an old entry has been changed
857 or a new entry has been added to insn's backward deps.
859 This function merely checks if producer and consumer is the same insn
860 and doesn't create a dep in this case. Actual manipulation of
861 dependence data structures is performed in add_or_update_dep_1. */
862 static enum DEPS_ADJUST_RESULT
863 maybe_add_or_update_dep_1 (dep_t dep
, bool resolved_p
, rtx mem1
, rtx mem2
)
865 rtx elem
= DEP_PRO (dep
);
866 rtx insn
= DEP_CON (dep
);
868 gcc_assert (INSN_P (insn
) && INSN_P (elem
));
870 /* Don't depend an insn on itself. */
873 if (sched_deps_info
->generate_spec_deps
)
874 /* INSN has an internal dependence, which we can't overcome. */
875 HAS_INTERNAL_DEP (insn
) = 1;
880 return add_or_update_dep_1 (dep
, resolved_p
, mem1
, mem2
);
883 /* Ask dependency caches what needs to be done for dependence DEP.
884 Return DEP_CREATED if new dependence should be created and there is no
885 need to try to find one searching the dependencies lists.
886 Return DEP_PRESENT if there already is a dependence described by DEP and
887 hence nothing is to be done.
888 Return DEP_CHANGED if there already is a dependence, but it should be
889 updated to incorporate additional information from DEP. */
890 static enum DEPS_ADJUST_RESULT
891 ask_dependency_caches (dep_t dep
)
893 int elem_luid
= INSN_LUID (DEP_PRO (dep
));
894 int insn_luid
= INSN_LUID (DEP_CON (dep
));
896 gcc_assert (true_dependency_cache
!= NULL
897 && output_dependency_cache
!= NULL
898 && anti_dependency_cache
!= NULL
);
900 if (!(current_sched_info
->flags
& USE_DEPS_LIST
))
902 enum reg_note present_dep_type
;
904 if (bitmap_bit_p (&true_dependency_cache
[insn_luid
], elem_luid
))
905 present_dep_type
= REG_DEP_TRUE
;
906 else if (bitmap_bit_p (&output_dependency_cache
[insn_luid
], elem_luid
))
907 present_dep_type
= REG_DEP_OUTPUT
;
908 else if (bitmap_bit_p (&anti_dependency_cache
[insn_luid
], elem_luid
))
909 present_dep_type
= REG_DEP_ANTI
;
911 /* There is no existing dep so it should be created. */
914 if ((int) DEP_TYPE (dep
) >= (int) present_dep_type
)
915 /* DEP does not add anything to the existing dependence. */
920 ds_t present_dep_types
= 0;
922 if (bitmap_bit_p (&true_dependency_cache
[insn_luid
], elem_luid
))
923 present_dep_types
|= DEP_TRUE
;
924 if (bitmap_bit_p (&output_dependency_cache
[insn_luid
], elem_luid
))
925 present_dep_types
|= DEP_OUTPUT
;
926 if (bitmap_bit_p (&anti_dependency_cache
[insn_luid
], elem_luid
))
927 present_dep_types
|= DEP_ANTI
;
929 if (present_dep_types
== 0)
930 /* There is no existing dep so it should be created. */
933 if (!(current_sched_info
->flags
& DO_SPECULATION
)
934 || !bitmap_bit_p (&spec_dependency_cache
[insn_luid
], elem_luid
))
936 if ((present_dep_types
| (DEP_STATUS (dep
) & DEP_TYPES
))
937 == present_dep_types
)
938 /* DEP does not add anything to the existing dependence. */
943 /* Only true dependencies can be data speculative and
944 only anti dependencies can be control speculative. */
945 gcc_assert ((present_dep_types
& (DEP_TRUE
| DEP_ANTI
))
946 == present_dep_types
);
948 /* if (DEP is SPECULATIVE) then
949 ..we should update DEP_STATUS
951 ..we should reset existing dep to non-speculative. */
958 /* Set dependency caches according to DEP. */
960 set_dependency_caches (dep_t dep
)
962 int elem_luid
= INSN_LUID (DEP_PRO (dep
));
963 int insn_luid
= INSN_LUID (DEP_CON (dep
));
965 if (!(current_sched_info
->flags
& USE_DEPS_LIST
))
967 switch (DEP_TYPE (dep
))
970 bitmap_set_bit (&true_dependency_cache
[insn_luid
], elem_luid
);
974 bitmap_set_bit (&output_dependency_cache
[insn_luid
], elem_luid
);
978 bitmap_set_bit (&anti_dependency_cache
[insn_luid
], elem_luid
);
987 ds_t ds
= DEP_STATUS (dep
);
990 bitmap_set_bit (&true_dependency_cache
[insn_luid
], elem_luid
);
992 bitmap_set_bit (&output_dependency_cache
[insn_luid
], elem_luid
);
994 bitmap_set_bit (&anti_dependency_cache
[insn_luid
], elem_luid
);
996 if (ds
& SPECULATIVE
)
998 gcc_assert (current_sched_info
->flags
& DO_SPECULATION
);
999 bitmap_set_bit (&spec_dependency_cache
[insn_luid
], elem_luid
);
1004 /* Type of dependence DEP have changed from OLD_TYPE. Update dependency
1005 caches accordingly. */
1007 update_dependency_caches (dep_t dep
, enum reg_note old_type
)
1009 int elem_luid
= INSN_LUID (DEP_PRO (dep
));
1010 int insn_luid
= INSN_LUID (DEP_CON (dep
));
1012 /* Clear corresponding cache entry because type of the link
1013 may have changed. Keep them if we use_deps_list. */
1014 if (!(current_sched_info
->flags
& USE_DEPS_LIST
))
1018 case REG_DEP_OUTPUT
:
1019 bitmap_clear_bit (&output_dependency_cache
[insn_luid
], elem_luid
);
1023 bitmap_clear_bit (&anti_dependency_cache
[insn_luid
], elem_luid
);
1031 set_dependency_caches (dep
);
1034 /* Convert a dependence pointed to by SD_IT to be non-speculative. */
1036 change_spec_dep_to_hard (sd_iterator_def sd_it
)
1038 dep_node_t node
= DEP_LINK_NODE (*sd_it
.linkp
);
1039 dep_link_t link
= DEP_NODE_BACK (node
);
1040 dep_t dep
= DEP_NODE_DEP (node
);
1041 rtx elem
= DEP_PRO (dep
);
1042 rtx insn
= DEP_CON (dep
);
1044 move_dep_link (link
, INSN_SPEC_BACK_DEPS (insn
), INSN_HARD_BACK_DEPS (insn
));
1046 DEP_STATUS (dep
) &= ~SPECULATIVE
;
1048 if (true_dependency_cache
!= NULL
)
1049 /* Clear the cache entry. */
1050 bitmap_clear_bit (&spec_dependency_cache
[INSN_LUID (insn
)],
1054 /* Update DEP to incorporate information from NEW_DEP.
1055 SD_IT points to DEP in case it should be moved to another list.
1056 MEM1 and MEM2, if nonnull, correspond to memory locations in case if
1057 data-speculative dependence should be updated. */
1058 static enum DEPS_ADJUST_RESULT
1059 update_dep (dep_t dep
, dep_t new_dep
,
1060 sd_iterator_def sd_it ATTRIBUTE_UNUSED
,
1061 rtx mem1 ATTRIBUTE_UNUSED
,
1062 rtx mem2 ATTRIBUTE_UNUSED
)
1064 enum DEPS_ADJUST_RESULT res
= DEP_PRESENT
;
1065 enum reg_note old_type
= DEP_TYPE (dep
);
1067 /* If this is a more restrictive type of dependence than the
1068 existing one, then change the existing dependence to this
1070 if ((int) DEP_TYPE (new_dep
) < (int) old_type
)
1072 DEP_TYPE (dep
) = DEP_TYPE (new_dep
);
1076 if (current_sched_info
->flags
& USE_DEPS_LIST
)
1077 /* Update DEP_STATUS. */
1079 ds_t dep_status
= DEP_STATUS (dep
);
1080 ds_t ds
= DEP_STATUS (new_dep
);
1081 ds_t new_status
= ds
| dep_status
;
1083 if (new_status
& SPECULATIVE
)
1084 /* Either existing dep or a dep we're adding or both are
1087 if (!(ds
& SPECULATIVE
)
1088 || !(dep_status
& SPECULATIVE
))
1089 /* The new dep can't be speculative. */
1091 new_status
&= ~SPECULATIVE
;
1093 if (dep_status
& SPECULATIVE
)
1094 /* The old dep was speculative, but now it
1096 change_spec_dep_to_hard (sd_it
);
1100 /* Both are speculative. Merge probabilities. */
1105 dw
= estimate_dep_weak (mem1
, mem2
);
1106 ds
= set_dep_weak (ds
, BEGIN_DATA
, dw
);
1109 new_status
= ds_merge (dep_status
, ds
);
1115 if (dep_status
!= ds
)
1117 DEP_STATUS (dep
) = ds
;
1122 if (true_dependency_cache
!= NULL
1123 && res
== DEP_CHANGED
)
1124 update_dependency_caches (dep
, old_type
);
1129 /* Add or update a dependence described by DEP.
1130 MEM1 and MEM2, if non-null, correspond to memory locations in case of
1133 The function returns a value indicating if an old entry has been changed
1134 or a new entry has been added to insn's backward deps or nothing has
1135 been updated at all. */
1136 static enum DEPS_ADJUST_RESULT
1137 add_or_update_dep_1 (dep_t new_dep
, bool resolved_p
,
1138 rtx mem1 ATTRIBUTE_UNUSED
, rtx mem2 ATTRIBUTE_UNUSED
)
1140 bool maybe_present_p
= true;
1141 bool present_p
= false;
1143 gcc_assert (INSN_P (DEP_PRO (new_dep
)) && INSN_P (DEP_CON (new_dep
))
1144 && DEP_PRO (new_dep
) != DEP_CON (new_dep
));
1146 #ifdef ENABLE_CHECKING
1147 check_dep (new_dep
, mem1
!= NULL
);
1150 if (true_dependency_cache
!= NULL
)
1152 switch (ask_dependency_caches (new_dep
))
1158 maybe_present_p
= true;
1163 maybe_present_p
= false;
1173 /* Check that we don't already have this dependence. */
1174 if (maybe_present_p
)
1177 sd_iterator_def sd_it
;
1179 gcc_assert (true_dependency_cache
== NULL
|| present_p
);
1181 present_dep
= sd_find_dep_between_no_cache (DEP_PRO (new_dep
),
1183 resolved_p
, &sd_it
);
1185 if (present_dep
!= NULL
)
1186 /* We found an existing dependency between ELEM and INSN. */
1187 return update_dep (present_dep
, new_dep
, sd_it
, mem1
, mem2
);
1189 /* We didn't find a dep, it shouldn't present in the cache. */
1190 gcc_assert (!present_p
);
1193 /* Might want to check one level of transitivity to save conses.
1194 This check should be done in maybe_add_or_update_dep_1.
1195 Since we made it to add_or_update_dep_1, we must create
1196 (or update) a link. */
1198 if (mem1
!= NULL_RTX
)
1200 gcc_assert (sched_deps_info
->generate_spec_deps
);
1201 DEP_STATUS (new_dep
) = set_dep_weak (DEP_STATUS (new_dep
), BEGIN_DATA
,
1202 estimate_dep_weak (mem1
, mem2
));
1205 sd_add_dep (new_dep
, resolved_p
);
1210 /* Initialize BACK_LIST_PTR with consumer's backward list and
1211 FORW_LIST_PTR with producer's forward list. If RESOLVED_P is true
1212 initialize with lists that hold resolved deps. */
1214 get_back_and_forw_lists (dep_t dep
, bool resolved_p
,
1215 deps_list_t
*back_list_ptr
,
1216 deps_list_t
*forw_list_ptr
)
1218 rtx con
= DEP_CON (dep
);
1222 if ((current_sched_info
->flags
& DO_SPECULATION
)
1223 && (DEP_STATUS (dep
) & SPECULATIVE
))
1224 *back_list_ptr
= INSN_SPEC_BACK_DEPS (con
);
1226 *back_list_ptr
= INSN_HARD_BACK_DEPS (con
);
1228 *forw_list_ptr
= INSN_FORW_DEPS (DEP_PRO (dep
));
1232 *back_list_ptr
= INSN_RESOLVED_BACK_DEPS (con
);
1233 *forw_list_ptr
= INSN_RESOLVED_FORW_DEPS (DEP_PRO (dep
));
1237 /* Add dependence described by DEP.
1238 If RESOLVED_P is true treat the dependence as a resolved one. */
1240 sd_add_dep (dep_t dep
, bool resolved_p
)
1242 dep_node_t n
= create_dep_node ();
1243 deps_list_t con_back_deps
;
1244 deps_list_t pro_forw_deps
;
1245 rtx elem
= DEP_PRO (dep
);
1246 rtx insn
= DEP_CON (dep
);
1248 gcc_assert (INSN_P (insn
) && INSN_P (elem
) && insn
!= elem
);
1250 if ((current_sched_info
->flags
& DO_SPECULATION
)
1251 && !sched_insn_is_legitimate_for_speculation_p (insn
, DEP_STATUS (dep
)))
1252 DEP_STATUS (dep
) &= ~SPECULATIVE
;
1254 copy_dep (DEP_NODE_DEP (n
), dep
);
1256 get_back_and_forw_lists (dep
, resolved_p
, &con_back_deps
, &pro_forw_deps
);
1258 add_to_deps_list (DEP_NODE_BACK (n
), con_back_deps
);
1260 #ifdef ENABLE_CHECKING
1261 check_dep (dep
, false);
1264 add_to_deps_list (DEP_NODE_FORW (n
), pro_forw_deps
);
1266 /* If we are adding a dependency to INSN's LOG_LINKs, then note that
1267 in the bitmap caches of dependency information. */
1268 if (true_dependency_cache
!= NULL
)
1269 set_dependency_caches (dep
);
1272 /* Add or update backward dependence between INSN and ELEM
1273 with given type DEP_TYPE and dep_status DS.
1274 This function is a convenience wrapper. */
1275 enum DEPS_ADJUST_RESULT
1276 sd_add_or_update_dep (dep_t dep
, bool resolved_p
)
1278 return add_or_update_dep_1 (dep
, resolved_p
, NULL_RTX
, NULL_RTX
);
1281 /* Resolved dependence pointed to by SD_IT.
1282 SD_IT will advance to the next element. */
1284 sd_resolve_dep (sd_iterator_def sd_it
)
1286 dep_node_t node
= DEP_LINK_NODE (*sd_it
.linkp
);
1287 dep_t dep
= DEP_NODE_DEP (node
);
1288 rtx pro
= DEP_PRO (dep
);
1289 rtx con
= DEP_CON (dep
);
1291 if ((current_sched_info
->flags
& DO_SPECULATION
)
1292 && (DEP_STATUS (dep
) & SPECULATIVE
))
1293 move_dep_link (DEP_NODE_BACK (node
), INSN_SPEC_BACK_DEPS (con
),
1294 INSN_RESOLVED_BACK_DEPS (con
));
1296 move_dep_link (DEP_NODE_BACK (node
), INSN_HARD_BACK_DEPS (con
),
1297 INSN_RESOLVED_BACK_DEPS (con
));
1299 move_dep_link (DEP_NODE_FORW (node
), INSN_FORW_DEPS (pro
),
1300 INSN_RESOLVED_FORW_DEPS (pro
));
1303 /* Make TO depend on all the FROM's producers.
1304 If RESOLVED_P is true add dependencies to the resolved lists. */
1306 sd_copy_back_deps (rtx to
, rtx from
, bool resolved_p
)
1308 sd_list_types_def list_type
;
1309 sd_iterator_def sd_it
;
1312 list_type
= resolved_p
? SD_LIST_RES_BACK
: SD_LIST_BACK
;
1314 FOR_EACH_DEP (from
, list_type
, sd_it
, dep
)
1316 dep_def _new_dep
, *new_dep
= &_new_dep
;
1318 copy_dep (new_dep
, dep
);
1319 DEP_CON (new_dep
) = to
;
1320 sd_add_dep (new_dep
, resolved_p
);
1324 /* Remove a dependency referred to by SD_IT.
1325 SD_IT will point to the next dependence after removal. */
1327 sd_delete_dep (sd_iterator_def sd_it
)
1329 dep_node_t n
= DEP_LINK_NODE (*sd_it
.linkp
);
1330 dep_t dep
= DEP_NODE_DEP (n
);
1331 rtx pro
= DEP_PRO (dep
);
1332 rtx con
= DEP_CON (dep
);
1333 deps_list_t con_back_deps
;
1334 deps_list_t pro_forw_deps
;
1336 if (true_dependency_cache
!= NULL
)
1338 int elem_luid
= INSN_LUID (pro
);
1339 int insn_luid
= INSN_LUID (con
);
1341 bitmap_clear_bit (&true_dependency_cache
[insn_luid
], elem_luid
);
1342 bitmap_clear_bit (&anti_dependency_cache
[insn_luid
], elem_luid
);
1343 bitmap_clear_bit (&output_dependency_cache
[insn_luid
], elem_luid
);
1345 if (current_sched_info
->flags
& DO_SPECULATION
)
1346 bitmap_clear_bit (&spec_dependency_cache
[insn_luid
], elem_luid
);
1349 get_back_and_forw_lists (dep
, sd_it
.resolved_p
,
1350 &con_back_deps
, &pro_forw_deps
);
1352 remove_from_deps_list (DEP_NODE_BACK (n
), con_back_deps
);
1353 remove_from_deps_list (DEP_NODE_FORW (n
), pro_forw_deps
);
1355 delete_dep_node (n
);
1358 /* Dump size of the lists. */
1359 #define DUMP_LISTS_SIZE (2)
1361 /* Dump dependencies of the lists. */
1362 #define DUMP_LISTS_DEPS (4)
1364 /* Dump all information about the lists. */
1365 #define DUMP_LISTS_ALL (DUMP_LISTS_SIZE | DUMP_LISTS_DEPS)
1367 /* Dump deps_lists of INSN specified by TYPES to DUMP.
1368 FLAGS is a bit mask specifying what information about the lists needs
1370 If FLAGS has the very first bit set, then dump all information about
1371 the lists and propagate this bit into the callee dump functions. */
1373 dump_lists (FILE *dump
, rtx insn
, sd_list_types_def types
, int flags
)
1375 sd_iterator_def sd_it
;
1382 flags
|= DUMP_LISTS_ALL
;
1384 fprintf (dump
, "[");
1386 if (flags
& DUMP_LISTS_SIZE
)
1387 fprintf (dump
, "%d; ", sd_lists_size (insn
, types
));
1389 if (flags
& DUMP_LISTS_DEPS
)
1391 FOR_EACH_DEP (insn
, types
, sd_it
, dep
)
1393 dump_dep (dump
, dep
, dump_dep_flags
| all
);
1394 fprintf (dump
, " ");
1399 /* Dump all information about deps_lists of INSN specified by TYPES
1402 sd_debug_lists (rtx insn
, sd_list_types_def types
)
1404 dump_lists (stderr
, insn
, types
, 1);
1405 fprintf (stderr
, "\n");
1408 /* A convenience wrapper to operate on an entire list. */
1411 add_dependence_list (rtx insn
, rtx list
, int uncond
, enum reg_note dep_type
)
1413 for (; list
; list
= XEXP (list
, 1))
1415 if (uncond
|| ! sched_insns_conditions_mutex_p (insn
, XEXP (list
, 0)))
1416 add_dependence (insn
, XEXP (list
, 0), dep_type
);
1420 /* Similar, but free *LISTP at the same time, when the context
1424 add_dependence_list_and_free (struct deps_desc
*deps
, rtx insn
, rtx
*listp
,
1425 int uncond
, enum reg_note dep_type
)
1429 /* We don't want to short-circuit dependencies involving debug
1430 insns, because they may cause actual dependencies to be
1432 if (deps
->readonly
|| DEBUG_INSN_P (insn
))
1434 add_dependence_list (insn
, *listp
, uncond
, dep_type
);
1438 for (list
= *listp
, *listp
= NULL
; list
; list
= next
)
1440 next
= XEXP (list
, 1);
1441 if (uncond
|| ! sched_insns_conditions_mutex_p (insn
, XEXP (list
, 0)))
1442 add_dependence (insn
, XEXP (list
, 0), dep_type
);
1443 free_INSN_LIST_node (list
);
1447 /* Remove all occurences of INSN from LIST. Return the number of
1448 occurences removed. */
1451 remove_from_dependence_list (rtx insn
, rtx
* listp
)
1457 if (XEXP (*listp
, 0) == insn
)
1459 remove_free_INSN_LIST_node (listp
);
1464 listp
= &XEXP (*listp
, 1);
1470 /* Same as above, but process two lists at once. */
1472 remove_from_both_dependence_lists (rtx insn
, rtx
*listp
, rtx
*exprp
)
1478 if (XEXP (*listp
, 0) == insn
)
1480 remove_free_INSN_LIST_node (listp
);
1481 remove_free_EXPR_LIST_node (exprp
);
1486 listp
= &XEXP (*listp
, 1);
1487 exprp
= &XEXP (*exprp
, 1);
1493 /* Clear all dependencies for an insn. */
1495 delete_all_dependences (rtx insn
)
1497 sd_iterator_def sd_it
;
1500 /* The below cycle can be optimized to clear the caches and back_deps
1501 in one call but that would provoke duplication of code from
1504 for (sd_it
= sd_iterator_start (insn
, SD_LIST_BACK
);
1505 sd_iterator_cond (&sd_it
, &dep
);)
1506 sd_delete_dep (sd_it
);
1509 /* All insns in a scheduling group except the first should only have
1510 dependencies on the previous insn in the group. So we find the
1511 first instruction in the scheduling group by walking the dependence
1512 chains backwards. Then we add the dependencies for the group to
1513 the previous nonnote insn. */
1516 fixup_sched_groups (rtx insn
)
1518 sd_iterator_def sd_it
;
1522 FOR_EACH_DEP (insn
, SD_LIST_BACK
, sd_it
, dep
)
1525 rtx pro
= DEP_PRO (dep
);
1529 i
= prev_nonnote_insn (i
);
1533 } while (SCHED_GROUP_P (i
) || DEBUG_INSN_P (i
));
1535 if (! sched_insns_conditions_mutex_p (i
, pro
))
1536 add_dependence (i
, pro
, DEP_TYPE (dep
));
1540 delete_all_dependences (insn
);
1542 prev_nonnote
= prev_nonnote_nondebug_insn (insn
);
1543 if (BLOCK_FOR_INSN (insn
) == BLOCK_FOR_INSN (prev_nonnote
)
1544 && ! sched_insns_conditions_mutex_p (insn
, prev_nonnote
))
1545 add_dependence (insn
, prev_nonnote
, REG_DEP_ANTI
);
1548 /* Process an insn's memory dependencies. There are four kinds of
1551 (0) read dependence: read follows read
1552 (1) true dependence: read follows write
1553 (2) output dependence: write follows write
1554 (3) anti dependence: write follows read
1556 We are careful to build only dependencies which actually exist, and
1557 use transitivity to avoid building too many links. */
1559 /* Add an INSN and MEM reference pair to a pending INSN_LIST and MEM_LIST.
1560 The MEM is a memory reference contained within INSN, which we are saving
1561 so that we can do memory aliasing on it. */
1564 add_insn_mem_dependence (struct deps_desc
*deps
, bool read_p
,
1571 gcc_assert (!deps
->readonly
);
1574 insn_list
= &deps
->pending_read_insns
;
1575 mem_list
= &deps
->pending_read_mems
;
1576 if (!DEBUG_INSN_P (insn
))
1577 deps
->pending_read_list_length
++;
1581 insn_list
= &deps
->pending_write_insns
;
1582 mem_list
= &deps
->pending_write_mems
;
1583 deps
->pending_write_list_length
++;
1586 link
= alloc_INSN_LIST (insn
, *insn_list
);
1589 if (sched_deps_info
->use_cselib
)
1591 mem
= shallow_copy_rtx (mem
);
1592 XEXP (mem
, 0) = cselib_subst_to_values (XEXP (mem
, 0), GET_MODE (mem
));
1594 link
= alloc_EXPR_LIST (VOIDmode
, canon_rtx (mem
), *mem_list
);
1598 /* Make a dependency between every memory reference on the pending lists
1599 and INSN, thus flushing the pending lists. FOR_READ is true if emitting
1600 dependencies for a read operation, similarly with FOR_WRITE. */
1603 flush_pending_lists (struct deps_desc
*deps
, rtx insn
, int for_read
,
1608 add_dependence_list_and_free (deps
, insn
, &deps
->pending_read_insns
,
1610 if (!deps
->readonly
)
1612 free_EXPR_LIST_list (&deps
->pending_read_mems
);
1613 deps
->pending_read_list_length
= 0;
1617 add_dependence_list_and_free (deps
, insn
, &deps
->pending_write_insns
, 1,
1618 for_read
? REG_DEP_ANTI
: REG_DEP_OUTPUT
);
1620 add_dependence_list_and_free (deps
, insn
,
1621 &deps
->last_pending_memory_flush
, 1,
1622 for_read
? REG_DEP_ANTI
: REG_DEP_OUTPUT
);
1623 if (!deps
->readonly
)
1625 free_EXPR_LIST_list (&deps
->pending_write_mems
);
1626 deps
->pending_write_list_length
= 0;
1628 deps
->last_pending_memory_flush
= alloc_INSN_LIST (insn
, NULL_RTX
);
1629 deps
->pending_flush_length
= 1;
1633 /* Instruction which dependencies we are analyzing. */
1634 static rtx cur_insn
= NULL_RTX
;
1636 /* Implement hooks for haifa scheduler. */
1639 haifa_start_insn (rtx insn
)
1641 gcc_assert (insn
&& !cur_insn
);
1647 haifa_finish_insn (void)
1653 haifa_note_reg_set (int regno
)
1655 SET_REGNO_REG_SET (reg_pending_sets
, regno
);
1659 haifa_note_reg_clobber (int regno
)
1661 SET_REGNO_REG_SET (reg_pending_clobbers
, regno
);
1665 haifa_note_reg_use (int regno
)
1667 SET_REGNO_REG_SET (reg_pending_uses
, regno
);
1671 haifa_note_mem_dep (rtx mem
, rtx pending_mem
, rtx pending_insn
, ds_t ds
)
1673 if (!(ds
& SPECULATIVE
))
1676 pending_mem
= NULL_RTX
;
1679 gcc_assert (ds
& BEGIN_DATA
);
1682 dep_def _dep
, *dep
= &_dep
;
1684 init_dep_1 (dep
, pending_insn
, cur_insn
, ds_to_dt (ds
),
1685 current_sched_info
->flags
& USE_DEPS_LIST
? ds
: -1);
1686 maybe_add_or_update_dep_1 (dep
, false, pending_mem
, mem
);
1692 haifa_note_dep (rtx elem
, ds_t ds
)
1697 init_dep (dep
, elem
, cur_insn
, ds_to_dt (ds
));
1698 maybe_add_or_update_dep_1 (dep
, false, NULL_RTX
, NULL_RTX
);
1702 note_reg_use (int r
)
1704 if (sched_deps_info
->note_reg_use
)
1705 sched_deps_info
->note_reg_use (r
);
1709 note_reg_set (int r
)
1711 if (sched_deps_info
->note_reg_set
)
1712 sched_deps_info
->note_reg_set (r
);
1716 note_reg_clobber (int r
)
1718 if (sched_deps_info
->note_reg_clobber
)
1719 sched_deps_info
->note_reg_clobber (r
);
1723 note_mem_dep (rtx m1
, rtx m2
, rtx e
, ds_t ds
)
1725 if (sched_deps_info
->note_mem_dep
)
1726 sched_deps_info
->note_mem_dep (m1
, m2
, e
, ds
);
1730 note_dep (rtx e
, ds_t ds
)
1732 if (sched_deps_info
->note_dep
)
1733 sched_deps_info
->note_dep (e
, ds
);
1736 /* Return corresponding to DS reg_note. */
1741 return REG_DEP_TRUE
;
1742 else if (ds
& DEP_OUTPUT
)
1743 return REG_DEP_OUTPUT
;
1746 gcc_assert (ds
& DEP_ANTI
);
1747 return REG_DEP_ANTI
;
1753 /* Functions for computation of info needed for register pressure
1754 sensitive insn scheduling. */
1757 /* Allocate and return reg_use_data structure for REGNO and INSN. */
1758 static struct reg_use_data
*
1759 create_insn_reg_use (int regno
, rtx insn
)
1761 struct reg_use_data
*use
;
1763 use
= (struct reg_use_data
*) xmalloc (sizeof (struct reg_use_data
));
1766 use
->next_insn_use
= INSN_REG_USE_LIST (insn
);
1767 INSN_REG_USE_LIST (insn
) = use
;
1771 /* Allocate and return reg_set_data structure for REGNO and INSN. */
1772 static struct reg_set_data
*
1773 create_insn_reg_set (int regno
, rtx insn
)
1775 struct reg_set_data
*set
;
1777 set
= (struct reg_set_data
*) xmalloc (sizeof (struct reg_set_data
));
1780 set
->next_insn_set
= INSN_REG_SET_LIST (insn
);
1781 INSN_REG_SET_LIST (insn
) = set
;
1785 /* Set up insn register uses for INSN and dependency context DEPS. */
1787 setup_insn_reg_uses (struct deps_desc
*deps
, rtx insn
)
1790 reg_set_iterator rsi
;
1792 struct reg_use_data
*use
, *use2
, *next
;
1793 struct deps_reg
*reg_last
;
1795 EXECUTE_IF_SET_IN_REG_SET (reg_pending_uses
, 0, i
, rsi
)
1797 if (i
< FIRST_PSEUDO_REGISTER
1798 && TEST_HARD_REG_BIT (ira_no_alloc_regs
, i
))
1801 if (find_regno_note (insn
, REG_DEAD
, i
) == NULL_RTX
1802 && ! REGNO_REG_SET_P (reg_pending_sets
, i
)
1803 && ! REGNO_REG_SET_P (reg_pending_clobbers
, i
))
1804 /* Ignore use which is not dying. */
1807 use
= create_insn_reg_use (i
, insn
);
1808 use
->next_regno_use
= use
;
1809 reg_last
= &deps
->reg_last
[i
];
1811 /* Create the cycle list of uses. */
1812 for (list
= reg_last
->uses
; list
; list
= XEXP (list
, 1))
1814 use2
= create_insn_reg_use (i
, XEXP (list
, 0));
1815 next
= use
->next_regno_use
;
1816 use
->next_regno_use
= use2
;
1817 use2
->next_regno_use
= next
;
1822 /* Register pressure info for the currently processed insn. */
1823 static struct reg_pressure_data reg_pressure_info
[N_REG_CLASSES
];
1825 /* Return TRUE if INSN has the use structure for REGNO. */
1827 insn_use_p (rtx insn
, int regno
)
1829 struct reg_use_data
*use
;
1831 for (use
= INSN_REG_USE_LIST (insn
); use
!= NULL
; use
= use
->next_insn_use
)
1832 if (use
->regno
== regno
)
1837 /* Update the register pressure info after birth of pseudo register REGNO
1838 in INSN. Arguments CLOBBER_P and UNUSED_P say correspondingly that
1839 the register is in clobber or unused after the insn. */
1841 mark_insn_pseudo_birth (rtx insn
, int regno
, bool clobber_p
, bool unused_p
)
1846 gcc_assert (regno
>= FIRST_PSEUDO_REGISTER
);
1847 cl
= sched_regno_pressure_class
[regno
];
1850 incr
= ira_reg_class_max_nregs
[cl
][PSEUDO_REGNO_MODE (regno
)];
1853 new_incr
= reg_pressure_info
[cl
].clobber_increase
+ incr
;
1854 reg_pressure_info
[cl
].clobber_increase
= new_incr
;
1858 new_incr
= reg_pressure_info
[cl
].unused_set_increase
+ incr
;
1859 reg_pressure_info
[cl
].unused_set_increase
= new_incr
;
1863 new_incr
= reg_pressure_info
[cl
].set_increase
+ incr
;
1864 reg_pressure_info
[cl
].set_increase
= new_incr
;
1865 if (! insn_use_p (insn
, regno
))
1866 reg_pressure_info
[cl
].change
+= incr
;
1867 create_insn_reg_set (regno
, insn
);
1869 gcc_assert (new_incr
< (1 << INCREASE_BITS
));
1873 /* Like mark_insn_pseudo_regno_birth except that NREGS saying how many
1874 hard registers involved in the birth. */
1876 mark_insn_hard_regno_birth (rtx insn
, int regno
, int nregs
,
1877 bool clobber_p
, bool unused_p
)
1880 int new_incr
, last
= regno
+ nregs
;
1882 while (regno
< last
)
1884 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
1885 if (! TEST_HARD_REG_BIT (ira_no_alloc_regs
, regno
))
1887 cl
= sched_regno_pressure_class
[regno
];
1892 new_incr
= reg_pressure_info
[cl
].clobber_increase
+ 1;
1893 reg_pressure_info
[cl
].clobber_increase
= new_incr
;
1897 new_incr
= reg_pressure_info
[cl
].unused_set_increase
+ 1;
1898 reg_pressure_info
[cl
].unused_set_increase
= new_incr
;
1902 new_incr
= reg_pressure_info
[cl
].set_increase
+ 1;
1903 reg_pressure_info
[cl
].set_increase
= new_incr
;
1904 if (! insn_use_p (insn
, regno
))
1905 reg_pressure_info
[cl
].change
+= 1;
1906 create_insn_reg_set (regno
, insn
);
1908 gcc_assert (new_incr
< (1 << INCREASE_BITS
));
1915 /* Update the register pressure info after birth of pseudo or hard
1916 register REG in INSN. Arguments CLOBBER_P and UNUSED_P say
1917 correspondingly that the register is in clobber or unused after the
1920 mark_insn_reg_birth (rtx insn
, rtx reg
, bool clobber_p
, bool unused_p
)
1924 if (GET_CODE (reg
) == SUBREG
)
1925 reg
= SUBREG_REG (reg
);
1930 regno
= REGNO (reg
);
1931 if (regno
< FIRST_PSEUDO_REGISTER
)
1932 mark_insn_hard_regno_birth (insn
, regno
,
1933 hard_regno_nregs
[regno
][GET_MODE (reg
)],
1934 clobber_p
, unused_p
);
1936 mark_insn_pseudo_birth (insn
, regno
, clobber_p
, unused_p
);
1939 /* Update the register pressure info after death of pseudo register
1942 mark_pseudo_death (int regno
)
1947 gcc_assert (regno
>= FIRST_PSEUDO_REGISTER
);
1948 cl
= sched_regno_pressure_class
[regno
];
1951 incr
= ira_reg_class_max_nregs
[cl
][PSEUDO_REGNO_MODE (regno
)];
1952 reg_pressure_info
[cl
].change
-= incr
;
1956 /* Like mark_pseudo_death except that NREGS saying how many hard
1957 registers involved in the death. */
1959 mark_hard_regno_death (int regno
, int nregs
)
1962 int last
= regno
+ nregs
;
1964 while (regno
< last
)
1966 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
1967 if (! TEST_HARD_REG_BIT (ira_no_alloc_regs
, regno
))
1969 cl
= sched_regno_pressure_class
[regno
];
1971 reg_pressure_info
[cl
].change
-= 1;
1977 /* Update the register pressure info after death of pseudo or hard
1980 mark_reg_death (rtx reg
)
1984 if (GET_CODE (reg
) == SUBREG
)
1985 reg
= SUBREG_REG (reg
);
1990 regno
= REGNO (reg
);
1991 if (regno
< FIRST_PSEUDO_REGISTER
)
1992 mark_hard_regno_death (regno
, hard_regno_nregs
[regno
][GET_MODE (reg
)]);
1994 mark_pseudo_death (regno
);
1997 /* Process SETTER of REG. DATA is an insn containing the setter. */
1999 mark_insn_reg_store (rtx reg
, const_rtx setter
, void *data
)
2001 if (setter
!= NULL_RTX
&& GET_CODE (setter
) != SET
)
2004 ((rtx
) data
, reg
, false,
2005 find_reg_note ((const_rtx
) data
, REG_UNUSED
, reg
) != NULL_RTX
);
2008 /* Like mark_insn_reg_store except notice just CLOBBERs; ignore SETs. */
2010 mark_insn_reg_clobber (rtx reg
, const_rtx setter
, void *data
)
2012 if (GET_CODE (setter
) == CLOBBER
)
2013 mark_insn_reg_birth ((rtx
) data
, reg
, true, false);
2016 /* Set up reg pressure info related to INSN. */
2018 init_insn_reg_pressure_info (rtx insn
)
2022 static struct reg_pressure_data
*pressure_info
;
2025 gcc_assert (sched_pressure_p
);
2027 if (! INSN_P (insn
))
2030 for (i
= 0; i
< ira_pressure_classes_num
; i
++)
2032 cl
= ira_pressure_classes
[i
];
2033 reg_pressure_info
[cl
].clobber_increase
= 0;
2034 reg_pressure_info
[cl
].set_increase
= 0;
2035 reg_pressure_info
[cl
].unused_set_increase
= 0;
2036 reg_pressure_info
[cl
].change
= 0;
2039 note_stores (PATTERN (insn
), mark_insn_reg_clobber
, insn
);
2041 note_stores (PATTERN (insn
), mark_insn_reg_store
, insn
);
2044 for (link
= REG_NOTES (insn
); link
; link
= XEXP (link
, 1))
2045 if (REG_NOTE_KIND (link
) == REG_INC
)
2046 mark_insn_reg_store (XEXP (link
, 0), NULL_RTX
, insn
);
2049 for (link
= REG_NOTES (insn
); link
; link
= XEXP (link
, 1))
2050 if (REG_NOTE_KIND (link
) == REG_DEAD
)
2051 mark_reg_death (XEXP (link
, 0));
2053 len
= sizeof (struct reg_pressure_data
) * ira_pressure_classes_num
;
2055 = INSN_REG_PRESSURE (insn
) = (struct reg_pressure_data
*) xmalloc (len
);
2056 INSN_MAX_REG_PRESSURE (insn
) = (int *) xcalloc (ira_pressure_classes_num
2058 for (i
= 0; i
< ira_pressure_classes_num
; i
++)
2060 cl
= ira_pressure_classes
[i
];
2061 pressure_info
[i
].clobber_increase
2062 = reg_pressure_info
[cl
].clobber_increase
;
2063 pressure_info
[i
].set_increase
= reg_pressure_info
[cl
].set_increase
;
2064 pressure_info
[i
].unused_set_increase
2065 = reg_pressure_info
[cl
].unused_set_increase
;
2066 pressure_info
[i
].change
= reg_pressure_info
[cl
].change
;
2073 /* Internal variable for sched_analyze_[12] () functions.
2074 If it is nonzero, this means that sched_analyze_[12] looks
2075 at the most toplevel SET. */
2076 static bool can_start_lhs_rhs_p
;
2078 /* Extend reg info for the deps context DEPS given that
2079 we have just generated a register numbered REGNO. */
2081 extend_deps_reg_info (struct deps_desc
*deps
, int regno
)
2083 int max_regno
= regno
+ 1;
2085 gcc_assert (!reload_completed
);
2087 /* In a readonly context, it would not hurt to extend info,
2088 but it should not be needed. */
2089 if (reload_completed
&& deps
->readonly
)
2091 deps
->max_reg
= max_regno
;
2095 if (max_regno
> deps
->max_reg
)
2097 deps
->reg_last
= XRESIZEVEC (struct deps_reg
, deps
->reg_last
,
2099 memset (&deps
->reg_last
[deps
->max_reg
],
2100 0, (max_regno
- deps
->max_reg
)
2101 * sizeof (struct deps_reg
));
2102 deps
->max_reg
= max_regno
;
2106 /* Extends REG_INFO_P if needed. */
2108 maybe_extend_reg_info_p (void)
2110 /* Extend REG_INFO_P, if needed. */
2111 if ((unsigned int)max_regno
- 1 >= reg_info_p_size
)
2113 size_t new_reg_info_p_size
= max_regno
+ 128;
2115 gcc_assert (!reload_completed
&& sel_sched_p ());
2117 reg_info_p
= (struct reg_info_t
*) xrecalloc (reg_info_p
,
2118 new_reg_info_p_size
,
2120 sizeof (*reg_info_p
));
2121 reg_info_p_size
= new_reg_info_p_size
;
2125 /* Analyze a single reference to register (reg:MODE REGNO) in INSN.
2126 The type of the reference is specified by REF and can be SET,
2127 CLOBBER, PRE_DEC, POST_DEC, PRE_INC, POST_INC or USE. */
2130 sched_analyze_reg (struct deps_desc
*deps
, int regno
, enum machine_mode mode
,
2131 enum rtx_code ref
, rtx insn
)
2133 /* We could emit new pseudos in renaming. Extend the reg structures. */
2134 if (!reload_completed
&& sel_sched_p ()
2135 && (regno
>= max_reg_num () - 1 || regno
>= deps
->max_reg
))
2136 extend_deps_reg_info (deps
, regno
);
2138 maybe_extend_reg_info_p ();
2140 /* A hard reg in a wide mode may really be multiple registers.
2141 If so, mark all of them just like the first. */
2142 if (regno
< FIRST_PSEUDO_REGISTER
)
2144 int i
= hard_regno_nregs
[regno
][mode
];
2148 note_reg_set (regno
+ i
);
2150 else if (ref
== USE
)
2153 note_reg_use (regno
+ i
);
2158 note_reg_clobber (regno
+ i
);
2162 /* ??? Reload sometimes emits USEs and CLOBBERs of pseudos that
2163 it does not reload. Ignore these as they have served their
2165 else if (regno
>= deps
->max_reg
)
2167 enum rtx_code code
= GET_CODE (PATTERN (insn
));
2168 gcc_assert (code
== USE
|| code
== CLOBBER
);
2174 note_reg_set (regno
);
2175 else if (ref
== USE
)
2176 note_reg_use (regno
);
2178 note_reg_clobber (regno
);
2180 /* Pseudos that are REG_EQUIV to something may be replaced
2181 by that during reloading. We need only add dependencies for
2182 the address in the REG_EQUIV note. */
2183 if (!reload_completed
&& get_reg_known_equiv_p (regno
))
2185 rtx t
= get_reg_known_value (regno
);
2187 sched_analyze_2 (deps
, XEXP (t
, 0), insn
);
2190 /* Don't let it cross a call after scheduling if it doesn't
2191 already cross one. */
2192 if (REG_N_CALLS_CROSSED (regno
) == 0)
2194 if (!deps
->readonly
&& ref
== USE
&& !DEBUG_INSN_P (insn
))
2195 deps
->sched_before_next_call
2196 = alloc_INSN_LIST (insn
, deps
->sched_before_next_call
);
2198 add_dependence_list (insn
, deps
->last_function_call
, 1,
2204 /* Analyze a single SET, CLOBBER, PRE_DEC, POST_DEC, PRE_INC or POST_INC
2205 rtx, X, creating all dependencies generated by the write to the
2206 destination of X, and reads of everything mentioned. */
2209 sched_analyze_1 (struct deps_desc
*deps
, rtx x
, rtx insn
)
2211 rtx dest
= XEXP (x
, 0);
2212 enum rtx_code code
= GET_CODE (x
);
2213 bool cslr_p
= can_start_lhs_rhs_p
;
2215 can_start_lhs_rhs_p
= false;
2221 if (cslr_p
&& sched_deps_info
->start_lhs
)
2222 sched_deps_info
->start_lhs (dest
);
2224 if (GET_CODE (dest
) == PARALLEL
)
2228 for (i
= XVECLEN (dest
, 0) - 1; i
>= 0; i
--)
2229 if (XEXP (XVECEXP (dest
, 0, i
), 0) != 0)
2230 sched_analyze_1 (deps
,
2231 gen_rtx_CLOBBER (VOIDmode
,
2232 XEXP (XVECEXP (dest
, 0, i
), 0)),
2235 if (cslr_p
&& sched_deps_info
->finish_lhs
)
2236 sched_deps_info
->finish_lhs ();
2240 can_start_lhs_rhs_p
= cslr_p
;
2242 sched_analyze_2 (deps
, SET_SRC (x
), insn
);
2244 can_start_lhs_rhs_p
= false;
2250 while (GET_CODE (dest
) == STRICT_LOW_PART
|| GET_CODE (dest
) == SUBREG
2251 || GET_CODE (dest
) == ZERO_EXTRACT
)
2253 if (GET_CODE (dest
) == STRICT_LOW_PART
2254 || GET_CODE (dest
) == ZERO_EXTRACT
2255 || df_read_modify_subreg_p (dest
))
2257 /* These both read and modify the result. We must handle
2258 them as writes to get proper dependencies for following
2259 instructions. We must handle them as reads to get proper
2260 dependencies from this to previous instructions.
2261 Thus we need to call sched_analyze_2. */
2263 sched_analyze_2 (deps
, XEXP (dest
, 0), insn
);
2265 if (GET_CODE (dest
) == ZERO_EXTRACT
)
2267 /* The second and third arguments are values read by this insn. */
2268 sched_analyze_2 (deps
, XEXP (dest
, 1), insn
);
2269 sched_analyze_2 (deps
, XEXP (dest
, 2), insn
);
2271 dest
= XEXP (dest
, 0);
2276 int regno
= REGNO (dest
);
2277 enum machine_mode mode
= GET_MODE (dest
);
2279 sched_analyze_reg (deps
, regno
, mode
, code
, insn
);
2282 /* Treat all writes to a stack register as modifying the TOS. */
2283 if (regno
>= FIRST_STACK_REG
&& regno
<= LAST_STACK_REG
)
2285 /* Avoid analyzing the same register twice. */
2286 if (regno
!= FIRST_STACK_REG
)
2287 sched_analyze_reg (deps
, FIRST_STACK_REG
, mode
, code
, insn
);
2289 add_to_hard_reg_set (&implicit_reg_pending_uses
, mode
,
2294 else if (MEM_P (dest
))
2296 /* Writing memory. */
2299 if (sched_deps_info
->use_cselib
)
2301 enum machine_mode address_mode
2302 = targetm
.addr_space
.address_mode (MEM_ADDR_SPACE (dest
));
2304 t
= shallow_copy_rtx (dest
);
2305 cselib_lookup_from_insn (XEXP (t
, 0), address_mode
, 1,
2306 GET_MODE (t
), insn
);
2307 XEXP (t
, 0) = cselib_subst_to_values (XEXP (t
, 0), GET_MODE (t
));
2311 /* Pending lists can't get larger with a readonly context. */
2313 && ((deps
->pending_read_list_length
+ deps
->pending_write_list_length
)
2314 > MAX_PENDING_LIST_LENGTH
))
2316 /* Flush all pending reads and writes to prevent the pending lists
2317 from getting any larger. Insn scheduling runs too slowly when
2318 these lists get long. When compiling GCC with itself,
2319 this flush occurs 8 times for sparc, and 10 times for m88k using
2320 the default value of 32. */
2321 flush_pending_lists (deps
, insn
, false, true);
2325 rtx pending
, pending_mem
;
2327 pending
= deps
->pending_read_insns
;
2328 pending_mem
= deps
->pending_read_mems
;
2331 if (anti_dependence (XEXP (pending_mem
, 0), t
)
2332 && ! sched_insns_conditions_mutex_p (insn
, XEXP (pending
, 0)))
2333 note_mem_dep (t
, XEXP (pending_mem
, 0), XEXP (pending
, 0),
2336 pending
= XEXP (pending
, 1);
2337 pending_mem
= XEXP (pending_mem
, 1);
2340 pending
= deps
->pending_write_insns
;
2341 pending_mem
= deps
->pending_write_mems
;
2344 if (output_dependence (XEXP (pending_mem
, 0), t
)
2345 && ! sched_insns_conditions_mutex_p (insn
, XEXP (pending
, 0)))
2346 note_mem_dep (t
, XEXP (pending_mem
, 0), XEXP (pending
, 0),
2349 pending
= XEXP (pending
, 1);
2350 pending_mem
= XEXP (pending_mem
, 1);
2353 add_dependence_list (insn
, deps
->last_pending_memory_flush
, 1,
2356 if (!deps
->readonly
)
2357 add_insn_mem_dependence (deps
, false, insn
, dest
);
2359 sched_analyze_2 (deps
, XEXP (dest
, 0), insn
);
2362 if (cslr_p
&& sched_deps_info
->finish_lhs
)
2363 sched_deps_info
->finish_lhs ();
2365 /* Analyze reads. */
2366 if (GET_CODE (x
) == SET
)
2368 can_start_lhs_rhs_p
= cslr_p
;
2370 sched_analyze_2 (deps
, SET_SRC (x
), insn
);
2372 can_start_lhs_rhs_p
= false;
2376 /* Analyze the uses of memory and registers in rtx X in INSN. */
2378 sched_analyze_2 (struct deps_desc
*deps
, rtx x
, rtx insn
)
2384 bool cslr_p
= can_start_lhs_rhs_p
;
2386 can_start_lhs_rhs_p
= false;
2392 if (cslr_p
&& sched_deps_info
->start_rhs
)
2393 sched_deps_info
->start_rhs (x
);
2395 code
= GET_CODE (x
);
2406 /* Ignore constants. */
2407 if (cslr_p
&& sched_deps_info
->finish_rhs
)
2408 sched_deps_info
->finish_rhs ();
2414 /* User of CC0 depends on immediately preceding insn. */
2415 SCHED_GROUP_P (insn
) = 1;
2416 /* Don't move CC0 setter to another block (it can set up the
2417 same flag for previous CC0 users which is safe). */
2418 CANT_MOVE (prev_nonnote_insn (insn
)) = 1;
2420 if (cslr_p
&& sched_deps_info
->finish_rhs
)
2421 sched_deps_info
->finish_rhs ();
2428 int regno
= REGNO (x
);
2429 enum machine_mode mode
= GET_MODE (x
);
2431 sched_analyze_reg (deps
, regno
, mode
, USE
, insn
);
2434 /* Treat all reads of a stack register as modifying the TOS. */
2435 if (regno
>= FIRST_STACK_REG
&& regno
<= LAST_STACK_REG
)
2437 /* Avoid analyzing the same register twice. */
2438 if (regno
!= FIRST_STACK_REG
)
2439 sched_analyze_reg (deps
, FIRST_STACK_REG
, mode
, USE
, insn
);
2440 sched_analyze_reg (deps
, FIRST_STACK_REG
, mode
, SET
, insn
);
2444 if (cslr_p
&& sched_deps_info
->finish_rhs
)
2445 sched_deps_info
->finish_rhs ();
2452 /* Reading memory. */
2454 rtx pending
, pending_mem
;
2457 if (sched_deps_info
->use_cselib
)
2459 enum machine_mode address_mode
2460 = targetm
.addr_space
.address_mode (MEM_ADDR_SPACE (t
));
2462 t
= shallow_copy_rtx (t
);
2463 cselib_lookup_from_insn (XEXP (t
, 0), address_mode
, 1,
2464 GET_MODE (t
), insn
);
2465 XEXP (t
, 0) = cselib_subst_to_values (XEXP (t
, 0), GET_MODE (t
));
2468 if (!DEBUG_INSN_P (insn
))
2471 pending
= deps
->pending_read_insns
;
2472 pending_mem
= deps
->pending_read_mems
;
2475 if (read_dependence (XEXP (pending_mem
, 0), t
)
2476 && ! sched_insns_conditions_mutex_p (insn
,
2478 note_mem_dep (t
, XEXP (pending_mem
, 0), XEXP (pending
, 0),
2481 pending
= XEXP (pending
, 1);
2482 pending_mem
= XEXP (pending_mem
, 1);
2485 pending
= deps
->pending_write_insns
;
2486 pending_mem
= deps
->pending_write_mems
;
2489 if (true_dependence (XEXP (pending_mem
, 0), VOIDmode
,
2491 && ! sched_insns_conditions_mutex_p (insn
,
2493 note_mem_dep (t
, XEXP (pending_mem
, 0), XEXP (pending
, 0),
2494 sched_deps_info
->generate_spec_deps
2495 ? BEGIN_DATA
| DEP_TRUE
: DEP_TRUE
);
2497 pending
= XEXP (pending
, 1);
2498 pending_mem
= XEXP (pending_mem
, 1);
2501 for (u
= deps
->last_pending_memory_flush
; u
; u
= XEXP (u
, 1))
2503 if (! NON_FLUSH_JUMP_P (u
))
2504 add_dependence (insn
, XEXP (u
, 0), REG_DEP_ANTI
);
2505 else if (deps_may_trap_p (x
))
2507 if ((sched_deps_info
->generate_spec_deps
)
2508 && sel_sched_p () && (spec_info
->mask
& BEGIN_CONTROL
))
2510 ds_t ds
= set_dep_weak (DEP_ANTI
, BEGIN_CONTROL
,
2513 note_dep (XEXP (u
, 0), ds
);
2516 add_dependence (insn
, XEXP (u
, 0), REG_DEP_ANTI
);
2521 /* Always add these dependencies to pending_reads, since
2522 this insn may be followed by a write. */
2523 if (!deps
->readonly
)
2524 add_insn_mem_dependence (deps
, true, insn
, x
);
2526 sched_analyze_2 (deps
, XEXP (x
, 0), insn
);
2528 if (cslr_p
&& sched_deps_info
->finish_rhs
)
2529 sched_deps_info
->finish_rhs ();
2534 /* Force pending stores to memory in case a trap handler needs them. */
2536 flush_pending_lists (deps
, insn
, true, false);
2540 if (PREFETCH_SCHEDULE_BARRIER_P (x
))
2541 reg_pending_barrier
= TRUE_BARRIER
;
2544 case UNSPEC_VOLATILE
:
2545 flush_pending_lists (deps
, insn
, true, true);
2551 /* Traditional and volatile asm instructions must be considered to use
2552 and clobber all hard registers, all pseudo-registers and all of
2553 memory. So must TRAP_IF and UNSPEC_VOLATILE operations.
2555 Consider for instance a volatile asm that changes the fpu rounding
2556 mode. An insn should not be moved across this even if it only uses
2557 pseudo-regs because it might give an incorrectly rounded result. */
2558 if (code
!= ASM_OPERANDS
|| MEM_VOLATILE_P (x
))
2559 reg_pending_barrier
= TRUE_BARRIER
;
2561 /* For all ASM_OPERANDS, we must traverse the vector of input operands.
2562 We can not just fall through here since then we would be confused
2563 by the ASM_INPUT rtx inside ASM_OPERANDS, which do not indicate
2564 traditional asms unlike their normal usage. */
2566 if (code
== ASM_OPERANDS
)
2568 for (j
= 0; j
< ASM_OPERANDS_INPUT_LENGTH (x
); j
++)
2569 sched_analyze_2 (deps
, ASM_OPERANDS_INPUT (x
, j
), insn
);
2571 if (cslr_p
&& sched_deps_info
->finish_rhs
)
2572 sched_deps_info
->finish_rhs ();
2583 /* These both read and modify the result. We must handle them as writes
2584 to get proper dependencies for following instructions. We must handle
2585 them as reads to get proper dependencies from this to previous
2586 instructions. Thus we need to pass them to both sched_analyze_1
2587 and sched_analyze_2. We must call sched_analyze_2 first in order
2588 to get the proper antecedent for the read. */
2589 sched_analyze_2 (deps
, XEXP (x
, 0), insn
);
2590 sched_analyze_1 (deps
, x
, insn
);
2592 if (cslr_p
&& sched_deps_info
->finish_rhs
)
2593 sched_deps_info
->finish_rhs ();
2599 /* op0 = op0 + op1 */
2600 sched_analyze_2 (deps
, XEXP (x
, 0), insn
);
2601 sched_analyze_2 (deps
, XEXP (x
, 1), insn
);
2602 sched_analyze_1 (deps
, x
, insn
);
2604 if (cslr_p
&& sched_deps_info
->finish_rhs
)
2605 sched_deps_info
->finish_rhs ();
2613 /* Other cases: walk the insn. */
2614 fmt
= GET_RTX_FORMAT (code
);
2615 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2618 sched_analyze_2 (deps
, XEXP (x
, i
), insn
);
2619 else if (fmt
[i
] == 'E')
2620 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2621 sched_analyze_2 (deps
, XVECEXP (x
, i
, j
), insn
);
2624 if (cslr_p
&& sched_deps_info
->finish_rhs
)
2625 sched_deps_info
->finish_rhs ();
2628 /* Analyze an INSN with pattern X to find all dependencies. */
2630 sched_analyze_insn (struct deps_desc
*deps
, rtx x
, rtx insn
)
2632 RTX_CODE code
= GET_CODE (x
);
2635 reg_set_iterator rsi
;
2637 if (! reload_completed
)
2641 extract_insn (insn
);
2642 preprocess_constraints ();
2643 ira_implicitly_set_insn_hard_regs (&temp
);
2644 AND_COMPL_HARD_REG_SET (temp
, ira_no_alloc_regs
);
2645 IOR_HARD_REG_SET (implicit_reg_pending_clobbers
, temp
);
2648 can_start_lhs_rhs_p
= (NONJUMP_INSN_P (insn
)
2652 /* Avoid moving trapping instructions accross function calls that might
2653 not always return. */
2654 add_dependence_list (insn
, deps
->last_function_call_may_noreturn
,
2657 if (code
== COND_EXEC
)
2659 sched_analyze_2 (deps
, COND_EXEC_TEST (x
), insn
);
2661 /* ??? Should be recording conditions so we reduce the number of
2662 false dependencies. */
2663 x
= COND_EXEC_CODE (x
);
2664 code
= GET_CODE (x
);
2666 if (code
== SET
|| code
== CLOBBER
)
2668 sched_analyze_1 (deps
, x
, insn
);
2670 /* Bare clobber insns are used for letting life analysis, reg-stack
2671 and others know that a value is dead. Depend on the last call
2672 instruction so that reg-stack won't get confused. */
2673 if (code
== CLOBBER
)
2674 add_dependence_list (insn
, deps
->last_function_call
, 1,
2677 else if (code
== PARALLEL
)
2679 for (i
= XVECLEN (x
, 0); i
--;)
2681 rtx sub
= XVECEXP (x
, 0, i
);
2682 code
= GET_CODE (sub
);
2684 if (code
== COND_EXEC
)
2686 sched_analyze_2 (deps
, COND_EXEC_TEST (sub
), insn
);
2687 sub
= COND_EXEC_CODE (sub
);
2688 code
= GET_CODE (sub
);
2690 if (code
== SET
|| code
== CLOBBER
)
2691 sched_analyze_1 (deps
, sub
, insn
);
2693 sched_analyze_2 (deps
, sub
, insn
);
2697 sched_analyze_2 (deps
, x
, insn
);
2699 /* Mark registers CLOBBERED or used by called function. */
2702 for (link
= CALL_INSN_FUNCTION_USAGE (insn
); link
; link
= XEXP (link
, 1))
2704 if (GET_CODE (XEXP (link
, 0)) == CLOBBER
)
2705 sched_analyze_1 (deps
, XEXP (link
, 0), insn
);
2707 sched_analyze_2 (deps
, XEXP (link
, 0), insn
);
2709 if (find_reg_note (insn
, REG_SETJMP
, NULL
))
2710 reg_pending_barrier
= MOVE_BARRIER
;
2716 next
= next_nonnote_nondebug_insn (insn
);
2717 if (next
&& BARRIER_P (next
))
2718 reg_pending_barrier
= MOVE_BARRIER
;
2721 rtx pending
, pending_mem
;
2723 if (sched_deps_info
->compute_jump_reg_dependencies
)
2725 regset_head tmp_uses
, tmp_sets
;
2726 INIT_REG_SET (&tmp_uses
);
2727 INIT_REG_SET (&tmp_sets
);
2729 (*sched_deps_info
->compute_jump_reg_dependencies
)
2730 (insn
, &deps
->reg_conditional_sets
, &tmp_uses
, &tmp_sets
);
2731 /* Make latency of jump equal to 0 by using anti-dependence. */
2732 EXECUTE_IF_SET_IN_REG_SET (&tmp_uses
, 0, i
, rsi
)
2734 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
2735 add_dependence_list (insn
, reg_last
->sets
, 0, REG_DEP_ANTI
);
2736 add_dependence_list (insn
, reg_last
->implicit_sets
,
2738 add_dependence_list (insn
, reg_last
->clobbers
, 0,
2741 if (!deps
->readonly
)
2743 reg_last
->uses_length
++;
2744 reg_last
->uses
= alloc_INSN_LIST (insn
, reg_last
->uses
);
2747 IOR_REG_SET (reg_pending_sets
, &tmp_sets
);
2749 CLEAR_REG_SET (&tmp_uses
);
2750 CLEAR_REG_SET (&tmp_sets
);
2753 /* All memory writes and volatile reads must happen before the
2754 jump. Non-volatile reads must happen before the jump iff
2755 the result is needed by the above register used mask. */
2757 pending
= deps
->pending_write_insns
;
2758 pending_mem
= deps
->pending_write_mems
;
2761 if (! sched_insns_conditions_mutex_p (insn
, XEXP (pending
, 0)))
2762 add_dependence (insn
, XEXP (pending
, 0), REG_DEP_OUTPUT
);
2763 pending
= XEXP (pending
, 1);
2764 pending_mem
= XEXP (pending_mem
, 1);
2767 pending
= deps
->pending_read_insns
;
2768 pending_mem
= deps
->pending_read_mems
;
2771 if (MEM_VOLATILE_P (XEXP (pending_mem
, 0))
2772 && ! sched_insns_conditions_mutex_p (insn
, XEXP (pending
, 0)))
2773 add_dependence (insn
, XEXP (pending
, 0), REG_DEP_OUTPUT
);
2774 pending
= XEXP (pending
, 1);
2775 pending_mem
= XEXP (pending_mem
, 1);
2778 add_dependence_list (insn
, deps
->last_pending_memory_flush
, 1,
2783 /* If this instruction can throw an exception, then moving it changes
2784 where block boundaries fall. This is mighty confusing elsewhere.
2785 Therefore, prevent such an instruction from being moved. Same for
2786 non-jump instructions that define block boundaries.
2787 ??? Unclear whether this is still necessary in EBB mode. If not,
2788 add_branch_dependences should be adjusted for RGN mode instead. */
2789 if (((CALL_P (insn
) || JUMP_P (insn
)) && can_throw_internal (insn
))
2790 || (NONJUMP_INSN_P (insn
) && control_flow_insn_p (insn
)))
2791 reg_pending_barrier
= MOVE_BARRIER
;
2793 if (sched_pressure_p
)
2795 setup_insn_reg_uses (deps
, insn
);
2796 init_insn_reg_pressure_info (insn
);
2799 /* Add register dependencies for insn. */
2800 if (DEBUG_INSN_P (insn
))
2802 rtx prev
= deps
->last_debug_insn
;
2805 if (!deps
->readonly
)
2806 deps
->last_debug_insn
= insn
;
2809 add_dependence (insn
, prev
, REG_DEP_ANTI
);
2811 add_dependence_list (insn
, deps
->last_function_call
, 1,
2814 for (u
= deps
->last_pending_memory_flush
; u
; u
= XEXP (u
, 1))
2815 if (! NON_FLUSH_JUMP_P (u
) || !sel_sched_p ())
2816 add_dependence (insn
, XEXP (u
, 0), REG_DEP_ANTI
);
2818 EXECUTE_IF_SET_IN_REG_SET (reg_pending_uses
, 0, i
, rsi
)
2820 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
2821 add_dependence_list (insn
, reg_last
->sets
, 1, REG_DEP_ANTI
);
2822 add_dependence_list (insn
, reg_last
->clobbers
, 1, REG_DEP_ANTI
);
2824 if (!deps
->readonly
)
2825 reg_last
->uses
= alloc_INSN_LIST (insn
, reg_last
->uses
);
2827 CLEAR_REG_SET (reg_pending_uses
);
2829 /* Quite often, a debug insn will refer to stuff in the
2830 previous instruction, but the reason we want this
2831 dependency here is to make sure the scheduler doesn't
2832 gratuitously move a debug insn ahead. This could dirty
2833 DF flags and cause additional analysis that wouldn't have
2834 occurred in compilation without debug insns, and such
2835 additional analysis can modify the generated code. */
2836 prev
= PREV_INSN (insn
);
2838 if (prev
&& NONDEBUG_INSN_P (prev
))
2839 add_dependence (insn
, prev
, REG_DEP_ANTI
);
2843 regset_head set_or_clobbered
;
2845 EXECUTE_IF_SET_IN_REG_SET (reg_pending_uses
, 0, i
, rsi
)
2847 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
2848 add_dependence_list (insn
, reg_last
->sets
, 0, REG_DEP_TRUE
);
2849 add_dependence_list (insn
, reg_last
->implicit_sets
, 0, REG_DEP_ANTI
);
2850 add_dependence_list (insn
, reg_last
->clobbers
, 0, REG_DEP_TRUE
);
2852 if (!deps
->readonly
)
2854 reg_last
->uses
= alloc_INSN_LIST (insn
, reg_last
->uses
);
2855 reg_last
->uses_length
++;
2859 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
2860 if (TEST_HARD_REG_BIT (implicit_reg_pending_uses
, i
))
2862 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
2863 add_dependence_list (insn
, reg_last
->sets
, 0, REG_DEP_TRUE
);
2864 add_dependence_list (insn
, reg_last
->implicit_sets
, 0,
2866 add_dependence_list (insn
, reg_last
->clobbers
, 0, REG_DEP_TRUE
);
2868 if (!deps
->readonly
)
2870 reg_last
->uses
= alloc_INSN_LIST (insn
, reg_last
->uses
);
2871 reg_last
->uses_length
++;
2875 if (targetm
.sched
.exposed_pipeline
)
2877 INIT_REG_SET (&set_or_clobbered
);
2878 bitmap_ior (&set_or_clobbered
, reg_pending_clobbers
,
2880 EXECUTE_IF_SET_IN_REG_SET (&set_or_clobbered
, 0, i
, rsi
)
2882 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
2884 for (list
= reg_last
->uses
; list
; list
= XEXP (list
, 1))
2886 rtx other
= XEXP (list
, 0);
2887 if (INSN_COND (other
) != const_true_rtx
2888 && refers_to_regno_p (i
, i
+ 1, INSN_COND (other
), NULL
))
2889 INSN_COND (other
) = const_true_rtx
;
2894 /* If the current insn is conditional, we can't free any
2896 if (sched_has_condition_p (insn
))
2898 EXECUTE_IF_SET_IN_REG_SET (reg_pending_clobbers
, 0, i
, rsi
)
2900 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
2901 add_dependence_list (insn
, reg_last
->sets
, 0, REG_DEP_OUTPUT
);
2902 add_dependence_list (insn
, reg_last
->implicit_sets
, 0,
2904 add_dependence_list (insn
, reg_last
->uses
, 0, REG_DEP_ANTI
);
2906 if (!deps
->readonly
)
2909 = alloc_INSN_LIST (insn
, reg_last
->clobbers
);
2910 reg_last
->clobbers_length
++;
2913 EXECUTE_IF_SET_IN_REG_SET (reg_pending_sets
, 0, i
, rsi
)
2915 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
2916 add_dependence_list (insn
, reg_last
->sets
, 0, REG_DEP_OUTPUT
);
2917 add_dependence_list (insn
, reg_last
->implicit_sets
, 0,
2919 add_dependence_list (insn
, reg_last
->clobbers
, 0, REG_DEP_OUTPUT
);
2920 add_dependence_list (insn
, reg_last
->uses
, 0, REG_DEP_ANTI
);
2922 if (!deps
->readonly
)
2924 reg_last
->sets
= alloc_INSN_LIST (insn
, reg_last
->sets
);
2925 SET_REGNO_REG_SET (&deps
->reg_conditional_sets
, i
);
2931 EXECUTE_IF_SET_IN_REG_SET (reg_pending_clobbers
, 0, i
, rsi
)
2933 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
2934 if (reg_last
->uses_length
> MAX_PENDING_LIST_LENGTH
2935 || reg_last
->clobbers_length
> MAX_PENDING_LIST_LENGTH
)
2937 add_dependence_list_and_free (deps
, insn
, ®_last
->sets
, 0,
2939 add_dependence_list_and_free (deps
, insn
,
2940 ®_last
->implicit_sets
, 0,
2942 add_dependence_list_and_free (deps
, insn
, ®_last
->uses
, 0,
2944 add_dependence_list_and_free
2945 (deps
, insn
, ®_last
->clobbers
, 0, REG_DEP_OUTPUT
);
2947 if (!deps
->readonly
)
2949 reg_last
->sets
= alloc_INSN_LIST (insn
, reg_last
->sets
);
2950 reg_last
->clobbers_length
= 0;
2951 reg_last
->uses_length
= 0;
2956 add_dependence_list (insn
, reg_last
->sets
, 0, REG_DEP_OUTPUT
);
2957 add_dependence_list (insn
, reg_last
->implicit_sets
, 0,
2959 add_dependence_list (insn
, reg_last
->uses
, 0, REG_DEP_ANTI
);
2962 if (!deps
->readonly
)
2964 reg_last
->clobbers_length
++;
2966 = alloc_INSN_LIST (insn
, reg_last
->clobbers
);
2969 EXECUTE_IF_SET_IN_REG_SET (reg_pending_sets
, 0, i
, rsi
)
2971 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
2973 add_dependence_list_and_free (deps
, insn
, ®_last
->sets
, 0,
2975 add_dependence_list_and_free (deps
, insn
,
2976 ®_last
->implicit_sets
,
2978 add_dependence_list_and_free (deps
, insn
, ®_last
->clobbers
, 0,
2980 add_dependence_list_and_free (deps
, insn
, ®_last
->uses
, 0,
2983 if (!deps
->readonly
)
2985 reg_last
->sets
= alloc_INSN_LIST (insn
, reg_last
->sets
);
2986 reg_last
->uses_length
= 0;
2987 reg_last
->clobbers_length
= 0;
2988 CLEAR_REGNO_REG_SET (&deps
->reg_conditional_sets
, i
);
2994 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
2995 if (TEST_HARD_REG_BIT (implicit_reg_pending_clobbers
, i
))
2997 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
2998 add_dependence_list (insn
, reg_last
->sets
, 0, REG_DEP_ANTI
);
2999 add_dependence_list (insn
, reg_last
->clobbers
, 0, REG_DEP_ANTI
);
3000 add_dependence_list (insn
, reg_last
->uses
, 0, REG_DEP_ANTI
);
3002 if (!deps
->readonly
)
3003 reg_last
->implicit_sets
3004 = alloc_INSN_LIST (insn
, reg_last
->implicit_sets
);
3007 if (!deps
->readonly
)
3009 IOR_REG_SET (&deps
->reg_last_in_use
, reg_pending_uses
);
3010 IOR_REG_SET (&deps
->reg_last_in_use
, reg_pending_clobbers
);
3011 IOR_REG_SET (&deps
->reg_last_in_use
, reg_pending_sets
);
3012 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3013 if (TEST_HARD_REG_BIT (implicit_reg_pending_uses
, i
)
3014 || TEST_HARD_REG_BIT (implicit_reg_pending_clobbers
, i
))
3015 SET_REGNO_REG_SET (&deps
->reg_last_in_use
, i
);
3017 /* Set up the pending barrier found. */
3018 deps
->last_reg_pending_barrier
= reg_pending_barrier
;
3021 CLEAR_REG_SET (reg_pending_uses
);
3022 CLEAR_REG_SET (reg_pending_clobbers
);
3023 CLEAR_REG_SET (reg_pending_sets
);
3024 CLEAR_HARD_REG_SET (implicit_reg_pending_clobbers
);
3025 CLEAR_HARD_REG_SET (implicit_reg_pending_uses
);
3027 /* Add dependencies if a scheduling barrier was found. */
3028 if (reg_pending_barrier
)
3030 /* In the case of barrier the most added dependencies are not
3031 real, so we use anti-dependence here. */
3032 if (sched_has_condition_p (insn
))
3034 EXECUTE_IF_SET_IN_REG_SET (&deps
->reg_last_in_use
, 0, i
, rsi
)
3036 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
3037 add_dependence_list (insn
, reg_last
->uses
, 0, REG_DEP_ANTI
);
3038 add_dependence_list (insn
, reg_last
->sets
, 0,
3039 reg_pending_barrier
== TRUE_BARRIER
3040 ? REG_DEP_TRUE
: REG_DEP_ANTI
);
3041 add_dependence_list (insn
, reg_last
->implicit_sets
, 0,
3043 add_dependence_list (insn
, reg_last
->clobbers
, 0,
3044 reg_pending_barrier
== TRUE_BARRIER
3045 ? REG_DEP_TRUE
: REG_DEP_ANTI
);
3050 EXECUTE_IF_SET_IN_REG_SET (&deps
->reg_last_in_use
, 0, i
, rsi
)
3052 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
3053 add_dependence_list_and_free (deps
, insn
, ®_last
->uses
, 0,
3055 add_dependence_list_and_free (deps
, insn
, ®_last
->sets
, 0,
3056 reg_pending_barrier
== TRUE_BARRIER
3057 ? REG_DEP_TRUE
: REG_DEP_ANTI
);
3058 add_dependence_list_and_free (deps
, insn
,
3059 ®_last
->implicit_sets
, 0,
3061 add_dependence_list_and_free (deps
, insn
, ®_last
->clobbers
, 0,
3062 reg_pending_barrier
== TRUE_BARRIER
3063 ? REG_DEP_TRUE
: REG_DEP_ANTI
);
3065 if (!deps
->readonly
)
3067 reg_last
->uses_length
= 0;
3068 reg_last
->clobbers_length
= 0;
3073 if (!deps
->readonly
)
3074 for (i
= 0; i
< (unsigned)deps
->max_reg
; i
++)
3076 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
3077 reg_last
->sets
= alloc_INSN_LIST (insn
, reg_last
->sets
);
3078 SET_REGNO_REG_SET (&deps
->reg_last_in_use
, i
);
3081 /* Flush pending lists on jumps, but not on speculative checks. */
3082 if (JUMP_P (insn
) && !(sel_sched_p ()
3083 && sel_insn_is_speculation_check (insn
)))
3084 flush_pending_lists (deps
, insn
, true, true);
3086 if (!deps
->readonly
)
3087 CLEAR_REG_SET (&deps
->reg_conditional_sets
);
3088 reg_pending_barrier
= NOT_A_BARRIER
;
3091 /* If a post-call group is still open, see if it should remain so.
3092 This insn must be a simple move of a hard reg to a pseudo or
3095 We must avoid moving these insns for correctness on targets
3096 with small register classes, and for special registers like
3097 PIC_OFFSET_TABLE_REGNUM. For simplicity, extend this to all
3098 hard regs for all targets. */
3100 if (deps
->in_post_call_group_p
)
3102 rtx tmp
, set
= single_set (insn
);
3103 int src_regno
, dest_regno
;
3107 if (DEBUG_INSN_P (insn
))
3108 /* We don't want to mark debug insns as part of the same
3109 sched group. We know they really aren't, but if we use
3110 debug insns to tell that a call group is over, we'll
3111 get different code if debug insns are not there and
3112 instructions that follow seem like they should be part
3115 Also, if we did, fixup_sched_groups() would move the
3116 deps of the debug insn to the call insn, modifying
3117 non-debug post-dependency counts of the debug insn
3118 dependencies and otherwise messing with the scheduling
3121 Instead, let such debug insns be scheduled freely, but
3122 keep the call group open in case there are insns that
3123 should be part of it afterwards. Since we grant debug
3124 insns higher priority than even sched group insns, it
3125 will all turn out all right. */
3126 goto debug_dont_end_call_group
;
3128 goto end_call_group
;
3131 tmp
= SET_DEST (set
);
3132 if (GET_CODE (tmp
) == SUBREG
)
3133 tmp
= SUBREG_REG (tmp
);
3135 dest_regno
= REGNO (tmp
);
3137 goto end_call_group
;
3139 tmp
= SET_SRC (set
);
3140 if (GET_CODE (tmp
) == SUBREG
)
3141 tmp
= SUBREG_REG (tmp
);
3142 if ((GET_CODE (tmp
) == PLUS
3143 || GET_CODE (tmp
) == MINUS
)
3144 && REG_P (XEXP (tmp
, 0))
3145 && REGNO (XEXP (tmp
, 0)) == STACK_POINTER_REGNUM
3146 && dest_regno
== STACK_POINTER_REGNUM
)
3147 src_regno
= STACK_POINTER_REGNUM
;
3148 else if (REG_P (tmp
))
3149 src_regno
= REGNO (tmp
);
3151 goto end_call_group
;
3153 if (src_regno
< FIRST_PSEUDO_REGISTER
3154 || dest_regno
< FIRST_PSEUDO_REGISTER
)
3157 && deps
->in_post_call_group_p
== post_call_initial
)
3158 deps
->in_post_call_group_p
= post_call
;
3160 if (!sel_sched_p () || sched_emulate_haifa_p
)
3162 SCHED_GROUP_P (insn
) = 1;
3163 CANT_MOVE (insn
) = 1;
3169 if (!deps
->readonly
)
3170 deps
->in_post_call_group_p
= not_post_call
;
3174 debug_dont_end_call_group
:
3175 if ((current_sched_info
->flags
& DO_SPECULATION
)
3176 && !sched_insn_is_legitimate_for_speculation_p (insn
, 0))
3177 /* INSN has an internal dependency (e.g. r14 = [r14]) and thus cannot
3181 sel_mark_hard_insn (insn
);
3184 sd_iterator_def sd_it
;
3187 for (sd_it
= sd_iterator_start (insn
, SD_LIST_SPEC_BACK
);
3188 sd_iterator_cond (&sd_it
, &dep
);)
3189 change_spec_dep_to_hard (sd_it
);
3194 /* Return TRUE if INSN might not always return normally (e.g. call exit,
3195 longjmp, loop forever, ...). */
3197 call_may_noreturn_p (rtx insn
)
3201 /* const or pure calls that aren't looping will always return. */
3202 if (RTL_CONST_OR_PURE_CALL_P (insn
)
3203 && !RTL_LOOPING_CONST_OR_PURE_CALL_P (insn
))
3206 call
= PATTERN (insn
);
3207 if (GET_CODE (call
) == PARALLEL
)
3208 call
= XVECEXP (call
, 0, 0);
3209 if (GET_CODE (call
) == SET
)
3210 call
= SET_SRC (call
);
3211 if (GET_CODE (call
) == CALL
3212 && MEM_P (XEXP (call
, 0))
3213 && GET_CODE (XEXP (XEXP (call
, 0), 0)) == SYMBOL_REF
)
3215 rtx symbol
= XEXP (XEXP (call
, 0), 0);
3216 if (SYMBOL_REF_DECL (symbol
)
3217 && TREE_CODE (SYMBOL_REF_DECL (symbol
)) == FUNCTION_DECL
)
3219 if (DECL_BUILT_IN_CLASS (SYMBOL_REF_DECL (symbol
))
3221 switch (DECL_FUNCTION_CODE (SYMBOL_REF_DECL (symbol
)))
3224 case BUILT_IN_BCOPY
:
3225 case BUILT_IN_BZERO
:
3226 case BUILT_IN_INDEX
:
3227 case BUILT_IN_MEMCHR
:
3228 case BUILT_IN_MEMCMP
:
3229 case BUILT_IN_MEMCPY
:
3230 case BUILT_IN_MEMMOVE
:
3231 case BUILT_IN_MEMPCPY
:
3232 case BUILT_IN_MEMSET
:
3233 case BUILT_IN_RINDEX
:
3234 case BUILT_IN_STPCPY
:
3235 case BUILT_IN_STPNCPY
:
3236 case BUILT_IN_STRCAT
:
3237 case BUILT_IN_STRCHR
:
3238 case BUILT_IN_STRCMP
:
3239 case BUILT_IN_STRCPY
:
3240 case BUILT_IN_STRCSPN
:
3241 case BUILT_IN_STRLEN
:
3242 case BUILT_IN_STRNCAT
:
3243 case BUILT_IN_STRNCMP
:
3244 case BUILT_IN_STRNCPY
:
3245 case BUILT_IN_STRPBRK
:
3246 case BUILT_IN_STRRCHR
:
3247 case BUILT_IN_STRSPN
:
3248 case BUILT_IN_STRSTR
:
3249 /* Assume certain string/memory builtins always return. */
3257 /* For all other calls assume that they might not always return. */
3261 /* Analyze INSN with DEPS as a context. */
3263 deps_analyze_insn (struct deps_desc
*deps
, rtx insn
)
3265 if (sched_deps_info
->start_insn
)
3266 sched_deps_info
->start_insn (insn
);
3268 /* Record the condition for this insn. */
3269 if (NONDEBUG_INSN_P (insn
))
3270 sched_get_condition_with_rev (insn
, NULL
);
3272 if (NONJUMP_INSN_P (insn
) || DEBUG_INSN_P (insn
) || JUMP_P (insn
))
3274 /* Make each JUMP_INSN (but not a speculative check)
3275 a scheduling barrier for memory references. */
3279 && sel_insn_is_speculation_check (insn
)))
3281 /* Keep the list a reasonable size. */
3282 if (deps
->pending_flush_length
++ > MAX_PENDING_LIST_LENGTH
)
3283 flush_pending_lists (deps
, insn
, true, true);
3286 deps
->last_pending_memory_flush
3287 = alloc_INSN_LIST (insn
, deps
->last_pending_memory_flush
);
3288 /* Signal to sched_analyze_insn that this jump stands
3289 just for its own, not any other pending memory
3290 reads/writes flush_pending_lists had to flush. */
3291 PUT_REG_NOTE_KIND (deps
->last_pending_memory_flush
,
3292 NON_FLUSH_JUMP_KIND
);
3296 sched_analyze_insn (deps
, PATTERN (insn
), insn
);
3298 else if (CALL_P (insn
))
3302 CANT_MOVE (insn
) = 1;
3304 if (find_reg_note (insn
, REG_SETJMP
, NULL
))
3306 /* This is setjmp. Assume that all registers, not just
3307 hard registers, may be clobbered by this call. */
3308 reg_pending_barrier
= MOVE_BARRIER
;
3312 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3313 /* A call may read and modify global register variables. */
3316 SET_REGNO_REG_SET (reg_pending_sets
, i
);
3317 SET_HARD_REG_BIT (implicit_reg_pending_uses
, i
);
3319 /* Other call-clobbered hard regs may be clobbered.
3320 Since we only have a choice between 'might be clobbered'
3321 and 'definitely not clobbered', we must include all
3322 partly call-clobbered registers here. */
3323 else if (HARD_REGNO_CALL_PART_CLOBBERED (i
, reg_raw_mode
[i
])
3324 || TEST_HARD_REG_BIT (regs_invalidated_by_call
, i
))
3325 SET_REGNO_REG_SET (reg_pending_clobbers
, i
);
3326 /* We don't know what set of fixed registers might be used
3327 by the function, but it is certain that the stack pointer
3328 is among them, but be conservative. */
3329 else if (fixed_regs
[i
])
3330 SET_HARD_REG_BIT (implicit_reg_pending_uses
, i
);
3331 /* The frame pointer is normally not used by the function
3332 itself, but by the debugger. */
3333 /* ??? MIPS o32 is an exception. It uses the frame pointer
3334 in the macro expansion of jal but does not represent this
3335 fact in the call_insn rtl. */
3336 else if (i
== FRAME_POINTER_REGNUM
3337 || (i
== HARD_FRAME_POINTER_REGNUM
3338 && (! reload_completed
|| frame_pointer_needed
)))
3339 SET_HARD_REG_BIT (implicit_reg_pending_uses
, i
);
3342 /* For each insn which shouldn't cross a call, add a dependence
3343 between that insn and this call insn. */
3344 add_dependence_list_and_free (deps
, insn
,
3345 &deps
->sched_before_next_call
, 1,
3348 sched_analyze_insn (deps
, PATTERN (insn
), insn
);
3350 /* If CALL would be in a sched group, then this will violate
3351 convention that sched group insns have dependencies only on the
3352 previous instruction.
3354 Of course one can say: "Hey! What about head of the sched group?"
3355 And I will answer: "Basic principles (one dep per insn) are always
3357 gcc_assert (!SCHED_GROUP_P (insn
));
3359 /* In the absence of interprocedural alias analysis, we must flush
3360 all pending reads and writes, and start new dependencies starting
3361 from here. But only flush writes for constant calls (which may
3362 be passed a pointer to something we haven't written yet). */
3363 flush_pending_lists (deps
, insn
, true, ! RTL_CONST_OR_PURE_CALL_P (insn
));
3365 if (!deps
->readonly
)
3367 /* Remember the last function call for limiting lifetimes. */
3368 free_INSN_LIST_list (&deps
->last_function_call
);
3369 deps
->last_function_call
= alloc_INSN_LIST (insn
, NULL_RTX
);
3371 if (call_may_noreturn_p (insn
))
3373 /* Remember the last function call that might not always return
3374 normally for limiting moves of trapping insns. */
3375 free_INSN_LIST_list (&deps
->last_function_call_may_noreturn
);
3376 deps
->last_function_call_may_noreturn
3377 = alloc_INSN_LIST (insn
, NULL_RTX
);
3380 /* Before reload, begin a post-call group, so as to keep the
3381 lifetimes of hard registers correct. */
3382 if (! reload_completed
)
3383 deps
->in_post_call_group_p
= post_call
;
3387 if (sched_deps_info
->use_cselib
)
3388 cselib_process_insn (insn
);
3390 /* EH_REGION insn notes can not appear until well after we complete
3393 gcc_assert (NOTE_KIND (insn
) != NOTE_INSN_EH_REGION_BEG
3394 && NOTE_KIND (insn
) != NOTE_INSN_EH_REGION_END
);
3396 if (sched_deps_info
->finish_insn
)
3397 sched_deps_info
->finish_insn ();
3399 /* Fixup the dependencies in the sched group. */
3400 if ((NONJUMP_INSN_P (insn
) || JUMP_P (insn
))
3401 && SCHED_GROUP_P (insn
) && !sel_sched_p ())
3402 fixup_sched_groups (insn
);
3405 /* Initialize DEPS for the new block beginning with HEAD. */
3407 deps_start_bb (struct deps_desc
*deps
, rtx head
)
3409 gcc_assert (!deps
->readonly
);
3411 /* Before reload, if the previous block ended in a call, show that
3412 we are inside a post-call group, so as to keep the lifetimes of
3413 hard registers correct. */
3414 if (! reload_completed
&& !LABEL_P (head
))
3416 rtx insn
= prev_nonnote_nondebug_insn (head
);
3418 if (insn
&& CALL_P (insn
))
3419 deps
->in_post_call_group_p
= post_call_initial
;
3423 /* Analyze every insn between HEAD and TAIL inclusive, creating backward
3424 dependencies for each insn. */
3426 sched_analyze (struct deps_desc
*deps
, rtx head
, rtx tail
)
3430 if (sched_deps_info
->use_cselib
)
3431 cselib_init (CSELIB_RECORD_MEMORY
);
3433 deps_start_bb (deps
, head
);
3435 for (insn
= head
;; insn
= NEXT_INSN (insn
))
3440 /* And initialize deps_lists. */
3441 sd_init_insn (insn
);
3444 deps_analyze_insn (deps
, insn
);
3448 if (sched_deps_info
->use_cselib
)
3456 /* Helper for sched_free_deps ().
3457 Delete INSN's (RESOLVED_P) backward dependencies. */
3459 delete_dep_nodes_in_back_deps (rtx insn
, bool resolved_p
)
3461 sd_iterator_def sd_it
;
3463 sd_list_types_def types
;
3466 types
= SD_LIST_RES_BACK
;
3468 types
= SD_LIST_BACK
;
3470 for (sd_it
= sd_iterator_start (insn
, types
);
3471 sd_iterator_cond (&sd_it
, &dep
);)
3473 dep_link_t link
= *sd_it
.linkp
;
3474 dep_node_t node
= DEP_LINK_NODE (link
);
3475 deps_list_t back_list
;
3476 deps_list_t forw_list
;
3478 get_back_and_forw_lists (dep
, resolved_p
, &back_list
, &forw_list
);
3479 remove_from_deps_list (link
, back_list
);
3480 delete_dep_node (node
);
3484 /* Delete (RESOLVED_P) dependencies between HEAD and TAIL together with
3487 sched_free_deps (rtx head
, rtx tail
, bool resolved_p
)
3490 rtx next_tail
= NEXT_INSN (tail
);
3492 for (insn
= head
; insn
!= next_tail
; insn
= NEXT_INSN (insn
))
3493 if (INSN_P (insn
) && INSN_LUID (insn
) > 0)
3495 /* Clear resolved back deps together with its dep_nodes. */
3496 delete_dep_nodes_in_back_deps (insn
, resolved_p
);
3498 /* Clear forward deps and leave the dep_nodes to the
3499 corresponding back_deps list. */
3501 clear_deps_list (INSN_RESOLVED_FORW_DEPS (insn
));
3503 clear_deps_list (INSN_FORW_DEPS (insn
));
3505 sd_finish_insn (insn
);
3509 /* Initialize variables for region data dependence analysis.
3510 When LAZY_REG_LAST is true, do not allocate reg_last array
3511 of struct deps_desc immediately. */
3514 init_deps (struct deps_desc
*deps
, bool lazy_reg_last
)
3516 int max_reg
= (reload_completed
? FIRST_PSEUDO_REGISTER
: max_reg_num ());
3518 deps
->max_reg
= max_reg
;
3520 deps
->reg_last
= NULL
;
3522 deps
->reg_last
= XCNEWVEC (struct deps_reg
, max_reg
);
3523 INIT_REG_SET (&deps
->reg_last_in_use
);
3524 INIT_REG_SET (&deps
->reg_conditional_sets
);
3526 deps
->pending_read_insns
= 0;
3527 deps
->pending_read_mems
= 0;
3528 deps
->pending_write_insns
= 0;
3529 deps
->pending_write_mems
= 0;
3530 deps
->pending_read_list_length
= 0;
3531 deps
->pending_write_list_length
= 0;
3532 deps
->pending_flush_length
= 0;
3533 deps
->last_pending_memory_flush
= 0;
3534 deps
->last_function_call
= 0;
3535 deps
->last_function_call_may_noreturn
= 0;
3536 deps
->sched_before_next_call
= 0;
3537 deps
->in_post_call_group_p
= not_post_call
;
3538 deps
->last_debug_insn
= 0;
3539 deps
->last_reg_pending_barrier
= NOT_A_BARRIER
;
3543 /* Init only reg_last field of DEPS, which was not allocated before as
3544 we inited DEPS lazily. */
3546 init_deps_reg_last (struct deps_desc
*deps
)
3548 gcc_assert (deps
&& deps
->max_reg
> 0);
3549 gcc_assert (deps
->reg_last
== NULL
);
3551 deps
->reg_last
= XCNEWVEC (struct deps_reg
, deps
->max_reg
);
3555 /* Free insn lists found in DEPS. */
3558 free_deps (struct deps_desc
*deps
)
3561 reg_set_iterator rsi
;
3563 /* We set max_reg to 0 when this context was already freed. */
3564 if (deps
->max_reg
== 0)
3566 gcc_assert (deps
->reg_last
== NULL
);
3571 free_INSN_LIST_list (&deps
->pending_read_insns
);
3572 free_EXPR_LIST_list (&deps
->pending_read_mems
);
3573 free_INSN_LIST_list (&deps
->pending_write_insns
);
3574 free_EXPR_LIST_list (&deps
->pending_write_mems
);
3575 free_INSN_LIST_list (&deps
->last_pending_memory_flush
);
3577 /* Without the EXECUTE_IF_SET, this loop is executed max_reg * nr_regions
3578 times. For a testcase with 42000 regs and 8000 small basic blocks,
3579 this loop accounted for nearly 60% (84 sec) of the total -O2 runtime. */
3580 EXECUTE_IF_SET_IN_REG_SET (&deps
->reg_last_in_use
, 0, i
, rsi
)
3582 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
3584 free_INSN_LIST_list (®_last
->uses
);
3586 free_INSN_LIST_list (®_last
->sets
);
3587 if (reg_last
->implicit_sets
)
3588 free_INSN_LIST_list (®_last
->implicit_sets
);
3589 if (reg_last
->clobbers
)
3590 free_INSN_LIST_list (®_last
->clobbers
);
3592 CLEAR_REG_SET (&deps
->reg_last_in_use
);
3593 CLEAR_REG_SET (&deps
->reg_conditional_sets
);
3595 /* As we initialize reg_last lazily, it is possible that we didn't allocate
3597 free (deps
->reg_last
);
3598 deps
->reg_last
= NULL
;
3603 /* Remove INSN from dependence contexts DEPS. Caution: reg_conditional_sets
3606 remove_from_deps (struct deps_desc
*deps
, rtx insn
)
3610 reg_set_iterator rsi
;
3612 removed
= remove_from_both_dependence_lists (insn
, &deps
->pending_read_insns
,
3613 &deps
->pending_read_mems
);
3614 if (!DEBUG_INSN_P (insn
))
3615 deps
->pending_read_list_length
-= removed
;
3616 removed
= remove_from_both_dependence_lists (insn
, &deps
->pending_write_insns
,
3617 &deps
->pending_write_mems
);
3618 deps
->pending_write_list_length
-= removed
;
3619 removed
= remove_from_dependence_list (insn
, &deps
->last_pending_memory_flush
);
3620 deps
->pending_flush_length
-= removed
;
3622 EXECUTE_IF_SET_IN_REG_SET (&deps
->reg_last_in_use
, 0, i
, rsi
)
3624 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
3626 remove_from_dependence_list (insn
, ®_last
->uses
);
3628 remove_from_dependence_list (insn
, ®_last
->sets
);
3629 if (reg_last
->implicit_sets
)
3630 remove_from_dependence_list (insn
, ®_last
->implicit_sets
);
3631 if (reg_last
->clobbers
)
3632 remove_from_dependence_list (insn
, ®_last
->clobbers
);
3633 if (!reg_last
->uses
&& !reg_last
->sets
&& !reg_last
->implicit_sets
3634 && !reg_last
->clobbers
)
3635 CLEAR_REGNO_REG_SET (&deps
->reg_last_in_use
, i
);
3640 remove_from_dependence_list (insn
, &deps
->last_function_call
);
3641 remove_from_dependence_list (insn
,
3642 &deps
->last_function_call_may_noreturn
);
3644 remove_from_dependence_list (insn
, &deps
->sched_before_next_call
);
3647 /* Init deps data vector. */
3649 init_deps_data_vector (void)
3651 int reserve
= (sched_max_luid
+ 1
3652 - VEC_length (haifa_deps_insn_data_def
, h_d_i_d
));
3654 && ! VEC_space (haifa_deps_insn_data_def
, h_d_i_d
, reserve
))
3655 VEC_safe_grow_cleared (haifa_deps_insn_data_def
, heap
, h_d_i_d
,
3656 3 * sched_max_luid
/ 2);
3659 /* If it is profitable to use them, initialize or extend (depending on
3660 GLOBAL_P) dependency data. */
3662 sched_deps_init (bool global_p
)
3664 /* Average number of insns in the basic block.
3665 '+ 1' is used to make it nonzero. */
3666 int insns_in_block
= sched_max_luid
/ n_basic_blocks
+ 1;
3668 init_deps_data_vector ();
3670 /* We use another caching mechanism for selective scheduling, so
3671 we don't use this one. */
3672 if (!sel_sched_p () && global_p
&& insns_in_block
> 100 * 5)
3674 /* ?!? We could save some memory by computing a per-region luid mapping
3675 which could reduce both the number of vectors in the cache and the
3676 size of each vector. Instead we just avoid the cache entirely unless
3677 the average number of instructions in a basic block is very high. See
3678 the comment before the declaration of true_dependency_cache for
3679 what we consider "very high". */
3681 extend_dependency_caches (sched_max_luid
, true);
3686 dl_pool
= create_alloc_pool ("deps_list", sizeof (struct _deps_list
),
3687 /* Allocate lists for one block at a time. */
3689 dn_pool
= create_alloc_pool ("dep_node", sizeof (struct _dep_node
),
3690 /* Allocate nodes for one block at a time.
3691 We assume that average insn has
3693 5 * insns_in_block
);
3698 /* Create or extend (depending on CREATE_P) dependency caches to
3701 extend_dependency_caches (int n
, bool create_p
)
3703 if (create_p
|| true_dependency_cache
)
3705 int i
, luid
= cache_size
+ n
;
3707 true_dependency_cache
= XRESIZEVEC (bitmap_head
, true_dependency_cache
,
3709 output_dependency_cache
= XRESIZEVEC (bitmap_head
,
3710 output_dependency_cache
, luid
);
3711 anti_dependency_cache
= XRESIZEVEC (bitmap_head
, anti_dependency_cache
,
3714 if (current_sched_info
->flags
& DO_SPECULATION
)
3715 spec_dependency_cache
= XRESIZEVEC (bitmap_head
, spec_dependency_cache
,
3718 for (i
= cache_size
; i
< luid
; i
++)
3720 bitmap_initialize (&true_dependency_cache
[i
], 0);
3721 bitmap_initialize (&output_dependency_cache
[i
], 0);
3722 bitmap_initialize (&anti_dependency_cache
[i
], 0);
3724 if (current_sched_info
->flags
& DO_SPECULATION
)
3725 bitmap_initialize (&spec_dependency_cache
[i
], 0);
3731 /* Finalize dependency information for the whole function. */
3733 sched_deps_finish (void)
3735 gcc_assert (deps_pools_are_empty_p ());
3736 free_alloc_pool_if_empty (&dn_pool
);
3737 free_alloc_pool_if_empty (&dl_pool
);
3738 gcc_assert (dn_pool
== NULL
&& dl_pool
== NULL
);
3740 VEC_free (haifa_deps_insn_data_def
, heap
, h_d_i_d
);
3743 if (true_dependency_cache
)
3747 for (i
= 0; i
< cache_size
; i
++)
3749 bitmap_clear (&true_dependency_cache
[i
]);
3750 bitmap_clear (&output_dependency_cache
[i
]);
3751 bitmap_clear (&anti_dependency_cache
[i
]);
3753 if (sched_deps_info
->generate_spec_deps
)
3754 bitmap_clear (&spec_dependency_cache
[i
]);
3756 free (true_dependency_cache
);
3757 true_dependency_cache
= NULL
;
3758 free (output_dependency_cache
);
3759 output_dependency_cache
= NULL
;
3760 free (anti_dependency_cache
);
3761 anti_dependency_cache
= NULL
;
3763 if (sched_deps_info
->generate_spec_deps
)
3765 free (spec_dependency_cache
);
3766 spec_dependency_cache
= NULL
;
3772 /* Initialize some global variables needed by the dependency analysis
3776 init_deps_global (void)
3778 CLEAR_HARD_REG_SET (implicit_reg_pending_clobbers
);
3779 CLEAR_HARD_REG_SET (implicit_reg_pending_uses
);
3780 reg_pending_sets
= ALLOC_REG_SET (®_obstack
);
3781 reg_pending_clobbers
= ALLOC_REG_SET (®_obstack
);
3782 reg_pending_uses
= ALLOC_REG_SET (®_obstack
);
3783 reg_pending_barrier
= NOT_A_BARRIER
;
3785 if (!sel_sched_p () || sched_emulate_haifa_p
)
3787 sched_deps_info
->start_insn
= haifa_start_insn
;
3788 sched_deps_info
->finish_insn
= haifa_finish_insn
;
3790 sched_deps_info
->note_reg_set
= haifa_note_reg_set
;
3791 sched_deps_info
->note_reg_clobber
= haifa_note_reg_clobber
;
3792 sched_deps_info
->note_reg_use
= haifa_note_reg_use
;
3794 sched_deps_info
->note_mem_dep
= haifa_note_mem_dep
;
3795 sched_deps_info
->note_dep
= haifa_note_dep
;
3799 /* Free everything used by the dependency analysis code. */
3802 finish_deps_global (void)
3804 FREE_REG_SET (reg_pending_sets
);
3805 FREE_REG_SET (reg_pending_clobbers
);
3806 FREE_REG_SET (reg_pending_uses
);
3809 /* Estimate the weakness of dependence between MEM1 and MEM2. */
3811 estimate_dep_weak (rtx mem1
, rtx mem2
)
3816 /* MEMs are the same - don't speculate. */
3817 return MIN_DEP_WEAK
;
3819 r1
= XEXP (mem1
, 0);
3820 r2
= XEXP (mem2
, 0);
3823 || (REG_P (r1
) && REG_P (r2
)
3824 && REGNO (r1
) == REGNO (r2
)))
3825 /* Again, MEMs are the same. */
3826 return MIN_DEP_WEAK
;
3827 else if ((REG_P (r1
) && !REG_P (r2
))
3828 || (!REG_P (r1
) && REG_P (r2
)))
3829 /* Different addressing modes - reason to be more speculative,
3831 return NO_DEP_WEAK
- (NO_DEP_WEAK
- UNCERTAIN_DEP_WEAK
) / 2;
3833 /* We can't say anything about the dependence. */
3834 return UNCERTAIN_DEP_WEAK
;
3837 /* Add or update backward dependence between INSN and ELEM with type DEP_TYPE.
3838 This function can handle same INSN and ELEM (INSN == ELEM).
3839 It is a convenience wrapper. */
3841 add_dependence (rtx insn
, rtx elem
, enum reg_note dep_type
)
3846 if (dep_type
== REG_DEP_TRUE
)
3848 else if (dep_type
== REG_DEP_OUTPUT
)
3852 gcc_assert (dep_type
== REG_DEP_ANTI
);
3856 /* When add_dependence is called from inside sched-deps.c, we expect
3857 cur_insn to be non-null. */
3858 internal
= cur_insn
!= NULL
;
3860 gcc_assert (insn
== cur_insn
);
3864 note_dep (elem
, ds
);
3869 /* Return weakness of speculative type TYPE in the dep_status DS. */
3871 get_dep_weak_1 (ds_t ds
, ds_t type
)
3877 case BEGIN_DATA
: ds
>>= BEGIN_DATA_BITS_OFFSET
; break;
3878 case BE_IN_DATA
: ds
>>= BE_IN_DATA_BITS_OFFSET
; break;
3879 case BEGIN_CONTROL
: ds
>>= BEGIN_CONTROL_BITS_OFFSET
; break;
3880 case BE_IN_CONTROL
: ds
>>= BE_IN_CONTROL_BITS_OFFSET
; break;
3881 default: gcc_unreachable ();
3888 get_dep_weak (ds_t ds
, ds_t type
)
3890 dw_t dw
= get_dep_weak_1 (ds
, type
);
3892 gcc_assert (MIN_DEP_WEAK
<= dw
&& dw
<= MAX_DEP_WEAK
);
3896 /* Return the dep_status, which has the same parameters as DS, except for
3897 speculative type TYPE, that will have weakness DW. */
3899 set_dep_weak (ds_t ds
, ds_t type
, dw_t dw
)
3901 gcc_assert (MIN_DEP_WEAK
<= dw
&& dw
<= MAX_DEP_WEAK
);
3906 case BEGIN_DATA
: ds
|= ((ds_t
) dw
) << BEGIN_DATA_BITS_OFFSET
; break;
3907 case BE_IN_DATA
: ds
|= ((ds_t
) dw
) << BE_IN_DATA_BITS_OFFSET
; break;
3908 case BEGIN_CONTROL
: ds
|= ((ds_t
) dw
) << BEGIN_CONTROL_BITS_OFFSET
; break;
3909 case BE_IN_CONTROL
: ds
|= ((ds_t
) dw
) << BE_IN_CONTROL_BITS_OFFSET
; break;
3910 default: gcc_unreachable ();
3915 /* Return the join of two dep_statuses DS1 and DS2.
3916 If MAX_P is true then choose the greater probability,
3917 otherwise multiply probabilities.
3918 This function assumes that both DS1 and DS2 contain speculative bits. */
3920 ds_merge_1 (ds_t ds1
, ds_t ds2
, bool max_p
)
3924 gcc_assert ((ds1
& SPECULATIVE
) && (ds2
& SPECULATIVE
));
3926 ds
= (ds1
& DEP_TYPES
) | (ds2
& DEP_TYPES
);
3928 t
= FIRST_SPEC_TYPE
;
3931 if ((ds1
& t
) && !(ds2
& t
))
3933 else if (!(ds1
& t
) && (ds2
& t
))
3935 else if ((ds1
& t
) && (ds2
& t
))
3937 dw_t dw1
= get_dep_weak (ds1
, t
);
3938 dw_t dw2
= get_dep_weak (ds2
, t
);
3943 dw
= ((ds_t
) dw1
) * ((ds_t
) dw2
);
3945 if (dw
< MIN_DEP_WEAK
)
3956 ds
= set_dep_weak (ds
, t
, (dw_t
) dw
);
3959 if (t
== LAST_SPEC_TYPE
)
3961 t
<<= SPEC_TYPE_SHIFT
;
3968 /* Return the join of two dep_statuses DS1 and DS2.
3969 This function assumes that both DS1 and DS2 contain speculative bits. */
3971 ds_merge (ds_t ds1
, ds_t ds2
)
3973 return ds_merge_1 (ds1
, ds2
, false);
3976 /* Return the join of two dep_statuses DS1 and DS2. */
3978 ds_full_merge (ds_t ds
, ds_t ds2
, rtx mem1
, rtx mem2
)
3980 ds_t new_status
= ds
| ds2
;
3982 if (new_status
& SPECULATIVE
)
3984 if ((ds
&& !(ds
& SPECULATIVE
))
3985 || (ds2
&& !(ds2
& SPECULATIVE
)))
3986 /* Then this dep can't be speculative. */
3987 new_status
&= ~SPECULATIVE
;
3990 /* Both are speculative. Merging probabilities. */
3995 dw
= estimate_dep_weak (mem1
, mem2
);
3996 ds
= set_dep_weak (ds
, BEGIN_DATA
, dw
);
4004 new_status
= ds_merge (ds2
, ds
);
4011 /* Return the join of DS1 and DS2. Use maximum instead of multiplying
4014 ds_max_merge (ds_t ds1
, ds_t ds2
)
4016 if (ds1
== 0 && ds2
== 0)
4019 if (ds1
== 0 && ds2
!= 0)
4022 if (ds1
!= 0 && ds2
== 0)
4025 return ds_merge_1 (ds1
, ds2
, true);
4028 /* Return the probability of speculation success for the speculation
4036 dt
= FIRST_SPEC_TYPE
;
4041 res
*= (ds_t
) get_dep_weak (ds
, dt
);
4045 if (dt
== LAST_SPEC_TYPE
)
4047 dt
<<= SPEC_TYPE_SHIFT
;
4053 res
/= MAX_DEP_WEAK
;
4055 if (res
< MIN_DEP_WEAK
)
4058 gcc_assert (res
<= MAX_DEP_WEAK
);
4063 /* Return a dep status that contains all speculation types of DS. */
4065 ds_get_speculation_types (ds_t ds
)
4067 if (ds
& BEGIN_DATA
)
4069 if (ds
& BE_IN_DATA
)
4071 if (ds
& BEGIN_CONTROL
)
4072 ds
|= BEGIN_CONTROL
;
4073 if (ds
& BE_IN_CONTROL
)
4074 ds
|= BE_IN_CONTROL
;
4076 return ds
& SPECULATIVE
;
4079 /* Return a dep status that contains maximal weakness for each speculation
4080 type present in DS. */
4082 ds_get_max_dep_weak (ds_t ds
)
4084 if (ds
& BEGIN_DATA
)
4085 ds
= set_dep_weak (ds
, BEGIN_DATA
, MAX_DEP_WEAK
);
4086 if (ds
& BE_IN_DATA
)
4087 ds
= set_dep_weak (ds
, BE_IN_DATA
, MAX_DEP_WEAK
);
4088 if (ds
& BEGIN_CONTROL
)
4089 ds
= set_dep_weak (ds
, BEGIN_CONTROL
, MAX_DEP_WEAK
);
4090 if (ds
& BE_IN_CONTROL
)
4091 ds
= set_dep_weak (ds
, BE_IN_CONTROL
, MAX_DEP_WEAK
);
4096 /* Dump information about the dependence status S. */
4098 dump_ds (FILE *f
, ds_t s
)
4103 fprintf (f
, "BEGIN_DATA: %d; ", get_dep_weak_1 (s
, BEGIN_DATA
));
4105 fprintf (f
, "BE_IN_DATA: %d; ", get_dep_weak_1 (s
, BE_IN_DATA
));
4106 if (s
& BEGIN_CONTROL
)
4107 fprintf (f
, "BEGIN_CONTROL: %d; ", get_dep_weak_1 (s
, BEGIN_CONTROL
));
4108 if (s
& BE_IN_CONTROL
)
4109 fprintf (f
, "BE_IN_CONTROL: %d; ", get_dep_weak_1 (s
, BE_IN_CONTROL
));
4112 fprintf (f
, "HARD_DEP; ");
4115 fprintf (f
, "DEP_TRUE; ");
4117 fprintf (f
, "DEP_ANTI; ");
4119 fprintf (f
, "DEP_OUTPUT; ");
4127 dump_ds (stderr
, s
);
4128 fprintf (stderr
, "\n");
4131 #ifdef ENABLE_CHECKING
4132 /* Verify that dependence type and status are consistent.
4133 If RELAXED_P is true, then skip dep_weakness checks. */
4135 check_dep (dep_t dep
, bool relaxed_p
)
4137 enum reg_note dt
= DEP_TYPE (dep
);
4138 ds_t ds
= DEP_STATUS (dep
);
4140 gcc_assert (DEP_PRO (dep
) != DEP_CON (dep
));
4142 if (!(current_sched_info
->flags
& USE_DEPS_LIST
))
4144 gcc_assert (ds
== -1);
4148 /* Check that dependence type contains the same bits as the status. */
4149 if (dt
== REG_DEP_TRUE
)
4150 gcc_assert (ds
& DEP_TRUE
);
4151 else if (dt
== REG_DEP_OUTPUT
)
4152 gcc_assert ((ds
& DEP_OUTPUT
)
4153 && !(ds
& DEP_TRUE
));
4155 gcc_assert ((dt
== REG_DEP_ANTI
)
4157 && !(ds
& (DEP_OUTPUT
| DEP_TRUE
)));
4159 /* HARD_DEP can not appear in dep_status of a link. */
4160 gcc_assert (!(ds
& HARD_DEP
));
4162 /* Check that dependence status is set correctly when speculation is not
4164 if (!sched_deps_info
->generate_spec_deps
)
4165 gcc_assert (!(ds
& SPECULATIVE
));
4166 else if (ds
& SPECULATIVE
)
4170 ds_t type
= FIRST_SPEC_TYPE
;
4172 /* Check that dependence weakness is in proper range. */
4176 get_dep_weak (ds
, type
);
4178 if (type
== LAST_SPEC_TYPE
)
4180 type
<<= SPEC_TYPE_SHIFT
;
4185 if (ds
& BEGIN_SPEC
)
4187 /* Only true dependence can be data speculative. */
4188 if (ds
& BEGIN_DATA
)
4189 gcc_assert (ds
& DEP_TRUE
);
4191 /* Control dependencies in the insn scheduler are represented by
4192 anti-dependencies, therefore only anti dependence can be
4193 control speculative. */
4194 if (ds
& BEGIN_CONTROL
)
4195 gcc_assert (ds
& DEP_ANTI
);
4199 /* Subsequent speculations should resolve true dependencies. */
4200 gcc_assert ((ds
& DEP_TYPES
) == DEP_TRUE
);
4203 /* Check that true and anti dependencies can't have other speculative
4206 gcc_assert (ds
& (BEGIN_DATA
| BE_IN_SPEC
));
4207 /* An output dependence can't be speculative at all. */
4208 gcc_assert (!(ds
& DEP_OUTPUT
));
4210 gcc_assert (ds
& BEGIN_CONTROL
);
4213 #endif /* ENABLE_CHECKING */
4215 #endif /* INSN_SCHEDULING */