OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.5.1/] [gcc/] [config/] [or32/] [or32.c] - Blame information for rev 518

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 378 julius
/* Subroutines for insn-output.c for GNU compiler.  OpenRISC 1000 version.
2 282 jeremybenn
   Copyright (C) 1987, 1992, 1997, 1999, 2000, 2001, 2002, 2003, 2004,
3
   2005, 2006, 2007, 2008, 2009, 2010  Free Software Foundation, Inc
4
   Copyright (C) 2010 Embecosm Limited
5
 
6
   Contributed by Damjan Lampret <damjanl@bsemi.com> in 1999.
7
   Major optimizations by Matjaz Breskvar <matjazb@bsemi.com> in 2005.
8 399 jeremybenn
   Updated for GCC 4.5 by Jeremy Bennett <jeremy.bennett@embecoms.com>
9
   and Joern Rennecke <joern.rennecke@embecosm.com> in 2010.
10 282 jeremybenn
 
11
   This file is part of GNU CC.
12
 
13
   This program is free software; you can redistribute it and/or modify it
14
   under the terms of the GNU General Public License as published by the Free
15
   Software Foundation; either version 3 of the License, or (at your option)
16
   any later version.
17
 
18
   This program is distributed in the hope that it will be useful, but WITHOUT
19
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20
   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
21
   more details.
22
 
23
   You should have received a copy of the GNU General Public License along
24
   with this program.  If not, see <http://www.gnu.org/licenses/>. */
25
 
26
#include "config.h"
27
#include "system.h"
28
#include "coretypes.h"
29
#include "tm.h"
30
#include "rtl.h"
31
#include "tree.h"
32
#include "obstack.h"
33
#include "regs.h"
34
#include "hard-reg-set.h"
35
#include "real.h"
36
#include "insn-config.h"
37
#include "conditions.h"
38
#include "output.h"
39
#include "insn-attr.h"
40
#include "flags.h"
41
#include "reload.h"
42
#include "function.h"
43
#include "expr.h"
44
#include "toplev.h"
45
#include "recog.h"
46
#include "ggc.h"
47
#include "except.h"
48
#include "integrate.h"
49
#include "tm_p.h"
50
#include "target.h"
51
#include "target-def.h"
52
#include "debug.h"
53
#include "langhooks.h"
54
#include "df.h"
55
#include "dwarf2.h"
56
 
57
 
58 332 jeremybenn
/* ========================================================================== */
59
/* Local macros                                                               */
60 282 jeremybenn
 
61 332 jeremybenn
/* Construct a l.movhi instruction for the given reg and value */
62
#define OR32_MOVHI(rd, k)                                               \
63
  ((0x6 << 26) | ((rd) << 21) | (k))
64
 
65
/* Construct a l.ori instruction for the given two regs and value */
66
#define OR32_ORI(rd, ra, k)                                             \
67
  ((0x2a << 26) | ((rd) << 21) | ((ra) << 16) | (k))
68
 
69
/* Construct a l.lwz instruction for the given two registers and offset */
70
#define OR32_LWZ(rd, ra, i)                                             \
71
  ((0x21 << 26) | ((rd) << 21) | ((ra) << 16) | (i))
72
 
73
/* Construct a l.jr instruction for the given register */
74
#define OR32_JR(rb)                                                     \
75
  ((0x11 << 26) | ((rb) << 11))
76
 
77 282 jeremybenn
/* ========================================================================== */
78
/* Static variables (i.e. global to this file only.                           */
79
 
80
 
81
/* Save information from a "cmpxx" pattern until the branch or scc is
82
   emitted. These record the two operands of the "cmpxx" */
83
rtx  or32_compare_op0;
84
rtx  or32_compare_op1;
85
 
86
/*!Stack layout we use for pushing and poping saved registers */
87
static struct
88
{
89
  bool save_lr_p;
90
  int lr_save_offset;
91
  bool save_fp_p;
92
  int fp_save_offset;
93
  int gpr_size;
94
  int gpr_offset;
95
  int total_size;
96
  int vars_size;
97
  int args_size;
98 414 jeremybenn
  int gpr_frame;
99
  int late_frame;
100 282 jeremybenn
  HOST_WIDE_INT mask;
101
}  frame_info;
102
 
103
 
104
/* ========================================================================== */
105
/* Local (i.e. static) utility functions */
106
 
107
/* -------------------------------------------------------------------------- */
108
/*!Must the current function save a register?
109
 
110
   @param[in] regno  The register to consider.
111
 
112
   @return  Non-zero (TRUE) if current function must save "regno", zero
113
            (FALSE) otherwise.                                                */
114
/* -------------------------------------------------------------------------- */
115
static bool
116
or32_save_reg_p (int regno)
117
{
118
  /* No need to save the faked cc0 register.  */
119
  if (regno == OR32_FLAGS_REG)
120
    return false;
121
 
122
  /* Check call-saved registers.  */
123
  if (df_regs_ever_live_p(regno) && !call_used_regs[regno])
124
    return true;
125
 
126
  /* We need to save the old frame pointer before setting up a new
127
     one.  */
128 399 jeremybenn
  if (regno == HARD_FRAME_POINTER_REGNUM && frame_pointer_needed)
129 282 jeremybenn
    return true;
130
 
131
  /* We need to save the incoming return address if it is ever clobbered
132
     within the function.  */
133
  if (regno == LINK_REGNUM && df_regs_ever_live_p(regno))
134
    return true;
135
 
136
  return false;
137
 
138
}       /* or32_save_reg_p () */
139
 
140 399 jeremybenn
bool
141
or32_save_reg_p_cached (int regno)
142
{
143
  return (frame_info.mask & ((HOST_WIDE_INT) 1 << regno)) != 0;
144
}
145
 
146
/* N.B. contrary to the ISA documentation, the stack includes the outgoing
147
   arguments.  */
148 282 jeremybenn
/* -------------------------------------------------------------------------- */
149
/*!Compute full frame size and layout.
150
 
151
   Store information in "frame_info".
152
 
153
   @param[in] size  The size of the function's local variables.
154
 
155
   @return  Total size of stack frame.                                        */
156
/* -------------------------------------------------------------------------- */
157
static HOST_WIDE_INT
158
or32_compute_frame_size (HOST_WIDE_INT size)
159
{
160
  HOST_WIDE_INT args_size;
161
  HOST_WIDE_INT vars_size;
162
  HOST_WIDE_INT stack_offset;
163 414 jeremybenn
  HOST_WIDE_INT save_size;
164 399 jeremybenn
  bool interrupt_p = false;
165 282 jeremybenn
 
166
  int regno;
167
 
168
  args_size = crtl->outgoing_args_size;
169
  vars_size = OR32_ALIGN (size, 4);
170
 
171
  frame_info.args_size = args_size;
172
  frame_info.vars_size = vars_size;
173 414 jeremybenn
  frame_info.gpr_frame = interrupt_p ? or32_redzone : 0;
174 282 jeremybenn
 
175
  /* If the function has local variables, we're committed to
176
     allocating it anyway.  Otherwise reclaim it here.  */
177
  /* FIXME: Verify this.  Got if from the MIPS port.  */
178
  if (vars_size == 0 && current_function_is_leaf)
179
    args_size = 0;
180
 
181 399 jeremybenn
  stack_offset = 0;
182 282 jeremybenn
 
183 399 jeremybenn
  /* Save link register right at the bottom.  */
184 282 jeremybenn
  if (or32_save_reg_p (LINK_REGNUM))
185
    {
186 399 jeremybenn
      stack_offset = stack_offset - UNITS_PER_WORD;
187 282 jeremybenn
      frame_info.lr_save_offset = stack_offset;
188
      frame_info.save_lr_p = true;
189
    }
190
  else
191
    frame_info.save_lr_p = false;
192
 
193
  /* Save frame pointer right after possible link register.  */
194 399 jeremybenn
  if (frame_pointer_needed)
195 282 jeremybenn
    {
196 399 jeremybenn
      stack_offset = stack_offset - UNITS_PER_WORD;
197 282 jeremybenn
      frame_info.fp_save_offset = stack_offset;
198
      frame_info.save_fp_p = true;
199
    }
200
  else
201
    frame_info.save_fp_p = false;
202
 
203
  frame_info.gpr_size = 0;
204
  frame_info.mask = 0;
205
 
206 399 jeremybenn
  for (regno = 0; regno <= OR32_LAST_ACTUAL_REG; regno++)
207 282 jeremybenn
    {
208 399 jeremybenn
      if (regno == LINK_REGNUM
209
          || (frame_pointer_needed && regno == HARD_FRAME_POINTER_REGNUM))
210 282 jeremybenn
        /* These have already been saved if so needed.  */
211
        continue;
212
 
213
      if (or32_save_reg_p (regno))
214
        {
215
          frame_info.gpr_size += UNITS_PER_WORD;
216 399 jeremybenn
          frame_info.mask |= ((HOST_WIDE_INT) 1 << regno);
217 282 jeremybenn
        }
218
    }
219
 
220 414 jeremybenn
  save_size = (frame_info.gpr_size
221
               + (frame_info.save_fp_p ? UNITS_PER_WORD : 0)
222
               + (frame_info.save_lr_p ? UNITS_PER_WORD : 0));
223
  frame_info.total_size = save_size + vars_size + args_size;
224 399 jeremybenn
  gcc_assert (PROLOGUE_TMP != STATIC_CHAIN_REGNUM);
225
  if (frame_info.total_size > 32767 && interrupt_p)
226
    {
227
      int n_extra
228
        = (!!(~frame_info.mask && 1 << PROLOGUE_TMP)
229
           + !!(~frame_info.mask & 1 << EPILOGUE_TMP)) * UNITS_PER_WORD;
230 282 jeremybenn
 
231 414 jeremybenn
      save_size += n_extra;
232 399 jeremybenn
      frame_info.gpr_size += n_extra;
233
      frame_info.total_size += n_extra;
234
      frame_info.mask |= (1 << PROLOGUE_TMP) | (1 << EPILOGUE_TMP);
235
    }
236
 
237
  stack_offset -= frame_info.gpr_size;
238
  frame_info.gpr_offset = stack_offset;
239 414 jeremybenn
  frame_info.late_frame = frame_info.total_size;
240 399 jeremybenn
 
241 414 jeremybenn
  if (save_size > or32_redzone
242
      || (frame_info.gpr_frame
243
          && (frame_info.gpr_frame + frame_info.late_frame <= 32767)))
244
    {
245
      if (frame_info.gpr_frame + frame_info.late_frame <= 32767)
246
        save_size = frame_info.total_size;
247
      frame_info.gpr_frame += save_size;
248
      frame_info.lr_save_offset += save_size;
249
      frame_info.fp_save_offset += save_size;
250
      frame_info.gpr_offset += save_size;
251
      frame_info.late_frame -= save_size;
252
      /* FIXME: check in TARGET_OVERRIDE_OPTIONS for invalid or32_redzone.  */
253
      gcc_assert (frame_info.gpr_frame <= 32767);
254
      gcc_assert ((frame_info.gpr_frame & 3) == 0);
255
    }
256
 
257 282 jeremybenn
  return frame_info.total_size;
258
 
259
}       /* or32_compute_frame_size () */
260
 
261
 
262
/* -------------------------------------------------------------------------- */
263
/*!Emit a frame related insn.
264
 
265
   Same as emit_insn, but sets RTX_FRAME_RELATED_P to one. Getting this right
266
   will matter for DWARF 2 output, if prologues are handled via the "prologue"
267
   pattern rather than target hooks.
268
 
269
   @param[in] insn  The insn to emit.
270
 
271
   @return  The RTX for the emitted insn.                                     */
272
/* -------------------------------------------------------------------------- */
273
static rtx
274
emit_frame_insn (rtx insn)
275
{
276
  insn = emit_insn (insn);
277
  RTX_FRAME_RELATED_P (insn) = 1;
278
  return (insn);
279
 
280
}       /* emit_frame_insn () */
281
 
282
 
283
/* -------------------------------------------------------------------------- */
284 399 jeremybenn
/* Generate a RTX for the indexed memory address based on stack_pointer_rtx
285
   and a displacement
286 282 jeremybenn
 
287
   @param[in] disp  The displacement
288
 
289
   @return  The RTX for the generated address.                                */
290
/* -------------------------------------------------------------------------- */
291
static rtx
292 399 jeremybenn
stack_disp_mem (HOST_WIDE_INT disp)
293 282 jeremybenn
{
294 399 jeremybenn
  return gen_frame_mem (Pmode, plus_constant (stack_pointer_rtx, disp));
295
}
296 282 jeremybenn
 
297
 
298
/* -------------------------------------------------------------------------- */
299
/*!Generate insn patterns to do an integer compare of operands.
300
 
301
   @param[in] code  RTX for the condition code.
302
   @param[in] op0   RTX for the first operand.
303
   @param[in] op1   RTX for the second operand.
304
 
305
   @return  RTX for the comparison.                                           */
306
/* -------------------------------------------------------------------------- */
307
static rtx
308
or32_expand_int_compare (enum rtx_code  code,
309
                         rtx            op0,
310
                         rtx            op1)
311
{
312
  enum machine_mode cmpmode;
313
  rtx tmp, flags;
314
 
315
  cmpmode = SELECT_CC_MODE (code, op0, op1);
316
  flags = gen_rtx_REG (cmpmode, OR32_FLAGS_REG);
317
 
318
  /* This is very simple, but making the interface the same as in the
319
     FP case makes the rest of the code easier.  */
320
  tmp = gen_rtx_COMPARE (cmpmode, op0, op1);
321
  emit_insn (gen_rtx_SET (VOIDmode, flags, tmp));
322
 
323
  /* Return the test that should be put into the flags user, i.e.
324
     the bcc, scc, or cmov instruction.  */
325
  return gen_rtx_fmt_ee (code, VOIDmode, flags, const0_rtx);
326
 
327
}       /* or32_expand_int_compare () */
328
 
329
 
330
/* -------------------------------------------------------------------------- */
331
/*!Generate insn patterns to do an integer compare of operands.
332
 
333
   We only deal with the case where the comparison is an integer
334
   comparison. This wrapper function potentially allows reuse for non-integer
335
   comparison in the future.
336
 
337
   @param[in] code  RTX for the condition code.
338
   @param[in] op0   RTX for the first operand.
339
   @param[in] op1   RTX for the second operand.
340
 
341
   @return  RTX for the comparison.                                           */
342
/* -------------------------------------------------------------------------- */
343
static rtx
344
or32_expand_compare (enum rtx_code code, rtx op0, rtx op1)
345
{
346
  return or32_expand_int_compare (code, op0, op1);
347
 
348
}       /* or32_expand_compare () */
349
 
350
 
351
/* -------------------------------------------------------------------------- */
352
/*!Emit insns to use the l.cmov instruction
353
 
354
   Emit a compare and then cmov. Only works for integer first operand.
355
 
356
   @param[in] dest        RTX for the destination operand.
357
   @param[in] op          RTX for the comparison operation
358
   @param[in] true_cond   RTX to move to dest if condition is TRUE.
359
   @param[in] false_cond  RTX to move to dest if condition is FALSE.
360
 
361
   @return  Non-zero (TRUE) if insns were emitted, zero (FALSE) otherwise.    */
362
/* -------------------------------------------------------------------------- */
363
static int
364
or32_emit_int_cmove (rtx  dest,
365
                     rtx  op,
366
                     rtx  true_cond,
367
                     rtx  false_cond)
368
{
369
  rtx condition_rtx, cr;
370
 
371
  if ((GET_MODE (or32_compare_op0) != SImode) &&
372
      (GET_MODE (or32_compare_op0) != HImode) &&
373
      (GET_MODE (or32_compare_op0) != QImode))
374
    {
375
      return 0;
376
    }
377
 
378
  /* We still have to do the compare, because cmov doesn't do a compare, it
379
     just looks at the FLAG bit set by a previous compare instruction.  */
380
  condition_rtx = or32_expand_compare (GET_CODE (op),
381
                                       or32_compare_op0, or32_compare_op1);
382
 
383
  cr = XEXP (condition_rtx, 0);
384
 
385
  emit_insn (gen_cmov (dest, condition_rtx, true_cond, false_cond, cr));
386
 
387
  return 1;
388
 
389
}       /* or32_emit_int_cmove () */
390
 
391
 
392
/* -------------------------------------------------------------------------- */
393
/*!Calculate stack size for current function.
394
 
395
   We need space for:
396
   - any callee-saved registers that are live in the function
397
   - any local variables
398
   - the return address (if saved)
399
   - the frame pointer (if saved)
400
   - any outgoing arguments.
401
 
402
   We also return information on whether the return address and frame pointer
403
   must be saved, the space required to save callee-saved registers and the
404
   sapce required to save the return address, frame pointer and outgoing
405
   arguments.
406
 
407
   Throughout adjust for OR32 alignment requirements.
408
 
409
   @param[in]  vars           Bytes required for local variables (if any).
410
   @param[out] lr_save_area   Space required for return address (if any).
411
   @param[out] fp_save_area   Space required for frame pointer (if any).
412
   @param[out] gpr_save_area  Space required for callee-saved registers (if
413
                              any).
414
   @param[out] save_area      Space required for outgoing arguments (if any) +
415
                              return address (if any) and frame pointer (if
416
                              any).
417
 
418
   @return  Total space required (if any).                                    */
419
/* -------------------------------------------------------------------------- */
420
static int
421
calculate_stack_size (int  vars,
422
                      int *lr_save_area,
423
                      int *fp_save_area,
424
                      int *gpr_save_area,
425
                      int *save_area)
426
{
427
  int regno;
428
 
429
  *gpr_save_area = 0;
430
  for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
431
    {
432
      if (df_regs_ever_live_p(regno) && !call_used_regs[regno])
433
        *gpr_save_area += 4;
434
    }
435
 
436
  *lr_save_area = (!current_function_is_leaf
437
                   || df_regs_ever_live_p(LINK_REGNUM)) ? 4 : 0;
438
  *fp_save_area = frame_pointer_needed ? 4 : 0;
439
  *save_area    = (OR32_ALIGN (crtl->outgoing_args_size, 4)
440
                   + *lr_save_area + *fp_save_area);
441
 
442
  return *save_area + *gpr_save_area + OR32_ALIGN (vars, 4);
443
 
444
}       /* calculate_stack_size () */
445
 
446
 
447
/* -------------------------------------------------------------------------- */
448
/*!Is this a value suitable for an OR32 address displacement?
449
 
450
   Must be an integer (signed) which fits into 16-bits. If the result is a
451
   double word, we had better also check that we can also get at the second
452
   word.
453
 
454
   @param[in] mode  Mode of the result for which this displacement will be
455
                    used.
456
   @param[in] x     RTX for an expression.
457
 
458
   @return  Non-zero (TRUE) if this is a valid 16-bit offset, zero (FALSE)
459
            otherwise.                                                        */
460
/* -------------------------------------------------------------------------- */
461
static int
462
or32_legitimate_displacement_p (enum machine_mode  mode,
463
                                rtx                x)
464
{
465
  if (CONST_INT == GET_CODE(x))
466
    {
467
      HOST_WIDE_INT  disp = INTVAL (x);
468
 
469
      /* Allow for a second access 4 bytes further on if double. */
470
      if ((DFmode == mode) || (DImode == mode))
471
        {
472
          return  (-32768 < disp) && (disp <= 32763);
473
        }
474
      else
475
        {
476
          return  (-32768 < disp) && (disp <= 32767);
477
        }
478
    }
479
  else
480
    {
481
      return  0;
482
    }
483
}       /* or32_legitimate_displacement_p () */
484
 
485
 
486
/* -------------------------------------------------------------------------- */
487
/*!Can this register be used as a base register?
488
 
489
   We need a strict version, for which the register must either be a hard
490
   register, or already renumbered to a hard register.
491
 
492
   For the non-strict version, any register (other than the flag register will
493
   do).
494
 
495
   @todo The code from the old port does not allow r0 as a base when strict,
496
         and does when non-strict. Surely it is always a valid register?
497
 
498
   @param[in] regno   The register to test
499
   @param[in] strict  Non-zero (TRUE) if this is a strict check, zero (FALSE)
500
                      otherwise.
501
 
502
   @return  Non-zero (TRUE) if this register can be used as a base register,
503
            zero (FALSE) otherwise.                                           */
504
/* -------------------------------------------------------------------------- */
505
static bool
506
or32_regnum_ok_for_base_p (HOST_WIDE_INT  num,
507
                           bool           strict)
508
{
509
  if (strict)
510
    {
511
      return (num < FIRST_PSEUDO_REGISTER)
512
        ? (num > 0) && (num <= OR32_LAST_INT_REG)
513
        : (reg_renumber[num] > 0) && (reg_renumber[num] <= OR32_LAST_INT_REG);
514
    }
515
  else
516
    {
517
      return (num <= OR32_LAST_INT_REG) || (num >= FIRST_PSEUDO_REGISTER);
518
    }
519
}       /* or32_regnum_ok_for_base_p () */
520
 
521
 
522 332 jeremybenn
/* -------------------------------------------------------------------------- */
523
/*!Emit a move from SRC to DEST.
524
 
525
   Assume that the move expanders can handle all moves if !can_create_pseudo_p
526
   ().  The distinction is important because, unlike emit_move_insn, the move
527
   expanders know how to force Pmode objects into the constant pool even when
528
   the constant pool address is not itself legitimate.
529
 
530
   @param[in] dest  Destination of the move.
531
   @param[in] src   Source for the move.
532
 
533
   @return  RTX for the move.                                                 */
534
/* -------------------------------------------------------------------------- */
535 399 jeremybenn
static rtx
536 332 jeremybenn
or32_emit_move (rtx dest, rtx src)
537
{
538
  return (can_create_pseudo_p ()
539
          ? emit_move_insn (dest, src)
540
          : emit_move_insn_1 (dest, src));
541
 
542
}       /* or32_emit_move () */
543
 
544
 
545
/* -------------------------------------------------------------------------- */
546
/*!Emit an instruction of the form (set TARGET (CODE OP0 OP1)).
547
 
548
   @param[in] code    The code for the operation.
549
   @param[in] target  Destination for the set operation.
550
   @param[in] op0     First operand.
551
   @param[in] op1     Second operand.                                         */
552
/* -------------------------------------------------------------------------- */
553
static void
554
or32_emit_binary (enum rtx_code  code,
555
                  rtx            target,
556
                  rtx            op0,
557
                  rtx            op1)
558
{
559
  emit_insn (gen_rtx_SET (VOIDmode, target,
560
                          gen_rtx_fmt_ee (code, GET_MODE (target), op0, op1)));
561
 
562
}       /* or32_emit_binary () */
563
 
564
 
565
/* -------------------------------------------------------------------------- */
566
/*!Compute the result of an operation into a new register.
567
 
568
   Compute ("code" "op0" "op1") and store the result in a new register of mode
569
   "mode".
570
 
571
   @param[in] mode  Mode of the result
572
   @parma[in] code  RTX for the operation to perform
573
   @param[in] op0   RTX for the first operand
574
   @param[in] op1   RTX for the second operand
575
 
576
   @return  The RTX for the new register.                                     */
577
/* -------------------------------------------------------------------------- */
578
static rtx
579
or32_force_binary (enum machine_mode  mode,
580
                   enum rtx_code      code,
581
                   rtx                op0,
582
                   rtx                op1)
583
{
584
  rtx  reg;
585
 
586
  reg = gen_reg_rtx (mode);
587
  or32_emit_binary (code, reg, op0, op1);
588
 
589
  return reg;
590
 
591
}       /* or32_force_binary () */
592
 
593
 
594 282 jeremybenn
/* ========================================================================== */
595 332 jeremybenn
/* Global support functions                                                   */
596
 
597
/* -------------------------------------------------------------------------- */
598
/* Return the size in bytes of the trampoline code.
599
 
600
   Padded to TRAMPOLINE_ALIGNMENT bits. The code sequence is documented in
601
   or32_trampoline_init ().
602
 
603
   This is just the code size. the static chain pointer and target function
604
   address immediately follow.
605
 
606
   @return  The size of the trampoline code in bytes.                         */
607
/* -------------------------------------------------------------------------- */
608
int
609
or32_trampoline_code_size (void)
610
{
611
  const int  TRAMP_BYTE_ALIGN = TRAMPOLINE_ALIGNMENT / 8;
612
 
613
  /* Five 32-bit code words are needed */
614
  return (5 * 4 + TRAMP_BYTE_ALIGN - 1) / TRAMP_BYTE_ALIGN * TRAMP_BYTE_ALIGN;
615
 
616
}       /* or32_trampoline_code_size () */
617
 
618
 
619
/* ========================================================================== */
620 282 jeremybenn
/* Functions to support the Machine Description                               */
621
 
622
 
623
/* -------------------------------------------------------------------------- */
624
/*!Expand a prologue pattern.
625
 
626
   Called after register allocation to add any instructions needed for the
627
   prologue.  Using a prologue insn is favored compared to putting all of the
628
   instructions in output_function_prologue(), since it allows the scheduler
629
   to intermix instructions with the saves of the caller saved registers.  In
630
   some cases, it might be necessary to emit a barrier instruction as the last
631
   insn to prevent such scheduling.
632
 
633
   For the OR32 this is currently controlled by the -mlogue option. It should
634
   be the default, once it is proved to work.                                 */
635
/* -------------------------------------------------------------------------- */
636
void
637
or32_expand_prologue (void)
638
{
639
  int total_size = or32_compute_frame_size (get_frame_size ());
640 399 jeremybenn
  rtx insn;
641 282 jeremybenn
 
642
  if (!total_size)
643
    /* No frame needed.  */
644
    return;
645
 
646 414 jeremybenn
  if (frame_info.gpr_frame)
647
    emit_frame_insn (gen_add2_insn (stack_pointer_rtx,
648
                                    GEN_INT (-frame_info.gpr_frame)));
649 282 jeremybenn
  if (frame_info.save_fp_p)
650
    {
651 399 jeremybenn
      emit_frame_insn (gen_rtx_SET (Pmode,
652
                                    stack_disp_mem (frame_info.fp_save_offset),
653
                                    hard_frame_pointer_rtx));
654 282 jeremybenn
 
655
      emit_frame_insn
656 399 jeremybenn
        (gen_add3_insn (hard_frame_pointer_rtx, stack_pointer_rtx, const0_rtx));
657 282 jeremybenn
    }
658
  if (frame_info.save_lr_p)
659
    {
660
 
661
      emit_frame_insn
662 399 jeremybenn
        (gen_rtx_SET (Pmode, stack_disp_mem (frame_info.lr_save_offset),
663 282 jeremybenn
                      gen_rtx_REG (Pmode, LINK_REGNUM)));
664
    }
665
  if (frame_info.gpr_size)
666
    {
667
      int offset = 0;
668
      int regno;
669
 
670 399 jeremybenn
      for (regno = 0; regno <= OR32_LAST_ACTUAL_REG; regno++)
671 282 jeremybenn
        {
672 399 jeremybenn
          if (!(frame_info.mask & ((HOST_WIDE_INT) 1 << regno)))
673 282 jeremybenn
            continue;
674
 
675
          emit_frame_insn
676
            (gen_rtx_SET (Pmode,
677 399 jeremybenn
                          stack_disp_mem (frame_info.gpr_offset + offset),
678 282 jeremybenn
                          gen_rtx_REG (Pmode, regno)));
679
          offset = offset + UNITS_PER_WORD;
680
        }
681
    }
682 399 jeremybenn
 
683
  /* Update the stack pointer to reflect frame size.  */
684 414 jeremybenn
  total_size = frame_info.late_frame;
685 399 jeremybenn
  insn = gen_add2_insn (stack_pointer_rtx, GEN_INT (-total_size));
686 414 jeremybenn
  if (total_size > 32768)
687 399 jeremybenn
    {
688
      rtx note = insn;
689
      rtx value_rtx = gen_rtx_REG (Pmode, PROLOGUE_TMP);
690
 
691
      or32_emit_set_const32 (value_rtx, GEN_INT (-total_size));
692 490 jeremybenn
      if (frame_info.save_fp_p)
693
        insn = gen_frame_alloc_fp (value_rtx);
694
      else
695
        insn = gen_add2_insn (stack_pointer_rtx, value_rtx);
696
      insn = emit_frame_insn (insn);
697 399 jeremybenn
      add_reg_note (insn, REG_FRAME_RELATED_EXPR, note);
698
    }
699 414 jeremybenn
  else if (total_size)
700 490 jeremybenn
    {
701
      if (frame_info.save_fp_p)
702
        emit_frame_insn (gen_frame_alloc_fp (GEN_INT (-total_size)));
703
      else
704
        emit_frame_insn (insn);
705
    }
706 399 jeremybenn
 
707 282 jeremybenn
}       /* or32_expand_prologue () */
708
 
709
 
710
/* -------------------------------------------------------------------------- */
711
/*!Expand an epilogue pattern.
712
 
713
   Called after register allocation to add any instructions needed for the
714
   epilogue.  Using an epilogue insn is favored compared to putting all of the
715
   instructions in output_function_epilogue(), since it allows the scheduler
716
   to intermix instructions with the restores of the caller saved registers.
717
   In some cases, it might be necessary to emit a barrier instruction as the
718
   first insn to prevent such scheduling.
719
 
720
   For the OR32 this is currently controlled by the -mlogue option. It should
721
   be the default, once it is proved to work.
722
 
723 399 jeremybenn
   @param[in] sibcall  The sibcall epilogue insn if this is a sibcall return,
724
                       NULL_RTX otherwise.                                             */
725 282 jeremybenn
/* -------------------------------------------------------------------------- */
726
void
727 399 jeremybenn
or32_expand_epilogue (rtx sibcall)
728 282 jeremybenn
{
729
  int total_size = or32_compute_frame_size (get_frame_size ());
730 399 jeremybenn
  int sibcall_regno = FIRST_PSEUDO_REGISTER;
731 282 jeremybenn
 
732 399 jeremybenn
  if (sibcall)
733 282 jeremybenn
    {
734 399 jeremybenn
      sibcall = next_nonnote_insn (sibcall);
735
      gcc_assert (CALL_P (sibcall) && SIBLING_CALL_P (sibcall));
736
      sibcall = XVECEXP (PATTERN (sibcall), 0, 0);
737
      if (GET_CODE (sibcall) == SET)
738
        sibcall = SET_SRC (sibcall);
739
      gcc_assert (GET_CODE (sibcall) == CALL);
740
      sibcall = XEXP (sibcall, 0);
741
      gcc_assert (MEM_P (sibcall));
742
      sibcall = XEXP (sibcall, 0);
743
      if (REG_P (sibcall))
744
        sibcall_regno = REGNO (sibcall);
745
      else
746
        gcc_assert (CONSTANT_P (sibcall));
747 282 jeremybenn
    }
748 399 jeremybenn
  if (frame_info.save_fp_p)
749
    {
750 414 jeremybenn
      emit_insn (gen_frame_dealloc_fp ());
751 399 jeremybenn
      emit_insn
752
        (gen_rtx_SET (Pmode, hard_frame_pointer_rtx,
753
                      stack_disp_mem (frame_info.fp_save_offset)));
754
    }
755 282 jeremybenn
  else
756 399 jeremybenn
    {
757
      rtx value_rtx;
758 282 jeremybenn
 
759 414 jeremybenn
      total_size = frame_info.late_frame;
760 399 jeremybenn
      if (total_size > 32767)
761
        {
762
          value_rtx = gen_rtx_REG (Pmode, EPILOGUE_TMP);
763
          or32_emit_set_const32 (value_rtx, GEN_INT (total_size));
764
        }
765 414 jeremybenn
      else if (frame_info.late_frame)
766 399 jeremybenn
        value_rtx = GEN_INT (total_size);
767
      if (total_size)
768 414 jeremybenn
        emit_insn (gen_frame_dealloc_sp (value_rtx));
769 399 jeremybenn
    }
770
 
771 282 jeremybenn
  if (frame_info.save_lr_p)
772
    {
773
      emit_insn
774
        (gen_rtx_SET (Pmode, gen_rtx_REG (Pmode, LINK_REGNUM),
775 399 jeremybenn
                      stack_disp_mem (frame_info.lr_save_offset)));
776 282 jeremybenn
    }
777
 
778
  if (frame_info.gpr_size)
779
    {
780
      int offset = 0;
781
      int regno;
782
 
783 399 jeremybenn
      for (regno = 0; regno <= OR32_LAST_ACTUAL_REG; regno++)
784 282 jeremybenn
        {
785 399 jeremybenn
          if (!(frame_info.mask & ((HOST_WIDE_INT) 1 << regno)))
786 282 jeremybenn
            continue;
787
 
788 399 jeremybenn
          if (regno != sibcall_regno)
789
            emit_insn
790
              (gen_rtx_SET (Pmode, gen_rtx_REG (Pmode, regno),
791
                            stack_disp_mem (frame_info.gpr_offset + offset)));
792 282 jeremybenn
          offset = offset + UNITS_PER_WORD;
793
        }
794
    }
795
 
796 414 jeremybenn
  if (frame_info.gpr_frame)
797
    emit_insn (gen_add2_insn (stack_pointer_rtx,
798
                              GEN_INT (frame_info.gpr_frame)));
799 282 jeremybenn
  if (!sibcall)
800 399 jeremybenn
    emit_jump_insn (gen_return_internal (gen_rtx_REG (Pmode, 9)));
801 282 jeremybenn
 
802
}       /* or32_expand_epilogue () */
803
 
804 399 jeremybenn
/* We are outputting a jump which needs JUMP_ADDRESS, which is the
805
   register it uses as jump destination, restored,
806
   e.g. a sibcall using a callee-saved register.
807
   Emit the register restore as delay slot insn.  */
808
void
809
or32_print_jump_restore (rtx jump_address)
810
{
811
  int regno, jump_regno;
812
  HOST_WIDE_INT offset = frame_info.gpr_offset;
813 282 jeremybenn
 
814 399 jeremybenn
  gcc_assert (REG_P (jump_address));
815
  jump_regno = REGNO (jump_address);
816
  for (regno = 0; regno != jump_regno; regno++)
817
    {
818
      gcc_assert (regno <= OR32_LAST_ACTUAL_REG);
819
      if (!(frame_info.mask & ((HOST_WIDE_INT) 1 << regno)))
820
        continue;
821
      offset = offset + UNITS_PER_WORD;
822
    }
823
  asm_fprintf (asm_out_file, "\n\tl.lwz\tr%d,"HOST_WIDE_INT_PRINT_DEC"(r1)\n",
824
               jump_regno, offset);
825
}
826
 
827
 
828 282 jeremybenn
/* -------------------------------------------------------------------------- */
829
/*!Generate assembler code for a movdi/movdf pattern
830
 
831
   @param[in] operands  Operands to the movdx pattern.
832
 
833
   @return  The assembler string to output (always "", since we've done the
834
            output here).                                                     */
835
/* -------------------------------------------------------------------------- */
836
const char *
837
or32_output_move_double (rtx *operands)
838
{
839
  rtx xoperands[3];
840
 
841
  switch (GET_CODE (operands[0]))
842
    {
843
    case REG:
844
      if (GET_CODE (operands[1]) == REG)
845
        {
846
          if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
847
            {
848
              output_asm_insn ("\tl.or    \t%H0, %H1, r0", operands);
849
              output_asm_insn ("\tl.or    \t%0, %1, r0", operands);
850
              return "";
851
            }
852
          else
853
            {
854
              output_asm_insn ("\tl.or    \t%0, %1, r0", operands);
855
              output_asm_insn ("\tl.or    \t%H0, %H1, r0", operands);
856
              return "";
857
            }
858
        }
859
      else if (GET_CODE (operands[1]) == MEM)
860
        {
861
          xoperands[1] = XEXP (operands[1], 0);
862
          if (GET_CODE (xoperands[1]) == REG)
863
            {
864
              xoperands[0] = operands[0];
865
              if (REGNO (xoperands[0]) == REGNO (xoperands[1]))
866
                {
867
                  output_asm_insn ("\tl.lwz   \t%H0, 4(%1)", xoperands);
868
                  output_asm_insn ("\tl.lwz   \t%0, 0(%1)", xoperands);
869
                  return "";
870
                }
871
              else
872
                {
873
                  output_asm_insn ("\tl.lwz   \t%0, 0(%1)", xoperands);
874
                  output_asm_insn ("\tl.lwz   \t%H0, 4(%1)", xoperands);
875
                  return "";
876
                }
877
            }
878
          else if (GET_CODE (xoperands[1]) == PLUS)
879
            {
880
              if (GET_CODE (xoperands[2] = XEXP (xoperands[1], 1)) == REG)
881
                {
882
                  xoperands[0] = operands[0];
883
                  xoperands[1] = XEXP (xoperands[1], 0);
884
                  if (REGNO (xoperands[0]) == REGNO (xoperands[2]))
885
                    {
886
                      output_asm_insn ("\tl.lwz   \t%H0, %1+4(%2)",
887
                                       xoperands);
888
                      output_asm_insn ("\tl.lwz   \t%0, %1(%2)", xoperands);
889
                      return "";
890
                    }
891
                  else
892
                    {
893
                      output_asm_insn ("\tl.lwz   \t%0, %1(%2)", xoperands);
894
                      output_asm_insn ("\tl.lwz   \t%H0, %1+4(%2)",
895
                                       xoperands);
896
                      return "";
897
                    }
898
                }
899
              else if (GET_CODE (xoperands[2] = XEXP (xoperands[1], 0)) ==
900
                       REG)
901
                {
902
                  xoperands[0] = operands[0];
903
                  xoperands[1] = XEXP (xoperands[1], 1);
904
                  if (REGNO (xoperands[0]) == REGNO (xoperands[2]))
905
                    {
906
                      output_asm_insn ("\tl.lwz   \t%H0, %1+4(%2)",
907
                                       xoperands);
908
                      output_asm_insn ("\tl.lwz   \t%0, %1(%2)", xoperands);
909
                      return "";
910
                    }
911
                  else
912
                    {
913
                      output_asm_insn ("\tl.lwz   \t%0, %1(%2)", xoperands);
914
                      output_asm_insn ("\tl.lwz   \t%H0, %1+4(%2)",
915
                                       xoperands);
916
                      return "";
917
                    }
918
                }
919
              else
920
                abort ();
921
            }
922
          else
923
            abort ();
924
        }
925
      else
926
        abort ();
927
    case MEM:
928
      xoperands[0] = XEXP (operands[0], 0);
929
      if (GET_CODE (xoperands[0]) == REG)
930
        {
931
          xoperands[1] = operands[1];
932
          output_asm_insn ("\tl.sw    \t0(%0), %1", xoperands);
933
          output_asm_insn ("\tl.sw    \t4(%0), %H1", xoperands);
934
          return "";
935
        }
936
      else if (GET_CODE (xoperands[0]) == PLUS)
937
        {
938
          if (GET_CODE (xoperands[1] = XEXP (xoperands[0], 1)) == REG)
939
            {
940
              xoperands[0] = XEXP (xoperands[0], 0);
941
              xoperands[2] = operands[1];
942
              output_asm_insn ("\tl.sw    \t%0(%1), %2", xoperands);
943
              output_asm_insn ("\tl.sw    \t%0+4(%1), %H2", xoperands);
944
              return "";
945
            }
946
          else if (GET_CODE (xoperands[1] = XEXP (xoperands[0], 0)) == REG)
947
            {
948
              xoperands[0] = XEXP (xoperands[0], 1);
949
              xoperands[2] = operands[1];
950
              output_asm_insn ("\tl.sw    \t%0(%1), %2", xoperands);
951
              output_asm_insn ("\tl.sw    \t%0+4(%1), %H2", xoperands);
952
              return "";
953
            }
954
          else
955
            abort ();
956
        }
957
      else
958
        {
959
          fprintf (stderr, "  O/p error %s\n",
960
                   GET_RTX_NAME (GET_CODE (xoperands[0])));
961
          return "";
962
          /* abort (); */
963
        }
964
    default:
965
      abort ();
966
    }
967
}       /* or32_output_move_double () */
968
 
969
 
970
/* -------------------------------------------------------------------------- */
971
/*!Expand a conditional branch
972
 
973
   @param[in] operands  Operands to the branch.
974
   @param[in] mode      Mode of the comparison.                               */
975
/* -------------------------------------------------------------------------- */
976
void
977
or32_expand_conditional_branch (rtx               *operands,
978
                                enum machine_mode  mode)
979
{
980
  rtx tmp;
981
  enum rtx_code test_code = GET_CODE(operands[0]);
982
 
983
  switch (mode)
984
    {
985
    case SImode:
986
      tmp = or32_expand_compare (test_code, operands[1], operands[2]);
987
      tmp = gen_rtx_IF_THEN_ELSE (VOIDmode,
988
                                  tmp,
989
                                  gen_rtx_LABEL_REF (VOIDmode, operands[3]),
990
                                  pc_rtx);
991
      emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
992
      return;
993
 
994
    case SFmode:
995
      tmp = or32_expand_compare (test_code, operands[1], operands[2]);
996
      tmp = gen_rtx_IF_THEN_ELSE (VOIDmode,
997
                                  tmp,
998
                                  gen_rtx_LABEL_REF (VOIDmode, operands[3]),
999
                                  pc_rtx);
1000
      emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
1001
      return;
1002
 
1003
    default:
1004
      abort ();
1005
    }
1006
 
1007
}       /* or32_expand_conditional_branch () */
1008
 
1009
 
1010
/* -------------------------------------------------------------------------- */
1011
/*!Emit a conditional move
1012
 
1013
   move "true_cond" to "dest" if "op" of the operands of the last comparison
1014
   is nonzero/true, "false_cond" if it is zero/false.
1015
 
1016
   @param[in] dest        RTX for the destination operand.
1017
   @param[in] op          RTX for the comparison operation
1018
   @param[in] true_cond   RTX to move to dest if condition is TRUE.
1019
   @param[in] false_cond  RTX to move to dest if condition is FALSE.
1020
 
1021
   @return  Non-zero (TRUE) if the hardware supports such an operation, zero
1022
            (FALSE) otherwise.                                                */
1023
/* -------------------------------------------------------------------------- */
1024
int
1025
or32_emit_cmove (rtx  dest,
1026
                 rtx  op,
1027
                 rtx  true_cond,
1028
                 rtx  false_cond)
1029
{
1030
  enum machine_mode result_mode = GET_MODE (dest);
1031
 
1032
  if (GET_MODE (true_cond) != result_mode)
1033
    return 0;
1034
 
1035
  if (GET_MODE (false_cond) != result_mode)
1036
    return 0;
1037
 
1038
  /* First, work out if the hardware can do this at all */
1039
  return or32_emit_int_cmove (dest, op, true_cond, false_cond);
1040
 
1041
}       /* or32_emit_cmove () */
1042
 
1043
 
1044
/* -------------------------------------------------------------------------- */
1045
/*!Output the assembler for a branch on flag instruction.
1046
 
1047
   @param[in] operands  Operands to the branch.
1048
 
1049
   @return  The assembler string to use.                                      */
1050
/* -------------------------------------------------------------------------- */
1051
const char *
1052
or32_output_bf (rtx * operands)
1053
{
1054
  enum rtx_code code;
1055
  enum machine_mode mode_calc, mode_got;
1056
 
1057
  code      = GET_CODE (operands[1]);
1058
  mode_calc = SELECT_CC_MODE (code, or32_compare_op0, or32_compare_op1);
1059
  mode_got  = GET_MODE (operands[2]);
1060
 
1061 399 jeremybenn
  if (mode_calc != mode_got)
1062
    return "l.bnf\t%l0%(";
1063 282 jeremybenn
  else
1064 399 jeremybenn
    return "l.bf\t%l0%(";
1065 282 jeremybenn
}       /* or32_output_bf () */
1066
 
1067
 
1068
/* -------------------------------------------------------------------------- */
1069
/*!Output the assembler for a conditional move instruction.
1070
 
1071
   @param[in] operands  Operands to the conditional move.
1072
 
1073
   @return  The assembler string to use.                                      */
1074
/* -------------------------------------------------------------------------- */
1075
const char *
1076
or32_output_cmov (rtx * operands)
1077
{
1078
  enum rtx_code code;
1079
  enum machine_mode mode_calc, mode_got;
1080
 
1081
  code      = GET_CODE (operands[1]);
1082
  mode_calc = SELECT_CC_MODE (code, or32_compare_op0, or32_compare_op1);
1083
  mode_got  = GET_MODE (operands[4]);
1084
 
1085
  if (mode_calc != mode_got)
1086
    return "\tl.cmov\t%0,%3,%2";        /* reversed */
1087
  else
1088
    return "\tl.cmov\t%0,%2,%3";
1089
 
1090
}       /* or32_output_cmov () */
1091
 
1092
 
1093
/* -------------------------------------------------------------------------- */
1094
/*!Expand a sibcall pattern.
1095
 
1096
   For now this is very simple way for sibcall support (i.e tail call
1097
   optimization).
1098
 
1099
   @param[in] result     Not sure. RTX for the result location?
1100
   @param[in] addr       Not sure. RXT for the address to call?
1101
   @param[in] args_size  Not sure. RTX for the size of the args (in bytes?)?  */
1102
/* -------------------------------------------------------------------------- */
1103
void
1104
or32_expand_sibcall (rtx  result ATTRIBUTE_UNUSED,
1105
                     rtx  addr,
1106
                     rtx  args_size)
1107
{
1108
  emit_call_insn (gen_sibcall_internal (addr, args_size));
1109
 
1110
}       /* or32_expand_sibcall () */
1111
 
1112
 
1113
/* -------------------------------------------------------------------------- */
1114
/*!Load a 32-bit constant.
1115
 
1116
   We know it can't be done in one insn when we get here, the movsi expander
1117
   guarantees this.
1118
 
1119
   @param[in] op0  RTX for the destination.
1120
   @param[in] op1  RTX for the (constant) source.                             */
1121
/* -------------------------------------------------------------------------- */
1122
void
1123
or32_emit_set_const32 (rtx  op0,
1124
                       rtx  op1)
1125
{
1126
  enum machine_mode mode = GET_MODE (op0);
1127
  rtx temp;
1128
 
1129
  /* Sanity check that we really can't do it in one instruction. I.e that we
1130
     don't have a 16-bit constant. */
1131
  if (GET_CODE (op1) == CONST_INT)
1132
    {
1133
      HOST_WIDE_INT val = INTVAL (op1) & GET_MODE_MASK (mode);
1134
 
1135
      if ((-32768 <= val) && (val <= 32767))
1136
        {
1137
          abort ();
1138
        }
1139
    }
1140
 
1141
  /* Full 2-insn decomposition is needed.  */
1142
  if (reload_in_progress || reload_completed)
1143
    temp = op0;
1144
  else
1145
    temp = gen_reg_rtx (mode);
1146
 
1147
  if (GET_CODE (op1) == CONST_INT)
1148
    {
1149
      /* Emit them as real moves instead of a HIGH/LO_SUM,
1150
         this way CSE can see everything and reuse intermediate
1151
         values if it wants.  */
1152
      emit_insn (gen_rtx_SET (VOIDmode, temp,
1153
                              GEN_INT (INTVAL (op1)
1154
                                       & ~(HOST_WIDE_INT) 0xffff)));
1155
 
1156
      emit_insn (gen_rtx_SET (VOIDmode,
1157
                              op0,
1158
                              gen_rtx_IOR (mode, temp,
1159
                                           GEN_INT (INTVAL (op1) & 0xffff))));
1160
    }
1161
  else
1162
    {
1163
      /* since or32 bfd can not deal with relocs that are not of type
1164
         OR32_CONSTH_RELOC + OR32_CONST_RELOC (ie move high must be
1165
         followed by exactly one lo_sum)
1166
       */
1167
      emit_insn (gen_movsi_insn_big (op0, op1));
1168
    }
1169
}       /* or32_emit_set_const32 () */
1170
 
1171
 
1172
/* ========================================================================== */
1173
/* Target hook functions.
1174
 
1175
   These are initialized at the end of this file, to avoid having to
1176
   predeclare all the functions. They are only needed here, so are static.    */
1177
 
1178
 
1179
/* -------------------------------------------------------------------------- */
1180
/*!Set up the stack and frame pointer (if desired) for the function.
1181
 
1182
   If defined, a function that outputs the assembler code for entry to a
1183
   function. The prologue is responsible for setting up the stack frame,
1184
   initializing the frame pointer register, saving registers that must be
1185
   saved, and allocating "size" additional bytes of storage for the local
1186
   variables. "size" is an integer. "file" is a stdio stream to which the
1187
   assembler code should be output.
1188
 
1189
   The label for the beginning of the function need not be output by this
1190
   macro. That has already been done when the macro is run.
1191
 
1192
   To determine which registers to save, the macro can refer to the array
1193
   "regs_ever_live": element "r" is nonzero if hard register "r" is used
1194
   anywhere within the function.  This implies the function prologue should
1195
   save register r, provided it is not one of the call-used
1196
   registers. (TARGET_ASM_FUNCTION_EPILOGUE must likewise use
1197
   "regs_ever_live".)
1198
 
1199
   On machines that have "register windows", the function entry code does not
1200
   save on the stack the registers that are in the windows, even if they are
1201
   supposed to be preserved by function calls; instead it takes appropriate
1202
   steps to “push” the register stack, if any non-call-used registers are used
1203
   in the function.
1204
 
1205
   On machines where functions may or may not have frame-pointers, the
1206
   function entry code must vary accordingly; it must set up the frame pointer
1207
   if one is wanted, and not otherwise. To determine whether a frame pointer
1208
   is in wanted, the macro can refer to the variable frame_pointer_needed. The
1209
   variable’s value will be 1 at run time in a function that needs a frame
1210
   pointer. See the section on "Eliminating Frame Pointer and Arg Pointer" in
1211
   the "Target Description Macros and Functions" chapter of the GCC internals
1212
   manual.
1213
 
1214
   The function entry code is responsible for allocating any stack space
1215
   required for the function. This stack space consists of the regions listed
1216
   below. In most cases, these regions are allocated in the order listed, with
1217
   the last listed region closest to the top of the stack (the lowest address
1218
   if STACK_GROWS_DOWNWARD is defined, and the highest address if it is not
1219
   defined). You can use a different order for a machine if doing so is more
1220
   convenient or required for compatibility reasons. Except in cases where
1221
   required by standard or by a debugger, there is no reason why the stack
1222
   layout used by GCC need agree with that used by other compilers for a
1223
   machine.
1224
 
1225
   @param[in] file  File handle for any generated code.
1226
   @param[in] size  Number of bytes of storage needed for local variables.    */
1227
/* -------------------------------------------------------------------------- */
1228
static void
1229
or32_output_function_prologue (FILE          *file,
1230
                               HOST_WIDE_INT  size)
1231
{
1232
  int save_area;
1233
  int gpr_save_area;
1234
  int lr_save_area;
1235
  int fp_save_area;
1236
  int stack_size;
1237
  int regno;
1238
 
1239
  /* If we are doing the prologue using the "prologue" pattern in the machine
1240
     description, do nothing more here.
1241
 
1242
     JPB 30-Aug-10: Surely that is not correct. If this option is set, we
1243
     should never even be called! */
1244 399 jeremybenn
  if (TARGET_SCHED_LOGUE)
1245 282 jeremybenn
    return;
1246
 
1247
  if (size < 0)
1248
    abort ();
1249
 
1250
  /* Work out and log the frame size */
1251
  stack_size = calculate_stack_size (size, &lr_save_area, &fp_save_area,
1252
                                     &gpr_save_area, &save_area);
1253
 
1254
  fprintf (file,
1255
           "\n\t# gpr_save_area %d size %ld crtl->outgoing_args_size %d\n",
1256
           gpr_save_area, size, crtl->outgoing_args_size);
1257
 
1258
  /* Decrement the stack pointer by the total frame size (if we have a
1259
     frame). */
1260
  if (stack_size > 0)
1261
    {
1262
      /* Special code for large stack frames */
1263
      if (stack_size >= 0x8000)
1264
        {
1265
          fprintf (file, "\tl.movhi\tr%d,hi(%d)\n", GP_ARG_RETURN, stack_size);
1266
          fprintf (file, "\tl.ori\tr%d,r%d,lo(%d)\n", GP_ARG_RETURN,
1267
                   GP_ARG_RETURN, stack_size);
1268
          fprintf (file, "\tl.sub\tr%d,r%d,r%d\n", STACK_POINTER_REGNUM,
1269
                   STACK_POINTER_REGNUM, GP_ARG_RETURN);
1270
        }
1271
      else
1272
        {
1273
          fprintf (file, "\tl.addi\tr%d,r%d,%d\n", STACK_POINTER_REGNUM,
1274
                   STACK_POINTER_REGNUM, -stack_size);
1275
        }
1276
 
1277
      /* Update the DWARF2 CFA using the new stack pointer. After this the CFA
1278
         will be the SP + frame size, i.e. the FP (or start of frame if we
1279
         don't actually have a FP). All register refs should relate to this. */
1280
      if (dwarf2out_do_frame ())
1281
        {
1282
          char *l = dwarf2out_cfi_label (false);
1283
 
1284
          dwarf2out_def_cfa (l, STACK_POINTER_REGNUM, stack_size);
1285
        }
1286
    }
1287
 
1288
  /* Update the frame pointer if necessary */
1289
  if (fp_save_area)
1290
    {
1291
      char *l     = dwarf2out_cfi_label (false);
1292
      int  offset = OR32_ALIGN (crtl->outgoing_args_size, 4) + lr_save_area;
1293
 
1294
      fprintf (file, "\tl.sw\t%d(r%d),r%d\n", offset,
1295 399 jeremybenn
               STACK_POINTER_REGNUM, HARD_FRAME_POINTER_REGNUM);
1296 282 jeremybenn
 
1297
      if (stack_size >= 0x8000)
1298 399 jeremybenn
        fprintf (file, "\tl.add\tr%d,r%d,r%d\n", HARD_FRAME_POINTER_REGNUM,
1299 282 jeremybenn
                 STACK_POINTER_REGNUM, GP_ARG_RETURN);
1300
      else
1301 399 jeremybenn
        fprintf (file, "\tl.addi\tr%d,r%d,%d\n", HARD_FRAME_POINTER_REGNUM,
1302 282 jeremybenn
                 STACK_POINTER_REGNUM, stack_size);
1303
 
1304
      /* The CFA is already pointing at the start of our frame (i.e. the new
1305
         FP). The old FP has been saved relative to the SP, so we need to use
1306
         stack_size to work out where. */
1307 399 jeremybenn
      dwarf2out_reg_save (l, HARD_FRAME_POINTER_REGNUM, offset - stack_size);
1308 282 jeremybenn
    }
1309
 
1310
  /* Save the return address if necessary */
1311
  if (lr_save_area)
1312
    {
1313
      char *l     = dwarf2out_cfi_label (false);
1314
      int  offset = OR32_ALIGN (crtl->outgoing_args_size, 4);
1315
 
1316
      fprintf (file, "\tl.sw\t%d(r%d),r%d\n", offset, STACK_POINTER_REGNUM,
1317
               LINK_REGNUM);
1318
 
1319
      /* The CFA is already pointing at the start of our frame (i.e. the new
1320
         FP). The LR has been saved relative to the SP, so we need to use
1321
         stack_size to work out where. */
1322 399 jeremybenn
      dwarf2out_reg_save (l, HARD_FRAME_POINTER_REGNUM, offset - stack_size);
1323 282 jeremybenn
    }
1324
 
1325
  save_area = (OR32_ALIGN (crtl->outgoing_args_size, 4)
1326
               + lr_save_area + fp_save_area);
1327
 
1328
  /* Save any callee saved registers */
1329
  for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
1330
    {
1331
      if (df_regs_ever_live_p(regno) && !call_used_regs[regno])
1332
        {
1333
          char *l = dwarf2out_cfi_label (false);
1334
 
1335
          fprintf (file, "\tl.sw\t%d(r%d),r%d\n", save_area,
1336
                   STACK_POINTER_REGNUM, regno);
1337
 
1338
          /* The CFA is already pointing at the start of our frame (i.e. the
1339
             new FP). The register has been saved relative to the SP, so we
1340
             need to use stack_size to work out where. */
1341 399 jeremybenn
          dwarf2out_reg_save (l, HARD_FRAME_POINTER_REGNUM,
1342
                              save_area - stack_size);
1343 282 jeremybenn
          save_area += 4;
1344
        }
1345
    }
1346
}       /* or32_output_function_prologue () */
1347
 
1348
 
1349
/* -------------------------------------------------------------------------- */
1350
/*!Do any necessary cleanup after a function to restore stack, frame, and regs.
1351
 
1352
   This is a function that outputs the assembler code for exit from a
1353
   function. The epilogue is responsible for restoring the saved registers and
1354
   stack pointer to their values when the function was called, and returning
1355
   control to the caller. This macro takes the same arguments as the macro
1356
   TARGET_ASM_FUNCTION_PROLOGUE, and the registers to restore are determined
1357
   from regs_ever_live and CALL_USED_REGISTERS in the same way (@see
1358
   or32_output_function_prologue ()) .
1359
 
1360
   On some machines, there is a single instruction that does all the work of
1361
   returning from the function. On these machines, give that instruction the
1362
   name "return" (in the machine definition) and do not define the macro
1363
   TARGET_ASM_FUNCTION_EPILOGUE at all.
1364
 
1365
   Do not define a pattern named "return" if you want the
1366
   TARGET_ASM_FUNCTION_EPILOGUE to be used. If you want the target switches to
1367
   control whether return instructions or epilogues are used, define a
1368
   "return" pattern with a validity condition that tests the target switches
1369
   appropriately. If the "return" pattern’s validity condition is false,
1370
   epilogues will be used.
1371
 
1372
   On machines where functions may or may not have frame-pointers, the
1373
   function exit code must vary accordingly. Sometimes the code for these two
1374
   cases is completely different. To determine whether a frame pointer is
1375
   wanted, the macro can refer to the variable frame_pointer_needed. The
1376
   variable’s value will be 1 when compiling a function that needs a frame
1377
   pointer.
1378
 
1379
   Normally, TARGET_ASM_FUNCTION_PROLOGUE and TARGET_ASM_FUNCTION_EPILOGUE
1380
   must treat leaf functions specially. The C variable
1381
   "current_function_is_leaf" is nonzero for such a function. See "Handling
1382
   Leaf Functions" in the "Target Description Macros and Functions" section of
1383
   the GCC internals manual.
1384
 
1385
   On some machines, some functions pop their arguments on exit while others
1386
   leave that for the caller to do. For example, the 68020 when given "-mrtd"
1387
   pops arguments in functions that take a fixed number of arguments.
1388
 
1389
   Your definition of the macro RETURN_POPS_ARGS decides which functions pop
1390
   their own arguments. TARGET_ASM_FUNCTION_EPILOGUE needs to know what was
1391
   decided.  The number of bytes of the current function’s arguments that this
1392
   function should pop is available in "crtl->args.pops_args". See "How Scalar
1393
   Function Values Are Returned" in the "Target Description Macros and
1394
   Functions" section of the GCC internals manual.
1395
 
1396
   @param[in] file  File handle for any generated code.
1397
   @param[in] size  Number of bytes of storage needed for local variables.    */
1398
/* -------------------------------------------------------------------------- */
1399
static void
1400
or32_output_function_epilogue (FILE * file, HOST_WIDE_INT size)
1401
{
1402
  int save_area;
1403
  int gpr_save_area;
1404
  int lr_save_area;
1405
  int fp_save_area;
1406
  int stack_size;
1407
  int regno;
1408
 
1409
  /* If we are doing the epilogue using the "epilogue" pattern in the machine
1410
     description, do nothing more here.
1411
 
1412
     JPB 30-Aug-10: Surely that is not correct. If this option is set, we
1413
     should never even be called! */
1414 399 jeremybenn
  if (TARGET_SCHED_LOGUE)
1415 282 jeremybenn
    return;
1416
 
1417
  /* Work out the frame size */
1418
  stack_size = calculate_stack_size (size, &lr_save_area, &fp_save_area,
1419
                                     &gpr_save_area, &save_area);
1420
 
1421
  /* Restore the return address if necessary */
1422
  if (lr_save_area)
1423
    {
1424
      fprintf (file, "\tl.lwz\tr%d,%d(r%d)\n", LINK_REGNUM,
1425
               OR32_ALIGN (crtl->outgoing_args_size, 4),
1426
               STACK_POINTER_REGNUM);
1427
    }
1428
 
1429
  /* Restore the frame pointer if necessary */
1430
  if (fp_save_area)
1431
    {
1432 399 jeremybenn
      fprintf (file, "\tl.lwz\tr%d,%d(r%d)\n", HARD_FRAME_POINTER_REGNUM,
1433 282 jeremybenn
               OR32_ALIGN (crtl->outgoing_args_size, 4)
1434
               + lr_save_area, STACK_POINTER_REGNUM);
1435
    }
1436
 
1437
  save_area = (OR32_ALIGN (crtl->outgoing_args_size, 4)
1438
               + lr_save_area + fp_save_area);
1439
 
1440
  /* Restore any callee-saved registers */
1441
  for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
1442
    {
1443
      if (df_regs_ever_live_p(regno) && !call_used_regs[regno])
1444
        {
1445
          fprintf (file, "\tl.lwz\tr%d,%d(r%d)\n", regno, save_area,
1446
                   STACK_POINTER_REGNUM);
1447
          save_area += 4;
1448
        }
1449
    }
1450
 
1451
  /* Restore the stack pointer (if necessary) */
1452
  if (stack_size >= 0x8000)
1453
    {
1454
      fprintf (file, "\tl.movhi\tr3,hi(%d)\n", stack_size);
1455
      fprintf (file, "\tl.ori\tr3,r3,lo(%d)\n", stack_size);
1456
 
1457 399 jeremybenn
      fprintf (file, "\tl.jr\tr%d\n", LINK_REGNUM);
1458 282 jeremybenn
 
1459
      fprintf (file, "\tl.add\tr%d,r%d,r3\n", STACK_POINTER_REGNUM,
1460
               STACK_POINTER_REGNUM);
1461
    }
1462
  else if (stack_size > 0)
1463
    {
1464 399 jeremybenn
      fprintf (file, "\tl.jr\tr%d\n", LINK_REGNUM);
1465 282 jeremybenn
 
1466
      fprintf (file, "\tl.addi\tr%d,r%d,%d\n", STACK_POINTER_REGNUM,
1467
               STACK_POINTER_REGNUM, stack_size);
1468
    }
1469
  else
1470
    {
1471 399 jeremybenn
      fprintf (file, "\tl.jr\tr%d\n", LINK_REGNUM);
1472 282 jeremybenn
 
1473
      fprintf (file, "\tl.nop\n");              /* Delay slot */
1474
    }
1475
}       /* or32_output_function_epilogue () */
1476
 
1477
 
1478
/* -------------------------------------------------------------------------- */
1479
/*!Define where a function returns values.
1480
 
1481
   Define this to return an RTX representing the place where a function
1482
   returns or receives a value of data type ret type, a tree node representing
1483
   a data type.  "func" is a tree node representing FUNCTION_DECL or
1484
   FUNCTION_TYPE of a function being called. If "outgoing" is false, the hook
1485
   should compute the register in which the caller will see the return
1486
   value. Otherwise, the hook should return an RTX representing the place
1487
   where a function returns a value.
1488
 
1489
   On many machines, only TYPE_MODE ("ret_type") is relevant. (Actually, on
1490
   most machines, scalar values are returned in the same place regardless of
1491
   mode.) The value of the expression is usually a reg RTX for the hard
1492
   register where the return value is stored. The value can also be a parallel
1493
   RTX, if the return value is in multiple places. See FUNCTION_ARG for an
1494
   explanation of the parallel form. Note that the callee will populate every
1495
   location specified in the parallel, but if the first element of the
1496
   parallel contains the whole return value, callers will use that element as
1497
   the canonical location and ignore the others. The m68k port uses this type
1498
   of parallel to return pointers in both ‘%a0’ (the canonical location) and
1499
   ‘%d0’.
1500
 
1501
   If TARGET_PROMOTE_FUNCTION_RETURN returns true, you must apply the same
1502
   promotion rules specified in PROMOTE_MODE if valtype is a scalar type.
1503
 
1504
   If the precise function being called is known, "func" is a tree node
1505
   (FUNCTION_DECL) for it; otherwise, "func" is a null pointer. This makes it
1506
   possible to use a different value-returning convention for specific
1507
   functions when all their calls are known.
1508
 
1509
   Some target machines have "register windows" so that the register in which
1510
   a function returns its value is not the same as the one in which the caller
1511
   sees the value. For such machines, you should return different RTX
1512
   depending on outgoing.
1513
 
1514
   TARGET_FUNCTION_VALUE is not used for return values with aggregate data
1515
   types, because these are returned in another way. See
1516
   TARGET_STRUCT_VALUE_RTX and related macros.
1517
 
1518
   For the OR32, we can just use the result of LIBCALL_VALUE, since all
1519
   functions return their result in the same place (register rv = r11).
1520
 
1521
   JPB 30-Aug-10: What about 64-bit scalar returns (long long int, double),
1522
                  which also use rvh (=r12)?
1523
 
1524
   @param[in] ret_type  The return type of the function.
1525
   @param[in] func      Tree representing function being called.
1526
   @param[in] outgoing  Non-zero (TRUE) if the result represents where the
1527
                        function places the results, zero (FALSE) if the
1528
                        result represents where the caller sees the result.
1529
 
1530
   @return  A RTX representing where the result can be found.                 */
1531
/* -------------------------------------------------------------------------- */
1532
static rtx
1533
or32_function_value (const_tree  ret_type,
1534
                     const_tree  func ATTRIBUTE_UNUSED,
1535
                     bool        outgoing ATTRIBUTE_UNUSED)
1536
{
1537
  return LIBCALL_VALUE (TYPE_MODE(ret_type));
1538
 
1539
}       /* or32_function_value () */
1540
 
1541
 
1542
/* -------------------------------------------------------------------------- */
1543
/*!Check if a function is suitable for tail call optimization.
1544
 
1545
   True if it is OK to do sibling call optimization for the specified call
1546
   expression "exp". "decl" will be the called function, or NULL if this is an
1547
   indirect call.
1548
 
1549
   It is not uncommon for limitations of calling conventions to prevent tail
1550
   calls to functions outside the current unit of translation, or during PIC
1551
   compilation. The hook is used to enforce these restrictions, as the sibcall
1552
   md pattern can not fail, or fall over to a “normal” call. The criteria for
1553
   successful sibling call optimization may vary greatly between different
1554
   architectures.
1555
 
1556 399 jeremybenn
   For the OR32, we currently allow sibcall optimization whenever
1557
   -foptimize-sibling-calls is enabled.
1558 282 jeremybenn
 
1559
   @param[in] decl  The function for which we may optimize
1560
   @param[in] exp   The call expression which is candidate for optimization.
1561
 
1562
   @return  Non-zero (TRUE) if sibcall optimization is permitted, zero (FALSE)
1563
            otherwise.                                                        */
1564
/* -------------------------------------------------------------------------- */
1565
static bool
1566
or32_function_ok_for_sibcall (tree  decl ATTRIBUTE_UNUSED,
1567
                              tree  exp ATTRIBUTE_UNUSED)
1568
{
1569 414 jeremybenn
  /* Assume up to 31 registers of 4 bytes might be saved.  */
1570
  return or32_redzone >= 31 * 4;
1571 282 jeremybenn
}       /* or32_function_ok_for_sibcall () */
1572
 
1573
 
1574
/* -------------------------------------------------------------------------- */
1575
/*!Should an argument be passed by reference.
1576
 
1577
   This target hook should return true if an argument at the position
1578
   indicated by "cum" should be passed by reference. This predicate is queried
1579
   after target independent reasons for being passed by reference, such as
1580
   TREE_ADDRESSABLE ("type").
1581
 
1582
   If the hook returns TRUE, a copy of that argument is made in memory and a
1583
   pointer to the argument is passed instead of the argument itself. The
1584
   pointer is passed in whatever way is appropriate for passing a pointer to
1585
   that type.
1586
 
1587
   For the OR32, all aggregates and arguments greater than 8 bytes are passed
1588
   this way.
1589
 
1590
   @param[in] cum    Position of argument under consideration.
1591
   @param[in[ mode   Not sure what this relates to.
1592
   @param[in] type   Type of the argument.
1593
   @param[in] named  Not sure what this relates to.
1594
 
1595
   @return  Non-zero (TRUE) if the argument should be passed by reference,
1596
            zero (FALSE) otherwise.                                           */
1597
/* -------------------------------------------------------------------------- */
1598
static bool
1599
or32_pass_by_reference (CUMULATIVE_ARGS   *cum ATTRIBUTE_UNUSED,
1600
                        enum machine_mode  mode ATTRIBUTE_UNUSED,
1601
                        const_tree         type,
1602
                        bool               named ATTRIBUTE_UNUSED)
1603
{
1604
  return (type && (AGGREGATE_TYPE_P (type) || int_size_in_bytes (type) > 8));
1605
 
1606
}       /* or32_pass_by_reference () */
1607
 
1608
 
1609 399 jeremybenn
#if 0
1610 282 jeremybenn
/* -------------------------------------------------------------------------- */
1611
/*!Is a frame pointer required?
1612
 
1613
   This target hook should return TRUE if a function must have and use a frame
1614
   pointer.  This target hook is called in the reload pass. If its return
1615
   value is TRUE the function will have a frame pointer.
1616
 
1617
   This target hook can in principle examine the current function and decide
1618
   according to the facts, but on most machines the constant false or the
1619
   constant true suffices.  Use FALSE when the machine allows code to be
1620
   generated with no frame pointer, and doing so saves some time or space. Use
1621
   TRUE when there is no possible advantage to avoiding a frame pointer.
1622
 
1623
   In certain cases, the compiler does not know how to produce valid code
1624
   without a frame pointer. The compiler recognizes those cases and
1625
   automatically gives the function a frame pointer regardless of what
1626
   TARGET_FRAME_POINTER_REQUIRED returns.  You don’t need to worry about them.
1627
 
1628
   In a function that does not require a frame pointer, the frame pointer
1629
   register can be allocated for ordinary usage, unless you mark it as a fixed
1630
   register. See FIXED_REGISTERS for more information.
1631
 
1632
   Default return value is false.
1633
 
1634
   For the OR32 we do not need the frame pointer, so the default would have
1635
   sufficed.
1636
 
1637
   JPB 30-Aug-10: The version supplied returned TRUE, which is patently the
1638
                  wrong answer. This function really could be eliminated and
1639
                  the default used.
1640
 
1641
   @return  Non-zero (TRUE) if a frame pointer is not required, zero (FALSE)
1642
            otherwise.                                                        */
1643
/* -------------------------------------------------------------------------- */
1644
static bool
1645
or32_frame_pointer_required (void)
1646
{
1647
        return 1;
1648
 
1649
}       /* or32_frame_pointer_required () */
1650 399 jeremybenn
#endif
1651 282 jeremybenn
 
1652 399 jeremybenn
int
1653
or32_initial_elimination_offset(int from, int to)
1654
{
1655
  or32_compute_frame_size (get_frame_size ());
1656 414 jeremybenn
  return ((from == FRAME_POINTER_REGNUM
1657
           ? frame_info.gpr_offset : frame_info.gpr_frame)
1658
          + (to == STACK_POINTER_REGNUM ? frame_info.late_frame : 0));
1659 399 jeremybenn
}
1660 282 jeremybenn
 
1661 399 jeremybenn
 
1662 282 jeremybenn
/* -------------------------------------------------------------------------- */
1663
/*!How many bytes at the beginning of an argument must be put into registers.
1664
 
1665
   This target hook returns the number of bytes at the beginning of an
1666
   argument that must be put in registers. The value must be zero for
1667
   arguments that are passed entirely in registers or that are entirely pushed
1668
   on the stack.
1669
 
1670
   On some machines, certain arguments must be passed partially in registers
1671
   and partially in memory. On these machines, typically the first few words
1672
   of arguments a re passed in registers, and the rest on the stack. If a
1673
   multi-word argument (a double or a structure) crosses that boundary, its
1674
   first few words must be passed in registers and the rest must be
1675
   pushed. This macro tells the compiler when this occurs, and how many bytes
1676
   should go in registers.
1677
 
1678
   FUNCTION_ARG for these arguments should return the first register to be
1679
   used by the caller for this argument; likewise FUNCTION_INCOMING_ARG, for
1680
   the called function.
1681
 
1682
   On the OR32 we never split argumetns between registers and memory.
1683
 
1684
   JPB 30-Aug-10: Is this correct? Surely we should allow this. The ABI spec
1685
                  is incomplete on this point.
1686
 
1687
   @param[in] cum    Position of argument under consideration.
1688
   @param[in[ mode   Not sure what this relates to.
1689
   @param[in] type   Type of the argument.
1690
   @param[in] named  Not sure what this relates to.
1691
 
1692
   @return  The number of bytes of the argument to go into registers          */
1693
/* -------------------------------------------------------------------------- */
1694
static int
1695
or32_arg_partial_bytes (CUMULATIVE_ARGS   *cum ATTRIBUTE_UNUSED,
1696
                        enum machine_mode  mode ATTRIBUTE_UNUSED,
1697
                        tree               type ATTRIBUTE_UNUSED,
1698
                        bool               named ATTRIBUTE_UNUSED)
1699
{
1700
  return 0;
1701
 
1702
}       /* or32_arg_partial_bytes () */
1703
 
1704
 
1705
/* -------------------------------------------------------------------------- */
1706
/*!Promote the mode of a function's arguments/return value.
1707
 
1708
   Like PROMOTE_MODE, but it is applied to outgoing function arguments or
1709
   function return values. The target hook should return the new mode and
1710
   possibly change "*punsignedp" if the promotion should change
1711
   signedness. This function is called only for scalar or pointer types.
1712
 
1713
   "for_return" allows to distinguish the promotion of arguments and return
1714
   values. If it is 1, a return value is being promoted and
1715
   TARGET_FUNCTION_VALUE must perform the same promotions done here. If it is
1716
   2, the returned mode should be that of the register in which an incoming
1717
   parameter is copied, or the outgoing result is computed; then the hook
1718
   should return the same mode as PROMOTE_MODE, though the signedness may be
1719
   different.
1720
 
1721
   The default is to not promote arguments and return values. You can also
1722
   define the hook to "default_promote_function_mode_always_promote" if you
1723
   would like to apply the same rules given by PROMOTE_MODE.
1724
 
1725
   For the OR32, if the size of the mode is integral and less than 4, we
1726
   promote to SImode, otherwise we return the mode we are supplied.
1727
 
1728
   @param[in]  type        Not sure. Type of the argument?
1729
   @param[in]  mode        The mode of argument/return value to consider.
1730
   @param[out] punsignedp  Signedness of the value.
1731
   @param[in]  fntype      Not sure. Type of the function?
1732
   @param[in]  for_return  1 if a return value, 2 if an incoming value.
1733
 
1734
   @return  The new mode.                                                     */
1735
/* -------------------------------------------------------------------------- */
1736
static enum machine_mode
1737
or32_promote_function_mode (const_tree         type ATTRIBUTE_UNUSED,
1738
                            enum machine_mode  mode,
1739
                            int               *punsignedp ATTRIBUTE_UNUSED,
1740
                            const_tree         fntype ATTRIBUTE_UNUSED,
1741
                            int                for_return ATTRIBUTE_UNUSED)
1742
{
1743
  return (   (GET_MODE_CLASS (mode) == MODE_INT)
1744
          && (GET_MODE_SIZE (mode) < 4)) ? SImode : mode;
1745
 
1746
}       /* or32_promote_function_mode () */
1747
 
1748
 
1749
/* -------------------------------------------------------------------------- */
1750
/*!Is this a legitimate address?
1751
 
1752
  A function that returns whether x (an RTX) is a legitimate memory address on
1753
  the target machine for a memory operand of mode mode.
1754
 
1755
  Legitimate addresses are defined in two variants: a strict variant and a
1756
  non-strict one.  The strict parameter chooses which variant is desired by
1757
  the caller.
1758
 
1759
  The strict variant is used in the reload pass. It must be defined so that
1760
  any pseudo- register that has not been allocated a hard register is
1761
  considered a memory reference.  This is because in contexts where some kind
1762
  of register is required, a pseudo-register with no hard register must be
1763
  rejected. For non-hard registers, the strict variant should look up the
1764
  reg_renumber array; it should then proceed using the hard register number in
1765
  the array, or treat the pseudo as a memory reference if the array holds -1.
1766
 
1767
  The non-strict variant is used in other passes. It must be defined to accept
1768
  all pseudo-registers in every context where some kind of register is
1769
  required.
1770
 
1771
  Normally, constant addresses which are the sum of a symbol_ref and an
1772
  integer are stored inside a const RTX to mark them as constant. Therefore,
1773
  there is no need to recognize such sums specifically as legitimate
1774
  addresses. Normally you would simply recognize any const as legitimate.
1775
 
1776
  Usually PRINT_OPERAND_ADDRESS is not prepared to handle constant sums that
1777
  are not marked with const. It assumes that a naked plus indicates
1778
  indexing. If so, then you must reject such naked constant sums as
1779
  illegitimate addresses, so that none of them will be given to
1780
  PRINT_OPERAND_ADDRESS.
1781
 
1782
  On some machines, whether a symbolic address is legitimate depends on the
1783
  section that the address refers to. On these machines, define the target
1784
  hook TARGET_ENCODE_ SECTION_INFO to store the information into the
1785
  symbol_ref, and then check for it here. When you see a const, you will have
1786
  to look inside it to find the symbol_ref in order to determine the
1787
  section. See the internals manual section on "Assembler Format" for more
1788
  info.
1789
 
1790
  Some ports are still using a deprecated legacy substitute for this hook, the
1791
  GO_IF_LEGITIMATE_ADDRESS macro. This macro has this syntax:
1792
 
1793
    #define GO_IF_LEGITIMATE_ADDRESS (mode, x, label )
1794
 
1795
  and should goto label if the address x is a valid address on the target
1796
  machine for a memory operand of mode mode. Whether the strict or non-strict
1797
  variants are desired is defined by the REG_OK_STRICT macro introduced
1798
  earlier in this section. Using the hook is usually simpler because it limits
1799
  the number of files that are recompiled when changes are made.
1800
 
1801
   The OR32 only has a single addressing mode, which is a base register with
1802
   16-bit displacement. We can accept just 16-bit constants as addresses (they
1803
   can use r0 as base address, and we can accept plain registers as addresses
1804
   (they can use a displacement of zero).
1805
 
1806
   @param[in] mode    The mode of the address
1807
   @param[in] x       The address (RTX)
1808
   @param[in] strict  Non-zero (TRUE) if we are in "strict" mode, zero (FALSE)
1809
                      otherwise.
1810
 
1811
   @return  Non-zero (TRUE) if this is a legitimate address, zero (FALSE)
1812
            otherwise.                                                        */
1813
/* -------------------------------------------------------------------------- */
1814
static bool
1815 378 julius
or32_legitimate_address_p (enum machine_mode  mode ATTRIBUTE_UNUSED,
1816 282 jeremybenn
                           rtx                x,
1817
                           bool               strict)
1818
{
1819
  /* You might think 16-bit constants are suitable. They can be built into
1820
     addresses using r0 as the base. However this seems to lead to defective
1821
     code. So for now this is a placeholder, and this code is not used.
1822
 
1823
     if (or32_legitimate_displacement_p (mode, x))
1824
       {
1825
         return  1;
1826
       }
1827
  */
1828
 
1829
  /* Addresses consisting of a register and 16-bit displacement are also
1830
     suitable. We need the mode, since for double words, we had better be
1831
     able to address the full 8 bytes. */
1832
  if (GET_CODE(x) == PLUS)
1833
    {
1834
      rtx reg = XEXP(x,0);
1835
 
1836
      /* If valid register... */
1837
      if ((GET_CODE(reg) == REG)
1838 377 julius
          && or32_regnum_ok_for_base_p (REGNO (reg), strict))
1839 282 jeremybenn
        {
1840
          rtx offset = XEXP(x,1);
1841
 
1842
          /* ...and valid offset */
1843
          if (or32_legitimate_displacement_p (mode, offset))
1844
            {
1845
              return 1;
1846
            }
1847
        }
1848
    }
1849
 
1850
  /* Addresses consisting of just a register are OK. They can be built into
1851
     addresses using an offset of zero (and an offset of four if double
1852
     word). */
1853 378 julius
  if (GET_CODE(x) == REG
1854
    && or32_regnum_ok_for_base_p(REGNO(x),strict)) {
1855 282 jeremybenn
      return 1;
1856 378 julius
  }
1857 282 jeremybenn
 
1858
  return 0;
1859 378 julius
}
1860 282 jeremybenn
 
1861
/* -------------------------------------------------------------------------- */
1862 332 jeremybenn
/*!Initialize a trampoline for nested functions.
1863
 
1864
   A nested function is defined by *two* pieces of information, the address of
1865
   the function (like any other function) and a pointer to the frame of the
1866
   enclosing function. The latter is required to allow the nested function to
1867
   access local variables in the enclosing function's frame.
1868
 
1869
   This represents a problem, since a function in C is represented as an
1870
   address that can be held in a single variable as a pointer. Requiring two
1871
   pointers will not fit.
1872
 
1873
   The solution is documented in "Lexical Closures for C++" by Thomas
1874
   M. Breuel (USENIX C++ Conference Proceedings, October 17-21, 1988). The
1875
   nested function is represented by a small block of code and data on the
1876
   enclosing function's stack frame, which sets up a pointer to the enclosing
1877
   function's stack frame (the static chain pointer) in a register defined by
1878
   the ABI, and then jumps to the code of the function proper.
1879
 
1880
   The function can be represented as a single pointer to this block of code,
1881
   known as a trampoline, which when called generates both pointers
1882
   needed. The nested function (which knows it is a nested function at compile
1883
   time) can then generate code to access the enclosing frame via the static
1884
   chain register.
1885
 
1886
   There is a catch that the trampoline is set up as data, but executed as
1887
   instructions. The former will be via the data cache, the latter via the
1888
   instruction cache. There is a risk that a later trampoline will not be seen
1889
   by the instruction cache, so the wrong code will be executed. So the
1890
   instruction cache should be flushed for the trampoline address range.
1891
 
1892
   This hook is called to initialize a trampoline. "m_tramp" is an RTX for the
1893
   memory block for the trampoline; "fndecl" is the FUNCTION_DECL for the
1894
   nested function; "static_chain" is an RTX for the static chain value that
1895
   should be passed to the function when it is called.
1896
 
1897
   If the target defines TARGET_ASM_TRAMPOLINE_TEMPLATE, then the first thing
1898
   this hook should do is emit a block move into "m_tramp" from the memory
1899
   block returned by assemble_trampoline_template. Note that the block move
1900
   need only cover the constant parts of the trampoline. If the target
1901
   isolates the variable parts of the trampoline to the end, not all
1902
   TRAMPOLINE_SIZE bytes need be copied.
1903
 
1904
   If the target requires any other actions, such as flushing caches or
1905
   enabling stack execution, these actions should be performed after
1906
   initializing the trampoline proper.
1907
 
1908
   For the OR32, no static chain register is used. We choose to use the return
1909 399 jeremybenn
   value (rv) register. The code is based on that for MIPS.
1910
   The trampoline code is:
1911 332 jeremybenn
 
1912 399 jeremybenn
              l.movhi r11,hi(end_addr)
1913
              l.ori   r11,lo(end_addr)
1914
              l.lwz   r13,4(r11)
1915 332 jeremybenn
              l.jr    r13
1916 399 jeremybenn
              l.lwz   r11,0(r11)
1917 332 jeremybenn
      end_addr:
1918
              .word   <static chain>
1919
              .word   <nested_function>
1920
 
1921
   @note For the OR32 we need to flush the instruction cache, which is a
1922
         privileged operation. Needs fixing.
1923
 
1924
   @param[in] m_tramp      The lowest address of the trampoline on the stack.
1925
   @param[in] fndecl       Declaration of the enclosing function.
1926
   @param[in] chain_value  Static chain pointer to pass to the nested
1927
                           function.                                          */
1928
/* -------------------------------------------------------------------------- */
1929
static void
1930
or32_trampoline_init (rtx   m_tramp,
1931
                      tree  fndecl,
1932
                      rtx   chain_value)
1933
{
1934
  rtx  addr;                            /* Start address of the trampoline */
1935
  rtx  end_addr;                        /* End address of the code block */
1936
 
1937
  rtx  high;                            /* RTX for the high part of end_addr */
1938
  rtx  low;                             /* RTX for the low part of end_addr */
1939
  rtx  opcode;                          /* RTX for generated opcodes */
1940
  rtx  mem;                             /* RTX for trampoline memory */
1941
 
1942
  rtx trampoline[5];                    /* The trampoline code */
1943
 
1944
  unsigned int  i;                      /* Index into trampoline */
1945
  unsigned int  j;                      /* General counter */
1946
 
1947
  HOST_WIDE_INT  end_addr_offset;         /* Offset to end of code */
1948
  HOST_WIDE_INT  static_chain_offset;     /* Offset to stack chain word */
1949
  HOST_WIDE_INT  target_function_offset;  /* Offset to func address word */
1950
 
1951
  /* Work out the offsets of the pointers from the start of the trampoline
1952
     code.  */
1953
  end_addr_offset        = or32_trampoline_code_size ();
1954
  static_chain_offset    = end_addr_offset;
1955
  target_function_offset = static_chain_offset + GET_MODE_SIZE (ptr_mode);
1956
 
1957
  /* Get pointers in registers to the beginning and end of the code block.  */
1958
  addr     = force_reg (Pmode, XEXP (m_tramp, 0));
1959
  end_addr = or32_force_binary (Pmode, PLUS, addr, GEN_INT (end_addr_offset));
1960
 
1961
  /* Build up the code in TRAMPOLINE.
1962
 
1963 399 jeremybenn
              l.movhi r11,hi(end_addr)
1964
              l.ori   r11,lo(end_addr)
1965
              l.lwz   r13,4(r11)
1966 332 jeremybenn
              l.jr    r13
1967 399 jeremybenn
              l.lwz   r11,0(r11)
1968 332 jeremybenn
       end_addr:
1969
  */
1970
 
1971
  i = 0;
1972
 
1973
  /* Break out the high and low parts of the end_addr */
1974
  high = expand_simple_binop (SImode, LSHIFTRT, end_addr, GEN_INT (16),
1975
                              NULL, false, OPTAB_WIDEN);
1976
  low  = convert_to_mode (SImode, gen_lowpart (HImode, end_addr), true);
1977
 
1978
  /* Emit the l.movhi, adding an operation to OR in the high bits from the
1979
     RTX. */
1980 399 jeremybenn
  opcode = gen_int_mode (OR32_MOVHI (11, 0), SImode);
1981 332 jeremybenn
  trampoline[i++] = expand_simple_binop (SImode, IOR, opcode, high, NULL,
1982
                                         false, OPTAB_WIDEN);
1983
 
1984
  /* Emit the l.ori, adding an operations to OR in the low bits from the
1985
     RTX. */
1986 399 jeremybenn
  opcode = gen_int_mode (OR32_ORI (11, 11, 0), SImode);
1987 332 jeremybenn
  trampoline[i++] = expand_simple_binop (SImode, IOR, opcode, low, NULL,
1988
                                         false, OPTAB_WIDEN);
1989
 
1990
  /* Emit the l.lwz of the function address. No bits to OR in here, so we can
1991
     do the opcode directly. */
1992
  trampoline[i++] =
1993 399 jeremybenn
    gen_int_mode (OR32_LWZ (13, 11, target_function_offset - end_addr_offset),
1994 332 jeremybenn
                  SImode);
1995
 
1996
  /* Emit the l.jr of the function. No bits to OR in here, so we can do the
1997
     opcode directly. */
1998
  trampoline[i++] = gen_int_mode (OR32_JR (13), SImode);
1999
 
2000
  /* Emit the l.lwz of the static chain. No bits to OR in here, so we can
2001
     do the opcode directly. */
2002
  trampoline[i++] =
2003 399 jeremybenn
    gen_int_mode (OR32_LWZ (STATIC_CHAIN_REGNUM, 11,
2004 332 jeremybenn
                            static_chain_offset - end_addr_offset), SImode);
2005
 
2006
  /* Copy the trampoline code.  Leave any padding uninitialized.  */
2007
  for (j = 0; j < i; j++)
2008
    {
2009
      mem = adjust_address (m_tramp, SImode, j * GET_MODE_SIZE (SImode));
2010
      or32_emit_move (mem, trampoline[j]);
2011
    }
2012
 
2013
  /* Set up the static chain pointer field.  */
2014
  mem = adjust_address (m_tramp, ptr_mode, static_chain_offset);
2015
  or32_emit_move (mem, chain_value);
2016
 
2017
  /* Set up the target function field.  */
2018
  mem = adjust_address (m_tramp, ptr_mode, target_function_offset);
2019
  or32_emit_move (mem, XEXP (DECL_RTL (fndecl), 0));
2020
 
2021
  /* Flushing the trampoline from the instruction cache needs to be done
2022
     here. */
2023
 
2024
}       /* or32_trampoline_init () */
2025
 
2026
 
2027
/* -------------------------------------------------------------------------- */
2028 282 jeremybenn
/*!Provide support for DW_AT_calling_convention
2029
 
2030
   Define this to enable the dwarf attribute DW_AT_calling_convention to be
2031
   emitted for each function. Instead of an integer return the enum value for
2032
   the DW_CC_ tag.
2033
 
2034
   To support optional call frame debugging information, you must also define
2035
   INCOMING_RETURN_ADDR_RTX and either set RTX_FRAME_RELATED_P on the prologue
2036
   insns if you use RTL for the prologue, or call "dwarf2out_def_cfa" and
2037
   "dwarf2out_reg_save" as appropriate from TARGET_ASM_FUNCTION_PROLOGUE if
2038
   you don’t.
2039
 
2040
   For the OR32, it should be sufficient to return DW_CC_normal in all cases.
2041
 
2042
   @param[in] function  The function requiring debug information
2043
 
2044
   @return  The enum of the DW_CC tag.                                        */
2045
/* -------------------------------------------------------------------------- */
2046
static int
2047
or32_dwarf_calling_convention (const_tree  function ATTRIBUTE_UNUSED)
2048
{
2049
  return  DW_CC_normal;
2050
 
2051
}       /* or32_dwarf_calling_convention () */
2052
 
2053 399 jeremybenn
/* If DELTA doesn't fit into a 16 bit signed number, emit instructions to
2054
   add the highpart to DST; return the signed-16-bit lowpart of DELTA.
2055
   TMP_REGNO is a register that may be used to load a constant.  */
2056
static HOST_WIDE_INT
2057
or32_output_highadd (FILE *file,
2058
                     const char *dst, int tmp_regno, HOST_WIDE_INT delta)
2059
{
2060
  if (delta < -32768 || delta > 32767)
2061
    {
2062
      if (delta >= -65536 && delta < 65534)
2063
        {
2064
          asm_fprintf (file, "\tl.addi\t%s,%s,%d\n",
2065
                       dst, dst, (int) (delta + 1) >> 1);
2066
          delta >>= 1;
2067
        }
2068
      else
2069
        {
2070
          const char *tmp = reg_names[tmp_regno];
2071
          HOST_WIDE_INT high = (delta + 0x8000) >> 16;
2072 282 jeremybenn
 
2073 399 jeremybenn
          gcc_assert (call_used_regs[tmp_regno]);
2074
          asm_fprintf (file, "\tl.movhi\t%s,%d\n" "\tl.add\t%s,%s,%s\n",
2075
                 tmp, (int) high,
2076
                 dst, dst, tmp);
2077
          delta -= high << 16;
2078
        }
2079
    }
2080
  return delta;
2081
}
2082
 
2083
/* Output a tailcall to FUNCTION.  The caller will fill in the delay slot.  */
2084 402 jeremybenn
static void
2085 399 jeremybenn
or32_output_tailcall (FILE *file, tree function)
2086
{
2087
  /* We'll need to add more code if we want to fully support PIC.  */
2088
  gcc_assert (!flag_pic || (*targetm.binds_local_p) (function));
2089
 
2090
  fputs ("\tl.j\t", file);
2091
  assemble_name (file, XSTR (XEXP (DECL_RTL (function), 0), 0));
2092
  fputc ('\n', file);
2093
}
2094
 
2095
static void
2096
or32_output_mi_thunk (FILE *file, tree thunk ATTRIBUTE_UNUSED,
2097
                      HOST_WIDE_INT delta, HOST_WIDE_INT vcall_offset,
2098
                      tree function)
2099
{
2100
  int this_regno
2101
    = aggregate_value_p (TREE_TYPE (TREE_TYPE (function)), function) ? 4 : 3;
2102
  const char *this_name = reg_names[this_regno];
2103
 
2104
 
2105
  delta = or32_output_highadd (file, this_name, PROLOGUE_TMP, delta);
2106
  if (!vcall_offset)
2107
    or32_output_tailcall (file, function);
2108
  if (delta || !vcall_offset)
2109
    asm_fprintf (file, "\tl.addi\t%s,%s,%d\n",
2110
                 this_name, this_name, (int) delta);
2111
 
2112
  /* If needed, add *(*THIS + VCALL_OFFSET) to THIS.  */
2113
  if (vcall_offset != 0)
2114
    {
2115
      const char *tmp_name = reg_names[PROLOGUE_TMP];
2116
 
2117
      /* l.lwz tmp,0(this)           --> tmp = *this
2118
         l.lwz tmp,vcall_offset(tmp) --> tmp = *(*this + vcall_offset)
2119
         add this,this,tmp           --> this += *(*this + vcall_offset) */
2120
 
2121
      asm_fprintf (file, "\tl.lwz\t%s,0(%s)\n",
2122
                   tmp_name, this_name);
2123
      vcall_offset = or32_output_highadd (file, tmp_name,
2124
                                          STATIC_CHAIN_REGNUM, vcall_offset);
2125
      asm_fprintf (file, "\tl.lwz\t%s,%d(%s)\n",
2126
                   tmp_name, (int) vcall_offset, tmp_name);
2127
      or32_output_tailcall (file, function);
2128
      asm_fprintf (file, "\tl.add\t%s,%s,%s\n", this_name, this_name, tmp_name);
2129
    }
2130
}
2131
 
2132 452 jeremybenn
static bool
2133
or32_handle_option (size_t code, const char *arg ATTRIBUTE_UNUSED,
2134
                    int value ATTRIBUTE_UNUSED)
2135
{
2136
  switch (code)
2137
    {
2138
    case OPT_mnewlib:
2139
      or32_libc = or32_libc_newlib;
2140
      return true;
2141
    case OPT_muclibc:
2142
      or32_libc = or32_libc_uclibc;
2143
      return true;
2144
    case OPT_mglibc:
2145
      or32_libc = or32_libc_glibc;
2146
      return false;
2147
    default:
2148
      return true;
2149
    }
2150
}
2151 399 jeremybenn
 
2152 452 jeremybenn
 
2153 282 jeremybenn
/* ========================================================================== */
2154
/* Target hook initialization.
2155
 
2156
   In most cases these use the static functions declared above. They have
2157
   defaults, so must be undefined first, before being redefined.
2158
 
2159 333 jeremybenn
   The description of what they do is found with the function above, unless it
2160
   is a standard function or a constant, in which case it is defined here (as
2161
   with TARGET_ASM_NAMED_SECTION).
2162 282 jeremybenn
 
2163
   The final declaration is of the global "targetm" structure. */
2164
 
2165
 
2166 333 jeremybenn
/* Default target_flags if no switches specified. */
2167
#undef  TARGET_DEFAULT_TARGET_FLAGS
2168 399 jeremybenn
#define TARGET_DEFAULT_TARGET_FLAGS (MASK_HARD_MUL | MASK_SCHED_LOGUE)
2169 333 jeremybenn
 
2170 452 jeremybenn
#undef TARGET_HANDLE_OPTION
2171
#define TARGET_HANDLE_OPTION or32_handle_option
2172
 
2173 282 jeremybenn
/* Output assembly directives to switch to section name. The section should
2174
   have attributes as specified by flags, which is a bit mask of the SECTION_*
2175
   flags defined in ‘output.h’. If decl is non-NULL, it is the VAR_DECL or
2176
   FUNCTION_DECL with which this section is associated.
2177
 
2178
   For OR32, we use the default ELF sectioning. */
2179 332 jeremybenn
#undef  TARGET_ASM_NAMED_SECTION
2180 282 jeremybenn
#define TARGET_ASM_NAMED_SECTION  default_elf_asm_named_section
2181
 
2182 332 jeremybenn
#undef  TARGET_ASM_FUNCTION_PROLOGUE
2183 282 jeremybenn
#define TARGET_ASM_FUNCTION_PROLOGUE or32_output_function_prologue
2184
 
2185 332 jeremybenn
#undef  TARGET_ASM_FUNCTION_EPILOGUE
2186 282 jeremybenn
#define TARGET_ASM_FUNCTION_EPILOGUE or32_output_function_epilogue
2187
 
2188 332 jeremybenn
#undef  TARGET_FUNCTION_VALUE
2189 282 jeremybenn
#define TARGET_FUNCTION_VALUE or32_function_value
2190
 
2191 332 jeremybenn
#undef  TARGET_FUNCTION_OK_FOR_SIBCALL
2192 282 jeremybenn
#define TARGET_FUNCTION_OK_FOR_SIBCALL or32_function_ok_for_sibcall
2193
 
2194 332 jeremybenn
#undef  TARGET_PASS_BY_REFERENCE
2195 282 jeremybenn
#define TARGET_PASS_BY_REFERENCE or32_pass_by_reference
2196
 
2197 332 jeremybenn
#undef  TARGET_ARG_PARTIAL_BYTES
2198 282 jeremybenn
#define TARGET_ARG_PARTIAL_BYTES or32_arg_partial_bytes
2199
 
2200
/* This target hook returns TRUE if an argument declared in a prototype as an
2201
   integral type smaller than int should actually be passed as an int. In
2202
   addition to avoiding errors in certain cases of mismatch, it also makes for
2203
   better code on certain machines.
2204
 
2205
   The default is to not promote prototypes.
2206
 
2207
   For the OR32 we do require this, so use a utility hook, which always
2208
   returns TRUE. */
2209 332 jeremybenn
#undef  TARGET_PROMOTE_PROTOTYPES
2210 282 jeremybenn
#define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
2211
 
2212 332 jeremybenn
#undef  TARGET_PROMOTE_FUNCTION_MODE
2213 282 jeremybenn
#define TARGET_PROMOTE_FUNCTION_MODE or32_promote_function_mode
2214
 
2215 332 jeremybenn
#undef  TARGET_LEGITIMATE_ADDRESS_P
2216 282 jeremybenn
#define TARGET_LEGITIMATE_ADDRESS_P  or32_legitimate_address_p
2217
 
2218 332 jeremybenn
#undef  TARGET_TRAMPOLINE_INIT
2219
#define TARGET_TRAMPOLINE_INIT  or32_trampoline_init
2220
 
2221 282 jeremybenn
#undef TARGET_DWARF_CALLING_CONVENTION
2222
#define TARGET_DWARF_CALLING_CONVENTION  or32_dwarf_calling_convention
2223
 
2224 399 jeremybenn
#undef TARGET_ASM_OUTPUT_MI_THUNK
2225
#define TARGET_ASM_OUTPUT_MI_THUNK or32_output_mi_thunk
2226
 
2227
#undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
2228
#define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_const_tree_hwi_hwi_const_tree_true
2229
 
2230 444 jeremybenn
/* uClibc has some instances where (non-coforming to ISO C) a non-varargs
2231
   prototype is in scope when calling that function which is implemented
2232
   as varargs.  We want this to work at least where none of the anonymous
2233
   arguments are used.  I.e. we want the last named argument to be known
2234
   as named so it can be passed in a register, varars funtion or not.  */
2235
#undef TARGET_STRICT_ARGUMENT_NAMING
2236
#define TARGET_STRICT_ARGUMENT_NAMING hook_bool_CUMULATIVE_ARGS_true
2237
 
2238 282 jeremybenn
/* Trampoline stubs are yet to be written. */
2239
/* #define TARGET_ASM_TRAMPOLINE_TEMPLATE */
2240
/* #define TARGET_TRAMPOLINE_INIT */
2241
 
2242
/* Initialize the GCC target structure.  */
2243
struct gcc_target targetm = TARGET_INITIALIZER;
2244 399 jeremybenn
 
2245
/* Lay out structs with increased alignment so that they can be accessed
2246
   more efficiently.  But don't increase the size of one or two byte
2247
   structs.  */
2248
int
2249
or32_struct_alignment (tree t)
2250
{
2251
  unsigned HOST_WIDE_INT total = 0;
2252 402 jeremybenn
  int default_align_fields = 0;
2253
  int special_align_fields = 0;
2254 399 jeremybenn
  tree field;
2255
  unsigned max_align
2256
    = maximum_field_alignment ? maximum_field_alignment : BIGGEST_ALIGNMENT;
2257
  bool struct_p;
2258
 
2259
  switch (TREE_CODE (t))
2260
    {
2261
    case RECORD_TYPE:
2262
      struct_p = true; break;
2263
    case UNION_TYPE: case QUAL_UNION_TYPE:
2264
      struct_p = false; break;
2265
    default: gcc_unreachable ();
2266
    }
2267
  /* Skip all non field decls */
2268
  for (field = TYPE_FIELDS (t); field; field = TREE_CHAIN (field))
2269
    {
2270
      unsigned HOST_WIDE_INT field_size;
2271
 
2272
      if (TREE_CODE (field) != FIELD_DECL)
2273
        continue;
2274 402 jeremybenn
      /* If this is a field in a non-qualified union, or the sole field in
2275
         a struct, and the alignment was set by the user, don't change the
2276
         alignment.
2277
         If the field is a struct/union in a non-qualified union, we already
2278
         had sufficient opportunity to pad it - if we didn't, that'd be
2279
         because the alignment was set as above.
2280
         Likewise if the field is a struct/union and the sole field in a
2281
         struct.  */
2282
      if (DECL_USER_ALIGN (field)
2283
          || TYPE_USER_ALIGN (TREE_TYPE (field))
2284
          || TREE_CODE (TREE_TYPE (field)) == UNION_TYPE
2285
          || TREE_CODE (TREE_TYPE (field)) == QUAL_UNION_TYPE
2286
          || TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE)
2287
        {
2288
          if (TREE_CODE (t) == UNION_TYPE)
2289
            return 0;
2290
          special_align_fields++;
2291
        }
2292
      else if (DECL_PACKED (field))
2293
        special_align_fields++;
2294
      else
2295
        default_align_fields++;
2296 399 jeremybenn
      if (!host_integerp (DECL_SIZE (field), 1))
2297 402 jeremybenn
        field_size = max_align;
2298
      else
2299
        field_size = tree_low_cst (DECL_SIZE (field), 1);
2300 399 jeremybenn
      if (field_size >= BIGGEST_ALIGNMENT)
2301 402 jeremybenn
        total = max_align;
2302 399 jeremybenn
      if (struct_p)
2303
        total += field_size;
2304
      else
2305
        total = MAX (total, field_size);
2306
    }
2307
 
2308 402 jeremybenn
  if (!default_align_fields
2309
      && (TREE_CODE (t) != RECORD_TYPE || special_align_fields <= 1))
2310
    return 0;
2311 399 jeremybenn
  return total < max_align ? (1U << ceil_log2 (total)) : max_align;
2312
}
2313
 
2314
/* Increase the alignment of objects so that they are easier to copy.
2315
   Note that this can cause more struct copies to be inlined, so code
2316
   size might increase, but so should perfromance.  */
2317
int
2318
or32_data_alignment (tree t, int align)
2319
{
2320
  if (align < FASTEST_ALIGNMENT && TREE_CODE (t) == ARRAY_TYPE)
2321
    {
2322
      int size = int_size_in_bytes (t);
2323
 
2324
      return (size > 0 && size < FASTEST_ALIGNMENT / BITS_PER_UNIT
2325
              ? (1 << floor_log2 (size)) * BITS_PER_UNIT
2326
              : FASTEST_ALIGNMENT);
2327
    }
2328
  return align;
2329
}

powered by: WebSVN 2.1.0

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