]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/config/mn10300/mn10300.c
configure.target (hpux): Set os_include_dir.
[thirdparty/gcc.git] / gcc / config / mn10300 / mn10300.c
CommitLineData
11bb1f11 1/* Subroutines for insn-output.c for Matsushita MN10300 series
69bc71fa 2 Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
11bb1f11
JL
3 Contributed by Jeff Law (law@cygnus.com).
4
5This file is part of GNU CC.
6
7GNU CC is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2, or (at your option)
10any later version.
11
12GNU CC is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU CC; see the file COPYING. If not, write to
19the Free Software Foundation, 59 Temple Place - Suite 330,
20Boston, MA 02111-1307, USA. */
21
11bb1f11 22#include "config.h"
c5c76735 23#include "system.h"
11bb1f11 24#include "rtl.h"
bf6bb899 25#include "tree.h"
11bb1f11
JL
26#include "regs.h"
27#include "hard-reg-set.h"
28#include "real.h"
29#include "insn-config.h"
30#include "conditions.h"
31#include "insn-flags.h"
32#include "output.h"
33#include "insn-attr.h"
34#include "flags.h"
35#include "recog.h"
36#include "expr.h"
bf6bb899 37#include "function.h"
11bb1f11 38#include "obstack.h"
69bc71fa
KG
39#include "toplev.h"
40#include "tm_p.h"
11bb1f11 41
4d1a91c2
JL
42/* The size of the callee register save area. Right now we save everything
43 on entry since it costs us nothing in code size. It does cost us from a
44 speed standpoint, so we want to optimize this sooner or later. */
980d0e81
JL
45#define REG_SAVE_BYTES (4 * regs_ever_live[2] \
46 + 4 * regs_ever_live[3] \
705ac34f
JL
47 + 4 * regs_ever_live[6] \
48 + 4 * regs_ever_live[7] \
49 + 16 * (regs_ever_live[14] || regs_ever_live[15] \
50 || regs_ever_live[16] || regs_ever_live[17]))
4d1a91c2 51
11bb1f11
JL
52void
53asm_file_start (file)
54 FILE *file;
55{
56 fprintf (file, "#\tGCC For the Matsushita MN10300\n");
57 if (optimize)
58 fprintf (file, "# -O%d\n", optimize);
59 else
60 fprintf (file, "\n\n");
705ac34f
JL
61
62 if (TARGET_AM33)
63 fprintf (file, "\t.am33\n");
11bb1f11
JL
64 output_file_directive (file, main_input_filename);
65}
66\f
67
11bb1f11
JL
68/* Print operand X using operand code CODE to assembly language output file
69 FILE. */
70
71void
72print_operand (file, x, code)
73 FILE *file;
74 rtx x;
75 int code;
76{
77 switch (code)
78 {
79 case 'b':
80 case 'B':
81 /* These are normal and reversed branches. */
82 switch (code == 'b' ? GET_CODE (x) : reverse_condition (GET_CODE (x)))
83 {
84 case NE:
85 fprintf (file, "ne");
86 break;
87 case EQ:
88 fprintf (file, "eq");
89 break;
90 case GE:
91 fprintf (file, "ge");
92 break;
93 case GT:
94 fprintf (file, "gt");
95 break;
96 case LE:
97 fprintf (file, "le");
98 break;
99 case LT:
100 fprintf (file, "lt");
101 break;
102 case GEU:
103 fprintf (file, "cc");
104 break;
105 case GTU:
106 fprintf (file, "hi");
107 break;
108 case LEU:
109 fprintf (file, "ls");
110 break;
111 case LTU:
112 fprintf (file, "cs");
113 break;
114 default:
115 abort ();
116 }
117 break;
118 case 'C':
119 /* This is used for the operand to a call instruction;
120 if it's a REG, enclose it in parens, else output
121 the operand normally. */
122 if (GET_CODE (x) == REG)
123 {
124 fputc ('(', file);
125 print_operand (file, x, 0);
126 fputc (')', file);
127 }
128 else
129 print_operand (file, x, 0);
130 break;
131
38c37a0e
JL
132 /* These are the least significant word in a 64bit value. */
133 case 'L':
134 switch (GET_CODE (x))
135 {
136 case MEM:
137 fputc ('(', file);
138 output_address (XEXP (x, 0));
139 fputc (')', file);
140 break;
141
142 case REG:
143 fprintf (file, "%s", reg_names[REGNO (x)]);
144 break;
145
146 case SUBREG:
147 fprintf (file, "%s",
148 reg_names[REGNO (SUBREG_REG (x)) + SUBREG_WORD (x)]);
149 break;
150
151 case CONST_DOUBLE:
152 {
153 long val[2];
154 REAL_VALUE_TYPE rv;
155
156 switch (GET_MODE (x))
157 {
158 case DFmode:
159 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
160 REAL_VALUE_TO_TARGET_DOUBLE (rv, val);
cf31fafa 161 fprintf (file, "0x%lx", val[0]);
38c37a0e
JL
162 break;;
163 case SFmode:
164 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
165 REAL_VALUE_TO_TARGET_SINGLE (rv, val[0]);
cf31fafa 166 fprintf (file, "0x%lx", val[0]);
38c37a0e
JL
167 break;;
168 case VOIDmode:
169 case DImode:
170 print_operand_address (file,
171 GEN_INT (CONST_DOUBLE_LOW (x)));
172 break;
69bc71fa
KG
173 default:
174 break;
38c37a0e
JL
175 }
176 break;
177 }
178
179 case CONST_INT:
212bc5fa
AO
180 {
181 rtx low, high;
182 split_double (x, &low, &high);
183 fprintf (file, "%ld", (long)INTVAL (low));
184 break;
185 }
38c37a0e
JL
186
187 default:
188 abort ();
189 }
190 break;
191
192 /* Similarly, but for the most significant word. */
193 case 'H':
194 switch (GET_CODE (x))
195 {
196 case MEM:
197 fputc ('(', file);
198 x = adj_offsettable_operand (x, 4);
199 output_address (XEXP (x, 0));
200 fputc (')', file);
201 break;
202
203 case REG:
204 fprintf (file, "%s", reg_names[REGNO (x) + 1]);
205 break;
206
207 case SUBREG:
208 fprintf (file, "%s",
209 reg_names[REGNO (SUBREG_REG (x)) + SUBREG_WORD (x)] + 1);
210 break;
211
212 case CONST_DOUBLE:
213 {
214 long val[2];
215 REAL_VALUE_TYPE rv;
216
217 switch (GET_MODE (x))
218 {
219 case DFmode:
220 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
221 REAL_VALUE_TO_TARGET_DOUBLE (rv, val);
cf31fafa 222 fprintf (file, "0x%lx", val[1]);
38c37a0e
JL
223 break;;
224 case SFmode:
225 abort ();
226 case VOIDmode:
227 case DImode:
228 print_operand_address (file,
229 GEN_INT (CONST_DOUBLE_HIGH (x)));
230 break;
69bc71fa
KG
231 default:
232 break;
38c37a0e
JL
233 }
234 break;
235 }
236
237 case CONST_INT:
212bc5fa
AO
238 {
239 rtx low, high;
240 split_double (x, &low, &high);
241 fprintf (file, "%ld", (long)INTVAL (high));
242 break;
243 }
244
38c37a0e
JL
245 default:
246 abort ();
247 }
248 break;
249
250 case 'A':
251 fputc ('(', file);
252 if (GET_CODE (XEXP (x, 0)) == REG)
c5c76735 253 output_address (gen_rtx_PLUS (SImode, XEXP (x, 0), GEN_INT (0)));
38c37a0e
JL
254 else
255 output_address (XEXP (x, 0));
256 fputc (')', file);
257 break;
258
6fafc523
JL
259 case 'N':
260 output_address (GEN_INT ((~INTVAL (x)) & 0xff));
261 break;
262
576e5acc
JL
263 /* For shift counts. The hardware ignores the upper bits of
264 any immediate, but the assembler will flag an out of range
265 shift count as an error. So we mask off the high bits
266 of the immediate here. */
267 case 'S':
268 if (GET_CODE (x) == CONST_INT)
269 {
270 fprintf (file, "%d", INTVAL (x) & 0x1f);
271 break;
272 }
273 /* FALL THROUGH */
274
11bb1f11
JL
275 default:
276 switch (GET_CODE (x))
277 {
278 case MEM:
279 fputc ('(', file);
280 output_address (XEXP (x, 0));
281 fputc (')', file);
282 break;
283
38c37a0e
JL
284 case PLUS:
285 output_address (x);
286 break;
287
11bb1f11
JL
288 case REG:
289 fprintf (file, "%s", reg_names[REGNO (x)]);
290 break;
291
292 case SUBREG:
293 fprintf (file, "%s",
294 reg_names[REGNO (SUBREG_REG (x)) + SUBREG_WORD (x)]);
295 break;
296
38c37a0e
JL
297 /* This will only be single precision.... */
298 case CONST_DOUBLE:
299 {
300 unsigned long val;
301 REAL_VALUE_TYPE rv;
302
303 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
304 REAL_VALUE_TO_TARGET_SINGLE (rv, val);
cf31fafa 305 fprintf (file, "0x%lx", val);
38c37a0e
JL
306 break;
307 }
308
11bb1f11
JL
309 case CONST_INT:
310 case SYMBOL_REF:
311 case CONST:
312 case LABEL_REF:
313 case CODE_LABEL:
314 print_operand_address (file, x);
315 break;
316 default:
317 abort ();
318 }
319 break;
320 }
321}
322
323/* Output assembly language output for the address ADDR to FILE. */
324
325void
326print_operand_address (file, addr)
327 FILE *file;
328 rtx addr;
329{
330 switch (GET_CODE (addr))
331 {
705ac34f
JL
332 case POST_INC:
333 print_operand_address (file, XEXP (addr, 0));
334 fputc ('+', file);
335 break;
11bb1f11 336 case REG:
79e4122c 337 print_operand (file, addr, 0);
11bb1f11
JL
338 break;
339 case PLUS:
340 {
341 rtx base, index;
342 if (REG_P (XEXP (addr, 0))
343 && REG_OK_FOR_BASE_P (XEXP (addr, 0)))
344 base = XEXP (addr, 0), index = XEXP (addr, 1);
345 else if (REG_P (XEXP (addr, 1))
346 && REG_OK_FOR_BASE_P (XEXP (addr, 1)))
347 base = XEXP (addr, 1), index = XEXP (addr, 0);
348 else
349 abort ();
350 print_operand (file, index, 0);
351 fputc (',', file);
352 print_operand (file, base, 0);;
353 break;
354 }
355 case SYMBOL_REF:
356 output_addr_const (file, addr);
357 break;
358 default:
359 output_addr_const (file, addr);
360 break;
361 }
362}
363
38c37a0e
JL
364int
365can_use_return_insn ()
366{
460f4b9d
JL
367 /* size includes the fixed stack space needed for function calls. */
368 int size = get_frame_size () + current_function_outgoing_args_size;
369
370 /* And space for the return pointer. */
371 size += current_function_outgoing_args_size ? 4 : 0;
38c37a0e
JL
372
373 return (reload_completed
374 && size == 0
375 && !regs_ever_live[2]
376 && !regs_ever_live[3]
377 && !regs_ever_live[6]
378 && !regs_ever_live[7]
705ac34f
JL
379 && !regs_ever_live[14]
380 && !regs_ever_live[15]
381 && !regs_ever_live[16]
382 && !regs_ever_live[17]
38c37a0e
JL
383 && !frame_pointer_needed);
384}
385
11bb1f11
JL
386void
387expand_prologue ()
388{
036182e7 389 HOST_WIDE_INT size;
3dbc43d1 390
3dbc43d1 391 /* SIZE includes the fixed stack space needed for function calls. */
460f4b9d
JL
392 size = get_frame_size () + current_function_outgoing_args_size;
393 size += (current_function_outgoing_args_size ? 4 : 0);
11bb1f11 394
22ef4e9b
JL
395 /* If this is an old-style varargs function, then its arguments
396 need to be flushed back to the stack. */
397 if (current_function_varargs)
398 {
c5c76735
JL
399 emit_move_insn (gen_rtx_MEM (SImode,
400 plus_constant (stack_pointer_rtx, 4)),
401 gen_rtx_REG (SImode, 0));
402 emit_move_insn (gen_rtx_MEM (SImode,
403 plus_constant (stack_pointer_rtx, 8)),
404 gen_rtx_REG (SImode, 1));
22ef4e9b
JL
405 }
406
777fbf09
JL
407 /* And now store all the registers onto the stack with a
408 single two byte instruction. */
409 if (regs_ever_live[2] || regs_ever_live[3]
410 || regs_ever_live[6] || regs_ever_live[7]
705ac34f
JL
411 || regs_ever_live[14] || regs_ever_live[15]
412 || regs_ever_live[16] || regs_ever_live[17]
777fbf09
JL
413 || frame_pointer_needed)
414 emit_insn (gen_store_movm ());
415
416 /* Now put the frame pointer into the frame pointer register. */
11bb1f11 417 if (frame_pointer_needed)
6e86170d 418 emit_move_insn (frame_pointer_rtx, stack_pointer_rtx);
11bb1f11 419
777fbf09 420 /* Allocate stack for this frame. */
11bb1f11
JL
421 if (size)
422 emit_insn (gen_addsi3 (stack_pointer_rtx,
423 stack_pointer_rtx,
424 GEN_INT (-size)));
425}
426
427void
428expand_epilogue ()
429{
036182e7 430 HOST_WIDE_INT size;
3dbc43d1 431
3dbc43d1 432 /* SIZE includes the fixed stack space needed for function calls. */
460f4b9d
JL
433 size = get_frame_size () + current_function_outgoing_args_size;
434 size += (current_function_outgoing_args_size ? 4 : 0);
11bb1f11 435
5d29a95f
JL
436 /* Maybe cut back the stack, except for the register save area.
437
438 If the frame pointer exists, then use the frame pointer to
439 cut back the stack.
440
441 If the stack size + register save area is more than 255 bytes,
442 then the stack must be cut back here since the size + register
443 save size is too big for a ret/retf instruction.
444
445 Else leave it alone, it will be cut back as part of the
446 ret/retf instruction, or there wasn't any stack to begin with.
447
448 Under no circumstanes should the register save area be
449 deallocated here, that would leave a window where an interrupt
450 could occur and trash the register save area. */
11bb1f11
JL
451 if (frame_pointer_needed)
452 {
11bb1f11 453 emit_move_insn (stack_pointer_rtx, frame_pointer_rtx);
4246e0c5
JL
454 size = 0;
455 }
ed6089d6 456 else if (size + REG_SAVE_BYTES > 255)
4246e0c5
JL
457 {
458 emit_insn (gen_addsi3 (stack_pointer_rtx,
459 stack_pointer_rtx,
460 GEN_INT (size)));
461 size = 0;
11bb1f11 462 }
11bb1f11 463
ed6089d6
AO
464 /* Adjust the stack and restore callee-saved registers, if any. */
465 if (size || regs_ever_live[2] || regs_ever_live[3]
777fbf09 466 || regs_ever_live[6] || regs_ever_live[7]
705ac34f
JL
467 || regs_ever_live[14] || regs_ever_live[15]
468 || regs_ever_live[16] || regs_ever_live[17]
777fbf09 469 || frame_pointer_needed)
ed6089d6
AO
470 emit_jump_insn (gen_return_internal_regs
471 (GEN_INT (size + REG_SAVE_BYTES)));
777fbf09 472 else
ed6089d6 473 emit_jump_insn (gen_return_internal ());
11bb1f11
JL
474}
475
476/* Update the condition code from the insn. */
477
478void
479notice_update_cc (body, insn)
480 rtx body;
481 rtx insn;
482{
11bb1f11
JL
483 switch (get_attr_cc (insn))
484 {
485 case CC_NONE:
486 /* Insn does not affect CC at all. */
487 break;
488
489 case CC_NONE_0HIT:
490 /* Insn does not change CC, but the 0'th operand has been changed. */
491 if (cc_status.value1 != 0
1ccbefce 492 && reg_overlap_mentioned_p (recog_data.operand[0], cc_status.value1))
11bb1f11
JL
493 cc_status.value1 = 0;
494 break;
495
d116300b 496 case CC_SET_ZN:
1ccbefce 497 /* Insn sets the Z,N flags of CC to recog_data.operand[0].
d116300b 498 V,C are unusable. */
11bb1f11 499 CC_STATUS_INIT;
d116300b 500 cc_status.flags |= CC_NO_CARRY | CC_OVERFLOW_UNUSABLE;
1ccbefce 501 cc_status.value1 = recog_data.operand[0];
11bb1f11
JL
502 break;
503
d116300b 504 case CC_SET_ZNV:
1ccbefce 505 /* Insn sets the Z,N,V flags of CC to recog_data.operand[0].
d116300b 506 C is unusable. */
82c6faa8 507 CC_STATUS_INIT;
d116300b 508 cc_status.flags |= CC_NO_CARRY;
1ccbefce 509 cc_status.value1 = recog_data.operand[0];
82c6faa8
JL
510 break;
511
11bb1f11
JL
512 case CC_COMPARE:
513 /* The insn is a compare instruction. */
514 CC_STATUS_INIT;
515 cc_status.value1 = SET_SRC (body);
516 break;
517
3b800f71
JL
518 case CC_INVERT:
519 /* The insn is a compare instruction. */
520 CC_STATUS_INIT;
521 cc_status.value1 = SET_SRC (body);
522 cc_status.flags |= CC_INVERTED;
523 break;
524
11bb1f11
JL
525 case CC_CLOBBER:
526 /* Insn doesn't leave CC in a usable state. */
527 CC_STATUS_INIT;
528 break;
82c6faa8
JL
529
530 default:
531 abort ();
11bb1f11 532 }
11bb1f11
JL
533}
534
535/* Return true if OP is a valid call operand. */
536
537int
538call_address_operand (op, mode)
539 rtx op;
69bc71fa 540 enum machine_mode mode ATTRIBUTE_UNUSED;
11bb1f11
JL
541{
542 return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == REG);
543}
544
545/* What (if any) secondary registers are needed to move IN with mode
8493cfcb 546 MODE into a register in register class CLASS.
11bb1f11
JL
547
548 We might be able to simplify this. */
549enum reg_class
550secondary_reload_class (class, mode, in)
551 enum reg_class class;
552 enum machine_mode mode;
553 rtx in;
554{
11bb1f11
JL
555 /* Memory loads less than a full word wide can't have an
556 address or stack pointer destination. They must use
557 a data register as an intermediate register. */
15c09738
AH
558 if ((GET_CODE (in) == MEM
559 || (GET_CODE (in) == REG
560 && REGNO (in) >= FIRST_PSEUDO_REGISTER)
561 || (GET_CODE (in) == SUBREG
562 && GET_CODE (SUBREG_REG (in)) == REG
563 && REGNO (SUBREG_REG (in)) >= FIRST_PSEUDO_REGISTER))
11bb1f11 564 && (mode == QImode || mode == HImode)
15c09738 565 && (class == ADDRESS_REGS || class == SP_REGS
842a0788 566 || class == SP_OR_ADDRESS_REGS))
4d1a91c2 567 {
705ac34f
JL
568 if (TARGET_AM33)
569 return DATA_OR_EXTENDED_REGS;
4d1a91c2
JL
570 return DATA_REGS;
571 }
11bb1f11
JL
572
573 /* We can't directly load sp + const_int into a data register;
574 we must use an address register as an intermediate. */
777fbf09
JL
575 if (class != SP_REGS
576 && class != ADDRESS_REGS
577 && class != SP_OR_ADDRESS_REGS
705ac34f
JL
578 && class != SP_OR_EXTENDED_REGS
579 && class != ADDRESS_OR_EXTENDED_REGS
580 && class != SP_OR_ADDRESS_OR_EXTENDED_REGS
11bb1f11
JL
581 && (in == stack_pointer_rtx
582 || (GET_CODE (in) == PLUS
777fbf09
JL
583 && (XEXP (in, 0) == stack_pointer_rtx
584 || XEXP (in, 1) == stack_pointer_rtx))))
11bb1f11
JL
585 return ADDRESS_REGS;
586
4c742813
JL
587 if (GET_CODE (in) == PLUS
588 && (XEXP (in, 0) == stack_pointer_rtx
589 || XEXP (in, 1) == stack_pointer_rtx))
4d1a91c2 590 {
705ac34f
JL
591 if (TARGET_AM33)
592 return DATA_OR_EXTENDED_REGS;
4d1a91c2
JL
593 return DATA_REGS;
594 }
4c742813 595
777fbf09
JL
596 /* Otherwise assume no secondary reloads are needed. */
597 return NO_REGS;
598}
599
600int
601initial_offset (from, to)
602 int from, to;
603{
3dbc43d1
JL
604 /* The difference between the argument pointer and the frame pointer
605 is the size of the callee register save area. */
777fbf09 606 if (from == ARG_POINTER_REGNUM && to == FRAME_POINTER_REGNUM)
11bb1f11 607 {
777fbf09
JL
608 if (regs_ever_live[2] || regs_ever_live[3]
609 || regs_ever_live[6] || regs_ever_live[7]
705ac34f
JL
610 || regs_ever_live[14] || regs_ever_live[15]
611 || regs_ever_live[16] || regs_ever_live[17]
777fbf09 612 || frame_pointer_needed)
4d1a91c2 613 return REG_SAVE_BYTES;
777fbf09 614 else
22ef4e9b 615 return 0;
11bb1f11
JL
616 }
617
3dbc43d1
JL
618 /* The difference between the argument pointer and the stack pointer is
619 the sum of the size of this function's frame, the callee register save
620 area, and the fixed stack space needed for function calls (if any). */
777fbf09
JL
621 if (from == ARG_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
622 {
623 if (regs_ever_live[2] || regs_ever_live[3]
624 || regs_ever_live[6] || regs_ever_live[7]
705ac34f
JL
625 || regs_ever_live[14] || regs_ever_live[15]
626 || regs_ever_live[16] || regs_ever_live[17]
777fbf09 627 || frame_pointer_needed)
4d1a91c2 628 return (get_frame_size () + REG_SAVE_BYTES
460f4b9d
JL
629 + (current_function_outgoing_args_size
630 ? current_function_outgoing_args_size + 4 : 0));
777fbf09 631 else
460f4b9d
JL
632 return (get_frame_size ()
633 + (current_function_outgoing_args_size
634 ? current_function_outgoing_args_size + 4 : 0));
777fbf09 635 }
11bb1f11 636
3dbc43d1
JL
637 /* The difference between the frame pointer and stack pointer is the sum
638 of the size of this function's frame and the fixed stack space needed
639 for function calls (if any). */
777fbf09 640 if (from == FRAME_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
460f4b9d
JL
641 return (get_frame_size ()
642 + (current_function_outgoing_args_size
643 ? current_function_outgoing_args_size + 4 : 0));
777fbf09
JL
644
645 abort ();
11bb1f11 646}
22ef4e9b
JL
647
648/* Flush the argument registers to the stack for a stdarg function;
649 return the new argument pointer. */
650rtx
648d2ffc 651mn10300_builtin_saveregs ()
22ef4e9b 652{
fc2acc87 653 rtx offset, mem;
22ef4e9b
JL
654 tree fntype = TREE_TYPE (current_function_decl);
655 int argadj = ((!(TYPE_ARG_TYPES (fntype) != 0
656 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
657 != void_type_node)))
658 ? UNITS_PER_WORD : 0);
fc2acc87 659 int set = get_varargs_alias_set ();
22ef4e9b
JL
660
661 if (argadj)
662 offset = plus_constant (current_function_arg_offset_rtx, argadj);
663 else
664 offset = current_function_arg_offset_rtx;
665
fc2acc87
RH
666 mem = gen_rtx_MEM (SImode, current_function_internal_arg_pointer);
667 MEM_ALIAS_SET (mem) = set;
668 emit_move_insn (mem, gen_rtx_REG (SImode, 0));
669
670 mem = gen_rtx_MEM (SImode,
671 plus_constant (current_function_internal_arg_pointer, 4));
672 MEM_ALIAS_SET (mem) = set;
673 emit_move_insn (mem, gen_rtx_REG (SImode, 1));
674
22ef4e9b
JL
675 return copy_to_reg (expand_binop (Pmode, add_optab,
676 current_function_internal_arg_pointer,
677 offset, 0, 0, OPTAB_LIB_WIDEN));
678}
679
fc2acc87
RH
680void
681mn10300_va_start (stdarg_p, valist, nextarg)
682 int stdarg_p;
683 tree valist;
684 rtx nextarg;
685{
686 if (stdarg_p)
687 nextarg = expand_builtin_saveregs ();
688
689 std_expand_builtin_va_start (stdarg_p, valist, nextarg);
690}
691
692rtx
693mn10300_va_arg (valist, type)
694 tree valist, type;
695{
696 HOST_WIDE_INT align, rsize;
697 tree t, ptr, pptr;
698
699 /* Compute the rounded size of the type. */
700 align = PARM_BOUNDARY / BITS_PER_UNIT;
701 rsize = (((int_size_in_bytes (type) + align - 1) / align) * align);
702
703 t = build (POSTINCREMENT_EXPR, TREE_TYPE (valist), valist,
704 build_int_2 ((rsize > 8 ? 4 : rsize), 0));
705 TREE_SIDE_EFFECTS (t) = 1;
706
707 ptr = build_pointer_type (type);
708
709 /* "Large" types are passed by reference. */
710 if (rsize > 8)
711 {
712 pptr = build_pointer_type (ptr);
713 t = build1 (NOP_EXPR, pptr, t);
714 TREE_SIDE_EFFECTS (t) = 1;
715
716 t = build1 (INDIRECT_REF, ptr, t);
717 TREE_SIDE_EFFECTS (t) = 1;
718 }
719 else
720 {
721 t = build1 (NOP_EXPR, ptr, t);
722 TREE_SIDE_EFFECTS (t) = 1;
723 }
724
725 /* Calculate! */
726 return expand_expr (t, NULL_RTX, Pmode, EXPAND_NORMAL);
727}
728
22ef4e9b
JL
729/* Return an RTX to represent where a value with mode MODE will be returned
730 from a function. If the result is 0, the argument is pushed. */
731
732rtx
733function_arg (cum, mode, type, named)
734 CUMULATIVE_ARGS *cum;
735 enum machine_mode mode;
736 tree type;
69bc71fa 737 int named ATTRIBUTE_UNUSED;
22ef4e9b
JL
738{
739 rtx result = 0;
740 int size, align;
741
742 /* We only support using 2 data registers as argument registers. */
743 int nregs = 2;
744
745 /* Figure out the size of the object to be passed. */
746 if (mode == BLKmode)
747 size = int_size_in_bytes (type);
748 else
749 size = GET_MODE_SIZE (mode);
750
751 /* Figure out the alignment of the object to be passed. */
752 align = size;
753
754 cum->nbytes = (cum->nbytes + 3) & ~3;
755
756 /* Don't pass this arg via a register if all the argument registers
757 are used up. */
758 if (cum->nbytes > nregs * UNITS_PER_WORD)
759 return 0;
760
761 /* Don't pass this arg via a register if it would be split between
762 registers and memory. */
763 if (type == NULL_TREE
764 && cum->nbytes + size > nregs * UNITS_PER_WORD)
765 return 0;
766
767 switch (cum->nbytes / UNITS_PER_WORD)
768 {
769 case 0:
c5c76735 770 result = gen_rtx_REG (mode, 0);
22ef4e9b
JL
771 break;
772 case 1:
c5c76735 773 result = gen_rtx_REG (mode, 1);
22ef4e9b
JL
774 break;
775 default:
776 result = 0;
777 }
778
779 return result;
780}
781
782/* Return the number of registers to use for an argument passed partially
783 in registers and partially in memory. */
784
785int
786function_arg_partial_nregs (cum, mode, type, named)
787 CUMULATIVE_ARGS *cum;
788 enum machine_mode mode;
789 tree type;
69bc71fa 790 int named ATTRIBUTE_UNUSED;
22ef4e9b
JL
791{
792 int size, align;
793
794 /* We only support using 2 data registers as argument registers. */
795 int nregs = 2;
796
797 /* Figure out the size of the object to be passed. */
798 if (mode == BLKmode)
799 size = int_size_in_bytes (type);
800 else
801 size = GET_MODE_SIZE (mode);
802
803 /* Figure out the alignment of the object to be passed. */
804 align = size;
805
806 cum->nbytes = (cum->nbytes + 3) & ~3;
807
808 /* Don't pass this arg via a register if all the argument registers
809 are used up. */
810 if (cum->nbytes > nregs * UNITS_PER_WORD)
811 return 0;
812
813 if (cum->nbytes + size <= nregs * UNITS_PER_WORD)
814 return 0;
815
816 /* Don't pass this arg via a register if it would be split between
817 registers and memory. */
818 if (type == NULL_TREE
819 && cum->nbytes + size > nregs * UNITS_PER_WORD)
820 return 0;
821
822 return (nregs * UNITS_PER_WORD - cum->nbytes) / UNITS_PER_WORD;
823}
824
825/* Output a tst insn. */
826char *
827output_tst (operand, insn)
828 rtx operand, insn;
829{
22ef4e9b
JL
830 rtx temp;
831 int past_call = 0;
832
833 /* We can save a byte if we can find a register which has the value
834 zero in it. */
835 temp = PREV_INSN (insn);
74452ac3 836 while (optimize && temp)
22ef4e9b
JL
837 {
838 rtx set;
839
840 /* We allow the search to go through call insns. We record
841 the fact that we've past a CALL_INSN and reject matches which
842 use call clobbered registers. */
843 if (GET_CODE (temp) == CODE_LABEL
844 || GET_CODE (temp) == JUMP_INSN
845 || GET_CODE (temp) == BARRIER)
846 break;
847
848 if (GET_CODE (temp) == CALL_INSN)
849 past_call = 1;
850
851 if (GET_CODE (temp) == NOTE)
852 {
853 temp = PREV_INSN (temp);
854 continue;
855 }
856
857 /* It must be an insn, see if it is a simple set. */
858 set = single_set (temp);
859 if (!set)
860 {
861 temp = PREV_INSN (temp);
862 continue;
863 }
864
865 /* Are we setting a data register to zero (this does not win for
866 address registers)?
867
868 If it's a call clobbered register, have we past a call?
869
870 Make sure the register we find isn't the same as ourself;
4d1a91c2
JL
871 the mn10300 can't encode that.
872
873 ??? reg_set_between_p return nonzero anytime we pass a CALL_INSN
874 so the code to detect calls here isn't doing anything useful. */
22ef4e9b
JL
875 if (REG_P (SET_DEST (set))
876 && SET_SRC (set) == CONST0_RTX (GET_MODE (SET_DEST (set)))
877 && !reg_set_between_p (SET_DEST (set), temp, insn)
74452ac3
JL
878 && (REGNO_REG_CLASS (REGNO (SET_DEST (set)))
879 == REGNO_REG_CLASS (REGNO (operand)))
705ac34f
JL
880 && REGNO_REG_CLASS (REGNO (SET_DEST (set))) != EXTENDED_REGS
881 && REGNO (SET_DEST (set)) != REGNO (operand)
882 && (!past_call
883 || !call_used_regs[REGNO (SET_DEST (set))]))
884 {
885 rtx xoperands[2];
886 xoperands[0] = operand;
887 xoperands[1] = SET_DEST (set);
888
889 output_asm_insn ("cmp %1,%0", xoperands);
890 return "";
891 }
892
893 if (REGNO_REG_CLASS (REGNO (operand)) == EXTENDED_REGS
894 && REG_P (SET_DEST (set))
895 && SET_SRC (set) == CONST0_RTX (GET_MODE (SET_DEST (set)))
896 && !reg_set_between_p (SET_DEST (set), temp, insn)
897 && (REGNO_REG_CLASS (REGNO (SET_DEST (set)))
898 != REGNO_REG_CLASS (REGNO (operand)))
899 && REGNO_REG_CLASS (REGNO (SET_DEST (set))) == EXTENDED_REGS
22ef4e9b
JL
900 && REGNO (SET_DEST (set)) != REGNO (operand)
901 && (!past_call
902 || !call_used_regs[REGNO (SET_DEST (set))]))
903 {
904 rtx xoperands[2];
905 xoperands[0] = operand;
906 xoperands[1] = SET_DEST (set);
907
908 output_asm_insn ("cmp %1,%0", xoperands);
909 return "";
910 }
911 temp = PREV_INSN (temp);
912 }
913 return "cmp 0,%0";
914}
460f4b9d
JL
915
916int
917impossible_plus_operand (op, mode)
918 rtx op;
69bc71fa 919 enum machine_mode mode ATTRIBUTE_UNUSED;
460f4b9d 920{
460f4b9d
JL
921 if (GET_CODE (op) != PLUS)
922 return 0;
923
4c742813
JL
924 if (XEXP (op, 0) == stack_pointer_rtx
925 || XEXP (op, 1) == stack_pointer_rtx)
460f4b9d
JL
926 return 1;
927
460f4b9d
JL
928 return 0;
929}
e9ad4573 930
f8912297
JL
931/* Return 1 if X is a CONST_INT that is only 8 bits wide. This is used
932 for the btst insn which may examine memory or a register (the memory
933 variant only allows an unsigned 8 bit integer). */
934int
935const_8bit_operand (op, mode)
936 register rtx op;
69bc71fa 937 enum machine_mode mode ATTRIBUTE_UNUSED;
f8912297
JL
938{
939 return (GET_CODE (op) == CONST_INT
940 && INTVAL (op) >= 0
941 && INTVAL (op) < 256);
942}
943
944/* Similarly, but when using a zero_extract pattern for a btst where
945 the source operand might end up in memory. */
946int
947mask_ok_for_mem_btst (len, bit)
948 int len;
949 int bit;
950{
951 int mask = 0;
952
953 while (len > 0)
954 {
955 mask |= (1 << bit);
956 bit++;
957 len--;
958 }
959
960 /* MASK must bit into an 8bit value. */
961 return (((mask & 0xff) == mask)
962 || ((mask & 0xff00) == mask)
963 || ((mask & 0xff0000) == mask)
964 || ((mask & 0xff000000) == mask));
965}
966
e9ad4573
JL
967/* Return 1 if X contains a symbolic expression. We know these
968 expressions will have one of a few well defined forms, so
969 we need only check those forms. */
970int
971symbolic_operand (op, mode)
972 register rtx op;
69bc71fa 973 enum machine_mode mode ATTRIBUTE_UNUSED;
e9ad4573
JL
974{
975 switch (GET_CODE (op))
976 {
977 case SYMBOL_REF:
978 case LABEL_REF:
979 return 1;
980 case CONST:
981 op = XEXP (op, 0);
982 return ((GET_CODE (XEXP (op, 0)) == SYMBOL_REF
983 || GET_CODE (XEXP (op, 0)) == LABEL_REF)
984 && GET_CODE (XEXP (op, 1)) == CONST_INT);
985 default:
986 return 0;
987 }
988}
989
990/* Try machine dependent ways of modifying an illegitimate address
991 to be legitimate. If we find one, return the new valid address.
992 This macro is used in only one place: `memory_address' in explow.c.
993
994 OLDX is the address as it was before break_out_memory_refs was called.
995 In some cases it is useful to look at this to decide what needs to be done.
996
997 MODE and WIN are passed so that this macro can use
998 GO_IF_LEGITIMATE_ADDRESS.
999
1000 Normally it is always safe for this macro to do nothing. It exists to
1001 recognize opportunities to optimize the output.
1002
1003 But on a few ports with segmented architectures and indexed addressing
1004 (mn10300, hppa) it is used to rewrite certain problematical addresses. */
1005rtx
1006legitimize_address (x, oldx, mode)
1007 rtx x;
69bc71fa
KG
1008 rtx oldx ATTRIBUTE_UNUSED;
1009 enum machine_mode mode ATTRIBUTE_UNUSED;
e9ad4573
JL
1010{
1011 /* Uh-oh. We might have an address for x[n-100000]. This needs
1012 special handling to avoid creating an indexed memory address
1013 with x-100000 as the base. */
1014 if (GET_CODE (x) == PLUS
1015 && symbolic_operand (XEXP (x, 1), VOIDmode))
1016 {
1017 /* Ugly. We modify things here so that the address offset specified
1018 by the index expression is computed first, then added to x to form
1019 the entire address. */
1020
69bc71fa 1021 rtx regx1, regy1, regy2, y;
e9ad4573
JL
1022
1023 /* Strip off any CONST. */
1024 y = XEXP (x, 1);
1025 if (GET_CODE (y) == CONST)
1026 y = XEXP (y, 0);
1027
bf4219f0
JL
1028 if (GET_CODE (y) == PLUS || GET_CODE (y) == MINUS)
1029 {
1030 regx1 = force_reg (Pmode, force_operand (XEXP (x, 0), 0));
1031 regy1 = force_reg (Pmode, force_operand (XEXP (y, 0), 0));
1032 regy2 = force_reg (Pmode, force_operand (XEXP (y, 1), 0));
1033 regx1 = force_reg (Pmode,
1034 gen_rtx (GET_CODE (y), Pmode, regx1, regy2));
c5c76735 1035 return force_reg (Pmode, gen_rtx_PLUS (Pmode, regx1, regy1));
bf4219f0 1036 }
e9ad4573 1037 }
371036e0 1038 return x;
e9ad4573 1039}
460ad325
AO
1040
1041int
1042mn10300_address_cost (x, unsig)
1043 rtx x;
1044 int *unsig;
1045{
1046 int _s = 0;
1047 if (unsig == 0)
1048 unsig = &_s;
1049
1050 switch (GET_CODE (x))
1051 {
1052 case REG:
1053 switch (REGNO_REG_CLASS (REGNO (x)))
1054 {
1055 case SP_REGS:
1056 *unsig = 1;
1057 return 0;
1058
1059 case ADDRESS_REGS:
1060 return 1;
1061
1062 case DATA_REGS:
1063 case EXTENDED_REGS:
1064 return 3;
1065
1066 case NO_REGS:
1067 return 5;
1068
1069 default:
1070 abort ();
1071 }
1072
1073 case PLUS:
1074 case MINUS:
d82704fb
AO
1075 case ASHIFT:
1076 case AND:
460ad325
AO
1077 case IOR:
1078 return (mn10300_address_cost (XEXP (x, 0), unsig)
1079 + mn10300_address_cost (XEXP (x, 1), unsig));
1080
1081 case EXPR_LIST:
1082 case SUBREG:
1083 case MEM:
1084 return ADDRESS_COST (XEXP (x, 0));
1085
1086 case ZERO_EXTEND:
1087 *unsig = 1;
1088 return mn10300_address_cost (XEXP (x, 0), unsig);
1089
1090 case CONST_INT:
1091 if (INTVAL (x) == 0)
1092 return 0;
1093 if (INTVAL (x) + (*unsig ? 0 : 0x80) < 0x100)
1094 return 1;
1095 if (INTVAL (x) + (*unsig ? 0 : 0x8000) < 0x10000)
1096 return 3;
1097 if (INTVAL (x) + (*unsig ? 0 : 0x800000) < 0x1000000)
1098 return 5;
1099 return 7;
1100
1101 case CONST:
1102 case SYMBOL_REF:
d82704fb 1103 case LABEL_REF:
460ad325
AO
1104 return 8;
1105
1106 case ADDRESSOF:
1107 switch (GET_CODE (XEXP (x, 0)))
1108 {
1109 case MEM:
1110 return ADDRESS_COST (XEXP (x, 0));
1111
1112 case REG:
1113 return 1;
1114
1115 default:
1116 abort ();
1117 }
1118
1119 default:
1120 abort ();
1121
1122 }
1123}