OSDN Git Service

(memory_address): Call update_temp_slot_address on new and old
[pf3gnuchains/gcc-fork.git] / gcc / explow.c
1 /* Subroutines for manipulating rtx's in semantically interesting ways.
2    Copyright (C) 1987, 1991, 1994 Free Software Foundation, Inc.
3
4 This file is part of GNU CC.
5
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)
9 any later version.
10
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.
15
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.  */
19
20
21 #include "config.h"
22 #include "rtl.h"
23 #include "tree.h"
24 #include "flags.h"
25 #include "expr.h"
26 #include "hard-reg-set.h"
27 #include "insn-config.h"
28 #include "recog.h"
29 #include "insn-flags.h"
30 #include "insn-codes.h"
31
32 /* Return an rtx for the sum of X and the integer C.
33
34    This function should be used via the `plus_constant' macro.  */
35
36 rtx
37 plus_constant_wide (x, c)
38      register rtx x;
39      register HOST_WIDE_INT c;
40 {
41   register RTX_CODE code;
42   register enum machine_mode mode;
43   register rtx tem;
44   int all_constant = 0;
45
46   if (c == 0)
47     return x;
48
49  restart:
50
51   code = GET_CODE (x);
52   mode = GET_MODE (x);
53   switch (code)
54     {
55     case CONST_INT:
56       return GEN_INT (INTVAL (x) + c);
57
58     case CONST_DOUBLE:
59       {
60         HOST_WIDE_INT l1 = CONST_DOUBLE_LOW (x);
61         HOST_WIDE_INT h1 = CONST_DOUBLE_HIGH (x);
62         HOST_WIDE_INT l2 = c;
63         HOST_WIDE_INT h2 = c < 0 ? ~0 : 0;
64         HOST_WIDE_INT lv, hv;
65
66         add_double (l1, h1, l2, h2, &lv, &hv);
67
68         return immed_double_const (lv, hv, VOIDmode);
69       }
70
71     case MEM:
72       /* If this is a reference to the constant pool, try replacing it with
73          a reference to a new constant.  If the resulting address isn't
74          valid, don't return it because we have no way to validize it.  */
75       if (GET_CODE (XEXP (x, 0)) == SYMBOL_REF
76           && CONSTANT_POOL_ADDRESS_P (XEXP (x, 0)))
77         {
78           tem
79             = force_const_mem (GET_MODE (x),
80                                plus_constant (get_pool_constant (XEXP (x, 0)),
81                                               c));
82           if (memory_address_p (GET_MODE (tem), XEXP (tem, 0)))
83             return tem;
84         }
85       break;
86
87     case CONST:
88       /* If adding to something entirely constant, set a flag
89          so that we can add a CONST around the result.  */
90       x = XEXP (x, 0);
91       all_constant = 1;
92       goto restart;
93
94     case SYMBOL_REF:
95     case LABEL_REF:
96       all_constant = 1;
97       break;
98
99     case PLUS:
100       /* The interesting case is adding the integer to a sum.
101          Look for constant term in the sum and combine
102          with C.  For an integer constant term, we make a combined
103          integer.  For a constant term that is not an explicit integer,
104          we cannot really combine, but group them together anyway.  
105
106          Use a recursive call in case the remaining operand is something
107          that we handle specially, such as a SYMBOL_REF.  */
108
109       if (GET_CODE (XEXP (x, 1)) == CONST_INT)
110         return plus_constant (XEXP (x, 0), c + INTVAL (XEXP (x, 1)));
111       else if (CONSTANT_P (XEXP (x, 0)))
112         return gen_rtx (PLUS, mode,
113                         plus_constant (XEXP (x, 0), c),
114                         XEXP (x, 1));
115       else if (CONSTANT_P (XEXP (x, 1)))
116         return gen_rtx (PLUS, mode,
117                         XEXP (x, 0),
118                         plus_constant (XEXP (x, 1), c));
119     }
120
121   if (c != 0)
122     x = gen_rtx (PLUS, mode, x, GEN_INT (c));
123
124   if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == LABEL_REF)
125     return x;
126   else if (all_constant)
127     return gen_rtx (CONST, mode, x);
128   else
129     return x;
130 }
131
132 /* This is the same as `plus_constant', except that it handles LO_SUM.
133
134    This function should be used via the `plus_constant_for_output' macro.  */
135
136 rtx
137 plus_constant_for_output_wide (x, c)
138      register rtx x;
139      register HOST_WIDE_INT c;
140 {
141   register RTX_CODE code = GET_CODE (x);
142   register enum machine_mode mode = GET_MODE (x);
143   int all_constant = 0;
144
145   if (GET_CODE (x) == LO_SUM)
146     return gen_rtx (LO_SUM, mode, XEXP (x, 0),
147                     plus_constant_for_output (XEXP (x, 1), c));
148
149   else
150     return plus_constant (x, c);
151 }
152 \f
153 /* If X is a sum, return a new sum like X but lacking any constant terms.
154    Add all the removed constant terms into *CONSTPTR.
155    X itself is not altered.  The result != X if and only if
156    it is not isomorphic to X.  */
157
158 rtx
159 eliminate_constant_term (x, constptr)
160      rtx x;
161      rtx *constptr;
162 {
163   register rtx x0, x1;
164   rtx tem;
165
166   if (GET_CODE (x) != PLUS)
167     return x;
168
169   /* First handle constants appearing at this level explicitly.  */
170   if (GET_CODE (XEXP (x, 1)) == CONST_INT
171       && 0 != (tem = simplify_binary_operation (PLUS, GET_MODE (x), *constptr,
172                                                 XEXP (x, 1)))
173       && GET_CODE (tem) == CONST_INT)
174     {
175       *constptr = tem;
176       return eliminate_constant_term (XEXP (x, 0), constptr);
177     }
178
179   tem = const0_rtx;
180   x0 = eliminate_constant_term (XEXP (x, 0), &tem);
181   x1 = eliminate_constant_term (XEXP (x, 1), &tem);
182   if ((x1 != XEXP (x, 1) || x0 != XEXP (x, 0))
183       && 0 != (tem = simplify_binary_operation (PLUS, GET_MODE (x),
184                                                 *constptr, tem))
185       && GET_CODE (tem) == CONST_INT)
186     {
187       *constptr = tem;
188       return gen_rtx (PLUS, GET_MODE (x), x0, x1);
189     }
190
191   return x;
192 }
193
194 /* Returns the insn that next references REG after INSN, or 0
195    if REG is clobbered before next referenced or we cannot find
196    an insn that references REG in a straight-line piece of code.  */
197
198 rtx
199 find_next_ref (reg, insn)
200      rtx reg;
201      rtx insn;
202 {
203   rtx next;
204
205   for (insn = NEXT_INSN (insn); insn; insn = next)
206     {
207       next = NEXT_INSN (insn);
208       if (GET_CODE (insn) == NOTE)
209         continue;
210       if (GET_CODE (insn) == CODE_LABEL
211           || GET_CODE (insn) == BARRIER)
212         return 0;
213       if (GET_CODE (insn) == INSN
214           || GET_CODE (insn) == JUMP_INSN
215           || GET_CODE (insn) == CALL_INSN)
216         {
217           if (reg_set_p (reg, insn))
218             return 0;
219           if (reg_mentioned_p (reg, PATTERN (insn)))
220             return insn;
221           if (GET_CODE (insn) == JUMP_INSN)
222             {
223               if (simplejump_p (insn))
224                 next = JUMP_LABEL (insn);
225               else
226                 return 0;
227             }
228           if (GET_CODE (insn) == CALL_INSN
229               && REGNO (reg) < FIRST_PSEUDO_REGISTER
230               && call_used_regs[REGNO (reg)])
231             return 0;
232         }
233       else
234         abort ();
235     }
236   return 0;
237 }
238
239 /* Return an rtx for the size in bytes of the value of EXP.  */
240
241 rtx
242 expr_size (exp)
243      tree exp;
244 {
245   tree size = size_in_bytes (TREE_TYPE (exp));
246
247   if (TREE_CODE (size) != INTEGER_CST
248       && contains_placeholder_p (size))
249     size = build (WITH_RECORD_EXPR, sizetype, size, exp);
250
251   return expand_expr (size, NULL_RTX, TYPE_MODE (sizetype), 0);
252 }
253 \f
254 /* Return a copy of X in which all memory references
255    and all constants that involve symbol refs
256    have been replaced with new temporary registers.
257    Also emit code to load the memory locations and constants
258    into those registers.
259
260    If X contains no such constants or memory references,
261    X itself (not a copy) is returned.
262
263    If a constant is found in the address that is not a legitimate constant
264    in an insn, it is left alone in the hope that it might be valid in the
265    address.
266
267    X may contain no arithmetic except addition, subtraction and multiplication.
268    Values returned by expand_expr with 1 for sum_ok fit this constraint.  */
269
270 static rtx
271 break_out_memory_refs (x)
272      register rtx x;
273 {
274   if (GET_CODE (x) == MEM
275       || (CONSTANT_P (x) && CONSTANT_ADDRESS_P (x)
276           && GET_MODE (x) != VOIDmode))
277     {
278       register rtx temp = force_reg (GET_MODE (x), x);
279       mark_reg_pointer (temp);
280       x = temp;
281     }
282   else if (GET_CODE (x) == PLUS || GET_CODE (x) == MINUS
283            || GET_CODE (x) == MULT)
284     {
285       register rtx op0 = break_out_memory_refs (XEXP (x, 0));
286       register rtx op1 = break_out_memory_refs (XEXP (x, 1));
287       if (op0 != XEXP (x, 0) || op1 != XEXP (x, 1))
288         x = gen_rtx (GET_CODE (x), Pmode, op0, op1);
289     }
290   return x;
291 }
292
293 /* Given a memory address or facsimile X, construct a new address,
294    currently equivalent, that is stable: future stores won't change it.
295
296    X must be composed of constants, register and memory references
297    combined with addition, subtraction and multiplication:
298    in other words, just what you can get from expand_expr if sum_ok is 1.
299
300    Works by making copies of all regs and memory locations used
301    by X and combining them the same way X does.
302    You could also stabilize the reference to this address
303    by copying the address to a register with copy_to_reg;
304    but then you wouldn't get indexed addressing in the reference.  */
305
306 rtx
307 copy_all_regs (x)
308      register rtx x;
309 {
310   if (GET_CODE (x) == REG)
311     {
312       if (REGNO (x) != FRAME_POINTER_REGNUM
313 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
314           && REGNO (x) != HARD_FRAME_POINTER_REGNUM
315 #endif
316           )
317         x = copy_to_reg (x);
318     }
319   else if (GET_CODE (x) == MEM)
320     x = copy_to_reg (x);
321   else if (GET_CODE (x) == PLUS || GET_CODE (x) == MINUS
322            || GET_CODE (x) == MULT)
323     {
324       register rtx op0 = copy_all_regs (XEXP (x, 0));
325       register rtx op1 = copy_all_regs (XEXP (x, 1));
326       if (op0 != XEXP (x, 0) || op1 != XEXP (x, 1))
327         x = gen_rtx (GET_CODE (x), Pmode, op0, op1);
328     }
329   return x;
330 }
331 \f
332 /* Return something equivalent to X but valid as a memory address
333    for something of mode MODE.  When X is not itself valid, this
334    works by copying X or subexpressions of it into registers.  */
335
336 rtx
337 memory_address (mode, x)
338      enum machine_mode mode;
339      register rtx x;
340 {
341   register rtx oldx = x;
342
343   /* By passing constant addresses thru registers
344      we get a chance to cse them.  */
345   if (! cse_not_expected && CONSTANT_P (x) && CONSTANT_ADDRESS_P (x))
346     x = force_reg (Pmode, x);
347
348   /* Accept a QUEUED that refers to a REG
349      even though that isn't a valid address.
350      On attempting to put this in an insn we will call protect_from_queue
351      which will turn it into a REG, which is valid.  */
352   else if (GET_CODE (x) == QUEUED
353       && GET_CODE (QUEUED_VAR (x)) == REG)
354     ;
355
356   /* We get better cse by rejecting indirect addressing at this stage.
357      Let the combiner create indirect addresses where appropriate.
358      For now, generate the code so that the subexpressions useful to share
359      are visible.  But not if cse won't be done!  */
360   else
361     {
362       if (! cse_not_expected && GET_CODE (x) != REG)
363         x = break_out_memory_refs (x);
364
365       /* At this point, any valid address is accepted.  */
366       GO_IF_LEGITIMATE_ADDRESS (mode, x, win);
367
368       /* If it was valid before but breaking out memory refs invalidated it,
369          use it the old way.  */
370       if (memory_address_p (mode, oldx))
371         goto win2;
372
373       /* Perform machine-dependent transformations on X
374          in certain cases.  This is not necessary since the code
375          below can handle all possible cases, but machine-dependent
376          transformations can make better code.  */
377       LEGITIMIZE_ADDRESS (x, oldx, mode, win);
378
379       /* PLUS and MULT can appear in special ways
380          as the result of attempts to make an address usable for indexing.
381          Usually they are dealt with by calling force_operand, below.
382          But a sum containing constant terms is special
383          if removing them makes the sum a valid address:
384          then we generate that address in a register
385          and index off of it.  We do this because it often makes
386          shorter code, and because the addresses thus generated
387          in registers often become common subexpressions.  */
388       if (GET_CODE (x) == PLUS)
389         {
390           rtx constant_term = const0_rtx;
391           rtx y = eliminate_constant_term (x, &constant_term);
392           if (constant_term == const0_rtx
393               || ! memory_address_p (mode, y))
394             x = force_operand (x, NULL_RTX);
395           else
396             {
397               y = gen_rtx (PLUS, GET_MODE (x), copy_to_reg (y), constant_term);
398               if (! memory_address_p (mode, y))
399                 x = force_operand (x, NULL_RTX);
400               else
401                 x = y;
402             }
403         }
404
405       if (GET_CODE (x) == MULT || GET_CODE (x) == MINUS)
406         x = force_operand (x, NULL_RTX);
407
408       /* If we have a register that's an invalid address,
409          it must be a hard reg of the wrong class.  Copy it to a pseudo.  */
410       else if (GET_CODE (x) == REG)
411         x = copy_to_reg (x);
412
413       /* Last resort: copy the value to a register, since
414          the register is a valid address.  */
415       else
416         x = force_reg (Pmode, x);
417
418       goto done;
419     }
420
421  win2:
422   x = oldx;
423  win:
424   if (flag_force_addr && ! cse_not_expected && GET_CODE (x) != REG
425       /* Don't copy an addr via a reg if it is one of our stack slots.  */
426       && ! (GET_CODE (x) == PLUS
427             && (XEXP (x, 0) == virtual_stack_vars_rtx
428                 || XEXP (x, 0) == virtual_incoming_args_rtx)))
429     {
430       if (general_operand (x, Pmode))
431         x = force_reg (Pmode, x);
432       else
433         x = force_operand (x, NULL_RTX);
434     }
435
436  done:
437
438   /* OLDX may have been the address on a temporary.  Update the address
439      to indicate that X is now used.  */
440   update_temp_slot_address (oldx, x);
441
442   return x;
443 }
444
445 /* Like `memory_address' but pretend `flag_force_addr' is 0.  */
446
447 rtx
448 memory_address_noforce (mode, x)
449      enum machine_mode mode;
450      rtx x;
451 {
452   int ambient_force_addr = flag_force_addr;
453   rtx val;
454
455   flag_force_addr = 0;
456   val = memory_address (mode, x);
457   flag_force_addr = ambient_force_addr;
458   return val;
459 }
460
461 /* Convert a mem ref into one with a valid memory address.
462    Pass through anything else unchanged.  */
463
464 rtx
465 validize_mem (ref)
466      rtx ref;
467 {
468   if (GET_CODE (ref) != MEM)
469     return ref;
470   if (memory_address_p (GET_MODE (ref), XEXP (ref, 0)))
471     return ref;
472   /* Don't alter REF itself, since that is probably a stack slot.  */
473   return change_address (ref, GET_MODE (ref), XEXP (ref, 0));
474 }
475 \f
476 /* Return a modified copy of X with its memory address copied
477    into a temporary register to protect it from side effects.
478    If X is not a MEM, it is returned unchanged (and not copied).
479    Perhaps even if it is a MEM, if there is no need to change it.  */
480
481 rtx
482 stabilize (x)
483      rtx x;
484 {
485   register rtx addr;
486   if (GET_CODE (x) != MEM)
487     return x;
488   addr = XEXP (x, 0);
489   if (rtx_unstable_p (addr))
490     {
491       rtx temp = copy_all_regs (addr);
492       rtx mem;
493       if (GET_CODE (temp) != REG)
494         temp = copy_to_reg (temp);
495       mem = gen_rtx (MEM, GET_MODE (x), temp);
496
497       /* Mark returned memref with in_struct if it's in an array or
498          structure.  Copy const and volatile from original memref.  */
499
500       MEM_IN_STRUCT_P (mem) = MEM_IN_STRUCT_P (x) || GET_CODE (addr) == PLUS;
501       RTX_UNCHANGING_P (mem) = RTX_UNCHANGING_P (x);
502       MEM_VOLATILE_P (mem) = MEM_VOLATILE_P (x);
503       return mem;
504     }
505   return x;
506 }
507 \f
508 /* Copy the value or contents of X to a new temp reg and return that reg.  */
509
510 rtx
511 copy_to_reg (x)
512      rtx x;
513 {
514   register rtx temp = gen_reg_rtx (GET_MODE (x));
515  
516   /* If not an operand, must be an address with PLUS and MULT so
517      do the computation.  */ 
518   if (! general_operand (x, VOIDmode))
519     x = force_operand (x, temp);
520   
521   if (x != temp)
522     emit_move_insn (temp, x);
523
524   return temp;
525 }
526
527 /* Like copy_to_reg but always give the new register mode Pmode
528    in case X is a constant.  */
529
530 rtx
531 copy_addr_to_reg (x)
532      rtx x;
533 {
534   return copy_to_mode_reg (Pmode, x);
535 }
536
537 /* Like copy_to_reg but always give the new register mode MODE
538    in case X is a constant.  */
539
540 rtx
541 copy_to_mode_reg (mode, x)
542      enum machine_mode mode;
543      rtx x;
544 {
545   register rtx temp = gen_reg_rtx (mode);
546   
547   /* If not an operand, must be an address with PLUS and MULT so
548      do the computation.  */ 
549   if (! general_operand (x, VOIDmode))
550     x = force_operand (x, temp);
551
552   if (GET_MODE (x) != mode && GET_MODE (x) != VOIDmode)
553     abort ();
554   if (x != temp)
555     emit_move_insn (temp, x);
556   return temp;
557 }
558
559 /* Load X into a register if it is not already one.
560    Use mode MODE for the register.
561    X should be valid for mode MODE, but it may be a constant which
562    is valid for all integer modes; that's why caller must specify MODE.
563
564    The caller must not alter the value in the register we return,
565    since we mark it as a "constant" register.  */
566
567 rtx
568 force_reg (mode, x)
569      enum machine_mode mode;
570      rtx x;
571 {
572   register rtx temp, insn;
573
574   if (GET_CODE (x) == REG)
575     return x;
576   temp = gen_reg_rtx (mode);
577   insn = emit_move_insn (temp, x);
578   /* Let optimizers know that TEMP's value never changes
579      and that X can be substituted for it.  */
580   if (CONSTANT_P (x))
581     {
582       rtx note = find_reg_note (insn, REG_EQUAL, NULL_RTX);
583
584       if (note)
585         XEXP (note, 0) = x;
586       else
587         REG_NOTES (insn) = gen_rtx (EXPR_LIST, REG_EQUAL, x, REG_NOTES (insn));
588     }
589   return temp;
590 }
591
592 /* If X is a memory ref, copy its contents to a new temp reg and return
593    that reg.  Otherwise, return X.  */
594
595 rtx
596 force_not_mem (x)
597      rtx x;
598 {
599   register rtx temp;
600   if (GET_CODE (x) != MEM || GET_MODE (x) == BLKmode)
601     return x;
602   temp = gen_reg_rtx (GET_MODE (x));
603   emit_move_insn (temp, x);
604   return temp;
605 }
606
607 /* Copy X to TARGET (if it's nonzero and a reg)
608    or to a new temp reg and return that reg.
609    MODE is the mode to use for X in case it is a constant.  */
610
611 rtx
612 copy_to_suggested_reg (x, target, mode)
613      rtx x, target;
614      enum machine_mode mode;
615 {
616   register rtx temp;
617
618   if (target && GET_CODE (target) == REG)
619     temp = target;
620   else
621     temp = gen_reg_rtx (mode);
622
623   emit_move_insn (temp, x);
624   return temp;
625 }
626 \f
627 /* Adjust the stack pointer by ADJUST (an rtx for a number of bytes).
628    This pops when ADJUST is positive.  ADJUST need not be constant.  */
629
630 void
631 adjust_stack (adjust)
632      rtx adjust;
633 {
634   rtx temp;
635   adjust = protect_from_queue (adjust, 0);
636
637   if (adjust == const0_rtx)
638     return;
639
640   temp = expand_binop (Pmode,
641 #ifdef STACK_GROWS_DOWNWARD
642                        add_optab,
643 #else
644                        sub_optab,
645 #endif
646                        stack_pointer_rtx, adjust, stack_pointer_rtx, 0,
647                        OPTAB_LIB_WIDEN);
648
649   if (temp != stack_pointer_rtx)
650     emit_move_insn (stack_pointer_rtx, temp);
651 }
652
653 /* Adjust the stack pointer by minus ADJUST (an rtx for a number of bytes).
654    This pushes when ADJUST is positive.  ADJUST need not be constant.  */
655
656 void
657 anti_adjust_stack (adjust)
658      rtx adjust;
659 {
660   rtx temp;
661   adjust = protect_from_queue (adjust, 0);
662
663   if (adjust == const0_rtx)
664     return;
665
666   temp = expand_binop (Pmode,
667 #ifdef STACK_GROWS_DOWNWARD
668                        sub_optab,
669 #else
670                        add_optab,
671 #endif
672                        stack_pointer_rtx, adjust, stack_pointer_rtx, 0,
673                        OPTAB_LIB_WIDEN);
674
675   if (temp != stack_pointer_rtx)
676     emit_move_insn (stack_pointer_rtx, temp);
677 }
678
679 /* Round the size of a block to be pushed up to the boundary required
680    by this machine.  SIZE is the desired size, which need not be constant.  */
681
682 rtx
683 round_push (size)
684      rtx size;
685 {
686 #ifdef STACK_BOUNDARY
687   int align = STACK_BOUNDARY / BITS_PER_UNIT;
688   if (align == 1)
689     return size;
690   if (GET_CODE (size) == CONST_INT)
691     {
692       int new = (INTVAL (size) + align - 1) / align * align;
693       if (INTVAL (size) != new)
694         size = GEN_INT (new);
695     }
696   else
697     {
698       size = expand_divmod (0, CEIL_DIV_EXPR, Pmode, size, GEN_INT (align),
699                             NULL_RTX, 1);
700       size = expand_mult (Pmode, size, GEN_INT (align), NULL_RTX, 1);
701     }
702 #endif /* STACK_BOUNDARY */
703   return size;
704 }
705 \f
706 /* Save the stack pointer for the purpose in SAVE_LEVEL.  PSAVE is a pointer
707    to a previously-created save area.  If no save area has been allocated,
708    this function will allocate one.  If a save area is specified, it
709    must be of the proper mode.
710
711    The insns are emitted after insn AFTER, if nonzero, otherwise the insns
712    are emitted at the current position.  */
713
714 void
715 emit_stack_save (save_level, psave, after)
716      enum save_level save_level;
717      rtx *psave;
718      rtx after;
719 {
720   rtx sa = *psave;
721   /* The default is that we use a move insn and save in a Pmode object.  */
722   rtx (*fcn) () = gen_move_insn;
723   enum machine_mode mode = Pmode;
724
725   /* See if this machine has anything special to do for this kind of save.  */
726   switch (save_level)
727     {
728 #ifdef HAVE_save_stack_block
729     case SAVE_BLOCK:
730       if (HAVE_save_stack_block)
731         {
732           fcn = gen_save_stack_block;
733           mode = insn_operand_mode[CODE_FOR_save_stack_block][0];
734         }
735       break;
736 #endif
737 #ifdef HAVE_save_stack_function
738     case SAVE_FUNCTION:
739       if (HAVE_save_stack_function)
740         {
741           fcn = gen_save_stack_function;
742           mode = insn_operand_mode[CODE_FOR_save_stack_function][0];
743         }
744       break;
745 #endif
746 #ifdef HAVE_save_stack_nonlocal
747     case SAVE_NONLOCAL:
748       if (HAVE_save_stack_nonlocal)
749         {
750           fcn = gen_save_stack_nonlocal;
751           mode = insn_operand_mode[(int) CODE_FOR_save_stack_nonlocal][0];
752         }
753       break;
754 #endif
755     }
756
757   /* If there is no save area and we have to allocate one, do so.  Otherwise
758      verify the save area is the proper mode.  */
759
760   if (sa == 0)
761     {
762       if (mode != VOIDmode)
763         {
764           if (save_level == SAVE_NONLOCAL)
765             *psave = sa = assign_stack_local (mode, GET_MODE_SIZE (mode), 0);
766           else
767             *psave = sa = gen_reg_rtx (mode);
768         }
769     }
770   else
771     {
772       if (mode == VOIDmode || GET_MODE (sa) != mode)
773         abort ();
774     }
775
776   if (after)
777     {
778       rtx seq;
779
780       start_sequence ();
781       /* We must validize inside the sequence, to ensure that any instructions
782          created by the validize call also get moved to the right place.  */
783       if (sa != 0)
784         sa = validize_mem (sa);
785       emit_insn (fcn (sa, stack_pointer_rtx));
786       seq = gen_sequence ();
787       end_sequence ();
788       emit_insn_after (seq, after);
789     }
790   else
791     {
792       if (sa != 0)
793         sa = validize_mem (sa);
794       emit_insn (fcn (sa, stack_pointer_rtx));
795     }
796 }
797
798 /* Restore the stack pointer for the purpose in SAVE_LEVEL.  SA is the save
799    area made by emit_stack_save.  If it is zero, we have nothing to do. 
800
801    Put any emitted insns after insn AFTER, if nonzero, otherwise at 
802    current position.  */
803
804 void
805 emit_stack_restore (save_level, sa, after)
806      enum save_level save_level;
807      rtx after;
808      rtx sa;
809 {
810   /* The default is that we use a move insn.  */
811   rtx (*fcn) () = gen_move_insn;
812
813   /* See if this machine has anything special to do for this kind of save.  */
814   switch (save_level)
815     {
816 #ifdef HAVE_restore_stack_block
817     case SAVE_BLOCK:
818       if (HAVE_restore_stack_block)
819         fcn = gen_restore_stack_block;
820       break;
821 #endif
822 #ifdef HAVE_restore_stack_function
823     case SAVE_FUNCTION:
824       if (HAVE_restore_stack_function)
825         fcn = gen_restore_stack_function;
826       break;
827 #endif
828 #ifdef HAVE_restore_stack_nonlocal
829
830     case SAVE_NONLOCAL:
831       if (HAVE_restore_stack_nonlocal)
832         fcn = gen_restore_stack_nonlocal;
833       break;
834 #endif
835     }
836
837   if (sa != 0)
838     sa = validize_mem (sa);
839
840   if (after)
841     {
842       rtx seq;
843
844       start_sequence ();
845       emit_insn (fcn (stack_pointer_rtx, sa));
846       seq = gen_sequence ();
847       end_sequence ();
848       emit_insn_after (seq, after);
849     }
850   else
851     emit_insn (fcn (stack_pointer_rtx, sa));
852 }
853 \f
854 /* Return an rtx representing the address of an area of memory dynamically
855    pushed on the stack.  This region of memory is always aligned to
856    a multiple of BIGGEST_ALIGNMENT.
857
858    Any required stack pointer alignment is preserved.
859
860    SIZE is an rtx representing the size of the area.
861    TARGET is a place in which the address can be placed.
862
863    KNOWN_ALIGN is the alignment (in bits) that we know SIZE has.  */
864
865 rtx
866 allocate_dynamic_stack_space (size, target, known_align)
867      rtx size;
868      rtx target;
869      int known_align;
870 {
871   /* Ensure the size is in the proper mode.  */
872   if (GET_MODE (size) != VOIDmode && GET_MODE (size) != Pmode)
873     size = convert_to_mode (Pmode, size, 1);
874
875   /* We will need to ensure that the address we return is aligned to
876      BIGGEST_ALIGNMENT.  If STACK_DYNAMIC_OFFSET is defined, we don't
877      always know its final value at this point in the compilation (it 
878      might depend on the size of the outgoing parameter lists, for
879      example), so we must align the value to be returned in that case.
880      (Note that STACK_DYNAMIC_OFFSET will have a default non-zero value if
881      STACK_POINTER_OFFSET or ACCUMULATE_OUTGOING_ARGS are defined).
882      We must also do an alignment operation on the returned value if
883      the stack pointer alignment is less strict that BIGGEST_ALIGNMENT.
884
885      If we have to align, we must leave space in SIZE for the hole
886      that might result from the alignment operation.  */
887
888 #if defined (STACK_DYNAMIC_OFFSET) || defined(STACK_POINTER_OFFSET) || defined (ALLOCATE_OUTGOING_ARGS)
889 #define MUST_ALIGN
890 #endif
891
892 #if ! defined (MUST_ALIGN) && (!defined(STACK_BOUNDARY) || STACK_BOUNDARY < BIGGEST_ALIGNMENT)
893 #define MUST_ALIGN
894 #endif
895
896 #ifdef MUST_ALIGN
897
898 #if 0 /* It turns out we must always make extra space, if MUST_ALIGN
899          because we must always round the address up at the end,
900          because we don't know whether the dynamic offset
901          will mess up the desired alignment.  */
902   /* If we have to round the address up regardless of known_align,
903      make extra space regardless, also.  */
904   if (known_align % BIGGEST_ALIGNMENT != 0)
905 #endif
906     {
907       if (GET_CODE (size) == CONST_INT)
908         size = GEN_INT (INTVAL (size)
909                         + (BIGGEST_ALIGNMENT / BITS_PER_UNIT - 1));
910       else
911         size = expand_binop (Pmode, add_optab, size,
912                              GEN_INT (BIGGEST_ALIGNMENT / BITS_PER_UNIT - 1),
913                              NULL_RTX, 1, OPTAB_LIB_WIDEN);
914     }
915
916 #endif
917
918 #ifdef SETJMP_VIA_SAVE_AREA
919   /* If setjmp restores regs from a save area in the stack frame,
920      avoid clobbering the reg save area.  Note that the offset of
921      virtual_incoming_args_rtx includes the preallocated stack args space.
922      It would be no problem to clobber that, but it's on the wrong side
923      of the old save area.  */
924   {
925     rtx dynamic_offset
926       = expand_binop (Pmode, sub_optab, virtual_stack_dynamic_rtx,
927                       stack_pointer_rtx, NULL_RTX, 1, OPTAB_LIB_WIDEN);
928     size = expand_binop (Pmode, add_optab, size, dynamic_offset,
929                          NULL_RTX, 1, OPTAB_LIB_WIDEN);
930   }
931 #endif /* SETJMP_VIA_SAVE_AREA */
932
933   /* Round the size to a multiple of the required stack alignment.
934      Since the stack if presumed to be rounded before this allocation,
935      this will maintain the required alignment.
936
937      If the stack grows downward, we could save an insn by subtracting
938      SIZE from the stack pointer and then aligning the stack pointer.
939      The problem with this is that the stack pointer may be unaligned
940      between the execution of the subtraction and alignment insns and
941      some machines do not allow this.  Even on those that do, some
942      signal handlers malfunction if a signal should occur between those
943      insns.  Since this is an extremely rare event, we have no reliable
944      way of knowing which systems have this problem.  So we avoid even
945      momentarily mis-aligning the stack.  */
946
947 #ifdef STACK_BOUNDARY
948   /* If we added a variable amount to SIZE,
949      we can no longer assume it is aligned.  */
950 #if !defined (SETJMP_VIA_SAVE_AREA) && !defined (MUST_ALIGN)
951   if (known_align % STACK_BOUNDARY != 0)
952 #endif
953     size = round_push (size);
954 #endif
955
956   do_pending_stack_adjust ();
957
958   /* Don't use a TARGET that isn't a pseudo.  */
959   if (target == 0 || GET_CODE (target) != REG
960       || REGNO (target) < FIRST_PSEUDO_REGISTER)
961     target = gen_reg_rtx (Pmode);
962
963   mark_reg_pointer (target);
964
965 #ifndef STACK_GROWS_DOWNWARD
966   emit_move_insn (target, virtual_stack_dynamic_rtx);
967 #endif
968
969   /* Perform the required allocation from the stack.  Some systems do
970      this differently than simply incrementing/decrementing from the
971      stack pointer.  */
972 #ifdef HAVE_allocate_stack
973   if (HAVE_allocate_stack)
974     {
975       enum machine_mode mode
976         = insn_operand_mode[(int) CODE_FOR_allocate_stack][0];
977
978       if (insn_operand_predicate[(int) CODE_FOR_allocate_stack][0]
979           && ! ((*insn_operand_predicate[(int) CODE_FOR_allocate_stack][0])
980                 (size, mode)))
981         size = copy_to_mode_reg (mode, size);
982
983       emit_insn (gen_allocate_stack (size));
984     }
985   else
986 #endif
987     anti_adjust_stack (size);
988
989 #ifdef STACK_GROWS_DOWNWARD
990   emit_move_insn (target, virtual_stack_dynamic_rtx);
991 #endif
992
993 #ifdef MUST_ALIGN
994 #if 0  /* Even if we know the stack pointer has enough alignment,
995           there's no way to tell whether virtual_stack_dynamic_rtx shares that
996           alignment, so we still need to round the address up.  */
997   if (known_align % BIGGEST_ALIGNMENT != 0)
998 #endif
999     {
1000       target = expand_divmod (0, CEIL_DIV_EXPR, Pmode, target,
1001                               GEN_INT (BIGGEST_ALIGNMENT / BITS_PER_UNIT),
1002                               NULL_RTX, 1);
1003
1004       target = expand_mult (Pmode, target,
1005                             GEN_INT (BIGGEST_ALIGNMENT / BITS_PER_UNIT),
1006                             NULL_RTX, 1);
1007     }
1008 #endif
1009   
1010   /* Some systems require a particular insn to refer to the stack
1011      to make the pages exist.  */
1012 #ifdef HAVE_probe
1013   if (HAVE_probe)
1014     emit_insn (gen_probe ());
1015 #endif
1016
1017   return target;
1018 }
1019 \f
1020 /* Return an rtx representing the register or memory location
1021    in which a scalar value of data type VALTYPE
1022    was returned by a function call to function FUNC.
1023    FUNC is a FUNCTION_DECL node if the precise function is known,
1024    otherwise 0.  */
1025
1026 rtx
1027 hard_function_value (valtype, func)
1028      tree valtype;
1029      tree func;
1030 {
1031   return FUNCTION_VALUE (valtype, func);
1032 }
1033
1034 /* Return an rtx representing the register or memory location
1035    in which a scalar value of mode MODE was returned by a library call.  */
1036
1037 rtx
1038 hard_libcall_value (mode)
1039      enum machine_mode mode;
1040 {
1041   return LIBCALL_VALUE (mode);
1042 }
1043
1044 /* Look up the tree code for a given rtx code
1045    to provide the arithmetic operation for REAL_ARITHMETIC.
1046    The function returns an int because the caller may not know
1047    what `enum tree_code' means.  */
1048
1049 int
1050 rtx_to_tree_code (code)
1051      enum rtx_code code;
1052 {
1053   enum tree_code tcode;
1054
1055   switch (code)
1056     {
1057     case PLUS:
1058       tcode = PLUS_EXPR;
1059       break;
1060     case MINUS:
1061       tcode = MINUS_EXPR;
1062       break;
1063     case MULT:
1064       tcode = MULT_EXPR;
1065       break;
1066     case DIV:
1067       tcode = RDIV_EXPR;
1068       break;
1069     case SMIN:
1070       tcode = MIN_EXPR;
1071       break;
1072     case SMAX:
1073       tcode = MAX_EXPR;
1074       break;
1075     default:
1076       tcode = LAST_AND_UNUSED_TREE_CODE;
1077       break;
1078     }
1079   return ((int) tcode);
1080 }