OSDN Git Service

gcc/
[pf3gnuchains/gcc-fork.git] / gcc / config / vax / vax.c
1 /* Subroutines for insn-output.c for VAX.
2    Copyright (C) 1987, 1994, 1995, 1997, 1998, 1999, 2000, 2001, 2002,
3    2004, 2005, 2006, 2007, 2008, 2009, 2010
4    Free Software Foundation, Inc.
5
6 This file is part of GCC.
7
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
11 any later version.
12
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3.  If not see
20 <http://www.gnu.org/licenses/>.  */
21
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26 #include "rtl.h"
27 #include "df.h"
28 #include "tree.h"
29 #include "regs.h"
30 #include "hard-reg-set.h"
31 #include "insn-config.h"
32 #include "conditions.h"
33 #include "function.h"
34 #include "output.h"
35 #include "insn-attr.h"
36 #include "recog.h"
37 #include "expr.h"
38 #include "optabs.h"
39 #include "flags.h"
40 #include "debug.h"
41 #include "diagnostic-core.h"
42 #include "reload.h"
43 #include "tm-preds.h"
44 #include "tm-constrs.h"
45 #include "tm_p.h"
46 #include "target.h"
47 #include "target-def.h"
48
49 static void vax_option_override (void);
50 static bool vax_legitimate_address_p (enum machine_mode, rtx, bool);
51 static void vax_output_function_prologue (FILE *, HOST_WIDE_INT);
52 static void vax_file_start (void);
53 static void vax_init_libfuncs (void);
54 static void vax_output_mi_thunk (FILE *, tree, HOST_WIDE_INT,
55                                  HOST_WIDE_INT, tree);
56 static int vax_address_cost_1 (rtx);
57 static int vax_address_cost (rtx, bool);
58 static bool vax_rtx_costs (rtx, int, int, int *, bool);
59 static rtx vax_function_arg (CUMULATIVE_ARGS *, enum machine_mode,
60                              const_tree, bool);
61 static void vax_function_arg_advance (CUMULATIVE_ARGS *, enum machine_mode,
62                                       const_tree, bool);
63 static rtx vax_struct_value_rtx (tree, int);
64 static rtx vax_builtin_setjmp_frame_value (void);
65 static void vax_asm_trampoline_template (FILE *);
66 static void vax_trampoline_init (rtx, tree, rtx);
67 static int vax_return_pops_args (tree, tree, int);
68 \f
69 /* Initialize the GCC target structure.  */
70 #undef TARGET_ASM_ALIGNED_HI_OP
71 #define TARGET_ASM_ALIGNED_HI_OP "\t.word\t"
72
73 #undef TARGET_ASM_FUNCTION_PROLOGUE
74 #define TARGET_ASM_FUNCTION_PROLOGUE vax_output_function_prologue
75
76 #undef TARGET_ASM_FILE_START
77 #define TARGET_ASM_FILE_START vax_file_start
78 #undef TARGET_ASM_FILE_START_APP_OFF
79 #define TARGET_ASM_FILE_START_APP_OFF true
80
81 #undef TARGET_INIT_LIBFUNCS
82 #define TARGET_INIT_LIBFUNCS vax_init_libfuncs
83
84 #undef TARGET_ASM_OUTPUT_MI_THUNK
85 #define TARGET_ASM_OUTPUT_MI_THUNK vax_output_mi_thunk
86 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
87 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall
88
89 #undef TARGET_DEFAULT_TARGET_FLAGS
90 #define TARGET_DEFAULT_TARGET_FLAGS TARGET_DEFAULT
91
92 #undef TARGET_RTX_COSTS
93 #define TARGET_RTX_COSTS vax_rtx_costs
94 #undef TARGET_ADDRESS_COST
95 #define TARGET_ADDRESS_COST vax_address_cost
96
97 #undef TARGET_PROMOTE_PROTOTYPES
98 #define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
99
100 #undef TARGET_FUNCTION_ARG
101 #define TARGET_FUNCTION_ARG vax_function_arg
102 #undef TARGET_FUNCTION_ARG_ADVANCE
103 #define TARGET_FUNCTION_ARG_ADVANCE vax_function_arg_advance
104
105 #undef TARGET_STRUCT_VALUE_RTX
106 #define TARGET_STRUCT_VALUE_RTX vax_struct_value_rtx
107
108 #undef TARGET_BUILTIN_SETJMP_FRAME_VALUE
109 #define TARGET_BUILTIN_SETJMP_FRAME_VALUE vax_builtin_setjmp_frame_value
110
111 #undef TARGET_LEGITIMATE_ADDRESS_P
112 #define TARGET_LEGITIMATE_ADDRESS_P vax_legitimate_address_p
113
114 #undef TARGET_FRAME_POINTER_REQUIRED
115 #define TARGET_FRAME_POINTER_REQUIRED hook_bool_void_true
116
117 #undef TARGET_ASM_TRAMPOLINE_TEMPLATE
118 #define TARGET_ASM_TRAMPOLINE_TEMPLATE vax_asm_trampoline_template
119 #undef TARGET_TRAMPOLINE_INIT
120 #define TARGET_TRAMPOLINE_INIT vax_trampoline_init
121 #undef TARGET_RETURN_POPS_ARGS
122 #define TARGET_RETURN_POPS_ARGS vax_return_pops_args
123
124 #undef TARGET_OPTION_OVERRIDE
125 #define TARGET_OPTION_OVERRIDE vax_option_override
126
127 struct gcc_target targetm = TARGET_INITIALIZER;
128 \f
129 /* Set global variables as needed for the options enabled.  */
130
131 static void
132 vax_option_override (void)
133 {
134   /* We're VAX floating point, not IEEE floating point.  */
135   if (TARGET_G_FLOAT)
136     REAL_MODE_FORMAT (DFmode) = &vax_g_format;
137
138 #ifdef SUBTARGET_OVERRIDE_OPTIONS
139   SUBTARGET_OVERRIDE_OPTIONS;
140 #endif
141 }
142
143 /* Generate the assembly code for function entry.  FILE is a stdio
144    stream to output the code to.  SIZE is an int: how many units of
145    temporary storage to allocate.
146
147    Refer to the array `regs_ever_live' to determine which registers to
148    save; `regs_ever_live[I]' is nonzero if register number I is ever
149    used in the function.  This function is responsible for knowing
150    which registers should not be saved even if used.  */
151
152 static void
153 vax_output_function_prologue (FILE * file, HOST_WIDE_INT size)
154 {
155   int regno;
156   int mask = 0;
157
158   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
159     if (df_regs_ever_live_p (regno) && !call_used_regs[regno])
160       mask |= 1 << regno;
161
162   fprintf (file, "\t.word 0x%x\n", mask);
163
164   if (dwarf2out_do_frame ())
165     {
166       const char *label = dwarf2out_cfi_label (false);
167       int offset = 0;
168
169       for (regno = FIRST_PSEUDO_REGISTER-1; regno >= 0; --regno)
170         if (df_regs_ever_live_p (regno) && !call_used_regs[regno])
171           dwarf2out_reg_save (label, regno, offset -= 4);
172
173       dwarf2out_reg_save (label, PC_REGNUM, offset -= 4);
174       dwarf2out_reg_save (label, FRAME_POINTER_REGNUM, offset -= 4);
175       dwarf2out_reg_save (label, ARG_POINTER_REGNUM, offset -= 4);
176       dwarf2out_def_cfa (label, FRAME_POINTER_REGNUM, -(offset - 4));
177     }
178
179   size -= STARTING_FRAME_OFFSET;
180   if (size >= 64)
181     asm_fprintf (file, "\tmovab %wd(%Rsp),%Rsp\n", -size);
182   else if (size)
183     asm_fprintf (file, "\tsubl2 $%wd,%Rsp\n", size);
184 }
185
186 /* When debugging with stabs, we want to output an extra dummy label
187    so that gas can distinguish between D_float and G_float prior to
188    processing the .stabs directive identifying type double.  */
189 static void
190 vax_file_start (void)
191 {
192   default_file_start ();
193
194   if (write_symbols == DBX_DEBUG)
195     fprintf (asm_out_file, "___vax_%c_doubles:\n", ASM_DOUBLE_CHAR);
196 }
197
198 /* We can use the BSD C library routines for the libgcc calls that are
199    still generated, since that's what they boil down to anyways.  When
200    ELF, avoid the user's namespace.  */
201
202 static void
203 vax_init_libfuncs (void)
204 {
205   if (TARGET_BSD_DIVMOD)
206     {
207       set_optab_libfunc (udiv_optab, SImode, TARGET_ELF ? "*__udiv" : "*udiv");
208       set_optab_libfunc (umod_optab, SImode, TARGET_ELF ? "*__urem" : "*urem");
209     }
210 }
211
212 /* This is like nonimmediate_operand with a restriction on the type of MEM.  */
213
214 static void
215 split_quadword_operands (rtx insn, enum rtx_code code, rtx * operands,
216                          rtx * low, int n)
217 {
218   int i;
219
220   for (i = 0; i < n; i++)
221     low[i] = 0;
222
223   for (i = 0; i < n; i++)
224     {
225       if (MEM_P (operands[i])
226           && (GET_CODE (XEXP (operands[i], 0)) == PRE_DEC
227               || GET_CODE (XEXP (operands[i], 0)) == POST_INC))
228         {
229           rtx addr = XEXP (operands[i], 0);
230           operands[i] = low[i] = gen_rtx_MEM (SImode, addr);
231         }
232       else if (optimize_size && MEM_P (operands[i])
233                && REG_P (XEXP (operands[i], 0))
234                && (code != MINUS || operands[1] != const0_rtx)
235                && find_regno_note (insn, REG_DEAD,
236                                    REGNO (XEXP (operands[i], 0))))
237         {
238           low[i] = gen_rtx_MEM (SImode,
239                                 gen_rtx_POST_INC (Pmode,
240                                                   XEXP (operands[i], 0)));
241           operands[i] = gen_rtx_MEM (SImode, XEXP (operands[i], 0));
242         }
243       else
244         {
245           low[i] = operand_subword (operands[i], 0, 0, DImode);
246           operands[i] = operand_subword (operands[i], 1, 0, DImode);
247         }
248     }
249 }
250 \f
251 void
252 print_operand_address (FILE * file, rtx addr)
253 {
254   rtx orig = addr;
255   rtx reg1, breg, ireg;
256   rtx offset;
257
258  retry:
259   switch (GET_CODE (addr))
260     {
261     case MEM:
262       fprintf (file, "*");
263       addr = XEXP (addr, 0);
264       goto retry;
265
266     case REG:
267       fprintf (file, "(%s)", reg_names[REGNO (addr)]);
268       break;
269
270     case PRE_DEC:
271       fprintf (file, "-(%s)", reg_names[REGNO (XEXP (addr, 0))]);
272       break;
273
274     case POST_INC:
275       fprintf (file, "(%s)+", reg_names[REGNO (XEXP (addr, 0))]);
276       break;
277
278     case PLUS:
279       /* There can be either two or three things added here.  One must be a
280          REG.  One can be either a REG or a MULT of a REG and an appropriate
281          constant, and the third can only be a constant or a MEM.
282
283          We get these two or three things and put the constant or MEM in
284          OFFSET, the MULT or REG in IREG, and the REG in BREG.  If we have
285          a register and can't tell yet if it is a base or index register,
286          put it into REG1.  */
287
288       reg1 = 0; ireg = 0; breg = 0; offset = 0;
289
290       if (CONSTANT_ADDRESS_P (XEXP (addr, 0))
291           || MEM_P (XEXP (addr, 0)))
292         {
293           offset = XEXP (addr, 0);
294           addr = XEXP (addr, 1);
295         }
296       else if (CONSTANT_ADDRESS_P (XEXP (addr, 1))
297                || MEM_P (XEXP (addr, 1)))
298         {
299           offset = XEXP (addr, 1);
300           addr = XEXP (addr, 0);
301         }
302       else if (GET_CODE (XEXP (addr, 1)) == MULT)
303         {
304           ireg = XEXP (addr, 1);
305           addr = XEXP (addr, 0);
306         }
307       else if (GET_CODE (XEXP (addr, 0)) == MULT)
308         {
309           ireg = XEXP (addr, 0);
310           addr = XEXP (addr, 1);
311         }
312       else if (REG_P (XEXP (addr, 1)))
313         {
314           reg1 = XEXP (addr, 1);
315           addr = XEXP (addr, 0);
316         }
317       else if (REG_P (XEXP (addr, 0)))
318         {
319           reg1 = XEXP (addr, 0);
320           addr = XEXP (addr, 1);
321         }
322       else
323         gcc_unreachable ();
324
325       if (REG_P (addr))
326         {
327           if (reg1)
328             ireg = addr;
329           else
330             reg1 = addr;
331         }
332       else if (GET_CODE (addr) == MULT)
333         ireg = addr;
334       else
335         {
336           gcc_assert (GET_CODE (addr) == PLUS);
337           if (CONSTANT_ADDRESS_P (XEXP (addr, 0))
338               || MEM_P (XEXP (addr, 0)))
339             {
340               if (offset)
341                 {
342                   if (CONST_INT_P (offset))
343                     offset = plus_constant (XEXP (addr, 0), INTVAL (offset));
344                   else
345                     {
346                       gcc_assert (CONST_INT_P (XEXP (addr, 0)));
347                       offset = plus_constant (offset, INTVAL (XEXP (addr, 0)));
348                     }
349                 }
350               offset = XEXP (addr, 0);
351             }
352           else if (REG_P (XEXP (addr, 0)))
353             {
354               if (reg1)
355                 ireg = reg1, breg = XEXP (addr, 0), reg1 = 0;
356               else
357                 reg1 = XEXP (addr, 0);
358             }
359           else
360             {
361               gcc_assert (GET_CODE (XEXP (addr, 0)) == MULT);
362               gcc_assert (!ireg);
363               ireg = XEXP (addr, 0);
364             }
365
366           if (CONSTANT_ADDRESS_P (XEXP (addr, 1))
367               || MEM_P (XEXP (addr, 1)))
368             {
369               if (offset)
370                 {
371                   if (CONST_INT_P (offset))
372                     offset = plus_constant (XEXP (addr, 1), INTVAL (offset));
373                   else
374                     {
375                       gcc_assert (CONST_INT_P (XEXP (addr, 1)));
376                       offset = plus_constant (offset, INTVAL (XEXP (addr, 1)));
377                     }
378                 }
379               offset = XEXP (addr, 1);
380             }
381           else if (REG_P (XEXP (addr, 1)))
382             {
383               if (reg1)
384                 ireg = reg1, breg = XEXP (addr, 1), reg1 = 0;
385               else
386                 reg1 = XEXP (addr, 1);
387             }
388           else
389             {
390               gcc_assert (GET_CODE (XEXP (addr, 1)) == MULT);
391               gcc_assert (!ireg);
392               ireg = XEXP (addr, 1);
393             }
394         }
395
396       /* If REG1 is nonzero, figure out if it is a base or index register.  */
397       if (reg1)
398         {
399           if (breg
400               || (flag_pic && GET_CODE (addr) == SYMBOL_REF)
401               || (offset
402                   && (MEM_P (offset)
403                       || (flag_pic && symbolic_operand (offset, SImode)))))
404             {
405               gcc_assert (!ireg);
406               ireg = reg1;
407             }
408           else
409             breg = reg1;
410         }
411
412       if (offset != 0)
413         {
414           if (flag_pic && symbolic_operand (offset, SImode))
415             {
416               if (breg && ireg)
417                 {
418                   debug_rtx (orig);
419                   output_operand_lossage ("symbol used with both base and indexed registers");
420                 }
421
422 #ifdef NO_EXTERNAL_INDIRECT_ADDRESS
423               if (flag_pic > 1 && GET_CODE (offset) == CONST
424                   && GET_CODE (XEXP (XEXP (offset, 0), 0)) == SYMBOL_REF
425                   && !SYMBOL_REF_LOCAL_P (XEXP (XEXP (offset, 0), 0)))
426                 {
427                   debug_rtx (orig);
428                   output_operand_lossage ("symbol with offset used in PIC mode");
429                 }
430 #endif
431
432               /* symbol(reg) isn't PIC, but symbol[reg] is.  */
433               if (breg)
434                 {
435                   ireg = breg;
436                   breg = 0;
437                 }
438
439             }
440
441           output_address (offset);
442         }
443
444       if (breg != 0)
445         fprintf (file, "(%s)", reg_names[REGNO (breg)]);
446
447       if (ireg != 0)
448         {
449           if (GET_CODE (ireg) == MULT)
450             ireg = XEXP (ireg, 0);
451           gcc_assert (REG_P (ireg));
452           fprintf (file, "[%s]", reg_names[REGNO (ireg)]);
453         }
454       break;
455
456     default:
457       output_addr_const (file, addr);
458     }
459 }
460
461 void
462 print_operand (FILE *file, rtx x, int code)
463 {
464   if (code == '#')
465     fputc (ASM_DOUBLE_CHAR, file);
466   else if (code == '|')
467     fputs (REGISTER_PREFIX, file);
468   else if (code == 'c')
469     fputs (cond_name (x), file);
470   else if (code == 'C')
471     fputs (rev_cond_name (x), file);
472   else if (code == 'D' && CONST_INT_P (x) && INTVAL (x) < 0)
473     fprintf (file, "$" NEG_HWI_PRINT_HEX16, INTVAL (x));
474   else if (code == 'P' && CONST_INT_P (x))
475     fprintf (file, "$" HOST_WIDE_INT_PRINT_DEC, INTVAL (x) + 1);
476   else if (code == 'N' && CONST_INT_P (x))
477     fprintf (file, "$" HOST_WIDE_INT_PRINT_DEC, ~ INTVAL (x));
478   /* rotl instruction cannot deal with negative arguments.  */
479   else if (code == 'R' && CONST_INT_P (x))
480     fprintf (file, "$" HOST_WIDE_INT_PRINT_DEC, 32 - INTVAL (x));
481   else if (code == 'H' && CONST_INT_P (x))
482     fprintf (file, "$%d", (int) (0xffff & ~ INTVAL (x)));
483   else if (code == 'h' && CONST_INT_P (x))
484     fprintf (file, "$%d", (short) - INTVAL (x));
485   else if (code == 'B' && CONST_INT_P (x))
486     fprintf (file, "$%d", (int) (0xff & ~ INTVAL (x)));
487   else if (code == 'b' && CONST_INT_P (x))
488     fprintf (file, "$%d", (int) (0xff & - INTVAL (x)));
489   else if (code == 'M' && CONST_INT_P (x))
490     fprintf (file, "$%d", ~((1 << INTVAL (x)) - 1));
491   else if (REG_P (x))
492     fprintf (file, "%s", reg_names[REGNO (x)]);
493   else if (MEM_P (x))
494     output_address (XEXP (x, 0));
495   else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode)
496     {
497       char dstr[30];
498       real_to_decimal (dstr, CONST_DOUBLE_REAL_VALUE (x),
499                        sizeof (dstr), 0, 1);
500       fprintf (file, "$0f%s", dstr);
501     }
502   else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == DFmode)
503     {
504       char dstr[30];
505       real_to_decimal (dstr, CONST_DOUBLE_REAL_VALUE (x),
506                        sizeof (dstr), 0, 1);
507       fprintf (file, "$0%c%s", ASM_DOUBLE_CHAR, dstr);
508     }
509   else
510     {
511       if (flag_pic > 1 && symbolic_operand (x, SImode))
512         {
513           debug_rtx (x);
514           output_operand_lossage ("symbol used as immediate operand");
515         }
516       putc ('$', file);
517       output_addr_const (file, x);
518     }
519 }
520 \f
521 const char *
522 cond_name (rtx op)
523 {
524   switch (GET_CODE (op))
525     {
526     case NE:
527       return "neq";
528     case EQ:
529       return "eql";
530     case GE:
531       return "geq";
532     case GT:
533       return "gtr";
534     case LE:
535       return "leq";
536     case LT:
537       return "lss";
538     case GEU:
539       return "gequ";
540     case GTU:
541       return "gtru";
542     case LEU:
543       return "lequ";
544     case LTU:
545       return "lssu";
546
547     default:
548       gcc_unreachable ();
549     }
550 }
551
552 const char *
553 rev_cond_name (rtx op)
554 {
555   switch (GET_CODE (op))
556     {
557     case EQ:
558       return "neq";
559     case NE:
560       return "eql";
561     case LT:
562       return "geq";
563     case LE:
564       return "gtr";
565     case GT:
566       return "leq";
567     case GE:
568       return "lss";
569     case LTU:
570       return "gequ";
571     case LEU:
572       return "gtru";
573     case GTU:
574       return "lequ";
575     case GEU:
576       return "lssu";
577
578     default:
579       gcc_unreachable ();
580     }
581 }
582
583 static bool
584 vax_float_literal (rtx c)
585 {
586   enum machine_mode mode;
587   REAL_VALUE_TYPE r, s;
588   int i;
589
590   if (GET_CODE (c) != CONST_DOUBLE)
591     return false;
592
593   mode = GET_MODE (c);
594
595   if (c == const_tiny_rtx[(int) mode][0]
596       || c == const_tiny_rtx[(int) mode][1]
597       || c == const_tiny_rtx[(int) mode][2])
598     return true;
599
600   REAL_VALUE_FROM_CONST_DOUBLE (r, c);
601
602   for (i = 0; i < 7; i++)
603     {
604       int x = 1 << i;
605       bool ok;
606       REAL_VALUE_FROM_INT (s, x, 0, mode);
607
608       if (REAL_VALUES_EQUAL (r, s))
609         return true;
610       ok = exact_real_inverse (mode, &s);
611       gcc_assert (ok);
612       if (REAL_VALUES_EQUAL (r, s))
613         return true;
614     }
615   return false;
616 }
617
618
619 /* Return the cost in cycles of a memory address, relative to register
620    indirect.
621
622    Each of the following adds the indicated number of cycles:
623
624    1 - symbolic address
625    1 - pre-decrement
626    1 - indexing and/or offset(register)
627    2 - indirect */
628
629
630 static int
631 vax_address_cost_1 (rtx addr)
632 {
633   int reg = 0, indexed = 0, indir = 0, offset = 0, predec = 0;
634   rtx plus_op0 = 0, plus_op1 = 0;
635  restart:
636   switch (GET_CODE (addr))
637     {
638     case PRE_DEC:
639       predec = 1;
640     case REG:
641     case SUBREG:
642     case POST_INC:
643       reg = 1;
644       break;
645     case MULT:
646       indexed = 1;      /* 2 on VAX 2 */
647       break;
648     case CONST_INT:
649       /* byte offsets cost nothing (on a VAX 2, they cost 1 cycle) */
650       if (offset == 0)
651         offset = (unsigned HOST_WIDE_INT)(INTVAL(addr)+128) > 256;
652       break;
653     case CONST:
654     case SYMBOL_REF:
655       offset = 1;       /* 2 on VAX 2 */
656       break;
657     case LABEL_REF:     /* this is probably a byte offset from the pc */
658       if (offset == 0)
659         offset = 1;
660       break;
661     case PLUS:
662       if (plus_op0)
663         plus_op1 = XEXP (addr, 0);
664       else
665         plus_op0 = XEXP (addr, 0);
666       addr = XEXP (addr, 1);
667       goto restart;
668     case MEM:
669       indir = 2;        /* 3 on VAX 2 */
670       addr = XEXP (addr, 0);
671       goto restart;
672     default:
673       break;
674     }
675
676   /* Up to 3 things can be added in an address.  They are stored in
677      plus_op0, plus_op1, and addr.  */
678
679   if (plus_op0)
680     {
681       addr = plus_op0;
682       plus_op0 = 0;
683       goto restart;
684     }
685   if (plus_op1)
686     {
687       addr = plus_op1;
688       plus_op1 = 0;
689       goto restart;
690     }
691   /* Indexing and register+offset can both be used (except on a VAX 2)
692      without increasing execution time over either one alone.  */
693   if (reg && indexed && offset)
694     return reg + indir + offset + predec;
695   return reg + indexed + indir + offset + predec;
696 }
697
698 static int
699 vax_address_cost (rtx x, bool speed ATTRIBUTE_UNUSED)
700 {
701   return (1 + (REG_P (x) ? 0 : vax_address_cost_1 (x)));
702 }
703
704 /* Cost of an expression on a VAX.  This version has costs tuned for the
705    CVAX chip (found in the VAX 3 series) with comments for variations on
706    other models.
707
708    FIXME: The costs need review, particularly for TRUNCATE, FLOAT_EXTEND
709    and FLOAT_TRUNCATE.  We need a -mcpu option to allow provision of
710    costs on a per cpu basis.  */
711
712 static bool
713 vax_rtx_costs (rtx x, int code, int outer_code, int *total,
714                bool speed ATTRIBUTE_UNUSED)
715 {
716   enum machine_mode mode = GET_MODE (x);
717   int i = 0;                               /* may be modified in switch */
718   const char *fmt = GET_RTX_FORMAT (code); /* may be modified in switch */
719
720   switch (code)
721     {
722       /* On a VAX, constants from 0..63 are cheap because they can use the
723          1 byte literal constant format.  Compare to -1 should be made cheap
724          so that decrement-and-branch insns can be formed more easily (if
725          the value -1 is copied to a register some decrement-and-branch
726          patterns will not match).  */
727     case CONST_INT:
728       if (INTVAL (x) == 0)
729         {
730           *total = 0;
731           return true;
732         }
733       if (outer_code == AND)
734         {
735           *total = ((unsigned HOST_WIDE_INT) ~INTVAL (x) <= 077) ? 1 : 2;
736           return true;
737         }
738       if ((unsigned HOST_WIDE_INT) INTVAL (x) <= 077
739           || (outer_code == COMPARE
740               && INTVAL (x) == -1)
741           || ((outer_code == PLUS || outer_code == MINUS)
742               && (unsigned HOST_WIDE_INT) -INTVAL (x) <= 077))
743         {
744           *total = 1;
745           return true;
746         }
747       /* FALLTHRU */
748
749     case CONST:
750     case LABEL_REF:
751     case SYMBOL_REF:
752       *total = 3;
753       return true;
754
755     case CONST_DOUBLE:
756       if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
757         *total = vax_float_literal (x) ? 5 : 8;
758       else
759         *total = ((CONST_DOUBLE_HIGH (x) == 0
760                    && (unsigned HOST_WIDE_INT) CONST_DOUBLE_LOW (x) < 64)
761                   || (outer_code == PLUS
762                       && CONST_DOUBLE_HIGH (x) == -1
763                       && (unsigned HOST_WIDE_INT)-CONST_DOUBLE_LOW (x) < 64))
764                  ? 2 : 5;
765       return true;
766
767     case POST_INC:
768       *total = 2;
769       return true;              /* Implies register operand.  */
770
771     case PRE_DEC:
772       *total = 3;
773       return true;              /* Implies register operand.  */
774
775     case MULT:
776       switch (mode)
777         {
778         case DFmode:
779           *total = 16;          /* 4 on VAX 9000 */
780           break;
781         case SFmode:
782           *total = 9;           /* 4 on VAX 9000, 12 on VAX 2 */
783           break;
784         case DImode:
785           *total = 16;          /* 6 on VAX 9000, 28 on VAX 2 */
786           break;
787         case SImode:
788         case HImode:
789         case QImode:
790           *total = 10;          /* 3-4 on VAX 9000, 20-28 on VAX 2 */
791           break;
792         default:
793           *total = MAX_COST;    /* Mode is not supported.  */
794           return true;
795         }
796       break;
797
798     case UDIV:
799       if (mode != SImode)
800         {
801           *total = MAX_COST;    /* Mode is not supported.  */
802           return true;
803         }
804       *total = 17;
805       break;
806
807     case DIV:
808       if (mode == DImode)
809         *total = 30;            /* Highly variable.  */
810       else if (mode == DFmode)
811         /* divide takes 28 cycles if the result is not zero, 13 otherwise */
812         *total = 24;
813       else
814         *total = 11;            /* 25 on VAX 2 */
815       break;
816
817     case MOD:
818       *total = 23;
819       break;
820
821     case UMOD:
822       if (mode != SImode)
823         {
824           *total = MAX_COST;    /* Mode is not supported.  */
825           return true;
826         }
827       *total = 29;
828       break;
829
830     case FLOAT:
831       *total = (6               /* 4 on VAX 9000 */
832                 + (mode == DFmode) + (GET_MODE (XEXP (x, 0)) != SImode));
833       break;
834
835     case FIX:
836       *total = 7;               /* 17 on VAX 2 */
837       break;
838
839     case ASHIFT:
840     case LSHIFTRT:
841     case ASHIFTRT:
842       if (mode == DImode)
843         *total = 12;
844       else
845         *total = 10;            /* 6 on VAX 9000 */
846       break;
847
848     case ROTATE:
849     case ROTATERT:
850       *total = 6;               /* 5 on VAX 2, 4 on VAX 9000 */
851       if (CONST_INT_P (XEXP (x, 1)))
852         fmt = "e";              /* all constant rotate counts are short */
853       break;
854
855     case PLUS:
856     case MINUS:
857       *total = (mode == DFmode) ? 13 : 8; /* 6/8 on VAX 9000, 16/15 on VAX 2 */
858       /* Small integer operands can use subl2 and addl2.  */
859       if ((CONST_INT_P (XEXP (x, 1)))
860           && (unsigned HOST_WIDE_INT)(INTVAL (XEXP (x, 1)) + 63) < 127)
861         fmt = "e";
862       break;
863
864     case IOR:
865     case XOR:
866       *total = 3;
867       break;
868
869     case AND:
870       /* AND is special because the first operand is complemented.  */
871       *total = 3;
872       if (CONST_INT_P (XEXP (x, 0)))
873         {
874           if ((unsigned HOST_WIDE_INT)~INTVAL (XEXP (x, 0)) > 63)
875             *total = 4;
876           fmt = "e";
877           i = 1;
878         }
879       break;
880
881     case NEG:
882       if (mode == DFmode)
883         *total = 9;
884       else if (mode == SFmode)
885         *total = 6;
886       else if (mode == DImode)
887         *total = 4;
888       else
889         *total = 2;
890       break;
891
892     case NOT:
893       *total = 2;
894       break;
895
896     case ZERO_EXTRACT:
897     case SIGN_EXTRACT:
898       *total = 15;
899       break;
900
901     case MEM:
902       if (mode == DImode || mode == DFmode)
903         *total = 5;             /* 7 on VAX 2 */
904       else
905         *total = 3;             /* 4 on VAX 2 */
906       x = XEXP (x, 0);
907       if (!REG_P (x) && GET_CODE (x) != POST_INC)
908         *total += vax_address_cost_1 (x);
909       return true;
910
911     case FLOAT_EXTEND:
912     case FLOAT_TRUNCATE:
913     case TRUNCATE:
914       *total = 3;               /* FIXME: Costs need to be checked  */
915       break;
916
917     default:
918       return false;
919     }
920
921   /* Now look inside the expression.  Operands which are not registers or
922      short constants add to the cost.
923
924      FMT and I may have been adjusted in the switch above for instructions
925      which require special handling.  */
926
927   while (*fmt++ == 'e')
928     {
929       rtx op = XEXP (x, i);
930
931       i += 1;
932       code = GET_CODE (op);
933
934       /* A NOT is likely to be found as the first operand of an AND
935          (in which case the relevant cost is of the operand inside
936          the not) and not likely to be found anywhere else.  */
937       if (code == NOT)
938         op = XEXP (op, 0), code = GET_CODE (op);
939
940       switch (code)
941         {
942         case CONST_INT:
943           if ((unsigned HOST_WIDE_INT)INTVAL (op) > 63
944               && GET_MODE (x) != QImode)
945             *total += 1;        /* 2 on VAX 2 */
946           break;
947         case CONST:
948         case LABEL_REF:
949         case SYMBOL_REF:
950           *total += 1;          /* 2 on VAX 2 */
951           break;
952         case CONST_DOUBLE:
953           if (GET_MODE_CLASS (GET_MODE (op)) == MODE_FLOAT)
954             {
955               /* Registers are faster than floating point constants -- even
956                  those constants which can be encoded in a single byte.  */
957               if (vax_float_literal (op))
958                 *total += 1;
959               else
960                 *total += (GET_MODE (x) == DFmode) ? 3 : 2;
961             }
962           else
963             {
964               if (CONST_DOUBLE_HIGH (op) != 0
965                   || (unsigned HOST_WIDE_INT)CONST_DOUBLE_LOW (op) > 63)
966                 *total += 2;
967             }
968           break;
969         case MEM:
970           *total += 1;          /* 2 on VAX 2 */
971           if (!REG_P (XEXP (op, 0)))
972             *total += vax_address_cost_1 (XEXP (op, 0));
973           break;
974         case REG:
975         case SUBREG:
976           break;
977         default:
978           *total += 1;
979           break;
980         }
981     }
982   return true;
983 }
984 \f
985 /* Output code to add DELTA to the first argument, and then jump to FUNCTION.
986    Used for C++ multiple inheritance.
987         .mask   ^m<r2,r3,r4,r5,r6,r7,r8,r9,r10,r11>  #conservative entry mask
988         addl2   $DELTA, 4(ap)   #adjust first argument
989         jmp     FUNCTION+2      #jump beyond FUNCTION's entry mask
990 */
991
992 static void
993 vax_output_mi_thunk (FILE * file,
994                      tree thunk ATTRIBUTE_UNUSED,
995                      HOST_WIDE_INT delta,
996                      HOST_WIDE_INT vcall_offset ATTRIBUTE_UNUSED,
997                      tree function)
998 {
999   fprintf (file, "\t.word 0x0ffc\n\taddl2 $" HOST_WIDE_INT_PRINT_DEC, delta);
1000   asm_fprintf (file, ",4(%Rap)\n");
1001   fprintf (file, "\tjmp ");
1002   assemble_name (file,  XSTR (XEXP (DECL_RTL (function), 0), 0));
1003   fprintf (file, "+2\n");
1004 }
1005 \f
1006 static rtx
1007 vax_struct_value_rtx (tree fntype ATTRIBUTE_UNUSED,
1008                       int incoming ATTRIBUTE_UNUSED)
1009 {
1010   return gen_rtx_REG (Pmode, VAX_STRUCT_VALUE_REGNUM);
1011 }
1012
1013 static rtx
1014 vax_builtin_setjmp_frame_value (void)
1015 {
1016   return hard_frame_pointer_rtx;
1017 }
1018
1019 /* Worker function for NOTICE_UPDATE_CC.  */
1020
1021 void
1022 vax_notice_update_cc (rtx exp, rtx insn ATTRIBUTE_UNUSED)
1023 {
1024   if (GET_CODE (exp) == SET)
1025     {
1026       if (GET_CODE (SET_SRC (exp)) == CALL)
1027         CC_STATUS_INIT;
1028       else if (GET_CODE (SET_DEST (exp)) != ZERO_EXTRACT
1029                && GET_CODE (SET_DEST (exp)) != PC)
1030         {
1031           cc_status.flags = 0;
1032           /* The integer operations below don't set carry or
1033              set it in an incompatible way.  That's ok though
1034              as the Z bit is all we need when doing unsigned
1035              comparisons on the result of these insns (since
1036              they're always with 0).  Set CC_NO_OVERFLOW to
1037              generate the correct unsigned branches.  */
1038           switch (GET_CODE (SET_SRC (exp)))
1039             {
1040             case NEG:
1041               if (GET_MODE_CLASS (GET_MODE (exp)) == MODE_FLOAT)
1042                 break;
1043             case AND:
1044             case IOR:
1045             case XOR:
1046             case NOT:
1047             case MEM:
1048             case REG:
1049               cc_status.flags = CC_NO_OVERFLOW;
1050               break;
1051             default:
1052               break;
1053             }
1054           cc_status.value1 = SET_DEST (exp);
1055           cc_status.value2 = SET_SRC (exp);
1056         }
1057     }
1058   else if (GET_CODE (exp) == PARALLEL
1059            && GET_CODE (XVECEXP (exp, 0, 0)) == SET)
1060     {
1061       if (GET_CODE (SET_SRC (XVECEXP (exp, 0, 0))) == CALL)
1062         CC_STATUS_INIT;
1063       else if (GET_CODE (SET_DEST (XVECEXP (exp, 0, 0))) != PC)
1064         {
1065           cc_status.flags = 0;
1066           cc_status.value1 = SET_DEST (XVECEXP (exp, 0, 0));
1067           cc_status.value2 = SET_SRC (XVECEXP (exp, 0, 0));
1068         }
1069       else
1070         /* PARALLELs whose first element sets the PC are aob,
1071            sob insns.  They do change the cc's.  */
1072         CC_STATUS_INIT;
1073     }
1074   else
1075     CC_STATUS_INIT;
1076   if (cc_status.value1 && REG_P (cc_status.value1)
1077       && cc_status.value2
1078       && reg_overlap_mentioned_p (cc_status.value1, cc_status.value2))
1079     cc_status.value2 = 0;
1080   if (cc_status.value1 && MEM_P (cc_status.value1)
1081       && cc_status.value2
1082       && MEM_P (cc_status.value2))
1083     cc_status.value2 = 0;
1084   /* Actual condition, one line up, should be that value2's address
1085      depends on value1, but that is too much of a pain.  */
1086 }
1087
1088 /* Output integer move instructions.  */
1089
1090 const char *
1091 vax_output_int_move (rtx insn ATTRIBUTE_UNUSED, rtx *operands,
1092                      enum machine_mode mode)
1093 {
1094   rtx hi[3], lo[3];
1095   const char *pattern_hi, *pattern_lo;
1096
1097   switch (mode)
1098     {
1099     case DImode:
1100       if (operands[1] == const0_rtx)
1101         return "clrq %0";
1102       if (TARGET_QMATH && optimize_size
1103           && (CONST_INT_P (operands[1])
1104               || GET_CODE (operands[1]) == CONST_DOUBLE))
1105         {
1106           unsigned HOST_WIDE_INT hval, lval;
1107           int n;
1108
1109           if (GET_CODE (operands[1]) == CONST_DOUBLE)
1110             {
1111               gcc_assert (HOST_BITS_PER_WIDE_INT != 64);
1112
1113               /* Make sure only the low 32 bits are valid.  */
1114               lval = CONST_DOUBLE_LOW (operands[1]) & 0xffffffff;
1115               hval = CONST_DOUBLE_HIGH (operands[1]) & 0xffffffff;
1116             }
1117           else
1118             {
1119               lval = INTVAL (operands[1]);
1120               hval = 0;
1121             }
1122
1123           /* Here we see if we are trying to see if the 64bit value is really
1124              a 6bit shifted some arbitrary amount.  If so, we can use ashq to
1125              shift it to the correct value saving 7 bytes (1 addr-mode-byte +
1126              8 bytes - 1 shift byte - 1 short literal byte.  */
1127           if (lval != 0
1128               && (n = exact_log2 (lval & (- lval))) != -1
1129               && (lval >> n) < 64)
1130             {
1131               lval >>= n;
1132
1133               /* On 32bit platforms, if the 6bits didn't overflow into the
1134                  upper 32bit value that value better be 0.  If we have
1135                  overflowed, make sure it wasn't too much.  */
1136               if (HOST_BITS_PER_WIDE_INT == 32 && hval != 0)
1137                 {
1138                   if (n <= 26 || hval >= ((unsigned)1 << (n - 26)))
1139                     n = 0;      /* failure */
1140                   else
1141                     lval |= hval << (32 - n);
1142                 }
1143               /*  If n is 0, then ashq is not the best way to emit this.  */
1144               if (n > 0)
1145                 {
1146                   operands[1] = GEN_INT (lval);
1147                   operands[2] = GEN_INT (n);
1148                   return "ashq %2,%1,%0";
1149                 }
1150 #if HOST_BITS_PER_WIDE_INT == 32
1151             }
1152           /* On 32bit platforms, if the low 32bit value is 0, checkout the
1153              upper 32bit value.  */
1154           else if (hval != 0
1155                    && (n = exact_log2 (hval & (- hval)) - 1) != -1
1156                    && (hval >> n) < 64)
1157             {
1158               operands[1] = GEN_INT (hval >> n);
1159               operands[2] = GEN_INT (n + 32);
1160               return "ashq %2,%1,%0";
1161 #endif
1162             }
1163         }
1164
1165       if (TARGET_QMATH
1166           && (!MEM_P (operands[0])
1167               || GET_CODE (XEXP (operands[0], 0)) == PRE_DEC
1168               || GET_CODE (XEXP (operands[0], 0)) == POST_INC
1169               || !illegal_addsub_di_memory_operand (operands[0], DImode))
1170           && ((CONST_INT_P (operands[1])
1171                && (unsigned HOST_WIDE_INT) INTVAL (operands[1]) >= 64)
1172               || GET_CODE (operands[1]) == CONST_DOUBLE))
1173         {
1174           hi[0] = operands[0];
1175           hi[1] = operands[1];
1176
1177           split_quadword_operands (insn, SET, hi, lo, 2);
1178
1179           pattern_lo = vax_output_int_move (NULL, lo, SImode);
1180           pattern_hi = vax_output_int_move (NULL, hi, SImode);
1181
1182           /* The patterns are just movl/movl or pushl/pushl then a movq will
1183              be shorter (1 opcode byte + 1 addrmode byte + 8 immediate value
1184              bytes .vs. 2 opcode bytes + 2 addrmode bytes + 8 immediate value
1185              value bytes.  */
1186           if ((!strncmp (pattern_lo, "movl", 4)
1187               && !strncmp (pattern_hi, "movl", 4))
1188               || (!strncmp (pattern_lo, "pushl", 5)
1189                   && !strncmp (pattern_hi, "pushl", 5)))
1190             return "movq %1,%0";
1191
1192           if (MEM_P (operands[0])
1193               && GET_CODE (XEXP (operands[0], 0)) == PRE_DEC)
1194             {
1195               output_asm_insn (pattern_hi, hi);
1196               operands[0] = lo[0];
1197               operands[1] = lo[1];
1198               operands[2] = lo[2];
1199               return pattern_lo;
1200             }
1201           else
1202             {
1203               output_asm_insn (pattern_lo, lo);
1204               operands[0] = hi[0];
1205               operands[1] = hi[1];
1206               operands[2] = hi[2];
1207               return pattern_hi;
1208             }
1209         }
1210       return "movq %1,%0";
1211
1212     case SImode:
1213       if (symbolic_operand (operands[1], SImode))
1214         {
1215           if (push_operand (operands[0], SImode))
1216             return "pushab %a1";
1217           return "movab %a1,%0";
1218         }
1219
1220       if (operands[1] == const0_rtx)
1221         {
1222           if (push_operand (operands[1], SImode))
1223             return "pushl %1";
1224           return "clrl %0";
1225         }
1226
1227       if (CONST_INT_P (operands[1])
1228           && (unsigned HOST_WIDE_INT) INTVAL (operands[1]) >= 64)
1229         {
1230           HOST_WIDE_INT i = INTVAL (operands[1]);
1231           int n;
1232           if ((unsigned HOST_WIDE_INT)(~i) < 64)
1233             return "mcoml %N1,%0";
1234           if ((unsigned HOST_WIDE_INT)i < 0x100)
1235             return "movzbl %1,%0";
1236           if (i >= -0x80 && i < 0)
1237             return "cvtbl %1,%0";
1238           if (optimize_size
1239               && (n = exact_log2 (i & (-i))) != -1
1240               && ((unsigned HOST_WIDE_INT)i >> n) < 64)
1241             {
1242               operands[1] = GEN_INT ((unsigned HOST_WIDE_INT)i >> n);
1243               operands[2] = GEN_INT (n);
1244               return "ashl %2,%1,%0";
1245             }
1246           if ((unsigned HOST_WIDE_INT)i < 0x10000)
1247             return "movzwl %1,%0";
1248           if (i >= -0x8000 && i < 0)
1249             return "cvtwl %1,%0";
1250         }
1251       if (push_operand (operands[0], SImode))
1252         return "pushl %1";
1253       return "movl %1,%0";
1254
1255     case HImode:
1256       if (CONST_INT_P (operands[1]))
1257         {
1258           HOST_WIDE_INT i = INTVAL (operands[1]);
1259           if (i == 0)
1260             return "clrw %0";
1261           else if ((unsigned HOST_WIDE_INT)i < 64)
1262             return "movw %1,%0";
1263           else if ((unsigned HOST_WIDE_INT)~i < 64)
1264             return "mcomw %H1,%0";
1265           else if ((unsigned HOST_WIDE_INT)i < 256)
1266             return "movzbw %1,%0";
1267           else if (i >= -0x80 && i < 0)
1268             return "cvtbw %1,%0";
1269         }
1270       return "movw %1,%0";
1271
1272     case QImode:
1273       if (CONST_INT_P (operands[1]))
1274         {
1275           HOST_WIDE_INT i = INTVAL (operands[1]);
1276           if (i == 0)
1277             return "clrb %0";
1278           else if ((unsigned HOST_WIDE_INT)~i < 64)
1279             return "mcomb %B1,%0";
1280         }
1281       return "movb %1,%0";
1282
1283     default:
1284       gcc_unreachable ();
1285     }
1286 }
1287
1288 /* Output integer add instructions.
1289
1290    The space-time-opcode tradeoffs for addition vary by model of VAX.
1291
1292    On a VAX 3 "movab (r1)[r2],r3" is faster than "addl3 r1,r2,r3",
1293    but it not faster on other models.
1294
1295    "movab #(r1),r2" is usually shorter than "addl3 #,r1,r2", and is
1296    faster on a VAX 3, but some VAXen (e.g. VAX 9000) will stall if
1297    a register is used in an address too soon after it is set.
1298    Compromise by using movab only when it is shorter than the add
1299    or the base register in the address is one of sp, ap, and fp,
1300    which are not modified very often.  */
1301
1302 const char *
1303 vax_output_int_add (rtx insn, rtx *operands, enum machine_mode mode)
1304 {
1305   switch (mode)
1306     {
1307     case DImode:
1308       {
1309         rtx low[3];
1310         const char *pattern;
1311         int carry = 1;
1312         bool sub;
1313
1314         if (TARGET_QMATH && 0)
1315           debug_rtx (insn);
1316
1317         split_quadword_operands (insn, PLUS, operands, low, 3);
1318
1319         if (TARGET_QMATH)
1320           {
1321             gcc_assert (rtx_equal_p (operands[0], operands[1]));
1322 #ifdef NO_EXTERNAL_INDIRECT_ADDRESSS
1323             gcc_assert (!flag_pic || !external_memory_operand (low[2], SImode));
1324             gcc_assert (!flag_pic || !external_memory_operand (low[0], SImode));
1325 #endif
1326
1327             /* No reason to add a 0 to the low part and thus no carry, so just
1328                emit the appropriate add/sub instruction.  */
1329             if (low[2] == const0_rtx)
1330               return vax_output_int_add (NULL, operands, SImode);
1331
1332             /* Are we doing addition or subtraction?  */
1333             sub = CONST_INT_P (operands[2]) && INTVAL (operands[2]) < 0;
1334
1335             /* We can't use vax_output_int_add since some the patterns don't
1336                modify the carry bit.  */
1337             if (sub)
1338               {
1339                 if (low[2] == constm1_rtx)
1340                   pattern = "decl %0";
1341                 else
1342                   pattern = "subl2 $%n2,%0";
1343               }
1344             else
1345               {
1346                 if (low[2] == const1_rtx)
1347                   pattern = "incl %0";
1348                 else
1349                   pattern = "addl2 %2,%0";
1350               }
1351             output_asm_insn (pattern, low);
1352
1353             /* In 2's complement, -n = ~n + 1.  Since we are dealing with
1354                two 32bit parts, we complement each and then add one to
1355                low part.  We know that the low part can't overflow since
1356                it's value can never be 0.  */
1357             if (sub)
1358                 return "sbwc %N2,%0";
1359             return "adwc %2,%0";
1360           }
1361
1362         /* Add low parts.  */
1363         if (rtx_equal_p (operands[0], operands[1]))
1364           {
1365             if (low[2] == const0_rtx)
1366         /* Should examine operand, punt if not POST_INC.  */
1367               pattern = "tstl %0", carry = 0;
1368             else if (low[2] == const1_rtx)
1369               pattern = "incl %0";
1370             else
1371               pattern = "addl2 %2,%0";
1372           }
1373         else
1374           {
1375             if (low[2] == const0_rtx)
1376               pattern = "movl %1,%0", carry = 0;
1377             else
1378               pattern = "addl3 %2,%1,%0";
1379           }
1380         if (pattern)
1381           output_asm_insn (pattern, low);
1382         if (!carry)
1383           /* If CARRY is 0, we don't have any carry value to worry about.  */
1384           return get_insn_template (CODE_FOR_addsi3, insn);
1385         /* %0 = C + %1 + %2 */
1386         if (!rtx_equal_p (operands[0], operands[1]))
1387           output_asm_insn ((operands[1] == const0_rtx
1388                             ? "clrl %0"
1389                             : "movl %1,%0"), operands);
1390         return "adwc %2,%0";
1391       }
1392
1393     case SImode:
1394       if (rtx_equal_p (operands[0], operands[1]))
1395         {
1396           if (operands[2] == const1_rtx)
1397             return "incl %0";
1398           if (operands[2] == constm1_rtx)
1399             return "decl %0";
1400           if (CONST_INT_P (operands[2])
1401               && (unsigned HOST_WIDE_INT) (- INTVAL (operands[2])) < 64)
1402             return "subl2 $%n2,%0";
1403           if (CONST_INT_P (operands[2])
1404               && (unsigned HOST_WIDE_INT) INTVAL (operands[2]) >= 64
1405               && REG_P (operands[1])
1406               && ((INTVAL (operands[2]) < 32767 && INTVAL (operands[2]) > -32768)
1407                    || REGNO (operands[1]) > 11))
1408             return "movab %c2(%1),%0";
1409           if (REG_P (operands[0]) && symbolic_operand (operands[2], SImode))
1410             return "movab %a2[%0],%0";
1411           return "addl2 %2,%0";
1412         }
1413
1414       if (rtx_equal_p (operands[0], operands[2]))
1415         {
1416           if (REG_P (operands[0]) && symbolic_operand (operands[1], SImode))
1417             return "movab %a1[%0],%0";
1418           return "addl2 %1,%0";
1419         }
1420
1421       if (CONST_INT_P (operands[2])
1422           && INTVAL (operands[2]) < 32767
1423           && INTVAL (operands[2]) > -32768
1424           && REG_P (operands[1])
1425           && push_operand (operands[0], SImode))
1426         return "pushab %c2(%1)";
1427
1428       if (CONST_INT_P (operands[2])
1429           && (unsigned HOST_WIDE_INT) (- INTVAL (operands[2])) < 64)
1430         return "subl3 $%n2,%1,%0";
1431
1432       if (CONST_INT_P (operands[2])
1433           && (unsigned HOST_WIDE_INT) INTVAL (operands[2]) >= 64
1434           && REG_P (operands[1])
1435           && ((INTVAL (operands[2]) < 32767 && INTVAL (operands[2]) > -32768)
1436                || REGNO (operands[1]) > 11))
1437         return "movab %c2(%1),%0";
1438
1439       /* Add this if using gcc on a VAX 3xxx:
1440       if (REG_P (operands[1]) && REG_P (operands[2]))
1441         return "movab (%1)[%2],%0";
1442       */
1443
1444       if (REG_P (operands[1]) && symbolic_operand (operands[2], SImode))
1445         {
1446           if (push_operand (operands[0], SImode))
1447             return "pushab %a2[%1]";
1448           return "movab %a2[%1],%0";
1449         }
1450
1451       if (REG_P (operands[2]) && symbolic_operand (operands[1], SImode))
1452         {
1453           if (push_operand (operands[0], SImode))
1454             return "pushab %a1[%2]";
1455           return "movab %a1[%2],%0";
1456         }
1457
1458       if (flag_pic && REG_P (operands[0])
1459           && symbolic_operand (operands[2], SImode))
1460         return "movab %a2,%0;addl2 %1,%0";
1461
1462       if (flag_pic
1463           && (symbolic_operand (operands[1], SImode)
1464               || symbolic_operand (operands[1], SImode)))
1465         debug_rtx (insn);
1466
1467       return "addl3 %1,%2,%0";
1468
1469     case HImode:
1470       if (rtx_equal_p (operands[0], operands[1]))
1471         {
1472           if (operands[2] == const1_rtx)
1473             return "incw %0";
1474           if (operands[2] == constm1_rtx)
1475             return "decw %0";
1476           if (CONST_INT_P (operands[2])
1477               && (unsigned HOST_WIDE_INT) (- INTVAL (operands[2])) < 64)
1478             return "subw2 $%n2,%0";
1479           return "addw2 %2,%0";
1480         }
1481       if (rtx_equal_p (operands[0], operands[2]))
1482         return "addw2 %1,%0";
1483       if (CONST_INT_P (operands[2])
1484           && (unsigned HOST_WIDE_INT) (- INTVAL (operands[2])) < 64)
1485         return "subw3 $%n2,%1,%0";
1486       return "addw3 %1,%2,%0";
1487
1488     case QImode:
1489       if (rtx_equal_p (operands[0], operands[1]))
1490         {
1491           if (operands[2] == const1_rtx)
1492             return "incb %0";
1493           if (operands[2] == constm1_rtx)
1494             return "decb %0";
1495           if (CONST_INT_P (operands[2])
1496               && (unsigned HOST_WIDE_INT) (- INTVAL (operands[2])) < 64)
1497             return "subb2 $%n2,%0";
1498           return "addb2 %2,%0";
1499         }
1500       if (rtx_equal_p (operands[0], operands[2]))
1501         return "addb2 %1,%0";
1502       if (CONST_INT_P (operands[2])
1503           && (unsigned HOST_WIDE_INT) (- INTVAL (operands[2])) < 64)
1504         return "subb3 $%n2,%1,%0";
1505       return "addb3 %1,%2,%0";
1506
1507     default:
1508       gcc_unreachable ();
1509     }
1510 }
1511
1512 const char *
1513 vax_output_int_subtract (rtx insn, rtx *operands, enum machine_mode mode)
1514 {
1515   switch (mode)
1516     {
1517     case DImode:
1518       {
1519         rtx low[3];
1520         const char *pattern;
1521         int carry = 1;
1522
1523         if (TARGET_QMATH && 0)
1524           debug_rtx (insn);
1525
1526         split_quadword_operands (insn, MINUS, operands, low, 3);
1527
1528         if (TARGET_QMATH)
1529           {
1530             if (operands[1] == const0_rtx && low[1] == const0_rtx)
1531               {
1532                 /* Negation is tricky.  It's basically complement and increment.
1533                    Negate hi, then lo, and subtract the carry back.  */
1534                 if ((MEM_P (low[0]) && GET_CODE (XEXP (low[0], 0)) == POST_INC)
1535                     || (MEM_P (operands[0])
1536                         && GET_CODE (XEXP (operands[0], 0)) == POST_INC))
1537                   fatal_insn ("illegal operand detected", insn);
1538                 output_asm_insn ("mnegl %2,%0", operands);
1539                 output_asm_insn ("mnegl %2,%0", low);
1540                 return "sbwc $0,%0";
1541               }
1542             gcc_assert (rtx_equal_p (operands[0], operands[1]));
1543             gcc_assert (rtx_equal_p (low[0], low[1]));
1544             if (low[2] == const1_rtx)
1545               output_asm_insn ("decl %0", low);
1546             else
1547               output_asm_insn ("subl2 %2,%0", low);
1548             return "sbwc %2,%0";
1549           }
1550
1551         /* Subtract low parts.  */
1552         if (rtx_equal_p (operands[0], operands[1]))
1553           {
1554             if (low[2] == const0_rtx)
1555               pattern = 0, carry = 0;
1556             else if (low[2] == constm1_rtx)
1557               pattern = "decl %0";
1558             else
1559               pattern = "subl2 %2,%0";
1560           }
1561         else
1562           {
1563             if (low[2] == constm1_rtx)
1564               pattern = "decl %0";
1565             else if (low[2] == const0_rtx)
1566               pattern = get_insn_template (CODE_FOR_movsi, insn), carry = 0;
1567             else
1568               pattern = "subl3 %2,%1,%0";
1569           }
1570         if (pattern)
1571           output_asm_insn (pattern, low);
1572         if (carry)
1573           {
1574             if (!rtx_equal_p (operands[0], operands[1]))
1575               return "movl %1,%0;sbwc %2,%0";
1576             return "sbwc %2,%0";
1577             /* %0 = %2 - %1 - C */
1578           }
1579         return get_insn_template (CODE_FOR_subsi3, insn);
1580       }
1581
1582     default:
1583       gcc_unreachable ();
1584   }
1585 }
1586
1587 /* True if X is an rtx for a constant that is a valid address.  */
1588
1589 bool
1590 legitimate_constant_address_p (rtx x)
1591 {
1592   if (GET_CODE (x) == LABEL_REF || GET_CODE (x) == SYMBOL_REF
1593           || CONST_INT_P (x) || GET_CODE (x) == HIGH)
1594     return true;
1595   if (GET_CODE (x) != CONST)
1596     return false;
1597 #ifdef NO_EXTERNAL_INDIRECT_ADDRESS
1598   if (flag_pic
1599       && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
1600       && !SYMBOL_REF_LOCAL_P (XEXP (XEXP (x, 0), 0)))
1601     return false;
1602 #endif
1603    return true;
1604 }
1605
1606 /* The other macros defined here are used only in legitimate_address_p ().  */
1607
1608 /* Nonzero if X is a hard reg that can be used as an index
1609    or, if not strict, if it is a pseudo reg.  */
1610 #define INDEX_REGISTER_P(X, STRICT) \
1611 (REG_P (X) && (!(STRICT) || REGNO_OK_FOR_INDEX_P (REGNO (X))))
1612
1613 /* Nonzero if X is a hard reg that can be used as a base reg
1614    or, if not strict, if it is a pseudo reg.  */
1615 #define BASE_REGISTER_P(X, STRICT) \
1616 (REG_P (X) && (!(STRICT) || REGNO_OK_FOR_BASE_P (REGNO (X))))
1617
1618 #ifdef NO_EXTERNAL_INDIRECT_ADDRESS
1619
1620 /* Re-definition of CONSTANT_ADDRESS_P, which is true only when there
1621    are no SYMBOL_REFs for external symbols present.  */
1622
1623 static bool
1624 indirectable_constant_address_p (rtx x, bool indirect)
1625 {
1626   if (GET_CODE (x) == SYMBOL_REF)
1627     return !flag_pic || SYMBOL_REF_LOCAL_P (x) || !indirect;
1628
1629   if (GET_CODE (x) == CONST)
1630     return !flag_pic
1631            || GET_CODE (XEXP (XEXP (x, 0), 0)) != SYMBOL_REF
1632            || SYMBOL_REF_LOCAL_P (XEXP (XEXP (x, 0), 0));
1633
1634   return CONSTANT_ADDRESS_P (x);
1635 }
1636
1637 #else /* not NO_EXTERNAL_INDIRECT_ADDRESS */
1638
1639 static bool
1640 indirectable_constant_address_p (rtx x, bool indirect ATTRIBUTE_UNUSED)
1641 {
1642   return CONSTANT_ADDRESS_P (x);
1643 }
1644
1645 #endif /* not NO_EXTERNAL_INDIRECT_ADDRESS */
1646
1647 /* True if X is an address which can be indirected.  External symbols
1648    could be in a sharable image library, so we disallow those.  */
1649
1650 static bool
1651 indirectable_address_p (rtx x, bool strict, bool indirect)
1652 {
1653   if (indirectable_constant_address_p (x, indirect)
1654       || BASE_REGISTER_P (x, strict))
1655     return true;
1656   if (GET_CODE (x) != PLUS
1657       || !BASE_REGISTER_P (XEXP (x, 0), strict)
1658       || (flag_pic && !CONST_INT_P (XEXP (x, 1))))
1659     return false;
1660   return indirectable_constant_address_p (XEXP (x, 1), indirect);
1661 }
1662
1663 /* Return true if x is a valid address not using indexing.
1664    (This much is the easy part.)  */
1665 static bool
1666 nonindexed_address_p (rtx x, bool strict)
1667 {
1668   rtx xfoo0;
1669   if (REG_P (x))
1670     {
1671       if (! reload_in_progress
1672           || reg_equiv_mem (REGNO (x)) == 0
1673           || indirectable_address_p (reg_equiv_mem (REGNO (x)), strict, false))
1674         return true;
1675     }
1676   if (indirectable_constant_address_p (x, false))
1677     return true;
1678   if (indirectable_address_p (x, strict, false))
1679     return true;
1680   xfoo0 = XEXP (x, 0);
1681   if (MEM_P (x) && indirectable_address_p (xfoo0, strict, true))
1682     return true;
1683   if ((GET_CODE (x) == PRE_DEC || GET_CODE (x) == POST_INC)
1684       && BASE_REGISTER_P (xfoo0, strict))
1685     return true;
1686   return false;
1687 }
1688
1689 /* True if PROD is either a reg times size of mode MODE and MODE is less
1690    than or equal 8 bytes, or just a reg if MODE is one byte.  */
1691
1692 static bool
1693 index_term_p (rtx prod, enum machine_mode mode, bool strict)
1694 {
1695   rtx xfoo0, xfoo1;
1696
1697   if (GET_MODE_SIZE (mode) == 1)
1698     return BASE_REGISTER_P (prod, strict);
1699
1700   if (GET_CODE (prod) != MULT || GET_MODE_SIZE (mode) > 8)
1701     return false;
1702
1703   xfoo0 = XEXP (prod, 0);
1704   xfoo1 = XEXP (prod, 1);
1705
1706   if (CONST_INT_P (xfoo0)
1707       && INTVAL (xfoo0) == (int)GET_MODE_SIZE (mode)
1708       && INDEX_REGISTER_P (xfoo1, strict))
1709     return true;
1710
1711   if (CONST_INT_P (xfoo1)
1712       && INTVAL (xfoo1) == (int)GET_MODE_SIZE (mode)
1713       && INDEX_REGISTER_P (xfoo0, strict))
1714     return true;
1715
1716   return false;
1717 }
1718
1719 /* Return true if X is the sum of a register
1720    and a valid index term for mode MODE.  */
1721 static bool
1722 reg_plus_index_p (rtx x, enum machine_mode mode, bool strict)
1723 {
1724   rtx xfoo0, xfoo1;
1725
1726   if (GET_CODE (x) != PLUS)
1727     return false;
1728
1729   xfoo0 = XEXP (x, 0);
1730   xfoo1 = XEXP (x, 1);
1731
1732   if (BASE_REGISTER_P (xfoo0, strict) && index_term_p (xfoo1, mode, strict))
1733     return true;
1734
1735   if (BASE_REGISTER_P (xfoo1, strict) && index_term_p (xfoo0, mode, strict))
1736     return true;
1737
1738   return false;
1739 }
1740
1741 /* Return true if xfoo0 and xfoo1 constitute a valid indexed address.  */
1742 static bool
1743 indexable_address_p (rtx xfoo0, rtx xfoo1, enum machine_mode mode, bool strict)
1744 {
1745   if (!CONSTANT_ADDRESS_P (xfoo0))
1746     return false;
1747   if (BASE_REGISTER_P (xfoo1, strict))
1748     return !flag_pic || mode == QImode;
1749   if (flag_pic && symbolic_operand (xfoo0, SImode))
1750     return false;
1751   return reg_plus_index_p (xfoo1, mode, strict);
1752 }
1753
1754 /* legitimate_address_p returns true if it recognizes an RTL expression "x"
1755    that is a valid memory address for an instruction.
1756    The MODE argument is the machine mode for the MEM expression
1757    that wants to use this address.  */
1758 bool
1759 vax_legitimate_address_p (enum machine_mode mode, rtx x, bool strict)
1760 {
1761   rtx xfoo0, xfoo1;
1762
1763   if (nonindexed_address_p (x, strict))
1764     return true;
1765
1766   if (GET_CODE (x) != PLUS)
1767     return false;
1768
1769   /* Handle <address>[index] represented with index-sum outermost */
1770
1771   xfoo0 = XEXP (x, 0);
1772   xfoo1 = XEXP (x, 1);
1773
1774   if (index_term_p (xfoo0, mode, strict)
1775       && nonindexed_address_p (xfoo1, strict))
1776     return true;
1777
1778   if (index_term_p (xfoo1, mode, strict)
1779       && nonindexed_address_p (xfoo0, strict))
1780     return true;
1781
1782   /* Handle offset(reg)[index] with offset added outermost */
1783
1784   if (indexable_address_p (xfoo0, xfoo1, mode, strict)
1785       || indexable_address_p (xfoo1, xfoo0, mode, strict))
1786     return true;
1787
1788   return false;
1789 }
1790
1791 /* Return true if x (a legitimate address expression) has an effect that
1792    depends on the machine mode it is used for.  On the VAX, the predecrement
1793    and postincrement address depend thus (the amount of decrement or
1794    increment being the length of the operand) and all indexed address depend
1795    thus (because the index scale factor is the length of the operand).  */
1796
1797 bool
1798 vax_mode_dependent_address_p (rtx x)
1799 {
1800   rtx xfoo0, xfoo1;
1801
1802   /* Auto-increment cases are now dealt with generically in recog.c.  */
1803   if (GET_CODE (x) != PLUS)
1804     return false;
1805
1806   xfoo0 = XEXP (x, 0);
1807   xfoo1 = XEXP (x, 1);
1808
1809   if (CONST_INT_P (xfoo0) && REG_P (xfoo1))
1810     return false;
1811   if (CONST_INT_P (xfoo1) && REG_P (xfoo0))
1812     return false;
1813   if (!flag_pic && CONSTANT_ADDRESS_P (xfoo0) && REG_P (xfoo1))
1814     return false;
1815   if (!flag_pic && CONSTANT_ADDRESS_P (xfoo1) && REG_P (xfoo0))
1816     return false;
1817
1818   return true;
1819 }
1820
1821 static rtx
1822 fixup_mathdi_operand (rtx x, enum machine_mode mode)
1823 {
1824   if (illegal_addsub_di_memory_operand (x, mode))
1825     {
1826       rtx addr = XEXP (x, 0);
1827       rtx temp = gen_reg_rtx (Pmode);
1828       rtx offset = 0;
1829 #ifdef NO_EXTERNAL_INDIRECT_ADDRESS
1830       if (GET_CODE (addr) == CONST && flag_pic)
1831         {
1832           offset = XEXP (XEXP (addr, 0), 1);
1833           addr = XEXP (XEXP (addr, 0), 0);
1834         }
1835 #endif
1836       emit_move_insn (temp, addr);
1837       if (offset)
1838         temp = gen_rtx_PLUS (Pmode, temp, offset);
1839       x = gen_rtx_MEM (DImode, temp);
1840     }
1841   return x;
1842 }
1843
1844 void
1845 vax_expand_addsub_di_operands (rtx * operands, enum rtx_code code)
1846 {
1847   int hi_only = operand_subword (operands[2], 0, 0, DImode) == const0_rtx;
1848   rtx temp;
1849
1850   rtx (*gen_old_insn)(rtx, rtx, rtx);
1851   rtx (*gen_si_insn)(rtx, rtx, rtx);
1852   rtx (*gen_insn)(rtx, rtx, rtx);
1853
1854   if (code == PLUS)
1855     {
1856       gen_old_insn = gen_adddi3_old;
1857       gen_si_insn = gen_addsi3;
1858       gen_insn = gen_adcdi3;
1859     }
1860   else if (code == MINUS)
1861     {
1862       gen_old_insn = gen_subdi3_old;
1863       gen_si_insn = gen_subsi3;
1864       gen_insn = gen_sbcdi3;
1865     }
1866   else
1867     gcc_unreachable ();
1868
1869   /* If this is addition (thus operands are commutative) and if there is one
1870      addend that duplicates the desination, we want that addend to be the
1871      first addend.  */
1872   if (code == PLUS
1873       && rtx_equal_p (operands[0], operands[2])
1874       && !rtx_equal_p (operands[1], operands[2]))
1875     {
1876       temp = operands[2];
1877       operands[2] = operands[1];
1878       operands[1] = temp;
1879     }
1880
1881   if (!TARGET_QMATH)
1882     {
1883       emit_insn ((*gen_old_insn) (operands[0], operands[1], operands[2]));
1884     }
1885   else if (hi_only)
1886     {
1887       if (!rtx_equal_p (operands[0], operands[1])
1888           && (REG_P (operands[0]) && MEM_P (operands[1])))
1889         {
1890           emit_move_insn (operands[0], operands[1]);
1891           operands[1] = operands[0];
1892         }
1893
1894       operands[0] = fixup_mathdi_operand (operands[0], DImode);
1895       operands[1] = fixup_mathdi_operand (operands[1], DImode);
1896       operands[2] = fixup_mathdi_operand (operands[2], DImode);
1897
1898       if (!rtx_equal_p (operands[0], operands[1]))
1899         emit_move_insn (operand_subword (operands[0], 0, 0, DImode),
1900                           operand_subword (operands[1], 0, 0, DImode));
1901
1902       emit_insn ((*gen_si_insn) (operand_subword (operands[0], 1, 0, DImode),
1903                                  operand_subword (operands[1], 1, 0, DImode),
1904                                  operand_subword (operands[2], 1, 0, DImode)));
1905     }
1906   else
1907     {
1908       /* If are adding the same value together, that's really a multiply by 2,
1909          and that's just a left shift of 1.  */
1910       if (rtx_equal_p (operands[1], operands[2]))
1911         {
1912           gcc_assert (code != MINUS);
1913           emit_insn (gen_ashldi3 (operands[0], operands[1], const1_rtx));
1914           return;
1915         }
1916
1917       operands[0] = fixup_mathdi_operand (operands[0], DImode);
1918
1919       /* If an operand is the same as operand[0], use the operand[0] rtx
1920          because fixup will an equivalent rtx but not an equal one. */
1921
1922       if (rtx_equal_p (operands[0], operands[1]))
1923         operands[1] = operands[0];
1924       else
1925         operands[1] = fixup_mathdi_operand (operands[1], DImode);
1926
1927       if (rtx_equal_p (operands[0], operands[2]))
1928         operands[2] = operands[0];
1929       else
1930         operands[2] = fixup_mathdi_operand (operands[2], DImode);
1931
1932       /* If we are subtracting not from ourselves [d = a - b], and because the
1933          carry ops are two operand only, we would need to do a move prior to
1934          the subtract.  And if d == b, we would need a temp otherwise
1935          [d = a, d -= d] and we end up with 0.  Instead we rewrite d = a - b
1936          into d = -b, d += a.  Since -b can never overflow, even if b == d,
1937          no temp is needed.
1938
1939          If we are doing addition, since the carry ops are two operand, if
1940          we aren't adding to ourselves, move the first addend to the
1941          destination first.  */
1942
1943       gcc_assert (operands[1] != const0_rtx || code == MINUS);
1944       if (!rtx_equal_p (operands[0], operands[1]) && operands[1] != const0_rtx)
1945         {
1946           if (code == MINUS && CONSTANT_P (operands[1]))
1947             {
1948               temp = gen_reg_rtx (DImode);
1949               emit_insn (gen_sbcdi3 (operands[0], const0_rtx, operands[2]));
1950               code = PLUS;
1951               gen_insn = gen_adcdi3;
1952               operands[2] = operands[1];
1953               operands[1] = operands[0];
1954             }
1955           else
1956             emit_move_insn (operands[0], operands[1]);
1957         }
1958
1959       /* Subtracting a constant will have been rewritten to an addition of the
1960          negative of that constant before we get here.  */
1961       gcc_assert (!CONSTANT_P (operands[2]) || code == PLUS);
1962       emit_insn ((*gen_insn) (operands[0], operands[1], operands[2]));
1963     }
1964 }
1965
1966 bool
1967 adjacent_operands_p (rtx lo, rtx hi, enum machine_mode mode)
1968 {
1969   HOST_WIDE_INT lo_offset;
1970   HOST_WIDE_INT hi_offset;
1971
1972   if (GET_CODE (lo) != GET_CODE (hi))
1973     return false;
1974
1975   if (REG_P (lo))
1976     return mode == SImode && REGNO (lo) + 1 == REGNO (hi);
1977   if (CONST_INT_P (lo))
1978     return INTVAL (hi) == 0 && 0 <= INTVAL (lo) && INTVAL (lo) < 64;
1979   if (CONST_INT_P (lo))
1980     return mode != SImode;
1981
1982   if (!MEM_P (lo))
1983     return false;
1984
1985   if (MEM_VOLATILE_P (lo) || MEM_VOLATILE_P (hi))
1986     return false;
1987
1988   lo = XEXP (lo, 0);
1989   hi = XEXP (hi, 0);
1990
1991   if (GET_CODE (lo) == POST_INC /* || GET_CODE (lo) == PRE_DEC */)
1992     return rtx_equal_p (lo, hi);
1993
1994   switch (GET_CODE (lo))
1995     {
1996     case REG:
1997     case SYMBOL_REF:
1998       lo_offset = 0;
1999       break;
2000     case CONST:
2001       lo = XEXP (lo, 0);
2002       /* FALLTHROUGH */
2003     case PLUS:
2004       if (!CONST_INT_P (XEXP (lo, 1)))
2005         return false;
2006       lo_offset = INTVAL (XEXP (lo, 1));
2007       lo = XEXP (lo, 0);
2008       break;
2009     default:
2010       return false;
2011     }
2012
2013   switch (GET_CODE (hi))
2014     {
2015     case REG:
2016     case SYMBOL_REF:
2017       hi_offset = 0;
2018       break;
2019     case CONST:
2020       hi = XEXP (hi, 0);
2021       /* FALLTHROUGH */
2022     case PLUS:
2023       if (!CONST_INT_P (XEXP (hi, 1)))
2024         return false;
2025       hi_offset = INTVAL (XEXP (hi, 1));
2026       hi = XEXP (hi, 0);
2027       break;
2028     default:
2029       return false;
2030     }
2031
2032   if (GET_CODE (lo) == MULT || GET_CODE (lo) == PLUS)
2033     return false;
2034
2035   return rtx_equal_p (lo, hi)
2036          && hi_offset - lo_offset == GET_MODE_SIZE (mode);
2037 }
2038
2039 /* Output assembler code for a block containing the constant parts
2040    of a trampoline, leaving space for the variable parts.  */
2041
2042 /* On the VAX, the trampoline contains an entry mask and two instructions:
2043      .word NN
2044      movl $STATIC,r0   (store the functions static chain)
2045      jmp  *$FUNCTION   (jump to function code at address FUNCTION)  */
2046
2047 static void
2048 vax_asm_trampoline_template (FILE *f ATTRIBUTE_UNUSED)
2049 {
2050   assemble_aligned_integer (2, const0_rtx);
2051   assemble_aligned_integer (2, GEN_INT (0x8fd0));
2052   assemble_aligned_integer (4, const0_rtx);
2053   assemble_aligned_integer (1, GEN_INT (0x50 + STATIC_CHAIN_REGNUM));
2054   assemble_aligned_integer (2, GEN_INT (0x9f17));
2055   assemble_aligned_integer (4, const0_rtx);
2056 }
2057
2058 /* We copy the register-mask from the function's pure code
2059    to the start of the trampoline.  */
2060
2061 static void
2062 vax_trampoline_init (rtx m_tramp, tree fndecl, rtx cxt)
2063 {
2064   rtx fnaddr = XEXP (DECL_RTL (fndecl), 0);
2065   rtx mem;
2066
2067   emit_block_move (m_tramp, assemble_trampoline_template (),
2068                    GEN_INT (TRAMPOLINE_SIZE), BLOCK_OP_NORMAL);
2069
2070   mem = adjust_address (m_tramp, HImode, 0);
2071   emit_move_insn (mem, gen_const_mem (HImode, fnaddr));
2072
2073   mem = adjust_address (m_tramp, SImode, 4);
2074   emit_move_insn (mem, cxt);
2075   mem = adjust_address (m_tramp, SImode, 11);
2076   emit_move_insn (mem, plus_constant (fnaddr, 2));
2077   emit_insn (gen_sync_istream ());
2078 }
2079
2080 /* Value is the number of bytes of arguments automatically
2081    popped when returning from a subroutine call.
2082    FUNDECL is the declaration node of the function (as a tree),
2083    FUNTYPE is the data type of the function (as a tree),
2084    or for a library call it is an identifier node for the subroutine name.
2085    SIZE is the number of bytes of arguments passed on the stack.
2086
2087    On the VAX, the RET insn pops a maximum of 255 args for any function.  */
2088
2089 static int
2090 vax_return_pops_args (tree fundecl ATTRIBUTE_UNUSED,
2091                       tree funtype ATTRIBUTE_UNUSED, int size)
2092 {
2093   return size > 255 * 4 ? 0 : size;
2094 }
2095
2096 /* Define where to put the arguments to a function.
2097    Value is zero to push the argument on the stack,
2098    or a hard register in which to store the argument.
2099
2100    MODE is the argument's machine mode.
2101    TYPE is the data type of the argument (as a tree).
2102     This is null for libcalls where that information may
2103     not be available.
2104    CUM is a variable of type CUMULATIVE_ARGS which gives info about
2105     the preceding args and about the function being called.
2106    NAMED is nonzero if this argument is a named parameter
2107     (otherwise it is an extra parameter matching an ellipsis).  */
2108
2109 /* On the VAX all args are pushed.  */
2110
2111 static rtx
2112 vax_function_arg (CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED,
2113                   enum machine_mode mode ATTRIBUTE_UNUSED,
2114                   const_tree type ATTRIBUTE_UNUSED,
2115                   bool named ATTRIBUTE_UNUSED)
2116 {
2117   return NULL_RTX;
2118 }
2119
2120 /* Update the data in CUM to advance over an argument of mode MODE and
2121    data type TYPE.  (TYPE is null for libcalls where that information
2122    may not be available.)  */
2123
2124 static void
2125 vax_function_arg_advance (CUMULATIVE_ARGS *cum, enum machine_mode mode,
2126                           const_tree type, bool named ATTRIBUTE_UNUSED)
2127 {
2128   *cum += (mode != BLKmode
2129            ? (GET_MODE_SIZE (mode) + 3) & ~3
2130            : (int_size_in_bytes (type) + 3) & ~3);
2131 }