]> gcc.gnu.org Git - gcc.git/blame - gcc/config/sh/sh.c
(find_barrier): Always use get_attr_length to compute length of instructions.
[gcc.git] / gcc / config / sh / sh.c
CommitLineData
16bea517 1/* Output routines for GCC for Hitachi Super-H.
8aa2a305 2 Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
bc45ade3 3
c15c9075
RK
4This file is part of GNU CC.
5
6GNU CC is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU CC is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU CC; see the file COPYING. If not, write to
18the Free Software Foundation, 59 Temple Place - Suite 330,
19Boston, MA 02111-1307, USA. */
bc45ade3 20
8aa2a305
JW
21/* Contributed by Steve Chamberlain (sac@cygnus.com).
22 Improved by Jim Wilson (wilson@cygnus.com). */
bc45ade3 23
bc45ade3 24#include "config.h"
8aa2a305
JW
25
26#include <stdio.h>
27
bc45ade3 28#include "rtl.h"
bc45ade3 29#include "tree.h"
bc45ade3 30#include "flags.h"
8aa2a305 31#include "insn-flags.h"
bc45ade3 32#include "expr.h"
8aa2a305
JW
33#include "regs.h"
34#include "hard-reg-set.h"
35#include "output.h"
bc45ade3 36
00f8ff66
SC
37#define MSW (TARGET_LITTLE_ENDIAN ? 1 : 0)
38#define LSW (TARGET_LITTLE_ENDIAN ? 0 : 1)
39
20b04867 40/* ??? The pragma interrupt support will not work for SH3. */
8aa2a305
JW
41/* This is set by #pragma interrupt and #pragma trapa, and causes gcc to
42 output code for the next function appropriate for an interrupt handler. */
0d7e008e 43int pragma_interrupt;
bc45ade3 44
8aa2a305
JW
45/* This is set by #pragma trapa, and is similar to the above, except that
46 the compiler doesn't emit code to preserve all registers. */
47static int pragma_trapa;
48
49/* This is used for communication between SETUP_INCOMING_VARARGS and
50 sh_expand_prologue. */
bc45ade3 51int current_function_anonymous_args;
16bea517 52
8aa2a305
JW
53/* Global variables from toplev.c and final.c that are used within, but
54 not declared in any header file. */
b9654711 55extern char *version_string;
8aa2a305 56extern int *insn_addresses;
00f8ff66 57
bc45ade3
SC
58/* Global variables for machine-dependent things. */
59
16bea517
JW
60/* Which cpu are we scheduling for. */
61enum processor_type sh_cpu;
62
bc45ade3 63/* Saved operands from the last compare to use when we generate an scc
16bea517 64 or bcc insn. */
bc45ade3
SC
65
66rtx sh_compare_op0;
67rtx sh_compare_op1;
68
69/* Provides the class number of the smallest class containing
16bea517 70 reg number. */
bc45ade3
SC
71
72int regno_reg_class[FIRST_PSEUDO_REGISTER] =
73{
8e87e161 74 R0_REGS, GENERAL_REGS, GENERAL_REGS, GENERAL_REGS,
bc45ade3
SC
75 GENERAL_REGS, GENERAL_REGS, GENERAL_REGS, GENERAL_REGS,
76 GENERAL_REGS, GENERAL_REGS, GENERAL_REGS, GENERAL_REGS,
77 GENERAL_REGS, GENERAL_REGS, GENERAL_REGS, GENERAL_REGS,
8e87e161
SC
78 GENERAL_REGS, PR_REGS, T_REGS, NO_REGS,
79 MAC_REGS, MAC_REGS,
bc45ade3
SC
80};
81
82/* Provide reg_class from a letter such as appears in the machine
16bea517 83 description. */
bc45ade3
SC
84
85enum reg_class reg_class_from_letter[] =
86{
87 /* a */ NO_REGS, /* b */ NO_REGS, /* c */ NO_REGS, /* d */ NO_REGS,
88 /* e */ NO_REGS, /* f */ NO_REGS, /* g */ NO_REGS, /* h */ NO_REGS,
89 /* i */ NO_REGS, /* j */ NO_REGS, /* k */ NO_REGS, /* l */ PR_REGS,
90 /* m */ NO_REGS, /* n */ NO_REGS, /* o */ NO_REGS, /* p */ NO_REGS,
91 /* q */ NO_REGS, /* r */ NO_REGS, /* s */ NO_REGS, /* t */ T_REGS,
92 /* u */ NO_REGS, /* v */ NO_REGS, /* w */ NO_REGS, /* x */ MAC_REGS,
93 /* y */ NO_REGS, /* z */ R0_REGS
94};
b9654711 95\f
16bea517 96/* Print the operand address in x to the stream. */
bc45ade3
SC
97
98void
99print_operand_address (stream, x)
100 FILE *stream;
101 rtx x;
102{
103 switch (GET_CODE (x))
104 {
105 case REG:
106 fprintf (stream, "@%s", reg_names[REGNO (x)]);
107 break;
8aa2a305 108
bc45ade3
SC
109 case PLUS:
110 {
111 rtx base = XEXP (x, 0);
112 rtx index = XEXP (x, 1);
113
bc45ade3
SC
114 switch (GET_CODE (index))
115 {
116 case CONST_INT:
8aa2a305 117 fprintf (stream, "@(%d,%s)", INTVAL (index),
bc45ade3
SC
118 reg_names[REGNO (base)]);
119 break;
120
121 case REG:
b9654711
SC
122 fprintf (stream, "@(r0,%s)",
123 reg_names[MAX (REGNO (base), REGNO (index))]);
bc45ade3
SC
124 break;
125
126 default:
b9654711 127 debug_rtx (x);
bc45ade3
SC
128 abort ();
129 }
130 }
bc45ade3 131 break;
8aa2a305 132
bc45ade3
SC
133 case PRE_DEC:
134 fprintf (stream, "@-%s", reg_names[REGNO (XEXP (x, 0))]);
135 break;
136
137 case POST_INC:
138 fprintf (stream, "@%s+", reg_names[REGNO (XEXP (x, 0))]);
139 break;
140
141 default:
142 output_addr_const (stream, x);
143 break;
144 }
145}
146
147/* Print operand x (an rtx) in assembler syntax to file stream
148 according to modifier code.
149
b9654711 150 '.' print a .s if insn needs delay slot
d3ae8277 151 '@' print rte or rts depending upon pragma interruptness
8aa2a305
JW
152 '#' output a nop if there is nothing to put in the delay slot
153 'O' print a constant without the #
00f8ff66 154 'R' print the LSW of a dp value - changes if in little endian
00f8ff66 155 'S' print the MSW of a dp value - changes if in little endian
8aa2a305 156 'T' print the next word of a dp value - same as 'R' in big endian mode. */
bc45ade3
SC
157
158void
159print_operand (stream, x, code)
160 FILE *stream;
161 rtx x;
162 int code;
163{
164 switch (code)
165 {
b9654711 166 case '.':
79b2746a
JW
167 if (final_sequence
168 && ! INSN_ANNULLED_BRANCH_P (XVECEXP (final_sequence, 0, 0)))
b9654711
SC
169 fprintf (stream, ".s");
170 break;
d3ae8277
SC
171 case '@':
172 if (pragma_interrupt)
8e87e161 173 fprintf (stream, "rte");
d3ae8277 174 else
8e87e161 175 fprintf (stream, "rts");
d3ae8277 176 break;
bc45ade3 177 case '#':
16bea517 178 /* Output a nop if there's nothing in the delay slot. */
bc45ade3 179 if (dbr_sequence_length () == 0)
8aa2a305 180 fprintf (stream, "\n\tnop");
bc45ade3 181 break;
b9654711 182 case 'O':
0d7e008e 183 output_addr_const (stream, x);
bc45ade3 184 break;
bc45ade3 185 case 'R':
8aa2a305
JW
186 fputs (reg_names[REGNO (x) + LSW], (stream));
187 break;
188 case 'S':
189 fputs (reg_names[REGNO (x) + MSW], (stream));
00f8ff66
SC
190 break;
191 case 'T':
16bea517 192 /* Next word of a double. */
bc45ade3
SC
193 switch (GET_CODE (x))
194 {
195 case REG:
196 fputs (reg_names[REGNO (x) + 1], (stream));
197 break;
198 case MEM:
8aa2a305
JW
199 print_operand_address (stream,
200 XEXP (adj_offsettable_operand (x, 4), 0));
bc45ade3
SC
201 break;
202 }
203 break;
bc45ade3
SC
204 default:
205 switch (GET_CODE (x))
206 {
207 case REG:
208 fputs (reg_names[REGNO (x)], (stream));
209 break;
210 case MEM:
211 output_address (XEXP (x, 0));
212 break;
213 default:
214 fputc ('#', stream);
215 output_addr_const (stream, x);
216 break;
bc45ade3
SC
217 }
218 break;
219 }
220}
bc45ade3 221\f
0d7e008e
SC
222/* Emit code to perform a block move. Choose the best method.
223
224 OPERANDS[0] is the destination.
225 OPERANDS[1] is the source.
226 OPERANDS[2] is the size.
227 OPERANDS[3] is the alignment safe to use. */
228
0d7e008e
SC
229int
230expand_block_move (operands)
231 rtx *operands;
232{
233 int align = INTVAL (operands[3]);
234 int constp = (GET_CODE (operands[2]) == CONST_INT);
235 int bytes = (constp ? INTVAL (operands[2]) : 0);
0d7e008e 236
8aa2a305
JW
237 /* If it isn't a constant number of bytes, or if it doesn't have 4 byte
238 alignment, or if it isn't a multiple of 4 bytes, then fail. */
239 if (! constp || align < 4 || (bytes % 4 != 0))
d3ae8277
SC
240 return 0;
241
8aa2a305 242 if (bytes < 64)
0d7e008e
SC
243 {
244 char entry[30];
245 tree entry_name;
246 rtx func_addr_rtx;
247 rtx r4 = gen_rtx (REG, SImode, 4);
248 rtx r5 = gen_rtx (REG, SImode, 5);
8aa2a305
JW
249
250 sprintf (entry, "__movstrSI%d", bytes);
0d7e008e
SC
251 entry_name = get_identifier (entry);
252
8aa2a305
JW
253 func_addr_rtx
254 = copy_to_mode_reg (Pmode,
255 gen_rtx (SYMBOL_REF, Pmode,
256 IDENTIFIER_POINTER (entry_name)));
0d7e008e
SC
257 emit_insn (gen_move_insn (r4, XEXP (operands[0], 0)));
258 emit_insn (gen_move_insn (r5, XEXP (operands[1], 0)));
259 emit_insn (gen_block_move_real (func_addr_rtx));
260 return 1;
261 }
8aa2a305
JW
262
263 /* This is the same number of bytes as a memcpy call, but to a different
264 less common function name, so this will occasionally use more space. */
265 if (! TARGET_SMALLCODE)
0d7e008e 266 {
0d7e008e
SC
267 tree entry_name;
268 rtx func_addr_rtx;
8aa2a305 269 int final_switch, while_loop;
0d7e008e
SC
270 rtx r4 = gen_rtx (REG, SImode, 4);
271 rtx r5 = gen_rtx (REG, SImode, 5);
272 rtx r6 = gen_rtx (REG, SImode, 6);
0d7e008e 273
8aa2a305
JW
274 entry_name = get_identifier ("__movstr");
275 func_addr_rtx
276 = copy_to_mode_reg (Pmode,
277 gen_rtx (SYMBOL_REF, Pmode,
278 IDENTIFIER_POINTER (entry_name)));
0d7e008e
SC
279 emit_insn (gen_move_insn (r4, XEXP (operands[0], 0)));
280 emit_insn (gen_move_insn (r5, XEXP (operands[1], 0)));
281
8aa2a305
JW
282 /* r6 controls the size of the move. 16 is decremented from it
283 for each 64 bytes moved. Then the negative bit left over is used
284 as an index into a list of move instructions. e.g., a 72 byte move
285 would be set up with size(r6) = 14, for one iteration through the
286 big while loop, and a switch of -2 for the last part. */
0d7e008e 287
8aa2a305
JW
288 final_switch = 16 - ((bytes / 4) % 16);
289 while_loop = ((bytes / 4) / 16 - 1) * 16;
290 emit_insn (gen_move_insn (r6, GEN_INT (while_loop + final_switch)));
291 emit_insn (gen_block_lump_real (func_addr_rtx));
292 return 1;
0d7e008e 293 }
0d7e008e 294
d3ae8277 295 return 0;
0d7e008e
SC
296}
297
bc45ade3 298/* Prepare operands for a move define_expand; specifically, one of the
8aa2a305 299 operands must be in a register. */
bc45ade3 300
b9654711 301int
bc45ade3
SC
302prepare_move_operands (operands, mode)
303 rtx operands[];
304 enum machine_mode mode;
305{
8aa2a305
JW
306 /* Copy the source to a register if both operands aren't registers. */
307 if (! reload_in_progress && ! reload_completed
308 && ! register_operand (operands[0], mode)
309 && ! register_operand (operands[1], mode))
310 operands[1] = copy_to_mode_reg (mode, operands[1]);
311
312 return 0;
313}
314
315/* Prepare the operands for an scc instruction; make sure that the
316 compare has been done. */
317rtx
318prepare_scc_operands (code)
319 enum rtx_code code;
320{
321 rtx t_reg = gen_rtx (REG, SImode, T_REG);
322 enum rtx_code oldcode = code;
323
324 /* First need a compare insn. */
325 switch (code)
bc45ade3 326 {
8aa2a305
JW
327 case NE:
328 /* It isn't possible to handle this case. */
329 abort ();
330 case LT:
331 code = GT;
332 break;
333 case LE:
334 code = GE;
335 break;
336 case LTU:
337 code = GTU;
338 break;
339 case LEU:
340 code = GEU;
341 break;
bc45ade3 342 }
8aa2a305 343 if (code != oldcode)
b9654711 344 {
8aa2a305
JW
345 rtx tmp = sh_compare_op0;
346 sh_compare_op0 = sh_compare_op1;
347 sh_compare_op1 = tmp;
0d7e008e 348 }
b9654711 349
8aa2a305
JW
350 sh_compare_op0 = force_reg (SImode, sh_compare_op0);
351 if (code != EQ && code != NE
352 && (sh_compare_op1 != const0_rtx
353 || code == GTU || code == GEU || code == LTU || code == LEU))
354 sh_compare_op1 = force_reg (SImode, sh_compare_op1);
0d7e008e 355
8aa2a305
JW
356 emit_insn (gen_rtx (SET, VOIDmode, t_reg,
357 gen_rtx (code, SImode, sh_compare_op0,
358 sh_compare_op1)));
0d7e008e 359
8aa2a305 360 return t_reg;
bc45ade3
SC
361}
362
8aa2a305
JW
363/* Called from the md file, set up the operands of a compare instruction. */
364
365void
366from_compare (operands, code)
367 rtx *operands;
8e87e161 368 int code;
bc45ade3 369{
8aa2a305 370 if (code != EQ && code != NE)
bc45ade3 371 {
8aa2a305 372 /* Force args into regs, since we can't use constants here. */
0d7e008e 373 sh_compare_op0 = force_reg (SImode, sh_compare_op0);
8aa2a305
JW
374 if (sh_compare_op1 != const0_rtx
375 || code == GTU || code == GEU || code == LTU || code == LEU)
22e1ebf1 376 sh_compare_op1 = force_reg (SImode, sh_compare_op1);
bc45ade3 377 }
8aa2a305
JW
378 operands[1] = sh_compare_op0;
379 operands[2] = sh_compare_op1;
bc45ade3
SC
380}
381\f
16bea517 382/* Functions to output assembly code. */
bc45ade3 383
b9654711 384/* Return a sequence of instructions to perform DI or DF move.
bc45ade3 385
b9654711 386 Since the SH cannot move a DI or DF in one instruction, we have
16bea517 387 to take care when we see overlapping source and dest registers. */
0d7e008e 388
bc45ade3 389char *
0d7e008e
SC
390output_movedouble (insn, operands, mode)
391 rtx insn;
bc45ade3
SC
392 rtx operands[];
393 enum machine_mode mode;
394{
b9654711
SC
395 rtx dst = operands[0];
396 rtx src = operands[1];
b9654711 397
0d7e008e 398 if (GET_CODE (dst) == MEM
16bea517 399 && GET_CODE (XEXP (dst, 0)) == PRE_DEC)
8aa2a305
JW
400 return "mov.l %T1,%0\n\tmov.l %1,%0";
401
b9654711
SC
402 if (register_operand (dst, mode)
403 && register_operand (src, mode))
bc45ade3 404 {
b9654711 405 if (REGNO (src) == MACH_REG)
00f8ff66 406 return "sts mach,%S0\n\tsts macl,%R0";
bc45ade3 407
8aa2a305
JW
408 /* When mov.d r1,r2 do r2->r3 then r1->r2;
409 when mov.d r1,r0 do r1->r0 then r2->r1. */
b9654711
SC
410
411 if (REGNO (src) + 1 == REGNO (dst))
5325c0fa 412 return "mov %T1,%T0\n\tmov %1,%0";
b9654711 413 else
5325c0fa 414 return "mov %1,%0\n\tmov %T1,%T0";
b9654711
SC
415 }
416 else if (GET_CODE (src) == CONST_INT)
bc45ade3 417 {
8aa2a305
JW
418 if (INTVAL (src) < 0)
419 output_asm_insn ("mov #-1,%S0", operands);
bc45ade3 420 else
8aa2a305 421 output_asm_insn ("mov #0,%S0", operands);
bc45ade3 422
8aa2a305 423 return "mov %1,%R0";
0d7e008e 424 }
b9654711 425 else if (GET_CODE (src) == MEM)
bc45ade3 426 {
8aa2a305 427 int ptrreg = -1;
b9654711
SC
428 int dreg = REGNO (dst);
429 rtx inside = XEXP (src, 0);
bc45ade3
SC
430
431 if (GET_CODE (inside) == REG)
8aa2a305 432 ptrreg = REGNO (inside);
79b2746a
JW
433 else if (GET_CODE (inside) == SUBREG)
434 ptrreg = REGNO (SUBREG_REG (inside)) + SUBREG_WORD (inside);
bc45ade3
SC
435 else if (GET_CODE (inside) == PLUS)
436 {
8aa2a305
JW
437 ptrreg = REGNO (XEXP (inside, 0));
438 /* ??? A r0+REG address shouldn't be possible here, because it isn't
439 an offsettable address. Unfortunately, offsettable addresses use
440 QImode to check the offset, and a QImode offsettable address
441 requires r0 for the other operand, which is not currently
442 supported, so we can't use the 'o' constraint.
443 Thus we must check for and handle r0+REG addresses here.
444 We punt for now, since this is likely very rare. */
445 if (GET_CODE (XEXP (inside, 1)) == REG)
446 abort ();
bc45ade3 447 }
0d7e008e 448 else if (GET_CODE (inside) == LABEL_REF)
8aa2a305 449 return "mov.l %1,%0\n\tmov.l %1+4,%T0";
8e87e161 450 else if (GET_CODE (inside) == POST_INC)
8aa2a305 451 return "mov.l %1,%0\n\tmov.l %1,%T0";
bc45ade3
SC
452 else
453 abort ();
454
8aa2a305
JW
455 /* Work out the safe way to copy. Copy into the second half first. */
456 if (dreg == ptrreg)
457 return "mov.l %T1,%T0\n\tmov.l %1,%0";
bc45ade3
SC
458 }
459
00f8ff66 460 return "mov.l %1,%0\n\tmov.l %T1,%T0";
bc45ade3
SC
461}
462
8aa2a305
JW
463/* Print an instruction which would have gone into a delay slot after
464 another instruction, but couldn't because the other instruction expanded
465 into a sequence where putting the slot insn at the end wouldn't work. */
0d7e008e 466
8aa2a305
JW
467static void
468print_slot (insn)
469 rtx insn;
470{
471 final_scan_insn (XVECEXP (insn, 0, 1), asm_out_file, optimize, 0, 1);
b9654711 472
8aa2a305
JW
473 INSN_DELETED_P (XVECEXP (insn, 0, 1)) = 1;
474}
0d7e008e 475
8aa2a305
JW
476/* We can't tell if we need a register as a scratch for the jump
477 until after branch shortening, and then it's too late to allocate a
478 register the 'proper' way. These instruction sequences are rare
479 anyway, so to avoid always using a reg up from our limited set, we'll
480 grab one when we need one on output. */
0d7e008e 481
8aa2a305
JW
482/* ??? Should fix compiler so that using a clobber scratch in jump
483 instructions works, and then this will be unnecessary. */
0d7e008e
SC
484
485char *
486output_far_jump (insn, op)
487 rtx insn;
488 rtx op;
489{
490 rtx thislab = gen_label_rtx ();
491
8aa2a305 492 /* Output the delay slot insn first if any. */
0d7e008e 493 if (dbr_sequence_length ())
8aa2a305 494 print_slot (final_sequence);
b9654711 495
8aa2a305
JW
496 output_asm_insn ("mov.l r13,@-r15", 0);
497 output_asm_insn ("mov.l %O0,r13", &thislab);
498 output_asm_insn ("jmp @r13", 0);
499 output_asm_insn ("mov.l @r15+,r13", 0);
0d7e008e 500 output_asm_insn (".align 2", 0);
d3ae8277 501 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "L", CODE_LABEL_NUMBER (thislab));
0d7e008e
SC
502 output_asm_insn (".long %O0", &op);
503 return "";
504}
bc45ade3 505
8aa2a305
JW
506/* Local label counter, used for constants in the pool and inside
507 pattern branches. */
508
509static int lf = 100;
510
511/* Output code for ordinary branches. */
512
bc45ade3 513char *
8aa2a305 514output_branch (logic, insn, operands)
bc45ade3 515 int logic;
b9654711 516 rtx insn;
8aa2a305 517 rtx *operands;
bc45ade3 518{
bc45ade3 519 int label = lf++;
8e87e161 520
bc45ade3
SC
521 switch (get_attr_length (insn))
522 {
523 case 2:
22e1ebf1
JW
524 /* A branch with an unfilled delay slot. */
525 case 4:
526 /* Simple branch in range -252..+258 bytes */
b9654711 527 return logic ? "bt%. %l0" : "bf%. %l0";
bc45ade3
SC
528
529 case 6:
22e1ebf1
JW
530 /* A branch with an unfilled delay slot. */
531 case 8:
16bea517 532 /* Branch in range -4092..+4098 bytes. */
b9654711 533 {
8aa2a305
JW
534 /* The call to print_slot will clobber the operands. */
535 rtx op0 = operands[0];
b9654711 536
79b2746a
JW
537 /* If the instruction in the delay slot is annulled (true), then
538 there is no delay slot where we can put it now. The only safe
539 place for it is after the label. */
540
16bea517 541 if (final_sequence)
b9654711 542 {
79b2746a
JW
543 fprintf (asm_out_file, "\tb%c%s\tLF%d\n", logic ? 'f' : 't',
544 INSN_ANNULLED_BRANCH_P (XVECEXP (final_sequence, 0, 0))
545 ? "" : ".s", label);
546 if (! INSN_ANNULLED_BRANCH_P (XVECEXP (final_sequence, 0, 0)))
547 print_slot (final_sequence);
b9654711 548 }
b9654711 549 else
8aa2a305 550 fprintf (asm_out_file, "\tb%c\tLF%d\n", logic ? 'f' : 't', label);
b9654711 551
8aa2a305
JW
552 output_asm_insn ("bra %l0", &op0);
553 fprintf (asm_out_file, "\tnop\n");
b9654711 554 fprintf (asm_out_file, "LF%d:\n", label);
79b2746a
JW
555
556 if (final_sequence
557 && INSN_ANNULLED_BRANCH_P (XVECEXP (final_sequence, 0, 0)))
558 print_slot (final_sequence);
b9654711 559 }
bc45ade3
SC
560 return "";
561
8aa2a305
JW
562 case 16:
563 /* A branch with an unfilled delay slot. */
564 case 18:
565 /* Branches a long way away. */
566 {
567 /* The call to print_slot will clobber the operands. */
568 rtx op0 = operands[0];
bc45ade3 569
79b2746a
JW
570 /* If the instruction in the delay slot is annulled (true), then
571 there is no delay slot where we can put it now. The only safe
572 place for it is after the label. */
573
8aa2a305
JW
574 if (final_sequence)
575 {
79b2746a
JW
576 fprintf (asm_out_file, "\tb%c%s\tLF%d\n", logic ? 'f' : 't',
577 INSN_ANNULLED_BRANCH_P (XVECEXP (final_sequence, 0, 0))
578 ? "" : ".s", label);
579 if (! INSN_ANNULLED_BRANCH_P (XVECEXP (final_sequence, 0, 0)))
580 print_slot (final_sequence);
8aa2a305
JW
581 }
582 else
583 fprintf (asm_out_file, "\tb%c\tLF%d\n", logic ? 'f' : 't', label);
bc45ade3 584
8aa2a305
JW
585 output_far_jump (insn, op0);
586 fprintf (asm_out_file, "LF%d:\n", label);
79b2746a
JW
587
588 if (final_sequence
589 && INSN_ANNULLED_BRANCH_P (XVECEXP (final_sequence, 0, 0)))
590 print_slot (final_sequence);
8aa2a305 591 }
79b2746a 592 return "";
bc45ade3 593 }
8aa2a305 594 return "bad";
bc45ade3 595}
8e87e161 596\f
8aa2a305 597/* A copy of the option structure defined in toplev.c. */
bc45ade3 598
0d7e008e 599struct option
bc45ade3 600{
0d7e008e
SC
601 char *string;
602 int *variable;
603 int on_value;
604};
b9654711 605
8aa2a305
JW
606/* Output a single output option string NAME to FILE, without generating
607 lines longer than MAX. */
608
0d7e008e
SC
609static int
610output_option (file, sep, type, name, indent, pos, max)
611 FILE *file;
612 char *sep;
613 char *type;
614 char *name;
615 char *indent;
616 int pos;
617 int max;
618{
619 if (strlen (sep) + strlen (type) + strlen (name) + pos > max)
bc45ade3 620 {
0d7e008e
SC
621 fprintf (file, indent);
622 return fprintf (file, "%s%s", type, name);
b9654711 623 }
0d7e008e
SC
624 return pos + fprintf (file, "%s%s%s", sep, type, name);
625}
bc45ade3 626
8aa2a305
JW
627/* A copy of the target_switches variable in toplev.c. */
628
0d7e008e
SC
629static struct
630{
631 char *name;
632 int value;
8aa2a305 633} m_options[] = TARGET_SWITCHES;
bc45ade3 634
8aa2a305 635/* Output all options to the assembly language file. */
bc45ade3 636
0d7e008e
SC
637static void
638output_options (file, f_options, f_len, W_options, W_len,
639 pos, max, sep, indent, term)
640 FILE *file;
641 struct option *f_options;
642 struct option *W_options;
643 int f_len, W_len;
644 int pos;
645 int max;
646 char *sep;
647 char *indent;
648 char *term;
649{
650 register int j;
bc45ade3 651
0d7e008e
SC
652 if (optimize)
653 pos = output_option (file, sep, "-O", "", indent, pos, max);
654 if (write_symbols != NO_DEBUG)
655 pos = output_option (file, sep, "-g", "", indent, pos, max);
0d7e008e
SC
656 if (profile_flag)
657 pos = output_option (file, sep, "-p", "", indent, pos, max);
658 if (profile_block_flag)
659 pos = output_option (file, sep, "-a", "", indent, pos, max);
bc45ade3 660
0d7e008e
SC
661 for (j = 0; j < f_len; j++)
662 if (*f_options[j].variable == f_options[j].on_value)
663 pos = output_option (file, sep, "-f", f_options[j].string,
664 indent, pos, max);
bc45ade3 665
0d7e008e
SC
666 for (j = 0; j < W_len; j++)
667 if (*W_options[j].variable == W_options[j].on_value)
668 pos = output_option (file, sep, "-W", W_options[j].string,
669 indent, pos, max);
bc45ade3 670
0d7e008e
SC
671 for (j = 0; j < sizeof m_options / sizeof m_options[0]; j++)
672 if (m_options[j].name[0] != '\0'
673 && m_options[j].value > 0
674 && ((m_options[j].value & target_flags)
675 == m_options[j].value))
676 pos = output_option (file, sep, "-m", m_options[j].name,
677 indent, pos, max);
bc45ade3 678
0d7e008e 679 fprintf (file, term);
0d7e008e 680}
b9654711 681
8aa2a305
JW
682/* Output to FILE the start of the assembler file. */
683
0d7e008e
SC
684void
685output_file_start (file, f_options, f_len, W_options, W_len)
686 FILE *file;
687 struct option *f_options;
688 struct option *W_options;
689 int f_len, W_len;
bc45ade3 690{
0d7e008e 691 register int pos;
b9654711 692
0d7e008e 693 output_file_directive (file, main_input_filename);
b9654711 694
0d7e008e
SC
695 /* Switch to the data section so that the coffsem symbol and the
696 gcc2_compiled. symbol aren't in the text section. */
697 data_section ();
b9654711 698
00f8ff66 699 pos = fprintf (file, "\n! Hitachi SH cc1 (%s) arguments:", version_string);
0d7e008e
SC
700 output_options (file, f_options, f_len, W_options, W_len,
701 pos, 75, " ", "\n! ", "\n\n");
8aa2a305
JW
702
703 if (TARGET_LITTLE_ENDIAN)
704 fprintf (file, "\t.little\n");
bc45ade3 705}
0d7e008e 706\f
16bea517 707/* Actual number of instructions used to make a shift by N. */
8aa2a305 708static char ashiftrt_insns[] =
16bea517
JW
709 { 0,1,2,3,4,5,8,8,8,8,8,8,8,8,8,8,2,3,4,5,8,8,8,8,8,8,8,8,8,8,8,2};
710
711/* Left shift and logical right shift are the same. */
8aa2a305 712static char shift_insns[] =
16bea517 713 { 0,1,1,2,2,3,3,4,1,2,2,3,3,4,3,3,1,2,2,3,3,4,3,3,2,3,3,4,4,4,3,3};
8aa2a305 714
16bea517
JW
715/* Individual shift amounts needed to get the above length sequences.
716 One bit right shifts clobber the T bit, so when possible, put one bit
717 shifts in the middle of the sequence, so the ends are eligible for
718 branch delay slots. */
8aa2a305 719static short shift_amounts[32][5] = {
16bea517
JW
720 {0}, {1}, {2}, {2, 1},
721 {2, 2}, {2, 1, 2}, {2, 2, 2}, {2, 2, 1, 2},
722 {8}, {8, 1}, {8, 2}, {8, 1, 2},
723 {8, 2, 2}, {8, 2, 1, 2}, {8, -2, 8}, {8, -1, 8},
724 {16}, {16, 1}, {16, 2}, {16, 1, 2},
725 {16, 2, 2}, {16, 2, 1, 2}, {16, -2, 8}, {16, -1, 8},
726 {16, 8}, {16, 1, 8}, {16, 8, 2}, {16, 8, 1, 2},
1d3534c0 727 {16, 8, 2, 2}, {16, -1, -2, 16}, {16, -2, 16}, {16, -1, 16}};
16bea517
JW
728
729/* This is used in length attributes in sh.md to help compute the length
730 of arbitrary constant shift instructions. */
bc45ade3 731
16bea517
JW
732int
733shift_insns_rtx (insn)
734 rtx insn;
735{
736 rtx set_src = SET_SRC (XVECEXP (PATTERN (insn), 0, 0));
737 int shift_count = INTVAL (XEXP (set_src, 1));
738 enum rtx_code shift_code = GET_CODE (set_src);
00f8ff66 739
16bea517
JW
740 switch (shift_code)
741 {
742 case ASHIFTRT:
743 return ashiftrt_insns[shift_count];
744 case LSHIFTRT:
745 case ASHIFT:
746 return shift_insns[shift_count];
747 default:
748 abort();
749 }
750}
751
16bea517 752/* Return the cost of a shift. */
bc45ade3 753
0d7e008e 754int
8aa2a305
JW
755shiftcosts (x)
756 rtx x;
bc45ade3 757{
8aa2a305
JW
758 int value = INTVAL (XEXP (x, 1));
759
16bea517 760 /* If shift by a non constant, then this will be expensive. */
8aa2a305 761 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
00f8ff66 762 {
20b04867
JW
763 if (TARGET_SH3)
764 return 2;
765 /* If not an sh3 then we don't even have an instruction for it. */
00f8ff66
SC
766 return 20;
767 }
bc45ade3 768
16bea517 769 /* Otherwise, return the true cost in instructions. */
8aa2a305
JW
770 if (GET_CODE (x) == ASHIFTRT)
771 return ashiftrt_insns[value];
772 else
773 return shift_insns[value];
0d7e008e 774}
b9654711 775
8aa2a305
JW
776/* Return the cost of an AND operation. */
777
8e87e161 778int
8aa2a305
JW
779andcosts (x)
780 rtx x;
0d7e008e
SC
781{
782 int i;
8aa2a305 783
a6f71af5 784 /* Anding with a register is a single cycle and instruction. */
8aa2a305 785 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
a6f71af5 786 return 1;
8aa2a305
JW
787
788 i = INTVAL (XEXP (x, 1));
a6f71af5 789 /* These constants are single cycle extu.[bw] instructions. */
0d7e008e 790 if (i == 0xff || i == 0xffff)
a6f71af5
JW
791 return 1;
792 /* Constants that can be used in an and immediate instruction is a single
793 cycle, but this requires r0, so make it a little more expensive. */
794 if (CONST_OK_FOR_L (i))
0d7e008e 795 return 2;
a6f71af5
JW
796 /* Constants that can be loaded with a mov immediate and an and.
797 This case is probably unnecessary. */
0d7e008e 798 if (CONST_OK_FOR_I (i))
a6f71af5
JW
799 return 2;
800 /* Any other constants requires a 2 cycle pc-relative load plus an and.
801 This case is probably unnecessary. */
802 return 3;
0d7e008e 803}
d3ae8277 804
16bea517 805/* Return the cost of a multiply. */
0d7e008e 806int
8aa2a305
JW
807multcosts (x)
808 rtx x;
0d7e008e
SC
809{
810 if (TARGET_SH2)
d3ae8277
SC
811 {
812 /* We have a mul insn, so we can never take more than the mul and the
a7771f78 813 read of the mac reg, but count more because of the latency and extra
16bea517 814 reg usage. */
d3ae8277 815 if (TARGET_SMALLCODE)
8e87e161 816 return 2;
a7771f78 817 return 3;
d3ae8277
SC
818 }
819
a7771f78 820 /* If we're aiming at small code, then just count the number of
16bea517 821 insns in a multiply call sequence. */
8e87e161 822 if (TARGET_SMALLCODE)
8aa2a305 823 return 5;
d3ae8277 824
16bea517 825 /* Otherwise count all the insns in the routine we'd be calling too. */
d3ae8277 826 return 20;
0d7e008e 827}
b9654711 828
16bea517 829/* Code to expand a shift. */
b9654711 830
0d7e008e
SC
831void
832gen_ashift (type, n, reg)
833 int type;
834 int n;
835 rtx reg;
836{
16bea517
JW
837 /* Negative values here come from the shift_amounts array. */
838 if (n < 0)
839 {
840 if (type == ASHIFT)
841 type = LSHIFTRT;
842 else
843 type = ASHIFT;
844 n = -n;
845 }
846
0d7e008e 847 switch (type)
bc45ade3 848 {
0d7e008e
SC
849 case ASHIFTRT:
850 emit_insn (gen_ashrsi3_k (reg, reg, GEN_INT (n)));
851 break;
852 case LSHIFTRT:
16bea517
JW
853 if (n == 1)
854 emit_insn (gen_lshrsi3_m (reg, reg, GEN_INT (n)));
855 else
856 emit_insn (gen_lshrsi3_k (reg, reg, GEN_INT (n)));
0d7e008e
SC
857 break;
858 case ASHIFT:
5325c0fa 859 emit_insn (gen_ashlsi3_k (reg, reg, GEN_INT (n)));
0d7e008e 860 break;
bc45ade3 861 }
bc45ade3 862}
bc45ade3 863
8aa2a305
JW
864/* Output RTL to split a constant shift into its component SH constant
865 shift instructions. */
866
20b04867
JW
867/* ??? For SH3, should reject constant shifts when slower than loading the
868 shift count into a register? */
8aa2a305 869
0d7e008e
SC
870int
871gen_shifty_op (code, operands)
872 int code;
873 rtx *operands;
bc45ade3 874{
16bea517 875 int value = INTVAL (operands[2]);
8aa2a305 876 int max, i;
00f8ff66 877
8aa2a305 878 if (value == 31)
16bea517 879 {
8aa2a305 880 if (code == LSHIFTRT)
0d7e008e 881 {
8aa2a305
JW
882 emit_insn (gen_rotlsi3_1 (operands[0], operands[0]));
883 emit_insn (gen_movt (operands[0]));
884 return;
16bea517 885 }
8aa2a305 886 else if (code == ASHIFT)
16bea517 887 {
8aa2a305
JW
888 /* There is a two instruction sequence for 31 bit left shifts,
889 but it requires r0. */
890 if (GET_CODE (operands[0]) == REG && REGNO (operands[0]) == 0)
0d7e008e 891 {
8aa2a305
JW
892 emit_insn (gen_andsi3 (operands[0], operands[0], const1_rtx));
893 emit_insn (gen_rotlsi3_31 (operands[0], operands[0]));
894 return;
0d7e008e 895 }
16bea517 896 }
8aa2a305 897 }
a9f71ad8 898
8aa2a305
JW
899 max = shift_insns[value];
900 for (i = 0; i < max; i++)
901 gen_ashift (code, shift_amounts[value][i], operands[0]);
902}
903
904/* Output RTL for an arithmetic right shift. */
905
906/* ??? Rewrite to use super-optimizer sequences. */
907
908int
909expand_ashiftrt (operands)
910 rtx *operands;
911{
912 rtx wrk;
913 char func[18];
914 tree func_name;
915 int value;
916
20b04867
JW
917 if (TARGET_SH3 && GET_CODE (operands[2]) != CONST_INT)
918 {
919 rtx count = copy_to_mode_reg (SImode, operands[2]);
920 emit_insn (gen_negsi2 (count, count));
921 emit_insn (gen_ashrsi3_d (operands[0], operands[1], count));
922 return 1;
923 }
8aa2a305
JW
924 if (GET_CODE (operands[2]) != CONST_INT)
925 return 0;
926
927 value = INTVAL (operands[2]);
928
929 if (value == 31)
930 {
931 emit_insn (gen_ashrsi2_31 (operands[0], operands[1]));
932 return 1;
933 }
934 else if (value >= 16 && value <= 19)
935 {
936 wrk = gen_reg_rtx (SImode);
937 emit_insn (gen_ashrsi2_16 (wrk, operands[1]));
938 value -= 16;
939 while (value--)
940 gen_ashift (ASHIFTRT, 1, wrk);
941 emit_move_insn (operands[0], wrk);
942 return 1;
a9f71ad8 943 }
8aa2a305
JW
944 /* Expand a short sequence inline, longer call a magic routine. */
945 else if (value <= 5)
946 {
947 wrk = gen_reg_rtx (SImode);
948 emit_move_insn (wrk, operands[1]);
949 while (value--)
950 gen_ashift (ASHIFTRT, 1, wrk);
951 emit_move_insn (operands[0], wrk);
952 return 1;
953 }
954
955 wrk = gen_reg_rtx (Pmode);
956
957 /* Load the value into an arg reg and call a helper. */
958 emit_move_insn (gen_rtx (REG, SImode, 4), operands[1]);
959 sprintf (func, "__ashiftrt_r4_%d", value);
960 func_name = get_identifier (func);
961 emit_move_insn (wrk, gen_rtx (SYMBOL_REF, Pmode,
962 IDENTIFIER_POINTER (func_name)));
963 emit_insn (gen_ashrsi3_n (GEN_INT (value), wrk));
964 emit_move_insn (operands[0], gen_rtx (REG, SImode, 4));
965 return 1;
bc45ade3 966}
8aa2a305
JW
967\f
968/* The SH cannot load a large constant into a register, constants have to
969 come from a pc relative load. The reference of a pc relative load
970 instruction must be less than 1k infront of the instruction. This
971 means that we often have to dump a constant inside a function, and
972 generate code to branch around it.
bc45ade3 973
8aa2a305
JW
974 It is important to minimize this, since the branches will slow things
975 down and make things bigger.
976
977 Worst case code looks like:
978
979 mov.l L1,rn
980 bra L2
981 nop
982 align
983 L1: .long value
984 L2:
985 ..
986
987 mov.l L3,rn
988 bra L4
989 nop
990 align
991 L3: .long value
992 L4:
993 ..
994
995 We fix this by performing a scan before scheduling, which notices which
996 instructions need to have their operands fetched from the constant table
997 and builds the table.
998
999 The algorithm is:
1000
1001 scan, find an instruction which needs a pcrel move. Look forward, find the
1002 last barrier which is within MAX_COUNT bytes of the requirement.
1003 If there isn't one, make one. Process all the instructions between
1004 the find and the barrier.
1005
1006 In the above example, we can tell that L3 is within 1k of L1, so
1007 the first move can be shrunk from the 3 insn+constant sequence into
1008 just 1 insn, and the constant moved to L3 to make:
1009
1010 mov.l L1,rn
1011 ..
1012 mov.l L3,rn
1013 bra L4
1014 nop
1015 align
1016 L3:.long value
1017 L4:.long value
1018
1019 Then the second move becomes the target for the shortening process. */
1020
1021typedef struct
1022{
1023 rtx value; /* Value in table. */
1024 rtx label; /* Label of value. */
1025 enum machine_mode mode; /* Mode of value. */
1026} pool_node;
1027
1028/* The maximum number of constants that can fit into one pool, since
1029 the pc relative range is 0...1020 bytes and constants are at least 4
1030 bytes long. */
1031
1032#define MAX_POOL_SIZE (1020/4)
1033static pool_node pool_vector[MAX_POOL_SIZE];
1034static int pool_size;
1035
1036/* ??? If we need a constant in HImode which is the truncated value of a
1037 constant we need in SImode, we could combine the two entries thus saving
1038 two bytes. Is this common enough to be worth the effort of implementing
1039 it? */
1040
1041/* ??? This stuff should be done at the same time that we shorten branches.
1042 As it is now, we must assume that all branches are the maximum size, and
1043 this causes us to almost always output constant pools sooner than
1044 necessary. */
1045
1046/* Add a constant to the pool and return its label. */
1047
1048static rtx
1049add_constant (x, mode)
1050 rtx x;
1051 enum machine_mode mode;
0d7e008e
SC
1052{
1053 int i;
8aa2a305
JW
1054 rtx lab;
1055
1056 /* First see if we've already got it. */
1057 for (i = 0; i < pool_size; i++)
0d7e008e 1058 {
8aa2a305
JW
1059 if (x->code == pool_vector[i].value->code
1060 && mode == pool_vector[i].mode)
0d7e008e 1061 {
8aa2a305
JW
1062 if (x->code == CODE_LABEL)
1063 {
1064 if (XINT (x, 3) != XINT (pool_vector[i].value, 3))
1065 continue;
1066 }
1067 if (rtx_equal_p (x, pool_vector[i].value))
1068 return pool_vector[i].label;
0d7e008e 1069 }
0d7e008e 1070 }
b9654711 1071
8aa2a305
JW
1072 /* Need a new one. */
1073 pool_vector[pool_size].value = x;
1074 lab = gen_label_rtx ();
1075 pool_vector[pool_size].mode = mode;
1076 pool_vector[pool_size].label = lab;
1077 pool_size++;
1078 return lab;
0d7e008e 1079}
16bea517
JW
1080
1081/* Output the literal table. */
b9654711 1082
b9654711 1083static void
0d7e008e
SC
1084dump_table (scan)
1085 rtx scan;
b9654711 1086{
0d7e008e 1087 int i;
0d7e008e 1088 int need_align = 1;
b9654711 1089
16bea517 1090 /* Do two passes, first time dump out the HI sized constants. */
b9654711 1091
0d7e008e 1092 for (i = 0; i < pool_size; i++)
b9654711 1093 {
8aa2a305
JW
1094 pool_node *p = &pool_vector[i];
1095
0d7e008e
SC
1096 if (p->mode == HImode)
1097 {
1098 if (need_align)
1099 {
1100 scan = emit_insn_after (gen_align_2 (), scan);
1101 need_align = 0;
1102 }
1103 scan = emit_label_after (p->label, scan);
1104 scan = emit_insn_after (gen_consttable_2 (p->value), scan);
1105 }
b9654711 1106 }
8aa2a305 1107
0d7e008e 1108 need_align = 1;
b9654711 1109
0d7e008e 1110 for (i = 0; i < pool_size; i++)
b9654711 1111 {
8aa2a305 1112 pool_node *p = &pool_vector[i];
b9654711 1113
0d7e008e 1114 switch (p->mode)
b9654711 1115 {
0d7e008e
SC
1116 case HImode:
1117 break;
1118 case SImode:
1119 if (need_align)
b9654711 1120 {
0d7e008e 1121 need_align = 0;
d3ae8277 1122 scan = emit_label_after (gen_label_rtx (), scan);
0d7e008e 1123 scan = emit_insn_after (gen_align_4 (), scan);
b9654711 1124 }
0d7e008e
SC
1125 scan = emit_label_after (p->label, scan);
1126 scan = emit_insn_after (gen_consttable_4 (p->value), scan);
1127 break;
1128 case DImode:
1129 if (need_align)
1130 {
1131 need_align = 0;
d3ae8277 1132 scan = emit_label_after (gen_label_rtx (), scan);
0d7e008e
SC
1133 scan = emit_insn_after (gen_align_4 (), scan);
1134 }
1135 scan = emit_label_after (p->label, scan);
1136 scan = emit_insn_after (gen_consttable_8 (p->value), scan);
1137 break;
1138 default:
1139 abort ();
1140 break;
b9654711
SC
1141 }
1142 }
b9654711 1143
0d7e008e
SC
1144 scan = emit_insn_after (gen_consttable_end (), scan);
1145 scan = emit_barrier_after (scan);
1146 pool_size = 0;
1147}
b9654711 1148
8aa2a305
JW
1149/* Return non-zero if constant would be an ok source for a
1150 mov.w instead of a mov.l. */
b9654711 1151
16bea517 1152static int
8aa2a305 1153hi_const (src)
0d7e008e 1154 rtx src;
0d7e008e 1155{
8aa2a305
JW
1156 return (GET_CODE (src) == CONST_INT
1157 && INTVAL (src) >= -32768
1158 && INTVAL (src) <= 32767);
b9654711
SC
1159}
1160
8aa2a305
JW
1161/* Non-zero if the insn is a move instruction which needs to be fixed. */
1162
1163/* ??? For a DImode/DFmode moves, we don't need to fix it if each half of the
1164 CONST_DOUBLE input value is CONST_OK_FOR_I. For a SFmode move, we don't
1165 need to fix it if the input value is CONST_OK_FOR_I. */
1166
1167static int
1168broken_move (insn)
1169 rtx insn;
b9654711 1170{
8aa2a305
JW
1171 if (GET_CODE (insn) == INSN
1172 && GET_CODE (PATTERN (insn)) == SET
1173 /* We can load any 8 bit value if we don't care what the high
1174 order bits end up as. */
1175 && GET_MODE (SET_DEST (PATTERN (insn))) != QImode
1176 && CONSTANT_P (SET_SRC (PATTERN (insn)))
1177 && (GET_CODE (SET_SRC (PATTERN (insn))) != CONST_INT
1178 || ! CONST_OK_FOR_I (INTVAL (SET_SRC (PATTERN (insn))))))
d3ae8277
SC
1179 return 1;
1180
8aa2a305 1181 return 0;
b9654711 1182}
b9654711 1183
8aa2a305
JW
1184/* Find the last barrier from insn FROM which is close enough to hold the
1185 constant pool. If we can't find one, then create one near the end of
1186 the range. */
b9654711 1187
5325c0fa
JW
1188/* ??? It would be good to put constant pool tables between a case jump and
1189 the jump table. This fails for two reasons. First, there is no
1190 barrier after the case jump. This is a bug in the casesi pattern.
1191 Second, inserting the table here may break the mova instruction that
1192 loads the jump table address, by moving the jump table too far away.
1193 We fix that problem by never outputting the constant pool between a mova
1194 and its label. */
1195
8aa2a305 1196static rtx
06c386ea
SC
1197find_barrier (from)
1198 rtx from;
b9654711 1199{
0d7e008e
SC
1200 int count_si = 0;
1201 int count_hi = 0;
1202 int found_hi = 0;
1203 int found_si = 0;
1204 rtx found_barrier = 0;
5325c0fa 1205 rtx found_mova = 0;
8aa2a305
JW
1206
1207 /* For HImode: range is 510, add 4 because pc counts from address of
1208 second instruction after this one, subtract 2 for the jump instruction
1209 that we may need to emit before the table. This gives 512.
1210 For SImode: range is 1020, add 4 because pc counts from address of
1211 second instruction after this one, subtract 2 in case pc is 2 byte
1212 aligned, subtract 2 for the jump instruction that we may need to emit
1213 before the table. This gives 1020. */
1214 while (from && count_si < 1020 && count_hi < 512)
0d7e008e 1215 {
5dbcc9c0 1216 int inc = get_attr_length (from);
8aa2a305 1217
0d7e008e 1218 if (GET_CODE (from) == BARRIER)
8aa2a305
JW
1219 found_barrier = from;
1220
8aa2a305 1221 if (broken_move (from))
0d7e008e
SC
1222 {
1223 rtx src = SET_SRC (PATTERN (from));
8aa2a305 1224
0d7e008e 1225 if (hi_const (src))
00e94d65
RK
1226 {
1227 found_hi = 1;
1228 /* We put the short constants before the long constants, so
1229 we must count the length of short constants in the range
1230 for the long constants. */
1231 /* ??? This isn't optimal, but is easy to do. */
1232 if (found_si)
1233 count_si += 2;
1234 }
0d7e008e
SC
1235 else
1236 found_si = 1;
0d7e008e 1237 }
5325c0fa 1238
5325c0fa
JW
1239 if (GET_CODE (from) == INSN
1240 && GET_CODE (PATTERN (from)) == SET
16bea517
JW
1241 && GET_CODE (SET_SRC (PATTERN (from))) == UNSPEC
1242 && XINT (SET_SRC (PATTERN (from)), 1) == 1)
5325c0fa
JW
1243 found_mova = from;
1244 else if (GET_CODE (from) == JUMP_INSN
1245 && (GET_CODE (PATTERN (from)) == ADDR_VEC
1246 || GET_CODE (PATTERN (from)) == ADDR_DIFF_VEC))
1247 found_mova = 0;
1248
0d7e008e
SC
1249 if (found_si)
1250 count_si += inc;
1251 if (found_hi)
1252 count_hi += inc;
1253 from = NEXT_INSN (from);
1254 }
1255
5325c0fa
JW
1256 /* Insert the constant pool table before the mova instruction, to prevent
1257 the mova label reference from going out of range. */
1258 if (found_mova)
1259 from = found_mova;
1260
8aa2a305 1261 if (! found_barrier)
b9654711 1262 {
8aa2a305
JW
1263 /* We didn't find a barrier in time to dump our stuff,
1264 so we'll make one. */
0d7e008e 1265 rtx label = gen_label_rtx ();
8aa2a305 1266
5dbcc9c0
RK
1267 /* If we exceeded the range, then we must back up over the last
1268 instruction we looked at. Otherwise, we just need to undo the
1269 NEXT_INSN at the end of the loop. */
1270 if (count_hi > 512 || count_si > 1020)
1271 from = PREV_INSN (PREV_INSN (from));
1272 else
1273 from = PREV_INSN (from);
1274
8aa2a305
JW
1275 /* Walk back to be just before any jump or label.
1276 Putting it before a label reduces the number of times the branch
1277 around the constant pool table will be hit. Putting it before
1278 a jump makes it more likely that the bra delay slot will be
1279 filled. */
1280 while (GET_CODE (from) == JUMP_INSN || GET_CODE (from) == NOTE
8e87e161 1281 || GET_CODE (from) == CODE_LABEL)
8aa2a305
JW
1282 from = PREV_INSN (from);
1283
0d7e008e
SC
1284 from = emit_jump_insn_after (gen_jump (label), from);
1285 JUMP_LABEL (from) = label;
1286 found_barrier = emit_barrier_after (from);
1287 emit_label_after (label, found_barrier);
b9654711 1288 }
b9654711 1289
8aa2a305 1290 return found_barrier;
0d7e008e 1291}
b9654711 1292
8aa2a305 1293/* Exported to toplev.c.
b9654711 1294
0d7e008e 1295 Scan the function looking for move instructions which have to be changed to
8aa2a305 1296 pc-relative loads and insert the literal tables. */
b9654711 1297
0d7e008e
SC
1298void
1299machine_dependent_reorg (first)
1300 rtx first;
1301{
1302 rtx insn;
8aa2a305 1303
0d7e008e
SC
1304 for (insn = first; insn; insn = NEXT_INSN (insn))
1305 {
1306 if (broken_move (insn))
1307 {
0d7e008e 1308 rtx scan;
8aa2a305
JW
1309 /* Scan ahead looking for a barrier to stick the constant table
1310 behind. */
0d7e008e 1311 rtx barrier = find_barrier (insn);
b9654711 1312
16bea517 1313 /* Now find all the moves between the points and modify them. */
0d7e008e
SC
1314 for (scan = insn; scan != barrier; scan = NEXT_INSN (scan))
1315 {
1316 if (broken_move (scan))
1317 {
1318 rtx pat = PATTERN (scan);
1319 rtx src = SET_SRC (pat);
1320 rtx dst = SET_DEST (pat);
1321 enum machine_mode mode = GET_MODE (dst);
1322 rtx lab;
1323 rtx newinsn;
1324 rtx newsrc;
0d7e008e
SC
1325
1326 if (mode == SImode && hi_const (src))
1327 {
23ed92ca 1328 int offset = 0;
8aa2a305 1329
0d7e008e 1330 mode = HImode;
d3ae8277 1331 while (GET_CODE (dst) == SUBREG)
23ed92ca
JW
1332 {
1333 offset += SUBREG_WORD (dst);
1334 dst = SUBREG_REG (dst);
1335 }
1336 dst = gen_rtx (REG, HImode, REGNO (dst) + offset);
0d7e008e 1337 }
8aa2a305 1338
0d7e008e
SC
1339 lab = add_constant (src, mode);
1340 newsrc = gen_rtx (MEM, mode,
1341 gen_rtx (LABEL_REF, VOIDmode, lab));
8aa2a305
JW
1342 RTX_UNCHANGING_P (newsrc) = 1;
1343 newinsn = emit_insn_after (gen_rtx (SET, VOIDmode,
1344 dst, newsrc), scan);
0d7e008e 1345
0d7e008e
SC
1346 delete_insn (scan);
1347 scan = newinsn;
1348 }
1349 }
1350 dump_table (barrier);
1351 }
1352 }
b9654711
SC
1353}
1354
8aa2a305
JW
1355/* Dump out instruction addresses, which is useful for debugging the
1356 constant pool table stuff. */
1357
1358/* ??? This is unnecessary, and probably should be deleted. This makes
1359 the insn_addresses declaration above unnecessary. */
1360
1361/* ??? The addresses printed by this routine for insns are nonsense for
1362 insns which are inside of a sequence where none of the inner insns have
1363 variable length. This is because the second pass of shorten_branches
1364 does not bother to update them. */
0d7e008e 1365
8e87e161 1366void
8aa2a305
JW
1367final_prescan_insn (insn, opvec, noperands)
1368 rtx insn;
1369 rtx *opvec;
1370 int noperands;
b9654711 1371{
8aa2a305
JW
1372 if (TARGET_DUMPISIZE)
1373 fprintf (asm_out_file, "\n! at %04x\n", insn_addresses[INSN_UID (insn)]);
0d7e008e 1374}
b9654711 1375
8aa2a305
JW
1376/* Dump out any constants accumulated in the final pass. These will
1377 will only be labels. */
b9654711 1378
8aa2a305
JW
1379char *
1380output_jump_label_table ()
0d7e008e 1381{
8aa2a305
JW
1382 int i;
1383
1384 if (pool_size)
1385 {
1386 fprintf (asm_out_file, "\t.align 2\n");
1387 for (i = 0; i < pool_size; i++)
1388 {
1389 pool_node *p = &pool_vector[i];
1390
1391 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "L",
1392 CODE_LABEL_NUMBER (p->label));
1393 output_asm_insn (".long %O0", &p->value);
1394 }
1395 pool_size = 0;
1396 }
b9654711 1397
8aa2a305
JW
1398 return "";
1399}
1400\f
1401/* A full frame looks like:
16bea517
JW
1402
1403 arg-5
1404 arg-4
1405 [ if current_function_anonymous_args
1406 arg-3
1407 arg-2
1408 arg-1
1409 arg-0 ]
1410 saved-fp
1411 saved-r10
1412 saved-r11
1413 saved-r12
1414 saved-pr
1415 local-n
1416 ..
1417 local-1
1418 local-0 <- fp points here. */
8e87e161 1419
8aa2a305
JW
1420/* Number of bytes pushed for anonymous args, used to pass information
1421 between expand_prologue and expand_epilogue. */
1422
1423static int extra_push;
1424
1425/* Adjust the stack and return the number of bytes taken to do it. */
1426
1427static void
46d81ffa 1428output_stack_adjust (size, reg)
8aa2a305 1429 int size;
46d81ffa 1430 rtx reg;
8aa2a305
JW
1431{
1432 if (size)
1433 {
1434 rtx val = GEN_INT (size);
1435 rtx insn;
1436
1437 if (! CONST_OK_FOR_I (size))
1438 {
1439 rtx reg = gen_rtx (REG, SImode, 3);
1440 emit_insn (gen_movsi (reg, val));
1441 val = reg;
1442 }
1443
46d81ffa 1444 insn = gen_addsi3 (reg, reg, val);
8aa2a305
JW
1445 emit_insn (insn);
1446 }
1447}
1448
1449/* Output RTL to push register RN onto the stack. */
1450
1451static void
1452push (rn)
1453 int rn;
1454{
1455 rtx x;
1456 x = emit_insn (gen_push (gen_rtx (REG, SImode, rn)));
1457 REG_NOTES (x) = gen_rtx (EXPR_LIST, REG_INC,
1458 gen_rtx(REG, SImode, STACK_POINTER_REGNUM), 0);
1459}
1460
1461/* Output RTL to pop register RN from the stack. */
1462
1463static void
1464pop (rn)
1465 int rn;
1466{
1467 rtx x;
1468 x = emit_insn (gen_pop (gen_rtx (REG, SImode, rn)));
1469 REG_NOTES (x) = gen_rtx (EXPR_LIST, REG_INC,
1470 gen_rtx(REG, SImode, STACK_POINTER_REGNUM), 0);
1471}
1472
1473/* Generate code to push the regs specified in the mask, and return
1474 the number of bytes the insns take. */
1475
1476static void
1477push_regs (mask)
1478 int mask;
1479{
1480 int i;
1481
1482 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1483 if (mask & (1 << i))
1484 push (i);
1485}
1486
1487/* Work out the registers which need to be saved, both as a mask and a
1488 count.
1489
1490 If doing a pragma interrupt function, then push all regs used by the
1491 function, and if we call another function (we can tell by looking at PR),
1492 make sure that all the regs it clobbers are safe too. */
1493
1494static int
1495calc_live_regs (count_ptr)
1496 int *count_ptr;
1497{
1498 int reg;
1499 int live_regs_mask = 0;
1500 int count = 0;
1501
1502 for (reg = 0; reg < FIRST_PSEUDO_REGISTER; reg++)
1503 {
1504 if (pragma_interrupt && ! pragma_trapa)
1505 {
1506 /* Need to save all the regs ever live. */
1507 if ((regs_ever_live[reg]
1508 || (call_used_regs[reg] && regs_ever_live[PR_REG]))
1509 && reg != STACK_POINTER_REGNUM && reg != ARG_POINTER_REGNUM
1510 && reg != T_REG && reg != GBR_REG)
1511 {
1512 live_regs_mask |= 1 << reg;
1513 count++;
1514 }
1515 }
1516 else
1517 {
1518 /* Only push those regs which are used and need to be saved. */
1519 if (regs_ever_live[reg] && ! call_used_regs[reg])
1520 {
1521 live_regs_mask |= (1 << reg);
1522 count++;
1523 }
1524 }
1525 }
1526
1527 *count_ptr = count;
1528 return live_regs_mask;
1529}
1530
1531/* Code to generate prologue and epilogue sequences */
b9654711
SC
1532
1533void
1534sh_expand_prologue ()
1535{
1536 int live_regs_mask;
40d2032b 1537 int d, i;
b9654711
SC
1538 live_regs_mask = calc_live_regs (&d);
1539
0d7e008e 1540 /* We have pretend args if we had an object sent partially in registers
8aa2a305 1541 and partially on the stack, e.g. a large structure. */
46d81ffa 1542 output_stack_adjust (-current_function_pretend_args_size, stack_pointer_rtx);
b9654711 1543
40d2032b
JW
1544 extra_push = 0;
1545
1546 /* This is set by SETUP_VARARGS to indicate that this is a varargs
1547 routine. Clear it here so that the next function isn't affected. */
b9654711
SC
1548 if (current_function_anonymous_args)
1549 {
40d2032b
JW
1550 current_function_anonymous_args = 0;
1551
16bea517 1552 /* Push arg regs as if they'd been provided by caller in stack. */
b9654711
SC
1553 for (i = 0; i < NPARM_REGS; i++)
1554 {
1555 int rn = NPARM_REGS + FIRST_PARM_REG - i - 1;
79b2746a
JW
1556 if (i > (NPARM_REGS - current_function_args_info
1557 - current_function_varargs))
b9654711
SC
1558 break;
1559 push (rn);
b9654711
SC
1560 extra_push += 4;
1561 }
1562 }
0d7e008e 1563 push_regs (live_regs_mask);
46d81ffa 1564 output_stack_adjust (-get_frame_size (), stack_pointer_rtx);
b9654711
SC
1565
1566 if (frame_pointer_needed)
8aa2a305 1567 emit_insn (gen_movsi (frame_pointer_rtx, stack_pointer_rtx));
b9654711
SC
1568}
1569
1570void
1571sh_expand_epilogue ()
1572{
1573 int live_regs_mask;
40d2032b 1574 int d, i;
b9654711
SC
1575
1576 live_regs_mask = calc_live_regs (&d);
16bea517 1577
b9654711 1578 if (frame_pointer_needed)
46d81ffa
RK
1579 {
1580 /* We deliberately make the add dependent on the frame_pointer,
1581 to ensure that instruction scheduling won't move the stack pointer
1582 adjust before instructions reading from the frame. This can fail
1583 if there is an interrupt which then writes to the stack. */
1584 output_stack_adjust (get_frame_size (), frame_pointer_rtx);
1585 emit_insn (gen_movsi (stack_pointer_rtx, frame_pointer_rtx));
1586 }
1587 else
1588 output_stack_adjust (get_frame_size (), stack_pointer_rtx);
b9654711 1589
16bea517 1590 /* Pop all the registers. */
0d7e008e 1591
b9654711
SC
1592 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1593 {
1594 int j = (FIRST_PSEUDO_REGISTER - 1) - i;
1595 if (live_regs_mask & (1 << j))
8aa2a305 1596 pop (j);
b9654711 1597 }
b9654711 1598
46d81ffa
RK
1599 output_stack_adjust (extra_push + current_function_pretend_args_size,
1600 stack_pointer_rtx);
b9654711
SC
1601}
1602
8aa2a305
JW
1603/* Clear variables at function end. */
1604
1605void
1606function_epilogue (stream, size)
1607 FILE *stream;
1608 int size;
1609{
1610 pragma_interrupt = pragma_trapa = 0;
1611}
1612
0d7e008e
SC
1613/* Define the offset between two registers, one to be eliminated, and
1614 the other its replacement, at the start of a routine. */
1615
1616int
1617initial_elimination_offset (from, to)
8e87e161
SC
1618 int from;
1619 int to;
0d7e008e
SC
1620{
1621 int regs_saved;
0d7e008e
SC
1622 int total_saved_regs_space;
1623 int total_auto_space = get_frame_size ();
8e87e161
SC
1624
1625 calc_live_regs (&regs_saved);
0d7e008e 1626 total_saved_regs_space = (regs_saved) * 4;
b9654711 1627
0d7e008e 1628 if (from == ARG_POINTER_REGNUM && to == FRAME_POINTER_REGNUM)
8aa2a305
JW
1629 return total_saved_regs_space + total_auto_space;
1630
0d7e008e 1631 if (from == ARG_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
8aa2a305
JW
1632 return total_saved_regs_space + total_auto_space;
1633
1634 /* Initial gap between fp and sp is 0. */
0d7e008e 1635 if (from == FRAME_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
8aa2a305
JW
1636 return 0;
1637
0d7e008e
SC
1638 abort ();
1639}
8aa2a305 1640\f
0d7e008e 1641/* Handle machine specific pragmas to be semi-compatible with Hitachi
16bea517 1642 compiler. */
b9654711
SC
1643
1644int
0d7e008e
SC
1645handle_pragma (file)
1646 FILE *file;
b9654711 1647{
0d7e008e
SC
1648 int c;
1649 char pbuf[200];
1650 int psize = 0;
b9654711 1651
0d7e008e
SC
1652 c = getc (file);
1653 while (c == ' ' || c == '\t')
1654 c = getc (file);
1655
1656 if (c == '\n' || c == EOF)
1657 return c;
1658
1659 while (psize < sizeof (pbuf) - 1 && c != '\n')
1660 {
1661 pbuf[psize++] = c;
1662 if (psize == 9 && strncmp (pbuf, "interrupt", 9) == 0)
1663 {
1664 pragma_interrupt = 1;
06c386ea 1665 return ' ';
0d7e008e
SC
1666 }
1667 if (psize == 5 && strncmp (pbuf, "trapa", 5) == 0)
1668 {
1669 pragma_interrupt = pragma_trapa = 1;
06c386ea 1670 return ' ';
0d7e008e
SC
1671 }
1672 c = getc (file);
1673 }
1674 return c;
1675}
1676\f
8aa2a305 1677/* Predicates used by the templates. */
0d7e008e 1678
8aa2a305
JW
1679/* Returns 1 if OP is MACL, MACH or PR. The input must be a REG rtx.
1680 Used only in general_movsrc_operand. */
0d7e008e 1681
8aa2a305
JW
1682int
1683system_reg_operand (op, mode)
1684 rtx op;
1685 enum machine_mode mode;
0d7e008e 1686{
8aa2a305 1687 switch (REGNO (op))
0d7e008e 1688 {
8aa2a305
JW
1689 case PR_REG:
1690 case MACL_REG:
1691 case MACH_REG:
1692 return 1;
0d7e008e 1693 }
8aa2a305 1694 return 0;
0d7e008e 1695}
0d7e008e
SC
1696
1697/* Returns 1 if OP can be source of a simple move operation.
1698 Same as general_operand, but a LABEL_REF is valid, PRE_DEC is
16bea517 1699 invalid as are subregs of system registers. */
0d7e008e
SC
1700
1701int
1702general_movsrc_operand (op, mode)
1703 rtx op;
1704 enum machine_mode mode;
1705{
06c386ea
SC
1706 if (GET_CODE (op) == MEM)
1707 {
1708 rtx inside = XEXP (op, 0);
1709 if (GET_CODE (inside) == CONST)
1710 inside = XEXP (inside, 0);
0d7e008e 1711
06c386ea
SC
1712 if (GET_CODE (inside) == LABEL_REF)
1713 return 1;
8e87e161 1714
06c386ea 1715 if (GET_CODE (inside) == PLUS
8aa2a305
JW
1716 && GET_CODE (XEXP (inside, 0)) == LABEL_REF
1717 && GET_CODE (XEXP (inside, 1)) == CONST_INT)
06c386ea 1718 return 1;
16bea517
JW
1719
1720 /* Only post inc allowed. */
97f8690b 1721 if (GET_CODE (inside) == PRE_DEC)
06c386ea 1722 return 0;
06c386ea 1723 }
0d7e008e
SC
1724
1725 if ((mode == QImode || mode == HImode)
1726 && (GET_CODE (op) == SUBREG
1727 && GET_CODE (XEXP (op, 0)) == REG
1728 && system_reg_operand (XEXP (op, 0), mode)))
1729 return 0;
1730
0d7e008e 1731 return general_operand (op, mode);
b9654711
SC
1732}
1733
0d7e008e
SC
1734/* Returns 1 if OP can be a destination of a move.
1735 Same as general_operand, but no preinc allowed. */
1736
b9654711 1737int
0d7e008e
SC
1738general_movdst_operand (op, mode)
1739 rtx op;
1740 enum machine_mode mode;
b9654711 1741{
16bea517 1742 /* Only pre dec allowed. */
97f8690b 1743 if (GET_CODE (op) == MEM && GET_CODE (XEXP (op, 0)) == POST_INC)
0d7e008e 1744 return 0;
d3ae8277 1745
0d7e008e
SC
1746 return general_operand (op, mode);
1747}
1748
0d7e008e
SC
1749/* Returns 1 if OP is a normal arithmetic register. */
1750
1751int
1752arith_reg_operand (op, mode)
1753 rtx op;
1754 enum machine_mode mode;
1755{
1756 if (register_operand (op, mode))
1757 {
1758 if (GET_CODE (op) == REG)
1759 return (REGNO (op) != T_REG
07c109c8
JW
1760 && REGNO (op) != PR_REG
1761 && REGNO (op) != MACH_REG
1762 && REGNO (op) != MACL_REG);
0d7e008e
SC
1763 return 1;
1764 }
1765 return 0;
1766}
1767
0d7e008e
SC
1768/* Returns 1 if OP is a valid source operand for an arithmetic insn. */
1769
1770int
1771arith_operand (op, mode)
1772 rtx op;
1773 enum machine_mode mode;
1774{
1775 if (arith_reg_operand (op, mode))
1776 return 1;
1777
8aa2a305
JW
1778 if (GET_CODE (op) == CONST_INT && CONST_OK_FOR_I (INTVAL (op)))
1779 return 1;
1780
0d7e008e
SC
1781 return 0;
1782}
1783
22e1ebf1
JW
1784/* Returns 1 if OP is a valid source operand for a compare insn. */
1785
1786int
1787arith_reg_or_0_operand (op, mode)
1788 rtx op;
1789 enum machine_mode mode;
1790{
1791 if (arith_reg_operand (op, mode))
1792 return 1;
1793
8aa2a305
JW
1794 if (GET_CODE (op) == CONST_INT && CONST_OK_FOR_N (INTVAL (op)))
1795 return 1;
1796
22e1ebf1
JW
1797 return 0;
1798}
1799
16bea517 1800/* Returns 1 if OP is a valid source operand for a logical operation. */
0d7e008e
SC
1801
1802int
1803logical_operand (op, mode)
1804 rtx op;
1805 enum machine_mode mode;
1806{
1807 if (arith_reg_operand (op, mode))
1808 return 1;
1809
8aa2a305
JW
1810 if (GET_CODE (op) == CONST_INT && CONST_OK_FOR_L (INTVAL (op)))
1811 return 1;
1812
0d7e008e 1813 return 0;
b9654711 1814}
8aa2a305 1815\f
d3ae8277
SC
1816/* Determine where to put an argument to a function.
1817 Value is zero to push the argument on the stack,
1818 or a hard register in which to store the argument.
1819
1820 MODE is the argument's machine mode.
1821 TYPE is the data type of the argument (as a tree).
1822 This is null for libcalls where that information may
1823 not be available.
1824 CUM is a variable of type CUMULATIVE_ARGS which gives info about
1825 the preceding args and about the function being called.
1826 NAMED is nonzero if this argument is a named parameter
1827 (otherwise it is an extra parameter matching an ellipsis). */
1828
8e87e161 1829rtx
d3ae8277 1830sh_function_arg (cum, mode, type, named)
8e87e161
SC
1831 CUMULATIVE_ARGS cum;
1832 enum machine_mode mode;
1833 tree type;
1834 int named;
d3ae8277
SC
1835{
1836 if (named)
1837 {
8aa2a305 1838 int rr = (ROUND_REG (cum, mode));
d3ae8277
SC
1839
1840 if (rr < NPARM_REGS)
8aa2a305
JW
1841 return ((type == 0 || ! TREE_ADDRESSABLE (type))
1842 ? gen_rtx (REG, mode, FIRST_PARM_REG + rr) : 0);
d3ae8277
SC
1843 }
1844 return 0;
1845}
1846
1847/* For an arg passed partly in registers and partly in memory,
1848 this is the number of registers used.
1849 For args passed entirely in registers or entirely in memory, zero.
1850 Any arg that starts in the first 4 regs but won't entirely fit in them
1851 needs partial registers on the SH. */
1852
1853int
8aa2a305
JW
1854sh_function_arg_partial_nregs (cum, mode, type, named)
1855 CUMULATIVE_ARGS cum;
1856 enum machine_mode mode;
1857 tree type;
1858 int named;
d3ae8277 1859{
8aa2a305 1860 if (cum < NPARM_REGS)
8e87e161 1861 {
8aa2a305
JW
1862 if ((type == 0 || ! TREE_ADDRESSABLE (type))
1863 && (cum + (mode == BLKmode
1864 ? ROUND_ADVANCE (int_size_in_bytes (type))
1865 : ROUND_ADVANCE (GET_MODE_SIZE (mode))) - NPARM_REGS > 0))
1866 return NPARM_REGS - cum;
d3ae8277
SC
1867 }
1868 return 0;
1869}
a55e9d2b
RK
1870\f
1871/* Return non-zero if REG is not used after INSN.
1872 We assume REG is a reload reg, and therefore does
1873 not live past labels or calls or jumps. */
1874int
1875reg_unused_after (reg, insn)
1876 rtx reg;
1877 rtx insn;
1878{
8783b15e 1879 enum rtx_code code;
a55e9d2b
RK
1880 rtx set;
1881
1882 /* If the reg is set by this instruction, then it is safe for our
1883 case. Disregard the case where this is a store to memory, since
1884 we are checking a register used in the store address. */
1885 set = single_set (insn);
1886 if (set && GET_CODE (SET_DEST (set)) != MEM
1887 && reg_overlap_mentioned_p (reg, SET_DEST (set)))
1888 return 1;
1889
1890 while (insn = NEXT_INSN (insn))
1891 {
a55e9d2b 1892 code = GET_CODE (insn);
8783b15e
RK
1893
1894 if (code == CODE_LABEL)
a55e9d2b
RK
1895 return 1;
1896
8783b15e
RK
1897 /* If this is a sequence, we must handle them all at once.
1898 We could have for instance a call that sets the target register,
1899 and a insn in a delay slot that uses the register. In this case,
1900 we must return 0. */
1901 else if (code == INSN && GET_CODE (PATTERN (insn)) == SEQUENCE)
a55e9d2b 1902 {
8783b15e
RK
1903 int i;
1904 int retval = 0;
1905
1906 for (i = 0; i < XVECLEN (PATTERN (insn), 0); i++)
1907 {
1908 rtx this_insn = XVECEXP (PATTERN (insn), 0, i);
1909 rtx set = single_set (this_insn);
1910
1911 if (GET_CODE (this_insn) == CALL_INSN)
1912 code = CALL_INSN;
a55e9d2b 1913
8783b15e
RK
1914 if (set && reg_overlap_mentioned_p (reg, SET_SRC (set)))
1915 return 0;
1916 if (set && reg_overlap_mentioned_p (reg, SET_DEST (set)))
1917 {
1918 if (GET_CODE (SET_DEST (set)) != MEM)
1919 retval = 1;
1920 else
1921 return 0;
1922 }
1923 if (set == 0
1924 && reg_overlap_mentioned_p (reg, PATTERN (this_insn)))
1925 return 0;
1926 }
1927 if (retval == 1)
1928 return 1;
1929 }
1930 else if (GET_RTX_CLASS (code) == 'i')
a55e9d2b
RK
1931 {
1932 rtx set = single_set (insn);
1933
1934 if (set && reg_overlap_mentioned_p (reg, SET_SRC (set)))
1935 return 0;
1936 if (set && reg_overlap_mentioned_p (reg, SET_DEST (set)))
1937 return GET_CODE (SET_DEST (set)) != MEM;
1938 if (set == 0 && reg_overlap_mentioned_p (reg, PATTERN (insn)))
1939 return 0;
1940 }
8783b15e
RK
1941
1942 if (code == CALL_INSN && call_used_regs[REGNO (reg)])
1943 return 1;
a55e9d2b
RK
1944 }
1945 return 1;
1946}
This page took 0.421787 seconds and 5 git commands to generate.