1 /* Definitions of target machine for GNU compiler, for MMIX.
2 Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
4 Free Software Foundation, Inc.
5 Contributed by Hans-Peter Nilsson (hp@bitrange.com)
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3, or (at your option)
14 GCC is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
25 #include "coretypes.h"
29 #include "hard-reg-set.h"
31 #include "insn-config.h"
33 #include "basic-block.h"
38 #include "diagnostic-core.h"
45 #include "target-def.h"
48 /* First some local helper definitions. */
49 #define MMIX_FIRST_GLOBAL_REGNUM 32
51 /* We'd need a current_function_has_landing_pad. It's marked as such when
52 a nonlocal_goto_receiver is expanded. Not just a C++ thing, but
54 #define MMIX_CFUN_HAS_LANDING_PAD (cfun->machine->has_landing_pad != 0)
56 /* We have no means to tell DWARF 2 about the register stack, so we need
57 to store the return address on the stack if an exception can get into
58 this function. FIXME: Narrow condition. Before any whole-function
59 analysis, df_regs_ever_live_p () isn't initialized. We know it's up-to-date
60 after reload_completed; it may contain incorrect information some time
61 before that. Within a RTL sequence (after a call to start_sequence,
62 such as in RTL expanders), leaf_function_p doesn't see all insns
63 (perhaps any insn). But regs_ever_live is up-to-date when
64 leaf_function_p () isn't, so we "or" them together to get accurate
65 information. FIXME: Some tweak to leaf_function_p might be
67 #define MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS \
69 && ((reload_completed && df_regs_ever_live_p (MMIX_rJ_REGNUM)) \
70 || !leaf_function_p ()))
72 #define IS_MMIX_EH_RETURN_DATA_REG(REGNO) \
73 (crtl->calls_eh_return \
74 && (EH_RETURN_DATA_REGNO (0) == REGNO \
75 || EH_RETURN_DATA_REGNO (1) == REGNO \
76 || EH_RETURN_DATA_REGNO (2) == REGNO \
77 || EH_RETURN_DATA_REGNO (3) == REGNO))
79 /* For the default ABI, we rename registers at output-time to fill the gap
80 between the (statically partitioned) saved registers and call-clobbered
81 registers. In effect this makes unused call-saved registers to be used
82 as call-clobbered registers. The benefit comes from keeping the number
83 of local registers (value of rL) low, since there's a cost of
84 increasing rL and clearing unused (unset) registers with lower numbers.
85 Don't translate while outputting the prologue. */
86 #define MMIX_OUTPUT_REGNO(N) \
88 || (int) (N) < MMIX_RETURN_VALUE_REGNUM \
89 || (int) (N) > MMIX_LAST_STACK_REGISTER_REGNUM \
91 || cfun->machine == NULL \
92 || cfun->machine->in_prologue \
93 ? (N) : ((N) - MMIX_RETURN_VALUE_REGNUM \
94 + cfun->machine->highest_saved_stack_register + 1))
96 /* The %d in "POP %d,0". */
97 #define MMIX_POP_ARGUMENT() \
99 && crtl->return_rtx != NULL \
100 && ! cfun->returns_struct) \
101 ? (GET_CODE (crtl->return_rtx) == PARALLEL \
102 ? GET_NUM_ELEM (XVEC (crtl->return_rtx, 0)) : 1) \
105 /* The canonical saved comparison operands for non-cc0 machines, set in
106 the compare expander. */
107 rtx mmix_compare_op0
;
108 rtx mmix_compare_op1
;
110 /* Declarations of locals. */
112 /* Intermediate for insn output. */
113 static int mmix_output_destination_register
;
115 static void mmix_option_override (void);
116 static void mmix_asm_output_source_filename (FILE *, const char *);
117 static void mmix_output_shiftvalue_op_from_str
118 (FILE *, const char *, HOST_WIDEST_INT
);
119 static void mmix_output_shifted_value (FILE *, HOST_WIDEST_INT
);
120 static void mmix_output_condition (FILE *, const_rtx
, int);
121 static HOST_WIDEST_INT
mmix_intval (const_rtx
);
122 static void mmix_output_octa (FILE *, HOST_WIDEST_INT
, int);
123 static bool mmix_assemble_integer (rtx
, unsigned int, int);
124 static struct machine_function
*mmix_init_machine_status (void);
125 static void mmix_encode_section_info (tree
, rtx
, int);
126 static const char *mmix_strip_name_encoding (const char *);
127 static void mmix_emit_sp_add (HOST_WIDE_INT offset
);
128 static void mmix_target_asm_function_prologue (FILE *, HOST_WIDE_INT
);
129 static void mmix_target_asm_function_end_prologue (FILE *);
130 static void mmix_target_asm_function_epilogue (FILE *, HOST_WIDE_INT
);
131 static reg_class_t
mmix_preferred_reload_class (rtx
, reg_class_t
);
132 static reg_class_t
mmix_preferred_output_reload_class (rtx
, reg_class_t
);
133 static bool mmix_legitimate_address_p (enum machine_mode
, rtx
, bool);
134 static bool mmix_legitimate_constant_p (enum machine_mode
, rtx
);
135 static void mmix_reorg (void);
136 static void mmix_asm_output_mi_thunk
137 (FILE *, tree
, HOST_WIDE_INT
, HOST_WIDE_INT
, tree
);
138 static void mmix_setup_incoming_varargs
139 (cumulative_args_t
, enum machine_mode
, tree
, int *, int);
140 static void mmix_file_start (void);
141 static void mmix_file_end (void);
142 static bool mmix_rtx_costs (rtx
, int, int, int, int *, bool);
143 static int mmix_register_move_cost (enum machine_mode
,
144 reg_class_t
, reg_class_t
);
145 static rtx
mmix_struct_value_rtx (tree
, int);
146 static enum machine_mode
mmix_promote_function_mode (const_tree
,
148 int *, const_tree
, int);
149 static void mmix_function_arg_advance (cumulative_args_t
, enum machine_mode
,
151 static rtx
mmix_function_arg_1 (const cumulative_args_t
, enum machine_mode
,
152 const_tree
, bool, bool);
153 static rtx
mmix_function_incoming_arg (cumulative_args_t
, enum machine_mode
,
155 static rtx
mmix_function_arg (cumulative_args_t
, enum machine_mode
,
157 static rtx
mmix_function_value (const_tree
, const_tree
, bool);
158 static rtx
mmix_libcall_value (enum machine_mode
, const_rtx
);
159 static bool mmix_function_value_regno_p (const unsigned int);
160 static bool mmix_pass_by_reference (cumulative_args_t
,
161 enum machine_mode
, const_tree
, bool);
162 static bool mmix_frame_pointer_required (void);
163 static void mmix_asm_trampoline_template (FILE *);
164 static void mmix_trampoline_init (rtx
, tree
, rtx
);
165 static void mmix_print_operand (FILE *, rtx
, int);
166 static void mmix_print_operand_address (FILE *, rtx
);
167 static bool mmix_print_operand_punct_valid_p (unsigned char);
168 static void mmix_conditional_register_usage (void);
170 /* Target structure macros. Listed by node. See `Using and Porting GCC'
171 for a general description. */
173 /* Node: Function Entry */
175 #undef TARGET_ASM_BYTE_OP
176 #define TARGET_ASM_BYTE_OP NULL
177 #undef TARGET_ASM_ALIGNED_HI_OP
178 #define TARGET_ASM_ALIGNED_HI_OP NULL
179 #undef TARGET_ASM_ALIGNED_SI_OP
180 #define TARGET_ASM_ALIGNED_SI_OP NULL
181 #undef TARGET_ASM_ALIGNED_DI_OP
182 #define TARGET_ASM_ALIGNED_DI_OP NULL
183 #undef TARGET_ASM_INTEGER
184 #define TARGET_ASM_INTEGER mmix_assemble_integer
186 #undef TARGET_ASM_FUNCTION_PROLOGUE
187 #define TARGET_ASM_FUNCTION_PROLOGUE mmix_target_asm_function_prologue
189 #undef TARGET_ASM_FUNCTION_END_PROLOGUE
190 #define TARGET_ASM_FUNCTION_END_PROLOGUE mmix_target_asm_function_end_prologue
192 #undef TARGET_ASM_FUNCTION_EPILOGUE
193 #define TARGET_ASM_FUNCTION_EPILOGUE mmix_target_asm_function_epilogue
195 #undef TARGET_PRINT_OPERAND
196 #define TARGET_PRINT_OPERAND mmix_print_operand
197 #undef TARGET_PRINT_OPERAND_ADDRESS
198 #define TARGET_PRINT_OPERAND_ADDRESS mmix_print_operand_address
199 #undef TARGET_PRINT_OPERAND_PUNCT_VALID_P
200 #define TARGET_PRINT_OPERAND_PUNCT_VALID_P mmix_print_operand_punct_valid_p
202 #undef TARGET_ENCODE_SECTION_INFO
203 #define TARGET_ENCODE_SECTION_INFO mmix_encode_section_info
204 #undef TARGET_STRIP_NAME_ENCODING
205 #define TARGET_STRIP_NAME_ENCODING mmix_strip_name_encoding
207 #undef TARGET_ASM_OUTPUT_MI_THUNK
208 #define TARGET_ASM_OUTPUT_MI_THUNK mmix_asm_output_mi_thunk
209 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
210 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall
211 #undef TARGET_ASM_FILE_START
212 #define TARGET_ASM_FILE_START mmix_file_start
213 #undef TARGET_ASM_FILE_START_FILE_DIRECTIVE
214 #define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
215 #undef TARGET_ASM_FILE_END
216 #define TARGET_ASM_FILE_END mmix_file_end
217 #undef TARGET_ASM_OUTPUT_SOURCE_FILENAME
218 #define TARGET_ASM_OUTPUT_SOURCE_FILENAME mmix_asm_output_source_filename
220 #undef TARGET_CONDITIONAL_REGISTER_USAGE
221 #define TARGET_CONDITIONAL_REGISTER_USAGE mmix_conditional_register_usage
223 #undef TARGET_RTX_COSTS
224 #define TARGET_RTX_COSTS mmix_rtx_costs
225 #undef TARGET_ADDRESS_COST
226 #define TARGET_ADDRESS_COST hook_int_rtx_mode_as_bool_0
228 #undef TARGET_REGISTER_MOVE_COST
229 #define TARGET_REGISTER_MOVE_COST mmix_register_move_cost
231 #undef TARGET_MACHINE_DEPENDENT_REORG
232 #define TARGET_MACHINE_DEPENDENT_REORG mmix_reorg
234 #undef TARGET_PROMOTE_FUNCTION_MODE
235 #define TARGET_PROMOTE_FUNCTION_MODE mmix_promote_function_mode
237 #undef TARGET_FUNCTION_VALUE
238 #define TARGET_FUNCTION_VALUE mmix_function_value
239 #undef TARGET_LIBCALL_VALUE
240 #define TARGET_LIBCALL_VALUE mmix_libcall_value
241 #undef TARGET_FUNCTION_VALUE_REGNO_P
242 #define TARGET_FUNCTION_VALUE_REGNO_P mmix_function_value_regno_p
244 #undef TARGET_FUNCTION_ARG
245 #define TARGET_FUNCTION_ARG mmix_function_arg
246 #undef TARGET_FUNCTION_INCOMING_ARG
247 #define TARGET_FUNCTION_INCOMING_ARG mmix_function_incoming_arg
248 #undef TARGET_FUNCTION_ARG_ADVANCE
249 #define TARGET_FUNCTION_ARG_ADVANCE mmix_function_arg_advance
250 #undef TARGET_STRUCT_VALUE_RTX
251 #define TARGET_STRUCT_VALUE_RTX mmix_struct_value_rtx
252 #undef TARGET_SETUP_INCOMING_VARARGS
253 #define TARGET_SETUP_INCOMING_VARARGS mmix_setup_incoming_varargs
254 #undef TARGET_PASS_BY_REFERENCE
255 #define TARGET_PASS_BY_REFERENCE mmix_pass_by_reference
256 #undef TARGET_CALLEE_COPIES
257 #define TARGET_CALLEE_COPIES hook_bool_CUMULATIVE_ARGS_mode_tree_bool_true
259 #undef TARGET_PREFERRED_RELOAD_CLASS
260 #define TARGET_PREFERRED_RELOAD_CLASS mmix_preferred_reload_class
261 #undef TARGET_PREFERRED_OUTPUT_RELOAD_CLASS
262 #define TARGET_PREFERRED_OUTPUT_RELOAD_CLASS mmix_preferred_output_reload_class
264 #undef TARGET_LEGITIMATE_ADDRESS_P
265 #define TARGET_LEGITIMATE_ADDRESS_P mmix_legitimate_address_p
266 #undef TARGET_LEGITIMATE_CONSTANT_P
267 #define TARGET_LEGITIMATE_CONSTANT_P mmix_legitimate_constant_p
269 #undef TARGET_FRAME_POINTER_REQUIRED
270 #define TARGET_FRAME_POINTER_REQUIRED mmix_frame_pointer_required
272 #undef TARGET_ASM_TRAMPOLINE_TEMPLATE
273 #define TARGET_ASM_TRAMPOLINE_TEMPLATE mmix_asm_trampoline_template
274 #undef TARGET_TRAMPOLINE_INIT
275 #define TARGET_TRAMPOLINE_INIT mmix_trampoline_init
277 #undef TARGET_OPTION_OVERRIDE
278 #define TARGET_OPTION_OVERRIDE mmix_option_override
280 struct gcc_target targetm
= TARGET_INITIALIZER
;
282 /* Functions that are expansions for target macros.
283 See Target Macros in `Using and Porting GCC'. */
285 /* TARGET_OPTION_OVERRIDE. */
288 mmix_option_override (void)
290 /* Should we err or should we warn? Hmm. At least we must neutralize
291 it. For example the wrong kind of case-tables will be generated with
292 PIC; we use absolute address items for mmixal compatibility. FIXME:
293 They could be relative if we just elide them to after all pertinent
297 warning (0, "-f%s not supported: ignored", (flag_pic
> 1) ? "PIC" : "pic");
302 /* INIT_EXPANDERS. */
305 mmix_init_expanders (void)
307 init_machine_status
= mmix_init_machine_status
;
310 /* Set the per-function data. */
312 static struct machine_function
*
313 mmix_init_machine_status (void)
315 return ggc_alloc_cleared_machine_function ();
319 We have trouble getting the address of stuff that is located at other
320 than 32-bit alignments (GETA requirements), so try to give everything
321 at least 32-bit alignment. */
324 mmix_data_alignment (tree type ATTRIBUTE_UNUSED
, int basic_align
)
326 if (basic_align
< 32)
332 /* CONSTANT_ALIGNMENT. */
335 mmix_constant_alignment (tree constant ATTRIBUTE_UNUSED
, int basic_align
)
337 if (basic_align
< 32)
343 /* LOCAL_ALIGNMENT. */
346 mmix_local_alignment (tree type ATTRIBUTE_UNUSED
, unsigned basic_align
)
348 if (basic_align
< 32)
354 /* TARGET_CONDITIONAL_REGISTER_USAGE. */
357 mmix_conditional_register_usage (void)
363 static const int gnu_abi_reg_alloc_order
[]
364 = MMIX_GNU_ABI_REG_ALLOC_ORDER
;
366 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
367 reg_alloc_order
[i
] = gnu_abi_reg_alloc_order
[i
];
369 /* Change the default from the mmixware ABI. For the GNU ABI,
370 $15..$30 are call-saved just as $0..$14. There must be one
371 call-clobbered local register for the "hole" that holds the
372 number of saved local registers saved by PUSHJ/PUSHGO during the
373 function call, receiving the return value at return. So best is
374 to use the highest, $31. It's already marked call-clobbered for
376 for (i
= 15; i
<= 30; i
++)
377 call_used_regs
[i
] = 0;
379 /* "Unfix" the parameter registers. */
380 for (i
= MMIX_RESERVED_GNU_ARG_0_REGNUM
;
381 i
< MMIX_RESERVED_GNU_ARG_0_REGNUM
+ MMIX_MAX_ARGS_IN_REGS
;
386 /* Step over the ":" in special register names. */
387 if (! TARGET_TOPLEVEL_SYMBOLS
)
388 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
389 if (reg_names
[i
][0] == ':')
393 /* INCOMING_REGNO and OUTGOING_REGNO worker function.
394 Those two macros must only be applied to function argument
395 registers. FIXME: for their current use in gcc, it'd be better
396 with an explicit specific additional FUNCTION_INCOMING_ARG_REGNO_P
397 a'la TARGET_FUNCTION_ARG / TARGET_FUNCTION_INCOMING_ARG instead of
398 forcing the target to commit to a fixed mapping and for any
399 unspecified register use. */
402 mmix_opposite_regno (int regno
, int incoming
)
404 if (!mmix_function_arg_regno_p (regno
, incoming
))
409 ? MMIX_FIRST_INCOMING_ARG_REGNUM
- MMIX_FIRST_ARG_REGNUM
410 : MMIX_FIRST_ARG_REGNUM
- MMIX_FIRST_INCOMING_ARG_REGNUM
);
414 All registers that are part of the register stack and that will be
418 mmix_local_regno (int regno
)
420 return regno
<= MMIX_LAST_STACK_REGISTER_REGNUM
&& !call_used_regs
[regno
];
423 /* TARGET_PREFERRED_RELOAD_CLASS.
424 We need to extend the reload class of REMAINDER_REG and HIMULT_REG. */
427 mmix_preferred_reload_class (rtx x
, reg_class_t rclass
)
429 /* FIXME: Revisit. */
430 return GET_CODE (x
) == MOD
&& GET_MODE (x
) == DImode
431 ? REMAINDER_REG
: rclass
;
434 /* TARGET_PREFERRED_OUTPUT_RELOAD_CLASS.
435 We need to extend the reload class of REMAINDER_REG and HIMULT_REG. */
438 mmix_preferred_output_reload_class (rtx x
, reg_class_t rclass
)
440 /* FIXME: Revisit. */
441 return GET_CODE (x
) == MOD
&& GET_MODE (x
) == DImode
442 ? REMAINDER_REG
: rclass
;
445 /* SECONDARY_RELOAD_CLASS.
446 We need to reload regs of REMAINDER_REG and HIMULT_REG elsewhere. */
449 mmix_secondary_reload_class (enum reg_class rclass
,
450 enum machine_mode mode ATTRIBUTE_UNUSED
,
451 rtx x ATTRIBUTE_UNUSED
,
452 int in_p ATTRIBUTE_UNUSED
)
454 if (rclass
== REMAINDER_REG
455 || rclass
== HIMULT_REG
456 || rclass
== SYSTEM_REGS
)
462 /* CONST_OK_FOR_LETTER_P. */
465 mmix_const_ok_for_letter_p (HOST_WIDE_INT value
, int c
)
468 (c
== 'I' ? value
>= 0 && value
<= 255
469 : c
== 'J' ? value
>= 0 && value
<= 65535
470 : c
== 'K' ? value
<= 0 && value
>= -255
471 : c
== 'L' ? mmix_shiftable_wyde_value (value
)
472 : c
== 'M' ? value
== 0
473 : c
== 'N' ? mmix_shiftable_wyde_value (~value
)
474 : c
== 'O' ? (value
== 3 || value
== 5 || value
== 9
479 /* CONST_DOUBLE_OK_FOR_LETTER_P. */
482 mmix_const_double_ok_for_letter_p (rtx value
, int c
)
485 (c
== 'G' ? value
== CONST0_RTX (GET_MODE (value
))
490 We need this since our constants are not always expressible as
491 CONST_INT:s, but rather often as CONST_DOUBLE:s. */
494 mmix_extra_constraint (rtx x
, int c
, int strict
)
496 HOST_WIDEST_INT value
;
498 /* When checking for an address, we need to handle strict vs. non-strict
499 register checks. Don't use address_operand, but instead its
500 equivalent (its callee, which it is just a wrapper for),
501 memory_operand_p and the strict-equivalent strict_memory_address_p. */
505 ? strict_memory_address_p (Pmode
, x
)
506 : memory_address_p (Pmode
, x
);
508 /* R asks whether x is to be loaded with GETA or something else. Right
509 now, only a SYMBOL_REF and LABEL_REF can fit for
510 TARGET_BASE_ADDRESSES.
512 Only constant symbolic addresses apply. With TARGET_BASE_ADDRESSES,
513 we just allow straight LABEL_REF or SYMBOL_REFs with SYMBOL_REF_FLAG
514 set right now; only function addresses and code labels. If we change
515 to let SYMBOL_REF_FLAG be set on other symbols, we have to check
516 inside CONST expressions. When TARGET_BASE_ADDRESSES is not in
517 effect, a "raw" constant check together with mmix_constant_address_p
518 is all that's needed; we want all constant addresses to be loaded
522 GET_CODE (x
) != CONST_INT
&& GET_CODE (x
) != CONST_DOUBLE
523 && mmix_constant_address_p (x
)
524 && (! TARGET_BASE_ADDRESSES
525 || (GET_CODE (x
) == LABEL_REF
526 || (GET_CODE (x
) == SYMBOL_REF
&& SYMBOL_REF_FLAG (x
))));
528 if (GET_CODE (x
) != CONST_DOUBLE
|| GET_MODE (x
) != VOIDmode
)
531 value
= mmix_intval (x
);
533 /* We used to map Q->J, R->K, S->L, T->N, U->O, but we don't have to any
534 more ('U' taken for address_operand, 'R' similarly). Some letters map
535 outside of CONST_INT, though; we still use 'S' and 'T'. */
537 return mmix_shiftable_wyde_value (value
);
539 return mmix_shiftable_wyde_value (~value
);
543 /* DYNAMIC_CHAIN_ADDRESS. */
546 mmix_dynamic_chain_address (rtx frame
)
548 /* FIXME: the frame-pointer is stored at offset -8 from the current
549 frame-pointer. Unfortunately, the caller assumes that a
550 frame-pointer is present for *all* previous frames. There should be
551 a way to say that that cannot be done, like for RETURN_ADDR_RTX. */
552 return plus_constant (Pmode
, frame
, -8);
555 /* STARTING_FRAME_OFFSET. */
558 mmix_starting_frame_offset (void)
560 /* The old frame pointer is in the slot below the new one, so
561 FIRST_PARM_OFFSET does not need to depend on whether the
562 frame-pointer is needed or not. We have to adjust for the register
563 stack pointer being located below the saved frame pointer.
564 Similarly, we store the return address on the stack too, for
565 exception handling, and always if we save the register stack pointer. */
568 + (MMIX_CFUN_HAS_LANDING_PAD
569 ? -16 : (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
? -8 : 0)));
572 /* RETURN_ADDR_RTX. */
575 mmix_return_addr_rtx (int count
, rtx frame ATTRIBUTE_UNUSED
)
578 ? (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
579 /* FIXME: Set frame_alias_set on the following. (Why?)
580 See mmix_initial_elimination_offset for the reason we can't use
581 get_hard_reg_initial_val for both. Always using a stack slot
582 and not a register would be suboptimal. */
583 ? validize_mem (gen_rtx_MEM (Pmode
,
584 plus_constant (Pmode
,
585 frame_pointer_rtx
, -16)))
586 : get_hard_reg_initial_val (Pmode
, MMIX_INCOMING_RETURN_ADDRESS_REGNUM
))
590 /* SETUP_FRAME_ADDRESSES. */
593 mmix_setup_frame_addresses (void)
595 /* Nothing needed at the moment. */
598 /* The difference between the (imaginary) frame pointer and the stack
599 pointer. Used to eliminate the frame pointer. */
602 mmix_initial_elimination_offset (int fromreg
, int toreg
)
606 = (get_frame_size () + crtl
->outgoing_args_size
+ 7) & ~7;
608 /* There is no actual offset between these two virtual values, but for
609 the frame-pointer, we have the old one in the stack position below
610 it, so the offset for the frame-pointer to the stack-pointer is one
612 if (fromreg
== MMIX_ARG_POINTER_REGNUM
613 && toreg
== MMIX_FRAME_POINTER_REGNUM
)
616 /* The difference is the size of local variables plus the size of
617 outgoing function arguments that would normally be passed as
618 registers but must be passed on stack because we're out of
619 function-argument registers. Only global saved registers are
620 counted; the others go on the register stack.
622 The frame-pointer is counted too if it is what is eliminated, as we
623 need to balance the offset for it from STARTING_FRAME_OFFSET.
625 Also add in the slot for the register stack pointer we save if we
628 Unfortunately, we can't access $0..$14, from unwinder code easily, so
629 store the return address in a frame slot too. FIXME: Only for
630 non-leaf functions. FIXME: Always with a landing pad, because it's
631 hard to know whether we need the other at the time we know we need
632 the offset for one (and have to state it). It's a kludge until we
633 can express the register stack in the EH frame info.
635 We have to do alignment here; get_frame_size will not return a
636 multiple of STACK_BOUNDARY. FIXME: Add note in manual. */
638 for (regno
= MMIX_FIRST_GLOBAL_REGNUM
;
641 if ((df_regs_ever_live_p (regno
) && ! call_used_regs
[regno
])
642 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
646 + (MMIX_CFUN_HAS_LANDING_PAD
647 ? 16 : (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
? 8 : 0))
648 + (fromreg
== MMIX_ARG_POINTER_REGNUM
? 0 : 8);
652 mmix_function_arg_advance (cumulative_args_t argsp_v
, enum machine_mode mode
,
653 const_tree type
, bool named ATTRIBUTE_UNUSED
)
655 CUMULATIVE_ARGS
*argsp
= get_cumulative_args (argsp_v
);
656 int arg_size
= MMIX_FUNCTION_ARG_SIZE (mode
, type
);
658 argsp
->regs
= ((targetm
.calls
.must_pass_in_stack (mode
, type
)
662 ? (MMIX_MAX_ARGS_IN_REGS
) + 1
663 : argsp
->regs
+ (7 + arg_size
) / 8);
666 /* Helper function for mmix_function_arg and mmix_function_incoming_arg. */
669 mmix_function_arg_1 (const cumulative_args_t argsp_v
,
670 enum machine_mode mode
,
672 bool named ATTRIBUTE_UNUSED
,
675 CUMULATIVE_ARGS
*argsp
= get_cumulative_args (argsp_v
);
677 /* Last-argument marker. */
678 if (type
== void_type_node
)
679 return (argsp
->regs
< MMIX_MAX_ARGS_IN_REGS
)
682 ? MMIX_FIRST_INCOMING_ARG_REGNUM
683 : MMIX_FIRST_ARG_REGNUM
) + argsp
->regs
)
686 return (argsp
->regs
< MMIX_MAX_ARGS_IN_REGS
687 && !targetm
.calls
.must_pass_in_stack (mode
, type
)
688 && (GET_MODE_BITSIZE (mode
) <= 64
693 ? MMIX_FIRST_INCOMING_ARG_REGNUM
694 : MMIX_FIRST_ARG_REGNUM
)
699 /* Return an rtx for a function argument to go in a register, and 0 for
700 one that must go on stack. */
703 mmix_function_arg (cumulative_args_t argsp
,
704 enum machine_mode mode
,
708 return mmix_function_arg_1 (argsp
, mode
, type
, named
, false);
712 mmix_function_incoming_arg (cumulative_args_t argsp
,
713 enum machine_mode mode
,
717 return mmix_function_arg_1 (argsp
, mode
, type
, named
, true);
720 /* Returns nonzero for everything that goes by reference, 0 for
721 everything that goes by value. */
724 mmix_pass_by_reference (cumulative_args_t argsp_v
, enum machine_mode mode
,
725 const_tree type
, bool named ATTRIBUTE_UNUSED
)
727 CUMULATIVE_ARGS
*argsp
= get_cumulative_args (argsp_v
);
729 /* FIXME: Check: I'm not sure the must_pass_in_stack check is
731 if (targetm
.calls
.must_pass_in_stack (mode
, type
))
734 if (MMIX_FUNCTION_ARG_SIZE (mode
, type
) > 8
736 && (!argsp
|| !argsp
->lib
))
742 /* Return nonzero if regno is a register number where a parameter is
743 passed, and 0 otherwise. */
746 mmix_function_arg_regno_p (int regno
, int incoming
)
749 = incoming
? MMIX_FIRST_INCOMING_ARG_REGNUM
: MMIX_FIRST_ARG_REGNUM
;
751 return regno
>= first_arg_regnum
752 && regno
< first_arg_regnum
+ MMIX_MAX_ARGS_IN_REGS
;
755 /* Implements TARGET_FUNCTION_VALUE. */
758 mmix_function_value (const_tree valtype
,
759 const_tree func ATTRIBUTE_UNUSED
,
762 enum machine_mode mode
= TYPE_MODE (valtype
);
763 enum machine_mode cmode
;
764 int first_val_regnum
= MMIX_OUTGOING_RETURN_VALUE_REGNUM
;
765 rtx vec
[MMIX_MAX_REGS_FOR_VALUE
];
770 return gen_rtx_REG (mode
, MMIX_RETURN_VALUE_REGNUM
);
772 /* Return values that fit in a register need no special handling.
773 There's no register hole when parameters are passed in global
776 || GET_MODE_BITSIZE (mode
) <= BITS_PER_WORD
)
778 gen_rtx_REG (mode
, MMIX_OUTGOING_RETURN_VALUE_REGNUM
);
780 if (COMPLEX_MODE_P (mode
))
781 /* A complex type, made up of components. */
782 cmode
= TYPE_MODE (TREE_TYPE (valtype
));
785 /* Of the other larger-than-register modes, we only support
786 scalar mode TImode. (At least, that's the only one that's
787 been rudimentally tested.) Make sure we're alerted for
790 sorry ("support for mode %qs", GET_MODE_NAME (mode
));
792 /* In any case, we will fill registers to the natural size. */
796 nregs
= ((GET_MODE_BITSIZE (mode
) + BITS_PER_WORD
- 1) / BITS_PER_WORD
);
798 /* We need to take care of the effect of the register hole on return
799 values of large sizes; the last register will appear as the first
800 register, with the rest shifted. (For complex modes, this is just
801 swapped registers.) */
803 if (nregs
> MMIX_MAX_REGS_FOR_VALUE
)
804 internal_error ("too large function value type, needs %d registers,\
805 have only %d registers for this", nregs
, MMIX_MAX_REGS_FOR_VALUE
);
807 /* FIXME: Maybe we should handle structure values like this too
808 (adjusted for BLKmode), perhaps for both ABI:s. */
809 for (i
= 0; i
< nregs
- 1; i
++)
811 = gen_rtx_EXPR_LIST (VOIDmode
,
812 gen_rtx_REG (cmode
, first_val_regnum
+ i
),
813 GEN_INT ((i
+ 1) * BITS_PER_UNIT
));
816 = gen_rtx_EXPR_LIST (VOIDmode
,
817 gen_rtx_REG (cmode
, first_val_regnum
+ nregs
- 1),
820 return gen_rtx_PARALLEL (VOIDmode
, gen_rtvec_v (nregs
, vec
));
823 /* Implements TARGET_LIBCALL_VALUE. */
826 mmix_libcall_value (enum machine_mode mode
,
827 const_rtx fun ATTRIBUTE_UNUSED
)
829 return gen_rtx_REG (mode
, MMIX_RETURN_VALUE_REGNUM
);
832 /* Implements TARGET_FUNCTION_VALUE_REGNO_P. */
835 mmix_function_value_regno_p (const unsigned int regno
)
837 return regno
== MMIX_RETURN_VALUE_REGNUM
;
840 /* EH_RETURN_DATA_REGNO. */
843 mmix_eh_return_data_regno (int n
)
846 return MMIX_EH_RETURN_DATA_REGNO_START
+ n
;
848 return INVALID_REGNUM
;
851 /* EH_RETURN_STACKADJ_RTX. */
854 mmix_eh_return_stackadj_rtx (void)
856 return gen_rtx_REG (Pmode
, MMIX_EH_RETURN_STACKADJ_REGNUM
);
859 /* EH_RETURN_HANDLER_RTX. */
862 mmix_eh_return_handler_rtx (void)
864 return gen_rtx_REG (Pmode
, MMIX_INCOMING_RETURN_ADDRESS_REGNUM
);
867 /* ASM_PREFERRED_EH_DATA_FORMAT. */
870 mmix_asm_preferred_eh_data_format (int code ATTRIBUTE_UNUSED
,
871 int global ATTRIBUTE_UNUSED
)
873 /* This is the default (was at 2001-07-20). Revisit when needed. */
874 return DW_EH_PE_absptr
;
877 /* Make a note that we've seen the beginning of the prologue. This
878 matters to whether we'll translate register numbers as calculated by
882 mmix_target_asm_function_prologue (FILE *stream ATTRIBUTE_UNUSED
,
883 HOST_WIDE_INT framesize ATTRIBUTE_UNUSED
)
885 cfun
->machine
->in_prologue
= 1;
888 /* Make a note that we've seen the end of the prologue. */
891 mmix_target_asm_function_end_prologue (FILE *stream ATTRIBUTE_UNUSED
)
893 cfun
->machine
->in_prologue
= 0;
896 /* Implement TARGET_MACHINE_DEPENDENT_REORG. No actual rearrangements
897 done here; just virtually by calculating the highest saved stack
898 register number used to modify the register numbers at output time. */
905 /* We put the number of the highest saved register-file register in a
906 location convenient for the call-patterns to output. Note that we
907 don't tell dwarf2 about these registers, since it can't restore them
909 for (regno
= MMIX_LAST_STACK_REGISTER_REGNUM
;
912 if ((df_regs_ever_live_p (regno
) && !call_used_regs
[regno
])
913 || (regno
== MMIX_FRAME_POINTER_REGNUM
&& frame_pointer_needed
))
916 /* Regardless of whether they're saved (they might be just read), we
917 mustn't include registers that carry parameters. We could scan the
918 insns to see whether they're actually used (and indeed do other less
919 trivial register usage analysis and transformations), but it seems
920 wasteful to optimize for unused parameter registers. As of
921 2002-04-30, df_regs_ever_live_p (n) seems to be set for only-reads too, but
922 that might change. */
923 if (!TARGET_ABI_GNU
&& regno
< crtl
->args
.info
.regs
- 1)
925 regno
= crtl
->args
.info
.regs
- 1;
927 /* We don't want to let this cause us to go over the limit and make
928 incoming parameter registers be misnumbered and treating the last
929 parameter register and incoming return value register call-saved.
930 Stop things at the unmodified scheme. */
931 if (regno
> MMIX_RETURN_VALUE_REGNUM
- 1)
932 regno
= MMIX_RETURN_VALUE_REGNUM
- 1;
935 cfun
->machine
->highest_saved_stack_register
= regno
;
938 /* TARGET_ASM_FUNCTION_EPILOGUE. */
941 mmix_target_asm_function_epilogue (FILE *stream
,
942 HOST_WIDE_INT locals_size ATTRIBUTE_UNUSED
)
944 /* Emit an \n for readability of the generated assembly. */
945 fputc ('\n', stream
);
948 /* TARGET_ASM_OUTPUT_MI_THUNK. */
951 mmix_asm_output_mi_thunk (FILE *stream
,
952 tree fndecl ATTRIBUTE_UNUSED
,
954 HOST_WIDE_INT vcall_offset ATTRIBUTE_UNUSED
,
957 /* If you define TARGET_STRUCT_VALUE_RTX that returns 0 (i.e. pass
958 location of structure to return as invisible first argument), you
959 need to tweak this code too. */
960 const char *regname
= reg_names
[MMIX_FIRST_INCOMING_ARG_REGNUM
];
962 if (delta
>= 0 && delta
< 65536)
963 fprintf (stream
, "\tINCL %s,%d\n", regname
, (int)delta
);
964 else if (delta
< 0 && delta
>= -255)
965 fprintf (stream
, "\tSUBU %s,%s,%d\n", regname
, regname
, (int)-delta
);
968 mmix_output_register_setting (stream
, 255, delta
, 1);
969 fprintf (stream
, "\tADDU %s,%s,$255\n", regname
, regname
);
972 fprintf (stream
, "\tJMP ");
973 assemble_name (stream
, XSTR (XEXP (DECL_RTL (func
), 0), 0));
974 fprintf (stream
, "\n");
977 /* FUNCTION_PROFILER. */
980 mmix_function_profiler (FILE *stream ATTRIBUTE_UNUSED
,
981 int labelno ATTRIBUTE_UNUSED
)
983 sorry ("function_profiler support for MMIX");
986 /* Worker function for TARGET_SETUP_INCOMING_VARARGS. For the moment,
987 let's stick to pushing argument registers on the stack. Later, we
988 can parse all arguments in registers, to improve performance. */
991 mmix_setup_incoming_varargs (cumulative_args_t args_so_farp_v
,
992 enum machine_mode mode
,
995 int second_time ATTRIBUTE_UNUSED
)
997 CUMULATIVE_ARGS
*args_so_farp
= get_cumulative_args (args_so_farp_v
);
999 /* The last named variable has been handled, but
1000 args_so_farp has not been advanced for it. */
1001 if (args_so_farp
->regs
+ 1 < MMIX_MAX_ARGS_IN_REGS
)
1002 *pretend_sizep
= (MMIX_MAX_ARGS_IN_REGS
- (args_so_farp
->regs
+ 1)) * 8;
1004 /* We assume that one argument takes up one register here. That should
1005 be true until we start messing with multi-reg parameters. */
1006 if ((7 + (MMIX_FUNCTION_ARG_SIZE (mode
, vartype
))) / 8 != 1)
1007 internal_error ("MMIX Internal: Last named vararg would not fit in a register");
1010 /* TARGET_ASM_TRAMPOLINE_TEMPLATE. */
1013 mmix_asm_trampoline_template (FILE *stream
)
1015 /* Read a value into the static-chain register and jump somewhere. The
1016 static chain is stored at offset 16, and the function address is
1017 stored at offset 24. */
1019 fprintf (stream
, "\tGETA $255,1F\n\t");
1020 fprintf (stream
, "LDOU %s,$255,0\n\t", reg_names
[MMIX_STATIC_CHAIN_REGNUM
]);
1021 fprintf (stream
, "LDOU $255,$255,8\n\t");
1022 fprintf (stream
, "GO $255,$255,0\n");
1023 fprintf (stream
, "1H\tOCTA 0\n\t");
1024 fprintf (stream
, "OCTA 0\n");
1027 /* TARGET_TRAMPOLINE_INIT. */
1028 /* Set the static chain and function pointer field in the trampoline.
1029 We also SYNCID here to be sure (doesn't matter in the simulator, but
1030 some day it will). */
1033 mmix_trampoline_init (rtx m_tramp
, tree fndecl
, rtx static_chain
)
1035 rtx fnaddr
= XEXP (DECL_RTL (fndecl
), 0);
1038 emit_block_move (m_tramp
, assemble_trampoline_template (),
1039 GEN_INT (2*UNITS_PER_WORD
), BLOCK_OP_NORMAL
);
1041 mem
= adjust_address (m_tramp
, DImode
, 2*UNITS_PER_WORD
);
1042 emit_move_insn (mem
, static_chain
);
1043 mem
= adjust_address (m_tramp
, DImode
, 3*UNITS_PER_WORD
);
1044 emit_move_insn (mem
, fnaddr
);
1046 mem
= adjust_address (m_tramp
, DImode
, 0);
1047 emit_insn (gen_sync_icache (mem
, GEN_INT (TRAMPOLINE_SIZE
- 1)));
1050 /* We must exclude constant addresses that have an increment that is not a
1051 multiple of four bytes because of restrictions of the GETA
1052 instruction, unless TARGET_BASE_ADDRESSES. */
1055 mmix_constant_address_p (rtx x
)
1057 RTX_CODE code
= GET_CODE (x
);
1059 /* When using "base addresses", anything constant goes. */
1060 int constant_ok
= TARGET_BASE_ADDRESSES
!= 0;
1069 /* FIXME: Don't know how to dissect these. Avoid them for now,
1070 except we know they're constants. */
1074 addend
= INTVAL (x
);
1078 if (GET_MODE (x
) != VOIDmode
)
1079 /* Strange that we got here. FIXME: Check if we do. */
1081 addend
= CONST_DOUBLE_LOW (x
);
1085 /* Note that expressions with arithmetic on forward references don't
1086 work in mmixal. People using gcc assembly code with mmixal might
1087 need to move arrays and such to before the point of use. */
1088 if (GET_CODE (XEXP (x
, 0)) == PLUS
)
1090 rtx x0
= XEXP (XEXP (x
, 0), 0);
1091 rtx x1
= XEXP (XEXP (x
, 0), 1);
1093 if ((GET_CODE (x0
) == SYMBOL_REF
1094 || GET_CODE (x0
) == LABEL_REF
)
1095 && (GET_CODE (x1
) == CONST_INT
1096 || (GET_CODE (x1
) == CONST_DOUBLE
1097 && GET_MODE (x1
) == VOIDmode
)))
1098 addend
= mmix_intval (x1
);
1110 return constant_ok
|| (addend
& 3) == 0;
1113 /* Return 1 if the address is OK, otherwise 0. */
1116 mmix_legitimate_address_p (enum machine_mode mode ATTRIBUTE_UNUSED
,
1118 bool strict_checking
)
1120 #define MMIX_REG_OK(X) \
1122 && (REGNO (X) <= MMIX_LAST_GENERAL_REGISTER \
1123 || (reg_renumber[REGNO (X)] > 0 \
1124 && reg_renumber[REGNO (X)] <= MMIX_LAST_GENERAL_REGISTER))) \
1125 || (!strict_checking \
1126 && (REGNO (X) <= MMIX_LAST_GENERAL_REGISTER \
1127 || REGNO (X) >= FIRST_PSEUDO_REGISTER \
1128 || REGNO (X) == ARG_POINTER_REGNUM)))
1132 (mem (plus reg reg))
1133 (mem (plus reg 0..255)).
1134 unless TARGET_BASE_ADDRESSES, in which case we accept all
1135 (mem constant_address) too. */
1139 if (REG_P (x
) && MMIX_REG_OK (x
))
1142 if (GET_CODE(x
) == PLUS
)
1144 rtx x1
= XEXP (x
, 0);
1145 rtx x2
= XEXP (x
, 1);
1147 /* Try swapping the order. FIXME: Do we need this? */
1155 /* (mem (plus (reg?) (?))) */
1156 if (!REG_P (x1
) || !MMIX_REG_OK (x1
))
1157 return TARGET_BASE_ADDRESSES
&& mmix_constant_address_p (x
);
1159 /* (mem (plus (reg) (reg?))) */
1160 if (REG_P (x2
) && MMIX_REG_OK (x2
))
1163 /* (mem (plus (reg) (0..255?))) */
1164 if (GET_CODE (x2
) == CONST_INT
1165 && CONST_OK_FOR_LETTER_P (INTVAL (x2
), 'I'))
1171 return TARGET_BASE_ADDRESSES
&& mmix_constant_address_p (x
);
1174 /* Implement TARGET_LEGITIMATE_CONSTANT_P. */
1177 mmix_legitimate_constant_p (enum machine_mode mode ATTRIBUTE_UNUSED
, rtx x
)
1179 RTX_CODE code
= GET_CODE (x
);
1181 /* We must allow any number due to the way the cse passes works; if we
1182 do not allow any number here, general_operand will fail, and insns
1183 will fatally fail recognition instead of "softly". */
1184 if (code
== CONST_INT
|| code
== CONST_DOUBLE
)
1187 return CONSTANT_ADDRESS_P (x
);
1190 /* SELECT_CC_MODE. */
1193 mmix_select_cc_mode (RTX_CODE op
, rtx x
, rtx y ATTRIBUTE_UNUSED
)
1195 /* We use CCmode, CC_UNSmode, CC_FPmode, CC_FPEQmode and CC_FUNmode to
1196 output different compare insns. Note that we do not check the
1197 validity of the comparison here. */
1199 if (GET_MODE_CLASS (GET_MODE (x
)) == MODE_FLOAT
)
1201 if (op
== ORDERED
|| op
== UNORDERED
|| op
== UNGE
1202 || op
== UNGT
|| op
== UNLE
|| op
== UNLT
)
1205 if (op
== EQ
|| op
== NE
)
1211 if (op
== GTU
|| op
== LTU
|| op
== GEU
|| op
== LEU
)
1217 /* REVERSIBLE_CC_MODE. */
1220 mmix_reversible_cc_mode (enum machine_mode mode
)
1222 /* That is, all integer and the EQ, NE, ORDERED and UNORDERED float
1224 return mode
!= CC_FPmode
;
1227 /* TARGET_RTX_COSTS. */
1230 mmix_rtx_costs (rtx x ATTRIBUTE_UNUSED
,
1231 int code ATTRIBUTE_UNUSED
,
1232 int outer_code ATTRIBUTE_UNUSED
,
1233 int opno ATTRIBUTE_UNUSED
,
1234 int *total ATTRIBUTE_UNUSED
,
1235 bool speed ATTRIBUTE_UNUSED
)
1237 /* For the time being, this is just a stub and we'll accept the
1238 generic calculations, until we can do measurements, at least.
1239 Say we did not modify any calculated costs. */
1243 /* TARGET_REGISTER_MOVE_COST.
1245 The special registers can only move to and from general regs, and we
1246 need to check that their constraints match, so say 3 for them. */
1249 mmix_register_move_cost (enum machine_mode mode ATTRIBUTE_UNUSED
,
1253 return (from
== GENERAL_REGS
&& from
== to
) ? 2 : 3;
1256 /* Note that we don't have a TEXT_SECTION_ASM_OP, because it has to be a
1257 compile-time constant; it's used in an asm in crtstuff.c, compiled for
1260 /* DATA_SECTION_ASM_OP. */
1263 mmix_data_section_asm_op (void)
1265 return "\t.data ! mmixal:= 8H LOC 9B";
1269 mmix_encode_section_info (tree decl
, rtx rtl
, int first
)
1271 /* Test for an external declaration, and do nothing if it is one. */
1272 if ((TREE_CODE (decl
) == VAR_DECL
1273 && (DECL_EXTERNAL (decl
) || TREE_PUBLIC (decl
)))
1274 || (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_PUBLIC (decl
)))
1276 else if (first
&& DECL_P (decl
))
1278 /* For non-visible declarations, add a "@" prefix, which we skip
1279 when the label is output. If the label does not have this
1280 prefix, a ":" is output if -mtoplevel-symbols.
1282 Note that this does not work for data that is declared extern and
1283 later defined as static. If there's code in between, that code
1284 will refer to the extern declaration, and vice versa. This just
1285 means that when -mtoplevel-symbols is in use, we can just handle
1286 well-behaved ISO-compliant code. */
1288 const char *str
= XSTR (XEXP (rtl
, 0), 0);
1289 int len
= strlen (str
);
1290 char *newstr
= XALLOCAVEC (char, len
+ 2);
1292 strcpy (newstr
+ 1, str
);
1293 XSTR (XEXP (rtl
, 0), 0) = ggc_alloc_string (newstr
, len
+ 1);
1296 /* Set SYMBOL_REF_FLAG for things that we want to access with GETA. We
1297 may need different options to reach for different things with GETA.
1298 For now, functions and things we know or have been told are constant. */
1299 if (TREE_CODE (decl
) == FUNCTION_DECL
1300 || TREE_CONSTANT (decl
)
1301 || (TREE_CODE (decl
) == VAR_DECL
1302 && TREE_READONLY (decl
)
1303 && !TREE_SIDE_EFFECTS (decl
)
1304 && (!DECL_INITIAL (decl
)
1305 || TREE_CONSTANT (DECL_INITIAL (decl
)))))
1306 SYMBOL_REF_FLAG (XEXP (rtl
, 0)) = 1;
1310 mmix_strip_name_encoding (const char *name
)
1312 for (; (*name
== '@' || *name
== '*'); name
++)
1318 /* TARGET_ASM_FILE_START.
1319 We just emit a little comment for the time being. */
1322 mmix_file_start (void)
1324 default_file_start ();
1326 fputs ("! mmixal:= 8H LOC Data_Section\n", asm_out_file
);
1328 /* Make sure each file starts with the text section. */
1329 switch_to_section (text_section
);
1332 /* TARGET_ASM_FILE_END. */
1335 mmix_file_end (void)
1337 /* Make sure each file ends with the data section. */
1338 switch_to_section (data_section
);
1341 /* TARGET_ASM_OUTPUT_SOURCE_FILENAME. */
1344 mmix_asm_output_source_filename (FILE *stream
, const char *name
)
1346 fprintf (stream
, "# 1 ");
1347 OUTPUT_QUOTED_STRING (stream
, name
);
1348 fprintf (stream
, "\n");
1351 /* OUTPUT_QUOTED_STRING. */
1354 mmix_output_quoted_string (FILE *stream
, const char *string
, int length
)
1356 const char * string_end
= string
+ length
;
1357 static const char *const unwanted_chars
= "\"[]\\";
1359 /* Output "any character except newline and double quote character". We
1360 play it safe and avoid all control characters too. We also do not
1361 want [] as characters, should input be passed through m4 with [] as
1362 quotes. Further, we avoid "\", because the GAS port handles it as a
1363 quoting character. */
1364 while (string
< string_end
)
1367 && (unsigned char) *string
< 128
1368 && !ISCNTRL (*string
)
1369 && strchr (unwanted_chars
, *string
) == NULL
)
1371 fputc ('"', stream
);
1373 && (unsigned char) *string
< 128
1374 && !ISCNTRL (*string
)
1375 && strchr (unwanted_chars
, *string
) == NULL
1376 && string
< string_end
)
1378 fputc (*string
, stream
);
1381 fputc ('"', stream
);
1382 if (string
< string_end
)
1383 fprintf (stream
, ",");
1385 if (string
< string_end
)
1387 fprintf (stream
, "#%x", *string
& 255);
1389 if (string
< string_end
)
1390 fprintf (stream
, ",");
1395 /* Target hook for assembling integer objects. Use mmix_print_operand
1396 for WYDE and TETRA. Use mmix_output_octa to output 8-byte
1400 mmix_assemble_integer (rtx x
, unsigned int size
, int aligned_p
)
1405 /* We handle a limited number of types of operands in here. But
1406 that's ok, because we can punt to generic functions. We then
1407 pretend that aligned data isn't needed, so the usual .<pseudo>
1408 syntax is used (which works for aligned data too). We actually
1409 *must* do that, since we say we don't have simple aligned
1410 pseudos, causing this function to be called. We just try and
1411 keep as much compatibility as possible with mmixal syntax for
1412 normal cases (i.e. without GNU extensions and C only). */
1414 if (GET_CODE (x
) != CONST_INT
)
1419 fputs ("\tBYTE\t", asm_out_file
);
1420 mmix_print_operand (asm_out_file
, x
, 'B');
1421 fputc ('\n', asm_out_file
);
1425 if (GET_CODE (x
) != CONST_INT
)
1430 fputs ("\tWYDE\t", asm_out_file
);
1431 mmix_print_operand (asm_out_file
, x
, 'W');
1432 fputc ('\n', asm_out_file
);
1436 if (GET_CODE (x
) != CONST_INT
)
1441 fputs ("\tTETRA\t", asm_out_file
);
1442 mmix_print_operand (asm_out_file
, x
, 'L');
1443 fputc ('\n', asm_out_file
);
1447 /* We don't get here anymore for CONST_DOUBLE, because DImode
1448 isn't expressed as CONST_DOUBLE, and DFmode is handled
1450 gcc_assert (GET_CODE (x
) != CONST_DOUBLE
);
1451 assemble_integer_with_op ("\tOCTA\t", x
);
1454 return default_assemble_integer (x
, size
, aligned_p
);
1457 /* ASM_OUTPUT_ASCII. */
1460 mmix_asm_output_ascii (FILE *stream
, const char *string
, int length
)
1464 int chunk_size
= length
> 60 ? 60 : length
;
1465 fprintf (stream
, "\tBYTE ");
1466 mmix_output_quoted_string (stream
, string
, chunk_size
);
1467 string
+= chunk_size
;
1468 length
-= chunk_size
;
1469 fprintf (stream
, "\n");
1473 /* ASM_OUTPUT_ALIGNED_COMMON. */
1476 mmix_asm_output_aligned_common (FILE *stream
,
1481 /* This is mostly the elfos.h one. There doesn't seem to be a way to
1482 express this in a mmixal-compatible way. */
1483 fprintf (stream
, "\t.comm\t");
1484 assemble_name (stream
, name
);
1485 fprintf (stream
, ",%u,%u ! mmixal-incompatible COMMON\n",
1486 size
, align
/ BITS_PER_UNIT
);
1489 /* ASM_OUTPUT_ALIGNED_LOCAL. */
1492 mmix_asm_output_aligned_local (FILE *stream
,
1497 switch_to_section (data_section
);
1499 ASM_OUTPUT_ALIGN (stream
, exact_log2 (align
/BITS_PER_UNIT
));
1500 assemble_name (stream
, name
);
1501 fprintf (stream
, "\tLOC @+%d\n", size
);
1504 /* ASM_OUTPUT_LABEL. */
1507 mmix_asm_output_label (FILE *stream
, const char *name
)
1509 assemble_name (stream
, name
);
1510 fprintf (stream
, "\tIS @\n");
1513 /* ASM_OUTPUT_INTERNAL_LABEL. */
1516 mmix_asm_output_internal_label (FILE *stream
, const char *name
)
1518 assemble_name_raw (stream
, name
);
1519 fprintf (stream
, "\tIS @\n");
1522 /* ASM_DECLARE_REGISTER_GLOBAL. */
1525 mmix_asm_declare_register_global (FILE *stream ATTRIBUTE_UNUSED
,
1526 tree decl ATTRIBUTE_UNUSED
,
1527 int regno ATTRIBUTE_UNUSED
,
1528 const char *name ATTRIBUTE_UNUSED
)
1530 /* Nothing to do here, but there *will* be, therefore the framework is
1534 /* ASM_WEAKEN_LABEL. */
1537 mmix_asm_weaken_label (FILE *stream ATTRIBUTE_UNUSED
,
1538 const char *name ATTRIBUTE_UNUSED
)
1540 fprintf (stream
, "\t.weak ");
1541 assemble_name (stream
, name
);
1542 fprintf (stream
, " ! mmixal-incompatible\n");
1545 /* MAKE_DECL_ONE_ONLY. */
1548 mmix_make_decl_one_only (tree decl
)
1550 DECL_WEAK (decl
) = 1;
1553 /* ASM_OUTPUT_LABELREF.
1554 Strip GCC's '*' and our own '@'. No order is assumed. */
1557 mmix_asm_output_labelref (FILE *stream
, const char *name
)
1561 for (; (*name
== '@' || *name
== '*'); name
++)
1565 asm_fprintf (stream
, "%s%U%s",
1566 is_extern
&& TARGET_TOPLEVEL_SYMBOLS
? ":" : "",
1570 /* ASM_OUTPUT_DEF. */
1573 mmix_asm_output_def (FILE *stream
, const char *name
, const char *value
)
1575 assemble_name (stream
, name
);
1576 fprintf (stream
, "\tIS ");
1577 assemble_name (stream
, value
);
1578 fputc ('\n', stream
);
1581 /* TARGET_PRINT_OPERAND. */
1584 mmix_print_operand (FILE *stream
, rtx x
, int code
)
1586 /* When we add support for different codes later, we can, when needed,
1587 drop through to the main handler with a modified operand. */
1589 int regno
= x
!= NULL_RTX
&& REG_P (x
) ? REGNO (x
) : 0;
1593 /* Unrelated codes are in alphabetic order. */
1596 /* For conditional branches, output "P" for a probable branch. */
1597 if (TARGET_BRANCH_PREDICT
)
1599 x
= find_reg_note (current_output_insn
, REG_BR_PROB
, 0);
1600 if (x
&& INTVAL (XEXP (x
, 0)) > REG_BR_PROB_BASE
/ 2)
1606 /* For the %d in POP %d,0. */
1607 fprintf (stream
, "%d", MMIX_POP_ARGUMENT ());
1611 if (GET_CODE (x
) != CONST_INT
)
1612 fatal_insn ("MMIX Internal: Expected a CONST_INT, not this", x
);
1613 fprintf (stream
, "%d", (int) (INTVAL (x
) & 0xff));
1617 /* Highpart. Must be general register, and not the last one, as
1618 that one cannot be part of a consecutive register pair. */
1619 if (regno
> MMIX_LAST_GENERAL_REGISTER
- 1)
1620 internal_error ("MMIX Internal: Bad register: %d", regno
);
1622 /* This is big-endian, so the high-part is the first one. */
1623 fprintf (stream
, "%s", reg_names
[MMIX_OUTPUT_REGNO (regno
)]);
1627 /* Lowpart. Must be CONST_INT or general register, and not the last
1628 one, as that one cannot be part of a consecutive register pair. */
1629 if (GET_CODE (x
) == CONST_INT
)
1631 fprintf (stream
, "#%lx",
1632 (unsigned long) (INTVAL (x
)
1633 & ((unsigned int) 0x7fffffff * 2 + 1)));
1637 if (GET_CODE (x
) == SYMBOL_REF
)
1639 output_addr_const (stream
, x
);
1643 if (regno
> MMIX_LAST_GENERAL_REGISTER
- 1)
1644 internal_error ("MMIX Internal: Bad register: %d", regno
);
1646 /* This is big-endian, so the low-part is + 1. */
1647 fprintf (stream
, "%s", reg_names
[MMIX_OUTPUT_REGNO (regno
) + 1]);
1650 /* Can't use 'a' because that's a generic modifier for address
1653 mmix_output_shiftvalue_op_from_str (stream
, "ANDN",
1654 ~(unsigned HOST_WIDEST_INT
)
1659 mmix_output_shiftvalue_op_from_str (stream
, "INC",
1660 (unsigned HOST_WIDEST_INT
)
1665 mmix_output_shiftvalue_op_from_str (stream
, "OR",
1666 (unsigned HOST_WIDEST_INT
)
1671 mmix_output_shiftvalue_op_from_str (stream
, "SET",
1672 (unsigned HOST_WIDEST_INT
)
1678 mmix_output_condition (stream
, x
, (code
== 'D'));
1682 /* Output an extra "e" to make fcmpe, fune. */
1683 if (TARGET_FCMP_EPSILON
)
1684 fprintf (stream
, "e");
1688 /* Output the number minus 1. */
1689 if (GET_CODE (x
) != CONST_INT
)
1691 fatal_insn ("MMIX Internal: Bad value for 'm', not a CONST_INT",
1694 fprintf (stream
, HOST_WIDEST_INT_PRINT_DEC
,
1695 (HOST_WIDEST_INT
) (mmix_intval (x
) - 1));
1699 /* Store the number of registers we want to save. This was setup
1700 by the prologue. The actual operand contains the number of
1701 registers to pass, but we don't use it currently. Anyway, we
1702 need to output the number of saved registers here. */
1703 fprintf (stream
, "%d",
1704 cfun
->machine
->highest_saved_stack_register
+ 1);
1708 /* Store the register to output a constant to. */
1710 fatal_insn ("MMIX Internal: Expected a register, not this", x
);
1711 mmix_output_destination_register
= MMIX_OUTPUT_REGNO (regno
);
1715 /* Output the constant. Note that we use this for floats as well. */
1716 if (GET_CODE (x
) != CONST_INT
1717 && (GET_CODE (x
) != CONST_DOUBLE
1718 || (GET_MODE (x
) != VOIDmode
&& GET_MODE (x
) != DFmode
1719 && GET_MODE (x
) != SFmode
)))
1720 fatal_insn ("MMIX Internal: Expected a constant, not this", x
);
1721 mmix_output_register_setting (stream
,
1722 mmix_output_destination_register
,
1723 mmix_intval (x
), 0);
1727 /* An U for unsigned, if TARGET_ZERO_EXTEND. Ignore the operand. */
1728 if (TARGET_ZERO_EXTEND
)
1733 mmix_output_shifted_value (stream
, (HOST_WIDEST_INT
) mmix_intval (x
));
1737 mmix_output_shifted_value (stream
, (HOST_WIDEST_INT
) ~mmix_intval (x
));
1741 if (GET_CODE (x
) != CONST_INT
)
1742 fatal_insn ("MMIX Internal: Expected a CONST_INT, not this", x
);
1743 fprintf (stream
, "#%x", (int) (INTVAL (x
) & 0xffff));
1747 /* Nothing to do. */
1751 /* Presumably there's a missing case above if we get here. */
1752 internal_error ("MMIX Internal: Missing %qc case in mmix_print_operand", code
);
1755 switch (GET_CODE (modified_x
))
1758 regno
= REGNO (modified_x
);
1759 if (regno
>= FIRST_PSEUDO_REGISTER
)
1760 internal_error ("MMIX Internal: Bad register: %d", regno
);
1761 fprintf (stream
, "%s", reg_names
[MMIX_OUTPUT_REGNO (regno
)]);
1765 output_address (XEXP (modified_x
, 0));
1769 /* For -2147483648, mmixal complains that the constant does not fit
1770 in 4 bytes, so let's output it as hex. Take care to handle hosts
1771 where HOST_WIDE_INT is longer than an int.
1773 Print small constants +-255 using decimal. */
1775 if (INTVAL (modified_x
) > -256 && INTVAL (modified_x
) < 256)
1776 fprintf (stream
, "%d", (int) (INTVAL (modified_x
)));
1778 fprintf (stream
, "#%x",
1779 (int) (INTVAL (modified_x
)) & (unsigned int) ~0);
1783 /* Do somewhat as CONST_INT. */
1784 mmix_output_octa (stream
, mmix_intval (modified_x
), 0);
1788 output_addr_const (stream
, modified_x
);
1792 /* No need to test for all strange things. Let output_addr_const do
1794 if (CONSTANT_P (modified_x
)
1795 /* Strangely enough, this is not included in CONSTANT_P.
1796 FIXME: Ask/check about sanity here. */
1797 || GET_CODE (modified_x
) == CODE_LABEL
)
1799 output_addr_const (stream
, modified_x
);
1803 /* We need the original here. */
1804 fatal_insn ("MMIX Internal: Cannot decode this operand", x
);
1808 /* TARGET_PRINT_OPERAND_PUNCT_VALID_P. */
1811 mmix_print_operand_punct_valid_p (unsigned char code
)
1813 /* A '+' is used for branch prediction, similar to other ports. */
1815 /* A '.' is used for the %d in the POP %d,0 return insn. */
1819 /* TARGET_PRINT_OPERAND_ADDRESS. */
1822 mmix_print_operand_address (FILE *stream
, rtx x
)
1826 /* I find the generated assembly code harder to read without
1828 fprintf (stream
, "%s,0", reg_names
[MMIX_OUTPUT_REGNO (REGNO (x
))]);
1831 else if (GET_CODE (x
) == PLUS
)
1833 rtx x1
= XEXP (x
, 0);
1834 rtx x2
= XEXP (x
, 1);
1838 fprintf (stream
, "%s,", reg_names
[MMIX_OUTPUT_REGNO (REGNO (x1
))]);
1842 fprintf (stream
, "%s",
1843 reg_names
[MMIX_OUTPUT_REGNO (REGNO (x2
))]);
1846 else if (GET_CODE (x2
) == CONST_INT
1847 && CONST_OK_FOR_LETTER_P (INTVAL (x2
), 'I'))
1849 output_addr_const (stream
, x2
);
1855 if (TARGET_BASE_ADDRESSES
&& mmix_legitimate_constant_p (Pmode
, x
))
1857 output_addr_const (stream
, x
);
1861 fatal_insn ("MMIX Internal: This is not a recognized address", x
);
1864 /* ASM_OUTPUT_REG_PUSH. */
1867 mmix_asm_output_reg_push (FILE *stream
, int regno
)
1869 fprintf (stream
, "\tSUBU %s,%s,8\n\tSTOU %s,%s,0\n",
1870 reg_names
[MMIX_STACK_POINTER_REGNUM
],
1871 reg_names
[MMIX_STACK_POINTER_REGNUM
],
1872 reg_names
[MMIX_OUTPUT_REGNO (regno
)],
1873 reg_names
[MMIX_STACK_POINTER_REGNUM
]);
1876 /* ASM_OUTPUT_REG_POP. */
1879 mmix_asm_output_reg_pop (FILE *stream
, int regno
)
1881 fprintf (stream
, "\tLDOU %s,%s,0\n\tINCL %s,8\n",
1882 reg_names
[MMIX_OUTPUT_REGNO (regno
)],
1883 reg_names
[MMIX_STACK_POINTER_REGNUM
],
1884 reg_names
[MMIX_STACK_POINTER_REGNUM
]);
1887 /* ASM_OUTPUT_ADDR_DIFF_ELT. */
1890 mmix_asm_output_addr_diff_elt (FILE *stream
,
1891 rtx body ATTRIBUTE_UNUSED
,
1895 fprintf (stream
, "\tTETRA L%d-L%d\n", value
, rel
);
1898 /* ASM_OUTPUT_ADDR_VEC_ELT. */
1901 mmix_asm_output_addr_vec_elt (FILE *stream
, int value
)
1903 fprintf (stream
, "\tOCTA L:%d\n", value
);
1906 /* ASM_OUTPUT_SKIP. */
1909 mmix_asm_output_skip (FILE *stream
, int nbytes
)
1911 fprintf (stream
, "\tLOC @+%d\n", nbytes
);
1914 /* ASM_OUTPUT_ALIGN. */
1917 mmix_asm_output_align (FILE *stream
, int power
)
1919 /* We need to record the needed alignment of this section in the object,
1920 so we have to output an alignment directive. Use a .p2align (not
1921 .align) so people will never have to wonder about whether the
1922 argument is in number of bytes or the log2 thereof. We do it in
1923 addition to the LOC directive, so nothing needs tweaking when
1924 copy-pasting assembly into mmixal. */
1925 fprintf (stream
, "\t.p2align %d\n", power
);
1926 fprintf (stream
, "\tLOC @+(%d-@)&%d\n", 1 << power
, (1 << power
) - 1);
1929 /* DBX_REGISTER_NUMBER. */
1932 mmix_dbx_register_number (unsigned regno
)
1934 /* Adjust the register number to the one it will be output as, dammit.
1935 It'd be nice if we could check the assumption that we're filling a
1936 gap, but every register between the last saved register and parameter
1937 registers might be a valid parameter register. */
1938 regno
= MMIX_OUTPUT_REGNO (regno
);
1940 /* We need to renumber registers to get the number of the return address
1941 register in the range 0..255. It is also space-saving if registers
1942 mentioned in the call-frame information (which uses this function by
1943 defaulting DWARF_FRAME_REGNUM to DBX_REGISTER_NUMBER) are numbered
1944 0 .. 63. So map 224 .. 256+15 -> 0 .. 47 and 0 .. 223 -> 48..223+48. */
1945 return regno
>= 224 ? (regno
- 224) : (regno
+ 48);
1948 /* End of target macro support functions.
1950 Now the MMIX port's own functions. First the exported ones. */
1952 /* Wrapper for get_hard_reg_initial_val since integrate.h isn't included
1953 from insn-emit.c. */
1956 mmix_get_hard_reg_initial_val (enum machine_mode mode
, int regno
)
1958 return get_hard_reg_initial_val (mode
, regno
);
1961 /* Nonzero when the function epilogue is simple enough that a single
1962 "POP %d,0" should be used even within the function. */
1965 mmix_use_simple_return (void)
1969 int stack_space_to_allocate
1970 = (crtl
->outgoing_args_size
1971 + crtl
->args
.pretend_args_size
1972 + get_frame_size () + 7) & ~7;
1974 if (!TARGET_USE_RETURN_INSN
|| !reload_completed
)
1978 regno
>= MMIX_FIRST_GLOBAL_REGNUM
;
1980 /* Note that we assume that the frame-pointer-register is one of these
1981 registers, in which case we don't count it here. */
1982 if ((((regno
!= MMIX_FRAME_POINTER_REGNUM
|| !frame_pointer_needed
)
1983 && df_regs_ever_live_p (regno
) && !call_used_regs
[regno
]))
1984 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
1987 if (frame_pointer_needed
)
1988 stack_space_to_allocate
+= 8;
1990 if (MMIX_CFUN_HAS_LANDING_PAD
)
1991 stack_space_to_allocate
+= 16;
1992 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
)
1993 stack_space_to_allocate
+= 8;
1995 return stack_space_to_allocate
== 0;
1999 /* Expands the function prologue into RTX. */
2002 mmix_expand_prologue (void)
2004 HOST_WIDE_INT locals_size
= get_frame_size ();
2006 HOST_WIDE_INT stack_space_to_allocate
2007 = (crtl
->outgoing_args_size
2008 + crtl
->args
.pretend_args_size
2009 + locals_size
+ 7) & ~7;
2010 HOST_WIDE_INT offset
= -8;
2012 /* Add room needed to save global non-register-stack registers. */
2014 regno
>= MMIX_FIRST_GLOBAL_REGNUM
;
2016 /* Note that we assume that the frame-pointer-register is one of these
2017 registers, in which case we don't count it here. */
2018 if ((((regno
!= MMIX_FRAME_POINTER_REGNUM
|| !frame_pointer_needed
)
2019 && df_regs_ever_live_p (regno
) && !call_used_regs
[regno
]))
2020 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
2021 stack_space_to_allocate
+= 8;
2023 /* If we do have a frame-pointer, add room for it. */
2024 if (frame_pointer_needed
)
2025 stack_space_to_allocate
+= 8;
2027 /* If we have a non-local label, we need to be able to unwind to it, so
2028 store the current register stack pointer. Also store the return
2029 address if we do that. */
2030 if (MMIX_CFUN_HAS_LANDING_PAD
)
2031 stack_space_to_allocate
+= 16;
2032 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
)
2033 /* If we do have a saved return-address slot, add room for it. */
2034 stack_space_to_allocate
+= 8;
2036 /* Make sure we don't get an unaligned stack. */
2037 if ((stack_space_to_allocate
% 8) != 0)
2038 internal_error ("stack frame not a multiple of 8 bytes: %wd",
2039 stack_space_to_allocate
);
2041 if (crtl
->args
.pretend_args_size
)
2043 int mmix_first_vararg_reg
2044 = (MMIX_FIRST_INCOMING_ARG_REGNUM
2045 + (MMIX_MAX_ARGS_IN_REGS
2046 - crtl
->args
.pretend_args_size
/ 8));
2049 = MMIX_FIRST_INCOMING_ARG_REGNUM
+ MMIX_MAX_ARGS_IN_REGS
- 1;
2050 regno
>= mmix_first_vararg_reg
;
2055 HOST_WIDE_INT stack_chunk
2056 = stack_space_to_allocate
> (256 - 8)
2057 ? (256 - 8) : stack_space_to_allocate
;
2059 mmix_emit_sp_add (-stack_chunk
);
2060 offset
+= stack_chunk
;
2061 stack_space_to_allocate
-= stack_chunk
;
2064 /* These registers aren't actually saved (as in "will be
2065 restored"), so don't tell DWARF2 they're saved. */
2066 emit_move_insn (gen_rtx_MEM (DImode
,
2067 plus_constant (Pmode
, stack_pointer_rtx
,
2069 gen_rtx_REG (DImode
, regno
));
2074 /* Store the frame-pointer. */
2076 if (frame_pointer_needed
)
2082 /* Get 8 less than otherwise, since we need to reach offset + 8. */
2083 HOST_WIDE_INT stack_chunk
2084 = stack_space_to_allocate
> (256 - 8 - 8)
2085 ? (256 - 8 - 8) : stack_space_to_allocate
;
2087 mmix_emit_sp_add (-stack_chunk
);
2089 offset
+= stack_chunk
;
2090 stack_space_to_allocate
-= stack_chunk
;
2093 insn
= emit_move_insn (gen_rtx_MEM (DImode
,
2094 plus_constant (Pmode
,
2097 hard_frame_pointer_rtx
);
2098 RTX_FRAME_RELATED_P (insn
) = 1;
2099 insn
= emit_insn (gen_adddi3 (hard_frame_pointer_rtx
,
2101 GEN_INT (offset
+ 8)));
2102 RTX_FRAME_RELATED_P (insn
) = 1;
2106 if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
)
2111 /* Store the return-address, if one is needed on the stack. We
2112 usually store it in a register when needed, but that doesn't work
2113 with -fexceptions. */
2117 /* Get 8 less than otherwise, since we need to reach offset + 8. */
2118 HOST_WIDE_INT stack_chunk
2119 = stack_space_to_allocate
> (256 - 8 - 8)
2120 ? (256 - 8 - 8) : stack_space_to_allocate
;
2122 mmix_emit_sp_add (-stack_chunk
);
2124 offset
+= stack_chunk
;
2125 stack_space_to_allocate
-= stack_chunk
;
2128 tmpreg
= gen_rtx_REG (DImode
, 255);
2129 retreg
= gen_rtx_REG (DImode
, MMIX_rJ_REGNUM
);
2131 /* Dwarf2 code is confused by the use of a temporary register for
2132 storing the return address, so we have to express it as a note,
2133 which we attach to the actual store insn. */
2134 emit_move_insn (tmpreg
, retreg
);
2136 insn
= emit_move_insn (gen_rtx_MEM (DImode
,
2137 plus_constant (Pmode
,
2141 RTX_FRAME_RELATED_P (insn
) = 1;
2142 add_reg_note (insn
, REG_FRAME_RELATED_EXPR
,
2143 gen_rtx_SET (VOIDmode
,
2144 gen_rtx_MEM (DImode
,
2145 plus_constant (Pmode
,
2152 else if (MMIX_CFUN_HAS_LANDING_PAD
)
2155 if (MMIX_CFUN_HAS_LANDING_PAD
)
2157 /* Store the register defining the numbering of local registers, so
2158 we know how long to unwind the register stack. */
2162 /* Get 8 less than otherwise, since we need to reach offset + 8. */
2163 HOST_WIDE_INT stack_chunk
2164 = stack_space_to_allocate
> (256 - 8 - 8)
2165 ? (256 - 8 - 8) : stack_space_to_allocate
;
2167 mmix_emit_sp_add (-stack_chunk
);
2169 offset
+= stack_chunk
;
2170 stack_space_to_allocate
-= stack_chunk
;
2173 /* We don't tell dwarf2 about this one; we just have it to unwind
2174 the register stack at landing pads. FIXME: It's a kludge because
2175 we can't describe the effect of the PUSHJ and PUSHGO insns on the
2176 register stack at the moment. Best thing would be to handle it
2177 like stack-pointer offsets. Better: some hook into dwarf2out.c
2178 to produce DW_CFA_expression:s that specify the increment of rO,
2179 and unwind it at eh_return (preferred) or at the landing pad.
2180 Then saves to $0..$G-1 could be specified through that register. */
2182 emit_move_insn (gen_rtx_REG (DImode
, 255),
2183 gen_rtx_REG (DImode
,
2185 emit_move_insn (gen_rtx_MEM (DImode
,
2186 plus_constant (Pmode
, stack_pointer_rtx
,
2188 gen_rtx_REG (DImode
, 255));
2192 /* After the return-address and the frame-pointer, we have the local
2193 variables. They're the ones that may have an "unaligned" size. */
2194 offset
-= (locals_size
+ 7) & ~7;
2196 /* Now store all registers that are global, i.e. not saved by the
2197 register file machinery.
2199 It is assumed that the frame-pointer is one of these registers, so it
2200 is explicitly excluded in the count. */
2203 regno
>= MMIX_FIRST_GLOBAL_REGNUM
;
2205 if (((regno
!= MMIX_FRAME_POINTER_REGNUM
|| !frame_pointer_needed
)
2206 && df_regs_ever_live_p (regno
) && ! call_used_regs
[regno
])
2207 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
2213 HOST_WIDE_INT stack_chunk
2214 = (stack_space_to_allocate
> (256 - offset
- 8)
2215 ? (256 - offset
- 8) : stack_space_to_allocate
);
2217 mmix_emit_sp_add (-stack_chunk
);
2218 offset
+= stack_chunk
;
2219 stack_space_to_allocate
-= stack_chunk
;
2222 insn
= emit_move_insn (gen_rtx_MEM (DImode
,
2223 plus_constant (Pmode
,
2226 gen_rtx_REG (DImode
, regno
));
2227 RTX_FRAME_RELATED_P (insn
) = 1;
2231 /* Finally, allocate room for outgoing args and local vars if room
2232 wasn't allocated above. */
2233 if (stack_space_to_allocate
)
2234 mmix_emit_sp_add (-stack_space_to_allocate
);
2237 /* Expands the function epilogue into RTX. */
2240 mmix_expand_epilogue (void)
2242 HOST_WIDE_INT locals_size
= get_frame_size ();
2244 HOST_WIDE_INT stack_space_to_deallocate
2245 = (crtl
->outgoing_args_size
2246 + crtl
->args
.pretend_args_size
2247 + locals_size
+ 7) & ~7;
2249 /* The first address to access is beyond the outgoing_args area. */
2250 HOST_WIDE_INT offset
= crtl
->outgoing_args_size
;
2252 /* Add the space for global non-register-stack registers.
2253 It is assumed that the frame-pointer register can be one of these
2254 registers, in which case it is excluded from the count when needed. */
2256 regno
>= MMIX_FIRST_GLOBAL_REGNUM
;
2258 if (((regno
!= MMIX_FRAME_POINTER_REGNUM
|| !frame_pointer_needed
)
2259 && df_regs_ever_live_p (regno
) && !call_used_regs
[regno
])
2260 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
2261 stack_space_to_deallocate
+= 8;
2263 /* Add in the space for register stack-pointer. If so, always add room
2264 for the saved PC. */
2265 if (MMIX_CFUN_HAS_LANDING_PAD
)
2266 stack_space_to_deallocate
+= 16;
2267 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
)
2268 /* If we have a saved return-address slot, add it in. */
2269 stack_space_to_deallocate
+= 8;
2271 /* Add in the frame-pointer. */
2272 if (frame_pointer_needed
)
2273 stack_space_to_deallocate
+= 8;
2275 /* Make sure we don't get an unaligned stack. */
2276 if ((stack_space_to_deallocate
% 8) != 0)
2277 internal_error ("stack frame not a multiple of octabyte: %wd",
2278 stack_space_to_deallocate
);
2280 /* We will add back small offsets to the stack pointer as we go.
2281 First, we restore all registers that are global, i.e. not saved by
2282 the register file machinery. */
2284 for (regno
= MMIX_FIRST_GLOBAL_REGNUM
;
2287 if (((regno
!= MMIX_FRAME_POINTER_REGNUM
|| !frame_pointer_needed
)
2288 && df_regs_ever_live_p (regno
) && !call_used_regs
[regno
])
2289 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
2293 mmix_emit_sp_add (offset
);
2294 stack_space_to_deallocate
-= offset
;
2298 emit_move_insn (gen_rtx_REG (DImode
, regno
),
2299 gen_rtx_MEM (DImode
,
2300 plus_constant (Pmode
, stack_pointer_rtx
,
2305 /* Here is where the local variables were. As in the prologue, they
2306 might be of an unaligned size. */
2307 offset
+= (locals_size
+ 7) & ~7;
2309 /* The saved register stack pointer is just below the frame-pointer
2310 register. We don't need to restore it "manually"; the POP
2311 instruction does that. */
2312 if (MMIX_CFUN_HAS_LANDING_PAD
)
2314 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
)
2315 /* The return-address slot is just below the frame-pointer register.
2316 We don't need to restore it because we don't really use it. */
2319 /* Get back the old frame-pointer-value. */
2320 if (frame_pointer_needed
)
2324 mmix_emit_sp_add (offset
);
2326 stack_space_to_deallocate
-= offset
;
2330 emit_move_insn (hard_frame_pointer_rtx
,
2331 gen_rtx_MEM (DImode
,
2332 plus_constant (Pmode
, stack_pointer_rtx
,
2337 /* We do not need to restore pretended incoming args, just add back
2339 if (stack_space_to_deallocate
!= 0)
2340 mmix_emit_sp_add (stack_space_to_deallocate
);
2342 if (crtl
->calls_eh_return
)
2343 /* Adjust the (normal) stack-pointer to that of the receiver.
2344 FIXME: It would be nice if we could also adjust the register stack
2345 here, but we need to express it through DWARF 2 too. */
2346 emit_insn (gen_adddi3 (stack_pointer_rtx
, stack_pointer_rtx
,
2347 gen_rtx_REG (DImode
,
2348 MMIX_EH_RETURN_STACKADJ_REGNUM
)));
2351 /* Output an optimal sequence for setting a register to a specific
2352 constant. Used in an alternative for const_ints in movdi, and when
2353 using large stack-frame offsets.
2355 Use do_begin_end to say if a line-starting TAB and newline before the
2356 first insn and after the last insn is wanted. */
2359 mmix_output_register_setting (FILE *stream
,
2361 HOST_WIDEST_INT value
,
2365 fprintf (stream
, "\t");
2367 if (mmix_shiftable_wyde_value ((unsigned HOST_WIDEST_INT
) value
))
2369 /* First, the one-insn cases. */
2370 mmix_output_shiftvalue_op_from_str (stream
, "SET",
2371 (unsigned HOST_WIDEST_INT
)
2373 fprintf (stream
, " %s,", reg_names
[regno
]);
2374 mmix_output_shifted_value (stream
, (unsigned HOST_WIDEST_INT
) value
);
2376 else if (mmix_shiftable_wyde_value (-(unsigned HOST_WIDEST_INT
) value
))
2378 /* We do this to get a bit more legible assembly code. The next
2379 alternative is mostly redundant with this. */
2381 mmix_output_shiftvalue_op_from_str (stream
, "SET",
2382 -(unsigned HOST_WIDEST_INT
)
2384 fprintf (stream
, " %s,", reg_names
[regno
]);
2385 mmix_output_shifted_value (stream
, -(unsigned HOST_WIDEST_INT
) value
);
2386 fprintf (stream
, "\n\tNEGU %s,0,%s", reg_names
[regno
],
2389 else if (mmix_shiftable_wyde_value (~(unsigned HOST_WIDEST_INT
) value
))
2391 /* Slightly more expensive, the two-insn cases. */
2393 /* FIXME: We could of course also test if 0..255-N or ~(N | 1..255)
2394 is shiftable, or any other one-insn transformation of the value.
2395 FIXME: Check first if the value is "shiftable" by two loading
2396 with two insns, since it makes more readable assembly code (if
2397 anyone else cares). */
2399 mmix_output_shiftvalue_op_from_str (stream
, "SET",
2400 ~(unsigned HOST_WIDEST_INT
)
2402 fprintf (stream
, " %s,", reg_names
[regno
]);
2403 mmix_output_shifted_value (stream
, ~(unsigned HOST_WIDEST_INT
) value
);
2404 fprintf (stream
, "\n\tNOR %s,%s,0", reg_names
[regno
],
2409 /* The generic case. 2..4 insns. */
2410 static const char *const higher_parts
[] = {"L", "ML", "MH", "H"};
2411 const char *op
= "SET";
2412 const char *line_begin
= "";
2415 HOST_WIDEST_INT tmpvalue
= value
;
2417 /* Compute the number of insns needed to output this constant. */
2418 for (i
= 0; i
< 4 && tmpvalue
!= 0; i
++)
2420 if (tmpvalue
& 65535)
2424 if (TARGET_BASE_ADDRESSES
&& insns
== 3)
2426 /* The number three is based on a static observation on
2427 ghostscript-6.52. Two and four are excluded because there
2428 are too many such constants, and each unique constant (maybe
2429 offset by 1..255) were used few times compared to other uses,
2432 We use base-plus-offset addressing to force it into a global
2433 register; we just use a "LDA reg,VALUE", which will cause the
2434 assembler and linker to DTRT (for constants as well as
2436 fprintf (stream
, "LDA %s,", reg_names
[regno
]);
2437 mmix_output_octa (stream
, value
, 0);
2441 /* Output pertinent parts of the 4-wyde sequence.
2442 Still more to do if we want this to be optimal, but hey...
2443 Note that the zero case has been handled above. */
2444 for (i
= 0; i
< 4 && value
!= 0; i
++)
2448 fprintf (stream
, "%s%s%s %s,#%x", line_begin
, op
,
2449 higher_parts
[i
], reg_names
[regno
],
2450 (int) (value
& 65535));
2451 /* The first one sets the rest of the bits to 0, the next
2452 ones add set bits. */
2454 line_begin
= "\n\t";
2463 fprintf (stream
, "\n");
2466 /* Return 1 if value is 0..65535*2**(16*N) for N=0..3.
2470 mmix_shiftable_wyde_value (unsigned HOST_WIDEST_INT value
)
2472 /* Shift by 16 bits per group, stop when we've found two groups with
2475 int has_candidate
= 0;
2477 for (i
= 0; i
< 4; i
++)
2493 /* X and Y are two things to compare using CODE. Return the rtx for
2494 the cc-reg in the proper mode. */
2497 mmix_gen_compare_reg (RTX_CODE code
, rtx x
, rtx y
)
2499 enum machine_mode ccmode
= SELECT_CC_MODE (code
, x
, y
);
2500 return gen_reg_rtx (ccmode
);
2503 /* Local (static) helper functions. */
2506 mmix_emit_sp_add (HOST_WIDE_INT offset
)
2512 /* Negative stack-pointer adjustments are allocations and appear in
2513 the prologue only. We mark them as frame-related so unwind and
2514 debug info is properly emitted for them. */
2516 insn
= emit_insn (gen_adddi3 (stack_pointer_rtx
,
2521 rtx tmpr
= gen_rtx_REG (DImode
, 255);
2522 RTX_FRAME_RELATED_P (emit_move_insn (tmpr
, GEN_INT (offset
))) = 1;
2523 insn
= emit_insn (gen_adddi3 (stack_pointer_rtx
,
2524 stack_pointer_rtx
, tmpr
));
2526 RTX_FRAME_RELATED_P (insn
) = 1;
2530 /* Positive adjustments are in the epilogue only. Don't mark them
2531 as "frame-related" for unwind info. */
2532 if (CONST_OK_FOR_LETTER_P (offset
, 'L'))
2533 emit_insn (gen_adddi3 (stack_pointer_rtx
,
2538 rtx tmpr
= gen_rtx_REG (DImode
, 255);
2539 emit_move_insn (tmpr
, GEN_INT (offset
));
2540 insn
= emit_insn (gen_adddi3 (stack_pointer_rtx
,
2541 stack_pointer_rtx
, tmpr
));
2546 /* Print operator suitable for doing something with a shiftable
2547 wyde. The type of operator is passed as an asm output modifier. */
2550 mmix_output_shiftvalue_op_from_str (FILE *stream
,
2552 HOST_WIDEST_INT value
)
2554 static const char *const op_part
[] = {"L", "ML", "MH", "H"};
2557 if (! mmix_shiftable_wyde_value (value
))
2559 char s
[sizeof ("0xffffffffffffffff")];
2560 sprintf (s
, HOST_WIDEST_INT_PRINT_HEX
, value
);
2561 internal_error ("MMIX Internal: %s is not a shiftable int", s
);
2564 for (i
= 0; i
< 4; i
++)
2566 /* We know we're through when we find one-bits in the low
2570 fprintf (stream
, "%s%s", mainop
, op_part
[i
]);
2576 /* No bits set? Then it must have been zero. */
2577 fprintf (stream
, "%sL", mainop
);
2580 /* Print a 64-bit value, optionally prefixed by assembly pseudo. */
2583 mmix_output_octa (FILE *stream
, HOST_WIDEST_INT value
, int do_begin_end
)
2585 /* Snipped from final.c:output_addr_const. We need to avoid the
2586 presumed universal "0x" prefix. We can do it by replacing "0x" with
2587 "#0" here; we must avoid a space in the operands and no, the zero
2588 won't cause the number to be assumed in octal format. */
2589 char hex_format
[sizeof (HOST_WIDEST_INT_PRINT_HEX
)];
2592 fprintf (stream
, "\tOCTA ");
2594 strcpy (hex_format
, HOST_WIDEST_INT_PRINT_HEX
);
2595 hex_format
[0] = '#';
2596 hex_format
[1] = '0';
2598 /* Provide a few alternative output formats depending on the number, to
2599 improve legibility of assembler output. */
2600 if ((value
< (HOST_WIDEST_INT
) 0 && value
> (HOST_WIDEST_INT
) -10000)
2601 || (value
>= (HOST_WIDEST_INT
) 0 && value
<= (HOST_WIDEST_INT
) 16384))
2602 fprintf (stream
, "%d", (int) value
);
2603 else if (value
> (HOST_WIDEST_INT
) 0
2604 && value
< ((HOST_WIDEST_INT
) 1 << 31) * 2)
2605 fprintf (stream
, "#%x", (unsigned int) value
);
2607 fprintf (stream
, hex_format
, value
);
2610 fprintf (stream
, "\n");
2613 /* Print the presumed shiftable wyde argument shifted into place (to
2614 be output with an operand). */
2617 mmix_output_shifted_value (FILE *stream
, HOST_WIDEST_INT value
)
2621 if (! mmix_shiftable_wyde_value (value
))
2624 sprintf (s
, HOST_WIDEST_INT_PRINT_HEX
, value
);
2625 internal_error ("MMIX Internal: %s is not a shiftable int", s
);
2628 for (i
= 0; i
< 4; i
++)
2630 /* We know we're through when we find one-bits in the low 16 bits. */
2633 fprintf (stream
, "#%x", (int) (value
& 0xffff));
2640 /* No bits set? Then it must have been zero. */
2641 fprintf (stream
, "0");
2644 /* Output an MMIX condition name corresponding to an operator
2646 (comparison_operator [(comparison_operator ...) (const_int 0)])
2647 which means we have to look at *two* operators.
2649 The argument "reversed" refers to reversal of the condition (not the
2650 same as swapping the arguments). */
2653 mmix_output_condition (FILE *stream
, const_rtx x
, int reversed
)
2659 /* The normal output cc-code. */
2660 const char *const normal
;
2662 /* The reversed cc-code, or NULL if invalid. */
2663 const char *const reversed
;
2668 enum machine_mode cc_mode
;
2670 /* Terminated with {UNKNOWN, NULL, NULL} */
2671 const struct cc_conv
*const convs
;
2675 #define CCEND {UNKNOWN, NULL, NULL}
2677 static const struct cc_conv cc_fun_convs
[]
2678 = {{ORDERED
, "Z", "P"},
2679 {UNORDERED
, "P", "Z"},
2681 static const struct cc_conv cc_fp_convs
[]
2685 static const struct cc_conv cc_fpeq_convs
[]
2689 static const struct cc_conv cc_uns_convs
[]
2690 = {{GEU
, "NN", "N"},
2695 static const struct cc_conv cc_signed_convs
[]
2703 static const struct cc_conv cc_di_convs
[]
2715 static const struct cc_type_conv cc_convs
[]
2716 = {{CC_FUNmode
, cc_fun_convs
},
2717 {CC_FPmode
, cc_fp_convs
},
2718 {CC_FPEQmode
, cc_fpeq_convs
},
2719 {CC_UNSmode
, cc_uns_convs
},
2720 {CCmode
, cc_signed_convs
},
2721 {DImode
, cc_di_convs
}};
2726 enum machine_mode mode
= GET_MODE (XEXP (x
, 0));
2727 RTX_CODE cc
= GET_CODE (x
);
2729 for (i
= 0; i
< ARRAY_SIZE (cc_convs
); i
++)
2731 if (mode
== cc_convs
[i
].cc_mode
)
2733 for (j
= 0; cc_convs
[i
].convs
[j
].cc
!= UNKNOWN
; j
++)
2734 if (cc
== cc_convs
[i
].convs
[j
].cc
)
2737 = (reversed
? cc_convs
[i
].convs
[j
].reversed
2738 : cc_convs
[i
].convs
[j
].normal
);
2740 if (mmix_cc
== NULL
)
2741 fatal_insn ("MMIX Internal: Trying to output invalidly\
2742 reversed condition:", x
);
2744 fprintf (stream
, "%s", mmix_cc
);
2748 fatal_insn ("MMIX Internal: What's the CC of this?", x
);
2752 fatal_insn ("MMIX Internal: What is the CC of this?", x
);
2755 /* Return the bit-value for a const_int or const_double. */
2757 static HOST_WIDEST_INT
2758 mmix_intval (const_rtx x
)
2760 unsigned HOST_WIDEST_INT retval
;
2762 if (GET_CODE (x
) == CONST_INT
)
2765 /* We make a little song and dance because converting to long long in
2766 gcc-2.7.2 is broken. I still want people to be able to use it for
2767 cross-compilation to MMIX. */
2768 if (GET_CODE (x
) == CONST_DOUBLE
&& GET_MODE (x
) == VOIDmode
)
2770 if (sizeof (HOST_WIDE_INT
) < sizeof (HOST_WIDEST_INT
))
2772 retval
= (unsigned) CONST_DOUBLE_LOW (x
) / 2;
2774 retval
|= CONST_DOUBLE_LOW (x
) & 1;
2777 (unsigned HOST_WIDEST_INT
) CONST_DOUBLE_HIGH (x
)
2778 << (HOST_BITS_PER_LONG
)/2 << (HOST_BITS_PER_LONG
)/2;
2781 retval
= CONST_DOUBLE_HIGH (x
);
2786 if (GET_CODE (x
) == CONST_DOUBLE
)
2788 REAL_VALUE_TYPE value
;
2790 /* FIXME: This macro is not in the manual but should be. */
2791 REAL_VALUE_FROM_CONST_DOUBLE (value
, x
);
2793 if (GET_MODE (x
) == DFmode
)
2797 REAL_VALUE_TO_TARGET_DOUBLE (value
, bits
);
2799 /* The double cast is necessary to avoid getting the long
2800 sign-extended to unsigned long long(!) when they're of
2801 different size (usually 32-bit hosts). */
2803 ((unsigned HOST_WIDEST_INT
) (unsigned long) bits
[0]
2804 << (unsigned HOST_WIDEST_INT
) 32U)
2805 | (unsigned HOST_WIDEST_INT
) (unsigned long) bits
[1];
2807 else if (GET_MODE (x
) == SFmode
)
2810 REAL_VALUE_TO_TARGET_SINGLE (value
, bits
);
2812 return (unsigned long) bits
;
2816 fatal_insn ("MMIX Internal: This is not a constant:", x
);
2819 /* Worker function for TARGET_PROMOTE_FUNCTION_MODE. */
2822 mmix_promote_function_mode (const_tree type ATTRIBUTE_UNUSED
,
2823 enum machine_mode mode
,
2824 int *punsignedp ATTRIBUTE_UNUSED
,
2825 const_tree fntype ATTRIBUTE_UNUSED
,
2828 /* Apparently not doing TRT if int < register-size. FIXME: Perhaps
2829 FUNCTION_VALUE and LIBCALL_VALUE needs tweaking as some ports say. */
2830 if (for_return
== 1)
2833 /* Promotion of modes currently generates slow code, extending before
2834 operation, so we do it only for arguments. */
2835 if (GET_MODE_CLASS (mode
) == MODE_INT
2836 && GET_MODE_SIZE (mode
) < 8)
2841 /* Worker function for TARGET_STRUCT_VALUE_RTX. */
2844 mmix_struct_value_rtx (tree fntype ATTRIBUTE_UNUSED
,
2845 int incoming ATTRIBUTE_UNUSED
)
2847 return gen_rtx_REG (Pmode
, MMIX_STRUCT_VALUE_REGNUM
);
2850 /* Worker function for TARGET_FRAME_POINTER_REQUIRED.
2852 FIXME: Is this requirement built-in? Anyway, we should try to get rid
2853 of it; we can deduce the value. */
2856 mmix_frame_pointer_required (void)
2858 return (cfun
->has_nonlocal_label
);
2863 * eval: (c-set-style "gnu")
2864 * indent-tabs-mode: t