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"
43 #include "integrate.h"
45 #include "target-def.h"
47 /* First some local helper definitions. */
48 #define MMIX_FIRST_GLOBAL_REGNUM 32
50 /* We'd need a current_function_has_landing_pad. It's marked as such when
51 a nonlocal_goto_receiver is expanded. Not just a C++ thing, but
53 #define MMIX_CFUN_HAS_LANDING_PAD (cfun->machine->has_landing_pad != 0)
55 /* We have no means to tell DWARF 2 about the register stack, so we need
56 to store the return address on the stack if an exception can get into
57 this function. FIXME: Narrow condition. Before any whole-function
58 analysis, df_regs_ever_live_p () isn't initialized. We know it's up-to-date
59 after reload_completed; it may contain incorrect information some time
60 before that. Within a RTL sequence (after a call to start_sequence,
61 such as in RTL expanders), leaf_function_p doesn't see all insns
62 (perhaps any insn). But regs_ever_live is up-to-date when
63 leaf_function_p () isn't, so we "or" them together to get accurate
64 information. FIXME: Some tweak to leaf_function_p might be
66 #define MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS \
68 && ((reload_completed && df_regs_ever_live_p (MMIX_rJ_REGNUM)) \
69 || !leaf_function_p ()))
71 #define IS_MMIX_EH_RETURN_DATA_REG(REGNO) \
72 (crtl->calls_eh_return \
73 && (EH_RETURN_DATA_REGNO (0) == REGNO \
74 || EH_RETURN_DATA_REGNO (1) == REGNO \
75 || EH_RETURN_DATA_REGNO (2) == REGNO \
76 || EH_RETURN_DATA_REGNO (3) == REGNO))
78 /* For the default ABI, we rename registers at output-time to fill the gap
79 between the (statically partitioned) saved registers and call-clobbered
80 registers. In effect this makes unused call-saved registers to be used
81 as call-clobbered registers. The benefit comes from keeping the number
82 of local registers (value of rL) low, since there's a cost of
83 increasing rL and clearing unused (unset) registers with lower numbers.
84 Don't translate while outputting the prologue. */
85 #define MMIX_OUTPUT_REGNO(N) \
87 || (int) (N) < MMIX_RETURN_VALUE_REGNUM \
88 || (int) (N) > MMIX_LAST_STACK_REGISTER_REGNUM \
90 || cfun->machine == NULL \
91 || cfun->machine->in_prologue \
92 ? (N) : ((N) - MMIX_RETURN_VALUE_REGNUM \
93 + cfun->machine->highest_saved_stack_register + 1))
95 /* The %d in "POP %d,0". */
96 #define MMIX_POP_ARGUMENT() \
98 && crtl->return_rtx != NULL \
99 && ! cfun->returns_struct) \
100 ? (GET_CODE (crtl->return_rtx) == PARALLEL \
101 ? GET_NUM_ELEM (XVEC (crtl->return_rtx, 0)) : 1) \
104 /* The canonical saved comparison operands for non-cc0 machines, set in
105 the compare expander. */
106 rtx mmix_compare_op0;
107 rtx mmix_compare_op1;
109 /* Declarations of locals. */
111 /* Intermediate for insn output. */
112 static int mmix_output_destination_register;
114 static void mmix_output_shiftvalue_op_from_str
115 (FILE *, const char *, HOST_WIDEST_INT);
116 static void mmix_output_shifted_value (FILE *, HOST_WIDEST_INT);
117 static void mmix_output_condition (FILE *, rtx, int);
118 static HOST_WIDEST_INT mmix_intval (rtx);
119 static void mmix_output_octa (FILE *, HOST_WIDEST_INT, int);
120 static bool mmix_assemble_integer (rtx, unsigned int, int);
121 static struct machine_function *mmix_init_machine_status (void);
122 static void mmix_encode_section_info (tree, rtx, int);
123 static const char *mmix_strip_name_encoding (const char *);
124 static void mmix_emit_sp_add (HOST_WIDE_INT offset);
125 static void mmix_target_asm_function_prologue (FILE *, HOST_WIDE_INT);
126 static void mmix_target_asm_function_end_prologue (FILE *);
127 static void mmix_target_asm_function_epilogue (FILE *, HOST_WIDE_INT);
128 static bool mmix_legitimate_address_p (enum machine_mode, rtx, bool);
129 static void mmix_reorg (void);
130 static void mmix_asm_output_mi_thunk
131 (FILE *, tree, HOST_WIDE_INT, HOST_WIDE_INT, tree);
132 static void mmix_setup_incoming_varargs
133 (CUMULATIVE_ARGS *, enum machine_mode, tree, int *, int);
134 static void mmix_file_start (void);
135 static void mmix_file_end (void);
136 static bool mmix_rtx_costs (rtx, int, int, int *, bool);
137 static rtx mmix_struct_value_rtx (tree, int);
138 static enum machine_mode mmix_promote_function_mode (const_tree,
140 int *, const_tree, int);
141 static rtx mmix_function_value (const_tree, const_tree, bool);
142 static rtx mmix_libcall_value (enum machine_mode, const_rtx);
143 static bool mmix_function_value_regno_p (const unsigned int);
144 static bool mmix_pass_by_reference (CUMULATIVE_ARGS *,
145 enum machine_mode, const_tree, bool);
146 static bool mmix_frame_pointer_required (void);
147 static void mmix_asm_trampoline_template (FILE *);
148 static void mmix_trampoline_init (rtx, tree, rtx);
150 /* Target structure macros. Listed by node. See `Using and Porting GCC'
151 for a general description. */
153 /* Node: Function Entry */
155 #undef TARGET_ASM_BYTE_OP
156 #define TARGET_ASM_BYTE_OP NULL
157 #undef TARGET_ASM_ALIGNED_HI_OP
158 #define TARGET_ASM_ALIGNED_HI_OP NULL
159 #undef TARGET_ASM_ALIGNED_SI_OP
160 #define TARGET_ASM_ALIGNED_SI_OP NULL
161 #undef TARGET_ASM_ALIGNED_DI_OP
162 #define TARGET_ASM_ALIGNED_DI_OP NULL
163 #undef TARGET_ASM_INTEGER
164 #define TARGET_ASM_INTEGER mmix_assemble_integer
166 #undef TARGET_ASM_FUNCTION_PROLOGUE
167 #define TARGET_ASM_FUNCTION_PROLOGUE mmix_target_asm_function_prologue
169 #undef TARGET_ASM_FUNCTION_END_PROLOGUE
170 #define TARGET_ASM_FUNCTION_END_PROLOGUE mmix_target_asm_function_end_prologue
172 #undef TARGET_ASM_FUNCTION_EPILOGUE
173 #define TARGET_ASM_FUNCTION_EPILOGUE mmix_target_asm_function_epilogue
175 #undef TARGET_ENCODE_SECTION_INFO
176 #define TARGET_ENCODE_SECTION_INFO mmix_encode_section_info
177 #undef TARGET_STRIP_NAME_ENCODING
178 #define TARGET_STRIP_NAME_ENCODING mmix_strip_name_encoding
180 #undef TARGET_ASM_OUTPUT_MI_THUNK
181 #define TARGET_ASM_OUTPUT_MI_THUNK mmix_asm_output_mi_thunk
182 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
183 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall
184 #undef TARGET_ASM_FILE_START
185 #define TARGET_ASM_FILE_START mmix_file_start
186 #undef TARGET_ASM_FILE_START_FILE_DIRECTIVE
187 #define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
188 #undef TARGET_ASM_FILE_END
189 #define TARGET_ASM_FILE_END mmix_file_end
191 #undef TARGET_RTX_COSTS
192 #define TARGET_RTX_COSTS mmix_rtx_costs
193 #undef TARGET_ADDRESS_COST
194 #define TARGET_ADDRESS_COST hook_int_rtx_bool_0
196 #undef TARGET_MACHINE_DEPENDENT_REORG
197 #define TARGET_MACHINE_DEPENDENT_REORG mmix_reorg
199 #undef TARGET_PROMOTE_FUNCTION_MODE
200 #define TARGET_PROMOTE_FUNCTION_MODE mmix_promote_function_mode
202 #undef TARGET_FUNCTION_VALUE
203 #define TARGET_FUNCTION_VALUE mmix_function_value
204 #undef TARGET_LIBCALL_VALUE
205 #define TARGET_LIBCALL_VALUE mmix_libcall_value
206 #undef TARGET_FUNCTION_VALUE_REGNO_P
207 #define TARGET_FUNCTION_VALUE_REGNO_P mmix_function_value_regno_p
209 #undef TARGET_STRUCT_VALUE_RTX
210 #define TARGET_STRUCT_VALUE_RTX mmix_struct_value_rtx
211 #undef TARGET_SETUP_INCOMING_VARARGS
212 #define TARGET_SETUP_INCOMING_VARARGS mmix_setup_incoming_varargs
213 #undef TARGET_PASS_BY_REFERENCE
214 #define TARGET_PASS_BY_REFERENCE mmix_pass_by_reference
215 #undef TARGET_CALLEE_COPIES
216 #define TARGET_CALLEE_COPIES hook_bool_CUMULATIVE_ARGS_mode_tree_bool_true
217 #undef TARGET_DEFAULT_TARGET_FLAGS
218 #define TARGET_DEFAULT_TARGET_FLAGS TARGET_DEFAULT
220 #undef TARGET_LEGITIMATE_ADDRESS_P
221 #define TARGET_LEGITIMATE_ADDRESS_P mmix_legitimate_address_p
223 #undef TARGET_FRAME_POINTER_REQUIRED
224 #define TARGET_FRAME_POINTER_REQUIRED mmix_frame_pointer_required
226 #undef TARGET_ASM_TRAMPOLINE_TEMPLATE
227 #define TARGET_ASM_TRAMPOLINE_TEMPLATE mmix_asm_trampoline_template
228 #undef TARGET_TRAMPOLINE_INIT
229 #define TARGET_TRAMPOLINE_INIT mmix_trampoline_init
231 struct gcc_target targetm = TARGET_INITIALIZER;
233 /* Functions that are expansions for target macros.
234 See Target Macros in `Using and Porting GCC'. */
236 /* OVERRIDE_OPTIONS. */
239 mmix_override_options (void)
241 /* Should we err or should we warn? Hmm. At least we must neutralize
242 it. For example the wrong kind of case-tables will be generated with
243 PIC; we use absolute address items for mmixal compatibility. FIXME:
244 They could be relative if we just elide them to after all pertinent
248 warning (0, "-f%s not supported: ignored", (flag_pic > 1) ? "PIC" : "pic");
253 /* INIT_EXPANDERS. */
256 mmix_init_expanders (void)
258 init_machine_status = mmix_init_machine_status;
261 /* Set the per-function data. */
263 static struct machine_function *
264 mmix_init_machine_status (void)
266 return ggc_alloc_cleared_machine_function ();
270 We have trouble getting the address of stuff that is located at other
271 than 32-bit alignments (GETA requirements), so try to give everything
272 at least 32-bit alignment. */
275 mmix_data_alignment (tree type ATTRIBUTE_UNUSED, int basic_align)
277 if (basic_align < 32)
283 /* CONSTANT_ALIGNMENT. */
286 mmix_constant_alignment (tree constant ATTRIBUTE_UNUSED, int basic_align)
288 if (basic_align < 32)
294 /* LOCAL_ALIGNMENT. */
297 mmix_local_alignment (tree type ATTRIBUTE_UNUSED, int basic_align)
299 if (basic_align < 32)
305 /* CONDITIONAL_REGISTER_USAGE. */
308 mmix_conditional_register_usage (void)
314 static const int gnu_abi_reg_alloc_order[]
315 = MMIX_GNU_ABI_REG_ALLOC_ORDER;
317 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
318 reg_alloc_order[i] = gnu_abi_reg_alloc_order[i];
320 /* Change the default from the mmixware ABI. For the GNU ABI,
321 $15..$30 are call-saved just as $0..$14. There must be one
322 call-clobbered local register for the "hole" that holds the
323 number of saved local registers saved by PUSHJ/PUSHGO during the
324 function call, receiving the return value at return. So best is
325 to use the highest, $31. It's already marked call-clobbered for
327 for (i = 15; i <= 30; i++)
328 call_used_regs[i] = 0;
330 /* "Unfix" the parameter registers. */
331 for (i = MMIX_RESERVED_GNU_ARG_0_REGNUM;
332 i < MMIX_RESERVED_GNU_ARG_0_REGNUM + MMIX_MAX_ARGS_IN_REGS;
337 /* Step over the ":" in special register names. */
338 if (! TARGET_TOPLEVEL_SYMBOLS)
339 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
340 if (reg_names[i][0] == ':')
344 /* INCOMING_REGNO and OUTGOING_REGNO worker function.
345 Those two macros must only be applied to function argument
346 registers. FIXME: for their current use in gcc, it'd be better
347 with an explicit specific additional FUNCTION_INCOMING_ARG_REGNO_P
348 a'la FUNCTION_ARG / FUNCTION_INCOMING_ARG instead of forcing the
349 target to commit to a fixed mapping and for any unspecified
353 mmix_opposite_regno (int regno, int incoming)
355 if (!mmix_function_arg_regno_p (regno, incoming))
360 ? MMIX_FIRST_INCOMING_ARG_REGNUM - MMIX_FIRST_ARG_REGNUM
361 : MMIX_FIRST_ARG_REGNUM - MMIX_FIRST_INCOMING_ARG_REGNUM);
365 All registers that are part of the register stack and that will be
369 mmix_local_regno (int regno)
371 return regno <= MMIX_LAST_STACK_REGISTER_REGNUM && !call_used_regs[regno];
374 /* PREFERRED_RELOAD_CLASS.
375 We need to extend the reload class of REMAINDER_REG and HIMULT_REG. */
378 mmix_preferred_reload_class (rtx x ATTRIBUTE_UNUSED, enum reg_class rclass)
380 /* FIXME: Revisit. */
381 return GET_CODE (x) == MOD && GET_MODE (x) == DImode
382 ? REMAINDER_REG : rclass;
385 /* PREFERRED_OUTPUT_RELOAD_CLASS.
386 We need to extend the reload class of REMAINDER_REG and HIMULT_REG. */
389 mmix_preferred_output_reload_class (rtx x ATTRIBUTE_UNUSED,
390 enum reg_class rclass)
392 /* FIXME: Revisit. */
393 return GET_CODE (x) == MOD && GET_MODE (x) == DImode
394 ? REMAINDER_REG : rclass;
397 /* SECONDARY_RELOAD_CLASS.
398 We need to reload regs of REMAINDER_REG and HIMULT_REG elsewhere. */
401 mmix_secondary_reload_class (enum reg_class rclass,
402 enum machine_mode mode ATTRIBUTE_UNUSED,
403 rtx x ATTRIBUTE_UNUSED,
404 int in_p ATTRIBUTE_UNUSED)
406 if (rclass == REMAINDER_REG
407 || rclass == HIMULT_REG
408 || rclass == SYSTEM_REGS)
414 /* CONST_OK_FOR_LETTER_P. */
417 mmix_const_ok_for_letter_p (HOST_WIDE_INT value, int c)
420 (c == 'I' ? value >= 0 && value <= 255
421 : c == 'J' ? value >= 0 && value <= 65535
422 : c == 'K' ? value <= 0 && value >= -255
423 : c == 'L' ? mmix_shiftable_wyde_value (value)
424 : c == 'M' ? value == 0
425 : c == 'N' ? mmix_shiftable_wyde_value (~value)
426 : c == 'O' ? (value == 3 || value == 5 || value == 9
431 /* CONST_DOUBLE_OK_FOR_LETTER_P. */
434 mmix_const_double_ok_for_letter_p (rtx value, int c)
437 (c == 'G' ? value == CONST0_RTX (GET_MODE (value))
442 We need this since our constants are not always expressible as
443 CONST_INT:s, but rather often as CONST_DOUBLE:s. */
446 mmix_extra_constraint (rtx x, int c, int strict)
448 HOST_WIDEST_INT value;
450 /* When checking for an address, we need to handle strict vs. non-strict
451 register checks. Don't use address_operand, but instead its
452 equivalent (its callee, which it is just a wrapper for),
453 memory_operand_p and the strict-equivalent strict_memory_address_p. */
457 ? strict_memory_address_p (Pmode, x)
458 : memory_address_p (Pmode, x);
460 /* R asks whether x is to be loaded with GETA or something else. Right
461 now, only a SYMBOL_REF and LABEL_REF can fit for
462 TARGET_BASE_ADDRESSES.
464 Only constant symbolic addresses apply. With TARGET_BASE_ADDRESSES,
465 we just allow straight LABEL_REF or SYMBOL_REFs with SYMBOL_REF_FLAG
466 set right now; only function addresses and code labels. If we change
467 to let SYMBOL_REF_FLAG be set on other symbols, we have to check
468 inside CONST expressions. When TARGET_BASE_ADDRESSES is not in
469 effect, a "raw" constant check together with mmix_constant_address_p
470 is all that's needed; we want all constant addresses to be loaded
474 GET_CODE (x) != CONST_INT && GET_CODE (x) != CONST_DOUBLE
475 && mmix_constant_address_p (x)
476 && (! TARGET_BASE_ADDRESSES
477 || (GET_CODE (x) == LABEL_REF
478 || (GET_CODE (x) == SYMBOL_REF && SYMBOL_REF_FLAG (x))));
480 if (GET_CODE (x) != CONST_DOUBLE || GET_MODE (x) != VOIDmode)
483 value = mmix_intval (x);
485 /* We used to map Q->J, R->K, S->L, T->N, U->O, but we don't have to any
486 more ('U' taken for address_operand, 'R' similarly). Some letters map
487 outside of CONST_INT, though; we still use 'S' and 'T'. */
489 return mmix_shiftable_wyde_value (value);
491 return mmix_shiftable_wyde_value (~value);
495 /* DYNAMIC_CHAIN_ADDRESS. */
498 mmix_dynamic_chain_address (rtx frame)
500 /* FIXME: the frame-pointer is stored at offset -8 from the current
501 frame-pointer. Unfortunately, the caller assumes that a
502 frame-pointer is present for *all* previous frames. There should be
503 a way to say that that cannot be done, like for RETURN_ADDR_RTX. */
504 return plus_constant (frame, -8);
507 /* STARTING_FRAME_OFFSET. */
510 mmix_starting_frame_offset (void)
512 /* The old frame pointer is in the slot below the new one, so
513 FIRST_PARM_OFFSET does not need to depend on whether the
514 frame-pointer is needed or not. We have to adjust for the register
515 stack pointer being located below the saved frame pointer.
516 Similarly, we store the return address on the stack too, for
517 exception handling, and always if we save the register stack pointer. */
520 + (MMIX_CFUN_HAS_LANDING_PAD
521 ? -16 : (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS ? -8 : 0)));
524 /* RETURN_ADDR_RTX. */
527 mmix_return_addr_rtx (int count, rtx frame ATTRIBUTE_UNUSED)
530 ? (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
531 /* FIXME: Set frame_alias_set on the following. (Why?)
532 See mmix_initial_elimination_offset for the reason we can't use
533 get_hard_reg_initial_val for both. Always using a stack slot
534 and not a register would be suboptimal. */
535 ? validize_mem (gen_rtx_MEM (Pmode, plus_constant (frame_pointer_rtx, -16)))
536 : get_hard_reg_initial_val (Pmode, MMIX_INCOMING_RETURN_ADDRESS_REGNUM))
540 /* SETUP_FRAME_ADDRESSES. */
543 mmix_setup_frame_addresses (void)
545 /* Nothing needed at the moment. */
548 /* The difference between the (imaginary) frame pointer and the stack
549 pointer. Used to eliminate the frame pointer. */
552 mmix_initial_elimination_offset (int fromreg, int toreg)
556 = (get_frame_size () + crtl->outgoing_args_size + 7) & ~7;
558 /* There is no actual offset between these two virtual values, but for
559 the frame-pointer, we have the old one in the stack position below
560 it, so the offset for the frame-pointer to the stack-pointer is one
562 if (fromreg == MMIX_ARG_POINTER_REGNUM
563 && toreg == MMIX_FRAME_POINTER_REGNUM)
566 /* The difference is the size of local variables plus the size of
567 outgoing function arguments that would normally be passed as
568 registers but must be passed on stack because we're out of
569 function-argument registers. Only global saved registers are
570 counted; the others go on the register stack.
572 The frame-pointer is counted too if it is what is eliminated, as we
573 need to balance the offset for it from STARTING_FRAME_OFFSET.
575 Also add in the slot for the register stack pointer we save if we
578 Unfortunately, we can't access $0..$14, from unwinder code easily, so
579 store the return address in a frame slot too. FIXME: Only for
580 non-leaf functions. FIXME: Always with a landing pad, because it's
581 hard to know whether we need the other at the time we know we need
582 the offset for one (and have to state it). It's a kludge until we
583 can express the register stack in the EH frame info.
585 We have to do alignment here; get_frame_size will not return a
586 multiple of STACK_BOUNDARY. FIXME: Add note in manual. */
588 for (regno = MMIX_FIRST_GLOBAL_REGNUM;
591 if ((df_regs_ever_live_p (regno) && ! call_used_regs[regno])
592 || IS_MMIX_EH_RETURN_DATA_REG (regno))
596 + (MMIX_CFUN_HAS_LANDING_PAD
597 ? 16 : (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS ? 8 : 0))
598 + (fromreg == MMIX_ARG_POINTER_REGNUM ? 0 : 8);
601 /* Return an rtx for a function argument to go in a register, and 0 for
602 one that must go on stack. */
605 mmix_function_arg (const CUMULATIVE_ARGS *argsp,
606 enum machine_mode mode,
608 int named ATTRIBUTE_UNUSED,
611 /* Last-argument marker. */
612 if (type == void_type_node)
613 return (argsp->regs < MMIX_MAX_ARGS_IN_REGS)
616 ? MMIX_FIRST_INCOMING_ARG_REGNUM
617 : MMIX_FIRST_ARG_REGNUM) + argsp->regs)
620 return (argsp->regs < MMIX_MAX_ARGS_IN_REGS
621 && !targetm.calls.must_pass_in_stack (mode, type)
622 && (GET_MODE_BITSIZE (mode) <= 64
627 ? MMIX_FIRST_INCOMING_ARG_REGNUM
628 : MMIX_FIRST_ARG_REGNUM)
633 /* Returns nonzero for everything that goes by reference, 0 for
634 everything that goes by value. */
637 mmix_pass_by_reference (CUMULATIVE_ARGS *argsp, enum machine_mode mode,
638 const_tree type, bool named ATTRIBUTE_UNUSED)
640 /* FIXME: Check: I'm not sure the must_pass_in_stack check is
642 if (targetm.calls.must_pass_in_stack (mode, type))
645 if (MMIX_FUNCTION_ARG_SIZE (mode, type) > 8
647 && (!argsp || !argsp->lib))
653 /* Return nonzero if regno is a register number where a parameter is
654 passed, and 0 otherwise. */
657 mmix_function_arg_regno_p (int regno, int incoming)
660 = incoming ? MMIX_FIRST_INCOMING_ARG_REGNUM : MMIX_FIRST_ARG_REGNUM;
662 return regno >= first_arg_regnum
663 && regno < first_arg_regnum + MMIX_MAX_ARGS_IN_REGS;
666 /* Implements TARGET_FUNCTION_VALUE. */
669 mmix_function_value (const_tree valtype,
670 const_tree func ATTRIBUTE_UNUSED,
673 enum machine_mode mode = TYPE_MODE (valtype);
674 enum machine_mode cmode;
675 int first_val_regnum = MMIX_OUTGOING_RETURN_VALUE_REGNUM;
676 rtx vec[MMIX_MAX_REGS_FOR_VALUE];
681 return gen_rtx_REG (mode, MMIX_RETURN_VALUE_REGNUM);
683 /* Return values that fit in a register need no special handling.
684 There's no register hole when parameters are passed in global
687 || GET_MODE_BITSIZE (mode) <= BITS_PER_WORD)
689 gen_rtx_REG (mode, MMIX_OUTGOING_RETURN_VALUE_REGNUM);
691 if (COMPLEX_MODE_P (mode))
692 /* A complex type, made up of components. */
693 cmode = TYPE_MODE (TREE_TYPE (valtype));
696 /* Of the other larger-than-register modes, we only support
697 scalar mode TImode. (At least, that's the only one that's
698 been rudimentally tested.) Make sure we're alerted for
701 sorry ("support for mode %qs", GET_MODE_NAME (mode));
703 /* In any case, we will fill registers to the natural size. */
707 nregs = ((GET_MODE_BITSIZE (mode) + BITS_PER_WORD - 1) / BITS_PER_WORD);
709 /* We need to take care of the effect of the register hole on return
710 values of large sizes; the last register will appear as the first
711 register, with the rest shifted. (For complex modes, this is just
712 swapped registers.) */
714 if (nregs > MMIX_MAX_REGS_FOR_VALUE)
715 internal_error ("too large function value type, needs %d registers,\
716 have only %d registers for this", nregs, MMIX_MAX_REGS_FOR_VALUE);
718 /* FIXME: Maybe we should handle structure values like this too
719 (adjusted for BLKmode), perhaps for both ABI:s. */
720 for (i = 0; i < nregs - 1; i++)
722 = gen_rtx_EXPR_LIST (VOIDmode,
723 gen_rtx_REG (cmode, first_val_regnum + i),
724 GEN_INT ((i + 1) * BITS_PER_UNIT));
727 = gen_rtx_EXPR_LIST (VOIDmode,
728 gen_rtx_REG (cmode, first_val_regnum + nregs - 1),
731 return gen_rtx_PARALLEL (VOIDmode, gen_rtvec_v (nregs, vec));
734 /* Implements TARGET_LIBCALL_VALUE. */
737 mmix_libcall_value (enum machine_mode mode,
738 const_rtx fun ATTRIBUTE_UNUSED)
740 return gen_rtx_REG (mode, MMIX_RETURN_VALUE_REGNUM);
743 /* Implements TARGET_FUNCTION_VALUE_REGNO_P. */
746 mmix_function_value_regno_p (const unsigned int regno)
748 return regno == MMIX_RETURN_VALUE_REGNUM;
751 /* EH_RETURN_DATA_REGNO. */
754 mmix_eh_return_data_regno (int n)
757 return MMIX_EH_RETURN_DATA_REGNO_START + n;
759 return INVALID_REGNUM;
762 /* EH_RETURN_STACKADJ_RTX. */
765 mmix_eh_return_stackadj_rtx (void)
767 return gen_rtx_REG (Pmode, MMIX_EH_RETURN_STACKADJ_REGNUM);
770 /* EH_RETURN_HANDLER_RTX. */
773 mmix_eh_return_handler_rtx (void)
775 return gen_rtx_REG (Pmode, MMIX_INCOMING_RETURN_ADDRESS_REGNUM);
778 /* ASM_PREFERRED_EH_DATA_FORMAT. */
781 mmix_asm_preferred_eh_data_format (int code ATTRIBUTE_UNUSED,
782 int global ATTRIBUTE_UNUSED)
784 /* This is the default (was at 2001-07-20). Revisit when needed. */
785 return DW_EH_PE_absptr;
788 /* Make a note that we've seen the beginning of the prologue. This
789 matters to whether we'll translate register numbers as calculated by
793 mmix_target_asm_function_prologue (FILE *stream ATTRIBUTE_UNUSED,
794 HOST_WIDE_INT framesize ATTRIBUTE_UNUSED)
796 cfun->machine->in_prologue = 1;
799 /* Make a note that we've seen the end of the prologue. */
802 mmix_target_asm_function_end_prologue (FILE *stream ATTRIBUTE_UNUSED)
804 cfun->machine->in_prologue = 0;
807 /* Implement TARGET_MACHINE_DEPENDENT_REORG. No actual rearrangements
808 done here; just virtually by calculating the highest saved stack
809 register number used to modify the register numbers at output time. */
816 /* We put the number of the highest saved register-file register in a
817 location convenient for the call-patterns to output. Note that we
818 don't tell dwarf2 about these registers, since it can't restore them
820 for (regno = MMIX_LAST_STACK_REGISTER_REGNUM;
823 if ((df_regs_ever_live_p (regno) && !call_used_regs[regno])
824 || (regno == MMIX_FRAME_POINTER_REGNUM && frame_pointer_needed))
827 /* Regardless of whether they're saved (they might be just read), we
828 mustn't include registers that carry parameters. We could scan the
829 insns to see whether they're actually used (and indeed do other less
830 trivial register usage analysis and transformations), but it seems
831 wasteful to optimize for unused parameter registers. As of
832 2002-04-30, df_regs_ever_live_p (n) seems to be set for only-reads too, but
833 that might change. */
834 if (!TARGET_ABI_GNU && regno < crtl->args.info.regs - 1)
836 regno = crtl->args.info.regs - 1;
838 /* We don't want to let this cause us to go over the limit and make
839 incoming parameter registers be misnumbered and treating the last
840 parameter register and incoming return value register call-saved.
841 Stop things at the unmodified scheme. */
842 if (regno > MMIX_RETURN_VALUE_REGNUM - 1)
843 regno = MMIX_RETURN_VALUE_REGNUM - 1;
846 cfun->machine->highest_saved_stack_register = regno;
849 /* TARGET_ASM_FUNCTION_EPILOGUE. */
852 mmix_target_asm_function_epilogue (FILE *stream,
853 HOST_WIDE_INT locals_size ATTRIBUTE_UNUSED)
855 /* Emit an \n for readability of the generated assembly. */
856 fputc ('\n', stream);
859 /* TARGET_ASM_OUTPUT_MI_THUNK. */
862 mmix_asm_output_mi_thunk (FILE *stream,
863 tree fndecl ATTRIBUTE_UNUSED,
865 HOST_WIDE_INT vcall_offset ATTRIBUTE_UNUSED,
868 /* If you define TARGET_STRUCT_VALUE_RTX that returns 0 (i.e. pass
869 location of structure to return as invisible first argument), you
870 need to tweak this code too. */
871 const char *regname = reg_names[MMIX_FIRST_INCOMING_ARG_REGNUM];
873 if (delta >= 0 && delta < 65536)
874 fprintf (stream, "\tINCL %s,%d\n", regname, (int)delta);
875 else if (delta < 0 && delta >= -255)
876 fprintf (stream, "\tSUBU %s,%s,%d\n", regname, regname, (int)-delta);
879 mmix_output_register_setting (stream, 255, delta, 1);
880 fprintf (stream, "\tADDU %s,%s,$255\n", regname, regname);
883 fprintf (stream, "\tJMP ");
884 assemble_name (stream, XSTR (XEXP (DECL_RTL (func), 0), 0));
885 fprintf (stream, "\n");
888 /* FUNCTION_PROFILER. */
891 mmix_function_profiler (FILE *stream ATTRIBUTE_UNUSED,
892 int labelno ATTRIBUTE_UNUSED)
894 sorry ("function_profiler support for MMIX");
897 /* Worker function for TARGET_SETUP_INCOMING_VARARGS. For the moment,
898 let's stick to pushing argument registers on the stack. Later, we
899 can parse all arguments in registers, to improve performance. */
902 mmix_setup_incoming_varargs (CUMULATIVE_ARGS *args_so_farp,
903 enum machine_mode mode,
906 int second_time ATTRIBUTE_UNUSED)
908 /* The last named variable has been handled, but
909 args_so_farp has not been advanced for it. */
910 if (args_so_farp->regs + 1 < MMIX_MAX_ARGS_IN_REGS)
911 *pretend_sizep = (MMIX_MAX_ARGS_IN_REGS - (args_so_farp->regs + 1)) * 8;
913 /* We assume that one argument takes up one register here. That should
914 be true until we start messing with multi-reg parameters. */
915 if ((7 + (MMIX_FUNCTION_ARG_SIZE (mode, vartype))) / 8 != 1)
916 internal_error ("MMIX Internal: Last named vararg would not fit in a register");
919 /* TARGET_ASM_TRAMPOLINE_TEMPLATE. */
922 mmix_asm_trampoline_template (FILE *stream)
924 /* Read a value into the static-chain register and jump somewhere. The
925 static chain is stored at offset 16, and the function address is
926 stored at offset 24. */
928 fprintf (stream, "\tGETA $255,1F\n\t");
929 fprintf (stream, "LDOU %s,$255,0\n\t", reg_names[MMIX_STATIC_CHAIN_REGNUM]);
930 fprintf (stream, "LDOU $255,$255,8\n\t");
931 fprintf (stream, "GO $255,$255,0\n");
932 fprintf (stream, "1H\tOCTA 0\n\t");
933 fprintf (stream, "OCTA 0\n");
936 /* TARGET_TRAMPOLINE_INIT. */
937 /* Set the static chain and function pointer field in the trampoline.
938 We also SYNCID here to be sure (doesn't matter in the simulator, but
939 some day it will). */
942 mmix_trampoline_init (rtx m_tramp, tree fndecl, rtx static_chain)
944 rtx fnaddr = XEXP (DECL_RTL (fndecl), 0);
947 emit_block_move (m_tramp, assemble_trampoline_template (),
948 GEN_INT (2*UNITS_PER_WORD), BLOCK_OP_NORMAL);
950 mem = adjust_address (m_tramp, DImode, 2*UNITS_PER_WORD);
951 emit_move_insn (mem, static_chain);
952 mem = adjust_address (m_tramp, DImode, 3*UNITS_PER_WORD);
953 emit_move_insn (mem, fnaddr);
955 mem = adjust_address (m_tramp, DImode, 0);
956 emit_insn (gen_sync_icache (mem, GEN_INT (TRAMPOLINE_SIZE - 1)));
959 /* We must exclude constant addresses that have an increment that is not a
960 multiple of four bytes because of restrictions of the GETA
961 instruction, unless TARGET_BASE_ADDRESSES. */
964 mmix_constant_address_p (rtx x)
966 RTX_CODE code = GET_CODE (x);
968 /* When using "base addresses", anything constant goes. */
969 int constant_ok = TARGET_BASE_ADDRESSES != 0;
978 /* FIXME: Don't know how to dissect these. Avoid them for now,
979 except we know they're constants. */
987 if (GET_MODE (x) != VOIDmode)
988 /* Strange that we got here. FIXME: Check if we do. */
990 addend = CONST_DOUBLE_LOW (x);
994 /* Note that expressions with arithmetic on forward references don't
995 work in mmixal. People using gcc assembly code with mmixal might
996 need to move arrays and such to before the point of use. */
997 if (GET_CODE (XEXP (x, 0)) == PLUS)
999 rtx x0 = XEXP (XEXP (x, 0), 0);
1000 rtx x1 = XEXP (XEXP (x, 0), 1);
1002 if ((GET_CODE (x0) == SYMBOL_REF
1003 || GET_CODE (x0) == LABEL_REF)
1004 && (GET_CODE (x1) == CONST_INT
1005 || (GET_CODE (x1) == CONST_DOUBLE
1006 && GET_MODE (x1) == VOIDmode)))
1007 addend = mmix_intval (x1);
1019 return constant_ok || (addend & 3) == 0;
1022 /* Return 1 if the address is OK, otherwise 0. */
1025 mmix_legitimate_address_p (enum machine_mode mode ATTRIBUTE_UNUSED,
1027 bool strict_checking)
1029 #define MMIX_REG_OK(X) \
1031 && (REGNO (X) <= MMIX_LAST_GENERAL_REGISTER \
1032 || (reg_renumber[REGNO (X)] > 0 \
1033 && reg_renumber[REGNO (X)] <= MMIX_LAST_GENERAL_REGISTER))) \
1034 || (!strict_checking \
1035 && (REGNO (X) <= MMIX_LAST_GENERAL_REGISTER \
1036 || REGNO (X) >= FIRST_PSEUDO_REGISTER \
1037 || REGNO (X) == ARG_POINTER_REGNUM)))
1041 (mem (plus reg reg))
1042 (mem (plus reg 0..255)).
1043 unless TARGET_BASE_ADDRESSES, in which case we accept all
1044 (mem constant_address) too. */
1048 if (REG_P (x) && MMIX_REG_OK (x))
1051 if (GET_CODE(x) == PLUS)
1053 rtx x1 = XEXP (x, 0);
1054 rtx x2 = XEXP (x, 1);
1056 /* Try swapping the order. FIXME: Do we need this? */
1064 /* (mem (plus (reg?) (?))) */
1065 if (!REG_P (x1) || !MMIX_REG_OK (x1))
1066 return TARGET_BASE_ADDRESSES && mmix_constant_address_p (x);
1068 /* (mem (plus (reg) (reg?))) */
1069 if (REG_P (x2) && MMIX_REG_OK (x2))
1072 /* (mem (plus (reg) (0..255?))) */
1073 if (GET_CODE (x2) == CONST_INT
1074 && CONST_OK_FOR_LETTER_P (INTVAL (x2), 'I'))
1080 return TARGET_BASE_ADDRESSES && mmix_constant_address_p (x);
1083 /* LEGITIMATE_CONSTANT_P. */
1086 mmix_legitimate_constant_p (rtx x)
1088 RTX_CODE code = GET_CODE (x);
1090 /* We must allow any number due to the way the cse passes works; if we
1091 do not allow any number here, general_operand will fail, and insns
1092 will fatally fail recognition instead of "softly". */
1093 if (code == CONST_INT || code == CONST_DOUBLE)
1096 return CONSTANT_ADDRESS_P (x);
1099 /* SELECT_CC_MODE. */
1102 mmix_select_cc_mode (RTX_CODE op, rtx x, rtx y ATTRIBUTE_UNUSED)
1104 /* We use CCmode, CC_UNSmode, CC_FPmode, CC_FPEQmode and CC_FUNmode to
1105 output different compare insns. Note that we do not check the
1106 validity of the comparison here. */
1108 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1110 if (op == ORDERED || op == UNORDERED || op == UNGE
1111 || op == UNGT || op == UNLE || op == UNLT)
1114 if (op == EQ || op == NE)
1120 if (op == GTU || op == LTU || op == GEU || op == LEU)
1126 /* REVERSIBLE_CC_MODE. */
1129 mmix_reversible_cc_mode (enum machine_mode mode)
1131 /* That is, all integer and the EQ, NE, ORDERED and UNORDERED float
1133 return mode != CC_FPmode;
1136 /* TARGET_RTX_COSTS. */
1139 mmix_rtx_costs (rtx x ATTRIBUTE_UNUSED,
1140 int code ATTRIBUTE_UNUSED,
1141 int outer_code ATTRIBUTE_UNUSED,
1142 int *total ATTRIBUTE_UNUSED,
1143 bool speed ATTRIBUTE_UNUSED)
1145 /* For the time being, this is just a stub and we'll accept the
1146 generic calculations, until we can do measurements, at least.
1147 Say we did not modify any calculated costs. */
1151 /* REGISTER_MOVE_COST. */
1154 mmix_register_move_cost (enum machine_mode mode ATTRIBUTE_UNUSED,
1155 enum reg_class from,
1158 return (from == GENERAL_REGS && from == to) ? 2 : 3;
1161 /* Note that we don't have a TEXT_SECTION_ASM_OP, because it has to be a
1162 compile-time constant; it's used in an asm in crtstuff.c, compiled for
1165 /* DATA_SECTION_ASM_OP. */
1168 mmix_data_section_asm_op (void)
1170 return "\t.data ! mmixal:= 8H LOC 9B";
1174 mmix_encode_section_info (tree decl, rtx rtl, int first)
1176 /* Test for an external declaration, and do nothing if it is one. */
1177 if ((TREE_CODE (decl) == VAR_DECL
1178 && (DECL_EXTERNAL (decl) || TREE_PUBLIC (decl)))
1179 || (TREE_CODE (decl) == FUNCTION_DECL && TREE_PUBLIC (decl)))
1181 else if (first && DECL_P (decl))
1183 /* For non-visible declarations, add a "@" prefix, which we skip
1184 when the label is output. If the label does not have this
1185 prefix, a ":" is output if -mtoplevel-symbols.
1187 Note that this does not work for data that is declared extern and
1188 later defined as static. If there's code in between, that code
1189 will refer to the extern declaration, and vice versa. This just
1190 means that when -mtoplevel-symbols is in use, we can just handle
1191 well-behaved ISO-compliant code. */
1193 const char *str = XSTR (XEXP (rtl, 0), 0);
1194 int len = strlen (str);
1195 char *newstr = XALLOCAVEC (char, len + 2);
1197 strcpy (newstr + 1, str);
1198 XSTR (XEXP (rtl, 0), 0) = ggc_alloc_string (newstr, len + 1);
1201 /* Set SYMBOL_REF_FLAG for things that we want to access with GETA. We
1202 may need different options to reach for different things with GETA.
1203 For now, functions and things we know or have been told are constant. */
1204 if (TREE_CODE (decl) == FUNCTION_DECL
1205 || TREE_CONSTANT (decl)
1206 || (TREE_CODE (decl) == VAR_DECL
1207 && TREE_READONLY (decl)
1208 && !TREE_SIDE_EFFECTS (decl)
1209 && (!DECL_INITIAL (decl)
1210 || TREE_CONSTANT (DECL_INITIAL (decl)))))
1211 SYMBOL_REF_FLAG (XEXP (rtl, 0)) = 1;
1215 mmix_strip_name_encoding (const char *name)
1217 for (; (*name == '@' || *name == '*'); name++)
1223 /* TARGET_ASM_FILE_START.
1224 We just emit a little comment for the time being. */
1227 mmix_file_start (void)
1229 default_file_start ();
1231 fputs ("! mmixal:= 8H LOC Data_Section\n", asm_out_file);
1233 /* Make sure each file starts with the text section. */
1234 switch_to_section (text_section);
1237 /* TARGET_ASM_FILE_END. */
1240 mmix_file_end (void)
1242 /* Make sure each file ends with the data section. */
1243 switch_to_section (data_section);
1246 /* ASM_OUTPUT_SOURCE_FILENAME. */
1249 mmix_asm_output_source_filename (FILE *stream, const char *name)
1251 fprintf (stream, "# 1 ");
1252 OUTPUT_QUOTED_STRING (stream, name);
1253 fprintf (stream, "\n");
1256 /* OUTPUT_QUOTED_STRING. */
1259 mmix_output_quoted_string (FILE *stream, const char *string, int length)
1261 const char * string_end = string + length;
1262 static const char *const unwanted_chars = "\"[]\\";
1264 /* Output "any character except newline and double quote character". We
1265 play it safe and avoid all control characters too. We also do not
1266 want [] as characters, should input be passed through m4 with [] as
1267 quotes. Further, we avoid "\", because the GAS port handles it as a
1268 quoting character. */
1269 while (string < string_end)
1272 && (unsigned char) *string < 128
1273 && !ISCNTRL (*string)
1274 && strchr (unwanted_chars, *string) == NULL)
1276 fputc ('"', stream);
1278 && (unsigned char) *string < 128
1279 && !ISCNTRL (*string)
1280 && strchr (unwanted_chars, *string) == NULL
1281 && string < string_end)
1283 fputc (*string, stream);
1286 fputc ('"', stream);
1287 if (string < string_end)
1288 fprintf (stream, ",");
1290 if (string < string_end)
1292 fprintf (stream, "#%x", *string & 255);
1294 if (string < string_end)
1295 fprintf (stream, ",");
1300 /* Target hook for assembling integer objects. Use mmix_print_operand
1301 for WYDE and TETRA. Use mmix_output_octa to output 8-byte
1305 mmix_assemble_integer (rtx x, unsigned int size, int aligned_p)
1310 /* We handle a limited number of types of operands in here. But
1311 that's ok, because we can punt to generic functions. We then
1312 pretend that aligned data isn't needed, so the usual .<pseudo>
1313 syntax is used (which works for aligned data too). We actually
1314 *must* do that, since we say we don't have simple aligned
1315 pseudos, causing this function to be called. We just try and
1316 keep as much compatibility as possible with mmixal syntax for
1317 normal cases (i.e. without GNU extensions and C only). */
1319 if (GET_CODE (x) != CONST_INT)
1324 fputs ("\tBYTE\t", asm_out_file);
1325 mmix_print_operand (asm_out_file, x, 'B');
1326 fputc ('\n', asm_out_file);
1330 if (GET_CODE (x) != CONST_INT)
1335 fputs ("\tWYDE\t", asm_out_file);
1336 mmix_print_operand (asm_out_file, x, 'W');
1337 fputc ('\n', asm_out_file);
1341 if (GET_CODE (x) != CONST_INT)
1346 fputs ("\tTETRA\t", asm_out_file);
1347 mmix_print_operand (asm_out_file, x, 'L');
1348 fputc ('\n', asm_out_file);
1352 /* We don't get here anymore for CONST_DOUBLE, because DImode
1353 isn't expressed as CONST_DOUBLE, and DFmode is handled
1355 gcc_assert (GET_CODE (x) != CONST_DOUBLE);
1356 assemble_integer_with_op ("\tOCTA\t", x);
1359 return default_assemble_integer (x, size, aligned_p);
1362 /* ASM_OUTPUT_ASCII. */
1365 mmix_asm_output_ascii (FILE *stream, const char *string, int length)
1369 int chunk_size = length > 60 ? 60 : length;
1370 fprintf (stream, "\tBYTE ");
1371 mmix_output_quoted_string (stream, string, chunk_size);
1372 string += chunk_size;
1373 length -= chunk_size;
1374 fprintf (stream, "\n");
1378 /* ASM_OUTPUT_ALIGNED_COMMON. */
1381 mmix_asm_output_aligned_common (FILE *stream,
1386 /* This is mostly the elfos.h one. There doesn't seem to be a way to
1387 express this in a mmixal-compatible way. */
1388 fprintf (stream, "\t.comm\t");
1389 assemble_name (stream, name);
1390 fprintf (stream, ",%u,%u ! mmixal-incompatible COMMON\n",
1391 size, align / BITS_PER_UNIT);
1394 /* ASM_OUTPUT_ALIGNED_LOCAL. */
1397 mmix_asm_output_aligned_local (FILE *stream,
1402 switch_to_section (data_section);
1404 ASM_OUTPUT_ALIGN (stream, exact_log2 (align/BITS_PER_UNIT));
1405 assemble_name (stream, name);
1406 fprintf (stream, "\tLOC @+%d\n", size);
1409 /* ASM_OUTPUT_LABEL. */
1412 mmix_asm_output_label (FILE *stream, const char *name)
1414 assemble_name (stream, name);
1415 fprintf (stream, "\tIS @\n");
1418 /* ASM_OUTPUT_INTERNAL_LABEL. */
1421 mmix_asm_output_internal_label (FILE *stream, const char *name)
1423 assemble_name_raw (stream, name);
1424 fprintf (stream, "\tIS @\n");
1427 /* ASM_DECLARE_REGISTER_GLOBAL. */
1430 mmix_asm_declare_register_global (FILE *stream ATTRIBUTE_UNUSED,
1431 tree decl ATTRIBUTE_UNUSED,
1432 int regno ATTRIBUTE_UNUSED,
1433 const char *name ATTRIBUTE_UNUSED)
1435 /* Nothing to do here, but there *will* be, therefore the framework is
1439 /* ASM_WEAKEN_LABEL. */
1442 mmix_asm_weaken_label (FILE *stream ATTRIBUTE_UNUSED,
1443 const char *name ATTRIBUTE_UNUSED)
1445 fprintf (stream, "\t.weak ");
1446 assemble_name (stream, name);
1447 fprintf (stream, " ! mmixal-incompatible\n");
1450 /* MAKE_DECL_ONE_ONLY. */
1453 mmix_make_decl_one_only (tree decl)
1455 DECL_WEAK (decl) = 1;
1458 /* ASM_OUTPUT_LABELREF.
1459 Strip GCC's '*' and our own '@'. No order is assumed. */
1462 mmix_asm_output_labelref (FILE *stream, const char *name)
1466 for (; (*name == '@' || *name == '*'); name++)
1470 asm_fprintf (stream, "%s%U%s",
1471 is_extern && TARGET_TOPLEVEL_SYMBOLS ? ":" : "",
1475 /* ASM_OUTPUT_DEF. */
1478 mmix_asm_output_def (FILE *stream, const char *name, const char *value)
1480 assemble_name (stream, name);
1481 fprintf (stream, "\tIS ");
1482 assemble_name (stream, value);
1483 fputc ('\n', stream);
1486 /* PRINT_OPERAND. */
1489 mmix_print_operand (FILE *stream, rtx x, int code)
1491 /* When we add support for different codes later, we can, when needed,
1492 drop through to the main handler with a modified operand. */
1494 int regno = x != NULL_RTX && REG_P (x) ? REGNO (x) : 0;
1498 /* Unrelated codes are in alphabetic order. */
1501 /* For conditional branches, output "P" for a probable branch. */
1502 if (TARGET_BRANCH_PREDICT)
1504 x = find_reg_note (current_output_insn, REG_BR_PROB, 0);
1505 if (x && INTVAL (XEXP (x, 0)) > REG_BR_PROB_BASE / 2)
1511 /* For the %d in POP %d,0. */
1512 fprintf (stream, "%d", MMIX_POP_ARGUMENT ());
1516 if (GET_CODE (x) != CONST_INT)
1517 fatal_insn ("MMIX Internal: Expected a CONST_INT, not this", x);
1518 fprintf (stream, "%d", (int) (INTVAL (x) & 0xff));
1522 /* Highpart. Must be general register, and not the last one, as
1523 that one cannot be part of a consecutive register pair. */
1524 if (regno > MMIX_LAST_GENERAL_REGISTER - 1)
1525 internal_error ("MMIX Internal: Bad register: %d", regno);
1527 /* This is big-endian, so the high-part is the first one. */
1528 fprintf (stream, "%s", reg_names[MMIX_OUTPUT_REGNO (regno)]);
1532 /* Lowpart. Must be CONST_INT or general register, and not the last
1533 one, as that one cannot be part of a consecutive register pair. */
1534 if (GET_CODE (x) == CONST_INT)
1536 fprintf (stream, "#%lx",
1537 (unsigned long) (INTVAL (x)
1538 & ((unsigned int) 0x7fffffff * 2 + 1)));
1542 if (GET_CODE (x) == SYMBOL_REF)
1544 output_addr_const (stream, x);
1548 if (regno > MMIX_LAST_GENERAL_REGISTER - 1)
1549 internal_error ("MMIX Internal: Bad register: %d", regno);
1551 /* This is big-endian, so the low-part is + 1. */
1552 fprintf (stream, "%s", reg_names[MMIX_OUTPUT_REGNO (regno) + 1]);
1555 /* Can't use 'a' because that's a generic modifier for address
1558 mmix_output_shiftvalue_op_from_str (stream, "ANDN",
1559 ~(unsigned HOST_WIDEST_INT)
1564 mmix_output_shiftvalue_op_from_str (stream, "INC",
1565 (unsigned HOST_WIDEST_INT)
1570 mmix_output_shiftvalue_op_from_str (stream, "OR",
1571 (unsigned HOST_WIDEST_INT)
1576 mmix_output_shiftvalue_op_from_str (stream, "SET",
1577 (unsigned HOST_WIDEST_INT)
1583 mmix_output_condition (stream, x, (code == 'D'));
1587 /* Output an extra "e" to make fcmpe, fune. */
1588 if (TARGET_FCMP_EPSILON)
1589 fprintf (stream, "e");
1593 /* Output the number minus 1. */
1594 if (GET_CODE (x) != CONST_INT)
1596 fatal_insn ("MMIX Internal: Bad value for 'm', not a CONST_INT",
1599 fprintf (stream, HOST_WIDEST_INT_PRINT_DEC,
1600 (HOST_WIDEST_INT) (mmix_intval (x) - 1));
1604 /* Store the number of registers we want to save. This was setup
1605 by the prologue. The actual operand contains the number of
1606 registers to pass, but we don't use it currently. Anyway, we
1607 need to output the number of saved registers here. */
1608 fprintf (stream, "%d",
1609 cfun->machine->highest_saved_stack_register + 1);
1613 /* Store the register to output a constant to. */
1615 fatal_insn ("MMIX Internal: Expected a register, not this", x);
1616 mmix_output_destination_register = MMIX_OUTPUT_REGNO (regno);
1620 /* Output the constant. Note that we use this for floats as well. */
1621 if (GET_CODE (x) != CONST_INT
1622 && (GET_CODE (x) != CONST_DOUBLE
1623 || (GET_MODE (x) != VOIDmode && GET_MODE (x) != DFmode
1624 && GET_MODE (x) != SFmode)))
1625 fatal_insn ("MMIX Internal: Expected a constant, not this", x);
1626 mmix_output_register_setting (stream,
1627 mmix_output_destination_register,
1628 mmix_intval (x), 0);
1632 /* An U for unsigned, if TARGET_ZERO_EXTEND. Ignore the operand. */
1633 if (TARGET_ZERO_EXTEND)
1638 mmix_output_shifted_value (stream, (HOST_WIDEST_INT) mmix_intval (x));
1642 mmix_output_shifted_value (stream, (HOST_WIDEST_INT) ~mmix_intval (x));
1646 if (GET_CODE (x) != CONST_INT)
1647 fatal_insn ("MMIX Internal: Expected a CONST_INT, not this", x);
1648 fprintf (stream, "#%x", (int) (INTVAL (x) & 0xffff));
1652 /* Nothing to do. */
1656 /* Presumably there's a missing case above if we get here. */
1657 internal_error ("MMIX Internal: Missing %qc case in mmix_print_operand", code);
1660 switch (GET_CODE (modified_x))
1663 regno = REGNO (modified_x);
1664 if (regno >= FIRST_PSEUDO_REGISTER)
1665 internal_error ("MMIX Internal: Bad register: %d", regno);
1666 fprintf (stream, "%s", reg_names[MMIX_OUTPUT_REGNO (regno)]);
1670 output_address (XEXP (modified_x, 0));
1674 /* For -2147483648, mmixal complains that the constant does not fit
1675 in 4 bytes, so let's output it as hex. Take care to handle hosts
1676 where HOST_WIDE_INT is longer than an int.
1678 Print small constants +-255 using decimal. */
1680 if (INTVAL (modified_x) > -256 && INTVAL (modified_x) < 256)
1681 fprintf (stream, "%d", (int) (INTVAL (modified_x)));
1683 fprintf (stream, "#%x",
1684 (int) (INTVAL (modified_x)) & (unsigned int) ~0);
1688 /* Do somewhat as CONST_INT. */
1689 mmix_output_octa (stream, mmix_intval (modified_x), 0);
1693 output_addr_const (stream, modified_x);
1697 /* No need to test for all strange things. Let output_addr_const do
1699 if (CONSTANT_P (modified_x)
1700 /* Strangely enough, this is not included in CONSTANT_P.
1701 FIXME: Ask/check about sanity here. */
1702 || GET_CODE (modified_x) == CODE_LABEL)
1704 output_addr_const (stream, modified_x);
1708 /* We need the original here. */
1709 fatal_insn ("MMIX Internal: Cannot decode this operand", x);
1713 /* PRINT_OPERAND_PUNCT_VALID_P. */
1716 mmix_print_operand_punct_valid_p (int code ATTRIBUTE_UNUSED)
1718 /* A '+' is used for branch prediction, similar to other ports. */
1720 /* A '.' is used for the %d in the POP %d,0 return insn. */
1724 /* PRINT_OPERAND_ADDRESS. */
1727 mmix_print_operand_address (FILE *stream, rtx x)
1731 /* I find the generated assembly code harder to read without
1733 fprintf (stream, "%s,0", reg_names[MMIX_OUTPUT_REGNO (REGNO (x))]);
1736 else if (GET_CODE (x) == PLUS)
1738 rtx x1 = XEXP (x, 0);
1739 rtx x2 = XEXP (x, 1);
1743 fprintf (stream, "%s,", reg_names[MMIX_OUTPUT_REGNO (REGNO (x1))]);
1747 fprintf (stream, "%s",
1748 reg_names[MMIX_OUTPUT_REGNO (REGNO (x2))]);
1751 else if (GET_CODE (x2) == CONST_INT
1752 && CONST_OK_FOR_LETTER_P (INTVAL (x2), 'I'))
1754 output_addr_const (stream, x2);
1760 if (TARGET_BASE_ADDRESSES && mmix_legitimate_constant_p (x))
1762 output_addr_const (stream, x);
1766 fatal_insn ("MMIX Internal: This is not a recognized address", x);
1769 /* ASM_OUTPUT_REG_PUSH. */
1772 mmix_asm_output_reg_push (FILE *stream, int regno)
1774 fprintf (stream, "\tSUBU %s,%s,8\n\tSTOU %s,%s,0\n",
1775 reg_names[MMIX_STACK_POINTER_REGNUM],
1776 reg_names[MMIX_STACK_POINTER_REGNUM],
1777 reg_names[MMIX_OUTPUT_REGNO (regno)],
1778 reg_names[MMIX_STACK_POINTER_REGNUM]);
1781 /* ASM_OUTPUT_REG_POP. */
1784 mmix_asm_output_reg_pop (FILE *stream, int regno)
1786 fprintf (stream, "\tLDOU %s,%s,0\n\tINCL %s,8\n",
1787 reg_names[MMIX_OUTPUT_REGNO (regno)],
1788 reg_names[MMIX_STACK_POINTER_REGNUM],
1789 reg_names[MMIX_STACK_POINTER_REGNUM]);
1792 /* ASM_OUTPUT_ADDR_DIFF_ELT. */
1795 mmix_asm_output_addr_diff_elt (FILE *stream,
1796 rtx body ATTRIBUTE_UNUSED,
1800 fprintf (stream, "\tTETRA L%d-L%d\n", value, rel);
1803 /* ASM_OUTPUT_ADDR_VEC_ELT. */
1806 mmix_asm_output_addr_vec_elt (FILE *stream, int value)
1808 fprintf (stream, "\tOCTA L:%d\n", value);
1811 /* ASM_OUTPUT_SKIP. */
1814 mmix_asm_output_skip (FILE *stream, int nbytes)
1816 fprintf (stream, "\tLOC @+%d\n", nbytes);
1819 /* ASM_OUTPUT_ALIGN. */
1822 mmix_asm_output_align (FILE *stream, int power)
1824 /* We need to record the needed alignment of this section in the object,
1825 so we have to output an alignment directive. Use a .p2align (not
1826 .align) so people will never have to wonder about whether the
1827 argument is in number of bytes or the log2 thereof. We do it in
1828 addition to the LOC directive, so nothing needs tweaking when
1829 copy-pasting assembly into mmixal. */
1830 fprintf (stream, "\t.p2align %d\n", power);
1831 fprintf (stream, "\tLOC @+(%d-@)&%d\n", 1 << power, (1 << power) - 1);
1834 /* DBX_REGISTER_NUMBER. */
1837 mmix_dbx_register_number (int regno)
1839 /* Adjust the register number to the one it will be output as, dammit.
1840 It'd be nice if we could check the assumption that we're filling a
1841 gap, but every register between the last saved register and parameter
1842 registers might be a valid parameter register. */
1843 regno = MMIX_OUTPUT_REGNO (regno);
1845 /* We need to renumber registers to get the number of the return address
1846 register in the range 0..255. It is also space-saving if registers
1847 mentioned in the call-frame information (which uses this function by
1848 defaulting DWARF_FRAME_REGNUM to DBX_REGISTER_NUMBER) are numbered
1849 0 .. 63. So map 224 .. 256+15 -> 0 .. 47 and 0 .. 223 -> 48..223+48. */
1850 return regno >= 224 ? (regno - 224) : (regno + 48);
1853 /* End of target macro support functions.
1855 Now the MMIX port's own functions. First the exported ones. */
1857 /* Wrapper for get_hard_reg_initial_val since integrate.h isn't included
1858 from insn-emit.c. */
1861 mmix_get_hard_reg_initial_val (enum machine_mode mode, int regno)
1863 return get_hard_reg_initial_val (mode, regno);
1866 /* Nonzero when the function epilogue is simple enough that a single
1867 "POP %d,0" should be used even within the function. */
1870 mmix_use_simple_return (void)
1874 int stack_space_to_allocate
1875 = (crtl->outgoing_args_size
1876 + crtl->args.pretend_args_size
1877 + get_frame_size () + 7) & ~7;
1879 if (!TARGET_USE_RETURN_INSN || !reload_completed)
1883 regno >= MMIX_FIRST_GLOBAL_REGNUM;
1885 /* Note that we assume that the frame-pointer-register is one of these
1886 registers, in which case we don't count it here. */
1887 if ((((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
1888 && df_regs_ever_live_p (regno) && !call_used_regs[regno]))
1889 || IS_MMIX_EH_RETURN_DATA_REG (regno))
1892 if (frame_pointer_needed)
1893 stack_space_to_allocate += 8;
1895 if (MMIX_CFUN_HAS_LANDING_PAD)
1896 stack_space_to_allocate += 16;
1897 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
1898 stack_space_to_allocate += 8;
1900 return stack_space_to_allocate == 0;
1904 /* Expands the function prologue into RTX. */
1907 mmix_expand_prologue (void)
1909 HOST_WIDE_INT locals_size = get_frame_size ();
1911 HOST_WIDE_INT stack_space_to_allocate
1912 = (crtl->outgoing_args_size
1913 + crtl->args.pretend_args_size
1914 + locals_size + 7) & ~7;
1915 HOST_WIDE_INT offset = -8;
1917 /* Add room needed to save global non-register-stack registers. */
1919 regno >= MMIX_FIRST_GLOBAL_REGNUM;
1921 /* Note that we assume that the frame-pointer-register is one of these
1922 registers, in which case we don't count it here. */
1923 if ((((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
1924 && df_regs_ever_live_p (regno) && !call_used_regs[regno]))
1925 || IS_MMIX_EH_RETURN_DATA_REG (regno))
1926 stack_space_to_allocate += 8;
1928 /* If we do have a frame-pointer, add room for it. */
1929 if (frame_pointer_needed)
1930 stack_space_to_allocate += 8;
1932 /* If we have a non-local label, we need to be able to unwind to it, so
1933 store the current register stack pointer. Also store the return
1934 address if we do that. */
1935 if (MMIX_CFUN_HAS_LANDING_PAD)
1936 stack_space_to_allocate += 16;
1937 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
1938 /* If we do have a saved return-address slot, add room for it. */
1939 stack_space_to_allocate += 8;
1941 /* Make sure we don't get an unaligned stack. */
1942 if ((stack_space_to_allocate % 8) != 0)
1943 internal_error ("stack frame not a multiple of 8 bytes: %wd",
1944 stack_space_to_allocate);
1946 if (crtl->args.pretend_args_size)
1948 int mmix_first_vararg_reg
1949 = (MMIX_FIRST_INCOMING_ARG_REGNUM
1950 + (MMIX_MAX_ARGS_IN_REGS
1951 - crtl->args.pretend_args_size / 8));
1954 = MMIX_FIRST_INCOMING_ARG_REGNUM + MMIX_MAX_ARGS_IN_REGS - 1;
1955 regno >= mmix_first_vararg_reg;
1960 HOST_WIDE_INT stack_chunk
1961 = stack_space_to_allocate > (256 - 8)
1962 ? (256 - 8) : stack_space_to_allocate;
1964 mmix_emit_sp_add (-stack_chunk);
1965 offset += stack_chunk;
1966 stack_space_to_allocate -= stack_chunk;
1969 /* These registers aren't actually saved (as in "will be
1970 restored"), so don't tell DWARF2 they're saved. */
1971 emit_move_insn (gen_rtx_MEM (DImode,
1972 plus_constant (stack_pointer_rtx,
1974 gen_rtx_REG (DImode, regno));
1979 /* Store the frame-pointer. */
1981 if (frame_pointer_needed)
1987 /* Get 8 less than otherwise, since we need to reach offset + 8. */
1988 HOST_WIDE_INT stack_chunk
1989 = stack_space_to_allocate > (256 - 8 - 8)
1990 ? (256 - 8 - 8) : stack_space_to_allocate;
1992 mmix_emit_sp_add (-stack_chunk);
1994 offset += stack_chunk;
1995 stack_space_to_allocate -= stack_chunk;
1998 insn = emit_move_insn (gen_rtx_MEM (DImode,
1999 plus_constant (stack_pointer_rtx,
2001 hard_frame_pointer_rtx);
2002 RTX_FRAME_RELATED_P (insn) = 1;
2003 insn = emit_insn (gen_adddi3 (hard_frame_pointer_rtx,
2005 GEN_INT (offset + 8)));
2006 RTX_FRAME_RELATED_P (insn) = 1;
2010 if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
2015 /* Store the return-address, if one is needed on the stack. We
2016 usually store it in a register when needed, but that doesn't work
2017 with -fexceptions. */
2021 /* Get 8 less than otherwise, since we need to reach offset + 8. */
2022 HOST_WIDE_INT stack_chunk
2023 = stack_space_to_allocate > (256 - 8 - 8)
2024 ? (256 - 8 - 8) : stack_space_to_allocate;
2026 mmix_emit_sp_add (-stack_chunk);
2028 offset += stack_chunk;
2029 stack_space_to_allocate -= stack_chunk;
2032 tmpreg = gen_rtx_REG (DImode, 255);
2033 retreg = gen_rtx_REG (DImode, MMIX_rJ_REGNUM);
2035 /* Dwarf2 code is confused by the use of a temporary register for
2036 storing the return address, so we have to express it as a note,
2037 which we attach to the actual store insn. */
2038 emit_move_insn (tmpreg, retreg);
2040 insn = emit_move_insn (gen_rtx_MEM (DImode,
2041 plus_constant (stack_pointer_rtx,
2044 RTX_FRAME_RELATED_P (insn) = 1;
2046 = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
2047 gen_rtx_SET (VOIDmode,
2048 gen_rtx_MEM (DImode,
2049 plus_constant (stack_pointer_rtx,
2056 else if (MMIX_CFUN_HAS_LANDING_PAD)
2059 if (MMIX_CFUN_HAS_LANDING_PAD)
2061 /* Store the register defining the numbering of local registers, so
2062 we know how long to unwind the register stack. */
2066 /* Get 8 less than otherwise, since we need to reach offset + 8. */
2067 HOST_WIDE_INT stack_chunk
2068 = stack_space_to_allocate > (256 - 8 - 8)
2069 ? (256 - 8 - 8) : stack_space_to_allocate;
2071 mmix_emit_sp_add (-stack_chunk);
2073 offset += stack_chunk;
2074 stack_space_to_allocate -= stack_chunk;
2077 /* We don't tell dwarf2 about this one; we just have it to unwind
2078 the register stack at landing pads. FIXME: It's a kludge because
2079 we can't describe the effect of the PUSHJ and PUSHGO insns on the
2080 register stack at the moment. Best thing would be to handle it
2081 like stack-pointer offsets. Better: some hook into dwarf2out.c
2082 to produce DW_CFA_expression:s that specify the increment of rO,
2083 and unwind it at eh_return (preferred) or at the landing pad.
2084 Then saves to $0..$G-1 could be specified through that register. */
2086 emit_move_insn (gen_rtx_REG (DImode, 255),
2087 gen_rtx_REG (DImode,
2089 emit_move_insn (gen_rtx_MEM (DImode,
2090 plus_constant (stack_pointer_rtx, offset)),
2091 gen_rtx_REG (DImode, 255));
2095 /* After the return-address and the frame-pointer, we have the local
2096 variables. They're the ones that may have an "unaligned" size. */
2097 offset -= (locals_size + 7) & ~7;
2099 /* Now store all registers that are global, i.e. not saved by the
2100 register file machinery.
2102 It is assumed that the frame-pointer is one of these registers, so it
2103 is explicitly excluded in the count. */
2106 regno >= MMIX_FIRST_GLOBAL_REGNUM;
2108 if (((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
2109 && df_regs_ever_live_p (regno) && ! call_used_regs[regno])
2110 || IS_MMIX_EH_RETURN_DATA_REG (regno))
2116 HOST_WIDE_INT stack_chunk
2117 = (stack_space_to_allocate > (256 - offset - 8)
2118 ? (256 - offset - 8) : stack_space_to_allocate);
2120 mmix_emit_sp_add (-stack_chunk);
2121 offset += stack_chunk;
2122 stack_space_to_allocate -= stack_chunk;
2125 insn = emit_move_insn (gen_rtx_MEM (DImode,
2126 plus_constant (stack_pointer_rtx,
2128 gen_rtx_REG (DImode, regno));
2129 RTX_FRAME_RELATED_P (insn) = 1;
2133 /* Finally, allocate room for outgoing args and local vars if room
2134 wasn't allocated above. */
2135 if (stack_space_to_allocate)
2136 mmix_emit_sp_add (-stack_space_to_allocate);
2139 /* Expands the function epilogue into RTX. */
2142 mmix_expand_epilogue (void)
2144 HOST_WIDE_INT locals_size = get_frame_size ();
2146 HOST_WIDE_INT stack_space_to_deallocate
2147 = (crtl->outgoing_args_size
2148 + crtl->args.pretend_args_size
2149 + locals_size + 7) & ~7;
2151 /* The first address to access is beyond the outgoing_args area. */
2152 HOST_WIDE_INT offset = crtl->outgoing_args_size;
2154 /* Add the space for global non-register-stack registers.
2155 It is assumed that the frame-pointer register can be one of these
2156 registers, in which case it is excluded from the count when needed. */
2158 regno >= MMIX_FIRST_GLOBAL_REGNUM;
2160 if (((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
2161 && df_regs_ever_live_p (regno) && !call_used_regs[regno])
2162 || IS_MMIX_EH_RETURN_DATA_REG (regno))
2163 stack_space_to_deallocate += 8;
2165 /* Add in the space for register stack-pointer. If so, always add room
2166 for the saved PC. */
2167 if (MMIX_CFUN_HAS_LANDING_PAD)
2168 stack_space_to_deallocate += 16;
2169 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
2170 /* If we have a saved return-address slot, add it in. */
2171 stack_space_to_deallocate += 8;
2173 /* Add in the frame-pointer. */
2174 if (frame_pointer_needed)
2175 stack_space_to_deallocate += 8;
2177 /* Make sure we don't get an unaligned stack. */
2178 if ((stack_space_to_deallocate % 8) != 0)
2179 internal_error ("stack frame not a multiple of octabyte: %wd",
2180 stack_space_to_deallocate);
2182 /* We will add back small offsets to the stack pointer as we go.
2183 First, we restore all registers that are global, i.e. not saved by
2184 the register file machinery. */
2186 for (regno = MMIX_FIRST_GLOBAL_REGNUM;
2189 if (((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
2190 && df_regs_ever_live_p (regno) && !call_used_regs[regno])
2191 || IS_MMIX_EH_RETURN_DATA_REG (regno))
2195 mmix_emit_sp_add (offset);
2196 stack_space_to_deallocate -= offset;
2200 emit_move_insn (gen_rtx_REG (DImode, regno),
2201 gen_rtx_MEM (DImode,
2202 plus_constant (stack_pointer_rtx,
2207 /* Here is where the local variables were. As in the prologue, they
2208 might be of an unaligned size. */
2209 offset += (locals_size + 7) & ~7;
2211 /* The saved register stack pointer is just below the frame-pointer
2212 register. We don't need to restore it "manually"; the POP
2213 instruction does that. */
2214 if (MMIX_CFUN_HAS_LANDING_PAD)
2216 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
2217 /* The return-address slot is just below the frame-pointer register.
2218 We don't need to restore it because we don't really use it. */
2221 /* Get back the old frame-pointer-value. */
2222 if (frame_pointer_needed)
2226 mmix_emit_sp_add (offset);
2228 stack_space_to_deallocate -= offset;
2232 emit_move_insn (hard_frame_pointer_rtx,
2233 gen_rtx_MEM (DImode,
2234 plus_constant (stack_pointer_rtx,
2239 /* We do not need to restore pretended incoming args, just add back
2241 if (stack_space_to_deallocate != 0)
2242 mmix_emit_sp_add (stack_space_to_deallocate);
2244 if (crtl->calls_eh_return)
2245 /* Adjust the (normal) stack-pointer to that of the receiver.
2246 FIXME: It would be nice if we could also adjust the register stack
2247 here, but we need to express it through DWARF 2 too. */
2248 emit_insn (gen_adddi3 (stack_pointer_rtx, stack_pointer_rtx,
2249 gen_rtx_REG (DImode,
2250 MMIX_EH_RETURN_STACKADJ_REGNUM)));
2253 /* Output an optimal sequence for setting a register to a specific
2254 constant. Used in an alternative for const_ints in movdi, and when
2255 using large stack-frame offsets.
2257 Use do_begin_end to say if a line-starting TAB and newline before the
2258 first insn and after the last insn is wanted. */
2261 mmix_output_register_setting (FILE *stream,
2263 HOST_WIDEST_INT value,
2267 fprintf (stream, "\t");
2269 if (mmix_shiftable_wyde_value ((unsigned HOST_WIDEST_INT) value))
2271 /* First, the one-insn cases. */
2272 mmix_output_shiftvalue_op_from_str (stream, "SET",
2273 (unsigned HOST_WIDEST_INT)
2275 fprintf (stream, " %s,", reg_names[regno]);
2276 mmix_output_shifted_value (stream, (unsigned HOST_WIDEST_INT) value);
2278 else if (mmix_shiftable_wyde_value (-(unsigned HOST_WIDEST_INT) value))
2280 /* We do this to get a bit more legible assembly code. The next
2281 alternative is mostly redundant with this. */
2283 mmix_output_shiftvalue_op_from_str (stream, "SET",
2284 -(unsigned HOST_WIDEST_INT)
2286 fprintf (stream, " %s,", reg_names[regno]);
2287 mmix_output_shifted_value (stream, -(unsigned HOST_WIDEST_INT) value);
2288 fprintf (stream, "\n\tNEGU %s,0,%s", reg_names[regno],
2291 else if (mmix_shiftable_wyde_value (~(unsigned HOST_WIDEST_INT) value))
2293 /* Slightly more expensive, the two-insn cases. */
2295 /* FIXME: We could of course also test if 0..255-N or ~(N | 1..255)
2296 is shiftable, or any other one-insn transformation of the value.
2297 FIXME: Check first if the value is "shiftable" by two loading
2298 with two insns, since it makes more readable assembly code (if
2299 anyone else cares). */
2301 mmix_output_shiftvalue_op_from_str (stream, "SET",
2302 ~(unsigned HOST_WIDEST_INT)
2304 fprintf (stream, " %s,", reg_names[regno]);
2305 mmix_output_shifted_value (stream, ~(unsigned HOST_WIDEST_INT) value);
2306 fprintf (stream, "\n\tNOR %s,%s,0", reg_names[regno],
2311 /* The generic case. 2..4 insns. */
2312 static const char *const higher_parts[] = {"L", "ML", "MH", "H"};
2313 const char *op = "SET";
2314 const char *line_begin = "";
2317 HOST_WIDEST_INT tmpvalue = value;
2319 /* Compute the number of insns needed to output this constant. */
2320 for (i = 0; i < 4 && tmpvalue != 0; i++)
2322 if (tmpvalue & 65535)
2326 if (TARGET_BASE_ADDRESSES && insns == 3)
2328 /* The number three is based on a static observation on
2329 ghostscript-6.52. Two and four are excluded because there
2330 are too many such constants, and each unique constant (maybe
2331 offset by 1..255) were used few times compared to other uses,
2334 We use base-plus-offset addressing to force it into a global
2335 register; we just use a "LDA reg,VALUE", which will cause the
2336 assembler and linker to DTRT (for constants as well as
2338 fprintf (stream, "LDA %s,", reg_names[regno]);
2339 mmix_output_octa (stream, value, 0);
2343 /* Output pertinent parts of the 4-wyde sequence.
2344 Still more to do if we want this to be optimal, but hey...
2345 Note that the zero case has been handled above. */
2346 for (i = 0; i < 4 && value != 0; i++)
2350 fprintf (stream, "%s%s%s %s,#%x", line_begin, op,
2351 higher_parts[i], reg_names[regno],
2352 (int) (value & 65535));
2353 /* The first one sets the rest of the bits to 0, the next
2354 ones add set bits. */
2356 line_begin = "\n\t";
2365 fprintf (stream, "\n");
2368 /* Return 1 if value is 0..65535*2**(16*N) for N=0..3.
2372 mmix_shiftable_wyde_value (unsigned HOST_WIDEST_INT value)
2374 /* Shift by 16 bits per group, stop when we've found two groups with
2377 int has_candidate = 0;
2379 for (i = 0; i < 4; i++)
2395 /* X and Y are two things to compare using CODE. Return the rtx for
2396 the cc-reg in the proper mode. */
2399 mmix_gen_compare_reg (RTX_CODE code, rtx x, rtx y)
2401 enum machine_mode ccmode = SELECT_CC_MODE (code, x, y);
2402 return gen_reg_rtx (ccmode);
2405 /* Local (static) helper functions. */
2408 mmix_emit_sp_add (HOST_WIDE_INT offset)
2414 /* Negative stack-pointer adjustments are allocations and appear in
2415 the prologue only. We mark them as frame-related so unwind and
2416 debug info is properly emitted for them. */
2418 insn = emit_insn (gen_adddi3 (stack_pointer_rtx,
2423 rtx tmpr = gen_rtx_REG (DImode, 255);
2424 RTX_FRAME_RELATED_P (emit_move_insn (tmpr, GEN_INT (offset))) = 1;
2425 insn = emit_insn (gen_adddi3 (stack_pointer_rtx,
2426 stack_pointer_rtx, tmpr));
2428 RTX_FRAME_RELATED_P (insn) = 1;
2432 /* Positive adjustments are in the epilogue only. Don't mark them
2433 as "frame-related" for unwind info. */
2434 if (CONST_OK_FOR_LETTER_P (offset, 'L'))
2435 emit_insn (gen_adddi3 (stack_pointer_rtx,
2440 rtx tmpr = gen_rtx_REG (DImode, 255);
2441 emit_move_insn (tmpr, GEN_INT (offset));
2442 insn = emit_insn (gen_adddi3 (stack_pointer_rtx,
2443 stack_pointer_rtx, tmpr));
2448 /* Print operator suitable for doing something with a shiftable
2449 wyde. The type of operator is passed as an asm output modifier. */
2452 mmix_output_shiftvalue_op_from_str (FILE *stream,
2454 HOST_WIDEST_INT value)
2456 static const char *const op_part[] = {"L", "ML", "MH", "H"};
2459 if (! mmix_shiftable_wyde_value (value))
2461 char s[sizeof ("0xffffffffffffffff")];
2462 sprintf (s, HOST_WIDEST_INT_PRINT_HEX, value);
2463 internal_error ("MMIX Internal: %s is not a shiftable int", s);
2466 for (i = 0; i < 4; i++)
2468 /* We know we're through when we find one-bits in the low
2472 fprintf (stream, "%s%s", mainop, op_part[i]);
2478 /* No bits set? Then it must have been zero. */
2479 fprintf (stream, "%sL", mainop);
2482 /* Print a 64-bit value, optionally prefixed by assembly pseudo. */
2485 mmix_output_octa (FILE *stream, HOST_WIDEST_INT value, int do_begin_end)
2487 /* Snipped from final.c:output_addr_const. We need to avoid the
2488 presumed universal "0x" prefix. We can do it by replacing "0x" with
2489 "#0" here; we must avoid a space in the operands and no, the zero
2490 won't cause the number to be assumed in octal format. */
2491 char hex_format[sizeof (HOST_WIDEST_INT_PRINT_HEX)];
2494 fprintf (stream, "\tOCTA ");
2496 strcpy (hex_format, HOST_WIDEST_INT_PRINT_HEX);
2497 hex_format[0] = '#';
2498 hex_format[1] = '0';
2500 /* Provide a few alternative output formats depending on the number, to
2501 improve legibility of assembler output. */
2502 if ((value < (HOST_WIDEST_INT) 0 && value > (HOST_WIDEST_INT) -10000)
2503 || (value >= (HOST_WIDEST_INT) 0 && value <= (HOST_WIDEST_INT) 16384))
2504 fprintf (stream, "%d", (int) value);
2505 else if (value > (HOST_WIDEST_INT) 0
2506 && value < ((HOST_WIDEST_INT) 1 << 31) * 2)
2507 fprintf (stream, "#%x", (unsigned int) value);
2509 fprintf (stream, hex_format, value);
2512 fprintf (stream, "\n");
2515 /* Print the presumed shiftable wyde argument shifted into place (to
2516 be output with an operand). */
2519 mmix_output_shifted_value (FILE *stream, HOST_WIDEST_INT value)
2523 if (! mmix_shiftable_wyde_value (value))
2526 sprintf (s, HOST_WIDEST_INT_PRINT_HEX, value);
2527 internal_error ("MMIX Internal: %s is not a shiftable int", s);
2530 for (i = 0; i < 4; i++)
2532 /* We know we're through when we find one-bits in the low 16 bits. */
2535 fprintf (stream, "#%x", (int) (value & 0xffff));
2542 /* No bits set? Then it must have been zero. */
2543 fprintf (stream, "0");
2546 /* Output an MMIX condition name corresponding to an operator
2548 (comparison_operator [(comparison_operator ...) (const_int 0)])
2549 which means we have to look at *two* operators.
2551 The argument "reversed" refers to reversal of the condition (not the
2552 same as swapping the arguments). */
2555 mmix_output_condition (FILE *stream, rtx x, int reversed)
2561 /* The normal output cc-code. */
2562 const char *const normal;
2564 /* The reversed cc-code, or NULL if invalid. */
2565 const char *const reversed;
2570 enum machine_mode cc_mode;
2572 /* Terminated with {UNKNOWN, NULL, NULL} */
2573 const struct cc_conv *const convs;
2577 #define CCEND {UNKNOWN, NULL, NULL}
2579 static const struct cc_conv cc_fun_convs[]
2580 = {{ORDERED, "Z", "P"},
2581 {UNORDERED, "P", "Z"},
2583 static const struct cc_conv cc_fp_convs[]
2587 static const struct cc_conv cc_fpeq_convs[]
2591 static const struct cc_conv cc_uns_convs[]
2592 = {{GEU, "NN", "N"},
2597 static const struct cc_conv cc_signed_convs[]
2605 static const struct cc_conv cc_di_convs[]
2617 static const struct cc_type_conv cc_convs[]
2618 = {{CC_FUNmode, cc_fun_convs},
2619 {CC_FPmode, cc_fp_convs},
2620 {CC_FPEQmode, cc_fpeq_convs},
2621 {CC_UNSmode, cc_uns_convs},
2622 {CCmode, cc_signed_convs},
2623 {DImode, cc_di_convs}};
2628 enum machine_mode mode = GET_MODE (XEXP (x, 0));
2629 RTX_CODE cc = GET_CODE (x);
2631 for (i = 0; i < ARRAY_SIZE (cc_convs); i++)
2633 if (mode == cc_convs[i].cc_mode)
2635 for (j = 0; cc_convs[i].convs[j].cc != UNKNOWN; j++)
2636 if (cc == cc_convs[i].convs[j].cc)
2639 = (reversed ? cc_convs[i].convs[j].reversed
2640 : cc_convs[i].convs[j].normal);
2642 if (mmix_cc == NULL)
2643 fatal_insn ("MMIX Internal: Trying to output invalidly\
2644 reversed condition:", x);
2646 fprintf (stream, "%s", mmix_cc);
2650 fatal_insn ("MMIX Internal: What's the CC of this?", x);
2654 fatal_insn ("MMIX Internal: What is the CC of this?", x);
2657 /* Return the bit-value for a const_int or const_double. */
2659 static HOST_WIDEST_INT
2662 unsigned HOST_WIDEST_INT retval;
2664 if (GET_CODE (x) == CONST_INT)
2667 /* We make a little song and dance because converting to long long in
2668 gcc-2.7.2 is broken. I still want people to be able to use it for
2669 cross-compilation to MMIX. */
2670 if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == VOIDmode)
2672 if (sizeof (HOST_WIDE_INT) < sizeof (HOST_WIDEST_INT))
2674 retval = (unsigned) CONST_DOUBLE_LOW (x) / 2;
2676 retval |= CONST_DOUBLE_LOW (x) & 1;
2679 (unsigned HOST_WIDEST_INT) CONST_DOUBLE_HIGH (x)
2680 << (HOST_BITS_PER_LONG);
2683 retval = CONST_DOUBLE_HIGH (x);
2688 if (GET_CODE (x) == CONST_DOUBLE)
2690 REAL_VALUE_TYPE value;
2692 /* FIXME: This macro is not in the manual but should be. */
2693 REAL_VALUE_FROM_CONST_DOUBLE (value, x);
2695 if (GET_MODE (x) == DFmode)
2699 REAL_VALUE_TO_TARGET_DOUBLE (value, bits);
2701 /* The double cast is necessary to avoid getting the long
2702 sign-extended to unsigned long long(!) when they're of
2703 different size (usually 32-bit hosts). */
2705 ((unsigned HOST_WIDEST_INT) (unsigned long) bits[0]
2706 << (unsigned HOST_WIDEST_INT) 32U)
2707 | (unsigned HOST_WIDEST_INT) (unsigned long) bits[1];
2709 else if (GET_MODE (x) == SFmode)
2712 REAL_VALUE_TO_TARGET_SINGLE (value, bits);
2714 return (unsigned long) bits;
2718 fatal_insn ("MMIX Internal: This is not a constant:", x);
2721 /* Worker function for TARGET_PROMOTE_FUNCTION_MODE. */
2724 mmix_promote_function_mode (const_tree type ATTRIBUTE_UNUSED,
2725 enum machine_mode mode,
2726 int *punsignedp ATTRIBUTE_UNUSED,
2727 const_tree fntype ATTRIBUTE_UNUSED,
2730 /* Apparently not doing TRT if int < register-size. FIXME: Perhaps
2731 FUNCTION_VALUE and LIBCALL_VALUE needs tweaking as some ports say. */
2732 if (for_return == 1)
2735 /* Promotion of modes currently generates slow code, extending before
2736 operation, so we do it only for arguments. */
2737 if (GET_MODE_CLASS (mode) == MODE_INT
2738 && GET_MODE_SIZE (mode) < 8)
2743 /* Worker function for TARGET_STRUCT_VALUE_RTX. */
2746 mmix_struct_value_rtx (tree fntype ATTRIBUTE_UNUSED,
2747 int incoming ATTRIBUTE_UNUSED)
2749 return gen_rtx_REG (Pmode, MMIX_STRUCT_VALUE_REGNUM);
2752 /* Worker function for TARGET_FRAME_POINTER_REQUIRED.
2754 FIXME: Is this requirement built-in? Anyway, we should try to get rid
2755 of it; we can deduce the value. */
2758 mmix_frame_pointer_required (void)
2760 return (cfun->has_nonlocal_label);
2765 * eval: (c-set-style "gnu")
2766 * indent-tabs-mode: t