1 /* Definitions of target machine for GNU compiler, for MMIX.
2 Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
4 Free Software Foundation, Inc.
5 Contributed by Hans-Peter Nilsson (hp@bitrange.com)
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3, or (at your option)
14 GCC is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
25 #include "coretypes.h"
29 #include "hard-reg-set.h"
31 #include "insn-config.h"
33 #include "basic-block.h"
38 #include "diagnostic-core.h"
45 #include "integrate.h"
47 #include "target-def.h"
49 /* First some local helper definitions. */
50 #define MMIX_FIRST_GLOBAL_REGNUM 32
52 /* We'd need a current_function_has_landing_pad. It's marked as such when
53 a nonlocal_goto_receiver is expanded. Not just a C++ thing, but
55 #define MMIX_CFUN_HAS_LANDING_PAD (cfun->machine->has_landing_pad != 0)
57 /* We have no means to tell DWARF 2 about the register stack, so we need
58 to store the return address on the stack if an exception can get into
59 this function. FIXME: Narrow condition. Before any whole-function
60 analysis, df_regs_ever_live_p () isn't initialized. We know it's up-to-date
61 after reload_completed; it may contain incorrect information some time
62 before that. Within a RTL sequence (after a call to start_sequence,
63 such as in RTL expanders), leaf_function_p doesn't see all insns
64 (perhaps any insn). But regs_ever_live is up-to-date when
65 leaf_function_p () isn't, so we "or" them together to get accurate
66 information. FIXME: Some tweak to leaf_function_p might be
68 #define MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS \
70 && ((reload_completed && df_regs_ever_live_p (MMIX_rJ_REGNUM)) \
71 || !leaf_function_p ()))
73 #define IS_MMIX_EH_RETURN_DATA_REG(REGNO) \
74 (crtl->calls_eh_return \
75 && (EH_RETURN_DATA_REGNO (0) == REGNO \
76 || EH_RETURN_DATA_REGNO (1) == REGNO \
77 || EH_RETURN_DATA_REGNO (2) == REGNO \
78 || EH_RETURN_DATA_REGNO (3) == REGNO))
80 /* For the default ABI, we rename registers at output-time to fill the gap
81 between the (statically partitioned) saved registers and call-clobbered
82 registers. In effect this makes unused call-saved registers to be used
83 as call-clobbered registers. The benefit comes from keeping the number
84 of local registers (value of rL) low, since there's a cost of
85 increasing rL and clearing unused (unset) registers with lower numbers.
86 Don't translate while outputting the prologue. */
87 #define MMIX_OUTPUT_REGNO(N) \
89 || (int) (N) < MMIX_RETURN_VALUE_REGNUM \
90 || (int) (N) > MMIX_LAST_STACK_REGISTER_REGNUM \
92 || cfun->machine == NULL \
93 || cfun->machine->in_prologue \
94 ? (N) : ((N) - MMIX_RETURN_VALUE_REGNUM \
95 + cfun->machine->highest_saved_stack_register + 1))
97 /* The %d in "POP %d,0". */
98 #define MMIX_POP_ARGUMENT() \
100 && crtl->return_rtx != NULL \
101 && ! cfun->returns_struct) \
102 ? (GET_CODE (crtl->return_rtx) == PARALLEL \
103 ? GET_NUM_ELEM (XVEC (crtl->return_rtx, 0)) : 1) \
106 /* The canonical saved comparison operands for non-cc0 machines, set in
107 the compare expander. */
108 rtx mmix_compare_op0;
109 rtx mmix_compare_op1;
111 /* Declarations of locals. */
113 /* Intermediate for insn output. */
114 static int mmix_output_destination_register;
116 static void mmix_asm_output_source_filename (FILE *, const char *);
117 static void mmix_output_shiftvalue_op_from_str
118 (FILE *, const char *, HOST_WIDEST_INT);
119 static void mmix_output_shifted_value (FILE *, HOST_WIDEST_INT);
120 static void mmix_output_condition (FILE *, rtx, int);
121 static HOST_WIDEST_INT mmix_intval (rtx);
122 static void mmix_output_octa (FILE *, HOST_WIDEST_INT, int);
123 static bool mmix_assemble_integer (rtx, unsigned int, int);
124 static struct machine_function *mmix_init_machine_status (void);
125 static void mmix_encode_section_info (tree, rtx, int);
126 static const char *mmix_strip_name_encoding (const char *);
127 static void mmix_emit_sp_add (HOST_WIDE_INT offset);
128 static void mmix_target_asm_function_prologue (FILE *, HOST_WIDE_INT);
129 static void mmix_target_asm_function_end_prologue (FILE *);
130 static void mmix_target_asm_function_epilogue (FILE *, HOST_WIDE_INT);
131 static bool mmix_legitimate_address_p (enum machine_mode, rtx, bool);
132 static void mmix_reorg (void);
133 static void mmix_asm_output_mi_thunk
134 (FILE *, tree, HOST_WIDE_INT, HOST_WIDE_INT, tree);
135 static void mmix_setup_incoming_varargs
136 (CUMULATIVE_ARGS *, enum machine_mode, tree, int *, int);
137 static void mmix_file_start (void);
138 static void mmix_file_end (void);
139 static bool mmix_rtx_costs (rtx, int, int, int *, bool);
140 static rtx mmix_struct_value_rtx (tree, int);
141 static enum machine_mode mmix_promote_function_mode (const_tree,
143 int *, const_tree, int);
144 static rtx mmix_function_value (const_tree, const_tree, bool);
145 static rtx mmix_libcall_value (enum machine_mode, const_rtx);
146 static bool mmix_function_value_regno_p (const unsigned int);
147 static bool mmix_pass_by_reference (CUMULATIVE_ARGS *,
148 enum machine_mode, const_tree, bool);
149 static bool mmix_frame_pointer_required (void);
150 static void mmix_asm_trampoline_template (FILE *);
151 static void mmix_trampoline_init (rtx, tree, rtx);
153 /* Target structure macros. Listed by node. See `Using and Porting GCC'
154 for a general description. */
156 /* Node: Function Entry */
158 #undef TARGET_ASM_BYTE_OP
159 #define TARGET_ASM_BYTE_OP NULL
160 #undef TARGET_ASM_ALIGNED_HI_OP
161 #define TARGET_ASM_ALIGNED_HI_OP NULL
162 #undef TARGET_ASM_ALIGNED_SI_OP
163 #define TARGET_ASM_ALIGNED_SI_OP NULL
164 #undef TARGET_ASM_ALIGNED_DI_OP
165 #define TARGET_ASM_ALIGNED_DI_OP NULL
166 #undef TARGET_ASM_INTEGER
167 #define TARGET_ASM_INTEGER mmix_assemble_integer
169 #undef TARGET_ASM_FUNCTION_PROLOGUE
170 #define TARGET_ASM_FUNCTION_PROLOGUE mmix_target_asm_function_prologue
172 #undef TARGET_ASM_FUNCTION_END_PROLOGUE
173 #define TARGET_ASM_FUNCTION_END_PROLOGUE mmix_target_asm_function_end_prologue
175 #undef TARGET_ASM_FUNCTION_EPILOGUE
176 #define TARGET_ASM_FUNCTION_EPILOGUE mmix_target_asm_function_epilogue
178 #undef TARGET_ENCODE_SECTION_INFO
179 #define TARGET_ENCODE_SECTION_INFO mmix_encode_section_info
180 #undef TARGET_STRIP_NAME_ENCODING
181 #define TARGET_STRIP_NAME_ENCODING mmix_strip_name_encoding
183 #undef TARGET_ASM_OUTPUT_MI_THUNK
184 #define TARGET_ASM_OUTPUT_MI_THUNK mmix_asm_output_mi_thunk
185 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
186 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall
187 #undef TARGET_ASM_FILE_START
188 #define TARGET_ASM_FILE_START mmix_file_start
189 #undef TARGET_ASM_FILE_START_FILE_DIRECTIVE
190 #define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
191 #undef TARGET_ASM_FILE_END
192 #define TARGET_ASM_FILE_END mmix_file_end
193 #undef TARGET_ASM_OUTPUT_SOURCE_FILENAME
194 #define TARGET_ASM_OUTPUT_SOURCE_FILENAME mmix_asm_output_source_filename
196 #undef TARGET_RTX_COSTS
197 #define TARGET_RTX_COSTS mmix_rtx_costs
198 #undef TARGET_ADDRESS_COST
199 #define TARGET_ADDRESS_COST hook_int_rtx_bool_0
201 #undef TARGET_MACHINE_DEPENDENT_REORG
202 #define TARGET_MACHINE_DEPENDENT_REORG mmix_reorg
204 #undef TARGET_PROMOTE_FUNCTION_MODE
205 #define TARGET_PROMOTE_FUNCTION_MODE mmix_promote_function_mode
207 #undef TARGET_FUNCTION_VALUE
208 #define TARGET_FUNCTION_VALUE mmix_function_value
209 #undef TARGET_LIBCALL_VALUE
210 #define TARGET_LIBCALL_VALUE mmix_libcall_value
211 #undef TARGET_FUNCTION_VALUE_REGNO_P
212 #define TARGET_FUNCTION_VALUE_REGNO_P mmix_function_value_regno_p
214 #undef TARGET_STRUCT_VALUE_RTX
215 #define TARGET_STRUCT_VALUE_RTX mmix_struct_value_rtx
216 #undef TARGET_SETUP_INCOMING_VARARGS
217 #define TARGET_SETUP_INCOMING_VARARGS mmix_setup_incoming_varargs
218 #undef TARGET_PASS_BY_REFERENCE
219 #define TARGET_PASS_BY_REFERENCE mmix_pass_by_reference
220 #undef TARGET_CALLEE_COPIES
221 #define TARGET_CALLEE_COPIES hook_bool_CUMULATIVE_ARGS_mode_tree_bool_true
222 #undef TARGET_DEFAULT_TARGET_FLAGS
223 #define TARGET_DEFAULT_TARGET_FLAGS TARGET_DEFAULT
225 #undef TARGET_LEGITIMATE_ADDRESS_P
226 #define TARGET_LEGITIMATE_ADDRESS_P mmix_legitimate_address_p
228 #undef TARGET_FRAME_POINTER_REQUIRED
229 #define TARGET_FRAME_POINTER_REQUIRED mmix_frame_pointer_required
231 #undef TARGET_ASM_TRAMPOLINE_TEMPLATE
232 #define TARGET_ASM_TRAMPOLINE_TEMPLATE mmix_asm_trampoline_template
233 #undef TARGET_TRAMPOLINE_INIT
234 #define TARGET_TRAMPOLINE_INIT mmix_trampoline_init
236 struct gcc_target targetm = TARGET_INITIALIZER;
238 /* Functions that are expansions for target macros.
239 See Target Macros in `Using and Porting GCC'. */
241 /* OVERRIDE_OPTIONS. */
244 mmix_override_options (void)
246 /* Should we err or should we warn? Hmm. At least we must neutralize
247 it. For example the wrong kind of case-tables will be generated with
248 PIC; we use absolute address items for mmixal compatibility. FIXME:
249 They could be relative if we just elide them to after all pertinent
253 warning (0, "-f%s not supported: ignored", (flag_pic > 1) ? "PIC" : "pic");
258 /* INIT_EXPANDERS. */
261 mmix_init_expanders (void)
263 init_machine_status = mmix_init_machine_status;
266 /* Set the per-function data. */
268 static struct machine_function *
269 mmix_init_machine_status (void)
271 return ggc_alloc_cleared_machine_function ();
275 We have trouble getting the address of stuff that is located at other
276 than 32-bit alignments (GETA requirements), so try to give everything
277 at least 32-bit alignment. */
280 mmix_data_alignment (tree type ATTRIBUTE_UNUSED, int basic_align)
282 if (basic_align < 32)
288 /* CONSTANT_ALIGNMENT. */
291 mmix_constant_alignment (tree constant ATTRIBUTE_UNUSED, int basic_align)
293 if (basic_align < 32)
299 /* LOCAL_ALIGNMENT. */
302 mmix_local_alignment (tree type ATTRIBUTE_UNUSED, int basic_align)
304 if (basic_align < 32)
310 /* CONDITIONAL_REGISTER_USAGE. */
313 mmix_conditional_register_usage (void)
319 static const int gnu_abi_reg_alloc_order[]
320 = MMIX_GNU_ABI_REG_ALLOC_ORDER;
322 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
323 reg_alloc_order[i] = gnu_abi_reg_alloc_order[i];
325 /* Change the default from the mmixware ABI. For the GNU ABI,
326 $15..$30 are call-saved just as $0..$14. There must be one
327 call-clobbered local register for the "hole" that holds the
328 number of saved local registers saved by PUSHJ/PUSHGO during the
329 function call, receiving the return value at return. So best is
330 to use the highest, $31. It's already marked call-clobbered for
332 for (i = 15; i <= 30; i++)
333 call_used_regs[i] = 0;
335 /* "Unfix" the parameter registers. */
336 for (i = MMIX_RESERVED_GNU_ARG_0_REGNUM;
337 i < MMIX_RESERVED_GNU_ARG_0_REGNUM + MMIX_MAX_ARGS_IN_REGS;
342 /* Step over the ":" in special register names. */
343 if (! TARGET_TOPLEVEL_SYMBOLS)
344 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
345 if (reg_names[i][0] == ':')
349 /* INCOMING_REGNO and OUTGOING_REGNO worker function.
350 Those two macros must only be applied to function argument
351 registers. FIXME: for their current use in gcc, it'd be better
352 with an explicit specific additional FUNCTION_INCOMING_ARG_REGNO_P
353 a'la FUNCTION_ARG / FUNCTION_INCOMING_ARG instead of forcing the
354 target to commit to a fixed mapping and for any unspecified
358 mmix_opposite_regno (int regno, int incoming)
360 if (!mmix_function_arg_regno_p (regno, incoming))
365 ? MMIX_FIRST_INCOMING_ARG_REGNUM - MMIX_FIRST_ARG_REGNUM
366 : MMIX_FIRST_ARG_REGNUM - MMIX_FIRST_INCOMING_ARG_REGNUM);
370 All registers that are part of the register stack and that will be
374 mmix_local_regno (int regno)
376 return regno <= MMIX_LAST_STACK_REGISTER_REGNUM && !call_used_regs[regno];
379 /* PREFERRED_RELOAD_CLASS.
380 We need to extend the reload class of REMAINDER_REG and HIMULT_REG. */
383 mmix_preferred_reload_class (rtx x ATTRIBUTE_UNUSED, enum reg_class rclass)
385 /* FIXME: Revisit. */
386 return GET_CODE (x) == MOD && GET_MODE (x) == DImode
387 ? REMAINDER_REG : rclass;
390 /* PREFERRED_OUTPUT_RELOAD_CLASS.
391 We need to extend the reload class of REMAINDER_REG and HIMULT_REG. */
394 mmix_preferred_output_reload_class (rtx x ATTRIBUTE_UNUSED,
395 enum reg_class rclass)
397 /* FIXME: Revisit. */
398 return GET_CODE (x) == MOD && GET_MODE (x) == DImode
399 ? REMAINDER_REG : rclass;
402 /* SECONDARY_RELOAD_CLASS.
403 We need to reload regs of REMAINDER_REG and HIMULT_REG elsewhere. */
406 mmix_secondary_reload_class (enum reg_class rclass,
407 enum machine_mode mode ATTRIBUTE_UNUSED,
408 rtx x ATTRIBUTE_UNUSED,
409 int in_p ATTRIBUTE_UNUSED)
411 if (rclass == REMAINDER_REG
412 || rclass == HIMULT_REG
413 || rclass == SYSTEM_REGS)
419 /* CONST_OK_FOR_LETTER_P. */
422 mmix_const_ok_for_letter_p (HOST_WIDE_INT value, int c)
425 (c == 'I' ? value >= 0 && value <= 255
426 : c == 'J' ? value >= 0 && value <= 65535
427 : c == 'K' ? value <= 0 && value >= -255
428 : c == 'L' ? mmix_shiftable_wyde_value (value)
429 : c == 'M' ? value == 0
430 : c == 'N' ? mmix_shiftable_wyde_value (~value)
431 : c == 'O' ? (value == 3 || value == 5 || value == 9
436 /* CONST_DOUBLE_OK_FOR_LETTER_P. */
439 mmix_const_double_ok_for_letter_p (rtx value, int c)
442 (c == 'G' ? value == CONST0_RTX (GET_MODE (value))
447 We need this since our constants are not always expressible as
448 CONST_INT:s, but rather often as CONST_DOUBLE:s. */
451 mmix_extra_constraint (rtx x, int c, int strict)
453 HOST_WIDEST_INT value;
455 /* When checking for an address, we need to handle strict vs. non-strict
456 register checks. Don't use address_operand, but instead its
457 equivalent (its callee, which it is just a wrapper for),
458 memory_operand_p and the strict-equivalent strict_memory_address_p. */
462 ? strict_memory_address_p (Pmode, x)
463 : memory_address_p (Pmode, x);
465 /* R asks whether x is to be loaded with GETA or something else. Right
466 now, only a SYMBOL_REF and LABEL_REF can fit for
467 TARGET_BASE_ADDRESSES.
469 Only constant symbolic addresses apply. With TARGET_BASE_ADDRESSES,
470 we just allow straight LABEL_REF or SYMBOL_REFs with SYMBOL_REF_FLAG
471 set right now; only function addresses and code labels. If we change
472 to let SYMBOL_REF_FLAG be set on other symbols, we have to check
473 inside CONST expressions. When TARGET_BASE_ADDRESSES is not in
474 effect, a "raw" constant check together with mmix_constant_address_p
475 is all that's needed; we want all constant addresses to be loaded
479 GET_CODE (x) != CONST_INT && GET_CODE (x) != CONST_DOUBLE
480 && mmix_constant_address_p (x)
481 && (! TARGET_BASE_ADDRESSES
482 || (GET_CODE (x) == LABEL_REF
483 || (GET_CODE (x) == SYMBOL_REF && SYMBOL_REF_FLAG (x))));
485 if (GET_CODE (x) != CONST_DOUBLE || GET_MODE (x) != VOIDmode)
488 value = mmix_intval (x);
490 /* We used to map Q->J, R->K, S->L, T->N, U->O, but we don't have to any
491 more ('U' taken for address_operand, 'R' similarly). Some letters map
492 outside of CONST_INT, though; we still use 'S' and 'T'. */
494 return mmix_shiftable_wyde_value (value);
496 return mmix_shiftable_wyde_value (~value);
500 /* DYNAMIC_CHAIN_ADDRESS. */
503 mmix_dynamic_chain_address (rtx frame)
505 /* FIXME: the frame-pointer is stored at offset -8 from the current
506 frame-pointer. Unfortunately, the caller assumes that a
507 frame-pointer is present for *all* previous frames. There should be
508 a way to say that that cannot be done, like for RETURN_ADDR_RTX. */
509 return plus_constant (frame, -8);
512 /* STARTING_FRAME_OFFSET. */
515 mmix_starting_frame_offset (void)
517 /* The old frame pointer is in the slot below the new one, so
518 FIRST_PARM_OFFSET does not need to depend on whether the
519 frame-pointer is needed or not. We have to adjust for the register
520 stack pointer being located below the saved frame pointer.
521 Similarly, we store the return address on the stack too, for
522 exception handling, and always if we save the register stack pointer. */
525 + (MMIX_CFUN_HAS_LANDING_PAD
526 ? -16 : (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS ? -8 : 0)));
529 /* RETURN_ADDR_RTX. */
532 mmix_return_addr_rtx (int count, rtx frame ATTRIBUTE_UNUSED)
535 ? (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
536 /* FIXME: Set frame_alias_set on the following. (Why?)
537 See mmix_initial_elimination_offset for the reason we can't use
538 get_hard_reg_initial_val for both. Always using a stack slot
539 and not a register would be suboptimal. */
540 ? validize_mem (gen_rtx_MEM (Pmode, plus_constant (frame_pointer_rtx, -16)))
541 : get_hard_reg_initial_val (Pmode, MMIX_INCOMING_RETURN_ADDRESS_REGNUM))
545 /* SETUP_FRAME_ADDRESSES. */
548 mmix_setup_frame_addresses (void)
550 /* Nothing needed at the moment. */
553 /* The difference between the (imaginary) frame pointer and the stack
554 pointer. Used to eliminate the frame pointer. */
557 mmix_initial_elimination_offset (int fromreg, int toreg)
561 = (get_frame_size () + crtl->outgoing_args_size + 7) & ~7;
563 /* There is no actual offset between these two virtual values, but for
564 the frame-pointer, we have the old one in the stack position below
565 it, so the offset for the frame-pointer to the stack-pointer is one
567 if (fromreg == MMIX_ARG_POINTER_REGNUM
568 && toreg == MMIX_FRAME_POINTER_REGNUM)
571 /* The difference is the size of local variables plus the size of
572 outgoing function arguments that would normally be passed as
573 registers but must be passed on stack because we're out of
574 function-argument registers. Only global saved registers are
575 counted; the others go on the register stack.
577 The frame-pointer is counted too if it is what is eliminated, as we
578 need to balance the offset for it from STARTING_FRAME_OFFSET.
580 Also add in the slot for the register stack pointer we save if we
583 Unfortunately, we can't access $0..$14, from unwinder code easily, so
584 store the return address in a frame slot too. FIXME: Only for
585 non-leaf functions. FIXME: Always with a landing pad, because it's
586 hard to know whether we need the other at the time we know we need
587 the offset for one (and have to state it). It's a kludge until we
588 can express the register stack in the EH frame info.
590 We have to do alignment here; get_frame_size will not return a
591 multiple of STACK_BOUNDARY. FIXME: Add note in manual. */
593 for (regno = MMIX_FIRST_GLOBAL_REGNUM;
596 if ((df_regs_ever_live_p (regno) && ! call_used_regs[regno])
597 || IS_MMIX_EH_RETURN_DATA_REG (regno))
601 + (MMIX_CFUN_HAS_LANDING_PAD
602 ? 16 : (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS ? 8 : 0))
603 + (fromreg == MMIX_ARG_POINTER_REGNUM ? 0 : 8);
606 /* Return an rtx for a function argument to go in a register, and 0 for
607 one that must go on stack. */
610 mmix_function_arg (const CUMULATIVE_ARGS *argsp,
611 enum machine_mode mode,
613 int named ATTRIBUTE_UNUSED,
616 /* Last-argument marker. */
617 if (type == void_type_node)
618 return (argsp->regs < MMIX_MAX_ARGS_IN_REGS)
621 ? MMIX_FIRST_INCOMING_ARG_REGNUM
622 : MMIX_FIRST_ARG_REGNUM) + argsp->regs)
625 return (argsp->regs < MMIX_MAX_ARGS_IN_REGS
626 && !targetm.calls.must_pass_in_stack (mode, type)
627 && (GET_MODE_BITSIZE (mode) <= 64
632 ? MMIX_FIRST_INCOMING_ARG_REGNUM
633 : MMIX_FIRST_ARG_REGNUM)
638 /* Returns nonzero for everything that goes by reference, 0 for
639 everything that goes by value. */
642 mmix_pass_by_reference (CUMULATIVE_ARGS *argsp, enum machine_mode mode,
643 const_tree type, bool named ATTRIBUTE_UNUSED)
645 /* FIXME: Check: I'm not sure the must_pass_in_stack check is
647 if (targetm.calls.must_pass_in_stack (mode, type))
650 if (MMIX_FUNCTION_ARG_SIZE (mode, type) > 8
652 && (!argsp || !argsp->lib))
658 /* Return nonzero if regno is a register number where a parameter is
659 passed, and 0 otherwise. */
662 mmix_function_arg_regno_p (int regno, int incoming)
665 = incoming ? MMIX_FIRST_INCOMING_ARG_REGNUM : MMIX_FIRST_ARG_REGNUM;
667 return regno >= first_arg_regnum
668 && regno < first_arg_regnum + MMIX_MAX_ARGS_IN_REGS;
671 /* Implements TARGET_FUNCTION_VALUE. */
674 mmix_function_value (const_tree valtype,
675 const_tree func ATTRIBUTE_UNUSED,
678 enum machine_mode mode = TYPE_MODE (valtype);
679 enum machine_mode cmode;
680 int first_val_regnum = MMIX_OUTGOING_RETURN_VALUE_REGNUM;
681 rtx vec[MMIX_MAX_REGS_FOR_VALUE];
686 return gen_rtx_REG (mode, MMIX_RETURN_VALUE_REGNUM);
688 /* Return values that fit in a register need no special handling.
689 There's no register hole when parameters are passed in global
692 || GET_MODE_BITSIZE (mode) <= BITS_PER_WORD)
694 gen_rtx_REG (mode, MMIX_OUTGOING_RETURN_VALUE_REGNUM);
696 if (COMPLEX_MODE_P (mode))
697 /* A complex type, made up of components. */
698 cmode = TYPE_MODE (TREE_TYPE (valtype));
701 /* Of the other larger-than-register modes, we only support
702 scalar mode TImode. (At least, that's the only one that's
703 been rudimentally tested.) Make sure we're alerted for
706 sorry ("support for mode %qs", GET_MODE_NAME (mode));
708 /* In any case, we will fill registers to the natural size. */
712 nregs = ((GET_MODE_BITSIZE (mode) + BITS_PER_WORD - 1) / BITS_PER_WORD);
714 /* We need to take care of the effect of the register hole on return
715 values of large sizes; the last register will appear as the first
716 register, with the rest shifted. (For complex modes, this is just
717 swapped registers.) */
719 if (nregs > MMIX_MAX_REGS_FOR_VALUE)
720 internal_error ("too large function value type, needs %d registers,\
721 have only %d registers for this", nregs, MMIX_MAX_REGS_FOR_VALUE);
723 /* FIXME: Maybe we should handle structure values like this too
724 (adjusted for BLKmode), perhaps for both ABI:s. */
725 for (i = 0; i < nregs - 1; i++)
727 = gen_rtx_EXPR_LIST (VOIDmode,
728 gen_rtx_REG (cmode, first_val_regnum + i),
729 GEN_INT ((i + 1) * BITS_PER_UNIT));
732 = gen_rtx_EXPR_LIST (VOIDmode,
733 gen_rtx_REG (cmode, first_val_regnum + nregs - 1),
736 return gen_rtx_PARALLEL (VOIDmode, gen_rtvec_v (nregs, vec));
739 /* Implements TARGET_LIBCALL_VALUE. */
742 mmix_libcall_value (enum machine_mode mode,
743 const_rtx fun ATTRIBUTE_UNUSED)
745 return gen_rtx_REG (mode, MMIX_RETURN_VALUE_REGNUM);
748 /* Implements TARGET_FUNCTION_VALUE_REGNO_P. */
751 mmix_function_value_regno_p (const unsigned int regno)
753 return regno == MMIX_RETURN_VALUE_REGNUM;
756 /* EH_RETURN_DATA_REGNO. */
759 mmix_eh_return_data_regno (int n)
762 return MMIX_EH_RETURN_DATA_REGNO_START + n;
764 return INVALID_REGNUM;
767 /* EH_RETURN_STACKADJ_RTX. */
770 mmix_eh_return_stackadj_rtx (void)
772 return gen_rtx_REG (Pmode, MMIX_EH_RETURN_STACKADJ_REGNUM);
775 /* EH_RETURN_HANDLER_RTX. */
778 mmix_eh_return_handler_rtx (void)
780 return gen_rtx_REG (Pmode, MMIX_INCOMING_RETURN_ADDRESS_REGNUM);
783 /* ASM_PREFERRED_EH_DATA_FORMAT. */
786 mmix_asm_preferred_eh_data_format (int code ATTRIBUTE_UNUSED,
787 int global ATTRIBUTE_UNUSED)
789 /* This is the default (was at 2001-07-20). Revisit when needed. */
790 return DW_EH_PE_absptr;
793 /* Make a note that we've seen the beginning of the prologue. This
794 matters to whether we'll translate register numbers as calculated by
798 mmix_target_asm_function_prologue (FILE *stream ATTRIBUTE_UNUSED,
799 HOST_WIDE_INT framesize ATTRIBUTE_UNUSED)
801 cfun->machine->in_prologue = 1;
804 /* Make a note that we've seen the end of the prologue. */
807 mmix_target_asm_function_end_prologue (FILE *stream ATTRIBUTE_UNUSED)
809 cfun->machine->in_prologue = 0;
812 /* Implement TARGET_MACHINE_DEPENDENT_REORG. No actual rearrangements
813 done here; just virtually by calculating the highest saved stack
814 register number used to modify the register numbers at output time. */
821 /* We put the number of the highest saved register-file register in a
822 location convenient for the call-patterns to output. Note that we
823 don't tell dwarf2 about these registers, since it can't restore them
825 for (regno = MMIX_LAST_STACK_REGISTER_REGNUM;
828 if ((df_regs_ever_live_p (regno) && !call_used_regs[regno])
829 || (regno == MMIX_FRAME_POINTER_REGNUM && frame_pointer_needed))
832 /* Regardless of whether they're saved (they might be just read), we
833 mustn't include registers that carry parameters. We could scan the
834 insns to see whether they're actually used (and indeed do other less
835 trivial register usage analysis and transformations), but it seems
836 wasteful to optimize for unused parameter registers. As of
837 2002-04-30, df_regs_ever_live_p (n) seems to be set for only-reads too, but
838 that might change. */
839 if (!TARGET_ABI_GNU && regno < crtl->args.info.regs - 1)
841 regno = crtl->args.info.regs - 1;
843 /* We don't want to let this cause us to go over the limit and make
844 incoming parameter registers be misnumbered and treating the last
845 parameter register and incoming return value register call-saved.
846 Stop things at the unmodified scheme. */
847 if (regno > MMIX_RETURN_VALUE_REGNUM - 1)
848 regno = MMIX_RETURN_VALUE_REGNUM - 1;
851 cfun->machine->highest_saved_stack_register = regno;
854 /* TARGET_ASM_FUNCTION_EPILOGUE. */
857 mmix_target_asm_function_epilogue (FILE *stream,
858 HOST_WIDE_INT locals_size ATTRIBUTE_UNUSED)
860 /* Emit an \n for readability of the generated assembly. */
861 fputc ('\n', stream);
864 /* TARGET_ASM_OUTPUT_MI_THUNK. */
867 mmix_asm_output_mi_thunk (FILE *stream,
868 tree fndecl ATTRIBUTE_UNUSED,
870 HOST_WIDE_INT vcall_offset ATTRIBUTE_UNUSED,
873 /* If you define TARGET_STRUCT_VALUE_RTX that returns 0 (i.e. pass
874 location of structure to return as invisible first argument), you
875 need to tweak this code too. */
876 const char *regname = reg_names[MMIX_FIRST_INCOMING_ARG_REGNUM];
878 if (delta >= 0 && delta < 65536)
879 fprintf (stream, "\tINCL %s,%d\n", regname, (int)delta);
880 else if (delta < 0 && delta >= -255)
881 fprintf (stream, "\tSUBU %s,%s,%d\n", regname, regname, (int)-delta);
884 mmix_output_register_setting (stream, 255, delta, 1);
885 fprintf (stream, "\tADDU %s,%s,$255\n", regname, regname);
888 fprintf (stream, "\tJMP ");
889 assemble_name (stream, XSTR (XEXP (DECL_RTL (func), 0), 0));
890 fprintf (stream, "\n");
893 /* FUNCTION_PROFILER. */
896 mmix_function_profiler (FILE *stream ATTRIBUTE_UNUSED,
897 int labelno ATTRIBUTE_UNUSED)
899 sorry ("function_profiler support for MMIX");
902 /* Worker function for TARGET_SETUP_INCOMING_VARARGS. For the moment,
903 let's stick to pushing argument registers on the stack. Later, we
904 can parse all arguments in registers, to improve performance. */
907 mmix_setup_incoming_varargs (CUMULATIVE_ARGS *args_so_farp,
908 enum machine_mode mode,
911 int second_time ATTRIBUTE_UNUSED)
913 /* The last named variable has been handled, but
914 args_so_farp has not been advanced for it. */
915 if (args_so_farp->regs + 1 < MMIX_MAX_ARGS_IN_REGS)
916 *pretend_sizep = (MMIX_MAX_ARGS_IN_REGS - (args_so_farp->regs + 1)) * 8;
918 /* We assume that one argument takes up one register here. That should
919 be true until we start messing with multi-reg parameters. */
920 if ((7 + (MMIX_FUNCTION_ARG_SIZE (mode, vartype))) / 8 != 1)
921 internal_error ("MMIX Internal: Last named vararg would not fit in a register");
924 /* TARGET_ASM_TRAMPOLINE_TEMPLATE. */
927 mmix_asm_trampoline_template (FILE *stream)
929 /* Read a value into the static-chain register and jump somewhere. The
930 static chain is stored at offset 16, and the function address is
931 stored at offset 24. */
933 fprintf (stream, "\tGETA $255,1F\n\t");
934 fprintf (stream, "LDOU %s,$255,0\n\t", reg_names[MMIX_STATIC_CHAIN_REGNUM]);
935 fprintf (stream, "LDOU $255,$255,8\n\t");
936 fprintf (stream, "GO $255,$255,0\n");
937 fprintf (stream, "1H\tOCTA 0\n\t");
938 fprintf (stream, "OCTA 0\n");
941 /* TARGET_TRAMPOLINE_INIT. */
942 /* Set the static chain and function pointer field in the trampoline.
943 We also SYNCID here to be sure (doesn't matter in the simulator, but
944 some day it will). */
947 mmix_trampoline_init (rtx m_tramp, tree fndecl, rtx static_chain)
949 rtx fnaddr = XEXP (DECL_RTL (fndecl), 0);
952 emit_block_move (m_tramp, assemble_trampoline_template (),
953 GEN_INT (2*UNITS_PER_WORD), BLOCK_OP_NORMAL);
955 mem = adjust_address (m_tramp, DImode, 2*UNITS_PER_WORD);
956 emit_move_insn (mem, static_chain);
957 mem = adjust_address (m_tramp, DImode, 3*UNITS_PER_WORD);
958 emit_move_insn (mem, fnaddr);
960 mem = adjust_address (m_tramp, DImode, 0);
961 emit_insn (gen_sync_icache (mem, GEN_INT (TRAMPOLINE_SIZE - 1)));
964 /* We must exclude constant addresses that have an increment that is not a
965 multiple of four bytes because of restrictions of the GETA
966 instruction, unless TARGET_BASE_ADDRESSES. */
969 mmix_constant_address_p (rtx x)
971 RTX_CODE code = GET_CODE (x);
973 /* When using "base addresses", anything constant goes. */
974 int constant_ok = TARGET_BASE_ADDRESSES != 0;
983 /* FIXME: Don't know how to dissect these. Avoid them for now,
984 except we know they're constants. */
992 if (GET_MODE (x) != VOIDmode)
993 /* Strange that we got here. FIXME: Check if we do. */
995 addend = CONST_DOUBLE_LOW (x);
999 /* Note that expressions with arithmetic on forward references don't
1000 work in mmixal. People using gcc assembly code with mmixal might
1001 need to move arrays and such to before the point of use. */
1002 if (GET_CODE (XEXP (x, 0)) == PLUS)
1004 rtx x0 = XEXP (XEXP (x, 0), 0);
1005 rtx x1 = XEXP (XEXP (x, 0), 1);
1007 if ((GET_CODE (x0) == SYMBOL_REF
1008 || GET_CODE (x0) == LABEL_REF)
1009 && (GET_CODE (x1) == CONST_INT
1010 || (GET_CODE (x1) == CONST_DOUBLE
1011 && GET_MODE (x1) == VOIDmode)))
1012 addend = mmix_intval (x1);
1024 return constant_ok || (addend & 3) == 0;
1027 /* Return 1 if the address is OK, otherwise 0. */
1030 mmix_legitimate_address_p (enum machine_mode mode ATTRIBUTE_UNUSED,
1032 bool strict_checking)
1034 #define MMIX_REG_OK(X) \
1036 && (REGNO (X) <= MMIX_LAST_GENERAL_REGISTER \
1037 || (reg_renumber[REGNO (X)] > 0 \
1038 && reg_renumber[REGNO (X)] <= MMIX_LAST_GENERAL_REGISTER))) \
1039 || (!strict_checking \
1040 && (REGNO (X) <= MMIX_LAST_GENERAL_REGISTER \
1041 || REGNO (X) >= FIRST_PSEUDO_REGISTER \
1042 || REGNO (X) == ARG_POINTER_REGNUM)))
1046 (mem (plus reg reg))
1047 (mem (plus reg 0..255)).
1048 unless TARGET_BASE_ADDRESSES, in which case we accept all
1049 (mem constant_address) too. */
1053 if (REG_P (x) && MMIX_REG_OK (x))
1056 if (GET_CODE(x) == PLUS)
1058 rtx x1 = XEXP (x, 0);
1059 rtx x2 = XEXP (x, 1);
1061 /* Try swapping the order. FIXME: Do we need this? */
1069 /* (mem (plus (reg?) (?))) */
1070 if (!REG_P (x1) || !MMIX_REG_OK (x1))
1071 return TARGET_BASE_ADDRESSES && mmix_constant_address_p (x);
1073 /* (mem (plus (reg) (reg?))) */
1074 if (REG_P (x2) && MMIX_REG_OK (x2))
1077 /* (mem (plus (reg) (0..255?))) */
1078 if (GET_CODE (x2) == CONST_INT
1079 && CONST_OK_FOR_LETTER_P (INTVAL (x2), 'I'))
1085 return TARGET_BASE_ADDRESSES && mmix_constant_address_p (x);
1088 /* LEGITIMATE_CONSTANT_P. */
1091 mmix_legitimate_constant_p (rtx x)
1093 RTX_CODE code = GET_CODE (x);
1095 /* We must allow any number due to the way the cse passes works; if we
1096 do not allow any number here, general_operand will fail, and insns
1097 will fatally fail recognition instead of "softly". */
1098 if (code == CONST_INT || code == CONST_DOUBLE)
1101 return CONSTANT_ADDRESS_P (x);
1104 /* SELECT_CC_MODE. */
1107 mmix_select_cc_mode (RTX_CODE op, rtx x, rtx y ATTRIBUTE_UNUSED)
1109 /* We use CCmode, CC_UNSmode, CC_FPmode, CC_FPEQmode and CC_FUNmode to
1110 output different compare insns. Note that we do not check the
1111 validity of the comparison here. */
1113 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1115 if (op == ORDERED || op == UNORDERED || op == UNGE
1116 || op == UNGT || op == UNLE || op == UNLT)
1119 if (op == EQ || op == NE)
1125 if (op == GTU || op == LTU || op == GEU || op == LEU)
1131 /* REVERSIBLE_CC_MODE. */
1134 mmix_reversible_cc_mode (enum machine_mode mode)
1136 /* That is, all integer and the EQ, NE, ORDERED and UNORDERED float
1138 return mode != CC_FPmode;
1141 /* TARGET_RTX_COSTS. */
1144 mmix_rtx_costs (rtx x ATTRIBUTE_UNUSED,
1145 int code ATTRIBUTE_UNUSED,
1146 int outer_code ATTRIBUTE_UNUSED,
1147 int *total ATTRIBUTE_UNUSED,
1148 bool speed ATTRIBUTE_UNUSED)
1150 /* For the time being, this is just a stub and we'll accept the
1151 generic calculations, until we can do measurements, at least.
1152 Say we did not modify any calculated costs. */
1156 /* REGISTER_MOVE_COST. */
1159 mmix_register_move_cost (enum machine_mode mode ATTRIBUTE_UNUSED,
1160 enum reg_class from,
1163 return (from == GENERAL_REGS && from == to) ? 2 : 3;
1166 /* Note that we don't have a TEXT_SECTION_ASM_OP, because it has to be a
1167 compile-time constant; it's used in an asm in crtstuff.c, compiled for
1170 /* DATA_SECTION_ASM_OP. */
1173 mmix_data_section_asm_op (void)
1175 return "\t.data ! mmixal:= 8H LOC 9B";
1179 mmix_encode_section_info (tree decl, rtx rtl, int first)
1181 /* Test for an external declaration, and do nothing if it is one. */
1182 if ((TREE_CODE (decl) == VAR_DECL
1183 && (DECL_EXTERNAL (decl) || TREE_PUBLIC (decl)))
1184 || (TREE_CODE (decl) == FUNCTION_DECL && TREE_PUBLIC (decl)))
1186 else if (first && DECL_P (decl))
1188 /* For non-visible declarations, add a "@" prefix, which we skip
1189 when the label is output. If the label does not have this
1190 prefix, a ":" is output if -mtoplevel-symbols.
1192 Note that this does not work for data that is declared extern and
1193 later defined as static. If there's code in between, that code
1194 will refer to the extern declaration, and vice versa. This just
1195 means that when -mtoplevel-symbols is in use, we can just handle
1196 well-behaved ISO-compliant code. */
1198 const char *str = XSTR (XEXP (rtl, 0), 0);
1199 int len = strlen (str);
1200 char *newstr = XALLOCAVEC (char, len + 2);
1202 strcpy (newstr + 1, str);
1203 XSTR (XEXP (rtl, 0), 0) = ggc_alloc_string (newstr, len + 1);
1206 /* Set SYMBOL_REF_FLAG for things that we want to access with GETA. We
1207 may need different options to reach for different things with GETA.
1208 For now, functions and things we know or have been told are constant. */
1209 if (TREE_CODE (decl) == FUNCTION_DECL
1210 || TREE_CONSTANT (decl)
1211 || (TREE_CODE (decl) == VAR_DECL
1212 && TREE_READONLY (decl)
1213 && !TREE_SIDE_EFFECTS (decl)
1214 && (!DECL_INITIAL (decl)
1215 || TREE_CONSTANT (DECL_INITIAL (decl)))))
1216 SYMBOL_REF_FLAG (XEXP (rtl, 0)) = 1;
1220 mmix_strip_name_encoding (const char *name)
1222 for (; (*name == '@' || *name == '*'); name++)
1228 /* TARGET_ASM_FILE_START.
1229 We just emit a little comment for the time being. */
1232 mmix_file_start (void)
1234 default_file_start ();
1236 fputs ("! mmixal:= 8H LOC Data_Section\n", asm_out_file);
1238 /* Make sure each file starts with the text section. */
1239 switch_to_section (text_section);
1242 /* TARGET_ASM_FILE_END. */
1245 mmix_file_end (void)
1247 /* Make sure each file ends with the data section. */
1248 switch_to_section (data_section);
1251 /* TARGET_ASM_OUTPUT_SOURCE_FILENAME. */
1254 mmix_asm_output_source_filename (FILE *stream, const char *name)
1256 fprintf (stream, "# 1 ");
1257 OUTPUT_QUOTED_STRING (stream, name);
1258 fprintf (stream, "\n");
1261 /* OUTPUT_QUOTED_STRING. */
1264 mmix_output_quoted_string (FILE *stream, const char *string, int length)
1266 const char * string_end = string + length;
1267 static const char *const unwanted_chars = "\"[]\\";
1269 /* Output "any character except newline and double quote character". We
1270 play it safe and avoid all control characters too. We also do not
1271 want [] as characters, should input be passed through m4 with [] as
1272 quotes. Further, we avoid "\", because the GAS port handles it as a
1273 quoting character. */
1274 while (string < string_end)
1277 && (unsigned char) *string < 128
1278 && !ISCNTRL (*string)
1279 && strchr (unwanted_chars, *string) == NULL)
1281 fputc ('"', stream);
1283 && (unsigned char) *string < 128
1284 && !ISCNTRL (*string)
1285 && strchr (unwanted_chars, *string) == NULL
1286 && string < string_end)
1288 fputc (*string, stream);
1291 fputc ('"', stream);
1292 if (string < string_end)
1293 fprintf (stream, ",");
1295 if (string < string_end)
1297 fprintf (stream, "#%x", *string & 255);
1299 if (string < string_end)
1300 fprintf (stream, ",");
1305 /* Target hook for assembling integer objects. Use mmix_print_operand
1306 for WYDE and TETRA. Use mmix_output_octa to output 8-byte
1310 mmix_assemble_integer (rtx x, unsigned int size, int aligned_p)
1315 /* We handle a limited number of types of operands in here. But
1316 that's ok, because we can punt to generic functions. We then
1317 pretend that aligned data isn't needed, so the usual .<pseudo>
1318 syntax is used (which works for aligned data too). We actually
1319 *must* do that, since we say we don't have simple aligned
1320 pseudos, causing this function to be called. We just try and
1321 keep as much compatibility as possible with mmixal syntax for
1322 normal cases (i.e. without GNU extensions and C only). */
1324 if (GET_CODE (x) != CONST_INT)
1329 fputs ("\tBYTE\t", asm_out_file);
1330 mmix_print_operand (asm_out_file, x, 'B');
1331 fputc ('\n', asm_out_file);
1335 if (GET_CODE (x) != CONST_INT)
1340 fputs ("\tWYDE\t", asm_out_file);
1341 mmix_print_operand (asm_out_file, x, 'W');
1342 fputc ('\n', asm_out_file);
1346 if (GET_CODE (x) != CONST_INT)
1351 fputs ("\tTETRA\t", asm_out_file);
1352 mmix_print_operand (asm_out_file, x, 'L');
1353 fputc ('\n', asm_out_file);
1357 /* We don't get here anymore for CONST_DOUBLE, because DImode
1358 isn't expressed as CONST_DOUBLE, and DFmode is handled
1360 gcc_assert (GET_CODE (x) != CONST_DOUBLE);
1361 assemble_integer_with_op ("\tOCTA\t", x);
1364 return default_assemble_integer (x, size, aligned_p);
1367 /* ASM_OUTPUT_ASCII. */
1370 mmix_asm_output_ascii (FILE *stream, const char *string, int length)
1374 int chunk_size = length > 60 ? 60 : length;
1375 fprintf (stream, "\tBYTE ");
1376 mmix_output_quoted_string (stream, string, chunk_size);
1377 string += chunk_size;
1378 length -= chunk_size;
1379 fprintf (stream, "\n");
1383 /* ASM_OUTPUT_ALIGNED_COMMON. */
1386 mmix_asm_output_aligned_common (FILE *stream,
1391 /* This is mostly the elfos.h one. There doesn't seem to be a way to
1392 express this in a mmixal-compatible way. */
1393 fprintf (stream, "\t.comm\t");
1394 assemble_name (stream, name);
1395 fprintf (stream, ",%u,%u ! mmixal-incompatible COMMON\n",
1396 size, align / BITS_PER_UNIT);
1399 /* ASM_OUTPUT_ALIGNED_LOCAL. */
1402 mmix_asm_output_aligned_local (FILE *stream,
1407 switch_to_section (data_section);
1409 ASM_OUTPUT_ALIGN (stream, exact_log2 (align/BITS_PER_UNIT));
1410 assemble_name (stream, name);
1411 fprintf (stream, "\tLOC @+%d\n", size);
1414 /* ASM_OUTPUT_LABEL. */
1417 mmix_asm_output_label (FILE *stream, const char *name)
1419 assemble_name (stream, name);
1420 fprintf (stream, "\tIS @\n");
1423 /* ASM_OUTPUT_INTERNAL_LABEL. */
1426 mmix_asm_output_internal_label (FILE *stream, const char *name)
1428 assemble_name_raw (stream, name);
1429 fprintf (stream, "\tIS @\n");
1432 /* ASM_DECLARE_REGISTER_GLOBAL. */
1435 mmix_asm_declare_register_global (FILE *stream ATTRIBUTE_UNUSED,
1436 tree decl ATTRIBUTE_UNUSED,
1437 int regno ATTRIBUTE_UNUSED,
1438 const char *name ATTRIBUTE_UNUSED)
1440 /* Nothing to do here, but there *will* be, therefore the framework is
1444 /* ASM_WEAKEN_LABEL. */
1447 mmix_asm_weaken_label (FILE *stream ATTRIBUTE_UNUSED,
1448 const char *name ATTRIBUTE_UNUSED)
1450 fprintf (stream, "\t.weak ");
1451 assemble_name (stream, name);
1452 fprintf (stream, " ! mmixal-incompatible\n");
1455 /* MAKE_DECL_ONE_ONLY. */
1458 mmix_make_decl_one_only (tree decl)
1460 DECL_WEAK (decl) = 1;
1463 /* ASM_OUTPUT_LABELREF.
1464 Strip GCC's '*' and our own '@'. No order is assumed. */
1467 mmix_asm_output_labelref (FILE *stream, const char *name)
1471 for (; (*name == '@' || *name == '*'); name++)
1475 asm_fprintf (stream, "%s%U%s",
1476 is_extern && TARGET_TOPLEVEL_SYMBOLS ? ":" : "",
1480 /* ASM_OUTPUT_DEF. */
1483 mmix_asm_output_def (FILE *stream, const char *name, const char *value)
1485 assemble_name (stream, name);
1486 fprintf (stream, "\tIS ");
1487 assemble_name (stream, value);
1488 fputc ('\n', stream);
1491 /* PRINT_OPERAND. */
1494 mmix_print_operand (FILE *stream, rtx x, int code)
1496 /* When we add support for different codes later, we can, when needed,
1497 drop through to the main handler with a modified operand. */
1499 int regno = x != NULL_RTX && REG_P (x) ? REGNO (x) : 0;
1503 /* Unrelated codes are in alphabetic order. */
1506 /* For conditional branches, output "P" for a probable branch. */
1507 if (TARGET_BRANCH_PREDICT)
1509 x = find_reg_note (current_output_insn, REG_BR_PROB, 0);
1510 if (x && INTVAL (XEXP (x, 0)) > REG_BR_PROB_BASE / 2)
1516 /* For the %d in POP %d,0. */
1517 fprintf (stream, "%d", MMIX_POP_ARGUMENT ());
1521 if (GET_CODE (x) != CONST_INT)
1522 fatal_insn ("MMIX Internal: Expected a CONST_INT, not this", x);
1523 fprintf (stream, "%d", (int) (INTVAL (x) & 0xff));
1527 /* Highpart. Must be general register, and not the last one, as
1528 that one cannot be part of a consecutive register pair. */
1529 if (regno > MMIX_LAST_GENERAL_REGISTER - 1)
1530 internal_error ("MMIX Internal: Bad register: %d", regno);
1532 /* This is big-endian, so the high-part is the first one. */
1533 fprintf (stream, "%s", reg_names[MMIX_OUTPUT_REGNO (regno)]);
1537 /* Lowpart. Must be CONST_INT or general register, and not the last
1538 one, as that one cannot be part of a consecutive register pair. */
1539 if (GET_CODE (x) == CONST_INT)
1541 fprintf (stream, "#%lx",
1542 (unsigned long) (INTVAL (x)
1543 & ((unsigned int) 0x7fffffff * 2 + 1)));
1547 if (GET_CODE (x) == SYMBOL_REF)
1549 output_addr_const (stream, x);
1553 if (regno > MMIX_LAST_GENERAL_REGISTER - 1)
1554 internal_error ("MMIX Internal: Bad register: %d", regno);
1556 /* This is big-endian, so the low-part is + 1. */
1557 fprintf (stream, "%s", reg_names[MMIX_OUTPUT_REGNO (regno) + 1]);
1560 /* Can't use 'a' because that's a generic modifier for address
1563 mmix_output_shiftvalue_op_from_str (stream, "ANDN",
1564 ~(unsigned HOST_WIDEST_INT)
1569 mmix_output_shiftvalue_op_from_str (stream, "INC",
1570 (unsigned HOST_WIDEST_INT)
1575 mmix_output_shiftvalue_op_from_str (stream, "OR",
1576 (unsigned HOST_WIDEST_INT)
1581 mmix_output_shiftvalue_op_from_str (stream, "SET",
1582 (unsigned HOST_WIDEST_INT)
1588 mmix_output_condition (stream, x, (code == 'D'));
1592 /* Output an extra "e" to make fcmpe, fune. */
1593 if (TARGET_FCMP_EPSILON)
1594 fprintf (stream, "e");
1598 /* Output the number minus 1. */
1599 if (GET_CODE (x) != CONST_INT)
1601 fatal_insn ("MMIX Internal: Bad value for 'm', not a CONST_INT",
1604 fprintf (stream, HOST_WIDEST_INT_PRINT_DEC,
1605 (HOST_WIDEST_INT) (mmix_intval (x) - 1));
1609 /* Store the number of registers we want to save. This was setup
1610 by the prologue. The actual operand contains the number of
1611 registers to pass, but we don't use it currently. Anyway, we
1612 need to output the number of saved registers here. */
1613 fprintf (stream, "%d",
1614 cfun->machine->highest_saved_stack_register + 1);
1618 /* Store the register to output a constant to. */
1620 fatal_insn ("MMIX Internal: Expected a register, not this", x);
1621 mmix_output_destination_register = MMIX_OUTPUT_REGNO (regno);
1625 /* Output the constant. Note that we use this for floats as well. */
1626 if (GET_CODE (x) != CONST_INT
1627 && (GET_CODE (x) != CONST_DOUBLE
1628 || (GET_MODE (x) != VOIDmode && GET_MODE (x) != DFmode
1629 && GET_MODE (x) != SFmode)))
1630 fatal_insn ("MMIX Internal: Expected a constant, not this", x);
1631 mmix_output_register_setting (stream,
1632 mmix_output_destination_register,
1633 mmix_intval (x), 0);
1637 /* An U for unsigned, if TARGET_ZERO_EXTEND. Ignore the operand. */
1638 if (TARGET_ZERO_EXTEND)
1643 mmix_output_shifted_value (stream, (HOST_WIDEST_INT) mmix_intval (x));
1647 mmix_output_shifted_value (stream, (HOST_WIDEST_INT) ~mmix_intval (x));
1651 if (GET_CODE (x) != CONST_INT)
1652 fatal_insn ("MMIX Internal: Expected a CONST_INT, not this", x);
1653 fprintf (stream, "#%x", (int) (INTVAL (x) & 0xffff));
1657 /* Nothing to do. */
1661 /* Presumably there's a missing case above if we get here. */
1662 internal_error ("MMIX Internal: Missing %qc case in mmix_print_operand", code);
1665 switch (GET_CODE (modified_x))
1668 regno = REGNO (modified_x);
1669 if (regno >= FIRST_PSEUDO_REGISTER)
1670 internal_error ("MMIX Internal: Bad register: %d", regno);
1671 fprintf (stream, "%s", reg_names[MMIX_OUTPUT_REGNO (regno)]);
1675 output_address (XEXP (modified_x, 0));
1679 /* For -2147483648, mmixal complains that the constant does not fit
1680 in 4 bytes, so let's output it as hex. Take care to handle hosts
1681 where HOST_WIDE_INT is longer than an int.
1683 Print small constants +-255 using decimal. */
1685 if (INTVAL (modified_x) > -256 && INTVAL (modified_x) < 256)
1686 fprintf (stream, "%d", (int) (INTVAL (modified_x)));
1688 fprintf (stream, "#%x",
1689 (int) (INTVAL (modified_x)) & (unsigned int) ~0);
1693 /* Do somewhat as CONST_INT. */
1694 mmix_output_octa (stream, mmix_intval (modified_x), 0);
1698 output_addr_const (stream, modified_x);
1702 /* No need to test for all strange things. Let output_addr_const do
1704 if (CONSTANT_P (modified_x)
1705 /* Strangely enough, this is not included in CONSTANT_P.
1706 FIXME: Ask/check about sanity here. */
1707 || GET_CODE (modified_x) == CODE_LABEL)
1709 output_addr_const (stream, modified_x);
1713 /* We need the original here. */
1714 fatal_insn ("MMIX Internal: Cannot decode this operand", x);
1718 /* PRINT_OPERAND_PUNCT_VALID_P. */
1721 mmix_print_operand_punct_valid_p (int code ATTRIBUTE_UNUSED)
1723 /* A '+' is used for branch prediction, similar to other ports. */
1725 /* A '.' is used for the %d in the POP %d,0 return insn. */
1729 /* PRINT_OPERAND_ADDRESS. */
1732 mmix_print_operand_address (FILE *stream, rtx x)
1736 /* I find the generated assembly code harder to read without
1738 fprintf (stream, "%s,0", reg_names[MMIX_OUTPUT_REGNO (REGNO (x))]);
1741 else if (GET_CODE (x) == PLUS)
1743 rtx x1 = XEXP (x, 0);
1744 rtx x2 = XEXP (x, 1);
1748 fprintf (stream, "%s,", reg_names[MMIX_OUTPUT_REGNO (REGNO (x1))]);
1752 fprintf (stream, "%s",
1753 reg_names[MMIX_OUTPUT_REGNO (REGNO (x2))]);
1756 else if (GET_CODE (x2) == CONST_INT
1757 && CONST_OK_FOR_LETTER_P (INTVAL (x2), 'I'))
1759 output_addr_const (stream, x2);
1765 if (TARGET_BASE_ADDRESSES && mmix_legitimate_constant_p (x))
1767 output_addr_const (stream, x);
1771 fatal_insn ("MMIX Internal: This is not a recognized address", x);
1774 /* ASM_OUTPUT_REG_PUSH. */
1777 mmix_asm_output_reg_push (FILE *stream, int regno)
1779 fprintf (stream, "\tSUBU %s,%s,8\n\tSTOU %s,%s,0\n",
1780 reg_names[MMIX_STACK_POINTER_REGNUM],
1781 reg_names[MMIX_STACK_POINTER_REGNUM],
1782 reg_names[MMIX_OUTPUT_REGNO (regno)],
1783 reg_names[MMIX_STACK_POINTER_REGNUM]);
1786 /* ASM_OUTPUT_REG_POP. */
1789 mmix_asm_output_reg_pop (FILE *stream, int regno)
1791 fprintf (stream, "\tLDOU %s,%s,0\n\tINCL %s,8\n",
1792 reg_names[MMIX_OUTPUT_REGNO (regno)],
1793 reg_names[MMIX_STACK_POINTER_REGNUM],
1794 reg_names[MMIX_STACK_POINTER_REGNUM]);
1797 /* ASM_OUTPUT_ADDR_DIFF_ELT. */
1800 mmix_asm_output_addr_diff_elt (FILE *stream,
1801 rtx body ATTRIBUTE_UNUSED,
1805 fprintf (stream, "\tTETRA L%d-L%d\n", value, rel);
1808 /* ASM_OUTPUT_ADDR_VEC_ELT. */
1811 mmix_asm_output_addr_vec_elt (FILE *stream, int value)
1813 fprintf (stream, "\tOCTA L:%d\n", value);
1816 /* ASM_OUTPUT_SKIP. */
1819 mmix_asm_output_skip (FILE *stream, int nbytes)
1821 fprintf (stream, "\tLOC @+%d\n", nbytes);
1824 /* ASM_OUTPUT_ALIGN. */
1827 mmix_asm_output_align (FILE *stream, int power)
1829 /* We need to record the needed alignment of this section in the object,
1830 so we have to output an alignment directive. Use a .p2align (not
1831 .align) so people will never have to wonder about whether the
1832 argument is in number of bytes or the log2 thereof. We do it in
1833 addition to the LOC directive, so nothing needs tweaking when
1834 copy-pasting assembly into mmixal. */
1835 fprintf (stream, "\t.p2align %d\n", power);
1836 fprintf (stream, "\tLOC @+(%d-@)&%d\n", 1 << power, (1 << power) - 1);
1839 /* DBX_REGISTER_NUMBER. */
1842 mmix_dbx_register_number (int regno)
1844 /* Adjust the register number to the one it will be output as, dammit.
1845 It'd be nice if we could check the assumption that we're filling a
1846 gap, but every register between the last saved register and parameter
1847 registers might be a valid parameter register. */
1848 regno = MMIX_OUTPUT_REGNO (regno);
1850 /* We need to renumber registers to get the number of the return address
1851 register in the range 0..255. It is also space-saving if registers
1852 mentioned in the call-frame information (which uses this function by
1853 defaulting DWARF_FRAME_REGNUM to DBX_REGISTER_NUMBER) are numbered
1854 0 .. 63. So map 224 .. 256+15 -> 0 .. 47 and 0 .. 223 -> 48..223+48. */
1855 return regno >= 224 ? (regno - 224) : (regno + 48);
1858 /* End of target macro support functions.
1860 Now the MMIX port's own functions. First the exported ones. */
1862 /* Wrapper for get_hard_reg_initial_val since integrate.h isn't included
1863 from insn-emit.c. */
1866 mmix_get_hard_reg_initial_val (enum machine_mode mode, int regno)
1868 return get_hard_reg_initial_val (mode, regno);
1871 /* Nonzero when the function epilogue is simple enough that a single
1872 "POP %d,0" should be used even within the function. */
1875 mmix_use_simple_return (void)
1879 int stack_space_to_allocate
1880 = (crtl->outgoing_args_size
1881 + crtl->args.pretend_args_size
1882 + get_frame_size () + 7) & ~7;
1884 if (!TARGET_USE_RETURN_INSN || !reload_completed)
1888 regno >= MMIX_FIRST_GLOBAL_REGNUM;
1890 /* Note that we assume that the frame-pointer-register is one of these
1891 registers, in which case we don't count it here. */
1892 if ((((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
1893 && df_regs_ever_live_p (regno) && !call_used_regs[regno]))
1894 || IS_MMIX_EH_RETURN_DATA_REG (regno))
1897 if (frame_pointer_needed)
1898 stack_space_to_allocate += 8;
1900 if (MMIX_CFUN_HAS_LANDING_PAD)
1901 stack_space_to_allocate += 16;
1902 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
1903 stack_space_to_allocate += 8;
1905 return stack_space_to_allocate == 0;
1909 /* Expands the function prologue into RTX. */
1912 mmix_expand_prologue (void)
1914 HOST_WIDE_INT locals_size = get_frame_size ();
1916 HOST_WIDE_INT stack_space_to_allocate
1917 = (crtl->outgoing_args_size
1918 + crtl->args.pretend_args_size
1919 + locals_size + 7) & ~7;
1920 HOST_WIDE_INT offset = -8;
1922 /* Add room needed to save global non-register-stack registers. */
1924 regno >= MMIX_FIRST_GLOBAL_REGNUM;
1926 /* Note that we assume that the frame-pointer-register is one of these
1927 registers, in which case we don't count it here. */
1928 if ((((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
1929 && df_regs_ever_live_p (regno) && !call_used_regs[regno]))
1930 || IS_MMIX_EH_RETURN_DATA_REG (regno))
1931 stack_space_to_allocate += 8;
1933 /* If we do have a frame-pointer, add room for it. */
1934 if (frame_pointer_needed)
1935 stack_space_to_allocate += 8;
1937 /* If we have a non-local label, we need to be able to unwind to it, so
1938 store the current register stack pointer. Also store the return
1939 address if we do that. */
1940 if (MMIX_CFUN_HAS_LANDING_PAD)
1941 stack_space_to_allocate += 16;
1942 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
1943 /* If we do have a saved return-address slot, add room for it. */
1944 stack_space_to_allocate += 8;
1946 /* Make sure we don't get an unaligned stack. */
1947 if ((stack_space_to_allocate % 8) != 0)
1948 internal_error ("stack frame not a multiple of 8 bytes: %wd",
1949 stack_space_to_allocate);
1951 if (crtl->args.pretend_args_size)
1953 int mmix_first_vararg_reg
1954 = (MMIX_FIRST_INCOMING_ARG_REGNUM
1955 + (MMIX_MAX_ARGS_IN_REGS
1956 - crtl->args.pretend_args_size / 8));
1959 = MMIX_FIRST_INCOMING_ARG_REGNUM + MMIX_MAX_ARGS_IN_REGS - 1;
1960 regno >= mmix_first_vararg_reg;
1965 HOST_WIDE_INT stack_chunk
1966 = stack_space_to_allocate > (256 - 8)
1967 ? (256 - 8) : stack_space_to_allocate;
1969 mmix_emit_sp_add (-stack_chunk);
1970 offset += stack_chunk;
1971 stack_space_to_allocate -= stack_chunk;
1974 /* These registers aren't actually saved (as in "will be
1975 restored"), so don't tell DWARF2 they're saved. */
1976 emit_move_insn (gen_rtx_MEM (DImode,
1977 plus_constant (stack_pointer_rtx,
1979 gen_rtx_REG (DImode, regno));
1984 /* Store the frame-pointer. */
1986 if (frame_pointer_needed)
1992 /* Get 8 less than otherwise, since we need to reach offset + 8. */
1993 HOST_WIDE_INT stack_chunk
1994 = stack_space_to_allocate > (256 - 8 - 8)
1995 ? (256 - 8 - 8) : stack_space_to_allocate;
1997 mmix_emit_sp_add (-stack_chunk);
1999 offset += stack_chunk;
2000 stack_space_to_allocate -= stack_chunk;
2003 insn = emit_move_insn (gen_rtx_MEM (DImode,
2004 plus_constant (stack_pointer_rtx,
2006 hard_frame_pointer_rtx);
2007 RTX_FRAME_RELATED_P (insn) = 1;
2008 insn = emit_insn (gen_adddi3 (hard_frame_pointer_rtx,
2010 GEN_INT (offset + 8)));
2011 RTX_FRAME_RELATED_P (insn) = 1;
2015 if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
2020 /* Store the return-address, if one is needed on the stack. We
2021 usually store it in a register when needed, but that doesn't work
2022 with -fexceptions. */
2026 /* Get 8 less than otherwise, since we need to reach offset + 8. */
2027 HOST_WIDE_INT stack_chunk
2028 = stack_space_to_allocate > (256 - 8 - 8)
2029 ? (256 - 8 - 8) : stack_space_to_allocate;
2031 mmix_emit_sp_add (-stack_chunk);
2033 offset += stack_chunk;
2034 stack_space_to_allocate -= stack_chunk;
2037 tmpreg = gen_rtx_REG (DImode, 255);
2038 retreg = gen_rtx_REG (DImode, MMIX_rJ_REGNUM);
2040 /* Dwarf2 code is confused by the use of a temporary register for
2041 storing the return address, so we have to express it as a note,
2042 which we attach to the actual store insn. */
2043 emit_move_insn (tmpreg, retreg);
2045 insn = emit_move_insn (gen_rtx_MEM (DImode,
2046 plus_constant (stack_pointer_rtx,
2049 RTX_FRAME_RELATED_P (insn) = 1;
2051 = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
2052 gen_rtx_SET (VOIDmode,
2053 gen_rtx_MEM (DImode,
2054 plus_constant (stack_pointer_rtx,
2061 else if (MMIX_CFUN_HAS_LANDING_PAD)
2064 if (MMIX_CFUN_HAS_LANDING_PAD)
2066 /* Store the register defining the numbering of local registers, so
2067 we know how long to unwind the register stack. */
2071 /* Get 8 less than otherwise, since we need to reach offset + 8. */
2072 HOST_WIDE_INT stack_chunk
2073 = stack_space_to_allocate > (256 - 8 - 8)
2074 ? (256 - 8 - 8) : stack_space_to_allocate;
2076 mmix_emit_sp_add (-stack_chunk);
2078 offset += stack_chunk;
2079 stack_space_to_allocate -= stack_chunk;
2082 /* We don't tell dwarf2 about this one; we just have it to unwind
2083 the register stack at landing pads. FIXME: It's a kludge because
2084 we can't describe the effect of the PUSHJ and PUSHGO insns on the
2085 register stack at the moment. Best thing would be to handle it
2086 like stack-pointer offsets. Better: some hook into dwarf2out.c
2087 to produce DW_CFA_expression:s that specify the increment of rO,
2088 and unwind it at eh_return (preferred) or at the landing pad.
2089 Then saves to $0..$G-1 could be specified through that register. */
2091 emit_move_insn (gen_rtx_REG (DImode, 255),
2092 gen_rtx_REG (DImode,
2094 emit_move_insn (gen_rtx_MEM (DImode,
2095 plus_constant (stack_pointer_rtx, offset)),
2096 gen_rtx_REG (DImode, 255));
2100 /* After the return-address and the frame-pointer, we have the local
2101 variables. They're the ones that may have an "unaligned" size. */
2102 offset -= (locals_size + 7) & ~7;
2104 /* Now store all registers that are global, i.e. not saved by the
2105 register file machinery.
2107 It is assumed that the frame-pointer is one of these registers, so it
2108 is explicitly excluded in the count. */
2111 regno >= MMIX_FIRST_GLOBAL_REGNUM;
2113 if (((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
2114 && df_regs_ever_live_p (regno) && ! call_used_regs[regno])
2115 || IS_MMIX_EH_RETURN_DATA_REG (regno))
2121 HOST_WIDE_INT stack_chunk
2122 = (stack_space_to_allocate > (256 - offset - 8)
2123 ? (256 - offset - 8) : stack_space_to_allocate);
2125 mmix_emit_sp_add (-stack_chunk);
2126 offset += stack_chunk;
2127 stack_space_to_allocate -= stack_chunk;
2130 insn = emit_move_insn (gen_rtx_MEM (DImode,
2131 plus_constant (stack_pointer_rtx,
2133 gen_rtx_REG (DImode, regno));
2134 RTX_FRAME_RELATED_P (insn) = 1;
2138 /* Finally, allocate room for outgoing args and local vars if room
2139 wasn't allocated above. */
2140 if (stack_space_to_allocate)
2141 mmix_emit_sp_add (-stack_space_to_allocate);
2144 /* Expands the function epilogue into RTX. */
2147 mmix_expand_epilogue (void)
2149 HOST_WIDE_INT locals_size = get_frame_size ();
2151 HOST_WIDE_INT stack_space_to_deallocate
2152 = (crtl->outgoing_args_size
2153 + crtl->args.pretend_args_size
2154 + locals_size + 7) & ~7;
2156 /* The first address to access is beyond the outgoing_args area. */
2157 HOST_WIDE_INT offset = crtl->outgoing_args_size;
2159 /* Add the space for global non-register-stack registers.
2160 It is assumed that the frame-pointer register can be one of these
2161 registers, in which case it is excluded from the count when needed. */
2163 regno >= MMIX_FIRST_GLOBAL_REGNUM;
2165 if (((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
2166 && df_regs_ever_live_p (regno) && !call_used_regs[regno])
2167 || IS_MMIX_EH_RETURN_DATA_REG (regno))
2168 stack_space_to_deallocate += 8;
2170 /* Add in the space for register stack-pointer. If so, always add room
2171 for the saved PC. */
2172 if (MMIX_CFUN_HAS_LANDING_PAD)
2173 stack_space_to_deallocate += 16;
2174 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
2175 /* If we have a saved return-address slot, add it in. */
2176 stack_space_to_deallocate += 8;
2178 /* Add in the frame-pointer. */
2179 if (frame_pointer_needed)
2180 stack_space_to_deallocate += 8;
2182 /* Make sure we don't get an unaligned stack. */
2183 if ((stack_space_to_deallocate % 8) != 0)
2184 internal_error ("stack frame not a multiple of octabyte: %wd",
2185 stack_space_to_deallocate);
2187 /* We will add back small offsets to the stack pointer as we go.
2188 First, we restore all registers that are global, i.e. not saved by
2189 the register file machinery. */
2191 for (regno = MMIX_FIRST_GLOBAL_REGNUM;
2194 if (((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
2195 && df_regs_ever_live_p (regno) && !call_used_regs[regno])
2196 || IS_MMIX_EH_RETURN_DATA_REG (regno))
2200 mmix_emit_sp_add (offset);
2201 stack_space_to_deallocate -= offset;
2205 emit_move_insn (gen_rtx_REG (DImode, regno),
2206 gen_rtx_MEM (DImode,
2207 plus_constant (stack_pointer_rtx,
2212 /* Here is where the local variables were. As in the prologue, they
2213 might be of an unaligned size. */
2214 offset += (locals_size + 7) & ~7;
2216 /* The saved register stack pointer is just below the frame-pointer
2217 register. We don't need to restore it "manually"; the POP
2218 instruction does that. */
2219 if (MMIX_CFUN_HAS_LANDING_PAD)
2221 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
2222 /* The return-address slot is just below the frame-pointer register.
2223 We don't need to restore it because we don't really use it. */
2226 /* Get back the old frame-pointer-value. */
2227 if (frame_pointer_needed)
2231 mmix_emit_sp_add (offset);
2233 stack_space_to_deallocate -= offset;
2237 emit_move_insn (hard_frame_pointer_rtx,
2238 gen_rtx_MEM (DImode,
2239 plus_constant (stack_pointer_rtx,
2244 /* We do not need to restore pretended incoming args, just add back
2246 if (stack_space_to_deallocate != 0)
2247 mmix_emit_sp_add (stack_space_to_deallocate);
2249 if (crtl->calls_eh_return)
2250 /* Adjust the (normal) stack-pointer to that of the receiver.
2251 FIXME: It would be nice if we could also adjust the register stack
2252 here, but we need to express it through DWARF 2 too. */
2253 emit_insn (gen_adddi3 (stack_pointer_rtx, stack_pointer_rtx,
2254 gen_rtx_REG (DImode,
2255 MMIX_EH_RETURN_STACKADJ_REGNUM)));
2258 /* Output an optimal sequence for setting a register to a specific
2259 constant. Used in an alternative for const_ints in movdi, and when
2260 using large stack-frame offsets.
2262 Use do_begin_end to say if a line-starting TAB and newline before the
2263 first insn and after the last insn is wanted. */
2266 mmix_output_register_setting (FILE *stream,
2268 HOST_WIDEST_INT value,
2272 fprintf (stream, "\t");
2274 if (mmix_shiftable_wyde_value ((unsigned HOST_WIDEST_INT) value))
2276 /* First, the one-insn cases. */
2277 mmix_output_shiftvalue_op_from_str (stream, "SET",
2278 (unsigned HOST_WIDEST_INT)
2280 fprintf (stream, " %s,", reg_names[regno]);
2281 mmix_output_shifted_value (stream, (unsigned HOST_WIDEST_INT) value);
2283 else if (mmix_shiftable_wyde_value (-(unsigned HOST_WIDEST_INT) value))
2285 /* We do this to get a bit more legible assembly code. The next
2286 alternative is mostly redundant with this. */
2288 mmix_output_shiftvalue_op_from_str (stream, "SET",
2289 -(unsigned HOST_WIDEST_INT)
2291 fprintf (stream, " %s,", reg_names[regno]);
2292 mmix_output_shifted_value (stream, -(unsigned HOST_WIDEST_INT) value);
2293 fprintf (stream, "\n\tNEGU %s,0,%s", reg_names[regno],
2296 else if (mmix_shiftable_wyde_value (~(unsigned HOST_WIDEST_INT) value))
2298 /* Slightly more expensive, the two-insn cases. */
2300 /* FIXME: We could of course also test if 0..255-N or ~(N | 1..255)
2301 is shiftable, or any other one-insn transformation of the value.
2302 FIXME: Check first if the value is "shiftable" by two loading
2303 with two insns, since it makes more readable assembly code (if
2304 anyone else cares). */
2306 mmix_output_shiftvalue_op_from_str (stream, "SET",
2307 ~(unsigned HOST_WIDEST_INT)
2309 fprintf (stream, " %s,", reg_names[regno]);
2310 mmix_output_shifted_value (stream, ~(unsigned HOST_WIDEST_INT) value);
2311 fprintf (stream, "\n\tNOR %s,%s,0", reg_names[regno],
2316 /* The generic case. 2..4 insns. */
2317 static const char *const higher_parts[] = {"L", "ML", "MH", "H"};
2318 const char *op = "SET";
2319 const char *line_begin = "";
2322 HOST_WIDEST_INT tmpvalue = value;
2324 /* Compute the number of insns needed to output this constant. */
2325 for (i = 0; i < 4 && tmpvalue != 0; i++)
2327 if (tmpvalue & 65535)
2331 if (TARGET_BASE_ADDRESSES && insns == 3)
2333 /* The number three is based on a static observation on
2334 ghostscript-6.52. Two and four are excluded because there
2335 are too many such constants, and each unique constant (maybe
2336 offset by 1..255) were used few times compared to other uses,
2339 We use base-plus-offset addressing to force it into a global
2340 register; we just use a "LDA reg,VALUE", which will cause the
2341 assembler and linker to DTRT (for constants as well as
2343 fprintf (stream, "LDA %s,", reg_names[regno]);
2344 mmix_output_octa (stream, value, 0);
2348 /* Output pertinent parts of the 4-wyde sequence.
2349 Still more to do if we want this to be optimal, but hey...
2350 Note that the zero case has been handled above. */
2351 for (i = 0; i < 4 && value != 0; i++)
2355 fprintf (stream, "%s%s%s %s,#%x", line_begin, op,
2356 higher_parts[i], reg_names[regno],
2357 (int) (value & 65535));
2358 /* The first one sets the rest of the bits to 0, the next
2359 ones add set bits. */
2361 line_begin = "\n\t";
2370 fprintf (stream, "\n");
2373 /* Return 1 if value is 0..65535*2**(16*N) for N=0..3.
2377 mmix_shiftable_wyde_value (unsigned HOST_WIDEST_INT value)
2379 /* Shift by 16 bits per group, stop when we've found two groups with
2382 int has_candidate = 0;
2384 for (i = 0; i < 4; i++)
2400 /* X and Y are two things to compare using CODE. Return the rtx for
2401 the cc-reg in the proper mode. */
2404 mmix_gen_compare_reg (RTX_CODE code, rtx x, rtx y)
2406 enum machine_mode ccmode = SELECT_CC_MODE (code, x, y);
2407 return gen_reg_rtx (ccmode);
2410 /* Local (static) helper functions. */
2413 mmix_emit_sp_add (HOST_WIDE_INT offset)
2419 /* Negative stack-pointer adjustments are allocations and appear in
2420 the prologue only. We mark them as frame-related so unwind and
2421 debug info is properly emitted for them. */
2423 insn = emit_insn (gen_adddi3 (stack_pointer_rtx,
2428 rtx tmpr = gen_rtx_REG (DImode, 255);
2429 RTX_FRAME_RELATED_P (emit_move_insn (tmpr, GEN_INT (offset))) = 1;
2430 insn = emit_insn (gen_adddi3 (stack_pointer_rtx,
2431 stack_pointer_rtx, tmpr));
2433 RTX_FRAME_RELATED_P (insn) = 1;
2437 /* Positive adjustments are in the epilogue only. Don't mark them
2438 as "frame-related" for unwind info. */
2439 if (CONST_OK_FOR_LETTER_P (offset, 'L'))
2440 emit_insn (gen_adddi3 (stack_pointer_rtx,
2445 rtx tmpr = gen_rtx_REG (DImode, 255);
2446 emit_move_insn (tmpr, GEN_INT (offset));
2447 insn = emit_insn (gen_adddi3 (stack_pointer_rtx,
2448 stack_pointer_rtx, tmpr));
2453 /* Print operator suitable for doing something with a shiftable
2454 wyde. The type of operator is passed as an asm output modifier. */
2457 mmix_output_shiftvalue_op_from_str (FILE *stream,
2459 HOST_WIDEST_INT value)
2461 static const char *const op_part[] = {"L", "ML", "MH", "H"};
2464 if (! mmix_shiftable_wyde_value (value))
2466 char s[sizeof ("0xffffffffffffffff")];
2467 sprintf (s, HOST_WIDEST_INT_PRINT_HEX, value);
2468 internal_error ("MMIX Internal: %s is not a shiftable int", s);
2471 for (i = 0; i < 4; i++)
2473 /* We know we're through when we find one-bits in the low
2477 fprintf (stream, "%s%s", mainop, op_part[i]);
2483 /* No bits set? Then it must have been zero. */
2484 fprintf (stream, "%sL", mainop);
2487 /* Print a 64-bit value, optionally prefixed by assembly pseudo. */
2490 mmix_output_octa (FILE *stream, HOST_WIDEST_INT value, int do_begin_end)
2492 /* Snipped from final.c:output_addr_const. We need to avoid the
2493 presumed universal "0x" prefix. We can do it by replacing "0x" with
2494 "#0" here; we must avoid a space in the operands and no, the zero
2495 won't cause the number to be assumed in octal format. */
2496 char hex_format[sizeof (HOST_WIDEST_INT_PRINT_HEX)];
2499 fprintf (stream, "\tOCTA ");
2501 strcpy (hex_format, HOST_WIDEST_INT_PRINT_HEX);
2502 hex_format[0] = '#';
2503 hex_format[1] = '0';
2505 /* Provide a few alternative output formats depending on the number, to
2506 improve legibility of assembler output. */
2507 if ((value < (HOST_WIDEST_INT) 0 && value > (HOST_WIDEST_INT) -10000)
2508 || (value >= (HOST_WIDEST_INT) 0 && value <= (HOST_WIDEST_INT) 16384))
2509 fprintf (stream, "%d", (int) value);
2510 else if (value > (HOST_WIDEST_INT) 0
2511 && value < ((HOST_WIDEST_INT) 1 << 31) * 2)
2512 fprintf (stream, "#%x", (unsigned int) value);
2514 fprintf (stream, hex_format, value);
2517 fprintf (stream, "\n");
2520 /* Print the presumed shiftable wyde argument shifted into place (to
2521 be output with an operand). */
2524 mmix_output_shifted_value (FILE *stream, HOST_WIDEST_INT value)
2528 if (! mmix_shiftable_wyde_value (value))
2531 sprintf (s, HOST_WIDEST_INT_PRINT_HEX, value);
2532 internal_error ("MMIX Internal: %s is not a shiftable int", s);
2535 for (i = 0; i < 4; i++)
2537 /* We know we're through when we find one-bits in the low 16 bits. */
2540 fprintf (stream, "#%x", (int) (value & 0xffff));
2547 /* No bits set? Then it must have been zero. */
2548 fprintf (stream, "0");
2551 /* Output an MMIX condition name corresponding to an operator
2553 (comparison_operator [(comparison_operator ...) (const_int 0)])
2554 which means we have to look at *two* operators.
2556 The argument "reversed" refers to reversal of the condition (not the
2557 same as swapping the arguments). */
2560 mmix_output_condition (FILE *stream, rtx x, int reversed)
2566 /* The normal output cc-code. */
2567 const char *const normal;
2569 /* The reversed cc-code, or NULL if invalid. */
2570 const char *const reversed;
2575 enum machine_mode cc_mode;
2577 /* Terminated with {UNKNOWN, NULL, NULL} */
2578 const struct cc_conv *const convs;
2582 #define CCEND {UNKNOWN, NULL, NULL}
2584 static const struct cc_conv cc_fun_convs[]
2585 = {{ORDERED, "Z", "P"},
2586 {UNORDERED, "P", "Z"},
2588 static const struct cc_conv cc_fp_convs[]
2592 static const struct cc_conv cc_fpeq_convs[]
2596 static const struct cc_conv cc_uns_convs[]
2597 = {{GEU, "NN", "N"},
2602 static const struct cc_conv cc_signed_convs[]
2610 static const struct cc_conv cc_di_convs[]
2622 static const struct cc_type_conv cc_convs[]
2623 = {{CC_FUNmode, cc_fun_convs},
2624 {CC_FPmode, cc_fp_convs},
2625 {CC_FPEQmode, cc_fpeq_convs},
2626 {CC_UNSmode, cc_uns_convs},
2627 {CCmode, cc_signed_convs},
2628 {DImode, cc_di_convs}};
2633 enum machine_mode mode = GET_MODE (XEXP (x, 0));
2634 RTX_CODE cc = GET_CODE (x);
2636 for (i = 0; i < ARRAY_SIZE (cc_convs); i++)
2638 if (mode == cc_convs[i].cc_mode)
2640 for (j = 0; cc_convs[i].convs[j].cc != UNKNOWN; j++)
2641 if (cc == cc_convs[i].convs[j].cc)
2644 = (reversed ? cc_convs[i].convs[j].reversed
2645 : cc_convs[i].convs[j].normal);
2647 if (mmix_cc == NULL)
2648 fatal_insn ("MMIX Internal: Trying to output invalidly\
2649 reversed condition:", x);
2651 fprintf (stream, "%s", mmix_cc);
2655 fatal_insn ("MMIX Internal: What's the CC of this?", x);
2659 fatal_insn ("MMIX Internal: What is the CC of this?", x);
2662 /* Return the bit-value for a const_int or const_double. */
2664 static HOST_WIDEST_INT
2667 unsigned HOST_WIDEST_INT retval;
2669 if (GET_CODE (x) == CONST_INT)
2672 /* We make a little song and dance because converting to long long in
2673 gcc-2.7.2 is broken. I still want people to be able to use it for
2674 cross-compilation to MMIX. */
2675 if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == VOIDmode)
2677 if (sizeof (HOST_WIDE_INT) < sizeof (HOST_WIDEST_INT))
2679 retval = (unsigned) CONST_DOUBLE_LOW (x) / 2;
2681 retval |= CONST_DOUBLE_LOW (x) & 1;
2684 (unsigned HOST_WIDEST_INT) CONST_DOUBLE_HIGH (x)
2685 << (HOST_BITS_PER_LONG);
2688 retval = CONST_DOUBLE_HIGH (x);
2693 if (GET_CODE (x) == CONST_DOUBLE)
2695 REAL_VALUE_TYPE value;
2697 /* FIXME: This macro is not in the manual but should be. */
2698 REAL_VALUE_FROM_CONST_DOUBLE (value, x);
2700 if (GET_MODE (x) == DFmode)
2704 REAL_VALUE_TO_TARGET_DOUBLE (value, bits);
2706 /* The double cast is necessary to avoid getting the long
2707 sign-extended to unsigned long long(!) when they're of
2708 different size (usually 32-bit hosts). */
2710 ((unsigned HOST_WIDEST_INT) (unsigned long) bits[0]
2711 << (unsigned HOST_WIDEST_INT) 32U)
2712 | (unsigned HOST_WIDEST_INT) (unsigned long) bits[1];
2714 else if (GET_MODE (x) == SFmode)
2717 REAL_VALUE_TO_TARGET_SINGLE (value, bits);
2719 return (unsigned long) bits;
2723 fatal_insn ("MMIX Internal: This is not a constant:", x);
2726 /* Worker function for TARGET_PROMOTE_FUNCTION_MODE. */
2729 mmix_promote_function_mode (const_tree type ATTRIBUTE_UNUSED,
2730 enum machine_mode mode,
2731 int *punsignedp ATTRIBUTE_UNUSED,
2732 const_tree fntype ATTRIBUTE_UNUSED,
2735 /* Apparently not doing TRT if int < register-size. FIXME: Perhaps
2736 FUNCTION_VALUE and LIBCALL_VALUE needs tweaking as some ports say. */
2737 if (for_return == 1)
2740 /* Promotion of modes currently generates slow code, extending before
2741 operation, so we do it only for arguments. */
2742 if (GET_MODE_CLASS (mode) == MODE_INT
2743 && GET_MODE_SIZE (mode) < 8)
2748 /* Worker function for TARGET_STRUCT_VALUE_RTX. */
2751 mmix_struct_value_rtx (tree fntype ATTRIBUTE_UNUSED,
2752 int incoming ATTRIBUTE_UNUSED)
2754 return gen_rtx_REG (Pmode, MMIX_STRUCT_VALUE_REGNUM);
2757 /* Worker function for TARGET_FRAME_POINTER_REQUIRED.
2759 FIXME: Is this requirement built-in? Anyway, we should try to get rid
2760 of it; we can deduce the value. */
2763 mmix_frame_pointer_required (void)
2765 return (cfun->has_nonlocal_label);
2770 * eval: (c-set-style "gnu")
2771 * indent-tabs-mode: t