1 /* Definitions of target machine for GNU compiler, for MMIX.
2 Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
4 Free Software Foundation, Inc.
5 Contributed by Hans-Peter Nilsson (hp@bitrange.com)
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3, or (at your option)
14 GCC is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
25 #include "coretypes.h"
29 #include "hard-reg-set.h"
31 #include "insn-config.h"
33 #include "basic-block.h"
38 #include "diagnostic-core.h"
45 #include "integrate.h"
47 #include "target-def.h"
50 /* First some local helper definitions. */
51 #define MMIX_FIRST_GLOBAL_REGNUM 32
53 /* We'd need a current_function_has_landing_pad. It's marked as such when
54 a nonlocal_goto_receiver is expanded. Not just a C++ thing, but
56 #define MMIX_CFUN_HAS_LANDING_PAD (cfun->machine->has_landing_pad != 0)
58 /* We have no means to tell DWARF 2 about the register stack, so we need
59 to store the return address on the stack if an exception can get into
60 this function. FIXME: Narrow condition. Before any whole-function
61 analysis, df_regs_ever_live_p () isn't initialized. We know it's up-to-date
62 after reload_completed; it may contain incorrect information some time
63 before that. Within a RTL sequence (after a call to start_sequence,
64 such as in RTL expanders), leaf_function_p doesn't see all insns
65 (perhaps any insn). But regs_ever_live is up-to-date when
66 leaf_function_p () isn't, so we "or" them together to get accurate
67 information. FIXME: Some tweak to leaf_function_p might be
69 #define MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS \
71 && ((reload_completed && df_regs_ever_live_p (MMIX_rJ_REGNUM)) \
72 || !leaf_function_p ()))
74 #define IS_MMIX_EH_RETURN_DATA_REG(REGNO) \
75 (crtl->calls_eh_return \
76 && (EH_RETURN_DATA_REGNO (0) == REGNO \
77 || EH_RETURN_DATA_REGNO (1) == REGNO \
78 || EH_RETURN_DATA_REGNO (2) == REGNO \
79 || EH_RETURN_DATA_REGNO (3) == REGNO))
81 /* For the default ABI, we rename registers at output-time to fill the gap
82 between the (statically partitioned) saved registers and call-clobbered
83 registers. In effect this makes unused call-saved registers to be used
84 as call-clobbered registers. The benefit comes from keeping the number
85 of local registers (value of rL) low, since there's a cost of
86 increasing rL and clearing unused (unset) registers with lower numbers.
87 Don't translate while outputting the prologue. */
88 #define MMIX_OUTPUT_REGNO(N) \
90 || (int) (N) < MMIX_RETURN_VALUE_REGNUM \
91 || (int) (N) > MMIX_LAST_STACK_REGISTER_REGNUM \
93 || cfun->machine == NULL \
94 || cfun->machine->in_prologue \
95 ? (N) : ((N) - MMIX_RETURN_VALUE_REGNUM \
96 + cfun->machine->highest_saved_stack_register + 1))
98 /* The %d in "POP %d,0". */
99 #define MMIX_POP_ARGUMENT() \
101 && crtl->return_rtx != NULL \
102 && ! cfun->returns_struct) \
103 ? (GET_CODE (crtl->return_rtx) == PARALLEL \
104 ? GET_NUM_ELEM (XVEC (crtl->return_rtx, 0)) : 1) \
107 /* The canonical saved comparison operands for non-cc0 machines, set in
108 the compare expander. */
109 rtx mmix_compare_op0
;
110 rtx mmix_compare_op1
;
112 /* Declarations of locals. */
114 /* Intermediate for insn output. */
115 static int mmix_output_destination_register
;
117 static void mmix_option_override (void);
118 static void mmix_asm_output_source_filename (FILE *, const char *);
119 static void mmix_output_shiftvalue_op_from_str
120 (FILE *, const char *, HOST_WIDEST_INT
);
121 static void mmix_output_shifted_value (FILE *, HOST_WIDEST_INT
);
122 static void mmix_output_condition (FILE *, rtx
, int);
123 static HOST_WIDEST_INT
mmix_intval (rtx
);
124 static void mmix_output_octa (FILE *, HOST_WIDEST_INT
, int);
125 static bool mmix_assemble_integer (rtx
, unsigned int, int);
126 static struct machine_function
*mmix_init_machine_status (void);
127 static void mmix_encode_section_info (tree
, rtx
, int);
128 static const char *mmix_strip_name_encoding (const char *);
129 static void mmix_emit_sp_add (HOST_WIDE_INT offset
);
130 static void mmix_target_asm_function_prologue (FILE *, HOST_WIDE_INT
);
131 static void mmix_target_asm_function_end_prologue (FILE *);
132 static void mmix_target_asm_function_epilogue (FILE *, HOST_WIDE_INT
);
133 static bool mmix_legitimate_address_p (enum machine_mode
, rtx
, bool);
134 static void mmix_reorg (void);
135 static void mmix_asm_output_mi_thunk
136 (FILE *, tree
, HOST_WIDE_INT
, HOST_WIDE_INT
, tree
);
137 static void mmix_setup_incoming_varargs
138 (CUMULATIVE_ARGS
*, enum machine_mode
, tree
, int *, int);
139 static void mmix_file_start (void);
140 static void mmix_file_end (void);
141 static bool mmix_rtx_costs (rtx
, int, int, int *, bool);
142 static rtx
mmix_struct_value_rtx (tree
, int);
143 static enum machine_mode
mmix_promote_function_mode (const_tree
,
145 int *, const_tree
, int);
146 static void mmix_function_arg_advance (CUMULATIVE_ARGS
*, enum machine_mode
,
148 static rtx
mmix_function_arg_1 (const CUMULATIVE_ARGS
*, enum machine_mode
,
149 const_tree
, bool, bool);
150 static rtx
mmix_function_incoming_arg (CUMULATIVE_ARGS
*, enum machine_mode
,
152 static rtx
mmix_function_arg (CUMULATIVE_ARGS
*, enum machine_mode
,
154 static rtx
mmix_function_value (const_tree
, const_tree
, bool);
155 static rtx
mmix_libcall_value (enum machine_mode
, const_rtx
);
156 static bool mmix_function_value_regno_p (const unsigned int);
157 static bool mmix_pass_by_reference (CUMULATIVE_ARGS
*,
158 enum machine_mode
, const_tree
, bool);
159 static bool mmix_frame_pointer_required (void);
160 static void mmix_asm_trampoline_template (FILE *);
161 static void mmix_trampoline_init (rtx
, tree
, rtx
);
162 static void mmix_conditional_register_usage (void);
164 /* TARGET_OPTION_OPTIMIZATION_TABLE. */
166 static const struct default_options mmix_option_optimization_table
[] =
168 { OPT_LEVELS_1_PLUS
, OPT_fregmove
, NULL
, 1 },
169 { OPT_LEVELS_2_PLUS
, OPT_fomit_frame_pointer
, NULL
, 1 },
170 { OPT_LEVELS_NONE
, 0, NULL
, 0 }
173 /* Target structure macros. Listed by node. See `Using and Porting GCC'
174 for a general description. */
176 /* Node: Function Entry */
178 #undef TARGET_ASM_BYTE_OP
179 #define TARGET_ASM_BYTE_OP NULL
180 #undef TARGET_ASM_ALIGNED_HI_OP
181 #define TARGET_ASM_ALIGNED_HI_OP NULL
182 #undef TARGET_ASM_ALIGNED_SI_OP
183 #define TARGET_ASM_ALIGNED_SI_OP NULL
184 #undef TARGET_ASM_ALIGNED_DI_OP
185 #define TARGET_ASM_ALIGNED_DI_OP NULL
186 #undef TARGET_ASM_INTEGER
187 #define TARGET_ASM_INTEGER mmix_assemble_integer
189 #undef TARGET_ASM_FUNCTION_PROLOGUE
190 #define TARGET_ASM_FUNCTION_PROLOGUE mmix_target_asm_function_prologue
192 #undef TARGET_ASM_FUNCTION_END_PROLOGUE
193 #define TARGET_ASM_FUNCTION_END_PROLOGUE mmix_target_asm_function_end_prologue
195 #undef TARGET_ASM_FUNCTION_EPILOGUE
196 #define TARGET_ASM_FUNCTION_EPILOGUE mmix_target_asm_function_epilogue
198 #undef TARGET_ENCODE_SECTION_INFO
199 #define TARGET_ENCODE_SECTION_INFO mmix_encode_section_info
200 #undef TARGET_STRIP_NAME_ENCODING
201 #define TARGET_STRIP_NAME_ENCODING mmix_strip_name_encoding
203 #undef TARGET_ASM_OUTPUT_MI_THUNK
204 #define TARGET_ASM_OUTPUT_MI_THUNK mmix_asm_output_mi_thunk
205 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
206 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall
207 #undef TARGET_ASM_FILE_START
208 #define TARGET_ASM_FILE_START mmix_file_start
209 #undef TARGET_ASM_FILE_START_FILE_DIRECTIVE
210 #define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
211 #undef TARGET_ASM_FILE_END
212 #define TARGET_ASM_FILE_END mmix_file_end
213 #undef TARGET_ASM_OUTPUT_SOURCE_FILENAME
214 #define TARGET_ASM_OUTPUT_SOURCE_FILENAME mmix_asm_output_source_filename
216 #undef TARGET_CONDITIONAL_REGISTER_USAGE
217 #define TARGET_CONDITIONAL_REGISTER_USAGE mmix_conditional_register_usage
219 #undef TARGET_RTX_COSTS
220 #define TARGET_RTX_COSTS mmix_rtx_costs
221 #undef TARGET_ADDRESS_COST
222 #define TARGET_ADDRESS_COST hook_int_rtx_bool_0
224 #undef TARGET_MACHINE_DEPENDENT_REORG
225 #define TARGET_MACHINE_DEPENDENT_REORG mmix_reorg
227 #undef TARGET_PROMOTE_FUNCTION_MODE
228 #define TARGET_PROMOTE_FUNCTION_MODE mmix_promote_function_mode
230 #undef TARGET_FUNCTION_VALUE
231 #define TARGET_FUNCTION_VALUE mmix_function_value
232 #undef TARGET_LIBCALL_VALUE
233 #define TARGET_LIBCALL_VALUE mmix_libcall_value
234 #undef TARGET_FUNCTION_VALUE_REGNO_P
235 #define TARGET_FUNCTION_VALUE_REGNO_P mmix_function_value_regno_p
237 #undef TARGET_FUNCTION_ARG
238 #define TARGET_FUNCTION_ARG mmix_function_arg
239 #undef TARGET_FUNCTION_INCOMING_ARG
240 #define TARGET_FUNCTION_INCOMING_ARG mmix_function_incoming_arg
241 #undef TARGET_FUNCTION_ARG_ADVANCE
242 #define TARGET_FUNCTION_ARG_ADVANCE mmix_function_arg_advance
243 #undef TARGET_STRUCT_VALUE_RTX
244 #define TARGET_STRUCT_VALUE_RTX mmix_struct_value_rtx
245 #undef TARGET_SETUP_INCOMING_VARARGS
246 #define TARGET_SETUP_INCOMING_VARARGS mmix_setup_incoming_varargs
247 #undef TARGET_PASS_BY_REFERENCE
248 #define TARGET_PASS_BY_REFERENCE mmix_pass_by_reference
249 #undef TARGET_CALLEE_COPIES
250 #define TARGET_CALLEE_COPIES hook_bool_CUMULATIVE_ARGS_mode_tree_bool_true
251 #undef TARGET_DEFAULT_TARGET_FLAGS
252 #define TARGET_DEFAULT_TARGET_FLAGS TARGET_DEFAULT
254 #undef TARGET_LEGITIMATE_ADDRESS_P
255 #define TARGET_LEGITIMATE_ADDRESS_P mmix_legitimate_address_p
257 #undef TARGET_FRAME_POINTER_REQUIRED
258 #define TARGET_FRAME_POINTER_REQUIRED mmix_frame_pointer_required
260 #undef TARGET_ASM_TRAMPOLINE_TEMPLATE
261 #define TARGET_ASM_TRAMPOLINE_TEMPLATE mmix_asm_trampoline_template
262 #undef TARGET_TRAMPOLINE_INIT
263 #define TARGET_TRAMPOLINE_INIT mmix_trampoline_init
265 #undef TARGET_OPTION_OVERRIDE
266 #define TARGET_OPTION_OVERRIDE mmix_option_override
267 #undef TARGET_OPTION_OPTIMIZATION_TABLE
268 #define TARGET_OPTION_OPTIMIZATION_TABLE mmix_option_optimization_table
270 struct gcc_target targetm
= TARGET_INITIALIZER
;
272 /* Functions that are expansions for target macros.
273 See Target Macros in `Using and Porting GCC'. */
275 /* TARGET_OPTION_OVERRIDE. */
278 mmix_option_override (void)
280 /* Should we err or should we warn? Hmm. At least we must neutralize
281 it. For example the wrong kind of case-tables will be generated with
282 PIC; we use absolute address items for mmixal compatibility. FIXME:
283 They could be relative if we just elide them to after all pertinent
287 warning (0, "-f%s not supported: ignored", (flag_pic
> 1) ? "PIC" : "pic");
292 /* INIT_EXPANDERS. */
295 mmix_init_expanders (void)
297 init_machine_status
= mmix_init_machine_status
;
300 /* Set the per-function data. */
302 static struct machine_function
*
303 mmix_init_machine_status (void)
305 return ggc_alloc_cleared_machine_function ();
309 We have trouble getting the address of stuff that is located at other
310 than 32-bit alignments (GETA requirements), so try to give everything
311 at least 32-bit alignment. */
314 mmix_data_alignment (tree type ATTRIBUTE_UNUSED
, int basic_align
)
316 if (basic_align
< 32)
322 /* CONSTANT_ALIGNMENT. */
325 mmix_constant_alignment (tree constant ATTRIBUTE_UNUSED
, int basic_align
)
327 if (basic_align
< 32)
333 /* LOCAL_ALIGNMENT. */
336 mmix_local_alignment (tree type ATTRIBUTE_UNUSED
, unsigned basic_align
)
338 if (basic_align
< 32)
344 /* TARGET_CONDITIONAL_REGISTER_USAGE. */
347 mmix_conditional_register_usage (void)
353 static const int gnu_abi_reg_alloc_order
[]
354 = MMIX_GNU_ABI_REG_ALLOC_ORDER
;
356 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
357 reg_alloc_order
[i
] = gnu_abi_reg_alloc_order
[i
];
359 /* Change the default from the mmixware ABI. For the GNU ABI,
360 $15..$30 are call-saved just as $0..$14. There must be one
361 call-clobbered local register for the "hole" that holds the
362 number of saved local registers saved by PUSHJ/PUSHGO during the
363 function call, receiving the return value at return. So best is
364 to use the highest, $31. It's already marked call-clobbered for
366 for (i
= 15; i
<= 30; i
++)
367 call_used_regs
[i
] = 0;
369 /* "Unfix" the parameter registers. */
370 for (i
= MMIX_RESERVED_GNU_ARG_0_REGNUM
;
371 i
< MMIX_RESERVED_GNU_ARG_0_REGNUM
+ MMIX_MAX_ARGS_IN_REGS
;
376 /* Step over the ":" in special register names. */
377 if (! TARGET_TOPLEVEL_SYMBOLS
)
378 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
379 if (reg_names
[i
][0] == ':')
383 /* INCOMING_REGNO and OUTGOING_REGNO worker function.
384 Those two macros must only be applied to function argument
385 registers. FIXME: for their current use in gcc, it'd be better
386 with an explicit specific additional FUNCTION_INCOMING_ARG_REGNO_P
387 a'la TARGET_FUNCTION_ARG / TARGET_FUNCTION_INCOMING_ARG instead of
388 forcing the target to commit to a fixed mapping and for any
389 unspecified register use. */
392 mmix_opposite_regno (int regno
, int incoming
)
394 if (!mmix_function_arg_regno_p (regno
, incoming
))
399 ? MMIX_FIRST_INCOMING_ARG_REGNUM
- MMIX_FIRST_ARG_REGNUM
400 : MMIX_FIRST_ARG_REGNUM
- MMIX_FIRST_INCOMING_ARG_REGNUM
);
404 All registers that are part of the register stack and that will be
408 mmix_local_regno (int regno
)
410 return regno
<= MMIX_LAST_STACK_REGISTER_REGNUM
&& !call_used_regs
[regno
];
413 /* PREFERRED_RELOAD_CLASS.
414 We need to extend the reload class of REMAINDER_REG and HIMULT_REG. */
417 mmix_preferred_reload_class (rtx x ATTRIBUTE_UNUSED
, enum reg_class rclass
)
419 /* FIXME: Revisit. */
420 return GET_CODE (x
) == MOD
&& GET_MODE (x
) == DImode
421 ? REMAINDER_REG
: rclass
;
424 /* PREFERRED_OUTPUT_RELOAD_CLASS.
425 We need to extend the reload class of REMAINDER_REG and HIMULT_REG. */
428 mmix_preferred_output_reload_class (rtx x ATTRIBUTE_UNUSED
,
429 enum reg_class rclass
)
431 /* FIXME: Revisit. */
432 return GET_CODE (x
) == MOD
&& GET_MODE (x
) == DImode
433 ? REMAINDER_REG
: rclass
;
436 /* SECONDARY_RELOAD_CLASS.
437 We need to reload regs of REMAINDER_REG and HIMULT_REG elsewhere. */
440 mmix_secondary_reload_class (enum reg_class rclass
,
441 enum machine_mode mode ATTRIBUTE_UNUSED
,
442 rtx x ATTRIBUTE_UNUSED
,
443 int in_p ATTRIBUTE_UNUSED
)
445 if (rclass
== REMAINDER_REG
446 || rclass
== HIMULT_REG
447 || rclass
== SYSTEM_REGS
)
453 /* CONST_OK_FOR_LETTER_P. */
456 mmix_const_ok_for_letter_p (HOST_WIDE_INT value
, int c
)
459 (c
== 'I' ? value
>= 0 && value
<= 255
460 : c
== 'J' ? value
>= 0 && value
<= 65535
461 : c
== 'K' ? value
<= 0 && value
>= -255
462 : c
== 'L' ? mmix_shiftable_wyde_value (value
)
463 : c
== 'M' ? value
== 0
464 : c
== 'N' ? mmix_shiftable_wyde_value (~value
)
465 : c
== 'O' ? (value
== 3 || value
== 5 || value
== 9
470 /* CONST_DOUBLE_OK_FOR_LETTER_P. */
473 mmix_const_double_ok_for_letter_p (rtx value
, int c
)
476 (c
== 'G' ? value
== CONST0_RTX (GET_MODE (value
))
481 We need this since our constants are not always expressible as
482 CONST_INT:s, but rather often as CONST_DOUBLE:s. */
485 mmix_extra_constraint (rtx x
, int c
, int strict
)
487 HOST_WIDEST_INT value
;
489 /* When checking for an address, we need to handle strict vs. non-strict
490 register checks. Don't use address_operand, but instead its
491 equivalent (its callee, which it is just a wrapper for),
492 memory_operand_p and the strict-equivalent strict_memory_address_p. */
496 ? strict_memory_address_p (Pmode
, x
)
497 : memory_address_p (Pmode
, x
);
499 /* R asks whether x is to be loaded with GETA or something else. Right
500 now, only a SYMBOL_REF and LABEL_REF can fit for
501 TARGET_BASE_ADDRESSES.
503 Only constant symbolic addresses apply. With TARGET_BASE_ADDRESSES,
504 we just allow straight LABEL_REF or SYMBOL_REFs with SYMBOL_REF_FLAG
505 set right now; only function addresses and code labels. If we change
506 to let SYMBOL_REF_FLAG be set on other symbols, we have to check
507 inside CONST expressions. When TARGET_BASE_ADDRESSES is not in
508 effect, a "raw" constant check together with mmix_constant_address_p
509 is all that's needed; we want all constant addresses to be loaded
513 GET_CODE (x
) != CONST_INT
&& GET_CODE (x
) != CONST_DOUBLE
514 && mmix_constant_address_p (x
)
515 && (! TARGET_BASE_ADDRESSES
516 || (GET_CODE (x
) == LABEL_REF
517 || (GET_CODE (x
) == SYMBOL_REF
&& SYMBOL_REF_FLAG (x
))));
519 if (GET_CODE (x
) != CONST_DOUBLE
|| GET_MODE (x
) != VOIDmode
)
522 value
= mmix_intval (x
);
524 /* We used to map Q->J, R->K, S->L, T->N, U->O, but we don't have to any
525 more ('U' taken for address_operand, 'R' similarly). Some letters map
526 outside of CONST_INT, though; we still use 'S' and 'T'. */
528 return mmix_shiftable_wyde_value (value
);
530 return mmix_shiftable_wyde_value (~value
);
534 /* DYNAMIC_CHAIN_ADDRESS. */
537 mmix_dynamic_chain_address (rtx frame
)
539 /* FIXME: the frame-pointer is stored at offset -8 from the current
540 frame-pointer. Unfortunately, the caller assumes that a
541 frame-pointer is present for *all* previous frames. There should be
542 a way to say that that cannot be done, like for RETURN_ADDR_RTX. */
543 return plus_constant (frame
, -8);
546 /* STARTING_FRAME_OFFSET. */
549 mmix_starting_frame_offset (void)
551 /* The old frame pointer is in the slot below the new one, so
552 FIRST_PARM_OFFSET does not need to depend on whether the
553 frame-pointer is needed or not. We have to adjust for the register
554 stack pointer being located below the saved frame pointer.
555 Similarly, we store the return address on the stack too, for
556 exception handling, and always if we save the register stack pointer. */
559 + (MMIX_CFUN_HAS_LANDING_PAD
560 ? -16 : (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
? -8 : 0)));
563 /* RETURN_ADDR_RTX. */
566 mmix_return_addr_rtx (int count
, rtx frame ATTRIBUTE_UNUSED
)
569 ? (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
570 /* FIXME: Set frame_alias_set on the following. (Why?)
571 See mmix_initial_elimination_offset for the reason we can't use
572 get_hard_reg_initial_val for both. Always using a stack slot
573 and not a register would be suboptimal. */
574 ? validize_mem (gen_rtx_MEM (Pmode
, plus_constant (frame_pointer_rtx
, -16)))
575 : get_hard_reg_initial_val (Pmode
, MMIX_INCOMING_RETURN_ADDRESS_REGNUM
))
579 /* SETUP_FRAME_ADDRESSES. */
582 mmix_setup_frame_addresses (void)
584 /* Nothing needed at the moment. */
587 /* The difference between the (imaginary) frame pointer and the stack
588 pointer. Used to eliminate the frame pointer. */
591 mmix_initial_elimination_offset (int fromreg
, int toreg
)
595 = (get_frame_size () + crtl
->outgoing_args_size
+ 7) & ~7;
597 /* There is no actual offset between these two virtual values, but for
598 the frame-pointer, we have the old one in the stack position below
599 it, so the offset for the frame-pointer to the stack-pointer is one
601 if (fromreg
== MMIX_ARG_POINTER_REGNUM
602 && toreg
== MMIX_FRAME_POINTER_REGNUM
)
605 /* The difference is the size of local variables plus the size of
606 outgoing function arguments that would normally be passed as
607 registers but must be passed on stack because we're out of
608 function-argument registers. Only global saved registers are
609 counted; the others go on the register stack.
611 The frame-pointer is counted too if it is what is eliminated, as we
612 need to balance the offset for it from STARTING_FRAME_OFFSET.
614 Also add in the slot for the register stack pointer we save if we
617 Unfortunately, we can't access $0..$14, from unwinder code easily, so
618 store the return address in a frame slot too. FIXME: Only for
619 non-leaf functions. FIXME: Always with a landing pad, because it's
620 hard to know whether we need the other at the time we know we need
621 the offset for one (and have to state it). It's a kludge until we
622 can express the register stack in the EH frame info.
624 We have to do alignment here; get_frame_size will not return a
625 multiple of STACK_BOUNDARY. FIXME: Add note in manual. */
627 for (regno
= MMIX_FIRST_GLOBAL_REGNUM
;
630 if ((df_regs_ever_live_p (regno
) && ! call_used_regs
[regno
])
631 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
635 + (MMIX_CFUN_HAS_LANDING_PAD
636 ? 16 : (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
? 8 : 0))
637 + (fromreg
== MMIX_ARG_POINTER_REGNUM
? 0 : 8);
641 mmix_function_arg_advance (CUMULATIVE_ARGS
*argsp
, enum machine_mode mode
,
642 const_tree type
, bool named ATTRIBUTE_UNUSED
)
644 int arg_size
= MMIX_FUNCTION_ARG_SIZE (mode
, type
);
646 argsp
->regs
= ((targetm
.calls
.must_pass_in_stack (mode
, type
)
650 ? (MMIX_MAX_ARGS_IN_REGS
) + 1
651 : argsp
->regs
+ (7 + arg_size
) / 8);
654 /* Helper function for mmix_function_arg and mmix_function_incoming_arg. */
657 mmix_function_arg_1 (const CUMULATIVE_ARGS
*argsp
,
658 enum machine_mode mode
,
660 bool named ATTRIBUTE_UNUSED
,
663 /* Last-argument marker. */
664 if (type
== void_type_node
)
665 return (argsp
->regs
< MMIX_MAX_ARGS_IN_REGS
)
668 ? MMIX_FIRST_INCOMING_ARG_REGNUM
669 : MMIX_FIRST_ARG_REGNUM
) + argsp
->regs
)
672 return (argsp
->regs
< MMIX_MAX_ARGS_IN_REGS
673 && !targetm
.calls
.must_pass_in_stack (mode
, type
)
674 && (GET_MODE_BITSIZE (mode
) <= 64
679 ? MMIX_FIRST_INCOMING_ARG_REGNUM
680 : MMIX_FIRST_ARG_REGNUM
)
685 /* Return an rtx for a function argument to go in a register, and 0 for
686 one that must go on stack. */
689 mmix_function_arg (CUMULATIVE_ARGS
*argsp
,
690 enum machine_mode mode
,
694 return mmix_function_arg_1 (argsp
, mode
, type
, named
, false);
698 mmix_function_incoming_arg (CUMULATIVE_ARGS
*argsp
,
699 enum machine_mode mode
,
703 return mmix_function_arg_1 (argsp
, mode
, type
, named
, true);
706 /* Returns nonzero for everything that goes by reference, 0 for
707 everything that goes by value. */
710 mmix_pass_by_reference (CUMULATIVE_ARGS
*argsp
, enum machine_mode mode
,
711 const_tree type
, bool named ATTRIBUTE_UNUSED
)
713 /* FIXME: Check: I'm not sure the must_pass_in_stack check is
715 if (targetm
.calls
.must_pass_in_stack (mode
, type
))
718 if (MMIX_FUNCTION_ARG_SIZE (mode
, type
) > 8
720 && (!argsp
|| !argsp
->lib
))
726 /* Return nonzero if regno is a register number where a parameter is
727 passed, and 0 otherwise. */
730 mmix_function_arg_regno_p (int regno
, int incoming
)
733 = incoming
? MMIX_FIRST_INCOMING_ARG_REGNUM
: MMIX_FIRST_ARG_REGNUM
;
735 return regno
>= first_arg_regnum
736 && regno
< first_arg_regnum
+ MMIX_MAX_ARGS_IN_REGS
;
739 /* Implements TARGET_FUNCTION_VALUE. */
742 mmix_function_value (const_tree valtype
,
743 const_tree func ATTRIBUTE_UNUSED
,
746 enum machine_mode mode
= TYPE_MODE (valtype
);
747 enum machine_mode cmode
;
748 int first_val_regnum
= MMIX_OUTGOING_RETURN_VALUE_REGNUM
;
749 rtx vec
[MMIX_MAX_REGS_FOR_VALUE
];
754 return gen_rtx_REG (mode
, MMIX_RETURN_VALUE_REGNUM
);
756 /* Return values that fit in a register need no special handling.
757 There's no register hole when parameters are passed in global
760 || GET_MODE_BITSIZE (mode
) <= BITS_PER_WORD
)
762 gen_rtx_REG (mode
, MMIX_OUTGOING_RETURN_VALUE_REGNUM
);
764 if (COMPLEX_MODE_P (mode
))
765 /* A complex type, made up of components. */
766 cmode
= TYPE_MODE (TREE_TYPE (valtype
));
769 /* Of the other larger-than-register modes, we only support
770 scalar mode TImode. (At least, that's the only one that's
771 been rudimentally tested.) Make sure we're alerted for
774 sorry ("support for mode %qs", GET_MODE_NAME (mode
));
776 /* In any case, we will fill registers to the natural size. */
780 nregs
= ((GET_MODE_BITSIZE (mode
) + BITS_PER_WORD
- 1) / BITS_PER_WORD
);
782 /* We need to take care of the effect of the register hole on return
783 values of large sizes; the last register will appear as the first
784 register, with the rest shifted. (For complex modes, this is just
785 swapped registers.) */
787 if (nregs
> MMIX_MAX_REGS_FOR_VALUE
)
788 internal_error ("too large function value type, needs %d registers,\
789 have only %d registers for this", nregs
, MMIX_MAX_REGS_FOR_VALUE
);
791 /* FIXME: Maybe we should handle structure values like this too
792 (adjusted for BLKmode), perhaps for both ABI:s. */
793 for (i
= 0; i
< nregs
- 1; i
++)
795 = gen_rtx_EXPR_LIST (VOIDmode
,
796 gen_rtx_REG (cmode
, first_val_regnum
+ i
),
797 GEN_INT ((i
+ 1) * BITS_PER_UNIT
));
800 = gen_rtx_EXPR_LIST (VOIDmode
,
801 gen_rtx_REG (cmode
, first_val_regnum
+ nregs
- 1),
804 return gen_rtx_PARALLEL (VOIDmode
, gen_rtvec_v (nregs
, vec
));
807 /* Implements TARGET_LIBCALL_VALUE. */
810 mmix_libcall_value (enum machine_mode mode
,
811 const_rtx fun ATTRIBUTE_UNUSED
)
813 return gen_rtx_REG (mode
, MMIX_RETURN_VALUE_REGNUM
);
816 /* Implements TARGET_FUNCTION_VALUE_REGNO_P. */
819 mmix_function_value_regno_p (const unsigned int regno
)
821 return regno
== MMIX_RETURN_VALUE_REGNUM
;
824 /* EH_RETURN_DATA_REGNO. */
827 mmix_eh_return_data_regno (int n
)
830 return MMIX_EH_RETURN_DATA_REGNO_START
+ n
;
832 return INVALID_REGNUM
;
835 /* EH_RETURN_STACKADJ_RTX. */
838 mmix_eh_return_stackadj_rtx (void)
840 return gen_rtx_REG (Pmode
, MMIX_EH_RETURN_STACKADJ_REGNUM
);
843 /* EH_RETURN_HANDLER_RTX. */
846 mmix_eh_return_handler_rtx (void)
848 return gen_rtx_REG (Pmode
, MMIX_INCOMING_RETURN_ADDRESS_REGNUM
);
851 /* ASM_PREFERRED_EH_DATA_FORMAT. */
854 mmix_asm_preferred_eh_data_format (int code ATTRIBUTE_UNUSED
,
855 int global ATTRIBUTE_UNUSED
)
857 /* This is the default (was at 2001-07-20). Revisit when needed. */
858 return DW_EH_PE_absptr
;
861 /* Make a note that we've seen the beginning of the prologue. This
862 matters to whether we'll translate register numbers as calculated by
866 mmix_target_asm_function_prologue (FILE *stream ATTRIBUTE_UNUSED
,
867 HOST_WIDE_INT framesize ATTRIBUTE_UNUSED
)
869 cfun
->machine
->in_prologue
= 1;
872 /* Make a note that we've seen the end of the prologue. */
875 mmix_target_asm_function_end_prologue (FILE *stream ATTRIBUTE_UNUSED
)
877 cfun
->machine
->in_prologue
= 0;
880 /* Implement TARGET_MACHINE_DEPENDENT_REORG. No actual rearrangements
881 done here; just virtually by calculating the highest saved stack
882 register number used to modify the register numbers at output time. */
889 /* We put the number of the highest saved register-file register in a
890 location convenient for the call-patterns to output. Note that we
891 don't tell dwarf2 about these registers, since it can't restore them
893 for (regno
= MMIX_LAST_STACK_REGISTER_REGNUM
;
896 if ((df_regs_ever_live_p (regno
) && !call_used_regs
[regno
])
897 || (regno
== MMIX_FRAME_POINTER_REGNUM
&& frame_pointer_needed
))
900 /* Regardless of whether they're saved (they might be just read), we
901 mustn't include registers that carry parameters. We could scan the
902 insns to see whether they're actually used (and indeed do other less
903 trivial register usage analysis and transformations), but it seems
904 wasteful to optimize for unused parameter registers. As of
905 2002-04-30, df_regs_ever_live_p (n) seems to be set for only-reads too, but
906 that might change. */
907 if (!TARGET_ABI_GNU
&& regno
< crtl
->args
.info
.regs
- 1)
909 regno
= crtl
->args
.info
.regs
- 1;
911 /* We don't want to let this cause us to go over the limit and make
912 incoming parameter registers be misnumbered and treating the last
913 parameter register and incoming return value register call-saved.
914 Stop things at the unmodified scheme. */
915 if (regno
> MMIX_RETURN_VALUE_REGNUM
- 1)
916 regno
= MMIX_RETURN_VALUE_REGNUM
- 1;
919 cfun
->machine
->highest_saved_stack_register
= regno
;
922 /* TARGET_ASM_FUNCTION_EPILOGUE. */
925 mmix_target_asm_function_epilogue (FILE *stream
,
926 HOST_WIDE_INT locals_size ATTRIBUTE_UNUSED
)
928 /* Emit an \n for readability of the generated assembly. */
929 fputc ('\n', stream
);
932 /* TARGET_ASM_OUTPUT_MI_THUNK. */
935 mmix_asm_output_mi_thunk (FILE *stream
,
936 tree fndecl ATTRIBUTE_UNUSED
,
938 HOST_WIDE_INT vcall_offset ATTRIBUTE_UNUSED
,
941 /* If you define TARGET_STRUCT_VALUE_RTX that returns 0 (i.e. pass
942 location of structure to return as invisible first argument), you
943 need to tweak this code too. */
944 const char *regname
= reg_names
[MMIX_FIRST_INCOMING_ARG_REGNUM
];
946 if (delta
>= 0 && delta
< 65536)
947 fprintf (stream
, "\tINCL %s,%d\n", regname
, (int)delta
);
948 else if (delta
< 0 && delta
>= -255)
949 fprintf (stream
, "\tSUBU %s,%s,%d\n", regname
, regname
, (int)-delta
);
952 mmix_output_register_setting (stream
, 255, delta
, 1);
953 fprintf (stream
, "\tADDU %s,%s,$255\n", regname
, regname
);
956 fprintf (stream
, "\tJMP ");
957 assemble_name (stream
, XSTR (XEXP (DECL_RTL (func
), 0), 0));
958 fprintf (stream
, "\n");
961 /* FUNCTION_PROFILER. */
964 mmix_function_profiler (FILE *stream ATTRIBUTE_UNUSED
,
965 int labelno ATTRIBUTE_UNUSED
)
967 sorry ("function_profiler support for MMIX");
970 /* Worker function for TARGET_SETUP_INCOMING_VARARGS. For the moment,
971 let's stick to pushing argument registers on the stack. Later, we
972 can parse all arguments in registers, to improve performance. */
975 mmix_setup_incoming_varargs (CUMULATIVE_ARGS
*args_so_farp
,
976 enum machine_mode mode
,
979 int second_time ATTRIBUTE_UNUSED
)
981 /* The last named variable has been handled, but
982 args_so_farp has not been advanced for it. */
983 if (args_so_farp
->regs
+ 1 < MMIX_MAX_ARGS_IN_REGS
)
984 *pretend_sizep
= (MMIX_MAX_ARGS_IN_REGS
- (args_so_farp
->regs
+ 1)) * 8;
986 /* We assume that one argument takes up one register here. That should
987 be true until we start messing with multi-reg parameters. */
988 if ((7 + (MMIX_FUNCTION_ARG_SIZE (mode
, vartype
))) / 8 != 1)
989 internal_error ("MMIX Internal: Last named vararg would not fit in a register");
992 /* TARGET_ASM_TRAMPOLINE_TEMPLATE. */
995 mmix_asm_trampoline_template (FILE *stream
)
997 /* Read a value into the static-chain register and jump somewhere. The
998 static chain is stored at offset 16, and the function address is
999 stored at offset 24. */
1001 fprintf (stream
, "\tGETA $255,1F\n\t");
1002 fprintf (stream
, "LDOU %s,$255,0\n\t", reg_names
[MMIX_STATIC_CHAIN_REGNUM
]);
1003 fprintf (stream
, "LDOU $255,$255,8\n\t");
1004 fprintf (stream
, "GO $255,$255,0\n");
1005 fprintf (stream
, "1H\tOCTA 0\n\t");
1006 fprintf (stream
, "OCTA 0\n");
1009 /* TARGET_TRAMPOLINE_INIT. */
1010 /* Set the static chain and function pointer field in the trampoline.
1011 We also SYNCID here to be sure (doesn't matter in the simulator, but
1012 some day it will). */
1015 mmix_trampoline_init (rtx m_tramp
, tree fndecl
, rtx static_chain
)
1017 rtx fnaddr
= XEXP (DECL_RTL (fndecl
), 0);
1020 emit_block_move (m_tramp
, assemble_trampoline_template (),
1021 GEN_INT (2*UNITS_PER_WORD
), BLOCK_OP_NORMAL
);
1023 mem
= adjust_address (m_tramp
, DImode
, 2*UNITS_PER_WORD
);
1024 emit_move_insn (mem
, static_chain
);
1025 mem
= adjust_address (m_tramp
, DImode
, 3*UNITS_PER_WORD
);
1026 emit_move_insn (mem
, fnaddr
);
1028 mem
= adjust_address (m_tramp
, DImode
, 0);
1029 emit_insn (gen_sync_icache (mem
, GEN_INT (TRAMPOLINE_SIZE
- 1)));
1032 /* We must exclude constant addresses that have an increment that is not a
1033 multiple of four bytes because of restrictions of the GETA
1034 instruction, unless TARGET_BASE_ADDRESSES. */
1037 mmix_constant_address_p (rtx x
)
1039 RTX_CODE code
= GET_CODE (x
);
1041 /* When using "base addresses", anything constant goes. */
1042 int constant_ok
= TARGET_BASE_ADDRESSES
!= 0;
1051 /* FIXME: Don't know how to dissect these. Avoid them for now,
1052 except we know they're constants. */
1056 addend
= INTVAL (x
);
1060 if (GET_MODE (x
) != VOIDmode
)
1061 /* Strange that we got here. FIXME: Check if we do. */
1063 addend
= CONST_DOUBLE_LOW (x
);
1067 /* Note that expressions with arithmetic on forward references don't
1068 work in mmixal. People using gcc assembly code with mmixal might
1069 need to move arrays and such to before the point of use. */
1070 if (GET_CODE (XEXP (x
, 0)) == PLUS
)
1072 rtx x0
= XEXP (XEXP (x
, 0), 0);
1073 rtx x1
= XEXP (XEXP (x
, 0), 1);
1075 if ((GET_CODE (x0
) == SYMBOL_REF
1076 || GET_CODE (x0
) == LABEL_REF
)
1077 && (GET_CODE (x1
) == CONST_INT
1078 || (GET_CODE (x1
) == CONST_DOUBLE
1079 && GET_MODE (x1
) == VOIDmode
)))
1080 addend
= mmix_intval (x1
);
1092 return constant_ok
|| (addend
& 3) == 0;
1095 /* Return 1 if the address is OK, otherwise 0. */
1098 mmix_legitimate_address_p (enum machine_mode mode ATTRIBUTE_UNUSED
,
1100 bool strict_checking
)
1102 #define MMIX_REG_OK(X) \
1104 && (REGNO (X) <= MMIX_LAST_GENERAL_REGISTER \
1105 || (reg_renumber[REGNO (X)] > 0 \
1106 && reg_renumber[REGNO (X)] <= MMIX_LAST_GENERAL_REGISTER))) \
1107 || (!strict_checking \
1108 && (REGNO (X) <= MMIX_LAST_GENERAL_REGISTER \
1109 || REGNO (X) >= FIRST_PSEUDO_REGISTER \
1110 || REGNO (X) == ARG_POINTER_REGNUM)))
1114 (mem (plus reg reg))
1115 (mem (plus reg 0..255)).
1116 unless TARGET_BASE_ADDRESSES, in which case we accept all
1117 (mem constant_address) too. */
1121 if (REG_P (x
) && MMIX_REG_OK (x
))
1124 if (GET_CODE(x
) == PLUS
)
1126 rtx x1
= XEXP (x
, 0);
1127 rtx x2
= XEXP (x
, 1);
1129 /* Try swapping the order. FIXME: Do we need this? */
1137 /* (mem (plus (reg?) (?))) */
1138 if (!REG_P (x1
) || !MMIX_REG_OK (x1
))
1139 return TARGET_BASE_ADDRESSES
&& mmix_constant_address_p (x
);
1141 /* (mem (plus (reg) (reg?))) */
1142 if (REG_P (x2
) && MMIX_REG_OK (x2
))
1145 /* (mem (plus (reg) (0..255?))) */
1146 if (GET_CODE (x2
) == CONST_INT
1147 && CONST_OK_FOR_LETTER_P (INTVAL (x2
), 'I'))
1153 return TARGET_BASE_ADDRESSES
&& mmix_constant_address_p (x
);
1156 /* LEGITIMATE_CONSTANT_P. */
1159 mmix_legitimate_constant_p (rtx x
)
1161 RTX_CODE code
= GET_CODE (x
);
1163 /* We must allow any number due to the way the cse passes works; if we
1164 do not allow any number here, general_operand will fail, and insns
1165 will fatally fail recognition instead of "softly". */
1166 if (code
== CONST_INT
|| code
== CONST_DOUBLE
)
1169 return CONSTANT_ADDRESS_P (x
);
1172 /* SELECT_CC_MODE. */
1175 mmix_select_cc_mode (RTX_CODE op
, rtx x
, rtx y ATTRIBUTE_UNUSED
)
1177 /* We use CCmode, CC_UNSmode, CC_FPmode, CC_FPEQmode and CC_FUNmode to
1178 output different compare insns. Note that we do not check the
1179 validity of the comparison here. */
1181 if (GET_MODE_CLASS (GET_MODE (x
)) == MODE_FLOAT
)
1183 if (op
== ORDERED
|| op
== UNORDERED
|| op
== UNGE
1184 || op
== UNGT
|| op
== UNLE
|| op
== UNLT
)
1187 if (op
== EQ
|| op
== NE
)
1193 if (op
== GTU
|| op
== LTU
|| op
== GEU
|| op
== LEU
)
1199 /* REVERSIBLE_CC_MODE. */
1202 mmix_reversible_cc_mode (enum machine_mode mode
)
1204 /* That is, all integer and the EQ, NE, ORDERED and UNORDERED float
1206 return mode
!= CC_FPmode
;
1209 /* TARGET_RTX_COSTS. */
1212 mmix_rtx_costs (rtx x ATTRIBUTE_UNUSED
,
1213 int code ATTRIBUTE_UNUSED
,
1214 int outer_code ATTRIBUTE_UNUSED
,
1215 int *total ATTRIBUTE_UNUSED
,
1216 bool speed ATTRIBUTE_UNUSED
)
1218 /* For the time being, this is just a stub and we'll accept the
1219 generic calculations, until we can do measurements, at least.
1220 Say we did not modify any calculated costs. */
1224 /* REGISTER_MOVE_COST. */
1227 mmix_register_move_cost (enum machine_mode mode ATTRIBUTE_UNUSED
,
1228 enum reg_class from
,
1231 return (from
== GENERAL_REGS
&& from
== to
) ? 2 : 3;
1234 /* Note that we don't have a TEXT_SECTION_ASM_OP, because it has to be a
1235 compile-time constant; it's used in an asm in crtstuff.c, compiled for
1238 /* DATA_SECTION_ASM_OP. */
1241 mmix_data_section_asm_op (void)
1243 return "\t.data ! mmixal:= 8H LOC 9B";
1247 mmix_encode_section_info (tree decl
, rtx rtl
, int first
)
1249 /* Test for an external declaration, and do nothing if it is one. */
1250 if ((TREE_CODE (decl
) == VAR_DECL
1251 && (DECL_EXTERNAL (decl
) || TREE_PUBLIC (decl
)))
1252 || (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_PUBLIC (decl
)))
1254 else if (first
&& DECL_P (decl
))
1256 /* For non-visible declarations, add a "@" prefix, which we skip
1257 when the label is output. If the label does not have this
1258 prefix, a ":" is output if -mtoplevel-symbols.
1260 Note that this does not work for data that is declared extern and
1261 later defined as static. If there's code in between, that code
1262 will refer to the extern declaration, and vice versa. This just
1263 means that when -mtoplevel-symbols is in use, we can just handle
1264 well-behaved ISO-compliant code. */
1266 const char *str
= XSTR (XEXP (rtl
, 0), 0);
1267 int len
= strlen (str
);
1268 char *newstr
= XALLOCAVEC (char, len
+ 2);
1270 strcpy (newstr
+ 1, str
);
1271 XSTR (XEXP (rtl
, 0), 0) = ggc_alloc_string (newstr
, len
+ 1);
1274 /* Set SYMBOL_REF_FLAG for things that we want to access with GETA. We
1275 may need different options to reach for different things with GETA.
1276 For now, functions and things we know or have been told are constant. */
1277 if (TREE_CODE (decl
) == FUNCTION_DECL
1278 || TREE_CONSTANT (decl
)
1279 || (TREE_CODE (decl
) == VAR_DECL
1280 && TREE_READONLY (decl
)
1281 && !TREE_SIDE_EFFECTS (decl
)
1282 && (!DECL_INITIAL (decl
)
1283 || TREE_CONSTANT (DECL_INITIAL (decl
)))))
1284 SYMBOL_REF_FLAG (XEXP (rtl
, 0)) = 1;
1288 mmix_strip_name_encoding (const char *name
)
1290 for (; (*name
== '@' || *name
== '*'); name
++)
1296 /* TARGET_ASM_FILE_START.
1297 We just emit a little comment for the time being. */
1300 mmix_file_start (void)
1302 default_file_start ();
1304 fputs ("! mmixal:= 8H LOC Data_Section\n", asm_out_file
);
1306 /* Make sure each file starts with the text section. */
1307 switch_to_section (text_section
);
1310 /* TARGET_ASM_FILE_END. */
1313 mmix_file_end (void)
1315 /* Make sure each file ends with the data section. */
1316 switch_to_section (data_section
);
1319 /* TARGET_ASM_OUTPUT_SOURCE_FILENAME. */
1322 mmix_asm_output_source_filename (FILE *stream
, const char *name
)
1324 fprintf (stream
, "# 1 ");
1325 OUTPUT_QUOTED_STRING (stream
, name
);
1326 fprintf (stream
, "\n");
1329 /* OUTPUT_QUOTED_STRING. */
1332 mmix_output_quoted_string (FILE *stream
, const char *string
, int length
)
1334 const char * string_end
= string
+ length
;
1335 static const char *const unwanted_chars
= "\"[]\\";
1337 /* Output "any character except newline and double quote character". We
1338 play it safe and avoid all control characters too. We also do not
1339 want [] as characters, should input be passed through m4 with [] as
1340 quotes. Further, we avoid "\", because the GAS port handles it as a
1341 quoting character. */
1342 while (string
< string_end
)
1345 && (unsigned char) *string
< 128
1346 && !ISCNTRL (*string
)
1347 && strchr (unwanted_chars
, *string
) == NULL
)
1349 fputc ('"', stream
);
1351 && (unsigned char) *string
< 128
1352 && !ISCNTRL (*string
)
1353 && strchr (unwanted_chars
, *string
) == NULL
1354 && string
< string_end
)
1356 fputc (*string
, stream
);
1359 fputc ('"', stream
);
1360 if (string
< string_end
)
1361 fprintf (stream
, ",");
1363 if (string
< string_end
)
1365 fprintf (stream
, "#%x", *string
& 255);
1367 if (string
< string_end
)
1368 fprintf (stream
, ",");
1373 /* Target hook for assembling integer objects. Use mmix_print_operand
1374 for WYDE and TETRA. Use mmix_output_octa to output 8-byte
1378 mmix_assemble_integer (rtx x
, unsigned int size
, int aligned_p
)
1383 /* We handle a limited number of types of operands in here. But
1384 that's ok, because we can punt to generic functions. We then
1385 pretend that aligned data isn't needed, so the usual .<pseudo>
1386 syntax is used (which works for aligned data too). We actually
1387 *must* do that, since we say we don't have simple aligned
1388 pseudos, causing this function to be called. We just try and
1389 keep as much compatibility as possible with mmixal syntax for
1390 normal cases (i.e. without GNU extensions and C only). */
1392 if (GET_CODE (x
) != CONST_INT
)
1397 fputs ("\tBYTE\t", asm_out_file
);
1398 mmix_print_operand (asm_out_file
, x
, 'B');
1399 fputc ('\n', asm_out_file
);
1403 if (GET_CODE (x
) != CONST_INT
)
1408 fputs ("\tWYDE\t", asm_out_file
);
1409 mmix_print_operand (asm_out_file
, x
, 'W');
1410 fputc ('\n', asm_out_file
);
1414 if (GET_CODE (x
) != CONST_INT
)
1419 fputs ("\tTETRA\t", asm_out_file
);
1420 mmix_print_operand (asm_out_file
, x
, 'L');
1421 fputc ('\n', asm_out_file
);
1425 /* We don't get here anymore for CONST_DOUBLE, because DImode
1426 isn't expressed as CONST_DOUBLE, and DFmode is handled
1428 gcc_assert (GET_CODE (x
) != CONST_DOUBLE
);
1429 assemble_integer_with_op ("\tOCTA\t", x
);
1432 return default_assemble_integer (x
, size
, aligned_p
);
1435 /* ASM_OUTPUT_ASCII. */
1438 mmix_asm_output_ascii (FILE *stream
, const char *string
, int length
)
1442 int chunk_size
= length
> 60 ? 60 : length
;
1443 fprintf (stream
, "\tBYTE ");
1444 mmix_output_quoted_string (stream
, string
, chunk_size
);
1445 string
+= chunk_size
;
1446 length
-= chunk_size
;
1447 fprintf (stream
, "\n");
1451 /* ASM_OUTPUT_ALIGNED_COMMON. */
1454 mmix_asm_output_aligned_common (FILE *stream
,
1459 /* This is mostly the elfos.h one. There doesn't seem to be a way to
1460 express this in a mmixal-compatible way. */
1461 fprintf (stream
, "\t.comm\t");
1462 assemble_name (stream
, name
);
1463 fprintf (stream
, ",%u,%u ! mmixal-incompatible COMMON\n",
1464 size
, align
/ BITS_PER_UNIT
);
1467 /* ASM_OUTPUT_ALIGNED_LOCAL. */
1470 mmix_asm_output_aligned_local (FILE *stream
,
1475 switch_to_section (data_section
);
1477 ASM_OUTPUT_ALIGN (stream
, exact_log2 (align
/BITS_PER_UNIT
));
1478 assemble_name (stream
, name
);
1479 fprintf (stream
, "\tLOC @+%d\n", size
);
1482 /* ASM_OUTPUT_LABEL. */
1485 mmix_asm_output_label (FILE *stream
, const char *name
)
1487 assemble_name (stream
, name
);
1488 fprintf (stream
, "\tIS @\n");
1491 /* ASM_OUTPUT_INTERNAL_LABEL. */
1494 mmix_asm_output_internal_label (FILE *stream
, const char *name
)
1496 assemble_name_raw (stream
, name
);
1497 fprintf (stream
, "\tIS @\n");
1500 /* ASM_DECLARE_REGISTER_GLOBAL. */
1503 mmix_asm_declare_register_global (FILE *stream ATTRIBUTE_UNUSED
,
1504 tree decl ATTRIBUTE_UNUSED
,
1505 int regno ATTRIBUTE_UNUSED
,
1506 const char *name ATTRIBUTE_UNUSED
)
1508 /* Nothing to do here, but there *will* be, therefore the framework is
1512 /* ASM_WEAKEN_LABEL. */
1515 mmix_asm_weaken_label (FILE *stream ATTRIBUTE_UNUSED
,
1516 const char *name ATTRIBUTE_UNUSED
)
1518 fprintf (stream
, "\t.weak ");
1519 assemble_name (stream
, name
);
1520 fprintf (stream
, " ! mmixal-incompatible\n");
1523 /* MAKE_DECL_ONE_ONLY. */
1526 mmix_make_decl_one_only (tree decl
)
1528 DECL_WEAK (decl
) = 1;
1531 /* ASM_OUTPUT_LABELREF.
1532 Strip GCC's '*' and our own '@'. No order is assumed. */
1535 mmix_asm_output_labelref (FILE *stream
, const char *name
)
1539 for (; (*name
== '@' || *name
== '*'); name
++)
1543 asm_fprintf (stream
, "%s%U%s",
1544 is_extern
&& TARGET_TOPLEVEL_SYMBOLS
? ":" : "",
1548 /* ASM_OUTPUT_DEF. */
1551 mmix_asm_output_def (FILE *stream
, const char *name
, const char *value
)
1553 assemble_name (stream
, name
);
1554 fprintf (stream
, "\tIS ");
1555 assemble_name (stream
, value
);
1556 fputc ('\n', stream
);
1559 /* PRINT_OPERAND. */
1562 mmix_print_operand (FILE *stream
, rtx x
, int code
)
1564 /* When we add support for different codes later, we can, when needed,
1565 drop through to the main handler with a modified operand. */
1567 int regno
= x
!= NULL_RTX
&& REG_P (x
) ? REGNO (x
) : 0;
1571 /* Unrelated codes are in alphabetic order. */
1574 /* For conditional branches, output "P" for a probable branch. */
1575 if (TARGET_BRANCH_PREDICT
)
1577 x
= find_reg_note (current_output_insn
, REG_BR_PROB
, 0);
1578 if (x
&& INTVAL (XEXP (x
, 0)) > REG_BR_PROB_BASE
/ 2)
1584 /* For the %d in POP %d,0. */
1585 fprintf (stream
, "%d", MMIX_POP_ARGUMENT ());
1589 if (GET_CODE (x
) != CONST_INT
)
1590 fatal_insn ("MMIX Internal: Expected a CONST_INT, not this", x
);
1591 fprintf (stream
, "%d", (int) (INTVAL (x
) & 0xff));
1595 /* Highpart. Must be general register, and not the last one, as
1596 that one cannot be part of a consecutive register pair. */
1597 if (regno
> MMIX_LAST_GENERAL_REGISTER
- 1)
1598 internal_error ("MMIX Internal: Bad register: %d", regno
);
1600 /* This is big-endian, so the high-part is the first one. */
1601 fprintf (stream
, "%s", reg_names
[MMIX_OUTPUT_REGNO (regno
)]);
1605 /* Lowpart. Must be CONST_INT or general register, and not the last
1606 one, as that one cannot be part of a consecutive register pair. */
1607 if (GET_CODE (x
) == CONST_INT
)
1609 fprintf (stream
, "#%lx",
1610 (unsigned long) (INTVAL (x
)
1611 & ((unsigned int) 0x7fffffff * 2 + 1)));
1615 if (GET_CODE (x
) == SYMBOL_REF
)
1617 output_addr_const (stream
, x
);
1621 if (regno
> MMIX_LAST_GENERAL_REGISTER
- 1)
1622 internal_error ("MMIX Internal: Bad register: %d", regno
);
1624 /* This is big-endian, so the low-part is + 1. */
1625 fprintf (stream
, "%s", reg_names
[MMIX_OUTPUT_REGNO (regno
) + 1]);
1628 /* Can't use 'a' because that's a generic modifier for address
1631 mmix_output_shiftvalue_op_from_str (stream
, "ANDN",
1632 ~(unsigned HOST_WIDEST_INT
)
1637 mmix_output_shiftvalue_op_from_str (stream
, "INC",
1638 (unsigned HOST_WIDEST_INT
)
1643 mmix_output_shiftvalue_op_from_str (stream
, "OR",
1644 (unsigned HOST_WIDEST_INT
)
1649 mmix_output_shiftvalue_op_from_str (stream
, "SET",
1650 (unsigned HOST_WIDEST_INT
)
1656 mmix_output_condition (stream
, x
, (code
== 'D'));
1660 /* Output an extra "e" to make fcmpe, fune. */
1661 if (TARGET_FCMP_EPSILON
)
1662 fprintf (stream
, "e");
1666 /* Output the number minus 1. */
1667 if (GET_CODE (x
) != CONST_INT
)
1669 fatal_insn ("MMIX Internal: Bad value for 'm', not a CONST_INT",
1672 fprintf (stream
, HOST_WIDEST_INT_PRINT_DEC
,
1673 (HOST_WIDEST_INT
) (mmix_intval (x
) - 1));
1677 /* Store the number of registers we want to save. This was setup
1678 by the prologue. The actual operand contains the number of
1679 registers to pass, but we don't use it currently. Anyway, we
1680 need to output the number of saved registers here. */
1681 fprintf (stream
, "%d",
1682 cfun
->machine
->highest_saved_stack_register
+ 1);
1686 /* Store the register to output a constant to. */
1688 fatal_insn ("MMIX Internal: Expected a register, not this", x
);
1689 mmix_output_destination_register
= MMIX_OUTPUT_REGNO (regno
);
1693 /* Output the constant. Note that we use this for floats as well. */
1694 if (GET_CODE (x
) != CONST_INT
1695 && (GET_CODE (x
) != CONST_DOUBLE
1696 || (GET_MODE (x
) != VOIDmode
&& GET_MODE (x
) != DFmode
1697 && GET_MODE (x
) != SFmode
)))
1698 fatal_insn ("MMIX Internal: Expected a constant, not this", x
);
1699 mmix_output_register_setting (stream
,
1700 mmix_output_destination_register
,
1701 mmix_intval (x
), 0);
1705 /* An U for unsigned, if TARGET_ZERO_EXTEND. Ignore the operand. */
1706 if (TARGET_ZERO_EXTEND
)
1711 mmix_output_shifted_value (stream
, (HOST_WIDEST_INT
) mmix_intval (x
));
1715 mmix_output_shifted_value (stream
, (HOST_WIDEST_INT
) ~mmix_intval (x
));
1719 if (GET_CODE (x
) != CONST_INT
)
1720 fatal_insn ("MMIX Internal: Expected a CONST_INT, not this", x
);
1721 fprintf (stream
, "#%x", (int) (INTVAL (x
) & 0xffff));
1725 /* Nothing to do. */
1729 /* Presumably there's a missing case above if we get here. */
1730 internal_error ("MMIX Internal: Missing %qc case in mmix_print_operand", code
);
1733 switch (GET_CODE (modified_x
))
1736 regno
= REGNO (modified_x
);
1737 if (regno
>= FIRST_PSEUDO_REGISTER
)
1738 internal_error ("MMIX Internal: Bad register: %d", regno
);
1739 fprintf (stream
, "%s", reg_names
[MMIX_OUTPUT_REGNO (regno
)]);
1743 output_address (XEXP (modified_x
, 0));
1747 /* For -2147483648, mmixal complains that the constant does not fit
1748 in 4 bytes, so let's output it as hex. Take care to handle hosts
1749 where HOST_WIDE_INT is longer than an int.
1751 Print small constants +-255 using decimal. */
1753 if (INTVAL (modified_x
) > -256 && INTVAL (modified_x
) < 256)
1754 fprintf (stream
, "%d", (int) (INTVAL (modified_x
)));
1756 fprintf (stream
, "#%x",
1757 (int) (INTVAL (modified_x
)) & (unsigned int) ~0);
1761 /* Do somewhat as CONST_INT. */
1762 mmix_output_octa (stream
, mmix_intval (modified_x
), 0);
1766 output_addr_const (stream
, modified_x
);
1770 /* No need to test for all strange things. Let output_addr_const do
1772 if (CONSTANT_P (modified_x
)
1773 /* Strangely enough, this is not included in CONSTANT_P.
1774 FIXME: Ask/check about sanity here. */
1775 || GET_CODE (modified_x
) == CODE_LABEL
)
1777 output_addr_const (stream
, modified_x
);
1781 /* We need the original here. */
1782 fatal_insn ("MMIX Internal: Cannot decode this operand", x
);
1786 /* PRINT_OPERAND_PUNCT_VALID_P. */
1789 mmix_print_operand_punct_valid_p (int code ATTRIBUTE_UNUSED
)
1791 /* A '+' is used for branch prediction, similar to other ports. */
1793 /* A '.' is used for the %d in the POP %d,0 return insn. */
1797 /* PRINT_OPERAND_ADDRESS. */
1800 mmix_print_operand_address (FILE *stream
, rtx x
)
1804 /* I find the generated assembly code harder to read without
1806 fprintf (stream
, "%s,0", reg_names
[MMIX_OUTPUT_REGNO (REGNO (x
))]);
1809 else if (GET_CODE (x
) == PLUS
)
1811 rtx x1
= XEXP (x
, 0);
1812 rtx x2
= XEXP (x
, 1);
1816 fprintf (stream
, "%s,", reg_names
[MMIX_OUTPUT_REGNO (REGNO (x1
))]);
1820 fprintf (stream
, "%s",
1821 reg_names
[MMIX_OUTPUT_REGNO (REGNO (x2
))]);
1824 else if (GET_CODE (x2
) == CONST_INT
1825 && CONST_OK_FOR_LETTER_P (INTVAL (x2
), 'I'))
1827 output_addr_const (stream
, x2
);
1833 if (TARGET_BASE_ADDRESSES
&& mmix_legitimate_constant_p (x
))
1835 output_addr_const (stream
, x
);
1839 fatal_insn ("MMIX Internal: This is not a recognized address", x
);
1842 /* ASM_OUTPUT_REG_PUSH. */
1845 mmix_asm_output_reg_push (FILE *stream
, int regno
)
1847 fprintf (stream
, "\tSUBU %s,%s,8\n\tSTOU %s,%s,0\n",
1848 reg_names
[MMIX_STACK_POINTER_REGNUM
],
1849 reg_names
[MMIX_STACK_POINTER_REGNUM
],
1850 reg_names
[MMIX_OUTPUT_REGNO (regno
)],
1851 reg_names
[MMIX_STACK_POINTER_REGNUM
]);
1854 /* ASM_OUTPUT_REG_POP. */
1857 mmix_asm_output_reg_pop (FILE *stream
, int regno
)
1859 fprintf (stream
, "\tLDOU %s,%s,0\n\tINCL %s,8\n",
1860 reg_names
[MMIX_OUTPUT_REGNO (regno
)],
1861 reg_names
[MMIX_STACK_POINTER_REGNUM
],
1862 reg_names
[MMIX_STACK_POINTER_REGNUM
]);
1865 /* ASM_OUTPUT_ADDR_DIFF_ELT. */
1868 mmix_asm_output_addr_diff_elt (FILE *stream
,
1869 rtx body ATTRIBUTE_UNUSED
,
1873 fprintf (stream
, "\tTETRA L%d-L%d\n", value
, rel
);
1876 /* ASM_OUTPUT_ADDR_VEC_ELT. */
1879 mmix_asm_output_addr_vec_elt (FILE *stream
, int value
)
1881 fprintf (stream
, "\tOCTA L:%d\n", value
);
1884 /* ASM_OUTPUT_SKIP. */
1887 mmix_asm_output_skip (FILE *stream
, int nbytes
)
1889 fprintf (stream
, "\tLOC @+%d\n", nbytes
);
1892 /* ASM_OUTPUT_ALIGN. */
1895 mmix_asm_output_align (FILE *stream
, int power
)
1897 /* We need to record the needed alignment of this section in the object,
1898 so we have to output an alignment directive. Use a .p2align (not
1899 .align) so people will never have to wonder about whether the
1900 argument is in number of bytes or the log2 thereof. We do it in
1901 addition to the LOC directive, so nothing needs tweaking when
1902 copy-pasting assembly into mmixal. */
1903 fprintf (stream
, "\t.p2align %d\n", power
);
1904 fprintf (stream
, "\tLOC @+(%d-@)&%d\n", 1 << power
, (1 << power
) - 1);
1907 /* DBX_REGISTER_NUMBER. */
1910 mmix_dbx_register_number (unsigned regno
)
1912 /* Adjust the register number to the one it will be output as, dammit.
1913 It'd be nice if we could check the assumption that we're filling a
1914 gap, but every register between the last saved register and parameter
1915 registers might be a valid parameter register. */
1916 regno
= MMIX_OUTPUT_REGNO (regno
);
1918 /* We need to renumber registers to get the number of the return address
1919 register in the range 0..255. It is also space-saving if registers
1920 mentioned in the call-frame information (which uses this function by
1921 defaulting DWARF_FRAME_REGNUM to DBX_REGISTER_NUMBER) are numbered
1922 0 .. 63. So map 224 .. 256+15 -> 0 .. 47 and 0 .. 223 -> 48..223+48. */
1923 return regno
>= 224 ? (regno
- 224) : (regno
+ 48);
1926 /* End of target macro support functions.
1928 Now the MMIX port's own functions. First the exported ones. */
1930 /* Wrapper for get_hard_reg_initial_val since integrate.h isn't included
1931 from insn-emit.c. */
1934 mmix_get_hard_reg_initial_val (enum machine_mode mode
, int regno
)
1936 return get_hard_reg_initial_val (mode
, regno
);
1939 /* Nonzero when the function epilogue is simple enough that a single
1940 "POP %d,0" should be used even within the function. */
1943 mmix_use_simple_return (void)
1947 int stack_space_to_allocate
1948 = (crtl
->outgoing_args_size
1949 + crtl
->args
.pretend_args_size
1950 + get_frame_size () + 7) & ~7;
1952 if (!TARGET_USE_RETURN_INSN
|| !reload_completed
)
1956 regno
>= MMIX_FIRST_GLOBAL_REGNUM
;
1958 /* Note that we assume that the frame-pointer-register is one of these
1959 registers, in which case we don't count it here. */
1960 if ((((regno
!= MMIX_FRAME_POINTER_REGNUM
|| !frame_pointer_needed
)
1961 && df_regs_ever_live_p (regno
) && !call_used_regs
[regno
]))
1962 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
1965 if (frame_pointer_needed
)
1966 stack_space_to_allocate
+= 8;
1968 if (MMIX_CFUN_HAS_LANDING_PAD
)
1969 stack_space_to_allocate
+= 16;
1970 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
)
1971 stack_space_to_allocate
+= 8;
1973 return stack_space_to_allocate
== 0;
1977 /* Expands the function prologue into RTX. */
1980 mmix_expand_prologue (void)
1982 HOST_WIDE_INT locals_size
= get_frame_size ();
1984 HOST_WIDE_INT stack_space_to_allocate
1985 = (crtl
->outgoing_args_size
1986 + crtl
->args
.pretend_args_size
1987 + locals_size
+ 7) & ~7;
1988 HOST_WIDE_INT offset
= -8;
1990 /* Add room needed to save global non-register-stack registers. */
1992 regno
>= MMIX_FIRST_GLOBAL_REGNUM
;
1994 /* Note that we assume that the frame-pointer-register is one of these
1995 registers, in which case we don't count it here. */
1996 if ((((regno
!= MMIX_FRAME_POINTER_REGNUM
|| !frame_pointer_needed
)
1997 && df_regs_ever_live_p (regno
) && !call_used_regs
[regno
]))
1998 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
1999 stack_space_to_allocate
+= 8;
2001 /* If we do have a frame-pointer, add room for it. */
2002 if (frame_pointer_needed
)
2003 stack_space_to_allocate
+= 8;
2005 /* If we have a non-local label, we need to be able to unwind to it, so
2006 store the current register stack pointer. Also store the return
2007 address if we do that. */
2008 if (MMIX_CFUN_HAS_LANDING_PAD
)
2009 stack_space_to_allocate
+= 16;
2010 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
)
2011 /* If we do have a saved return-address slot, add room for it. */
2012 stack_space_to_allocate
+= 8;
2014 /* Make sure we don't get an unaligned stack. */
2015 if ((stack_space_to_allocate
% 8) != 0)
2016 internal_error ("stack frame not a multiple of 8 bytes: %wd",
2017 stack_space_to_allocate
);
2019 if (crtl
->args
.pretend_args_size
)
2021 int mmix_first_vararg_reg
2022 = (MMIX_FIRST_INCOMING_ARG_REGNUM
2023 + (MMIX_MAX_ARGS_IN_REGS
2024 - crtl
->args
.pretend_args_size
/ 8));
2027 = MMIX_FIRST_INCOMING_ARG_REGNUM
+ MMIX_MAX_ARGS_IN_REGS
- 1;
2028 regno
>= mmix_first_vararg_reg
;
2033 HOST_WIDE_INT stack_chunk
2034 = stack_space_to_allocate
> (256 - 8)
2035 ? (256 - 8) : stack_space_to_allocate
;
2037 mmix_emit_sp_add (-stack_chunk
);
2038 offset
+= stack_chunk
;
2039 stack_space_to_allocate
-= stack_chunk
;
2042 /* These registers aren't actually saved (as in "will be
2043 restored"), so don't tell DWARF2 they're saved. */
2044 emit_move_insn (gen_rtx_MEM (DImode
,
2045 plus_constant (stack_pointer_rtx
,
2047 gen_rtx_REG (DImode
, regno
));
2052 /* Store the frame-pointer. */
2054 if (frame_pointer_needed
)
2060 /* Get 8 less than otherwise, since we need to reach offset + 8. */
2061 HOST_WIDE_INT stack_chunk
2062 = stack_space_to_allocate
> (256 - 8 - 8)
2063 ? (256 - 8 - 8) : stack_space_to_allocate
;
2065 mmix_emit_sp_add (-stack_chunk
);
2067 offset
+= stack_chunk
;
2068 stack_space_to_allocate
-= stack_chunk
;
2071 insn
= emit_move_insn (gen_rtx_MEM (DImode
,
2072 plus_constant (stack_pointer_rtx
,
2074 hard_frame_pointer_rtx
);
2075 RTX_FRAME_RELATED_P (insn
) = 1;
2076 insn
= emit_insn (gen_adddi3 (hard_frame_pointer_rtx
,
2078 GEN_INT (offset
+ 8)));
2079 RTX_FRAME_RELATED_P (insn
) = 1;
2083 if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
)
2088 /* Store the return-address, if one is needed on the stack. We
2089 usually store it in a register when needed, but that doesn't work
2090 with -fexceptions. */
2094 /* Get 8 less than otherwise, since we need to reach offset + 8. */
2095 HOST_WIDE_INT stack_chunk
2096 = stack_space_to_allocate
> (256 - 8 - 8)
2097 ? (256 - 8 - 8) : stack_space_to_allocate
;
2099 mmix_emit_sp_add (-stack_chunk
);
2101 offset
+= stack_chunk
;
2102 stack_space_to_allocate
-= stack_chunk
;
2105 tmpreg
= gen_rtx_REG (DImode
, 255);
2106 retreg
= gen_rtx_REG (DImode
, MMIX_rJ_REGNUM
);
2108 /* Dwarf2 code is confused by the use of a temporary register for
2109 storing the return address, so we have to express it as a note,
2110 which we attach to the actual store insn. */
2111 emit_move_insn (tmpreg
, retreg
);
2113 insn
= emit_move_insn (gen_rtx_MEM (DImode
,
2114 plus_constant (stack_pointer_rtx
,
2117 RTX_FRAME_RELATED_P (insn
) = 1;
2118 add_reg_note (insn
, REG_FRAME_RELATED_EXPR
,
2119 gen_rtx_SET (VOIDmode
,
2120 gen_rtx_MEM (DImode
,
2121 plus_constant (stack_pointer_rtx
,
2127 else if (MMIX_CFUN_HAS_LANDING_PAD
)
2130 if (MMIX_CFUN_HAS_LANDING_PAD
)
2132 /* Store the register defining the numbering of local registers, so
2133 we know how long to unwind the register stack. */
2137 /* Get 8 less than otherwise, since we need to reach offset + 8. */
2138 HOST_WIDE_INT stack_chunk
2139 = stack_space_to_allocate
> (256 - 8 - 8)
2140 ? (256 - 8 - 8) : stack_space_to_allocate
;
2142 mmix_emit_sp_add (-stack_chunk
);
2144 offset
+= stack_chunk
;
2145 stack_space_to_allocate
-= stack_chunk
;
2148 /* We don't tell dwarf2 about this one; we just have it to unwind
2149 the register stack at landing pads. FIXME: It's a kludge because
2150 we can't describe the effect of the PUSHJ and PUSHGO insns on the
2151 register stack at the moment. Best thing would be to handle it
2152 like stack-pointer offsets. Better: some hook into dwarf2out.c
2153 to produce DW_CFA_expression:s that specify the increment of rO,
2154 and unwind it at eh_return (preferred) or at the landing pad.
2155 Then saves to $0..$G-1 could be specified through that register. */
2157 emit_move_insn (gen_rtx_REG (DImode
, 255),
2158 gen_rtx_REG (DImode
,
2160 emit_move_insn (gen_rtx_MEM (DImode
,
2161 plus_constant (stack_pointer_rtx
, offset
)),
2162 gen_rtx_REG (DImode
, 255));
2166 /* After the return-address and the frame-pointer, we have the local
2167 variables. They're the ones that may have an "unaligned" size. */
2168 offset
-= (locals_size
+ 7) & ~7;
2170 /* Now store all registers that are global, i.e. not saved by the
2171 register file machinery.
2173 It is assumed that the frame-pointer is one of these registers, so it
2174 is explicitly excluded in the count. */
2177 regno
>= MMIX_FIRST_GLOBAL_REGNUM
;
2179 if (((regno
!= MMIX_FRAME_POINTER_REGNUM
|| !frame_pointer_needed
)
2180 && df_regs_ever_live_p (regno
) && ! call_used_regs
[regno
])
2181 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
2187 HOST_WIDE_INT stack_chunk
2188 = (stack_space_to_allocate
> (256 - offset
- 8)
2189 ? (256 - offset
- 8) : stack_space_to_allocate
);
2191 mmix_emit_sp_add (-stack_chunk
);
2192 offset
+= stack_chunk
;
2193 stack_space_to_allocate
-= stack_chunk
;
2196 insn
= emit_move_insn (gen_rtx_MEM (DImode
,
2197 plus_constant (stack_pointer_rtx
,
2199 gen_rtx_REG (DImode
, regno
));
2200 RTX_FRAME_RELATED_P (insn
) = 1;
2204 /* Finally, allocate room for outgoing args and local vars if room
2205 wasn't allocated above. */
2206 if (stack_space_to_allocate
)
2207 mmix_emit_sp_add (-stack_space_to_allocate
);
2210 /* Expands the function epilogue into RTX. */
2213 mmix_expand_epilogue (void)
2215 HOST_WIDE_INT locals_size
= get_frame_size ();
2217 HOST_WIDE_INT stack_space_to_deallocate
2218 = (crtl
->outgoing_args_size
2219 + crtl
->args
.pretend_args_size
2220 + locals_size
+ 7) & ~7;
2222 /* The first address to access is beyond the outgoing_args area. */
2223 HOST_WIDE_INT offset
= crtl
->outgoing_args_size
;
2225 /* Add the space for global non-register-stack registers.
2226 It is assumed that the frame-pointer register can be one of these
2227 registers, in which case it is excluded from the count when needed. */
2229 regno
>= MMIX_FIRST_GLOBAL_REGNUM
;
2231 if (((regno
!= MMIX_FRAME_POINTER_REGNUM
|| !frame_pointer_needed
)
2232 && df_regs_ever_live_p (regno
) && !call_used_regs
[regno
])
2233 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
2234 stack_space_to_deallocate
+= 8;
2236 /* Add in the space for register stack-pointer. If so, always add room
2237 for the saved PC. */
2238 if (MMIX_CFUN_HAS_LANDING_PAD
)
2239 stack_space_to_deallocate
+= 16;
2240 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
)
2241 /* If we have a saved return-address slot, add it in. */
2242 stack_space_to_deallocate
+= 8;
2244 /* Add in the frame-pointer. */
2245 if (frame_pointer_needed
)
2246 stack_space_to_deallocate
+= 8;
2248 /* Make sure we don't get an unaligned stack. */
2249 if ((stack_space_to_deallocate
% 8) != 0)
2250 internal_error ("stack frame not a multiple of octabyte: %wd",
2251 stack_space_to_deallocate
);
2253 /* We will add back small offsets to the stack pointer as we go.
2254 First, we restore all registers that are global, i.e. not saved by
2255 the register file machinery. */
2257 for (regno
= MMIX_FIRST_GLOBAL_REGNUM
;
2260 if (((regno
!= MMIX_FRAME_POINTER_REGNUM
|| !frame_pointer_needed
)
2261 && df_regs_ever_live_p (regno
) && !call_used_regs
[regno
])
2262 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
2266 mmix_emit_sp_add (offset
);
2267 stack_space_to_deallocate
-= offset
;
2271 emit_move_insn (gen_rtx_REG (DImode
, regno
),
2272 gen_rtx_MEM (DImode
,
2273 plus_constant (stack_pointer_rtx
,
2278 /* Here is where the local variables were. As in the prologue, they
2279 might be of an unaligned size. */
2280 offset
+= (locals_size
+ 7) & ~7;
2282 /* The saved register stack pointer is just below the frame-pointer
2283 register. We don't need to restore it "manually"; the POP
2284 instruction does that. */
2285 if (MMIX_CFUN_HAS_LANDING_PAD
)
2287 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
)
2288 /* The return-address slot is just below the frame-pointer register.
2289 We don't need to restore it because we don't really use it. */
2292 /* Get back the old frame-pointer-value. */
2293 if (frame_pointer_needed
)
2297 mmix_emit_sp_add (offset
);
2299 stack_space_to_deallocate
-= offset
;
2303 emit_move_insn (hard_frame_pointer_rtx
,
2304 gen_rtx_MEM (DImode
,
2305 plus_constant (stack_pointer_rtx
,
2310 /* We do not need to restore pretended incoming args, just add back
2312 if (stack_space_to_deallocate
!= 0)
2313 mmix_emit_sp_add (stack_space_to_deallocate
);
2315 if (crtl
->calls_eh_return
)
2316 /* Adjust the (normal) stack-pointer to that of the receiver.
2317 FIXME: It would be nice if we could also adjust the register stack
2318 here, but we need to express it through DWARF 2 too. */
2319 emit_insn (gen_adddi3 (stack_pointer_rtx
, stack_pointer_rtx
,
2320 gen_rtx_REG (DImode
,
2321 MMIX_EH_RETURN_STACKADJ_REGNUM
)));
2324 /* Output an optimal sequence for setting a register to a specific
2325 constant. Used in an alternative for const_ints in movdi, and when
2326 using large stack-frame offsets.
2328 Use do_begin_end to say if a line-starting TAB and newline before the
2329 first insn and after the last insn is wanted. */
2332 mmix_output_register_setting (FILE *stream
,
2334 HOST_WIDEST_INT value
,
2338 fprintf (stream
, "\t");
2340 if (mmix_shiftable_wyde_value ((unsigned HOST_WIDEST_INT
) value
))
2342 /* First, the one-insn cases. */
2343 mmix_output_shiftvalue_op_from_str (stream
, "SET",
2344 (unsigned HOST_WIDEST_INT
)
2346 fprintf (stream
, " %s,", reg_names
[regno
]);
2347 mmix_output_shifted_value (stream
, (unsigned HOST_WIDEST_INT
) value
);
2349 else if (mmix_shiftable_wyde_value (-(unsigned HOST_WIDEST_INT
) value
))
2351 /* We do this to get a bit more legible assembly code. The next
2352 alternative is mostly redundant with this. */
2354 mmix_output_shiftvalue_op_from_str (stream
, "SET",
2355 -(unsigned HOST_WIDEST_INT
)
2357 fprintf (stream
, " %s,", reg_names
[regno
]);
2358 mmix_output_shifted_value (stream
, -(unsigned HOST_WIDEST_INT
) value
);
2359 fprintf (stream
, "\n\tNEGU %s,0,%s", reg_names
[regno
],
2362 else if (mmix_shiftable_wyde_value (~(unsigned HOST_WIDEST_INT
) value
))
2364 /* Slightly more expensive, the two-insn cases. */
2366 /* FIXME: We could of course also test if 0..255-N or ~(N | 1..255)
2367 is shiftable, or any other one-insn transformation of the value.
2368 FIXME: Check first if the value is "shiftable" by two loading
2369 with two insns, since it makes more readable assembly code (if
2370 anyone else cares). */
2372 mmix_output_shiftvalue_op_from_str (stream
, "SET",
2373 ~(unsigned HOST_WIDEST_INT
)
2375 fprintf (stream
, " %s,", reg_names
[regno
]);
2376 mmix_output_shifted_value (stream
, ~(unsigned HOST_WIDEST_INT
) value
);
2377 fprintf (stream
, "\n\tNOR %s,%s,0", reg_names
[regno
],
2382 /* The generic case. 2..4 insns. */
2383 static const char *const higher_parts
[] = {"L", "ML", "MH", "H"};
2384 const char *op
= "SET";
2385 const char *line_begin
= "";
2388 HOST_WIDEST_INT tmpvalue
= value
;
2390 /* Compute the number of insns needed to output this constant. */
2391 for (i
= 0; i
< 4 && tmpvalue
!= 0; i
++)
2393 if (tmpvalue
& 65535)
2397 if (TARGET_BASE_ADDRESSES
&& insns
== 3)
2399 /* The number three is based on a static observation on
2400 ghostscript-6.52. Two and four are excluded because there
2401 are too many such constants, and each unique constant (maybe
2402 offset by 1..255) were used few times compared to other uses,
2405 We use base-plus-offset addressing to force it into a global
2406 register; we just use a "LDA reg,VALUE", which will cause the
2407 assembler and linker to DTRT (for constants as well as
2409 fprintf (stream
, "LDA %s,", reg_names
[regno
]);
2410 mmix_output_octa (stream
, value
, 0);
2414 /* Output pertinent parts of the 4-wyde sequence.
2415 Still more to do if we want this to be optimal, but hey...
2416 Note that the zero case has been handled above. */
2417 for (i
= 0; i
< 4 && value
!= 0; i
++)
2421 fprintf (stream
, "%s%s%s %s,#%x", line_begin
, op
,
2422 higher_parts
[i
], reg_names
[regno
],
2423 (int) (value
& 65535));
2424 /* The first one sets the rest of the bits to 0, the next
2425 ones add set bits. */
2427 line_begin
= "\n\t";
2436 fprintf (stream
, "\n");
2439 /* Return 1 if value is 0..65535*2**(16*N) for N=0..3.
2443 mmix_shiftable_wyde_value (unsigned HOST_WIDEST_INT value
)
2445 /* Shift by 16 bits per group, stop when we've found two groups with
2448 int has_candidate
= 0;
2450 for (i
= 0; i
< 4; i
++)
2466 /* X and Y are two things to compare using CODE. Return the rtx for
2467 the cc-reg in the proper mode. */
2470 mmix_gen_compare_reg (RTX_CODE code
, rtx x
, rtx y
)
2472 enum machine_mode ccmode
= SELECT_CC_MODE (code
, x
, y
);
2473 return gen_reg_rtx (ccmode
);
2476 /* Local (static) helper functions. */
2479 mmix_emit_sp_add (HOST_WIDE_INT offset
)
2485 /* Negative stack-pointer adjustments are allocations and appear in
2486 the prologue only. We mark them as frame-related so unwind and
2487 debug info is properly emitted for them. */
2489 insn
= emit_insn (gen_adddi3 (stack_pointer_rtx
,
2494 rtx tmpr
= gen_rtx_REG (DImode
, 255);
2495 RTX_FRAME_RELATED_P (emit_move_insn (tmpr
, GEN_INT (offset
))) = 1;
2496 insn
= emit_insn (gen_adddi3 (stack_pointer_rtx
,
2497 stack_pointer_rtx
, tmpr
));
2499 RTX_FRAME_RELATED_P (insn
) = 1;
2503 /* Positive adjustments are in the epilogue only. Don't mark them
2504 as "frame-related" for unwind info. */
2505 if (CONST_OK_FOR_LETTER_P (offset
, 'L'))
2506 emit_insn (gen_adddi3 (stack_pointer_rtx
,
2511 rtx tmpr
= gen_rtx_REG (DImode
, 255);
2512 emit_move_insn (tmpr
, GEN_INT (offset
));
2513 insn
= emit_insn (gen_adddi3 (stack_pointer_rtx
,
2514 stack_pointer_rtx
, tmpr
));
2519 /* Print operator suitable for doing something with a shiftable
2520 wyde. The type of operator is passed as an asm output modifier. */
2523 mmix_output_shiftvalue_op_from_str (FILE *stream
,
2525 HOST_WIDEST_INT value
)
2527 static const char *const op_part
[] = {"L", "ML", "MH", "H"};
2530 if (! mmix_shiftable_wyde_value (value
))
2532 char s
[sizeof ("0xffffffffffffffff")];
2533 sprintf (s
, HOST_WIDEST_INT_PRINT_HEX
, value
);
2534 internal_error ("MMIX Internal: %s is not a shiftable int", s
);
2537 for (i
= 0; i
< 4; i
++)
2539 /* We know we're through when we find one-bits in the low
2543 fprintf (stream
, "%s%s", mainop
, op_part
[i
]);
2549 /* No bits set? Then it must have been zero. */
2550 fprintf (stream
, "%sL", mainop
);
2553 /* Print a 64-bit value, optionally prefixed by assembly pseudo. */
2556 mmix_output_octa (FILE *stream
, HOST_WIDEST_INT value
, int do_begin_end
)
2558 /* Snipped from final.c:output_addr_const. We need to avoid the
2559 presumed universal "0x" prefix. We can do it by replacing "0x" with
2560 "#0" here; we must avoid a space in the operands and no, the zero
2561 won't cause the number to be assumed in octal format. */
2562 char hex_format
[sizeof (HOST_WIDEST_INT_PRINT_HEX
)];
2565 fprintf (stream
, "\tOCTA ");
2567 strcpy (hex_format
, HOST_WIDEST_INT_PRINT_HEX
);
2568 hex_format
[0] = '#';
2569 hex_format
[1] = '0';
2571 /* Provide a few alternative output formats depending on the number, to
2572 improve legibility of assembler output. */
2573 if ((value
< (HOST_WIDEST_INT
) 0 && value
> (HOST_WIDEST_INT
) -10000)
2574 || (value
>= (HOST_WIDEST_INT
) 0 && value
<= (HOST_WIDEST_INT
) 16384))
2575 fprintf (stream
, "%d", (int) value
);
2576 else if (value
> (HOST_WIDEST_INT
) 0
2577 && value
< ((HOST_WIDEST_INT
) 1 << 31) * 2)
2578 fprintf (stream
, "#%x", (unsigned int) value
);
2580 fprintf (stream
, hex_format
, value
);
2583 fprintf (stream
, "\n");
2586 /* Print the presumed shiftable wyde argument shifted into place (to
2587 be output with an operand). */
2590 mmix_output_shifted_value (FILE *stream
, HOST_WIDEST_INT value
)
2594 if (! mmix_shiftable_wyde_value (value
))
2597 sprintf (s
, HOST_WIDEST_INT_PRINT_HEX
, value
);
2598 internal_error ("MMIX Internal: %s is not a shiftable int", s
);
2601 for (i
= 0; i
< 4; i
++)
2603 /* We know we're through when we find one-bits in the low 16 bits. */
2606 fprintf (stream
, "#%x", (int) (value
& 0xffff));
2613 /* No bits set? Then it must have been zero. */
2614 fprintf (stream
, "0");
2617 /* Output an MMIX condition name corresponding to an operator
2619 (comparison_operator [(comparison_operator ...) (const_int 0)])
2620 which means we have to look at *two* operators.
2622 The argument "reversed" refers to reversal of the condition (not the
2623 same as swapping the arguments). */
2626 mmix_output_condition (FILE *stream
, rtx x
, int reversed
)
2632 /* The normal output cc-code. */
2633 const char *const normal
;
2635 /* The reversed cc-code, or NULL if invalid. */
2636 const char *const reversed
;
2641 enum machine_mode cc_mode
;
2643 /* Terminated with {UNKNOWN, NULL, NULL} */
2644 const struct cc_conv
*const convs
;
2648 #define CCEND {UNKNOWN, NULL, NULL}
2650 static const struct cc_conv cc_fun_convs
[]
2651 = {{ORDERED
, "Z", "P"},
2652 {UNORDERED
, "P", "Z"},
2654 static const struct cc_conv cc_fp_convs
[]
2658 static const struct cc_conv cc_fpeq_convs
[]
2662 static const struct cc_conv cc_uns_convs
[]
2663 = {{GEU
, "NN", "N"},
2668 static const struct cc_conv cc_signed_convs
[]
2676 static const struct cc_conv cc_di_convs
[]
2688 static const struct cc_type_conv cc_convs
[]
2689 = {{CC_FUNmode
, cc_fun_convs
},
2690 {CC_FPmode
, cc_fp_convs
},
2691 {CC_FPEQmode
, cc_fpeq_convs
},
2692 {CC_UNSmode
, cc_uns_convs
},
2693 {CCmode
, cc_signed_convs
},
2694 {DImode
, cc_di_convs
}};
2699 enum machine_mode mode
= GET_MODE (XEXP (x
, 0));
2700 RTX_CODE cc
= GET_CODE (x
);
2702 for (i
= 0; i
< ARRAY_SIZE (cc_convs
); i
++)
2704 if (mode
== cc_convs
[i
].cc_mode
)
2706 for (j
= 0; cc_convs
[i
].convs
[j
].cc
!= UNKNOWN
; j
++)
2707 if (cc
== cc_convs
[i
].convs
[j
].cc
)
2710 = (reversed
? cc_convs
[i
].convs
[j
].reversed
2711 : cc_convs
[i
].convs
[j
].normal
);
2713 if (mmix_cc
== NULL
)
2714 fatal_insn ("MMIX Internal: Trying to output invalidly\
2715 reversed condition:", x
);
2717 fprintf (stream
, "%s", mmix_cc
);
2721 fatal_insn ("MMIX Internal: What's the CC of this?", x
);
2725 fatal_insn ("MMIX Internal: What is the CC of this?", x
);
2728 /* Return the bit-value for a const_int or const_double. */
2730 static HOST_WIDEST_INT
2733 unsigned HOST_WIDEST_INT retval
;
2735 if (GET_CODE (x
) == CONST_INT
)
2738 /* We make a little song and dance because converting to long long in
2739 gcc-2.7.2 is broken. I still want people to be able to use it for
2740 cross-compilation to MMIX. */
2741 if (GET_CODE (x
) == CONST_DOUBLE
&& GET_MODE (x
) == VOIDmode
)
2743 if (sizeof (HOST_WIDE_INT
) < sizeof (HOST_WIDEST_INT
))
2745 retval
= (unsigned) CONST_DOUBLE_LOW (x
) / 2;
2747 retval
|= CONST_DOUBLE_LOW (x
) & 1;
2750 (unsigned HOST_WIDEST_INT
) CONST_DOUBLE_HIGH (x
)
2751 << (HOST_BITS_PER_LONG
);
2754 retval
= CONST_DOUBLE_HIGH (x
);
2759 if (GET_CODE (x
) == CONST_DOUBLE
)
2761 REAL_VALUE_TYPE value
;
2763 /* FIXME: This macro is not in the manual but should be. */
2764 REAL_VALUE_FROM_CONST_DOUBLE (value
, x
);
2766 if (GET_MODE (x
) == DFmode
)
2770 REAL_VALUE_TO_TARGET_DOUBLE (value
, bits
);
2772 /* The double cast is necessary to avoid getting the long
2773 sign-extended to unsigned long long(!) when they're of
2774 different size (usually 32-bit hosts). */
2776 ((unsigned HOST_WIDEST_INT
) (unsigned long) bits
[0]
2777 << (unsigned HOST_WIDEST_INT
) 32U)
2778 | (unsigned HOST_WIDEST_INT
) (unsigned long) bits
[1];
2780 else if (GET_MODE (x
) == SFmode
)
2783 REAL_VALUE_TO_TARGET_SINGLE (value
, bits
);
2785 return (unsigned long) bits
;
2789 fatal_insn ("MMIX Internal: This is not a constant:", x
);
2792 /* Worker function for TARGET_PROMOTE_FUNCTION_MODE. */
2795 mmix_promote_function_mode (const_tree type ATTRIBUTE_UNUSED
,
2796 enum machine_mode mode
,
2797 int *punsignedp ATTRIBUTE_UNUSED
,
2798 const_tree fntype ATTRIBUTE_UNUSED
,
2801 /* Apparently not doing TRT if int < register-size. FIXME: Perhaps
2802 FUNCTION_VALUE and LIBCALL_VALUE needs tweaking as some ports say. */
2803 if (for_return
== 1)
2806 /* Promotion of modes currently generates slow code, extending before
2807 operation, so we do it only for arguments. */
2808 if (GET_MODE_CLASS (mode
) == MODE_INT
2809 && GET_MODE_SIZE (mode
) < 8)
2814 /* Worker function for TARGET_STRUCT_VALUE_RTX. */
2817 mmix_struct_value_rtx (tree fntype ATTRIBUTE_UNUSED
,
2818 int incoming ATTRIBUTE_UNUSED
)
2820 return gen_rtx_REG (Pmode
, MMIX_STRUCT_VALUE_REGNUM
);
2823 /* Worker function for TARGET_FRAME_POINTER_REQUIRED.
2825 FIXME: Is this requirement built-in? Anyway, we should try to get rid
2826 of it; we can deduce the value. */
2829 mmix_frame_pointer_required (void)
2831 return (cfun
->has_nonlocal_label
);
2836 * eval: (c-set-style "gnu")
2837 * indent-tabs-mode: t