1 /* Subroutines for manipulating rtx's in semantically interesting ways.
2 Copyright (C) 1987, 1991, 1994, 1995 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
26 #include "hard-reg-set.h"
27 #include "insn-config.h"
29 #include "insn-flags.h"
30 #include "insn-codes.h"
32 static rtx break_out_memory_refs
PROTO((rtx
));
34 /* Return an rtx for the sum of X and the integer C.
36 This function should be used via the `plus_constant' macro. */
39 plus_constant_wide (x
, c
)
41 register HOST_WIDE_INT c
;
43 register RTX_CODE code
;
44 register enum machine_mode mode
;
58 return GEN_INT (INTVAL (x
) + c
);
62 HOST_WIDE_INT l1
= CONST_DOUBLE_LOW (x
);
63 HOST_WIDE_INT h1
= CONST_DOUBLE_HIGH (x
);
65 HOST_WIDE_INT h2
= c
< 0 ? ~0 : 0;
68 add_double (l1
, h1
, l2
, h2
, &lv
, &hv
);
70 return immed_double_const (lv
, hv
, VOIDmode
);
74 /* If this is a reference to the constant pool, try replacing it with
75 a reference to a new constant. If the resulting address isn't
76 valid, don't return it because we have no way to validize it. */
77 if (GET_CODE (XEXP (x
, 0)) == SYMBOL_REF
78 && CONSTANT_POOL_ADDRESS_P (XEXP (x
, 0)))
81 = force_const_mem (GET_MODE (x
),
82 plus_constant (get_pool_constant (XEXP (x
, 0)),
84 if (memory_address_p (GET_MODE (tem
), XEXP (tem
, 0)))
90 /* If adding to something entirely constant, set a flag
91 so that we can add a CONST around the result. */
102 /* The interesting case is adding the integer to a sum.
103 Look for constant term in the sum and combine
104 with C. For an integer constant term, we make a combined
105 integer. For a constant term that is not an explicit integer,
106 we cannot really combine, but group them together anyway.
108 Use a recursive call in case the remaining operand is something
109 that we handle specially, such as a SYMBOL_REF. */
111 if (GET_CODE (XEXP (x
, 1)) == CONST_INT
)
112 return plus_constant (XEXP (x
, 0), c
+ INTVAL (XEXP (x
, 1)));
113 else if (CONSTANT_P (XEXP (x
, 0)))
114 return gen_rtx (PLUS
, mode
,
115 plus_constant (XEXP (x
, 0), c
),
117 else if (CONSTANT_P (XEXP (x
, 1)))
118 return gen_rtx (PLUS
, mode
,
120 plus_constant (XEXP (x
, 1), c
));
124 x
= gen_rtx (PLUS
, mode
, x
, GEN_INT (c
));
126 if (GET_CODE (x
) == SYMBOL_REF
|| GET_CODE (x
) == LABEL_REF
)
128 else if (all_constant
)
129 return gen_rtx (CONST
, mode
, x
);
134 /* This is the same as `plus_constant', except that it handles LO_SUM.
136 This function should be used via the `plus_constant_for_output' macro. */
139 plus_constant_for_output_wide (x
, c
)
141 register HOST_WIDE_INT c
;
143 register RTX_CODE code
= GET_CODE (x
);
144 register enum machine_mode mode
= GET_MODE (x
);
145 int all_constant
= 0;
147 if (GET_CODE (x
) == LO_SUM
)
148 return gen_rtx (LO_SUM
, mode
, XEXP (x
, 0),
149 plus_constant_for_output (XEXP (x
, 1), c
));
152 return plus_constant (x
, c
);
155 /* If X is a sum, return a new sum like X but lacking any constant terms.
156 Add all the removed constant terms into *CONSTPTR.
157 X itself is not altered. The result != X if and only if
158 it is not isomorphic to X. */
161 eliminate_constant_term (x
, constptr
)
168 if (GET_CODE (x
) != PLUS
)
171 /* First handle constants appearing at this level explicitly. */
172 if (GET_CODE (XEXP (x
, 1)) == CONST_INT
173 && 0 != (tem
= simplify_binary_operation (PLUS
, GET_MODE (x
), *constptr
,
175 && GET_CODE (tem
) == CONST_INT
)
178 return eliminate_constant_term (XEXP (x
, 0), constptr
);
182 x0
= eliminate_constant_term (XEXP (x
, 0), &tem
);
183 x1
= eliminate_constant_term (XEXP (x
, 1), &tem
);
184 if ((x1
!= XEXP (x
, 1) || x0
!= XEXP (x
, 0))
185 && 0 != (tem
= simplify_binary_operation (PLUS
, GET_MODE (x
),
187 && GET_CODE (tem
) == CONST_INT
)
190 return gen_rtx (PLUS
, GET_MODE (x
), x0
, x1
);
196 /* Returns the insn that next references REG after INSN, or 0
197 if REG is clobbered before next referenced or we cannot find
198 an insn that references REG in a straight-line piece of code. */
201 find_next_ref (reg
, insn
)
207 for (insn
= NEXT_INSN (insn
); insn
; insn
= next
)
209 next
= NEXT_INSN (insn
);
210 if (GET_CODE (insn
) == NOTE
)
212 if (GET_CODE (insn
) == CODE_LABEL
213 || GET_CODE (insn
) == BARRIER
)
215 if (GET_CODE (insn
) == INSN
216 || GET_CODE (insn
) == JUMP_INSN
217 || GET_CODE (insn
) == CALL_INSN
)
219 if (reg_set_p (reg
, insn
))
221 if (reg_mentioned_p (reg
, PATTERN (insn
)))
223 if (GET_CODE (insn
) == JUMP_INSN
)
225 if (simplejump_p (insn
))
226 next
= JUMP_LABEL (insn
);
230 if (GET_CODE (insn
) == CALL_INSN
231 && REGNO (reg
) < FIRST_PSEUDO_REGISTER
232 && call_used_regs
[REGNO (reg
)])
241 /* Return an rtx for the size in bytes of the value of EXP. */
247 tree size
= size_in_bytes (TREE_TYPE (exp
));
249 if (TREE_CODE (size
) != INTEGER_CST
250 && contains_placeholder_p (size
))
251 size
= build (WITH_RECORD_EXPR
, sizetype
, size
, exp
);
253 return expand_expr (size
, NULL_RTX
, TYPE_MODE (sizetype
), 0);
256 /* Return a copy of X in which all memory references
257 and all constants that involve symbol refs
258 have been replaced with new temporary registers.
259 Also emit code to load the memory locations and constants
260 into those registers.
262 If X contains no such constants or memory references,
263 X itself (not a copy) is returned.
265 If a constant is found in the address that is not a legitimate constant
266 in an insn, it is left alone in the hope that it might be valid in the
269 X may contain no arithmetic except addition, subtraction and multiplication.
270 Values returned by expand_expr with 1 for sum_ok fit this constraint. */
273 break_out_memory_refs (x
)
276 if (GET_CODE (x
) == MEM
277 || (CONSTANT_P (x
) && CONSTANT_ADDRESS_P (x
)
278 && GET_MODE (x
) != VOIDmode
))
279 x
= force_reg (GET_MODE (x
), x
);
280 else if (GET_CODE (x
) == PLUS
|| GET_CODE (x
) == MINUS
281 || GET_CODE (x
) == MULT
)
283 register rtx op0
= break_out_memory_refs (XEXP (x
, 0));
284 register rtx op1
= break_out_memory_refs (XEXP (x
, 1));
286 if (op0
!= XEXP (x
, 0) || op1
!= XEXP (x
, 1))
287 x
= gen_rtx (GET_CODE (x
), Pmode
, op0
, op1
);
293 #ifdef POINTERS_EXTEND_UNSIGNED
295 /* Given X, a memory address in ptr_mode, convert it to an address
296 in Pmode, or vice versa (TO_MODE says which way). We take advantage of
297 the fact that pointers are not allowed to overflow by commuting arithmetic
298 operations over conversions so that address arithmetic insns can be
302 convert_memory_address (to_mode
, x
)
303 enum machine_mode to_mode
;
308 switch (GET_CODE (x
))
315 return gen_rtx (LABEL_REF
, to_mode
, XEXP (x
, 0));
318 temp
= gen_rtx (SYMBOL_REF
, to_mode
, XSTR (x
, 0));
319 SYMBOL_REF_FLAG (temp
) = SYMBOL_REF_FLAG (x
);
324 return gen_rtx (GET_CODE (x
), to_mode
,
325 convert_memory_address (to_mode
, XEXP (x
, 0)),
326 convert_memory_address (to_mode
, XEXP (x
, 1)));
329 return gen_rtx (CONST
, to_mode
,
330 convert_memory_address (to_mode
, XEXP (x
, 0)));
333 return convert_modes (to_mode
,
334 to_mode
== ptr_mode
? Pmode
: ptr_mode
,
335 x
, POINTERS_EXTEND_UNSIGNED
);
340 /* Given a memory address or facsimile X, construct a new address,
341 currently equivalent, that is stable: future stores won't change it.
343 X must be composed of constants, register and memory references
344 combined with addition, subtraction and multiplication:
345 in other words, just what you can get from expand_expr if sum_ok is 1.
347 Works by making copies of all regs and memory locations used
348 by X and combining them the same way X does.
349 You could also stabilize the reference to this address
350 by copying the address to a register with copy_to_reg;
351 but then you wouldn't get indexed addressing in the reference. */
357 if (GET_CODE (x
) == REG
)
359 if (REGNO (x
) != FRAME_POINTER_REGNUM
360 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
361 && REGNO (x
) != HARD_FRAME_POINTER_REGNUM
366 else if (GET_CODE (x
) == MEM
)
368 else if (GET_CODE (x
) == PLUS
|| GET_CODE (x
) == MINUS
369 || GET_CODE (x
) == MULT
)
371 register rtx op0
= copy_all_regs (XEXP (x
, 0));
372 register rtx op1
= copy_all_regs (XEXP (x
, 1));
373 if (op0
!= XEXP (x
, 0) || op1
!= XEXP (x
, 1))
374 x
= gen_rtx (GET_CODE (x
), Pmode
, op0
, op1
);
379 /* Return something equivalent to X but valid as a memory address
380 for something of mode MODE. When X is not itself valid, this
381 works by copying X or subexpressions of it into registers. */
384 memory_address (mode
, x
)
385 enum machine_mode mode
;
388 register rtx oldx
= x
;
390 #ifdef POINTERS_EXTEND_UNSIGNED
391 if (GET_MODE (x
) == ptr_mode
)
392 x
= convert_memory_address (Pmode
, x
);
395 /* By passing constant addresses thru registers
396 we get a chance to cse them. */
397 if (! cse_not_expected
&& CONSTANT_P (x
) && CONSTANT_ADDRESS_P (x
))
398 x
= force_reg (Pmode
, x
);
400 /* Accept a QUEUED that refers to a REG
401 even though that isn't a valid address.
402 On attempting to put this in an insn we will call protect_from_queue
403 which will turn it into a REG, which is valid. */
404 else if (GET_CODE (x
) == QUEUED
405 && GET_CODE (QUEUED_VAR (x
)) == REG
)
408 /* We get better cse by rejecting indirect addressing at this stage.
409 Let the combiner create indirect addresses where appropriate.
410 For now, generate the code so that the subexpressions useful to share
411 are visible. But not if cse won't be done! */
414 if (! cse_not_expected
&& GET_CODE (x
) != REG
)
415 x
= break_out_memory_refs (x
);
417 /* At this point, any valid address is accepted. */
418 GO_IF_LEGITIMATE_ADDRESS (mode
, x
, win
);
420 /* If it was valid before but breaking out memory refs invalidated it,
421 use it the old way. */
422 if (memory_address_p (mode
, oldx
))
425 /* Perform machine-dependent transformations on X
426 in certain cases. This is not necessary since the code
427 below can handle all possible cases, but machine-dependent
428 transformations can make better code. */
429 LEGITIMIZE_ADDRESS (x
, oldx
, mode
, win
);
431 /* PLUS and MULT can appear in special ways
432 as the result of attempts to make an address usable for indexing.
433 Usually they are dealt with by calling force_operand, below.
434 But a sum containing constant terms is special
435 if removing them makes the sum a valid address:
436 then we generate that address in a register
437 and index off of it. We do this because it often makes
438 shorter code, and because the addresses thus generated
439 in registers often become common subexpressions. */
440 if (GET_CODE (x
) == PLUS
)
442 rtx constant_term
= const0_rtx
;
443 rtx y
= eliminate_constant_term (x
, &constant_term
);
444 if (constant_term
== const0_rtx
445 || ! memory_address_p (mode
, y
))
446 x
= force_operand (x
, NULL_RTX
);
449 y
= gen_rtx (PLUS
, GET_MODE (x
), copy_to_reg (y
), constant_term
);
450 if (! memory_address_p (mode
, y
))
451 x
= force_operand (x
, NULL_RTX
);
457 else if (GET_CODE (x
) == MULT
|| GET_CODE (x
) == MINUS
)
458 x
= force_operand (x
, NULL_RTX
);
460 /* If we have a register that's an invalid address,
461 it must be a hard reg of the wrong class. Copy it to a pseudo. */
462 else if (GET_CODE (x
) == REG
)
465 /* Last resort: copy the value to a register, since
466 the register is a valid address. */
468 x
= force_reg (Pmode
, x
);
475 if (flag_force_addr
&& ! cse_not_expected
&& GET_CODE (x
) != REG
476 /* Don't copy an addr via a reg if it is one of our stack slots. */
477 && ! (GET_CODE (x
) == PLUS
478 && (XEXP (x
, 0) == virtual_stack_vars_rtx
479 || XEXP (x
, 0) == virtual_incoming_args_rtx
)))
481 if (general_operand (x
, Pmode
))
482 x
= force_reg (Pmode
, x
);
484 x
= force_operand (x
, NULL_RTX
);
490 /* If we didn't change the address, we are done. Otherwise, mark
491 a reg as a pointer if we have REG or REG + CONST_INT. */
494 else if (GET_CODE (x
) == REG
)
495 mark_reg_pointer (x
);
496 else if (GET_CODE (x
) == PLUS
497 && GET_CODE (XEXP (x
, 0)) == REG
498 && GET_CODE (XEXP (x
, 1)) == CONST_INT
)
499 mark_reg_pointer (XEXP (x
, 0));
501 /* OLDX may have been the address on a temporary. Update the address
502 to indicate that X is now used. */
503 update_temp_slot_address (oldx
, x
);
508 /* Like `memory_address' but pretend `flag_force_addr' is 0. */
511 memory_address_noforce (mode
, x
)
512 enum machine_mode mode
;
515 int ambient_force_addr
= flag_force_addr
;
519 val
= memory_address (mode
, x
);
520 flag_force_addr
= ambient_force_addr
;
524 /* Convert a mem ref into one with a valid memory address.
525 Pass through anything else unchanged. */
531 if (GET_CODE (ref
) != MEM
)
533 if (memory_address_p (GET_MODE (ref
), XEXP (ref
, 0)))
535 /* Don't alter REF itself, since that is probably a stack slot. */
536 return change_address (ref
, GET_MODE (ref
), XEXP (ref
, 0));
539 /* Return a modified copy of X with its memory address copied
540 into a temporary register to protect it from side effects.
541 If X is not a MEM, it is returned unchanged (and not copied).
542 Perhaps even if it is a MEM, if there is no need to change it. */
549 if (GET_CODE (x
) != MEM
)
552 if (rtx_unstable_p (addr
))
554 rtx temp
= copy_all_regs (addr
);
556 if (GET_CODE (temp
) != REG
)
557 temp
= copy_to_reg (temp
);
558 mem
= gen_rtx (MEM
, GET_MODE (x
), temp
);
560 /* Mark returned memref with in_struct if it's in an array or
561 structure. Copy const and volatile from original memref. */
563 MEM_IN_STRUCT_P (mem
) = MEM_IN_STRUCT_P (x
) || GET_CODE (addr
) == PLUS
;
564 RTX_UNCHANGING_P (mem
) = RTX_UNCHANGING_P (x
);
565 MEM_VOLATILE_P (mem
) = MEM_VOLATILE_P (x
);
571 /* Copy the value or contents of X to a new temp reg and return that reg. */
577 register rtx temp
= gen_reg_rtx (GET_MODE (x
));
579 /* If not an operand, must be an address with PLUS and MULT so
580 do the computation. */
581 if (! general_operand (x
, VOIDmode
))
582 x
= force_operand (x
, temp
);
585 emit_move_insn (temp
, x
);
590 /* Like copy_to_reg but always give the new register mode Pmode
591 in case X is a constant. */
597 return copy_to_mode_reg (Pmode
, x
);
600 /* Like copy_to_reg but always give the new register mode MODE
601 in case X is a constant. */
604 copy_to_mode_reg (mode
, x
)
605 enum machine_mode mode
;
608 register rtx temp
= gen_reg_rtx (mode
);
610 /* If not an operand, must be an address with PLUS and MULT so
611 do the computation. */
612 if (! general_operand (x
, VOIDmode
))
613 x
= force_operand (x
, temp
);
615 if (GET_MODE (x
) != mode
&& GET_MODE (x
) != VOIDmode
)
618 emit_move_insn (temp
, x
);
622 /* Load X into a register if it is not already one.
623 Use mode MODE for the register.
624 X should be valid for mode MODE, but it may be a constant which
625 is valid for all integer modes; that's why caller must specify MODE.
627 The caller must not alter the value in the register we return,
628 since we mark it as a "constant" register. */
632 enum machine_mode mode
;
635 register rtx temp
, insn
, set
;
637 if (GET_CODE (x
) == REG
)
639 temp
= gen_reg_rtx (mode
);
640 insn
= emit_move_insn (temp
, x
);
642 /* Let optimizers know that TEMP's value never changes
643 and that X can be substituted for it. Don't get confused
644 if INSN set something else (such as a SUBREG of TEMP). */
646 && (set
= single_set (insn
)) != 0
647 && SET_DEST (set
) == temp
)
649 rtx note
= find_reg_note (insn
, REG_EQUAL
, NULL_RTX
);
654 REG_NOTES (insn
) = gen_rtx (EXPR_LIST
, REG_EQUAL
, x
, REG_NOTES (insn
));
659 /* If X is a memory ref, copy its contents to a new temp reg and return
660 that reg. Otherwise, return X. */
667 if (GET_CODE (x
) != MEM
|| GET_MODE (x
) == BLKmode
)
669 temp
= gen_reg_rtx (GET_MODE (x
));
670 emit_move_insn (temp
, x
);
674 /* Copy X to TARGET (if it's nonzero and a reg)
675 or to a new temp reg and return that reg.
676 MODE is the mode to use for X in case it is a constant. */
679 copy_to_suggested_reg (x
, target
, mode
)
681 enum machine_mode mode
;
685 if (target
&& GET_CODE (target
) == REG
)
688 temp
= gen_reg_rtx (mode
);
690 emit_move_insn (temp
, x
);
694 /* Return the mode to use to store a scalar of TYPE and MODE.
695 PUNSIGNEDP points to the signedness of the type and may be adjusted
696 to show what signedness to use on extension operations.
698 FOR_CALL is non-zero if this call is promoting args for a call. */
701 promote_mode (type
, mode
, punsignedp
, for_call
)
703 enum machine_mode mode
;
707 enum tree_code code
= TREE_CODE (type
);
708 int unsignedp
= *punsignedp
;
710 #ifdef PROMOTE_FOR_CALL_ONLY
718 case INTEGER_TYPE
: case ENUMERAL_TYPE
: case BOOLEAN_TYPE
:
719 case CHAR_TYPE
: case REAL_TYPE
: case OFFSET_TYPE
:
720 PROMOTE_MODE (mode
, unsignedp
, type
);
724 #ifdef POINTERS_EXTEND_UNSIGNED
727 unsignedp
= POINTERS_EXTEND_UNSIGNED
;
732 *punsignedp
= unsignedp
;
736 /* Adjust the stack pointer by ADJUST (an rtx for a number of bytes).
737 This pops when ADJUST is positive. ADJUST need not be constant. */
740 adjust_stack (adjust
)
744 adjust
= protect_from_queue (adjust
, 0);
746 if (adjust
== const0_rtx
)
749 temp
= expand_binop (Pmode
,
750 #ifdef STACK_GROWS_DOWNWARD
755 stack_pointer_rtx
, adjust
, stack_pointer_rtx
, 0,
758 if (temp
!= stack_pointer_rtx
)
759 emit_move_insn (stack_pointer_rtx
, temp
);
762 /* Adjust the stack pointer by minus ADJUST (an rtx for a number of bytes).
763 This pushes when ADJUST is positive. ADJUST need not be constant. */
766 anti_adjust_stack (adjust
)
770 adjust
= protect_from_queue (adjust
, 0);
772 if (adjust
== const0_rtx
)
775 temp
= expand_binop (Pmode
,
776 #ifdef STACK_GROWS_DOWNWARD
781 stack_pointer_rtx
, adjust
, stack_pointer_rtx
, 0,
784 if (temp
!= stack_pointer_rtx
)
785 emit_move_insn (stack_pointer_rtx
, temp
);
788 /* Round the size of a block to be pushed up to the boundary required
789 by this machine. SIZE is the desired size, which need not be constant. */
795 #ifdef STACK_BOUNDARY
796 int align
= STACK_BOUNDARY
/ BITS_PER_UNIT
;
799 if (GET_CODE (size
) == CONST_INT
)
801 int new = (INTVAL (size
) + align
- 1) / align
* align
;
802 if (INTVAL (size
) != new)
803 size
= GEN_INT (new);
807 /* CEIL_DIV_EXPR needs to worry about the addition overflowing,
808 but we know it can't. So add ourselves and then do TRUNC_DIV_EXPR. */
809 size
= expand_binop (Pmode
, add_optab
, size
, GEN_INT (align
- 1),
810 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
811 size
= expand_divmod (0, TRUNC_DIV_EXPR
, Pmode
, size
, GEN_INT (align
),
813 size
= expand_mult (Pmode
, size
, GEN_INT (align
), NULL_RTX
, 1);
815 #endif /* STACK_BOUNDARY */
819 /* Save the stack pointer for the purpose in SAVE_LEVEL. PSAVE is a pointer
820 to a previously-created save area. If no save area has been allocated,
821 this function will allocate one. If a save area is specified, it
822 must be of the proper mode.
824 The insns are emitted after insn AFTER, if nonzero, otherwise the insns
825 are emitted at the current position. */
828 emit_stack_save (save_level
, psave
, after
)
829 enum save_level save_level
;
834 /* The default is that we use a move insn and save in a Pmode object. */
835 rtx (*fcn
) () = gen_move_insn
;
836 enum machine_mode mode
= Pmode
;
838 /* See if this machine has anything special to do for this kind of save. */
841 #ifdef HAVE_save_stack_block
843 if (HAVE_save_stack_block
)
845 fcn
= gen_save_stack_block
;
846 mode
= insn_operand_mode
[CODE_FOR_save_stack_block
][0];
850 #ifdef HAVE_save_stack_function
852 if (HAVE_save_stack_function
)
854 fcn
= gen_save_stack_function
;
855 mode
= insn_operand_mode
[CODE_FOR_save_stack_function
][0];
859 #ifdef HAVE_save_stack_nonlocal
861 if (HAVE_save_stack_nonlocal
)
863 fcn
= gen_save_stack_nonlocal
;
864 mode
= insn_operand_mode
[(int) CODE_FOR_save_stack_nonlocal
][0];
870 /* If there is no save area and we have to allocate one, do so. Otherwise
871 verify the save area is the proper mode. */
875 if (mode
!= VOIDmode
)
877 if (save_level
== SAVE_NONLOCAL
)
878 *psave
= sa
= assign_stack_local (mode
, GET_MODE_SIZE (mode
), 0);
880 *psave
= sa
= gen_reg_rtx (mode
);
885 if (mode
== VOIDmode
|| GET_MODE (sa
) != mode
)
894 /* We must validize inside the sequence, to ensure that any instructions
895 created by the validize call also get moved to the right place. */
897 sa
= validize_mem (sa
);
898 emit_insn (fcn (sa
, stack_pointer_rtx
));
899 seq
= gen_sequence ();
901 emit_insn_after (seq
, after
);
906 sa
= validize_mem (sa
);
907 emit_insn (fcn (sa
, stack_pointer_rtx
));
911 /* Restore the stack pointer for the purpose in SAVE_LEVEL. SA is the save
912 area made by emit_stack_save. If it is zero, we have nothing to do.
914 Put any emitted insns after insn AFTER, if nonzero, otherwise at
918 emit_stack_restore (save_level
, sa
, after
)
919 enum save_level save_level
;
923 /* The default is that we use a move insn. */
924 rtx (*fcn
) () = gen_move_insn
;
926 /* See if this machine has anything special to do for this kind of save. */
929 #ifdef HAVE_restore_stack_block
931 if (HAVE_restore_stack_block
)
932 fcn
= gen_restore_stack_block
;
935 #ifdef HAVE_restore_stack_function
937 if (HAVE_restore_stack_function
)
938 fcn
= gen_restore_stack_function
;
941 #ifdef HAVE_restore_stack_nonlocal
944 if (HAVE_restore_stack_nonlocal
)
945 fcn
= gen_restore_stack_nonlocal
;
951 sa
= validize_mem (sa
);
958 emit_insn (fcn (stack_pointer_rtx
, sa
));
959 seq
= gen_sequence ();
961 emit_insn_after (seq
, after
);
964 emit_insn (fcn (stack_pointer_rtx
, sa
));
967 /* Return an rtx representing the address of an area of memory dynamically
968 pushed on the stack. This region of memory is always aligned to
969 a multiple of BIGGEST_ALIGNMENT.
971 Any required stack pointer alignment is preserved.
973 SIZE is an rtx representing the size of the area.
974 TARGET is a place in which the address can be placed.
976 KNOWN_ALIGN is the alignment (in bits) that we know SIZE has. */
979 allocate_dynamic_stack_space (size
, target
, known_align
)
984 /* If we're asking for zero bytes, it doesn't matter what we point
985 to since we can't derefference it. But return a reasonable
987 if (size
== const0_rtx
)
988 return virtual_stack_dynamic_rtx
;
990 /* Otherwise, show we're calling alloca or equivalent. */
991 current_function_calls_alloca
= 1;
993 /* Ensure the size is in the proper mode. */
994 if (GET_MODE (size
) != VOIDmode
&& GET_MODE (size
) != Pmode
)
995 size
= convert_to_mode (Pmode
, size
, 1);
997 /* We will need to ensure that the address we return is aligned to
998 BIGGEST_ALIGNMENT. If STACK_DYNAMIC_OFFSET is defined, we don't
999 always know its final value at this point in the compilation (it
1000 might depend on the size of the outgoing parameter lists, for
1001 example), so we must align the value to be returned in that case.
1002 (Note that STACK_DYNAMIC_OFFSET will have a default non-zero value if
1003 STACK_POINTER_OFFSET or ACCUMULATE_OUTGOING_ARGS are defined).
1004 We must also do an alignment operation on the returned value if
1005 the stack pointer alignment is less strict that BIGGEST_ALIGNMENT.
1007 If we have to align, we must leave space in SIZE for the hole
1008 that might result from the alignment operation. */
1010 #if defined (STACK_DYNAMIC_OFFSET) || defined (STACK_POINTER_OFFSET) || defined (ALLOCATE_OUTGOING_ARGS) || ! defined (STACK_BOUNDARY)
1011 #define MUST_ALIGN 1
1013 #define MUST_ALIGN (STACK_BOUNDARY < BIGGEST_ALIGNMENT)
1018 if (GET_CODE (size
) == CONST_INT
)
1019 size
= GEN_INT (INTVAL (size
)
1020 + (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
- 1));
1022 size
= expand_binop (Pmode
, add_optab
, size
,
1023 GEN_INT (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
- 1),
1024 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
1027 #ifdef SETJMP_VIA_SAVE_AREA
1028 /* If setjmp restores regs from a save area in the stack frame,
1029 avoid clobbering the reg save area. Note that the offset of
1030 virtual_incoming_args_rtx includes the preallocated stack args space.
1031 It would be no problem to clobber that, but it's on the wrong side
1032 of the old save area. */
1035 = expand_binop (Pmode
, sub_optab
, virtual_stack_dynamic_rtx
,
1036 stack_pointer_rtx
, NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
1037 size
= expand_binop (Pmode
, add_optab
, size
, dynamic_offset
,
1038 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
1040 #endif /* SETJMP_VIA_SAVE_AREA */
1042 /* Round the size to a multiple of the required stack alignment.
1043 Since the stack if presumed to be rounded before this allocation,
1044 this will maintain the required alignment.
1046 If the stack grows downward, we could save an insn by subtracting
1047 SIZE from the stack pointer and then aligning the stack pointer.
1048 The problem with this is that the stack pointer may be unaligned
1049 between the execution of the subtraction and alignment insns and
1050 some machines do not allow this. Even on those that do, some
1051 signal handlers malfunction if a signal should occur between those
1052 insns. Since this is an extremely rare event, we have no reliable
1053 way of knowing which systems have this problem. So we avoid even
1054 momentarily mis-aligning the stack. */
1056 #ifdef STACK_BOUNDARY
1057 /* If we added a variable amount to SIZE,
1058 we can no longer assume it is aligned. */
1059 #if !defined (SETJMP_VIA_SAVE_AREA)
1060 if (MUST_ALIGN
|| known_align
% STACK_BOUNDARY
!= 0)
1062 size
= round_push (size
);
1065 do_pending_stack_adjust ();
1067 /* Don't use a TARGET that isn't a pseudo. */
1068 if (target
== 0 || GET_CODE (target
) != REG
1069 || REGNO (target
) < FIRST_PSEUDO_REGISTER
)
1070 target
= gen_reg_rtx (Pmode
);
1072 mark_reg_pointer (target
);
1074 #ifndef STACK_GROWS_DOWNWARD
1075 emit_move_insn (target
, virtual_stack_dynamic_rtx
);
1078 /* Perform the required allocation from the stack. Some systems do
1079 this differently than simply incrementing/decrementing from the
1081 #ifdef HAVE_allocate_stack
1082 if (HAVE_allocate_stack
)
1084 enum machine_mode mode
1085 = insn_operand_mode
[(int) CODE_FOR_allocate_stack
][0];
1087 size
= convert_modes (mode
, ptr_mode
, size
, 1);
1089 if (insn_operand_predicate
[(int) CODE_FOR_allocate_stack
][0]
1090 && ! ((*insn_operand_predicate
[(int) CODE_FOR_allocate_stack
][0])
1092 size
= copy_to_mode_reg (mode
, size
);
1094 emit_insn (gen_allocate_stack (size
));
1099 size
= convert_modes (Pmode
, ptr_mode
, size
, 1);
1100 anti_adjust_stack (size
);
1103 #ifdef STACK_GROWS_DOWNWARD
1104 emit_move_insn (target
, virtual_stack_dynamic_rtx
);
1109 /* CEIL_DIV_EXPR needs to worry about the addition overflowing,
1110 but we know it can't. So add ourselves and then do TRUNC_DIV_EXPR. */
1111 target
= expand_binop (Pmode
, add_optab
, target
,
1112 GEN_INT (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
- 1),
1113 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
1114 target
= expand_divmod (0, TRUNC_DIV_EXPR
, Pmode
, target
,
1115 GEN_INT (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
),
1117 target
= expand_mult (Pmode
, target
,
1118 GEN_INT (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
),
1122 /* Some systems require a particular insn to refer to the stack
1123 to make the pages exist. */
1126 emit_insn (gen_probe ());
1129 /* Record the new stack level for nonlocal gotos. */
1130 if (nonlocal_goto_handler_slot
!= 0)
1131 emit_stack_save (SAVE_NONLOCAL
, &nonlocal_goto_stack_level
, NULL_RTX
);
1136 /* Return an rtx representing the register or memory location
1137 in which a scalar value of data type VALTYPE
1138 was returned by a function call to function FUNC.
1139 FUNC is a FUNCTION_DECL node if the precise function is known,
1143 hard_function_value (valtype
, func
)
1147 rtx val
= FUNCTION_VALUE (valtype
, func
);
1148 if (GET_CODE (val
) == REG
1149 && GET_MODE (val
) == BLKmode
)
1151 int bytes
= int_size_in_bytes (valtype
);
1152 enum machine_mode tmpmode
;
1153 for (tmpmode
= GET_CLASS_NARROWEST_MODE (MODE_INT
);
1154 tmpmode
!= MAX_MACHINE_MODE
;
1155 tmpmode
= GET_MODE_WIDER_MODE (tmpmode
))
1157 /* Have we found a large enough mode? */
1158 if (GET_MODE_SIZE (tmpmode
) >= bytes
)
1162 /* No suitable mode found. */
1163 if (tmpmode
== MAX_MACHINE_MODE
)
1166 PUT_MODE (val
, tmpmode
);
1171 /* Return an rtx representing the register or memory location
1172 in which a scalar value of mode MODE was returned by a library call. */
1175 hard_libcall_value (mode
)
1176 enum machine_mode mode
;
1178 return LIBCALL_VALUE (mode
);
1181 /* Look up the tree code for a given rtx code
1182 to provide the arithmetic operation for REAL_ARITHMETIC.
1183 The function returns an int because the caller may not know
1184 what `enum tree_code' means. */
1187 rtx_to_tree_code (code
)
1190 enum tree_code tcode
;
1213 tcode
= LAST_AND_UNUSED_TREE_CODE
;
1216 return ((int) tcode
);