Remove obstacks.
[gcc.git] / gcc / config / m32r / m32r.c
1 /* Subroutines used for code generation on the Mitsubishi M32R cpu.
2 Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
3
4 This file is part of GNU CC.
5
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
20
21 #include "config.h"
22 #include "system.h"
23 #include "tree.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 "expr.h"
35 #include "function.h"
36 #include "recog.h"
37 #include "toplev.h"
38 #include "m32r-protos.h"
39
40 /* Save the operands last given to a compare for use when we
41 generate a scc or bcc insn. */
42 rtx m32r_compare_op0, m32r_compare_op1;
43
44 /* Array of valid operand punctuation characters. */
45 char m32r_punct_chars[256];
46
47 /* Selected code model. */
48 const char * m32r_model_string = M32R_MODEL_DEFAULT;
49 enum m32r_model m32r_model;
50
51 /* Selected SDA support. */
52 const char * m32r_sdata_string = M32R_SDATA_DEFAULT;
53 enum m32r_sdata m32r_sdata;
54
55 /* Scheduler support */
56 int m32r_sched_odd_word_p;
57
58 /* Forward declaration. */
59 static void init_reg_tables PARAMS ((void));
60
61 /* Called by OVERRIDE_OPTIONS to initialize various things. */
62
63 void
64 m32r_init ()
65 {
66 init_reg_tables ();
67
68 /* Initialize array for PRINT_OPERAND_PUNCT_VALID_P. */
69 memset (m32r_punct_chars, 0, sizeof (m32r_punct_chars));
70 m32r_punct_chars['#'] = 1;
71 m32r_punct_chars['@'] = 1; /* ??? no longer used */
72
73 /* Provide default value if not specified. */
74 if (!g_switch_set)
75 g_switch_value = SDATA_DEFAULT_SIZE;
76
77 if (strcmp (m32r_model_string, "small") == 0)
78 m32r_model = M32R_MODEL_SMALL;
79 else if (strcmp (m32r_model_string, "medium") == 0)
80 m32r_model = M32R_MODEL_MEDIUM;
81 else if (strcmp (m32r_model_string, "large") == 0)
82 m32r_model = M32R_MODEL_LARGE;
83 else
84 error ("bad value (%s) for -mmodel switch", m32r_model_string);
85
86 if (strcmp (m32r_sdata_string, "none") == 0)
87 m32r_sdata = M32R_SDATA_NONE;
88 else if (strcmp (m32r_sdata_string, "sdata") == 0)
89 m32r_sdata = M32R_SDATA_SDATA;
90 else if (strcmp (m32r_sdata_string, "use") == 0)
91 m32r_sdata = M32R_SDATA_USE;
92 else
93 error ("bad value (%s) for -msdata switch", m32r_sdata_string);
94 }
95
96 /* Vectors to keep interesting information about registers where it can easily
97 be got. We use to use the actual mode value as the bit number, but there
98 is (or may be) more than 32 modes now. Instead we use two tables: one
99 indexed by hard register number, and one indexed by mode. */
100
101 /* The purpose of m32r_mode_class is to shrink the range of modes so that
102 they all fit (as bit numbers) in a 32 bit word (again). Each real mode is
103 mapped into one m32r_mode_class mode. */
104
105 enum m32r_mode_class
106 {
107 C_MODE,
108 S_MODE, D_MODE, T_MODE, O_MODE,
109 SF_MODE, DF_MODE, TF_MODE, OF_MODE, A_MODE
110 };
111
112 /* Modes for condition codes. */
113 #define C_MODES (1 << (int) C_MODE)
114
115 /* Modes for single-word and smaller quantities. */
116 #define S_MODES ((1 << (int) S_MODE) | (1 << (int) SF_MODE))
117
118 /* Modes for double-word and smaller quantities. */
119 #define D_MODES (S_MODES | (1 << (int) D_MODE) | (1 << DF_MODE))
120
121 /* Modes for quad-word and smaller quantities. */
122 #define T_MODES (D_MODES | (1 << (int) T_MODE) | (1 << (int) TF_MODE))
123
124 /* Modes for accumulators. */
125 #define A_MODES (1 << (int) A_MODE)
126
127 /* Value is 1 if register/mode pair is acceptable on arc. */
128
129 unsigned int m32r_hard_regno_mode_ok[FIRST_PSEUDO_REGISTER] =
130 {
131 T_MODES, T_MODES, T_MODES, T_MODES, T_MODES, T_MODES, T_MODES, T_MODES,
132 T_MODES, T_MODES, T_MODES, T_MODES, T_MODES, S_MODES, S_MODES, S_MODES,
133 S_MODES, C_MODES, A_MODES
134 };
135
136 unsigned int m32r_mode_class [NUM_MACHINE_MODES];
137
138 enum reg_class m32r_regno_reg_class[FIRST_PSEUDO_REGISTER];
139
140 static void
141 init_reg_tables ()
142 {
143 int i;
144
145 for (i = 0; i < NUM_MACHINE_MODES; i++)
146 {
147 switch (GET_MODE_CLASS (i))
148 {
149 case MODE_INT:
150 case MODE_PARTIAL_INT:
151 case MODE_COMPLEX_INT:
152 if (GET_MODE_SIZE (i) <= 4)
153 m32r_mode_class[i] = 1 << (int) S_MODE;
154 else if (GET_MODE_SIZE (i) == 8)
155 m32r_mode_class[i] = 1 << (int) D_MODE;
156 else if (GET_MODE_SIZE (i) == 16)
157 m32r_mode_class[i] = 1 << (int) T_MODE;
158 else if (GET_MODE_SIZE (i) == 32)
159 m32r_mode_class[i] = 1 << (int) O_MODE;
160 else
161 m32r_mode_class[i] = 0;
162 break;
163 case MODE_FLOAT:
164 case MODE_COMPLEX_FLOAT:
165 if (GET_MODE_SIZE (i) <= 4)
166 m32r_mode_class[i] = 1 << (int) SF_MODE;
167 else if (GET_MODE_SIZE (i) == 8)
168 m32r_mode_class[i] = 1 << (int) DF_MODE;
169 else if (GET_MODE_SIZE (i) == 16)
170 m32r_mode_class[i] = 1 << (int) TF_MODE;
171 else if (GET_MODE_SIZE (i) == 32)
172 m32r_mode_class[i] = 1 << (int) OF_MODE;
173 else
174 m32r_mode_class[i] = 0;
175 break;
176 case MODE_CC:
177 default:
178 /* mode_class hasn't been initialized yet for EXTRA_CC_MODES, so
179 we must explicitly check for them here. */
180 if (i == (int) CCmode)
181 m32r_mode_class[i] = 1 << (int) C_MODE;
182 else
183 m32r_mode_class[i] = 0;
184 break;
185 }
186 }
187
188 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
189 {
190 if (GPR_P (i))
191 m32r_regno_reg_class[i] = GENERAL_REGS;
192 else if (i == ARG_POINTER_REGNUM)
193 m32r_regno_reg_class[i] = GENERAL_REGS;
194 else
195 m32r_regno_reg_class[i] = NO_REGS;
196 }
197 }
198 \f
199 /* M32R specific attribute support.
200
201 interrupt - for interrupt functions
202
203 model - select code model used to access object
204
205 small: addresses use 24 bits, use bl to make calls
206 medium: addresses use 32 bits, use bl to make calls
207 large: addresses use 32 bits, use seth/add3/jl to make calls
208
209 Grep for MODEL in m32r.h for more info.
210 */
211
212 static tree interrupt_ident1;
213 static tree interrupt_ident2;
214 static tree model_ident1;
215 static tree model_ident2;
216 static tree small_ident1;
217 static tree small_ident2;
218 static tree medium_ident1;
219 static tree medium_ident2;
220 static tree large_ident1;
221 static tree large_ident2;
222
223 static void
224 init_idents PARAMS ((void))
225 {
226 if (interrupt_ident1 == 0)
227 {
228 interrupt_ident1 = get_identifier ("interrupt");
229 interrupt_ident2 = get_identifier ("__interrupt__");
230 model_ident1 = get_identifier ("model");
231 model_ident2 = get_identifier ("__model__");
232 small_ident1 = get_identifier ("small");
233 small_ident2 = get_identifier ("__small__");
234 medium_ident1 = get_identifier ("medium");
235 medium_ident2 = get_identifier ("__medium__");
236 large_ident1 = get_identifier ("large");
237 large_ident2 = get_identifier ("__large__");
238 }
239 }
240
241 /* Return nonzero if IDENTIFIER is a valid decl attribute. */
242
243 int
244 m32r_valid_machine_decl_attribute (type, attributes, identifier, args)
245 tree type ATTRIBUTE_UNUSED;
246 tree attributes ATTRIBUTE_UNUSED;
247 tree identifier;
248 tree args;
249 {
250 init_idents ();
251
252 if ((identifier == interrupt_ident1
253 || identifier == interrupt_ident2)
254 && list_length (args) == 0)
255 return 1;
256
257 if ((identifier == model_ident1
258 || identifier == model_ident2)
259 && list_length (args) == 1
260 && (TREE_VALUE (args) == small_ident1
261 || TREE_VALUE (args) == small_ident2
262 || TREE_VALUE (args) == medium_ident1
263 || TREE_VALUE (args) == medium_ident2
264 || TREE_VALUE (args) == large_ident1
265 || TREE_VALUE (args) == large_ident2))
266 return 1;
267
268 return 0;
269 }
270
271 /* Return zero if TYPE1 and TYPE are incompatible, one if they are compatible,
272 and two if they are nearly compatible (which causes a warning to be
273 generated). */
274
275 int
276 m32r_comp_type_attributes (type1, type2)
277 tree type1 ATTRIBUTE_UNUSED;
278 tree type2 ATTRIBUTE_UNUSED;
279 {
280 return 1;
281 }
282
283 /* Set the default attributes for TYPE. */
284
285 void
286 m32r_set_default_type_attributes (type)
287 tree type ATTRIBUTE_UNUSED;
288 {
289 }
290 \f
291 /* A C statement or statements to switch to the appropriate
292 section for output of DECL. DECL is either a `VAR_DECL' node
293 or a constant of some sort. RELOC indicates whether forming
294 the initial value of DECL requires link-time relocations. */
295
296 void
297 m32r_select_section (decl, reloc)
298 tree decl;
299 int reloc;
300 {
301 if (TREE_CODE (decl) == STRING_CST)
302 {
303 if (! flag_writable_strings)
304 const_section ();
305 else
306 data_section ();
307 }
308 else if (TREE_CODE (decl) == VAR_DECL)
309 {
310 if (SDATA_NAME_P (XSTR (XEXP (DECL_RTL (decl), 0), 0)))
311 sdata_section ();
312 else if ((flag_pic && reloc)
313 || !TREE_READONLY (decl)
314 || TREE_SIDE_EFFECTS (decl)
315 || !DECL_INITIAL (decl)
316 || (DECL_INITIAL (decl) != error_mark_node
317 && !TREE_CONSTANT (DECL_INITIAL (decl))))
318 data_section ();
319 else
320 const_section ();
321 }
322 else
323 const_section ();
324 }
325
326 /* Encode section information of DECL, which is either a VAR_DECL,
327 FUNCTION_DECL, STRING_CST, CONSTRUCTOR, or ???.
328
329 For the M32R we want to record:
330
331 - whether the object lives in .sdata/.sbss.
332 objects living in .sdata/.sbss are prefixed with SDATA_FLAG_CHAR
333
334 - what code model should be used to access the object
335 small: recorded with no flag - for space efficiency since they'll
336 be the most common
337 medium: prefixed with MEDIUM_FLAG_CHAR
338 large: prefixed with LARGE_FLAG_CHAR
339 */
340
341 void
342 m32r_encode_section_info (decl)
343 tree decl;
344 {
345 char prefix = 0;
346 tree model = 0;
347
348 switch (TREE_CODE (decl))
349 {
350 case VAR_DECL :
351 case FUNCTION_DECL :
352 model = lookup_attribute ("model", DECL_MACHINE_ATTRIBUTES (decl));
353 break;
354 case STRING_CST :
355 case CONSTRUCTOR :
356 /* ??? document all others that can appear here */
357 default :
358 return;
359 }
360
361 /* Only mark the object as being small data area addressable if
362 it hasn't been explicitly marked with a code model.
363
364 The user can explicitly put an object in the small data area with the
365 section attribute. If the object is in sdata/sbss and marked with a
366 code model do both [put the object in .sdata and mark it as being
367 addressed with a specific code model - don't mark it as being addressed
368 with an SDA reloc though]. This is ok and might be useful at times. If
369 the object doesn't fit the linker will give an error. */
370
371 if (! model)
372 {
373 if (TREE_CODE_CLASS (TREE_CODE (decl)) == 'd'
374 && DECL_SECTION_NAME (decl) != NULL_TREE)
375 {
376 char *name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
377 if (! strcmp (name, ".sdata") || ! strcmp (name, ".sbss"))
378 {
379 #if 0 /* ??? There's no reason to disallow this, is there? */
380 if (TREE_READONLY (decl))
381 error_with_decl (decl, "const objects cannot go in .sdata/.sbss");
382 #endif
383 prefix = SDATA_FLAG_CHAR;
384 }
385 }
386 else
387 {
388 if (TREE_CODE (decl) == VAR_DECL
389 && ! TREE_READONLY (decl)
390 && ! TARGET_SDATA_NONE)
391 {
392 int size = int_size_in_bytes (TREE_TYPE (decl));
393
394 if (size > 0 && size <= g_switch_value)
395 prefix = SDATA_FLAG_CHAR;
396 }
397 }
398 }
399
400 /* If data area not decided yet, check for a code model. */
401 if (prefix == 0)
402 {
403 if (model)
404 {
405 tree id;
406
407 init_idents ();
408
409 id = TREE_VALUE (TREE_VALUE (model));
410
411 if (id == small_ident1 || id == small_ident2)
412 ; /* don't mark the symbol specially */
413 else if (id == medium_ident1 || id == medium_ident2)
414 prefix = MEDIUM_FLAG_CHAR;
415 else if (id == large_ident1 || id == large_ident2)
416 prefix = LARGE_FLAG_CHAR;
417 else
418 abort (); /* shouldn't happen */
419 }
420 else
421 {
422 if (TARGET_MODEL_SMALL)
423 ; /* don't mark the symbol specially */
424 else if (TARGET_MODEL_MEDIUM)
425 prefix = MEDIUM_FLAG_CHAR;
426 else if (TARGET_MODEL_LARGE)
427 prefix = LARGE_FLAG_CHAR;
428 else
429 abort (); /* shouldn't happen */
430 }
431 }
432
433 if (prefix != 0)
434 {
435 rtx rtl = (TREE_CODE_CLASS (TREE_CODE (decl)) != 'd'
436 ? TREE_CST_RTL (decl) : DECL_RTL (decl));
437 const char *str = XSTR (XEXP (rtl, 0), 0);
438 int len = strlen (str);
439 char *newstr = ggc_alloc (len + 2);
440 strcpy (newstr + 1, str);
441 *newstr = prefix;
442 XSTR (XEXP (rtl, 0), 0) = newstr;
443 }
444 }
445
446 /* Do anything needed before RTL is emitted for each function. */
447
448 void
449 m32r_init_expanders ()
450 {
451 /* ??? At one point there was code here. The function is left in
452 to make it easy to experiment. */
453 }
454 \f
455 /* Acceptable arguments to the call insn. */
456
457 int
458 call_address_operand (op, mode)
459 rtx op;
460 enum machine_mode mode;
461 {
462 return symbolic_operand (op, mode);
463
464 /* Constants and values in registers are not OK, because
465 the m32r BL instruction can only support PC relative branching. */
466 }
467
468 int
469 call_operand (op, mode)
470 rtx op;
471 enum machine_mode mode;
472 {
473 if (GET_CODE (op) != MEM)
474 return 0;
475 op = XEXP (op, 0);
476 return call_address_operand (op, mode);
477 }
478
479 /* Returns 1 if OP is a symbol reference. */
480
481 int
482 symbolic_operand (op, mode)
483 rtx op;
484 enum machine_mode mode ATTRIBUTE_UNUSED;
485 {
486 switch (GET_CODE (op))
487 {
488 case SYMBOL_REF:
489 case LABEL_REF:
490 case CONST :
491 return 1;
492
493 default:
494 return 0;
495 }
496 }
497
498 /* Return 1 if OP is a reference to an object in .sdata/.sbss. */
499
500 int
501 small_data_operand (op, mode)
502 rtx op;
503 enum machine_mode mode ATTRIBUTE_UNUSED;
504 {
505 if (! TARGET_SDATA_USE)
506 return 0;
507
508 if (GET_CODE (op) == SYMBOL_REF)
509 return SDATA_NAME_P (XSTR (op, 0));
510
511 if (GET_CODE (op) == CONST
512 && GET_CODE (XEXP (op, 0)) == PLUS
513 && GET_CODE (XEXP (XEXP (op, 0), 0)) == SYMBOL_REF
514 && GET_CODE (XEXP (XEXP (op, 0), 1)) == CONST_INT
515 && INT16_P (INTVAL (XEXP (XEXP (op, 0), 1))))
516 return SDATA_NAME_P (XSTR (XEXP (XEXP (op, 0), 0), 0));
517
518 return 0;
519 }
520
521 /* Return 1 if OP is a symbol that can use 24 bit addressing. */
522
523 int
524 addr24_operand (op, mode)
525 rtx op;
526 enum machine_mode mode ATTRIBUTE_UNUSED;
527 {
528 if (GET_CODE (op) == LABEL_REF)
529 return TARGET_ADDR24;
530
531 if (GET_CODE (op) == SYMBOL_REF)
532 return (SMALL_NAME_P (XSTR (op, 0))
533 || (TARGET_ADDR24
534 && (CONSTANT_POOL_ADDRESS_P (op)
535 || LIT_NAME_P (XSTR (op, 0)))));
536
537 if (GET_CODE (op) == CONST
538 && GET_CODE (XEXP (op, 0)) == PLUS
539 && GET_CODE (XEXP (XEXP (op, 0), 0)) == SYMBOL_REF
540 && GET_CODE (XEXP (XEXP (op, 0), 1)) == CONST_INT
541 && UINT24_P (INTVAL (XEXP (XEXP (op, 0), 1))))
542 {
543 rtx sym = XEXP (XEXP (op, 0), 0);
544 return (SMALL_NAME_P (XSTR (sym, 0))
545 || (TARGET_ADDR24
546 && (CONSTANT_POOL_ADDRESS_P (op)
547 || LIT_NAME_P (XSTR (op, 0)))));
548 }
549
550 return 0;
551 }
552
553 /* Return 1 if OP is a symbol that needs 32 bit addressing. */
554
555 int
556 addr32_operand (op, mode)
557 rtx op;
558 enum machine_mode mode;
559 {
560 if (GET_CODE (op) == LABEL_REF)
561 return TARGET_ADDR32;
562
563 if (GET_CODE (op) == SYMBOL_REF)
564 return (! addr24_operand (op, mode)
565 && ! small_data_operand (op, mode));
566
567 if (GET_CODE (op) == CONST
568 && GET_CODE (XEXP (op, 0)) == PLUS
569 && GET_CODE (XEXP (XEXP (op, 0), 0)) == SYMBOL_REF
570 && GET_CODE (XEXP (XEXP (op, 0), 1)) == CONST_INT)
571 {
572 return (! addr24_operand (op, mode)
573 && ! small_data_operand (op, mode));
574 }
575
576 return 0;
577 }
578
579 /* Return 1 if OP is a function that can be called with the `bl' insn. */
580
581 int
582 call26_operand (op, mode)
583 rtx op;
584 enum machine_mode mode ATTRIBUTE_UNUSED;
585 {
586 if (GET_CODE (op) == SYMBOL_REF)
587 return ! LARGE_NAME_P (XSTR (op, 0));
588
589 return TARGET_CALL26;
590 }
591
592 /* Returns 1 if OP is an acceptable operand for seth/add3. */
593
594 int
595 seth_add3_operand (op, mode)
596 rtx op;
597 enum machine_mode mode ATTRIBUTE_UNUSED;
598 {
599 if (GET_CODE (op) == SYMBOL_REF
600 || GET_CODE (op) == LABEL_REF)
601 return 1;
602
603 if (GET_CODE (op) == CONST
604 && GET_CODE (XEXP (op, 0)) == PLUS
605 && GET_CODE (XEXP (XEXP (op, 0), 0)) == SYMBOL_REF
606 && GET_CODE (XEXP (XEXP (op, 0), 1)) == CONST_INT
607 && INT16_P (INTVAL (XEXP (XEXP (op, 0), 1))))
608 return 1;
609
610 return 0;
611 }
612
613 /* Return true if OP is a signed 8 bit immediate value. */
614
615 int
616 int8_operand (op, mode)
617 rtx op;
618 enum machine_mode mode ATTRIBUTE_UNUSED;
619 {
620 if (GET_CODE (op) != CONST_INT)
621 return 0;
622 return INT8_P (INTVAL (op));
623 }
624
625 /* Return true if OP is a signed 16 bit immediate value
626 useful in comparisons. */
627
628 int
629 cmp_int16_operand (op, mode)
630 rtx op;
631 enum machine_mode mode ATTRIBUTE_UNUSED;
632 {
633 if (GET_CODE (op) != CONST_INT)
634 return 0;
635 return CMP_INT16_P (INTVAL (op));
636 }
637
638 /* Return true if OP is an unsigned 16 bit immediate value. */
639
640 int
641 uint16_operand (op, mode)
642 rtx op;
643 enum machine_mode mode ATTRIBUTE_UNUSED;
644 {
645 if (GET_CODE (op) != CONST_INT)
646 return 0;
647 return UINT16_P (INTVAL (op));
648 }
649
650 /* Return true if OP is a register or signed 16 bit value. */
651
652 int
653 reg_or_int16_operand (op, mode)
654 rtx op;
655 enum machine_mode mode;
656 {
657 if (GET_CODE (op) == REG || GET_CODE (op) == SUBREG)
658 return register_operand (op, mode);
659 if (GET_CODE (op) != CONST_INT)
660 return 0;
661 return INT16_P (INTVAL (op));
662 }
663
664 /* Return true if OP is a register or an unsigned 16 bit value. */
665
666 int
667 reg_or_uint16_operand (op, mode)
668 rtx op;
669 enum machine_mode mode;
670 {
671 if (GET_CODE (op) == REG || GET_CODE (op) == SUBREG)
672 return register_operand (op, mode);
673 if (GET_CODE (op) != CONST_INT)
674 return 0;
675 return UINT16_P (INTVAL (op));
676 }
677
678 /* Return true if OP is a register or an integer value that can be
679 used is SEQ/SNE. We can use either XOR of the value or ADD of
680 the negative of the value for the constant. Don't allow 0,
681 because that is special cased. */
682
683 int
684 reg_or_eq_int16_operand (op, mode)
685 rtx op;
686 enum machine_mode mode;
687 {
688 HOST_WIDE_INT value;
689
690 if (GET_CODE (op) == REG || GET_CODE (op) == SUBREG)
691 return register_operand (op, mode);
692
693 if (GET_CODE (op) != CONST_INT)
694 return 0;
695
696 value = INTVAL (op);
697 return (value != 0) && (UINT16_P (value) || CMP_INT16_P (-value));
698 }
699
700 /* Return true if OP is a register or signed 16 bit value for compares. */
701
702 int
703 reg_or_cmp_int16_operand (op, mode)
704 rtx op;
705 enum machine_mode mode;
706 {
707 if (GET_CODE (op) == REG || GET_CODE (op) == SUBREG)
708 return register_operand (op, mode);
709 if (GET_CODE (op) != CONST_INT)
710 return 0;
711 return CMP_INT16_P (INTVAL (op));
712 }
713
714 /* Return true if OP is a const_int requiring two instructions to load. */
715
716 int
717 two_insn_const_operand (op, mode)
718 rtx op;
719 enum machine_mode mode ATTRIBUTE_UNUSED;
720 {
721 if (GET_CODE (op) != CONST_INT)
722 return 0;
723 if (INT16_P (INTVAL (op))
724 || UINT24_P (INTVAL (op))
725 || UPPER16_P (INTVAL (op)))
726 return 0;
727 return 1;
728 }
729
730 /* Return true if OP is an acceptable argument for a single word
731 move source. */
732
733 int
734 move_src_operand (op, mode)
735 rtx op;
736 enum machine_mode mode;
737 {
738 switch (GET_CODE (op))
739 {
740 case SYMBOL_REF :
741 case CONST :
742 return addr24_operand (op, mode);
743 case CONST_INT :
744 /* ??? We allow more cse opportunities if we only allow constants
745 loadable with one insn, and split the rest into two. The instances
746 where this would help should be rare and the current way is
747 simpler. */
748 return INT32_P (INTVAL (op));
749 case LABEL_REF :
750 return TARGET_ADDR24;
751 case CONST_DOUBLE :
752 if (mode == SFmode)
753 return 1;
754 else if (mode == SImode)
755 {
756 /* Large unsigned constants are represented as const_double's. */
757 unsigned HOST_WIDE_INT low, high;
758
759 low = CONST_DOUBLE_LOW (op);
760 high = CONST_DOUBLE_HIGH (op);
761 return high == 0 && low <= 0xffffffff;
762 }
763 else
764 return 0;
765 case REG :
766 return register_operand (op, mode);
767 case SUBREG :
768 /* (subreg (mem ...) ...) can occur here if the inner part was once a
769 pseudo-reg and is now a stack slot. */
770 if (GET_CODE (SUBREG_REG (op)) == MEM)
771 return address_operand (XEXP (SUBREG_REG (op), 0), mode);
772 else
773 return register_operand (op, mode);
774 case MEM :
775 if (GET_CODE (XEXP (op, 0)) == PRE_INC
776 || GET_CODE (XEXP (op, 0)) == PRE_DEC)
777 return 0; /* loads can't do pre-{inc,dec} */
778 return address_operand (XEXP (op, 0), mode);
779 default :
780 return 0;
781 }
782 }
783
784 /* Return true if OP is an acceptable argument for a double word
785 move source. */
786
787 int
788 move_double_src_operand (op, mode)
789 rtx op;
790 enum machine_mode mode;
791 {
792 switch (GET_CODE (op))
793 {
794 case CONST_INT :
795 case CONST_DOUBLE :
796 return 1;
797 case REG :
798 return register_operand (op, mode);
799 case SUBREG :
800 /* (subreg (mem ...) ...) can occur here if the inner part was once a
801 pseudo-reg and is now a stack slot. */
802 if (GET_CODE (SUBREG_REG (op)) == MEM)
803 return move_double_src_operand (SUBREG_REG (op), mode);
804 else
805 return register_operand (op, mode);
806 case MEM :
807 /* Disallow auto inc/dec for now. */
808 if (GET_CODE (XEXP (op, 0)) == PRE_DEC
809 || GET_CODE (XEXP (op, 0)) == PRE_INC)
810 return 0;
811 return address_operand (XEXP (op, 0), mode);
812 default :
813 return 0;
814 }
815 }
816
817 /* Return true if OP is an acceptable argument for a move destination. */
818
819 int
820 move_dest_operand (op, mode)
821 rtx op;
822 enum machine_mode mode;
823 {
824 switch (GET_CODE (op))
825 {
826 case REG :
827 return register_operand (op, mode);
828 case SUBREG :
829 /* (subreg (mem ...) ...) can occur here if the inner part was once a
830 pseudo-reg and is now a stack slot. */
831 if (GET_CODE (SUBREG_REG (op)) == MEM)
832 return address_operand (XEXP (SUBREG_REG (op), 0), mode);
833 else
834 return register_operand (op, mode);
835 case MEM :
836 if (GET_CODE (XEXP (op, 0)) == POST_INC)
837 return 0; /* stores can't do post inc */
838 return address_operand (XEXP (op, 0), mode);
839 default :
840 return 0;
841 }
842 }
843
844 /* Return 1 if OP is a DImode const we want to handle inline.
845 This must match the code in the movdi pattern.
846 It is used by the 'G' CONST_DOUBLE_OK_FOR_LETTER. */
847
848 int
849 easy_di_const (op)
850 rtx op;
851 {
852 rtx high_rtx, low_rtx;
853 HOST_WIDE_INT high, low;
854
855 split_double (op, &high_rtx, &low_rtx);
856 high = INTVAL (high_rtx);
857 low = INTVAL (low_rtx);
858 /* Pick constants loadable with 2 16 bit `ldi' insns. */
859 if (high >= -128 && high <= 127
860 && low >= -128 && low <= 127)
861 return 1;
862 return 0;
863 }
864
865 /* Return 1 if OP is a DFmode const we want to handle inline.
866 This must match the code in the movdf pattern.
867 It is used by the 'H' CONST_DOUBLE_OK_FOR_LETTER. */
868
869 int
870 easy_df_const (op)
871 rtx op;
872 {
873 REAL_VALUE_TYPE r;
874 long l[2];
875
876 REAL_VALUE_FROM_CONST_DOUBLE (r, op);
877 REAL_VALUE_TO_TARGET_DOUBLE (r, l);
878 if (l[0] == 0 && l[1] == 0)
879 return 1;
880 if ((l[0] & 0xffff) == 0 && l[1] == 0)
881 return 1;
882 return 0;
883 }
884
885 /* Return 1 if OP is an EQ or NE comparison operator. */
886
887 int
888 eqne_comparison_operator (op, mode)
889 rtx op;
890 enum machine_mode mode ATTRIBUTE_UNUSED;
891 {
892 enum rtx_code code = GET_CODE (op);
893
894 if (GET_RTX_CLASS (code) != '<')
895 return 0;
896 return (code == EQ || code == NE);
897 }
898
899 /* Return 1 if OP is a signed comparison operator. */
900
901 int
902 signed_comparison_operator (op, mode)
903 rtx op;
904 enum machine_mode mode ATTRIBUTE_UNUSED;
905 {
906 enum rtx_code code = GET_CODE (op);
907
908 if (GET_RTX_CLASS (code) != '<')
909 return 0;
910 return (code == EQ || code == NE
911 || code == LT || code == LE || code == GT || code == GE);
912 }
913
914 /* Return 1 if OP is (mem (reg ...)).
915 This is used in insn length calcs. */
916
917 int
918 memreg_operand (op, mode)
919 rtx op;
920 enum machine_mode mode ATTRIBUTE_UNUSED;
921 {
922 return GET_CODE (op) == MEM && GET_CODE (XEXP (op, 0)) == REG;
923 }
924
925 /* Return true if OP is an acceptable input argument for a zero/sign extend
926 operation. */
927
928 int
929 extend_operand (op, mode)
930 rtx op;
931 enum machine_mode mode;
932 {
933 rtx addr;
934
935 switch (GET_CODE (op))
936 {
937 case REG :
938 case SUBREG :
939 return register_operand (op, mode);
940
941 case MEM :
942 addr = XEXP (op, 0);
943 if (GET_CODE (addr) == PRE_INC || GET_CODE (addr) == PRE_DEC)
944 return 0; /* loads can't do pre inc/pre dec */
945
946 return address_operand (addr, mode);
947
948 default :
949 return 0;
950 }
951 }
952
953 /* Return non-zero if the operand is an insn that is a small insn.
954 Allow const_int 0 as well, which is a placeholder for NOP slots. */
955
956 int
957 small_insn_p (op, mode)
958 rtx op;
959 enum machine_mode mode ATTRIBUTE_UNUSED;
960 {
961 if (GET_CODE (op) == CONST_INT && INTVAL (op) == 0)
962 return 1;
963
964 if (! INSN_P (op))
965 return 0;
966
967 return get_attr_length (op) == 2;
968 }
969
970 /* Return non-zero if the operand is an insn that is a large insn. */
971
972 int
973 large_insn_p (op, mode)
974 rtx op;
975 enum machine_mode mode ATTRIBUTE_UNUSED;
976 {
977 if (! INSN_P (op))
978 return 0;
979
980 return get_attr_length (op) != 2;
981 }
982
983 \f
984 /* Comparisons. */
985
986 /* Given a comparison code (EQ, NE, etc.) and the first operand of a COMPARE,
987 return the mode to be used for the comparison. */
988
989 int
990 m32r_select_cc_mode (op, x, y)
991 int op ATTRIBUTE_UNUSED;
992 rtx x ATTRIBUTE_UNUSED;
993 rtx y ATTRIBUTE_UNUSED;
994 {
995 return (int) CCmode;
996 }
997
998 /* X and Y are two things to compare using CODE. Emit the compare insn and
999 return the rtx for compare [arg0 of the if_then_else].
1000 If need_compare is true then the comparison insn must be generated, rather
1001 than being susummed into the following branch instruction. */
1002
1003 rtx
1004 gen_compare (code, x, y, need_compare)
1005 enum rtx_code code;
1006 rtx x, y;
1007 int need_compare;
1008 {
1009 enum machine_mode mode = SELECT_CC_MODE (code, x, y);
1010 enum rtx_code compare_code, branch_code;
1011 rtx cc_reg = gen_rtx_REG (mode, CARRY_REGNUM);
1012 int must_swap = 0;
1013
1014 switch (code)
1015 {
1016 case EQ: compare_code = EQ; branch_code = NE; break;
1017 case NE: compare_code = EQ; branch_code = EQ; break;
1018 case LT: compare_code = LT; branch_code = NE; break;
1019 case LE: compare_code = LT; branch_code = EQ; must_swap = 1; break;
1020 case GT: compare_code = LT; branch_code = NE; must_swap = 1; break;
1021 case GE: compare_code = LT; branch_code = EQ; break;
1022 case LTU: compare_code = LTU; branch_code = NE; break;
1023 case LEU: compare_code = LTU; branch_code = EQ; must_swap = 1; break;
1024 case GTU: compare_code = LTU; branch_code = NE; must_swap = 1; break;
1025 case GEU: compare_code = LTU; branch_code = EQ; break;
1026
1027 default:
1028 abort ();
1029 }
1030
1031 if (need_compare)
1032 {
1033 switch (compare_code)
1034 {
1035 case EQ:
1036 if (GET_CODE (y) == CONST_INT
1037 && CMP_INT16_P (INTVAL (y)) /* reg equal to small const. */
1038 && y != const0_rtx)
1039 {
1040 rtx tmp = gen_reg_rtx (SImode);
1041
1042 emit_insn (gen_cmp_ne_small_const_insn (tmp, x, y));
1043 x = tmp;
1044 y = const0_rtx;
1045 }
1046 else if (CONSTANT_P (y)) /* reg equal to const. */
1047 {
1048 rtx tmp = force_reg (GET_MODE (x), y);
1049 y = tmp;
1050 }
1051
1052 if (register_operand (y, SImode) /* reg equal to reg. */
1053 || y == const0_rtx) /* req equal to zero. */
1054 {
1055 emit_insn (gen_cmp_eqsi_insn (x, y));
1056
1057 return gen_rtx (code, mode, cc_reg, const0_rtx);
1058 }
1059 break;
1060
1061 case LT:
1062 if (register_operand (y, SImode)
1063 || (GET_CODE (y) == CONST_INT && CMP_INT16_P (INTVAL (y))))
1064 {
1065 rtx tmp = gen_reg_rtx (SImode); /* reg compared to reg. */
1066
1067 switch (code)
1068 {
1069 case LT:
1070 emit_insn (gen_cmp_ltsi_insn (x, y));
1071 code = EQ;
1072 break;
1073 case LE:
1074 if (y == const0_rtx)
1075 tmp = const1_rtx;
1076 else
1077 emit_insn (gen_cmp_ne_small_const_insn (tmp, y, const1_rtx));
1078 emit_insn (gen_cmp_ltsi_insn (x, tmp));
1079 code = EQ;
1080 break;
1081 case GT:
1082 if (GET_CODE (y) == CONST_INT)
1083 tmp = gen_rtx (PLUS, SImode, y, const1_rtx);
1084 else
1085 emit_insn (gen_cmp_ne_small_const_insn (tmp, y, const1_rtx));
1086 emit_insn (gen_cmp_ltsi_insn (x, tmp));
1087 code = NE;
1088 break;
1089 case GE:
1090 emit_insn (gen_cmp_ltsi_insn (x, y));
1091 code = NE;
1092 break;
1093 default:
1094 abort ();
1095 }
1096
1097 return gen_rtx (code, mode, cc_reg, const0_rtx);
1098 }
1099 break;
1100
1101 case LTU:
1102 if (register_operand (y, SImode)
1103 || (GET_CODE (y) == CONST_INT && CMP_INT16_P (INTVAL (y))))
1104 {
1105 rtx tmp = gen_reg_rtx (SImode); /* reg (unsigned) compared to reg. */
1106
1107 switch (code)
1108 {
1109 case LTU:
1110 emit_insn (gen_cmp_ltusi_insn (x, y));
1111 code = EQ;
1112 break;
1113 case LEU:
1114 if (y == const0_rtx)
1115 tmp = const1_rtx;
1116 else
1117 emit_insn (gen_cmp_ne_small_const_insn (tmp, y, const1_rtx));
1118 emit_insn (gen_cmp_ltusi_insn (x, tmp));
1119 code = EQ;
1120 break;
1121 case GTU:
1122 if (GET_CODE (y) == CONST_INT)
1123 tmp = gen_rtx (PLUS, SImode, y, const1_rtx);
1124 else
1125 emit_insn (gen_cmp_ne_small_const_insn (tmp, y, const1_rtx));
1126 emit_insn (gen_cmp_ltusi_insn (x, tmp));
1127 code = NE;
1128 break;
1129 case GEU:
1130 emit_insn (gen_cmp_ltusi_insn (x, y));
1131 code = NE;
1132 break;
1133 default:
1134 abort();
1135 }
1136
1137 return gen_rtx (code, mode, cc_reg, const0_rtx);
1138 }
1139 break;
1140
1141 default:
1142 abort();
1143 }
1144 }
1145 else
1146 {
1147 /* reg/reg equal comparison */
1148 if (compare_code == EQ
1149 && register_operand (y, SImode))
1150 return gen_rtx (code, mode, x, y);
1151
1152 /* reg/zero signed comparison */
1153 if ((compare_code == EQ || compare_code == LT)
1154 && y == const0_rtx)
1155 return gen_rtx (code, mode, x, y);
1156
1157 /* reg/smallconst equal comparison */
1158 if (compare_code == EQ
1159 && GET_CODE (y) == CONST_INT
1160 && CMP_INT16_P (INTVAL (y)))
1161 {
1162 rtx tmp = gen_reg_rtx (SImode);
1163 emit_insn (gen_cmp_ne_small_const_insn (tmp, x, y));
1164 return gen_rtx (code, mode, tmp, const0_rtx);
1165 }
1166
1167 /* reg/const equal comparison */
1168 if (compare_code == EQ
1169 && CONSTANT_P (y))
1170 {
1171 rtx tmp = force_reg (GET_MODE (x), y);
1172 return gen_rtx (code, mode, x, tmp);
1173 }
1174 }
1175
1176 if (CONSTANT_P (y))
1177 {
1178 if (must_swap)
1179 y = force_reg (GET_MODE (x), y);
1180 else
1181 {
1182 int ok_const =
1183 (code == LTU || code == LEU || code == GTU || code == GEU)
1184 ? uint16_operand (y, GET_MODE (y))
1185 : reg_or_cmp_int16_operand (y, GET_MODE (y));
1186
1187 if (! ok_const)
1188 y = force_reg (GET_MODE (x), y);
1189 }
1190 }
1191
1192 switch (compare_code)
1193 {
1194 case EQ :
1195 emit_insn (gen_cmp_eqsi_insn (must_swap ? y : x, must_swap ? x : y));
1196 break;
1197 case LT :
1198 emit_insn (gen_cmp_ltsi_insn (must_swap ? y : x, must_swap ? x : y));
1199 break;
1200 case LTU :
1201 emit_insn (gen_cmp_ltusi_insn (must_swap ? y : x, must_swap ? x : y));
1202 break;
1203
1204 default:
1205 abort ();
1206 }
1207
1208 return gen_rtx (branch_code, VOIDmode, cc_reg, CONST0_RTX (mode));
1209 }
1210 \f
1211 /* Split a 2 word move (DI or DF) into component parts. */
1212
1213 rtx
1214 gen_split_move_double (operands)
1215 rtx operands[];
1216 {
1217 enum machine_mode mode = GET_MODE (operands[0]);
1218 rtx dest = operands[0];
1219 rtx src = operands[1];
1220 rtx val;
1221
1222 /* We might have (SUBREG (MEM)) here, so just get rid of the
1223 subregs to make this code simpler. It is safe to call
1224 alter_subreg any time after reload. */
1225 if (GET_CODE (dest) == SUBREG)
1226 dest = alter_subreg (dest);
1227 if (GET_CODE (src) == SUBREG)
1228 src = alter_subreg (src);
1229
1230 start_sequence ();
1231 if (GET_CODE (dest) == REG)
1232 {
1233 int dregno = REGNO (dest);
1234
1235 /* reg = reg */
1236 if (GET_CODE (src) == REG)
1237 {
1238 int sregno = REGNO (src);
1239
1240 int reverse = (dregno == sregno + 1);
1241
1242 /* We normally copy the low-numbered register first. However, if
1243 the first register operand 0 is the same as the second register of
1244 operand 1, we must copy in the opposite order. */
1245 emit_insn (gen_rtx_SET (VOIDmode,
1246 operand_subword (dest, reverse, TRUE, mode),
1247 operand_subword (src, reverse, TRUE, mode)));
1248
1249 emit_insn (gen_rtx_SET (VOIDmode,
1250 operand_subword (dest, !reverse, TRUE, mode),
1251 operand_subword (src, !reverse, TRUE, mode)));
1252 }
1253
1254 /* reg = constant */
1255 else if (GET_CODE (src) == CONST_INT || GET_CODE (src) == CONST_DOUBLE)
1256 {
1257 rtx words[2];
1258 split_double (src, &words[0], &words[1]);
1259 emit_insn (gen_rtx_SET (VOIDmode,
1260 operand_subword (dest, 0, TRUE, mode),
1261 words[0]));
1262
1263 emit_insn (gen_rtx_SET (VOIDmode,
1264 operand_subword (dest, 1, TRUE, mode),
1265 words[1]));
1266 }
1267
1268 /* reg = mem */
1269 else if (GET_CODE (src) == MEM)
1270 {
1271 /* If the high-address word is used in the address, we must load it
1272 last. Otherwise, load it first. */
1273 rtx addr = XEXP (src, 0);
1274 int reverse = (refers_to_regno_p (dregno, dregno+1, addr, 0) != 0);
1275
1276 /* We used to optimize loads from single registers as
1277
1278 ld r1,r3+; ld r2,r3
1279
1280 if r3 were not used subsequently. However, the REG_NOTES aren't
1281 propigated correctly by the reload phase, and it can cause bad
1282 code to be generated. We could still try:
1283
1284 ld r1,r3+; ld r2,r3; addi r3,-4
1285
1286 which saves 2 bytes and doesn't force longword alignment. */
1287 emit_insn (gen_rtx_SET (VOIDmode,
1288 operand_subword (dest, reverse, TRUE, mode),
1289 change_address (src, SImode,
1290 plus_constant (addr,
1291 reverse * UNITS_PER_WORD))));
1292
1293 emit_insn (gen_rtx_SET (VOIDmode,
1294 operand_subword (dest, !reverse, TRUE, mode),
1295 change_address (src, SImode,
1296 plus_constant (addr,
1297 (!reverse) * UNITS_PER_WORD))));
1298 }
1299
1300 else
1301 abort ();
1302 }
1303
1304 /* mem = reg */
1305 /* We used to optimize loads from single registers as
1306
1307 st r1,r3; st r2,+r3
1308
1309 if r3 were not used subsequently. However, the REG_NOTES aren't
1310 propigated correctly by the reload phase, and it can cause bad
1311 code to be generated. We could still try:
1312
1313 st r1,r3; st r2,+r3; addi r3,-4
1314
1315 which saves 2 bytes and doesn't force longword alignment. */
1316 else if (GET_CODE (dest) == MEM && GET_CODE (src) == REG)
1317 {
1318 rtx addr = XEXP (dest, 0);
1319
1320 emit_insn (gen_rtx_SET (VOIDmode,
1321 change_address (dest, SImode, addr),
1322 operand_subword (src, 0, TRUE, mode)));
1323
1324 emit_insn (gen_rtx_SET (VOIDmode,
1325 change_address (dest, SImode,
1326 plus_constant (addr, UNITS_PER_WORD)),
1327 operand_subword (src, 1, TRUE, mode)));
1328 }
1329
1330 else
1331 abort ();
1332
1333 val = gen_sequence ();
1334 end_sequence ();
1335 return val;
1336 }
1337
1338 \f
1339 /* Implements the FUNCTION_ARG_PARTIAL_NREGS macro. */
1340
1341 int
1342 function_arg_partial_nregs (cum, mode, type, named)
1343 CUMULATIVE_ARGS *cum;
1344 enum machine_mode mode;
1345 tree type;
1346 int named ATTRIBUTE_UNUSED;
1347 {
1348 int ret;
1349 int size = (((mode == BLKmode && type)
1350 ? int_size_in_bytes (type)
1351 : GET_MODE_SIZE (mode)) + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
1352
1353 if (*cum >= M32R_MAX_PARM_REGS)
1354 ret = 0;
1355 else if (*cum + size > M32R_MAX_PARM_REGS)
1356 ret = (*cum + size) - M32R_MAX_PARM_REGS;
1357 else
1358 ret = 0;
1359
1360 return ret;
1361 }
1362
1363 /* Do any needed setup for a variadic function. For the M32R, we must
1364 create a register parameter block, and then copy any anonymous arguments
1365 in registers to memory.
1366
1367 CUM has not been updated for the last named argument which has type TYPE
1368 and mode MODE, and we rely on this fact. */
1369
1370 void
1371 m32r_setup_incoming_varargs (cum, mode, type, pretend_size, no_rtl)
1372 CUMULATIVE_ARGS *cum;
1373 enum machine_mode mode;
1374 tree type;
1375 int *pretend_size;
1376 int no_rtl;
1377 {
1378 int first_anon_arg;
1379
1380 if (no_rtl)
1381 return;
1382
1383 /* All BLKmode values are passed by reference. */
1384 if (mode == BLKmode)
1385 abort ();
1386
1387 /* We must treat `__builtin_va_alist' as an anonymous arg. */
1388 if (current_function_varargs)
1389 first_anon_arg = *cum;
1390 else
1391 first_anon_arg = (ROUND_ADVANCE_CUM (*cum, mode, type)
1392 + ROUND_ADVANCE_ARG (mode, type));
1393
1394 if (first_anon_arg < M32R_MAX_PARM_REGS)
1395 {
1396 /* Note that first_reg_offset < M32R_MAX_PARM_REGS. */
1397 int first_reg_offset = first_anon_arg;
1398 /* Size in words to "pretend" allocate. */
1399 int size = M32R_MAX_PARM_REGS - first_reg_offset;
1400 rtx regblock;
1401
1402 regblock = gen_rtx_MEM (BLKmode,
1403 plus_constant (arg_pointer_rtx,
1404 FIRST_PARM_OFFSET (0)));
1405 MEM_ALIAS_SET (regblock) = get_varargs_alias_set ();
1406 move_block_from_reg (first_reg_offset, regblock,
1407 size, size * UNITS_PER_WORD);
1408
1409 *pretend_size = (size * UNITS_PER_WORD);
1410 }
1411 }
1412
1413 \f
1414 /* Implement `va_arg'. */
1415
1416 rtx
1417 m32r_va_arg (valist, type)
1418 tree valist, type;
1419 {
1420 HOST_WIDE_INT size, rsize;
1421 tree t;
1422 rtx addr_rtx;
1423
1424 size = int_size_in_bytes (type);
1425 rsize = (size + UNITS_PER_WORD - 1) & -UNITS_PER_WORD;
1426
1427 if (size > 8)
1428 {
1429 tree type_ptr, type_ptr_ptr;
1430
1431 /* Pass by reference. */
1432
1433 type_ptr = build_pointer_type (type);
1434 type_ptr_ptr = build_pointer_type (type_ptr);
1435
1436 t = build (POSTINCREMENT_EXPR, va_list_type_node, valist,
1437 build_int_2 (UNITS_PER_WORD, 0));
1438 TREE_SIDE_EFFECTS (t) = 1;
1439 t = build1 (NOP_EXPR, type_ptr_ptr, t);
1440 TREE_SIDE_EFFECTS (t) = 1;
1441 t = build1 (INDIRECT_REF, type_ptr, t);
1442
1443 addr_rtx = expand_expr (t, NULL_RTX, Pmode, EXPAND_NORMAL);
1444 }
1445 else
1446 {
1447 /* Pass by value. */
1448
1449 if (size < UNITS_PER_WORD)
1450 {
1451 /* Care for bigendian correction on the aligned address. */
1452 t = build (PLUS_EXPR, ptr_type_node, valist,
1453 build_int_2 (rsize - size, 0));
1454 addr_rtx = expand_expr (t, NULL_RTX, Pmode, EXPAND_NORMAL);
1455 addr_rtx = copy_to_reg (addr_rtx);
1456
1457 /* Increment AP. */
1458 t = build (PLUS_EXPR, va_list_type_node, valist,
1459 build_int_2 (rsize, 0));
1460 t = build (MODIFY_EXPR, va_list_type_node, valist, t);
1461 TREE_SIDE_EFFECTS (t) = 1;
1462 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
1463 }
1464 else
1465 {
1466 t = build (POSTINCREMENT_EXPR, va_list_type_node, valist,
1467 build_int_2 (rsize, 0));
1468 TREE_SIDE_EFFECTS (t) = 1;
1469 addr_rtx = expand_expr (t, NULL_RTX, Pmode, EXPAND_NORMAL);
1470 }
1471 }
1472
1473 return addr_rtx;
1474 }
1475 \f
1476 int
1477 m32r_adjust_cost (insn, link, dep_insn, cost)
1478 rtx insn ATTRIBUTE_UNUSED;
1479 rtx link ATTRIBUTE_UNUSED;
1480 rtx dep_insn ATTRIBUTE_UNUSED;
1481 int cost;
1482 {
1483 return cost;
1484 }
1485
1486 \f
1487 /* Return true if INSN is real instruction bearing insn. */
1488
1489 static int
1490 m32r_is_insn (insn)
1491 rtx insn;
1492 {
1493 return (INSN_P (insn)
1494 && GET_CODE (PATTERN (insn)) != USE
1495 && GET_CODE (PATTERN (insn)) != CLOBBER
1496 && GET_CODE (PATTERN (insn)) != ADDR_VEC);
1497 }
1498
1499 /* Increase the priority of long instructions so that the
1500 short instructions are scheduled ahead of the long ones. */
1501
1502 int
1503 m32r_adjust_priority (insn, priority)
1504 rtx insn;
1505 int priority;
1506 {
1507 if (m32r_is_insn (insn)
1508 && get_attr_insn_size (insn) != INSN_SIZE_SHORT)
1509 priority <<= 3;
1510
1511 return priority;
1512 }
1513
1514 \f
1515 /* Initialize for scheduling a group of instructions. */
1516
1517 void
1518 m32r_sched_init (stream, verbose)
1519 FILE * stream ATTRIBUTE_UNUSED;
1520 int verbose ATTRIBUTE_UNUSED;
1521 {
1522 m32r_sched_odd_word_p = FALSE;
1523 }
1524
1525 \f
1526 /* Reorder the schedulers priority list if needed */
1527
1528 void
1529 m32r_sched_reorder (stream, verbose, ready, n_ready)
1530 FILE * stream;
1531 int verbose;
1532 rtx * ready;
1533 int n_ready;
1534 {
1535 if (TARGET_DEBUG)
1536 return;
1537
1538 if (verbose <= 7)
1539 stream = (FILE *)0;
1540
1541 if (stream)
1542 fprintf (stream,
1543 ";;\t\t::: Looking at %d insn(s) on ready list, boundary is %s word\n",
1544 n_ready,
1545 (m32r_sched_odd_word_p) ? "odd" : "even");
1546
1547 if (n_ready > 1)
1548 {
1549 rtx * long_head = (rtx *) alloca (sizeof (rtx) * n_ready);
1550 rtx * long_tail = long_head;
1551 rtx * short_head = (rtx *) alloca (sizeof (rtx) * n_ready);
1552 rtx * short_tail = short_head;
1553 rtx * new_head = (rtx *) alloca (sizeof (rtx) * n_ready);
1554 rtx * new_tail = new_head + (n_ready - 1);
1555 int i;
1556
1557 /* Loop through the instructions, classifing them as short/long. Try
1558 to keep 2 short together and/or 1 long. Note, the ready list is
1559 actually ordered backwards, so keep it in that manner. */
1560 for (i = n_ready-1; i >= 0; i--)
1561 {
1562 rtx insn = ready[i];
1563 enum rtx_code code;
1564
1565 if (! m32r_is_insn (insn))
1566 {
1567 /* Dump all current short/long insns just in case. */
1568 while (long_head != long_tail)
1569 *new_tail-- = *long_head++;
1570
1571 while (short_head != short_tail)
1572 *new_tail-- = *short_head++;
1573
1574 *new_tail-- = insn;
1575 if (stream)
1576 fprintf (stream,
1577 ";;\t\t::: Skipping non instruction %d\n",
1578 INSN_UID (insn));
1579
1580 }
1581
1582 else
1583 {
1584 if (get_attr_insn_size (insn) != INSN_SIZE_SHORT)
1585 *long_tail++ = insn;
1586
1587 else
1588 *short_tail++ = insn;
1589 }
1590 }
1591
1592 /* If we are on an odd word, emit a single short instruction if
1593 we can */
1594 if (m32r_sched_odd_word_p && short_head != short_tail)
1595 *new_tail-- = *short_head++;
1596
1597 /* Now dump out all of the long instructions */
1598 while (long_head != long_tail)
1599 *new_tail-- = *long_head++;
1600
1601 /* Now dump out all of the short instructions */
1602 while (short_head != short_tail)
1603 *new_tail-- = *short_head++;
1604
1605 if (new_tail+1 != new_head)
1606 abort ();
1607
1608 bcopy ((char *) new_head, (char *) ready, sizeof (rtx) * n_ready);
1609 if (stream)
1610 {
1611 #ifdef HAIFA
1612 fprintf (stream, ";;\t\t::: New ready list: ");
1613 debug_ready_list (ready, n_ready);
1614 #else
1615 int i;
1616 for (i = 0; i < n_ready; i++)
1617 {
1618 rtx insn = ready[i];
1619 enum rtx_code code;
1620
1621 fprintf (stream, " %d", INSN_UID (ready[i]));
1622
1623 if (! m32r_is_insn (insn))
1624 fputs ("(?)", stream);
1625
1626 else if (get_attr_insn_size (insn) != INSN_SIZE_SHORT)
1627 fputs ("(l)", stream);
1628
1629 else
1630 fputs ("(s)", stream);
1631 }
1632
1633 fprintf (stream, "\n");
1634 #endif
1635 }
1636 }
1637 }
1638
1639 \f
1640 /* If we have a machine that can issue a variable # of instructions
1641 per cycle, indicate how many more instructions can be issued
1642 after the current one. */
1643 int
1644 m32r_sched_variable_issue (stream, verbose, insn, how_many)
1645 FILE * stream;
1646 int verbose;
1647 rtx insn;
1648 int how_many;
1649 {
1650 int orig_odd_word_p = m32r_sched_odd_word_p;
1651 int short_p = FALSE;
1652
1653 how_many--;
1654 if (how_many > 0 && !TARGET_DEBUG)
1655 {
1656 if (! m32r_is_insn (insn))
1657 how_many++;
1658
1659 else if (get_attr_insn_size (insn) != INSN_SIZE_SHORT)
1660 {
1661 how_many = 0;
1662 m32r_sched_odd_word_p = 0;
1663 }
1664 else
1665 {
1666 m32r_sched_odd_word_p = !m32r_sched_odd_word_p;
1667 short_p = TRUE;
1668 }
1669 }
1670
1671 if (verbose > 7 && stream)
1672 fprintf (stream,
1673 ";;\t\t::: %s insn %d starts on an %s word, can emit %d more instruction(s)\n",
1674 short_p ? "short" : "long",
1675 INSN_UID (insn),
1676 orig_odd_word_p ? "odd" : "even",
1677 how_many);
1678
1679 return how_many;
1680 }
1681 \f
1682 /* Cost functions. */
1683
1684 /* Provide the costs of an addressing mode that contains ADDR.
1685 If ADDR is not a valid address, its cost is irrelevant.
1686
1687 This function is trivial at the moment. This code doesn't live
1688 in m32r.h so it's easy to experiment. */
1689
1690 int
1691 m32r_address_cost (addr)
1692 rtx addr ATTRIBUTE_UNUSED;
1693 {
1694 return 1;
1695 }
1696 \f
1697 /* Type of function DECL.
1698
1699 The result is cached. To reset the cache at the end of a function,
1700 call with DECL = NULL_TREE. */
1701
1702 enum m32r_function_type
1703 m32r_compute_function_type (decl)
1704 tree decl;
1705 {
1706 /* Cached value. */
1707 static enum m32r_function_type fn_type = M32R_FUNCTION_UNKNOWN;
1708 /* Last function we were called for. */
1709 static tree last_fn = NULL_TREE;
1710
1711 /* Resetting the cached value? */
1712 if (decl == NULL_TREE)
1713 {
1714 fn_type = M32R_FUNCTION_UNKNOWN;
1715 last_fn = NULL_TREE;
1716 return fn_type;
1717 }
1718
1719 if (decl == last_fn && fn_type != M32R_FUNCTION_UNKNOWN)
1720 return fn_type;
1721
1722 /* Compute function type. */
1723 fn_type = (lookup_attribute ("interrupt", DECL_MACHINE_ATTRIBUTES (current_function_decl)) != NULL_TREE
1724 ? M32R_FUNCTION_INTERRUPT
1725 : M32R_FUNCTION_NORMAL);
1726
1727 last_fn = decl;
1728 return fn_type;
1729 }
1730 \f/* Function prologue/epilogue handlers. */
1731
1732 /* M32R stack frames look like:
1733
1734 Before call After call
1735 +-----------------------+ +-----------------------+
1736 | | | |
1737 high | local variables, | | local variables, |
1738 mem | reg save area, etc. | | reg save area, etc. |
1739 | | | |
1740 +-----------------------+ +-----------------------+
1741 | | | |
1742 | arguments on stack. | | arguments on stack. |
1743 | | | |
1744 SP+0->+-----------------------+ +-----------------------+
1745 | reg parm save area, |
1746 | only created for |
1747 | variable argument |
1748 | functions |
1749 +-----------------------+
1750 | previous frame ptr |
1751 +-----------------------+
1752 | |
1753 | register save area |
1754 | |
1755 +-----------------------+
1756 | return address |
1757 +-----------------------+
1758 | |
1759 | local variables |
1760 | |
1761 +-----------------------+
1762 | |
1763 | alloca allocations |
1764 | |
1765 +-----------------------+
1766 | |
1767 low | arguments on stack |
1768 memory | |
1769 SP+0->+-----------------------+
1770
1771 Notes:
1772 1) The "reg parm save area" does not exist for non variable argument fns.
1773 2) The "reg parm save area" can be eliminated completely if we saved regs
1774 containing anonymous args separately but that complicates things too
1775 much (so it's not done).
1776 3) The return address is saved after the register save area so as to have as
1777 many insns as possible between the restoration of `lr' and the `jmp lr'.
1778 */
1779
1780 /* Structure to be filled in by m32r_compute_frame_size with register
1781 save masks, and offsets for the current function. */
1782 struct m32r_frame_info
1783 {
1784 unsigned int total_size; /* # bytes that the entire frame takes up */
1785 unsigned int extra_size; /* # bytes of extra stuff */
1786 unsigned int pretend_size; /* # bytes we push and pretend caller did */
1787 unsigned int args_size; /* # bytes that outgoing arguments take up */
1788 unsigned int reg_size; /* # bytes needed to store regs */
1789 unsigned int var_size; /* # bytes that variables take up */
1790 unsigned int gmask; /* mask of saved gp registers */
1791 unsigned int save_fp; /* nonzero if fp must be saved */
1792 unsigned int save_lr; /* nonzero if lr (return addr) must be saved */
1793 int initialized; /* nonzero if frame size already calculated */
1794 };
1795
1796 /* Current frame information calculated by m32r_compute_frame_size. */
1797 static struct m32r_frame_info current_frame_info;
1798
1799 /* Zero structure to initialize current_frame_info. */
1800 static struct m32r_frame_info zero_frame_info;
1801
1802 #define FRAME_POINTER_MASK (1 << (FRAME_POINTER_REGNUM))
1803 #define RETURN_ADDR_MASK (1 << (RETURN_ADDR_REGNUM))
1804
1805 /* Tell prologue and epilogue if register REGNO should be saved / restored.
1806 The return address and frame pointer are treated separately.
1807 Don't consider them here. */
1808 #define MUST_SAVE_REGISTER(regno, interrupt_p) \
1809 ((regno) != RETURN_ADDR_REGNUM && (regno) != FRAME_POINTER_REGNUM \
1810 && (regs_ever_live[regno] && (!call_used_regs[regno] || interrupt_p)))
1811
1812 #define MUST_SAVE_FRAME_POINTER (regs_ever_live[FRAME_POINTER_REGNUM])
1813 #define MUST_SAVE_RETURN_ADDR (regs_ever_live[RETURN_ADDR_REGNUM] || profile_flag)
1814
1815 #define SHORT_INSN_SIZE 2 /* size of small instructions */
1816 #define LONG_INSN_SIZE 4 /* size of long instructions */
1817
1818 /* Return the bytes needed to compute the frame pointer from the current
1819 stack pointer.
1820
1821 SIZE is the size needed for local variables. */
1822
1823 unsigned int
1824 m32r_compute_frame_size (size)
1825 int size; /* # of var. bytes allocated. */
1826 {
1827 int regno;
1828 unsigned int total_size, var_size, args_size, pretend_size, extra_size;
1829 unsigned int reg_size, frame_size;
1830 unsigned int gmask;
1831 enum m32r_function_type fn_type;
1832 int interrupt_p;
1833
1834 var_size = M32R_STACK_ALIGN (size);
1835 args_size = M32R_STACK_ALIGN (current_function_outgoing_args_size);
1836 pretend_size = current_function_pretend_args_size;
1837 extra_size = FIRST_PARM_OFFSET (0);
1838 total_size = extra_size + pretend_size + args_size + var_size;
1839 reg_size = 0;
1840 gmask = 0;
1841
1842 /* See if this is an interrupt handler. Call used registers must be saved
1843 for them too. */
1844 fn_type = m32r_compute_function_type (current_function_decl);
1845 interrupt_p = M32R_INTERRUPT_P (fn_type);
1846
1847 /* Calculate space needed for registers. */
1848
1849 for (regno = 0; regno < M32R_MAX_INT_REGS; regno++)
1850 {
1851 if (MUST_SAVE_REGISTER (regno, interrupt_p))
1852 {
1853 reg_size += UNITS_PER_WORD;
1854 gmask |= 1 << regno;
1855 }
1856 }
1857
1858 current_frame_info.save_fp = MUST_SAVE_FRAME_POINTER;
1859 current_frame_info.save_lr = MUST_SAVE_RETURN_ADDR;
1860
1861 reg_size += ((current_frame_info.save_fp + current_frame_info.save_lr)
1862 * UNITS_PER_WORD);
1863 total_size += reg_size;
1864
1865 /* ??? Not sure this is necessary, and I don't think the epilogue
1866 handler will do the right thing if this changes total_size. */
1867 total_size = M32R_STACK_ALIGN (total_size);
1868
1869 frame_size = total_size - (pretend_size + reg_size);
1870
1871 /* Save computed information. */
1872 current_frame_info.total_size = total_size;
1873 current_frame_info.extra_size = extra_size;
1874 current_frame_info.pretend_size = pretend_size;
1875 current_frame_info.var_size = var_size;
1876 current_frame_info.args_size = args_size;
1877 current_frame_info.reg_size = reg_size;
1878 current_frame_info.gmask = gmask;
1879 current_frame_info.initialized = reload_completed;
1880
1881 /* Ok, we're done. */
1882 return total_size;
1883 }
1884 \f
1885 /* When the `length' insn attribute is used, this macro specifies the
1886 value to be assigned to the address of the first insn in a
1887 function. If not specified, 0 is used. */
1888
1889 int
1890 m32r_first_insn_address ()
1891 {
1892 if (! current_frame_info.initialized)
1893 m32r_compute_frame_size (get_frame_size ());
1894
1895 return 0;
1896 }
1897 \f
1898 /* Expand the m32r prologue as a series of insns. */
1899
1900 void
1901 m32r_expand_prologue ()
1902 {
1903 int regno;
1904 int frame_size;
1905 unsigned int gmask;
1906
1907 if (! current_frame_info.initialized)
1908 m32r_compute_frame_size (get_frame_size ());
1909
1910 gmask = current_frame_info.gmask;
1911
1912 /* These cases shouldn't happen. Catch them now. */
1913 if (current_frame_info.total_size == 0 && gmask)
1914 abort ();
1915
1916 /* Allocate space for register arguments if this is a variadic function. */
1917 if (current_frame_info.pretend_size != 0)
1918 {
1919 /* Use a HOST_WIDE_INT temporary, since negating an unsigned int gives
1920 the wrong result on a 64-bit host. */
1921 HOST_WIDE_INT pretend_size = current_frame_info.pretend_size;
1922 emit_insn (gen_addsi3 (stack_pointer_rtx,
1923 stack_pointer_rtx,
1924 GEN_INT (-pretend_size)));
1925 }
1926
1927 /* Save any registers we need to and set up fp. */
1928
1929 if (current_frame_info.save_fp)
1930 emit_insn (gen_movsi_push (stack_pointer_rtx, frame_pointer_rtx));
1931
1932 gmask &= ~(FRAME_POINTER_MASK | RETURN_ADDR_MASK);
1933
1934 /* Save any needed call-saved regs (and call-used if this is an
1935 interrupt handler). */
1936 for (regno = 0; regno <= M32R_MAX_INT_REGS; ++regno)
1937 {
1938 if ((gmask & (1 << regno)) != 0)
1939 emit_insn (gen_movsi_push (stack_pointer_rtx,
1940 gen_rtx_REG (Pmode, regno)));
1941 }
1942
1943 if (current_frame_info.save_lr)
1944 emit_insn (gen_movsi_push (stack_pointer_rtx,
1945 gen_rtx_REG (Pmode, RETURN_ADDR_REGNUM)));
1946
1947 /* Allocate the stack frame. */
1948 frame_size = (current_frame_info.total_size
1949 - (current_frame_info.pretend_size
1950 + current_frame_info.reg_size));
1951
1952 if (frame_size == 0)
1953 ; /* nothing to do */
1954 else if (frame_size <= 32768)
1955 emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx,
1956 GEN_INT (-frame_size)));
1957 else
1958 {
1959 rtx tmp = gen_rtx_REG (Pmode, PROLOGUE_TMP_REGNUM);
1960 emit_insn (gen_movsi (tmp, GEN_INT (frame_size)));
1961 emit_insn (gen_subsi3 (stack_pointer_rtx, stack_pointer_rtx, tmp));
1962 }
1963
1964 if (frame_pointer_needed)
1965 emit_insn (gen_movsi (frame_pointer_rtx, stack_pointer_rtx));
1966
1967 if (profile_flag || profile_block_flag)
1968 emit_insn (gen_blockage ());
1969 }
1970
1971 \f
1972 /* Set up the stack and frame pointer (if desired) for the function.
1973 Note, if this is changed, you need to mirror the changes in
1974 m32r_compute_frame_size which calculates the prolog size. */
1975
1976 void
1977 m32r_output_function_prologue (file, size)
1978 FILE * file;
1979 int size;
1980 {
1981 enum m32r_function_type fn_type = m32r_compute_function_type (current_function_decl);
1982
1983 /* If this is an interrupt handler, mark it as such. */
1984 if (M32R_INTERRUPT_P (fn_type))
1985 {
1986 fprintf (file, "\t%s interrupt handler\n",
1987 ASM_COMMENT_START);
1988 }
1989
1990 if (! current_frame_info.initialized)
1991 m32r_compute_frame_size (size);
1992
1993 /* This is only for the human reader. */
1994 fprintf (file,
1995 "\t%s PROLOGUE, vars= %d, regs= %d, args= %d, extra= %d\n",
1996 ASM_COMMENT_START,
1997 current_frame_info.var_size,
1998 current_frame_info.reg_size / 4,
1999 current_frame_info.args_size,
2000 current_frame_info.extra_size);
2001 }
2002 \f
2003 /* Do any necessary cleanup after a function to restore stack, frame,
2004 and regs. */
2005
2006 void
2007 m32r_output_function_epilogue (file, size)
2008 FILE * file;
2009 int size ATTRIBUTE_UNUSED;
2010 {
2011 int regno;
2012 int noepilogue = FALSE;
2013 int total_size;
2014 enum m32r_function_type fn_type = m32r_compute_function_type (current_function_decl);
2015
2016 /* This is only for the human reader. */
2017 fprintf (file, "\t%s EPILOGUE\n", ASM_COMMENT_START);
2018
2019 if (!current_frame_info.initialized)
2020 abort ();
2021 total_size = current_frame_info.total_size;
2022
2023 if (total_size == 0)
2024 {
2025 rtx insn = get_last_insn ();
2026
2027 /* If the last insn was a BARRIER, we don't have to write any code
2028 because a jump (aka return) was put there. */
2029 if (GET_CODE (insn) == NOTE)
2030 insn = prev_nonnote_insn (insn);
2031 if (insn && GET_CODE (insn) == BARRIER)
2032 noepilogue = TRUE;
2033 }
2034
2035 if (!noepilogue)
2036 {
2037 unsigned int var_size = current_frame_info.var_size;
2038 unsigned int args_size = current_frame_info.args_size;
2039 unsigned int gmask = current_frame_info.gmask;
2040 int can_trust_sp_p = !current_function_calls_alloca;
2041 const char * sp_str = reg_names[STACK_POINTER_REGNUM];
2042 const char * fp_str = reg_names[FRAME_POINTER_REGNUM];
2043
2044 /* The first thing to do is point the sp at the bottom of the register
2045 save area. */
2046 if (can_trust_sp_p)
2047 {
2048 unsigned int reg_offset = var_size + args_size;
2049 if (reg_offset == 0)
2050 ; /* nothing to do */
2051 else if (reg_offset < 128)
2052 fprintf (file, "\taddi %s,%s%d\n",
2053 sp_str, IMMEDIATE_PREFIX, reg_offset);
2054 else if (reg_offset < 32768)
2055 fprintf (file, "\tadd3 %s,%s,%s%d\n",
2056 sp_str, sp_str, IMMEDIATE_PREFIX, reg_offset);
2057 else
2058 fprintf (file, "\tld24 %s,%s%d\n\tadd %s,%s\n",
2059 reg_names[PROLOGUE_TMP_REGNUM],
2060 IMMEDIATE_PREFIX, reg_offset,
2061 sp_str, reg_names[PROLOGUE_TMP_REGNUM]);
2062 }
2063 else if (frame_pointer_needed)
2064 {
2065 unsigned int reg_offset = var_size + args_size;
2066 if (reg_offset == 0)
2067 fprintf (file, "\tmv %s,%s\n", sp_str, fp_str);
2068 else if (reg_offset < 32768)
2069 fprintf (file, "\tadd3 %s,%s,%s%d\n",
2070 sp_str, fp_str, IMMEDIATE_PREFIX, reg_offset);
2071 else
2072 fprintf (file, "\tld24 %s,%s%d\n\tadd %s,%s\n",
2073 reg_names[PROLOGUE_TMP_REGNUM],
2074 IMMEDIATE_PREFIX, reg_offset,
2075 sp_str, reg_names[PROLOGUE_TMP_REGNUM]);
2076 }
2077 else
2078 abort ();
2079
2080 if (current_frame_info.save_lr)
2081 fprintf (file, "\tpop %s\n", reg_names[RETURN_ADDR_REGNUM]);
2082
2083 /* Restore any saved registers, in reverse order of course. */
2084 gmask &= ~(FRAME_POINTER_MASK | RETURN_ADDR_MASK);
2085 for (regno = M32R_MAX_INT_REGS - 1; regno >= 0; --regno)
2086 {
2087 if ((gmask & (1L << regno)) != 0)
2088 fprintf (file, "\tpop %s\n", reg_names[regno]);
2089 }
2090
2091 if (current_frame_info.save_fp)
2092 fprintf (file, "\tpop %s\n", fp_str);
2093
2094 /* Remove varargs area if present. */
2095 if (current_frame_info.pretend_size != 0)
2096 fprintf (file, "\taddi %s,%s%d\n",
2097 sp_str, IMMEDIATE_PREFIX, current_frame_info.pretend_size);
2098
2099 /* Emit the return instruction. */
2100 if (M32R_INTERRUPT_P (fn_type))
2101 fprintf (file, "\trte\n");
2102 else
2103 fprintf (file, "\tjmp %s\n", reg_names[RETURN_ADDR_REGNUM]);
2104 }
2105
2106 #if 0 /* no longer needed */
2107 /* Ensure the function cleanly ends on a 32 bit boundary. */
2108 fprintf (file, "\t.fillinsn\n");
2109 #endif
2110
2111 /* Reset state info for each function. */
2112 current_frame_info = zero_frame_info;
2113 m32r_compute_function_type (NULL_TREE);
2114 }
2115 \f
2116 /* Return non-zero if this function is known to have a null or 1 instruction
2117 epilogue. */
2118
2119 int
2120 direct_return ()
2121 {
2122 if (!reload_completed)
2123 return FALSE;
2124
2125 if (! current_frame_info.initialized)
2126 m32r_compute_frame_size (get_frame_size ());
2127
2128 return current_frame_info.total_size == 0;
2129 }
2130
2131 \f
2132 /* PIC */
2133
2134 /* Emit special PIC prologues and epilogues. */
2135
2136 void
2137 m32r_finalize_pic ()
2138 {
2139 /* nothing to do */
2140 }
2141 \f
2142 /* Nested function support. */
2143
2144 /* Emit RTL insns to initialize the variable parts of a trampoline.
2145 FNADDR is an RTX for the address of the function's pure code.
2146 CXT is an RTX for the static chain value for the function. */
2147
2148 void
2149 m32r_initialize_trampoline (tramp, fnaddr, cxt)
2150 rtx tramp ATTRIBUTE_UNUSED;
2151 rtx fnaddr ATTRIBUTE_UNUSED;
2152 rtx cxt ATTRIBUTE_UNUSED;
2153 {
2154 }
2155 \f
2156 /* Set the cpu type and print out other fancy things,
2157 at the top of the file. */
2158
2159 void
2160 m32r_asm_file_start (file)
2161 FILE * file;
2162 {
2163 if (flag_verbose_asm)
2164 fprintf (file, "%s M32R/D special options: -G %d\n",
2165 ASM_COMMENT_START, g_switch_value);
2166 }
2167 \f
2168 /* Print operand X (an rtx) in assembler syntax to file FILE.
2169 CODE is a letter or dot (`z' in `%z0') or 0 if no letter was specified.
2170 For `%' followed by punctuation, CODE is the punctuation and X is null. */
2171
2172 void
2173 m32r_print_operand (file, x, code)
2174 FILE * file;
2175 rtx x;
2176 int code;
2177 {
2178 rtx addr;
2179
2180 switch (code)
2181 {
2182 /* The 's' and 'p' codes are used by output_block_move() to
2183 indicate post-increment 's'tores and 'p're-increment loads. */
2184 case 's':
2185 if (GET_CODE (x) == REG)
2186 fprintf (file, "@+%s", reg_names [REGNO (x)]);
2187 else
2188 output_operand_lossage ("invalid operand to %s code");
2189 return;
2190
2191 case 'p':
2192 if (GET_CODE (x) == REG)
2193 fprintf (file, "@%s+", reg_names [REGNO (x)]);
2194 else
2195 output_operand_lossage ("invalid operand to %p code");
2196 return;
2197
2198 case 'R' :
2199 /* Write second word of DImode or DFmode reference,
2200 register or memory. */
2201 if (GET_CODE (x) == REG)
2202 fputs (reg_names[REGNO (x)+1], file);
2203 else if (GET_CODE (x) == MEM)
2204 {
2205 fprintf (file, "@(");
2206 /* Handle possible auto-increment. Since it is pre-increment and
2207 we have already done it, we can just use an offset of four. */
2208 /* ??? This is taken from rs6000.c I think. I don't think it is
2209 currently necessary, but keep it around. */
2210 if (GET_CODE (XEXP (x, 0)) == PRE_INC
2211 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
2212 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 4));
2213 else
2214 output_address (plus_constant (XEXP (x, 0), 4));
2215 fputc (')', file);
2216 }
2217 else
2218 output_operand_lossage ("invalid operand to %R code");
2219 return;
2220
2221 case 'H' : /* High word */
2222 case 'L' : /* Low word */
2223 if (GET_CODE (x) == REG)
2224 {
2225 /* L = least significant word, H = most significant word */
2226 if ((WORDS_BIG_ENDIAN != 0) ^ (code == 'L'))
2227 fputs (reg_names[REGNO (x)], file);
2228 else
2229 fputs (reg_names[REGNO (x)+1], file);
2230 }
2231 else if (GET_CODE (x) == CONST_INT
2232 || GET_CODE (x) == CONST_DOUBLE)
2233 {
2234 rtx first, second;
2235
2236 split_double (x, &first, &second);
2237 fprintf (file, HOST_WIDE_INT_PRINT_HEX,
2238 code == 'L' ? INTVAL (first) : INTVAL (second));
2239 }
2240 else
2241 output_operand_lossage ("invalid operand to %H/%L code");
2242 return;
2243
2244 case 'A' :
2245 {
2246 REAL_VALUE_TYPE d;
2247 char str[30];
2248
2249 if (GET_CODE (x) != CONST_DOUBLE
2250 || GET_MODE_CLASS (GET_MODE (x)) != MODE_FLOAT)
2251 fatal_insn ("Bad insn for 'A'", x);
2252 REAL_VALUE_FROM_CONST_DOUBLE (d, x);
2253 REAL_VALUE_TO_DECIMAL (d, "%.20e", str);
2254 fprintf (file, "%s", str);
2255 return;
2256 }
2257
2258 case 'B' : /* Bottom half */
2259 case 'T' : /* Top half */
2260 /* Output the argument to a `seth' insn (sets the Top half-word).
2261 For constants output arguments to a seth/or3 pair to set Top and
2262 Bottom halves. For symbols output arguments to a seth/add3 pair to
2263 set Top and Bottom halves. The difference exists because for
2264 constants seth/or3 is more readable but for symbols we need to use
2265 the same scheme as `ld' and `st' insns (16 bit addend is signed). */
2266 switch (GET_CODE (x))
2267 {
2268 case CONST_INT :
2269 case CONST_DOUBLE :
2270 {
2271 rtx first, second;
2272
2273 split_double (x, &first, &second);
2274 x = WORDS_BIG_ENDIAN ? second : first;
2275 fprintf (file,
2276 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
2277 "0x%x",
2278 #else
2279 "0x%lx",
2280 #endif
2281 (code == 'B'
2282 ? INTVAL (x) & 0xffff
2283 : (INTVAL (x) >> 16) & 0xffff));
2284 }
2285 return;
2286 case CONST :
2287 case SYMBOL_REF :
2288 if (code == 'B'
2289 && small_data_operand (x, VOIDmode))
2290 {
2291 fputs ("sda(", file);
2292 output_addr_const (file, x);
2293 fputc (')', file);
2294 return;
2295 }
2296 /* fall through */
2297 case LABEL_REF :
2298 fputs (code == 'T' ? "shigh(" : "low(", file);
2299 output_addr_const (file, x);
2300 fputc (')', file);
2301 return;
2302 default :
2303 output_operand_lossage ("invalid operand to %T/%B code");
2304 return;
2305 }
2306 break;
2307
2308 case 'U' :
2309 /* ??? wip */
2310 /* Output a load/store with update indicator if appropriate. */
2311 if (GET_CODE (x) == MEM)
2312 {
2313 if (GET_CODE (XEXP (x, 0)) == PRE_INC
2314 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
2315 fputs (".a", file);
2316 }
2317 else
2318 output_operand_lossage ("invalid operand to %U code");
2319 return;
2320
2321 case 'N' :
2322 /* Print a constant value negated. */
2323 if (GET_CODE (x) == CONST_INT)
2324 output_addr_const (file, GEN_INT (- INTVAL (x)));
2325 else
2326 output_operand_lossage ("invalid operand to %N code");
2327 return;
2328
2329 case 'X' :
2330 /* Print a const_int in hex. Used in comments. */
2331 if (GET_CODE (x) == CONST_INT)
2332 fprintf (file,
2333 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
2334 "0x%x",
2335 #else
2336 "0x%lx",
2337 #endif
2338 INTVAL (x));
2339 return;
2340
2341 case '#' :
2342 fputs (IMMEDIATE_PREFIX, file);
2343 return;
2344
2345 #if 0 /* ??? no longer used */
2346 case '@' :
2347 fputs (reg_names[SDA_REGNUM], file);
2348 return;
2349 #endif
2350
2351 case 0 :
2352 /* Do nothing special. */
2353 break;
2354
2355 default :
2356 /* Unknown flag. */
2357 output_operand_lossage ("invalid operand output code");
2358 }
2359
2360 switch (GET_CODE (x))
2361 {
2362 case REG :
2363 fputs (reg_names[REGNO (x)], file);
2364 break;
2365
2366 case MEM :
2367 addr = XEXP (x, 0);
2368 if (GET_CODE (addr) == PRE_INC)
2369 {
2370 if (GET_CODE (XEXP (addr, 0)) != REG)
2371 fatal_insn ("Pre-increment address is not a register", x);
2372
2373 fprintf (file, "@+%s", reg_names[REGNO (XEXP (addr, 0))]);
2374 }
2375 else if (GET_CODE (addr) == PRE_DEC)
2376 {
2377 if (GET_CODE (XEXP (addr, 0)) != REG)
2378 fatal_insn ("Pre-decrement address is not a register", x);
2379
2380 fprintf (file, "@-%s", reg_names[REGNO (XEXP (addr, 0))]);
2381 }
2382 else if (GET_CODE (addr) == POST_INC)
2383 {
2384 if (GET_CODE (XEXP (addr, 0)) != REG)
2385 fatal_insn ("Post-increment address is not a register", x);
2386
2387 fprintf (file, "@%s+", reg_names[REGNO (XEXP (addr, 0))]);
2388 }
2389 else
2390 {
2391 fputs ("@(", file);
2392 output_address (XEXP (x, 0));
2393 fputc (')', file);
2394 }
2395 break;
2396
2397 case CONST_DOUBLE :
2398 /* We handle SFmode constants here as output_addr_const doesn't. */
2399 if (GET_MODE (x) == SFmode)
2400 {
2401 REAL_VALUE_TYPE d;
2402 long l;
2403
2404 REAL_VALUE_FROM_CONST_DOUBLE (d, x);
2405 REAL_VALUE_TO_TARGET_SINGLE (d, l);
2406 fprintf (file, "0x%08lx", l);
2407 break;
2408 }
2409
2410 /* Fall through. Let output_addr_const deal with it. */
2411
2412 default :
2413 output_addr_const (file, x);
2414 break;
2415 }
2416 }
2417
2418 /* Print a memory address as an operand to reference that memory location. */
2419
2420 void
2421 m32r_print_operand_address (file, addr)
2422 FILE * file;
2423 rtx addr;
2424 {
2425 register rtx base;
2426 register rtx index = 0;
2427 int offset = 0;
2428
2429 switch (GET_CODE (addr))
2430 {
2431 case REG :
2432 fputs (reg_names[REGNO (addr)], file);
2433 break;
2434
2435 case PLUS :
2436 if (GET_CODE (XEXP (addr, 0)) == CONST_INT)
2437 offset = INTVAL (XEXP (addr, 0)), base = XEXP (addr, 1);
2438 else if (GET_CODE (XEXP (addr, 1)) == CONST_INT)
2439 offset = INTVAL (XEXP (addr, 1)), base = XEXP (addr, 0);
2440 else
2441 base = XEXP (addr, 0), index = XEXP (addr, 1);
2442 if (GET_CODE (base) == REG)
2443 {
2444 /* Print the offset first (if present) to conform to the manual. */
2445 if (index == 0)
2446 {
2447 if (offset != 0)
2448 fprintf (file, "%d,", offset);
2449 fputs (reg_names[REGNO (base)], file);
2450 }
2451 /* The chip doesn't support this, but left in for generality. */
2452 else if (GET_CODE (index) == REG)
2453 fprintf (file, "%s,%s",
2454 reg_names[REGNO (base)], reg_names[REGNO (index)]);
2455 /* Not sure this can happen, but leave in for now. */
2456 else if (GET_CODE (index) == SYMBOL_REF)
2457 {
2458 output_addr_const (file, index);
2459 fputc (',', file);
2460 fputs (reg_names[REGNO (base)], file);
2461 }
2462 else
2463 fatal_insn ("Bad address", addr);
2464 }
2465 else if (GET_CODE (base) == LO_SUM)
2466 {
2467 if (index != 0
2468 || GET_CODE (XEXP (base, 0)) != REG)
2469 abort ();
2470 if (small_data_operand (XEXP (base, 1), VOIDmode))
2471 fputs ("sda(", file);
2472 else
2473 fputs ("low(", file);
2474 output_addr_const (file, plus_constant (XEXP (base, 1), offset));
2475 fputs ("),", file);
2476 fputs (reg_names[REGNO (XEXP (base, 0))], file);
2477 }
2478 else
2479 fatal_insn ("Bad address", addr);
2480 break;
2481
2482 case LO_SUM :
2483 if (GET_CODE (XEXP (addr, 0)) != REG)
2484 fatal_insn ("Lo_sum not of register", addr);
2485 if (small_data_operand (XEXP (addr, 1), VOIDmode))
2486 fputs ("sda(", file);
2487 else
2488 fputs ("low(", file);
2489 output_addr_const (file, XEXP (addr, 1));
2490 fputs ("),", file);
2491 fputs (reg_names[REGNO (XEXP (addr, 0))], file);
2492 break;
2493
2494 case PRE_INC : /* Assume SImode */
2495 fprintf (file, "+%s", reg_names[REGNO (XEXP (addr, 0))]);
2496 break;
2497
2498 case PRE_DEC : /* Assume SImode */
2499 fprintf (file, "-%s", reg_names[REGNO (XEXP (addr, 0))]);
2500 break;
2501
2502 case POST_INC : /* Assume SImode */
2503 fprintf (file, "%s+", reg_names[REGNO (XEXP (addr, 0))]);
2504 break;
2505
2506 default :
2507 output_addr_const (file, addr);
2508 break;
2509 }
2510 }
2511
2512 /* Return true if the operands are the constants 0 and 1. */
2513 int
2514 zero_and_one (operand1, operand2)
2515 rtx operand1;
2516 rtx operand2;
2517 {
2518 return
2519 GET_CODE (operand1) == CONST_INT
2520 && GET_CODE (operand2) == CONST_INT
2521 && ( ((INTVAL (operand1) == 0) && (INTVAL (operand2) == 1))
2522 ||((INTVAL (operand1) == 1) && (INTVAL (operand2) == 0)));
2523 }
2524
2525 /* Return non-zero if the operand is suitable for use in a conditional move sequence. */
2526 int
2527 conditional_move_operand (operand, mode)
2528 rtx operand;
2529 enum machine_mode mode;
2530 {
2531 /* Only defined for simple integers so far... */
2532 if (mode != SImode && mode != HImode && mode != QImode)
2533 return FALSE;
2534
2535 /* At the moment we can hanndle moving registers and loading constants. */
2536 /* To be added: Addition/subtraction/bitops/multiplication of registers. */
2537
2538 switch (GET_CODE (operand))
2539 {
2540 case REG:
2541 return 1;
2542
2543 case CONST_INT:
2544 return INT8_P (INTVAL (operand));
2545
2546 default:
2547 #if 0
2548 fprintf (stderr, "Test for cond move op of type: %s\n",
2549 GET_RTX_NAME (GET_CODE (operand)));
2550 #endif
2551 return 0;
2552 }
2553 }
2554
2555 /* Return true if the code is a test of the carry bit */
2556 int
2557 carry_compare_operand (op, mode)
2558 rtx op;
2559 enum machine_mode mode ATTRIBUTE_UNUSED;
2560 {
2561 rtx x;
2562
2563 if (GET_MODE (op) != CCmode && GET_MODE (op) != VOIDmode)
2564 return FALSE;
2565
2566 if (GET_CODE (op) != NE && GET_CODE (op) != EQ)
2567 return FALSE;
2568
2569 x = XEXP (op, 0);
2570 if (GET_CODE (x) != REG || REGNO (x) != CARRY_REGNUM)
2571 return FALSE;
2572
2573 x = XEXP (op, 1);
2574 if (GET_CODE (x) != CONST_INT || INTVAL (x) != 0)
2575 return FALSE;
2576
2577 return TRUE;
2578 }
2579
2580 /* Generate the correct assembler code to handle the conditional loading of a
2581 value into a register. It is known that the operands satisfy the
2582 conditional_move_operand() function above. The destination is operand[0].
2583 The condition is operand [1]. The 'true' value is operand [2] and the
2584 'false' value is operand [3]. */
2585 char *
2586 emit_cond_move (operands, insn)
2587 rtx * operands;
2588 rtx insn ATTRIBUTE_UNUSED;
2589 {
2590 static char buffer [100];
2591 const char * dest = reg_names [REGNO (operands [0])];
2592
2593 buffer [0] = 0;
2594
2595 /* Destination must be a register. */
2596 if (GET_CODE (operands [0]) != REG)
2597 abort();
2598 if (! conditional_move_operand (operands [2], SImode))
2599 abort();
2600 if (! conditional_move_operand (operands [3], SImode))
2601 abort();
2602
2603 /* Check to see if the test is reversed. */
2604 if (GET_CODE (operands [1]) == NE)
2605 {
2606 rtx tmp = operands [2];
2607 operands [2] = operands [3];
2608 operands [3] = tmp;
2609 }
2610
2611 sprintf (buffer, "mvfc %s, cbr", dest);
2612
2613 /* If the true value was '0' then we need to invert the results of the move. */
2614 if (INTVAL (operands [2]) == 0)
2615 sprintf (buffer + strlen (buffer), "\n\txor3 %s, %s, #1",
2616 dest, dest);
2617
2618 return buffer;
2619 }
2620
2621 /* Returns true if the registers contained in the two
2622 rtl expressions are different. */
2623 int
2624 m32r_not_same_reg (a, b)
2625 rtx a;
2626 rtx b;
2627 {
2628 int reg_a = -1;
2629 int reg_b = -2;
2630
2631 while (GET_CODE (a) == SUBREG)
2632 a = SUBREG_REG (a);
2633
2634 if (GET_CODE (a) == REG)
2635 reg_a = REGNO (a);
2636
2637 while (GET_CODE (b) == SUBREG)
2638 b = SUBREG_REG (b);
2639
2640 if (GET_CODE (b) == REG)
2641 reg_b = REGNO (b);
2642
2643 return reg_a != reg_b;
2644 }
2645
2646 \f
2647 /* Use a library function to move some bytes. */
2648 static void
2649 block_move_call (dest_reg, src_reg, bytes_rtx)
2650 rtx dest_reg;
2651 rtx src_reg;
2652 rtx bytes_rtx;
2653 {
2654 /* We want to pass the size as Pmode, which will normally be SImode
2655 but will be DImode if we are using 64 bit longs and pointers. */
2656 if (GET_MODE (bytes_rtx) != VOIDmode
2657 && GET_MODE (bytes_rtx) != Pmode)
2658 bytes_rtx = convert_to_mode (Pmode, bytes_rtx, 1);
2659
2660 #ifdef TARGET_MEM_FUNCTIONS
2661 emit_library_call (gen_rtx (SYMBOL_REF, Pmode, "memcpy"), 0,
2662 VOIDmode, 3, dest_reg, Pmode, src_reg, Pmode,
2663 convert_to_mode (TYPE_MODE (sizetype), bytes_rtx,
2664 TREE_UNSIGNED (sizetype)),
2665 TYPE_MODE (sizetype));
2666 #else
2667 emit_library_call (gen_rtx (SYMBOL_REF, Pmode, "bcopy"), 0,
2668 VOIDmode, 3, src_reg, Pmode, dest_reg, Pmode,
2669 convert_to_mode (TYPE_MODE (integer_type_node), bytes_rtx,
2670 TREE_UNSIGNED (integer_type_node)),
2671 TYPE_MODE (integer_type_node));
2672 #endif
2673 }
2674
2675 /* The maximum number of bytes to copy using pairs of load/store instructions.
2676 If a block is larger than this then a loop will be generated to copy
2677 MAX_MOVE_BYTES chunks at a time. The value of 32 is a semi-arbitary choice.
2678 A customer uses Dhrystome as their benchmark, and Dhrystone has a 31 byte
2679 string copy in it. */
2680 #define MAX_MOVE_BYTES 32
2681
2682 /* Expand string/block move operations.
2683
2684 operands[0] is the pointer to the destination.
2685 operands[1] is the pointer to the source.
2686 operands[2] is the number of bytes to move.
2687 operands[3] is the alignment. */
2688
2689 void
2690 m32r_expand_block_move (operands)
2691 rtx operands[];
2692 {
2693 rtx orig_dst = operands[0];
2694 rtx orig_src = operands[1];
2695 rtx bytes_rtx = operands[2];
2696 rtx align_rtx = operands[3];
2697 int constp = GET_CODE (bytes_rtx) == CONST_INT;
2698 HOST_WIDE_INT bytes = constp ? INTVAL (bytes_rtx) : 0;
2699 int align = INTVAL (align_rtx);
2700 int leftover;
2701 rtx src_reg;
2702 rtx dst_reg;
2703
2704 if (constp && bytes <= 0)
2705 return;
2706
2707 /* Move the address into scratch registers. */
2708 dst_reg = copy_addr_to_reg (XEXP (orig_dst, 0));
2709 src_reg = copy_addr_to_reg (XEXP (orig_src, 0));
2710
2711 if (align > UNITS_PER_WORD)
2712 align = UNITS_PER_WORD;
2713
2714 /* If we prefer size over speed, always use a function call.
2715 If we do not know the size, use a function call.
2716 If the blocks are not word aligned, use a function call. */
2717 if (optimize_size || ! constp || align != UNITS_PER_WORD)
2718 {
2719 block_move_call (dst_reg, src_reg, bytes_rtx);
2720 return;
2721 }
2722
2723 leftover = bytes % MAX_MOVE_BYTES;
2724 bytes -= leftover;
2725
2726 /* If necessary, generate a loop to handle the bulk of the copy. */
2727 if (bytes)
2728 {
2729 rtx label;
2730 rtx final_src;
2731 rtx at_a_time = GEN_INT (MAX_MOVE_BYTES);
2732 rtx rounded_total = GEN_INT (bytes);
2733
2734 /* If we are going to have to perform this loop more than
2735 once, then generate a label and compute the address the
2736 source register will contain upon completion of the final
2737 itteration. */
2738 if (bytes > MAX_MOVE_BYTES)
2739 {
2740 final_src = gen_reg_rtx (Pmode);
2741
2742 if (INT16_P(bytes))
2743 emit_insn (gen_addsi3 (final_src, src_reg, rounded_total));
2744 else
2745 {
2746 emit_insn (gen_movsi (final_src, rounded_total));
2747 emit_insn (gen_addsi3 (final_src, final_src, src_reg));
2748 }
2749
2750 label = gen_label_rtx ();
2751 emit_label (label);
2752 }
2753
2754 /* It is known that output_block_move() will update src_reg to point
2755 to the word after the end of the source block, and dst_reg to point
2756 to the last word of the destination block, provided that the block
2757 is MAX_MOVE_BYTES long. */
2758 emit_insn (gen_movstrsi_internal (dst_reg, src_reg, at_a_time));
2759 emit_insn (gen_addsi3 (dst_reg, dst_reg, GEN_INT (4)));
2760
2761 if (bytes > MAX_MOVE_BYTES)
2762 {
2763 emit_insn (gen_cmpsi (src_reg, final_src));
2764 emit_jump_insn (gen_bne (label));
2765 }
2766 }
2767
2768 if (leftover)
2769 emit_insn (gen_movstrsi_internal (dst_reg, src_reg, GEN_INT (leftover)));
2770 }
2771
2772 \f
2773 /* Emit load/stores for a small constant word aligned block_move.
2774
2775 operands[0] is the memory address of the destination.
2776 operands[1] is the memory address of the source.
2777 operands[2] is the number of bytes to move.
2778 operands[3] is a temp register.
2779 operands[4] is a temp register. */
2780
2781 char *
2782 m32r_output_block_move (insn, operands)
2783 rtx insn ATTRIBUTE_UNUSED;
2784 rtx operands[];
2785 {
2786 HOST_WIDE_INT bytes = INTVAL (operands[2]);
2787 int first_time;
2788 int got_extra = 0;
2789
2790 if (bytes < 1 || bytes > MAX_MOVE_BYTES)
2791 abort ();
2792
2793 /* We do not have a post-increment store available, so the first set of
2794 stores are done without any increment, then the remaining ones can use
2795 the pre-increment addressing mode.
2796
2797 Note: expand_block_move() also relies upon this behaviour when building
2798 loops to copy large blocks. */
2799 first_time = 1;
2800
2801 while (bytes > 0)
2802 {
2803 if (bytes >= 8)
2804 {
2805 if (first_time)
2806 {
2807 output_asm_insn ("ld\t%3, %p1", operands);
2808 output_asm_insn ("ld\t%4, %p1", operands);
2809 output_asm_insn ("st\t%3, @%0", operands);
2810 output_asm_insn ("st\t%4, %s0", operands);
2811 }
2812 else
2813 {
2814 output_asm_insn ("ld\t%3, %p1", operands);
2815 output_asm_insn ("ld\t%4, %p1", operands);
2816 output_asm_insn ("st\t%3, %s0", operands);
2817 output_asm_insn ("st\t%4, %s0", operands);
2818 }
2819
2820 bytes -= 8;
2821 }
2822 else if (bytes >= 4)
2823 {
2824 if (bytes > 4)
2825 got_extra = 1;
2826
2827 output_asm_insn ("ld\t%3, %p1", operands);
2828
2829 if (got_extra)
2830 output_asm_insn ("ld\t%4, %p1", operands);
2831
2832 if (first_time)
2833 output_asm_insn ("st\t%3, @%0", operands);
2834 else
2835 output_asm_insn ("st\t%3, %s0", operands);
2836
2837 bytes -= 4;
2838 }
2839 else
2840 {
2841 /* Get the entire next word, even though we do not want all of it.
2842 The saves us from doing several smaller loads, and we assume that
2843 we cannot cause a page fault when at least part of the word is in
2844 valid memory [since we don't get called if things aren't properly
2845 aligned]. */
2846 int dst_offset = first_time ? 0 : 4;
2847 int last_shift;
2848 rtx my_operands[3];
2849
2850 /* If got_extra is true then we have already loaded
2851 the next word as part of loading and storing the previous word. */
2852 if (! got_extra)
2853 output_asm_insn ("ld\t%4, @%1", operands);
2854
2855 if (bytes >= 2)
2856 {
2857 bytes -= 2;
2858
2859 output_asm_insn ("sra3\t%3, %4, #16", operands);
2860 my_operands[0] = operands[3];
2861 my_operands[1] = GEN_INT (dst_offset);
2862 my_operands[2] = operands[0];
2863 output_asm_insn ("sth\t%0, @(%1,%2)", my_operands);
2864
2865 /* If there is a byte left to store then increment the
2866 destination address and shift the contents of the source
2867 register down by 8 bits. We could not do the address
2868 increment in the store half word instruction, because it does
2869 not have an auto increment mode. */
2870 if (bytes > 0) /* assert (bytes == 1) */
2871 {
2872 dst_offset += 2;
2873 last_shift = 8;
2874 }
2875 }
2876 else
2877 last_shift = 24;
2878
2879 if (bytes > 0)
2880 {
2881 my_operands[0] = operands[4];
2882 my_operands[1] = GEN_INT (last_shift);
2883 output_asm_insn ("srai\t%0, #%1", my_operands);
2884 my_operands[0] = operands[4];
2885 my_operands[1] = GEN_INT (dst_offset);
2886 my_operands[2] = operands[0];
2887 output_asm_insn ("stb\t%0, @(%1,%2)", my_operands);
2888 }
2889
2890 bytes = 0;
2891 }
2892
2893 first_time = 0;
2894 }
2895
2896 return "";
2897 }
2898
2899 /* Return true if op is an integer constant, less than or equal to
2900 MAX_MOVE_BYTES. */
2901 int
2902 m32r_block_immediate_operand (op, mode)
2903 rtx op;
2904 enum machine_mode mode ATTRIBUTE_UNUSED;
2905 {
2906 if (GET_CODE (op) != CONST_INT
2907 || INTVAL (op) > MAX_MOVE_BYTES
2908 || INTVAL (op) <= 0)
2909 return 0;
2910
2911 return 1;
2912 }