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 490

Go to most recent revision | 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 if (GET_CODE (operands[1]) == CONST_INT)
926
        {
927
          if (INTVAL (operands[1]) < 0)
928
            output_asm_insn ("\tl.addi  \t%0, r0, -1", operands);
929
          else
930
            output_asm_insn ("\tl.or    \t%0, r0, r0", operands);
931
          output_asm_insn ("\tl.movhi \t%H0, hi(%1)", operands);
932
          output_asm_insn ("\tl.ori   \t%H0, %H0, lo(%1)", operands);
933
          return "";
934
        }
935
      else
936
        abort ();
937
    case MEM:
938
      xoperands[0] = XEXP (operands[0], 0);
939
      if (GET_CODE (xoperands[0]) == REG)
940
        {
941
          xoperands[1] = operands[1];
942
          output_asm_insn ("\tl.sw    \t0(%0), %1", xoperands);
943
          output_asm_insn ("\tl.sw    \t4(%0), %H1", xoperands);
944
          return "";
945
        }
946
      else if (GET_CODE (xoperands[0]) == PLUS)
947
        {
948
          if (GET_CODE (xoperands[1] = XEXP (xoperands[0], 1)) == REG)
949
            {
950
              xoperands[0] = XEXP (xoperands[0], 0);
951
              xoperands[2] = operands[1];
952
              output_asm_insn ("\tl.sw    \t%0(%1), %2", xoperands);
953
              output_asm_insn ("\tl.sw    \t%0+4(%1), %H2", xoperands);
954
              return "";
955
            }
956
          else if (GET_CODE (xoperands[1] = XEXP (xoperands[0], 0)) == REG)
957
            {
958
              xoperands[0] = XEXP (xoperands[0], 1);
959
              xoperands[2] = operands[1];
960
              output_asm_insn ("\tl.sw    \t%0(%1), %2", xoperands);
961
              output_asm_insn ("\tl.sw    \t%0+4(%1), %H2", xoperands);
962
              return "";
963
            }
964
          else
965
            abort ();
966
        }
967
      else
968
        {
969
          fprintf (stderr, "  O/p error %s\n",
970
                   GET_RTX_NAME (GET_CODE (xoperands[0])));
971
          return "";
972
          /* abort (); */
973
        }
974
    default:
975
      abort ();
976
    }
977
}       /* or32_output_move_double () */
978
 
979
 
980
/* -------------------------------------------------------------------------- */
981
/*!Expand a conditional branch
982
 
983
   @param[in] operands  Operands to the branch.
984
   @param[in] mode      Mode of the comparison.                               */
985
/* -------------------------------------------------------------------------- */
986
void
987
or32_expand_conditional_branch (rtx               *operands,
988
                                enum machine_mode  mode)
989
{
990
  rtx tmp;
991
  enum rtx_code test_code = GET_CODE(operands[0]);
992
 
993
  switch (mode)
994
    {
995
    case SImode:
996
      tmp = or32_expand_compare (test_code, operands[1], operands[2]);
997
      tmp = gen_rtx_IF_THEN_ELSE (VOIDmode,
998
                                  tmp,
999
                                  gen_rtx_LABEL_REF (VOIDmode, operands[3]),
1000
                                  pc_rtx);
1001
      emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
1002
      return;
1003
 
1004
    case SFmode:
1005
      tmp = or32_expand_compare (test_code, operands[1], operands[2]);
1006
      tmp = gen_rtx_IF_THEN_ELSE (VOIDmode,
1007
                                  tmp,
1008
                                  gen_rtx_LABEL_REF (VOIDmode, operands[3]),
1009
                                  pc_rtx);
1010
      emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
1011
      return;
1012
 
1013
    default:
1014
      abort ();
1015
    }
1016
 
1017
}       /* or32_expand_conditional_branch () */
1018
 
1019
 
1020
/* -------------------------------------------------------------------------- */
1021
/*!Emit a conditional move
1022
 
1023
   move "true_cond" to "dest" if "op" of the operands of the last comparison
1024
   is nonzero/true, "false_cond" if it is zero/false.
1025
 
1026
   @param[in] dest        RTX for the destination operand.
1027
   @param[in] op          RTX for the comparison operation
1028
   @param[in] true_cond   RTX to move to dest if condition is TRUE.
1029
   @param[in] false_cond  RTX to move to dest if condition is FALSE.
1030
 
1031
   @return  Non-zero (TRUE) if the hardware supports such an operation, zero
1032
            (FALSE) otherwise.                                                */
1033
/* -------------------------------------------------------------------------- */
1034
int
1035
or32_emit_cmove (rtx  dest,
1036
                 rtx  op,
1037
                 rtx  true_cond,
1038
                 rtx  false_cond)
1039
{
1040
  enum machine_mode result_mode = GET_MODE (dest);
1041
 
1042
  if (GET_MODE (true_cond) != result_mode)
1043
    return 0;
1044
 
1045
  if (GET_MODE (false_cond) != result_mode)
1046
    return 0;
1047
 
1048
  /* First, work out if the hardware can do this at all */
1049
  return or32_emit_int_cmove (dest, op, true_cond, false_cond);
1050
 
1051
}       /* or32_emit_cmove () */
1052
 
1053
 
1054
/* -------------------------------------------------------------------------- */
1055
/*!Output the assembler for a branch on flag instruction.
1056
 
1057
   @param[in] operands  Operands to the branch.
1058
 
1059
   @return  The assembler string to use.                                      */
1060
/* -------------------------------------------------------------------------- */
1061
const char *
1062
or32_output_bf (rtx * operands)
1063
{
1064
  enum rtx_code code;
1065
  enum machine_mode mode_calc, mode_got;
1066
 
1067
  code      = GET_CODE (operands[1]);
1068
  mode_calc = SELECT_CC_MODE (code, or32_compare_op0, or32_compare_op1);
1069
  mode_got  = GET_MODE (operands[2]);
1070
 
1071 399 jeremybenn
  if (mode_calc != mode_got)
1072
    return "l.bnf\t%l0%(";
1073 282 jeremybenn
  else
1074 399 jeremybenn
    return "l.bf\t%l0%(";
1075 282 jeremybenn
}       /* or32_output_bf () */
1076
 
1077
 
1078
/* -------------------------------------------------------------------------- */
1079
/*!Output the assembler for a conditional move instruction.
1080
 
1081
   @param[in] operands  Operands to the conditional move.
1082
 
1083
   @return  The assembler string to use.                                      */
1084
/* -------------------------------------------------------------------------- */
1085
const char *
1086
or32_output_cmov (rtx * operands)
1087
{
1088
  enum rtx_code code;
1089
  enum machine_mode mode_calc, mode_got;
1090
 
1091
  code      = GET_CODE (operands[1]);
1092
  mode_calc = SELECT_CC_MODE (code, or32_compare_op0, or32_compare_op1);
1093
  mode_got  = GET_MODE (operands[4]);
1094
 
1095
  if (mode_calc != mode_got)
1096
    return "\tl.cmov\t%0,%3,%2";        /* reversed */
1097
  else
1098
    return "\tl.cmov\t%0,%2,%3";
1099
 
1100
}       /* or32_output_cmov () */
1101
 
1102
 
1103
/* -------------------------------------------------------------------------- */
1104
/*!Expand a sibcall pattern.
1105
 
1106
   For now this is very simple way for sibcall support (i.e tail call
1107
   optimization).
1108
 
1109
   @param[in] result     Not sure. RTX for the result location?
1110
   @param[in] addr       Not sure. RXT for the address to call?
1111
   @param[in] args_size  Not sure. RTX for the size of the args (in bytes?)?  */
1112
/* -------------------------------------------------------------------------- */
1113
void
1114
or32_expand_sibcall (rtx  result ATTRIBUTE_UNUSED,
1115
                     rtx  addr,
1116
                     rtx  args_size)
1117
{
1118
  emit_call_insn (gen_sibcall_internal (addr, args_size));
1119
 
1120
}       /* or32_expand_sibcall () */
1121
 
1122
 
1123
/* -------------------------------------------------------------------------- */
1124
/*!Load a 32-bit constant.
1125
 
1126
   We know it can't be done in one insn when we get here, the movsi expander
1127
   guarantees this.
1128
 
1129
   @param[in] op0  RTX for the destination.
1130
   @param[in] op1  RTX for the (constant) source.                             */
1131
/* -------------------------------------------------------------------------- */
1132
void
1133
or32_emit_set_const32 (rtx  op0,
1134
                       rtx  op1)
1135
{
1136
  enum machine_mode mode = GET_MODE (op0);
1137
  rtx temp;
1138
 
1139
  /* Sanity check that we really can't do it in one instruction. I.e that we
1140
     don't have a 16-bit constant. */
1141
  if (GET_CODE (op1) == CONST_INT)
1142
    {
1143
      HOST_WIDE_INT val = INTVAL (op1) & GET_MODE_MASK (mode);
1144
 
1145
      if ((-32768 <= val) && (val <= 32767))
1146
        {
1147
          abort ();
1148
        }
1149
    }
1150
 
1151
  /* Full 2-insn decomposition is needed.  */
1152
  if (reload_in_progress || reload_completed)
1153
    temp = op0;
1154
  else
1155
    temp = gen_reg_rtx (mode);
1156
 
1157
  if (GET_CODE (op1) == CONST_INT)
1158
    {
1159
      /* Emit them as real moves instead of a HIGH/LO_SUM,
1160
         this way CSE can see everything and reuse intermediate
1161
         values if it wants.  */
1162
      emit_insn (gen_rtx_SET (VOIDmode, temp,
1163
                              GEN_INT (INTVAL (op1)
1164
                                       & ~(HOST_WIDE_INT) 0xffff)));
1165
 
1166
      emit_insn (gen_rtx_SET (VOIDmode,
1167
                              op0,
1168
                              gen_rtx_IOR (mode, temp,
1169
                                           GEN_INT (INTVAL (op1) & 0xffff))));
1170
    }
1171
  else
1172
    {
1173
      /* since or32 bfd can not deal with relocs that are not of type
1174
         OR32_CONSTH_RELOC + OR32_CONST_RELOC (ie move high must be
1175
         followed by exactly one lo_sum)
1176
       */
1177
      emit_insn (gen_movsi_insn_big (op0, op1));
1178
    }
1179
}       /* or32_emit_set_const32 () */
1180
 
1181
 
1182
/* ========================================================================== */
1183
/* Target hook functions.
1184
 
1185
   These are initialized at the end of this file, to avoid having to
1186
   predeclare all the functions. They are only needed here, so are static.    */
1187
 
1188
 
1189
/* -------------------------------------------------------------------------- */
1190
/*!Set up the stack and frame pointer (if desired) for the function.
1191
 
1192
   If defined, a function that outputs the assembler code for entry to a
1193
   function. The prologue is responsible for setting up the stack frame,
1194
   initializing the frame pointer register, saving registers that must be
1195
   saved, and allocating "size" additional bytes of storage for the local
1196
   variables. "size" is an integer. "file" is a stdio stream to which the
1197
   assembler code should be output.
1198
 
1199
   The label for the beginning of the function need not be output by this
1200
   macro. That has already been done when the macro is run.
1201
 
1202
   To determine which registers to save, the macro can refer to the array
1203
   "regs_ever_live": element "r" is nonzero if hard register "r" is used
1204
   anywhere within the function.  This implies the function prologue should
1205
   save register r, provided it is not one of the call-used
1206
   registers. (TARGET_ASM_FUNCTION_EPILOGUE must likewise use
1207
   "regs_ever_live".)
1208
 
1209
   On machines that have "register windows", the function entry code does not
1210
   save on the stack the registers that are in the windows, even if they are
1211
   supposed to be preserved by function calls; instead it takes appropriate
1212
   steps to “push” the register stack, if any non-call-used registers are used
1213
   in the function.
1214
 
1215
   On machines where functions may or may not have frame-pointers, the
1216
   function entry code must vary accordingly; it must set up the frame pointer
1217
   if one is wanted, and not otherwise. To determine whether a frame pointer
1218
   is in wanted, the macro can refer to the variable frame_pointer_needed. The
1219
   variable’s value will be 1 at run time in a function that needs a frame
1220
   pointer. See the section on "Eliminating Frame Pointer and Arg Pointer" in
1221
   the "Target Description Macros and Functions" chapter of the GCC internals
1222
   manual.
1223
 
1224
   The function entry code is responsible for allocating any stack space
1225
   required for the function. This stack space consists of the regions listed
1226
   below. In most cases, these regions are allocated in the order listed, with
1227
   the last listed region closest to the top of the stack (the lowest address
1228
   if STACK_GROWS_DOWNWARD is defined, and the highest address if it is not
1229
   defined). You can use a different order for a machine if doing so is more
1230
   convenient or required for compatibility reasons. Except in cases where
1231
   required by standard or by a debugger, there is no reason why the stack
1232
   layout used by GCC need agree with that used by other compilers for a
1233
   machine.
1234
 
1235
   @param[in] file  File handle for any generated code.
1236
   @param[in] size  Number of bytes of storage needed for local variables.    */
1237
/* -------------------------------------------------------------------------- */
1238
static void
1239
or32_output_function_prologue (FILE          *file,
1240
                               HOST_WIDE_INT  size)
1241
{
1242
  int save_area;
1243
  int gpr_save_area;
1244
  int lr_save_area;
1245
  int fp_save_area;
1246
  int stack_size;
1247
  int regno;
1248
 
1249
  /* If we are doing the prologue using the "prologue" pattern in the machine
1250
     description, do nothing more here.
1251
 
1252
     JPB 30-Aug-10: Surely that is not correct. If this option is set, we
1253
     should never even be called! */
1254 399 jeremybenn
  if (TARGET_SCHED_LOGUE)
1255 282 jeremybenn
    return;
1256
 
1257
  if (size < 0)
1258
    abort ();
1259
 
1260
  /* Work out and log the frame size */
1261
  stack_size = calculate_stack_size (size, &lr_save_area, &fp_save_area,
1262
                                     &gpr_save_area, &save_area);
1263
 
1264
  fprintf (file,
1265
           "\n\t# gpr_save_area %d size %ld crtl->outgoing_args_size %d\n",
1266
           gpr_save_area, size, crtl->outgoing_args_size);
1267
 
1268
  /* Decrement the stack pointer by the total frame size (if we have a
1269
     frame). */
1270
  if (stack_size > 0)
1271
    {
1272
      /* Special code for large stack frames */
1273
      if (stack_size >= 0x8000)
1274
        {
1275
          fprintf (file, "\tl.movhi\tr%d,hi(%d)\n", GP_ARG_RETURN, stack_size);
1276
          fprintf (file, "\tl.ori\tr%d,r%d,lo(%d)\n", GP_ARG_RETURN,
1277
                   GP_ARG_RETURN, stack_size);
1278
          fprintf (file, "\tl.sub\tr%d,r%d,r%d\n", STACK_POINTER_REGNUM,
1279
                   STACK_POINTER_REGNUM, GP_ARG_RETURN);
1280
        }
1281
      else
1282
        {
1283
          fprintf (file, "\tl.addi\tr%d,r%d,%d\n", STACK_POINTER_REGNUM,
1284
                   STACK_POINTER_REGNUM, -stack_size);
1285
        }
1286
 
1287
      /* Update the DWARF2 CFA using the new stack pointer. After this the CFA
1288
         will be the SP + frame size, i.e. the FP (or start of frame if we
1289
         don't actually have a FP). All register refs should relate to this. */
1290
      if (dwarf2out_do_frame ())
1291
        {
1292
          char *l = dwarf2out_cfi_label (false);
1293
 
1294
          dwarf2out_def_cfa (l, STACK_POINTER_REGNUM, stack_size);
1295
        }
1296
    }
1297
 
1298
  /* Update the frame pointer if necessary */
1299
  if (fp_save_area)
1300
    {
1301
      char *l     = dwarf2out_cfi_label (false);
1302
      int  offset = OR32_ALIGN (crtl->outgoing_args_size, 4) + lr_save_area;
1303
 
1304
      fprintf (file, "\tl.sw\t%d(r%d),r%d\n", offset,
1305 399 jeremybenn
               STACK_POINTER_REGNUM, HARD_FRAME_POINTER_REGNUM);
1306 282 jeremybenn
 
1307
      if (stack_size >= 0x8000)
1308 399 jeremybenn
        fprintf (file, "\tl.add\tr%d,r%d,r%d\n", HARD_FRAME_POINTER_REGNUM,
1309 282 jeremybenn
                 STACK_POINTER_REGNUM, GP_ARG_RETURN);
1310
      else
1311 399 jeremybenn
        fprintf (file, "\tl.addi\tr%d,r%d,%d\n", HARD_FRAME_POINTER_REGNUM,
1312 282 jeremybenn
                 STACK_POINTER_REGNUM, stack_size);
1313
 
1314
      /* The CFA is already pointing at the start of our frame (i.e. the new
1315
         FP). The old FP has been saved relative to the SP, so we need to use
1316
         stack_size to work out where. */
1317 399 jeremybenn
      dwarf2out_reg_save (l, HARD_FRAME_POINTER_REGNUM, offset - stack_size);
1318 282 jeremybenn
    }
1319
 
1320
  /* Save the return address if necessary */
1321
  if (lr_save_area)
1322
    {
1323
      char *l     = dwarf2out_cfi_label (false);
1324
      int  offset = OR32_ALIGN (crtl->outgoing_args_size, 4);
1325
 
1326
      fprintf (file, "\tl.sw\t%d(r%d),r%d\n", offset, STACK_POINTER_REGNUM,
1327
               LINK_REGNUM);
1328
 
1329
      /* The CFA is already pointing at the start of our frame (i.e. the new
1330
         FP). The LR has been saved relative to the SP, so we need to use
1331
         stack_size to work out where. */
1332 399 jeremybenn
      dwarf2out_reg_save (l, HARD_FRAME_POINTER_REGNUM, offset - stack_size);
1333 282 jeremybenn
    }
1334
 
1335
  save_area = (OR32_ALIGN (crtl->outgoing_args_size, 4)
1336
               + lr_save_area + fp_save_area);
1337
 
1338
  /* Save any callee saved registers */
1339
  for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
1340
    {
1341
      if (df_regs_ever_live_p(regno) && !call_used_regs[regno])
1342
        {
1343
          char *l = dwarf2out_cfi_label (false);
1344
 
1345
          fprintf (file, "\tl.sw\t%d(r%d),r%d\n", save_area,
1346
                   STACK_POINTER_REGNUM, regno);
1347
 
1348
          /* The CFA is already pointing at the start of our frame (i.e. the
1349
             new FP). The register has been saved relative to the SP, so we
1350
             need to use stack_size to work out where. */
1351 399 jeremybenn
          dwarf2out_reg_save (l, HARD_FRAME_POINTER_REGNUM,
1352
                              save_area - stack_size);
1353 282 jeremybenn
          save_area += 4;
1354
        }
1355
    }
1356
}       /* or32_output_function_prologue () */
1357
 
1358
 
1359
/* -------------------------------------------------------------------------- */
1360
/*!Do any necessary cleanup after a function to restore stack, frame, and regs.
1361
 
1362
   This is a function that outputs the assembler code for exit from a
1363
   function. The epilogue is responsible for restoring the saved registers and
1364
   stack pointer to their values when the function was called, and returning
1365
   control to the caller. This macro takes the same arguments as the macro
1366
   TARGET_ASM_FUNCTION_PROLOGUE, and the registers to restore are determined
1367
   from regs_ever_live and CALL_USED_REGISTERS in the same way (@see
1368
   or32_output_function_prologue ()) .
1369
 
1370
   On some machines, there is a single instruction that does all the work of
1371
   returning from the function. On these machines, give that instruction the
1372
   name "return" (in the machine definition) and do not define the macro
1373
   TARGET_ASM_FUNCTION_EPILOGUE at all.
1374
 
1375
   Do not define a pattern named "return" if you want the
1376
   TARGET_ASM_FUNCTION_EPILOGUE to be used. If you want the target switches to
1377
   control whether return instructions or epilogues are used, define a
1378
   "return" pattern with a validity condition that tests the target switches
1379
   appropriately. If the "return" pattern’s validity condition is false,
1380
   epilogues will be used.
1381
 
1382
   On machines where functions may or may not have frame-pointers, the
1383
   function exit code must vary accordingly. Sometimes the code for these two
1384
   cases is completely different. To determine whether a frame pointer is
1385
   wanted, the macro can refer to the variable frame_pointer_needed. The
1386
   variable’s value will be 1 when compiling a function that needs a frame
1387
   pointer.
1388
 
1389
   Normally, TARGET_ASM_FUNCTION_PROLOGUE and TARGET_ASM_FUNCTION_EPILOGUE
1390
   must treat leaf functions specially. The C variable
1391
   "current_function_is_leaf" is nonzero for such a function. See "Handling
1392
   Leaf Functions" in the "Target Description Macros and Functions" section of
1393
   the GCC internals manual.
1394
 
1395
   On some machines, some functions pop their arguments on exit while others
1396
   leave that for the caller to do. For example, the 68020 when given "-mrtd"
1397
   pops arguments in functions that take a fixed number of arguments.
1398
 
1399
   Your definition of the macro RETURN_POPS_ARGS decides which functions pop
1400
   their own arguments. TARGET_ASM_FUNCTION_EPILOGUE needs to know what was
1401
   decided.  The number of bytes of the current function’s arguments that this
1402
   function should pop is available in "crtl->args.pops_args". See "How Scalar
1403
   Function Values Are Returned" in the "Target Description Macros and
1404
   Functions" section of the GCC internals manual.
1405
 
1406
   @param[in] file  File handle for any generated code.
1407
   @param[in] size  Number of bytes of storage needed for local variables.    */
1408
/* -------------------------------------------------------------------------- */
1409
static void
1410
or32_output_function_epilogue (FILE * file, HOST_WIDE_INT size)
1411
{
1412
  int save_area;
1413
  int gpr_save_area;
1414
  int lr_save_area;
1415
  int fp_save_area;
1416
  int stack_size;
1417
  int regno;
1418
 
1419
  /* If we are doing the epilogue using the "epilogue" pattern in the machine
1420
     description, do nothing more here.
1421
 
1422
     JPB 30-Aug-10: Surely that is not correct. If this option is set, we
1423
     should never even be called! */
1424 399 jeremybenn
  if (TARGET_SCHED_LOGUE)
1425 282 jeremybenn
    return;
1426
 
1427
  /* Work out the frame size */
1428
  stack_size = calculate_stack_size (size, &lr_save_area, &fp_save_area,
1429
                                     &gpr_save_area, &save_area);
1430
 
1431
  /* Restore the return address if necessary */
1432
  if (lr_save_area)
1433
    {
1434
      fprintf (file, "\tl.lwz\tr%d,%d(r%d)\n", LINK_REGNUM,
1435
               OR32_ALIGN (crtl->outgoing_args_size, 4),
1436
               STACK_POINTER_REGNUM);
1437
    }
1438
 
1439
  /* Restore the frame pointer if necessary */
1440
  if (fp_save_area)
1441
    {
1442 399 jeremybenn
      fprintf (file, "\tl.lwz\tr%d,%d(r%d)\n", HARD_FRAME_POINTER_REGNUM,
1443 282 jeremybenn
               OR32_ALIGN (crtl->outgoing_args_size, 4)
1444
               + lr_save_area, STACK_POINTER_REGNUM);
1445
    }
1446
 
1447
  save_area = (OR32_ALIGN (crtl->outgoing_args_size, 4)
1448
               + lr_save_area + fp_save_area);
1449
 
1450
  /* Restore any callee-saved registers */
1451
  for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
1452
    {
1453
      if (df_regs_ever_live_p(regno) && !call_used_regs[regno])
1454
        {
1455
          fprintf (file, "\tl.lwz\tr%d,%d(r%d)\n", regno, save_area,
1456
                   STACK_POINTER_REGNUM);
1457
          save_area += 4;
1458
        }
1459
    }
1460
 
1461
  /* Restore the stack pointer (if necessary) */
1462
  if (stack_size >= 0x8000)
1463
    {
1464
      fprintf (file, "\tl.movhi\tr3,hi(%d)\n", stack_size);
1465
      fprintf (file, "\tl.ori\tr3,r3,lo(%d)\n", stack_size);
1466
 
1467 399 jeremybenn
      fprintf (file, "\tl.jr\tr%d\n", LINK_REGNUM);
1468 282 jeremybenn
 
1469
      fprintf (file, "\tl.add\tr%d,r%d,r3\n", STACK_POINTER_REGNUM,
1470
               STACK_POINTER_REGNUM);
1471
    }
1472
  else if (stack_size > 0)
1473
    {
1474 399 jeremybenn
      fprintf (file, "\tl.jr\tr%d\n", LINK_REGNUM);
1475 282 jeremybenn
 
1476
      fprintf (file, "\tl.addi\tr%d,r%d,%d\n", STACK_POINTER_REGNUM,
1477
               STACK_POINTER_REGNUM, stack_size);
1478
    }
1479
  else
1480
    {
1481 399 jeremybenn
      fprintf (file, "\tl.jr\tr%d\n", LINK_REGNUM);
1482 282 jeremybenn
 
1483
      fprintf (file, "\tl.nop\n");              /* Delay slot */
1484
    }
1485
}       /* or32_output_function_epilogue () */
1486
 
1487
 
1488
/* -------------------------------------------------------------------------- */
1489
/*!Define where a function returns values.
1490
 
1491
   Define this to return an RTX representing the place where a function
1492
   returns or receives a value of data type ret type, a tree node representing
1493
   a data type.  "func" is a tree node representing FUNCTION_DECL or
1494
   FUNCTION_TYPE of a function being called. If "outgoing" is false, the hook
1495
   should compute the register in which the caller will see the return
1496
   value. Otherwise, the hook should return an RTX representing the place
1497
   where a function returns a value.
1498
 
1499
   On many machines, only TYPE_MODE ("ret_type") is relevant. (Actually, on
1500
   most machines, scalar values are returned in the same place regardless of
1501
   mode.) The value of the expression is usually a reg RTX for the hard
1502
   register where the return value is stored. The value can also be a parallel
1503
   RTX, if the return value is in multiple places. See FUNCTION_ARG for an
1504
   explanation of the parallel form. Note that the callee will populate every
1505
   location specified in the parallel, but if the first element of the
1506
   parallel contains the whole return value, callers will use that element as
1507
   the canonical location and ignore the others. The m68k port uses this type
1508
   of parallel to return pointers in both ‘%a0’ (the canonical location) and
1509
   ‘%d0’.
1510
 
1511
   If TARGET_PROMOTE_FUNCTION_RETURN returns true, you must apply the same
1512
   promotion rules specified in PROMOTE_MODE if valtype is a scalar type.
1513
 
1514
   If the precise function being called is known, "func" is a tree node
1515
   (FUNCTION_DECL) for it; otherwise, "func" is a null pointer. This makes it
1516
   possible to use a different value-returning convention for specific
1517
   functions when all their calls are known.
1518
 
1519
   Some target machines have "register windows" so that the register in which
1520
   a function returns its value is not the same as the one in which the caller
1521
   sees the value. For such machines, you should return different RTX
1522
   depending on outgoing.
1523
 
1524
   TARGET_FUNCTION_VALUE is not used for return values with aggregate data
1525
   types, because these are returned in another way. See
1526
   TARGET_STRUCT_VALUE_RTX and related macros.
1527
 
1528
   For the OR32, we can just use the result of LIBCALL_VALUE, since all
1529
   functions return their result in the same place (register rv = r11).
1530
 
1531
   JPB 30-Aug-10: What about 64-bit scalar returns (long long int, double),
1532
                  which also use rvh (=r12)?
1533
 
1534
   @param[in] ret_type  The return type of the function.
1535
   @param[in] func      Tree representing function being called.
1536
   @param[in] outgoing  Non-zero (TRUE) if the result represents where the
1537
                        function places the results, zero (FALSE) if the
1538
                        result represents where the caller sees the result.
1539
 
1540
   @return  A RTX representing where the result can be found.                 */
1541
/* -------------------------------------------------------------------------- */
1542
static rtx
1543
or32_function_value (const_tree  ret_type,
1544
                     const_tree  func ATTRIBUTE_UNUSED,
1545
                     bool        outgoing ATTRIBUTE_UNUSED)
1546
{
1547
  return LIBCALL_VALUE (TYPE_MODE(ret_type));
1548
 
1549
}       /* or32_function_value () */
1550
 
1551
 
1552
/* -------------------------------------------------------------------------- */
1553
/*!Check if a function is suitable for tail call optimization.
1554
 
1555
   True if it is OK to do sibling call optimization for the specified call
1556
   expression "exp". "decl" will be the called function, or NULL if this is an
1557
   indirect call.
1558
 
1559
   It is not uncommon for limitations of calling conventions to prevent tail
1560
   calls to functions outside the current unit of translation, or during PIC
1561
   compilation. The hook is used to enforce these restrictions, as the sibcall
1562
   md pattern can not fail, or fall over to a “normal” call. The criteria for
1563
   successful sibling call optimization may vary greatly between different
1564
   architectures.
1565
 
1566 399 jeremybenn
   For the OR32, we currently allow sibcall optimization whenever
1567
   -foptimize-sibling-calls is enabled.
1568 282 jeremybenn
 
1569
   @param[in] decl  The function for which we may optimize
1570
   @param[in] exp   The call expression which is candidate for optimization.
1571
 
1572
   @return  Non-zero (TRUE) if sibcall optimization is permitted, zero (FALSE)
1573
            otherwise.                                                        */
1574
/* -------------------------------------------------------------------------- */
1575
static bool
1576
or32_function_ok_for_sibcall (tree  decl ATTRIBUTE_UNUSED,
1577
                              tree  exp ATTRIBUTE_UNUSED)
1578
{
1579 414 jeremybenn
  /* Assume up to 31 registers of 4 bytes might be saved.  */
1580
  return or32_redzone >= 31 * 4;
1581 282 jeremybenn
}       /* or32_function_ok_for_sibcall () */
1582
 
1583
 
1584
/* -------------------------------------------------------------------------- */
1585
/*!Should an argument be passed by reference.
1586
 
1587
   This target hook should return true if an argument at the position
1588
   indicated by "cum" should be passed by reference. This predicate is queried
1589
   after target independent reasons for being passed by reference, such as
1590
   TREE_ADDRESSABLE ("type").
1591
 
1592
   If the hook returns TRUE, a copy of that argument is made in memory and a
1593
   pointer to the argument is passed instead of the argument itself. The
1594
   pointer is passed in whatever way is appropriate for passing a pointer to
1595
   that type.
1596
 
1597
   For the OR32, all aggregates and arguments greater than 8 bytes are passed
1598
   this way.
1599
 
1600
   @param[in] cum    Position of argument under consideration.
1601
   @param[in[ mode   Not sure what this relates to.
1602
   @param[in] type   Type of the argument.
1603
   @param[in] named  Not sure what this relates to.
1604
 
1605
   @return  Non-zero (TRUE) if the argument should be passed by reference,
1606
            zero (FALSE) otherwise.                                           */
1607
/* -------------------------------------------------------------------------- */
1608
static bool
1609
or32_pass_by_reference (CUMULATIVE_ARGS   *cum ATTRIBUTE_UNUSED,
1610
                        enum machine_mode  mode ATTRIBUTE_UNUSED,
1611
                        const_tree         type,
1612
                        bool               named ATTRIBUTE_UNUSED)
1613
{
1614
  return (type && (AGGREGATE_TYPE_P (type) || int_size_in_bytes (type) > 8));
1615
 
1616
}       /* or32_pass_by_reference () */
1617
 
1618
 
1619 399 jeremybenn
#if 0
1620 282 jeremybenn
/* -------------------------------------------------------------------------- */
1621
/*!Is a frame pointer required?
1622
 
1623
   This target hook should return TRUE if a function must have and use a frame
1624
   pointer.  This target hook is called in the reload pass. If its return
1625
   value is TRUE the function will have a frame pointer.
1626
 
1627
   This target hook can in principle examine the current function and decide
1628
   according to the facts, but on most machines the constant false or the
1629
   constant true suffices.  Use FALSE when the machine allows code to be
1630
   generated with no frame pointer, and doing so saves some time or space. Use
1631
   TRUE when there is no possible advantage to avoiding a frame pointer.
1632
 
1633
   In certain cases, the compiler does not know how to produce valid code
1634
   without a frame pointer. The compiler recognizes those cases and
1635
   automatically gives the function a frame pointer regardless of what
1636
   TARGET_FRAME_POINTER_REQUIRED returns.  You don’t need to worry about them.
1637
 
1638
   In a function that does not require a frame pointer, the frame pointer
1639
   register can be allocated for ordinary usage, unless you mark it as a fixed
1640
   register. See FIXED_REGISTERS for more information.
1641
 
1642
   Default return value is false.
1643
 
1644
   For the OR32 we do not need the frame pointer, so the default would have
1645
   sufficed.
1646
 
1647
   JPB 30-Aug-10: The version supplied returned TRUE, which is patently the
1648
                  wrong answer. This function really could be eliminated and
1649
                  the default used.
1650
 
1651
   @return  Non-zero (TRUE) if a frame pointer is not required, zero (FALSE)
1652
            otherwise.                                                        */
1653
/* -------------------------------------------------------------------------- */
1654
static bool
1655
or32_frame_pointer_required (void)
1656
{
1657
        return 1;
1658
 
1659
}       /* or32_frame_pointer_required () */
1660 399 jeremybenn
#endif
1661 282 jeremybenn
 
1662 399 jeremybenn
int
1663
or32_initial_elimination_offset(int from, int to)
1664
{
1665
  or32_compute_frame_size (get_frame_size ());
1666 414 jeremybenn
  return ((from == FRAME_POINTER_REGNUM
1667
           ? frame_info.gpr_offset : frame_info.gpr_frame)
1668
          + (to == STACK_POINTER_REGNUM ? frame_info.late_frame : 0));
1669 399 jeremybenn
}
1670 282 jeremybenn
 
1671 399 jeremybenn
 
1672 282 jeremybenn
/* -------------------------------------------------------------------------- */
1673
/*!How many bytes at the beginning of an argument must be put into registers.
1674
 
1675
   This target hook returns the number of bytes at the beginning of an
1676
   argument that must be put in registers. The value must be zero for
1677
   arguments that are passed entirely in registers or that are entirely pushed
1678
   on the stack.
1679
 
1680
   On some machines, certain arguments must be passed partially in registers
1681
   and partially in memory. On these machines, typically the first few words
1682
   of arguments a re passed in registers, and the rest on the stack. If a
1683
   multi-word argument (a double or a structure) crosses that boundary, its
1684
   first few words must be passed in registers and the rest must be
1685
   pushed. This macro tells the compiler when this occurs, and how many bytes
1686
   should go in registers.
1687
 
1688
   FUNCTION_ARG for these arguments should return the first register to be
1689
   used by the caller for this argument; likewise FUNCTION_INCOMING_ARG, for
1690
   the called function.
1691
 
1692
   On the OR32 we never split argumetns between registers and memory.
1693
 
1694
   JPB 30-Aug-10: Is this correct? Surely we should allow this. The ABI spec
1695
                  is incomplete on this point.
1696
 
1697
   @param[in] cum    Position of argument under consideration.
1698
   @param[in[ mode   Not sure what this relates to.
1699
   @param[in] type   Type of the argument.
1700
   @param[in] named  Not sure what this relates to.
1701
 
1702
   @return  The number of bytes of the argument to go into registers          */
1703
/* -------------------------------------------------------------------------- */
1704
static int
1705
or32_arg_partial_bytes (CUMULATIVE_ARGS   *cum ATTRIBUTE_UNUSED,
1706
                        enum machine_mode  mode ATTRIBUTE_UNUSED,
1707
                        tree               type ATTRIBUTE_UNUSED,
1708
                        bool               named ATTRIBUTE_UNUSED)
1709
{
1710
  return 0;
1711
 
1712
}       /* or32_arg_partial_bytes () */
1713
 
1714
 
1715
/* -------------------------------------------------------------------------- */
1716
/*!Promote the mode of a function's arguments/return value.
1717
 
1718
   Like PROMOTE_MODE, but it is applied to outgoing function arguments or
1719
   function return values. The target hook should return the new mode and
1720
   possibly change "*punsignedp" if the promotion should change
1721
   signedness. This function is called only for scalar or pointer types.
1722
 
1723
   "for_return" allows to distinguish the promotion of arguments and return
1724
   values. If it is 1, a return value is being promoted and
1725
   TARGET_FUNCTION_VALUE must perform the same promotions done here. If it is
1726
   2, the returned mode should be that of the register in which an incoming
1727
   parameter is copied, or the outgoing result is computed; then the hook
1728
   should return the same mode as PROMOTE_MODE, though the signedness may be
1729
   different.
1730
 
1731
   The default is to not promote arguments and return values. You can also
1732
   define the hook to "default_promote_function_mode_always_promote" if you
1733
   would like to apply the same rules given by PROMOTE_MODE.
1734
 
1735
   For the OR32, if the size of the mode is integral and less than 4, we
1736
   promote to SImode, otherwise we return the mode we are supplied.
1737
 
1738
   @param[in]  type        Not sure. Type of the argument?
1739
   @param[in]  mode        The mode of argument/return value to consider.
1740
   @param[out] punsignedp  Signedness of the value.
1741
   @param[in]  fntype      Not sure. Type of the function?
1742
   @param[in]  for_return  1 if a return value, 2 if an incoming value.
1743
 
1744
   @return  The new mode.                                                     */
1745
/* -------------------------------------------------------------------------- */
1746
static enum machine_mode
1747
or32_promote_function_mode (const_tree         type ATTRIBUTE_UNUSED,
1748
                            enum machine_mode  mode,
1749
                            int               *punsignedp ATTRIBUTE_UNUSED,
1750
                            const_tree         fntype ATTRIBUTE_UNUSED,
1751
                            int                for_return ATTRIBUTE_UNUSED)
1752
{
1753
  return (   (GET_MODE_CLASS (mode) == MODE_INT)
1754
          && (GET_MODE_SIZE (mode) < 4)) ? SImode : mode;
1755
 
1756
}       /* or32_promote_function_mode () */
1757
 
1758
 
1759
/* -------------------------------------------------------------------------- */
1760
/*!Is this a legitimate address?
1761
 
1762
  A function that returns whether x (an RTX) is a legitimate memory address on
1763
  the target machine for a memory operand of mode mode.
1764
 
1765
  Legitimate addresses are defined in two variants: a strict variant and a
1766
  non-strict one.  The strict parameter chooses which variant is desired by
1767
  the caller.
1768
 
1769
  The strict variant is used in the reload pass. It must be defined so that
1770
  any pseudo- register that has not been allocated a hard register is
1771
  considered a memory reference.  This is because in contexts where some kind
1772
  of register is required, a pseudo-register with no hard register must be
1773
  rejected. For non-hard registers, the strict variant should look up the
1774
  reg_renumber array; it should then proceed using the hard register number in
1775
  the array, or treat the pseudo as a memory reference if the array holds -1.
1776
 
1777
  The non-strict variant is used in other passes. It must be defined to accept
1778
  all pseudo-registers in every context where some kind of register is
1779
  required.
1780
 
1781
  Normally, constant addresses which are the sum of a symbol_ref and an
1782
  integer are stored inside a const RTX to mark them as constant. Therefore,
1783
  there is no need to recognize such sums specifically as legitimate
1784
  addresses. Normally you would simply recognize any const as legitimate.
1785
 
1786
  Usually PRINT_OPERAND_ADDRESS is not prepared to handle constant sums that
1787
  are not marked with const. It assumes that a naked plus indicates
1788
  indexing. If so, then you must reject such naked constant sums as
1789
  illegitimate addresses, so that none of them will be given to
1790
  PRINT_OPERAND_ADDRESS.
1791
 
1792
  On some machines, whether a symbolic address is legitimate depends on the
1793
  section that the address refers to. On these machines, define the target
1794
  hook TARGET_ENCODE_ SECTION_INFO to store the information into the
1795
  symbol_ref, and then check for it here. When you see a const, you will have
1796
  to look inside it to find the symbol_ref in order to determine the
1797
  section. See the internals manual section on "Assembler Format" for more
1798
  info.
1799
 
1800
  Some ports are still using a deprecated legacy substitute for this hook, the
1801
  GO_IF_LEGITIMATE_ADDRESS macro. This macro has this syntax:
1802
 
1803
    #define GO_IF_LEGITIMATE_ADDRESS (mode, x, label )
1804
 
1805
  and should goto label if the address x is a valid address on the target
1806
  machine for a memory operand of mode mode. Whether the strict or non-strict
1807
  variants are desired is defined by the REG_OK_STRICT macro introduced
1808
  earlier in this section. Using the hook is usually simpler because it limits
1809
  the number of files that are recompiled when changes are made.
1810
 
1811
   The OR32 only has a single addressing mode, which is a base register with
1812
   16-bit displacement. We can accept just 16-bit constants as addresses (they
1813
   can use r0 as base address, and we can accept plain registers as addresses
1814
   (they can use a displacement of zero).
1815
 
1816
   @param[in] mode    The mode of the address
1817
   @param[in] x       The address (RTX)
1818
   @param[in] strict  Non-zero (TRUE) if we are in "strict" mode, zero (FALSE)
1819
                      otherwise.
1820
 
1821
   @return  Non-zero (TRUE) if this is a legitimate address, zero (FALSE)
1822
            otherwise.                                                        */
1823
/* -------------------------------------------------------------------------- */
1824
static bool
1825 378 julius
or32_legitimate_address_p (enum machine_mode  mode ATTRIBUTE_UNUSED,
1826 282 jeremybenn
                           rtx                x,
1827
                           bool               strict)
1828
{
1829
  /* You might think 16-bit constants are suitable. They can be built into
1830
     addresses using r0 as the base. However this seems to lead to defective
1831
     code. So for now this is a placeholder, and this code is not used.
1832
 
1833
     if (or32_legitimate_displacement_p (mode, x))
1834
       {
1835
         return  1;
1836
       }
1837
  */
1838
 
1839
  /* Addresses consisting of a register and 16-bit displacement are also
1840
     suitable. We need the mode, since for double words, we had better be
1841
     able to address the full 8 bytes. */
1842
  if (GET_CODE(x) == PLUS)
1843
    {
1844
      rtx reg = XEXP(x,0);
1845
 
1846
      /* If valid register... */
1847
      if ((GET_CODE(reg) == REG)
1848 377 julius
          && or32_regnum_ok_for_base_p (REGNO (reg), strict))
1849 282 jeremybenn
        {
1850
          rtx offset = XEXP(x,1);
1851
 
1852
          /* ...and valid offset */
1853
          if (or32_legitimate_displacement_p (mode, offset))
1854
            {
1855
              return 1;
1856
            }
1857
        }
1858
    }
1859
 
1860
  /* Addresses consisting of just a register are OK. They can be built into
1861
     addresses using an offset of zero (and an offset of four if double
1862
     word). */
1863 378 julius
  if (GET_CODE(x) == REG
1864
    && or32_regnum_ok_for_base_p(REGNO(x),strict)) {
1865 282 jeremybenn
      return 1;
1866 378 julius
  }
1867 282 jeremybenn
 
1868
  return 0;
1869 378 julius
}
1870 282 jeremybenn
 
1871
/* -------------------------------------------------------------------------- */
1872 332 jeremybenn
/*!Initialize a trampoline for nested functions.
1873
 
1874
   A nested function is defined by *two* pieces of information, the address of
1875
   the function (like any other function) and a pointer to the frame of the
1876
   enclosing function. The latter is required to allow the nested function to
1877
   access local variables in the enclosing function's frame.
1878
 
1879
   This represents a problem, since a function in C is represented as an
1880
   address that can be held in a single variable as a pointer. Requiring two
1881
   pointers will not fit.
1882
 
1883
   The solution is documented in "Lexical Closures for C++" by Thomas
1884
   M. Breuel (USENIX C++ Conference Proceedings, October 17-21, 1988). The
1885
   nested function is represented by a small block of code and data on the
1886
   enclosing function's stack frame, which sets up a pointer to the enclosing
1887
   function's stack frame (the static chain pointer) in a register defined by
1888
   the ABI, and then jumps to the code of the function proper.
1889
 
1890
   The function can be represented as a single pointer to this block of code,
1891
   known as a trampoline, which when called generates both pointers
1892
   needed. The nested function (which knows it is a nested function at compile
1893
   time) can then generate code to access the enclosing frame via the static
1894
   chain register.
1895
 
1896
   There is a catch that the trampoline is set up as data, but executed as
1897
   instructions. The former will be via the data cache, the latter via the
1898
   instruction cache. There is a risk that a later trampoline will not be seen
1899
   by the instruction cache, so the wrong code will be executed. So the
1900
   instruction cache should be flushed for the trampoline address range.
1901
 
1902
   This hook is called to initialize a trampoline. "m_tramp" is an RTX for the
1903
   memory block for the trampoline; "fndecl" is the FUNCTION_DECL for the
1904
   nested function; "static_chain" is an RTX for the static chain value that
1905
   should be passed to the function when it is called.
1906
 
1907
   If the target defines TARGET_ASM_TRAMPOLINE_TEMPLATE, then the first thing
1908
   this hook should do is emit a block move into "m_tramp" from the memory
1909
   block returned by assemble_trampoline_template. Note that the block move
1910
   need only cover the constant parts of the trampoline. If the target
1911
   isolates the variable parts of the trampoline to the end, not all
1912
   TRAMPOLINE_SIZE bytes need be copied.
1913
 
1914
   If the target requires any other actions, such as flushing caches or
1915
   enabling stack execution, these actions should be performed after
1916
   initializing the trampoline proper.
1917
 
1918
   For the OR32, no static chain register is used. We choose to use the return
1919 399 jeremybenn
   value (rv) register. The code is based on that for MIPS.
1920
   The trampoline code is:
1921 332 jeremybenn
 
1922 399 jeremybenn
              l.movhi r11,hi(end_addr)
1923
              l.ori   r11,lo(end_addr)
1924
              l.lwz   r13,4(r11)
1925 332 jeremybenn
              l.jr    r13
1926 399 jeremybenn
              l.lwz   r11,0(r11)
1927 332 jeremybenn
      end_addr:
1928
              .word   <static chain>
1929
              .word   <nested_function>
1930
 
1931
   @note For the OR32 we need to flush the instruction cache, which is a
1932
         privileged operation. Needs fixing.
1933
 
1934
   @param[in] m_tramp      The lowest address of the trampoline on the stack.
1935
   @param[in] fndecl       Declaration of the enclosing function.
1936
   @param[in] chain_value  Static chain pointer to pass to the nested
1937
                           function.                                          */
1938
/* -------------------------------------------------------------------------- */
1939
static void
1940
or32_trampoline_init (rtx   m_tramp,
1941
                      tree  fndecl,
1942
                      rtx   chain_value)
1943
{
1944
  rtx  addr;                            /* Start address of the trampoline */
1945
  rtx  end_addr;                        /* End address of the code block */
1946
 
1947
  rtx  high;                            /* RTX for the high part of end_addr */
1948
  rtx  low;                             /* RTX for the low part of end_addr */
1949
  rtx  opcode;                          /* RTX for generated opcodes */
1950
  rtx  mem;                             /* RTX for trampoline memory */
1951
 
1952
  rtx trampoline[5];                    /* The trampoline code */
1953
 
1954
  unsigned int  i;                      /* Index into trampoline */
1955
  unsigned int  j;                      /* General counter */
1956
 
1957
  HOST_WIDE_INT  end_addr_offset;         /* Offset to end of code */
1958
  HOST_WIDE_INT  static_chain_offset;     /* Offset to stack chain word */
1959
  HOST_WIDE_INT  target_function_offset;  /* Offset to func address word */
1960
 
1961
  /* Work out the offsets of the pointers from the start of the trampoline
1962
     code.  */
1963
  end_addr_offset        = or32_trampoline_code_size ();
1964
  static_chain_offset    = end_addr_offset;
1965
  target_function_offset = static_chain_offset + GET_MODE_SIZE (ptr_mode);
1966
 
1967
  /* Get pointers in registers to the beginning and end of the code block.  */
1968
  addr     = force_reg (Pmode, XEXP (m_tramp, 0));
1969
  end_addr = or32_force_binary (Pmode, PLUS, addr, GEN_INT (end_addr_offset));
1970
 
1971
  /* Build up the code in TRAMPOLINE.
1972
 
1973 399 jeremybenn
              l.movhi r11,hi(end_addr)
1974
              l.ori   r11,lo(end_addr)
1975
              l.lwz   r13,4(r11)
1976 332 jeremybenn
              l.jr    r13
1977 399 jeremybenn
              l.lwz   r11,0(r11)
1978 332 jeremybenn
       end_addr:
1979
  */
1980
 
1981
  i = 0;
1982
 
1983
  /* Break out the high and low parts of the end_addr */
1984
  high = expand_simple_binop (SImode, LSHIFTRT, end_addr, GEN_INT (16),
1985
                              NULL, false, OPTAB_WIDEN);
1986
  low  = convert_to_mode (SImode, gen_lowpart (HImode, end_addr), true);
1987
 
1988
  /* Emit the l.movhi, adding an operation to OR in the high bits from the
1989
     RTX. */
1990 399 jeremybenn
  opcode = gen_int_mode (OR32_MOVHI (11, 0), SImode);
1991 332 jeremybenn
  trampoline[i++] = expand_simple_binop (SImode, IOR, opcode, high, NULL,
1992
                                         false, OPTAB_WIDEN);
1993
 
1994
  /* Emit the l.ori, adding an operations to OR in the low bits from the
1995
     RTX. */
1996 399 jeremybenn
  opcode = gen_int_mode (OR32_ORI (11, 11, 0), SImode);
1997 332 jeremybenn
  trampoline[i++] = expand_simple_binop (SImode, IOR, opcode, low, NULL,
1998
                                         false, OPTAB_WIDEN);
1999
 
2000
  /* Emit the l.lwz of the function address. 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 (13, 11, target_function_offset - end_addr_offset),
2004 332 jeremybenn
                  SImode);
2005
 
2006
  /* Emit the l.jr of the function. No bits to OR in here, so we can do the
2007
     opcode directly. */
2008
  trampoline[i++] = gen_int_mode (OR32_JR (13), SImode);
2009
 
2010
  /* Emit the l.lwz of the static chain. No bits to OR in here, so we can
2011
     do the opcode directly. */
2012
  trampoline[i++] =
2013 399 jeremybenn
    gen_int_mode (OR32_LWZ (STATIC_CHAIN_REGNUM, 11,
2014 332 jeremybenn
                            static_chain_offset - end_addr_offset), SImode);
2015
 
2016
  /* Copy the trampoline code.  Leave any padding uninitialized.  */
2017
  for (j = 0; j < i; j++)
2018
    {
2019
      mem = adjust_address (m_tramp, SImode, j * GET_MODE_SIZE (SImode));
2020
      or32_emit_move (mem, trampoline[j]);
2021
    }
2022
 
2023
  /* Set up the static chain pointer field.  */
2024
  mem = adjust_address (m_tramp, ptr_mode, static_chain_offset);
2025
  or32_emit_move (mem, chain_value);
2026
 
2027
  /* Set up the target function field.  */
2028
  mem = adjust_address (m_tramp, ptr_mode, target_function_offset);
2029
  or32_emit_move (mem, XEXP (DECL_RTL (fndecl), 0));
2030
 
2031
  /* Flushing the trampoline from the instruction cache needs to be done
2032
     here. */
2033
 
2034
}       /* or32_trampoline_init () */
2035
 
2036
 
2037
/* -------------------------------------------------------------------------- */
2038 282 jeremybenn
/*!Provide support for DW_AT_calling_convention
2039
 
2040
   Define this to enable the dwarf attribute DW_AT_calling_convention to be
2041
   emitted for each function. Instead of an integer return the enum value for
2042
   the DW_CC_ tag.
2043
 
2044
   To support optional call frame debugging information, you must also define
2045
   INCOMING_RETURN_ADDR_RTX and either set RTX_FRAME_RELATED_P on the prologue
2046
   insns if you use RTL for the prologue, or call "dwarf2out_def_cfa" and
2047
   "dwarf2out_reg_save" as appropriate from TARGET_ASM_FUNCTION_PROLOGUE if
2048
   you don’t.
2049
 
2050
   For the OR32, it should be sufficient to return DW_CC_normal in all cases.
2051
 
2052
   @param[in] function  The function requiring debug information
2053
 
2054
   @return  The enum of the DW_CC tag.                                        */
2055
/* -------------------------------------------------------------------------- */
2056
static int
2057
or32_dwarf_calling_convention (const_tree  function ATTRIBUTE_UNUSED)
2058
{
2059
  return  DW_CC_normal;
2060
 
2061
}       /* or32_dwarf_calling_convention () */
2062
 
2063 399 jeremybenn
/* If DELTA doesn't fit into a 16 bit signed number, emit instructions to
2064
   add the highpart to DST; return the signed-16-bit lowpart of DELTA.
2065
   TMP_REGNO is a register that may be used to load a constant.  */
2066
static HOST_WIDE_INT
2067
or32_output_highadd (FILE *file,
2068
                     const char *dst, int tmp_regno, HOST_WIDE_INT delta)
2069
{
2070
  if (delta < -32768 || delta > 32767)
2071
    {
2072
      if (delta >= -65536 && delta < 65534)
2073
        {
2074
          asm_fprintf (file, "\tl.addi\t%s,%s,%d\n",
2075
                       dst, dst, (int) (delta + 1) >> 1);
2076
          delta >>= 1;
2077
        }
2078
      else
2079
        {
2080
          const char *tmp = reg_names[tmp_regno];
2081
          HOST_WIDE_INT high = (delta + 0x8000) >> 16;
2082 282 jeremybenn
 
2083 399 jeremybenn
          gcc_assert (call_used_regs[tmp_regno]);
2084
          asm_fprintf (file, "\tl.movhi\t%s,%d\n" "\tl.add\t%s,%s,%s\n",
2085
                 tmp, (int) high,
2086
                 dst, dst, tmp);
2087
          delta -= high << 16;
2088
        }
2089
    }
2090
  return delta;
2091
}
2092
 
2093
/* Output a tailcall to FUNCTION.  The caller will fill in the delay slot.  */
2094 402 jeremybenn
static void
2095 399 jeremybenn
or32_output_tailcall (FILE *file, tree function)
2096
{
2097
  /* We'll need to add more code if we want to fully support PIC.  */
2098
  gcc_assert (!flag_pic || (*targetm.binds_local_p) (function));
2099
 
2100
  fputs ("\tl.j\t", file);
2101
  assemble_name (file, XSTR (XEXP (DECL_RTL (function), 0), 0));
2102
  fputc ('\n', file);
2103
}
2104
 
2105
static void
2106
or32_output_mi_thunk (FILE *file, tree thunk ATTRIBUTE_UNUSED,
2107
                      HOST_WIDE_INT delta, HOST_WIDE_INT vcall_offset,
2108
                      tree function)
2109
{
2110
  int this_regno
2111
    = aggregate_value_p (TREE_TYPE (TREE_TYPE (function)), function) ? 4 : 3;
2112
  const char *this_name = reg_names[this_regno];
2113
 
2114
 
2115
  delta = or32_output_highadd (file, this_name, PROLOGUE_TMP, delta);
2116
  if (!vcall_offset)
2117
    or32_output_tailcall (file, function);
2118
  if (delta || !vcall_offset)
2119
    asm_fprintf (file, "\tl.addi\t%s,%s,%d\n",
2120
                 this_name, this_name, (int) delta);
2121
 
2122
  /* If needed, add *(*THIS + VCALL_OFFSET) to THIS.  */
2123
  if (vcall_offset != 0)
2124
    {
2125
      const char *tmp_name = reg_names[PROLOGUE_TMP];
2126
 
2127
      /* l.lwz tmp,0(this)           --> tmp = *this
2128
         l.lwz tmp,vcall_offset(tmp) --> tmp = *(*this + vcall_offset)
2129
         add this,this,tmp           --> this += *(*this + vcall_offset) */
2130
 
2131
      asm_fprintf (file, "\tl.lwz\t%s,0(%s)\n",
2132
                   tmp_name, this_name);
2133
      vcall_offset = or32_output_highadd (file, tmp_name,
2134
                                          STATIC_CHAIN_REGNUM, vcall_offset);
2135
      asm_fprintf (file, "\tl.lwz\t%s,%d(%s)\n",
2136
                   tmp_name, (int) vcall_offset, tmp_name);
2137
      or32_output_tailcall (file, function);
2138
      asm_fprintf (file, "\tl.add\t%s,%s,%s\n", this_name, this_name, tmp_name);
2139
    }
2140
}
2141
 
2142 452 jeremybenn
static bool
2143
or32_handle_option (size_t code, const char *arg ATTRIBUTE_UNUSED,
2144
                    int value ATTRIBUTE_UNUSED)
2145
{
2146
  switch (code)
2147
    {
2148
    case OPT_mnewlib:
2149
      or32_libc = or32_libc_newlib;
2150
      return true;
2151
    case OPT_muclibc:
2152
      or32_libc = or32_libc_uclibc;
2153
      return true;
2154
    case OPT_mglibc:
2155
      or32_libc = or32_libc_glibc;
2156
      return false;
2157
    default:
2158
      return true;
2159
    }
2160
}
2161 399 jeremybenn
 
2162 452 jeremybenn
 
2163 282 jeremybenn
/* ========================================================================== */
2164
/* Target hook initialization.
2165
 
2166
   In most cases these use the static functions declared above. They have
2167
   defaults, so must be undefined first, before being redefined.
2168
 
2169 333 jeremybenn
   The description of what they do is found with the function above, unless it
2170
   is a standard function or a constant, in which case it is defined here (as
2171
   with TARGET_ASM_NAMED_SECTION).
2172 282 jeremybenn
 
2173
   The final declaration is of the global "targetm" structure. */
2174
 
2175
 
2176 333 jeremybenn
/* Default target_flags if no switches specified. */
2177
#undef  TARGET_DEFAULT_TARGET_FLAGS
2178 399 jeremybenn
#define TARGET_DEFAULT_TARGET_FLAGS (MASK_HARD_MUL | MASK_SCHED_LOGUE)
2179 333 jeremybenn
 
2180 452 jeremybenn
#undef TARGET_HANDLE_OPTION
2181
#define TARGET_HANDLE_OPTION or32_handle_option
2182
 
2183 282 jeremybenn
/* Output assembly directives to switch to section name. The section should
2184
   have attributes as specified by flags, which is a bit mask of the SECTION_*
2185
   flags defined in ‘output.h’. If decl is non-NULL, it is the VAR_DECL or
2186
   FUNCTION_DECL with which this section is associated.
2187
 
2188
   For OR32, we use the default ELF sectioning. */
2189 332 jeremybenn
#undef  TARGET_ASM_NAMED_SECTION
2190 282 jeremybenn
#define TARGET_ASM_NAMED_SECTION  default_elf_asm_named_section
2191
 
2192 332 jeremybenn
#undef  TARGET_ASM_FUNCTION_PROLOGUE
2193 282 jeremybenn
#define TARGET_ASM_FUNCTION_PROLOGUE or32_output_function_prologue
2194
 
2195 332 jeremybenn
#undef  TARGET_ASM_FUNCTION_EPILOGUE
2196 282 jeremybenn
#define TARGET_ASM_FUNCTION_EPILOGUE or32_output_function_epilogue
2197
 
2198 332 jeremybenn
#undef  TARGET_FUNCTION_VALUE
2199 282 jeremybenn
#define TARGET_FUNCTION_VALUE or32_function_value
2200
 
2201 332 jeremybenn
#undef  TARGET_FUNCTION_OK_FOR_SIBCALL
2202 282 jeremybenn
#define TARGET_FUNCTION_OK_FOR_SIBCALL or32_function_ok_for_sibcall
2203
 
2204 332 jeremybenn
#undef  TARGET_PASS_BY_REFERENCE
2205 282 jeremybenn
#define TARGET_PASS_BY_REFERENCE or32_pass_by_reference
2206
 
2207 332 jeremybenn
#undef  TARGET_ARG_PARTIAL_BYTES
2208 282 jeremybenn
#define TARGET_ARG_PARTIAL_BYTES or32_arg_partial_bytes
2209
 
2210
/* This target hook returns TRUE if an argument declared in a prototype as an
2211
   integral type smaller than int should actually be passed as an int. In
2212
   addition to avoiding errors in certain cases of mismatch, it also makes for
2213
   better code on certain machines.
2214
 
2215
   The default is to not promote prototypes.
2216
 
2217
   For the OR32 we do require this, so use a utility hook, which always
2218
   returns TRUE. */
2219 332 jeremybenn
#undef  TARGET_PROMOTE_PROTOTYPES
2220 282 jeremybenn
#define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
2221
 
2222 332 jeremybenn
#undef  TARGET_PROMOTE_FUNCTION_MODE
2223 282 jeremybenn
#define TARGET_PROMOTE_FUNCTION_MODE or32_promote_function_mode
2224
 
2225 332 jeremybenn
#undef  TARGET_LEGITIMATE_ADDRESS_P
2226 282 jeremybenn
#define TARGET_LEGITIMATE_ADDRESS_P  or32_legitimate_address_p
2227
 
2228 332 jeremybenn
#undef  TARGET_TRAMPOLINE_INIT
2229
#define TARGET_TRAMPOLINE_INIT  or32_trampoline_init
2230
 
2231 282 jeremybenn
#undef TARGET_DWARF_CALLING_CONVENTION
2232
#define TARGET_DWARF_CALLING_CONVENTION  or32_dwarf_calling_convention
2233
 
2234 399 jeremybenn
#undef TARGET_ASM_OUTPUT_MI_THUNK
2235
#define TARGET_ASM_OUTPUT_MI_THUNK or32_output_mi_thunk
2236
 
2237
#undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
2238
#define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_const_tree_hwi_hwi_const_tree_true
2239
 
2240 444 jeremybenn
/* uClibc has some instances where (non-coforming to ISO C) a non-varargs
2241
   prototype is in scope when calling that function which is implemented
2242
   as varargs.  We want this to work at least where none of the anonymous
2243
   arguments are used.  I.e. we want the last named argument to be known
2244
   as named so it can be passed in a register, varars funtion or not.  */
2245
#undef TARGET_STRICT_ARGUMENT_NAMING
2246
#define TARGET_STRICT_ARGUMENT_NAMING hook_bool_CUMULATIVE_ARGS_true
2247
 
2248 282 jeremybenn
/* Trampoline stubs are yet to be written. */
2249
/* #define TARGET_ASM_TRAMPOLINE_TEMPLATE */
2250
/* #define TARGET_TRAMPOLINE_INIT */
2251
 
2252
/* Initialize the GCC target structure.  */
2253
struct gcc_target targetm = TARGET_INITIALIZER;
2254 399 jeremybenn
 
2255
/* Lay out structs with increased alignment so that they can be accessed
2256
   more efficiently.  But don't increase the size of one or two byte
2257
   structs.  */
2258
int
2259
or32_struct_alignment (tree t)
2260
{
2261
  unsigned HOST_WIDE_INT total = 0;
2262 402 jeremybenn
  int default_align_fields = 0;
2263
  int special_align_fields = 0;
2264 399 jeremybenn
  tree field;
2265
  unsigned max_align
2266
    = maximum_field_alignment ? maximum_field_alignment : BIGGEST_ALIGNMENT;
2267
  bool struct_p;
2268
 
2269
  switch (TREE_CODE (t))
2270
    {
2271
    case RECORD_TYPE:
2272
      struct_p = true; break;
2273
    case UNION_TYPE: case QUAL_UNION_TYPE:
2274
      struct_p = false; break;
2275
    default: gcc_unreachable ();
2276
    }
2277
  /* Skip all non field decls */
2278
  for (field = TYPE_FIELDS (t); field; field = TREE_CHAIN (field))
2279
    {
2280
      unsigned HOST_WIDE_INT field_size;
2281
 
2282
      if (TREE_CODE (field) != FIELD_DECL)
2283
        continue;
2284 402 jeremybenn
      /* If this is a field in a non-qualified union, or the sole field in
2285
         a struct, and the alignment was set by the user, don't change the
2286
         alignment.
2287
         If the field is a struct/union in a non-qualified union, we already
2288
         had sufficient opportunity to pad it - if we didn't, that'd be
2289
         because the alignment was set as above.
2290
         Likewise if the field is a struct/union and the sole field in a
2291
         struct.  */
2292
      if (DECL_USER_ALIGN (field)
2293
          || TYPE_USER_ALIGN (TREE_TYPE (field))
2294
          || TREE_CODE (TREE_TYPE (field)) == UNION_TYPE
2295
          || TREE_CODE (TREE_TYPE (field)) == QUAL_UNION_TYPE
2296
          || TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE)
2297
        {
2298
          if (TREE_CODE (t) == UNION_TYPE)
2299
            return 0;
2300
          special_align_fields++;
2301
        }
2302
      else if (DECL_PACKED (field))
2303
        special_align_fields++;
2304
      else
2305
        default_align_fields++;
2306 399 jeremybenn
      if (!host_integerp (DECL_SIZE (field), 1))
2307 402 jeremybenn
        field_size = max_align;
2308
      else
2309
        field_size = tree_low_cst (DECL_SIZE (field), 1);
2310 399 jeremybenn
      if (field_size >= BIGGEST_ALIGNMENT)
2311 402 jeremybenn
        total = max_align;
2312 399 jeremybenn
      if (struct_p)
2313
        total += field_size;
2314
      else
2315
        total = MAX (total, field_size);
2316
    }
2317
 
2318 402 jeremybenn
  if (!default_align_fields
2319
      && (TREE_CODE (t) != RECORD_TYPE || special_align_fields <= 1))
2320
    return 0;
2321 399 jeremybenn
  return total < max_align ? (1U << ceil_log2 (total)) : max_align;
2322
}
2323
 
2324
/* Increase the alignment of objects so that they are easier to copy.
2325
   Note that this can cause more struct copies to be inlined, so code
2326
   size might increase, but so should perfromance.  */
2327
int
2328
or32_data_alignment (tree t, int align)
2329
{
2330
  if (align < FASTEST_ALIGNMENT && TREE_CODE (t) == ARRAY_TYPE)
2331
    {
2332
      int size = int_size_in_bytes (t);
2333
 
2334
      return (size > 0 && size < FASTEST_ALIGNMENT / BITS_PER_UNIT
2335
              ? (1 << floor_log2 (size)) * BITS_PER_UNIT
2336
              : FASTEST_ALIGNMENT);
2337
    }
2338
  return align;
2339
}

powered by: WebSVN 2.1.0

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