OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.2.2/] [gcc/] [config/] [mn10300/] [mn10300.c] - Blame information for rev 307

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.