1 /* Definitions of target machine for GNU compiler, for MMIX.
2 Copyright (C) 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
3 Contributed by Hans-Peter Nilsson (hp@bitrange.com)
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
24 #include "coretypes.h"
28 #include "hard-reg-set.h"
30 #include "insn-config.h"
42 #include "integrate.h"
44 #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, regs_ever_live[] 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 && regs_ever_live[MMIX_rJ_REGNUM]) \
69 || !leaf_function_p ()))
71 #define IS_MMIX_EH_RETURN_DATA_REG(REGNO) \
72 (current_function_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 && current_function_return_rtx != NULL \
99 && ! current_function_returns_struct) \
100 ? (GET_CODE (current_function_return_rtx) == PARALLEL \
101 ? GET_NUM_ELEM (XVEC (current_function_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 /* We ignore some options with arguments. They are passed to the linker,
110 but also ends up here because they start with "-m". We tell the driver
111 to store them in a variable we don't inspect. */
112 const char *mmix_cc1_ignored_option;
114 /* Declarations of locals. */
116 /* Intermediate for insn output. */
117 static int mmix_output_destination_register;
119 static void mmix_output_shiftvalue_op_from_str
120 (FILE *, const char *, HOST_WIDEST_INT);
121 static void mmix_output_shifted_value (FILE *, HOST_WIDEST_INT);
122 static void mmix_output_condition (FILE *, rtx, int);
123 static HOST_WIDEST_INT mmix_intval (rtx);
124 static void mmix_output_octa (FILE *, HOST_WIDEST_INT, int);
125 static bool mmix_assemble_integer (rtx, unsigned int, int);
126 static struct machine_function *mmix_init_machine_status (void);
127 static void mmix_encode_section_info (tree, rtx, int);
128 static const char *mmix_strip_name_encoding (const char *);
129 static void mmix_emit_sp_add (HOST_WIDE_INT offset);
130 static void mmix_target_asm_function_prologue (FILE *, HOST_WIDE_INT);
131 static void mmix_target_asm_function_end_prologue (FILE *);
132 static void mmix_target_asm_function_epilogue (FILE *, HOST_WIDE_INT);
133 static void mmix_reorg (void);
134 static void mmix_asm_output_mi_thunk
135 (FILE *, tree, HOST_WIDE_INT, HOST_WIDE_INT, tree);
136 static void mmix_setup_incoming_varargs
137 (CUMULATIVE_ARGS *, enum machine_mode, tree, int *, int);
138 static void mmix_file_start (void);
139 static void mmix_file_end (void);
140 static bool mmix_rtx_costs (rtx, int, int, int *);
141 static rtx mmix_struct_value_rtx (tree, int);
142 static bool mmix_pass_by_reference (const CUMULATIVE_ARGS *,
143 enum machine_mode, tree, bool);
145 /* Target structure macros. Listed by node. See `Using and Porting GCC'
146 for a general description. */
148 /* Node: Function Entry */
150 #undef TARGET_ASM_BYTE_OP
151 #define TARGET_ASM_BYTE_OP NULL
152 #undef TARGET_ASM_ALIGNED_HI_OP
153 #define TARGET_ASM_ALIGNED_HI_OP NULL
154 #undef TARGET_ASM_ALIGNED_SI_OP
155 #define TARGET_ASM_ALIGNED_SI_OP NULL
156 #undef TARGET_ASM_ALIGNED_DI_OP
157 #define TARGET_ASM_ALIGNED_DI_OP NULL
158 #undef TARGET_ASM_INTEGER
159 #define TARGET_ASM_INTEGER mmix_assemble_integer
161 #undef TARGET_ASM_FUNCTION_PROLOGUE
162 #define TARGET_ASM_FUNCTION_PROLOGUE mmix_target_asm_function_prologue
164 #undef TARGET_ASM_FUNCTION_END_PROLOGUE
165 #define TARGET_ASM_FUNCTION_END_PROLOGUE mmix_target_asm_function_end_prologue
167 #undef TARGET_ASM_FUNCTION_EPILOGUE
168 #define TARGET_ASM_FUNCTION_EPILOGUE mmix_target_asm_function_epilogue
170 #undef TARGET_ENCODE_SECTION_INFO
171 #define TARGET_ENCODE_SECTION_INFO mmix_encode_section_info
172 #undef TARGET_STRIP_NAME_ENCODING
173 #define TARGET_STRIP_NAME_ENCODING mmix_strip_name_encoding
175 #undef TARGET_ASM_OUTPUT_MI_THUNK
176 #define TARGET_ASM_OUTPUT_MI_THUNK mmix_asm_output_mi_thunk
177 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
178 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall
179 #undef TARGET_ASM_FILE_START
180 #define TARGET_ASM_FILE_START mmix_file_start
181 #undef TARGET_ASM_FILE_START_FILE_DIRECTIVE
182 #define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
183 #undef TARGET_ASM_FILE_END
184 #define TARGET_ASM_FILE_END mmix_file_end
186 #undef TARGET_RTX_COSTS
187 #define TARGET_RTX_COSTS mmix_rtx_costs
188 #undef TARGET_ADDRESS_COST
189 #define TARGET_ADDRESS_COST hook_int_rtx_0
191 #undef TARGET_MACHINE_DEPENDENT_REORG
192 #define TARGET_MACHINE_DEPENDENT_REORG mmix_reorg
194 #undef TARGET_PROMOTE_FUNCTION_ARGS
195 #define TARGET_PROMOTE_FUNCTION_ARGS hook_bool_tree_true
197 /* Apparently not doing TRT if int < register-size. FIXME: Perhaps
198 FUNCTION_VALUE and LIBCALL_VALUE needs tweaking as some ports say. */
199 #undef TARGET_PROMOTE_FUNCTION_RETURN
200 #define TARGET_PROMOTE_FUNCTION_RETURN hook_bool_tree_true
203 #undef TARGET_STRUCT_VALUE_RTX
204 #define TARGET_STRUCT_VALUE_RTX mmix_struct_value_rtx
205 #undef TARGET_SETUP_INCOMING_VARARGS
206 #define TARGET_SETUP_INCOMING_VARARGS mmix_setup_incoming_varargs
207 #undef TARGET_PASS_BY_REFERENCE
208 #define TARGET_PASS_BY_REFERENCE mmix_pass_by_reference
209 #undef TARGET_CALLEE_COPIES
210 #define TARGET_CALLEE_COPIES hook_bool_CUMULATIVE_ARGS_mode_tree_bool_true
212 struct gcc_target targetm = TARGET_INITIALIZER;
214 /* Functions that are expansions for target macros.
215 See Target Macros in `Using and Porting GCC'. */
217 /* OVERRIDE_OPTIONS. */
220 mmix_override_options (void)
222 /* Should we err or should we warn? Hmm. At least we must neutralize
223 it. For example the wrong kind of case-tables will be generated with
224 PIC; we use absolute address items for mmixal compatibility. FIXME:
225 They could be relative if we just elide them to after all pertinent
229 warning ("-f%s not supported: ignored", (flag_pic > 1) ? "PIC" : "pic");
234 /* INIT_EXPANDERS. */
237 mmix_init_expanders (void)
239 init_machine_status = mmix_init_machine_status;
242 /* Set the per-function data. */
244 static struct machine_function *
245 mmix_init_machine_status (void)
247 return ggc_alloc_cleared (sizeof (struct machine_function));
251 We have trouble getting the address of stuff that is located at other
252 than 32-bit alignments (GETA requirements), so try to give everything
253 at least 32-bit alignment. */
256 mmix_data_alignment (tree type ATTRIBUTE_UNUSED, int basic_align)
258 if (basic_align < 32)
264 /* CONSTANT_ALIGNMENT. */
267 mmix_constant_alignment (tree constant ATTRIBUTE_UNUSED, int basic_align)
269 if (basic_align < 32)
275 /* LOCAL_ALIGNMENT. */
278 mmix_local_alignment (tree type ATTRIBUTE_UNUSED, int basic_align)
280 if (basic_align < 32)
286 /* CONDITIONAL_REGISTER_USAGE. */
289 mmix_conditional_register_usage (void)
295 static const int gnu_abi_reg_alloc_order[]
296 = MMIX_GNU_ABI_REG_ALLOC_ORDER;
298 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
299 reg_alloc_order[i] = gnu_abi_reg_alloc_order[i];
301 /* Change the default from the mmixware ABI. For the GNU ABI,
302 $15..$30 are call-saved just as $0..$14. There must be one
303 call-clobbered local register for the "hole" that holds the
304 number of saved local registers saved by PUSHJ/PUSHGO during the
305 function call, receiving the return value at return. So best is
306 to use the highest, $31. It's already marked call-clobbered for
308 for (i = 15; i <= 30; i++)
309 call_used_regs[i] = 0;
311 /* "Unfix" the parameter registers. */
312 for (i = MMIX_RESERVED_GNU_ARG_0_REGNUM;
313 i < MMIX_RESERVED_GNU_ARG_0_REGNUM + MMIX_MAX_ARGS_IN_REGS;
318 /* Step over the ":" in special register names. */
319 if (! TARGET_TOPLEVEL_SYMBOLS)
320 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
321 if (reg_names[i][0] == ':')
326 All registers that are part of the register stack and that will be
330 mmix_local_regno (int regno)
332 return regno <= MMIX_LAST_STACK_REGISTER_REGNUM && !call_used_regs[regno];
335 /* PREFERRED_RELOAD_CLASS.
336 We need to extend the reload class of REMAINDER_REG and HIMULT_REG. */
339 mmix_preferred_reload_class (rtx x ATTRIBUTE_UNUSED, enum reg_class class)
341 /* FIXME: Revisit. */
342 return GET_CODE (x) == MOD && GET_MODE (x) == DImode
343 ? REMAINDER_REG : class;
346 /* PREFERRED_OUTPUT_RELOAD_CLASS.
347 We need to extend the reload class of REMAINDER_REG and HIMULT_REG. */
350 mmix_preferred_output_reload_class (rtx x ATTRIBUTE_UNUSED,
351 enum reg_class class)
353 /* FIXME: Revisit. */
354 return GET_CODE (x) == MOD && GET_MODE (x) == DImode
355 ? REMAINDER_REG : class;
358 /* SECONDARY_RELOAD_CLASS.
359 We need to reload regs of REMAINDER_REG and HIMULT_REG elsewhere. */
362 mmix_secondary_reload_class (enum reg_class class,
363 enum machine_mode mode ATTRIBUTE_UNUSED,
364 rtx x ATTRIBUTE_UNUSED,
365 int in_p ATTRIBUTE_UNUSED)
367 if (class == REMAINDER_REG
368 || class == HIMULT_REG
369 || class == SYSTEM_REGS)
375 /* CONST_OK_FOR_LETTER_P. */
378 mmix_const_ok_for_letter_p (HOST_WIDE_INT value, int c)
381 (c == 'I' ? value >= 0 && value <= 255
382 : c == 'J' ? value >= 0 && value <= 65535
383 : c == 'K' ? value <= 0 && value >= -255
384 : c == 'L' ? mmix_shiftable_wyde_value (value)
385 : c == 'M' ? value == 0
386 : c == 'N' ? mmix_shiftable_wyde_value (~value)
387 : c == 'O' ? (value == 3 || value == 5 || value == 9
392 /* CONST_DOUBLE_OK_FOR_LETTER_P. */
395 mmix_const_double_ok_for_letter_p (rtx value, int c)
398 (c == 'G' ? value == CONST0_RTX (GET_MODE (value))
403 We need this since our constants are not always expressible as
404 CONST_INT:s, but rather often as CONST_DOUBLE:s. */
407 mmix_extra_constraint (rtx x, int c, int strict)
409 HOST_WIDEST_INT value;
411 /* When checking for an address, we need to handle strict vs. non-strict
412 register checks. Don't use address_operand, but instead its
413 equivalent (its callee, which it is just a wrapper for),
414 memory_operand_p and the strict-equivalent strict_memory_address_p. */
418 ? strict_memory_address_p (Pmode, x)
419 : memory_address_p (Pmode, x);
421 /* R asks whether x is to be loaded with GETA or something else. Right
422 now, only a SYMBOL_REF and LABEL_REF can fit for
423 TARGET_BASE_ADDRESSES.
425 Only constant symbolic addresses apply. With TARGET_BASE_ADDRESSES,
426 we just allow straight LABEL_REF or SYMBOL_REFs with SYMBOL_REF_FLAG
427 set right now; only function addresses and code labels. If we change
428 to let SYMBOL_REF_FLAG be set on other symbols, we have to check
429 inside CONST expressions. When TARGET_BASE_ADDRESSES is not in
430 effect, a "raw" constant check together with mmix_constant_address_p
431 is all that's needed; we want all constant addresses to be loaded
435 GET_CODE (x) != CONST_INT && GET_CODE (x) != CONST_DOUBLE
436 && mmix_constant_address_p (x)
437 && (! TARGET_BASE_ADDRESSES
438 || (GET_CODE (x) == LABEL_REF
439 || (GET_CODE (x) == SYMBOL_REF && SYMBOL_REF_FLAG (x))));
441 if (GET_CODE (x) != CONST_DOUBLE || GET_MODE (x) != VOIDmode)
444 value = mmix_intval (x);
446 /* We used to map Q->J, R->K, S->L, T->N, U->O, but we don't have to any
447 more ('U' taken for address_operand, 'R' similarly). Some letters map
448 outside of CONST_INT, though; we still use 'S' and 'T'. */
450 return mmix_shiftable_wyde_value (value);
452 return mmix_shiftable_wyde_value (~value);
456 /* DYNAMIC_CHAIN_ADDRESS. */
459 mmix_dynamic_chain_address (rtx frame)
461 /* FIXME: the frame-pointer is stored at offset -8 from the current
462 frame-pointer. Unfortunately, the caller assumes that a
463 frame-pointer is present for *all* previous frames. There should be
464 a way to say that that cannot be done, like for RETURN_ADDR_RTX. */
465 return plus_constant (frame, -8);
468 /* STARTING_FRAME_OFFSET. */
471 mmix_starting_frame_offset (void)
473 /* The old frame pointer is in the slot below the new one, so
474 FIRST_PARM_OFFSET does not need to depend on whether the
475 frame-pointer is needed or not. We have to adjust for the register
476 stack pointer being located below the saved frame pointer.
477 Similarly, we store the return address on the stack too, for
478 exception handling, and always if we save the register stack pointer. */
481 + (MMIX_CFUN_HAS_LANDING_PAD
482 ? -16 : (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS ? -8 : 0)));
485 /* RETURN_ADDR_RTX. */
488 mmix_return_addr_rtx (int count, rtx frame ATTRIBUTE_UNUSED)
491 ? (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
492 /* FIXME: Set frame_alias_set on the following. (Why?)
493 See mmix_initial_elimination_offset for the reason we can't use
494 get_hard_reg_initial_val for both. Always using a stack slot
495 and not a register would be suboptimal. */
496 ? validize_mem (gen_rtx_MEM (Pmode, plus_constant (frame_pointer_rtx, -16)))
497 : get_hard_reg_initial_val (Pmode, MMIX_INCOMING_RETURN_ADDRESS_REGNUM))
501 /* SETUP_FRAME_ADDRESSES. */
504 mmix_setup_frame_addresses (void)
506 /* Nothing needed at the moment. */
509 /* The difference between the (imaginary) frame pointer and the stack
510 pointer. Used to eliminate the frame pointer. */
513 mmix_initial_elimination_offset (int fromreg, int toreg)
517 = (get_frame_size () + current_function_outgoing_args_size + 7) & ~7;
519 /* There is no actual offset between these two virtual values, but for
520 the frame-pointer, we have the old one in the stack position below
521 it, so the offset for the frame-pointer to the stack-pointer is one
523 if (fromreg == MMIX_ARG_POINTER_REGNUM
524 && toreg == MMIX_FRAME_POINTER_REGNUM)
527 /* The difference is the size of local variables plus the size of
528 outgoing function arguments that would normally be passed as
529 registers but must be passed on stack because we're out of
530 function-argument registers. Only global saved registers are
531 counted; the others go on the register stack.
533 The frame-pointer is counted too if it is what is eliminated, as we
534 need to balance the offset for it from STARTING_FRAME_OFFSET.
536 Also add in the slot for the register stack pointer we save if we
539 Unfortunately, we can't access $0..$14, from unwinder code easily, so
540 store the return address in a frame slot too. FIXME: Only for
541 non-leaf functions. FIXME: Always with a landing pad, because it's
542 hard to know whether we need the other at the time we know we need
543 the offset for one (and have to state it). It's a kludge until we
544 can express the register stack in the EH frame info.
546 We have to do alignment here; get_frame_size will not return a
547 multiple of STACK_BOUNDARY. FIXME: Add note in manual. */
549 for (regno = MMIX_FIRST_GLOBAL_REGNUM;
552 if ((regs_ever_live[regno] && ! call_used_regs[regno])
553 || IS_MMIX_EH_RETURN_DATA_REG (regno))
557 + (MMIX_CFUN_HAS_LANDING_PAD
558 ? 16 : (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS ? 8 : 0))
559 + (fromreg == MMIX_ARG_POINTER_REGNUM ? 0 : 8);
562 /* Return an rtx for a function argument to go in a register, and 0 for
563 one that must go on stack. */
566 mmix_function_arg (const CUMULATIVE_ARGS *argsp,
567 enum machine_mode mode,
569 int named ATTRIBUTE_UNUSED,
572 /* Last-argument marker. */
573 if (type == void_type_node)
574 return (argsp->regs < MMIX_MAX_ARGS_IN_REGS)
577 ? MMIX_FIRST_INCOMING_ARG_REGNUM
578 : MMIX_FIRST_ARG_REGNUM) + argsp->regs)
581 return (argsp->regs < MMIX_MAX_ARGS_IN_REGS
582 && !targetm.calls.must_pass_in_stack (mode, type)
583 && (GET_MODE_BITSIZE (mode) <= 64
588 ? MMIX_FIRST_INCOMING_ARG_REGNUM
589 : MMIX_FIRST_ARG_REGNUM)
594 /* Returns nonzero for everything that goes by reference, 0 for
595 everything that goes by value. */
598 mmix_pass_by_reference (const CUMULATIVE_ARGS *argsp, enum machine_mode mode,
599 tree type, bool named ATTRIBUTE_UNUSED)
601 /* FIXME: Check: I'm not sure the must_pass_in_stack check is
603 if (targetm.calls.must_pass_in_stack (mode, type))
606 if (MMIX_FUNCTION_ARG_SIZE (mode, type) > 8
608 && (!argsp || !argsp->lib))
614 /* Return nonzero if regno is a register number where a parameter is
615 passed, and 0 otherwise. */
618 mmix_function_arg_regno_p (int regno, int incoming)
621 = incoming ? MMIX_FIRST_INCOMING_ARG_REGNUM : MMIX_FIRST_ARG_REGNUM;
623 return regno >= first_arg_regnum
624 && regno < first_arg_regnum + MMIX_MAX_ARGS_IN_REGS;
627 /* FUNCTION_OUTGOING_VALUE. */
630 mmix_function_outgoing_value (tree valtype, tree func ATTRIBUTE_UNUSED)
632 enum machine_mode mode = TYPE_MODE (valtype);
633 enum machine_mode cmode;
634 int first_val_regnum = MMIX_OUTGOING_RETURN_VALUE_REGNUM;
635 rtx vec[MMIX_MAX_REGS_FOR_VALUE];
639 /* Return values that fit in a register need no special handling.
640 There's no register hole when parameters are passed in global
643 || GET_MODE_BITSIZE (mode) <= BITS_PER_WORD)
645 gen_rtx_REG (mode, MMIX_OUTGOING_RETURN_VALUE_REGNUM);
647 /* A complex type, made up of components. */
648 cmode = TYPE_MODE (TREE_TYPE (valtype));
649 nregs = ((GET_MODE_BITSIZE (mode) + BITS_PER_WORD - 1) / BITS_PER_WORD);
651 /* We need to take care of the effect of the register hole on return
652 values of large sizes; the last register will appear as the first
653 register, with the rest shifted. (For complex modes, this is just
654 swapped registers.) */
656 if (nregs > MMIX_MAX_REGS_FOR_VALUE)
657 internal_error ("too large function value type, needs %d registers,\
658 have only %d registers for this", nregs, MMIX_MAX_REGS_FOR_VALUE);
660 /* FIXME: Maybe we should handle structure values like this too
661 (adjusted for BLKmode), perhaps for both ABI:s. */
662 for (i = 0; i < nregs - 1; i++)
664 = gen_rtx_EXPR_LIST (VOIDmode,
665 gen_rtx_REG (cmode, first_val_regnum + i),
666 GEN_INT ((i + 1) * BITS_PER_UNIT));
669 = gen_rtx_EXPR_LIST (VOIDmode,
670 gen_rtx_REG (cmode, first_val_regnum + nregs - 1),
673 return gen_rtx_PARALLEL (VOIDmode, gen_rtvec_v (nregs, vec));
676 /* FUNCTION_VALUE_REGNO_P. */
679 mmix_function_value_regno_p (int regno)
681 return regno == MMIX_RETURN_VALUE_REGNUM;
684 /* EH_RETURN_DATA_REGNO. */
687 mmix_eh_return_data_regno (int n)
690 return MMIX_EH_RETURN_DATA_REGNO_START + n;
692 return INVALID_REGNUM;
695 /* EH_RETURN_STACKADJ_RTX. */
698 mmix_eh_return_stackadj_rtx (void)
700 return gen_rtx_REG (Pmode, MMIX_EH_RETURN_STACKADJ_REGNUM);
703 /* EH_RETURN_HANDLER_RTX. */
706 mmix_eh_return_handler_rtx (void)
708 return gen_rtx_REG (Pmode, MMIX_INCOMING_RETURN_ADDRESS_REGNUM);
711 /* ASM_PREFERRED_EH_DATA_FORMAT. */
714 mmix_asm_preferred_eh_data_format (int code ATTRIBUTE_UNUSED,
715 int global ATTRIBUTE_UNUSED)
717 /* This is the default (was at 2001-07-20). Revisit when needed. */
718 return DW_EH_PE_absptr;
721 /* Make a note that we've seen the beginning of the prologue. This
722 matters to whether we'll translate register numbers as calculated by
726 mmix_target_asm_function_prologue (FILE *stream ATTRIBUTE_UNUSED,
727 HOST_WIDE_INT framesize ATTRIBUTE_UNUSED)
729 cfun->machine->in_prologue = 1;
732 /* Make a note that we've seen the end of the prologue. */
735 mmix_target_asm_function_end_prologue (FILE *stream ATTRIBUTE_UNUSED)
737 cfun->machine->in_prologue = 0;
740 /* Implement TARGET_MACHINE_DEPENDENT_REORG. No actual rearrangements
741 done here; just virtually by calculating the highest saved stack
742 register number used to modify the register numbers at output time. */
749 /* We put the number of the highest saved register-file register in a
750 location convenient for the call-patterns to output. Note that we
751 don't tell dwarf2 about these registers, since it can't restore them
753 for (regno = MMIX_LAST_STACK_REGISTER_REGNUM;
756 if ((regs_ever_live[regno] && !call_used_regs[regno])
757 || (regno == MMIX_FRAME_POINTER_REGNUM && frame_pointer_needed))
760 /* Regardless of whether they're saved (they might be just read), we
761 mustn't include registers that carry parameters. We could scan the
762 insns to see whether they're actually used (and indeed do other less
763 trivial register usage analysis and transformations), but it seems
764 wasteful to optimize for unused parameter registers. As of
765 2002-04-30, regs_ever_live[n] seems to be set for only-reads too, but
766 that might change. */
767 if (!TARGET_ABI_GNU && regno < current_function_args_info.regs - 1)
769 regno = current_function_args_info.regs - 1;
771 /* We don't want to let this cause us to go over the limit and make
772 incoming parameter registers be misnumbered and treating the last
773 parameter register and incoming return value register call-saved.
774 Stop things at the unmodified scheme. */
775 if (regno > MMIX_RETURN_VALUE_REGNUM - 1)
776 regno = MMIX_RETURN_VALUE_REGNUM - 1;
779 cfun->machine->highest_saved_stack_register = regno;
782 /* TARGET_ASM_FUNCTION_EPILOGUE. */
785 mmix_target_asm_function_epilogue (FILE *stream,
786 HOST_WIDE_INT locals_size ATTRIBUTE_UNUSED)
788 /* Emit an \n for readability of the generated assembly. */
789 fputc ('\n', stream);
792 /* TARGET_ASM_OUTPUT_MI_THUNK. */
795 mmix_asm_output_mi_thunk (FILE *stream,
796 tree fndecl ATTRIBUTE_UNUSED,
798 HOST_WIDE_INT vcall_offset ATTRIBUTE_UNUSED,
801 /* If you define TARGET_STRUCT_VALUE_RTX that returns 0 (i.e. pass
802 location of structure to return as invisible first argument), you
803 need to tweak this code too. */
804 const char *regname = reg_names[MMIX_FIRST_INCOMING_ARG_REGNUM];
806 if (delta >= 0 && delta < 65536)
807 fprintf (stream, "\tINCL %s,%d\n", regname, (int)delta);
808 else if (delta < 0 && delta >= -255)
809 fprintf (stream, "\tSUBU %s,%s,%d\n", regname, regname, (int)-delta);
812 mmix_output_register_setting (stream, 255, delta, 1);
813 fprintf (stream, "\tADDU %s,%s,$255\n", regname, regname);
816 fprintf (stream, "\tJMP ");
817 assemble_name (stream, XSTR (XEXP (DECL_RTL (func), 0), 0));
818 fprintf (stream, "\n");
821 /* FUNCTION_PROFILER. */
824 mmix_function_profiler (FILE *stream ATTRIBUTE_UNUSED,
825 int labelno ATTRIBUTE_UNUSED)
827 sorry ("function_profiler support for MMIX");
830 /* Worker function for TARGET_SETUP_INCOMING_VARARGS. For the moment,
831 let's stick to pushing argument registers on the stack. Later, we
832 can parse all arguments in registers, to improve performance. */
835 mmix_setup_incoming_varargs (CUMULATIVE_ARGS *args_so_farp,
836 enum machine_mode mode,
839 int second_time ATTRIBUTE_UNUSED)
841 /* The last named variable has been handled, but
842 args_so_farp has not been advanced for it. */
843 if (args_so_farp->regs + 1 < MMIX_MAX_ARGS_IN_REGS)
844 *pretend_sizep = (MMIX_MAX_ARGS_IN_REGS - (args_so_farp->regs + 1)) * 8;
846 /* We assume that one argument takes up one register here. That should
847 be true until we start messing with multi-reg parameters. */
848 if ((7 + (MMIX_FUNCTION_ARG_SIZE (mode, vartype))) / 8 != 1)
849 internal_error ("MMIX Internal: Last named vararg would not fit in a register");
852 /* TRAMPOLINE_SIZE. */
853 /* Four 4-byte insns plus two 8-byte values. */
854 int mmix_trampoline_size = 32;
857 /* TRAMPOLINE_TEMPLATE. */
860 mmix_trampoline_template (FILE *stream)
862 /* Read a value into the static-chain register and jump somewhere. The
863 static chain is stored at offset 16, and the function address is
864 stored at offset 24. */
865 /* FIXME: GCC copies this using *intsize* (tetra), when it should use
866 register size (octa). */
867 fprintf (stream, "\tGETA $255,1F\n\t");
868 fprintf (stream, "LDOU %s,$255,0\n\t",
869 reg_names[MMIX_STATIC_CHAIN_REGNUM]);
870 fprintf (stream, "LDOU $255,$255,8\n\t");
871 fprintf (stream, "GO $255,$255,0\n");
872 fprintf (stream, "1H\tOCTA 0\n\t");
873 fprintf (stream, "OCTA 0\n");
876 /* INITIALIZE_TRAMPOLINE. */
877 /* Set the static chain and function pointer field in the trampoline.
878 We also SYNCID here to be sure (doesn't matter in the simulator, but
879 some day it will). */
882 mmix_initialize_trampoline (rtx trampaddr, rtx fnaddr, rtx static_chain)
884 emit_move_insn (gen_rtx_MEM (DImode, plus_constant (trampaddr, 16)),
886 emit_move_insn (gen_rtx_MEM (DImode,
887 plus_constant (trampaddr, 24)),
889 emit_insn (gen_sync_icache (validize_mem (gen_rtx_MEM (DImode,
891 GEN_INT (mmix_trampoline_size - 1)));
894 /* We must exclude constant addresses that have an increment that is not a
895 multiple of four bytes because of restrictions of the GETA
896 instruction, unless TARGET_BASE_ADDRESSES. */
899 mmix_constant_address_p (rtx x)
901 RTX_CODE code = GET_CODE (x);
903 /* When using "base addresses", anything constant goes. */
904 int constant_ok = TARGET_BASE_ADDRESSES != 0;
913 /* FIXME: Don't know how to dissect these. Avoid them for now,
914 except we know they're constants. */
922 if (GET_MODE (x) != VOIDmode)
923 /* Strange that we got here. FIXME: Check if we do. */
925 addend = CONST_DOUBLE_LOW (x);
929 /* Note that expressions with arithmetic on forward references don't
930 work in mmixal. People using gcc assembly code with mmixal might
931 need to move arrays and such to before the point of use. */
932 if (GET_CODE (XEXP (x, 0)) == PLUS)
934 rtx x0 = XEXP (XEXP (x, 0), 0);
935 rtx x1 = XEXP (XEXP (x, 0), 1);
937 if ((GET_CODE (x0) == SYMBOL_REF
938 || GET_CODE (x0) == LABEL_REF)
939 && (GET_CODE (x1) == CONST_INT
940 || (GET_CODE (x1) == CONST_DOUBLE
941 && GET_MODE (x1) == VOIDmode)))
942 addend = mmix_intval (x1);
954 return constant_ok || (addend & 3) == 0;
957 /* Return 1 if the address is OK, otherwise 0.
958 Used by GO_IF_LEGITIMATE_ADDRESS. */
961 mmix_legitimate_address (enum machine_mode mode ATTRIBUTE_UNUSED,
965 #define MMIX_REG_OK(X) \
967 && (REGNO (X) <= MMIX_LAST_GENERAL_REGISTER \
968 || (reg_renumber[REGNO (X)] > 0 \
969 && reg_renumber[REGNO (X)] <= MMIX_LAST_GENERAL_REGISTER))) \
970 || (!strict_checking \
971 && (REGNO (X) <= MMIX_LAST_GENERAL_REGISTER \
972 || REGNO (X) >= FIRST_PSEUDO_REGISTER \
973 || REGNO (X) == ARG_POINTER_REGNUM)))
978 (mem (plus reg 0..255)).
979 unless TARGET_BASE_ADDRESSES, in which case we accept all
980 (mem constant_address) too. */
984 if (REG_P (x) && MMIX_REG_OK (x))
987 if (GET_CODE(x) == PLUS)
989 rtx x1 = XEXP (x, 0);
990 rtx x2 = XEXP (x, 1);
992 /* Try swapping the order. FIXME: Do we need this? */
1000 /* (mem (plus (reg?) (?))) */
1001 if (!REG_P (x1) || !MMIX_REG_OK (x1))
1002 return TARGET_BASE_ADDRESSES && mmix_constant_address_p (x);
1004 /* (mem (plus (reg) (reg?))) */
1005 if (REG_P (x2) && MMIX_REG_OK (x2))
1008 /* (mem (plus (reg) (0..255?))) */
1009 if (GET_CODE (x2) == CONST_INT
1010 && CONST_OK_FOR_LETTER_P (INTVAL (x2), 'I'))
1016 return TARGET_BASE_ADDRESSES && mmix_constant_address_p (x);
1019 /* LEGITIMATE_CONSTANT_P. */
1022 mmix_legitimate_constant_p (rtx x)
1024 RTX_CODE code = GET_CODE (x);
1026 /* We must allow any number due to the way the cse passes works; if we
1027 do not allow any number here, general_operand will fail, and insns
1028 will fatally fail recognition instead of "softly". */
1029 if (code == CONST_INT || code == CONST_DOUBLE)
1032 return CONSTANT_ADDRESS_P (x);
1035 /* SELECT_CC_MODE. */
1038 mmix_select_cc_mode (RTX_CODE op, rtx x, rtx y ATTRIBUTE_UNUSED)
1040 /* We use CCmode, CC_UNSmode, CC_FPmode, CC_FPEQmode and CC_FUNmode to
1041 output different compare insns. Note that we do not check the
1042 validity of the comparison here. */
1044 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1046 if (op == ORDERED || op == UNORDERED || op == UNGE
1047 || op == UNGT || op == UNLE || op == UNLT)
1050 if (op == EQ || op == NE)
1056 if (op == GTU || op == LTU || op == GEU || op == LEU)
1062 /* REVERSIBLE_CC_MODE. */
1065 mmix_reversible_cc_mode (enum machine_mode mode)
1067 /* That is, all integer and the EQ, NE, ORDERED and UNORDERED float
1069 return mode != CC_FPmode;
1072 /* TARGET_RTX_COSTS. */
1075 mmix_rtx_costs (rtx x ATTRIBUTE_UNUSED,
1076 int code ATTRIBUTE_UNUSED,
1077 int outer_code ATTRIBUTE_UNUSED,
1078 int *total ATTRIBUTE_UNUSED)
1080 /* For the time being, this is just a stub and we'll accept the
1081 generic calculations, until we can do measurements, at least.
1082 Say we did not modify any calculated costs. */
1086 /* REGISTER_MOVE_COST. */
1089 mmix_register_move_cost (enum machine_mode mode ATTRIBUTE_UNUSED,
1090 enum reg_class from,
1093 return (from == GENERAL_REGS && from == to) ? 2 : 3;
1096 /* Note that we don't have a TEXT_SECTION_ASM_OP, because it has to be a
1097 compile-time constant; it's used in an asm in crtstuff.c, compiled for
1100 /* DATA_SECTION_ASM_OP. */
1103 mmix_data_section_asm_op (void)
1105 return "\t.data ! mmixal:= 8H LOC 9B";
1109 mmix_encode_section_info (tree decl, rtx rtl, int first)
1111 /* Test for an external declaration, and do nothing if it is one. */
1112 if ((TREE_CODE (decl) == VAR_DECL
1113 && (DECL_EXTERNAL (decl) || TREE_PUBLIC (decl)))
1114 || (TREE_CODE (decl) == FUNCTION_DECL && TREE_PUBLIC (decl)))
1116 else if (first && DECL_P (decl))
1118 /* For non-visible declarations, add a "@" prefix, which we skip
1119 when the label is output. If the label does not have this
1120 prefix, a ":" is output if -mtoplevel-symbols.
1122 Note that this does not work for data that is declared extern and
1123 later defined as static. If there's code in between, that code
1124 will refer to the extern declaration, and vice versa. This just
1125 means that when -mtoplevel-symbols is in use, we can just handle
1126 well-behaved ISO-compliant code. */
1128 const char *str = XSTR (XEXP (rtl, 0), 0);
1129 int len = strlen (str);
1132 /* Why is the return type of ggc_alloc_string const? */
1133 newstr = (char *) ggc_alloc_string ("", len + 1);
1135 strcpy (newstr + 1, str);
1137 XSTR (XEXP (rtl, 0), 0) = newstr;
1140 /* Set SYMBOL_REF_FLAG for things that we want to access with GETA. We
1141 may need different options to reach for different things with GETA.
1142 For now, functions and things we know or have been told are constant. */
1143 if (TREE_CODE (decl) == FUNCTION_DECL
1144 || TREE_CONSTANT (decl)
1145 || (TREE_CODE (decl) == VAR_DECL
1146 && TREE_READONLY (decl)
1147 && !TREE_SIDE_EFFECTS (decl)
1148 && (!DECL_INITIAL (decl)
1149 || TREE_CONSTANT (DECL_INITIAL (decl)))))
1150 SYMBOL_REF_FLAG (XEXP (rtl, 0)) = 1;
1154 mmix_strip_name_encoding (const char *name)
1156 for (; (*name == '@' || *name == '*'); name++)
1162 /* TARGET_ASM_FILE_START.
1163 We just emit a little comment for the time being. */
1166 mmix_file_start (void)
1168 default_file_start ();
1170 fputs ("! mmixal:= 8H LOC Data_Section\n", asm_out_file);
1172 /* Make sure each file starts with the text section. */
1176 /* TARGET_ASM_FILE_END. */
1179 mmix_file_end (void)
1181 /* Make sure each file ends with the data section. */
1185 /* ASM_OUTPUT_SOURCE_FILENAME. */
1188 mmix_asm_output_source_filename (FILE *stream, const char *name)
1190 fprintf (stream, "# 1 ");
1191 OUTPUT_QUOTED_STRING (stream, name);
1192 fprintf (stream, "\n");
1195 /* OUTPUT_QUOTED_STRING. */
1198 mmix_output_quoted_string (FILE *stream, const char *string, int length)
1200 const char * string_end = string + length;
1201 static const char *const unwanted_chars = "\"[]\\";
1203 /* Output "any character except newline and double quote character". We
1204 play it safe and avoid all control characters too. We also do not
1205 want [] as characters, should input be passed through m4 with [] as
1206 quotes. Further, we avoid "\", because the GAS port handles it as a
1207 quoting character. */
1208 while (string < string_end)
1211 && (unsigned char) *string < 128
1212 && !ISCNTRL (*string)
1213 && strchr (unwanted_chars, *string) == NULL)
1215 fputc ('"', stream);
1217 && (unsigned char) *string < 128
1218 && !ISCNTRL (*string)
1219 && strchr (unwanted_chars, *string) == NULL
1220 && string < string_end)
1222 fputc (*string, stream);
1225 fputc ('"', stream);
1226 if (string < string_end)
1227 fprintf (stream, ",");
1229 if (string < string_end)
1231 fprintf (stream, "#%x", *string & 255);
1233 if (string < string_end)
1234 fprintf (stream, ",");
1239 /* Target hook for assembling integer objects. Use mmix_print_operand
1240 for WYDE and TETRA. Use mmix_output_octa to output 8-byte
1244 mmix_assemble_integer (rtx x, unsigned int size, int aligned_p)
1249 /* We handle a limited number of types of operands in here. But
1250 that's ok, because we can punt to generic functions. We then
1251 pretend that aligned data isn't needed, so the usual .<pseudo>
1252 syntax is used (which works for aligned data too). We actually
1253 *must* do that, since we say we don't have simple aligned
1254 pseudos, causing this function to be called. We just try and
1255 keep as much compatibility as possible with mmixal syntax for
1256 normal cases (i.e. without GNU extensions and C only). */
1258 if (GET_CODE (x) != CONST_INT)
1263 fputs ("\tBYTE\t", asm_out_file);
1264 mmix_print_operand (asm_out_file, x, 'B');
1265 fputc ('\n', asm_out_file);
1269 if (GET_CODE (x) != CONST_INT)
1274 fputs ("\tWYDE\t", asm_out_file);
1275 mmix_print_operand (asm_out_file, x, 'W');
1276 fputc ('\n', asm_out_file);
1280 if (GET_CODE (x) != CONST_INT)
1285 fputs ("\tTETRA\t", asm_out_file);
1286 mmix_print_operand (asm_out_file, x, 'L');
1287 fputc ('\n', asm_out_file);
1291 if (GET_CODE (x) == CONST_DOUBLE)
1292 /* We don't get here anymore for CONST_DOUBLE, because DImode
1293 isn't expressed as CONST_DOUBLE, and DFmode is handled
1296 assemble_integer_with_op ("\tOCTA\t", x);
1299 return default_assemble_integer (x, size, aligned_p);
1302 /* ASM_OUTPUT_ASCII. */
1305 mmix_asm_output_ascii (FILE *stream, const char *string, int length)
1309 int chunk_size = length > 60 ? 60 : length;
1310 fprintf (stream, "\tBYTE ");
1311 mmix_output_quoted_string (stream, string, chunk_size);
1312 string += chunk_size;
1313 length -= chunk_size;
1314 fprintf (stream, "\n");
1318 /* ASM_OUTPUT_ALIGNED_COMMON. */
1321 mmix_asm_output_aligned_common (FILE *stream,
1326 /* This is mostly the elfos.h one. There doesn't seem to be a way to
1327 express this in a mmixal-compatible way. */
1328 fprintf (stream, "\t.comm\t");
1329 assemble_name (stream, name);
1330 fprintf (stream, ",%u,%u ! mmixal-incompatible COMMON\n",
1331 size, align / BITS_PER_UNIT);
1334 /* ASM_OUTPUT_ALIGNED_LOCAL. */
1337 mmix_asm_output_aligned_local (FILE *stream,
1344 ASM_OUTPUT_ALIGN (stream, exact_log2 (align/BITS_PER_UNIT));
1345 assemble_name (stream, name);
1346 fprintf (stream, "\tLOC @+%d\n", size);
1349 /* ASM_OUTPUT_LABEL. */
1352 mmix_asm_output_label (FILE *stream, const char *name)
1354 assemble_name (stream, name);
1355 fprintf (stream, "\tIS @\n");
1358 /* ASM_DECLARE_REGISTER_GLOBAL. */
1361 mmix_asm_declare_register_global (FILE *stream ATTRIBUTE_UNUSED,
1362 tree decl ATTRIBUTE_UNUSED,
1363 int regno ATTRIBUTE_UNUSED,
1364 const char *name ATTRIBUTE_UNUSED)
1366 /* Nothing to do here, but there *will* be, therefore the framework is
1370 /* ASM_WEAKEN_LABEL. */
1373 mmix_asm_weaken_label (FILE *stream ATTRIBUTE_UNUSED,
1374 const char *name ATTRIBUTE_UNUSED)
1376 fprintf (stream, "\t.weak ");
1377 assemble_name (stream, name);
1378 fprintf (stream, " ! mmixal-incompatible\n");
1381 /* MAKE_DECL_ONE_ONLY. */
1384 mmix_make_decl_one_only (tree decl)
1386 DECL_WEAK (decl) = 1;
1389 /* ASM_OUTPUT_LABELREF.
1390 Strip GCC's '*' and our own '@'. No order is assumed. */
1393 mmix_asm_output_labelref (FILE *stream, const char *name)
1397 for (; (*name == '@' || *name == '*'); name++)
1401 asm_fprintf (stream, "%s%U%s",
1402 is_extern && TARGET_TOPLEVEL_SYMBOLS ? ":" : "",
1406 /* ASM_OUTPUT_DEF. */
1409 mmix_asm_output_def (FILE *stream, const char *name, const char *value)
1411 assemble_name (stream, name);
1412 fprintf (stream, "\tIS ");
1413 assemble_name (stream, value);
1414 fputc ('\n', stream);
1417 /* PRINT_OPERAND. */
1420 mmix_print_operand (FILE *stream, rtx x, int code)
1422 /* When we add support for different codes later, we can, when needed,
1423 drop through to the main handler with a modified operand. */
1425 int regno = x != NULL_RTX && REG_P (x) ? REGNO (x) : 0;
1429 /* Unrelated codes are in alphabetic order. */
1432 /* For conditional branches, output "P" for a probable branch. */
1433 if (TARGET_BRANCH_PREDICT)
1435 x = find_reg_note (current_output_insn, REG_BR_PROB, 0);
1436 if (x && INTVAL (XEXP (x, 0)) > REG_BR_PROB_BASE / 2)
1442 /* For the %d in POP %d,0. */
1443 fprintf (stream, "%d", MMIX_POP_ARGUMENT ());
1447 if (GET_CODE (x) != CONST_INT)
1448 fatal_insn ("MMIX Internal: Expected a CONST_INT, not this", x);
1449 fprintf (stream, "%d", (int) (INTVAL (x) & 0xff));
1453 /* Highpart. Must be general register, and not the last one, as
1454 that one cannot be part of a consecutive register pair. */
1455 if (regno > MMIX_LAST_GENERAL_REGISTER - 1)
1456 internal_error ("MMIX Internal: Bad register: %d", regno);
1458 /* This is big-endian, so the high-part is the first one. */
1459 fprintf (stream, "%s", reg_names[MMIX_OUTPUT_REGNO (regno)]);
1463 /* Lowpart. Must be CONST_INT or general register, and not the last
1464 one, as that one cannot be part of a consecutive register pair. */
1465 if (GET_CODE (x) == CONST_INT)
1467 fprintf (stream, "#%lx",
1468 (unsigned long) (INTVAL (x)
1469 & ((unsigned int) 0x7fffffff * 2 + 1)));
1473 if (GET_CODE (x) == SYMBOL_REF)
1475 output_addr_const (stream, x);
1479 if (regno > MMIX_LAST_GENERAL_REGISTER - 1)
1480 internal_error ("MMIX Internal: Bad register: %d", regno);
1482 /* This is big-endian, so the low-part is + 1. */
1483 fprintf (stream, "%s", reg_names[MMIX_OUTPUT_REGNO (regno) + 1]);
1486 /* Can't use 'a' because that's a generic modifier for address
1489 mmix_output_shiftvalue_op_from_str (stream, "ANDN",
1490 ~(unsigned HOST_WIDEST_INT)
1495 mmix_output_shiftvalue_op_from_str (stream, "INC",
1496 (unsigned HOST_WIDEST_INT)
1501 mmix_output_shiftvalue_op_from_str (stream, "OR",
1502 (unsigned HOST_WIDEST_INT)
1507 mmix_output_shiftvalue_op_from_str (stream, "SET",
1508 (unsigned HOST_WIDEST_INT)
1514 mmix_output_condition (stream, x, (code == 'D'));
1518 /* Output an extra "e" to make fcmpe, fune. */
1519 if (TARGET_FCMP_EPSILON)
1520 fprintf (stream, "e");
1524 /* Output the number minus 1. */
1525 if (GET_CODE (x) != CONST_INT)
1527 fatal_insn ("MMIX Internal: Bad value for 'm', not a CONST_INT",
1530 fprintf (stream, HOST_WIDEST_INT_PRINT_DEC,
1531 (HOST_WIDEST_INT) (mmix_intval (x) - 1));
1535 /* Store the number of registers we want to save. This was setup
1536 by the prologue. The actual operand contains the number of
1537 registers to pass, but we don't use it currently. Anyway, we
1538 need to output the number of saved registers here. */
1539 fprintf (stream, "%d",
1540 cfun->machine->highest_saved_stack_register + 1);
1544 /* Store the register to output a constant to. */
1546 fatal_insn ("MMIX Internal: Expected a register, not this", x);
1547 mmix_output_destination_register = MMIX_OUTPUT_REGNO (regno);
1551 /* Output the constant. Note that we use this for floats as well. */
1552 if (GET_CODE (x) != CONST_INT
1553 && (GET_CODE (x) != CONST_DOUBLE
1554 || (GET_MODE (x) != VOIDmode && GET_MODE (x) != DFmode
1555 && GET_MODE (x) != SFmode)))
1556 fatal_insn ("MMIX Internal: Expected a constant, not this", x);
1557 mmix_output_register_setting (stream,
1558 mmix_output_destination_register,
1559 mmix_intval (x), 0);
1563 /* An U for unsigned, if TARGET_ZERO_EXTEND. Ignore the operand. */
1564 if (TARGET_ZERO_EXTEND)
1569 mmix_output_shifted_value (stream, (HOST_WIDEST_INT) mmix_intval (x));
1573 mmix_output_shifted_value (stream, (HOST_WIDEST_INT) ~mmix_intval (x));
1577 if (GET_CODE (x) != CONST_INT)
1578 fatal_insn ("MMIX Internal: Expected a CONST_INT, not this", x);
1579 fprintf (stream, "#%x", (int) (INTVAL (x) & 0xffff));
1583 /* Nothing to do. */
1587 /* Presumably there's a missing case above if we get here. */
1588 internal_error ("MMIX Internal: Missing %qc case in mmix_print_operand", code);
1591 switch (GET_CODE (modified_x))
1594 regno = REGNO (modified_x);
1595 if (regno >= FIRST_PSEUDO_REGISTER)
1596 internal_error ("MMIX Internal: Bad register: %d", regno);
1597 fprintf (stream, "%s", reg_names[MMIX_OUTPUT_REGNO (regno)]);
1601 output_address (XEXP (modified_x, 0));
1605 /* For -2147483648, mmixal complains that the constant does not fit
1606 in 4 bytes, so let's output it as hex. Take care to handle hosts
1607 where HOST_WIDE_INT is longer than an int.
1609 Print small constants +-255 using decimal. */
1611 if (INTVAL (modified_x) > -256 && INTVAL (modified_x) < 256)
1612 fprintf (stream, "%d", (int) (INTVAL (modified_x)));
1614 fprintf (stream, "#%x",
1615 (int) (INTVAL (modified_x)) & (unsigned int) ~0);
1619 /* Do somewhat as CONST_INT. */
1620 mmix_output_octa (stream, mmix_intval (modified_x), 0);
1624 output_addr_const (stream, modified_x);
1628 /* No need to test for all strange things. Let output_addr_const do
1630 if (CONSTANT_P (modified_x)
1631 /* Strangely enough, this is not included in CONSTANT_P.
1632 FIXME: Ask/check about sanity here. */
1633 || GET_CODE (modified_x) == CODE_LABEL)
1635 output_addr_const (stream, modified_x);
1639 /* We need the original here. */
1640 fatal_insn ("MMIX Internal: Cannot decode this operand", x);
1644 /* PRINT_OPERAND_PUNCT_VALID_P. */
1647 mmix_print_operand_punct_valid_p (int code ATTRIBUTE_UNUSED)
1649 /* A '+' is used for branch prediction, similar to other ports. */
1651 /* A '.' is used for the %d in the POP %d,0 return insn. */
1655 /* PRINT_OPERAND_ADDRESS. */
1658 mmix_print_operand_address (FILE *stream, rtx x)
1662 /* I find the generated assembly code harder to read without
1664 fprintf (stream, "%s,0", reg_names[MMIX_OUTPUT_REGNO (REGNO (x))]);
1667 else if (GET_CODE (x) == PLUS)
1669 rtx x1 = XEXP (x, 0);
1670 rtx x2 = XEXP (x, 1);
1674 fprintf (stream, "%s,", reg_names[MMIX_OUTPUT_REGNO (REGNO (x1))]);
1678 fprintf (stream, "%s",
1679 reg_names[MMIX_OUTPUT_REGNO (REGNO (x2))]);
1682 else if (GET_CODE (x2) == CONST_INT
1683 && CONST_OK_FOR_LETTER_P (INTVAL (x2), 'I'))
1685 output_addr_const (stream, x2);
1691 if (TARGET_BASE_ADDRESSES && mmix_legitimate_constant_p (x))
1693 output_addr_const (stream, x);
1697 fatal_insn ("MMIX Internal: This is not a recognized address", x);
1700 /* ASM_OUTPUT_REG_PUSH. */
1703 mmix_asm_output_reg_push (FILE *stream, int regno)
1705 fprintf (stream, "\tSUBU %s,%s,8\n\tSTOU %s,%s,0\n",
1706 reg_names[MMIX_STACK_POINTER_REGNUM],
1707 reg_names[MMIX_STACK_POINTER_REGNUM],
1708 reg_names[MMIX_OUTPUT_REGNO (regno)],
1709 reg_names[MMIX_STACK_POINTER_REGNUM]);
1712 /* ASM_OUTPUT_REG_POP. */
1715 mmix_asm_output_reg_pop (FILE *stream, int regno)
1717 fprintf (stream, "\tLDOU %s,%s,0\n\tINCL %s,8\n",
1718 reg_names[MMIX_OUTPUT_REGNO (regno)],
1719 reg_names[MMIX_STACK_POINTER_REGNUM],
1720 reg_names[MMIX_STACK_POINTER_REGNUM]);
1723 /* ASM_OUTPUT_ADDR_DIFF_ELT. */
1726 mmix_asm_output_addr_diff_elt (FILE *stream,
1727 rtx body ATTRIBUTE_UNUSED,
1731 fprintf (stream, "\tTETRA L%d-L%d\n", value, rel);
1734 /* ASM_OUTPUT_ADDR_VEC_ELT. */
1737 mmix_asm_output_addr_vec_elt (FILE *stream, int value)
1739 fprintf (stream, "\tOCTA L:%d\n", value);
1742 /* ASM_OUTPUT_SKIP. */
1745 mmix_asm_output_skip (FILE *stream, int nbytes)
1747 fprintf (stream, "\tLOC @+%d\n", nbytes);
1750 /* ASM_OUTPUT_ALIGN. */
1753 mmix_asm_output_align (FILE *stream, int power)
1755 /* We need to record the needed alignment of this section in the object,
1756 so we have to output an alignment directive. Use a .p2align (not
1757 .align) so people will never have to wonder about whether the
1758 argument is in number of bytes or the log2 thereof. We do it in
1759 addition to the LOC directive, so nothing needs tweaking when
1760 copy-pasting assembly into mmixal. */
1761 fprintf (stream, "\t.p2align %d\n", power);
1762 fprintf (stream, "\tLOC @+(%d-@)&%d\n", 1 << power, (1 << power) - 1);
1765 /* DBX_REGISTER_NUMBER. */
1768 mmix_dbx_register_number (int regno)
1770 /* Adjust the register number to the one it will be output as, dammit.
1771 It'd be nice if we could check the assumption that we're filling a
1772 gap, but every register between the last saved register and parameter
1773 registers might be a valid parameter register. */
1774 regno = MMIX_OUTPUT_REGNO (regno);
1776 /* We need to renumber registers to get the number of the return address
1777 register in the range 0..255. It is also space-saving if registers
1778 mentioned in the call-frame information (which uses this function by
1779 defaulting DWARF_FRAME_REGNUM to DBX_REGISTER_NUMBER) are numbered
1780 0 .. 63. So map 224 .. 256+15 -> 0 .. 47 and 0 .. 223 -> 48..223+48. */
1781 return regno >= 224 ? (regno - 224) : (regno + 48);
1784 /* End of target macro support functions.
1786 Now the MMIX port's own functions. First the exported ones. */
1788 /* Wrapper for get_hard_reg_initial_val since integrate.h isn't included
1789 from insn-emit.c. */
1792 mmix_get_hard_reg_initial_val (enum machine_mode mode, int regno)
1794 return get_hard_reg_initial_val (mode, regno);
1797 /* Nonzero when the function epilogue is simple enough that a single
1798 "POP %d,0" should be used even within the function. */
1801 mmix_use_simple_return (void)
1805 int stack_space_to_allocate
1806 = (current_function_outgoing_args_size
1807 + current_function_pretend_args_size
1808 + get_frame_size () + 7) & ~7;
1810 if (!TARGET_USE_RETURN_INSN || !reload_completed)
1814 regno >= MMIX_FIRST_GLOBAL_REGNUM;
1816 /* Note that we assume that the frame-pointer-register is one of these
1817 registers, in which case we don't count it here. */
1818 if ((((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
1819 && regs_ever_live[regno] && !call_used_regs[regno]))
1820 || IS_MMIX_EH_RETURN_DATA_REG (regno))
1823 if (frame_pointer_needed)
1824 stack_space_to_allocate += 8;
1826 if (MMIX_CFUN_HAS_LANDING_PAD)
1827 stack_space_to_allocate += 16;
1828 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
1829 stack_space_to_allocate += 8;
1831 return stack_space_to_allocate == 0;
1835 /* Expands the function prologue into RTX. */
1838 mmix_expand_prologue (void)
1840 HOST_WIDE_INT locals_size = get_frame_size ();
1842 HOST_WIDE_INT stack_space_to_allocate
1843 = (current_function_outgoing_args_size
1844 + current_function_pretend_args_size
1845 + locals_size + 7) & ~7;
1846 HOST_WIDE_INT offset = -8;
1848 /* Add room needed to save global non-register-stack registers. */
1850 regno >= MMIX_FIRST_GLOBAL_REGNUM;
1852 /* Note that we assume that the frame-pointer-register is one of these
1853 registers, in which case we don't count it here. */
1854 if ((((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
1855 && regs_ever_live[regno] && !call_used_regs[regno]))
1856 || IS_MMIX_EH_RETURN_DATA_REG (regno))
1857 stack_space_to_allocate += 8;
1859 /* If we do have a frame-pointer, add room for it. */
1860 if (frame_pointer_needed)
1861 stack_space_to_allocate += 8;
1863 /* If we have a non-local label, we need to be able to unwind to it, so
1864 store the current register stack pointer. Also store the return
1865 address if we do that. */
1866 if (MMIX_CFUN_HAS_LANDING_PAD)
1867 stack_space_to_allocate += 16;
1868 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
1869 /* If we do have a saved return-address slot, add room for it. */
1870 stack_space_to_allocate += 8;
1872 /* Make sure we don't get an unaligned stack. */
1873 if ((stack_space_to_allocate % 8) != 0)
1874 internal_error ("stack frame not a multiple of 8 bytes: %d",
1875 stack_space_to_allocate);
1877 if (current_function_pretend_args_size)
1879 int mmix_first_vararg_reg
1880 = (MMIX_FIRST_INCOMING_ARG_REGNUM
1881 + (MMIX_MAX_ARGS_IN_REGS
1882 - current_function_pretend_args_size / 8));
1885 = MMIX_FIRST_INCOMING_ARG_REGNUM + MMIX_MAX_ARGS_IN_REGS - 1;
1886 regno >= mmix_first_vararg_reg;
1891 HOST_WIDE_INT stack_chunk
1892 = stack_space_to_allocate > (256 - 8)
1893 ? (256 - 8) : stack_space_to_allocate;
1895 mmix_emit_sp_add (-stack_chunk);
1896 offset += stack_chunk;
1897 stack_space_to_allocate -= stack_chunk;
1900 /* These registers aren't actually saved (as in "will be
1901 restored"), so don't tell DWARF2 they're saved. */
1902 emit_move_insn (gen_rtx_MEM (DImode,
1903 plus_constant (stack_pointer_rtx,
1905 gen_rtx_REG (DImode, regno));
1910 /* Store the frame-pointer. */
1912 if (frame_pointer_needed)
1918 /* Get 8 less than otherwise, since we need to reach offset + 8. */
1919 HOST_WIDE_INT stack_chunk
1920 = stack_space_to_allocate > (256 - 8 - 8)
1921 ? (256 - 8 - 8) : stack_space_to_allocate;
1923 mmix_emit_sp_add (-stack_chunk);
1925 offset += stack_chunk;
1926 stack_space_to_allocate -= stack_chunk;
1929 insn = emit_move_insn (gen_rtx_MEM (DImode,
1930 plus_constant (stack_pointer_rtx,
1932 hard_frame_pointer_rtx);
1933 RTX_FRAME_RELATED_P (insn) = 1;
1934 insn = emit_insn (gen_adddi3 (hard_frame_pointer_rtx,
1936 GEN_INT (offset + 8)));
1937 RTX_FRAME_RELATED_P (insn) = 1;
1941 if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
1946 /* Store the return-address, if one is needed on the stack. We
1947 usually store it in a register when needed, but that doesn't work
1948 with -fexceptions. */
1952 /* Get 8 less than otherwise, since we need to reach offset + 8. */
1953 HOST_WIDE_INT stack_chunk
1954 = stack_space_to_allocate > (256 - 8 - 8)
1955 ? (256 - 8 - 8) : stack_space_to_allocate;
1957 mmix_emit_sp_add (-stack_chunk);
1959 offset += stack_chunk;
1960 stack_space_to_allocate -= stack_chunk;
1963 tmpreg = gen_rtx_REG (DImode, 255);
1964 retreg = gen_rtx_REG (DImode, MMIX_rJ_REGNUM);
1966 /* Dwarf2 code is confused by the use of a temporary register for
1967 storing the return address, so we have to express it as a note,
1968 which we attach to the actual store insn. */
1969 emit_move_insn (tmpreg, retreg);
1971 insn = emit_move_insn (gen_rtx_MEM (DImode,
1972 plus_constant (stack_pointer_rtx,
1975 RTX_FRAME_RELATED_P (insn) = 1;
1977 = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
1978 gen_rtx_SET (VOIDmode,
1979 gen_rtx_MEM (DImode,
1980 plus_constant (stack_pointer_rtx,
1987 else if (MMIX_CFUN_HAS_LANDING_PAD)
1990 if (MMIX_CFUN_HAS_LANDING_PAD)
1992 /* Store the register defining the numbering of local registers, so
1993 we know how long to unwind the register stack. */
1997 /* Get 8 less than otherwise, since we need to reach offset + 8. */
1998 HOST_WIDE_INT stack_chunk
1999 = stack_space_to_allocate > (256 - 8 - 8)
2000 ? (256 - 8 - 8) : stack_space_to_allocate;
2002 mmix_emit_sp_add (-stack_chunk);
2004 offset += stack_chunk;
2005 stack_space_to_allocate -= stack_chunk;
2008 /* We don't tell dwarf2 about this one; we just have it to unwind
2009 the register stack at landing pads. FIXME: It's a kludge because
2010 we can't describe the effect of the PUSHJ and PUSHGO insns on the
2011 register stack at the moment. Best thing would be to handle it
2012 like stack-pointer offsets. Better: some hook into dwarf2out.c
2013 to produce DW_CFA_expression:s that specify the increment of rO,
2014 and unwind it at eh_return (preferred) or at the landing pad.
2015 Then saves to $0..$G-1 could be specified through that register. */
2017 emit_move_insn (gen_rtx_REG (DImode, 255),
2018 gen_rtx_REG (DImode,
2020 emit_move_insn (gen_rtx_MEM (DImode,
2021 plus_constant (stack_pointer_rtx, offset)),
2022 gen_rtx_REG (DImode, 255));
2026 /* After the return-address and the frame-pointer, we have the local
2027 variables. They're the ones that may have an "unaligned" size. */
2028 offset -= (locals_size + 7) & ~7;
2030 /* Now store all registers that are global, i.e. not saved by the
2031 register file machinery.
2033 It is assumed that the frame-pointer is one of these registers, so it
2034 is explicitly excluded in the count. */
2037 regno >= MMIX_FIRST_GLOBAL_REGNUM;
2039 if (((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
2040 && regs_ever_live[regno] && ! call_used_regs[regno])
2041 || IS_MMIX_EH_RETURN_DATA_REG (regno))
2047 HOST_WIDE_INT stack_chunk
2048 = (stack_space_to_allocate > (256 - offset - 8)
2049 ? (256 - offset - 8) : stack_space_to_allocate);
2051 mmix_emit_sp_add (-stack_chunk);
2052 offset += stack_chunk;
2053 stack_space_to_allocate -= stack_chunk;
2056 insn = emit_move_insn (gen_rtx_MEM (DImode,
2057 plus_constant (stack_pointer_rtx,
2059 gen_rtx_REG (DImode, regno));
2060 RTX_FRAME_RELATED_P (insn) = 1;
2064 /* Finally, allocate room for outgoing args and local vars if room
2065 wasn't allocated above. */
2066 if (stack_space_to_allocate)
2067 mmix_emit_sp_add (-stack_space_to_allocate);
2070 /* Expands the function epilogue into RTX. */
2073 mmix_expand_epilogue (void)
2075 HOST_WIDE_INT locals_size = get_frame_size ();
2077 HOST_WIDE_INT stack_space_to_deallocate
2078 = (current_function_outgoing_args_size
2079 + current_function_pretend_args_size
2080 + locals_size + 7) & ~7;
2082 /* The assumption that locals_size fits in an int is asserted in
2083 mmix_expand_prologue. */
2085 /* The first address to access is beyond the outgoing_args area. */
2086 int offset = current_function_outgoing_args_size;
2088 /* Add the space for global non-register-stack registers.
2089 It is assumed that the frame-pointer register can be one of these
2090 registers, in which case it is excluded from the count when needed. */
2092 regno >= MMIX_FIRST_GLOBAL_REGNUM;
2094 if (((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
2095 && regs_ever_live[regno] && !call_used_regs[regno])
2096 || IS_MMIX_EH_RETURN_DATA_REG (regno))
2097 stack_space_to_deallocate += 8;
2099 /* Add in the space for register stack-pointer. If so, always add room
2100 for the saved PC. */
2101 if (MMIX_CFUN_HAS_LANDING_PAD)
2102 stack_space_to_deallocate += 16;
2103 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
2104 /* If we have a saved return-address slot, add it in. */
2105 stack_space_to_deallocate += 8;
2107 /* Add in the frame-pointer. */
2108 if (frame_pointer_needed)
2109 stack_space_to_deallocate += 8;
2111 /* Make sure we don't get an unaligned stack. */
2112 if ((stack_space_to_deallocate % 8) != 0)
2113 internal_error ("stack frame not a multiple of octabyte: %d",
2114 stack_space_to_deallocate);
2116 /* We will add back small offsets to the stack pointer as we go.
2117 First, we restore all registers that are global, i.e. not saved by
2118 the register file machinery. */
2120 for (regno = MMIX_FIRST_GLOBAL_REGNUM;
2123 if (((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
2124 && regs_ever_live[regno] && !call_used_regs[regno])
2125 || IS_MMIX_EH_RETURN_DATA_REG (regno))
2129 mmix_emit_sp_add (offset);
2130 stack_space_to_deallocate -= offset;
2134 emit_move_insn (gen_rtx_REG (DImode, regno),
2135 gen_rtx_MEM (DImode,
2136 plus_constant (stack_pointer_rtx,
2141 /* Here is where the local variables were. As in the prologue, they
2142 might be of an unaligned size. */
2143 offset += (locals_size + 7) & ~7;
2146 /* The saved register stack pointer is just below the frame-pointer
2147 register. We don't need to restore it "manually"; the POP
2148 instruction does that. */
2149 if (MMIX_CFUN_HAS_LANDING_PAD)
2151 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
2152 /* The return-address slot is just below the frame-pointer register.
2153 We don't need to restore it because we don't really use it. */
2156 /* Get back the old frame-pointer-value. */
2157 if (frame_pointer_needed)
2161 mmix_emit_sp_add (offset);
2163 stack_space_to_deallocate -= offset;
2167 emit_move_insn (hard_frame_pointer_rtx,
2168 gen_rtx_MEM (DImode,
2169 plus_constant (stack_pointer_rtx,
2174 /* We do not need to restore pretended incoming args, just add back
2176 if (stack_space_to_deallocate != 0)
2177 mmix_emit_sp_add (stack_space_to_deallocate);
2179 if (current_function_calls_eh_return)
2180 /* Adjust the (normal) stack-pointer to that of the receiver.
2181 FIXME: It would be nice if we could also adjust the register stack
2182 here, but we need to express it through DWARF 2 too. */
2183 emit_insn (gen_adddi3 (stack_pointer_rtx, stack_pointer_rtx,
2184 gen_rtx_REG (DImode,
2185 MMIX_EH_RETURN_STACKADJ_REGNUM)));
2188 /* Output an optimal sequence for setting a register to a specific
2189 constant. Used in an alternative for const_ints in movdi, and when
2190 using large stack-frame offsets.
2192 Use do_begin_end to say if a line-starting TAB and newline before the
2193 first insn and after the last insn is wanted. */
2196 mmix_output_register_setting (FILE *stream,
2198 HOST_WIDEST_INT value,
2202 fprintf (stream, "\t");
2204 if (mmix_shiftable_wyde_value ((unsigned HOST_WIDEST_INT) value))
2206 /* First, the one-insn cases. */
2207 mmix_output_shiftvalue_op_from_str (stream, "SET",
2208 (unsigned HOST_WIDEST_INT)
2210 fprintf (stream, " %s,", reg_names[regno]);
2211 mmix_output_shifted_value (stream, (unsigned HOST_WIDEST_INT) value);
2213 else if (mmix_shiftable_wyde_value (-(unsigned HOST_WIDEST_INT) value))
2215 /* We do this to get a bit more legible assembly code. The next
2216 alternative is mostly redundant with this. */
2218 mmix_output_shiftvalue_op_from_str (stream, "SET",
2219 -(unsigned HOST_WIDEST_INT)
2221 fprintf (stream, " %s,", reg_names[regno]);
2222 mmix_output_shifted_value (stream, -(unsigned HOST_WIDEST_INT) value);
2223 fprintf (stream, "\n\tNEGU %s,0,%s", reg_names[regno],
2226 else if (mmix_shiftable_wyde_value (~(unsigned HOST_WIDEST_INT) value))
2228 /* Slightly more expensive, the two-insn cases. */
2230 /* FIXME: We could of course also test if 0..255-N or ~(N | 1..255)
2231 is shiftable, or any other one-insn transformation of the value.
2232 FIXME: Check first if the value is "shiftable" by two loading
2233 with two insns, since it makes more readable assembly code (if
2234 anyone else cares). */
2236 mmix_output_shiftvalue_op_from_str (stream, "SET",
2237 ~(unsigned HOST_WIDEST_INT)
2239 fprintf (stream, " %s,", reg_names[regno]);
2240 mmix_output_shifted_value (stream, ~(unsigned HOST_WIDEST_INT) value);
2241 fprintf (stream, "\n\tNOR %s,%s,0", reg_names[regno],
2246 /* The generic case. 2..4 insns. */
2247 static const char *const higher_parts[] = {"L", "ML", "MH", "H"};
2248 const char *op = "SET";
2249 const char *line_begin = "";
2252 HOST_WIDEST_INT tmpvalue = value;
2254 /* Compute the number of insns needed to output this constant. */
2255 for (i = 0; i < 4 && tmpvalue != 0; i++)
2257 if (tmpvalue & 65535)
2261 if (TARGET_BASE_ADDRESSES && insns == 3)
2263 /* The number three is based on a static observation on
2264 ghostscript-6.52. Two and four are excluded because there
2265 are too many such constants, and each unique constant (maybe
2266 offset by 1..255) were used few times compared to other uses,
2269 We use base-plus-offset addressing to force it into a global
2270 register; we just use a "LDA reg,VALUE", which will cause the
2271 assembler and linker to DTRT (for constants as well as
2273 fprintf (stream, "LDA %s,", reg_names[regno]);
2274 mmix_output_octa (stream, value, 0);
2278 /* Output pertinent parts of the 4-wyde sequence.
2279 Still more to do if we want this to be optimal, but hey...
2280 Note that the zero case has been handled above. */
2281 for (i = 0; i < 4 && value != 0; i++)
2285 fprintf (stream, "%s%s%s %s,#%x", line_begin, op,
2286 higher_parts[i], reg_names[regno],
2287 (int) (value & 65535));
2288 /* The first one sets the rest of the bits to 0, the next
2289 ones add set bits. */
2291 line_begin = "\n\t";
2300 fprintf (stream, "\n");
2303 /* Return 1 if value is 0..65535*2**(16*N) for N=0..3.
2307 mmix_shiftable_wyde_value (unsigned HOST_WIDEST_INT value)
2309 /* Shift by 16 bits per group, stop when we've found two groups with
2312 int has_candidate = 0;
2314 for (i = 0; i < 4; i++)
2330 /* True if this is an address_operand or a symbolic operand. */
2333 mmix_symbolic_or_address_operand (rtx op, enum machine_mode mode)
2335 switch (GET_CODE (op))
2342 if ((GET_CODE (XEXP (op, 0)) == SYMBOL_REF
2343 || GET_CODE (XEXP (op, 0)) == LABEL_REF)
2344 && (GET_CODE (XEXP (op, 1)) == CONST_INT
2345 || (GET_CODE (XEXP (op, 1)) == CONST_DOUBLE
2346 && GET_MODE (XEXP (op, 1)) == VOIDmode)))
2350 return address_operand (op, mode);
2354 /* True if this is a register or CONST_INT (or CONST_DOUBLE for DImode).
2355 We could narrow the value down with a couple of predicated, but that
2356 doesn't seem to be worth it at the moment. */
2359 mmix_reg_or_constant_operand (rtx op, enum machine_mode mode)
2361 return register_operand (op, mode)
2362 || (GET_CODE (op) == CONST_DOUBLE && GET_MODE (op) == VOIDmode)
2363 || GET_CODE (op) == CONST_INT;
2366 /* True if this is a register with a condition-code mode. */
2369 mmix_reg_cc_operand (rtx op, enum machine_mode mode)
2371 if (mode == VOIDmode)
2372 mode = GET_MODE (op);
2374 return register_operand (op, mode)
2375 && (mode == CCmode || mode == CC_UNSmode || mode == CC_FPmode
2376 || mode == CC_FPEQmode || mode == CC_FUNmode);
2379 /* True if this is a foldable comparison operator
2380 - one where a the result of (compare:CC (reg) (const_int 0)) can be
2381 replaced by (reg). */
2384 mmix_foldable_comparison_operator (rtx op, enum machine_mode mode)
2386 RTX_CODE code = GET_CODE (op);
2388 if (mode == VOIDmode)
2389 mode = GET_MODE (op);
2391 if (mode == VOIDmode && COMPARISON_P (op))
2392 mode = GET_MODE (XEXP (op, 0));
2394 return ((mode == CCmode || mode == DImode)
2395 && (code == NE || code == EQ || code == GE || code == GT
2397 /* FIXME: This may be a stupid trick. What happens when GCC wants to
2398 reverse the condition? Can it do that by itself? Maybe it can
2399 even reverse the condition to fit a foldable one in the first
2401 || (mode == CC_UNSmode && (code == GTU || code == LEU));
2404 /* Like comparison_operator, but only true if this comparison operator is
2405 applied to a valid mode. Needed to avoid jump.c generating invalid
2406 code with -ffast-math (gcc.dg/20001228-1.c). */
2409 mmix_comparison_operator (rtx op, enum machine_mode mode)
2411 RTX_CODE code = GET_CODE (op);
2413 /* Comparison operators usually don't have a mode, but let's try and get
2414 one anyway for the day that changes. */
2415 if (mode == VOIDmode)
2416 mode = GET_MODE (op);
2418 /* Get the mode from the first operand if we don't have one. */
2419 if (mode == VOIDmode && COMPARISON_P (op))
2420 mode = GET_MODE (XEXP (op, 0));
2422 /* FIXME: This needs to be kept in sync with the tables in
2423 mmix_output_condition. */
2425 (mode == VOIDmode && COMPARISON_P (op))
2426 || (mode == CC_FUNmode
2427 && (code == ORDERED || code == UNORDERED))
2428 || (mode == CC_FPmode
2429 && (code == GT || code == LT))
2430 || (mode == CC_FPEQmode
2431 && (code == NE || code == EQ))
2432 || (mode == CC_UNSmode
2433 && (code == GEU || code == GTU || code == LEU || code == LTU))
2435 && (code == NE || code == EQ || code == GE || code == GT
2436 || code == LE || code == LT))
2438 && (code == NE || code == EQ || code == GE || code == GT
2439 || code == LE || code == LT || code == LEU || code == GTU));
2442 /* True if this is a register or 0 (int or float). */
2445 mmix_reg_or_0_operand (rtx op, enum machine_mode mode)
2447 /* FIXME: Is mode calculation necessary and correct? */
2449 op == CONST0_RTX (mode == VOIDmode ? GET_MODE (op) : mode)
2450 || register_operand (op, mode);
2453 /* True if this is a register or an int 0..255. */
2456 mmix_reg_or_8bit_operand (rtx op, enum machine_mode mode)
2458 return register_operand (op, mode)
2459 || (GET_CODE (op) == CONST_INT
2460 && CONST_OK_FOR_LETTER_P (INTVAL (op), 'I'));
2463 /* Returns zero if code and mode is not a valid condition from a
2464 compare-type insn. Nonzero if it is. The parameter op, if non-NULL,
2465 is the comparison of mode is CC-somethingmode. */
2468 mmix_valid_comparison (RTX_CODE code, enum machine_mode mode, rtx op)
2470 if (mode == VOIDmode && op != NULL_RTX)
2471 mode = GET_MODE (op);
2473 /* We don't care to look at these, they should always be valid. */
2474 if (mode == CCmode || mode == CC_UNSmode || mode == DImode)
2477 if ((mode == CC_FPmode || mode == DFmode)
2478 && (code == GT || code == LT))
2481 if ((mode == CC_FPEQmode || mode == DFmode)
2482 && (code == EQ || code == NE))
2485 if ((mode == CC_FUNmode || mode == DFmode)
2486 && (code == ORDERED || code == UNORDERED))
2492 /* X and Y are two things to compare using CODE. Emit a compare insn if
2493 possible and return the rtx for the cc-reg in the proper mode, or
2494 NULL_RTX if this is not a valid comparison. */
2497 mmix_gen_compare_reg (RTX_CODE code, rtx x, rtx y)
2499 enum machine_mode ccmode = SELECT_CC_MODE (code, x, y);
2502 /* FIXME: Do we get constants here? Of double mode? */
2503 enum machine_mode mode
2504 = GET_MODE (x) == VOIDmode
2506 : GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT ? DFmode : DImode;
2508 if (! mmix_valid_comparison (code, mode, x))
2511 cc_reg = gen_reg_rtx (ccmode);
2513 /* FIXME: Can we avoid emitting a compare insn here? */
2514 if (! REG_P (x) && ! REG_P (y))
2515 x = force_reg (mode, x);
2517 /* If it's not quite right yet, put y in a register. */
2519 && (GET_CODE (y) != CONST_INT
2520 || ! CONST_OK_FOR_LETTER_P (INTVAL (y), 'I')))
2521 y = force_reg (mode, y);
2523 emit_insn (gen_rtx_SET (VOIDmode, cc_reg,
2524 gen_rtx_COMPARE (ccmode, x, y)));
2529 /* Local (static) helper functions. */
2532 mmix_emit_sp_add (HOST_WIDE_INT offset)
2538 /* Negative stack-pointer adjustments are allocations and appear in
2539 the prologue only. We mark them as frame-related so unwind and
2540 debug info is properly emitted for them. */
2542 insn = emit_insn (gen_adddi3 (stack_pointer_rtx,
2547 rtx tmpr = gen_rtx_REG (DImode, 255);
2548 RTX_FRAME_RELATED_P (emit_move_insn (tmpr, GEN_INT (offset))) = 1;
2549 insn = emit_insn (gen_adddi3 (stack_pointer_rtx,
2550 stack_pointer_rtx, tmpr));
2552 RTX_FRAME_RELATED_P (insn) = 1;
2556 /* Positive adjustments are in the epilogue only. Don't mark them
2557 as "frame-related" for unwind info. */
2558 if (CONST_OK_FOR_LETTER_P (offset, 'L'))
2559 emit_insn (gen_adddi3 (stack_pointer_rtx,
2564 rtx tmpr = gen_rtx_REG (DImode, 255);
2565 emit_move_insn (tmpr, GEN_INT (offset));
2566 insn = emit_insn (gen_adddi3 (stack_pointer_rtx,
2567 stack_pointer_rtx, tmpr));
2572 /* Print operator suitable for doing something with a shiftable
2573 wyde. The type of operator is passed as an asm output modifier. */
2576 mmix_output_shiftvalue_op_from_str (FILE *stream,
2578 HOST_WIDEST_INT value)
2580 static const char *const op_part[] = {"L", "ML", "MH", "H"};
2583 if (! mmix_shiftable_wyde_value (value))
2585 char s[sizeof ("0xffffffffffffffff")];
2586 sprintf (s, HOST_WIDEST_INT_PRINT_HEX, value);
2587 internal_error ("MMIX Internal: %s is not a shiftable int", s);
2590 for (i = 0; i < 4; i++)
2592 /* We know we're through when we find one-bits in the low
2596 fprintf (stream, "%s%s", mainop, op_part[i]);
2602 /* No bits set? Then it must have been zero. */
2603 fprintf (stream, "%sL", mainop);
2606 /* Print a 64-bit value, optionally prefixed by assembly pseudo. */
2609 mmix_output_octa (FILE *stream, HOST_WIDEST_INT value, int do_begin_end)
2611 /* Snipped from final.c:output_addr_const. We need to avoid the
2612 presumed universal "0x" prefix. We can do it by replacing "0x" with
2613 "#0" here; we must avoid a space in the operands and no, the zero
2614 won't cause the number to be assumed in octal format. */
2615 char hex_format[sizeof (HOST_WIDEST_INT_PRINT_HEX)];
2618 fprintf (stream, "\tOCTA ");
2620 strcpy (hex_format, HOST_WIDEST_INT_PRINT_HEX);
2621 hex_format[0] = '#';
2622 hex_format[1] = '0';
2624 /* Provide a few alternative output formats depending on the number, to
2625 improve legibility of assembler output. */
2626 if ((value < (HOST_WIDEST_INT) 0 && value > (HOST_WIDEST_INT) -10000)
2627 || (value >= (HOST_WIDEST_INT) 0 && value <= (HOST_WIDEST_INT) 16384))
2628 fprintf (stream, "%d", (int) value);
2629 else if (value > (HOST_WIDEST_INT) 0
2630 && value < ((HOST_WIDEST_INT) 1 << 31) * 2)
2631 fprintf (stream, "#%x", (unsigned int) value);
2633 fprintf (stream, hex_format, value);
2636 fprintf (stream, "\n");
2639 /* Print the presumed shiftable wyde argument shifted into place (to
2640 be output with an operand). */
2643 mmix_output_shifted_value (FILE *stream, HOST_WIDEST_INT value)
2647 if (! mmix_shiftable_wyde_value (value))
2650 sprintf (s, HOST_WIDEST_INT_PRINT_HEX, value);
2651 internal_error ("MMIX Internal: %s is not a shiftable int", s);
2654 for (i = 0; i < 4; i++)
2656 /* We know we're through when we find one-bits in the low 16 bits. */
2659 fprintf (stream, "#%x", (int) (value & 0xffff));
2666 /* No bits set? Then it must have been zero. */
2667 fprintf (stream, "0");
2670 /* Output an MMIX condition name corresponding to an operator
2672 (comparison_operator [(comparison_operator ...) (const_int 0)])
2673 which means we have to look at *two* operators.
2675 The argument "reversed" refers to reversal of the condition (not the
2676 same as swapping the arguments). */
2679 mmix_output_condition (FILE *stream, rtx x, int reversed)
2685 /* The normal output cc-code. */
2686 const char *const normal;
2688 /* The reversed cc-code, or NULL if invalid. */
2689 const char *const reversed;
2694 enum machine_mode cc_mode;
2696 /* Terminated with {UNKNOWN, NULL, NULL} */
2697 const struct cc_conv *const convs;
2701 #define CCEND {UNKNOWN, NULL, NULL}
2703 static const struct cc_conv cc_fun_convs[]
2704 = {{ORDERED, "Z", "P"},
2705 {UNORDERED, "P", "Z"},
2707 static const struct cc_conv cc_fp_convs[]
2711 static const struct cc_conv cc_fpeq_convs[]
2715 static const struct cc_conv cc_uns_convs[]
2716 = {{GEU, "NN", "N"},
2721 static const struct cc_conv cc_signed_convs[]
2729 static const struct cc_conv cc_di_convs[]
2741 static const struct cc_type_conv cc_convs[]
2742 = {{CC_FUNmode, cc_fun_convs},
2743 {CC_FPmode, cc_fp_convs},
2744 {CC_FPEQmode, cc_fpeq_convs},
2745 {CC_UNSmode, cc_uns_convs},
2746 {CCmode, cc_signed_convs},
2747 {DImode, cc_di_convs}};
2752 enum machine_mode mode = GET_MODE (XEXP (x, 0));
2753 RTX_CODE cc = GET_CODE (x);
2755 for (i = 0; i < ARRAY_SIZE (cc_convs); i++)
2757 if (mode == cc_convs[i].cc_mode)
2759 for (j = 0; cc_convs[i].convs[j].cc != UNKNOWN; j++)
2760 if (cc == cc_convs[i].convs[j].cc)
2763 = (reversed ? cc_convs[i].convs[j].reversed
2764 : cc_convs[i].convs[j].normal);
2766 if (mmix_cc == NULL)
2767 fatal_insn ("MMIX Internal: Trying to output invalidly\
2768 reversed condition:", x);
2770 fprintf (stream, "%s", mmix_cc);
2774 fatal_insn ("MMIX Internal: What's the CC of this?", x);
2778 fatal_insn ("MMIX Internal: What is the CC of this?", x);
2781 /* Return the bit-value for a const_int or const_double. */
2783 static HOST_WIDEST_INT
2786 unsigned HOST_WIDEST_INT retval;
2788 if (GET_CODE (x) == CONST_INT)
2791 /* We make a little song and dance because converting to long long in
2792 gcc-2.7.2 is broken. I still want people to be able to use it for
2793 cross-compilation to MMIX. */
2794 if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == VOIDmode)
2796 if (sizeof (HOST_WIDE_INT) < sizeof (HOST_WIDEST_INT))
2798 retval = (unsigned) CONST_DOUBLE_LOW (x) / 2;
2800 retval |= CONST_DOUBLE_LOW (x) & 1;
2803 (unsigned HOST_WIDEST_INT) CONST_DOUBLE_HIGH (x)
2804 << (HOST_BITS_PER_LONG);
2807 retval = CONST_DOUBLE_HIGH (x);
2812 if (GET_CODE (x) == CONST_DOUBLE)
2814 REAL_VALUE_TYPE value;
2816 /* FIXME: This macro is not in the manual but should be. */
2817 REAL_VALUE_FROM_CONST_DOUBLE (value, x);
2819 if (GET_MODE (x) == DFmode)
2823 REAL_VALUE_TO_TARGET_DOUBLE (value, bits);
2825 if (sizeof (long) < sizeof (HOST_WIDEST_INT))
2827 retval = (unsigned long) bits[1] / 2;
2829 retval |= (unsigned long) bits[1] & 1;
2831 |= (unsigned HOST_WIDEST_INT) bits[0]
2832 << (sizeof (bits[0]) * 8);
2835 retval = (unsigned long) bits[1];
2839 else if (GET_MODE (x) == SFmode)
2842 REAL_VALUE_TO_TARGET_SINGLE (value, bits);
2844 return (unsigned long) bits;
2848 fatal_insn ("MMIX Internal: This is not a constant:", x);
2851 /* Worker function for TARGET_STRUCT_VALUE_RTX. */
2854 mmix_struct_value_rtx (tree fntype ATTRIBUTE_UNUSED,
2855 int incoming ATTRIBUTE_UNUSED)
2857 return gen_rtx_REG (Pmode, MMIX_STRUCT_VALUE_REGNUM);
2862 * eval: (c-set-style "gnu")
2863 * indent-tabs-mode: t