1 /* Definitions of target machine for GNU compiler, for MMIX.
2 Copyright (C) 2000-2016 Free Software Foundation, Inc.
3 Contributed by Hans-Peter Nilsson (hp@bitrange.com)
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
23 #include "coretypes.h"
30 #include "insn-config.h"
34 #include "diagnostic-core.h"
37 #include "stor-layout.h"
42 #include "tm-constrs.h"
45 /* This file should be included last. */
46 #include "target-def.h"
48 /* First some local helper definitions. */
49 #define MMIX_FIRST_GLOBAL_REGNUM 32
51 /* We'd need a current_function_has_landing_pad. It's marked as such when
52 a nonlocal_goto_receiver is expanded. Not just a C++ thing, but
54 #define MMIX_CFUN_HAS_LANDING_PAD (cfun->machine->has_landing_pad != 0)
56 /* We have no means to tell DWARF 2 about the register stack, so we need
57 to store the return address on the stack if an exception can get into
58 this function. FIXME: Narrow condition. Before any whole-function
59 analysis, df_regs_ever_live_p () isn't initialized. We know it's up-to-date
60 after reload_completed; it may contain incorrect information some time
61 before that. Within a RTL sequence (after a call to start_sequence,
62 such as in RTL expanders), leaf_function_p doesn't see all insns
63 (perhaps any insn). But regs_ever_live is up-to-date when
64 leaf_function_p () isn't, so we "or" them together to get accurate
65 information. FIXME: Some tweak to leaf_function_p might be
67 #define MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS \
69 && ((reload_completed && df_regs_ever_live_p (MMIX_rJ_REGNUM)) \
70 || !leaf_function_p ()))
72 #define IS_MMIX_EH_RETURN_DATA_REG(REGNO) \
73 (crtl->calls_eh_return \
74 && (EH_RETURN_DATA_REGNO (0) == REGNO \
75 || EH_RETURN_DATA_REGNO (1) == REGNO \
76 || EH_RETURN_DATA_REGNO (2) == REGNO \
77 || EH_RETURN_DATA_REGNO (3) == REGNO))
79 /* For the default ABI, we rename registers at output-time to fill the gap
80 between the (statically partitioned) saved registers and call-clobbered
81 registers. In effect this makes unused call-saved registers to be used
82 as call-clobbered registers. The benefit comes from keeping the number
83 of local registers (value of rL) low, since there's a cost of
84 increasing rL and clearing unused (unset) registers with lower numbers.
85 Don't translate while outputting the prologue. */
86 #define MMIX_OUTPUT_REGNO(N) \
88 || (int) (N) < MMIX_RETURN_VALUE_REGNUM \
89 || (int) (N) > MMIX_LAST_STACK_REGISTER_REGNUM \
91 || cfun->machine == NULL \
92 || cfun->machine->in_prologue \
93 ? (N) : ((N) - MMIX_RETURN_VALUE_REGNUM \
94 + cfun->machine->highest_saved_stack_register + 1))
96 /* The %d in "POP %d,0". */
97 #define MMIX_POP_ARGUMENT() \
99 && crtl->return_rtx != NULL \
100 && ! cfun->returns_struct) \
101 ? (GET_CODE (crtl->return_rtx) == PARALLEL \
102 ? GET_NUM_ELEM (XVEC (crtl->return_rtx, 0)) : 1) \
105 /* The canonical saved comparison operands for non-cc0 machines, set in
106 the compare expander. */
107 rtx mmix_compare_op0
;
108 rtx mmix_compare_op1
;
110 /* Declarations of locals. */
112 /* Intermediate for insn output. */
113 static int mmix_output_destination_register
;
115 static void mmix_option_override (void);
116 static void mmix_asm_output_source_filename (FILE *, const char *);
117 static void mmix_output_shiftvalue_op_from_str
118 (FILE *, const char *, int64_t);
119 static void mmix_output_shifted_value (FILE *, int64_t);
120 static void mmix_output_condition (FILE *, const_rtx
, int);
121 static void mmix_output_octa (FILE *, int64_t, int);
122 static bool mmix_assemble_integer (rtx
, unsigned int, int);
123 static struct machine_function
*mmix_init_machine_status (void);
124 static void mmix_encode_section_info (tree
, rtx
, int);
125 static const char *mmix_strip_name_encoding (const char *);
126 static void mmix_emit_sp_add (HOST_WIDE_INT offset
);
127 static void mmix_target_asm_function_prologue (FILE *, HOST_WIDE_INT
);
128 static void mmix_target_asm_function_end_prologue (FILE *);
129 static void mmix_target_asm_function_epilogue (FILE *, HOST_WIDE_INT
);
130 static reg_class_t
mmix_preferred_reload_class (rtx
, reg_class_t
);
131 static reg_class_t
mmix_preferred_output_reload_class (rtx
, reg_class_t
);
132 static bool mmix_legitimate_address_p (machine_mode
, rtx
, bool);
133 static bool mmix_legitimate_constant_p (machine_mode
, rtx
);
134 static void mmix_reorg (void);
135 static void mmix_asm_output_mi_thunk
136 (FILE *, tree
, HOST_WIDE_INT
, HOST_WIDE_INT
, tree
);
137 static void mmix_setup_incoming_varargs
138 (cumulative_args_t
, machine_mode
, tree
, int *, int);
139 static void mmix_file_start (void);
140 static void mmix_file_end (void);
141 static bool mmix_rtx_costs (rtx
, machine_mode
, int, int, int *, bool);
142 static int mmix_register_move_cost (machine_mode
,
143 reg_class_t
, reg_class_t
);
144 static rtx
mmix_struct_value_rtx (tree
, int);
145 static machine_mode
mmix_promote_function_mode (const_tree
,
147 int *, const_tree
, int);
148 static void mmix_function_arg_advance (cumulative_args_t
, machine_mode
,
150 static rtx
mmix_function_arg_1 (const cumulative_args_t
, machine_mode
,
151 const_tree
, bool, bool);
152 static rtx
mmix_function_incoming_arg (cumulative_args_t
, machine_mode
,
154 static rtx
mmix_function_arg (cumulative_args_t
, machine_mode
,
156 static rtx
mmix_function_value (const_tree
, const_tree
, bool);
157 static rtx
mmix_libcall_value (machine_mode
, const_rtx
);
158 static bool mmix_function_value_regno_p (const unsigned int);
159 static bool mmix_pass_by_reference (cumulative_args_t
,
160 machine_mode
, const_tree
, bool);
161 static bool mmix_frame_pointer_required (void);
162 static void mmix_asm_trampoline_template (FILE *);
163 static void mmix_trampoline_init (rtx
, tree
, rtx
);
164 static void mmix_print_operand (FILE *, rtx
, int);
165 static void mmix_print_operand_address (FILE *, machine_mode
, rtx
);
166 static bool mmix_print_operand_punct_valid_p (unsigned char);
167 static void mmix_conditional_register_usage (void);
169 /* Target structure macros. Listed by node. See `Using and Porting GCC'
170 for a general description. */
172 /* Node: Function Entry */
174 #undef TARGET_ASM_BYTE_OP
175 #define TARGET_ASM_BYTE_OP NULL
176 #undef TARGET_ASM_ALIGNED_HI_OP
177 #define TARGET_ASM_ALIGNED_HI_OP NULL
178 #undef TARGET_ASM_ALIGNED_SI_OP
179 #define TARGET_ASM_ALIGNED_SI_OP NULL
180 #undef TARGET_ASM_ALIGNED_DI_OP
181 #define TARGET_ASM_ALIGNED_DI_OP NULL
182 #undef TARGET_ASM_INTEGER
183 #define TARGET_ASM_INTEGER mmix_assemble_integer
185 #undef TARGET_ASM_FUNCTION_PROLOGUE
186 #define TARGET_ASM_FUNCTION_PROLOGUE mmix_target_asm_function_prologue
188 #undef TARGET_ASM_FUNCTION_END_PROLOGUE
189 #define TARGET_ASM_FUNCTION_END_PROLOGUE mmix_target_asm_function_end_prologue
191 #undef TARGET_ASM_FUNCTION_EPILOGUE
192 #define TARGET_ASM_FUNCTION_EPILOGUE mmix_target_asm_function_epilogue
194 #undef TARGET_PRINT_OPERAND
195 #define TARGET_PRINT_OPERAND mmix_print_operand
196 #undef TARGET_PRINT_OPERAND_ADDRESS
197 #define TARGET_PRINT_OPERAND_ADDRESS mmix_print_operand_address
198 #undef TARGET_PRINT_OPERAND_PUNCT_VALID_P
199 #define TARGET_PRINT_OPERAND_PUNCT_VALID_P mmix_print_operand_punct_valid_p
201 #undef TARGET_ENCODE_SECTION_INFO
202 #define TARGET_ENCODE_SECTION_INFO mmix_encode_section_info
203 #undef TARGET_STRIP_NAME_ENCODING
204 #define TARGET_STRIP_NAME_ENCODING mmix_strip_name_encoding
206 #undef TARGET_ASM_OUTPUT_MI_THUNK
207 #define TARGET_ASM_OUTPUT_MI_THUNK mmix_asm_output_mi_thunk
208 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
209 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall
210 #undef TARGET_ASM_FILE_START
211 #define TARGET_ASM_FILE_START mmix_file_start
212 #undef TARGET_ASM_FILE_START_FILE_DIRECTIVE
213 #define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
214 #undef TARGET_ASM_FILE_END
215 #define TARGET_ASM_FILE_END mmix_file_end
216 #undef TARGET_ASM_OUTPUT_SOURCE_FILENAME
217 #define TARGET_ASM_OUTPUT_SOURCE_FILENAME mmix_asm_output_source_filename
219 #undef TARGET_CONDITIONAL_REGISTER_USAGE
220 #define TARGET_CONDITIONAL_REGISTER_USAGE mmix_conditional_register_usage
222 #undef TARGET_RTX_COSTS
223 #define TARGET_RTX_COSTS mmix_rtx_costs
224 #undef TARGET_ADDRESS_COST
225 #define TARGET_ADDRESS_COST hook_int_rtx_mode_as_bool_0
227 #undef TARGET_REGISTER_MOVE_COST
228 #define TARGET_REGISTER_MOVE_COST mmix_register_move_cost
230 #undef TARGET_MACHINE_DEPENDENT_REORG
231 #define TARGET_MACHINE_DEPENDENT_REORG mmix_reorg
233 #undef TARGET_PROMOTE_FUNCTION_MODE
234 #define TARGET_PROMOTE_FUNCTION_MODE mmix_promote_function_mode
236 #undef TARGET_FUNCTION_VALUE
237 #define TARGET_FUNCTION_VALUE mmix_function_value
238 #undef TARGET_LIBCALL_VALUE
239 #define TARGET_LIBCALL_VALUE mmix_libcall_value
240 #undef TARGET_FUNCTION_VALUE_REGNO_P
241 #define TARGET_FUNCTION_VALUE_REGNO_P mmix_function_value_regno_p
243 #undef TARGET_FUNCTION_ARG
244 #define TARGET_FUNCTION_ARG mmix_function_arg
245 #undef TARGET_FUNCTION_INCOMING_ARG
246 #define TARGET_FUNCTION_INCOMING_ARG mmix_function_incoming_arg
247 #undef TARGET_FUNCTION_ARG_ADVANCE
248 #define TARGET_FUNCTION_ARG_ADVANCE mmix_function_arg_advance
249 #undef TARGET_STRUCT_VALUE_RTX
250 #define TARGET_STRUCT_VALUE_RTX mmix_struct_value_rtx
251 #undef TARGET_SETUP_INCOMING_VARARGS
252 #define TARGET_SETUP_INCOMING_VARARGS mmix_setup_incoming_varargs
253 #undef TARGET_PASS_BY_REFERENCE
254 #define TARGET_PASS_BY_REFERENCE mmix_pass_by_reference
255 #undef TARGET_CALLEE_COPIES
256 #define TARGET_CALLEE_COPIES hook_bool_CUMULATIVE_ARGS_mode_tree_bool_true
258 #undef TARGET_PREFERRED_RELOAD_CLASS
259 #define TARGET_PREFERRED_RELOAD_CLASS mmix_preferred_reload_class
260 #undef TARGET_PREFERRED_OUTPUT_RELOAD_CLASS
261 #define TARGET_PREFERRED_OUTPUT_RELOAD_CLASS mmix_preferred_output_reload_class
263 #undef TARGET_LEGITIMATE_ADDRESS_P
264 #define TARGET_LEGITIMATE_ADDRESS_P mmix_legitimate_address_p
265 #undef TARGET_LEGITIMATE_CONSTANT_P
266 #define TARGET_LEGITIMATE_CONSTANT_P mmix_legitimate_constant_p
268 #undef TARGET_FRAME_POINTER_REQUIRED
269 #define TARGET_FRAME_POINTER_REQUIRED mmix_frame_pointer_required
271 #undef TARGET_ASM_TRAMPOLINE_TEMPLATE
272 #define TARGET_ASM_TRAMPOLINE_TEMPLATE mmix_asm_trampoline_template
273 #undef TARGET_TRAMPOLINE_INIT
274 #define TARGET_TRAMPOLINE_INIT mmix_trampoline_init
276 #undef TARGET_OPTION_OVERRIDE
277 #define TARGET_OPTION_OVERRIDE mmix_option_override
279 struct gcc_target targetm
= TARGET_INITIALIZER
;
281 /* Functions that are expansions for target macros.
282 See Target Macros in `Using and Porting GCC'. */
284 /* TARGET_OPTION_OVERRIDE. */
287 mmix_option_override (void)
289 /* Should we err or should we warn? Hmm. At least we must neutralize
290 it. For example the wrong kind of case-tables will be generated with
291 PIC; we use absolute address items for mmixal compatibility. FIXME:
292 They could be relative if we just elide them to after all pertinent
296 warning (0, "-f%s not supported: ignored", (flag_pic
> 1) ? "PIC" : "pic");
301 /* INIT_EXPANDERS. */
304 mmix_init_expanders (void)
306 init_machine_status
= mmix_init_machine_status
;
309 /* Set the per-function data. */
311 static struct machine_function
*
312 mmix_init_machine_status (void)
314 return ggc_cleared_alloc
<machine_function
> ();
317 /* DATA_ABI_ALIGNMENT.
318 We have trouble getting the address of stuff that is located at other
319 than 32-bit alignments (GETA requirements), so try to give everything
320 at least 32-bit alignment. */
323 mmix_data_alignment (tree type ATTRIBUTE_UNUSED
, int basic_align
)
325 if (basic_align
< 32)
331 /* CONSTANT_ALIGNMENT. */
334 mmix_constant_alignment (tree constant ATTRIBUTE_UNUSED
, int basic_align
)
336 if (basic_align
< 32)
342 /* LOCAL_ALIGNMENT. */
345 mmix_local_alignment (tree type ATTRIBUTE_UNUSED
, unsigned basic_align
)
347 if (basic_align
< 32)
353 /* TARGET_CONDITIONAL_REGISTER_USAGE. */
356 mmix_conditional_register_usage (void)
362 static const int gnu_abi_reg_alloc_order
[]
363 = MMIX_GNU_ABI_REG_ALLOC_ORDER
;
365 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
366 reg_alloc_order
[i
] = gnu_abi_reg_alloc_order
[i
];
368 /* Change the default from the mmixware ABI. For the GNU ABI,
369 $15..$30 are call-saved just as $0..$14. There must be one
370 call-clobbered local register for the "hole" that holds the
371 number of saved local registers saved by PUSHJ/PUSHGO during the
372 function call, receiving the return value at return. So best is
373 to use the highest, $31. It's already marked call-clobbered for
375 for (i
= 15; i
<= 30; i
++)
376 call_used_regs
[i
] = 0;
378 /* "Unfix" the parameter registers. */
379 for (i
= MMIX_RESERVED_GNU_ARG_0_REGNUM
;
380 i
< MMIX_RESERVED_GNU_ARG_0_REGNUM
+ MMIX_MAX_ARGS_IN_REGS
;
385 /* Step over the ":" in special register names. */
386 if (! TARGET_TOPLEVEL_SYMBOLS
)
387 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
388 if (reg_names
[i
][0] == ':')
392 /* INCOMING_REGNO and OUTGOING_REGNO worker function.
393 Those two macros must only be applied to function argument
394 registers and the function return value register for the opposite
395 use. FIXME: for their current use in gcc, it'd be better with an
396 explicit specific additional FUNCTION_INCOMING_ARG_REGNO_P a'la
397 TARGET_FUNCTION_ARG / TARGET_FUNCTION_INCOMING_ARG instead of
398 forcing the target to commit to a fixed mapping and for any
399 unspecified register use. Particularly when thinking about the
400 return-value, it is better to imagine INCOMING_REGNO and
401 OUTGOING_REGNO as named CALLEE_TO_CALLER_REGNO and INNER_REGNO as
402 named CALLER_TO_CALLEE_REGNO because the direction. The "incoming"
403 and "outgoing" is from the perspective of the parameter-registers,
404 but the same macro is (must be, lacking an alternative like
405 suggested above) used to map the return-value-register from the
406 same perspective. To make directions even more confusing, the macro
407 MMIX_OUTGOING_RETURN_VALUE_REGNUM holds the number of the register
408 in which to return a value, i.e. INCOMING_REGNO for the return-value-
409 register as received from a called function; the return-value on the
413 mmix_opposite_regno (int regno
, int incoming
)
415 if (incoming
&& regno
== MMIX_OUTGOING_RETURN_VALUE_REGNUM
)
416 return MMIX_RETURN_VALUE_REGNUM
;
418 if (!incoming
&& regno
== MMIX_RETURN_VALUE_REGNUM
)
419 return MMIX_OUTGOING_RETURN_VALUE_REGNUM
;
421 if (!mmix_function_arg_regno_p (regno
, incoming
))
426 ? MMIX_FIRST_INCOMING_ARG_REGNUM
- MMIX_FIRST_ARG_REGNUM
427 : MMIX_FIRST_ARG_REGNUM
- MMIX_FIRST_INCOMING_ARG_REGNUM
);
431 All registers that are part of the register stack and that will be
435 mmix_local_regno (int regno
)
437 return regno
<= MMIX_LAST_STACK_REGISTER_REGNUM
&& !call_used_regs
[regno
];
440 /* TARGET_PREFERRED_RELOAD_CLASS.
441 We need to extend the reload class of REMAINDER_REG and HIMULT_REG. */
444 mmix_preferred_reload_class (rtx x
, reg_class_t rclass
)
446 /* FIXME: Revisit. */
447 return GET_CODE (x
) == MOD
&& GET_MODE (x
) == DImode
448 ? REMAINDER_REG
: rclass
;
451 /* TARGET_PREFERRED_OUTPUT_RELOAD_CLASS.
452 We need to extend the reload class of REMAINDER_REG and HIMULT_REG. */
455 mmix_preferred_output_reload_class (rtx x
, reg_class_t rclass
)
457 /* FIXME: Revisit. */
458 return GET_CODE (x
) == MOD
&& GET_MODE (x
) == DImode
459 ? REMAINDER_REG
: rclass
;
462 /* SECONDARY_RELOAD_CLASS.
463 We need to reload regs of REMAINDER_REG and HIMULT_REG elsewhere. */
466 mmix_secondary_reload_class (enum reg_class rclass
,
467 machine_mode mode ATTRIBUTE_UNUSED
,
468 rtx x ATTRIBUTE_UNUSED
,
469 int in_p ATTRIBUTE_UNUSED
)
471 if (rclass
== REMAINDER_REG
472 || rclass
== HIMULT_REG
473 || rclass
== SYSTEM_REGS
)
479 /* DYNAMIC_CHAIN_ADDRESS. */
482 mmix_dynamic_chain_address (rtx frame
)
484 /* FIXME: the frame-pointer is stored at offset -8 from the current
485 frame-pointer. Unfortunately, the caller assumes that a
486 frame-pointer is present for *all* previous frames. There should be
487 a way to say that that cannot be done, like for RETURN_ADDR_RTX. */
488 return plus_constant (Pmode
, frame
, -8);
491 /* STARTING_FRAME_OFFSET. */
494 mmix_starting_frame_offset (void)
496 /* The old frame pointer is in the slot below the new one, so
497 FIRST_PARM_OFFSET does not need to depend on whether the
498 frame-pointer is needed or not. We have to adjust for the register
499 stack pointer being located below the saved frame pointer.
500 Similarly, we store the return address on the stack too, for
501 exception handling, and always if we save the register stack pointer. */
504 + (MMIX_CFUN_HAS_LANDING_PAD
505 ? -16 : (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
? -8 : 0)));
508 /* RETURN_ADDR_RTX. */
511 mmix_return_addr_rtx (int count
, rtx frame ATTRIBUTE_UNUSED
)
514 ? (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
515 /* FIXME: Set frame_alias_set on the following. (Why?)
516 See mmix_initial_elimination_offset for the reason we can't use
517 get_hard_reg_initial_val for both. Always using a stack slot
518 and not a register would be suboptimal. */
519 ? validize_mem (gen_rtx_MEM (Pmode
,
520 plus_constant (Pmode
,
521 frame_pointer_rtx
, -16)))
522 : get_hard_reg_initial_val (Pmode
, MMIX_INCOMING_RETURN_ADDRESS_REGNUM
))
526 /* SETUP_FRAME_ADDRESSES. */
529 mmix_setup_frame_addresses (void)
531 /* Nothing needed at the moment. */
534 /* The difference between the (imaginary) frame pointer and the stack
535 pointer. Used to eliminate the frame pointer. */
538 mmix_initial_elimination_offset (int fromreg
, int toreg
)
542 = (get_frame_size () + crtl
->outgoing_args_size
+ 7) & ~7;
544 /* There is no actual offset between these two virtual values, but for
545 the frame-pointer, we have the old one in the stack position below
546 it, so the offset for the frame-pointer to the stack-pointer is one
548 if (fromreg
== MMIX_ARG_POINTER_REGNUM
549 && toreg
== MMIX_FRAME_POINTER_REGNUM
)
552 /* The difference is the size of local variables plus the size of
553 outgoing function arguments that would normally be passed as
554 registers but must be passed on stack because we're out of
555 function-argument registers. Only global saved registers are
556 counted; the others go on the register stack.
558 The frame-pointer is counted too if it is what is eliminated, as we
559 need to balance the offset for it from STARTING_FRAME_OFFSET.
561 Also add in the slot for the register stack pointer we save if we
564 Unfortunately, we can't access $0..$14, from unwinder code easily, so
565 store the return address in a frame slot too. FIXME: Only for
566 non-leaf functions. FIXME: Always with a landing pad, because it's
567 hard to know whether we need the other at the time we know we need
568 the offset for one (and have to state it). It's a kludge until we
569 can express the register stack in the EH frame info.
571 We have to do alignment here; get_frame_size will not return a
572 multiple of STACK_BOUNDARY. FIXME: Add note in manual. */
574 for (regno
= MMIX_FIRST_GLOBAL_REGNUM
;
577 if ((df_regs_ever_live_p (regno
) && ! call_used_regs
[regno
])
578 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
582 + (MMIX_CFUN_HAS_LANDING_PAD
583 ? 16 : (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
? 8 : 0))
584 + (fromreg
== MMIX_ARG_POINTER_REGNUM
? 0 : 8);
588 mmix_function_arg_advance (cumulative_args_t argsp_v
, machine_mode mode
,
589 const_tree type
, bool named ATTRIBUTE_UNUSED
)
591 CUMULATIVE_ARGS
*argsp
= get_cumulative_args (argsp_v
);
592 int arg_size
= MMIX_FUNCTION_ARG_SIZE (mode
, type
);
594 argsp
->regs
= ((targetm
.calls
.must_pass_in_stack (mode
, type
)
598 ? (MMIX_MAX_ARGS_IN_REGS
) + 1
599 : argsp
->regs
+ (7 + arg_size
) / 8);
602 /* Helper function for mmix_function_arg and mmix_function_incoming_arg. */
605 mmix_function_arg_1 (const cumulative_args_t argsp_v
,
608 bool named ATTRIBUTE_UNUSED
,
611 CUMULATIVE_ARGS
*argsp
= get_cumulative_args (argsp_v
);
613 /* Last-argument marker. */
614 if (type
== void_type_node
)
615 return (argsp
->regs
< MMIX_MAX_ARGS_IN_REGS
)
618 ? MMIX_FIRST_INCOMING_ARG_REGNUM
619 : MMIX_FIRST_ARG_REGNUM
) + argsp
->regs
)
622 return (argsp
->regs
< MMIX_MAX_ARGS_IN_REGS
623 && !targetm
.calls
.must_pass_in_stack (mode
, type
)
624 && (GET_MODE_BITSIZE (mode
) <= 64
629 ? MMIX_FIRST_INCOMING_ARG_REGNUM
630 : MMIX_FIRST_ARG_REGNUM
)
635 /* Return an rtx for a function argument to go in a register, and 0 for
636 one that must go on stack. */
639 mmix_function_arg (cumulative_args_t argsp
,
644 return mmix_function_arg_1 (argsp
, mode
, type
, named
, false);
648 mmix_function_incoming_arg (cumulative_args_t argsp
,
653 return mmix_function_arg_1 (argsp
, mode
, type
, named
, true);
656 /* Returns nonzero for everything that goes by reference, 0 for
657 everything that goes by value. */
660 mmix_pass_by_reference (cumulative_args_t argsp_v
, machine_mode mode
,
661 const_tree type
, bool named ATTRIBUTE_UNUSED
)
663 CUMULATIVE_ARGS
*argsp
= get_cumulative_args (argsp_v
);
665 /* FIXME: Check: I'm not sure the must_pass_in_stack check is
667 if (targetm
.calls
.must_pass_in_stack (mode
, type
))
670 if (MMIX_FUNCTION_ARG_SIZE (mode
, type
) > 8
672 && (!argsp
|| !argsp
->lib
))
678 /* Return nonzero if regno is a register number where a parameter is
679 passed, and 0 otherwise. */
682 mmix_function_arg_regno_p (int regno
, int incoming
)
685 = incoming
? MMIX_FIRST_INCOMING_ARG_REGNUM
: MMIX_FIRST_ARG_REGNUM
;
687 return regno
>= first_arg_regnum
688 && regno
< first_arg_regnum
+ MMIX_MAX_ARGS_IN_REGS
;
691 /* Implements TARGET_FUNCTION_VALUE. */
694 mmix_function_value (const_tree valtype
,
695 const_tree func ATTRIBUTE_UNUSED
,
698 machine_mode mode
= TYPE_MODE (valtype
);
700 int first_val_regnum
= MMIX_OUTGOING_RETURN_VALUE_REGNUM
;
701 rtx vec
[MMIX_MAX_REGS_FOR_VALUE
];
706 return gen_rtx_REG (mode
, MMIX_RETURN_VALUE_REGNUM
);
708 /* Return values that fit in a register need no special handling.
709 There's no register hole when parameters are passed in global
712 || GET_MODE_BITSIZE (mode
) <= BITS_PER_WORD
)
714 gen_rtx_REG (mode
, MMIX_OUTGOING_RETURN_VALUE_REGNUM
);
716 if (COMPLEX_MODE_P (mode
))
717 /* A complex type, made up of components. */
718 cmode
= TYPE_MODE (TREE_TYPE (valtype
));
721 /* Of the other larger-than-register modes, we only support
722 scalar mode TImode. (At least, that's the only one that's
723 been rudimentally tested.) Make sure we're alerted for
726 sorry ("support for mode %qs", GET_MODE_NAME (mode
));
728 /* In any case, we will fill registers to the natural size. */
732 nregs
= ((GET_MODE_BITSIZE (mode
) + BITS_PER_WORD
- 1) / BITS_PER_WORD
);
734 /* We need to take care of the effect of the register hole on return
735 values of large sizes; the last register will appear as the first
736 register, with the rest shifted. (For complex modes, this is just
737 swapped registers.) */
739 if (nregs
> MMIX_MAX_REGS_FOR_VALUE
)
740 internal_error ("too large function value type, needs %d registers,\
741 have only %d registers for this", nregs
, MMIX_MAX_REGS_FOR_VALUE
);
743 /* FIXME: Maybe we should handle structure values like this too
744 (adjusted for BLKmode), perhaps for both ABI:s. */
745 for (i
= 0; i
< nregs
- 1; i
++)
747 = gen_rtx_EXPR_LIST (VOIDmode
,
748 gen_rtx_REG (cmode
, first_val_regnum
+ i
),
749 GEN_INT ((i
+ 1) * BITS_PER_UNIT
));
752 = gen_rtx_EXPR_LIST (VOIDmode
,
753 gen_rtx_REG (cmode
, first_val_regnum
+ nregs
- 1),
756 return gen_rtx_PARALLEL (mode
, gen_rtvec_v (nregs
, vec
));
759 /* Implements TARGET_LIBCALL_VALUE. */
762 mmix_libcall_value (machine_mode mode
,
763 const_rtx fun ATTRIBUTE_UNUSED
)
765 return gen_rtx_REG (mode
, MMIX_RETURN_VALUE_REGNUM
);
768 /* Implements TARGET_FUNCTION_VALUE_REGNO_P. */
771 mmix_function_value_regno_p (const unsigned int regno
)
773 return regno
== MMIX_RETURN_VALUE_REGNUM
;
776 /* EH_RETURN_DATA_REGNO. */
779 mmix_eh_return_data_regno (int n
)
782 return MMIX_EH_RETURN_DATA_REGNO_START
+ n
;
784 return INVALID_REGNUM
;
787 /* EH_RETURN_STACKADJ_RTX. */
790 mmix_eh_return_stackadj_rtx (void)
792 return gen_rtx_REG (Pmode
, MMIX_EH_RETURN_STACKADJ_REGNUM
);
795 /* EH_RETURN_HANDLER_RTX. */
798 mmix_eh_return_handler_rtx (void)
800 return gen_rtx_REG (Pmode
, MMIX_INCOMING_RETURN_ADDRESS_REGNUM
);
803 /* ASM_PREFERRED_EH_DATA_FORMAT. */
806 mmix_asm_preferred_eh_data_format (int code ATTRIBUTE_UNUSED
,
807 int global ATTRIBUTE_UNUSED
)
809 /* This is the default (was at 2001-07-20). Revisit when needed. */
810 return DW_EH_PE_absptr
;
813 /* Make a note that we've seen the beginning of the prologue. This
814 matters to whether we'll translate register numbers as calculated by
818 mmix_target_asm_function_prologue (FILE *stream ATTRIBUTE_UNUSED
,
819 HOST_WIDE_INT framesize ATTRIBUTE_UNUSED
)
821 cfun
->machine
->in_prologue
= 1;
824 /* Make a note that we've seen the end of the prologue. */
827 mmix_target_asm_function_end_prologue (FILE *stream ATTRIBUTE_UNUSED
)
829 cfun
->machine
->in_prologue
= 0;
832 /* Implement TARGET_MACHINE_DEPENDENT_REORG. No actual rearrangements
833 done here; just virtually by calculating the highest saved stack
834 register number used to modify the register numbers at output time. */
841 /* We put the number of the highest saved register-file register in a
842 location convenient for the call-patterns to output. Note that we
843 don't tell dwarf2 about these registers, since it can't restore them
845 for (regno
= MMIX_LAST_STACK_REGISTER_REGNUM
;
848 if ((df_regs_ever_live_p (regno
) && !call_used_regs
[regno
])
849 || (regno
== MMIX_FRAME_POINTER_REGNUM
&& frame_pointer_needed
))
852 /* Regardless of whether they're saved (they might be just read), we
853 mustn't include registers that carry parameters. We could scan the
854 insns to see whether they're actually used (and indeed do other less
855 trivial register usage analysis and transformations), but it seems
856 wasteful to optimize for unused parameter registers. As of
857 2002-04-30, df_regs_ever_live_p (n) seems to be set for only-reads too, but
858 that might change. */
859 if (!TARGET_ABI_GNU
&& regno
< crtl
->args
.info
.regs
- 1)
861 regno
= crtl
->args
.info
.regs
- 1;
863 /* We don't want to let this cause us to go over the limit and make
864 incoming parameter registers be misnumbered and treating the last
865 parameter register and incoming return value register call-saved.
866 Stop things at the unmodified scheme. */
867 if (regno
> MMIX_RETURN_VALUE_REGNUM
- 1)
868 regno
= MMIX_RETURN_VALUE_REGNUM
- 1;
871 cfun
->machine
->highest_saved_stack_register
= regno
;
874 /* TARGET_ASM_FUNCTION_EPILOGUE. */
877 mmix_target_asm_function_epilogue (FILE *stream
,
878 HOST_WIDE_INT locals_size ATTRIBUTE_UNUSED
)
880 /* Emit an \n for readability of the generated assembly. */
881 fputc ('\n', stream
);
884 /* TARGET_ASM_OUTPUT_MI_THUNK. */
887 mmix_asm_output_mi_thunk (FILE *stream
,
888 tree fndecl ATTRIBUTE_UNUSED
,
890 HOST_WIDE_INT vcall_offset ATTRIBUTE_UNUSED
,
893 /* If you define TARGET_STRUCT_VALUE_RTX that returns 0 (i.e. pass
894 location of structure to return as invisible first argument), you
895 need to tweak this code too. */
896 const char *regname
= reg_names
[MMIX_FIRST_INCOMING_ARG_REGNUM
];
898 if (delta
>= 0 && delta
< 65536)
899 fprintf (stream
, "\tINCL %s,%d\n", regname
, (int)delta
);
900 else if (delta
< 0 && delta
>= -255)
901 fprintf (stream
, "\tSUBU %s,%s,%d\n", regname
, regname
, (int)-delta
);
904 mmix_output_register_setting (stream
, 255, delta
, 1);
905 fprintf (stream
, "\tADDU %s,%s,$255\n", regname
, regname
);
908 fprintf (stream
, "\tJMP ");
909 assemble_name (stream
, XSTR (XEXP (DECL_RTL (func
), 0), 0));
910 fprintf (stream
, "\n");
913 /* FUNCTION_PROFILER. */
916 mmix_function_profiler (FILE *stream ATTRIBUTE_UNUSED
,
917 int labelno ATTRIBUTE_UNUSED
)
919 sorry ("function_profiler support for MMIX");
922 /* Worker function for TARGET_SETUP_INCOMING_VARARGS. For the moment,
923 let's stick to pushing argument registers on the stack. Later, we
924 can parse all arguments in registers, to improve performance. */
927 mmix_setup_incoming_varargs (cumulative_args_t args_so_farp_v
,
931 int second_time ATTRIBUTE_UNUSED
)
933 CUMULATIVE_ARGS
*args_so_farp
= get_cumulative_args (args_so_farp_v
);
935 /* The last named variable has been handled, but
936 args_so_farp has not been advanced for it. */
937 if (args_so_farp
->regs
+ 1 < MMIX_MAX_ARGS_IN_REGS
)
938 *pretend_sizep
= (MMIX_MAX_ARGS_IN_REGS
- (args_so_farp
->regs
+ 1)) * 8;
940 /* We assume that one argument takes up one register here. That should
941 be true until we start messing with multi-reg parameters. */
942 if ((7 + (MMIX_FUNCTION_ARG_SIZE (mode
, vartype
))) / 8 != 1)
943 internal_error ("MMIX Internal: Last named vararg would not fit in a register");
946 /* TARGET_ASM_TRAMPOLINE_TEMPLATE. */
949 mmix_asm_trampoline_template (FILE *stream
)
951 /* Read a value into the static-chain register and jump somewhere. The
952 static chain is stored at offset 16, and the function address is
953 stored at offset 24. */
955 fprintf (stream
, "\tGETA $255,1F\n\t");
956 fprintf (stream
, "LDOU %s,$255,0\n\t", reg_names
[MMIX_STATIC_CHAIN_REGNUM
]);
957 fprintf (stream
, "LDOU $255,$255,8\n\t");
958 fprintf (stream
, "GO $255,$255,0\n");
959 fprintf (stream
, "1H\tOCTA 0\n\t");
960 fprintf (stream
, "OCTA 0\n");
963 /* TARGET_TRAMPOLINE_INIT. */
964 /* Set the static chain and function pointer field in the trampoline.
965 We also SYNCID here to be sure (doesn't matter in the simulator, but
966 some day it will). */
969 mmix_trampoline_init (rtx m_tramp
, tree fndecl
, rtx static_chain
)
971 rtx fnaddr
= XEXP (DECL_RTL (fndecl
), 0);
974 emit_block_move (m_tramp
, assemble_trampoline_template (),
975 GEN_INT (2*UNITS_PER_WORD
), BLOCK_OP_NORMAL
);
977 mem
= adjust_address (m_tramp
, DImode
, 2*UNITS_PER_WORD
);
978 emit_move_insn (mem
, static_chain
);
979 mem
= adjust_address (m_tramp
, DImode
, 3*UNITS_PER_WORD
);
980 emit_move_insn (mem
, fnaddr
);
982 mem
= adjust_address (m_tramp
, DImode
, 0);
983 emit_insn (gen_sync_icache (mem
, GEN_INT (TRAMPOLINE_SIZE
- 1)));
986 /* We must exclude constant addresses that have an increment that is not a
987 multiple of four bytes because of restrictions of the GETA
988 instruction, unless TARGET_BASE_ADDRESSES. */
991 mmix_constant_address_p (rtx x
)
993 RTX_CODE code
= GET_CODE (x
);
995 /* When using "base addresses", anything constant goes. */
996 int constant_ok
= TARGET_BASE_ADDRESSES
!= 0;
1005 /* FIXME: Don't know how to dissect these. Avoid them for now,
1006 except we know they're constants. */
1010 addend
= INTVAL (x
);
1014 if (GET_MODE (x
) != VOIDmode
)
1015 /* Strange that we got here. FIXME: Check if we do. */
1017 addend
= CONST_DOUBLE_LOW (x
);
1021 /* Note that expressions with arithmetic on forward references don't
1022 work in mmixal. People using gcc assembly code with mmixal might
1023 need to move arrays and such to before the point of use. */
1024 if (GET_CODE (XEXP (x
, 0)) == PLUS
)
1026 rtx x0
= XEXP (XEXP (x
, 0), 0);
1027 rtx x1
= XEXP (XEXP (x
, 0), 1);
1029 if ((GET_CODE (x0
) == SYMBOL_REF
1030 || GET_CODE (x0
) == LABEL_REF
)
1031 && (GET_CODE (x1
) == CONST_INT
1032 || (GET_CODE (x1
) == CONST_DOUBLE
1033 && GET_MODE (x1
) == VOIDmode
)))
1034 addend
= mmix_intval (x1
);
1046 return constant_ok
|| (addend
& 3) == 0;
1049 /* Return 1 if the address is OK, otherwise 0. */
1052 mmix_legitimate_address_p (machine_mode mode ATTRIBUTE_UNUSED
,
1054 bool strict_checking
)
1056 #define MMIX_REG_OK(X) \
1058 && (REGNO (X) <= MMIX_LAST_GENERAL_REGISTER \
1059 || (reg_renumber[REGNO (X)] > 0 \
1060 && reg_renumber[REGNO (X)] <= MMIX_LAST_GENERAL_REGISTER))) \
1061 || (!strict_checking \
1062 && (REGNO (X) <= MMIX_LAST_GENERAL_REGISTER \
1063 || REGNO (X) >= FIRST_PSEUDO_REGISTER \
1064 || REGNO (X) == ARG_POINTER_REGNUM)))
1068 (mem (plus reg reg))
1069 (mem (plus reg 0..255)).
1070 unless TARGET_BASE_ADDRESSES, in which case we accept all
1071 (mem constant_address) too. */
1075 if (REG_P (x
) && MMIX_REG_OK (x
))
1078 if (GET_CODE(x
) == PLUS
)
1080 rtx x1
= XEXP (x
, 0);
1081 rtx x2
= XEXP (x
, 1);
1083 /* Try swapping the order. FIXME: Do we need this? */
1091 /* (mem (plus (reg?) (?))) */
1092 if (!REG_P (x1
) || !MMIX_REG_OK (x1
))
1093 return TARGET_BASE_ADDRESSES
&& mmix_constant_address_p (x
);
1095 /* (mem (plus (reg) (reg?))) */
1096 if (REG_P (x2
) && MMIX_REG_OK (x2
))
1099 /* (mem (plus (reg) (0..255?))) */
1100 if (satisfies_constraint_I (x2
))
1106 return TARGET_BASE_ADDRESSES
&& mmix_constant_address_p (x
);
1109 /* Implement TARGET_LEGITIMATE_CONSTANT_P. */
1112 mmix_legitimate_constant_p (machine_mode mode ATTRIBUTE_UNUSED
, rtx x
)
1114 RTX_CODE code
= GET_CODE (x
);
1116 /* We must allow any number due to the way the cse passes works; if we
1117 do not allow any number here, general_operand will fail, and insns
1118 will fatally fail recognition instead of "softly". */
1119 if (code
== CONST_INT
|| code
== CONST_DOUBLE
)
1122 return CONSTANT_ADDRESS_P (x
);
1125 /* SELECT_CC_MODE. */
1128 mmix_select_cc_mode (RTX_CODE op
, rtx x
, rtx y ATTRIBUTE_UNUSED
)
1130 /* We use CCmode, CC_UNSmode, CC_FPmode, CC_FPEQmode and CC_FUNmode to
1131 output different compare insns. Note that we do not check the
1132 validity of the comparison here. */
1134 if (GET_MODE_CLASS (GET_MODE (x
)) == MODE_FLOAT
)
1136 if (op
== ORDERED
|| op
== UNORDERED
|| op
== UNGE
1137 || op
== UNGT
|| op
== UNLE
|| op
== UNLT
)
1140 if (op
== EQ
|| op
== NE
)
1146 if (op
== GTU
|| op
== LTU
|| op
== GEU
|| op
== LEU
)
1152 /* REVERSIBLE_CC_MODE. */
1155 mmix_reversible_cc_mode (machine_mode mode
)
1157 /* That is, all integer and the EQ, NE, ORDERED and UNORDERED float
1159 return mode
!= CC_FPmode
;
1162 /* TARGET_RTX_COSTS. */
1165 mmix_rtx_costs (rtx x ATTRIBUTE_UNUSED
,
1166 machine_mode mode ATTRIBUTE_UNUSED
,
1167 int outer_code ATTRIBUTE_UNUSED
,
1168 int opno ATTRIBUTE_UNUSED
,
1169 int *total ATTRIBUTE_UNUSED
,
1170 bool speed ATTRIBUTE_UNUSED
)
1172 /* For the time being, this is just a stub and we'll accept the
1173 generic calculations, until we can do measurements, at least.
1174 Say we did not modify any calculated costs. */
1178 /* TARGET_REGISTER_MOVE_COST.
1180 The special registers can only move to and from general regs, and we
1181 need to check that their constraints match, so say 3 for them. */
1184 mmix_register_move_cost (machine_mode mode ATTRIBUTE_UNUSED
,
1188 return (from
== GENERAL_REGS
&& from
== to
) ? 2 : 3;
1191 /* Note that we don't have a TEXT_SECTION_ASM_OP, because it has to be a
1192 compile-time constant; it's used in an asm in crtstuff.c, compiled for
1195 /* DATA_SECTION_ASM_OP. */
1198 mmix_data_section_asm_op (void)
1200 return "\t.data ! mmixal:= 8H LOC 9B";
1204 mmix_encode_section_info (tree decl
, rtx rtl
, int first
)
1206 /* Test for an external declaration, and do nothing if it is one. */
1207 if ((TREE_CODE (decl
) == VAR_DECL
1208 && (DECL_EXTERNAL (decl
) || TREE_PUBLIC (decl
)))
1209 || (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_PUBLIC (decl
)))
1211 else if (first
&& DECL_P (decl
))
1213 /* For non-visible declarations, add a "@" prefix, which we skip
1214 when the label is output. If the label does not have this
1215 prefix, a ":" is output if -mtoplevel-symbols.
1217 Note that this does not work for data that is declared extern and
1218 later defined as static. If there's code in between, that code
1219 will refer to the extern declaration, and vice versa. This just
1220 means that when -mtoplevel-symbols is in use, we can just handle
1221 well-behaved ISO-compliant code. */
1223 const char *str
= XSTR (XEXP (rtl
, 0), 0);
1224 int len
= strlen (str
);
1225 char *newstr
= XALLOCAVEC (char, len
+ 2);
1227 strcpy (newstr
+ 1, str
);
1228 XSTR (XEXP (rtl
, 0), 0) = ggc_alloc_string (newstr
, len
+ 1);
1231 /* Set SYMBOL_REF_FLAG for things that we want to access with GETA. We
1232 may need different options to reach for different things with GETA.
1233 For now, functions and things we know or have been told are constant. */
1234 if (TREE_CODE (decl
) == FUNCTION_DECL
1235 || TREE_CONSTANT (decl
)
1236 || (TREE_CODE (decl
) == VAR_DECL
1237 && TREE_READONLY (decl
)
1238 && !TREE_SIDE_EFFECTS (decl
)
1239 && (!DECL_INITIAL (decl
)
1240 || TREE_CONSTANT (DECL_INITIAL (decl
)))))
1241 SYMBOL_REF_FLAG (XEXP (rtl
, 0)) = 1;
1245 mmix_strip_name_encoding (const char *name
)
1247 for (; (*name
== '@' || *name
== '*'); name
++)
1253 /* TARGET_ASM_FILE_START.
1254 We just emit a little comment for the time being. */
1257 mmix_file_start (void)
1259 default_file_start ();
1261 fputs ("! mmixal:= 8H LOC Data_Section\n", asm_out_file
);
1263 /* Make sure each file starts with the text section. */
1264 switch_to_section (text_section
);
1267 /* TARGET_ASM_FILE_END. */
1270 mmix_file_end (void)
1272 /* Make sure each file ends with the data section. */
1273 switch_to_section (data_section
);
1276 /* TARGET_ASM_OUTPUT_SOURCE_FILENAME. */
1279 mmix_asm_output_source_filename (FILE *stream
, const char *name
)
1281 fprintf (stream
, "# 1 ");
1282 OUTPUT_QUOTED_STRING (stream
, name
);
1283 fprintf (stream
, "\n");
1286 /* OUTPUT_QUOTED_STRING. */
1289 mmix_output_quoted_string (FILE *stream
, const char *string
, int length
)
1291 const char * string_end
= string
+ length
;
1292 static const char *const unwanted_chars
= "\"[]\\";
1294 /* Output "any character except newline and double quote character". We
1295 play it safe and avoid all control characters too. We also do not
1296 want [] as characters, should input be passed through m4 with [] as
1297 quotes. Further, we avoid "\", because the GAS port handles it as a
1298 quoting character. */
1299 while (string
< string_end
)
1302 && (unsigned char) *string
< 128
1303 && !ISCNTRL (*string
)
1304 && strchr (unwanted_chars
, *string
) == NULL
)
1306 fputc ('"', stream
);
1308 && (unsigned char) *string
< 128
1309 && !ISCNTRL (*string
)
1310 && strchr (unwanted_chars
, *string
) == NULL
1311 && string
< string_end
)
1313 fputc (*string
, stream
);
1316 fputc ('"', stream
);
1317 if (string
< string_end
)
1318 fprintf (stream
, ",");
1320 if (string
< string_end
)
1322 fprintf (stream
, "#%x", *string
& 255);
1324 if (string
< string_end
)
1325 fprintf (stream
, ",");
1330 /* Target hook for assembling integer objects. Use mmix_print_operand
1331 for WYDE and TETRA. Use mmix_output_octa to output 8-byte
1335 mmix_assemble_integer (rtx x
, unsigned int size
, int aligned_p
)
1340 /* We handle a limited number of types of operands in here. But
1341 that's ok, because we can punt to generic functions. We then
1342 pretend that aligned data isn't needed, so the usual .<pseudo>
1343 syntax is used (which works for aligned data too). We actually
1344 *must* do that, since we say we don't have simple aligned
1345 pseudos, causing this function to be called. We just try and
1346 keep as much compatibility as possible with mmixal syntax for
1347 normal cases (i.e. without GNU extensions and C only). */
1349 if (GET_CODE (x
) != CONST_INT
)
1354 fputs ("\tBYTE\t", asm_out_file
);
1355 mmix_print_operand (asm_out_file
, x
, 'B');
1356 fputc ('\n', asm_out_file
);
1360 if (GET_CODE (x
) != CONST_INT
)
1365 fputs ("\tWYDE\t", asm_out_file
);
1366 mmix_print_operand (asm_out_file
, x
, 'W');
1367 fputc ('\n', asm_out_file
);
1371 if (GET_CODE (x
) != CONST_INT
)
1376 fputs ("\tTETRA\t", asm_out_file
);
1377 mmix_print_operand (asm_out_file
, x
, 'L');
1378 fputc ('\n', asm_out_file
);
1382 /* We don't get here anymore for CONST_DOUBLE, because DImode
1383 isn't expressed as CONST_DOUBLE, and DFmode is handled
1385 gcc_assert (GET_CODE (x
) != CONST_DOUBLE
);
1386 assemble_integer_with_op ("\tOCTA\t", x
);
1389 return default_assemble_integer (x
, size
, aligned_p
);
1392 /* ASM_OUTPUT_ASCII. */
1395 mmix_asm_output_ascii (FILE *stream
, const char *string
, int length
)
1399 int chunk_size
= length
> 60 ? 60 : length
;
1400 fprintf (stream
, "\tBYTE ");
1401 mmix_output_quoted_string (stream
, string
, chunk_size
);
1402 string
+= chunk_size
;
1403 length
-= chunk_size
;
1404 fprintf (stream
, "\n");
1408 /* ASM_OUTPUT_ALIGNED_COMMON. */
1411 mmix_asm_output_aligned_common (FILE *stream
,
1416 /* This is mostly the elfos.h one. There doesn't seem to be a way to
1417 express this in a mmixal-compatible way. */
1418 fprintf (stream
, "\t.comm\t");
1419 assemble_name (stream
, name
);
1420 fprintf (stream
, ",%u,%u ! mmixal-incompatible COMMON\n",
1421 size
, align
/ BITS_PER_UNIT
);
1424 /* ASM_OUTPUT_ALIGNED_LOCAL. */
1427 mmix_asm_output_aligned_local (FILE *stream
,
1432 switch_to_section (data_section
);
1434 ASM_OUTPUT_ALIGN (stream
, exact_log2 (align
/BITS_PER_UNIT
));
1435 assemble_name (stream
, name
);
1436 fprintf (stream
, "\tLOC @+%d\n", size
);
1439 /* ASM_OUTPUT_LABEL. */
1442 mmix_asm_output_label (FILE *stream
, const char *name
)
1444 assemble_name (stream
, name
);
1445 fprintf (stream
, "\tIS @\n");
1448 /* ASM_OUTPUT_INTERNAL_LABEL. */
1451 mmix_asm_output_internal_label (FILE *stream
, const char *name
)
1453 assemble_name_raw (stream
, name
);
1454 fprintf (stream
, "\tIS @\n");
1457 /* ASM_DECLARE_REGISTER_GLOBAL. */
1460 mmix_asm_declare_register_global (FILE *stream ATTRIBUTE_UNUSED
,
1461 tree decl ATTRIBUTE_UNUSED
,
1462 int regno ATTRIBUTE_UNUSED
,
1463 const char *name ATTRIBUTE_UNUSED
)
1465 /* Nothing to do here, but there *will* be, therefore the framework is
1469 /* ASM_WEAKEN_LABEL. */
1472 mmix_asm_weaken_label (FILE *stream ATTRIBUTE_UNUSED
,
1473 const char *name ATTRIBUTE_UNUSED
)
1475 fprintf (stream
, "\t.weak ");
1476 assemble_name (stream
, name
);
1477 fprintf (stream
, " ! mmixal-incompatible\n");
1480 /* MAKE_DECL_ONE_ONLY. */
1483 mmix_make_decl_one_only (tree decl
)
1485 DECL_WEAK (decl
) = 1;
1488 /* ASM_OUTPUT_LABELREF.
1489 Strip GCC's '*' and our own '@'. No order is assumed. */
1492 mmix_asm_output_labelref (FILE *stream
, const char *name
)
1496 for (; (*name
== '@' || *name
== '*'); name
++)
1500 asm_fprintf (stream
, "%s%U%s",
1501 is_extern
&& TARGET_TOPLEVEL_SYMBOLS
? ":" : "",
1505 /* ASM_OUTPUT_DEF. */
1508 mmix_asm_output_def (FILE *stream
, const char *name
, const char *value
)
1510 assemble_name (stream
, name
);
1511 fprintf (stream
, "\tIS ");
1512 assemble_name (stream
, value
);
1513 fputc ('\n', stream
);
1516 /* TARGET_PRINT_OPERAND. */
1519 mmix_print_operand (FILE *stream
, rtx x
, int code
)
1521 /* When we add support for different codes later, we can, when needed,
1522 drop through to the main handler with a modified operand. */
1524 int regno
= x
!= NULL_RTX
&& REG_P (x
) ? REGNO (x
) : 0;
1528 /* Unrelated codes are in alphabetic order. */
1531 /* For conditional branches, output "P" for a probable branch. */
1532 if (TARGET_BRANCH_PREDICT
)
1534 x
= find_reg_note (current_output_insn
, REG_BR_PROB
, 0);
1535 if (x
&& XINT (x
, 0) > REG_BR_PROB_BASE
/ 2)
1541 /* For the %d in POP %d,0. */
1542 fprintf (stream
, "%d", MMIX_POP_ARGUMENT ());
1546 if (GET_CODE (x
) != CONST_INT
)
1547 fatal_insn ("MMIX Internal: Expected a CONST_INT, not this", x
);
1548 fprintf (stream
, "%d", (int) (INTVAL (x
) & 0xff));
1552 /* Highpart. Must be general register, and not the last one, as
1553 that one cannot be part of a consecutive register pair. */
1554 if (regno
> MMIX_LAST_GENERAL_REGISTER
- 1)
1555 internal_error ("MMIX Internal: Bad register: %d", regno
);
1557 /* This is big-endian, so the high-part is the first one. */
1558 fprintf (stream
, "%s", reg_names
[MMIX_OUTPUT_REGNO (regno
)]);
1562 /* Lowpart. Must be CONST_INT or general register, and not the last
1563 one, as that one cannot be part of a consecutive register pair. */
1564 if (GET_CODE (x
) == CONST_INT
)
1566 fprintf (stream
, "#%lx",
1567 (unsigned long) (INTVAL (x
)
1568 & ((unsigned int) 0x7fffffff * 2 + 1)));
1572 if (GET_CODE (x
) == SYMBOL_REF
)
1574 output_addr_const (stream
, x
);
1578 if (regno
> MMIX_LAST_GENERAL_REGISTER
- 1)
1579 internal_error ("MMIX Internal: Bad register: %d", regno
);
1581 /* This is big-endian, so the low-part is + 1. */
1582 fprintf (stream
, "%s", reg_names
[MMIX_OUTPUT_REGNO (regno
) + 1]);
1585 /* Can't use 'a' because that's a generic modifier for address
1588 mmix_output_shiftvalue_op_from_str (stream
, "ANDN",
1594 mmix_output_shiftvalue_op_from_str (stream
, "INC",
1600 mmix_output_shiftvalue_op_from_str (stream
, "OR",
1606 mmix_output_shiftvalue_op_from_str (stream
, "SET",
1613 mmix_output_condition (stream
, x
, (code
== 'D'));
1617 /* Output an extra "e" to make fcmpe, fune. */
1618 if (TARGET_FCMP_EPSILON
)
1619 fprintf (stream
, "e");
1623 /* Output the number minus 1. */
1624 if (GET_CODE (x
) != CONST_INT
)
1626 fatal_insn ("MMIX Internal: Bad value for 'm', not a CONST_INT",
1629 fprintf (stream
, "%" PRId64
,
1630 (int64_t) (mmix_intval (x
) - 1));
1634 /* Store the number of registers we want to save. This was setup
1635 by the prologue. The actual operand contains the number of
1636 registers to pass, but we don't use it currently. Anyway, we
1637 need to output the number of saved registers here. */
1638 fprintf (stream
, "%d",
1639 cfun
->machine
->highest_saved_stack_register
+ 1);
1643 /* Store the register to output a constant to. */
1645 fatal_insn ("MMIX Internal: Expected a register, not this", x
);
1646 mmix_output_destination_register
= MMIX_OUTPUT_REGNO (regno
);
1650 /* Output the constant. Note that we use this for floats as well. */
1651 if (GET_CODE (x
) != CONST_INT
1652 && (GET_CODE (x
) != CONST_DOUBLE
1653 || (GET_MODE (x
) != VOIDmode
&& GET_MODE (x
) != DFmode
1654 && GET_MODE (x
) != SFmode
)))
1655 fatal_insn ("MMIX Internal: Expected a constant, not this", x
);
1656 mmix_output_register_setting (stream
,
1657 mmix_output_destination_register
,
1658 mmix_intval (x
), 0);
1662 /* An U for unsigned, if TARGET_ZERO_EXTEND. Ignore the operand. */
1663 if (TARGET_ZERO_EXTEND
)
1668 mmix_output_shifted_value (stream
, (int64_t) mmix_intval (x
));
1672 mmix_output_shifted_value (stream
, (int64_t) ~mmix_intval (x
));
1676 if (GET_CODE (x
) != CONST_INT
)
1677 fatal_insn ("MMIX Internal: Expected a CONST_INT, not this", x
);
1678 fprintf (stream
, "#%x", (int) (INTVAL (x
) & 0xffff));
1682 /* Nothing to do. */
1686 /* Presumably there's a missing case above if we get here. */
1687 internal_error ("MMIX Internal: Missing %qc case in mmix_print_operand", code
);
1690 switch (GET_CODE (modified_x
))
1693 regno
= REGNO (modified_x
);
1694 if (regno
>= FIRST_PSEUDO_REGISTER
)
1695 internal_error ("MMIX Internal: Bad register: %d", regno
);
1696 fprintf (stream
, "%s", reg_names
[MMIX_OUTPUT_REGNO (regno
)]);
1700 output_address (GET_MODE (modified_x
), XEXP (modified_x
, 0));
1704 /* For -2147483648, mmixal complains that the constant does not fit
1705 in 4 bytes, so let's output it as hex. Take care to handle hosts
1706 where HOST_WIDE_INT is longer than an int.
1708 Print small constants +-255 using decimal. */
1710 if (INTVAL (modified_x
) > -256 && INTVAL (modified_x
) < 256)
1711 fprintf (stream
, "%d", (int) (INTVAL (modified_x
)));
1713 fprintf (stream
, "#%x",
1714 (int) (INTVAL (modified_x
)) & (unsigned int) ~0);
1718 /* Do somewhat as CONST_INT. */
1719 mmix_output_octa (stream
, mmix_intval (modified_x
), 0);
1723 output_addr_const (stream
, modified_x
);
1727 /* No need to test for all strange things. Let output_addr_const do
1729 if (CONSTANT_P (modified_x
)
1730 /* Strangely enough, this is not included in CONSTANT_P.
1731 FIXME: Ask/check about sanity here. */
1732 || LABEL_P (modified_x
))
1734 output_addr_const (stream
, modified_x
);
1738 /* We need the original here. */
1739 fatal_insn ("MMIX Internal: Cannot decode this operand", x
);
1743 /* TARGET_PRINT_OPERAND_PUNCT_VALID_P. */
1746 mmix_print_operand_punct_valid_p (unsigned char code
)
1748 /* A '+' is used for branch prediction, similar to other ports. */
1750 /* A '.' is used for the %d in the POP %d,0 return insn. */
1754 /* TARGET_PRINT_OPERAND_ADDRESS. */
1757 mmix_print_operand_address (FILE *stream
, machine_mode
/*mode*/, rtx x
)
1761 /* I find the generated assembly code harder to read without
1763 fprintf (stream
, "%s,0", reg_names
[MMIX_OUTPUT_REGNO (REGNO (x
))]);
1766 else if (GET_CODE (x
) == PLUS
)
1768 rtx x1
= XEXP (x
, 0);
1769 rtx x2
= XEXP (x
, 1);
1773 fprintf (stream
, "%s,", reg_names
[MMIX_OUTPUT_REGNO (REGNO (x1
))]);
1777 fprintf (stream
, "%s",
1778 reg_names
[MMIX_OUTPUT_REGNO (REGNO (x2
))]);
1781 else if (satisfies_constraint_I (x2
))
1783 output_addr_const (stream
, x2
);
1789 if (TARGET_BASE_ADDRESSES
&& mmix_legitimate_constant_p (Pmode
, x
))
1791 output_addr_const (stream
, x
);
1795 fatal_insn ("MMIX Internal: This is not a recognized address", x
);
1798 /* ASM_OUTPUT_REG_PUSH. */
1801 mmix_asm_output_reg_push (FILE *stream
, int regno
)
1803 fprintf (stream
, "\tSUBU %s,%s,8\n\tSTOU %s,%s,0\n",
1804 reg_names
[MMIX_STACK_POINTER_REGNUM
],
1805 reg_names
[MMIX_STACK_POINTER_REGNUM
],
1806 reg_names
[MMIX_OUTPUT_REGNO (regno
)],
1807 reg_names
[MMIX_STACK_POINTER_REGNUM
]);
1810 /* ASM_OUTPUT_REG_POP. */
1813 mmix_asm_output_reg_pop (FILE *stream
, int regno
)
1815 fprintf (stream
, "\tLDOU %s,%s,0\n\tINCL %s,8\n",
1816 reg_names
[MMIX_OUTPUT_REGNO (regno
)],
1817 reg_names
[MMIX_STACK_POINTER_REGNUM
],
1818 reg_names
[MMIX_STACK_POINTER_REGNUM
]);
1821 /* ASM_OUTPUT_ADDR_DIFF_ELT. */
1824 mmix_asm_output_addr_diff_elt (FILE *stream
,
1825 rtx body ATTRIBUTE_UNUSED
,
1829 fprintf (stream
, "\tTETRA L%d-L%d\n", value
, rel
);
1832 /* ASM_OUTPUT_ADDR_VEC_ELT. */
1835 mmix_asm_output_addr_vec_elt (FILE *stream
, int value
)
1837 fprintf (stream
, "\tOCTA L:%d\n", value
);
1840 /* ASM_OUTPUT_SKIP. */
1843 mmix_asm_output_skip (FILE *stream
, int nbytes
)
1845 fprintf (stream
, "\tLOC @+%d\n", nbytes
);
1848 /* ASM_OUTPUT_ALIGN. */
1851 mmix_asm_output_align (FILE *stream
, int power
)
1853 /* We need to record the needed alignment of this section in the object,
1854 so we have to output an alignment directive. Use a .p2align (not
1855 .align) so people will never have to wonder about whether the
1856 argument is in number of bytes or the log2 thereof. We do it in
1857 addition to the LOC directive, so nothing needs tweaking when
1858 copy-pasting assembly into mmixal. */
1859 fprintf (stream
, "\t.p2align %d\n", power
);
1860 fprintf (stream
, "\tLOC @+(%d-@)&%d\n", 1 << power
, (1 << power
) - 1);
1863 /* DBX_REGISTER_NUMBER. */
1866 mmix_dbx_register_number (unsigned regno
)
1868 /* Adjust the register number to the one it will be output as, dammit.
1869 It'd be nice if we could check the assumption that we're filling a
1870 gap, but every register between the last saved register and parameter
1871 registers might be a valid parameter register. */
1872 regno
= MMIX_OUTPUT_REGNO (regno
);
1874 /* We need to renumber registers to get the number of the return address
1875 register in the range 0..255. It is also space-saving if registers
1876 mentioned in the call-frame information (which uses this function by
1877 defaulting DWARF_FRAME_REGNUM to DBX_REGISTER_NUMBER) are numbered
1878 0 .. 63. So map 224 .. 256+15 -> 0 .. 47 and 0 .. 223 -> 48..223+48. */
1879 return regno
>= 224 ? (regno
- 224) : (regno
+ 48);
1882 /* End of target macro support functions.
1884 Now the MMIX port's own functions. First the exported ones. */
1886 /* Wrapper for get_hard_reg_initial_val since integrate.h isn't included
1887 from insn-emit.c. */
1890 mmix_get_hard_reg_initial_val (machine_mode mode
, int regno
)
1892 return get_hard_reg_initial_val (mode
, regno
);
1895 /* Nonzero when the function epilogue is simple enough that a single
1896 "POP %d,0" should be used even within the function. */
1899 mmix_use_simple_return (void)
1903 int stack_space_to_allocate
1904 = (crtl
->outgoing_args_size
1905 + crtl
->args
.pretend_args_size
1906 + get_frame_size () + 7) & ~7;
1908 if (!TARGET_USE_RETURN_INSN
|| !reload_completed
)
1912 regno
>= MMIX_FIRST_GLOBAL_REGNUM
;
1914 /* Note that we assume that the frame-pointer-register is one of these
1915 registers, in which case we don't count it here. */
1916 if ((((regno
!= MMIX_FRAME_POINTER_REGNUM
|| !frame_pointer_needed
)
1917 && df_regs_ever_live_p (regno
) && !call_used_regs
[regno
]))
1918 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
1921 if (frame_pointer_needed
)
1922 stack_space_to_allocate
+= 8;
1924 if (MMIX_CFUN_HAS_LANDING_PAD
)
1925 stack_space_to_allocate
+= 16;
1926 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
)
1927 stack_space_to_allocate
+= 8;
1929 return stack_space_to_allocate
== 0;
1933 /* Expands the function prologue into RTX. */
1936 mmix_expand_prologue (void)
1938 HOST_WIDE_INT locals_size
= get_frame_size ();
1940 HOST_WIDE_INT stack_space_to_allocate
1941 = (crtl
->outgoing_args_size
1942 + crtl
->args
.pretend_args_size
1943 + locals_size
+ 7) & ~7;
1944 HOST_WIDE_INT offset
= -8;
1946 /* Add room needed to save global non-register-stack registers. */
1948 regno
>= MMIX_FIRST_GLOBAL_REGNUM
;
1950 /* Note that we assume that the frame-pointer-register is one of these
1951 registers, in which case we don't count it here. */
1952 if ((((regno
!= MMIX_FRAME_POINTER_REGNUM
|| !frame_pointer_needed
)
1953 && df_regs_ever_live_p (regno
) && !call_used_regs
[regno
]))
1954 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
1955 stack_space_to_allocate
+= 8;
1957 /* If we do have a frame-pointer, add room for it. */
1958 if (frame_pointer_needed
)
1959 stack_space_to_allocate
+= 8;
1961 /* If we have a non-local label, we need to be able to unwind to it, so
1962 store the current register stack pointer. Also store the return
1963 address if we do that. */
1964 if (MMIX_CFUN_HAS_LANDING_PAD
)
1965 stack_space_to_allocate
+= 16;
1966 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
)
1967 /* If we do have a saved return-address slot, add room for it. */
1968 stack_space_to_allocate
+= 8;
1970 /* Make sure we don't get an unaligned stack. */
1971 if ((stack_space_to_allocate
% 8) != 0)
1972 internal_error ("stack frame not a multiple of 8 bytes: %wd",
1973 stack_space_to_allocate
);
1975 if (crtl
->args
.pretend_args_size
)
1977 int mmix_first_vararg_reg
1978 = (MMIX_FIRST_INCOMING_ARG_REGNUM
1979 + (MMIX_MAX_ARGS_IN_REGS
1980 - crtl
->args
.pretend_args_size
/ 8));
1983 = MMIX_FIRST_INCOMING_ARG_REGNUM
+ MMIX_MAX_ARGS_IN_REGS
- 1;
1984 regno
>= mmix_first_vararg_reg
;
1989 HOST_WIDE_INT stack_chunk
1990 = stack_space_to_allocate
> (256 - 8)
1991 ? (256 - 8) : stack_space_to_allocate
;
1993 mmix_emit_sp_add (-stack_chunk
);
1994 offset
+= stack_chunk
;
1995 stack_space_to_allocate
-= stack_chunk
;
1998 /* These registers aren't actually saved (as in "will be
1999 restored"), so don't tell DWARF2 they're saved. */
2000 emit_move_insn (gen_rtx_MEM (DImode
,
2001 plus_constant (Pmode
, stack_pointer_rtx
,
2003 gen_rtx_REG (DImode
, regno
));
2008 /* Store the frame-pointer. */
2010 if (frame_pointer_needed
)
2016 /* Get 8 less than otherwise, since we need to reach offset + 8. */
2017 HOST_WIDE_INT stack_chunk
2018 = stack_space_to_allocate
> (256 - 8 - 8)
2019 ? (256 - 8 - 8) : stack_space_to_allocate
;
2021 mmix_emit_sp_add (-stack_chunk
);
2023 offset
+= stack_chunk
;
2024 stack_space_to_allocate
-= stack_chunk
;
2027 insn
= emit_move_insn (gen_rtx_MEM (DImode
,
2028 plus_constant (Pmode
,
2031 hard_frame_pointer_rtx
);
2032 RTX_FRAME_RELATED_P (insn
) = 1;
2033 insn
= emit_insn (gen_adddi3 (hard_frame_pointer_rtx
,
2035 GEN_INT (offset
+ 8)));
2036 RTX_FRAME_RELATED_P (insn
) = 1;
2040 if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
)
2045 /* Store the return-address, if one is needed on the stack. We
2046 usually store it in a register when needed, but that doesn't work
2047 with -fexceptions. */
2051 /* Get 8 less than otherwise, since we need to reach offset + 8. */
2052 HOST_WIDE_INT stack_chunk
2053 = stack_space_to_allocate
> (256 - 8 - 8)
2054 ? (256 - 8 - 8) : stack_space_to_allocate
;
2056 mmix_emit_sp_add (-stack_chunk
);
2058 offset
+= stack_chunk
;
2059 stack_space_to_allocate
-= stack_chunk
;
2062 tmpreg
= gen_rtx_REG (DImode
, 255);
2063 retreg
= gen_rtx_REG (DImode
, MMIX_rJ_REGNUM
);
2065 /* Dwarf2 code is confused by the use of a temporary register for
2066 storing the return address, so we have to express it as a note,
2067 which we attach to the actual store insn. */
2068 emit_move_insn (tmpreg
, retreg
);
2070 insn
= emit_move_insn (gen_rtx_MEM (DImode
,
2071 plus_constant (Pmode
,
2075 RTX_FRAME_RELATED_P (insn
) = 1;
2076 add_reg_note (insn
, REG_FRAME_RELATED_EXPR
,
2077 gen_rtx_SET (gen_rtx_MEM (DImode
,
2078 plus_constant (Pmode
,
2085 else if (MMIX_CFUN_HAS_LANDING_PAD
)
2088 if (MMIX_CFUN_HAS_LANDING_PAD
)
2090 /* Store the register defining the numbering of local registers, so
2091 we know how long to unwind the register stack. */
2095 /* Get 8 less than otherwise, since we need to reach offset + 8. */
2096 HOST_WIDE_INT stack_chunk
2097 = stack_space_to_allocate
> (256 - 8 - 8)
2098 ? (256 - 8 - 8) : stack_space_to_allocate
;
2100 mmix_emit_sp_add (-stack_chunk
);
2102 offset
+= stack_chunk
;
2103 stack_space_to_allocate
-= stack_chunk
;
2106 /* We don't tell dwarf2 about this one; we just have it to unwind
2107 the register stack at landing pads. FIXME: It's a kludge because
2108 we can't describe the effect of the PUSHJ and PUSHGO insns on the
2109 register stack at the moment. Best thing would be to handle it
2110 like stack-pointer offsets. Better: some hook into dwarf2out.c
2111 to produce DW_CFA_expression:s that specify the increment of rO,
2112 and unwind it at eh_return (preferred) or at the landing pad.
2113 Then saves to $0..$G-1 could be specified through that register. */
2115 emit_move_insn (gen_rtx_REG (DImode
, 255),
2116 gen_rtx_REG (DImode
,
2118 emit_move_insn (gen_rtx_MEM (DImode
,
2119 plus_constant (Pmode
, stack_pointer_rtx
,
2121 gen_rtx_REG (DImode
, 255));
2125 /* After the return-address and the frame-pointer, we have the local
2126 variables. They're the ones that may have an "unaligned" size. */
2127 offset
-= (locals_size
+ 7) & ~7;
2129 /* Now store all registers that are global, i.e. not saved by the
2130 register file machinery.
2132 It is assumed that the frame-pointer is one of these registers, so it
2133 is explicitly excluded in the count. */
2136 regno
>= MMIX_FIRST_GLOBAL_REGNUM
;
2138 if (((regno
!= MMIX_FRAME_POINTER_REGNUM
|| !frame_pointer_needed
)
2139 && df_regs_ever_live_p (regno
) && ! call_used_regs
[regno
])
2140 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
2146 HOST_WIDE_INT stack_chunk
2147 = (stack_space_to_allocate
> (256 - offset
- 8)
2148 ? (256 - offset
- 8) : stack_space_to_allocate
);
2150 mmix_emit_sp_add (-stack_chunk
);
2151 offset
+= stack_chunk
;
2152 stack_space_to_allocate
-= stack_chunk
;
2155 insn
= emit_move_insn (gen_rtx_MEM (DImode
,
2156 plus_constant (Pmode
,
2159 gen_rtx_REG (DImode
, regno
));
2160 RTX_FRAME_RELATED_P (insn
) = 1;
2164 /* Finally, allocate room for outgoing args and local vars if room
2165 wasn't allocated above. */
2166 if (stack_space_to_allocate
)
2167 mmix_emit_sp_add (-stack_space_to_allocate
);
2170 /* Expands the function epilogue into RTX. */
2173 mmix_expand_epilogue (void)
2175 HOST_WIDE_INT locals_size
= get_frame_size ();
2177 HOST_WIDE_INT stack_space_to_deallocate
2178 = (crtl
->outgoing_args_size
2179 + crtl
->args
.pretend_args_size
2180 + locals_size
+ 7) & ~7;
2182 /* The first address to access is beyond the outgoing_args area. */
2183 HOST_WIDE_INT offset
= crtl
->outgoing_args_size
;
2185 /* Add the space for global non-register-stack registers.
2186 It is assumed that the frame-pointer register can be one of these
2187 registers, in which case it is excluded from the count when needed. */
2189 regno
>= MMIX_FIRST_GLOBAL_REGNUM
;
2191 if (((regno
!= MMIX_FRAME_POINTER_REGNUM
|| !frame_pointer_needed
)
2192 && df_regs_ever_live_p (regno
) && !call_used_regs
[regno
])
2193 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
2194 stack_space_to_deallocate
+= 8;
2196 /* Add in the space for register stack-pointer. If so, always add room
2197 for the saved PC. */
2198 if (MMIX_CFUN_HAS_LANDING_PAD
)
2199 stack_space_to_deallocate
+= 16;
2200 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
)
2201 /* If we have a saved return-address slot, add it in. */
2202 stack_space_to_deallocate
+= 8;
2204 /* Add in the frame-pointer. */
2205 if (frame_pointer_needed
)
2206 stack_space_to_deallocate
+= 8;
2208 /* Make sure we don't get an unaligned stack. */
2209 if ((stack_space_to_deallocate
% 8) != 0)
2210 internal_error ("stack frame not a multiple of octabyte: %wd",
2211 stack_space_to_deallocate
);
2213 /* We will add back small offsets to the stack pointer as we go.
2214 First, we restore all registers that are global, i.e. not saved by
2215 the register file machinery. */
2217 for (regno
= MMIX_FIRST_GLOBAL_REGNUM
;
2220 if (((regno
!= MMIX_FRAME_POINTER_REGNUM
|| !frame_pointer_needed
)
2221 && df_regs_ever_live_p (regno
) && !call_used_regs
[regno
])
2222 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
2226 mmix_emit_sp_add (offset
);
2227 stack_space_to_deallocate
-= offset
;
2231 emit_move_insn (gen_rtx_REG (DImode
, regno
),
2232 gen_rtx_MEM (DImode
,
2233 plus_constant (Pmode
, stack_pointer_rtx
,
2238 /* Here is where the local variables were. As in the prologue, they
2239 might be of an unaligned size. */
2240 offset
+= (locals_size
+ 7) & ~7;
2242 /* The saved register stack pointer is just below the frame-pointer
2243 register. We don't need to restore it "manually"; the POP
2244 instruction does that. */
2245 if (MMIX_CFUN_HAS_LANDING_PAD
)
2247 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
)
2248 /* The return-address slot is just below the frame-pointer register.
2249 We don't need to restore it because we don't really use it. */
2252 /* Get back the old frame-pointer-value. */
2253 if (frame_pointer_needed
)
2257 mmix_emit_sp_add (offset
);
2259 stack_space_to_deallocate
-= offset
;
2263 emit_move_insn (hard_frame_pointer_rtx
,
2264 gen_rtx_MEM (DImode
,
2265 plus_constant (Pmode
, stack_pointer_rtx
,
2270 /* We do not need to restore pretended incoming args, just add back
2272 if (stack_space_to_deallocate
!= 0)
2273 mmix_emit_sp_add (stack_space_to_deallocate
);
2275 if (crtl
->calls_eh_return
)
2276 /* Adjust the (normal) stack-pointer to that of the receiver.
2277 FIXME: It would be nice if we could also adjust the register stack
2278 here, but we need to express it through DWARF 2 too. */
2279 emit_insn (gen_adddi3 (stack_pointer_rtx
, stack_pointer_rtx
,
2280 gen_rtx_REG (DImode
,
2281 MMIX_EH_RETURN_STACKADJ_REGNUM
)));
2284 /* Output an optimal sequence for setting a register to a specific
2285 constant. Used in an alternative for const_ints in movdi, and when
2286 using large stack-frame offsets.
2288 Use do_begin_end to say if a line-starting TAB and newline before the
2289 first insn and after the last insn is wanted. */
2292 mmix_output_register_setting (FILE *stream
,
2298 fprintf (stream
, "\t");
2300 if (insn_const_int_ok_for_constraint (value
, CONSTRAINT_K
))
2301 fprintf (stream
, "NEGU %s,0,%" PRId64
, reg_names
[regno
], -value
);
2302 else if (mmix_shiftable_wyde_value ((uint64_t) value
))
2304 /* First, the one-insn cases. */
2305 mmix_output_shiftvalue_op_from_str (stream
, "SET",
2308 fprintf (stream
, " %s,", reg_names
[regno
]);
2309 mmix_output_shifted_value (stream
, (uint64_t) value
);
2311 else if (mmix_shiftable_wyde_value (-(uint64_t) value
))
2313 /* We do this to get a bit more legible assembly code. The next
2314 alternative is mostly redundant with this. */
2316 mmix_output_shiftvalue_op_from_str (stream
, "SET",
2319 fprintf (stream
, " %s,", reg_names
[regno
]);
2320 mmix_output_shifted_value (stream
, -(uint64_t) value
);
2321 fprintf (stream
, "\n\tNEGU %s,0,%s", reg_names
[regno
],
2324 else if (mmix_shiftable_wyde_value (~(uint64_t) value
))
2326 /* Slightly more expensive, the two-insn cases. */
2328 /* FIXME: We could of course also test if 0..255-N or ~(N | 1..255)
2329 is shiftable, or any other one-insn transformation of the value.
2330 FIXME: Check first if the value is "shiftable" by two loading
2331 with two insns, since it makes more readable assembly code (if
2332 anyone else cares). */
2334 mmix_output_shiftvalue_op_from_str (stream
, "SET",
2337 fprintf (stream
, " %s,", reg_names
[regno
]);
2338 mmix_output_shifted_value (stream
, ~(uint64_t) value
);
2339 fprintf (stream
, "\n\tNOR %s,%s,0", reg_names
[regno
],
2344 /* The generic case. 2..4 insns. */
2345 static const char *const higher_parts
[] = {"L", "ML", "MH", "H"};
2346 const char *op
= "SET";
2347 const char *line_begin
= "";
2350 int64_t tmpvalue
= value
;
2352 /* Compute the number of insns needed to output this constant. */
2353 for (i
= 0; i
< 4 && tmpvalue
!= 0; i
++)
2355 if (tmpvalue
& 65535)
2359 if (TARGET_BASE_ADDRESSES
&& insns
== 3)
2361 /* The number three is based on a static observation on
2362 ghostscript-6.52. Two and four are excluded because there
2363 are too many such constants, and each unique constant (maybe
2364 offset by 1..255) were used few times compared to other uses,
2367 We use base-plus-offset addressing to force it into a global
2368 register; we just use a "LDA reg,VALUE", which will cause the
2369 assembler and linker to DTRT (for constants as well as
2371 fprintf (stream
, "LDA %s,", reg_names
[regno
]);
2372 mmix_output_octa (stream
, value
, 0);
2376 /* Output pertinent parts of the 4-wyde sequence.
2377 Still more to do if we want this to be optimal, but hey...
2378 Note that the zero case has been handled above. */
2379 for (i
= 0; i
< 4 && value
!= 0; i
++)
2383 fprintf (stream
, "%s%s%s %s,#%x", line_begin
, op
,
2384 higher_parts
[i
], reg_names
[regno
],
2385 (int) (value
& 65535));
2386 /* The first one sets the rest of the bits to 0, the next
2387 ones add set bits. */
2389 line_begin
= "\n\t";
2398 fprintf (stream
, "\n");
2401 /* Return 1 if value is 0..65535*2**(16*N) for N=0..3.
2405 mmix_shiftable_wyde_value (uint64_t value
)
2407 /* Shift by 16 bits per group, stop when we've found two groups with
2410 int has_candidate
= 0;
2412 for (i
= 0; i
< 4; i
++)
2428 /* X and Y are two things to compare using CODE. Return the rtx for
2429 the cc-reg in the proper mode. */
2432 mmix_gen_compare_reg (RTX_CODE code
, rtx x
, rtx y
)
2434 machine_mode ccmode
= SELECT_CC_MODE (code
, x
, y
);
2435 return gen_reg_rtx (ccmode
);
2438 /* Local (static) helper functions. */
2441 mmix_emit_sp_add (HOST_WIDE_INT offset
)
2447 /* Negative stack-pointer adjustments are allocations and appear in
2448 the prologue only. We mark them as frame-related so unwind and
2449 debug info is properly emitted for them. */
2451 insn
= emit_insn (gen_adddi3 (stack_pointer_rtx
,
2456 rtx tmpr
= gen_rtx_REG (DImode
, 255);
2457 RTX_FRAME_RELATED_P (emit_move_insn (tmpr
, GEN_INT (offset
))) = 1;
2458 insn
= emit_insn (gen_adddi3 (stack_pointer_rtx
,
2459 stack_pointer_rtx
, tmpr
));
2461 RTX_FRAME_RELATED_P (insn
) = 1;
2465 /* Positive adjustments are in the epilogue only. Don't mark them
2466 as "frame-related" for unwind info. */
2467 if (insn_const_int_ok_for_constraint (offset
, CONSTRAINT_L
))
2468 emit_insn (gen_adddi3 (stack_pointer_rtx
,
2473 rtx tmpr
= gen_rtx_REG (DImode
, 255);
2474 emit_move_insn (tmpr
, GEN_INT (offset
));
2475 insn
= emit_insn (gen_adddi3 (stack_pointer_rtx
,
2476 stack_pointer_rtx
, tmpr
));
2481 /* Print operator suitable for doing something with a shiftable
2482 wyde. The type of operator is passed as an asm output modifier. */
2485 mmix_output_shiftvalue_op_from_str (FILE *stream
,
2489 static const char *const op_part
[] = {"L", "ML", "MH", "H"};
2492 if (! mmix_shiftable_wyde_value (value
))
2494 char s
[sizeof ("0xffffffffffffffff")];
2495 sprintf (s
, "%#" PRIx64
, value
);
2496 internal_error ("MMIX Internal: %s is not a shiftable int", s
);
2499 for (i
= 0; i
< 4; i
++)
2501 /* We know we're through when we find one-bits in the low
2505 fprintf (stream
, "%s%s", mainop
, op_part
[i
]);
2511 /* No bits set? Then it must have been zero. */
2512 fprintf (stream
, "%sL", mainop
);
2515 /* Print a 64-bit value, optionally prefixed by assembly pseudo. */
2518 mmix_output_octa (FILE *stream
, int64_t value
, int do_begin_end
)
2521 fprintf (stream
, "\tOCTA ");
2523 /* Provide a few alternative output formats depending on the number, to
2524 improve legibility of assembler output. */
2525 if ((value
< (int64_t) 0 && value
> (int64_t) -10000)
2526 || (value
>= (int64_t) 0 && value
<= (int64_t) 16384))
2527 fprintf (stream
, "%d", (int) value
);
2528 else if (value
> (int64_t) 0
2529 && value
< ((int64_t) 1 << 31) * 2)
2530 fprintf (stream
, "#%x", (unsigned int) value
);
2531 else if (sizeof (HOST_WIDE_INT
) == sizeof (int64_t))
2532 /* We need to avoid the not-so-universal "0x" prefix; we need the
2533 pure hex-digits together with the mmixal "#" hex prefix. */
2534 fprintf (stream
, "#" HOST_WIDE_INT_PRINT_HEX_PURE
,
2535 (HOST_WIDE_INT
) value
);
2536 else /* Need to avoid the hex output; there's no ...WIDEST...HEX_PURE. */
2537 fprintf (stream
, "%" PRIu64
, value
);
2540 fprintf (stream
, "\n");
2543 /* Print the presumed shiftable wyde argument shifted into place (to
2544 be output with an operand). */
2547 mmix_output_shifted_value (FILE *stream
, int64_t value
)
2551 if (! mmix_shiftable_wyde_value (value
))
2554 sprintf (s
, "%#" PRIx64
, value
);
2555 internal_error ("MMIX Internal: %s is not a shiftable int", s
);
2558 for (i
= 0; i
< 4; i
++)
2560 /* We know we're through when we find one-bits in the low 16 bits. */
2563 fprintf (stream
, "#%x", (int) (value
& 0xffff));
2570 /* No bits set? Then it must have been zero. */
2571 fprintf (stream
, "0");
2574 /* Output an MMIX condition name corresponding to an operator
2576 (comparison_operator [(comparison_operator ...) (const_int 0)])
2577 which means we have to look at *two* operators.
2579 The argument "reversed" refers to reversal of the condition (not the
2580 same as swapping the arguments). */
2583 mmix_output_condition (FILE *stream
, const_rtx x
, int reversed
)
2589 /* The normal output cc-code. */
2590 const char *const normal
;
2592 /* The reversed cc-code, or NULL if invalid. */
2593 const char *const reversed
;
2598 machine_mode cc_mode
;
2600 /* Terminated with {UNKNOWN, NULL, NULL} */
2601 const struct cc_conv
*const convs
;
2605 #define CCEND {UNKNOWN, NULL, NULL}
2607 static const struct cc_conv cc_fun_convs
[]
2608 = {{ORDERED
, "Z", "P"},
2609 {UNORDERED
, "P", "Z"},
2611 static const struct cc_conv cc_fp_convs
[]
2615 static const struct cc_conv cc_fpeq_convs
[]
2619 static const struct cc_conv cc_uns_convs
[]
2620 = {{GEU
, "NN", "N"},
2625 static const struct cc_conv cc_signed_convs
[]
2633 static const struct cc_conv cc_di_convs
[]
2645 static const struct cc_type_conv cc_convs
[]
2646 = {{CC_FUNmode
, cc_fun_convs
},
2647 {CC_FPmode
, cc_fp_convs
},
2648 {CC_FPEQmode
, cc_fpeq_convs
},
2649 {CC_UNSmode
, cc_uns_convs
},
2650 {CCmode
, cc_signed_convs
},
2651 {DImode
, cc_di_convs
}};
2656 machine_mode mode
= GET_MODE (XEXP (x
, 0));
2657 RTX_CODE cc
= GET_CODE (x
);
2659 for (i
= 0; i
< ARRAY_SIZE (cc_convs
); i
++)
2661 if (mode
== cc_convs
[i
].cc_mode
)
2663 for (j
= 0; cc_convs
[i
].convs
[j
].cc
!= UNKNOWN
; j
++)
2664 if (cc
== cc_convs
[i
].convs
[j
].cc
)
2667 = (reversed
? cc_convs
[i
].convs
[j
].reversed
2668 : cc_convs
[i
].convs
[j
].normal
);
2670 if (mmix_cc
== NULL
)
2671 fatal_insn ("MMIX Internal: Trying to output invalidly\
2672 reversed condition:", x
);
2674 fprintf (stream
, "%s", mmix_cc
);
2678 fatal_insn ("MMIX Internal: What's the CC of this?", x
);
2682 fatal_insn ("MMIX Internal: What is the CC of this?", x
);
2685 /* Return the bit-value for a const_int or const_double. */
2688 mmix_intval (const_rtx x
)
2690 if (GET_CODE (x
) == CONST_INT
)
2693 /* We make a little song and dance because converting to long long in
2694 gcc-2.7.2 is broken. I still want people to be able to use it for
2695 cross-compilation to MMIX. */
2696 if (GET_CODE (x
) == CONST_DOUBLE
&& GET_MODE (x
) == VOIDmode
)
2697 return CONST_DOUBLE_HIGH (x
);
2699 if (GET_CODE (x
) == CONST_DOUBLE
)
2701 if (GET_MODE (x
) == DFmode
)
2705 REAL_VALUE_TO_TARGET_DOUBLE (*CONST_DOUBLE_REAL_VALUE (x
), bits
);
2707 /* The double cast is necessary to avoid getting the long
2708 sign-extended to unsigned long long(!) when they're of
2709 different size (usually 32-bit hosts). */
2711 ((uint64_t) (unsigned long) bits
[0]
2713 | (uint64_t) (unsigned long) bits
[1];
2715 else if (GET_MODE (x
) == SFmode
)
2718 REAL_VALUE_TO_TARGET_SINGLE (*CONST_DOUBLE_REAL_VALUE (x
), bits
);
2720 return (unsigned long) bits
;
2724 fatal_insn ("MMIX Internal: This is not a constant:", x
);
2727 /* Worker function for TARGET_PROMOTE_FUNCTION_MODE. */
2730 mmix_promote_function_mode (const_tree type ATTRIBUTE_UNUSED
,
2732 int *punsignedp ATTRIBUTE_UNUSED
,
2733 const_tree fntype ATTRIBUTE_UNUSED
,
2736 /* Apparently not doing TRT if int < register-size. FIXME: Perhaps
2737 FUNCTION_VALUE and LIBCALL_VALUE needs tweaking as some ports say. */
2738 if (for_return
== 1)
2741 /* Promotion of modes currently generates slow code, extending before
2742 operation, so we do it only for arguments. */
2743 if (GET_MODE_CLASS (mode
) == MODE_INT
2744 && GET_MODE_SIZE (mode
) < 8)
2749 /* Worker function for TARGET_STRUCT_VALUE_RTX. */
2752 mmix_struct_value_rtx (tree fntype ATTRIBUTE_UNUSED
,
2753 int incoming ATTRIBUTE_UNUSED
)
2755 return gen_rtx_REG (Pmode
, MMIX_STRUCT_VALUE_REGNUM
);
2758 /* Worker function for TARGET_FRAME_POINTER_REQUIRED.
2760 FIXME: Is this requirement built-in? Anyway, we should try to get rid
2761 of it; we can deduce the value. */
2764 mmix_frame_pointer_required (void)
2766 return (cfun
->has_nonlocal_label
);
2771 * eval: (c-set-style "gnu")
2772 * indent-tabs-mode: t