1 /* Register to Stack convert for GNU compiler.
2 Copyright (C) 1992, 93-98, 1999 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. */
21 /* This pass converts stack-like registers from the "flat register
22 file" model that gcc uses, to a stack convention that the 387 uses.
24 * The form of the input:
26 On input, the function consists of insn that have had their
27 registers fully allocated to a set of "virtual" registers. Note that
28 the word "virtual" is used differently here than elsewhere in gcc: for
29 each virtual stack reg, there is a hard reg, but the mapping between
30 them is not known until this pass is run. On output, hard register
31 numbers have been substituted, and various pop and exchange insns have
32 been emitted. The hard register numbers and the virtual register
33 numbers completely overlap - before this pass, all stack register
34 numbers are virtual, and afterward they are all hard.
36 The virtual registers can be manipulated normally by gcc, and their
37 semantics are the same as for normal registers. After the hard
38 register numbers are substituted, the semantics of an insn containing
39 stack-like regs are not the same as for an insn with normal regs: for
40 instance, it is not safe to delete an insn that appears to be a no-op
41 move. In general, no insn containing hard regs should be changed
42 after this pass is done.
44 * The form of the output:
46 After this pass, hard register numbers represent the distance from
47 the current top of stack to the desired register. A reference to
48 FIRST_STACK_REG references the top of stack, FIRST_STACK_REG + 1,
49 represents the register just below that, and so forth. Also, REG_DEAD
50 notes indicate whether or not a stack register should be popped.
52 A "swap" insn looks like a parallel of two patterns, where each
53 pattern is a SET: one sets A to B, the other B to A.
55 A "push" or "load" insn is a SET whose SET_DEST is FIRST_STACK_REG
56 and whose SET_DEST is REG or MEM. Any other SET_DEST, such as PLUS,
57 will replace the existing stack top, not push a new value.
59 A store insn is a SET whose SET_DEST is FIRST_STACK_REG, and whose
60 SET_SRC is REG or MEM.
62 The case where the SET_SRC and SET_DEST are both FIRST_STACK_REG
63 appears ambiguous. As a special case, the presence of a REG_DEAD note
64 for FIRST_STACK_REG differentiates between a load insn and a pop.
66 If a REG_DEAD is present, the insn represents a "pop" that discards
67 the top of the register stack. If there is no REG_DEAD note, then the
68 insn represents a "dup" or a push of the current top of stack onto the
73 Existing REG_DEAD and REG_UNUSED notes for stack registers are
74 deleted and recreated from scratch. REG_DEAD is never created for a
75 SET_DEST, only REG_UNUSED.
79 There are several rules on the usage of stack-like regs in
80 asm_operands insns. These rules apply only to the operands that are
83 1. Given a set of input regs that die in an asm_operands, it is
84 necessary to know which are implicitly popped by the asm, and
85 which must be explicitly popped by gcc.
87 An input reg that is implicitly popped by the asm must be
88 explicitly clobbered, unless it is constrained to match an
91 2. For any input reg that is implicitly popped by an asm, it is
92 necessary to know how to adjust the stack to compensate for the pop.
93 If any non-popped input is closer to the top of the reg-stack than
94 the implicitly popped reg, it would not be possible to know what the
95 stack looked like - it's not clear how the rest of the stack "slides
98 All implicitly popped input regs must be closer to the top of
99 the reg-stack than any input that is not implicitly popped.
101 3. It is possible that if an input dies in an insn, reload might
102 use the input reg for an output reload. Consider this example:
104 asm ("foo" : "=t" (a) : "f" (b));
106 This asm says that input B is not popped by the asm, and that
107 the asm pushes a result onto the reg-stack, ie, the stack is one
108 deeper after the asm than it was before. But, it is possible that
109 reload will think that it can use the same reg for both the input and
110 the output, if input B dies in this insn.
112 If any input operand uses the "f" constraint, all output reg
113 constraints must use the "&" earlyclobber.
115 The asm above would be written as
117 asm ("foo" : "=&t" (a) : "f" (b));
119 4. Some operands need to be in particular places on the stack. All
120 output operands fall in this category - there is no other way to
121 know which regs the outputs appear in unless the user indicates
122 this in the constraints.
124 Output operands must specifically indicate which reg an output
125 appears in after an asm. "=f" is not allowed: the operand
126 constraints must select a class with a single reg.
128 5. Output operands may not be "inserted" between existing stack regs.
129 Since no 387 opcode uses a read/write operand, all output operands
130 are dead before the asm_operands, and are pushed by the asm_operands.
131 It makes no sense to push anywhere but the top of the reg-stack.
133 Output operands must start at the top of the reg-stack: output
134 operands may not "skip" a reg.
136 6. Some asm statements may need extra stack space for internal
137 calculations. This can be guaranteed by clobbering stack registers
138 unrelated to the inputs and outputs.
140 Here are a couple of reasonable asms to want to write. This asm
141 takes one input, which is internally popped, and produces two outputs.
143 asm ("fsincos" : "=t" (cos), "=u" (sin) : "0" (inp));
145 This asm takes two inputs, which are popped by the fyl2xp1 opcode,
146 and replaces them with one output. The user must code the "st(1)"
147 clobber for reg-stack.c to know that fyl2xp1 pops both inputs.
149 asm ("fyl2xp1" : "=t" (result) : "0" (x), "u" (y) : "st(1)");
158 #include "function.h"
159 #include "insn-config.h"
161 #include "hard-reg-set.h"
163 #include "insn-flags.h"
167 #include "basic-block.h"
172 #define REG_STACK_SIZE (LAST_STACK_REG - FIRST_STACK_REG + 1)
174 /* This is the basic stack record. TOP is an index into REG[] such
175 that REG[TOP] is the top of stack. If TOP is -1 the stack is empty.
177 If TOP is -2, REG[] is not yet initialized. Stack initialization
178 consists of placing each live reg in array `reg' and setting `top'
181 REG_SET indicates which registers are live. */
183 typedef struct stack_def
185 int top; /* index to top stack element */
186 HARD_REG_SET reg_set; /* set of live registers */
187 char reg[REG_STACK_SIZE]; /* register - stack mapping */
190 /* This is used to carry information about basic blocks. It is
191 attached to the AUX field of the standard CFG block. */
193 typedef struct block_info_def
195 struct stack_def stack_in; /* Input stack configuration. */
196 HARD_REG_SET out_reg_set; /* Stack regs live on output. */
197 int done; /* True if block already converted. */
200 #define BLOCK_INFO(B) ((block_info) (B)->aux)
202 /* Passed to change_stack to indicate where to emit insns. */
209 /* We use this array to cache info about insns, because otherwise we
210 spend too much time in stack_regs_mentioned_p.
212 Indexed by insn UIDs. A value of zero is uninitialized, one indicates
213 the insn uses stack registers, two indicates the insn does not use
215 static varray_type stack_regs_mentioned_data;
217 /* The block we're currently working on. */
218 static basic_block current_block;
220 /* This is the register file for all register after conversion */
222 FP_mode_reg[LAST_STACK_REG+1-FIRST_STACK_REG][(int) MAX_MACHINE_MODE];
224 #define FP_MODE_REG(regno,mode) \
225 (FP_mode_reg[(regno)-FIRST_STACK_REG][(int)(mode)])
227 /* Used to initialize uninitialized registers. */
230 /* Forward declarations */
232 static int stack_regs_mentioned_p PROTO((rtx pat));
233 static void straighten_stack PROTO((rtx, stack));
234 static void pop_stack PROTO((stack, int));
235 static rtx *get_true_reg PROTO((rtx *));
237 static int check_asm_stack_operands PROTO((rtx));
238 static int get_asm_operand_n_inputs PROTO((rtx));
239 static rtx stack_result PROTO((tree));
240 static void replace_reg PROTO((rtx *, int));
241 static void remove_regno_note PROTO((rtx, enum reg_note, int));
242 static int get_hard_regnum PROTO((stack, rtx));
243 static void delete_insn_for_stacker PROTO((rtx));
244 static rtx emit_pop_insn PROTO((rtx, stack, rtx,
246 static void emit_swap_insn PROTO((rtx, stack, rtx));
247 static void move_for_stack_reg PROTO((rtx, stack, rtx));
248 static int swap_rtx_condition_1 PROTO((rtx));
249 static int swap_rtx_condition PROTO((rtx));
250 static void compare_for_stack_reg PROTO((rtx, stack, rtx));
251 static void subst_stack_regs_pat PROTO((rtx, stack, rtx));
252 static void subst_asm_stack_regs PROTO((rtx, stack));
253 static void subst_stack_regs PROTO((rtx, stack));
254 static void change_stack PROTO((rtx, stack, stack,
256 static int convert_regs_entry PROTO((void));
257 static void convert_regs_exit PROTO((void));
258 static int convert_regs_1 PROTO((FILE *, basic_block));
259 static int convert_regs_2 PROTO((FILE *, basic_block));
260 static int convert_regs PROTO((FILE *));
261 static void print_stack PROTO((FILE *, stack));
263 /* Return non-zero if any stack register is mentioned somewhere within PAT. */
266 stack_regs_mentioned_p (pat)
269 register const char *fmt;
272 if (STACK_REG_P (pat))
275 fmt = GET_RTX_FORMAT (GET_CODE (pat));
276 for (i = GET_RTX_LENGTH (GET_CODE (pat)) - 1; i >= 0; i--)
282 for (j = XVECLEN (pat, i) - 1; j >= 0; j--)
283 if (stack_regs_mentioned_p (XVECEXP (pat, i, j)))
286 else if (fmt[i] == 'e' && stack_regs_mentioned_p (XEXP (pat, i)))
293 /* Return nonzero if INSN mentions stacked registers, else return zero. */
296 stack_regs_mentioned (insn)
299 unsigned int uid, max;
302 if (GET_RTX_CLASS (GET_CODE (insn)) != 'i')
305 uid = INSN_UID (insn);
306 max = VARRAY_SIZE (stack_regs_mentioned_data);
309 /* Allocate some extra size to avoid too many reallocs, but
310 do not grow too quickly. */
311 max = uid + uid / 20;
312 VARRAY_GROW (stack_regs_mentioned_data, max);
315 test = VARRAY_CHAR (stack_regs_mentioned_data, uid);
318 /* This insn has yet to be examined. Do so now. */
319 test = stack_regs_mentioned_p (PATTERN (insn)) ? 1 : 2;
320 VARRAY_CHAR (stack_regs_mentioned_data, uid) = test;
326 static rtx ix86_flags_rtx;
329 next_flags_user (insn)
332 /* Search forward looking for the first use of this value.
333 Stop at block boundaries. */
334 /* ??? This really cries for BLOCK_END! */
338 insn = NEXT_INSN (insn);
342 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i'
343 && reg_mentioned_p (ix86_flags_rtx, PATTERN (insn)))
346 if (GET_CODE (insn) == JUMP_INSN
347 || GET_CODE (insn) == CODE_LABEL
348 || GET_CODE (insn) == CALL_INSN)
353 /* Reorganise the stack into ascending numbers,
357 straighten_stack (insn, regstack)
361 struct stack_def temp_stack;
364 /* If there is only a single register on the stack, then the stack is
365 already in increasing order and no reorganization is needed.
367 Similarly if the stack is empty. */
368 if (regstack->top <= 0)
371 COPY_HARD_REG_SET (temp_stack.reg_set, regstack->reg_set);
373 for (top = temp_stack.top = regstack->top; top >= 0; top--)
374 temp_stack.reg[top] = FIRST_STACK_REG + temp_stack.top - top;
376 change_stack (insn, regstack, &temp_stack, EMIT_AFTER);
379 /* Pop a register from the stack */
382 pop_stack (regstack, regno)
386 int top = regstack->top;
388 CLEAR_HARD_REG_BIT (regstack->reg_set, regno);
390 /* If regno was not at the top of stack then adjust stack */
391 if (regstack->reg [top] != regno)
394 for (i = regstack->top; i >= 0; i--)
395 if (regstack->reg [i] == regno)
398 for (j = i; j < top; j++)
399 regstack->reg [j] = regstack->reg [j + 1];
405 /* Convert register usage from "flat" register file usage to a "stack
406 register file. FIRST is the first insn in the function, FILE is the
409 Construct a CFG and run life analysis. Then convert each insn one
410 by one. Run a last jump_optimize pass, if optimizing, to eliminate
411 code duplication created when the converter inserts pop insns on
415 reg_to_stack (first, file)
424 /* See if there is something to do. Flow analysis is quite
425 expensive so we might save some compilation time. */
426 for (i = FIRST_STACK_REG; i <= LAST_STACK_REG; i++)
427 if (regs_ever_live[i])
429 if (i > LAST_STACK_REG)
432 /* Ok, floating point instructions exist. If not optimizing,
433 build the CFG and run life analysis. */
436 find_basic_blocks (first, max_reg_num (), file, 0);
438 blocks = sbitmap_alloc (n_basic_blocks);
439 sbitmap_ones (blocks);
440 count_or_remove_death_notes (blocks, 1);
441 sbitmap_free (blocks);
443 life_analysis (first, max_reg_num (), file, 0);
446 /* Set up block info for each basic block. */
447 bi = (block_info) alloca ((n_basic_blocks + 1) * sizeof (*bi));
448 memset (bi, 0, (n_basic_blocks + 1) * sizeof (*bi));
449 for (i = n_basic_blocks - 1; i >= 0; --i)
450 BASIC_BLOCK (i)->aux = bi + i;
451 EXIT_BLOCK_PTR->aux = bi + n_basic_blocks;
453 /* Create the replacement registers up front. */
454 for (i = FIRST_STACK_REG; i <= LAST_STACK_REG; i++)
456 enum machine_mode mode;
457 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT);
459 mode = GET_MODE_WIDER_MODE (mode))
460 FP_MODE_REG (i, mode) = gen_rtx_REG (mode, i);
461 for (mode = GET_CLASS_NARROWEST_MODE (MODE_COMPLEX_FLOAT);
463 mode = GET_MODE_WIDER_MODE (mode))
464 FP_MODE_REG (i, mode) = gen_rtx_REG (mode, i);
467 ix86_flags_rtx = gen_rtx_REG (CCmode, FLAGS_REG);
469 /* A QNaN for initializing uninitialized variables.
471 ??? We can't load from constant memory in PIC mode, because
472 we're insertting these instructions before the prologue and
473 the PIC register hasn't been set up. In that case, fall back
474 on zero, which we can get from `ldz'. */
477 nan = CONST0_RTX (SFmode);
480 nan = gen_lowpart (SFmode, GEN_INT (0x7fc00000));
481 nan = force_const_mem (SFmode, nan);
484 /* Allocate a cache for stack_regs_mentioned. */
485 max_uid = get_max_uid ();
486 VARRAY_CHAR_INIT (stack_regs_mentioned_data, max_uid + 1,
487 "stack_regs_mentioned cache");
489 if (convert_regs (file) && optimize)
491 jump_optimize (first, JUMP_CROSS_JUMP_DEATH_MATTERS,
492 !JUMP_NOOP_MOVES, !JUMP_AFTER_REGSCAN);
495 VARRAY_FREE (stack_regs_mentioned_data);
498 /* Check PAT, which is in INSN, for LABEL_REFs. Add INSN to the
499 label's chain of references, and note which insn contains each
503 record_label_references (insn, pat)
506 register enum rtx_code code = GET_CODE (pat);
508 register const char *fmt;
510 if (code == LABEL_REF)
512 register rtx label = XEXP (pat, 0);
515 if (GET_CODE (label) != CODE_LABEL)
518 /* If this is an undefined label, LABEL_REFS (label) contains
520 if (INSN_UID (label) == 0)
523 /* Don't make a duplicate in the code_label's chain. */
525 for (ref = LABEL_REFS (label);
527 ref = LABEL_NEXTREF (ref))
528 if (CONTAINING_INSN (ref) == insn)
531 CONTAINING_INSN (pat) = insn;
532 LABEL_NEXTREF (pat) = LABEL_REFS (label);
533 LABEL_REFS (label) = pat;
538 fmt = GET_RTX_FORMAT (code);
539 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
542 record_label_references (insn, XEXP (pat, i));
546 for (j = 0; j < XVECLEN (pat, i); j++)
547 record_label_references (insn, XVECEXP (pat, i, j));
552 /* Return a pointer to the REG expression within PAT. If PAT is not a
553 REG, possible enclosed by a conversion rtx, return the inner part of
554 PAT that stopped the search. */
561 switch (GET_CODE (*pat))
564 /* Eliminate FP subregister accesses in favour of the
565 actual FP register in use. */
568 if (FP_REG_P (subreg = SUBREG_REG (*pat)))
570 *pat = FP_MODE_REG (REGNO (subreg) + SUBREG_WORD (*pat),
579 pat = & XEXP (*pat, 0);
583 /* There are many rules that an asm statement for stack-like regs must
584 follow. Those rules are explained at the top of this file: the rule
585 numbers below refer to that explanation. */
588 check_asm_stack_operands (insn)
593 int malformed_asm = 0;
594 rtx body = PATTERN (insn);
596 char reg_used_as_output[FIRST_PSEUDO_REGISTER];
597 char implicitly_dies[FIRST_PSEUDO_REGISTER];
601 int n_inputs, n_outputs;
603 /* Find out what the constraints require. If no constraint
604 alternative matches, this asm is malformed. */
606 constrain_operands (1);
607 alt = which_alternative;
609 preprocess_constraints ();
611 n_inputs = get_asm_operand_n_inputs (body);
612 n_outputs = recog_data.n_operands - n_inputs;
617 /* Avoid further trouble with this insn. */
618 PATTERN (insn) = gen_rtx_USE (VOIDmode, const0_rtx);
622 /* Strip SUBREGs here to make the following code simpler. */
623 for (i = 0; i < recog_data.n_operands; i++)
624 if (GET_CODE (recog_data.operand[i]) == SUBREG
625 && GET_CODE (SUBREG_REG (recog_data.operand[i])) == REG)
626 recog_data.operand[i] = SUBREG_REG (recog_data.operand[i]);
628 /* Set up CLOBBER_REG. */
632 if (GET_CODE (body) == PARALLEL)
634 clobber_reg = (rtx *) alloca (XVECLEN (body, 0) * sizeof (rtx));
636 for (i = 0; i < XVECLEN (body, 0); i++)
637 if (GET_CODE (XVECEXP (body, 0, i)) == CLOBBER)
639 rtx clobber = XVECEXP (body, 0, i);
640 rtx reg = XEXP (clobber, 0);
642 if (GET_CODE (reg) == SUBREG && GET_CODE (SUBREG_REG (reg)) == REG)
643 reg = SUBREG_REG (reg);
645 if (STACK_REG_P (reg))
647 clobber_reg[n_clobbers] = reg;
653 /* Enforce rule #4: Output operands must specifically indicate which
654 reg an output appears in after an asm. "=f" is not allowed: the
655 operand constraints must select a class with a single reg.
657 Also enforce rule #5: Output operands must start at the top of
658 the reg-stack: output operands may not "skip" a reg. */
660 memset (reg_used_as_output, 0, sizeof (reg_used_as_output));
661 for (i = 0; i < n_outputs; i++)
662 if (STACK_REG_P (recog_data.operand[i]))
664 if (reg_class_size[(int) recog_op_alt[i][alt].class] != 1)
666 error_for_asm (insn, "Output constraint %d must specify a single register", i);
670 reg_used_as_output[REGNO (recog_data.operand[i])] = 1;
674 /* Search for first non-popped reg. */
675 for (i = FIRST_STACK_REG; i < LAST_STACK_REG + 1; i++)
676 if (! reg_used_as_output[i])
679 /* If there are any other popped regs, that's an error. */
680 for (; i < LAST_STACK_REG + 1; i++)
681 if (reg_used_as_output[i])
684 if (i != LAST_STACK_REG + 1)
686 error_for_asm (insn, "Output regs must be grouped at top of stack");
690 /* Enforce rule #2: All implicitly popped input regs must be closer
691 to the top of the reg-stack than any input that is not implicitly
694 memset (implicitly_dies, 0, sizeof (implicitly_dies));
695 for (i = n_outputs; i < n_outputs + n_inputs; i++)
696 if (STACK_REG_P (recog_data.operand[i]))
698 /* An input reg is implicitly popped if it is tied to an
699 output, or if there is a CLOBBER for it. */
702 for (j = 0; j < n_clobbers; j++)
703 if (operands_match_p (clobber_reg[j], recog_data.operand[i]))
706 if (j < n_clobbers || recog_op_alt[i][alt].matches >= 0)
707 implicitly_dies[REGNO (recog_data.operand[i])] = 1;
710 /* Search for first non-popped reg. */
711 for (i = FIRST_STACK_REG; i < LAST_STACK_REG + 1; i++)
712 if (! implicitly_dies[i])
715 /* If there are any other popped regs, that's an error. */
716 for (; i < LAST_STACK_REG + 1; i++)
717 if (implicitly_dies[i])
720 if (i != LAST_STACK_REG + 1)
723 "Implicitly popped regs must be grouped at top of stack");
727 /* Enfore rule #3: If any input operand uses the "f" constraint, all
728 output constraints must use the "&" earlyclobber.
730 ??? Detect this more deterministically by having constrain_asm_operands
731 record any earlyclobber. */
733 for (i = n_outputs; i < n_outputs + n_inputs; i++)
734 if (recog_op_alt[i][alt].matches == -1)
738 for (j = 0; j < n_outputs; j++)
739 if (operands_match_p (recog_data.operand[j], recog_data.operand[i]))
742 "Output operand %d must use `&' constraint", j);
749 /* Avoid further trouble with this insn. */
750 PATTERN (insn) = gen_rtx_USE (VOIDmode, const0_rtx);
757 /* Calculate the number of inputs and outputs in BODY, an
758 asm_operands. N_OPERANDS is the total number of operands, and
759 N_INPUTS and N_OUTPUTS are pointers to ints into which the results are
763 get_asm_operand_n_inputs (body)
766 if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
767 return ASM_OPERANDS_INPUT_LENGTH (SET_SRC (body));
769 else if (GET_CODE (body) == ASM_OPERANDS)
770 return ASM_OPERANDS_INPUT_LENGTH (body);
772 else if (GET_CODE (body) == PARALLEL
773 && GET_CODE (XVECEXP (body, 0, 0)) == SET)
774 return ASM_OPERANDS_INPUT_LENGTH (SET_SRC (XVECEXP (body, 0, 0)));
776 else if (GET_CODE (body) == PARALLEL
777 && GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
778 return ASM_OPERANDS_INPUT_LENGTH (XVECEXP (body, 0, 0));
783 /* If current function returns its result in an fp stack register,
784 return the REG. Otherwise, return 0. */
792 /* If the value is supposed to be returned in memory, then clearly
793 it is not returned in a stack register. */
794 if (aggregate_value_p (DECL_RESULT (decl)))
797 result = DECL_RTL (DECL_RESULT (decl));
798 /* ?!? What is this code supposed to do? Can this code actually
799 trigger if we kick out aggregates above? */
801 && ! (GET_CODE (result) == REG
802 && REGNO (result) < FIRST_PSEUDO_REGISTER))
804 #ifdef FUNCTION_OUTGOING_VALUE
806 = FUNCTION_OUTGOING_VALUE (TREE_TYPE (DECL_RESULT (decl)), decl);
808 result = FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (decl)), decl);
812 return result != 0 && STACK_REG_P (result) ? result : 0;
817 * This section deals with stack register substitution, and forms the second
821 /* Replace REG, which is a pointer to a stack reg RTX, with an RTX for
822 the desired hard REGNO. */
825 replace_reg (reg, regno)
829 if (regno < FIRST_STACK_REG || regno > LAST_STACK_REG
830 || ! STACK_REG_P (*reg))
833 switch (GET_MODE_CLASS (GET_MODE (*reg)))
837 case MODE_COMPLEX_FLOAT:;
840 *reg = FP_MODE_REG (regno, GET_MODE (*reg));
843 /* Remove a note of type NOTE, which must be found, for register
844 number REGNO from INSN. Remove only one such note. */
847 remove_regno_note (insn, note, regno)
852 register rtx *note_link, this;
854 note_link = ®_NOTES(insn);
855 for (this = *note_link; this; this = XEXP (this, 1))
856 if (REG_NOTE_KIND (this) == note
857 && REG_P (XEXP (this, 0)) && REGNO (XEXP (this, 0)) == regno)
859 *note_link = XEXP (this, 1);
863 note_link = &XEXP (this, 1);
868 /* Find the hard register number of virtual register REG in REGSTACK.
869 The hard register number is relative to the top of the stack. -1 is
870 returned if the register is not found. */
873 get_hard_regnum (regstack, reg)
879 if (! STACK_REG_P (reg))
882 for (i = regstack->top; i >= 0; i--)
883 if (regstack->reg[i] == REGNO (reg))
886 return i >= 0 ? (FIRST_STACK_REG + regstack->top - i) : -1;
889 /* Delete INSN from the RTL. Mark the insn, but don't remove it from
890 the chain of insns. Doing so could confuse block_begin and block_end
891 if this were the only insn in the block. */
894 delete_insn_for_stacker (insn)
897 PUT_CODE (insn, NOTE);
898 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
899 NOTE_SOURCE_FILE (insn) = 0;
902 /* Emit an insn to pop virtual register REG before or after INSN.
903 REGSTACK is the stack state after INSN and is updated to reflect this
904 pop. WHEN is either emit_insn_before or emit_insn_after. A pop insn
905 is represented as a SET whose destination is the register to be popped
906 and source is the top of stack. A death note for the top of stack
907 cases the movdf pattern to pop. */
910 emit_pop_insn (insn, regstack, reg, where)
914 enum emit_where where;
916 rtx pop_insn, pop_rtx;
919 hard_regno = get_hard_regnum (regstack, reg);
921 if (hard_regno < FIRST_STACK_REG)
924 pop_rtx = gen_rtx_SET (VOIDmode, FP_MODE_REG (hard_regno, DFmode),
925 FP_MODE_REG (FIRST_STACK_REG, DFmode));
927 if (where == EMIT_AFTER)
928 pop_insn = emit_block_insn_after (pop_rtx, insn, current_block);
930 pop_insn = emit_block_insn_before (pop_rtx, insn, current_block);
933 = gen_rtx_EXPR_LIST (REG_DEAD, FP_MODE_REG (FIRST_STACK_REG, DFmode),
934 REG_NOTES (pop_insn));
936 regstack->reg[regstack->top - (hard_regno - FIRST_STACK_REG)]
937 = regstack->reg[regstack->top];
939 CLEAR_HARD_REG_BIT (regstack->reg_set, REGNO (reg));
944 /* Emit an insn before or after INSN to swap virtual register REG with
945 the top of stack. REGSTACK is the stack state before the swap, and
946 is updated to reflect the swap. A swap insn is represented as a
947 PARALLEL of two patterns: each pattern moves one reg to the other.
949 If REG is already at the top of the stack, no insn is emitted. */
952 emit_swap_insn (insn, regstack, reg)
959 int tmp, other_reg; /* swap regno temps */
960 rtx i1; /* the stack-reg insn prior to INSN */
961 rtx i1set = NULL_RTX; /* the SET rtx within I1 */
963 hard_regno = get_hard_regnum (regstack, reg);
965 if (hard_regno < FIRST_STACK_REG)
967 if (hard_regno == FIRST_STACK_REG)
970 other_reg = regstack->top - (hard_regno - FIRST_STACK_REG);
972 tmp = regstack->reg[other_reg];
973 regstack->reg[other_reg] = regstack->reg[regstack->top];
974 regstack->reg[regstack->top] = tmp;
976 /* Find the previous insn involving stack regs, but don't pass a
979 if (current_block && insn != current_block->head)
981 rtx tmp = PREV_INSN (insn);
982 while (tmp != current_block->head)
984 if (GET_CODE (tmp) == CODE_LABEL
985 || (GET_CODE (tmp) == NOTE
986 && NOTE_LINE_NUMBER (tmp) == NOTE_INSN_BASIC_BLOCK)
987 || (GET_CODE (tmp) == INSN
988 && stack_regs_mentioned (tmp)))
993 tmp = PREV_INSN (tmp);
998 && (i1set = single_set (i1)) != NULL_RTX)
1000 rtx i1src = *get_true_reg (&SET_SRC (i1set));
1001 rtx i1dest = *get_true_reg (&SET_DEST (i1set));
1003 /* If the previous register stack push was from the reg we are to
1004 swap with, omit the swap. */
1006 if (GET_CODE (i1dest) == REG && REGNO (i1dest) == FIRST_STACK_REG
1007 && GET_CODE (i1src) == REG && REGNO (i1src) == hard_regno - 1
1008 && find_regno_note (i1, REG_DEAD, FIRST_STACK_REG) == NULL_RTX)
1011 /* If the previous insn wrote to the reg we are to swap with,
1014 if (GET_CODE (i1dest) == REG && REGNO (i1dest) == hard_regno
1015 && GET_CODE (i1src) == REG && REGNO (i1src) == FIRST_STACK_REG
1016 && find_regno_note (i1, REG_DEAD, FIRST_STACK_REG) == NULL_RTX)
1020 swap_rtx = gen_swapxf (FP_MODE_REG (hard_regno, XFmode),
1021 FP_MODE_REG (FIRST_STACK_REG, XFmode));
1024 emit_block_insn_after (swap_rtx, i1, current_block);
1025 else if (current_block)
1027 i1 = emit_insn_before (swap_rtx, current_block->head);
1028 current_block->head = i1;
1031 emit_insn_before (swap_rtx, insn);
1034 /* Handle a move to or from a stack register in PAT, which is in INSN.
1035 REGSTACK is the current stack. */
1038 move_for_stack_reg (insn, regstack, pat)
1043 rtx *psrc = get_true_reg (&SET_SRC (pat));
1044 rtx *pdest = get_true_reg (&SET_DEST (pat));
1048 src = *psrc; dest = *pdest;
1050 if (STACK_REG_P (src) && STACK_REG_P (dest))
1052 /* Write from one stack reg to another. If SRC dies here, then
1053 just change the register mapping and delete the insn. */
1055 note = find_regno_note (insn, REG_DEAD, REGNO (src));
1060 /* If this is a no-op move, there must not be a REG_DEAD note. */
1061 if (REGNO (src) == REGNO (dest))
1064 for (i = regstack->top; i >= 0; i--)
1065 if (regstack->reg[i] == REGNO (src))
1068 /* The source must be live, and the dest must be dead. */
1069 if (i < 0 || get_hard_regnum (regstack, dest) >= FIRST_STACK_REG)
1072 /* It is possible that the dest is unused after this insn.
1073 If so, just pop the src. */
1075 if (find_regno_note (insn, REG_UNUSED, REGNO (dest)))
1077 emit_pop_insn (insn, regstack, src, EMIT_AFTER);
1079 delete_insn_for_stacker (insn);
1083 regstack->reg[i] = REGNO (dest);
1085 SET_HARD_REG_BIT (regstack->reg_set, REGNO (dest));
1086 CLEAR_HARD_REG_BIT (regstack->reg_set, REGNO (src));
1088 delete_insn_for_stacker (insn);
1093 /* The source reg does not die. */
1095 /* If this appears to be a no-op move, delete it, or else it
1096 will confuse the machine description output patterns. But if
1097 it is REG_UNUSED, we must pop the reg now, as per-insn processing
1098 for REG_UNUSED will not work for deleted insns. */
1100 if (REGNO (src) == REGNO (dest))
1102 if (find_regno_note (insn, REG_UNUSED, REGNO (dest)))
1103 emit_pop_insn (insn, regstack, dest, EMIT_AFTER);
1105 delete_insn_for_stacker (insn);
1109 /* The destination ought to be dead */
1110 if (get_hard_regnum (regstack, dest) >= FIRST_STACK_REG)
1113 replace_reg (psrc, get_hard_regnum (regstack, src));
1115 regstack->reg[++regstack->top] = REGNO (dest);
1116 SET_HARD_REG_BIT (regstack->reg_set, REGNO (dest));
1117 replace_reg (pdest, FIRST_STACK_REG);
1119 else if (STACK_REG_P (src))
1121 /* Save from a stack reg to MEM, or possibly integer reg. Since
1122 only top of stack may be saved, emit an exchange first if
1125 emit_swap_insn (insn, regstack, src);
1127 note = find_regno_note (insn, REG_DEAD, REGNO (src));
1130 replace_reg (&XEXP (note, 0), FIRST_STACK_REG);
1132 CLEAR_HARD_REG_BIT (regstack->reg_set, REGNO (src));
1134 else if (GET_MODE (src) == XFmode && regstack->top < REG_STACK_SIZE - 1)
1136 /* A 387 cannot write an XFmode value to a MEM without
1137 clobbering the source reg. The output code can handle
1138 this by reading back the value from the MEM.
1139 But it is more efficient to use a temp register if one is
1140 available. Push the source value here if the register
1141 stack is not full, and then write the value to memory via
1143 rtx push_rtx, push_insn;
1144 rtx top_stack_reg = FP_MODE_REG (FIRST_STACK_REG, XFmode);
1146 push_rtx = gen_movxf (top_stack_reg, top_stack_reg);
1147 push_insn = emit_insn_before (push_rtx, insn);
1148 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_DEAD, top_stack_reg,
1152 replace_reg (psrc, FIRST_STACK_REG);
1154 else if (STACK_REG_P (dest))
1156 /* Load from MEM, or possibly integer REG or constant, into the
1157 stack regs. The actual target is always the top of the
1158 stack. The stack mapping is changed to reflect that DEST is
1159 now at top of stack. */
1161 /* The destination ought to be dead */
1162 if (get_hard_regnum (regstack, dest) >= FIRST_STACK_REG)
1165 if (regstack->top >= REG_STACK_SIZE)
1168 regstack->reg[++regstack->top] = REGNO (dest);
1169 SET_HARD_REG_BIT (regstack->reg_set, REGNO (dest));
1170 replace_reg (pdest, FIRST_STACK_REG);
1176 /* Swap the condition on a branch, if there is one. Return true if we
1177 found a condition to swap. False if the condition was not used as
1181 swap_rtx_condition_1 (pat)
1184 register const char *fmt;
1185 register int i, r = 0;
1187 if (GET_RTX_CLASS (GET_CODE (pat)) == '<')
1189 PUT_CODE (pat, swap_condition (GET_CODE (pat)));
1194 fmt = GET_RTX_FORMAT (GET_CODE (pat));
1195 for (i = GET_RTX_LENGTH (GET_CODE (pat)) - 1; i >= 0; i--)
1201 for (j = XVECLEN (pat, i) - 1; j >= 0; j--)
1202 r |= swap_rtx_condition_1 (XVECEXP (pat, i, j));
1204 else if (fmt[i] == 'e')
1205 r |= swap_rtx_condition_1 (XEXP (pat, i));
1213 swap_rtx_condition (insn)
1216 rtx pat = PATTERN (insn);
1218 /* We're looking for a single set to cc0 or an HImode temporary. */
1220 if (GET_CODE (pat) == SET
1221 && GET_CODE (SET_DEST (pat)) == REG
1222 && REGNO (SET_DEST (pat)) == FLAGS_REG)
1224 insn = next_flags_user (insn);
1225 if (insn == NULL_RTX)
1227 pat = PATTERN (insn);
1230 /* See if this is, or ends in, a fnstsw, aka unspec 9. If so, we're
1231 not doing anything with the cc value right now. We may be able to
1232 search for one though. */
1234 if (GET_CODE (pat) == SET
1235 && GET_CODE (SET_SRC (pat)) == UNSPEC
1236 && XINT (SET_SRC (pat), 1) == 9)
1238 rtx dest = SET_DEST (pat);
1240 /* Search forward looking for the first use of this value.
1241 Stop at block boundaries. */
1242 /* ??? This really cries for BLOCK_END! */
1245 insn = NEXT_INSN (insn);
1246 if (insn == NULL_RTX)
1248 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i'
1249 && reg_mentioned_p (dest, insn))
1251 if (GET_CODE (insn) == JUMP_INSN)
1253 if (GET_CODE (insn) == CODE_LABEL)
1257 /* So we've found the insn using this value. If it is anything
1258 other than sahf, aka unspec 10, or the value does not die
1259 (meaning we'd have to search further), then we must give up. */
1260 pat = PATTERN (insn);
1261 if (GET_CODE (pat) != SET
1262 || GET_CODE (SET_SRC (pat)) != UNSPEC
1263 || XINT (SET_SRC (pat), 1) != 10
1264 || ! dead_or_set_p (insn, dest))
1267 /* Now we are prepared to handle this as a normal cc0 setter. */
1268 insn = next_flags_user (insn);
1269 if (insn == NULL_RTX)
1271 pat = PATTERN (insn);
1274 return swap_rtx_condition_1 (pat);
1277 /* Handle a comparison. Special care needs to be taken to avoid
1278 causing comparisons that a 387 cannot do correctly, such as EQ.
1280 Also, a pop insn may need to be emitted. The 387 does have an
1281 `fcompp' insn that can pop two regs, but it is sometimes too expensive
1282 to do this - a `fcomp' followed by a `fstpl %st(0)' may be easier to
1286 compare_for_stack_reg (insn, regstack, pat_src)
1292 rtx src1_note, src2_note;
1295 src1 = get_true_reg (&XEXP (pat_src, 0));
1296 src2 = get_true_reg (&XEXP (pat_src, 1));
1297 flags_user = next_flags_user (insn);
1299 /* ??? If fxch turns out to be cheaper than fstp, give priority to
1300 registers that die in this insn - move those to stack top first. */
1301 if ((! STACK_REG_P (*src1)
1302 || (STACK_REG_P (*src2)
1303 && get_hard_regnum (regstack, *src2) == FIRST_STACK_REG))
1304 && swap_rtx_condition (insn))
1307 temp = XEXP (pat_src, 0);
1308 XEXP (pat_src, 0) = XEXP (pat_src, 1);
1309 XEXP (pat_src, 1) = temp;
1311 src1 = get_true_reg (&XEXP (pat_src, 0));
1312 src2 = get_true_reg (&XEXP (pat_src, 1));
1314 INSN_CODE (insn) = -1;
1317 /* We will fix any death note later. */
1319 src1_note = find_regno_note (insn, REG_DEAD, REGNO (*src1));
1321 if (STACK_REG_P (*src2))
1322 src2_note = find_regno_note (insn, REG_DEAD, REGNO (*src2));
1324 src2_note = NULL_RTX;
1326 emit_swap_insn (insn, regstack, *src1);
1328 replace_reg (src1, FIRST_STACK_REG);
1330 if (STACK_REG_P (*src2))
1331 replace_reg (src2, get_hard_regnum (regstack, *src2));
1335 pop_stack (regstack, REGNO (XEXP (src1_note, 0)));
1336 replace_reg (&XEXP (src1_note, 0), FIRST_STACK_REG);
1339 /* If the second operand dies, handle that. But if the operands are
1340 the same stack register, don't bother, because only one death is
1341 needed, and it was just handled. */
1344 && ! (STACK_REG_P (*src1) && STACK_REG_P (*src2)
1345 && REGNO (*src1) == REGNO (*src2)))
1347 /* As a special case, two regs may die in this insn if src2 is
1348 next to top of stack and the top of stack also dies. Since
1349 we have already popped src1, "next to top of stack" is really
1350 at top (FIRST_STACK_REG) now. */
1352 if (get_hard_regnum (regstack, XEXP (src2_note, 0)) == FIRST_STACK_REG
1355 pop_stack (regstack, REGNO (XEXP (src2_note, 0)));
1356 replace_reg (&XEXP (src2_note, 0), FIRST_STACK_REG + 1);
1360 /* The 386 can only represent death of the first operand in
1361 the case handled above. In all other cases, emit a separate
1362 pop and remove the death note from here. */
1364 /* link_cc0_insns (insn); */
1366 remove_regno_note (insn, REG_DEAD, REGNO (XEXP (src2_note, 0)));
1368 emit_pop_insn (insn, regstack, XEXP (src2_note, 0),
1374 /* Substitute new registers in PAT, which is part of INSN. REGSTACK
1375 is the current register layout. */
1378 subst_stack_regs_pat (insn, regstack, pat)
1385 switch (GET_CODE (pat))
1388 /* Deaths in USE insns can happen in non optimizing compilation.
1389 Handle them by popping the dying register. */
1390 src = get_true_reg (&XEXP (pat, 0));
1391 if (STACK_REG_P (*src)
1392 && find_regno_note (insn, REG_DEAD, REGNO (*src)))
1394 emit_pop_insn (insn, regstack, *src, EMIT_AFTER);
1397 /* ??? Uninitialized USE should not happen. */
1398 else if (get_hard_regnum (regstack, *src) == -1)
1406 /* The fix_truncdi_1 pattern wants to be able to allocate it's
1407 own scratch register. It does this by clobbering an fp reg
1408 so that it is assured of an empty reg-stack register.
1409 If the register is live, kill it now. Remove the DEAD/UNUSED
1410 note so we don't try to kill it later too. */
1412 dest = get_true_reg (&XEXP (pat, 0));
1413 if (STACK_REG_P (*dest))
1415 note = find_reg_note (insn, REG_DEAD, *dest);
1417 emit_pop_insn (insn, regstack, *dest, EMIT_BEFORE);
1420 note = find_reg_note (insn, REG_UNUSED, *dest);
1425 remove_note (insn, note);
1426 replace_reg (dest, LAST_STACK_REG);
1433 rtx *src1 = (rtx *) NULL_PTR, *src2;
1434 rtx src1_note, src2_note;
1437 dest = get_true_reg (&SET_DEST (pat));
1438 src = get_true_reg (&SET_SRC (pat));
1439 pat_src = SET_SRC (pat);
1441 /* See if this is a `movM' pattern, and handle elsewhere if so. */
1442 if (STACK_REG_P (*src)
1443 || (STACK_REG_P (*dest)
1444 && (GET_CODE (*src) == REG || GET_CODE (*src) == MEM
1445 || GET_CODE (*src) == CONST_DOUBLE)))
1447 move_for_stack_reg (insn, regstack, pat);
1451 switch (GET_CODE (pat_src))
1454 compare_for_stack_reg (insn, regstack, pat_src);
1460 for (count = HARD_REGNO_NREGS (REGNO (*dest), GET_MODE (*dest));
1463 regstack->reg[++regstack->top] = REGNO (*dest) + count;
1464 SET_HARD_REG_BIT (regstack->reg_set, REGNO (*dest) + count);
1467 replace_reg (dest, FIRST_STACK_REG);
1471 /* This is a `tstM2' case. */
1472 if (*dest != cc0_rtx)
1478 case FLOAT_TRUNCATE:
1482 /* These insns only operate on the top of the stack. DEST might
1483 be cc0_rtx if we're processing a tstM pattern. Also, it's
1484 possible that the tstM case results in a REG_DEAD note on the
1488 src1 = get_true_reg (&XEXP (pat_src, 0));
1490 emit_swap_insn (insn, regstack, *src1);
1492 src1_note = find_regno_note (insn, REG_DEAD, REGNO (*src1));
1494 if (STACK_REG_P (*dest))
1495 replace_reg (dest, FIRST_STACK_REG);
1499 replace_reg (&XEXP (src1_note, 0), FIRST_STACK_REG);
1501 CLEAR_HARD_REG_BIT (regstack->reg_set, REGNO (*src1));
1504 replace_reg (src1, FIRST_STACK_REG);
1509 /* On i386, reversed forms of subM3 and divM3 exist for
1510 MODE_FLOAT, so the same code that works for addM3 and mulM3
1514 /* These insns can accept the top of stack as a destination
1515 from a stack reg or mem, or can use the top of stack as a
1516 source and some other stack register (possibly top of stack)
1517 as a destination. */
1519 src1 = get_true_reg (&XEXP (pat_src, 0));
1520 src2 = get_true_reg (&XEXP (pat_src, 1));
1522 /* We will fix any death note later. */
1524 if (STACK_REG_P (*src1))
1525 src1_note = find_regno_note (insn, REG_DEAD, REGNO (*src1));
1527 src1_note = NULL_RTX;
1528 if (STACK_REG_P (*src2))
1529 src2_note = find_regno_note (insn, REG_DEAD, REGNO (*src2));
1531 src2_note = NULL_RTX;
1533 /* If either operand is not a stack register, then the dest
1534 must be top of stack. */
1536 if (! STACK_REG_P (*src1) || ! STACK_REG_P (*src2))
1537 emit_swap_insn (insn, regstack, *dest);
1540 /* Both operands are REG. If neither operand is already
1541 at the top of stack, choose to make the one that is the dest
1542 the new top of stack. */
1544 int src1_hard_regnum, src2_hard_regnum;
1546 src1_hard_regnum = get_hard_regnum (regstack, *src1);
1547 src2_hard_regnum = get_hard_regnum (regstack, *src2);
1548 if (src1_hard_regnum == -1 || src2_hard_regnum == -1)
1551 if (src1_hard_regnum != FIRST_STACK_REG
1552 && src2_hard_regnum != FIRST_STACK_REG)
1553 emit_swap_insn (insn, regstack, *dest);
1556 if (STACK_REG_P (*src1))
1557 replace_reg (src1, get_hard_regnum (regstack, *src1));
1558 if (STACK_REG_P (*src2))
1559 replace_reg (src2, get_hard_regnum (regstack, *src2));
1563 rtx src1_reg = XEXP (src1_note, 0);
1565 /* If the register that dies is at the top of stack, then
1566 the destination is somewhere else - merely substitute it.
1567 But if the reg that dies is not at top of stack, then
1568 move the top of stack to the dead reg, as though we had
1569 done the insn and then a store-with-pop. */
1571 if (REGNO (src1_reg) == regstack->reg[regstack->top])
1573 SET_HARD_REG_BIT (regstack->reg_set, REGNO (*dest));
1574 replace_reg (dest, get_hard_regnum (regstack, *dest));
1578 int regno = get_hard_regnum (regstack, src1_reg);
1580 SET_HARD_REG_BIT (regstack->reg_set, REGNO (*dest));
1581 replace_reg (dest, regno);
1583 regstack->reg[regstack->top - (regno - FIRST_STACK_REG)]
1584 = regstack->reg[regstack->top];
1587 CLEAR_HARD_REG_BIT (regstack->reg_set,
1588 REGNO (XEXP (src1_note, 0)));
1589 replace_reg (&XEXP (src1_note, 0), FIRST_STACK_REG);
1594 rtx src2_reg = XEXP (src2_note, 0);
1595 if (REGNO (src2_reg) == regstack->reg[regstack->top])
1597 SET_HARD_REG_BIT (regstack->reg_set, REGNO (*dest));
1598 replace_reg (dest, get_hard_regnum (regstack, *dest));
1602 int regno = get_hard_regnum (regstack, src2_reg);
1604 SET_HARD_REG_BIT (regstack->reg_set, REGNO (*dest));
1605 replace_reg (dest, regno);
1607 regstack->reg[regstack->top - (regno - FIRST_STACK_REG)]
1608 = regstack->reg[regstack->top];
1611 CLEAR_HARD_REG_BIT (regstack->reg_set,
1612 REGNO (XEXP (src2_note, 0)));
1613 replace_reg (&XEXP (src2_note, 0), FIRST_STACK_REG);
1618 SET_HARD_REG_BIT (regstack->reg_set, REGNO (*dest));
1619 replace_reg (dest, get_hard_regnum (regstack, *dest));
1624 switch (XINT (pat_src, 1))
1628 /* These insns only operate on the top of the stack. */
1630 src1 = get_true_reg (&XVECEXP (pat_src, 0, 0));
1632 emit_swap_insn (insn, regstack, *src1);
1634 src1_note = find_regno_note (insn, REG_DEAD, REGNO (*src1));
1636 if (STACK_REG_P (*dest))
1637 replace_reg (dest, FIRST_STACK_REG);
1641 replace_reg (&XEXP (src1_note, 0), FIRST_STACK_REG);
1643 CLEAR_HARD_REG_BIT (regstack->reg_set, REGNO (*src1));
1646 replace_reg (src1, FIRST_STACK_REG);
1650 /* (unspec [(unspec [(compare ..)] 9)] 10)
1651 Unspec 9 is fnstsw; unspec 10 is sahf. The combination
1652 matches the PPRO fcomi instruction. */
1654 pat_src = XVECEXP (pat_src, 0, 0);
1655 if (GET_CODE (pat_src) != UNSPEC
1656 || XINT (pat_src, 1) != 9)
1661 /* (unspec [(compare ..)] 9) */
1662 /* Combined fcomp+fnstsw generated for doing well with
1663 CSE. When optimizing this would have been broken
1666 pat_src = XVECEXP (pat_src, 0, 0);
1667 if (GET_CODE (pat_src) != COMPARE)
1670 compare_for_stack_reg (insn, regstack, pat_src);
1679 /* This insn requires the top of stack to be the destination. */
1681 /* If the comparison operator is an FP comparison operator,
1682 it is handled correctly by compare_for_stack_reg () who
1683 will move the destination to the top of stack. But if the
1684 comparison operator is not an FP comparison operator, we
1685 have to handle it here. */
1686 if (get_hard_regnum (regstack, *dest) >= FIRST_STACK_REG
1687 && REGNO (*dest) != regstack->reg[regstack->top])
1688 emit_swap_insn (insn, regstack, *dest);
1690 src1 = get_true_reg (&XEXP (pat_src, 1));
1691 src2 = get_true_reg (&XEXP (pat_src, 2));
1693 src1_note = find_regno_note (insn, REG_DEAD, REGNO (*src1));
1694 src2_note = find_regno_note (insn, REG_DEAD, REGNO (*src2));
1701 src_note[1] = src1_note;
1702 src_note[2] = src2_note;
1704 if (STACK_REG_P (*src1))
1705 replace_reg (src1, get_hard_regnum (regstack, *src1));
1706 if (STACK_REG_P (*src2))
1707 replace_reg (src2, get_hard_regnum (regstack, *src2));
1709 for (i = 1; i <= 2; i++)
1712 int regno = REGNO (XEXP (src_note[i], 0));
1714 /* If the register that dies is not at the top of
1715 stack, then move the top of stack to the dead reg */
1716 if (regno != regstack->reg[regstack->top])
1718 remove_regno_note (insn, REG_DEAD, regno);
1719 emit_pop_insn (insn, regstack, XEXP (src_note[i], 0),
1724 CLEAR_HARD_REG_BIT (regstack->reg_set, regno);
1725 replace_reg (&XEXP (src_note[i], 0), FIRST_STACK_REG);
1731 /* Make dest the top of stack. Add dest to regstack if
1733 if (get_hard_regnum (regstack, *dest) < FIRST_STACK_REG)
1734 regstack->reg[++regstack->top] = REGNO (*dest);
1735 SET_HARD_REG_BIT (regstack->reg_set, REGNO (*dest));
1736 replace_reg (dest, FIRST_STACK_REG);
1750 /* Substitute hard regnums for any stack regs in INSN, which has
1751 N_INPUTS inputs and N_OUTPUTS outputs. REGSTACK is the stack info
1752 before the insn, and is updated with changes made here.
1754 There are several requirements and assumptions about the use of
1755 stack-like regs in asm statements. These rules are enforced by
1756 record_asm_stack_regs; see comments there for details. Any
1757 asm_operands left in the RTL at this point may be assume to meet the
1758 requirements, since record_asm_stack_regs removes any problem asm. */
1761 subst_asm_stack_regs (insn, regstack)
1765 rtx body = PATTERN (insn);
1768 rtx *note_reg; /* Array of note contents */
1769 rtx **note_loc; /* Address of REG field of each note */
1770 enum reg_note *note_kind; /* The type of each note */
1775 struct stack_def temp_stack;
1780 int n_inputs, n_outputs;
1782 if (! check_asm_stack_operands (insn))
1785 /* Find out what the constraints required. If no constraint
1786 alternative matches, that is a compiler bug: we should have caught
1787 such an insn in check_asm_stack_operands. */
1788 extract_insn (insn);
1789 constrain_operands (1);
1790 alt = which_alternative;
1792 preprocess_constraints ();
1794 n_inputs = get_asm_operand_n_inputs (body);
1795 n_outputs = recog_data.n_operands - n_inputs;
1800 /* Strip SUBREGs here to make the following code simpler. */
1801 for (i = 0; i < recog_data.n_operands; i++)
1802 if (GET_CODE (recog_data.operand[i]) == SUBREG
1803 && GET_CODE (SUBREG_REG (recog_data.operand[i])) == REG)
1805 recog_data.operand_loc[i] = & SUBREG_REG (recog_data.operand[i]);
1806 recog_data.operand[i] = SUBREG_REG (recog_data.operand[i]);
1809 /* Set up NOTE_REG, NOTE_LOC and NOTE_KIND. */
1811 for (i = 0, note = REG_NOTES (insn); note; note = XEXP (note, 1))
1814 note_reg = (rtx *) alloca (i * sizeof (rtx));
1815 note_loc = (rtx **) alloca (i * sizeof (rtx *));
1816 note_kind = (enum reg_note *) alloca (i * sizeof (enum reg_note));
1819 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
1821 rtx reg = XEXP (note, 0);
1822 rtx *loc = & XEXP (note, 0);
1824 if (GET_CODE (reg) == SUBREG && GET_CODE (SUBREG_REG (reg)) == REG)
1826 loc = & SUBREG_REG (reg);
1827 reg = SUBREG_REG (reg);
1830 if (STACK_REG_P (reg)
1831 && (REG_NOTE_KIND (note) == REG_DEAD
1832 || REG_NOTE_KIND (note) == REG_UNUSED))
1834 note_reg[n_notes] = reg;
1835 note_loc[n_notes] = loc;
1836 note_kind[n_notes] = REG_NOTE_KIND (note);
1841 /* Set up CLOBBER_REG and CLOBBER_LOC. */
1845 if (GET_CODE (body) == PARALLEL)
1847 clobber_reg = (rtx *) alloca (XVECLEN (body, 0) * sizeof (rtx));
1848 clobber_loc = (rtx **) alloca (XVECLEN (body, 0) * sizeof (rtx *));
1850 for (i = 0; i < XVECLEN (body, 0); i++)
1851 if (GET_CODE (XVECEXP (body, 0, i)) == CLOBBER)
1853 rtx clobber = XVECEXP (body, 0, i);
1854 rtx reg = XEXP (clobber, 0);
1855 rtx *loc = & XEXP (clobber, 0);
1857 if (GET_CODE (reg) == SUBREG && GET_CODE (SUBREG_REG (reg)) == REG)
1859 loc = & SUBREG_REG (reg);
1860 reg = SUBREG_REG (reg);
1863 if (STACK_REG_P (reg))
1865 clobber_reg[n_clobbers] = reg;
1866 clobber_loc[n_clobbers] = loc;
1872 temp_stack = *regstack;
1874 /* Put the input regs into the desired place in TEMP_STACK. */
1876 for (i = n_outputs; i < n_outputs + n_inputs; i++)
1877 if (STACK_REG_P (recog_data.operand[i])
1878 && reg_class_subset_p (recog_op_alt[i][alt].class,
1880 && recog_op_alt[i][alt].class != FLOAT_REGS)
1882 /* If an operand needs to be in a particular reg in
1883 FLOAT_REGS, the constraint was either 't' or 'u'. Since
1884 these constraints are for single register classes, and
1885 reload guaranteed that operand[i] is already in that class,
1886 we can just use REGNO (recog_data.operand[i]) to know which
1887 actual reg this operand needs to be in. */
1889 int regno = get_hard_regnum (&temp_stack, recog_data.operand[i]);
1894 if (regno != REGNO (recog_data.operand[i]))
1896 /* recog_data.operand[i] is not in the right place. Find
1897 it and swap it with whatever is already in I's place.
1898 K is where recog_data.operand[i] is now. J is where it
1902 k = temp_stack.top - (regno - FIRST_STACK_REG);
1904 - (REGNO (recog_data.operand[i]) - FIRST_STACK_REG));
1906 temp = temp_stack.reg[k];
1907 temp_stack.reg[k] = temp_stack.reg[j];
1908 temp_stack.reg[j] = temp;
1912 /* Emit insns before INSN to make sure the reg-stack is in the right
1915 change_stack (insn, regstack, &temp_stack, EMIT_BEFORE);
1917 /* Make the needed input register substitutions. Do death notes and
1918 clobbers too, because these are for inputs, not outputs. */
1920 for (i = n_outputs; i < n_outputs + n_inputs; i++)
1921 if (STACK_REG_P (recog_data.operand[i]))
1923 int regnum = get_hard_regnum (regstack, recog_data.operand[i]);
1928 replace_reg (recog_data.operand_loc[i], regnum);
1931 for (i = 0; i < n_notes; i++)
1932 if (note_kind[i] == REG_DEAD)
1934 int regnum = get_hard_regnum (regstack, note_reg[i]);
1939 replace_reg (note_loc[i], regnum);
1942 for (i = 0; i < n_clobbers; i++)
1944 /* It's OK for a CLOBBER to reference a reg that is not live.
1945 Don't try to replace it in that case. */
1946 int regnum = get_hard_regnum (regstack, clobber_reg[i]);
1950 /* Sigh - clobbers always have QImode. But replace_reg knows
1951 that these regs can't be MODE_INT and will abort. Just put
1952 the right reg there without calling replace_reg. */
1954 *clobber_loc[i] = FP_MODE_REG (regnum, DFmode);
1958 /* Now remove from REGSTACK any inputs that the asm implicitly popped. */
1960 for (i = n_outputs; i < n_outputs + n_inputs; i++)
1961 if (STACK_REG_P (recog_data.operand[i]))
1963 /* An input reg is implicitly popped if it is tied to an
1964 output, or if there is a CLOBBER for it. */
1967 for (j = 0; j < n_clobbers; j++)
1968 if (operands_match_p (clobber_reg[j], recog_data.operand[i]))
1971 if (j < n_clobbers || recog_op_alt[i][alt].matches >= 0)
1973 /* recog_data.operand[i] might not be at the top of stack.
1974 But that's OK, because all we need to do is pop the
1975 right number of regs off of the top of the reg-stack.
1976 record_asm_stack_regs guaranteed that all implicitly
1977 popped regs were grouped at the top of the reg-stack. */
1979 CLEAR_HARD_REG_BIT (regstack->reg_set,
1980 regstack->reg[regstack->top]);
1985 /* Now add to REGSTACK any outputs that the asm implicitly pushed.
1986 Note that there isn't any need to substitute register numbers.
1987 ??? Explain why this is true. */
1989 for (i = LAST_STACK_REG; i >= FIRST_STACK_REG; i--)
1991 /* See if there is an output for this hard reg. */
1994 for (j = 0; j < n_outputs; j++)
1995 if (STACK_REG_P (recog_data.operand[j])
1996 && REGNO (recog_data.operand[j]) == i)
1998 regstack->reg[++regstack->top] = i;
1999 SET_HARD_REG_BIT (regstack->reg_set, i);
2004 /* Now emit a pop insn for any REG_UNUSED output, or any REG_DEAD
2005 input that the asm didn't implicitly pop. If the asm didn't
2006 implicitly pop an input reg, that reg will still be live.
2008 Note that we can't use find_regno_note here: the register numbers
2009 in the death notes have already been substituted. */
2011 for (i = 0; i < n_outputs; i++)
2012 if (STACK_REG_P (recog_data.operand[i]))
2016 for (j = 0; j < n_notes; j++)
2017 if (REGNO (recog_data.operand[i]) == REGNO (note_reg[j])
2018 && note_kind[j] == REG_UNUSED)
2020 insn = emit_pop_insn (insn, regstack, recog_data.operand[i],
2026 for (i = n_outputs; i < n_outputs + n_inputs; i++)
2027 if (STACK_REG_P (recog_data.operand[i]))
2031 for (j = 0; j < n_notes; j++)
2032 if (REGNO (recog_data.operand[i]) == REGNO (note_reg[j])
2033 && note_kind[j] == REG_DEAD
2034 && TEST_HARD_REG_BIT (regstack->reg_set,
2035 REGNO (recog_data.operand[i])))
2037 insn = emit_pop_insn (insn, regstack, recog_data.operand[i],
2044 /* Substitute stack hard reg numbers for stack virtual registers in
2045 INSN. Non-stack register numbers are not changed. REGSTACK is the
2046 current stack content. Insns may be emitted as needed to arrange the
2047 stack for the 387 based on the contents of the insn. */
2050 subst_stack_regs (insn, regstack)
2054 register rtx *note_link, note;
2057 if (GET_CODE (insn) == CALL_INSN)
2059 int top = regstack->top;
2061 /* If there are any floating point parameters to be passed in
2062 registers for this call, make sure they are in the right
2067 straighten_stack (PREV_INSN (insn), regstack);
2069 /* Now mark the arguments as dead after the call. */
2071 while (regstack->top >= 0)
2073 CLEAR_HARD_REG_BIT (regstack->reg_set, FIRST_STACK_REG + regstack->top);
2079 /* Do the actual substitution if any stack regs are mentioned.
2080 Since we only record whether entire insn mentions stack regs, and
2081 subst_stack_regs_pat only works for patterns that contain stack regs,
2082 we must check each pattern in a parallel here. A call_value_pop could
2085 if (stack_regs_mentioned (insn))
2087 int n_operands = asm_noperands (PATTERN (insn));
2088 if (n_operands >= 0)
2090 /* This insn is an `asm' with operands. Decode the operands,
2091 decide how many are inputs, and do register substitution.
2092 Any REG_UNUSED notes will be handled by subst_asm_stack_regs. */
2094 subst_asm_stack_regs (insn, regstack);
2098 if (GET_CODE (PATTERN (insn)) == PARALLEL)
2099 for (i = 0; i < XVECLEN (PATTERN (insn), 0); i++)
2101 if (stack_regs_mentioned_p (XVECEXP (PATTERN (insn), 0, i)))
2102 subst_stack_regs_pat (insn, regstack,
2103 XVECEXP (PATTERN (insn), 0, i));
2106 subst_stack_regs_pat (insn, regstack, PATTERN (insn));
2109 /* subst_stack_regs_pat may have deleted a no-op insn. If so, any
2110 REG_UNUSED will already have been dealt with, so just return. */
2112 if (GET_CODE (insn) == NOTE)
2115 /* If there is a REG_UNUSED note on a stack register on this insn,
2116 the indicated reg must be popped. The REG_UNUSED note is removed,
2117 since the form of the newly emitted pop insn references the reg,
2118 making it no longer `unset'. */
2120 note_link = ®_NOTES(insn);
2121 for (note = *note_link; note; note = XEXP (note, 1))
2122 if (REG_NOTE_KIND (note) == REG_UNUSED && STACK_REG_P (XEXP (note, 0)))
2124 *note_link = XEXP (note, 1);
2125 insn = emit_pop_insn (insn, regstack, XEXP (note, 0), EMIT_AFTER);
2128 note_link = &XEXP (note, 1);
2131 /* Change the organization of the stack so that it fits a new basic
2132 block. Some registers might have to be popped, but there can never be
2133 a register live in the new block that is not now live.
2135 Insert any needed insns before or after INSN, as indicated by
2136 WHERE. OLD is the original stack layout, and NEW is the desired
2137 form. OLD is updated to reflect the code emitted, ie, it will be
2138 the same as NEW upon return.
2140 This function will not preserve block_end[]. But that information
2141 is no longer needed once this has executed. */
2144 change_stack (insn, old, new, where)
2148 enum emit_where where;
2153 /* We will be inserting new insns "backwards". If we are to insert
2154 after INSN, find the next insn, and insert before it. */
2156 if (where == EMIT_AFTER)
2158 if (current_block && current_block->end == insn)
2160 insn = NEXT_INSN (insn);
2163 /* Pop any registers that are not needed in the new block. */
2165 for (reg = old->top; reg >= 0; reg--)
2166 if (! TEST_HARD_REG_BIT (new->reg_set, old->reg[reg]))
2167 emit_pop_insn (insn, old, FP_MODE_REG (old->reg[reg], DFmode),
2172 /* If the new block has never been processed, then it can inherit
2173 the old stack order. */
2175 new->top = old->top;
2176 memcpy (new->reg, old->reg, sizeof (new->reg));
2180 /* This block has been entered before, and we must match the
2181 previously selected stack order. */
2183 /* By now, the only difference should be the order of the stack,
2184 not their depth or liveliness. */
2186 GO_IF_HARD_REG_EQUAL (old->reg_set, new->reg_set, win);
2189 if (old->top != new->top)
2192 /* If the stack is not empty (new->top != -1), loop here emitting
2193 swaps until the stack is correct.
2195 The worst case number of swaps emitted is N + 2, where N is the
2196 depth of the stack. In some cases, the reg at the top of
2197 stack may be correct, but swapped anyway in order to fix
2198 other regs. But since we never swap any other reg away from
2199 its correct slot, this algorithm will converge. */
2204 /* Swap the reg at top of stack into the position it is
2205 supposed to be in, until the correct top of stack appears. */
2207 while (old->reg[old->top] != new->reg[new->top])
2209 for (reg = new->top; reg >= 0; reg--)
2210 if (new->reg[reg] == old->reg[old->top])
2216 emit_swap_insn (insn, old,
2217 FP_MODE_REG (old->reg[reg], DFmode));
2220 /* See if any regs remain incorrect. If so, bring an
2221 incorrect reg to the top of stack, and let the while loop
2224 for (reg = new->top; reg >= 0; reg--)
2225 if (new->reg[reg] != old->reg[reg])
2227 emit_swap_insn (insn, old,
2228 FP_MODE_REG (old->reg[reg], DFmode));
2233 /* At this point there must be no differences. */
2235 for (reg = old->top; reg >= 0; reg--)
2236 if (old->reg[reg] != new->reg[reg])
2241 current_block->end = PREV_INSN (insn);
2244 /* Print stack configuration. */
2247 print_stack (file, s)
2255 fprintf (file, "uninitialized\n");
2256 else if (s->top == -1)
2257 fprintf (file, "empty\n");
2262 for (i = 0; i <= s->top; ++i)
2263 fprintf (file, "%d ", s->reg[i]);
2264 fputs ("]\n", file);
2268 /* This function was doing life analysis. We now let the regular live
2269 code do it's job, so we only need to check some extra invariants
2270 that reg-stack expects. Primary among these being that all registers
2271 are initialized before use.
2273 The function returns true when code was emitted to CFG edges and
2274 commit_edge_insertions needs to be called. */
2277 convert_regs_entry ()
2279 int inserted = 0, i;
2282 for (i = n_basic_blocks - 1; i >= 0; --i)
2284 basic_block block = BASIC_BLOCK (i);
2285 block_info bi = BLOCK_INFO (block);
2288 /* Set current register status at last instruction `uninitialized'. */
2289 bi->stack_in.top = -2;
2291 /* Copy live_at_end and live_at_start into temporaries. */
2292 for (reg = FIRST_STACK_REG; reg <= LAST_STACK_REG; reg++)
2294 if (REGNO_REG_SET_P (block->global_live_at_end, reg))
2295 SET_HARD_REG_BIT (bi->out_reg_set, reg);
2296 if (REGNO_REG_SET_P (block->global_live_at_start, reg))
2297 SET_HARD_REG_BIT (bi->stack_in.reg_set, reg);
2301 /* Load something into each stack register live at function entry.
2302 Such live registers can be caused by uninitialized variables or
2303 functions not returning values on all paths. In order to keep
2304 the push/pop code happy, and to not scrog the register stack, we
2305 must put something in these registers. Use a QNaN.
2307 Note that we are insertting converted code here. This code is
2308 never seen by the convert_regs pass. */
2310 for (e = ENTRY_BLOCK_PTR->succ; e ; e = e->succ_next)
2312 basic_block block = e->dest;
2313 block_info bi = BLOCK_INFO (block);
2316 for (reg = LAST_STACK_REG; reg >= FIRST_STACK_REG; --reg)
2317 if (TEST_HARD_REG_BIT (bi->stack_in.reg_set, reg))
2321 bi->stack_in.reg[++top] = reg;
2323 init = gen_rtx_SET (VOIDmode,
2324 FP_MODE_REG (FIRST_STACK_REG, SFmode),
2326 insert_insn_on_edge (init, e);
2330 bi->stack_in.top = top;
2336 /* Construct the desired stack for function exit. This will either
2337 be `empty', or the function return value at top-of-stack. */
2340 convert_regs_exit ()
2342 int value_reg_low, value_reg_high;
2346 retvalue = stack_result (current_function_decl);
2347 value_reg_low = value_reg_high = -1;
2350 value_reg_low = REGNO (retvalue);
2351 value_reg_high = value_reg_low
2352 + HARD_REGNO_NREGS (value_reg_low, GET_MODE (retvalue)) - 1;
2355 output_stack = &BLOCK_INFO (EXIT_BLOCK_PTR)->stack_in;
2356 if (value_reg_low == -1)
2357 output_stack->top = -1;
2362 output_stack->top = value_reg_high - value_reg_low;
2363 for (reg = value_reg_low; reg <= value_reg_high; ++reg)
2365 output_stack->reg[reg - value_reg_low] = reg;
2366 SET_HARD_REG_BIT (output_stack->reg_set, reg);
2371 /* Convert stack register references in one block. */
2374 convert_regs_1 (file, block)
2378 struct stack_def regstack, tmpstack;
2379 block_info bi = BLOCK_INFO (block);
2384 current_block = block;
2388 fprintf (file, "\nBasic block %d\nInput stack: ", block->index);
2389 print_stack (file, &bi->stack_in);
2392 /* Process all insns in this block. Keep track of NEXT so that we
2393 don't process insns emitted while substituting in INSN. */
2395 regstack = bi->stack_in;
2399 next = NEXT_INSN (insn);
2401 /* Ensure we have not missed a block boundary. */
2404 if (insn == block->end)
2407 /* Don't bother processing unless there is a stack reg
2408 mentioned or if it's a CALL_INSN. */
2409 if (stack_regs_mentioned (insn)
2410 || GET_CODE (insn) == CALL_INSN)
2414 fprintf (file, " insn %d input stack: ",
2416 print_stack (file, ®stack);
2418 subst_stack_regs (insn, ®stack);
2425 fprintf (file, "Expected live registers [");
2426 for (reg = FIRST_STACK_REG; reg <= LAST_STACK_REG; ++reg)
2427 if (TEST_HARD_REG_BIT (bi->out_reg_set, reg))
2428 fprintf (file, " %d", reg);
2429 fprintf (file, " ]\nOutput stack: ");
2430 print_stack (file, ®stack);
2434 if (GET_CODE (insn) == JUMP_INSN)
2435 insn = PREV_INSN (insn);
2437 /* If the function is declared to return a value, but it returns one
2438 in only some cases, some registers might come live here. Emit
2439 necessary moves for them. */
2441 for (reg = FIRST_STACK_REG; reg <= LAST_STACK_REG; ++reg)
2443 if (TEST_HARD_REG_BIT (bi->out_reg_set, reg)
2444 && ! TEST_HARD_REG_BIT (regstack.reg_set, reg))
2450 fprintf (file, "Emitting insn initializing reg %d\n",
2454 set = gen_rtx_SET (VOIDmode, FP_MODE_REG (reg, SFmode),
2456 insn = emit_block_insn_after (set, insn, block);
2457 subst_stack_regs (insn, ®stack);
2461 /* Something failed if the stack lives don't match. */
2462 GO_IF_HARD_REG_EQUAL (regstack.reg_set, bi->out_reg_set, win);
2466 /* Adjust the stack of this block on exit to match the stack of the
2467 target block, or copy stack info into the stack of the successor
2468 of the successor hasn't been processed yet. */
2470 for (e = block->succ; e ; e = e->succ_next)
2472 basic_block target = e->dest;
2473 stack target_stack = &BLOCK_INFO (target)->stack_in;
2476 fprintf (file, "Edge to block %d: ", target->index);
2478 if (target_stack->top == -2)
2480 /* The target block hasn't had a stack order selected.
2481 We need merely ensure that no pops are needed. */
2482 for (reg = regstack.top; reg >= 0; --reg)
2483 if (! TEST_HARD_REG_BIT (target_stack->reg_set,
2490 fprintf (file, "new block; copying stack position\n");
2492 /* change_stack kills values in regstack. */
2493 tmpstack = regstack;
2495 change_stack (block->end, &tmpstack,
2496 target_stack, EMIT_AFTER);
2501 fprintf (file, "new block; pops needed\n");
2505 if (target_stack->top == regstack.top)
2507 for (reg = target_stack->top; reg >= 0; --reg)
2508 if (target_stack->reg[reg] != regstack.reg[reg])
2514 fprintf (file, "no changes needed\n");
2521 fprintf (file, "correcting stack to ");
2522 print_stack (file, target_stack);
2526 /* It is better to output directly to the end of the block
2527 instead of to the edge, because emit_swap can do minimal
2528 insn scheduling. We can do this when there is only one
2529 edge out, and it is not abnormal. */
2530 if (block->succ->succ_next == NULL
2531 && ! (e->flags & EDGE_ABNORMAL))
2533 /* change_stack kills values in regstack. */
2534 tmpstack = regstack;
2536 change_stack (block->end, &tmpstack, target_stack,
2537 (GET_CODE (block->end) == JUMP_INSN
2538 ? EMIT_BEFORE : EMIT_AFTER));
2544 /* We don't support abnormal edges. Global takes
2545 care to avoid any live register across them, so
2546 we should never have to. */
2547 if (e->flags & EDGE_ABNORMAL)
2550 current_block = NULL;
2553 /* ??? change_stack needs some point to emit insns after.
2554 Also needed to keep gen_sequence from returning a
2555 pattern as opposed to a sequence, which would lose
2557 after = emit_note (NULL, NOTE_INSN_DELETED);
2559 tmpstack = regstack;
2560 change_stack (after, &tmpstack, target_stack, EMIT_BEFORE);
2562 seq = gen_sequence ();
2565 insert_insn_on_edge (seq, e);
2567 current_block = block;
2574 /* Convert registers in all blocks reachable from BLOCK. */
2577 convert_regs_2 (file, block)
2581 basic_block *stack, *sp;
2584 stack = (basic_block *) alloca (sizeof (*stack) * n_basic_blocks);
2588 BLOCK_INFO (block)->done = 1;
2596 inserted |= convert_regs_1 (file, block);
2598 for (e = block->succ; e ; e = e->succ_next)
2599 if (! BLOCK_INFO (e->dest)->done)
2602 BLOCK_INFO (e->dest)->done = 1;
2605 while (sp != stack);
2610 /* Traverse all basic blocks in a function, converting the register
2611 references in each insn from the "flat" register file that gcc uses,
2612 to the stack-like registers the 387 uses. */
2621 /* Initialize uninitialized registers on function entry. */
2622 inserted = convert_regs_entry ();
2624 /* Construct the desired stack for function exit. */
2625 convert_regs_exit ();
2626 BLOCK_INFO (EXIT_BLOCK_PTR)->done = 1;
2628 /* ??? Future: process inner loops first, and give them arbitrary
2629 initial stacks which emit_swap_insn can modify. This ought to
2630 prevent double fxch that aften appears at the head of a loop. */
2632 /* Process all blocks reachable from all entry points. */
2633 for (e = ENTRY_BLOCK_PTR->succ; e ; e = e->succ_next)
2634 inserted |= convert_regs_2 (file, e->dest);
2636 /* ??? Process all unreachable blocks. Though there's no excuse
2637 for keeping these even when not optimizing. */
2638 for (i = 0; i < n_basic_blocks; ++i)
2640 basic_block b = BASIC_BLOCK (i);
2641 block_info bi = BLOCK_INFO (b);
2647 /* Create an arbitrary input stack. */
2648 bi->stack_in.top = -1;
2649 for (reg = LAST_STACK_REG; reg >= FIRST_STACK_REG; --reg)
2650 if (TEST_HARD_REG_BIT (bi->stack_in.reg_set, reg))
2651 bi->stack_in.reg[++bi->stack_in.top] = reg;
2653 inserted |= convert_regs_2 (file, b);
2658 commit_edge_insertions ();
2665 #endif /* STACK_REGS */