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 GCC.
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
24 #include "coretypes.h"
28 #include "hard-reg-set.h"
30 #include "insn-config.h"
42 #include "integrate.h"
44 #include "target-def.h"
47 /* First some local helper definitions. */
48 #define MMIX_FIRST_GLOBAL_REGNUM 32
50 /* We'd need a current_function_has_landing_pad. It's marked as such when
51 a nonlocal_goto_receiver is expanded. Not just a C++ thing, but
53 #define MMIX_CFUN_HAS_LANDING_PAD (cfun->machine->has_landing_pad != 0)
55 /* We have no means to tell DWARF 2 about the register stack, so we need
56 to store the return address on the stack if an exception can get into
57 this function. FIXME: Narrow condition. Before any whole-function
58 analysis, regs_ever_live[] isn't initialized. We know it's up-to-date
59 after reload_completed; it may contain incorrect information some time
60 before that. Within a RTL sequence (after a call to start_sequence,
61 such as in RTL expanders), leaf_function_p doesn't see all insns
62 (perhaps any insn). But regs_ever_live is up-to-date when
63 leaf_function_p () isn't, so we "or" them together to get accurate
64 information. FIXME: Some tweak to leaf_function_p might be
66 #define MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS \
68 && ((reload_completed && regs_ever_live[MMIX_rJ_REGNUM]) \
69 || !leaf_function_p ()))
71 #define IS_MMIX_EH_RETURN_DATA_REG(REGNO) \
72 (current_function_calls_eh_return \
73 && (EH_RETURN_DATA_REGNO (0) == REGNO \
74 || EH_RETURN_DATA_REGNO (1) == REGNO \
75 || EH_RETURN_DATA_REGNO (2) == REGNO \
76 || EH_RETURN_DATA_REGNO (3) == REGNO))
78 /* For the default ABI, we rename registers at output-time to fill the gap
79 between the (statically partitioned) saved registers and call-clobbered
80 registers. In effect this makes unused call-saved registers to be used
81 as call-clobbered registers. The benefit comes from keeping the number
82 of local registers (value of rL) low, since there's a cost of
83 increasing rL and clearing unused (unset) registers with lower numbers.
84 Don't translate while outputting the prologue. */
85 #define MMIX_OUTPUT_REGNO(N) \
87 || (int) (N) < MMIX_RETURN_VALUE_REGNUM \
88 || (int) (N) > MMIX_LAST_STACK_REGISTER_REGNUM \
90 || cfun->machine == NULL \
91 || cfun->machine->in_prologue \
92 ? (N) : ((N) - MMIX_RETURN_VALUE_REGNUM \
93 + cfun->machine->highest_saved_stack_register + 1))
95 /* The %d in "POP %d,0". */
96 #define MMIX_POP_ARGUMENT() \
98 && current_function_return_rtx != NULL \
99 && ! current_function_returns_struct) \
100 ? (GET_CODE (current_function_return_rtx) == PARALLEL \
101 ? GET_NUM_ELEM (XVEC (current_function_return_rtx, 0)) : 1) \
104 /* The canonical saved comparison operands for non-cc0 machines, set in
105 the compare expander. */
106 rtx mmix_compare_op0
;
107 rtx mmix_compare_op1
;
109 /* We ignore some options with arguments. They are passed to the linker,
110 but also ends up here because they start with "-m". We tell the driver
111 to store them in a variable we don't inspect. */
112 const char *mmix_cc1_ignored_option
;
114 /* Declarations of locals. */
116 /* Intermediate for insn output. */
117 static int mmix_output_destination_register
;
119 static void mmix_output_shiftvalue_op_from_str
120 PARAMS ((FILE *, const char *, HOST_WIDEST_INT
));
121 static void mmix_output_shifted_value
PARAMS ((FILE *, HOST_WIDEST_INT
));
122 static void mmix_output_condition
PARAMS ((FILE *, rtx
, int));
123 static HOST_WIDEST_INT mmix_intval
PARAMS ((rtx
));
124 static void mmix_output_octa
PARAMS ((FILE *, HOST_WIDEST_INT
, int));
125 static bool mmix_assemble_integer
PARAMS ((rtx
, unsigned int, int));
126 static struct machine_function
* mmix_init_machine_status
PARAMS ((void));
127 static void mmix_encode_section_info
PARAMS ((tree
, int));
128 static const char *mmix_strip_name_encoding
PARAMS ((const char *));
129 static void mmix_emit_sp_add
PARAMS ((HOST_WIDE_INT offset
));
130 static void mmix_target_asm_function_prologue
131 PARAMS ((FILE *, HOST_WIDE_INT
));
132 static void mmix_target_asm_function_end_prologue
PARAMS ((FILE *));
133 static void mmix_target_asm_function_epilogue
134 PARAMS ((FILE *, HOST_WIDE_INT
));
135 static void mmix_asm_output_mi_thunk
136 PARAMS ((FILE *, tree
, HOST_WIDE_INT
, HOST_WIDE_INT
, tree
));
139 /* Target structure macros. Listed by node. See `Using and Porting GCC'
140 for a general description. */
142 /* Node: Function Entry */
144 #undef TARGET_ASM_BYTE_OP
145 #define TARGET_ASM_BYTE_OP NULL
146 #undef TARGET_ASM_ALIGNED_HI_OP
147 #define TARGET_ASM_ALIGNED_HI_OP NULL
148 #undef TARGET_ASM_ALIGNED_SI_OP
149 #define TARGET_ASM_ALIGNED_SI_OP NULL
150 #undef TARGET_ASM_ALIGNED_DI_OP
151 #define TARGET_ASM_ALIGNED_DI_OP NULL
152 #undef TARGET_ASM_INTEGER
153 #define TARGET_ASM_INTEGER mmix_assemble_integer
155 #undef TARGET_ASM_FUNCTION_PROLOGUE
156 #define TARGET_ASM_FUNCTION_PROLOGUE mmix_target_asm_function_prologue
158 #undef TARGET_ASM_FUNCTION_END_PROLOGUE
159 #define TARGET_ASM_FUNCTION_END_PROLOGUE mmix_target_asm_function_end_prologue
161 #undef TARGET_ASM_FUNCTION_EPILOGUE
162 #define TARGET_ASM_FUNCTION_EPILOGUE mmix_target_asm_function_epilogue
164 #undef TARGET_ENCODE_SECTION_INFO
165 #define TARGET_ENCODE_SECTION_INFO mmix_encode_section_info
166 #undef TARGET_STRIP_NAME_ENCODING
167 #define TARGET_STRIP_NAME_ENCODING mmix_strip_name_encoding
169 #undef TARGET_ASM_OUTPUT_MI_THUNK
170 #define TARGET_ASM_OUTPUT_MI_THUNK mmix_asm_output_mi_thunk
171 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
172 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall
174 struct gcc_target targetm
= TARGET_INITIALIZER
;
176 /* Functions that are expansions for target macros.
177 See Target Macros in `Using and Porting GCC'. */
179 /* OVERRIDE_OPTIONS. */
182 mmix_override_options ()
184 /* Should we err or should we warn? Hmm. At least we must neutralize
185 it. For example the wrong kind of case-tables will be generated with
186 PIC; we use absolute address items for mmixal compatibility. FIXME:
187 They could be relative if we just elide them to after all pertinent
191 warning ("-f%s not supported: ignored", (flag_pic
> 1) ? "PIC" : "pic");
196 /* INIT_EXPANDERS. */
199 mmix_init_expanders ()
201 init_machine_status
= mmix_init_machine_status
;
204 /* Set the per-function data. */
206 static struct machine_function
*
207 mmix_init_machine_status ()
209 return ggc_alloc_cleared (sizeof (struct machine_function
));
213 We have trouble getting the address of stuff that is located at other
214 than 32-bit alignments (GETA requirements), so try to give everything
215 at least 32-bit alignment. */
218 mmix_data_alignment (type
, basic_align
)
219 tree type ATTRIBUTE_UNUSED
;
222 if (basic_align
< 32)
228 /* CONSTANT_ALIGNMENT. */
231 mmix_constant_alignment (constant
, basic_align
)
232 tree constant ATTRIBUTE_UNUSED
;
235 if (basic_align
< 32)
241 /* LOCAL_ALIGNMENT. */
244 mmix_local_alignment (type
, basic_align
)
245 tree type ATTRIBUTE_UNUSED
;
248 if (basic_align
< 32)
254 /* CONDITIONAL_REGISTER_USAGE. */
257 mmix_conditional_register_usage ()
263 static const int gnu_abi_reg_alloc_order
[]
264 = MMIX_GNU_ABI_REG_ALLOC_ORDER
;
266 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
267 reg_alloc_order
[i
] = gnu_abi_reg_alloc_order
[i
];
269 /* Change the default from the mmixware ABI. For the GNU ABI,
270 $15..$30 are call-saved just as $0..$14. There must be one
271 call-clobbered local register for the "hole" that holds the
272 number of saved local registers saved by PUSHJ/PUSHGO during the
273 function call, receiving the return value at return. So best is
274 to use the highest, $31. It's already marked call-clobbered for
276 for (i
= 15; i
<= 30; i
++)
277 call_used_regs
[i
] = 0;
279 /* "Unfix" the parameter registers. */
280 for (i
= MMIX_RESERVED_GNU_ARG_0_REGNUM
;
281 i
< MMIX_RESERVED_GNU_ARG_0_REGNUM
+ MMIX_MAX_ARGS_IN_REGS
;
286 /* Step over the ":" in special register names. */
287 if (! TARGET_TOPLEVEL_SYMBOLS
)
288 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
289 if (reg_names
[i
][0] == ':')
294 All registers that are part of the register stack and that will be
298 mmix_local_regno (regno
)
301 return regno
<= MMIX_LAST_STACK_REGISTER_REGNUM
&& !call_used_regs
[regno
];
304 /* PREFERRED_RELOAD_CLASS.
305 We need to extend the reload class of REMAINDER_REG and HIMULT_REG. */
308 mmix_preferred_reload_class (x
, class)
309 rtx x ATTRIBUTE_UNUSED
;
310 enum reg_class
class;
312 /* FIXME: Revisit. */
313 return GET_CODE (x
) == MOD
&& GET_MODE (x
) == DImode
314 ? REMAINDER_REG
: class;
317 /* PREFERRED_OUTPUT_RELOAD_CLASS.
318 We need to extend the reload class of REMAINDER_REG and HIMULT_REG. */
321 mmix_preferred_output_reload_class (x
, class)
322 rtx x ATTRIBUTE_UNUSED
;
323 enum reg_class
class;
325 /* FIXME: Revisit. */
326 return GET_CODE (x
) == MOD
&& GET_MODE (x
) == DImode
327 ? REMAINDER_REG
: class;
330 /* SECONDARY_RELOAD_CLASS.
331 We need to reload regs of REMAINDER_REG and HIMULT_REG elsewhere. */
334 mmix_secondary_reload_class (class, mode
, x
, in_p
)
335 enum reg_class
class;
336 enum machine_mode mode ATTRIBUTE_UNUSED
;
337 rtx x ATTRIBUTE_UNUSED
;
338 int in_p ATTRIBUTE_UNUSED
;
340 if (class == REMAINDER_REG
341 || class == HIMULT_REG
342 || class == SYSTEM_REGS
)
348 /* CONST_OK_FOR_LETTER_P. */
351 mmix_const_ok_for_letter_p (value
, c
)
356 (c
== 'I' ? value
>= 0 && value
<= 255
357 : c
== 'J' ? value
>= 0 && value
<= 65535
358 : c
== 'K' ? value
<= 0 && value
>= -255
359 : c
== 'L' ? mmix_shiftable_wyde_value (value
)
360 : c
== 'M' ? value
== 0
361 : c
== 'N' ? mmix_shiftable_wyde_value (~value
)
362 : c
== 'O' ? (value
== 3 || value
== 5 || value
== 9
367 /* CONST_DOUBLE_OK_FOR_LETTER_P. */
370 mmix_const_double_ok_for_letter_p (value
, c
)
375 (c
== 'G' ? value
== CONST0_RTX (GET_MODE (value
))
380 We need this since our constants are not always expressible as
381 CONST_INT:s, but rather often as CONST_DOUBLE:s. */
384 mmix_extra_constraint (x
, c
, strict
)
389 HOST_WIDEST_INT value
;
391 /* When checking for an address, we need to handle strict vs. non-strict
392 register checks. Don't use address_operand, but instead its
393 equivalent (its callee, which it is just a wrapper for),
394 memory_operand_p and the strict-equivalent strict_memory_address_p. */
398 ? strict_memory_address_p (Pmode
, x
)
399 : memory_address_p (Pmode
, x
);
401 /* R asks whether x is to be loaded with GETA or something else. Right
402 now, only a SYMBOL_REF and LABEL_REF can fit for
403 TARGET_BASE_ADDRESSES.
405 Only constant symbolic addresses apply. With TARGET_BASE_ADDRESSES,
406 we just allow straight LABEL_REF or SYMBOL_REFs with SYMBOL_REF_FLAG
407 set right now; only function addresses and code labels. If we change
408 to let SYMBOL_REF_FLAG be set on other symbols, we have to check
409 inside CONST expressions. When TARGET_BASE_ADDRESSES is not in
410 effect, a "raw" constant check together with mmix_constant_address_p
411 is all that's needed; we want all constant addresses to be loaded
415 GET_CODE (x
) != CONST_INT
&& GET_CODE (x
) != CONST_DOUBLE
416 && mmix_constant_address_p (x
)
417 && (! TARGET_BASE_ADDRESSES
418 || (GET_CODE (x
) == LABEL_REF
419 || (GET_CODE (x
) == SYMBOL_REF
&& SYMBOL_REF_FLAG (x
))));
421 if (GET_CODE (x
) != CONST_DOUBLE
|| GET_MODE (x
) != VOIDmode
)
424 value
= mmix_intval (x
);
426 /* We used to map Q->J, R->K, S->L, T->N, U->O, but we don't have to any
427 more ('U' taken for address_operand, 'R' similarly). Some letters map
428 outside of CONST_INT, though; we still use 'S' and 'T'. */
430 return mmix_shiftable_wyde_value (value
);
432 return mmix_shiftable_wyde_value (~value
);
436 /* DYNAMIC_CHAIN_ADDRESS. */
439 mmix_dynamic_chain_address (frame
)
442 /* FIXME: the frame-pointer is stored at offset -8 from the current
443 frame-pointer. Unfortunately, the caller assumes that a
444 frame-pointer is present for *all* previous frames. There should be
445 a way to say that that cannot be done, like for RETURN_ADDR_RTX. */
446 return plus_constant (frame
, -8);
449 /* STARTING_FRAME_OFFSET. */
452 mmix_starting_frame_offset ()
454 /* The old frame pointer is in the slot below the new one, so
455 FIRST_PARM_OFFSET does not need to depend on whether the
456 frame-pointer is needed or not. We have to adjust for the register
457 stack pointer being located below the saved frame pointer.
458 Similarly, we store the return address on the stack too, for
459 exception handling, and always if we save the register stack pointer. */
462 + (MMIX_CFUN_HAS_LANDING_PAD
463 ? -16 : (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
? -8 : 0)));
466 /* RETURN_ADDR_RTX. */
469 mmix_return_addr_rtx (count
, frame
)
471 rtx frame ATTRIBUTE_UNUSED
;
474 ? (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
475 /* FIXME: Set frame_alias_set on the following. (Why?)
476 See mmix_initial_elimination_offset for the reason we can't use
477 get_hard_reg_initial_val for both. Always using a stack slot
478 and not a register would be suboptimal. */
479 ? validize_mem (gen_rtx_MEM (Pmode
, plus_constant (frame_pointer_rtx
, -16)))
480 : get_hard_reg_initial_val (Pmode
, MMIX_INCOMING_RETURN_ADDRESS_REGNUM
))
484 /* SETUP_FRAME_ADDRESSES. */
487 mmix_setup_frame_addresses ()
489 /* Nothing needed at the moment. */
492 /* The difference between the (imaginary) frame pointer and the stack
493 pointer. Used to eliminate the frame pointer. */
496 mmix_initial_elimination_offset (fromreg
, toreg
)
502 = (get_frame_size () + current_function_outgoing_args_size
+ 7) & ~7;
504 /* There is no actual offset between these two virtual values, but for
505 the frame-pointer, we have the old one in the stack position below
506 it, so the offset for the frame-pointer to the stack-pointer is one
508 if (fromreg
== MMIX_ARG_POINTER_REGNUM
509 && toreg
== MMIX_FRAME_POINTER_REGNUM
)
512 /* The difference is the size of local variables plus the size of
513 outgoing function arguments that would normally be passed as
514 registers but must be passed on stack because we're out of
515 function-argument registers. Only global saved registers are
516 counted; the others go on the register stack.
518 The frame-pointer is counted too if it is what is eliminated, as we
519 need to balance the offset for it from STARTING_FRAME_OFFSET.
521 Also add in the slot for the register stack pointer we save if we
524 Unfortunately, we can't access $0..$14, from unwinder code easily, so
525 store the return address in a frame slot too. FIXME: Only for
526 non-leaf functions. FIXME: Always with a landing pad, because it's
527 hard to know whether we need the other at the time we know we need
528 the offset for one (and have to state it). It's a kludge until we
529 can express the register stack in the EH frame info.
531 We have to do alignment here; get_frame_size will not return a
532 multiple of STACK_BOUNDARY. FIXME: Add note in manual. */
534 for (regno
= MMIX_FIRST_GLOBAL_REGNUM
;
537 if ((regs_ever_live
[regno
] && ! call_used_regs
[regno
])
538 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
542 + (MMIX_CFUN_HAS_LANDING_PAD
543 ? 16 : (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
? 8 : 0))
544 + (fromreg
== MMIX_ARG_POINTER_REGNUM
? 0 : 8);
547 /* Return an rtx for a function argument to go in a register, and 0 for
548 one that must go on stack. */
551 mmix_function_arg (argsp
, mode
, type
, named
, incoming
)
552 const CUMULATIVE_ARGS
* argsp
;
553 enum machine_mode mode
;
555 int named ATTRIBUTE_UNUSED
;
558 /* Last-argument marker. */
559 if (type
== void_type_node
)
560 return (argsp
->regs
< MMIX_MAX_ARGS_IN_REGS
)
563 ? MMIX_FIRST_INCOMING_ARG_REGNUM
564 : MMIX_FIRST_ARG_REGNUM
) + argsp
->regs
)
567 return (argsp
->regs
< MMIX_MAX_ARGS_IN_REGS
568 && !MUST_PASS_IN_STACK (mode
, type
)
569 && (GET_MODE_BITSIZE (mode
) <= 64
574 ? MMIX_FIRST_INCOMING_ARG_REGNUM
575 : MMIX_FIRST_ARG_REGNUM
)
580 /* Returns nonzero for everything that goes by reference, 0 for
581 everything that goes by value. */
584 mmix_function_arg_pass_by_reference (argsp
, mode
, type
, named
)
585 const CUMULATIVE_ARGS
* argsp
;
586 enum machine_mode mode
;
588 int named ATTRIBUTE_UNUSED
;
590 /* FIXME: Check: I'm not sure the MUST_PASS_IN_STACK check is
593 MUST_PASS_IN_STACK (mode
, type
)
594 || (MMIX_FUNCTION_ARG_SIZE (mode
, type
) > 8
599 /* Return nonzero if regno is a register number where a parameter is
600 passed, and 0 otherwise. */
603 mmix_function_arg_regno_p (regno
, incoming
)
608 = incoming
? MMIX_FIRST_INCOMING_ARG_REGNUM
: MMIX_FIRST_ARG_REGNUM
;
610 return regno
>= first_arg_regnum
611 && regno
< first_arg_regnum
+ MMIX_MAX_ARGS_IN_REGS
;
614 /* FUNCTION_OUTGOING_VALUE. */
617 mmix_function_outgoing_value (valtype
, func
)
619 tree func ATTRIBUTE_UNUSED
;
621 enum machine_mode mode
= TYPE_MODE (valtype
);
622 enum machine_mode cmode
;
623 int first_val_regnum
= MMIX_OUTGOING_RETURN_VALUE_REGNUM
;
624 rtx vec
[MMIX_MAX_REGS_FOR_VALUE
];
628 /* Return values that fit in a register need no special handling.
629 There's no register hole when parameters are passed in global
632 || GET_MODE_BITSIZE (mode
) <= BITS_PER_WORD
)
634 gen_rtx_REG (mode
, MMIX_OUTGOING_RETURN_VALUE_REGNUM
);
636 /* A complex type, made up of components. */
637 cmode
= TYPE_MODE (TREE_TYPE (valtype
));
638 nregs
= ((GET_MODE_BITSIZE (mode
) + BITS_PER_WORD
- 1) / BITS_PER_WORD
);
640 /* We need to take care of the effect of the register hole on return
641 values of large sizes; the last register will appear as the first
642 register, with the rest shifted. (For complex modes, this is just
643 swapped registers.) */
645 if (nregs
> MMIX_MAX_REGS_FOR_VALUE
)
646 internal_error ("too large function value type, needs %d registers,\
647 have only %d registers for this", nregs
, MMIX_MAX_REGS_FOR_VALUE
);
649 /* FIXME: Maybe we should handle structure values like this too
650 (adjusted for BLKmode), perhaps for both ABI:s. */
651 for (i
= 0; i
< nregs
- 1; i
++)
653 = gen_rtx_EXPR_LIST (VOIDmode
,
654 gen_rtx_REG (cmode
, first_val_regnum
+ i
),
655 GEN_INT ((i
+ 1) * BITS_PER_UNIT
));
658 = gen_rtx_EXPR_LIST (VOIDmode
,
659 gen_rtx_REG (cmode
, first_val_regnum
+ nregs
- 1),
662 return gen_rtx_PARALLEL (VOIDmode
, gen_rtvec_v (nregs
, vec
));
665 /* FUNCTION_VALUE_REGNO_P. */
668 mmix_function_value_regno_p (regno
)
671 return regno
== MMIX_RETURN_VALUE_REGNUM
;
674 /* EH_RETURN_DATA_REGNO. */
677 mmix_eh_return_data_regno (n
)
678 int n ATTRIBUTE_UNUSED
;
681 return MMIX_EH_RETURN_DATA_REGNO_START
+ n
;
683 return INVALID_REGNUM
;
686 /* EH_RETURN_STACKADJ_RTX. */
689 mmix_eh_return_stackadj_rtx ()
691 return gen_rtx_REG (Pmode
, MMIX_EH_RETURN_STACKADJ_REGNUM
);
694 /* EH_RETURN_HANDLER_RTX. */
697 mmix_eh_return_handler_rtx ()
700 gen_rtx_REG (Pmode
, MMIX_INCOMING_RETURN_ADDRESS_REGNUM
);
703 /* ASM_PREFERRED_EH_DATA_FORMAT. */
706 mmix_asm_preferred_eh_data_format (code
, global
)
707 int code ATTRIBUTE_UNUSED
;
708 int global ATTRIBUTE_UNUSED
;
710 /* This is the default (was at 2001-07-20). Revisit when needed. */
711 return DW_EH_PE_absptr
;
714 /* Make a note that we've seen the beginning of the prologue. This
715 matters to whether we'll translate register numbers as calculated by
716 mmix_machine_dependent_reorg. */
719 mmix_target_asm_function_prologue (stream
, framesize
)
720 FILE *stream ATTRIBUTE_UNUSED
;
721 HOST_WIDE_INT framesize ATTRIBUTE_UNUSED
;
723 cfun
->machine
->in_prologue
= 1;
726 /* Make a note that we've seen the end of the prologue. */
729 mmix_target_asm_function_end_prologue (stream
)
730 FILE *stream ATTRIBUTE_UNUSED
;
732 cfun
->machine
->in_prologue
= 0;
735 /* MACHINE_DEPENDENT_REORG.
736 No actual rearrangements done here; just virtually by calculating the
737 highest saved stack register number used to modify the register numbers
741 mmix_machine_dependent_reorg (first
)
742 rtx first ATTRIBUTE_UNUSED
;
746 /* We put the number of the highest saved register-file register in a
747 location convenient for the call-patterns to output. Note that we
748 don't tell dwarf2 about these registers, since it can't restore them
750 for (regno
= MMIX_LAST_STACK_REGISTER_REGNUM
;
753 if ((regs_ever_live
[regno
] && !call_used_regs
[regno
])
754 || (regno
== MMIX_FRAME_POINTER_REGNUM
&& frame_pointer_needed
))
757 /* Regardless of whether they're saved (they might be just read), we
758 mustn't include registers that carry parameters. We could scan the
759 insns to see whether they're actually used (and indeed do other less
760 trivial register usage analysis and transformations), but it seems
761 wasteful to optimize for unused parameter registers. As of
762 2002-04-30, regs_ever_live[n] seems to be set for only-reads too, but
763 that might change. */
764 if (!TARGET_ABI_GNU
&& regno
< current_function_args_info
.regs
- 1)
766 regno
= current_function_args_info
.regs
- 1;
768 /* We don't want to let this cause us to go over the limit and make
769 incoming parameter registers be misnumbered and treating the last
770 parameter register and incoming return value register call-saved.
771 Stop things at the unmodified scheme. */
772 if (regno
> MMIX_RETURN_VALUE_REGNUM
- 1)
773 regno
= MMIX_RETURN_VALUE_REGNUM
- 1;
776 cfun
->machine
->highest_saved_stack_register
= regno
;
779 /* TARGET_ASM_FUNCTION_EPILOGUE. */
782 mmix_target_asm_function_epilogue (stream
, locals_size
)
784 HOST_WIDE_INT locals_size ATTRIBUTE_UNUSED
;
787 /* Emit an \n for readability of the generated assembly. */
788 fputc ('\n', stream
);
791 /* TARGET_ASM_OUTPUT_MI_THUNK. */
794 mmix_asm_output_mi_thunk (stream
, fndecl
, delta
, vcall_offset
, func
)
796 tree fndecl ATTRIBUTE_UNUSED
;
798 HOST_WIDE_INT vcall_offset ATTRIBUTE_UNUSED
;
801 /* If you define STRUCT_VALUE to 0, rather than use STRUCT_VALUE_REGNUM,
802 (i.e. pass location of structure to return as invisible first
803 argument) you need to tweak this code too. */
804 const char *regname
= reg_names
[MMIX_FIRST_INCOMING_ARG_REGNUM
];
806 if (delta
>= 0 && delta
< 65536)
807 fprintf (stream
, "\tINCL %s,%d\n", regname
, (int)delta
);
808 else if (delta
< 0 && delta
>= -255)
809 fprintf (stream
, "\tSUBU %s,%s,%d\n", regname
, regname
, (int)-delta
);
812 mmix_output_register_setting (stream
, 255, delta
, 1);
813 fprintf (stream
, "\tADDU %s,%s,$255\n", regname
, regname
);
816 fprintf (stream
, "\tJMP ");
817 assemble_name (stream
, XSTR (XEXP (DECL_RTL (func
), 0), 0));
818 fprintf (stream
, "\n");
821 /* FUNCTION_PROFILER. */
824 mmix_function_profiler (stream
, labelno
)
825 FILE *stream ATTRIBUTE_UNUSED
;
826 int labelno ATTRIBUTE_UNUSED
;
828 sorry ("function_profiler support for MMIX");
831 /* SETUP_INCOMING_VARARGS. */
834 mmix_setup_incoming_varargs (args_so_farp
, mode
, vartype
, pretend_sizep
,
836 CUMULATIVE_ARGS
* args_so_farp
;
837 enum machine_mode mode
;
840 int second_time ATTRIBUTE_UNUSED
;
842 /* The last named variable has been handled, but
843 args_so_farp has not been advanced for it. */
844 if (args_so_farp
->regs
+ 1 < MMIX_MAX_ARGS_IN_REGS
)
845 *pretend_sizep
= (MMIX_MAX_ARGS_IN_REGS
- (args_so_farp
->regs
+ 1)) * 8;
847 /* We assume that one argument takes up one register here. That should
848 be true until we start messing with multi-reg parameters. */
849 if ((7 + (MMIX_FUNCTION_ARG_SIZE (mode
, vartype
))) / 8 != 1)
850 internal_error ("MMIX Internal: Last named vararg would not fit in a register");
853 /* EXPAND_BUILTIN_VA_ARG. */
855 /* This is modified from the "standard" implementation of va_arg: read the
856 value from the current (padded) address and increment by the (padded)
857 size. The difference for MMIX is that if the type is
858 pass-by-reference, then perform an indirection. */
861 mmix_expand_builtin_va_arg (valist
, type
)
865 tree ptr_size
= size_int (BITS_PER_WORD
/ BITS_PER_UNIT
);
866 tree addr_tree
, type_size
= NULL
;
871 /* Compute the rounded size of the type. */
875 align
= size_int (PARM_BOUNDARY
/ BITS_PER_UNIT
);
876 alignm1
= size_int (PARM_BOUNDARY
/ BITS_PER_UNIT
- 1);
877 if (type
== error_mark_node
878 || (type_size
= TYPE_SIZE_UNIT (TYPE_MAIN_VARIANT (type
))) == NULL
879 || TREE_OVERFLOW (type_size
))
880 /* Presumably an error; the size isn't computable. A message has
881 supposedly been emitted elsewhere. */
882 rounded_size
= size_zero_node
;
884 rounded_size
= fold (build (MULT_EXPR
, sizetype
,
885 fold (build (TRUNC_DIV_EXPR
, sizetype
,
886 fold (build (PLUS_EXPR
, sizetype
,
887 type_size
, alignm1
)),
891 if (AGGREGATE_TYPE_P (type
)
892 && GET_MODE_UNIT_SIZE (TYPE_MODE (type
)) < 8
893 && GET_MODE_UNIT_SIZE (TYPE_MODE (type
)) != 0)
895 /* Adjust for big-endian the location of aggregates passed in a
896 register, but where the aggregate is accessed in a shorter mode
897 than the natural register mode (i.e. it is accessed as SFmode(?),
898 SImode, HImode or QImode rather than DImode or DFmode(?)). FIXME:
899 Or should we adjust the mode in which the aggregate is read, to be
900 a register size mode? (Hum, nah, a small offset is generally
901 cheaper than a wider memory access on MMIX.) */
903 = build (PLUS_EXPR
, TREE_TYPE (addr_tree
), addr_tree
,
904 size_int ((BITS_PER_WORD
/ BITS_PER_UNIT
)
905 - GET_MODE_UNIT_SIZE (TYPE_MODE (type
))));
907 else if (!integer_zerop (rounded_size
))
909 if (!really_constant_p (type_size
))
910 /* Varying-size types come in by reference. */
912 = build1 (INDIRECT_REF
, build_pointer_type (type
), addr_tree
);
915 /* If the size is less than a register, then we need to pad the
916 address by adding the difference. */
918 = fold (build (COND_EXPR
, sizetype
,
919 fold (build (GT_EXPR
, sizetype
,
923 fold (build (MINUS_EXPR
, sizetype
,
927 = fold (build (PLUS_EXPR
, TREE_TYPE (addr_tree
), addr_tree
,
930 /* If this type is larger than what fits in a register, then it
931 is passed by reference. */
933 = fold (build (COND_EXPR
, TREE_TYPE (addr_tree1
),
934 fold (build (GT_EXPR
, sizetype
,
937 build1 (INDIRECT_REF
, build_pointer_type (type
),
943 addr
= expand_expr (addr_tree
, NULL_RTX
, Pmode
, EXPAND_NORMAL
);
944 addr
= copy_to_reg (addr
);
946 if (!integer_zerop (rounded_size
))
948 /* Compute new value for AP. For MMIX, it is always advanced by the
949 size of a register. */
950 tree t
= build (MODIFY_EXPR
, TREE_TYPE (valist
), valist
,
951 build (PLUS_EXPR
, TREE_TYPE (valist
), valist
,
953 TREE_SIDE_EFFECTS (t
) = 1;
954 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
960 /* TRAMPOLINE_SIZE. */
961 /* Four 4-byte insns plus two 8-byte values. */
962 int mmix_trampoline_size
= 32;
965 /* TRAMPOLINE_TEMPLATE. */
968 mmix_trampoline_template (stream
)
971 /* Read a value into the static-chain register and jump somewhere. The
972 static chain is stored at offset 16, and the function address is
973 stored at offset 24. */
974 /* FIXME: GCC copies this using *intsize* (tetra), when it should use
975 register size (octa). */
976 fprintf (stream
, "\tGETA $255,1F\n\t");
977 fprintf (stream
, "LDOU %s,$255,0\n\t",
978 reg_names
[MMIX_STATIC_CHAIN_REGNUM
]);
979 fprintf (stream
, "LDOU $255,$255,8\n\t");
980 fprintf (stream
, "GO $255,$255,0\n");
981 fprintf (stream
, "1H\tOCTA 0\n\t");
982 fprintf (stream
, "OCTA 0\n");
985 /* INITIALIZE_TRAMPOLINE. */
986 /* Set the static chain and function pointer field in the trampoline.
987 We also SYNCID here to be sure (doesn't matter in the simulator, but
988 some day it will). */
991 mmix_initialize_trampoline (trampaddr
, fnaddr
, static_chain
)
996 emit_move_insn (gen_rtx_MEM (DImode
, plus_constant (trampaddr
, 16)),
998 emit_move_insn (gen_rtx_MEM (DImode
,
999 plus_constant (trampaddr
, 24)),
1001 emit_insn (gen_sync_icache (validize_mem (gen_rtx_MEM (DImode
,
1003 GEN_INT (mmix_trampoline_size
- 1)));
1006 /* We must exclude constant addresses that have an increment that is not a
1007 multiple of four bytes because of restrictions of the GETA
1008 instruction, unless TARGET_BASE_ADDRESSES. */
1011 mmix_constant_address_p (x
)
1014 RTX_CODE code
= GET_CODE (x
);
1016 /* When using "base addresses", anything constant goes. */
1017 int constant_ok
= TARGET_BASE_ADDRESSES
!= 0;
1025 case CONSTANT_P_RTX
:
1027 /* FIXME: Don't know how to dissect these. Avoid them for now,
1028 except we know they're constants. */
1032 addend
= INTVAL (x
);
1036 if (GET_MODE (x
) != VOIDmode
)
1037 /* Strange that we got here. FIXME: Check if we do. */
1039 addend
= CONST_DOUBLE_LOW (x
);
1043 /* Note that expressions with arithmetic on forward references don't
1044 work in mmixal. People using gcc assembly code with mmixal might
1045 need to move arrays and such to before the point of use. */
1046 if (GET_CODE (XEXP (x
, 0)) == PLUS
)
1048 rtx x0
= XEXP (XEXP (x
, 0), 0);
1049 rtx x1
= XEXP (XEXP (x
, 0), 1);
1051 if ((GET_CODE (x0
) == SYMBOL_REF
1052 || GET_CODE (x0
) == LABEL_REF
)
1053 && (GET_CODE (x1
) == CONST_INT
1054 || (GET_CODE (x1
) == CONST_DOUBLE
1055 && GET_MODE (x1
) == VOIDmode
)))
1056 addend
= mmix_intval (x1
);
1068 return constant_ok
|| (addend
& 3) == 0;
1071 /* Return 1 if the address is OK, otherwise 0.
1072 Used by GO_IF_LEGITIMATE_ADDRESS. */
1075 mmix_legitimate_address (mode
, x
, strict_checking
)
1076 enum machine_mode mode ATTRIBUTE_UNUSED
;
1078 int strict_checking
;
1080 #define MMIX_REG_OK(X) \
1082 && (REGNO (X) <= MMIX_LAST_GENERAL_REGISTER \
1083 || (reg_renumber[REGNO (X)] > 0 \
1084 && reg_renumber[REGNO (X)] <= MMIX_LAST_GENERAL_REGISTER))) \
1085 || (!strict_checking \
1086 && (REGNO (X) <= MMIX_LAST_GENERAL_REGISTER \
1087 || REGNO (X) >= FIRST_PSEUDO_REGISTER \
1088 || REGNO (X) == ARG_POINTER_REGNUM)))
1092 (mem (plus reg reg))
1093 (mem (plus reg 0..255)).
1094 unless TARGET_BASE_ADDRESSES, in which case we accept all
1095 (mem constant_address) too. */
1099 if (REG_P (x
) && MMIX_REG_OK (x
))
1102 if (GET_CODE(x
) == PLUS
)
1104 rtx x1
= XEXP (x
, 0);
1105 rtx x2
= XEXP (x
, 1);
1107 /* Try swapping the order. FIXME: Do we need this? */
1115 /* (mem (plus (reg?) (?))) */
1116 if (!REG_P (x1
) || !MMIX_REG_OK (x1
))
1117 return TARGET_BASE_ADDRESSES
&& mmix_constant_address_p (x
);
1119 /* (mem (plus (reg) (reg?))) */
1120 if (REG_P (x2
) && MMIX_REG_OK (x2
))
1123 /* (mem (plus (reg) (0..255?))) */
1124 if (GET_CODE (x2
) == CONST_INT
1125 && CONST_OK_FOR_LETTER_P (INTVAL (x2
), 'I'))
1131 return TARGET_BASE_ADDRESSES
&& mmix_constant_address_p (x
);
1134 /* LEGITIMATE_CONSTANT_P. */
1137 mmix_legitimate_constant_p (x
)
1140 RTX_CODE code
= GET_CODE (x
);
1142 /* We must allow any number due to the way the cse passes works; if we
1143 do not allow any number here, general_operand will fail, and insns
1144 will fatally fail recognition instead of "softly". */
1145 if (code
== CONST_INT
|| code
== CONST_DOUBLE
)
1148 return CONSTANT_ADDRESS_P (x
);
1151 /* SELECT_CC_MODE. */
1154 mmix_select_cc_mode (op
, x
, y
)
1157 rtx y ATTRIBUTE_UNUSED
;
1159 /* We use CCmode, CC_UNSmode, CC_FPmode, CC_FPEQmode and CC_FUNmode to
1160 output different compare insns. Note that we do not check the
1161 validity of the comparison here. */
1163 if (GET_MODE_CLASS (GET_MODE (x
)) == MODE_FLOAT
)
1165 if (op
== ORDERED
|| op
== UNORDERED
|| op
== UNGE
1166 || op
== UNGT
|| op
== UNLE
|| op
== UNLT
)
1169 if (op
== EQ
|| op
== NE
)
1175 if (op
== GTU
|| op
== LTU
|| op
== GEU
|| op
== LEU
)
1181 /* REVERSIBLE_CC_MODE. */
1184 mmix_reversible_cc_mode (mode
)
1185 enum machine_mode mode
;
1187 /* That is, all integer and the EQ, NE, ORDERED and UNORDERED float
1189 return mode
!= CC_FPmode
;
1192 /* DEFAULT_RTX_COSTS. */
1195 mmix_rtx_cost_recalculated (x
, code
, outer_code
, costp
)
1196 rtx x ATTRIBUTE_UNUSED
;
1197 RTX_CODE code ATTRIBUTE_UNUSED
;
1198 RTX_CODE outer_code ATTRIBUTE_UNUSED
;
1199 int *costp ATTRIBUTE_UNUSED
;
1201 /* For the time being, this is just a stub and we'll accept the
1202 generic calculations, until we can do measurements, at least.
1203 Say we did not modify any calculated costs. */
1210 mmix_address_cost (addr
)
1211 rtx addr ATTRIBUTE_UNUSED
;
1213 /* There's no difference in the address costs and we have lots of
1214 registers. Some targets use constant 0, many others use 1 to say
1215 this. Let's start with 1. */
1219 /* REGISTER_MOVE_COST. */
1222 mmix_register_move_cost (mode
, from
, to
)
1223 enum machine_mode mode ATTRIBUTE_UNUSED
;
1224 enum reg_class from
;
1227 return (from
== GENERAL_REGS
&& from
== to
) ? 2 : 3;
1230 /* Note that we don't have a TEXT_SECTION_ASM_OP, because it has to be a
1231 compile-time constant; it's used in an asm in crtstuff.c, compiled for
1234 /* DATA_SECTION_ASM_OP. */
1237 mmix_data_section_asm_op ()
1239 return "\t.data ! mmixal:= 8H LOC 9B";
1243 mmix_encode_section_info (decl
, first
)
1247 /* Test for an external declaration, and do nothing if it is one. */
1248 if ((TREE_CODE (decl
) == VAR_DECL
1249 && (DECL_EXTERNAL (decl
) || TREE_PUBLIC (decl
)))
1250 || (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_PUBLIC (decl
)))
1252 else if (first
&& DECL_P (decl
))
1254 /* For non-visible declarations, add a "@" prefix, which we skip
1255 when the label is output. If the label does not have this
1256 prefix, a ":" is output if -mtoplevel-symbols.
1258 Note that this does not work for data that is declared extern and
1259 later defined as static. If there's code in between, that code
1260 will refer to the extern declaration, and vice versa. This just
1261 means that when -mtoplevel-symbols is in use, we can just handle
1262 well-behaved ISO-compliant code. */
1264 const char *str
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
1265 int len
= strlen (str
);
1268 /* Why is the return type of ggc_alloc_string const? */
1269 newstr
= (char *) ggc_alloc_string ("", len
+ 1);
1271 strcpy (newstr
+ 1, str
);
1273 XSTR (XEXP (DECL_RTL (decl
), 0), 0) = newstr
;
1276 /* Set SYMBOL_REF_FLAG for things that we want to access with GETA. We
1277 may need different options to reach for different things with GETA.
1278 For now, functions and things we know or have been told are constant. */
1279 if (TREE_CODE (decl
) == FUNCTION_DECL
1280 || TREE_CONSTANT (decl
)
1281 || (TREE_CODE (decl
) == VAR_DECL
1282 && TREE_READONLY (decl
)
1283 && !TREE_SIDE_EFFECTS (decl
)
1284 && (!DECL_INITIAL (decl
)
1285 || TREE_CONSTANT (DECL_INITIAL (decl
)))))
1287 rtx rtl
= (TREE_CODE_CLASS (TREE_CODE (decl
)) != 'd'
1288 ? TREE_CST_RTL (decl
) : DECL_RTL (decl
));
1289 SYMBOL_REF_FLAG (XEXP (rtl
, 0)) = 1;
1294 mmix_strip_name_encoding (name
)
1297 for (; (*name
== '@' || *name
== '*'); name
++)
1303 /* ASM_FILE_START. */
1306 mmix_asm_file_start (stream
)
1309 /* We just emit a little comment for the time being. FIXME: Perhaps add
1310 -mstandalone and some segment and prefix setup here. */
1311 ASM_OUTPUT_SOURCE_FILENAME (stream
, main_input_filename
);
1313 fprintf (stream
, "! mmixal:= 8H LOC Data_Section\n");
1315 /* Make sure each file starts with the text section. */
1322 mmix_asm_file_end (stream
)
1323 FILE * stream ATTRIBUTE_UNUSED
;
1325 /* Make sure each file ends with the data section. */
1329 /* ASM_OUTPUT_SOURCE_FILENAME. */
1332 mmix_asm_output_source_filename (stream
, name
)
1336 fprintf (stream
, "# 1 ");
1337 OUTPUT_QUOTED_STRING (stream
, name
);
1338 fprintf (stream
, "\n");
1341 /* OUTPUT_QUOTED_STRING. */
1344 mmix_output_quoted_string (stream
, string
, length
)
1346 const char * string
;
1349 const char * string_end
= string
+ length
;
1350 static const char *const unwanted_chars
= "\"[]\\";
1352 /* Output "any character except newline and double quote character". We
1353 play it safe and avoid all control characters too. We also do not
1354 want [] as characters, should input be passed through m4 with [] as
1355 quotes. Further, we avoid "\", because the GAS port handles it as a
1356 quoting character. */
1357 while (string
< string_end
)
1360 && (unsigned char) *string
< 128
1361 && !ISCNTRL (*string
)
1362 && strchr (unwanted_chars
, *string
) == NULL
)
1364 fputc ('"', stream
);
1366 && (unsigned char) *string
< 128
1367 && !ISCNTRL (*string
)
1368 && strchr (unwanted_chars
, *string
) == NULL
1369 && string
< string_end
)
1371 fputc (*string
, stream
);
1374 fputc ('"', stream
);
1375 if (string
< string_end
)
1376 fprintf (stream
, ",");
1378 if (string
< string_end
)
1380 fprintf (stream
, "#%x", *string
& 255);
1382 if (string
< string_end
)
1383 fprintf (stream
, ",");
1388 /* ASM_OUTPUT_SOURCE_LINE. */
1391 mmix_asm_output_source_line (stream
, lineno
)
1395 fprintf (stream
, "# %d ", lineno
);
1396 OUTPUT_QUOTED_STRING (stream
, main_input_filename
);
1397 fprintf (stream
, "\n");
1400 /* Target hook for assembling integer objects. Use mmix_print_operand
1401 for WYDE and TETRA. Use mmix_output_octa to output 8-byte
1405 mmix_assemble_integer (x
, size
, aligned_p
)
1413 /* We handle a limited number of types of operands in here. But
1414 that's ok, because we can punt to generic functions. We then
1415 pretend that aligned data isn't needed, so the usual .<pseudo>
1416 syntax is used (which works for aligned data too). We actually
1417 *must* do that, since we say we don't have simple aligned
1418 pseudos, causing this function to be called. We just try and
1419 keep as much compatibility as possible with mmixal syntax for
1420 normal cases (i.e. without GNU extensions and C only). */
1422 if (GET_CODE (x
) != CONST_INT
)
1427 fputs ("\tBYTE\t", asm_out_file
);
1428 mmix_print_operand (asm_out_file
, x
, 'B');
1429 fputc ('\n', asm_out_file
);
1433 if (GET_CODE (x
) != CONST_INT
)
1438 fputs ("\tWYDE\t", asm_out_file
);
1439 mmix_print_operand (asm_out_file
, x
, 'W');
1440 fputc ('\n', asm_out_file
);
1444 if (GET_CODE (x
) != CONST_INT
)
1449 fputs ("\tTETRA\t", asm_out_file
);
1450 mmix_print_operand (asm_out_file
, x
, 'L');
1451 fputc ('\n', asm_out_file
);
1455 if (GET_CODE (x
) == CONST_DOUBLE
)
1456 /* We don't get here anymore for CONST_DOUBLE, because DImode
1457 isn't expressed as CONST_DOUBLE, and DFmode is handled
1460 assemble_integer_with_op ("\tOCTA\t", x
);
1463 return default_assemble_integer (x
, size
, aligned_p
);
1466 /* ASM_OUTPUT_ASCII. */
1469 mmix_asm_output_ascii (stream
, string
, length
)
1476 int chunk_size
= length
> 60 ? 60 : length
;
1477 fprintf (stream
, "\tBYTE ");
1478 mmix_output_quoted_string (stream
, string
, chunk_size
);
1479 string
+= chunk_size
;
1480 length
-= chunk_size
;
1481 fprintf (stream
, "\n");
1485 /* ASM_OUTPUT_ALIGNED_COMMON. */
1488 mmix_asm_output_aligned_common (stream
, name
, size
, align
)
1494 /* This is mostly the elfos.h one. There doesn't seem to be a way to
1495 express this in a mmixal-compatible way. */
1496 fprintf (stream
, "\t.comm\t");
1497 assemble_name (stream
, name
);
1498 fprintf (stream
, ",%u,%u ! mmixal-incompatible COMMON\n",
1499 size
, align
/ BITS_PER_UNIT
);
1502 /* ASM_OUTPUT_ALIGNED_LOCAL. */
1505 mmix_asm_output_aligned_local (stream
, name
, size
, align
)
1513 ASM_OUTPUT_ALIGN (stream
, exact_log2 (align
/BITS_PER_UNIT
));
1514 assemble_name (stream
, name
);
1515 fprintf (stream
, "\tLOC @+%d\n", size
);
1518 /* ASM_OUTPUT_LABEL. */
1521 mmix_asm_output_label (stream
, name
)
1525 assemble_name (stream
, name
);
1526 fprintf (stream
, "\tIS @\n");
1529 /* ASM_DECLARE_REGISTER_GLOBAL. */
1532 mmix_asm_declare_register_global (stream
, decl
, regno
, name
)
1533 FILE *stream ATTRIBUTE_UNUSED
;
1534 tree decl ATTRIBUTE_UNUSED
;
1535 int regno ATTRIBUTE_UNUSED
;
1536 const char *name ATTRIBUTE_UNUSED
;
1538 /* Nothing to do here, but there *will* be, therefore the framework is
1542 /* ASM_WEAKEN_LABEL. */
1545 mmix_asm_weaken_label (stream
, name
)
1546 FILE * stream ATTRIBUTE_UNUSED
;
1547 const char * name ATTRIBUTE_UNUSED
;
1549 fprintf (stream
, "\t.weak ");
1550 assemble_name (stream
, name
);
1551 fprintf (stream
, " ! mmixal-incompatible\n");
1554 /* MAKE_DECL_ONE_ONLY. */
1557 mmix_make_decl_one_only (decl
)
1560 DECL_WEAK (decl
) = 1;
1563 /* ASM_OUTPUT_LABELREF.
1564 Strip GCC's '*' and our own '@'. No order is assumed. */
1567 mmix_asm_output_labelref (stream
, name
)
1573 for (; (*name
== '@' || *name
== '*'); name
++)
1577 asm_fprintf (stream
, "%s%U%s",
1578 is_extern
&& TARGET_TOPLEVEL_SYMBOLS
? ":" : "",
1582 /* ASM_OUTPUT_DEF. */
1585 mmix_asm_output_def (stream
, name
, value
)
1590 assemble_name (stream
, name
);
1591 fprintf (stream
, "\tIS ");
1592 assemble_name (stream
, value
);
1593 fputc ('\n', stream
);
1596 /* PRINT_OPERAND. */
1599 mmix_print_operand (stream
, x
, code
)
1604 /* When we add support for different codes later, we can, when needed,
1605 drop through to the main handler with a modified operand. */
1607 int regno
= x
!= NULL_RTX
&& REG_P (x
) ? REGNO (x
) : 0;
1611 /* Unrelated codes are in alphabetic order. */
1614 /* For conditional branches, output "P" for a probable branch. */
1615 if (TARGET_BRANCH_PREDICT
)
1617 x
= find_reg_note (current_output_insn
, REG_BR_PROB
, 0);
1618 if (x
&& INTVAL (XEXP (x
, 0)) > REG_BR_PROB_BASE
/ 2)
1624 /* For the %d in POP %d,0. */
1625 fprintf (stream
, "%d", MMIX_POP_ARGUMENT ());
1629 if (GET_CODE (x
) != CONST_INT
)
1630 fatal_insn ("MMIX Internal: Expected a CONST_INT, not this", x
);
1631 fprintf (stream
, "%d", (int) (INTVAL (x
) & 0xff));
1635 /* Highpart. Must be general register, and not the last one, as
1636 that one cannot be part of a consecutive register pair. */
1637 if (regno
> MMIX_LAST_GENERAL_REGISTER
- 1)
1638 internal_error ("MMIX Internal: Bad register: %d", regno
);
1640 /* This is big-endian, so the high-part is the first one. */
1641 fprintf (stream
, "%s", reg_names
[MMIX_OUTPUT_REGNO (regno
)]);
1645 /* Lowpart. Must be CONST_INT or general register, and not the last
1646 one, as that one cannot be part of a consecutive register pair. */
1647 if (GET_CODE (x
) == CONST_INT
)
1649 fprintf (stream
, "#%lx",
1650 (unsigned long) (INTVAL (x
)
1651 & ((unsigned int) 0x7fffffff * 2 + 1)));
1655 if (GET_CODE (x
) == SYMBOL_REF
)
1657 output_addr_const (stream
, x
);
1661 if (regno
> MMIX_LAST_GENERAL_REGISTER
- 1)
1662 internal_error ("MMIX Internal: Bad register: %d", regno
);
1664 /* This is big-endian, so the low-part is + 1. */
1665 fprintf (stream
, "%s", reg_names
[MMIX_OUTPUT_REGNO (regno
) + 1]);
1668 /* Can't use 'a' because that's a generic modifier for address
1671 mmix_output_shiftvalue_op_from_str (stream
, "ANDN",
1672 ~(unsigned HOST_WIDEST_INT
)
1677 mmix_output_shiftvalue_op_from_str (stream
, "INC",
1678 (unsigned HOST_WIDEST_INT
)
1683 mmix_output_shiftvalue_op_from_str (stream
, "OR",
1684 (unsigned HOST_WIDEST_INT
)
1689 mmix_output_shiftvalue_op_from_str (stream
, "SET",
1690 (unsigned HOST_WIDEST_INT
)
1696 mmix_output_condition (stream
, x
, (code
== 'D'));
1700 /* Output an extra "e" to make fcmpe, fune. */
1701 if (TARGET_FCMP_EPSILON
)
1702 fprintf (stream
, "e");
1706 /* Output the number minus 1. */
1707 if (GET_CODE (x
) != CONST_INT
)
1709 fatal_insn ("MMIX Internal: Bad value for 'm', not a CONST_INT",
1712 fprintf (stream
, HOST_WIDEST_INT_PRINT_DEC
,
1713 (HOST_WIDEST_INT
) (mmix_intval (x
) - 1));
1717 /* Store the number of registers we want to save. This was setup
1718 by the prologue. The actual operand contains the number of
1719 registers to pass, but we don't use it currently. Anyway, we
1720 need to output the number of saved registers here. */
1721 fprintf (stream
, "%d",
1722 cfun
->machine
->highest_saved_stack_register
+ 1);
1726 /* Store the register to output a constant to. */
1728 fatal_insn ("MMIX Internal: Expected a register, not this", x
);
1729 mmix_output_destination_register
= MMIX_OUTPUT_REGNO (regno
);
1733 /* Output the constant. Note that we use this for floats as well. */
1734 if (GET_CODE (x
) != CONST_INT
1735 && (GET_CODE (x
) != CONST_DOUBLE
1736 || (GET_MODE (x
) != VOIDmode
&& GET_MODE (x
) != DFmode
1737 && GET_MODE (x
) != SFmode
)))
1738 fatal_insn ("MMIX Internal: Expected a constant, not this", x
);
1739 mmix_output_register_setting (stream
,
1740 mmix_output_destination_register
,
1741 mmix_intval (x
), 0);
1745 /* An U for unsigned, if TARGET_ZERO_EXTEND. Ignore the operand. */
1746 if (TARGET_ZERO_EXTEND
)
1751 mmix_output_shifted_value (stream
, (HOST_WIDEST_INT
) mmix_intval (x
));
1755 mmix_output_shifted_value (stream
, (HOST_WIDEST_INT
) ~mmix_intval (x
));
1759 if (GET_CODE (x
) != CONST_INT
)
1760 fatal_insn ("MMIX Internal: Expected a CONST_INT, not this", x
);
1761 fprintf (stream
, "#%x", (int) (INTVAL (x
) & 0xffff));
1765 /* Nothing to do. */
1769 /* Presumably there's a missing case above if we get here. */
1770 internal_error ("MMIX Internal: Missing `%c' case in mmix_print_operand", code
);
1773 switch (GET_CODE (modified_x
))
1776 regno
= REGNO (modified_x
);
1777 if (regno
>= FIRST_PSEUDO_REGISTER
)
1778 internal_error ("MMIX Internal: Bad register: %d", regno
);
1779 fprintf (stream
, "%s", reg_names
[MMIX_OUTPUT_REGNO (regno
)]);
1783 output_address (XEXP (modified_x
, 0));
1787 /* For -2147483648, mmixal complains that the constant does not fit
1788 in 4 bytes, so let's output it as hex. Take care to handle hosts
1789 where HOST_WIDE_INT is longer than an int.
1791 Print small constants +-255 using decimal. */
1793 if (INTVAL (modified_x
) > -256 && INTVAL (modified_x
) < 256)
1794 fprintf (stream
, "%d", (int) (INTVAL (modified_x
)));
1796 fprintf (stream
, "#%x",
1797 (int) (INTVAL (modified_x
)) & (unsigned int) ~0);
1801 /* Do somewhat as CONST_INT. */
1802 mmix_output_octa (stream
, mmix_intval (modified_x
), 0);
1806 output_addr_const (stream
, modified_x
);
1810 /* No need to test for all strange things. Let output_addr_const do
1812 if (CONSTANT_P (modified_x
)
1813 /* Strangely enough, this is not included in CONSTANT_P.
1814 FIXME: Ask/check about sanity here. */
1815 || GET_CODE (modified_x
) == CODE_LABEL
)
1817 output_addr_const (stream
, modified_x
);
1821 /* We need the original here. */
1822 fatal_insn ("MMIX Internal: Cannot decode this operand", x
);
1826 /* PRINT_OPERAND_PUNCT_VALID_P. */
1829 mmix_print_operand_punct_valid_p (code
)
1830 int code ATTRIBUTE_UNUSED
;
1832 /* A '+' is used for branch prediction, similar to other ports. */
1834 /* A '.' is used for the %d in the POP %d,0 return insn. */
1838 /* PRINT_OPERAND_ADDRESS. */
1841 mmix_print_operand_address (stream
, x
)
1847 /* I find the generated assembly code harder to read without
1849 fprintf (stream
, "%s,0", reg_names
[MMIX_OUTPUT_REGNO (REGNO (x
))]);
1852 else if (GET_CODE (x
) == PLUS
)
1854 rtx x1
= XEXP (x
, 0);
1855 rtx x2
= XEXP (x
, 1);
1859 fprintf (stream
, "%s,", reg_names
[MMIX_OUTPUT_REGNO (REGNO (x1
))]);
1863 fprintf (stream
, "%s",
1864 reg_names
[MMIX_OUTPUT_REGNO (REGNO (x2
))]);
1867 else if (GET_CODE (x2
) == CONST_INT
1868 && CONST_OK_FOR_LETTER_P (INTVAL (x2
), 'I'))
1870 output_addr_const (stream
, x2
);
1876 if (TARGET_BASE_ADDRESSES
&& mmix_legitimate_constant_p (x
))
1878 output_addr_const (stream
, x
);
1882 fatal_insn ("MMIX Internal: This is not a recognized address", x
);
1885 /* ASM_OUTPUT_REG_PUSH. */
1888 mmix_asm_output_reg_push (stream
, regno
)
1892 fprintf (stream
, "\tSUBU %s,%s,8\n\tSTOU %s,%s,0\n",
1893 reg_names
[MMIX_STACK_POINTER_REGNUM
],
1894 reg_names
[MMIX_STACK_POINTER_REGNUM
],
1895 reg_names
[MMIX_OUTPUT_REGNO (regno
)],
1896 reg_names
[MMIX_STACK_POINTER_REGNUM
]);
1899 /* ASM_OUTPUT_REG_POP. */
1902 mmix_asm_output_reg_pop (stream
, regno
)
1906 fprintf (stream
, "\tLDOU %s,%s,0\n\tINCL %s,8\n",
1907 reg_names
[MMIX_OUTPUT_REGNO (regno
)],
1908 reg_names
[MMIX_STACK_POINTER_REGNUM
],
1909 reg_names
[MMIX_STACK_POINTER_REGNUM
]);
1912 /* ASM_OUTPUT_ADDR_DIFF_ELT. */
1915 mmix_asm_output_addr_diff_elt (stream
, body
, value
, rel
)
1917 rtx body ATTRIBUTE_UNUSED
;
1921 fprintf (stream
, "\tTETRA L%d-L%d\n", value
, rel
);
1924 /* ASM_OUTPUT_ADDR_VEC_ELT. */
1927 mmix_asm_output_addr_vec_elt (stream
, value
)
1931 fprintf (stream
, "\tOCTA L:%d\n", value
);
1934 /* ASM_OUTPUT_SKIP. */
1937 mmix_asm_output_skip (stream
, nbytes
)
1941 fprintf (stream
, "\tLOC @+%d\n", nbytes
);
1944 /* ASM_OUTPUT_ALIGN. */
1947 mmix_asm_output_align (stream
, power
)
1951 /* We need to record the needed alignment of this section in the object,
1952 so we have to output an alignment directive. Use a .p2align (not
1953 .align) so people will never have to wonder about whether the
1954 argument is in number of bytes or the log2 thereof. We do it in
1955 addition to the LOC directive, so nothing needs tweaking when
1956 copy-pasting assembly into mmixal. */
1957 fprintf (stream
, "\t.p2align %d\n", power
);
1958 fprintf (stream
, "\tLOC @+(%d-@)&%d\n", 1 << power
, (1 << power
) - 1);
1961 /* DBX_REGISTER_NUMBER. */
1964 mmix_dbx_register_number (regno
)
1967 /* Adjust the register number to the one it will be output as, dammit.
1968 It'd be nice if we could check the assumption that we're filling a
1969 gap, but every register between the last saved register and parameter
1970 registers might be a valid parameter register. */
1971 regno
= MMIX_OUTPUT_REGNO (regno
);
1973 /* We need to renumber registers to get the number of the return address
1974 register in the range 0..255. It is also space-saving if registers
1975 mentioned in the call-frame information (which uses this function by
1976 defaulting DWARF_FRAME_REGNUM to DBX_REGISTER_NUMBER) are numbered
1977 0 .. 63. So map 224 .. 256+15 -> 0 .. 47 and 0 .. 223 -> 48..223+48. */
1978 return regno
>= 224 ? (regno
- 224) : (regno
+ 48);
1981 /* End of target macro support functions.
1983 Now MMIX's own functions. First the exported ones. */
1985 /* Wrapper for get_hard_reg_initial_val since integrate.h isn't included
1986 from insn-emit.c. */
1989 mmix_get_hard_reg_initial_val (mode
, regno
)
1990 enum machine_mode mode
;
1993 return get_hard_reg_initial_val (mode
, regno
);
1996 /* Nonzero when the function epilogue is simple enough that a single
1997 "POP %d,0" should be used even within the function. */
2000 mmix_use_simple_return ()
2004 int stack_space_to_allocate
2005 = (current_function_outgoing_args_size
2006 + current_function_pretend_args_size
2007 + get_frame_size () + 7) & ~7;
2009 if (!TARGET_USE_RETURN_INSN
|| !reload_completed
)
2013 regno
>= MMIX_FIRST_GLOBAL_REGNUM
;
2015 /* Note that we assume that the frame-pointer-register is one of these
2016 registers, in which case we don't count it here. */
2017 if ((((regno
!= MMIX_FRAME_POINTER_REGNUM
|| !frame_pointer_needed
)
2018 && regs_ever_live
[regno
] && !call_used_regs
[regno
]))
2019 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
2022 if (frame_pointer_needed
)
2023 stack_space_to_allocate
+= 8;
2025 if (MMIX_CFUN_HAS_LANDING_PAD
)
2026 stack_space_to_allocate
+= 16;
2027 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
)
2028 stack_space_to_allocate
+= 8;
2030 return stack_space_to_allocate
== 0;
2034 /* Expands the function prologue into RTX. */
2037 mmix_expand_prologue ()
2039 HOST_WIDE_INT locals_size
= get_frame_size ();
2041 HOST_WIDE_INT stack_space_to_allocate
2042 = (current_function_outgoing_args_size
2043 + current_function_pretend_args_size
2044 + locals_size
+ 7) & ~7;
2045 HOST_WIDE_INT offset
= -8;
2047 /* Add room needed to save global non-register-stack registers. */
2049 regno
>= MMIX_FIRST_GLOBAL_REGNUM
;
2051 /* Note that we assume that the frame-pointer-register is one of these
2052 registers, in which case we don't count it here. */
2053 if ((((regno
!= MMIX_FRAME_POINTER_REGNUM
|| !frame_pointer_needed
)
2054 && regs_ever_live
[regno
] && !call_used_regs
[regno
]))
2055 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
2056 stack_space_to_allocate
+= 8;
2058 /* If we do have a frame-pointer, add room for it. */
2059 if (frame_pointer_needed
)
2060 stack_space_to_allocate
+= 8;
2062 /* If we have a non-local label, we need to be able to unwind to it, so
2063 store the current register stack pointer. Also store the return
2064 address if we do that. */
2065 if (MMIX_CFUN_HAS_LANDING_PAD
)
2066 stack_space_to_allocate
+= 16;
2067 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
)
2068 /* If we do have a saved return-address slot, add room for it. */
2069 stack_space_to_allocate
+= 8;
2071 /* Make sure we don't get an unaligned stack. */
2072 if ((stack_space_to_allocate
% 8) != 0)
2073 internal_error ("stack frame not a multiple of 8 bytes: %d",
2074 stack_space_to_allocate
);
2076 if (current_function_pretend_args_size
)
2078 int mmix_first_vararg_reg
2079 = (MMIX_FIRST_INCOMING_ARG_REGNUM
2080 + (MMIX_MAX_ARGS_IN_REGS
2081 - current_function_pretend_args_size
/ 8));
2084 = MMIX_FIRST_INCOMING_ARG_REGNUM
+ MMIX_MAX_ARGS_IN_REGS
- 1;
2085 regno
>= mmix_first_vararg_reg
;
2090 HOST_WIDE_INT stack_chunk
2091 = stack_space_to_allocate
> (256 - 8)
2092 ? (256 - 8) : stack_space_to_allocate
;
2094 mmix_emit_sp_add (-stack_chunk
);
2095 offset
+= stack_chunk
;
2096 stack_space_to_allocate
-= stack_chunk
;
2099 /* These registers aren't actually saved (as in "will be
2100 restored"), so don't tell DWARF2 they're saved. */
2101 emit_move_insn (gen_rtx_MEM (DImode
,
2102 plus_constant (stack_pointer_rtx
,
2104 gen_rtx_REG (DImode
, regno
));
2109 /* Store the frame-pointer. */
2111 if (frame_pointer_needed
)
2117 /* Get 8 less than otherwise, since we need to reach offset + 8. */
2118 HOST_WIDE_INT stack_chunk
2119 = stack_space_to_allocate
> (256 - 8 - 8)
2120 ? (256 - 8 - 8) : stack_space_to_allocate
;
2122 mmix_emit_sp_add (-stack_chunk
);
2124 offset
+= stack_chunk
;
2125 stack_space_to_allocate
-= stack_chunk
;
2128 insn
= emit_move_insn (gen_rtx_MEM (DImode
,
2129 plus_constant (stack_pointer_rtx
,
2131 hard_frame_pointer_rtx
);
2132 RTX_FRAME_RELATED_P (insn
) = 1;
2133 insn
= emit_insn (gen_adddi3 (hard_frame_pointer_rtx
,
2135 GEN_INT (offset
+ 8)));
2136 RTX_FRAME_RELATED_P (insn
) = 1;
2140 if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
)
2145 /* Store the return-address, if one is needed on the stack. We
2146 usually store it in a register when needed, but that doesn't work
2147 with -fexceptions. */
2151 /* Get 8 less than otherwise, since we need to reach offset + 8. */
2152 HOST_WIDE_INT stack_chunk
2153 = stack_space_to_allocate
> (256 - 8 - 8)
2154 ? (256 - 8 - 8) : stack_space_to_allocate
;
2156 mmix_emit_sp_add (-stack_chunk
);
2158 offset
+= stack_chunk
;
2159 stack_space_to_allocate
-= stack_chunk
;
2162 tmpreg
= gen_rtx_REG (DImode
, 255);
2163 retreg
= gen_rtx_REG (DImode
, MMIX_rJ_REGNUM
);
2165 /* Dwarf2 code is confused by the use of a temporary register for
2166 storing the return address, so we have to express it as a note,
2167 which we attach to the actual store insn. */
2168 emit_move_insn (tmpreg
, retreg
);
2170 insn
= emit_move_insn (gen_rtx_MEM (DImode
,
2171 plus_constant (stack_pointer_rtx
,
2174 RTX_FRAME_RELATED_P (insn
) = 1;
2176 = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR
,
2177 gen_rtx_SET (VOIDmode
,
2178 gen_rtx_MEM (DImode
,
2179 plus_constant (stack_pointer_rtx
,
2186 else if (MMIX_CFUN_HAS_LANDING_PAD
)
2189 if (MMIX_CFUN_HAS_LANDING_PAD
)
2191 /* Store the register defining the numbering of local registers, so
2192 we know how long to unwind the register stack. */
2196 /* Get 8 less than otherwise, since we need to reach offset + 8. */
2197 HOST_WIDE_INT stack_chunk
2198 = stack_space_to_allocate
> (256 - 8 - 8)
2199 ? (256 - 8 - 8) : stack_space_to_allocate
;
2201 mmix_emit_sp_add (-stack_chunk
);
2203 offset
+= stack_chunk
;
2204 stack_space_to_allocate
-= stack_chunk
;
2207 /* We don't tell dwarf2 about this one; we just have it to unwind
2208 the register stack at landing pads. FIXME: It's a kludge because
2209 we can't describe the effect of the PUSHJ and PUSHGO insns on the
2210 register stack at the moment. Best thing would be to handle it
2211 like stack-pointer offsets. Better: some hook into dwarf2out.c
2212 to produce DW_CFA_expression:s that specify the increment of rO,
2213 and unwind it at eh_return (preferred) or at the landing pad.
2214 Then saves to $0..$G-1 could be specified through that register. */
2216 emit_move_insn (gen_rtx_REG (DImode
, 255),
2217 gen_rtx_REG (DImode
,
2219 emit_move_insn (gen_rtx_MEM (DImode
,
2220 plus_constant (stack_pointer_rtx
, offset
)),
2221 gen_rtx_REG (DImode
, 255));
2225 /* After the return-address and the frame-pointer, we have the local
2226 variables. They're the ones that may have an "unaligned" size. */
2227 offset
-= (locals_size
+ 7) & ~7;
2229 /* Now store all registers that are global, i.e. not saved by the
2230 register file machinery.
2232 It is assumed that the frame-pointer is one of these registers, so it
2233 is explicitly excluded in the count. */
2236 regno
>= MMIX_FIRST_GLOBAL_REGNUM
;
2238 if (((regno
!= MMIX_FRAME_POINTER_REGNUM
|| !frame_pointer_needed
)
2239 && regs_ever_live
[regno
] && ! call_used_regs
[regno
])
2240 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
2246 HOST_WIDE_INT stack_chunk
2247 = (stack_space_to_allocate
> (256 - offset
- 8)
2248 ? (256 - offset
- 8) : stack_space_to_allocate
);
2250 mmix_emit_sp_add (-stack_chunk
);
2251 offset
+= stack_chunk
;
2252 stack_space_to_allocate
-= stack_chunk
;
2255 insn
= emit_move_insn (gen_rtx_MEM (DImode
,
2256 plus_constant (stack_pointer_rtx
,
2258 gen_rtx_REG (DImode
, regno
));
2259 RTX_FRAME_RELATED_P (insn
) = 1;
2263 /* Finally, allocate room for outgoing args and local vars if room
2264 wasn't allocated above. */
2265 if (stack_space_to_allocate
)
2266 mmix_emit_sp_add (-stack_space_to_allocate
);
2269 /* Expands the function epilogue into RTX. */
2272 mmix_expand_epilogue ()
2274 HOST_WIDE_INT locals_size
= get_frame_size ();
2276 HOST_WIDE_INT stack_space_to_deallocate
2277 = (current_function_outgoing_args_size
2278 + current_function_pretend_args_size
2279 + locals_size
+ 7) & ~7;
2281 /* The assumption that locals_size fits in an int is asserted in
2282 mmix_expand_prologue. */
2284 /* The first address to access is beyond the outgoing_args area. */
2285 int offset
= current_function_outgoing_args_size
;
2287 /* Add the space for global non-register-stack registers.
2288 It is assumed that the frame-pointer register can be one of these
2289 registers, in which case it is excluded from the count when needed. */
2291 regno
>= MMIX_FIRST_GLOBAL_REGNUM
;
2293 if (((regno
!= MMIX_FRAME_POINTER_REGNUM
|| !frame_pointer_needed
)
2294 && regs_ever_live
[regno
] && !call_used_regs
[regno
])
2295 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
2296 stack_space_to_deallocate
+= 8;
2298 /* Add in the space for register stack-pointer. If so, always add room
2299 for the saved PC. */
2300 if (MMIX_CFUN_HAS_LANDING_PAD
)
2301 stack_space_to_deallocate
+= 16;
2302 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
)
2303 /* If we have a saved return-address slot, add it in. */
2304 stack_space_to_deallocate
+= 8;
2306 /* Add in the frame-pointer. */
2307 if (frame_pointer_needed
)
2308 stack_space_to_deallocate
+= 8;
2310 /* Make sure we don't get an unaligned stack. */
2311 if ((stack_space_to_deallocate
% 8) != 0)
2312 internal_error ("stack frame not a multiple of octabyte: %d",
2313 stack_space_to_deallocate
);
2315 /* We will add back small offsets to the stack pointer as we go.
2316 First, we restore all registers that are global, i.e. not saved by
2317 the register file machinery. */
2319 for (regno
= MMIX_FIRST_GLOBAL_REGNUM
;
2322 if (((regno
!= MMIX_FRAME_POINTER_REGNUM
|| !frame_pointer_needed
)
2323 && regs_ever_live
[regno
] && !call_used_regs
[regno
])
2324 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
2328 mmix_emit_sp_add (offset
);
2329 stack_space_to_deallocate
-= offset
;
2333 emit_move_insn (gen_rtx_REG (DImode
, regno
),
2334 gen_rtx_MEM (DImode
,
2335 plus_constant (stack_pointer_rtx
,
2340 /* Here is where the local variables were. As in the prologue, they
2341 might be of an unaligned size. */
2342 offset
+= (locals_size
+ 7) & ~7;
2345 /* The saved register stack pointer is just below the frame-pointer
2346 register. We don't need to restore it "manually"; the POP
2347 instruction does that. */
2348 if (MMIX_CFUN_HAS_LANDING_PAD
)
2350 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
)
2351 /* The return-address slot is just below the frame-pointer register.
2352 We don't need to restore it because we don't really use it. */
2355 /* Get back the old frame-pointer-value. */
2356 if (frame_pointer_needed
)
2360 mmix_emit_sp_add (offset
);
2362 stack_space_to_deallocate
-= offset
;
2366 emit_move_insn (hard_frame_pointer_rtx
,
2367 gen_rtx_MEM (DImode
,
2368 plus_constant (stack_pointer_rtx
,
2373 /* We do not need to restore pretended incoming args, just add back
2375 if (stack_space_to_deallocate
!= 0)
2376 mmix_emit_sp_add (stack_space_to_deallocate
);
2378 if (current_function_calls_eh_return
)
2379 /* Adjust the (normal) stack-pointer to that of the receiver.
2380 FIXME: It would be nice if we could also adjust the register stack
2381 here, but we need to express it through DWARF 2 too. */
2382 emit_insn (gen_adddi3 (stack_pointer_rtx
, stack_pointer_rtx
,
2383 gen_rtx_REG (DImode
,
2384 MMIX_EH_RETURN_STACKADJ_REGNUM
)));
2387 /* Output an optimal sequence for setting a register to a specific
2388 constant. Used in an alternative for const_ints in movdi, and when
2389 using large stack-frame offsets.
2391 Use do_begin_end to say if a line-starting TAB and newline before the
2392 first insn and after the last insn is wanted. */
2395 mmix_output_register_setting (stream
, regno
, value
, do_begin_end
)
2398 HOST_WIDEST_INT value
;
2402 fprintf (stream
, "\t");
2404 if (mmix_shiftable_wyde_value ((unsigned HOST_WIDEST_INT
) value
))
2406 /* First, the one-insn cases. */
2407 mmix_output_shiftvalue_op_from_str (stream
, "SET",
2408 (unsigned HOST_WIDEST_INT
)
2410 fprintf (stream
, " %s,", reg_names
[regno
]);
2411 mmix_output_shifted_value (stream
, (unsigned HOST_WIDEST_INT
) value
);
2413 else if (mmix_shiftable_wyde_value (-(unsigned HOST_WIDEST_INT
) value
))
2415 /* We do this to get a bit more legible assembly code. The next
2416 alternative is mostly redundant with this. */
2418 mmix_output_shiftvalue_op_from_str (stream
, "SET",
2419 -(unsigned HOST_WIDEST_INT
)
2421 fprintf (stream
, " %s,", reg_names
[regno
]);
2422 mmix_output_shifted_value (stream
, -(unsigned HOST_WIDEST_INT
) value
);
2423 fprintf (stream
, "\n\tNEGU %s,0,%s", reg_names
[regno
],
2426 else if (mmix_shiftable_wyde_value (~(unsigned HOST_WIDEST_INT
) value
))
2428 /* Slightly more expensive, the two-insn cases. */
2430 /* FIXME: We could of course also test if 0..255-N or ~(N | 1..255)
2431 is shiftable, or any other one-insn transformation of the value.
2432 FIXME: Check first if the value is "shiftable" by two loading
2433 with two insns, since it makes more readable assembly code (if
2434 anyone else cares). */
2436 mmix_output_shiftvalue_op_from_str (stream
, "SET",
2437 ~(unsigned HOST_WIDEST_INT
)
2439 fprintf (stream
, " %s,", reg_names
[regno
]);
2440 mmix_output_shifted_value (stream
, ~(unsigned HOST_WIDEST_INT
) value
);
2441 fprintf (stream
, "\n\tNOR %s,%s,0", reg_names
[regno
],
2446 /* The generic case. 2..4 insns. */
2447 static const char *const higher_parts
[] = {"L", "ML", "MH", "H"};
2448 const char *op
= "SET";
2449 const char *line_begin
= "";
2452 HOST_WIDEST_INT tmpvalue
= value
;
2454 /* Compute the number of insns needed to output this constant. */
2455 for (i
= 0; i
< 4 && tmpvalue
!= 0; i
++)
2457 if (tmpvalue
& 65535)
2461 if (TARGET_BASE_ADDRESSES
&& insns
== 3)
2463 /* The number three is based on a static observation on
2464 ghostscript-6.52. Two and four are excluded because there
2465 are too many such constants, and each unique constant (maybe
2466 offset by 1..255) were used few times compared to other uses,
2469 We use base-plus-offset addressing to force it into a global
2470 register; we just use a "LDA reg,VALUE", which will cause the
2471 assembler and linker to DTRT (for constants as well as
2473 fprintf (stream
, "LDA %s,", reg_names
[regno
]);
2474 mmix_output_octa (stream
, value
, 0);
2478 /* Output pertinent parts of the 4-wyde sequence.
2479 Still more to do if we want this to be optimal, but hey...
2480 Note that the zero case has been handled above. */
2481 for (i
= 0; i
< 4 && value
!= 0; i
++)
2485 fprintf (stream
, "%s%s%s %s,#%x", line_begin
, op
,
2486 higher_parts
[i
], reg_names
[regno
],
2487 (int) (value
& 65535));
2488 /* The first one sets the rest of the bits to 0, the next
2489 ones add set bits. */
2491 line_begin
= "\n\t";
2500 fprintf (stream
, "\n");
2503 /* Return 1 if value is 0..65535*2**(16*N) for N=0..3.
2507 mmix_shiftable_wyde_value (value
)
2508 unsigned HOST_WIDEST_INT value
;
2510 /* Shift by 16 bits per group, stop when we've found two groups with
2513 int has_candidate
= 0;
2515 for (i
= 0; i
< 4; i
++)
2531 /* True if this is an address_operand or a symbolic operand. */
2534 mmix_symbolic_or_address_operand (op
, mode
)
2536 enum machine_mode mode
;
2538 switch (GET_CODE (op
))
2545 if ((GET_CODE (XEXP (op
, 0)) == SYMBOL_REF
2546 || GET_CODE (XEXP (op
, 0)) == LABEL_REF
)
2547 && (GET_CODE (XEXP (op
, 1)) == CONST_INT
2548 || (GET_CODE (XEXP (op
, 1)) == CONST_DOUBLE
2549 && GET_MODE (XEXP (op
, 1)) == VOIDmode
)))
2553 return address_operand (op
, mode
);
2557 /* True if this is a register or CONST_INT (or CONST_DOUBLE for DImode).
2558 We could narrow the value down with a couple of predicated, but that
2559 doesn't seem to be worth it at the moment. */
2562 mmix_reg_or_constant_operand (op
, mode
)
2564 enum machine_mode mode
;
2566 return register_operand (op
, mode
)
2567 || (GET_CODE (op
) == CONST_DOUBLE
&& GET_MODE (op
) == VOIDmode
)
2568 || GET_CODE (op
) == CONST_INT
;
2571 /* True if this is a register with a condition-code mode. */
2574 mmix_reg_cc_operand (op
, mode
)
2576 enum machine_mode mode
;
2578 if (mode
== VOIDmode
)
2579 mode
= GET_MODE (op
);
2581 return register_operand (op
, mode
)
2582 && (mode
== CCmode
|| mode
== CC_UNSmode
|| mode
== CC_FPmode
2583 || mode
== CC_FPEQmode
|| mode
== CC_FUNmode
);
2586 /* True if this is a foldable comparison operator
2587 - one where a the result of (compare:CC (reg) (const_int 0)) can be
2588 replaced by (reg). */
2591 mmix_foldable_comparison_operator (op
, mode
)
2593 enum machine_mode mode
;
2595 RTX_CODE code
= GET_CODE (op
);
2597 if (mode
== VOIDmode
)
2598 mode
= GET_MODE (op
);
2600 if (mode
== VOIDmode
&& GET_RTX_CLASS (GET_CODE (op
)) == '<')
2601 mode
= GET_MODE (XEXP (op
, 0));
2603 return ((mode
== CCmode
|| mode
== DImode
)
2604 && (code
== NE
|| code
== EQ
|| code
== GE
|| code
== GT
2606 /* FIXME: This may be a stupid trick. What happens when GCC wants to
2607 reverse the condition? Can it do that by itself? Maybe it can
2608 even reverse the condition to fit a foldable one in the first
2610 || (mode
== CC_UNSmode
&& (code
== GTU
|| code
== LEU
));
2613 /* Like comparison_operator, but only true if this comparison operator is
2614 applied to a valid mode. Needed to avoid jump.c generating invalid
2615 code with -ffast-math (gcc.dg/20001228-1.c). */
2618 mmix_comparison_operator (op
, mode
)
2620 enum machine_mode mode
;
2622 RTX_CODE code
= GET_CODE (op
);
2624 /* Comparison operators usually don't have a mode, but let's try and get
2625 one anyway for the day that changes. */
2626 if (mode
== VOIDmode
)
2627 mode
= GET_MODE (op
);
2629 /* Get the mode from the first operand if we don't have one. */
2630 if (mode
== VOIDmode
&& GET_RTX_CLASS (GET_CODE (op
)) == '<')
2631 mode
= GET_MODE (XEXP (op
, 0));
2633 /* FIXME: This needs to be kept in sync with the tables in
2634 mmix_output_condition. */
2636 (mode
== VOIDmode
&& GET_RTX_CLASS (GET_CODE (op
)) == '<')
2637 || (mode
== CC_FUNmode
2638 && (code
== ORDERED
|| code
== UNORDERED
))
2639 || (mode
== CC_FPmode
2640 && (code
== GT
|| code
== LT
))
2641 || (mode
== CC_FPEQmode
2642 && (code
== NE
|| code
== EQ
))
2643 || (mode
== CC_UNSmode
2644 && (code
== GEU
|| code
== GTU
|| code
== LEU
|| code
== LTU
))
2646 && (code
== NE
|| code
== EQ
|| code
== GE
|| code
== GT
2647 || code
== LE
|| code
== LT
))
2649 && (code
== NE
|| code
== EQ
|| code
== GE
|| code
== GT
2650 || code
== LE
|| code
== LT
|| code
== LEU
|| code
== GTU
));
2653 /* True if this is a register or 0 (int or float). */
2656 mmix_reg_or_0_operand (op
, mode
)
2658 enum machine_mode mode
;
2660 /* FIXME: Is mode calculation necessary and correct? */
2662 op
== CONST0_RTX (mode
== VOIDmode
? GET_MODE (op
) : mode
)
2663 || register_operand (op
, mode
);
2666 /* True if this is a register or an int 0..255. */
2669 mmix_reg_or_8bit_operand (op
, mode
)
2671 enum machine_mode mode
;
2673 return register_operand (op
, mode
)
2674 || (GET_CODE (op
) == CONST_INT
2675 && CONST_OK_FOR_LETTER_P (INTVAL (op
), 'I'));
2678 /* Returns zero if code and mode is not a valid condition from a
2679 compare-type insn. Nonzero if it is. The parameter op, if non-NULL,
2680 is the comparison of mode is CC-somethingmode. */
2683 mmix_valid_comparison (code
, mode
, op
)
2685 enum machine_mode mode
;
2688 if (mode
== VOIDmode
&& op
!= NULL_RTX
)
2689 mode
= GET_MODE (op
);
2691 /* We don't care to look at these, they should always be valid. */
2692 if (mode
== CCmode
|| mode
== CC_UNSmode
|| mode
== DImode
)
2695 if ((mode
== CC_FPmode
|| mode
== DFmode
)
2696 && (code
== GT
|| code
== LT
))
2699 if ((mode
== CC_FPEQmode
|| mode
== DFmode
)
2700 && (code
== EQ
|| code
== NE
))
2703 if ((mode
== CC_FUNmode
|| mode
== DFmode
)
2704 && (code
== ORDERED
|| code
== UNORDERED
))
2710 /* X and Y are two things to compare using CODE. Emit a compare insn if
2711 possible and return the rtx for the cc-reg in the proper mode, or
2712 NULL_RTX if this is not a valid comparison. */
2715 mmix_gen_compare_reg (code
, x
, y
)
2719 enum machine_mode ccmode
= SELECT_CC_MODE (code
, x
, y
);
2722 /* FIXME: Do we get constants here? Of double mode? */
2723 enum machine_mode mode
2724 = GET_MODE (x
) == VOIDmode
2726 : GET_MODE_CLASS (GET_MODE (x
)) == MODE_FLOAT
? DFmode
: DImode
;
2728 if (! mmix_valid_comparison (code
, mode
, x
))
2731 cc_reg
= gen_reg_rtx (ccmode
);
2733 /* FIXME: Can we avoid emitting a compare insn here? */
2734 if (! REG_P (x
) && ! REG_P (y
))
2735 x
= force_reg (mode
, x
);
2737 /* If it's not quite right yet, put y in a register. */
2739 && (GET_CODE (y
) != CONST_INT
2740 || ! CONST_OK_FOR_LETTER_P (INTVAL (y
), 'I')))
2741 y
= force_reg (mode
, y
);
2743 emit_insn (gen_rtx_SET (VOIDmode
, cc_reg
,
2744 gen_rtx_COMPARE (ccmode
, x
, y
)));
2749 /* Local (static) helper functions. */
2752 mmix_emit_sp_add (offset
)
2753 HOST_WIDE_INT offset
;
2759 /* Negative stack-pointer adjustments are allocations and appear in
2760 the prologue only. We mark them as frame-related so unwind and
2761 debug info is properly emitted for them. */
2763 insn
= emit_insn (gen_adddi3 (stack_pointer_rtx
,
2768 rtx tmpr
= gen_rtx_REG (DImode
, 255);
2769 RTX_FRAME_RELATED_P (emit_move_insn (tmpr
, GEN_INT (offset
))) = 1;
2770 insn
= emit_insn (gen_adddi3 (stack_pointer_rtx
,
2771 stack_pointer_rtx
, tmpr
));
2773 RTX_FRAME_RELATED_P (insn
) = 1;
2777 /* Positive adjustments are in the epilogue only. Don't mark them
2778 as "frame-related" for unwind info. */
2779 if (CONST_OK_FOR_LETTER_P (offset
, 'L'))
2780 emit_insn (gen_adddi3 (stack_pointer_rtx
,
2785 rtx tmpr
= gen_rtx_REG (DImode
, 255);
2786 emit_move_insn (tmpr
, GEN_INT (offset
));
2787 insn
= emit_insn (gen_adddi3 (stack_pointer_rtx
,
2788 stack_pointer_rtx
, tmpr
));
2793 /* Print operator suitable for doing something with a shiftable
2794 wyde. The type of operator is passed as an asm output modifier. */
2797 mmix_output_shiftvalue_op_from_str (stream
, mainop
, value
)
2800 HOST_WIDEST_INT value
;
2802 static const char *const op_part
[] = {"L", "ML", "MH", "H"};
2805 if (! mmix_shiftable_wyde_value (value
))
2807 char s
[sizeof ("0xffffffffffffffff")];
2808 sprintf (s
, HOST_WIDEST_INT_PRINT_HEX
, value
);
2809 internal_error ("MMIX Internal: %s is not a shiftable int", s
);
2812 for (i
= 0; i
< 4; i
++)
2814 /* We know we're through when we find one-bits in the low
2818 fprintf (stream
, "%s%s", mainop
, op_part
[i
]);
2824 /* No bits set? Then it must have been zero. */
2825 fprintf (stream
, "%sL", mainop
);
2828 /* Print a 64-bit value, optionally prefixed by assembly pseudo. */
2831 mmix_output_octa (stream
, value
, do_begin_end
)
2833 HOST_WIDEST_INT value
;
2836 /* Snipped from final.c:output_addr_const. We need to avoid the
2837 presumed universal "0x" prefix. We can do it by replacing "0x" with
2838 "#0" here; we must avoid a space in the operands and no, the zero
2839 won't cause the number to be assumed in octal format. */
2840 char hex_format
[sizeof (HOST_WIDEST_INT_PRINT_HEX
)];
2843 fprintf (stream
, "\tOCTA ");
2845 strcpy (hex_format
, HOST_WIDEST_INT_PRINT_HEX
);
2846 hex_format
[0] = '#';
2847 hex_format
[1] = '0';
2849 /* Provide a few alternative output formats depending on the number, to
2850 improve legibility of assembler output. */
2851 if ((value
< (HOST_WIDEST_INT
) 0 && value
> (HOST_WIDEST_INT
) -10000)
2852 || (value
>= (HOST_WIDEST_INT
) 0 && value
<= (HOST_WIDEST_INT
) 16384))
2853 fprintf (stream
, "%d", (int) value
);
2854 else if (value
> (HOST_WIDEST_INT
) 0
2855 && value
< ((HOST_WIDEST_INT
) 1 << 31) * 2)
2856 fprintf (stream
, "#%x", (unsigned int) value
);
2858 fprintf (stream
, hex_format
, value
);
2861 fprintf (stream
, "\n");
2864 /* Print the presumed shiftable wyde argument shifted into place (to
2865 be output with an operand). */
2868 mmix_output_shifted_value (stream
, value
)
2870 HOST_WIDEST_INT value
;
2874 if (! mmix_shiftable_wyde_value (value
))
2877 sprintf (s
, HOST_WIDEST_INT_PRINT_HEX
, value
);
2878 internal_error ("MMIX Internal: %s is not a shiftable int", s
);
2881 for (i
= 0; i
< 4; i
++)
2883 /* We know we're through when we find one-bits in the low 16 bits. */
2886 fprintf (stream
, "#%x", (int) (value
& 0xffff));
2893 /* No bits set? Then it must have been zero. */
2894 fprintf (stream
, "0");
2897 /* Output an MMIX condition name corresponding to an operator
2899 (comparison_operator [(comparison_operator ...) (const_int 0)])
2900 which means we have to look at *two* operators.
2902 The argument "reversed" refers to reversal of the condition (not the
2903 same as swapping the arguments). */
2906 mmix_output_condition (stream
, x
, reversed
)
2915 /* The normal output cc-code. */
2916 const char *const normal
;
2918 /* The reversed cc-code, or NULL if invalid. */
2919 const char *const reversed
;
2924 enum machine_mode cc_mode
;
2926 /* Terminated with {NIL, NULL, NULL} */
2927 const struct cc_conv
*const convs
;
2931 #define CCEND {NIL, NULL, NULL}
2933 static const struct cc_conv cc_fun_convs
[]
2934 = {{ORDERED
, "Z", "P"},
2935 {UNORDERED
, "P", "Z"},
2937 static const struct cc_conv cc_fp_convs
[]
2941 static const struct cc_conv cc_fpeq_convs
[]
2945 static const struct cc_conv cc_uns_convs
[]
2946 = {{GEU
, "NN", "N"},
2951 static const struct cc_conv cc_signed_convs
[]
2959 static const struct cc_conv cc_di_convs
[]
2971 static const struct cc_type_conv cc_convs
[]
2972 = {{CC_FUNmode
, cc_fun_convs
},
2973 {CC_FPmode
, cc_fp_convs
},
2974 {CC_FPEQmode
, cc_fpeq_convs
},
2975 {CC_UNSmode
, cc_uns_convs
},
2976 {CCmode
, cc_signed_convs
},
2977 {DImode
, cc_di_convs
}};
2982 enum machine_mode mode
= GET_MODE (XEXP (x
, 0));
2983 RTX_CODE cc
= GET_CODE (x
);
2985 for (i
= 0; i
< ARRAY_SIZE (cc_convs
); i
++)
2987 if (mode
== cc_convs
[i
].cc_mode
)
2989 for (j
= 0; cc_convs
[i
].convs
[j
].cc
!= NIL
; j
++)
2990 if (cc
== cc_convs
[i
].convs
[j
].cc
)
2993 = (reversed
? cc_convs
[i
].convs
[j
].reversed
2994 : cc_convs
[i
].convs
[j
].normal
);
2996 if (mmix_cc
== NULL
)
2997 fatal_insn ("MMIX Internal: Trying to output invalidly\
2998 reversed condition:", x
);
3000 fprintf (stream
, "%s", mmix_cc
);
3004 fatal_insn ("MMIX Internal: What's the CC of this?", x
);
3008 fatal_insn ("MMIX Internal: What is the CC of this?", x
);
3011 /* Return the bit-value for a const_int or const_double. */
3013 static HOST_WIDEST_INT
3017 unsigned HOST_WIDEST_INT retval
;
3019 if (GET_CODE (x
) == CONST_INT
)
3022 /* We make a little song and dance because converting to long long in
3023 gcc-2.7.2 is broken. I still want people to be able to use it for
3024 cross-compilation to MMIX. */
3025 if (GET_CODE (x
) == CONST_DOUBLE
&& GET_MODE (x
) == VOIDmode
)
3027 if (sizeof (HOST_WIDE_INT
) < sizeof (HOST_WIDEST_INT
))
3029 retval
= (unsigned) CONST_DOUBLE_LOW (x
) / 2;
3031 retval
|= CONST_DOUBLE_LOW (x
) & 1;
3034 (unsigned HOST_WIDEST_INT
) CONST_DOUBLE_HIGH (x
)
3035 << (HOST_BITS_PER_LONG
);
3038 retval
= CONST_DOUBLE_HIGH (x
);
3043 if (GET_CODE (x
) == CONST_DOUBLE
)
3045 REAL_VALUE_TYPE value
;
3047 /* FIXME: This macro is not in the manual but should be. */
3048 REAL_VALUE_FROM_CONST_DOUBLE (value
, x
);
3050 if (GET_MODE (x
) == DFmode
)
3054 REAL_VALUE_TO_TARGET_DOUBLE (value
, bits
);
3056 if (sizeof (long) < sizeof (HOST_WIDEST_INT
))
3058 retval
= (unsigned long) bits
[1] / 2;
3060 retval
|= (unsigned long) bits
[1] & 1;
3062 |= (unsigned HOST_WIDEST_INT
) bits
[0]
3063 << (sizeof (bits
[0]) * 8);
3066 retval
= (unsigned long) bits
[1];
3070 else if (GET_MODE (x
) == SFmode
)
3073 REAL_VALUE_TO_TARGET_SINGLE (value
, bits
);
3075 return (unsigned long) bits
;
3079 fatal_insn ("MMIX Internal: This is not a constant:", x
);
3084 * eval: (c-set-style "gnu")
3085 * indent-tabs-mode: t