1*404b540aSrobert /* Instruction scheduling pass. This file contains definitions used 2*404b540aSrobert internally in the scheduler. 3*404b540aSrobert Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 4*404b540aSrobert 1999, 2000, 2001, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. 5*404b540aSrobert 6*404b540aSrobert This file is part of GCC. 7*404b540aSrobert 8*404b540aSrobert GCC is free software; you can redistribute it and/or modify it under 9*404b540aSrobert the terms of the GNU General Public License as published by the Free 10*404b540aSrobert Software Foundation; either version 2, or (at your option) any later 11*404b540aSrobert version. 12*404b540aSrobert 13*404b540aSrobert GCC is distributed in the hope that it will be useful, but WITHOUT ANY 14*404b540aSrobert WARRANTY; without even the implied warranty of MERCHANTABILITY or 15*404b540aSrobert FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 16*404b540aSrobert for more details. 17*404b540aSrobert 18*404b540aSrobert You should have received a copy of the GNU General Public License 19*404b540aSrobert along with GCC; see the file COPYING. If not, write to the Free 20*404b540aSrobert Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 21*404b540aSrobert 02110-1301, USA. */ 22*404b540aSrobert 23*404b540aSrobert #ifndef GCC_SCHED_INT_H 24*404b540aSrobert #define GCC_SCHED_INT_H 25*404b540aSrobert 26*404b540aSrobert /* For state_t. */ 27*404b540aSrobert #include "insn-attr.h" 28*404b540aSrobert /* For regset_head. */ 29*404b540aSrobert #include "basic-block.h" 30*404b540aSrobert /* For reg_note. */ 31*404b540aSrobert #include "rtl.h" 32*404b540aSrobert 33*404b540aSrobert /* Pointer to data describing the current DFA state. */ 34*404b540aSrobert extern state_t curr_state; 35*404b540aSrobert 36*404b540aSrobert /* Forward declaration. */ 37*404b540aSrobert struct ready_list; 38*404b540aSrobert 39*404b540aSrobert /* Type to represent status of a dependence. */ 40*404b540aSrobert typedef int ds_t; 41*404b540aSrobert 42*404b540aSrobert /* Type to represent weakness of speculative dependence. */ 43*404b540aSrobert typedef int dw_t; 44*404b540aSrobert 45*404b540aSrobert /* Describe state of dependencies used during sched_analyze phase. */ 46*404b540aSrobert struct deps 47*404b540aSrobert { 48*404b540aSrobert /* The *_insns and *_mems are paired lists. Each pending memory operation 49*404b540aSrobert will have a pointer to the MEM rtx on one list and a pointer to the 50*404b540aSrobert containing insn on the other list in the same place in the list. */ 51*404b540aSrobert 52*404b540aSrobert /* We can't use add_dependence like the old code did, because a single insn 53*404b540aSrobert may have multiple memory accesses, and hence needs to be on the list 54*404b540aSrobert once for each memory access. Add_dependence won't let you add an insn 55*404b540aSrobert to a list more than once. */ 56*404b540aSrobert 57*404b540aSrobert /* An INSN_LIST containing all insns with pending read operations. */ 58*404b540aSrobert rtx pending_read_insns; 59*404b540aSrobert 60*404b540aSrobert /* An EXPR_LIST containing all MEM rtx's which are pending reads. */ 61*404b540aSrobert rtx pending_read_mems; 62*404b540aSrobert 63*404b540aSrobert /* An INSN_LIST containing all insns with pending write operations. */ 64*404b540aSrobert rtx pending_write_insns; 65*404b540aSrobert 66*404b540aSrobert /* An EXPR_LIST containing all MEM rtx's which are pending writes. */ 67*404b540aSrobert rtx pending_write_mems; 68*404b540aSrobert 69*404b540aSrobert /* Indicates the combined length of the two pending lists. We must prevent 70*404b540aSrobert these lists from ever growing too large since the number of dependencies 71*404b540aSrobert produced is at least O(N*N), and execution time is at least O(4*N*N), as 72*404b540aSrobert a function of the length of these pending lists. */ 73*404b540aSrobert int pending_lists_length; 74*404b540aSrobert 75*404b540aSrobert /* Length of the pending memory flush list. Large functions with no 76*404b540aSrobert calls may build up extremely large lists. */ 77*404b540aSrobert int pending_flush_length; 78*404b540aSrobert 79*404b540aSrobert /* The last insn upon which all memory references must depend. 80*404b540aSrobert This is an insn which flushed the pending lists, creating a dependency 81*404b540aSrobert between it and all previously pending memory references. This creates 82*404b540aSrobert a barrier (or a checkpoint) which no memory reference is allowed to cross. 83*404b540aSrobert 84*404b540aSrobert This includes all non constant CALL_INSNs. When we do interprocedural 85*404b540aSrobert alias analysis, this restriction can be relaxed. 86*404b540aSrobert This may also be an INSN that writes memory if the pending lists grow 87*404b540aSrobert too large. */ 88*404b540aSrobert rtx last_pending_memory_flush; 89*404b540aSrobert 90*404b540aSrobert /* A list of the last function calls we have seen. We use a list to 91*404b540aSrobert represent last function calls from multiple predecessor blocks. 92*404b540aSrobert Used to prevent register lifetimes from expanding unnecessarily. */ 93*404b540aSrobert rtx last_function_call; 94*404b540aSrobert 95*404b540aSrobert /* A list of insns which use a pseudo register that does not already 96*404b540aSrobert cross a call. We create dependencies between each of those insn 97*404b540aSrobert and the next call insn, to ensure that they won't cross a call after 98*404b540aSrobert scheduling is done. */ 99*404b540aSrobert rtx sched_before_next_call; 100*404b540aSrobert 101*404b540aSrobert /* Used to keep post-call pseudo/hard reg movements together with 102*404b540aSrobert the call. */ 103*404b540aSrobert enum { not_post_call, post_call, post_call_initial } in_post_call_group_p; 104*404b540aSrobert 105*404b540aSrobert /* Set to the tail insn of the outermost libcall block. 106*404b540aSrobert 107*404b540aSrobert When nonzero, we will mark each insn processed by sched_analyze_insn 108*404b540aSrobert with SCHED_GROUP_P to ensure libcalls are scheduled as a unit. */ 109*404b540aSrobert rtx libcall_block_tail_insn; 110*404b540aSrobert 111*404b540aSrobert /* The maximum register number for the following arrays. Before reload 112*404b540aSrobert this is max_reg_num; after reload it is FIRST_PSEUDO_REGISTER. */ 113*404b540aSrobert int max_reg; 114*404b540aSrobert 115*404b540aSrobert /* Element N is the next insn that sets (hard or pseudo) register 116*404b540aSrobert N within the current basic block; or zero, if there is no 117*404b540aSrobert such insn. Needed for new registers which may be introduced 118*404b540aSrobert by splitting insns. */ 119*404b540aSrobert struct deps_reg 120*404b540aSrobert { 121*404b540aSrobert rtx uses; 122*404b540aSrobert rtx sets; 123*404b540aSrobert rtx clobbers; 124*404b540aSrobert int uses_length; 125*404b540aSrobert int clobbers_length; 126*404b540aSrobert } *reg_last; 127*404b540aSrobert 128*404b540aSrobert /* Element N is set for each register that has any nonzero element 129*404b540aSrobert in reg_last[N].{uses,sets,clobbers}. */ 130*404b540aSrobert regset_head reg_last_in_use; 131*404b540aSrobert 132*404b540aSrobert /* Element N is set for each register that is conditionally set. */ 133*404b540aSrobert regset_head reg_conditional_sets; 134*404b540aSrobert }; 135*404b540aSrobert 136*404b540aSrobert /* This structure holds some state of the current scheduling pass, and 137*404b540aSrobert contains some function pointers that abstract out some of the non-generic 138*404b540aSrobert functionality from functions such as schedule_block or schedule_insn. 139*404b540aSrobert There is one global variable, current_sched_info, which points to the 140*404b540aSrobert sched_info structure currently in use. */ 141*404b540aSrobert struct sched_info 142*404b540aSrobert { 143*404b540aSrobert /* Add all insns that are initially ready to the ready list. Called once 144*404b540aSrobert before scheduling a set of insns. */ 145*404b540aSrobert void (*init_ready_list) (void); 146*404b540aSrobert /* Called after taking an insn from the ready list. Returns nonzero if 147*404b540aSrobert this insn can be scheduled, nonzero if we should silently discard it. */ 148*404b540aSrobert int (*can_schedule_ready_p) (rtx); 149*404b540aSrobert /* Return nonzero if there are more insns that should be scheduled. */ 150*404b540aSrobert int (*schedule_more_p) (void); 151*404b540aSrobert /* Called after an insn has all its hard dependencies resolved. 152*404b540aSrobert Adjusts status of instruction (which is passed through second parameter) 153*404b540aSrobert to indicate if instruction should be moved to the ready list or the 154*404b540aSrobert queue, or if it should silently discard it (until next resolved 155*404b540aSrobert dependence). */ 156*404b540aSrobert ds_t (*new_ready) (rtx, ds_t); 157*404b540aSrobert /* Compare priority of two insns. Return a positive number if the second 158*404b540aSrobert insn is to be preferred for scheduling, and a negative one if the first 159*404b540aSrobert is to be preferred. Zero if they are equally good. */ 160*404b540aSrobert int (*rank) (rtx, rtx); 161*404b540aSrobert /* Return a string that contains the insn uid and optionally anything else 162*404b540aSrobert necessary to identify this insn in an output. It's valid to use a 163*404b540aSrobert static buffer for this. The ALIGNED parameter should cause the string 164*404b540aSrobert to be formatted so that multiple output lines will line up nicely. */ 165*404b540aSrobert const char *(*print_insn) (rtx, int); 166*404b540aSrobert /* Return nonzero if an insn should be included in priority 167*404b540aSrobert calculations. */ 168*404b540aSrobert int (*contributes_to_priority) (rtx, rtx); 169*404b540aSrobert /* Called when computing dependencies for a JUMP_INSN. This function 170*404b540aSrobert should store the set of registers that must be considered as set by 171*404b540aSrobert the jump in the regset. */ 172*404b540aSrobert void (*compute_jump_reg_dependencies) (rtx, regset, regset, regset); 173*404b540aSrobert 174*404b540aSrobert /* The boundaries of the set of insns to be scheduled. */ 175*404b540aSrobert rtx prev_head, next_tail; 176*404b540aSrobert 177*404b540aSrobert /* Filled in after the schedule is finished; the first and last scheduled 178*404b540aSrobert insns. */ 179*404b540aSrobert rtx head, tail; 180*404b540aSrobert 181*404b540aSrobert /* If nonzero, enables an additional sanity check in schedule_block. */ 182*404b540aSrobert unsigned int queue_must_finish_empty:1; 183*404b540aSrobert /* Nonzero if we should use cselib for better alias analysis. This 184*404b540aSrobert must be 0 if the dependency information is used after sched_analyze 185*404b540aSrobert has completed, e.g. if we're using it to initialize state for successor 186*404b540aSrobert blocks in region scheduling. */ 187*404b540aSrobert unsigned int use_cselib:1; 188*404b540aSrobert 189*404b540aSrobert /* Maximum priority that has been assigned to an insn. */ 190*404b540aSrobert int sched_max_insns_priority; 191*404b540aSrobert 192*404b540aSrobert /* Hooks to support speculative scheduling. */ 193*404b540aSrobert 194*404b540aSrobert /* Called to notify frontend that instruction is being added (second 195*404b540aSrobert parameter == 0) or removed (second parameter == 1). */ 196*404b540aSrobert void (*add_remove_insn) (rtx, int); 197*404b540aSrobert 198*404b540aSrobert /* Called to notify frontend that instruction is being scheduled. 199*404b540aSrobert The first parameter - instruction to scheduled, the second parameter - 200*404b540aSrobert last scheduled instruction. */ 201*404b540aSrobert void (*begin_schedule_ready) (rtx, rtx); 202*404b540aSrobert 203*404b540aSrobert /* Called to notify frontend, that new basic block is being added. 204*404b540aSrobert The first parameter - new basic block. 205*404b540aSrobert The second parameter - block, after which new basic block is being added, 206*404b540aSrobert or EXIT_BLOCK_PTR, if recovery block is being added, 207*404b540aSrobert or NULL, if standalone block is being added. */ 208*404b540aSrobert void (*add_block) (basic_block, basic_block); 209*404b540aSrobert 210*404b540aSrobert /* If the second parameter is not NULL, return nonnull value, if the 211*404b540aSrobert basic block should be advanced. 212*404b540aSrobert If the second parameter is NULL, return the next basic block in EBB. 213*404b540aSrobert The first parameter is the current basic block in EBB. */ 214*404b540aSrobert basic_block (*advance_target_bb) (basic_block, rtx); 215*404b540aSrobert 216*404b540aSrobert /* Called after blocks were rearranged due to movement of jump instruction. 217*404b540aSrobert The first parameter - index of basic block, in which jump currently is. 218*404b540aSrobert The second parameter - index of basic block, in which jump used 219*404b540aSrobert to be. 220*404b540aSrobert The third parameter - index of basic block, that follows the second 221*404b540aSrobert parameter. */ 222*404b540aSrobert void (*fix_recovery_cfg) (int, int, int); 223*404b540aSrobert 224*404b540aSrobert #ifdef ENABLE_CHECKING 225*404b540aSrobert /* If the second parameter is zero, return nonzero, if block is head of the 226*404b540aSrobert region. 227*404b540aSrobert If the second parameter is nonzero, return nonzero, if block is leaf of 228*404b540aSrobert the region. 229*404b540aSrobert global_live_at_start should not change in region heads and 230*404b540aSrobert global_live_at_end should not change in region leafs due to scheduling. */ 231*404b540aSrobert int (*region_head_or_leaf_p) (basic_block, int); 232*404b540aSrobert #endif 233*404b540aSrobert 234*404b540aSrobert /* ??? FIXME: should use straight bitfields inside sched_info instead of 235*404b540aSrobert this flag field. */ 236*404b540aSrobert unsigned int flags; 237*404b540aSrobert }; 238*404b540aSrobert 239*404b540aSrobert /* This structure holds description of the properties for speculative 240*404b540aSrobert scheduling. */ 241*404b540aSrobert struct spec_info_def 242*404b540aSrobert { 243*404b540aSrobert /* Holds types of allowed speculations: BEGIN_{DATA|CONTROL}, 244*404b540aSrobert BE_IN_{DATA_CONTROL}. */ 245*404b540aSrobert int mask; 246*404b540aSrobert 247*404b540aSrobert /* A dump file for additional information on speculative scheduling. */ 248*404b540aSrobert FILE *dump; 249*404b540aSrobert 250*404b540aSrobert /* Minimal cumulative weakness of speculative instruction's 251*404b540aSrobert dependencies, so that insn will be scheduled. */ 252*404b540aSrobert dw_t weakness_cutoff; 253*404b540aSrobert 254*404b540aSrobert /* Flags from the enum SPEC_SCHED_FLAGS. */ 255*404b540aSrobert int flags; 256*404b540aSrobert }; 257*404b540aSrobert typedef struct spec_info_def *spec_info_t; 258*404b540aSrobert 259*404b540aSrobert extern struct sched_info *current_sched_info; 260*404b540aSrobert 261*404b540aSrobert /* Indexed by INSN_UID, the collection of all data associated with 262*404b540aSrobert a single instruction. */ 263*404b540aSrobert 264*404b540aSrobert struct haifa_insn_data 265*404b540aSrobert { 266*404b540aSrobert /* A list of insns which depend on the instruction. Unlike LOG_LINKS, 267*404b540aSrobert it represents forward dependencies. */ 268*404b540aSrobert rtx depend; 269*404b540aSrobert 270*404b540aSrobert /* A list of scheduled producers of the instruction. Links are being moved 271*404b540aSrobert from LOG_LINKS to RESOLVED_DEPS during scheduling. */ 272*404b540aSrobert rtx resolved_deps; 273*404b540aSrobert 274*404b540aSrobert /* The line number note in effect for each insn. For line number 275*404b540aSrobert notes, this indicates whether the note may be reused. */ 276*404b540aSrobert rtx line_note; 277*404b540aSrobert 278*404b540aSrobert /* Logical uid gives the original ordering of the insns. */ 279*404b540aSrobert int luid; 280*404b540aSrobert 281*404b540aSrobert /* A priority for each insn. */ 282*404b540aSrobert int priority; 283*404b540aSrobert 284*404b540aSrobert /* The number of incoming edges in the forward dependency graph. 285*404b540aSrobert As scheduling proceeds, counts are decreased. An insn moves to 286*404b540aSrobert the ready queue when its counter reaches zero. */ 287*404b540aSrobert int dep_count; 288*404b540aSrobert 289*404b540aSrobert /* Number of instructions referring to this insn. */ 290*404b540aSrobert int ref_count; 291*404b540aSrobert 292*404b540aSrobert /* The minimum clock tick at which the insn becomes ready. This is 293*404b540aSrobert used to note timing constraints for the insns in the pending list. */ 294*404b540aSrobert int tick; 295*404b540aSrobert 296*404b540aSrobert /* INTER_TICK is used to adjust INSN_TICKs of instructions from the 297*404b540aSrobert subsequent blocks in a region. */ 298*404b540aSrobert int inter_tick; 299*404b540aSrobert 300*404b540aSrobert /* See comment on QUEUE_INDEX macro in haifa-sched.c. */ 301*404b540aSrobert int queue_index; 302*404b540aSrobert 303*404b540aSrobert short cost; 304*404b540aSrobert 305*404b540aSrobert /* This weight is an estimation of the insn's contribution to 306*404b540aSrobert register pressure. */ 307*404b540aSrobert short reg_weight; 308*404b540aSrobert 309*404b540aSrobert /* Some insns (e.g. call) are not allowed to move across blocks. */ 310*404b540aSrobert unsigned int cant_move : 1; 311*404b540aSrobert 312*404b540aSrobert /* Set if there's DEF-USE dependence between some speculatively 313*404b540aSrobert moved load insn and this one. */ 314*404b540aSrobert unsigned int fed_by_spec_load : 1; 315*404b540aSrobert unsigned int is_load_insn : 1; 316*404b540aSrobert 317*404b540aSrobert /* Nonzero if priority has been computed already. */ 318*404b540aSrobert unsigned int priority_known : 1; 319*404b540aSrobert 320*404b540aSrobert /* Nonzero if instruction has internal dependence 321*404b540aSrobert (e.g. add_dependence was invoked with (insn == elem)). */ 322*404b540aSrobert unsigned int has_internal_dep : 1; 323*404b540aSrobert 324*404b540aSrobert /* What speculations are necessary to apply to schedule the instruction. */ 325*404b540aSrobert ds_t todo_spec; 326*404b540aSrobert /* What speculations were already applied. */ 327*404b540aSrobert ds_t done_spec; 328*404b540aSrobert /* What speculations are checked by this instruction. */ 329*404b540aSrobert ds_t check_spec; 330*404b540aSrobert 331*404b540aSrobert /* Recovery block for speculation checks. */ 332*404b540aSrobert basic_block recovery_block; 333*404b540aSrobert 334*404b540aSrobert /* Original pattern of the instruction. */ 335*404b540aSrobert rtx orig_pat; 336*404b540aSrobert }; 337*404b540aSrobert 338*404b540aSrobert extern struct haifa_insn_data *h_i_d; 339*404b540aSrobert /* Used only if (current_sched_info->flags & USE_GLAT) != 0. 340*404b540aSrobert These regsets store global_live_at_{start, end} information 341*404b540aSrobert for each basic block. */ 342*404b540aSrobert extern regset *glat_start, *glat_end; 343*404b540aSrobert 344*404b540aSrobert /* Accessor macros for h_i_d. There are more in haifa-sched.c and 345*404b540aSrobert sched-rgn.c. */ 346*404b540aSrobert #define INSN_DEPEND(INSN) (h_i_d[INSN_UID (INSN)].depend) 347*404b540aSrobert #define RESOLVED_DEPS(INSN) (h_i_d[INSN_UID (INSN)].resolved_deps) 348*404b540aSrobert #define INSN_LUID(INSN) (h_i_d[INSN_UID (INSN)].luid) 349*404b540aSrobert #define CANT_MOVE(insn) (h_i_d[INSN_UID (insn)].cant_move) 350*404b540aSrobert #define INSN_DEP_COUNT(INSN) (h_i_d[INSN_UID (INSN)].dep_count) 351*404b540aSrobert #define INSN_PRIORITY(INSN) (h_i_d[INSN_UID (INSN)].priority) 352*404b540aSrobert #define INSN_PRIORITY_KNOWN(INSN) (h_i_d[INSN_UID (INSN)].priority_known) 353*404b540aSrobert #define INSN_COST(INSN) (h_i_d[INSN_UID (INSN)].cost) 354*404b540aSrobert #define INSN_REG_WEIGHT(INSN) (h_i_d[INSN_UID (INSN)].reg_weight) 355*404b540aSrobert #define HAS_INTERNAL_DEP(INSN) (h_i_d[INSN_UID (INSN)].has_internal_dep) 356*404b540aSrobert #define TODO_SPEC(INSN) (h_i_d[INSN_UID (INSN)].todo_spec) 357*404b540aSrobert #define DONE_SPEC(INSN) (h_i_d[INSN_UID (INSN)].done_spec) 358*404b540aSrobert #define CHECK_SPEC(INSN) (h_i_d[INSN_UID (INSN)].check_spec) 359*404b540aSrobert #define RECOVERY_BLOCK(INSN) (h_i_d[INSN_UID (INSN)].recovery_block) 360*404b540aSrobert #define ORIG_PAT(INSN) (h_i_d[INSN_UID (INSN)].orig_pat) 361*404b540aSrobert 362*404b540aSrobert /* INSN is either a simple or a branchy speculation check. */ 363*404b540aSrobert #define IS_SPECULATION_CHECK_P(INSN) (RECOVERY_BLOCK (INSN) != NULL) 364*404b540aSrobert 365*404b540aSrobert /* INSN is a speculation check that will simply reexecute the speculatively 366*404b540aSrobert scheduled instruction if the speculation fails. */ 367*404b540aSrobert #define IS_SPECULATION_SIMPLE_CHECK_P(INSN) \ 368*404b540aSrobert (RECOVERY_BLOCK (INSN) == EXIT_BLOCK_PTR) 369*404b540aSrobert 370*404b540aSrobert /* INSN is a speculation check that will branch to RECOVERY_BLOCK if the 371*404b540aSrobert speculation fails. Insns in that block will reexecute the speculatively 372*404b540aSrobert scheduled code and then will return immediately after INSN thus preserving 373*404b540aSrobert semantics of the program. */ 374*404b540aSrobert #define IS_SPECULATION_BRANCHY_CHECK_P(INSN) \ 375*404b540aSrobert (RECOVERY_BLOCK (INSN) != NULL && RECOVERY_BLOCK (INSN) != EXIT_BLOCK_PTR) 376*404b540aSrobert 377*404b540aSrobert /* DEP_STATUS of the link encapsulates information, that is needed for 378*404b540aSrobert speculative scheduling. Namely, it is 4 integers in the range 379*404b540aSrobert [0, MAX_DEP_WEAK] and 3 bits. 380*404b540aSrobert The integers correspond to the probability of the dependence to *not* 381*404b540aSrobert exist, it is the probability, that overcoming of this dependence will 382*404b540aSrobert not be followed by execution of the recovery code. Nevertheless, 383*404b540aSrobert whatever high the probability of success is, recovery code should still 384*404b540aSrobert be generated to preserve semantics of the program. To find a way to 385*404b540aSrobert get/set these integers, please refer to the {get, set}_dep_weak () 386*404b540aSrobert functions in sched-deps.c . 387*404b540aSrobert The 3 bits in the DEP_STATUS correspond to 3 dependence types: true-, 388*404b540aSrobert output- and anti- dependence. It is not enough for speculative scheduling 389*404b540aSrobert to know just the major type of all the dependence between two instructions, 390*404b540aSrobert as only true dependence can be overcome. 391*404b540aSrobert There also is the 4-th bit in the DEP_STATUS (HARD_DEP), that is reserved 392*404b540aSrobert for using to describe instruction's status. It is set whenever instruction 393*404b540aSrobert has at least one dependence, that cannot be overcome. 394*404b540aSrobert See also: check_dep_status () in sched-deps.c . */ 395*404b540aSrobert #define DEP_STATUS(LINK) XINT (LINK, 2) 396*404b540aSrobert 397*404b540aSrobert /* We exclude sign bit. */ 398*404b540aSrobert #define BITS_PER_DEP_STATUS (HOST_BITS_PER_INT - 1) 399*404b540aSrobert 400*404b540aSrobert /* First '4' stands for 3 dep type bits and HARD_DEP bit. 401*404b540aSrobert Second '4' stands for BEGIN_{DATA, CONTROL}, BE_IN_{DATA, CONTROL} 402*404b540aSrobert dep weakness. */ 403*404b540aSrobert #define BITS_PER_DEP_WEAK ((BITS_PER_DEP_STATUS - 4) / 4) 404*404b540aSrobert 405*404b540aSrobert /* Mask of speculative weakness in dep_status. */ 406*404b540aSrobert #define DEP_WEAK_MASK ((1 << BITS_PER_DEP_WEAK) - 1) 407*404b540aSrobert 408*404b540aSrobert /* This constant means that dependence is fake with 99.999...% probability. 409*404b540aSrobert This is the maximum value, that can appear in dep_status. 410*404b540aSrobert Note, that we don't want MAX_DEP_WEAK to be the same as DEP_WEAK_MASK for 411*404b540aSrobert debugging reasons. Though, it can be set to DEP_WEAK_MASK, and, when 412*404b540aSrobert done so, we'll get fast (mul for)/(div by) NO_DEP_WEAK. */ 413*404b540aSrobert #define MAX_DEP_WEAK (DEP_WEAK_MASK - 1) 414*404b540aSrobert 415*404b540aSrobert /* This constant means that dependence is 99.999...% real and it is a really 416*404b540aSrobert bad idea to overcome it (though this can be done, preserving program 417*404b540aSrobert semantics). */ 418*404b540aSrobert #define MIN_DEP_WEAK 1 419*404b540aSrobert 420*404b540aSrobert /* This constant represents 100% probability. 421*404b540aSrobert E.g. it is used to represent weakness of dependence, that doesn't exist. */ 422*404b540aSrobert #define NO_DEP_WEAK (MAX_DEP_WEAK + MIN_DEP_WEAK) 423*404b540aSrobert 424*404b540aSrobert /* Default weakness of speculative dependence. Used when we can't say 425*404b540aSrobert neither bad nor good about the dependence. */ 426*404b540aSrobert #define UNCERTAIN_DEP_WEAK (MAX_DEP_WEAK - MAX_DEP_WEAK / 4) 427*404b540aSrobert 428*404b540aSrobert /* Offset for speculative weaknesses in dep_status. */ 429*404b540aSrobert enum SPEC_TYPES_OFFSETS { 430*404b540aSrobert BEGIN_DATA_BITS_OFFSET = 0, 431*404b540aSrobert BE_IN_DATA_BITS_OFFSET = BEGIN_DATA_BITS_OFFSET + BITS_PER_DEP_WEAK, 432*404b540aSrobert BEGIN_CONTROL_BITS_OFFSET = BE_IN_DATA_BITS_OFFSET + BITS_PER_DEP_WEAK, 433*404b540aSrobert BE_IN_CONTROL_BITS_OFFSET = BEGIN_CONTROL_BITS_OFFSET + BITS_PER_DEP_WEAK 434*404b540aSrobert }; 435*404b540aSrobert 436*404b540aSrobert /* The following defines provide numerous constants used to distinguish between 437*404b540aSrobert different types of speculative dependencies. */ 438*404b540aSrobert 439*404b540aSrobert /* Dependence can be overcome with generation of new data speculative 440*404b540aSrobert instruction. */ 441*404b540aSrobert #define BEGIN_DATA (((ds_t) DEP_WEAK_MASK) << BEGIN_DATA_BITS_OFFSET) 442*404b540aSrobert 443*404b540aSrobert /* This dependence is to the instruction in the recovery block, that was 444*404b540aSrobert formed to recover after data-speculation failure. 445*404b540aSrobert Thus, this dependence can overcome with generating of the copy of 446*404b540aSrobert this instruction in the recovery block. */ 447*404b540aSrobert #define BE_IN_DATA (((ds_t) DEP_WEAK_MASK) << BE_IN_DATA_BITS_OFFSET) 448*404b540aSrobert 449*404b540aSrobert /* Dependence can be overcome with generation of new control speculative 450*404b540aSrobert instruction. */ 451*404b540aSrobert #define BEGIN_CONTROL (((ds_t) DEP_WEAK_MASK) << BEGIN_CONTROL_BITS_OFFSET) 452*404b540aSrobert 453*404b540aSrobert /* This dependence is to the instruction in the recovery block, that was 454*404b540aSrobert formed to recover after control-speculation failure. 455*404b540aSrobert Thus, this dependence can be overcome with generating of the copy of 456*404b540aSrobert this instruction in the recovery block. */ 457*404b540aSrobert #define BE_IN_CONTROL (((ds_t) DEP_WEAK_MASK) << BE_IN_CONTROL_BITS_OFFSET) 458*404b540aSrobert 459*404b540aSrobert /* A few convenient combinations. */ 460*404b540aSrobert #define BEGIN_SPEC (BEGIN_DATA | BEGIN_CONTROL) 461*404b540aSrobert #define DATA_SPEC (BEGIN_DATA | BE_IN_DATA) 462*404b540aSrobert #define CONTROL_SPEC (BEGIN_CONTROL | BE_IN_CONTROL) 463*404b540aSrobert #define SPECULATIVE (DATA_SPEC | CONTROL_SPEC) 464*404b540aSrobert #define BE_IN_SPEC (BE_IN_DATA | BE_IN_CONTROL) 465*404b540aSrobert 466*404b540aSrobert /* Constants, that are helpful in iterating through dep_status. */ 467*404b540aSrobert #define FIRST_SPEC_TYPE BEGIN_DATA 468*404b540aSrobert #define LAST_SPEC_TYPE BE_IN_CONTROL 469*404b540aSrobert #define SPEC_TYPE_SHIFT BITS_PER_DEP_WEAK 470*404b540aSrobert 471*404b540aSrobert /* Dependence on instruction can be of multiple types 472*404b540aSrobert (e.g. true and output). This fields enhance REG_NOTE_KIND information 473*404b540aSrobert of the dependence. */ 474*404b540aSrobert #define DEP_TRUE (((ds_t) 1) << (BE_IN_CONTROL_BITS_OFFSET + BITS_PER_DEP_WEAK)) 475*404b540aSrobert #define DEP_OUTPUT (DEP_TRUE << 1) 476*404b540aSrobert #define DEP_ANTI (DEP_OUTPUT << 1) 477*404b540aSrobert 478*404b540aSrobert #define DEP_TYPES (DEP_TRUE | DEP_OUTPUT | DEP_ANTI) 479*404b540aSrobert 480*404b540aSrobert /* Instruction has non-speculative dependence. This bit represents the 481*404b540aSrobert property of an instruction - not the one of a dependence. 482*404b540aSrobert Therefore, it can appear only in TODO_SPEC field of an instruction. */ 483*404b540aSrobert #define HARD_DEP (DEP_ANTI << 1) 484*404b540aSrobert 485*404b540aSrobert /* This represents the results of calling sched-deps.c functions, 486*404b540aSrobert which modify dependencies. Possible choices are: a dependence 487*404b540aSrobert is already present and nothing has been changed; a dependence type 488*404b540aSrobert has been changed; brand new dependence has been created. */ 489*404b540aSrobert enum DEPS_ADJUST_RESULT { 490*404b540aSrobert DEP_PRESENT = 1, 491*404b540aSrobert DEP_CHANGED = 2, 492*404b540aSrobert DEP_CREATED = 3 493*404b540aSrobert }; 494*404b540aSrobert 495*404b540aSrobert /* Represents the bits that can be set in the flags field of the 496*404b540aSrobert sched_info structure. */ 497*404b540aSrobert enum SCHED_FLAGS { 498*404b540aSrobert /* If set, generate links between instruction as DEPS_LIST. 499*404b540aSrobert Otherwise, generate usual INSN_LIST links. */ 500*404b540aSrobert USE_DEPS_LIST = 1, 501*404b540aSrobert /* Perform data or control (or both) speculation. 502*404b540aSrobert Results in generation of data and control speculative dependencies. 503*404b540aSrobert Requires USE_DEPS_LIST set. */ 504*404b540aSrobert DO_SPECULATION = USE_DEPS_LIST << 1, 505*404b540aSrobert SCHED_RGN = DO_SPECULATION << 1, 506*404b540aSrobert SCHED_EBB = SCHED_RGN << 1, 507*404b540aSrobert /* Detach register live information from basic block headers. 508*404b540aSrobert This is necessary to invoke functions, that change CFG (e.g. split_edge). 509*404b540aSrobert Requires USE_GLAT. */ 510*404b540aSrobert DETACH_LIFE_INFO = SCHED_EBB << 1, 511*404b540aSrobert /* Save register live information from basic block headers to 512*404b540aSrobert glat_{start, end} arrays. */ 513*404b540aSrobert USE_GLAT = DETACH_LIFE_INFO << 1 514*404b540aSrobert }; 515*404b540aSrobert 516*404b540aSrobert enum SPEC_SCHED_FLAGS { 517*404b540aSrobert COUNT_SPEC_IN_CRITICAL_PATH = 1, 518*404b540aSrobert PREFER_NON_DATA_SPEC = COUNT_SPEC_IN_CRITICAL_PATH << 1, 519*404b540aSrobert PREFER_NON_CONTROL_SPEC = PREFER_NON_DATA_SPEC << 1 520*404b540aSrobert }; 521*404b540aSrobert 522*404b540aSrobert #define NOTE_NOT_BB_P(NOTE) (NOTE_P (NOTE) && (NOTE_LINE_NUMBER (NOTE) \ 523*404b540aSrobert != NOTE_INSN_BASIC_BLOCK)) 524*404b540aSrobert 525*404b540aSrobert extern FILE *sched_dump; 526*404b540aSrobert extern int sched_verbose; 527*404b540aSrobert 528*404b540aSrobert /* Exception Free Loads: 529*404b540aSrobert 530*404b540aSrobert We define five classes of speculative loads: IFREE, IRISKY, 531*404b540aSrobert PFREE, PRISKY, and MFREE. 532*404b540aSrobert 533*404b540aSrobert IFREE loads are loads that are proved to be exception-free, just 534*404b540aSrobert by examining the load insn. Examples for such loads are loads 535*404b540aSrobert from TOC and loads of global data. 536*404b540aSrobert 537*404b540aSrobert IRISKY loads are loads that are proved to be exception-risky, 538*404b540aSrobert just by examining the load insn. Examples for such loads are 539*404b540aSrobert volatile loads and loads from shared memory. 540*404b540aSrobert 541*404b540aSrobert PFREE loads are loads for which we can prove, by examining other 542*404b540aSrobert insns, that they are exception-free. Currently, this class consists 543*404b540aSrobert of loads for which we are able to find a "similar load", either in 544*404b540aSrobert the target block, or, if only one split-block exists, in that split 545*404b540aSrobert block. Load2 is similar to load1 if both have same single base 546*404b540aSrobert register. We identify only part of the similar loads, by finding 547*404b540aSrobert an insn upon which both load1 and load2 have a DEF-USE dependence. 548*404b540aSrobert 549*404b540aSrobert PRISKY loads are loads for which we can prove, by examining other 550*404b540aSrobert insns, that they are exception-risky. Currently we have two proofs for 551*404b540aSrobert such loads. The first proof detects loads that are probably guarded by a 552*404b540aSrobert test on the memory address. This proof is based on the 553*404b540aSrobert backward and forward data dependence information for the region. 554*404b540aSrobert Let load-insn be the examined load. 555*404b540aSrobert Load-insn is PRISKY iff ALL the following hold: 556*404b540aSrobert 557*404b540aSrobert - insn1 is not in the same block as load-insn 558*404b540aSrobert - there is a DEF-USE dependence chain (insn1, ..., load-insn) 559*404b540aSrobert - test-insn is either a compare or a branch, not in the same block 560*404b540aSrobert as load-insn 561*404b540aSrobert - load-insn is reachable from test-insn 562*404b540aSrobert - there is a DEF-USE dependence chain (insn1, ..., test-insn) 563*404b540aSrobert 564*404b540aSrobert This proof might fail when the compare and the load are fed 565*404b540aSrobert by an insn not in the region. To solve this, we will add to this 566*404b540aSrobert group all loads that have no input DEF-USE dependence. 567*404b540aSrobert 568*404b540aSrobert The second proof detects loads that are directly or indirectly 569*404b540aSrobert fed by a speculative load. This proof is affected by the 570*404b540aSrobert scheduling process. We will use the flag fed_by_spec_load. 571*404b540aSrobert Initially, all insns have this flag reset. After a speculative 572*404b540aSrobert motion of an insn, if insn is either a load, or marked as 573*404b540aSrobert fed_by_spec_load, we will also mark as fed_by_spec_load every 574*404b540aSrobert insn1 for which a DEF-USE dependence (insn, insn1) exists. A 575*404b540aSrobert load which is fed_by_spec_load is also PRISKY. 576*404b540aSrobert 577*404b540aSrobert MFREE (maybe-free) loads are all the remaining loads. They may be 578*404b540aSrobert exception-free, but we cannot prove it. 579*404b540aSrobert 580*404b540aSrobert Now, all loads in IFREE and PFREE classes are considered 581*404b540aSrobert exception-free, while all loads in IRISKY and PRISKY classes are 582*404b540aSrobert considered exception-risky. As for loads in the MFREE class, 583*404b540aSrobert these are considered either exception-free or exception-risky, 584*404b540aSrobert depending on whether we are pessimistic or optimistic. We have 585*404b540aSrobert to take the pessimistic approach to assure the safety of 586*404b540aSrobert speculative scheduling, but we can take the optimistic approach 587*404b540aSrobert by invoking the -fsched_spec_load_dangerous option. */ 588*404b540aSrobert 589*404b540aSrobert enum INSN_TRAP_CLASS 590*404b540aSrobert { 591*404b540aSrobert TRAP_FREE = 0, IFREE = 1, PFREE_CANDIDATE = 2, 592*404b540aSrobert PRISKY_CANDIDATE = 3, IRISKY = 4, TRAP_RISKY = 5 593*404b540aSrobert }; 594*404b540aSrobert 595*404b540aSrobert #define WORST_CLASS(class1, class2) \ 596*404b540aSrobert ((class1 > class2) ? class1 : class2) 597*404b540aSrobert 598*404b540aSrobert #ifndef __GNUC__ 599*404b540aSrobert #define __inline 600*404b540aSrobert #endif 601*404b540aSrobert 602*404b540aSrobert #ifndef HAIFA_INLINE 603*404b540aSrobert #define HAIFA_INLINE __inline 604*404b540aSrobert #endif 605*404b540aSrobert 606*404b540aSrobert /* Functions in sched-vis.c. */ 607*404b540aSrobert extern void print_insn (char *, rtx, int); 608*404b540aSrobert 609*404b540aSrobert /* Functions in sched-deps.c. */ 610*404b540aSrobert extern bool sched_insns_conditions_mutex_p (rtx, rtx); 611*404b540aSrobert extern void add_dependence (rtx, rtx, enum reg_note); 612*404b540aSrobert extern void sched_analyze (struct deps *, rtx, rtx); 613*404b540aSrobert extern void init_deps (struct deps *); 614*404b540aSrobert extern void free_deps (struct deps *); 615*404b540aSrobert extern void init_deps_global (void); 616*404b540aSrobert extern void finish_deps_global (void); 617*404b540aSrobert extern void add_forw_dep (rtx, rtx); 618*404b540aSrobert extern void compute_forward_dependences (rtx, rtx); 619*404b540aSrobert extern rtx find_insn_list (rtx, rtx); 620*404b540aSrobert extern void init_dependency_caches (int); 621*404b540aSrobert extern void free_dependency_caches (void); 622*404b540aSrobert extern void extend_dependency_caches (int, bool); 623*404b540aSrobert extern enum DEPS_ADJUST_RESULT add_or_update_back_dep (rtx, rtx, 624*404b540aSrobert enum reg_note, ds_t); 625*404b540aSrobert extern void add_or_update_back_forw_dep (rtx, rtx, enum reg_note, ds_t); 626*404b540aSrobert extern void add_back_forw_dep (rtx, rtx, enum reg_note, ds_t); 627*404b540aSrobert extern void delete_back_forw_dep (rtx, rtx); 628*404b540aSrobert extern dw_t get_dep_weak (ds_t, ds_t); 629*404b540aSrobert extern ds_t set_dep_weak (ds_t, ds_t, dw_t); 630*404b540aSrobert extern ds_t ds_merge (ds_t, ds_t); 631*404b540aSrobert 632*404b540aSrobert /* Functions in haifa-sched.c. */ 633*404b540aSrobert extern int haifa_classify_insn (rtx); 634*404b540aSrobert extern void get_ebb_head_tail (basic_block, basic_block, rtx *, rtx *); 635*404b540aSrobert extern int no_real_insns_p (rtx, rtx); 636*404b540aSrobert 637*404b540aSrobert extern void rm_line_notes (rtx, rtx); 638*404b540aSrobert extern void save_line_notes (int, rtx, rtx); 639*404b540aSrobert extern void restore_line_notes (rtx, rtx); 640*404b540aSrobert extern void rm_redundant_line_notes (void); 641*404b540aSrobert extern void rm_other_notes (rtx, rtx); 642*404b540aSrobert 643*404b540aSrobert extern int insn_cost (rtx, rtx, rtx); 644*404b540aSrobert extern int set_priorities (rtx, rtx); 645*404b540aSrobert 646*404b540aSrobert extern void schedule_block (basic_block *, int); 647*404b540aSrobert extern void sched_init (void); 648*404b540aSrobert extern void sched_finish (void); 649*404b540aSrobert 650*404b540aSrobert extern int try_ready (rtx); 651*404b540aSrobert extern void * xrecalloc (void *, size_t, size_t, size_t); 652*404b540aSrobert extern void unlink_bb_notes (basic_block, basic_block); 653*404b540aSrobert extern void add_block (basic_block, basic_block); 654*404b540aSrobert extern void attach_life_info (void); 655*404b540aSrobert extern rtx bb_note (basic_block); 656*404b540aSrobert 657*404b540aSrobert #ifdef ENABLE_CHECKING 658*404b540aSrobert extern void check_reg_live (bool); 659*404b540aSrobert #endif 660*404b540aSrobert 661*404b540aSrobert #endif /* GCC_SCHED_INT_H */ 662