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"
44 #include "integrate.h"
46 #include "target-def.h"
49 /* First some local helper definitions. */
50 #define MMIX_FIRST_GLOBAL_REGNUM 32
52 /* We'd need a current_function_has_landing_pad. It's marked as such when
53 a nonlocal_goto_receiver is expanded. Not just a C++ thing, but
55 #define MMIX_CFUN_HAS_LANDING_PAD (cfun->machine->has_landing_pad != 0)
57 /* We have no means to tell DWARF 2 about the register stack, so we need
58 to store the return address on the stack if an exception can get into
59 this function. FIXME: Narrow condition. Before any whole-function
60 analysis, df_regs_ever_live_p () isn't initialized. We know it's up-to-date
61 after reload_completed; it may contain incorrect information some time
62 before that. Within a RTL sequence (after a call to start_sequence,
63 such as in RTL expanders), leaf_function_p doesn't see all insns
64 (perhaps any insn). But regs_ever_live is up-to-date when
65 leaf_function_p () isn't, so we "or" them together to get accurate
66 information. FIXME: Some tweak to leaf_function_p might be
68 #define MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS \
70 && ((reload_completed && df_regs_ever_live_p (MMIX_rJ_REGNUM)) \
71 || !leaf_function_p ()))
73 #define IS_MMIX_EH_RETURN_DATA_REG(REGNO) \
74 (crtl->calls_eh_return \
75 && (EH_RETURN_DATA_REGNO (0) == REGNO \
76 || EH_RETURN_DATA_REGNO (1) == REGNO \
77 || EH_RETURN_DATA_REGNO (2) == REGNO \
78 || EH_RETURN_DATA_REGNO (3) == REGNO))
80 /* For the default ABI, we rename registers at output-time to fill the gap
81 between the (statically partitioned) saved registers and call-clobbered
82 registers. In effect this makes unused call-saved registers to be used
83 as call-clobbered registers. The benefit comes from keeping the number
84 of local registers (value of rL) low, since there's a cost of
85 increasing rL and clearing unused (unset) registers with lower numbers.
86 Don't translate while outputting the prologue. */
87 #define MMIX_OUTPUT_REGNO(N) \
89 || (int) (N) < MMIX_RETURN_VALUE_REGNUM \
90 || (int) (N) > MMIX_LAST_STACK_REGISTER_REGNUM \
92 || cfun->machine == NULL \
93 || cfun->machine->in_prologue \
94 ? (N) : ((N) - MMIX_RETURN_VALUE_REGNUM \
95 + cfun->machine->highest_saved_stack_register + 1))
97 /* The %d in "POP %d,0". */
98 #define MMIX_POP_ARGUMENT() \
100 && crtl->return_rtx != NULL \
101 && ! cfun->returns_struct) \
102 ? (GET_CODE (crtl->return_rtx) == PARALLEL \
103 ? GET_NUM_ELEM (XVEC (crtl->return_rtx, 0)) : 1) \
106 /* The canonical saved comparison operands for non-cc0 machines, set in
107 the compare expander. */
108 rtx mmix_compare_op0;
109 rtx mmix_compare_op1;
111 /* Declarations of locals. */
113 /* Intermediate for insn output. */
114 static int mmix_output_destination_register;
116 static void mmix_option_override (void);
117 static void mmix_asm_output_source_filename (FILE *, const char *);
118 static void mmix_output_shiftvalue_op_from_str
119 (FILE *, const char *, HOST_WIDEST_INT);
120 static void mmix_output_shifted_value (FILE *, HOST_WIDEST_INT);
121 static void mmix_output_condition (FILE *, rtx, int);
122 static HOST_WIDEST_INT mmix_intval (rtx);
123 static void mmix_output_octa (FILE *, HOST_WIDEST_INT, int);
124 static bool mmix_assemble_integer (rtx, unsigned int, int);
125 static struct machine_function *mmix_init_machine_status (void);
126 static void mmix_encode_section_info (tree, rtx, int);
127 static const char *mmix_strip_name_encoding (const char *);
128 static void mmix_emit_sp_add (HOST_WIDE_INT offset);
129 static void mmix_target_asm_function_prologue (FILE *, HOST_WIDE_INT);
130 static void mmix_target_asm_function_end_prologue (FILE *);
131 static void mmix_target_asm_function_epilogue (FILE *, HOST_WIDE_INT);
132 static bool mmix_legitimate_address_p (enum machine_mode, rtx, bool);
133 static bool mmix_legitimate_constant_p (enum machine_mode, rtx);
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
256 #undef TARGET_LEGITIMATE_CONSTANT_P
257 #define TARGET_LEGITIMATE_CONSTANT_P mmix_legitimate_constant_p
259 #undef TARGET_FRAME_POINTER_REQUIRED
260 #define TARGET_FRAME_POINTER_REQUIRED mmix_frame_pointer_required
262 #undef TARGET_ASM_TRAMPOLINE_TEMPLATE
263 #define TARGET_ASM_TRAMPOLINE_TEMPLATE mmix_asm_trampoline_template
264 #undef TARGET_TRAMPOLINE_INIT
265 #define TARGET_TRAMPOLINE_INIT mmix_trampoline_init
267 #undef TARGET_OPTION_OVERRIDE
268 #define TARGET_OPTION_OVERRIDE mmix_option_override
269 #undef TARGET_OPTION_OPTIMIZATION_TABLE
270 #define TARGET_OPTION_OPTIMIZATION_TABLE mmix_option_optimization_table
272 struct gcc_target targetm = TARGET_INITIALIZER;
274 /* Functions that are expansions for target macros.
275 See Target Macros in `Using and Porting GCC'. */
277 /* TARGET_OPTION_OVERRIDE. */
280 mmix_option_override (void)
282 /* Should we err or should we warn? Hmm. At least we must neutralize
283 it. For example the wrong kind of case-tables will be generated with
284 PIC; we use absolute address items for mmixal compatibility. FIXME:
285 They could be relative if we just elide them to after all pertinent
289 warning (0, "-f%s not supported: ignored", (flag_pic > 1) ? "PIC" : "pic");
294 /* INIT_EXPANDERS. */
297 mmix_init_expanders (void)
299 init_machine_status = mmix_init_machine_status;
302 /* Set the per-function data. */
304 static struct machine_function *
305 mmix_init_machine_status (void)
307 return ggc_alloc_cleared_machine_function ();
311 We have trouble getting the address of stuff that is located at other
312 than 32-bit alignments (GETA requirements), so try to give everything
313 at least 32-bit alignment. */
316 mmix_data_alignment (tree type ATTRIBUTE_UNUSED, int basic_align)
318 if (basic_align < 32)
324 /* CONSTANT_ALIGNMENT. */
327 mmix_constant_alignment (tree constant ATTRIBUTE_UNUSED, int basic_align)
329 if (basic_align < 32)
335 /* LOCAL_ALIGNMENT. */
338 mmix_local_alignment (tree type ATTRIBUTE_UNUSED, unsigned basic_align)
340 if (basic_align < 32)
346 /* TARGET_CONDITIONAL_REGISTER_USAGE. */
349 mmix_conditional_register_usage (void)
355 static const int gnu_abi_reg_alloc_order[]
356 = MMIX_GNU_ABI_REG_ALLOC_ORDER;
358 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
359 reg_alloc_order[i] = gnu_abi_reg_alloc_order[i];
361 /* Change the default from the mmixware ABI. For the GNU ABI,
362 $15..$30 are call-saved just as $0..$14. There must be one
363 call-clobbered local register for the "hole" that holds the
364 number of saved local registers saved by PUSHJ/PUSHGO during the
365 function call, receiving the return value at return. So best is
366 to use the highest, $31. It's already marked call-clobbered for
368 for (i = 15; i <= 30; i++)
369 call_used_regs[i] = 0;
371 /* "Unfix" the parameter registers. */
372 for (i = MMIX_RESERVED_GNU_ARG_0_REGNUM;
373 i < MMIX_RESERVED_GNU_ARG_0_REGNUM + MMIX_MAX_ARGS_IN_REGS;
378 /* Step over the ":" in special register names. */
379 if (! TARGET_TOPLEVEL_SYMBOLS)
380 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
381 if (reg_names[i][0] == ':')
385 /* INCOMING_REGNO and OUTGOING_REGNO worker function.
386 Those two macros must only be applied to function argument
387 registers. FIXME: for their current use in gcc, it'd be better
388 with an explicit specific additional FUNCTION_INCOMING_ARG_REGNO_P
389 a'la TARGET_FUNCTION_ARG / TARGET_FUNCTION_INCOMING_ARG instead of
390 forcing the target to commit to a fixed mapping and for any
391 unspecified register use. */
394 mmix_opposite_regno (int regno, int incoming)
396 if (!mmix_function_arg_regno_p (regno, incoming))
401 ? MMIX_FIRST_INCOMING_ARG_REGNUM - MMIX_FIRST_ARG_REGNUM
402 : MMIX_FIRST_ARG_REGNUM - MMIX_FIRST_INCOMING_ARG_REGNUM);
406 All registers that are part of the register stack and that will be
410 mmix_local_regno (int regno)
412 return regno <= MMIX_LAST_STACK_REGISTER_REGNUM && !call_used_regs[regno];
415 /* PREFERRED_RELOAD_CLASS.
416 We need to extend the reload class of REMAINDER_REG and HIMULT_REG. */
419 mmix_preferred_reload_class (rtx x ATTRIBUTE_UNUSED, enum reg_class rclass)
421 /* FIXME: Revisit. */
422 return GET_CODE (x) == MOD && GET_MODE (x) == DImode
423 ? REMAINDER_REG : rclass;
426 /* PREFERRED_OUTPUT_RELOAD_CLASS.
427 We need to extend the reload class of REMAINDER_REG and HIMULT_REG. */
430 mmix_preferred_output_reload_class (rtx x ATTRIBUTE_UNUSED,
431 enum reg_class rclass)
433 /* FIXME: Revisit. */
434 return GET_CODE (x) == MOD && GET_MODE (x) == DImode
435 ? REMAINDER_REG : rclass;
438 /* SECONDARY_RELOAD_CLASS.
439 We need to reload regs of REMAINDER_REG and HIMULT_REG elsewhere. */
442 mmix_secondary_reload_class (enum reg_class rclass,
443 enum machine_mode mode ATTRIBUTE_UNUSED,
444 rtx x ATTRIBUTE_UNUSED,
445 int in_p ATTRIBUTE_UNUSED)
447 if (rclass == REMAINDER_REG
448 || rclass == HIMULT_REG
449 || rclass == SYSTEM_REGS)
455 /* CONST_OK_FOR_LETTER_P. */
458 mmix_const_ok_for_letter_p (HOST_WIDE_INT value, int c)
461 (c == 'I' ? value >= 0 && value <= 255
462 : c == 'J' ? value >= 0 && value <= 65535
463 : c == 'K' ? value <= 0 && value >= -255
464 : c == 'L' ? mmix_shiftable_wyde_value (value)
465 : c == 'M' ? value == 0
466 : c == 'N' ? mmix_shiftable_wyde_value (~value)
467 : c == 'O' ? (value == 3 || value == 5 || value == 9
472 /* CONST_DOUBLE_OK_FOR_LETTER_P. */
475 mmix_const_double_ok_for_letter_p (rtx value, int c)
478 (c == 'G' ? value == CONST0_RTX (GET_MODE (value))
483 We need this since our constants are not always expressible as
484 CONST_INT:s, but rather often as CONST_DOUBLE:s. */
487 mmix_extra_constraint (rtx x, int c, int strict)
489 HOST_WIDEST_INT value;
491 /* When checking for an address, we need to handle strict vs. non-strict
492 register checks. Don't use address_operand, but instead its
493 equivalent (its callee, which it is just a wrapper for),
494 memory_operand_p and the strict-equivalent strict_memory_address_p. */
498 ? strict_memory_address_p (Pmode, x)
499 : memory_address_p (Pmode, x);
501 /* R asks whether x is to be loaded with GETA or something else. Right
502 now, only a SYMBOL_REF and LABEL_REF can fit for
503 TARGET_BASE_ADDRESSES.
505 Only constant symbolic addresses apply. With TARGET_BASE_ADDRESSES,
506 we just allow straight LABEL_REF or SYMBOL_REFs with SYMBOL_REF_FLAG
507 set right now; only function addresses and code labels. If we change
508 to let SYMBOL_REF_FLAG be set on other symbols, we have to check
509 inside CONST expressions. When TARGET_BASE_ADDRESSES is not in
510 effect, a "raw" constant check together with mmix_constant_address_p
511 is all that's needed; we want all constant addresses to be loaded
515 GET_CODE (x) != CONST_INT && GET_CODE (x) != CONST_DOUBLE
516 && mmix_constant_address_p (x)
517 && (! TARGET_BASE_ADDRESSES
518 || (GET_CODE (x) == LABEL_REF
519 || (GET_CODE (x) == SYMBOL_REF && SYMBOL_REF_FLAG (x))));
521 if (GET_CODE (x) != CONST_DOUBLE || GET_MODE (x) != VOIDmode)
524 value = mmix_intval (x);
526 /* We used to map Q->J, R->K, S->L, T->N, U->O, but we don't have to any
527 more ('U' taken for address_operand, 'R' similarly). Some letters map
528 outside of CONST_INT, though; we still use 'S' and 'T'. */
530 return mmix_shiftable_wyde_value (value);
532 return mmix_shiftable_wyde_value (~value);
536 /* DYNAMIC_CHAIN_ADDRESS. */
539 mmix_dynamic_chain_address (rtx frame)
541 /* FIXME: the frame-pointer is stored at offset -8 from the current
542 frame-pointer. Unfortunately, the caller assumes that a
543 frame-pointer is present for *all* previous frames. There should be
544 a way to say that that cannot be done, like for RETURN_ADDR_RTX. */
545 return plus_constant (frame, -8);
548 /* STARTING_FRAME_OFFSET. */
551 mmix_starting_frame_offset (void)
553 /* The old frame pointer is in the slot below the new one, so
554 FIRST_PARM_OFFSET does not need to depend on whether the
555 frame-pointer is needed or not. We have to adjust for the register
556 stack pointer being located below the saved frame pointer.
557 Similarly, we store the return address on the stack too, for
558 exception handling, and always if we save the register stack pointer. */
561 + (MMIX_CFUN_HAS_LANDING_PAD
562 ? -16 : (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS ? -8 : 0)));
565 /* RETURN_ADDR_RTX. */
568 mmix_return_addr_rtx (int count, rtx frame ATTRIBUTE_UNUSED)
571 ? (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
572 /* FIXME: Set frame_alias_set on the following. (Why?)
573 See mmix_initial_elimination_offset for the reason we can't use
574 get_hard_reg_initial_val for both. Always using a stack slot
575 and not a register would be suboptimal. */
576 ? validize_mem (gen_rtx_MEM (Pmode, plus_constant (frame_pointer_rtx, -16)))
577 : get_hard_reg_initial_val (Pmode, MMIX_INCOMING_RETURN_ADDRESS_REGNUM))
581 /* SETUP_FRAME_ADDRESSES. */
584 mmix_setup_frame_addresses (void)
586 /* Nothing needed at the moment. */
589 /* The difference between the (imaginary) frame pointer and the stack
590 pointer. Used to eliminate the frame pointer. */
593 mmix_initial_elimination_offset (int fromreg, int toreg)
597 = (get_frame_size () + crtl->outgoing_args_size + 7) & ~7;
599 /* There is no actual offset between these two virtual values, but for
600 the frame-pointer, we have the old one in the stack position below
601 it, so the offset for the frame-pointer to the stack-pointer is one
603 if (fromreg == MMIX_ARG_POINTER_REGNUM
604 && toreg == MMIX_FRAME_POINTER_REGNUM)
607 /* The difference is the size of local variables plus the size of
608 outgoing function arguments that would normally be passed as
609 registers but must be passed on stack because we're out of
610 function-argument registers. Only global saved registers are
611 counted; the others go on the register stack.
613 The frame-pointer is counted too if it is what is eliminated, as we
614 need to balance the offset for it from STARTING_FRAME_OFFSET.
616 Also add in the slot for the register stack pointer we save if we
619 Unfortunately, we can't access $0..$14, from unwinder code easily, so
620 store the return address in a frame slot too. FIXME: Only for
621 non-leaf functions. FIXME: Always with a landing pad, because it's
622 hard to know whether we need the other at the time we know we need
623 the offset for one (and have to state it). It's a kludge until we
624 can express the register stack in the EH frame info.
626 We have to do alignment here; get_frame_size will not return a
627 multiple of STACK_BOUNDARY. FIXME: Add note in manual. */
629 for (regno = MMIX_FIRST_GLOBAL_REGNUM;
632 if ((df_regs_ever_live_p (regno) && ! call_used_regs[regno])
633 || IS_MMIX_EH_RETURN_DATA_REG (regno))
637 + (MMIX_CFUN_HAS_LANDING_PAD
638 ? 16 : (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS ? 8 : 0))
639 + (fromreg == MMIX_ARG_POINTER_REGNUM ? 0 : 8);
643 mmix_function_arg_advance (CUMULATIVE_ARGS *argsp, enum machine_mode mode,
644 const_tree type, bool named ATTRIBUTE_UNUSED)
646 int arg_size = MMIX_FUNCTION_ARG_SIZE (mode, type);
648 argsp->regs = ((targetm.calls.must_pass_in_stack (mode, type)
652 ? (MMIX_MAX_ARGS_IN_REGS) + 1
653 : argsp->regs + (7 + arg_size) / 8);
656 /* Helper function for mmix_function_arg and mmix_function_incoming_arg. */
659 mmix_function_arg_1 (const CUMULATIVE_ARGS *argsp,
660 enum machine_mode mode,
662 bool named ATTRIBUTE_UNUSED,
665 /* Last-argument marker. */
666 if (type == void_type_node)
667 return (argsp->regs < MMIX_MAX_ARGS_IN_REGS)
670 ? MMIX_FIRST_INCOMING_ARG_REGNUM
671 : MMIX_FIRST_ARG_REGNUM) + argsp->regs)
674 return (argsp->regs < MMIX_MAX_ARGS_IN_REGS
675 && !targetm.calls.must_pass_in_stack (mode, type)
676 && (GET_MODE_BITSIZE (mode) <= 64
681 ? MMIX_FIRST_INCOMING_ARG_REGNUM
682 : MMIX_FIRST_ARG_REGNUM)
687 /* Return an rtx for a function argument to go in a register, and 0 for
688 one that must go on stack. */
691 mmix_function_arg (CUMULATIVE_ARGS *argsp,
692 enum machine_mode mode,
696 return mmix_function_arg_1 (argsp, mode, type, named, false);
700 mmix_function_incoming_arg (CUMULATIVE_ARGS *argsp,
701 enum machine_mode mode,
705 return mmix_function_arg_1 (argsp, mode, type, named, true);
708 /* Returns nonzero for everything that goes by reference, 0 for
709 everything that goes by value. */
712 mmix_pass_by_reference (CUMULATIVE_ARGS *argsp, enum machine_mode mode,
713 const_tree type, bool named ATTRIBUTE_UNUSED)
715 /* FIXME: Check: I'm not sure the must_pass_in_stack check is
717 if (targetm.calls.must_pass_in_stack (mode, type))
720 if (MMIX_FUNCTION_ARG_SIZE (mode, type) > 8
722 && (!argsp || !argsp->lib))
728 /* Return nonzero if regno is a register number where a parameter is
729 passed, and 0 otherwise. */
732 mmix_function_arg_regno_p (int regno, int incoming)
735 = incoming ? MMIX_FIRST_INCOMING_ARG_REGNUM : MMIX_FIRST_ARG_REGNUM;
737 return regno >= first_arg_regnum
738 && regno < first_arg_regnum + MMIX_MAX_ARGS_IN_REGS;
741 /* Implements TARGET_FUNCTION_VALUE. */
744 mmix_function_value (const_tree valtype,
745 const_tree func ATTRIBUTE_UNUSED,
748 enum machine_mode mode = TYPE_MODE (valtype);
749 enum machine_mode cmode;
750 int first_val_regnum = MMIX_OUTGOING_RETURN_VALUE_REGNUM;
751 rtx vec[MMIX_MAX_REGS_FOR_VALUE];
756 return gen_rtx_REG (mode, MMIX_RETURN_VALUE_REGNUM);
758 /* Return values that fit in a register need no special handling.
759 There's no register hole when parameters are passed in global
762 || GET_MODE_BITSIZE (mode) <= BITS_PER_WORD)
764 gen_rtx_REG (mode, MMIX_OUTGOING_RETURN_VALUE_REGNUM);
766 if (COMPLEX_MODE_P (mode))
767 /* A complex type, made up of components. */
768 cmode = TYPE_MODE (TREE_TYPE (valtype));
771 /* Of the other larger-than-register modes, we only support
772 scalar mode TImode. (At least, that's the only one that's
773 been rudimentally tested.) Make sure we're alerted for
776 sorry ("support for mode %qs", GET_MODE_NAME (mode));
778 /* In any case, we will fill registers to the natural size. */
782 nregs = ((GET_MODE_BITSIZE (mode) + BITS_PER_WORD - 1) / BITS_PER_WORD);
784 /* We need to take care of the effect of the register hole on return
785 values of large sizes; the last register will appear as the first
786 register, with the rest shifted. (For complex modes, this is just
787 swapped registers.) */
789 if (nregs > MMIX_MAX_REGS_FOR_VALUE)
790 internal_error ("too large function value type, needs %d registers,\
791 have only %d registers for this", nregs, MMIX_MAX_REGS_FOR_VALUE);
793 /* FIXME: Maybe we should handle structure values like this too
794 (adjusted for BLKmode), perhaps for both ABI:s. */
795 for (i = 0; i < nregs - 1; i++)
797 = gen_rtx_EXPR_LIST (VOIDmode,
798 gen_rtx_REG (cmode, first_val_regnum + i),
799 GEN_INT ((i + 1) * BITS_PER_UNIT));
802 = gen_rtx_EXPR_LIST (VOIDmode,
803 gen_rtx_REG (cmode, first_val_regnum + nregs - 1),
806 return gen_rtx_PARALLEL (VOIDmode, gen_rtvec_v (nregs, vec));
809 /* Implements TARGET_LIBCALL_VALUE. */
812 mmix_libcall_value (enum machine_mode mode,
813 const_rtx fun ATTRIBUTE_UNUSED)
815 return gen_rtx_REG (mode, MMIX_RETURN_VALUE_REGNUM);
818 /* Implements TARGET_FUNCTION_VALUE_REGNO_P. */
821 mmix_function_value_regno_p (const unsigned int regno)
823 return regno == MMIX_RETURN_VALUE_REGNUM;
826 /* EH_RETURN_DATA_REGNO. */
829 mmix_eh_return_data_regno (int n)
832 return MMIX_EH_RETURN_DATA_REGNO_START + n;
834 return INVALID_REGNUM;
837 /* EH_RETURN_STACKADJ_RTX. */
840 mmix_eh_return_stackadj_rtx (void)
842 return gen_rtx_REG (Pmode, MMIX_EH_RETURN_STACKADJ_REGNUM);
845 /* EH_RETURN_HANDLER_RTX. */
848 mmix_eh_return_handler_rtx (void)
850 return gen_rtx_REG (Pmode, MMIX_INCOMING_RETURN_ADDRESS_REGNUM);
853 /* ASM_PREFERRED_EH_DATA_FORMAT. */
856 mmix_asm_preferred_eh_data_format (int code ATTRIBUTE_UNUSED,
857 int global ATTRIBUTE_UNUSED)
859 /* This is the default (was at 2001-07-20). Revisit when needed. */
860 return DW_EH_PE_absptr;
863 /* Make a note that we've seen the beginning of the prologue. This
864 matters to whether we'll translate register numbers as calculated by
868 mmix_target_asm_function_prologue (FILE *stream ATTRIBUTE_UNUSED,
869 HOST_WIDE_INT framesize ATTRIBUTE_UNUSED)
871 cfun->machine->in_prologue = 1;
874 /* Make a note that we've seen the end of the prologue. */
877 mmix_target_asm_function_end_prologue (FILE *stream ATTRIBUTE_UNUSED)
879 cfun->machine->in_prologue = 0;
882 /* Implement TARGET_MACHINE_DEPENDENT_REORG. No actual rearrangements
883 done here; just virtually by calculating the highest saved stack
884 register number used to modify the register numbers at output time. */
891 /* We put the number of the highest saved register-file register in a
892 location convenient for the call-patterns to output. Note that we
893 don't tell dwarf2 about these registers, since it can't restore them
895 for (regno = MMIX_LAST_STACK_REGISTER_REGNUM;
898 if ((df_regs_ever_live_p (regno) && !call_used_regs[regno])
899 || (regno == MMIX_FRAME_POINTER_REGNUM && frame_pointer_needed))
902 /* Regardless of whether they're saved (they might be just read), we
903 mustn't include registers that carry parameters. We could scan the
904 insns to see whether they're actually used (and indeed do other less
905 trivial register usage analysis and transformations), but it seems
906 wasteful to optimize for unused parameter registers. As of
907 2002-04-30, df_regs_ever_live_p (n) seems to be set for only-reads too, but
908 that might change. */
909 if (!TARGET_ABI_GNU && regno < crtl->args.info.regs - 1)
911 regno = crtl->args.info.regs - 1;
913 /* We don't want to let this cause us to go over the limit and make
914 incoming parameter registers be misnumbered and treating the last
915 parameter register and incoming return value register call-saved.
916 Stop things at the unmodified scheme. */
917 if (regno > MMIX_RETURN_VALUE_REGNUM - 1)
918 regno = MMIX_RETURN_VALUE_REGNUM - 1;
921 cfun->machine->highest_saved_stack_register = regno;
924 /* TARGET_ASM_FUNCTION_EPILOGUE. */
927 mmix_target_asm_function_epilogue (FILE *stream,
928 HOST_WIDE_INT locals_size ATTRIBUTE_UNUSED)
930 /* Emit an \n for readability of the generated assembly. */
931 fputc ('\n', stream);
934 /* TARGET_ASM_OUTPUT_MI_THUNK. */
937 mmix_asm_output_mi_thunk (FILE *stream,
938 tree fndecl ATTRIBUTE_UNUSED,
940 HOST_WIDE_INT vcall_offset ATTRIBUTE_UNUSED,
943 /* If you define TARGET_STRUCT_VALUE_RTX that returns 0 (i.e. pass
944 location of structure to return as invisible first argument), you
945 need to tweak this code too. */
946 const char *regname = reg_names[MMIX_FIRST_INCOMING_ARG_REGNUM];
948 if (delta >= 0 && delta < 65536)
949 fprintf (stream, "\tINCL %s,%d\n", regname, (int)delta);
950 else if (delta < 0 && delta >= -255)
951 fprintf (stream, "\tSUBU %s,%s,%d\n", regname, regname, (int)-delta);
954 mmix_output_register_setting (stream, 255, delta, 1);
955 fprintf (stream, "\tADDU %s,%s,$255\n", regname, regname);
958 fprintf (stream, "\tJMP ");
959 assemble_name (stream, XSTR (XEXP (DECL_RTL (func), 0), 0));
960 fprintf (stream, "\n");
963 /* FUNCTION_PROFILER. */
966 mmix_function_profiler (FILE *stream ATTRIBUTE_UNUSED,
967 int labelno ATTRIBUTE_UNUSED)
969 sorry ("function_profiler support for MMIX");
972 /* Worker function for TARGET_SETUP_INCOMING_VARARGS. For the moment,
973 let's stick to pushing argument registers on the stack. Later, we
974 can parse all arguments in registers, to improve performance. */
977 mmix_setup_incoming_varargs (CUMULATIVE_ARGS *args_so_farp,
978 enum machine_mode mode,
981 int second_time ATTRIBUTE_UNUSED)
983 /* The last named variable has been handled, but
984 args_so_farp has not been advanced for it. */
985 if (args_so_farp->regs + 1 < MMIX_MAX_ARGS_IN_REGS)
986 *pretend_sizep = (MMIX_MAX_ARGS_IN_REGS - (args_so_farp->regs + 1)) * 8;
988 /* We assume that one argument takes up one register here. That should
989 be true until we start messing with multi-reg parameters. */
990 if ((7 + (MMIX_FUNCTION_ARG_SIZE (mode, vartype))) / 8 != 1)
991 internal_error ("MMIX Internal: Last named vararg would not fit in a register");
994 /* TARGET_ASM_TRAMPOLINE_TEMPLATE. */
997 mmix_asm_trampoline_template (FILE *stream)
999 /* Read a value into the static-chain register and jump somewhere. The
1000 static chain is stored at offset 16, and the function address is
1001 stored at offset 24. */
1003 fprintf (stream, "\tGETA $255,1F\n\t");
1004 fprintf (stream, "LDOU %s,$255,0\n\t", reg_names[MMIX_STATIC_CHAIN_REGNUM]);
1005 fprintf (stream, "LDOU $255,$255,8\n\t");
1006 fprintf (stream, "GO $255,$255,0\n");
1007 fprintf (stream, "1H\tOCTA 0\n\t");
1008 fprintf (stream, "OCTA 0\n");
1011 /* TARGET_TRAMPOLINE_INIT. */
1012 /* Set the static chain and function pointer field in the trampoline.
1013 We also SYNCID here to be sure (doesn't matter in the simulator, but
1014 some day it will). */
1017 mmix_trampoline_init (rtx m_tramp, tree fndecl, rtx static_chain)
1019 rtx fnaddr = XEXP (DECL_RTL (fndecl), 0);
1022 emit_block_move (m_tramp, assemble_trampoline_template (),
1023 GEN_INT (2*UNITS_PER_WORD), BLOCK_OP_NORMAL);
1025 mem = adjust_address (m_tramp, DImode, 2*UNITS_PER_WORD);
1026 emit_move_insn (mem, static_chain);
1027 mem = adjust_address (m_tramp, DImode, 3*UNITS_PER_WORD);
1028 emit_move_insn (mem, fnaddr);
1030 mem = adjust_address (m_tramp, DImode, 0);
1031 emit_insn (gen_sync_icache (mem, GEN_INT (TRAMPOLINE_SIZE - 1)));
1034 /* We must exclude constant addresses that have an increment that is not a
1035 multiple of four bytes because of restrictions of the GETA
1036 instruction, unless TARGET_BASE_ADDRESSES. */
1039 mmix_constant_address_p (rtx x)
1041 RTX_CODE code = GET_CODE (x);
1043 /* When using "base addresses", anything constant goes. */
1044 int constant_ok = TARGET_BASE_ADDRESSES != 0;
1053 /* FIXME: Don't know how to dissect these. Avoid them for now,
1054 except we know they're constants. */
1058 addend = INTVAL (x);
1062 if (GET_MODE (x) != VOIDmode)
1063 /* Strange that we got here. FIXME: Check if we do. */
1065 addend = CONST_DOUBLE_LOW (x);
1069 /* Note that expressions with arithmetic on forward references don't
1070 work in mmixal. People using gcc assembly code with mmixal might
1071 need to move arrays and such to before the point of use. */
1072 if (GET_CODE (XEXP (x, 0)) == PLUS)
1074 rtx x0 = XEXP (XEXP (x, 0), 0);
1075 rtx x1 = XEXP (XEXP (x, 0), 1);
1077 if ((GET_CODE (x0) == SYMBOL_REF
1078 || GET_CODE (x0) == LABEL_REF)
1079 && (GET_CODE (x1) == CONST_INT
1080 || (GET_CODE (x1) == CONST_DOUBLE
1081 && GET_MODE (x1) == VOIDmode)))
1082 addend = mmix_intval (x1);
1094 return constant_ok || (addend & 3) == 0;
1097 /* Return 1 if the address is OK, otherwise 0. */
1100 mmix_legitimate_address_p (enum machine_mode mode ATTRIBUTE_UNUSED,
1102 bool strict_checking)
1104 #define MMIX_REG_OK(X) \
1106 && (REGNO (X) <= MMIX_LAST_GENERAL_REGISTER \
1107 || (reg_renumber[REGNO (X)] > 0 \
1108 && reg_renumber[REGNO (X)] <= MMIX_LAST_GENERAL_REGISTER))) \
1109 || (!strict_checking \
1110 && (REGNO (X) <= MMIX_LAST_GENERAL_REGISTER \
1111 || REGNO (X) >= FIRST_PSEUDO_REGISTER \
1112 || REGNO (X) == ARG_POINTER_REGNUM)))
1116 (mem (plus reg reg))
1117 (mem (plus reg 0..255)).
1118 unless TARGET_BASE_ADDRESSES, in which case we accept all
1119 (mem constant_address) too. */
1123 if (REG_P (x) && MMIX_REG_OK (x))
1126 if (GET_CODE(x) == PLUS)
1128 rtx x1 = XEXP (x, 0);
1129 rtx x2 = XEXP (x, 1);
1131 /* Try swapping the order. FIXME: Do we need this? */
1139 /* (mem (plus (reg?) (?))) */
1140 if (!REG_P (x1) || !MMIX_REG_OK (x1))
1141 return TARGET_BASE_ADDRESSES && mmix_constant_address_p (x);
1143 /* (mem (plus (reg) (reg?))) */
1144 if (REG_P (x2) && MMIX_REG_OK (x2))
1147 /* (mem (plus (reg) (0..255?))) */
1148 if (GET_CODE (x2) == CONST_INT
1149 && CONST_OK_FOR_LETTER_P (INTVAL (x2), 'I'))
1155 return TARGET_BASE_ADDRESSES && mmix_constant_address_p (x);
1158 /* Implement TARGET_LEGITIMATE_CONSTANT_P. */
1161 mmix_legitimate_constant_p (enum machine_mode mode ATTRIBUTE_UNUSED, rtx x)
1163 RTX_CODE code = GET_CODE (x);
1165 /* We must allow any number due to the way the cse passes works; if we
1166 do not allow any number here, general_operand will fail, and insns
1167 will fatally fail recognition instead of "softly". */
1168 if (code == CONST_INT || code == CONST_DOUBLE)
1171 return CONSTANT_ADDRESS_P (x);
1174 /* SELECT_CC_MODE. */
1177 mmix_select_cc_mode (RTX_CODE op, rtx x, rtx y ATTRIBUTE_UNUSED)
1179 /* We use CCmode, CC_UNSmode, CC_FPmode, CC_FPEQmode and CC_FUNmode to
1180 output different compare insns. Note that we do not check the
1181 validity of the comparison here. */
1183 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1185 if (op == ORDERED || op == UNORDERED || op == UNGE
1186 || op == UNGT || op == UNLE || op == UNLT)
1189 if (op == EQ || op == NE)
1195 if (op == GTU || op == LTU || op == GEU || op == LEU)
1201 /* REVERSIBLE_CC_MODE. */
1204 mmix_reversible_cc_mode (enum machine_mode mode)
1206 /* That is, all integer and the EQ, NE, ORDERED and UNORDERED float
1208 return mode != CC_FPmode;
1211 /* TARGET_RTX_COSTS. */
1214 mmix_rtx_costs (rtx x ATTRIBUTE_UNUSED,
1215 int code ATTRIBUTE_UNUSED,
1216 int outer_code ATTRIBUTE_UNUSED,
1217 int *total ATTRIBUTE_UNUSED,
1218 bool speed ATTRIBUTE_UNUSED)
1220 /* For the time being, this is just a stub and we'll accept the
1221 generic calculations, until we can do measurements, at least.
1222 Say we did not modify any calculated costs. */
1226 /* REGISTER_MOVE_COST. */
1229 mmix_register_move_cost (enum machine_mode mode ATTRIBUTE_UNUSED,
1230 enum reg_class from,
1233 return (from == GENERAL_REGS && from == to) ? 2 : 3;
1236 /* Note that we don't have a TEXT_SECTION_ASM_OP, because it has to be a
1237 compile-time constant; it's used in an asm in crtstuff.c, compiled for
1240 /* DATA_SECTION_ASM_OP. */
1243 mmix_data_section_asm_op (void)
1245 return "\t.data ! mmixal:= 8H LOC 9B";
1249 mmix_encode_section_info (tree decl, rtx rtl, int first)
1251 /* Test for an external declaration, and do nothing if it is one. */
1252 if ((TREE_CODE (decl) == VAR_DECL
1253 && (DECL_EXTERNAL (decl) || TREE_PUBLIC (decl)))
1254 || (TREE_CODE (decl) == FUNCTION_DECL && TREE_PUBLIC (decl)))
1256 else if (first && DECL_P (decl))
1258 /* For non-visible declarations, add a "@" prefix, which we skip
1259 when the label is output. If the label does not have this
1260 prefix, a ":" is output if -mtoplevel-symbols.
1262 Note that this does not work for data that is declared extern and
1263 later defined as static. If there's code in between, that code
1264 will refer to the extern declaration, and vice versa. This just
1265 means that when -mtoplevel-symbols is in use, we can just handle
1266 well-behaved ISO-compliant code. */
1268 const char *str = XSTR (XEXP (rtl, 0), 0);
1269 int len = strlen (str);
1270 char *newstr = XALLOCAVEC (char, len + 2);
1272 strcpy (newstr + 1, str);
1273 XSTR (XEXP (rtl, 0), 0) = ggc_alloc_string (newstr, len + 1);
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)))))
1286 SYMBOL_REF_FLAG (XEXP (rtl, 0)) = 1;
1290 mmix_strip_name_encoding (const char *name)
1292 for (; (*name == '@' || *name == '*'); name++)
1298 /* TARGET_ASM_FILE_START.
1299 We just emit a little comment for the time being. */
1302 mmix_file_start (void)
1304 default_file_start ();
1306 fputs ("! mmixal:= 8H LOC Data_Section\n", asm_out_file);
1308 /* Make sure each file starts with the text section. */
1309 switch_to_section (text_section);
1312 /* TARGET_ASM_FILE_END. */
1315 mmix_file_end (void)
1317 /* Make sure each file ends with the data section. */
1318 switch_to_section (data_section);
1321 /* TARGET_ASM_OUTPUT_SOURCE_FILENAME. */
1324 mmix_asm_output_source_filename (FILE *stream, const char *name)
1326 fprintf (stream, "# 1 ");
1327 OUTPUT_QUOTED_STRING (stream, name);
1328 fprintf (stream, "\n");
1331 /* OUTPUT_QUOTED_STRING. */
1334 mmix_output_quoted_string (FILE *stream, const char *string, int length)
1336 const char * string_end = string + length;
1337 static const char *const unwanted_chars = "\"[]\\";
1339 /* Output "any character except newline and double quote character". We
1340 play it safe and avoid all control characters too. We also do not
1341 want [] as characters, should input be passed through m4 with [] as
1342 quotes. Further, we avoid "\", because the GAS port handles it as a
1343 quoting character. */
1344 while (string < string_end)
1347 && (unsigned char) *string < 128
1348 && !ISCNTRL (*string)
1349 && strchr (unwanted_chars, *string) == NULL)
1351 fputc ('"', stream);
1353 && (unsigned char) *string < 128
1354 && !ISCNTRL (*string)
1355 && strchr (unwanted_chars, *string) == NULL
1356 && string < string_end)
1358 fputc (*string, stream);
1361 fputc ('"', stream);
1362 if (string < string_end)
1363 fprintf (stream, ",");
1365 if (string < string_end)
1367 fprintf (stream, "#%x", *string & 255);
1369 if (string < string_end)
1370 fprintf (stream, ",");
1375 /* Target hook for assembling integer objects. Use mmix_print_operand
1376 for WYDE and TETRA. Use mmix_output_octa to output 8-byte
1380 mmix_assemble_integer (rtx x, unsigned int size, int aligned_p)
1385 /* We handle a limited number of types of operands in here. But
1386 that's ok, because we can punt to generic functions. We then
1387 pretend that aligned data isn't needed, so the usual .<pseudo>
1388 syntax is used (which works for aligned data too). We actually
1389 *must* do that, since we say we don't have simple aligned
1390 pseudos, causing this function to be called. We just try and
1391 keep as much compatibility as possible with mmixal syntax for
1392 normal cases (i.e. without GNU extensions and C only). */
1394 if (GET_CODE (x) != CONST_INT)
1399 fputs ("\tBYTE\t", asm_out_file);
1400 mmix_print_operand (asm_out_file, x, 'B');
1401 fputc ('\n', asm_out_file);
1405 if (GET_CODE (x) != CONST_INT)
1410 fputs ("\tWYDE\t", asm_out_file);
1411 mmix_print_operand (asm_out_file, x, 'W');
1412 fputc ('\n', asm_out_file);
1416 if (GET_CODE (x) != CONST_INT)
1421 fputs ("\tTETRA\t", asm_out_file);
1422 mmix_print_operand (asm_out_file, x, 'L');
1423 fputc ('\n', asm_out_file);
1427 /* We don't get here anymore for CONST_DOUBLE, because DImode
1428 isn't expressed as CONST_DOUBLE, and DFmode is handled
1430 gcc_assert (GET_CODE (x) != CONST_DOUBLE);
1431 assemble_integer_with_op ("\tOCTA\t", x);
1434 return default_assemble_integer (x, size, aligned_p);
1437 /* ASM_OUTPUT_ASCII. */
1440 mmix_asm_output_ascii (FILE *stream, const char *string, int length)
1444 int chunk_size = length > 60 ? 60 : length;
1445 fprintf (stream, "\tBYTE ");
1446 mmix_output_quoted_string (stream, string, chunk_size);
1447 string += chunk_size;
1448 length -= chunk_size;
1449 fprintf (stream, "\n");
1453 /* ASM_OUTPUT_ALIGNED_COMMON. */
1456 mmix_asm_output_aligned_common (FILE *stream,
1461 /* This is mostly the elfos.h one. There doesn't seem to be a way to
1462 express this in a mmixal-compatible way. */
1463 fprintf (stream, "\t.comm\t");
1464 assemble_name (stream, name);
1465 fprintf (stream, ",%u,%u ! mmixal-incompatible COMMON\n",
1466 size, align / BITS_PER_UNIT);
1469 /* ASM_OUTPUT_ALIGNED_LOCAL. */
1472 mmix_asm_output_aligned_local (FILE *stream,
1477 switch_to_section (data_section);
1479 ASM_OUTPUT_ALIGN (stream, exact_log2 (align/BITS_PER_UNIT));
1480 assemble_name (stream, name);
1481 fprintf (stream, "\tLOC @+%d\n", size);
1484 /* ASM_OUTPUT_LABEL. */
1487 mmix_asm_output_label (FILE *stream, const char *name)
1489 assemble_name (stream, name);
1490 fprintf (stream, "\tIS @\n");
1493 /* ASM_OUTPUT_INTERNAL_LABEL. */
1496 mmix_asm_output_internal_label (FILE *stream, const char *name)
1498 assemble_name_raw (stream, name);
1499 fprintf (stream, "\tIS @\n");
1502 /* ASM_DECLARE_REGISTER_GLOBAL. */
1505 mmix_asm_declare_register_global (FILE *stream ATTRIBUTE_UNUSED,
1506 tree decl ATTRIBUTE_UNUSED,
1507 int regno ATTRIBUTE_UNUSED,
1508 const char *name ATTRIBUTE_UNUSED)
1510 /* Nothing to do here, but there *will* be, therefore the framework is
1514 /* ASM_WEAKEN_LABEL. */
1517 mmix_asm_weaken_label (FILE *stream ATTRIBUTE_UNUSED,
1518 const char *name ATTRIBUTE_UNUSED)
1520 fprintf (stream, "\t.weak ");
1521 assemble_name (stream, name);
1522 fprintf (stream, " ! mmixal-incompatible\n");
1525 /* MAKE_DECL_ONE_ONLY. */
1528 mmix_make_decl_one_only (tree decl)
1530 DECL_WEAK (decl) = 1;
1533 /* ASM_OUTPUT_LABELREF.
1534 Strip GCC's '*' and our own '@'. No order is assumed. */
1537 mmix_asm_output_labelref (FILE *stream, const char *name)
1541 for (; (*name == '@' || *name == '*'); name++)
1545 asm_fprintf (stream, "%s%U%s",
1546 is_extern && TARGET_TOPLEVEL_SYMBOLS ? ":" : "",
1550 /* ASM_OUTPUT_DEF. */
1553 mmix_asm_output_def (FILE *stream, const char *name, const char *value)
1555 assemble_name (stream, name);
1556 fprintf (stream, "\tIS ");
1557 assemble_name (stream, value);
1558 fputc ('\n', stream);
1561 /* PRINT_OPERAND. */
1564 mmix_print_operand (FILE *stream, rtx x, int code)
1566 /* When we add support for different codes later, we can, when needed,
1567 drop through to the main handler with a modified operand. */
1569 int regno = x != NULL_RTX && REG_P (x) ? REGNO (x) : 0;
1573 /* Unrelated codes are in alphabetic order. */
1576 /* For conditional branches, output "P" for a probable branch. */
1577 if (TARGET_BRANCH_PREDICT)
1579 x = find_reg_note (current_output_insn, REG_BR_PROB, 0);
1580 if (x && INTVAL (XEXP (x, 0)) > REG_BR_PROB_BASE / 2)
1586 /* For the %d in POP %d,0. */
1587 fprintf (stream, "%d", MMIX_POP_ARGUMENT ());
1591 if (GET_CODE (x) != CONST_INT)
1592 fatal_insn ("MMIX Internal: Expected a CONST_INT, not this", x);
1593 fprintf (stream, "%d", (int) (INTVAL (x) & 0xff));
1597 /* Highpart. Must be general register, and not the last one, as
1598 that one cannot be part of a consecutive register pair. */
1599 if (regno > MMIX_LAST_GENERAL_REGISTER - 1)
1600 internal_error ("MMIX Internal: Bad register: %d", regno);
1602 /* This is big-endian, so the high-part is the first one. */
1603 fprintf (stream, "%s", reg_names[MMIX_OUTPUT_REGNO (regno)]);
1607 /* Lowpart. Must be CONST_INT or general register, and not the last
1608 one, as that one cannot be part of a consecutive register pair. */
1609 if (GET_CODE (x) == CONST_INT)
1611 fprintf (stream, "#%lx",
1612 (unsigned long) (INTVAL (x)
1613 & ((unsigned int) 0x7fffffff * 2 + 1)));
1617 if (GET_CODE (x) == SYMBOL_REF)
1619 output_addr_const (stream, x);
1623 if (regno > MMIX_LAST_GENERAL_REGISTER - 1)
1624 internal_error ("MMIX Internal: Bad register: %d", regno);
1626 /* This is big-endian, so the low-part is + 1. */
1627 fprintf (stream, "%s", reg_names[MMIX_OUTPUT_REGNO (regno) + 1]);
1630 /* Can't use 'a' because that's a generic modifier for address
1633 mmix_output_shiftvalue_op_from_str (stream, "ANDN",
1634 ~(unsigned HOST_WIDEST_INT)
1639 mmix_output_shiftvalue_op_from_str (stream, "INC",
1640 (unsigned HOST_WIDEST_INT)
1645 mmix_output_shiftvalue_op_from_str (stream, "OR",
1646 (unsigned HOST_WIDEST_INT)
1651 mmix_output_shiftvalue_op_from_str (stream, "SET",
1652 (unsigned HOST_WIDEST_INT)
1658 mmix_output_condition (stream, x, (code == 'D'));
1662 /* Output an extra "e" to make fcmpe, fune. */
1663 if (TARGET_FCMP_EPSILON)
1664 fprintf (stream, "e");
1668 /* Output the number minus 1. */
1669 if (GET_CODE (x) != CONST_INT)
1671 fatal_insn ("MMIX Internal: Bad value for 'm', not a CONST_INT",
1674 fprintf (stream, HOST_WIDEST_INT_PRINT_DEC,
1675 (HOST_WIDEST_INT) (mmix_intval (x) - 1));
1679 /* Store the number of registers we want to save. This was setup
1680 by the prologue. The actual operand contains the number of
1681 registers to pass, but we don't use it currently. Anyway, we
1682 need to output the number of saved registers here. */
1683 fprintf (stream, "%d",
1684 cfun->machine->highest_saved_stack_register + 1);
1688 /* Store the register to output a constant to. */
1690 fatal_insn ("MMIX Internal: Expected a register, not this", x);
1691 mmix_output_destination_register = MMIX_OUTPUT_REGNO (regno);
1695 /* Output the constant. Note that we use this for floats as well. */
1696 if (GET_CODE (x) != CONST_INT
1697 && (GET_CODE (x) != CONST_DOUBLE
1698 || (GET_MODE (x) != VOIDmode && GET_MODE (x) != DFmode
1699 && GET_MODE (x) != SFmode)))
1700 fatal_insn ("MMIX Internal: Expected a constant, not this", x);
1701 mmix_output_register_setting (stream,
1702 mmix_output_destination_register,
1703 mmix_intval (x), 0);
1707 /* An U for unsigned, if TARGET_ZERO_EXTEND. Ignore the operand. */
1708 if (TARGET_ZERO_EXTEND)
1713 mmix_output_shifted_value (stream, (HOST_WIDEST_INT) mmix_intval (x));
1717 mmix_output_shifted_value (stream, (HOST_WIDEST_INT) ~mmix_intval (x));
1721 if (GET_CODE (x) != CONST_INT)
1722 fatal_insn ("MMIX Internal: Expected a CONST_INT, not this", x);
1723 fprintf (stream, "#%x", (int) (INTVAL (x) & 0xffff));
1727 /* Nothing to do. */
1731 /* Presumably there's a missing case above if we get here. */
1732 internal_error ("MMIX Internal: Missing %qc case in mmix_print_operand", code);
1735 switch (GET_CODE (modified_x))
1738 regno = REGNO (modified_x);
1739 if (regno >= FIRST_PSEUDO_REGISTER)
1740 internal_error ("MMIX Internal: Bad register: %d", regno);
1741 fprintf (stream, "%s", reg_names[MMIX_OUTPUT_REGNO (regno)]);
1745 output_address (XEXP (modified_x, 0));
1749 /* For -2147483648, mmixal complains that the constant does not fit
1750 in 4 bytes, so let's output it as hex. Take care to handle hosts
1751 where HOST_WIDE_INT is longer than an int.
1753 Print small constants +-255 using decimal. */
1755 if (INTVAL (modified_x) > -256 && INTVAL (modified_x) < 256)
1756 fprintf (stream, "%d", (int) (INTVAL (modified_x)));
1758 fprintf (stream, "#%x",
1759 (int) (INTVAL (modified_x)) & (unsigned int) ~0);
1763 /* Do somewhat as CONST_INT. */
1764 mmix_output_octa (stream, mmix_intval (modified_x), 0);
1768 output_addr_const (stream, modified_x);
1772 /* No need to test for all strange things. Let output_addr_const do
1774 if (CONSTANT_P (modified_x)
1775 /* Strangely enough, this is not included in CONSTANT_P.
1776 FIXME: Ask/check about sanity here. */
1777 || GET_CODE (modified_x) == CODE_LABEL)
1779 output_addr_const (stream, modified_x);
1783 /* We need the original here. */
1784 fatal_insn ("MMIX Internal: Cannot decode this operand", x);
1788 /* PRINT_OPERAND_PUNCT_VALID_P. */
1791 mmix_print_operand_punct_valid_p (int code ATTRIBUTE_UNUSED)
1793 /* A '+' is used for branch prediction, similar to other ports. */
1795 /* A '.' is used for the %d in the POP %d,0 return insn. */
1799 /* PRINT_OPERAND_ADDRESS. */
1802 mmix_print_operand_address (FILE *stream, rtx x)
1806 /* I find the generated assembly code harder to read without
1808 fprintf (stream, "%s,0", reg_names[MMIX_OUTPUT_REGNO (REGNO (x))]);
1811 else if (GET_CODE (x) == PLUS)
1813 rtx x1 = XEXP (x, 0);
1814 rtx x2 = XEXP (x, 1);
1818 fprintf (stream, "%s,", reg_names[MMIX_OUTPUT_REGNO (REGNO (x1))]);
1822 fprintf (stream, "%s",
1823 reg_names[MMIX_OUTPUT_REGNO (REGNO (x2))]);
1826 else if (GET_CODE (x2) == CONST_INT
1827 && CONST_OK_FOR_LETTER_P (INTVAL (x2), 'I'))
1829 output_addr_const (stream, x2);
1835 if (TARGET_BASE_ADDRESSES && mmix_legitimate_constant_p (Pmode, x))
1837 output_addr_const (stream, x);
1841 fatal_insn ("MMIX Internal: This is not a recognized address", x);
1844 /* ASM_OUTPUT_REG_PUSH. */
1847 mmix_asm_output_reg_push (FILE *stream, int regno)
1849 fprintf (stream, "\tSUBU %s,%s,8\n\tSTOU %s,%s,0\n",
1850 reg_names[MMIX_STACK_POINTER_REGNUM],
1851 reg_names[MMIX_STACK_POINTER_REGNUM],
1852 reg_names[MMIX_OUTPUT_REGNO (regno)],
1853 reg_names[MMIX_STACK_POINTER_REGNUM]);
1856 /* ASM_OUTPUT_REG_POP. */
1859 mmix_asm_output_reg_pop (FILE *stream, int regno)
1861 fprintf (stream, "\tLDOU %s,%s,0\n\tINCL %s,8\n",
1862 reg_names[MMIX_OUTPUT_REGNO (regno)],
1863 reg_names[MMIX_STACK_POINTER_REGNUM],
1864 reg_names[MMIX_STACK_POINTER_REGNUM]);
1867 /* ASM_OUTPUT_ADDR_DIFF_ELT. */
1870 mmix_asm_output_addr_diff_elt (FILE *stream,
1871 rtx body ATTRIBUTE_UNUSED,
1875 fprintf (stream, "\tTETRA L%d-L%d\n", value, rel);
1878 /* ASM_OUTPUT_ADDR_VEC_ELT. */
1881 mmix_asm_output_addr_vec_elt (FILE *stream, int value)
1883 fprintf (stream, "\tOCTA L:%d\n", value);
1886 /* ASM_OUTPUT_SKIP. */
1889 mmix_asm_output_skip (FILE *stream, int nbytes)
1891 fprintf (stream, "\tLOC @+%d\n", nbytes);
1894 /* ASM_OUTPUT_ALIGN. */
1897 mmix_asm_output_align (FILE *stream, int power)
1899 /* We need to record the needed alignment of this section in the object,
1900 so we have to output an alignment directive. Use a .p2align (not
1901 .align) so people will never have to wonder about whether the
1902 argument is in number of bytes or the log2 thereof. We do it in
1903 addition to the LOC directive, so nothing needs tweaking when
1904 copy-pasting assembly into mmixal. */
1905 fprintf (stream, "\t.p2align %d\n", power);
1906 fprintf (stream, "\tLOC @+(%d-@)&%d\n", 1 << power, (1 << power) - 1);
1909 /* DBX_REGISTER_NUMBER. */
1912 mmix_dbx_register_number (unsigned regno)
1914 /* Adjust the register number to the one it will be output as, dammit.
1915 It'd be nice if we could check the assumption that we're filling a
1916 gap, but every register between the last saved register and parameter
1917 registers might be a valid parameter register. */
1918 regno = MMIX_OUTPUT_REGNO (regno);
1920 /* We need to renumber registers to get the number of the return address
1921 register in the range 0..255. It is also space-saving if registers
1922 mentioned in the call-frame information (which uses this function by
1923 defaulting DWARF_FRAME_REGNUM to DBX_REGISTER_NUMBER) are numbered
1924 0 .. 63. So map 224 .. 256+15 -> 0 .. 47 and 0 .. 223 -> 48..223+48. */
1925 return regno >= 224 ? (regno - 224) : (regno + 48);
1928 /* End of target macro support functions.
1930 Now the MMIX port's own functions. First the exported ones. */
1932 /* Wrapper for get_hard_reg_initial_val since integrate.h isn't included
1933 from insn-emit.c. */
1936 mmix_get_hard_reg_initial_val (enum machine_mode mode, int regno)
1938 return get_hard_reg_initial_val (mode, regno);
1941 /* Nonzero when the function epilogue is simple enough that a single
1942 "POP %d,0" should be used even within the function. */
1945 mmix_use_simple_return (void)
1949 int stack_space_to_allocate
1950 = (crtl->outgoing_args_size
1951 + crtl->args.pretend_args_size
1952 + get_frame_size () + 7) & ~7;
1954 if (!TARGET_USE_RETURN_INSN || !reload_completed)
1958 regno >= MMIX_FIRST_GLOBAL_REGNUM;
1960 /* Note that we assume that the frame-pointer-register is one of these
1961 registers, in which case we don't count it here. */
1962 if ((((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
1963 && df_regs_ever_live_p (regno) && !call_used_regs[regno]))
1964 || IS_MMIX_EH_RETURN_DATA_REG (regno))
1967 if (frame_pointer_needed)
1968 stack_space_to_allocate += 8;
1970 if (MMIX_CFUN_HAS_LANDING_PAD)
1971 stack_space_to_allocate += 16;
1972 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
1973 stack_space_to_allocate += 8;
1975 return stack_space_to_allocate == 0;
1979 /* Expands the function prologue into RTX. */
1982 mmix_expand_prologue (void)
1984 HOST_WIDE_INT locals_size = get_frame_size ();
1986 HOST_WIDE_INT stack_space_to_allocate
1987 = (crtl->outgoing_args_size
1988 + crtl->args.pretend_args_size
1989 + locals_size + 7) & ~7;
1990 HOST_WIDE_INT offset = -8;
1992 /* Add room needed to save global non-register-stack registers. */
1994 regno >= MMIX_FIRST_GLOBAL_REGNUM;
1996 /* Note that we assume that the frame-pointer-register is one of these
1997 registers, in which case we don't count it here. */
1998 if ((((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
1999 && df_regs_ever_live_p (regno) && !call_used_regs[regno]))
2000 || IS_MMIX_EH_RETURN_DATA_REG (regno))
2001 stack_space_to_allocate += 8;
2003 /* If we do have a frame-pointer, add room for it. */
2004 if (frame_pointer_needed)
2005 stack_space_to_allocate += 8;
2007 /* If we have a non-local label, we need to be able to unwind to it, so
2008 store the current register stack pointer. Also store the return
2009 address if we do that. */
2010 if (MMIX_CFUN_HAS_LANDING_PAD)
2011 stack_space_to_allocate += 16;
2012 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
2013 /* If we do have a saved return-address slot, add room for it. */
2014 stack_space_to_allocate += 8;
2016 /* Make sure we don't get an unaligned stack. */
2017 if ((stack_space_to_allocate % 8) != 0)
2018 internal_error ("stack frame not a multiple of 8 bytes: %wd",
2019 stack_space_to_allocate);
2021 if (crtl->args.pretend_args_size)
2023 int mmix_first_vararg_reg
2024 = (MMIX_FIRST_INCOMING_ARG_REGNUM
2025 + (MMIX_MAX_ARGS_IN_REGS
2026 - crtl->args.pretend_args_size / 8));
2029 = MMIX_FIRST_INCOMING_ARG_REGNUM + MMIX_MAX_ARGS_IN_REGS - 1;
2030 regno >= mmix_first_vararg_reg;
2035 HOST_WIDE_INT stack_chunk
2036 = stack_space_to_allocate > (256 - 8)
2037 ? (256 - 8) : stack_space_to_allocate;
2039 mmix_emit_sp_add (-stack_chunk);
2040 offset += stack_chunk;
2041 stack_space_to_allocate -= stack_chunk;
2044 /* These registers aren't actually saved (as in "will be
2045 restored"), so don't tell DWARF2 they're saved. */
2046 emit_move_insn (gen_rtx_MEM (DImode,
2047 plus_constant (stack_pointer_rtx,
2049 gen_rtx_REG (DImode, regno));
2054 /* Store the frame-pointer. */
2056 if (frame_pointer_needed)
2062 /* Get 8 less than otherwise, since we need to reach offset + 8. */
2063 HOST_WIDE_INT stack_chunk
2064 = stack_space_to_allocate > (256 - 8 - 8)
2065 ? (256 - 8 - 8) : stack_space_to_allocate;
2067 mmix_emit_sp_add (-stack_chunk);
2069 offset += stack_chunk;
2070 stack_space_to_allocate -= stack_chunk;
2073 insn = emit_move_insn (gen_rtx_MEM (DImode,
2074 plus_constant (stack_pointer_rtx,
2076 hard_frame_pointer_rtx);
2077 RTX_FRAME_RELATED_P (insn) = 1;
2078 insn = emit_insn (gen_adddi3 (hard_frame_pointer_rtx,
2080 GEN_INT (offset + 8)));
2081 RTX_FRAME_RELATED_P (insn) = 1;
2085 if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
2090 /* Store the return-address, if one is needed on the stack. We
2091 usually store it in a register when needed, but that doesn't work
2092 with -fexceptions. */
2096 /* Get 8 less than otherwise, since we need to reach offset + 8. */
2097 HOST_WIDE_INT stack_chunk
2098 = stack_space_to_allocate > (256 - 8 - 8)
2099 ? (256 - 8 - 8) : stack_space_to_allocate;
2101 mmix_emit_sp_add (-stack_chunk);
2103 offset += stack_chunk;
2104 stack_space_to_allocate -= stack_chunk;
2107 tmpreg = gen_rtx_REG (DImode, 255);
2108 retreg = gen_rtx_REG (DImode, MMIX_rJ_REGNUM);
2110 /* Dwarf2 code is confused by the use of a temporary register for
2111 storing the return address, so we have to express it as a note,
2112 which we attach to the actual store insn. */
2113 emit_move_insn (tmpreg, retreg);
2115 insn = emit_move_insn (gen_rtx_MEM (DImode,
2116 plus_constant (stack_pointer_rtx,
2119 RTX_FRAME_RELATED_P (insn) = 1;
2120 add_reg_note (insn, REG_FRAME_RELATED_EXPR,
2121 gen_rtx_SET (VOIDmode,
2122 gen_rtx_MEM (DImode,
2123 plus_constant (stack_pointer_rtx,
2129 else if (MMIX_CFUN_HAS_LANDING_PAD)
2132 if (MMIX_CFUN_HAS_LANDING_PAD)
2134 /* Store the register defining the numbering of local registers, so
2135 we know how long to unwind the register stack. */
2139 /* Get 8 less than otherwise, since we need to reach offset + 8. */
2140 HOST_WIDE_INT stack_chunk
2141 = stack_space_to_allocate > (256 - 8 - 8)
2142 ? (256 - 8 - 8) : stack_space_to_allocate;
2144 mmix_emit_sp_add (-stack_chunk);
2146 offset += stack_chunk;
2147 stack_space_to_allocate -= stack_chunk;
2150 /* We don't tell dwarf2 about this one; we just have it to unwind
2151 the register stack at landing pads. FIXME: It's a kludge because
2152 we can't describe the effect of the PUSHJ and PUSHGO insns on the
2153 register stack at the moment. Best thing would be to handle it
2154 like stack-pointer offsets. Better: some hook into dwarf2out.c
2155 to produce DW_CFA_expression:s that specify the increment of rO,
2156 and unwind it at eh_return (preferred) or at the landing pad.
2157 Then saves to $0..$G-1 could be specified through that register. */
2159 emit_move_insn (gen_rtx_REG (DImode, 255),
2160 gen_rtx_REG (DImode,
2162 emit_move_insn (gen_rtx_MEM (DImode,
2163 plus_constant (stack_pointer_rtx, offset)),
2164 gen_rtx_REG (DImode, 255));
2168 /* After the return-address and the frame-pointer, we have the local
2169 variables. They're the ones that may have an "unaligned" size. */
2170 offset -= (locals_size + 7) & ~7;
2172 /* Now store all registers that are global, i.e. not saved by the
2173 register file machinery.
2175 It is assumed that the frame-pointer is one of these registers, so it
2176 is explicitly excluded in the count. */
2179 regno >= MMIX_FIRST_GLOBAL_REGNUM;
2181 if (((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
2182 && df_regs_ever_live_p (regno) && ! call_used_regs[regno])
2183 || IS_MMIX_EH_RETURN_DATA_REG (regno))
2189 HOST_WIDE_INT stack_chunk
2190 = (stack_space_to_allocate > (256 - offset - 8)
2191 ? (256 - offset - 8) : stack_space_to_allocate);
2193 mmix_emit_sp_add (-stack_chunk);
2194 offset += stack_chunk;
2195 stack_space_to_allocate -= stack_chunk;
2198 insn = emit_move_insn (gen_rtx_MEM (DImode,
2199 plus_constant (stack_pointer_rtx,
2201 gen_rtx_REG (DImode, regno));
2202 RTX_FRAME_RELATED_P (insn) = 1;
2206 /* Finally, allocate room for outgoing args and local vars if room
2207 wasn't allocated above. */
2208 if (stack_space_to_allocate)
2209 mmix_emit_sp_add (-stack_space_to_allocate);
2212 /* Expands the function epilogue into RTX. */
2215 mmix_expand_epilogue (void)
2217 HOST_WIDE_INT locals_size = get_frame_size ();
2219 HOST_WIDE_INT stack_space_to_deallocate
2220 = (crtl->outgoing_args_size
2221 + crtl->args.pretend_args_size
2222 + locals_size + 7) & ~7;
2224 /* The first address to access is beyond the outgoing_args area. */
2225 HOST_WIDE_INT offset = crtl->outgoing_args_size;
2227 /* Add the space for global non-register-stack registers.
2228 It is assumed that the frame-pointer register can be one of these
2229 registers, in which case it is excluded from the count when needed. */
2231 regno >= MMIX_FIRST_GLOBAL_REGNUM;
2233 if (((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
2234 && df_regs_ever_live_p (regno) && !call_used_regs[regno])
2235 || IS_MMIX_EH_RETURN_DATA_REG (regno))
2236 stack_space_to_deallocate += 8;
2238 /* Add in the space for register stack-pointer. If so, always add room
2239 for the saved PC. */
2240 if (MMIX_CFUN_HAS_LANDING_PAD)
2241 stack_space_to_deallocate += 16;
2242 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
2243 /* If we have a saved return-address slot, add it in. */
2244 stack_space_to_deallocate += 8;
2246 /* Add in the frame-pointer. */
2247 if (frame_pointer_needed)
2248 stack_space_to_deallocate += 8;
2250 /* Make sure we don't get an unaligned stack. */
2251 if ((stack_space_to_deallocate % 8) != 0)
2252 internal_error ("stack frame not a multiple of octabyte: %wd",
2253 stack_space_to_deallocate);
2255 /* We will add back small offsets to the stack pointer as we go.
2256 First, we restore all registers that are global, i.e. not saved by
2257 the register file machinery. */
2259 for (regno = MMIX_FIRST_GLOBAL_REGNUM;
2262 if (((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
2263 && df_regs_ever_live_p (regno) && !call_used_regs[regno])
2264 || IS_MMIX_EH_RETURN_DATA_REG (regno))
2268 mmix_emit_sp_add (offset);
2269 stack_space_to_deallocate -= offset;
2273 emit_move_insn (gen_rtx_REG (DImode, regno),
2274 gen_rtx_MEM (DImode,
2275 plus_constant (stack_pointer_rtx,
2280 /* Here is where the local variables were. As in the prologue, they
2281 might be of an unaligned size. */
2282 offset += (locals_size + 7) & ~7;
2284 /* The saved register stack pointer is just below the frame-pointer
2285 register. We don't need to restore it "manually"; the POP
2286 instruction does that. */
2287 if (MMIX_CFUN_HAS_LANDING_PAD)
2289 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
2290 /* The return-address slot is just below the frame-pointer register.
2291 We don't need to restore it because we don't really use it. */
2294 /* Get back the old frame-pointer-value. */
2295 if (frame_pointer_needed)
2299 mmix_emit_sp_add (offset);
2301 stack_space_to_deallocate -= offset;
2305 emit_move_insn (hard_frame_pointer_rtx,
2306 gen_rtx_MEM (DImode,
2307 plus_constant (stack_pointer_rtx,
2312 /* We do not need to restore pretended incoming args, just add back
2314 if (stack_space_to_deallocate != 0)
2315 mmix_emit_sp_add (stack_space_to_deallocate);
2317 if (crtl->calls_eh_return)
2318 /* Adjust the (normal) stack-pointer to that of the receiver.
2319 FIXME: It would be nice if we could also adjust the register stack
2320 here, but we need to express it through DWARF 2 too. */
2321 emit_insn (gen_adddi3 (stack_pointer_rtx, stack_pointer_rtx,
2322 gen_rtx_REG (DImode,
2323 MMIX_EH_RETURN_STACKADJ_REGNUM)));
2326 /* Output an optimal sequence for setting a register to a specific
2327 constant. Used in an alternative for const_ints in movdi, and when
2328 using large stack-frame offsets.
2330 Use do_begin_end to say if a line-starting TAB and newline before the
2331 first insn and after the last insn is wanted. */
2334 mmix_output_register_setting (FILE *stream,
2336 HOST_WIDEST_INT value,
2340 fprintf (stream, "\t");
2342 if (mmix_shiftable_wyde_value ((unsigned HOST_WIDEST_INT) value))
2344 /* First, the one-insn cases. */
2345 mmix_output_shiftvalue_op_from_str (stream, "SET",
2346 (unsigned HOST_WIDEST_INT)
2348 fprintf (stream, " %s,", reg_names[regno]);
2349 mmix_output_shifted_value (stream, (unsigned HOST_WIDEST_INT) value);
2351 else if (mmix_shiftable_wyde_value (-(unsigned HOST_WIDEST_INT) value))
2353 /* We do this to get a bit more legible assembly code. The next
2354 alternative is mostly redundant with this. */
2356 mmix_output_shiftvalue_op_from_str (stream, "SET",
2357 -(unsigned HOST_WIDEST_INT)
2359 fprintf (stream, " %s,", reg_names[regno]);
2360 mmix_output_shifted_value (stream, -(unsigned HOST_WIDEST_INT) value);
2361 fprintf (stream, "\n\tNEGU %s,0,%s", reg_names[regno],
2364 else if (mmix_shiftable_wyde_value (~(unsigned HOST_WIDEST_INT) value))
2366 /* Slightly more expensive, the two-insn cases. */
2368 /* FIXME: We could of course also test if 0..255-N or ~(N | 1..255)
2369 is shiftable, or any other one-insn transformation of the value.
2370 FIXME: Check first if the value is "shiftable" by two loading
2371 with two insns, since it makes more readable assembly code (if
2372 anyone else cares). */
2374 mmix_output_shiftvalue_op_from_str (stream, "SET",
2375 ~(unsigned HOST_WIDEST_INT)
2377 fprintf (stream, " %s,", reg_names[regno]);
2378 mmix_output_shifted_value (stream, ~(unsigned HOST_WIDEST_INT) value);
2379 fprintf (stream, "\n\tNOR %s,%s,0", reg_names[regno],
2384 /* The generic case. 2..4 insns. */
2385 static const char *const higher_parts[] = {"L", "ML", "MH", "H"};
2386 const char *op = "SET";
2387 const char *line_begin = "";
2390 HOST_WIDEST_INT tmpvalue = value;
2392 /* Compute the number of insns needed to output this constant. */
2393 for (i = 0; i < 4 && tmpvalue != 0; i++)
2395 if (tmpvalue & 65535)
2399 if (TARGET_BASE_ADDRESSES && insns == 3)
2401 /* The number three is based on a static observation on
2402 ghostscript-6.52. Two and four are excluded because there
2403 are too many such constants, and each unique constant (maybe
2404 offset by 1..255) were used few times compared to other uses,
2407 We use base-plus-offset addressing to force it into a global
2408 register; we just use a "LDA reg,VALUE", which will cause the
2409 assembler and linker to DTRT (for constants as well as
2411 fprintf (stream, "LDA %s,", reg_names[regno]);
2412 mmix_output_octa (stream, value, 0);
2416 /* Output pertinent parts of the 4-wyde sequence.
2417 Still more to do if we want this to be optimal, but hey...
2418 Note that the zero case has been handled above. */
2419 for (i = 0; i < 4 && value != 0; i++)
2423 fprintf (stream, "%s%s%s %s,#%x", line_begin, op,
2424 higher_parts[i], reg_names[regno],
2425 (int) (value & 65535));
2426 /* The first one sets the rest of the bits to 0, the next
2427 ones add set bits. */
2429 line_begin = "\n\t";
2438 fprintf (stream, "\n");
2441 /* Return 1 if value is 0..65535*2**(16*N) for N=0..3.
2445 mmix_shiftable_wyde_value (unsigned HOST_WIDEST_INT value)
2447 /* Shift by 16 bits per group, stop when we've found two groups with
2450 int has_candidate = 0;
2452 for (i = 0; i < 4; i++)
2468 /* X and Y are two things to compare using CODE. Return the rtx for
2469 the cc-reg in the proper mode. */
2472 mmix_gen_compare_reg (RTX_CODE code, rtx x, rtx y)
2474 enum machine_mode ccmode = SELECT_CC_MODE (code, x, y);
2475 return gen_reg_rtx (ccmode);
2478 /* Local (static) helper functions. */
2481 mmix_emit_sp_add (HOST_WIDE_INT offset)
2487 /* Negative stack-pointer adjustments are allocations and appear in
2488 the prologue only. We mark them as frame-related so unwind and
2489 debug info is properly emitted for them. */
2491 insn = emit_insn (gen_adddi3 (stack_pointer_rtx,
2496 rtx tmpr = gen_rtx_REG (DImode, 255);
2497 RTX_FRAME_RELATED_P (emit_move_insn (tmpr, GEN_INT (offset))) = 1;
2498 insn = emit_insn (gen_adddi3 (stack_pointer_rtx,
2499 stack_pointer_rtx, tmpr));
2501 RTX_FRAME_RELATED_P (insn) = 1;
2505 /* Positive adjustments are in the epilogue only. Don't mark them
2506 as "frame-related" for unwind info. */
2507 if (CONST_OK_FOR_LETTER_P (offset, 'L'))
2508 emit_insn (gen_adddi3 (stack_pointer_rtx,
2513 rtx tmpr = gen_rtx_REG (DImode, 255);
2514 emit_move_insn (tmpr, GEN_INT (offset));
2515 insn = emit_insn (gen_adddi3 (stack_pointer_rtx,
2516 stack_pointer_rtx, tmpr));
2521 /* Print operator suitable for doing something with a shiftable
2522 wyde. The type of operator is passed as an asm output modifier. */
2525 mmix_output_shiftvalue_op_from_str (FILE *stream,
2527 HOST_WIDEST_INT value)
2529 static const char *const op_part[] = {"L", "ML", "MH", "H"};
2532 if (! mmix_shiftable_wyde_value (value))
2534 char s[sizeof ("0xffffffffffffffff")];
2535 sprintf (s, HOST_WIDEST_INT_PRINT_HEX, value);
2536 internal_error ("MMIX Internal: %s is not a shiftable int", s);
2539 for (i = 0; i < 4; i++)
2541 /* We know we're through when we find one-bits in the low
2545 fprintf (stream, "%s%s", mainop, op_part[i]);
2551 /* No bits set? Then it must have been zero. */
2552 fprintf (stream, "%sL", mainop);
2555 /* Print a 64-bit value, optionally prefixed by assembly pseudo. */
2558 mmix_output_octa (FILE *stream, HOST_WIDEST_INT value, int do_begin_end)
2560 /* Snipped from final.c:output_addr_const. We need to avoid the
2561 presumed universal "0x" prefix. We can do it by replacing "0x" with
2562 "#0" here; we must avoid a space in the operands and no, the zero
2563 won't cause the number to be assumed in octal format. */
2564 char hex_format[sizeof (HOST_WIDEST_INT_PRINT_HEX)];
2567 fprintf (stream, "\tOCTA ");
2569 strcpy (hex_format, HOST_WIDEST_INT_PRINT_HEX);
2570 hex_format[0] = '#';
2571 hex_format[1] = '0';
2573 /* Provide a few alternative output formats depending on the number, to
2574 improve legibility of assembler output. */
2575 if ((value < (HOST_WIDEST_INT) 0 && value > (HOST_WIDEST_INT) -10000)
2576 || (value >= (HOST_WIDEST_INT) 0 && value <= (HOST_WIDEST_INT) 16384))
2577 fprintf (stream, "%d", (int) value);
2578 else if (value > (HOST_WIDEST_INT) 0
2579 && value < ((HOST_WIDEST_INT) 1 << 31) * 2)
2580 fprintf (stream, "#%x", (unsigned int) value);
2582 fprintf (stream, hex_format, value);
2585 fprintf (stream, "\n");
2588 /* Print the presumed shiftable wyde argument shifted into place (to
2589 be output with an operand). */
2592 mmix_output_shifted_value (FILE *stream, HOST_WIDEST_INT value)
2596 if (! mmix_shiftable_wyde_value (value))
2599 sprintf (s, HOST_WIDEST_INT_PRINT_HEX, value);
2600 internal_error ("MMIX Internal: %s is not a shiftable int", s);
2603 for (i = 0; i < 4; i++)
2605 /* We know we're through when we find one-bits in the low 16 bits. */
2608 fprintf (stream, "#%x", (int) (value & 0xffff));
2615 /* No bits set? Then it must have been zero. */
2616 fprintf (stream, "0");
2619 /* Output an MMIX condition name corresponding to an operator
2621 (comparison_operator [(comparison_operator ...) (const_int 0)])
2622 which means we have to look at *two* operators.
2624 The argument "reversed" refers to reversal of the condition (not the
2625 same as swapping the arguments). */
2628 mmix_output_condition (FILE *stream, rtx x, int reversed)
2634 /* The normal output cc-code. */
2635 const char *const normal;
2637 /* The reversed cc-code, or NULL if invalid. */
2638 const char *const reversed;
2643 enum machine_mode cc_mode;
2645 /* Terminated with {UNKNOWN, NULL, NULL} */
2646 const struct cc_conv *const convs;
2650 #define CCEND {UNKNOWN, NULL, NULL}
2652 static const struct cc_conv cc_fun_convs[]
2653 = {{ORDERED, "Z", "P"},
2654 {UNORDERED, "P", "Z"},
2656 static const struct cc_conv cc_fp_convs[]
2660 static const struct cc_conv cc_fpeq_convs[]
2664 static const struct cc_conv cc_uns_convs[]
2665 = {{GEU, "NN", "N"},
2670 static const struct cc_conv cc_signed_convs[]
2678 static const struct cc_conv cc_di_convs[]
2690 static const struct cc_type_conv cc_convs[]
2691 = {{CC_FUNmode, cc_fun_convs},
2692 {CC_FPmode, cc_fp_convs},
2693 {CC_FPEQmode, cc_fpeq_convs},
2694 {CC_UNSmode, cc_uns_convs},
2695 {CCmode, cc_signed_convs},
2696 {DImode, cc_di_convs}};
2701 enum machine_mode mode = GET_MODE (XEXP (x, 0));
2702 RTX_CODE cc = GET_CODE (x);
2704 for (i = 0; i < ARRAY_SIZE (cc_convs); i++)
2706 if (mode == cc_convs[i].cc_mode)
2708 for (j = 0; cc_convs[i].convs[j].cc != UNKNOWN; j++)
2709 if (cc == cc_convs[i].convs[j].cc)
2712 = (reversed ? cc_convs[i].convs[j].reversed
2713 : cc_convs[i].convs[j].normal);
2715 if (mmix_cc == NULL)
2716 fatal_insn ("MMIX Internal: Trying to output invalidly\
2717 reversed condition:", x);
2719 fprintf (stream, "%s", mmix_cc);
2723 fatal_insn ("MMIX Internal: What's the CC of this?", x);
2727 fatal_insn ("MMIX Internal: What is the CC of this?", x);
2730 /* Return the bit-value for a const_int or const_double. */
2732 static HOST_WIDEST_INT
2735 unsigned HOST_WIDEST_INT retval;
2737 if (GET_CODE (x) == CONST_INT)
2740 /* We make a little song and dance because converting to long long in
2741 gcc-2.7.2 is broken. I still want people to be able to use it for
2742 cross-compilation to MMIX. */
2743 if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == VOIDmode)
2745 if (sizeof (HOST_WIDE_INT) < sizeof (HOST_WIDEST_INT))
2747 retval = (unsigned) CONST_DOUBLE_LOW (x) / 2;
2749 retval |= CONST_DOUBLE_LOW (x) & 1;
2752 (unsigned HOST_WIDEST_INT) CONST_DOUBLE_HIGH (x)
2753 << (HOST_BITS_PER_LONG)/2 << (HOST_BITS_PER_LONG)/2;
2756 retval = CONST_DOUBLE_HIGH (x);
2761 if (GET_CODE (x) == CONST_DOUBLE)
2763 REAL_VALUE_TYPE value;
2765 /* FIXME: This macro is not in the manual but should be. */
2766 REAL_VALUE_FROM_CONST_DOUBLE (value, x);
2768 if (GET_MODE (x) == DFmode)
2772 REAL_VALUE_TO_TARGET_DOUBLE (value, bits);
2774 /* The double cast is necessary to avoid getting the long
2775 sign-extended to unsigned long long(!) when they're of
2776 different size (usually 32-bit hosts). */
2778 ((unsigned HOST_WIDEST_INT) (unsigned long) bits[0]
2779 << (unsigned HOST_WIDEST_INT) 32U)
2780 | (unsigned HOST_WIDEST_INT) (unsigned long) bits[1];
2782 else if (GET_MODE (x) == SFmode)
2785 REAL_VALUE_TO_TARGET_SINGLE (value, bits);
2787 return (unsigned long) bits;
2791 fatal_insn ("MMIX Internal: This is not a constant:", x);
2794 /* Worker function for TARGET_PROMOTE_FUNCTION_MODE. */
2797 mmix_promote_function_mode (const_tree type ATTRIBUTE_UNUSED,
2798 enum machine_mode mode,
2799 int *punsignedp ATTRIBUTE_UNUSED,
2800 const_tree fntype ATTRIBUTE_UNUSED,
2803 /* Apparently not doing TRT if int < register-size. FIXME: Perhaps
2804 FUNCTION_VALUE and LIBCALL_VALUE needs tweaking as some ports say. */
2805 if (for_return == 1)
2808 /* Promotion of modes currently generates slow code, extending before
2809 operation, so we do it only for arguments. */
2810 if (GET_MODE_CLASS (mode) == MODE_INT
2811 && GET_MODE_SIZE (mode) < 8)
2816 /* Worker function for TARGET_STRUCT_VALUE_RTX. */
2819 mmix_struct_value_rtx (tree fntype ATTRIBUTE_UNUSED,
2820 int incoming ATTRIBUTE_UNUSED)
2822 return gen_rtx_REG (Pmode, MMIX_STRUCT_VALUE_REGNUM);
2825 /* Worker function for TARGET_FRAME_POINTER_REQUIRED.
2827 FIXME: Is this requirement built-in? Anyway, we should try to get rid
2828 of it; we can deduce the value. */
2831 mmix_frame_pointer_required (void)
2833 return (cfun->has_nonlocal_label);
2838 * eval: (c-set-style "gnu")
2839 * indent-tabs-mode: t