1 /* Definitions of target machine for GNU compiler, for MMIX.
2 Copyright (C) 2000-2015 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"
30 #include "insn-config.h"
36 #include "cfgcleanup.h"
39 #include "stor-layout.h"
48 #include "diagnostic-core.h"
54 #include "tm-constrs.h"
57 /* This file should be included last. */
58 #include "target-def.h"
60 /* First some local helper definitions. */
61 #define MMIX_FIRST_GLOBAL_REGNUM 32
63 /* We'd need a current_function_has_landing_pad. It's marked as such when
64 a nonlocal_goto_receiver is expanded. Not just a C++ thing, but
66 #define MMIX_CFUN_HAS_LANDING_PAD (cfun->machine->has_landing_pad != 0)
68 /* We have no means to tell DWARF 2 about the register stack, so we need
69 to store the return address on the stack if an exception can get into
70 this function. FIXME: Narrow condition. Before any whole-function
71 analysis, df_regs_ever_live_p () isn't initialized. We know it's up-to-date
72 after reload_completed; it may contain incorrect information some time
73 before that. Within a RTL sequence (after a call to start_sequence,
74 such as in RTL expanders), leaf_function_p doesn't see all insns
75 (perhaps any insn). But regs_ever_live is up-to-date when
76 leaf_function_p () isn't, so we "or" them together to get accurate
77 information. FIXME: Some tweak to leaf_function_p might be
79 #define MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS \
81 && ((reload_completed && df_regs_ever_live_p (MMIX_rJ_REGNUM)) \
82 || !leaf_function_p ()))
84 #define IS_MMIX_EH_RETURN_DATA_REG(REGNO) \
85 (crtl->calls_eh_return \
86 && (EH_RETURN_DATA_REGNO (0) == REGNO \
87 || EH_RETURN_DATA_REGNO (1) == REGNO \
88 || EH_RETURN_DATA_REGNO (2) == REGNO \
89 || EH_RETURN_DATA_REGNO (3) == REGNO))
91 /* For the default ABI, we rename registers at output-time to fill the gap
92 between the (statically partitioned) saved registers and call-clobbered
93 registers. In effect this makes unused call-saved registers to be used
94 as call-clobbered registers. The benefit comes from keeping the number
95 of local registers (value of rL) low, since there's a cost of
96 increasing rL and clearing unused (unset) registers with lower numbers.
97 Don't translate while outputting the prologue. */
98 #define MMIX_OUTPUT_REGNO(N) \
100 || (int) (N) < MMIX_RETURN_VALUE_REGNUM \
101 || (int) (N) > MMIX_LAST_STACK_REGISTER_REGNUM \
103 || cfun->machine == NULL \
104 || cfun->machine->in_prologue \
105 ? (N) : ((N) - MMIX_RETURN_VALUE_REGNUM \
106 + cfun->machine->highest_saved_stack_register + 1))
108 /* The %d in "POP %d,0". */
109 #define MMIX_POP_ARGUMENT() \
111 && crtl->return_rtx != NULL \
112 && ! cfun->returns_struct) \
113 ? (GET_CODE (crtl->return_rtx) == PARALLEL \
114 ? GET_NUM_ELEM (XVEC (crtl->return_rtx, 0)) : 1) \
117 /* The canonical saved comparison operands for non-cc0 machines, set in
118 the compare expander. */
119 rtx mmix_compare_op0
;
120 rtx mmix_compare_op1
;
122 /* Declarations of locals. */
124 /* Intermediate for insn output. */
125 static int mmix_output_destination_register
;
127 static void mmix_option_override (void);
128 static void mmix_asm_output_source_filename (FILE *, const char *);
129 static void mmix_output_shiftvalue_op_from_str
130 (FILE *, const char *, int64_t);
131 static void mmix_output_shifted_value (FILE *, int64_t);
132 static void mmix_output_condition (FILE *, const_rtx
, int);
133 static void mmix_output_octa (FILE *, int64_t, int);
134 static bool mmix_assemble_integer (rtx
, unsigned int, int);
135 static struct machine_function
*mmix_init_machine_status (void);
136 static void mmix_encode_section_info (tree
, rtx
, int);
137 static const char *mmix_strip_name_encoding (const char *);
138 static void mmix_emit_sp_add (HOST_WIDE_INT offset
);
139 static void mmix_target_asm_function_prologue (FILE *, HOST_WIDE_INT
);
140 static void mmix_target_asm_function_end_prologue (FILE *);
141 static void mmix_target_asm_function_epilogue (FILE *, HOST_WIDE_INT
);
142 static reg_class_t
mmix_preferred_reload_class (rtx
, reg_class_t
);
143 static reg_class_t
mmix_preferred_output_reload_class (rtx
, reg_class_t
);
144 static bool mmix_legitimate_address_p (machine_mode
, rtx
, bool);
145 static bool mmix_legitimate_constant_p (machine_mode
, rtx
);
146 static void mmix_reorg (void);
147 static void mmix_asm_output_mi_thunk
148 (FILE *, tree
, HOST_WIDE_INT
, HOST_WIDE_INT
, tree
);
149 static void mmix_setup_incoming_varargs
150 (cumulative_args_t
, machine_mode
, tree
, int *, int);
151 static void mmix_file_start (void);
152 static void mmix_file_end (void);
153 static bool mmix_rtx_costs (rtx
, machine_mode
, int, int, int *, bool);
154 static int mmix_register_move_cost (machine_mode
,
155 reg_class_t
, reg_class_t
);
156 static rtx
mmix_struct_value_rtx (tree
, int);
157 static machine_mode
mmix_promote_function_mode (const_tree
,
159 int *, const_tree
, int);
160 static void mmix_function_arg_advance (cumulative_args_t
, machine_mode
,
162 static rtx
mmix_function_arg_1 (const cumulative_args_t
, machine_mode
,
163 const_tree
, bool, bool);
164 static rtx
mmix_function_incoming_arg (cumulative_args_t
, machine_mode
,
166 static rtx
mmix_function_arg (cumulative_args_t
, machine_mode
,
168 static rtx
mmix_function_value (const_tree
, const_tree
, bool);
169 static rtx
mmix_libcall_value (machine_mode
, const_rtx
);
170 static bool mmix_function_value_regno_p (const unsigned int);
171 static bool mmix_pass_by_reference (cumulative_args_t
,
172 machine_mode
, const_tree
, bool);
173 static bool mmix_frame_pointer_required (void);
174 static void mmix_asm_trampoline_template (FILE *);
175 static void mmix_trampoline_init (rtx
, tree
, rtx
);
176 static void mmix_print_operand (FILE *, rtx
, int);
177 static void mmix_print_operand_address (FILE *, rtx
);
178 static bool mmix_print_operand_punct_valid_p (unsigned char);
179 static void mmix_conditional_register_usage (void);
181 /* Target structure macros. Listed by node. See `Using and Porting GCC'
182 for a general description. */
184 /* Node: Function Entry */
186 #undef TARGET_ASM_BYTE_OP
187 #define TARGET_ASM_BYTE_OP NULL
188 #undef TARGET_ASM_ALIGNED_HI_OP
189 #define TARGET_ASM_ALIGNED_HI_OP NULL
190 #undef TARGET_ASM_ALIGNED_SI_OP
191 #define TARGET_ASM_ALIGNED_SI_OP NULL
192 #undef TARGET_ASM_ALIGNED_DI_OP
193 #define TARGET_ASM_ALIGNED_DI_OP NULL
194 #undef TARGET_ASM_INTEGER
195 #define TARGET_ASM_INTEGER mmix_assemble_integer
197 #undef TARGET_ASM_FUNCTION_PROLOGUE
198 #define TARGET_ASM_FUNCTION_PROLOGUE mmix_target_asm_function_prologue
200 #undef TARGET_ASM_FUNCTION_END_PROLOGUE
201 #define TARGET_ASM_FUNCTION_END_PROLOGUE mmix_target_asm_function_end_prologue
203 #undef TARGET_ASM_FUNCTION_EPILOGUE
204 #define TARGET_ASM_FUNCTION_EPILOGUE mmix_target_asm_function_epilogue
206 #undef TARGET_PRINT_OPERAND
207 #define TARGET_PRINT_OPERAND mmix_print_operand
208 #undef TARGET_PRINT_OPERAND_ADDRESS
209 #define TARGET_PRINT_OPERAND_ADDRESS mmix_print_operand_address
210 #undef TARGET_PRINT_OPERAND_PUNCT_VALID_P
211 #define TARGET_PRINT_OPERAND_PUNCT_VALID_P mmix_print_operand_punct_valid_p
213 #undef TARGET_ENCODE_SECTION_INFO
214 #define TARGET_ENCODE_SECTION_INFO mmix_encode_section_info
215 #undef TARGET_STRIP_NAME_ENCODING
216 #define TARGET_STRIP_NAME_ENCODING mmix_strip_name_encoding
218 #undef TARGET_ASM_OUTPUT_MI_THUNK
219 #define TARGET_ASM_OUTPUT_MI_THUNK mmix_asm_output_mi_thunk
220 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
221 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall
222 #undef TARGET_ASM_FILE_START
223 #define TARGET_ASM_FILE_START mmix_file_start
224 #undef TARGET_ASM_FILE_START_FILE_DIRECTIVE
225 #define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
226 #undef TARGET_ASM_FILE_END
227 #define TARGET_ASM_FILE_END mmix_file_end
228 #undef TARGET_ASM_OUTPUT_SOURCE_FILENAME
229 #define TARGET_ASM_OUTPUT_SOURCE_FILENAME mmix_asm_output_source_filename
231 #undef TARGET_CONDITIONAL_REGISTER_USAGE
232 #define TARGET_CONDITIONAL_REGISTER_USAGE mmix_conditional_register_usage
234 #undef TARGET_RTX_COSTS
235 #define TARGET_RTX_COSTS mmix_rtx_costs
236 #undef TARGET_ADDRESS_COST
237 #define TARGET_ADDRESS_COST hook_int_rtx_mode_as_bool_0
239 #undef TARGET_REGISTER_MOVE_COST
240 #define TARGET_REGISTER_MOVE_COST mmix_register_move_cost
242 #undef TARGET_MACHINE_DEPENDENT_REORG
243 #define TARGET_MACHINE_DEPENDENT_REORG mmix_reorg
245 #undef TARGET_PROMOTE_FUNCTION_MODE
246 #define TARGET_PROMOTE_FUNCTION_MODE mmix_promote_function_mode
248 #undef TARGET_FUNCTION_VALUE
249 #define TARGET_FUNCTION_VALUE mmix_function_value
250 #undef TARGET_LIBCALL_VALUE
251 #define TARGET_LIBCALL_VALUE mmix_libcall_value
252 #undef TARGET_FUNCTION_VALUE_REGNO_P
253 #define TARGET_FUNCTION_VALUE_REGNO_P mmix_function_value_regno_p
255 #undef TARGET_FUNCTION_ARG
256 #define TARGET_FUNCTION_ARG mmix_function_arg
257 #undef TARGET_FUNCTION_INCOMING_ARG
258 #define TARGET_FUNCTION_INCOMING_ARG mmix_function_incoming_arg
259 #undef TARGET_FUNCTION_ARG_ADVANCE
260 #define TARGET_FUNCTION_ARG_ADVANCE mmix_function_arg_advance
261 #undef TARGET_STRUCT_VALUE_RTX
262 #define TARGET_STRUCT_VALUE_RTX mmix_struct_value_rtx
263 #undef TARGET_SETUP_INCOMING_VARARGS
264 #define TARGET_SETUP_INCOMING_VARARGS mmix_setup_incoming_varargs
265 #undef TARGET_PASS_BY_REFERENCE
266 #define TARGET_PASS_BY_REFERENCE mmix_pass_by_reference
267 #undef TARGET_CALLEE_COPIES
268 #define TARGET_CALLEE_COPIES hook_bool_CUMULATIVE_ARGS_mode_tree_bool_true
270 #undef TARGET_PREFERRED_RELOAD_CLASS
271 #define TARGET_PREFERRED_RELOAD_CLASS mmix_preferred_reload_class
272 #undef TARGET_PREFERRED_OUTPUT_RELOAD_CLASS
273 #define TARGET_PREFERRED_OUTPUT_RELOAD_CLASS mmix_preferred_output_reload_class
275 #undef TARGET_LEGITIMATE_ADDRESS_P
276 #define TARGET_LEGITIMATE_ADDRESS_P mmix_legitimate_address_p
277 #undef TARGET_LEGITIMATE_CONSTANT_P
278 #define TARGET_LEGITIMATE_CONSTANT_P mmix_legitimate_constant_p
280 #undef TARGET_FRAME_POINTER_REQUIRED
281 #define TARGET_FRAME_POINTER_REQUIRED mmix_frame_pointer_required
283 #undef TARGET_ASM_TRAMPOLINE_TEMPLATE
284 #define TARGET_ASM_TRAMPOLINE_TEMPLATE mmix_asm_trampoline_template
285 #undef TARGET_TRAMPOLINE_INIT
286 #define TARGET_TRAMPOLINE_INIT mmix_trampoline_init
288 #undef TARGET_OPTION_OVERRIDE
289 #define TARGET_OPTION_OVERRIDE mmix_option_override
291 struct gcc_target targetm
= TARGET_INITIALIZER
;
293 /* Functions that are expansions for target macros.
294 See Target Macros in `Using and Porting GCC'. */
296 /* TARGET_OPTION_OVERRIDE. */
299 mmix_option_override (void)
301 /* Should we err or should we warn? Hmm. At least we must neutralize
302 it. For example the wrong kind of case-tables will be generated with
303 PIC; we use absolute address items for mmixal compatibility. FIXME:
304 They could be relative if we just elide them to after all pertinent
308 warning (0, "-f%s not supported: ignored", (flag_pic
> 1) ? "PIC" : "pic");
313 /* INIT_EXPANDERS. */
316 mmix_init_expanders (void)
318 init_machine_status
= mmix_init_machine_status
;
321 /* Set the per-function data. */
323 static struct machine_function
*
324 mmix_init_machine_status (void)
326 return ggc_cleared_alloc
<machine_function
> ();
329 /* DATA_ABI_ALIGNMENT.
330 We have trouble getting the address of stuff that is located at other
331 than 32-bit alignments (GETA requirements), so try to give everything
332 at least 32-bit alignment. */
335 mmix_data_alignment (tree type ATTRIBUTE_UNUSED
, int basic_align
)
337 if (basic_align
< 32)
343 /* CONSTANT_ALIGNMENT. */
346 mmix_constant_alignment (tree constant ATTRIBUTE_UNUSED
, int basic_align
)
348 if (basic_align
< 32)
354 /* LOCAL_ALIGNMENT. */
357 mmix_local_alignment (tree type ATTRIBUTE_UNUSED
, unsigned basic_align
)
359 if (basic_align
< 32)
365 /* TARGET_CONDITIONAL_REGISTER_USAGE. */
368 mmix_conditional_register_usage (void)
374 static const int gnu_abi_reg_alloc_order
[]
375 = MMIX_GNU_ABI_REG_ALLOC_ORDER
;
377 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
378 reg_alloc_order
[i
] = gnu_abi_reg_alloc_order
[i
];
380 /* Change the default from the mmixware ABI. For the GNU ABI,
381 $15..$30 are call-saved just as $0..$14. There must be one
382 call-clobbered local register for the "hole" that holds the
383 number of saved local registers saved by PUSHJ/PUSHGO during the
384 function call, receiving the return value at return. So best is
385 to use the highest, $31. It's already marked call-clobbered for
387 for (i
= 15; i
<= 30; i
++)
388 call_used_regs
[i
] = 0;
390 /* "Unfix" the parameter registers. */
391 for (i
= MMIX_RESERVED_GNU_ARG_0_REGNUM
;
392 i
< MMIX_RESERVED_GNU_ARG_0_REGNUM
+ MMIX_MAX_ARGS_IN_REGS
;
397 /* Step over the ":" in special register names. */
398 if (! TARGET_TOPLEVEL_SYMBOLS
)
399 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
400 if (reg_names
[i
][0] == ':')
404 /* INCOMING_REGNO and OUTGOING_REGNO worker function.
405 Those two macros must only be applied to function argument
406 registers and the function return value register for the opposite
407 use. FIXME: for their current use in gcc, it'd be better with an
408 explicit specific additional FUNCTION_INCOMING_ARG_REGNO_P a'la
409 TARGET_FUNCTION_ARG / TARGET_FUNCTION_INCOMING_ARG instead of
410 forcing the target to commit to a fixed mapping and for any
411 unspecified register use. Particularly when thinking about the
412 return-value, it is better to imagine INCOMING_REGNO and
413 OUTGOING_REGNO as named CALLEE_TO_CALLER_REGNO and INNER_REGNO as
414 named CALLER_TO_CALLEE_REGNO because the direction. The "incoming"
415 and "outgoing" is from the perspective of the parameter-registers,
416 but the same macro is (must be, lacking an alternative like
417 suggested above) used to map the return-value-register from the
418 same perspective. To make directions even more confusing, the macro
419 MMIX_OUTGOING_RETURN_VALUE_REGNUM holds the number of the register
420 in which to return a value, i.e. INCOMING_REGNO for the return-value-
421 register as received from a called function; the return-value on the
425 mmix_opposite_regno (int regno
, int incoming
)
427 if (incoming
&& regno
== MMIX_OUTGOING_RETURN_VALUE_REGNUM
)
428 return MMIX_RETURN_VALUE_REGNUM
;
430 if (!incoming
&& regno
== MMIX_RETURN_VALUE_REGNUM
)
431 return MMIX_OUTGOING_RETURN_VALUE_REGNUM
;
433 if (!mmix_function_arg_regno_p (regno
, incoming
))
438 ? MMIX_FIRST_INCOMING_ARG_REGNUM
- MMIX_FIRST_ARG_REGNUM
439 : MMIX_FIRST_ARG_REGNUM
- MMIX_FIRST_INCOMING_ARG_REGNUM
);
443 All registers that are part of the register stack and that will be
447 mmix_local_regno (int regno
)
449 return regno
<= MMIX_LAST_STACK_REGISTER_REGNUM
&& !call_used_regs
[regno
];
452 /* TARGET_PREFERRED_RELOAD_CLASS.
453 We need to extend the reload class of REMAINDER_REG and HIMULT_REG. */
456 mmix_preferred_reload_class (rtx x
, reg_class_t rclass
)
458 /* FIXME: Revisit. */
459 return GET_CODE (x
) == MOD
&& GET_MODE (x
) == DImode
460 ? REMAINDER_REG
: rclass
;
463 /* TARGET_PREFERRED_OUTPUT_RELOAD_CLASS.
464 We need to extend the reload class of REMAINDER_REG and HIMULT_REG. */
467 mmix_preferred_output_reload_class (rtx x
, reg_class_t rclass
)
469 /* FIXME: Revisit. */
470 return GET_CODE (x
) == MOD
&& GET_MODE (x
) == DImode
471 ? REMAINDER_REG
: rclass
;
474 /* SECONDARY_RELOAD_CLASS.
475 We need to reload regs of REMAINDER_REG and HIMULT_REG elsewhere. */
478 mmix_secondary_reload_class (enum reg_class rclass
,
479 machine_mode mode ATTRIBUTE_UNUSED
,
480 rtx x ATTRIBUTE_UNUSED
,
481 int in_p ATTRIBUTE_UNUSED
)
483 if (rclass
== REMAINDER_REG
484 || rclass
== HIMULT_REG
485 || rclass
== SYSTEM_REGS
)
491 /* DYNAMIC_CHAIN_ADDRESS. */
494 mmix_dynamic_chain_address (rtx frame
)
496 /* FIXME: the frame-pointer is stored at offset -8 from the current
497 frame-pointer. Unfortunately, the caller assumes that a
498 frame-pointer is present for *all* previous frames. There should be
499 a way to say that that cannot be done, like for RETURN_ADDR_RTX. */
500 return plus_constant (Pmode
, frame
, -8);
503 /* STARTING_FRAME_OFFSET. */
506 mmix_starting_frame_offset (void)
508 /* The old frame pointer is in the slot below the new one, so
509 FIRST_PARM_OFFSET does not need to depend on whether the
510 frame-pointer is needed or not. We have to adjust for the register
511 stack pointer being located below the saved frame pointer.
512 Similarly, we store the return address on the stack too, for
513 exception handling, and always if we save the register stack pointer. */
516 + (MMIX_CFUN_HAS_LANDING_PAD
517 ? -16 : (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
? -8 : 0)));
520 /* RETURN_ADDR_RTX. */
523 mmix_return_addr_rtx (int count
, rtx frame ATTRIBUTE_UNUSED
)
526 ? (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
527 /* FIXME: Set frame_alias_set on the following. (Why?)
528 See mmix_initial_elimination_offset for the reason we can't use
529 get_hard_reg_initial_val for both. Always using a stack slot
530 and not a register would be suboptimal. */
531 ? validize_mem (gen_rtx_MEM (Pmode
,
532 plus_constant (Pmode
,
533 frame_pointer_rtx
, -16)))
534 : get_hard_reg_initial_val (Pmode
, MMIX_INCOMING_RETURN_ADDRESS_REGNUM
))
538 /* SETUP_FRAME_ADDRESSES. */
541 mmix_setup_frame_addresses (void)
543 /* Nothing needed at the moment. */
546 /* The difference between the (imaginary) frame pointer and the stack
547 pointer. Used to eliminate the frame pointer. */
550 mmix_initial_elimination_offset (int fromreg
, int toreg
)
554 = (get_frame_size () + crtl
->outgoing_args_size
+ 7) & ~7;
556 /* There is no actual offset between these two virtual values, but for
557 the frame-pointer, we have the old one in the stack position below
558 it, so the offset for the frame-pointer to the stack-pointer is one
560 if (fromreg
== MMIX_ARG_POINTER_REGNUM
561 && toreg
== MMIX_FRAME_POINTER_REGNUM
)
564 /* The difference is the size of local variables plus the size of
565 outgoing function arguments that would normally be passed as
566 registers but must be passed on stack because we're out of
567 function-argument registers. Only global saved registers are
568 counted; the others go on the register stack.
570 The frame-pointer is counted too if it is what is eliminated, as we
571 need to balance the offset for it from STARTING_FRAME_OFFSET.
573 Also add in the slot for the register stack pointer we save if we
576 Unfortunately, we can't access $0..$14, from unwinder code easily, so
577 store the return address in a frame slot too. FIXME: Only for
578 non-leaf functions. FIXME: Always with a landing pad, because it's
579 hard to know whether we need the other at the time we know we need
580 the offset for one (and have to state it). It's a kludge until we
581 can express the register stack in the EH frame info.
583 We have to do alignment here; get_frame_size will not return a
584 multiple of STACK_BOUNDARY. FIXME: Add note in manual. */
586 for (regno
= MMIX_FIRST_GLOBAL_REGNUM
;
589 if ((df_regs_ever_live_p (regno
) && ! call_used_regs
[regno
])
590 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
594 + (MMIX_CFUN_HAS_LANDING_PAD
595 ? 16 : (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
? 8 : 0))
596 + (fromreg
== MMIX_ARG_POINTER_REGNUM
? 0 : 8);
600 mmix_function_arg_advance (cumulative_args_t argsp_v
, machine_mode mode
,
601 const_tree type
, bool named ATTRIBUTE_UNUSED
)
603 CUMULATIVE_ARGS
*argsp
= get_cumulative_args (argsp_v
);
604 int arg_size
= MMIX_FUNCTION_ARG_SIZE (mode
, type
);
606 argsp
->regs
= ((targetm
.calls
.must_pass_in_stack (mode
, type
)
610 ? (MMIX_MAX_ARGS_IN_REGS
) + 1
611 : argsp
->regs
+ (7 + arg_size
) / 8);
614 /* Helper function for mmix_function_arg and mmix_function_incoming_arg. */
617 mmix_function_arg_1 (const cumulative_args_t argsp_v
,
620 bool named ATTRIBUTE_UNUSED
,
623 CUMULATIVE_ARGS
*argsp
= get_cumulative_args (argsp_v
);
625 /* Last-argument marker. */
626 if (type
== void_type_node
)
627 return (argsp
->regs
< MMIX_MAX_ARGS_IN_REGS
)
630 ? MMIX_FIRST_INCOMING_ARG_REGNUM
631 : MMIX_FIRST_ARG_REGNUM
) + argsp
->regs
)
634 return (argsp
->regs
< MMIX_MAX_ARGS_IN_REGS
635 && !targetm
.calls
.must_pass_in_stack (mode
, type
)
636 && (GET_MODE_BITSIZE (mode
) <= 64
641 ? MMIX_FIRST_INCOMING_ARG_REGNUM
642 : MMIX_FIRST_ARG_REGNUM
)
647 /* Return an rtx for a function argument to go in a register, and 0 for
648 one that must go on stack. */
651 mmix_function_arg (cumulative_args_t argsp
,
656 return mmix_function_arg_1 (argsp
, mode
, type
, named
, false);
660 mmix_function_incoming_arg (cumulative_args_t argsp
,
665 return mmix_function_arg_1 (argsp
, mode
, type
, named
, true);
668 /* Returns nonzero for everything that goes by reference, 0 for
669 everything that goes by value. */
672 mmix_pass_by_reference (cumulative_args_t argsp_v
, machine_mode mode
,
673 const_tree type
, bool named ATTRIBUTE_UNUSED
)
675 CUMULATIVE_ARGS
*argsp
= get_cumulative_args (argsp_v
);
677 /* FIXME: Check: I'm not sure the must_pass_in_stack check is
679 if (targetm
.calls
.must_pass_in_stack (mode
, type
))
682 if (MMIX_FUNCTION_ARG_SIZE (mode
, type
) > 8
684 && (!argsp
|| !argsp
->lib
))
690 /* Return nonzero if regno is a register number where a parameter is
691 passed, and 0 otherwise. */
694 mmix_function_arg_regno_p (int regno
, int incoming
)
697 = incoming
? MMIX_FIRST_INCOMING_ARG_REGNUM
: MMIX_FIRST_ARG_REGNUM
;
699 return regno
>= first_arg_regnum
700 && regno
< first_arg_regnum
+ MMIX_MAX_ARGS_IN_REGS
;
703 /* Implements TARGET_FUNCTION_VALUE. */
706 mmix_function_value (const_tree valtype
,
707 const_tree func ATTRIBUTE_UNUSED
,
710 machine_mode mode
= TYPE_MODE (valtype
);
712 int first_val_regnum
= MMIX_OUTGOING_RETURN_VALUE_REGNUM
;
713 rtx vec
[MMIX_MAX_REGS_FOR_VALUE
];
718 return gen_rtx_REG (mode
, MMIX_RETURN_VALUE_REGNUM
);
720 /* Return values that fit in a register need no special handling.
721 There's no register hole when parameters are passed in global
724 || GET_MODE_BITSIZE (mode
) <= BITS_PER_WORD
)
726 gen_rtx_REG (mode
, MMIX_OUTGOING_RETURN_VALUE_REGNUM
);
728 if (COMPLEX_MODE_P (mode
))
729 /* A complex type, made up of components. */
730 cmode
= TYPE_MODE (TREE_TYPE (valtype
));
733 /* Of the other larger-than-register modes, we only support
734 scalar mode TImode. (At least, that's the only one that's
735 been rudimentally tested.) Make sure we're alerted for
738 sorry ("support for mode %qs", GET_MODE_NAME (mode
));
740 /* In any case, we will fill registers to the natural size. */
744 nregs
= ((GET_MODE_BITSIZE (mode
) + BITS_PER_WORD
- 1) / BITS_PER_WORD
);
746 /* We need to take care of the effect of the register hole on return
747 values of large sizes; the last register will appear as the first
748 register, with the rest shifted. (For complex modes, this is just
749 swapped registers.) */
751 if (nregs
> MMIX_MAX_REGS_FOR_VALUE
)
752 internal_error ("too large function value type, needs %d registers,\
753 have only %d registers for this", nregs
, MMIX_MAX_REGS_FOR_VALUE
);
755 /* FIXME: Maybe we should handle structure values like this too
756 (adjusted for BLKmode), perhaps for both ABI:s. */
757 for (i
= 0; i
< nregs
- 1; i
++)
759 = gen_rtx_EXPR_LIST (VOIDmode
,
760 gen_rtx_REG (cmode
, first_val_regnum
+ i
),
761 GEN_INT ((i
+ 1) * BITS_PER_UNIT
));
764 = gen_rtx_EXPR_LIST (VOIDmode
,
765 gen_rtx_REG (cmode
, first_val_regnum
+ nregs
- 1),
768 return gen_rtx_PARALLEL (mode
, gen_rtvec_v (nregs
, vec
));
771 /* Implements TARGET_LIBCALL_VALUE. */
774 mmix_libcall_value (machine_mode mode
,
775 const_rtx fun ATTRIBUTE_UNUSED
)
777 return gen_rtx_REG (mode
, MMIX_RETURN_VALUE_REGNUM
);
780 /* Implements TARGET_FUNCTION_VALUE_REGNO_P. */
783 mmix_function_value_regno_p (const unsigned int regno
)
785 return regno
== MMIX_RETURN_VALUE_REGNUM
;
788 /* EH_RETURN_DATA_REGNO. */
791 mmix_eh_return_data_regno (int n
)
794 return MMIX_EH_RETURN_DATA_REGNO_START
+ n
;
796 return INVALID_REGNUM
;
799 /* EH_RETURN_STACKADJ_RTX. */
802 mmix_eh_return_stackadj_rtx (void)
804 return gen_rtx_REG (Pmode
, MMIX_EH_RETURN_STACKADJ_REGNUM
);
807 /* EH_RETURN_HANDLER_RTX. */
810 mmix_eh_return_handler_rtx (void)
812 return gen_rtx_REG (Pmode
, MMIX_INCOMING_RETURN_ADDRESS_REGNUM
);
815 /* ASM_PREFERRED_EH_DATA_FORMAT. */
818 mmix_asm_preferred_eh_data_format (int code ATTRIBUTE_UNUSED
,
819 int global ATTRIBUTE_UNUSED
)
821 /* This is the default (was at 2001-07-20). Revisit when needed. */
822 return DW_EH_PE_absptr
;
825 /* Make a note that we've seen the beginning of the prologue. This
826 matters to whether we'll translate register numbers as calculated by
830 mmix_target_asm_function_prologue (FILE *stream ATTRIBUTE_UNUSED
,
831 HOST_WIDE_INT framesize ATTRIBUTE_UNUSED
)
833 cfun
->machine
->in_prologue
= 1;
836 /* Make a note that we've seen the end of the prologue. */
839 mmix_target_asm_function_end_prologue (FILE *stream ATTRIBUTE_UNUSED
)
841 cfun
->machine
->in_prologue
= 0;
844 /* Implement TARGET_MACHINE_DEPENDENT_REORG. No actual rearrangements
845 done here; just virtually by calculating the highest saved stack
846 register number used to modify the register numbers at output time. */
853 /* We put the number of the highest saved register-file register in a
854 location convenient for the call-patterns to output. Note that we
855 don't tell dwarf2 about these registers, since it can't restore them
857 for (regno
= MMIX_LAST_STACK_REGISTER_REGNUM
;
860 if ((df_regs_ever_live_p (regno
) && !call_used_regs
[regno
])
861 || (regno
== MMIX_FRAME_POINTER_REGNUM
&& frame_pointer_needed
))
864 /* Regardless of whether they're saved (they might be just read), we
865 mustn't include registers that carry parameters. We could scan the
866 insns to see whether they're actually used (and indeed do other less
867 trivial register usage analysis and transformations), but it seems
868 wasteful to optimize for unused parameter registers. As of
869 2002-04-30, df_regs_ever_live_p (n) seems to be set for only-reads too, but
870 that might change. */
871 if (!TARGET_ABI_GNU
&& regno
< crtl
->args
.info
.regs
- 1)
873 regno
= crtl
->args
.info
.regs
- 1;
875 /* We don't want to let this cause us to go over the limit and make
876 incoming parameter registers be misnumbered and treating the last
877 parameter register and incoming return value register call-saved.
878 Stop things at the unmodified scheme. */
879 if (regno
> MMIX_RETURN_VALUE_REGNUM
- 1)
880 regno
= MMIX_RETURN_VALUE_REGNUM
- 1;
883 cfun
->machine
->highest_saved_stack_register
= regno
;
886 /* TARGET_ASM_FUNCTION_EPILOGUE. */
889 mmix_target_asm_function_epilogue (FILE *stream
,
890 HOST_WIDE_INT locals_size ATTRIBUTE_UNUSED
)
892 /* Emit an \n for readability of the generated assembly. */
893 fputc ('\n', stream
);
896 /* TARGET_ASM_OUTPUT_MI_THUNK. */
899 mmix_asm_output_mi_thunk (FILE *stream
,
900 tree fndecl ATTRIBUTE_UNUSED
,
902 HOST_WIDE_INT vcall_offset ATTRIBUTE_UNUSED
,
905 /* If you define TARGET_STRUCT_VALUE_RTX that returns 0 (i.e. pass
906 location of structure to return as invisible first argument), you
907 need to tweak this code too. */
908 const char *regname
= reg_names
[MMIX_FIRST_INCOMING_ARG_REGNUM
];
910 if (delta
>= 0 && delta
< 65536)
911 fprintf (stream
, "\tINCL %s,%d\n", regname
, (int)delta
);
912 else if (delta
< 0 && delta
>= -255)
913 fprintf (stream
, "\tSUBU %s,%s,%d\n", regname
, regname
, (int)-delta
);
916 mmix_output_register_setting (stream
, 255, delta
, 1);
917 fprintf (stream
, "\tADDU %s,%s,$255\n", regname
, regname
);
920 fprintf (stream
, "\tJMP ");
921 assemble_name (stream
, XSTR (XEXP (DECL_RTL (func
), 0), 0));
922 fprintf (stream
, "\n");
925 /* FUNCTION_PROFILER. */
928 mmix_function_profiler (FILE *stream ATTRIBUTE_UNUSED
,
929 int labelno ATTRIBUTE_UNUSED
)
931 sorry ("function_profiler support for MMIX");
934 /* Worker function for TARGET_SETUP_INCOMING_VARARGS. For the moment,
935 let's stick to pushing argument registers on the stack. Later, we
936 can parse all arguments in registers, to improve performance. */
939 mmix_setup_incoming_varargs (cumulative_args_t args_so_farp_v
,
943 int second_time ATTRIBUTE_UNUSED
)
945 CUMULATIVE_ARGS
*args_so_farp
= get_cumulative_args (args_so_farp_v
);
947 /* The last named variable has been handled, but
948 args_so_farp has not been advanced for it. */
949 if (args_so_farp
->regs
+ 1 < MMIX_MAX_ARGS_IN_REGS
)
950 *pretend_sizep
= (MMIX_MAX_ARGS_IN_REGS
- (args_so_farp
->regs
+ 1)) * 8;
952 /* We assume that one argument takes up one register here. That should
953 be true until we start messing with multi-reg parameters. */
954 if ((7 + (MMIX_FUNCTION_ARG_SIZE (mode
, vartype
))) / 8 != 1)
955 internal_error ("MMIX Internal: Last named vararg would not fit in a register");
958 /* TARGET_ASM_TRAMPOLINE_TEMPLATE. */
961 mmix_asm_trampoline_template (FILE *stream
)
963 /* Read a value into the static-chain register and jump somewhere. The
964 static chain is stored at offset 16, and the function address is
965 stored at offset 24. */
967 fprintf (stream
, "\tGETA $255,1F\n\t");
968 fprintf (stream
, "LDOU %s,$255,0\n\t", reg_names
[MMIX_STATIC_CHAIN_REGNUM
]);
969 fprintf (stream
, "LDOU $255,$255,8\n\t");
970 fprintf (stream
, "GO $255,$255,0\n");
971 fprintf (stream
, "1H\tOCTA 0\n\t");
972 fprintf (stream
, "OCTA 0\n");
975 /* TARGET_TRAMPOLINE_INIT. */
976 /* Set the static chain and function pointer field in the trampoline.
977 We also SYNCID here to be sure (doesn't matter in the simulator, but
978 some day it will). */
981 mmix_trampoline_init (rtx m_tramp
, tree fndecl
, rtx static_chain
)
983 rtx fnaddr
= XEXP (DECL_RTL (fndecl
), 0);
986 emit_block_move (m_tramp
, assemble_trampoline_template (),
987 GEN_INT (2*UNITS_PER_WORD
), BLOCK_OP_NORMAL
);
989 mem
= adjust_address (m_tramp
, DImode
, 2*UNITS_PER_WORD
);
990 emit_move_insn (mem
, static_chain
);
991 mem
= adjust_address (m_tramp
, DImode
, 3*UNITS_PER_WORD
);
992 emit_move_insn (mem
, fnaddr
);
994 mem
= adjust_address (m_tramp
, DImode
, 0);
995 emit_insn (gen_sync_icache (mem
, GEN_INT (TRAMPOLINE_SIZE
- 1)));
998 /* We must exclude constant addresses that have an increment that is not a
999 multiple of four bytes because of restrictions of the GETA
1000 instruction, unless TARGET_BASE_ADDRESSES. */
1003 mmix_constant_address_p (rtx x
)
1005 RTX_CODE code
= GET_CODE (x
);
1007 /* When using "base addresses", anything constant goes. */
1008 int constant_ok
= TARGET_BASE_ADDRESSES
!= 0;
1017 /* FIXME: Don't know how to dissect these. Avoid them for now,
1018 except we know they're constants. */
1022 addend
= INTVAL (x
);
1026 if (GET_MODE (x
) != VOIDmode
)
1027 /* Strange that we got here. FIXME: Check if we do. */
1029 addend
= CONST_DOUBLE_LOW (x
);
1033 /* Note that expressions with arithmetic on forward references don't
1034 work in mmixal. People using gcc assembly code with mmixal might
1035 need to move arrays and such to before the point of use. */
1036 if (GET_CODE (XEXP (x
, 0)) == PLUS
)
1038 rtx x0
= XEXP (XEXP (x
, 0), 0);
1039 rtx x1
= XEXP (XEXP (x
, 0), 1);
1041 if ((GET_CODE (x0
) == SYMBOL_REF
1042 || GET_CODE (x0
) == LABEL_REF
)
1043 && (GET_CODE (x1
) == CONST_INT
1044 || (GET_CODE (x1
) == CONST_DOUBLE
1045 && GET_MODE (x1
) == VOIDmode
)))
1046 addend
= mmix_intval (x1
);
1058 return constant_ok
|| (addend
& 3) == 0;
1061 /* Return 1 if the address is OK, otherwise 0. */
1064 mmix_legitimate_address_p (machine_mode mode ATTRIBUTE_UNUSED
,
1066 bool strict_checking
)
1068 #define MMIX_REG_OK(X) \
1070 && (REGNO (X) <= MMIX_LAST_GENERAL_REGISTER \
1071 || (reg_renumber[REGNO (X)] > 0 \
1072 && reg_renumber[REGNO (X)] <= MMIX_LAST_GENERAL_REGISTER))) \
1073 || (!strict_checking \
1074 && (REGNO (X) <= MMIX_LAST_GENERAL_REGISTER \
1075 || REGNO (X) >= FIRST_PSEUDO_REGISTER \
1076 || REGNO (X) == ARG_POINTER_REGNUM)))
1080 (mem (plus reg reg))
1081 (mem (plus reg 0..255)).
1082 unless TARGET_BASE_ADDRESSES, in which case we accept all
1083 (mem constant_address) too. */
1087 if (REG_P (x
) && MMIX_REG_OK (x
))
1090 if (GET_CODE(x
) == PLUS
)
1092 rtx x1
= XEXP (x
, 0);
1093 rtx x2
= XEXP (x
, 1);
1095 /* Try swapping the order. FIXME: Do we need this? */
1103 /* (mem (plus (reg?) (?))) */
1104 if (!REG_P (x1
) || !MMIX_REG_OK (x1
))
1105 return TARGET_BASE_ADDRESSES
&& mmix_constant_address_p (x
);
1107 /* (mem (plus (reg) (reg?))) */
1108 if (REG_P (x2
) && MMIX_REG_OK (x2
))
1111 /* (mem (plus (reg) (0..255?))) */
1112 if (satisfies_constraint_I (x2
))
1118 return TARGET_BASE_ADDRESSES
&& mmix_constant_address_p (x
);
1121 /* Implement TARGET_LEGITIMATE_CONSTANT_P. */
1124 mmix_legitimate_constant_p (machine_mode mode ATTRIBUTE_UNUSED
, rtx x
)
1126 RTX_CODE code
= GET_CODE (x
);
1128 /* We must allow any number due to the way the cse passes works; if we
1129 do not allow any number here, general_operand will fail, and insns
1130 will fatally fail recognition instead of "softly". */
1131 if (code
== CONST_INT
|| code
== CONST_DOUBLE
)
1134 return CONSTANT_ADDRESS_P (x
);
1137 /* SELECT_CC_MODE. */
1140 mmix_select_cc_mode (RTX_CODE op
, rtx x
, rtx y ATTRIBUTE_UNUSED
)
1142 /* We use CCmode, CC_UNSmode, CC_FPmode, CC_FPEQmode and CC_FUNmode to
1143 output different compare insns. Note that we do not check the
1144 validity of the comparison here. */
1146 if (GET_MODE_CLASS (GET_MODE (x
)) == MODE_FLOAT
)
1148 if (op
== ORDERED
|| op
== UNORDERED
|| op
== UNGE
1149 || op
== UNGT
|| op
== UNLE
|| op
== UNLT
)
1152 if (op
== EQ
|| op
== NE
)
1158 if (op
== GTU
|| op
== LTU
|| op
== GEU
|| op
== LEU
)
1164 /* REVERSIBLE_CC_MODE. */
1167 mmix_reversible_cc_mode (machine_mode mode
)
1169 /* That is, all integer and the EQ, NE, ORDERED and UNORDERED float
1171 return mode
!= CC_FPmode
;
1174 /* TARGET_RTX_COSTS. */
1177 mmix_rtx_costs (rtx x ATTRIBUTE_UNUSED
,
1178 machine_mode mode ATTRIBUTE_UNUSED
,
1179 int outer_code ATTRIBUTE_UNUSED
,
1180 int opno ATTRIBUTE_UNUSED
,
1181 int *total ATTRIBUTE_UNUSED
,
1182 bool speed ATTRIBUTE_UNUSED
)
1184 /* For the time being, this is just a stub and we'll accept the
1185 generic calculations, until we can do measurements, at least.
1186 Say we did not modify any calculated costs. */
1190 /* TARGET_REGISTER_MOVE_COST.
1192 The special registers can only move to and from general regs, and we
1193 need to check that their constraints match, so say 3 for them. */
1196 mmix_register_move_cost (machine_mode mode ATTRIBUTE_UNUSED
,
1200 return (from
== GENERAL_REGS
&& from
== to
) ? 2 : 3;
1203 /* Note that we don't have a TEXT_SECTION_ASM_OP, because it has to be a
1204 compile-time constant; it's used in an asm in crtstuff.c, compiled for
1207 /* DATA_SECTION_ASM_OP. */
1210 mmix_data_section_asm_op (void)
1212 return "\t.data ! mmixal:= 8H LOC 9B";
1216 mmix_encode_section_info (tree decl
, rtx rtl
, int first
)
1218 /* Test for an external declaration, and do nothing if it is one. */
1219 if ((TREE_CODE (decl
) == VAR_DECL
1220 && (DECL_EXTERNAL (decl
) || TREE_PUBLIC (decl
)))
1221 || (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_PUBLIC (decl
)))
1223 else if (first
&& DECL_P (decl
))
1225 /* For non-visible declarations, add a "@" prefix, which we skip
1226 when the label is output. If the label does not have this
1227 prefix, a ":" is output if -mtoplevel-symbols.
1229 Note that this does not work for data that is declared extern and
1230 later defined as static. If there's code in between, that code
1231 will refer to the extern declaration, and vice versa. This just
1232 means that when -mtoplevel-symbols is in use, we can just handle
1233 well-behaved ISO-compliant code. */
1235 const char *str
= XSTR (XEXP (rtl
, 0), 0);
1236 int len
= strlen (str
);
1237 char *newstr
= XALLOCAVEC (char, len
+ 2);
1239 strcpy (newstr
+ 1, str
);
1240 XSTR (XEXP (rtl
, 0), 0) = ggc_alloc_string (newstr
, len
+ 1);
1243 /* Set SYMBOL_REF_FLAG for things that we want to access with GETA. We
1244 may need different options to reach for different things with GETA.
1245 For now, functions and things we know or have been told are constant. */
1246 if (TREE_CODE (decl
) == FUNCTION_DECL
1247 || TREE_CONSTANT (decl
)
1248 || (TREE_CODE (decl
) == VAR_DECL
1249 && TREE_READONLY (decl
)
1250 && !TREE_SIDE_EFFECTS (decl
)
1251 && (!DECL_INITIAL (decl
)
1252 || TREE_CONSTANT (DECL_INITIAL (decl
)))))
1253 SYMBOL_REF_FLAG (XEXP (rtl
, 0)) = 1;
1257 mmix_strip_name_encoding (const char *name
)
1259 for (; (*name
== '@' || *name
== '*'); name
++)
1265 /* TARGET_ASM_FILE_START.
1266 We just emit a little comment for the time being. */
1269 mmix_file_start (void)
1271 default_file_start ();
1273 fputs ("! mmixal:= 8H LOC Data_Section\n", asm_out_file
);
1275 /* Make sure each file starts with the text section. */
1276 switch_to_section (text_section
);
1279 /* TARGET_ASM_FILE_END. */
1282 mmix_file_end (void)
1284 /* Make sure each file ends with the data section. */
1285 switch_to_section (data_section
);
1288 /* TARGET_ASM_OUTPUT_SOURCE_FILENAME. */
1291 mmix_asm_output_source_filename (FILE *stream
, const char *name
)
1293 fprintf (stream
, "# 1 ");
1294 OUTPUT_QUOTED_STRING (stream
, name
);
1295 fprintf (stream
, "\n");
1298 /* OUTPUT_QUOTED_STRING. */
1301 mmix_output_quoted_string (FILE *stream
, const char *string
, int length
)
1303 const char * string_end
= string
+ length
;
1304 static const char *const unwanted_chars
= "\"[]\\";
1306 /* Output "any character except newline and double quote character". We
1307 play it safe and avoid all control characters too. We also do not
1308 want [] as characters, should input be passed through m4 with [] as
1309 quotes. Further, we avoid "\", because the GAS port handles it as a
1310 quoting character. */
1311 while (string
< string_end
)
1314 && (unsigned char) *string
< 128
1315 && !ISCNTRL (*string
)
1316 && strchr (unwanted_chars
, *string
) == NULL
)
1318 fputc ('"', stream
);
1320 && (unsigned char) *string
< 128
1321 && !ISCNTRL (*string
)
1322 && strchr (unwanted_chars
, *string
) == NULL
1323 && string
< string_end
)
1325 fputc (*string
, stream
);
1328 fputc ('"', stream
);
1329 if (string
< string_end
)
1330 fprintf (stream
, ",");
1332 if (string
< string_end
)
1334 fprintf (stream
, "#%x", *string
& 255);
1336 if (string
< string_end
)
1337 fprintf (stream
, ",");
1342 /* Target hook for assembling integer objects. Use mmix_print_operand
1343 for WYDE and TETRA. Use mmix_output_octa to output 8-byte
1347 mmix_assemble_integer (rtx x
, unsigned int size
, int aligned_p
)
1352 /* We handle a limited number of types of operands in here. But
1353 that's ok, because we can punt to generic functions. We then
1354 pretend that aligned data isn't needed, so the usual .<pseudo>
1355 syntax is used (which works for aligned data too). We actually
1356 *must* do that, since we say we don't have simple aligned
1357 pseudos, causing this function to be called. We just try and
1358 keep as much compatibility as possible with mmixal syntax for
1359 normal cases (i.e. without GNU extensions and C only). */
1361 if (GET_CODE (x
) != CONST_INT
)
1366 fputs ("\tBYTE\t", asm_out_file
);
1367 mmix_print_operand (asm_out_file
, x
, 'B');
1368 fputc ('\n', asm_out_file
);
1372 if (GET_CODE (x
) != CONST_INT
)
1377 fputs ("\tWYDE\t", asm_out_file
);
1378 mmix_print_operand (asm_out_file
, x
, 'W');
1379 fputc ('\n', asm_out_file
);
1383 if (GET_CODE (x
) != CONST_INT
)
1388 fputs ("\tTETRA\t", asm_out_file
);
1389 mmix_print_operand (asm_out_file
, x
, 'L');
1390 fputc ('\n', asm_out_file
);
1394 /* We don't get here anymore for CONST_DOUBLE, because DImode
1395 isn't expressed as CONST_DOUBLE, and DFmode is handled
1397 gcc_assert (GET_CODE (x
) != CONST_DOUBLE
);
1398 assemble_integer_with_op ("\tOCTA\t", x
);
1401 return default_assemble_integer (x
, size
, aligned_p
);
1404 /* ASM_OUTPUT_ASCII. */
1407 mmix_asm_output_ascii (FILE *stream
, const char *string
, int length
)
1411 int chunk_size
= length
> 60 ? 60 : length
;
1412 fprintf (stream
, "\tBYTE ");
1413 mmix_output_quoted_string (stream
, string
, chunk_size
);
1414 string
+= chunk_size
;
1415 length
-= chunk_size
;
1416 fprintf (stream
, "\n");
1420 /* ASM_OUTPUT_ALIGNED_COMMON. */
1423 mmix_asm_output_aligned_common (FILE *stream
,
1428 /* This is mostly the elfos.h one. There doesn't seem to be a way to
1429 express this in a mmixal-compatible way. */
1430 fprintf (stream
, "\t.comm\t");
1431 assemble_name (stream
, name
);
1432 fprintf (stream
, ",%u,%u ! mmixal-incompatible COMMON\n",
1433 size
, align
/ BITS_PER_UNIT
);
1436 /* ASM_OUTPUT_ALIGNED_LOCAL. */
1439 mmix_asm_output_aligned_local (FILE *stream
,
1444 switch_to_section (data_section
);
1446 ASM_OUTPUT_ALIGN (stream
, exact_log2 (align
/BITS_PER_UNIT
));
1447 assemble_name (stream
, name
);
1448 fprintf (stream
, "\tLOC @+%d\n", size
);
1451 /* ASM_OUTPUT_LABEL. */
1454 mmix_asm_output_label (FILE *stream
, const char *name
)
1456 assemble_name (stream
, name
);
1457 fprintf (stream
, "\tIS @\n");
1460 /* ASM_OUTPUT_INTERNAL_LABEL. */
1463 mmix_asm_output_internal_label (FILE *stream
, const char *name
)
1465 assemble_name_raw (stream
, name
);
1466 fprintf (stream
, "\tIS @\n");
1469 /* ASM_DECLARE_REGISTER_GLOBAL. */
1472 mmix_asm_declare_register_global (FILE *stream ATTRIBUTE_UNUSED
,
1473 tree decl ATTRIBUTE_UNUSED
,
1474 int regno ATTRIBUTE_UNUSED
,
1475 const char *name ATTRIBUTE_UNUSED
)
1477 /* Nothing to do here, but there *will* be, therefore the framework is
1481 /* ASM_WEAKEN_LABEL. */
1484 mmix_asm_weaken_label (FILE *stream ATTRIBUTE_UNUSED
,
1485 const char *name ATTRIBUTE_UNUSED
)
1487 fprintf (stream
, "\t.weak ");
1488 assemble_name (stream
, name
);
1489 fprintf (stream
, " ! mmixal-incompatible\n");
1492 /* MAKE_DECL_ONE_ONLY. */
1495 mmix_make_decl_one_only (tree decl
)
1497 DECL_WEAK (decl
) = 1;
1500 /* ASM_OUTPUT_LABELREF.
1501 Strip GCC's '*' and our own '@'. No order is assumed. */
1504 mmix_asm_output_labelref (FILE *stream
, const char *name
)
1508 for (; (*name
== '@' || *name
== '*'); name
++)
1512 asm_fprintf (stream
, "%s%U%s",
1513 is_extern
&& TARGET_TOPLEVEL_SYMBOLS
? ":" : "",
1517 /* ASM_OUTPUT_DEF. */
1520 mmix_asm_output_def (FILE *stream
, const char *name
, const char *value
)
1522 assemble_name (stream
, name
);
1523 fprintf (stream
, "\tIS ");
1524 assemble_name (stream
, value
);
1525 fputc ('\n', stream
);
1528 /* TARGET_PRINT_OPERAND. */
1531 mmix_print_operand (FILE *stream
, rtx x
, int code
)
1533 /* When we add support for different codes later, we can, when needed,
1534 drop through to the main handler with a modified operand. */
1536 int regno
= x
!= NULL_RTX
&& REG_P (x
) ? REGNO (x
) : 0;
1540 /* Unrelated codes are in alphabetic order. */
1543 /* For conditional branches, output "P" for a probable branch. */
1544 if (TARGET_BRANCH_PREDICT
)
1546 x
= find_reg_note (current_output_insn
, REG_BR_PROB
, 0);
1547 if (x
&& XINT (x
, 0) > REG_BR_PROB_BASE
/ 2)
1553 /* For the %d in POP %d,0. */
1554 fprintf (stream
, "%d", MMIX_POP_ARGUMENT ());
1558 if (GET_CODE (x
) != CONST_INT
)
1559 fatal_insn ("MMIX Internal: Expected a CONST_INT, not this", x
);
1560 fprintf (stream
, "%d", (int) (INTVAL (x
) & 0xff));
1564 /* Highpart. Must be general register, and not the last one, as
1565 that one cannot be part of a consecutive register pair. */
1566 if (regno
> MMIX_LAST_GENERAL_REGISTER
- 1)
1567 internal_error ("MMIX Internal: Bad register: %d", regno
);
1569 /* This is big-endian, so the high-part is the first one. */
1570 fprintf (stream
, "%s", reg_names
[MMIX_OUTPUT_REGNO (regno
)]);
1574 /* Lowpart. Must be CONST_INT or general register, and not the last
1575 one, as that one cannot be part of a consecutive register pair. */
1576 if (GET_CODE (x
) == CONST_INT
)
1578 fprintf (stream
, "#%lx",
1579 (unsigned long) (INTVAL (x
)
1580 & ((unsigned int) 0x7fffffff * 2 + 1)));
1584 if (GET_CODE (x
) == SYMBOL_REF
)
1586 output_addr_const (stream
, x
);
1590 if (regno
> MMIX_LAST_GENERAL_REGISTER
- 1)
1591 internal_error ("MMIX Internal: Bad register: %d", regno
);
1593 /* This is big-endian, so the low-part is + 1. */
1594 fprintf (stream
, "%s", reg_names
[MMIX_OUTPUT_REGNO (regno
) + 1]);
1597 /* Can't use 'a' because that's a generic modifier for address
1600 mmix_output_shiftvalue_op_from_str (stream
, "ANDN",
1606 mmix_output_shiftvalue_op_from_str (stream
, "INC",
1612 mmix_output_shiftvalue_op_from_str (stream
, "OR",
1618 mmix_output_shiftvalue_op_from_str (stream
, "SET",
1625 mmix_output_condition (stream
, x
, (code
== 'D'));
1629 /* Output an extra "e" to make fcmpe, fune. */
1630 if (TARGET_FCMP_EPSILON
)
1631 fprintf (stream
, "e");
1635 /* Output the number minus 1. */
1636 if (GET_CODE (x
) != CONST_INT
)
1638 fatal_insn ("MMIX Internal: Bad value for 'm', not a CONST_INT",
1641 fprintf (stream
, "%" PRId64
,
1642 (int64_t) (mmix_intval (x
) - 1));
1646 /* Store the number of registers we want to save. This was setup
1647 by the prologue. The actual operand contains the number of
1648 registers to pass, but we don't use it currently. Anyway, we
1649 need to output the number of saved registers here. */
1650 fprintf (stream
, "%d",
1651 cfun
->machine
->highest_saved_stack_register
+ 1);
1655 /* Store the register to output a constant to. */
1657 fatal_insn ("MMIX Internal: Expected a register, not this", x
);
1658 mmix_output_destination_register
= MMIX_OUTPUT_REGNO (regno
);
1662 /* Output the constant. Note that we use this for floats as well. */
1663 if (GET_CODE (x
) != CONST_INT
1664 && (GET_CODE (x
) != CONST_DOUBLE
1665 || (GET_MODE (x
) != VOIDmode
&& GET_MODE (x
) != DFmode
1666 && GET_MODE (x
) != SFmode
)))
1667 fatal_insn ("MMIX Internal: Expected a constant, not this", x
);
1668 mmix_output_register_setting (stream
,
1669 mmix_output_destination_register
,
1670 mmix_intval (x
), 0);
1674 /* An U for unsigned, if TARGET_ZERO_EXTEND. Ignore the operand. */
1675 if (TARGET_ZERO_EXTEND
)
1680 mmix_output_shifted_value (stream
, (int64_t) mmix_intval (x
));
1684 mmix_output_shifted_value (stream
, (int64_t) ~mmix_intval (x
));
1688 if (GET_CODE (x
) != CONST_INT
)
1689 fatal_insn ("MMIX Internal: Expected a CONST_INT, not this", x
);
1690 fprintf (stream
, "#%x", (int) (INTVAL (x
) & 0xffff));
1694 /* Nothing to do. */
1698 /* Presumably there's a missing case above if we get here. */
1699 internal_error ("MMIX Internal: Missing %qc case in mmix_print_operand", code
);
1702 switch (GET_CODE (modified_x
))
1705 regno
= REGNO (modified_x
);
1706 if (regno
>= FIRST_PSEUDO_REGISTER
)
1707 internal_error ("MMIX Internal: Bad register: %d", regno
);
1708 fprintf (stream
, "%s", reg_names
[MMIX_OUTPUT_REGNO (regno
)]);
1712 output_address (XEXP (modified_x
, 0));
1716 /* For -2147483648, mmixal complains that the constant does not fit
1717 in 4 bytes, so let's output it as hex. Take care to handle hosts
1718 where HOST_WIDE_INT is longer than an int.
1720 Print small constants +-255 using decimal. */
1722 if (INTVAL (modified_x
) > -256 && INTVAL (modified_x
) < 256)
1723 fprintf (stream
, "%d", (int) (INTVAL (modified_x
)));
1725 fprintf (stream
, "#%x",
1726 (int) (INTVAL (modified_x
)) & (unsigned int) ~0);
1730 /* Do somewhat as CONST_INT. */
1731 mmix_output_octa (stream
, mmix_intval (modified_x
), 0);
1735 output_addr_const (stream
, modified_x
);
1739 /* No need to test for all strange things. Let output_addr_const do
1741 if (CONSTANT_P (modified_x
)
1742 /* Strangely enough, this is not included in CONSTANT_P.
1743 FIXME: Ask/check about sanity here. */
1744 || LABEL_P (modified_x
))
1746 output_addr_const (stream
, modified_x
);
1750 /* We need the original here. */
1751 fatal_insn ("MMIX Internal: Cannot decode this operand", x
);
1755 /* TARGET_PRINT_OPERAND_PUNCT_VALID_P. */
1758 mmix_print_operand_punct_valid_p (unsigned char code
)
1760 /* A '+' is used for branch prediction, similar to other ports. */
1762 /* A '.' is used for the %d in the POP %d,0 return insn. */
1766 /* TARGET_PRINT_OPERAND_ADDRESS. */
1769 mmix_print_operand_address (FILE *stream
, rtx x
)
1773 /* I find the generated assembly code harder to read without
1775 fprintf (stream
, "%s,0", reg_names
[MMIX_OUTPUT_REGNO (REGNO (x
))]);
1778 else if (GET_CODE (x
) == PLUS
)
1780 rtx x1
= XEXP (x
, 0);
1781 rtx x2
= XEXP (x
, 1);
1785 fprintf (stream
, "%s,", reg_names
[MMIX_OUTPUT_REGNO (REGNO (x1
))]);
1789 fprintf (stream
, "%s",
1790 reg_names
[MMIX_OUTPUT_REGNO (REGNO (x2
))]);
1793 else if (satisfies_constraint_I (x2
))
1795 output_addr_const (stream
, x2
);
1801 if (TARGET_BASE_ADDRESSES
&& mmix_legitimate_constant_p (Pmode
, x
))
1803 output_addr_const (stream
, x
);
1807 fatal_insn ("MMIX Internal: This is not a recognized address", x
);
1810 /* ASM_OUTPUT_REG_PUSH. */
1813 mmix_asm_output_reg_push (FILE *stream
, int regno
)
1815 fprintf (stream
, "\tSUBU %s,%s,8\n\tSTOU %s,%s,0\n",
1816 reg_names
[MMIX_STACK_POINTER_REGNUM
],
1817 reg_names
[MMIX_STACK_POINTER_REGNUM
],
1818 reg_names
[MMIX_OUTPUT_REGNO (regno
)],
1819 reg_names
[MMIX_STACK_POINTER_REGNUM
]);
1822 /* ASM_OUTPUT_REG_POP. */
1825 mmix_asm_output_reg_pop (FILE *stream
, int regno
)
1827 fprintf (stream
, "\tLDOU %s,%s,0\n\tINCL %s,8\n",
1828 reg_names
[MMIX_OUTPUT_REGNO (regno
)],
1829 reg_names
[MMIX_STACK_POINTER_REGNUM
],
1830 reg_names
[MMIX_STACK_POINTER_REGNUM
]);
1833 /* ASM_OUTPUT_ADDR_DIFF_ELT. */
1836 mmix_asm_output_addr_diff_elt (FILE *stream
,
1837 rtx body ATTRIBUTE_UNUSED
,
1841 fprintf (stream
, "\tTETRA L%d-L%d\n", value
, rel
);
1844 /* ASM_OUTPUT_ADDR_VEC_ELT. */
1847 mmix_asm_output_addr_vec_elt (FILE *stream
, int value
)
1849 fprintf (stream
, "\tOCTA L:%d\n", value
);
1852 /* ASM_OUTPUT_SKIP. */
1855 mmix_asm_output_skip (FILE *stream
, int nbytes
)
1857 fprintf (stream
, "\tLOC @+%d\n", nbytes
);
1860 /* ASM_OUTPUT_ALIGN. */
1863 mmix_asm_output_align (FILE *stream
, int power
)
1865 /* We need to record the needed alignment of this section in the object,
1866 so we have to output an alignment directive. Use a .p2align (not
1867 .align) so people will never have to wonder about whether the
1868 argument is in number of bytes or the log2 thereof. We do it in
1869 addition to the LOC directive, so nothing needs tweaking when
1870 copy-pasting assembly into mmixal. */
1871 fprintf (stream
, "\t.p2align %d\n", power
);
1872 fprintf (stream
, "\tLOC @+(%d-@)&%d\n", 1 << power
, (1 << power
) - 1);
1875 /* DBX_REGISTER_NUMBER. */
1878 mmix_dbx_register_number (unsigned regno
)
1880 /* Adjust the register number to the one it will be output as, dammit.
1881 It'd be nice if we could check the assumption that we're filling a
1882 gap, but every register between the last saved register and parameter
1883 registers might be a valid parameter register. */
1884 regno
= MMIX_OUTPUT_REGNO (regno
);
1886 /* We need to renumber registers to get the number of the return address
1887 register in the range 0..255. It is also space-saving if registers
1888 mentioned in the call-frame information (which uses this function by
1889 defaulting DWARF_FRAME_REGNUM to DBX_REGISTER_NUMBER) are numbered
1890 0 .. 63. So map 224 .. 256+15 -> 0 .. 47 and 0 .. 223 -> 48..223+48. */
1891 return regno
>= 224 ? (regno
- 224) : (regno
+ 48);
1894 /* End of target macro support functions.
1896 Now the MMIX port's own functions. First the exported ones. */
1898 /* Wrapper for get_hard_reg_initial_val since integrate.h isn't included
1899 from insn-emit.c. */
1902 mmix_get_hard_reg_initial_val (machine_mode mode
, int regno
)
1904 return get_hard_reg_initial_val (mode
, regno
);
1907 /* Nonzero when the function epilogue is simple enough that a single
1908 "POP %d,0" should be used even within the function. */
1911 mmix_use_simple_return (void)
1915 int stack_space_to_allocate
1916 = (crtl
->outgoing_args_size
1917 + crtl
->args
.pretend_args_size
1918 + get_frame_size () + 7) & ~7;
1920 if (!TARGET_USE_RETURN_INSN
|| !reload_completed
)
1924 regno
>= MMIX_FIRST_GLOBAL_REGNUM
;
1926 /* Note that we assume that the frame-pointer-register is one of these
1927 registers, in which case we don't count it here. */
1928 if ((((regno
!= MMIX_FRAME_POINTER_REGNUM
|| !frame_pointer_needed
)
1929 && df_regs_ever_live_p (regno
) && !call_used_regs
[regno
]))
1930 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
1933 if (frame_pointer_needed
)
1934 stack_space_to_allocate
+= 8;
1936 if (MMIX_CFUN_HAS_LANDING_PAD
)
1937 stack_space_to_allocate
+= 16;
1938 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
)
1939 stack_space_to_allocate
+= 8;
1941 return stack_space_to_allocate
== 0;
1945 /* Expands the function prologue into RTX. */
1948 mmix_expand_prologue (void)
1950 HOST_WIDE_INT locals_size
= get_frame_size ();
1952 HOST_WIDE_INT stack_space_to_allocate
1953 = (crtl
->outgoing_args_size
1954 + crtl
->args
.pretend_args_size
1955 + locals_size
+ 7) & ~7;
1956 HOST_WIDE_INT offset
= -8;
1958 /* Add room needed to save global non-register-stack registers. */
1960 regno
>= MMIX_FIRST_GLOBAL_REGNUM
;
1962 /* Note that we assume that the frame-pointer-register is one of these
1963 registers, in which case we don't count it here. */
1964 if ((((regno
!= MMIX_FRAME_POINTER_REGNUM
|| !frame_pointer_needed
)
1965 && df_regs_ever_live_p (regno
) && !call_used_regs
[regno
]))
1966 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
1967 stack_space_to_allocate
+= 8;
1969 /* If we do have a frame-pointer, add room for it. */
1970 if (frame_pointer_needed
)
1971 stack_space_to_allocate
+= 8;
1973 /* If we have a non-local label, we need to be able to unwind to it, so
1974 store the current register stack pointer. Also store the return
1975 address if we do that. */
1976 if (MMIX_CFUN_HAS_LANDING_PAD
)
1977 stack_space_to_allocate
+= 16;
1978 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
)
1979 /* If we do have a saved return-address slot, add room for it. */
1980 stack_space_to_allocate
+= 8;
1982 /* Make sure we don't get an unaligned stack. */
1983 if ((stack_space_to_allocate
% 8) != 0)
1984 internal_error ("stack frame not a multiple of 8 bytes: %wd",
1985 stack_space_to_allocate
);
1987 if (crtl
->args
.pretend_args_size
)
1989 int mmix_first_vararg_reg
1990 = (MMIX_FIRST_INCOMING_ARG_REGNUM
1991 + (MMIX_MAX_ARGS_IN_REGS
1992 - crtl
->args
.pretend_args_size
/ 8));
1995 = MMIX_FIRST_INCOMING_ARG_REGNUM
+ MMIX_MAX_ARGS_IN_REGS
- 1;
1996 regno
>= mmix_first_vararg_reg
;
2001 HOST_WIDE_INT stack_chunk
2002 = stack_space_to_allocate
> (256 - 8)
2003 ? (256 - 8) : stack_space_to_allocate
;
2005 mmix_emit_sp_add (-stack_chunk
);
2006 offset
+= stack_chunk
;
2007 stack_space_to_allocate
-= stack_chunk
;
2010 /* These registers aren't actually saved (as in "will be
2011 restored"), so don't tell DWARF2 they're saved. */
2012 emit_move_insn (gen_rtx_MEM (DImode
,
2013 plus_constant (Pmode
, stack_pointer_rtx
,
2015 gen_rtx_REG (DImode
, regno
));
2020 /* Store the frame-pointer. */
2022 if (frame_pointer_needed
)
2028 /* Get 8 less than otherwise, since we need to reach offset + 8. */
2029 HOST_WIDE_INT stack_chunk
2030 = stack_space_to_allocate
> (256 - 8 - 8)
2031 ? (256 - 8 - 8) : stack_space_to_allocate
;
2033 mmix_emit_sp_add (-stack_chunk
);
2035 offset
+= stack_chunk
;
2036 stack_space_to_allocate
-= stack_chunk
;
2039 insn
= emit_move_insn (gen_rtx_MEM (DImode
,
2040 plus_constant (Pmode
,
2043 hard_frame_pointer_rtx
);
2044 RTX_FRAME_RELATED_P (insn
) = 1;
2045 insn
= emit_insn (gen_adddi3 (hard_frame_pointer_rtx
,
2047 GEN_INT (offset
+ 8)));
2048 RTX_FRAME_RELATED_P (insn
) = 1;
2052 if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
)
2057 /* Store the return-address, if one is needed on the stack. We
2058 usually store it in a register when needed, but that doesn't work
2059 with -fexceptions. */
2063 /* Get 8 less than otherwise, since we need to reach offset + 8. */
2064 HOST_WIDE_INT stack_chunk
2065 = stack_space_to_allocate
> (256 - 8 - 8)
2066 ? (256 - 8 - 8) : stack_space_to_allocate
;
2068 mmix_emit_sp_add (-stack_chunk
);
2070 offset
+= stack_chunk
;
2071 stack_space_to_allocate
-= stack_chunk
;
2074 tmpreg
= gen_rtx_REG (DImode
, 255);
2075 retreg
= gen_rtx_REG (DImode
, MMIX_rJ_REGNUM
);
2077 /* Dwarf2 code is confused by the use of a temporary register for
2078 storing the return address, so we have to express it as a note,
2079 which we attach to the actual store insn. */
2080 emit_move_insn (tmpreg
, retreg
);
2082 insn
= emit_move_insn (gen_rtx_MEM (DImode
,
2083 plus_constant (Pmode
,
2087 RTX_FRAME_RELATED_P (insn
) = 1;
2088 add_reg_note (insn
, REG_FRAME_RELATED_EXPR
,
2089 gen_rtx_SET (gen_rtx_MEM (DImode
,
2090 plus_constant (Pmode
,
2097 else if (MMIX_CFUN_HAS_LANDING_PAD
)
2100 if (MMIX_CFUN_HAS_LANDING_PAD
)
2102 /* Store the register defining the numbering of local registers, so
2103 we know how long to unwind the register stack. */
2107 /* Get 8 less than otherwise, since we need to reach offset + 8. */
2108 HOST_WIDE_INT stack_chunk
2109 = stack_space_to_allocate
> (256 - 8 - 8)
2110 ? (256 - 8 - 8) : stack_space_to_allocate
;
2112 mmix_emit_sp_add (-stack_chunk
);
2114 offset
+= stack_chunk
;
2115 stack_space_to_allocate
-= stack_chunk
;
2118 /* We don't tell dwarf2 about this one; we just have it to unwind
2119 the register stack at landing pads. FIXME: It's a kludge because
2120 we can't describe the effect of the PUSHJ and PUSHGO insns on the
2121 register stack at the moment. Best thing would be to handle it
2122 like stack-pointer offsets. Better: some hook into dwarf2out.c
2123 to produce DW_CFA_expression:s that specify the increment of rO,
2124 and unwind it at eh_return (preferred) or at the landing pad.
2125 Then saves to $0..$G-1 could be specified through that register. */
2127 emit_move_insn (gen_rtx_REG (DImode
, 255),
2128 gen_rtx_REG (DImode
,
2130 emit_move_insn (gen_rtx_MEM (DImode
,
2131 plus_constant (Pmode
, stack_pointer_rtx
,
2133 gen_rtx_REG (DImode
, 255));
2137 /* After the return-address and the frame-pointer, we have the local
2138 variables. They're the ones that may have an "unaligned" size. */
2139 offset
-= (locals_size
+ 7) & ~7;
2141 /* Now store all registers that are global, i.e. not saved by the
2142 register file machinery.
2144 It is assumed that the frame-pointer is one of these registers, so it
2145 is explicitly excluded in the count. */
2148 regno
>= MMIX_FIRST_GLOBAL_REGNUM
;
2150 if (((regno
!= MMIX_FRAME_POINTER_REGNUM
|| !frame_pointer_needed
)
2151 && df_regs_ever_live_p (regno
) && ! call_used_regs
[regno
])
2152 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
2158 HOST_WIDE_INT stack_chunk
2159 = (stack_space_to_allocate
> (256 - offset
- 8)
2160 ? (256 - offset
- 8) : stack_space_to_allocate
);
2162 mmix_emit_sp_add (-stack_chunk
);
2163 offset
+= stack_chunk
;
2164 stack_space_to_allocate
-= stack_chunk
;
2167 insn
= emit_move_insn (gen_rtx_MEM (DImode
,
2168 plus_constant (Pmode
,
2171 gen_rtx_REG (DImode
, regno
));
2172 RTX_FRAME_RELATED_P (insn
) = 1;
2176 /* Finally, allocate room for outgoing args and local vars if room
2177 wasn't allocated above. */
2178 if (stack_space_to_allocate
)
2179 mmix_emit_sp_add (-stack_space_to_allocate
);
2182 /* Expands the function epilogue into RTX. */
2185 mmix_expand_epilogue (void)
2187 HOST_WIDE_INT locals_size
= get_frame_size ();
2189 HOST_WIDE_INT stack_space_to_deallocate
2190 = (crtl
->outgoing_args_size
2191 + crtl
->args
.pretend_args_size
2192 + locals_size
+ 7) & ~7;
2194 /* The first address to access is beyond the outgoing_args area. */
2195 HOST_WIDE_INT offset
= crtl
->outgoing_args_size
;
2197 /* Add the space for global non-register-stack registers.
2198 It is assumed that the frame-pointer register can be one of these
2199 registers, in which case it is excluded from the count when needed. */
2201 regno
>= MMIX_FIRST_GLOBAL_REGNUM
;
2203 if (((regno
!= MMIX_FRAME_POINTER_REGNUM
|| !frame_pointer_needed
)
2204 && df_regs_ever_live_p (regno
) && !call_used_regs
[regno
])
2205 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
2206 stack_space_to_deallocate
+= 8;
2208 /* Add in the space for register stack-pointer. If so, always add room
2209 for the saved PC. */
2210 if (MMIX_CFUN_HAS_LANDING_PAD
)
2211 stack_space_to_deallocate
+= 16;
2212 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
)
2213 /* If we have a saved return-address slot, add it in. */
2214 stack_space_to_deallocate
+= 8;
2216 /* Add in the frame-pointer. */
2217 if (frame_pointer_needed
)
2218 stack_space_to_deallocate
+= 8;
2220 /* Make sure we don't get an unaligned stack. */
2221 if ((stack_space_to_deallocate
% 8) != 0)
2222 internal_error ("stack frame not a multiple of octabyte: %wd",
2223 stack_space_to_deallocate
);
2225 /* We will add back small offsets to the stack pointer as we go.
2226 First, we restore all registers that are global, i.e. not saved by
2227 the register file machinery. */
2229 for (regno
= MMIX_FIRST_GLOBAL_REGNUM
;
2232 if (((regno
!= MMIX_FRAME_POINTER_REGNUM
|| !frame_pointer_needed
)
2233 && df_regs_ever_live_p (regno
) && !call_used_regs
[regno
])
2234 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
2238 mmix_emit_sp_add (offset
);
2239 stack_space_to_deallocate
-= offset
;
2243 emit_move_insn (gen_rtx_REG (DImode
, regno
),
2244 gen_rtx_MEM (DImode
,
2245 plus_constant (Pmode
, stack_pointer_rtx
,
2250 /* Here is where the local variables were. As in the prologue, they
2251 might be of an unaligned size. */
2252 offset
+= (locals_size
+ 7) & ~7;
2254 /* The saved register stack pointer is just below the frame-pointer
2255 register. We don't need to restore it "manually"; the POP
2256 instruction does that. */
2257 if (MMIX_CFUN_HAS_LANDING_PAD
)
2259 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
)
2260 /* The return-address slot is just below the frame-pointer register.
2261 We don't need to restore it because we don't really use it. */
2264 /* Get back the old frame-pointer-value. */
2265 if (frame_pointer_needed
)
2269 mmix_emit_sp_add (offset
);
2271 stack_space_to_deallocate
-= offset
;
2275 emit_move_insn (hard_frame_pointer_rtx
,
2276 gen_rtx_MEM (DImode
,
2277 plus_constant (Pmode
, stack_pointer_rtx
,
2282 /* We do not need to restore pretended incoming args, just add back
2284 if (stack_space_to_deallocate
!= 0)
2285 mmix_emit_sp_add (stack_space_to_deallocate
);
2287 if (crtl
->calls_eh_return
)
2288 /* Adjust the (normal) stack-pointer to that of the receiver.
2289 FIXME: It would be nice if we could also adjust the register stack
2290 here, but we need to express it through DWARF 2 too. */
2291 emit_insn (gen_adddi3 (stack_pointer_rtx
, stack_pointer_rtx
,
2292 gen_rtx_REG (DImode
,
2293 MMIX_EH_RETURN_STACKADJ_REGNUM
)));
2296 /* Output an optimal sequence for setting a register to a specific
2297 constant. Used in an alternative for const_ints in movdi, and when
2298 using large stack-frame offsets.
2300 Use do_begin_end to say if a line-starting TAB and newline before the
2301 first insn and after the last insn is wanted. */
2304 mmix_output_register_setting (FILE *stream
,
2310 fprintf (stream
, "\t");
2312 if (insn_const_int_ok_for_constraint (value
, CONSTRAINT_K
))
2313 fprintf (stream
, "NEGU %s,0,%" PRId64
, reg_names
[regno
], -value
);
2314 else if (mmix_shiftable_wyde_value ((uint64_t) value
))
2316 /* First, the one-insn cases. */
2317 mmix_output_shiftvalue_op_from_str (stream
, "SET",
2320 fprintf (stream
, " %s,", reg_names
[regno
]);
2321 mmix_output_shifted_value (stream
, (uint64_t) value
);
2323 else if (mmix_shiftable_wyde_value (-(uint64_t) value
))
2325 /* We do this to get a bit more legible assembly code. The next
2326 alternative is mostly redundant with this. */
2328 mmix_output_shiftvalue_op_from_str (stream
, "SET",
2331 fprintf (stream
, " %s,", reg_names
[regno
]);
2332 mmix_output_shifted_value (stream
, -(uint64_t) value
);
2333 fprintf (stream
, "\n\tNEGU %s,0,%s", reg_names
[regno
],
2336 else if (mmix_shiftable_wyde_value (~(uint64_t) value
))
2338 /* Slightly more expensive, the two-insn cases. */
2340 /* FIXME: We could of course also test if 0..255-N or ~(N | 1..255)
2341 is shiftable, or any other one-insn transformation of the value.
2342 FIXME: Check first if the value is "shiftable" by two loading
2343 with two insns, since it makes more readable assembly code (if
2344 anyone else cares). */
2346 mmix_output_shiftvalue_op_from_str (stream
, "SET",
2349 fprintf (stream
, " %s,", reg_names
[regno
]);
2350 mmix_output_shifted_value (stream
, ~(uint64_t) value
);
2351 fprintf (stream
, "\n\tNOR %s,%s,0", reg_names
[regno
],
2356 /* The generic case. 2..4 insns. */
2357 static const char *const higher_parts
[] = {"L", "ML", "MH", "H"};
2358 const char *op
= "SET";
2359 const char *line_begin
= "";
2362 int64_t tmpvalue
= value
;
2364 /* Compute the number of insns needed to output this constant. */
2365 for (i
= 0; i
< 4 && tmpvalue
!= 0; i
++)
2367 if (tmpvalue
& 65535)
2371 if (TARGET_BASE_ADDRESSES
&& insns
== 3)
2373 /* The number three is based on a static observation on
2374 ghostscript-6.52. Two and four are excluded because there
2375 are too many such constants, and each unique constant (maybe
2376 offset by 1..255) were used few times compared to other uses,
2379 We use base-plus-offset addressing to force it into a global
2380 register; we just use a "LDA reg,VALUE", which will cause the
2381 assembler and linker to DTRT (for constants as well as
2383 fprintf (stream
, "LDA %s,", reg_names
[regno
]);
2384 mmix_output_octa (stream
, value
, 0);
2388 /* Output pertinent parts of the 4-wyde sequence.
2389 Still more to do if we want this to be optimal, but hey...
2390 Note that the zero case has been handled above. */
2391 for (i
= 0; i
< 4 && value
!= 0; i
++)
2395 fprintf (stream
, "%s%s%s %s,#%x", line_begin
, op
,
2396 higher_parts
[i
], reg_names
[regno
],
2397 (int) (value
& 65535));
2398 /* The first one sets the rest of the bits to 0, the next
2399 ones add set bits. */
2401 line_begin
= "\n\t";
2410 fprintf (stream
, "\n");
2413 /* Return 1 if value is 0..65535*2**(16*N) for N=0..3.
2417 mmix_shiftable_wyde_value (uint64_t value
)
2419 /* Shift by 16 bits per group, stop when we've found two groups with
2422 int has_candidate
= 0;
2424 for (i
= 0; i
< 4; i
++)
2440 /* X and Y are two things to compare using CODE. Return the rtx for
2441 the cc-reg in the proper mode. */
2444 mmix_gen_compare_reg (RTX_CODE code
, rtx x
, rtx y
)
2446 machine_mode ccmode
= SELECT_CC_MODE (code
, x
, y
);
2447 return gen_reg_rtx (ccmode
);
2450 /* Local (static) helper functions. */
2453 mmix_emit_sp_add (HOST_WIDE_INT offset
)
2459 /* Negative stack-pointer adjustments are allocations and appear in
2460 the prologue only. We mark them as frame-related so unwind and
2461 debug info is properly emitted for them. */
2463 insn
= emit_insn (gen_adddi3 (stack_pointer_rtx
,
2468 rtx tmpr
= gen_rtx_REG (DImode
, 255);
2469 RTX_FRAME_RELATED_P (emit_move_insn (tmpr
, GEN_INT (offset
))) = 1;
2470 insn
= emit_insn (gen_adddi3 (stack_pointer_rtx
,
2471 stack_pointer_rtx
, tmpr
));
2473 RTX_FRAME_RELATED_P (insn
) = 1;
2477 /* Positive adjustments are in the epilogue only. Don't mark them
2478 as "frame-related" for unwind info. */
2479 if (insn_const_int_ok_for_constraint (offset
, CONSTRAINT_L
))
2480 emit_insn (gen_adddi3 (stack_pointer_rtx
,
2485 rtx tmpr
= gen_rtx_REG (DImode
, 255);
2486 emit_move_insn (tmpr
, GEN_INT (offset
));
2487 insn
= emit_insn (gen_adddi3 (stack_pointer_rtx
,
2488 stack_pointer_rtx
, tmpr
));
2493 /* Print operator suitable for doing something with a shiftable
2494 wyde. The type of operator is passed as an asm output modifier. */
2497 mmix_output_shiftvalue_op_from_str (FILE *stream
,
2501 static const char *const op_part
[] = {"L", "ML", "MH", "H"};
2504 if (! mmix_shiftable_wyde_value (value
))
2506 char s
[sizeof ("0xffffffffffffffff")];
2507 sprintf (s
, "%#" PRIx64
, value
);
2508 internal_error ("MMIX Internal: %s is not a shiftable int", s
);
2511 for (i
= 0; i
< 4; i
++)
2513 /* We know we're through when we find one-bits in the low
2517 fprintf (stream
, "%s%s", mainop
, op_part
[i
]);
2523 /* No bits set? Then it must have been zero. */
2524 fprintf (stream
, "%sL", mainop
);
2527 /* Print a 64-bit value, optionally prefixed by assembly pseudo. */
2530 mmix_output_octa (FILE *stream
, int64_t value
, int do_begin_end
)
2533 fprintf (stream
, "\tOCTA ");
2535 /* Provide a few alternative output formats depending on the number, to
2536 improve legibility of assembler output. */
2537 if ((value
< (int64_t) 0 && value
> (int64_t) -10000)
2538 || (value
>= (int64_t) 0 && value
<= (int64_t) 16384))
2539 fprintf (stream
, "%d", (int) value
);
2540 else if (value
> (int64_t) 0
2541 && value
< ((int64_t) 1 << 31) * 2)
2542 fprintf (stream
, "#%x", (unsigned int) value
);
2543 else if (sizeof (HOST_WIDE_INT
) == sizeof (int64_t))
2544 /* We need to avoid the not-so-universal "0x" prefix; we need the
2545 pure hex-digits together with the mmixal "#" hex prefix. */
2546 fprintf (stream
, "#" HOST_WIDE_INT_PRINT_HEX_PURE
,
2547 (HOST_WIDE_INT
) value
);
2548 else /* Need to avoid the hex output; there's no ...WIDEST...HEX_PURE. */
2549 fprintf (stream
, "%" PRIu64
, value
);
2552 fprintf (stream
, "\n");
2555 /* Print the presumed shiftable wyde argument shifted into place (to
2556 be output with an operand). */
2559 mmix_output_shifted_value (FILE *stream
, int64_t value
)
2563 if (! mmix_shiftable_wyde_value (value
))
2566 sprintf (s
, "%#" PRIx64
, value
);
2567 internal_error ("MMIX Internal: %s is not a shiftable int", s
);
2570 for (i
= 0; i
< 4; i
++)
2572 /* We know we're through when we find one-bits in the low 16 bits. */
2575 fprintf (stream
, "#%x", (int) (value
& 0xffff));
2582 /* No bits set? Then it must have been zero. */
2583 fprintf (stream
, "0");
2586 /* Output an MMIX condition name corresponding to an operator
2588 (comparison_operator [(comparison_operator ...) (const_int 0)])
2589 which means we have to look at *two* operators.
2591 The argument "reversed" refers to reversal of the condition (not the
2592 same as swapping the arguments). */
2595 mmix_output_condition (FILE *stream
, const_rtx x
, int reversed
)
2601 /* The normal output cc-code. */
2602 const char *const normal
;
2604 /* The reversed cc-code, or NULL if invalid. */
2605 const char *const reversed
;
2610 machine_mode cc_mode
;
2612 /* Terminated with {UNKNOWN, NULL, NULL} */
2613 const struct cc_conv
*const convs
;
2617 #define CCEND {UNKNOWN, NULL, NULL}
2619 static const struct cc_conv cc_fun_convs
[]
2620 = {{ORDERED
, "Z", "P"},
2621 {UNORDERED
, "P", "Z"},
2623 static const struct cc_conv cc_fp_convs
[]
2627 static const struct cc_conv cc_fpeq_convs
[]
2631 static const struct cc_conv cc_uns_convs
[]
2632 = {{GEU
, "NN", "N"},
2637 static const struct cc_conv cc_signed_convs
[]
2645 static const struct cc_conv cc_di_convs
[]
2657 static const struct cc_type_conv cc_convs
[]
2658 = {{CC_FUNmode
, cc_fun_convs
},
2659 {CC_FPmode
, cc_fp_convs
},
2660 {CC_FPEQmode
, cc_fpeq_convs
},
2661 {CC_UNSmode
, cc_uns_convs
},
2662 {CCmode
, cc_signed_convs
},
2663 {DImode
, cc_di_convs
}};
2668 machine_mode mode
= GET_MODE (XEXP (x
, 0));
2669 RTX_CODE cc
= GET_CODE (x
);
2671 for (i
= 0; i
< ARRAY_SIZE (cc_convs
); i
++)
2673 if (mode
== cc_convs
[i
].cc_mode
)
2675 for (j
= 0; cc_convs
[i
].convs
[j
].cc
!= UNKNOWN
; j
++)
2676 if (cc
== cc_convs
[i
].convs
[j
].cc
)
2679 = (reversed
? cc_convs
[i
].convs
[j
].reversed
2680 : cc_convs
[i
].convs
[j
].normal
);
2682 if (mmix_cc
== NULL
)
2683 fatal_insn ("MMIX Internal: Trying to output invalidly\
2684 reversed condition:", x
);
2686 fprintf (stream
, "%s", mmix_cc
);
2690 fatal_insn ("MMIX Internal: What's the CC of this?", x
);
2694 fatal_insn ("MMIX Internal: What is the CC of this?", x
);
2697 /* Return the bit-value for a const_int or const_double. */
2700 mmix_intval (const_rtx x
)
2702 if (GET_CODE (x
) == CONST_INT
)
2705 /* We make a little song and dance because converting to long long in
2706 gcc-2.7.2 is broken. I still want people to be able to use it for
2707 cross-compilation to MMIX. */
2708 if (GET_CODE (x
) == CONST_DOUBLE
&& GET_MODE (x
) == VOIDmode
)
2709 return CONST_DOUBLE_HIGH (x
);
2711 if (GET_CODE (x
) == CONST_DOUBLE
)
2713 REAL_VALUE_TYPE value
;
2715 /* FIXME: This macro is not in the manual but should be. */
2716 REAL_VALUE_FROM_CONST_DOUBLE (value
, x
);
2718 if (GET_MODE (x
) == DFmode
)
2722 REAL_VALUE_TO_TARGET_DOUBLE (value
, bits
);
2724 /* The double cast is necessary to avoid getting the long
2725 sign-extended to unsigned long long(!) when they're of
2726 different size (usually 32-bit hosts). */
2728 ((uint64_t) (unsigned long) bits
[0]
2730 | (uint64_t) (unsigned long) bits
[1];
2732 else if (GET_MODE (x
) == SFmode
)
2735 REAL_VALUE_TO_TARGET_SINGLE (value
, bits
);
2737 return (unsigned long) bits
;
2741 fatal_insn ("MMIX Internal: This is not a constant:", x
);
2744 /* Worker function for TARGET_PROMOTE_FUNCTION_MODE. */
2747 mmix_promote_function_mode (const_tree type ATTRIBUTE_UNUSED
,
2749 int *punsignedp ATTRIBUTE_UNUSED
,
2750 const_tree fntype ATTRIBUTE_UNUSED
,
2753 /* Apparently not doing TRT if int < register-size. FIXME: Perhaps
2754 FUNCTION_VALUE and LIBCALL_VALUE needs tweaking as some ports say. */
2755 if (for_return
== 1)
2758 /* Promotion of modes currently generates slow code, extending before
2759 operation, so we do it only for arguments. */
2760 if (GET_MODE_CLASS (mode
) == MODE_INT
2761 && GET_MODE_SIZE (mode
) < 8)
2766 /* Worker function for TARGET_STRUCT_VALUE_RTX. */
2769 mmix_struct_value_rtx (tree fntype ATTRIBUTE_UNUSED
,
2770 int incoming ATTRIBUTE_UNUSED
)
2772 return gen_rtx_REG (Pmode
, MMIX_STRUCT_VALUE_REGNUM
);
2775 /* Worker function for TARGET_FRAME_POINTER_REQUIRED.
2777 FIXME: Is this requirement built-in? Anyway, we should try to get rid
2778 of it; we can deduce the value. */
2781 mmix_frame_pointer_required (void)
2783 return (cfun
->has_nonlocal_label
);
2788 * eval: (c-set-style "gnu")
2789 * indent-tabs-mode: t