1 /* Subroutines used for code generation on the Argonaut ARC cpu.
2 Copyright (C) 1994, 1995, 1997, 1998, 1999,
3 2000 Free Software Foundation, Inc.
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* ??? This is an old port, and is undoubtedly suffering from bit rot. */
29 #include "hard-reg-set.h"
31 #include "insn-config.h"
32 #include "conditions.h"
33 #include "insn-flags.h"
35 #include "insn-attr.h"
43 /* Which cpu we're compiling for (NULL(=base), ???). */
44 const char *arc_cpu_string
;
47 /* Name of mangle string to add to symbols to separate code compiled for each
49 const char *arc_mangle_cpu
;
51 /* Save the operands last given to a compare for use when we
52 generate a scc or bcc insn. */
53 rtx arc_compare_op0
, arc_compare_op1
;
55 /* Name of text, data, and rodata sections, as specified on command line.
56 Selected by -m{text,data,rodata} flags. */
57 const char *arc_text_string
= ARC_DEFAULT_TEXT_SECTION
;
58 const char *arc_data_string
= ARC_DEFAULT_DATA_SECTION
;
59 const char *arc_rodata_string
= ARC_DEFAULT_RODATA_SECTION
;
61 /* Name of text, data, and rodata sections used in varasm.c. */
62 const char *arc_text_section
;
63 const char *arc_data_section
;
64 const char *arc_rodata_section
;
66 /* Array of valid operand punctuation characters. */
67 char arc_punct_chars
[256];
69 /* Variables used by arc_final_prescan_insn to implement conditional
71 static int arc_ccfsm_state
;
72 static int arc_ccfsm_current_cc
;
73 static rtx arc_ccfsm_target_insn
;
74 static int arc_ccfsm_target_label
;
76 /* The maximum number of insns skipped which will be conditionalised if
78 #define MAX_INSNS_SKIPPED 3
80 /* A nop is needed between a 4 byte insn that sets the condition codes and
81 a branch that uses them (the same isn't true for an 8 byte insn that sets
82 the condition codes). Set by arc_final_prescan_insn. Used by
84 static int last_insn_set_cc_p
;
85 static int current_insn_set_cc_p
;
86 static void record_cc_ref
PARAMS ((rtx
));
87 static void arc_init_reg_tables
PARAMS ((void));
88 static int get_arc_condition_code
PARAMS ((rtx
));
90 /* Called by OVERRIDE_OPTIONS to initialize various things. */
97 if (arc_cpu_string
== 0
98 || !strcmp (arc_cpu_string
, "base"))
100 /* Ensure we have a printable value for the .cpu pseudo-op. */
101 arc_cpu_string
= "base";
103 arc_mangle_cpu
= NULL
;
105 else if (ARC_EXTENSION_CPU (arc_cpu_string
))
106 ; /* nothing to do */
109 error ("bad value (%s) for -mcpu switch", arc_cpu_string
);
110 arc_cpu_string
= "base";
112 arc_mangle_cpu
= NULL
;
115 /* Set the pseudo-ops for the various standard sections. */
116 arc_text_section
= tmp
= xmalloc (strlen (arc_text_string
) + sizeof (ARC_SECTION_FORMAT
) + 1);
117 sprintf (tmp
, ARC_SECTION_FORMAT
, arc_text_string
);
118 arc_data_section
= tmp
= xmalloc (strlen (arc_data_string
) + sizeof (ARC_SECTION_FORMAT
) + 1);
119 sprintf (tmp
, ARC_SECTION_FORMAT
, arc_data_string
);
120 arc_rodata_section
= tmp
= xmalloc (strlen (arc_rodata_string
) + sizeof (ARC_SECTION_FORMAT
) + 1);
121 sprintf (tmp
, ARC_SECTION_FORMAT
, arc_rodata_string
);
123 arc_init_reg_tables ();
125 /* Initialize array for PRINT_OPERAND_PUNCT_VALID_P. */
126 memset (arc_punct_chars
, 0, sizeof (arc_punct_chars
));
127 arc_punct_chars
['#'] = 1;
128 arc_punct_chars
['*'] = 1;
129 arc_punct_chars
['?'] = 1;
130 arc_punct_chars
['!'] = 1;
131 arc_punct_chars
['~'] = 1;
134 /* The condition codes of the ARC, and the inverse function. */
135 static const char *const arc_condition_codes
[] =
137 "al", 0, "eq", "ne", "p", "n", "c", "nc", "v", "nv",
138 "gt", "le", "ge", "lt", "hi", "ls", "pnz", 0
141 #define ARC_INVERSE_CONDITION_CODE(X) ((X) ^ 1)
143 /* Returns the index of the ARC condition code string in
144 `arc_condition_codes'. COMPARISON should be an rtx like
145 `(eq (...) (...))'. */
148 get_arc_condition_code (comparison
)
151 switch (GET_CODE (comparison
))
159 case GTU
: return 14;
160 case LEU
: return 15;
169 /* Given a comparison code (EQ, NE, etc.) and the first operand of a COMPARE,
170 return the mode to be used for the comparison. */
173 arc_select_cc_mode (op
, x
, y
)
175 rtx x
, y ATTRIBUTE_UNUSED
;
183 switch (GET_CODE (x
))
202 /* Vectors to keep interesting information about registers where it can easily
203 be got. We use to use the actual mode value as the bit number, but there
204 is (or may be) more than 32 modes now. Instead we use two tables: one
205 indexed by hard register number, and one indexed by mode. */
207 /* The purpose of arc_mode_class is to shrink the range of modes so that
208 they all fit (as bit numbers) in a 32 bit word (again). Each real mode is
209 mapped into one arc_mode_class mode. */
211 enum arc_mode_class
{
213 S_MODE
, D_MODE
, T_MODE
, O_MODE
,
214 SF_MODE
, DF_MODE
, TF_MODE
, OF_MODE
217 /* Modes for condition codes. */
218 #define C_MODES (1 << (int) C_MODE)
220 /* Modes for single-word and smaller quantities. */
221 #define S_MODES ((1 << (int) S_MODE) | (1 << (int) SF_MODE))
223 /* Modes for double-word and smaller quantities. */
224 #define D_MODES (S_MODES | (1 << (int) D_MODE) | (1 << DF_MODE))
226 /* Modes for quad-word and smaller quantities. */
227 #define T_MODES (D_MODES | (1 << (int) T_MODE) | (1 << (int) TF_MODE))
229 /* Value is 1 if register/mode pair is acceptable on arc. */
231 unsigned int arc_hard_regno_mode_ok
[] = {
232 T_MODES
, T_MODES
, T_MODES
, T_MODES
, T_MODES
, T_MODES
, T_MODES
, T_MODES
,
233 T_MODES
, T_MODES
, T_MODES
, T_MODES
, T_MODES
, T_MODES
, T_MODES
, T_MODES
,
234 T_MODES
, T_MODES
, T_MODES
, T_MODES
, T_MODES
, T_MODES
, T_MODES
, D_MODES
,
235 D_MODES
, S_MODES
, S_MODES
, S_MODES
, S_MODES
, S_MODES
, S_MODES
, S_MODES
,
237 /* ??? Leave these as S_MODES for now. */
238 S_MODES
, S_MODES
, S_MODES
, S_MODES
, S_MODES
, S_MODES
, S_MODES
, S_MODES
,
239 S_MODES
, S_MODES
, S_MODES
, S_MODES
, S_MODES
, S_MODES
, S_MODES
, S_MODES
,
240 S_MODES
, S_MODES
, S_MODES
, S_MODES
, S_MODES
, S_MODES
, S_MODES
, S_MODES
,
241 S_MODES
, S_MODES
, S_MODES
, S_MODES
, S_MODES
, C_MODES
244 unsigned int arc_mode_class
[NUM_MACHINE_MODES
];
246 enum reg_class arc_regno_reg_class
[FIRST_PSEUDO_REGISTER
];
249 arc_init_reg_tables ()
253 for (i
= 0; i
< NUM_MACHINE_MODES
; i
++)
255 switch (GET_MODE_CLASS (i
))
258 case MODE_PARTIAL_INT
:
259 case MODE_COMPLEX_INT
:
260 if (GET_MODE_SIZE (i
) <= 4)
261 arc_mode_class
[i
] = 1 << (int) S_MODE
;
262 else if (GET_MODE_SIZE (i
) == 8)
263 arc_mode_class
[i
] = 1 << (int) D_MODE
;
264 else if (GET_MODE_SIZE (i
) == 16)
265 arc_mode_class
[i
] = 1 << (int) T_MODE
;
266 else if (GET_MODE_SIZE (i
) == 32)
267 arc_mode_class
[i
] = 1 << (int) O_MODE
;
269 arc_mode_class
[i
] = 0;
272 case MODE_COMPLEX_FLOAT
:
273 if (GET_MODE_SIZE (i
) <= 4)
274 arc_mode_class
[i
] = 1 << (int) SF_MODE
;
275 else if (GET_MODE_SIZE (i
) == 8)
276 arc_mode_class
[i
] = 1 << (int) DF_MODE
;
277 else if (GET_MODE_SIZE (i
) == 16)
278 arc_mode_class
[i
] = 1 << (int) TF_MODE
;
279 else if (GET_MODE_SIZE (i
) == 32)
280 arc_mode_class
[i
] = 1 << (int) OF_MODE
;
282 arc_mode_class
[i
] = 0;
286 /* mode_class hasn't been initialized yet for EXTRA_CC_MODES, so
287 we must explicitly check for them here. */
288 if (i
== (int) CCmode
|| i
== (int) CCZNmode
|| i
== (int) CCZNCmode
)
289 arc_mode_class
[i
] = 1 << (int) C_MODE
;
291 arc_mode_class
[i
] = 0;
296 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
299 arc_regno_reg_class
[i
] = GENERAL_REGS
;
301 arc_regno_reg_class
[i
] = LPCOUNT_REG
;
303 arc_regno_reg_class
[i
] = NO_REGS
/* CC_REG: must be NO_REGS */;
305 arc_regno_reg_class
[i
] = NO_REGS
;
309 /* ARC specific attribute support.
311 The ARC has these attributes:
312 interrupt - for interrupt functions
315 /* Return nonzero if IDENTIFIER is a valid decl attribute. */
318 arc_valid_machine_decl_attribute (type
, attributes
, identifier
, args
)
319 tree type ATTRIBUTE_UNUSED
;
320 tree attributes ATTRIBUTE_UNUSED
;
324 if (identifier
== get_identifier ("__interrupt__")
325 && list_length (args
) == 1
326 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
)
328 tree value
= TREE_VALUE (args
);
330 if (!strcmp (TREE_STRING_POINTER (value
), "ilink1")
331 || !strcmp (TREE_STRING_POINTER (value
), "ilink2"))
337 /* Return zero if TYPE1 and TYPE are incompatible, one if they are compatible,
338 and two if they are nearly compatible (which causes a warning to be
342 arc_comp_type_attributes (type1
, type2
)
343 tree type1 ATTRIBUTE_UNUSED
, type2 ATTRIBUTE_UNUSED
;
348 /* Set the default attributes for TYPE. */
351 arc_set_default_type_attributes (type
)
352 tree type ATTRIBUTE_UNUSED
;
356 /* Acceptable arguments to the call insn. */
359 call_address_operand (op
, mode
)
361 enum machine_mode mode
;
363 return (symbolic_operand (op
, mode
)
364 || (GET_CODE (op
) == CONST_INT
&& LEGITIMATE_CONSTANT_P (op
))
365 || (GET_CODE (op
) == REG
));
369 call_operand (op
, mode
)
371 enum machine_mode mode
;
373 if (GET_CODE (op
) != MEM
)
376 return call_address_operand (op
, mode
);
379 /* Returns 1 if OP is a symbol reference. */
382 symbolic_operand (op
, mode
)
384 enum machine_mode mode ATTRIBUTE_UNUSED
;
386 switch (GET_CODE (op
))
397 /* Return truth value of statement that OP is a symbolic memory
398 operand of mode MODE. */
401 symbolic_memory_operand (op
, mode
)
403 enum machine_mode mode ATTRIBUTE_UNUSED
;
405 if (GET_CODE (op
) == SUBREG
)
406 op
= SUBREG_REG (op
);
407 if (GET_CODE (op
) != MEM
)
410 return (GET_CODE (op
) == SYMBOL_REF
|| GET_CODE (op
) == CONST
411 || GET_CODE (op
) == LABEL_REF
);
414 /* Return true if OP is a short immediate (shimm) value. */
417 short_immediate_operand (op
, mode
)
419 enum machine_mode mode ATTRIBUTE_UNUSED
;
421 if (GET_CODE (op
) != CONST_INT
)
423 return SMALL_INT (INTVAL (op
));
426 /* Return true if OP will require a long immediate (limm) value.
427 This is currently only used when calculating length attributes. */
430 long_immediate_operand (op
, mode
)
432 enum machine_mode mode ATTRIBUTE_UNUSED
;
434 switch (GET_CODE (op
))
441 return !SMALL_INT (INTVAL (op
));
443 /* These can happen because large unsigned 32 bit constants are
444 represented this way (the multiplication patterns can cause these
445 to be generated). They also occur for SFmode values. */
453 /* Return true if OP is a MEM that when used as a load or store address will
454 require an 8 byte insn.
455 Load and store instructions don't allow the same possibilities but they're
456 similar enough that this one function will do.
457 This is currently only used when calculating length attributes. */
460 long_immediate_loadstore_operand (op
, mode
)
462 enum machine_mode mode ATTRIBUTE_UNUSED
;
464 if (GET_CODE (op
) != MEM
)
468 switch (GET_CODE (op
))
475 /* This must be handled as "st c,[limm]". Ditto for load.
476 Technically, the assembler could translate some possibilities to
477 "st c,[limm/2 + limm/2]" if limm/2 will fit in a shimm, but we don't
478 assume that it does. */
481 /* These can happen because large unsigned 32 bit constants are
482 represented this way (the multiplication patterns can cause these
483 to be generated). They also occur for SFmode values. */
488 if (GET_CODE (XEXP (op
, 1)) == CONST_INT
489 && !SMALL_INT (INTVAL (XEXP (op
, 1))))
498 /* Return true if OP is an acceptable argument for a single word
502 move_src_operand (op
, mode
)
504 enum machine_mode mode
;
506 switch (GET_CODE (op
))
513 return (LARGE_INT (INTVAL (op
)));
515 /* We can handle DImode integer constants in SImode if the value
516 (signed or unsigned) will fit in 32 bits. This is needed because
517 large unsigned 32 bit constants are represented as CONST_DOUBLEs. */
519 return arc_double_limm_p (op
);
520 /* We can handle 32 bit floating point constants. */
522 return GET_MODE (op
) == SFmode
;
525 return register_operand (op
, mode
);
527 /* (subreg (mem ...) ...) can occur here if the inner part was once a
528 pseudo-reg and is now a stack slot. */
529 if (GET_CODE (SUBREG_REG (op
)) == MEM
)
530 return address_operand (XEXP (SUBREG_REG (op
), 0), mode
);
532 return register_operand (op
, mode
);
534 return address_operand (XEXP (op
, 0), mode
);
540 /* Return true if OP is an acceptable argument for a double word
544 move_double_src_operand (op
, mode
)
546 enum machine_mode mode
;
548 switch (GET_CODE (op
))
551 return register_operand (op
, mode
);
553 /* (subreg (mem ...) ...) can occur here if the inner part was once a
554 pseudo-reg and is now a stack slot. */
555 if (GET_CODE (SUBREG_REG (op
)) == MEM
)
556 return move_double_src_operand (SUBREG_REG (op
), mode
);
558 return register_operand (op
, mode
);
560 /* Disallow auto inc/dec for now. */
561 if (GET_CODE (XEXP (op
, 0)) == PRE_DEC
562 || GET_CODE (XEXP (op
, 0)) == PRE_INC
)
564 return address_operand (XEXP (op
, 0), mode
);
573 /* Return true if OP is an acceptable argument for a move destination. */
576 move_dest_operand (op
, mode
)
578 enum machine_mode mode
;
580 switch (GET_CODE (op
))
583 return register_operand (op
, mode
);
585 /* (subreg (mem ...) ...) can occur here if the inner part was once a
586 pseudo-reg and is now a stack slot. */
587 if (GET_CODE (SUBREG_REG (op
)) == MEM
)
588 return address_operand (XEXP (SUBREG_REG (op
), 0), mode
);
590 return register_operand (op
, mode
);
592 return address_operand (XEXP (op
, 0), mode
);
598 /* Return true if OP is valid load with update operand. */
601 load_update_operand (op
, mode
)
603 enum machine_mode mode
;
605 if (GET_CODE (op
) != MEM
606 || GET_MODE (op
) != mode
)
609 if (GET_CODE (op
) != PLUS
610 || GET_MODE (op
) != Pmode
611 || !register_operand (XEXP (op
, 0), Pmode
)
612 || !nonmemory_operand (XEXP (op
, 1), Pmode
))
617 /* Return true if OP is valid store with update operand. */
620 store_update_operand (op
, mode
)
622 enum machine_mode mode
;
624 if (GET_CODE (op
) != MEM
625 || GET_MODE (op
) != mode
)
628 if (GET_CODE (op
) != PLUS
629 || GET_MODE (op
) != Pmode
630 || !register_operand (XEXP (op
, 0), Pmode
)
631 || !(GET_CODE (XEXP (op
, 1)) == CONST_INT
632 && SMALL_INT (INTVAL (XEXP (op
, 1)))))
637 /* Return true if OP is a non-volatile non-immediate operand.
638 Volatile memory refs require a special "cache-bypass" instruction
639 and only the standard movXX patterns are set up to handle them. */
642 nonvol_nonimm_operand (op
, mode
)
644 enum machine_mode mode
;
646 if (GET_CODE (op
) == MEM
&& MEM_VOLATILE_P (op
))
648 return nonimmediate_operand (op
, mode
);
651 /* Accept integer operands in the range -0x80000000..0x7fffffff. We have
652 to check the range carefully since this predicate is used in DImode
656 const_sint32_operand (op
, mode
)
658 enum machine_mode mode ATTRIBUTE_UNUSED
;
660 /* All allowed constants will fit a CONST_INT. */
661 return (GET_CODE (op
) == CONST_INT
662 && (INTVAL (op
) >= (-0x7fffffff - 1) && INTVAL (op
) <= 0x7fffffff));
665 /* Accept integer operands in the range 0..0xffffffff. We have to check the
666 range carefully since this predicate is used in DImode contexts. Also, we
667 need some extra crud to make it work when hosted on 64-bit machines. */
670 const_uint32_operand (op
, mode
)
672 enum machine_mode mode ATTRIBUTE_UNUSED
;
674 #if HOST_BITS_PER_WIDE_INT > 32
675 /* All allowed constants will fit a CONST_INT. */
676 return (GET_CODE (op
) == CONST_INT
677 && (INTVAL (op
) >= 0 && INTVAL (op
) <= 0xffffffffL
));
679 return ((GET_CODE (op
) == CONST_INT
&& INTVAL (op
) >= 0)
680 || (GET_CODE (op
) == CONST_DOUBLE
&& CONST_DOUBLE_HIGH (op
) == 0));
684 /* Return 1 if OP is a comparison operator valid for the mode of CC.
685 This allows the use of MATCH_OPERATOR to recognize all the branch insns.
687 Some insns only set a few bits in the condition code. So only allow those
688 comparisons that use the bits that are valid. */
691 proper_comparison_operator (op
, mode
)
693 enum machine_mode mode ATTRIBUTE_UNUSED
;
695 enum rtx_code code
= GET_CODE (op
);
697 if (GET_RTX_CLASS (code
) != '<')
700 if (GET_MODE (XEXP (op
, 0)) == CCZNmode
)
701 return (code
== EQ
|| code
== NE
);
702 if (GET_MODE (XEXP (op
, 0)) == CCZNCmode
)
703 return (code
== EQ
|| code
== NE
704 || code
== LTU
|| code
== GEU
|| code
== GTU
|| code
== LEU
);
708 /* Misc. utilities. */
710 /* X and Y are two things to compare using CODE. Emit the compare insn and
711 return the rtx for the cc reg in the proper mode. */
714 gen_compare_reg (code
, x
, y
)
718 enum machine_mode mode
= SELECT_CC_MODE (code
, x
, y
);
721 cc_reg
= gen_rtx_REG (mode
, 61);
723 emit_insn (gen_rtx_SET (VOIDmode
, cc_reg
,
724 gen_rtx_COMPARE (mode
, x
, y
)));
729 /* Return 1 if VALUE, a const_double, will fit in a limm (4 byte number).
730 We assume the value can be either signed or unsigned. */
733 arc_double_limm_p (value
)
736 HOST_WIDE_INT low
, high
;
738 if (GET_CODE (value
) != CONST_DOUBLE
)
741 low
= CONST_DOUBLE_LOW (value
);
742 high
= CONST_DOUBLE_HIGH (value
);
744 if (low
& 0x80000000)
746 return (((unsigned HOST_WIDE_INT
) low
<= 0xffffffff && high
== 0)
747 || (((low
& - (unsigned HOST_WIDE_INT
) 0x80000000)
748 == - (unsigned HOST_WIDE_INT
) 0x80000000)
753 return (unsigned HOST_WIDE_INT
) low
<= 0x7fffffff && high
== 0;
757 /* Do any needed setup for a variadic function. For the ARC, we must
758 create a register parameter block, and then copy any anonymous arguments
759 in registers to memory.
761 CUM has not been updated for the last named argument which has type TYPE
762 and mode MODE, and we rely on this fact.
764 We do things a little weird here. We're supposed to only allocate space
765 for the anonymous arguments. However we need to keep the stack eight byte
766 aligned. So we round the space up if necessary, and leave it to va_start
770 arc_setup_incoming_varargs (cum
, mode
, type
, pretend_size
, no_rtl
)
771 CUMULATIVE_ARGS
*cum
;
772 enum machine_mode mode
;
773 tree type ATTRIBUTE_UNUSED
;
779 /* All BLKmode values are passed by reference. */
783 /* We must treat `__builtin_va_alist' as an anonymous arg. */
784 if (current_function_varargs
)
785 first_anon_arg
= *cum
;
787 first_anon_arg
= *cum
+ ((GET_MODE_SIZE (mode
) + UNITS_PER_WORD
- 1)
790 if (first_anon_arg
< MAX_ARC_PARM_REGS
&& !no_rtl
)
792 /* Note that first_reg_offset < MAX_ARC_PARM_REGS. */
793 int first_reg_offset
= first_anon_arg
;
794 /* Size in words to "pretend" allocate. */
795 int size
= MAX_ARC_PARM_REGS
- first_reg_offset
;
796 /* Extra slop to keep stack eight byte aligned. */
797 int align_slop
= size
& 1;
800 regblock
= gen_rtx_MEM (BLKmode
,
801 plus_constant (arg_pointer_rtx
,
802 FIRST_PARM_OFFSET (0)
803 + align_slop
* UNITS_PER_WORD
));
804 MEM_ALIAS_SET (regblock
) = get_varargs_alias_set ();
805 move_block_from_reg (first_reg_offset
, regblock
,
806 MAX_ARC_PARM_REGS
- first_reg_offset
,
807 ((MAX_ARC_PARM_REGS
- first_reg_offset
)
810 *pretend_size
= ((MAX_ARC_PARM_REGS
- first_reg_offset
+ align_slop
)
815 /* Cost functions. */
817 /* Provide the costs of an addressing mode that contains ADDR.
818 If ADDR is not a valid address, its cost is irrelevant. */
821 arc_address_cost (addr
)
824 switch (GET_CODE (addr
))
827 /* This is handled in the macro that calls us.
828 It's here for documentation. */
838 register rtx plus0
= XEXP (addr
, 0);
839 register rtx plus1
= XEXP (addr
, 1);
841 if (GET_CODE (plus0
) != REG
)
844 switch (GET_CODE (plus1
))
847 return SMALL_INT (plus1
) ? 1 : 2;
864 /* Function prologue/epilogue handlers. */
866 /* ARC stack frames look like:
868 Before call After call
869 +-----------------------+ +-----------------------+
871 high | local variables, | | local variables, |
872 mem | reg save area, etc. | | reg save area, etc. |
874 +-----------------------+ +-----------------------+
876 | arguments on stack. | | arguments on stack. |
878 SP+16->+-----------------------+FP+48->+-----------------------+
879 | 4 word save area for | | reg parm save area, |
880 | return addr, prev %fp | | only created for |
881 SP+0->+-----------------------+ | variable argument |
883 FP+16->+-----------------------+
884 | 4 word save area for |
885 | return addr, prev %fp |
886 FP+0->+-----------------------+
890 +-----------------------+
892 | register save area |
894 +-----------------------+
896 | alloca allocations |
898 +-----------------------+
900 | arguments on stack |
902 SP+16->+-----------------------+
903 low | 4 word save area for |
904 memory | return addr, prev %fp |
905 SP+0->+-----------------------+
908 1) The "reg parm save area" does not exist for non variable argument fns.
909 The "reg parm save area" can be eliminated completely if we created our
910 own va-arc.h, but that has tradeoffs as well (so it's not done). */
912 /* Structure to be filled in by arc_compute_frame_size with register
913 save masks, and offsets for the current function. */
914 struct arc_frame_info
916 unsigned int total_size
; /* # bytes that the entire frame takes up. */
917 unsigned int extra_size
; /* # bytes of extra stuff. */
918 unsigned int pretend_size
; /* # bytes we push and pretend caller did. */
919 unsigned int args_size
; /* # bytes that outgoing arguments take up. */
920 unsigned int reg_size
; /* # bytes needed to store regs. */
921 unsigned int var_size
; /* # bytes that variables take up. */
922 unsigned int reg_offset
; /* Offset from new sp to store regs. */
923 unsigned int gmask
; /* Mask of saved gp registers. */
924 int initialized
; /* Nonzero if frame size already calculated. */
927 /* Current frame information calculated by arc_compute_frame_size. */
928 static struct arc_frame_info current_frame_info
;
930 /* Zero structure to initialize current_frame_info. */
931 static struct arc_frame_info zero_frame_info
;
933 /* Type of function DECL.
935 The result is cached. To reset the cache at the end of a function,
936 call with DECL = NULL_TREE. */
938 enum arc_function_type
939 arc_compute_function_type (decl
)
944 static enum arc_function_type fn_type
= ARC_FUNCTION_UNKNOWN
;
945 /* Last function we were called for. */
946 static tree last_fn
= NULL_TREE
;
948 /* Resetting the cached value? */
949 if (decl
== NULL_TREE
)
951 fn_type
= ARC_FUNCTION_UNKNOWN
;
956 if (decl
== last_fn
&& fn_type
!= ARC_FUNCTION_UNKNOWN
)
959 /* Assume we have a normal function (not an interrupt handler). */
960 fn_type
= ARC_FUNCTION_NORMAL
;
962 /* Now see if this is an interrupt handler. */
963 for (a
= DECL_MACHINE_ATTRIBUTES (current_function_decl
);
967 tree name
= TREE_PURPOSE (a
), args
= TREE_VALUE (a
);
969 if (name
== get_identifier ("__interrupt__")
970 && list_length (args
) == 1
971 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
)
973 tree value
= TREE_VALUE (args
);
975 if (!strcmp (TREE_STRING_POINTER (value
), "ilink1"))
976 fn_type
= ARC_FUNCTION_ILINK1
;
977 else if (!strcmp (TREE_STRING_POINTER (value
), "ilink2"))
978 fn_type
= ARC_FUNCTION_ILINK2
;
989 #define ILINK1_REGNUM 29
990 #define ILINK2_REGNUM 30
991 #define RETURN_ADDR_REGNUM 31
992 #define FRAME_POINTER_MASK (1 << (FRAME_POINTER_REGNUM))
993 #define RETURN_ADDR_MASK (1 << (RETURN_ADDR_REGNUM))
995 /* Tell prologue and epilogue if register REGNO should be saved / restored.
996 The return address and frame pointer are treated separately.
997 Don't consider them here. */
998 #define MUST_SAVE_REGISTER(regno, interrupt_p) \
999 ((regno) != RETURN_ADDR_REGNUM && (regno) != FRAME_POINTER_REGNUM \
1000 && (regs_ever_live[regno] && (!call_used_regs[regno] || interrupt_p)))
1002 #define MUST_SAVE_RETURN_ADDR (regs_ever_live[RETURN_ADDR_REGNUM])
1004 /* Return the bytes needed to compute the frame pointer from the current
1007 SIZE is the size needed for local variables. */
1010 arc_compute_frame_size (size
)
1011 int size
; /* # of var. bytes allocated. */
1014 unsigned int total_size
, var_size
, args_size
, pretend_size
, extra_size
;
1015 unsigned int reg_size
, reg_offset
;
1017 enum arc_function_type fn_type
;
1021 args_size
= current_function_outgoing_args_size
;
1022 pretend_size
= current_function_pretend_args_size
;
1023 extra_size
= FIRST_PARM_OFFSET (0);
1024 total_size
= extra_size
+ pretend_size
+ args_size
+ var_size
;
1025 reg_offset
= FIRST_PARM_OFFSET(0) + current_function_outgoing_args_size
;
1029 /* See if this is an interrupt handler. Call used registers must be saved
1031 fn_type
= arc_compute_function_type (current_function_decl
);
1032 interrupt_p
= ARC_INTERRUPT_P (fn_type
);
1034 /* Calculate space needed for registers.
1035 ??? We ignore the extension registers for now. */
1037 for (regno
= 0; regno
<= 31; regno
++)
1039 if (MUST_SAVE_REGISTER (regno
, interrupt_p
))
1041 reg_size
+= UNITS_PER_WORD
;
1042 gmask
|= 1 << regno
;
1046 total_size
+= reg_size
;
1048 /* If the only space to allocate is the fp/blink save area this is an
1049 empty frame. However, if we'll be making a function call we need to
1050 allocate a stack frame for our callee's fp/blink save area. */
1051 if (total_size
== extra_size
1052 && !MUST_SAVE_RETURN_ADDR
)
1053 total_size
= extra_size
= 0;
1055 total_size
= ARC_STACK_ALIGN (total_size
);
1057 /* Save computed information. */
1058 current_frame_info
.total_size
= total_size
;
1059 current_frame_info
.extra_size
= extra_size
;
1060 current_frame_info
.pretend_size
= pretend_size
;
1061 current_frame_info
.var_size
= var_size
;
1062 current_frame_info
.args_size
= args_size
;
1063 current_frame_info
.reg_size
= reg_size
;
1064 current_frame_info
.reg_offset
= reg_offset
;
1065 current_frame_info
.gmask
= gmask
;
1066 current_frame_info
.initialized
= reload_completed
;
1068 /* Ok, we're done. */
1072 /* Common code to save/restore registers. */
1075 arc_save_restore (file
, base_reg
, offset
, gmask
, op
)
1077 const char *base_reg
;
1078 unsigned int offset
;
1087 for (regno
= 0; regno
<= 31; regno
++)
1089 if ((gmask
& (1L << regno
)) != 0)
1091 fprintf (file
, "\t%s %s,[%s,%d]\n",
1092 op
, reg_names
[regno
], base_reg
, offset
);
1093 offset
+= UNITS_PER_WORD
;
1098 /* Set up the stack and frame pointer (if desired) for the function. */
1101 arc_output_function_prologue (file
, size
)
1105 const char *sp_str
= reg_names
[STACK_POINTER_REGNUM
];
1106 const char *fp_str
= reg_names
[FRAME_POINTER_REGNUM
];
1107 unsigned int gmask
= current_frame_info
.gmask
;
1108 enum arc_function_type fn_type
= arc_compute_function_type (current_function_decl
);
1110 /* If this is an interrupt handler, set up our stack frame.
1111 ??? Optimize later. */
1112 if (ARC_INTERRUPT_P (fn_type
))
1114 fprintf (file
, "\t%s interrupt handler\n",
1116 fprintf (file
, "\tsub %s,%s,16\n", sp_str
, sp_str
);
1119 /* This is only for the human reader. */
1120 fprintf (file
, "\t%s BEGIN PROLOGUE %s vars= %d, regs= %d, args= %d, extra= %d\n",
1121 ASM_COMMENT_START
, ASM_COMMENT_START
,
1122 current_frame_info
.var_size
,
1123 current_frame_info
.reg_size
/ 4,
1124 current_frame_info
.args_size
,
1125 current_frame_info
.extra_size
);
1127 size
= ARC_STACK_ALIGN (size
);
1128 size
= (! current_frame_info
.initialized
1129 ? arc_compute_frame_size (size
)
1130 : current_frame_info
.total_size
);
1132 /* These cases shouldn't happen. Catch them now. */
1133 if (size
== 0 && gmask
)
1136 /* Allocate space for register arguments if this is a variadic function. */
1137 if (current_frame_info
.pretend_size
!= 0)
1138 fprintf (file
, "\tsub %s,%s,%d\n",
1139 sp_str
, sp_str
, current_frame_info
.pretend_size
);
1141 /* The home-grown ABI says link register is saved first. */
1142 if (MUST_SAVE_RETURN_ADDR
)
1143 fprintf (file
, "\tst %s,[%s,%d]\n",
1144 reg_names
[RETURN_ADDR_REGNUM
], sp_str
, UNITS_PER_WORD
);
1146 /* Set up the previous frame pointer next (if we need to). */
1147 if (frame_pointer_needed
)
1149 fprintf (file
, "\tst %s,[%s]\n", fp_str
, sp_str
);
1150 fprintf (file
, "\tmov %s,%s\n", fp_str
, sp_str
);
1153 /* ??? We don't handle the case where the saved regs are more than 252
1154 bytes away from sp. This can be handled by decrementing sp once, saving
1155 the regs, and then decrementing it again. The epilogue doesn't have this
1156 problem as the `ld' insn takes reg+limm values (though it would be more
1157 efficient to avoid reg+limm). */
1159 /* Allocate the stack frame. */
1160 if (size
- current_frame_info
.pretend_size
> 0)
1161 fprintf (file
, "\tsub %s,%s,%d\n",
1162 sp_str
, sp_str
, size
- current_frame_info
.pretend_size
);
1164 /* Save any needed call-saved regs (and call-used if this is an
1165 interrupt handler). */
1166 arc_save_restore (file
, sp_str
, current_frame_info
.reg_offset
,
1167 /* The zeroing of these two bits is unnecessary,
1168 but leave this in for clarity. */
1169 gmask
& ~(FRAME_POINTER_MASK
| RETURN_ADDR_MASK
),
1172 fprintf (file
, "\t%s END PROLOGUE\n", ASM_COMMENT_START
);
1175 /* Do any necessary cleanup after a function to restore stack, frame,
1179 arc_output_function_epilogue (file
, size
)
1183 rtx epilogue_delay
= current_function_epilogue_delay_list
;
1184 int noepilogue
= FALSE
;
1185 enum arc_function_type fn_type
= arc_compute_function_type (current_function_decl
);
1187 /* This is only for the human reader. */
1188 fprintf (file
, "\t%s EPILOGUE\n", ASM_COMMENT_START
);
1190 size
= ARC_STACK_ALIGN (size
);
1191 size
= (!current_frame_info
.initialized
1192 ? arc_compute_frame_size (size
)
1193 : current_frame_info
.total_size
);
1195 if (size
== 0 && epilogue_delay
== 0)
1197 rtx insn
= get_last_insn ();
1199 /* If the last insn was a BARRIER, we don't have to write any code
1200 because a jump (aka return) was put there. */
1201 if (GET_CODE (insn
) == NOTE
)
1202 insn
= prev_nonnote_insn (insn
);
1203 if (insn
&& GET_CODE (insn
) == BARRIER
)
1209 unsigned int pretend_size
= current_frame_info
.pretend_size
;
1210 unsigned int frame_size
= size
- pretend_size
;
1211 int restored
, fp_restored_p
;
1212 int can_trust_sp_p
= !current_function_calls_alloca
;
1213 const char *sp_str
= reg_names
[STACK_POINTER_REGNUM
];
1214 const char *fp_str
= reg_names
[FRAME_POINTER_REGNUM
];
1216 /* ??? There are lots of optimizations that can be done here.
1217 EG: Use fp to restore regs if it's closer.
1218 Maybe in time we'll do them all. For now, always restore regs from
1219 sp, but don't restore sp if we don't have to. */
1221 if (!can_trust_sp_p
)
1223 if (!frame_pointer_needed
)
1225 fprintf (file
,"\tsub %s,%s,%d\t\t%s sp not trusted here\n",
1226 sp_str
, fp_str
, frame_size
, ASM_COMMENT_START
);
1229 /* Restore any saved registers. */
1230 arc_save_restore (file
, sp_str
, current_frame_info
.reg_offset
,
1231 /* The zeroing of these two bits is unnecessary,
1232 but leave this in for clarity. */
1233 current_frame_info
.gmask
& ~(FRAME_POINTER_MASK
| RETURN_ADDR_MASK
),
1236 if (MUST_SAVE_RETURN_ADDR
)
1237 fprintf (file
, "\tld %s,[%s,%d]\n",
1238 reg_names
[RETURN_ADDR_REGNUM
],
1239 frame_pointer_needed
? fp_str
: sp_str
,
1240 UNITS_PER_WORD
+ (frame_pointer_needed
? 0 : frame_size
));
1242 /* Keep track of how much of the stack pointer we've restored.
1243 It makes the following a lot more readable. */
1247 /* We try to emit the epilogue delay slot insn right after the load
1248 of the return address register so that it can execute with the
1249 stack intact. Secondly, loads are delayed. */
1250 /* ??? If stack intactness is important, always emit now. */
1251 if (MUST_SAVE_RETURN_ADDR
&& epilogue_delay
!= NULL_RTX
)
1253 final_scan_insn (XEXP (epilogue_delay
, 0), file
, 1, -2, 1);
1254 epilogue_delay
= NULL_RTX
;
1257 if (frame_pointer_needed
)
1259 /* Try to restore the frame pointer in the delay slot. We can't,
1260 however, if any of these is true. */
1261 if (epilogue_delay
!= NULL_RTX
1262 || !SMALL_INT (frame_size
)
1264 || ARC_INTERRUPT_P (fn_type
))
1266 /* Note that we restore fp and sp here! */
1267 fprintf (file
, "\tld.a %s,[%s,%d]\n", fp_str
, sp_str
, frame_size
);
1268 restored
+= frame_size
;
1272 else if (!SMALL_INT (size
/* frame_size + pretend_size */)
1273 || ARC_INTERRUPT_P (fn_type
))
1275 fprintf (file
, "\tadd %s,%s,%d\n", sp_str
, sp_str
, frame_size
);
1276 restored
+= frame_size
;
1279 /* These must be done before the return insn because the delay slot
1280 does the final stack restore. */
1281 if (ARC_INTERRUPT_P (fn_type
))
1285 final_scan_insn (XEXP (epilogue_delay
, 0), file
, 1, -2, 1);
1289 /* Emit the return instruction. */
1291 static int regs
[4] = {
1292 0, RETURN_ADDR_REGNUM
, ILINK1_REGNUM
, ILINK2_REGNUM
1294 fprintf (file
, "\tj.d %s\n", reg_names
[regs
[fn_type
]]);
1297 /* If the only register saved is the return address, we need a
1298 nop, unless we have an instruction to put into it. Otherwise
1299 we don't since reloading multiple registers doesn't reference
1300 the register being loaded. */
1302 if (ARC_INTERRUPT_P (fn_type
))
1303 fprintf (file
, "\tadd %s,%s,16\n", sp_str
, sp_str
);
1304 else if (epilogue_delay
!= NULL_RTX
)
1306 if (frame_pointer_needed
&& !fp_restored_p
)
1308 if (restored
< size
)
1310 final_scan_insn (XEXP (epilogue_delay
, 0), file
, 1, -2, 1);
1312 else if (frame_pointer_needed
&& !fp_restored_p
)
1314 if (!SMALL_INT (frame_size
))
1316 /* Note that we restore fp and sp here! */
1317 fprintf (file
, "\tld.a %s,[%s,%d]\n", fp_str
, sp_str
, frame_size
);
1319 else if (restored
< size
)
1321 if (!SMALL_INT (size
- restored
))
1323 fprintf (file
, "\tadd %s,%s,%d\n",
1324 sp_str
, sp_str
, size
- restored
);
1327 fprintf (file
, "\tnop\n");
1330 /* Reset state info for each function. */
1331 current_frame_info
= zero_frame_info
;
1332 arc_compute_function_type (NULL_TREE
);
1335 /* Define the number of delay slots needed for the function epilogue.
1337 Interrupt handlers can't have any epilogue delay slots (it's always needed
1338 for something else, I think). For normal functions, we have to worry about
1339 using call-saved regs as they'll be restored before the delay slot insn.
1340 Functions with non-empty frames already have enough choices for the epilogue
1341 delay slot so for now we only consider functions with empty frames. */
1344 arc_delay_slots_for_epilogue ()
1346 if (arc_compute_function_type (current_function_decl
) != ARC_FUNCTION_NORMAL
)
1348 if (!current_frame_info
.initialized
)
1349 (void) arc_compute_frame_size (get_frame_size ());
1350 if (current_frame_info
.total_size
== 0)
1355 /* Return true if TRIAL is a valid insn for the epilogue delay slot.
1356 Any single length instruction which doesn't reference the stack or frame
1357 pointer or any call-saved register is OK. SLOT will always be 0. */
1360 arc_eligible_for_epilogue_delay (trial
, slot
)
1367 if (get_attr_length (trial
) == 1
1368 /* If registers where saved, presumably there's more than enough
1369 possibilities for the delay slot. The alternative is something
1370 more complicated (of course, if we expanded the epilogue as rtl
1371 this problem would go away). */
1372 /* ??? Note that this will always be true since only functions with
1373 empty frames have epilogue delay slots. See
1374 arc_delay_slots_for_epilogue. */
1375 && current_frame_info
.gmask
== 0
1376 && ! reg_mentioned_p (stack_pointer_rtx
, PATTERN (trial
))
1377 && ! reg_mentioned_p (frame_pointer_rtx
, PATTERN (trial
)))
1384 /* Emit special PIC prologues and epilogues. */
1392 /* Return true if OP is a shift operator. */
1395 shift_operator (op
, mode
)
1397 enum machine_mode mode ATTRIBUTE_UNUSED
;
1399 switch (GET_CODE (op
))
1410 /* Output the assembler code for doing a shift.
1411 We go to a bit of trouble to generate efficient code as the ARC only has
1412 single bit shifts. This is taken from the h8300 port. We only have one
1413 mode of shifting and can't access individual bytes like the h8300 can, so
1414 this is greatly simplified (at the expense of not generating hyper-
1417 This function is not used if the variable shift insns are present. */
1419 /* ??? We assume the output operand is the same as operand 1.
1420 This can be optimized (deleted) in the case of 1 bit shifts. */
1421 /* ??? We use the loop register here. We don't use it elsewhere (yet) and
1422 using it here will give us a chance to play with it. */
1425 output_shift (operands
)
1428 rtx shift
= operands
[3];
1429 enum machine_mode mode
= GET_MODE (shift
);
1430 enum rtx_code code
= GET_CODE (shift
);
1431 const char *shift_one
;
1438 case ASHIFT
: shift_one
= "asl %0,%0"; break;
1439 case ASHIFTRT
: shift_one
= "asr %0,%0"; break;
1440 case LSHIFTRT
: shift_one
= "lsr %0,%0"; break;
1444 if (GET_CODE (operands
[2]) != CONST_INT
)
1447 output_asm_insn ("mov lp_count,%2", operands
);
1449 output_asm_insn ("mov %4,%2", operands
);
1454 int n
= INTVAL (operands
[2]);
1456 /* If the count is negative, make it 0. */
1459 /* If the count is too big, truncate it.
1460 ANSI says shifts of GET_MODE_BITSIZE are undefined - we choose to
1461 do the intuitive thing. */
1462 else if (n
> GET_MODE_BITSIZE (mode
))
1463 n
= GET_MODE_BITSIZE (mode
);
1465 /* First see if we can do them inline. */
1469 output_asm_insn (shift_one
, operands
);
1471 /* See if we can use a rotate/and. */
1472 else if (n
== BITS_PER_WORD
- 1)
1477 output_asm_insn ("and %0,%0,1\n\tror %0,%0", operands
);
1480 /* The ARC doesn't have a rol insn. Use something else. */
1481 output_asm_insn ("asl.f 0,%0\n\tsbc %0,0,0", operands
);
1484 /* The ARC doesn't have a rol insn. Use something else. */
1485 output_asm_insn ("asl.f 0,%0\n\tadc %0,0,0", operands
);
1497 output_asm_insn ("mov lp_count,%c2", operands
);
1499 output_asm_insn ("mov %4,%c2", operands
);
1504 sprintf (buf
, "lr %%4,[status]\n\tadd %%4,%%4,6\t%s single insn loop start",
1507 sprintf (buf
, "mov %%4,%%%%st(1f)\t%s (single insn loop start) >> 2",
1509 output_asm_insn (buf
, operands
);
1510 output_asm_insn ("sr %4,[lp_start]", operands
);
1511 output_asm_insn ("add %4,%4,1", operands
);
1512 output_asm_insn ("sr %4,[lp_end]", operands
);
1513 output_asm_insn ("nop\n\tnop", operands
);
1515 asm_fprintf (asm_out_file
, "\t%s single insn loop\n",
1518 asm_fprintf (asm_out_file
, "1:\t%s single insn loop\n",
1520 output_asm_insn (shift_one
, operands
);
1524 asm_fprintf (asm_out_file
, "1:\t%s begin shift loop\n",
1526 output_asm_insn ("sub.f %4,%4,1", operands
);
1527 output_asm_insn ("nop", operands
);
1528 output_asm_insn ("bn.nd 2f", operands
);
1529 output_asm_insn (shift_one
, operands
);
1530 output_asm_insn ("b.nd 1b", operands
);
1531 asm_fprintf (asm_out_file
, "2:\t%s end shift loop\n",
1540 /* Nested function support. */
1542 /* Emit RTL insns to initialize the variable parts of a trampoline.
1543 FNADDR is an RTX for the address of the function's pure code.
1544 CXT is an RTX for the static chain value for the function. */
1547 arc_initialize_trampoline (tramp
, fnaddr
, cxt
)
1548 rtx tramp ATTRIBUTE_UNUSED
, fnaddr ATTRIBUTE_UNUSED
, cxt ATTRIBUTE_UNUSED
;
1552 /* Set the cpu type and print out other fancy things,
1553 at the top of the file. */
1556 arc_asm_file_start (file
)
1559 fprintf (file
, "\t.cpu %s\n", arc_cpu_string
);
1562 /* Print operand X (an rtx) in assembler syntax to file FILE.
1563 CODE is a letter or dot (`z' in `%z0') or 0 if no letter was specified.
1564 For `%' followed by punctuation, CODE is the punctuation and X is null. */
1567 arc_print_operand (file
, x
, code
)
1575 /* Conditional branches. For now these are equivalent. */
1577 /* Unconditional branches. Output the appropriate delay slot suffix. */
1578 if (!final_sequence
|| XVECLEN (final_sequence
, 0) == 1)
1580 /* There's nothing in the delay slot. */
1581 fputs (".nd", file
);
1585 rtx jump
= XVECEXP (final_sequence
, 0, 0);
1586 rtx delay
= XVECEXP (final_sequence
, 0, 1);
1587 if (INSN_ANNULLED_BRANCH_P (jump
))
1588 fputs (INSN_FROM_TARGET_P (delay
) ? ".jd" : ".nd", file
);
1593 case '?' : /* with leading "." */
1594 case '!' : /* without leading "." */
1595 /* This insn can be conditionally executed. See if the ccfsm machinery
1596 says it should be conditionalized. */
1597 if (arc_ccfsm_state
== 3 || arc_ccfsm_state
== 4)
1599 /* Is this insn in a delay slot? */
1600 if (final_sequence
&& XVECLEN (final_sequence
, 0) == 2)
1602 rtx insn
= XVECEXP (final_sequence
, 0, 1);
1604 /* If the insn is annulled and is from the target path, we need
1605 to inverse the condition test. */
1606 if (INSN_ANNULLED_BRANCH_P (insn
))
1608 if (INSN_FROM_TARGET_P (insn
))
1609 fprintf (file
, "%s%s",
1610 code
== '?' ? "." : "",
1611 arc_condition_codes
[ARC_INVERSE_CONDITION_CODE (arc_ccfsm_current_cc
)]);
1613 fprintf (file
, "%s%s",
1614 code
== '?' ? "." : "",
1615 arc_condition_codes
[arc_ccfsm_current_cc
]);
1619 /* This insn is executed for either path, so don't
1620 conditionalize it at all. */
1621 ; /* nothing to do */
1626 /* This insn isn't in a delay slot. */
1627 fprintf (file
, "%s%s",
1628 code
== '?' ? "." : "",
1629 arc_condition_codes
[arc_ccfsm_current_cc
]);
1634 /* Output a nop if we're between a set of the condition codes,
1635 and a conditional branch. */
1636 if (last_insn_set_cc_p
)
1637 fputs ("nop\n\t", file
);
1640 fputs (arc_condition_codes
[get_arc_condition_code (x
)], file
);
1643 fputs (arc_condition_codes
[ARC_INVERSE_CONDITION_CODE
1644 (get_arc_condition_code (x
))],
1648 /* Write second word of DImode or DFmode reference,
1649 register or memory. */
1650 if (GET_CODE (x
) == REG
)
1651 fputs (reg_names
[REGNO (x
)+1], file
);
1652 else if (GET_CODE (x
) == MEM
)
1655 /* Handle possible auto-increment. Since it is pre-increment and
1656 we have already done it, we can just use an offset of four. */
1657 /* ??? This is taken from rs6000.c I think. I don't think it is
1658 currently necessary, but keep it around. */
1659 if (GET_CODE (XEXP (x
, 0)) == PRE_INC
1660 || GET_CODE (XEXP (x
, 0)) == PRE_DEC
)
1661 output_address (plus_constant (XEXP (XEXP (x
, 0), 0), 4));
1663 output_address (plus_constant (XEXP (x
, 0), 4));
1667 output_operand_lossage ("invalid operand to %R code");
1670 if ((GET_CODE (x
) == SYMBOL_REF
&& SYMBOL_REF_FLAG (x
))
1671 || GET_CODE (x
) == LABEL_REF
)
1673 fprintf (file
, "%%st(");
1674 output_addr_const (file
, x
);
1675 fprintf (file
, ")");
1681 if (GET_CODE (x
) == REG
)
1683 /* L = least significant word, H = most significant word */
1684 if ((TARGET_BIG_ENDIAN
!= 0) ^ (code
== 'L'))
1685 fputs (reg_names
[REGNO (x
)], file
);
1687 fputs (reg_names
[REGNO (x
)+1], file
);
1689 else if (GET_CODE (x
) == CONST_INT
1690 || GET_CODE (x
) == CONST_DOUBLE
)
1694 split_double (x
, &first
, &second
);
1695 fprintf (file
, "0x%08lx",
1696 (long)(code
== 'L' ? INTVAL (first
) : INTVAL (second
)));
1699 output_operand_lossage ("invalid operand to %H/%L code");
1706 if (GET_CODE (x
) != CONST_DOUBLE
1707 || GET_MODE_CLASS (GET_MODE (x
)) != MODE_FLOAT
)
1709 REAL_VALUE_FROM_CONST_DOUBLE (d
, x
);
1710 REAL_VALUE_TO_DECIMAL (d
, "%.20e", str
);
1711 fprintf (file
, "%s", str
);
1715 /* Output a load/store with update indicator if appropriate. */
1716 if (GET_CODE (x
) == MEM
)
1718 if (GET_CODE (XEXP (x
, 0)) == PRE_INC
1719 || GET_CODE (XEXP (x
, 0)) == PRE_DEC
)
1723 output_operand_lossage ("invalid operand to %U code");
1726 /* Output cache bypass indicator for a load/store insn. Volatile memory
1727 refs are defined to use the cache bypass mechanism. */
1728 if (GET_CODE (x
) == MEM
)
1730 if (MEM_VOLATILE_P (x
))
1731 fputs (".di", file
);
1734 output_operand_lossage ("invalid operand to %V code");
1737 /* Do nothing special. */
1741 output_operand_lossage ("invalid operand output code");
1744 switch (GET_CODE (x
))
1747 fputs (reg_names
[REGNO (x
)], file
);
1751 if (GET_CODE (XEXP (x
, 0)) == PRE_INC
)
1752 output_address (plus_constant (XEXP (XEXP (x
, 0), 0),
1753 GET_MODE_SIZE (GET_MODE (x
))));
1754 else if (GET_CODE (XEXP (x
, 0)) == PRE_DEC
)
1755 output_address (plus_constant (XEXP (XEXP (x
, 0), 0),
1756 - GET_MODE_SIZE (GET_MODE (x
))));
1758 output_address (XEXP (x
, 0));
1762 /* We handle SFmode constants here as output_addr_const doesn't. */
1763 if (GET_MODE (x
) == SFmode
)
1768 REAL_VALUE_FROM_CONST_DOUBLE (d
, x
);
1769 REAL_VALUE_TO_TARGET_SINGLE (d
, l
);
1770 fprintf (file
, "0x%08lx", l
);
1773 /* Fall through. Let output_addr_const deal with it. */
1775 output_addr_const (file
, x
);
1780 /* Print a memory address as an operand to reference that memory location. */
1783 arc_print_operand_address (file
, addr
)
1787 register rtx base
, index
= 0;
1790 switch (GET_CODE (addr
))
1793 fputs (reg_names
[REGNO (addr
)], file
);
1796 if (/*???*/ 0 && SYMBOL_REF_FLAG (addr
))
1798 fprintf (file
, "%%st(");
1799 output_addr_const (file
, addr
);
1800 fprintf (file
, ")");
1803 output_addr_const (file
, addr
);
1806 if (GET_CODE (XEXP (addr
, 0)) == CONST_INT
)
1807 offset
= INTVAL (XEXP (addr
, 0)), base
= XEXP (addr
, 1);
1808 else if (GET_CODE (XEXP (addr
, 1)) == CONST_INT
)
1809 offset
= INTVAL (XEXP (addr
, 1)), base
= XEXP (addr
, 0);
1811 base
= XEXP (addr
, 0), index
= XEXP (addr
, 1);
1812 if (GET_CODE (base
) != REG
)
1814 fputs (reg_names
[REGNO (base
)], file
);
1818 fprintf (file
, ",%d", offset
);
1820 else if (GET_CODE (index
) == REG
)
1821 fprintf (file
, ",%s", reg_names
[REGNO (index
)]);
1822 else if (GET_CODE (index
) == SYMBOL_REF
)
1823 fputc (',', file
), output_addr_const (file
, index
);
1829 /* We shouldn't get here as we've lost the mode of the memory object
1830 (which says how much to inc/dec by. */
1834 output_addr_const (file
, addr
);
1839 /* Update compare/branch separation marker. */
1842 record_cc_ref (insn
)
1845 last_insn_set_cc_p
= current_insn_set_cc_p
;
1847 switch (get_attr_cond (insn
))
1852 if (get_attr_length (insn
) == 1)
1853 current_insn_set_cc_p
= 1;
1855 current_insn_set_cc_p
= 0;
1858 current_insn_set_cc_p
= 0;
1863 /* Conditional execution support.
1865 This is based on the ARM port but for now is much simpler.
1867 A finite state machine takes care of noticing whether or not instructions
1868 can be conditionally executed, and thus decrease execution time and code
1869 size by deleting branch instructions. The fsm is controlled by
1870 final_prescan_insn, and controls the actions of PRINT_OPERAND. The patterns
1871 in the .md file for the branch insns also have a hand in this. */
1873 /* The state of the fsm controlling condition codes are:
1874 0: normal, do nothing special
1875 1: don't output this insn
1876 2: don't output this insn
1877 3: make insns conditional
1878 4: make insns conditional
1880 State transitions (state->state by whom, under what condition):
1881 0 -> 1 final_prescan_insn, if insn is conditional branch
1882 0 -> 2 final_prescan_insn, if the `target' is an unconditional branch
1883 1 -> 3 branch patterns, after having not output the conditional branch
1884 2 -> 4 branch patterns, after having not output the conditional branch
1885 3 -> 0 ASM_OUTPUT_INTERNAL_LABEL, if the `target' label is reached
1886 (the target label has CODE_LABEL_NUMBER equal to
1887 arc_ccfsm_target_label).
1888 4 -> 0 final_prescan_insn, if `target' unconditional branch is reached
1890 If the jump clobbers the conditions then we use states 2 and 4.
1892 A similar thing can be done with conditional return insns.
1894 We also handle separating branches from sets of the condition code.
1895 This is done here because knowledge of the ccfsm state is required,
1896 we may not be outputting the branch. */
1899 arc_final_prescan_insn (insn
, opvec
, noperands
)
1901 rtx
*opvec ATTRIBUTE_UNUSED
;
1902 int noperands ATTRIBUTE_UNUSED
;
1904 /* BODY will hold the body of INSN. */
1905 register rtx body
= PATTERN (insn
);
1907 /* This will be 1 if trying to repeat the trick (ie: do the `else' part of
1908 an if/then/else), and things need to be reversed. */
1911 /* If we start with a return insn, we only succeed if we find another one. */
1912 int seeking_return
= 0;
1914 /* START_INSN will hold the insn from where we start looking. This is the
1915 first insn after the following code_label if REVERSE is true. */
1916 rtx start_insn
= insn
;
1918 /* Update compare/branch separation marker. */
1919 record_cc_ref (insn
);
1921 /* Allow -mdebug-ccfsm to turn this off so we can see how well it does.
1922 We can't do this in macro FINAL_PRESCAN_INSN because its called from
1923 final_scan_insn which has `optimize' as a local. */
1924 if (optimize
< 2 || TARGET_NO_COND_EXEC
)
1927 /* If in state 4, check if the target branch is reached, in order to
1928 change back to state 0. */
1929 if (arc_ccfsm_state
== 4)
1931 if (insn
== arc_ccfsm_target_insn
)
1933 arc_ccfsm_target_insn
= NULL
;
1934 arc_ccfsm_state
= 0;
1939 /* If in state 3, it is possible to repeat the trick, if this insn is an
1940 unconditional branch to a label, and immediately following this branch
1941 is the previous target label which is only used once, and the label this
1942 branch jumps to is not too far off. Or in other words "we've done the
1943 `then' part, see if we can do the `else' part." */
1944 if (arc_ccfsm_state
== 3)
1946 if (simplejump_p (insn
))
1948 start_insn
= next_nonnote_insn (start_insn
);
1949 if (GET_CODE (start_insn
) == BARRIER
)
1951 /* ??? Isn't this always a barrier? */
1952 start_insn
= next_nonnote_insn (start_insn
);
1954 if (GET_CODE (start_insn
) == CODE_LABEL
1955 && CODE_LABEL_NUMBER (start_insn
) == arc_ccfsm_target_label
1956 && LABEL_NUSES (start_insn
) == 1)
1961 else if (GET_CODE (body
) == RETURN
)
1963 start_insn
= next_nonnote_insn (start_insn
);
1964 if (GET_CODE (start_insn
) == BARRIER
)
1965 start_insn
= next_nonnote_insn (start_insn
);
1966 if (GET_CODE (start_insn
) == CODE_LABEL
1967 && CODE_LABEL_NUMBER (start_insn
) == arc_ccfsm_target_label
1968 && LABEL_NUSES (start_insn
) == 1)
1980 if (GET_CODE (insn
) != JUMP_INSN
)
1983 /* This jump might be paralleled with a clobber of the condition codes,
1984 the jump should always come first. */
1985 if (GET_CODE (body
) == PARALLEL
&& XVECLEN (body
, 0) > 0)
1986 body
= XVECEXP (body
, 0, 0);
1989 || (GET_CODE (body
) == SET
&& GET_CODE (SET_DEST (body
)) == PC
1990 && GET_CODE (SET_SRC (body
)) == IF_THEN_ELSE
))
1992 int insns_skipped
= 0, fail
= FALSE
, succeed
= FALSE
;
1993 /* Flag which part of the IF_THEN_ELSE is the LABEL_REF. */
1994 int then_not_else
= TRUE
;
1995 /* Nonzero if next insn must be the target label. */
1996 int next_must_be_target_label_p
;
1997 rtx this_insn
= start_insn
, label
= 0;
1999 /* Register the insn jumped to. */
2002 if (!seeking_return
)
2003 label
= XEXP (SET_SRC (body
), 0);
2005 else if (GET_CODE (XEXP (SET_SRC (body
), 1)) == LABEL_REF
)
2006 label
= XEXP (XEXP (SET_SRC (body
), 1), 0);
2007 else if (GET_CODE (XEXP (SET_SRC (body
), 2)) == LABEL_REF
)
2009 label
= XEXP (XEXP (SET_SRC (body
), 2), 0);
2010 then_not_else
= FALSE
;
2012 else if (GET_CODE (XEXP (SET_SRC (body
), 1)) == RETURN
)
2014 else if (GET_CODE (XEXP (SET_SRC (body
), 2)) == RETURN
)
2017 then_not_else
= FALSE
;
2022 /* See how many insns this branch skips, and what kind of insns. If all
2023 insns are okay, and the label or unconditional branch to the same
2024 label is not too far away, succeed. */
2025 for (insns_skipped
= 0, next_must_be_target_label_p
= FALSE
;
2026 !fail
&& !succeed
&& insns_skipped
< MAX_INSNS_SKIPPED
;
2031 this_insn
= next_nonnote_insn (this_insn
);
2035 if (next_must_be_target_label_p
)
2037 if (GET_CODE (this_insn
) == BARRIER
)
2039 if (GET_CODE (this_insn
) == CODE_LABEL
2040 && this_insn
== label
)
2042 arc_ccfsm_state
= 1;
2050 scanbody
= PATTERN (this_insn
);
2052 switch (GET_CODE (this_insn
))
2055 /* Succeed if it is the target label, otherwise fail since
2056 control falls in from somewhere else. */
2057 if (this_insn
== label
)
2059 arc_ccfsm_state
= 1;
2067 /* Succeed if the following insn is the target label.
2069 If return insns are used then the last insn in a function
2070 will be a barrier. */
2071 next_must_be_target_label_p
= TRUE
;
2075 /* Can handle a call insn if there are no insns after it.
2076 IE: The next "insn" is the target label. We don't have to
2077 worry about delay slots as such insns are SEQUENCE's inside
2078 INSN's. ??? It is possible to handle such insns though. */
2079 if (get_attr_cond (this_insn
) == COND_CANUSE
)
2080 next_must_be_target_label_p
= TRUE
;
2086 /* If this is an unconditional branch to the same label, succeed.
2087 If it is to another label, do nothing. If it is conditional,
2089 /* ??? Probably, the test for the SET and the PC are unnecessary. */
2091 if (GET_CODE (scanbody
) == SET
2092 && GET_CODE (SET_DEST (scanbody
)) == PC
)
2094 if (GET_CODE (SET_SRC (scanbody
)) == LABEL_REF
2095 && XEXP (SET_SRC (scanbody
), 0) == label
&& !reverse
)
2097 arc_ccfsm_state
= 2;
2100 else if (GET_CODE (SET_SRC (scanbody
)) == IF_THEN_ELSE
)
2103 else if (GET_CODE (scanbody
) == RETURN
2106 arc_ccfsm_state
= 2;
2109 else if (GET_CODE (scanbody
) == PARALLEL
)
2111 if (get_attr_cond (this_insn
) != COND_CANUSE
)
2117 /* We can only do this with insns that can use the condition
2118 codes (and don't set them). */
2119 if (GET_CODE (scanbody
) == SET
2120 || GET_CODE (scanbody
) == PARALLEL
)
2122 if (get_attr_cond (this_insn
) != COND_CANUSE
)
2125 /* We can't handle other insns like sequences. */
2137 if ((!seeking_return
) && (arc_ccfsm_state
== 1 || reverse
))
2138 arc_ccfsm_target_label
= CODE_LABEL_NUMBER (label
);
2139 else if (seeking_return
|| arc_ccfsm_state
== 2)
2141 while (this_insn
&& GET_CODE (PATTERN (this_insn
)) == USE
)
2143 this_insn
= next_nonnote_insn (this_insn
);
2144 if (this_insn
&& (GET_CODE (this_insn
) == BARRIER
2145 || GET_CODE (this_insn
) == CODE_LABEL
))
2150 /* Oh dear! we ran off the end, give up. */
2151 insn_extract (insn
);
2152 arc_ccfsm_state
= 0;
2153 arc_ccfsm_target_insn
= NULL
;
2156 arc_ccfsm_target_insn
= this_insn
;
2161 /* If REVERSE is true, ARM_CURRENT_CC needs to be inverted from
2164 arc_ccfsm_current_cc
= get_arc_condition_code (XEXP (SET_SRC (body
),
2167 if (reverse
|| then_not_else
)
2168 arc_ccfsm_current_cc
= ARC_INVERSE_CONDITION_CODE (arc_ccfsm_current_cc
);
2171 /* Restore recog_data. Getting the attributes of other insns can
2172 destroy this array, but final.c assumes that it remains intact
2173 across this call; since the insn has been recognized already we
2174 call insn_extract direct. */
2175 insn_extract (insn
);
2179 /* Record that we are currently outputting label NUM with prefix PREFIX.
2180 It it's the label we're looking for, reset the ccfsm machinery.
2182 Called from ASM_OUTPUT_INTERNAL_LABEL. */
2185 arc_ccfsm_at_label (prefix
, num
)
2189 if (arc_ccfsm_state
== 3 && arc_ccfsm_target_label
== num
2190 && !strcmp (prefix
, "L"))
2192 arc_ccfsm_state
= 0;
2193 arc_ccfsm_target_insn
= NULL_RTX
;
2197 /* See if the current insn, which is a conditional branch, is to be
2201 arc_ccfsm_branch_deleted_p ()
2203 if (arc_ccfsm_state
== 1 || arc_ccfsm_state
== 2)
2208 /* Record a branch isn't output because subsequent insns can be
2212 arc_ccfsm_record_branch_deleted ()
2214 /* Indicate we're conditionalizing insns now. */
2215 arc_ccfsm_state
+= 2;
2217 /* If the next insn is a subroutine call, we still need a nop between the
2218 cc setter and user. We need to undo the effect of calling record_cc_ref
2219 for the just deleted branch. */
2220 current_insn_set_cc_p
= last_insn_set_cc_p
;
2224 arc_va_start (stdarg_p
, valist
, nextarg
)
2229 /* See arc_setup_incoming_varargs for reasons for this oddity. */
2230 if (current_function_args_info
< 8
2231 && (current_function_args_info
& 1))
2232 nextarg
= plus_constant (nextarg
, UNITS_PER_WORD
);
2234 std_expand_builtin_va_start (stdarg_p
, valist
, nextarg
);
2238 arc_va_arg (valist
, type
)
2243 tree type_ptr
= build_pointer_type (type
);
2245 /* All aggregates are passed by reference. All scalar types larger
2246 than 8 bytes are passed by reference. */
2248 if (AGGREGATE_TYPE_P (type
) || int_size_in_bytes (type
) > 8)
2250 tree type_ptr_ptr
= build_pointer_type (type_ptr
);
2252 addr
= build (INDIRECT_REF
, type_ptr
,
2253 build (NOP_EXPR
, type_ptr_ptr
, valist
));
2255 incr
= build (PLUS_EXPR
, TREE_TYPE (valist
),
2256 valist
, build_int_2 (UNITS_PER_WORD
, 0));
2260 HOST_WIDE_INT align
, rounded_size
;
2262 /* Compute the rounded size of the type. */
2263 align
= PARM_BOUNDARY
/ BITS_PER_UNIT
;
2264 rounded_size
= (((TREE_INT_CST_LOW (TYPE_SIZE (type
)) / BITS_PER_UNIT
2265 + align
- 1) / align
) * align
);
2267 /* Align 8 byte operands. */
2269 if (TYPE_ALIGN (type
) > BITS_PER_WORD
)
2271 /* AP = (TYPE *)(((int)AP + 7) & -8) */
2273 addr
= build (NOP_EXPR
, integer_type_node
, valist
);
2274 addr
= fold (build (PLUS_EXPR
, integer_type_node
, addr
,
2275 build_int_2 (7, 0)));
2276 addr
= fold (build (BIT_AND_EXPR
, integer_type_node
, addr
,
2277 build_int_2 (-8, 0)));
2278 addr
= fold (build (NOP_EXPR
, TREE_TYPE (valist
), addr
));
2281 /* The increment is always rounded_size past the aligned pointer. */
2282 incr
= fold (build (PLUS_EXPR
, TREE_TYPE (addr
), addr
,
2283 build_int_2 (rounded_size
, 0)));
2285 /* Adjust the pointer in big-endian mode. */
2286 if (BYTES_BIG_ENDIAN
)
2289 adj
= TREE_INT_CST_LOW (TYPE_SIZE (type
)) / BITS_PER_UNIT
;
2290 if (rounded_size
> align
)
2293 addr
= fold (build (PLUS_EXPR
, TREE_TYPE (addr
), addr
,
2294 build_int_2 (rounded_size
- adj
, 0)));
2298 /* Evaluate the data address. */
2299 addr_rtx
= expand_expr (addr
, NULL_RTX
, Pmode
, EXPAND_NORMAL
);
2300 addr_rtx
= copy_to_reg (addr_rtx
);
2302 /* Compute new value for AP. */
2303 incr
= build (MODIFY_EXPR
, TREE_TYPE (valist
), valist
, incr
);
2304 TREE_SIDE_EFFECTS (incr
) = 1;
2305 expand_expr (incr
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);