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 /* ASM_OUTPUT_SOURCE_LINE. */
1242 mmix_asm_output_source_line (FILE *stream, int lineno)
1244 fprintf (stream, "# %d ", lineno);
1245 OUTPUT_QUOTED_STRING (stream, main_input_filename);
1246 fprintf (stream, "\n");
1249 /* Target hook for assembling integer objects. Use mmix_print_operand
1250 for WYDE and TETRA. Use mmix_output_octa to output 8-byte
1254 mmix_assemble_integer (rtx x, unsigned int size, int aligned_p)
1259 /* We handle a limited number of types of operands in here. But
1260 that's ok, because we can punt to generic functions. We then
1261 pretend that aligned data isn't needed, so the usual .<pseudo>
1262 syntax is used (which works for aligned data too). We actually
1263 *must* do that, since we say we don't have simple aligned
1264 pseudos, causing this function to be called. We just try and
1265 keep as much compatibility as possible with mmixal syntax for
1266 normal cases (i.e. without GNU extensions and C only). */
1268 if (GET_CODE (x) != CONST_INT)
1273 fputs ("\tBYTE\t", asm_out_file);
1274 mmix_print_operand (asm_out_file, x, 'B');
1275 fputc ('\n', asm_out_file);
1279 if (GET_CODE (x) != CONST_INT)
1284 fputs ("\tWYDE\t", asm_out_file);
1285 mmix_print_operand (asm_out_file, x, 'W');
1286 fputc ('\n', asm_out_file);
1290 if (GET_CODE (x) != CONST_INT)
1295 fputs ("\tTETRA\t", asm_out_file);
1296 mmix_print_operand (asm_out_file, x, 'L');
1297 fputc ('\n', asm_out_file);
1301 if (GET_CODE (x) == CONST_DOUBLE)
1302 /* We don't get here anymore for CONST_DOUBLE, because DImode
1303 isn't expressed as CONST_DOUBLE, and DFmode is handled
1306 assemble_integer_with_op ("\tOCTA\t", x);
1309 return default_assemble_integer (x, size, aligned_p);
1312 /* ASM_OUTPUT_ASCII. */
1315 mmix_asm_output_ascii (FILE *stream, const char *string, int length)
1319 int chunk_size = length > 60 ? 60 : length;
1320 fprintf (stream, "\tBYTE ");
1321 mmix_output_quoted_string (stream, string, chunk_size);
1322 string += chunk_size;
1323 length -= chunk_size;
1324 fprintf (stream, "\n");
1328 /* ASM_OUTPUT_ALIGNED_COMMON. */
1331 mmix_asm_output_aligned_common (FILE *stream,
1336 /* This is mostly the elfos.h one. There doesn't seem to be a way to
1337 express this in a mmixal-compatible way. */
1338 fprintf (stream, "\t.comm\t");
1339 assemble_name (stream, name);
1340 fprintf (stream, ",%u,%u ! mmixal-incompatible COMMON\n",
1341 size, align / BITS_PER_UNIT);
1344 /* ASM_OUTPUT_ALIGNED_LOCAL. */
1347 mmix_asm_output_aligned_local (FILE *stream,
1354 ASM_OUTPUT_ALIGN (stream, exact_log2 (align/BITS_PER_UNIT));
1355 assemble_name (stream, name);
1356 fprintf (stream, "\tLOC @+%d\n", size);
1359 /* ASM_OUTPUT_LABEL. */
1362 mmix_asm_output_label (FILE *stream, const char *name)
1364 assemble_name (stream, name);
1365 fprintf (stream, "\tIS @\n");
1368 /* ASM_DECLARE_REGISTER_GLOBAL. */
1371 mmix_asm_declare_register_global (FILE *stream ATTRIBUTE_UNUSED,
1372 tree decl ATTRIBUTE_UNUSED,
1373 int regno ATTRIBUTE_UNUSED,
1374 const char *name ATTRIBUTE_UNUSED)
1376 /* Nothing to do here, but there *will* be, therefore the framework is
1380 /* ASM_WEAKEN_LABEL. */
1383 mmix_asm_weaken_label (FILE *stream ATTRIBUTE_UNUSED,
1384 const char *name ATTRIBUTE_UNUSED)
1386 fprintf (stream, "\t.weak ");
1387 assemble_name (stream, name);
1388 fprintf (stream, " ! mmixal-incompatible\n");
1391 /* MAKE_DECL_ONE_ONLY. */
1394 mmix_make_decl_one_only (tree decl)
1396 DECL_WEAK (decl) = 1;
1399 /* ASM_OUTPUT_LABELREF.
1400 Strip GCC's '*' and our own '@'. No order is assumed. */
1403 mmix_asm_output_labelref (FILE *stream, const char *name)
1407 for (; (*name == '@' || *name == '*'); name++)
1411 asm_fprintf (stream, "%s%U%s",
1412 is_extern && TARGET_TOPLEVEL_SYMBOLS ? ":" : "",
1416 /* ASM_OUTPUT_DEF. */
1419 mmix_asm_output_def (FILE *stream, const char *name, const char *value)
1421 assemble_name (stream, name);
1422 fprintf (stream, "\tIS ");
1423 assemble_name (stream, value);
1424 fputc ('\n', stream);
1427 /* PRINT_OPERAND. */
1430 mmix_print_operand (FILE *stream, rtx x, int code)
1432 /* When we add support for different codes later, we can, when needed,
1433 drop through to the main handler with a modified operand. */
1435 int regno = x != NULL_RTX && REG_P (x) ? REGNO (x) : 0;
1439 /* Unrelated codes are in alphabetic order. */
1442 /* For conditional branches, output "P" for a probable branch. */
1443 if (TARGET_BRANCH_PREDICT)
1445 x = find_reg_note (current_output_insn, REG_BR_PROB, 0);
1446 if (x && INTVAL (XEXP (x, 0)) > REG_BR_PROB_BASE / 2)
1452 /* For the %d in POP %d,0. */
1453 fprintf (stream, "%d", MMIX_POP_ARGUMENT ());
1457 if (GET_CODE (x) != CONST_INT)
1458 fatal_insn ("MMIX Internal: Expected a CONST_INT, not this", x);
1459 fprintf (stream, "%d", (int) (INTVAL (x) & 0xff));
1463 /* Highpart. Must be general register, and not the last one, as
1464 that one cannot be part of a consecutive register pair. */
1465 if (regno > MMIX_LAST_GENERAL_REGISTER - 1)
1466 internal_error ("MMIX Internal: Bad register: %d", regno);
1468 /* This is big-endian, so the high-part is the first one. */
1469 fprintf (stream, "%s", reg_names[MMIX_OUTPUT_REGNO (regno)]);
1473 /* Lowpart. Must be CONST_INT or general register, and not the last
1474 one, as that one cannot be part of a consecutive register pair. */
1475 if (GET_CODE (x) == CONST_INT)
1477 fprintf (stream, "#%lx",
1478 (unsigned long) (INTVAL (x)
1479 & ((unsigned int) 0x7fffffff * 2 + 1)));
1483 if (GET_CODE (x) == SYMBOL_REF)
1485 output_addr_const (stream, x);
1489 if (regno > MMIX_LAST_GENERAL_REGISTER - 1)
1490 internal_error ("MMIX Internal: Bad register: %d", regno);
1492 /* This is big-endian, so the low-part is + 1. */
1493 fprintf (stream, "%s", reg_names[MMIX_OUTPUT_REGNO (regno) + 1]);
1496 /* Can't use 'a' because that's a generic modifier for address
1499 mmix_output_shiftvalue_op_from_str (stream, "ANDN",
1500 ~(unsigned HOST_WIDEST_INT)
1505 mmix_output_shiftvalue_op_from_str (stream, "INC",
1506 (unsigned HOST_WIDEST_INT)
1511 mmix_output_shiftvalue_op_from_str (stream, "OR",
1512 (unsigned HOST_WIDEST_INT)
1517 mmix_output_shiftvalue_op_from_str (stream, "SET",
1518 (unsigned HOST_WIDEST_INT)
1524 mmix_output_condition (stream, x, (code == 'D'));
1528 /* Output an extra "e" to make fcmpe, fune. */
1529 if (TARGET_FCMP_EPSILON)
1530 fprintf (stream, "e");
1534 /* Output the number minus 1. */
1535 if (GET_CODE (x) != CONST_INT)
1537 fatal_insn ("MMIX Internal: Bad value for 'm', not a CONST_INT",
1540 fprintf (stream, HOST_WIDEST_INT_PRINT_DEC,
1541 (HOST_WIDEST_INT) (mmix_intval (x) - 1));
1545 /* Store the number of registers we want to save. This was setup
1546 by the prologue. The actual operand contains the number of
1547 registers to pass, but we don't use it currently. Anyway, we
1548 need to output the number of saved registers here. */
1549 fprintf (stream, "%d",
1550 cfun->machine->highest_saved_stack_register + 1);
1554 /* Store the register to output a constant to. */
1556 fatal_insn ("MMIX Internal: Expected a register, not this", x);
1557 mmix_output_destination_register = MMIX_OUTPUT_REGNO (regno);
1561 /* Output the constant. Note that we use this for floats as well. */
1562 if (GET_CODE (x) != CONST_INT
1563 && (GET_CODE (x) != CONST_DOUBLE
1564 || (GET_MODE (x) != VOIDmode && GET_MODE (x) != DFmode
1565 && GET_MODE (x) != SFmode)))
1566 fatal_insn ("MMIX Internal: Expected a constant, not this", x);
1567 mmix_output_register_setting (stream,
1568 mmix_output_destination_register,
1569 mmix_intval (x), 0);
1573 /* An U for unsigned, if TARGET_ZERO_EXTEND. Ignore the operand. */
1574 if (TARGET_ZERO_EXTEND)
1579 mmix_output_shifted_value (stream, (HOST_WIDEST_INT) mmix_intval (x));
1583 mmix_output_shifted_value (stream, (HOST_WIDEST_INT) ~mmix_intval (x));
1587 if (GET_CODE (x) != CONST_INT)
1588 fatal_insn ("MMIX Internal: Expected a CONST_INT, not this", x);
1589 fprintf (stream, "#%x", (int) (INTVAL (x) & 0xffff));
1593 /* Nothing to do. */
1597 /* Presumably there's a missing case above if we get here. */
1598 internal_error ("MMIX Internal: Missing `%c' case in mmix_print_operand", code);
1601 switch (GET_CODE (modified_x))
1604 regno = REGNO (modified_x);
1605 if (regno >= FIRST_PSEUDO_REGISTER)
1606 internal_error ("MMIX Internal: Bad register: %d", regno);
1607 fprintf (stream, "%s", reg_names[MMIX_OUTPUT_REGNO (regno)]);
1611 output_address (XEXP (modified_x, 0));
1615 /* For -2147483648, mmixal complains that the constant does not fit
1616 in 4 bytes, so let's output it as hex. Take care to handle hosts
1617 where HOST_WIDE_INT is longer than an int.
1619 Print small constants +-255 using decimal. */
1621 if (INTVAL (modified_x) > -256 && INTVAL (modified_x) < 256)
1622 fprintf (stream, "%d", (int) (INTVAL (modified_x)));
1624 fprintf (stream, "#%x",
1625 (int) (INTVAL (modified_x)) & (unsigned int) ~0);
1629 /* Do somewhat as CONST_INT. */
1630 mmix_output_octa (stream, mmix_intval (modified_x), 0);
1634 output_addr_const (stream, modified_x);
1638 /* No need to test for all strange things. Let output_addr_const do
1640 if (CONSTANT_P (modified_x)
1641 /* Strangely enough, this is not included in CONSTANT_P.
1642 FIXME: Ask/check about sanity here. */
1643 || GET_CODE (modified_x) == CODE_LABEL)
1645 output_addr_const (stream, modified_x);
1649 /* We need the original here. */
1650 fatal_insn ("MMIX Internal: Cannot decode this operand", x);
1654 /* PRINT_OPERAND_PUNCT_VALID_P. */
1657 mmix_print_operand_punct_valid_p (int code ATTRIBUTE_UNUSED)
1659 /* A '+' is used for branch prediction, similar to other ports. */
1661 /* A '.' is used for the %d in the POP %d,0 return insn. */
1665 /* PRINT_OPERAND_ADDRESS. */
1668 mmix_print_operand_address (FILE *stream, rtx x)
1672 /* I find the generated assembly code harder to read without
1674 fprintf (stream, "%s,0", reg_names[MMIX_OUTPUT_REGNO (REGNO (x))]);
1677 else if (GET_CODE (x) == PLUS)
1679 rtx x1 = XEXP (x, 0);
1680 rtx x2 = XEXP (x, 1);
1684 fprintf (stream, "%s,", reg_names[MMIX_OUTPUT_REGNO (REGNO (x1))]);
1688 fprintf (stream, "%s",
1689 reg_names[MMIX_OUTPUT_REGNO (REGNO (x2))]);
1692 else if (GET_CODE (x2) == CONST_INT
1693 && CONST_OK_FOR_LETTER_P (INTVAL (x2), 'I'))
1695 output_addr_const (stream, x2);
1701 if (TARGET_BASE_ADDRESSES && mmix_legitimate_constant_p (x))
1703 output_addr_const (stream, x);
1707 fatal_insn ("MMIX Internal: This is not a recognized address", x);
1710 /* ASM_OUTPUT_REG_PUSH. */
1713 mmix_asm_output_reg_push (FILE *stream, int regno)
1715 fprintf (stream, "\tSUBU %s,%s,8\n\tSTOU %s,%s,0\n",
1716 reg_names[MMIX_STACK_POINTER_REGNUM],
1717 reg_names[MMIX_STACK_POINTER_REGNUM],
1718 reg_names[MMIX_OUTPUT_REGNO (regno)],
1719 reg_names[MMIX_STACK_POINTER_REGNUM]);
1722 /* ASM_OUTPUT_REG_POP. */
1725 mmix_asm_output_reg_pop (FILE *stream, int regno)
1727 fprintf (stream, "\tLDOU %s,%s,0\n\tINCL %s,8\n",
1728 reg_names[MMIX_OUTPUT_REGNO (regno)],
1729 reg_names[MMIX_STACK_POINTER_REGNUM],
1730 reg_names[MMIX_STACK_POINTER_REGNUM]);
1733 /* ASM_OUTPUT_ADDR_DIFF_ELT. */
1736 mmix_asm_output_addr_diff_elt (FILE *stream,
1737 rtx body ATTRIBUTE_UNUSED,
1741 fprintf (stream, "\tTETRA L%d-L%d\n", value, rel);
1744 /* ASM_OUTPUT_ADDR_VEC_ELT. */
1747 mmix_asm_output_addr_vec_elt (FILE *stream, int value)
1749 fprintf (stream, "\tOCTA L:%d\n", value);
1752 /* ASM_OUTPUT_SKIP. */
1755 mmix_asm_output_skip (FILE *stream, int nbytes)
1757 fprintf (stream, "\tLOC @+%d\n", nbytes);
1760 /* ASM_OUTPUT_ALIGN. */
1763 mmix_asm_output_align (FILE *stream, int power)
1765 /* We need to record the needed alignment of this section in the object,
1766 so we have to output an alignment directive. Use a .p2align (not
1767 .align) so people will never have to wonder about whether the
1768 argument is in number of bytes or the log2 thereof. We do it in
1769 addition to the LOC directive, so nothing needs tweaking when
1770 copy-pasting assembly into mmixal. */
1771 fprintf (stream, "\t.p2align %d\n", power);
1772 fprintf (stream, "\tLOC @+(%d-@)&%d\n", 1 << power, (1 << power) - 1);
1775 /* DBX_REGISTER_NUMBER. */
1778 mmix_dbx_register_number (int regno)
1780 /* Adjust the register number to the one it will be output as, dammit.
1781 It'd be nice if we could check the assumption that we're filling a
1782 gap, but every register between the last saved register and parameter
1783 registers might be a valid parameter register. */
1784 regno = MMIX_OUTPUT_REGNO (regno);
1786 /* We need to renumber registers to get the number of the return address
1787 register in the range 0..255. It is also space-saving if registers
1788 mentioned in the call-frame information (which uses this function by
1789 defaulting DWARF_FRAME_REGNUM to DBX_REGISTER_NUMBER) are numbered
1790 0 .. 63. So map 224 .. 256+15 -> 0 .. 47 and 0 .. 223 -> 48..223+48. */
1791 return regno >= 224 ? (regno - 224) : (regno + 48);
1794 /* End of target macro support functions.
1796 Now the MMIX port's own functions. First the exported ones. */
1798 /* Wrapper for get_hard_reg_initial_val since integrate.h isn't included
1799 from insn-emit.c. */
1802 mmix_get_hard_reg_initial_val (enum machine_mode mode, int regno)
1804 return get_hard_reg_initial_val (mode, regno);
1807 /* Nonzero when the function epilogue is simple enough that a single
1808 "POP %d,0" should be used even within the function. */
1811 mmix_use_simple_return (void)
1815 int stack_space_to_allocate
1816 = (current_function_outgoing_args_size
1817 + current_function_pretend_args_size
1818 + get_frame_size () + 7) & ~7;
1820 if (!TARGET_USE_RETURN_INSN || !reload_completed)
1824 regno >= MMIX_FIRST_GLOBAL_REGNUM;
1826 /* Note that we assume that the frame-pointer-register is one of these
1827 registers, in which case we don't count it here. */
1828 if ((((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
1829 && regs_ever_live[regno] && !call_used_regs[regno]))
1830 || IS_MMIX_EH_RETURN_DATA_REG (regno))
1833 if (frame_pointer_needed)
1834 stack_space_to_allocate += 8;
1836 if (MMIX_CFUN_HAS_LANDING_PAD)
1837 stack_space_to_allocate += 16;
1838 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
1839 stack_space_to_allocate += 8;
1841 return stack_space_to_allocate == 0;
1845 /* Expands the function prologue into RTX. */
1848 mmix_expand_prologue (void)
1850 HOST_WIDE_INT locals_size = get_frame_size ();
1852 HOST_WIDE_INT stack_space_to_allocate
1853 = (current_function_outgoing_args_size
1854 + current_function_pretend_args_size
1855 + locals_size + 7) & ~7;
1856 HOST_WIDE_INT offset = -8;
1858 /* Add room needed to save global non-register-stack registers. */
1860 regno >= MMIX_FIRST_GLOBAL_REGNUM;
1862 /* Note that we assume that the frame-pointer-register is one of these
1863 registers, in which case we don't count it here. */
1864 if ((((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
1865 && regs_ever_live[regno] && !call_used_regs[regno]))
1866 || IS_MMIX_EH_RETURN_DATA_REG (regno))
1867 stack_space_to_allocate += 8;
1869 /* If we do have a frame-pointer, add room for it. */
1870 if (frame_pointer_needed)
1871 stack_space_to_allocate += 8;
1873 /* If we have a non-local label, we need to be able to unwind to it, so
1874 store the current register stack pointer. Also store the return
1875 address if we do that. */
1876 if (MMIX_CFUN_HAS_LANDING_PAD)
1877 stack_space_to_allocate += 16;
1878 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
1879 /* If we do have a saved return-address slot, add room for it. */
1880 stack_space_to_allocate += 8;
1882 /* Make sure we don't get an unaligned stack. */
1883 if ((stack_space_to_allocate % 8) != 0)
1884 internal_error ("stack frame not a multiple of 8 bytes: %d",
1885 stack_space_to_allocate);
1887 if (current_function_pretend_args_size)
1889 int mmix_first_vararg_reg
1890 = (MMIX_FIRST_INCOMING_ARG_REGNUM
1891 + (MMIX_MAX_ARGS_IN_REGS
1892 - current_function_pretend_args_size / 8));
1895 = MMIX_FIRST_INCOMING_ARG_REGNUM + MMIX_MAX_ARGS_IN_REGS - 1;
1896 regno >= mmix_first_vararg_reg;
1901 HOST_WIDE_INT stack_chunk
1902 = stack_space_to_allocate > (256 - 8)
1903 ? (256 - 8) : stack_space_to_allocate;
1905 mmix_emit_sp_add (-stack_chunk);
1906 offset += stack_chunk;
1907 stack_space_to_allocate -= stack_chunk;
1910 /* These registers aren't actually saved (as in "will be
1911 restored"), so don't tell DWARF2 they're saved. */
1912 emit_move_insn (gen_rtx_MEM (DImode,
1913 plus_constant (stack_pointer_rtx,
1915 gen_rtx_REG (DImode, regno));
1920 /* Store the frame-pointer. */
1922 if (frame_pointer_needed)
1928 /* Get 8 less than otherwise, since we need to reach offset + 8. */
1929 HOST_WIDE_INT stack_chunk
1930 = stack_space_to_allocate > (256 - 8 - 8)
1931 ? (256 - 8 - 8) : stack_space_to_allocate;
1933 mmix_emit_sp_add (-stack_chunk);
1935 offset += stack_chunk;
1936 stack_space_to_allocate -= stack_chunk;
1939 insn = emit_move_insn (gen_rtx_MEM (DImode,
1940 plus_constant (stack_pointer_rtx,
1942 hard_frame_pointer_rtx);
1943 RTX_FRAME_RELATED_P (insn) = 1;
1944 insn = emit_insn (gen_adddi3 (hard_frame_pointer_rtx,
1946 GEN_INT (offset + 8)));
1947 RTX_FRAME_RELATED_P (insn) = 1;
1951 if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
1956 /* Store the return-address, if one is needed on the stack. We
1957 usually store it in a register when needed, but that doesn't work
1958 with -fexceptions. */
1962 /* Get 8 less than otherwise, since we need to reach offset + 8. */
1963 HOST_WIDE_INT stack_chunk
1964 = stack_space_to_allocate > (256 - 8 - 8)
1965 ? (256 - 8 - 8) : stack_space_to_allocate;
1967 mmix_emit_sp_add (-stack_chunk);
1969 offset += stack_chunk;
1970 stack_space_to_allocate -= stack_chunk;
1973 tmpreg = gen_rtx_REG (DImode, 255);
1974 retreg = gen_rtx_REG (DImode, MMIX_rJ_REGNUM);
1976 /* Dwarf2 code is confused by the use of a temporary register for
1977 storing the return address, so we have to express it as a note,
1978 which we attach to the actual store insn. */
1979 emit_move_insn (tmpreg, retreg);
1981 insn = emit_move_insn (gen_rtx_MEM (DImode,
1982 plus_constant (stack_pointer_rtx,
1985 RTX_FRAME_RELATED_P (insn) = 1;
1987 = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
1988 gen_rtx_SET (VOIDmode,
1989 gen_rtx_MEM (DImode,
1990 plus_constant (stack_pointer_rtx,
1997 else if (MMIX_CFUN_HAS_LANDING_PAD)
2000 if (MMIX_CFUN_HAS_LANDING_PAD)
2002 /* Store the register defining the numbering of local registers, so
2003 we know how long to unwind the register stack. */
2007 /* Get 8 less than otherwise, since we need to reach offset + 8. */
2008 HOST_WIDE_INT stack_chunk
2009 = stack_space_to_allocate > (256 - 8 - 8)
2010 ? (256 - 8 - 8) : stack_space_to_allocate;
2012 mmix_emit_sp_add (-stack_chunk);
2014 offset += stack_chunk;
2015 stack_space_to_allocate -= stack_chunk;
2018 /* We don't tell dwarf2 about this one; we just have it to unwind
2019 the register stack at landing pads. FIXME: It's a kludge because
2020 we can't describe the effect of the PUSHJ and PUSHGO insns on the
2021 register stack at the moment. Best thing would be to handle it
2022 like stack-pointer offsets. Better: some hook into dwarf2out.c
2023 to produce DW_CFA_expression:s that specify the increment of rO,
2024 and unwind it at eh_return (preferred) or at the landing pad.
2025 Then saves to $0..$G-1 could be specified through that register. */
2027 emit_move_insn (gen_rtx_REG (DImode, 255),
2028 gen_rtx_REG (DImode,
2030 emit_move_insn (gen_rtx_MEM (DImode,
2031 plus_constant (stack_pointer_rtx, offset)),
2032 gen_rtx_REG (DImode, 255));
2036 /* After the return-address and the frame-pointer, we have the local
2037 variables. They're the ones that may have an "unaligned" size. */
2038 offset -= (locals_size + 7) & ~7;
2040 /* Now store all registers that are global, i.e. not saved by the
2041 register file machinery.
2043 It is assumed that the frame-pointer is one of these registers, so it
2044 is explicitly excluded in the count. */
2047 regno >= MMIX_FIRST_GLOBAL_REGNUM;
2049 if (((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
2050 && regs_ever_live[regno] && ! call_used_regs[regno])
2051 || IS_MMIX_EH_RETURN_DATA_REG (regno))
2057 HOST_WIDE_INT stack_chunk
2058 = (stack_space_to_allocate > (256 - offset - 8)
2059 ? (256 - offset - 8) : stack_space_to_allocate);
2061 mmix_emit_sp_add (-stack_chunk);
2062 offset += stack_chunk;
2063 stack_space_to_allocate -= stack_chunk;
2066 insn = emit_move_insn (gen_rtx_MEM (DImode,
2067 plus_constant (stack_pointer_rtx,
2069 gen_rtx_REG (DImode, regno));
2070 RTX_FRAME_RELATED_P (insn) = 1;
2074 /* Finally, allocate room for outgoing args and local vars if room
2075 wasn't allocated above. */
2076 if (stack_space_to_allocate)
2077 mmix_emit_sp_add (-stack_space_to_allocate);
2080 /* Expands the function epilogue into RTX. */
2083 mmix_expand_epilogue (void)
2085 HOST_WIDE_INT locals_size = get_frame_size ();
2087 HOST_WIDE_INT stack_space_to_deallocate
2088 = (current_function_outgoing_args_size
2089 + current_function_pretend_args_size
2090 + locals_size + 7) & ~7;
2092 /* The assumption that locals_size fits in an int is asserted in
2093 mmix_expand_prologue. */
2095 /* The first address to access is beyond the outgoing_args area. */
2096 int offset = current_function_outgoing_args_size;
2098 /* Add the space for global non-register-stack registers.
2099 It is assumed that the frame-pointer register can be one of these
2100 registers, in which case it is excluded from the count when needed. */
2102 regno >= MMIX_FIRST_GLOBAL_REGNUM;
2104 if (((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
2105 && regs_ever_live[regno] && !call_used_regs[regno])
2106 || IS_MMIX_EH_RETURN_DATA_REG (regno))
2107 stack_space_to_deallocate += 8;
2109 /* Add in the space for register stack-pointer. If so, always add room
2110 for the saved PC. */
2111 if (MMIX_CFUN_HAS_LANDING_PAD)
2112 stack_space_to_deallocate += 16;
2113 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
2114 /* If we have a saved return-address slot, add it in. */
2115 stack_space_to_deallocate += 8;
2117 /* Add in the frame-pointer. */
2118 if (frame_pointer_needed)
2119 stack_space_to_deallocate += 8;
2121 /* Make sure we don't get an unaligned stack. */
2122 if ((stack_space_to_deallocate % 8) != 0)
2123 internal_error ("stack frame not a multiple of octabyte: %d",
2124 stack_space_to_deallocate);
2126 /* We will add back small offsets to the stack pointer as we go.
2127 First, we restore all registers that are global, i.e. not saved by
2128 the register file machinery. */
2130 for (regno = MMIX_FIRST_GLOBAL_REGNUM;
2133 if (((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
2134 && regs_ever_live[regno] && !call_used_regs[regno])
2135 || IS_MMIX_EH_RETURN_DATA_REG (regno))
2139 mmix_emit_sp_add (offset);
2140 stack_space_to_deallocate -= offset;
2144 emit_move_insn (gen_rtx_REG (DImode, regno),
2145 gen_rtx_MEM (DImode,
2146 plus_constant (stack_pointer_rtx,
2151 /* Here is where the local variables were. As in the prologue, they
2152 might be of an unaligned size. */
2153 offset += (locals_size + 7) & ~7;
2156 /* The saved register stack pointer is just below the frame-pointer
2157 register. We don't need to restore it "manually"; the POP
2158 instruction does that. */
2159 if (MMIX_CFUN_HAS_LANDING_PAD)
2161 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
2162 /* The return-address slot is just below the frame-pointer register.
2163 We don't need to restore it because we don't really use it. */
2166 /* Get back the old frame-pointer-value. */
2167 if (frame_pointer_needed)
2171 mmix_emit_sp_add (offset);
2173 stack_space_to_deallocate -= offset;
2177 emit_move_insn (hard_frame_pointer_rtx,
2178 gen_rtx_MEM (DImode,
2179 plus_constant (stack_pointer_rtx,
2184 /* We do not need to restore pretended incoming args, just add back
2186 if (stack_space_to_deallocate != 0)
2187 mmix_emit_sp_add (stack_space_to_deallocate);
2189 if (current_function_calls_eh_return)
2190 /* Adjust the (normal) stack-pointer to that of the receiver.
2191 FIXME: It would be nice if we could also adjust the register stack
2192 here, but we need to express it through DWARF 2 too. */
2193 emit_insn (gen_adddi3 (stack_pointer_rtx, stack_pointer_rtx,
2194 gen_rtx_REG (DImode,
2195 MMIX_EH_RETURN_STACKADJ_REGNUM)));
2198 /* Output an optimal sequence for setting a register to a specific
2199 constant. Used in an alternative for const_ints in movdi, and when
2200 using large stack-frame offsets.
2202 Use do_begin_end to say if a line-starting TAB and newline before the
2203 first insn and after the last insn is wanted. */
2206 mmix_output_register_setting (FILE *stream,
2208 HOST_WIDEST_INT value,
2212 fprintf (stream, "\t");
2214 if (mmix_shiftable_wyde_value ((unsigned HOST_WIDEST_INT) value))
2216 /* First, the one-insn cases. */
2217 mmix_output_shiftvalue_op_from_str (stream, "SET",
2218 (unsigned HOST_WIDEST_INT)
2220 fprintf (stream, " %s,", reg_names[regno]);
2221 mmix_output_shifted_value (stream, (unsigned HOST_WIDEST_INT) value);
2223 else if (mmix_shiftable_wyde_value (-(unsigned HOST_WIDEST_INT) value))
2225 /* We do this to get a bit more legible assembly code. The next
2226 alternative is mostly redundant with this. */
2228 mmix_output_shiftvalue_op_from_str (stream, "SET",
2229 -(unsigned HOST_WIDEST_INT)
2231 fprintf (stream, " %s,", reg_names[regno]);
2232 mmix_output_shifted_value (stream, -(unsigned HOST_WIDEST_INT) value);
2233 fprintf (stream, "\n\tNEGU %s,0,%s", reg_names[regno],
2236 else if (mmix_shiftable_wyde_value (~(unsigned HOST_WIDEST_INT) value))
2238 /* Slightly more expensive, the two-insn cases. */
2240 /* FIXME: We could of course also test if 0..255-N or ~(N | 1..255)
2241 is shiftable, or any other one-insn transformation of the value.
2242 FIXME: Check first if the value is "shiftable" by two loading
2243 with two insns, since it makes more readable assembly code (if
2244 anyone else cares). */
2246 mmix_output_shiftvalue_op_from_str (stream, "SET",
2247 ~(unsigned HOST_WIDEST_INT)
2249 fprintf (stream, " %s,", reg_names[regno]);
2250 mmix_output_shifted_value (stream, ~(unsigned HOST_WIDEST_INT) value);
2251 fprintf (stream, "\n\tNOR %s,%s,0", reg_names[regno],
2256 /* The generic case. 2..4 insns. */
2257 static const char *const higher_parts[] = {"L", "ML", "MH", "H"};
2258 const char *op = "SET";
2259 const char *line_begin = "";
2262 HOST_WIDEST_INT tmpvalue = value;
2264 /* Compute the number of insns needed to output this constant. */
2265 for (i = 0; i < 4 && tmpvalue != 0; i++)
2267 if (tmpvalue & 65535)
2271 if (TARGET_BASE_ADDRESSES && insns == 3)
2273 /* The number three is based on a static observation on
2274 ghostscript-6.52. Two and four are excluded because there
2275 are too many such constants, and each unique constant (maybe
2276 offset by 1..255) were used few times compared to other uses,
2279 We use base-plus-offset addressing to force it into a global
2280 register; we just use a "LDA reg,VALUE", which will cause the
2281 assembler and linker to DTRT (for constants as well as
2283 fprintf (stream, "LDA %s,", reg_names[regno]);
2284 mmix_output_octa (stream, value, 0);
2288 /* Output pertinent parts of the 4-wyde sequence.
2289 Still more to do if we want this to be optimal, but hey...
2290 Note that the zero case has been handled above. */
2291 for (i = 0; i < 4 && value != 0; i++)
2295 fprintf (stream, "%s%s%s %s,#%x", line_begin, op,
2296 higher_parts[i], reg_names[regno],
2297 (int) (value & 65535));
2298 /* The first one sets the rest of the bits to 0, the next
2299 ones add set bits. */
2301 line_begin = "\n\t";
2310 fprintf (stream, "\n");
2313 /* Return 1 if value is 0..65535*2**(16*N) for N=0..3.
2317 mmix_shiftable_wyde_value (unsigned HOST_WIDEST_INT value)
2319 /* Shift by 16 bits per group, stop when we've found two groups with
2322 int has_candidate = 0;
2324 for (i = 0; i < 4; i++)
2340 /* True if this is an address_operand or a symbolic operand. */
2343 mmix_symbolic_or_address_operand (rtx op, enum machine_mode mode)
2345 switch (GET_CODE (op))
2352 if ((GET_CODE (XEXP (op, 0)) == SYMBOL_REF
2353 || GET_CODE (XEXP (op, 0)) == LABEL_REF)
2354 && (GET_CODE (XEXP (op, 1)) == CONST_INT
2355 || (GET_CODE (XEXP (op, 1)) == CONST_DOUBLE
2356 && GET_MODE (XEXP (op, 1)) == VOIDmode)))
2360 return address_operand (op, mode);
2364 /* True if this is a register or CONST_INT (or CONST_DOUBLE for DImode).
2365 We could narrow the value down with a couple of predicated, but that
2366 doesn't seem to be worth it at the moment. */
2369 mmix_reg_or_constant_operand (rtx op, enum machine_mode mode)
2371 return register_operand (op, mode)
2372 || (GET_CODE (op) == CONST_DOUBLE && GET_MODE (op) == VOIDmode)
2373 || GET_CODE (op) == CONST_INT;
2376 /* True if this is a register with a condition-code mode. */
2379 mmix_reg_cc_operand (rtx op, enum machine_mode mode)
2381 if (mode == VOIDmode)
2382 mode = GET_MODE (op);
2384 return register_operand (op, mode)
2385 && (mode == CCmode || mode == CC_UNSmode || mode == CC_FPmode
2386 || mode == CC_FPEQmode || mode == CC_FUNmode);
2389 /* True if this is a foldable comparison operator
2390 - one where a the result of (compare:CC (reg) (const_int 0)) can be
2391 replaced by (reg). */
2394 mmix_foldable_comparison_operator (rtx op, enum machine_mode mode)
2396 RTX_CODE code = GET_CODE (op);
2398 if (mode == VOIDmode)
2399 mode = GET_MODE (op);
2401 if (mode == VOIDmode && COMPARISON_P (op))
2402 mode = GET_MODE (XEXP (op, 0));
2404 return ((mode == CCmode || mode == DImode)
2405 && (code == NE || code == EQ || code == GE || code == GT
2407 /* FIXME: This may be a stupid trick. What happens when GCC wants to
2408 reverse the condition? Can it do that by itself? Maybe it can
2409 even reverse the condition to fit a foldable one in the first
2411 || (mode == CC_UNSmode && (code == GTU || code == LEU));
2414 /* Like comparison_operator, but only true if this comparison operator is
2415 applied to a valid mode. Needed to avoid jump.c generating invalid
2416 code with -ffast-math (gcc.dg/20001228-1.c). */
2419 mmix_comparison_operator (rtx op, enum machine_mode mode)
2421 RTX_CODE code = GET_CODE (op);
2423 /* Comparison operators usually don't have a mode, but let's try and get
2424 one anyway for the day that changes. */
2425 if (mode == VOIDmode)
2426 mode = GET_MODE (op);
2428 /* Get the mode from the first operand if we don't have one. */
2429 if (mode == VOIDmode && COMPARISON_P (op))
2430 mode = GET_MODE (XEXP (op, 0));
2432 /* FIXME: This needs to be kept in sync with the tables in
2433 mmix_output_condition. */
2435 (mode == VOIDmode && COMPARISON_P (op))
2436 || (mode == CC_FUNmode
2437 && (code == ORDERED || code == UNORDERED))
2438 || (mode == CC_FPmode
2439 && (code == GT || code == LT))
2440 || (mode == CC_FPEQmode
2441 && (code == NE || code == EQ))
2442 || (mode == CC_UNSmode
2443 && (code == GEU || code == GTU || code == LEU || code == LTU))
2445 && (code == NE || code == EQ || code == GE || code == GT
2446 || code == LE || code == LT))
2448 && (code == NE || code == EQ || code == GE || code == GT
2449 || code == LE || code == LT || code == LEU || code == GTU));
2452 /* True if this is a register or 0 (int or float). */
2455 mmix_reg_or_0_operand (rtx op, enum machine_mode mode)
2457 /* FIXME: Is mode calculation necessary and correct? */
2459 op == CONST0_RTX (mode == VOIDmode ? GET_MODE (op) : mode)
2460 || register_operand (op, mode);
2463 /* True if this is a register or an int 0..255. */
2466 mmix_reg_or_8bit_operand (rtx op, enum machine_mode mode)
2468 return register_operand (op, mode)
2469 || (GET_CODE (op) == CONST_INT
2470 && CONST_OK_FOR_LETTER_P (INTVAL (op), 'I'));
2473 /* Returns zero if code and mode is not a valid condition from a
2474 compare-type insn. Nonzero if it is. The parameter op, if non-NULL,
2475 is the comparison of mode is CC-somethingmode. */
2478 mmix_valid_comparison (RTX_CODE code, enum machine_mode mode, rtx op)
2480 if (mode == VOIDmode && op != NULL_RTX)
2481 mode = GET_MODE (op);
2483 /* We don't care to look at these, they should always be valid. */
2484 if (mode == CCmode || mode == CC_UNSmode || mode == DImode)
2487 if ((mode == CC_FPmode || mode == DFmode)
2488 && (code == GT || code == LT))
2491 if ((mode == CC_FPEQmode || mode == DFmode)
2492 && (code == EQ || code == NE))
2495 if ((mode == CC_FUNmode || mode == DFmode)
2496 && (code == ORDERED || code == UNORDERED))
2502 /* X and Y are two things to compare using CODE. Emit a compare insn if
2503 possible and return the rtx for the cc-reg in the proper mode, or
2504 NULL_RTX if this is not a valid comparison. */
2507 mmix_gen_compare_reg (RTX_CODE code, rtx x, rtx y)
2509 enum machine_mode ccmode = SELECT_CC_MODE (code, x, y);
2512 /* FIXME: Do we get constants here? Of double mode? */
2513 enum machine_mode mode
2514 = GET_MODE (x) == VOIDmode
2516 : GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT ? DFmode : DImode;
2518 if (! mmix_valid_comparison (code, mode, x))
2521 cc_reg = gen_reg_rtx (ccmode);
2523 /* FIXME: Can we avoid emitting a compare insn here? */
2524 if (! REG_P (x) && ! REG_P (y))
2525 x = force_reg (mode, x);
2527 /* If it's not quite right yet, put y in a register. */
2529 && (GET_CODE (y) != CONST_INT
2530 || ! CONST_OK_FOR_LETTER_P (INTVAL (y), 'I')))
2531 y = force_reg (mode, y);
2533 emit_insn (gen_rtx_SET (VOIDmode, cc_reg,
2534 gen_rtx_COMPARE (ccmode, x, y)));
2539 /* Local (static) helper functions. */
2542 mmix_emit_sp_add (HOST_WIDE_INT offset)
2548 /* Negative stack-pointer adjustments are allocations and appear in
2549 the prologue only. We mark them as frame-related so unwind and
2550 debug info is properly emitted for them. */
2552 insn = emit_insn (gen_adddi3 (stack_pointer_rtx,
2557 rtx tmpr = gen_rtx_REG (DImode, 255);
2558 RTX_FRAME_RELATED_P (emit_move_insn (tmpr, GEN_INT (offset))) = 1;
2559 insn = emit_insn (gen_adddi3 (stack_pointer_rtx,
2560 stack_pointer_rtx, tmpr));
2562 RTX_FRAME_RELATED_P (insn) = 1;
2566 /* Positive adjustments are in the epilogue only. Don't mark them
2567 as "frame-related" for unwind info. */
2568 if (CONST_OK_FOR_LETTER_P (offset, 'L'))
2569 emit_insn (gen_adddi3 (stack_pointer_rtx,
2574 rtx tmpr = gen_rtx_REG (DImode, 255);
2575 emit_move_insn (tmpr, GEN_INT (offset));
2576 insn = emit_insn (gen_adddi3 (stack_pointer_rtx,
2577 stack_pointer_rtx, tmpr));
2582 /* Print operator suitable for doing something with a shiftable
2583 wyde. The type of operator is passed as an asm output modifier. */
2586 mmix_output_shiftvalue_op_from_str (FILE *stream,
2588 HOST_WIDEST_INT value)
2590 static const char *const op_part[] = {"L", "ML", "MH", "H"};
2593 if (! mmix_shiftable_wyde_value (value))
2595 char s[sizeof ("0xffffffffffffffff")];
2596 sprintf (s, HOST_WIDEST_INT_PRINT_HEX, value);
2597 internal_error ("MMIX Internal: %s is not a shiftable int", s);
2600 for (i = 0; i < 4; i++)
2602 /* We know we're through when we find one-bits in the low
2606 fprintf (stream, "%s%s", mainop, op_part[i]);
2612 /* No bits set? Then it must have been zero. */
2613 fprintf (stream, "%sL", mainop);
2616 /* Print a 64-bit value, optionally prefixed by assembly pseudo. */
2619 mmix_output_octa (FILE *stream, HOST_WIDEST_INT value, int do_begin_end)
2621 /* Snipped from final.c:output_addr_const. We need to avoid the
2622 presumed universal "0x" prefix. We can do it by replacing "0x" with
2623 "#0" here; we must avoid a space in the operands and no, the zero
2624 won't cause the number to be assumed in octal format. */
2625 char hex_format[sizeof (HOST_WIDEST_INT_PRINT_HEX)];
2628 fprintf (stream, "\tOCTA ");
2630 strcpy (hex_format, HOST_WIDEST_INT_PRINT_HEX);
2631 hex_format[0] = '#';
2632 hex_format[1] = '0';
2634 /* Provide a few alternative output formats depending on the number, to
2635 improve legibility of assembler output. */
2636 if ((value < (HOST_WIDEST_INT) 0 && value > (HOST_WIDEST_INT) -10000)
2637 || (value >= (HOST_WIDEST_INT) 0 && value <= (HOST_WIDEST_INT) 16384))
2638 fprintf (stream, "%d", (int) value);
2639 else if (value > (HOST_WIDEST_INT) 0
2640 && value < ((HOST_WIDEST_INT) 1 << 31) * 2)
2641 fprintf (stream, "#%x", (unsigned int) value);
2643 fprintf (stream, hex_format, value);
2646 fprintf (stream, "\n");
2649 /* Print the presumed shiftable wyde argument shifted into place (to
2650 be output with an operand). */
2653 mmix_output_shifted_value (FILE *stream, HOST_WIDEST_INT value)
2657 if (! mmix_shiftable_wyde_value (value))
2660 sprintf (s, HOST_WIDEST_INT_PRINT_HEX, value);
2661 internal_error ("MMIX Internal: %s is not a shiftable int", s);
2664 for (i = 0; i < 4; i++)
2666 /* We know we're through when we find one-bits in the low 16 bits. */
2669 fprintf (stream, "#%x", (int) (value & 0xffff));
2676 /* No bits set? Then it must have been zero. */
2677 fprintf (stream, "0");
2680 /* Output an MMIX condition name corresponding to an operator
2682 (comparison_operator [(comparison_operator ...) (const_int 0)])
2683 which means we have to look at *two* operators.
2685 The argument "reversed" refers to reversal of the condition (not the
2686 same as swapping the arguments). */
2689 mmix_output_condition (FILE *stream, rtx x, int reversed)
2695 /* The normal output cc-code. */
2696 const char *const normal;
2698 /* The reversed cc-code, or NULL if invalid. */
2699 const char *const reversed;
2704 enum machine_mode cc_mode;
2706 /* Terminated with {UNKNOWN, NULL, NULL} */
2707 const struct cc_conv *const convs;
2711 #define CCEND {UNKNOWN, NULL, NULL}
2713 static const struct cc_conv cc_fun_convs[]
2714 = {{ORDERED, "Z", "P"},
2715 {UNORDERED, "P", "Z"},
2717 static const struct cc_conv cc_fp_convs[]
2721 static const struct cc_conv cc_fpeq_convs[]
2725 static const struct cc_conv cc_uns_convs[]
2726 = {{GEU, "NN", "N"},
2731 static const struct cc_conv cc_signed_convs[]
2739 static const struct cc_conv cc_di_convs[]
2751 static const struct cc_type_conv cc_convs[]
2752 = {{CC_FUNmode, cc_fun_convs},
2753 {CC_FPmode, cc_fp_convs},
2754 {CC_FPEQmode, cc_fpeq_convs},
2755 {CC_UNSmode, cc_uns_convs},
2756 {CCmode, cc_signed_convs},
2757 {DImode, cc_di_convs}};
2762 enum machine_mode mode = GET_MODE (XEXP (x, 0));
2763 RTX_CODE cc = GET_CODE (x);
2765 for (i = 0; i < ARRAY_SIZE (cc_convs); i++)
2767 if (mode == cc_convs[i].cc_mode)
2769 for (j = 0; cc_convs[i].convs[j].cc != UNKNOWN; j++)
2770 if (cc == cc_convs[i].convs[j].cc)
2773 = (reversed ? cc_convs[i].convs[j].reversed
2774 : cc_convs[i].convs[j].normal);
2776 if (mmix_cc == NULL)
2777 fatal_insn ("MMIX Internal: Trying to output invalidly\
2778 reversed condition:", x);
2780 fprintf (stream, "%s", mmix_cc);
2784 fatal_insn ("MMIX Internal: What's the CC of this?", x);
2788 fatal_insn ("MMIX Internal: What is the CC of this?", x);
2791 /* Return the bit-value for a const_int or const_double. */
2793 static HOST_WIDEST_INT
2796 unsigned HOST_WIDEST_INT retval;
2798 if (GET_CODE (x) == CONST_INT)
2801 /* We make a little song and dance because converting to long long in
2802 gcc-2.7.2 is broken. I still want people to be able to use it for
2803 cross-compilation to MMIX. */
2804 if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == VOIDmode)
2806 if (sizeof (HOST_WIDE_INT) < sizeof (HOST_WIDEST_INT))
2808 retval = (unsigned) CONST_DOUBLE_LOW (x) / 2;
2810 retval |= CONST_DOUBLE_LOW (x) & 1;
2813 (unsigned HOST_WIDEST_INT) CONST_DOUBLE_HIGH (x)
2814 << (HOST_BITS_PER_LONG);
2817 retval = CONST_DOUBLE_HIGH (x);
2822 if (GET_CODE (x) == CONST_DOUBLE)
2824 REAL_VALUE_TYPE value;
2826 /* FIXME: This macro is not in the manual but should be. */
2827 REAL_VALUE_FROM_CONST_DOUBLE (value, x);
2829 if (GET_MODE (x) == DFmode)
2833 REAL_VALUE_TO_TARGET_DOUBLE (value, bits);
2835 if (sizeof (long) < sizeof (HOST_WIDEST_INT))
2837 retval = (unsigned long) bits[1] / 2;
2839 retval |= (unsigned long) bits[1] & 1;
2841 |= (unsigned HOST_WIDEST_INT) bits[0]
2842 << (sizeof (bits[0]) * 8);
2845 retval = (unsigned long) bits[1];
2849 else if (GET_MODE (x) == SFmode)
2852 REAL_VALUE_TO_TARGET_SINGLE (value, bits);
2854 return (unsigned long) bits;
2858 fatal_insn ("MMIX Internal: This is not a constant:", x);
2861 /* Worker function for TARGET_STRUCT_VALUE_RTX. */
2864 mmix_struct_value_rtx (tree fntype ATTRIBUTE_UNUSED,
2865 int incoming ATTRIBUTE_UNUSED)
2867 return gen_rtx_REG (Pmode, MMIX_STRUCT_VALUE_REGNUM);
2872 * eval: (c-set-style "gnu")
2873 * indent-tabs-mode: t