OSDN Git Service

PR middle-end/20983
[pf3gnuchains/gcc-fork.git] / gcc / config / mn10300 / mn10300.c
1 /* Subroutines for insn-output.c for Matsushita MN10300 series
2    Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
3    2005, 2006, 2007 Free Software Foundation, Inc.
4    Contributed by Jeff Law (law@cygnus.com).
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 "tree.h"
28 #include "regs.h"
29 #include "hard-reg-set.h"
30 #include "real.h"
31 #include "insn-config.h"
32 #include "conditions.h"
33 #include "output.h"
34 #include "insn-attr.h"
35 #include "flags.h"
36 #include "recog.h"
37 #include "expr.h"
38 #include "optabs.h"
39 #include "function.h"
40 #include "obstack.h"
41 #include "toplev.h"
42 #include "tm_p.h"
43 #include "target.h"
44 #include "target-def.h"
45
46 /* This is used by GOTaddr2picreg to uniquely identify
47    UNSPEC_INT_LABELs.  */
48 int mn10300_unspec_int_label_counter;
49
50 /* This is used in the am33_2.0-linux-gnu port, in which global symbol
51    names are not prefixed by underscores, to tell whether to prefix a
52    label with a plus sign or not, so that the assembler can tell
53    symbol names from register names.  */
54 int mn10300_protect_label;
55
56 /* The selected processor.  */
57 enum processor_type mn10300_processor = PROCESSOR_DEFAULT;
58
59 /* The size of the callee register save area.  Right now we save everything
60    on entry since it costs us nothing in code size.  It does cost us from a
61    speed standpoint, so we want to optimize this sooner or later.  */
62 #define REG_SAVE_BYTES (4 * df_regs_ever_live_p (2)     \
63                         + 4 * df_regs_ever_live_p (3)   \
64                         + 4 * df_regs_ever_live_p (6)   \
65                         + 4 * df_regs_ever_live_p (7)                   \
66                         + 16 * (df_regs_ever_live_p (14) || df_regs_ever_live_p (15) \
67                                 || df_regs_ever_live_p (16) || df_regs_ever_live_p (17)))
68
69
70 static bool mn10300_handle_option (size_t, const char *, int);
71 static int mn10300_address_cost_1 (rtx, int *);
72 static int mn10300_address_cost (rtx);
73 static bool mn10300_rtx_costs (rtx, int, int, int *);
74 static void mn10300_file_start (void);
75 static bool mn10300_return_in_memory (const_tree, const_tree);
76 static rtx mn10300_builtin_saveregs (void);
77 static void mn10300_va_start (tree, rtx);
78 static bool mn10300_pass_by_reference (CUMULATIVE_ARGS *, enum machine_mode,
79                                        const_tree, bool);
80 static int mn10300_arg_partial_bytes (CUMULATIVE_ARGS *, enum machine_mode,
81                                       tree, bool);
82 \f
83 /* Initialize the GCC target structure.  */
84 #undef TARGET_ASM_ALIGNED_HI_OP
85 #define TARGET_ASM_ALIGNED_HI_OP "\t.hword\t"
86
87 #undef TARGET_RTX_COSTS
88 #define TARGET_RTX_COSTS mn10300_rtx_costs
89 #undef TARGET_ADDRESS_COST
90 #define TARGET_ADDRESS_COST mn10300_address_cost
91
92 #undef TARGET_ASM_FILE_START
93 #define TARGET_ASM_FILE_START mn10300_file_start
94 #undef TARGET_ASM_FILE_START_FILE_DIRECTIVE
95 #define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
96
97 #undef TARGET_DEFAULT_TARGET_FLAGS
98 #define TARGET_DEFAULT_TARGET_FLAGS MASK_MULT_BUG | MASK_PTR_A0D0
99 #undef TARGET_HANDLE_OPTION
100 #define TARGET_HANDLE_OPTION mn10300_handle_option
101
102 #undef  TARGET_ENCODE_SECTION_INFO
103 #define TARGET_ENCODE_SECTION_INFO mn10300_encode_section_info
104
105 #undef TARGET_PROMOTE_PROTOTYPES
106 #define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
107 #undef TARGET_RETURN_IN_MEMORY
108 #define TARGET_RETURN_IN_MEMORY mn10300_return_in_memory
109 #undef TARGET_PASS_BY_REFERENCE
110 #define TARGET_PASS_BY_REFERENCE mn10300_pass_by_reference
111 #undef TARGET_CALLEE_COPIES
112 #define TARGET_CALLEE_COPIES hook_bool_CUMULATIVE_ARGS_mode_tree_bool_true
113 #undef TARGET_ARG_PARTIAL_BYTES
114 #define TARGET_ARG_PARTIAL_BYTES mn10300_arg_partial_bytes
115
116 #undef TARGET_EXPAND_BUILTIN_SAVEREGS
117 #define TARGET_EXPAND_BUILTIN_SAVEREGS mn10300_builtin_saveregs
118 #undef TARGET_EXPAND_BUILTIN_VA_START
119 #define TARGET_EXPAND_BUILTIN_VA_START mn10300_va_start
120
121 static void mn10300_encode_section_info (tree, rtx, int);
122 struct gcc_target targetm = TARGET_INITIALIZER;
123 \f
124 /* Implement TARGET_HANDLE_OPTION.  */
125
126 static bool
127 mn10300_handle_option (size_t code,
128                        const char *arg ATTRIBUTE_UNUSED,
129                        int value)
130 {
131   switch (code)
132     {
133     case OPT_mam33:
134       mn10300_processor = value ? PROCESSOR_AM33 : PROCESSOR_MN10300;
135       return true;
136     case OPT_mam33_2:
137       mn10300_processor = (value
138                            ? PROCESSOR_AM33_2
139                            : MIN (PROCESSOR_AM33, PROCESSOR_DEFAULT));
140       return true;
141     default:
142       return true;
143     }
144 }
145
146 /* Implement OVERRIDE_OPTIONS.  */
147
148 void
149 mn10300_override_options (void)
150 {
151   if (TARGET_AM33)
152     target_flags &= ~MASK_MULT_BUG;
153 }
154
155 static void
156 mn10300_file_start (void)
157 {
158   default_file_start ();
159
160   if (TARGET_AM33_2)
161     fprintf (asm_out_file, "\t.am33_2\n");
162   else if (TARGET_AM33)
163     fprintf (asm_out_file, "\t.am33\n");
164 }
165 \f
166
167 /* Print operand X using operand code CODE to assembly language output file
168    FILE.  */
169
170 void
171 print_operand (FILE *file, rtx x, int code)
172 {
173   switch (code)
174     {
175       case 'b':
176       case 'B':
177         if (cc_status.mdep.fpCC)
178           {
179             switch (code == 'b' ? GET_CODE (x)
180                     : reverse_condition_maybe_unordered (GET_CODE (x)))
181               {
182               case NE:
183                 fprintf (file, "ne");
184                 break;
185               case EQ:
186                 fprintf (file, "eq");
187                 break;
188               case GE:
189                 fprintf (file, "ge");
190                 break;
191               case GT:
192                 fprintf (file, "gt");
193                 break;
194               case LE:
195                 fprintf (file, "le");
196                 break;
197               case LT:
198                 fprintf (file, "lt");
199                 break;
200               case ORDERED:
201                 fprintf (file, "lge");
202                 break;
203               case UNORDERED:
204                 fprintf (file, "uo");
205                 break;
206               case LTGT:
207                 fprintf (file, "lg");
208                 break;
209               case UNEQ:
210                 fprintf (file, "ue");
211                 break;
212               case UNGE:
213                 fprintf (file, "uge");
214                 break;
215               case UNGT:
216                 fprintf (file, "ug");
217                 break;
218               case UNLE:
219                 fprintf (file, "ule");
220                 break;
221               case UNLT:
222                 fprintf (file, "ul");
223                 break;
224               default:
225                 gcc_unreachable ();
226               }
227             break;
228           }
229         /* These are normal and reversed branches.  */
230         switch (code == 'b' ? GET_CODE (x) : reverse_condition (GET_CODE (x)))
231           {
232           case NE:
233             fprintf (file, "ne");
234             break;
235           case EQ:
236             fprintf (file, "eq");
237             break;
238           case GE:
239             fprintf (file, "ge");
240             break;
241           case GT:
242             fprintf (file, "gt");
243             break;
244           case LE:
245             fprintf (file, "le");
246             break;
247           case LT:
248             fprintf (file, "lt");
249             break;
250           case GEU:
251             fprintf (file, "cc");
252             break;
253           case GTU:
254             fprintf (file, "hi");
255             break;
256           case LEU:
257             fprintf (file, "ls");
258             break;
259           case LTU:
260             fprintf (file, "cs");
261             break;
262           default:
263             gcc_unreachable ();
264           }
265         break;
266       case 'C':
267         /* This is used for the operand to a call instruction;
268            if it's a REG, enclose it in parens, else output
269            the operand normally.  */
270         if (GET_CODE (x) == REG)
271           {
272             fputc ('(', file);
273             print_operand (file, x, 0);
274             fputc (')', file);
275           }
276         else
277           print_operand (file, x, 0);
278         break;
279
280       case 'D':
281         switch (GET_CODE (x))
282           {
283           case MEM:
284             fputc ('(', file);
285             output_address (XEXP (x, 0));
286             fputc (')', file);
287             break;
288
289           case REG:
290             fprintf (file, "fd%d", REGNO (x) - 18);
291             break;
292
293           default:
294             gcc_unreachable ();
295           }
296         break;
297
298       /* These are the least significant word in a 64bit value.  */
299       case 'L':
300         switch (GET_CODE (x))
301           {
302           case MEM:
303             fputc ('(', file);
304             output_address (XEXP (x, 0));
305             fputc (')', file);
306             break;
307
308           case REG:
309             fprintf (file, "%s", reg_names[REGNO (x)]);
310             break;
311
312           case SUBREG:
313             fprintf (file, "%s", reg_names[subreg_regno (x)]);
314             break;
315
316           case CONST_DOUBLE:
317               {
318                 long val[2];
319                 REAL_VALUE_TYPE rv;
320
321                 switch (GET_MODE (x))
322                   {
323                     case DFmode:
324                       REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
325                       REAL_VALUE_TO_TARGET_DOUBLE (rv, val);
326                       fprintf (file, "0x%lx", val[0]);
327                       break;;
328                     case SFmode:
329                       REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
330                       REAL_VALUE_TO_TARGET_SINGLE (rv, val[0]);
331                       fprintf (file, "0x%lx", val[0]);
332                       break;;
333                     case VOIDmode:
334                     case DImode:
335                       print_operand_address (file,
336                                              GEN_INT (CONST_DOUBLE_LOW (x)));
337                       break;
338                     default:
339                       break;
340                   }
341                 break;
342               }
343
344           case CONST_INT:
345             {
346               rtx low, high;
347               split_double (x, &low, &high);
348               fprintf (file, "%ld", (long)INTVAL (low));
349               break;
350             }
351
352           default:
353             gcc_unreachable ();
354           }
355         break;
356
357       /* Similarly, but for the most significant word.  */
358       case 'H':
359         switch (GET_CODE (x))
360           {
361           case MEM:
362             fputc ('(', file);
363             x = adjust_address (x, SImode, 4);
364             output_address (XEXP (x, 0));
365             fputc (')', file);
366             break;
367
368           case REG:
369             fprintf (file, "%s", reg_names[REGNO (x) + 1]);
370             break;
371
372           case SUBREG:
373             fprintf (file, "%s", reg_names[subreg_regno (x) + 1]);
374             break;
375
376           case CONST_DOUBLE:
377               {
378                 long val[2];
379                 REAL_VALUE_TYPE rv;
380
381                 switch (GET_MODE (x))
382                   {
383                     case DFmode:
384                       REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
385                       REAL_VALUE_TO_TARGET_DOUBLE (rv, val);
386                       fprintf (file, "0x%lx", val[1]);
387                       break;;
388                     case SFmode:
389                       gcc_unreachable ();
390                     case VOIDmode:
391                     case DImode:
392                       print_operand_address (file,
393                                              GEN_INT (CONST_DOUBLE_HIGH (x)));
394                       break;
395                     default:
396                       break;
397                   }
398                 break;
399               }
400
401           case CONST_INT:
402             {
403               rtx low, high;
404               split_double (x, &low, &high);
405               fprintf (file, "%ld", (long)INTVAL (high));
406               break;
407             }
408
409           default:
410             gcc_unreachable ();
411           }
412         break;
413
414       case 'A':
415         fputc ('(', file);
416         if (GET_CODE (XEXP (x, 0)) == REG)
417           output_address (gen_rtx_PLUS (SImode, XEXP (x, 0), const0_rtx));
418         else
419           output_address (XEXP (x, 0));
420         fputc (')', file);
421         break;
422
423       case 'N':
424         gcc_assert (INTVAL (x) >= -128 && INTVAL (x) <= 255);
425         fprintf (file, "%d", (int)((~INTVAL (x)) & 0xff));
426         break;
427
428       case 'U':
429         gcc_assert (INTVAL (x) >= -128 && INTVAL (x) <= 255);
430         fprintf (file, "%d", (int)(INTVAL (x) & 0xff));
431         break;
432
433       /* For shift counts.  The hardware ignores the upper bits of
434          any immediate, but the assembler will flag an out of range
435          shift count as an error.  So we mask off the high bits
436          of the immediate here.  */
437       case 'S':
438         if (GET_CODE (x) == CONST_INT)
439           {
440             fprintf (file, "%d", (int)(INTVAL (x) & 0x1f));
441             break;
442           }
443         /* FALL THROUGH */
444
445       default:
446         switch (GET_CODE (x))
447           {
448           case MEM:
449             fputc ('(', file);
450             output_address (XEXP (x, 0));
451             fputc (')', file);
452             break;
453
454           case PLUS:
455             output_address (x);
456             break;
457
458           case REG:
459             fprintf (file, "%s", reg_names[REGNO (x)]);
460             break;
461
462           case SUBREG:
463             fprintf (file, "%s", reg_names[subreg_regno (x)]);
464             break;
465
466           /* This will only be single precision....  */
467           case CONST_DOUBLE:
468             {
469               unsigned long val;
470               REAL_VALUE_TYPE rv;
471
472               REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
473               REAL_VALUE_TO_TARGET_SINGLE (rv, val);
474               fprintf (file, "0x%lx", val);
475               break;
476             }
477
478           case CONST_INT:
479           case SYMBOL_REF:
480           case CONST:
481           case LABEL_REF:
482           case CODE_LABEL:
483           case UNSPEC:
484             print_operand_address (file, x);
485             break;
486           default:
487             gcc_unreachable ();
488           }
489         break;
490    }
491 }
492
493 /* Output assembly language output for the address ADDR to FILE.  */
494
495 void
496 print_operand_address (FILE *file, rtx addr)
497 {
498   switch (GET_CODE (addr))
499     {
500     case POST_INC:
501       print_operand_address (file, XEXP (addr, 0));
502       fputc ('+', file);
503       break;
504     case REG:
505       print_operand (file, addr, 0);
506       break;
507     case PLUS:
508       {
509         rtx base, index;
510         if (REG_P (XEXP (addr, 0))
511             && REG_OK_FOR_BASE_P (XEXP (addr, 0)))
512           base = XEXP (addr, 0), index = XEXP (addr, 1);
513         else if (REG_P (XEXP (addr, 1))
514             && REG_OK_FOR_BASE_P (XEXP (addr, 1)))
515           base = XEXP (addr, 1), index = XEXP (addr, 0);
516         else
517           gcc_unreachable ();
518         print_operand (file, index, 0);
519         fputc (',', file);
520         print_operand (file, base, 0);;
521         break;
522       }
523     case SYMBOL_REF:
524       output_addr_const (file, addr);
525       break;
526     default:
527       output_addr_const (file, addr);
528       break;
529     }
530 }
531
532 /* Count the number of FP registers that have to be saved.  */
533 static int
534 fp_regs_to_save (void)
535 {
536   int i, n = 0;
537
538   if (! TARGET_AM33_2)
539     return 0;
540
541   for (i = FIRST_FP_REGNUM; i <= LAST_FP_REGNUM; ++i)
542     if (df_regs_ever_live_p (i) && ! call_used_regs[i])
543       ++n;
544
545   return n;
546 }
547
548 /* Print a set of registers in the format required by "movm" and "ret".
549    Register K is saved if bit K of MASK is set.  The data and address
550    registers can be stored individually, but the extended registers cannot.
551    We assume that the mask already takes that into account.  For instance,
552    bits 14 to 17 must have the same value.  */
553
554 void
555 mn10300_print_reg_list (FILE *file, int mask)
556 {
557   int need_comma;
558   int i;
559
560   need_comma = 0;
561   fputc ('[', file);
562
563   for (i = 0; i < FIRST_EXTENDED_REGNUM; i++)
564     if ((mask & (1 << i)) != 0)
565       {
566         if (need_comma)
567           fputc (',', file);
568         fputs (reg_names [i], file);
569         need_comma = 1;
570       }
571
572   if ((mask & 0x3c000) != 0)
573     {
574       gcc_assert ((mask & 0x3c000) == 0x3c000);
575       if (need_comma)
576         fputc (',', file);
577       fputs ("exreg1", file);
578       need_comma = 1;
579     }
580
581   fputc (']', file);
582 }
583
584 int
585 can_use_return_insn (void)
586 {
587   /* size includes the fixed stack space needed for function calls.  */
588   int size = get_frame_size () + current_function_outgoing_args_size;
589
590   /* And space for the return pointer.  */
591   size += current_function_outgoing_args_size ? 4 : 0;
592
593   return (reload_completed
594           && size == 0
595           && !df_regs_ever_live_p (2)
596           && !df_regs_ever_live_p (3)
597           && !df_regs_ever_live_p (6)
598           && !df_regs_ever_live_p (7)
599           && !df_regs_ever_live_p (14)
600           && !df_regs_ever_live_p (15)
601           && !df_regs_ever_live_p (16)
602           && !df_regs_ever_live_p (17)
603           && fp_regs_to_save () == 0
604           && !frame_pointer_needed);
605 }
606
607 /* Returns the set of live, callee-saved registers as a bitmask.  The
608    callee-saved extended registers cannot be stored individually, so
609    all of them will be included in the mask if any one of them is used.  */
610
611 int
612 mn10300_get_live_callee_saved_regs (void)
613 {
614   int mask;
615   int i;
616
617   mask = 0;
618   for (i = 0; i <= LAST_EXTENDED_REGNUM; i++)
619     if (df_regs_ever_live_p (i) && ! call_used_regs[i])
620       mask |= (1 << i);
621   if ((mask & 0x3c000) != 0)
622     mask |= 0x3c000;
623
624   return mask;
625 }
626
627 /* Generate an instruction that pushes several registers onto the stack.
628    Register K will be saved if bit K in MASK is set.  The function does
629    nothing if MASK is zero.
630
631    To be compatible with the "movm" instruction, the lowest-numbered
632    register must be stored in the lowest slot.  If MASK is the set
633    { R1,...,RN }, where R1...RN are ordered least first, the generated
634    instruction will have the form:
635
636        (parallel
637          (set (reg:SI 9) (plus:SI (reg:SI 9) (const_int -N*4)))
638          (set (mem:SI (plus:SI (reg:SI 9)
639                                (const_int -1*4)))
640               (reg:SI RN))
641          ...
642          (set (mem:SI (plus:SI (reg:SI 9)
643                                (const_int -N*4)))
644               (reg:SI R1))) */
645
646 void
647 mn10300_gen_multiple_store (int mask)
648 {
649   if (mask != 0)
650     {
651       int i;
652       int count;
653       rtx par;
654       int pari;
655
656       /* Count how many registers need to be saved.  */
657       count = 0;
658       for (i = 0; i <= LAST_EXTENDED_REGNUM; i++)
659         if ((mask & (1 << i)) != 0)
660           count += 1;
661
662       /* We need one PARALLEL element to update the stack pointer and
663          an additional element for each register that is stored.  */
664       par = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count + 1));
665
666       /* Create the instruction that updates the stack pointer.  */
667       XVECEXP (par, 0, 0)
668         = gen_rtx_SET (SImode,
669                        stack_pointer_rtx,
670                        gen_rtx_PLUS (SImode,
671                                      stack_pointer_rtx,
672                                      GEN_INT (-count * 4)));
673
674       /* Create each store.  */
675       pari = 1;
676       for (i = LAST_EXTENDED_REGNUM; i >= 0; i--)
677         if ((mask & (1 << i)) != 0)
678           {
679             rtx address = gen_rtx_PLUS (SImode,
680                                         stack_pointer_rtx,
681                                         GEN_INT (-pari * 4));
682             XVECEXP(par, 0, pari)
683               = gen_rtx_SET (VOIDmode,
684                              gen_rtx_MEM (SImode, address),
685                              gen_rtx_REG (SImode, i));
686             pari += 1;
687           }
688
689       par = emit_insn (par);
690       RTX_FRAME_RELATED_P (par) = 1;
691     }
692 }
693
694 void
695 expand_prologue (void)
696 {
697   HOST_WIDE_INT size;
698
699   /* SIZE includes the fixed stack space needed for function calls.  */
700   size = get_frame_size () + current_function_outgoing_args_size;
701   size += (current_function_outgoing_args_size ? 4 : 0);
702
703   /* If we use any of the callee-saved registers, save them now.  */
704   mn10300_gen_multiple_store (mn10300_get_live_callee_saved_regs ());
705
706   if (TARGET_AM33_2 && fp_regs_to_save ())
707     {
708       int num_regs_to_save = fp_regs_to_save (), i;
709       HOST_WIDE_INT xsize;
710       enum { save_sp_merge,
711              save_sp_no_merge,
712              save_sp_partial_merge,
713              save_a0_merge,
714              save_a0_no_merge } strategy;
715       unsigned int strategy_size = (unsigned)-1, this_strategy_size;
716       rtx reg;
717       rtx insn;
718
719       /* We have several different strategies to save FP registers.
720          We can store them using SP offsets, which is beneficial if
721          there are just a few registers to save, or we can use `a0' in
722          post-increment mode (`a0' is the only call-clobbered address
723          register that is never used to pass information to a
724          function).  Furthermore, if we don't need a frame pointer, we
725          can merge the two SP adds into a single one, but this isn't
726          always beneficial; sometimes we can just split the two adds
727          so that we don't exceed a 16-bit constant size.  The code
728          below will select which strategy to use, so as to generate
729          smallest code.  Ties are broken in favor or shorter sequences
730          (in terms of number of instructions).  */
731
732 #define SIZE_ADD_AX(S) ((((S) >= (1 << 15)) || ((S) < -(1 << 15))) ? 6 \
733                         : (((S) >= (1 << 7)) || ((S) < -(1 << 7))) ? 4 : 2)
734 #define SIZE_ADD_SP(S) ((((S) >= (1 << 15)) || ((S) < -(1 << 15))) ? 6 \
735                         : (((S) >= (1 << 7)) || ((S) < -(1 << 7))) ? 4 : 3)
736 #define SIZE_FMOV_LIMIT(S,N,L,SIZE1,SIZE2,ELSE) \
737   (((S) >= (L)) ? (SIZE1) * (N) \
738    : ((S) + 4 * (N) >= (L)) ? (((L) - (S)) / 4 * (SIZE2) \
739                                + ((S) + 4 * (N) - (L)) / 4 * (SIZE1)) \
740    : (ELSE))
741 #define SIZE_FMOV_SP_(S,N) \
742   (SIZE_FMOV_LIMIT ((S), (N), (1 << 24), 7, 6, \
743                    SIZE_FMOV_LIMIT ((S), (N), (1 << 8), 6, 4, \
744                                     (S) ? 4 * (N) : 3 + 4 * ((N) - 1))))
745 #define SIZE_FMOV_SP(S,N) (SIZE_FMOV_SP_ ((unsigned HOST_WIDE_INT)(S), (N)))
746
747       /* Consider alternative save_sp_merge only if we don't need the
748          frame pointer and size is nonzero.  */
749       if (! frame_pointer_needed && size)
750         {
751           /* Insn: add -(size + 4 * num_regs_to_save), sp.  */
752           this_strategy_size = SIZE_ADD_SP (-(size + 4 * num_regs_to_save));
753           /* Insn: fmov fs#, (##, sp), for each fs# to be saved.  */
754           this_strategy_size += SIZE_FMOV_SP (size, num_regs_to_save);
755
756           if (this_strategy_size < strategy_size)
757             {
758               strategy = save_sp_merge;
759               strategy_size = this_strategy_size;
760             }
761         }
762
763       /* Consider alternative save_sp_no_merge unconditionally.  */
764       /* Insn: add -4 * num_regs_to_save, sp.  */
765       this_strategy_size = SIZE_ADD_SP (-4 * num_regs_to_save);
766       /* Insn: fmov fs#, (##, sp), for each fs# to be saved.  */
767       this_strategy_size += SIZE_FMOV_SP (0, num_regs_to_save);
768       if (size)
769         {
770           /* Insn: add -size, sp.  */
771           this_strategy_size += SIZE_ADD_SP (-size);
772         }
773
774       if (this_strategy_size < strategy_size)
775         {
776           strategy = save_sp_no_merge;
777           strategy_size = this_strategy_size;
778         }
779
780       /* Consider alternative save_sp_partial_merge only if we don't
781          need a frame pointer and size is reasonably large.  */
782       if (! frame_pointer_needed && size + 4 * num_regs_to_save > 128)
783         {
784           /* Insn: add -128, sp.  */
785           this_strategy_size = SIZE_ADD_SP (-128);
786           /* Insn: fmov fs#, (##, sp), for each fs# to be saved.  */
787           this_strategy_size += SIZE_FMOV_SP (128 - 4 * num_regs_to_save,
788                                               num_regs_to_save);
789           if (size)
790             {
791               /* Insn: add 128-size, sp.  */
792               this_strategy_size += SIZE_ADD_SP (128 - size);
793             }
794
795           if (this_strategy_size < strategy_size)
796             {
797               strategy = save_sp_partial_merge;
798               strategy_size = this_strategy_size;
799             }
800         }
801
802       /* Consider alternative save_a0_merge only if we don't need a
803          frame pointer, size is nonzero and the user hasn't
804          changed the calling conventions of a0.  */
805       if (! frame_pointer_needed && size
806           && call_used_regs[FIRST_ADDRESS_REGNUM]
807           && ! fixed_regs[FIRST_ADDRESS_REGNUM])
808         {
809           /* Insn: add -(size + 4 * num_regs_to_save), sp.  */
810           this_strategy_size = SIZE_ADD_SP (-(size + 4 * num_regs_to_save));
811           /* Insn: mov sp, a0.  */
812           this_strategy_size++;
813           if (size)
814             {
815               /* Insn: add size, a0.  */
816               this_strategy_size += SIZE_ADD_AX (size);
817             }
818           /* Insn: fmov fs#, (a0+), for each fs# to be saved.  */
819           this_strategy_size += 3 * num_regs_to_save;
820
821           if (this_strategy_size < strategy_size)
822             {
823               strategy = save_a0_merge;
824               strategy_size = this_strategy_size;
825             }
826         }
827
828       /* Consider alternative save_a0_no_merge if the user hasn't
829          changed the calling conventions of a0.  */
830       if (call_used_regs[FIRST_ADDRESS_REGNUM]
831           && ! fixed_regs[FIRST_ADDRESS_REGNUM])
832         {
833           /* Insn: add -4 * num_regs_to_save, sp.  */
834           this_strategy_size = SIZE_ADD_SP (-4 * num_regs_to_save);
835           /* Insn: mov sp, a0.  */
836           this_strategy_size++;
837           /* Insn: fmov fs#, (a0+), for each fs# to be saved.  */
838           this_strategy_size += 3 * num_regs_to_save;
839           if (size)
840             {
841               /* Insn: add -size, sp.  */
842               this_strategy_size += SIZE_ADD_SP (-size);
843             }
844
845           if (this_strategy_size < strategy_size)
846             {
847               strategy = save_a0_no_merge;
848               strategy_size = this_strategy_size;
849             }
850         }
851
852       /* Emit the initial SP add, common to all strategies.  */
853       switch (strategy)
854         {
855         case save_sp_no_merge:
856         case save_a0_no_merge:
857           emit_insn (gen_addsi3 (stack_pointer_rtx,
858                                  stack_pointer_rtx,
859                                  GEN_INT (-4 * num_regs_to_save)));
860           xsize = 0;
861           break;
862
863         case save_sp_partial_merge:
864           emit_insn (gen_addsi3 (stack_pointer_rtx,
865                                  stack_pointer_rtx,
866                                  GEN_INT (-128)));
867           xsize = 128 - 4 * num_regs_to_save;
868           size -= xsize;
869           break;
870
871         case save_sp_merge:
872         case save_a0_merge:
873           emit_insn (gen_addsi3 (stack_pointer_rtx,
874                                  stack_pointer_rtx,
875                                  GEN_INT (-(size + 4 * num_regs_to_save))));
876           /* We'll have to adjust FP register saves according to the
877              frame size.  */
878           xsize = size;
879           /* Since we've already created the stack frame, don't do it
880              again at the end of the function.  */
881           size = 0;
882           break;
883
884         default:
885           gcc_unreachable ();
886         }
887
888       /* Now prepare register a0, if we have decided to use it.  */
889       switch (strategy)
890         {
891         case save_sp_merge:
892         case save_sp_no_merge:
893         case save_sp_partial_merge:
894           reg = 0;
895           break;
896
897         case save_a0_merge:
898         case save_a0_no_merge:
899           reg = gen_rtx_REG (SImode, FIRST_ADDRESS_REGNUM);
900           emit_insn (gen_movsi (reg, stack_pointer_rtx));
901           if (xsize)
902             emit_insn (gen_addsi3 (reg, reg, GEN_INT (xsize)));
903           reg = gen_rtx_POST_INC (SImode, reg);
904           break;
905
906         default:
907           gcc_unreachable ();
908         }
909
910       /* Now actually save the FP registers.  */
911       for (i = FIRST_FP_REGNUM; i <= LAST_FP_REGNUM; ++i)
912         if (df_regs_ever_live_p (i) && ! call_used_regs[i])
913           {
914             rtx addr;
915
916             if (reg)
917               addr = reg;
918             else
919               {
920                 /* If we aren't using `a0', use an SP offset.  */
921                 if (xsize)
922                   {
923                     addr = gen_rtx_PLUS (SImode,
924                                          stack_pointer_rtx,
925                                          GEN_INT (xsize));
926                   }
927                 else
928                   addr = stack_pointer_rtx;
929
930                 xsize += 4;
931               }
932
933             insn = emit_insn (gen_movsi (gen_rtx_MEM (SImode, addr),
934                                          gen_rtx_REG (SImode, i)));
935
936             RTX_FRAME_RELATED_P (insn) = 1;
937           }
938     }
939
940   /* Now put the frame pointer into the frame pointer register.  */
941   if (frame_pointer_needed)
942     emit_move_insn (frame_pointer_rtx, stack_pointer_rtx);
943
944   /* Allocate stack for this frame.  */
945   if (size)
946     emit_insn (gen_addsi3 (stack_pointer_rtx,
947                            stack_pointer_rtx,
948                            GEN_INT (-size)));
949   if (flag_pic && df_regs_ever_live_p (PIC_OFFSET_TABLE_REGNUM))
950     emit_insn (gen_GOTaddr2picreg ());
951 }
952
953 void
954 expand_epilogue (void)
955 {
956   HOST_WIDE_INT size;
957
958   /* SIZE includes the fixed stack space needed for function calls.  */
959   size = get_frame_size () + current_function_outgoing_args_size;
960   size += (current_function_outgoing_args_size ? 4 : 0);
961
962   if (TARGET_AM33_2 && fp_regs_to_save ())
963     {
964       int num_regs_to_save = fp_regs_to_save (), i;
965       rtx reg = 0;
966
967       /* We have several options to restore FP registers.  We could
968          load them from SP offsets, but, if there are enough FP
969          registers to restore, we win if we use a post-increment
970          addressing mode.  */
971
972       /* If we have a frame pointer, it's the best option, because we
973          already know it has the value we want.  */
974       if (frame_pointer_needed)
975         reg = gen_rtx_REG (SImode, FRAME_POINTER_REGNUM);
976       /* Otherwise, we may use `a1', since it's call-clobbered and
977          it's never used for return values.  But only do so if it's
978          smaller than using SP offsets.  */
979       else
980         {
981           enum { restore_sp_post_adjust,
982                  restore_sp_pre_adjust,
983                  restore_sp_partial_adjust,
984                  restore_a1 } strategy;
985           unsigned int this_strategy_size, strategy_size = (unsigned)-1;
986
987           /* Consider using sp offsets before adjusting sp.  */
988           /* Insn: fmov (##,sp),fs#, for each fs# to be restored.  */
989           this_strategy_size = SIZE_FMOV_SP (size, num_regs_to_save);
990           /* If size is too large, we'll have to adjust SP with an
991                  add.  */
992           if (size + 4 * num_regs_to_save + REG_SAVE_BYTES > 255)
993             {
994               /* Insn: add size + 4 * num_regs_to_save, sp.  */
995               this_strategy_size += SIZE_ADD_SP (size + 4 * num_regs_to_save);
996             }
997           /* If we don't have to restore any non-FP registers,
998                  we'll be able to save one byte by using rets.  */
999           if (! REG_SAVE_BYTES)
1000             this_strategy_size--;
1001
1002           if (this_strategy_size < strategy_size)
1003             {
1004               strategy = restore_sp_post_adjust;
1005               strategy_size = this_strategy_size;
1006             }
1007
1008           /* Consider using sp offsets after adjusting sp.  */
1009           /* Insn: add size, sp.  */
1010           this_strategy_size = SIZE_ADD_SP (size);
1011           /* Insn: fmov (##,sp),fs#, for each fs# to be restored.  */
1012           this_strategy_size += SIZE_FMOV_SP (0, num_regs_to_save);
1013           /* We're going to use ret to release the FP registers
1014                  save area, so, no savings.  */
1015
1016           if (this_strategy_size < strategy_size)
1017             {
1018               strategy = restore_sp_pre_adjust;
1019               strategy_size = this_strategy_size;
1020             }
1021
1022           /* Consider using sp offsets after partially adjusting sp.
1023              When size is close to 32Kb, we may be able to adjust SP
1024              with an imm16 add instruction while still using fmov
1025              (d8,sp).  */
1026           if (size + 4 * num_regs_to_save + REG_SAVE_BYTES > 255)
1027             {
1028               /* Insn: add size + 4 * num_regs_to_save
1029                                 + REG_SAVE_BYTES - 252,sp.  */
1030               this_strategy_size = SIZE_ADD_SP (size + 4 * num_regs_to_save
1031                                                 + REG_SAVE_BYTES - 252);
1032               /* Insn: fmov (##,sp),fs#, fo each fs# to be restored.  */
1033               this_strategy_size += SIZE_FMOV_SP (252 - REG_SAVE_BYTES
1034                                                   - 4 * num_regs_to_save,
1035                                                   num_regs_to_save);
1036               /* We're going to use ret to release the FP registers
1037                  save area, so, no savings.  */
1038
1039               if (this_strategy_size < strategy_size)
1040                 {
1041                   strategy = restore_sp_partial_adjust;
1042                   strategy_size = this_strategy_size;
1043                 }
1044             }
1045
1046           /* Consider using a1 in post-increment mode, as long as the
1047              user hasn't changed the calling conventions of a1.  */
1048           if (call_used_regs[FIRST_ADDRESS_REGNUM+1]
1049               && ! fixed_regs[FIRST_ADDRESS_REGNUM+1])
1050             {
1051               /* Insn: mov sp,a1.  */
1052               this_strategy_size = 1;
1053               if (size)
1054                 {
1055                   /* Insn: add size,a1.  */
1056                   this_strategy_size += SIZE_ADD_AX (size);
1057                 }
1058               /* Insn: fmov (a1+),fs#, for each fs# to be restored.  */
1059               this_strategy_size += 3 * num_regs_to_save;
1060               /* If size is large enough, we may be able to save a
1061                  couple of bytes.  */
1062               if (size + 4 * num_regs_to_save + REG_SAVE_BYTES > 255)
1063                 {
1064                   /* Insn: mov a1,sp.  */
1065                   this_strategy_size += 2;
1066                 }
1067               /* If we don't have to restore any non-FP registers,
1068                  we'll be able to save one byte by using rets.  */
1069               if (! REG_SAVE_BYTES)
1070                 this_strategy_size--;
1071
1072               if (this_strategy_size < strategy_size)
1073                 {
1074                   strategy = restore_a1;
1075                   strategy_size = this_strategy_size;
1076                 }
1077             }
1078
1079           switch (strategy)
1080             {
1081             case restore_sp_post_adjust:
1082               break;
1083
1084             case restore_sp_pre_adjust:
1085               emit_insn (gen_addsi3 (stack_pointer_rtx,
1086                                      stack_pointer_rtx,
1087                                      GEN_INT (size)));
1088               size = 0;
1089               break;
1090
1091             case restore_sp_partial_adjust:
1092               emit_insn (gen_addsi3 (stack_pointer_rtx,
1093                                      stack_pointer_rtx,
1094                                      GEN_INT (size + 4 * num_regs_to_save
1095                                               + REG_SAVE_BYTES - 252)));
1096               size = 252 - REG_SAVE_BYTES - 4 * num_regs_to_save;
1097               break;
1098
1099             case restore_a1:
1100               reg = gen_rtx_REG (SImode, FIRST_ADDRESS_REGNUM + 1);
1101               emit_insn (gen_movsi (reg, stack_pointer_rtx));
1102               if (size)
1103                 emit_insn (gen_addsi3 (reg, reg, GEN_INT (size)));
1104               break;
1105
1106             default:
1107               gcc_unreachable ();
1108             }
1109         }
1110
1111       /* Adjust the selected register, if any, for post-increment.  */
1112       if (reg)
1113         reg = gen_rtx_POST_INC (SImode, reg);
1114
1115       for (i = FIRST_FP_REGNUM; i <= LAST_FP_REGNUM; ++i)
1116         if (df_regs_ever_live_p (i) && ! call_used_regs[i])
1117           {
1118             rtx addr;
1119
1120             if (reg)
1121               addr = reg;
1122             else if (size)
1123               {
1124                 /* If we aren't using a post-increment register, use an
1125                    SP offset.  */
1126                 addr = gen_rtx_PLUS (SImode,
1127                                      stack_pointer_rtx,
1128                                      GEN_INT (size));
1129               }
1130             else
1131               addr = stack_pointer_rtx;
1132
1133             size += 4;
1134
1135             emit_insn (gen_movsi (gen_rtx_REG (SImode, i),
1136                                   gen_rtx_MEM (SImode, addr)));
1137           }
1138
1139       /* If we were using the restore_a1 strategy and the number of
1140          bytes to be released won't fit in the `ret' byte, copy `a1'
1141          to `sp', to avoid having to use `add' to adjust it.  */
1142       if (! frame_pointer_needed && reg && size + REG_SAVE_BYTES > 255)
1143         {
1144           emit_move_insn (stack_pointer_rtx, XEXP (reg, 0));
1145           size = 0;
1146         }
1147     }
1148
1149   /* Maybe cut back the stack, except for the register save area.
1150
1151      If the frame pointer exists, then use the frame pointer to
1152      cut back the stack.
1153
1154      If the stack size + register save area is more than 255 bytes,
1155      then the stack must be cut back here since the size + register
1156      save size is too big for a ret/retf instruction.
1157
1158      Else leave it alone, it will be cut back as part of the
1159      ret/retf instruction, or there wasn't any stack to begin with.
1160
1161      Under no circumstances should the register save area be
1162      deallocated here, that would leave a window where an interrupt
1163      could occur and trash the register save area.  */
1164   if (frame_pointer_needed)
1165     {
1166       emit_move_insn (stack_pointer_rtx, frame_pointer_rtx);
1167       size = 0;
1168     }
1169   else if (size + REG_SAVE_BYTES > 255)
1170     {
1171       emit_insn (gen_addsi3 (stack_pointer_rtx,
1172                              stack_pointer_rtx,
1173                              GEN_INT (size)));
1174       size = 0;
1175     }
1176
1177   /* Adjust the stack and restore callee-saved registers, if any.  */
1178   if (size || df_regs_ever_live_p (2) || df_regs_ever_live_p (3)
1179       || df_regs_ever_live_p (6) || df_regs_ever_live_p (7)
1180       || df_regs_ever_live_p (14) || df_regs_ever_live_p (15)
1181       || df_regs_ever_live_p (16) || df_regs_ever_live_p (17)
1182       || frame_pointer_needed)
1183     emit_jump_insn (gen_return_internal_regs
1184                     (GEN_INT (size + REG_SAVE_BYTES)));
1185   else
1186     emit_jump_insn (gen_return_internal ());
1187 }
1188
1189 /* Update the condition code from the insn.  */
1190
1191 void
1192 notice_update_cc (rtx body, rtx insn)
1193 {
1194   switch (get_attr_cc (insn))
1195     {
1196     case CC_NONE:
1197       /* Insn does not affect CC at all.  */
1198       break;
1199
1200     case CC_NONE_0HIT:
1201       /* Insn does not change CC, but the 0'th operand has been changed.  */
1202       if (cc_status.value1 != 0
1203           && reg_overlap_mentioned_p (recog_data.operand[0], cc_status.value1))
1204         cc_status.value1 = 0;
1205       break;
1206
1207     case CC_SET_ZN:
1208       /* Insn sets the Z,N flags of CC to recog_data.operand[0].
1209          V,C are unusable.  */
1210       CC_STATUS_INIT;
1211       cc_status.flags |= CC_NO_CARRY | CC_OVERFLOW_UNUSABLE;
1212       cc_status.value1 = recog_data.operand[0];
1213       break;
1214
1215     case CC_SET_ZNV:
1216       /* Insn sets the Z,N,V flags of CC to recog_data.operand[0].
1217          C is unusable.  */
1218       CC_STATUS_INIT;
1219       cc_status.flags |= CC_NO_CARRY;
1220       cc_status.value1 = recog_data.operand[0];
1221       break;
1222
1223     case CC_COMPARE:
1224       /* The insn is a compare instruction.  */
1225       CC_STATUS_INIT;
1226       cc_status.value1 = SET_SRC (body);
1227       if (GET_CODE (cc_status.value1) == COMPARE
1228           && GET_MODE (XEXP (cc_status.value1, 0)) == SFmode)
1229         cc_status.mdep.fpCC = 1;
1230       break;
1231
1232     case CC_CLOBBER:
1233       /* Insn doesn't leave CC in a usable state.  */
1234       CC_STATUS_INIT;
1235       break;
1236
1237     default:
1238       gcc_unreachable ();
1239     }
1240 }
1241
1242 /* Recognize the PARALLEL rtx generated by mn10300_gen_multiple_store().
1243    This function is for MATCH_PARALLEL and so assumes OP is known to be
1244    parallel.  If OP is a multiple store, return a mask indicating which
1245    registers it saves.  Return 0 otherwise.  */
1246
1247 int
1248 store_multiple_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1249 {
1250   int count;
1251   int mask;
1252   int i;
1253   unsigned int last;
1254   rtx elt;
1255
1256   count = XVECLEN (op, 0);
1257   if (count < 2)
1258     return 0;
1259
1260   /* Check that first instruction has the form (set (sp) (plus A B)) */
1261   elt = XVECEXP (op, 0, 0);
1262   if (GET_CODE (elt) != SET
1263       || GET_CODE (SET_DEST (elt)) != REG
1264       || REGNO (SET_DEST (elt)) != STACK_POINTER_REGNUM
1265       || GET_CODE (SET_SRC (elt)) != PLUS)
1266     return 0;
1267
1268   /* Check that A is the stack pointer and B is the expected stack size.
1269      For OP to match, each subsequent instruction should push a word onto
1270      the stack.  We therefore expect the first instruction to create
1271      COUNT-1 stack slots.  */
1272   elt = SET_SRC (elt);
1273   if (GET_CODE (XEXP (elt, 0)) != REG
1274       || REGNO (XEXP (elt, 0)) != STACK_POINTER_REGNUM
1275       || GET_CODE (XEXP (elt, 1)) != CONST_INT
1276       || INTVAL (XEXP (elt, 1)) != -(count - 1) * 4)
1277     return 0;
1278
1279   /* Now go through the rest of the vector elements.  They must be
1280      ordered so that the first instruction stores the highest-numbered
1281      register to the highest stack slot and that subsequent instructions
1282      store a lower-numbered register to the slot below.
1283
1284      LAST keeps track of the smallest-numbered register stored so far.
1285      MASK is the set of stored registers.  */
1286   last = LAST_EXTENDED_REGNUM + 1;
1287   mask = 0;
1288   for (i = 1; i < count; i++)
1289     {
1290       /* Check that element i is a (set (mem M) R) and that R is valid.  */
1291       elt = XVECEXP (op, 0, i);
1292       if (GET_CODE (elt) != SET
1293           || GET_CODE (SET_DEST (elt)) != MEM
1294           || GET_CODE (SET_SRC (elt)) != REG
1295           || REGNO (SET_SRC (elt)) >= last)
1296         return 0;
1297
1298       /* R was OK, so provisionally add it to MASK.  We return 0 in any
1299          case if the rest of the instruction has a flaw.  */
1300       last = REGNO (SET_SRC (elt));
1301       mask |= (1 << last);
1302
1303       /* Check that M has the form (plus (sp) (const_int -I*4)) */
1304       elt = XEXP (SET_DEST (elt), 0);
1305       if (GET_CODE (elt) != PLUS
1306           || GET_CODE (XEXP (elt, 0)) != REG
1307           || REGNO (XEXP (elt, 0)) != STACK_POINTER_REGNUM
1308           || GET_CODE (XEXP (elt, 1)) != CONST_INT
1309           || INTVAL (XEXP (elt, 1)) != -i * 4)
1310         return 0;
1311     }
1312
1313   /* All or none of the callee-saved extended registers must be in the set.  */
1314   if ((mask & 0x3c000) != 0
1315       && (mask & 0x3c000) != 0x3c000)
1316     return 0;
1317
1318   return mask;
1319 }
1320
1321 /* What (if any) secondary registers are needed to move IN with mode
1322    MODE into a register in register class CLASS.
1323
1324    We might be able to simplify this.  */
1325 enum reg_class
1326 mn10300_secondary_reload_class (enum reg_class class, enum machine_mode mode,
1327                                 rtx in)
1328 {
1329   /* Memory loads less than a full word wide can't have an
1330      address or stack pointer destination.  They must use
1331      a data register as an intermediate register.  */
1332   if ((GET_CODE (in) == MEM
1333        || (GET_CODE (in) == REG
1334            && REGNO (in) >= FIRST_PSEUDO_REGISTER)
1335        || (GET_CODE (in) == SUBREG
1336            && GET_CODE (SUBREG_REG (in)) == REG
1337            && REGNO (SUBREG_REG (in)) >= FIRST_PSEUDO_REGISTER))
1338       && (mode == QImode || mode == HImode)
1339       && (class == ADDRESS_REGS || class == SP_REGS
1340           || class == SP_OR_ADDRESS_REGS))
1341     {
1342       if (TARGET_AM33)
1343         return DATA_OR_EXTENDED_REGS;
1344       return DATA_REGS;
1345     }
1346
1347   /* We can't directly load sp + const_int into a data register;
1348      we must use an address register as an intermediate.  */
1349   if (class != SP_REGS
1350       && class != ADDRESS_REGS
1351       && class != SP_OR_ADDRESS_REGS
1352       && class != SP_OR_EXTENDED_REGS
1353       && class != ADDRESS_OR_EXTENDED_REGS
1354       && class != SP_OR_ADDRESS_OR_EXTENDED_REGS
1355       && (in == stack_pointer_rtx
1356           || (GET_CODE (in) == PLUS
1357               && (XEXP (in, 0) == stack_pointer_rtx
1358                   || XEXP (in, 1) == stack_pointer_rtx))))
1359     return ADDRESS_REGS;
1360
1361   if (GET_CODE (in) == PLUS
1362       && (XEXP (in, 0) == stack_pointer_rtx
1363           || XEXP (in, 1) == stack_pointer_rtx))
1364     {
1365       if (TARGET_AM33)
1366         return DATA_OR_EXTENDED_REGS;
1367       return DATA_REGS;
1368     }
1369
1370   if (TARGET_AM33_2 && class == FP_REGS
1371       && GET_CODE (in) == MEM
1372       && ! (GET_CODE (in) == MEM && !CONSTANT_ADDRESS_P (XEXP (in, 0))))
1373     {
1374       if (TARGET_AM33)
1375         return DATA_OR_EXTENDED_REGS;
1376       return DATA_REGS;
1377     }
1378
1379   /* Otherwise assume no secondary reloads are needed.  */
1380   return NO_REGS;
1381 }
1382
1383 int
1384 initial_offset (int from, int to)
1385 {
1386   /* The difference between the argument pointer and the frame pointer
1387      is the size of the callee register save area.  */
1388   if (from == ARG_POINTER_REGNUM && to == FRAME_POINTER_REGNUM)
1389     {
1390       if (df_regs_ever_live_p (2) || df_regs_ever_live_p (3)
1391           || df_regs_ever_live_p (6) || df_regs_ever_live_p (7)
1392           || df_regs_ever_live_p (14) || df_regs_ever_live_p (15)
1393           || df_regs_ever_live_p (16) || df_regs_ever_live_p (17)
1394           || fp_regs_to_save ()
1395           || frame_pointer_needed)
1396         return REG_SAVE_BYTES
1397           + 4 * fp_regs_to_save ();
1398       else
1399         return 0;
1400     }
1401
1402   /* The difference between the argument pointer and the stack pointer is
1403      the sum of the size of this function's frame, the callee register save
1404      area, and the fixed stack space needed for function calls (if any).  */
1405   if (from == ARG_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
1406     {
1407       if (df_regs_ever_live_p (2) || df_regs_ever_live_p (3)
1408           || df_regs_ever_live_p (6) || df_regs_ever_live_p (7)
1409           || df_regs_ever_live_p (14) || df_regs_ever_live_p (15)
1410           || df_regs_ever_live_p (16) || df_regs_ever_live_p (17)
1411           || fp_regs_to_save ()
1412           || frame_pointer_needed)
1413         return (get_frame_size () + REG_SAVE_BYTES
1414                 + 4 * fp_regs_to_save ()
1415                 + (current_function_outgoing_args_size
1416                    ? current_function_outgoing_args_size + 4 : 0));
1417       else
1418         return (get_frame_size ()
1419                 + (current_function_outgoing_args_size
1420                    ? current_function_outgoing_args_size + 4 : 0));
1421     }
1422
1423   /* The difference between the frame pointer and stack pointer is the sum
1424      of the size of this function's frame and the fixed stack space needed
1425      for function calls (if any).  */
1426   if (from == FRAME_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
1427     return (get_frame_size ()
1428             + (current_function_outgoing_args_size
1429                ? current_function_outgoing_args_size + 4 : 0));
1430
1431   gcc_unreachable ();
1432 }
1433
1434 /* Worker function for TARGET_RETURN_IN_MEMORY.  */
1435
1436 static bool
1437 mn10300_return_in_memory (const_tree type, const_tree fntype ATTRIBUTE_UNUSED)
1438 {
1439   /* Return values > 8 bytes in length in memory.  */
1440   return (int_size_in_bytes (type) > 8
1441           || int_size_in_bytes (type) == 0
1442           || TYPE_MODE (type) == BLKmode);
1443 }
1444
1445 /* Flush the argument registers to the stack for a stdarg function;
1446    return the new argument pointer.  */
1447 static rtx
1448 mn10300_builtin_saveregs (void)
1449 {
1450   rtx offset, mem;
1451   tree fntype = TREE_TYPE (current_function_decl);
1452   int argadj = ((!(TYPE_ARG_TYPES (fntype) != 0
1453                    && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
1454                        != void_type_node)))
1455                 ? UNITS_PER_WORD : 0);
1456   alias_set_type set = get_varargs_alias_set ();
1457
1458   if (argadj)
1459     offset = plus_constant (current_function_arg_offset_rtx, argadj);
1460   else
1461     offset = current_function_arg_offset_rtx;
1462
1463   mem = gen_rtx_MEM (SImode, current_function_internal_arg_pointer);
1464   set_mem_alias_set (mem, set);
1465   emit_move_insn (mem, gen_rtx_REG (SImode, 0));
1466
1467   mem = gen_rtx_MEM (SImode,
1468                      plus_constant (current_function_internal_arg_pointer, 4));
1469   set_mem_alias_set (mem, set);
1470   emit_move_insn (mem, gen_rtx_REG (SImode, 1));
1471
1472   return copy_to_reg (expand_binop (Pmode, add_optab,
1473                                     current_function_internal_arg_pointer,
1474                                     offset, 0, 0, OPTAB_LIB_WIDEN));
1475 }
1476
1477 static void
1478 mn10300_va_start (tree valist, rtx nextarg)
1479 {
1480   nextarg = expand_builtin_saveregs ();
1481   std_expand_builtin_va_start (valist, nextarg);
1482 }
1483
1484 /* Return true when a parameter should be passed by reference.  */
1485
1486 static bool
1487 mn10300_pass_by_reference (CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED,
1488                            enum machine_mode mode, const_tree type,
1489                            bool named ATTRIBUTE_UNUSED)
1490 {
1491   unsigned HOST_WIDE_INT size;
1492
1493   if (type)
1494     size = int_size_in_bytes (type);
1495   else
1496     size = GET_MODE_SIZE (mode);
1497
1498   return (size > 8 || size == 0);
1499 }
1500
1501 /* Return an RTX to represent where a value with mode MODE will be returned
1502    from a function.  If the result is 0, the argument is pushed.  */
1503
1504 rtx
1505 function_arg (CUMULATIVE_ARGS *cum, enum machine_mode mode,
1506               tree type, int named ATTRIBUTE_UNUSED)
1507 {
1508   rtx result = 0;
1509   int size, align;
1510
1511   /* We only support using 2 data registers as argument registers.  */
1512   int nregs = 2;
1513
1514   /* Figure out the size of the object to be passed.  */
1515   if (mode == BLKmode)
1516     size = int_size_in_bytes (type);
1517   else
1518     size = GET_MODE_SIZE (mode);
1519
1520   /* Figure out the alignment of the object to be passed.  */
1521   align = size;
1522
1523   cum->nbytes = (cum->nbytes + 3) & ~3;
1524
1525   /* Don't pass this arg via a register if all the argument registers
1526      are used up.  */
1527   if (cum->nbytes > nregs * UNITS_PER_WORD)
1528     return 0;
1529
1530   /* Don't pass this arg via a register if it would be split between
1531      registers and memory.  */
1532   if (type == NULL_TREE
1533       && cum->nbytes + size > nregs * UNITS_PER_WORD)
1534     return 0;
1535
1536   switch (cum->nbytes / UNITS_PER_WORD)
1537     {
1538     case 0:
1539       result = gen_rtx_REG (mode, 0);
1540       break;
1541     case 1:
1542       result = gen_rtx_REG (mode, 1);
1543       break;
1544     default:
1545       result = 0;
1546     }
1547
1548   return result;
1549 }
1550
1551 /* Return the number of bytes of registers to use for an argument passed
1552    partially in registers and partially in memory.  */
1553
1554 static int
1555 mn10300_arg_partial_bytes (CUMULATIVE_ARGS *cum, enum machine_mode mode,
1556                            tree type, bool named ATTRIBUTE_UNUSED)
1557 {
1558   int size, align;
1559
1560   /* We only support using 2 data registers as argument registers.  */
1561   int nregs = 2;
1562
1563   /* Figure out the size of the object to be passed.  */
1564   if (mode == BLKmode)
1565     size = int_size_in_bytes (type);
1566   else
1567     size = GET_MODE_SIZE (mode);
1568
1569   /* Figure out the alignment of the object to be passed.  */
1570   align = size;
1571
1572   cum->nbytes = (cum->nbytes + 3) & ~3;
1573
1574   /* Don't pass this arg via a register if all the argument registers
1575      are used up.  */
1576   if (cum->nbytes > nregs * UNITS_PER_WORD)
1577     return 0;
1578
1579   if (cum->nbytes + size <= nregs * UNITS_PER_WORD)
1580     return 0;
1581
1582   /* Don't pass this arg via a register if it would be split between
1583      registers and memory.  */
1584   if (type == NULL_TREE
1585       && cum->nbytes + size > nregs * UNITS_PER_WORD)
1586     return 0;
1587
1588   return nregs * UNITS_PER_WORD - cum->nbytes;
1589 }
1590
1591 /* Return the location of the function's value.  This will be either
1592    $d0 for integer functions, $a0 for pointers, or a PARALLEL of both
1593    $d0 and $a0 if the -mreturn-pointer-on-do flag is set.  Note that
1594    we only return the PARALLEL for outgoing values; we do not want
1595    callers relying on this extra copy.  */
1596
1597 rtx
1598 mn10300_function_value (const_tree valtype, const_tree func, int outgoing)
1599 {
1600   rtx rv;
1601   enum machine_mode mode = TYPE_MODE (valtype);
1602
1603   if (! POINTER_TYPE_P (valtype))
1604     return gen_rtx_REG (mode, FIRST_DATA_REGNUM);
1605   else if (! TARGET_PTR_A0D0 || ! outgoing
1606            || current_function_returns_struct)
1607     return gen_rtx_REG (mode, FIRST_ADDRESS_REGNUM);
1608
1609   rv = gen_rtx_PARALLEL (mode, rtvec_alloc (2));
1610   XVECEXP (rv, 0, 0)
1611     = gen_rtx_EXPR_LIST (VOIDmode,
1612                          gen_rtx_REG (mode, FIRST_ADDRESS_REGNUM),
1613                          GEN_INT (0));
1614
1615   XVECEXP (rv, 0, 1)
1616     = gen_rtx_EXPR_LIST (VOIDmode,
1617                          gen_rtx_REG (mode, FIRST_DATA_REGNUM),
1618                          GEN_INT (0));
1619   return rv;
1620 }
1621
1622 /* Output a tst insn.  */
1623 const char *
1624 output_tst (rtx operand, rtx insn)
1625 {
1626   rtx temp;
1627   int past_call = 0;
1628
1629   /* We can save a byte if we can find a register which has the value
1630      zero in it.  */
1631   temp = PREV_INSN (insn);
1632   while (optimize && temp)
1633     {
1634       rtx set;
1635
1636       /* We allow the search to go through call insns.  We record
1637          the fact that we've past a CALL_INSN and reject matches which
1638          use call clobbered registers.  */
1639       if (GET_CODE (temp) == CODE_LABEL
1640           || GET_CODE (temp) == JUMP_INSN
1641           || GET_CODE (temp) == BARRIER)
1642         break;
1643
1644       if (GET_CODE (temp) == CALL_INSN)
1645         past_call = 1;
1646
1647       if (GET_CODE (temp) == NOTE)
1648         {
1649           temp = PREV_INSN (temp);
1650           continue;
1651         }
1652
1653       /* It must be an insn, see if it is a simple set.  */
1654       set = single_set (temp);
1655       if (!set)
1656         {
1657           temp = PREV_INSN (temp);
1658           continue;
1659         }
1660
1661       /* Are we setting a data register to zero (this does not win for
1662          address registers)?
1663
1664          If it's a call clobbered register, have we past a call?
1665
1666          Make sure the register we find isn't the same as ourself;
1667          the mn10300 can't encode that.
1668
1669          ??? reg_set_between_p return nonzero anytime we pass a CALL_INSN
1670          so the code to detect calls here isn't doing anything useful.  */
1671       if (REG_P (SET_DEST (set))
1672           && SET_SRC (set) == CONST0_RTX (GET_MODE (SET_DEST (set)))
1673           && !reg_set_between_p (SET_DEST (set), temp, insn)
1674           && (REGNO_REG_CLASS (REGNO (SET_DEST (set)))
1675               == REGNO_REG_CLASS (REGNO (operand)))
1676           && REGNO_REG_CLASS (REGNO (SET_DEST (set))) != EXTENDED_REGS
1677           && REGNO (SET_DEST (set)) != REGNO (operand)
1678           && (!past_call
1679               || !call_used_regs[REGNO (SET_DEST (set))]))
1680         {
1681           rtx xoperands[2];
1682           xoperands[0] = operand;
1683           xoperands[1] = SET_DEST (set);
1684
1685           output_asm_insn ("cmp %1,%0", xoperands);
1686           return "";
1687         }
1688
1689       if (REGNO_REG_CLASS (REGNO (operand)) == EXTENDED_REGS
1690           && REG_P (SET_DEST (set))
1691           && SET_SRC (set) == CONST0_RTX (GET_MODE (SET_DEST (set)))
1692           && !reg_set_between_p (SET_DEST (set), temp, insn)
1693           && (REGNO_REG_CLASS (REGNO (SET_DEST (set)))
1694               != REGNO_REG_CLASS (REGNO (operand)))
1695           && REGNO_REG_CLASS (REGNO (SET_DEST (set))) == EXTENDED_REGS
1696           && REGNO (SET_DEST (set)) != REGNO (operand)
1697           && (!past_call
1698               || !call_used_regs[REGNO (SET_DEST (set))]))
1699         {
1700           rtx xoperands[2];
1701           xoperands[0] = operand;
1702           xoperands[1] = SET_DEST (set);
1703
1704           output_asm_insn ("cmp %1,%0", xoperands);
1705           return "";
1706         }
1707       temp = PREV_INSN (temp);
1708     }
1709   return "cmp 0,%0";
1710 }
1711
1712 int
1713 impossible_plus_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1714 {
1715   if (GET_CODE (op) != PLUS)
1716     return 0;
1717
1718   if (XEXP (op, 0) == stack_pointer_rtx
1719       || XEXP (op, 1) == stack_pointer_rtx)
1720     return 1;
1721
1722   return 0;
1723 }
1724
1725 /* Similarly, but when using a zero_extract pattern for a btst where
1726    the source operand might end up in memory.  */
1727 int
1728 mask_ok_for_mem_btst (int len, int bit)
1729 {
1730   unsigned int mask = 0;
1731
1732   while (len > 0)
1733     {
1734       mask |= (1 << bit);
1735       bit++;
1736       len--;
1737     }
1738
1739   /* MASK must bit into an 8bit value.  */
1740   return (((mask & 0xff) == mask)
1741           || ((mask & 0xff00) == mask)
1742           || ((mask & 0xff0000) == mask)
1743           || ((mask & 0xff000000) == mask));
1744 }
1745
1746 /* Return 1 if X contains a symbolic expression.  We know these
1747    expressions will have one of a few well defined forms, so
1748    we need only check those forms.  */
1749 int
1750 symbolic_operand (register rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1751 {
1752   switch (GET_CODE (op))
1753     {
1754     case SYMBOL_REF:
1755     case LABEL_REF:
1756       return 1;
1757     case CONST:
1758       op = XEXP (op, 0);
1759       return ((GET_CODE (XEXP (op, 0)) == SYMBOL_REF
1760                || GET_CODE (XEXP (op, 0)) == LABEL_REF)
1761               && GET_CODE (XEXP (op, 1)) == CONST_INT);
1762     default:
1763       return 0;
1764     }
1765 }
1766
1767 /* Try machine dependent ways of modifying an illegitimate address
1768    to be legitimate.  If we find one, return the new valid address.
1769    This macro is used in only one place: `memory_address' in explow.c.
1770
1771    OLDX is the address as it was before break_out_memory_refs was called.
1772    In some cases it is useful to look at this to decide what needs to be done.
1773
1774    MODE and WIN are passed so that this macro can use
1775    GO_IF_LEGITIMATE_ADDRESS.
1776
1777    Normally it is always safe for this macro to do nothing.  It exists to
1778    recognize opportunities to optimize the output.
1779
1780    But on a few ports with segmented architectures and indexed addressing
1781    (mn10300, hppa) it is used to rewrite certain problematical addresses.  */
1782 rtx
1783 legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED,
1784                     enum machine_mode mode ATTRIBUTE_UNUSED)
1785 {
1786   if (flag_pic && ! legitimate_pic_operand_p (x))
1787     x = legitimize_pic_address (oldx, NULL_RTX);
1788
1789   /* Uh-oh.  We might have an address for x[n-100000].  This needs
1790      special handling to avoid creating an indexed memory address
1791      with x-100000 as the base.  */
1792   if (GET_CODE (x) == PLUS
1793       && symbolic_operand (XEXP (x, 1), VOIDmode))
1794     {
1795       /* Ugly.  We modify things here so that the address offset specified
1796          by the index expression is computed first, then added to x to form
1797          the entire address.  */
1798
1799       rtx regx1, regy1, regy2, y;
1800
1801       /* Strip off any CONST.  */
1802       y = XEXP (x, 1);
1803       if (GET_CODE (y) == CONST)
1804         y = XEXP (y, 0);
1805
1806       if (GET_CODE (y) == PLUS || GET_CODE (y) == MINUS)
1807         {
1808           regx1 = force_reg (Pmode, force_operand (XEXP (x, 0), 0));
1809           regy1 = force_reg (Pmode, force_operand (XEXP (y, 0), 0));
1810           regy2 = force_reg (Pmode, force_operand (XEXP (y, 1), 0));
1811           regx1 = force_reg (Pmode,
1812                              gen_rtx_fmt_ee (GET_CODE (y), Pmode, regx1, regy2));
1813           return force_reg (Pmode, gen_rtx_PLUS (Pmode, regx1, regy1));
1814         }
1815     }
1816   return x;
1817 }
1818
1819 /* Convert a non-PIC address in `orig' to a PIC address using @GOT or
1820    @GOTOFF in `reg'.  */
1821 rtx
1822 legitimize_pic_address (rtx orig, rtx reg)
1823 {
1824   if (GET_CODE (orig) == LABEL_REF
1825       || (GET_CODE (orig) == SYMBOL_REF
1826           && (CONSTANT_POOL_ADDRESS_P (orig)
1827               || ! MN10300_GLOBAL_P (orig))))
1828     {
1829       if (reg == 0)
1830         reg = gen_reg_rtx (Pmode);
1831
1832       emit_insn (gen_symGOTOFF2reg (reg, orig));
1833       return reg;
1834     }
1835   else if (GET_CODE (orig) == SYMBOL_REF)
1836     {
1837       if (reg == 0)
1838         reg = gen_reg_rtx (Pmode);
1839
1840       emit_insn (gen_symGOT2reg (reg, orig));
1841       return reg;
1842     }
1843   return orig;
1844 }
1845
1846 /* Return zero if X references a SYMBOL_REF or LABEL_REF whose symbol
1847    isn't protected by a PIC unspec; nonzero otherwise.  */
1848 int
1849 legitimate_pic_operand_p (rtx x)
1850 {
1851   register const char *fmt;
1852   register int i;
1853
1854   if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == LABEL_REF)
1855     return 0;
1856
1857   if (GET_CODE (x) == UNSPEC
1858       && (XINT (x, 1) == UNSPEC_PIC
1859           || XINT (x, 1) == UNSPEC_GOT
1860           || XINT (x, 1) == UNSPEC_GOTOFF
1861           || XINT (x, 1) == UNSPEC_PLT))
1862       return 1;
1863
1864   fmt = GET_RTX_FORMAT (GET_CODE (x));
1865   for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
1866     {
1867       if (fmt[i] == 'E')
1868         {
1869           register int j;
1870
1871           for (j = XVECLEN (x, i) - 1; j >= 0; j--)
1872             if (! legitimate_pic_operand_p (XVECEXP (x, i, j)))
1873               return 0;
1874         }
1875       else if (fmt[i] == 'e' && ! legitimate_pic_operand_p (XEXP (x, i)))
1876         return 0;
1877     }
1878
1879   return 1;
1880 }
1881
1882 /* Return TRUE if the address X, taken from a (MEM:MODE X) rtx, is
1883    legitimate, and FALSE otherwise.  */
1884 bool
1885 legitimate_address_p (enum machine_mode mode, rtx x, int strict)
1886 {
1887   if (CONSTANT_ADDRESS_P (x)
1888       && (! flag_pic || legitimate_pic_operand_p (x)))
1889     return TRUE;
1890
1891   if (RTX_OK_FOR_BASE_P (x, strict))
1892     return TRUE;
1893
1894   if (TARGET_AM33
1895       && GET_CODE (x) == POST_INC
1896       && RTX_OK_FOR_BASE_P (XEXP (x, 0), strict)
1897       && (mode == SImode || mode == SFmode || mode == HImode))
1898     return TRUE;
1899
1900   if (GET_CODE (x) == PLUS)
1901     {
1902       rtx base = 0, index = 0;
1903
1904       if (REG_P (XEXP (x, 0))
1905           && REGNO_STRICT_OK_FOR_BASE_P (REGNO (XEXP (x, 0)), strict))
1906         {
1907           base = XEXP (x, 0);
1908           index = XEXP (x, 1);
1909         }
1910
1911       if (REG_P (XEXP (x, 1))
1912           && REGNO_STRICT_OK_FOR_BASE_P (REGNO (XEXP (x, 1)), strict))
1913         {
1914           base = XEXP (x, 1);
1915           index = XEXP (x, 0);
1916         }
1917
1918       if (base != 0 && index != 0)
1919         {
1920           if (GET_CODE (index) == CONST_INT)
1921             return TRUE;
1922           if (GET_CODE (index) == CONST
1923               && GET_CODE (XEXP (index, 0)) != PLUS
1924               && (! flag_pic
1925                   || legitimate_pic_operand_p (index)))
1926             return TRUE;
1927         }
1928     }
1929
1930   return FALSE;
1931 }
1932
1933 static int
1934 mn10300_address_cost_1 (rtx x, int *unsig)
1935 {
1936   switch (GET_CODE (x))
1937     {
1938     case REG:
1939       switch (REGNO_REG_CLASS (REGNO (x)))
1940         {
1941         case SP_REGS:
1942           *unsig = 1;
1943           return 0;
1944
1945         case ADDRESS_REGS:
1946           return 1;
1947
1948         case DATA_REGS:
1949         case EXTENDED_REGS:
1950         case FP_REGS:
1951           return 3;
1952
1953         case NO_REGS:
1954           return 5;
1955
1956         default:
1957           gcc_unreachable ();
1958         }
1959
1960     case PLUS:
1961     case MINUS:
1962     case ASHIFT:
1963     case AND:
1964     case IOR:
1965       return (mn10300_address_cost_1 (XEXP (x, 0), unsig)
1966               + mn10300_address_cost_1 (XEXP (x, 1), unsig));
1967
1968     case EXPR_LIST:
1969     case SUBREG:
1970     case MEM:
1971       return mn10300_address_cost (XEXP (x, 0));
1972
1973     case ZERO_EXTEND:
1974       *unsig = 1;
1975       return mn10300_address_cost_1 (XEXP (x, 0), unsig);
1976
1977     case CONST_INT:
1978       if (INTVAL (x) == 0)
1979         return 0;
1980       if (INTVAL (x) + (*unsig ? 0 : 0x80) < 0x100)
1981         return 1;
1982       if (INTVAL (x) + (*unsig ? 0 : 0x8000) < 0x10000)
1983         return 3;
1984       if (INTVAL (x) + (*unsig ? 0 : 0x800000) < 0x1000000)
1985         return 5;
1986       return 7;
1987
1988     case CONST:
1989     case SYMBOL_REF:
1990     case LABEL_REF:
1991       return 8;
1992
1993     default:
1994       gcc_unreachable ();
1995
1996     }
1997 }
1998
1999 static int
2000 mn10300_address_cost (rtx x)
2001 {
2002   int s = 0;
2003   return mn10300_address_cost_1 (x, &s);
2004 }
2005
2006 static bool
2007 mn10300_rtx_costs (rtx x, int code, int outer_code, int *total)
2008 {
2009   switch (code)
2010     {
2011     case CONST_INT:
2012       /* Zeros are extremely cheap.  */
2013       if (INTVAL (x) == 0 && outer_code == SET)
2014         *total = 0;
2015       /* If it fits in 8 bits, then it's still relatively cheap.  */
2016       else if (INT_8_BITS (INTVAL (x)))
2017         *total = 1;
2018       /* This is the "base" cost, includes constants where either the
2019          upper or lower 16bits are all zeros.  */
2020       else if (INT_16_BITS (INTVAL (x))
2021                || (INTVAL (x) & 0xffff) == 0
2022                || (INTVAL (x) & 0xffff0000) == 0)
2023         *total = 2;
2024       else
2025         *total = 4;
2026       return true;
2027
2028     case CONST:
2029     case LABEL_REF:
2030     case SYMBOL_REF:
2031       /* These are more costly than a CONST_INT, but we can relax them,
2032          so they're less costly than a CONST_DOUBLE.  */
2033       *total = 6;
2034       return true;
2035
2036     case CONST_DOUBLE:
2037       /* We don't optimize CONST_DOUBLEs well nor do we relax them well,
2038          so their cost is very high.  */
2039       *total = 8;
2040       return true;
2041
2042    /* ??? This probably needs more work.  */
2043     case MOD:
2044     case DIV:
2045     case MULT:
2046       *total = 8;
2047       return true;
2048
2049     default:
2050       return false;
2051     }
2052 }
2053
2054 /* Check whether a constant used to initialize a DImode or DFmode can
2055    use a clr instruction.  The code here must be kept in sync with
2056    movdf and movdi.  */
2057
2058 bool
2059 mn10300_wide_const_load_uses_clr (rtx operands[2])
2060 {
2061   long val[2];
2062
2063   if (GET_CODE (operands[0]) != REG
2064       || REGNO_REG_CLASS (REGNO (operands[0])) != DATA_REGS)
2065     return false;
2066
2067   switch (GET_CODE (operands[1]))
2068     {
2069     case CONST_INT:
2070       {
2071         rtx low, high;
2072         split_double (operands[1], &low, &high);
2073         val[0] = INTVAL (low);
2074         val[1] = INTVAL (high);
2075       }
2076       break;
2077
2078     case CONST_DOUBLE:
2079       if (GET_MODE (operands[1]) == DFmode)
2080         {
2081           REAL_VALUE_TYPE rv;
2082
2083           REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
2084           REAL_VALUE_TO_TARGET_DOUBLE (rv, val);
2085         }
2086       else if (GET_MODE (operands[1]) == VOIDmode
2087                || GET_MODE (operands[1]) == DImode)
2088         {
2089           val[0] = CONST_DOUBLE_LOW (operands[1]);
2090           val[1] = CONST_DOUBLE_HIGH (operands[1]);
2091         }
2092       break;
2093
2094     default:
2095       return false;
2096     }
2097
2098   return val[0] == 0 || val[1] == 0;
2099 }
2100 /* If using PIC, mark a SYMBOL_REF for a non-global symbol so that we
2101    may access it using GOTOFF instead of GOT.  */
2102
2103 static void
2104 mn10300_encode_section_info (tree decl, rtx rtl, int first ATTRIBUTE_UNUSED)
2105 {
2106   rtx symbol;
2107
2108   if (GET_CODE (rtl) != MEM)
2109     return;
2110   symbol = XEXP (rtl, 0);
2111   if (GET_CODE (symbol) != SYMBOL_REF)
2112     return;
2113
2114   if (flag_pic)
2115     SYMBOL_REF_FLAG (symbol) = (*targetm.binds_local_p) (decl);
2116 }