1 /* Compute register class preferences for pseudo-registers.
2 Copyright (C) 1987, 88, 91, 92, 93, 94, 96, 1997 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
22 /* This file contains two passes of the compiler: reg_scan and reg_class.
23 It also defines some tables of information about the hardware registers
24 and a function init_reg_sets to initialize the tables. */
28 #include "hard-reg-set.h"
30 #include "basic-block.h"
32 #include "insn-config.h"
38 #ifndef REGISTER_MOVE_COST
39 #define REGISTER_MOVE_COST(x, y) 2
42 #ifndef MEMORY_MOVE_COST
43 #define MEMORY_MOVE_COST(x) 4
46 /* If we have auto-increment or auto-decrement and we can have secondary
47 reloads, we are not allowed to use classes requiring secondary
48 reloads for pseudos auto-incremented since reload can't handle it. */
51 #if defined(SECONDARY_INPUT_RELOAD_CLASS) || defined(SECONDARY_OUTPUT_RELOAD_CLASS)
52 #define FORBIDDEN_INC_DEC_CLASSES
56 /* Register tables used by many passes. */
58 /* Indexed by hard register number, contains 1 for registers
59 that are fixed use (stack pointer, pc, frame pointer, etc.).
60 These are the registers that cannot be used to allocate
61 a pseudo reg whose life does not cross calls. */
63 char fixed_regs
[FIRST_PSEUDO_REGISTER
];
65 /* Same info as a HARD_REG_SET. */
67 HARD_REG_SET fixed_reg_set
;
69 /* Data for initializing the above. */
71 static char initial_fixed_regs
[] = FIXED_REGISTERS
;
73 /* Indexed by hard register number, contains 1 for registers
74 that are fixed use or are clobbered by function calls.
75 These are the registers that cannot be used to allocate
76 a pseudo reg whose life crosses calls. */
78 char call_used_regs
[FIRST_PSEUDO_REGISTER
];
80 /* Same info as a HARD_REG_SET. */
82 HARD_REG_SET call_used_reg_set
;
84 /* HARD_REG_SET of registers we want to avoid caller saving. */
85 HARD_REG_SET losing_caller_save_reg_set
;
87 /* Data for initializing the above. */
89 static char initial_call_used_regs
[] = CALL_USED_REGISTERS
;
91 /* Indexed by hard register number, contains 1 for registers that are
92 fixed use -- i.e. in fixed_regs -- or a function value return register
93 or STRUCT_VALUE_REGNUM or STATIC_CHAIN_REGNUM. These are the
94 registers that cannot hold quantities across calls even if we are
95 willing to save and restore them. */
97 char call_fixed_regs
[FIRST_PSEUDO_REGISTER
];
99 /* The same info as a HARD_REG_SET. */
101 HARD_REG_SET call_fixed_reg_set
;
103 /* Number of non-fixed registers. */
105 int n_non_fixed_regs
;
107 /* Indexed by hard register number, contains 1 for registers
108 that are being used for global register decls.
109 These must be exempt from ordinary flow analysis
110 and are also considered fixed. */
112 char global_regs
[FIRST_PSEUDO_REGISTER
];
114 /* Table of register numbers in the order in which to try to use them. */
115 #ifdef REG_ALLOC_ORDER
116 int reg_alloc_order
[FIRST_PSEUDO_REGISTER
] = REG_ALLOC_ORDER
;
119 /* For each reg class, a HARD_REG_SET saying which registers are in it. */
121 HARD_REG_SET reg_class_contents
[N_REG_CLASSES
];
123 /* The same information, but as an array of unsigned ints. We copy from
124 these unsigned ints to the table above. We do this so the tm.h files
125 do not have to be aware of the wordsize for machines with <= 64 regs. */
128 ((FIRST_PSEUDO_REGISTER + (HOST_BITS_PER_INT - 1)) / HOST_BITS_PER_INT)
130 static unsigned int_reg_class_contents
[N_REG_CLASSES
][N_REG_INTS
]
131 = REG_CLASS_CONTENTS
;
133 /* For each reg class, number of regs it contains. */
135 int reg_class_size
[N_REG_CLASSES
];
137 /* For each reg class, table listing all the containing classes. */
139 enum reg_class reg_class_superclasses
[N_REG_CLASSES
][N_REG_CLASSES
];
141 /* For each reg class, table listing all the classes contained in it. */
143 enum reg_class reg_class_subclasses
[N_REG_CLASSES
][N_REG_CLASSES
];
145 /* For each pair of reg classes,
146 a largest reg class contained in their union. */
148 enum reg_class reg_class_subunion
[N_REG_CLASSES
][N_REG_CLASSES
];
150 /* For each pair of reg classes,
151 the smallest reg class containing their union. */
153 enum reg_class reg_class_superunion
[N_REG_CLASSES
][N_REG_CLASSES
];
155 /* Array containing all of the register names */
157 char *reg_names
[] = REGISTER_NAMES
;
159 /* For each hard register, the widest mode object that it can contain.
160 This will be a MODE_INT mode if the register can hold integers. Otherwise
161 it will be a MODE_FLOAT or a MODE_CC mode, whichever is valid for the
164 enum machine_mode reg_raw_mode
[FIRST_PSEUDO_REGISTER
];
166 /* Maximum cost of moving from a register in one class to a register in
167 another class. Based on REGISTER_MOVE_COST. */
169 static int move_cost
[N_REG_CLASSES
][N_REG_CLASSES
];
171 /* Similar, but here we don't have to move if the first index is a subset
172 of the second so in that case the cost is zero. */
174 static int may_move_cost
[N_REG_CLASSES
][N_REG_CLASSES
];
176 #ifdef FORBIDDEN_INC_DEC_CLASSES
178 /* These are the classes that regs which are auto-incremented or decremented
181 static int forbidden_inc_dec_class
[N_REG_CLASSES
];
183 /* Indexed by n, is non-zero if (REG n) is used in an auto-inc or auto-dec
186 static char *in_inc_dec
;
188 #endif /* FORBIDDEN_INC_DEC_CLASSES */
190 /* Function called only once to initialize the above data on reg usage.
191 Once this is done, various switches may override. */
198 /* First copy the register information from the initial int form into
201 for (i
= 0; i
< N_REG_CLASSES
; i
++)
203 CLEAR_HARD_REG_SET (reg_class_contents
[i
]);
205 for (j
= 0; j
< FIRST_PSEUDO_REGISTER
; j
++)
206 if (int_reg_class_contents
[i
][j
/ HOST_BITS_PER_INT
]
207 & ((unsigned) 1 << (j
% HOST_BITS_PER_INT
)))
208 SET_HARD_REG_BIT (reg_class_contents
[i
], j
);
211 bcopy (initial_fixed_regs
, fixed_regs
, sizeof fixed_regs
);
212 bcopy (initial_call_used_regs
, call_used_regs
, sizeof call_used_regs
);
213 bzero (global_regs
, sizeof global_regs
);
215 /* Compute number of hard regs in each class. */
217 bzero ((char *) reg_class_size
, sizeof reg_class_size
);
218 for (i
= 0; i
< N_REG_CLASSES
; i
++)
219 for (j
= 0; j
< FIRST_PSEUDO_REGISTER
; j
++)
220 if (TEST_HARD_REG_BIT (reg_class_contents
[i
], j
))
223 /* Initialize the table of subunions.
224 reg_class_subunion[I][J] gets the largest-numbered reg-class
225 that is contained in the union of classes I and J. */
227 for (i
= 0; i
< N_REG_CLASSES
; i
++)
229 for (j
= 0; j
< N_REG_CLASSES
; j
++)
232 register /* Declare it register if it's a scalar. */
237 COPY_HARD_REG_SET (c
, reg_class_contents
[i
]);
238 IOR_HARD_REG_SET (c
, reg_class_contents
[j
]);
239 for (k
= 0; k
< N_REG_CLASSES
; k
++)
241 GO_IF_HARD_REG_SUBSET (reg_class_contents
[k
], c
,
246 /* keep the largest subclass */ /* SPEE 900308 */
247 GO_IF_HARD_REG_SUBSET (reg_class_contents
[k
],
248 reg_class_contents
[(int) reg_class_subunion
[i
][j
]],
250 reg_class_subunion
[i
][j
] = (enum reg_class
) k
;
257 /* Initialize the table of superunions.
258 reg_class_superunion[I][J] gets the smallest-numbered reg-class
259 containing the union of classes I and J. */
261 for (i
= 0; i
< N_REG_CLASSES
; i
++)
263 for (j
= 0; j
< N_REG_CLASSES
; j
++)
266 register /* Declare it register if it's a scalar. */
271 COPY_HARD_REG_SET (c
, reg_class_contents
[i
]);
272 IOR_HARD_REG_SET (c
, reg_class_contents
[j
]);
273 for (k
= 0; k
< N_REG_CLASSES
; k
++)
274 GO_IF_HARD_REG_SUBSET (c
, reg_class_contents
[k
], superclass
);
277 reg_class_superunion
[i
][j
] = (enum reg_class
) k
;
281 /* Initialize the tables of subclasses and superclasses of each reg class.
282 First clear the whole table, then add the elements as they are found. */
284 for (i
= 0; i
< N_REG_CLASSES
; i
++)
286 for (j
= 0; j
< N_REG_CLASSES
; j
++)
288 reg_class_superclasses
[i
][j
] = LIM_REG_CLASSES
;
289 reg_class_subclasses
[i
][j
] = LIM_REG_CLASSES
;
293 for (i
= 0; i
< N_REG_CLASSES
; i
++)
295 if (i
== (int) NO_REGS
)
298 for (j
= i
+ 1; j
< N_REG_CLASSES
; j
++)
302 GO_IF_HARD_REG_SUBSET (reg_class_contents
[i
], reg_class_contents
[j
],
306 /* Reg class I is a subclass of J.
307 Add J to the table of superclasses of I. */
308 p
= ®_class_superclasses
[i
][0];
309 while (*p
!= LIM_REG_CLASSES
) p
++;
310 *p
= (enum reg_class
) j
;
311 /* Add I to the table of superclasses of J. */
312 p
= ®_class_subclasses
[j
][0];
313 while (*p
!= LIM_REG_CLASSES
) p
++;
314 *p
= (enum reg_class
) i
;
318 /* Initialize the move cost table. Find every subset of each class
319 and take the maximum cost of moving any subset to any other. */
321 for (i
= 0; i
< N_REG_CLASSES
; i
++)
322 for (j
= 0; j
< N_REG_CLASSES
; j
++)
324 int cost
= i
== j
? 2 : REGISTER_MOVE_COST (i
, j
);
325 enum reg_class
*p1
, *p2
;
327 for (p2
= ®_class_subclasses
[j
][0]; *p2
!= LIM_REG_CLASSES
; p2
++)
329 cost
= MAX (cost
, REGISTER_MOVE_COST (i
, *p2
));
331 for (p1
= ®_class_subclasses
[i
][0]; *p1
!= LIM_REG_CLASSES
; p1
++)
334 cost
= MAX (cost
, REGISTER_MOVE_COST (*p1
, j
));
336 for (p2
= ®_class_subclasses
[j
][0];
337 *p2
!= LIM_REG_CLASSES
; p2
++)
339 cost
= MAX (cost
, REGISTER_MOVE_COST (*p1
, *p2
));
342 move_cost
[i
][j
] = cost
;
344 if (reg_class_subset_p (i
, j
))
347 may_move_cost
[i
][j
] = cost
;
351 /* After switches have been processed, which perhaps alter
352 `fixed_regs' and `call_used_regs', convert them to HARD_REG_SETs. */
359 /* This macro allows the fixed or call-used registers
360 to depend on target flags. */
362 #ifdef CONDITIONAL_REGISTER_USAGE
363 CONDITIONAL_REGISTER_USAGE
;
366 /* Initialize "constant" tables. */
368 CLEAR_HARD_REG_SET (fixed_reg_set
);
369 CLEAR_HARD_REG_SET (call_used_reg_set
);
370 CLEAR_HARD_REG_SET (call_fixed_reg_set
);
372 bcopy (fixed_regs
, call_fixed_regs
, sizeof call_fixed_regs
);
374 n_non_fixed_regs
= 0;
376 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
379 SET_HARD_REG_BIT (fixed_reg_set
, i
);
383 if (call_used_regs
[i
])
384 SET_HARD_REG_BIT (call_used_reg_set
, i
);
385 if (call_fixed_regs
[i
])
386 SET_HARD_REG_BIT (call_fixed_reg_set
, i
);
387 if (CLASS_LIKELY_SPILLED_P (REGNO_REG_CLASS (i
)))
388 SET_HARD_REG_BIT (losing_caller_save_reg_set
, i
);
392 /* Compute the table of register modes.
393 These values are used to record death information for individual registers
394 (as opposed to a multi-register mode). */
401 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
403 reg_raw_mode
[i
] = choose_hard_reg_mode (i
, 1);
405 /* If we couldn't find a valid mode, fall back to `word_mode'.
406 ??? We assume `word_mode' has already been initialized.
407 ??? One situation in which we need to do this is on the mips where
408 HARD_REGNO_NREGS (fpreg, [SD]Fmode) returns 2. Ideally we'd like
409 to use DF mode for the even registers and VOIDmode for the odd
410 (for the cpu models where the odd ones are inaccessible). */
411 if (reg_raw_mode
[i
] == VOIDmode
)
412 reg_raw_mode
[i
] = word_mode
;
416 /* Finish initializing the register sets and
417 initialize the register modes. */
422 /* This finishes what was started by init_reg_sets, but couldn't be done
423 until after register usage was specified. */
424 if (!output_bytecode
)
430 /* Return a machine mode that is legitimate for hard reg REGNO and large
431 enough to save nregs. If we can't find one, return VOIDmode. */
434 choose_hard_reg_mode (regno
, nregs
)
438 enum machine_mode found_mode
= VOIDmode
, mode
;
440 /* We first look for the largest integer mode that can be validly
441 held in REGNO. If none, we look for the largest floating-point mode.
442 If we still didn't find a valid mode, try CCmode. */
444 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
);
446 mode
= GET_MODE_WIDER_MODE (mode
))
447 if (HARD_REGNO_NREGS (regno
, mode
) == nregs
448 && HARD_REGNO_MODE_OK (regno
, mode
))
451 if (found_mode
!= VOIDmode
)
454 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_FLOAT
);
456 mode
= GET_MODE_WIDER_MODE (mode
))
457 if (HARD_REGNO_NREGS (regno
, mode
) == nregs
458 && HARD_REGNO_MODE_OK (regno
, mode
))
461 if (found_mode
!= VOIDmode
)
464 if (HARD_REGNO_NREGS (regno
, CCmode
) == nregs
465 && HARD_REGNO_MODE_OK (regno
, CCmode
))
468 /* We can't find a mode valid for this register. */
472 /* Specify the usage characteristics of the register named NAME.
473 It should be a fixed register if FIXED and a
474 call-used register if CALL_USED. */
477 fix_register (name
, fixed
, call_used
)
479 int fixed
, call_used
;
485 warning ("request to mark `%s' as %s ignored by bytecode compiler",
486 name
, call_used
? "call-used" : "fixed");
490 /* Decode the name and update the primary form of
491 the register info. */
493 if ((i
= decode_reg_name (name
)) >= 0)
495 fixed_regs
[i
] = fixed
;
496 call_used_regs
[i
] = call_used
;
500 warning ("unknown register name: %s", name
);
504 /* Mark register number I as global. */
512 warning ("register used for two global register variables");
516 if (call_used_regs
[i
] && ! fixed_regs
[i
])
517 warning ("call-clobbered register used for global register variable");
521 /* If already fixed, nothing else to do. */
525 fixed_regs
[i
] = call_used_regs
[i
] = call_fixed_regs
[i
] = 1;
528 SET_HARD_REG_BIT (fixed_reg_set
, i
);
529 SET_HARD_REG_BIT (call_used_reg_set
, i
);
530 SET_HARD_REG_BIT (call_fixed_reg_set
, i
);
533 /* Now the data and code for the `regclass' pass, which happens
534 just before local-alloc. */
536 /* The `costs' struct records the cost of using a hard register of each class
537 and of using memory for each pseudo. We use this data to set up
538 register class preferences. */
542 int cost
[N_REG_CLASSES
];
546 /* Record the cost of each class for each pseudo. */
548 static struct costs
*costs
;
550 /* Record the same data by operand number, accumulated for each alternative
551 in an insn. The contribution to a pseudo is that of the minimum-cost
554 static struct costs op_costs
[MAX_RECOG_OPERANDS
];
556 /* (enum reg_class) prefclass[R] is the preferred class for pseudo number R.
557 This is available after `regclass' is run. */
559 static char *prefclass
;
561 /* altclass[R] is a register class that we should use for allocating
562 pseudo number R if no register in the preferred class is available.
563 If no register in this class is available, memory is preferred.
565 It might appear to be more general to have a bitmask of classes here,
566 but since it is recommended that there be a class corresponding to the
567 union of most major pair of classes, that generality is not required.
569 This is available after `regclass' is run. */
571 static char *altclass
;
573 /* Record the depth of loops that we are in. */
575 static int loop_depth
;
577 /* Account for the fact that insns within a loop are executed very commonly,
578 but don't keep doing this as loops go too deep. */
580 static int loop_cost
;
582 static void record_reg_classes
PROTO((int, int, rtx
*, enum machine_mode
*,
584 static int copy_cost
PROTO((rtx
, enum machine_mode
,
585 enum reg_class
, int));
586 static void record_address_regs
PROTO((rtx
, enum reg_class
, int));
587 static auto_inc_dec_reg_p
PROTO((rtx
, enum machine_mode
));
588 static void reg_scan_mark_refs
PROTO((rtx
, rtx
, int));
590 /* Return the reg_class in which pseudo reg number REGNO is best allocated.
591 This function is sometimes called before the info has been computed.
592 When that happens, just return GENERAL_REGS, which is innocuous. */
595 reg_preferred_class (regno
)
600 return (enum reg_class
) prefclass
[regno
];
604 reg_alternate_class (regno
)
609 return (enum reg_class
) altclass
[regno
];
612 /* This prevents dump_flow_info from losing if called
613 before regclass is run. */
621 /* This is a pass of the compiler that scans all instructions
622 and calculates the preferred class for each pseudo-register.
623 This information can be accessed later by calling `reg_preferred_class'.
624 This pass comes just before local register allocation. */
631 #ifdef REGISTER_CONSTRAINTS
634 struct costs init_cost
;
640 costs
= (struct costs
*) alloca (nregs
* sizeof (struct costs
));
642 #ifdef FORBIDDEN_INC_DEC_CLASSES
644 in_inc_dec
= (char *) alloca (nregs
);
646 /* Initialize information about which register classes can be used for
647 pseudos that are auto-incremented or auto-decremented. It would
648 seem better to put this in init_reg_sets, but we need to be able
649 to allocate rtx, which we can't do that early. */
651 for (i
= 0; i
< N_REG_CLASSES
; i
++)
653 rtx r
= gen_rtx (REG
, VOIDmode
, 0);
656 for (j
= 0; j
< FIRST_PSEUDO_REGISTER
; j
++)
657 if (TEST_HARD_REG_BIT (reg_class_contents
[i
], j
))
661 for (m
= VOIDmode
; (int) m
< (int) MAX_MACHINE_MODE
;
662 m
= (enum machine_mode
) ((int) m
+ 1))
663 if (HARD_REGNO_MODE_OK (j
, m
))
667 /* If a register is not directly suitable for an
668 auto-increment or decrement addressing mode and
669 requires secondary reloads, disallow its class from
670 being used in such addresses. */
673 #ifdef SECONDARY_RELOAD_CLASS
674 || (SECONDARY_RELOAD_CLASS (BASE_REG_CLASS
, m
, r
)
677 #ifdef SECONDARY_INPUT_RELOAD_CLASS
678 || (SECONDARY_INPUT_RELOAD_CLASS (BASE_REG_CLASS
, m
, r
)
681 #ifdef SECONDARY_OUTPUT_RELOAD_CLASS
682 || (SECONDARY_OUTPUT_RELOAD_CLASS (BASE_REG_CLASS
, m
, r
)
687 && ! auto_inc_dec_reg_p (r
, m
))
688 forbidden_inc_dec_class
[i
] = 1;
692 #endif /* FORBIDDEN_INC_DEC_CLASSES */
694 init_cost
.mem_cost
= 10000;
695 for (i
= 0; i
< N_REG_CLASSES
; i
++)
696 init_cost
.cost
[i
] = 10000;
698 /* Normally we scan the insns once and determine the best class to use for
699 each register. However, if -fexpensive_optimizations are on, we do so
700 twice, the second time using the tentative best classes to guide the
703 for (pass
= 0; pass
<= flag_expensive_optimizations
; pass
++)
705 /* Zero out our accumulation of the cost of each class for each reg. */
707 bzero ((char *) costs
, nregs
* sizeof (struct costs
));
709 #ifdef FORBIDDEN_INC_DEC_CLASSES
710 bzero (in_inc_dec
, nregs
);
713 loop_depth
= 0, loop_cost
= 1;
715 /* Scan the instructions and record each time it would
716 save code to put a certain register in a certain class. */
718 for (insn
= f
; insn
; insn
= NEXT_INSN (insn
))
720 char *constraints
[MAX_RECOG_OPERANDS
];
721 enum machine_mode modes
[MAX_RECOG_OPERANDS
];
725 /* Show that an insn inside a loop is likely to be executed three
726 times more than insns outside a loop. This is much more aggressive
727 than the assumptions made elsewhere and is being tried as an
730 if (GET_CODE (insn
) == NOTE
731 && NOTE_LINE_NUMBER (insn
) == NOTE_INSN_LOOP_BEG
)
732 loop_depth
++, loop_cost
= 1 << (2 * MIN (loop_depth
, 5));
733 else if (GET_CODE (insn
) == NOTE
734 && NOTE_LINE_NUMBER (insn
) == NOTE_INSN_LOOP_END
)
735 loop_depth
--, loop_cost
= 1 << (2 * MIN (loop_depth
, 5));
737 else if ((GET_CODE (insn
) == INSN
738 && GET_CODE (PATTERN (insn
)) != USE
739 && GET_CODE (PATTERN (insn
)) != CLOBBER
740 && GET_CODE (PATTERN (insn
)) != ASM_INPUT
)
741 || (GET_CODE (insn
) == JUMP_INSN
742 && GET_CODE (PATTERN (insn
)) != ADDR_VEC
743 && GET_CODE (PATTERN (insn
)) != ADDR_DIFF_VEC
)
744 || GET_CODE (insn
) == CALL_INSN
)
746 if (GET_CODE (insn
) == INSN
747 && (noperands
= asm_noperands (PATTERN (insn
))) >= 0)
749 decode_asm_operands (PATTERN (insn
), recog_operand
, NULL_PTR
,
751 nalternatives
= (noperands
== 0 ? 0
752 : n_occurrences (',', constraints
[0]) + 1);
756 int insn_code_number
= recog_memoized (insn
);
759 set
= single_set (insn
);
762 nalternatives
= insn_n_alternatives
[insn_code_number
];
763 noperands
= insn_n_operands
[insn_code_number
];
765 /* If this insn loads a parameter from its stack slot, then
766 it represents a savings, rather than a cost, if the
767 parameter is stored in memory. Record this fact. */
769 if (set
!= 0 && GET_CODE (SET_DEST (set
)) == REG
770 && GET_CODE (SET_SRC (set
)) == MEM
771 && (note
= find_reg_note (insn
, REG_EQUIV
,
773 && GET_CODE (XEXP (note
, 0)) == MEM
)
775 costs
[REGNO (SET_DEST (set
))].mem_cost
776 -= (MEMORY_MOVE_COST (GET_MODE (SET_DEST (set
)))
778 record_address_regs (XEXP (SET_SRC (set
), 0),
779 BASE_REG_CLASS
, loop_cost
* 2);
783 /* Improve handling of two-address insns such as
784 (set X (ashift CONST Y)) where CONST must be made to
785 match X. Change it into two insns: (set X CONST)
786 (set X (ashift X Y)). If we left this for reloading, it
787 would probably get three insns because X and Y might go
788 in the same place. This prevents X and Y from receiving
791 We can only do this if the modes of operands 0 and 1
792 (which might not be the same) are tieable and we only need
793 do this during our first pass. */
795 if (pass
== 0 && optimize
797 && insn_operand_constraint
[insn_code_number
][1][0] == '0'
798 && insn_operand_constraint
[insn_code_number
][1][1] == 0
799 && CONSTANT_P (recog_operand
[1])
800 && ! rtx_equal_p (recog_operand
[0], recog_operand
[1])
801 && ! rtx_equal_p (recog_operand
[0], recog_operand
[2])
802 && GET_CODE (recog_operand
[0]) == REG
803 && MODES_TIEABLE_P (GET_MODE (recog_operand
[0]),
804 insn_operand_mode
[insn_code_number
][1]))
806 rtx previnsn
= prev_real_insn (insn
);
808 = gen_lowpart (insn_operand_mode
[insn_code_number
][1],
811 = emit_insn_before (gen_move_insn (dest
,
815 /* If this insn was the start of a basic block,
816 include the new insn in that block.
817 We need not check for code_label here;
818 while a basic block can start with a code_label,
819 INSN could not be at the beginning of that block. */
820 if (previnsn
== 0 || GET_CODE (previnsn
) == JUMP_INSN
)
823 for (b
= 0; b
< n_basic_blocks
; b
++)
824 if (insn
== basic_block_head
[b
])
825 basic_block_head
[b
] = newinsn
;
828 /* This makes one more setting of new insns's dest. */
829 REG_N_SETS (REGNO (recog_operand
[0]))++;
831 *recog_operand_loc
[1] = recog_operand
[0];
832 for (i
= insn_n_dups
[insn_code_number
] - 1; i
>= 0; i
--)
833 if (recog_dup_num
[i
] == 1)
834 *recog_dup_loc
[i
] = recog_operand
[0];
836 insn
= PREV_INSN (newinsn
);
840 for (i
= 0; i
< noperands
; i
++)
843 = insn_operand_constraint
[insn_code_number
][i
];
844 modes
[i
] = insn_operand_mode
[insn_code_number
][i
];
848 /* If we get here, we are set up to record the costs of all the
849 operands for this insn. Start by initializing the costs.
850 Then handle any address registers. Finally record the desired
851 classes for any pseudos, doing it twice if some pair of
852 operands are commutative. */
854 for (i
= 0; i
< noperands
; i
++)
856 op_costs
[i
] = init_cost
;
858 if (GET_CODE (recog_operand
[i
]) == SUBREG
)
859 recog_operand
[i
] = SUBREG_REG (recog_operand
[i
]);
861 if (GET_CODE (recog_operand
[i
]) == MEM
)
862 record_address_regs (XEXP (recog_operand
[i
], 0),
863 BASE_REG_CLASS
, loop_cost
* 2);
864 else if (constraints
[i
][0] == 'p')
865 record_address_regs (recog_operand
[i
],
866 BASE_REG_CLASS
, loop_cost
* 2);
869 /* Check for commutative in a separate loop so everything will
870 have been initialized. We must do this even if one operand
871 is a constant--see addsi3 in m68k.md. */
873 for (i
= 0; i
< noperands
- 1; i
++)
874 if (constraints
[i
][0] == '%')
876 char *xconstraints
[MAX_RECOG_OPERANDS
];
879 /* Handle commutative operands by swapping the constraints.
880 We assume the modes are the same. */
882 for (j
= 0; j
< noperands
; j
++)
883 xconstraints
[j
] = constraints
[j
];
885 xconstraints
[i
] = constraints
[i
+1];
886 xconstraints
[i
+1] = constraints
[i
];
887 record_reg_classes (nalternatives
, noperands
,
888 recog_operand
, modes
, xconstraints
,
892 record_reg_classes (nalternatives
, noperands
, recog_operand
,
893 modes
, constraints
, insn
);
895 /* Now add the cost for each operand to the total costs for
898 for (i
= 0; i
< noperands
; i
++)
899 if (GET_CODE (recog_operand
[i
]) == REG
900 && REGNO (recog_operand
[i
]) >= FIRST_PSEUDO_REGISTER
)
902 int regno
= REGNO (recog_operand
[i
]);
903 struct costs
*p
= &costs
[regno
], *q
= &op_costs
[i
];
905 p
->mem_cost
+= q
->mem_cost
* loop_cost
;
906 for (j
= 0; j
< N_REG_CLASSES
; j
++)
907 p
->cost
[j
] += q
->cost
[j
] * loop_cost
;
912 /* Now for each register look at how desirable each class is
913 and find which class is preferred. Store that in
914 `prefclass[REGNO]'. Record in `altclass[REGNO]' the largest register
915 class any of whose registers is better than memory. */
919 prefclass
= (char *) oballoc (nregs
);
920 altclass
= (char *) oballoc (nregs
);
923 for (i
= FIRST_PSEUDO_REGISTER
; i
< nregs
; i
++)
925 register int best_cost
= (1 << (HOST_BITS_PER_INT
- 2)) - 1;
926 enum reg_class best
= ALL_REGS
, alt
= NO_REGS
;
927 /* This is an enum reg_class, but we call it an int
928 to save lots of casts. */
930 register struct costs
*p
= &costs
[i
];
932 for (class = (int) ALL_REGS
- 1; class > 0; class--)
934 /* Ignore classes that are too small for this operand or
935 invalid for a operand that was auto-incremented. */
936 if (CLASS_MAX_NREGS (class, PSEUDO_REGNO_MODE (i
))
937 > reg_class_size
[class]
938 #ifdef FORBIDDEN_INC_DEC_CLASSES
939 || (in_inc_dec
[i
] && forbidden_inc_dec_class
[class])
943 else if (p
->cost
[class] < best_cost
)
945 best_cost
= p
->cost
[class];
946 best
= (enum reg_class
) class;
948 else if (p
->cost
[class] == best_cost
)
949 best
= reg_class_subunion
[(int)best
][class];
952 /* Record the alternate register class; i.e., a class for which
953 every register in it is better than using memory. If adding a
954 class would make a smaller class (i.e., no union of just those
955 classes exists), skip that class. The major unions of classes
956 should be provided as a register class. Don't do this if we
957 will be doing it again later. */
959 if (pass
== 1 || ! flag_expensive_optimizations
)
960 for (class = 0; class < N_REG_CLASSES
; class++)
961 if (p
->cost
[class] < p
->mem_cost
962 && (reg_class_size
[(int) reg_class_subunion
[(int) alt
][class]]
963 > reg_class_size
[(int) alt
])
964 #ifdef FORBIDDEN_INC_DEC_CLASSES
965 && ! (in_inc_dec
[i
] && forbidden_inc_dec_class
[class])
968 alt
= reg_class_subunion
[(int) alt
][class];
970 /* If we don't add any classes, nothing to try. */
974 /* We cast to (int) because (char) hits bugs in some compilers. */
975 prefclass
[i
] = (int) best
;
976 altclass
[i
] = (int) alt
;
979 #endif /* REGISTER_CONSTRAINTS */
982 #ifdef REGISTER_CONSTRAINTS
984 /* Record the cost of using memory or registers of various classes for
985 the operands in INSN.
987 N_ALTS is the number of alternatives.
989 N_OPS is the number of operands.
991 OPS is an array of the operands.
993 MODES are the modes of the operands, in case any are VOIDmode.
995 CONSTRAINTS are the constraints to use for the operands. This array
996 is modified by this procedure.
998 This procedure works alternative by alternative. For each alternative
999 we assume that we will be able to allocate all pseudos to their ideal
1000 register class and calculate the cost of using that alternative. Then
1001 we compute for each operand that is a pseudo-register, the cost of
1002 having the pseudo allocated to each register class and using it in that
1003 alternative. To this cost is added the cost of the alternative.
1005 The cost of each class for this insn is its lowest cost among all the
1009 record_reg_classes (n_alts
, n_ops
, ops
, modes
, constraints
, insn
)
1013 enum machine_mode
*modes
;
1018 enum op_type
{OP_READ
, OP_WRITE
, OP_READ_WRITE
} op_types
[MAX_RECOG_OPERANDS
];
1022 /* By default, each operand is an input operand. */
1024 for (i
= 0; i
< n_ops
; i
++)
1025 op_types
[i
] = OP_READ
;
1027 /* Process each alternative, each time minimizing an operand's cost with
1028 the cost for each operand in that alternative. */
1030 for (alt
= 0; alt
< n_alts
; alt
++)
1032 struct costs this_op_costs
[MAX_RECOG_OPERANDS
];
1035 enum reg_class classes
[MAX_RECOG_OPERANDS
];
1038 for (i
= 0; i
< n_ops
; i
++)
1040 char *p
= constraints
[i
];
1042 enum machine_mode mode
= modes
[i
];
1047 /* If this operand has no constraints at all, we can conclude
1048 nothing about it since anything is valid. */
1052 if (GET_CODE (op
) == REG
&& REGNO (op
) >= FIRST_PSEUDO_REGISTER
)
1053 bzero ((char *) &this_op_costs
[i
], sizeof this_op_costs
[i
]);
1061 /* If this alternative is only relevant when this operand
1062 matches a previous operand, we do different things depending
1063 on whether this operand is a pseudo-reg or not. */
1065 if (p
[0] >= '0' && p
[0] <= '0' + i
&& (p
[1] == ',' || p
[1] == 0))
1068 classes
[i
] = classes
[j
];
1070 if (GET_CODE (op
) != REG
|| REGNO (op
) < FIRST_PSEUDO_REGISTER
)
1072 /* If this matches the other operand, we have no added
1074 if (rtx_equal_p (ops
[j
], op
))
1077 /* If we can put the other operand into a register, add to
1078 the cost of this alternative the cost to copy this
1079 operand to the register used for the other operand. */
1081 else if (classes
[j
] != NO_REGS
)
1082 alt_cost
+= copy_cost (op
, mode
, classes
[j
], 1), win
= 1;
1084 else if (GET_CODE (ops
[j
]) != REG
1085 || REGNO (ops
[j
]) < FIRST_PSEUDO_REGISTER
)
1087 /* This op is a pseudo but the one it matches is not. */
1089 /* If we can't put the other operand into a register, this
1090 alternative can't be used. */
1092 if (classes
[j
] == NO_REGS
)
1095 /* Otherwise, add to the cost of this alternative the cost
1096 to copy the other operand to the register used for this
1100 alt_cost
+= copy_cost (ops
[j
], mode
, classes
[j
], 1);
1104 /* The costs of this operand are the same as that of the
1105 other operand. However, if we cannot tie them, this
1106 alternative needs to do a copy, which is one
1109 this_op_costs
[i
] = this_op_costs
[j
];
1110 if (REGNO (ops
[i
]) != REGNO (ops
[j
])
1111 && ! find_reg_note (insn
, REG_DEAD
, op
))
1114 /* This is in place of ordinary cost computation
1115 for this operand, so skip to the end of the
1116 alternative (should be just one character). */
1117 while (*p
&& *p
++ != ',')
1125 /* Scan all the constraint letters. See if the operand matches
1126 any of the constraints. Collect the valid register classes
1127 and see if this operand accepts memory. */
1129 classes
[i
] = NO_REGS
;
1130 while (*p
&& (c
= *p
++) != ',')
1134 op_types
[i
] = OP_WRITE
;
1138 op_types
[i
] = OP_READ_WRITE
;
1142 /* Ignore the next letter for this pass. */
1147 case '?': case '!': case '#':
1149 case '0': case '1': case '2': case '3': case '4':
1153 case 'm': case 'o': case 'V':
1154 /* It doesn't seem worth distinguishing between offsettable
1155 and non-offsettable addresses here. */
1157 if (GET_CODE (op
) == MEM
)
1162 if (GET_CODE (op
) == MEM
1163 && (GET_CODE (XEXP (op
, 0)) == PRE_DEC
1164 || GET_CODE (XEXP (op
, 0)) == POST_DEC
))
1169 if (GET_CODE (op
) == MEM
1170 && (GET_CODE (XEXP (op
, 0)) == PRE_INC
1171 || GET_CODE (XEXP (op
, 0)) == POST_INC
))
1176 #ifndef REAL_ARITHMETIC
1177 /* Match any floating double constant, but only if
1178 we can examine the bits of it reliably. */
1179 if ((HOST_FLOAT_FORMAT
!= TARGET_FLOAT_FORMAT
1180 || HOST_BITS_PER_WIDE_INT
!= BITS_PER_WORD
)
1181 && GET_MODE (op
) != VOIDmode
&& ! flag_pretend_float
)
1184 if (GET_CODE (op
) == CONST_DOUBLE
)
1189 if (GET_CODE (op
) == CONST_DOUBLE
)
1195 if (GET_CODE (op
) == CONST_DOUBLE
1196 && CONST_DOUBLE_OK_FOR_LETTER_P (op
, c
))
1201 if (GET_CODE (op
) == CONST_INT
1202 || (GET_CODE (op
) == CONST_DOUBLE
1203 && GET_MODE (op
) == VOIDmode
))
1207 #ifdef LEGITIMATE_PIC_OPERAND_P
1208 && (! flag_pic
|| LEGITIMATE_PIC_OPERAND_P (op
))
1215 if (GET_CODE (op
) == CONST_INT
1216 || (GET_CODE (op
) == CONST_DOUBLE
1217 && GET_MODE (op
) == VOIDmode
))
1229 if (GET_CODE (op
) == CONST_INT
1230 && CONST_OK_FOR_LETTER_P (INTVAL (op
), c
))
1238 #ifdef EXTRA_CONSTRAINT
1244 if (EXTRA_CONSTRAINT (op
, c
))
1250 if (GET_CODE (op
) == MEM
1252 #ifdef LEGITIMATE_PIC_OPERAND_P
1253 && (! flag_pic
|| LEGITIMATE_PIC_OPERAND_P (op
))
1260 = reg_class_subunion
[(int) classes
[i
]][(int) GENERAL_REGS
];
1265 = reg_class_subunion
[(int) classes
[i
]]
1266 [(int) REG_CLASS_FROM_LETTER (c
)];
1271 /* How we account for this operand now depends on whether it is a
1272 pseudo register or not. If it is, we first check if any
1273 register classes are valid. If not, we ignore this alternative,
1274 since we want to assume that all pseudos get allocated for
1275 register preferencing. If some register class is valid, compute
1276 the costs of moving the pseudo into that class. */
1278 if (GET_CODE (op
) == REG
&& REGNO (op
) >= FIRST_PSEUDO_REGISTER
)
1280 if (classes
[i
] == NO_REGS
)
1284 struct costs
*pp
= &this_op_costs
[i
];
1286 for (class = 0; class < N_REG_CLASSES
; class++)
1287 pp
->cost
[class] = may_move_cost
[class][(int) classes
[i
]];
1289 /* If the alternative actually allows memory, make things
1290 a bit cheaper since we won't need an extra insn to
1293 pp
->mem_cost
= MEMORY_MOVE_COST (mode
) - allows_mem
;
1295 /* If we have assigned a class to this register in our
1296 first pass, add a cost to this alternative corresponding
1297 to what we would add if this register were not in the
1298 appropriate class. */
1302 += may_move_cost
[prefclass
[REGNO (op
)]][(int) classes
[i
]];
1306 /* Otherwise, if this alternative wins, either because we
1307 have already determined that or if we have a hard register of
1308 the proper class, there is no cost for this alternative. */
1311 || (GET_CODE (op
) == REG
1312 && reg_fits_class_p (op
, classes
[i
], 0, GET_MODE (op
))))
1315 /* If registers are valid, the cost of this alternative includes
1316 copying the object to and/or from a register. */
1318 else if (classes
[i
] != NO_REGS
)
1320 if (op_types
[i
] != OP_WRITE
)
1321 alt_cost
+= copy_cost (op
, mode
, classes
[i
], 1);
1323 if (op_types
[i
] != OP_READ
)
1324 alt_cost
+= copy_cost (op
, mode
, classes
[i
], 0);
1327 /* The only other way this alternative can be used is if this is a
1328 constant that could be placed into memory. */
1330 else if (CONSTANT_P (op
) && allows_mem
)
1331 alt_cost
+= MEMORY_MOVE_COST (mode
);
1339 /* Finally, update the costs with the information we've calculated
1340 about this alternative. */
1342 for (i
= 0; i
< n_ops
; i
++)
1343 if (GET_CODE (ops
[i
]) == REG
1344 && REGNO (ops
[i
]) >= FIRST_PSEUDO_REGISTER
)
1346 struct costs
*pp
= &op_costs
[i
], *qq
= &this_op_costs
[i
];
1347 int scale
= 1 + (op_types
[i
] == OP_READ_WRITE
);
1349 pp
->mem_cost
= MIN (pp
->mem_cost
,
1350 (qq
->mem_cost
+ alt_cost
) * scale
);
1352 for (class = 0; class < N_REG_CLASSES
; class++)
1353 pp
->cost
[class] = MIN (pp
->cost
[class],
1354 (qq
->cost
[class] + alt_cost
) * scale
);
1358 /* If this insn is a single set copying operand 1 to operand 0
1359 and one is a pseudo with the other a hard reg that is in its
1360 own register class, set the cost of that register class to -1. */
1362 if ((set
= single_set (insn
)) != 0
1363 && ops
[0] == SET_DEST (set
) && ops
[1] == SET_SRC (set
)
1364 && GET_CODE (ops
[0]) == REG
&& GET_CODE (ops
[1]) == REG
)
1365 for (i
= 0; i
<= 1; i
++)
1366 if (REGNO (ops
[i
]) >= FIRST_PSEUDO_REGISTER
)
1368 int regno
= REGNO (ops
[!i
]);
1369 enum machine_mode mode
= GET_MODE (ops
[!i
]);
1373 if (regno
>= FIRST_PSEUDO_REGISTER
&& prefclass
!= 0
1374 && (reg_class_size
[prefclass
[regno
]]
1375 == CLASS_MAX_NREGS (prefclass
[regno
], mode
)))
1376 op_costs
[i
].cost
[prefclass
[regno
]] = -1;
1377 else if (regno
< FIRST_PSEUDO_REGISTER
)
1378 for (class = 0; class < N_REG_CLASSES
; class++)
1379 if (TEST_HARD_REG_BIT (reg_class_contents
[class], regno
)
1380 && reg_class_size
[class] == CLASS_MAX_NREGS (class, mode
))
1382 if (reg_class_size
[class] == 1)
1383 op_costs
[i
].cost
[class] = -1;
1386 for (nr
= 0; nr
< HARD_REGNO_NREGS(regno
, mode
); nr
++)
1388 if (!TEST_HARD_REG_BIT (reg_class_contents
[class], regno
+ nr
))
1392 if (nr
== HARD_REGNO_NREGS(regno
,mode
))
1393 op_costs
[i
].cost
[class] = -1;
1399 /* Compute the cost of loading X into (if TO_P is non-zero) or from (if
1400 TO_P is zero) a register of class CLASS in mode MODE.
1402 X must not be a pseudo. */
1405 copy_cost (x
, mode
, class, to_p
)
1407 enum machine_mode mode
;
1408 enum reg_class
class;
1411 enum reg_class secondary_class
= NO_REGS
;
1413 /* If X is a SCRATCH, there is actually nothing to move since we are
1414 assuming optimal allocation. */
1416 if (GET_CODE (x
) == SCRATCH
)
1419 /* Get the class we will actually use for a reload. */
1420 class = PREFERRED_RELOAD_CLASS (x
, class);
1422 #ifdef HAVE_SECONDARY_RELOADS
1423 /* If we need a secondary reload (we assume here that we are using
1424 the secondary reload as an intermediate, not a scratch register), the
1425 cost is that to load the input into the intermediate register, then
1426 to copy them. We use a special value of TO_P to avoid recursion. */
1428 #ifdef SECONDARY_INPUT_RELOAD_CLASS
1430 secondary_class
= SECONDARY_INPUT_RELOAD_CLASS (class, mode
, x
);
1433 #ifdef SECONDARY_OUTPUT_RELOAD_CLASS
1435 secondary_class
= SECONDARY_OUTPUT_RELOAD_CLASS (class, mode
, x
);
1438 if (secondary_class
!= NO_REGS
)
1439 return (move_cost
[(int) secondary_class
][(int) class]
1440 + copy_cost (x
, mode
, secondary_class
, 2));
1441 #endif /* HAVE_SECONDARY_RELOADS */
1443 /* For memory, use the memory move cost, for (hard) registers, use the
1444 cost to move between the register classes, and use 2 for everything
1445 else (constants). */
1447 if (GET_CODE (x
) == MEM
|| class == NO_REGS
)
1448 return MEMORY_MOVE_COST (mode
);
1450 else if (GET_CODE (x
) == REG
)
1451 return move_cost
[(int) REGNO_REG_CLASS (REGNO (x
))][(int) class];
1454 /* If this is a constant, we may eventually want to call rtx_cost here. */
1458 /* Record the pseudo registers we must reload into hard registers
1459 in a subexpression of a memory address, X.
1461 CLASS is the class that the register needs to be in and is either
1462 BASE_REG_CLASS or INDEX_REG_CLASS.
1464 SCALE is twice the amount to multiply the cost by (it is twice so we
1465 can represent half-cost adjustments). */
1468 record_address_regs (x
, class, scale
)
1470 enum reg_class
class;
1473 register enum rtx_code code
= GET_CODE (x
);
1486 /* When we have an address that is a sum,
1487 we must determine whether registers are "base" or "index" regs.
1488 If there is a sum of two registers, we must choose one to be
1489 the "base". Luckily, we can use the REGNO_POINTER_FLAG
1490 to make a good choice most of the time. We only need to do this
1491 on machines that can have two registers in an address and where
1492 the base and index register classes are different.
1494 ??? This code used to set REGNO_POINTER_FLAG in some cases, but
1495 that seems bogus since it should only be set when we are sure
1496 the register is being used as a pointer. */
1499 rtx arg0
= XEXP (x
, 0);
1500 rtx arg1
= XEXP (x
, 1);
1501 register enum rtx_code code0
= GET_CODE (arg0
);
1502 register enum rtx_code code1
= GET_CODE (arg1
);
1504 /* Look inside subregs. */
1505 if (code0
== SUBREG
)
1506 arg0
= SUBREG_REG (arg0
), code0
= GET_CODE (arg0
);
1507 if (code1
== SUBREG
)
1508 arg1
= SUBREG_REG (arg1
), code1
= GET_CODE (arg1
);
1510 /* If this machine only allows one register per address, it must
1511 be in the first operand. */
1513 if (MAX_REGS_PER_ADDRESS
== 1)
1514 record_address_regs (arg0
, class, scale
);
1516 /* If index and base registers are the same on this machine, just
1517 record registers in any non-constant operands. We assume here,
1518 as well as in the tests below, that all addresses are in
1521 else if (INDEX_REG_CLASS
== BASE_REG_CLASS
)
1523 record_address_regs (arg0
, class, scale
);
1524 if (! CONSTANT_P (arg1
))
1525 record_address_regs (arg1
, class, scale
);
1528 /* If the second operand is a constant integer, it doesn't change
1529 what class the first operand must be. */
1531 else if (code1
== CONST_INT
|| code1
== CONST_DOUBLE
)
1532 record_address_regs (arg0
, class, scale
);
1534 /* If the second operand is a symbolic constant, the first operand
1535 must be an index register. */
1537 else if (code1
== SYMBOL_REF
|| code1
== CONST
|| code1
== LABEL_REF
)
1538 record_address_regs (arg0
, INDEX_REG_CLASS
, scale
);
1540 /* If this the sum of two registers where the first is known to be a
1541 pointer, it must be a base register with the second an index. */
1543 else if (code0
== REG
&& code1
== REG
1544 && REGNO_POINTER_FLAG (REGNO (arg0
)))
1546 record_address_regs (arg0
, BASE_REG_CLASS
, scale
);
1547 record_address_regs (arg1
, INDEX_REG_CLASS
, scale
);
1550 /* If this is the sum of two registers and neither is known to
1551 be a pointer, count equal chances that each might be a base
1552 or index register. This case should be rare. */
1554 else if (code0
== REG
&& code1
== REG
1555 && ! REGNO_POINTER_FLAG (REGNO (arg0
))
1556 && ! REGNO_POINTER_FLAG (REGNO (arg1
)))
1558 record_address_regs (arg0
, BASE_REG_CLASS
, scale
/ 2);
1559 record_address_regs (arg0
, INDEX_REG_CLASS
, scale
/ 2);
1560 record_address_regs (arg1
, BASE_REG_CLASS
, scale
/ 2);
1561 record_address_regs (arg1
, INDEX_REG_CLASS
, scale
/ 2);
1564 /* In all other cases, the first operand is an index and the
1565 second is the base. */
1569 record_address_regs (arg0
, INDEX_REG_CLASS
, scale
);
1570 record_address_regs (arg1
, BASE_REG_CLASS
, scale
);
1579 /* Double the importance of a pseudo register that is incremented
1580 or decremented, since it would take two extra insns
1581 if it ends up in the wrong place. If the operand is a pseudo,
1582 show it is being used in an INC_DEC context. */
1584 #ifdef FORBIDDEN_INC_DEC_CLASSES
1585 if (GET_CODE (XEXP (x
, 0)) == REG
1586 && REGNO (XEXP (x
, 0)) >= FIRST_PSEUDO_REGISTER
)
1587 in_inc_dec
[REGNO (XEXP (x
, 0))] = 1;
1590 record_address_regs (XEXP (x
, 0), class, 2 * scale
);
1595 register struct costs
*pp
= &costs
[REGNO (x
)];
1598 pp
->mem_cost
+= (MEMORY_MOVE_COST (Pmode
) * scale
) / 2;
1600 for (i
= 0; i
< N_REG_CLASSES
; i
++)
1601 pp
->cost
[i
] += (may_move_cost
[i
][(int) class] * scale
) / 2;
1607 register char *fmt
= GET_RTX_FORMAT (code
);
1609 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1611 record_address_regs (XEXP (x
, i
), class, scale
);
1616 #ifdef FORBIDDEN_INC_DEC_CLASSES
1618 /* Return 1 if REG is valid as an auto-increment memory reference
1619 to an object of MODE. */
1622 auto_inc_dec_reg_p (reg
, mode
)
1624 enum machine_mode mode
;
1626 #ifdef HAVE_POST_INCREMENT
1627 if (memory_address_p (mode
, gen_rtx (POST_INC
, Pmode
, reg
)))
1631 #ifdef HAVE_POST_DECREMENT
1632 if (memory_address_p (mode
, gen_rtx (POST_DEC
, Pmode
, reg
)))
1636 #ifdef HAVE_PRE_INCREMENT
1637 if (memory_address_p (mode
, gen_rtx (PRE_INC
, Pmode
, reg
)))
1641 #ifdef HAVE_PRE_DECREMENT
1642 if (memory_address_p (mode
, gen_rtx (PRE_DEC
, Pmode
, reg
)))
1650 #endif /* REGISTER_CONSTRAINTS */
1652 /* Allocate enough space to hold NUM_REGS registers for the tables used for
1653 reg_scan and flow_analysis that are indexed by the register number. If
1654 NEW_P is non zero, initialize all of the registers, otherwise only
1655 initialize the new registers allocated. The same table is kept from
1656 function to function, only reallocating it when we need more room. If
1657 RENUMBER_P is non zero, allocate the reg_renumber array also. */
1660 allocate_reg_info (num_regs
, new_p
, renumber_p
)
1665 static int regno_allocated
= 0;
1666 static int regno_max
= 0;
1667 static short *renumber
= (short *)0;
1671 int min
= (new_p
) ? 0 : regno_max
;
1673 /* If this message come up, and you want to fix it, then all of the tables
1674 like reg_renumber, etc. that use short will have to be found and lengthed
1675 to int or HOST_WIDE_INT. */
1677 /* Free up all storage allocated */
1682 free ((char *)reg_n_info
);
1683 free ((char *)renumber
);
1684 reg_n_info
= (reg_info
*)0;
1685 renumber
= (short *)0;
1687 regno_allocated
= 0;
1692 if (num_regs
> regno_allocated
)
1694 regno_allocated
= num_regs
+ (num_regs
/ 20); /* add some slop space */
1695 size_info
= regno_allocated
* sizeof (reg_info
);
1696 size_renumber
= regno_allocated
* sizeof (short);
1700 reg_n_info
= (reg_info
*) xmalloc (size_info
);
1701 renumber
= (short *) xmalloc (size_renumber
);
1704 else if (new_p
) /* if we're zapping everything, no need to realloc */
1706 free ((char *)reg_n_info
);
1707 free ((char *)renumber
);
1708 reg_n_info
= (reg_info
*) xmalloc (size_info
);
1709 renumber
= (short *) xmalloc (size_renumber
);
1714 reg_n_info
= (reg_info
*) xrealloc ((char *)reg_n_info
, size_info
);
1715 renumber
= (short *) xrealloc ((char *)renumber
, size_renumber
);
1721 bzero ((char *) ®_n_info
[min
], (num_regs
- min
) * sizeof (reg_info
));
1722 for (i
= min
; i
< num_regs
; i
++)
1724 REG_BASIC_BLOCK (i
) = REG_BLOCK_UNKNOWN
;
1730 reg_renumber
= renumber
;
1732 regno_max
= num_regs
;
1736 /* This is the `regscan' pass of the compiler, run just before cse
1737 and again just before loop.
1739 It finds the first and last use of each pseudo-register
1740 and records them in the vectors regno_first_uid, regno_last_uid
1741 and counts the number of sets in the vector reg_n_sets.
1743 REPEAT is nonzero the second time this is called. */
1745 /* Maximum number of parallel sets and clobbers in any insn in this fn.
1746 Always at least 3, since the combiner could put that many together
1747 and we want this to remain correct for all the remaining passes. */
1752 reg_scan (f
, nregs
, repeat
)
1759 allocate_reg_info (nregs
, TRUE
, FALSE
);
1762 for (insn
= f
; insn
; insn
= NEXT_INSN (insn
))
1763 if (GET_CODE (insn
) == INSN
1764 || GET_CODE (insn
) == CALL_INSN
1765 || GET_CODE (insn
) == JUMP_INSN
)
1767 if (GET_CODE (PATTERN (insn
)) == PARALLEL
1768 && XVECLEN (PATTERN (insn
), 0) > max_parallel
)
1769 max_parallel
= XVECLEN (PATTERN (insn
), 0);
1770 reg_scan_mark_refs (PATTERN (insn
), insn
, 0);
1772 if (REG_NOTES (insn
))
1773 reg_scan_mark_refs (REG_NOTES (insn
), insn
, 1);
1777 /* X is the expression to scan. INSN is the insn it appears in.
1778 NOTE_FLAG is nonzero if X is from INSN's notes rather than its body. */
1781 reg_scan_mark_refs (x
, insn
, note_flag
)
1786 register enum rtx_code code
= GET_CODE (x
);
1805 register int regno
= REGNO (x
);
1807 REGNO_LAST_NOTE_UID (regno
) = INSN_UID (insn
);
1809 REGNO_LAST_UID (regno
) = INSN_UID (insn
);
1810 if (REGNO_FIRST_UID (regno
) == 0)
1811 REGNO_FIRST_UID (regno
) = INSN_UID (insn
);
1817 reg_scan_mark_refs (XEXP (x
, 0), insn
, note_flag
);
1819 reg_scan_mark_refs (XEXP (x
, 1), insn
, note_flag
);
1824 reg_scan_mark_refs (XEXP (x
, 1), insn
, note_flag
);
1828 /* Count a set of the destination if it is a register. */
1829 for (dest
= SET_DEST (x
);
1830 GET_CODE (dest
) == SUBREG
|| GET_CODE (dest
) == STRICT_LOW_PART
1831 || GET_CODE (dest
) == ZERO_EXTEND
;
1832 dest
= XEXP (dest
, 0))
1835 if (GET_CODE (dest
) == REG
)
1836 REG_N_SETS (REGNO (dest
))++;
1838 /* If this is setting a pseudo from another pseudo or the sum of a
1839 pseudo and a constant integer and the other pseudo is known to be
1840 a pointer, set the destination to be a pointer as well.
1842 Likewise if it is setting the destination from an address or from a
1843 value equivalent to an address or to the sum of an address and
1846 But don't do any of this if the pseudo corresponds to a user
1847 variable since it should have already been set as a pointer based
1850 if (GET_CODE (SET_DEST (x
)) == REG
1851 && REGNO (SET_DEST (x
)) >= FIRST_PSEUDO_REGISTER
1852 && ! REG_USERVAR_P (SET_DEST (x
))
1853 && ! REGNO_POINTER_FLAG (REGNO (SET_DEST (x
)))
1854 && ((GET_CODE (SET_SRC (x
)) == REG
1855 && REGNO_POINTER_FLAG (REGNO (SET_SRC (x
))))
1856 || ((GET_CODE (SET_SRC (x
)) == PLUS
1857 || GET_CODE (SET_SRC (x
)) == LO_SUM
)
1858 && GET_CODE (XEXP (SET_SRC (x
), 1)) == CONST_INT
1859 && GET_CODE (XEXP (SET_SRC (x
), 0)) == REG
1860 && REGNO_POINTER_FLAG (REGNO (XEXP (SET_SRC (x
), 0))))
1861 || GET_CODE (SET_SRC (x
)) == CONST
1862 || GET_CODE (SET_SRC (x
)) == SYMBOL_REF
1863 || GET_CODE (SET_SRC (x
)) == LABEL_REF
1864 || (GET_CODE (SET_SRC (x
)) == HIGH
1865 && (GET_CODE (XEXP (SET_SRC (x
), 0)) == CONST
1866 || GET_CODE (XEXP (SET_SRC (x
), 0)) == SYMBOL_REF
1867 || GET_CODE (XEXP (SET_SRC (x
), 0)) == LABEL_REF
))
1868 || ((GET_CODE (SET_SRC (x
)) == PLUS
1869 || GET_CODE (SET_SRC (x
)) == LO_SUM
)
1870 && (GET_CODE (XEXP (SET_SRC (x
), 1)) == CONST
1871 || GET_CODE (XEXP (SET_SRC (x
), 1)) == SYMBOL_REF
1872 || GET_CODE (XEXP (SET_SRC (x
), 1)) == LABEL_REF
))
1873 || ((note
= find_reg_note (insn
, REG_EQUAL
, 0)) != 0
1874 && (GET_CODE (XEXP (note
, 0)) == CONST
1875 || GET_CODE (XEXP (note
, 0)) == SYMBOL_REF
1876 || GET_CODE (XEXP (note
, 0)) == LABEL_REF
))))
1877 REGNO_POINTER_FLAG (REGNO (SET_DEST (x
))) = 1;
1879 /* ... fall through ... */
1883 register char *fmt
= GET_RTX_FORMAT (code
);
1885 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1888 reg_scan_mark_refs (XEXP (x
, i
), insn
, note_flag
);
1889 else if (fmt
[i
] == 'E' && XVEC (x
, i
) != 0)
1892 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
1893 reg_scan_mark_refs (XVECEXP (x
, i
, j
), insn
, note_flag
);
1900 /* Return nonzero if C1 is a subset of C2, i.e., if every register in C1
1904 reg_class_subset_p (c1
, c2
)
1905 register enum reg_class c1
;
1906 register enum reg_class c2
;
1908 if (c1
== c2
) return 1;
1913 GO_IF_HARD_REG_SUBSET (reg_class_contents
[(int)c1
],
1914 reg_class_contents
[(int)c2
],
1919 /* Return nonzero if there is a register that is in both C1 and C2. */
1922 reg_classes_intersect_p (c1
, c2
)
1923 register enum reg_class c1
;
1924 register enum reg_class c2
;
1931 if (c1
== c2
) return 1;
1933 if (c1
== ALL_REGS
|| c2
== ALL_REGS
)
1936 COPY_HARD_REG_SET (c
, reg_class_contents
[(int) c1
]);
1937 AND_HARD_REG_SET (c
, reg_class_contents
[(int) c2
]);
1939 GO_IF_HARD_REG_SUBSET (c
, reg_class_contents
[(int) NO_REGS
], lose
);