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 /* The canonical saved comparison operands for non-cc0 machines, set in
66 the compare expander. */
70 /* We ignore some options with arguments. They are passed to the linker,
71 but also ends up here because they start with "-m". We tell the driver
72 to store them in a variable we don't inspect. */
73 const char *mmix_cc1_ignored_option
;
75 /* Declarations of locals. */
77 /* This is used in the prologue for what number to pass in a PUSHJ or
79 static int mmix_highest_saved_stack_register
;
81 /* Intermediate for insn output. */
82 static int mmix_output_destination_register
;
84 static void mmix_output_shiftvalue_op_from_str
85 PARAMS ((FILE *, const char *, HOST_WIDEST_INT
));
86 static void mmix_output_shifted_value
PARAMS ((FILE *, HOST_WIDEST_INT
));
87 static void mmix_output_condition
PARAMS ((FILE *, rtx
, int));
88 static HOST_WIDEST_INT mmix_intval
PARAMS ((rtx
));
89 static void mmix_output_octa
PARAMS ((FILE *, HOST_WIDEST_INT
, int));
90 static bool mmix_assemble_integer
PARAMS ((rtx
, unsigned int, int));
91 static void mmix_init_machine_status
PARAMS ((struct function
*));
93 extern void mmix_target_asm_function_prologue
94 PARAMS ((FILE *, HOST_WIDE_INT
));
95 extern void mmix_target_asm_function_epilogue
96 PARAMS ((FILE *, HOST_WIDE_INT
));
99 /* Target structure macros. Listed by node. See `Using and Porting GCC'
100 for a general description. */
102 /* Node: Function Entry */
104 #undef TARGET_ASM_BYTE_OP
105 #define TARGET_ASM_BYTE_OP NULL
106 #undef TARGET_ASM_ALIGNED_HI_OP
107 #define TARGET_ASM_ALIGNED_HI_OP NULL
108 #undef TARGET_ASM_ALIGNED_SI_OP
109 #define TARGET_ASM_ALIGNED_SI_OP NULL
110 #undef TARGET_ASM_ALIGNED_DI_OP
111 #define TARGET_ASM_ALIGNED_DI_OP NULL
112 #undef TARGET_ASM_INTEGER
113 #define TARGET_ASM_INTEGER mmix_assemble_integer
115 #undef TARGET_ASM_FUNCTION_PROLOGUE
116 #define TARGET_ASM_FUNCTION_PROLOGUE mmix_target_asm_function_prologue
118 #undef TARGET_ASM_FUNCTION_EPILOGUE
119 #define TARGET_ASM_FUNCTION_EPILOGUE mmix_target_asm_function_epilogue
121 struct gcc_target targetm
= TARGET_INITIALIZER
;
123 /* Functions that are expansions for target macros.
124 See Target Macros in `Using and Porting GCC'. */
126 /* OVERRIDE_OPTIONS. */
129 mmix_override_options ()
131 /* Should we err or should we warn? Hmm. At least we must neutralize
132 it. For example the wrong kind of case-tables will be generated with
133 PIC; we use absolute address items for mmixal compatibility. FIXME:
134 They could be relative if we just elide them to after all pertinent
138 warning ("-f%s not supported: ignored", (flag_pic
> 1) ? "PIC" : "pic");
142 /* All other targets add GC roots from their override_options function,
144 ggc_add_rtx_root (&mmix_compare_op0
, 1);
145 ggc_add_rtx_root (&mmix_compare_op1
, 1);
148 /* INIT_EXPANDERS. */
151 mmix_init_expanders ()
153 init_machine_status
= mmix_init_machine_status
;
156 /* Set the per-function data. */
159 mmix_init_machine_status (f
)
162 f
->machine
= xcalloc (1, sizeof (struct machine_function
));
166 We have trouble getting the address of stuff that is located at other
167 than 32-bit alignments (GETA requirements), so try to give everything
168 at least 32-bit alignment. */
171 mmix_data_alignment (type
, basic_align
)
172 tree type ATTRIBUTE_UNUSED
;
175 if (basic_align
< 32)
181 /* CONSTANT_ALIGNMENT. */
184 mmix_constant_alignment (constant
, basic_align
)
185 tree constant ATTRIBUTE_UNUSED
;
188 if (basic_align
< 32)
194 /* LOCAL_ALIGNMENT. */
197 mmix_local_alignment (type
, basic_align
)
198 tree type ATTRIBUTE_UNUSED
;
201 if (basic_align
< 32)
207 /* CONDITIONAL_REGISTER_USAGE. */
210 mmix_conditional_register_usage ()
216 static const int gnu_abi_reg_alloc_order
[]
217 = MMIX_GNU_ABI_REG_ALLOC_ORDER
;
219 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
220 reg_alloc_order
[i
] = gnu_abi_reg_alloc_order
[i
];
222 /* Change the default from the mmixware ABI. For the GNU ABI,
223 $15..$30 are call-saved just as $0..$14. There must be one
224 call-clobbered local register for the "hole" describing number of
225 saved local registers saved by PUSHJ/PUSHGO during the function
226 call, receiving the return value at return. So best is to use
227 the highest, $31. It's already marked call-clobbered for the
229 for (i
= 15; i
<= 30; i
++)
230 call_used_regs
[i
] = 0;
233 /* Step over the ":" in special register names. */
234 if (! TARGET_TOPLEVEL_SYMBOLS
)
235 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
236 if (reg_names
[i
][0] == ':')
240 /* PREFERRED_RELOAD_CLASS.
241 We need to extend the reload class of REMAINDER_REG and HIMULT_REG. */
244 mmix_preferred_reload_class (x
, class)
245 rtx x ATTRIBUTE_UNUSED
;
246 enum reg_class
class;
248 /* FIXME: Revisit. */
249 return GET_CODE (x
) == MOD
&& GET_MODE (x
) == DImode
250 ? REMAINDER_REG
: class;
253 /* PREFERRED_OUTPUT_RELOAD_CLASS.
254 We need to extend the reload class of REMAINDER_REG and HIMULT_REG. */
257 mmix_preferred_output_reload_class (x
, class)
258 rtx x ATTRIBUTE_UNUSED
;
259 enum reg_class
class;
261 /* FIXME: Revisit. */
262 return GET_CODE (x
) == MOD
&& GET_MODE (x
) == DImode
263 ? REMAINDER_REG
: class;
266 /* SECONDARY_RELOAD_CLASS.
267 We need to reload regs of REMAINDER_REG and HIMULT_REG elsewhere. */
270 mmix_secondary_reload_class (class, mode
, x
, in_p
)
271 enum reg_class
class;
272 enum machine_mode mode ATTRIBUTE_UNUSED
;
273 rtx x ATTRIBUTE_UNUSED
;
274 int in_p ATTRIBUTE_UNUSED
;
276 if (class == REMAINDER_REG
277 || class == HIMULT_REG
278 || class == SYSTEM_REGS
)
284 /* CONST_OK_FOR_LETTER_P. */
287 mmix_const_ok_for_letter_p (value
, c
)
292 (c
== 'I' ? value
>= 0 && value
<= 255
293 : c
== 'J' ? value
>= 0 && value
<= 65535
294 : c
== 'K' ? value
<= 0 && value
>= -255
295 : c
== 'L' ? mmix_shiftable_wyde_value (value
)
296 : c
== 'M' ? value
== 0
297 : c
== 'N' ? mmix_shiftable_wyde_value (~value
)
298 : c
== 'O' ? (value
== 3 || value
== 5 || value
== 9
303 /* CONST_DOUBLE_OK_FOR_LETTER_P. */
306 mmix_const_double_ok_for_letter_p (value
, c
)
311 (c
== 'G' ? value
== CONST0_RTX (GET_MODE (value
))
316 We need this since our constants are not always expressible as
317 CONST_INT:s, but rather often as CONST_DOUBLE:s. */
320 mmix_extra_constraint (x
, c
, strict
)
325 HOST_WIDEST_INT value
;
327 /* When checking for an address, we need to handle strict vs. non-strict
328 register checks. Don't use address_operand, but instead its
329 equivalent (its callee, which it is just a wrapper for),
330 memory_operand_p and the strict-equivalent strict_memory_address_p. */
334 ? strict_memory_address_p (Pmode
, x
)
335 : memory_address_p (Pmode
, x
);
337 if (GET_CODE (x
) != CONST_DOUBLE
|| GET_MODE (x
) != VOIDmode
)
340 value
= mmix_intval (x
);
342 /* We used to map Q->J, R->K, S->L, T->N, U->O, but we don't have to any
343 more ('U' taken for address_operand). Some letters map outside of
344 CONST_INT, though; we still use 'S' and 'T'. */
346 return mmix_shiftable_wyde_value (value
);
348 return mmix_shiftable_wyde_value (~value
);
352 /* DYNAMIC_CHAIN_ADDRESS. */
355 mmix_dynamic_chain_address (frame
)
358 /* FIXME: the frame-pointer is stored at offset -8 from the current
359 frame-pointer. Unfortunately, the caller assumes that a
360 frame-pointer is present for *all* previous frames. There should be
361 a way to say that that cannot be done, like for RETURN_ADDR_RTX. */
362 return plus_constant (frame
, -8);
365 /* STARTING_FRAME_OFFSET. */
368 mmix_starting_frame_offset ()
370 /* The old frame pointer is in the slot below the new one, so
371 FIRST_PARM_OFFSET does not need to depend on whether the
372 frame-pointer is needed or not. We have to adjust for the register
373 stack pointer being located below the saved frame pointer.
374 Similarly, we store the return address on the stack too, for
375 exception handling, and always if we save the register stack pointer. */
378 + (MMIX_CFUN_HAS_LANDING_PAD
379 ? -16 : (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
? -8 : 0)));
382 /* RETURN_ADDR_RTX. */
385 mmix_return_addr_rtx (count
, frame
)
387 rtx frame ATTRIBUTE_UNUSED
;
390 ? (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
391 /* FIXME: Set frame_alias_set on the following. */
392 ? validize_mem (gen_rtx_MEM (Pmode
, plus_constant (frame_pointer_rtx
, -16)))
393 : get_hard_reg_initial_val (Pmode
, MMIX_INCOMING_RETURN_ADDRESS_REGNUM
))
397 /* SETUP_FRAME_ADDRESSES. */
400 mmix_setup_frame_addresses ()
402 /* Nothing needed at the moment. */
405 /* The difference between the (imaginary) frame pointer and the stack
406 pointer. Used to eliminate the frame pointer. */
409 mmix_initial_elimination_offset (fromreg
, toreg
)
415 = (get_frame_size () + current_function_outgoing_args_size
+ 7) & ~7;
417 /* There is no actual difference between these two. */
418 if (fromreg
== MMIX_ARG_POINTER_REGNUM
419 && toreg
== MMIX_FRAME_POINTER_REGNUM
)
422 /* The difference is the size of local variables plus the size of
423 outgoing function arguments that would normally be passed as
424 registers but must be passed on stack because we're out of
425 function-argument registers. Only global saved registers are
426 counted; the others go on the register stack.
428 The frame-pointer is counted too if it is what is eliminated, as we
429 need to balance the offset for it from STARTING_FRAME_OFFSET.
431 Also add in the slot for the register stack pointer we save if we
434 Unfortunately, we can't access $0..$14, from unwinder code easily, so
435 store the return address in a frame slot too. FIXME: Only for
436 non-leaf functions. FIXME: Always with a landing pad, because it's
437 hard to know whether we need the other at the time we know we need
438 the offset for one (and have to state it). It's a kludge until we
439 can express the register stack in the EH frame info.
441 We have to do alignment here; get_frame_size will not return a
442 multiple of STACK_BOUNDARY. FIXME: Add note in manual. */
444 for (regno
= MMIX_FIRST_GLOBAL_REGNUM
;
447 if ((regs_ever_live
[regno
] && ! call_used_regs
[regno
])
448 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
452 + (MMIX_CFUN_HAS_LANDING_PAD
453 ? 16 : (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
? 8 : 0))
454 + (fromreg
== MMIX_ARG_POINTER_REGNUM
? 0 : 8);
457 /* Return an rtx for a function argument to go in a register, and 0 for
458 one that must go on stack. */
461 mmix_function_arg (argsp
, mode
, type
, named
, incoming
)
462 const CUMULATIVE_ARGS
* argsp
;
463 enum machine_mode mode
;
465 int named ATTRIBUTE_UNUSED
;
468 /* Handling of the positional dummy parameter for varargs gets nasty.
469 Check execute/991216-3 and function.c:assign_params. We have to say
470 that the dummy parameter goes on stack in order to get the correct
471 offset when va_start and va_arg is applied. FIXME: Should do TRT by
472 itself in the gcc core. */
473 if ((! named
&& incoming
&& current_function_varargs
) || argsp
->now_varargs
)
476 /* Last-argument marker. */
477 if (type
== void_type_node
)
478 return (argsp
->regs
< MMIX_MAX_ARGS_IN_REGS
)
481 ? MMIX_FIRST_INCOMING_ARG_REGNUM
482 : MMIX_FIRST_ARG_REGNUM
) + argsp
->regs
)
485 return (argsp
->regs
< MMIX_MAX_ARGS_IN_REGS
486 && !MUST_PASS_IN_STACK (mode
, type
)
487 && (GET_MODE_BITSIZE (mode
) <= 64
492 ? MMIX_FIRST_INCOMING_ARG_REGNUM
493 : MMIX_FIRST_ARG_REGNUM
)
498 /* Returns nonzero for everything that goes by reference, 0 for
499 everything that goes by value. */
502 mmix_function_arg_pass_by_reference (argsp
, mode
, type
, named
)
503 const CUMULATIVE_ARGS
* argsp
;
504 enum machine_mode mode
;
506 int named ATTRIBUTE_UNUSED
;
508 /* FIXME: Check: I'm not sure the MUST_PASS_IN_STACK check is
511 MUST_PASS_IN_STACK (mode
, type
)
512 || (MMIX_FUNCTION_ARG_SIZE (mode
, type
) > 8
517 /* Return nonzero if regno is a register number where a parameter is
518 passed, and 0 otherwise. */
521 mmix_function_arg_regno_p (regno
, incoming
)
526 = incoming
? MMIX_FIRST_INCOMING_ARG_REGNUM
: MMIX_FIRST_ARG_REGNUM
;
528 return regno
>= first_arg_regnum
529 && regno
< first_arg_regnum
+ MMIX_MAX_ARGS_IN_REGS
;
532 /* FUNCTION_OUTGOING_VALUE. */
535 mmix_function_outgoing_value (valtype
, func
)
537 tree func ATTRIBUTE_UNUSED
;
539 enum machine_mode mode
= TYPE_MODE (valtype
);
540 enum machine_mode cmode
;
541 int first_val_regnum
= MMIX_OUTGOING_RETURN_VALUE_REGNUM
;
542 rtx vec
[MMIX_MAX_REGS_FOR_VALUE
];
546 /* Return values that fit in a register need no special handling.
547 There's no register hole when parameters are passed in global
550 || GET_MODE_BITSIZE (mode
) <= BITS_PER_WORD
)
552 gen_rtx_REG (mode
, MMIX_OUTGOING_RETURN_VALUE_REGNUM
);
554 /* A complex type, made up of components. */
555 cmode
= TYPE_MODE (TREE_TYPE (valtype
));
556 nregs
= ((GET_MODE_BITSIZE (mode
) + BITS_PER_WORD
- 1) / BITS_PER_WORD
);
558 /* We need to take care of the effect of the register hole on return
559 values of large sizes; the last register will appear as the first
560 register, with the rest shifted. (For complex modes, this is just
561 swapped registers.) */
563 if (nregs
> MMIX_MAX_REGS_FOR_VALUE
)
564 internal_error ("too large function value type, needs %d registers,\
565 have only %d registers for this", nregs
, MMIX_MAX_REGS_FOR_VALUE
);
567 /* FIXME: Maybe we should handle structure values like this too
568 (adjusted for BLKmode), perhaps for both ABI:s. */
569 for (i
= 0; i
< nregs
- 1; i
++)
571 = gen_rtx_EXPR_LIST (VOIDmode
,
572 gen_rtx_REG (cmode
, first_val_regnum
+ i
),
573 GEN_INT ((i
+ 1) * BITS_PER_UNIT
));
576 = gen_rtx_EXPR_LIST (VOIDmode
,
577 gen_rtx_REG (cmode
, first_val_regnum
+ nregs
- 1),
580 return gen_rtx_PARALLEL (VOIDmode
, gen_rtvec_v (nregs
, vec
));
583 /* EH_RETURN_DATA_REGNO. */
586 mmix_eh_return_data_regno (n
)
587 int n ATTRIBUTE_UNUSED
;
590 return MMIX_EH_RETURN_DATA_REGNO_START
+ n
;
592 return INVALID_REGNUM
;
595 /* EH_RETURN_STACKADJ_RTX. */
598 mmix_eh_return_stackadj_rtx ()
600 return gen_rtx_REG (Pmode
, MMIX_EH_RETURN_STACKADJ_REGNUM
);
603 /* EH_RETURN_HANDLER_RTX. */
606 mmix_eh_return_handler_rtx ()
609 gen_rtx_REG (Pmode
, MMIX_INCOMING_RETURN_ADDRESS_REGNUM
);
612 /* ASM_PREFERRED_EH_DATA_FORMAT. */
615 mmix_asm_preferred_eh_data_format (code
, global
)
616 int code ATTRIBUTE_UNUSED
;
617 int global ATTRIBUTE_UNUSED
;
619 /* This is the default (was at 2001-07-20). Revisit when needed. */
620 return DW_EH_PE_absptr
;
623 /* Emit the function prologue. For simplicity while the port is still
624 in a flux, we do it as text rather than the now preferred RTL way,
625 as (define_insn "function_prologue").
627 FIXME: Translate to RTL and/or optimize some of the DWARF 2 stuff. */
630 mmix_target_asm_function_prologue (stream
, locals_size
)
632 HOST_WIDE_INT locals_size
;
635 int stack_space_to_allocate
636 = (current_function_outgoing_args_size
637 + current_function_pretend_args_size
638 + (int) locals_size
+ 8 + 7) & ~7;
640 int empty_stack_frame
641 = (current_function_outgoing_args_size
== 0
643 && current_function_pretend_args_size
== 0
644 && current_function_varargs
== 0
645 && current_function_stdarg
== 0);
646 int doing_dwarf
= dwarf2out_do_frame ();
649 /* Guard our assumptions. Very low priority FIXME. */
650 if (locals_size
!= (int) locals_size
)
651 error ("stack frame too big");
653 /* Add room needed to save global non-register-stack registers. */
655 regno
>= MMIX_FIRST_GLOBAL_REGNUM
;
657 /* Note that we assume that the frame-pointer-register is one of these
658 registers, in which case we don't count it here. */
659 if ((((regno
!= MMIX_FRAME_POINTER_REGNUM
|| !frame_pointer_needed
)
660 && regs_ever_live
[regno
] && !call_used_regs
[regno
]))
661 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
662 stack_space_to_allocate
+= 8;
664 /* If we do have a frame-pointer, add room for it. */
665 if (frame_pointer_needed
)
666 stack_space_to_allocate
+= 8;
668 /* If we have a non-local label, we need to be able to unwind to it, so
669 store the current register stack pointer. Also store the return
670 address if we do that. */
671 if (MMIX_CFUN_HAS_LANDING_PAD
)
672 stack_space_to_allocate
+= 16;
673 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
)
674 /* If we do have a saved return-address slot, add room for it. */
675 stack_space_to_allocate
+= 8;
677 /* Make sure we don't get an unaligned stack. */
678 if ((stack_space_to_allocate
% 8) != 0)
679 internal_error ("stack frame not a multiple of 8 bytes: %d",
680 stack_space_to_allocate
);
682 if (current_function_pretend_args_size
)
684 int mmix_first_vararg_reg
685 = (MMIX_FIRST_INCOMING_ARG_REGNUM
686 + (MMIX_MAX_ARGS_IN_REGS
687 - current_function_pretend_args_size
/ 8));
690 = MMIX_FIRST_INCOMING_ARG_REGNUM
+ MMIX_MAX_ARGS_IN_REGS
- 1;
691 regno
>= mmix_first_vararg_reg
;
697 = stack_space_to_allocate
> (256 - 8)
698 ? (256 - 8) : stack_space_to_allocate
;
700 fprintf (stream
, "\tSUBU %s,%s,%d\n",
701 reg_names
[MMIX_STACK_POINTER_REGNUM
],
702 reg_names
[MMIX_STACK_POINTER_REGNUM
],
707 /* Each call to dwarf2out_def_cfa overrides the previous
708 setting; they don't accumulate. We must keep track
709 of the offset ourselves. */
710 cfa_offset
+= stack_chunk
;
711 dwarf2out_def_cfa ("", MMIX_STACK_POINTER_REGNUM
,
714 offset
+= stack_chunk
;
715 stack_space_to_allocate
-= stack_chunk
;
718 fprintf (stream
, "\tSTOU %s,%s,%d\n", reg_names
[regno
],
719 reg_names
[MMIX_STACK_POINTER_REGNUM
],
722 /* These registers aren't actually saved (as in "will be
723 restored"), so don't tell DWARF2 they're saved. */
729 /* In any case, skip over the return-address slot. FIXME: Not needed
733 /* Store the frame-pointer. */
735 if (frame_pointer_needed
)
737 empty_stack_frame
= 0;
741 /* Get 8 less than otherwise, since we need to reach offset + 8. */
743 = stack_space_to_allocate
> (256 - 8 - 8)
744 ? (256 - 8 - 8) : stack_space_to_allocate
;
746 fprintf (stream
, "\tSUBU %s,%s,%d\n",
747 reg_names
[MMIX_STACK_POINTER_REGNUM
],
748 reg_names
[MMIX_STACK_POINTER_REGNUM
],
752 cfa_offset
+= stack_chunk
;
753 dwarf2out_def_cfa ("", MMIX_STACK_POINTER_REGNUM
,
756 offset
+= stack_chunk
;
757 stack_space_to_allocate
-= stack_chunk
;
760 fprintf (stream
, "\tSTOU %s,%s,%d\n\tADDU %s,%s,%d\n",
761 reg_names
[MMIX_FRAME_POINTER_REGNUM
],
762 reg_names
[MMIX_STACK_POINTER_REGNUM
],
764 reg_names
[MMIX_FRAME_POINTER_REGNUM
],
765 reg_names
[MMIX_STACK_POINTER_REGNUM
],
768 dwarf2out_reg_save ("", MMIX_FRAME_POINTER_REGNUM
,
769 -cfa_offset
+ offset
);
774 if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
)
776 /* Store the return-address, if one is needed on the stack. */
777 empty_stack_frame
= 0;
781 /* Get 8 less than otherwise, since we need to reach offset + 8. */
783 = stack_space_to_allocate
> (256 - 8 - 8)
784 ? (256 - 8 - 8) : stack_space_to_allocate
;
786 fprintf (stream
, "\tSUBU %s,%s,%d\n",
787 reg_names
[MMIX_STACK_POINTER_REGNUM
],
788 reg_names
[MMIX_STACK_POINTER_REGNUM
],
792 cfa_offset
+= stack_chunk
;
793 dwarf2out_def_cfa ("", MMIX_STACK_POINTER_REGNUM
,
796 offset
+= stack_chunk
;
797 stack_space_to_allocate
-= stack_chunk
;
800 fprintf (stream
, "\tGET $255,rJ\n\tSTOU $255,%s,%d\n",
801 reg_names
[MMIX_STACK_POINTER_REGNUM
],
804 dwarf2out_return_save ("", -cfa_offset
+ offset
);
807 else if (MMIX_CFUN_HAS_LANDING_PAD
)
810 if (MMIX_CFUN_HAS_LANDING_PAD
)
812 /* Store the register defining the numbering of local registers, so
813 we know how long to unwind the register stack. */
815 empty_stack_frame
= 0;
819 /* Get 8 less than otherwise, since we need to reach offset + 8. */
821 = stack_space_to_allocate
> (256 - 8 - 8)
822 ? (256 - 8 - 8) : stack_space_to_allocate
;
824 fprintf (stream
, "\tSUBU %s,%s,%d\n",
825 reg_names
[MMIX_STACK_POINTER_REGNUM
],
826 reg_names
[MMIX_STACK_POINTER_REGNUM
],
828 offset
+= stack_chunk
;
829 stack_space_to_allocate
-= stack_chunk
;
833 cfa_offset
+= stack_chunk
;
834 dwarf2out_def_cfa ("", MMIX_STACK_POINTER_REGNUM
,
839 /* We don't tell dwarf2 about this one; we just have it to unwind
840 the register stack at landing pads. FIXME: It's a kludge because
841 we can't describe the effect of the PUSHJ and PUSHGO insns on the
842 register stack at the moment. Best thing would be to handle it
843 like stack-pointer offsets. Better: some hook into dwarf2out.c
844 to produce DW_CFA_expression:s that specify the increment of rO,
845 and unwind it at eh_return (preferred) or at the landing pad.
846 Then saves to $0..$G-1 could be specified through that register. */
848 fprintf (stream
, "\tGET $255,rO\n\tSTOU $255,%s,%d\n",
849 reg_names
[MMIX_STACK_POINTER_REGNUM
], offset
);
854 /* After the return-address and the frame-pointer, we have the local
855 variables. They're the ones that may have an "unaligned" size. */
856 offset
-= (locals_size
+ 7) & ~7;
858 /* Now store all registers that are global, i.e. not saved by the
859 register file machinery.
861 It is assumed that the frame-pointer is one of these registers, so it
862 is explicitly excluded in the count. */
865 regno
>= MMIX_FIRST_GLOBAL_REGNUM
;
867 if (((regno
!= MMIX_FRAME_POINTER_REGNUM
|| !frame_pointer_needed
)
868 && regs_ever_live
[regno
] && ! call_used_regs
[regno
])
869 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
871 empty_stack_frame
= 0;
877 /* Since the local variables go above, we may get a large
881 /* We're not going to access the locals area in the
882 prologue, so we'll just silently subtract the slab we
885 stack_space_to_allocate
> (256 - offset
- 8)
886 ? (256 - offset
- 8) : stack_space_to_allocate
;
888 mmix_output_register_setting (stream
, 255, stack_chunk
, 1);
889 fprintf (stream
, "\tSUBU %s,%s,$255\n",
890 reg_names
[MMIX_STACK_POINTER_REGNUM
],
891 reg_names
[MMIX_STACK_POINTER_REGNUM
]);
895 cfa_offset
+= stack_chunk
;
896 dwarf2out_def_cfa ("", MMIX_STACK_POINTER_REGNUM
,
902 stack_chunk
= stack_space_to_allocate
> (256 - 8)
903 ? (256 - 8) : stack_space_to_allocate
;
905 fprintf (stream
, "\tSUBU %s,%s,%d\n",
906 reg_names
[MMIX_STACK_POINTER_REGNUM
],
907 reg_names
[MMIX_STACK_POINTER_REGNUM
], stack_chunk
);
910 cfa_offset
+= stack_chunk
;
911 dwarf2out_def_cfa ("", MMIX_STACK_POINTER_REGNUM
,
916 offset
+= stack_chunk
;
917 stack_space_to_allocate
-= stack_chunk
;
920 fprintf (stream
, "\tSTOU %s,%s,%d\n", reg_names
[regno
],
921 reg_names
[MMIX_STACK_POINTER_REGNUM
], offset
);
923 dwarf2out_reg_save ("", regno
, -cfa_offset
+ offset
);
927 /* Finally, allocate room for local vars (if they weren't allocated for
928 above) and outgoing args. This might be any number of bytes (well,
929 we assume it fits in a host-int).
930 Don't allocate (the return-address slot) if the stack frame is empty. */
931 if (stack_space_to_allocate
&& ! empty_stack_frame
)
933 if (stack_space_to_allocate
< 256)
935 fprintf (stream
, "\tSUBU %s,%s,%d\n",
936 reg_names
[MMIX_STACK_POINTER_REGNUM
],
937 reg_names
[MMIX_STACK_POINTER_REGNUM
],
938 stack_space_to_allocate
);
942 mmix_output_register_setting (stream
, 255,
943 stack_space_to_allocate
, 1);
944 fprintf (stream
, "\tSUBU %s,%s,$255\n",
945 reg_names
[MMIX_STACK_POINTER_REGNUM
],
946 reg_names
[MMIX_STACK_POINTER_REGNUM
]);
951 cfa_offset
+= stack_space_to_allocate
;
952 dwarf2out_def_cfa ("", MMIX_STACK_POINTER_REGNUM
,
957 /* We put the number of the highest saved register-file register in a
958 location convenient for the call-patterns to output. Note that we
959 don't tell dwarf2 about these registers, since it can't restore them
961 for (regno
= MMIX_LAST_REGISTER_FILE_REGNUM
;
964 if ((regs_ever_live
[regno
] && !call_used_regs
[regno
])
965 || (regno
== MMIX_FRAME_POINTER_REGNUM
&& frame_pointer_needed
))
968 mmix_highest_saved_stack_register
= regno
;
970 /* FIXME: A kludge for the MMIXware ABI. The return value comes back in
971 L of the caller, not just the register number of the X field of
972 PUSH{J,GO}. So we need to make L agree with that number if there's a
973 function call in this function that returns a value but takes no
974 parameters (if there were parameters, L would be set to at least the
975 first parameter register, $16). A real solution includes a pass to
976 test that settings of $15 (MMIX_RETURN_VALUE_REGNUM for the MMIXware
977 ABI) dominate all function calls that return a value. This could be
978 done in the planned machine_dep_reorg pass to rename all registers. */
979 if (! TARGET_ABI_GNU
&& cfun
->machine
->has_call_value_without_parameters
)
980 fprintf (stream
, "\tSET %s,%s\n",
981 reg_names
[MMIX_RETURN_VALUE_REGNUM
],
982 reg_names
[MMIX_RETURN_VALUE_REGNUM
]);
985 /* TARGET_ASM_FUNCTION_EPILOGUE. */
988 mmix_target_asm_function_epilogue (stream
, locals_size
)
990 HOST_WIDE_INT locals_size
;
994 int stack_space_to_deallocate
995 = (current_function_outgoing_args_size
996 + current_function_pretend_args_size
997 + (int) locals_size
+ 8 + 7) & ~7;
999 /* The assumption that locals_size fits in an int is asserted in
1000 mmix_target_asm_function_prologue. */
1002 /* The first address to access is beyond the outgoing_args area. */
1003 int offset
= current_function_outgoing_args_size
;
1004 int empty_stack_frame
1005 = (current_function_outgoing_args_size
== 0
1007 && current_function_pretend_args_size
== 0
1008 && ! MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
1009 && ! MMIX_CFUN_HAS_LANDING_PAD
);
1011 /* Add the space for global non-register-stack registers.
1012 It is assumed that the frame-pointer register can be one of these
1013 registers, in which case it is excluded from the count when needed. */
1015 regno
>= MMIX_FIRST_GLOBAL_REGNUM
;
1017 if (((regno
!= MMIX_FRAME_POINTER_REGNUM
|| !frame_pointer_needed
)
1018 && regs_ever_live
[regno
] && !call_used_regs
[regno
])
1019 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
1020 stack_space_to_deallocate
+= 8;
1022 /* Add in the space for register stack-pointer. If so, always add room
1023 for the saved PC. */
1024 if (MMIX_CFUN_HAS_LANDING_PAD
)
1025 stack_space_to_deallocate
+= 16;
1026 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
)
1027 /* If we have a saved return-address slot, add it in. */
1028 stack_space_to_deallocate
+= 8;
1030 /* Add in the frame-pointer. */
1031 if (frame_pointer_needed
)
1032 stack_space_to_deallocate
+= 8;
1034 /* Make sure we don't get an unaligned stack. */
1035 if ((stack_space_to_deallocate
% 8) != 0)
1036 internal_error ("stack frame not a multiple of octabyte: %d",
1037 stack_space_to_deallocate
);
1039 /* We will add back small offsets to the stack pointer as we go.
1040 First, we restore all registers that are global, i.e. not saved by
1041 the register file machinery. */
1043 for (regno
= MMIX_FIRST_GLOBAL_REGNUM
;
1046 if (((regno
!= MMIX_FRAME_POINTER_REGNUM
|| !frame_pointer_needed
)
1047 && regs_ever_live
[regno
] && !call_used_regs
[regno
])
1048 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
1050 empty_stack_frame
= 0;
1056 /* There's better support for incrementing than
1057 decrementing, so we might be able to optimize this as
1059 mmix_output_register_setting (stream
, 255, offset
, 1);
1060 fprintf (stream
, "\tADDU %s,%s,$255\n",
1061 reg_names
[MMIX_STACK_POINTER_REGNUM
],
1062 reg_names
[MMIX_STACK_POINTER_REGNUM
]);
1065 fprintf (stream
, "\tINCL %s,%d\n",
1066 reg_names
[MMIX_STACK_POINTER_REGNUM
], offset
);
1068 stack_space_to_deallocate
-= offset
;
1072 fprintf (stream
, "\tLDOU %s,%s,%d\n",
1074 reg_names
[MMIX_STACK_POINTER_REGNUM
],
1079 /* Here is where the local variables were. As in the prologue, they
1080 might be of an unaligned size. */
1081 offset
+= (locals_size
+ 7) & ~7;
1084 /* The saved register stack pointer is just below the frame-pointer
1085 register. We don't need to restore it "manually"; the POP
1086 instruction does that. */
1087 if (MMIX_CFUN_HAS_LANDING_PAD
)
1089 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
)
1090 /* The return-address slot is just below the frame-pointer register.
1091 We don't need to restore it because we don't really use it. */
1094 /* Get back the old frame-pointer-value. */
1095 if (frame_pointer_needed
)
1097 empty_stack_frame
= 0;
1103 /* There's better support for incrementing than
1104 decrementing, so we might be able to optimize this as
1106 mmix_output_register_setting (stream
, 255, offset
, 1);
1107 fprintf (stream
, "\tADDU %s,%s,$255\n",
1108 reg_names
[MMIX_STACK_POINTER_REGNUM
],
1109 reg_names
[MMIX_STACK_POINTER_REGNUM
]);
1112 fprintf (stream
, "\tINCL %s,%d\n",
1113 reg_names
[MMIX_STACK_POINTER_REGNUM
], offset
);
1115 stack_space_to_deallocate
-= offset
;
1119 fprintf (stream
, "\tLDOU %s,%s,%d\n",
1120 reg_names
[MMIX_FRAME_POINTER_REGNUM
],
1121 reg_names
[MMIX_STACK_POINTER_REGNUM
],
1126 /* Do not deallocate the return-address slot if the stack frame is
1127 empty, because then it was never allocated. */
1128 if (! empty_stack_frame
)
1130 /* We do not need to restore pretended incoming args, just add
1131 back offset to sp. */
1132 if (stack_space_to_deallocate
> 65535)
1134 /* There's better support for incrementing than decrementing, so
1135 we might be able to optimize this as we see a need. */
1136 mmix_output_register_setting (stream
, 255,
1137 stack_space_to_deallocate
, 1);
1138 fprintf (stream
, "\tADDU %s,%s,$255\n",
1139 reg_names
[MMIX_STACK_POINTER_REGNUM
],
1140 reg_names
[MMIX_STACK_POINTER_REGNUM
]);
1143 fprintf (stream
, "\tINCL %s,%d\n",
1144 reg_names
[MMIX_STACK_POINTER_REGNUM
],
1145 stack_space_to_deallocate
);
1148 if (current_function_calls_eh_return
)
1149 /* Adjustment the (normal) stack-pointer to that of the receiver.
1150 FIXME: It would be nice if we could also adjust the register stack
1151 here, but we need to express it through DWARF 2 too. */
1152 fprintf (stream
, "\tADDU %s,%s,%s\n",
1153 reg_names
[MMIX_STACK_POINTER_REGNUM
],
1154 reg_names
[MMIX_STACK_POINTER_REGNUM
],
1155 reg_names
[MMIX_EH_RETURN_STACKADJ_REGNUM
]);
1157 /* The extra \n is so we have a blank line between the assembly code of
1158 separate functions. */
1159 fprintf (stream
, "\tPOP %d,0\n\n",
1161 && current_function_return_rtx
!= NULL
1162 && ! current_function_returns_struct
)
1163 ? (GET_CODE (current_function_return_rtx
) == PARALLEL
1164 ? GET_NUM_ELEM (XVEC (current_function_return_rtx
, 0)) : 1)
1168 /* ASM_OUTPUT_MI_THUNK. */
1171 mmix_asm_output_mi_thunk (stream
, fndecl
, delta
, func
)
1173 tree fndecl ATTRIBUTE_UNUSED
;
1177 /* If you define STRUCT_VALUE to 0, rather than use STRUCT_VALUE_REGNUM,
1178 (i.e. pass location of structure to return as invisible first
1179 argument) you need to tweak this code too. */
1180 const char *regname
= reg_names
[MMIX_FIRST_INCOMING_ARG_REGNUM
];
1182 if (delta
>= 0 && delta
< 65536)
1183 asm_fprintf (stream
, "\tINCL %s,%d\n", delta
, regname
);
1184 else if (delta
< 0 && delta
>= -255)
1185 asm_fprintf (stream
, "\tSUBU %s,%s,%d\n", regname
, regname
, -delta
);
1188 mmix_output_register_setting (stream
, 255, delta
, 1);
1189 asm_fprintf (stream
, "\tADDU %s,%s,$255\n", regname
, regname
);
1192 fprintf (stream
, "\tJMP ");
1193 assemble_name (stream
, XSTR (XEXP (DECL_RTL (func
), 0), 0));
1194 fprintf (stream
, "\n");
1197 /* FUNCTION_PROFILER. */
1200 mmix_function_profiler (stream
, labelno
)
1201 FILE *stream ATTRIBUTE_UNUSED
;
1202 int labelno ATTRIBUTE_UNUSED
;
1204 sorry ("function_profiler support for MMIX");
1207 /* SETUP_INCOMING_VARARGS. */
1210 mmix_setup_incoming_varargs (args_so_farp
, mode
, vartype
, pretend_sizep
,
1212 CUMULATIVE_ARGS
* args_so_farp
;
1213 enum machine_mode mode
;
1215 int * pretend_sizep
;
1216 int second_time ATTRIBUTE_UNUSED
;
1218 /* For stdarg, the last named variable has been handled, but
1219 args_so_farp has not been advanced for it. For varargs, the current
1220 argument is to be counted to the anonymous ones. */
1221 if (current_function_stdarg
)
1223 if (args_so_farp
->regs
+ 1 < MMIX_MAX_ARGS_IN_REGS
)
1225 = (MMIX_MAX_ARGS_IN_REGS
- (args_so_farp
->regs
+ 1)) * 8;
1227 else if (current_function_varargs
)
1229 if (args_so_farp
->regs
< MMIX_MAX_ARGS_IN_REGS
)
1231 = (MMIX_MAX_ARGS_IN_REGS
- args_so_farp
->regs
) * 8;
1233 /* For varargs, we get here when we see the last named parameter,
1234 which will actually be passed on stack. So make the next call
1235 (there will be one) to FUNCTION_ARG return 0, to count it on
1236 stack, so va_arg for it will get right. FIXME: The GCC core
1237 should provide TRT. */
1238 args_so_farp
->now_varargs
= 1;
1241 internal_error ("neither varargs or stdarg in mmix_setup_incoming_varargs");
1244 /* We assume that one argument takes up one register here. That should
1245 be true until we start messing with multi-reg parameters. */
1246 if ((7 + (MMIX_FUNCTION_ARG_SIZE (mode
, vartype
))) / 8 != 1)
1247 internal_error ("MMIX Internal: Last named vararg would not fit in a register");
1250 /* EXPAND_BUILTIN_VA_ARG. */
1252 /* This is modified from the "standard" implementation of va_arg: read the
1253 value from the current (padded) address and increment by the (padded)
1254 size. The difference for MMIX is that if the type is
1255 pass-by-reference, then perform an indirection. */
1258 mmix_expand_builtin_va_arg (valist
, type
)
1263 HOST_WIDE_INT align
;
1264 HOST_WIDE_INT rounded_size
;
1267 /* Compute the rounded size of the type. */
1268 align
= PARM_BOUNDARY
/ BITS_PER_UNIT
;
1269 rounded_size
= (((int_size_in_bytes (type
) + align
- 1) / align
) * align
);
1274 if (AGGREGATE_TYPE_P (type
)
1275 && GET_MODE_UNIT_SIZE (TYPE_MODE (type
)) < 8
1276 && GET_MODE_UNIT_SIZE (TYPE_MODE (type
)) != 0)
1278 /* Adjust for big-endian the location of aggregates passed in a
1279 register, but where the aggregate is accessed in a shorter mode
1280 than the natural register mode (i.e. it is accessed as SFmode(?),
1281 SImode, HImode or QImode rather than DImode or DFmode(?)). FIXME:
1282 Or should we adjust the mode in which the aggregate is read, to be
1283 a register size mode? (Hum, nah, a small offset is generally
1284 cheaper than a wider memory access on MMIX.) */
1286 = build (PLUS_EXPR
, TREE_TYPE (addr_tree
), addr_tree
,
1287 build_int_2 ((BITS_PER_WORD
/ BITS_PER_UNIT
)
1288 - GET_MODE_UNIT_SIZE (TYPE_MODE (type
)), 0));
1293 adj
= TREE_INT_CST_LOW (TYPE_SIZE (type
)) / BITS_PER_UNIT
;
1294 if (rounded_size
> align
)
1297 addr_tree
= build (PLUS_EXPR
, TREE_TYPE (addr_tree
), addr_tree
,
1298 build_int_2 (rounded_size
- adj
, 0));
1300 /* If this type is larger than what fits in a register, then it is
1301 passed by reference. */
1302 if (rounded_size
> BITS_PER_WORD
/ BITS_PER_UNIT
)
1304 tree type_ptr
= build_pointer_type (type
);
1305 addr_tree
= build1 (INDIRECT_REF
, type_ptr
, addr_tree
);
1309 addr
= expand_expr (addr_tree
, NULL_RTX
, Pmode
, EXPAND_NORMAL
);
1310 addr
= copy_to_reg (addr
);
1312 /* Compute new value for AP. For MMIX, it is always advanced by the
1313 size of a register. */
1314 t
= build (MODIFY_EXPR
, TREE_TYPE (valist
), valist
,
1315 build (PLUS_EXPR
, TREE_TYPE (valist
), valist
,
1316 build_int_2 (BITS_PER_WORD
/ BITS_PER_UNIT
, 0)));
1317 TREE_SIDE_EFFECTS (t
) = 1;
1318 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
1323 /* TRAMPOLINE_SIZE. */
1324 /* Four 4-byte insns plus two 8-byte values. */
1325 int mmix_trampoline_size
= 32;
1328 /* TRAMPOLINE_TEMPLATE. */
1331 mmix_trampoline_template (stream
)
1334 /* Read a value from to static-chain, jump somewhere. The static chain
1335 is stored at offset 16, and the function address is stored at offset
1337 /* FIXME: GCC copies this using *intsize* (tetra), when it should use
1338 register size (octa). */
1339 fprintf (stream
, "\tGETA $255,1F\n\t");
1340 fprintf (stream
, "LDOU %s,$255,0\n\t",
1341 reg_names
[MMIX_STATIC_CHAIN_REGNUM
]);
1342 fprintf (stream
, "LDOU $255,$255,8\n\t");
1343 fprintf (stream
, "GO $255,$255,0\n");
1344 fprintf (stream
, "1H\tOCTA 0\n\t");
1345 fprintf (stream
, "OCTA 0\n");
1348 /* INITIALIZE_TRAMPOLINE. */
1349 /* Set the static chain and function pointer field in the trampoline.
1350 We also SYNCID here to be sure (doesn't matter in the simulator, but
1351 some day it will). */
1354 mmix_initialize_trampoline (trampaddr
, fnaddr
, static_chain
)
1359 emit_move_insn (gen_rtx_MEM (DImode
, plus_constant (trampaddr
, 16)),
1361 emit_move_insn (gen_rtx_MEM (DImode
,
1362 plus_constant (trampaddr
, 24)),
1364 emit_insn (gen_sync_icache (validize_mem (gen_rtx_MEM (DImode
,
1366 GEN_INT (mmix_trampoline_size
- 1)));
1369 /* We must exclude constant addresses that have an increment that is not a
1370 multiple of four bytes because of restrictions of the GETA
1371 instruction. FIXME: No, I don't think so. Just add a constraint. */
1374 mmix_constant_address_p (x
)
1377 RTX_CODE code
= GET_CODE (x
);
1380 if (code
== LABEL_REF
|| code
== SYMBOL_REF
)
1383 if (code
== CONSTANT_P_RTX
|| code
== HIGH
)
1384 /* FIXME: Don't know how to dissect these. Avoid them for now. */
1394 /* Can we get a naked PLUS? */
1395 case CONSTANT_P_RTX
:
1397 /* FIXME: Don't know how to dissect these. Avoid them for now. */
1401 addend
= INTVAL (x
);
1405 if (GET_MODE (x
) != VOIDmode
)
1406 /* Strange that we got here. FIXME: Check if we do. */
1408 addend
= CONST_DOUBLE_LOW (x
);
1412 /* Note that expressions with arithmetic on forward references don't
1413 work in mmixal. People using gcc assembly code with mmixal might
1414 need to move arrays and such to before the point of use. */
1415 if (GET_CODE (XEXP (x
, 0)) == PLUS
)
1417 rtx x0
= XEXP (XEXP (x
, 0), 0);
1418 rtx x1
= XEXP (XEXP (x
, 0), 1);
1420 if ((GET_CODE (x0
) == SYMBOL_REF
1421 || GET_CODE (x0
) == LABEL_REF
)
1422 && (GET_CODE (x1
) == CONST_INT
1423 || (GET_CODE (x1
) == CONST_DOUBLE
1424 && GET_MODE (x1
) == VOIDmode
)))
1425 addend
= mmix_intval (x1
);
1437 return (addend
& 3) == 0;
1440 /* Return 1 if the address is OK, otherwise 0.
1441 Used by GO_IF_LEGITIMATE_ADDRESS. */
1444 mmix_legitimate_address (mode
, x
, strict_checking
)
1445 enum machine_mode mode ATTRIBUTE_UNUSED
;
1447 int strict_checking
;
1449 #define MMIX_REG_OK(X) \
1451 && (REGNO (X) <= MMIX_LAST_GENERAL_REGISTER \
1452 || (reg_renumber[REGNO (X)] > 0 \
1453 && reg_renumber[REGNO (X)] <= MMIX_LAST_GENERAL_REGISTER))) \
1454 || (!strict_checking \
1455 && (REGNO (X) <= MMIX_LAST_GENERAL_REGISTER \
1456 || REGNO (X) >= FIRST_PSEUDO_REGISTER \
1457 || REGNO (X) == ARG_POINTER_REGNUM)))
1461 (mem (plus reg reg))
1462 (mem (plus reg 0..255)). */
1466 if (REG_P (x
) && MMIX_REG_OK (x
))
1469 if (GET_CODE(x
) == PLUS
)
1471 rtx x1
= XEXP (x
, 0);
1472 rtx x2
= XEXP (x
, 1);
1474 /* Try swapping the order. FIXME: Do we need this? */
1482 /* (mem (plus (reg) (?))) */
1483 if (!REG_P (x1
) || !MMIX_REG_OK (x1
))
1486 /* (mem (plus (reg) (reg))) */
1487 if (REG_P (x2
) && MMIX_REG_OK (x2
))
1490 /* (mem (plus (reg) (0..255))) */
1491 if (GET_CODE (x2
) == CONST_INT
1492 && CONST_OK_FOR_LETTER_P (INTVAL (x2
), 'I'))
1499 /* LEGITIMATE_CONSTANT_P. */
1502 mmix_legitimate_constant_p (x
)
1505 RTX_CODE code
= GET_CODE (x
);
1507 /* We must allow any number due to the way the cse passes works; if we
1508 do not allow any number here, general_operand will fail, and insns
1509 will fatally fail recognition instead of "softly". */
1510 if (code
== CONST_INT
|| code
== CONST_DOUBLE
)
1513 return CONSTANT_ADDRESS_P (x
);
1516 /* SELECT_CC_MODE. */
1519 mmix_select_cc_mode (op
, x
, y
)
1522 rtx y ATTRIBUTE_UNUSED
;
1524 /* We use CCmode, CC_UNSmode, CC_FPmode, CC_FPEQmode and CC_FUNmode to
1525 output different compare insns. Note that we do not check the
1526 validity of the comparison here. */
1528 if (GET_MODE_CLASS (GET_MODE (x
)) == MODE_FLOAT
)
1530 if (op
== ORDERED
|| op
== UNORDERED
|| op
== UNGE
1531 || op
== UNGT
|| op
== UNLE
|| op
== UNLT
)
1534 if (op
== EQ
|| op
== NE
)
1540 if (op
== GTU
|| op
== LTU
|| op
== GEU
|| op
== LEU
)
1546 /* CANONICALIZE_COMPARISON.
1547 FIXME: Check if the number adjustments trig. */
1550 mmix_canonicalize_comparison (codep
, op0p
, op1p
)
1552 rtx
* op0p ATTRIBUTE_UNUSED
;
1555 /* Change -1 to zero, if possible. */
1556 if ((*codep
== LE
|| *codep
== GT
)
1557 && GET_CODE (*op1p
) == CONST_INT
1558 && *op1p
== constm1_rtx
)
1560 *codep
= *codep
== LE
? LT
: GE
;
1564 /* Fix up 256 to 255, if possible. */
1565 if ((*codep
== LT
|| *codep
== LTU
|| *codep
== GE
|| *codep
== GEU
)
1566 && GET_CODE (*op1p
) == CONST_INT
1567 && INTVAL (*op1p
) == 256)
1569 /* FIXME: Remove when I know this trigs. */
1570 fatal_insn ("oops, not debugged; fixing up value:", *op1p
);
1571 *codep
= *codep
== LT
? LE
: *codep
== LTU
? LEU
: *codep
1573 *op1p
= GEN_INT (255);
1577 /* REVERSIBLE_CC_MODE. */
1580 mmix_reversible_cc_mode (mode
)
1581 enum machine_mode mode
;
1583 /* That is, all integer and the EQ, NE, ORDERED and UNORDERED float
1585 return mode
!= CC_FPmode
;
1588 /* DEFAULT_RTX_COSTS. */
1591 mmix_rtx_cost_recalculated (x
, code
, outer_code
, costp
)
1592 rtx x ATTRIBUTE_UNUSED
;
1593 RTX_CODE code ATTRIBUTE_UNUSED
;
1594 RTX_CODE outer_code ATTRIBUTE_UNUSED
;
1595 int *costp ATTRIBUTE_UNUSED
;
1597 /* For the time being, this is just a stub and we'll accept the
1598 generic calculations, until we can do measurements, at least.
1599 Say we did not modify any calculated costs. */
1606 mmix_address_cost (addr
)
1607 rtx addr ATTRIBUTE_UNUSED
;
1609 /* There's no difference in the address costs and we have lots of
1610 registers. Some targets use constant 0, many others use 1 to say
1611 this. Let's start with 1. */
1615 /* REGISTER_MOVE_COST. */
1618 mmix_register_move_cost (mode
, from
, to
)
1619 enum machine_mode mode ATTRIBUTE_UNUSED
;
1620 enum reg_class from
;
1623 return (from
== GENERAL_REGS
&& from
== to
) ? 2 : 3;
1626 /* Note that we don't have a TEXT_SECTION_ASM_OP, because it has to be a
1627 compile-time constant; it's used in an asm in crtstuff.c, compiled for
1630 /* DATA_SECTION_ASM_OP. */
1633 mmix_data_section_asm_op ()
1635 return "\t.data ! mmixal:= 8H LOC 9B";
1639 The meat is from elfos.h, which we will eventually consider using. */
1642 mmix_select_section (decl
, reloc
, align
)
1645 int align ATTRIBUTE_UNUSED
;
1647 if (TREE_CODE (decl
) == STRING_CST
)
1649 if (! flag_writable_strings
)
1654 else if (TREE_CODE (decl
) == VAR_DECL
)
1656 if ((flag_pic
&& reloc
)
1657 || !TREE_READONLY (decl
) || TREE_SIDE_EFFECTS (decl
)
1658 || !DECL_INITIAL (decl
)
1659 || (DECL_INITIAL (decl
) != error_mark_node
1660 && !TREE_CONSTANT (DECL_INITIAL (decl
))))
1665 else if (TREE_CODE (decl
) == CONSTRUCTOR
)
1667 if ((flag_pic
&& reloc
)
1668 || !TREE_READONLY (decl
) || TREE_SIDE_EFFECTS (decl
)
1669 || ! TREE_CONSTANT (decl
))
1678 /* ENCODE_SECTION_INFO. */
1681 mmix_encode_section_info (decl
)
1684 /* Test for an external declaration, and do nothing if it is one. */
1685 if ((TREE_CODE (decl
) == VAR_DECL
1686 && (DECL_EXTERNAL (decl
) || TREE_PUBLIC (decl
)))
1687 || (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_PUBLIC (decl
)))
1689 else if (DECL_P (decl
))
1691 /* For non-visible declarations, add a "@" prefix, which we skip
1692 when the label is output. If the label does not have this
1693 prefix, a ":" is output.
1695 Note that this does not work for data that is declared extern and
1696 later defined as static. If there's code in between, that code
1697 will refer to the extern declaration. And vice versa. Until we
1698 can get rid of mmixal, we have to assume that code is
1701 const char *str
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
1702 int len
= strlen (str
);
1705 /* Doing as rs6000 seems safe; always use ggc. Except don't copy
1706 the suspected off-by-one bug.
1707 FIXME: Is it still there? yes 2001-08-23
1708 Why is the return type of ggc_alloc_string const? */
1709 newstr
= (char *) ggc_alloc_string ("", len
+ 2);
1711 strcpy (newstr
+ 1, str
);
1713 XSTR (XEXP (DECL_RTL (decl
), 0), 0) = newstr
;
1716 /* FIXME: Later on, add SYMBOL_REF_FLAG for things that we can reach
1717 from here via GETA, to check in LEGITIMATE_CONSTANT_P. Needs to have
1718 different options for the cases where we want *all* to be assumed
1719 reachable via GETA, or all constant symbols, or just text symbols in
1720 this file, or perhaps just the constant pool. */
1723 /* STRIP_NAME_ENCODING. */
1726 mmix_strip_name_encoding (name
)
1729 for (; (*name
== '@' || *name
== '*'); name
++)
1736 The meat is from elfos.h, which we should consider using. */
1739 mmix_unique_section (decl
, reloc
)
1748 static const char *const prefixes
[4][2] =
1750 { ".text.", ".gnu.linkonce.t." },
1751 { ".rodata.", ".gnu.linkonce.r." },
1752 { ".data.", ".gnu.linkonce.d." },
1753 { ".bss.", ".gnu.linkonce.b." }
1756 if (TREE_CODE (decl
) == FUNCTION_DECL
)
1758 else if (DECL_INITIAL (decl
) == 0
1759 || DECL_INITIAL (decl
) == error_mark_node
)
1761 else if (DECL_READONLY_SECTION (decl
, reloc
))
1766 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
1767 /* Strip off any encoding in name. */
1768 STRIP_NAME_ENCODING (name
, name
);
1769 prefix
= prefixes
[sec
][DECL_ONE_ONLY (decl
)];
1770 len
= strlen (name
) + strlen (prefix
);
1771 string
= alloca (len
+ 1);
1773 sprintf (string
, "%s%s", prefix
, name
);
1775 DECL_SECTION_NAME (decl
) = build_string (len
, string
);
1778 /* ASM_FILE_START. */
1781 mmix_asm_file_start (stream
)
1784 /* We just emit a little comment for the time being. FIXME: Perhaps add
1785 -mstandalone and some segment and prefix setup here. */
1786 ASM_OUTPUT_SOURCE_FILENAME (stream
, main_input_filename
);
1788 fprintf (stream
, "! mmixal:= 8H LOC Data_Section\n");
1790 /* Make sure each file starts with the text section. */
1797 mmix_asm_file_end (stream
)
1798 FILE * stream ATTRIBUTE_UNUSED
;
1800 /* Make sure each file ends with the data section. */
1804 /* ASM_IDENTIFY_GCC. */
1807 mmix_asm_identify_gcc (stream
)
1810 /* No real need for the time being. May be useful to GDB later on. */
1811 fprintf (stream
, "# Compiled by GCC version %s\n",
1815 /* ASM_OUTPUT_SOURCE_FILENAME. */
1818 mmix_asm_output_source_filename (stream
, name
)
1822 fprintf (stream
, "# 1 ");
1823 OUTPUT_QUOTED_STRING (stream
, name
);
1824 fprintf (stream
, "\n");
1827 /* OUTPUT_QUOTED_STRING. */
1830 mmix_output_quoted_string (stream
, string
, length
)
1832 const char * string
;
1835 const char * string_end
= string
+ length
;
1836 static const char *const unwanted_chars
= "\"[]\\";
1838 /* Output "any character except newline and double quote character". We
1839 play it safe and avoid all control characters too. We also do not
1840 want [] as characters, should input be passed through m4 with [] as
1841 quotes. Further, we avoid "\", because the GAS port handles it as a
1842 quoting character. */
1843 while (string
< string_end
)
1846 && (unsigned char) *string
< 128
1847 && !ISCNTRL (*string
)
1848 && strchr (unwanted_chars
, *string
) == NULL
)
1850 fputc ('"', stream
);
1852 && (unsigned char) *string
< 128
1853 && !ISCNTRL (*string
)
1854 && strchr (unwanted_chars
, *string
) == NULL
1855 && string
< string_end
)
1857 fputc (*string
, stream
);
1860 fputc ('"', stream
);
1861 if (string
< string_end
)
1862 fprintf (stream
, ",");
1864 if (string
< string_end
)
1866 fprintf (stream
, "#%x", *string
& 255);
1868 if (string
< string_end
)
1869 fprintf (stream
, ",");
1874 /* ASM_OUTPUT_SOURCE_LINE. */
1877 mmix_asm_output_source_line (stream
, lineno
)
1881 fprintf (stream
, "# %d ", lineno
);
1882 OUTPUT_QUOTED_STRING (stream
, main_input_filename
);
1883 fprintf (stream
, "\n");
1886 /* Target hook for assembling integer objects. Use mmix_print_operand
1887 for WYDE and TETRA. Use mmix_output_octa to output 8-byte
1891 mmix_assemble_integer (x
, size
, aligned_p
)
1900 fputs ("\tBYTE\t", asm_out_file
);
1901 mmix_print_operand (asm_out_file
, x
, 'B');
1902 fputc ('\n', asm_out_file
);
1906 fputs ("\tWYDE\t", asm_out_file
);
1907 mmix_print_operand (asm_out_file
, x
, 'W');
1908 fputc ('\n', asm_out_file
);
1912 fputs ("\tTETRA\t", asm_out_file
);
1913 mmix_print_operand (asm_out_file
, x
, 'L');
1914 fputc ('\n', asm_out_file
);
1918 if (GET_CODE (x
) == CONST_DOUBLE
)
1919 mmix_output_octa (asm_out_file
, mmix_intval (x
), 0);
1921 assemble_integer_with_op ("\tOCTA\t", x
);
1924 return default_assemble_integer (x
, size
, aligned_p
);
1927 /* ASM_OUTPUT_ASCII. */
1930 mmix_asm_output_ascii (stream
, string
, length
)
1937 int chunk_size
= length
> 60 ? 60 : length
;
1938 fprintf (stream
, "\tBYTE ");
1939 mmix_output_quoted_string (stream
, string
, chunk_size
);
1940 string
+= chunk_size
;
1941 length
-= chunk_size
;
1942 fprintf (stream
, "\n");
1946 /* ASM_OUTPUT_ALIGNED_COMMON. */
1949 mmix_asm_output_aligned_common (stream
, name
, size
, align
)
1955 /* This is mostly the elfos.h one. There doesn't seem to be a way to
1956 express this in a mmixal-compatible way. */
1957 fprintf (stream
, "\t.comm\t");
1958 assemble_name (stream
, name
);
1959 fprintf (stream
, ",%u,%u ! mmixal-incompatible COMMON\n",
1960 size
, align
/ BITS_PER_UNIT
);
1963 /* ASM_OUTPUT_ALIGNED_LOCAL. */
1966 mmix_asm_output_aligned_local (stream
, name
, size
, align
)
1974 ASM_OUTPUT_ALIGN (stream
, exact_log2 (align
/BITS_PER_UNIT
));
1975 assemble_name (stream
, name
);
1976 fprintf (stream
, "\tLOC @+%d\n", size
);
1979 /* ASM_OUTPUT_LABEL. */
1982 mmix_asm_output_label (stream
, name
)
1986 assemble_name (stream
, name
);
1987 fprintf (stream
, "\tIS @\n");
1990 /* ASM_DECLARE_REGISTER_GLOBAL. */
1993 mmix_asm_declare_register_global (stream
, decl
, regno
, name
)
1994 FILE *stream ATTRIBUTE_UNUSED
;
1995 tree decl ATTRIBUTE_UNUSED
;
1996 int regno ATTRIBUTE_UNUSED
;
1997 const char *name ATTRIBUTE_UNUSED
;
1999 /* Nothing to do here, but there *will* be, therefore the framework is
2003 /* ASM_GLOBALIZE_LABEL. */
2006 mmix_asm_globalize_label (stream
, name
)
2007 FILE * stream ATTRIBUTE_UNUSED
;
2008 const char * name ATTRIBUTE_UNUSED
;
2010 asm_fprintf (stream
, "\t.global ");
2011 assemble_name (stream
, name
);
2012 putc ('\n', stream
);
2015 /* ASM_WEAKEN_LABEL. */
2018 mmix_asm_weaken_label (stream
, name
)
2019 FILE * stream ATTRIBUTE_UNUSED
;
2020 const char * name ATTRIBUTE_UNUSED
;
2022 asm_fprintf (stream
, "\t.weak ");
2023 assemble_name (stream
, name
);
2024 asm_fprintf (stream
, " ! mmixal-incompatible\n");
2027 /* MAKE_DECL_ONE_ONLY. */
2030 mmix_make_decl_one_only (decl
)
2033 DECL_WEAK (decl
) = 1;
2036 /* ASM_OUTPUT_LABELREF.
2037 Strip GCC's '*' and our own '@'. No order is assumed. */
2040 mmix_asm_output_labelref (stream
, name
)
2046 for (; (*name
== '@' || *name
== '*'); name
++)
2050 asm_fprintf (stream
, "%s%U%s",
2051 is_extern
&& TARGET_TOPLEVEL_SYMBOLS
? ":" : "",
2055 /* ASM_OUTPUT_INTERNAL_LABEL. */
2058 mmix_asm_output_internal_label (stream
, name
, num
)
2063 fprintf (stream
, "%s:%d\tIS @\n", name
, num
);
2066 /* ASM_OUTPUT_DEF. */
2069 mmix_asm_output_def (stream
, name
, value
)
2074 assemble_name (stream
, name
);
2075 fprintf (stream
, "\tIS ");
2076 assemble_name (stream
, value
);
2077 fputc ('\n', stream
);
2080 /* ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL. */
2083 mmix_asm_output_define_label_difference_symbol (stream
, symbol
, hi
, lo
)
2089 assemble_name (stream
, symbol
);
2090 fprintf (stream
, "\tIS\t");
2091 assemble_name (stream
, hi
);
2092 fputc ('-', stream
);
2093 assemble_name (stream
, lo
);
2094 fprintf (stream
, "\n");
2097 /* PRINT_OPERAND. */
2100 mmix_print_operand (stream
, x
, code
)
2105 /* When we add support for different codes later, we can, when needed,
2106 drop through to the main handler with a modified operand. */
2111 /* Unrelated codes are in alphabetic order. */
2114 /* For conditional branches, output "P" for a probable branch. */
2115 if (TARGET_BRANCH_PREDICT
)
2117 x
= find_reg_note (current_output_insn
, REG_BR_PROB
, 0);
2118 if (x
&& INTVAL (XEXP (x
, 0)) > REG_BR_PROB_BASE
/ 2)
2124 if (GET_CODE (x
) != CONST_INT
)
2125 fatal_insn ("MMIX Internal: Expected a CONST_INT, not this", x
);
2126 fprintf (stream
, "%d", (int) (INTVAL (x
) & 0xff));
2130 /* Highpart. Must be general register, and not the last one, as
2131 that one cannot be part of a consecutive register pair. */
2132 if (REGNO (x
) > MMIX_LAST_GENERAL_REGISTER
- 1)
2133 internal_error ("MMIX Internal: Bad register: %d", REGNO (x
));
2135 /* This is big-endian, so the high-part is the first one. */
2136 fprintf (stream
, "%s", reg_names
[REGNO (x
)]);
2140 /* Lowpart. Must be CONST_INT or general register, and not the last
2141 one, as that one cannot be part of a consecutive register pair. */
2142 if (GET_CODE (x
) == CONST_INT
)
2144 fprintf (stream
, "#%lx",
2145 (unsigned long) (INTVAL (x
)
2146 & ((unsigned int) 0x7fffffff * 2 + 1)));
2150 if (GET_CODE (x
) == SYMBOL_REF
)
2152 output_addr_const (stream
, x
);
2156 if (REGNO (x
) > MMIX_LAST_GENERAL_REGISTER
- 1)
2157 internal_error ("MMIX Internal: Bad register: %d", REGNO (x
));
2159 /* This is big-endian, so the low-part is + 1. */
2160 fprintf (stream
, "%s", reg_names
[REGNO (x
) + 1]);
2163 /* Can't use 'a' because that's a generic modifier for address
2166 mmix_output_shiftvalue_op_from_str (stream
, "ANDN",
2167 ~(unsigned HOST_WIDEST_INT
)
2172 mmix_output_shiftvalue_op_from_str (stream
, "INC",
2173 (unsigned HOST_WIDEST_INT
)
2178 mmix_output_shiftvalue_op_from_str (stream
, "OR",
2179 (unsigned HOST_WIDEST_INT
)
2184 mmix_output_shiftvalue_op_from_str (stream
, "SET",
2185 (unsigned HOST_WIDEST_INT
)
2191 mmix_output_condition (stream
, x
, (code
== 'D'));
2195 /* Output an extra "e" to make fcmpe, fune. */
2196 if (TARGET_FCMP_EPSILON
)
2197 fprintf (stream
, "e");
2201 /* Output the number minus 1. */
2202 if (GET_CODE (x
) != CONST_INT
)
2204 fatal_insn ("MMIX Internal: Bad value for 'm', not a CONST_INT",
2207 fprintf (stream
, HOST_WIDEST_INT_PRINT_DEC
,
2208 (HOST_WIDEST_INT
) (mmix_intval (x
) - 1));
2212 /* Store the number of registers we want to save. This was setup
2213 by the prologue. The actual operand contains the number of
2214 registers to pass, but we don't use it currently. Anyway, we
2215 need to output the number of saved registers here. */
2217 fprintf (stream
, "%d", mmix_highest_saved_stack_register
+ 1);
2219 /* FIXME: Get the effect of renaming $16, $17.. to the first
2220 unused call-saved reg. */
2221 fprintf (stream
, "15");
2225 /* Store the register to output a constant to. */
2227 fatal_insn ("MMIX Internal: Expected a register, not this", x
);
2228 mmix_output_destination_register
= REGNO (x
);
2232 /* Output the constant. Note that we use this for floats as well. */
2233 if (GET_CODE (x
) != CONST_INT
2234 && (GET_CODE (x
) != CONST_DOUBLE
2235 || (GET_MODE (x
) != VOIDmode
&& GET_MODE (x
) != DFmode
2236 && GET_MODE (x
) != SFmode
)))
2237 fatal_insn ("MMIX Internal: Expected a constant, not this", x
);
2238 mmix_output_register_setting (stream
,
2239 mmix_output_destination_register
,
2240 mmix_intval (x
), 0);
2244 /* An U for unsigned, if TARGET_ZERO_EXTEND. Ignore the operand. */
2245 if (TARGET_ZERO_EXTEND
)
2250 mmix_output_shifted_value (stream
, (HOST_WIDEST_INT
) mmix_intval (x
));
2254 mmix_output_shifted_value (stream
, (HOST_WIDEST_INT
) ~mmix_intval (x
));
2258 if (GET_CODE (x
) != CONST_INT
)
2259 fatal_insn ("MMIX Internal: Expected a CONST_INT, not this", x
);
2260 fprintf (stream
, "#%x", (int) (INTVAL (x
) & 0xffff));
2264 /* Nothing to do. */
2268 /* Presumably there's a missing case above if we get here. */
2269 internal_error ("MMIX Internal: Missing `%c' case in mmix_print_operand", code
);
2272 switch (GET_CODE (modified_x
))
2275 if (REGNO (modified_x
) >= FIRST_PSEUDO_REGISTER
)
2276 internal_error ("MMIX Internal: Bad register: %d", REGNO (modified_x
));
2277 fprintf (stream
, "%s", reg_names
[REGNO (modified_x
)]);
2281 output_address (XEXP (modified_x
, 0));
2285 /* For -2147483648, mmixal complains that the constant does not fit
2286 in 4 bytes, so let's output it as hex. Take care to handle hosts
2287 where HOST_WIDE_INT is longer than an int.
2289 Print small constants +-255 using decimal. */
2291 if (INTVAL (modified_x
) > -256 && INTVAL (modified_x
) < 256)
2292 fprintf (stream
, "%d", (int) (INTVAL (modified_x
)));
2294 fprintf (stream
, "#%x",
2295 (int) (INTVAL (modified_x
)) & (unsigned int) ~0);
2299 /* Do somewhat as CONST_INT. */
2300 mmix_output_octa (stream
, mmix_intval (modified_x
), 0);
2304 output_addr_const (stream
, modified_x
);
2308 /* No need to test for all strange things. Let output_addr_const do
2310 if (CONSTANT_P (modified_x
)
2311 /* Strangely enough, this is not included in CONSTANT_P.
2312 FIXME: Ask/check about sanity here. */
2313 || GET_CODE (modified_x
) == CODE_LABEL
)
2315 output_addr_const (stream
, modified_x
);
2319 /* We need the original here. */
2320 fatal_insn ("MMIX Internal: Cannot decode this operand", x
);
2324 /* PRINT_OPERAND_PUNCT_VALID_P. */
2327 mmix_print_operand_punct_valid_p (code
)
2328 int code ATTRIBUTE_UNUSED
;
2330 /* A '+' is used for branch prediction, similar to other ports. */
2334 /* PRINT_OPERAND_ADDRESS. */
2337 mmix_print_operand_address (stream
, x
)
2343 /* I find the generated assembly code harder to read without
2345 fprintf (stream
, "%s,0",reg_names
[REGNO (x
)]);
2348 else if (GET_CODE (x
) == PLUS
)
2350 rtx x1
= XEXP (x
, 0);
2351 rtx x2
= XEXP (x
, 1);
2353 /* Try swap the order. FIXME: Do we need this? */
2363 fprintf (stream
, "%s,", reg_names
[REGNO (x1
)]);
2367 fprintf (stream
, "%s", reg_names
[REGNO (x2
)]);
2370 else if (GET_CODE (x2
) == CONST_INT
2371 && CONST_OK_FOR_LETTER_P (INTVAL (x2
), 'I'))
2373 output_addr_const (stream
, x2
);
2379 fatal_insn ("MMIX Internal: This is not a recognized address", x
);
2382 /* ASM_OUTPUT_REG_PUSH. */
2385 mmix_asm_output_reg_push (stream
, regno
)
2389 fprintf (stream
, "\tSUBU %s,%s,8\n\tSTOU %s,%s,0\n",
2390 reg_names
[MMIX_STACK_POINTER_REGNUM
],
2391 reg_names
[MMIX_STACK_POINTER_REGNUM
],
2393 reg_names
[MMIX_STACK_POINTER_REGNUM
]);
2396 /* ASM_OUTPUT_REG_POP. */
2399 mmix_asm_output_reg_pop (stream
, regno
)
2403 fprintf (stream
, "\tLDOU %s,%s,0\n\tINCL %s,8\n",
2405 reg_names
[MMIX_STACK_POINTER_REGNUM
],
2406 reg_names
[MMIX_STACK_POINTER_REGNUM
]);
2409 /* ASM_OUTPUT_ADDR_DIFF_ELT. */
2412 mmix_asm_output_addr_diff_elt (stream
, body
, value
, rel
)
2414 rtx body ATTRIBUTE_UNUSED
;
2418 fprintf (stream
, "\tTETRA L%d-L%d\n", value
, rel
);
2421 /* ASM_OUTPUT_ADDR_VEC_ELT. */
2424 mmix_asm_output_addr_vec_elt (stream
, value
)
2428 fprintf (stream
, "\tOCTA L:%d\n", value
);
2431 /* ASM_OUTPUT_SKIP. */
2434 mmix_asm_output_skip (stream
, nbytes
)
2438 fprintf (stream
, "\tLOC @+%d\n", nbytes
);
2441 /* ASM_OUTPUT_ALIGN. */
2444 mmix_asm_output_align (stream
, power
)
2448 /* We need to record the needed alignment of this section in the object,
2449 so we have to output an alignment directive. Use a .p2align (not
2450 .align) so people will never have to wonder about whether the
2451 argument is in number of bytes or the log2 thereof. We do it in
2452 addition to the LOC directive, so nothing needs tweaking when
2453 copy-pasting assembly into mmixal. */
2454 fprintf (stream
, "\t.p2align %d\n", power
);
2455 fprintf (stream
, "\tLOC @+(%d-@)&%d\n", 1 << power
, (1 << power
) - 1);
2458 /* DBX_REGISTER_NUMBER. */
2461 mmix_dbx_register_number (regno
)
2464 /* FIXME: Implement final register renumbering if necessary. (Use
2465 target state in cfun). */
2467 /* We need to renumber registers to get the number of the return address
2468 register in the range 0..255. It is also space-saving if registers
2469 mentioned in the call-frame information (which uses this function by
2470 defaulting DWARF_FRAME_REGNUM to DBX_REGISTER_NUMBER) are numbered
2471 0 .. 63. So map 224 .. 256+15 -> 0 .. 47 and 0 .. 223 -> 48..223+48. */
2472 return regno
>= 224 ? (regno
- 224) : (regno
+ 48);
2475 /* End of target macro support functions.
2477 Now MMIX's own functions. First the exported ones. */
2479 /* Output an optimal sequence for setting a register to a specific
2480 constant. Used in an alternative for const_ints in movdi, and when
2481 using large stack-frame offsets.
2483 Use do_begin_end to say if a line-starting TAB and newline before the
2484 first insn and after the last insn is wanted. */
2487 mmix_output_register_setting (stream
, regno
, value
, do_begin_end
)
2490 HOST_WIDEST_INT value
;
2494 fprintf (stream
, "\t");
2496 if (mmix_shiftable_wyde_value ((unsigned HOST_WIDEST_INT
) value
))
2498 /* First, the one-insn cases. */
2499 mmix_output_shiftvalue_op_from_str (stream
, "SET",
2500 (unsigned HOST_WIDEST_INT
)
2502 fprintf (stream
, " %s,", reg_names
[regno
]);
2503 mmix_output_shifted_value (stream
, (unsigned HOST_WIDEST_INT
) value
);
2505 else if (mmix_shiftable_wyde_value (-(unsigned HOST_WIDEST_INT
) value
))
2507 /* We do this to get a bit more legible assembly code. The next
2508 alternative is mostly redundant with this. */
2510 mmix_output_shiftvalue_op_from_str (stream
, "SET",
2511 -(unsigned HOST_WIDEST_INT
)
2513 fprintf (stream
, " %s,", reg_names
[regno
]);
2514 mmix_output_shifted_value (stream
, -(unsigned HOST_WIDEST_INT
) value
);
2515 fprintf (stream
, "\n\tNEGU %s,0,%s", reg_names
[regno
],
2518 else if (mmix_shiftable_wyde_value (~(unsigned HOST_WIDEST_INT
) value
))
2520 /* Slightly more expensive, the two-insn cases. */
2522 /* FIXME: We could of course also test if 0..255-N or ~(N | 1..255)
2523 is shiftable, or any other one-insn transformation of the value.
2524 FIXME: Check first if the value is "shiftable" by two loading
2525 with two insns, since it makes more readable assembly code (if
2526 anyone else cares). */
2528 mmix_output_shiftvalue_op_from_str (stream
, "SET",
2529 ~(unsigned HOST_WIDEST_INT
)
2531 fprintf (stream
, " %s,", reg_names
[regno
]);
2532 mmix_output_shifted_value (stream
, ~(unsigned HOST_WIDEST_INT
) value
);
2533 fprintf (stream
, "\n\tNOR %s,%s,0", reg_names
[regno
],
2538 /* The generic case. 2..4 insns. */
2539 static const char *const higher_parts
[] = {"L", "ML", "MH", "H"};
2540 const char *op
= "SET";
2541 const char *line_begin
= "";
2544 /* Output pertinent parts of the 4-wyde sequence.
2545 Still more to do if we want this to be optimal, but hey...
2546 Note that the zero case has been handled above. */
2547 for (i
= 0; i
< 4 && value
!= 0; i
++)
2551 fprintf (stream
, "%s%s%s %s,#%x", line_begin
, op
,
2552 higher_parts
[i
], reg_names
[regno
],
2553 (int) (value
& 65535));
2554 /* The first one sets the rest of the bits to 0, the next
2555 ones add set bits. */
2557 line_begin
= "\n\t";
2565 fprintf (stream
, "\n");
2568 /* Return 1 if value is 0..65535*2**(16*N) for N=0..3.
2572 mmix_shiftable_wyde_value (value
)
2573 unsigned HOST_WIDEST_INT value
;
2575 /* Shift by 16 bits per group, stop when we've found two groups with
2578 int has_candidate
= 0;
2580 for (i
= 0; i
< 4; i
++)
2596 /* True if this is an address_operand or a symbolic operand. */
2599 mmix_symbolic_or_address_operand (op
, mode
)
2601 enum machine_mode mode
;
2603 switch (GET_CODE (op
))
2610 if ((GET_CODE (XEXP (op
, 0)) == SYMBOL_REF
2611 || GET_CODE (XEXP (op
, 0)) == LABEL_REF
)
2612 && (GET_CODE (XEXP (op
, 1)) == CONST_INT
2613 || (GET_CODE (XEXP (op
, 1)) == CONST_DOUBLE
2614 && GET_MODE (XEXP (op
, 1)) == VOIDmode
)))
2618 return address_operand (op
, mode
);
2622 /* True if this is a register or CONST_INT (or CONST_DOUBLE for DImode).
2623 We could narrow the value down with a couple of predicated, but that
2624 doesn't seem to be worth it at the moment. */
2627 mmix_reg_or_constant_operand (op
, mode
)
2629 enum machine_mode mode
;
2631 return register_operand (op
, mode
)
2632 || (GET_CODE (op
) == CONST_DOUBLE
&& GET_MODE (op
) == VOIDmode
)
2633 || GET_CODE (op
) == CONST_INT
;
2636 /* True if this is a register with a condition-code mode. */
2639 mmix_reg_cc_operand (op
, mode
)
2641 enum machine_mode mode
;
2643 if (mode
== VOIDmode
)
2644 mode
= GET_MODE (op
);
2646 return register_operand (op
, mode
)
2647 && (mode
== CCmode
|| mode
== CC_UNSmode
|| mode
== CC_FPmode
2648 || mode
== CC_FPEQmode
|| mode
== CC_FUNmode
);
2651 /* True if this is a foldable comparison operator
2652 - one where a the result of (compare:CC (reg) (const_int 0)) can be
2653 replaced by (reg). */
2656 mmix_foldable_comparison_operator (op
, mode
)
2658 enum machine_mode mode
;
2660 RTX_CODE code
= GET_CODE (op
);
2662 if (mode
== VOIDmode
)
2663 mode
= GET_MODE (op
);
2665 if (mode
== VOIDmode
&& GET_RTX_CLASS (GET_CODE (op
)) == '<')
2666 mode
= GET_MODE (XEXP (op
, 0));
2668 return ((mode
== CCmode
|| mode
== DImode
)
2669 && (code
== NE
|| code
== EQ
|| code
== GE
|| code
== GT
2671 /* FIXME: This may be a stupid trick. What happens when GCC wants to
2672 reverse the condition? Can it do that by itself? Maybe it can
2673 even reverse the condition to fit a foldable one in the first
2675 || (mode
== CC_UNSmode
&& (code
== GTU
|| code
== LEU
));
2678 /* Like comparison_operator, but only true if this comparison operator is
2679 applied to a valid mode. Needed to avoid jump.c generating invalid
2680 code with -ffast-math (gcc.dg/20001228-1.c). */
2683 mmix_comparison_operator (op
, mode
)
2685 enum machine_mode mode
;
2687 RTX_CODE code
= GET_CODE (op
);
2689 /* Comparison operators usually don't have a mode, but let's try and get
2690 one anyway for the day that changes. */
2691 if (mode
== VOIDmode
)
2692 mode
= GET_MODE (op
);
2694 /* Get the mode from the first operand if we don't have one. */
2695 if (mode
== VOIDmode
&& GET_RTX_CLASS (GET_CODE (op
)) == '<')
2696 mode
= GET_MODE (XEXP (op
, 0));
2698 /* FIXME: This needs to be kept in sync with the tables in
2699 mmix_output_condition. */
2701 (mode
== VOIDmode
&& GET_RTX_CLASS (GET_CODE (op
)) == '<')
2702 || (mode
== CC_FUNmode
2703 && (code
== ORDERED
|| code
== UNORDERED
))
2704 || (mode
== CC_FPmode
2705 && (code
== GT
|| code
== LT
))
2706 || (mode
== CC_FPEQmode
2707 && (code
== NE
|| code
== EQ
))
2708 || (mode
== CC_UNSmode
2709 && (code
== GEU
|| code
== GTU
|| code
== LEU
|| code
== LTU
))
2711 && (code
== NE
|| code
== EQ
|| code
== GE
|| code
== GT
2712 || code
== LE
|| code
== LT
))
2714 && (code
== NE
|| code
== EQ
|| code
== GE
|| code
== GT
2715 || code
== LE
|| code
== LT
|| code
== LEU
|| code
== GTU
));
2718 /* True if this is a register or 0 (int or float). */
2721 mmix_reg_or_0_operand (op
, mode
)
2723 enum machine_mode mode
;
2725 /* FIXME: Is mode calculation necessary and correct? */
2727 op
== CONST0_RTX (mode
== VOIDmode
? GET_MODE (op
) : mode
)
2728 || register_operand (op
, mode
);
2731 /* True if this is a register or an int 0..255. */
2734 mmix_reg_or_8bit_operand (op
, mode
)
2736 enum machine_mode mode
;
2738 return register_operand (op
, mode
)
2739 || (GET_CODE (op
) == CONST_INT
2740 && CONST_OK_FOR_LETTER_P (INTVAL (op
), 'I'));
2743 /* True if this is a register or an int 0..256. We include 256,
2744 because it can be canonicalized into 255 for comparisons, which is
2745 currently the only use of this predicate.
2746 FIXME: Check that this happens and does TRT. */
2749 mmix_reg_or_8bit_or_256_operand (op
, mode
)
2751 enum machine_mode mode
;
2753 return mmix_reg_or_8bit_operand (op
, mode
)
2754 || (GET_CODE (op
) == CONST_INT
&& INTVAL (op
) == 256);
2757 /* Returns zero if code and mode is not a valid condition from a
2758 compare-type insn. Nonzero if it is. The parameter op, if non-NULL,
2759 is the comparison of mode is CC-somethingmode. */
2762 mmix_valid_comparison (code
, mode
, op
)
2764 enum machine_mode mode
;
2767 if (mode
== VOIDmode
&& op
!= NULL_RTX
)
2768 mode
= GET_MODE (op
);
2770 /* We don't care to look at these, they should always be valid. */
2771 if (mode
== CCmode
|| mode
== CC_UNSmode
|| mode
== DImode
)
2774 if ((mode
== CC_FPmode
|| mode
== DFmode
)
2775 && (code
== GT
|| code
== LT
))
2778 if ((mode
== CC_FPEQmode
|| mode
== DFmode
)
2779 && (code
== EQ
|| code
== NE
))
2782 if ((mode
== CC_FUNmode
|| mode
== DFmode
)
2783 && (code
== ORDERED
|| code
== UNORDERED
))
2789 /* X and Y are two things to compare using CODE. Emit a compare insn if
2790 possible and return the rtx for the cc-reg in the proper mode, or
2791 NULL_RTX if this is not a valid comparison. */
2794 mmix_gen_compare_reg (code
, x
, y
)
2798 enum machine_mode ccmode
= SELECT_CC_MODE (code
, x
, y
);
2801 /* FIXME: Do we get constants here? Of double mode? */
2802 enum machine_mode mode
2803 = GET_MODE (x
) == VOIDmode
2805 : GET_MODE_CLASS (GET_MODE (x
)) == MODE_FLOAT
? DFmode
: DImode
;
2807 if (! mmix_valid_comparison (code
, mode
, x
))
2810 cc_reg
= gen_reg_rtx (ccmode
);
2812 /* FIXME: Can we avoid emitting a compare insn here? */
2813 if (! REG_P (x
) && ! REG_P (y
))
2814 x
= force_reg (mode
, x
);
2816 CANONICALIZE_COMPARISON (code
, x
, y
);
2818 /* If it's not quite right yet, put y in a register. */
2820 && (GET_CODE (y
) != CONST_INT
2821 || ! CONST_OK_FOR_LETTER_P (INTVAL (y
), 'I')))
2822 y
= force_reg (mode
, y
);
2824 emit_insn (gen_rtx_SET (VOIDmode
, cc_reg
,
2825 gen_rtx_COMPARE (ccmode
, x
, y
)));
2830 /* Local (static) helper functions. */
2832 /* Print operator suitable for doing something with a shiftable
2833 wyde. The type of operator is passed as an asm output modifier. */
2836 mmix_output_shiftvalue_op_from_str (stream
, mainop
, value
)
2839 HOST_WIDEST_INT value
;
2841 static const char *const op_part
[] = {"L", "ML", "MH", "H"};
2844 if (! mmix_shiftable_wyde_value (value
))
2846 char s
[sizeof ("0xffffffffffffffff")];
2847 sprintf (s
, HOST_WIDEST_INT_PRINT_HEX
, value
);
2848 internal_error ("MMIX Internal: %s is not a shiftable int", s
);
2851 for (i
= 0; i
< 4; i
++)
2853 /* We know we're through when we find one-bits in the low
2857 fprintf (stream
, "%s%s", mainop
, op_part
[i
]);
2863 /* No bits set? Then it must have been zero. */
2864 fprintf (stream
, "%sL", mainop
);
2867 /* Print a 64-bit value, optionally prefixed by assembly pseudo. */
2870 mmix_output_octa (stream
, value
, do_begin_end
)
2872 HOST_WIDEST_INT value
;
2875 /* Snipped from final.c:output_addr_const. We need to avoid the
2876 presumed universal "0x" prefix. We can do it by replacing "0x" with
2877 "#0" here; we must avoid a space in the operands and no, the zero
2878 won't cause the number to be assumed in octal format. */
2879 char hex_format
[sizeof (HOST_WIDEST_INT_PRINT_HEX
)];
2882 fprintf (stream
, "\tOCTA ");
2884 strcpy (hex_format
, HOST_WIDEST_INT_PRINT_HEX
);
2885 hex_format
[0] = '#';
2886 hex_format
[1] = '0';
2888 /* Provide a few alternative output formats depending on the number, to
2889 improve legibility of assembler output. */
2890 if ((value
< (HOST_WIDEST_INT
) 0 && value
> (HOST_WIDEST_INT
) -10000)
2891 || (value
>= (HOST_WIDEST_INT
) 0 && value
<= (HOST_WIDEST_INT
) 16384))
2892 fprintf (stream
, "%d", (int) value
);
2893 else if (value
> (HOST_WIDEST_INT
) 0
2894 && value
< ((HOST_WIDEST_INT
) 1 << 31) * 2)
2895 fprintf (stream
, "#%x", (unsigned int) value
);
2897 fprintf (stream
, hex_format
, value
);
2900 fprintf (stream
, "\n");
2903 /* Print the presumed shiftable wyde argument shifted into place (to
2904 be output with an operand). */
2907 mmix_output_shifted_value (stream
, value
)
2909 HOST_WIDEST_INT value
;
2913 if (! mmix_shiftable_wyde_value (value
))
2916 sprintf (s
, HOST_WIDEST_INT_PRINT_HEX
, value
);
2917 internal_error ("MMIX Internal: %s is not a shiftable int", s
);
2920 for (i
= 0; i
< 4; i
++)
2922 /* We know we're through when we find one-bits in the low 16 bits. */
2925 fprintf (stream
, "#%x", (int) (value
& 0xffff));
2932 /* No bits set? Then it must have been zero. */
2933 fprintf (stream
, "0");
2936 /* Output an MMIX condition name corresponding to an operator
2938 (comparison_operator [(comparison_operator ...) (const_int 0)])
2939 which means we have to look at *two* operators.
2941 The argument "reversed" refers to reversal of the condition (not the
2942 same as swapping the arguments). */
2945 mmix_output_condition (stream
, x
, reversed
)
2954 /* The normal output cc-code. */
2955 const char *const normal
;
2957 /* The reversed cc-code, or NULL if invalid. */
2958 const char *const reversed
;
2963 enum machine_mode cc_mode
;
2965 /* Terminated with {NIL, NULL, NULL} */
2966 const struct cc_conv
*const convs
;
2970 #define CCEND {NIL, NULL, NULL}
2972 static const struct cc_conv cc_fun_convs
[]
2973 = {{ORDERED
, "Z", "P"},
2974 {UNORDERED
, "P", "Z"},
2976 static const struct cc_conv cc_fp_convs
[]
2980 static const struct cc_conv cc_fpeq_convs
[]
2984 static const struct cc_conv cc_uns_convs
[]
2985 = {{GEU
, "NN", "N"},
2990 static const struct cc_conv cc_signed_convs
[]
2998 static const struct cc_conv cc_di_convs
[]
3010 static const struct cc_type_conv cc_convs
[]
3011 = {{CC_FUNmode
, cc_fun_convs
},
3012 {CC_FPmode
, cc_fp_convs
},
3013 {CC_FPEQmode
, cc_fpeq_convs
},
3014 {CC_UNSmode
, cc_uns_convs
},
3015 {CCmode
, cc_signed_convs
},
3016 {DImode
, cc_di_convs
}};
3021 enum machine_mode mode
= GET_MODE (XEXP (x
, 0));
3022 RTX_CODE cc
= GET_CODE (x
);
3024 for (i
= 0; i
< sizeof (cc_convs
)/sizeof(*cc_convs
); i
++)
3026 if (mode
== cc_convs
[i
].cc_mode
)
3028 for (j
= 0; cc_convs
[i
].convs
[j
].cc
!= NIL
; j
++)
3029 if (cc
== cc_convs
[i
].convs
[j
].cc
)
3032 = (reversed
? cc_convs
[i
].convs
[j
].reversed
3033 : cc_convs
[i
].convs
[j
].normal
);
3035 if (mmix_cc
== NULL
)
3036 fatal_insn ("MMIX Internal: Trying to output invalidly\
3037 reversed condition:", x
);
3039 fprintf (stream
, "%s", mmix_cc
);
3043 fatal_insn ("MMIX Internal: What's the CC of this?", x
);
3047 fatal_insn ("MMIX Internal: What is the CC of this?", x
);
3050 /* Return the bit-value for a const_int or const_double. */
3052 static HOST_WIDEST_INT
3056 unsigned HOST_WIDEST_INT retval
;
3058 if (GET_CODE (x
) == CONST_INT
)
3061 /* We make a little song and dance because converting to long long in
3062 gcc-2.7.2 is broken. I still want people to be able to use it for
3063 cross-compilation to MMIX. */
3064 if (GET_CODE (x
) == CONST_DOUBLE
&& GET_MODE (x
) == VOIDmode
)
3066 if (sizeof (HOST_WIDE_INT
) < sizeof (HOST_WIDEST_INT
))
3068 retval
= (unsigned) CONST_DOUBLE_LOW (x
) / 2;
3070 retval
|= CONST_DOUBLE_LOW (x
) & 1;
3073 (unsigned HOST_WIDEST_INT
) CONST_DOUBLE_HIGH (x
)
3074 << (HOST_BITS_PER_LONG
);
3077 retval
= CONST_DOUBLE_HIGH (x
);
3082 if (GET_CODE (x
) == CONST_DOUBLE
)
3084 REAL_VALUE_TYPE value
;
3086 /* FIXME: This macro is not in the manual but should be. */
3087 REAL_VALUE_FROM_CONST_DOUBLE (value
, x
);
3089 if (GET_MODE (x
) == DFmode
)
3093 REAL_VALUE_TO_TARGET_DOUBLE (value
, bits
);
3095 if (sizeof (long) < sizeof (HOST_WIDEST_INT
))
3097 retval
= (unsigned long) bits
[1] / 2;
3099 retval
|= (unsigned long) bits
[1] & 1;
3101 |= (unsigned HOST_WIDEST_INT
) bits
[0]
3102 << (sizeof (bits
[0]) * 8);
3105 retval
= (unsigned long) bits
[1];
3109 else if (GET_MODE (x
) == SFmode
)
3112 REAL_VALUE_TO_TARGET_SINGLE (value
, bits
);
3114 return (unsigned long) bits
;
3118 fatal_insn ("MMIX Internal: This is not a constant:", x
);
3123 * eval: (c-set-style "gnu")
3124 * indent-tabs-mode: t