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 378

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

powered by: WebSVN 2.1.0

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