1 /* Definitions of target machine for GNU compiler, for MMIX.
2 Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
3 Contributed by Hans-Peter Nilsson (hp@bitrange.com)
5 This file is part of GNU CC.
7 GNU CC 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 GNU CC 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 GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
26 #include "hard-reg-set.h"
28 #include "insn-config.h"
40 #include "integrate.h"
42 #include "target-def.h"
44 /* First some local helper definitions. */
45 #define MMIX_FIRST_GLOBAL_REGNUM 32
47 /* We'd need a current_function_has_landing_pad. It's marked as such when
48 a nonlocal_goto_receiver is expanded. Not just a C++ thing, but
50 #define MMIX_CFUN_HAS_LANDING_PAD (cfun->machine->has_landing_pad != 0)
52 /* We have no means to tell DWARF 2 about the register stack, so we need
53 to store the return address on the stack if an exception can get into
54 this function. FIXME: Narrow condition. */
55 #define MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS \
56 (flag_exceptions && ! leaf_function_p ())
58 #define IS_MMIX_EH_RETURN_DATA_REG(REGNO) \
59 (current_function_calls_eh_return \
60 && (EH_RETURN_DATA_REGNO (0) == REGNO \
61 || EH_RETURN_DATA_REGNO (1) == REGNO \
62 || EH_RETURN_DATA_REGNO (2) == REGNO \
63 || EH_RETURN_DATA_REGNO (3) == REGNO))
65 /* For the default ABI, we rename registers at output-time to fill the gap
66 between the (statically partitioned) saved registers and call-clobbered
67 registers. In effect this makes unused call-saved registers to be used
68 as call-clobbered registers. The benefit comes from keeping the number
69 of local registers (value of rL) low, since there's a cost of
70 increasing rL and clearing unused (unset) registers with lower numbers. */
71 #define MMIX_OUTPUT_REGNO(N) \
73 || (N) < MMIX_RETURN_VALUE_REGNUM \
74 || (N) > MMIX_LAST_STACK_REGISTER_REGNUM \
75 ? (N) : ((N) - MMIX_RETURN_VALUE_REGNUM \
76 + cfun->machine->highest_saved_stack_register + 1))
78 /* The canonical saved comparison operands for non-cc0 machines, set in
79 the compare expander. */
83 /* We ignore some options with arguments. They are passed to the linker,
84 but also ends up here because they start with "-m". We tell the driver
85 to store them in a variable we don't inspect. */
86 const char *mmix_cc1_ignored_option;
88 /* Declarations of locals. */
90 /* Intermediate for insn output. */
91 static int mmix_output_destination_register;
93 static void mmix_output_shiftvalue_op_from_str
94 PARAMS ((FILE *, const char *, HOST_WIDEST_INT));
95 static void mmix_output_shifted_value PARAMS ((FILE *, HOST_WIDEST_INT));
96 static void mmix_output_condition PARAMS ((FILE *, rtx, int));
97 static HOST_WIDEST_INT mmix_intval PARAMS ((rtx));
98 static void mmix_output_octa PARAMS ((FILE *, HOST_WIDEST_INT, int));
99 static bool mmix_assemble_integer PARAMS ((rtx, unsigned int, int));
100 static void mmix_init_machine_status PARAMS ((struct function *));
101 static void mmix_encode_section_info PARAMS ((tree, int));
103 extern void mmix_target_asm_function_prologue
104 PARAMS ((FILE *, HOST_WIDE_INT));
105 extern void mmix_target_asm_function_epilogue
106 PARAMS ((FILE *, HOST_WIDE_INT));
109 /* Target structure macros. Listed by node. See `Using and Porting GCC'
110 for a general description. */
112 /* Node: Function Entry */
114 #undef TARGET_ASM_BYTE_OP
115 #define TARGET_ASM_BYTE_OP NULL
116 #undef TARGET_ASM_ALIGNED_HI_OP
117 #define TARGET_ASM_ALIGNED_HI_OP NULL
118 #undef TARGET_ASM_ALIGNED_SI_OP
119 #define TARGET_ASM_ALIGNED_SI_OP NULL
120 #undef TARGET_ASM_ALIGNED_DI_OP
121 #define TARGET_ASM_ALIGNED_DI_OP NULL
122 #undef TARGET_ASM_INTEGER
123 #define TARGET_ASM_INTEGER mmix_assemble_integer
125 #undef TARGET_ASM_FUNCTION_PROLOGUE
126 #define TARGET_ASM_FUNCTION_PROLOGUE mmix_target_asm_function_prologue
128 #undef TARGET_ASM_FUNCTION_EPILOGUE
129 #define TARGET_ASM_FUNCTION_EPILOGUE mmix_target_asm_function_epilogue
131 #undef TARGET_ENCODE_SECTION_INFO
132 #define TARGET_ENCODE_SECTION_INFO mmix_encode_section_info
134 struct gcc_target targetm = TARGET_INITIALIZER;
136 /* Functions that are expansions for target macros.
137 See Target Macros in `Using and Porting GCC'. */
139 /* OVERRIDE_OPTIONS. */
142 mmix_override_options ()
144 /* Should we err or should we warn? Hmm. At least we must neutralize
145 it. For example the wrong kind of case-tables will be generated with
146 PIC; we use absolute address items for mmixal compatibility. FIXME:
147 They could be relative if we just elide them to after all pertinent
151 warning ("-f%s not supported: ignored", (flag_pic > 1) ? "PIC" : "pic");
155 /* All other targets add GC roots from their override_options function,
157 ggc_add_rtx_root (&mmix_compare_op0, 1);
158 ggc_add_rtx_root (&mmix_compare_op1, 1);
161 /* INIT_EXPANDERS. */
164 mmix_init_expanders ()
166 init_machine_status = mmix_init_machine_status;
169 /* Set the per-function data. */
172 mmix_init_machine_status (f)
175 f->machine = xcalloc (1, sizeof (struct machine_function));
179 We have trouble getting the address of stuff that is located at other
180 than 32-bit alignments (GETA requirements), so try to give everything
181 at least 32-bit alignment. */
184 mmix_data_alignment (type, basic_align)
185 tree type ATTRIBUTE_UNUSED;
188 if (basic_align < 32)
194 /* CONSTANT_ALIGNMENT. */
197 mmix_constant_alignment (constant, basic_align)
198 tree constant ATTRIBUTE_UNUSED;
201 if (basic_align < 32)
207 /* LOCAL_ALIGNMENT. */
210 mmix_local_alignment (type, basic_align)
211 tree type ATTRIBUTE_UNUSED;
214 if (basic_align < 32)
220 /* CONDITIONAL_REGISTER_USAGE. */
223 mmix_conditional_register_usage ()
229 static const int gnu_abi_reg_alloc_order[]
230 = MMIX_GNU_ABI_REG_ALLOC_ORDER;
232 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
233 reg_alloc_order[i] = gnu_abi_reg_alloc_order[i];
235 /* Change the default from the mmixware ABI. For the GNU ABI,
236 $15..$30 are call-saved just as $0..$14. There must be one
237 call-clobbered local register for the "hole" describing number of
238 saved local registers saved by PUSHJ/PUSHGO during the function
239 call, receiving the return value at return. So best is to use
240 the highest, $31. It's already marked call-clobbered for the
242 for (i = 15; i <= 30; i++)
243 call_used_regs[i] = 0;
245 /* "Unfix" the parameter registers. */
246 for (i = MMIX_RESERVED_GNU_ARG_0_REGNUM;
247 i < MMIX_RESERVED_GNU_ARG_0_REGNUM + MMIX_MAX_ARGS_IN_REGS;
252 /* Step over the ":" in special register names. */
253 if (! TARGET_TOPLEVEL_SYMBOLS)
254 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
255 if (reg_names[i][0] == ':')
259 /* PREFERRED_RELOAD_CLASS.
260 We need to extend the reload class of REMAINDER_REG and HIMULT_REG. */
263 mmix_preferred_reload_class (x, class)
264 rtx x ATTRIBUTE_UNUSED;
265 enum reg_class class;
267 /* FIXME: Revisit. */
268 return GET_CODE (x) == MOD && GET_MODE (x) == DImode
269 ? REMAINDER_REG : class;
272 /* PREFERRED_OUTPUT_RELOAD_CLASS.
273 We need to extend the reload class of REMAINDER_REG and HIMULT_REG. */
276 mmix_preferred_output_reload_class (x, class)
277 rtx x ATTRIBUTE_UNUSED;
278 enum reg_class class;
280 /* FIXME: Revisit. */
281 return GET_CODE (x) == MOD && GET_MODE (x) == DImode
282 ? REMAINDER_REG : class;
285 /* SECONDARY_RELOAD_CLASS.
286 We need to reload regs of REMAINDER_REG and HIMULT_REG elsewhere. */
289 mmix_secondary_reload_class (class, mode, x, in_p)
290 enum reg_class class;
291 enum machine_mode mode ATTRIBUTE_UNUSED;
292 rtx x ATTRIBUTE_UNUSED;
293 int in_p ATTRIBUTE_UNUSED;
295 if (class == REMAINDER_REG
296 || class == HIMULT_REG
297 || class == SYSTEM_REGS)
303 /* CONST_OK_FOR_LETTER_P. */
306 mmix_const_ok_for_letter_p (value, c)
311 (c == 'I' ? value >= 0 && value <= 255
312 : c == 'J' ? value >= 0 && value <= 65535
313 : c == 'K' ? value <= 0 && value >= -255
314 : c == 'L' ? mmix_shiftable_wyde_value (value)
315 : c == 'M' ? value == 0
316 : c == 'N' ? mmix_shiftable_wyde_value (~value)
317 : c == 'O' ? (value == 3 || value == 5 || value == 9
322 /* CONST_DOUBLE_OK_FOR_LETTER_P. */
325 mmix_const_double_ok_for_letter_p (value, c)
330 (c == 'G' ? value == CONST0_RTX (GET_MODE (value))
335 We need this since our constants are not always expressible as
336 CONST_INT:s, but rather often as CONST_DOUBLE:s. */
339 mmix_extra_constraint (x, c, strict)
344 HOST_WIDEST_INT value;
346 /* When checking for an address, we need to handle strict vs. non-strict
347 register checks. Don't use address_operand, but instead its
348 equivalent (its callee, which it is just a wrapper for),
349 memory_operand_p and the strict-equivalent strict_memory_address_p. */
353 ? strict_memory_address_p (Pmode, x)
354 : memory_address_p (Pmode, x);
356 /* R asks whether x is to be loaded with GETA or something else. Right
357 now, only a SYMBOL_REF and LABEL_REF can fit for
358 TARGET_BASE_ADDRESSES.
360 Only constant symbolic addresses apply. With TARGET_BASE_ADDRESSES,
361 we just allow straight LABEL_REF or SYMBOL_REFs with SYMBOL_REF_FLAG
362 set right now; only function addresses and code labels. If we change
363 to let SYMBOL_REF_FLAG be set on other symbols, we have to check
364 inside CONST expressions. When TARGET_BASE_ADDRESSES is not in
365 effect, a "raw" constant check together with mmix_constant_address_p
366 is all that's needed; we want all constant addresses to be loaded
370 GET_CODE (x) != CONST_INT && GET_CODE (x) != CONST_DOUBLE
371 && mmix_constant_address_p (x)
372 && (! TARGET_BASE_ADDRESSES
373 || (GET_CODE (x) == LABEL_REF
374 || (GET_CODE (x) == SYMBOL_REF && SYMBOL_REF_FLAG (x))));
376 if (GET_CODE (x) != CONST_DOUBLE || GET_MODE (x) != VOIDmode)
379 value = mmix_intval (x);
381 /* We used to map Q->J, R->K, S->L, T->N, U->O, but we don't have to any
382 more ('U' taken for address_operand, 'R' similarly). Some letters map
383 outside of CONST_INT, though; we still use 'S' and 'T'. */
385 return mmix_shiftable_wyde_value (value);
387 return mmix_shiftable_wyde_value (~value);
391 /* DYNAMIC_CHAIN_ADDRESS. */
394 mmix_dynamic_chain_address (frame)
397 /* FIXME: the frame-pointer is stored at offset -8 from the current
398 frame-pointer. Unfortunately, the caller assumes that a
399 frame-pointer is present for *all* previous frames. There should be
400 a way to say that that cannot be done, like for RETURN_ADDR_RTX. */
401 return plus_constant (frame, -8);
404 /* STARTING_FRAME_OFFSET. */
407 mmix_starting_frame_offset ()
409 /* The old frame pointer is in the slot below the new one, so
410 FIRST_PARM_OFFSET does not need to depend on whether the
411 frame-pointer is needed or not. We have to adjust for the register
412 stack pointer being located below the saved frame pointer.
413 Similarly, we store the return address on the stack too, for
414 exception handling, and always if we save the register stack pointer. */
417 + (MMIX_CFUN_HAS_LANDING_PAD
418 ? -16 : (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS ? -8 : 0)));
421 /* RETURN_ADDR_RTX. */
424 mmix_return_addr_rtx (count, frame)
426 rtx frame ATTRIBUTE_UNUSED;
429 ? (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
430 /* FIXME: Set frame_alias_set on the following. (Why?)
431 See mmix_initial_elimination_offset for the reason we can't use
432 get_hard_reg_initial_val for both. Always using a stack slot
433 and not a register would be suboptimal. */
434 ? validize_mem (gen_rtx_MEM (Pmode, plus_constant (frame_pointer_rtx, -16)))
435 : get_hard_reg_initial_val (Pmode, MMIX_INCOMING_RETURN_ADDRESS_REGNUM))
439 /* SETUP_FRAME_ADDRESSES. */
442 mmix_setup_frame_addresses ()
444 /* Nothing needed at the moment. */
447 /* The difference between the (imaginary) frame pointer and the stack
448 pointer. Used to eliminate the frame pointer. */
451 mmix_initial_elimination_offset (fromreg, toreg)
457 = (get_frame_size () + current_function_outgoing_args_size + 7) & ~7;
459 /* There is no actual offset between these two virtual values, but for
460 the frame-pointer, we have the old one in the stack position below
461 it, so the offset for the frame-pointer to the stack-pointer is one
463 if (fromreg == MMIX_ARG_POINTER_REGNUM
464 && toreg == MMIX_FRAME_POINTER_REGNUM)
467 /* The difference is the size of local variables plus the size of
468 outgoing function arguments that would normally be passed as
469 registers but must be passed on stack because we're out of
470 function-argument registers. Only global saved registers are
471 counted; the others go on the register stack.
473 The frame-pointer is counted too if it is what is eliminated, as we
474 need to balance the offset for it from STARTING_FRAME_OFFSET.
476 Also add in the slot for the register stack pointer we save if we
479 Unfortunately, we can't access $0..$14, from unwinder code easily, so
480 store the return address in a frame slot too. FIXME: Only for
481 non-leaf functions. FIXME: Always with a landing pad, because it's
482 hard to know whether we need the other at the time we know we need
483 the offset for one (and have to state it). It's a kludge until we
484 can express the register stack in the EH frame info.
486 We have to do alignment here; get_frame_size will not return a
487 multiple of STACK_BOUNDARY. FIXME: Add note in manual. */
489 for (regno = MMIX_FIRST_GLOBAL_REGNUM;
492 if ((regs_ever_live[regno] && ! call_used_regs[regno])
493 || IS_MMIX_EH_RETURN_DATA_REG (regno))
497 + (MMIX_CFUN_HAS_LANDING_PAD
498 ? 16 : (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS ? 8 : 0))
499 + (fromreg == MMIX_ARG_POINTER_REGNUM ? 0 : 8);
502 /* Return an rtx for a function argument to go in a register, and 0 for
503 one that must go on stack. */
506 mmix_function_arg (argsp, mode, type, named, incoming)
507 const CUMULATIVE_ARGS * argsp;
508 enum machine_mode mode;
510 int named ATTRIBUTE_UNUSED;
513 /* Handling of the positional dummy parameter for varargs gets nasty.
514 Check execute/991216-3 and function.c:assign_params. We have to say
515 that the dummy parameter goes on stack in order to get the correct
516 offset when va_start and va_arg is applied. FIXME: Should do TRT by
517 itself in the gcc core. */
518 if ((! named && incoming && current_function_varargs) || argsp->now_varargs)
521 /* Last-argument marker. */
522 if (type == void_type_node)
523 return (argsp->regs < MMIX_MAX_ARGS_IN_REGS)
526 ? MMIX_FIRST_INCOMING_ARG_REGNUM
527 : MMIX_FIRST_ARG_REGNUM) + argsp->regs)
530 return (argsp->regs < MMIX_MAX_ARGS_IN_REGS
531 && !MUST_PASS_IN_STACK (mode, type)
532 && (GET_MODE_BITSIZE (mode) <= 64
537 ? MMIX_FIRST_INCOMING_ARG_REGNUM
538 : MMIX_FIRST_ARG_REGNUM)
543 /* Returns nonzero for everything that goes by reference, 0 for
544 everything that goes by value. */
547 mmix_function_arg_pass_by_reference (argsp, mode, type, named)
548 const CUMULATIVE_ARGS * argsp;
549 enum machine_mode mode;
551 int named ATTRIBUTE_UNUSED;
553 /* FIXME: Check: I'm not sure the MUST_PASS_IN_STACK check is
556 MUST_PASS_IN_STACK (mode, type)
557 || (MMIX_FUNCTION_ARG_SIZE (mode, type) > 8
562 /* Return nonzero if regno is a register number where a parameter is
563 passed, and 0 otherwise. */
566 mmix_function_arg_regno_p (regno, incoming)
571 = incoming ? MMIX_FIRST_INCOMING_ARG_REGNUM : MMIX_FIRST_ARG_REGNUM;
573 return regno >= first_arg_regnum
574 && regno < first_arg_regnum + MMIX_MAX_ARGS_IN_REGS;
577 /* FUNCTION_OUTGOING_VALUE. */
580 mmix_function_outgoing_value (valtype, func)
582 tree func ATTRIBUTE_UNUSED;
584 enum machine_mode mode = TYPE_MODE (valtype);
585 enum machine_mode cmode;
586 int first_val_regnum = MMIX_OUTGOING_RETURN_VALUE_REGNUM;
587 rtx vec[MMIX_MAX_REGS_FOR_VALUE];
591 /* Return values that fit in a register need no special handling.
592 There's no register hole when parameters are passed in global
595 || GET_MODE_BITSIZE (mode) <= BITS_PER_WORD)
597 gen_rtx_REG (mode, MMIX_OUTGOING_RETURN_VALUE_REGNUM);
599 /* A complex type, made up of components. */
600 cmode = TYPE_MODE (TREE_TYPE (valtype));
601 nregs = ((GET_MODE_BITSIZE (mode) + BITS_PER_WORD - 1) / BITS_PER_WORD);
603 /* We need to take care of the effect of the register hole on return
604 values of large sizes; the last register will appear as the first
605 register, with the rest shifted. (For complex modes, this is just
606 swapped registers.) */
608 if (nregs > MMIX_MAX_REGS_FOR_VALUE)
609 internal_error ("too large function value type, needs %d registers,\
610 have only %d registers for this", nregs, MMIX_MAX_REGS_FOR_VALUE);
612 /* FIXME: Maybe we should handle structure values like this too
613 (adjusted for BLKmode), perhaps for both ABI:s. */
614 for (i = 0; i < nregs - 1; i++)
616 = gen_rtx_EXPR_LIST (VOIDmode,
617 gen_rtx_REG (cmode, first_val_regnum + i),
618 GEN_INT ((i + 1) * BITS_PER_UNIT));
621 = gen_rtx_EXPR_LIST (VOIDmode,
622 gen_rtx_REG (cmode, first_val_regnum + nregs - 1),
625 return gen_rtx_PARALLEL (VOIDmode, gen_rtvec_v (nregs, vec));
628 /* EH_RETURN_DATA_REGNO. */
631 mmix_eh_return_data_regno (n)
632 int n ATTRIBUTE_UNUSED;
635 return MMIX_EH_RETURN_DATA_REGNO_START + n;
637 return INVALID_REGNUM;
640 /* EH_RETURN_STACKADJ_RTX. */
643 mmix_eh_return_stackadj_rtx ()
645 return gen_rtx_REG (Pmode, MMIX_EH_RETURN_STACKADJ_REGNUM);
648 /* EH_RETURN_HANDLER_RTX. */
651 mmix_eh_return_handler_rtx ()
654 gen_rtx_REG (Pmode, MMIX_INCOMING_RETURN_ADDRESS_REGNUM);
657 /* ASM_PREFERRED_EH_DATA_FORMAT. */
660 mmix_asm_preferred_eh_data_format (code, global)
661 int code ATTRIBUTE_UNUSED;
662 int global ATTRIBUTE_UNUSED;
664 /* This is the default (was at 2001-07-20). Revisit when needed. */
665 return DW_EH_PE_absptr;
668 /* Emit the function prologue. For simplicity while the port is still
669 in a flux, we do it as text rather than the now preferred RTL way,
670 as (define_insn "function_prologue").
672 FIXME: Translate to RTL and/or optimize some of the DWARF 2 stuff. */
675 mmix_target_asm_function_prologue (stream, locals_size)
677 HOST_WIDE_INT locals_size;
680 int stack_space_to_allocate
681 = (current_function_outgoing_args_size
682 + current_function_pretend_args_size
683 + (int) locals_size + 7) & ~7;
685 int doing_dwarf = dwarf2out_do_frame ();
688 /* Guard our assumptions. Very low priority FIXME. */
689 if (locals_size != (int) locals_size)
690 error ("stack frame too big");
692 /* Add room needed to save global non-register-stack registers. */
694 regno >= MMIX_FIRST_GLOBAL_REGNUM;
696 /* Note that we assume that the frame-pointer-register is one of these
697 registers, in which case we don't count it here. */
698 if ((((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
699 && regs_ever_live[regno] && !call_used_regs[regno]))
700 || IS_MMIX_EH_RETURN_DATA_REG (regno))
701 stack_space_to_allocate += 8;
703 /* If we do have a frame-pointer, add room for it. */
704 if (frame_pointer_needed)
705 stack_space_to_allocate += 8;
707 /* If we have a non-local label, we need to be able to unwind to it, so
708 store the current register stack pointer. Also store the return
709 address if we do that. */
710 if (MMIX_CFUN_HAS_LANDING_PAD)
711 stack_space_to_allocate += 16;
712 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
713 /* If we do have a saved return-address slot, add room for it. */
714 stack_space_to_allocate += 8;
716 /* Make sure we don't get an unaligned stack. */
717 if ((stack_space_to_allocate % 8) != 0)
718 internal_error ("stack frame not a multiple of 8 bytes: %d",
719 stack_space_to_allocate);
721 if (current_function_pretend_args_size)
723 int mmix_first_vararg_reg
724 = (MMIX_FIRST_INCOMING_ARG_REGNUM
725 + (MMIX_MAX_ARGS_IN_REGS
726 - current_function_pretend_args_size / 8));
729 = MMIX_FIRST_INCOMING_ARG_REGNUM + MMIX_MAX_ARGS_IN_REGS - 1;
730 regno >= mmix_first_vararg_reg;
736 = stack_space_to_allocate > (256 - 8)
737 ? (256 - 8) : stack_space_to_allocate;
739 fprintf (stream, "\tSUBU %s,%s,%d\n",
740 reg_names[MMIX_STACK_POINTER_REGNUM],
741 reg_names[MMIX_STACK_POINTER_REGNUM],
746 /* Each call to dwarf2out_def_cfa overrides the previous
747 setting; they don't accumulate. We must keep track
748 of the offset ourselves. */
749 cfa_offset += stack_chunk;
750 if (!frame_pointer_needed)
751 dwarf2out_def_cfa ("", MMIX_STACK_POINTER_REGNUM,
754 offset += stack_chunk;
755 stack_space_to_allocate -= stack_chunk;
758 fprintf (stream, "\tSTOU %s,%s,%d\n", reg_names[regno],
759 reg_names[MMIX_STACK_POINTER_REGNUM],
762 /* These registers aren't actually saved (as in "will be
763 restored"), so don't tell DWARF2 they're saved. */
769 /* Store the frame-pointer. */
771 if (frame_pointer_needed)
775 /* Get 8 less than otherwise, since we need to reach offset + 8. */
777 = stack_space_to_allocate > (256 - 8 - 8)
778 ? (256 - 8 - 8) : stack_space_to_allocate;
780 fprintf (stream, "\tSUBU %s,%s,%d\n",
781 reg_names[MMIX_STACK_POINTER_REGNUM],
782 reg_names[MMIX_STACK_POINTER_REGNUM],
785 cfa_offset += stack_chunk;
786 offset += stack_chunk;
787 stack_space_to_allocate -= stack_chunk;
790 fprintf (stream, "\tSTOU %s,%s,%d\n\tADDU %s,%s,%d\n",
791 reg_names[MMIX_FRAME_POINTER_REGNUM],
792 reg_names[MMIX_STACK_POINTER_REGNUM],
794 reg_names[MMIX_FRAME_POINTER_REGNUM],
795 reg_names[MMIX_STACK_POINTER_REGNUM],
799 /* If we're using the frame-pointer, then we just need this CFA
800 definition basing on that value (often equal to the CFA).
801 Further changes to the stack-pointer do not affect the
802 frame-pointer, so we conditionalize them below on
803 !frame_pointer_needed. */
804 dwarf2out_def_cfa ("", MMIX_FRAME_POINTER_REGNUM,
805 -cfa_offset + offset + 8);
807 dwarf2out_reg_save ("", MMIX_FRAME_POINTER_REGNUM,
808 -cfa_offset + offset);
814 if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
816 /* Store the return-address, if one is needed on the stack. We
817 usually store it in a register when needed, but that doesn't work
818 with -fexceptions. */
822 /* Get 8 less than otherwise, since we need to reach offset + 8. */
824 = stack_space_to_allocate > (256 - 8 - 8)
825 ? (256 - 8 - 8) : stack_space_to_allocate;
827 fprintf (stream, "\tSUBU %s,%s,%d\n",
828 reg_names[MMIX_STACK_POINTER_REGNUM],
829 reg_names[MMIX_STACK_POINTER_REGNUM],
833 cfa_offset += stack_chunk;
834 if (!frame_pointer_needed)
835 dwarf2out_def_cfa ("", MMIX_STACK_POINTER_REGNUM,
838 offset += stack_chunk;
839 stack_space_to_allocate -= stack_chunk;
842 fprintf (stream, "\tGET $255,rJ\n\tSTOU $255,%s,%d\n",
843 reg_names[MMIX_STACK_POINTER_REGNUM],
846 dwarf2out_return_save ("", -cfa_offset + offset);
849 else if (MMIX_CFUN_HAS_LANDING_PAD)
852 if (MMIX_CFUN_HAS_LANDING_PAD)
854 /* Store the register defining the numbering of local registers, so
855 we know how long to unwind the register stack. */
859 /* Get 8 less than otherwise, since we need to reach offset + 8. */
861 = stack_space_to_allocate > (256 - 8 - 8)
862 ? (256 - 8 - 8) : stack_space_to_allocate;
864 fprintf (stream, "\tSUBU %s,%s,%d\n",
865 reg_names[MMIX_STACK_POINTER_REGNUM],
866 reg_names[MMIX_STACK_POINTER_REGNUM],
868 offset += stack_chunk;
869 stack_space_to_allocate -= stack_chunk;
873 cfa_offset += stack_chunk;
874 if (!frame_pointer_needed)
875 dwarf2out_def_cfa ("", MMIX_STACK_POINTER_REGNUM,
880 /* We don't tell dwarf2 about this one; we just have it to unwind
881 the register stack at landing pads. FIXME: It's a kludge because
882 we can't describe the effect of the PUSHJ and PUSHGO insns on the
883 register stack at the moment. Best thing would be to handle it
884 like stack-pointer offsets. Better: some hook into dwarf2out.c
885 to produce DW_CFA_expression:s that specify the increment of rO,
886 and unwind it at eh_return (preferred) or at the landing pad.
887 Then saves to $0..$G-1 could be specified through that register. */
889 fprintf (stream, "\tGET $255,rO\n\tSTOU $255,%s,%d\n",
890 reg_names[MMIX_STACK_POINTER_REGNUM], offset);
895 /* After the return-address and the frame-pointer, we have the local
896 variables. They're the ones that may have an "unaligned" size. */
897 offset -= (locals_size + 7) & ~7;
899 /* Now store all registers that are global, i.e. not saved by the
900 register file machinery.
902 It is assumed that the frame-pointer is one of these registers, so it
903 is explicitly excluded in the count. */
906 regno >= MMIX_FIRST_GLOBAL_REGNUM;
908 if (((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
909 && regs_ever_live[regno] && ! call_used_regs[regno])
910 || IS_MMIX_EH_RETURN_DATA_REG (regno))
916 /* Since the local variables go above, we may get a large
920 /* We're not going to access the locals area in the
921 prologue, so we'll just silently subtract the slab we
924 stack_space_to_allocate > (256 - offset - 8)
925 ? (256 - offset - 8) : stack_space_to_allocate;
927 mmix_output_register_setting (stream, 255, stack_chunk, 1);
928 fprintf (stream, "\tSUBU %s,%s,$255\n",
929 reg_names[MMIX_STACK_POINTER_REGNUM],
930 reg_names[MMIX_STACK_POINTER_REGNUM]);
934 cfa_offset += stack_chunk;
935 if (!frame_pointer_needed)
936 dwarf2out_def_cfa ("", MMIX_STACK_POINTER_REGNUM,
942 stack_chunk = stack_space_to_allocate > (256 - 8)
943 ? (256 - 8) : stack_space_to_allocate;
945 fprintf (stream, "\tSUBU %s,%s,%d\n",
946 reg_names[MMIX_STACK_POINTER_REGNUM],
947 reg_names[MMIX_STACK_POINTER_REGNUM], stack_chunk);
950 cfa_offset += stack_chunk;
951 if (!frame_pointer_needed)
952 dwarf2out_def_cfa ("", MMIX_STACK_POINTER_REGNUM,
957 offset += stack_chunk;
958 stack_space_to_allocate -= stack_chunk;
961 fprintf (stream, "\tSTOU %s,%s,%d\n", reg_names[regno],
962 reg_names[MMIX_STACK_POINTER_REGNUM], offset);
964 dwarf2out_reg_save ("", regno, -cfa_offset + offset);
968 /* Finally, allocate room for outgoing args and local vars if room
969 wasn't allocated above. This might be any number of bytes (well, we
970 assume it fits in a host-int). */
971 if (stack_space_to_allocate)
973 if (stack_space_to_allocate < 256)
975 fprintf (stream, "\tSUBU %s,%s,%d\n",
976 reg_names[MMIX_STACK_POINTER_REGNUM],
977 reg_names[MMIX_STACK_POINTER_REGNUM],
978 stack_space_to_allocate);
982 mmix_output_register_setting (stream, 255,
983 stack_space_to_allocate, 1);
984 fprintf (stream, "\tSUBU %s,%s,$255\n",
985 reg_names[MMIX_STACK_POINTER_REGNUM],
986 reg_names[MMIX_STACK_POINTER_REGNUM]);
991 cfa_offset += stack_space_to_allocate;
992 if (!frame_pointer_needed)
993 dwarf2out_def_cfa ("", MMIX_STACK_POINTER_REGNUM,
999 /* MACHINE_DEPENDENT_REORG.
1000 No actual rearrangements done here; just virtually by calculating the
1001 highest saved stack register number used to modify the register numbers
1005 mmix_machine_dependent_reorg (first)
1006 rtx first ATTRIBUTE_UNUSED;
1010 /* We put the number of the highest saved register-file register in a
1011 location convenient for the call-patterns to output. Note that we
1012 don't tell dwarf2 about these registers, since it can't restore them
1014 for (regno = MMIX_LAST_STACK_REGISTER_REGNUM;
1017 if ((regs_ever_live[regno] && !call_used_regs[regno])
1018 || (regno == MMIX_FRAME_POINTER_REGNUM && frame_pointer_needed))
1021 /* Regardless of whether they're saved (they might be just read), we
1022 mustn't include registers that carry parameters. We could scan the
1023 insns to see whether they're actually used (and indeed do other less
1024 trivial register usage analysis and transformations), but it seems
1025 wasteful to optimize for unused parameter registers. As of
1026 2002-04-30, regs_ever_live[n] seems to be set for only-reads too, but
1027 that might change. */
1028 if (!TARGET_ABI_GNU && regno < current_function_args_info.regs - 1)
1030 regno = current_function_args_info.regs - 1;
1032 /* We don't want to let this cause us to go over the limit and make
1033 incoming parameter registers be misnumbered and treating the last
1034 parameter register and incoming return value register call-saved.
1035 Stop things at the unmodified scheme. */
1036 if (regno > MMIX_RETURN_VALUE_REGNUM - 1)
1037 regno = MMIX_RETURN_VALUE_REGNUM - 1;
1040 cfun->machine->highest_saved_stack_register = regno;
1043 /* TARGET_ASM_FUNCTION_EPILOGUE. */
1046 mmix_target_asm_function_epilogue (stream, locals_size)
1048 HOST_WIDE_INT locals_size;
1052 int stack_space_to_deallocate
1053 = (current_function_outgoing_args_size
1054 + current_function_pretend_args_size
1055 + (int) locals_size + 7) & ~7;
1057 /* The assumption that locals_size fits in an int is asserted in
1058 mmix_target_asm_function_prologue. */
1060 /* The first address to access is beyond the outgoing_args area. */
1061 int offset = current_function_outgoing_args_size;
1063 /* Add the space for global non-register-stack registers.
1064 It is assumed that the frame-pointer register can be one of these
1065 registers, in which case it is excluded from the count when needed. */
1067 regno >= MMIX_FIRST_GLOBAL_REGNUM;
1069 if (((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
1070 && regs_ever_live[regno] && !call_used_regs[regno])
1071 || IS_MMIX_EH_RETURN_DATA_REG (regno))
1072 stack_space_to_deallocate += 8;
1074 /* Add in the space for register stack-pointer. If so, always add room
1075 for the saved PC. */
1076 if (MMIX_CFUN_HAS_LANDING_PAD)
1077 stack_space_to_deallocate += 16;
1078 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
1079 /* If we have a saved return-address slot, add it in. */
1080 stack_space_to_deallocate += 8;
1082 /* Add in the frame-pointer. */
1083 if (frame_pointer_needed)
1084 stack_space_to_deallocate += 8;
1086 /* Make sure we don't get an unaligned stack. */
1087 if ((stack_space_to_deallocate % 8) != 0)
1088 internal_error ("stack frame not a multiple of octabyte: %d",
1089 stack_space_to_deallocate);
1091 /* We will add back small offsets to the stack pointer as we go.
1092 First, we restore all registers that are global, i.e. not saved by
1093 the register file machinery. */
1095 for (regno = MMIX_FIRST_GLOBAL_REGNUM;
1098 if (((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
1099 && regs_ever_live[regno] && !call_used_regs[regno])
1100 || IS_MMIX_EH_RETURN_DATA_REG (regno))
1106 /* There's better support for incrementing than
1107 decrementing, so we might be able to optimize this as
1109 mmix_output_register_setting (stream, 255, offset, 1);
1110 fprintf (stream, "\tADDU %s,%s,$255\n",
1111 reg_names[MMIX_STACK_POINTER_REGNUM],
1112 reg_names[MMIX_STACK_POINTER_REGNUM]);
1115 fprintf (stream, "\tINCL %s,%d\n",
1116 reg_names[MMIX_STACK_POINTER_REGNUM], offset);
1118 stack_space_to_deallocate -= offset;
1122 fprintf (stream, "\tLDOU %s,%s,%d\n",
1124 reg_names[MMIX_STACK_POINTER_REGNUM],
1129 /* Here is where the local variables were. As in the prologue, they
1130 might be of an unaligned size. */
1131 offset += (locals_size + 7) & ~7;
1134 /* The saved register stack pointer is just below the frame-pointer
1135 register. We don't need to restore it "manually"; the POP
1136 instruction does that. */
1137 if (MMIX_CFUN_HAS_LANDING_PAD)
1139 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
1140 /* The return-address slot is just below the frame-pointer register.
1141 We don't need to restore it because we don't really use it. */
1144 /* Get back the old frame-pointer-value. */
1145 if (frame_pointer_needed)
1151 /* There's better support for incrementing than
1152 decrementing, so we might be able to optimize this as
1154 mmix_output_register_setting (stream, 255, offset, 1);
1155 fprintf (stream, "\tADDU %s,%s,$255\n",
1156 reg_names[MMIX_STACK_POINTER_REGNUM],
1157 reg_names[MMIX_STACK_POINTER_REGNUM]);
1160 fprintf (stream, "\tINCL %s,%d\n",
1161 reg_names[MMIX_STACK_POINTER_REGNUM], offset);
1163 stack_space_to_deallocate -= offset;
1167 fprintf (stream, "\tLDOU %s,%s,%d\n",
1168 reg_names[MMIX_FRAME_POINTER_REGNUM],
1169 reg_names[MMIX_STACK_POINTER_REGNUM],
1174 /* We do not need to restore pretended incoming args, just add back
1176 if (stack_space_to_deallocate > 65535)
1178 /* There's better support for incrementing than decrementing, so
1179 we might be able to optimize this as we see a need. */
1180 mmix_output_register_setting (stream, 255,
1181 stack_space_to_deallocate, 1);
1182 fprintf (stream, "\tADDU %s,%s,$255\n",
1183 reg_names[MMIX_STACK_POINTER_REGNUM],
1184 reg_names[MMIX_STACK_POINTER_REGNUM]);
1186 else if (stack_space_to_deallocate != 0)
1187 fprintf (stream, "\tINCL %s,%d\n",
1188 reg_names[MMIX_STACK_POINTER_REGNUM],
1189 stack_space_to_deallocate);
1191 if (current_function_calls_eh_return)
1192 /* Adjustment the (normal) stack-pointer to that of the receiver.
1193 FIXME: It would be nice if we could also adjust the register stack
1194 here, but we need to express it through DWARF 2 too. */
1195 fprintf (stream, "\tADDU %s,%s,%s\n",
1196 reg_names [MMIX_STACK_POINTER_REGNUM],
1197 reg_names [MMIX_STACK_POINTER_REGNUM],
1198 reg_names [MMIX_EH_RETURN_STACKADJ_REGNUM]);
1200 /* The extra \n is so we have a blank line between the assembly code of
1201 separate functions. */
1202 fprintf (stream, "\tPOP %d,0\n\n",
1204 && current_function_return_rtx != NULL
1205 && ! current_function_returns_struct)
1206 ? (GET_CODE (current_function_return_rtx) == PARALLEL
1207 ? GET_NUM_ELEM (XVEC (current_function_return_rtx, 0)) : 1)
1211 /* ASM_OUTPUT_MI_THUNK. */
1214 mmix_asm_output_mi_thunk (stream, fndecl, delta, func)
1216 tree fndecl ATTRIBUTE_UNUSED;
1220 /* If you define STRUCT_VALUE to 0, rather than use STRUCT_VALUE_REGNUM,
1221 (i.e. pass location of structure to return as invisible first
1222 argument) you need to tweak this code too. */
1223 const char *regname = reg_names[MMIX_FIRST_INCOMING_ARG_REGNUM];
1225 if (delta >= 0 && delta < 65536)
1226 asm_fprintf (stream, "\tINCL %s,%d\n", delta, regname);
1227 else if (delta < 0 && delta >= -255)
1228 asm_fprintf (stream, "\tSUBU %s,%s,%d\n", regname, regname, -delta);
1231 mmix_output_register_setting (stream, 255, delta, 1);
1232 asm_fprintf (stream, "\tADDU %s,%s,$255\n", regname, regname);
1235 fprintf (stream, "\tJMP ");
1236 assemble_name (stream, XSTR (XEXP (DECL_RTL (func), 0), 0));
1237 fprintf (stream, "\n");
1240 /* FUNCTION_PROFILER. */
1243 mmix_function_profiler (stream, labelno)
1244 FILE *stream ATTRIBUTE_UNUSED;
1245 int labelno ATTRIBUTE_UNUSED;
1247 sorry ("function_profiler support for MMIX");
1250 /* SETUP_INCOMING_VARARGS. */
1253 mmix_setup_incoming_varargs (args_so_farp, mode, vartype, pretend_sizep,
1255 CUMULATIVE_ARGS * args_so_farp;
1256 enum machine_mode mode;
1258 int * pretend_sizep;
1259 int second_time ATTRIBUTE_UNUSED;
1261 /* For stdarg, the last named variable has been handled, but
1262 args_so_farp has not been advanced for it. For varargs, the current
1263 argument is to be counted to the anonymous ones. */
1264 if (current_function_stdarg)
1266 if (args_so_farp->regs + 1 < MMIX_MAX_ARGS_IN_REGS)
1268 = (MMIX_MAX_ARGS_IN_REGS - (args_so_farp->regs + 1)) * 8;
1270 else if (current_function_varargs)
1272 if (args_so_farp->regs < MMIX_MAX_ARGS_IN_REGS)
1274 = (MMIX_MAX_ARGS_IN_REGS - args_so_farp->regs) * 8;
1276 /* For varargs, we get here when we see the last named parameter,
1277 which will actually be passed on stack. So make the next call
1278 (there will be one) to FUNCTION_ARG return 0, to count it on
1279 stack, so va_arg for it will get right. FIXME: The GCC core
1280 should provide TRT. */
1281 args_so_farp->now_varargs = 1;
1284 internal_error ("neither varargs or stdarg in mmix_setup_incoming_varargs");
1287 /* We assume that one argument takes up one register here. That should
1288 be true until we start messing with multi-reg parameters. */
1289 if ((7 + (MMIX_FUNCTION_ARG_SIZE (mode, vartype))) / 8 != 1)
1290 internal_error ("MMIX Internal: Last named vararg would not fit in a register");
1293 /* EXPAND_BUILTIN_VA_ARG. */
1295 /* This is modified from the "standard" implementation of va_arg: read the
1296 value from the current (padded) address and increment by the (padded)
1297 size. The difference for MMIX is that if the type is
1298 pass-by-reference, then perform an indirection. */
1301 mmix_expand_builtin_va_arg (valist, type)
1305 tree ptr_size = size_int (BITS_PER_WORD / BITS_PER_UNIT);
1306 tree addr_tree, type_size = NULL;
1307 tree align, alignm1;
1311 /* Compute the rounded size of the type. */
1315 align = size_int (PARM_BOUNDARY / BITS_PER_UNIT);
1316 alignm1 = size_int (PARM_BOUNDARY / BITS_PER_UNIT - 1);
1317 if (type == error_mark_node
1318 || (type_size = TYPE_SIZE_UNIT (TYPE_MAIN_VARIANT (type))) == NULL
1319 || TREE_OVERFLOW (type_size))
1320 /* Presumably an error; the size isn't computable. A message has
1321 supposedly been emitted elsewhere. */
1322 rounded_size = size_zero_node;
1324 rounded_size = fold (build (MULT_EXPR, sizetype,
1325 fold (build (TRUNC_DIV_EXPR, sizetype,
1326 fold (build (PLUS_EXPR, sizetype,
1327 type_size, alignm1)),
1331 if (AGGREGATE_TYPE_P (type)
1332 && GET_MODE_UNIT_SIZE (TYPE_MODE (type)) < 8
1333 && GET_MODE_UNIT_SIZE (TYPE_MODE (type)) != 0)
1335 /* Adjust for big-endian the location of aggregates passed in a
1336 register, but where the aggregate is accessed in a shorter mode
1337 than the natural register mode (i.e. it is accessed as SFmode(?),
1338 SImode, HImode or QImode rather than DImode or DFmode(?)). FIXME:
1339 Or should we adjust the mode in which the aggregate is read, to be
1340 a register size mode? (Hum, nah, a small offset is generally
1341 cheaper than a wider memory access on MMIX.) */
1343 = build (PLUS_EXPR, TREE_TYPE (addr_tree), addr_tree,
1344 size_int ((BITS_PER_WORD / BITS_PER_UNIT)
1345 - GET_MODE_UNIT_SIZE (TYPE_MODE (type))));
1347 else if (!integer_zerop (rounded_size))
1349 if (!really_constant_p (type_size))
1350 /* Varying-size types come in by reference. */
1352 = build1 (INDIRECT_REF, build_pointer_type (type), addr_tree);
1355 /* If the size is less than a register, then we need to pad the
1356 address by adding the difference. */
1358 = fold (build (COND_EXPR, sizetype,
1359 fold (build (GT_EXPR, sizetype,
1363 fold (build (MINUS_EXPR, sizetype,
1367 = fold (build (PLUS_EXPR, TREE_TYPE (addr_tree), addr_tree,
1370 /* If this type is larger than what fits in a register, then it
1371 is passed by reference. */
1373 = fold (build (COND_EXPR, TREE_TYPE (addr_tree1),
1374 fold (build (GT_EXPR, sizetype,
1377 build1 (INDIRECT_REF, build_pointer_type (type),
1383 addr = expand_expr (addr_tree, NULL_RTX, Pmode, EXPAND_NORMAL);
1384 addr = copy_to_reg (addr);
1386 if (!integer_zerop (rounded_size))
1388 /* Compute new value for AP. For MMIX, it is always advanced by the
1389 size of a register. */
1390 tree t = build (MODIFY_EXPR, TREE_TYPE (valist), valist,
1391 build (PLUS_EXPR, TREE_TYPE (valist), valist,
1393 TREE_SIDE_EFFECTS (t) = 1;
1394 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
1400 /* TRAMPOLINE_SIZE. */
1401 /* Four 4-byte insns plus two 8-byte values. */
1402 int mmix_trampoline_size = 32;
1405 /* TRAMPOLINE_TEMPLATE. */
1408 mmix_trampoline_template (stream)
1411 /* Read a value into the static-chain register and jump somewhere. The
1412 static chain is stored at offset 16, and the function address is
1413 stored at offset 24. */
1414 /* FIXME: GCC copies this using *intsize* (tetra), when it should use
1415 register size (octa). */
1416 fprintf (stream, "\tGETA $255,1F\n\t");
1417 fprintf (stream, "LDOU %s,$255,0\n\t",
1418 reg_names[MMIX_STATIC_CHAIN_REGNUM]);
1419 fprintf (stream, "LDOU $255,$255,8\n\t");
1420 fprintf (stream, "GO $255,$255,0\n");
1421 fprintf (stream, "1H\tOCTA 0\n\t");
1422 fprintf (stream, "OCTA 0\n");
1425 /* INITIALIZE_TRAMPOLINE. */
1426 /* Set the static chain and function pointer field in the trampoline.
1427 We also SYNCID here to be sure (doesn't matter in the simulator, but
1428 some day it will). */
1431 mmix_initialize_trampoline (trampaddr, fnaddr, static_chain)
1436 emit_move_insn (gen_rtx_MEM (DImode, plus_constant (trampaddr, 16)),
1438 emit_move_insn (gen_rtx_MEM (DImode,
1439 plus_constant (trampaddr, 24)),
1441 emit_insn (gen_sync_icache (validize_mem (gen_rtx_MEM (DImode,
1443 GEN_INT (mmix_trampoline_size - 1)));
1446 /* We must exclude constant addresses that have an increment that is not a
1447 multiple of four bytes because of restrictions of the GETA
1448 instruction, unless TARGET_BASE_ADDRESSES. */
1451 mmix_constant_address_p (x)
1454 RTX_CODE code = GET_CODE (x);
1456 /* When using "base addresses", anything constant goes. */
1457 int constant_ok = TARGET_BASE_ADDRESSES != 0;
1459 if (code == LABEL_REF || code == SYMBOL_REF)
1462 if (code == CONSTANT_P_RTX || code == HIGH)
1463 /* FIXME: Don't know how to dissect these. Avoid them for now. */
1472 case CONSTANT_P_RTX:
1474 /* FIXME: Don't know how to dissect these. Avoid them for now,
1475 except we know they're constants. */
1479 addend = INTVAL (x);
1483 if (GET_MODE (x) != VOIDmode)
1484 /* Strange that we got here. FIXME: Check if we do. */
1486 addend = CONST_DOUBLE_LOW (x);
1490 /* Note that expressions with arithmetic on forward references don't
1491 work in mmixal. People using gcc assembly code with mmixal might
1492 need to move arrays and such to before the point of use. */
1493 if (GET_CODE (XEXP (x, 0)) == PLUS)
1495 rtx x0 = XEXP (XEXP (x, 0), 0);
1496 rtx x1 = XEXP (XEXP (x, 0), 1);
1498 if ((GET_CODE (x0) == SYMBOL_REF
1499 || GET_CODE (x0) == LABEL_REF)
1500 && (GET_CODE (x1) == CONST_INT
1501 || (GET_CODE (x1) == CONST_DOUBLE
1502 && GET_MODE (x1) == VOIDmode)))
1503 addend = mmix_intval (x1);
1515 return constant_ok || (addend & 3) == 0;
1518 /* Return 1 if the address is OK, otherwise 0.
1519 Used by GO_IF_LEGITIMATE_ADDRESS. */
1522 mmix_legitimate_address (mode, x, strict_checking)
1523 enum machine_mode mode ATTRIBUTE_UNUSED;
1525 int strict_checking;
1527 #define MMIX_REG_OK(X) \
1529 && (REGNO (X) <= MMIX_LAST_GENERAL_REGISTER \
1530 || (reg_renumber[REGNO (X)] > 0 \
1531 && reg_renumber[REGNO (X)] <= MMIX_LAST_GENERAL_REGISTER))) \
1532 || (!strict_checking \
1533 && (REGNO (X) <= MMIX_LAST_GENERAL_REGISTER \
1534 || REGNO (X) >= FIRST_PSEUDO_REGISTER \
1535 || REGNO (X) == ARG_POINTER_REGNUM)))
1539 (mem (plus reg reg))
1540 (mem (plus reg 0..255)).
1541 unless TARGET_BASE_ADDRESSES, in which case we accept all
1542 (mem constant_address) too. */
1546 if (REG_P (x) && MMIX_REG_OK (x))
1549 if (GET_CODE(x) == PLUS)
1551 rtx x1 = XEXP (x, 0);
1552 rtx x2 = XEXP (x, 1);
1554 /* Try swapping the order. FIXME: Do we need this? */
1562 /* (mem (plus (reg?) (?))) */
1563 if (!REG_P (x1) || !MMIX_REG_OK (x1))
1564 return TARGET_BASE_ADDRESSES && mmix_constant_address_p (x);
1566 /* (mem (plus (reg) (reg?))) */
1567 if (REG_P (x2) && MMIX_REG_OK (x2))
1570 /* (mem (plus (reg) (0..255?))) */
1571 if (GET_CODE (x2) == CONST_INT
1572 && CONST_OK_FOR_LETTER_P (INTVAL (x2), 'I'))
1578 return TARGET_BASE_ADDRESSES && mmix_constant_address_p (x);
1581 /* LEGITIMATE_CONSTANT_P. */
1584 mmix_legitimate_constant_p (x)
1587 RTX_CODE code = GET_CODE (x);
1589 /* We must allow any number due to the way the cse passes works; if we
1590 do not allow any number here, general_operand will fail, and insns
1591 will fatally fail recognition instead of "softly". */
1592 if (code == CONST_INT || code == CONST_DOUBLE)
1595 return CONSTANT_ADDRESS_P (x);
1598 /* SELECT_CC_MODE. */
1601 mmix_select_cc_mode (op, x, y)
1604 rtx y ATTRIBUTE_UNUSED;
1606 /* We use CCmode, CC_UNSmode, CC_FPmode, CC_FPEQmode and CC_FUNmode to
1607 output different compare insns. Note that we do not check the
1608 validity of the comparison here. */
1610 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1612 if (op == ORDERED || op == UNORDERED || op == UNGE
1613 || op == UNGT || op == UNLE || op == UNLT)
1616 if (op == EQ || op == NE)
1622 if (op == GTU || op == LTU || op == GEU || op == LEU)
1628 /* CANONICALIZE_COMPARISON.
1629 FIXME: Check if the number adjustments trig. */
1632 mmix_canonicalize_comparison (codep, op0p, op1p)
1634 rtx * op0p ATTRIBUTE_UNUSED;
1637 /* Change -1 to zero, if possible. */
1638 if ((*codep == LE || *codep == GT)
1639 && GET_CODE (*op1p) == CONST_INT
1640 && *op1p == constm1_rtx)
1642 *codep = *codep == LE ? LT : GE;
1646 /* Fix up 256 to 255, if possible. */
1647 if ((*codep == LT || *codep == LTU || *codep == GE || *codep == GEU)
1648 && GET_CODE (*op1p) == CONST_INT
1649 && INTVAL (*op1p) == 256)
1651 /* FIXME: Remove when I know this trigs. */
1652 fatal_insn ("oops, not debugged; fixing up value:", *op1p);
1653 *codep = *codep == LT ? LE : *codep == LTU ? LEU : *codep
1655 *op1p = GEN_INT (255);
1659 /* REVERSIBLE_CC_MODE. */
1662 mmix_reversible_cc_mode (mode)
1663 enum machine_mode mode;
1665 /* That is, all integer and the EQ, NE, ORDERED and UNORDERED float
1667 return mode != CC_FPmode;
1670 /* DEFAULT_RTX_COSTS. */
1673 mmix_rtx_cost_recalculated (x, code, outer_code, costp)
1674 rtx x ATTRIBUTE_UNUSED;
1675 RTX_CODE code ATTRIBUTE_UNUSED;
1676 RTX_CODE outer_code ATTRIBUTE_UNUSED;
1677 int *costp ATTRIBUTE_UNUSED;
1679 /* For the time being, this is just a stub and we'll accept the
1680 generic calculations, until we can do measurements, at least.
1681 Say we did not modify any calculated costs. */
1688 mmix_address_cost (addr)
1689 rtx addr ATTRIBUTE_UNUSED;
1691 /* There's no difference in the address costs and we have lots of
1692 registers. Some targets use constant 0, many others use 1 to say
1693 this. Let's start with 1. */
1697 /* REGISTER_MOVE_COST. */
1700 mmix_register_move_cost (mode, from, to)
1701 enum machine_mode mode ATTRIBUTE_UNUSED;
1702 enum reg_class from;
1705 return (from == GENERAL_REGS && from == to) ? 2 : 3;
1708 /* Note that we don't have a TEXT_SECTION_ASM_OP, because it has to be a
1709 compile-time constant; it's used in an asm in crtstuff.c, compiled for
1712 /* DATA_SECTION_ASM_OP. */
1715 mmix_data_section_asm_op ()
1717 return "\t.data ! mmixal:= 8H LOC 9B";
1721 mmix_encode_section_info (decl, first)
1725 /* Test for an external declaration, and do nothing if it is one. */
1726 if ((TREE_CODE (decl) == VAR_DECL
1727 && (DECL_EXTERNAL (decl) || TREE_PUBLIC (decl)))
1728 || (TREE_CODE (decl) == FUNCTION_DECL && TREE_PUBLIC (decl)))
1730 else if (first && DECL_P (decl))
1732 /* For non-visible declarations, add a "@" prefix, which we skip
1733 when the label is output. If the label does not have this
1734 prefix, a ":" is output if -mtoplevel-symbols.
1736 Note that this does not work for data that is declared extern and
1737 later defined as static. If there's code in between, that code
1738 will refer to the extern declaration, and vice versa. This just
1739 means that when -mtoplevel-symbols is in use, we can just handle
1740 well-behaved ISO-compliant code. */
1742 const char *str = XSTR (XEXP (DECL_RTL (decl), 0), 0);
1743 int len = strlen (str);
1746 /* Why is the return type of ggc_alloc_string const? */
1747 newstr = (char *) ggc_alloc_string ("", len + 1);
1749 strcpy (newstr + 1, str);
1751 XSTR (XEXP (DECL_RTL (decl), 0), 0) = newstr;
1754 /* Set SYMBOL_REF_FLAG for things that we want to access with GETA. We
1755 may need different options to reach for different things with GETA.
1756 For now, functions and things we know or have been told are constant. */
1757 if (TREE_CODE (decl) == FUNCTION_DECL
1758 || TREE_CONSTANT (decl)
1759 || (TREE_CODE (decl) == VAR_DECL
1760 && TREE_READONLY (decl)
1761 && !TREE_SIDE_EFFECTS (decl)
1762 && (!DECL_INITIAL (decl)
1763 || TREE_CONSTANT (DECL_INITIAL (decl)))))
1765 rtx rtl = (TREE_CODE_CLASS (TREE_CODE (decl)) != 'd'
1766 ? TREE_CST_RTL (decl) : DECL_RTL (decl));
1767 SYMBOL_REF_FLAG (XEXP (rtl, 0)) = 1;
1771 /* STRIP_NAME_ENCODING. */
1774 mmix_strip_name_encoding (name)
1777 for (; (*name == '@' || *name == '*'); name++)
1783 /* ASM_FILE_START. */
1786 mmix_asm_file_start (stream)
1789 /* We just emit a little comment for the time being. FIXME: Perhaps add
1790 -mstandalone and some segment and prefix setup here. */
1791 ASM_OUTPUT_SOURCE_FILENAME (stream, main_input_filename);
1793 fprintf (stream, "! mmixal:= 8H LOC Data_Section\n");
1795 /* Make sure each file starts with the text section. */
1802 mmix_asm_file_end (stream)
1803 FILE * stream ATTRIBUTE_UNUSED;
1805 /* Make sure each file ends with the data section. */
1809 /* ASM_OUTPUT_SOURCE_FILENAME. */
1812 mmix_asm_output_source_filename (stream, name)
1816 fprintf (stream, "# 1 ");
1817 OUTPUT_QUOTED_STRING (stream, name);
1818 fprintf (stream, "\n");
1821 /* OUTPUT_QUOTED_STRING. */
1824 mmix_output_quoted_string (stream, string, length)
1826 const char * string;
1829 const char * string_end = string + length;
1830 static const char *const unwanted_chars = "\"[]\\";
1832 /* Output "any character except newline and double quote character". We
1833 play it safe and avoid all control characters too. We also do not
1834 want [] as characters, should input be passed through m4 with [] as
1835 quotes. Further, we avoid "\", because the GAS port handles it as a
1836 quoting character. */
1837 while (string < string_end)
1840 && (unsigned char) *string < 128
1841 && !ISCNTRL (*string)
1842 && strchr (unwanted_chars, *string) == NULL)
1844 fputc ('"', stream);
1846 && (unsigned char) *string < 128
1847 && !ISCNTRL (*string)
1848 && strchr (unwanted_chars, *string) == NULL
1849 && string < string_end)
1851 fputc (*string, stream);
1854 fputc ('"', stream);
1855 if (string < string_end)
1856 fprintf (stream, ",");
1858 if (string < string_end)
1860 fprintf (stream, "#%x", *string & 255);
1862 if (string < string_end)
1863 fprintf (stream, ",");
1868 /* ASM_OUTPUT_SOURCE_LINE. */
1871 mmix_asm_output_source_line (stream, lineno)
1875 fprintf (stream, "# %d ", lineno);
1876 OUTPUT_QUOTED_STRING (stream, main_input_filename);
1877 fprintf (stream, "\n");
1880 /* Target hook for assembling integer objects. Use mmix_print_operand
1881 for WYDE and TETRA. Use mmix_output_octa to output 8-byte
1885 mmix_assemble_integer (x, size, aligned_p)
1893 /* We handle a limited number of types of operands in here. But
1894 that's ok, because we can punt to generic functions. We then
1895 pretend that aligned data isn't needed, so the usual .<pseudo>
1896 syntax is used (which works for aligned data too). We actually
1897 *must* do that, since we say we don't have simple aligned
1898 pseudos, causing this function to be called. We just try and
1899 keep as much compatibility as possible with mmixal syntax for
1900 normal cases (i.e. without GNU extensions and C only). */
1902 if (GET_CODE (x) != CONST_INT)
1907 fputs ("\tBYTE\t", asm_out_file);
1908 mmix_print_operand (asm_out_file, x, 'B');
1909 fputc ('\n', asm_out_file);
1913 if (GET_CODE (x) != CONST_INT)
1918 fputs ("\tWYDE\t", asm_out_file);
1919 mmix_print_operand (asm_out_file, x, 'W');
1920 fputc ('\n', asm_out_file);
1924 if (GET_CODE (x) != CONST_INT)
1929 fputs ("\tTETRA\t", asm_out_file);
1930 mmix_print_operand (asm_out_file, x, 'L');
1931 fputc ('\n', asm_out_file);
1935 if (GET_CODE (x) == CONST_DOUBLE)
1936 /* We don't get here anymore for CONST_DOUBLE, because DImode
1937 isn't expressed as CONST_DOUBLE, and DFmode is handled
1940 assemble_integer_with_op ("\tOCTA\t", x);
1943 return default_assemble_integer (x, size, aligned_p);
1946 /* ASM_OUTPUT_ASCII. */
1949 mmix_asm_output_ascii (stream, string, length)
1956 int chunk_size = length > 60 ? 60 : length;
1957 fprintf (stream, "\tBYTE ");
1958 mmix_output_quoted_string (stream, string, chunk_size);
1959 string += chunk_size;
1960 length -= chunk_size;
1961 fprintf (stream, "\n");
1965 /* ASM_OUTPUT_ALIGNED_COMMON. */
1968 mmix_asm_output_aligned_common (stream, name, size, align)
1974 /* This is mostly the elfos.h one. There doesn't seem to be a way to
1975 express this in a mmixal-compatible way. */
1976 fprintf (stream, "\t.comm\t");
1977 assemble_name (stream, name);
1978 fprintf (stream, ",%u,%u ! mmixal-incompatible COMMON\n",
1979 size, align / BITS_PER_UNIT);
1982 /* ASM_OUTPUT_ALIGNED_LOCAL. */
1985 mmix_asm_output_aligned_local (stream, name, size, align)
1993 ASM_OUTPUT_ALIGN (stream, exact_log2 (align/BITS_PER_UNIT));
1994 assemble_name (stream, name);
1995 fprintf (stream, "\tLOC @+%d\n", size);
1998 /* ASM_OUTPUT_LABEL. */
2001 mmix_asm_output_label (stream, name)
2005 assemble_name (stream, name);
2006 fprintf (stream, "\tIS @\n");
2009 /* ASM_DECLARE_REGISTER_GLOBAL. */
2012 mmix_asm_declare_register_global (stream, decl, regno, name)
2013 FILE *stream ATTRIBUTE_UNUSED;
2014 tree decl ATTRIBUTE_UNUSED;
2015 int regno ATTRIBUTE_UNUSED;
2016 const char *name ATTRIBUTE_UNUSED;
2018 /* Nothing to do here, but there *will* be, therefore the framework is
2022 /* ASM_GLOBALIZE_LABEL. */
2025 mmix_asm_globalize_label (stream, name)
2026 FILE * stream ATTRIBUTE_UNUSED;
2027 const char * name ATTRIBUTE_UNUSED;
2029 asm_fprintf (stream, "\t.global ");
2030 assemble_name (stream, name);
2031 putc ('\n', stream);
2034 /* ASM_WEAKEN_LABEL. */
2037 mmix_asm_weaken_label (stream, name)
2038 FILE * stream ATTRIBUTE_UNUSED;
2039 const char * name ATTRIBUTE_UNUSED;
2041 asm_fprintf (stream, "\t.weak ");
2042 assemble_name (stream, name);
2043 asm_fprintf (stream, " ! mmixal-incompatible\n");
2046 /* MAKE_DECL_ONE_ONLY. */
2049 mmix_make_decl_one_only (decl)
2052 DECL_WEAK (decl) = 1;
2055 /* ASM_OUTPUT_LABELREF.
2056 Strip GCC's '*' and our own '@'. No order is assumed. */
2059 mmix_asm_output_labelref (stream, name)
2065 for (; (*name == '@' || *name == '*'); name++)
2069 asm_fprintf (stream, "%s%U%s",
2070 is_extern && TARGET_TOPLEVEL_SYMBOLS ? ":" : "",
2074 /* ASM_OUTPUT_INTERNAL_LABEL. */
2077 mmix_asm_output_internal_label (stream, name, num)
2082 fprintf (stream, "%s:%d\tIS @\n", name, num);
2085 /* ASM_OUTPUT_DEF. */
2088 mmix_asm_output_def (stream, name, value)
2093 assemble_name (stream, name);
2094 fprintf (stream, "\tIS ");
2095 assemble_name (stream, value);
2096 fputc ('\n', stream);
2099 /* ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL. */
2102 mmix_asm_output_define_label_difference_symbol (stream, symbol, hi, lo)
2108 assemble_name (stream, symbol);
2109 fprintf (stream, "\tIS\t");
2110 assemble_name (stream, hi);
2111 fputc ('-', stream);
2112 assemble_name (stream, lo);
2113 fprintf (stream, "\n");
2116 /* PRINT_OPERAND. */
2119 mmix_print_operand (stream, x, code)
2124 /* When we add support for different codes later, we can, when needed,
2125 drop through to the main handler with a modified operand. */
2127 int regno = x != NULL_RTX && REG_P (x) ? REGNO (x) : 0;
2131 /* Unrelated codes are in alphabetic order. */
2134 /* For conditional branches, output "P" for a probable branch. */
2135 if (TARGET_BRANCH_PREDICT)
2137 x = find_reg_note (current_output_insn, REG_BR_PROB, 0);
2138 if (x && INTVAL (XEXP (x, 0)) > REG_BR_PROB_BASE / 2)
2144 if (GET_CODE (x) != CONST_INT)
2145 fatal_insn ("MMIX Internal: Expected a CONST_INT, not this", x);
2146 fprintf (stream, "%d", (int) (INTVAL (x) & 0xff));
2150 /* Highpart. Must be general register, and not the last one, as
2151 that one cannot be part of a consecutive register pair. */
2152 if (regno > MMIX_LAST_GENERAL_REGISTER - 1)
2153 internal_error ("MMIX Internal: Bad register: %d", regno);
2155 /* This is big-endian, so the high-part is the first one. */
2156 fprintf (stream, "%s", reg_names[MMIX_OUTPUT_REGNO (regno)]);
2160 /* Lowpart. Must be CONST_INT or general register, and not the last
2161 one, as that one cannot be part of a consecutive register pair. */
2162 if (GET_CODE (x) == CONST_INT)
2164 fprintf (stream, "#%lx",
2165 (unsigned long) (INTVAL (x)
2166 & ((unsigned int) 0x7fffffff * 2 + 1)));
2170 if (GET_CODE (x) == SYMBOL_REF)
2172 output_addr_const (stream, x);
2176 if (regno > MMIX_LAST_GENERAL_REGISTER - 1)
2177 internal_error ("MMIX Internal: Bad register: %d", regno);
2179 /* This is big-endian, so the low-part is + 1. */
2180 fprintf (stream, "%s", reg_names[MMIX_OUTPUT_REGNO (regno) + 1]);
2183 /* Can't use 'a' because that's a generic modifier for address
2186 mmix_output_shiftvalue_op_from_str (stream, "ANDN",
2187 ~(unsigned HOST_WIDEST_INT)
2192 mmix_output_shiftvalue_op_from_str (stream, "INC",
2193 (unsigned HOST_WIDEST_INT)
2198 mmix_output_shiftvalue_op_from_str (stream, "OR",
2199 (unsigned HOST_WIDEST_INT)
2204 mmix_output_shiftvalue_op_from_str (stream, "SET",
2205 (unsigned HOST_WIDEST_INT)
2211 mmix_output_condition (stream, x, (code == 'D'));
2215 /* Output an extra "e" to make fcmpe, fune. */
2216 if (TARGET_FCMP_EPSILON)
2217 fprintf (stream, "e");
2221 /* Output the number minus 1. */
2222 if (GET_CODE (x) != CONST_INT)
2224 fatal_insn ("MMIX Internal: Bad value for 'm', not a CONST_INT",
2227 fprintf (stream, HOST_WIDEST_INT_PRINT_DEC,
2228 (HOST_WIDEST_INT) (mmix_intval (x) - 1));
2232 /* Store the number of registers we want to save. This was setup
2233 by the prologue. The actual operand contains the number of
2234 registers to pass, but we don't use it currently. Anyway, we
2235 need to output the number of saved registers here. */
2236 fprintf (stream, "%d",
2237 cfun->machine->highest_saved_stack_register + 1);
2241 /* Store the register to output a constant to. */
2243 fatal_insn ("MMIX Internal: Expected a register, not this", x);
2244 mmix_output_destination_register = MMIX_OUTPUT_REGNO (regno);
2248 /* Output the constant. Note that we use this for floats as well. */
2249 if (GET_CODE (x) != CONST_INT
2250 && (GET_CODE (x) != CONST_DOUBLE
2251 || (GET_MODE (x) != VOIDmode && GET_MODE (x) != DFmode
2252 && GET_MODE (x) != SFmode)))
2253 fatal_insn ("MMIX Internal: Expected a constant, not this", x);
2254 mmix_output_register_setting (stream,
2255 mmix_output_destination_register,
2256 mmix_intval (x), 0);
2260 /* An U for unsigned, if TARGET_ZERO_EXTEND. Ignore the operand. */
2261 if (TARGET_ZERO_EXTEND)
2266 mmix_output_shifted_value (stream, (HOST_WIDEST_INT) mmix_intval (x));
2270 mmix_output_shifted_value (stream, (HOST_WIDEST_INT) ~mmix_intval (x));
2274 if (GET_CODE (x) != CONST_INT)
2275 fatal_insn ("MMIX Internal: Expected a CONST_INT, not this", x);
2276 fprintf (stream, "#%x", (int) (INTVAL (x) & 0xffff));
2280 /* Nothing to do. */
2284 /* Presumably there's a missing case above if we get here. */
2285 internal_error ("MMIX Internal: Missing `%c' case in mmix_print_operand", code);
2288 switch (GET_CODE (modified_x))
2291 regno = REGNO (modified_x);
2292 if (regno >= FIRST_PSEUDO_REGISTER)
2293 internal_error ("MMIX Internal: Bad register: %d", regno);
2294 fprintf (stream, "%s", reg_names[MMIX_OUTPUT_REGNO (regno)]);
2298 output_address (XEXP (modified_x, 0));
2302 /* For -2147483648, mmixal complains that the constant does not fit
2303 in 4 bytes, so let's output it as hex. Take care to handle hosts
2304 where HOST_WIDE_INT is longer than an int.
2306 Print small constants +-255 using decimal. */
2308 if (INTVAL (modified_x) > -256 && INTVAL (modified_x) < 256)
2309 fprintf (stream, "%d", (int) (INTVAL (modified_x)));
2311 fprintf (stream, "#%x",
2312 (int) (INTVAL (modified_x)) & (unsigned int) ~0);
2316 /* Do somewhat as CONST_INT. */
2317 mmix_output_octa (stream, mmix_intval (modified_x), 0);
2321 output_addr_const (stream, modified_x);
2325 /* No need to test for all strange things. Let output_addr_const do
2327 if (CONSTANT_P (modified_x)
2328 /* Strangely enough, this is not included in CONSTANT_P.
2329 FIXME: Ask/check about sanity here. */
2330 || GET_CODE (modified_x) == CODE_LABEL)
2332 output_addr_const (stream, modified_x);
2336 /* We need the original here. */
2337 fatal_insn ("MMIX Internal: Cannot decode this operand", x);
2341 /* PRINT_OPERAND_PUNCT_VALID_P. */
2344 mmix_print_operand_punct_valid_p (code)
2345 int code ATTRIBUTE_UNUSED;
2347 /* A '+' is used for branch prediction, similar to other ports. */
2351 /* PRINT_OPERAND_ADDRESS. */
2354 mmix_print_operand_address (stream, x)
2360 /* I find the generated assembly code harder to read without
2362 fprintf (stream, "%s,0", reg_names[MMIX_OUTPUT_REGNO (REGNO (x))]);
2365 else if (GET_CODE (x) == PLUS)
2367 rtx x1 = XEXP (x, 0);
2368 rtx x2 = XEXP (x, 1);
2370 /* Try swap the order. FIXME: Do we need this? */
2380 fprintf (stream, "%s,", reg_names[MMIX_OUTPUT_REGNO (REGNO (x1))]);
2384 fprintf (stream, "%s",
2385 reg_names[MMIX_OUTPUT_REGNO (REGNO (x2))]);
2388 else if (GET_CODE (x2) == CONST_INT
2389 && CONST_OK_FOR_LETTER_P (INTVAL (x2), 'I'))
2391 output_addr_const (stream, x2);
2397 if (TARGET_BASE_ADDRESSES && mmix_legitimate_constant_p (x))
2399 output_addr_const (stream, x);
2403 fatal_insn ("MMIX Internal: This is not a recognized address", x);
2406 /* ASM_OUTPUT_REG_PUSH. */
2409 mmix_asm_output_reg_push (stream, regno)
2413 fprintf (stream, "\tSUBU %s,%s,8\n\tSTOU %s,%s,0\n",
2414 reg_names[MMIX_STACK_POINTER_REGNUM],
2415 reg_names[MMIX_STACK_POINTER_REGNUM],
2416 reg_names[MMIX_OUTPUT_REGNO (regno)],
2417 reg_names[MMIX_STACK_POINTER_REGNUM]);
2420 /* ASM_OUTPUT_REG_POP. */
2423 mmix_asm_output_reg_pop (stream, regno)
2427 fprintf (stream, "\tLDOU %s,%s,0\n\tINCL %s,8\n",
2428 reg_names[MMIX_OUTPUT_REGNO (regno)],
2429 reg_names[MMIX_STACK_POINTER_REGNUM],
2430 reg_names[MMIX_STACK_POINTER_REGNUM]);
2433 /* ASM_OUTPUT_ADDR_DIFF_ELT. */
2436 mmix_asm_output_addr_diff_elt (stream, body, value, rel)
2438 rtx body ATTRIBUTE_UNUSED;
2442 fprintf (stream, "\tTETRA L%d-L%d\n", value, rel);
2445 /* ASM_OUTPUT_ADDR_VEC_ELT. */
2448 mmix_asm_output_addr_vec_elt (stream, value)
2452 fprintf (stream, "\tOCTA L:%d\n", value);
2455 /* ASM_OUTPUT_SKIP. */
2458 mmix_asm_output_skip (stream, nbytes)
2462 fprintf (stream, "\tLOC @+%d\n", nbytes);
2465 /* ASM_OUTPUT_ALIGN. */
2468 mmix_asm_output_align (stream, power)
2472 /* We need to record the needed alignment of this section in the object,
2473 so we have to output an alignment directive. Use a .p2align (not
2474 .align) so people will never have to wonder about whether the
2475 argument is in number of bytes or the log2 thereof. We do it in
2476 addition to the LOC directive, so nothing needs tweaking when
2477 copy-pasting assembly into mmixal. */
2478 fprintf (stream, "\t.p2align %d\n", power);
2479 fprintf (stream, "\tLOC @+(%d-@)&%d\n", 1 << power, (1 << power) - 1);
2482 /* DBX_REGISTER_NUMBER. */
2485 mmix_dbx_register_number (regno)
2488 /* Adjust the register number to the one it will be output as, dammit.
2489 It'd be nice if we could check the assumption that we're filling a
2490 gap, but every register between the last saved register and parameter
2491 registers might be a valid parameter register. */
2492 regno = MMIX_OUTPUT_REGNO (regno);
2494 /* We need to renumber registers to get the number of the return address
2495 register in the range 0..255. It is also space-saving if registers
2496 mentioned in the call-frame information (which uses this function by
2497 defaulting DWARF_FRAME_REGNUM to DBX_REGISTER_NUMBER) are numbered
2498 0 .. 63. So map 224 .. 256+15 -> 0 .. 47 and 0 .. 223 -> 48..223+48. */
2499 return regno >= 224 ? (regno - 224) : (regno + 48);
2502 /* End of target macro support functions.
2504 Now MMIX's own functions. First the exported ones. */
2506 /* Output an optimal sequence for setting a register to a specific
2507 constant. Used in an alternative for const_ints in movdi, and when
2508 using large stack-frame offsets.
2510 Use do_begin_end to say if a line-starting TAB and newline before the
2511 first insn and after the last insn is wanted. */
2514 mmix_output_register_setting (stream, regno, value, do_begin_end)
2517 HOST_WIDEST_INT value;
2521 fprintf (stream, "\t");
2523 if (mmix_shiftable_wyde_value ((unsigned HOST_WIDEST_INT) value))
2525 /* First, the one-insn cases. */
2526 mmix_output_shiftvalue_op_from_str (stream, "SET",
2527 (unsigned HOST_WIDEST_INT)
2529 fprintf (stream, " %s,", reg_names[regno]);
2530 mmix_output_shifted_value (stream, (unsigned HOST_WIDEST_INT) value);
2532 else if (mmix_shiftable_wyde_value (-(unsigned HOST_WIDEST_INT) value))
2534 /* We do this to get a bit more legible assembly code. The next
2535 alternative is mostly redundant with this. */
2537 mmix_output_shiftvalue_op_from_str (stream, "SET",
2538 -(unsigned HOST_WIDEST_INT)
2540 fprintf (stream, " %s,", reg_names[regno]);
2541 mmix_output_shifted_value (stream, -(unsigned HOST_WIDEST_INT) value);
2542 fprintf (stream, "\n\tNEGU %s,0,%s", reg_names[regno],
2545 else if (mmix_shiftable_wyde_value (~(unsigned HOST_WIDEST_INT) value))
2547 /* Slightly more expensive, the two-insn cases. */
2549 /* FIXME: We could of course also test if 0..255-N or ~(N | 1..255)
2550 is shiftable, or any other one-insn transformation of the value.
2551 FIXME: Check first if the value is "shiftable" by two loading
2552 with two insns, since it makes more readable assembly code (if
2553 anyone else cares). */
2555 mmix_output_shiftvalue_op_from_str (stream, "SET",
2556 ~(unsigned HOST_WIDEST_INT)
2558 fprintf (stream, " %s,", reg_names[regno]);
2559 mmix_output_shifted_value (stream, ~(unsigned HOST_WIDEST_INT) value);
2560 fprintf (stream, "\n\tNOR %s,%s,0", reg_names[regno],
2565 /* The generic case. 2..4 insns. */
2566 static const char *const higher_parts[] = {"L", "ML", "MH", "H"};
2567 const char *op = "SET";
2568 const char *line_begin = "";
2571 HOST_WIDEST_INT tmpvalue = value;
2573 /* Compute the number of insns needed to output this constant. */
2574 for (i = 0; i < 4 && tmpvalue != 0; i++)
2576 if (tmpvalue & 65535)
2580 if (TARGET_BASE_ADDRESSES && insns == 3)
2582 /* The number three is based on a static observation on
2583 ghostscript-6.52. Two and four are excluded because there
2584 are too many such constants, and each unique constant (maybe
2585 offset by 1..255) were used few times compared to other uses,
2588 We use base-plus-offset addressing to force it into a global
2589 register; we just use a "LDA reg,VALUE", which will cause the
2590 assembler and linker to DTRT (for constants as well as
2592 fprintf (stream, "LDA %s,", reg_names[regno]);
2593 mmix_output_octa (stream, value, 0);
2597 /* Output pertinent parts of the 4-wyde sequence.
2598 Still more to do if we want this to be optimal, but hey...
2599 Note that the zero case has been handled above. */
2600 for (i = 0; i < 4 && value != 0; i++)
2604 fprintf (stream, "%s%s%s %s,#%x", line_begin, op,
2605 higher_parts[i], reg_names[regno],
2606 (int) (value & 65535));
2607 /* The first one sets the rest of the bits to 0, the next
2608 ones add set bits. */
2610 line_begin = "\n\t";
2619 fprintf (stream, "\n");
2622 /* Return 1 if value is 0..65535*2**(16*N) for N=0..3.
2626 mmix_shiftable_wyde_value (value)
2627 unsigned HOST_WIDEST_INT value;
2629 /* Shift by 16 bits per group, stop when we've found two groups with
2632 int has_candidate = 0;
2634 for (i = 0; i < 4; i++)
2650 /* True if this is an address_operand or a symbolic operand. */
2653 mmix_symbolic_or_address_operand (op, mode)
2655 enum machine_mode mode;
2657 switch (GET_CODE (op))
2664 if ((GET_CODE (XEXP (op, 0)) == SYMBOL_REF
2665 || GET_CODE (XEXP (op, 0)) == LABEL_REF)
2666 && (GET_CODE (XEXP (op, 1)) == CONST_INT
2667 || (GET_CODE (XEXP (op, 1)) == CONST_DOUBLE
2668 && GET_MODE (XEXP (op, 1)) == VOIDmode)))
2672 return address_operand (op, mode);
2676 /* True if this is a register or CONST_INT (or CONST_DOUBLE for DImode).
2677 We could narrow the value down with a couple of predicated, but that
2678 doesn't seem to be worth it at the moment. */
2681 mmix_reg_or_constant_operand (op, mode)
2683 enum machine_mode mode;
2685 return register_operand (op, mode)
2686 || (GET_CODE (op) == CONST_DOUBLE && GET_MODE (op) == VOIDmode)
2687 || GET_CODE (op) == CONST_INT;
2690 /* True if this is a register with a condition-code mode. */
2693 mmix_reg_cc_operand (op, mode)
2695 enum machine_mode mode;
2697 if (mode == VOIDmode)
2698 mode = GET_MODE (op);
2700 return register_operand (op, mode)
2701 && (mode == CCmode || mode == CC_UNSmode || mode == CC_FPmode
2702 || mode == CC_FPEQmode || mode == CC_FUNmode);
2705 /* True if this is a foldable comparison operator
2706 - one where a the result of (compare:CC (reg) (const_int 0)) can be
2707 replaced by (reg). */
2710 mmix_foldable_comparison_operator (op, mode)
2712 enum machine_mode mode;
2714 RTX_CODE code = GET_CODE (op);
2716 if (mode == VOIDmode)
2717 mode = GET_MODE (op);
2719 if (mode == VOIDmode && GET_RTX_CLASS (GET_CODE (op)) == '<')
2720 mode = GET_MODE (XEXP (op, 0));
2722 return ((mode == CCmode || mode == DImode)
2723 && (code == NE || code == EQ || code == GE || code == GT
2725 /* FIXME: This may be a stupid trick. What happens when GCC wants to
2726 reverse the condition? Can it do that by itself? Maybe it can
2727 even reverse the condition to fit a foldable one in the first
2729 || (mode == CC_UNSmode && (code == GTU || code == LEU));
2732 /* Like comparison_operator, but only true if this comparison operator is
2733 applied to a valid mode. Needed to avoid jump.c generating invalid
2734 code with -ffast-math (gcc.dg/20001228-1.c). */
2737 mmix_comparison_operator (op, mode)
2739 enum machine_mode mode;
2741 RTX_CODE code = GET_CODE (op);
2743 /* Comparison operators usually don't have a mode, but let's try and get
2744 one anyway for the day that changes. */
2745 if (mode == VOIDmode)
2746 mode = GET_MODE (op);
2748 /* Get the mode from the first operand if we don't have one. */
2749 if (mode == VOIDmode && GET_RTX_CLASS (GET_CODE (op)) == '<')
2750 mode = GET_MODE (XEXP (op, 0));
2752 /* FIXME: This needs to be kept in sync with the tables in
2753 mmix_output_condition. */
2755 (mode == VOIDmode && GET_RTX_CLASS (GET_CODE (op)) == '<')
2756 || (mode == CC_FUNmode
2757 && (code == ORDERED || code == UNORDERED))
2758 || (mode == CC_FPmode
2759 && (code == GT || code == LT))
2760 || (mode == CC_FPEQmode
2761 && (code == NE || code == EQ))
2762 || (mode == CC_UNSmode
2763 && (code == GEU || code == GTU || code == LEU || code == LTU))
2765 && (code == NE || code == EQ || code == GE || code == GT
2766 || code == LE || code == LT))
2768 && (code == NE || code == EQ || code == GE || code == GT
2769 || code == LE || code == LT || code == LEU || code == GTU));
2772 /* True if this is a register or 0 (int or float). */
2775 mmix_reg_or_0_operand (op, mode)
2777 enum machine_mode mode;
2779 /* FIXME: Is mode calculation necessary and correct? */
2781 op == CONST0_RTX (mode == VOIDmode ? GET_MODE (op) : mode)
2782 || register_operand (op, mode);
2785 /* True if this is a register or an int 0..255. */
2788 mmix_reg_or_8bit_operand (op, mode)
2790 enum machine_mode mode;
2792 return register_operand (op, mode)
2793 || (GET_CODE (op) == CONST_INT
2794 && CONST_OK_FOR_LETTER_P (INTVAL (op), 'I'));
2797 /* True if this is a register or an int 0..256. We include 256,
2798 because it can be canonicalized into 255 for comparisons, which is
2799 currently the only use of this predicate.
2800 FIXME: Check that this happens and does TRT. */
2803 mmix_reg_or_8bit_or_256_operand (op, mode)
2805 enum machine_mode mode;
2807 return mmix_reg_or_8bit_operand (op, mode)
2808 || (GET_CODE (op) == CONST_INT && INTVAL (op) == 256);
2811 /* Returns zero if code and mode is not a valid condition from a
2812 compare-type insn. Nonzero if it is. The parameter op, if non-NULL,
2813 is the comparison of mode is CC-somethingmode. */
2816 mmix_valid_comparison (code, mode, op)
2818 enum machine_mode mode;
2821 if (mode == VOIDmode && op != NULL_RTX)
2822 mode = GET_MODE (op);
2824 /* We don't care to look at these, they should always be valid. */
2825 if (mode == CCmode || mode == CC_UNSmode || mode == DImode)
2828 if ((mode == CC_FPmode || mode == DFmode)
2829 && (code == GT || code == LT))
2832 if ((mode == CC_FPEQmode || mode == DFmode)
2833 && (code == EQ || code == NE))
2836 if ((mode == CC_FUNmode || mode == DFmode)
2837 && (code == ORDERED || code == UNORDERED))
2843 /* X and Y are two things to compare using CODE. Emit a compare insn if
2844 possible and return the rtx for the cc-reg in the proper mode, or
2845 NULL_RTX if this is not a valid comparison. */
2848 mmix_gen_compare_reg (code, x, y)
2852 enum machine_mode ccmode = SELECT_CC_MODE (code, x, y);
2855 /* FIXME: Do we get constants here? Of double mode? */
2856 enum machine_mode mode
2857 = GET_MODE (x) == VOIDmode
2859 : GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT ? DFmode : DImode;
2861 if (! mmix_valid_comparison (code, mode, x))
2864 cc_reg = gen_reg_rtx (ccmode);
2866 /* FIXME: Can we avoid emitting a compare insn here? */
2867 if (! REG_P (x) && ! REG_P (y))
2868 x = force_reg (mode, x);
2870 CANONICALIZE_COMPARISON (code, x, y);
2872 /* If it's not quite right yet, put y in a register. */
2874 && (GET_CODE (y) != CONST_INT
2875 || ! CONST_OK_FOR_LETTER_P (INTVAL (y), 'I')))
2876 y = force_reg (mode, y);
2878 emit_insn (gen_rtx_SET (VOIDmode, cc_reg,
2879 gen_rtx_COMPARE (ccmode, x, y)));
2884 /* Local (static) helper functions. */
2886 /* Print operator suitable for doing something with a shiftable
2887 wyde. The type of operator is passed as an asm output modifier. */
2890 mmix_output_shiftvalue_op_from_str (stream, mainop, value)
2893 HOST_WIDEST_INT value;
2895 static const char *const op_part[] = {"L", "ML", "MH", "H"};
2898 if (! mmix_shiftable_wyde_value (value))
2900 char s[sizeof ("0xffffffffffffffff")];
2901 sprintf (s, HOST_WIDEST_INT_PRINT_HEX, value);
2902 internal_error ("MMIX Internal: %s is not a shiftable int", s);
2905 for (i = 0; i < 4; i++)
2907 /* We know we're through when we find one-bits in the low
2911 fprintf (stream, "%s%s", mainop, op_part[i]);
2917 /* No bits set? Then it must have been zero. */
2918 fprintf (stream, "%sL", mainop);
2921 /* Print a 64-bit value, optionally prefixed by assembly pseudo. */
2924 mmix_output_octa (stream, value, do_begin_end)
2926 HOST_WIDEST_INT value;
2929 /* Snipped from final.c:output_addr_const. We need to avoid the
2930 presumed universal "0x" prefix. We can do it by replacing "0x" with
2931 "#0" here; we must avoid a space in the operands and no, the zero
2932 won't cause the number to be assumed in octal format. */
2933 char hex_format[sizeof (HOST_WIDEST_INT_PRINT_HEX)];
2936 fprintf (stream, "\tOCTA ");
2938 strcpy (hex_format, HOST_WIDEST_INT_PRINT_HEX);
2939 hex_format[0] = '#';
2940 hex_format[1] = '0';
2942 /* Provide a few alternative output formats depending on the number, to
2943 improve legibility of assembler output. */
2944 if ((value < (HOST_WIDEST_INT) 0 && value > (HOST_WIDEST_INT) -10000)
2945 || (value >= (HOST_WIDEST_INT) 0 && value <= (HOST_WIDEST_INT) 16384))
2946 fprintf (stream, "%d", (int) value);
2947 else if (value > (HOST_WIDEST_INT) 0
2948 && value < ((HOST_WIDEST_INT) 1 << 31) * 2)
2949 fprintf (stream, "#%x", (unsigned int) value);
2951 fprintf (stream, hex_format, value);
2954 fprintf (stream, "\n");
2957 /* Print the presumed shiftable wyde argument shifted into place (to
2958 be output with an operand). */
2961 mmix_output_shifted_value (stream, value)
2963 HOST_WIDEST_INT value;
2967 if (! mmix_shiftable_wyde_value (value))
2970 sprintf (s, HOST_WIDEST_INT_PRINT_HEX, value);
2971 internal_error ("MMIX Internal: %s is not a shiftable int", s);
2974 for (i = 0; i < 4; i++)
2976 /* We know we're through when we find one-bits in the low 16 bits. */
2979 fprintf (stream, "#%x", (int) (value & 0xffff));
2986 /* No bits set? Then it must have been zero. */
2987 fprintf (stream, "0");
2990 /* Output an MMIX condition name corresponding to an operator
2992 (comparison_operator [(comparison_operator ...) (const_int 0)])
2993 which means we have to look at *two* operators.
2995 The argument "reversed" refers to reversal of the condition (not the
2996 same as swapping the arguments). */
2999 mmix_output_condition (stream, x, reversed)
3008 /* The normal output cc-code. */
3009 const char *const normal;
3011 /* The reversed cc-code, or NULL if invalid. */
3012 const char *const reversed;
3017 enum machine_mode cc_mode;
3019 /* Terminated with {NIL, NULL, NULL} */
3020 const struct cc_conv *const convs;
3024 #define CCEND {NIL, NULL, NULL}
3026 static const struct cc_conv cc_fun_convs[]
3027 = {{ORDERED, "Z", "P"},
3028 {UNORDERED, "P", "Z"},
3030 static const struct cc_conv cc_fp_convs[]
3034 static const struct cc_conv cc_fpeq_convs[]
3038 static const struct cc_conv cc_uns_convs[]
3039 = {{GEU, "NN", "N"},
3044 static const struct cc_conv cc_signed_convs[]
3052 static const struct cc_conv cc_di_convs[]
3064 static const struct cc_type_conv cc_convs[]
3065 = {{CC_FUNmode, cc_fun_convs},
3066 {CC_FPmode, cc_fp_convs},
3067 {CC_FPEQmode, cc_fpeq_convs},
3068 {CC_UNSmode, cc_uns_convs},
3069 {CCmode, cc_signed_convs},
3070 {DImode, cc_di_convs}};
3075 enum machine_mode mode = GET_MODE (XEXP (x, 0));
3076 RTX_CODE cc = GET_CODE (x);
3078 for (i = 0; i < ARRAY_SIZE (cc_convs); i++)
3080 if (mode == cc_convs[i].cc_mode)
3082 for (j = 0; cc_convs[i].convs[j].cc != NIL; j++)
3083 if (cc == cc_convs[i].convs[j].cc)
3086 = (reversed ? cc_convs[i].convs[j].reversed
3087 : cc_convs[i].convs[j].normal);
3089 if (mmix_cc == NULL)
3090 fatal_insn ("MMIX Internal: Trying to output invalidly\
3091 reversed condition:", x);
3093 fprintf (stream, "%s", mmix_cc);
3097 fatal_insn ("MMIX Internal: What's the CC of this?", x);
3101 fatal_insn ("MMIX Internal: What is the CC of this?", x);
3104 /* Return the bit-value for a const_int or const_double. */
3106 static HOST_WIDEST_INT
3110 unsigned HOST_WIDEST_INT retval;
3112 if (GET_CODE (x) == CONST_INT)
3115 /* We make a little song and dance because converting to long long in
3116 gcc-2.7.2 is broken. I still want people to be able to use it for
3117 cross-compilation to MMIX. */
3118 if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == VOIDmode)
3120 if (sizeof (HOST_WIDE_INT) < sizeof (HOST_WIDEST_INT))
3122 retval = (unsigned) CONST_DOUBLE_LOW (x) / 2;
3124 retval |= CONST_DOUBLE_LOW (x) & 1;
3127 (unsigned HOST_WIDEST_INT) CONST_DOUBLE_HIGH (x)
3128 << (HOST_BITS_PER_LONG);
3131 retval = CONST_DOUBLE_HIGH (x);
3136 if (GET_CODE (x) == CONST_DOUBLE)
3138 REAL_VALUE_TYPE value;
3140 /* FIXME: This macro is not in the manual but should be. */
3141 REAL_VALUE_FROM_CONST_DOUBLE (value, x);
3143 if (GET_MODE (x) == DFmode)
3147 REAL_VALUE_TO_TARGET_DOUBLE (value, bits);
3149 if (sizeof (long) < sizeof (HOST_WIDEST_INT))
3151 retval = (unsigned long) bits[1] / 2;
3153 retval |= (unsigned long) bits[1] & 1;
3155 |= (unsigned HOST_WIDEST_INT) bits[0]
3156 << (sizeof (bits[0]) * 8);
3159 retval = (unsigned long) bits[1];
3163 else if (GET_MODE (x) == SFmode)
3166 REAL_VALUE_TO_TARGET_SINGLE (value, bits);
3168 return (unsigned long) bits;
3172 fatal_insn ("MMIX Internal: This is not a constant:", x);
3177 * eval: (c-set-style "gnu")
3178 * indent-tabs-mode: t