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 Free Software Foundation, Inc.
5 Contributed by Michael Tiemann (tiemann@cygnus.com) Enhanced by,
6 and currently maintained by, Jim Wilson (wilson@cygnus.com)
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 2, or (at your option) any later
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING. If not, write to the Free
22 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
27 #include "coretypes.h"
32 #include "hard-reg-set.h"
33 #include "basic-block.h"
37 #include "insn-config.h"
38 #include "insn-attr.h"
42 #include "sched-int.h"
48 static regset_head reg_pending_sets_head
;
49 static regset_head reg_pending_clobbers_head
;
50 static regset_head reg_pending_uses_head
;
52 static regset reg_pending_sets
;
53 static regset reg_pending_clobbers
;
54 static regset reg_pending_uses
;
56 /* The following enumeration values tell us what dependencies we
57 should use to implement the barrier. We use true-dependencies for
58 TRUE_BARRIER and anti-dependencies for MOVE_BARRIER. */
59 enum reg_pending_barrier_mode
66 static enum reg_pending_barrier_mode reg_pending_barrier
;
68 /* To speed up the test for duplicate dependency links we keep a
69 record of dependencies created by add_dependence when the average
70 number of instructions in a basic block is very large.
72 Studies have shown that there is typically around 5 instructions between
73 branches for typical C code. So we can make a guess that the average
74 basic block is approximately 5 instructions long; we will choose 100X
75 the average size as a very large basic block.
77 Each insn has associated bitmaps for its dependencies. Each bitmap
78 has enough entries to represent a dependency on any other insn in
79 the insn chain. All bitmap for true dependencies cache is
80 allocated then the rest two ones are also allocated. */
81 static bitmap_head
*true_dependency_cache
;
82 static bitmap_head
*anti_dependency_cache
;
83 static bitmap_head
*output_dependency_cache
;
86 /* To speed up checking consistency of formed forward insn
87 dependencies we use the following cache. Another possible solution
88 could be switching off checking duplication of insns in forward
90 #ifdef ENABLE_CHECKING
91 static bitmap_head
*forward_dependency_cache
;
94 static int deps_may_trap_p (rtx
);
95 static void add_dependence_list (rtx
, rtx
, enum reg_note
);
96 static void add_dependence_list_and_free (rtx
, rtx
*, enum reg_note
);
97 static void set_sched_group_p (rtx
);
99 static void flush_pending_lists (struct deps
*, rtx
, int, int);
100 static void sched_analyze_1 (struct deps
*, rtx
, rtx
);
101 static void sched_analyze_2 (struct deps
*, rtx
, rtx
);
102 static void sched_analyze_insn (struct deps
*, rtx
, rtx
, rtx
);
104 static rtx
get_condition (rtx
);
105 static int conditions_mutex_p (rtx
, rtx
);
107 /* Return nonzero if a load of the memory reference MEM can cause a trap. */
110 deps_may_trap_p (rtx mem
)
112 rtx addr
= XEXP (mem
, 0);
114 if (REG_P (addr
) && REGNO (addr
) >= FIRST_PSEUDO_REGISTER
)
116 rtx t
= get_reg_known_value (REGNO (addr
));
120 return rtx_addr_can_trap_p (addr
);
123 /* Return the INSN_LIST containing INSN in LIST, or NULL
124 if LIST does not contain INSN. */
127 find_insn_list (rtx insn
, rtx list
)
131 if (XEXP (list
, 0) == insn
)
133 list
= XEXP (list
, 1);
138 /* Find the condition under which INSN is executed. */
141 get_condition (rtx insn
)
143 rtx pat
= PATTERN (insn
);
149 if (GET_CODE (pat
) == COND_EXEC
)
150 return COND_EXEC_TEST (pat
);
152 if (!any_condjump_p (insn
) || !onlyjump_p (insn
))
155 src
= SET_SRC (pc_set (insn
));
157 /* The previous code here was completely invalid and could never extract
158 the condition from a jump. This code does the correct thing, but that
159 triggers latent bugs later in the scheduler on ports with conditional
160 execution. So this is disabled for now. */
161 if (XEXP (src
, 2) == pc_rtx
)
162 return XEXP (src
, 0);
163 else if (XEXP (src
, 1) == pc_rtx
)
165 rtx cond
= XEXP (src
, 0);
166 enum rtx_code revcode
= reversed_comparison_code (cond
, insn
);
168 if (revcode
== UNKNOWN
)
170 return gen_rtx_fmt_ee (revcode
, GET_MODE (cond
), XEXP (cond
, 0),
178 /* Return nonzero if conditions COND1 and COND2 can never be both true. */
181 conditions_mutex_p (rtx cond1
, rtx cond2
)
183 if (COMPARISON_P (cond1
)
184 && COMPARISON_P (cond2
)
185 && GET_CODE (cond1
) == reversed_comparison_code (cond2
, NULL
)
186 && XEXP (cond1
, 0) == XEXP (cond2
, 0)
187 && XEXP (cond1
, 1) == XEXP (cond2
, 1))
192 /* Add ELEM wrapped in an INSN_LIST with reg note kind DEP_TYPE to the
193 LOG_LINKS of INSN, if not already there. DEP_TYPE indicates the
194 type of dependence that this link represents. The function returns
195 nonzero if a new entry has been added to insn's LOG_LINK. */
198 add_dependence (rtx insn
, rtx elem
, enum reg_note dep_type
)
204 /* Don't depend an insn on itself. */
208 /* We can get a dependency on deleted insns due to optimizations in
209 the register allocation and reloading or due to splitting. Any
210 such dependency is useless and can be ignored. */
214 /* flow.c doesn't handle conditional lifetimes entirely correctly;
215 calls mess up the conditional lifetimes. */
216 /* ??? add_dependence is the wrong place to be eliding dependencies,
217 as that forgets that the condition expressions themselves may
219 if (!CALL_P (insn
) && !CALL_P (elem
))
221 cond1
= get_condition (insn
);
222 cond2
= get_condition (elem
);
224 && conditions_mutex_p (cond1
, cond2
)
225 /* Make sure first instruction doesn't affect condition of second
226 instruction if switched. */
227 && !modified_in_p (cond1
, elem
)
228 /* Make sure second instruction doesn't affect condition of first
229 instruction if switched. */
230 && !modified_in_p (cond2
, insn
))
235 #ifdef INSN_SCHEDULING
236 /* ??? No good way to tell from here whether we're doing interblock
237 scheduling. Possibly add another callback. */
239 /* (This code is guarded by INSN_SCHEDULING, otherwise INSN_BB is undefined.)
240 No need for interblock dependences with calls, since
241 calls are not moved between blocks. Note: the edge where
242 elem is a CALL is still required. */
244 && (INSN_BB (elem
) != INSN_BB (insn
)))
248 /* If we already have a dependency for ELEM, then we do not need to
249 do anything. Avoiding the list walk below can cut compile times
250 dramatically for some code. */
251 if (true_dependency_cache
!= NULL
)
253 enum reg_note present_dep_type
= 0;
255 gcc_assert (anti_dependency_cache
);
256 gcc_assert (output_dependency_cache
);
257 if (bitmap_bit_p (&true_dependency_cache
[INSN_LUID (insn
)],
259 /* Do nothing (present_set_type is already 0). */
261 else if (bitmap_bit_p (&anti_dependency_cache
[INSN_LUID (insn
)],
263 present_dep_type
= REG_DEP_ANTI
;
264 else if (bitmap_bit_p (&output_dependency_cache
[INSN_LUID (insn
)],
266 present_dep_type
= REG_DEP_OUTPUT
;
269 if (present_p
&& (int) dep_type
>= (int) present_dep_type
)
274 /* Check that we don't already have this dependence. */
276 for (link
= LOG_LINKS (insn
); link
; link
= XEXP (link
, 1))
277 if (XEXP (link
, 0) == elem
)
279 #ifdef INSN_SCHEDULING
280 /* Clear corresponding cache entry because type of the link
282 if (true_dependency_cache
!= NULL
)
284 enum reg_note kind
= REG_NOTE_KIND (link
);
288 bitmap_clear_bit (&anti_dependency_cache
[INSN_LUID (insn
)],
292 gcc_assert (output_dependency_cache
);
293 bitmap_clear_bit (&output_dependency_cache
[INSN_LUID (insn
)],
302 /* If this is a more restrictive type of dependence than the existing
303 one, then change the existing dependence to this type. */
304 if ((int) dep_type
< (int) REG_NOTE_KIND (link
))
305 PUT_REG_NOTE_KIND (link
, dep_type
);
307 #ifdef INSN_SCHEDULING
308 /* If we are adding a dependency to INSN's LOG_LINKs, then
309 note that in the bitmap caches of dependency information. */
310 if (true_dependency_cache
!= NULL
)
312 if ((int) REG_NOTE_KIND (link
) == 0)
313 bitmap_set_bit (&true_dependency_cache
[INSN_LUID (insn
)],
315 else if (REG_NOTE_KIND (link
) == REG_DEP_ANTI
)
316 bitmap_set_bit (&anti_dependency_cache
[INSN_LUID (insn
)],
318 else if (REG_NOTE_KIND (link
) == REG_DEP_OUTPUT
)
319 bitmap_set_bit (&output_dependency_cache
[INSN_LUID (insn
)],
325 /* Might want to check one level of transitivity to save conses. */
327 link
= alloc_INSN_LIST (elem
, LOG_LINKS (insn
));
328 LOG_LINKS (insn
) = link
;
330 /* Insn dependency, not data dependency. */
331 PUT_REG_NOTE_KIND (link
, dep_type
);
333 #ifdef INSN_SCHEDULING
334 /* If we are adding a dependency to INSN's LOG_LINKs, then note that
335 in the bitmap caches of dependency information. */
336 if (true_dependency_cache
!= NULL
)
338 if ((int) dep_type
== 0)
339 bitmap_set_bit (&true_dependency_cache
[INSN_LUID (insn
)], INSN_LUID (elem
));
340 else if (dep_type
== REG_DEP_ANTI
)
341 bitmap_set_bit (&anti_dependency_cache
[INSN_LUID (insn
)], INSN_LUID (elem
));
342 else if (dep_type
== REG_DEP_OUTPUT
)
343 bitmap_set_bit (&output_dependency_cache
[INSN_LUID (insn
)], INSN_LUID (elem
));
349 /* A convenience wrapper to operate on an entire list. */
352 add_dependence_list (rtx insn
, rtx list
, enum reg_note dep_type
)
354 for (; list
; list
= XEXP (list
, 1))
355 add_dependence (insn
, XEXP (list
, 0), dep_type
);
358 /* Similar, but free *LISTP at the same time. */
361 add_dependence_list_and_free (rtx insn
, rtx
*listp
, enum reg_note dep_type
)
364 for (list
= *listp
, *listp
= NULL
; list
; list
= next
)
366 next
= XEXP (list
, 1);
367 add_dependence (insn
, XEXP (list
, 0), dep_type
);
368 free_INSN_LIST_node (list
);
372 /* Set SCHED_GROUP_P and care for the rest of the bookkeeping that
373 goes along with that. */
376 set_sched_group_p (rtx insn
)
380 SCHED_GROUP_P (insn
) = 1;
382 prev
= prev_nonnote_insn (insn
);
383 add_dependence (insn
, prev
, REG_DEP_ANTI
);
386 /* Process an insn's memory dependencies. There are four kinds of
389 (0) read dependence: read follows read
390 (1) true dependence: read follows write
391 (2) anti dependence: write follows read
392 (3) output dependence: write follows write
394 We are careful to build only dependencies which actually exist, and
395 use transitivity to avoid building too many links. */
397 /* Add an INSN and MEM reference pair to a pending INSN_LIST and MEM_LIST.
398 The MEM is a memory reference contained within INSN, which we are saving
399 so that we can do memory aliasing on it. */
402 add_insn_mem_dependence (struct deps
*deps
, rtx
*insn_list
, rtx
*mem_list
,
407 link
= alloc_INSN_LIST (insn
, *insn_list
);
410 if (current_sched_info
->use_cselib
)
412 mem
= shallow_copy_rtx (mem
);
413 XEXP (mem
, 0) = cselib_subst_to_values (XEXP (mem
, 0));
415 link
= alloc_EXPR_LIST (VOIDmode
, canon_rtx (mem
), *mem_list
);
418 deps
->pending_lists_length
++;
421 /* Make a dependency between every memory reference on the pending lists
422 and INSN, thus flushing the pending lists. FOR_READ is true if emitting
423 dependencies for a read operation, similarly with FOR_WRITE. */
426 flush_pending_lists (struct deps
*deps
, rtx insn
, int for_read
,
431 add_dependence_list_and_free (insn
, &deps
->pending_read_insns
,
433 free_EXPR_LIST_list (&deps
->pending_read_mems
);
436 add_dependence_list_and_free (insn
, &deps
->pending_write_insns
,
437 for_read
? REG_DEP_ANTI
: REG_DEP_OUTPUT
);
438 free_EXPR_LIST_list (&deps
->pending_write_mems
);
439 deps
->pending_lists_length
= 0;
441 add_dependence_list_and_free (insn
, &deps
->last_pending_memory_flush
,
442 for_read
? REG_DEP_ANTI
: REG_DEP_OUTPUT
);
443 deps
->last_pending_memory_flush
= alloc_INSN_LIST (insn
, NULL_RTX
);
444 deps
->pending_flush_length
= 1;
447 /* Analyze a single SET, CLOBBER, PRE_DEC, POST_DEC, PRE_INC or POST_INC
448 rtx, X, creating all dependencies generated by the write to the
449 destination of X, and reads of everything mentioned. */
452 sched_analyze_1 (struct deps
*deps
, rtx x
, rtx insn
)
455 rtx dest
= XEXP (x
, 0);
456 enum rtx_code code
= GET_CODE (x
);
461 if (GET_CODE (dest
) == PARALLEL
)
465 for (i
= XVECLEN (dest
, 0) - 1; i
>= 0; i
--)
466 if (XEXP (XVECEXP (dest
, 0, i
), 0) != 0)
467 sched_analyze_1 (deps
,
468 gen_rtx_CLOBBER (VOIDmode
,
469 XEXP (XVECEXP (dest
, 0, i
), 0)),
472 if (GET_CODE (x
) == SET
)
473 sched_analyze_2 (deps
, SET_SRC (x
), insn
);
477 while (GET_CODE (dest
) == STRICT_LOW_PART
|| GET_CODE (dest
) == SUBREG
478 || GET_CODE (dest
) == ZERO_EXTRACT
|| GET_CODE (dest
) == SIGN_EXTRACT
)
480 if (GET_CODE (dest
) == STRICT_LOW_PART
481 || GET_CODE (dest
) == ZERO_EXTRACT
482 || GET_CODE (dest
) == SIGN_EXTRACT
483 || read_modify_subreg_p (dest
))
485 /* These both read and modify the result. We must handle
486 them as writes to get proper dependencies for following
487 instructions. We must handle them as reads to get proper
488 dependencies from this to previous instructions.
489 Thus we need to call sched_analyze_2. */
491 sched_analyze_2 (deps
, XEXP (dest
, 0), insn
);
493 if (GET_CODE (dest
) == ZERO_EXTRACT
|| GET_CODE (dest
) == SIGN_EXTRACT
)
495 /* The second and third arguments are values read by this insn. */
496 sched_analyze_2 (deps
, XEXP (dest
, 1), insn
);
497 sched_analyze_2 (deps
, XEXP (dest
, 2), insn
);
499 dest
= XEXP (dest
, 0);
504 regno
= REGNO (dest
);
506 /* A hard reg in a wide mode may really be multiple registers.
507 If so, mark all of them just like the first. */
508 if (regno
< FIRST_PSEUDO_REGISTER
)
510 int i
= hard_regno_nregs
[regno
][GET_MODE (dest
)];
514 SET_REGNO_REG_SET (reg_pending_sets
, regno
+ i
);
519 SET_REGNO_REG_SET (reg_pending_clobbers
, regno
+ i
);
522 /* ??? Reload sometimes emits USEs and CLOBBERs of pseudos that
523 it does not reload. Ignore these as they have served their
525 else if (regno
>= deps
->max_reg
)
527 gcc_assert (GET_CODE (PATTERN (insn
)) == USE
528 || GET_CODE (PATTERN (insn
)) == CLOBBER
);
533 SET_REGNO_REG_SET (reg_pending_sets
, regno
);
535 SET_REGNO_REG_SET (reg_pending_clobbers
, regno
);
537 /* Pseudos that are REG_EQUIV to something may be replaced
538 by that during reloading. We need only add dependencies for
539 the address in the REG_EQUIV note. */
540 if (!reload_completed
&& get_reg_known_equiv_p (regno
))
542 rtx t
= get_reg_known_value (regno
);
544 sched_analyze_2 (deps
, XEXP (t
, 0), insn
);
547 /* Don't let it cross a call after scheduling if it doesn't
548 already cross one. */
549 if (REG_N_CALLS_CROSSED (regno
) == 0)
550 add_dependence_list (insn
, deps
->last_function_call
, REG_DEP_ANTI
);
553 else if (MEM_P (dest
))
555 /* Writing memory. */
558 if (current_sched_info
->use_cselib
)
560 t
= shallow_copy_rtx (dest
);
561 cselib_lookup (XEXP (t
, 0), Pmode
, 1);
562 XEXP (t
, 0) = cselib_subst_to_values (XEXP (t
, 0));
566 if (deps
->pending_lists_length
> MAX_PENDING_LIST_LENGTH
)
568 /* Flush all pending reads and writes to prevent the pending lists
569 from getting any larger. Insn scheduling runs too slowly when
570 these lists get long. When compiling GCC with itself,
571 this flush occurs 8 times for sparc, and 10 times for m88k using
572 the default value of 32. */
573 flush_pending_lists (deps
, insn
, false, true);
577 rtx pending
, pending_mem
;
579 pending
= deps
->pending_read_insns
;
580 pending_mem
= deps
->pending_read_mems
;
583 if (anti_dependence (XEXP (pending_mem
, 0), t
))
584 add_dependence (insn
, XEXP (pending
, 0), REG_DEP_ANTI
);
586 pending
= XEXP (pending
, 1);
587 pending_mem
= XEXP (pending_mem
, 1);
590 pending
= deps
->pending_write_insns
;
591 pending_mem
= deps
->pending_write_mems
;
594 if (output_dependence (XEXP (pending_mem
, 0), t
))
595 add_dependence (insn
, XEXP (pending
, 0), REG_DEP_OUTPUT
);
597 pending
= XEXP (pending
, 1);
598 pending_mem
= XEXP (pending_mem
, 1);
601 add_dependence_list (insn
, deps
->last_pending_memory_flush
,
604 add_insn_mem_dependence (deps
, &deps
->pending_write_insns
,
605 &deps
->pending_write_mems
, insn
, dest
);
607 sched_analyze_2 (deps
, XEXP (dest
, 0), insn
);
611 if (GET_CODE (x
) == SET
)
612 sched_analyze_2 (deps
, SET_SRC (x
), insn
);
615 /* Analyze the uses of memory and registers in rtx X in INSN. */
618 sched_analyze_2 (struct deps
*deps
, rtx x
, rtx insn
)
638 /* Ignore constants. Note that we must handle CONST_DOUBLE here
639 because it may have a cc0_rtx in its CONST_DOUBLE_CHAIN field, but
640 this does not mean that this insn is using cc0. */
645 /* User of CC0 depends on immediately preceding insn. */
646 set_sched_group_p (insn
);
647 /* Don't move CC0 setter to another block (it can set up the
648 same flag for previous CC0 users which is safe). */
649 CANT_MOVE (prev_nonnote_insn (insn
)) = 1;
655 int regno
= REGNO (x
);
656 if (regno
< FIRST_PSEUDO_REGISTER
)
658 int i
= hard_regno_nregs
[regno
][GET_MODE (x
)];
660 SET_REGNO_REG_SET (reg_pending_uses
, regno
+ i
);
662 /* ??? Reload sometimes emits USEs and CLOBBERs of pseudos that
663 it does not reload. Ignore these as they have served their
665 else if (regno
>= deps
->max_reg
)
667 gcc_assert (GET_CODE (PATTERN (insn
)) == USE
668 || GET_CODE (PATTERN (insn
)) == CLOBBER
);
672 SET_REGNO_REG_SET (reg_pending_uses
, regno
);
674 /* Pseudos that are REG_EQUIV to something may be replaced
675 by that during reloading. We need only add dependencies for
676 the address in the REG_EQUIV note. */
677 if (!reload_completed
&& get_reg_known_equiv_p (regno
))
679 rtx t
= get_reg_known_value (regno
);
681 sched_analyze_2 (deps
, XEXP (t
, 0), insn
);
684 /* If the register does not already cross any calls, then add this
685 insn to the sched_before_next_call list so that it will still
686 not cross calls after scheduling. */
687 if (REG_N_CALLS_CROSSED (regno
) == 0)
688 deps
->sched_before_next_call
689 = alloc_INSN_LIST (insn
, deps
->sched_before_next_call
);
696 /* Reading memory. */
698 rtx pending
, pending_mem
;
701 if (current_sched_info
->use_cselib
)
703 t
= shallow_copy_rtx (t
);
704 cselib_lookup (XEXP (t
, 0), Pmode
, 1);
705 XEXP (t
, 0) = cselib_subst_to_values (XEXP (t
, 0));
708 pending
= deps
->pending_read_insns
;
709 pending_mem
= deps
->pending_read_mems
;
712 if (read_dependence (XEXP (pending_mem
, 0), t
))
713 add_dependence (insn
, XEXP (pending
, 0), REG_DEP_ANTI
);
715 pending
= XEXP (pending
, 1);
716 pending_mem
= XEXP (pending_mem
, 1);
719 pending
= deps
->pending_write_insns
;
720 pending_mem
= deps
->pending_write_mems
;
723 if (true_dependence (XEXP (pending_mem
, 0), VOIDmode
,
725 add_dependence (insn
, XEXP (pending
, 0), 0);
727 pending
= XEXP (pending
, 1);
728 pending_mem
= XEXP (pending_mem
, 1);
731 for (u
= deps
->last_pending_memory_flush
; u
; u
= XEXP (u
, 1))
732 if (!JUMP_P (XEXP (u
, 0))
733 || deps_may_trap_p (x
))
734 add_dependence (insn
, XEXP (u
, 0), REG_DEP_ANTI
);
736 /* Always add these dependencies to pending_reads, since
737 this insn may be followed by a write. */
738 add_insn_mem_dependence (deps
, &deps
->pending_read_insns
,
739 &deps
->pending_read_mems
, insn
, x
);
741 /* Take advantage of tail recursion here. */
742 sched_analyze_2 (deps
, XEXP (x
, 0), insn
);
746 /* Force pending stores to memory in case a trap handler needs them. */
748 flush_pending_lists (deps
, insn
, true, false);
753 case UNSPEC_VOLATILE
:
755 /* Traditional and volatile asm instructions must be considered to use
756 and clobber all hard registers, all pseudo-registers and all of
757 memory. So must TRAP_IF and UNSPEC_VOLATILE operations.
759 Consider for instance a volatile asm that changes the fpu rounding
760 mode. An insn should not be moved across this even if it only uses
761 pseudo-regs because it might give an incorrectly rounded result. */
762 if (code
!= ASM_OPERANDS
|| MEM_VOLATILE_P (x
))
763 reg_pending_barrier
= TRUE_BARRIER
;
765 /* For all ASM_OPERANDS, we must traverse the vector of input operands.
766 We can not just fall through here since then we would be confused
767 by the ASM_INPUT rtx inside ASM_OPERANDS, which do not indicate
768 traditional asms unlike their normal usage. */
770 if (code
== ASM_OPERANDS
)
772 for (j
= 0; j
< ASM_OPERANDS_INPUT_LENGTH (x
); j
++)
773 sched_analyze_2 (deps
, ASM_OPERANDS_INPUT (x
, j
), insn
);
783 /* These both read and modify the result. We must handle them as writes
784 to get proper dependencies for following instructions. We must handle
785 them as reads to get proper dependencies from this to previous
786 instructions. Thus we need to pass them to both sched_analyze_1
787 and sched_analyze_2. We must call sched_analyze_2 first in order
788 to get the proper antecedent for the read. */
789 sched_analyze_2 (deps
, XEXP (x
, 0), insn
);
790 sched_analyze_1 (deps
, x
, insn
);
795 /* op0 = op0 + op1 */
796 sched_analyze_2 (deps
, XEXP (x
, 0), insn
);
797 sched_analyze_2 (deps
, XEXP (x
, 1), insn
);
798 sched_analyze_1 (deps
, x
, insn
);
805 /* Other cases: walk the insn. */
806 fmt
= GET_RTX_FORMAT (code
);
807 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
810 sched_analyze_2 (deps
, XEXP (x
, i
), insn
);
811 else if (fmt
[i
] == 'E')
812 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
813 sched_analyze_2 (deps
, XVECEXP (x
, i
, j
), insn
);
817 /* Analyze an INSN with pattern X to find all dependencies. */
820 sched_analyze_insn (struct deps
*deps
, rtx x
, rtx insn
, rtx loop_notes
)
822 RTX_CODE code
= GET_CODE (x
);
826 if (code
== COND_EXEC
)
828 sched_analyze_2 (deps
, COND_EXEC_TEST (x
), insn
);
830 /* ??? Should be recording conditions so we reduce the number of
831 false dependencies. */
832 x
= COND_EXEC_CODE (x
);
835 if (code
== SET
|| code
== CLOBBER
)
837 sched_analyze_1 (deps
, x
, insn
);
839 /* Bare clobber insns are used for letting life analysis, reg-stack
840 and others know that a value is dead. Depend on the last call
841 instruction so that reg-stack won't get confused. */
843 add_dependence_list (insn
, deps
->last_function_call
, REG_DEP_OUTPUT
);
845 else if (code
== PARALLEL
)
848 for (i
= XVECLEN (x
, 0) - 1; i
>= 0; i
--)
850 rtx sub
= XVECEXP (x
, 0, i
);
851 code
= GET_CODE (sub
);
853 if (code
== COND_EXEC
)
855 sched_analyze_2 (deps
, COND_EXEC_TEST (sub
), insn
);
856 sub
= COND_EXEC_CODE (sub
);
857 code
= GET_CODE (sub
);
859 if (code
== SET
|| code
== CLOBBER
)
860 sched_analyze_1 (deps
, sub
, insn
);
862 sched_analyze_2 (deps
, sub
, insn
);
866 sched_analyze_2 (deps
, x
, insn
);
868 /* Mark registers CLOBBERED or used by called function. */
871 for (link
= CALL_INSN_FUNCTION_USAGE (insn
); link
; link
= XEXP (link
, 1))
873 if (GET_CODE (XEXP (link
, 0)) == CLOBBER
)
874 sched_analyze_1 (deps
, XEXP (link
, 0), insn
);
876 sched_analyze_2 (deps
, XEXP (link
, 0), insn
);
878 if (find_reg_note (insn
, REG_SETJMP
, NULL
))
879 reg_pending_barrier
= MOVE_BARRIER
;
885 next
= next_nonnote_insn (insn
);
886 if (next
&& BARRIER_P (next
))
887 reg_pending_barrier
= TRUE_BARRIER
;
890 rtx pending
, pending_mem
;
891 regset_head tmp_uses
, tmp_sets
;
892 INIT_REG_SET (&tmp_uses
);
893 INIT_REG_SET (&tmp_sets
);
895 (*current_sched_info
->compute_jump_reg_dependencies
)
896 (insn
, &deps
->reg_conditional_sets
, &tmp_uses
, &tmp_sets
);
897 /* Make latency of jump equal to 0 by using anti-dependence. */
898 EXECUTE_IF_SET_IN_REG_SET (&tmp_uses
, 0, i
,
900 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
901 add_dependence_list (insn
, reg_last
->sets
, REG_DEP_ANTI
);
902 add_dependence_list (insn
, reg_last
->clobbers
, REG_DEP_ANTI
);
903 reg_last
->uses_length
++;
904 reg_last
->uses
= alloc_INSN_LIST (insn
, reg_last
->uses
);
906 IOR_REG_SET (reg_pending_sets
, &tmp_sets
);
908 CLEAR_REG_SET (&tmp_uses
);
909 CLEAR_REG_SET (&tmp_sets
);
911 /* All memory writes and volatile reads must happen before the
912 jump. Non-volatile reads must happen before the jump iff
913 the result is needed by the above register used mask. */
915 pending
= deps
->pending_write_insns
;
916 pending_mem
= deps
->pending_write_mems
;
919 add_dependence (insn
, XEXP (pending
, 0), REG_DEP_OUTPUT
);
920 pending
= XEXP (pending
, 1);
921 pending_mem
= XEXP (pending_mem
, 1);
924 pending
= deps
->pending_read_insns
;
925 pending_mem
= deps
->pending_read_mems
;
928 if (MEM_VOLATILE_P (XEXP (pending_mem
, 0)))
929 add_dependence (insn
, XEXP (pending
, 0), REG_DEP_OUTPUT
);
930 pending
= XEXP (pending
, 1);
931 pending_mem
= XEXP (pending_mem
, 1);
934 add_dependence_list (insn
, deps
->last_pending_memory_flush
,
939 /* If there is a {LOOP,EHREGION}_{BEG,END} note in the middle of a basic
940 block, then we must be sure that no instructions are scheduled across it.
941 Otherwise, the reg_n_refs info (which depends on loop_depth) would
947 /* Update loop_notes with any notes from this insn. Also determine
948 if any of the notes on the list correspond to instruction scheduling
949 barriers (loop, eh & setjmp notes, but not range notes). */
951 while (XEXP (link
, 1))
953 if (INTVAL (XEXP (link
, 0)) == NOTE_INSN_LOOP_BEG
954 || INTVAL (XEXP (link
, 0)) == NOTE_INSN_LOOP_END
955 || INTVAL (XEXP (link
, 0)) == NOTE_INSN_EH_REGION_BEG
956 || INTVAL (XEXP (link
, 0)) == NOTE_INSN_EH_REGION_END
)
957 reg_pending_barrier
= MOVE_BARRIER
;
959 link
= XEXP (link
, 1);
961 XEXP (link
, 1) = REG_NOTES (insn
);
962 REG_NOTES (insn
) = loop_notes
;
965 /* If this instruction can throw an exception, then moving it changes
966 where block boundaries fall. This is mighty confusing elsewhere.
967 Therefore, prevent such an instruction from being moved. */
968 if (can_throw_internal (insn
))
969 reg_pending_barrier
= MOVE_BARRIER
;
971 /* Add dependencies if a scheduling barrier was found. */
972 if (reg_pending_barrier
)
974 /* In the case of barrier the most added dependencies are not
975 real, so we use anti-dependence here. */
976 if (GET_CODE (PATTERN (insn
)) == COND_EXEC
)
978 EXECUTE_IF_SET_IN_REG_SET (&deps
->reg_last_in_use
, 0, i
,
980 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
981 add_dependence_list (insn
, reg_last
->uses
, REG_DEP_ANTI
);
983 (insn
, reg_last
->sets
,
984 reg_pending_barrier
== TRUE_BARRIER
? 0 : REG_DEP_ANTI
);
986 (insn
, reg_last
->clobbers
,
987 reg_pending_barrier
== TRUE_BARRIER
? 0 : REG_DEP_ANTI
);
992 EXECUTE_IF_SET_IN_REG_SET (&deps
->reg_last_in_use
, 0, i
,
994 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
995 add_dependence_list_and_free (insn
, ®_last
->uses
,
997 add_dependence_list_and_free
998 (insn
, ®_last
->sets
,
999 reg_pending_barrier
== TRUE_BARRIER
? 0 : REG_DEP_ANTI
);
1000 add_dependence_list_and_free
1001 (insn
, ®_last
->clobbers
,
1002 reg_pending_barrier
== TRUE_BARRIER
? 0 : REG_DEP_ANTI
);
1003 reg_last
->uses_length
= 0;
1004 reg_last
->clobbers_length
= 0;
1008 for (i
= 0; i
< deps
->max_reg
; i
++)
1010 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
1011 reg_last
->sets
= alloc_INSN_LIST (insn
, reg_last
->sets
);
1012 SET_REGNO_REG_SET (&deps
->reg_last_in_use
, i
);
1015 flush_pending_lists (deps
, insn
, true, true);
1016 CLEAR_REG_SET (&deps
->reg_conditional_sets
);
1017 reg_pending_barrier
= NOT_A_BARRIER
;
1021 /* If the current insn is conditional, we can't free any
1023 if (GET_CODE (PATTERN (insn
)) == COND_EXEC
)
1025 EXECUTE_IF_SET_IN_REG_SET (reg_pending_uses
, 0, i
,
1027 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
1028 add_dependence_list (insn
, reg_last
->sets
, 0);
1029 add_dependence_list (insn
, reg_last
->clobbers
, 0);
1030 reg_last
->uses
= alloc_INSN_LIST (insn
, reg_last
->uses
);
1031 reg_last
->uses_length
++;
1033 EXECUTE_IF_SET_IN_REG_SET (reg_pending_clobbers
, 0, i
,
1035 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
1036 add_dependence_list (insn
, reg_last
->sets
, REG_DEP_OUTPUT
);
1037 add_dependence_list (insn
, reg_last
->uses
, REG_DEP_ANTI
);
1038 reg_last
->clobbers
= alloc_INSN_LIST (insn
, reg_last
->clobbers
);
1039 reg_last
->clobbers_length
++;
1041 EXECUTE_IF_SET_IN_REG_SET (reg_pending_sets
, 0, i
,
1043 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
1044 add_dependence_list (insn
, reg_last
->sets
, REG_DEP_OUTPUT
);
1045 add_dependence_list (insn
, reg_last
->clobbers
, REG_DEP_OUTPUT
);
1046 add_dependence_list (insn
, reg_last
->uses
, REG_DEP_ANTI
);
1047 reg_last
->sets
= alloc_INSN_LIST (insn
, reg_last
->sets
);
1048 SET_REGNO_REG_SET (&deps
->reg_conditional_sets
, i
);
1053 EXECUTE_IF_SET_IN_REG_SET (reg_pending_uses
, 0, i
,
1055 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
1056 add_dependence_list (insn
, reg_last
->sets
, 0);
1057 add_dependence_list (insn
, reg_last
->clobbers
, 0);
1058 reg_last
->uses_length
++;
1059 reg_last
->uses
= alloc_INSN_LIST (insn
, reg_last
->uses
);
1061 EXECUTE_IF_SET_IN_REG_SET (reg_pending_clobbers
, 0, i
,
1063 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
1064 if (reg_last
->uses_length
> MAX_PENDING_LIST_LENGTH
1065 || reg_last
->clobbers_length
> MAX_PENDING_LIST_LENGTH
)
1067 add_dependence_list_and_free (insn
, ®_last
->sets
,
1069 add_dependence_list_and_free (insn
, ®_last
->uses
,
1071 add_dependence_list_and_free (insn
, ®_last
->clobbers
,
1073 reg_last
->sets
= alloc_INSN_LIST (insn
, reg_last
->sets
);
1074 reg_last
->clobbers_length
= 0;
1075 reg_last
->uses_length
= 0;
1079 add_dependence_list (insn
, reg_last
->sets
, REG_DEP_OUTPUT
);
1080 add_dependence_list (insn
, reg_last
->uses
, REG_DEP_ANTI
);
1082 reg_last
->clobbers_length
++;
1083 reg_last
->clobbers
= alloc_INSN_LIST (insn
, reg_last
->clobbers
);
1085 EXECUTE_IF_SET_IN_REG_SET (reg_pending_sets
, 0, i
,
1087 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
1088 add_dependence_list_and_free (insn
, ®_last
->sets
,
1090 add_dependence_list_and_free (insn
, ®_last
->clobbers
,
1092 add_dependence_list_and_free (insn
, ®_last
->uses
,
1094 reg_last
->sets
= alloc_INSN_LIST (insn
, reg_last
->sets
);
1095 reg_last
->uses_length
= 0;
1096 reg_last
->clobbers_length
= 0;
1097 CLEAR_REGNO_REG_SET (&deps
->reg_conditional_sets
, i
);
1101 IOR_REG_SET (&deps
->reg_last_in_use
, reg_pending_uses
);
1102 IOR_REG_SET (&deps
->reg_last_in_use
, reg_pending_clobbers
);
1103 IOR_REG_SET (&deps
->reg_last_in_use
, reg_pending_sets
);
1105 CLEAR_REG_SET (reg_pending_uses
);
1106 CLEAR_REG_SET (reg_pending_clobbers
);
1107 CLEAR_REG_SET (reg_pending_sets
);
1109 /* If we are currently in a libcall scheduling group, then mark the
1110 current insn as being in a scheduling group and that it can not
1111 be moved into a different basic block. */
1113 if (deps
->libcall_block_tail_insn
)
1115 set_sched_group_p (insn
);
1116 CANT_MOVE (insn
) = 1;
1119 /* If a post-call group is still open, see if it should remain so.
1120 This insn must be a simple move of a hard reg to a pseudo or
1123 We must avoid moving these insns for correctness on
1124 SMALL_REGISTER_CLASS machines, and for special registers like
1125 PIC_OFFSET_TABLE_REGNUM. For simplicity, extend this to all
1126 hard regs for all targets. */
1128 if (deps
->in_post_call_group_p
)
1130 rtx tmp
, set
= single_set (insn
);
1131 int src_regno
, dest_regno
;
1134 goto end_call_group
;
1136 tmp
= SET_DEST (set
);
1137 if (GET_CODE (tmp
) == SUBREG
)
1138 tmp
= SUBREG_REG (tmp
);
1140 dest_regno
= REGNO (tmp
);
1142 goto end_call_group
;
1144 tmp
= SET_SRC (set
);
1145 if (GET_CODE (tmp
) == SUBREG
)
1146 tmp
= SUBREG_REG (tmp
);
1147 if ((GET_CODE (tmp
) == PLUS
1148 || GET_CODE (tmp
) == MINUS
)
1149 && REG_P (XEXP (tmp
, 0))
1150 && REGNO (XEXP (tmp
, 0)) == STACK_POINTER_REGNUM
1151 && dest_regno
== STACK_POINTER_REGNUM
)
1152 src_regno
= STACK_POINTER_REGNUM
;
1153 else if (REG_P (tmp
))
1154 src_regno
= REGNO (tmp
);
1156 goto end_call_group
;
1158 if (src_regno
< FIRST_PSEUDO_REGISTER
1159 || dest_regno
< FIRST_PSEUDO_REGISTER
)
1161 /* If we are inside a post-call group right at the start of the
1162 scheduling region, we must not add a dependency. */
1163 if (deps
->in_post_call_group_p
== post_call_initial
)
1165 SCHED_GROUP_P (insn
) = 1;
1166 deps
->in_post_call_group_p
= post_call
;
1169 set_sched_group_p (insn
);
1170 CANT_MOVE (insn
) = 1;
1175 deps
->in_post_call_group_p
= not_post_call
;
1180 /* Analyze every insn between HEAD and TAIL inclusive, creating LOG_LINKS
1181 for every dependency. */
1184 sched_analyze (struct deps
*deps
, rtx head
, rtx tail
)
1189 if (current_sched_info
->use_cselib
)
1192 /* Before reload, if the previous block ended in a call, show that
1193 we are inside a post-call group, so as to keep the lifetimes of
1194 hard registers correct. */
1195 if (! reload_completed
&& !LABEL_P (head
))
1197 insn
= prev_nonnote_insn (head
);
1198 if (insn
&& CALL_P (insn
))
1199 deps
->in_post_call_group_p
= post_call_initial
;
1201 for (insn
= head
;; insn
= NEXT_INSN (insn
))
1203 rtx link
, end_seq
, r0
, set
;
1205 if (NONJUMP_INSN_P (insn
) || JUMP_P (insn
))
1207 /* Clear out the stale LOG_LINKS from flow. */
1208 free_INSN_LIST_list (&LOG_LINKS (insn
));
1210 /* Make each JUMP_INSN a scheduling barrier for memory
1214 /* Keep the list a reasonable size. */
1215 if (deps
->pending_flush_length
++ > MAX_PENDING_LIST_LENGTH
)
1216 flush_pending_lists (deps
, insn
, true, true);
1218 deps
->last_pending_memory_flush
1219 = alloc_INSN_LIST (insn
, deps
->last_pending_memory_flush
);
1221 sched_analyze_insn (deps
, PATTERN (insn
), insn
, loop_notes
);
1224 else if (CALL_P (insn
))
1228 CANT_MOVE (insn
) = 1;
1230 /* Clear out the stale LOG_LINKS from flow. */
1231 free_INSN_LIST_list (&LOG_LINKS (insn
));
1233 if (find_reg_note (insn
, REG_SETJMP
, NULL
))
1235 /* This is setjmp. Assume that all registers, not just
1236 hard registers, may be clobbered by this call. */
1237 reg_pending_barrier
= MOVE_BARRIER
;
1241 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1242 /* A call may read and modify global register variables. */
1245 SET_REGNO_REG_SET (reg_pending_sets
, i
);
1246 SET_REGNO_REG_SET (reg_pending_uses
, i
);
1248 /* Other call-clobbered hard regs may be clobbered.
1249 Since we only have a choice between 'might be clobbered'
1250 and 'definitely not clobbered', we must include all
1251 partly call-clobbered registers here. */
1252 else if (HARD_REGNO_CALL_PART_CLOBBERED (i
, reg_raw_mode
[i
])
1253 || TEST_HARD_REG_BIT (regs_invalidated_by_call
, i
))
1254 SET_REGNO_REG_SET (reg_pending_clobbers
, i
);
1255 /* We don't know what set of fixed registers might be used
1256 by the function, but it is certain that the stack pointer
1257 is among them, but be conservative. */
1258 else if (fixed_regs
[i
])
1259 SET_REGNO_REG_SET (reg_pending_uses
, i
);
1260 /* The frame pointer is normally not used by the function
1261 itself, but by the debugger. */
1262 /* ??? MIPS o32 is an exception. It uses the frame pointer
1263 in the macro expansion of jal but does not represent this
1264 fact in the call_insn rtl. */
1265 else if (i
== FRAME_POINTER_REGNUM
1266 || (i
== HARD_FRAME_POINTER_REGNUM
1267 && (! reload_completed
|| frame_pointer_needed
)))
1268 SET_REGNO_REG_SET (reg_pending_uses
, i
);
1271 /* For each insn which shouldn't cross a call, add a dependence
1272 between that insn and this call insn. */
1273 add_dependence_list_and_free (insn
, &deps
->sched_before_next_call
,
1276 sched_analyze_insn (deps
, PATTERN (insn
), insn
, loop_notes
);
1279 /* In the absence of interprocedural alias analysis, we must flush
1280 all pending reads and writes, and start new dependencies starting
1281 from here. But only flush writes for constant calls (which may
1282 be passed a pointer to something we haven't written yet). */
1283 flush_pending_lists (deps
, insn
, true, !CONST_OR_PURE_CALL_P (insn
));
1285 /* Remember the last function call for limiting lifetimes. */
1286 free_INSN_LIST_list (&deps
->last_function_call
);
1287 deps
->last_function_call
= alloc_INSN_LIST (insn
, NULL_RTX
);
1289 /* Before reload, begin a post-call group, so as to keep the
1290 lifetimes of hard registers correct. */
1291 if (! reload_completed
)
1292 deps
->in_post_call_group_p
= post_call
;
1295 /* See comments on reemit_notes as to why we do this.
1296 ??? Actually, the reemit_notes just say what is done, not why. */
1299 && (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_LOOP_BEG
1300 || NOTE_LINE_NUMBER (insn
) == NOTE_INSN_LOOP_END
1301 || NOTE_LINE_NUMBER (insn
) == NOTE_INSN_EH_REGION_BEG
1302 || NOTE_LINE_NUMBER (insn
) == NOTE_INSN_EH_REGION_END
))
1306 if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_EH_REGION_BEG
1307 || NOTE_LINE_NUMBER (insn
) == NOTE_INSN_EH_REGION_END
)
1308 rtx_region
= GEN_INT (NOTE_EH_HANDLER (insn
));
1310 rtx_region
= const0_rtx
;
1312 loop_notes
= alloc_EXPR_LIST (REG_SAVE_NOTE
,
1315 loop_notes
= alloc_EXPR_LIST (REG_SAVE_NOTE
,
1316 GEN_INT (NOTE_LINE_NUMBER (insn
)),
1318 CONST_OR_PURE_CALL_P (loop_notes
) = CONST_OR_PURE_CALL_P (insn
);
1321 if (current_sched_info
->use_cselib
)
1322 cselib_process_insn (insn
);
1324 /* Now that we have completed handling INSN, check and see if it is
1325 a CLOBBER beginning a libcall block. If it is, record the
1326 end of the libcall sequence.
1328 We want to schedule libcall blocks as a unit before reload. While
1329 this restricts scheduling, it preserves the meaning of a libcall
1332 As a side effect, we may get better code due to decreased register
1333 pressure as well as less chance of a foreign insn appearing in
1335 if (!reload_completed
1336 /* Note we may have nested libcall sequences. We only care about
1337 the outermost libcall sequence. */
1338 && deps
->libcall_block_tail_insn
== 0
1339 /* The sequence must start with a clobber of a register. */
1340 && NONJUMP_INSN_P (insn
)
1341 && GET_CODE (PATTERN (insn
)) == CLOBBER
1342 && (r0
= XEXP (PATTERN (insn
), 0), REG_P (r0
))
1343 && REG_P (XEXP (PATTERN (insn
), 0))
1344 /* The CLOBBER must also have a REG_LIBCALL note attached. */
1345 && (link
= find_reg_note (insn
, REG_LIBCALL
, NULL_RTX
)) != 0
1346 && (end_seq
= XEXP (link
, 0)) != 0
1347 /* The insn referenced by the REG_LIBCALL note must be a
1348 simple nop copy with the same destination as the register
1349 mentioned in the clobber. */
1350 && (set
= single_set (end_seq
)) != 0
1351 && SET_DEST (set
) == r0
&& SET_SRC (set
) == r0
1352 /* And finally the insn referenced by the REG_LIBCALL must
1353 also contain a REG_EQUAL note and a REG_RETVAL note. */
1354 && find_reg_note (end_seq
, REG_EQUAL
, NULL_RTX
) != 0
1355 && find_reg_note (end_seq
, REG_RETVAL
, NULL_RTX
) != 0)
1356 deps
->libcall_block_tail_insn
= XEXP (link
, 0);
1358 /* If we have reached the end of a libcall block, then close the
1360 if (deps
->libcall_block_tail_insn
== insn
)
1361 deps
->libcall_block_tail_insn
= 0;
1365 if (current_sched_info
->use_cselib
)
1374 /* The following function adds forward dependence (FROM, TO) with
1375 given DEP_TYPE. The forward dependence should be not exist before. */
1378 add_forward_dependence (rtx from
, rtx to
, enum reg_note dep_type
)
1382 #ifdef ENABLE_CHECKING
1383 /* If add_dependence is working properly there should never
1384 be notes, deleted insns or duplicates in the backward
1385 links. Thus we need not check for them here.
1387 However, if we have enabled checking we might as well go
1388 ahead and verify that add_dependence worked properly. */
1389 gcc_assert (!NOTE_P (from
));
1390 gcc_assert (!INSN_DELETED_P (from
));
1391 if (forward_dependency_cache
)
1392 gcc_assert (!bitmap_bit_p (&forward_dependency_cache
[INSN_LUID (from
)],
1395 gcc_assert (!find_insn_list (to
, INSN_DEPEND (from
)));
1397 /* ??? If bitmap_bit_p is a predicate, what is this supposed to do? */
1398 if (forward_dependency_cache
!= NULL
)
1399 bitmap_bit_p (&forward_dependency_cache
[INSN_LUID (from
)],
1403 new_link
= alloc_INSN_LIST (to
, INSN_DEPEND (from
));
1405 PUT_REG_NOTE_KIND (new_link
, dep_type
);
1407 INSN_DEPEND (from
) = new_link
;
1408 INSN_DEP_COUNT (to
) += 1;
1411 /* Examine insns in the range [ HEAD, TAIL ] and Use the backward
1412 dependences from LOG_LINKS to build forward dependences in
1416 compute_forward_dependences (rtx head
, rtx tail
)
1421 next_tail
= NEXT_INSN (tail
);
1422 for (insn
= head
; insn
!= next_tail
; insn
= NEXT_INSN (insn
))
1424 if (! INSN_P (insn
))
1427 for (link
= LOG_LINKS (insn
); link
; link
= XEXP (link
, 1))
1428 add_forward_dependence (XEXP (link
, 0), insn
, REG_NOTE_KIND (link
));
1432 /* Initialize variables for region data dependence analysis.
1433 n_bbs is the number of region blocks. */
1436 init_deps (struct deps
*deps
)
1438 int max_reg
= (reload_completed
? FIRST_PSEUDO_REGISTER
: max_reg_num ());
1440 deps
->max_reg
= max_reg
;
1441 deps
->reg_last
= xcalloc (max_reg
, sizeof (struct deps_reg
));
1442 INIT_REG_SET (&deps
->reg_last_in_use
);
1443 INIT_REG_SET (&deps
->reg_conditional_sets
);
1445 deps
->pending_read_insns
= 0;
1446 deps
->pending_read_mems
= 0;
1447 deps
->pending_write_insns
= 0;
1448 deps
->pending_write_mems
= 0;
1449 deps
->pending_lists_length
= 0;
1450 deps
->pending_flush_length
= 0;
1451 deps
->last_pending_memory_flush
= 0;
1452 deps
->last_function_call
= 0;
1453 deps
->sched_before_next_call
= 0;
1454 deps
->in_post_call_group_p
= not_post_call
;
1455 deps
->libcall_block_tail_insn
= 0;
1458 /* Free insn lists found in DEPS. */
1461 free_deps (struct deps
*deps
)
1465 free_INSN_LIST_list (&deps
->pending_read_insns
);
1466 free_EXPR_LIST_list (&deps
->pending_read_mems
);
1467 free_INSN_LIST_list (&deps
->pending_write_insns
);
1468 free_EXPR_LIST_list (&deps
->pending_write_mems
);
1469 free_INSN_LIST_list (&deps
->last_pending_memory_flush
);
1471 /* Without the EXECUTE_IF_SET, this loop is executed max_reg * nr_regions
1472 times. For a testcase with 42000 regs and 8000 small basic blocks,
1473 this loop accounted for nearly 60% (84 sec) of the total -O2 runtime. */
1474 EXECUTE_IF_SET_IN_REG_SET (&deps
->reg_last_in_use
, 0, i
,
1476 struct deps_reg
*reg_last
= &deps
->reg_last
[i
];
1478 free_INSN_LIST_list (®_last
->uses
);
1480 free_INSN_LIST_list (®_last
->sets
);
1481 if (reg_last
->clobbers
)
1482 free_INSN_LIST_list (®_last
->clobbers
);
1484 CLEAR_REG_SET (&deps
->reg_last_in_use
);
1485 CLEAR_REG_SET (&deps
->reg_conditional_sets
);
1487 free (deps
->reg_last
);
1490 /* If it is profitable to use them, initialize caches for tracking
1491 dependency information. LUID is the number of insns to be scheduled,
1492 it is used in the estimate of profitability. */
1495 init_dependency_caches (int luid
)
1497 /* ?!? We could save some memory by computing a per-region luid mapping
1498 which could reduce both the number of vectors in the cache and the size
1499 of each vector. Instead we just avoid the cache entirely unless the
1500 average number of instructions in a basic block is very high. See
1501 the comment before the declaration of true_dependency_cache for
1502 what we consider "very high". */
1503 if (luid
/ n_basic_blocks
> 100 * 5)
1506 true_dependency_cache
= xmalloc (luid
* sizeof (bitmap_head
));
1507 anti_dependency_cache
= xmalloc (luid
* sizeof (bitmap_head
));
1508 output_dependency_cache
= xmalloc (luid
* sizeof (bitmap_head
));
1509 #ifdef ENABLE_CHECKING
1510 forward_dependency_cache
= xmalloc (luid
* sizeof (bitmap_head
));
1512 for (i
= 0; i
< luid
; i
++)
1514 bitmap_initialize (&true_dependency_cache
[i
], 0);
1515 bitmap_initialize (&anti_dependency_cache
[i
], 0);
1516 bitmap_initialize (&output_dependency_cache
[i
], 0);
1517 #ifdef ENABLE_CHECKING
1518 bitmap_initialize (&forward_dependency_cache
[i
], 0);
1525 /* Free the caches allocated in init_dependency_caches. */
1528 free_dependency_caches (void)
1530 if (true_dependency_cache
)
1534 for (i
= 0; i
< cache_size
; i
++)
1536 bitmap_clear (&true_dependency_cache
[i
]);
1537 bitmap_clear (&anti_dependency_cache
[i
]);
1538 bitmap_clear (&output_dependency_cache
[i
]);
1539 #ifdef ENABLE_CHECKING
1540 bitmap_clear (&forward_dependency_cache
[i
]);
1543 free (true_dependency_cache
);
1544 true_dependency_cache
= NULL
;
1545 free (anti_dependency_cache
);
1546 anti_dependency_cache
= NULL
;
1547 free (output_dependency_cache
);
1548 output_dependency_cache
= NULL
;
1549 #ifdef ENABLE_CHECKING
1550 free (forward_dependency_cache
);
1551 forward_dependency_cache
= NULL
;
1556 /* Initialize some global variables needed by the dependency analysis
1560 init_deps_global (void)
1562 reg_pending_sets
= INITIALIZE_REG_SET (reg_pending_sets_head
);
1563 reg_pending_clobbers
= INITIALIZE_REG_SET (reg_pending_clobbers_head
);
1564 reg_pending_uses
= INITIALIZE_REG_SET (reg_pending_uses_head
);
1565 reg_pending_barrier
= NOT_A_BARRIER
;
1568 /* Free everything used by the dependency analysis code. */
1571 finish_deps_global (void)
1573 FREE_REG_SET (reg_pending_sets
);
1574 FREE_REG_SET (reg_pending_clobbers
);
1575 FREE_REG_SET (reg_pending_uses
);