1 /* Instruction scheduling pass. This file contains definitions used
2 internally in the scheduler.
3 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
4 2001, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
5 Free Software Foundation, Inc.
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
23 #ifndef GCC_SCHED_INT_H
24 #define GCC_SCHED_INT_H
26 #ifdef INSN_SCHEDULING
29 #include "insn-attr.h"
31 #include "basic-block.h"
33 /* For VEC (int, heap). */
36 /* Identificator of a scheduler pass. */
37 enum sched_pass_id_t
{ SCHED_PASS_UNKNOWN
, SCHED_RGN_PASS
, SCHED_EBB_PASS
,
38 SCHED_SMS_PASS
, SCHED_SEL_PASS
};
40 /* The algorithm used to implement -fsched-pressure. */
41 enum sched_pressure_algorithm
44 SCHED_PRESSURE_WEIGHTED
,
48 typedef VEC (basic_block
, heap
) *bb_vec_t
;
49 typedef VEC (rtx
, heap
) *insn_vec_t
;
50 typedef VEC (rtx
, heap
) *rtx_vec_t
;
52 extern void sched_init_bbs (void);
54 extern void sched_extend_luids (void);
55 extern void sched_init_insn_luid (rtx
);
56 extern void sched_init_luids (bb_vec_t
);
57 extern void sched_finish_luids (void);
59 extern void sched_extend_target (void);
61 extern void haifa_init_h_i_d (bb_vec_t
);
62 extern void haifa_finish_h_i_d (void);
64 /* Hooks that are common to all the schedulers. */
65 struct common_sched_info_def
67 /* Called after blocks were rearranged due to movement of jump instruction.
68 The first parameter - index of basic block, in which jump currently is.
69 The second parameter - index of basic block, in which jump used
71 The third parameter - index of basic block, that follows the second
73 void (*fix_recovery_cfg
) (int, int, int);
75 /* Called to notify frontend, that new basic block is being added.
76 The first parameter - new basic block.
77 The second parameter - block, after which new basic block is being added,
78 or EXIT_BLOCK_PTR, if recovery block is being added,
79 or NULL, if standalone block is being added. */
80 void (*add_block
) (basic_block
, basic_block
);
82 /* Estimate number of insns in the basic block. */
83 int (*estimate_number_of_insns
) (basic_block
);
85 /* Given a non-insn (!INSN_P (x)) return
86 -1 - if this rtx don't need a luid.
87 0 - if it should have the same luid as the previous insn.
88 1 - if it needs a separate luid. */
89 int (*luid_for_non_insn
) (rtx
);
91 /* Scheduler pass identifier. It is preferably used in assertions. */
92 enum sched_pass_id_t sched_pass_id
;
95 extern struct common_sched_info_def
*common_sched_info
;
97 extern const struct common_sched_info_def haifa_common_sched_info
;
99 /* Return true if selective scheduling pass is working. */
103 return common_sched_info
->sched_pass_id
== SCHED_SEL_PASS
;
106 /* Returns maximum priority that an insn was assigned to. */
107 extern int get_rgn_sched_max_insns_priority (void);
109 /* Increases effective priority for INSN by AMOUNT. */
110 extern void sel_add_to_insn_priority (rtx
, int);
112 /* True if during selective scheduling we need to emulate some of haifa
113 scheduler behaviour. */
114 extern int sched_emulate_haifa_p
;
116 /* Mapping from INSN_UID to INSN_LUID. In the end all other per insn data
117 structures should be indexed by luid. */
118 extern VEC (int, heap
) *sched_luids
;
119 #define INSN_LUID(INSN) (VEC_index (int, sched_luids, INSN_UID (INSN)))
120 #define LUID_BY_UID(UID) (VEC_index (int, sched_luids, UID))
122 #define SET_INSN_LUID(INSN, LUID) \
123 (VEC_replace (int, sched_luids, INSN_UID (INSN), (LUID)))
125 /* The highest INSN_LUID. */
126 extern int sched_max_luid
;
128 extern int insn_luid (rtx
);
130 /* This list holds ripped off notes from the current block. These notes will
131 be attached to the beginning of the block when its scheduling is
133 extern rtx note_list
;
135 extern void remove_notes (rtx
, rtx
);
136 extern rtx
restore_other_notes (rtx
, basic_block
);
137 extern void sched_insns_init (rtx
);
138 extern void sched_insns_finish (void);
140 extern void *xrecalloc (void *, size_t, size_t, size_t);
142 extern void reemit_notes (rtx
);
144 /* Functions in haifa-sched.c. */
145 extern int haifa_classify_insn (const_rtx
);
147 /* Functions in sel-sched-ir.c. */
148 extern void sel_find_rgns (void);
149 extern void sel_mark_hard_insn (rtx
);
151 extern size_t dfa_state_size
;
153 extern void advance_state (state_t
);
155 extern void setup_sched_dump (void);
156 extern void sched_init (void);
157 extern void sched_finish (void);
159 extern bool sel_insn_is_speculation_check (rtx
);
161 /* Describe the ready list of the scheduler.
162 VEC holds space enough for all insns in the current region. VECLEN
163 says how many exactly.
164 FIRST is the index of the element with the highest priority; i.e. the
165 last one in the ready list, since elements are ordered by ascending
167 N_READY determines how many insns are on the ready list.
168 N_DEBUG determines how many debug insns are on the ready list. */
178 extern char *ready_try
;
179 extern struct ready_list ready
;
181 extern int max_issue (struct ready_list
*, int, state_t
, bool, int *);
183 extern void ebb_compute_jump_reg_dependencies (rtx
, regset
);
185 extern edge
find_fallthru_edge_from (basic_block
);
187 extern void (* sched_init_only_bb
) (basic_block
, basic_block
);
188 extern basic_block (* sched_split_block
) (basic_block
, rtx
);
189 extern basic_block
sched_split_block_1 (basic_block
, rtx
);
190 extern basic_block (* sched_create_empty_bb
) (basic_block
);
191 extern basic_block
sched_create_empty_bb_1 (basic_block
);
193 extern basic_block
sched_create_recovery_block (basic_block
*);
194 extern void sched_create_recovery_edges (basic_block
, basic_block
,
197 /* Pointer to data describing the current DFA state. */
198 extern state_t curr_state
;
200 /* Type to represent status of a dependence. */
203 /* Type to represent weakness of speculative dependence. */
206 extern enum reg_note
ds_to_dk (ds_t
);
207 extern ds_t
dk_to_ds (enum reg_note
);
209 /* Information about the dependency. */
218 /* Dependency major type. This field is superseded by STATUS below.
219 Though, it is still in place because some targets use it. */
222 /* Dependency status. This field holds all dependency types and additional
223 information for speculative dependencies. */
226 /* Cached cost of the dependency. */
230 typedef struct _dep dep_def
;
231 typedef dep_def
*dep_t
;
233 #define DEP_PRO(D) ((D)->pro)
234 #define DEP_CON(D) ((D)->con)
235 #define DEP_TYPE(D) ((D)->type)
236 #define DEP_STATUS(D) ((D)->status)
237 #define DEP_COST(D) ((D)->cost)
239 #define UNKNOWN_DEP_COST INT_MIN
241 /* Functions to work with dep. */
243 extern void init_dep_1 (dep_t
, rtx
, rtx
, enum reg_note
, ds_t
);
244 extern void init_dep (dep_t
, rtx
, rtx
, enum reg_note
);
246 extern void sd_debug_dep (dep_t
);
248 /* Definition of this struct resides below. */
250 typedef struct _dep_node
*dep_node_t
;
252 /* A link in the dependency list. This is essentially an equivalent of a
253 single {INSN, DEPS}_LIST rtx. */
256 /* Dep node with all the data. */
259 /* Next link in the list. For the last one it is NULL. */
260 struct _dep_link
*next
;
262 /* Pointer to the next field of the previous link in the list.
263 For the first link this points to the deps_list->first.
265 With help of this field it is easy to remove and insert links to the
267 struct _dep_link
**prev_nextp
;
269 typedef struct _dep_link
*dep_link_t
;
271 #define DEP_LINK_NODE(N) ((N)->node)
272 #define DEP_LINK_NEXT(N) ((N)->next)
273 #define DEP_LINK_PREV_NEXTP(N) ((N)->prev_nextp)
275 /* Macros to work dep_link. For most usecases only part of the dependency
276 information is need. These macros conveniently provide that piece of
279 #define DEP_LINK_DEP(N) (DEP_NODE_DEP (DEP_LINK_NODE (N)))
280 #define DEP_LINK_PRO(N) (DEP_PRO (DEP_LINK_DEP (N)))
281 #define DEP_LINK_CON(N) (DEP_CON (DEP_LINK_DEP (N)))
282 #define DEP_LINK_TYPE(N) (DEP_TYPE (DEP_LINK_DEP (N)))
283 #define DEP_LINK_STATUS(N) (DEP_STATUS (DEP_LINK_DEP (N)))
285 /* A list of dep_links. */
291 /* Total number of elements in the list. */
294 typedef struct _deps_list
*deps_list_t
;
296 #define DEPS_LIST_FIRST(L) ((L)->first)
297 #define DEPS_LIST_N_LINKS(L) ((L)->n_links)
299 /* Suppose we have a dependence Y between insn pro1 and con1, where pro1 has
300 additional dependents con0 and con2, and con1 is dependent on additional
321 This is represented using a "dep_node" for each dependence arc, which are
322 connected as follows (diagram is centered around Y which is fully shown;
323 other dep_nodes shown partially):
325 . +------------+ +--------------+ +------------+
326 . : dep_node X : | dep_node Y | : dep_node Z :
329 . : forw : | forw | : forw :
330 . : +--------+ : | +--------+ | : +--------+ :
331 forw_deps : |dep_link| : | |dep_link| | : |dep_link| :
332 +-----+ : | +----+ | : | | +----+ | | : | +----+ | :
333 |first|----->| |next|-+------+->| |next|-+--+----->| |next|-+--->NULL
334 +-----+ : | +----+ | : | | +----+ | | : | +----+ | :
335 . ^ ^ : | ^ | : | | ^ | | : | | :
336 . | | : | | | : | | | | | : | | :
337 . | +--<----+--+ +--+---<--+--+--+ +--+--+--<---+--+ | :
338 . | : | | | : | | | | | : | | | :
339 . | : | +----+ | : | | +----+ | | : | +----+ | :
340 . | : | |prev| | : | | |prev| | | : | |prev| | :
341 . | : | |next| | : | | |next| | | : | |next| | :
342 . | : | +----+ | : | | +----+ | | : | +----+ | :
343 . | : | | :<-+ | | | |<-+ : | | :<-+
344 . | : | +----+ | : | | | +----+ | | | : | +----+ | : |
345 . | : | |node|-+----+ | | |node|-+--+--+ : | |node|-+----+
346 . | : | +----+ | : | | +----+ | | : | +----+ | :
347 . | : | | : | | | | : | | :
348 . | : +--------+ : | +--------+ | : +--------+ :
350 . | : SAME pro1 : | +--------+ | : SAME pro1 :
351 . | : DIFF con0 : | |dep | | : DIFF con2 :
354 .RTX<------------------------+--+-|pro1| | |
358 .RTX<------------------------+--+-|con1| | |
364 . | : : | | |stat| | | : :
365 . | : DIFF pro0 : | | +----+ | | : DIFF pro2 :
366 . | : SAME con1 : | | | | : SAME con1 :
367 . | : : | +--------+ | : :
369 . | : back : | back | : back :
370 . v : +--------+ : | +--------+ | : +--------+ :
371 back_deps : |dep_link| : | |dep_link| | : |dep_link| :
372 +-----+ : | +----+ | : | | +----+ | | : | +----+ | :
373 |first|----->| |next|-+------+->| |next|-+--+----->| |next|-+--->NULL
374 +-----+ : | +----+ | : | | +----+ | | : | +----+ | :
375 . ^ : | ^ | : | | ^ | | : | | :
376 . | : | | | : | | | | | : | | :
377 . +--<----+--+ +--+---<--+--+--+ +--+--+--<---+--+ | :
378 . : | | | : | | | | | : | | | :
379 . : | +----+ | : | | +----+ | | : | +----+ | :
380 . : | |prev| | : | | |prev| | | : | |prev| | :
381 . : | |next| | : | | |next| | | : | |next| | :
382 . : | +----+ | : | | +----+ | | : | +----+ | :
383 . : | | :<-+ | | | |<-+ : | | :<-+
384 . : | +----+ | : | | | +----+ | | | : | +----+ | : |
385 . : | |node|-+----+ | | |node|-+--+--+ : | |node|-+----+
386 . : | +----+ | : | | +----+ | | : | +----+ | :
387 . : | | : | | | | : | | :
388 . : +--------+ : | +--------+ | : +--------+ :
390 . : dep_node A : | dep_node Y | : dep_node B :
391 . +------------+ +--------------+ +------------+
397 struct _dep_link back
;
403 struct _dep_link forw
;
406 #define DEP_NODE_BACK(N) (&(N)->back)
407 #define DEP_NODE_DEP(N) (&(N)->dep)
408 #define DEP_NODE_FORW(N) (&(N)->forw)
410 /* The following enumeration values tell us what dependencies we
411 should use to implement the barrier. We use true-dependencies for
412 TRUE_BARRIER and anti-dependencies for MOVE_BARRIER. */
413 enum reg_pending_barrier_mode
420 /* Whether a register movement is associated with a call. */
428 /* Insns which affect pseudo-registers. */
440 /* Describe state of dependencies used during sched_analyze phase. */
443 /* The *_insns and *_mems are paired lists. Each pending memory operation
444 will have a pointer to the MEM rtx on one list and a pointer to the
445 containing insn on the other list in the same place in the list. */
447 /* We can't use add_dependence like the old code did, because a single insn
448 may have multiple memory accesses, and hence needs to be on the list
449 once for each memory access. Add_dependence won't let you add an insn
450 to a list more than once. */
452 /* An INSN_LIST containing all insns with pending read operations. */
453 rtx pending_read_insns
;
455 /* An EXPR_LIST containing all MEM rtx's which are pending reads. */
456 rtx pending_read_mems
;
458 /* An INSN_LIST containing all insns with pending write operations. */
459 rtx pending_write_insns
;
461 /* An EXPR_LIST containing all MEM rtx's which are pending writes. */
462 rtx pending_write_mems
;
464 /* An INSN_LIST containing all jump insns. */
465 rtx pending_jump_insns
;
467 /* We must prevent the above lists from ever growing too large since
468 the number of dependencies produced is at least O(N*N),
469 and execution time is at least O(4*N*N), as a function of the
470 length of these pending lists. */
472 /* Indicates the length of the pending_read list. */
473 int pending_read_list_length
;
475 /* Indicates the length of the pending_write list. */
476 int pending_write_list_length
;
478 /* Length of the pending memory flush list plus the length of the pending
479 jump insn list. Large functions with no calls may build up extremely
481 int pending_flush_length
;
483 /* The last insn upon which all memory references must depend.
484 This is an insn which flushed the pending lists, creating a dependency
485 between it and all previously pending memory references. This creates
486 a barrier (or a checkpoint) which no memory reference is allowed to cross.
488 This includes all non constant CALL_INSNs. When we do interprocedural
489 alias analysis, this restriction can be relaxed.
490 This may also be an INSN that writes memory if the pending lists grow
492 rtx last_pending_memory_flush
;
494 /* A list of the last function calls we have seen. We use a list to
495 represent last function calls from multiple predecessor blocks.
496 Used to prevent register lifetimes from expanding unnecessarily. */
497 rtx last_function_call
;
499 /* A list of the last function calls that may not return normally
500 we have seen. We use a list to represent last function calls from
501 multiple predecessor blocks. Used to prevent moving trapping insns
502 across such calls. */
503 rtx last_function_call_may_noreturn
;
505 /* A list of insns which use a pseudo register that does not already
506 cross a call. We create dependencies between each of those insn
507 and the next call insn, to ensure that they won't cross a call after
508 scheduling is done. */
509 rtx sched_before_next_call
;
511 /* Similarly, a list of insns which should not cross a branch. */
512 rtx sched_before_next_jump
;
514 /* Used to keep post-call pseudo/hard reg movements together with
516 enum post_call_group in_post_call_group_p
;
518 /* The last debug insn we've seen. */
521 /* The maximum register number for the following arrays. Before reload
522 this is max_reg_num; after reload it is FIRST_PSEUDO_REGISTER. */
525 /* Element N is the next insn that sets (hard or pseudo) register
526 N within the current basic block; or zero, if there is no
527 such insn. Needed for new registers which may be introduced
528 by splitting insns. */
529 struct deps_reg
*reg_last
;
531 /* Element N is set for each register that has any nonzero element
532 in reg_last[N].{uses,sets,clobbers}. */
533 regset_head reg_last_in_use
;
535 /* Shows the last value of reg_pending_barrier associated with the insn. */
536 enum reg_pending_barrier_mode last_reg_pending_barrier
;
538 /* True when this context should be treated as a readonly by
540 BOOL_BITFIELD readonly
: 1;
543 typedef struct deps_desc
*deps_t
;
545 /* This structure holds some state of the current scheduling pass, and
546 contains some function pointers that abstract out some of the non-generic
547 functionality from functions such as schedule_block or schedule_insn.
548 There is one global variable, current_sched_info, which points to the
549 sched_info structure currently in use. */
550 struct haifa_sched_info
552 /* Add all insns that are initially ready to the ready list. Called once
553 before scheduling a set of insns. */
554 void (*init_ready_list
) (void);
555 /* Called after taking an insn from the ready list. Returns nonzero if
556 this insn can be scheduled, nonzero if we should silently discard it. */
557 int (*can_schedule_ready_p
) (rtx
);
558 /* Return nonzero if there are more insns that should be scheduled. */
559 int (*schedule_more_p
) (void);
560 /* Called after an insn has all its hard dependencies resolved.
561 Adjusts status of instruction (which is passed through second parameter)
562 to indicate if instruction should be moved to the ready list or the
563 queue, or if it should silently discard it (until next resolved
565 ds_t (*new_ready
) (rtx
, ds_t
);
566 /* Compare priority of two insns. Return a positive number if the second
567 insn is to be preferred for scheduling, and a negative one if the first
568 is to be preferred. Zero if they are equally good. */
569 int (*rank
) (rtx
, rtx
);
570 /* Return a string that contains the insn uid and optionally anything else
571 necessary to identify this insn in an output. It's valid to use a
572 static buffer for this. The ALIGNED parameter should cause the string
573 to be formatted so that multiple output lines will line up nicely. */
574 const char *(*print_insn
) (const_rtx
, int);
575 /* Return nonzero if an insn should be included in priority
577 int (*contributes_to_priority
) (rtx
, rtx
);
579 /* Return true if scheduling insn (passed as the parameter) will trigger
580 finish of scheduling current block. */
581 bool (*insn_finishes_block_p
) (rtx
);
583 /* The boundaries of the set of insns to be scheduled. */
584 rtx prev_head
, next_tail
;
586 /* Filled in after the schedule is finished; the first and last scheduled
590 /* If nonzero, enables an additional sanity check in schedule_block. */
591 unsigned int queue_must_finish_empty
:1;
593 /* Maximum priority that has been assigned to an insn. */
594 int sched_max_insns_priority
;
596 /* Hooks to support speculative scheduling. */
598 /* Called to notify frontend that instruction is being added (second
599 parameter == 0) or removed (second parameter == 1). */
600 void (*add_remove_insn
) (rtx
, int);
602 /* Called to notify the frontend that instruction INSN is being
604 void (*begin_schedule_ready
) (rtx insn
);
606 /* Called to notify the frontend that an instruction INSN is about to be
607 moved to its correct place in the final schedule. This is done for all
608 insns in order of the schedule. LAST indicates the last scheduled
610 void (*begin_move_insn
) (rtx insn
, rtx last
);
612 /* If the second parameter is not NULL, return nonnull value, if the
613 basic block should be advanced.
614 If the second parameter is NULL, return the next basic block in EBB.
615 The first parameter is the current basic block in EBB. */
616 basic_block (*advance_target_bb
) (basic_block
, rtx
);
618 /* Allocate memory, store the frontend scheduler state in it, and
620 void *(*save_state
) (void);
621 /* Restore frontend scheduler state from the argument, and free the
623 void (*restore_state
) (void *);
625 /* ??? FIXME: should use straight bitfields inside sched_info instead of
630 /* This structure holds description of the properties for speculative
634 /* Holds types of allowed speculations: BEGIN_{DATA|CONTROL},
635 BE_IN_{DATA_CONTROL}. */
638 /* A dump file for additional information on speculative scheduling. */
641 /* Minimal cumulative weakness of speculative instruction's
642 dependencies, so that insn will be scheduled. */
643 dw_t data_weakness_cutoff
;
645 /* Minimal usefulness of speculative instruction to be considered for
647 int control_weakness_cutoff
;
649 /* Flags from the enum SPEC_SCHED_FLAGS. */
652 typedef struct spec_info_def
*spec_info_t
;
654 extern spec_info_t spec_info
;
656 extern struct haifa_sched_info
*current_sched_info
;
658 /* Do register pressure sensitive insn scheduling if the flag is set
660 extern enum sched_pressure_algorithm sched_pressure
;
662 /* Map regno -> its pressure class. The map defined only when
663 SCHED_PRESSURE_P is true. */
664 extern enum reg_class
*sched_regno_pressure_class
;
666 /* Indexed by INSN_UID, the collection of all data associated with
667 a single instruction. */
669 struct _haifa_deps_insn_data
671 /* The number of incoming edges in the forward dependency graph.
672 As scheduling proceeds, counts are decreased. An insn moves to
673 the ready queue when its counter reaches zero. */
676 /* Nonzero if instruction has internal dependence
677 (e.g. add_dependence was invoked with (insn == elem)). */
678 unsigned int has_internal_dep
;
680 /* NB: We can't place 'struct _deps_list' here instead of deps_list_t into
681 h_i_d because when h_i_d extends, addresses of the deps_list->first
682 change without updating deps_list->first->next->prev_nextp. Thus
683 BACK_DEPS and RESOLVED_BACK_DEPS are allocated on the heap and FORW_DEPS
684 list is allocated on the obstack. */
686 /* A list of hard backward dependencies. The insn is a consumer of all the
687 deps mentioned here. */
688 deps_list_t hard_back_deps
;
690 /* A list of speculative (weak) dependencies. The insn is a consumer of all
691 the deps mentioned here. */
692 deps_list_t spec_back_deps
;
694 /* A list of insns which depend on the instruction. Unlike 'back_deps',
695 it represents forward dependencies. */
696 deps_list_t forw_deps
;
698 /* A list of scheduled producers of the instruction. Links are being moved
699 from 'back_deps' to 'resolved_back_deps' while scheduling. */
700 deps_list_t resolved_back_deps
;
702 /* A list of scheduled consumers of the instruction. Links are being moved
703 from 'forw_deps' to 'resolved_forw_deps' while scheduling to fasten the
704 search in 'forw_deps'. */
705 deps_list_t resolved_forw_deps
;
707 /* If the insn is conditional (either through COND_EXEC, or because
708 it is a conditional branch), this records the condition. NULL
709 for insns that haven't been seen yet or don't have a condition;
710 const_true_rtx to mark an insn without a condition, or with a
711 condition that has been clobbered by a subsequent insn. */
714 /* For a conditional insn, a list of insns that could set the condition
715 register. Used when generating control dependencies. */
718 /* True if the condition in 'cond' should be reversed to get the actual
720 unsigned int reverse_cond
: 1;
722 /* Some insns (e.g. call) are not allowed to move across blocks. */
723 unsigned int cant_move
: 1;
726 /* Bits used for storing values of the fields in the following
728 #define INCREASE_BITS 8
730 /* The structure describes how the corresponding insn increases the
731 register pressure for each pressure class. */
732 struct reg_pressure_data
734 /* Pressure increase for given class because of clobber. */
735 unsigned int clobber_increase
: INCREASE_BITS
;
736 /* Increase in register pressure for given class because of register
738 unsigned int set_increase
: INCREASE_BITS
;
739 /* Pressure increase for given class because of unused register
741 unsigned int unused_set_increase
: INCREASE_BITS
;
742 /* Pressure change: #sets - #deaths. */
743 int change
: INCREASE_BITS
;
746 /* The following structure describes usage of registers by insns. */
749 /* Regno used in the insn. */
751 /* Insn using the regno. */
753 /* Cyclic list of elements with the same regno. */
754 struct reg_use_data
*next_regno_use
;
755 /* List of elements with the same insn. */
756 struct reg_use_data
*next_insn_use
;
759 /* The following structure describes used sets of registers by insns.
760 Registers are pseudos whose pressure class is not NO_REGS or hard
761 registers available for allocations. */
764 /* Regno used in the insn. */
766 /* Insn setting the regno. */
768 /* List of elements with the same insn. */
769 struct reg_set_data
*next_insn_set
;
772 struct _haifa_insn_data
774 /* We can't place 'struct _deps_list' into h_i_d instead of deps_list_t
775 because when h_i_d extends, addresses of the deps_list->first
776 change without updating deps_list->first->next->prev_nextp. */
778 /* Logical uid gives the original ordering of the insns. */
781 /* A priority for each insn. */
784 /* The minimum clock tick at which the insn becomes ready. This is
785 used to note timing constraints for the insns in the pending list. */
788 /* For insns that are scheduled at a fixed difference from another,
789 this records the tick in which they must be ready. */
792 /* INTER_TICK is used to adjust INSN_TICKs of instructions from the
793 subsequent blocks in a region. */
796 /* Used temporarily to estimate an INSN_TICK value for an insn given
797 current knowledge. */
800 /* See comment on QUEUE_INDEX macro in haifa-sched.c. */
805 /* '> 0' if priority is valid,
806 '== 0' if priority was not yet computed,
807 '< 0' if priority in invalid and should be recomputed. */
808 signed char priority_status
;
810 /* Set if there's DEF-USE dependence between some speculatively
811 moved load insn and this one. */
812 unsigned int fed_by_spec_load
: 1;
813 unsigned int is_load_insn
: 1;
814 /* Nonzero if this insn has negative-cost forward dependencies against
815 an already scheduled insn. */
816 unsigned int feeds_backtrack_insn
: 1;
818 /* Nonzero if this insn is a shadow of another, scheduled after a fixed
819 delay. We only emit shadows at the end of a cycle, with no other
820 real insns following them. */
821 unsigned int shadow_p
: 1;
823 /* Used internally in unschedule_insns_until to mark insns that must have
824 their TODO_SPEC recomputed. */
825 unsigned int must_recompute_spec
: 1;
827 /* What speculations are necessary to apply to schedule the instruction. */
830 /* What speculations were already applied. */
833 /* What speculations are checked by this instruction. */
836 /* Recovery block for speculation checks. */
837 basic_block recovery_block
;
839 /* Original pattern of the instruction. */
842 /* For insns with DEP_CONTROL dependencies, the predicated pattern if it
843 was ever successfully constructed. */
846 /* The following array contains info how the insn increases register
847 pressure. There is an element for each cover class of pseudos
848 referenced in insns. */
849 struct reg_pressure_data
*reg_pressure
;
850 /* The following array contains maximal reg pressure between last
851 scheduled insn and given insn. There is an element for each
852 pressure class of pseudos referenced in insns. This info updated
853 after scheduling each insn for each insn between the two
855 int *max_reg_pressure
;
856 /* The following list contains info about used pseudos and hard
857 registers available for allocation. */
858 struct reg_use_data
*reg_use_list
;
859 /* The following list contains info about set pseudos and hard
860 registers available for allocation. */
861 struct reg_set_data
*reg_set_list
;
862 /* Info about how scheduling the insn changes cost of register
863 pressure excess (between source and target). */
864 int reg_pressure_excess_cost_change
;
868 typedef struct _haifa_insn_data haifa_insn_data_def
;
869 typedef haifa_insn_data_def
*haifa_insn_data_t
;
871 DEF_VEC_O (haifa_insn_data_def
);
872 DEF_VEC_ALLOC_O (haifa_insn_data_def
, heap
);
874 extern VEC(haifa_insn_data_def
, heap
) *h_i_d
;
876 #define HID(INSN) (VEC_index (haifa_insn_data_def, h_i_d, INSN_UID (INSN)))
878 /* Accessor macros for h_i_d. There are more in haifa-sched.c and
880 #define INSN_PRIORITY(INSN) (HID (INSN)->priority)
881 #define INSN_REG_PRESSURE(INSN) (HID (INSN)->reg_pressure)
882 #define INSN_MAX_REG_PRESSURE(INSN) (HID (INSN)->max_reg_pressure)
883 #define INSN_REG_USE_LIST(INSN) (HID (INSN)->reg_use_list)
884 #define INSN_REG_SET_LIST(INSN) (HID (INSN)->reg_set_list)
885 #define INSN_REG_PRESSURE_EXCESS_COST_CHANGE(INSN) \
886 (HID (INSN)->reg_pressure_excess_cost_change)
887 #define INSN_PRIORITY_STATUS(INSN) (HID (INSN)->priority_status)
888 #define INSN_MODEL_INDEX(INSN) (HID (INSN)->model_index)
890 typedef struct _haifa_deps_insn_data haifa_deps_insn_data_def
;
891 typedef haifa_deps_insn_data_def
*haifa_deps_insn_data_t
;
893 DEF_VEC_O (haifa_deps_insn_data_def
);
894 DEF_VEC_ALLOC_O (haifa_deps_insn_data_def
, heap
);
896 extern VEC(haifa_deps_insn_data_def
, heap
) *h_d_i_d
;
898 #define HDID(INSN) (VEC_index (haifa_deps_insn_data_def, h_d_i_d, \
900 #define INSN_DEP_COUNT(INSN) (HDID (INSN)->dep_count)
901 #define HAS_INTERNAL_DEP(INSN) (HDID (INSN)->has_internal_dep)
902 #define INSN_FORW_DEPS(INSN) (HDID (INSN)->forw_deps)
903 #define INSN_RESOLVED_BACK_DEPS(INSN) (HDID (INSN)->resolved_back_deps)
904 #define INSN_RESOLVED_FORW_DEPS(INSN) (HDID (INSN)->resolved_forw_deps)
905 #define INSN_HARD_BACK_DEPS(INSN) (HDID (INSN)->hard_back_deps)
906 #define INSN_SPEC_BACK_DEPS(INSN) (HDID (INSN)->spec_back_deps)
907 #define INSN_CACHED_COND(INSN) (HDID (INSN)->cond)
908 #define INSN_REVERSE_COND(INSN) (HDID (INSN)->reverse_cond)
909 #define INSN_COND_DEPS(INSN) (HDID (INSN)->cond_deps)
910 #define CANT_MOVE(INSN) (HDID (INSN)->cant_move)
911 #define CANT_MOVE_BY_LUID(LUID) (VEC_index (haifa_deps_insn_data_def, h_d_i_d, \
915 #define INSN_PRIORITY(INSN) (HID (INSN)->priority)
916 #define INSN_PRIORITY_STATUS(INSN) (HID (INSN)->priority_status)
917 #define INSN_PRIORITY_KNOWN(INSN) (INSN_PRIORITY_STATUS (INSN) > 0)
918 #define TODO_SPEC(INSN) (HID (INSN)->todo_spec)
919 #define DONE_SPEC(INSN) (HID (INSN)->done_spec)
920 #define CHECK_SPEC(INSN) (HID (INSN)->check_spec)
921 #define RECOVERY_BLOCK(INSN) (HID (INSN)->recovery_block)
922 #define ORIG_PAT(INSN) (HID (INSN)->orig_pat)
923 #define PREDICATED_PAT(INSN) (HID (INSN)->predicated_pat)
925 /* INSN is either a simple or a branchy speculation check. */
926 #define IS_SPECULATION_CHECK_P(INSN) \
927 (sel_sched_p () ? sel_insn_is_speculation_check (INSN) : RECOVERY_BLOCK (INSN) != NULL)
929 /* INSN is a speculation check that will simply reexecute the speculatively
930 scheduled instruction if the speculation fails. */
931 #define IS_SPECULATION_SIMPLE_CHECK_P(INSN) \
932 (RECOVERY_BLOCK (INSN) == EXIT_BLOCK_PTR)
934 /* INSN is a speculation check that will branch to RECOVERY_BLOCK if the
935 speculation fails. Insns in that block will reexecute the speculatively
936 scheduled code and then will return immediately after INSN thus preserving
937 semantics of the program. */
938 #define IS_SPECULATION_BRANCHY_CHECK_P(INSN) \
939 (RECOVERY_BLOCK (INSN) != NULL && RECOVERY_BLOCK (INSN) != EXIT_BLOCK_PTR)
941 /* Dep status (aka ds_t) of the link encapsulates information, that is needed
942 for speculative scheduling. Namely, it is 4 integers in the range
943 [0, MAX_DEP_WEAK] and 3 bits.
944 The integers correspond to the probability of the dependence to *not*
945 exist, it is the probability, that overcoming of this dependence will
946 not be followed by execution of the recovery code. Nevertheless,
947 whatever high the probability of success is, recovery code should still
948 be generated to preserve semantics of the program. To find a way to
949 get/set these integers, please refer to the {get, set}_dep_weak ()
950 functions in sched-deps.c .
951 The 3 bits in the DEP_STATUS correspond to 3 dependence types: true-,
952 output- and anti- dependence. It is not enough for speculative scheduling
953 to know just the major type of all the dependence between two instructions,
954 as only true dependence can be overcome.
955 There also is the 4-th bit in the DEP_STATUS (HARD_DEP), that is reserved
956 for using to describe instruction's status. It is set whenever instruction
957 has at least one dependence, that cannot be overcame.
958 See also: check_dep_status () in sched-deps.c . */
960 /* We exclude sign bit. */
961 #define BITS_PER_DEP_STATUS (HOST_BITS_PER_INT - 1)
963 /* First '6' stands for 4 dep type bits and the HARD_DEP and DEP_CANCELLED
965 Second '4' stands for BEGIN_{DATA, CONTROL}, BE_IN_{DATA, CONTROL}
967 #define BITS_PER_DEP_WEAK ((BITS_PER_DEP_STATUS - 6) / 4)
969 /* Mask of speculative weakness in dep_status. */
970 #define DEP_WEAK_MASK ((1 << BITS_PER_DEP_WEAK) - 1)
972 /* This constant means that dependence is fake with 99.999...% probability.
973 This is the maximum value, that can appear in dep_status.
974 Note, that we don't want MAX_DEP_WEAK to be the same as DEP_WEAK_MASK for
975 debugging reasons. Though, it can be set to DEP_WEAK_MASK, and, when
976 done so, we'll get fast (mul for)/(div by) NO_DEP_WEAK. */
977 #define MAX_DEP_WEAK (DEP_WEAK_MASK - 1)
979 /* This constant means that dependence is 99.999...% real and it is a really
980 bad idea to overcome it (though this can be done, preserving program
982 #define MIN_DEP_WEAK 1
984 /* This constant represents 100% probability.
985 E.g. it is used to represent weakness of dependence, that doesn't exist. */
986 #define NO_DEP_WEAK (MAX_DEP_WEAK + MIN_DEP_WEAK)
988 /* Default weakness of speculative dependence. Used when we can't say
989 neither bad nor good about the dependence. */
990 #define UNCERTAIN_DEP_WEAK (MAX_DEP_WEAK - MAX_DEP_WEAK / 4)
992 /* Offset for speculative weaknesses in dep_status. */
993 enum SPEC_TYPES_OFFSETS
{
994 BEGIN_DATA_BITS_OFFSET
= 0,
995 BE_IN_DATA_BITS_OFFSET
= BEGIN_DATA_BITS_OFFSET
+ BITS_PER_DEP_WEAK
,
996 BEGIN_CONTROL_BITS_OFFSET
= BE_IN_DATA_BITS_OFFSET
+ BITS_PER_DEP_WEAK
,
997 BE_IN_CONTROL_BITS_OFFSET
= BEGIN_CONTROL_BITS_OFFSET
+ BITS_PER_DEP_WEAK
1000 /* The following defines provide numerous constants used to distinguish between
1001 different types of speculative dependencies. */
1003 /* Dependence can be overcome with generation of new data speculative
1005 #define BEGIN_DATA (((ds_t) DEP_WEAK_MASK) << BEGIN_DATA_BITS_OFFSET)
1007 /* This dependence is to the instruction in the recovery block, that was
1008 formed to recover after data-speculation failure.
1009 Thus, this dependence can overcome with generating of the copy of
1010 this instruction in the recovery block. */
1011 #define BE_IN_DATA (((ds_t) DEP_WEAK_MASK) << BE_IN_DATA_BITS_OFFSET)
1013 /* Dependence can be overcome with generation of new control speculative
1015 #define BEGIN_CONTROL (((ds_t) DEP_WEAK_MASK) << BEGIN_CONTROL_BITS_OFFSET)
1017 /* This dependence is to the instruction in the recovery block, that was
1018 formed to recover after control-speculation failure.
1019 Thus, this dependence can be overcome with generating of the copy of
1020 this instruction in the recovery block. */
1021 #define BE_IN_CONTROL (((ds_t) DEP_WEAK_MASK) << BE_IN_CONTROL_BITS_OFFSET)
1023 /* A few convenient combinations. */
1024 #define BEGIN_SPEC (BEGIN_DATA | BEGIN_CONTROL)
1025 #define DATA_SPEC (BEGIN_DATA | BE_IN_DATA)
1026 #define CONTROL_SPEC (BEGIN_CONTROL | BE_IN_CONTROL)
1027 #define SPECULATIVE (DATA_SPEC | CONTROL_SPEC)
1028 #define BE_IN_SPEC (BE_IN_DATA | BE_IN_CONTROL)
1030 /* Constants, that are helpful in iterating through dep_status. */
1031 #define FIRST_SPEC_TYPE BEGIN_DATA
1032 #define LAST_SPEC_TYPE BE_IN_CONTROL
1033 #define SPEC_TYPE_SHIFT BITS_PER_DEP_WEAK
1035 /* Dependence on instruction can be of multiple types
1036 (e.g. true and output). This fields enhance REG_NOTE_KIND information
1037 of the dependence. */
1038 #define DEP_TRUE (((ds_t) 1) << (BE_IN_CONTROL_BITS_OFFSET + BITS_PER_DEP_WEAK))
1039 #define DEP_OUTPUT (DEP_TRUE << 1)
1040 #define DEP_ANTI (DEP_OUTPUT << 1)
1041 #define DEP_CONTROL (DEP_ANTI << 1)
1043 #define DEP_TYPES (DEP_TRUE | DEP_OUTPUT | DEP_ANTI | DEP_CONTROL)
1045 /* Instruction has non-speculative dependence. This bit represents the
1046 property of an instruction - not the one of a dependence.
1047 Therefore, it can appear only in TODO_SPEC field of an instruction. */
1048 #define HARD_DEP (DEP_CONTROL << 1)
1050 #define DEP_CANCELLED (HARD_DEP << 1)
1052 /* This represents the results of calling sched-deps.c functions,
1053 which modify dependencies. */
1054 enum DEPS_ADJUST_RESULT
{
1055 /* No dependence needed (e.g. producer == consumer). */
1057 /* Dependence is already present and wasn't modified. */
1059 /* Existing dependence was modified to include additional information. */
1061 /* New dependence has been created. */
1065 /* Represents the bits that can be set in the flags field of the
1066 sched_info structure. */
1068 /* If set, generate links between instruction as DEPS_LIST.
1069 Otherwise, generate usual INSN_LIST links. */
1071 /* Perform data or control (or both) speculation.
1072 Results in generation of data and control speculative dependencies.
1073 Requires USE_DEPS_LIST set. */
1074 DO_SPECULATION
= USE_DEPS_LIST
<< 1,
1075 DO_BACKTRACKING
= DO_SPECULATION
<< 1,
1076 DO_PREDICATION
= DO_BACKTRACKING
<< 1,
1077 SCHED_RGN
= DO_PREDICATION
<< 1,
1078 SCHED_EBB
= SCHED_RGN
<< 1,
1079 /* Scheduler can possibly create new basic blocks. Used for assertions. */
1080 NEW_BBS
= SCHED_EBB
<< 1,
1081 SEL_SCHED
= NEW_BBS
<< 1
1084 enum SPEC_SCHED_FLAGS
{
1085 COUNT_SPEC_IN_CRITICAL_PATH
= 1,
1086 PREFER_NON_DATA_SPEC
= COUNT_SPEC_IN_CRITICAL_PATH
<< 1,
1087 PREFER_NON_CONTROL_SPEC
= PREFER_NON_DATA_SPEC
<< 1,
1088 SEL_SCHED_SPEC_DONT_CHECK_CONTROL
= PREFER_NON_CONTROL_SPEC
<< 1
1091 #define NOTE_NOT_BB_P(NOTE) (NOTE_P (NOTE) && (NOTE_KIND (NOTE) \
1092 != NOTE_INSN_BASIC_BLOCK))
1094 extern FILE *sched_dump
;
1095 extern int sched_verbose
;
1097 extern spec_info_t spec_info
;
1098 extern bool haifa_recovery_bb_ever_added_p
;
1100 /* Exception Free Loads:
1102 We define five classes of speculative loads: IFREE, IRISKY,
1103 PFREE, PRISKY, and MFREE.
1105 IFREE loads are loads that are proved to be exception-free, just
1106 by examining the load insn. Examples for such loads are loads
1107 from TOC and loads of global data.
1109 IRISKY loads are loads that are proved to be exception-risky,
1110 just by examining the load insn. Examples for such loads are
1111 volatile loads and loads from shared memory.
1113 PFREE loads are loads for which we can prove, by examining other
1114 insns, that they are exception-free. Currently, this class consists
1115 of loads for which we are able to find a "similar load", either in
1116 the target block, or, if only one split-block exists, in that split
1117 block. Load2 is similar to load1 if both have same single base
1118 register. We identify only part of the similar loads, by finding
1119 an insn upon which both load1 and load2 have a DEF-USE dependence.
1121 PRISKY loads are loads for which we can prove, by examining other
1122 insns, that they are exception-risky. Currently we have two proofs for
1123 such loads. The first proof detects loads that are probably guarded by a
1124 test on the memory address. This proof is based on the
1125 backward and forward data dependence information for the region.
1126 Let load-insn be the examined load.
1127 Load-insn is PRISKY iff ALL the following hold:
1129 - insn1 is not in the same block as load-insn
1130 - there is a DEF-USE dependence chain (insn1, ..., load-insn)
1131 - test-insn is either a compare or a branch, not in the same block
1133 - load-insn is reachable from test-insn
1134 - there is a DEF-USE dependence chain (insn1, ..., test-insn)
1136 This proof might fail when the compare and the load are fed
1137 by an insn not in the region. To solve this, we will add to this
1138 group all loads that have no input DEF-USE dependence.
1140 The second proof detects loads that are directly or indirectly
1141 fed by a speculative load. This proof is affected by the
1142 scheduling process. We will use the flag fed_by_spec_load.
1143 Initially, all insns have this flag reset. After a speculative
1144 motion of an insn, if insn is either a load, or marked as
1145 fed_by_spec_load, we will also mark as fed_by_spec_load every
1146 insn1 for which a DEF-USE dependence (insn, insn1) exists. A
1147 load which is fed_by_spec_load is also PRISKY.
1149 MFREE (maybe-free) loads are all the remaining loads. They may be
1150 exception-free, but we cannot prove it.
1152 Now, all loads in IFREE and PFREE classes are considered
1153 exception-free, while all loads in IRISKY and PRISKY classes are
1154 considered exception-risky. As for loads in the MFREE class,
1155 these are considered either exception-free or exception-risky,
1156 depending on whether we are pessimistic or optimistic. We have
1157 to take the pessimistic approach to assure the safety of
1158 speculative scheduling, but we can take the optimistic approach
1159 by invoking the -fsched_spec_load_dangerous option. */
1161 enum INSN_TRAP_CLASS
1163 TRAP_FREE
= 0, IFREE
= 1, PFREE_CANDIDATE
= 2,
1164 PRISKY_CANDIDATE
= 3, IRISKY
= 4, TRAP_RISKY
= 5
1167 #define WORST_CLASS(class1, class2) \
1168 ((class1 > class2) ? class1 : class2)
1174 #ifndef HAIFA_INLINE
1175 #define HAIFA_INLINE __inline
1178 struct sched_deps_info_def
1180 /* Called when computing dependencies for a JUMP_INSN. This function
1181 should store the set of registers that must be considered as set by
1182 the jump in the regset. */
1183 void (*compute_jump_reg_dependencies
) (rtx
, regset
);
1185 /* Start analyzing insn. */
1186 void (*start_insn
) (rtx
);
1188 /* Finish analyzing insn. */
1189 void (*finish_insn
) (void);
1191 /* Start analyzing insn LHS (Left Hand Side). */
1192 void (*start_lhs
) (rtx
);
1194 /* Finish analyzing insn LHS. */
1195 void (*finish_lhs
) (void);
1197 /* Start analyzing insn RHS (Right Hand Side). */
1198 void (*start_rhs
) (rtx
);
1200 /* Finish analyzing insn RHS. */
1201 void (*finish_rhs
) (void);
1203 /* Note set of the register. */
1204 void (*note_reg_set
) (int);
1206 /* Note clobber of the register. */
1207 void (*note_reg_clobber
) (int);
1209 /* Note use of the register. */
1210 void (*note_reg_use
) (int);
1212 /* Note memory dependence of type DS between MEM1 and MEM2 (which is
1214 void (*note_mem_dep
) (rtx mem1
, rtx mem2
, rtx insn2
, ds_t ds
);
1216 /* Note a dependence of type DS from the INSN. */
1217 void (*note_dep
) (rtx insn
, ds_t ds
);
1219 /* Nonzero if we should use cselib for better alias analysis. This
1220 must be 0 if the dependency information is used after sched_analyze
1221 has completed, e.g. if we're using it to initialize state for successor
1222 blocks in region scheduling. */
1223 unsigned int use_cselib
: 1;
1225 /* If set, generate links between instruction as DEPS_LIST.
1226 Otherwise, generate usual INSN_LIST links. */
1227 unsigned int use_deps_list
: 1;
1229 /* Generate data and control speculative dependencies.
1230 Requires USE_DEPS_LIST set. */
1231 unsigned int generate_spec_deps
: 1;
1234 extern struct sched_deps_info_def
*sched_deps_info
;
1237 /* Functions in sched-deps.c. */
1238 extern rtx
sched_get_reverse_condition_uncached (const_rtx
);
1239 extern bool sched_insns_conditions_mutex_p (const_rtx
, const_rtx
);
1240 extern bool sched_insn_is_legitimate_for_speculation_p (const_rtx
, ds_t
);
1241 extern void add_dependence (rtx
, rtx
, enum reg_note
);
1242 extern void sched_analyze (struct deps_desc
*, rtx
, rtx
);
1243 extern void init_deps (struct deps_desc
*, bool);
1244 extern void init_deps_reg_last (struct deps_desc
*);
1245 extern void free_deps (struct deps_desc
*);
1246 extern void init_deps_global (void);
1247 extern void finish_deps_global (void);
1248 extern void deps_analyze_insn (struct deps_desc
*, rtx
);
1249 extern void remove_from_deps (struct deps_desc
*, rtx
);
1250 extern void init_insn_reg_pressure_info (rtx
);
1252 extern dw_t
get_dep_weak_1 (ds_t
, ds_t
);
1253 extern dw_t
get_dep_weak (ds_t
, ds_t
);
1254 extern ds_t
set_dep_weak (ds_t
, ds_t
, dw_t
);
1255 extern dw_t
estimate_dep_weak (rtx
, rtx
);
1256 extern ds_t
ds_merge (ds_t
, ds_t
);
1257 extern ds_t
ds_full_merge (ds_t
, ds_t
, rtx
, rtx
);
1258 extern ds_t
ds_max_merge (ds_t
, ds_t
);
1259 extern dw_t
ds_weak (ds_t
);
1260 extern ds_t
ds_get_speculation_types (ds_t
);
1261 extern ds_t
ds_get_max_dep_weak (ds_t
);
1263 extern void sched_deps_init (bool);
1264 extern void sched_deps_finish (void);
1266 extern void haifa_note_reg_set (int);
1267 extern void haifa_note_reg_clobber (int);
1268 extern void haifa_note_reg_use (int);
1270 extern void maybe_extend_reg_info_p (void);
1272 extern void deps_start_bb (struct deps_desc
*, rtx
);
1273 extern enum reg_note
ds_to_dt (ds_t
);
1275 extern bool deps_pools_are_empty_p (void);
1276 extern void sched_free_deps (rtx
, rtx
, bool);
1277 extern void extend_dependency_caches (int, bool);
1279 extern void debug_ds (ds_t
);
1282 /* Functions in haifa-sched.c. */
1283 extern void sched_init_region_reg_pressure_info (void);
1284 extern int haifa_classify_insn (const_rtx
);
1285 extern void get_ebb_head_tail (basic_block
, basic_block
, rtx
*, rtx
*);
1286 extern int no_real_insns_p (const_rtx
, const_rtx
);
1288 extern int insn_cost (rtx
);
1289 extern int dep_cost_1 (dep_t
, dw_t
);
1290 extern int dep_cost (dep_t
);
1291 extern int set_priorities (rtx
, rtx
);
1293 extern void sched_setup_bb_reg_pressure_info (basic_block
, rtx
);
1294 extern bool schedule_block (basic_block
*);
1296 extern int cycle_issued_insns
;
1297 extern int issue_rate
;
1298 extern int dfa_lookahead
;
1300 extern void ready_sort (struct ready_list
*);
1301 extern rtx
ready_element (struct ready_list
*, int);
1302 extern rtx
*ready_lastpos (struct ready_list
*);
1304 extern int try_ready (rtx
);
1305 extern void sched_extend_ready_list (int);
1306 extern void sched_finish_ready_list (void);
1307 extern void sched_change_pattern (rtx
, rtx
);
1308 extern int sched_speculate_insn (rtx
, ds_t
, rtx
*);
1309 extern void unlink_bb_notes (basic_block
, basic_block
);
1310 extern void add_block (basic_block
, basic_block
);
1311 extern rtx
bb_note (basic_block
);
1312 extern void concat_note_lists (rtx
, rtx
*);
1313 extern rtx
sched_emit_insn (rtx
);
1314 extern rtx
get_ready_element (int);
1315 extern int number_in_ready (void);
1317 /* Types and functions in sched-ebb.c. */
1319 extern basic_block
schedule_ebb (rtx
, rtx
, bool);
1320 extern void schedule_ebbs_init (void);
1321 extern void schedule_ebbs_finish (void);
1323 /* Types and functions in sched-rgn.c. */
1325 /* A region is the main entity for interblock scheduling: insns
1326 are allowed to move between blocks in the same region, along
1327 control flow graph edges, in the 'up' direction. */
1330 /* Number of extended basic blocks in region. */
1332 /* cblocks in the region (actually index in rgn_bb_table). */
1334 /* Dependencies for this region are already computed. Basically, indicates,
1335 that this is a recovery block. */
1336 unsigned int dont_calc_deps
: 1;
1337 /* This region has at least one non-trivial ebb. */
1338 unsigned int has_real_ebb
: 1;
1342 extern int nr_regions
;
1343 extern region
*rgn_table
;
1344 extern int *rgn_bb_table
;
1345 extern int *block_to_bb
;
1346 extern int *containing_rgn
;
1348 /* Often used short-hand in the scheduler. The rest of the compiler uses
1349 BLOCK_FOR_INSN(INSN) and an indirect reference to get the basic block
1350 number ("index"). For historical reasons, the scheduler does not. */
1351 #define BLOCK_NUM(INSN) (BLOCK_FOR_INSN (INSN)->index + 0)
1353 #define RGN_NR_BLOCKS(rgn) (rgn_table[rgn].rgn_nr_blocks)
1354 #define RGN_BLOCKS(rgn) (rgn_table[rgn].rgn_blocks)
1355 #define RGN_DONT_CALC_DEPS(rgn) (rgn_table[rgn].dont_calc_deps)
1356 #define RGN_HAS_REAL_EBB(rgn) (rgn_table[rgn].has_real_ebb)
1357 #define BLOCK_TO_BB(block) (block_to_bb[block])
1358 #define CONTAINING_RGN(block) (containing_rgn[block])
1360 /* The mapping from ebb to block. */
1361 extern int *ebb_head
;
1362 #define BB_TO_BLOCK(ebb) (rgn_bb_table[ebb_head[ebb]])
1363 #define EBB_FIRST_BB(ebb) BASIC_BLOCK (BB_TO_BLOCK (ebb))
1364 #define EBB_LAST_BB(ebb) BASIC_BLOCK (rgn_bb_table[ebb_head[ebb + 1] - 1])
1365 #define INSN_BB(INSN) (BLOCK_TO_BB (BLOCK_NUM (INSN)))
1367 extern int current_nr_blocks
;
1368 extern int current_blocks
;
1369 extern int target_bb
;
1370 extern bool sched_no_dce
;
1372 extern void set_modulo_params (int, int, int, int);
1373 extern void record_delay_slot_pair (rtx
, rtx
, int, int);
1374 extern rtx
real_insn_for_shadow (rtx
);
1375 extern void discard_delay_pairs_above (int);
1376 extern void free_delay_pairs (void);
1377 extern void add_delay_dependencies (rtx
);
1378 extern bool sched_is_disabled_for_current_region_p (void);
1379 extern void sched_rgn_init (bool);
1380 extern void sched_rgn_finish (void);
1381 extern void rgn_setup_region (int);
1382 extern void sched_rgn_compute_dependencies (int);
1383 extern void sched_rgn_local_init (int);
1384 extern void sched_rgn_local_finish (void);
1385 extern void sched_rgn_local_free (void);
1386 extern void extend_regions (void);
1387 extern void rgn_make_new_region_out_of_new_block (basic_block
);
1389 extern void compute_priorities (void);
1390 extern void increase_insn_priority (rtx
, int);
1391 extern void debug_rgn_dependencies (int);
1392 extern void debug_dependencies (rtx
, rtx
);
1393 extern void free_rgn_deps (void);
1394 extern int contributes_to_priority (rtx
, rtx
);
1395 extern void extend_rgns (int *, int *, sbitmap
, int *);
1396 extern void deps_join (struct deps_desc
*, struct deps_desc
*);
1398 extern void rgn_setup_common_sched_info (void);
1399 extern void rgn_setup_sched_infos (void);
1401 extern void debug_regions (void);
1402 extern void debug_region (int);
1403 extern void dump_region_dot (FILE *, int);
1404 extern void dump_region_dot_file (const char *, int);
1406 extern void haifa_sched_init (void);
1407 extern void haifa_sched_finish (void);
1409 /* sched-deps.c interface to walk, add, search, update, resolve, delete
1410 and debug instruction dependencies. */
1412 /* Constants defining dependences lists. */
1415 #define SD_LIST_NONE (0)
1417 /* hard_back_deps. */
1418 #define SD_LIST_HARD_BACK (1)
1420 /* spec_back_deps. */
1421 #define SD_LIST_SPEC_BACK (2)
1424 #define SD_LIST_FORW (4)
1426 /* resolved_back_deps. */
1427 #define SD_LIST_RES_BACK (8)
1429 /* resolved_forw_deps. */
1430 #define SD_LIST_RES_FORW (16)
1432 #define SD_LIST_BACK (SD_LIST_HARD_BACK | SD_LIST_SPEC_BACK)
1434 /* A type to hold above flags. */
1435 typedef int sd_list_types_def
;
1437 extern void sd_next_list (const_rtx
, sd_list_types_def
*, deps_list_t
*, bool *);
1439 /* Iterator to walk through, resolve and delete dependencies. */
1442 /* What lists to walk. Can be any combination of SD_LIST_* flags. */
1443 sd_list_types_def types
;
1445 /* Instruction dependencies lists of which will be walked. */
1448 /* Pointer to the next field of the previous element. This is not
1449 simply a pointer to the next element to allow easy deletion from the
1450 list. When a dep is being removed from the list the iterator
1451 will automatically advance because the value in *linkp will start
1452 referring to the next element. */
1455 /* True if the current list is a resolved one. */
1459 typedef struct _sd_iterator sd_iterator_def
;
1461 /* ??? We can move some definitions that are used in below inline functions
1462 out of sched-int.h to sched-deps.c provided that the below functions will
1463 become global externals.
1464 These definitions include:
1465 * struct _deps_list: opaque pointer is needed at global scope.
1466 * struct _dep_link: opaque pointer is needed at scope of sd_iterator_def.
1467 * struct _dep_node: opaque pointer is needed at scope of
1468 struct _deps_link. */
1470 /* Return initialized iterator. */
1471 static inline sd_iterator_def
1472 sd_iterator_start (rtx insn
, sd_list_types_def types
)
1474 /* Some dep_link a pointer to which will return NULL. */
1475 static dep_link_t null_link
= NULL
;
1481 i
.linkp
= &null_link
;
1483 /* Avoid 'uninitialized warning'. */
1484 i
.resolved_p
= false;
1489 /* Return the current element. */
1491 sd_iterator_cond (sd_iterator_def
*it_ptr
, dep_t
*dep_ptr
)
1493 dep_link_t link
= *it_ptr
->linkp
;
1497 *dep_ptr
= DEP_LINK_DEP (link
);
1502 sd_list_types_def types
= it_ptr
->types
;
1504 if (types
!= SD_LIST_NONE
)
1505 /* Switch to next list. */
1509 sd_next_list (it_ptr
->insn
,
1510 &it_ptr
->types
, &list
, &it_ptr
->resolved_p
);
1512 it_ptr
->linkp
= &DEPS_LIST_FIRST (list
);
1515 return sd_iterator_cond (it_ptr
, dep_ptr
);
1523 /* Advance iterator. */
1525 sd_iterator_next (sd_iterator_def
*it_ptr
)
1527 it_ptr
->linkp
= &DEP_LINK_NEXT (*it_ptr
->linkp
);
1530 /* A cycle wrapper. */
1531 #define FOR_EACH_DEP(INSN, LIST_TYPES, ITER, DEP) \
1532 for ((ITER) = sd_iterator_start ((INSN), (LIST_TYPES)); \
1533 sd_iterator_cond (&(ITER), &(DEP)); \
1534 sd_iterator_next (&(ITER)))
1536 #define IS_DISPATCH_ON 1
1538 #define DISPATCH_VIOLATION 3
1539 #define FITS_DISPATCH_WINDOW 4
1540 #define DISPATCH_INIT 5
1541 #define ADD_TO_DISPATCH_WINDOW 6
1543 extern int sd_lists_size (const_rtx
, sd_list_types_def
);
1544 extern bool sd_lists_empty_p (const_rtx
, sd_list_types_def
);
1545 extern void sd_init_insn (rtx
);
1546 extern void sd_finish_insn (rtx
);
1547 extern dep_t
sd_find_dep_between (rtx
, rtx
, bool);
1548 extern void sd_add_dep (dep_t
, bool);
1549 extern enum DEPS_ADJUST_RESULT
sd_add_or_update_dep (dep_t
, bool);
1550 extern void sd_resolve_dep (sd_iterator_def
);
1551 extern void sd_unresolve_dep (sd_iterator_def
);
1552 extern void sd_copy_back_deps (rtx
, rtx
, bool);
1553 extern void sd_delete_dep (sd_iterator_def
);
1554 extern void sd_debug_lists (rtx
, sd_list_types_def
);
1556 #endif /* INSN_SCHEDULING */
1558 /* Functions in sched-vis.c. These must be outside INSN_SCHEDULING as
1559 sched-vis.c is compiled always. */
1560 extern void print_insn (char *, const_rtx
, int);
1561 extern void print_pattern (char *, const_rtx
, int);
1562 extern void print_value (char *, const_rtx
, int);
1564 #endif /* GCC_SCHED_INT_H */