OSDN Git Service

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