1 /* Definitions of target machine for GNU compiler, for MMIX.
2 Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005
3 Free Software Foundation, Inc.
4 Contributed by Hans-Peter Nilsson (hp@bitrange.com)
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
25 #include "coretypes.h"
29 #include "hard-reg-set.h"
31 #include "insn-config.h"
43 #include "integrate.h"
45 #include "target-def.h"
48 /* First some local helper definitions. */
49 #define MMIX_FIRST_GLOBAL_REGNUM 32
51 /* We'd need a current_function_has_landing_pad. It's marked as such when
52 a nonlocal_goto_receiver is expanded. Not just a C++ thing, but
54 #define MMIX_CFUN_HAS_LANDING_PAD (cfun->machine->has_landing_pad != 0)
56 /* We have no means to tell DWARF 2 about the register stack, so we need
57 to store the return address on the stack if an exception can get into
58 this function. FIXME: Narrow condition. Before any whole-function
59 analysis, regs_ever_live[] isn't initialized. We know it's up-to-date
60 after reload_completed; it may contain incorrect information some time
61 before that. Within a RTL sequence (after a call to start_sequence,
62 such as in RTL expanders), leaf_function_p doesn't see all insns
63 (perhaps any insn). But regs_ever_live is up-to-date when
64 leaf_function_p () isn't, so we "or" them together to get accurate
65 information. FIXME: Some tweak to leaf_function_p might be
67 #define MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS \
69 && ((reload_completed && regs_ever_live[MMIX_rJ_REGNUM]) \
70 || !leaf_function_p ()))
72 #define IS_MMIX_EH_RETURN_DATA_REG(REGNO) \
73 (current_function_calls_eh_return \
74 && (EH_RETURN_DATA_REGNO (0) == REGNO \
75 || EH_RETURN_DATA_REGNO (1) == REGNO \
76 || EH_RETURN_DATA_REGNO (2) == REGNO \
77 || EH_RETURN_DATA_REGNO (3) == REGNO))
79 /* For the default ABI, we rename registers at output-time to fill the gap
80 between the (statically partitioned) saved registers and call-clobbered
81 registers. In effect this makes unused call-saved registers to be used
82 as call-clobbered registers. The benefit comes from keeping the number
83 of local registers (value of rL) low, since there's a cost of
84 increasing rL and clearing unused (unset) registers with lower numbers.
85 Don't translate while outputting the prologue. */
86 #define MMIX_OUTPUT_REGNO(N) \
88 || (int) (N) < MMIX_RETURN_VALUE_REGNUM \
89 || (int) (N) > MMIX_LAST_STACK_REGISTER_REGNUM \
91 || cfun->machine == NULL \
92 || cfun->machine->in_prologue \
93 ? (N) : ((N) - MMIX_RETURN_VALUE_REGNUM \
94 + cfun->machine->highest_saved_stack_register + 1))
96 /* The %d in "POP %d,0". */
97 #define MMIX_POP_ARGUMENT() \
99 && current_function_return_rtx != NULL \
100 && ! current_function_returns_struct) \
101 ? (GET_CODE (current_function_return_rtx) == PARALLEL \
102 ? GET_NUM_ELEM (XVEC (current_function_return_rtx, 0)) : 1) \
105 /* The canonical saved comparison operands for non-cc0 machines, set in
106 the compare expander. */
107 rtx mmix_compare_op0;
108 rtx mmix_compare_op1;
110 /* We ignore some options with arguments. They are passed to the linker,
111 but also ends up here because they start with "-m". We tell the driver
112 to store them in a variable we don't inspect. */
113 const char *mmix_cc1_ignored_option;
115 /* Declarations of locals. */
117 /* Intermediate for insn output. */
118 static int mmix_output_destination_register;
120 static void mmix_output_shiftvalue_op_from_str
121 (FILE *, const char *, HOST_WIDEST_INT);
122 static void mmix_output_shifted_value (FILE *, HOST_WIDEST_INT);
123 static void mmix_output_condition (FILE *, rtx, int);
124 static HOST_WIDEST_INT mmix_intval (rtx);
125 static void mmix_output_octa (FILE *, HOST_WIDEST_INT, int);
126 static bool mmix_assemble_integer (rtx, unsigned int, int);
127 static struct machine_function *mmix_init_machine_status (void);
128 static void mmix_encode_section_info (tree, rtx, int);
129 static const char *mmix_strip_name_encoding (const char *);
130 static void mmix_emit_sp_add (HOST_WIDE_INT offset);
131 static void mmix_target_asm_function_prologue (FILE *, HOST_WIDE_INT);
132 static void mmix_target_asm_function_end_prologue (FILE *);
133 static void mmix_target_asm_function_epilogue (FILE *, HOST_WIDE_INT);
134 static void mmix_reorg (void);
135 static void mmix_asm_output_mi_thunk
136 (FILE *, tree, HOST_WIDE_INT, HOST_WIDE_INT, tree);
137 static void mmix_setup_incoming_varargs
138 (CUMULATIVE_ARGS *, enum machine_mode, tree, int *, int);
139 static void mmix_file_start (void);
140 static void mmix_file_end (void);
141 static bool mmix_rtx_costs (rtx, int, int, int *);
142 static rtx mmix_struct_value_rtx (tree, int);
143 static bool mmix_pass_by_reference (const CUMULATIVE_ARGS *,
144 enum machine_mode, tree, bool);
146 /* Target structure macros. Listed by node. See `Using and Porting GCC'
147 for a general description. */
149 /* Node: Function Entry */
151 #undef TARGET_ASM_BYTE_OP
152 #define TARGET_ASM_BYTE_OP NULL
153 #undef TARGET_ASM_ALIGNED_HI_OP
154 #define TARGET_ASM_ALIGNED_HI_OP NULL
155 #undef TARGET_ASM_ALIGNED_SI_OP
156 #define TARGET_ASM_ALIGNED_SI_OP NULL
157 #undef TARGET_ASM_ALIGNED_DI_OP
158 #define TARGET_ASM_ALIGNED_DI_OP NULL
159 #undef TARGET_ASM_INTEGER
160 #define TARGET_ASM_INTEGER mmix_assemble_integer
162 #undef TARGET_ASM_FUNCTION_PROLOGUE
163 #define TARGET_ASM_FUNCTION_PROLOGUE mmix_target_asm_function_prologue
165 #undef TARGET_ASM_FUNCTION_END_PROLOGUE
166 #define TARGET_ASM_FUNCTION_END_PROLOGUE mmix_target_asm_function_end_prologue
168 #undef TARGET_ASM_FUNCTION_EPILOGUE
169 #define TARGET_ASM_FUNCTION_EPILOGUE mmix_target_asm_function_epilogue
171 #undef TARGET_ENCODE_SECTION_INFO
172 #define TARGET_ENCODE_SECTION_INFO mmix_encode_section_info
173 #undef TARGET_STRIP_NAME_ENCODING
174 #define TARGET_STRIP_NAME_ENCODING mmix_strip_name_encoding
176 #undef TARGET_ASM_OUTPUT_MI_THUNK
177 #define TARGET_ASM_OUTPUT_MI_THUNK mmix_asm_output_mi_thunk
178 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
179 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall
180 #undef TARGET_ASM_FILE_START
181 #define TARGET_ASM_FILE_START mmix_file_start
182 #undef TARGET_ASM_FILE_START_FILE_DIRECTIVE
183 #define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
184 #undef TARGET_ASM_FILE_END
185 #define TARGET_ASM_FILE_END mmix_file_end
187 #undef TARGET_RTX_COSTS
188 #define TARGET_RTX_COSTS mmix_rtx_costs
189 #undef TARGET_ADDRESS_COST
190 #define TARGET_ADDRESS_COST hook_int_rtx_0
192 #undef TARGET_MACHINE_DEPENDENT_REORG
193 #define TARGET_MACHINE_DEPENDENT_REORG mmix_reorg
195 #undef TARGET_PROMOTE_FUNCTION_ARGS
196 #define TARGET_PROMOTE_FUNCTION_ARGS hook_bool_tree_true
198 /* Apparently not doing TRT if int < register-size. FIXME: Perhaps
199 FUNCTION_VALUE and LIBCALL_VALUE needs tweaking as some ports say. */
200 #undef TARGET_PROMOTE_FUNCTION_RETURN
201 #define TARGET_PROMOTE_FUNCTION_RETURN hook_bool_tree_true
204 #undef TARGET_STRUCT_VALUE_RTX
205 #define TARGET_STRUCT_VALUE_RTX mmix_struct_value_rtx
206 #undef TARGET_SETUP_INCOMING_VARARGS
207 #define TARGET_SETUP_INCOMING_VARARGS mmix_setup_incoming_varargs
208 #undef TARGET_PASS_BY_REFERENCE
209 #define TARGET_PASS_BY_REFERENCE mmix_pass_by_reference
210 #undef TARGET_CALLEE_COPIES
211 #define TARGET_CALLEE_COPIES hook_bool_CUMULATIVE_ARGS_mode_tree_bool_true
213 struct gcc_target targetm = TARGET_INITIALIZER;
215 /* Functions that are expansions for target macros.
216 See Target Macros in `Using and Porting GCC'. */
218 /* OVERRIDE_OPTIONS. */
221 mmix_override_options (void)
223 /* Should we err or should we warn? Hmm. At least we must neutralize
224 it. For example the wrong kind of case-tables will be generated with
225 PIC; we use absolute address items for mmixal compatibility. FIXME:
226 They could be relative if we just elide them to after all pertinent
230 warning (0, "-f%s not supported: ignored", (flag_pic > 1) ? "PIC" : "pic");
235 /* INIT_EXPANDERS. */
238 mmix_init_expanders (void)
240 init_machine_status = mmix_init_machine_status;
243 /* Set the per-function data. */
245 static struct machine_function *
246 mmix_init_machine_status (void)
248 return ggc_alloc_cleared (sizeof (struct machine_function));
252 We have trouble getting the address of stuff that is located at other
253 than 32-bit alignments (GETA requirements), so try to give everything
254 at least 32-bit alignment. */
257 mmix_data_alignment (tree type ATTRIBUTE_UNUSED, int basic_align)
259 if (basic_align < 32)
265 /* CONSTANT_ALIGNMENT. */
268 mmix_constant_alignment (tree constant ATTRIBUTE_UNUSED, int basic_align)
270 if (basic_align < 32)
276 /* LOCAL_ALIGNMENT. */
279 mmix_local_alignment (tree type ATTRIBUTE_UNUSED, int basic_align)
281 if (basic_align < 32)
287 /* CONDITIONAL_REGISTER_USAGE. */
290 mmix_conditional_register_usage (void)
296 static const int gnu_abi_reg_alloc_order[]
297 = MMIX_GNU_ABI_REG_ALLOC_ORDER;
299 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
300 reg_alloc_order[i] = gnu_abi_reg_alloc_order[i];
302 /* Change the default from the mmixware ABI. For the GNU ABI,
303 $15..$30 are call-saved just as $0..$14. There must be one
304 call-clobbered local register for the "hole" that holds the
305 number of saved local registers saved by PUSHJ/PUSHGO during the
306 function call, receiving the return value at return. So best is
307 to use the highest, $31. It's already marked call-clobbered for
309 for (i = 15; i <= 30; i++)
310 call_used_regs[i] = 0;
312 /* "Unfix" the parameter registers. */
313 for (i = MMIX_RESERVED_GNU_ARG_0_REGNUM;
314 i < MMIX_RESERVED_GNU_ARG_0_REGNUM + MMIX_MAX_ARGS_IN_REGS;
319 /* Step over the ":" in special register names. */
320 if (! TARGET_TOPLEVEL_SYMBOLS)
321 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
322 if (reg_names[i][0] == ':')
327 All registers that are part of the register stack and that will be
331 mmix_local_regno (int regno)
333 return regno <= MMIX_LAST_STACK_REGISTER_REGNUM && !call_used_regs[regno];
336 /* PREFERRED_RELOAD_CLASS.
337 We need to extend the reload class of REMAINDER_REG and HIMULT_REG. */
340 mmix_preferred_reload_class (rtx x ATTRIBUTE_UNUSED, enum reg_class class)
342 /* FIXME: Revisit. */
343 return GET_CODE (x) == MOD && GET_MODE (x) == DImode
344 ? REMAINDER_REG : class;
347 /* PREFERRED_OUTPUT_RELOAD_CLASS.
348 We need to extend the reload class of REMAINDER_REG and HIMULT_REG. */
351 mmix_preferred_output_reload_class (rtx x ATTRIBUTE_UNUSED,
352 enum reg_class class)
354 /* FIXME: Revisit. */
355 return GET_CODE (x) == MOD && GET_MODE (x) == DImode
356 ? REMAINDER_REG : class;
359 /* SECONDARY_RELOAD_CLASS.
360 We need to reload regs of REMAINDER_REG and HIMULT_REG elsewhere. */
363 mmix_secondary_reload_class (enum reg_class class,
364 enum machine_mode mode ATTRIBUTE_UNUSED,
365 rtx x ATTRIBUTE_UNUSED,
366 int in_p ATTRIBUTE_UNUSED)
368 if (class == REMAINDER_REG
369 || class == HIMULT_REG
370 || class == SYSTEM_REGS)
376 /* CONST_OK_FOR_LETTER_P. */
379 mmix_const_ok_for_letter_p (HOST_WIDE_INT value, int c)
382 (c == 'I' ? value >= 0 && value <= 255
383 : c == 'J' ? value >= 0 && value <= 65535
384 : c == 'K' ? value <= 0 && value >= -255
385 : c == 'L' ? mmix_shiftable_wyde_value (value)
386 : c == 'M' ? value == 0
387 : c == 'N' ? mmix_shiftable_wyde_value (~value)
388 : c == 'O' ? (value == 3 || value == 5 || value == 9
393 /* CONST_DOUBLE_OK_FOR_LETTER_P. */
396 mmix_const_double_ok_for_letter_p (rtx value, int c)
399 (c == 'G' ? value == CONST0_RTX (GET_MODE (value))
404 We need this since our constants are not always expressible as
405 CONST_INT:s, but rather often as CONST_DOUBLE:s. */
408 mmix_extra_constraint (rtx x, int c, int strict)
410 HOST_WIDEST_INT value;
412 /* When checking for an address, we need to handle strict vs. non-strict
413 register checks. Don't use address_operand, but instead its
414 equivalent (its callee, which it is just a wrapper for),
415 memory_operand_p and the strict-equivalent strict_memory_address_p. */
419 ? strict_memory_address_p (Pmode, x)
420 : memory_address_p (Pmode, x);
422 /* R asks whether x is to be loaded with GETA or something else. Right
423 now, only a SYMBOL_REF and LABEL_REF can fit for
424 TARGET_BASE_ADDRESSES.
426 Only constant symbolic addresses apply. With TARGET_BASE_ADDRESSES,
427 we just allow straight LABEL_REF or SYMBOL_REFs with SYMBOL_REF_FLAG
428 set right now; only function addresses and code labels. If we change
429 to let SYMBOL_REF_FLAG be set on other symbols, we have to check
430 inside CONST expressions. When TARGET_BASE_ADDRESSES is not in
431 effect, a "raw" constant check together with mmix_constant_address_p
432 is all that's needed; we want all constant addresses to be loaded
436 GET_CODE (x) != CONST_INT && GET_CODE (x) != CONST_DOUBLE
437 && mmix_constant_address_p (x)
438 && (! TARGET_BASE_ADDRESSES
439 || (GET_CODE (x) == LABEL_REF
440 || (GET_CODE (x) == SYMBOL_REF && SYMBOL_REF_FLAG (x))));
442 if (GET_CODE (x) != CONST_DOUBLE || GET_MODE (x) != VOIDmode)
445 value = mmix_intval (x);
447 /* We used to map Q->J, R->K, S->L, T->N, U->O, but we don't have to any
448 more ('U' taken for address_operand, 'R' similarly). Some letters map
449 outside of CONST_INT, though; we still use 'S' and 'T'. */
451 return mmix_shiftable_wyde_value (value);
453 return mmix_shiftable_wyde_value (~value);
457 /* DYNAMIC_CHAIN_ADDRESS. */
460 mmix_dynamic_chain_address (rtx frame)
462 /* FIXME: the frame-pointer is stored at offset -8 from the current
463 frame-pointer. Unfortunately, the caller assumes that a
464 frame-pointer is present for *all* previous frames. There should be
465 a way to say that that cannot be done, like for RETURN_ADDR_RTX. */
466 return plus_constant (frame, -8);
469 /* STARTING_FRAME_OFFSET. */
472 mmix_starting_frame_offset (void)
474 /* The old frame pointer is in the slot below the new one, so
475 FIRST_PARM_OFFSET does not need to depend on whether the
476 frame-pointer is needed or not. We have to adjust for the register
477 stack pointer being located below the saved frame pointer.
478 Similarly, we store the return address on the stack too, for
479 exception handling, and always if we save the register stack pointer. */
482 + (MMIX_CFUN_HAS_LANDING_PAD
483 ? -16 : (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS ? -8 : 0)));
486 /* RETURN_ADDR_RTX. */
489 mmix_return_addr_rtx (int count, rtx frame ATTRIBUTE_UNUSED)
492 ? (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
493 /* FIXME: Set frame_alias_set on the following. (Why?)
494 See mmix_initial_elimination_offset for the reason we can't use
495 get_hard_reg_initial_val for both. Always using a stack slot
496 and not a register would be suboptimal. */
497 ? validize_mem (gen_rtx_MEM (Pmode, plus_constant (frame_pointer_rtx, -16)))
498 : get_hard_reg_initial_val (Pmode, MMIX_INCOMING_RETURN_ADDRESS_REGNUM))
502 /* SETUP_FRAME_ADDRESSES. */
505 mmix_setup_frame_addresses (void)
507 /* Nothing needed at the moment. */
510 /* The difference between the (imaginary) frame pointer and the stack
511 pointer. Used to eliminate the frame pointer. */
514 mmix_initial_elimination_offset (int fromreg, int toreg)
518 = (get_frame_size () + current_function_outgoing_args_size + 7) & ~7;
520 /* There is no actual offset between these two virtual values, but for
521 the frame-pointer, we have the old one in the stack position below
522 it, so the offset for the frame-pointer to the stack-pointer is one
524 if (fromreg == MMIX_ARG_POINTER_REGNUM
525 && toreg == MMIX_FRAME_POINTER_REGNUM)
528 /* The difference is the size of local variables plus the size of
529 outgoing function arguments that would normally be passed as
530 registers but must be passed on stack because we're out of
531 function-argument registers. Only global saved registers are
532 counted; the others go on the register stack.
534 The frame-pointer is counted too if it is what is eliminated, as we
535 need to balance the offset for it from STARTING_FRAME_OFFSET.
537 Also add in the slot for the register stack pointer we save if we
540 Unfortunately, we can't access $0..$14, from unwinder code easily, so
541 store the return address in a frame slot too. FIXME: Only for
542 non-leaf functions. FIXME: Always with a landing pad, because it's
543 hard to know whether we need the other at the time we know we need
544 the offset for one (and have to state it). It's a kludge until we
545 can express the register stack in the EH frame info.
547 We have to do alignment here; get_frame_size will not return a
548 multiple of STACK_BOUNDARY. FIXME: Add note in manual. */
550 for (regno = MMIX_FIRST_GLOBAL_REGNUM;
553 if ((regs_ever_live[regno] && ! call_used_regs[regno])
554 || IS_MMIX_EH_RETURN_DATA_REG (regno))
558 + (MMIX_CFUN_HAS_LANDING_PAD
559 ? 16 : (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS ? 8 : 0))
560 + (fromreg == MMIX_ARG_POINTER_REGNUM ? 0 : 8);
563 /* Return an rtx for a function argument to go in a register, and 0 for
564 one that must go on stack. */
567 mmix_function_arg (const CUMULATIVE_ARGS *argsp,
568 enum machine_mode mode,
570 int named ATTRIBUTE_UNUSED,
573 /* Last-argument marker. */
574 if (type == void_type_node)
575 return (argsp->regs < MMIX_MAX_ARGS_IN_REGS)
578 ? MMIX_FIRST_INCOMING_ARG_REGNUM
579 : MMIX_FIRST_ARG_REGNUM) + argsp->regs)
582 return (argsp->regs < MMIX_MAX_ARGS_IN_REGS
583 && !targetm.calls.must_pass_in_stack (mode, type)
584 && (GET_MODE_BITSIZE (mode) <= 64
589 ? MMIX_FIRST_INCOMING_ARG_REGNUM
590 : MMIX_FIRST_ARG_REGNUM)
595 /* Returns nonzero for everything that goes by reference, 0 for
596 everything that goes by value. */
599 mmix_pass_by_reference (const CUMULATIVE_ARGS *argsp, enum machine_mode mode,
600 tree type, bool named ATTRIBUTE_UNUSED)
602 /* FIXME: Check: I'm not sure the must_pass_in_stack check is
604 if (targetm.calls.must_pass_in_stack (mode, type))
607 if (MMIX_FUNCTION_ARG_SIZE (mode, type) > 8
609 && (!argsp || !argsp->lib))
615 /* Return nonzero if regno is a register number where a parameter is
616 passed, and 0 otherwise. */
619 mmix_function_arg_regno_p (int regno, int incoming)
622 = incoming ? MMIX_FIRST_INCOMING_ARG_REGNUM : MMIX_FIRST_ARG_REGNUM;
624 return regno >= first_arg_regnum
625 && regno < first_arg_regnum + MMIX_MAX_ARGS_IN_REGS;
628 /* FUNCTION_OUTGOING_VALUE. */
631 mmix_function_outgoing_value (tree valtype, tree func ATTRIBUTE_UNUSED)
633 enum machine_mode mode = TYPE_MODE (valtype);
634 enum machine_mode cmode;
635 int first_val_regnum = MMIX_OUTGOING_RETURN_VALUE_REGNUM;
636 rtx vec[MMIX_MAX_REGS_FOR_VALUE];
640 /* Return values that fit in a register need no special handling.
641 There's no register hole when parameters are passed in global
644 || GET_MODE_BITSIZE (mode) <= BITS_PER_WORD)
646 gen_rtx_REG (mode, MMIX_OUTGOING_RETURN_VALUE_REGNUM);
648 if (COMPLEX_MODE_P (mode))
649 /* A complex type, made up of components. */
650 cmode = TYPE_MODE (TREE_TYPE (valtype));
653 /* Of the other larger-than-register modes, we only support
654 scalar mode TImode. (At least, that's the only one that's
655 been rudimentally tested.) Make sure we're alerted for
658 sorry ("support for mode %qs", GET_MODE_NAME (mode));
660 /* In any case, we will fill registers to the natural size. */
664 nregs = ((GET_MODE_BITSIZE (mode) + BITS_PER_WORD - 1) / BITS_PER_WORD);
666 /* We need to take care of the effect of the register hole on return
667 values of large sizes; the last register will appear as the first
668 register, with the rest shifted. (For complex modes, this is just
669 swapped registers.) */
671 if (nregs > MMIX_MAX_REGS_FOR_VALUE)
672 internal_error ("too large function value type, needs %d registers,\
673 have only %d registers for this", nregs, MMIX_MAX_REGS_FOR_VALUE);
675 /* FIXME: Maybe we should handle structure values like this too
676 (adjusted for BLKmode), perhaps for both ABI:s. */
677 for (i = 0; i < nregs - 1; i++)
679 = gen_rtx_EXPR_LIST (VOIDmode,
680 gen_rtx_REG (cmode, first_val_regnum + i),
681 GEN_INT ((i + 1) * BITS_PER_UNIT));
684 = gen_rtx_EXPR_LIST (VOIDmode,
685 gen_rtx_REG (cmode, first_val_regnum + nregs - 1),
688 return gen_rtx_PARALLEL (VOIDmode, gen_rtvec_v (nregs, vec));
691 /* FUNCTION_VALUE_REGNO_P. */
694 mmix_function_value_regno_p (int regno)
696 return regno == MMIX_RETURN_VALUE_REGNUM;
699 /* EH_RETURN_DATA_REGNO. */
702 mmix_eh_return_data_regno (int n)
705 return MMIX_EH_RETURN_DATA_REGNO_START + n;
707 return INVALID_REGNUM;
710 /* EH_RETURN_STACKADJ_RTX. */
713 mmix_eh_return_stackadj_rtx (void)
715 return gen_rtx_REG (Pmode, MMIX_EH_RETURN_STACKADJ_REGNUM);
718 /* EH_RETURN_HANDLER_RTX. */
721 mmix_eh_return_handler_rtx (void)
723 return gen_rtx_REG (Pmode, MMIX_INCOMING_RETURN_ADDRESS_REGNUM);
726 /* ASM_PREFERRED_EH_DATA_FORMAT. */
729 mmix_asm_preferred_eh_data_format (int code ATTRIBUTE_UNUSED,
730 int global ATTRIBUTE_UNUSED)
732 /* This is the default (was at 2001-07-20). Revisit when needed. */
733 return DW_EH_PE_absptr;
736 /* Make a note that we've seen the beginning of the prologue. This
737 matters to whether we'll translate register numbers as calculated by
741 mmix_target_asm_function_prologue (FILE *stream ATTRIBUTE_UNUSED,
742 HOST_WIDE_INT framesize ATTRIBUTE_UNUSED)
744 cfun->machine->in_prologue = 1;
747 /* Make a note that we've seen the end of the prologue. */
750 mmix_target_asm_function_end_prologue (FILE *stream ATTRIBUTE_UNUSED)
752 cfun->machine->in_prologue = 0;
755 /* Implement TARGET_MACHINE_DEPENDENT_REORG. No actual rearrangements
756 done here; just virtually by calculating the highest saved stack
757 register number used to modify the register numbers at output time. */
764 /* We put the number of the highest saved register-file register in a
765 location convenient for the call-patterns to output. Note that we
766 don't tell dwarf2 about these registers, since it can't restore them
768 for (regno = MMIX_LAST_STACK_REGISTER_REGNUM;
771 if ((regs_ever_live[regno] && !call_used_regs[regno])
772 || (regno == MMIX_FRAME_POINTER_REGNUM && frame_pointer_needed))
775 /* Regardless of whether they're saved (they might be just read), we
776 mustn't include registers that carry parameters. We could scan the
777 insns to see whether they're actually used (and indeed do other less
778 trivial register usage analysis and transformations), but it seems
779 wasteful to optimize for unused parameter registers. As of
780 2002-04-30, regs_ever_live[n] seems to be set for only-reads too, but
781 that might change. */
782 if (!TARGET_ABI_GNU && regno < current_function_args_info.regs - 1)
784 regno = current_function_args_info.regs - 1;
786 /* We don't want to let this cause us to go over the limit and make
787 incoming parameter registers be misnumbered and treating the last
788 parameter register and incoming return value register call-saved.
789 Stop things at the unmodified scheme. */
790 if (regno > MMIX_RETURN_VALUE_REGNUM - 1)
791 regno = MMIX_RETURN_VALUE_REGNUM - 1;
794 cfun->machine->highest_saved_stack_register = regno;
797 /* TARGET_ASM_FUNCTION_EPILOGUE. */
800 mmix_target_asm_function_epilogue (FILE *stream,
801 HOST_WIDE_INT locals_size ATTRIBUTE_UNUSED)
803 /* Emit an \n for readability of the generated assembly. */
804 fputc ('\n', stream);
807 /* TARGET_ASM_OUTPUT_MI_THUNK. */
810 mmix_asm_output_mi_thunk (FILE *stream,
811 tree fndecl ATTRIBUTE_UNUSED,
813 HOST_WIDE_INT vcall_offset ATTRIBUTE_UNUSED,
816 /* If you define TARGET_STRUCT_VALUE_RTX that returns 0 (i.e. pass
817 location of structure to return as invisible first argument), you
818 need to tweak this code too. */
819 const char *regname = reg_names[MMIX_FIRST_INCOMING_ARG_REGNUM];
821 if (delta >= 0 && delta < 65536)
822 fprintf (stream, "\tINCL %s,%d\n", regname, (int)delta);
823 else if (delta < 0 && delta >= -255)
824 fprintf (stream, "\tSUBU %s,%s,%d\n", regname, regname, (int)-delta);
827 mmix_output_register_setting (stream, 255, delta, 1);
828 fprintf (stream, "\tADDU %s,%s,$255\n", regname, regname);
831 fprintf (stream, "\tJMP ");
832 assemble_name (stream, XSTR (XEXP (DECL_RTL (func), 0), 0));
833 fprintf (stream, "\n");
836 /* FUNCTION_PROFILER. */
839 mmix_function_profiler (FILE *stream ATTRIBUTE_UNUSED,
840 int labelno ATTRIBUTE_UNUSED)
842 sorry ("function_profiler support for MMIX");
845 /* Worker function for TARGET_SETUP_INCOMING_VARARGS. For the moment,
846 let's stick to pushing argument registers on the stack. Later, we
847 can parse all arguments in registers, to improve performance. */
850 mmix_setup_incoming_varargs (CUMULATIVE_ARGS *args_so_farp,
851 enum machine_mode mode,
854 int second_time ATTRIBUTE_UNUSED)
856 /* The last named variable has been handled, but
857 args_so_farp has not been advanced for it. */
858 if (args_so_farp->regs + 1 < MMIX_MAX_ARGS_IN_REGS)
859 *pretend_sizep = (MMIX_MAX_ARGS_IN_REGS - (args_so_farp->regs + 1)) * 8;
861 /* We assume that one argument takes up one register here. That should
862 be true until we start messing with multi-reg parameters. */
863 if ((7 + (MMIX_FUNCTION_ARG_SIZE (mode, vartype))) / 8 != 1)
864 internal_error ("MMIX Internal: Last named vararg would not fit in a register");
867 /* TRAMPOLINE_SIZE. */
868 /* Four 4-byte insns plus two 8-byte values. */
869 int mmix_trampoline_size = 32;
872 /* TRAMPOLINE_TEMPLATE. */
875 mmix_trampoline_template (FILE *stream)
877 /* Read a value into the static-chain register and jump somewhere. The
878 static chain is stored at offset 16, and the function address is
879 stored at offset 24. */
880 /* FIXME: GCC copies this using *intsize* (tetra), when it should use
881 register size (octa). */
882 fprintf (stream, "\tGETA $255,1F\n\t");
883 fprintf (stream, "LDOU %s,$255,0\n\t",
884 reg_names[MMIX_STATIC_CHAIN_REGNUM]);
885 fprintf (stream, "LDOU $255,$255,8\n\t");
886 fprintf (stream, "GO $255,$255,0\n");
887 fprintf (stream, "1H\tOCTA 0\n\t");
888 fprintf (stream, "OCTA 0\n");
891 /* INITIALIZE_TRAMPOLINE. */
892 /* Set the static chain and function pointer field in the trampoline.
893 We also SYNCID here to be sure (doesn't matter in the simulator, but
894 some day it will). */
897 mmix_initialize_trampoline (rtx trampaddr, rtx fnaddr, rtx static_chain)
899 emit_move_insn (gen_rtx_MEM (DImode, plus_constant (trampaddr, 16)),
901 emit_move_insn (gen_rtx_MEM (DImode,
902 plus_constant (trampaddr, 24)),
904 emit_insn (gen_sync_icache (validize_mem (gen_rtx_MEM (DImode,
906 GEN_INT (mmix_trampoline_size - 1)));
909 /* We must exclude constant addresses that have an increment that is not a
910 multiple of four bytes because of restrictions of the GETA
911 instruction, unless TARGET_BASE_ADDRESSES. */
914 mmix_constant_address_p (rtx x)
916 RTX_CODE code = GET_CODE (x);
918 /* When using "base addresses", anything constant goes. */
919 int constant_ok = TARGET_BASE_ADDRESSES != 0;
928 /* FIXME: Don't know how to dissect these. Avoid them for now,
929 except we know they're constants. */
937 if (GET_MODE (x) != VOIDmode)
938 /* Strange that we got here. FIXME: Check if we do. */
940 addend = CONST_DOUBLE_LOW (x);
944 /* Note that expressions with arithmetic on forward references don't
945 work in mmixal. People using gcc assembly code with mmixal might
946 need to move arrays and such to before the point of use. */
947 if (GET_CODE (XEXP (x, 0)) == PLUS)
949 rtx x0 = XEXP (XEXP (x, 0), 0);
950 rtx x1 = XEXP (XEXP (x, 0), 1);
952 if ((GET_CODE (x0) == SYMBOL_REF
953 || GET_CODE (x0) == LABEL_REF)
954 && (GET_CODE (x1) == CONST_INT
955 || (GET_CODE (x1) == CONST_DOUBLE
956 && GET_MODE (x1) == VOIDmode)))
957 addend = mmix_intval (x1);
969 return constant_ok || (addend & 3) == 0;
972 /* Return 1 if the address is OK, otherwise 0.
973 Used by GO_IF_LEGITIMATE_ADDRESS. */
976 mmix_legitimate_address (enum machine_mode mode ATTRIBUTE_UNUSED,
980 #define MMIX_REG_OK(X) \
982 && (REGNO (X) <= MMIX_LAST_GENERAL_REGISTER \
983 || (reg_renumber[REGNO (X)] > 0 \
984 && reg_renumber[REGNO (X)] <= MMIX_LAST_GENERAL_REGISTER))) \
985 || (!strict_checking \
986 && (REGNO (X) <= MMIX_LAST_GENERAL_REGISTER \
987 || REGNO (X) >= FIRST_PSEUDO_REGISTER \
988 || REGNO (X) == ARG_POINTER_REGNUM)))
993 (mem (plus reg 0..255)).
994 unless TARGET_BASE_ADDRESSES, in which case we accept all
995 (mem constant_address) too. */
999 if (REG_P (x) && MMIX_REG_OK (x))
1002 if (GET_CODE(x) == PLUS)
1004 rtx x1 = XEXP (x, 0);
1005 rtx x2 = XEXP (x, 1);
1007 /* Try swapping the order. FIXME: Do we need this? */
1015 /* (mem (plus (reg?) (?))) */
1016 if (!REG_P (x1) || !MMIX_REG_OK (x1))
1017 return TARGET_BASE_ADDRESSES && mmix_constant_address_p (x);
1019 /* (mem (plus (reg) (reg?))) */
1020 if (REG_P (x2) && MMIX_REG_OK (x2))
1023 /* (mem (plus (reg) (0..255?))) */
1024 if (GET_CODE (x2) == CONST_INT
1025 && CONST_OK_FOR_LETTER_P (INTVAL (x2), 'I'))
1031 return TARGET_BASE_ADDRESSES && mmix_constant_address_p (x);
1034 /* LEGITIMATE_CONSTANT_P. */
1037 mmix_legitimate_constant_p (rtx x)
1039 RTX_CODE code = GET_CODE (x);
1041 /* We must allow any number due to the way the cse passes works; if we
1042 do not allow any number here, general_operand will fail, and insns
1043 will fatally fail recognition instead of "softly". */
1044 if (code == CONST_INT || code == CONST_DOUBLE)
1047 return CONSTANT_ADDRESS_P (x);
1050 /* SELECT_CC_MODE. */
1053 mmix_select_cc_mode (RTX_CODE op, rtx x, rtx y ATTRIBUTE_UNUSED)
1055 /* We use CCmode, CC_UNSmode, CC_FPmode, CC_FPEQmode and CC_FUNmode to
1056 output different compare insns. Note that we do not check the
1057 validity of the comparison here. */
1059 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1061 if (op == ORDERED || op == UNORDERED || op == UNGE
1062 || op == UNGT || op == UNLE || op == UNLT)
1065 if (op == EQ || op == NE)
1071 if (op == GTU || op == LTU || op == GEU || op == LEU)
1077 /* REVERSIBLE_CC_MODE. */
1080 mmix_reversible_cc_mode (enum machine_mode mode)
1082 /* That is, all integer and the EQ, NE, ORDERED and UNORDERED float
1084 return mode != CC_FPmode;
1087 /* TARGET_RTX_COSTS. */
1090 mmix_rtx_costs (rtx x ATTRIBUTE_UNUSED,
1091 int code ATTRIBUTE_UNUSED,
1092 int outer_code ATTRIBUTE_UNUSED,
1093 int *total ATTRIBUTE_UNUSED)
1095 /* For the time being, this is just a stub and we'll accept the
1096 generic calculations, until we can do measurements, at least.
1097 Say we did not modify any calculated costs. */
1101 /* REGISTER_MOVE_COST. */
1104 mmix_register_move_cost (enum machine_mode mode ATTRIBUTE_UNUSED,
1105 enum reg_class from,
1108 return (from == GENERAL_REGS && from == to) ? 2 : 3;
1111 /* Note that we don't have a TEXT_SECTION_ASM_OP, because it has to be a
1112 compile-time constant; it's used in an asm in crtstuff.c, compiled for
1115 /* DATA_SECTION_ASM_OP. */
1118 mmix_data_section_asm_op (void)
1120 return "\t.data ! mmixal:= 8H LOC 9B";
1124 mmix_encode_section_info (tree decl, rtx rtl, int first)
1126 /* Test for an external declaration, and do nothing if it is one. */
1127 if ((TREE_CODE (decl) == VAR_DECL
1128 && (DECL_EXTERNAL (decl) || TREE_PUBLIC (decl)))
1129 || (TREE_CODE (decl) == FUNCTION_DECL && TREE_PUBLIC (decl)))
1131 else if (first && DECL_P (decl))
1133 /* For non-visible declarations, add a "@" prefix, which we skip
1134 when the label is output. If the label does not have this
1135 prefix, a ":" is output if -mtoplevel-symbols.
1137 Note that this does not work for data that is declared extern and
1138 later defined as static. If there's code in between, that code
1139 will refer to the extern declaration, and vice versa. This just
1140 means that when -mtoplevel-symbols is in use, we can just handle
1141 well-behaved ISO-compliant code. */
1143 const char *str = XSTR (XEXP (rtl, 0), 0);
1144 int len = strlen (str);
1147 /* Why is the return type of ggc_alloc_string const? */
1148 newstr = (char *) ggc_alloc_string ("", len + 1);
1150 strcpy (newstr + 1, str);
1152 XSTR (XEXP (rtl, 0), 0) = newstr;
1155 /* Set SYMBOL_REF_FLAG for things that we want to access with GETA. We
1156 may need different options to reach for different things with GETA.
1157 For now, functions and things we know or have been told are constant. */
1158 if (TREE_CODE (decl) == FUNCTION_DECL
1159 || TREE_CONSTANT (decl)
1160 || (TREE_CODE (decl) == VAR_DECL
1161 && TREE_READONLY (decl)
1162 && !TREE_SIDE_EFFECTS (decl)
1163 && (!DECL_INITIAL (decl)
1164 || TREE_CONSTANT (DECL_INITIAL (decl)))))
1165 SYMBOL_REF_FLAG (XEXP (rtl, 0)) = 1;
1169 mmix_strip_name_encoding (const char *name)
1171 for (; (*name == '@' || *name == '*'); name++)
1177 /* TARGET_ASM_FILE_START.
1178 We just emit a little comment for the time being. */
1181 mmix_file_start (void)
1183 default_file_start ();
1185 fputs ("! mmixal:= 8H LOC Data_Section\n", asm_out_file);
1187 /* Make sure each file starts with the text section. */
1191 /* TARGET_ASM_FILE_END. */
1194 mmix_file_end (void)
1196 /* Make sure each file ends with the data section. */
1200 /* ASM_OUTPUT_SOURCE_FILENAME. */
1203 mmix_asm_output_source_filename (FILE *stream, const char *name)
1205 fprintf (stream, "# 1 ");
1206 OUTPUT_QUOTED_STRING (stream, name);
1207 fprintf (stream, "\n");
1210 /* OUTPUT_QUOTED_STRING. */
1213 mmix_output_quoted_string (FILE *stream, const char *string, int length)
1215 const char * string_end = string + length;
1216 static const char *const unwanted_chars = "\"[]\\";
1218 /* Output "any character except newline and double quote character". We
1219 play it safe and avoid all control characters too. We also do not
1220 want [] as characters, should input be passed through m4 with [] as
1221 quotes. Further, we avoid "\", because the GAS port handles it as a
1222 quoting character. */
1223 while (string < string_end)
1226 && (unsigned char) *string < 128
1227 && !ISCNTRL (*string)
1228 && strchr (unwanted_chars, *string) == NULL)
1230 fputc ('"', stream);
1232 && (unsigned char) *string < 128
1233 && !ISCNTRL (*string)
1234 && strchr (unwanted_chars, *string) == NULL
1235 && string < string_end)
1237 fputc (*string, stream);
1240 fputc ('"', stream);
1241 if (string < string_end)
1242 fprintf (stream, ",");
1244 if (string < string_end)
1246 fprintf (stream, "#%x", *string & 255);
1248 if (string < string_end)
1249 fprintf (stream, ",");
1254 /* Target hook for assembling integer objects. Use mmix_print_operand
1255 for WYDE and TETRA. Use mmix_output_octa to output 8-byte
1259 mmix_assemble_integer (rtx x, unsigned int size, int aligned_p)
1264 /* We handle a limited number of types of operands in here. But
1265 that's ok, because we can punt to generic functions. We then
1266 pretend that aligned data isn't needed, so the usual .<pseudo>
1267 syntax is used (which works for aligned data too). We actually
1268 *must* do that, since we say we don't have simple aligned
1269 pseudos, causing this function to be called. We just try and
1270 keep as much compatibility as possible with mmixal syntax for
1271 normal cases (i.e. without GNU extensions and C only). */
1273 if (GET_CODE (x) != CONST_INT)
1278 fputs ("\tBYTE\t", asm_out_file);
1279 mmix_print_operand (asm_out_file, x, 'B');
1280 fputc ('\n', asm_out_file);
1284 if (GET_CODE (x) != CONST_INT)
1289 fputs ("\tWYDE\t", asm_out_file);
1290 mmix_print_operand (asm_out_file, x, 'W');
1291 fputc ('\n', asm_out_file);
1295 if (GET_CODE (x) != CONST_INT)
1300 fputs ("\tTETRA\t", asm_out_file);
1301 mmix_print_operand (asm_out_file, x, 'L');
1302 fputc ('\n', asm_out_file);
1306 /* We don't get here anymore for CONST_DOUBLE, because DImode
1307 isn't expressed as CONST_DOUBLE, and DFmode is handled
1309 gcc_assert (GET_CODE (x) != CONST_DOUBLE);
1310 assemble_integer_with_op ("\tOCTA\t", x);
1313 return default_assemble_integer (x, size, aligned_p);
1316 /* ASM_OUTPUT_ASCII. */
1319 mmix_asm_output_ascii (FILE *stream, const char *string, int length)
1323 int chunk_size = length > 60 ? 60 : length;
1324 fprintf (stream, "\tBYTE ");
1325 mmix_output_quoted_string (stream, string, chunk_size);
1326 string += chunk_size;
1327 length -= chunk_size;
1328 fprintf (stream, "\n");
1332 /* ASM_OUTPUT_ALIGNED_COMMON. */
1335 mmix_asm_output_aligned_common (FILE *stream,
1340 /* This is mostly the elfos.h one. There doesn't seem to be a way to
1341 express this in a mmixal-compatible way. */
1342 fprintf (stream, "\t.comm\t");
1343 assemble_name (stream, name);
1344 fprintf (stream, ",%u,%u ! mmixal-incompatible COMMON\n",
1345 size, align / BITS_PER_UNIT);
1348 /* ASM_OUTPUT_ALIGNED_LOCAL. */
1351 mmix_asm_output_aligned_local (FILE *stream,
1358 ASM_OUTPUT_ALIGN (stream, exact_log2 (align/BITS_PER_UNIT));
1359 assemble_name (stream, name);
1360 fprintf (stream, "\tLOC @+%d\n", size);
1363 /* ASM_OUTPUT_LABEL. */
1366 mmix_asm_output_label (FILE *stream, const char *name)
1368 assemble_name (stream, name);
1369 fprintf (stream, "\tIS @\n");
1372 /* ASM_OUTPUT_INTERNAL_LABEL. */
1375 mmix_asm_output_internal_label (FILE *stream, const char *name)
1377 assemble_name_raw (stream, name);
1378 fprintf (stream, "\tIS @\n");
1381 /* ASM_DECLARE_REGISTER_GLOBAL. */
1384 mmix_asm_declare_register_global (FILE *stream ATTRIBUTE_UNUSED,
1385 tree decl ATTRIBUTE_UNUSED,
1386 int regno ATTRIBUTE_UNUSED,
1387 const char *name ATTRIBUTE_UNUSED)
1389 /* Nothing to do here, but there *will* be, therefore the framework is
1393 /* ASM_WEAKEN_LABEL. */
1396 mmix_asm_weaken_label (FILE *stream ATTRIBUTE_UNUSED,
1397 const char *name ATTRIBUTE_UNUSED)
1399 fprintf (stream, "\t.weak ");
1400 assemble_name (stream, name);
1401 fprintf (stream, " ! mmixal-incompatible\n");
1404 /* MAKE_DECL_ONE_ONLY. */
1407 mmix_make_decl_one_only (tree decl)
1409 DECL_WEAK (decl) = 1;
1412 /* ASM_OUTPUT_LABELREF.
1413 Strip GCC's '*' and our own '@'. No order is assumed. */
1416 mmix_asm_output_labelref (FILE *stream, const char *name)
1420 for (; (*name == '@' || *name == '*'); name++)
1424 asm_fprintf (stream, "%s%U%s",
1425 is_extern && TARGET_TOPLEVEL_SYMBOLS ? ":" : "",
1429 /* ASM_OUTPUT_DEF. */
1432 mmix_asm_output_def (FILE *stream, const char *name, const char *value)
1434 assemble_name (stream, name);
1435 fprintf (stream, "\tIS ");
1436 assemble_name (stream, value);
1437 fputc ('\n', stream);
1440 /* PRINT_OPERAND. */
1443 mmix_print_operand (FILE *stream, rtx x, int code)
1445 /* When we add support for different codes later, we can, when needed,
1446 drop through to the main handler with a modified operand. */
1448 int regno = x != NULL_RTX && REG_P (x) ? REGNO (x) : 0;
1452 /* Unrelated codes are in alphabetic order. */
1455 /* For conditional branches, output "P" for a probable branch. */
1456 if (TARGET_BRANCH_PREDICT)
1458 x = find_reg_note (current_output_insn, REG_BR_PROB, 0);
1459 if (x && INTVAL (XEXP (x, 0)) > REG_BR_PROB_BASE / 2)
1465 /* For the %d in POP %d,0. */
1466 fprintf (stream, "%d", MMIX_POP_ARGUMENT ());
1470 if (GET_CODE (x) != CONST_INT)
1471 fatal_insn ("MMIX Internal: Expected a CONST_INT, not this", x);
1472 fprintf (stream, "%d", (int) (INTVAL (x) & 0xff));
1476 /* Highpart. Must be general register, and not the last one, as
1477 that one cannot be part of a consecutive register pair. */
1478 if (regno > MMIX_LAST_GENERAL_REGISTER - 1)
1479 internal_error ("MMIX Internal: Bad register: %d", regno);
1481 /* This is big-endian, so the high-part is the first one. */
1482 fprintf (stream, "%s", reg_names[MMIX_OUTPUT_REGNO (regno)]);
1486 /* Lowpart. Must be CONST_INT or general register, and not the last
1487 one, as that one cannot be part of a consecutive register pair. */
1488 if (GET_CODE (x) == CONST_INT)
1490 fprintf (stream, "#%lx",
1491 (unsigned long) (INTVAL (x)
1492 & ((unsigned int) 0x7fffffff * 2 + 1)));
1496 if (GET_CODE (x) == SYMBOL_REF)
1498 output_addr_const (stream, x);
1502 if (regno > MMIX_LAST_GENERAL_REGISTER - 1)
1503 internal_error ("MMIX Internal: Bad register: %d", regno);
1505 /* This is big-endian, so the low-part is + 1. */
1506 fprintf (stream, "%s", reg_names[MMIX_OUTPUT_REGNO (regno) + 1]);
1509 /* Can't use 'a' because that's a generic modifier for address
1512 mmix_output_shiftvalue_op_from_str (stream, "ANDN",
1513 ~(unsigned HOST_WIDEST_INT)
1518 mmix_output_shiftvalue_op_from_str (stream, "INC",
1519 (unsigned HOST_WIDEST_INT)
1524 mmix_output_shiftvalue_op_from_str (stream, "OR",
1525 (unsigned HOST_WIDEST_INT)
1530 mmix_output_shiftvalue_op_from_str (stream, "SET",
1531 (unsigned HOST_WIDEST_INT)
1537 mmix_output_condition (stream, x, (code == 'D'));
1541 /* Output an extra "e" to make fcmpe, fune. */
1542 if (TARGET_FCMP_EPSILON)
1543 fprintf (stream, "e");
1547 /* Output the number minus 1. */
1548 if (GET_CODE (x) != CONST_INT)
1550 fatal_insn ("MMIX Internal: Bad value for 'm', not a CONST_INT",
1553 fprintf (stream, HOST_WIDEST_INT_PRINT_DEC,
1554 (HOST_WIDEST_INT) (mmix_intval (x) - 1));
1558 /* Store the number of registers we want to save. This was setup
1559 by the prologue. The actual operand contains the number of
1560 registers to pass, but we don't use it currently. Anyway, we
1561 need to output the number of saved registers here. */
1562 fprintf (stream, "%d",
1563 cfun->machine->highest_saved_stack_register + 1);
1567 /* Store the register to output a constant to. */
1569 fatal_insn ("MMIX Internal: Expected a register, not this", x);
1570 mmix_output_destination_register = MMIX_OUTPUT_REGNO (regno);
1574 /* Output the constant. Note that we use this for floats as well. */
1575 if (GET_CODE (x) != CONST_INT
1576 && (GET_CODE (x) != CONST_DOUBLE
1577 || (GET_MODE (x) != VOIDmode && GET_MODE (x) != DFmode
1578 && GET_MODE (x) != SFmode)))
1579 fatal_insn ("MMIX Internal: Expected a constant, not this", x);
1580 mmix_output_register_setting (stream,
1581 mmix_output_destination_register,
1582 mmix_intval (x), 0);
1586 /* An U for unsigned, if TARGET_ZERO_EXTEND. Ignore the operand. */
1587 if (TARGET_ZERO_EXTEND)
1592 mmix_output_shifted_value (stream, (HOST_WIDEST_INT) mmix_intval (x));
1596 mmix_output_shifted_value (stream, (HOST_WIDEST_INT) ~mmix_intval (x));
1600 if (GET_CODE (x) != CONST_INT)
1601 fatal_insn ("MMIX Internal: Expected a CONST_INT, not this", x);
1602 fprintf (stream, "#%x", (int) (INTVAL (x) & 0xffff));
1606 /* Nothing to do. */
1610 /* Presumably there's a missing case above if we get here. */
1611 internal_error ("MMIX Internal: Missing %qc case in mmix_print_operand", code);
1614 switch (GET_CODE (modified_x))
1617 regno = REGNO (modified_x);
1618 if (regno >= FIRST_PSEUDO_REGISTER)
1619 internal_error ("MMIX Internal: Bad register: %d", regno);
1620 fprintf (stream, "%s", reg_names[MMIX_OUTPUT_REGNO (regno)]);
1624 output_address (XEXP (modified_x, 0));
1628 /* For -2147483648, mmixal complains that the constant does not fit
1629 in 4 bytes, so let's output it as hex. Take care to handle hosts
1630 where HOST_WIDE_INT is longer than an int.
1632 Print small constants +-255 using decimal. */
1634 if (INTVAL (modified_x) > -256 && INTVAL (modified_x) < 256)
1635 fprintf (stream, "%d", (int) (INTVAL (modified_x)));
1637 fprintf (stream, "#%x",
1638 (int) (INTVAL (modified_x)) & (unsigned int) ~0);
1642 /* Do somewhat as CONST_INT. */
1643 mmix_output_octa (stream, mmix_intval (modified_x), 0);
1647 output_addr_const (stream, modified_x);
1651 /* No need to test for all strange things. Let output_addr_const do
1653 if (CONSTANT_P (modified_x)
1654 /* Strangely enough, this is not included in CONSTANT_P.
1655 FIXME: Ask/check about sanity here. */
1656 || GET_CODE (modified_x) == CODE_LABEL)
1658 output_addr_const (stream, modified_x);
1662 /* We need the original here. */
1663 fatal_insn ("MMIX Internal: Cannot decode this operand", x);
1667 /* PRINT_OPERAND_PUNCT_VALID_P. */
1670 mmix_print_operand_punct_valid_p (int code ATTRIBUTE_UNUSED)
1672 /* A '+' is used for branch prediction, similar to other ports. */
1674 /* A '.' is used for the %d in the POP %d,0 return insn. */
1678 /* PRINT_OPERAND_ADDRESS. */
1681 mmix_print_operand_address (FILE *stream, rtx x)
1685 /* I find the generated assembly code harder to read without
1687 fprintf (stream, "%s,0", reg_names[MMIX_OUTPUT_REGNO (REGNO (x))]);
1690 else if (GET_CODE (x) == PLUS)
1692 rtx x1 = XEXP (x, 0);
1693 rtx x2 = XEXP (x, 1);
1697 fprintf (stream, "%s,", reg_names[MMIX_OUTPUT_REGNO (REGNO (x1))]);
1701 fprintf (stream, "%s",
1702 reg_names[MMIX_OUTPUT_REGNO (REGNO (x2))]);
1705 else if (GET_CODE (x2) == CONST_INT
1706 && CONST_OK_FOR_LETTER_P (INTVAL (x2), 'I'))
1708 output_addr_const (stream, x2);
1714 if (TARGET_BASE_ADDRESSES && mmix_legitimate_constant_p (x))
1716 output_addr_const (stream, x);
1720 fatal_insn ("MMIX Internal: This is not a recognized address", x);
1723 /* ASM_OUTPUT_REG_PUSH. */
1726 mmix_asm_output_reg_push (FILE *stream, int regno)
1728 fprintf (stream, "\tSUBU %s,%s,8\n\tSTOU %s,%s,0\n",
1729 reg_names[MMIX_STACK_POINTER_REGNUM],
1730 reg_names[MMIX_STACK_POINTER_REGNUM],
1731 reg_names[MMIX_OUTPUT_REGNO (regno)],
1732 reg_names[MMIX_STACK_POINTER_REGNUM]);
1735 /* ASM_OUTPUT_REG_POP. */
1738 mmix_asm_output_reg_pop (FILE *stream, int regno)
1740 fprintf (stream, "\tLDOU %s,%s,0\n\tINCL %s,8\n",
1741 reg_names[MMIX_OUTPUT_REGNO (regno)],
1742 reg_names[MMIX_STACK_POINTER_REGNUM],
1743 reg_names[MMIX_STACK_POINTER_REGNUM]);
1746 /* ASM_OUTPUT_ADDR_DIFF_ELT. */
1749 mmix_asm_output_addr_diff_elt (FILE *stream,
1750 rtx body ATTRIBUTE_UNUSED,
1754 fprintf (stream, "\tTETRA L%d-L%d\n", value, rel);
1757 /* ASM_OUTPUT_ADDR_VEC_ELT. */
1760 mmix_asm_output_addr_vec_elt (FILE *stream, int value)
1762 fprintf (stream, "\tOCTA L:%d\n", value);
1765 /* ASM_OUTPUT_SKIP. */
1768 mmix_asm_output_skip (FILE *stream, int nbytes)
1770 fprintf (stream, "\tLOC @+%d\n", nbytes);
1773 /* ASM_OUTPUT_ALIGN. */
1776 mmix_asm_output_align (FILE *stream, int power)
1778 /* We need to record the needed alignment of this section in the object,
1779 so we have to output an alignment directive. Use a .p2align (not
1780 .align) so people will never have to wonder about whether the
1781 argument is in number of bytes or the log2 thereof. We do it in
1782 addition to the LOC directive, so nothing needs tweaking when
1783 copy-pasting assembly into mmixal. */
1784 fprintf (stream, "\t.p2align %d\n", power);
1785 fprintf (stream, "\tLOC @+(%d-@)&%d\n", 1 << power, (1 << power) - 1);
1788 /* DBX_REGISTER_NUMBER. */
1791 mmix_dbx_register_number (int regno)
1793 /* Adjust the register number to the one it will be output as, dammit.
1794 It'd be nice if we could check the assumption that we're filling a
1795 gap, but every register between the last saved register and parameter
1796 registers might be a valid parameter register. */
1797 regno = MMIX_OUTPUT_REGNO (regno);
1799 /* We need to renumber registers to get the number of the return address
1800 register in the range 0..255. It is also space-saving if registers
1801 mentioned in the call-frame information (which uses this function by
1802 defaulting DWARF_FRAME_REGNUM to DBX_REGISTER_NUMBER) are numbered
1803 0 .. 63. So map 224 .. 256+15 -> 0 .. 47 and 0 .. 223 -> 48..223+48. */
1804 return regno >= 224 ? (regno - 224) : (regno + 48);
1807 /* End of target macro support functions.
1809 Now the MMIX port's own functions. First the exported ones. */
1811 /* Wrapper for get_hard_reg_initial_val since integrate.h isn't included
1812 from insn-emit.c. */
1815 mmix_get_hard_reg_initial_val (enum machine_mode mode, int regno)
1817 return get_hard_reg_initial_val (mode, regno);
1820 /* Nonzero when the function epilogue is simple enough that a single
1821 "POP %d,0" should be used even within the function. */
1824 mmix_use_simple_return (void)
1828 int stack_space_to_allocate
1829 = (current_function_outgoing_args_size
1830 + current_function_pretend_args_size
1831 + get_frame_size () + 7) & ~7;
1833 if (!TARGET_USE_RETURN_INSN || !reload_completed)
1837 regno >= MMIX_FIRST_GLOBAL_REGNUM;
1839 /* Note that we assume that the frame-pointer-register is one of these
1840 registers, in which case we don't count it here. */
1841 if ((((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
1842 && regs_ever_live[regno] && !call_used_regs[regno]))
1843 || IS_MMIX_EH_RETURN_DATA_REG (regno))
1846 if (frame_pointer_needed)
1847 stack_space_to_allocate += 8;
1849 if (MMIX_CFUN_HAS_LANDING_PAD)
1850 stack_space_to_allocate += 16;
1851 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
1852 stack_space_to_allocate += 8;
1854 return stack_space_to_allocate == 0;
1858 /* Expands the function prologue into RTX. */
1861 mmix_expand_prologue (void)
1863 HOST_WIDE_INT locals_size = get_frame_size ();
1865 HOST_WIDE_INT stack_space_to_allocate
1866 = (current_function_outgoing_args_size
1867 + current_function_pretend_args_size
1868 + locals_size + 7) & ~7;
1869 HOST_WIDE_INT offset = -8;
1871 /* Add room needed to save global non-register-stack registers. */
1873 regno >= MMIX_FIRST_GLOBAL_REGNUM;
1875 /* Note that we assume that the frame-pointer-register is one of these
1876 registers, in which case we don't count it here. */
1877 if ((((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
1878 && regs_ever_live[regno] && !call_used_regs[regno]))
1879 || IS_MMIX_EH_RETURN_DATA_REG (regno))
1880 stack_space_to_allocate += 8;
1882 /* If we do have a frame-pointer, add room for it. */
1883 if (frame_pointer_needed)
1884 stack_space_to_allocate += 8;
1886 /* If we have a non-local label, we need to be able to unwind to it, so
1887 store the current register stack pointer. Also store the return
1888 address if we do that. */
1889 if (MMIX_CFUN_HAS_LANDING_PAD)
1890 stack_space_to_allocate += 16;
1891 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
1892 /* If we do have a saved return-address slot, add room for it. */
1893 stack_space_to_allocate += 8;
1895 /* Make sure we don't get an unaligned stack. */
1896 if ((stack_space_to_allocate % 8) != 0)
1897 internal_error ("stack frame not a multiple of 8 bytes: %d",
1898 stack_space_to_allocate);
1900 if (current_function_pretend_args_size)
1902 int mmix_first_vararg_reg
1903 = (MMIX_FIRST_INCOMING_ARG_REGNUM
1904 + (MMIX_MAX_ARGS_IN_REGS
1905 - current_function_pretend_args_size / 8));
1908 = MMIX_FIRST_INCOMING_ARG_REGNUM + MMIX_MAX_ARGS_IN_REGS - 1;
1909 regno >= mmix_first_vararg_reg;
1914 HOST_WIDE_INT stack_chunk
1915 = stack_space_to_allocate > (256 - 8)
1916 ? (256 - 8) : stack_space_to_allocate;
1918 mmix_emit_sp_add (-stack_chunk);
1919 offset += stack_chunk;
1920 stack_space_to_allocate -= stack_chunk;
1923 /* These registers aren't actually saved (as in "will be
1924 restored"), so don't tell DWARF2 they're saved. */
1925 emit_move_insn (gen_rtx_MEM (DImode,
1926 plus_constant (stack_pointer_rtx,
1928 gen_rtx_REG (DImode, regno));
1933 /* Store the frame-pointer. */
1935 if (frame_pointer_needed)
1941 /* Get 8 less than otherwise, since we need to reach offset + 8. */
1942 HOST_WIDE_INT stack_chunk
1943 = stack_space_to_allocate > (256 - 8 - 8)
1944 ? (256 - 8 - 8) : stack_space_to_allocate;
1946 mmix_emit_sp_add (-stack_chunk);
1948 offset += stack_chunk;
1949 stack_space_to_allocate -= stack_chunk;
1952 insn = emit_move_insn (gen_rtx_MEM (DImode,
1953 plus_constant (stack_pointer_rtx,
1955 hard_frame_pointer_rtx);
1956 RTX_FRAME_RELATED_P (insn) = 1;
1957 insn = emit_insn (gen_adddi3 (hard_frame_pointer_rtx,
1959 GEN_INT (offset + 8)));
1960 RTX_FRAME_RELATED_P (insn) = 1;
1964 if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
1969 /* Store the return-address, if one is needed on the stack. We
1970 usually store it in a register when needed, but that doesn't work
1971 with -fexceptions. */
1975 /* Get 8 less than otherwise, since we need to reach offset + 8. */
1976 HOST_WIDE_INT stack_chunk
1977 = stack_space_to_allocate > (256 - 8 - 8)
1978 ? (256 - 8 - 8) : stack_space_to_allocate;
1980 mmix_emit_sp_add (-stack_chunk);
1982 offset += stack_chunk;
1983 stack_space_to_allocate -= stack_chunk;
1986 tmpreg = gen_rtx_REG (DImode, 255);
1987 retreg = gen_rtx_REG (DImode, MMIX_rJ_REGNUM);
1989 /* Dwarf2 code is confused by the use of a temporary register for
1990 storing the return address, so we have to express it as a note,
1991 which we attach to the actual store insn. */
1992 emit_move_insn (tmpreg, retreg);
1994 insn = emit_move_insn (gen_rtx_MEM (DImode,
1995 plus_constant (stack_pointer_rtx,
1998 RTX_FRAME_RELATED_P (insn) = 1;
2000 = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
2001 gen_rtx_SET (VOIDmode,
2002 gen_rtx_MEM (DImode,
2003 plus_constant (stack_pointer_rtx,
2010 else if (MMIX_CFUN_HAS_LANDING_PAD)
2013 if (MMIX_CFUN_HAS_LANDING_PAD)
2015 /* Store the register defining the numbering of local registers, so
2016 we know how long to unwind the register stack. */
2020 /* Get 8 less than otherwise, since we need to reach offset + 8. */
2021 HOST_WIDE_INT stack_chunk
2022 = stack_space_to_allocate > (256 - 8 - 8)
2023 ? (256 - 8 - 8) : stack_space_to_allocate;
2025 mmix_emit_sp_add (-stack_chunk);
2027 offset += stack_chunk;
2028 stack_space_to_allocate -= stack_chunk;
2031 /* We don't tell dwarf2 about this one; we just have it to unwind
2032 the register stack at landing pads. FIXME: It's a kludge because
2033 we can't describe the effect of the PUSHJ and PUSHGO insns on the
2034 register stack at the moment. Best thing would be to handle it
2035 like stack-pointer offsets. Better: some hook into dwarf2out.c
2036 to produce DW_CFA_expression:s that specify the increment of rO,
2037 and unwind it at eh_return (preferred) or at the landing pad.
2038 Then saves to $0..$G-1 could be specified through that register. */
2040 emit_move_insn (gen_rtx_REG (DImode, 255),
2041 gen_rtx_REG (DImode,
2043 emit_move_insn (gen_rtx_MEM (DImode,
2044 plus_constant (stack_pointer_rtx, offset)),
2045 gen_rtx_REG (DImode, 255));
2049 /* After the return-address and the frame-pointer, we have the local
2050 variables. They're the ones that may have an "unaligned" size. */
2051 offset -= (locals_size + 7) & ~7;
2053 /* Now store all registers that are global, i.e. not saved by the
2054 register file machinery.
2056 It is assumed that the frame-pointer is one of these registers, so it
2057 is explicitly excluded in the count. */
2060 regno >= MMIX_FIRST_GLOBAL_REGNUM;
2062 if (((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
2063 && regs_ever_live[regno] && ! call_used_regs[regno])
2064 || IS_MMIX_EH_RETURN_DATA_REG (regno))
2070 HOST_WIDE_INT stack_chunk
2071 = (stack_space_to_allocate > (256 - offset - 8)
2072 ? (256 - offset - 8) : stack_space_to_allocate);
2074 mmix_emit_sp_add (-stack_chunk);
2075 offset += stack_chunk;
2076 stack_space_to_allocate -= stack_chunk;
2079 insn = emit_move_insn (gen_rtx_MEM (DImode,
2080 plus_constant (stack_pointer_rtx,
2082 gen_rtx_REG (DImode, regno));
2083 RTX_FRAME_RELATED_P (insn) = 1;
2087 /* Finally, allocate room for outgoing args and local vars if room
2088 wasn't allocated above. */
2089 if (stack_space_to_allocate)
2090 mmix_emit_sp_add (-stack_space_to_allocate);
2093 /* Expands the function epilogue into RTX. */
2096 mmix_expand_epilogue (void)
2098 HOST_WIDE_INT locals_size = get_frame_size ();
2100 HOST_WIDE_INT stack_space_to_deallocate
2101 = (current_function_outgoing_args_size
2102 + current_function_pretend_args_size
2103 + locals_size + 7) & ~7;
2105 /* The first address to access is beyond the outgoing_args area. */
2106 HOST_WIDE_INT offset = current_function_outgoing_args_size;
2108 /* Add the space for global non-register-stack registers.
2109 It is assumed that the frame-pointer register can be one of these
2110 registers, in which case it is excluded from the count when needed. */
2112 regno >= MMIX_FIRST_GLOBAL_REGNUM;
2114 if (((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
2115 && regs_ever_live[regno] && !call_used_regs[regno])
2116 || IS_MMIX_EH_RETURN_DATA_REG (regno))
2117 stack_space_to_deallocate += 8;
2119 /* Add in the space for register stack-pointer. If so, always add room
2120 for the saved PC. */
2121 if (MMIX_CFUN_HAS_LANDING_PAD)
2122 stack_space_to_deallocate += 16;
2123 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
2124 /* If we have a saved return-address slot, add it in. */
2125 stack_space_to_deallocate += 8;
2127 /* Add in the frame-pointer. */
2128 if (frame_pointer_needed)
2129 stack_space_to_deallocate += 8;
2131 /* Make sure we don't get an unaligned stack. */
2132 if ((stack_space_to_deallocate % 8) != 0)
2133 internal_error ("stack frame not a multiple of octabyte: %d",
2134 stack_space_to_deallocate);
2136 /* We will add back small offsets to the stack pointer as we go.
2137 First, we restore all registers that are global, i.e. not saved by
2138 the register file machinery. */
2140 for (regno = MMIX_FIRST_GLOBAL_REGNUM;
2143 if (((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
2144 && regs_ever_live[regno] && !call_used_regs[regno])
2145 || IS_MMIX_EH_RETURN_DATA_REG (regno))
2149 mmix_emit_sp_add (offset);
2150 stack_space_to_deallocate -= offset;
2154 emit_move_insn (gen_rtx_REG (DImode, regno),
2155 gen_rtx_MEM (DImode,
2156 plus_constant (stack_pointer_rtx,
2161 /* Here is where the local variables were. As in the prologue, they
2162 might be of an unaligned size. */
2163 offset += (locals_size + 7) & ~7;
2165 /* The saved register stack pointer is just below the frame-pointer
2166 register. We don't need to restore it "manually"; the POP
2167 instruction does that. */
2168 if (MMIX_CFUN_HAS_LANDING_PAD)
2170 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
2171 /* The return-address slot is just below the frame-pointer register.
2172 We don't need to restore it because we don't really use it. */
2175 /* Get back the old frame-pointer-value. */
2176 if (frame_pointer_needed)
2180 mmix_emit_sp_add (offset);
2182 stack_space_to_deallocate -= offset;
2186 emit_move_insn (hard_frame_pointer_rtx,
2187 gen_rtx_MEM (DImode,
2188 plus_constant (stack_pointer_rtx,
2193 /* We do not need to restore pretended incoming args, just add back
2195 if (stack_space_to_deallocate != 0)
2196 mmix_emit_sp_add (stack_space_to_deallocate);
2198 if (current_function_calls_eh_return)
2199 /* Adjust the (normal) stack-pointer to that of the receiver.
2200 FIXME: It would be nice if we could also adjust the register stack
2201 here, but we need to express it through DWARF 2 too. */
2202 emit_insn (gen_adddi3 (stack_pointer_rtx, stack_pointer_rtx,
2203 gen_rtx_REG (DImode,
2204 MMIX_EH_RETURN_STACKADJ_REGNUM)));
2207 /* Output an optimal sequence for setting a register to a specific
2208 constant. Used in an alternative for const_ints in movdi, and when
2209 using large stack-frame offsets.
2211 Use do_begin_end to say if a line-starting TAB and newline before the
2212 first insn and after the last insn is wanted. */
2215 mmix_output_register_setting (FILE *stream,
2217 HOST_WIDEST_INT value,
2221 fprintf (stream, "\t");
2223 if (mmix_shiftable_wyde_value ((unsigned HOST_WIDEST_INT) value))
2225 /* First, the one-insn cases. */
2226 mmix_output_shiftvalue_op_from_str (stream, "SET",
2227 (unsigned HOST_WIDEST_INT)
2229 fprintf (stream, " %s,", reg_names[regno]);
2230 mmix_output_shifted_value (stream, (unsigned HOST_WIDEST_INT) value);
2232 else if (mmix_shiftable_wyde_value (-(unsigned HOST_WIDEST_INT) value))
2234 /* We do this to get a bit more legible assembly code. The next
2235 alternative is mostly redundant with this. */
2237 mmix_output_shiftvalue_op_from_str (stream, "SET",
2238 -(unsigned HOST_WIDEST_INT)
2240 fprintf (stream, " %s,", reg_names[regno]);
2241 mmix_output_shifted_value (stream, -(unsigned HOST_WIDEST_INT) value);
2242 fprintf (stream, "\n\tNEGU %s,0,%s", reg_names[regno],
2245 else if (mmix_shiftable_wyde_value (~(unsigned HOST_WIDEST_INT) value))
2247 /* Slightly more expensive, the two-insn cases. */
2249 /* FIXME: We could of course also test if 0..255-N or ~(N | 1..255)
2250 is shiftable, or any other one-insn transformation of the value.
2251 FIXME: Check first if the value is "shiftable" by two loading
2252 with two insns, since it makes more readable assembly code (if
2253 anyone else cares). */
2255 mmix_output_shiftvalue_op_from_str (stream, "SET",
2256 ~(unsigned HOST_WIDEST_INT)
2258 fprintf (stream, " %s,", reg_names[regno]);
2259 mmix_output_shifted_value (stream, ~(unsigned HOST_WIDEST_INT) value);
2260 fprintf (stream, "\n\tNOR %s,%s,0", reg_names[regno],
2265 /* The generic case. 2..4 insns. */
2266 static const char *const higher_parts[] = {"L", "ML", "MH", "H"};
2267 const char *op = "SET";
2268 const char *line_begin = "";
2271 HOST_WIDEST_INT tmpvalue = value;
2273 /* Compute the number of insns needed to output this constant. */
2274 for (i = 0; i < 4 && tmpvalue != 0; i++)
2276 if (tmpvalue & 65535)
2280 if (TARGET_BASE_ADDRESSES && insns == 3)
2282 /* The number three is based on a static observation on
2283 ghostscript-6.52. Two and four are excluded because there
2284 are too many such constants, and each unique constant (maybe
2285 offset by 1..255) were used few times compared to other uses,
2288 We use base-plus-offset addressing to force it into a global
2289 register; we just use a "LDA reg,VALUE", which will cause the
2290 assembler and linker to DTRT (for constants as well as
2292 fprintf (stream, "LDA %s,", reg_names[regno]);
2293 mmix_output_octa (stream, value, 0);
2297 /* Output pertinent parts of the 4-wyde sequence.
2298 Still more to do if we want this to be optimal, but hey...
2299 Note that the zero case has been handled above. */
2300 for (i = 0; i < 4 && value != 0; i++)
2304 fprintf (stream, "%s%s%s %s,#%x", line_begin, op,
2305 higher_parts[i], reg_names[regno],
2306 (int) (value & 65535));
2307 /* The first one sets the rest of the bits to 0, the next
2308 ones add set bits. */
2310 line_begin = "\n\t";
2319 fprintf (stream, "\n");
2322 /* Return 1 if value is 0..65535*2**(16*N) for N=0..3.
2326 mmix_shiftable_wyde_value (unsigned HOST_WIDEST_INT value)
2328 /* Shift by 16 bits per group, stop when we've found two groups with
2331 int has_candidate = 0;
2333 for (i = 0; i < 4; i++)
2349 /* True if this is an address_operand or a symbolic operand. */
2352 mmix_symbolic_or_address_operand (rtx op, enum machine_mode mode)
2354 switch (GET_CODE (op))
2361 if ((GET_CODE (XEXP (op, 0)) == SYMBOL_REF
2362 || GET_CODE (XEXP (op, 0)) == LABEL_REF)
2363 && (GET_CODE (XEXP (op, 1)) == CONST_INT
2364 || (GET_CODE (XEXP (op, 1)) == CONST_DOUBLE
2365 && GET_MODE (XEXP (op, 1)) == VOIDmode)))
2369 return address_operand (op, mode);
2373 /* True if this is a register or CONST_INT (or CONST_DOUBLE for DImode).
2374 We could narrow the value down with a couple of predicated, but that
2375 doesn't seem to be worth it at the moment. */
2378 mmix_reg_or_constant_operand (rtx op, enum machine_mode mode)
2380 return register_operand (op, mode)
2381 || (GET_CODE (op) == CONST_DOUBLE && GET_MODE (op) == VOIDmode)
2382 || GET_CODE (op) == CONST_INT;
2385 /* True if this is a register with a condition-code mode. */
2388 mmix_reg_cc_operand (rtx op, enum machine_mode mode)
2390 if (mode == VOIDmode)
2391 mode = GET_MODE (op);
2393 return register_operand (op, mode)
2394 && (mode == CCmode || mode == CC_UNSmode || mode == CC_FPmode
2395 || mode == CC_FPEQmode || mode == CC_FUNmode);
2398 /* True if this is a foldable comparison operator
2399 - one where a the result of (compare:CC (reg) (const_int 0)) can be
2400 replaced by (reg). */
2403 mmix_foldable_comparison_operator (rtx op, enum machine_mode mode)
2405 RTX_CODE code = GET_CODE (op);
2407 if (mode == VOIDmode)
2408 mode = GET_MODE (op);
2410 if (mode == VOIDmode && COMPARISON_P (op))
2411 mode = GET_MODE (XEXP (op, 0));
2413 return ((mode == CCmode || mode == DImode)
2414 && (code == NE || code == EQ || code == GE || code == GT
2416 /* FIXME: This may be a stupid trick. What happens when GCC wants to
2417 reverse the condition? Can it do that by itself? Maybe it can
2418 even reverse the condition to fit a foldable one in the first
2420 || (mode == CC_UNSmode && (code == GTU || code == LEU));
2423 /* Like comparison_operator, but only true if this comparison operator is
2424 applied to a valid mode. Needed to avoid jump.c generating invalid
2425 code with -ffast-math (gcc.dg/20001228-1.c). */
2428 mmix_comparison_operator (rtx op, enum machine_mode mode)
2430 RTX_CODE code = GET_CODE (op);
2432 /* Comparison operators usually don't have a mode, but let's try and get
2433 one anyway for the day that changes. */
2434 if (mode == VOIDmode)
2435 mode = GET_MODE (op);
2437 /* Get the mode from the first operand if we don't have one. */
2438 if (mode == VOIDmode && COMPARISON_P (op))
2439 mode = GET_MODE (XEXP (op, 0));
2441 /* FIXME: This needs to be kept in sync with the tables in
2442 mmix_output_condition. */
2444 (mode == VOIDmode && COMPARISON_P (op))
2445 || (mode == CC_FUNmode
2446 && (code == ORDERED || code == UNORDERED))
2447 || (mode == CC_FPmode
2448 && (code == GT || code == LT))
2449 || (mode == CC_FPEQmode
2450 && (code == NE || code == EQ))
2451 || (mode == CC_UNSmode
2452 && (code == GEU || code == GTU || code == LEU || code == LTU))
2454 && (code == NE || code == EQ || code == GE || code == GT
2455 || code == LE || code == LT))
2457 && (code == NE || code == EQ || code == GE || code == GT
2458 || code == LE || code == LT || code == LEU || code == GTU));
2461 /* True if this is a register or 0 (int or float). */
2464 mmix_reg_or_0_operand (rtx op, enum machine_mode mode)
2466 /* FIXME: Is mode calculation necessary and correct? */
2468 op == CONST0_RTX (mode == VOIDmode ? GET_MODE (op) : mode)
2469 || register_operand (op, mode);
2472 /* True if this is a register or an int 0..255. */
2475 mmix_reg_or_8bit_operand (rtx op, enum machine_mode mode)
2477 return register_operand (op, mode)
2478 || (GET_CODE (op) == CONST_INT
2479 && CONST_OK_FOR_LETTER_P (INTVAL (op), 'I'));
2482 /* Returns zero if code and mode is not a valid condition from a
2483 compare-type insn. Nonzero if it is. The parameter op, if non-NULL,
2484 is the comparison of mode is CC-somethingmode. */
2487 mmix_valid_comparison (RTX_CODE code, enum machine_mode mode, rtx op)
2489 if (mode == VOIDmode && op != NULL_RTX)
2490 mode = GET_MODE (op);
2492 /* We don't care to look at these, they should always be valid. */
2493 if (mode == CCmode || mode == CC_UNSmode || mode == DImode)
2496 if ((mode == CC_FPmode || mode == DFmode)
2497 && (code == GT || code == LT))
2500 if ((mode == CC_FPEQmode || mode == DFmode)
2501 && (code == EQ || code == NE))
2504 if ((mode == CC_FUNmode || mode == DFmode)
2505 && (code == ORDERED || code == UNORDERED))
2511 /* X and Y are two things to compare using CODE. Emit a compare insn if
2512 possible and return the rtx for the cc-reg in the proper mode, or
2513 NULL_RTX if this is not a valid comparison. */
2516 mmix_gen_compare_reg (RTX_CODE code, rtx x, rtx y)
2518 enum machine_mode ccmode = SELECT_CC_MODE (code, x, y);
2521 /* FIXME: Do we get constants here? Of double mode? */
2522 enum machine_mode mode
2523 = GET_MODE (x) == VOIDmode
2525 : GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT ? DFmode : DImode;
2527 if (! mmix_valid_comparison (code, mode, x))
2530 cc_reg = gen_reg_rtx (ccmode);
2532 /* FIXME: Can we avoid emitting a compare insn here? */
2533 if (! REG_P (x) && ! REG_P (y))
2534 x = force_reg (mode, x);
2536 /* If it's not quite right yet, put y in a register. */
2538 && (GET_CODE (y) != CONST_INT
2539 || ! CONST_OK_FOR_LETTER_P (INTVAL (y), 'I')))
2540 y = force_reg (mode, y);
2542 emit_insn (gen_rtx_SET (VOIDmode, cc_reg,
2543 gen_rtx_COMPARE (ccmode, x, y)));
2548 /* Local (static) helper functions. */
2551 mmix_emit_sp_add (HOST_WIDE_INT offset)
2557 /* Negative stack-pointer adjustments are allocations and appear in
2558 the prologue only. We mark them as frame-related so unwind and
2559 debug info is properly emitted for them. */
2561 insn = emit_insn (gen_adddi3 (stack_pointer_rtx,
2566 rtx tmpr = gen_rtx_REG (DImode, 255);
2567 RTX_FRAME_RELATED_P (emit_move_insn (tmpr, GEN_INT (offset))) = 1;
2568 insn = emit_insn (gen_adddi3 (stack_pointer_rtx,
2569 stack_pointer_rtx, tmpr));
2571 RTX_FRAME_RELATED_P (insn) = 1;
2575 /* Positive adjustments are in the epilogue only. Don't mark them
2576 as "frame-related" for unwind info. */
2577 if (CONST_OK_FOR_LETTER_P (offset, 'L'))
2578 emit_insn (gen_adddi3 (stack_pointer_rtx,
2583 rtx tmpr = gen_rtx_REG (DImode, 255);
2584 emit_move_insn (tmpr, GEN_INT (offset));
2585 insn = emit_insn (gen_adddi3 (stack_pointer_rtx,
2586 stack_pointer_rtx, tmpr));
2591 /* Print operator suitable for doing something with a shiftable
2592 wyde. The type of operator is passed as an asm output modifier. */
2595 mmix_output_shiftvalue_op_from_str (FILE *stream,
2597 HOST_WIDEST_INT value)
2599 static const char *const op_part[] = {"L", "ML", "MH", "H"};
2602 if (! mmix_shiftable_wyde_value (value))
2604 char s[sizeof ("0xffffffffffffffff")];
2605 sprintf (s, HOST_WIDEST_INT_PRINT_HEX, value);
2606 internal_error ("MMIX Internal: %s is not a shiftable int", s);
2609 for (i = 0; i < 4; i++)
2611 /* We know we're through when we find one-bits in the low
2615 fprintf (stream, "%s%s", mainop, op_part[i]);
2621 /* No bits set? Then it must have been zero. */
2622 fprintf (stream, "%sL", mainop);
2625 /* Print a 64-bit value, optionally prefixed by assembly pseudo. */
2628 mmix_output_octa (FILE *stream, HOST_WIDEST_INT value, int do_begin_end)
2630 /* Snipped from final.c:output_addr_const. We need to avoid the
2631 presumed universal "0x" prefix. We can do it by replacing "0x" with
2632 "#0" here; we must avoid a space in the operands and no, the zero
2633 won't cause the number to be assumed in octal format. */
2634 char hex_format[sizeof (HOST_WIDEST_INT_PRINT_HEX)];
2637 fprintf (stream, "\tOCTA ");
2639 strcpy (hex_format, HOST_WIDEST_INT_PRINT_HEX);
2640 hex_format[0] = '#';
2641 hex_format[1] = '0';
2643 /* Provide a few alternative output formats depending on the number, to
2644 improve legibility of assembler output. */
2645 if ((value < (HOST_WIDEST_INT) 0 && value > (HOST_WIDEST_INT) -10000)
2646 || (value >= (HOST_WIDEST_INT) 0 && value <= (HOST_WIDEST_INT) 16384))
2647 fprintf (stream, "%d", (int) value);
2648 else if (value > (HOST_WIDEST_INT) 0
2649 && value < ((HOST_WIDEST_INT) 1 << 31) * 2)
2650 fprintf (stream, "#%x", (unsigned int) value);
2652 fprintf (stream, hex_format, value);
2655 fprintf (stream, "\n");
2658 /* Print the presumed shiftable wyde argument shifted into place (to
2659 be output with an operand). */
2662 mmix_output_shifted_value (FILE *stream, HOST_WIDEST_INT value)
2666 if (! mmix_shiftable_wyde_value (value))
2669 sprintf (s, HOST_WIDEST_INT_PRINT_HEX, value);
2670 internal_error ("MMIX Internal: %s is not a shiftable int", s);
2673 for (i = 0; i < 4; i++)
2675 /* We know we're through when we find one-bits in the low 16 bits. */
2678 fprintf (stream, "#%x", (int) (value & 0xffff));
2685 /* No bits set? Then it must have been zero. */
2686 fprintf (stream, "0");
2689 /* Output an MMIX condition name corresponding to an operator
2691 (comparison_operator [(comparison_operator ...) (const_int 0)])
2692 which means we have to look at *two* operators.
2694 The argument "reversed" refers to reversal of the condition (not the
2695 same as swapping the arguments). */
2698 mmix_output_condition (FILE *stream, rtx x, int reversed)
2704 /* The normal output cc-code. */
2705 const char *const normal;
2707 /* The reversed cc-code, or NULL if invalid. */
2708 const char *const reversed;
2713 enum machine_mode cc_mode;
2715 /* Terminated with {UNKNOWN, NULL, NULL} */
2716 const struct cc_conv *const convs;
2720 #define CCEND {UNKNOWN, NULL, NULL}
2722 static const struct cc_conv cc_fun_convs[]
2723 = {{ORDERED, "Z", "P"},
2724 {UNORDERED, "P", "Z"},
2726 static const struct cc_conv cc_fp_convs[]
2730 static const struct cc_conv cc_fpeq_convs[]
2734 static const struct cc_conv cc_uns_convs[]
2735 = {{GEU, "NN", "N"},
2740 static const struct cc_conv cc_signed_convs[]
2748 static const struct cc_conv cc_di_convs[]
2760 static const struct cc_type_conv cc_convs[]
2761 = {{CC_FUNmode, cc_fun_convs},
2762 {CC_FPmode, cc_fp_convs},
2763 {CC_FPEQmode, cc_fpeq_convs},
2764 {CC_UNSmode, cc_uns_convs},
2765 {CCmode, cc_signed_convs},
2766 {DImode, cc_di_convs}};
2771 enum machine_mode mode = GET_MODE (XEXP (x, 0));
2772 RTX_CODE cc = GET_CODE (x);
2774 for (i = 0; i < ARRAY_SIZE (cc_convs); i++)
2776 if (mode == cc_convs[i].cc_mode)
2778 for (j = 0; cc_convs[i].convs[j].cc != UNKNOWN; j++)
2779 if (cc == cc_convs[i].convs[j].cc)
2782 = (reversed ? cc_convs[i].convs[j].reversed
2783 : cc_convs[i].convs[j].normal);
2785 if (mmix_cc == NULL)
2786 fatal_insn ("MMIX Internal: Trying to output invalidly\
2787 reversed condition:", x);
2789 fprintf (stream, "%s", mmix_cc);
2793 fatal_insn ("MMIX Internal: What's the CC of this?", x);
2797 fatal_insn ("MMIX Internal: What is the CC of this?", x);
2800 /* Return the bit-value for a const_int or const_double. */
2802 static HOST_WIDEST_INT
2805 unsigned HOST_WIDEST_INT retval;
2807 if (GET_CODE (x) == CONST_INT)
2810 /* We make a little song and dance because converting to long long in
2811 gcc-2.7.2 is broken. I still want people to be able to use it for
2812 cross-compilation to MMIX. */
2813 if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == VOIDmode)
2815 if (sizeof (HOST_WIDE_INT) < sizeof (HOST_WIDEST_INT))
2817 retval = (unsigned) CONST_DOUBLE_LOW (x) / 2;
2819 retval |= CONST_DOUBLE_LOW (x) & 1;
2822 (unsigned HOST_WIDEST_INT) CONST_DOUBLE_HIGH (x)
2823 << (HOST_BITS_PER_LONG);
2826 retval = CONST_DOUBLE_HIGH (x);
2831 if (GET_CODE (x) == CONST_DOUBLE)
2833 REAL_VALUE_TYPE value;
2835 /* FIXME: This macro is not in the manual but should be. */
2836 REAL_VALUE_FROM_CONST_DOUBLE (value, x);
2838 if (GET_MODE (x) == DFmode)
2842 REAL_VALUE_TO_TARGET_DOUBLE (value, bits);
2844 if (sizeof (long) < sizeof (HOST_WIDEST_INT))
2846 retval = (unsigned long) bits[1] / 2;
2848 retval |= (unsigned long) bits[1] & 1;
2850 |= (unsigned HOST_WIDEST_INT) bits[0]
2851 << (sizeof (bits[0]) * 8);
2854 retval = (unsigned long) bits[1];
2858 else if (GET_MODE (x) == SFmode)
2861 REAL_VALUE_TO_TARGET_SINGLE (value, bits);
2863 return (unsigned long) bits;
2867 fatal_insn ("MMIX Internal: This is not a constant:", x);
2870 /* Worker function for TARGET_STRUCT_VALUE_RTX. */
2873 mmix_struct_value_rtx (tree fntype ATTRIBUTE_UNUSED,
2874 int incoming ATTRIBUTE_UNUSED)
2876 return gen_rtx_REG (Pmode, MMIX_STRUCT_VALUE_REGNUM);
2881 * eval: (c-set-style "gnu")
2882 * indent-tabs-mode: t