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

Subversion Repositories openrisc_me

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

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

powered by: WebSVN 2.1.0

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