1 /* Definitions of target machine for GNU compiler, for MMIX.
2 Copyright (C) 2000-2013 Free Software Foundation, Inc.
3 Contributed by Hans-Peter Nilsson (hp@bitrange.com)
5 This file is part of GCC.
7 GCC 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 3, or (at your option)
12 GCC 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 GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
23 #include "coretypes.h"
27 #include "hard-reg-set.h"
29 #include "insn-config.h"
31 #include "basic-block.h"
36 #include "diagnostic-core.h"
43 #include "target-def.h"
45 #include "tm-constrs.h"
47 /* First some local helper definitions. */
48 #define MMIX_FIRST_GLOBAL_REGNUM 32
50 /* We'd need a current_function_has_landing_pad. It's marked as such when
51 a nonlocal_goto_receiver is expanded. Not just a C++ thing, but
53 #define MMIX_CFUN_HAS_LANDING_PAD (cfun->machine->has_landing_pad != 0)
55 /* We have no means to tell DWARF 2 about the register stack, so we need
56 to store the return address on the stack if an exception can get into
57 this function. FIXME: Narrow condition. Before any whole-function
58 analysis, df_regs_ever_live_p () isn't initialized. We know it's up-to-date
59 after reload_completed; it may contain incorrect information some time
60 before that. Within a RTL sequence (after a call to start_sequence,
61 such as in RTL expanders), leaf_function_p doesn't see all insns
62 (perhaps any insn). But regs_ever_live is up-to-date when
63 leaf_function_p () isn't, so we "or" them together to get accurate
64 information. FIXME: Some tweak to leaf_function_p might be
66 #define MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS \
68 && ((reload_completed && df_regs_ever_live_p (MMIX_rJ_REGNUM)) \
69 || !leaf_function_p ()))
71 #define IS_MMIX_EH_RETURN_DATA_REG(REGNO) \
72 (crtl->calls_eh_return \
73 && (EH_RETURN_DATA_REGNO (0) == REGNO \
74 || EH_RETURN_DATA_REGNO (1) == REGNO \
75 || EH_RETURN_DATA_REGNO (2) == REGNO \
76 || EH_RETURN_DATA_REGNO (3) == REGNO))
78 /* For the default ABI, we rename registers at output-time to fill the gap
79 between the (statically partitioned) saved registers and call-clobbered
80 registers. In effect this makes unused call-saved registers to be used
81 as call-clobbered registers. The benefit comes from keeping the number
82 of local registers (value of rL) low, since there's a cost of
83 increasing rL and clearing unused (unset) registers with lower numbers.
84 Don't translate while outputting the prologue. */
85 #define MMIX_OUTPUT_REGNO(N) \
87 || (int) (N) < MMIX_RETURN_VALUE_REGNUM \
88 || (int) (N) > MMIX_LAST_STACK_REGISTER_REGNUM \
90 || cfun->machine == NULL \
91 || cfun->machine->in_prologue \
92 ? (N) : ((N) - MMIX_RETURN_VALUE_REGNUM \
93 + cfun->machine->highest_saved_stack_register + 1))
95 /* The %d in "POP %d,0". */
96 #define MMIX_POP_ARGUMENT() \
98 && crtl->return_rtx != NULL \
99 && ! cfun->returns_struct) \
100 ? (GET_CODE (crtl->return_rtx) == PARALLEL \
101 ? GET_NUM_ELEM (XVEC (crtl->return_rtx, 0)) : 1) \
104 /* The canonical saved comparison operands for non-cc0 machines, set in
105 the compare expander. */
106 rtx mmix_compare_op0
;
107 rtx mmix_compare_op1
;
109 /* Declarations of locals. */
111 /* Intermediate for insn output. */
112 static int mmix_output_destination_register
;
114 static void mmix_option_override (void);
115 static void mmix_asm_output_source_filename (FILE *, const char *);
116 static void mmix_output_shiftvalue_op_from_str
117 (FILE *, const char *, HOST_WIDEST_INT
);
118 static void mmix_output_shifted_value (FILE *, HOST_WIDEST_INT
);
119 static void mmix_output_condition (FILE *, const_rtx
, int);
120 static void mmix_output_octa (FILE *, HOST_WIDEST_INT
, int);
121 static bool mmix_assemble_integer (rtx
, unsigned int, int);
122 static struct machine_function
*mmix_init_machine_status (void);
123 static void mmix_encode_section_info (tree
, rtx
, int);
124 static const char *mmix_strip_name_encoding (const char *);
125 static void mmix_emit_sp_add (HOST_WIDE_INT offset
);
126 static void mmix_target_asm_function_prologue (FILE *, HOST_WIDE_INT
);
127 static void mmix_target_asm_function_end_prologue (FILE *);
128 static void mmix_target_asm_function_epilogue (FILE *, HOST_WIDE_INT
);
129 static reg_class_t
mmix_preferred_reload_class (rtx
, reg_class_t
);
130 static reg_class_t
mmix_preferred_output_reload_class (rtx
, reg_class_t
);
131 static bool mmix_legitimate_address_p (enum machine_mode
, rtx
, bool);
132 static bool mmix_legitimate_constant_p (enum machine_mode
, rtx
);
133 static void mmix_reorg (void);
134 static void mmix_asm_output_mi_thunk
135 (FILE *, tree
, HOST_WIDE_INT
, HOST_WIDE_INT
, tree
);
136 static void mmix_setup_incoming_varargs
137 (cumulative_args_t
, enum machine_mode
, tree
, int *, int);
138 static void mmix_file_start (void);
139 static void mmix_file_end (void);
140 static bool mmix_rtx_costs (rtx
, int, int, int, int *, bool);
141 static int mmix_register_move_cost (enum machine_mode
,
142 reg_class_t
, reg_class_t
);
143 static rtx
mmix_struct_value_rtx (tree
, int);
144 static enum machine_mode
mmix_promote_function_mode (const_tree
,
146 int *, const_tree
, int);
147 static void mmix_function_arg_advance (cumulative_args_t
, enum machine_mode
,
149 static rtx
mmix_function_arg_1 (const cumulative_args_t
, enum machine_mode
,
150 const_tree
, bool, bool);
151 static rtx
mmix_function_incoming_arg (cumulative_args_t
, enum machine_mode
,
153 static rtx
mmix_function_arg (cumulative_args_t
, enum machine_mode
,
155 static rtx
mmix_function_value (const_tree
, const_tree
, bool);
156 static rtx
mmix_libcall_value (enum machine_mode
, const_rtx
);
157 static bool mmix_function_value_regno_p (const unsigned int);
158 static bool mmix_pass_by_reference (cumulative_args_t
,
159 enum machine_mode
, const_tree
, bool);
160 static bool mmix_frame_pointer_required (void);
161 static void mmix_asm_trampoline_template (FILE *);
162 static void mmix_trampoline_init (rtx
, tree
, rtx
);
163 static void mmix_print_operand (FILE *, rtx
, int);
164 static void mmix_print_operand_address (FILE *, rtx
);
165 static bool mmix_print_operand_punct_valid_p (unsigned char);
166 static void mmix_conditional_register_usage (void);
168 /* Target structure macros. Listed by node. See `Using and Porting GCC'
169 for a general description. */
171 /* Node: Function Entry */
173 #undef TARGET_ASM_BYTE_OP
174 #define TARGET_ASM_BYTE_OP NULL
175 #undef TARGET_ASM_ALIGNED_HI_OP
176 #define TARGET_ASM_ALIGNED_HI_OP NULL
177 #undef TARGET_ASM_ALIGNED_SI_OP
178 #define TARGET_ASM_ALIGNED_SI_OP NULL
179 #undef TARGET_ASM_ALIGNED_DI_OP
180 #define TARGET_ASM_ALIGNED_DI_OP NULL
181 #undef TARGET_ASM_INTEGER
182 #define TARGET_ASM_INTEGER mmix_assemble_integer
184 #undef TARGET_ASM_FUNCTION_PROLOGUE
185 #define TARGET_ASM_FUNCTION_PROLOGUE mmix_target_asm_function_prologue
187 #undef TARGET_ASM_FUNCTION_END_PROLOGUE
188 #define TARGET_ASM_FUNCTION_END_PROLOGUE mmix_target_asm_function_end_prologue
190 #undef TARGET_ASM_FUNCTION_EPILOGUE
191 #define TARGET_ASM_FUNCTION_EPILOGUE mmix_target_asm_function_epilogue
193 #undef TARGET_PRINT_OPERAND
194 #define TARGET_PRINT_OPERAND mmix_print_operand
195 #undef TARGET_PRINT_OPERAND_ADDRESS
196 #define TARGET_PRINT_OPERAND_ADDRESS mmix_print_operand_address
197 #undef TARGET_PRINT_OPERAND_PUNCT_VALID_P
198 #define TARGET_PRINT_OPERAND_PUNCT_VALID_P mmix_print_operand_punct_valid_p
200 #undef TARGET_ENCODE_SECTION_INFO
201 #define TARGET_ENCODE_SECTION_INFO mmix_encode_section_info
202 #undef TARGET_STRIP_NAME_ENCODING
203 #define TARGET_STRIP_NAME_ENCODING mmix_strip_name_encoding
205 #undef TARGET_ASM_OUTPUT_MI_THUNK
206 #define TARGET_ASM_OUTPUT_MI_THUNK mmix_asm_output_mi_thunk
207 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
208 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall
209 #undef TARGET_ASM_FILE_START
210 #define TARGET_ASM_FILE_START mmix_file_start
211 #undef TARGET_ASM_FILE_START_FILE_DIRECTIVE
212 #define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
213 #undef TARGET_ASM_FILE_END
214 #define TARGET_ASM_FILE_END mmix_file_end
215 #undef TARGET_ASM_OUTPUT_SOURCE_FILENAME
216 #define TARGET_ASM_OUTPUT_SOURCE_FILENAME mmix_asm_output_source_filename
218 #undef TARGET_CONDITIONAL_REGISTER_USAGE
219 #define TARGET_CONDITIONAL_REGISTER_USAGE mmix_conditional_register_usage
221 #undef TARGET_RTX_COSTS
222 #define TARGET_RTX_COSTS mmix_rtx_costs
223 #undef TARGET_ADDRESS_COST
224 #define TARGET_ADDRESS_COST hook_int_rtx_mode_as_bool_0
226 #undef TARGET_REGISTER_MOVE_COST
227 #define TARGET_REGISTER_MOVE_COST mmix_register_move_cost
229 #undef TARGET_MACHINE_DEPENDENT_REORG
230 #define TARGET_MACHINE_DEPENDENT_REORG mmix_reorg
232 #undef TARGET_PROMOTE_FUNCTION_MODE
233 #define TARGET_PROMOTE_FUNCTION_MODE mmix_promote_function_mode
235 #undef TARGET_FUNCTION_VALUE
236 #define TARGET_FUNCTION_VALUE mmix_function_value
237 #undef TARGET_LIBCALL_VALUE
238 #define TARGET_LIBCALL_VALUE mmix_libcall_value
239 #undef TARGET_FUNCTION_VALUE_REGNO_P
240 #define TARGET_FUNCTION_VALUE_REGNO_P mmix_function_value_regno_p
242 #undef TARGET_FUNCTION_ARG
243 #define TARGET_FUNCTION_ARG mmix_function_arg
244 #undef TARGET_FUNCTION_INCOMING_ARG
245 #define TARGET_FUNCTION_INCOMING_ARG mmix_function_incoming_arg
246 #undef TARGET_FUNCTION_ARG_ADVANCE
247 #define TARGET_FUNCTION_ARG_ADVANCE mmix_function_arg_advance
248 #undef TARGET_STRUCT_VALUE_RTX
249 #define TARGET_STRUCT_VALUE_RTX mmix_struct_value_rtx
250 #undef TARGET_SETUP_INCOMING_VARARGS
251 #define TARGET_SETUP_INCOMING_VARARGS mmix_setup_incoming_varargs
252 #undef TARGET_PASS_BY_REFERENCE
253 #define TARGET_PASS_BY_REFERENCE mmix_pass_by_reference
254 #undef TARGET_CALLEE_COPIES
255 #define TARGET_CALLEE_COPIES hook_bool_CUMULATIVE_ARGS_mode_tree_bool_true
257 #undef TARGET_PREFERRED_RELOAD_CLASS
258 #define TARGET_PREFERRED_RELOAD_CLASS mmix_preferred_reload_class
259 #undef TARGET_PREFERRED_OUTPUT_RELOAD_CLASS
260 #define TARGET_PREFERRED_OUTPUT_RELOAD_CLASS mmix_preferred_output_reload_class
262 #undef TARGET_LEGITIMATE_ADDRESS_P
263 #define TARGET_LEGITIMATE_ADDRESS_P mmix_legitimate_address_p
264 #undef TARGET_LEGITIMATE_CONSTANT_P
265 #define TARGET_LEGITIMATE_CONSTANT_P mmix_legitimate_constant_p
267 #undef TARGET_FRAME_POINTER_REQUIRED
268 #define TARGET_FRAME_POINTER_REQUIRED mmix_frame_pointer_required
270 #undef TARGET_ASM_TRAMPOLINE_TEMPLATE
271 #define TARGET_ASM_TRAMPOLINE_TEMPLATE mmix_asm_trampoline_template
272 #undef TARGET_TRAMPOLINE_INIT
273 #define TARGET_TRAMPOLINE_INIT mmix_trampoline_init
275 #undef TARGET_OPTION_OVERRIDE
276 #define TARGET_OPTION_OVERRIDE mmix_option_override
278 struct gcc_target targetm
= TARGET_INITIALIZER
;
280 /* Functions that are expansions for target macros.
281 See Target Macros in `Using and Porting GCC'. */
283 /* TARGET_OPTION_OVERRIDE. */
286 mmix_option_override (void)
288 /* Should we err or should we warn? Hmm. At least we must neutralize
289 it. For example the wrong kind of case-tables will be generated with
290 PIC; we use absolute address items for mmixal compatibility. FIXME:
291 They could be relative if we just elide them to after all pertinent
295 warning (0, "-f%s not supported: ignored", (flag_pic
> 1) ? "PIC" : "pic");
300 /* INIT_EXPANDERS. */
303 mmix_init_expanders (void)
305 init_machine_status
= mmix_init_machine_status
;
308 /* Set the per-function data. */
310 static struct machine_function
*
311 mmix_init_machine_status (void)
313 return ggc_alloc_cleared_machine_function ();
317 We have trouble getting the address of stuff that is located at other
318 than 32-bit alignments (GETA requirements), so try to give everything
319 at least 32-bit alignment. */
322 mmix_data_alignment (tree type ATTRIBUTE_UNUSED
, int basic_align
)
324 if (basic_align
< 32)
330 /* CONSTANT_ALIGNMENT. */
333 mmix_constant_alignment (tree constant ATTRIBUTE_UNUSED
, int basic_align
)
335 if (basic_align
< 32)
341 /* LOCAL_ALIGNMENT. */
344 mmix_local_alignment (tree type ATTRIBUTE_UNUSED
, unsigned basic_align
)
346 if (basic_align
< 32)
352 /* TARGET_CONDITIONAL_REGISTER_USAGE. */
355 mmix_conditional_register_usage (void)
361 static const int gnu_abi_reg_alloc_order
[]
362 = MMIX_GNU_ABI_REG_ALLOC_ORDER
;
364 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
365 reg_alloc_order
[i
] = gnu_abi_reg_alloc_order
[i
];
367 /* Change the default from the mmixware ABI. For the GNU ABI,
368 $15..$30 are call-saved just as $0..$14. There must be one
369 call-clobbered local register for the "hole" that holds the
370 number of saved local registers saved by PUSHJ/PUSHGO during the
371 function call, receiving the return value at return. So best is
372 to use the highest, $31. It's already marked call-clobbered for
374 for (i
= 15; i
<= 30; i
++)
375 call_used_regs
[i
] = 0;
377 /* "Unfix" the parameter registers. */
378 for (i
= MMIX_RESERVED_GNU_ARG_0_REGNUM
;
379 i
< MMIX_RESERVED_GNU_ARG_0_REGNUM
+ MMIX_MAX_ARGS_IN_REGS
;
384 /* Step over the ":" in special register names. */
385 if (! TARGET_TOPLEVEL_SYMBOLS
)
386 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
387 if (reg_names
[i
][0] == ':')
391 /* INCOMING_REGNO and OUTGOING_REGNO worker function.
392 Those two macros must only be applied to function argument
393 registers and the function return value register for the opposite
394 use. FIXME: for their current use in gcc, it'd be better with an
395 explicit specific additional FUNCTION_INCOMING_ARG_REGNO_P a'la
396 TARGET_FUNCTION_ARG / TARGET_FUNCTION_INCOMING_ARG instead of
397 forcing the target to commit to a fixed mapping and for any
398 unspecified register use. Particularly when thinking about the
399 return-value, it is better to imagine INCOMING_REGNO and
400 OUTGOING_REGNO as named CALLEE_TO_CALLER_REGNO and INNER_REGNO as
401 named CALLER_TO_CALLEE_REGNO because the direction. The "incoming"
402 and "outgoing" is from the perspective of the parameter-registers,
403 but the same macro is (must be, lacking an alternative like
404 suggested above) used to map the return-value-register from the
405 same perspective. To make directions even more confusing, the macro
406 MMIX_OUTGOING_RETURN_VALUE_REGNUM holds the number of the register
407 in which to return a value, i.e. INCOMING_REGNO for the return-value-
408 register as received from a called function; the return-value on the
412 mmix_opposite_regno (int regno
, int incoming
)
414 if (incoming
&& regno
== MMIX_OUTGOING_RETURN_VALUE_REGNUM
)
415 return MMIX_RETURN_VALUE_REGNUM
;
417 if (!incoming
&& regno
== MMIX_RETURN_VALUE_REGNUM
)
418 return MMIX_OUTGOING_RETURN_VALUE_REGNUM
;
420 if (!mmix_function_arg_regno_p (regno
, incoming
))
425 ? MMIX_FIRST_INCOMING_ARG_REGNUM
- MMIX_FIRST_ARG_REGNUM
426 : MMIX_FIRST_ARG_REGNUM
- MMIX_FIRST_INCOMING_ARG_REGNUM
);
430 All registers that are part of the register stack and that will be
434 mmix_local_regno (int regno
)
436 return regno
<= MMIX_LAST_STACK_REGISTER_REGNUM
&& !call_used_regs
[regno
];
439 /* TARGET_PREFERRED_RELOAD_CLASS.
440 We need to extend the reload class of REMAINDER_REG and HIMULT_REG. */
443 mmix_preferred_reload_class (rtx x
, reg_class_t rclass
)
445 /* FIXME: Revisit. */
446 return GET_CODE (x
) == MOD
&& GET_MODE (x
) == DImode
447 ? REMAINDER_REG
: rclass
;
450 /* TARGET_PREFERRED_OUTPUT_RELOAD_CLASS.
451 We need to extend the reload class of REMAINDER_REG and HIMULT_REG. */
454 mmix_preferred_output_reload_class (rtx x
, reg_class_t rclass
)
456 /* FIXME: Revisit. */
457 return GET_CODE (x
) == MOD
&& GET_MODE (x
) == DImode
458 ? REMAINDER_REG
: rclass
;
461 /* SECONDARY_RELOAD_CLASS.
462 We need to reload regs of REMAINDER_REG and HIMULT_REG elsewhere. */
465 mmix_secondary_reload_class (enum reg_class rclass
,
466 enum machine_mode mode ATTRIBUTE_UNUSED
,
467 rtx x ATTRIBUTE_UNUSED
,
468 int in_p ATTRIBUTE_UNUSED
)
470 if (rclass
== REMAINDER_REG
471 || rclass
== HIMULT_REG
472 || rclass
== SYSTEM_REGS
)
478 /* DYNAMIC_CHAIN_ADDRESS. */
481 mmix_dynamic_chain_address (rtx frame
)
483 /* FIXME: the frame-pointer is stored at offset -8 from the current
484 frame-pointer. Unfortunately, the caller assumes that a
485 frame-pointer is present for *all* previous frames. There should be
486 a way to say that that cannot be done, like for RETURN_ADDR_RTX. */
487 return plus_constant (Pmode
, frame
, -8);
490 /* STARTING_FRAME_OFFSET. */
493 mmix_starting_frame_offset (void)
495 /* The old frame pointer is in the slot below the new one, so
496 FIRST_PARM_OFFSET does not need to depend on whether the
497 frame-pointer is needed or not. We have to adjust for the register
498 stack pointer being located below the saved frame pointer.
499 Similarly, we store the return address on the stack too, for
500 exception handling, and always if we save the register stack pointer. */
503 + (MMIX_CFUN_HAS_LANDING_PAD
504 ? -16 : (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
? -8 : 0)));
507 /* RETURN_ADDR_RTX. */
510 mmix_return_addr_rtx (int count
, rtx frame ATTRIBUTE_UNUSED
)
513 ? (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
514 /* FIXME: Set frame_alias_set on the following. (Why?)
515 See mmix_initial_elimination_offset for the reason we can't use
516 get_hard_reg_initial_val for both. Always using a stack slot
517 and not a register would be suboptimal. */
518 ? validize_mem (gen_rtx_MEM (Pmode
,
519 plus_constant (Pmode
,
520 frame_pointer_rtx
, -16)))
521 : get_hard_reg_initial_val (Pmode
, MMIX_INCOMING_RETURN_ADDRESS_REGNUM
))
525 /* SETUP_FRAME_ADDRESSES. */
528 mmix_setup_frame_addresses (void)
530 /* Nothing needed at the moment. */
533 /* The difference between the (imaginary) frame pointer and the stack
534 pointer. Used to eliminate the frame pointer. */
537 mmix_initial_elimination_offset (int fromreg
, int toreg
)
541 = (get_frame_size () + crtl
->outgoing_args_size
+ 7) & ~7;
543 /* There is no actual offset between these two virtual values, but for
544 the frame-pointer, we have the old one in the stack position below
545 it, so the offset for the frame-pointer to the stack-pointer is one
547 if (fromreg
== MMIX_ARG_POINTER_REGNUM
548 && toreg
== MMIX_FRAME_POINTER_REGNUM
)
551 /* The difference is the size of local variables plus the size of
552 outgoing function arguments that would normally be passed as
553 registers but must be passed on stack because we're out of
554 function-argument registers. Only global saved registers are
555 counted; the others go on the register stack.
557 The frame-pointer is counted too if it is what is eliminated, as we
558 need to balance the offset for it from STARTING_FRAME_OFFSET.
560 Also add in the slot for the register stack pointer we save if we
563 Unfortunately, we can't access $0..$14, from unwinder code easily, so
564 store the return address in a frame slot too. FIXME: Only for
565 non-leaf functions. FIXME: Always with a landing pad, because it's
566 hard to know whether we need the other at the time we know we need
567 the offset for one (and have to state it). It's a kludge until we
568 can express the register stack in the EH frame info.
570 We have to do alignment here; get_frame_size will not return a
571 multiple of STACK_BOUNDARY. FIXME: Add note in manual. */
573 for (regno
= MMIX_FIRST_GLOBAL_REGNUM
;
576 if ((df_regs_ever_live_p (regno
) && ! call_used_regs
[regno
])
577 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
581 + (MMIX_CFUN_HAS_LANDING_PAD
582 ? 16 : (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
? 8 : 0))
583 + (fromreg
== MMIX_ARG_POINTER_REGNUM
? 0 : 8);
587 mmix_function_arg_advance (cumulative_args_t argsp_v
, enum machine_mode mode
,
588 const_tree type
, bool named ATTRIBUTE_UNUSED
)
590 CUMULATIVE_ARGS
*argsp
= get_cumulative_args (argsp_v
);
591 int arg_size
= MMIX_FUNCTION_ARG_SIZE (mode
, type
);
593 argsp
->regs
= ((targetm
.calls
.must_pass_in_stack (mode
, type
)
597 ? (MMIX_MAX_ARGS_IN_REGS
) + 1
598 : argsp
->regs
+ (7 + arg_size
) / 8);
601 /* Helper function for mmix_function_arg and mmix_function_incoming_arg. */
604 mmix_function_arg_1 (const cumulative_args_t argsp_v
,
605 enum machine_mode mode
,
607 bool named ATTRIBUTE_UNUSED
,
610 CUMULATIVE_ARGS
*argsp
= get_cumulative_args (argsp_v
);
612 /* Last-argument marker. */
613 if (type
== void_type_node
)
614 return (argsp
->regs
< MMIX_MAX_ARGS_IN_REGS
)
617 ? MMIX_FIRST_INCOMING_ARG_REGNUM
618 : MMIX_FIRST_ARG_REGNUM
) + argsp
->regs
)
621 return (argsp
->regs
< MMIX_MAX_ARGS_IN_REGS
622 && !targetm
.calls
.must_pass_in_stack (mode
, type
)
623 && (GET_MODE_BITSIZE (mode
) <= 64
628 ? MMIX_FIRST_INCOMING_ARG_REGNUM
629 : MMIX_FIRST_ARG_REGNUM
)
634 /* Return an rtx for a function argument to go in a register, and 0 for
635 one that must go on stack. */
638 mmix_function_arg (cumulative_args_t argsp
,
639 enum machine_mode mode
,
643 return mmix_function_arg_1 (argsp
, mode
, type
, named
, false);
647 mmix_function_incoming_arg (cumulative_args_t argsp
,
648 enum machine_mode mode
,
652 return mmix_function_arg_1 (argsp
, mode
, type
, named
, true);
655 /* Returns nonzero for everything that goes by reference, 0 for
656 everything that goes by value. */
659 mmix_pass_by_reference (cumulative_args_t argsp_v
, enum machine_mode mode
,
660 const_tree type
, bool named ATTRIBUTE_UNUSED
)
662 CUMULATIVE_ARGS
*argsp
= get_cumulative_args (argsp_v
);
664 /* FIXME: Check: I'm not sure the must_pass_in_stack check is
666 if (targetm
.calls
.must_pass_in_stack (mode
, type
))
669 if (MMIX_FUNCTION_ARG_SIZE (mode
, type
) > 8
671 && (!argsp
|| !argsp
->lib
))
677 /* Return nonzero if regno is a register number where a parameter is
678 passed, and 0 otherwise. */
681 mmix_function_arg_regno_p (int regno
, int incoming
)
684 = incoming
? MMIX_FIRST_INCOMING_ARG_REGNUM
: MMIX_FIRST_ARG_REGNUM
;
686 return regno
>= first_arg_regnum
687 && regno
< first_arg_regnum
+ MMIX_MAX_ARGS_IN_REGS
;
690 /* Implements TARGET_FUNCTION_VALUE. */
693 mmix_function_value (const_tree valtype
,
694 const_tree func ATTRIBUTE_UNUSED
,
697 enum machine_mode mode
= TYPE_MODE (valtype
);
698 enum machine_mode cmode
;
699 int first_val_regnum
= MMIX_OUTGOING_RETURN_VALUE_REGNUM
;
700 rtx vec
[MMIX_MAX_REGS_FOR_VALUE
];
705 return gen_rtx_REG (mode
, MMIX_RETURN_VALUE_REGNUM
);
707 /* Return values that fit in a register need no special handling.
708 There's no register hole when parameters are passed in global
711 || GET_MODE_BITSIZE (mode
) <= BITS_PER_WORD
)
713 gen_rtx_REG (mode
, MMIX_OUTGOING_RETURN_VALUE_REGNUM
);
715 if (COMPLEX_MODE_P (mode
))
716 /* A complex type, made up of components. */
717 cmode
= TYPE_MODE (TREE_TYPE (valtype
));
720 /* Of the other larger-than-register modes, we only support
721 scalar mode TImode. (At least, that's the only one that's
722 been rudimentally tested.) Make sure we're alerted for
725 sorry ("support for mode %qs", GET_MODE_NAME (mode
));
727 /* In any case, we will fill registers to the natural size. */
731 nregs
= ((GET_MODE_BITSIZE (mode
) + BITS_PER_WORD
- 1) / BITS_PER_WORD
);
733 /* We need to take care of the effect of the register hole on return
734 values of large sizes; the last register will appear as the first
735 register, with the rest shifted. (For complex modes, this is just
736 swapped registers.) */
738 if (nregs
> MMIX_MAX_REGS_FOR_VALUE
)
739 internal_error ("too large function value type, needs %d registers,\
740 have only %d registers for this", nregs
, MMIX_MAX_REGS_FOR_VALUE
);
742 /* FIXME: Maybe we should handle structure values like this too
743 (adjusted for BLKmode), perhaps for both ABI:s. */
744 for (i
= 0; i
< nregs
- 1; i
++)
746 = gen_rtx_EXPR_LIST (VOIDmode
,
747 gen_rtx_REG (cmode
, first_val_regnum
+ i
),
748 GEN_INT ((i
+ 1) * BITS_PER_UNIT
));
751 = gen_rtx_EXPR_LIST (VOIDmode
,
752 gen_rtx_REG (cmode
, first_val_regnum
+ nregs
- 1),
755 return gen_rtx_PARALLEL (mode
, gen_rtvec_v (nregs
, vec
));
758 /* Implements TARGET_LIBCALL_VALUE. */
761 mmix_libcall_value (enum machine_mode mode
,
762 const_rtx fun ATTRIBUTE_UNUSED
)
764 return gen_rtx_REG (mode
, MMIX_RETURN_VALUE_REGNUM
);
767 /* Implements TARGET_FUNCTION_VALUE_REGNO_P. */
770 mmix_function_value_regno_p (const unsigned int regno
)
772 return regno
== MMIX_RETURN_VALUE_REGNUM
;
775 /* EH_RETURN_DATA_REGNO. */
778 mmix_eh_return_data_regno (int n
)
781 return MMIX_EH_RETURN_DATA_REGNO_START
+ n
;
783 return INVALID_REGNUM
;
786 /* EH_RETURN_STACKADJ_RTX. */
789 mmix_eh_return_stackadj_rtx (void)
791 return gen_rtx_REG (Pmode
, MMIX_EH_RETURN_STACKADJ_REGNUM
);
794 /* EH_RETURN_HANDLER_RTX. */
797 mmix_eh_return_handler_rtx (void)
799 return gen_rtx_REG (Pmode
, MMIX_INCOMING_RETURN_ADDRESS_REGNUM
);
802 /* ASM_PREFERRED_EH_DATA_FORMAT. */
805 mmix_asm_preferred_eh_data_format (int code ATTRIBUTE_UNUSED
,
806 int global ATTRIBUTE_UNUSED
)
808 /* This is the default (was at 2001-07-20). Revisit when needed. */
809 return DW_EH_PE_absptr
;
812 /* Make a note that we've seen the beginning of the prologue. This
813 matters to whether we'll translate register numbers as calculated by
817 mmix_target_asm_function_prologue (FILE *stream ATTRIBUTE_UNUSED
,
818 HOST_WIDE_INT framesize ATTRIBUTE_UNUSED
)
820 cfun
->machine
->in_prologue
= 1;
823 /* Make a note that we've seen the end of the prologue. */
826 mmix_target_asm_function_end_prologue (FILE *stream ATTRIBUTE_UNUSED
)
828 cfun
->machine
->in_prologue
= 0;
831 /* Implement TARGET_MACHINE_DEPENDENT_REORG. No actual rearrangements
832 done here; just virtually by calculating the highest saved stack
833 register number used to modify the register numbers at output time. */
840 /* We put the number of the highest saved register-file register in a
841 location convenient for the call-patterns to output. Note that we
842 don't tell dwarf2 about these registers, since it can't restore them
844 for (regno
= MMIX_LAST_STACK_REGISTER_REGNUM
;
847 if ((df_regs_ever_live_p (regno
) && !call_used_regs
[regno
])
848 || (regno
== MMIX_FRAME_POINTER_REGNUM
&& frame_pointer_needed
))
851 /* Regardless of whether they're saved (they might be just read), we
852 mustn't include registers that carry parameters. We could scan the
853 insns to see whether they're actually used (and indeed do other less
854 trivial register usage analysis and transformations), but it seems
855 wasteful to optimize for unused parameter registers. As of
856 2002-04-30, df_regs_ever_live_p (n) seems to be set for only-reads too, but
857 that might change. */
858 if (!TARGET_ABI_GNU
&& regno
< crtl
->args
.info
.regs
- 1)
860 regno
= crtl
->args
.info
.regs
- 1;
862 /* We don't want to let this cause us to go over the limit and make
863 incoming parameter registers be misnumbered and treating the last
864 parameter register and incoming return value register call-saved.
865 Stop things at the unmodified scheme. */
866 if (regno
> MMIX_RETURN_VALUE_REGNUM
- 1)
867 regno
= MMIX_RETURN_VALUE_REGNUM
- 1;
870 cfun
->machine
->highest_saved_stack_register
= regno
;
873 /* TARGET_ASM_FUNCTION_EPILOGUE. */
876 mmix_target_asm_function_epilogue (FILE *stream
,
877 HOST_WIDE_INT locals_size ATTRIBUTE_UNUSED
)
879 /* Emit an \n for readability of the generated assembly. */
880 fputc ('\n', stream
);
883 /* TARGET_ASM_OUTPUT_MI_THUNK. */
886 mmix_asm_output_mi_thunk (FILE *stream
,
887 tree fndecl ATTRIBUTE_UNUSED
,
889 HOST_WIDE_INT vcall_offset ATTRIBUTE_UNUSED
,
892 /* If you define TARGET_STRUCT_VALUE_RTX that returns 0 (i.e. pass
893 location of structure to return as invisible first argument), you
894 need to tweak this code too. */
895 const char *regname
= reg_names
[MMIX_FIRST_INCOMING_ARG_REGNUM
];
897 if (delta
>= 0 && delta
< 65536)
898 fprintf (stream
, "\tINCL %s,%d\n", regname
, (int)delta
);
899 else if (delta
< 0 && delta
>= -255)
900 fprintf (stream
, "\tSUBU %s,%s,%d\n", regname
, regname
, (int)-delta
);
903 mmix_output_register_setting (stream
, 255, delta
, 1);
904 fprintf (stream
, "\tADDU %s,%s,$255\n", regname
, regname
);
907 fprintf (stream
, "\tJMP ");
908 assemble_name (stream
, XSTR (XEXP (DECL_RTL (func
), 0), 0));
909 fprintf (stream
, "\n");
912 /* FUNCTION_PROFILER. */
915 mmix_function_profiler (FILE *stream ATTRIBUTE_UNUSED
,
916 int labelno ATTRIBUTE_UNUSED
)
918 sorry ("function_profiler support for MMIX");
921 /* Worker function for TARGET_SETUP_INCOMING_VARARGS. For the moment,
922 let's stick to pushing argument registers on the stack. Later, we
923 can parse all arguments in registers, to improve performance. */
926 mmix_setup_incoming_varargs (cumulative_args_t args_so_farp_v
,
927 enum machine_mode mode
,
930 int second_time ATTRIBUTE_UNUSED
)
932 CUMULATIVE_ARGS
*args_so_farp
= get_cumulative_args (args_so_farp_v
);
934 /* The last named variable has been handled, but
935 args_so_farp has not been advanced for it. */
936 if (args_so_farp
->regs
+ 1 < MMIX_MAX_ARGS_IN_REGS
)
937 *pretend_sizep
= (MMIX_MAX_ARGS_IN_REGS
- (args_so_farp
->regs
+ 1)) * 8;
939 /* We assume that one argument takes up one register here. That should
940 be true until we start messing with multi-reg parameters. */
941 if ((7 + (MMIX_FUNCTION_ARG_SIZE (mode
, vartype
))) / 8 != 1)
942 internal_error ("MMIX Internal: Last named vararg would not fit in a register");
945 /* TARGET_ASM_TRAMPOLINE_TEMPLATE. */
948 mmix_asm_trampoline_template (FILE *stream
)
950 /* Read a value into the static-chain register and jump somewhere. The
951 static chain is stored at offset 16, and the function address is
952 stored at offset 24. */
954 fprintf (stream
, "\tGETA $255,1F\n\t");
955 fprintf (stream
, "LDOU %s,$255,0\n\t", reg_names
[MMIX_STATIC_CHAIN_REGNUM
]);
956 fprintf (stream
, "LDOU $255,$255,8\n\t");
957 fprintf (stream
, "GO $255,$255,0\n");
958 fprintf (stream
, "1H\tOCTA 0\n\t");
959 fprintf (stream
, "OCTA 0\n");
962 /* TARGET_TRAMPOLINE_INIT. */
963 /* Set the static chain and function pointer field in the trampoline.
964 We also SYNCID here to be sure (doesn't matter in the simulator, but
965 some day it will). */
968 mmix_trampoline_init (rtx m_tramp
, tree fndecl
, rtx static_chain
)
970 rtx fnaddr
= XEXP (DECL_RTL (fndecl
), 0);
973 emit_block_move (m_tramp
, assemble_trampoline_template (),
974 GEN_INT (2*UNITS_PER_WORD
), BLOCK_OP_NORMAL
);
976 mem
= adjust_address (m_tramp
, DImode
, 2*UNITS_PER_WORD
);
977 emit_move_insn (mem
, static_chain
);
978 mem
= adjust_address (m_tramp
, DImode
, 3*UNITS_PER_WORD
);
979 emit_move_insn (mem
, fnaddr
);
981 mem
= adjust_address (m_tramp
, DImode
, 0);
982 emit_insn (gen_sync_icache (mem
, GEN_INT (TRAMPOLINE_SIZE
- 1)));
985 /* We must exclude constant addresses that have an increment that is not a
986 multiple of four bytes because of restrictions of the GETA
987 instruction, unless TARGET_BASE_ADDRESSES. */
990 mmix_constant_address_p (rtx x
)
992 RTX_CODE code
= GET_CODE (x
);
994 /* When using "base addresses", anything constant goes. */
995 int constant_ok
= TARGET_BASE_ADDRESSES
!= 0;
1004 /* FIXME: Don't know how to dissect these. Avoid them for now,
1005 except we know they're constants. */
1009 addend
= INTVAL (x
);
1013 if (GET_MODE (x
) != VOIDmode
)
1014 /* Strange that we got here. FIXME: Check if we do. */
1016 addend
= CONST_DOUBLE_LOW (x
);
1020 /* Note that expressions with arithmetic on forward references don't
1021 work in mmixal. People using gcc assembly code with mmixal might
1022 need to move arrays and such to before the point of use. */
1023 if (GET_CODE (XEXP (x
, 0)) == PLUS
)
1025 rtx x0
= XEXP (XEXP (x
, 0), 0);
1026 rtx x1
= XEXP (XEXP (x
, 0), 1);
1028 if ((GET_CODE (x0
) == SYMBOL_REF
1029 || GET_CODE (x0
) == LABEL_REF
)
1030 && (GET_CODE (x1
) == CONST_INT
1031 || (GET_CODE (x1
) == CONST_DOUBLE
1032 && GET_MODE (x1
) == VOIDmode
)))
1033 addend
= mmix_intval (x1
);
1045 return constant_ok
|| (addend
& 3) == 0;
1048 /* Return 1 if the address is OK, otherwise 0. */
1051 mmix_legitimate_address_p (enum machine_mode mode ATTRIBUTE_UNUSED
,
1053 bool strict_checking
)
1055 #define MMIX_REG_OK(X) \
1057 && (REGNO (X) <= MMIX_LAST_GENERAL_REGISTER \
1058 || (reg_renumber[REGNO (X)] > 0 \
1059 && reg_renumber[REGNO (X)] <= MMIX_LAST_GENERAL_REGISTER))) \
1060 || (!strict_checking \
1061 && (REGNO (X) <= MMIX_LAST_GENERAL_REGISTER \
1062 || REGNO (X) >= FIRST_PSEUDO_REGISTER \
1063 || REGNO (X) == ARG_POINTER_REGNUM)))
1067 (mem (plus reg reg))
1068 (mem (plus reg 0..255)).
1069 unless TARGET_BASE_ADDRESSES, in which case we accept all
1070 (mem constant_address) too. */
1074 if (REG_P (x
) && MMIX_REG_OK (x
))
1077 if (GET_CODE(x
) == PLUS
)
1079 rtx x1
= XEXP (x
, 0);
1080 rtx x2
= XEXP (x
, 1);
1082 /* Try swapping the order. FIXME: Do we need this? */
1090 /* (mem (plus (reg?) (?))) */
1091 if (!REG_P (x1
) || !MMIX_REG_OK (x1
))
1092 return TARGET_BASE_ADDRESSES
&& mmix_constant_address_p (x
);
1094 /* (mem (plus (reg) (reg?))) */
1095 if (REG_P (x2
) && MMIX_REG_OK (x2
))
1098 /* (mem (plus (reg) (0..255?))) */
1099 if (satisfies_constraint_I (x2
))
1105 return TARGET_BASE_ADDRESSES
&& mmix_constant_address_p (x
);
1108 /* Implement TARGET_LEGITIMATE_CONSTANT_P. */
1111 mmix_legitimate_constant_p (enum machine_mode mode ATTRIBUTE_UNUSED
, rtx x
)
1113 RTX_CODE code
= GET_CODE (x
);
1115 /* We must allow any number due to the way the cse passes works; if we
1116 do not allow any number here, general_operand will fail, and insns
1117 will fatally fail recognition instead of "softly". */
1118 if (code
== CONST_INT
|| code
== CONST_DOUBLE
)
1121 return CONSTANT_ADDRESS_P (x
);
1124 /* SELECT_CC_MODE. */
1127 mmix_select_cc_mode (RTX_CODE op
, rtx x
, rtx y ATTRIBUTE_UNUSED
)
1129 /* We use CCmode, CC_UNSmode, CC_FPmode, CC_FPEQmode and CC_FUNmode to
1130 output different compare insns. Note that we do not check the
1131 validity of the comparison here. */
1133 if (GET_MODE_CLASS (GET_MODE (x
)) == MODE_FLOAT
)
1135 if (op
== ORDERED
|| op
== UNORDERED
|| op
== UNGE
1136 || op
== UNGT
|| op
== UNLE
|| op
== UNLT
)
1139 if (op
== EQ
|| op
== NE
)
1145 if (op
== GTU
|| op
== LTU
|| op
== GEU
|| op
== LEU
)
1151 /* REVERSIBLE_CC_MODE. */
1154 mmix_reversible_cc_mode (enum machine_mode mode
)
1156 /* That is, all integer and the EQ, NE, ORDERED and UNORDERED float
1158 return mode
!= CC_FPmode
;
1161 /* TARGET_RTX_COSTS. */
1164 mmix_rtx_costs (rtx x ATTRIBUTE_UNUSED
,
1165 int code ATTRIBUTE_UNUSED
,
1166 int outer_code ATTRIBUTE_UNUSED
,
1167 int opno ATTRIBUTE_UNUSED
,
1168 int *total ATTRIBUTE_UNUSED
,
1169 bool speed ATTRIBUTE_UNUSED
)
1171 /* For the time being, this is just a stub and we'll accept the
1172 generic calculations, until we can do measurements, at least.
1173 Say we did not modify any calculated costs. */
1177 /* TARGET_REGISTER_MOVE_COST.
1179 The special registers can only move to and from general regs, and we
1180 need to check that their constraints match, so say 3 for them. */
1183 mmix_register_move_cost (enum machine_mode mode ATTRIBUTE_UNUSED
,
1187 return (from
== GENERAL_REGS
&& from
== to
) ? 2 : 3;
1190 /* Note that we don't have a TEXT_SECTION_ASM_OP, because it has to be a
1191 compile-time constant; it's used in an asm in crtstuff.c, compiled for
1194 /* DATA_SECTION_ASM_OP. */
1197 mmix_data_section_asm_op (void)
1199 return "\t.data ! mmixal:= 8H LOC 9B";
1203 mmix_encode_section_info (tree decl
, rtx rtl
, int first
)
1205 /* Test for an external declaration, and do nothing if it is one. */
1206 if ((TREE_CODE (decl
) == VAR_DECL
1207 && (DECL_EXTERNAL (decl
) || TREE_PUBLIC (decl
)))
1208 || (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_PUBLIC (decl
)))
1210 else if (first
&& DECL_P (decl
))
1212 /* For non-visible declarations, add a "@" prefix, which we skip
1213 when the label is output. If the label does not have this
1214 prefix, a ":" is output if -mtoplevel-symbols.
1216 Note that this does not work for data that is declared extern and
1217 later defined as static. If there's code in between, that code
1218 will refer to the extern declaration, and vice versa. This just
1219 means that when -mtoplevel-symbols is in use, we can just handle
1220 well-behaved ISO-compliant code. */
1222 const char *str
= XSTR (XEXP (rtl
, 0), 0);
1223 int len
= strlen (str
);
1224 char *newstr
= XALLOCAVEC (char, len
+ 2);
1226 strcpy (newstr
+ 1, str
);
1227 XSTR (XEXP (rtl
, 0), 0) = ggc_alloc_string (newstr
, len
+ 1);
1230 /* Set SYMBOL_REF_FLAG for things that we want to access with GETA. We
1231 may need different options to reach for different things with GETA.
1232 For now, functions and things we know or have been told are constant. */
1233 if (TREE_CODE (decl
) == FUNCTION_DECL
1234 || TREE_CONSTANT (decl
)
1235 || (TREE_CODE (decl
) == VAR_DECL
1236 && TREE_READONLY (decl
)
1237 && !TREE_SIDE_EFFECTS (decl
)
1238 && (!DECL_INITIAL (decl
)
1239 || TREE_CONSTANT (DECL_INITIAL (decl
)))))
1240 SYMBOL_REF_FLAG (XEXP (rtl
, 0)) = 1;
1244 mmix_strip_name_encoding (const char *name
)
1246 for (; (*name
== '@' || *name
== '*'); name
++)
1252 /* TARGET_ASM_FILE_START.
1253 We just emit a little comment for the time being. */
1256 mmix_file_start (void)
1258 default_file_start ();
1260 fputs ("! mmixal:= 8H LOC Data_Section\n", asm_out_file
);
1262 /* Make sure each file starts with the text section. */
1263 switch_to_section (text_section
);
1266 /* TARGET_ASM_FILE_END. */
1269 mmix_file_end (void)
1271 /* Make sure each file ends with the data section. */
1272 switch_to_section (data_section
);
1275 /* TARGET_ASM_OUTPUT_SOURCE_FILENAME. */
1278 mmix_asm_output_source_filename (FILE *stream
, const char *name
)
1280 fprintf (stream
, "# 1 ");
1281 OUTPUT_QUOTED_STRING (stream
, name
);
1282 fprintf (stream
, "\n");
1285 /* OUTPUT_QUOTED_STRING. */
1288 mmix_output_quoted_string (FILE *stream
, const char *string
, int length
)
1290 const char * string_end
= string
+ length
;
1291 static const char *const unwanted_chars
= "\"[]\\";
1293 /* Output "any character except newline and double quote character". We
1294 play it safe and avoid all control characters too. We also do not
1295 want [] as characters, should input be passed through m4 with [] as
1296 quotes. Further, we avoid "\", because the GAS port handles it as a
1297 quoting character. */
1298 while (string
< string_end
)
1301 && (unsigned char) *string
< 128
1302 && !ISCNTRL (*string
)
1303 && strchr (unwanted_chars
, *string
) == NULL
)
1305 fputc ('"', stream
);
1307 && (unsigned char) *string
< 128
1308 && !ISCNTRL (*string
)
1309 && strchr (unwanted_chars
, *string
) == NULL
1310 && string
< string_end
)
1312 fputc (*string
, stream
);
1315 fputc ('"', stream
);
1316 if (string
< string_end
)
1317 fprintf (stream
, ",");
1319 if (string
< string_end
)
1321 fprintf (stream
, "#%x", *string
& 255);
1323 if (string
< string_end
)
1324 fprintf (stream
, ",");
1329 /* Target hook for assembling integer objects. Use mmix_print_operand
1330 for WYDE and TETRA. Use mmix_output_octa to output 8-byte
1334 mmix_assemble_integer (rtx x
, unsigned int size
, int aligned_p
)
1339 /* We handle a limited number of types of operands in here. But
1340 that's ok, because we can punt to generic functions. We then
1341 pretend that aligned data isn't needed, so the usual .<pseudo>
1342 syntax is used (which works for aligned data too). We actually
1343 *must* do that, since we say we don't have simple aligned
1344 pseudos, causing this function to be called. We just try and
1345 keep as much compatibility as possible with mmixal syntax for
1346 normal cases (i.e. without GNU extensions and C only). */
1348 if (GET_CODE (x
) != CONST_INT
)
1353 fputs ("\tBYTE\t", asm_out_file
);
1354 mmix_print_operand (asm_out_file
, x
, 'B');
1355 fputc ('\n', asm_out_file
);
1359 if (GET_CODE (x
) != CONST_INT
)
1364 fputs ("\tWYDE\t", asm_out_file
);
1365 mmix_print_operand (asm_out_file
, x
, 'W');
1366 fputc ('\n', asm_out_file
);
1370 if (GET_CODE (x
) != CONST_INT
)
1375 fputs ("\tTETRA\t", asm_out_file
);
1376 mmix_print_operand (asm_out_file
, x
, 'L');
1377 fputc ('\n', asm_out_file
);
1381 /* We don't get here anymore for CONST_DOUBLE, because DImode
1382 isn't expressed as CONST_DOUBLE, and DFmode is handled
1384 gcc_assert (GET_CODE (x
) != CONST_DOUBLE
);
1385 assemble_integer_with_op ("\tOCTA\t", x
);
1388 return default_assemble_integer (x
, size
, aligned_p
);
1391 /* ASM_OUTPUT_ASCII. */
1394 mmix_asm_output_ascii (FILE *stream
, const char *string
, int length
)
1398 int chunk_size
= length
> 60 ? 60 : length
;
1399 fprintf (stream
, "\tBYTE ");
1400 mmix_output_quoted_string (stream
, string
, chunk_size
);
1401 string
+= chunk_size
;
1402 length
-= chunk_size
;
1403 fprintf (stream
, "\n");
1407 /* ASM_OUTPUT_ALIGNED_COMMON. */
1410 mmix_asm_output_aligned_common (FILE *stream
,
1415 /* This is mostly the elfos.h one. There doesn't seem to be a way to
1416 express this in a mmixal-compatible way. */
1417 fprintf (stream
, "\t.comm\t");
1418 assemble_name (stream
, name
);
1419 fprintf (stream
, ",%u,%u ! mmixal-incompatible COMMON\n",
1420 size
, align
/ BITS_PER_UNIT
);
1423 /* ASM_OUTPUT_ALIGNED_LOCAL. */
1426 mmix_asm_output_aligned_local (FILE *stream
,
1431 switch_to_section (data_section
);
1433 ASM_OUTPUT_ALIGN (stream
, exact_log2 (align
/BITS_PER_UNIT
));
1434 assemble_name (stream
, name
);
1435 fprintf (stream
, "\tLOC @+%d\n", size
);
1438 /* ASM_OUTPUT_LABEL. */
1441 mmix_asm_output_label (FILE *stream
, const char *name
)
1443 assemble_name (stream
, name
);
1444 fprintf (stream
, "\tIS @\n");
1447 /* ASM_OUTPUT_INTERNAL_LABEL. */
1450 mmix_asm_output_internal_label (FILE *stream
, const char *name
)
1452 assemble_name_raw (stream
, name
);
1453 fprintf (stream
, "\tIS @\n");
1456 /* ASM_DECLARE_REGISTER_GLOBAL. */
1459 mmix_asm_declare_register_global (FILE *stream ATTRIBUTE_UNUSED
,
1460 tree decl ATTRIBUTE_UNUSED
,
1461 int regno ATTRIBUTE_UNUSED
,
1462 const char *name ATTRIBUTE_UNUSED
)
1464 /* Nothing to do here, but there *will* be, therefore the framework is
1468 /* ASM_WEAKEN_LABEL. */
1471 mmix_asm_weaken_label (FILE *stream ATTRIBUTE_UNUSED
,
1472 const char *name ATTRIBUTE_UNUSED
)
1474 fprintf (stream
, "\t.weak ");
1475 assemble_name (stream
, name
);
1476 fprintf (stream
, " ! mmixal-incompatible\n");
1479 /* MAKE_DECL_ONE_ONLY. */
1482 mmix_make_decl_one_only (tree decl
)
1484 DECL_WEAK (decl
) = 1;
1487 /* ASM_OUTPUT_LABELREF.
1488 Strip GCC's '*' and our own '@'. No order is assumed. */
1491 mmix_asm_output_labelref (FILE *stream
, const char *name
)
1495 for (; (*name
== '@' || *name
== '*'); name
++)
1499 asm_fprintf (stream
, "%s%U%s",
1500 is_extern
&& TARGET_TOPLEVEL_SYMBOLS
? ":" : "",
1504 /* ASM_OUTPUT_DEF. */
1507 mmix_asm_output_def (FILE *stream
, const char *name
, const char *value
)
1509 assemble_name (stream
, name
);
1510 fprintf (stream
, "\tIS ");
1511 assemble_name (stream
, value
);
1512 fputc ('\n', stream
);
1515 /* TARGET_PRINT_OPERAND. */
1518 mmix_print_operand (FILE *stream
, rtx x
, int code
)
1520 /* When we add support for different codes later, we can, when needed,
1521 drop through to the main handler with a modified operand. */
1523 int regno
= x
!= NULL_RTX
&& REG_P (x
) ? REGNO (x
) : 0;
1527 /* Unrelated codes are in alphabetic order. */
1530 /* For conditional branches, output "P" for a probable branch. */
1531 if (TARGET_BRANCH_PREDICT
)
1533 x
= find_reg_note (current_output_insn
, REG_BR_PROB
, 0);
1534 if (x
&& INTVAL (XEXP (x
, 0)) > REG_BR_PROB_BASE
/ 2)
1540 /* For the %d in POP %d,0. */
1541 fprintf (stream
, "%d", MMIX_POP_ARGUMENT ());
1545 if (GET_CODE (x
) != CONST_INT
)
1546 fatal_insn ("MMIX Internal: Expected a CONST_INT, not this", x
);
1547 fprintf (stream
, "%d", (int) (INTVAL (x
) & 0xff));
1551 /* Highpart. Must be general register, and not the last one, as
1552 that one cannot be part of a consecutive register pair. */
1553 if (regno
> MMIX_LAST_GENERAL_REGISTER
- 1)
1554 internal_error ("MMIX Internal: Bad register: %d", regno
);
1556 /* This is big-endian, so the high-part is the first one. */
1557 fprintf (stream
, "%s", reg_names
[MMIX_OUTPUT_REGNO (regno
)]);
1561 /* Lowpart. Must be CONST_INT or general register, and not the last
1562 one, as that one cannot be part of a consecutive register pair. */
1563 if (GET_CODE (x
) == CONST_INT
)
1565 fprintf (stream
, "#%lx",
1566 (unsigned long) (INTVAL (x
)
1567 & ((unsigned int) 0x7fffffff * 2 + 1)));
1571 if (GET_CODE (x
) == SYMBOL_REF
)
1573 output_addr_const (stream
, x
);
1577 if (regno
> MMIX_LAST_GENERAL_REGISTER
- 1)
1578 internal_error ("MMIX Internal: Bad register: %d", regno
);
1580 /* This is big-endian, so the low-part is + 1. */
1581 fprintf (stream
, "%s", reg_names
[MMIX_OUTPUT_REGNO (regno
) + 1]);
1584 /* Can't use 'a' because that's a generic modifier for address
1587 mmix_output_shiftvalue_op_from_str (stream
, "ANDN",
1588 ~(unsigned HOST_WIDEST_INT
)
1593 mmix_output_shiftvalue_op_from_str (stream
, "INC",
1594 (unsigned HOST_WIDEST_INT
)
1599 mmix_output_shiftvalue_op_from_str (stream
, "OR",
1600 (unsigned HOST_WIDEST_INT
)
1605 mmix_output_shiftvalue_op_from_str (stream
, "SET",
1606 (unsigned HOST_WIDEST_INT
)
1612 mmix_output_condition (stream
, x
, (code
== 'D'));
1616 /* Output an extra "e" to make fcmpe, fune. */
1617 if (TARGET_FCMP_EPSILON
)
1618 fprintf (stream
, "e");
1622 /* Output the number minus 1. */
1623 if (GET_CODE (x
) != CONST_INT
)
1625 fatal_insn ("MMIX Internal: Bad value for 'm', not a CONST_INT",
1628 fprintf (stream
, HOST_WIDEST_INT_PRINT_DEC
,
1629 (HOST_WIDEST_INT
) (mmix_intval (x
) - 1));
1633 /* Store the number of registers we want to save. This was setup
1634 by the prologue. The actual operand contains the number of
1635 registers to pass, but we don't use it currently. Anyway, we
1636 need to output the number of saved registers here. */
1637 fprintf (stream
, "%d",
1638 cfun
->machine
->highest_saved_stack_register
+ 1);
1642 /* Store the register to output a constant to. */
1644 fatal_insn ("MMIX Internal: Expected a register, not this", x
);
1645 mmix_output_destination_register
= MMIX_OUTPUT_REGNO (regno
);
1649 /* Output the constant. Note that we use this for floats as well. */
1650 if (GET_CODE (x
) != CONST_INT
1651 && (GET_CODE (x
) != CONST_DOUBLE
1652 || (GET_MODE (x
) != VOIDmode
&& GET_MODE (x
) != DFmode
1653 && GET_MODE (x
) != SFmode
)))
1654 fatal_insn ("MMIX Internal: Expected a constant, not this", x
);
1655 mmix_output_register_setting (stream
,
1656 mmix_output_destination_register
,
1657 mmix_intval (x
), 0);
1661 /* An U for unsigned, if TARGET_ZERO_EXTEND. Ignore the operand. */
1662 if (TARGET_ZERO_EXTEND
)
1667 mmix_output_shifted_value (stream
, (HOST_WIDEST_INT
) mmix_intval (x
));
1671 mmix_output_shifted_value (stream
, (HOST_WIDEST_INT
) ~mmix_intval (x
));
1675 if (GET_CODE (x
) != CONST_INT
)
1676 fatal_insn ("MMIX Internal: Expected a CONST_INT, not this", x
);
1677 fprintf (stream
, "#%x", (int) (INTVAL (x
) & 0xffff));
1681 /* Nothing to do. */
1685 /* Presumably there's a missing case above if we get here. */
1686 internal_error ("MMIX Internal: Missing %qc case in mmix_print_operand", code
);
1689 switch (GET_CODE (modified_x
))
1692 regno
= REGNO (modified_x
);
1693 if (regno
>= FIRST_PSEUDO_REGISTER
)
1694 internal_error ("MMIX Internal: Bad register: %d", regno
);
1695 fprintf (stream
, "%s", reg_names
[MMIX_OUTPUT_REGNO (regno
)]);
1699 output_address (XEXP (modified_x
, 0));
1703 /* For -2147483648, mmixal complains that the constant does not fit
1704 in 4 bytes, so let's output it as hex. Take care to handle hosts
1705 where HOST_WIDE_INT is longer than an int.
1707 Print small constants +-255 using decimal. */
1709 if (INTVAL (modified_x
) > -256 && INTVAL (modified_x
) < 256)
1710 fprintf (stream
, "%d", (int) (INTVAL (modified_x
)));
1712 fprintf (stream
, "#%x",
1713 (int) (INTVAL (modified_x
)) & (unsigned int) ~0);
1717 /* Do somewhat as CONST_INT. */
1718 mmix_output_octa (stream
, mmix_intval (modified_x
), 0);
1722 output_addr_const (stream
, modified_x
);
1726 /* No need to test for all strange things. Let output_addr_const do
1728 if (CONSTANT_P (modified_x
)
1729 /* Strangely enough, this is not included in CONSTANT_P.
1730 FIXME: Ask/check about sanity here. */
1731 || GET_CODE (modified_x
) == CODE_LABEL
)
1733 output_addr_const (stream
, modified_x
);
1737 /* We need the original here. */
1738 fatal_insn ("MMIX Internal: Cannot decode this operand", x
);
1742 /* TARGET_PRINT_OPERAND_PUNCT_VALID_P. */
1745 mmix_print_operand_punct_valid_p (unsigned char code
)
1747 /* A '+' is used for branch prediction, similar to other ports. */
1749 /* A '.' is used for the %d in the POP %d,0 return insn. */
1753 /* TARGET_PRINT_OPERAND_ADDRESS. */
1756 mmix_print_operand_address (FILE *stream
, rtx x
)
1760 /* I find the generated assembly code harder to read without
1762 fprintf (stream
, "%s,0", reg_names
[MMIX_OUTPUT_REGNO (REGNO (x
))]);
1765 else if (GET_CODE (x
) == PLUS
)
1767 rtx x1
= XEXP (x
, 0);
1768 rtx x2
= XEXP (x
, 1);
1772 fprintf (stream
, "%s,", reg_names
[MMIX_OUTPUT_REGNO (REGNO (x1
))]);
1776 fprintf (stream
, "%s",
1777 reg_names
[MMIX_OUTPUT_REGNO (REGNO (x2
))]);
1780 else if (satisfies_constraint_I (x2
))
1782 output_addr_const (stream
, x2
);
1788 if (TARGET_BASE_ADDRESSES
&& mmix_legitimate_constant_p (Pmode
, x
))
1790 output_addr_const (stream
, x
);
1794 fatal_insn ("MMIX Internal: This is not a recognized address", x
);
1797 /* ASM_OUTPUT_REG_PUSH. */
1800 mmix_asm_output_reg_push (FILE *stream
, int regno
)
1802 fprintf (stream
, "\tSUBU %s,%s,8\n\tSTOU %s,%s,0\n",
1803 reg_names
[MMIX_STACK_POINTER_REGNUM
],
1804 reg_names
[MMIX_STACK_POINTER_REGNUM
],
1805 reg_names
[MMIX_OUTPUT_REGNO (regno
)],
1806 reg_names
[MMIX_STACK_POINTER_REGNUM
]);
1809 /* ASM_OUTPUT_REG_POP. */
1812 mmix_asm_output_reg_pop (FILE *stream
, int regno
)
1814 fprintf (stream
, "\tLDOU %s,%s,0\n\tINCL %s,8\n",
1815 reg_names
[MMIX_OUTPUT_REGNO (regno
)],
1816 reg_names
[MMIX_STACK_POINTER_REGNUM
],
1817 reg_names
[MMIX_STACK_POINTER_REGNUM
]);
1820 /* ASM_OUTPUT_ADDR_DIFF_ELT. */
1823 mmix_asm_output_addr_diff_elt (FILE *stream
,
1824 rtx body ATTRIBUTE_UNUSED
,
1828 fprintf (stream
, "\tTETRA L%d-L%d\n", value
, rel
);
1831 /* ASM_OUTPUT_ADDR_VEC_ELT. */
1834 mmix_asm_output_addr_vec_elt (FILE *stream
, int value
)
1836 fprintf (stream
, "\tOCTA L:%d\n", value
);
1839 /* ASM_OUTPUT_SKIP. */
1842 mmix_asm_output_skip (FILE *stream
, int nbytes
)
1844 fprintf (stream
, "\tLOC @+%d\n", nbytes
);
1847 /* ASM_OUTPUT_ALIGN. */
1850 mmix_asm_output_align (FILE *stream
, int power
)
1852 /* We need to record the needed alignment of this section in the object,
1853 so we have to output an alignment directive. Use a .p2align (not
1854 .align) so people will never have to wonder about whether the
1855 argument is in number of bytes or the log2 thereof. We do it in
1856 addition to the LOC directive, so nothing needs tweaking when
1857 copy-pasting assembly into mmixal. */
1858 fprintf (stream
, "\t.p2align %d\n", power
);
1859 fprintf (stream
, "\tLOC @+(%d-@)&%d\n", 1 << power
, (1 << power
) - 1);
1862 /* DBX_REGISTER_NUMBER. */
1865 mmix_dbx_register_number (unsigned regno
)
1867 /* Adjust the register number to the one it will be output as, dammit.
1868 It'd be nice if we could check the assumption that we're filling a
1869 gap, but every register between the last saved register and parameter
1870 registers might be a valid parameter register. */
1871 regno
= MMIX_OUTPUT_REGNO (regno
);
1873 /* We need to renumber registers to get the number of the return address
1874 register in the range 0..255. It is also space-saving if registers
1875 mentioned in the call-frame information (which uses this function by
1876 defaulting DWARF_FRAME_REGNUM to DBX_REGISTER_NUMBER) are numbered
1877 0 .. 63. So map 224 .. 256+15 -> 0 .. 47 and 0 .. 223 -> 48..223+48. */
1878 return regno
>= 224 ? (regno
- 224) : (regno
+ 48);
1881 /* End of target macro support functions.
1883 Now the MMIX port's own functions. First the exported ones. */
1885 /* Wrapper for get_hard_reg_initial_val since integrate.h isn't included
1886 from insn-emit.c. */
1889 mmix_get_hard_reg_initial_val (enum machine_mode mode
, int regno
)
1891 return get_hard_reg_initial_val (mode
, regno
);
1894 /* Nonzero when the function epilogue is simple enough that a single
1895 "POP %d,0" should be used even within the function. */
1898 mmix_use_simple_return (void)
1902 int stack_space_to_allocate
1903 = (crtl
->outgoing_args_size
1904 + crtl
->args
.pretend_args_size
1905 + get_frame_size () + 7) & ~7;
1907 if (!TARGET_USE_RETURN_INSN
|| !reload_completed
)
1911 regno
>= MMIX_FIRST_GLOBAL_REGNUM
;
1913 /* Note that we assume that the frame-pointer-register is one of these
1914 registers, in which case we don't count it here. */
1915 if ((((regno
!= MMIX_FRAME_POINTER_REGNUM
|| !frame_pointer_needed
)
1916 && df_regs_ever_live_p (regno
) && !call_used_regs
[regno
]))
1917 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
1920 if (frame_pointer_needed
)
1921 stack_space_to_allocate
+= 8;
1923 if (MMIX_CFUN_HAS_LANDING_PAD
)
1924 stack_space_to_allocate
+= 16;
1925 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
)
1926 stack_space_to_allocate
+= 8;
1928 return stack_space_to_allocate
== 0;
1932 /* Expands the function prologue into RTX. */
1935 mmix_expand_prologue (void)
1937 HOST_WIDE_INT locals_size
= get_frame_size ();
1939 HOST_WIDE_INT stack_space_to_allocate
1940 = (crtl
->outgoing_args_size
1941 + crtl
->args
.pretend_args_size
1942 + locals_size
+ 7) & ~7;
1943 HOST_WIDE_INT offset
= -8;
1945 /* Add room needed to save global non-register-stack registers. */
1947 regno
>= MMIX_FIRST_GLOBAL_REGNUM
;
1949 /* Note that we assume that the frame-pointer-register is one of these
1950 registers, in which case we don't count it here. */
1951 if ((((regno
!= MMIX_FRAME_POINTER_REGNUM
|| !frame_pointer_needed
)
1952 && df_regs_ever_live_p (regno
) && !call_used_regs
[regno
]))
1953 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
1954 stack_space_to_allocate
+= 8;
1956 /* If we do have a frame-pointer, add room for it. */
1957 if (frame_pointer_needed
)
1958 stack_space_to_allocate
+= 8;
1960 /* If we have a non-local label, we need to be able to unwind to it, so
1961 store the current register stack pointer. Also store the return
1962 address if we do that. */
1963 if (MMIX_CFUN_HAS_LANDING_PAD
)
1964 stack_space_to_allocate
+= 16;
1965 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
)
1966 /* If we do have a saved return-address slot, add room for it. */
1967 stack_space_to_allocate
+= 8;
1969 /* Make sure we don't get an unaligned stack. */
1970 if ((stack_space_to_allocate
% 8) != 0)
1971 internal_error ("stack frame not a multiple of 8 bytes: %wd",
1972 stack_space_to_allocate
);
1974 if (crtl
->args
.pretend_args_size
)
1976 int mmix_first_vararg_reg
1977 = (MMIX_FIRST_INCOMING_ARG_REGNUM
1978 + (MMIX_MAX_ARGS_IN_REGS
1979 - crtl
->args
.pretend_args_size
/ 8));
1982 = MMIX_FIRST_INCOMING_ARG_REGNUM
+ MMIX_MAX_ARGS_IN_REGS
- 1;
1983 regno
>= mmix_first_vararg_reg
;
1988 HOST_WIDE_INT stack_chunk
1989 = stack_space_to_allocate
> (256 - 8)
1990 ? (256 - 8) : stack_space_to_allocate
;
1992 mmix_emit_sp_add (-stack_chunk
);
1993 offset
+= stack_chunk
;
1994 stack_space_to_allocate
-= stack_chunk
;
1997 /* These registers aren't actually saved (as in "will be
1998 restored"), so don't tell DWARF2 they're saved. */
1999 emit_move_insn (gen_rtx_MEM (DImode
,
2000 plus_constant (Pmode
, stack_pointer_rtx
,
2002 gen_rtx_REG (DImode
, regno
));
2007 /* Store the frame-pointer. */
2009 if (frame_pointer_needed
)
2015 /* Get 8 less than otherwise, since we need to reach offset + 8. */
2016 HOST_WIDE_INT stack_chunk
2017 = stack_space_to_allocate
> (256 - 8 - 8)
2018 ? (256 - 8 - 8) : stack_space_to_allocate
;
2020 mmix_emit_sp_add (-stack_chunk
);
2022 offset
+= stack_chunk
;
2023 stack_space_to_allocate
-= stack_chunk
;
2026 insn
= emit_move_insn (gen_rtx_MEM (DImode
,
2027 plus_constant (Pmode
,
2030 hard_frame_pointer_rtx
);
2031 RTX_FRAME_RELATED_P (insn
) = 1;
2032 insn
= emit_insn (gen_adddi3 (hard_frame_pointer_rtx
,
2034 GEN_INT (offset
+ 8)));
2035 RTX_FRAME_RELATED_P (insn
) = 1;
2039 if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
)
2044 /* Store the return-address, if one is needed on the stack. We
2045 usually store it in a register when needed, but that doesn't work
2046 with -fexceptions. */
2050 /* Get 8 less than otherwise, since we need to reach offset + 8. */
2051 HOST_WIDE_INT stack_chunk
2052 = stack_space_to_allocate
> (256 - 8 - 8)
2053 ? (256 - 8 - 8) : stack_space_to_allocate
;
2055 mmix_emit_sp_add (-stack_chunk
);
2057 offset
+= stack_chunk
;
2058 stack_space_to_allocate
-= stack_chunk
;
2061 tmpreg
= gen_rtx_REG (DImode
, 255);
2062 retreg
= gen_rtx_REG (DImode
, MMIX_rJ_REGNUM
);
2064 /* Dwarf2 code is confused by the use of a temporary register for
2065 storing the return address, so we have to express it as a note,
2066 which we attach to the actual store insn. */
2067 emit_move_insn (tmpreg
, retreg
);
2069 insn
= emit_move_insn (gen_rtx_MEM (DImode
,
2070 plus_constant (Pmode
,
2074 RTX_FRAME_RELATED_P (insn
) = 1;
2075 add_reg_note (insn
, REG_FRAME_RELATED_EXPR
,
2076 gen_rtx_SET (VOIDmode
,
2077 gen_rtx_MEM (DImode
,
2078 plus_constant (Pmode
,
2085 else if (MMIX_CFUN_HAS_LANDING_PAD
)
2088 if (MMIX_CFUN_HAS_LANDING_PAD
)
2090 /* Store the register defining the numbering of local registers, so
2091 we know how long to unwind the register stack. */
2095 /* Get 8 less than otherwise, since we need to reach offset + 8. */
2096 HOST_WIDE_INT stack_chunk
2097 = stack_space_to_allocate
> (256 - 8 - 8)
2098 ? (256 - 8 - 8) : stack_space_to_allocate
;
2100 mmix_emit_sp_add (-stack_chunk
);
2102 offset
+= stack_chunk
;
2103 stack_space_to_allocate
-= stack_chunk
;
2106 /* We don't tell dwarf2 about this one; we just have it to unwind
2107 the register stack at landing pads. FIXME: It's a kludge because
2108 we can't describe the effect of the PUSHJ and PUSHGO insns on the
2109 register stack at the moment. Best thing would be to handle it
2110 like stack-pointer offsets. Better: some hook into dwarf2out.c
2111 to produce DW_CFA_expression:s that specify the increment of rO,
2112 and unwind it at eh_return (preferred) or at the landing pad.
2113 Then saves to $0..$G-1 could be specified through that register. */
2115 emit_move_insn (gen_rtx_REG (DImode
, 255),
2116 gen_rtx_REG (DImode
,
2118 emit_move_insn (gen_rtx_MEM (DImode
,
2119 plus_constant (Pmode
, stack_pointer_rtx
,
2121 gen_rtx_REG (DImode
, 255));
2125 /* After the return-address and the frame-pointer, we have the local
2126 variables. They're the ones that may have an "unaligned" size. */
2127 offset
-= (locals_size
+ 7) & ~7;
2129 /* Now store all registers that are global, i.e. not saved by the
2130 register file machinery.
2132 It is assumed that the frame-pointer is one of these registers, so it
2133 is explicitly excluded in the count. */
2136 regno
>= MMIX_FIRST_GLOBAL_REGNUM
;
2138 if (((regno
!= MMIX_FRAME_POINTER_REGNUM
|| !frame_pointer_needed
)
2139 && df_regs_ever_live_p (regno
) && ! call_used_regs
[regno
])
2140 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
2146 HOST_WIDE_INT stack_chunk
2147 = (stack_space_to_allocate
> (256 - offset
- 8)
2148 ? (256 - offset
- 8) : stack_space_to_allocate
);
2150 mmix_emit_sp_add (-stack_chunk
);
2151 offset
+= stack_chunk
;
2152 stack_space_to_allocate
-= stack_chunk
;
2155 insn
= emit_move_insn (gen_rtx_MEM (DImode
,
2156 plus_constant (Pmode
,
2159 gen_rtx_REG (DImode
, regno
));
2160 RTX_FRAME_RELATED_P (insn
) = 1;
2164 /* Finally, allocate room for outgoing args and local vars if room
2165 wasn't allocated above. */
2166 if (stack_space_to_allocate
)
2167 mmix_emit_sp_add (-stack_space_to_allocate
);
2170 /* Expands the function epilogue into RTX. */
2173 mmix_expand_epilogue (void)
2175 HOST_WIDE_INT locals_size
= get_frame_size ();
2177 HOST_WIDE_INT stack_space_to_deallocate
2178 = (crtl
->outgoing_args_size
2179 + crtl
->args
.pretend_args_size
2180 + locals_size
+ 7) & ~7;
2182 /* The first address to access is beyond the outgoing_args area. */
2183 HOST_WIDE_INT offset
= crtl
->outgoing_args_size
;
2185 /* Add the space for global non-register-stack registers.
2186 It is assumed that the frame-pointer register can be one of these
2187 registers, in which case it is excluded from the count when needed. */
2189 regno
>= MMIX_FIRST_GLOBAL_REGNUM
;
2191 if (((regno
!= MMIX_FRAME_POINTER_REGNUM
|| !frame_pointer_needed
)
2192 && df_regs_ever_live_p (regno
) && !call_used_regs
[regno
])
2193 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
2194 stack_space_to_deallocate
+= 8;
2196 /* Add in the space for register stack-pointer. If so, always add room
2197 for the saved PC. */
2198 if (MMIX_CFUN_HAS_LANDING_PAD
)
2199 stack_space_to_deallocate
+= 16;
2200 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
)
2201 /* If we have a saved return-address slot, add it in. */
2202 stack_space_to_deallocate
+= 8;
2204 /* Add in the frame-pointer. */
2205 if (frame_pointer_needed
)
2206 stack_space_to_deallocate
+= 8;
2208 /* Make sure we don't get an unaligned stack. */
2209 if ((stack_space_to_deallocate
% 8) != 0)
2210 internal_error ("stack frame not a multiple of octabyte: %wd",
2211 stack_space_to_deallocate
);
2213 /* We will add back small offsets to the stack pointer as we go.
2214 First, we restore all registers that are global, i.e. not saved by
2215 the register file machinery. */
2217 for (regno
= MMIX_FIRST_GLOBAL_REGNUM
;
2220 if (((regno
!= MMIX_FRAME_POINTER_REGNUM
|| !frame_pointer_needed
)
2221 && df_regs_ever_live_p (regno
) && !call_used_regs
[regno
])
2222 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
2226 mmix_emit_sp_add (offset
);
2227 stack_space_to_deallocate
-= offset
;
2231 emit_move_insn (gen_rtx_REG (DImode
, regno
),
2232 gen_rtx_MEM (DImode
,
2233 plus_constant (Pmode
, stack_pointer_rtx
,
2238 /* Here is where the local variables were. As in the prologue, they
2239 might be of an unaligned size. */
2240 offset
+= (locals_size
+ 7) & ~7;
2242 /* The saved register stack pointer is just below the frame-pointer
2243 register. We don't need to restore it "manually"; the POP
2244 instruction does that. */
2245 if (MMIX_CFUN_HAS_LANDING_PAD
)
2247 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
)
2248 /* The return-address slot is just below the frame-pointer register.
2249 We don't need to restore it because we don't really use it. */
2252 /* Get back the old frame-pointer-value. */
2253 if (frame_pointer_needed
)
2257 mmix_emit_sp_add (offset
);
2259 stack_space_to_deallocate
-= offset
;
2263 emit_move_insn (hard_frame_pointer_rtx
,
2264 gen_rtx_MEM (DImode
,
2265 plus_constant (Pmode
, stack_pointer_rtx
,
2270 /* We do not need to restore pretended incoming args, just add back
2272 if (stack_space_to_deallocate
!= 0)
2273 mmix_emit_sp_add (stack_space_to_deallocate
);
2275 if (crtl
->calls_eh_return
)
2276 /* Adjust the (normal) stack-pointer to that of the receiver.
2277 FIXME: It would be nice if we could also adjust the register stack
2278 here, but we need to express it through DWARF 2 too. */
2279 emit_insn (gen_adddi3 (stack_pointer_rtx
, stack_pointer_rtx
,
2280 gen_rtx_REG (DImode
,
2281 MMIX_EH_RETURN_STACKADJ_REGNUM
)));
2284 /* Output an optimal sequence for setting a register to a specific
2285 constant. Used in an alternative for const_ints in movdi, and when
2286 using large stack-frame offsets.
2288 Use do_begin_end to say if a line-starting TAB and newline before the
2289 first insn and after the last insn is wanted. */
2292 mmix_output_register_setting (FILE *stream
,
2294 HOST_WIDEST_INT value
,
2298 fprintf (stream
, "\t");
2300 if (insn_const_int_ok_for_constraint (value
, CONSTRAINT_K
))
2301 fprintf (stream
, "NEGU %s,0," HOST_WIDEST_INT_PRINT_DEC
, reg_names
[regno
], -value
);
2302 else if (mmix_shiftable_wyde_value ((unsigned HOST_WIDEST_INT
) value
))
2304 /* First, the one-insn cases. */
2305 mmix_output_shiftvalue_op_from_str (stream
, "SET",
2306 (unsigned HOST_WIDEST_INT
)
2308 fprintf (stream
, " %s,", reg_names
[regno
]);
2309 mmix_output_shifted_value (stream
, (unsigned HOST_WIDEST_INT
) value
);
2311 else if (mmix_shiftable_wyde_value (-(unsigned HOST_WIDEST_INT
) value
))
2313 /* We do this to get a bit more legible assembly code. The next
2314 alternative is mostly redundant with this. */
2316 mmix_output_shiftvalue_op_from_str (stream
, "SET",
2317 -(unsigned HOST_WIDEST_INT
)
2319 fprintf (stream
, " %s,", reg_names
[regno
]);
2320 mmix_output_shifted_value (stream
, -(unsigned HOST_WIDEST_INT
) value
);
2321 fprintf (stream
, "\n\tNEGU %s,0,%s", reg_names
[regno
],
2324 else if (mmix_shiftable_wyde_value (~(unsigned HOST_WIDEST_INT
) value
))
2326 /* Slightly more expensive, the two-insn cases. */
2328 /* FIXME: We could of course also test if 0..255-N or ~(N | 1..255)
2329 is shiftable, or any other one-insn transformation of the value.
2330 FIXME: Check first if the value is "shiftable" by two loading
2331 with two insns, since it makes more readable assembly code (if
2332 anyone else cares). */
2334 mmix_output_shiftvalue_op_from_str (stream
, "SET",
2335 ~(unsigned HOST_WIDEST_INT
)
2337 fprintf (stream
, " %s,", reg_names
[regno
]);
2338 mmix_output_shifted_value (stream
, ~(unsigned HOST_WIDEST_INT
) value
);
2339 fprintf (stream
, "\n\tNOR %s,%s,0", reg_names
[regno
],
2344 /* The generic case. 2..4 insns. */
2345 static const char *const higher_parts
[] = {"L", "ML", "MH", "H"};
2346 const char *op
= "SET";
2347 const char *line_begin
= "";
2350 HOST_WIDEST_INT tmpvalue
= value
;
2352 /* Compute the number of insns needed to output this constant. */
2353 for (i
= 0; i
< 4 && tmpvalue
!= 0; i
++)
2355 if (tmpvalue
& 65535)
2359 if (TARGET_BASE_ADDRESSES
&& insns
== 3)
2361 /* The number three is based on a static observation on
2362 ghostscript-6.52. Two and four are excluded because there
2363 are too many such constants, and each unique constant (maybe
2364 offset by 1..255) were used few times compared to other uses,
2367 We use base-plus-offset addressing to force it into a global
2368 register; we just use a "LDA reg,VALUE", which will cause the
2369 assembler and linker to DTRT (for constants as well as
2371 fprintf (stream
, "LDA %s,", reg_names
[regno
]);
2372 mmix_output_octa (stream
, value
, 0);
2376 /* Output pertinent parts of the 4-wyde sequence.
2377 Still more to do if we want this to be optimal, but hey...
2378 Note that the zero case has been handled above. */
2379 for (i
= 0; i
< 4 && value
!= 0; i
++)
2383 fprintf (stream
, "%s%s%s %s,#%x", line_begin
, op
,
2384 higher_parts
[i
], reg_names
[regno
],
2385 (int) (value
& 65535));
2386 /* The first one sets the rest of the bits to 0, the next
2387 ones add set bits. */
2389 line_begin
= "\n\t";
2398 fprintf (stream
, "\n");
2401 /* Return 1 if value is 0..65535*2**(16*N) for N=0..3.
2405 mmix_shiftable_wyde_value (unsigned HOST_WIDEST_INT value
)
2407 /* Shift by 16 bits per group, stop when we've found two groups with
2410 int has_candidate
= 0;
2412 for (i
= 0; i
< 4; i
++)
2428 /* X and Y are two things to compare using CODE. Return the rtx for
2429 the cc-reg in the proper mode. */
2432 mmix_gen_compare_reg (RTX_CODE code
, rtx x
, rtx y
)
2434 enum machine_mode ccmode
= SELECT_CC_MODE (code
, x
, y
);
2435 return gen_reg_rtx (ccmode
);
2438 /* Local (static) helper functions. */
2441 mmix_emit_sp_add (HOST_WIDE_INT offset
)
2447 /* Negative stack-pointer adjustments are allocations and appear in
2448 the prologue only. We mark them as frame-related so unwind and
2449 debug info is properly emitted for them. */
2451 insn
= emit_insn (gen_adddi3 (stack_pointer_rtx
,
2456 rtx tmpr
= gen_rtx_REG (DImode
, 255);
2457 RTX_FRAME_RELATED_P (emit_move_insn (tmpr
, GEN_INT (offset
))) = 1;
2458 insn
= emit_insn (gen_adddi3 (stack_pointer_rtx
,
2459 stack_pointer_rtx
, tmpr
));
2461 RTX_FRAME_RELATED_P (insn
) = 1;
2465 /* Positive adjustments are in the epilogue only. Don't mark them
2466 as "frame-related" for unwind info. */
2467 if (insn_const_int_ok_for_constraint (offset
, CONSTRAINT_L
))
2468 emit_insn (gen_adddi3 (stack_pointer_rtx
,
2473 rtx tmpr
= gen_rtx_REG (DImode
, 255);
2474 emit_move_insn (tmpr
, GEN_INT (offset
));
2475 insn
= emit_insn (gen_adddi3 (stack_pointer_rtx
,
2476 stack_pointer_rtx
, tmpr
));
2481 /* Print operator suitable for doing something with a shiftable
2482 wyde. The type of operator is passed as an asm output modifier. */
2485 mmix_output_shiftvalue_op_from_str (FILE *stream
,
2487 HOST_WIDEST_INT value
)
2489 static const char *const op_part
[] = {"L", "ML", "MH", "H"};
2492 if (! mmix_shiftable_wyde_value (value
))
2494 char s
[sizeof ("0xffffffffffffffff")];
2495 sprintf (s
, HOST_WIDEST_INT_PRINT_HEX
, value
);
2496 internal_error ("MMIX Internal: %s is not a shiftable int", s
);
2499 for (i
= 0; i
< 4; i
++)
2501 /* We know we're through when we find one-bits in the low
2505 fprintf (stream
, "%s%s", mainop
, op_part
[i
]);
2511 /* No bits set? Then it must have been zero. */
2512 fprintf (stream
, "%sL", mainop
);
2515 /* Print a 64-bit value, optionally prefixed by assembly pseudo. */
2518 mmix_output_octa (FILE *stream
, HOST_WIDEST_INT value
, int do_begin_end
)
2521 fprintf (stream
, "\tOCTA ");
2523 /* Provide a few alternative output formats depending on the number, to
2524 improve legibility of assembler output. */
2525 if ((value
< (HOST_WIDEST_INT
) 0 && value
> (HOST_WIDEST_INT
) -10000)
2526 || (value
>= (HOST_WIDEST_INT
) 0 && value
<= (HOST_WIDEST_INT
) 16384))
2527 fprintf (stream
, "%d", (int) value
);
2528 else if (value
> (HOST_WIDEST_INT
) 0
2529 && value
< ((HOST_WIDEST_INT
) 1 << 31) * 2)
2530 fprintf (stream
, "#%x", (unsigned int) value
);
2531 else if (sizeof (HOST_WIDE_INT
) == sizeof (HOST_WIDEST_INT
))
2532 /* We need to avoid the not-so-universal "0x" prefix; we need the
2533 pure hex-digits together with the mmixal "#" hex prefix. */
2534 fprintf (stream
, "#" HOST_WIDE_INT_PRINT_HEX_PURE
,
2535 (HOST_WIDE_INT
) value
);
2536 else /* Need to avoid the hex output; there's no ...WIDEST...HEX_PURE. */
2537 fprintf (stream
, HOST_WIDEST_INT_PRINT_UNSIGNED
, value
);
2540 fprintf (stream
, "\n");
2543 /* Print the presumed shiftable wyde argument shifted into place (to
2544 be output with an operand). */
2547 mmix_output_shifted_value (FILE *stream
, HOST_WIDEST_INT value
)
2551 if (! mmix_shiftable_wyde_value (value
))
2554 sprintf (s
, HOST_WIDEST_INT_PRINT_HEX
, value
);
2555 internal_error ("MMIX Internal: %s is not a shiftable int", s
);
2558 for (i
= 0; i
< 4; i
++)
2560 /* We know we're through when we find one-bits in the low 16 bits. */
2563 fprintf (stream
, "#%x", (int) (value
& 0xffff));
2570 /* No bits set? Then it must have been zero. */
2571 fprintf (stream
, "0");
2574 /* Output an MMIX condition name corresponding to an operator
2576 (comparison_operator [(comparison_operator ...) (const_int 0)])
2577 which means we have to look at *two* operators.
2579 The argument "reversed" refers to reversal of the condition (not the
2580 same as swapping the arguments). */
2583 mmix_output_condition (FILE *stream
, const_rtx x
, int reversed
)
2589 /* The normal output cc-code. */
2590 const char *const normal
;
2592 /* The reversed cc-code, or NULL if invalid. */
2593 const char *const reversed
;
2598 enum machine_mode cc_mode
;
2600 /* Terminated with {UNKNOWN, NULL, NULL} */
2601 const struct cc_conv
*const convs
;
2605 #define CCEND {UNKNOWN, NULL, NULL}
2607 static const struct cc_conv cc_fun_convs
[]
2608 = {{ORDERED
, "Z", "P"},
2609 {UNORDERED
, "P", "Z"},
2611 static const struct cc_conv cc_fp_convs
[]
2615 static const struct cc_conv cc_fpeq_convs
[]
2619 static const struct cc_conv cc_uns_convs
[]
2620 = {{GEU
, "NN", "N"},
2625 static const struct cc_conv cc_signed_convs
[]
2633 static const struct cc_conv cc_di_convs
[]
2645 static const struct cc_type_conv cc_convs
[]
2646 = {{CC_FUNmode
, cc_fun_convs
},
2647 {CC_FPmode
, cc_fp_convs
},
2648 {CC_FPEQmode
, cc_fpeq_convs
},
2649 {CC_UNSmode
, cc_uns_convs
},
2650 {CCmode
, cc_signed_convs
},
2651 {DImode
, cc_di_convs
}};
2656 enum machine_mode mode
= GET_MODE (XEXP (x
, 0));
2657 RTX_CODE cc
= GET_CODE (x
);
2659 for (i
= 0; i
< ARRAY_SIZE (cc_convs
); i
++)
2661 if (mode
== cc_convs
[i
].cc_mode
)
2663 for (j
= 0; cc_convs
[i
].convs
[j
].cc
!= UNKNOWN
; j
++)
2664 if (cc
== cc_convs
[i
].convs
[j
].cc
)
2667 = (reversed
? cc_convs
[i
].convs
[j
].reversed
2668 : cc_convs
[i
].convs
[j
].normal
);
2670 if (mmix_cc
== NULL
)
2671 fatal_insn ("MMIX Internal: Trying to output invalidly\
2672 reversed condition:", x
);
2674 fprintf (stream
, "%s", mmix_cc
);
2678 fatal_insn ("MMIX Internal: What's the CC of this?", x
);
2682 fatal_insn ("MMIX Internal: What is the CC of this?", x
);
2685 /* Return the bit-value for a const_int or const_double. */
2688 mmix_intval (const_rtx x
)
2690 unsigned HOST_WIDEST_INT retval
;
2692 if (GET_CODE (x
) == CONST_INT
)
2695 /* We make a little song and dance because converting to long long in
2696 gcc-2.7.2 is broken. I still want people to be able to use it for
2697 cross-compilation to MMIX. */
2698 if (GET_CODE (x
) == CONST_DOUBLE
&& GET_MODE (x
) == VOIDmode
)
2700 if (sizeof (HOST_WIDE_INT
) < sizeof (HOST_WIDEST_INT
))
2702 retval
= (unsigned) CONST_DOUBLE_LOW (x
) / 2;
2704 retval
|= CONST_DOUBLE_LOW (x
) & 1;
2707 (unsigned HOST_WIDEST_INT
) CONST_DOUBLE_HIGH (x
)
2708 << (HOST_BITS_PER_LONG
)/2 << (HOST_BITS_PER_LONG
)/2;
2711 retval
= CONST_DOUBLE_HIGH (x
);
2716 if (GET_CODE (x
) == CONST_DOUBLE
)
2718 REAL_VALUE_TYPE value
;
2720 /* FIXME: This macro is not in the manual but should be. */
2721 REAL_VALUE_FROM_CONST_DOUBLE (value
, x
);
2723 if (GET_MODE (x
) == DFmode
)
2727 REAL_VALUE_TO_TARGET_DOUBLE (value
, bits
);
2729 /* The double cast is necessary to avoid getting the long
2730 sign-extended to unsigned long long(!) when they're of
2731 different size (usually 32-bit hosts). */
2733 ((unsigned HOST_WIDEST_INT
) (unsigned long) bits
[0]
2734 << (unsigned HOST_WIDEST_INT
) 32U)
2735 | (unsigned HOST_WIDEST_INT
) (unsigned long) bits
[1];
2737 else if (GET_MODE (x
) == SFmode
)
2740 REAL_VALUE_TO_TARGET_SINGLE (value
, bits
);
2742 return (unsigned long) bits
;
2746 fatal_insn ("MMIX Internal: This is not a constant:", x
);
2749 /* Worker function for TARGET_PROMOTE_FUNCTION_MODE. */
2752 mmix_promote_function_mode (const_tree type ATTRIBUTE_UNUSED
,
2753 enum machine_mode mode
,
2754 int *punsignedp ATTRIBUTE_UNUSED
,
2755 const_tree fntype ATTRIBUTE_UNUSED
,
2758 /* Apparently not doing TRT if int < register-size. FIXME: Perhaps
2759 FUNCTION_VALUE and LIBCALL_VALUE needs tweaking as some ports say. */
2760 if (for_return
== 1)
2763 /* Promotion of modes currently generates slow code, extending before
2764 operation, so we do it only for arguments. */
2765 if (GET_MODE_CLASS (mode
) == MODE_INT
2766 && GET_MODE_SIZE (mode
) < 8)
2771 /* Worker function for TARGET_STRUCT_VALUE_RTX. */
2774 mmix_struct_value_rtx (tree fntype ATTRIBUTE_UNUSED
,
2775 int incoming ATTRIBUTE_UNUSED
)
2777 return gen_rtx_REG (Pmode
, MMIX_STRUCT_VALUE_REGNUM
);
2780 /* Worker function for TARGET_FRAME_POINTER_REQUIRED.
2782 FIXME: Is this requirement built-in? Anyway, we should try to get rid
2783 of it; we can deduce the value. */
2786 mmix_frame_pointer_required (void)
2788 return (cfun
->has_nonlocal_label
);
2793 * eval: (c-set-style "gnu")
2794 * indent-tabs-mode: t