1 /* Definitions of target machine for GNU compiler, for MMIX.
2 Copyright (C) 2000-2024 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/>. */
21 #define IN_TARGET_CODE 1
25 #include "coretypes.h"
30 #include "stringpool.h"
35 #include "insn-config.h"
40 #include "diagnostic-core.h"
43 #include "stor-layout.h"
48 #include "tm-constrs.h"
51 /* This file should be included last. */
52 #include "target-def.h"
54 /* First some local helper definitions. */
55 #define MMIX_FIRST_GLOBAL_REGNUM 32
57 /* We'd need a current_function_has_landing_pad. It's marked as such when
58 a nonlocal_goto_receiver is expanded. Not just a C++ thing, but
60 #define MMIX_CFUN_HAS_LANDING_PAD (cfun->machine->has_landing_pad != 0)
62 /* We have no means to tell DWARF 2 about the register stack, so we need
63 to store the return address on the stack if an exception can get into
64 this function. We'll have an "initial value" recorded for the
65 return-register if we've seen a call instruction emitted. This note
66 will be inaccurate before instructions are emitted, but the only caller
67 at that time is looking for modulo from stack-boundary, to which the
68 return-address does not contribute, and which is always 0 for MMIX
69 anyway. Beware of calling leaf_function_p here, as it'll abort if
70 called within a sequence. */
71 #define MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS \
73 && has_hard_reg_initial_val (Pmode, MMIX_INCOMING_RETURN_ADDRESS_REGNUM))
75 #define IS_MMIX_EH_RETURN_DATA_REG(REGNO) \
76 (crtl->calls_eh_return \
77 && (EH_RETURN_DATA_REGNO (0) == REGNO \
78 || EH_RETURN_DATA_REGNO (1) == REGNO \
79 || EH_RETURN_DATA_REGNO (2) == REGNO \
80 || EH_RETURN_DATA_REGNO (3) == REGNO))
82 /* For the default ABI, we rename registers at output-time to fill the gap
83 between the (statically partitioned) saved registers and call-clobbered
84 registers. In effect this makes unused call-saved registers to be used
85 as call-clobbered registers. The benefit comes from keeping the number
86 of local registers (value of rL) low, since there's a cost of
87 increasing rL and clearing unused (unset) registers with lower numbers.
88 Don't translate while outputting the prologue. */
89 #define MMIX_OUTPUT_REGNO(N) \
91 || (int) (N) < MMIX_RETURN_VALUE_REGNUM \
92 || (int) (N) > MMIX_LAST_STACK_REGISTER_REGNUM \
94 || cfun->machine == NULL \
95 || cfun->machine->in_prologue \
96 ? (N) : ((N) - MMIX_RETURN_VALUE_REGNUM \
97 + cfun->machine->highest_saved_stack_register + 1))
99 /* The %d in "POP %d,0". */
100 #define MMIX_POP_ARGUMENT() \
102 && crtl->return_rtx != NULL \
103 && ! cfun->returns_struct) \
104 ? (GET_CODE (crtl->return_rtx) == PARALLEL \
105 ? GET_NUM_ELEM (XVEC (crtl->return_rtx, 0)) : 1) \
108 /* The canonical saved comparison operands for non-cc0 machines, set in
109 the compare expander. */
110 rtx mmix_compare_op0
;
111 rtx mmix_compare_op1
;
113 /* Declarations of locals. */
115 /* Intermediate for insn output. */
116 static int mmix_output_destination_register
;
118 static void mmix_option_override (void);
119 static void mmix_asm_output_source_filename (FILE *, const char *);
120 static void mmix_output_shiftvalue_op_from_str
121 (FILE *, const char *, int64_t);
122 static void mmix_output_shifted_value (FILE *, int64_t);
123 static void mmix_output_condition (FILE *, const_rtx
, int);
124 static void mmix_output_octa (FILE *, int64_t, int);
125 static bool mmix_assemble_integer (rtx
, unsigned int, int);
126 static struct machine_function
*mmix_init_machine_status (void);
127 static void mmix_encode_section_info (tree
, rtx
, int);
128 static const char *mmix_strip_name_encoding (const char *);
129 static void mmix_emit_sp_add (HOST_WIDE_INT offset
);
130 static void mmix_target_asm_function_prologue (FILE *);
131 static void mmix_target_asm_function_end_prologue (FILE *);
132 static void mmix_target_asm_function_epilogue (FILE *);
133 static reg_class_t
mmix_preferred_reload_class (rtx
, reg_class_t
);
134 static reg_class_t
mmix_preferred_output_reload_class (rtx
, reg_class_t
);
135 static bool mmix_legitimate_address_p (machine_mode
, rtx
, bool,
136 code_helper
= ERROR_MARK
);
137 static bool mmix_legitimate_constant_p (machine_mode
, rtx
);
138 static void mmix_reorg (void);
139 static void mmix_asm_output_mi_thunk
140 (FILE *, tree
, HOST_WIDE_INT
, HOST_WIDE_INT
, tree
);
141 static void mmix_setup_incoming_varargs
142 (cumulative_args_t
, const function_arg_info
&, int *, int);
143 static void mmix_file_start (void);
144 static void mmix_file_end (void);
145 static void mmix_init_libfuncs (void);
146 static bool mmix_rtx_costs (rtx
, machine_mode
, int, int, int *, bool);
147 static int mmix_register_move_cost (machine_mode
,
148 reg_class_t
, reg_class_t
);
149 static rtx
mmix_struct_value_rtx (tree
, int);
150 static machine_mode
mmix_promote_function_mode (const_tree
,
152 int *, const_tree
, int);
153 static void mmix_function_arg_advance (cumulative_args_t
,
154 const function_arg_info
&);
155 static rtx
mmix_function_incoming_arg (cumulative_args_t
,
156 const function_arg_info
&);
157 static rtx
mmix_function_arg (cumulative_args_t
, const function_arg_info
&);
158 static rtx
mmix_function_value (const_tree
, const_tree
, bool);
159 static rtx
mmix_libcall_value (machine_mode
, const_rtx
);
160 static bool mmix_function_value_regno_p (const unsigned int);
161 static bool mmix_pass_by_reference (cumulative_args_t
,
162 const function_arg_info
&);
163 static bool mmix_frame_pointer_required (void);
164 static void mmix_asm_trampoline_template (FILE *);
165 static void mmix_trampoline_init (rtx
, tree
, rtx
);
166 static void mmix_print_operand (FILE *, rtx
, int);
167 static void mmix_print_operand_address (FILE *, machine_mode
, rtx
);
168 static bool mmix_print_operand_punct_valid_p (unsigned char);
169 static void mmix_conditional_register_usage (void);
170 static HOST_WIDE_INT
mmix_static_rtx_alignment (machine_mode
);
171 static HOST_WIDE_INT
mmix_constant_alignment (const_tree
, HOST_WIDE_INT
);
172 static HOST_WIDE_INT
mmix_starting_frame_offset (void);
174 /* Target structure macros. Listed by node. See `Using and Porting GCC'
175 for a general description. */
177 /* Node: Function Entry */
179 #undef TARGET_ASM_BYTE_OP
180 #define TARGET_ASM_BYTE_OP NULL
181 #undef TARGET_ASM_ALIGNED_HI_OP
182 #define TARGET_ASM_ALIGNED_HI_OP NULL
183 #undef TARGET_ASM_ALIGNED_SI_OP
184 #define TARGET_ASM_ALIGNED_SI_OP NULL
185 #undef TARGET_ASM_ALIGNED_DI_OP
186 #define TARGET_ASM_ALIGNED_DI_OP NULL
187 #undef TARGET_ASM_INTEGER
188 #define TARGET_ASM_INTEGER mmix_assemble_integer
190 #undef TARGET_ASM_FUNCTION_PROLOGUE
191 #define TARGET_ASM_FUNCTION_PROLOGUE mmix_target_asm_function_prologue
193 #undef TARGET_ASM_FUNCTION_END_PROLOGUE
194 #define TARGET_ASM_FUNCTION_END_PROLOGUE mmix_target_asm_function_end_prologue
196 #undef TARGET_ASM_FUNCTION_EPILOGUE
197 #define TARGET_ASM_FUNCTION_EPILOGUE mmix_target_asm_function_epilogue
199 #undef TARGET_PRINT_OPERAND
200 #define TARGET_PRINT_OPERAND mmix_print_operand
201 #undef TARGET_PRINT_OPERAND_ADDRESS
202 #define TARGET_PRINT_OPERAND_ADDRESS mmix_print_operand_address
203 #undef TARGET_PRINT_OPERAND_PUNCT_VALID_P
204 #define TARGET_PRINT_OPERAND_PUNCT_VALID_P mmix_print_operand_punct_valid_p
206 #undef TARGET_ENCODE_SECTION_INFO
207 #define TARGET_ENCODE_SECTION_INFO mmix_encode_section_info
208 #undef TARGET_STRIP_NAME_ENCODING
209 #define TARGET_STRIP_NAME_ENCODING mmix_strip_name_encoding
211 #undef TARGET_ASM_OUTPUT_MI_THUNK
212 #define TARGET_ASM_OUTPUT_MI_THUNK mmix_asm_output_mi_thunk
213 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
214 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall
215 #undef TARGET_ASM_FILE_START
216 #define TARGET_ASM_FILE_START mmix_file_start
217 #undef TARGET_ASM_FILE_START_FILE_DIRECTIVE
218 #define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
219 #undef TARGET_ASM_FILE_END
220 #define TARGET_ASM_FILE_END mmix_file_end
221 #undef TARGET_ASM_OUTPUT_SOURCE_FILENAME
222 #define TARGET_ASM_OUTPUT_SOURCE_FILENAME mmix_asm_output_source_filename
224 #undef TARGET_ASM_OUTPUT_IDENT
225 #define TARGET_ASM_OUTPUT_IDENT default_asm_output_ident_directive
227 #undef TARGET_INIT_LIBFUNCS
228 #define TARGET_INIT_LIBFUNCS mmix_init_libfuncs
230 #undef TARGET_CONDITIONAL_REGISTER_USAGE
231 #define TARGET_CONDITIONAL_REGISTER_USAGE mmix_conditional_register_usage
233 #undef TARGET_HAVE_SPECULATION_SAFE_VALUE
234 #define TARGET_HAVE_SPECULATION_SAFE_VALUE speculation_safe_value_not_needed
236 #undef TARGET_RTX_COSTS
237 #define TARGET_RTX_COSTS mmix_rtx_costs
238 #undef TARGET_ADDRESS_COST
239 #define TARGET_ADDRESS_COST hook_int_rtx_mode_as_bool_0
241 #undef TARGET_REGISTER_MOVE_COST
242 #define TARGET_REGISTER_MOVE_COST mmix_register_move_cost
244 #undef TARGET_MACHINE_DEPENDENT_REORG
245 #define TARGET_MACHINE_DEPENDENT_REORG mmix_reorg
247 #undef TARGET_PROMOTE_FUNCTION_MODE
248 #define TARGET_PROMOTE_FUNCTION_MODE mmix_promote_function_mode
250 #undef TARGET_FUNCTION_VALUE
251 #define TARGET_FUNCTION_VALUE mmix_function_value
252 #undef TARGET_LIBCALL_VALUE
253 #define TARGET_LIBCALL_VALUE mmix_libcall_value
254 #undef TARGET_FUNCTION_VALUE_REGNO_P
255 #define TARGET_FUNCTION_VALUE_REGNO_P mmix_function_value_regno_p
257 #undef TARGET_FUNCTION_ARG
258 #define TARGET_FUNCTION_ARG mmix_function_arg
259 #undef TARGET_FUNCTION_INCOMING_ARG
260 #define TARGET_FUNCTION_INCOMING_ARG mmix_function_incoming_arg
261 #undef TARGET_FUNCTION_ARG_ADVANCE
262 #define TARGET_FUNCTION_ARG_ADVANCE mmix_function_arg_advance
263 #undef TARGET_STRUCT_VALUE_RTX
264 #define TARGET_STRUCT_VALUE_RTX mmix_struct_value_rtx
265 #undef TARGET_SETUP_INCOMING_VARARGS
266 #define TARGET_SETUP_INCOMING_VARARGS mmix_setup_incoming_varargs
267 #undef TARGET_PASS_BY_REFERENCE
268 #define TARGET_PASS_BY_REFERENCE mmix_pass_by_reference
269 #undef TARGET_CALLEE_COPIES
270 #define TARGET_CALLEE_COPIES hook_bool_CUMULATIVE_ARGS_arg_info_true
272 #undef TARGET_PREFERRED_RELOAD_CLASS
273 #define TARGET_PREFERRED_RELOAD_CLASS mmix_preferred_reload_class
274 #undef TARGET_PREFERRED_OUTPUT_RELOAD_CLASS
275 #define TARGET_PREFERRED_OUTPUT_RELOAD_CLASS mmix_preferred_output_reload_class
277 #undef TARGET_LEGITIMATE_ADDRESS_P
278 #define TARGET_LEGITIMATE_ADDRESS_P mmix_legitimate_address_p
279 #undef TARGET_LEGITIMATE_CONSTANT_P
280 #define TARGET_LEGITIMATE_CONSTANT_P mmix_legitimate_constant_p
282 #undef TARGET_FRAME_POINTER_REQUIRED
283 #define TARGET_FRAME_POINTER_REQUIRED mmix_frame_pointer_required
285 #undef TARGET_ASM_TRAMPOLINE_TEMPLATE
286 #define TARGET_ASM_TRAMPOLINE_TEMPLATE mmix_asm_trampoline_template
287 #undef TARGET_TRAMPOLINE_INIT
288 #define TARGET_TRAMPOLINE_INIT mmix_trampoline_init
290 #undef TARGET_OPTION_OVERRIDE
291 #define TARGET_OPTION_OVERRIDE mmix_option_override
293 #undef TARGET_STATIC_RTX_ALIGNMENT
294 #define TARGET_STATIC_RTX_ALIGNMENT mmix_static_rtx_alignment
295 #undef TARGET_CONSTANT_ALIGNMENT
296 #define TARGET_CONSTANT_ALIGNMENT mmix_constant_alignment
298 #undef TARGET_STARTING_FRAME_OFFSET
299 #define TARGET_STARTING_FRAME_OFFSET mmix_starting_frame_offset
301 struct gcc_target targetm
= TARGET_INITIALIZER
;
303 /* Functions that are expansions for target macros.
304 See Target Macros in `Using and Porting GCC'. */
306 /* TARGET_OPTION_OVERRIDE. */
309 mmix_option_override (void)
311 /* Should we err or should we warn? Hmm. At least we must neutralize
312 it. For example the wrong kind of case-tables will be generated with
313 PIC; we use absolute address items for mmixal compatibility. FIXME:
314 They could be relative if we just elide them to after all pertinent
318 warning (0, "%<-f%s%> not supported: ignored",
319 (flag_pic
> 1) ? "PIC" : "pic");
323 /* Don't bother with mmixal-compatible syntax if it's likely that a
324 certain format of the assembly is expected, like no new-line
325 after the .byte (or BYTE) parameter, when scanning debug-info
326 output, as happens in many places in the gcc testsuite. The
327 dwarf2 output code (maybe others) takes a shortcut based on the
328 presence of certain assembler directives, instead of calling
329 assemble_integer. Not worthwhile editing the test-cases:
330 mixed-syntax assembly output already looks too ugly for the
331 intent of being readable, and the resulting mix certainly fails
332 the intent of being compatible with mmixal. See
333 varasm.cc:default_file_start for this triple. See also
334 mmix_assemble_integer. */
335 if (flag_verbose_asm
|| flag_debug_asm
|| flag_dump_rtl_in_asm
)
337 /* "Reinstate" the defaults from target-def.h that we
339 targetm
.asm_out
.byte_op
= "\t.byte\t";
340 targetm
.asm_out
.aligned_op
.hi
= "\t.short\t";
341 targetm
.asm_out
.aligned_op
.si
= "\t.long\t";
343 /* Note that TARGET_ASM_ALIGNED_DI_OP is default NULL, so
344 there's nothing to "reinstate". Still, we add the universal
345 default (with "recent" gas) for an address. */
346 targetm
.asm_out
.aligned_op
.di
= "\t.dc.a\t";
350 /* INIT_EXPANDERS. */
353 mmix_init_expanders (void)
355 init_machine_status
= mmix_init_machine_status
;
358 /* Set the per-function data. */
360 static struct machine_function
*
361 mmix_init_machine_status (void)
363 return ggc_cleared_alloc
<machine_function
> ();
366 /* DATA_ABI_ALIGNMENT.
367 We have trouble getting the address of stuff that is located at other
368 than 32-bit alignments (GETA requirements), so try to give everything
369 at least 32-bit alignment. */
372 mmix_data_alignment (tree type ATTRIBUTE_UNUSED
, int basic_align
)
374 if (basic_align
< 32)
380 /* Implement TARGET_STATIC_RTX_ALIGNMENT. */
383 mmix_static_rtx_alignment (machine_mode mode
)
385 return MAX (GET_MODE_ALIGNMENT (mode
), 32);
388 /* Implement tARGET_CONSTANT_ALIGNMENT. */
391 mmix_constant_alignment (const_tree
, HOST_WIDE_INT basic_align
)
393 if (basic_align
< 32)
399 /* LOCAL_ALIGNMENT. */
402 mmix_local_alignment (tree type ATTRIBUTE_UNUSED
, unsigned basic_align
)
404 if (basic_align
< 32)
410 /* TARGET_CONDITIONAL_REGISTER_USAGE. */
413 mmix_conditional_register_usage (void)
419 static const int gnu_abi_reg_alloc_order
[]
420 = MMIX_GNU_ABI_REG_ALLOC_ORDER
;
422 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
423 reg_alloc_order
[i
] = gnu_abi_reg_alloc_order
[i
];
425 /* Change the default from the mmixware ABI. For the GNU ABI,
426 $15..$30 are call-saved just as $0..$14. There must be one
427 call-clobbered local register for the "hole" that holds the
428 number of saved local registers saved by PUSHJ/PUSHGO during the
429 function call, receiving the return value at return. So best is
430 to use the highest, $31. It's already marked call-clobbered for
432 for (i
= 15; i
<= 30; i
++)
433 call_used_regs
[i
] = 0;
435 /* "Unfix" the parameter registers. */
436 for (i
= MMIX_RESERVED_GNU_ARG_0_REGNUM
;
437 i
< MMIX_RESERVED_GNU_ARG_0_REGNUM
+ MMIX_MAX_ARGS_IN_REGS
;
442 /* Step over the ":" in special register names. */
443 if (! TARGET_TOPLEVEL_SYMBOLS
)
444 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
445 if (reg_names
[i
][0] == ':')
449 /* INCOMING_REGNO and OUTGOING_REGNO worker function.
450 Those two macros must only be applied to function argument
451 registers and the function return value register for the opposite
452 use. FIXME: for their current use in gcc, it'd be better with an
453 explicit specific additional FUNCTION_INCOMING_ARG_REGNO_P a'la
454 TARGET_FUNCTION_ARG / TARGET_FUNCTION_INCOMING_ARG instead of
455 forcing the target to commit to a fixed mapping and for any
456 unspecified register use. Particularly when thinking about the
457 return-value, it is better to imagine INCOMING_REGNO and
458 OUTGOING_REGNO as named CALLEE_TO_CALLER_REGNO and INNER_REGNO as
459 named CALLER_TO_CALLEE_REGNO because the direction. The "incoming"
460 and "outgoing" is from the perspective of the parameter-registers,
461 but the same macro is (must be, lacking an alternative like
462 suggested above) used to map the return-value-register from the
463 same perspective. To make directions even more confusing, the macro
464 MMIX_OUTGOING_RETURN_VALUE_REGNUM holds the number of the register
465 in which to return a value, i.e. INCOMING_REGNO for the return-value-
466 register as received from a called function; the return-value on the
470 mmix_opposite_regno (int regno
, int incoming
)
472 if (incoming
&& regno
== MMIX_OUTGOING_RETURN_VALUE_REGNUM
)
473 return MMIX_RETURN_VALUE_REGNUM
;
475 if (!incoming
&& regno
== MMIX_RETURN_VALUE_REGNUM
)
476 return MMIX_OUTGOING_RETURN_VALUE_REGNUM
;
478 if (!mmix_function_arg_regno_p (regno
, incoming
))
483 ? MMIX_FIRST_INCOMING_ARG_REGNUM
- MMIX_FIRST_ARG_REGNUM
484 : MMIX_FIRST_ARG_REGNUM
- MMIX_FIRST_INCOMING_ARG_REGNUM
);
488 All registers that are part of the register stack and that will be
492 mmix_local_regno (int regno
)
494 return (regno
<= MMIX_LAST_STACK_REGISTER_REGNUM
495 && !call_used_or_fixed_reg_p (regno
));
498 /* TARGET_PREFERRED_RELOAD_CLASS.
499 We need to extend the reload class of REMAINDER_REG and HIMULT_REG. */
502 mmix_preferred_reload_class (rtx x
, reg_class_t rclass
)
504 /* FIXME: Revisit. */
505 return GET_CODE (x
) == MOD
&& GET_MODE (x
) == DImode
506 ? REMAINDER_REG
: rclass
;
509 /* TARGET_PREFERRED_OUTPUT_RELOAD_CLASS.
510 We need to extend the reload class of REMAINDER_REG and HIMULT_REG. */
513 mmix_preferred_output_reload_class (rtx x
, reg_class_t rclass
)
515 /* FIXME: Revisit. */
516 return GET_CODE (x
) == MOD
&& GET_MODE (x
) == DImode
517 ? REMAINDER_REG
: rclass
;
520 /* SECONDARY_RELOAD_CLASS.
521 We need to reload regs of REMAINDER_REG and HIMULT_REG elsewhere. */
524 mmix_secondary_reload_class (enum reg_class rclass
,
525 machine_mode mode ATTRIBUTE_UNUSED
,
526 rtx x ATTRIBUTE_UNUSED
,
527 int in_p ATTRIBUTE_UNUSED
)
529 if (rclass
== REMAINDER_REG
530 || rclass
== HIMULT_REG
531 || rclass
== SYSTEM_REGS
)
537 /* DYNAMIC_CHAIN_ADDRESS. */
540 mmix_dynamic_chain_address (rtx frame
)
542 /* FIXME: the frame-pointer is stored at offset -8 from the current
543 frame-pointer. Unfortunately, the caller assumes that a
544 frame-pointer is present for *all* previous frames. There should be
545 a way to say that that cannot be done, like for RETURN_ADDR_RTX. */
546 return plus_constant (Pmode
, frame
, -8);
549 /* Implement TARGET_STARTING_FRAME_OFFSET. */
552 mmix_starting_frame_offset (void)
554 /* The old frame pointer is in the slot below the new one, so
555 FIRST_PARM_OFFSET does not need to depend on whether the
556 frame-pointer is needed or not. We have to adjust for the register
557 stack pointer being located below the saved frame pointer.
558 Similarly, we store the return address on the stack too, for
559 exception handling, and always if we save the register stack pointer. */
562 + (MMIX_CFUN_HAS_LANDING_PAD
563 ? -16 : (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
? -8 : 0)));
566 /* RETURN_ADDR_RTX. */
569 mmix_return_addr_rtx (int count
, rtx frame ATTRIBUTE_UNUSED
)
572 ? (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
573 /* FIXME: Set frame_alias_set on the following. (Why?)
574 See mmix_initial_elimination_offset for the reason we can't use
575 get_hard_reg_initial_val for both. Always using a stack slot
576 and not a register would be suboptimal. */
577 ? validize_mem (gen_rtx_MEM (Pmode
,
578 plus_constant (Pmode
,
579 frame_pointer_rtx
, -16)))
580 : get_hard_reg_initial_val (Pmode
, MMIX_INCOMING_RETURN_ADDRESS_REGNUM
))
584 /* SETUP_FRAME_ADDRESSES. */
587 mmix_setup_frame_addresses (void)
589 /* Nothing needed at the moment. */
592 /* The difference between the (imaginary) frame pointer and the stack
593 pointer. Used to eliminate the frame pointer. */
596 mmix_initial_elimination_offset (int fromreg
, int toreg
)
600 = (get_frame_size () + crtl
->outgoing_args_size
+ 7) & ~7;
602 /* There is no actual offset between these two virtual values, but for
603 the frame-pointer, we have the old one in the stack position below
604 it, so the offset for the frame-pointer to the stack-pointer is one
606 if (fromreg
== MMIX_ARG_POINTER_REGNUM
607 && toreg
== MMIX_FRAME_POINTER_REGNUM
)
610 /* The difference is the size of local variables plus the size of
611 outgoing function arguments that would normally be passed as
612 registers but must be passed on stack because we're out of
613 function-argument registers. Only global saved registers are
614 counted; the others go on the register stack.
616 The frame-pointer is counted too if it is what is eliminated, as we
617 need to balance the offset for it from TARGET_STARTING_FRAME_OFFSET.
619 Also add in the slot for the register stack pointer we save if we
622 Unfortunately, we can't access $0..$14, from unwinder code easily, so
623 store the return address in a frame slot too. FIXME: Only for
624 non-leaf functions. FIXME: Always with a landing pad, because it's
625 hard to know whether we need the other at the time we know we need
626 the offset for one (and have to state it). It's a kludge until we
627 can express the register stack in the EH frame info.
629 We have to do alignment here; get_frame_size will not return a
630 multiple of STACK_BOUNDARY. FIXME: Add note in manual. */
632 for (regno
= MMIX_FIRST_GLOBAL_REGNUM
;
635 if ((df_regs_ever_live_p (regno
) && !call_used_or_fixed_reg_p (regno
))
636 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
640 + (MMIX_CFUN_HAS_LANDING_PAD
641 ? 16 : (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
? 8 : 0))
642 + (fromreg
== MMIX_ARG_POINTER_REGNUM
? 0 : 8);
646 mmix_function_arg_advance (cumulative_args_t argsp_v
,
647 const function_arg_info
&arg
)
649 CUMULATIVE_ARGS
*argsp
= get_cumulative_args (argsp_v
);
650 int arg_size
= MMIX_FUNCTION_ARG_SIZE (arg
.mode
, arg
.type
);
652 argsp
->regs
= ((targetm
.calls
.must_pass_in_stack (arg
)
656 ? (MMIX_MAX_ARGS_IN_REGS
) + 1
657 : argsp
->regs
+ (7 + arg_size
) / 8);
660 /* Helper function for mmix_function_arg and mmix_function_incoming_arg. */
663 mmix_function_arg_1 (const cumulative_args_t argsp_v
,
664 const function_arg_info
&arg
, bool incoming
)
666 CUMULATIVE_ARGS
*argsp
= get_cumulative_args (argsp_v
);
668 /* The mode of the argument will be VOIDmode for the "end_marker". Make sure
669 we don't ever generate a VOIDmode register; later passes will barf on that.
670 We may want to use the register number, so return something nominally
671 useful. Thus, for VOIDmode, use DImode, being the natural mode for the
673 machine_mode mode
= arg
.mode
== VOIDmode
? DImode
: arg
.mode
;
675 /* Last-argument marker. */
676 if (arg
.end_marker_p ())
677 return (argsp
->regs
< MMIX_MAX_ARGS_IN_REGS
)
680 ? MMIX_FIRST_INCOMING_ARG_REGNUM
681 : MMIX_FIRST_ARG_REGNUM
) + argsp
->regs
)
684 return (argsp
->regs
< MMIX_MAX_ARGS_IN_REGS
685 && !targetm
.calls
.must_pass_in_stack (arg
)
686 && (GET_MODE_BITSIZE (mode
) <= 64
691 ? MMIX_FIRST_INCOMING_ARG_REGNUM
692 : MMIX_FIRST_ARG_REGNUM
)
697 /* Return an rtx for a function argument to go in a register, and 0 for
698 one that must go on stack. */
701 mmix_function_arg (cumulative_args_t argsp
, const function_arg_info
&arg
)
703 return mmix_function_arg_1 (argsp
, arg
, false);
707 mmix_function_incoming_arg (cumulative_args_t argsp
,
708 const function_arg_info
&arg
)
710 return mmix_function_arg_1 (argsp
, arg
, true);
713 /* Returns nonzero for everything that goes by reference, 0 for
714 everything that goes by value. */
717 mmix_pass_by_reference (cumulative_args_t argsp_v
,
718 const function_arg_info
&arg
)
720 CUMULATIVE_ARGS
*argsp
= get_cumulative_args (argsp_v
);
722 /* FIXME: Check: I'm not sure the must_pass_in_stack check is
724 if (targetm
.calls
.must_pass_in_stack (arg
))
727 if (MMIX_FUNCTION_ARG_SIZE (arg
.mode
, arg
.type
) > 8
729 && (!argsp
|| !argsp
->lib
))
735 /* Return nonzero if regno is a register number where a parameter is
736 passed, and 0 otherwise. */
739 mmix_function_arg_regno_p (int regno
, int incoming
)
742 = incoming
? MMIX_FIRST_INCOMING_ARG_REGNUM
: MMIX_FIRST_ARG_REGNUM
;
744 return regno
>= first_arg_regnum
745 && regno
< first_arg_regnum
+ MMIX_MAX_ARGS_IN_REGS
;
748 /* Implements TARGET_FUNCTION_VALUE. */
751 mmix_function_value (const_tree valtype
,
752 const_tree func ATTRIBUTE_UNUSED
,
755 machine_mode mode
= TYPE_MODE (valtype
);
757 int first_val_regnum
= MMIX_OUTGOING_RETURN_VALUE_REGNUM
;
758 rtx vec
[MMIX_MAX_REGS_FOR_VALUE
];
763 return gen_rtx_REG (mode
, MMIX_RETURN_VALUE_REGNUM
);
765 /* Return values that fit in a register need no special handling.
766 There's no register hole when parameters are passed in global
769 || GET_MODE_BITSIZE (mode
) <= BITS_PER_WORD
)
771 gen_rtx_REG (mode
, MMIX_OUTGOING_RETURN_VALUE_REGNUM
);
773 if (COMPLEX_MODE_P (mode
))
774 /* A complex type, made up of components. */
775 cmode
= TYPE_MODE (TREE_TYPE (valtype
));
778 /* Of the other larger-than-register modes, we only support
779 scalar mode TImode. (At least, that's the only one that's
780 been rudimentally tested.) Make sure we're alerted for
783 sorry ("support for mode %qs", GET_MODE_NAME (mode
));
785 /* In any case, we will fill registers to the natural size. */
789 nregs
= ((GET_MODE_BITSIZE (mode
) + BITS_PER_WORD
- 1) / BITS_PER_WORD
);
791 /* We need to take care of the effect of the register hole on return
792 values of large sizes; the last register will appear as the first
793 register, with the rest shifted. (For complex modes, this is just
794 swapped registers.) */
796 if (nregs
> MMIX_MAX_REGS_FOR_VALUE
)
797 internal_error ("too large function value type, needs %d registers,\
798 have only %d registers for this", nregs
, MMIX_MAX_REGS_FOR_VALUE
);
800 /* FIXME: Maybe we should handle structure values like this too
801 (adjusted for BLKmode), perhaps for both ABI:s. */
802 for (i
= 0; i
< nregs
- 1; i
++)
804 = gen_rtx_EXPR_LIST (VOIDmode
,
805 gen_rtx_REG (cmode
, first_val_regnum
+ i
),
806 GEN_INT ((i
+ 1) * BITS_PER_UNIT
));
809 = gen_rtx_EXPR_LIST (VOIDmode
,
810 gen_rtx_REG (cmode
, first_val_regnum
+ nregs
- 1),
813 return gen_rtx_PARALLEL (mode
, gen_rtvec_v (nregs
, vec
));
816 /* Implements TARGET_LIBCALL_VALUE. */
819 mmix_libcall_value (machine_mode mode
,
820 const_rtx fun ATTRIBUTE_UNUSED
)
822 return gen_rtx_REG (mode
, MMIX_RETURN_VALUE_REGNUM
);
825 /* Implements TARGET_FUNCTION_VALUE_REGNO_P. */
828 mmix_function_value_regno_p (const unsigned int regno
)
830 return regno
== MMIX_RETURN_VALUE_REGNUM
;
833 /* EH_RETURN_DATA_REGNO. */
836 mmix_eh_return_data_regno (int n
)
839 return MMIX_EH_RETURN_DATA_REGNO_START
+ n
;
841 return INVALID_REGNUM
;
844 /* EH_RETURN_STACKADJ_RTX. */
847 mmix_eh_return_stackadj_rtx (void)
849 return gen_rtx_REG (Pmode
, MMIX_EH_RETURN_STACKADJ_REGNUM
);
852 /* EH_RETURN_HANDLER_RTX. */
855 mmix_eh_return_handler_rtx (void)
857 return gen_rtx_REG (Pmode
, MMIX_INCOMING_RETURN_ADDRESS_REGNUM
);
860 /* ASM_PREFERRED_EH_DATA_FORMAT. */
863 mmix_asm_preferred_eh_data_format (int code ATTRIBUTE_UNUSED
,
864 int global ATTRIBUTE_UNUSED
)
866 /* This is the default (was at 2001-07-20). Revisit when needed. */
867 return DW_EH_PE_absptr
;
870 /* Make a note that we've seen the beginning of the prologue. This
871 matters to whether we'll translate register numbers as calculated by
875 mmix_target_asm_function_prologue (FILE *)
877 cfun
->machine
->in_prologue
= 1;
880 /* Make a note that we've seen the end of the prologue. */
883 mmix_target_asm_function_end_prologue (FILE *stream ATTRIBUTE_UNUSED
)
885 cfun
->machine
->in_prologue
= 0;
888 /* Implement TARGET_MACHINE_DEPENDENT_REORG. No actual rearrangements
889 done here; just virtually by calculating the highest saved stack
890 register number used to modify the register numbers at output time. */
897 /* We put the number of the highest saved register-file register in a
898 location convenient for the call-patterns to output. Note that we
899 don't tell dwarf2 about these registers, since it can't restore them
901 for (regno
= MMIX_LAST_STACK_REGISTER_REGNUM
;
904 if ((df_regs_ever_live_p (regno
) && !call_used_or_fixed_reg_p (regno
))
905 || (regno
== MMIX_FRAME_POINTER_REGNUM
&& frame_pointer_needed
))
908 /* Regardless of whether they're saved (they might be just read), we
909 mustn't include registers that carry parameters. We could scan the
910 insns to see whether they're actually used (and indeed do other less
911 trivial register usage analysis and transformations), but it seems
912 wasteful to optimize for unused parameter registers. As of
913 2002-04-30, df_regs_ever_live_p (n) seems to be set for only-reads too, but
914 that might change. */
915 if (!TARGET_ABI_GNU
&& regno
< crtl
->args
.info
.regs
- 1)
917 regno
= crtl
->args
.info
.regs
- 1;
919 /* We don't want to let this cause us to go over the limit and make
920 incoming parameter registers be misnumbered and treating the last
921 parameter register and incoming return value register call-saved.
922 Stop things at the unmodified scheme. */
923 if (regno
> MMIX_RETURN_VALUE_REGNUM
- 1)
924 regno
= MMIX_RETURN_VALUE_REGNUM
- 1;
927 cfun
->machine
->highest_saved_stack_register
= regno
;
930 /* TARGET_ASM_FUNCTION_EPILOGUE. */
933 mmix_target_asm_function_epilogue (FILE *stream
)
935 /* Emit an \n for readability of the generated assembly. */
936 fputc ('\n', stream
);
939 /* TARGET_ASM_OUTPUT_MI_THUNK. */
942 mmix_asm_output_mi_thunk (FILE *stream
,
943 tree thunk_fndecl ATTRIBUTE_UNUSED
,
945 HOST_WIDE_INT vcall_offset ATTRIBUTE_UNUSED
,
948 /* If you define TARGET_STRUCT_VALUE_RTX that returns 0 (i.e. pass
949 location of structure to return as invisible first argument), you
950 need to tweak this code too. */
951 const char *regname
= reg_names
[MMIX_FIRST_INCOMING_ARG_REGNUM
];
952 const char *fnname
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (thunk_fndecl
));
954 assemble_start_function (thunk_fndecl
, fnname
);
956 if (delta
>= 0 && delta
< 65536)
957 fprintf (stream
, "\tINCL %s,%d\n", regname
, (int)delta
);
958 else if (delta
< 0 && delta
>= -255)
959 fprintf (stream
, "\tSUBU %s,%s,%d\n", regname
, regname
, (int)-delta
);
962 mmix_output_register_setting (stream
, 255, delta
, 1);
963 fprintf (stream
, "\tADDU %s,%s,$255\n", regname
, regname
);
966 fprintf (stream
, "\tJMP ");
967 assemble_name (stream
, XSTR (XEXP (DECL_RTL (func
), 0), 0));
968 fprintf (stream
, "\n");
969 assemble_end_function (thunk_fndecl
, fnname
);
972 /* FUNCTION_PROFILER. */
975 mmix_function_profiler (FILE *stream ATTRIBUTE_UNUSED
,
976 int labelno ATTRIBUTE_UNUSED
)
978 sorry ("%<function_profiler%> support for MMIX");
981 /* Worker function for TARGET_SETUP_INCOMING_VARARGS. For the moment,
982 let's stick to pushing argument registers on the stack. Later, we
983 can parse all arguments in registers, to improve performance. */
986 mmix_setup_incoming_varargs (cumulative_args_t args_so_farp_v
,
987 const function_arg_info
&arg
,
989 int second_time ATTRIBUTE_UNUSED
)
991 CUMULATIVE_ARGS
*args_so_farp
= get_cumulative_args (args_so_farp_v
);
993 /* The last named variable has been handled, but
994 args_so_farp has not been advanced for it. */
995 if (args_so_farp
->regs
+ 1 < MMIX_MAX_ARGS_IN_REGS
)
996 *pretend_sizep
= (MMIX_MAX_ARGS_IN_REGS
- (args_so_farp
->regs
+ 1)) * 8;
998 /* We assume that one argument takes up one register here. That should
999 be true until we start messing with multi-reg parameters. */
1000 if (!TYPE_NO_NAMED_ARGS_STDARG_P (TREE_TYPE (current_function_decl
))
1001 && (7 + (MMIX_FUNCTION_ARG_SIZE (arg
.mode
, arg
.type
))) / 8 != 1)
1002 internal_error ("MMIX Internal: Last named vararg would not fit in a register");
1005 /* TARGET_ASM_TRAMPOLINE_TEMPLATE. */
1008 mmix_asm_trampoline_template (FILE *stream
)
1010 /* Read a value into the static-chain register and jump somewhere. The
1011 static chain is stored at offset 16, and the function address is
1012 stored at offset 24. */
1014 fprintf (stream
, "\tGETA $255,1F\n\t");
1015 fprintf (stream
, "LDOU %s,$255,0\n\t", reg_names
[MMIX_STATIC_CHAIN_REGNUM
]);
1016 fprintf (stream
, "LDOU $255,$255,8\n\t");
1017 fprintf (stream
, "GO $255,$255,0\n");
1018 fprintf (stream
, "1H\tOCTA 0\n\t");
1019 fprintf (stream
, "OCTA 0\n");
1022 /* TARGET_TRAMPOLINE_INIT. */
1023 /* Set the static chain and function pointer field in the trampoline.
1024 We also SYNCID here to be sure (doesn't matter in the simulator, but
1025 some day it will). */
1028 mmix_trampoline_init (rtx m_tramp
, tree fndecl
, rtx static_chain
)
1030 rtx fnaddr
= XEXP (DECL_RTL (fndecl
), 0);
1033 emit_block_move (m_tramp
, assemble_trampoline_template (),
1034 GEN_INT (2*UNITS_PER_WORD
), BLOCK_OP_NORMAL
);
1036 mem
= adjust_address (m_tramp
, DImode
, 2*UNITS_PER_WORD
);
1037 emit_move_insn (mem
, static_chain
);
1038 mem
= adjust_address (m_tramp
, DImode
, 3*UNITS_PER_WORD
);
1039 emit_move_insn (mem
, fnaddr
);
1041 mem
= adjust_address (m_tramp
, DImode
, 0);
1042 emit_insn (gen_sync_icache (mem
, GEN_INT (TRAMPOLINE_SIZE
- 1)));
1045 /* We must exclude constant addresses that have an increment that is not a
1046 multiple of four bytes because of restrictions of the GETA
1047 instruction, unless TARGET_BASE_ADDRESSES. */
1050 mmix_constant_address_p (rtx x
)
1052 RTX_CODE code
= GET_CODE (x
);
1054 /* When using "base addresses", anything constant goes. */
1055 int constant_ok
= TARGET_BASE_ADDRESSES
!= 0;
1064 /* FIXME: Don't know how to dissect these. Avoid them for now,
1065 except we know they're constants. */
1069 addend
= INTVAL (x
);
1073 if (GET_MODE (x
) != VOIDmode
)
1074 /* Strange that we got here. FIXME: Check if we do. */
1076 addend
= CONST_DOUBLE_LOW (x
);
1080 /* Note that expressions with arithmetic on forward references don't
1081 work in mmixal. People using gcc assembly code with mmixal might
1082 need to move arrays and such to before the point of use. */
1083 if (GET_CODE (XEXP (x
, 0)) == PLUS
)
1085 rtx x0
= XEXP (XEXP (x
, 0), 0);
1086 rtx x1
= XEXP (XEXP (x
, 0), 1);
1088 if ((GET_CODE (x0
) == SYMBOL_REF
1089 || GET_CODE (x0
) == LABEL_REF
)
1090 && (GET_CODE (x1
) == CONST_INT
1091 || (GET_CODE (x1
) == CONST_DOUBLE
1092 && GET_MODE (x1
) == VOIDmode
)))
1093 addend
= mmix_intval (x1
);
1105 return constant_ok
|| (addend
& 3) == 0;
1108 /* Return 1 if the address is OK, otherwise 0. */
1111 mmix_legitimate_address_p (machine_mode mode ATTRIBUTE_UNUSED
,
1113 bool strict_checking
,
1116 #define MMIX_REG_OK(X) \
1118 && (REGNO (X) <= MMIX_LAST_GENERAL_REGISTER \
1119 || (reg_renumber[REGNO (X)] > 0 \
1120 && reg_renumber[REGNO (X)] <= MMIX_LAST_GENERAL_REGISTER))) \
1121 || (!strict_checking \
1122 && (REGNO (X) <= MMIX_LAST_GENERAL_REGISTER \
1123 || REGNO (X) >= FIRST_PSEUDO_REGISTER \
1124 || REGNO (X) == ARG_POINTER_REGNUM)))
1128 (mem (plus reg reg))
1129 (mem (plus reg 0..255)).
1130 unless TARGET_BASE_ADDRESSES, in which case we accept all
1131 (mem constant_address) too. */
1135 if (REG_P (x
) && MMIX_REG_OK (x
))
1138 if (GET_CODE(x
) == PLUS
)
1140 rtx x1
= XEXP (x
, 0);
1141 rtx x2
= XEXP (x
, 1);
1143 /* Try swapping the order. FIXME: Do we need this? */
1151 /* (mem (plus (reg?) (?))) */
1152 if (!REG_P (x1
) || !MMIX_REG_OK (x1
))
1153 return TARGET_BASE_ADDRESSES
&& mmix_constant_address_p (x
);
1155 /* (mem (plus (reg) (reg?))) */
1156 if (REG_P (x2
) && MMIX_REG_OK (x2
))
1159 /* (mem (plus (reg) (0..255?))) */
1160 if (satisfies_constraint_I (x2
))
1166 return TARGET_BASE_ADDRESSES
&& mmix_constant_address_p (x
);
1169 /* Implement TARGET_LEGITIMATE_CONSTANT_P. */
1172 mmix_legitimate_constant_p (machine_mode mode ATTRIBUTE_UNUSED
, rtx x
)
1174 RTX_CODE code
= GET_CODE (x
);
1176 /* We must allow any number due to the way the cse passes works; if we
1177 do not allow any number here, general_operand will fail, and insns
1178 will fatally fail recognition instead of "softly". */
1179 if (code
== CONST_INT
|| code
== CONST_DOUBLE
)
1182 return CONSTANT_ADDRESS_P (x
);
1185 /* SELECT_CC_MODE. */
1188 mmix_select_cc_mode (RTX_CODE op
, rtx x
, rtx y ATTRIBUTE_UNUSED
)
1190 /* We use CCmode, CC_UNSmode, CC_FPmode, CC_FPEQmode and CC_FUNmode to
1191 output different compare insns. Note that we do not check the
1192 validity of the comparison here. */
1194 if (GET_MODE_CLASS (GET_MODE (x
)) == MODE_FLOAT
)
1196 if (op
== ORDERED
|| op
== UNORDERED
|| op
== UNGE
1197 || op
== UNGT
|| op
== UNLE
|| op
== UNLT
)
1200 if (op
== EQ
|| op
== NE
)
1206 if (op
== GTU
|| op
== LTU
|| op
== GEU
|| op
== LEU
)
1212 /* REVERSIBLE_CC_MODE. */
1215 mmix_reversible_cc_mode (machine_mode mode
)
1217 /* That is, all integer and the EQ, NE, ORDERED and UNORDERED float
1219 return mode
!= CC_FPmode
;
1222 /* TARGET_RTX_COSTS. */
1225 mmix_rtx_costs (rtx x ATTRIBUTE_UNUSED
,
1226 machine_mode mode ATTRIBUTE_UNUSED
,
1227 int outer_code ATTRIBUTE_UNUSED
,
1228 int opno ATTRIBUTE_UNUSED
,
1229 int *total ATTRIBUTE_UNUSED
,
1230 bool speed ATTRIBUTE_UNUSED
)
1232 /* For the time being, this is just a stub and we'll accept the
1233 generic calculations, until we can do measurements, at least.
1234 Say we did not modify any calculated costs. */
1238 /* TARGET_REGISTER_MOVE_COST.
1240 The special registers can only move to and from general regs, and we
1241 need to check that their constraints match, so say 3 for them. */
1244 mmix_register_move_cost (machine_mode mode ATTRIBUTE_UNUSED
,
1248 return (from
== GENERAL_REGS
&& from
== to
) ? 2 : 3;
1251 /* Note that we don't have a TEXT_SECTION_ASM_OP, because it has to be a
1252 compile-time constant; it's used in an asm in crtstuff.c, compiled for
1255 /* DATA_SECTION_ASM_OP. */
1258 mmix_data_section_asm_op (void)
1260 return "\t.data ! mmixal:= 8H LOC 9B";
1264 mmix_encode_section_info (tree decl
, rtx rtl
, int first
)
1266 /* Test for an external declaration, and do nothing if it is one. */
1268 && (DECL_EXTERNAL (decl
) || TREE_PUBLIC (decl
)))
1269 || (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_PUBLIC (decl
)))
1271 else if (first
&& DECL_P (decl
))
1273 /* For non-visible declarations, add a "@" prefix, which we skip
1274 when the label is output. If the label does not have this
1275 prefix, a ":" is output if -mtoplevel-symbols.
1277 Note that this does not work for data that is declared extern and
1278 later defined as static. If there's code in between, that code
1279 will refer to the extern declaration, and vice versa. This just
1280 means that when -mtoplevel-symbols is in use, we can just handle
1281 well-behaved ISO-compliant code. */
1283 const char *str
= XSTR (XEXP (rtl
, 0), 0);
1284 int len
= strlen (str
);
1285 char *newstr
= XALLOCAVEC (char, len
+ 2);
1287 strcpy (newstr
+ 1, str
);
1288 XSTR (XEXP (rtl
, 0), 0) = ggc_alloc_string (newstr
, len
+ 1);
1291 /* Set SYMBOL_REF_FLAG for things that we want to access with GETA. We
1292 may need different options to reach for different things with GETA.
1293 For now, functions and things we know or have been told are constant. */
1294 if (TREE_CODE (decl
) == FUNCTION_DECL
1295 || TREE_CONSTANT (decl
)
1297 && TREE_READONLY (decl
)
1298 && !TREE_SIDE_EFFECTS (decl
)
1299 && (!DECL_INITIAL (decl
)
1300 || TREE_CONSTANT (DECL_INITIAL (decl
)))))
1301 SYMBOL_REF_FLAG (XEXP (rtl
, 0)) = 1;
1305 mmix_strip_name_encoding (const char *name
)
1307 for (; (*name
== '@' || *name
== '*'); name
++)
1313 /* TARGET_ASM_FILE_START.
1314 We just emit a little comment for the time being. */
1317 mmix_file_start (void)
1319 default_file_start ();
1321 fputs ("! mmixal:= 8H LOC Data_Section\n", asm_out_file
);
1323 /* Make sure each file starts with the text section. */
1324 switch_to_section (text_section
);
1327 /* TARGET_ASM_FILE_END. */
1330 mmix_file_end (void)
1332 /* Make sure each file ends with the data section. */
1333 switch_to_section (data_section
);
1336 /* TARGET_ASM_OUTPUT_SOURCE_FILENAME. */
1339 mmix_asm_output_source_filename (FILE *stream
, const char *name
)
1341 fprintf (stream
, "# 1 ");
1342 OUTPUT_QUOTED_STRING (stream
, name
);
1343 fprintf (stream
, "\n");
1346 /* Unfortunately, by default __builtin_ffs is expanded to ffs for
1347 targets where INT_TYPE_SIZE < BITS_PER_WORD. That together with
1348 newlib since 2017-07-04 implementing ffs as __builtin_ffs leads to
1349 (newlib) ffs recursively calling itself. But, because of argument
1350 promotion, and with ffs we're counting from the least bit, the
1351 libgcc equivalent for ffsl works equally well for int arguments, so
1355 mmix_init_libfuncs (void)
1357 set_optab_libfunc (ffs_optab
, SImode
, "__ffsdi2");
1360 /* OUTPUT_QUOTED_STRING. */
1363 mmix_output_quoted_string (FILE *stream
, const char *string
, int length
)
1365 const char * string_end
= string
+ length
;
1366 static const char *const unwanted_chars
= "\"[]\\";
1368 /* Output "any character except newline and double quote character". We
1369 play it safe and avoid all control characters too. We also do not
1370 want [] as characters, should input be passed through m4 with [] as
1371 quotes. Further, we avoid "\", because the GAS port handles it as a
1372 quoting character. */
1373 while (string
< string_end
)
1376 && (unsigned char) *string
< 128
1377 && !ISCNTRL (*string
)
1378 && strchr (unwanted_chars
, *string
) == NULL
)
1380 fputc ('"', stream
);
1382 && (unsigned char) *string
< 128
1383 && !ISCNTRL (*string
)
1384 && strchr (unwanted_chars
, *string
) == NULL
1385 && string
< string_end
)
1387 fputc (*string
, stream
);
1390 fputc ('"', stream
);
1391 if (string
< string_end
)
1392 fprintf (stream
, ",");
1394 if (string
< string_end
)
1396 fprintf (stream
, "#%x", *string
& 255);
1398 if (string
< string_end
)
1399 fprintf (stream
, ",");
1404 /* Target hook for assembling integer objects. Use mmix_print_operand
1405 for WYDE and TETRA. Use mmix_output_octa to output 8-byte
1409 mmix_assemble_integer (rtx x
, unsigned int size
, int aligned_p
)
1414 /* We handle a limited number of types of operands in here. But
1415 that's ok, because we can punt to generic functions. We then
1416 pretend that aligned data isn't needed, so the usual .<pseudo>
1417 syntax is used (which works for aligned data too). We actually
1418 *must* do that, since we (usually) say we don't have simple aligned
1419 pseudos, causing this function to be called. See
1420 mmix_option_override for an exception. We just try and keep as
1421 much compatibility as possible with mmixal syntax for normal
1422 cases (i.e. without GNU extensions and C only). */
1424 if (GET_CODE (x
) != CONST_INT
)
1426 /* There is no "unaligned byte" op or generic function to
1427 which we can punt, so we have to handle this here. As
1428 the expression isn't a plain literal, the generated
1429 assembly-code can't be mmixal-equivalent (i.e. "BYTE"
1430 won't work) and thus it's ok to emit the default op
1432 assemble_integer_with_op ("\t.byte\t", x
);
1435 fputs ("\tBYTE\t", asm_out_file
);
1436 mmix_print_operand (asm_out_file
, x
, 'B');
1437 fputc ('\n', asm_out_file
);
1441 if (GET_CODE (x
) != CONST_INT
)
1446 fputs ("\tWYDE\t", asm_out_file
);
1447 mmix_print_operand (asm_out_file
, x
, 'W');
1448 fputc ('\n', asm_out_file
);
1452 if (GET_CODE (x
) != CONST_INT
)
1457 fputs ("\tTETRA\t", asm_out_file
);
1458 mmix_print_operand (asm_out_file
, x
, 'L');
1459 fputc ('\n', asm_out_file
);
1463 /* We don't get here anymore for CONST_DOUBLE, because DImode
1464 isn't expressed as CONST_DOUBLE, and DFmode is handled
1466 gcc_assert (GET_CODE (x
) != CONST_DOUBLE
);
1467 assemble_integer_with_op ("\tOCTA\t", x
);
1470 return default_assemble_integer (x
, size
, aligned_p
);
1473 /* ASM_OUTPUT_ASCII. */
1476 mmix_asm_output_ascii (FILE *stream
, const char *string
, int length
)
1480 int chunk_size
= length
> 60 ? 60 : length
;
1481 fprintf (stream
, "\tBYTE ");
1482 mmix_output_quoted_string (stream
, string
, chunk_size
);
1483 string
+= chunk_size
;
1484 length
-= chunk_size
;
1485 fprintf (stream
, "\n");
1489 /* ASM_OUTPUT_ALIGNED_COMMON. */
1492 mmix_asm_output_aligned_common (FILE *stream
,
1497 /* This is mostly the elfos.h one. There doesn't seem to be a way to
1498 express this in a mmixal-compatible way. */
1499 fprintf (stream
, "\t.comm\t");
1500 assemble_name (stream
, name
);
1501 fprintf (stream
, ",%u,%u ! mmixal-incompatible COMMON\n",
1502 size
, align
/ BITS_PER_UNIT
);
1505 /* ASM_OUTPUT_ALIGNED_LOCAL. */
1508 mmix_asm_output_aligned_local (FILE *stream
,
1513 switch_to_section (data_section
);
1515 ASM_OUTPUT_ALIGN (stream
, exact_log2 (align
/BITS_PER_UNIT
));
1516 assemble_name (stream
, name
);
1517 fprintf (stream
, "\tLOC @+%d\n", size
);
1520 /* ASM_OUTPUT_LABEL. */
1523 mmix_asm_output_label (FILE *stream
, const char *name
)
1525 assemble_name (stream
, name
);
1526 fprintf (stream
, "\tIS @\n");
1529 /* ASM_OUTPUT_INTERNAL_LABEL. */
1532 mmix_asm_output_internal_label (FILE *stream
, const char *name
)
1534 assemble_name_raw (stream
, name
);
1535 fprintf (stream
, "\tIS @\n");
1538 /* ASM_DECLARE_REGISTER_GLOBAL. */
1541 mmix_asm_declare_register_global (FILE *stream ATTRIBUTE_UNUSED
,
1542 tree decl ATTRIBUTE_UNUSED
,
1543 int regno ATTRIBUTE_UNUSED
,
1544 const char *name ATTRIBUTE_UNUSED
)
1546 /* Nothing to do here, but there *will* be, therefore the framework is
1550 /* ASM_WEAKEN_LABEL. */
1553 mmix_asm_weaken_label (FILE *stream ATTRIBUTE_UNUSED
,
1554 const char *name ATTRIBUTE_UNUSED
)
1556 fprintf (stream
, "\t.weak ");
1557 assemble_name (stream
, name
);
1558 fprintf (stream
, " ! mmixal-incompatible\n");
1561 /* MAKE_DECL_ONE_ONLY. */
1564 mmix_make_decl_one_only (tree decl
)
1566 DECL_WEAK (decl
) = 1;
1569 /* ASM_OUTPUT_LABELREF.
1570 Strip GCC's '*' and our own '@'. No order is assumed. */
1573 mmix_asm_output_labelref (FILE *stream
, const char *name
)
1577 for (; (*name
== '@' || *name
== '*'); name
++)
1581 asm_fprintf (stream
, "%s%U%s",
1582 is_extern
&& TARGET_TOPLEVEL_SYMBOLS
? ":" : "",
1586 /* ASM_OUTPUT_DEF. */
1589 mmix_asm_output_def (FILE *stream
, const char *name
, const char *value
)
1591 assemble_name (stream
, name
);
1592 fprintf (stream
, "\tIS ");
1593 assemble_name (stream
, value
);
1594 fputc ('\n', stream
);
1597 /* TARGET_PRINT_OPERAND. */
1600 mmix_print_operand (FILE *stream
, rtx x
, int code
)
1602 /* When we add support for different codes later, we can, when needed,
1603 drop through to the main handler with a modified operand. */
1605 int regno
= x
!= NULL_RTX
&& REG_P (x
) ? REGNO (x
) : 0;
1609 /* Unrelated codes are in alphabetic order. */
1612 /* For conditional branches, output "P" for a probable branch. */
1613 if (TARGET_BRANCH_PREDICT
)
1615 x
= find_reg_note (current_output_insn
, REG_BR_PROB
, 0);
1616 if (x
&& profile_probability::from_reg_br_prob_note (XINT (x
, 0))
1617 > profile_probability::even ())
1623 /* For the %d in POP %d,0. */
1624 fprintf (stream
, "%d", MMIX_POP_ARGUMENT ());
1628 /* The number of registers we want to save. This was setup by the
1630 fprintf (stream
, "%d", cfun
->machine
->highest_saved_stack_register
+ 1);
1634 if (GET_CODE (x
) != CONST_INT
)
1635 fatal_insn ("MMIX Internal: Expected a CONST_INT, not this", x
);
1636 fprintf (stream
, "%d", (int) (INTVAL (x
) & 0xff));
1640 /* Highpart. Must be general register, and not the last one, as
1641 that one cannot be part of a consecutive register pair. */
1642 if (regno
> MMIX_LAST_GENERAL_REGISTER
- 1)
1643 internal_error ("MMIX Internal: Bad register: %d", regno
);
1645 /* This is big-endian, so the high-part is the first one. */
1646 fprintf (stream
, "%s", reg_names
[MMIX_OUTPUT_REGNO (regno
)]);
1650 /* Lowpart. Must be CONST_INT or general register, and not the last
1651 one, as that one cannot be part of a consecutive register pair. */
1652 if (GET_CODE (x
) == CONST_INT
)
1654 fprintf (stream
, "#%lx",
1655 (unsigned long) (INTVAL (x
)
1656 & ((unsigned int) 0x7fffffff * 2 + 1)));
1660 if (GET_CODE (x
) == SYMBOL_REF
)
1662 output_addr_const (stream
, x
);
1666 if (regno
> MMIX_LAST_GENERAL_REGISTER
- 1)
1667 internal_error ("MMIX Internal: Bad register: %d", regno
);
1669 /* This is big-endian, so the low-part is + 1. */
1670 fprintf (stream
, "%s", reg_names
[MMIX_OUTPUT_REGNO (regno
) + 1]);
1673 /* Can't use 'a' because that's a generic modifier for address
1676 mmix_output_shiftvalue_op_from_str (stream
, "ANDN",
1682 mmix_output_shiftvalue_op_from_str (stream
, "INC",
1688 mmix_output_shiftvalue_op_from_str (stream
, "OR",
1694 mmix_output_shiftvalue_op_from_str (stream
, "SET",
1701 mmix_output_condition (stream
, x
, (code
== 'D'));
1705 /* Output an extra "e" to make fcmpe, fune. */
1706 if (TARGET_FCMP_EPSILON
)
1707 fprintf (stream
, "e");
1711 /* Output the number minus 1. */
1712 if (GET_CODE (x
) != CONST_INT
)
1714 fatal_insn ("MMIX Internal: Bad value for 'm', not a CONST_INT",
1717 fprintf (stream
, "%" PRId64
,
1718 (int64_t) (mmix_intval (x
) - 1));
1722 /* Store the register to output a constant to. */
1724 fatal_insn ("MMIX Internal: Expected a register, not this", x
);
1725 mmix_output_destination_register
= MMIX_OUTPUT_REGNO (regno
);
1729 /* Output the constant. Note that we use this for floats as well. */
1730 if (GET_CODE (x
) != CONST_INT
1731 && (GET_CODE (x
) != CONST_DOUBLE
1732 || (GET_MODE (x
) != VOIDmode
&& GET_MODE (x
) != DFmode
1733 && GET_MODE (x
) != SFmode
)))
1734 fatal_insn ("MMIX Internal: Expected a constant, not this", x
);
1735 mmix_output_register_setting (stream
,
1736 mmix_output_destination_register
,
1737 mmix_intval (x
), 0);
1741 /* An U for unsigned, if TARGET_ZERO_EXTEND. Ignore the operand. */
1742 if (TARGET_ZERO_EXTEND
)
1747 mmix_output_shifted_value (stream
, (int64_t) mmix_intval (x
));
1751 mmix_output_shifted_value (stream
, (int64_t) ~mmix_intval (x
));
1755 if (GET_CODE (x
) != CONST_INT
)
1756 fatal_insn ("MMIX Internal: Expected a CONST_INT, not this", x
);
1757 fprintf (stream
, "#%x", (int) (INTVAL (x
) & 0xffff));
1761 /* Nothing to do. */
1765 /* Presumably there's a missing case above if we get here. */
1766 internal_error ("MMIX Internal: Missing %qc case in %<mmix_print_operand%>", code
);
1769 switch (GET_CODE (modified_x
))
1772 regno
= REGNO (modified_x
);
1773 if (regno
>= FIRST_PSEUDO_REGISTER
)
1774 internal_error ("MMIX Internal: Bad register: %d", regno
);
1775 fprintf (stream
, "%s", reg_names
[MMIX_OUTPUT_REGNO (regno
)]);
1779 output_address (GET_MODE (modified_x
), XEXP (modified_x
, 0));
1783 /* For -2147483648, mmixal complains that the constant does not fit
1784 in 4 bytes, so let's output it as hex. Take care to handle hosts
1785 where HOST_WIDE_INT is longer than an int.
1787 Print small constants +-255 using decimal. */
1789 if (INTVAL (modified_x
) > -256 && INTVAL (modified_x
) < 256)
1790 fprintf (stream
, "%d", (int) (INTVAL (modified_x
)));
1792 fprintf (stream
, "#%x",
1793 (int) (INTVAL (modified_x
)) & (unsigned int) ~0);
1797 /* Do somewhat as CONST_INT. */
1798 mmix_output_octa (stream
, mmix_intval (modified_x
), 0);
1802 output_addr_const (stream
, modified_x
);
1806 /* No need to test for all strange things. Let output_addr_const do
1808 if (CONSTANT_P (modified_x
)
1809 /* Strangely enough, this is not included in CONSTANT_P.
1810 FIXME: Ask/check about sanity here. */
1811 || LABEL_P (modified_x
))
1813 output_addr_const (stream
, modified_x
);
1817 /* We need the original here. */
1818 fatal_insn ("MMIX Internal: Cannot decode this operand", x
);
1822 /* TARGET_PRINT_OPERAND_PUNCT_VALID_P. */
1825 mmix_print_operand_punct_valid_p (unsigned char code
)
1827 /* A '+' is used for branch prediction, similar to other ports. */
1829 /* A '.' is used for the %d in the POP %d,0 return insn. */
1831 /* A '!' is used for the number of saved registers, like when outputting
1832 PUSHJ and PUSHGO. */
1836 /* TARGET_PRINT_OPERAND_ADDRESS. */
1839 mmix_print_operand_address (FILE *stream
, machine_mode
/*mode*/, rtx x
)
1843 /* I find the generated assembly code harder to read without
1845 fprintf (stream
, "%s,0", reg_names
[MMIX_OUTPUT_REGNO (REGNO (x
))]);
1848 else if (GET_CODE (x
) == PLUS
)
1850 rtx x1
= XEXP (x
, 0);
1851 rtx x2
= XEXP (x
, 1);
1855 fprintf (stream
, "%s,", reg_names
[MMIX_OUTPUT_REGNO (REGNO (x1
))]);
1859 fprintf (stream
, "%s",
1860 reg_names
[MMIX_OUTPUT_REGNO (REGNO (x2
))]);
1863 else if (satisfies_constraint_I (x2
))
1865 output_addr_const (stream
, x2
);
1871 if (TARGET_BASE_ADDRESSES
&& mmix_legitimate_constant_p (Pmode
, x
))
1873 output_addr_const (stream
, x
);
1877 fatal_insn ("MMIX Internal: This is not a recognized address", x
);
1880 /* ASM_OUTPUT_REG_PUSH. */
1883 mmix_asm_output_reg_push (FILE *stream
, int regno
)
1885 fprintf (stream
, "\tSUBU %s,%s,8\n\tSTOU %s,%s,0\n",
1886 reg_names
[MMIX_STACK_POINTER_REGNUM
],
1887 reg_names
[MMIX_STACK_POINTER_REGNUM
],
1888 reg_names
[MMIX_OUTPUT_REGNO (regno
)],
1889 reg_names
[MMIX_STACK_POINTER_REGNUM
]);
1892 /* ASM_OUTPUT_REG_POP. */
1895 mmix_asm_output_reg_pop (FILE *stream
, int regno
)
1897 fprintf (stream
, "\tLDOU %s,%s,0\n\tINCL %s,8\n",
1898 reg_names
[MMIX_OUTPUT_REGNO (regno
)],
1899 reg_names
[MMIX_STACK_POINTER_REGNUM
],
1900 reg_names
[MMIX_STACK_POINTER_REGNUM
]);
1903 /* ASM_OUTPUT_ADDR_DIFF_ELT. */
1906 mmix_asm_output_addr_diff_elt (FILE *stream
,
1907 rtx body ATTRIBUTE_UNUSED
,
1911 fprintf (stream
, "\tTETRA L%d-L%d\n", value
, rel
);
1914 /* ASM_OUTPUT_ADDR_VEC_ELT. */
1917 mmix_asm_output_addr_vec_elt (FILE *stream
, int value
)
1919 fprintf (stream
, "\tOCTA L:%d\n", value
);
1922 /* ASM_OUTPUT_SKIP. */
1925 mmix_asm_output_skip (FILE *stream
, int nbytes
)
1927 fprintf (stream
, "\tLOC @+%d\n", nbytes
);
1930 /* ASM_OUTPUT_ALIGN. */
1933 mmix_asm_output_align (FILE *stream
, int power
)
1935 /* We need to record the needed alignment of this section in the object,
1936 so we have to output an alignment directive. Use a .p2align (not
1937 .align) so people will never have to wonder about whether the
1938 argument is in number of bytes or the log2 thereof. We do it in
1939 addition to the LOC directive, so nothing needs tweaking when
1940 copy-pasting assembly into mmixal. */
1941 fprintf (stream
, "\t.p2align %d\n", power
);
1942 fprintf (stream
, "\tLOC @+(%d-@)&%d\n", 1 << power
, (1 << power
) - 1);
1945 /* DEBUGGER_REGNO. */
1948 mmix_debugger_regno (unsigned regno
)
1950 /* Adjust the register number to the one it will be output as, dammit.
1951 It'd be nice if we could check the assumption that we're filling a
1952 gap, but every register between the last saved register and parameter
1953 registers might be a valid parameter register. */
1954 regno
= MMIX_OUTPUT_REGNO (regno
);
1956 /* We need to renumber registers to get the number of the return address
1957 register in the range 0..255. It is also space-saving if registers
1958 mentioned in the call-frame information (which uses this function by
1959 defaulting DWARF_FRAME_REGNUM to DEBUGGER_REGNO) are numbered
1960 0 .. 63. So map 224 .. 256+15 -> 0 .. 47 and 0 .. 223 -> 48..223+48. */
1961 return regno
>= 224 ? (regno
- 224) : (regno
+ 48);
1964 /* End of target macro support functions.
1966 Now the MMIX port's own functions. First the exported ones. */
1968 /* Wrapper for get_hard_reg_initial_val since integrate.h isn't included
1969 from insn-emit.cc. */
1972 mmix_get_hard_reg_initial_val (machine_mode mode
, int regno
)
1974 return get_hard_reg_initial_val (mode
, regno
);
1977 /* Nonzero when the function epilogue is simple enough that a single
1978 "POP %d,0" should be used even within the function. */
1981 mmix_use_simple_return (void)
1985 int stack_space_to_allocate
1986 = (crtl
->outgoing_args_size
1987 + crtl
->args
.pretend_args_size
1988 + get_frame_size () + 7) & ~7;
1990 if (!TARGET_USE_RETURN_INSN
|| !reload_completed
)
1994 regno
>= MMIX_FIRST_GLOBAL_REGNUM
;
1996 /* Note that we assume that the frame-pointer-register is one of these
1997 registers, in which case we don't count it here. */
1998 if ((((regno
!= MMIX_FRAME_POINTER_REGNUM
|| !frame_pointer_needed
)
1999 && df_regs_ever_live_p (regno
) && !call_used_or_fixed_reg_p (regno
)))
2000 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
2003 if (frame_pointer_needed
)
2004 stack_space_to_allocate
+= 8;
2006 if (MMIX_CFUN_HAS_LANDING_PAD
)
2007 stack_space_to_allocate
+= 16;
2008 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
)
2009 stack_space_to_allocate
+= 8;
2011 return stack_space_to_allocate
== 0;
2015 /* Expands the function prologue into RTX. */
2018 mmix_expand_prologue (void)
2020 HOST_WIDE_INT locals_size
= get_frame_size ();
2022 HOST_WIDE_INT stack_space_to_allocate
2023 = (crtl
->outgoing_args_size
2024 + crtl
->args
.pretend_args_size
2025 + locals_size
+ 7) & ~7;
2026 HOST_WIDE_INT offset
= -8;
2027 HOST_WIDE_INT total_allocated_stack_space
= 0;
2029 /* Add room needed to save global non-register-stack registers. */
2031 regno
>= MMIX_FIRST_GLOBAL_REGNUM
;
2033 /* Note that we assume that the frame-pointer-register is one of these
2034 registers, in which case we don't count it here. */
2035 if ((((regno
!= MMIX_FRAME_POINTER_REGNUM
|| !frame_pointer_needed
)
2036 && df_regs_ever_live_p (regno
) && !call_used_or_fixed_reg_p (regno
)))
2037 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
2038 stack_space_to_allocate
+= 8;
2040 /* If we do have a frame-pointer, add room for it. */
2041 if (frame_pointer_needed
)
2042 stack_space_to_allocate
+= 8;
2044 /* If we have a non-local label, we need to be able to unwind to it, so
2045 store the current register stack pointer. Also store the return
2046 address if we do that. */
2047 if (MMIX_CFUN_HAS_LANDING_PAD
)
2048 stack_space_to_allocate
+= 16;
2049 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
)
2050 /* If we do have a saved return-address slot, add room for it. */
2051 stack_space_to_allocate
+= 8;
2053 /* Make sure we don't get an unaligned stack. */
2054 if ((stack_space_to_allocate
% 8) != 0)
2055 internal_error ("stack frame not a multiple of 8 bytes: %wd",
2056 stack_space_to_allocate
);
2058 if (crtl
->args
.pretend_args_size
)
2060 int mmix_first_vararg_reg
2061 = (MMIX_FIRST_INCOMING_ARG_REGNUM
2062 + (MMIX_MAX_ARGS_IN_REGS
2063 - crtl
->args
.pretend_args_size
/ 8));
2066 = MMIX_FIRST_INCOMING_ARG_REGNUM
+ MMIX_MAX_ARGS_IN_REGS
- 1;
2067 regno
>= mmix_first_vararg_reg
;
2072 HOST_WIDE_INT stack_chunk
2073 = stack_space_to_allocate
> (256 - 8)
2074 ? (256 - 8) : stack_space_to_allocate
;
2076 mmix_emit_sp_add (-stack_chunk
);
2077 total_allocated_stack_space
+= stack_chunk
;
2079 offset
+= stack_chunk
;
2080 stack_space_to_allocate
-= stack_chunk
;
2083 /* These registers aren't actually saved (as in "will be
2084 restored"), so don't tell DWARF2 they're saved. */
2085 emit_move_insn (gen_rtx_MEM (DImode
,
2086 plus_constant (Pmode
, stack_pointer_rtx
,
2088 gen_rtx_REG (DImode
, regno
));
2093 /* Store the frame-pointer. */
2095 if (frame_pointer_needed
)
2101 /* Get 8 less than otherwise, since we need to reach offset + 8. */
2102 HOST_WIDE_INT stack_chunk
2103 = stack_space_to_allocate
> (256 - 8 - 8)
2104 ? (256 - 8 - 8) : stack_space_to_allocate
;
2106 mmix_emit_sp_add (-stack_chunk
);
2107 total_allocated_stack_space
+= stack_chunk
;
2109 offset
+= stack_chunk
;
2110 stack_space_to_allocate
-= stack_chunk
;
2113 insn
= emit_move_insn (gen_rtx_MEM (DImode
,
2114 plus_constant (Pmode
,
2117 hard_frame_pointer_rtx
);
2118 RTX_FRAME_RELATED_P (insn
) = 1;
2119 insn
= emit_insn (gen_adddi3 (hard_frame_pointer_rtx
,
2121 GEN_INT (offset
+ 8)));
2122 RTX_FRAME_RELATED_P (insn
) = 1;
2126 if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
)
2131 /* Store the return-address, if one is needed on the stack. We
2132 usually store it in a register when needed, but that doesn't work
2133 with -fexceptions. */
2137 /* Get 8 less than otherwise, since we need to reach offset + 8. */
2138 HOST_WIDE_INT stack_chunk
2139 = stack_space_to_allocate
> (256 - 8 - 8)
2140 ? (256 - 8 - 8) : stack_space_to_allocate
;
2142 mmix_emit_sp_add (-stack_chunk
);
2143 total_allocated_stack_space
+= stack_chunk
;
2145 offset
+= stack_chunk
;
2146 stack_space_to_allocate
-= stack_chunk
;
2149 tmpreg
= gen_rtx_REG (DImode
, 255);
2150 retreg
= gen_rtx_REG (DImode
, MMIX_rJ_REGNUM
);
2152 /* Dwarf2 code is confused by the use of a temporary register for
2153 storing the return address, so we have to express it as a note,
2154 which we attach to the actual store insn. */
2155 emit_move_insn (tmpreg
, retreg
);
2157 insn
= emit_move_insn (gen_rtx_MEM (DImode
,
2158 plus_constant (Pmode
,
2162 RTX_FRAME_RELATED_P (insn
) = 1;
2163 add_reg_note (insn
, REG_FRAME_RELATED_EXPR
,
2164 gen_rtx_SET (gen_rtx_MEM (DImode
,
2165 plus_constant (Pmode
,
2172 else if (MMIX_CFUN_HAS_LANDING_PAD
)
2175 if (MMIX_CFUN_HAS_LANDING_PAD
)
2177 /* Store the register defining the numbering of local registers, so
2178 we know how long to unwind the register stack. */
2182 /* Get 8 less than otherwise, since we need to reach offset + 8. */
2183 HOST_WIDE_INT stack_chunk
2184 = stack_space_to_allocate
> (256 - 8 - 8)
2185 ? (256 - 8 - 8) : stack_space_to_allocate
;
2187 mmix_emit_sp_add (-stack_chunk
);
2188 total_allocated_stack_space
+= stack_chunk
;
2190 offset
+= stack_chunk
;
2191 stack_space_to_allocate
-= stack_chunk
;
2194 /* We don't tell dwarf2 about this one; we just have it to unwind
2195 the register stack at landing pads. FIXME: It's a kludge because
2196 we can't describe the effect of the PUSHJ and PUSHGO insns on the
2197 register stack at the moment. Best thing would be to handle it
2198 like stack-pointer offsets. Better: some hook into dwarf2out.cc
2199 to produce DW_CFA_expression:s that specify the increment of rO,
2200 and unwind it at eh_return (preferred) or at the landing pad.
2201 Then saves to $0..$G-1 could be specified through that register. */
2203 emit_move_insn (gen_rtx_REG (DImode
, 255),
2204 gen_rtx_REG (DImode
,
2206 emit_move_insn (gen_rtx_MEM (DImode
,
2207 plus_constant (Pmode
, stack_pointer_rtx
,
2209 gen_rtx_REG (DImode
, 255));
2213 /* After the return-address and the frame-pointer, we have the local
2214 variables. They're the ones that may have an "unaligned" size. */
2215 offset
-= (locals_size
+ 7) & ~7;
2217 /* Now store all registers that are global, i.e. not saved by the
2218 register file machinery.
2220 It is assumed that the frame-pointer is one of these registers, so it
2221 is explicitly excluded in the count. */
2224 regno
>= MMIX_FIRST_GLOBAL_REGNUM
;
2226 if (((regno
!= MMIX_FRAME_POINTER_REGNUM
|| !frame_pointer_needed
)
2227 && df_regs_ever_live_p (regno
) && !call_used_or_fixed_reg_p (regno
))
2228 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
2234 HOST_WIDE_INT stack_chunk
2235 = (stack_space_to_allocate
> (256 - offset
- 8)
2236 ? (256 - offset
- 8) : stack_space_to_allocate
);
2238 mmix_emit_sp_add (-stack_chunk
);
2239 total_allocated_stack_space
+= stack_chunk
;
2241 offset
+= stack_chunk
;
2242 stack_space_to_allocate
-= stack_chunk
;
2245 insn
= emit_move_insn (gen_rtx_MEM (DImode
,
2246 plus_constant (Pmode
,
2249 gen_rtx_REG (DImode
, regno
));
2250 RTX_FRAME_RELATED_P (insn
) = 1;
2254 /* Finally, allocate room for outgoing args and local vars if room
2255 wasn't allocated above. */
2256 if (stack_space_to_allocate
)
2257 mmix_emit_sp_add (-stack_space_to_allocate
);
2258 total_allocated_stack_space
+= stack_space_to_allocate
;
2260 /* Let's assume that reporting the usage of the regular stack on its
2261 own, is more useful than either not supporting -fstack-usage or
2262 reporting the sum of the usages of the regular stack and the
2264 if (flag_stack_usage_info
)
2265 current_function_static_stack_size
= total_allocated_stack_space
;
2268 /* Expands the function epilogue into RTX. */
2271 mmix_expand_epilogue (void)
2273 HOST_WIDE_INT locals_size
= get_frame_size ();
2275 HOST_WIDE_INT stack_space_to_deallocate
2276 = (crtl
->outgoing_args_size
2277 + crtl
->args
.pretend_args_size
2278 + locals_size
+ 7) & ~7;
2280 /* The first address to access is beyond the outgoing_args area. */
2281 HOST_WIDE_INT offset
= crtl
->outgoing_args_size
;
2283 /* Add the space for global non-register-stack registers.
2284 It is assumed that the frame-pointer register can be one of these
2285 registers, in which case it is excluded from the count when needed. */
2287 regno
>= MMIX_FIRST_GLOBAL_REGNUM
;
2289 if (((regno
!= MMIX_FRAME_POINTER_REGNUM
|| !frame_pointer_needed
)
2290 && df_regs_ever_live_p (regno
) && !call_used_or_fixed_reg_p (regno
))
2291 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
2292 stack_space_to_deallocate
+= 8;
2294 /* Add in the space for register stack-pointer. If so, always add room
2295 for the saved PC. */
2296 if (MMIX_CFUN_HAS_LANDING_PAD
)
2297 stack_space_to_deallocate
+= 16;
2298 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
)
2299 /* If we have a saved return-address slot, add it in. */
2300 stack_space_to_deallocate
+= 8;
2302 /* Add in the frame-pointer. */
2303 if (frame_pointer_needed
)
2304 stack_space_to_deallocate
+= 8;
2306 /* Make sure we don't get an unaligned stack. */
2307 if ((stack_space_to_deallocate
% 8) != 0)
2308 internal_error ("stack frame not a multiple of octabyte: %wd",
2309 stack_space_to_deallocate
);
2311 /* We will add back small offsets to the stack pointer as we go.
2312 First, we restore all registers that are global, i.e. not saved by
2313 the register file machinery. */
2315 for (regno
= MMIX_FIRST_GLOBAL_REGNUM
;
2318 if (((regno
!= MMIX_FRAME_POINTER_REGNUM
|| !frame_pointer_needed
)
2319 && df_regs_ever_live_p (regno
) && !call_used_or_fixed_reg_p (regno
))
2320 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
2324 mmix_emit_sp_add (offset
);
2325 stack_space_to_deallocate
-= offset
;
2329 emit_move_insn (gen_rtx_REG (DImode
, regno
),
2330 gen_rtx_MEM (DImode
,
2331 plus_constant (Pmode
, stack_pointer_rtx
,
2336 /* Here is where the local variables were. As in the prologue, they
2337 might be of an unaligned size. */
2338 offset
+= (locals_size
+ 7) & ~7;
2340 /* The saved register stack pointer is just below the frame-pointer
2341 register. We don't need to restore it "manually"; the POP
2342 instruction does that. */
2343 if (MMIX_CFUN_HAS_LANDING_PAD
)
2345 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
)
2346 /* The return-address slot is just below the frame-pointer register.
2347 We don't need to restore it because we don't really use it. */
2350 /* Get back the old frame-pointer-value. */
2351 if (frame_pointer_needed
)
2355 mmix_emit_sp_add (offset
);
2357 stack_space_to_deallocate
-= offset
;
2361 emit_move_insn (hard_frame_pointer_rtx
,
2362 gen_rtx_MEM (DImode
,
2363 plus_constant (Pmode
, stack_pointer_rtx
,
2368 /* We do not need to restore pretended incoming args, just add back
2370 if (stack_space_to_deallocate
!= 0)
2371 mmix_emit_sp_add (stack_space_to_deallocate
);
2373 if (crtl
->calls_eh_return
)
2374 /* Adjust the (normal) stack-pointer to that of the receiver.
2375 FIXME: It would be nice if we could also adjust the register stack
2376 here, but we need to express it through DWARF 2 too. */
2377 emit_insn (gen_adddi3 (stack_pointer_rtx
, stack_pointer_rtx
,
2378 gen_rtx_REG (DImode
,
2379 MMIX_EH_RETURN_STACKADJ_REGNUM
)));
2382 /* Output an optimal sequence for setting a register to a specific
2383 constant. Used in an alternative for const_ints in movdi, and when
2384 using large stack-frame offsets.
2386 Use do_begin_end to say if a line-starting TAB and newline before the
2387 first insn and after the last insn is wanted. */
2390 mmix_output_register_setting (FILE *stream
,
2396 fprintf (stream
, "\t");
2398 if (insn_const_int_ok_for_constraint (value
, CONSTRAINT_K
))
2399 fprintf (stream
, "NEGU %s,0,%" PRId64
, reg_names
[regno
], -value
);
2400 else if (mmix_shiftable_wyde_value ((uint64_t) value
))
2402 /* First, the one-insn cases. */
2403 mmix_output_shiftvalue_op_from_str (stream
, "SET",
2406 fprintf (stream
, " %s,", reg_names
[regno
]);
2407 mmix_output_shifted_value (stream
, (uint64_t) value
);
2409 else if (mmix_shiftable_wyde_value (-(uint64_t) value
))
2411 /* We do this to get a bit more legible assembly code. The next
2412 alternative is mostly redundant with this. */
2414 mmix_output_shiftvalue_op_from_str (stream
, "SET",
2417 fprintf (stream
, " %s,", reg_names
[regno
]);
2418 mmix_output_shifted_value (stream
, -(uint64_t) value
);
2419 fprintf (stream
, "\n\tNEGU %s,0,%s", reg_names
[regno
],
2422 else if (mmix_shiftable_wyde_value (~(uint64_t) value
))
2424 /* Slightly more expensive, the two-insn cases. */
2426 /* FIXME: We could of course also test if 0..255-N or ~(N | 1..255)
2427 is shiftable, or any other one-insn transformation of the value.
2428 FIXME: Check first if the value is "shiftable" by two loading
2429 with two insns, since it makes more readable assembly code (if
2430 anyone else cares). */
2432 mmix_output_shiftvalue_op_from_str (stream
, "SET",
2435 fprintf (stream
, " %s,", reg_names
[regno
]);
2436 mmix_output_shifted_value (stream
, ~(uint64_t) value
);
2437 fprintf (stream
, "\n\tNOR %s,%s,0", reg_names
[regno
],
2442 /* The generic case. 2..4 insns. */
2443 static const char *const higher_parts
[] = {"L", "ML", "MH", "H"};
2444 const char *op
= "SET";
2445 const char *line_begin
= "";
2448 int64_t tmpvalue
= value
;
2450 /* Compute the number of insns needed to output this constant. */
2451 for (i
= 0; i
< 4 && tmpvalue
!= 0; i
++)
2453 if (tmpvalue
& 65535)
2457 if (TARGET_BASE_ADDRESSES
&& insns
== 3)
2459 /* The number three is based on a static observation on
2460 ghostscript-6.52. Two and four are excluded because there
2461 are too many such constants, and each unique constant (maybe
2462 offset by 1..255) were used few times compared to other uses,
2465 We use base-plus-offset addressing to force it into a global
2466 register; we just use a "LDA reg,VALUE", which will cause the
2467 assembler and linker to DTRT (for constants as well as
2469 fprintf (stream
, "LDA %s,", reg_names
[regno
]);
2470 mmix_output_octa (stream
, value
, 0);
2474 /* Output pertinent parts of the 4-wyde sequence.
2475 Still more to do if we want this to be optimal, but hey...
2476 Note that the zero case has been handled above. */
2477 for (i
= 0; i
< 4 && value
!= 0; i
++)
2481 fprintf (stream
, "%s%s%s %s,#%x", line_begin
, op
,
2482 higher_parts
[i
], reg_names
[regno
],
2483 (int) (value
& 65535));
2484 /* The first one sets the rest of the bits to 0, the next
2485 ones add set bits. */
2487 line_begin
= "\n\t";
2496 fprintf (stream
, "\n");
2499 /* Return 1 if value is 0..65535*2**(16*N) for N=0..3.
2503 mmix_shiftable_wyde_value (uint64_t value
)
2505 /* Shift by 16 bits per group, stop when we've found two groups with
2508 int has_candidate
= 0;
2510 for (i
= 0; i
< 4; i
++)
2526 /* X and Y are two things to compare using CODE. Return the rtx for
2527 the cc-reg in the proper mode. */
2530 mmix_gen_compare_reg (RTX_CODE code
, rtx x
, rtx y
)
2532 machine_mode ccmode
= SELECT_CC_MODE (code
, x
, y
);
2533 return gen_reg_rtx (ccmode
);
2536 /* Local (static) helper functions. */
2539 mmix_emit_sp_add (HOST_WIDE_INT offset
)
2545 /* Negative stack-pointer adjustments are allocations and appear in
2546 the prologue only. We mark them as frame-related so unwind and
2547 debug info is properly emitted for them. */
2549 insn
= emit_insn (gen_adddi3 (stack_pointer_rtx
,
2554 rtx tmpr
= gen_rtx_REG (DImode
, 255);
2555 RTX_FRAME_RELATED_P (emit_move_insn (tmpr
, GEN_INT (offset
))) = 1;
2556 insn
= emit_insn (gen_adddi3 (stack_pointer_rtx
,
2557 stack_pointer_rtx
, tmpr
));
2559 RTX_FRAME_RELATED_P (insn
) = 1;
2563 /* Positive adjustments are in the epilogue only. Don't mark them
2564 as "frame-related" for unwind info. */
2565 if (insn_const_int_ok_for_constraint (offset
, CONSTRAINT_L
))
2566 emit_insn (gen_adddi3 (stack_pointer_rtx
,
2571 rtx tmpr
= gen_rtx_REG (DImode
, 255);
2572 emit_move_insn (tmpr
, GEN_INT (offset
));
2573 insn
= emit_insn (gen_adddi3 (stack_pointer_rtx
,
2574 stack_pointer_rtx
, tmpr
));
2579 /* Print operator suitable for doing something with a shiftable
2580 wyde. The type of operator is passed as an asm output modifier. */
2583 mmix_output_shiftvalue_op_from_str (FILE *stream
,
2587 static const char *const op_part
[] = {"L", "ML", "MH", "H"};
2590 if (! mmix_shiftable_wyde_value (value
))
2592 char s
[sizeof ("0xffffffffffffffff")];
2593 sprintf (s
, "%#" PRIx64
, value
);
2594 internal_error ("MMIX Internal: %s is not a shiftable integer", s
);
2597 for (i
= 0; i
< 4; i
++)
2599 /* We know we're through when we find one-bits in the low
2603 fprintf (stream
, "%s%s", mainop
, op_part
[i
]);
2609 /* No bits set? Then it must have been zero. */
2610 fprintf (stream
, "%sL", mainop
);
2613 /* Print a 64-bit value, optionally prefixed by assembly pseudo. */
2616 mmix_output_octa (FILE *stream
, int64_t value
, int do_begin_end
)
2619 fprintf (stream
, "\tOCTA ");
2621 /* Provide a few alternative output formats depending on the number, to
2622 improve legibility of assembler output. */
2623 if ((value
< (int64_t) 0 && value
> (int64_t) -10000)
2624 || (value
>= (int64_t) 0 && value
<= (int64_t) 16384))
2625 fprintf (stream
, "%d", (int) value
);
2626 else if (value
> (int64_t) 0
2627 && value
< ((int64_t) 1 << 31) * 2)
2628 fprintf (stream
, "#%x", (unsigned int) value
);
2629 else if (sizeof (HOST_WIDE_INT
) == sizeof (int64_t))
2630 /* We need to avoid the not-so-universal "0x" prefix; we need the
2631 pure hex-digits together with the mmixal "#" hex prefix. */
2632 fprintf (stream
, "#" HOST_WIDE_INT_PRINT_HEX_PURE
,
2633 (HOST_WIDE_INT
) value
);
2634 else /* Need to avoid the hex output; there's no ...WIDEST...HEX_PURE. */
2635 fprintf (stream
, "%" PRIu64
, value
);
2638 fprintf (stream
, "\n");
2641 /* Print the presumed shiftable wyde argument shifted into place (to
2642 be output with an operand). */
2645 mmix_output_shifted_value (FILE *stream
, int64_t value
)
2649 if (! mmix_shiftable_wyde_value (value
))
2652 sprintf (s
, "%#" PRIx64
, value
);
2653 internal_error ("MMIX Internal: %s is not a shiftable integer", s
);
2656 for (i
= 0; i
< 4; i
++)
2658 /* We know we're through when we find one-bits in the low 16 bits. */
2661 fprintf (stream
, "#%x", (int) (value
& 0xffff));
2668 /* No bits set? Then it must have been zero. */
2669 fprintf (stream
, "0");
2672 /* Output an MMIX condition name corresponding to an operator
2674 (comparison_operator [(comparison_operator ...) (const_int 0)])
2675 which means we have to look at *two* operators.
2677 The argument "reversed" refers to reversal of the condition (not the
2678 same as swapping the arguments). */
2681 mmix_output_condition (FILE *stream
, const_rtx x
, int reversed
)
2687 /* The normal output cc-code. */
2688 const char *const normal
;
2690 /* The reversed cc-code, or NULL if invalid. */
2691 const char *const reversed
;
2696 machine_mode cc_mode
;
2698 /* Terminated with {UNKNOWN, NULL, NULL} */
2699 const struct cc_conv
*const convs
;
2703 #define CCEND {UNKNOWN, NULL, NULL}
2705 static const struct cc_conv cc_fun_convs
[]
2706 = {{ORDERED
, "Z", "P"},
2707 {UNORDERED
, "P", "Z"},
2709 static const struct cc_conv cc_fp_convs
[]
2713 static const struct cc_conv cc_fpeq_convs
[]
2717 static const struct cc_conv cc_uns_convs
[]
2718 = {{GEU
, "NN", "N"},
2723 static const struct cc_conv cc_signed_convs
[]
2731 static const struct cc_conv cc_di_convs
[]
2743 static const struct cc_type_conv cc_convs
[]
2744 = {{E_CC_FUNmode
, cc_fun_convs
},
2745 {E_CC_FPmode
, cc_fp_convs
},
2746 {E_CC_FPEQmode
, cc_fpeq_convs
},
2747 {E_CC_UNSmode
, cc_uns_convs
},
2748 {E_CCmode
, cc_signed_convs
},
2749 {E_DImode
, cc_di_convs
}};
2754 machine_mode mode
= GET_MODE (XEXP (x
, 0));
2755 RTX_CODE cc
= GET_CODE (x
);
2757 for (i
= 0; i
< ARRAY_SIZE (cc_convs
); i
++)
2759 if (mode
== cc_convs
[i
].cc_mode
)
2761 for (j
= 0; cc_convs
[i
].convs
[j
].cc
!= UNKNOWN
; j
++)
2762 if (cc
== cc_convs
[i
].convs
[j
].cc
)
2765 = (reversed
? cc_convs
[i
].convs
[j
].reversed
2766 : cc_convs
[i
].convs
[j
].normal
);
2768 if (mmix_cc
== NULL
)
2769 fatal_insn ("MMIX Internal: Trying to output invalidly\
2770 reversed condition:", x
);
2772 fprintf (stream
, "%s", mmix_cc
);
2776 fatal_insn ("MMIX Internal: What's the CC of this?", x
);
2780 fatal_insn ("MMIX Internal: What is the CC of this?", x
);
2783 /* Return the bit-value for a const_int or const_double. */
2786 mmix_intval (const_rtx x
)
2788 if (GET_CODE (x
) == CONST_INT
)
2791 /* We make a little song and dance because converting to long long in
2792 gcc-2.7.2 is broken. I still want people to be able to use it for
2793 cross-compilation to MMIX. */
2794 if (GET_CODE (x
) == CONST_DOUBLE
&& GET_MODE (x
) == VOIDmode
)
2795 return CONST_DOUBLE_HIGH (x
);
2797 if (GET_CODE (x
) == CONST_DOUBLE
)
2799 if (GET_MODE (x
) == DFmode
)
2803 REAL_VALUE_TO_TARGET_DOUBLE (*CONST_DOUBLE_REAL_VALUE (x
), bits
);
2805 /* The double cast is necessary to avoid getting the long
2806 sign-extended to unsigned long long(!) when they're of
2807 different size (usually 32-bit hosts). */
2809 ((uint64_t) (unsigned long) bits
[0]
2811 | (uint64_t) (unsigned long) bits
[1];
2813 else if (GET_MODE (x
) == SFmode
)
2816 REAL_VALUE_TO_TARGET_SINGLE (*CONST_DOUBLE_REAL_VALUE (x
), bits
);
2818 return (unsigned long) bits
;
2822 fatal_insn ("MMIX Internal: This is not a constant:", x
);
2825 /* Worker function for TARGET_PROMOTE_FUNCTION_MODE. */
2828 mmix_promote_function_mode (const_tree type ATTRIBUTE_UNUSED
,
2830 int *punsignedp ATTRIBUTE_UNUSED
,
2831 const_tree fntype ATTRIBUTE_UNUSED
,
2834 /* Apparently not doing TRT if int < register-size. FIXME: Perhaps
2835 FUNCTION_VALUE and LIBCALL_VALUE needs tweaking as some ports say. */
2836 if (for_return
== 1)
2839 /* Promotion of modes currently generates slow code, extending before
2840 operation, so we do it only for arguments. */
2841 if (GET_MODE_CLASS (mode
) == MODE_INT
2842 && GET_MODE_SIZE (mode
) < 8)
2847 /* Worker function for TARGET_STRUCT_VALUE_RTX. */
2850 mmix_struct_value_rtx (tree fntype ATTRIBUTE_UNUSED
,
2851 int incoming ATTRIBUTE_UNUSED
)
2853 return gen_rtx_REG (Pmode
, MMIX_STRUCT_VALUE_REGNUM
);
2856 /* Worker function for TARGET_FRAME_POINTER_REQUIRED.
2858 FIXME: Is this requirement built-in? Anyway, we should try to get rid
2859 of it; we can deduce the value. */
2862 mmix_frame_pointer_required (void)
2864 return (cfun
->has_nonlocal_label
);
2869 * eval: (c-set-style "gnu")
2870 * indent-tabs-mode: t