Line data Source code
1 : /* Register to Stack convert for GNU compiler.
2 : Copyright (C) 1992-2026 Free Software Foundation, Inc.
3 :
4 : This file is part of GCC.
5 :
6 : GCC is free software; you can redistribute it and/or modify it
7 : under the terms of the GNU General Public License as published by
8 : the Free Software Foundation; either version 3, or (at your option)
9 : any later version.
10 :
11 : GCC is distributed in the hope that it will be useful, but WITHOUT
12 : ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 : or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14 : License for more details.
15 :
16 : You should have received a copy of the GNU General Public License
17 : along with GCC; see the file COPYING3. If not see
18 : <http://www.gnu.org/licenses/>. */
19 :
20 : /* This pass converts stack-like registers from the "flat register
21 : file" model that gcc uses, to a stack convention that the 387 uses.
22 :
23 : * The form of the input:
24 :
25 : On input, the function consists of insn that have had their
26 : registers fully allocated to a set of "virtual" registers. Note that
27 : the word "virtual" is used differently here than elsewhere in gcc: for
28 : each virtual stack reg, there is a hard reg, but the mapping between
29 : them is not known until this pass is run. On output, hard register
30 : numbers have been substituted, and various pop and exchange insns have
31 : been emitted. The hard register numbers and the virtual register
32 : numbers completely overlap - before this pass, all stack register
33 : numbers are virtual, and afterward they are all hard.
34 :
35 : The virtual registers can be manipulated normally by gcc, and their
36 : semantics are the same as for normal registers. After the hard
37 : register numbers are substituted, the semantics of an insn containing
38 : stack-like regs are not the same as for an insn with normal regs: for
39 : instance, it is not safe to delete an insn that appears to be a no-op
40 : move. In general, no insn containing hard regs should be changed
41 : after this pass is done.
42 :
43 : * The form of the output:
44 :
45 : After this pass, hard register numbers represent the distance from
46 : the current top of stack to the desired register. A reference to
47 : FIRST_STACK_REG references the top of stack, FIRST_STACK_REG + 1,
48 : represents the register just below that, and so forth. Also, REG_DEAD
49 : notes indicate whether or not a stack register should be popped.
50 :
51 : A "swap" insn looks like a parallel of two patterns, where each
52 : pattern is a SET: one sets A to B, the other B to A.
53 :
54 : A "push" or "load" insn is a SET whose SET_DEST is FIRST_STACK_REG
55 : and whose SET_DEST is REG or MEM. Any other SET_DEST, such as PLUS,
56 : will replace the existing stack top, not push a new value.
57 :
58 : A store insn is a SET whose SET_DEST is FIRST_STACK_REG, and whose
59 : SET_SRC is REG or MEM.
60 :
61 : The case where the SET_SRC and SET_DEST are both FIRST_STACK_REG
62 : appears ambiguous. As a special case, the presence of a REG_DEAD note
63 : for FIRST_STACK_REG differentiates between a load insn and a pop.
64 :
65 : If a REG_DEAD is present, the insn represents a "pop" that discards
66 : the top of the register stack. If there is no REG_DEAD note, then the
67 : insn represents a "dup" or a push of the current top of stack onto the
68 : stack.
69 :
70 : * Methodology:
71 :
72 : Existing REG_DEAD and REG_UNUSED notes for stack registers are
73 : deleted and recreated from scratch. REG_DEAD is never created for a
74 : SET_DEST, only REG_UNUSED.
75 :
76 : * asm_operands:
77 :
78 : There are several rules on the usage of stack-like regs in
79 : asm_operands insns. These rules apply only to the operands that are
80 : stack-like regs:
81 :
82 : 1. Given a set of input regs that die in an asm_operands, it is
83 : necessary to know which are implicitly popped by the asm, and
84 : which must be explicitly popped by gcc.
85 :
86 : An input reg that is implicitly popped by the asm must be
87 : explicitly clobbered, unless it is constrained to match an
88 : output operand.
89 :
90 : 2. For any input reg that is implicitly popped by an asm, it is
91 : necessary to know how to adjust the stack to compensate for the pop.
92 : If any non-popped input is closer to the top of the reg-stack than
93 : the implicitly popped reg, it would not be possible to know what the
94 : stack looked like - it's not clear how the rest of the stack "slides
95 : up".
96 :
97 : All implicitly popped input regs must be closer to the top of
98 : the reg-stack than any input that is not implicitly popped.
99 :
100 : All explicitly referenced input operands may not "skip" a reg.
101 : Otherwise we can have holes in the stack.
102 :
103 : 3. It is possible that if an input dies in an insn, reload might
104 : use the input reg for an output reload. Consider this example:
105 :
106 : asm ("foo" : "=t" (a) : "f" (b));
107 :
108 : This asm says that input B is not popped by the asm, and that
109 : the asm pushes a result onto the reg-stack, i.e., the stack is one
110 : deeper after the asm than it was before. But, it is possible that
111 : reload will think that it can use the same reg for both the input and
112 : the output, if input B dies in this insn.
113 :
114 : If any input operand uses the "f" constraint, all output reg
115 : constraints must use the "&" earlyclobber.
116 :
117 : The asm above would be written as
118 :
119 : asm ("foo" : "=&t" (a) : "f" (b));
120 :
121 : 4. Some operands need to be in particular places on the stack. All
122 : output operands fall in this category - there is no other way to
123 : know which regs the outputs appear in unless the user indicates
124 : this in the constraints.
125 :
126 : Output operands must specifically indicate which reg an output
127 : appears in after an asm. "=f" is not allowed: the operand
128 : constraints must select a class with a single reg.
129 :
130 : 5. Output operands may not be "inserted" between existing stack regs.
131 : Since no 387 opcode uses a read/write operand, all output operands
132 : are dead before the asm_operands, and are pushed by the asm_operands.
133 : It makes no sense to push anywhere but the top of the reg-stack.
134 :
135 : Output operands must start at the top of the reg-stack: output
136 : operands may not "skip" a reg.
137 :
138 : 6. Some asm statements may need extra stack space for internal
139 : calculations. This can be guaranteed by clobbering stack registers
140 : unrelated to the inputs and outputs.
141 :
142 : 7. Each operand must occupy a single register. Operands that
143 : need more, such as complex values, which take two, are not
144 : supported.
145 :
146 : Here are a couple of reasonable asms to want to write. This asm
147 : takes one input, which is internally popped, and produces two outputs.
148 :
149 : asm ("fsincos" : "=t" (cos), "=u" (sin) : "0" (inp));
150 :
151 : This asm takes two inputs, which are popped by the fyl2xp1 opcode, and
152 : replaces them with one output. The user must code the "st(1)" clobber
153 : for the register stack pass to know that fyl2xp1 pops both inputs.
154 :
155 : asm ("fyl2xp1" : "=t" (result) : "0" (x), "u" (y) : "st(1)");
156 :
157 : */
158 :
159 : #include "config.h"
160 : #include "system.h"
161 : #include "coretypes.h"
162 : #include "backend.h"
163 : #include "target.h"
164 : #include "rtl.h"
165 : #include "tree.h"
166 : #include "df.h"
167 : #include "tm_p.h"
168 : #include "insn-config.h"
169 : #include "memmodel.h"
170 : #include "regs.h"
171 : #include "emit-rtl.h" /* FIXME: Can go away once crtl is moved to rtl.h. */
172 : #include "recog.h"
173 : #include "varasm.h"
174 : #include "rtl-error.h"
175 : #include "cfgrtl.h"
176 : #include "cfganal.h"
177 : #include "cfgbuild.h"
178 : #include "cfgcleanup.h"
179 : #include "reload.h"
180 : #include "tree-pass.h"
181 : #include "rtl-iter.h"
182 : #include "function-abi.h"
183 :
184 : /* We use this array to cache info about insns, because otherwise we
185 : spend too much time in stack_regs_mentioned_p.
186 :
187 : Indexed by insn UIDs. A value of zero is uninitialized, one indicates
188 : the insn uses stack registers, two indicates the insn does not use
189 : stack registers. */
190 : static vec<char> stack_regs_mentioned_data;
191 :
192 : #define REG_STACK_SIZE (LAST_STACK_REG - FIRST_STACK_REG + 1)
193 :
194 : bool regstack_completed = false;
195 :
196 : /* This is the basic stack record. TOP is an index into REG[] such
197 : that REG[TOP] is the top of stack. If TOP is -1 the stack is empty.
198 :
199 : If TOP is -2, REG[] is not yet initialized. Stack initialization
200 : consists of placing each live reg in array `reg' and setting `top'
201 : appropriately.
202 :
203 : REG_SET indicates which registers are live. */
204 :
205 : typedef struct stack_def
206 : {
207 : int top; /* index to top stack element */
208 : HARD_REG_SET reg_set; /* set of live registers */
209 : unsigned char reg[REG_STACK_SIZE];/* register - stack mapping */
210 : } *stack_ptr;
211 :
212 : /* This is used to carry information about basic blocks. It is
213 : attached to the AUX field of the standard CFG block. */
214 :
215 : typedef struct block_info_def
216 : {
217 : struct stack_def stack_in; /* Input stack configuration. */
218 : struct stack_def stack_out; /* Output stack configuration. */
219 : HARD_REG_SET out_reg_set; /* Stack regs live on output. */
220 : bool done; /* True if block already converted. */
221 : int predecessors; /* Number of predecessors that need
222 : to be visited. */
223 : } *block_info;
224 :
225 : #define BLOCK_INFO(B) ((block_info) (B)->aux)
226 :
227 : /* Passed to change_stack to indicate where to emit insns. */
228 : enum emit_where
229 : {
230 : EMIT_AFTER,
231 : EMIT_BEFORE
232 : };
233 :
234 : /* The block we're currently working on. */
235 : static basic_block current_block;
236 :
237 : /* In the current_block, whether we're processing the first register
238 : stack or call instruction, i.e. the regstack is currently the
239 : same as BLOCK_INFO(current_block)->stack_in. */
240 : static bool starting_stack_p;
241 :
242 : /* This is the register file for all register after conversion. */
243 : static rtx
244 : FP_mode_reg[LAST_STACK_REG+1-FIRST_STACK_REG][(int) MAX_MACHINE_MODE];
245 :
246 : #define FP_MODE_REG(regno,mode) \
247 : (FP_mode_reg[(regno)-FIRST_STACK_REG][(int) (mode)])
248 :
249 : /* Used to initialize uninitialized registers. */
250 : static rtx not_a_num;
251 :
252 : /* Forward declarations */
253 :
254 : static bool stack_regs_mentioned_p (const_rtx pat);
255 : static void pop_stack (stack_ptr, int);
256 : static rtx *get_true_reg (rtx *);
257 :
258 : static bool check_asm_stack_operands (rtx_insn *);
259 : static void get_asm_operands_in_out (rtx, int *, int *);
260 : static rtx stack_result (tree);
261 : static void replace_reg (rtx *, int);
262 : static void remove_regno_note (rtx_insn *, enum reg_note, unsigned int);
263 : static int get_hard_regnum (stack_ptr, rtx);
264 : static rtx_insn *emit_pop_insn (rtx_insn *, stack_ptr, rtx, enum emit_where);
265 : static void swap_to_top (rtx_insn *, stack_ptr, rtx, rtx);
266 : static bool move_for_stack_reg (rtx_insn *, stack_ptr, rtx);
267 : static bool move_nan_for_stack_reg (rtx_insn *, stack_ptr, rtx);
268 : static bool swap_rtx_condition_1 (rtx);
269 : static bool swap_rtx_condition (rtx_insn *, int &);
270 : static void compare_for_stack_reg (rtx_insn *, stack_ptr, rtx, bool);
271 : static bool subst_stack_regs_pat (rtx_insn *, stack_ptr, rtx);
272 : static void subst_asm_stack_regs (rtx_insn *, stack_ptr);
273 : static bool subst_stack_regs (rtx_insn *, stack_ptr);
274 : static void change_stack (rtx_insn *, stack_ptr, stack_ptr, enum emit_where);
275 : static void print_stack (FILE *, stack_ptr);
276 : static rtx_insn *next_flags_user (rtx_insn *, int &);
277 :
278 : /* Return true if any stack register is mentioned somewhere within PAT. */
279 :
280 : static bool
281 51757157 : stack_regs_mentioned_p (const_rtx pat)
282 : {
283 51757157 : const char *fmt;
284 51757157 : int i;
285 :
286 51757157 : if (STACK_REG_P (pat))
287 : return true;
288 :
289 50962332 : fmt = GET_RTX_FORMAT (GET_CODE (pat));
290 122781575 : for (i = GET_RTX_LENGTH (GET_CODE (pat)) - 1; i >= 0; i--)
291 : {
292 72981821 : if (fmt[i] == 'E')
293 : {
294 1476823 : int j;
295 :
296 4045462 : for (j = XVECLEN (pat, i) - 1; j >= 0; j--)
297 2709798 : if (stack_regs_mentioned_p (XVECEXP (pat, i, j)))
298 : return true;
299 : }
300 71504998 : else if (fmt[i] == 'e' && stack_regs_mentioned_p (XEXP (pat, i)))
301 : return true;
302 : }
303 :
304 : return false;
305 : }
306 :
307 : /* Return true if INSN mentions stacked registers, else return zero. */
308 :
309 : bool
310 11878441 : stack_regs_mentioned (const rtx_insn *insn)
311 : {
312 11878441 : unsigned int uid, max;
313 11878441 : int test;
314 :
315 11878441 : if (! INSN_P (insn) || !stack_regs_mentioned_data.exists ())
316 : return false;
317 :
318 9872242 : uid = INSN_UID (insn);
319 9872242 : max = stack_regs_mentioned_data.length ();
320 9872242 : if (uid >= max)
321 : {
322 : /* Allocate some extra size to avoid too many reallocs, but
323 : do not grow too quickly. */
324 135328 : max = uid + uid / 20 + 1;
325 135328 : stack_regs_mentioned_data.safe_grow_cleared (max, true);
326 : }
327 :
328 9872242 : test = stack_regs_mentioned_data[uid];
329 9872242 : if (test == 0)
330 : {
331 : /* This insn has yet to be examined. Do so now. */
332 8927717 : test = stack_regs_mentioned_p (PATTERN (insn)) ? 1 : 2;
333 8927717 : stack_regs_mentioned_data[uid] = test;
334 : }
335 :
336 9872242 : return test == 1;
337 : }
338 :
339 : static rtx ix86_flags_rtx;
340 :
341 : static rtx_insn *
342 94560 : next_flags_user (rtx_insn *insn, int &debug_seen)
343 : {
344 : /* Search forward looking for the first use of this value.
345 : Stop at block boundaries. */
346 :
347 96330 : while (insn != BB_END (current_block))
348 : {
349 83981 : insn = NEXT_INSN (insn);
350 :
351 83981 : if (INSN_P (insn) && reg_mentioned_p (ix86_flags_rtx, PATTERN (insn)))
352 : {
353 82228 : if (DEBUG_INSN_P (insn) && debug_seen >= 0)
354 : {
355 18 : debug_seen = 1;
356 18 : continue;
357 : }
358 : return insn;
359 : }
360 :
361 1753 : if (CALL_P (insn))
362 : return NULL;
363 : }
364 : return NULL;
365 : }
366 :
367 : /* Reorganize the stack into ascending numbers, before this insn. */
368 :
369 : static void
370 0 : straighten_stack (rtx_insn *insn, stack_ptr regstack)
371 : {
372 0 : struct stack_def temp_stack;
373 0 : int top;
374 :
375 : /* If there is only a single register on the stack, then the stack is
376 : already in increasing order and no reorganization is needed.
377 :
378 : Similarly if the stack is empty. */
379 0 : if (regstack->top <= 0)
380 0 : return;
381 :
382 0 : temp_stack.reg_set = regstack->reg_set;
383 :
384 0 : for (top = temp_stack.top = regstack->top; top >= 0; top--)
385 0 : temp_stack.reg[top] = FIRST_STACK_REG + temp_stack.top - top;
386 :
387 0 : change_stack (insn, regstack, &temp_stack, EMIT_BEFORE);
388 : }
389 :
390 : /* Pop a register from the stack. */
391 :
392 : static void
393 90046 : pop_stack (stack_ptr regstack, int regno)
394 : {
395 90046 : int top = regstack->top;
396 :
397 90046 : CLEAR_HARD_REG_BIT (regstack->reg_set, regno);
398 90046 : regstack->top--;
399 : /* If regno was not at the top of stack then adjust stack. */
400 90046 : if (regstack->reg [top] != regno)
401 : {
402 : int i;
403 0 : for (i = regstack->top; i >= 0; i--)
404 0 : if (regstack->reg [i] == regno)
405 : {
406 : int j;
407 0 : for (j = i; j < top; j++)
408 0 : regstack->reg [j] = regstack->reg [j + 1];
409 : break;
410 : }
411 : }
412 90046 : }
413 :
414 : /* Return a pointer to the REG expression within PAT. If PAT is not a
415 : REG, possible enclosed by a conversion rtx, return the inner part of
416 : PAT that stopped the search. */
417 :
418 : static rtx *
419 2837512 : get_true_reg (rtx *pat)
420 : {
421 2929909 : for (;;)
422 2929909 : switch (GET_CODE (*pat))
423 : {
424 0 : case SUBREG:
425 : /* Eliminate FP subregister accesses in favor of the
426 : actual FP register in use. */
427 0 : {
428 0 : rtx subreg = SUBREG_REG (*pat);
429 :
430 0 : if (STACK_REG_P (subreg))
431 : {
432 0 : int regno_off = subreg_regno_offset (REGNO (subreg),
433 0 : GET_MODE (subreg),
434 0 : SUBREG_BYTE (*pat),
435 0 : GET_MODE (*pat));
436 0 : *pat = FP_MODE_REG (REGNO (subreg) + regno_off,
437 : GET_MODE (subreg));
438 0 : return pat;
439 : }
440 0 : pat = &XEXP (*pat, 0);
441 0 : break;
442 : }
443 :
444 7997 : case FLOAT_TRUNCATE:
445 7997 : if (!flag_unsafe_math_optimizations)
446 : return pat;
447 : /* FALLTHRU */
448 :
449 92397 : case FLOAT:
450 92397 : case FIX:
451 92397 : case FLOAT_EXTEND:
452 92397 : pat = &XEXP (*pat, 0);
453 92397 : break;
454 :
455 114853 : case UNSPEC:
456 114853 : if (XINT (*pat, 1) == UNSPEC_TRUNC_NOOP
457 114549 : || XINT (*pat, 1) == UNSPEC_FILD_ATOMIC)
458 304 : pat = &XVECEXP (*pat, 0, 0);
459 : return pat;
460 :
461 : default:
462 : return pat;
463 : }
464 : }
465 :
466 : /* Set if we find any malformed asms in a function. */
467 : static bool any_malformed_asm;
468 :
469 : /* There are many rules that an asm statement for stack-like regs must
470 : follow. Those rules are explained at the top of this file: the rule
471 : numbers below refer to that explanation. */
472 :
473 : static bool
474 119 : check_asm_stack_operands (rtx_insn *insn)
475 : {
476 119 : int i;
477 119 : int n_clobbers;
478 119 : bool malformed_asm = false;
479 119 : rtx body = PATTERN (insn);
480 :
481 119 : char reg_used_as_output[FIRST_PSEUDO_REGISTER];
482 119 : char implicitly_dies[FIRST_PSEUDO_REGISTER];
483 119 : char explicitly_used[FIRST_PSEUDO_REGISTER];
484 :
485 119 : rtx *clobber_reg = 0;
486 119 : int n_inputs, n_outputs;
487 :
488 : /* Find out what the constraints require. If no constraint
489 : alternative matches, this asm is malformed. */
490 119 : extract_constrain_insn (insn);
491 :
492 119 : preprocess_constraints (insn);
493 :
494 119 : get_asm_operands_in_out (body, &n_outputs, &n_inputs);
495 :
496 119 : if (which_alternative < 0)
497 : {
498 : /* Avoid further trouble with this insn. */
499 0 : PATTERN (insn) = gen_rtx_USE (VOIDmode, const0_rtx);
500 0 : return 0;
501 : }
502 119 : const operand_alternative *op_alt = which_op_alt ();
503 :
504 : /* Strip SUBREGs here to make the following code simpler. */
505 495 : for (i = 0; i < recog_data.n_operands; i++)
506 257 : if (GET_CODE (recog_data.operand[i]) == SUBREG
507 0 : && REG_P (SUBREG_REG (recog_data.operand[i])))
508 0 : recog_data.operand[i] = SUBREG_REG (recog_data.operand[i]);
509 :
510 : /* Enforce rule #7: Operands must occupy a single register. */
511 :
512 376 : for (i = 0; i < recog_data.n_operands; i++)
513 233 : if (STACK_REG_P (recog_data.operand[i])
514 488 : && REG_NREGS (recog_data.operand[i]) > 1)
515 : {
516 1 : error_for_asm (insn, "operand %d must occupy a single register", i);
517 1 : malformed_asm = true;
518 : }
519 :
520 : /* Set up CLOBBER_REG. */
521 :
522 119 : n_clobbers = 0;
523 :
524 119 : if (GET_CODE (body) == PARALLEL)
525 : {
526 119 : clobber_reg = XALLOCAVEC (rtx, XVECLEN (body, 0));
527 :
528 370 : for (i = 0; i < XVECLEN (body, 0); i++)
529 251 : if (GET_CODE (XVECEXP (body, 0, i)) == CLOBBER)
530 : {
531 129 : rtx clobber = XVECEXP (body, 0, i);
532 129 : rtx reg = XEXP (clobber, 0);
533 :
534 129 : if (GET_CODE (reg) == SUBREG && REG_P (SUBREG_REG (reg)))
535 129 : reg = SUBREG_REG (reg);
536 :
537 129 : if (STACK_REG_P (reg))
538 : {
539 10 : clobber_reg[n_clobbers] = reg;
540 10 : n_clobbers++;
541 : }
542 : }
543 : }
544 :
545 : /* Enforce rule #4: Output operands must specifically indicate which
546 : reg an output appears in after an asm. "=f" is not allowed: the
547 : operand constraints must select a class with a single reg.
548 :
549 : Also enforce rule #5: Output operands must start at the top of
550 : the reg-stack: output operands may not "skip" a reg. */
551 :
552 119 : memset (reg_used_as_output, 0, sizeof (reg_used_as_output));
553 222 : for (i = 0; i < n_outputs; i++)
554 103 : if (STACK_REG_P (recog_data.operand[i]))
555 : {
556 102 : if (reg_class_size[(int) op_alt[i].cl] != 1)
557 : {
558 16 : error_for_asm (insn, "output constraint %d must "
559 : "specify a single register", i);
560 16 : malformed_asm = true;
561 : }
562 : else
563 : {
564 : int j;
565 :
566 94 : for (j = 0; j < n_clobbers; j++)
567 8 : if (REGNO (recog_data.operand[i]) == REGNO (clobber_reg[j]))
568 : {
569 0 : error_for_asm (insn, "output constraint %d cannot be "
570 : "specified together with %qs clobber",
571 0 : i, reg_names [REGNO (clobber_reg[j])]);
572 0 : malformed_asm = true;
573 0 : break;
574 : }
575 86 : if (j == n_clobbers)
576 86 : reg_used_as_output[REGNO (recog_data.operand[i])] = 1;
577 : }
578 : }
579 :
580 :
581 : /* Search for first non-popped reg. */
582 204 : for (i = FIRST_STACK_REG; i < LAST_STACK_REG + 1; i++)
583 204 : if (! reg_used_as_output[i])
584 : break;
585 :
586 : /* If there are any other popped regs, that's an error. */
587 979 : for (; i < LAST_STACK_REG + 1; i++)
588 861 : if (reg_used_as_output[i])
589 : break;
590 :
591 119 : if (i != LAST_STACK_REG + 1)
592 : {
593 1 : error_for_asm (insn, "output registers must be grouped at top of stack");
594 1 : malformed_asm = true;
595 : }
596 :
597 : /* Enforce rule #2: All implicitly popped input regs must be closer
598 : to the top of the reg-stack than any input that is not implicitly
599 : popped. */
600 :
601 119 : memset (implicitly_dies, 0, sizeof (implicitly_dies));
602 119 : memset (explicitly_used, 0, sizeof (explicitly_used));
603 273 : for (i = n_outputs; i < n_outputs + n_inputs; i++)
604 154 : if (STACK_REG_P (recog_data.operand[i]))
605 : {
606 : /* An input reg is implicitly popped if it is tied to an
607 : output, or if there is a CLOBBER for it. */
608 : int j;
609 :
610 137 : for (j = 0; j < n_clobbers; j++)
611 17 : if (operands_match_p (clobber_reg[j], recog_data.operand[i]))
612 : break;
613 :
614 129 : if (j < n_clobbers || op_alt[i].matches >= 0)
615 107 : implicitly_dies[REGNO (recog_data.operand[i])] = 1;
616 22 : else if (reg_class_size[(int) op_alt[i].cl] == 1)
617 4 : explicitly_used[REGNO (recog_data.operand[i])] = 1;
618 : }
619 :
620 : /* Search for first non-popped reg. */
621 226 : for (i = FIRST_STACK_REG; i < LAST_STACK_REG + 1; i++)
622 226 : if (! implicitly_dies[i])
623 : break;
624 :
625 : /* If there are any other popped regs, that's an error. */
626 964 : for (; i < LAST_STACK_REG + 1; i++)
627 845 : if (implicitly_dies[i])
628 : break;
629 :
630 119 : if (i != LAST_STACK_REG + 1)
631 : {
632 0 : error_for_asm (insn,
633 : "implicitly popped registers must be grouped "
634 : "at top of stack");
635 0 : malformed_asm = true;
636 : }
637 :
638 : /* Search for first not-explicitly used reg. */
639 229 : for (i = FIRST_STACK_REG; i < LAST_STACK_REG + 1; i++)
640 229 : if (! implicitly_dies[i] && ! explicitly_used[i])
641 : break;
642 :
643 : /* If there are any other explicitly used regs, that's an error. */
644 954 : for (; i < LAST_STACK_REG + 1; i++)
645 836 : if (explicitly_used[i])
646 : break;
647 :
648 119 : if (i != LAST_STACK_REG + 1)
649 : {
650 1 : error_for_asm (insn,
651 : "explicitly used registers must be grouped "
652 : "at top of stack");
653 1 : malformed_asm = true;
654 : }
655 :
656 : /* Enforce rule #3: If any input operand uses the "f" constraint, all
657 : output constraints must use the "&" earlyclobber.
658 :
659 : ??? Detect this more deterministically by having constrain_asm_operands
660 : record any earlyclobber. */
661 :
662 273 : for (i = n_outputs; i < n_outputs + n_inputs; i++)
663 154 : if (STACK_REG_P (recog_data.operand[i]) && op_alt[i].matches == -1)
664 : {
665 : int j;
666 :
667 44 : for (j = 0; j < n_outputs; j++)
668 13 : if (operands_match_p (recog_data.operand[j], recog_data.operand[i]))
669 : {
670 0 : error_for_asm (insn,
671 : "output operand %d must use %<&%> constraint", j);
672 0 : malformed_asm = true;
673 : }
674 : }
675 :
676 119 : if (malformed_asm)
677 : {
678 : /* Avoid further trouble with this insn. */
679 19 : PATTERN (insn) = gen_rtx_USE (VOIDmode, const0_rtx);
680 19 : any_malformed_asm = true;
681 19 : return false;
682 : }
683 :
684 : return true;
685 : }
686 :
687 : /* Calculate the number of inputs and outputs in BODY, an
688 : asm_operands. N_OPERANDS is the total number of operands, and
689 : N_INPUTS and N_OUTPUTS are pointers to ints into which the results are
690 : placed. */
691 :
692 : static void
693 219 : get_asm_operands_in_out (rtx body, int *pout, int *pin)
694 : {
695 219 : rtx asmop = extract_asm_operands (body);
696 :
697 219 : *pin = ASM_OPERANDS_INPUT_LENGTH (asmop);
698 219 : *pout = (recog_data.n_operands
699 219 : - ASM_OPERANDS_INPUT_LENGTH (asmop)
700 219 : - ASM_OPERANDS_LABEL_LENGTH (asmop));
701 219 : }
702 :
703 : /* If current function returns its result in an fp stack register,
704 : return the REG. Otherwise, return 0. */
705 :
706 : static rtx
707 35263 : stack_result (tree decl)
708 : {
709 35263 : rtx result;
710 :
711 : /* If the value is supposed to be returned in memory, then clearly
712 : it is not returned in a stack register. */
713 35263 : if (aggregate_value_p (DECL_RESULT (decl), decl))
714 : return 0;
715 :
716 33419 : result = DECL_RTL_IF_SET (DECL_RESULT (decl));
717 8865 : if (result != 0)
718 8865 : result = targetm.calls.function_value (TREE_TYPE (DECL_RESULT (decl)),
719 : decl, true);
720 :
721 33419 : return result != 0 && STACK_REG_P (result) ? result : 0;
722 : }
723 :
724 :
725 : /*
726 : * This section deals with stack register substitution, and forms the second
727 : * pass over the RTL.
728 : */
729 :
730 : /* Replace REG, which is a pointer to a stack reg RTX, with an RTX for
731 : the desired hard REGNO. */
732 :
733 : static void
734 1284578 : replace_reg (rtx *reg, int regno)
735 : {
736 1284578 : gcc_assert (IN_RANGE (regno, FIRST_STACK_REG, LAST_STACK_REG));
737 1284578 : gcc_assert (STACK_REG_P (*reg));
738 :
739 1284578 : gcc_assert (GET_MODE_CLASS (GET_MODE (*reg)) == MODE_FLOAT
740 : || GET_MODE_CLASS (GET_MODE (*reg)) == MODE_COMPLEX_FLOAT);
741 :
742 1284578 : *reg = FP_MODE_REG (regno, GET_MODE (*reg));
743 1284578 : }
744 :
745 : /* Remove a note of type NOTE, which must be found, for register
746 : number REGNO from INSN. Remove only one such note. */
747 :
748 : static void
749 72082 : remove_regno_note (rtx_insn *insn, enum reg_note note, unsigned int regno)
750 : {
751 72082 : rtx *note_link, this_rtx;
752 :
753 72082 : note_link = ®_NOTES (insn);
754 81392 : for (this_rtx = *note_link; this_rtx; this_rtx = XEXP (this_rtx, 1))
755 81392 : if (REG_NOTE_KIND (this_rtx) == note
756 81392 : && REG_P (XEXP (this_rtx, 0)) && REGNO (XEXP (this_rtx, 0)) == regno)
757 : {
758 72082 : *note_link = XEXP (this_rtx, 1);
759 72082 : return;
760 : }
761 : else
762 9310 : note_link = &XEXP (this_rtx, 1);
763 :
764 0 : gcc_unreachable ();
765 : }
766 :
767 : /* Find the hard register number of virtual register REG in REGSTACK.
768 : The hard register number is relative to the top of the stack. -1 is
769 : returned if the register is not found. */
770 :
771 : static int
772 1501685 : get_hard_regnum (stack_ptr regstack, rtx reg)
773 : {
774 1501685 : int i;
775 :
776 1501685 : gcc_assert (STACK_REG_P (reg));
777 :
778 2611543 : for (i = regstack->top; i >= 0; i--)
779 2300181 : if (regstack->reg[i] == REGNO (reg))
780 : break;
781 :
782 1501685 : return i >= 0 ? (FIRST_STACK_REG + regstack->top - i) : -1;
783 : }
784 :
785 : /* Emit an insn to pop virtual register REG before or after INSN.
786 : REGSTACK is the stack state after INSN and is updated to reflect this
787 : pop. WHEN is either emit_insn_before or emit_insn_after. A pop insn
788 : is represented as a SET whose destination is the register to be popped
789 : and source is the top of stack. A death note for the top of stack
790 : cases the movdf pattern to pop. */
791 :
792 : static rtx_insn *
793 293253 : emit_pop_insn (rtx_insn *insn, stack_ptr regstack, rtx reg,
794 : enum emit_where where)
795 : {
796 293253 : machine_mode raw_mode = reg_raw_mode[FIRST_STACK_REG];
797 293253 : rtx_insn *pop_insn;
798 293253 : rtx pop_rtx;
799 293253 : int hard_regno;
800 :
801 : /* For complex types take care to pop both halves. These may survive in
802 : CLOBBER and USE expressions. */
803 293253 : if (COMPLEX_MODE_P (GET_MODE (reg)))
804 : {
805 739 : rtx reg1 = FP_MODE_REG (REGNO (reg), raw_mode);
806 739 : rtx reg2 = FP_MODE_REG (REGNO (reg) + 1, raw_mode);
807 :
808 739 : pop_insn = NULL;
809 739 : if (get_hard_regnum (regstack, reg1) >= 0)
810 739 : pop_insn = emit_pop_insn (insn, regstack, reg1, where);
811 739 : if (get_hard_regnum (regstack, reg2) >= 0)
812 739 : pop_insn = emit_pop_insn (insn, regstack, reg2, where);
813 739 : gcc_assert (pop_insn);
814 : return pop_insn;
815 : }
816 :
817 292514 : hard_regno = get_hard_regnum (regstack, reg);
818 :
819 292514 : gcc_assert (hard_regno >= FIRST_STACK_REG);
820 :
821 292514 : pop_rtx = gen_rtx_SET (FP_MODE_REG (hard_regno, raw_mode),
822 : FP_MODE_REG (FIRST_STACK_REG, raw_mode));
823 :
824 292514 : if (where == EMIT_AFTER)
825 75851 : pop_insn = emit_insn_after (pop_rtx, insn);
826 : else
827 216663 : pop_insn = emit_insn_before (pop_rtx, insn);
828 :
829 292514 : add_reg_note (pop_insn, REG_DEAD, FP_MODE_REG (FIRST_STACK_REG, raw_mode));
830 :
831 292514 : regstack->reg[regstack->top - (hard_regno - FIRST_STACK_REG)]
832 292514 : = regstack->reg[regstack->top];
833 292514 : regstack->top -= 1;
834 292514 : CLEAR_HARD_REG_BIT (regstack->reg_set, REGNO (reg));
835 :
836 292514 : return pop_insn;
837 : }
838 :
839 : /* Emit an insn before or after INSN to swap virtual register REG with
840 : the top of stack. REGSTACK is the stack state before the swap, and
841 : is updated to reflect the swap. A swap insn is represented as a
842 : PARALLEL of two patterns: each pattern moves one reg to the other.
843 :
844 : If REG is already at the top of the stack, no insn is emitted. */
845 :
846 : static void
847 280800 : emit_swap_insn (rtx_insn *insn, stack_ptr regstack, rtx reg)
848 : {
849 280800 : int hard_regno;
850 280800 : int other_reg; /* swap regno temps */
851 280800 : rtx_insn *i1; /* the stack-reg insn prior to INSN */
852 280800 : rtx i1set = NULL_RTX; /* the SET rtx within I1 */
853 :
854 280800 : hard_regno = get_hard_regnum (regstack, reg);
855 :
856 280800 : if (hard_regno == FIRST_STACK_REG)
857 : return;
858 53970 : if (hard_regno == -1)
859 : {
860 : /* Something failed if the register wasn't on the stack. If we had
861 : malformed asms, we zapped the instruction itself, but that didn't
862 : produce the same pattern of register sets as before. To prevent
863 : further failure, adjust REGSTACK to include REG at TOP. */
864 2 : gcc_assert (any_malformed_asm);
865 2 : regstack->reg[++regstack->top] = REGNO (reg);
866 2 : return;
867 : }
868 53968 : gcc_assert (hard_regno >= FIRST_STACK_REG);
869 :
870 53968 : other_reg = regstack->top - (hard_regno - FIRST_STACK_REG);
871 53968 : std::swap (regstack->reg[regstack->top], regstack->reg[other_reg]);
872 :
873 : /* Find the previous insn involving stack regs, but don't pass a
874 : block boundary. */
875 53968 : i1 = NULL;
876 53968 : if (current_block && insn != BB_HEAD (current_block))
877 : {
878 48003 : rtx_insn *tmp = PREV_INSN (insn);
879 48003 : rtx_insn *limit = PREV_INSN (BB_HEAD (current_block));
880 122318 : while (tmp != limit)
881 : {
882 74315 : if (LABEL_P (tmp)
883 74315 : || CALL_P (tmp)
884 117910 : || NOTE_INSN_BASIC_BLOCK_P (tmp)
885 144222 : || (NONJUMP_INSN_P (tmp)
886 55517 : && stack_regs_mentioned (tmp)))
887 : {
888 : i1 = tmp;
889 : break;
890 : }
891 26312 : tmp = PREV_INSN (tmp);
892 : }
893 : }
894 :
895 48003 : if (i1 != NULL_RTX
896 48003 : && (i1set = single_set (i1)) != NULL_RTX)
897 : {
898 40528 : rtx i1src = *get_true_reg (&SET_SRC (i1set));
899 40528 : rtx i1dest = *get_true_reg (&SET_DEST (i1set));
900 :
901 : /* If the previous register stack push was from the reg we are to
902 : swap with, omit the swap. */
903 :
904 37411 : if (REG_P (i1dest) && REGNO (i1dest) == FIRST_STACK_REG
905 31393 : && REG_P (i1src)
906 3390 : && REGNO (i1src) == (unsigned) hard_regno - 1
907 41704 : && find_regno_note (i1, REG_DEAD, FIRST_STACK_REG) == NULL_RTX)
908 : return;
909 :
910 : /* If the previous insn wrote to the reg we are to swap with,
911 : omit the swap. */
912 :
913 36928 : if (REG_P (i1dest) && REGNO (i1dest) == (unsigned) hard_regno
914 2650 : && REG_P (i1src) && REGNO (i1src) == FIRST_STACK_REG
915 40078 : && find_regno_note (i1, REG_DEAD, FIRST_STACK_REG) == NULL_RTX)
916 : return;
917 :
918 : /* Instead of
919 : fld a
920 : fld b
921 : fxch %st(1)
922 : just use
923 : fld b
924 : fld a
925 : if possible. Similarly for fld1, fldz, fldpi etc. instead of any
926 : of the loads or for float extension from memory. */
927 :
928 40045 : i1src = SET_SRC (i1set);
929 40045 : if (GET_CODE (i1src) == FLOAT_EXTEND)
930 2990 : i1src = XEXP (i1src, 0);
931 40045 : if (REG_P (i1dest)
932 36928 : && REGNO (i1dest) == FIRST_STACK_REG
933 30910 : && (MEM_P (i1src) || GET_CODE (i1src) == CONST_DOUBLE)
934 22052 : && !side_effects_p (i1src)
935 14901 : && hard_regno == FIRST_STACK_REG + 1
936 52421 : && i1 != BB_HEAD (current_block))
937 : {
938 : /* i1 is the last insn that involves stack regs before insn, and
939 : is known to be a load without other side-effects, i.e. fld b
940 : in the above comment. */
941 12376 : rtx_insn *i2 = NULL;
942 12376 : rtx i2set;
943 12376 : rtx_insn *tmp = PREV_INSN (i1);
944 12376 : rtx_insn *limit = PREV_INSN (BB_HEAD (current_block));
945 : /* Find the previous insn involving stack regs, but don't pass a
946 : block boundary. */
947 29551 : while (tmp != limit)
948 : {
949 17175 : if (LABEL_P (tmp)
950 17175 : || CALL_P (tmp)
951 27585 : || NOTE_INSN_BASIC_BLOCK_P (tmp)
952 32384 : || (NONJUMP_INSN_P (tmp)
953 11770 : && stack_regs_mentioned (tmp)))
954 : {
955 : i2 = tmp;
956 : break;
957 : }
958 4799 : tmp = PREV_INSN (tmp);
959 : }
960 12376 : if (i2 != NULL_RTX
961 12376 : && (i2set = single_set (i2)) != NULL_RTX)
962 : {
963 11121 : rtx i2dest = *get_true_reg (&SET_DEST (i2set));
964 11121 : rtx i2src = SET_SRC (i2set);
965 11121 : if (GET_CODE (i2src) == FLOAT_EXTEND)
966 207 : i2src = XEXP (i2src, 0);
967 : /* If the last two insns before insn that involve
968 : stack regs are loads, where the latter (i1)
969 : pushes onto the register stack and thus
970 : moves the value from the first load (i2) from
971 : %st to %st(1), consider swapping them. */
972 11121 : if (REG_P (i2dest)
973 10318 : && REGNO (i2dest) == FIRST_STACK_REG
974 9648 : && (MEM_P (i2src) || GET_CODE (i2src) == CONST_DOUBLE)
975 : /* Ensure i2 doesn't have other side-effects. */
976 7391 : && !side_effects_p (i2src)
977 : /* And that the two instructions can actually be
978 : swapped, i.e. there shouldn't be any stores
979 : in between i2 and i1 that might alias with
980 : the i1 memory, and the memory address can't
981 : use registers set in between i2 and i1. */
982 15826 : && !modified_between_p (SET_SRC (i1set), i2, i1))
983 : {
984 : /* Move i1 (fld b above) right before i2 (fld a
985 : above. */
986 4626 : remove_insn (i1);
987 4626 : SET_PREV_INSN (i1) = NULL_RTX;
988 4626 : SET_NEXT_INSN (i1) = NULL_RTX;
989 4626 : set_block_for_insn (i1, NULL);
990 4626 : emit_insn_before (i1, i2);
991 4626 : return;
992 : }
993 : }
994 : }
995 : }
996 :
997 : /* Avoid emitting the swap if this is the first register stack insn
998 : of the current_block. Instead update the current_block's stack_in
999 : and let compensate edges take care of this for us. */
1000 48859 : if (current_block && starting_stack_p)
1001 : {
1002 3880 : BLOCK_INFO (current_block)->stack_in = *regstack;
1003 3880 : starting_stack_p = false;
1004 3880 : return;
1005 : }
1006 :
1007 44979 : machine_mode raw_mode = reg_raw_mode[FIRST_STACK_REG];
1008 44979 : rtx op1 = FP_MODE_REG (hard_regno, raw_mode);
1009 44979 : rtx op2 = FP_MODE_REG (FIRST_STACK_REG, raw_mode);
1010 44979 : rtx swap_rtx
1011 44979 : = gen_rtx_PARALLEL (VOIDmode,
1012 : gen_rtvec (2, gen_rtx_SET (op1, op2),
1013 : gen_rtx_SET (op2, op1)));
1014 44979 : if (i1)
1015 39014 : emit_insn_after (swap_rtx, i1);
1016 5965 : else if (current_block)
1017 0 : emit_insn_before (swap_rtx, BB_HEAD (current_block));
1018 : else
1019 5965 : emit_insn_before (swap_rtx, insn);
1020 : }
1021 :
1022 : /* Emit an insns before INSN to swap virtual register SRC1 with
1023 : the top of stack and virtual register SRC2 with second stack
1024 : slot. REGSTACK is the stack state before the swaps, and
1025 : is updated to reflect the swaps. A swap insn is represented as a
1026 : PARALLEL of two patterns: each pattern moves one reg to the other.
1027 :
1028 : If SRC1 and/or SRC2 are already at the right place, no swap insn
1029 : is emitted. */
1030 :
1031 : static void
1032 348 : swap_to_top (rtx_insn *insn, stack_ptr regstack, rtx src1, rtx src2)
1033 : {
1034 348 : struct stack_def temp_stack;
1035 348 : int regno, j, k;
1036 :
1037 348 : temp_stack = *regstack;
1038 :
1039 : /* Place operand 1 at the top of stack. */
1040 348 : regno = get_hard_regnum (&temp_stack, src1);
1041 348 : gcc_assert (regno >= 0);
1042 348 : if (regno != FIRST_STACK_REG)
1043 : {
1044 50 : k = temp_stack.top - (regno - FIRST_STACK_REG);
1045 50 : j = temp_stack.top;
1046 :
1047 50 : std::swap (temp_stack.reg[j], temp_stack.reg[k]);
1048 : }
1049 :
1050 : /* Place operand 2 next on the stack. */
1051 348 : regno = get_hard_regnum (&temp_stack, src2);
1052 348 : gcc_assert (regno >= 0);
1053 348 : if (regno != FIRST_STACK_REG + 1)
1054 : {
1055 15 : k = temp_stack.top - (regno - FIRST_STACK_REG);
1056 15 : j = temp_stack.top - 1;
1057 :
1058 15 : std::swap (temp_stack.reg[j], temp_stack.reg[k]);
1059 : }
1060 :
1061 348 : change_stack (insn, regstack, &temp_stack, EMIT_BEFORE);
1062 348 : }
1063 :
1064 : /* Handle a move to or from a stack register in PAT, which is in INSN.
1065 : REGSTACK is the current stack. Return whether a control flow insn
1066 : was deleted in the process. */
1067 :
1068 : static bool
1069 418555 : move_for_stack_reg (rtx_insn *insn, stack_ptr regstack, rtx pat)
1070 : {
1071 418555 : rtx *psrc = get_true_reg (&SET_SRC (pat));
1072 418555 : rtx *pdest = get_true_reg (&SET_DEST (pat));
1073 418555 : rtx src, dest;
1074 418555 : rtx note;
1075 418555 : bool control_flow_insn_deleted = false;
1076 :
1077 418555 : src = *psrc; dest = *pdest;
1078 :
1079 418555 : if (STACK_REG_P (src) && STACK_REG_P (dest))
1080 : {
1081 : /* Write from one stack reg to another. If SRC dies here, then
1082 : just change the register mapping and delete the insn. */
1083 :
1084 29917 : note = find_regno_note (insn, REG_DEAD, REGNO (src));
1085 29917 : if (note)
1086 : {
1087 10608 : int i;
1088 :
1089 : /* If this is a no-op move, there must not be a REG_DEAD note. */
1090 10608 : gcc_assert (REGNO (src) != REGNO (dest));
1091 :
1092 16412 : for (i = regstack->top; i >= 0; i--)
1093 16412 : if (regstack->reg[i] == REGNO (src))
1094 : break;
1095 :
1096 : /* The destination must be dead, or life analysis is borked. */
1097 10608 : gcc_assert (get_hard_regnum (regstack, dest) < FIRST_STACK_REG
1098 : || any_malformed_asm);
1099 :
1100 : /* If the source is not live, this is yet another case of
1101 : uninitialized variables. Load up a NaN instead. */
1102 10608 : if (i < 0)
1103 0 : return move_nan_for_stack_reg (insn, regstack, dest);
1104 :
1105 : /* It is possible that the dest is unused after this insn.
1106 : If so, just pop the src. */
1107 :
1108 10608 : if (find_regno_note (insn, REG_UNUSED, REGNO (dest)))
1109 47 : emit_pop_insn (insn, regstack, src, EMIT_AFTER);
1110 : else
1111 : {
1112 10561 : regstack->reg[i] = REGNO (dest);
1113 10561 : SET_HARD_REG_BIT (regstack->reg_set, REGNO (dest));
1114 10561 : CLEAR_HARD_REG_BIT (regstack->reg_set, REGNO (src));
1115 : }
1116 :
1117 10608 : if (control_flow_insn_p (insn))
1118 : control_flow_insn_deleted = true;
1119 10608 : delete_insn (insn);
1120 10608 : return control_flow_insn_deleted;
1121 : }
1122 :
1123 : /* The source reg does not die. */
1124 :
1125 : /* If this appears to be a no-op move, delete it, or else it
1126 : will confuse the machine description output patterns. But if
1127 : it is REG_UNUSED, we must pop the reg now, as per-insn processing
1128 : for REG_UNUSED will not work for deleted insns. */
1129 :
1130 19309 : if (REGNO (src) == REGNO (dest))
1131 : {
1132 2457 : if (find_regno_note (insn, REG_UNUSED, REGNO (dest)))
1133 51 : emit_pop_insn (insn, regstack, dest, EMIT_AFTER);
1134 :
1135 2457 : if (control_flow_insn_p (insn))
1136 : control_flow_insn_deleted = true;
1137 2457 : delete_insn (insn);
1138 2457 : return control_flow_insn_deleted;
1139 : }
1140 :
1141 : /* The destination ought to be dead. */
1142 16852 : if (get_hard_regnum (regstack, dest) >= FIRST_STACK_REG)
1143 0 : gcc_assert (any_malformed_asm);
1144 : else
1145 : {
1146 16852 : replace_reg (psrc, get_hard_regnum (regstack, src));
1147 :
1148 16852 : regstack->reg[++regstack->top] = REGNO (dest);
1149 16852 : SET_HARD_REG_BIT (regstack->reg_set, REGNO (dest));
1150 16852 : replace_reg (pdest, FIRST_STACK_REG);
1151 : }
1152 : }
1153 388638 : else if (STACK_REG_P (src))
1154 : {
1155 : /* Save from a stack reg to MEM, or possibly integer reg. Since
1156 : only top of stack may be saved, emit an exchange first if
1157 : needs be. */
1158 :
1159 106202 : emit_swap_insn (insn, regstack, src);
1160 :
1161 106202 : note = find_regno_note (insn, REG_DEAD, REGNO (src));
1162 106202 : if (note)
1163 : {
1164 91970 : replace_reg (&XEXP (note, 0), FIRST_STACK_REG);
1165 91970 : regstack->top--;
1166 91970 : CLEAR_HARD_REG_BIT (regstack->reg_set, REGNO (src));
1167 : }
1168 14232 : else if ((GET_MODE (src) == XFmode)
1169 8576 : && regstack->top < REG_STACK_SIZE - 1)
1170 : {
1171 : /* A 387 cannot write an XFmode value to a MEM without
1172 : clobbering the source reg. The output code can handle
1173 : this by reading back the value from the MEM.
1174 : But it is more efficient to use a temp register if one is
1175 : available. Push the source value here if the register
1176 : stack is not full, and then write the value to memory via
1177 : a pop. */
1178 8541 : rtx push_rtx;
1179 8541 : rtx top_stack_reg = FP_MODE_REG (FIRST_STACK_REG, GET_MODE (src));
1180 :
1181 8541 : push_rtx = gen_movxf (top_stack_reg, top_stack_reg);
1182 8541 : emit_insn_before (push_rtx, insn);
1183 8541 : add_reg_note (insn, REG_DEAD, top_stack_reg);
1184 : }
1185 :
1186 106202 : replace_reg (psrc, FIRST_STACK_REG);
1187 : }
1188 : else
1189 : {
1190 282436 : rtx pat = PATTERN (insn);
1191 :
1192 282436 : gcc_assert (STACK_REG_P (dest));
1193 :
1194 : /* Load from MEM, or possibly integer REG or constant, into the
1195 : stack regs. The actual target is always the top of the
1196 : stack. The stack mapping is changed to reflect that DEST is
1197 : now at top of stack. */
1198 :
1199 : /* The destination ought to be dead. However, there is a
1200 : special case with i387 UNSPEC_TAN, where destination is live
1201 : (an argument to fptan) but inherent load of 1.0 is modelled
1202 : as a load from a constant. */
1203 282436 : if (GET_CODE (pat) == PARALLEL
1204 2 : && XVECLEN (pat, 0) == 2
1205 2 : && GET_CODE (XVECEXP (pat, 0, 1)) == SET
1206 2 : && GET_CODE (SET_SRC (XVECEXP (pat, 0, 1))) == UNSPEC
1207 2 : && XINT (SET_SRC (XVECEXP (pat, 0, 1)), 1) == UNSPEC_TAN)
1208 2 : emit_swap_insn (insn, regstack, dest);
1209 : else
1210 282434 : gcc_assert (get_hard_regnum (regstack, dest) < FIRST_STACK_REG
1211 : || any_malformed_asm);
1212 :
1213 282436 : gcc_assert (regstack->top < REG_STACK_SIZE);
1214 :
1215 282436 : regstack->reg[++regstack->top] = REGNO (dest);
1216 282436 : SET_HARD_REG_BIT (regstack->reg_set, REGNO (dest));
1217 282436 : replace_reg (pdest, FIRST_STACK_REG);
1218 : }
1219 :
1220 : return control_flow_insn_deleted;
1221 : }
1222 :
1223 : /* A helper function which replaces INSN with a pattern that loads up
1224 : a NaN into DEST, then invokes move_for_stack_reg. */
1225 :
1226 : static bool
1227 1474 : move_nan_for_stack_reg (rtx_insn *insn, stack_ptr regstack, rtx dest)
1228 : {
1229 1474 : rtx pat;
1230 :
1231 1474 : dest = FP_MODE_REG (REGNO (dest), SFmode);
1232 1474 : pat = gen_rtx_SET (dest, not_a_num);
1233 1474 : PATTERN (insn) = pat;
1234 1474 : INSN_CODE (insn) = -1;
1235 :
1236 1474 : return move_for_stack_reg (insn, regstack, pat);
1237 : }
1238 :
1239 : /* Swap the condition on a branch, if there is one. Return true if we
1240 : found a condition to swap. False if the condition was not used as
1241 : such. */
1242 :
1243 : static bool
1244 561343 : swap_rtx_condition_1 (rtx pat)
1245 : {
1246 561343 : const char *fmt;
1247 561343 : bool r = false;
1248 561343 : int i;
1249 :
1250 561343 : if (COMPARISON_P (pat))
1251 : {
1252 101421 : PUT_CODE (pat, swap_condition (GET_CODE (pat)));
1253 101421 : r = true;
1254 : }
1255 : else
1256 : {
1257 459922 : fmt = GET_RTX_FORMAT (GET_CODE (pat));
1258 1049431 : for (i = GET_RTX_LENGTH (GET_CODE (pat)) - 1; i >= 0; i--)
1259 : {
1260 589509 : if (fmt[i] == 'E')
1261 : {
1262 3 : int j;
1263 :
1264 10 : for (j = XVECLEN (pat, i) - 1; j >= 0; j--)
1265 7 : if (swap_rtx_condition_1 (XVECEXP (pat, i, j)))
1266 0 : r = true;
1267 : }
1268 589506 : else if (fmt[i] == 'e' && swap_rtx_condition_1 (XEXP (pat, i)))
1269 : r = true;
1270 : }
1271 : }
1272 :
1273 561343 : return r;
1274 : }
1275 :
1276 : /* This function swaps condition in cc users and returns true
1277 : if successful. It is invoked in 2 different modes, one with
1278 : DEBUG_SEEN set initially to 0. In this mode, next_flags_user
1279 : will skip DEBUG_INSNs that it would otherwise return and just
1280 : sets DEBUG_SEEN to 1 in that case. If DEBUG_SEEN is 0 at
1281 : the end of toplevel swap_rtx_condition which returns true,
1282 : it means no problematic DEBUG_INSNs were seen and all changes
1283 : have been applied. If it returns true but DEBUG_SEEN is 1,
1284 : it means some problematic DEBUG_INSNs were seen and no changes
1285 : have been applied so far. In that case one needs to call
1286 : swap_rtx_condition again with DEBUG_SEEN set to -1, in which
1287 : case it doesn't skip DEBUG_INSNs, but instead adjusts the
1288 : flags related condition in them or resets them as needed. */
1289 :
1290 : static bool
1291 82236 : swap_rtx_condition (rtx_insn *insn, int &debug_seen)
1292 : {
1293 82236 : rtx pat = PATTERN (insn);
1294 :
1295 : /* We're looking for a single set to an HImode temporary. */
1296 :
1297 82236 : if (GET_CODE (pat) == SET
1298 82230 : && REG_P (SET_DEST (pat))
1299 164449 : && REGNO (SET_DEST (pat)) == FLAGS_REG)
1300 : {
1301 76972 : insn = next_flags_user (insn, debug_seen);
1302 76972 : if (insn == NULL_RTX)
1303 : return false;
1304 76946 : pat = PATTERN (insn);
1305 : }
1306 :
1307 : /* See if this is, or ends in, a fnstsw. If so, we're not doing anything
1308 : with the cc value right now. We may be able to search for one
1309 : though. */
1310 :
1311 82210 : if (GET_CODE (pat) == SET
1312 82201 : && GET_CODE (SET_SRC (pat)) == UNSPEC
1313 0 : && XINT (SET_SRC (pat), 1) == UNSPEC_FNSTSW)
1314 : {
1315 0 : rtx dest = SET_DEST (pat);
1316 :
1317 : /* Search forward looking for the first use of this value.
1318 : Stop at block boundaries. */
1319 0 : while (insn != BB_END (current_block))
1320 : {
1321 0 : insn = NEXT_INSN (insn);
1322 0 : if (INSN_P (insn) && reg_mentioned_p (dest, insn))
1323 : {
1324 0 : if (DEBUG_INSN_P (insn))
1325 : {
1326 0 : if (debug_seen >= 0)
1327 0 : debug_seen = 1;
1328 : else
1329 : /* Reset the DEBUG insn otherwise. */
1330 0 : INSN_VAR_LOCATION_LOC (insn) = gen_rtx_UNKNOWN_VAR_LOC ();
1331 0 : continue;
1332 0 : }
1333 : break;
1334 : }
1335 0 : if (CALL_P (insn))
1336 : return false;
1337 : }
1338 :
1339 : /* We haven't found it. */
1340 0 : if (insn == BB_END (current_block))
1341 : return false;
1342 :
1343 : /* So we've found the insn using this value. If it is anything
1344 : other than sahf or the value does not die (meaning we'd have
1345 : to search further), then we must give up. */
1346 0 : pat = PATTERN (insn);
1347 0 : if (GET_CODE (pat) != SET
1348 0 : || GET_CODE (SET_SRC (pat)) != UNSPEC
1349 0 : || XINT (SET_SRC (pat), 1) != UNSPEC_SAHF
1350 0 : || ! dead_or_set_p (insn, dest))
1351 : return false;
1352 :
1353 : /* Now we are prepared to handle this. */
1354 0 : insn = next_flags_user (insn, debug_seen);
1355 0 : if (insn == NULL_RTX)
1356 : return false;
1357 0 : pat = PATTERN (insn);
1358 : }
1359 :
1360 82210 : if (swap_rtx_condition_1 (pat))
1361 : {
1362 82201 : bool fail = false;
1363 82201 : if (DEBUG_INSN_P (insn))
1364 6 : gcc_assert (debug_seen < 0);
1365 : else
1366 : {
1367 82195 : INSN_CODE (insn) = -1;
1368 82195 : if (recog_memoized (insn) == -1)
1369 : fail = true;
1370 : }
1371 : /* In case the flags don't die here, recurse to try fix
1372 : following user too. */
1373 75353 : if (!fail && !dead_or_set_p (insn, ix86_flags_rtx))
1374 : {
1375 17588 : insn = next_flags_user (insn, debug_seen);
1376 17588 : if (!insn || !swap_rtx_condition (insn, debug_seen))
1377 : fail = true;
1378 : }
1379 69841 : if (fail || debug_seen == 1)
1380 19220 : swap_rtx_condition_1 (pat);
1381 82201 : return !fail;
1382 : }
1383 : return false;
1384 : }
1385 :
1386 : /* Handle a comparison. Special care needs to be taken to avoid
1387 : causing comparisons that a 387 cannot do correctly, such as EQ.
1388 :
1389 : Also, a pop insn may need to be emitted. The 387 does have an
1390 : `fcompp' insn that can pop two regs, but it is sometimes too expensive
1391 : to do this - a `fcomp' followed by a `fstpl %st(0)' may be easier to
1392 : set up. */
1393 :
1394 : static void
1395 108314 : compare_for_stack_reg (rtx_insn *insn, stack_ptr regstack,
1396 : rtx pat_src, bool can_pop_second_op)
1397 : {
1398 108314 : rtx *src1, *src2;
1399 108314 : rtx src1_note, src2_note;
1400 108314 : int debug_seen = 0;
1401 :
1402 108314 : src1 = get_true_reg (&XEXP (pat_src, 0));
1403 108314 : src2 = get_true_reg (&XEXP (pat_src, 1));
1404 :
1405 : /* ??? If fxch turns out to be cheaper than fstp, give priority to
1406 : registers that die in this insn - move those to stack top first. */
1407 108314 : if ((! STACK_REG_P (*src1)
1408 108314 : || (STACK_REG_P (*src2)
1409 108314 : && get_hard_regnum (regstack, *src2) == FIRST_STACK_REG))
1410 185280 : && swap_rtx_condition (insn, debug_seen))
1411 : {
1412 : /* If swap_rtx_condition succeeded but some debug insns
1413 : were seen along the way, it has actually reverted all the
1414 : changes. Rerun swap_rtx_condition in a mode where DEBUG_ISNSs
1415 : will be adjusted as well. */
1416 57759 : if (debug_seen)
1417 : {
1418 6 : debug_seen = -1;
1419 6 : swap_rtx_condition (insn, debug_seen);
1420 : }
1421 57759 : std::swap (XEXP (pat_src, 0), XEXP (pat_src, 1));
1422 :
1423 57759 : src1 = get_true_reg (&XEXP (pat_src, 0));
1424 57759 : src2 = get_true_reg (&XEXP (pat_src, 1));
1425 :
1426 57759 : INSN_CODE (insn) = -1;
1427 : }
1428 :
1429 : /* We will fix any death note later. */
1430 :
1431 108314 : src1_note = find_regno_note (insn, REG_DEAD, REGNO (*src1));
1432 :
1433 108314 : if (STACK_REG_P (*src2))
1434 108314 : src2_note = find_regno_note (insn, REG_DEAD, REGNO (*src2));
1435 : else
1436 : src2_note = NULL_RTX;
1437 :
1438 108314 : emit_swap_insn (insn, regstack, *src1);
1439 :
1440 108314 : replace_reg (src1, FIRST_STACK_REG);
1441 :
1442 108314 : if (STACK_REG_P (*src2))
1443 108314 : replace_reg (src2, get_hard_regnum (regstack, *src2));
1444 :
1445 108314 : if (src1_note)
1446 : {
1447 90046 : if (*src2 == CONST0_RTX (GET_MODE (*src2)))
1448 : {
1449 : /* This is `ftst' insn that can't pop register. */
1450 0 : remove_regno_note (insn, REG_DEAD, REGNO (XEXP (src1_note, 0)));
1451 0 : emit_pop_insn (insn, regstack, XEXP (src1_note, 0),
1452 : EMIT_AFTER);
1453 : }
1454 : else
1455 : {
1456 90046 : pop_stack (regstack, REGNO (XEXP (src1_note, 0)));
1457 90046 : replace_reg (&XEXP (src1_note, 0), FIRST_STACK_REG);
1458 : }
1459 : }
1460 :
1461 : /* If the second operand dies, handle that. But if the operands are
1462 : the same stack register, don't bother, because only one death is
1463 : needed, and it was just handled. */
1464 :
1465 108314 : if (src2_note
1466 108314 : && ! (STACK_REG_P (*src1) && STACK_REG_P (*src2)
1467 59715 : && REGNO (*src1) == REGNO (*src2)))
1468 : {
1469 : /* As a special case, two regs may die in this insn if src2 is
1470 : next to top of stack and the top of stack also dies. Since
1471 : we have already popped src1, "next to top of stack" is really
1472 : at top (FIRST_STACK_REG) now. */
1473 :
1474 59132 : if (get_hard_regnum (regstack, XEXP (src2_note, 0)) == FIRST_STACK_REG
1475 59132 : && src1_note && can_pop_second_op)
1476 : {
1477 0 : pop_stack (regstack, REGNO (XEXP (src2_note, 0)));
1478 0 : replace_reg (&XEXP (src2_note, 0), FIRST_STACK_REG + 1);
1479 : }
1480 : else
1481 : {
1482 : /* The 386 can only represent death of the first operand in
1483 : the case handled above. In all other cases, emit a separate
1484 : pop and remove the death note from here. */
1485 59132 : remove_regno_note (insn, REG_DEAD, REGNO (XEXP (src2_note, 0)));
1486 59132 : emit_pop_insn (insn, regstack, XEXP (src2_note, 0),
1487 : EMIT_AFTER);
1488 : }
1489 : }
1490 108314 : }
1491 :
1492 : /* Substitute hardware stack regs in debug insn INSN, using stack
1493 : layout REGSTACK. If we can't find a hardware stack reg for any of
1494 : the REGs in it, reset the debug insn. */
1495 :
1496 : static void
1497 710646 : subst_all_stack_regs_in_debug_insn (rtx_insn *insn, struct stack_def *regstack)
1498 : {
1499 710646 : subrtx_ptr_iterator::array_type array;
1500 2133374 : FOR_EACH_SUBRTX_PTR (iter, array, &INSN_VAR_LOCATION_LOC (insn), NONCONST)
1501 : {
1502 1422728 : rtx *loc = *iter;
1503 1422728 : rtx x = *loc;
1504 1422728 : if (STACK_REG_P (x))
1505 : {
1506 26500 : int hard_regno = get_hard_regnum (regstack, x);
1507 :
1508 : /* If we can't find an active register, reset this debug insn. */
1509 26500 : if (hard_regno == -1)
1510 : {
1511 0 : INSN_VAR_LOCATION_LOC (insn) = gen_rtx_UNKNOWN_VAR_LOC ();
1512 0 : return;
1513 : }
1514 :
1515 26500 : gcc_assert (hard_regno >= FIRST_STACK_REG);
1516 26500 : replace_reg (loc, hard_regno);
1517 26500 : iter.skip_subrtxes ();
1518 : }
1519 : }
1520 710646 : }
1521 :
1522 : /* Substitute new registers in PAT, which is part of INSN. REGSTACK
1523 : is the current register layout. Return whether a control flow insn
1524 : was deleted in the process. */
1525 :
1526 : static bool
1527 766994 : subst_stack_regs_pat (rtx_insn *insn, stack_ptr regstack, rtx pat)
1528 : {
1529 766994 : rtx *dest, *src;
1530 766994 : bool control_flow_insn_deleted = false;
1531 :
1532 766994 : switch (GET_CODE (pat))
1533 : {
1534 4398 : case USE:
1535 : /* Deaths in USE insns can happen in non optimizing compilation.
1536 : Handle them by popping the dying register. */
1537 4398 : src = get_true_reg (&XEXP (pat, 0));
1538 4398 : if (STACK_REG_P (*src)
1539 8796 : && find_regno_note (insn, REG_DEAD, REGNO (*src)))
1540 : {
1541 : /* USEs are ignored for liveness information so USEs of dead
1542 : register might happen. */
1543 767 : if (TEST_HARD_REG_BIT (regstack->reg_set, REGNO (*src)))
1544 767 : emit_pop_insn (insn, regstack, *src, EMIT_AFTER);
1545 : return control_flow_insn_deleted;
1546 : }
1547 : /* Uninitialized USE might happen for functions returning uninitialized
1548 : value. We will properly initialize the USE on the edge to EXIT_BLOCK,
1549 : so it is safe to ignore the use here. This is consistent with behavior
1550 : of dataflow analyzer that ignores USE too. (This also imply that
1551 : forcibly initializing the register to NaN here would lead to ICE later,
1552 : since the REG_DEAD notes are not issued.) */
1553 : break;
1554 :
1555 0 : case VAR_LOCATION:
1556 0 : gcc_unreachable ();
1557 :
1558 122308 : case CLOBBER:
1559 122308 : {
1560 122308 : rtx note;
1561 :
1562 122308 : dest = get_true_reg (&XEXP (pat, 0));
1563 122308 : if (STACK_REG_P (*dest))
1564 : {
1565 122308 : note = find_reg_note (insn, REG_DEAD, *dest);
1566 :
1567 122308 : if (pat != PATTERN (insn))
1568 : {
1569 : /* The fix_truncdi_1 pattern wants to be able to
1570 : allocate its own scratch register. It does this by
1571 : clobbering an fp reg so that it is assured of an
1572 : empty reg-stack register. If the register is live,
1573 : kill it now. Remove the DEAD/UNUSED note so we
1574 : don't try to kill it later too.
1575 :
1576 : In reality the UNUSED note can be absent in some
1577 : complicated cases when the register is reused for
1578 : partially set variable. */
1579 :
1580 121567 : if (note)
1581 0 : emit_pop_insn (insn, regstack, *dest, EMIT_BEFORE);
1582 : else
1583 121567 : note = find_reg_note (insn, REG_UNUSED, *dest);
1584 121567 : if (note)
1585 121567 : remove_note (insn, note);
1586 121567 : replace_reg (dest, FIRST_STACK_REG + 1);
1587 : }
1588 : else
1589 : {
1590 : /* A top-level clobber with no REG_DEAD, and no hard-regnum
1591 : indicates an uninitialized value. Because reload removed
1592 : all other clobbers, this must be due to a function
1593 : returning without a value. Load up a NaN. */
1594 :
1595 741 : if (!note)
1596 : {
1597 741 : rtx t = *dest;
1598 741 : if (COMPLEX_MODE_P (GET_MODE (t)))
1599 : {
1600 733 : rtx u = FP_MODE_REG (REGNO (t) + 1, SFmode);
1601 733 : if (get_hard_regnum (regstack, u) == -1)
1602 : {
1603 733 : rtx pat2 = gen_rtx_CLOBBER (VOIDmode, u);
1604 733 : rtx_insn *insn2 = emit_insn_before (pat2, insn);
1605 733 : if (move_nan_for_stack_reg (insn2, regstack, u))
1606 741 : control_flow_insn_deleted = true;
1607 : }
1608 : }
1609 741 : if (get_hard_regnum (regstack, t) == -1
1610 741 : && move_nan_for_stack_reg (insn, regstack, t))
1611 : control_flow_insn_deleted = true;
1612 : }
1613 : }
1614 : }
1615 : break;
1616 : }
1617 :
1618 640288 : case SET:
1619 640288 : {
1620 640288 : rtx *src1 = (rtx *) 0, *src2;
1621 640288 : rtx src1_note, src2_note;
1622 640288 : rtx pat_src;
1623 :
1624 640288 : dest = get_true_reg (&SET_DEST (pat));
1625 640288 : src = get_true_reg (&SET_SRC (pat));
1626 640288 : pat_src = SET_SRC (pat);
1627 :
1628 : /* See if this is a `movM' pattern, and handle elsewhere if so. */
1629 136119 : if (STACK_REG_P (*src)
1630 640288 : || (STACK_REG_P (*dest)
1631 : && (REG_P (*src) || MEM_P (*src)
1632 : || CONST_DOUBLE_P (*src))))
1633 : {
1634 417081 : if (move_for_stack_reg (insn, regstack, pat))
1635 8 : control_flow_insn_deleted = true;
1636 : break;
1637 : }
1638 :
1639 223207 : switch (GET_CODE (pat_src))
1640 : {
1641 11399 : case CALL:
1642 11399 : {
1643 11399 : int count;
1644 24865 : for (count = REG_NREGS (*dest); --count >= 0;)
1645 : {
1646 13466 : regstack->reg[++regstack->top] = REGNO (*dest) + count;
1647 13466 : SET_HARD_REG_BIT (regstack->reg_set, REGNO (*dest) + count);
1648 : }
1649 : }
1650 11399 : replace_reg (dest, FIRST_STACK_REG);
1651 11399 : break;
1652 :
1653 0 : case REG:
1654 0 : gcc_unreachable ();
1655 :
1656 : /* Fall through. */
1657 :
1658 25523 : case FLOAT_TRUNCATE:
1659 25523 : case SQRT:
1660 25523 : case ABS:
1661 25523 : case NEG:
1662 : /* These insns only operate on the top of the stack. It's
1663 : possible that the tstM case results in a REG_DEAD note on the
1664 : source. */
1665 :
1666 25523 : if (src1 == 0)
1667 25523 : src1 = get_true_reg (&XEXP (pat_src, 0));
1668 :
1669 25523 : emit_swap_insn (insn, regstack, *src1);
1670 :
1671 25523 : src1_note = find_regno_note (insn, REG_DEAD, REGNO (*src1));
1672 :
1673 25523 : if (STACK_REG_P (*dest))
1674 18009 : replace_reg (dest, FIRST_STACK_REG);
1675 :
1676 25523 : if (src1_note)
1677 : {
1678 7459 : replace_reg (&XEXP (src1_note, 0), FIRST_STACK_REG);
1679 7459 : regstack->top--;
1680 7459 : CLEAR_HARD_REG_BIT (regstack->reg_set, REGNO (*src1));
1681 : }
1682 :
1683 25523 : replace_reg (src1, FIRST_STACK_REG);
1684 25523 : break;
1685 :
1686 56588 : case MINUS:
1687 56588 : case DIV:
1688 : /* On i386, reversed forms of subM3 and divM3 exist for
1689 : MODE_FLOAT, so the same code that works for addM3 and mulM3
1690 : can be used. */
1691 56588 : case MULT:
1692 56588 : case PLUS:
1693 : /* These insns can accept the top of stack as a destination
1694 : from a stack reg or mem, or can use the top of stack as a
1695 : source and some other stack register (possibly top of stack)
1696 : as a destination. */
1697 :
1698 56588 : src1 = get_true_reg (&XEXP (pat_src, 0));
1699 56588 : src2 = get_true_reg (&XEXP (pat_src, 1));
1700 :
1701 : /* We will fix any death note later. */
1702 :
1703 56588 : if (STACK_REG_P (*src1))
1704 54906 : src1_note = find_regno_note (insn, REG_DEAD, REGNO (*src1));
1705 : else
1706 : src1_note = NULL_RTX;
1707 56588 : if (STACK_REG_P (*src2))
1708 51701 : src2_note = find_regno_note (insn, REG_DEAD, REGNO (*src2));
1709 : else
1710 : src2_note = NULL_RTX;
1711 :
1712 : /* If either operand is not a stack register, then the dest
1713 : must be top of stack. */
1714 :
1715 56588 : if (! STACK_REG_P (*src1) || ! STACK_REG_P (*src2))
1716 6569 : emit_swap_insn (insn, regstack, *dest);
1717 : else
1718 : {
1719 : /* Both operands are REG. If neither operand is already
1720 : at the top of stack, choose to make the one that is the
1721 : dest the new top of stack. */
1722 :
1723 50019 : int src1_hard_regnum, src2_hard_regnum;
1724 :
1725 50019 : src1_hard_regnum = get_hard_regnum (regstack, *src1);
1726 50019 : src2_hard_regnum = get_hard_regnum (regstack, *src2);
1727 :
1728 : /* If the source is not live, this is yet another case of
1729 : uninitialized variables. Load up a NaN instead. */
1730 50019 : if (src1_hard_regnum == -1)
1731 : {
1732 0 : rtx pat2 = gen_rtx_CLOBBER (VOIDmode, *src1);
1733 0 : rtx_insn *insn2 = emit_insn_before (pat2, insn);
1734 0 : if (move_nan_for_stack_reg (insn2, regstack, *src1))
1735 50019 : control_flow_insn_deleted = true;
1736 : }
1737 50019 : if (src2_hard_regnum == -1)
1738 : {
1739 0 : rtx pat2 = gen_rtx_CLOBBER (VOIDmode, *src2);
1740 0 : rtx_insn *insn2 = emit_insn_before (pat2, insn);
1741 0 : if (move_nan_for_stack_reg (insn2, regstack, *src2))
1742 50019 : control_flow_insn_deleted = true;
1743 : }
1744 :
1745 50019 : if (src1_hard_regnum != FIRST_STACK_REG
1746 50019 : && src2_hard_regnum != FIRST_STACK_REG)
1747 6196 : emit_swap_insn (insn, regstack, *dest);
1748 : }
1749 :
1750 56588 : if (STACK_REG_P (*src1))
1751 54906 : replace_reg (src1, get_hard_regnum (regstack, *src1));
1752 56588 : if (STACK_REG_P (*src2))
1753 51701 : replace_reg (src2, get_hard_regnum (regstack, *src2));
1754 :
1755 56588 : if (src1_note)
1756 : {
1757 1891 : rtx src1_reg = XEXP (src1_note, 0);
1758 :
1759 : /* If the register that dies is at the top of stack, then
1760 : the destination is somewhere else - merely substitute it.
1761 : But if the reg that dies is not at top of stack, then
1762 : move the top of stack to the dead reg, as though we had
1763 : done the insn and then a store-with-pop. */
1764 :
1765 1891 : if (REGNO (src1_reg) == regstack->reg[regstack->top])
1766 : {
1767 610 : SET_HARD_REG_BIT (regstack->reg_set, REGNO (*dest));
1768 610 : replace_reg (dest, get_hard_regnum (regstack, *dest));
1769 : }
1770 : else
1771 : {
1772 1281 : int regno = get_hard_regnum (regstack, src1_reg);
1773 :
1774 1281 : SET_HARD_REG_BIT (regstack->reg_set, REGNO (*dest));
1775 1281 : replace_reg (dest, regno);
1776 :
1777 1281 : regstack->reg[regstack->top - (regno - FIRST_STACK_REG)]
1778 1281 : = regstack->reg[regstack->top];
1779 : }
1780 :
1781 1891 : CLEAR_HARD_REG_BIT (regstack->reg_set,
1782 1891 : REGNO (XEXP (src1_note, 0)));
1783 1891 : replace_reg (&XEXP (src1_note, 0), FIRST_STACK_REG);
1784 1891 : regstack->top--;
1785 : }
1786 54697 : else if (src2_note)
1787 : {
1788 29031 : rtx src2_reg = XEXP (src2_note, 0);
1789 29031 : if (REGNO (src2_reg) == regstack->reg[regstack->top])
1790 : {
1791 17573 : SET_HARD_REG_BIT (regstack->reg_set, REGNO (*dest));
1792 17573 : replace_reg (dest, get_hard_regnum (regstack, *dest));
1793 : }
1794 : else
1795 : {
1796 11458 : int regno = get_hard_regnum (regstack, src2_reg);
1797 :
1798 11458 : SET_HARD_REG_BIT (regstack->reg_set, REGNO (*dest));
1799 11458 : replace_reg (dest, regno);
1800 :
1801 11458 : regstack->reg[regstack->top - (regno - FIRST_STACK_REG)]
1802 11458 : = regstack->reg[regstack->top];
1803 : }
1804 :
1805 29031 : CLEAR_HARD_REG_BIT (regstack->reg_set,
1806 29031 : REGNO (XEXP (src2_note, 0)));
1807 29031 : replace_reg (&XEXP (src2_note, 0), FIRST_STACK_REG);
1808 29031 : regstack->top--;
1809 : }
1810 : else
1811 : {
1812 25666 : SET_HARD_REG_BIT (regstack->reg_set, REGNO (*dest));
1813 25666 : replace_reg (dest, get_hard_regnum (regstack, *dest));
1814 : }
1815 :
1816 : /* Keep operand 1 matching with destination. */
1817 56588 : if (COMMUTATIVE_ARITH_P (pat_src)
1818 41427 : && REG_P (*src1) && REG_P (*src2)
1819 93510 : && REGNO (*src1) != REGNO (*dest))
1820 : {
1821 9935 : int tmp = REGNO (*src1);
1822 9935 : replace_reg (src1, REGNO (*src2));
1823 9935 : replace_reg (src2, tmp);
1824 : }
1825 : break;
1826 :
1827 114425 : case UNSPEC:
1828 114425 : switch (XINT (pat_src, 1))
1829 : {
1830 142 : case UNSPEC_FIST:
1831 142 : case UNSPEC_FIST_ATOMIC:
1832 :
1833 142 : case UNSPEC_FIST_FLOOR:
1834 142 : case UNSPEC_FIST_CEIL:
1835 :
1836 : /* These insns only operate on the top of the stack. */
1837 :
1838 142 : src1 = get_true_reg (&XVECEXP (pat_src, 0, 0));
1839 142 : emit_swap_insn (insn, regstack, *src1);
1840 :
1841 142 : src1_note = find_regno_note (insn, REG_DEAD, REGNO (*src1));
1842 :
1843 142 : if (STACK_REG_P (*dest))
1844 0 : replace_reg (dest, FIRST_STACK_REG);
1845 :
1846 142 : if (src1_note)
1847 : {
1848 142 : replace_reg (&XEXP (src1_note, 0), FIRST_STACK_REG);
1849 142 : regstack->top--;
1850 142 : CLEAR_HARD_REG_BIT (regstack->reg_set, REGNO (*src1));
1851 : }
1852 :
1853 142 : replace_reg (src1, FIRST_STACK_REG);
1854 142 : break;
1855 :
1856 12222 : case UNSPEC_FXAM:
1857 :
1858 : /* This insn only operate on the top of the stack. */
1859 :
1860 12222 : src1 = get_true_reg (&XVECEXP (pat_src, 0, 0));
1861 12222 : emit_swap_insn (insn, regstack, *src1);
1862 :
1863 12222 : src1_note = find_regno_note (insn, REG_DEAD, REGNO (*src1));
1864 :
1865 12222 : replace_reg (src1, FIRST_STACK_REG);
1866 :
1867 12222 : if (src1_note)
1868 : {
1869 11991 : remove_regno_note (insn, REG_DEAD,
1870 11991 : REGNO (XEXP (src1_note, 0)));
1871 11991 : emit_pop_insn (insn, regstack, XEXP (src1_note, 0),
1872 : EMIT_AFTER);
1873 : }
1874 :
1875 : break;
1876 :
1877 292 : case UNSPEC_SIN:
1878 292 : case UNSPEC_COS:
1879 292 : case UNSPEC_FRNDINT:
1880 292 : case UNSPEC_F2XM1:
1881 :
1882 292 : case UNSPEC_FRNDINT_ROUNDEVEN:
1883 292 : case UNSPEC_FRNDINT_FLOOR:
1884 292 : case UNSPEC_FRNDINT_CEIL:
1885 292 : case UNSPEC_FRNDINT_TRUNC:
1886 :
1887 : /* Above insns operate on the top of the stack. */
1888 :
1889 292 : case UNSPEC_SINCOS_COS:
1890 292 : case UNSPEC_XTRACT_FRACT:
1891 :
1892 : /* Above insns operate on the top two stack slots,
1893 : first part of one input, double output insn. */
1894 :
1895 292 : src1 = get_true_reg (&XVECEXP (pat_src, 0, 0));
1896 :
1897 292 : emit_swap_insn (insn, regstack, *src1);
1898 :
1899 : /* Input should never die, it is replaced with output. */
1900 292 : src1_note = find_regno_note (insn, REG_DEAD, REGNO (*src1));
1901 292 : gcc_assert (!src1_note);
1902 :
1903 292 : if (STACK_REG_P (*dest))
1904 292 : replace_reg (dest, FIRST_STACK_REG);
1905 :
1906 292 : replace_reg (src1, FIRST_STACK_REG);
1907 292 : break;
1908 :
1909 10 : case UNSPEC_SINCOS_SIN:
1910 10 : case UNSPEC_XTRACT_EXP:
1911 :
1912 : /* These insns operate on the top two stack slots,
1913 : second part of one input, double output insn. */
1914 :
1915 10 : regstack->top++;
1916 : /* FALLTHRU */
1917 :
1918 12 : case UNSPEC_TAN:
1919 :
1920 : /* For UNSPEC_TAN, regstack->top is already increased
1921 : by inherent load of constant 1.0. */
1922 :
1923 : /* Output value is generated in the second stack slot.
1924 : Move current value from second slot to the top. */
1925 12 : regstack->reg[regstack->top]
1926 12 : = regstack->reg[regstack->top - 1];
1927 :
1928 12 : gcc_assert (STACK_REG_P (*dest));
1929 :
1930 12 : regstack->reg[regstack->top - 1] = REGNO (*dest);
1931 12 : SET_HARD_REG_BIT (regstack->reg_set, REGNO (*dest));
1932 12 : replace_reg (dest, FIRST_STACK_REG + 1);
1933 :
1934 12 : src1 = get_true_reg (&XVECEXP (pat_src, 0, 0));
1935 :
1936 12 : replace_reg (src1, FIRST_STACK_REG);
1937 12 : break;
1938 :
1939 24 : case UNSPEC_FPATAN:
1940 24 : case UNSPEC_FYL2X:
1941 24 : case UNSPEC_FYL2XP1:
1942 : /* These insns operate on the top two stack slots. */
1943 :
1944 24 : src1 = get_true_reg (&XVECEXP (pat_src, 0, 0));
1945 24 : src2 = get_true_reg (&XVECEXP (pat_src, 0, 1));
1946 :
1947 24 : src1_note = find_regno_note (insn, REG_DEAD, REGNO (*src1));
1948 24 : src2_note = find_regno_note (insn, REG_DEAD, REGNO (*src2));
1949 :
1950 24 : swap_to_top (insn, regstack, *src1, *src2);
1951 :
1952 24 : replace_reg (src1, FIRST_STACK_REG);
1953 24 : replace_reg (src2, FIRST_STACK_REG + 1);
1954 :
1955 24 : if (src1_note)
1956 0 : replace_reg (&XEXP (src1_note, 0), FIRST_STACK_REG);
1957 24 : if (src2_note)
1958 24 : replace_reg (&XEXP (src2_note, 0), FIRST_STACK_REG + 1);
1959 :
1960 : /* Pop both input operands from the stack. */
1961 24 : CLEAR_HARD_REG_BIT (regstack->reg_set,
1962 24 : regstack->reg[regstack->top]);
1963 24 : CLEAR_HARD_REG_BIT (regstack->reg_set,
1964 24 : regstack->reg[regstack->top - 1]);
1965 24 : regstack->top -= 2;
1966 :
1967 : /* Push the result back onto the stack. */
1968 24 : regstack->reg[++regstack->top] = REGNO (*dest);
1969 24 : SET_HARD_REG_BIT (regstack->reg_set, REGNO (*dest));
1970 24 : replace_reg (dest, FIRST_STACK_REG);
1971 24 : break;
1972 :
1973 324 : case UNSPEC_FSCALE_FRACT:
1974 324 : case UNSPEC_FPREM_F:
1975 324 : case UNSPEC_FPREM1_F:
1976 : /* These insns operate on the top two stack slots,
1977 : first part of double input, double output insn. */
1978 :
1979 324 : src1 = get_true_reg (&XVECEXP (pat_src, 0, 0));
1980 324 : src2 = get_true_reg (&XVECEXP (pat_src, 0, 1));
1981 :
1982 324 : src1_note = find_regno_note (insn, REG_DEAD, REGNO (*src1));
1983 324 : src2_note = find_regno_note (insn, REG_DEAD, REGNO (*src2));
1984 :
1985 : /* Inputs should never die, they are
1986 : replaced with outputs. */
1987 324 : gcc_assert (!src1_note);
1988 324 : gcc_assert (!src2_note);
1989 :
1990 324 : swap_to_top (insn, regstack, *src1, *src2);
1991 :
1992 : /* Push the result back onto stack. Empty stack slot
1993 : will be filled in second part of insn. */
1994 324 : if (STACK_REG_P (*dest))
1995 : {
1996 324 : regstack->reg[regstack->top] = REGNO (*dest);
1997 324 : SET_HARD_REG_BIT (regstack->reg_set, REGNO (*dest));
1998 324 : replace_reg (dest, FIRST_STACK_REG);
1999 : }
2000 :
2001 324 : replace_reg (src1, FIRST_STACK_REG);
2002 324 : replace_reg (src2, FIRST_STACK_REG + 1);
2003 324 : break;
2004 :
2005 324 : case UNSPEC_FSCALE_EXP:
2006 324 : case UNSPEC_FPREM_U:
2007 324 : case UNSPEC_FPREM1_U:
2008 : /* These insns operate on the top two stack slots,
2009 : second part of double input, double output insn. */
2010 :
2011 324 : src1 = get_true_reg (&XVECEXP (pat_src, 0, 0));
2012 324 : src2 = get_true_reg (&XVECEXP (pat_src, 0, 1));
2013 :
2014 : /* Push the result back onto stack. Fill empty slot from
2015 : first part of insn and fix top of stack pointer. */
2016 324 : if (STACK_REG_P (*dest))
2017 : {
2018 324 : regstack->reg[regstack->top - 1] = REGNO (*dest);
2019 324 : SET_HARD_REG_BIT (regstack->reg_set, REGNO (*dest));
2020 324 : replace_reg (dest, FIRST_STACK_REG + 1);
2021 : }
2022 :
2023 324 : replace_reg (src1, FIRST_STACK_REG);
2024 324 : replace_reg (src2, FIRST_STACK_REG + 1);
2025 324 : break;
2026 :
2027 285 : case UNSPEC_C2_FLAG:
2028 : /* This insn operates on the top two stack slots,
2029 : third part of C2 setting double input insn. */
2030 :
2031 285 : src1 = get_true_reg (&XVECEXP (pat_src, 0, 0));
2032 285 : src2 = get_true_reg (&XVECEXP (pat_src, 0, 1));
2033 :
2034 285 : replace_reg (src1, FIRST_STACK_REG);
2035 285 : replace_reg (src2, FIRST_STACK_REG + 1);
2036 285 : break;
2037 :
2038 0 : case UNSPEC_FNSTSW:
2039 : /* Combined fcomp+fnstsw generated for doing well with
2040 : CSE. When optimizing this would have been broken
2041 : up before now. */
2042 :
2043 0 : pat_src = XVECEXP (pat_src, 0, 0);
2044 0 : if (GET_CODE (pat_src) == COMPARE)
2045 0 : goto do_compare;
2046 :
2047 : /* Fall through. */
2048 :
2049 100800 : case UNSPEC_NOTRAP:
2050 :
2051 100800 : pat_src = XVECEXP (pat_src, 0, 0);
2052 100800 : gcc_assert (GET_CODE (pat_src) == COMPARE);
2053 100800 : goto do_compare;
2054 :
2055 0 : default:
2056 0 : gcc_unreachable ();
2057 : }
2058 : break;
2059 :
2060 108314 : case COMPARE:
2061 108314 : do_compare:
2062 : /* `fcomi' insn can't pop two regs. */
2063 108314 : compare_for_stack_reg (insn, regstack, pat_src,
2064 108314 : REGNO (*dest) != FLAGS_REG);
2065 108314 : break;
2066 :
2067 7758 : case IF_THEN_ELSE:
2068 : /* This insn requires the top of stack to be the destination. */
2069 :
2070 7758 : src1 = get_true_reg (&XEXP (pat_src, 1));
2071 7758 : src2 = get_true_reg (&XEXP (pat_src, 2));
2072 :
2073 7758 : src1_note = find_regno_note (insn, REG_DEAD, REGNO (*src1));
2074 7758 : src2_note = find_regno_note (insn, REG_DEAD, REGNO (*src2));
2075 :
2076 : /* If the comparison operator is an FP comparison operator,
2077 : it is handled correctly by compare_for_stack_reg () who
2078 : will move the destination to the top of stack. But if the
2079 : comparison operator is not an FP comparison operator, we
2080 : have to handle it here. */
2081 7758 : if (get_hard_regnum (regstack, *dest) >= FIRST_STACK_REG
2082 7758 : && REGNO (*dest) != regstack->reg[regstack->top])
2083 : {
2084 : /* In case one of operands is the top of stack and the operands
2085 : dies, it is safe to make it the destination operand by
2086 : reversing the direction of cmove and avoid fxch. */
2087 3872 : if ((REGNO (*src1) == regstack->reg[regstack->top]
2088 1919 : && src1_note)
2089 5477 : || (REGNO (*src2) == regstack->reg[regstack->top]
2090 1383 : && src2_note))
2091 : {
2092 604 : int idx1 = (get_hard_regnum (regstack, *src1)
2093 604 : - FIRST_STACK_REG);
2094 604 : int idx2 = (get_hard_regnum (regstack, *src2)
2095 604 : - FIRST_STACK_REG);
2096 :
2097 : /* Make reg-stack believe that the operands are already
2098 : swapped on the stack */
2099 604 : regstack->reg[regstack->top - idx1] = REGNO (*src2);
2100 604 : regstack->reg[regstack->top - idx2] = REGNO (*src1);
2101 :
2102 : /* Reverse condition to compensate the operand swap.
2103 : i386 do have comparison always reversible. */
2104 604 : PUT_CODE (XEXP (pat_src, 0),
2105 : reversed_comparison_code (XEXP (pat_src, 0), insn));
2106 : }
2107 : else
2108 3268 : emit_swap_insn (insn, regstack, *dest);
2109 : }
2110 :
2111 7758 : {
2112 7758 : rtx src_note [3];
2113 7758 : int i;
2114 :
2115 7758 : src_note[0] = 0;
2116 7758 : src_note[1] = src1_note;
2117 7758 : src_note[2] = src2_note;
2118 :
2119 7758 : if (STACK_REG_P (*src1))
2120 7758 : replace_reg (src1, get_hard_regnum (regstack, *src1));
2121 7758 : if (STACK_REG_P (*src2))
2122 7758 : replace_reg (src2, get_hard_regnum (regstack, *src2));
2123 :
2124 23274 : for (i = 1; i <= 2; i++)
2125 15516 : if (src_note [i])
2126 : {
2127 959 : int regno = REGNO (XEXP (src_note[i], 0));
2128 :
2129 : /* If the register that dies is not at the top of
2130 : stack, then move the top of stack to the dead reg.
2131 : Top of stack should never die, as it is the
2132 : destination. */
2133 959 : gcc_assert (regno != regstack->reg[regstack->top]);
2134 959 : remove_regno_note (insn, REG_DEAD, regno);
2135 959 : emit_pop_insn (insn, regstack, XEXP (src_note[i], 0),
2136 : EMIT_AFTER);
2137 : }
2138 : }
2139 :
2140 : /* Make dest the top of stack. Add dest to regstack if
2141 : not present. */
2142 7758 : if (get_hard_regnum (regstack, *dest) < FIRST_STACK_REG)
2143 0 : regstack->reg[++regstack->top] = REGNO (*dest);
2144 7758 : SET_HARD_REG_BIT (regstack->reg_set, REGNO (*dest));
2145 7758 : replace_reg (dest, FIRST_STACK_REG);
2146 7758 : break;
2147 :
2148 0 : default:
2149 0 : gcc_unreachable ();
2150 : }
2151 : break;
2152 : }
2153 :
2154 : default:
2155 : break;
2156 : }
2157 :
2158 : return control_flow_insn_deleted;
2159 : }
2160 :
2161 : /* Substitute hard regnums for any stack regs in INSN, which has
2162 : N_INPUTS inputs and N_OUTPUTS outputs. REGSTACK is the stack info
2163 : before the insn, and is updated with changes made here.
2164 :
2165 : There are several requirements and assumptions about the use of
2166 : stack-like regs in asm statements. These rules are enforced by
2167 : record_asm_stack_regs; see comments there for details. Any
2168 : asm_operands left in the RTL at this point may be assume to meet the
2169 : requirements, since record_asm_stack_regs removes any problem asm. */
2170 :
2171 : static void
2172 119 : subst_asm_stack_regs (rtx_insn *insn, stack_ptr regstack)
2173 : {
2174 119 : rtx body = PATTERN (insn);
2175 :
2176 119 : rtx *note_reg; /* Array of note contents */
2177 119 : rtx **note_loc; /* Address of REG field of each note */
2178 119 : enum reg_note *note_kind; /* The type of each note */
2179 :
2180 119 : rtx *clobber_reg = 0;
2181 119 : rtx **clobber_loc = 0;
2182 :
2183 119 : struct stack_def temp_stack;
2184 119 : int n_notes;
2185 119 : int n_clobbers;
2186 119 : rtx note;
2187 119 : int i;
2188 119 : int n_inputs, n_outputs;
2189 :
2190 119 : if (! check_asm_stack_operands (insn))
2191 19 : return;
2192 :
2193 : /* Find out what the constraints required. If no constraint
2194 : alternative matches, that is a compiler bug: we should have caught
2195 : such an insn in check_asm_stack_operands. */
2196 100 : extract_constrain_insn (insn);
2197 :
2198 100 : preprocess_constraints (insn);
2199 100 : const operand_alternative *op_alt = which_op_alt ();
2200 :
2201 100 : get_asm_operands_in_out (body, &n_outputs, &n_inputs);
2202 :
2203 : /* Strip SUBREGs here to make the following code simpler. */
2204 420 : for (i = 0; i < recog_data.n_operands; i++)
2205 220 : if (GET_CODE (recog_data.operand[i]) == SUBREG
2206 0 : && REG_P (SUBREG_REG (recog_data.operand[i])))
2207 : {
2208 0 : recog_data.operand_loc[i] = & SUBREG_REG (recog_data.operand[i]);
2209 0 : recog_data.operand[i] = SUBREG_REG (recog_data.operand[i]);
2210 : }
2211 :
2212 : /* Set up NOTE_REG, NOTE_LOC and NOTE_KIND. */
2213 :
2214 240 : for (i = 0, note = REG_NOTES (insn); note; note = XEXP (note, 1))
2215 140 : i++;
2216 :
2217 100 : note_reg = XALLOCAVEC (rtx, i);
2218 100 : note_loc = XALLOCAVEC (rtx *, i);
2219 100 : note_kind = XALLOCAVEC (enum reg_note, i);
2220 :
2221 100 : n_notes = 0;
2222 240 : for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
2223 : {
2224 140 : if (GET_CODE (note) != EXPR_LIST)
2225 0 : continue;
2226 140 : rtx reg = XEXP (note, 0);
2227 140 : rtx *loc = & XEXP (note, 0);
2228 :
2229 140 : if (GET_CODE (reg) == SUBREG && REG_P (SUBREG_REG (reg)))
2230 : {
2231 0 : loc = & SUBREG_REG (reg);
2232 0 : reg = SUBREG_REG (reg);
2233 : }
2234 :
2235 140 : if (STACK_REG_P (reg)
2236 180 : && (REG_NOTE_KIND (note) == REG_DEAD
2237 10 : || REG_NOTE_KIND (note) == REG_UNUSED))
2238 : {
2239 40 : note_reg[n_notes] = reg;
2240 40 : note_loc[n_notes] = loc;
2241 40 : note_kind[n_notes] = REG_NOTE_KIND (note);
2242 40 : n_notes++;
2243 : }
2244 : }
2245 :
2246 : /* Set up CLOBBER_REG and CLOBBER_LOC. */
2247 :
2248 100 : n_clobbers = 0;
2249 :
2250 100 : if (GET_CODE (body) == PARALLEL)
2251 : {
2252 100 : clobber_reg = XALLOCAVEC (rtx, XVECLEN (body, 0));
2253 100 : clobber_loc = XALLOCAVEC (rtx *, XVECLEN (body, 0));
2254 :
2255 313 : for (i = 0; i < XVECLEN (body, 0); i++)
2256 213 : if (GET_CODE (XVECEXP (body, 0, i)) == CLOBBER)
2257 : {
2258 110 : rtx clobber = XVECEXP (body, 0, i);
2259 110 : rtx reg = XEXP (clobber, 0);
2260 110 : rtx *loc = & XEXP (clobber, 0);
2261 :
2262 110 : if (GET_CODE (reg) == SUBREG && REG_P (SUBREG_REG (reg)))
2263 : {
2264 0 : loc = & SUBREG_REG (reg);
2265 0 : reg = SUBREG_REG (reg);
2266 : }
2267 :
2268 110 : if (STACK_REG_P (reg))
2269 : {
2270 10 : clobber_reg[n_clobbers] = reg;
2271 10 : clobber_loc[n_clobbers] = loc;
2272 10 : n_clobbers++;
2273 : }
2274 : }
2275 : }
2276 :
2277 100 : temp_stack = *regstack;
2278 :
2279 : /* Put the input regs into the desired place in TEMP_STACK. */
2280 :
2281 236 : for (i = n_outputs; i < n_outputs + n_inputs; i++)
2282 112 : if (STACK_REG_P (recog_data.operand[i])
2283 111 : && reg_class_subset_p (op_alt[i].cl, FLOAT_REGS)
2284 247 : && op_alt[i].cl != FLOAT_REGS)
2285 : {
2286 : /* If an operand needs to be in a particular reg in
2287 : FLOAT_REGS, the constraint was either 't' or 'u'. Since
2288 : these constraints are for single register classes, and
2289 : reload guaranteed that operand[i] is already in that class,
2290 : we can just use REGNO (recog_data.operand[i]) to know which
2291 : actual reg this operand needs to be in. */
2292 :
2293 93 : int regno = get_hard_regnum (&temp_stack, recog_data.operand[i]);
2294 :
2295 93 : gcc_assert (regno >= 0);
2296 :
2297 93 : if ((unsigned int) regno != REGNO (recog_data.operand[i]))
2298 : {
2299 : /* recog_data.operand[i] is not in the right place. Find
2300 : it and swap it with whatever is already in I's place.
2301 : K is where recog_data.operand[i] is now. J is where it
2302 : should be. */
2303 8 : int j, k;
2304 :
2305 8 : k = temp_stack.top - (regno - FIRST_STACK_REG);
2306 8 : j = (temp_stack.top
2307 8 : - (REGNO (recog_data.operand[i]) - FIRST_STACK_REG));
2308 :
2309 8 : std::swap (temp_stack.reg[j], temp_stack.reg[k]);
2310 : }
2311 : }
2312 :
2313 : /* Emit insns before INSN to make sure the reg-stack is in the right
2314 : order. */
2315 :
2316 100 : change_stack (insn, regstack, &temp_stack, EMIT_BEFORE);
2317 :
2318 : /* Make the needed input register substitutions. Do death notes and
2319 : clobbers too, because these are for inputs, not outputs. */
2320 :
2321 336 : for (i = n_outputs; i < n_outputs + n_inputs; i++)
2322 136 : if (STACK_REG_P (recog_data.operand[i]))
2323 : {
2324 111 : int regnum = get_hard_regnum (regstack, recog_data.operand[i]);
2325 :
2326 111 : gcc_assert (regnum >= 0);
2327 :
2328 111 : replace_reg (recog_data.operand_loc[i], regnum);
2329 : }
2330 :
2331 140 : for (i = 0; i < n_notes; i++)
2332 40 : if (note_kind[i] == REG_DEAD)
2333 : {
2334 30 : int regnum = get_hard_regnum (regstack, note_reg[i]);
2335 :
2336 30 : gcc_assert (regnum >= 0);
2337 :
2338 30 : replace_reg (note_loc[i], regnum);
2339 : }
2340 :
2341 110 : for (i = 0; i < n_clobbers; i++)
2342 : {
2343 : /* It's OK for a CLOBBER to reference a reg that is not live.
2344 : Don't try to replace it in that case. */
2345 10 : int regnum = get_hard_regnum (regstack, clobber_reg[i]);
2346 :
2347 10 : if (regnum >= 0)
2348 9 : replace_reg (clobber_loc[i], regnum);
2349 : }
2350 :
2351 : /* Now remove from REGSTACK any inputs that the asm implicitly popped. */
2352 :
2353 236 : for (i = n_outputs; i < n_outputs + n_inputs; i++)
2354 136 : if (STACK_REG_P (recog_data.operand[i]))
2355 : {
2356 : /* An input reg is implicitly popped if it is tied to an
2357 : output, or if there is a CLOBBER for it. */
2358 : int j;
2359 :
2360 119 : for (j = 0; j < n_clobbers; j++)
2361 17 : if (operands_match_p (clobber_reg[j], recog_data.operand[i]))
2362 : break;
2363 :
2364 111 : if (j < n_clobbers || op_alt[i].matches >= 0)
2365 : {
2366 : /* recog_data.operand[i] might not be at the top of stack.
2367 : But that's OK, because all we need to do is pop the
2368 : right number of regs off of the top of the reg-stack.
2369 : record_asm_stack_regs guaranteed that all implicitly
2370 : popped regs were grouped at the top of the reg-stack. */
2371 :
2372 90 : CLEAR_HARD_REG_BIT (regstack->reg_set,
2373 90 : regstack->reg[regstack->top]);
2374 90 : regstack->top--;
2375 : }
2376 : }
2377 :
2378 : /* Now add to REGSTACK any outputs that the asm implicitly pushed.
2379 : Note that there isn't any need to substitute register numbers.
2380 : ??? Explain why this is true. */
2381 :
2382 900 : for (i = LAST_STACK_REG; i >= FIRST_STACK_REG; i--)
2383 : {
2384 : /* See if there is an output for this hard reg. */
2385 : int j;
2386 :
2387 1386 : for (j = 0; j < n_outputs; j++)
2388 669 : if (STACK_REG_P (recog_data.operand[j])
2389 1330 : && REGNO (recog_data.operand[j]) == (unsigned) i)
2390 : {
2391 83 : regstack->reg[++regstack->top] = i;
2392 83 : SET_HARD_REG_BIT (regstack->reg_set, i);
2393 83 : break;
2394 : }
2395 : }
2396 :
2397 : /* Now emit a pop insn for any REG_UNUSED output, or any REG_DEAD
2398 : input that the asm didn't implicitly pop. If the asm didn't
2399 : implicitly pop an input reg, that reg will still be live.
2400 :
2401 : Note that we can't use find_regno_note here: the register numbers
2402 : in the death notes have already been substituted. */
2403 :
2404 184 : for (i = 0; i < n_outputs; i++)
2405 84 : if (STACK_REG_P (recog_data.operand[i]))
2406 : {
2407 : int j;
2408 :
2409 102 : for (j = 0; j < n_notes; j++)
2410 19 : if (REGNO (recog_data.operand[i]) == REGNO (note_reg[j])
2411 19 : && note_kind[j] == REG_UNUSED)
2412 : {
2413 0 : insn = emit_pop_insn (insn, regstack, recog_data.operand[i],
2414 : EMIT_AFTER);
2415 0 : break;
2416 : }
2417 : }
2418 :
2419 236 : for (i = n_outputs; i < n_outputs + n_inputs; i++)
2420 136 : if (STACK_REG_P (recog_data.operand[i]))
2421 : {
2422 : int j;
2423 :
2424 148 : for (j = 0; j < n_notes; j++)
2425 58 : if (REGNO (recog_data.operand[i]) == REGNO (note_reg[j])
2426 39 : && note_kind[j] == REG_DEAD
2427 58 : && TEST_HARD_REG_BIT (regstack->reg_set,
2428 30 : REGNO (recog_data.operand[i])))
2429 : {
2430 21 : insn = emit_pop_insn (insn, regstack, recog_data.operand[i],
2431 : EMIT_AFTER);
2432 21 : break;
2433 : }
2434 : }
2435 : }
2436 :
2437 : /* Return true if a function call is allowed to alter some or all bits
2438 : of any stack reg. */
2439 : static bool
2440 233930 : callee_clobbers_any_stack_reg (const function_abi & callee_abi)
2441 : {
2442 234602 : for (unsigned regno = FIRST_STACK_REG; regno <= LAST_STACK_REG; regno++)
2443 234518 : if (callee_abi.clobbers_at_least_part_of_reg_p (regno))
2444 : return true;
2445 : return false;
2446 : }
2447 :
2448 :
2449 : /* Substitute stack hard reg numbers for stack virtual registers in
2450 : INSN. Non-stack register numbers are not changed. REGSTACK is the
2451 : current stack content. Insns may be emitted as needed to arrange the
2452 : stack for the 387 based on the contents of the insn. Return whether
2453 : a control flow insn was deleted in the process. */
2454 :
2455 : static bool
2456 882199 : subst_stack_regs (rtx_insn *insn, stack_ptr regstack)
2457 : {
2458 882199 : rtx *note_link, note;
2459 882199 : bool control_flow_insn_deleted = false;
2460 882199 : int i;
2461 :
2462 : /* If the target of the call doesn't clobber any stack registers,
2463 : Don't clear the arguments. */
2464 882199 : auto call = dyn_cast<rtx_call_insn *> (insn);
2465 1116129 : if (call && callee_clobbers_any_stack_reg (insn_callee_abi (call)))
2466 : {
2467 233846 : int top = regstack->top;
2468 :
2469 : /* If there are any floating point parameters to be passed in
2470 : registers for this call, make sure they are in the right
2471 : order. */
2472 :
2473 233846 : if (top >= 0)
2474 : {
2475 0 : straighten_stack (call, regstack);
2476 :
2477 : /* Now mark the arguments as dead after the call. */
2478 :
2479 0 : while (regstack->top >= 0)
2480 : {
2481 0 : CLEAR_HARD_REG_BIT (regstack->reg_set, FIRST_STACK_REG + regstack->top);
2482 0 : regstack->top--;
2483 : }
2484 : }
2485 : }
2486 :
2487 : /* Do the actual substitution if any stack regs are mentioned.
2488 : Since we only record whether entire insn mentions stack regs, and
2489 : subst_stack_regs_pat only works for patterns that contain stack regs,
2490 : we must check each pattern in a parallel here. A call_value_pop could
2491 : fail otherwise. */
2492 :
2493 882199 : if (stack_regs_mentioned (insn))
2494 : {
2495 659668 : int n_operands = asm_noperands (PATTERN (insn));
2496 659668 : if (n_operands >= 0)
2497 : {
2498 : /* This insn is an `asm' with operands. Decode the operands,
2499 : decide how many are inputs, and do register substitution.
2500 : Any REG_UNUSED notes will be handled by subst_asm_stack_regs. */
2501 :
2502 119 : subst_asm_stack_regs (insn, regstack);
2503 119 : return control_flow_insn_deleted;
2504 : }
2505 :
2506 659549 : if (GET_CODE (PATTERN (insn)) == PARALLEL)
2507 183856 : for (i = 0; i < XVECLEN (PATTERN (insn), 0); i++)
2508 : {
2509 161096 : if (stack_regs_mentioned_p (XVECEXP (PATTERN (insn), 0, i)))
2510 : {
2511 130205 : if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == CLOBBER)
2512 243134 : XVECEXP (PATTERN (insn), 0, i)
2513 121567 : = shallow_copy_rtx (XVECEXP (PATTERN (insn), 0, i));
2514 130205 : if (subst_stack_regs_pat (insn, regstack,
2515 130205 : XVECEXP (PATTERN (insn), 0, i)))
2516 161096 : control_flow_insn_deleted = true;
2517 : }
2518 : }
2519 636789 : else if (subst_stack_regs_pat (insn, regstack, PATTERN (insn)))
2520 882080 : control_flow_insn_deleted = true;
2521 : }
2522 :
2523 : /* subst_stack_regs_pat may have deleted a no-op insn. If so, any
2524 : REG_UNUSED will already have been dealt with, so just return. */
2525 :
2526 882080 : if (NOTE_P (insn) || insn->deleted ())
2527 : return control_flow_insn_deleted;
2528 :
2529 : /* If this a noreturn call, we can't insert pop insns after it.
2530 : Instead, reset the stack state to empty. */
2531 869015 : if (CALL_P (insn)
2532 869015 : && find_reg_note (insn, REG_NORETURN, NULL))
2533 : {
2534 22398 : regstack->top = -1;
2535 22398 : CLEAR_HARD_REG_SET (regstack->reg_set);
2536 : return control_flow_insn_deleted;
2537 : }
2538 :
2539 : /* If there is a REG_UNUSED note on a stack register on this insn,
2540 : the indicated reg must be popped. The REG_UNUSED note is removed,
2541 : since the form of the newly emitted pop insn references the reg,
2542 : making it no longer `unset'. */
2543 :
2544 846617 : note_link = ®_NOTES (insn);
2545 1989992 : for (note = *note_link; note; note = XEXP (note, 1))
2546 1143375 : if (REG_NOTE_KIND (note) == REG_UNUSED && STACK_REG_P (XEXP (note, 0)))
2547 : {
2548 2144 : *note_link = XEXP (note, 1);
2549 2144 : insn = emit_pop_insn (insn, regstack, XEXP (note, 0), EMIT_AFTER);
2550 : }
2551 : else
2552 1141231 : note_link = &XEXP (note, 1);
2553 :
2554 : return control_flow_insn_deleted;
2555 : }
2556 :
2557 : /* Change the organization of the stack so that it fits a new basic
2558 : block. Some registers might have to be popped, but there can never be
2559 : a register live in the new block that is not now live.
2560 :
2561 : Insert any needed insns before or after INSN, as indicated by
2562 : WHERE. OLD is the original stack layout, and NEW is the desired
2563 : form. OLD is updated to reflect the code emitted, i.e., it will be
2564 : the same as NEW upon return.
2565 :
2566 : This function will not preserve block_end[]. But that information
2567 : is no longer needed once this has executed. */
2568 :
2569 : static void
2570 94117 : change_stack (rtx_insn *insn, stack_ptr old, stack_ptr new_stack,
2571 : enum emit_where where)
2572 : {
2573 94117 : int reg;
2574 94117 : machine_mode raw_mode = reg_raw_mode[FIRST_STACK_REG];
2575 94117 : rtx_insn *update_end = NULL;
2576 94117 : int i;
2577 :
2578 : /* Stack adjustments for the first insn in a block update the
2579 : current_block's stack_in instead of inserting insns directly.
2580 : compensate_edges will add the necessary code later. */
2581 94117 : if (current_block
2582 3015 : && starting_stack_p
2583 289 : && where == EMIT_BEFORE)
2584 : {
2585 289 : BLOCK_INFO (current_block)->stack_in = *new_stack;
2586 289 : starting_stack_p = false;
2587 289 : *old = *new_stack;
2588 289 : return;
2589 : }
2590 :
2591 : /* We will be inserting new insns "backwards". If we are to insert
2592 : after INSN, find the next insn, and insert before it. */
2593 :
2594 93828 : if (where == EMIT_AFTER)
2595 : {
2596 682 : if (current_block && BB_END (current_block) == insn)
2597 682 : update_end = insn;
2598 682 : insn = NEXT_INSN (insn);
2599 : }
2600 :
2601 : /* Initialize partially dead variables. */
2602 844452 : for (i = FIRST_STACK_REG; i < LAST_STACK_REG + 1; i++)
2603 750624 : if (TEST_HARD_REG_BIT (new_stack->reg_set, i)
2604 750624 : && !TEST_HARD_REG_BIT (old->reg_set, i))
2605 : {
2606 0 : old->reg[++old->top] = i;
2607 0 : SET_HARD_REG_BIT (old->reg_set, i);
2608 0 : emit_insn_before (gen_rtx_SET (FP_MODE_REG (i, SFmode), not_a_num),
2609 : insn);
2610 : }
2611 :
2612 : /* Pop any registers that are not needed in the new block. */
2613 :
2614 : /* If the destination block's stack already has a specified layout
2615 : and contains two or more registers, use a more intelligent algorithm
2616 : to pop registers that minimizes the number of fxchs below. */
2617 93828 : if (new_stack->top > 0)
2618 : {
2619 : bool slots[REG_STACK_SIZE];
2620 : int pops[REG_STACK_SIZE];
2621 : int next, dest, topsrc;
2622 :
2623 : /* First pass to determine the free slots. */
2624 47673 : for (reg = 0; reg <= new_stack->top; reg++)
2625 37184 : slots[reg] = TEST_HARD_REG_BIT (new_stack->reg_set, old->reg[reg]);
2626 :
2627 : /* Second pass to allocate preferred slots. */
2628 10489 : topsrc = -1;
2629 17984 : for (reg = old->top; reg > new_stack->top; reg--)
2630 7495 : if (TEST_HARD_REG_BIT (new_stack->reg_set, old->reg[reg]))
2631 : {
2632 10579 : dest = -1;
2633 10579 : for (next = 0; next <= new_stack->top; next++)
2634 9730 : if (!slots[next] && new_stack->reg[next] == old->reg[reg])
2635 : {
2636 : /* If this is a preference for the new top of stack, record
2637 : the fact by remembering it's old->reg in topsrc. */
2638 2446 : if (next == new_stack->top)
2639 1597 : topsrc = reg;
2640 2446 : slots[next] = true;
2641 2446 : dest = next;
2642 2446 : break;
2643 : }
2644 3295 : pops[reg] = dest;
2645 : }
2646 : else
2647 4200 : pops[reg] = reg;
2648 :
2649 : /* Intentionally, avoid placing the top of stack in it's correct
2650 : location, if we still need to permute the stack below and we
2651 : can usefully place it somewhere else. This is the case if any
2652 : slot is still unallocated, in which case we should place the
2653 : top of stack there. */
2654 10489 : if (topsrc != -1)
2655 5127 : for (reg = 0; reg < new_stack->top; reg++)
2656 3553 : if (!slots[reg])
2657 : {
2658 23 : pops[topsrc] = reg;
2659 23 : slots[new_stack->top] = false;
2660 23 : slots[reg] = true;
2661 23 : break;
2662 : }
2663 :
2664 : /* Third pass allocates remaining slots and emits pop insns. */
2665 10489 : next = new_stack->top;
2666 17984 : for (reg = old->top; reg > new_stack->top; reg--)
2667 : {
2668 7495 : dest = pops[reg];
2669 7495 : if (dest == -1)
2670 : {
2671 : /* Find next free slot. */
2672 2307 : while (slots[next])
2673 1458 : next--;
2674 849 : dest = next--;
2675 : }
2676 7495 : emit_pop_insn (insn, old, FP_MODE_REG (old->reg[dest], raw_mode),
2677 : EMIT_BEFORE);
2678 : }
2679 : }
2680 : else
2681 : {
2682 : /* The following loop attempts to maximize the number of times we
2683 : pop the top of the stack, as this permits the use of the faster
2684 : ffreep instruction on platforms that support it. */
2685 : int live, next;
2686 :
2687 : live = 0;
2688 296473 : for (reg = 0; reg <= old->top; reg++)
2689 213134 : if (TEST_HARD_REG_BIT (new_stack->reg_set, old->reg[reg]))
2690 3966 : live++;
2691 :
2692 : next = live;
2693 292507 : while (old->top >= live)
2694 209168 : if (TEST_HARD_REG_BIT (new_stack->reg_set, old->reg[old->top]))
2695 : {
2696 5391 : while (TEST_HARD_REG_BIT (new_stack->reg_set, old->reg[next]))
2697 2201 : next--;
2698 3190 : emit_pop_insn (insn, old, FP_MODE_REG (old->reg[next], raw_mode),
2699 : EMIT_BEFORE);
2700 : }
2701 : else
2702 205978 : emit_pop_insn (insn, old, FP_MODE_REG (old->reg[old->top], raw_mode),
2703 : EMIT_BEFORE);
2704 : }
2705 :
2706 93828 : if (new_stack->top == -2)
2707 : {
2708 : /* If the new block has never been processed, then it can inherit
2709 : the old stack order. */
2710 :
2711 0 : new_stack->top = old->top;
2712 0 : memcpy (new_stack->reg, old->reg, sizeof (new_stack->reg));
2713 : }
2714 : else
2715 : {
2716 : /* This block has been entered before, and we must match the
2717 : previously selected stack order. */
2718 :
2719 : /* By now, the only difference should be the order of the stack,
2720 : not their depth or liveliness. */
2721 :
2722 93828 : gcc_assert (old->reg_set == new_stack->reg_set);
2723 93828 : gcc_assert (old->top == new_stack->top);
2724 :
2725 : /* If the stack is not empty (new_stack->top != -1), loop here emitting
2726 : swaps until the stack is correct.
2727 :
2728 : The worst case number of swaps emitted is N + 2, where N is the
2729 : depth of the stack. In some cases, the reg at the top of
2730 : stack may be correct, but swapped anyway in order to fix
2731 : other regs. But since we never swap any other reg away from
2732 : its correct slot, this algorithm will converge. */
2733 :
2734 93828 : if (new_stack->top != -1)
2735 : do
2736 : {
2737 : /* Swap the reg at top of stack into the position it is
2738 : supposed to be in, until the correct top of stack appears. */
2739 :
2740 26525 : while (old->reg[old->top] != new_stack->reg[new_stack->top])
2741 : {
2742 33948 : for (reg = new_stack->top; reg >= 0; reg--)
2743 33948 : if (new_stack->reg[reg] == old->reg[old->top])
2744 : break;
2745 :
2746 11195 : gcc_assert (reg != -1);
2747 :
2748 11195 : emit_swap_insn (insn, old,
2749 11195 : FP_MODE_REG (old->reg[reg], raw_mode));
2750 : }
2751 :
2752 : /* See if any regs remain incorrect. If so, bring an
2753 : incorrect reg to the top of stack, and let the while loop
2754 : above fix it. */
2755 :
2756 57723 : for (reg = new_stack->top; reg >= 0; reg--)
2757 43268 : if (new_stack->reg[reg] != old->reg[reg])
2758 : {
2759 875 : emit_swap_insn (insn, old,
2760 875 : FP_MODE_REG (old->reg[reg], raw_mode));
2761 875 : break;
2762 : }
2763 875 : } while (reg >= 0);
2764 :
2765 : /* At this point there must be no differences. */
2766 :
2767 134978 : for (reg = old->top; reg >= 0; reg--)
2768 41150 : gcc_assert (old->reg[reg] == new_stack->reg[reg]);
2769 : }
2770 :
2771 93828 : if (update_end)
2772 : {
2773 2380 : for (update_end = NEXT_INSN (update_end); update_end != insn;
2774 1016 : update_end = NEXT_INSN (update_end))
2775 : {
2776 1016 : set_block_for_insn (update_end, current_block);
2777 1016 : if (INSN_P (update_end))
2778 1016 : df_insn_rescan (update_end);
2779 : }
2780 682 : BB_END (current_block) = PREV_INSN (insn);
2781 : }
2782 : }
2783 :
2784 : /* Print stack configuration. */
2785 :
2786 : static void
2787 0 : print_stack (FILE *file, stack_ptr s)
2788 : {
2789 0 : if (! file)
2790 : return;
2791 :
2792 0 : if (s->top == -2)
2793 0 : fprintf (file, "uninitialized\n");
2794 0 : else if (s->top == -1)
2795 0 : fprintf (file, "empty\n");
2796 : else
2797 : {
2798 0 : int i;
2799 0 : fputs ("[ ", file);
2800 0 : for (i = 0; i <= s->top; ++i)
2801 0 : fprintf (file, "%d ", s->reg[i]);
2802 0 : fputs ("]\n", file);
2803 : }
2804 : }
2805 :
2806 : /* This function was doing life analysis. We now let the regular live
2807 : code do it's job, so we only need to check some extra invariants
2808 : that reg-stack expects. Primary among these being that all registers
2809 : are initialized before use.
2810 :
2811 : The function returns true when code was emitted to CFG edges and
2812 : commit_edge_insertions needs to be called. */
2813 :
2814 : static bool
2815 35263 : convert_regs_entry (void)
2816 : {
2817 35263 : bool inserted = false;
2818 35263 : edge e;
2819 35263 : edge_iterator ei;
2820 :
2821 : /* Load something into each stack register live at function entry.
2822 : Such live registers can be caused by uninitialized variables or
2823 : functions not returning values on all paths. In order to keep
2824 : the push/pop code happy, and to not scrog the register stack, we
2825 : must put something in these registers. Use a QNaN.
2826 :
2827 : Note that we are inserting converted code here. This code is
2828 : never seen by the convert_regs pass. */
2829 :
2830 70526 : FOR_EACH_EDGE (e, ei, ENTRY_BLOCK_PTR_FOR_FN (cfun)->succs)
2831 : {
2832 35263 : basic_block block = e->dest;
2833 35263 : block_info bi = BLOCK_INFO (block);
2834 35263 : int reg, top = -1;
2835 :
2836 317367 : for (reg = LAST_STACK_REG; reg >= FIRST_STACK_REG; --reg)
2837 282104 : if (TEST_HARD_REG_BIT (bi->stack_in.reg_set, reg))
2838 : {
2839 6 : rtx init;
2840 :
2841 6 : bi->stack_in.reg[++top] = reg;
2842 :
2843 6 : init = gen_rtx_SET (FP_MODE_REG (FIRST_STACK_REG, SFmode),
2844 : not_a_num);
2845 6 : insert_insn_on_edge (init, e);
2846 6 : inserted = true;
2847 : }
2848 :
2849 35263 : bi->stack_in.top = top;
2850 : }
2851 :
2852 35263 : return inserted;
2853 : }
2854 :
2855 : /* Construct the desired stack for function exit. This will either
2856 : be `empty', or the function return value at top-of-stack. */
2857 :
2858 : static void
2859 35263 : convert_regs_exit (void)
2860 : {
2861 35263 : int value_reg_low, value_reg_high;
2862 35263 : stack_ptr output_stack;
2863 35263 : rtx retvalue;
2864 :
2865 35263 : retvalue = stack_result (current_function_decl);
2866 35263 : value_reg_low = value_reg_high = -1;
2867 35263 : if (retvalue)
2868 : {
2869 3835 : value_reg_low = REGNO (retvalue);
2870 3835 : value_reg_high = END_REGNO (retvalue) - 1;
2871 : }
2872 :
2873 35263 : output_stack = &BLOCK_INFO (EXIT_BLOCK_PTR_FOR_FN (cfun))->stack_in;
2874 35263 : if (value_reg_low == -1)
2875 31428 : output_stack->top = -1;
2876 : else
2877 : {
2878 3835 : int reg;
2879 :
2880 3835 : output_stack->top = value_reg_high - value_reg_low;
2881 8175 : for (reg = value_reg_low; reg <= value_reg_high; ++reg)
2882 : {
2883 4340 : output_stack->reg[value_reg_high - reg] = reg;
2884 4340 : SET_HARD_REG_BIT (output_stack->reg_set, reg);
2885 : }
2886 : }
2887 35263 : }
2888 :
2889 : /* Copy the stack info from the end of edge E's source block to the
2890 : start of E's destination block. */
2891 :
2892 : static void
2893 1075318 : propagate_stack (edge e)
2894 : {
2895 1075318 : stack_ptr src_stack = &BLOCK_INFO (e->src)->stack_out;
2896 1075318 : stack_ptr dest_stack = &BLOCK_INFO (e->dest)->stack_in;
2897 1075318 : int reg;
2898 :
2899 : /* Preserve the order of the original stack, but check whether
2900 : any pops are needed. */
2901 1075318 : dest_stack->top = -1;
2902 1401278 : for (reg = 0; reg <= src_stack->top; ++reg)
2903 325960 : if (TEST_HARD_REG_BIT (dest_stack->reg_set, src_stack->reg[reg]))
2904 281964 : dest_stack->reg[++dest_stack->top] = src_stack->reg[reg];
2905 :
2906 : /* Push in any partially dead values. */
2907 9677862 : for (reg = FIRST_STACK_REG; reg < LAST_STACK_REG + 1; reg++)
2908 8602544 : if (TEST_HARD_REG_BIT (dest_stack->reg_set, reg)
2909 8602544 : && !TEST_HARD_REG_BIT (src_stack->reg_set, reg))
2910 0 : dest_stack->reg[++dest_stack->top] = reg;
2911 1075318 : }
2912 :
2913 :
2914 : /* Adjust the stack of edge E's source block on exit to match the stack
2915 : of it's target block upon input. The stack layouts of both blocks
2916 : should have been defined by now. */
2917 :
2918 : static bool
2919 1741537 : compensate_edge (edge e)
2920 : {
2921 1741537 : basic_block source = e->src, target = e->dest;
2922 1741537 : stack_ptr target_stack = &BLOCK_INFO (target)->stack_in;
2923 1741537 : stack_ptr source_stack = &BLOCK_INFO (source)->stack_out;
2924 1741537 : struct stack_def regstack;
2925 1741537 : int reg;
2926 :
2927 1741537 : if (dump_file)
2928 0 : fprintf (dump_file, "Edge %d->%d: ", source->index, target->index);
2929 :
2930 1741537 : gcc_assert (target_stack->top != -2);
2931 :
2932 : /* Check whether stacks are identical. */
2933 1741537 : if (target_stack->top == source_stack->top)
2934 : {
2935 1946096 : for (reg = target_stack->top; reg >= 0; --reg)
2936 298404 : if (target_stack->reg[reg] != source_stack->reg[reg])
2937 : break;
2938 :
2939 1653777 : if (reg == -1)
2940 : {
2941 1647692 : if (dump_file)
2942 0 : fprintf (dump_file, "no changes needed\n");
2943 : return false;
2944 : }
2945 : }
2946 :
2947 93845 : if (dump_file)
2948 : {
2949 0 : fprintf (dump_file, "correcting stack to ");
2950 0 : print_stack (dump_file, target_stack);
2951 : }
2952 :
2953 : /* Abnormal calls may appear to have values live in st(0), but the
2954 : abnormal return path will not have actually loaded the values. */
2955 93845 : if (e->flags & EDGE_ABNORMAL_CALL)
2956 : {
2957 : /* Assert that the lifetimes are as we expect -- one value
2958 : live at st(0) on the end of the source block, and no
2959 : values live at the beginning of the destination block.
2960 : For complex return values, we may have st(1) live as well. */
2961 74 : gcc_assert (source_stack->top == 0 || source_stack->top == 1);
2962 74 : gcc_assert (target_stack->top == -1);
2963 : return false;
2964 : }
2965 :
2966 : /* Handle non-call EH edges specially. The normal return path have
2967 : values in registers. These will be popped en masse by the unwind
2968 : library. */
2969 93771 : if (e->flags & EDGE_EH)
2970 : {
2971 102 : gcc_assert (target_stack->top == -1);
2972 : return false;
2973 : }
2974 :
2975 : /* We don't support abnormal edges. Global takes care to
2976 : avoid any live register across them, so we should never
2977 : have to insert instructions on such edges. */
2978 93669 : gcc_assert (! (e->flags & EDGE_ABNORMAL));
2979 :
2980 : /* Make a copy of source_stack as change_stack is destructive. */
2981 93669 : regstack = *source_stack;
2982 :
2983 : /* It is better to output directly to the end of the block
2984 : instead of to the edge, because emit_swap can do minimal
2985 : insn scheduling. We can do this when there is only one
2986 : edge out, and it is not abnormal. */
2987 93669 : if (EDGE_COUNT (source->succs) == 1)
2988 : {
2989 2567 : current_block = source;
2990 5134 : change_stack (BB_END (source), ®stack, target_stack,
2991 2567 : (JUMP_P (BB_END (source)) ? EMIT_BEFORE : EMIT_AFTER));
2992 : }
2993 : else
2994 : {
2995 91102 : rtx_insn *seq;
2996 91102 : rtx_note *after;
2997 :
2998 91102 : current_block = NULL;
2999 91102 : start_sequence ();
3000 :
3001 : /* ??? change_stack needs some point to emit insns after. */
3002 91102 : after = emit_note (NOTE_INSN_DELETED);
3003 :
3004 91102 : change_stack (after, ®stack, target_stack, EMIT_BEFORE);
3005 :
3006 91102 : seq = end_sequence ();
3007 :
3008 91102 : set_insn_locations (seq, e->goto_locus);
3009 91102 : insert_insn_on_edge (seq, e);
3010 91102 : return true;
3011 : }
3012 2567 : return false;
3013 : }
3014 :
3015 : /* Traverse all non-entry edges in the CFG, and emit the necessary
3016 : edge compensation code to change the stack from stack_out of the
3017 : source block to the stack_in of the destination block. */
3018 :
3019 : static bool
3020 35263 : compensate_edges (void)
3021 : {
3022 35263 : bool inserted = false;
3023 35263 : basic_block bb;
3024 :
3025 35263 : starting_stack_p = false;
3026 :
3027 1145844 : FOR_EACH_BB_FN (bb, cfun)
3028 1110581 : if (bb != ENTRY_BLOCK_PTR_FOR_FN (cfun))
3029 : {
3030 1110581 : edge e;
3031 1110581 : edge_iterator ei;
3032 :
3033 2852118 : FOR_EACH_EDGE (e, ei, bb->succs)
3034 1741537 : if (compensate_edge (e))
3035 91102 : inserted = true;
3036 : }
3037 35263 : return inserted;
3038 : }
3039 :
3040 : /* Select the better of two edges E1 and E2 to use to determine the
3041 : stack layout for their shared destination basic block. This is
3042 : typically the more frequently executed. The edge E1 may be NULL
3043 : (in which case E2 is returned), but E2 is always non-NULL. */
3044 :
3045 : static edge
3046 1665797 : better_edge (edge e1, edge e2)
3047 : {
3048 1665797 : if (!e1)
3049 : return e2;
3050 :
3051 590479 : if (e1->count () > e2->count ())
3052 : return e1;
3053 528117 : if (e1->count () < e2->count ())
3054 : return e2;
3055 :
3056 : /* Prefer critical edges to minimize inserting compensation code on
3057 : critical edges. */
3058 :
3059 792947 : if (EDGE_CRITICAL_P (e1) != EDGE_CRITICAL_P (e2))
3060 222631 : return EDGE_CRITICAL_P (e1) ? e1 : e2;
3061 :
3062 : /* Avoid non-deterministic behavior. */
3063 282285 : return (e1->src->index < e2->src->index) ? e1 : e2;
3064 : }
3065 :
3066 : /* Convert stack register references in one block. Return true if the CFG
3067 : has been modified in the process. */
3068 :
3069 : static bool
3070 1110581 : convert_regs_1 (basic_block block)
3071 : {
3072 1110581 : struct stack_def regstack;
3073 1110581 : block_info bi = BLOCK_INFO (block);
3074 1110581 : int reg;
3075 1110581 : rtx_insn *insn, *next;
3076 1110581 : bool control_flow_insn_deleted = false;
3077 1110581 : bool cfg_altered = false;
3078 1110581 : int debug_insns_with_starting_stack = 0;
3079 :
3080 : /* Choose an initial stack layout, if one hasn't already been chosen. */
3081 1110581 : if (bi->stack_in.top == -2)
3082 : {
3083 1075318 : edge e, beste = NULL;
3084 1075318 : edge_iterator ei;
3085 :
3086 : /* Select the best incoming edge (typically the most frequent) to
3087 : use as a template for this basic block. */
3088 2778741 : FOR_EACH_EDGE (e, ei, block->preds)
3089 1703423 : if (BLOCK_INFO (e->src)->done)
3090 1665797 : beste = better_edge (beste, e);
3091 :
3092 1075318 : if (beste)
3093 1075318 : propagate_stack (beste);
3094 : else
3095 : {
3096 : /* No predecessors. Create an arbitrary input stack. */
3097 0 : bi->stack_in.top = -1;
3098 0 : for (reg = LAST_STACK_REG; reg >= FIRST_STACK_REG; --reg)
3099 0 : if (TEST_HARD_REG_BIT (bi->stack_in.reg_set, reg))
3100 0 : bi->stack_in.reg[++bi->stack_in.top] = reg;
3101 : }
3102 : }
3103 :
3104 1110581 : if (dump_file)
3105 : {
3106 0 : fprintf (dump_file, "\nBasic block %d\nInput stack: ", block->index);
3107 0 : print_stack (dump_file, &bi->stack_in);
3108 : }
3109 :
3110 : /* Process all insns in this block. Keep track of NEXT so that we
3111 : don't process insns emitted while substituting in INSN. */
3112 1110581 : current_block = block;
3113 1110581 : next = BB_HEAD (block);
3114 1110581 : regstack = bi->stack_in;
3115 1110581 : starting_stack_p = true;
3116 :
3117 11639601 : do
3118 : {
3119 11639601 : insn = next;
3120 11639601 : next = NEXT_INSN (insn);
3121 :
3122 : /* Ensure we have not missed a block boundary. */
3123 11639601 : gcc_assert (next);
3124 11639601 : if (insn == BB_END (block))
3125 1110581 : next = NULL;
3126 :
3127 : /* Don't bother processing unless there is a stack reg
3128 : mentioned or if it's a CALL_INSN. */
3129 11639601 : if (DEBUG_BIND_INSN_P (insn))
3130 : {
3131 710646 : if (starting_stack_p)
3132 531223 : debug_insns_with_starting_stack++;
3133 : else
3134 : {
3135 179423 : subst_all_stack_regs_in_debug_insn (insn, ®stack);
3136 :
3137 : /* Nothing must ever die at a debug insn. If something
3138 : is referenced in it that becomes dead, it should have
3139 : died before and the reference in the debug insn
3140 : should have been removed so as to avoid changing code
3141 : generation. */
3142 179423 : gcc_assert (!find_reg_note (insn, REG_DEAD, NULL));
3143 : }
3144 : }
3145 10928955 : else if (stack_regs_mentioned (insn)
3146 10928955 : || CALL_P (insn))
3147 : {
3148 882190 : if (dump_file)
3149 : {
3150 0 : fprintf (dump_file, " insn %d input stack: ",
3151 0 : INSN_UID (insn));
3152 0 : print_stack (dump_file, ®stack);
3153 : }
3154 882190 : if (subst_stack_regs (insn, ®stack))
3155 8 : control_flow_insn_deleted = true;
3156 882190 : starting_stack_p = false;
3157 : }
3158 : }
3159 11639601 : while (next);
3160 :
3161 1110581 : if (debug_insns_with_starting_stack)
3162 : {
3163 : /* Since it's the first non-debug instruction that determines
3164 : the stack requirements of the current basic block, we refrain
3165 : from updating debug insns before it in the loop above, and
3166 : fix them up here. */
3167 1231302 : for (insn = BB_HEAD (block); debug_insns_with_starting_stack;
3168 1155485 : insn = NEXT_INSN (insn))
3169 : {
3170 1155485 : if (!DEBUG_BIND_INSN_P (insn))
3171 624262 : continue;
3172 :
3173 531223 : debug_insns_with_starting_stack--;
3174 531223 : subst_all_stack_regs_in_debug_insn (insn, &bi->stack_in);
3175 : }
3176 : }
3177 :
3178 1110581 : if (dump_file)
3179 : {
3180 0 : fprintf (dump_file, "Expected live registers [");
3181 0 : for (reg = FIRST_STACK_REG; reg <= LAST_STACK_REG; ++reg)
3182 0 : if (TEST_HARD_REG_BIT (bi->out_reg_set, reg))
3183 0 : fprintf (dump_file, " %d", reg);
3184 0 : fprintf (dump_file, " ]\nOutput stack: ");
3185 0 : print_stack (dump_file, ®stack);
3186 : }
3187 :
3188 1110581 : insn = BB_END (block);
3189 1110581 : if (JUMP_P (insn))
3190 830643 : insn = PREV_INSN (insn);
3191 :
3192 : /* If the function is declared to return a value, but it returns one
3193 : in only some cases, some registers might come live here. Emit
3194 : necessary moves for them. */
3195 :
3196 9995229 : for (reg = FIRST_STACK_REG; reg <= LAST_STACK_REG; ++reg)
3197 : {
3198 8884648 : if (TEST_HARD_REG_BIT (bi->out_reg_set, reg)
3199 8884648 : && ! TEST_HARD_REG_BIT (regstack.reg_set, reg))
3200 : {
3201 9 : rtx set;
3202 :
3203 9 : if (dump_file)
3204 0 : fprintf (dump_file, "Emitting insn initializing reg %d\n", reg);
3205 :
3206 9 : set = gen_rtx_SET (FP_MODE_REG (reg, SFmode), not_a_num);
3207 9 : insn = emit_insn_after (set, insn);
3208 9 : if (subst_stack_regs (insn, ®stack))
3209 0 : control_flow_insn_deleted = true;
3210 : }
3211 : }
3212 :
3213 : /* Amongst the insns possibly deleted during the substitution process above,
3214 : might have been the only trapping insn in the block. We purge the now
3215 : possibly dead EH edges here to avoid an ICE from fixup_abnormal_edges,
3216 : called at the end of convert_regs. The order in which we process the
3217 : blocks ensures that we never delete an already processed edge.
3218 :
3219 : Note that, at this point, the CFG may have been damaged by the emission
3220 : of instructions after an abnormal call, which moves the basic block end
3221 : (and is the reason why we call fixup_abnormal_edges later). So we must
3222 : be sure that the trapping insn has been deleted before trying to purge
3223 : dead edges, otherwise we risk purging valid edges.
3224 :
3225 : ??? We are normally supposed not to delete trapping insns, so we pretend
3226 : that the insns deleted above don't actually trap. It would have been
3227 : better to detect this earlier and avoid creating the EH edge in the first
3228 : place, still, but we don't have enough information at that time. */
3229 :
3230 1110581 : if (control_flow_insn_deleted && purge_dead_edges (block))
3231 : cfg_altered = true;
3232 :
3233 : /* Something failed if the stack lives don't match. If we had malformed
3234 : asms, we zapped the instruction itself, but that didn't produce the
3235 : same pattern of register kills as before. */
3236 :
3237 2221162 : gcc_assert (regstack.reg_set == bi->out_reg_set || any_malformed_asm);
3238 1110581 : bi->stack_out = regstack;
3239 1110581 : bi->done = true;
3240 :
3241 1110581 : return cfg_altered;
3242 : }
3243 :
3244 : /* Convert registers in all blocks reachable from BLOCK. Return true if the
3245 : CFG has been modified in the process. */
3246 :
3247 : static bool
3248 35263 : convert_regs_2 (basic_block block)
3249 : {
3250 35263 : basic_block *stack, *sp;
3251 35263 : bool cfg_altered = false;
3252 :
3253 : /* We process the blocks in a top-down manner, in a way such that one block
3254 : is only processed after all its predecessors. The number of predecessors
3255 : of every block has already been computed. */
3256 :
3257 35263 : stack = XNEWVEC (basic_block, n_basic_blocks_for_fn (cfun));
3258 35263 : sp = stack;
3259 :
3260 35263 : *sp++ = block;
3261 :
3262 1110581 : do
3263 : {
3264 1110581 : edge e;
3265 1110581 : edge_iterator ei;
3266 :
3267 1110581 : block = *--sp;
3268 :
3269 : /* Processing BLOCK is achieved by convert_regs_1, which may purge
3270 : some dead EH outgoing edge after the deletion of the trapping
3271 : insn inside the block. Since the number of predecessors of
3272 : BLOCK's successors was computed based on the initial edge set,
3273 : we check the necessity to process some of these successors
3274 : before such an edge deletion may happen. However, there is
3275 : a pitfall: if BLOCK is the only predecessor of a successor and
3276 : the edge between them happens to be deleted, the successor
3277 : becomes unreachable and should not be processed. The problem
3278 : is that there is no way to preventively detect this case so we
3279 : stack the successor in all cases and hand over the task of
3280 : fixing up the discrepancy to convert_regs_1. */
3281 :
3282 2852126 : FOR_EACH_EDGE (e, ei, block->succs)
3283 1741545 : if (! (e->flags & EDGE_DFS_BACK))
3284 : {
3285 1703919 : BLOCK_INFO (e->dest)->predecessors--;
3286 1703919 : if (!BLOCK_INFO (e->dest)->predecessors)
3287 1075318 : *sp++ = e->dest;
3288 : }
3289 :
3290 1110581 : if (convert_regs_1 (block))
3291 8 : cfg_altered = true;
3292 : }
3293 1110581 : while (sp != stack);
3294 :
3295 35263 : free (stack);
3296 :
3297 35263 : return cfg_altered;
3298 : }
3299 :
3300 : /* Traverse all basic blocks in a function, converting the register
3301 : references in each insn from the "flat" register file that gcc uses,
3302 : to the stack-like registers the 387 uses. */
3303 :
3304 : static void
3305 35263 : convert_regs (void)
3306 : {
3307 35263 : bool cfg_altered = false;
3308 35263 : bool inserted;
3309 35263 : basic_block b;
3310 35263 : edge e;
3311 35263 : edge_iterator ei;
3312 :
3313 : /* Initialize uninitialized registers on function entry. */
3314 35263 : inserted = convert_regs_entry ();
3315 :
3316 : /* Construct the desired stack for function exit. */
3317 35263 : convert_regs_exit ();
3318 35263 : BLOCK_INFO (EXIT_BLOCK_PTR_FOR_FN (cfun))->done = true;
3319 :
3320 : /* ??? Future: process inner loops first, and give them arbitrary
3321 : initial stacks which emit_swap_insn can modify. This ought to
3322 : prevent double fxch that often appears at the head of a loop. */
3323 :
3324 : /* Process all blocks reachable from all entry points. */
3325 70526 : FOR_EACH_EDGE (e, ei, ENTRY_BLOCK_PTR_FOR_FN (cfun)->succs)
3326 35263 : if (convert_regs_2 (e->dest))
3327 5 : cfg_altered = true;
3328 :
3329 : /* ??? Process all unreachable blocks. Though there's no excuse
3330 : for keeping these even when not optimizing. */
3331 1145844 : FOR_EACH_BB_FN (b, cfun)
3332 : {
3333 1110581 : block_info bi = BLOCK_INFO (b);
3334 :
3335 1110581 : if (!bi->done && convert_regs_2 (b))
3336 : cfg_altered = true;
3337 : }
3338 :
3339 : /* We must fix up abnormal edges before inserting compensation code
3340 : because both mechanisms insert insns on edges. */
3341 35263 : if (fixup_abnormal_edges ())
3342 9 : inserted = true;
3343 :
3344 35263 : if (compensate_edges ())
3345 9434 : inserted = true;
3346 :
3347 25829 : clear_aux_for_blocks ();
3348 :
3349 35263 : if (inserted)
3350 9442 : commit_edge_insertions ();
3351 :
3352 35263 : if (cfg_altered)
3353 5 : cleanup_cfg (0);
3354 :
3355 35263 : if (dump_file)
3356 0 : fputc ('\n', dump_file);
3357 35263 : }
3358 :
3359 : /* Convert register usage from "flat" register file usage to a "stack
3360 : register file. FILE is the dump file, if used.
3361 :
3362 : Construct a CFG and run life analysis. Then convert each insn one
3363 : by one. Run a last cleanup_cfg pass, if optimizing, to eliminate
3364 : code duplication created when the converter inserts pop insns on
3365 : the edges. */
3366 :
3367 : static bool
3368 1531124 : reg_to_stack (void)
3369 : {
3370 1531124 : basic_block bb;
3371 1531124 : int i;
3372 1531124 : int max_uid;
3373 :
3374 : /* Clean up previous run. */
3375 1531124 : stack_regs_mentioned_data.release ();
3376 :
3377 : /* See if there is something to do. Flow analysis is quite
3378 : expensive so we might save some compilation time. */
3379 15029137 : for (i = FIRST_STACK_REG; i <= LAST_STACK_REG; i++)
3380 12002152 : if (df_regs_ever_live_p (i))
3381 : break;
3382 1531124 : if (i > LAST_STACK_REG)
3383 : return false;
3384 :
3385 35263 : df_note_add_problem ();
3386 35263 : df_analyze ();
3387 :
3388 35263 : mark_dfs_back_edges ();
3389 :
3390 : /* Set up block info for each basic block. */
3391 35263 : alloc_aux_for_blocks (sizeof (struct block_info_def));
3392 1145844 : FOR_EACH_BB_FN (bb, cfun)
3393 : {
3394 1110581 : block_info bi = BLOCK_INFO (bb);
3395 1110581 : edge_iterator ei;
3396 1110581 : edge e;
3397 1110581 : int reg;
3398 :
3399 2849275 : FOR_EACH_EDGE (e, ei, bb->preds)
3400 1738694 : if (!(e->flags & EDGE_DFS_BACK)
3401 1701068 : && e->src != ENTRY_BLOCK_PTR_FOR_FN (cfun))
3402 1665805 : bi->predecessors++;
3403 :
3404 : /* Set current register status at last instruction `uninitialized'. */
3405 1110581 : bi->stack_in.top = -2;
3406 :
3407 : /* Copy live_at_end and live_at_start into temporaries. */
3408 9995229 : for (reg = FIRST_STACK_REG; reg <= LAST_STACK_REG; reg++)
3409 : {
3410 17769296 : if (REGNO_REG_SET_P (DF_LR_OUT (bb), reg))
3411 298298 : SET_HARD_REG_BIT (bi->out_reg_set, reg);
3412 17769296 : if (REGNO_REG_SET_P (DF_LR_IN (bb), reg))
3413 281970 : SET_HARD_REG_BIT (bi->stack_in.reg_set, reg);
3414 : }
3415 : }
3416 :
3417 : /* Create the replacement registers up front. */
3418 317367 : for (i = FIRST_STACK_REG; i <= LAST_STACK_REG; i++)
3419 : {
3420 282104 : machine_mode mode;
3421 1974728 : FOR_EACH_MODE_IN_CLASS (mode, MODE_FLOAT)
3422 1692624 : FP_MODE_REG (i, mode) = gen_rtx_REG (mode, i);
3423 1974728 : FOR_EACH_MODE_IN_CLASS (mode, MODE_COMPLEX_FLOAT)
3424 1692624 : FP_MODE_REG (i, mode) = gen_rtx_REG (mode, i);
3425 : }
3426 :
3427 35263 : ix86_flags_rtx = gen_rtx_REG (CCmode, FLAGS_REG);
3428 :
3429 : /* A QNaN for initializing uninitialized variables.
3430 :
3431 : ??? We can't load from constant memory in PIC mode, because
3432 : we're inserting these instructions before the prologue and
3433 : the PIC register hasn't been set up. In that case, fall back
3434 : on zero, which we can get from `fldz'. */
3435 :
3436 35263 : if ((flag_pic && !TARGET_64BIT)
3437 33708 : || ix86_cmodel == CM_LARGE || ix86_cmodel == CM_LARGE_PIC)
3438 1555 : not_a_num = CONST0_RTX (SFmode);
3439 : else
3440 : {
3441 33708 : REAL_VALUE_TYPE r;
3442 :
3443 33708 : real_nan (&r, "", 1, SFmode);
3444 33708 : not_a_num = const_double_from_real_value (r, SFmode);
3445 33708 : not_a_num = force_const_mem (SFmode, not_a_num);
3446 : }
3447 :
3448 : /* Allocate a cache for stack_regs_mentioned. */
3449 35263 : max_uid = get_max_uid ();
3450 35263 : stack_regs_mentioned_data.create (max_uid + 1);
3451 35263 : memset (stack_regs_mentioned_data.address (),
3452 : 0, sizeof (char) * (max_uid + 1));
3453 :
3454 35263 : convert_regs ();
3455 35263 : any_malformed_asm = false;
3456 :
3457 35263 : free_aux_for_blocks ();
3458 35263 : return true;
3459 : }
3460 :
3461 : /* Convert register usage from flat register file usage to a stack
3462 : register file. */
3463 : static unsigned int
3464 1531124 : rest_of_handle_stack_regs (void)
3465 : {
3466 1531124 : if (reg_to_stack ())
3467 35263 : df_insn_rescan_all ();
3468 1531124 : regstack_completed = true;
3469 :
3470 1531124 : return 0;
3471 : }
3472 :
3473 : namespace {
3474 :
3475 : const pass_data pass_data_stack_regs =
3476 : {
3477 : RTL_PASS, /* type */
3478 : "stack", /* name */
3479 : OPTGROUP_NONE, /* optinfo_flags */
3480 : TV_REG_STACK, /* tv_id */
3481 : 0, /* properties_required */
3482 : 0, /* properties_provided */
3483 : 0, /* properties_destroyed */
3484 : 0, /* todo_flags_start */
3485 : TODO_df_finish, /* todo_flags_finish */
3486 : };
3487 :
3488 : class pass_stack_regs : public rtl_opt_pass
3489 : {
3490 : public:
3491 302985 : pass_stack_regs (gcc::context *ctxt)
3492 605970 : : rtl_opt_pass (pass_data_stack_regs, ctxt)
3493 : {}
3494 :
3495 : /* opt_pass methods: */
3496 1531124 : unsigned int execute (function *) final override
3497 : {
3498 1531124 : return rest_of_handle_stack_regs ();
3499 : }
3500 :
3501 : }; // class pass_stack_regs
3502 :
3503 : } // anon namespace
3504 :
3505 : rtl_opt_pass *
3506 302985 : make_pass_stack_regs (gcc::context *ctxt)
3507 : {
3508 302985 : return new pass_stack_regs (ctxt);
3509 : }
|