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"
27 #include "hard-reg-set.h"
28 #include "insn-config.h"
32 #include "dominance.h"
38 #include "cfgcleanup.h"
39 #include "basic-block.h"
44 #include "stor-layout.h"
53 #include "diagnostic-core.h"
60 #include "tm-constrs.h"
63 /* This file should be included last. */
64 #include "target-def.h"
66 /* First some local helper definitions. */
67 #define MMIX_FIRST_GLOBAL_REGNUM 32
69 /* We'd need a current_function_has_landing_pad. It's marked as such when
70 a nonlocal_goto_receiver is expanded. Not just a C++ thing, but
72 #define MMIX_CFUN_HAS_LANDING_PAD (cfun->machine->has_landing_pad != 0)
74 /* We have no means to tell DWARF 2 about the register stack, so we need
75 to store the return address on the stack if an exception can get into
76 this function. FIXME: Narrow condition. Before any whole-function
77 analysis, df_regs_ever_live_p () isn't initialized. We know it's up-to-date
78 after reload_completed; it may contain incorrect information some time
79 before that. Within a RTL sequence (after a call to start_sequence,
80 such as in RTL expanders), leaf_function_p doesn't see all insns
81 (perhaps any insn). But regs_ever_live is up-to-date when
82 leaf_function_p () isn't, so we "or" them together to get accurate
83 information. FIXME: Some tweak to leaf_function_p might be
85 #define MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS \
87 && ((reload_completed && df_regs_ever_live_p (MMIX_rJ_REGNUM)) \
88 || !leaf_function_p ()))
90 #define IS_MMIX_EH_RETURN_DATA_REG(REGNO) \
91 (crtl->calls_eh_return \
92 && (EH_RETURN_DATA_REGNO (0) == REGNO \
93 || EH_RETURN_DATA_REGNO (1) == REGNO \
94 || EH_RETURN_DATA_REGNO (2) == REGNO \
95 || EH_RETURN_DATA_REGNO (3) == REGNO))
97 /* For the default ABI, we rename registers at output-time to fill the gap
98 between the (statically partitioned) saved registers and call-clobbered
99 registers. In effect this makes unused call-saved registers to be used
100 as call-clobbered registers. The benefit comes from keeping the number
101 of local registers (value of rL) low, since there's a cost of
102 increasing rL and clearing unused (unset) registers with lower numbers.
103 Don't translate while outputting the prologue. */
104 #define MMIX_OUTPUT_REGNO(N) \
106 || (int) (N) < MMIX_RETURN_VALUE_REGNUM \
107 || (int) (N) > MMIX_LAST_STACK_REGISTER_REGNUM \
109 || cfun->machine == NULL \
110 || cfun->machine->in_prologue \
111 ? (N) : ((N) - MMIX_RETURN_VALUE_REGNUM \
112 + cfun->machine->highest_saved_stack_register + 1))
114 /* The %d in "POP %d,0". */
115 #define MMIX_POP_ARGUMENT() \
117 && crtl->return_rtx != NULL \
118 && ! cfun->returns_struct) \
119 ? (GET_CODE (crtl->return_rtx) == PARALLEL \
120 ? GET_NUM_ELEM (XVEC (crtl->return_rtx, 0)) : 1) \
123 /* The canonical saved comparison operands for non-cc0 machines, set in
124 the compare expander. */
125 rtx mmix_compare_op0
;
126 rtx mmix_compare_op1
;
128 /* Declarations of locals. */
130 /* Intermediate for insn output. */
131 static int mmix_output_destination_register
;
133 static void mmix_option_override (void);
134 static void mmix_asm_output_source_filename (FILE *, const char *);
135 static void mmix_output_shiftvalue_op_from_str
136 (FILE *, const char *, int64_t);
137 static void mmix_output_shifted_value (FILE *, int64_t);
138 static void mmix_output_condition (FILE *, const_rtx
, int);
139 static void mmix_output_octa (FILE *, int64_t, int);
140 static bool mmix_assemble_integer (rtx
, unsigned int, int);
141 static struct machine_function
*mmix_init_machine_status (void);
142 static void mmix_encode_section_info (tree
, rtx
, int);
143 static const char *mmix_strip_name_encoding (const char *);
144 static void mmix_emit_sp_add (HOST_WIDE_INT offset
);
145 static void mmix_target_asm_function_prologue (FILE *, HOST_WIDE_INT
);
146 static void mmix_target_asm_function_end_prologue (FILE *);
147 static void mmix_target_asm_function_epilogue (FILE *, HOST_WIDE_INT
);
148 static reg_class_t
mmix_preferred_reload_class (rtx
, reg_class_t
);
149 static reg_class_t
mmix_preferred_output_reload_class (rtx
, reg_class_t
);
150 static bool mmix_legitimate_address_p (machine_mode
, rtx
, bool);
151 static bool mmix_legitimate_constant_p (machine_mode
, rtx
);
152 static void mmix_reorg (void);
153 static void mmix_asm_output_mi_thunk
154 (FILE *, tree
, HOST_WIDE_INT
, HOST_WIDE_INT
, tree
);
155 static void mmix_setup_incoming_varargs
156 (cumulative_args_t
, machine_mode
, tree
, int *, int);
157 static void mmix_file_start (void);
158 static void mmix_file_end (void);
159 static bool mmix_rtx_costs (rtx
, int, int, int, int *, bool);
160 static int mmix_register_move_cost (machine_mode
,
161 reg_class_t
, reg_class_t
);
162 static rtx
mmix_struct_value_rtx (tree
, int);
163 static machine_mode
mmix_promote_function_mode (const_tree
,
165 int *, const_tree
, int);
166 static void mmix_function_arg_advance (cumulative_args_t
, machine_mode
,
168 static rtx
mmix_function_arg_1 (const cumulative_args_t
, machine_mode
,
169 const_tree
, bool, bool);
170 static rtx
mmix_function_incoming_arg (cumulative_args_t
, machine_mode
,
172 static rtx
mmix_function_arg (cumulative_args_t
, machine_mode
,
174 static rtx
mmix_function_value (const_tree
, const_tree
, bool);
175 static rtx
mmix_libcall_value (machine_mode
, const_rtx
);
176 static bool mmix_function_value_regno_p (const unsigned int);
177 static bool mmix_pass_by_reference (cumulative_args_t
,
178 machine_mode
, const_tree
, bool);
179 static bool mmix_frame_pointer_required (void);
180 static void mmix_asm_trampoline_template (FILE *);
181 static void mmix_trampoline_init (rtx
, tree
, rtx
);
182 static void mmix_print_operand (FILE *, rtx
, int);
183 static void mmix_print_operand_address (FILE *, rtx
);
184 static bool mmix_print_operand_punct_valid_p (unsigned char);
185 static void mmix_conditional_register_usage (void);
187 /* Target structure macros. Listed by node. See `Using and Porting GCC'
188 for a general description. */
190 /* Node: Function Entry */
192 #undef TARGET_ASM_BYTE_OP
193 #define TARGET_ASM_BYTE_OP NULL
194 #undef TARGET_ASM_ALIGNED_HI_OP
195 #define TARGET_ASM_ALIGNED_HI_OP NULL
196 #undef TARGET_ASM_ALIGNED_SI_OP
197 #define TARGET_ASM_ALIGNED_SI_OP NULL
198 #undef TARGET_ASM_ALIGNED_DI_OP
199 #define TARGET_ASM_ALIGNED_DI_OP NULL
200 #undef TARGET_ASM_INTEGER
201 #define TARGET_ASM_INTEGER mmix_assemble_integer
203 #undef TARGET_ASM_FUNCTION_PROLOGUE
204 #define TARGET_ASM_FUNCTION_PROLOGUE mmix_target_asm_function_prologue
206 #undef TARGET_ASM_FUNCTION_END_PROLOGUE
207 #define TARGET_ASM_FUNCTION_END_PROLOGUE mmix_target_asm_function_end_prologue
209 #undef TARGET_ASM_FUNCTION_EPILOGUE
210 #define TARGET_ASM_FUNCTION_EPILOGUE mmix_target_asm_function_epilogue
212 #undef TARGET_PRINT_OPERAND
213 #define TARGET_PRINT_OPERAND mmix_print_operand
214 #undef TARGET_PRINT_OPERAND_ADDRESS
215 #define TARGET_PRINT_OPERAND_ADDRESS mmix_print_operand_address
216 #undef TARGET_PRINT_OPERAND_PUNCT_VALID_P
217 #define TARGET_PRINT_OPERAND_PUNCT_VALID_P mmix_print_operand_punct_valid_p
219 #undef TARGET_ENCODE_SECTION_INFO
220 #define TARGET_ENCODE_SECTION_INFO mmix_encode_section_info
221 #undef TARGET_STRIP_NAME_ENCODING
222 #define TARGET_STRIP_NAME_ENCODING mmix_strip_name_encoding
224 #undef TARGET_ASM_OUTPUT_MI_THUNK
225 #define TARGET_ASM_OUTPUT_MI_THUNK mmix_asm_output_mi_thunk
226 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
227 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall
228 #undef TARGET_ASM_FILE_START
229 #define TARGET_ASM_FILE_START mmix_file_start
230 #undef TARGET_ASM_FILE_START_FILE_DIRECTIVE
231 #define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
232 #undef TARGET_ASM_FILE_END
233 #define TARGET_ASM_FILE_END mmix_file_end
234 #undef TARGET_ASM_OUTPUT_SOURCE_FILENAME
235 #define TARGET_ASM_OUTPUT_SOURCE_FILENAME mmix_asm_output_source_filename
237 #undef TARGET_CONDITIONAL_REGISTER_USAGE
238 #define TARGET_CONDITIONAL_REGISTER_USAGE mmix_conditional_register_usage
240 #undef TARGET_RTX_COSTS
241 #define TARGET_RTX_COSTS mmix_rtx_costs
242 #undef TARGET_ADDRESS_COST
243 #define TARGET_ADDRESS_COST hook_int_rtx_mode_as_bool_0
245 #undef TARGET_REGISTER_MOVE_COST
246 #define TARGET_REGISTER_MOVE_COST mmix_register_move_cost
248 #undef TARGET_MACHINE_DEPENDENT_REORG
249 #define TARGET_MACHINE_DEPENDENT_REORG mmix_reorg
251 #undef TARGET_PROMOTE_FUNCTION_MODE
252 #define TARGET_PROMOTE_FUNCTION_MODE mmix_promote_function_mode
254 #undef TARGET_FUNCTION_VALUE
255 #define TARGET_FUNCTION_VALUE mmix_function_value
256 #undef TARGET_LIBCALL_VALUE
257 #define TARGET_LIBCALL_VALUE mmix_libcall_value
258 #undef TARGET_FUNCTION_VALUE_REGNO_P
259 #define TARGET_FUNCTION_VALUE_REGNO_P mmix_function_value_regno_p
261 #undef TARGET_FUNCTION_ARG
262 #define TARGET_FUNCTION_ARG mmix_function_arg
263 #undef TARGET_FUNCTION_INCOMING_ARG
264 #define TARGET_FUNCTION_INCOMING_ARG mmix_function_incoming_arg
265 #undef TARGET_FUNCTION_ARG_ADVANCE
266 #define TARGET_FUNCTION_ARG_ADVANCE mmix_function_arg_advance
267 #undef TARGET_STRUCT_VALUE_RTX
268 #define TARGET_STRUCT_VALUE_RTX mmix_struct_value_rtx
269 #undef TARGET_SETUP_INCOMING_VARARGS
270 #define TARGET_SETUP_INCOMING_VARARGS mmix_setup_incoming_varargs
271 #undef TARGET_PASS_BY_REFERENCE
272 #define TARGET_PASS_BY_REFERENCE mmix_pass_by_reference
273 #undef TARGET_CALLEE_COPIES
274 #define TARGET_CALLEE_COPIES hook_bool_CUMULATIVE_ARGS_mode_tree_bool_true
276 #undef TARGET_PREFERRED_RELOAD_CLASS
277 #define TARGET_PREFERRED_RELOAD_CLASS mmix_preferred_reload_class
278 #undef TARGET_PREFERRED_OUTPUT_RELOAD_CLASS
279 #define TARGET_PREFERRED_OUTPUT_RELOAD_CLASS mmix_preferred_output_reload_class
281 #undef TARGET_LEGITIMATE_ADDRESS_P
282 #define TARGET_LEGITIMATE_ADDRESS_P mmix_legitimate_address_p
283 #undef TARGET_LEGITIMATE_CONSTANT_P
284 #define TARGET_LEGITIMATE_CONSTANT_P mmix_legitimate_constant_p
286 #undef TARGET_FRAME_POINTER_REQUIRED
287 #define TARGET_FRAME_POINTER_REQUIRED mmix_frame_pointer_required
289 #undef TARGET_ASM_TRAMPOLINE_TEMPLATE
290 #define TARGET_ASM_TRAMPOLINE_TEMPLATE mmix_asm_trampoline_template
291 #undef TARGET_TRAMPOLINE_INIT
292 #define TARGET_TRAMPOLINE_INIT mmix_trampoline_init
294 #undef TARGET_OPTION_OVERRIDE
295 #define TARGET_OPTION_OVERRIDE mmix_option_override
297 struct gcc_target targetm
= TARGET_INITIALIZER
;
299 /* Functions that are expansions for target macros.
300 See Target Macros in `Using and Porting GCC'. */
302 /* TARGET_OPTION_OVERRIDE. */
305 mmix_option_override (void)
307 /* Should we err or should we warn? Hmm. At least we must neutralize
308 it. For example the wrong kind of case-tables will be generated with
309 PIC; we use absolute address items for mmixal compatibility. FIXME:
310 They could be relative if we just elide them to after all pertinent
314 warning (0, "-f%s not supported: ignored", (flag_pic
> 1) ? "PIC" : "pic");
319 /* INIT_EXPANDERS. */
322 mmix_init_expanders (void)
324 init_machine_status
= mmix_init_machine_status
;
327 /* Set the per-function data. */
329 static struct machine_function
*
330 mmix_init_machine_status (void)
332 return ggc_cleared_alloc
<machine_function
> ();
335 /* DATA_ABI_ALIGNMENT.
336 We have trouble getting the address of stuff that is located at other
337 than 32-bit alignments (GETA requirements), so try to give everything
338 at least 32-bit alignment. */
341 mmix_data_alignment (tree type ATTRIBUTE_UNUSED
, int basic_align
)
343 if (basic_align
< 32)
349 /* CONSTANT_ALIGNMENT. */
352 mmix_constant_alignment (tree constant ATTRIBUTE_UNUSED
, int basic_align
)
354 if (basic_align
< 32)
360 /* LOCAL_ALIGNMENT. */
363 mmix_local_alignment (tree type ATTRIBUTE_UNUSED
, unsigned basic_align
)
365 if (basic_align
< 32)
371 /* TARGET_CONDITIONAL_REGISTER_USAGE. */
374 mmix_conditional_register_usage (void)
380 static const int gnu_abi_reg_alloc_order
[]
381 = MMIX_GNU_ABI_REG_ALLOC_ORDER
;
383 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
384 reg_alloc_order
[i
] = gnu_abi_reg_alloc_order
[i
];
386 /* Change the default from the mmixware ABI. For the GNU ABI,
387 $15..$30 are call-saved just as $0..$14. There must be one
388 call-clobbered local register for the "hole" that holds the
389 number of saved local registers saved by PUSHJ/PUSHGO during the
390 function call, receiving the return value at return. So best is
391 to use the highest, $31. It's already marked call-clobbered for
393 for (i
= 15; i
<= 30; i
++)
394 call_used_regs
[i
] = 0;
396 /* "Unfix" the parameter registers. */
397 for (i
= MMIX_RESERVED_GNU_ARG_0_REGNUM
;
398 i
< MMIX_RESERVED_GNU_ARG_0_REGNUM
+ MMIX_MAX_ARGS_IN_REGS
;
403 /* Step over the ":" in special register names. */
404 if (! TARGET_TOPLEVEL_SYMBOLS
)
405 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
406 if (reg_names
[i
][0] == ':')
410 /* INCOMING_REGNO and OUTGOING_REGNO worker function.
411 Those two macros must only be applied to function argument
412 registers and the function return value register for the opposite
413 use. FIXME: for their current use in gcc, it'd be better with an
414 explicit specific additional FUNCTION_INCOMING_ARG_REGNO_P a'la
415 TARGET_FUNCTION_ARG / TARGET_FUNCTION_INCOMING_ARG instead of
416 forcing the target to commit to a fixed mapping and for any
417 unspecified register use. Particularly when thinking about the
418 return-value, it is better to imagine INCOMING_REGNO and
419 OUTGOING_REGNO as named CALLEE_TO_CALLER_REGNO and INNER_REGNO as
420 named CALLER_TO_CALLEE_REGNO because the direction. The "incoming"
421 and "outgoing" is from the perspective of the parameter-registers,
422 but the same macro is (must be, lacking an alternative like
423 suggested above) used to map the return-value-register from the
424 same perspective. To make directions even more confusing, the macro
425 MMIX_OUTGOING_RETURN_VALUE_REGNUM holds the number of the register
426 in which to return a value, i.e. INCOMING_REGNO for the return-value-
427 register as received from a called function; the return-value on the
431 mmix_opposite_regno (int regno
, int incoming
)
433 if (incoming
&& regno
== MMIX_OUTGOING_RETURN_VALUE_REGNUM
)
434 return MMIX_RETURN_VALUE_REGNUM
;
436 if (!incoming
&& regno
== MMIX_RETURN_VALUE_REGNUM
)
437 return MMIX_OUTGOING_RETURN_VALUE_REGNUM
;
439 if (!mmix_function_arg_regno_p (regno
, incoming
))
444 ? MMIX_FIRST_INCOMING_ARG_REGNUM
- MMIX_FIRST_ARG_REGNUM
445 : MMIX_FIRST_ARG_REGNUM
- MMIX_FIRST_INCOMING_ARG_REGNUM
);
449 All registers that are part of the register stack and that will be
453 mmix_local_regno (int regno
)
455 return regno
<= MMIX_LAST_STACK_REGISTER_REGNUM
&& !call_used_regs
[regno
];
458 /* TARGET_PREFERRED_RELOAD_CLASS.
459 We need to extend the reload class of REMAINDER_REG and HIMULT_REG. */
462 mmix_preferred_reload_class (rtx x
, reg_class_t rclass
)
464 /* FIXME: Revisit. */
465 return GET_CODE (x
) == MOD
&& GET_MODE (x
) == DImode
466 ? REMAINDER_REG
: rclass
;
469 /* TARGET_PREFERRED_OUTPUT_RELOAD_CLASS.
470 We need to extend the reload class of REMAINDER_REG and HIMULT_REG. */
473 mmix_preferred_output_reload_class (rtx x
, reg_class_t rclass
)
475 /* FIXME: Revisit. */
476 return GET_CODE (x
) == MOD
&& GET_MODE (x
) == DImode
477 ? REMAINDER_REG
: rclass
;
480 /* SECONDARY_RELOAD_CLASS.
481 We need to reload regs of REMAINDER_REG and HIMULT_REG elsewhere. */
484 mmix_secondary_reload_class (enum reg_class rclass
,
485 machine_mode mode ATTRIBUTE_UNUSED
,
486 rtx x ATTRIBUTE_UNUSED
,
487 int in_p ATTRIBUTE_UNUSED
)
489 if (rclass
== REMAINDER_REG
490 || rclass
== HIMULT_REG
491 || rclass
== SYSTEM_REGS
)
497 /* DYNAMIC_CHAIN_ADDRESS. */
500 mmix_dynamic_chain_address (rtx frame
)
502 /* FIXME: the frame-pointer is stored at offset -8 from the current
503 frame-pointer. Unfortunately, the caller assumes that a
504 frame-pointer is present for *all* previous frames. There should be
505 a way to say that that cannot be done, like for RETURN_ADDR_RTX. */
506 return plus_constant (Pmode
, frame
, -8);
509 /* STARTING_FRAME_OFFSET. */
512 mmix_starting_frame_offset (void)
514 /* The old frame pointer is in the slot below the new one, so
515 FIRST_PARM_OFFSET does not need to depend on whether the
516 frame-pointer is needed or not. We have to adjust for the register
517 stack pointer being located below the saved frame pointer.
518 Similarly, we store the return address on the stack too, for
519 exception handling, and always if we save the register stack pointer. */
522 + (MMIX_CFUN_HAS_LANDING_PAD
523 ? -16 : (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
? -8 : 0)));
526 /* RETURN_ADDR_RTX. */
529 mmix_return_addr_rtx (int count
, rtx frame ATTRIBUTE_UNUSED
)
532 ? (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
533 /* FIXME: Set frame_alias_set on the following. (Why?)
534 See mmix_initial_elimination_offset for the reason we can't use
535 get_hard_reg_initial_val for both. Always using a stack slot
536 and not a register would be suboptimal. */
537 ? validize_mem (gen_rtx_MEM (Pmode
,
538 plus_constant (Pmode
,
539 frame_pointer_rtx
, -16)))
540 : get_hard_reg_initial_val (Pmode
, MMIX_INCOMING_RETURN_ADDRESS_REGNUM
))
544 /* SETUP_FRAME_ADDRESSES. */
547 mmix_setup_frame_addresses (void)
549 /* Nothing needed at the moment. */
552 /* The difference between the (imaginary) frame pointer and the stack
553 pointer. Used to eliminate the frame pointer. */
556 mmix_initial_elimination_offset (int fromreg
, int toreg
)
560 = (get_frame_size () + crtl
->outgoing_args_size
+ 7) & ~7;
562 /* There is no actual offset between these two virtual values, but for
563 the frame-pointer, we have the old one in the stack position below
564 it, so the offset for the frame-pointer to the stack-pointer is one
566 if (fromreg
== MMIX_ARG_POINTER_REGNUM
567 && toreg
== MMIX_FRAME_POINTER_REGNUM
)
570 /* The difference is the size of local variables plus the size of
571 outgoing function arguments that would normally be passed as
572 registers but must be passed on stack because we're out of
573 function-argument registers. Only global saved registers are
574 counted; the others go on the register stack.
576 The frame-pointer is counted too if it is what is eliminated, as we
577 need to balance the offset for it from STARTING_FRAME_OFFSET.
579 Also add in the slot for the register stack pointer we save if we
582 Unfortunately, we can't access $0..$14, from unwinder code easily, so
583 store the return address in a frame slot too. FIXME: Only for
584 non-leaf functions. FIXME: Always with a landing pad, because it's
585 hard to know whether we need the other at the time we know we need
586 the offset for one (and have to state it). It's a kludge until we
587 can express the register stack in the EH frame info.
589 We have to do alignment here; get_frame_size will not return a
590 multiple of STACK_BOUNDARY. FIXME: Add note in manual. */
592 for (regno
= MMIX_FIRST_GLOBAL_REGNUM
;
595 if ((df_regs_ever_live_p (regno
) && ! call_used_regs
[regno
])
596 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
600 + (MMIX_CFUN_HAS_LANDING_PAD
601 ? 16 : (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
? 8 : 0))
602 + (fromreg
== MMIX_ARG_POINTER_REGNUM
? 0 : 8);
606 mmix_function_arg_advance (cumulative_args_t argsp_v
, machine_mode mode
,
607 const_tree type
, bool named ATTRIBUTE_UNUSED
)
609 CUMULATIVE_ARGS
*argsp
= get_cumulative_args (argsp_v
);
610 int arg_size
= MMIX_FUNCTION_ARG_SIZE (mode
, type
);
612 argsp
->regs
= ((targetm
.calls
.must_pass_in_stack (mode
, type
)
616 ? (MMIX_MAX_ARGS_IN_REGS
) + 1
617 : argsp
->regs
+ (7 + arg_size
) / 8);
620 /* Helper function for mmix_function_arg and mmix_function_incoming_arg. */
623 mmix_function_arg_1 (const cumulative_args_t argsp_v
,
626 bool named ATTRIBUTE_UNUSED
,
629 CUMULATIVE_ARGS
*argsp
= get_cumulative_args (argsp_v
);
631 /* Last-argument marker. */
632 if (type
== void_type_node
)
633 return (argsp
->regs
< MMIX_MAX_ARGS_IN_REGS
)
636 ? MMIX_FIRST_INCOMING_ARG_REGNUM
637 : MMIX_FIRST_ARG_REGNUM
) + argsp
->regs
)
640 return (argsp
->regs
< MMIX_MAX_ARGS_IN_REGS
641 && !targetm
.calls
.must_pass_in_stack (mode
, type
)
642 && (GET_MODE_BITSIZE (mode
) <= 64
647 ? MMIX_FIRST_INCOMING_ARG_REGNUM
648 : MMIX_FIRST_ARG_REGNUM
)
653 /* Return an rtx for a function argument to go in a register, and 0 for
654 one that must go on stack. */
657 mmix_function_arg (cumulative_args_t argsp
,
662 return mmix_function_arg_1 (argsp
, mode
, type
, named
, false);
666 mmix_function_incoming_arg (cumulative_args_t argsp
,
671 return mmix_function_arg_1 (argsp
, mode
, type
, named
, true);
674 /* Returns nonzero for everything that goes by reference, 0 for
675 everything that goes by value. */
678 mmix_pass_by_reference (cumulative_args_t argsp_v
, machine_mode mode
,
679 const_tree type
, bool named ATTRIBUTE_UNUSED
)
681 CUMULATIVE_ARGS
*argsp
= get_cumulative_args (argsp_v
);
683 /* FIXME: Check: I'm not sure the must_pass_in_stack check is
685 if (targetm
.calls
.must_pass_in_stack (mode
, type
))
688 if (MMIX_FUNCTION_ARG_SIZE (mode
, type
) > 8
690 && (!argsp
|| !argsp
->lib
))
696 /* Return nonzero if regno is a register number where a parameter is
697 passed, and 0 otherwise. */
700 mmix_function_arg_regno_p (int regno
, int incoming
)
703 = incoming
? MMIX_FIRST_INCOMING_ARG_REGNUM
: MMIX_FIRST_ARG_REGNUM
;
705 return regno
>= first_arg_regnum
706 && regno
< first_arg_regnum
+ MMIX_MAX_ARGS_IN_REGS
;
709 /* Implements TARGET_FUNCTION_VALUE. */
712 mmix_function_value (const_tree valtype
,
713 const_tree func ATTRIBUTE_UNUSED
,
716 machine_mode mode
= TYPE_MODE (valtype
);
718 int first_val_regnum
= MMIX_OUTGOING_RETURN_VALUE_REGNUM
;
719 rtx vec
[MMIX_MAX_REGS_FOR_VALUE
];
724 return gen_rtx_REG (mode
, MMIX_RETURN_VALUE_REGNUM
);
726 /* Return values that fit in a register need no special handling.
727 There's no register hole when parameters are passed in global
730 || GET_MODE_BITSIZE (mode
) <= BITS_PER_WORD
)
732 gen_rtx_REG (mode
, MMIX_OUTGOING_RETURN_VALUE_REGNUM
);
734 if (COMPLEX_MODE_P (mode
))
735 /* A complex type, made up of components. */
736 cmode
= TYPE_MODE (TREE_TYPE (valtype
));
739 /* Of the other larger-than-register modes, we only support
740 scalar mode TImode. (At least, that's the only one that's
741 been rudimentally tested.) Make sure we're alerted for
744 sorry ("support for mode %qs", GET_MODE_NAME (mode
));
746 /* In any case, we will fill registers to the natural size. */
750 nregs
= ((GET_MODE_BITSIZE (mode
) + BITS_PER_WORD
- 1) / BITS_PER_WORD
);
752 /* We need to take care of the effect of the register hole on return
753 values of large sizes; the last register will appear as the first
754 register, with the rest shifted. (For complex modes, this is just
755 swapped registers.) */
757 if (nregs
> MMIX_MAX_REGS_FOR_VALUE
)
758 internal_error ("too large function value type, needs %d registers,\
759 have only %d registers for this", nregs
, MMIX_MAX_REGS_FOR_VALUE
);
761 /* FIXME: Maybe we should handle structure values like this too
762 (adjusted for BLKmode), perhaps for both ABI:s. */
763 for (i
= 0; i
< nregs
- 1; i
++)
765 = gen_rtx_EXPR_LIST (VOIDmode
,
766 gen_rtx_REG (cmode
, first_val_regnum
+ i
),
767 GEN_INT ((i
+ 1) * BITS_PER_UNIT
));
770 = gen_rtx_EXPR_LIST (VOIDmode
,
771 gen_rtx_REG (cmode
, first_val_regnum
+ nregs
- 1),
774 return gen_rtx_PARALLEL (mode
, gen_rtvec_v (nregs
, vec
));
777 /* Implements TARGET_LIBCALL_VALUE. */
780 mmix_libcall_value (machine_mode mode
,
781 const_rtx fun ATTRIBUTE_UNUSED
)
783 return gen_rtx_REG (mode
, MMIX_RETURN_VALUE_REGNUM
);
786 /* Implements TARGET_FUNCTION_VALUE_REGNO_P. */
789 mmix_function_value_regno_p (const unsigned int regno
)
791 return regno
== MMIX_RETURN_VALUE_REGNUM
;
794 /* EH_RETURN_DATA_REGNO. */
797 mmix_eh_return_data_regno (int n
)
800 return MMIX_EH_RETURN_DATA_REGNO_START
+ n
;
802 return INVALID_REGNUM
;
805 /* EH_RETURN_STACKADJ_RTX. */
808 mmix_eh_return_stackadj_rtx (void)
810 return gen_rtx_REG (Pmode
, MMIX_EH_RETURN_STACKADJ_REGNUM
);
813 /* EH_RETURN_HANDLER_RTX. */
816 mmix_eh_return_handler_rtx (void)
818 return gen_rtx_REG (Pmode
, MMIX_INCOMING_RETURN_ADDRESS_REGNUM
);
821 /* ASM_PREFERRED_EH_DATA_FORMAT. */
824 mmix_asm_preferred_eh_data_format (int code ATTRIBUTE_UNUSED
,
825 int global ATTRIBUTE_UNUSED
)
827 /* This is the default (was at 2001-07-20). Revisit when needed. */
828 return DW_EH_PE_absptr
;
831 /* Make a note that we've seen the beginning of the prologue. This
832 matters to whether we'll translate register numbers as calculated by
836 mmix_target_asm_function_prologue (FILE *stream ATTRIBUTE_UNUSED
,
837 HOST_WIDE_INT framesize ATTRIBUTE_UNUSED
)
839 cfun
->machine
->in_prologue
= 1;
842 /* Make a note that we've seen the end of the prologue. */
845 mmix_target_asm_function_end_prologue (FILE *stream ATTRIBUTE_UNUSED
)
847 cfun
->machine
->in_prologue
= 0;
850 /* Implement TARGET_MACHINE_DEPENDENT_REORG. No actual rearrangements
851 done here; just virtually by calculating the highest saved stack
852 register number used to modify the register numbers at output time. */
859 /* We put the number of the highest saved register-file register in a
860 location convenient for the call-patterns to output. Note that we
861 don't tell dwarf2 about these registers, since it can't restore them
863 for (regno
= MMIX_LAST_STACK_REGISTER_REGNUM
;
866 if ((df_regs_ever_live_p (regno
) && !call_used_regs
[regno
])
867 || (regno
== MMIX_FRAME_POINTER_REGNUM
&& frame_pointer_needed
))
870 /* Regardless of whether they're saved (they might be just read), we
871 mustn't include registers that carry parameters. We could scan the
872 insns to see whether they're actually used (and indeed do other less
873 trivial register usage analysis and transformations), but it seems
874 wasteful to optimize for unused parameter registers. As of
875 2002-04-30, df_regs_ever_live_p (n) seems to be set for only-reads too, but
876 that might change. */
877 if (!TARGET_ABI_GNU
&& regno
< crtl
->args
.info
.regs
- 1)
879 regno
= crtl
->args
.info
.regs
- 1;
881 /* We don't want to let this cause us to go over the limit and make
882 incoming parameter registers be misnumbered and treating the last
883 parameter register and incoming return value register call-saved.
884 Stop things at the unmodified scheme. */
885 if (regno
> MMIX_RETURN_VALUE_REGNUM
- 1)
886 regno
= MMIX_RETURN_VALUE_REGNUM
- 1;
889 cfun
->machine
->highest_saved_stack_register
= regno
;
892 /* TARGET_ASM_FUNCTION_EPILOGUE. */
895 mmix_target_asm_function_epilogue (FILE *stream
,
896 HOST_WIDE_INT locals_size ATTRIBUTE_UNUSED
)
898 /* Emit an \n for readability of the generated assembly. */
899 fputc ('\n', stream
);
902 /* TARGET_ASM_OUTPUT_MI_THUNK. */
905 mmix_asm_output_mi_thunk (FILE *stream
,
906 tree fndecl ATTRIBUTE_UNUSED
,
908 HOST_WIDE_INT vcall_offset ATTRIBUTE_UNUSED
,
911 /* If you define TARGET_STRUCT_VALUE_RTX that returns 0 (i.e. pass
912 location of structure to return as invisible first argument), you
913 need to tweak this code too. */
914 const char *regname
= reg_names
[MMIX_FIRST_INCOMING_ARG_REGNUM
];
916 if (delta
>= 0 && delta
< 65536)
917 fprintf (stream
, "\tINCL %s,%d\n", regname
, (int)delta
);
918 else if (delta
< 0 && delta
>= -255)
919 fprintf (stream
, "\tSUBU %s,%s,%d\n", regname
, regname
, (int)-delta
);
922 mmix_output_register_setting (stream
, 255, delta
, 1);
923 fprintf (stream
, "\tADDU %s,%s,$255\n", regname
, regname
);
926 fprintf (stream
, "\tJMP ");
927 assemble_name (stream
, XSTR (XEXP (DECL_RTL (func
), 0), 0));
928 fprintf (stream
, "\n");
931 /* FUNCTION_PROFILER. */
934 mmix_function_profiler (FILE *stream ATTRIBUTE_UNUSED
,
935 int labelno ATTRIBUTE_UNUSED
)
937 sorry ("function_profiler support for MMIX");
940 /* Worker function for TARGET_SETUP_INCOMING_VARARGS. For the moment,
941 let's stick to pushing argument registers on the stack. Later, we
942 can parse all arguments in registers, to improve performance. */
945 mmix_setup_incoming_varargs (cumulative_args_t args_so_farp_v
,
949 int second_time ATTRIBUTE_UNUSED
)
951 CUMULATIVE_ARGS
*args_so_farp
= get_cumulative_args (args_so_farp_v
);
953 /* The last named variable has been handled, but
954 args_so_farp has not been advanced for it. */
955 if (args_so_farp
->regs
+ 1 < MMIX_MAX_ARGS_IN_REGS
)
956 *pretend_sizep
= (MMIX_MAX_ARGS_IN_REGS
- (args_so_farp
->regs
+ 1)) * 8;
958 /* We assume that one argument takes up one register here. That should
959 be true until we start messing with multi-reg parameters. */
960 if ((7 + (MMIX_FUNCTION_ARG_SIZE (mode
, vartype
))) / 8 != 1)
961 internal_error ("MMIX Internal: Last named vararg would not fit in a register");
964 /* TARGET_ASM_TRAMPOLINE_TEMPLATE. */
967 mmix_asm_trampoline_template (FILE *stream
)
969 /* Read a value into the static-chain register and jump somewhere. The
970 static chain is stored at offset 16, and the function address is
971 stored at offset 24. */
973 fprintf (stream
, "\tGETA $255,1F\n\t");
974 fprintf (stream
, "LDOU %s,$255,0\n\t", reg_names
[MMIX_STATIC_CHAIN_REGNUM
]);
975 fprintf (stream
, "LDOU $255,$255,8\n\t");
976 fprintf (stream
, "GO $255,$255,0\n");
977 fprintf (stream
, "1H\tOCTA 0\n\t");
978 fprintf (stream
, "OCTA 0\n");
981 /* TARGET_TRAMPOLINE_INIT. */
982 /* Set the static chain and function pointer field in the trampoline.
983 We also SYNCID here to be sure (doesn't matter in the simulator, but
984 some day it will). */
987 mmix_trampoline_init (rtx m_tramp
, tree fndecl
, rtx static_chain
)
989 rtx fnaddr
= XEXP (DECL_RTL (fndecl
), 0);
992 emit_block_move (m_tramp
, assemble_trampoline_template (),
993 GEN_INT (2*UNITS_PER_WORD
), BLOCK_OP_NORMAL
);
995 mem
= adjust_address (m_tramp
, DImode
, 2*UNITS_PER_WORD
);
996 emit_move_insn (mem
, static_chain
);
997 mem
= adjust_address (m_tramp
, DImode
, 3*UNITS_PER_WORD
);
998 emit_move_insn (mem
, fnaddr
);
1000 mem
= adjust_address (m_tramp
, DImode
, 0);
1001 emit_insn (gen_sync_icache (mem
, GEN_INT (TRAMPOLINE_SIZE
- 1)));
1004 /* We must exclude constant addresses that have an increment that is not a
1005 multiple of four bytes because of restrictions of the GETA
1006 instruction, unless TARGET_BASE_ADDRESSES. */
1009 mmix_constant_address_p (rtx x
)
1011 RTX_CODE code
= GET_CODE (x
);
1013 /* When using "base addresses", anything constant goes. */
1014 int constant_ok
= TARGET_BASE_ADDRESSES
!= 0;
1023 /* FIXME: Don't know how to dissect these. Avoid them for now,
1024 except we know they're constants. */
1028 addend
= INTVAL (x
);
1032 if (GET_MODE (x
) != VOIDmode
)
1033 /* Strange that we got here. FIXME: Check if we do. */
1035 addend
= CONST_DOUBLE_LOW (x
);
1039 /* Note that expressions with arithmetic on forward references don't
1040 work in mmixal. People using gcc assembly code with mmixal might
1041 need to move arrays and such to before the point of use. */
1042 if (GET_CODE (XEXP (x
, 0)) == PLUS
)
1044 rtx x0
= XEXP (XEXP (x
, 0), 0);
1045 rtx x1
= XEXP (XEXP (x
, 0), 1);
1047 if ((GET_CODE (x0
) == SYMBOL_REF
1048 || GET_CODE (x0
) == LABEL_REF
)
1049 && (GET_CODE (x1
) == CONST_INT
1050 || (GET_CODE (x1
) == CONST_DOUBLE
1051 && GET_MODE (x1
) == VOIDmode
)))
1052 addend
= mmix_intval (x1
);
1064 return constant_ok
|| (addend
& 3) == 0;
1067 /* Return 1 if the address is OK, otherwise 0. */
1070 mmix_legitimate_address_p (machine_mode mode ATTRIBUTE_UNUSED
,
1072 bool strict_checking
)
1074 #define MMIX_REG_OK(X) \
1076 && (REGNO (X) <= MMIX_LAST_GENERAL_REGISTER \
1077 || (reg_renumber[REGNO (X)] > 0 \
1078 && reg_renumber[REGNO (X)] <= MMIX_LAST_GENERAL_REGISTER))) \
1079 || (!strict_checking \
1080 && (REGNO (X) <= MMIX_LAST_GENERAL_REGISTER \
1081 || REGNO (X) >= FIRST_PSEUDO_REGISTER \
1082 || REGNO (X) == ARG_POINTER_REGNUM)))
1086 (mem (plus reg reg))
1087 (mem (plus reg 0..255)).
1088 unless TARGET_BASE_ADDRESSES, in which case we accept all
1089 (mem constant_address) too. */
1093 if (REG_P (x
) && MMIX_REG_OK (x
))
1096 if (GET_CODE(x
) == PLUS
)
1098 rtx x1
= XEXP (x
, 0);
1099 rtx x2
= XEXP (x
, 1);
1101 /* Try swapping the order. FIXME: Do we need this? */
1109 /* (mem (plus (reg?) (?))) */
1110 if (!REG_P (x1
) || !MMIX_REG_OK (x1
))
1111 return TARGET_BASE_ADDRESSES
&& mmix_constant_address_p (x
);
1113 /* (mem (plus (reg) (reg?))) */
1114 if (REG_P (x2
) && MMIX_REG_OK (x2
))
1117 /* (mem (plus (reg) (0..255?))) */
1118 if (satisfies_constraint_I (x2
))
1124 return TARGET_BASE_ADDRESSES
&& mmix_constant_address_p (x
);
1127 /* Implement TARGET_LEGITIMATE_CONSTANT_P. */
1130 mmix_legitimate_constant_p (machine_mode mode ATTRIBUTE_UNUSED
, rtx x
)
1132 RTX_CODE code
= GET_CODE (x
);
1134 /* We must allow any number due to the way the cse passes works; if we
1135 do not allow any number here, general_operand will fail, and insns
1136 will fatally fail recognition instead of "softly". */
1137 if (code
== CONST_INT
|| code
== CONST_DOUBLE
)
1140 return CONSTANT_ADDRESS_P (x
);
1143 /* SELECT_CC_MODE. */
1146 mmix_select_cc_mode (RTX_CODE op
, rtx x
, rtx y ATTRIBUTE_UNUSED
)
1148 /* We use CCmode, CC_UNSmode, CC_FPmode, CC_FPEQmode and CC_FUNmode to
1149 output different compare insns. Note that we do not check the
1150 validity of the comparison here. */
1152 if (GET_MODE_CLASS (GET_MODE (x
)) == MODE_FLOAT
)
1154 if (op
== ORDERED
|| op
== UNORDERED
|| op
== UNGE
1155 || op
== UNGT
|| op
== UNLE
|| op
== UNLT
)
1158 if (op
== EQ
|| op
== NE
)
1164 if (op
== GTU
|| op
== LTU
|| op
== GEU
|| op
== LEU
)
1170 /* REVERSIBLE_CC_MODE. */
1173 mmix_reversible_cc_mode (machine_mode mode
)
1175 /* That is, all integer and the EQ, NE, ORDERED and UNORDERED float
1177 return mode
!= CC_FPmode
;
1180 /* TARGET_RTX_COSTS. */
1183 mmix_rtx_costs (rtx x ATTRIBUTE_UNUSED
,
1184 int code ATTRIBUTE_UNUSED
,
1185 int outer_code ATTRIBUTE_UNUSED
,
1186 int opno ATTRIBUTE_UNUSED
,
1187 int *total ATTRIBUTE_UNUSED
,
1188 bool speed ATTRIBUTE_UNUSED
)
1190 /* For the time being, this is just a stub and we'll accept the
1191 generic calculations, until we can do measurements, at least.
1192 Say we did not modify any calculated costs. */
1196 /* TARGET_REGISTER_MOVE_COST.
1198 The special registers can only move to and from general regs, and we
1199 need to check that their constraints match, so say 3 for them. */
1202 mmix_register_move_cost (machine_mode mode ATTRIBUTE_UNUSED
,
1206 return (from
== GENERAL_REGS
&& from
== to
) ? 2 : 3;
1209 /* Note that we don't have a TEXT_SECTION_ASM_OP, because it has to be a
1210 compile-time constant; it's used in an asm in crtstuff.c, compiled for
1213 /* DATA_SECTION_ASM_OP. */
1216 mmix_data_section_asm_op (void)
1218 return "\t.data ! mmixal:= 8H LOC 9B";
1222 mmix_encode_section_info (tree decl
, rtx rtl
, int first
)
1224 /* Test for an external declaration, and do nothing if it is one. */
1225 if ((TREE_CODE (decl
) == VAR_DECL
1226 && (DECL_EXTERNAL (decl
) || TREE_PUBLIC (decl
)))
1227 || (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_PUBLIC (decl
)))
1229 else if (first
&& DECL_P (decl
))
1231 /* For non-visible declarations, add a "@" prefix, which we skip
1232 when the label is output. If the label does not have this
1233 prefix, a ":" is output if -mtoplevel-symbols.
1235 Note that this does not work for data that is declared extern and
1236 later defined as static. If there's code in between, that code
1237 will refer to the extern declaration, and vice versa. This just
1238 means that when -mtoplevel-symbols is in use, we can just handle
1239 well-behaved ISO-compliant code. */
1241 const char *str
= XSTR (XEXP (rtl
, 0), 0);
1242 int len
= strlen (str
);
1243 char *newstr
= XALLOCAVEC (char, len
+ 2);
1245 strcpy (newstr
+ 1, str
);
1246 XSTR (XEXP (rtl
, 0), 0) = ggc_alloc_string (newstr
, len
+ 1);
1249 /* Set SYMBOL_REF_FLAG for things that we want to access with GETA. We
1250 may need different options to reach for different things with GETA.
1251 For now, functions and things we know or have been told are constant. */
1252 if (TREE_CODE (decl
) == FUNCTION_DECL
1253 || TREE_CONSTANT (decl
)
1254 || (TREE_CODE (decl
) == VAR_DECL
1255 && TREE_READONLY (decl
)
1256 && !TREE_SIDE_EFFECTS (decl
)
1257 && (!DECL_INITIAL (decl
)
1258 || TREE_CONSTANT (DECL_INITIAL (decl
)))))
1259 SYMBOL_REF_FLAG (XEXP (rtl
, 0)) = 1;
1263 mmix_strip_name_encoding (const char *name
)
1265 for (; (*name
== '@' || *name
== '*'); name
++)
1271 /* TARGET_ASM_FILE_START.
1272 We just emit a little comment for the time being. */
1275 mmix_file_start (void)
1277 default_file_start ();
1279 fputs ("! mmixal:= 8H LOC Data_Section\n", asm_out_file
);
1281 /* Make sure each file starts with the text section. */
1282 switch_to_section (text_section
);
1285 /* TARGET_ASM_FILE_END. */
1288 mmix_file_end (void)
1290 /* Make sure each file ends with the data section. */
1291 switch_to_section (data_section
);
1294 /* TARGET_ASM_OUTPUT_SOURCE_FILENAME. */
1297 mmix_asm_output_source_filename (FILE *stream
, const char *name
)
1299 fprintf (stream
, "# 1 ");
1300 OUTPUT_QUOTED_STRING (stream
, name
);
1301 fprintf (stream
, "\n");
1304 /* OUTPUT_QUOTED_STRING. */
1307 mmix_output_quoted_string (FILE *stream
, const char *string
, int length
)
1309 const char * string_end
= string
+ length
;
1310 static const char *const unwanted_chars
= "\"[]\\";
1312 /* Output "any character except newline and double quote character". We
1313 play it safe and avoid all control characters too. We also do not
1314 want [] as characters, should input be passed through m4 with [] as
1315 quotes. Further, we avoid "\", because the GAS port handles it as a
1316 quoting character. */
1317 while (string
< string_end
)
1320 && (unsigned char) *string
< 128
1321 && !ISCNTRL (*string
)
1322 && strchr (unwanted_chars
, *string
) == NULL
)
1324 fputc ('"', stream
);
1326 && (unsigned char) *string
< 128
1327 && !ISCNTRL (*string
)
1328 && strchr (unwanted_chars
, *string
) == NULL
1329 && string
< string_end
)
1331 fputc (*string
, stream
);
1334 fputc ('"', stream
);
1335 if (string
< string_end
)
1336 fprintf (stream
, ",");
1338 if (string
< string_end
)
1340 fprintf (stream
, "#%x", *string
& 255);
1342 if (string
< string_end
)
1343 fprintf (stream
, ",");
1348 /* Target hook for assembling integer objects. Use mmix_print_operand
1349 for WYDE and TETRA. Use mmix_output_octa to output 8-byte
1353 mmix_assemble_integer (rtx x
, unsigned int size
, int aligned_p
)
1358 /* We handle a limited number of types of operands in here. But
1359 that's ok, because we can punt to generic functions. We then
1360 pretend that aligned data isn't needed, so the usual .<pseudo>
1361 syntax is used (which works for aligned data too). We actually
1362 *must* do that, since we say we don't have simple aligned
1363 pseudos, causing this function to be called. We just try and
1364 keep as much compatibility as possible with mmixal syntax for
1365 normal cases (i.e. without GNU extensions and C only). */
1367 if (GET_CODE (x
) != CONST_INT
)
1372 fputs ("\tBYTE\t", asm_out_file
);
1373 mmix_print_operand (asm_out_file
, x
, 'B');
1374 fputc ('\n', asm_out_file
);
1378 if (GET_CODE (x
) != CONST_INT
)
1383 fputs ("\tWYDE\t", asm_out_file
);
1384 mmix_print_operand (asm_out_file
, x
, 'W');
1385 fputc ('\n', asm_out_file
);
1389 if (GET_CODE (x
) != CONST_INT
)
1394 fputs ("\tTETRA\t", asm_out_file
);
1395 mmix_print_operand (asm_out_file
, x
, 'L');
1396 fputc ('\n', asm_out_file
);
1400 /* We don't get here anymore for CONST_DOUBLE, because DImode
1401 isn't expressed as CONST_DOUBLE, and DFmode is handled
1403 gcc_assert (GET_CODE (x
) != CONST_DOUBLE
);
1404 assemble_integer_with_op ("\tOCTA\t", x
);
1407 return default_assemble_integer (x
, size
, aligned_p
);
1410 /* ASM_OUTPUT_ASCII. */
1413 mmix_asm_output_ascii (FILE *stream
, const char *string
, int length
)
1417 int chunk_size
= length
> 60 ? 60 : length
;
1418 fprintf (stream
, "\tBYTE ");
1419 mmix_output_quoted_string (stream
, string
, chunk_size
);
1420 string
+= chunk_size
;
1421 length
-= chunk_size
;
1422 fprintf (stream
, "\n");
1426 /* ASM_OUTPUT_ALIGNED_COMMON. */
1429 mmix_asm_output_aligned_common (FILE *stream
,
1434 /* This is mostly the elfos.h one. There doesn't seem to be a way to
1435 express this in a mmixal-compatible way. */
1436 fprintf (stream
, "\t.comm\t");
1437 assemble_name (stream
, name
);
1438 fprintf (stream
, ",%u,%u ! mmixal-incompatible COMMON\n",
1439 size
, align
/ BITS_PER_UNIT
);
1442 /* ASM_OUTPUT_ALIGNED_LOCAL. */
1445 mmix_asm_output_aligned_local (FILE *stream
,
1450 switch_to_section (data_section
);
1452 ASM_OUTPUT_ALIGN (stream
, exact_log2 (align
/BITS_PER_UNIT
));
1453 assemble_name (stream
, name
);
1454 fprintf (stream
, "\tLOC @+%d\n", size
);
1457 /* ASM_OUTPUT_LABEL. */
1460 mmix_asm_output_label (FILE *stream
, const char *name
)
1462 assemble_name (stream
, name
);
1463 fprintf (stream
, "\tIS @\n");
1466 /* ASM_OUTPUT_INTERNAL_LABEL. */
1469 mmix_asm_output_internal_label (FILE *stream
, const char *name
)
1471 assemble_name_raw (stream
, name
);
1472 fprintf (stream
, "\tIS @\n");
1475 /* ASM_DECLARE_REGISTER_GLOBAL. */
1478 mmix_asm_declare_register_global (FILE *stream ATTRIBUTE_UNUSED
,
1479 tree decl ATTRIBUTE_UNUSED
,
1480 int regno ATTRIBUTE_UNUSED
,
1481 const char *name ATTRIBUTE_UNUSED
)
1483 /* Nothing to do here, but there *will* be, therefore the framework is
1487 /* ASM_WEAKEN_LABEL. */
1490 mmix_asm_weaken_label (FILE *stream ATTRIBUTE_UNUSED
,
1491 const char *name ATTRIBUTE_UNUSED
)
1493 fprintf (stream
, "\t.weak ");
1494 assemble_name (stream
, name
);
1495 fprintf (stream
, " ! mmixal-incompatible\n");
1498 /* MAKE_DECL_ONE_ONLY. */
1501 mmix_make_decl_one_only (tree decl
)
1503 DECL_WEAK (decl
) = 1;
1506 /* ASM_OUTPUT_LABELREF.
1507 Strip GCC's '*' and our own '@'. No order is assumed. */
1510 mmix_asm_output_labelref (FILE *stream
, const char *name
)
1514 for (; (*name
== '@' || *name
== '*'); name
++)
1518 asm_fprintf (stream
, "%s%U%s",
1519 is_extern
&& TARGET_TOPLEVEL_SYMBOLS
? ":" : "",
1523 /* ASM_OUTPUT_DEF. */
1526 mmix_asm_output_def (FILE *stream
, const char *name
, const char *value
)
1528 assemble_name (stream
, name
);
1529 fprintf (stream
, "\tIS ");
1530 assemble_name (stream
, value
);
1531 fputc ('\n', stream
);
1534 /* TARGET_PRINT_OPERAND. */
1537 mmix_print_operand (FILE *stream
, rtx x
, int code
)
1539 /* When we add support for different codes later, we can, when needed,
1540 drop through to the main handler with a modified operand. */
1542 int regno
= x
!= NULL_RTX
&& REG_P (x
) ? REGNO (x
) : 0;
1546 /* Unrelated codes are in alphabetic order. */
1549 /* For conditional branches, output "P" for a probable branch. */
1550 if (TARGET_BRANCH_PREDICT
)
1552 x
= find_reg_note (current_output_insn
, REG_BR_PROB
, 0);
1553 if (x
&& XINT (x
, 0) > REG_BR_PROB_BASE
/ 2)
1559 /* For the %d in POP %d,0. */
1560 fprintf (stream
, "%d", MMIX_POP_ARGUMENT ());
1564 if (GET_CODE (x
) != CONST_INT
)
1565 fatal_insn ("MMIX Internal: Expected a CONST_INT, not this", x
);
1566 fprintf (stream
, "%d", (int) (INTVAL (x
) & 0xff));
1570 /* Highpart. Must be general register, and not the last one, as
1571 that one cannot be part of a consecutive register pair. */
1572 if (regno
> MMIX_LAST_GENERAL_REGISTER
- 1)
1573 internal_error ("MMIX Internal: Bad register: %d", regno
);
1575 /* This is big-endian, so the high-part is the first one. */
1576 fprintf (stream
, "%s", reg_names
[MMIX_OUTPUT_REGNO (regno
)]);
1580 /* Lowpart. Must be CONST_INT or general register, and not the last
1581 one, as that one cannot be part of a consecutive register pair. */
1582 if (GET_CODE (x
) == CONST_INT
)
1584 fprintf (stream
, "#%lx",
1585 (unsigned long) (INTVAL (x
)
1586 & ((unsigned int) 0x7fffffff * 2 + 1)));
1590 if (GET_CODE (x
) == SYMBOL_REF
)
1592 output_addr_const (stream
, x
);
1596 if (regno
> MMIX_LAST_GENERAL_REGISTER
- 1)
1597 internal_error ("MMIX Internal: Bad register: %d", regno
);
1599 /* This is big-endian, so the low-part is + 1. */
1600 fprintf (stream
, "%s", reg_names
[MMIX_OUTPUT_REGNO (regno
) + 1]);
1603 /* Can't use 'a' because that's a generic modifier for address
1606 mmix_output_shiftvalue_op_from_str (stream
, "ANDN",
1612 mmix_output_shiftvalue_op_from_str (stream
, "INC",
1618 mmix_output_shiftvalue_op_from_str (stream
, "OR",
1624 mmix_output_shiftvalue_op_from_str (stream
, "SET",
1631 mmix_output_condition (stream
, x
, (code
== 'D'));
1635 /* Output an extra "e" to make fcmpe, fune. */
1636 if (TARGET_FCMP_EPSILON
)
1637 fprintf (stream
, "e");
1641 /* Output the number minus 1. */
1642 if (GET_CODE (x
) != CONST_INT
)
1644 fatal_insn ("MMIX Internal: Bad value for 'm', not a CONST_INT",
1647 fprintf (stream
, "%" PRId64
,
1648 (int64_t) (mmix_intval (x
) - 1));
1652 /* Store the number of registers we want to save. This was setup
1653 by the prologue. The actual operand contains the number of
1654 registers to pass, but we don't use it currently. Anyway, we
1655 need to output the number of saved registers here. */
1656 fprintf (stream
, "%d",
1657 cfun
->machine
->highest_saved_stack_register
+ 1);
1661 /* Store the register to output a constant to. */
1663 fatal_insn ("MMIX Internal: Expected a register, not this", x
);
1664 mmix_output_destination_register
= MMIX_OUTPUT_REGNO (regno
);
1668 /* Output the constant. Note that we use this for floats as well. */
1669 if (GET_CODE (x
) != CONST_INT
1670 && (GET_CODE (x
) != CONST_DOUBLE
1671 || (GET_MODE (x
) != VOIDmode
&& GET_MODE (x
) != DFmode
1672 && GET_MODE (x
) != SFmode
)))
1673 fatal_insn ("MMIX Internal: Expected a constant, not this", x
);
1674 mmix_output_register_setting (stream
,
1675 mmix_output_destination_register
,
1676 mmix_intval (x
), 0);
1680 /* An U for unsigned, if TARGET_ZERO_EXTEND. Ignore the operand. */
1681 if (TARGET_ZERO_EXTEND
)
1686 mmix_output_shifted_value (stream
, (int64_t) mmix_intval (x
));
1690 mmix_output_shifted_value (stream
, (int64_t) ~mmix_intval (x
));
1694 if (GET_CODE (x
) != CONST_INT
)
1695 fatal_insn ("MMIX Internal: Expected a CONST_INT, not this", x
);
1696 fprintf (stream
, "#%x", (int) (INTVAL (x
) & 0xffff));
1700 /* Nothing to do. */
1704 /* Presumably there's a missing case above if we get here. */
1705 internal_error ("MMIX Internal: Missing %qc case in mmix_print_operand", code
);
1708 switch (GET_CODE (modified_x
))
1711 regno
= REGNO (modified_x
);
1712 if (regno
>= FIRST_PSEUDO_REGISTER
)
1713 internal_error ("MMIX Internal: Bad register: %d", regno
);
1714 fprintf (stream
, "%s", reg_names
[MMIX_OUTPUT_REGNO (regno
)]);
1718 output_address (XEXP (modified_x
, 0));
1722 /* For -2147483648, mmixal complains that the constant does not fit
1723 in 4 bytes, so let's output it as hex. Take care to handle hosts
1724 where HOST_WIDE_INT is longer than an int.
1726 Print small constants +-255 using decimal. */
1728 if (INTVAL (modified_x
) > -256 && INTVAL (modified_x
) < 256)
1729 fprintf (stream
, "%d", (int) (INTVAL (modified_x
)));
1731 fprintf (stream
, "#%x",
1732 (int) (INTVAL (modified_x
)) & (unsigned int) ~0);
1736 /* Do somewhat as CONST_INT. */
1737 mmix_output_octa (stream
, mmix_intval (modified_x
), 0);
1741 output_addr_const (stream
, modified_x
);
1745 /* No need to test for all strange things. Let output_addr_const do
1747 if (CONSTANT_P (modified_x
)
1748 /* Strangely enough, this is not included in CONSTANT_P.
1749 FIXME: Ask/check about sanity here. */
1750 || LABEL_P (modified_x
))
1752 output_addr_const (stream
, modified_x
);
1756 /* We need the original here. */
1757 fatal_insn ("MMIX Internal: Cannot decode this operand", x
);
1761 /* TARGET_PRINT_OPERAND_PUNCT_VALID_P. */
1764 mmix_print_operand_punct_valid_p (unsigned char code
)
1766 /* A '+' is used for branch prediction, similar to other ports. */
1768 /* A '.' is used for the %d in the POP %d,0 return insn. */
1772 /* TARGET_PRINT_OPERAND_ADDRESS. */
1775 mmix_print_operand_address (FILE *stream
, rtx x
)
1779 /* I find the generated assembly code harder to read without
1781 fprintf (stream
, "%s,0", reg_names
[MMIX_OUTPUT_REGNO (REGNO (x
))]);
1784 else if (GET_CODE (x
) == PLUS
)
1786 rtx x1
= XEXP (x
, 0);
1787 rtx x2
= XEXP (x
, 1);
1791 fprintf (stream
, "%s,", reg_names
[MMIX_OUTPUT_REGNO (REGNO (x1
))]);
1795 fprintf (stream
, "%s",
1796 reg_names
[MMIX_OUTPUT_REGNO (REGNO (x2
))]);
1799 else if (satisfies_constraint_I (x2
))
1801 output_addr_const (stream
, x2
);
1807 if (TARGET_BASE_ADDRESSES
&& mmix_legitimate_constant_p (Pmode
, x
))
1809 output_addr_const (stream
, x
);
1813 fatal_insn ("MMIX Internal: This is not a recognized address", x
);
1816 /* ASM_OUTPUT_REG_PUSH. */
1819 mmix_asm_output_reg_push (FILE *stream
, int regno
)
1821 fprintf (stream
, "\tSUBU %s,%s,8\n\tSTOU %s,%s,0\n",
1822 reg_names
[MMIX_STACK_POINTER_REGNUM
],
1823 reg_names
[MMIX_STACK_POINTER_REGNUM
],
1824 reg_names
[MMIX_OUTPUT_REGNO (regno
)],
1825 reg_names
[MMIX_STACK_POINTER_REGNUM
]);
1828 /* ASM_OUTPUT_REG_POP. */
1831 mmix_asm_output_reg_pop (FILE *stream
, int regno
)
1833 fprintf (stream
, "\tLDOU %s,%s,0\n\tINCL %s,8\n",
1834 reg_names
[MMIX_OUTPUT_REGNO (regno
)],
1835 reg_names
[MMIX_STACK_POINTER_REGNUM
],
1836 reg_names
[MMIX_STACK_POINTER_REGNUM
]);
1839 /* ASM_OUTPUT_ADDR_DIFF_ELT. */
1842 mmix_asm_output_addr_diff_elt (FILE *stream
,
1843 rtx body ATTRIBUTE_UNUSED
,
1847 fprintf (stream
, "\tTETRA L%d-L%d\n", value
, rel
);
1850 /* ASM_OUTPUT_ADDR_VEC_ELT. */
1853 mmix_asm_output_addr_vec_elt (FILE *stream
, int value
)
1855 fprintf (stream
, "\tOCTA L:%d\n", value
);
1858 /* ASM_OUTPUT_SKIP. */
1861 mmix_asm_output_skip (FILE *stream
, int nbytes
)
1863 fprintf (stream
, "\tLOC @+%d\n", nbytes
);
1866 /* ASM_OUTPUT_ALIGN. */
1869 mmix_asm_output_align (FILE *stream
, int power
)
1871 /* We need to record the needed alignment of this section in the object,
1872 so we have to output an alignment directive. Use a .p2align (not
1873 .align) so people will never have to wonder about whether the
1874 argument is in number of bytes or the log2 thereof. We do it in
1875 addition to the LOC directive, so nothing needs tweaking when
1876 copy-pasting assembly into mmixal. */
1877 fprintf (stream
, "\t.p2align %d\n", power
);
1878 fprintf (stream
, "\tLOC @+(%d-@)&%d\n", 1 << power
, (1 << power
) - 1);
1881 /* DBX_REGISTER_NUMBER. */
1884 mmix_dbx_register_number (unsigned regno
)
1886 /* Adjust the register number to the one it will be output as, dammit.
1887 It'd be nice if we could check the assumption that we're filling a
1888 gap, but every register between the last saved register and parameter
1889 registers might be a valid parameter register. */
1890 regno
= MMIX_OUTPUT_REGNO (regno
);
1892 /* We need to renumber registers to get the number of the return address
1893 register in the range 0..255. It is also space-saving if registers
1894 mentioned in the call-frame information (which uses this function by
1895 defaulting DWARF_FRAME_REGNUM to DBX_REGISTER_NUMBER) are numbered
1896 0 .. 63. So map 224 .. 256+15 -> 0 .. 47 and 0 .. 223 -> 48..223+48. */
1897 return regno
>= 224 ? (regno
- 224) : (regno
+ 48);
1900 /* End of target macro support functions.
1902 Now the MMIX port's own functions. First the exported ones. */
1904 /* Wrapper for get_hard_reg_initial_val since integrate.h isn't included
1905 from insn-emit.c. */
1908 mmix_get_hard_reg_initial_val (machine_mode mode
, int regno
)
1910 return get_hard_reg_initial_val (mode
, regno
);
1913 /* Nonzero when the function epilogue is simple enough that a single
1914 "POP %d,0" should be used even within the function. */
1917 mmix_use_simple_return (void)
1921 int stack_space_to_allocate
1922 = (crtl
->outgoing_args_size
1923 + crtl
->args
.pretend_args_size
1924 + get_frame_size () + 7) & ~7;
1926 if (!TARGET_USE_RETURN_INSN
|| !reload_completed
)
1930 regno
>= MMIX_FIRST_GLOBAL_REGNUM
;
1932 /* Note that we assume that the frame-pointer-register is one of these
1933 registers, in which case we don't count it here. */
1934 if ((((regno
!= MMIX_FRAME_POINTER_REGNUM
|| !frame_pointer_needed
)
1935 && df_regs_ever_live_p (regno
) && !call_used_regs
[regno
]))
1936 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
1939 if (frame_pointer_needed
)
1940 stack_space_to_allocate
+= 8;
1942 if (MMIX_CFUN_HAS_LANDING_PAD
)
1943 stack_space_to_allocate
+= 16;
1944 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
)
1945 stack_space_to_allocate
+= 8;
1947 return stack_space_to_allocate
== 0;
1951 /* Expands the function prologue into RTX. */
1954 mmix_expand_prologue (void)
1956 HOST_WIDE_INT locals_size
= get_frame_size ();
1958 HOST_WIDE_INT stack_space_to_allocate
1959 = (crtl
->outgoing_args_size
1960 + crtl
->args
.pretend_args_size
1961 + locals_size
+ 7) & ~7;
1962 HOST_WIDE_INT offset
= -8;
1964 /* Add room needed to save global non-register-stack registers. */
1966 regno
>= MMIX_FIRST_GLOBAL_REGNUM
;
1968 /* Note that we assume that the frame-pointer-register is one of these
1969 registers, in which case we don't count it here. */
1970 if ((((regno
!= MMIX_FRAME_POINTER_REGNUM
|| !frame_pointer_needed
)
1971 && df_regs_ever_live_p (regno
) && !call_used_regs
[regno
]))
1972 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
1973 stack_space_to_allocate
+= 8;
1975 /* If we do have a frame-pointer, add room for it. */
1976 if (frame_pointer_needed
)
1977 stack_space_to_allocate
+= 8;
1979 /* If we have a non-local label, we need to be able to unwind to it, so
1980 store the current register stack pointer. Also store the return
1981 address if we do that. */
1982 if (MMIX_CFUN_HAS_LANDING_PAD
)
1983 stack_space_to_allocate
+= 16;
1984 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
)
1985 /* If we do have a saved return-address slot, add room for it. */
1986 stack_space_to_allocate
+= 8;
1988 /* Make sure we don't get an unaligned stack. */
1989 if ((stack_space_to_allocate
% 8) != 0)
1990 internal_error ("stack frame not a multiple of 8 bytes: %wd",
1991 stack_space_to_allocate
);
1993 if (crtl
->args
.pretend_args_size
)
1995 int mmix_first_vararg_reg
1996 = (MMIX_FIRST_INCOMING_ARG_REGNUM
1997 + (MMIX_MAX_ARGS_IN_REGS
1998 - crtl
->args
.pretend_args_size
/ 8));
2001 = MMIX_FIRST_INCOMING_ARG_REGNUM
+ MMIX_MAX_ARGS_IN_REGS
- 1;
2002 regno
>= mmix_first_vararg_reg
;
2007 HOST_WIDE_INT stack_chunk
2008 = stack_space_to_allocate
> (256 - 8)
2009 ? (256 - 8) : stack_space_to_allocate
;
2011 mmix_emit_sp_add (-stack_chunk
);
2012 offset
+= stack_chunk
;
2013 stack_space_to_allocate
-= stack_chunk
;
2016 /* These registers aren't actually saved (as in "will be
2017 restored"), so don't tell DWARF2 they're saved. */
2018 emit_move_insn (gen_rtx_MEM (DImode
,
2019 plus_constant (Pmode
, stack_pointer_rtx
,
2021 gen_rtx_REG (DImode
, regno
));
2026 /* Store the frame-pointer. */
2028 if (frame_pointer_needed
)
2034 /* Get 8 less than otherwise, since we need to reach offset + 8. */
2035 HOST_WIDE_INT stack_chunk
2036 = stack_space_to_allocate
> (256 - 8 - 8)
2037 ? (256 - 8 - 8) : stack_space_to_allocate
;
2039 mmix_emit_sp_add (-stack_chunk
);
2041 offset
+= stack_chunk
;
2042 stack_space_to_allocate
-= stack_chunk
;
2045 insn
= emit_move_insn (gen_rtx_MEM (DImode
,
2046 plus_constant (Pmode
,
2049 hard_frame_pointer_rtx
);
2050 RTX_FRAME_RELATED_P (insn
) = 1;
2051 insn
= emit_insn (gen_adddi3 (hard_frame_pointer_rtx
,
2053 GEN_INT (offset
+ 8)));
2054 RTX_FRAME_RELATED_P (insn
) = 1;
2058 if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
)
2063 /* Store the return-address, if one is needed on the stack. We
2064 usually store it in a register when needed, but that doesn't work
2065 with -fexceptions. */
2069 /* Get 8 less than otherwise, since we need to reach offset + 8. */
2070 HOST_WIDE_INT stack_chunk
2071 = stack_space_to_allocate
> (256 - 8 - 8)
2072 ? (256 - 8 - 8) : stack_space_to_allocate
;
2074 mmix_emit_sp_add (-stack_chunk
);
2076 offset
+= stack_chunk
;
2077 stack_space_to_allocate
-= stack_chunk
;
2080 tmpreg
= gen_rtx_REG (DImode
, 255);
2081 retreg
= gen_rtx_REG (DImode
, MMIX_rJ_REGNUM
);
2083 /* Dwarf2 code is confused by the use of a temporary register for
2084 storing the return address, so we have to express it as a note,
2085 which we attach to the actual store insn. */
2086 emit_move_insn (tmpreg
, retreg
);
2088 insn
= emit_move_insn (gen_rtx_MEM (DImode
,
2089 plus_constant (Pmode
,
2093 RTX_FRAME_RELATED_P (insn
) = 1;
2094 add_reg_note (insn
, REG_FRAME_RELATED_EXPR
,
2095 gen_rtx_SET (gen_rtx_MEM (DImode
,
2096 plus_constant (Pmode
,
2103 else if (MMIX_CFUN_HAS_LANDING_PAD
)
2106 if (MMIX_CFUN_HAS_LANDING_PAD
)
2108 /* Store the register defining the numbering of local registers, so
2109 we know how long to unwind the register stack. */
2113 /* Get 8 less than otherwise, since we need to reach offset + 8. */
2114 HOST_WIDE_INT stack_chunk
2115 = stack_space_to_allocate
> (256 - 8 - 8)
2116 ? (256 - 8 - 8) : stack_space_to_allocate
;
2118 mmix_emit_sp_add (-stack_chunk
);
2120 offset
+= stack_chunk
;
2121 stack_space_to_allocate
-= stack_chunk
;
2124 /* We don't tell dwarf2 about this one; we just have it to unwind
2125 the register stack at landing pads. FIXME: It's a kludge because
2126 we can't describe the effect of the PUSHJ and PUSHGO insns on the
2127 register stack at the moment. Best thing would be to handle it
2128 like stack-pointer offsets. Better: some hook into dwarf2out.c
2129 to produce DW_CFA_expression:s that specify the increment of rO,
2130 and unwind it at eh_return (preferred) or at the landing pad.
2131 Then saves to $0..$G-1 could be specified through that register. */
2133 emit_move_insn (gen_rtx_REG (DImode
, 255),
2134 gen_rtx_REG (DImode
,
2136 emit_move_insn (gen_rtx_MEM (DImode
,
2137 plus_constant (Pmode
, stack_pointer_rtx
,
2139 gen_rtx_REG (DImode
, 255));
2143 /* After the return-address and the frame-pointer, we have the local
2144 variables. They're the ones that may have an "unaligned" size. */
2145 offset
-= (locals_size
+ 7) & ~7;
2147 /* Now store all registers that are global, i.e. not saved by the
2148 register file machinery.
2150 It is assumed that the frame-pointer is one of these registers, so it
2151 is explicitly excluded in the count. */
2154 regno
>= MMIX_FIRST_GLOBAL_REGNUM
;
2156 if (((regno
!= MMIX_FRAME_POINTER_REGNUM
|| !frame_pointer_needed
)
2157 && df_regs_ever_live_p (regno
) && ! call_used_regs
[regno
])
2158 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
2164 HOST_WIDE_INT stack_chunk
2165 = (stack_space_to_allocate
> (256 - offset
- 8)
2166 ? (256 - offset
- 8) : stack_space_to_allocate
);
2168 mmix_emit_sp_add (-stack_chunk
);
2169 offset
+= stack_chunk
;
2170 stack_space_to_allocate
-= stack_chunk
;
2173 insn
= emit_move_insn (gen_rtx_MEM (DImode
,
2174 plus_constant (Pmode
,
2177 gen_rtx_REG (DImode
, regno
));
2178 RTX_FRAME_RELATED_P (insn
) = 1;
2182 /* Finally, allocate room for outgoing args and local vars if room
2183 wasn't allocated above. */
2184 if (stack_space_to_allocate
)
2185 mmix_emit_sp_add (-stack_space_to_allocate
);
2188 /* Expands the function epilogue into RTX. */
2191 mmix_expand_epilogue (void)
2193 HOST_WIDE_INT locals_size
= get_frame_size ();
2195 HOST_WIDE_INT stack_space_to_deallocate
2196 = (crtl
->outgoing_args_size
2197 + crtl
->args
.pretend_args_size
2198 + locals_size
+ 7) & ~7;
2200 /* The first address to access is beyond the outgoing_args area. */
2201 HOST_WIDE_INT offset
= crtl
->outgoing_args_size
;
2203 /* Add the space for global non-register-stack registers.
2204 It is assumed that the frame-pointer register can be one of these
2205 registers, in which case it is excluded from the count when needed. */
2207 regno
>= MMIX_FIRST_GLOBAL_REGNUM
;
2209 if (((regno
!= MMIX_FRAME_POINTER_REGNUM
|| !frame_pointer_needed
)
2210 && df_regs_ever_live_p (regno
) && !call_used_regs
[regno
])
2211 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
2212 stack_space_to_deallocate
+= 8;
2214 /* Add in the space for register stack-pointer. If so, always add room
2215 for the saved PC. */
2216 if (MMIX_CFUN_HAS_LANDING_PAD
)
2217 stack_space_to_deallocate
+= 16;
2218 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
)
2219 /* If we have a saved return-address slot, add it in. */
2220 stack_space_to_deallocate
+= 8;
2222 /* Add in the frame-pointer. */
2223 if (frame_pointer_needed
)
2224 stack_space_to_deallocate
+= 8;
2226 /* Make sure we don't get an unaligned stack. */
2227 if ((stack_space_to_deallocate
% 8) != 0)
2228 internal_error ("stack frame not a multiple of octabyte: %wd",
2229 stack_space_to_deallocate
);
2231 /* We will add back small offsets to the stack pointer as we go.
2232 First, we restore all registers that are global, i.e. not saved by
2233 the register file machinery. */
2235 for (regno
= MMIX_FIRST_GLOBAL_REGNUM
;
2238 if (((regno
!= MMIX_FRAME_POINTER_REGNUM
|| !frame_pointer_needed
)
2239 && df_regs_ever_live_p (regno
) && !call_used_regs
[regno
])
2240 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
2244 mmix_emit_sp_add (offset
);
2245 stack_space_to_deallocate
-= offset
;
2249 emit_move_insn (gen_rtx_REG (DImode
, regno
),
2250 gen_rtx_MEM (DImode
,
2251 plus_constant (Pmode
, stack_pointer_rtx
,
2256 /* Here is where the local variables were. As in the prologue, they
2257 might be of an unaligned size. */
2258 offset
+= (locals_size
+ 7) & ~7;
2260 /* The saved register stack pointer is just below the frame-pointer
2261 register. We don't need to restore it "manually"; the POP
2262 instruction does that. */
2263 if (MMIX_CFUN_HAS_LANDING_PAD
)
2265 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
)
2266 /* The return-address slot is just below the frame-pointer register.
2267 We don't need to restore it because we don't really use it. */
2270 /* Get back the old frame-pointer-value. */
2271 if (frame_pointer_needed
)
2275 mmix_emit_sp_add (offset
);
2277 stack_space_to_deallocate
-= offset
;
2281 emit_move_insn (hard_frame_pointer_rtx
,
2282 gen_rtx_MEM (DImode
,
2283 plus_constant (Pmode
, stack_pointer_rtx
,
2288 /* We do not need to restore pretended incoming args, just add back
2290 if (stack_space_to_deallocate
!= 0)
2291 mmix_emit_sp_add (stack_space_to_deallocate
);
2293 if (crtl
->calls_eh_return
)
2294 /* Adjust the (normal) stack-pointer to that of the receiver.
2295 FIXME: It would be nice if we could also adjust the register stack
2296 here, but we need to express it through DWARF 2 too. */
2297 emit_insn (gen_adddi3 (stack_pointer_rtx
, stack_pointer_rtx
,
2298 gen_rtx_REG (DImode
,
2299 MMIX_EH_RETURN_STACKADJ_REGNUM
)));
2302 /* Output an optimal sequence for setting a register to a specific
2303 constant. Used in an alternative for const_ints in movdi, and when
2304 using large stack-frame offsets.
2306 Use do_begin_end to say if a line-starting TAB and newline before the
2307 first insn and after the last insn is wanted. */
2310 mmix_output_register_setting (FILE *stream
,
2316 fprintf (stream
, "\t");
2318 if (insn_const_int_ok_for_constraint (value
, CONSTRAINT_K
))
2319 fprintf (stream
, "NEGU %s,0,%" PRId64
, reg_names
[regno
], -value
);
2320 else if (mmix_shiftable_wyde_value ((uint64_t) value
))
2322 /* First, the one-insn cases. */
2323 mmix_output_shiftvalue_op_from_str (stream
, "SET",
2326 fprintf (stream
, " %s,", reg_names
[regno
]);
2327 mmix_output_shifted_value (stream
, (uint64_t) value
);
2329 else if (mmix_shiftable_wyde_value (-(uint64_t) value
))
2331 /* We do this to get a bit more legible assembly code. The next
2332 alternative is mostly redundant with this. */
2334 mmix_output_shiftvalue_op_from_str (stream
, "SET",
2337 fprintf (stream
, " %s,", reg_names
[regno
]);
2338 mmix_output_shifted_value (stream
, -(uint64_t) value
);
2339 fprintf (stream
, "\n\tNEGU %s,0,%s", reg_names
[regno
],
2342 else if (mmix_shiftable_wyde_value (~(uint64_t) value
))
2344 /* Slightly more expensive, the two-insn cases. */
2346 /* FIXME: We could of course also test if 0..255-N or ~(N | 1..255)
2347 is shiftable, or any other one-insn transformation of the value.
2348 FIXME: Check first if the value is "shiftable" by two loading
2349 with two insns, since it makes more readable assembly code (if
2350 anyone else cares). */
2352 mmix_output_shiftvalue_op_from_str (stream
, "SET",
2355 fprintf (stream
, " %s,", reg_names
[regno
]);
2356 mmix_output_shifted_value (stream
, ~(uint64_t) value
);
2357 fprintf (stream
, "\n\tNOR %s,%s,0", reg_names
[regno
],
2362 /* The generic case. 2..4 insns. */
2363 static const char *const higher_parts
[] = {"L", "ML", "MH", "H"};
2364 const char *op
= "SET";
2365 const char *line_begin
= "";
2368 int64_t tmpvalue
= value
;
2370 /* Compute the number of insns needed to output this constant. */
2371 for (i
= 0; i
< 4 && tmpvalue
!= 0; i
++)
2373 if (tmpvalue
& 65535)
2377 if (TARGET_BASE_ADDRESSES
&& insns
== 3)
2379 /* The number three is based on a static observation on
2380 ghostscript-6.52. Two and four are excluded because there
2381 are too many such constants, and each unique constant (maybe
2382 offset by 1..255) were used few times compared to other uses,
2385 We use base-plus-offset addressing to force it into a global
2386 register; we just use a "LDA reg,VALUE", which will cause the
2387 assembler and linker to DTRT (for constants as well as
2389 fprintf (stream
, "LDA %s,", reg_names
[regno
]);
2390 mmix_output_octa (stream
, value
, 0);
2394 /* Output pertinent parts of the 4-wyde sequence.
2395 Still more to do if we want this to be optimal, but hey...
2396 Note that the zero case has been handled above. */
2397 for (i
= 0; i
< 4 && value
!= 0; i
++)
2401 fprintf (stream
, "%s%s%s %s,#%x", line_begin
, op
,
2402 higher_parts
[i
], reg_names
[regno
],
2403 (int) (value
& 65535));
2404 /* The first one sets the rest of the bits to 0, the next
2405 ones add set bits. */
2407 line_begin
= "\n\t";
2416 fprintf (stream
, "\n");
2419 /* Return 1 if value is 0..65535*2**(16*N) for N=0..3.
2423 mmix_shiftable_wyde_value (uint64_t value
)
2425 /* Shift by 16 bits per group, stop when we've found two groups with
2428 int has_candidate
= 0;
2430 for (i
= 0; i
< 4; i
++)
2446 /* X and Y are two things to compare using CODE. Return the rtx for
2447 the cc-reg in the proper mode. */
2450 mmix_gen_compare_reg (RTX_CODE code
, rtx x
, rtx y
)
2452 machine_mode ccmode
= SELECT_CC_MODE (code
, x
, y
);
2453 return gen_reg_rtx (ccmode
);
2456 /* Local (static) helper functions. */
2459 mmix_emit_sp_add (HOST_WIDE_INT offset
)
2465 /* Negative stack-pointer adjustments are allocations and appear in
2466 the prologue only. We mark them as frame-related so unwind and
2467 debug info is properly emitted for them. */
2469 insn
= emit_insn (gen_adddi3 (stack_pointer_rtx
,
2474 rtx tmpr
= gen_rtx_REG (DImode
, 255);
2475 RTX_FRAME_RELATED_P (emit_move_insn (tmpr
, GEN_INT (offset
))) = 1;
2476 insn
= emit_insn (gen_adddi3 (stack_pointer_rtx
,
2477 stack_pointer_rtx
, tmpr
));
2479 RTX_FRAME_RELATED_P (insn
) = 1;
2483 /* Positive adjustments are in the epilogue only. Don't mark them
2484 as "frame-related" for unwind info. */
2485 if (insn_const_int_ok_for_constraint (offset
, CONSTRAINT_L
))
2486 emit_insn (gen_adddi3 (stack_pointer_rtx
,
2491 rtx tmpr
= gen_rtx_REG (DImode
, 255);
2492 emit_move_insn (tmpr
, GEN_INT (offset
));
2493 insn
= emit_insn (gen_adddi3 (stack_pointer_rtx
,
2494 stack_pointer_rtx
, tmpr
));
2499 /* Print operator suitable for doing something with a shiftable
2500 wyde. The type of operator is passed as an asm output modifier. */
2503 mmix_output_shiftvalue_op_from_str (FILE *stream
,
2507 static const char *const op_part
[] = {"L", "ML", "MH", "H"};
2510 if (! mmix_shiftable_wyde_value (value
))
2512 char s
[sizeof ("0xffffffffffffffff")];
2513 sprintf (s
, "%#" PRIx64
, value
);
2514 internal_error ("MMIX Internal: %s is not a shiftable int", s
);
2517 for (i
= 0; i
< 4; i
++)
2519 /* We know we're through when we find one-bits in the low
2523 fprintf (stream
, "%s%s", mainop
, op_part
[i
]);
2529 /* No bits set? Then it must have been zero. */
2530 fprintf (stream
, "%sL", mainop
);
2533 /* Print a 64-bit value, optionally prefixed by assembly pseudo. */
2536 mmix_output_octa (FILE *stream
, int64_t value
, int do_begin_end
)
2539 fprintf (stream
, "\tOCTA ");
2541 /* Provide a few alternative output formats depending on the number, to
2542 improve legibility of assembler output. */
2543 if ((value
< (int64_t) 0 && value
> (int64_t) -10000)
2544 || (value
>= (int64_t) 0 && value
<= (int64_t) 16384))
2545 fprintf (stream
, "%d", (int) value
);
2546 else if (value
> (int64_t) 0
2547 && value
< ((int64_t) 1 << 31) * 2)
2548 fprintf (stream
, "#%x", (unsigned int) value
);
2549 else if (sizeof (HOST_WIDE_INT
) == sizeof (int64_t))
2550 /* We need to avoid the not-so-universal "0x" prefix; we need the
2551 pure hex-digits together with the mmixal "#" hex prefix. */
2552 fprintf (stream
, "#" HOST_WIDE_INT_PRINT_HEX_PURE
,
2553 (HOST_WIDE_INT
) value
);
2554 else /* Need to avoid the hex output; there's no ...WIDEST...HEX_PURE. */
2555 fprintf (stream
, "%" PRIu64
, value
);
2558 fprintf (stream
, "\n");
2561 /* Print the presumed shiftable wyde argument shifted into place (to
2562 be output with an operand). */
2565 mmix_output_shifted_value (FILE *stream
, int64_t value
)
2569 if (! mmix_shiftable_wyde_value (value
))
2572 sprintf (s
, "%#" PRIx64
, value
);
2573 internal_error ("MMIX Internal: %s is not a shiftable int", s
);
2576 for (i
= 0; i
< 4; i
++)
2578 /* We know we're through when we find one-bits in the low 16 bits. */
2581 fprintf (stream
, "#%x", (int) (value
& 0xffff));
2588 /* No bits set? Then it must have been zero. */
2589 fprintf (stream
, "0");
2592 /* Output an MMIX condition name corresponding to an operator
2594 (comparison_operator [(comparison_operator ...) (const_int 0)])
2595 which means we have to look at *two* operators.
2597 The argument "reversed" refers to reversal of the condition (not the
2598 same as swapping the arguments). */
2601 mmix_output_condition (FILE *stream
, const_rtx x
, int reversed
)
2607 /* The normal output cc-code. */
2608 const char *const normal
;
2610 /* The reversed cc-code, or NULL if invalid. */
2611 const char *const reversed
;
2616 machine_mode cc_mode
;
2618 /* Terminated with {UNKNOWN, NULL, NULL} */
2619 const struct cc_conv
*const convs
;
2623 #define CCEND {UNKNOWN, NULL, NULL}
2625 static const struct cc_conv cc_fun_convs
[]
2626 = {{ORDERED
, "Z", "P"},
2627 {UNORDERED
, "P", "Z"},
2629 static const struct cc_conv cc_fp_convs
[]
2633 static const struct cc_conv cc_fpeq_convs
[]
2637 static const struct cc_conv cc_uns_convs
[]
2638 = {{GEU
, "NN", "N"},
2643 static const struct cc_conv cc_signed_convs
[]
2651 static const struct cc_conv cc_di_convs
[]
2663 static const struct cc_type_conv cc_convs
[]
2664 = {{CC_FUNmode
, cc_fun_convs
},
2665 {CC_FPmode
, cc_fp_convs
},
2666 {CC_FPEQmode
, cc_fpeq_convs
},
2667 {CC_UNSmode
, cc_uns_convs
},
2668 {CCmode
, cc_signed_convs
},
2669 {DImode
, cc_di_convs
}};
2674 machine_mode mode
= GET_MODE (XEXP (x
, 0));
2675 RTX_CODE cc
= GET_CODE (x
);
2677 for (i
= 0; i
< ARRAY_SIZE (cc_convs
); i
++)
2679 if (mode
== cc_convs
[i
].cc_mode
)
2681 for (j
= 0; cc_convs
[i
].convs
[j
].cc
!= UNKNOWN
; j
++)
2682 if (cc
== cc_convs
[i
].convs
[j
].cc
)
2685 = (reversed
? cc_convs
[i
].convs
[j
].reversed
2686 : cc_convs
[i
].convs
[j
].normal
);
2688 if (mmix_cc
== NULL
)
2689 fatal_insn ("MMIX Internal: Trying to output invalidly\
2690 reversed condition:", x
);
2692 fprintf (stream
, "%s", mmix_cc
);
2696 fatal_insn ("MMIX Internal: What's the CC of this?", x
);
2700 fatal_insn ("MMIX Internal: What is the CC of this?", x
);
2703 /* Return the bit-value for a const_int or const_double. */
2706 mmix_intval (const_rtx x
)
2708 if (GET_CODE (x
) == CONST_INT
)
2711 /* We make a little song and dance because converting to long long in
2712 gcc-2.7.2 is broken. I still want people to be able to use it for
2713 cross-compilation to MMIX. */
2714 if (GET_CODE (x
) == CONST_DOUBLE
&& GET_MODE (x
) == VOIDmode
)
2715 return CONST_DOUBLE_HIGH (x
);
2717 if (GET_CODE (x
) == CONST_DOUBLE
)
2719 REAL_VALUE_TYPE value
;
2721 /* FIXME: This macro is not in the manual but should be. */
2722 REAL_VALUE_FROM_CONST_DOUBLE (value
, x
);
2724 if (GET_MODE (x
) == DFmode
)
2728 REAL_VALUE_TO_TARGET_DOUBLE (value
, bits
);
2730 /* The double cast is necessary to avoid getting the long
2731 sign-extended to unsigned long long(!) when they're of
2732 different size (usually 32-bit hosts). */
2734 ((uint64_t) (unsigned long) bits
[0]
2736 | (uint64_t) (unsigned long) bits
[1];
2738 else if (GET_MODE (x
) == SFmode
)
2741 REAL_VALUE_TO_TARGET_SINGLE (value
, bits
);
2743 return (unsigned long) bits
;
2747 fatal_insn ("MMIX Internal: This is not a constant:", x
);
2750 /* Worker function for TARGET_PROMOTE_FUNCTION_MODE. */
2753 mmix_promote_function_mode (const_tree type ATTRIBUTE_UNUSED
,
2755 int *punsignedp ATTRIBUTE_UNUSED
,
2756 const_tree fntype ATTRIBUTE_UNUSED
,
2759 /* Apparently not doing TRT if int < register-size. FIXME: Perhaps
2760 FUNCTION_VALUE and LIBCALL_VALUE needs tweaking as some ports say. */
2761 if (for_return
== 1)
2764 /* Promotion of modes currently generates slow code, extending before
2765 operation, so we do it only for arguments. */
2766 if (GET_MODE_CLASS (mode
) == MODE_INT
2767 && GET_MODE_SIZE (mode
) < 8)
2772 /* Worker function for TARGET_STRUCT_VALUE_RTX. */
2775 mmix_struct_value_rtx (tree fntype ATTRIBUTE_UNUSED
,
2776 int incoming ATTRIBUTE_UNUSED
)
2778 return gen_rtx_REG (Pmode
, MMIX_STRUCT_VALUE_REGNUM
);
2781 /* Worker function for TARGET_FRAME_POINTER_REQUIRED.
2783 FIXME: Is this requirement built-in? Anyway, we should try to get rid
2784 of it; we can deduce the value. */
2787 mmix_frame_pointer_required (void)
2789 return (cfun
->has_nonlocal_label
);
2794 * eval: (c-set-style "gnu")
2795 * indent-tabs-mode: t