]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/config/mn10300/mn10300.c
calls.c (emit_library_call): Handle saving of stack slots when ACCUMULATE_OUTGOING_AR...
[thirdparty/gcc.git] / gcc / config / mn10300 / mn10300.c
CommitLineData
11bb1f11 1/* Subroutines for insn-output.c for Matsushita MN10300 series
74452ac3 2 Copyright (C) 1996, 1997 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
22#include <stdio.h>
23#include "config.h"
24#include "rtl.h"
25#include "regs.h"
26#include "hard-reg-set.h"
27#include "real.h"
28#include "insn-config.h"
29#include "conditions.h"
30#include "insn-flags.h"
31#include "output.h"
32#include "insn-attr.h"
33#include "flags.h"
34#include "recog.h"
35#include "expr.h"
36#include "tree.h"
37#include "obstack.h"
38
74452ac3
JL
39/* Global registers known to hold the value zero.
40
41 Normally we'd depend on CSE and combine to put zero into a
42 register and re-use it.
43
44 However, on the mn10x00 processors we implicitly use the constant
45 zero in tst instructions, so we might be able to do better by
46 loading the value into a register in the prologue, then re-useing
47 that register throughout the function.
48
49 We could perform similar optimizations for other constants, but with
50 gcse due soon, it doesn't seem worth the effort.
51
52 These variables hold a rtx for a register known to hold the value
53 zero throughout the entire function, or NULL if no register of
54 the appropriate class has such a value throughout the life of the
55 function. */
56rtx zero_dreg;
57rtx zero_areg;
58
11bb1f11
JL
59void
60asm_file_start (file)
61 FILE *file;
62{
63 fprintf (file, "#\tGCC For the Matsushita MN10300\n");
64 if (optimize)
65 fprintf (file, "# -O%d\n", optimize);
66 else
67 fprintf (file, "\n\n");
68 output_file_directive (file, main_input_filename);
69}
70\f
71
11bb1f11
JL
72/* Print operand X using operand code CODE to assembly language output file
73 FILE. */
74
75void
76print_operand (file, x, code)
77 FILE *file;
78 rtx x;
79 int code;
80{
81 switch (code)
82 {
83 case 'b':
84 case 'B':
85 /* These are normal and reversed branches. */
86 switch (code == 'b' ? GET_CODE (x) : reverse_condition (GET_CODE (x)))
87 {
88 case NE:
89 fprintf (file, "ne");
90 break;
91 case EQ:
92 fprintf (file, "eq");
93 break;
94 case GE:
95 fprintf (file, "ge");
96 break;
97 case GT:
98 fprintf (file, "gt");
99 break;
100 case LE:
101 fprintf (file, "le");
102 break;
103 case LT:
104 fprintf (file, "lt");
105 break;
106 case GEU:
107 fprintf (file, "cc");
108 break;
109 case GTU:
110 fprintf (file, "hi");
111 break;
112 case LEU:
113 fprintf (file, "ls");
114 break;
115 case LTU:
116 fprintf (file, "cs");
117 break;
118 default:
119 abort ();
120 }
121 break;
122 case 'C':
123 /* This is used for the operand to a call instruction;
124 if it's a REG, enclose it in parens, else output
125 the operand normally. */
126 if (GET_CODE (x) == REG)
127 {
128 fputc ('(', file);
129 print_operand (file, x, 0);
130 fputc (')', file);
131 }
132 else
133 print_operand (file, x, 0);
134 break;
135
38c37a0e
JL
136 /* These are the least significant word in a 64bit value. */
137 case 'L':
138 switch (GET_CODE (x))
139 {
140 case MEM:
141 fputc ('(', file);
142 output_address (XEXP (x, 0));
143 fputc (')', file);
144 break;
145
146 case REG:
147 fprintf (file, "%s", reg_names[REGNO (x)]);
148 break;
149
150 case SUBREG:
151 fprintf (file, "%s",
152 reg_names[REGNO (SUBREG_REG (x)) + SUBREG_WORD (x)]);
153 break;
154
155 case CONST_DOUBLE:
156 {
157 long val[2];
158 REAL_VALUE_TYPE rv;
159
160 switch (GET_MODE (x))
161 {
162 case DFmode:
163 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
164 REAL_VALUE_TO_TARGET_DOUBLE (rv, val);
165 print_operand_address (file, GEN_INT (val[0]));
166 break;;
167 case SFmode:
168 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
169 REAL_VALUE_TO_TARGET_SINGLE (rv, val[0]);
170 print_operand_address (file, GEN_INT (val[0]));
171 break;;
172 case VOIDmode:
173 case DImode:
174 print_operand_address (file,
175 GEN_INT (CONST_DOUBLE_LOW (x)));
176 break;
177 }
178 break;
179 }
180
181 case CONST_INT:
182 print_operand_address (file, x);
183 break;
184
185 default:
186 abort ();
187 }
188 break;
189
190 /* Similarly, but for the most significant word. */
191 case 'H':
192 switch (GET_CODE (x))
193 {
194 case MEM:
195 fputc ('(', file);
196 x = adj_offsettable_operand (x, 4);
197 output_address (XEXP (x, 0));
198 fputc (')', file);
199 break;
200
201 case REG:
202 fprintf (file, "%s", reg_names[REGNO (x) + 1]);
203 break;
204
205 case SUBREG:
206 fprintf (file, "%s",
207 reg_names[REGNO (SUBREG_REG (x)) + SUBREG_WORD (x)] + 1);
208 break;
209
210 case CONST_DOUBLE:
211 {
212 long val[2];
213 REAL_VALUE_TYPE rv;
214
215 switch (GET_MODE (x))
216 {
217 case DFmode:
218 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
219 REAL_VALUE_TO_TARGET_DOUBLE (rv, val);
220 print_operand_address (file, GEN_INT (val[1]));
221 break;;
222 case SFmode:
223 abort ();
224 case VOIDmode:
225 case DImode:
226 print_operand_address (file,
227 GEN_INT (CONST_DOUBLE_HIGH (x)));
228 break;
229 }
230 break;
231 }
232
233 case CONST_INT:
234 if (INTVAL (x) < 0)
235 print_operand_address (file, GEN_INT (-1));
236 else
237 print_operand_address (file, GEN_INT (0));
238 break;
239 default:
240 abort ();
241 }
242 break;
243
244 case 'A':
245 fputc ('(', file);
246 if (GET_CODE (XEXP (x, 0)) == REG)
247 output_address (gen_rtx (PLUS, SImode, XEXP (x, 0), GEN_INT (0)));
248 else
249 output_address (XEXP (x, 0));
250 fputc (')', file);
251 break;
252
6fafc523
JL
253 case 'N':
254 output_address (GEN_INT ((~INTVAL (x)) & 0xff));
255 break;
256
11bb1f11
JL
257 default:
258 switch (GET_CODE (x))
259 {
260 case MEM:
261 fputc ('(', file);
262 output_address (XEXP (x, 0));
263 fputc (')', file);
264 break;
265
38c37a0e
JL
266 case PLUS:
267 output_address (x);
268 break;
269
11bb1f11
JL
270 case REG:
271 fprintf (file, "%s", reg_names[REGNO (x)]);
272 break;
273
274 case SUBREG:
275 fprintf (file, "%s",
276 reg_names[REGNO (SUBREG_REG (x)) + SUBREG_WORD (x)]);
277 break;
278
38c37a0e
JL
279 /* This will only be single precision.... */
280 case CONST_DOUBLE:
281 {
282 unsigned long val;
283 REAL_VALUE_TYPE rv;
284
285 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
286 REAL_VALUE_TO_TARGET_SINGLE (rv, val);
287 print_operand_address (file, GEN_INT (val));
288 break;
289 }
290
11bb1f11
JL
291 case CONST_INT:
292 case SYMBOL_REF:
293 case CONST:
294 case LABEL_REF:
295 case CODE_LABEL:
296 print_operand_address (file, x);
297 break;
298 default:
299 abort ();
300 }
301 break;
302 }
303}
304
305/* Output assembly language output for the address ADDR to FILE. */
306
307void
308print_operand_address (file, addr)
309 FILE *file;
310 rtx addr;
311{
312 switch (GET_CODE (addr))
313 {
314 case REG:
315 if (addr == stack_pointer_rtx)
316 print_operand_address (file, gen_rtx (PLUS, SImode,
317 stack_pointer_rtx,
318 GEN_INT (0)));
319 else
320 print_operand (file, addr, 0);
321 break;
322 case PLUS:
323 {
324 rtx base, index;
325 if (REG_P (XEXP (addr, 0))
326 && REG_OK_FOR_BASE_P (XEXP (addr, 0)))
327 base = XEXP (addr, 0), index = XEXP (addr, 1);
328 else if (REG_P (XEXP (addr, 1))
329 && REG_OK_FOR_BASE_P (XEXP (addr, 1)))
330 base = XEXP (addr, 1), index = XEXP (addr, 0);
331 else
332 abort ();
333 print_operand (file, index, 0);
334 fputc (',', file);
335 print_operand (file, base, 0);;
336 break;
337 }
338 case SYMBOL_REF:
339 output_addr_const (file, addr);
340 break;
341 default:
342 output_addr_const (file, addr);
343 break;
344 }
345}
346
38c37a0e
JL
347int
348can_use_return_insn ()
349{
3dbc43d1
JL
350 /* SIZE includes the fixed stack space needed for function calls. */
351 int size = get_frame_size () + (!leaf_function_p () ? 12 : 0);
38c37a0e
JL
352
353 return (reload_completed
354 && size == 0
355 && !regs_ever_live[2]
356 && !regs_ever_live[3]
357 && !regs_ever_live[6]
358 && !regs_ever_live[7]
359 && !frame_pointer_needed);
360}
361
74452ac3
JL
362/* Count the number of tst insns which compare a data or address
363 register with zero. */
364static void
365count_tst_insns (dreg_countp, areg_countp)
366 int *dreg_countp;
367 int *areg_countp;
368{
369 rtx insn;
370
371 /* Assume no tst insns exist. */
372 *dreg_countp = 0;
373 *areg_countp = 0;
374
375 /* If not optimizing, then quit now. */
376 if (!optimize)
377 return;
378
379 /* Walk through all the insns. */
380 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
381 {
382 rtx pat;
383
384 /* Ignore anything that is not a normal INSN. */
385 if (GET_CODE (insn) != INSN)
386 continue;
387
388 /* Ignore anything that isn't a SET. */
389 pat = PATTERN (insn);
390 if (GET_CODE (pat) != SET)
391 continue;
392
393 /* Check for a tst insn. */
394 if (SET_DEST (pat) == cc0_rtx
395 && GET_CODE (SET_SRC (pat)) == REG)
396 {
397 if (REGNO_REG_CLASS (REGNO (SET_SRC (pat))) == DATA_REGS)
398 (*dreg_countp)++;
399
400 if (REGNO_REG_CLASS (REGNO (SET_SRC (pat))) == ADDRESS_REGS)
401 (*areg_countp)++;
402 }
403
404 /* Setting an address register to zero can also be optimized,
405 so count it just like a tst insn. */
406 if (GET_CODE (SET_DEST (pat)) == REG
407 && GET_CODE (SET_SRC (pat)) == CONST_INT
408 && INTVAL (SET_SRC (pat)) == 0
409 && REGNO_REG_CLASS (REGNO (SET_DEST (pat))) == ADDRESS_REGS)
410 (*areg_countp)++;
411 }
412}
413
11bb1f11
JL
414void
415expand_prologue ()
416{
3dbc43d1
JL
417 unsigned int size;
418
74452ac3
JL
419 /* We have to end the current sequence so leaf_function_p and
420 count_tst_insns will work. We then start a new sequence to
421 hold the prologue/epilogue. */
3dbc43d1
JL
422 end_sequence ();
423
74452ac3
JL
424 /* Determine if it is profitable to put the value zero into a register
425 for the entire function. If so, set ZERO_DREG and ZERO_AREG. */
426 if (regs_ever_live[2] || regs_ever_live[3]
427 || regs_ever_live[6] || regs_ever_live[7]
428 || frame_pointer_needed)
429 {
430 int dreg_count, areg_count;
431
432 /* Get a count of the number of tst insns which use address and
433 data registers. */
434 count_tst_insns (&dreg_count, &areg_count);
435
436 /* If there's more than one tst insn using a data register, then
437 this optimization is a win. */
438 if (dreg_count > 1
439 && (!regs_ever_live[2] || !regs_ever_live[3]))
440 {
441 if (!regs_ever_live[2])
442 {
443 regs_ever_live[2] = 1;
444 zero_dreg = gen_rtx (REG, SImode, 2);
445 }
446 else
447 {
448 regs_ever_live[3] = 1;
449 zero_dreg = gen_rtx (REG, SImode, 3);
450 }
451 }
452 else
453 zero_dreg = NULL_RTX;
454
455 /* If there's more than two tst insns using an address register,
456 then this optimization is a win. */
457 if (areg_count > 2
458 && (!regs_ever_live[6] || !regs_ever_live[7]))
459 {
460 if (!regs_ever_live[6])
461 {
462 regs_ever_live[6] = 1;
463 zero_areg = gen_rtx (REG, SImode, 6);
464 }
465 else
466 {
467 regs_ever_live[7] = 1;
468 zero_areg = gen_rtx (REG, SImode, 7);
469 }
470 }
471 else
472 zero_areg = NULL_RTX;
473 }
474 else
475 {
476 zero_dreg = NULL_RTX;
477 zero_areg = NULL_RTX;
478 }
479
3dbc43d1
JL
480 /* SIZE includes the fixed stack space needed for function calls. */
481 size = get_frame_size () + (!leaf_function_p () ? 12 : 0);
482
483 /* Start a new sequence for the prologue/epilogue. */
484 start_sequence ();
11bb1f11 485
22ef4e9b
JL
486 /* If this is an old-style varargs function, then its arguments
487 need to be flushed back to the stack. */
488 if (current_function_varargs)
489 {
490 emit_move_insn (gen_rtx (MEM, SImode,
491 gen_rtx (PLUS, Pmode, stack_pointer_rtx,
492 GEN_INT (4))),
493 gen_rtx (REG, SImode, 0));
494 emit_move_insn (gen_rtx (MEM, SImode,
495 gen_rtx (PLUS, Pmode, stack_pointer_rtx,
496 GEN_INT (8))),
497 gen_rtx (REG, SImode, 1));
498 }
499
777fbf09
JL
500 /* And now store all the registers onto the stack with a
501 single two byte instruction. */
502 if (regs_ever_live[2] || regs_ever_live[3]
503 || regs_ever_live[6] || regs_ever_live[7]
504 || frame_pointer_needed)
505 emit_insn (gen_store_movm ());
506
507 /* Now put the frame pointer into the frame pointer register. */
11bb1f11 508 if (frame_pointer_needed)
6e86170d 509 emit_move_insn (frame_pointer_rtx, stack_pointer_rtx);
11bb1f11 510
777fbf09 511 /* Allocate stack for this frame. */
11bb1f11
JL
512 if (size)
513 emit_insn (gen_addsi3 (stack_pointer_rtx,
514 stack_pointer_rtx,
515 GEN_INT (-size)));
74452ac3
JL
516
517 /* Load zeros into registers as needed. */
518 if (zero_dreg)
519 emit_move_insn (zero_dreg, const0_rtx);
520
521 if (zero_areg)
522 emit_move_insn (zero_areg, const0_rtx);
11bb1f11
JL
523}
524
525void
526expand_epilogue ()
527{
3dbc43d1
JL
528 unsigned int size;
529
530 /* We have to end the current sequence so leaf_function_p will
531 work. We then start a new sequence to hold the prologue/epilogue. */
532 end_sequence ();
533
534 /* SIZE includes the fixed stack space needed for function calls. */
535 size = get_frame_size () + (!leaf_function_p () ? 12 : 0);
536
537 /* Start a new sequence for the prologue/epilogue. */
538 start_sequence ();
11bb1f11
JL
539
540 /* Cut back the stack. */
541 if (frame_pointer_needed)
542 {
11bb1f11 543 emit_move_insn (stack_pointer_rtx, frame_pointer_rtx);
4246e0c5
JL
544 size = 0;
545 }
6fafc523
JL
546 else if ((regs_ever_live[2] || regs_ever_live[3]
547 || regs_ever_live[6] || regs_ever_live[7])
548 && size > 255)
4246e0c5
JL
549 {
550 emit_insn (gen_addsi3 (stack_pointer_rtx,
551 stack_pointer_rtx,
552 GEN_INT (size)));
553 size = 0;
11bb1f11 554 }
11bb1f11 555
777fbf09
JL
556 /* For simplicity, we just movm all the callee saved registers to
557 the stack with one instruction.
558
559 ?!? Only save registers which are actually used. Reduces
560 stack requireents and is faster. */
561 if (regs_ever_live[2] || regs_ever_live[3]
562 || regs_ever_live[6] || regs_ever_live[7]
563 || frame_pointer_needed)
564 emit_jump_insn (gen_return_internal_regs (GEN_INT (size)));
565 else
566 {
567 if (size)
38c37a0e
JL
568 {
569 emit_insn (gen_addsi3 (stack_pointer_rtx,
570 stack_pointer_rtx,
571 GEN_INT (size)));
572 emit_jump_insn (gen_return_internal ());
573 }
574 else
575 {
576 emit_jump_insn (gen_return ());
577 }
777fbf09 578 }
11bb1f11
JL
579}
580
581/* Update the condition code from the insn. */
582
583void
584notice_update_cc (body, insn)
585 rtx body;
586 rtx insn;
587{
11bb1f11
JL
588 switch (get_attr_cc (insn))
589 {
590 case CC_NONE:
591 /* Insn does not affect CC at all. */
592 break;
593
594 case CC_NONE_0HIT:
595 /* Insn does not change CC, but the 0'th operand has been changed. */
596 if (cc_status.value1 != 0
597 && reg_overlap_mentioned_p (recog_operand[0], cc_status.value1))
598 cc_status.value1 = 0;
599 break;
600
601 case CC_SET_ZN_C0:
602 /* Insn sets the Z,N flags of CC to recog_operand[0].
603 V is always set to 0. C may or may not be set to 0 but that's ok
604 because alter_cond will change tests to use EQ/NE. */
605 CC_STATUS_INIT;
777fbf09 606 cc_status.flags |= CC_NO_OVERFLOW | CC_OVERFLOW_UNUSABLE;
11bb1f11
JL
607 cc_status.value1 = recog_operand[0];
608 break;
609
777fbf09 610 case CC_TST:
82c6faa8
JL
611 /* The insn sets all the condition codes, except v is bogus. */
612 CC_STATUS_INIT;
82c6faa8
JL
613 cc_status.value1 = recog_operand[0];
614 break;
615
11bb1f11
JL
616 case CC_COMPARE:
617 /* The insn is a compare instruction. */
618 CC_STATUS_INIT;
619 cc_status.value1 = SET_SRC (body);
620 break;
621
3b800f71
JL
622 case CC_INVERT:
623 /* The insn is a compare instruction. */
624 CC_STATUS_INIT;
625 cc_status.value1 = SET_SRC (body);
626 cc_status.flags |= CC_INVERTED;
627 break;
628
11bb1f11
JL
629 case CC_CLOBBER:
630 /* Insn doesn't leave CC in a usable state. */
631 CC_STATUS_INIT;
632 break;
82c6faa8
JL
633
634 default:
635 abort ();
11bb1f11 636 }
11bb1f11
JL
637}
638
639/* Return true if OP is a valid call operand. */
640
641int
642call_address_operand (op, mode)
643 rtx op;
644 enum machine_mode mode;
645{
646 return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == REG);
647}
648
649/* What (if any) secondary registers are needed to move IN with mode
650 MODE into a register from in register class CLASS.
651
652 We might be able to simplify this. */
653enum reg_class
654secondary_reload_class (class, mode, in)
655 enum reg_class class;
656 enum machine_mode mode;
657 rtx in;
658{
659 int regno;
660
661 /* Memory loads less than a full word wide can't have an
662 address or stack pointer destination. They must use
663 a data register as an intermediate register. */
664 if (GET_CODE (in) == MEM
665 && (mode == QImode || mode == HImode)
666 && (class == ADDRESS_REGS || class == SP_REGS))
667 return DATA_REGS;
668
669 /* We can't directly load sp + const_int into a data register;
670 we must use an address register as an intermediate. */
777fbf09
JL
671 if (class != SP_REGS
672 && class != ADDRESS_REGS
673 && class != SP_OR_ADDRESS_REGS
11bb1f11
JL
674 && (in == stack_pointer_rtx
675 || (GET_CODE (in) == PLUS
777fbf09
JL
676 && (XEXP (in, 0) == stack_pointer_rtx
677 || XEXP (in, 1) == stack_pointer_rtx))))
11bb1f11
JL
678 return ADDRESS_REGS;
679
777fbf09
JL
680 /* Otherwise assume no secondary reloads are needed. */
681 return NO_REGS;
682}
683
684int
685initial_offset (from, to)
686 int from, to;
687{
3dbc43d1
JL
688 /* The difference between the argument pointer and the frame pointer
689 is the size of the callee register save area. */
777fbf09 690 if (from == ARG_POINTER_REGNUM && to == FRAME_POINTER_REGNUM)
11bb1f11 691 {
777fbf09
JL
692 if (regs_ever_live[2] || regs_ever_live[3]
693 || regs_ever_live[6] || regs_ever_live[7]
694 || frame_pointer_needed)
22ef4e9b 695 return 16;
777fbf09 696 else
22ef4e9b 697 return 0;
11bb1f11
JL
698 }
699
3dbc43d1
JL
700 /* The difference between the argument pointer and the stack pointer is
701 the sum of the size of this function's frame, the callee register save
702 area, and the fixed stack space needed for function calls (if any). */
777fbf09
JL
703 if (from == ARG_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
704 {
705 if (regs_ever_live[2] || regs_ever_live[3]
706 || regs_ever_live[6] || regs_ever_live[7]
707 || frame_pointer_needed)
3dbc43d1 708 return (get_frame_size () + 16 + (!leaf_function_p () ? 12 : 0));
777fbf09 709 else
3dbc43d1 710 return (get_frame_size () + (!leaf_function_p () ? 12 : 0));
777fbf09 711 }
11bb1f11 712
3dbc43d1
JL
713 /* The difference between the frame pointer and stack pointer is the sum
714 of the size of this function's frame and the fixed stack space needed
715 for function calls (if any). */
777fbf09 716 if (from == FRAME_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
3dbc43d1 717 return get_frame_size () + (!leaf_function_p () ? 12 : 0);
777fbf09
JL
718
719 abort ();
11bb1f11 720}
22ef4e9b
JL
721
722/* Flush the argument registers to the stack for a stdarg function;
723 return the new argument pointer. */
724rtx
725mn10300_builtin_saveregs (arglist)
726 tree arglist;
727{
728 rtx offset;
729 tree fntype = TREE_TYPE (current_function_decl);
730 int argadj = ((!(TYPE_ARG_TYPES (fntype) != 0
731 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
732 != void_type_node)))
733 ? UNITS_PER_WORD : 0);
734
735 if (argadj)
736 offset = plus_constant (current_function_arg_offset_rtx, argadj);
737 else
738 offset = current_function_arg_offset_rtx;
739
740 emit_move_insn (gen_rtx (MEM, SImode, current_function_internal_arg_pointer),
741 gen_rtx (REG, SImode, 0));
742 emit_move_insn (gen_rtx (MEM, SImode,
743 plus_constant
744 (current_function_internal_arg_pointer, 4)),
745 gen_rtx (REG, SImode, 1));
746 return copy_to_reg (expand_binop (Pmode, add_optab,
747 current_function_internal_arg_pointer,
748 offset, 0, 0, OPTAB_LIB_WIDEN));
749}
750
751/* Return an RTX to represent where a value with mode MODE will be returned
752 from a function. If the result is 0, the argument is pushed. */
753
754rtx
755function_arg (cum, mode, type, named)
756 CUMULATIVE_ARGS *cum;
757 enum machine_mode mode;
758 tree type;
759 int named;
760{
761 rtx result = 0;
762 int size, align;
763
764 /* We only support using 2 data registers as argument registers. */
765 int nregs = 2;
766
767 /* Figure out the size of the object to be passed. */
768 if (mode == BLKmode)
769 size = int_size_in_bytes (type);
770 else
771 size = GET_MODE_SIZE (mode);
772
773 /* Figure out the alignment of the object to be passed. */
774 align = size;
775
776 cum->nbytes = (cum->nbytes + 3) & ~3;
777
778 /* Don't pass this arg via a register if all the argument registers
779 are used up. */
780 if (cum->nbytes > nregs * UNITS_PER_WORD)
781 return 0;
782
783 /* Don't pass this arg via a register if it would be split between
784 registers and memory. */
785 if (type == NULL_TREE
786 && cum->nbytes + size > nregs * UNITS_PER_WORD)
787 return 0;
788
789 switch (cum->nbytes / UNITS_PER_WORD)
790 {
791 case 0:
792 result = gen_rtx (REG, mode, 0);
793 break;
794 case 1:
795 result = gen_rtx (REG, mode, 1);
796 break;
797 default:
798 result = 0;
799 }
800
801 return result;
802}
803
804/* Return the number of registers to use for an argument passed partially
805 in registers and partially in memory. */
806
807int
808function_arg_partial_nregs (cum, mode, type, named)
809 CUMULATIVE_ARGS *cum;
810 enum machine_mode mode;
811 tree type;
812 int named;
813{
814 int size, align;
815
816 /* We only support using 2 data registers as argument registers. */
817 int nregs = 2;
818
819 /* Figure out the size of the object to be passed. */
820 if (mode == BLKmode)
821 size = int_size_in_bytes (type);
822 else
823 size = GET_MODE_SIZE (mode);
824
825 /* Figure out the alignment of the object to be passed. */
826 align = size;
827
828 cum->nbytes = (cum->nbytes + 3) & ~3;
829
830 /* Don't pass this arg via a register if all the argument registers
831 are used up. */
832 if (cum->nbytes > nregs * UNITS_PER_WORD)
833 return 0;
834
835 if (cum->nbytes + size <= nregs * UNITS_PER_WORD)
836 return 0;
837
838 /* Don't pass this arg via a register if it would be split between
839 registers and memory. */
840 if (type == NULL_TREE
841 && cum->nbytes + size > nregs * UNITS_PER_WORD)
842 return 0;
843
844 return (nregs * UNITS_PER_WORD - cum->nbytes) / UNITS_PER_WORD;
845}
846
847/* Output a tst insn. */
848char *
849output_tst (operand, insn)
850 rtx operand, insn;
851{
22ef4e9b
JL
852 rtx temp;
853 int past_call = 0;
854
74452ac3
JL
855 /* If we have a data register which is known to be zero throughout
856 the function, then use it instead of doing a search. */
857 if (zero_dreg && REGNO_REG_CLASS (REGNO (operand)) == DATA_REGS)
858 {
859 rtx xoperands[2];
860 xoperands[0] = operand;
861 xoperands[1] = zero_dreg;
862
863 output_asm_insn ("cmp %1,%0", xoperands);
864 return "";
865 }
866
867 /* Similarly for address registers. */
868 if (zero_areg && REGNO_REG_CLASS (REGNO (operand)) == ADDRESS_REGS)
869 {
870 rtx xoperands[2];
871 xoperands[0] = operand;
872 xoperands[1] = zero_areg;
873
874 output_asm_insn ("cmp %1,%0", xoperands);
875 return "";
876 }
877
22ef4e9b
JL
878 /* We can save a byte if we can find a register which has the value
879 zero in it. */
880 temp = PREV_INSN (insn);
74452ac3 881 while (optimize && temp)
22ef4e9b
JL
882 {
883 rtx set;
884
885 /* We allow the search to go through call insns. We record
886 the fact that we've past a CALL_INSN and reject matches which
887 use call clobbered registers. */
888 if (GET_CODE (temp) == CODE_LABEL
889 || GET_CODE (temp) == JUMP_INSN
890 || GET_CODE (temp) == BARRIER)
891 break;
892
893 if (GET_CODE (temp) == CALL_INSN)
894 past_call = 1;
895
896 if (GET_CODE (temp) == NOTE)
897 {
898 temp = PREV_INSN (temp);
899 continue;
900 }
901
902 /* It must be an insn, see if it is a simple set. */
903 set = single_set (temp);
904 if (!set)
905 {
906 temp = PREV_INSN (temp);
907 continue;
908 }
909
910 /* Are we setting a data register to zero (this does not win for
911 address registers)?
912
913 If it's a call clobbered register, have we past a call?
914
915 Make sure the register we find isn't the same as ourself;
916 the mn10300 can't encode that. */
917 if (REG_P (SET_DEST (set))
918 && SET_SRC (set) == CONST0_RTX (GET_MODE (SET_DEST (set)))
919 && !reg_set_between_p (SET_DEST (set), temp, insn)
74452ac3
JL
920 && (REGNO_REG_CLASS (REGNO (SET_DEST (set)))
921 == REGNO_REG_CLASS (REGNO (operand)))
22ef4e9b
JL
922 && REGNO (SET_DEST (set)) != REGNO (operand)
923 && (!past_call
924 || !call_used_regs[REGNO (SET_DEST (set))]))
925 {
926 rtx xoperands[2];
927 xoperands[0] = operand;
928 xoperands[1] = SET_DEST (set);
929
930 output_asm_insn ("cmp %1,%0", xoperands);
931 return "";
932 }
933 temp = PREV_INSN (temp);
934 }
935 return "cmp 0,%0";
936}